IB/hfi1, rdmavt: Move SGE state helper routines into rdmavt
authorBrian Welty <brian.welty@intel.com>
Wed, 8 Feb 2017 13:27:37 +0000 (05:27 -0800)
committerDoug Ledford <dledford@redhat.com>
Sun, 19 Feb 2017 14:18:41 +0000 (09:18 -0500)
To improve code reuse, add small SGE state helper routines to rdmavt_mr.h.
Leverage these in hfi1, including refactoring of hfi1_copy_sge.

Reviewed-by: Mike Marciniszyn <mike.marciniszyn@intel.com>
Signed-off-by: Brian Welty <brian.welty@intel.com>
Signed-off-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
drivers/infiniband/hw/hfi1/hfi.h
drivers/infiniband/hw/hfi1/rc.c
drivers/infiniband/hw/hfi1/ud.c
drivers/infiniband/hw/hfi1/verbs.c
drivers/infiniband/hw/hfi1/verbs.h
include/rdma/rdmavt_mr.h

index fcfd5f1b901780b7b545b447b7f223cd5c77a446..9c3be919c0b74b357b374b0d089c2dfea2e981f9 100644 (file)
@@ -1797,8 +1797,6 @@ int kdeth_process_expected(struct hfi1_packet *packet);
 int kdeth_process_eager(struct hfi1_packet *packet);
 int process_receive_invalid(struct hfi1_packet *packet);
 
-void update_sge(struct rvt_sge_state *ss, u32 length);
-
 /* global module parameter variables */
 extern unsigned int hfi1_max_mtu;
 extern unsigned int hfi1_cu;
index b1c350dd3e8bf4718d5fb47872e99224ef18b6f2..85e7bf6dcc11d45fe9d5347bc1c5af8843492ba4 100644 (file)
@@ -67,7 +67,7 @@ static u32 restart_sge(struct rvt_sge_state *ss, struct rvt_swqe *wqe,
        ss->sg_list = wqe->sg_list + 1;
        ss->num_sge = wqe->wr.num_sge;
        ss->total_len = wqe->length;
-       hfi1_skip_sge(ss, len, false);
+       rvt_skip_sge(ss, len, false);
        return wqe->length - len;
 }
 
index 9329c16a1f6fb5da44ce736139e589643bcbdfc2..13ea4eb6ef3d81b3279ca58d9b16e97059cb1f00 100644 (file)
@@ -192,7 +192,7 @@ static void ud_loopback(struct rvt_qp *sqp, struct rvt_swqe *swqe)
                              sizeof(grh), true, false);
                wc.wc_flags |= IB_WC_GRH;
        } else {
-               hfi1_skip_sge(&qp->r_sge, sizeof(struct ib_grh), true);
+               rvt_skip_sge(&qp->r_sge, sizeof(struct ib_grh), true);
        }
        ssge.sg_list = swqe->sg_list + 1;
        ssge.sge = *swqe->sg_list;
@@ -815,7 +815,7 @@ void hfi1_ud_rcv(struct hfi1_packet *packet)
                              sizeof(struct ib_grh), true, false);
                wc.wc_flags |= IB_WC_GRH;
        } else {
-               hfi1_skip_sge(&qp->r_sge, sizeof(struct ib_grh), true);
+               rvt_skip_sge(&qp->r_sge, sizeof(struct ib_grh), true);
        }
        hfi1_copy_sge(&qp->r_sge, data, wc.byte_len - sizeof(struct ib_grh),
                      true, false);
index b10c2dcb4ba50f4499fe8226ed25be801f800220..72f459e1fdde39edac5532bf19dd2d8196da5d06 100644 (file)
@@ -462,12 +462,8 @@ void hfi1_copy_sge(
 
 again:
        while (length) {
-               u32 len = sge->length;
+               u32 len = rvt_get_sge_length(sge, length);
 
-               if (len > length)
-                       len = length;
-               if (len > sge->sge_length)
-                       len = sge->sge_length;
                WARN_ON_ONCE(len == 0);
                if (unlikely(in_last)) {
                        /* enforce byte transfer ordering */
@@ -478,25 +474,7 @@ again:
                } else {
                        memcpy(sge->vaddr, data, len);
                }
-               sge->vaddr += len;
-               sge->length -= len;
-               sge->sge_length -= len;
-               if (sge->sge_length == 0) {
-                       if (release)
-                               rvt_put_mr(sge->mr);
-                       if (--ss->num_sge)
-                               *sge = *ss->sg_list++;
-               } else if (sge->length == 0 && sge->mr->lkey) {
-                       if (++sge->n >= RVT_SEGSZ) {
-                               if (++sge->m >= sge->mr->mapsz)
-                                       break;
-                               sge->n = 0;
-                       }
-                       sge->vaddr =
-                               sge->mr->map[sge->m]->segs[sge->n].vaddr;
-                       sge->length =
-                               sge->mr->map[sge->m]->segs[sge->n].length;
-               }
+               rvt_update_sge(ss, len, release);
                data += len;
                length -= len;
        }
@@ -509,46 +487,6 @@ again:
        }
 }
 
-/**
- * hfi1_skip_sge - skip over SGE memory
- * @ss: the SGE state
- * @length: the number of bytes to skip
- */
-void hfi1_skip_sge(struct rvt_sge_state *ss, u32 length, bool release)
-{
-       struct rvt_sge *sge = &ss->sge;
-
-       while (length) {
-               u32 len = sge->length;
-
-               if (len > length)
-                       len = length;
-               if (len > sge->sge_length)
-                       len = sge->sge_length;
-               WARN_ON_ONCE(len == 0);
-               sge->vaddr += len;
-               sge->length -= len;
-               sge->sge_length -= len;
-               if (sge->sge_length == 0) {
-                       if (release)
-                               rvt_put_mr(sge->mr);
-                       if (--ss->num_sge)
-                               *sge = *ss->sg_list++;
-               } else if (sge->length == 0 && sge->mr->lkey) {
-                       if (++sge->n >= RVT_SEGSZ) {
-                               if (++sge->m >= sge->mr->mapsz)
-                                       break;
-                               sge->n = 0;
-                       }
-                       sge->vaddr =
-                               sge->mr->map[sge->m]->segs[sge->n].vaddr;
-                       sge->length =
-                               sge->mr->map[sge->m]->segs[sge->n].length;
-               }
-               length -= len;
-       }
-}
-
 /*
  * Make sure the QP is ready and able to accept the given opcode.
  */
@@ -690,27 +628,6 @@ static void mem_timer(unsigned long data)
                hfi1_qp_wakeup(qp, RVT_S_WAIT_KMEM);
 }
 
-void update_sge(struct rvt_sge_state *ss, u32 length)
-{
-       struct rvt_sge *sge = &ss->sge;
-
-       sge->vaddr += length;
-       sge->length -= length;
-       sge->sge_length -= length;
-       if (sge->sge_length == 0) {
-               if (--ss->num_sge)
-                       *sge = *ss->sg_list++;
-       } else if (sge->length == 0 && sge->mr->lkey) {
-               if (++sge->n >= RVT_SEGSZ) {
-                       if (++sge->m >= sge->mr->mapsz)
-                               return;
-                       sge->n = 0;
-               }
-               sge->vaddr = sge->mr->map[sge->m]->segs[sge->n].vaddr;
-               sge->length = sge->mr->map[sge->m]->segs[sge->n].length;
-       }
-}
-
 /*
  * This is called with progress side lock held.
  */
@@ -799,7 +716,7 @@ static noinline int build_verbs_ulp_payload(
                        len);
                if (ret)
                        goto bail_txadd;
-               update_sge(ss, len);
+               rvt_update_sge(ss, len, false);
                length -= len;
        }
        return ret;
@@ -1074,7 +991,7 @@ int hfi1_verbs_send_pio(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
 
                                if (slen > len)
                                        slen = len;
-                               update_sge(ss, slen);
+                               rvt_update_sge(ss, slen, false);
                                seg_pio_copy_mid(pbuf, addr, slen);
                                len -= slen;
                        }
index 9fab6b3d12f668512a4c1134fccbc113f62056f5..3a0b589e41c2105bbfe608af1820d48c6cc55782 100644 (file)
@@ -291,8 +291,6 @@ int hfi1_verbs_send(struct rvt_qp *qp, struct hfi1_pkt_state *ps);
 void hfi1_copy_sge(struct rvt_sge_state *ss, void *data, u32 length,
                   bool release, bool copy_last);
 
-void hfi1_skip_sge(struct rvt_sge_state *ss, u32 length, bool release);
-
 void hfi1_cnp_rcv(struct hfi1_packet *packet);
 
 void hfi1_uc_rcv(struct hfi1_packet *packet);
index 05698d8d9c6f943cfd9c53af45aa8cff5ce3f069..f418bd5571a56e60023cce3b432042a52a5dd7dc 100644 (file)
@@ -141,4 +141,54 @@ static inline void rvt_put_ss(struct rvt_sge_state *ss)
        }
 }
 
+static inline u32 rvt_get_sge_length(struct rvt_sge *sge, u32 length)
+{
+       u32 len = sge->length;
+
+       if (len > length)
+               len = length;
+       if (len > sge->sge_length)
+               len = sge->sge_length;
+
+       return len;
+}
+
+static inline void rvt_update_sge(struct rvt_sge_state *ss, u32 length,
+                                 bool release)
+{
+       struct rvt_sge *sge = &ss->sge;
+
+       sge->vaddr += length;
+       sge->length -= length;
+       sge->sge_length -= length;
+       if (sge->sge_length == 0) {
+               if (release)
+                       rvt_put_mr(sge->mr);
+               if (--ss->num_sge)
+                       *sge = *ss->sg_list++;
+       } else if (sge->length == 0 && sge->mr->lkey) {
+               if (++sge->n >= RVT_SEGSZ) {
+                       if (++sge->m >= sge->mr->mapsz)
+                               return;
+                       sge->n = 0;
+               }
+               sge->vaddr = sge->mr->map[sge->m]->segs[sge->n].vaddr;
+               sge->length = sge->mr->map[sge->m]->segs[sge->n].length;
+       }
+}
+
+static inline void rvt_skip_sge(struct rvt_sge_state *ss, u32 length,
+                               bool release)
+{
+       struct rvt_sge *sge = &ss->sge;
+
+       while (length) {
+               u32 len = rvt_get_sge_length(sge, length);
+
+               WARN_ON_ONCE(len == 0);
+               rvt_update_sge(ss, len, release);
+               length -= len;
+       }
+}
+
 #endif          /* DEF_RDMAVT_INCMRH */