diff mbox series

[v6,net-next,16/19] ionic: Add netdev-event handling

Message ID 20190829182720.68419-17-snelson@pensando.io
State Changes Requested
Delegated to: David Miller
Headers show
Series ionic: Add ionic driver | expand

Commit Message

Shannon Nelson Aug. 29, 2019, 6:27 p.m. UTC
When the netdev gets a new name from userland, pass that name
down to the NIC for internal tracking.

Signed-off-by: Shannon Nelson <snelson@pensando.io>
---
 drivers/net/ethernet/pensando/ionic/ionic.h   |  2 +
 .../net/ethernet/pensando/ionic/ionic_lif.c   | 62 +++++++++++++++++++
 2 files changed, 64 insertions(+)

Comments

Jakub Kicinski Aug. 29, 2019, 11:37 p.m. UTC | #1
On Thu, 29 Aug 2019 11:27:17 -0700, Shannon Nelson wrote:
> When the netdev gets a new name from userland, pass that name
> down to the NIC for internal tracking.
> 
> Signed-off-by: Shannon Nelson <snelson@pensando.io>

There is a precedent in ACPI for telling the FW what OS is running but
how is the interface name useful for the firmware I can't really tell.
Shannon Nelson Aug. 30, 2019, 9:36 p.m. UTC | #2
On 8/29/19 4:37 PM, Jakub Kicinski wrote:
> On Thu, 29 Aug 2019 11:27:17 -0700, Shannon Nelson wrote:
>> When the netdev gets a new name from userland, pass that name
>> down to the NIC for internal tracking.
>>
>> Signed-off-by: Shannon Nelson <snelson@pensando.io>
> There is a precedent in ACPI for telling the FW what OS is running but
> how is the interface name useful for the firmware I can't really tell.
It is so we can correlate the host's interface name with the internal 
port data for internal logging.

sln
Jakub Kicinski Aug. 30, 2019, 10:24 p.m. UTC | #3
On Fri, 30 Aug 2019 14:36:23 -0700, Shannon Nelson wrote:
> On 8/29/19 4:37 PM, Jakub Kicinski wrote:
> > On Thu, 29 Aug 2019 11:27:17 -0700, Shannon Nelson wrote:  
> >> When the netdev gets a new name from userland, pass that name
> >> down to the NIC for internal tracking.
> >>
> >> Signed-off-by: Shannon Nelson <snelson@pensando.io>  
> > There is a precedent in ACPI for telling the FW what OS is running but
> > how is the interface name useful for the firmware I can't really tell.  
> It is so we can correlate the host's interface name with the internal 
> port data for internal logging.

Okay.. honestly brings back too many bad memories of arguing with
engineers who spent their lives building middle boxes..

I just hope this won't spread.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/pensando/ionic/ionic.h b/drivers/net/ethernet/pensando/ionic/ionic.h
index 8269ea24bd79..7a7060677f15 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic.h
+++ b/drivers/net/ethernet/pensando/ionic/ionic.h
@@ -44,6 +44,8 @@  struct ionic {
 	DECLARE_BITMAP(lifbits, IONIC_LIFS_MAX);
 	unsigned int nintrs;
 	DECLARE_BITMAP(intrs, IONIC_INTR_CTRL_REGS_MAX);
+	struct work_struct nb_work;
+	struct notifier_block nb;
 };
 
 struct ionic_admin_ctx {
diff --git a/drivers/net/ethernet/pensando/ionic/ionic_lif.c b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
index 575c571d7b5e..1f2b826fbb54 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_lif.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
@@ -1947,10 +1947,66 @@  int ionic_lifs_init(struct ionic *ionic)
 	return 0;
 }
 
+static void ionic_lif_notify_work(struct work_struct *ws)
+{
+}
+
+static void ionic_lif_set_netdev_info(struct ionic_lif *lif)
+{
+	struct ionic_admin_ctx ctx = {
+		.work = COMPLETION_INITIALIZER_ONSTACK(ctx.work),
+		.cmd.lif_setattr = {
+			.opcode = IONIC_CMD_LIF_SETATTR,
+			.index = cpu_to_le16(lif->index),
+			.attr = IONIC_LIF_ATTR_NAME,
+		},
+	};
+
+	strlcpy(ctx.cmd.lif_setattr.name, lif->netdev->name,
+		sizeof(ctx.cmd.lif_setattr.name));
+
+	ionic_adminq_post_wait(lif, &ctx);
+}
+
+static struct ionic_lif *ionic_netdev_lif(struct net_device *netdev)
+{
+	if (!netdev || netdev->netdev_ops->ndo_start_xmit != ionic_start_xmit)
+		return NULL;
+
+	return netdev_priv(netdev);
+}
+
+static int ionic_lif_notify(struct notifier_block *nb,
+			    unsigned long event, void *info)
+{
+	struct net_device *ndev = netdev_notifier_info_to_dev(info);
+	struct ionic *ionic = container_of(nb, struct ionic, nb);
+	struct ionic_lif *lif = ionic_netdev_lif(ndev);
+
+	if (!lif || lif->ionic != ionic)
+		return NOTIFY_DONE;
+
+	switch (event) {
+	case NETDEV_CHANGENAME:
+		ionic_lif_set_netdev_info(lif);
+		break;
+	}
+
+	return NOTIFY_DONE;
+}
+
 int ionic_lifs_register(struct ionic *ionic)
 {
 	int err;
 
+	INIT_WORK(&ionic->nb_work, ionic_lif_notify_work);
+
+	ionic->nb.notifier_call = ionic_lif_notify;
+
+	err = register_netdevice_notifier(&ionic->nb);
+	if (err)
+		ionic->nb.notifier_call = NULL;
+
 	/* only register LIF0 for now */
 	err = register_netdev(ionic->master_lif->netdev);
 	if (err) {
@@ -1966,6 +2022,12 @@  int ionic_lifs_register(struct ionic *ionic)
 
 void ionic_lifs_unregister(struct ionic *ionic)
 {
+	if (ionic->nb.notifier_call) {
+		unregister_netdevice_notifier(&ionic->nb);
+		cancel_work_sync(&ionic->nb_work);
+		ionic->nb.notifier_call = NULL;
+	}
+
 	/* There is only one lif ever registered in the
 	 * current model, so don't bother searching the
 	 * ionic->lif for candidates to unregister