mirror of
https://github.com/corundum/corundum.git
synced 2025-01-16 08:12:53 +08:00
Use MAC list instead of base MAC for more flexibility
This commit is contained in:
parent
85d9ec7a87
commit
df32217dc8
@ -76,7 +76,8 @@ struct mqnic_dev {
|
||||
|
||||
struct mutex state_lock;
|
||||
|
||||
u8 base_mac[ETH_ALEN];
|
||||
int mac_count;
|
||||
u8 mac_list[MQNIC_MAX_IF][ETH_ALEN];
|
||||
|
||||
char name[16];
|
||||
|
||||
|
@ -441,6 +441,27 @@ int mqnic_init_i2c(struct mqnic_dev *mqnic)
|
||||
break;
|
||||
}
|
||||
|
||||
// Read MAC from EEPROM
|
||||
if (mqnic->eeprom_i2c_client)
|
||||
{
|
||||
int r, k;
|
||||
|
||||
r = i2c_smbus_read_i2c_block_data(mqnic->eeprom_i2c_client, 0x00, 6, mqnic->mac_list[0]);
|
||||
if (r < 0)
|
||||
{
|
||||
dev_warn(mqnic->dev, "Failed to read MAC from EEPROM");
|
||||
}
|
||||
else
|
||||
{
|
||||
mqnic->mac_count = MQNIC_MAX_IF;
|
||||
for (k = 1; k < mqnic->mac_count; k++)
|
||||
{
|
||||
memcpy(mqnic->mac_list[k], mqnic->mac_list[0], ETH_ALEN);
|
||||
mqnic->mac_list[k][ETH_ALEN-1] += k;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -258,20 +258,6 @@ static int mqnic_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent
|
||||
goto fail_i2c;
|
||||
}
|
||||
|
||||
// Read MAC from EEPROM
|
||||
if (mqnic->eeprom_i2c_client)
|
||||
{
|
||||
ret = i2c_smbus_read_i2c_block_data(mqnic->eeprom_i2c_client, 0x00, 6, mqnic->base_mac);
|
||||
if (ret < 0)
|
||||
{
|
||||
dev_warn(dev, "Failed to read MAC from EEPROM");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dev_warn(dev, "Failed to read MAC from EEPROM; no EEPROM I2C client registered");
|
||||
}
|
||||
|
||||
// Enable bus mastering for DMA
|
||||
pci_set_master(pdev);
|
||||
|
||||
|
@ -486,16 +486,21 @@ int mqnic_init_netdev(struct mqnic_dev *mdev, int port, u8 __iomem *hw_addr)
|
||||
|
||||
// set MAC
|
||||
ndev->addr_len = ETH_ALEN;
|
||||
memcpy(ndev->dev_addr, mdev->base_mac, ETH_ALEN);
|
||||
|
||||
if (!is_valid_ether_addr(ndev->dev_addr))
|
||||
if (port >= mdev->mac_count)
|
||||
{
|
||||
dev_warn(dev, "Bad MAC in EEPROM; using random MAC");
|
||||
dev_warn(dev, "Exhausted permanent MAC addresses; using random MAC");
|
||||
eth_hw_addr_random(ndev);
|
||||
}
|
||||
else
|
||||
{
|
||||
ndev->dev_addr[ETH_ALEN-1] += port;
|
||||
memcpy(ndev->dev_addr, mdev->mac_list[port], ETH_ALEN);
|
||||
|
||||
if (!is_valid_ether_addr(ndev->dev_addr))
|
||||
{
|
||||
dev_warn(dev, "Invalid MAC address in list; using random MAC");
|
||||
eth_hw_addr_random(ndev);
|
||||
}
|
||||
}
|
||||
|
||||
priv->hwts_config.flags = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user