From 2091ef8c42a8a2bbc6d6668e5304d34a70008fd7 Mon Sep 17 00:00:00 2001 From: Alex Forencich Date: Wed, 29 Dec 2021 14:29:55 -0800 Subject: [PATCH] Fix dev_port assignment --- modules/mqnic/mqnic.h | 10 +++++++++- modules/mqnic/mqnic_if.c | 5 ++++- modules/mqnic/mqnic_main.c | 4 ++++ modules/mqnic/mqnic_netdev.c | 9 +++++---- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/modules/mqnic/mqnic.h b/modules/mqnic/mqnic.h index 360ac2a78..3637402f7 100644 --- a/modules/mqnic/mqnic.h +++ b/modules/mqnic/mqnic.h @@ -121,6 +121,9 @@ struct mqnic_dev { struct miscdevice misc_dev; + int dev_port_max; + int dev_port_limit; + u32 fw_id; u32 fw_ver; u32 board_id; @@ -306,6 +309,10 @@ struct mqnic_if { int index; + int dev_port_base; + int dev_port_max; + int dev_port_limit; + u32 if_id; u32 if_features; @@ -400,7 +407,8 @@ void mqnic_destroy_interface(struct mqnic_if **interface_ptr); // mqnic_netdev.c void mqnic_update_stats(struct net_device *ndev); -int mqnic_create_netdev(struct mqnic_if *interface, struct net_device **ndev_ptr, int index); +int mqnic_create_netdev(struct mqnic_if *interface, struct net_device **ndev_ptr, + int index, int dev_port); void mqnic_destroy_netdev(struct net_device **ndev_ptr); // mqnic_port.c diff --git a/modules/mqnic/mqnic_if.c b/modules/mqnic/mqnic_if.c index 7684367c5..26e857c2e 100644 --- a/modules/mqnic/mqnic_if.c +++ b/modules/mqnic/mqnic_if.c @@ -172,9 +172,12 @@ int mqnic_create_interface(struct mqnic_dev *mdev, struct mqnic_if **interface_p } // create net_devices + interface->dev_port_base = mdev->dev_port_max; + interface->dev_port_max = mdev->dev_port_max; + interface->ndev_count = 1; for (k = 0; k < interface->ndev_count; k++) { - ret = mqnic_create_netdev(interface, &interface->ndev[k], k); + ret = mqnic_create_netdev(interface, &interface->ndev[k], k, interface->dev_port_max++); if (ret) goto fail; } diff --git a/modules/mqnic/mqnic_main.c b/modules/mqnic/mqnic_main.c index 35b5ad14f..3510b69b9 100644 --- a/modules/mqnic/mqnic_main.c +++ b/modules/mqnic/mqnic_main.c @@ -159,6 +159,9 @@ static int mqnic_common_probe(struct mqnic_dev *mqnic) mutex_init(&mqnic->state_lock); // Set up interfaces + mqnic->dev_port_max = 0; + mqnic->dev_port_limit = MQNIC_MAX_IF; + mqnic->if_count = min_t(u32, mqnic->if_count, MQNIC_MAX_IF); for (k = 0; k < mqnic->if_count; k++) { @@ -168,6 +171,7 @@ static int mqnic_common_probe(struct mqnic_dev *mqnic) dev_err(dev, "Failed to create interface: %d", ret); goto fail_create_if; } + mqnic->dev_port_max = mqnic->interface[k]->dev_port_max; } // pass module I2C clients to interface instances diff --git a/modules/mqnic/mqnic_netdev.c b/modules/mqnic/mqnic_netdev.c index f9d10b34e..2cb894c89 100644 --- a/modules/mqnic/mqnic_netdev.c +++ b/modules/mqnic/mqnic_netdev.c @@ -350,7 +350,8 @@ static const struct net_device_ops mqnic_netdev_ops = { .ndo_do_ioctl = mqnic_ioctl, }; -int mqnic_create_netdev(struct mqnic_if *interface, struct net_device **ndev_ptr, int index) +int mqnic_create_netdev(struct mqnic_if *interface, struct net_device **ndev_ptr, + int index, int dev_port) { struct mqnic_dev *mdev = interface->mdev; struct device *dev = interface->dev; @@ -367,7 +368,7 @@ int mqnic_create_netdev(struct mqnic_if *interface, struct net_device **ndev_ptr } SET_NETDEV_DEV(ndev, dev); - ndev->dev_port = index; + ndev->dev_port = dev_port; // init private data priv = netdev_priv(ndev); @@ -415,11 +416,11 @@ int mqnic_create_netdev(struct mqnic_if *interface, struct net_device **ndev_ptr // set MAC ndev->addr_len = ETH_ALEN; - if (index >= mdev->mac_count) { + if (dev_port >= mdev->mac_count) { dev_warn(dev, "Exhausted permanent MAC addresses; using random MAC"); eth_hw_addr_random(ndev); } else { - memcpy(ndev->dev_addr, mdev->mac_list[index], ETH_ALEN); + memcpy(ndev->dev_addr, mdev->mac_list[dev_port], ETH_ALEN); if (!is_valid_ether_addr(ndev->dev_addr)) { dev_warn(dev, "Invalid MAC address in list; using random MAC");