Add OPA extended LID support
authorHiatt, Don <don.hiatt@intel.com>
Mon, 14 Aug 2017 18:17:43 +0000 (14:17 -0400)
committerDoug Ledford <dledford@redhat.com>
Fri, 18 Aug 2017 18:47:37 +0000 (14:47 -0400)
This patch series primarily increases sizes of variables that hold
lid values from 16 to 32 bits. Additionally, it adds a check in
the IB mad stack to verify a properly formatted MAD when OPA
extended LIDs are used.

Signed-off-by: Don Hiatt <don.hiatt@intel.com>
Reviewed-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
drivers/infiniband/core/cm.c
drivers/infiniband/core/user_mad.c
drivers/infiniband/core/uverbs_cmd.c
drivers/infiniband/hw/hfi1/mad.c
drivers/infiniband/hw/mlx4/alias_GUID.c
drivers/infiniband/hw/mlx4/mad.c
drivers/infiniband/hw/mlx5/mad.c
drivers/infiniband/hw/mthca/mthca_cmd.c
drivers/infiniband/hw/mthca/mthca_mad.c
drivers/infiniband/sw/rdmavt/cq.c
include/rdma/ib_verbs.h

index 7a389697e2ec5111444b7bd4c1f157e2e566a0df..fa3b0a428195efc95dff93451e143b7baaa9af0c 100644 (file)
@@ -1770,7 +1770,7 @@ static void cm_process_routed_req(struct cm_req_msg *req_msg, struct ib_wc *wc)
 {
        if (!cm_req_get_primary_subnet_local(req_msg)) {
                if (req_msg->primary_local_lid == IB_LID_PERMISSIVE) {
-                       req_msg->primary_local_lid = ib_slid_be16(wc->slid);
+                       req_msg->primary_local_lid = ib_lid_be16(wc->slid);
                        cm_req_set_primary_sl(req_msg, wc->sl);
                }
 
@@ -1780,7 +1780,7 @@ static void cm_process_routed_req(struct cm_req_msg *req_msg, struct ib_wc *wc)
 
        if (!cm_req_get_alt_subnet_local(req_msg)) {
                if (req_msg->alt_local_lid == IB_LID_PERMISSIVE) {
-                       req_msg->alt_local_lid = ib_slid_be16(wc->slid);
+                       req_msg->alt_local_lid = ib_lid_be16(wc->slid);
                        cm_req_set_alt_sl(req_msg, wc->sl);
                }
 
index ff3c67a7aaad2b9163936c8bbb25c9b709228142..c1696e6084b2b12b2a671799a891ef0d0f04f3d1 100644 (file)
@@ -229,7 +229,7 @@ static void recv_handler(struct ib_mad_agent *agent,
        packet->mad.hdr.status     = 0;
        packet->mad.hdr.length     = hdr_size(file) + mad_recv_wc->mad_len;
        packet->mad.hdr.qpn        = cpu_to_be32(mad_recv_wc->wc->src_qp);
-       packet->mad.hdr.lid        = ib_slid_be16(mad_recv_wc->wc->slid);
+       packet->mad.hdr.lid        = ib_lid_be16(mad_recv_wc->wc->slid);
        packet->mad.hdr.sl         = mad_recv_wc->wc->sl;
        packet->mad.hdr.path_bits  = mad_recv_wc->wc->dlid_path_bits;
        packet->mad.hdr.pkey_index = mad_recv_wc->wc->pkey_index;
index 39a0f1dc84e4172c75b7087d66b5fd8a3b521801..a21881e22bad6bbf7df0e0dce526e3e6646a93fd 100644 (file)
@@ -275,12 +275,13 @@ ssize_t ib_uverbs_query_port(struct ib_uverbs_file *file,
        resp.bad_pkey_cntr   = attr.bad_pkey_cntr;
        resp.qkey_viol_cntr  = attr.qkey_viol_cntr;
        resp.pkey_tbl_len    = attr.pkey_tbl_len;
+
        if (rdma_cap_opa_ah(ib_dev, cmd.port_num)) {
-               resp.lid  = OPA_TO_IB_UCAST_LID(attr.lid);
+               resp.lid     = OPA_TO_IB_UCAST_LID(attr.lid);
                resp.sm_lid  = OPA_TO_IB_UCAST_LID(attr.sm_lid);
        } else {
-               resp.lid     = (u16)attr.lid;
-               resp.sm_lid  = (u16)attr.sm_lid;
+               resp.lid     = ib_lid_cpu16(attr.lid);
+               resp.sm_lid  = ib_lid_cpu16(attr.sm_lid);
        }
        resp.lmc             = attr.lmc;
        resp.max_vl_num      = attr.max_vl_num;
@@ -1206,9 +1207,9 @@ static int copy_wc_to_user(struct ib_device *ib_dev, void __user *dest,
        tmp.wc_flags            = wc->wc_flags;
        tmp.pkey_index          = wc->pkey_index;
        if (rdma_cap_opa_ah(ib_dev, wc->port_num))
-               tmp.slid  = OPA_TO_IB_UCAST_LID(wc->slid);
+               tmp.slid        = OPA_TO_IB_UCAST_LID(wc->slid);
        else
-               tmp.slid  = ib_slid_cpu16(wc->slid);
+               tmp.slid        = ib_lid_cpu16(wc->slid);
        tmp.sl                  = wc->sl;
        tmp.dlid_path_bits      = wc->dlid_path_bits;
        tmp.port_num            = wc->port_num;
index 8daa3a5f7e95a60252c497cc8ff875686e04116c..11be4d19e60705d544304b97df0d6144d0832d77 100644 (file)
@@ -4216,7 +4216,7 @@ static int opa_local_smp_check(struct hfi1_ibport *ibp,
                               const struct ib_wc *in_wc)
 {
        struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
-       u16 slid = ib_slid_cpu16(in_wc->slid);
+       u16 slid = ib_lid_cpu16(in_wc->slid);
        u16 pkey;
 
        if (in_wc->pkey_index >= ARRAY_SIZE(ppd->pkeys))
index 5a897b0106a93e51754513a4aaaee57b51efb40e..0e4f60cfc59d6e77c2bd57de216324ee9b74dcbb 100644 (file)
@@ -528,7 +528,7 @@ static int set_guid_rec(struct ib_device *ibdev,
 
        memset(&guid_info_rec, 0, sizeof (struct ib_sa_guidinfo_rec));
 
-       guid_info_rec.lid = cpu_to_be16((u16)attr.lid);
+       guid_info_rec.lid = ib_lid_be16(attr.lid);
        guid_info_rec.block_num = index;
 
        memcpy(guid_info_rec.guid_info_list, rec_det->all_recs,
index 04fb44e7699ea2e342d15f0b66d8dcac100ef039..0793a21d76f4c5bf82526e5cbc4ec5e5606f90b5 100644 (file)
@@ -169,7 +169,7 @@ int mlx4_MAD_IFC(struct mlx4_ib_dev *dev, int mad_ifc_flags,
 
                op_modifier |= 0x4;
 
-               in_modifier |= ib_slid_cpu16(in_wc->slid) << 16;
+               in_modifier |= ib_lid_cpu16(in_wc->slid) << 16;
        }
 
        err = mlx4_cmd_box(dev->dev, inmailbox->dma, outmailbox->dma, in_modifier,
@@ -625,7 +625,7 @@ int mlx4_ib_send_to_slave(struct mlx4_ib_dev *dev, int slave, u8 port,
                memcpy((char *)&tun_mad->hdr.slid_mac_47_32, &(wc->smac[4]), 2);
        } else {
                tun_mad->hdr.sl_vid = cpu_to_be16(((u16)(wc->sl)) << 12);
-               tun_mad->hdr.slid_mac_47_32 = ib_slid_be16(wc->slid);
+               tun_mad->hdr.slid_mac_47_32 = ib_lid_be16(wc->slid);
        }
 
        ib_dma_sync_single_for_device(&dev->ib_dev,
@@ -826,7 +826,7 @@ static int ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
                }
        }
 
-       slid = in_wc ? ib_slid_cpu16(in_wc->slid) : be16_to_cpu(IB_LID_PERMISSIVE);
+       slid = in_wc ? ib_lid_cpu16(in_wc->slid) : be16_to_cpu(IB_LID_PERMISSIVE);
 
        if (in_mad->mad_hdr.method == IB_MGMT_METHOD_TRAP && slid == 0) {
                forward_trap(to_mdev(ibdev), port_num, in_mad);
@@ -860,7 +860,7 @@ static int ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
            in_mad->mad_hdr.method == IB_MGMT_METHOD_SET &&
            in_mad->mad_hdr.attr_id == IB_SMP_ATTR_PORT_INFO &&
            !ib_query_port(ibdev, port_num, &pattr))
-               prev_lid = (u16)pattr.lid;
+               prev_lid = ib_lid_cpu16(pattr.lid);
 
        err = mlx4_MAD_IFC(to_mdev(ibdev),
                           (mad_flags & IB_MAD_IGNORE_MKEY ? MLX4_MAD_IFC_IGNORE_MKEY : 0) |
index cd2264ac88ae9d12b34901aa234f25c53018dce2..18cfe5bf0fa385251916a431052d0cd2d149a095 100644 (file)
@@ -78,7 +78,7 @@ static int process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
        u16 slid;
        int err;
 
-       slid = in_wc ? ib_slid_cpu16(in_wc->slid) : be16_to_cpu(IB_LID_PERMISSIVE);
+       slid = in_wc ? ib_lid_cpu16(in_wc->slid) : be16_to_cpu(IB_LID_PERMISSIVE);
 
        if (in_mad->mad_hdr.method == IB_MGMT_METHOD_TRAP && slid == 0)
                return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
index e19ae0b9b439e640c132a5bf2dd4519e868bcd04..d0f062fc2a4b519c54112464e359643eaccb733c 100644 (file)
@@ -1921,7 +1921,7 @@ int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
                        (in_wc->wc_flags & IB_WC_GRH ? 0x80 : 0);
                MTHCA_PUT(inbox, val,               MAD_IFC_G_PATH_OFFSET);
 
-               MTHCA_PUT(inbox, ib_slid_cpu16(in_wc->slid), MAD_IFC_RLID_OFFSET);
+               MTHCA_PUT(inbox, ib_lid_cpu16(in_wc->slid), MAD_IFC_RLID_OFFSET);
                MTHCA_PUT(inbox, in_wc->pkey_index, MAD_IFC_PKEY_OFFSET);
 
                if (in_grh)
@@ -1929,7 +1929,7 @@ int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
 
                op_modifier |= 0x4;
 
-               in_modifier |= ib_slid_cpu16(in_wc->slid) << 16;
+               in_modifier |= ib_lid_cpu16(in_wc->slid) << 16;
        }
 
        err = mthca_cmd_box(dev, inmailbox->dma, outmailbox->dma,
index a9caadab22cfa6dd9129beeff101259d08b9f264..093f7755c8434ce66e24e2a0817e4b4554849c41 100644 (file)
@@ -205,7 +205,7 @@ int mthca_process_mad(struct ib_device *ibdev,
                      u16 *out_mad_pkey_index)
 {
        int err;
-       u16 slid = in_wc ? ib_slid_cpu16(in_wc->slid) : be16_to_cpu(IB_LID_PERMISSIVE);
+       u16 slid = in_wc ? ib_lid_cpu16(in_wc->slid) : be16_to_cpu(IB_LID_PERMISSIVE);
        u16 prev_lid = 0;
        struct ib_port_attr pattr;
        const struct ib_mad *in_mad = (const struct ib_mad *)in;
@@ -256,7 +256,7 @@ int mthca_process_mad(struct ib_device *ibdev,
            in_mad->mad_hdr.method == IB_MGMT_METHOD_SET &&
            in_mad->mad_hdr.attr_id == IB_SMP_ATTR_PORT_INFO &&
            !ib_query_port(ibdev, port_num, &pattr))
-               prev_lid = (u16)pattr.lid;
+               prev_lid = ib_lid_cpu16(pattr.lid);
 
        err = mthca_MAD_IFC(to_mdev(ibdev),
                            mad_flags & IB_MAD_IGNORE_MKEY,
index 0335a3df74d52c372ec06ccb786693fda735c2e4..97d71e49c092f4e820efc4ebe23ec2bbdc411cbd 100644 (file)
@@ -107,7 +107,7 @@ void rvt_cq_enter(struct rvt_cq *cq, struct ib_wc *entry, bool solicited)
                wc->uqueue[head].src_qp = entry->src_qp;
                wc->uqueue[head].wc_flags = entry->wc_flags;
                wc->uqueue[head].pkey_index = entry->pkey_index;
-               wc->uqueue[head].slid = ib_slid_cpu16(entry->slid);
+               wc->uqueue[head].slid = ib_lid_cpu16(entry->slid);
                wc->uqueue[head].sl = entry->sl;
                wc->uqueue[head].dlid_path_bits = entry->dlid_path_bits;
                wc->uqueue[head].port_num = entry->port_num;
index 4db4ad56ace69c2bf4b940e5a1000a7ba6925abe..70a183179224156eb93f736e64012cb6ab00256d 100644 (file)
@@ -3724,16 +3724,30 @@ static inline enum rdma_ah_attr_type rdma_ah_find_type(struct ib_device *dev,
                return RDMA_AH_ATTR_TYPE_IB;
 }
 
-/* Return slid in 16bit CPU encoding */
-static inline u16 ib_slid_cpu16(u32 slid)
+/**
+ * ib_lid_cpu16 - Return lid in 16bit CPU encoding.
+ *     In the current implementation the only way to get
+ *     get the 32bit lid is from other sources for OPA.
+ *     For IB, lids will always be 16bits so cast the
+ *     value accordingly.
+ *
+ * @lid: A 32bit LID
+ */
+static inline u16 ib_lid_cpu16(u32 lid)
 {
-       return (u16)slid;
+       WARN_ON_ONCE(lid & 0xFFFF0000);
+       return (u16)lid;
 }
 
-/* Return slid in 16bit BE encoding */
-static inline u16 ib_slid_be16(u32 slid)
+/**
+ * ib_lid_be16 - Return lid in 16bit BE encoding.
+ *
+ * @lid: A 32bit LID
+ */
+static inline __be16 ib_lid_be16(u32 lid)
 {
-       return cpu_to_be16((u16)slid);
+       WARN_ON_ONCE(lid & 0xFFFF0000);
+       return cpu_to_be16((u16)lid);
 }
 
 /**