]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
IB/hfi1: Add functions to parse BTH/IB headers
authorDon Hiatt <don.hiatt@intel.com>
Fri, 12 May 2017 16:19:55 +0000 (09:19 -0700)
committerDoug Ledford <dledford@redhat.com>
Tue, 27 Jun 2017 20:56:33 +0000 (16:56 -0400)
Improve code readablity by adding inline functions
to read specific BTH/IB fields without knowledge of
byte offsets.

Reviewed-by: Brian Welty <brian.welty@intel.com>
Reviewed-by: Dasaratharaman Chandramouli <dasaratharaman.chandramouli@intel.com>
Reviewed-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: Don Hiatt <don.hiatt@intel.com>
Signed-off-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
drivers/infiniband/hw/hfi1/driver.c
drivers/infiniband/hw/hfi1/rc.c
drivers/infiniband/hw/hfi1/uc.c
drivers/infiniband/hw/hfi1/ud.c
drivers/infiniband/hw/hfi1/verbs.c
include/rdma/ib_hdrs.h
include/rdma/ib_verbs.h
include/rdma/rdmavt_qp.h

index a50870e455a30156a75c7527e4ec2b7646b8de9b..0583479f2576ae67c57c651088a1a0fc720d27fb 100644 (file)
@@ -286,7 +286,7 @@ static void rcv_hdrerr(struct hfi1_ctxtdata *rcd, struct hfi1_pportdata *ppd,
                        goto drop;
                }
                /* Get the destination QP number. */
-               qp_num = be32_to_cpu(ohdr->bth[1]) & RVT_QPN_MASK;
+               qp_num = ib_bth_get_qpn(ohdr);
                if (lid < be16_to_cpu(IB_MULTICAST_LID_BASE)) {
                        struct rvt_qp *qp;
                        unsigned long flags;
@@ -438,7 +438,7 @@ void hfi1_process_ecn_slowpath(struct rvt_qp *qp, struct hfi1_packet *pkt,
        case IB_QPT_GSI:
        case IB_QPT_UD:
                rlid = ib_get_slid(hdr);
-               rqpn = be32_to_cpu(ohdr->u.ud.deth[1]) & RVT_QPN_MASK;
+               rqpn = ib_get_sqpn(ohdr);
                svc_type = IB_CC_SVCTYPE_UD;
                is_mcast = (dlid > be16_to_cpu(IB_MULTICAST_LID_BASE)) &&
                        (dlid != be16_to_cpu(IB_LID_PERMISSIVE));
@@ -461,7 +461,7 @@ void hfi1_process_ecn_slowpath(struct rvt_qp *qp, struct hfi1_packet *pkt,
 
        bth1 = be32_to_cpu(ohdr->bth[1]);
        if (do_cnp && (bth1 & IB_FECN_SMASK)) {
-               u16 pkey = (u16)be32_to_cpu(ohdr->bth[0]);
+               u16 pkey = ib_bth_get_pkey(ohdr);
 
                return_cnp(ibp, qp, rqpn, pkey, dlid, rlid, sc, grh);
        }
index 1080778a1f7c4a38816ce02058f63baae862d89e..66e6843aab48e85894705d6b8b0d8e701c9657c7 100644 (file)
@@ -765,7 +765,7 @@ void hfi1_send_rc_ack(struct hfi1_ctxtdata *rcd, struct rvt_qp *qp,
                ohdr->u.aeth = rvt_compute_aeth(qp);
        sc5 = ibp->sl_to_sc[rdma_ah_get_sl(&qp->remote_ah_attr)];
        /* set PBC_DC_INFO bit (aka SC[4]) in pbc_flags */
-       pbc_flags |= ((!!(sc5 & 0x10)) << PBC_DC_INFO_SHIFT);
+       pbc_flags |= (ib_is_sc5(sc5) << PBC_DC_INFO_SHIFT);
        lrh0 |= (sc5 & 0xf) << 12 | (rdma_ah_get_sl(&qp->remote_ah_attr)
                                     & 0xf) << 4;
        hdr.lrh[0] = cpu_to_be16(lrh0);
@@ -1009,7 +1009,7 @@ void hfi1_rc_send_complete(struct rvt_qp *qp, struct ib_header *hdr)
                return;
        }
 
-       psn = be32_to_cpu(ohdr->bth[2]);
+       psn = ib_bth_get_psn(ohdr);
        reset_sending_psn(qp, psn);
 
        /*
@@ -1943,7 +1943,7 @@ void hfi1_rc_rcv(struct hfi1_packet *packet)
 
        is_fecn = process_ecn(qp, packet, false);
 
-       psn = be32_to_cpu(ohdr->bth[2]);
+       psn = ib_bth_get_psn(ohdr);
        opcode = ib_bth_get_opcode(ohdr);
 
        /*
@@ -2388,7 +2388,7 @@ void hfi1_rc_hdrerr(
        if (hfi1_ruc_check_hdr(ibp, hdr, has_grh, qp, bth0))
                return;
 
-       psn = be32_to_cpu(ohdr->bth[2]);
+       psn = ib_bth_get_psn(ohdr);
        opcode = ib_bth_get_opcode(ohdr);
 
        /* Only deal with RDMA Writes for now */
index 5da1e4546543710a9b11a84c13cf2e368f7d0365..2a5650f8aee00c63bc322d1bf53618b12861c988 100644 (file)
@@ -319,7 +319,7 @@ void hfi1_uc_rcv(struct hfi1_packet *packet)
 
        process_ecn(qp, packet, true);
 
-       psn = be32_to_cpu(ohdr->bth[2]);
+       psn = ib_bth_get_psn(ohdr);
        opcode = ib_bth_get_opcode(ohdr);
 
        /* Compare the PSN verses the expected PSN. */
index 6a4e95cefae5f64c337b69f75f9187c48a6e40f6..49fe179ad3ae200acc8f63d373937d22fc8a65bb 100644 (file)
@@ -549,7 +549,7 @@ void return_cnp(struct hfi1_ibport *ibp, struct rvt_qp *qp, u32 remote_qpn,
        hdr.lrh[3] = cpu_to_be16(slid);
 
        plen = 2 /* PBC */ + hwords;
-       pbc_flags |= (!!(sc5 & 0x10)) << PBC_DC_INFO_SHIFT;
+       pbc_flags |= (ib_is_sc5(sc5) << PBC_DC_INFO_SHIFT);
        vl = sc_to_vlt(ppd->dd, sc5);
        pbc = create_pbc(ppd, pbc_flags, qp->srate_mbps, vl, plen);
        if (ctxt) {
@@ -689,8 +689,8 @@ void hfi1_ud_rcv(struct hfi1_packet *packet)
        u16 slid;
        u8 extra_bytes;
 
-       qkey = be32_to_cpu(ohdr->u.ud.deth[0]);
-       src_qp = be32_to_cpu(ohdr->u.ud.deth[1]) & RVT_QPN_MASK;
+       qkey = ib_get_qkey(ohdr);
+       src_qp = ib_get_sqpn(ohdr);
        dlid = ib_get_dlid(hdr);
        bth1 = be32_to_cpu(ohdr->bth[1]);
        slid = ib_get_slid(hdr);
index 90e7b77d68e8ca1e41f7b2208d4497ac880680a1..128d2917a2d9fe13687e5bd2d89c2cb274359cb8 100644 (file)
@@ -595,7 +595,7 @@ void hfi1_ib_rcv(struct hfi1_packet *packet)
        inc_opstats(tlen, &rcd->opstats->stats[opcode]);
 
        /* Get the destination QP number. */
-       qp_num = be32_to_cpu(packet->ohdr->bth[1]) & RVT_QPN_MASK;
+       qp_num = ib_bth_get_qpn(packet->ohdr);
        lid = ib_get_dlid(hdr);
        if (unlikely((lid >= be16_to_cpu(IB_MULTICAST_LID_BASE)) &&
                     (lid != be16_to_cpu(IB_LID_PERMISSIVE)))) {
@@ -863,7 +863,7 @@ int hfi1_verbs_send_dma(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
 
                        /* No vl15 here */
                        /* set PBC_DC_INFO bit (aka SC[4]) in pbc_flags */
-                       pbc |= (!!(sc5 & 0x10)) << PBC_DC_INFO_SHIFT;
+                       pbc |= (ib_is_sc5(sc5) << PBC_DC_INFO_SHIFT);
 
                        if (unlikely(hfi1_dbg_fault_opcode(qp, opcode, false)))
                                pbc = hfi1_fault_tx(qp, opcode, pbc);
@@ -999,7 +999,7 @@ int hfi1_verbs_send_pio(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
                u8 opcode = get_opcode(&tx->phdr.hdr);
 
                /* set PBC_DC_INFO bit (aka SC[4]) in pbc_flags */
-               pbc |= (!!(sc5 & 0x10)) << PBC_DC_INFO_SHIFT;
+               pbc |= (ib_is_sc5(sc5) << PBC_DC_INFO_SHIFT);
                if (unlikely(hfi1_dbg_fault_opcode(qp, opcode, false)))
                        pbc = hfi1_fault_tx(qp, opcode, pbc);
                pbc = create_pbc(ppd, pbc, qp->srate_mbps, vl, plen);
index 5519f31f043a45b086e098407c4a15a2a7d02ca4..c124d515f7d545951dfc105d95ba1794a987e2bf 100644 (file)
@@ -193,8 +193,12 @@ static inline void put_ib_ateth_compare(u64 val, struct ib_atomic_eth *ateth)
 #define IB_LNH_MASK            3
 #define IB_SC_MASK             0xf
 #define IB_SC_SHIFT            12
+#define IB_SC5_MASK            0x10
 #define IB_SL_MASK             0xf
 #define IB_SL_SHIFT            4
+#define IB_SL_SHIFT            4
+#define IB_LVER_MASK   0xf
+#define IB_LVER_SHIFT  8
 
 static inline u8 ib_get_lnh(struct ib_header *hdr)
 {
@@ -206,6 +210,11 @@ static inline u8 ib_get_sc(struct ib_header *hdr)
        return ((be16_to_cpu(hdr->lrh[0]) >> IB_SC_SHIFT) & IB_SC_MASK);
 }
 
+static inline bool ib_is_sc5(u16 sc5)
+{
+       return !!(sc5 & IB_SC5_MASK);
+}
+
 static inline u8 ib_get_sl(struct ib_header *hdr)
 {
        return ((be16_to_cpu(hdr->lrh[0]) >> IB_SL_SHIFT) & IB_SL_MASK);
@@ -221,6 +230,27 @@ static inline u16 ib_get_slid(struct ib_header *hdr)
        return (be16_to_cpu(hdr->lrh[3]));
 }
 
+static inline u8 ib_get_lver(struct ib_header *hdr)
+{
+       return (u8)((be16_to_cpu(hdr->lrh[0]) >> IB_LVER_SHIFT) &
+                  IB_LVER_MASK);
+}
+
+static inline u16 ib_get_len(struct ib_header *hdr)
+{
+       return (u16)(be16_to_cpu(hdr->lrh[2]));
+}
+
+static inline u32 ib_get_qkey(struct ib_other_headers *ohdr)
+{
+       return be32_to_cpu(ohdr->u.ud.deth[0]);
+}
+
+static inline u32 ib_get_sqpn(struct ib_other_headers *ohdr)
+{
+       return ((be32_to_cpu(ohdr->u.ud.deth[1])) & IB_QPN_MASK);
+}
+
 /*
  * BTH
  */
@@ -229,6 +259,14 @@ static inline u16 ib_get_slid(struct ib_header *hdr)
 #define IB_BTH_PAD_MASK        3
 #define IB_BTH_PKEY_MASK       0xffff
 #define IB_BTH_PAD_SHIFT       20
+#define IB_BTH_A_MASK          1
+#define IB_BTH_A_SHIFT         31
+#define IB_BTH_M_MASK          1
+#define IB_BTH_M_SHIFT         22
+#define IB_BTH_SE_MASK         1
+#define IB_BTH_SE_SHIFT        23
+#define IB_BTH_TVER_MASK       0xf
+#define IB_BTH_TVER_SHIFT      16
 
 static inline u8 ib_bth_get_pad(struct ib_other_headers *ohdr)
 {
@@ -247,4 +285,50 @@ static inline u8 ib_bth_get_opcode(struct ib_other_headers *ohdr)
                   IB_BTH_OPCODE_MASK);
 }
 
+static inline u8 ib_bth_get_ackreq(struct ib_other_headers *ohdr)
+{
+       return (u8)((be32_to_cpu(ohdr->bth[2]) >> IB_BTH_A_SHIFT) &
+                  IB_BTH_A_MASK);
+}
+
+static inline u8 ib_bth_get_migreq(struct ib_other_headers *ohdr)
+{
+       return (u8)((be32_to_cpu(ohdr->bth[0]) >> IB_BTH_M_SHIFT) &
+                   IB_BTH_M_MASK);
+}
+
+static inline u8 ib_bth_get_se(struct ib_other_headers *ohdr)
+{
+       return (u8)((be32_to_cpu(ohdr->bth[0]) >> IB_BTH_SE_SHIFT) &
+                   IB_BTH_SE_MASK);
+}
+
+static inline u32 ib_bth_get_psn(struct ib_other_headers *ohdr)
+{
+       return (u32)(be32_to_cpu(ohdr->bth[2]));
+}
+
+static inline u32 ib_bth_get_qpn(struct ib_other_headers *ohdr)
+{
+       return (u32)((be32_to_cpu(ohdr->bth[1])) & IB_QPN_MASK);
+}
+
+static inline u8 ib_bth_get_becn(struct ib_other_headers *ohdr)
+{
+       return (u8)((be32_to_cpu(ohdr->bth[1]) >> IB_BECN_SHIFT) &
+                    IB_BECN_MASK);
+}
+
+static inline u8 ib_bth_get_fecn(struct ib_other_headers *ohdr)
+{
+       return (u8)((be32_to_cpu(ohdr->bth[1]) >> IB_FECN_SHIFT) &
+                   IB_FECN_MASK);
+}
+
+static inline u8 ib_bth_get_tver(struct ib_other_headers *ohdr)
+{
+       return (u8)((be32_to_cpu(ohdr->bth[0]) >> IB_BTH_TVER_SHIFT)  &
+                   IB_BTH_TVER_MASK);
+}
+
 #endif                          /* IB_HDRS_H */
index ba8314ec576844ddb7148364617a768c81acd90f..8f1ce4e27bbd9f1ea5b435574b51047b1d9d1a3b 100644 (file)
@@ -664,6 +664,8 @@ union rdma_network_hdr {
        };
 };
 
+#define IB_QPN_MASK            0xFFFFFF
+
 enum {
        IB_MULTICAST_QPN = 0xffffff
 };
index be6472e5b06bd1ed1117e928e9b3d44748dfbfeb..13f43b3527a83b3d328ea0162e1aa39184549ba2 100644 (file)
@@ -396,7 +396,7 @@ struct rvt_srq {
 #define RVT_QPNMAP_ENTRIES          (RVT_QPN_MAX / PAGE_SIZE / BITS_PER_BYTE)
 #define RVT_BITS_PER_PAGE           (PAGE_SIZE * BITS_PER_BYTE)
 #define RVT_BITS_PER_PAGE_MASK      (RVT_BITS_PER_PAGE - 1)
-#define RVT_QPN_MASK               0xFFFFFF
+#define RVT_QPN_MASK               IB_QPN_MASK
 
 /*
  * QPN-map pages start out as NULL, they get allocated upon