[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20201109151814.15040-6-kgraul@linux.ibm.com>
Date: Mon, 9 Nov 2020 16:18:04 +0100
From: Karsten Graul <kgraul@...ux.ibm.com>
To: davem@...emloft.net
Cc: netdev@...r.kernel.org, linux-s390@...r.kernel.org,
hca@...ux.ibm.com, raspl@...ux.ibm.com
Subject: [PATCH net-next v4 05/15] net/smc: Add diagnostic information to smc ib-device
From: Guvenc Gulce <guvenc@...ux.ibm.com>
During smc ib-device creation, add network device name to smc
ib-device structure. Register for netdevice name changes and
update ib-device accordingly. This is needed for diagnostic purposes.
Signed-off-by: Guvenc Gulce <guvenc@...ux.ibm.com>
Signed-off-by: Karsten Graul <kgraul@...ux.ibm.com>
---
net/smc/smc_ib.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
net/smc/smc_ib.h | 2 ++
net/smc/smc_pnet.c | 3 +++
3 files changed, 50 insertions(+)
diff --git a/net/smc/smc_ib.c b/net/smc/smc_ib.c
index 1c314dbdc7fa..300cca9296be 100644
--- a/net/smc/smc_ib.c
+++ b/net/smc/smc_ib.c
@@ -557,6 +557,50 @@ static void smc_ib_cleanup_per_ibdev(struct smc_ib_device *smcibdev)
static struct ib_client smc_ib_client;
+static void smc_copy_netdev_name(struct smc_ib_device *smcibdev, int port)
+{
+ struct ib_device *ibdev = smcibdev->ibdev;
+ struct net_device *ndev;
+
+ if (!ibdev->ops.get_netdev)
+ return;
+ ndev = ibdev->ops.get_netdev(ibdev, port + 1);
+ if (ndev) {
+ snprintf(smcibdev->netdev[port],
+ sizeof(smcibdev->netdev[port]),
+ "%s", ndev->name);
+ dev_put(ndev);
+ }
+}
+
+void smc_ib_ndev_name_change(struct net_device *ndev)
+{
+ struct smc_ib_device *smcibdev;
+ struct ib_device *libdev;
+ struct net_device *lndev;
+ u8 port_cnt;
+ int i;
+
+ mutex_lock(&smc_ib_devices.mutex);
+ list_for_each_entry(smcibdev, &smc_ib_devices.list, list) {
+ port_cnt = smcibdev->ibdev->phys_port_cnt;
+ for (i = 0; i < min_t(size_t, port_cnt, SMC_MAX_PORTS); i++) {
+ libdev = smcibdev->ibdev;
+ if (!libdev->ops.get_netdev)
+ continue;
+ lndev = libdev->ops.get_netdev(libdev, i + 1);
+ if (lndev)
+ dev_put(lndev);
+ if (lndev != ndev)
+ continue;
+ snprintf(smcibdev->netdev[i],
+ sizeof(smcibdev->netdev[i]),
+ "%s", ndev->name);
+ }
+ }
+ mutex_unlock(&smc_ib_devices.mutex);
+}
+
/* callback function for ib_register_client() */
static int smc_ib_add_dev(struct ib_device *ibdev)
{
@@ -596,6 +640,7 @@ static int smc_ib_add_dev(struct ib_device *ibdev)
if (smc_pnetid_by_dev_port(ibdev->dev.parent, i,
smcibdev->pnetid[i]))
smc_pnetid_by_table_ib(smcibdev, i + 1);
+ smc_copy_netdev_name(smcibdev, i);
pr_warn_ratelimited("smc: ib device %s port %d has pnetid "
"%.16s%s\n",
smcibdev->ibdev->name, i + 1,
diff --git a/net/smc/smc_ib.h b/net/smc/smc_ib.h
index 3b85360a473b..5319496adea0 100644
--- a/net/smc/smc_ib.h
+++ b/net/smc/smc_ib.h
@@ -55,11 +55,13 @@ struct smc_ib_device { /* ib-device infos for smc */
struct mutex mutex; /* protect dev setup+cleanup */
atomic_t lnk_cnt_by_port[SMC_MAX_PORTS];
/* number of links per port */
+ char netdev[SMC_MAX_PORTS][IFNAMSIZ];/* ndev names */
};
struct smc_buf_desc;
struct smc_link;
+void smc_ib_ndev_name_change(struct net_device *ndev);
int smc_ib_register_client(void) __init;
void smc_ib_unregister_client(void);
bool smc_ib_port_active(struct smc_ib_device *smcibdev, u8 ibport);
diff --git a/net/smc/smc_pnet.c b/net/smc/smc_pnet.c
index f3c18b991d35..b0f40d73afd6 100644
--- a/net/smc/smc_pnet.c
+++ b/net/smc/smc_pnet.c
@@ -828,6 +828,9 @@ static int smc_pnet_netdev_event(struct notifier_block *this,
case NETDEV_UNREGISTER:
smc_pnet_remove_by_ndev(event_dev);
return NOTIFY_OK;
+ case NETDEV_CHANGENAME:
+ smc_ib_ndev_name_change(event_dev);
+ return NOTIFY_OK;
case NETDEV_REGISTER:
smc_pnet_add_by_ndev(event_dev);
return NOTIFY_OK;
--
2.17.1
Powered by blists - more mailing lists