]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
IB/mlx4: Fix possible vl/sl field mismatch in LRH header in QP1 packets
authorJack Morgenstein <jackm@dev.mellanox.co.il>
Mon, 12 Sep 2016 16:16:21 +0000 (19:16 +0300)
committerChuck Anderson <chuck.anderson@oracle.com>
Tue, 15 Aug 2017 04:20:56 +0000 (21:20 -0700)
In MLX qp packets, the LRH (built by the driver) has both a VL field
and an SL field. When building a QP1 packet, the VL field should
reflect the SLtoVL mapping and not arbitrarily contain zero (as is
done now). This bug causes credit problems in IB switches at
high rates of QP1 packets.

The fix is to cache the SL to VL mapping in the driver, and look up
the VL mapped to the SL provided in the send request when sending
QP1 packets.

For FW versions which support generating a port_management_config_change
event with subtype sl-to-vl-table-change, the driver uses that event
to update its sl-to-vl mapping cache.  Otherwise, the driver snoops
incoming SMP mads to update the cache.

There remains the case where the FW is running in secure-host mode
(so no QP0 packets are delivered to the driver), and the FW does not
generate the sl2vl mapping change event. To support this case, the
driver updates (via querying the FW) its sl2vl mapping cache when
running in secure-host mode when it receives either a Port Up event
or a client-reregister event (where the port is still up, but there
may have been an opensm failover).
OpenSM modifies the sl2vl mapping before Port Up and Client-reregister
events occur, so if there is a mapping change the driver's cache will
be properly updated.

Fixes: 225c7b1feef1 ("IB/mlx4: Add a driver Mellanox ConnectX InfiniBand adapters")
Signed-off-by: Jack Morgenstein <jackm@dev.mellanox.co.il>
Signed-off-by: Leon Romanovsky <leon@kernel.org>
Signed-off-by: Doug Ledford <dledford@redhat.com>
[ Original fix ported from upstream commit fd10ed8 modified with
  changes from merge commit b9044ac and modifications in
  dump_dev_cap_flags2() likely to be made upstream for correctness
  (and verified with private communication with Mellanox) ]

Orabug: 26198210

Signed-off-by: Mukesh Kacker <mukesh.kacker@oracle.com>
Reviewed-by: HÃ¥kon Bugge <haakon.bugge@oracle.com>
drivers/infiniband/hw/mlx4/mad.c
drivers/infiniband/hw/mlx4/main.c
drivers/infiniband/hw/mlx4/mlx4_ib.h
drivers/infiniband/hw/mlx4/qp.c
drivers/net/ethernet/mellanox/mlx4/fw.c
include/linux/mlx4/device.h

index 4a225042dfa089e7e7a70841466881dcacad4281..6ed6cf87614e21f1134d8fe5f6a45bed585e0f89 100644 (file)
@@ -236,6 +236,8 @@ static void smp_snoop(struct ib_device *ibdev, u8 port_num, struct ib_mad *mad,
            mad->mad_hdr.method == IB_MGMT_METHOD_SET)
                switch (mad->mad_hdr.attr_id) {
                case IB_SMP_ATTR_PORT_INFO:
+                       if (dev->dev->caps.flags & MLX4_DEV_CAP_FLAG_PORT_MNG_CHG_EV)
+                               return;
                        pinfo = (struct ib_port_info *) ((struct ib_smp *) mad)->data;
                        lid = be16_to_cpu(pinfo->lid);
 
@@ -251,6 +253,8 @@ static void smp_snoop(struct ib_device *ibdev, u8 port_num, struct ib_mad *mad,
                        break;
 
                case IB_SMP_ATTR_PKEY_TABLE:
+                       if (dev->dev->caps.flags & MLX4_DEV_CAP_FLAG_PORT_MNG_CHG_EV)
+                               return;
                        if (!mlx4_is_mfunc(dev->dev)) {
                                mlx4_ib_dispatch_event(dev, port_num,
                                                       IB_EVENT_PKEY_CHANGE);
@@ -287,6 +291,8 @@ static void smp_snoop(struct ib_device *ibdev, u8 port_num, struct ib_mad *mad,
                        break;
 
                case IB_SMP_ATTR_GUID_INFO:
+                       if (dev->dev->caps.flags & MLX4_DEV_CAP_FLAG_PORT_MNG_CHG_EV)
+                               return;
                        /* paravirtualized master's guid is guid 0 -- does not change */
                        if (!mlx4_is_master(dev->dev))
                                mlx4_ib_dispatch_event(dev, port_num,
@@ -302,6 +308,26 @@ static void smp_snoop(struct ib_device *ibdev, u8 port_num, struct ib_mad *mad,
                        }
                        break;
 
+               case IB_SMP_ATTR_SL_TO_VL_TABLE:
+                       /* cache sl to vl mapping changes for use in
+                        * filling QP1 LRH VL field when sending packets
+                        */
+                       if (dev->dev->caps.flags & MLX4_DEV_CAP_FLAG_PORT_MNG_CHG_EV &&
+                           dev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_SL_TO_VL_CHANGE_EVENT)
+                               return;
+                       if (!mlx4_is_slave(dev->dev)) {
+                               union sl2vl_tbl_to_u64 sl2vl64;
+                               int jj;
+
+                               for (jj = 0; jj < 8; jj++) {
+                                       sl2vl64.sl8[jj] = ((struct ib_smp *)mad)->data[jj];
+                                       pr_debug("port %u, sl2vl[%d] = %02x\n",
+                                                port_num, jj, sl2vl64.sl8[jj]);
+                               }
+                               atomic64_set(&dev->sl2vl[port_num - 1], sl2vl64.sl64);
+                       }
+                       break;
+
                default:
                        break;
                }
@@ -793,8 +819,7 @@ static int ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
                return IB_MAD_RESULT_FAILURE;
 
        if (!out_mad->mad_hdr.status) {
-               if (!(to_mdev(ibdev)->dev->caps.flags & MLX4_DEV_CAP_FLAG_PORT_MNG_CHG_EV))
-                       smp_snoop(ibdev, port_num, in_mad, prev_lid);
+               smp_snoop(ibdev, port_num, in_mad, prev_lid);
                /* slaves get node desc from FW */
                if (!mlx4_is_slave(to_mdev(ibdev)->dev))
                        node_desc_override(ibdev, out_mad);
@@ -989,6 +1014,23 @@ static void handle_client_rereg_event(struct mlx4_ib_dev *dev, u8 port_num)
                                                    MLX4_EQ_PORT_INFO_CLIENT_REREG_MASK);
                }
        }
+
+       /* Update the sl to vl table from inside client rereg
+        * only if in secure-host mode (snooping is not possible)
+        * and the sl-to-vl change event is not generated by FW.
+        */
+       if (!mlx4_is_slave(dev->dev) &&
+           dev->dev->flags & MLX4_FLAG_SECURE_HOST &&
+           !(dev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_SL_TO_VL_CHANGE_EVENT)) {
+               if (mlx4_is_master(dev->dev))
+                       /* already in work queue from mlx4_ib_event queueing
+                        * mlx4_handle_port_mgmt_change_event, which calls
+                        * this procedure. Therefore, call sl2vl_update directly.
+                        */
+                       mlx4_ib_sl2vl_update(dev, port_num);
+               else
+                       mlx4_sched_ib_sl2vl_update_work(dev, port_num);
+       }
        mlx4_ib_dispatch_event(dev, port_num, IB_EVENT_CLIENT_REREGISTER);
 }
 
@@ -1107,6 +1149,24 @@ void handle_port_mgmt_change_event(struct work_struct *work)
                        handle_slaves_guid_change(dev, port, tbl_block, change_bitmap);
                }
                break;
+
+       case MLX4_DEV_PMC_SUBTYPE_SL_TO_VL_MAP:
+               /* cache sl to vl mapping changes for use in
+                * filling QP1 LRH VL field when sending packets
+                */
+               if (!mlx4_is_slave(dev->dev)) {
+                       union sl2vl_tbl_to_u64 sl2vl64;
+                       int jj;
+
+                       for (jj = 0; jj < 8; jj++) {
+                               sl2vl64.sl8[jj] =
+                                       eqe->event.port_mgmt_change.params.sl2vl_tbl_change_info.sl2vl_table[jj];
+                               pr_debug("port %u, sl2vl[%d] = %02x\n",
+                                        port, jj, sl2vl64.sl8[jj]);
+                       }
+                       atomic64_set(&dev->sl2vl[port - 1], sl2vl64.sl64);
+               }
+               break;
        default:
                pr_warn("Unsupported subtype 0x%x for "
                        "Port Management Change event\n", eqe->subtype);
index 0aefa10afd304db240064ea22fa45a4b7537532d..90c5f9eb89ddf27875ae750a747c1bdd98f321de 100644 (file)
@@ -506,6 +506,66 @@ static int mlx4_ib_query_gid(struct ib_device *ibdev, u8 port, int index,
                return iboe_query_gid(ibdev, port, index, gid);
 }
 
+static int mlx4_ib_query_sl2vl(struct ib_device *ibdev, u8 port, u64 *sl2vl_tbl)
+{
+       union sl2vl_tbl_to_u64 sl2vl64;
+       struct ib_smp *in_mad  = NULL;
+       struct ib_smp *out_mad = NULL;
+       int mad_ifc_flags = MLX4_MAD_IFC_IGNORE_KEYS;
+       int err = -ENOMEM;
+       int jj;
+
+       if (mlx4_is_slave(to_mdev(ibdev)->dev)) {
+               *sl2vl_tbl = 0;
+               return 0;
+       }
+
+       in_mad  = kzalloc(sizeof(*in_mad), GFP_KERNEL);
+       out_mad = kmalloc(sizeof(*out_mad), GFP_KERNEL);
+       if (!in_mad || !out_mad)
+               goto out;
+
+       init_query_mad(in_mad);
+       in_mad->attr_id  = IB_SMP_ATTR_SL_TO_VL_TABLE;
+       in_mad->attr_mod = 0;
+
+       if (mlx4_is_mfunc(to_mdev(ibdev)->dev))
+               mad_ifc_flags |= MLX4_MAD_IFC_NET_VIEW;
+
+       err = mlx4_MAD_IFC(to_mdev(ibdev), mad_ifc_flags, port, NULL, NULL,
+                          in_mad, out_mad);
+       if (err)
+               goto out;
+
+       for (jj = 0; jj < 8; jj++)
+               sl2vl64.sl8[jj] = ((struct ib_smp *)out_mad)->data[jj];
+       *sl2vl_tbl = sl2vl64.sl64;
+
+out:
+       kfree(in_mad);
+       kfree(out_mad);
+       return err;
+}
+
+static void mlx4_init_sl2vl_tbl(struct mlx4_ib_dev *mdev)
+{
+       u64 sl2vl;
+       int i;
+       int err;
+
+       for (i = 1; i <= mdev->dev->caps.num_ports; i++) {
+               if (mdev->dev->caps.port_type[i] == MLX4_PORT_TYPE_ETH)
+                       continue;
+               err = mlx4_ib_query_sl2vl(&mdev->ib_dev, i, &sl2vl);
+               if (err) {
+                       pr_err("Unable to get default sl to vl mapping for port %d.  Using all zeroes (%d)\n",
+                              i, err);
+                       sl2vl = 0;
+               }
+               atomic64_set(&mdev->sl2vl[i - 1], sl2vl);
+       }
+}
+
 int __mlx4_ib_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
                         u16 *pkey, int netw_view)
 {
@@ -2525,6 +2585,7 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
 
        if (init_node_data(ibdev))
                goto err_map;
+       mlx4_init_sl2vl_tbl(ibdev);
 
        num_req_counters = mlx4_is_bonded(dev) ? 1 : ibdev->num_ports;
        for (i = 0; i < num_req_counters; ++i) {
@@ -2965,6 +3026,47 @@ static void handle_bonded_port_state_event(struct work_struct *work)
        ib_dispatch_event(&ibev);
 }
 
+void mlx4_ib_sl2vl_update(struct mlx4_ib_dev *mdev, int port)
+{
+       u64 sl2vl;
+       int err;
+
+       err = mlx4_ib_query_sl2vl(&mdev->ib_dev, port, &sl2vl);
+       if (err) {
+               pr_err("Unable to get current sl to vl mapping for port %d.  Using all zeroes (%d)\n",
+                      port, err);
+               sl2vl = 0;
+       }
+       atomic64_set(&mdev->sl2vl[port - 1], sl2vl);
+}
+
+static void ib_sl2vl_update_work(struct work_struct *work)
+{
+       struct ib_event_work *ew = container_of(work, struct ib_event_work, work);
+       struct mlx4_ib_dev *mdev = ew->ib_dev;
+       int port = ew->port;
+
+       mlx4_ib_sl2vl_update(mdev, port);
+
+       kfree(ew);
+}
+
+void mlx4_sched_ib_sl2vl_update_work(struct mlx4_ib_dev *ibdev,
+                                    int port)
+{
+       struct ib_event_work *ew;
+
+       ew = kmalloc(sizeof(*ew), GFP_ATOMIC);
+       if (ew) {
+               INIT_WORK(&ew->work, ib_sl2vl_update_work);
+               ew->port = port;
+               ew->ib_dev = ibdev;
+               queue_work(wq, &ew->work);
+       } else {
+               pr_err("failed to allocate memory for sl2vl update work\n");
+       }
+}
+
 static void mlx4_ib_event(struct mlx4_dev *dev, void *ibdev_ptr,
                          enum mlx4_dev_event event, unsigned long param)
 {
@@ -2995,10 +3097,14 @@ static void mlx4_ib_event(struct mlx4_dev *dev, void *ibdev_ptr,
        case MLX4_DEV_EVENT_PORT_UP:
                if (p > ibdev->num_ports)
                        return;
-               if (mlx4_is_master(dev) &&
+               if (!mlx4_is_slave(dev) &&
                    rdma_port_get_link_layer(&ibdev->ib_dev, p) ==
                        IB_LINK_LAYER_INFINIBAND) {
-                       mlx4_ib_invalidate_all_guid_record(ibdev, p);
+                       if (mlx4_is_master(dev))
+                               mlx4_ib_invalidate_all_guid_record(ibdev, p);
+                       if (ibdev->dev->flags & MLX4_FLAG_SECURE_HOST &&
+                           !(ibdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_SL_TO_VL_CHANGE_EVENT))
+                               mlx4_sched_ib_sl2vl_update_work(ibdev, p);
                }
                mlx4_ib_info((struct ib_device *) ibdev_ptr,
                             "Port %d logical link is up\n", p);
index 5c50b4bbe0875946ff62b7a2324d5628a90a5f8b..bc260d4f08fcd89ff597318eb9c9035dad9ae387 100644 (file)
@@ -526,6 +526,7 @@ struct mlx4_ib_dev {
        struct ib_mad_agent    *send_agent[MLX4_MAX_PORTS][2];
        struct ib_ah           *sm_ah[MLX4_MAX_PORTS];
        spinlock_t              sm_lock;
+       atomic64_t              sl2vl[MLX4_MAX_PORTS];
        struct mlx4_ib_sriov    sriov;
 
        struct mutex            cap_mask_mutex;
@@ -556,6 +557,7 @@ struct ib_event_work {
        struct work_struct      work;
        struct mlx4_ib_dev      *ib_dev;
        struct mlx4_eqe         ib_eqe;
+       int                     port;
 };
 
 struct mlx4_ib_qp_tunnel_init_attr {
@@ -888,4 +890,9 @@ int mlx4_ib_rereg_user_mr(struct ib_mr *mr, int flags,
                          int mr_access_flags, struct ib_pd *pd,
                          struct ib_udata *udata);
 
+void mlx4_sched_ib_sl2vl_update_work(struct mlx4_ib_dev *ibdev,
+                                    int port);
+
+void mlx4_ib_sl2vl_update(struct mlx4_ib_dev *mdev, int port);
+
 #endif /* MLX4_IB_H */
index e92b55bb117d262fd044476ee51434360d315832..e223d2578564bbbf84e10e68115aa2ab557ea648 100644 (file)
@@ -2149,6 +2149,22 @@ static int build_sriov_qp0_header(struct mlx4_ib_sqp *sqp,
        return 0;
 }
 
+static u8 sl_to_vl(struct mlx4_ib_dev *dev, u8 sl, int port_num)
+{
+       union sl2vl_tbl_to_u64 tmp_vltab;
+       u8 vl;
+
+       if (sl > 15)
+               return 0xf;
+       tmp_vltab.sl64 = atomic64_read(&dev->sl2vl[port_num - 1]);
+       vl = tmp_vltab.sl8[sl >> 1];
+       if (sl & 1)
+               vl &= 0x0f;
+       else
+               vl >>= 4;
+       return vl;
+}
+
 static void mlx4_u64_to_smac(u8 *dst_mac, u64 src_mac)
 {
        int i;
@@ -2305,7 +2321,12 @@ static int build_mlx_header(struct mlx4_ib_sqp *sqp, struct ib_send_wr *wr,
                        sqp->ud_header.vlan.tag = cpu_to_be16(vlan | pcp);
                }
        } else {
-               sqp->ud_header.lrh.virtual_lane    = !sqp->qp.ibqp.qp_num ? 15 : 0;
+               sqp->ud_header.lrh.virtual_lane    = !sqp->qp.ibqp.qp_num ? 15 :
+                                                       sl_to_vl(to_mdev(ib_dev),
+                                                                sqp->ud_header.lrh.service_level,
+                                                                sqp->qp.port);
+               if (sqp->qp.ibqp.qp_num && sqp->ud_header.lrh.virtual_lane == 15)
+                       return -EINVAL;
                if (sqp->ud_header.lrh.destination_lid == IB_LID_PERMISSIVE)
                        sqp->ud_header.lrh.source_lid = IB_LID_PERMISSIVE;
        }
index c9fc7ffb16cc480dff29d6cd5f714528ec7bea7b..ec8d5e0b9efdab32364cecb19b50e27102227b6f 100644 (file)
@@ -154,6 +154,7 @@ static void dump_dev_cap_flags2(struct mlx4_dev *dev, u64 flags)
                [26] = "Port ETS Scheduler support",
                [27] = "Port beacon support",
                [28] = "RX-ALL support",
+               [37] = "sl to vl mapping table change event support",
        };
        int i;
 
@@ -686,6 +687,7 @@ int mlx4_QUERY_DEV_CAP(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap)
 #define QUERY_DEV_CAP_FLOW_STEERING_IPOIB_OFFSET       0x74
 #define QUERY_DEV_CAP_FLOW_STEERING_RANGE_EN_OFFSET    0x76
 #define QUERY_DEV_CAP_FLOW_STEERING_MAX_QP_OFFSET      0x77
+#define QUERY_DEV_CAP_SL2VL_EVENT_OFFSET       0x78
 #define QUERY_DEV_CAP_CQ_EQ_CACHE_LINE_STRIDE  0x7a
 #define QUERY_DEV_CAP_ECN_QCN_VER_OFFSET       0x7b
 #define QUERY_DEV_CAP_RDMARC_ENTRY_SZ_OFFSET   0x80
@@ -799,6 +801,9 @@ int mlx4_QUERY_DEV_CAP(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap)
                dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_DMFS_IPOIB;
        MLX4_GET(field, outbox, QUERY_DEV_CAP_FLOW_STEERING_MAX_QP_OFFSET);
        dev_cap->fs_max_num_qp_per_entry = field;
+       MLX4_GET(field, outbox, QUERY_DEV_CAP_SL2VL_EVENT_OFFSET);
+       if (field & (1 << 5))
+               dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_SL_TO_VL_CHANGE_EVENT;
        MLX4_GET(field, outbox, QUERY_DEV_CAP_ECN_QCN_VER_OFFSET);
        if (field & 0x1)
                dev_cap->flags2 |= MLX4_DEV_CAP_FLAG2_QCN;
@@ -2610,7 +2615,6 @@ static int mlx4_check_smp_firewall_active(struct mlx4_dev *dev,
 int mlx4_config_mad_demux(struct mlx4_dev *dev)
 {
        struct mlx4_cmd_mailbox *mailbox;
-       int secure_host_active;
        int err;
        u32 get_attr_mask;
 
@@ -2634,7 +2638,8 @@ int mlx4_config_mad_demux(struct mlx4_dev *dev)
                goto out;
        }
 
-       secure_host_active = mlx4_check_smp_firewall_active(dev, mailbox);
+       if (mlx4_check_smp_firewall_active(dev, mailbox))
+               dev->flags |= MLX4_FLAG_SECURE_HOST;
 
        /* Config hca to handle pi and ni queries if not already handling */
        MLX4_GET(get_attr_mask, mailbox->buf,
@@ -2674,7 +2679,7 @@ int mlx4_config_mad_demux(struct mlx4_dev *dev)
        else
                mlx4_warn(dev, "sm port and node info query - offload failed\n");
 
-       if (secure_host_active)
+       if (dev->flags & MLX4_FLAG_SECURE_HOST)
                mlx4_warn(dev, "HCA operating in secure-host mode. SMP firewall activated.\n");
 out:
        mlx4_free_cmd_mailbox(dev, mailbox);
index 80ee7f1a80f60aea9648712ca11653b34c926d42..bb9cebbdf4053255cb89f294cc8edbff57a1a8d0 100644 (file)
@@ -68,7 +68,8 @@ enum {
        MLX4_FLAG_SLAVE         = 1 << 3,
        MLX4_FLAG_SRIOV         = 1 << 4,
        MLX4_FLAG_OLD_REG_MAC   = 1 << 6,
-       MLX4_FLAG_BONDED        = 1 << 7
+       MLX4_FLAG_BONDED        = 1 << 7,
+       MLX4_FLAG_SECURE_HOST   = 1 << 8,
 };
 
 enum {
@@ -211,6 +212,7 @@ enum {
        MLX4_DEV_CAP_FLAG2_ETS_CFG              = 1LL <<  26,
        MLX4_DEV_CAP_FLAG2_PORT_BEACON          = 1LL <<  27,
        MLX4_DEV_CAP_FLAG2_IGNORE_FCS           = 1LL <<  28,
+       MLX4_DEV_CAP_FLAG2_SL_TO_VL_CHANGE_EVENT = 1ULL << 37,
 };
 
 enum {
@@ -429,6 +431,7 @@ enum {
        MLX4_DEV_PMC_SUBTYPE_GUID_INFO   = 0x14,
        MLX4_DEV_PMC_SUBTYPE_PORT_INFO   = 0x15,
        MLX4_DEV_PMC_SUBTYPE_PKEY_TABLE  = 0x16,
+       MLX4_DEV_PMC_SUBTYPE_SL_TO_VL_MAP = 0x17,
 };
 
 /* Port mgmt change event handling */
@@ -440,6 +443,11 @@ enum {
        MLX4_EQ_PORT_INFO_MSTR_SM_SL_CHANGE_MASK        = 1 << 4,
 };
 
+union sl2vl_tbl_to_u64 {
+       u8      sl8[8];
+       u64     sl64;
+};
+
 enum {
        MLX4_DEVICE_STATE_UP                    = 1 << 0,
        MLX4_DEVICE_STATE_INTERNAL_ERROR        = 1 << 1,
@@ -902,6 +910,9 @@ struct mlx4_eqe {
                                        __be32 block_ptr;
                                        __be32 tbl_entries_mask;
                                } __packed tbl_change_info;
+                               struct {
+                                       u8 sl2vl_table[8];
+                               } __packed sl2vl_tbl_change_info;
                        } params;
                } __packed port_mgmt_change;
                struct {