1
0
mirror of https://github.com/corundum/corundum.git synced 2025-01-30 08:32:52 +08:00

Fix dev_port assignment

This commit is contained in:
Alex Forencich 2021-12-29 14:29:55 -08:00
parent dc247259fd
commit 2091ef8c42
4 changed files with 22 additions and 6 deletions

View File

@ -121,6 +121,9 @@ struct mqnic_dev {
struct miscdevice misc_dev; struct miscdevice misc_dev;
int dev_port_max;
int dev_port_limit;
u32 fw_id; u32 fw_id;
u32 fw_ver; u32 fw_ver;
u32 board_id; u32 board_id;
@ -306,6 +309,10 @@ struct mqnic_if {
int index; int index;
int dev_port_base;
int dev_port_max;
int dev_port_limit;
u32 if_id; u32 if_id;
u32 if_features; u32 if_features;
@ -400,7 +407,8 @@ void mqnic_destroy_interface(struct mqnic_if **interface_ptr);
// mqnic_netdev.c // mqnic_netdev.c
void mqnic_update_stats(struct net_device *ndev); 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); void mqnic_destroy_netdev(struct net_device **ndev_ptr);
// mqnic_port.c // mqnic_port.c

View File

@ -172,9 +172,12 @@ int mqnic_create_interface(struct mqnic_dev *mdev, struct mqnic_if **interface_p
} }
// create net_devices // create net_devices
interface->dev_port_base = mdev->dev_port_max;
interface->dev_port_max = mdev->dev_port_max;
interface->ndev_count = 1; interface->ndev_count = 1;
for (k = 0; k < interface->ndev_count; k++) { 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) if (ret)
goto fail; goto fail;
} }

View File

@ -159,6 +159,9 @@ static int mqnic_common_probe(struct mqnic_dev *mqnic)
mutex_init(&mqnic->state_lock); mutex_init(&mqnic->state_lock);
// Set up interfaces // 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); mqnic->if_count = min_t(u32, mqnic->if_count, MQNIC_MAX_IF);
for (k = 0; k < mqnic->if_count; k++) { 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); dev_err(dev, "Failed to create interface: %d", ret);
goto fail_create_if; goto fail_create_if;
} }
mqnic->dev_port_max = mqnic->interface[k]->dev_port_max;
} }
// pass module I2C clients to interface instances // pass module I2C clients to interface instances

View File

@ -350,7 +350,8 @@ static const struct net_device_ops mqnic_netdev_ops = {
.ndo_do_ioctl = mqnic_ioctl, .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 mqnic_dev *mdev = interface->mdev;
struct device *dev = interface->dev; 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); SET_NETDEV_DEV(ndev, dev);
ndev->dev_port = index; ndev->dev_port = dev_port;
// init private data // init private data
priv = netdev_priv(ndev); priv = netdev_priv(ndev);
@ -415,11 +416,11 @@ int mqnic_create_netdev(struct mqnic_if *interface, struct net_device **ndev_ptr
// set MAC // set MAC
ndev->addr_len = ETH_ALEN; 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"); dev_warn(dev, "Exhausted permanent MAC addresses; using random MAC");
eth_hw_addr_random(ndev); eth_hw_addr_random(ndev);
} else { } 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)) { if (!is_valid_ether_addr(ndev->dev_addr)) {
dev_warn(dev, "Invalid MAC address in list; using random MAC"); dev_warn(dev, "Invalid MAC address in list; using random MAC");