Skip to content

Commit

Permalink
ethernet: use eth_hw_addr_set() in unmaintained drivers
Browse files Browse the repository at this point in the history
Commit 406f42f ("net-next: When a bond have a massive amount
of VLANs...") introduced a rbtree for faster Ethernet address look
up. To maintain netdev->dev_addr in this tree we need to make all
the writes to it got through appropriate helpers.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jakub Kicinski authored and David S. Miller committed Oct 18, 2021
1 parent 0e9e759 commit 4abd7cf
Show file tree
Hide file tree
Showing 21 changed files with 99 additions and 53 deletions.
4 changes: 3 additions & 1 deletion drivers/net/ethernet/calxeda/xgmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,7 @@ static int xgmac_probe(struct platform_device *pdev)
struct resource *res;
struct net_device *ndev = NULL;
struct xgmac_priv *priv = NULL;
u8 addr[ETH_ALEN];
u32 uid;

res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Expand Down Expand Up @@ -1785,7 +1786,8 @@ static int xgmac_probe(struct platform_device *pdev)
ndev->max_mtu = XGMAC_MAX_MTU;

/* Get the MAC address */
xgmac_get_mac_addr(priv->base, ndev->dev_addr, 0);
xgmac_get_mac_addr(priv->base, addr, 0);
eth_hw_addr_set(ndev, addr);
if (!is_valid_ether_addr(ndev->dev_addr))
netdev_warn(ndev, "MAC address %pM not valid",
ndev->dev_addr);
Expand Down
11 changes: 7 additions & 4 deletions drivers/net/ethernet/cirrus/cs89x0.c
Original file line number Diff line number Diff line change
Expand Up @@ -1314,6 +1314,7 @@ cs89x0_probe1(struct net_device *dev, void __iomem *ioaddr, int modular)
int tmp;
unsigned rev_type = 0;
int eeprom_buff[CHKSUM_LEN];
u8 addr[ETH_ALEN];
int retval;

/* Initialize the device structure. */
Expand Down Expand Up @@ -1387,9 +1388,10 @@ cs89x0_probe1(struct net_device *dev, void __iomem *ioaddr, int modular)
for (i = 0; i < ETH_ALEN / 2; i++) {
unsigned int Addr;
Addr = readreg(dev, PP_IA + i * 2);
dev->dev_addr[i * 2] = Addr & 0xFF;
dev->dev_addr[i * 2 + 1] = Addr >> 8;
addr[i * 2] = Addr & 0xFF;
addr[i * 2 + 1] = Addr >> 8;
}
eth_hw_addr_set(dev, addr);

/* Load the Adapter Configuration.
* Note: Barring any more specific information from some
Expand Down Expand Up @@ -1464,9 +1466,10 @@ cs89x0_probe1(struct net_device *dev, void __iomem *ioaddr, int modular)
/* eeprom_buff has 32-bit ints, so we can't just memcpy it */
/* store the initial memory base address */
for (i = 0; i < ETH_ALEN / 2; i++) {
dev->dev_addr[i * 2] = eeprom_buff[i];
dev->dev_addr[i * 2 + 1] = eeprom_buff[i] >> 8;
addr[i * 2] = eeprom_buff[i];
addr[i * 2 + 1] = eeprom_buff[i] >> 8;
}
eth_hw_addr_set(dev, addr);
cs89_dbg(1, debug, "%s: new adapter_cnf: 0x%x\n",
dev->name, lp->adapter_cnf);
}
Expand Down
7 changes: 5 additions & 2 deletions drivers/net/ethernet/davicom/dm9000.c
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,7 @@ dm9000_probe(struct platform_device *pdev)
enum of_gpio_flags flags;
struct regulator *power;
bool inv_mac_addr = false;
u8 addr[ETH_ALEN];

power = devm_regulator_get(dev, "vcc");
if (IS_ERR(power)) {
Expand Down Expand Up @@ -1666,7 +1667,8 @@ dm9000_probe(struct platform_device *pdev)

/* try reading the node address from the attached EEPROM */
for (i = 0; i < 6; i += 2)
dm9000_read_eeprom(db, i / 2, ndev->dev_addr+i);
dm9000_read_eeprom(db, i / 2, addr + i);
eth_hw_addr_set(ndev, addr);

if (!is_valid_ether_addr(ndev->dev_addr) && pdata != NULL) {
mac_src = "platform data";
Expand All @@ -1678,7 +1680,8 @@ dm9000_probe(struct platform_device *pdev)

mac_src = "chip";
for (i = 0; i < 6; i++)
ndev->dev_addr[i] = ior(db, i+DM9000_PAR);
addr[i] = ior(db, i + DM9000_PAR);
eth_hw_addr_set(ndev, pdata->dev_addr);
}

if (!is_valid_ether_addr(ndev->dev_addr)) {
Expand Down
8 changes: 6 additions & 2 deletions drivers/net/ethernet/ethoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1154,8 +1154,12 @@ static int ethoc_probe(struct platform_device *pdev)
/* Check that the given MAC address is valid. If it isn't, read the
* current MAC from the controller.
*/
if (!is_valid_ether_addr(netdev->dev_addr))
ethoc_get_mac_address(netdev, netdev->dev_addr);
if (!is_valid_ether_addr(netdev->dev_addr)) {
u8 addr[ETH_ALEN];

ethoc_get_mac_address(netdev, addr);
eth_hw_addr_set(netdev, addr);
}

/* Check the MAC again for validity, if it still isn't choose and
* program a random one.
Expand Down
4 changes: 3 additions & 1 deletion drivers/net/ethernet/fealnx.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ static int fealnx_init_one(struct pci_dev *pdev,
struct net_device *dev;
void *ring_space;
dma_addr_t ring_dma;
u8 addr[ETH_ALEN];
#ifdef USE_IO_OPS
int bar = 0;
#else
Expand Down Expand Up @@ -525,7 +526,8 @@ static int fealnx_init_one(struct pci_dev *pdev,

/* read ethernet id */
for (i = 0; i < 6; ++i)
dev->dev_addr[i] = ioread8(ioaddr + PAR0 + i);
addr[i] = ioread8(ioaddr + PAR0 + i);
eth_hw_addr_set(dev, addr);

/* Reset the chip to erase previous misconfiguration. */
iowrite32(0x00000001, ioaddr + BCR);
Expand Down
7 changes: 5 additions & 2 deletions drivers/net/ethernet/fujitsu/fmvj18x_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ static int fmvj18x_config(struct pcmcia_device *link)
u8 *buf;
size_t len;
u_char buggybuf[32];
u8 addr[ETH_ALEN];

dev_dbg(&link->dev, "fmvj18x_config\n");

Expand Down Expand Up @@ -489,7 +490,8 @@ static int fmvj18x_config(struct pcmcia_device *link)
case UNGERMANN:
/* Read MACID from register */
for (i = 0; i < 6; i++)
dev->dev_addr[i] = inb(ioaddr + UNGERMANN_MAC_ID + i);
addr[i] = inb(ioaddr + UNGERMANN_MAC_ID + i);
eth_hw_addr_set(dev, addr);
card_name = "Access/CARD";
break;
case XXX10304:
Expand All @@ -505,7 +507,8 @@ static int fmvj18x_config(struct pcmcia_device *link)
default:
/* Read MACID from register */
for (i = 0; i < 6; i++)
dev->dev_addr[i] = inb(ioaddr + MAC_ID + i);
addr[i] = inb(ioaddr + MAC_ID + i);
eth_hw_addr_set(dev, addr);
card_name = "FMV-J181";
break;
}
Expand Down
4 changes: 3 additions & 1 deletion drivers/net/ethernet/huawei/hinic/hinic_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,7 @@ static int nic_dev_init(struct pci_dev *pdev)
struct net_device *netdev;
struct hinic_hwdev *hwdev;
struct devlink *devlink;
u8 addr[ETH_ALEN];
int err, num_qps;

devlink = hinic_devlink_alloc(&pdev->dev);
Expand Down Expand Up @@ -1259,11 +1260,12 @@ static int nic_dev_init(struct pci_dev *pdev)

pci_set_drvdata(pdev, netdev);

err = hinic_port_get_mac(nic_dev, netdev->dev_addr);
err = hinic_port_get_mac(nic_dev, addr);
if (err) {
dev_err(&pdev->dev, "Failed to get mac address\n");
goto err_get_mac;
}
eth_hw_addr_set(netdev, addr);

if (!is_valid_ether_addr(netdev->dev_addr)) {
if (!HINIC_IS_VF(nic_dev->hwdev->hwif)) {
Expand Down
8 changes: 6 additions & 2 deletions drivers/net/ethernet/marvell/pxa168_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -1436,9 +1436,13 @@ static int pxa168_eth_probe(struct platform_device *pdev)

err = of_get_ethdev_address(pdev->dev.of_node, dev);
if (err) {
u8 addr[ETH_ALEN];

/* try reading the mac address, if set by the bootloader */
pxa168_eth_get_mac_address(dev, dev->dev_addr);
if (!is_valid_ether_addr(dev->dev_addr)) {
pxa168_eth_get_mac_address(dev, addr);
if (is_valid_ether_addr(addr)) {
eth_hw_addr_set(dev, addr);
} else {
dev_info(&pdev->dev, "Using random mac address\n");
eth_hw_addr_random(dev);
}
Expand Down
8 changes: 5 additions & 3 deletions drivers/net/ethernet/micrel/ks8842.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,15 @@ static void ks8842_reset_hw(struct ks8842_adapter *adapter)
ks8842_write16(adapter, 32, 0x1, REG_SW_ID_AND_ENABLE);
}

static void ks8842_read_mac_addr(struct ks8842_adapter *adapter, u8 *dest)
static void ks8842_init_mac_addr(struct ks8842_adapter *adapter)
{
u8 addr[ETH_ALEN];
int i;
u16 mac;

for (i = 0; i < ETH_ALEN; i++)
dest[ETH_ALEN - i - 1] = ks8842_read8(adapter, 2, REG_MARL + i);
addr[ETH_ALEN - i - 1] = ks8842_read8(adapter, 2, REG_MARL + i);
eth_hw_addr_set(adapter->netdev, addr);

if (adapter->conf_flags & MICREL_KS884X) {
/*
Expand Down Expand Up @@ -1195,7 +1197,7 @@ static int ks8842_probe(struct platform_device *pdev)
}

if (i == netdev->addr_len) {
ks8842_read_mac_addr(adapter, netdev->dev_addr);
ks8842_init_mac_addr(adapter);

if (!is_valid_ether_addr(netdev->dev_addr))
eth_hw_addr_random(netdev);
Expand Down
6 changes: 4 additions & 2 deletions drivers/net/ethernet/micrel/ks8851_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,18 @@ static void ks8851_read_mac_addr(struct net_device *dev)
{
struct ks8851_net *ks = netdev_priv(dev);
unsigned long flags;
u8 addr[ETH_ALEN];
u16 reg;
int i;

ks8851_lock(ks, &flags);

for (i = 0; i < ETH_ALEN; i += 2) {
reg = ks8851_rdreg16(ks, KS_MAR(i));
dev->dev_addr[i] = reg >> 8;
dev->dev_addr[i + 1] = reg & 0xff;
addr[i] = reg >> 8;
addr[i + 1] = reg & 0xff;
}
eth_hw_addr_set(dev, addr);

ks8851_unlock(ks, &flags);
}
Expand Down
7 changes: 5 additions & 2 deletions drivers/net/ethernet/micrel/ksz884x.c
Original file line number Diff line number Diff line change
Expand Up @@ -7007,9 +7007,12 @@ static int pcidev_init(struct pci_dev *pdev, const struct pci_device_id *id)
if (MAIN_PORT == i)
eth_hw_addr_set(dev, hw_priv->hw.override_addr);
else {
eth_hw_addr_set(dev, sw->other_addr);
u8 addr[ETH_ALEN];

ether_addr_copy(addr, sw->other_addr);
if (ether_addr_equal(sw->other_addr, hw->override_addr))
dev->dev_addr[5] += port->first_port;
addr[5] += port->first_port;
eth_hw_addr_set(dev, addr);
}

dev->netdev_ops = &netdev_ops;
Expand Down
4 changes: 3 additions & 1 deletion drivers/net/ethernet/microchip/encx24j600.c
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,7 @@ static int encx24j600_spi_probe(struct spi_device *spi)
struct net_device *ndev;
struct encx24j600_priv *priv;
u16 eidled;
u8 addr[ETH_ALEN];

ndev = alloc_etherdev(sizeof(struct encx24j600_priv));

Expand Down Expand Up @@ -1056,7 +1057,8 @@ static int encx24j600_spi_probe(struct spi_device *spi)
}

/* Get the MAC address from the chip */
encx24j600_hw_get_macaddr(priv, ndev->dev_addr);
encx24j600_hw_get_macaddr(priv, addr);
eth_hw_addr_set(ndev, addr);

ndev->ethtool_ops = &encx24j600_ethtool_ops;

Expand Down
6 changes: 4 additions & 2 deletions drivers/net/ethernet/natsemi/natsemi.c
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@ static int natsemi_probe1(struct pci_dev *pdev, const struct pci_device_id *ent)
unsigned long iosize;
void __iomem *ioaddr;
const int pcibar = 1; /* PCI base address register */
u8 addr[ETH_ALEN];
int prev_eedata;
u32 tmp;

Expand Down Expand Up @@ -859,10 +860,11 @@ static int natsemi_probe1(struct pci_dev *pdev, const struct pci_device_id *ent)
prev_eedata = eeprom_read(ioaddr, 6);
for (i = 0; i < 3; i++) {
int eedata = eeprom_read(ioaddr, i + 7);
dev->dev_addr[i*2] = (eedata << 1) + (prev_eedata >> 15);
dev->dev_addr[i*2+1] = eedata >> 7;
addr[i*2] = (eedata << 1) + (prev_eedata >> 15);
addr[i*2+1] = eedata >> 7;
prev_eedata = eedata;
}
eth_hw_addr_set(dev, addr);

np = netdev_priv(dev);
np->ioaddr = ioaddr;
Expand Down
11 changes: 7 additions & 4 deletions drivers/net/ethernet/natsemi/ns83820.c
Original file line number Diff line number Diff line change
Expand Up @@ -1649,9 +1649,11 @@ static int ns83820_open(struct net_device *ndev)
return ret;
}

static void ns83820_getmac(struct ns83820 *dev, u8 *mac)
static void ns83820_getmac(struct ns83820 *dev, struct net_device *ndev)
{
u8 mac[ETH_ALEN];
unsigned i;

for (i=0; i<3; i++) {
u32 data;

Expand All @@ -1661,9 +1663,10 @@ static void ns83820_getmac(struct ns83820 *dev, u8 *mac)
writel(i*2, dev->base + RFCR);
data = readl(dev->base + RFDR);

*mac++ = data;
*mac++ = data >> 8;
mac[i * 2] = data;
mac[i * 2 + 1] = data >> 8;
}
eth_hw_addr_set(ndev, mac);
}

static void ns83820_set_multicast(struct net_device *ndev)
Expand Down Expand Up @@ -2136,7 +2139,7 @@ static int ns83820_init_one(struct pci_dev *pci_dev,
/* Disable Wake On Lan */
writel(0, dev->base + WCSR);

ns83820_getmac(dev, ndev->dev_addr);
ns83820_getmac(dev, ndev);

/* Yes, we support dumb IP checksum on transmit */
ndev->features |= NETIF_F_SG;
Expand Down
5 changes: 3 additions & 2 deletions drivers/net/ethernet/packetengines/hamachi.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ static int hamachi_init_one(struct pci_dev *pdev,
void *ring_space;
dma_addr_t ring_dma;
int ret = -ENOMEM;
u8 addr[ETH_ALEN];

/* when built into the kernel, we only print version if device is found */
#ifndef MODULE
Expand Down Expand Up @@ -628,8 +629,8 @@ static int hamachi_init_one(struct pci_dev *pdev,
SET_NETDEV_DEV(dev, &pdev->dev);

for (i = 0; i < 6; i++)
dev->dev_addr[i] = 1 ? read_eeprom(ioaddr, 4 + i)
: readb(ioaddr + StationAddr + i);
addr[i] = read_eeprom(ioaddr, 4 + i);
eth_hw_addr_set(dev, addr);

#if ! defined(final_version)
if (hamachi_debug > 4)
Expand Down
6 changes: 4 additions & 2 deletions drivers/net/ethernet/packetengines/yellowfin.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ static int yellowfin_init_one(struct pci_dev *pdev,
#else
int bar = 1;
#endif
u8 addr[ETH_ALEN];

/* when built into the kernel, we only print version if device is found */
#ifndef MODULE
Expand Down Expand Up @@ -416,12 +417,13 @@ static int yellowfin_init_one(struct pci_dev *pdev,

if (drv_flags & DontUseEeprom)
for (i = 0; i < 6; i++)
dev->dev_addr[i] = ioread8(ioaddr + StnAddr + i);
addr[i] = ioread8(ioaddr + StnAddr + i);
else {
int ee_offset = (read_eeprom(ioaddr, 6) == 0xff ? 0x100 : 0);
for (i = 0; i < 6; i++)
dev->dev_addr[i] = read_eeprom(ioaddr, ee_offset + i);
addr[i] = read_eeprom(ioaddr, ee_offset + i);
}
eth_hw_addr_set(dev, addr);

/* Reset the chip. */
iowrite32(0x80000000, ioaddr + DMACtrl);
Expand Down
14 changes: 8 additions & 6 deletions drivers/net/ethernet/silan/sc92031.c
Original file line number Diff line number Diff line change
Expand Up @@ -1400,6 +1400,7 @@ static int sc92031_probe(struct pci_dev *pdev, const struct pci_device_id *id)
void __iomem* port_base;
struct net_device *dev;
struct sc92031_priv *priv;
u8 addr[ETH_ALEN];
u32 mac0, mac1;

err = pci_enable_device(pdev);
Expand Down Expand Up @@ -1458,12 +1459,13 @@ static int sc92031_probe(struct pci_dev *pdev, const struct pci_device_id *id)

mac0 = ioread32(port_base + MAC0);
mac1 = ioread32(port_base + MAC0 + 4);
dev->dev_addr[0] = mac0 >> 24;
dev->dev_addr[1] = mac0 >> 16;
dev->dev_addr[2] = mac0 >> 8;
dev->dev_addr[3] = mac0;
dev->dev_addr[4] = mac1 >> 8;
dev->dev_addr[5] = mac1;
addr[0] = mac0 >> 24;
addr[1] = mac0 >> 16;
addr[2] = mac0 >> 8;
addr[3] = mac0;
addr[4] = mac1 >> 8;
addr[5] = mac1;
eth_hw_addr_set(dev, addr);

err = register_netdev(dev);
if (err < 0)
Expand Down
Loading

0 comments on commit 4abd7cf

Please sign in to comment.