Skip to content

Commit

Permalink
Merge branch 'dev_addr-conversions-part-1'
Browse files Browse the repository at this point in the history
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 <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Oct 16, 2021
2 parents a07a296 + ec356ed commit 4b0dd00
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 46 deletions.
4 changes: 3 additions & 1 deletion drivers/net/ethernet/adaptec/starfire.c
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ static int starfire_init_one(struct pci_dev *pdev,
struct netdev_private *np;
int i, irq, chip_idx = ent->driver_data;
struct net_device *dev;
u8 addr[ETH_ALEN];
long ioaddr;
void __iomem *base;
int drv_flags, io_size;
Expand Down Expand Up @@ -696,7 +697,8 @@ static int starfire_init_one(struct pci_dev *pdev,

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

#if ! defined(final_version) /* Dump the EEPROM contents during development. */
if (debug > 4)
Expand Down
6 changes: 3 additions & 3 deletions drivers/net/ethernet/aeroflex/greth.c
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,7 @@ static int greth_of_probe(struct platform_device *ofdev)
int i;
int err;
int tmp;
u8 addr[ETH_ALEN];
unsigned long timeout;

dev = alloc_etherdev(sizeof(struct greth_private));
Expand Down Expand Up @@ -1449,8 +1450,6 @@ static int greth_of_probe(struct platform_device *ofdev)
break;
}
if (i == 6) {
u8 addr[ETH_ALEN];

err = of_get_mac_address(ofdev->dev.of_node, addr);
if (!err) {
for (i = 0; i < 6; i++)
Expand All @@ -1464,7 +1463,8 @@ static int greth_of_probe(struct platform_device *ofdev)
}

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

macaddr[5]++;

Expand Down
14 changes: 8 additions & 6 deletions drivers/net/ethernet/alteon/acenic.c
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@ static int ace_init(struct net_device *dev)
int board_idx, ecode = 0;
short i;
unsigned char cache_size;
u8 addr[ETH_ALEN];

ap = netdev_priv(dev);
regs = ap->regs;
Expand Down Expand Up @@ -988,12 +989,13 @@ static int ace_init(struct net_device *dev)
writel(mac1, &regs->MacAddrHi);
writel(mac2, &regs->MacAddrLo);

dev->dev_addr[0] = (mac1 >> 8) & 0xff;
dev->dev_addr[1] = mac1 & 0xff;
dev->dev_addr[2] = (mac2 >> 24) & 0xff;
dev->dev_addr[3] = (mac2 >> 16) & 0xff;
dev->dev_addr[4] = (mac2 >> 8) & 0xff;
dev->dev_addr[5] = mac2 & 0xff;
addr[0] = (mac1 >> 8) & 0xff;
addr[1] = mac1 & 0xff;
addr[2] = (mac2 >> 24) & 0xff;
addr[3] = (mac2 >> 16) & 0xff;
addr[4] = (mac2 >> 8) & 0xff;
addr[5] = mac2 & 0xff;
eth_hw_addr_set(dev, addr);

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

Expand Down
4 changes: 3 additions & 1 deletion drivers/net/ethernet/amd/amd8111e.c
Original file line number Diff line number Diff line change
Expand Up @@ -1743,6 +1743,7 @@ static int amd8111e_probe_one(struct pci_dev *pdev,
unsigned long reg_addr, reg_len;
struct amd8111e_priv *lp;
struct net_device *dev;
u8 addr[ETH_ALEN];

err = pci_enable_device(pdev);
if (err) {
Expand Down Expand Up @@ -1809,7 +1810,8 @@ static int amd8111e_probe_one(struct pci_dev *pdev,

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

/* Setting user defined parametrs */
lp->ext_phy_option = speed_duplex[card_idx];
Expand Down
13 changes: 9 additions & 4 deletions drivers/net/ethernet/amd/pcnet32.c
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
struct net_device *dev;
const struct pcnet32_access *a = NULL;
u8 promaddr[ETH_ALEN];
u8 addr[ETH_ALEN];
int ret = -ENODEV;

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

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

/* if the ethernet address is not valid, force to 00:00:00:00:00:00 */
if (!is_valid_ether_addr(dev->dev_addr))
eth_zero_addr(dev->dev_addr);
if (!is_valid_ether_addr(dev->dev_addr)) {
static const u8 zero_addr[ETH_ALEN] = {};

eth_hw_addr_set(dev, zero_addr);
}

if (pcnet32_debug & NETIF_MSG_PROBE) {
pr_cont(" %pM", dev->dev_addr);
Expand Down
6 changes: 4 additions & 2 deletions drivers/net/ethernet/aquantia/atlantic/aq_nic.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ static bool aq_nic_is_valid_ether_addr(const u8 *addr)

int aq_nic_ndev_register(struct aq_nic_s *self)
{
u8 addr[ETH_ALEN];
int err = 0;

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

mutex_lock(&self->fwreq_mutex);
err = self->aq_fw_ops->get_mac_permanent(self->aq_hw,
self->ndev->dev_addr);
err = self->aq_fw_ops->get_mac_permanent(self->aq_hw, addr);
mutex_unlock(&self->fwreq_mutex);
if (err)
goto err_exit;

eth_hw_addr_set(self->ndev, addr);

if (!is_valid_ether_addr(self->ndev->dev_addr) ||
!aq_nic_is_valid_ether_addr(self->ndev->dev_addr)) {
netdev_warn(self->ndev, "MAC is invalid, will use random.");
Expand Down
16 changes: 11 additions & 5 deletions drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11823,9 +11823,10 @@ static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
u32 val, val2;
int func = BP_ABS_FUNC(bp);
int port = BP_PORT(bp);
u8 addr[ETH_ALEN] = {};

/* Zero primary MAC configuration */
eth_zero_addr(bp->dev->dev_addr);
eth_hw_addr_set(bp->dev, addr);

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

if (CNIC_SUPPORT(bp))
bnx2x_get_cnic_mac_hwinfo(bp);
} else {
/* in SF read MACs from port configuration */
val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
bnx2x_set_mac_buf(addr, val, val2);
eth_hw_addr_set(bp->dev, addr);

if (CNIC_SUPPORT(bp))
bnx2x_get_cnic_mac_hwinfo(bp);
Expand Down Expand Up @@ -12291,7 +12295,9 @@ static int bnx2x_init_bp(struct bnx2x *bp)
if (rc)
return rc;
} else {
eth_zero_addr(bp->dev->dev_addr);
static const u8 zero_addr[ETH_ALEN] = {};

eth_hw_addr_set(bp->dev, zero_addr);
}

bnx2x_set_modes_bitmap(bp);
Expand Down
8 changes: 6 additions & 2 deletions drivers/net/ethernet/broadcom/genet/bcmgenet.c
Original file line number Diff line number Diff line change
Expand Up @@ -4085,8 +4085,12 @@ static int bcmgenet_probe(struct platform_device *pdev)
eth_hw_addr_set(dev, pd->mac_address);
else
if (device_get_ethdev_address(&pdev->dev, dev))
if (has_acpi_companion(&pdev->dev))
bcmgenet_get_hw_addr(priv, dev->dev_addr);
if (has_acpi_companion(&pdev->dev)) {
u8 addr[ETH_ALEN];

bcmgenet_get_hw_addr(priv, addr);
eth_hw_addr_set(dev, addr);
}

if (!is_valid_ether_addr(dev->dev_addr)) {
dev_warn(&pdev->dev, "using random Ethernet MAC\n");
Expand Down
5 changes: 3 additions & 2 deletions drivers/net/ethernet/cisco/enic/enic_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,7 @@ static int enic_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
static int enic_set_vf_port(struct net_device *netdev, int vf,
struct nlattr *port[])
{
static const u8 zero_addr[ETH_ALEN] = {};
struct enic *enic = netdev_priv(netdev);
struct enic_port_profile prev_pp;
struct enic_port_profile *pp;
Expand Down Expand Up @@ -1162,7 +1163,7 @@ static int enic_set_vf_port(struct net_device *netdev, int vf,
} else {
memset(pp, 0, sizeof(*pp));
if (vf == PORT_SELF_VF)
eth_zero_addr(netdev->dev_addr);
eth_hw_addr_set(netdev, zero_addr);
}
} else {
/* Set flag to indicate that the port assoc/disassoc
Expand All @@ -1174,7 +1175,7 @@ static int enic_set_vf_port(struct net_device *netdev, int vf,
if (pp->request == PORT_REQUEST_DISASSOCIATE) {
eth_zero_addr(pp->mac_addr);
if (vf == PORT_SELF_VF)
eth_zero_addr(netdev->dev_addr);
eth_hw_addr_set(netdev, zero_addr);
}
}

Expand Down
4 changes: 3 additions & 1 deletion drivers/net/ethernet/ec_bhf.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ static int ec_bhf_probe(struct pci_dev *dev, const struct pci_device_id *id)
struct net_device *net_dev;
struct ec_bhf_priv *priv;
void __iomem *dma_io;
u8 addr[ETH_ALEN];
void __iomem *io;
int err = 0;

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

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

err = register_netdev(net_dev);
if (err < 0)
Expand Down
6 changes: 5 additions & 1 deletion drivers/net/ethernet/freescale/enetc/enetc_hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -635,10 +635,14 @@ struct enetc_cmd_rfse {
#define ENETC_RFSE_EN BIT(15)
#define ENETC_RFSE_MODE_BD 2

static inline void enetc_get_primary_mac_addr(struct enetc_hw *hw, u8 *addr)
static inline void enetc_load_primary_mac_addr(struct enetc_hw *hw,
struct net_device *ndev)
{
u8 addr[ETH_ALEN] __aligned(4);

*(u32 *)addr = __raw_readl(hw->reg + ENETC_SIPMAR0);
*(u16 *)(addr + 4) = __raw_readw(hw->reg + ENETC_SIPMAR1);
eth_hw_addr_set(ndev, addr);
}

#define ENETC_SI_INT_IDX 0
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/freescale/enetc/enetc_pf.c
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ static void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
}

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

static int enetc_mdio_probe(struct enetc_pf *pf, struct device_node *np)
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/freescale/enetc/enetc_vf.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ static void enetc_vf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
ndev->hw_features |= NETIF_F_RXHASH;

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

static int enetc_vf_probe(struct pci_dev *pdev,
Expand Down
17 changes: 3 additions & 14 deletions drivers/net/ethernet/ibm/ibmveth.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,17 +483,6 @@ static int ibmveth_register_logical_lan(struct ibmveth_adapter *adapter,
return rc;
}

static u64 ibmveth_encode_mac_addr(u8 *mac)
{
int i;
u64 encoded = 0;

for (i = 0; i < ETH_ALEN; i++)
encoded = (encoded << 8) | mac[i];

return encoded;
}

static int ibmveth_open(struct net_device *netdev)
{
struct ibmveth_adapter *adapter = netdev_priv(netdev);
Expand Down Expand Up @@ -553,7 +542,7 @@ static int ibmveth_open(struct net_device *netdev)
adapter->rx_queue.num_slots = rxq_entries;
adapter->rx_queue.toggle = 1;

mac_address = ibmveth_encode_mac_addr(netdev->dev_addr);
mac_address = ether_addr_to_u64(netdev->dev_addr);

rxq_desc.fields.flags_len = IBMVETH_BUF_VALID |
adapter->rx_queue.queue_len;
Expand Down Expand Up @@ -1476,7 +1465,7 @@ static void ibmveth_set_multicast_list(struct net_device *netdev)
netdev_for_each_mc_addr(ha, netdev) {
/* add the multicast address to the filter table */
u64 mcast_addr;
mcast_addr = ibmveth_encode_mac_addr(ha->addr);
mcast_addr = ether_addr_to_u64(ha->addr);
lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
IbmVethMcastAddFilter,
mcast_addr);
Expand Down Expand Up @@ -1606,7 +1595,7 @@ static int ibmveth_set_mac_addr(struct net_device *dev, void *p)
if (!is_valid_ether_addr(addr->sa_data))
return -EADDRNOTAVAIL;

mac_address = ibmveth_encode_mac_addr(addr->sa_data);
mac_address = ether_addr_to_u64(addr->sa_data);
rc = h_change_logical_lan_mac(adapter->vdev->unit_address, mac_address);
if (rc) {
netdev_err(adapter->netdev, "h_change_logical_lan_mac failed with rc=%d\n", rc);
Expand Down
8 changes: 6 additions & 2 deletions drivers/net/ethernet/intel/ixgb/ixgb_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ ixgb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
struct ixgb_adapter *adapter;
static int cards_found = 0;
int pci_using_dac;
u8 addr[ETH_ALEN];
int i;
int err;

Expand Down Expand Up @@ -461,7 +462,8 @@ ixgb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
goto err_eeprom;
}

ixgb_get_ee_mac_addr(&adapter->hw, netdev->dev_addr);
ixgb_get_ee_mac_addr(&adapter->hw, addr);
eth_hw_addr_set(netdev, addr);

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

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

if (!is_valid_ether_addr(netdev->perm_addr)) {
Expand Down

0 comments on commit 4b0dd00

Please sign in to comment.