IB/mlx5: Use rdma_for_each_port for port iteration
authorParav Pandit <parav@nvidia.com>
Wed, 3 Feb 2021 13:01:33 +0000 (15:01 +0200)
committerJason Gunthorpe <jgg@nvidia.com>
Fri, 5 Feb 2021 16:06:01 +0000 (12:06 -0400)
Instead of open coding the loop for port iteration, use rdma_for_each_port
macro provided by core.

To use such macro, early initialization of phys_port_cnt is needed.
Hence, initialize such constant early enough in the init stage.

Whichever functions are called with port using rdma_for_each_port(),
convert their port type from u8 to unsigned int to match the core API.

Link: https://lore.kernel.org/r/20210203130133.4057329-6-leon@kernel.org
Signed-off-by: Parav Pandit <parav@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/infiniband/hw/mlx5/mad.c
drivers/infiniband/hw/mlx5/main.c
drivers/infiniband/hw/mlx5/mlx5_ib.h

index cdb47a00e516be840746dbabdbc0c1f2b43d2bf8..652c6ccf188144700768b71f85011be01851d670 100644 (file)
@@ -279,7 +279,7 @@ int mlx5_ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
        return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY;
 }
 
-int mlx5_query_ext_port_caps(struct mlx5_ib_dev *dev, u8 port)
+int mlx5_query_ext_port_caps(struct mlx5_ib_dev *dev, unsigned int port)
 {
        struct ib_smp *in_mad  = NULL;
        struct ib_smp *out_mad = NULL;
index 1e1e3edcb1d53f46b8a94f31893864f91823008c..ce4a9eba53f9af5951cad8626145bbf510712ea0 100644 (file)
@@ -2958,9 +2958,9 @@ static int set_has_smi_cap(struct mlx5_ib_dev *dev)
 
 static void get_ext_port_caps(struct mlx5_ib_dev *dev)
 {
-       int port;
+       unsigned int port;
 
-       for (port = 1; port <= dev->num_ports; port++)
+       rdma_for_each_port (&dev->ib_dev, port)
                mlx5_query_ext_port_caps(dev, port);
 }
 
@@ -3881,6 +3881,12 @@ static int mlx5_ib_stage_init_init(struct mlx5_ib_dev *dev)
        int err;
        int i;
 
+       dev->ib_dev.node_type = RDMA_NODE_IB_CA;
+       dev->ib_dev.local_dma_lkey = 0 /* not supported for now */;
+       dev->ib_dev.phys_port_cnt = dev->num_ports;
+       dev->ib_dev.dev.parent = mdev->device;
+       dev->ib_dev.lag_flags = RDMA_LAG_FLAGS_HASH_ALL_SLAVES;
+
        for (i = 0; i < dev->num_ports; i++) {
                spin_lock_init(&dev->port[i].mp.mpi_lock);
                rwlock_init(&dev->port[i].roce.netdev_lock);
@@ -3906,12 +3912,7 @@ static int mlx5_ib_stage_init_init(struct mlx5_ib_dev *dev)
        if (mlx5_use_mad_ifc(dev))
                get_ext_port_caps(dev);
 
-       dev->ib_dev.node_type           = RDMA_NODE_IB_CA;
-       dev->ib_dev.local_dma_lkey      = 0 /* not supported for now */;
-       dev->ib_dev.phys_port_cnt       = dev->num_ports;
        dev->ib_dev.num_comp_vectors    = mlx5_comp_vectors_count(mdev);
-       dev->ib_dev.dev.parent          = mdev->device;
-       dev->ib_dev.lag_flags           = RDMA_LAG_FLAGS_HASH_ALL_SLAVES;
 
        err = init_srcu_struct(&dev->odp_srcu);
        if (err)
index 0f567d570230bb8996cda6fc76b33ee7e95da2af..ab52083634e63e957237f76934d1efa5b2bf6c25 100644 (file)
@@ -1299,7 +1299,7 @@ int mlx5_ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
                        size_t *out_mad_size, u16 *out_mad_pkey_index);
 int mlx5_ib_alloc_xrcd(struct ib_xrcd *xrcd, struct ib_udata *udata);
 int mlx5_ib_dealloc_xrcd(struct ib_xrcd *xrcd, struct ib_udata *udata);
-int mlx5_query_ext_port_caps(struct mlx5_ib_dev *dev, u8 port);
+int mlx5_query_ext_port_caps(struct mlx5_ib_dev *dev, unsigned int port);
 int mlx5_query_mad_ifc_system_image_guid(struct ib_device *ibdev,
                                         __be64 *sys_image_guid);
 int mlx5_query_mad_ifc_max_pkeys(struct ib_device *ibdev,