All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: Doug Ledford <dledford@redhat.com>, Jason Gunthorpe <jgg@nvidia.com>
Cc: Parav Pandit <parav@nvidia.com>, linux-rdma@vger.kernel.org
Subject: [PATCH rdma-next 06/10] IB/mlx5: Use rdma_for_each_port for port iteration
Date: Wed, 27 Jan 2021 17:00:06 +0200	[thread overview]
Message-ID: <20210127150010.1876121-7-leon@kernel.org> (raw)
In-Reply-To: <20210127150010.1876121-1-leon@kernel.org>

From: Parav Pandit <parav@nvidia.com>

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.

Signed-off-by: Parav Pandit <parav@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 drivers/infiniband/hw/mlx5/mad.c     |  2 +-
 drivers/infiniband/hw/mlx5/main.c    | 15 ++++++++-------
 drivers/infiniband/hw/mlx5/mlx5_ib.h |  2 +-
 3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/infiniband/hw/mlx5/mad.c b/drivers/infiniband/hw/mlx5/mad.c
index cdb47a00e516..652c6ccf1881 100644
--- a/drivers/infiniband/hw/mlx5/mad.c
+++ b/drivers/infiniband/hw/mlx5/mad.c
@@ -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;
diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
index 742e565309f8..ad7bb37e501d 100644
--- a/drivers/infiniband/hw/mlx5/main.c
+++ b/drivers/infiniband/hw/mlx5/main.c
@@ -2982,9 +2982,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);
 }

@@ -3905,6 +3905,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);
@@ -3930,12 +3936,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;

 	mutex_init(&dev->cap_mask_mutex);
 	INIT_LIST_HEAD(&dev->qp_list);
diff --git a/drivers/infiniband/hw/mlx5/mlx5_ib.h b/drivers/infiniband/hw/mlx5/mlx5_ib.h
index 69c45adb2518..88cc26e008fc 100644
--- a/drivers/infiniband/hw/mlx5/mlx5_ib.h
+++ b/drivers/infiniband/hw/mlx5/mlx5_ib.h
@@ -1291,7 +1291,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,
--
2.29.2


  parent reply	other threads:[~2021-01-27 15:33 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-27 15:00 [PATCH rdma-next 00/10] Various cleanups Leon Romanovsky
2021-01-27 15:00 ` [PATCH rdma-next 01/10] IB/mlx5: Move mlx5_port_caps from mlx5_core_dev to mlx5_ib_dev Leon Romanovsky
2021-01-27 15:00 ` [PATCH rdma-next 02/10] IB/mlx5: Avoid calling query device for reading pkey table length Leon Romanovsky
2021-02-01 10:19   ` Leon Romanovsky
2021-01-27 15:00 ` [PATCH rdma-next 03/10] IB/mlx5: Support default partition key for representor port Leon Romanovsky
2021-01-27 15:00 ` [PATCH rdma-next 04/10] IB/mlx5: Improve query port " Leon Romanovsky
2021-01-27 15:00 ` [PATCH rdma-next 05/10] RDMA/core: Introduce and use API to read port immutable data Leon Romanovsky
2021-02-02 16:50   ` Jason Gunthorpe
2021-02-02 18:05     ` Parav Pandit
2021-02-02 18:14       ` Jason Gunthorpe
2021-02-02 19:00         ` Parav Pandit
2021-01-27 15:00 ` Leon Romanovsky [this message]
2021-01-27 15:00 ` [PATCH rdma-next 07/10] IB/mlx5: Return appropriate error code instead of ENOMEM Leon Romanovsky
2021-02-02 15:21   ` Jason Gunthorpe
2021-02-02 16:01     ` Parav Pandit
2021-02-02 18:57       ` Leon Romanovsky
2021-01-27 15:00 ` [PATCH rdma-next 08/10] IB/cm: Avoid a loop when device has 255 ports Leon Romanovsky
2021-01-27 15:00 ` [PATCH rdma-next 09/10] IB/mlx4: Use port iterator and validation APIs Leon Romanovsky
2021-01-27 15:00 ` [PATCH rdma-next 10/10] IB/core: Use valid port number to check link layer Leon Romanovsky
2021-02-02 23:35 ` [PATCH rdma-next 00/10] Various cleanups Jason Gunthorpe
2021-02-03  5:47   ` Leon Romanovsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210127150010.1876121-7-leon@kernel.org \
    --to=leon@kernel.org \
    --cc=dledford@redhat.com \
    --cc=jgg@nvidia.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=parav@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.