IB/hfi1, rdmavt: Update copy_sge to use boolean arguments
authorBrian Welty <brian.welty@intel.com>
Wed, 8 Feb 2017 13:27:31 +0000 (05:27 -0800)
committerDoug Ledford <dledford@redhat.com>
Sun, 19 Feb 2017 14:18:41 +0000 (09:18 -0500)
Convert copy_sge and related SGE state functions to use boolean.
For determining if QP is in user mode, add helper function in rdmavt_qp.h.
This is used to determine if QP needs the last byte ordering.
While here, change rvt_pd.user to a boolean.

Reviewed-by: Mike Marciniszyn <mike.marciniszyn@intel.com>
Reviewed-by: Dean Luick <dean.luick@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/rc.c
drivers/infiniband/hw/hfi1/ruc.c
drivers/infiniband/hw/hfi1/uc.c
drivers/infiniband/hw/hfi1/ud.c
drivers/infiniband/hw/hfi1/verbs.c
drivers/infiniband/hw/hfi1/verbs.h
drivers/infiniband/sw/rdmavt/pd.c
include/rdma/rdma_vt.h
include/rdma/rdmavt_qp.h

index c2f1a6f576fcd0282f493b992fd02f671e7311b7..b1c350dd3e8bf4718d5fb47872e99224ef18b6f2 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, 0);
+       hfi1_skip_sge(ss, len, false);
        return wqe->length - len;
 }
 
@@ -1508,7 +1508,7 @@ read_middle:
                qp->s_rdma_read_len -= pmtu;
                update_last_psn(qp, psn);
                spin_unlock_irqrestore(&qp->s_lock, flags);
-               hfi1_copy_sge(&qp->s_rdma_read_sge, data, pmtu, 0, 0);
+               hfi1_copy_sge(&qp->s_rdma_read_sge, data, pmtu, false, false);
                goto bail;
 
        case OP(RDMA_READ_RESPONSE_ONLY):
@@ -1552,7 +1552,7 @@ read_last:
                if (unlikely(tlen != qp->s_rdma_read_len))
                        goto ack_len_err;
                aeth = be32_to_cpu(ohdr->u.aeth);
-               hfi1_copy_sge(&qp->s_rdma_read_sge, data, tlen, 0, 0);
+               hfi1_copy_sge(&qp->s_rdma_read_sge, data, tlen, false, false);
                WARN_ON(qp->s_rdma_read_sge.num_sge);
                (void)do_rc_ack(qp, aeth, psn,
                                 OP(RDMA_READ_RESPONSE_LAST), 0, rcd);
@@ -1923,7 +1923,7 @@ void hfi1_rc_rcv(struct hfi1_packet *packet)
        struct ib_reth *reth;
        unsigned long flags;
        int ret, is_fecn = 0;
-       int copy_last = 0;
+       bool copy_last = false;
        u32 rkey;
 
        lockdep_assert_held(&qp->r_lock);
@@ -2017,7 +2017,7 @@ send_middle:
                qp->r_rcv_len += pmtu;
                if (unlikely(qp->r_rcv_len > qp->r_len))
                        goto nack_inv;
-               hfi1_copy_sge(&qp->r_sge, data, pmtu, 1, 0);
+               hfi1_copy_sge(&qp->r_sge, data, pmtu, true, false);
                break;
 
        case OP(RDMA_WRITE_LAST_WITH_IMMEDIATE):
@@ -2057,7 +2057,7 @@ send_last_inv:
                wc.wc_flags = IB_WC_WITH_INVALIDATE;
                goto send_last;
        case OP(RDMA_WRITE_LAST):
-               copy_last = ibpd_to_rvtpd(qp->ibqp.pd)->user;
+               copy_last = rvt_is_user_qp(qp);
                /* fall through */
        case OP(SEND_LAST):
 no_immediate_data:
@@ -2075,7 +2075,7 @@ send_last:
                wc.byte_len = tlen + qp->r_rcv_len;
                if (unlikely(wc.byte_len > qp->r_len))
                        goto nack_inv;
-               hfi1_copy_sge(&qp->r_sge, data, tlen, 1, copy_last);
+               hfi1_copy_sge(&qp->r_sge, data, tlen, true, copy_last);
                rvt_put_ss(&qp->r_sge);
                qp->r_msn++;
                if (!__test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags))
@@ -2113,7 +2113,7 @@ send_last:
                break;
 
        case OP(RDMA_WRITE_ONLY):
-               copy_last = 1;
+               copy_last = rvt_is_user_qp(qp);
                /* fall through */
        case OP(RDMA_WRITE_FIRST):
        case OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE):
index dc41b2c5628a90a604f718e7d364bb45c8f6adc7..bdf3697de88136c9def1b0a7a11395647ac07eb1 100644 (file)
@@ -320,9 +320,9 @@ static void ruc_loopback(struct rvt_qp *sqp)
        u64 sdata;
        atomic64_t *maddr;
        enum ib_wc_status send_status;
-       int release;
+       bool release;
        int ret;
-       int copy_last = 0;
+       bool copy_last = false;
        int local_ops = 0;
 
        rcu_read_lock();
@@ -386,7 +386,7 @@ again:
        memset(&wc, 0, sizeof(wc));
        send_status = IB_WC_SUCCESS;
 
-       release = 1;
+       release = true;
        sqp->s_sge.sge = wqe->sg_list[0];
        sqp->s_sge.sg_list = wqe->sg_list + 1;
        sqp->s_sge.num_sge = wqe->wr.num_sge;
@@ -437,7 +437,7 @@ send:
                /* skip copy_last set and qp_access_flags recheck */
                goto do_write;
        case IB_WR_RDMA_WRITE:
-               copy_last = ibpd_to_rvtpd(qp->ibqp.pd)->user;
+               copy_last = rvt_is_user_qp(qp);
                if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_WRITE)))
                        goto inv_err;
 do_write:
@@ -461,7 +461,7 @@ do_write:
                                          wqe->rdma_wr.rkey,
                                          IB_ACCESS_REMOTE_READ)))
                        goto acc_err;
-               release = 0;
+               release = false;
                sqp->s_sge.sg_list = NULL;
                sqp->s_sge.num_sge = 1;
                qp->r_sge.sge = wqe->sg_list[0];
index 782a0bfeedb7544ba40cf803981120f80eef125b..4b2a8400c8236f3f2677faf432c27729a3380781 100644 (file)
@@ -419,7 +419,7 @@ send_first:
                qp->r_rcv_len += pmtu;
                if (unlikely(qp->r_rcv_len > qp->r_len))
                        goto rewind;
-               hfi1_copy_sge(&qp->r_sge, data, pmtu, 0, 0);
+               hfi1_copy_sge(&qp->r_sge, data, pmtu, false, false);
                break;
 
        case OP(SEND_LAST_WITH_IMMEDIATE):
@@ -444,7 +444,7 @@ send_last:
                if (unlikely(wc.byte_len > qp->r_len))
                        goto rewind;
                wc.opcode = IB_WC_RECV;
-               hfi1_copy_sge(&qp->r_sge, data, tlen, 0, 0);
+               hfi1_copy_sge(&qp->r_sge, data, tlen, false, false);
                rvt_put_ss(&qp->s_rdma_read_sge);
 last_imm:
                wc.wr_id = qp->r_wr_id;
@@ -519,7 +519,7 @@ rdma_first:
                qp->r_rcv_len += pmtu;
                if (unlikely(qp->r_rcv_len > qp->r_len))
                        goto drop;
-               hfi1_copy_sge(&qp->r_sge, data, pmtu, 1, 0);
+               hfi1_copy_sge(&qp->r_sge, data, pmtu, true, false);
                break;
 
        case OP(RDMA_WRITE_LAST_WITH_IMMEDIATE):
@@ -548,7 +548,7 @@ rdma_last_imm:
                }
                wc.byte_len = qp->r_len;
                wc.opcode = IB_WC_RECV_RDMA_WITH_IMM;
-               hfi1_copy_sge(&qp->r_sge, data, tlen, 1, 0);
+               hfi1_copy_sge(&qp->r_sge, data, tlen, true, false);
                rvt_put_ss(&qp->r_sge);
                goto last_imm;
 
@@ -564,7 +564,7 @@ rdma_last:
                tlen -= (hdrsize + pad + 4);
                if (unlikely(tlen + qp->r_rcv_len != qp->r_len))
                        goto drop;
-               hfi1_copy_sge(&qp->r_sge, data, tlen, 1, 0);
+               hfi1_copy_sge(&qp->r_sge, data, tlen, true, false);
                rvt_put_ss(&qp->r_sge);
                break;
 
index 58cd30104ec237925f9b62da8e97a251b4a4120b..9329c16a1f6fb5da44ce736139e589643bcbdfc2 100644 (file)
@@ -189,10 +189,10 @@ static void ud_loopback(struct rvt_qp *sqp, struct rvt_swqe *swqe)
 
                hfi1_make_grh(ibp, &grh, &grd, 0, 0);
                hfi1_copy_sge(&qp->r_sge, &grh,
-                             sizeof(grh), 1, 0);
+                             sizeof(grh), true, false);
                wc.wc_flags |= IB_WC_GRH;
        } else {
-               hfi1_skip_sge(&qp->r_sge, sizeof(struct ib_grh), 1);
+               hfi1_skip_sge(&qp->r_sge, sizeof(struct ib_grh), true);
        }
        ssge.sg_list = swqe->sg_list + 1;
        ssge.sge = *swqe->sg_list;
@@ -206,7 +206,7 @@ static void ud_loopback(struct rvt_qp *sqp, struct rvt_swqe *swqe)
                if (len > sge->sge_length)
                        len = sge->sge_length;
                WARN_ON_ONCE(len == 0);
-               hfi1_copy_sge(&qp->r_sge, sge->vaddr, len, 1, 0);
+               hfi1_copy_sge(&qp->r_sge, sge->vaddr, len, true, false);
                sge->vaddr += len;
                sge->length -= len;
                sge->sge_length -= len;
@@ -812,13 +812,13 @@ void hfi1_ud_rcv(struct hfi1_packet *packet)
        }
        if (has_grh) {
                hfi1_copy_sge(&qp->r_sge, &hdr->u.l.grh,
-                             sizeof(struct ib_grh), 1, 0);
+                             sizeof(struct ib_grh), true, false);
                wc.wc_flags |= IB_WC_GRH;
        } else {
-               hfi1_skip_sge(&qp->r_sge, sizeof(struct ib_grh), 1);
+               hfi1_skip_sge(&qp->r_sge, sizeof(struct ib_grh), true);
        }
        hfi1_copy_sge(&qp->r_sge, data, wc.byte_len - sizeof(struct ib_grh),
-                     1, 0);
+                     true, false);
        rvt_put_ss(&qp->r_sge);
        if (!test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags))
                return;
index cae32304eabad881c63c6124110e5acc5e3f2198..b10c2dcb4ba50f4499fe8226ed25be801f800220 100644 (file)
@@ -291,7 +291,7 @@ static void wss_insert(void *address)
 /*
  * Is the working set larger than the threshold?
  */
-static inline int wss_exceeds_threshold(void)
+static inline bool wss_exceeds_threshold(void)
 {
        return atomic_read(&wss.total_count) >= wss.threshold;
 }
@@ -419,18 +419,19 @@ __be64 ib_hfi1_sys_image_guid;
  * @ss: the SGE state
  * @data: the data to copy
  * @length: the length of the data
+ * @release: boolean to release MR
  * @copy_last: do a separate copy of the last 8 bytes
  */
 void hfi1_copy_sge(
        struct rvt_sge_state *ss,
        void *data, u32 length,
-       int release,
-       int copy_last)
+       bool release,
+       bool copy_last)
 {
        struct rvt_sge *sge = &ss->sge;
-       int in_last = 0;
        int i;
-       int cacheless_copy = 0;
+       bool in_last = false;
+       bool cacheless_copy = false;
 
        if (sge_copy_mode == COPY_CACHELESS) {
                cacheless_copy = length >= PAGE_SIZE;
@@ -454,8 +455,8 @@ void hfi1_copy_sge(
                if (length > 8) {
                        length -= 8;
                } else {
-                       copy_last = 0;
-                       in_last = 1;
+                       copy_last = false;
+                       in_last = true;
                }
        }
 
@@ -501,8 +502,8 @@ again:
        }
 
        if (copy_last) {
-               copy_last = 0;
-               in_last = 1;
+               copy_last = false;
+               in_last = true;
                length = 8;
                goto again;
        }
@@ -513,7 +514,7 @@ again:
  * @ss: the SGE state
  * @length: the number of bytes to skip
  */
-void hfi1_skip_sge(struct rvt_sge_state *ss, u32 length, int release)
+void hfi1_skip_sge(struct rvt_sge_state *ss, u32 length, bool release)
 {
        struct rvt_sge *sge = &ss->sge;
 
index 6e9e4bbf8ae45bb5ef3a30d7f7a8e34dafa12db5..9fab6b3d12f668512a4c1134fccbc113f62056f5 100644 (file)
@@ -289,9 +289,9 @@ void hfi1_put_txreq(struct verbs_txreq *tx);
 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,
-                  int release, int copy_last);
+                  bool release, bool copy_last);
 
-void hfi1_skip_sge(struct rvt_sge_state *ss, u32 length, int release);
+void hfi1_skip_sge(struct rvt_sge_state *ss, u32 length, bool release);
 
 void hfi1_cnp_rcv(struct hfi1_packet *packet);
 
index d1292f324c67d7a799cb24debd33eea31d5929ba..8a89afff3363e2f8db20ac50ab3e0c168f63f5ed 100644 (file)
@@ -90,7 +90,7 @@ struct ib_pd *rvt_alloc_pd(struct ib_device *ibdev,
        spin_unlock(&dev->n_pds_lock);
 
        /* ib_alloc_pd() will initialize pd->ibpd. */
-       pd->user = udata ? 1 : 0;
+       pd->user = !!udata;
 
        ret = &pd->ibpd;
 
index a69dee38365f8957e9cacc5f0ee12370f8f84945..8fc1ca7b6f2329fd38f27577de827949a9697df7 100644 (file)
@@ -164,7 +164,7 @@ struct rvt_driver_params {
 /* Protection domain */
 struct rvt_pd {
        struct ib_pd ibpd;
-       int user;               /* non-zero if created from user space */
+       bool user;
 };
 
 /* Address handle */
index 0b1cbffb967ca87aa5db987d75ab5806b26010a6..561b6c87608625cfe13b6ef41612947d3e957f1e 100644 (file)
@@ -467,6 +467,15 @@ static inline struct rvt_rwqe *rvt_get_rwqe_ptr(struct rvt_rq *rq, unsigned n)
                  rq->max_sge * sizeof(struct ib_sge)) * n);
 }
 
+/**
+ * rvt_is_user_qp - return if this is user mode QP
+ * @qp - the target QP
+ */
+static inline bool rvt_is_user_qp(struct rvt_qp *qp)
+{
+       return !!qp->pid;
+}
+
 /**
  * rvt_get_qp - get a QP reference
  * @qp - the QP to hold