IB/rdmavt, hfi1, qib: Modify check_ah() to account for extended LIDs
authorDon Hiatt <don.hiatt@intel.com>
Fri, 4 Aug 2017 20:53:51 +0000 (13:53 -0700)
committerDoug Ledford <dledford@redhat.com>
Tue, 22 Aug 2017 18:22:36 +0000 (14:22 -0400)
rvt_check_ah() delegates lid verification to underlying
driver. Underlying driver uses different conditions to
check for dlid depending on whether the device supports
extended LIDs

Reviewed-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: Dasaratharaman Chandramouli <dasaratharaman.chandramouli@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/common.h
drivers/infiniband/hw/hfi1/mad.c
drivers/infiniband/hw/hfi1/verbs.c
drivers/infiniband/hw/qib/qib_verbs.c
drivers/infiniband/sw/rdmavt/ah.c
drivers/infiniband/sw/rdmavt/qp.c
include/rdma/opa_addr.h

index ba9ab971ced942352fd2ab27bba9ae97c275e81f..aa416ef93c1a5e3d2a85634e93bdf512cde96616 100644 (file)
@@ -333,15 +333,6 @@ struct diag_pkt {
 
 #define DEFAULT_P_KEY LIM_MGMT_P_KEY
 
-/**
- * 0xF8 - 4 bits of multicast range and 1 bit for collective range
- * Example: For 24 bit LID space,
- * Multicast range: 0xF00000 to 0xF7FFFF
- * Collective range: 0xF80000 to 0xFFFFFE
- */
-#define HFI1_MCAST_NR 0x4 /* Number of top bits set */
-#define HFI1_COLLECTIVE_NR 0x1 /* Number of bits after MCAST_NR */
-
 #define HFI1_PSM_IOC_BASE_SEQ 0x0
 
 static inline __u64 rhf_to_cpu(const __le32 *rbuf)
index cd1f6f841f3416f548c6d0e72f3199bf7eb88398..21fadb4b510c58d966cc83791fce88d4a800eb52 100644 (file)
@@ -46,6 +46,7 @@
  */
 
 #include <linux/net.h>
+#include <rdma/opa_addr.h>
 #define OPA_NUM_PKEY_BLOCKS_PER_SMP (OPA_SMP_DR_DATA_SIZE \
                        / (OPA_PARTITION_TABLE_BLK_SIZE * sizeof(u16)))
 
@@ -905,8 +906,8 @@ static int __subn_get_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data,
        pi->buffer_units = cpu_to_be32(buffer_units);
 
        pi->opa_cap_mask = cpu_to_be16(ibp->rvp.port_cap3_flags);
-       pi->collectivemask_multicastmask = ((HFI1_COLLECTIVE_NR & 0x7)
-                                           << 3 | (HFI1_MCAST_NR & 0x7));
+       pi->collectivemask_multicastmask = ((OPA_COLLECTIVE_NR & 0x7)
+                                           << 3 | (OPA_MCAST_NR & 0x7));
 
        /* HFI supports a replay buffer 128 LTPs in size */
        pi->replay_depth.buffer = 0x80;
index c88c03c115552b586a9d14e82c1e9407dddfdbc7..97ca42beb0238c50d2dce057c6f10dbe7c533baf 100644 (file)
@@ -53,6 +53,7 @@
 #include <linux/rculist.h>
 #include <linux/mm.h>
 #include <linux/vmalloc.h>
+#include <rdma/opa_addr.h>
 
 #include "hfi.h"
 #include "common.h"
@@ -1461,6 +1462,10 @@ static int hfi1_check_ah(struct ib_device *ibdev, struct rdma_ah_attr *ah_attr)
        struct hfi1_devdata *dd;
        u8 sc5;
 
+       if (hfi1_check_mcast(rdma_ah_get_dlid(ah_attr)) &&
+           !(rdma_ah_get_ah_flags(ah_attr) & IB_AH_GRH))
+               return -EINVAL;
+
        /* test the mapping for validity */
        ibp = to_iport(ibdev, rdma_ah_get_port_num(ah_attr));
        ppd = ppd_from_ibp(ibp);
index ac42dce7e2817a37570d184c4c0aa3b1216e969d..9d92aeb8d9a12e885a66d25fc7c8fa199a773b7f 100644 (file)
@@ -1341,6 +1341,15 @@ int qib_check_ah(struct ib_device *ibdev, struct rdma_ah_attr *ah_attr)
        if (rdma_ah_get_sl(ah_attr) > 15)
                return -EINVAL;
 
+       if (rdma_ah_get_dlid(ah_attr) == 0)
+               return -EINVAL;
+       if (rdma_ah_get_dlid(ah_attr) >=
+               be16_to_cpu(IB_MULTICAST_LID_BASE) &&
+           rdma_ah_get_dlid(ah_attr) !=
+               be16_to_cpu(IB_LID_PERMISSIVE) &&
+           !(rdma_ah_get_ah_flags(ah_attr) & IB_AH_GRH))
+               return -EINVAL;
+
        return 0;
 }
 
index a96d4aa80ae87fe2447cb8b9f0066866ce87e042..ba3639a0d77cf3977663d7a5fad0131b60932739 100644 (file)
@@ -66,8 +66,6 @@ int rvt_check_ah(struct ib_device *ibdev,
        int port_num = rdma_ah_get_port_num(ah_attr);
        struct ib_port_attr port_attr;
        struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
-       enum rdma_link_layer link = rdma_port_get_link_layer(ibdev, port_num);
-       u32 dlid = rdma_ah_get_dlid(ah_attr);
        u8 ah_flags = rdma_ah_get_ah_flags(ah_attr);
        u8 static_rate = rdma_ah_get_static_rate(ah_attr);
 
@@ -83,14 +81,6 @@ int rvt_check_ah(struct ib_device *ibdev,
        if ((ah_flags & IB_AH_GRH) &&
            rdma_ah_read_grh(ah_attr)->sgid_index >= port_attr.gid_tbl_len)
                return -EINVAL;
-       if (link != IB_LINK_LAYER_ETHERNET) {
-               if (dlid == 0)
-                       return -EINVAL;
-               if (dlid >= be16_to_cpu(IB_MULTICAST_LID_BASE) &&
-                   dlid != be16_to_cpu(IB_LID_PERMISSIVE) &&
-                   !(ah_flags & IB_AH_GRH))
-                       return -EINVAL;
-       }
        if (rdi->driver_f.check_ah)
                return rdi->driver_f.check_ah(ibdev, ah_attr);
        return 0;
index eb0c3d60c584f10f0b5eb2373b6668eb16cd2c16..6f6525d24a2f13ea1395ab4e71cb5162fff8a1b7 100644 (file)
@@ -52,6 +52,7 @@
 #include <linux/slab.h>
 #include <rdma/ib_verbs.h>
 #include <rdma/ib_hdrs.h>
+#include <rdma/opa_addr.h>
 #include "qp.h"
 #include "vt.h"
 #include "trace.h"
@@ -1066,6 +1067,7 @@ int rvt_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
        int mig = 0;
        int pmtu = 0; /* for gcc warning only */
        enum rdma_link_layer link;
+       int opa_ah;
 
        link = rdma_port_get_link_layer(ibqp->device, qp->port_num);
 
@@ -1076,6 +1078,7 @@ int rvt_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
        cur_state = attr_mask & IB_QP_CUR_STATE ?
                attr->cur_qp_state : qp->state;
        new_state = attr_mask & IB_QP_STATE ? attr->qp_state : cur_state;
+       opa_ah = rdma_cap_opa_ah(ibqp->device, qp->port_num);
 
        if (!ib_modify_qp_is_ok(cur_state, new_state, ibqp->qp_type,
                                attr_mask, link))
@@ -1086,17 +1089,31 @@ int rvt_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
                goto inval;
 
        if (attr_mask & IB_QP_AV) {
-               if (rdma_ah_get_dlid(&attr->ah_attr) >=
-                   be16_to_cpu(IB_MULTICAST_LID_BASE))
-                       goto inval;
+               if (opa_ah) {
+                       if (rdma_ah_get_dlid(&attr->ah_attr) >=
+                               opa_get_mcast_base(OPA_MCAST_NR))
+                               goto inval;
+               } else {
+                       if (rdma_ah_get_dlid(&attr->ah_attr) >=
+                               be16_to_cpu(IB_MULTICAST_LID_BASE))
+                               goto inval;
+               }
+
                if (rvt_check_ah(qp->ibqp.device, &attr->ah_attr))
                        goto inval;
        }
 
        if (attr_mask & IB_QP_ALT_PATH) {
-               if (rdma_ah_get_dlid(&attr->alt_ah_attr) >=
-                   be16_to_cpu(IB_MULTICAST_LID_BASE))
-                       goto inval;
+               if (opa_ah) {
+                       if (rdma_ah_get_dlid(&attr->alt_ah_attr) >=
+                               opa_get_mcast_base(OPA_MCAST_NR))
+                               goto inval;
+               } else {
+                       if (rdma_ah_get_dlid(&attr->alt_ah_attr) >=
+                               be16_to_cpu(IB_MULTICAST_LID_BASE))
+                               goto inval;
+               }
+
                if (rvt_check_ah(qp->ibqp.device, &attr->alt_ah_attr))
                        goto inval;
                if (attr->alt_pkey_index >= rvt_get_npkeys(rdi))
index 9b5e642cf55086cd8b6fe8518865712a89b92410..8d3ad4ecbea1e328472631dcd0b58e5233039074 100644 (file)
 #ifndef OPA_ADDR_H
 #define OPA_ADDR_H
 
+#include <rdma/opa_smi.h>
+
 #define        OPA_SPECIAL_OUI         (0x00066AULL)
 #define OPA_MAKE_ID(x)          (cpu_to_be64(OPA_SPECIAL_OUI << 40 | (x)))
 #define OPA_TO_IB_UCAST_LID(x) (((x) >= be16_to_cpu(IB_MULTICAST_LID_BASE)) \
                                ? 0 : x)
+/**
+ * 0xF8 - 4 bits of multicast range and 1 bit for collective range
+ * Example: For 24 bit LID space,
+ * Multicast range: 0xF00000 to 0xF7FFFF
+ * Collective range: 0xF80000 to 0xFFFFFE
+ */
+#define OPA_MCAST_NR 0x4 /* Number of top bits set */
+#define OPA_COLLECTIVE_NR 0x1 /* Number of bits after MCAST_NR */
+
 /**
  * ib_is_opa_gid: Returns true if the top 24 bits of the gid
  * contains the OPA_STL_OUI identifier. This identifies that
@@ -95,4 +106,11 @@ static inline bool opa_is_extended_lid(u32 dlid, u32 slid)
        else
                return false;
 }
+
+/* Get multicast lid base */
+static inline u32 opa_get_mcast_base(u32 nr_top_bits)
+{
+       return (be32_to_cpu(OPA_LID_PERMISSIVE) << (32 - nr_top_bits));
+}
+
 #endif /* OPA_ADDR_H */