Skip to contentSkip to conversation

ethernet: manual netdev->dev_addr conversions (part 3)

PATCH Applied Jakub Kicinski 3 participants 9 messages Oct 19, 2021 – Oct 20, 2021

Subsystems (9)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

cover ethernet: manual netdev->dev_addr conversions (part 3)

Manual conversions of Ethernet drivers writing directly to netdev->dev_addr (part 3 out of 3).

Jakub Kicinski (6):
ethernet: netsec: use eth_hw_addr_set()
ethernet: stmmac: use eth_hw_addr_set()
ethernet: tehuti: use eth_hw_addr_set()
ethernet: tlan: use eth_hw_addr_set()
ethernet: via-rhine: use eth_hw_addr_set()
ethernet: via-velocity: use eth_hw_addr_set()

 drivers/net/ethernet/socionext/netsec.c          | 16 +++++++++-------
 .../net/ethernet/stmicro/stmmac/stmmac_main.c    |  8 ++++++--
 drivers/net/ethernet/tehuti/tehuti.c             |  6 ++++--
 drivers/net/ethernet/ti/tlan.c                   | 10 ++++++----
 drivers/net/ethernet/via/via-rhine.c             |  4 +++-
 drivers/net/ethernet/via/via-velocity.c          |  4 +++-
 6 files changed, 31 insertions(+), 17 deletions(-)
Signature · 1 line
2.31.1
author maintainer
#1 lore raw

PATCH 1/6 ethernet: netsec: use eth_hw_addr_set()

Commit 406f42fa0d3c ("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.

Read the address into an array on the stack, then call eth_hw_addr_set().

---
CC: [email protected]
CC: [email protected]

---
 drivers/net/ethernet/socionext/netsec.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/net/ethernet/socionext/netsec.c +9 -7
index baa9f5d1c549..de7d8bf2c226 100644
@@ -2037,13 +2037,15 @@ static int netsec_probe(struct platform_device *pdev)
 	if (ret && priv->eeprom_base) {
 		void __iomem *macp = priv->eeprom_base +
 					NETSEC_EEPROM_MAC_ADDRESS;
-
-		ndev->dev_addr[0] = readb(macp + 3);
-		ndev->dev_addr[1] = readb(macp + 2);
-		ndev->dev_addr[2] = readb(macp + 1);
-		ndev->dev_addr[3] = readb(macp + 0);
-		ndev->dev_addr[4] = readb(macp + 7);
-		ndev->dev_addr[5] = readb(macp + 6);
+		u8 addr[ETH_ALEN];
+
+		addr[0] = readb(macp + 3);
+		addr[1] = readb(macp + 2);
+		addr[2] = readb(macp + 1);
+		addr[3] = readb(macp + 0);
+		addr[4] = readb(macp + 7);
+		addr[5] = readb(macp + 6);
+		eth_hw_addr_set(ndev, addr);
 	}
 
 	if (!is_valid_ether_addr(ndev->dev_addr)) {
Signature · 1 line
2.31.1
maintainer Acked-by on v1 1/6
#2 lore raw

Re: [PATCH net-next 1/6] ethernet: netsec: use eth_hw_addr_set()

Hi Jakub,

Quoted 45 lines · Jakub Kicinski

Commit 406f42fa0d3c ("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.

Read the address into an array on the stack, then call eth_hw_addr_set().

---
CC: [email protected]
CC: [email protected]

---
 drivers/net/ethernet/socionext/netsec.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/net/ethernet/socionext/netsec.c +9 -8
index baa9f5d1c549..de7d8bf2c226 100644
@@ -2037,13 +2037,15 @@ static int netsec_probe(struct platform_device *pdev)
        if (ret && priv->eeprom_base) {
                void __iomem *macp = priv->eeprom_base +
                                        NETSEC_EEPROM_MAC_ADDRESS;
-
-               ndev->dev_addr[0] = readb(macp + 3);
-               ndev->dev_addr[1] = readb(macp + 2);
-               ndev->dev_addr[2] = readb(macp + 1);
-               ndev->dev_addr[3] = readb(macp + 0);
-               ndev->dev_addr[4] = readb(macp + 7);
-               ndev->dev_addr[5] = readb(macp + 6);
+               u8 addr[ETH_ALEN];
+
+               addr[0] = readb(macp + 3);
+               addr[1] = readb(macp + 2);
+               addr[2] = readb(macp + 1);
+               addr[3] = readb(macp + 0);
+               addr[4] = readb(macp + 7);
+               addr[5] = readb(macp + 6);
+               eth_hw_addr_set(ndev, addr);
        }
 
        if (!is_valid_ether_addr(ndev->dev_addr)) {
--
Quoted 2 lines

2.31.1

Thanks!

author maintainer
#3 lore raw

PATCH 2/6 ethernet: stmmac: use eth_hw_addr_set()

In reply to Jakub Kicinski

Commit 406f42fa0d3c ("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.

Read the address into an array on the stack, then call eth_hw_addr_set().

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +6 -2
index b720539ccb0a..88d3053d2f87 100644
@@ -2818,9 +2818,13 @@ static int stmmac_get_hw_features(struct stmmac_priv *priv)
  */
 static void stmmac_check_ether_addr(struct stmmac_priv *priv)
 {
+	u8 addr[ETH_ALEN];
+
 	if (!is_valid_ether_addr(priv->dev->dev_addr)) {
-		stmmac_get_umac_addr(priv, priv->hw, priv->dev->dev_addr, 0);
-		if (!is_valid_ether_addr(priv->dev->dev_addr))
+		stmmac_get_umac_addr(priv, priv->hw, addr, 0);
+		if (is_valid_ether_addr(addr))
+			eth_hw_addr_set(priv->dev, addr);
+		else
 			eth_hw_addr_random(priv->dev);
 		dev_info(priv->device, "device MAC address %pM\n",
 			 priv->dev->dev_addr);
Signature · 1 line
2.31.1
author maintainer
#4 lore raw

PATCH 3/6 ethernet: tehuti: use eth_hw_addr_set()

In reply to Jakub Kicinski

Commit 406f42fa0d3c ("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.

Break the address up into an array on the stack, then call eth_hw_addr_set().

---
CC: [email protected]

---
 drivers/net/ethernet/tehuti/tehuti.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/tehuti/tehuti.c +4 -2
index 3e8a3fde8302..0775a5542f2f 100644
@@ -840,6 +840,7 @@ static int bdx_set_mac(struct net_device *ndev, void *p)
 static int bdx_read_mac(struct bdx_priv *priv)
 {
 	u16 macAddress[3], i;
+	u8 addr[ETH_ALEN];
 	ENTER;
 
 	macAddress[2] = READ_REG(priv, regUNC_MAC0_A);
@@ -849,9 +850,10 @@ static int bdx_read_mac(struct bdx_priv *priv)
 	macAddress[0] = READ_REG(priv, regUNC_MAC2_A);
 	macAddress[0] = READ_REG(priv, regUNC_MAC2_A);
 	for (i = 0; i < 3; i++) {
-		priv->ndev->dev_addr[i * 2 + 1] = macAddress[i];
-		priv->ndev->dev_addr[i * 2] = macAddress[i] >> 8;
+		addr[i * 2 + 1] = macAddress[i];
+		addr[i * 2] = macAddress[i] >> 8;
 	}
+	eth_hw_addr_set(priv->ndev, addr);
 	RET(0);
 }
 
Signature · 1 line
2.31.1
author maintainer
#5 lore raw

PATCH 4/6 ethernet: tlan: use eth_hw_addr_set()

In reply to Jakub Kicinski

Commit 406f42fa0d3c ("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.

Read the address into an array on the stack, do the swapping, then call eth_hw_addr_set().

---
CC: [email protected]

---
 drivers/net/ethernet/ti/tlan.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/net/ethernet/ti/tlan.c +6 -4
index eab7d78d7c72..741c42c6a417 100644
@@ -817,6 +817,7 @@ static int tlan_init(struct net_device *dev)
 	int		err;
 	int		i;
 	struct tlan_priv	*priv;
+	u8 addr[ETH_ALEN];
 
 	priv = netdev_priv(dev);
 
@@ -842,7 +843,7 @@ static int tlan_init(struct net_device *dev)
 	for (i = 0; i < ETH_ALEN; i++)
 		err |= tlan_ee_read_byte(dev,
 					 (u8) priv->adapter->addr_ofs + i,
-					 (u8 *) &dev->dev_addr[i]);
+					 addr + i);
 	if (err) {
 		pr_err("%s: Error reading MAC from eeprom: %d\n",
 		       dev->name, err);
@@ -850,11 +851,12 @@ static int tlan_init(struct net_device *dev)
 	/* Olicom OC-2325/OC-2326 have the address byte-swapped */
 	if (priv->adapter->addr_ofs == 0xf8) {
 		for (i = 0; i < ETH_ALEN; i += 2) {
-			char tmp = dev->dev_addr[i];
-			dev->dev_addr[i] = dev->dev_addr[i + 1];
-			dev->dev_addr[i + 1] = tmp;
+			char tmp = addr[i];
+			addr[i] = addr[i + 1];
+			addr[i + 1] = tmp;
 		}
 	}
+	eth_hw_addr_set(dev, addr);
 
 	netif_carrier_off(dev);
 
Signature · 1 line
2.31.1
author maintainer
#6 lore raw

PATCH 5/6 ethernet: via-rhine: use eth_hw_addr_set()

In reply to Jakub Kicinski

Commit 406f42fa0d3c ("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.

Read the address into an array on the stack, then call eth_hw_addr_set().

---
CC: [email protected]

---
 drivers/net/ethernet/via/via-rhine.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/via/via-rhine.c +3 -1
index 3b73a9c55a5a..509c5e9b29df 100644
@@ -899,6 +899,7 @@ static int rhine_init_one_common(struct device *hwdev, u32 quirks,
 	struct net_device *dev;
 	struct rhine_private *rp;
 	int i, rc, phy_id;
+	u8 addr[ETH_ALEN];
 	const char *name;
 
 	/* this should always be supported */
@@ -933,7 +934,8 @@ static int rhine_init_one_common(struct device *hwdev, u32 quirks,
 	rhine_hw_init(dev, pioaddr);
 
 	for (i = 0; i < 6; i++)
-		dev->dev_addr[i] = ioread8(ioaddr + StationAddr + i);
+		addr[i] = ioread8(ioaddr + StationAddr + i);
+	eth_hw_addr_set(dev, addr);
 
 	if (!is_valid_ether_addr(dev->dev_addr)) {
 		/* Report it and use a random ethernet address instead */
Signature · 1 line
2.31.1
author maintainer
#7 lore raw

PATCH 6/6 ethernet: via-velocity: use eth_hw_addr_set()

In reply to Jakub Kicinski

Commit 406f42fa0d3c ("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.

Read the address into an array on the stack, then call eth_hw_addr_set().

---
CC: [email protected]

---
 drivers/net/ethernet/via/via-velocity.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/via/via-velocity.c +3 -1
index 4b9c30f735b5..be2b992f24d9 100644
@@ -2767,6 +2767,7 @@ static int velocity_probe(struct device *dev, int irq,
 	struct velocity_info *vptr;
 	struct mac_regs __iomem *regs;
 	int ret = -ENOMEM;
+	u8 addr[ETH_ALEN];
 
 	/* FIXME: this driver, like almost all other ethernet drivers,
 	 * can support more than MAX_UNITS.
@@ -2820,7 +2821,8 @@ static int velocity_probe(struct device *dev, int irq,
 	mac_wol_reset(regs);
 
 	for (i = 0; i < 6; i++)
-		netdev->dev_addr[i] = readb(&regs->PAR[i]);
+		addr[i] = readb(&regs->PAR[i]);
+	eth_hw_addr_set(netdev, addr);
 
 
 	velocity_get_options(&vptr->options, velocity_nics);
Signature · 1 line
2.31.1
#8 lore raw
In reply to Jakub Kicinski
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Quoted 11 lines · On Tue, 19 Oct 2021 08:00:05 -0700 you wrote:

Manual conversions of Ethernet drivers writing directly to netdev->dev_addr (part 3 out of 3).

Jakub Kicinski (6):
ethernet: netsec: use eth_hw_addr_set()
ethernet: stmmac: use eth_hw_addr_set()
ethernet: tehuti: use eth_hw_addr_set()
ethernet: tlan: use eth_hw_addr_set()
ethernet: via-rhine: use eth_hw_addr_set()
ethernet: via-velocity: use eth_hw_addr_set()

Quoted 1 line

[...]

Here is the summary with links:
- [net-next,1/6] ethernet: netsec: use eth_hw_addr_set()

    https://git.kernel.org/netdev/net-next/c/414c6a3c84d7
  - [net-next,2/6] ethernet: stmmac: use eth_hw_addr_set()
    https://git.kernel.org/netdev/net-next/c/7f9b8fe5445c
  - [net-next,3/6] ethernet: tehuti: use eth_hw_addr_set()
    https://git.kernel.org/netdev/net-next/c/3d9c64ca52d5
  - [net-next,4/6] ethernet: tlan: use eth_hw_addr_set()
    https://git.kernel.org/netdev/net-next/c/41a19eb084f0
  - [net-next,5/6] ethernet: via-rhine: use eth_hw_addr_set()
    https://git.kernel.org/netdev/net-next/c/83f262babdde
  - [net-next,6/6] ethernet: via-velocity: use eth_hw_addr_set()
    https://git.kernel.org/netdev/net-next/c/0b271c48d9c5

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html