All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] RDMA/mlx5: Make mlx5 device work with ib_device_get_by_netdev
@ 2022-10-16  6:19 Zhu Yanjun
  2022-10-18  8:24 ` Leon Romanovsky
  0 siblings, 1 reply; 7+ messages in thread
From: Zhu Yanjun @ 2022-10-16  6:19 UTC (permalink / raw)
  To: leon, jgg, linux-rdma, yanjun.zhu, yanjun.zhu

From: Zhu Yanjun <yanjun.zhu@linux.dev>

Before mlx5 ib device is registered, the function ib_device_set_netdev
is not called to map the mlx5 ib device with the related net device.

As such, when the function ib_device_get_by_netdev is called to get ib
device, NULL is returned.

Other ib devices, such as irdma, rxe and so on, the function
ib_device_get_by_netdev can get ib device from the related net device.

Signed-off-by: Zhu Yanjun <yanjun.zhu@linux.dev>
---
 drivers/infiniband/hw/mlx5/main.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
index 883d7c60143e..6899c3f73509 100644
--- a/drivers/infiniband/hw/mlx5/main.c
+++ b/drivers/infiniband/hw/mlx5/main.c
@@ -168,6 +168,7 @@ static int mlx5_netdev_event(struct notifier_block *this,
 	u32 port_num = roce->native_port_num;
 	struct mlx5_core_dev *mdev;
 	struct mlx5_ib_dev *ibdev;
+	int ret = 0;
 
 	ibdev = roce->dev;
 	mdev = mlx5_ib_get_native_port_mdev(ibdev, port_num, NULL);
@@ -183,6 +184,14 @@ static int mlx5_netdev_event(struct notifier_block *this,
 		if (ndev->dev.parent == mdev->device)
 			roce->netdev = ndev;
 		write_unlock(&roce->netdev_lock);
+		if (ndev->dev.parent == mdev->device) {
+			ret = ib_device_set_netdev(&ibdev->ib_dev, ndev, port_num);
+			if (ret) {
+				pr_warn("func: %s, error: %d\n", __func__, ret);
+				goto done;
+			}
+		}
+
 		break;
 
 	case NETDEV_UNREGISTER:
@@ -191,6 +200,15 @@ static int mlx5_netdev_event(struct notifier_block *this,
 		if (roce->netdev == ndev)
 			roce->netdev = NULL;
 		write_unlock(&roce->netdev_lock);
+
+		if (roce->netdev == ndev) {
+			ret = ib_device_set_netdev(&ibdev->ib_dev, NULL, port_num);
+			if (ret) {
+				pr_warn("func: %s, error: %d\n", __func__, ret);
+				goto done;
+			}
+		}
+
 		break;
 
 	case NETDEV_CHANGE:
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-10-19 14:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-16  6:19 [PATCH 1/1] RDMA/mlx5: Make mlx5 device work with ib_device_get_by_netdev Zhu Yanjun
2022-10-18  8:24 ` Leon Romanovsky
2022-10-18 14:19   ` Jason Gunthorpe
2022-10-19  8:56   ` yanjun.zhu
2022-10-19  9:08   ` yanjun.zhu
2022-10-19 11:55     ` Jason Gunthorpe
2022-10-19 14:30       ` Yanjun Zhu

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.