Skip to content

Commit 4b0dd00

Browse files
committed
Merge branch 'dev_addr-conversions-part-1'
Jakub Kicinski says: ==================== ethernet: manual netdev->dev_addr conversions (part 1) Manual conversions of drivers writing directly to netdev->dev_addr (part 1 out of 3). ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents a07a296 + ec356ed commit 4b0dd00

File tree

15 files changed

+69
-46
lines changed

15 files changed

+69
-46
lines changed

drivers/net/ethernet/adaptec/starfire.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ static int starfire_init_one(struct pci_dev *pdev,
641641
struct netdev_private *np;
642642
int i, irq, chip_idx = ent->driver_data;
643643
struct net_device *dev;
644+
u8 addr[ETH_ALEN];
644645
long ioaddr;
645646
void __iomem *base;
646647
int drv_flags, io_size;
@@ -696,7 +697,8 @@ static int starfire_init_one(struct pci_dev *pdev,
696697

697698
/* Serial EEPROM reads are hidden by the hardware. */
698699
for (i = 0; i < 6; i++)
699-
dev->dev_addr[i] = readb(base + EEPROMCtrl + 20 - i);
700+
addr[i] = readb(base + EEPROMCtrl + 20 - i);
701+
eth_hw_addr_set(dev, addr);
700702

701703
#if ! defined(final_version) /* Dump the EEPROM contents during development. */
702704
if (debug > 4)

drivers/net/ethernet/aeroflex/greth.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,7 @@ static int greth_of_probe(struct platform_device *ofdev)
13461346
int i;
13471347
int err;
13481348
int tmp;
1349+
u8 addr[ETH_ALEN];
13491350
unsigned long timeout;
13501351

13511352
dev = alloc_etherdev(sizeof(struct greth_private));
@@ -1449,8 +1450,6 @@ static int greth_of_probe(struct platform_device *ofdev)
14491450
break;
14501451
}
14511452
if (i == 6) {
1452-
u8 addr[ETH_ALEN];
1453-
14541453
err = of_get_mac_address(ofdev->dev.of_node, addr);
14551454
if (!err) {
14561455
for (i = 0; i < 6; i++)
@@ -1464,7 +1463,8 @@ static int greth_of_probe(struct platform_device *ofdev)
14641463
}
14651464

14661465
for (i = 0; i < 6; i++)
1467-
dev->dev_addr[i] = macaddr[i];
1466+
addr[i] = macaddr[i];
1467+
eth_hw_addr_set(dev, addr);
14681468

14691469
macaddr[5]++;
14701470

drivers/net/ethernet/alteon/acenic.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,7 @@ static int ace_init(struct net_device *dev)
869869
int board_idx, ecode = 0;
870870
short i;
871871
unsigned char cache_size;
872+
u8 addr[ETH_ALEN];
872873

873874
ap = netdev_priv(dev);
874875
regs = ap->regs;
@@ -988,12 +989,13 @@ static int ace_init(struct net_device *dev)
988989
writel(mac1, &regs->MacAddrHi);
989990
writel(mac2, &regs->MacAddrLo);
990991

991-
dev->dev_addr[0] = (mac1 >> 8) & 0xff;
992-
dev->dev_addr[1] = mac1 & 0xff;
993-
dev->dev_addr[2] = (mac2 >> 24) & 0xff;
994-
dev->dev_addr[3] = (mac2 >> 16) & 0xff;
995-
dev->dev_addr[4] = (mac2 >> 8) & 0xff;
996-
dev->dev_addr[5] = mac2 & 0xff;
992+
addr[0] = (mac1 >> 8) & 0xff;
993+
addr[1] = mac1 & 0xff;
994+
addr[2] = (mac2 >> 24) & 0xff;
995+
addr[3] = (mac2 >> 16) & 0xff;
996+
addr[4] = (mac2 >> 8) & 0xff;
997+
addr[5] = mac2 & 0xff;
998+
eth_hw_addr_set(dev, addr);
997999

9981000
printk("MAC: %pM\n", dev->dev_addr);
9991001

drivers/net/ethernet/amd/amd8111e.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1743,6 +1743,7 @@ static int amd8111e_probe_one(struct pci_dev *pdev,
17431743
unsigned long reg_addr, reg_len;
17441744
struct amd8111e_priv *lp;
17451745
struct net_device *dev;
1746+
u8 addr[ETH_ALEN];
17461747

17471748
err = pci_enable_device(pdev);
17481749
if (err) {
@@ -1809,7 +1810,8 @@ static int amd8111e_probe_one(struct pci_dev *pdev,
18091810

18101811
/* Initializing MAC address */
18111812
for (i = 0; i < ETH_ALEN; i++)
1812-
dev->dev_addr[i] = readb(lp->mmio + PADR + i);
1813+
addr[i] = readb(lp->mmio + PADR + i);
1814+
eth_hw_addr_set(dev, addr);
18131815

18141816
/* Setting user defined parametrs */
18151817
lp->ext_phy_option = speed_duplex[card_idx];

drivers/net/ethernet/amd/pcnet32.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,6 +1595,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
15951595
struct net_device *dev;
15961596
const struct pcnet32_access *a = NULL;
15971597
u8 promaddr[ETH_ALEN];
1598+
u8 addr[ETH_ALEN];
15981599
int ret = -ENODEV;
15991600

16001601
/* reset the chip */
@@ -1760,9 +1761,10 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
17601761
unsigned int val;
17611762
val = a->read_csr(ioaddr, i + 12) & 0x0ffff;
17621763
/* There may be endianness issues here. */
1763-
dev->dev_addr[2 * i] = val & 0x0ff;
1764-
dev->dev_addr[2 * i + 1] = (val >> 8) & 0x0ff;
1764+
addr[2 * i] = val & 0x0ff;
1765+
addr[2 * i + 1] = (val >> 8) & 0x0ff;
17651766
}
1767+
eth_hw_addr_set(dev, addr);
17661768

17671769
/* read PROM address and compare with CSR address */
17681770
for (i = 0; i < ETH_ALEN; i++)
@@ -1780,8 +1782,11 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
17801782
}
17811783

17821784
/* if the ethernet address is not valid, force to 00:00:00:00:00:00 */
1783-
if (!is_valid_ether_addr(dev->dev_addr))
1784-
eth_zero_addr(dev->dev_addr);
1785+
if (!is_valid_ether_addr(dev->dev_addr)) {
1786+
static const u8 zero_addr[ETH_ALEN] = {};
1787+
1788+
eth_hw_addr_set(dev, zero_addr);
1789+
}
17851790

17861791
if (pcnet32_debug & NETIF_MSG_PROBE) {
17871792
pr_cont(" %pM", dev->dev_addr);

drivers/net/ethernet/aquantia/atlantic/aq_nic.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ static bool aq_nic_is_valid_ether_addr(const u8 *addr)
300300

301301
int aq_nic_ndev_register(struct aq_nic_s *self)
302302
{
303+
u8 addr[ETH_ALEN];
303304
int err = 0;
304305

305306
if (!self->ndev) {
@@ -316,12 +317,13 @@ int aq_nic_ndev_register(struct aq_nic_s *self)
316317
#endif
317318

318319
mutex_lock(&self->fwreq_mutex);
319-
err = self->aq_fw_ops->get_mac_permanent(self->aq_hw,
320-
self->ndev->dev_addr);
320+
err = self->aq_fw_ops->get_mac_permanent(self->aq_hw, addr);
321321
mutex_unlock(&self->fwreq_mutex);
322322
if (err)
323323
goto err_exit;
324324

325+
eth_hw_addr_set(self->ndev, addr);
326+
325327
if (!is_valid_ether_addr(self->ndev->dev_addr) ||
326328
!aq_nic_is_valid_ether_addr(self->ndev->dev_addr)) {
327329
netdev_warn(self->ndev, "MAC is invalid, will use random.");

drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11823,9 +11823,10 @@ static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
1182311823
u32 val, val2;
1182411824
int func = BP_ABS_FUNC(bp);
1182511825
int port = BP_PORT(bp);
11826+
u8 addr[ETH_ALEN] = {};
1182611827

1182711828
/* Zero primary MAC configuration */
11828-
eth_zero_addr(bp->dev->dev_addr);
11829+
eth_hw_addr_set(bp->dev, addr);
1182911830

1183011831
if (BP_NOMCP(bp)) {
1183111832
BNX2X_ERROR("warning: random MAC workaround active\n");
@@ -11834,16 +11835,19 @@ static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
1183411835
val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
1183511836
val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
1183611837
if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
11837-
(val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
11838-
bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
11838+
(val != FUNC_MF_CFG_LOWERMAC_DEFAULT)) {
11839+
bnx2x_set_mac_buf(addr, val, val2);
11840+
eth_hw_addr_set(bp->dev, addr);
11841+
}
1183911842

1184011843
if (CNIC_SUPPORT(bp))
1184111844
bnx2x_get_cnic_mac_hwinfo(bp);
1184211845
} else {
1184311846
/* in SF read MACs from port configuration */
1184411847
val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
1184511848
val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
11846-
bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
11849+
bnx2x_set_mac_buf(addr, val, val2);
11850+
eth_hw_addr_set(bp->dev, addr);
1184711851

1184811852
if (CNIC_SUPPORT(bp))
1184911853
bnx2x_get_cnic_mac_hwinfo(bp);
@@ -12291,7 +12295,9 @@ static int bnx2x_init_bp(struct bnx2x *bp)
1229112295
if (rc)
1229212296
return rc;
1229312297
} else {
12294-
eth_zero_addr(bp->dev->dev_addr);
12298+
static const u8 zero_addr[ETH_ALEN] = {};
12299+
12300+
eth_hw_addr_set(bp->dev, zero_addr);
1229512301
}
1229612302

1229712303
bnx2x_set_modes_bitmap(bp);

drivers/net/ethernet/broadcom/genet/bcmgenet.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4085,8 +4085,12 @@ static int bcmgenet_probe(struct platform_device *pdev)
40854085
eth_hw_addr_set(dev, pd->mac_address);
40864086
else
40874087
if (device_get_ethdev_address(&pdev->dev, dev))
4088-
if (has_acpi_companion(&pdev->dev))
4089-
bcmgenet_get_hw_addr(priv, dev->dev_addr);
4088+
if (has_acpi_companion(&pdev->dev)) {
4089+
u8 addr[ETH_ALEN];
4090+
4091+
bcmgenet_get_hw_addr(priv, addr);
4092+
eth_hw_addr_set(dev, addr);
4093+
}
40904094

40914095
if (!is_valid_ether_addr(dev->dev_addr)) {
40924096
dev_warn(&pdev->dev, "using random Ethernet MAC\n");

drivers/net/ethernet/cisco/enic/enic_main.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,7 @@ static int enic_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
10981098
static int enic_set_vf_port(struct net_device *netdev, int vf,
10991099
struct nlattr *port[])
11001100
{
1101+
static const u8 zero_addr[ETH_ALEN] = {};
11011102
struct enic *enic = netdev_priv(netdev);
11021103
struct enic_port_profile prev_pp;
11031104
struct enic_port_profile *pp;
@@ -1162,7 +1163,7 @@ static int enic_set_vf_port(struct net_device *netdev, int vf,
11621163
} else {
11631164
memset(pp, 0, sizeof(*pp));
11641165
if (vf == PORT_SELF_VF)
1165-
eth_zero_addr(netdev->dev_addr);
1166+
eth_hw_addr_set(netdev, zero_addr);
11661167
}
11671168
} else {
11681169
/* Set flag to indicate that the port assoc/disassoc
@@ -1174,7 +1175,7 @@ static int enic_set_vf_port(struct net_device *netdev, int vf,
11741175
if (pp->request == PORT_REQUEST_DISASSOCIATE) {
11751176
eth_zero_addr(pp->mac_addr);
11761177
if (vf == PORT_SELF_VF)
1177-
eth_zero_addr(netdev->dev_addr);
1178+
eth_hw_addr_set(netdev, zero_addr);
11781179
}
11791180
}
11801181

drivers/net/ethernet/ec_bhf.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ static int ec_bhf_probe(struct pci_dev *dev, const struct pci_device_id *id)
479479
struct net_device *net_dev;
480480
struct ec_bhf_priv *priv;
481481
void __iomem *dma_io;
482+
u8 addr[ETH_ALEN];
482483
void __iomem *io;
483484
int err = 0;
484485

@@ -539,7 +540,8 @@ static int ec_bhf_probe(struct pci_dev *dev, const struct pci_device_id *id)
539540
if (err < 0)
540541
goto err_free_net_dev;
541542

542-
memcpy_fromio(net_dev->dev_addr, priv->mii_io + MII_MAC_ADDR, 6);
543+
memcpy_fromio(addr, priv->mii_io + MII_MAC_ADDR, ETH_ALEN);
544+
eth_hw_addr_set(net_dev, addr);
543545

544546
err = register_netdev(net_dev);
545547
if (err < 0)

drivers/net/ethernet/freescale/enetc/enetc_hw.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,10 +635,14 @@ struct enetc_cmd_rfse {
635635
#define ENETC_RFSE_EN BIT(15)
636636
#define ENETC_RFSE_MODE_BD 2
637637

638-
static inline void enetc_get_primary_mac_addr(struct enetc_hw *hw, u8 *addr)
638+
static inline void enetc_load_primary_mac_addr(struct enetc_hw *hw,
639+
struct net_device *ndev)
639640
{
641+
u8 addr[ETH_ALEN] __aligned(4);
642+
640643
*(u32 *)addr = __raw_readl(hw->reg + ENETC_SIPMAR0);
641644
*(u16 *)(addr + 4) = __raw_readw(hw->reg + ENETC_SIPMAR1);
645+
eth_hw_addr_set(ndev, addr);
642646
}
643647

644648
#define ENETC_SI_INT_IDX 0

drivers/net/ethernet/freescale/enetc/enetc_pf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ static void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
783783
}
784784

785785
/* pick up primary MAC address from SI */
786-
enetc_get_primary_mac_addr(&si->hw, ndev->dev_addr);
786+
enetc_load_primary_mac_addr(&si->hw, ndev);
787787
}
788788

789789
static int enetc_mdio_probe(struct enetc_pf *pf, struct device_node *np)

drivers/net/ethernet/freescale/enetc/enetc_vf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ static void enetc_vf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
135135
ndev->hw_features |= NETIF_F_RXHASH;
136136

137137
/* pick up primary MAC address from SI */
138-
enetc_get_primary_mac_addr(&si->hw, ndev->dev_addr);
138+
enetc_load_primary_mac_addr(&si->hw, ndev);
139139
}
140140

141141
static int enetc_vf_probe(struct pci_dev *pdev,

drivers/net/ethernet/ibm/ibmveth.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -483,17 +483,6 @@ static int ibmveth_register_logical_lan(struct ibmveth_adapter *adapter,
483483
return rc;
484484
}
485485

486-
static u64 ibmveth_encode_mac_addr(u8 *mac)
487-
{
488-
int i;
489-
u64 encoded = 0;
490-
491-
for (i = 0; i < ETH_ALEN; i++)
492-
encoded = (encoded << 8) | mac[i];
493-
494-
return encoded;
495-
}
496-
497486
static int ibmveth_open(struct net_device *netdev)
498487
{
499488
struct ibmveth_adapter *adapter = netdev_priv(netdev);
@@ -553,7 +542,7 @@ static int ibmveth_open(struct net_device *netdev)
553542
adapter->rx_queue.num_slots = rxq_entries;
554543
adapter->rx_queue.toggle = 1;
555544

556-
mac_address = ibmveth_encode_mac_addr(netdev->dev_addr);
545+
mac_address = ether_addr_to_u64(netdev->dev_addr);
557546

558547
rxq_desc.fields.flags_len = IBMVETH_BUF_VALID |
559548
adapter->rx_queue.queue_len;
@@ -1476,7 +1465,7 @@ static void ibmveth_set_multicast_list(struct net_device *netdev)
14761465
netdev_for_each_mc_addr(ha, netdev) {
14771466
/* add the multicast address to the filter table */
14781467
u64 mcast_addr;
1479-
mcast_addr = ibmveth_encode_mac_addr(ha->addr);
1468+
mcast_addr = ether_addr_to_u64(ha->addr);
14801469
lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
14811470
IbmVethMcastAddFilter,
14821471
mcast_addr);
@@ -1606,7 +1595,7 @@ static int ibmveth_set_mac_addr(struct net_device *dev, void *p)
16061595
if (!is_valid_ether_addr(addr->sa_data))
16071596
return -EADDRNOTAVAIL;
16081597

1609-
mac_address = ibmveth_encode_mac_addr(addr->sa_data);
1598+
mac_address = ether_addr_to_u64(addr->sa_data);
16101599
rc = h_change_logical_lan_mac(adapter->vdev->unit_address, mac_address);
16111600
if (rc) {
16121601
netdev_err(adapter->netdev, "h_change_logical_lan_mac failed with rc=%d\n", rc);

drivers/net/ethernet/intel/ixgb/ixgb_main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ ixgb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
362362
struct ixgb_adapter *adapter;
363363
static int cards_found = 0;
364364
int pci_using_dac;
365+
u8 addr[ETH_ALEN];
365366
int i;
366367
int err;
367368

@@ -461,7 +462,8 @@ ixgb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
461462
goto err_eeprom;
462463
}
463464

464-
ixgb_get_ee_mac_addr(&adapter->hw, netdev->dev_addr);
465+
ixgb_get_ee_mac_addr(&adapter->hw, addr);
466+
eth_hw_addr_set(netdev, addr);
465467

466468
if (!is_valid_ether_addr(netdev->dev_addr)) {
467469
netif_err(adapter, probe, adapter->netdev, "Invalid MAC Address\n");
@@ -2227,6 +2229,7 @@ static pci_ers_result_t ixgb_io_slot_reset(struct pci_dev *pdev)
22272229
{
22282230
struct net_device *netdev = pci_get_drvdata(pdev);
22292231
struct ixgb_adapter *adapter = netdev_priv(netdev);
2232+
u8 addr[ETH_ALEN];
22302233

22312234
if (pci_enable_device(pdev)) {
22322235
netif_err(adapter, probe, adapter->netdev,
@@ -2250,7 +2253,8 @@ static pci_ers_result_t ixgb_io_slot_reset(struct pci_dev *pdev)
22502253
"After reset, the EEPROM checksum is not valid\n");
22512254
return PCI_ERS_RESULT_DISCONNECT;
22522255
}
2253-
ixgb_get_ee_mac_addr(&adapter->hw, netdev->dev_addr);
2256+
ixgb_get_ee_mac_addr(&adapter->hw, addr);
2257+
eth_hw_addr_set(netdev, addr);
22542258
memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
22552259

22562260
if (!is_valid_ether_addr(netdev->perm_addr)) {

0 commit comments

Comments
 (0)