Skip to content

Commit 1317965

Browse files
paravmellanoxjgunthorpe
authored andcommitted
IB/mlx5: Use rdma_for_each_port for port iteration
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/[email protected] Signed-off-by: Parav Pandit <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 7416790 commit 1317965

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

drivers/infiniband/hw/mlx5/mad.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ int mlx5_ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
279279
return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY;
280280
}
281281

282-
int mlx5_query_ext_port_caps(struct mlx5_ib_dev *dev, u8 port)
282+
int mlx5_query_ext_port_caps(struct mlx5_ib_dev *dev, unsigned int port)
283283
{
284284
struct ib_smp *in_mad = NULL;
285285
struct ib_smp *out_mad = NULL;

drivers/infiniband/hw/mlx5/main.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2958,9 +2958,9 @@ static int set_has_smi_cap(struct mlx5_ib_dev *dev)
29582958

29592959
static void get_ext_port_caps(struct mlx5_ib_dev *dev)
29602960
{
2961-
int port;
2961+
unsigned int port;
29622962

2963-
for (port = 1; port <= dev->num_ports; port++)
2963+
rdma_for_each_port (&dev->ib_dev, port)
29642964
mlx5_query_ext_port_caps(dev, port);
29652965
}
29662966

@@ -3881,6 +3881,12 @@ static int mlx5_ib_stage_init_init(struct mlx5_ib_dev *dev)
38813881
int err;
38823882
int i;
38833883

3884+
dev->ib_dev.node_type = RDMA_NODE_IB_CA;
3885+
dev->ib_dev.local_dma_lkey = 0 /* not supported for now */;
3886+
dev->ib_dev.phys_port_cnt = dev->num_ports;
3887+
dev->ib_dev.dev.parent = mdev->device;
3888+
dev->ib_dev.lag_flags = RDMA_LAG_FLAGS_HASH_ALL_SLAVES;
3889+
38843890
for (i = 0; i < dev->num_ports; i++) {
38853891
spin_lock_init(&dev->port[i].mp.mpi_lock);
38863892
rwlock_init(&dev->port[i].roce.netdev_lock);
@@ -3906,12 +3912,7 @@ static int mlx5_ib_stage_init_init(struct mlx5_ib_dev *dev)
39063912
if (mlx5_use_mad_ifc(dev))
39073913
get_ext_port_caps(dev);
39083914

3909-
dev->ib_dev.node_type = RDMA_NODE_IB_CA;
3910-
dev->ib_dev.local_dma_lkey = 0 /* not supported for now */;
3911-
dev->ib_dev.phys_port_cnt = dev->num_ports;
39123915
dev->ib_dev.num_comp_vectors = mlx5_comp_vectors_count(mdev);
3913-
dev->ib_dev.dev.parent = mdev->device;
3914-
dev->ib_dev.lag_flags = RDMA_LAG_FLAGS_HASH_ALL_SLAVES;
39153916

39163917
err = init_srcu_struct(&dev->odp_srcu);
39173918
if (err)

drivers/infiniband/hw/mlx5/mlx5_ib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ int mlx5_ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
12991299
size_t *out_mad_size, u16 *out_mad_pkey_index);
13001300
int mlx5_ib_alloc_xrcd(struct ib_xrcd *xrcd, struct ib_udata *udata);
13011301
int mlx5_ib_dealloc_xrcd(struct ib_xrcd *xrcd, struct ib_udata *udata);
1302-
int mlx5_query_ext_port_caps(struct mlx5_ib_dev *dev, u8 port);
1302+
int mlx5_query_ext_port_caps(struct mlx5_ib_dev *dev, unsigned int port);
13031303
int mlx5_query_mad_ifc_system_image_guid(struct ib_device *ibdev,
13041304
__be64 *sys_image_guid);
13051305
int mlx5_query_mad_ifc_max_pkeys(struct ib_device *ibdev,

0 commit comments

Comments
 (0)