net: remove direct netdev->dev_addr writes
Subsystems (9)
Jakub Kicinski
maintainercover net: remove direct netdev->dev_addr writes
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.
This series contains top 5 conversions in terms of LoC required to bring the driver into compliance.
Jakub Kicinski (5):
ethernet: forcedeth: remove direct netdev->dev_addr writes
ethernet: tg3: remove direct netdev->dev_addr writes
ethernet: tulip: remove direct netdev->dev_addr writes
ethernet: sun: remove direct netdev->dev_addr writes
ethernet: 8390: remove direct netdev->dev_addr writes
drivers/net/ethernet/8390/apne.c | 3 +- drivers/net/ethernet/8390/ax88796.c | 6 ++- drivers/net/ethernet/8390/axnet_cs.c | 7 ++- drivers/net/ethernet/8390/mcf8390.c | 3 +- drivers/net/ethernet/8390/ne.c | 4 +- drivers/net/ethernet/8390/pcnet_cs.c | 22 ++++++--- drivers/net/ethernet/8390/stnic.c | 5 +-- drivers/net/ethernet/8390/zorro8390.c | 3 +- drivers/net/ethernet/broadcom/tg3.c | 48 ++++++++++---------- drivers/net/ethernet/dec/tulip/de2104x.c | 15 ++++--- drivers/net/ethernet/dec/tulip/de4x5.c | 35 +++++++-------- drivers/net/ethernet/dec/tulip/dmfe.c | 9 ++-- drivers/net/ethernet/dec/tulip/tulip_core.c | 37 +++++++++------- drivers/net/ethernet/dec/tulip/uli526x.c | 11 +++-- drivers/net/ethernet/dec/tulip/xircom_cb.c | 4 +- drivers/net/ethernet/nvidia/forcedeth.c | 49 +++++++++++---------- drivers/net/ethernet/sun/cassini.c | 7 +-- drivers/net/ethernet/sun/ldmvsw.c | 7 +-- drivers/net/ethernet/sun/niu.c | 42 ++++++++++-------- drivers/net/ethernet/sun/sungem.c | 11 +++-- drivers/net/ethernet/sun/sunhme.c | 15 +++++-- 21 files changed, 191 insertions(+), 152 deletions(-)
Signature · 1 line
2.31.1
Jakub Kicinski
maintainerPATCH 1/5 ethernet: forcedeth: remove direct netdev->dev_addr writes
forcedeth writes to dev_addr byte by byte, make it use a local buffer instead. Commit the changes with eth_hw_addr_set() at the end.
---
CC: Rain River <[email protected]>
CC: Zhu Yanjun <[email protected]>
--- drivers/net/ethernet/nvidia/forcedeth.c | 49 +++++++++++++------------ 1 file changed, 26 insertions(+), 23 deletions(-)
drivers/net/ethernet/nvidia/forcedeth.c +26 -23
@@ -5711,6 +5711,7 @@ static int nv_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)u32 phystate_orig =0 , phystate;int phyinitialized =0 ;static int printed_version; +u8 mac[ETH_ALEN ];if (!printed_version++) pr_info("Reverse Engineered nForce ethernet driver. Version %s.\n",
@@ -5884,50 +5885,52 @@ static int nv_probe(struct pci_dev *pci_dev, const struct pci_device_id *id) txreg =readl (base + NvRegTransmitPoll);if (id->driver_data &DEV_HAS_CORRECT_MACADDR ) {/* mac address is already in correct order */ - dev->dev_addr[0 ] = (np->orig_mac[0 ] >>0 ) &0xff ; - dev->dev_addr[1 ] = (np->orig_mac[0 ] >>8 ) &0xff ; - dev->dev_addr[2 ] = (np->orig_mac[0 ] >>16 ) &0xff ; - dev->dev_addr[3 ] = (np->orig_mac[0 ] >>24 ) &0xff ; - dev->dev_addr[4 ] = (np->orig_mac[1 ] >>0 ) &0xff ; - dev->dev_addr[5 ] = (np->orig_mac[1 ] >>8 ) &0xff ; + mac[0 ] = (np->orig_mac[0 ] >>0 ) &0xff ; + mac[1 ] = (np->orig_mac[0 ] >>8 ) &0xff ; + mac[2 ] = (np->orig_mac[0 ] >>16 ) &0xff ; + mac[3 ] = (np->orig_mac[0 ] >>24 ) &0xff ; + mac[4 ] = (np->orig_mac[1 ] >>0 ) &0xff ; + mac[5 ] = (np->orig_mac[1 ] >>8 ) &0xff ; }else if (txreg &NVREG_TRANSMITPOLL_MAC_ADDR_REV ) {/* mac address is already in correct order */ - dev->dev_addr[0 ] = (np->orig_mac[0 ] >>0 ) &0xff ; - dev->dev_addr[1 ] = (np->orig_mac[0 ] >>8 ) &0xff ; - dev->dev_addr[2 ] = (np->orig_mac[0 ] >>16 ) &0xff ; - dev->dev_addr[3 ] = (np->orig_mac[0 ] >>24 ) &0xff ; - dev->dev_addr[4 ] = (np->orig_mac[1 ] >>0 ) &0xff ; - dev->dev_addr[5 ] = (np->orig_mac[1 ] >>8 ) &0xff ; + mac[0 ] = (np->orig_mac[0 ] >>0 ) &0xff ; + mac[1 ] = (np->orig_mac[0 ] >>8 ) &0xff ; + mac[2 ] = (np->orig_mac[0 ] >>16 ) &0xff ; + mac[3 ] = (np->orig_mac[0 ] >>24 ) &0xff ; + mac[4 ] = (np->orig_mac[1 ] >>0 ) &0xff ; + mac[5 ] = (np->orig_mac[1 ] >>8 ) &0xff ;/* * Set orig mac address back to the reversed version. * This flag will be cleared during low power transition. * Therefore, we should always put back the reversed address. */ - np->orig_mac[0 ] = (dev->dev_addr[5 ] <<0 ) + (dev->dev_addr[4 ] <<8 ) + - (dev->dev_addr[3 ] <<16 ) + (dev->dev_addr[2 ] <<24 ); - np->orig_mac[1 ] = (dev->dev_addr[1 ] <<0 ) + (dev->dev_addr[0 ] <<8 ); + np->orig_mac[0 ] = (mac[5 ] <<0 ) + (mac[4 ] <<8 ) + + (mac[3 ] <<16 ) + (mac[2 ] <<24 ); + np->orig_mac[1 ] = (mac[1 ] <<0 ) + (mac[0 ] <<8 ); }else {/* need to reverse mac address to correct order */ - dev->dev_addr[0 ] = (np->orig_mac[1 ] >>8 ) &0xff ; - dev->dev_addr[1 ] = (np->orig_mac[1 ] >>0 ) &0xff ; - dev->dev_addr[2 ] = (np->orig_mac[0 ] >>24 ) &0xff ; - dev->dev_addr[3 ] = (np->orig_mac[0 ] >>16 ) &0xff ; - dev->dev_addr[4 ] = (np->orig_mac[0 ] >>8 ) &0xff ; - dev->dev_addr[5 ] = (np->orig_mac[0 ] >>0 ) &0xff ; + mac[0 ] = (np->orig_mac[1 ] >>8 ) &0xff ; + mac[1 ] = (np->orig_mac[1 ] >>0 ) &0xff ; + mac[2 ] = (np->orig_mac[0 ] >>24 ) &0xff ; + mac[3 ] = (np->orig_mac[0 ] >>16 ) &0xff ; + mac[4 ] = (np->orig_mac[0 ] >>8 ) &0xff ; + mac[5 ] = (np->orig_mac[0 ] >>0 ) &0xff ;writel (txreg|NVREG_TRANSMITPOLL_MAC_ADDR_REV , base + NvRegTransmitPoll);dev_dbg (&pci_dev->dev,"%s: set workaround bit for reversed mac addr\n" , __func__); } -if (!is_valid_ether_addr (dev->dev_addr)) { +if (is_valid_ether_addr (mac)) { +eth_hw_addr_set (dev, mac); + }else {/* * Bad mac address. At least one bios sets the mac address * to 01:23:45:67:89:ab */ dev_err (&pci_dev->dev,"Invalid MAC address detected: %pM - Please complain to your hardware vendor.\n" , - dev->dev_addr); + mac);eth_hw_addr_random (dev);dev_err (&pci_dev->dev,"Using random MAC address: %pM\n" , dev->dev_addr);
Signature · 1 line
2.31.1
Jakub Kicinski
maintainerPATCH 2/5 ethernet: tg3: remove direct netdev->dev_addr writes
In reply to Jakub Kicinskitg3 does various forms of direct writes to netdev->dev_addr. Use a local buffer. Make sure local buffer is aligned since eth_platform_get_mac_address() may call ether_addr_copy().
tg3_get_device_address() returns whenever it finds a method that found a valid address. Instead of modifying all the exit points pass the buffer from the outside and commit the address in the caller.
Constify the argument of the set addr helper.
---
CC: Siva Reddy Kallam <[email protected]>
CC: Prashant Sreedharan <[email protected]>
CC: Michael Chan <[email protected]>
--- drivers/net/ethernet/broadcom/tg3.c | 48 +++++++++++++++-------------- 1 file changed, 25 insertions(+), 23 deletions(-)
drivers/net/ethernet/broadcom/tg3.c +25 -23
@@ -3942,7 +3942,8 @@ static int tg3_load_tso_firmware(struct tg3 *tp) }/* tp->lock is held. */ -static void __tg3_set_one_mac_addr (struct tg3 *tp,u8 *mac_addr,int index) +static void __tg3_set_one_mac_addr (struct tg3 *tp,const u8 *mac_addr, +int index) {u32 addr_high, addr_low;
@@ -16911,19 +16912,18 @@ static int tg3_get_invariants(struct tg3 *tp, const struct pci_device_id *ent)return err; } -static int tg3_get_device_address (struct tg3 *tp) +static int tg3_get_device_address (struct tg3 *tp,u8 *addr) { -struct net_device *dev = tp->dev;u32 hi, lo, mac_offset;int addr_ok =0 ;int err; -if (!eth_platform_get_mac_address (&tp->pdev->dev, dev->dev_addr)) +if (!eth_platform_get_mac_address (&tp->pdev->dev, addr))return 0 ;if (tg3_flag (tp,IS_SSB_CORE )) { - err =ssb_gige_get_macaddr (tp->pdev, &dev->dev_addr[0 ]); -if (!err &&is_valid_ether_addr (&dev->dev_addr[0 ])) + err =ssb_gige_get_macaddr (tp->pdev, addr); +if (!err &&is_valid_ether_addr (addr))return 0 ; }
@@ -16947,41 +16947,41 @@ static int tg3_get_device_address(struct tg3 *tp)/* First try to get it from MAC address mailbox. */ tg3_read_mem (tp,NIC_SRAM_MAC_ADDR_HIGH_MBOX , &hi);if ((hi >>16 ) ==0x484b ) { - dev->dev_addr[0 ] = (hi >>8 ) &0xff ; - dev->dev_addr[1 ] = (hi >>0 ) &0xff ; + addr[0 ] = (hi >>8 ) &0xff ; + addr[1 ] = (hi >>0 ) &0xff ;tg3_read_mem (tp,NIC_SRAM_MAC_ADDR_LOW_MBOX , &lo); - dev->dev_addr[2 ] = (lo >>24 ) &0xff ; - dev->dev_addr[3 ] = (lo >>16 ) &0xff ; - dev->dev_addr[4 ] = (lo >>8 ) &0xff ; - dev->dev_addr[5 ] = (lo >>0 ) &0xff ; + addr[2 ] = (lo >>24 ) &0xff ; + addr[3 ] = (lo >>16 ) &0xff ; + addr[4 ] = (lo >>8 ) &0xff ; + addr[5 ] = (lo >>0 ) &0xff ;/* Some old bootcode may report a 0 MAC address in SRAM */ - addr_ok =is_valid_ether_addr (&dev->dev_addr[0 ]); + addr_ok =is_valid_ether_addr (addr); }if (!addr_ok) {/* Next, try NVRAM. */ if (!tg3_flag (tp,NO_NVRAM ) && !tg3_nvram_read_be32 (tp, mac_offset +0 , &hi) && !tg3_nvram_read_be32 (tp, mac_offset +4 , &lo)) { -memcpy (&dev->dev_addr[0 ], ((char *)&hi) +2 ,2 ); -memcpy (&dev->dev_addr[2 ], (char *)&lo,sizeof (lo)); +memcpy (&addr[0 ], ((char *)&hi) +2 ,2 ); +memcpy (&addr[2 ], (char *)&lo,sizeof (lo)); }/* Finally just fetch it out of the MAC control regs. */ else { hi =tr32 (MAC_ADDR_0_HIGH ); lo =tr32 (MAC_ADDR_0_LOW ); - dev->dev_addr[5 ] = lo &0xff ; - dev->dev_addr[4 ] = (lo >>8 ) &0xff ; - dev->dev_addr[3 ] = (lo >>16 ) &0xff ; - dev->dev_addr[2 ] = (lo >>24 ) &0xff ; - dev->dev_addr[1 ] = hi &0xff ; - dev->dev_addr[0 ] = (hi >>8 ) &0xff ; + addr[5 ] = lo &0xff ; + addr[4 ] = (lo >>8 ) &0xff ; + addr[3 ] = (lo >>16 ) &0xff ; + addr[2 ] = (lo >>24 ) &0xff ; + addr[1 ] = hi &0xff ; + addr[0 ] = (hi >>8 ) &0xff ; } } -if (!is_valid_ether_addr (&dev->dev_addr[0 ])) +if (!is_valid_ether_addr (addr))return -EINVAL ;return 0 ; }
@@ -17557,6 +17557,7 @@ static int tg3_init_one(struct pci_dev *pdev,char str[40 ];u64 dma_mask, persist_dma_mask;netdev_features_t features =0 ; +u8 addr[ETH_ALEN ]__aligned(2) ; err =pci_enable_device (pdev);if (err) {
@@ -17779,12 +17780,13 @@ static int tg3_init_one(struct pci_dev *pdev, tp->rx_pending =63 ; } - err =tg3_get_device_address (tp); + err =tg3_get_device_address (tp, addr);if (err) {dev_err (&pdev->dev,"Could not obtain valid ethernet address, aborting\n" ); goto err_out_apeunmap; } +eth_hw_addr_set (dev, addr); intmbx =MAILBOX_INTERRUPT_0 +TG3_64BIT_REG_LOW ; rcvmbx =MAILBOX_RCVRET_CON_IDX_0 +TG3_64BIT_REG_LOW ;
Signature · 1 line
2.31.1
Jakub Kicinski
maintainerPATCH 3/5 ethernet: tulip: remove direct netdev->dev_addr writes
In reply to Jakub KicinskiConsify the casts of netdev->dev_addr.
Convert pointless to eth_hw_addr_set() where possible.
Use local buffers in a number of places.
--- drivers/net/ethernet/dec/tulip/de2104x.c | 15 +++++---- drivers/net/ethernet/dec/tulip/de4x5.c | 35 ++++++++++--------- drivers/net/ethernet/dec/tulip/dmfe.c | 9 +++-- drivers/net/ethernet/dec/tulip/tulip_core.c | 37 ++++++++++++--------- drivers/net/ethernet/dec/tulip/uli526x.c | 11 +++--- drivers/net/ethernet/dec/tulip/xircom_cb.c | 4 ++- 6 files changed, 61 insertions(+), 50 deletions(-)
drivers/net/ethernet/dec/tulip/de2104x.c +8 -7
@@ -666,8 +666,8 @@ static void build_setup_frame_hash(u16 *setup_frm, struct net_device *dev)struct de_private *de =netdev_priv (dev);u16 hash_table[32 ];struct netdev_hw_addr *ha; +const u16 *eaddrs;int i; -u16 *eaddrs;memset (hash_table,0 ,sizeof (hash_table));__set_bit_le (255 , hash_table);/* Broadcast entry */
@@ -685,7 +685,7 @@ static void build_setup_frame_hash(u16 *setup_frm, struct net_device *dev) setup_frm = &de->setup_frame[13 *6 ];/* Fill the final entry with our physical address. */ - eaddrs = (u16 *)dev->dev_addr; + eaddrs = (const u16 *)dev->dev_addr; *setup_frm++ = eaddrs[0 ]; *setup_frm++ = eaddrs[0 ]; *setup_frm++ = eaddrs[1 ]; *setup_frm++ = eaddrs[1 ]; *setup_frm++ = eaddrs[2 ]; *setup_frm++ = eaddrs[2 ];
@@ -695,7 +695,7 @@ static void build_setup_frame_perfect(u16 *setup_frm, struct net_device *dev) {struct de_private *de =netdev_priv (dev);struct netdev_hw_addr *ha; -u16 *eaddrs; +const u16 *eaddrs;/* We have <= 14 addresses so we can use the wonderful 16 address perfect filtering of the Tulip. */
@@ -710,7 +710,7 @@ static void build_setup_frame_perfect(u16 *setup_frm, struct net_device *dev) setup_frm = &de->setup_frame[15 *6 ];/* Fill the final entry with our physical address. */ - eaddrs = (u16 *)dev->dev_addr; + eaddrs = (const u16 *)dev->dev_addr; *setup_frm++ = eaddrs[0 ]; *setup_frm++ = eaddrs[0 ]; *setup_frm++ = eaddrs[1 ]; *setup_frm++ = eaddrs[1 ]; *setup_frm++ = eaddrs[2 ]; *setup_frm++ = eaddrs[2 ];
@@ -1713,6 +1713,7 @@ static const struct ethtool_ops de_ethtool_ops = {static void de21040_get_mac_address (struct de_private *de) { +u8 addr[ETH_ALEN ];unsigned i;dw32 (ROMCmd,0 );/* Reset the pointer with a dummy write. */
@@ -1724,12 +1725,13 @@ static void de21040_get_mac_address(struct de_private *de) value =dr32 (ROMCmd);rmb (); }while (value <0 && --boguscnt >0 ); - de->dev->dev_addr[i] = value; + addr[i] = value;udelay (1 );if (boguscnt <=0 )pr_warn ("timeout reading 21040 MAC address byte %u\n" , i); } +eth_hw_addr_set (de->dev, addr); }static void de21040_get_media_info (struct de_private *de)
@@ -1821,8 +1823,7 @@ static void de21041_get_srom_info(struct de_private *de)#endif /* store MAC address */ -for (i =0 ; i <6 ; i ++) - de->dev->dev_addr[i] = ee_data[i + sa_offset]; +eth_hw_addr_set (de->dev, &ee_data[i + sa_offset]);/* get offset of controller 0 info leaf. ignore 2nd byte. */ ofs = ee_data[SROMC0InfoLeaf];
drivers/net/ethernet/dec/tulip/de4x5.c +17 -18
@@ -4031,6 +4031,7 @@ get_hw_addr(struct net_device *dev)int broken, i, k, tmp, status =0 ;u_short j,chksum;struct de4x5_private *lp =netdev_priv (dev); +u8 addr[ETH_ALEN ]; broken =de4x5_bad_srom (lp);
@@ -4042,28 +4043,30 @@ get_hw_addr(struct net_device *dev)if (lp->chipset ==DC21040 ) {while ((tmp =inl (DE4X5_APROM )) <0 ); k += (u_char ) tmp; - dev->dev_addr[i++] = (u_char ) tmp; + addr[i++] = (u_char ) tmp;while ((tmp =inl (DE4X5_APROM )) <0 ); k += (u_short) (tmp <<8 ); - dev->dev_addr[i++] = (u_char ) tmp; + addr[i++] = (u_char ) tmp; }else if (!broken) { - dev->dev_addr[i] = (u_char ) lp->srom.ieee_addr[i]; i++; - dev->dev_addr[i] = (u_char ) lp->srom.ieee_addr[i]; i++; + addr[i] = (u_char ) lp->srom.ieee_addr[i]; i++; + addr[i] = (u_char ) lp->srom.ieee_addr[i]; i++; }else if ((broken ==SMC ) || (broken ==ACCTON )) { - dev->dev_addr[i] = *((u_char *)&lp->srom + i); i++; - dev->dev_addr[i] = *((u_char *)&lp->srom + i); i++; + addr[i] = *((u_char *)&lp->srom + i); i++; + addr[i] = *((u_char *)&lp->srom + i); i++; } }else { k += (u_char) (tmp =inb (EISA_APROM )); - dev->dev_addr[i++] = (u_char ) tmp; + addr[i++] = (u_char ) tmp; k += (u_short) ((tmp =inb (EISA_APROM )) <<8 ); - dev->dev_addr[i++] = (u_char ) tmp; + addr[i++] = (u_char ) tmp; }if (k >0xffff ) k-=0xffff ; }if (k ==0xffff ) k=0 ; +eth_hw_addr_set (dev, addr); +if (lp->bus ==PCI ) {if (lp->chipset ==DC21040 ) {while ((tmp =inl (DE4X5_APROM )) <0 );
@@ -4095,8 +4098,9 @@ get_hw_addr(struct net_device *dev)int x = dev->dev_addr[i]; x = ((x &0xf ) <<4 ) + ((x &0xf0 ) >>4 ); x = ((x &0x33 ) <<2 ) + ((x &0xcc ) >>2 ); - dev->dev_addr[i] = ((x & 0x55) << 1) + ((x & 0xaa) >> 1); + addr[i] = ((x & 0x55) << 1) + ((x & 0xaa) >> 1); } +eth_hw_addr_set (dev, addr); }#endif /* CONFIG_PPC_PMAC */
@@ -4158,12 +4162,9 @@ test_bad_enet(struct net_device *dev, int status)if ((tmp ==0 ) || (tmp ==0x5fa )) {if ((lp->chipset == last.chipset) && (lp->bus_num == last.bus) && (lp->bus_num >0 )) { -for (i=0 ; i<ETH_ALEN ; i++) dev->dev_addr[i] = last.addr[i]; -for (i=ETH_ALEN -1 ; i>2 ; --i) { - dev->dev_addr[i] +=1 ; -if (dev->dev_addr[i] !=0 )break ; - } -for (i=0 ; i<ETH_ALEN ; i++) last.addr[i] = dev->dev_addr[i]; +eth_addr_inc (last.addr); +eth_hw_addr_set (dev, last.addr); +if (!an_exception (lp)) { dev->irq = last.irq; }
@@ -5391,9 +5392,7 @@ de4x5_siocdevprivate(struct net_device *dev, struct ifreq *rq, void __user *dataif (netif_queue_stopped (dev))return -EBUSY ;netif_stop_queue (dev); -for (i=0 ; i<ETH_ALEN ; i++) { - dev->dev_addr[i] = tmp.addr[i]; - } +eth_hw_addr_set (dev, tmp.addr);build_setup_frame (dev,PHYS_ADDR_ONLY );/* Set up the descriptor and give ownership to the card */ load_packet(dev, lp->setup_frame, TD_IC | PERFECT_F | TD_SET |
drivers/net/ethernet/dec/tulip/dmfe.c +4 -5
@@ -476,8 +476,7 @@ static int dmfe_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) }/* Set Node address */ -for (i =0 ; i <6 ; i++) - dev->dev_addr[i] = db->srom[20 + i]; +eth_hw_addr_set (dev, &db->srom[20 + i]); err =register_netdev (dev);if (err)
@@ -1436,9 +1435,9 @@ static void update_cr6(u32 cr6_data, void __iomem *ioaddr)static void dm9132_id_table (struct net_device *dev) { +const u16 *addrptr = (const u16 *)dev->dev_addr;struct dmfe_board_info *db =netdev_priv (dev);void __iomem *ioaddr = db->ioaddr +0xc0 ; -u16 *addrptr = (u16 *)dev->dev_addr;struct netdev_hw_addr *ha;u16 i, hash_table[4 ];
@@ -1477,7 +1476,7 @@ static void send_filter_frame(struct net_device *dev)struct dmfe_board_info *db =netdev_priv (dev);struct netdev_hw_addr *ha;struct tx_desc *txptr; -u16 * addrptr; +const u16 * addrptr;u32 * suptr;int i;
@@ -1487,7 +1486,7 @@ static void send_filter_frame(struct net_device *dev) suptr = (u32 *) txptr->tx_buf_ptr;/* Node address */ - addrptr = (u16 *) dev->dev_addr; + addrptr = (const u16 *) dev->dev_addr; *suptr++ = addrptr[0 ]; *suptr++ = addrptr[1 ]; *suptr++ = addrptr[2 ];
drivers/net/ethernet/dec/tulip/tulip_core.c +22 -15
@@ -339,7 +339,7 @@ static void tulip_up(struct net_device *dev) } }else {/* This is set_rx_mode(), but without starting the transmitter. */ -u16 *eaddrs = (u16 *)dev->dev_addr; +const u16 *eaddrs = (const u16 *)dev->dev_addr;u16 *setup_frm = &tp->setup_frame[15 *6 ];dma_addr_t mapping;
@@ -1001,8 +1001,8 @@ static void build_setup_frame_hash(u16 *setup_frm, struct net_device *dev)struct tulip_private *tp =netdev_priv (dev);u16 hash_table[32 ];struct netdev_hw_addr *ha; +const u16 *eaddrs;int i; -u16 *eaddrs;memset (hash_table,0 ,sizeof (hash_table));__set_bit_le (255 , hash_table);/* Broadcast entry */
@@ -1019,7 +1019,7 @@ static void build_setup_frame_hash(u16 *setup_frm, struct net_device *dev) setup_frm = &tp->setup_frame[13 *6 ];/* Fill the final entry with our physical address. */ - eaddrs = (u16 *)dev->dev_addr; + eaddrs = (const u16 *)dev->dev_addr; *setup_frm++ = eaddrs[0 ]; *setup_frm++ = eaddrs[0 ]; *setup_frm++ = eaddrs[1 ]; *setup_frm++ = eaddrs[1 ]; *setup_frm++ = eaddrs[2 ]; *setup_frm++ = eaddrs[2 ];
@@ -1029,7 +1029,7 @@ static void build_setup_frame_perfect(u16 *setup_frm, struct net_device *dev) {struct tulip_private *tp =netdev_priv (dev);struct netdev_hw_addr *ha; -u16 *eaddrs; +const u16 *eaddrs;/* We have <= 14 addresses so we can use the wonderful 16 address perfect filtering of the Tulip. */
@@ -1044,7 +1044,7 @@ static void build_setup_frame_perfect(u16 *setup_frm, struct net_device *dev) setup_frm = &tp->setup_frame[15 *6 ];/* Fill the final entry with our physical address. */ - eaddrs = (u16 *)dev->dev_addr; + eaddrs = (const u16 *)dev->dev_addr; *setup_frm++ = eaddrs[0 ]; *setup_frm++ = eaddrs[0 ]; *setup_frm++ = eaddrs[1 ]; *setup_frm++ = eaddrs[1 ]; *setup_frm++ = eaddrs[2 ]; *setup_frm++ = eaddrs[2 ];
@@ -1305,6 +1305,7 @@ static int tulip_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)int chip_idx = ent->driver_data;const char *chip_name = tulip_tbl[chip_idx].chip_name;unsigned int eeprom_missing =0 ; +u8 addr[ETH_ALEN ]__aligned(2) ;unsigned int force_csr0 =0 ; board_idx++;
@@ -1506,13 +1507,15 @@ static int tulip_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)do { value =ioread32 (ioaddr +CSR9 ); }while (value <0 && --boguscnt >0 ); -put_unaligned_le16 (value, ((__le16 *)dev->dev_addr) + i); +put_unaligned_le16 (value, ((__le16 *)addr) + i); sum += value &0xffff ; } +eth_hw_addr_set (dev, addr); }else if (chip_idx ==COMET ) {/* No need to read the EEPROM. */ -put_unaligned_le32 (ioread32 (ioaddr +0xA4 ), dev->dev_addr); -put_unaligned_le16 (ioread32 (ioaddr +0xA8 ), dev->dev_addr +4 ); +put_unaligned_le32 (ioread32 (ioaddr +0xA4 ), addr); +put_unaligned_le16 (ioread32 (ioaddr +0xA8 ), addr +4 ); +eth_hw_addr_set (dev, addr);for (i =0 ; i <6 ; i ++) sum += dev->dev_addr[i]; }else {
@@ -1575,20 +1578,23 @@ static int tulip_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)#endif for (i =0 ; i <6 ; i ++) { - dev->dev_addr[i] = ee_data[i + sa_offset]; + addr[i] = ee_data[i + sa_offset]; sum += ee_data[i + sa_offset]; } +eth_hw_addr_set (dev, addr); }/* Lite-On boards have the address byte-swapped. */ if ((dev->dev_addr[0 ] ==0xA0 || dev->dev_addr[0 ] ==0xC0 || dev->dev_addr[0 ] ==0x02 ) && - dev->dev_addr[1 ] ==0x00 ) + dev->dev_addr[1 ] ==0x00 ) {for (i =0 ; i <6 ; i+=2 ) { -char tmp = dev->dev_addr[i]; - dev->dev_addr[i] = dev->dev_addr[i+1 ]; - dev->dev_addr[i+1 ] = tmp; + addr[i] = dev->dev_addr[i+1 ]; + addr[i+1 ] = dev->dev_addr[i]; } +eth_hw_addr_set (dev, addr); + } +/* On the Zynx 315 Etherarray and other multiport boards only the first Tulip has an EEPROM. On Sparc systems the mac address is held in the OBP property
@@ -1604,8 +1610,9 @@ static int tulip_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)#endif eeprom_missing =1 ;for (i =0 ; i <5 ; i++) - dev->dev_addr[i] = last_phys_addr[i]; - dev->dev_addr[i] = last_phys_addr[i] +1 ; + addr[i] = last_phys_addr[i]; + addr[i] = last_phys_addr[i] +1 ; +eth_hw_addr_set (dev, addr);#if defined(CONFIG_SPARC ) addr =of_get_property (dp,"local-mac-address" , &len);if (addr && len ==ETH_ALEN )
drivers/net/ethernet/dec/tulip/uli526x.c +7 -4
@@ -272,6 +272,7 @@ static int uli526x_init_one(struct pci_dev *pdev,struct uli526x_board_info *db;/* board information structure */ struct net_device *dev;void __iomem *ioaddr; +u8 addr[ETH_ALEN ];int i, err;ULI526X_DBUG (0 ,"uli526x_init_one()" ,0 );
@@ -379,7 +380,7 @@ static int uli526x_init_one(struct pci_dev *pdev,uw32 (DCR13 ,0x1b0 );//Select ID Table access port //Read MAC address from CR14 for (i =0 ; i <6 ; i++) - dev->dev_addr[i] =ur32 (DCR14 ); + addr[i] =ur32 (DCR14 );//Read end uw32 (DCR13 ,0 );//Clear CR13 uw32 (DCR0 ,0 );//Clear CR0
@@ -388,8 +389,10 @@ static int uli526x_init_one(struct pci_dev *pdev, else /*Exist SROM*/ {for (i =0 ; i <6 ; i++) - dev->dev_addr[i] = db->srom[20 + i]; + addr[i] = db->srom[20 + i]; } +eth_hw_addr_set (dev, addr); + err =register_netdev (dev);if (err) goto err_out_unmap;
@@ -1343,7 +1346,7 @@ static void send_filter_frame(struct net_device *dev, int mc_cnt)void __iomem *ioaddr = db->ioaddr;struct netdev_hw_addr *ha;struct tx_desc *txptr; -u16 * addrptr; +const u16 * addrptr;u32 * suptr;int i;
@@ -1353,7 +1356,7 @@ static void send_filter_frame(struct net_device *dev, int mc_cnt) suptr = (u32 *) txptr->tx_buf_ptr;/* Node address */ - addrptr = (u16 *) dev->dev_addr; + addrptr = (const u16 *) dev->dev_addr; *suptr++ = addrptr[0 ] <<FLT_SHIFT ; *suptr++ = addrptr[1 ] <<FLT_SHIFT ; *suptr++ = addrptr[2 ] <<FLT_SHIFT ;
drivers/net/ethernet/dec/tulip/xircom_cb.c +3 -1
@@ -1015,12 +1015,14 @@ static void read_mac_address(struct xircom_private *card)xw32 (CSR10 , i +3 ); data_count =xr32 (CSR9 );if ((tuple ==0x22 ) && (data_id ==0x04 ) && (data_count ==0x06 )) { +u8 addr[ETH_ALEN ];int j;for (j =0 ; j <6 ; j++) {xw32 (CSR10 , i + j +4 ); - card->dev->dev_addr[j] =xr32 (CSR9 ) &0xff ; + addr[j] =xr32 (CSR9 ) &0xff ; } +eth_hw_addr_set (card->dev, addr);break ; }else if (link ==0 ) {break ;
Signature · 1 line
2.31.1
Jakub Kicinski
maintainerPATCH 4/5 ethernet: sun: remove direct netdev->dev_addr writes
In reply to Jakub KicinskiConsify temporary variables pointing to netdev->dev_addr.
A few places need local storage but pretty simple conversion over all. Note that macaddr[] is an array of ints, so we need to keep the loops.
--- drivers/net/ethernet/sun/cassini.c | 7 ++--- drivers/net/ethernet/sun/ldmvsw.c | 7 ++--- drivers/net/ethernet/sun/niu.c | 42 +++++++++++++++++------------- drivers/net/ethernet/sun/sungem.c | 11 +++++--- drivers/net/ethernet/sun/sunhme.c | 15 ++++++++--- 5 files changed, 48 insertions(+), 34 deletions(-)
drivers/net/ethernet/sun/cassini.c +4 -3
@@ -3027,7 +3027,7 @@ static void cas_mac_reset(struct cas *cp)/* Must be invoked under cp->lock. */ static void cas_init_mac (struct cas *cp) { -unsigned char *e = &cp->dev->dev_addr[0 ]; +const unsigned char *e = &cp->dev->dev_addr[0 ];int i;cas_mac_reset (cp);
@@ -3379,6 +3379,7 @@ static void cas_check_pci_invariants(struct cas *cp)static int cas_check_invariants (struct cas *cp) {struct pci_dev *pdev = cp->pdev; +u8 addr[ETH_ALEN ];u32 cfg;int i;
@@ -3407,8 +3408,8 @@ static int cas_check_invariants(struct cas *cp)/* finish phy determination. MDIO1 takes precedence over MDIO0 if * they're both connected. */ - cp->phy_type =cas_get_vpd_info (cp, cp->dev->dev_addr, -PCI_SLOT (pdev->devfn)); + cp->phy_type =cas_get_vpd_info (cp, addr,PCI_SLOT (pdev->devfn)); +eth_hw_addr_set (cp->dev, addr);if (cp->phy_type &CAS_PHY_SERDES ) { cp->cas_flags |=CAS_FLAG_1000MB_CAP ;return 0 ;/* no more checking needed */
drivers/net/ethernet/sun/ldmvsw.c +2 -5
@@ -230,7 +230,6 @@ static struct net_device *vsw_alloc_netdev(u8 hwaddr[], {struct net_device *dev;struct vnet_port *port; -int i; dev =alloc_etherdev_mqs (sizeof (*port),VNET_MAX_TXQS ,1 );if (!dev)
@@ -238,10 +237,8 @@ static struct net_device *vsw_alloc_netdev(u8 hwaddr[], dev->needed_headroom =VNET_PACKET_SKIP +8 ; dev->needed_tailroom =8 ; -for (i =0 ; i <ETH_ALEN ; i++) { - dev->dev_addr[i] = hwaddr[i]; - dev->perm_addr[i] = dev->dev_addr[i]; - } +eth_hw_addr_set (dev, hwaddr); + ether_addr_copy(dev->perm_addr, dev->dev_addr)sprintf (dev->name,"vif%d.%d" , (int )handle, (int )port_id);
drivers/net/ethernet/sun/niu.c +24 -18
81 lines not on this page · raw message
drivers/net/ethernet/sun/sungem.c +7 -4
@@ -1810,7 +1810,7 @@ static u32 gem_setup_multicast(struct gem *gp)static void gem_init_mac (struct gem *gp) { -unsigned char *e = &gp->dev->dev_addr[0 ]; +const unsigned char *e = &gp->dev->dev_addr[0 ];writel (0x1bf0 , gp->regs +MAC_SNDPAUSE );
@@ -2087,7 +2087,7 @@ static void gem_stop_phy(struct gem *gp, int wol)writel (mifcfg, gp->regs +MIF_CFG );if (wol && gp->has_wol) { -unsigned char *e = &gp->dev->dev_addr[0 ]; +const unsigned char *e = &gp->dev->dev_addr[0 ];u32 csr;/* Setup wake-on-lan for MAGIC packet */
@@ -2431,8 +2431,8 @@ static struct net_device_stats *gem_get_stats(struct net_device *dev)static int gem_set_mac_address (struct net_device *dev,void *addr) {struct sockaddr *macaddr = (struct sockaddr *) addr; +const unsigned char *e = &dev->dev_addr[0 ];struct gem *gp =netdev_priv (dev); -unsigned char *e = &dev->dev_addr[0 ];if (!is_valid_ether_addr (macaddr->sa_data))return -EADDRNOTAVAIL ;
@@ -2799,7 +2799,10 @@ static int gem_get_device_address(struct gem *gp) }eth_hw_addr_set (dev, addr);#else -get_gem_mac_nonobp (gp->pdev, gp->dev->dev_addr); +u8 addr[ETH_ALEN ]; + +get_gem_mac_nonobp (gp->pdev, addr); +eth_hw_addr_set (gp->dev, addr);#endif return 0 ; }
drivers/net/ethernet/sun/sunhme.c +11 -4
@@ -1395,13 +1395,13 @@ happy_meal_begin_auto_negotiation(struct happy_meal *hp,/* hp->happy_lock must be held */ static int happy_meal_init (struct happy_meal *hp) { +const unsigned char *e = &hp->dev->dev_addr[0 ];void __iomem *gregs = hp->gregs;void __iomem *etxregs = hp->etxregs;void __iomem *erxregs = hp->erxregs;void __iomem *bregs = hp->bigmacregs;void __iomem *tregs = hp->tcvregs;u32 regtmp, rxcfg; -unsigned char *e = &hp->dev->dev_addr[0 ];/* If auto-negotiation timer is running, kill it. */ del_timer (&hp->happy_timer);
@@ -2661,6 +2661,7 @@ static int happy_meal_sbus_probe_one(struct platform_device *op, int is_qfe)struct happy_meal *hp;struct net_device *dev;int i, qfe_slot =-1 ; +u8 addr[ETH_ALEN ];int err = -ENODEV ; sbus_dp = op->dev.parent->of_node;
@@ -2698,7 +2699,8 @@ static int happy_meal_sbus_probe_one(struct platform_device *op, int is_qfe) }if (i <6 ) {/* a mac address was given */ for (i =0 ; i <6 ; i++) - dev->dev_addr[i] = macaddr[i]; + addr[i] = macaddr[i]; +eth_hw_addr_set (dev, addr); macaddr[5 ]++; }else {const unsigned char *addr;
@@ -2969,6 +2971,7 @@ static int happy_meal_pci_probe(struct pci_dev *pdev,unsigned long hpreg_res;int i, qfe_slot =-1 ;char prom_name[64 ]; +u8 addr[ETH_ALEN ];int err;/* Now make sure pci_dev cookie is there. */
@@ -3044,7 +3047,8 @@ static int happy_meal_pci_probe(struct pci_dev *pdev, }if (i <6 ) {/* a mac address was given */ for (i =0 ; i <6 ; i++) - dev->dev_addr[i] = macaddr[i]; + addr[i] = macaddr[i]; +eth_hw_addr_set (dev, addr); macaddr[5 ]++; }else {#ifdef CONFIG_SPARC
@@ -3060,7 +3064,10 @@ static int happy_meal_pci_probe(struct pci_dev *pdev, eth_hw_addr_set(dev, idprom->id_ethaddr); }#else -get_hme_mac_nonsparc (pdev, &dev->dev_addr[0 ]); +u8 addr[ETH_ALEN ]; + +get_hme_mac_nonsparc (pdev, addr); +eth_hw_addr_set (dev, addr);#endif }
Signature · 1 line
2.31.1
Jakub Kicinski
maintainerPATCH 5/5 ethernet: 8390: remove direct netdev->dev_addr writes
In reply to Jakub Kicinski8390 contains a lot of loops assigning netdev->dev_addr byte by byte. Convert what's possible directly to eth_hw_addr_set(), use local buf in other places.
--- drivers/net/ethernet/8390/apne.c | 3 +-- drivers/net/ethernet/8390/ax88796.c | 6 ++++-- drivers/net/ethernet/8390/axnet_cs.c | 7 +++++-- drivers/net/ethernet/8390/mcf8390.c | 3 +-- drivers/net/ethernet/8390/ne.c | 4 +--- drivers/net/ethernet/8390/pcnet_cs.c | 22 ++++++++++++++++------ drivers/net/ethernet/8390/stnic.c | 5 ++--- drivers/net/ethernet/8390/zorro8390.c | 3 +-- 8 files changed, 31 insertions(+), 22 deletions(-)
drivers/net/ethernet/8390/apne.c +1 -2
@@ -320,8 +320,7 @@ static int __init apne_probe1(struct net_device *dev, int ioaddr) i =request_irq (dev->irq, apne_interrupt,IRQF_SHARED ,DRV_NAME , dev);if (i)return i; -for (i =0 ; i <ETH_ALEN ; i++) - dev->dev_addr[i] = SA_prom[i]; +eth_hw_addr_set (dev, SA_prom);pr_cont (" %pM\n" , dev->dev_addr);
drivers/net/ethernet/8390/ax88796.c +4 -2
@@ -748,11 +748,13 @@ static int ax_init_dev(struct net_device *dev)/* load the mac-address from the device */ if (ax->plat->flags &AXFLG_MAC_FROMDEV ) { +u8 addr[ETH_ALEN ]; +ei_outb (E8390_NODMA +E8390_PAGE1 +E8390_STOP , ei_local->mem +E8390_CMD );/* 0x61 */ for (i =0 ; i <ETH_ALEN ; i++) - dev->dev_addr[i] = -ei_inb (ioaddr +EN1_PHYS_SHIFT (i)); + addr[i] =ei_inb (ioaddr +EN1_PHYS_SHIFT (i)); +eth_hw_addr_set (dev, addr); } if ((ax->plat->flags & AXFLG_MAC_FROMPLATFORM) &&
drivers/net/ethernet/8390/axnet_cs.c +5 -2
@@ -187,6 +187,7 @@ static int get_prom(struct pcmcia_device *link) {struct net_device *dev = link->priv;unsigned int ioaddr = dev->base_addr; +u8 addr[ETH_ALEN ];int i, j;/* This is based on drivers/net/ethernet/8390/ne.c */
@@ -220,9 +221,11 @@ static int get_prom(struct pcmcia_device *link)for (i =0 ; i <6 ; i +=2 ) { j =inw (ioaddr +AXNET_DATAPORT ); - dev->dev_addr[i] = j &0xff ; - dev->dev_addr[i+1 ] = j >>8 ; + addr[i] = j &0xff ; + addr[i+1 ] = j >>8 ; } +eth_hw_addr_set (dev, addr); +return 1 ; }/* get_prom */
drivers/net/ethernet/8390/mcf8390.c +1 -2
@@ -374,8 +374,7 @@ static int mcf8390_init(struct net_device *dev)if (ret)return ret; -for (i =0 ; i <ETH_ALEN ; i++) - dev->dev_addr[i] = SA_prom[i]; +eth_hw_addr_set (dev, SA_prom);netdev_dbg (dev,"Found ethernet address: %pM\n" , dev->dev_addr);
drivers/net/ethernet/8390/ne.c +1 -3
@@ -500,9 +500,7 @@ static int __init ne_probe1(struct net_device *dev, unsigned long ioaddr) dev->base_addr = ioaddr; -for (i =0 ; i <ETH_ALEN ; i++) { - dev->dev_addr[i] = SA_prom[i]; - } +eth_hw_addr_set (dev, SA_prom);pr_cont ("%pM\n" , dev->dev_addr);
drivers/net/ethernet/8390/pcnet_cs.c +16 -6
@@ -278,6 +278,7 @@ static struct hw_info *get_hwinfo(struct pcmcia_device *link) {struct net_device *dev = link->priv;u_char __iomem *base, *virt; +u8 addr[ETH_ALEN ];int i, j;/* Allocate a small memory window */
@@ -302,7 +303,8 @@ static struct hw_info *get_hwinfo(struct pcmcia_device *link) (readb(base+2) == hw_info[i].a1) && (readb(base+4) == hw_info[i].a2)) {for (j =0 ; j <6 ; j++) - dev->dev_addr[j] =readb (base + (j<<1 )); + addr[j] =readb (base + (j<<1 )); +eth_hw_addr_set (dev, addr);break ; } }
@@ -324,6 +326,7 @@ static struct hw_info *get_prom(struct pcmcia_device *link) {struct net_device *dev = link->priv;unsigned int ioaddr = dev->base_addr; +u8 addr[ETH_ALEN ];u_char prom[32 ];int i, j;
@@ -362,7 +365,8 @@ static struct hw_info *get_prom(struct pcmcia_device *link) }if ((i <NR_INFO ) || ((prom[28 ] ==0x57 ) && (prom[30 ] ==0x57 ))) {for (j =0 ; j <6 ; j++) - dev->dev_addr[j] = prom[j<<1 ]; + addr[j] = prom[j<<1 ]; +eth_hw_addr_set (dev, addr);return (i <NR_INFO ) ? hw_info+i : &default_info; }return NULL ;
@@ -377,6 +381,7 @@ static struct hw_info *get_prom(struct pcmcia_device *link)static struct hw_info *get_dl10019 (struct pcmcia_device *link) {struct net_device *dev = link->priv; +u8 addr[ETH_ALEN ];int i;u_char sum;
@@ -385,7 +390,8 @@ static struct hw_info *get_dl10019(struct pcmcia_device *link)if (sum !=0xff )return NULL ;for (i =0 ; i <6 ; i++) - dev->dev_addr[i] =inb_p (dev->base_addr +0x14 + i); + addr[i] =inb_p (dev->base_addr +0x14 + i); +eth_hw_addr_set (dev, addr); i =inb (dev->base_addr +0x1f );return ((i ==0x91 )||(i ==0x99 )) ? &dl10022_info : &dl10019_info; }
@@ -400,6 +406,7 @@ static struct hw_info *get_ax88190(struct pcmcia_device *link) {struct net_device *dev = link->priv;unsigned int ioaddr = dev->base_addr; +u8 addr[ETH_ALEN ];int i, j;/* Not much of a test, but the alternatives are messy */
@@ -413,9 +420,10 @@ static struct hw_info *get_ax88190(struct pcmcia_device *link)for (i =0 ; i <6 ; i +=2 ) { j =inw (ioaddr +PCNET_DATAPORT ); - dev->dev_addr[i] = j &0xff ; - dev->dev_addr[i+1 ] = j >>8 ; + addr[i] = j &0xff ; + addr[i+1 ] = j >>8 ; } +eth_hw_addr_set (dev, addr);return NULL ; }
@@ -430,6 +438,7 @@ static struct hw_info *get_ax88190(struct pcmcia_device *link)static struct hw_info *get_hwired (struct pcmcia_device *link) {struct net_device *dev = link->priv; +u8 addr[ETH_ALEN ];int i;for (i =0 ; i <6 ; i++)
@@ -438,7 +447,8 @@ static struct hw_info *get_hwired(struct pcmcia_device *link)return NULL ;for (i =0 ; i <6 ; i++) - dev->dev_addr[i] = hw_addr[i]; + addr[i] = hw_addr[i]; +eth_hw_addr_set (dev, addr);return &default_info; }/* get_hwired */
drivers/net/ethernet/8390/stnic.c +2 -3
@@ -104,8 +104,8 @@ STNIC_WRITE (int reg, byte val)static int __init stnic_probe (void ) {struct net_device *dev; -int i, err;struct ei_device *ei_local; +int err;/* If we are not running on a SolutionEngine, give up now */ if (!MACH_SE )
@@ -119,8 +119,7 @@ static int __init stnic_probe(void)#ifdef CONFIG_SH_STANDARD_BIOS sh_bios_get_node_addr (stnic_eadr);#endif -for (i =0 ; i <ETH_ALEN ; i++) - dev->dev_addr[i] = stnic_eadr[i]; +eth_hw_addr_set (dev, stnic_eadr);/* Set the base address to point to the NIC, not the "real" base! */ dev->base_addr =0x1000 ;
drivers/net/ethernet/8390/zorro8390.c +1 -2
@@ -364,8 +364,7 @@ static int zorro8390_init(struct net_device *dev, unsigned long board,if (i)return i; -for (i =0 ; i <ETH_ALEN ; i++) - dev->dev_addr[i] = SA_prom[i]; +eth_hw_addr_set (dev, SA_prom);pr_debug ("Found ethernet address: %pM\n" , dev->dev_addr);
Signature · 1 line
2.31.1
Re: [PATCH net-next 2/5] ethernet: tg3: remove direct netdev->dev_addr writes
In reply to Jakub KicinskiQuoted 5 lines · Jakub Kicinski
tg3 does various forms of direct writes to
netdev->dev_addr. Use a local buffer. Make sure local buffer is aligned sinceeth_platform_get_mac_address()may callether_addr_copy().
Quoted 8 lines
tg3_get_device_address()returns whenever it finds a method that found a valid address. Instead of modifying all the exit points pass the buffer from the outside and commit the address in the caller.Constify the argument of the set addr helper.
Signed-off-by Jakub Kicinski <[email protected]>
Thanks.
Re: [PATCH net-next 1/5] ethernet: forcedeth: remove direct netdev->dev_addr writes
In reply to Jakub KicinskiQuoted 9 lines · Jakub Kicinski
forcedeth writes to
dev_addrbyte by byte, make it use a local buffer instead. Commit the changes witheth_hw_addr_set()at the end.Signed-off-by Jakub Kicinski <[email protected]>---
CC: Rain River <[email protected]>
CC: Zhu Yanjun <[email protected]>
Thanks & Regards.
Zhu Yanjun
Quoted 95 lines
--- drivers/net/ethernet/nvidia/forcedeth.c | 49 +++++++++++++------------ 1 file changed, 26 insertions(+), 23 deletions(-)drivers/net/ethernet/nvidia/forcedeth.c +26
-24@@ -5711,6 +5711,7 @@ static int nv_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)u32 phystate_orig =0 , phystate;int phyinitialized =0 ;static int printed_version; +u8 mac[ETH_ALEN ];if (!printed_version++) pr_info("Reverse Engineered nForce ethernet driver. Version %s.\n",@@ -5884,50 +5885,52 @@ static int nv_probe(struct pci_dev *pci_dev, const struct pci_device_id *id) txreg =readl (base + NvRegTransmitPoll);if (id->driver_data &DEV_HAS_CORRECT_MACADDR ) {/* mac address is already in correct order */ - dev->dev_addr[0 ] = (np->orig_mac[0 ] >>0 ) &0xff ; - dev->dev_addr[1 ] = (np->orig_mac[0 ] >>8 ) &0xff ; - dev->dev_addr[2 ] = (np->orig_mac[0 ] >>16 ) &0xff ; - dev->dev_addr[3 ] = (np->orig_mac[0 ] >>24 ) &0xff ; - dev->dev_addr[4 ] = (np->orig_mac[1 ] >>0 ) &0xff ; - dev->dev_addr[5 ] = (np->orig_mac[1 ] >>8 ) &0xff ; + mac[0 ] = (np->orig_mac[0 ] >>0 ) &0xff ; + mac[1 ] = (np->orig_mac[0 ] >>8 ) &0xff ; + mac[2 ] = (np->orig_mac[0 ] >>16 ) &0xff ; + mac[3 ] = (np->orig_mac[0 ] >>24 ) &0xff ; + mac[4 ] = (np->orig_mac[1 ] >>0 ) &0xff ; + mac[5 ] = (np->orig_mac[1 ] >>8 ) &0xff ; }else if (txreg &NVREG_TRANSMITPOLL_MAC_ADDR_REV ) {/* mac address is already in correct order */ - dev->dev_addr[0 ] = (np->orig_mac[0 ] >>0 ) &0xff ; - dev->dev_addr[1 ] = (np->orig_mac[0 ] >>8 ) &0xff ; - dev->dev_addr[2 ] = (np->orig_mac[0 ] >>16 ) &0xff ; - dev->dev_addr[3 ] = (np->orig_mac[0 ] >>24 ) &0xff ; - dev->dev_addr[4 ] = (np->orig_mac[1 ] >>0 ) &0xff ; - dev->dev_addr[5 ] = (np->orig_mac[1 ] >>8 ) &0xff ; + mac[0 ] = (np->orig_mac[0 ] >>0 ) &0xff ; + mac[1 ] = (np->orig_mac[0 ] >>8 ) &0xff ; + mac[2 ] = (np->orig_mac[0 ] >>16 ) &0xff ; + mac[3 ] = (np->orig_mac[0 ] >>24 ) &0xff ; + mac[4 ] = (np->orig_mac[1 ] >>0 ) &0xff ; + mac[5 ] = (np->orig_mac[1 ] >>8 ) &0xff ;/* * Set orig mac address back to the reversed version. * This flag will be cleared during low power transition. * Therefore, we should always put back the reversed address. */ - np->orig_mac[0 ] = (dev->dev_addr[5 ] <<0 ) + (dev->dev_addr[4 ] <<8 ) + - (dev->dev_addr[3 ] <<16 ) + (dev->dev_addr[2 ] <<24 ); - np->orig_mac[1 ] = (dev->dev_addr[1 ] <<0 ) + (dev->dev_addr[0 ] <<8 ); + np->orig_mac[0 ] = (mac[5 ] <<0 ) + (mac[4 ] <<8 ) + + (mac[3 ] <<16 ) + (mac[2 ] <<24 ); + np->orig_mac[1 ] = (mac[1 ] <<0 ) + (mac[0 ] <<8 ); }else {/* need to reverse mac address to correct order */ - dev->dev_addr[0 ] = (np->orig_mac[1 ] >>8 ) &0xff ; - dev->dev_addr[1 ] = (np->orig_mac[1 ] >>0 ) &0xff ; - dev->dev_addr[2 ] = (np->orig_mac[0 ] >>24 ) &0xff ; - dev->dev_addr[3 ] = (np->orig_mac[0 ] >>16 ) &0xff ; - dev->dev_addr[4 ] = (np->orig_mac[0 ] >>8 ) &0xff ; - dev->dev_addr[5 ] = (np->orig_mac[0 ] >>0 ) &0xff ; + mac[0 ] = (np->orig_mac[1 ] >>8 ) &0xff ; + mac[1 ] = (np->orig_mac[1 ] >>0 ) &0xff ; + mac[2 ] = (np->orig_mac[0 ] >>24 ) &0xff ; + mac[3 ] = (np->orig_mac[0 ] >>16 ) &0xff ; + mac[4 ] = (np->orig_mac[0 ] >>8 ) &0xff ; + mac[5 ] = (np->orig_mac[0 ] >>0 ) &0xff ;writel (txreg|NVREG_TRANSMITPOLL_MAC_ADDR_REV , base + NvRegTransmitPoll);dev_dbg (&pci_dev->dev,"%s: set workaround bit for reversed mac addr\n" , __func__); } -if (!is_valid_ether_addr (dev->dev_addr)) { +if (is_valid_ether_addr (mac)) { +eth_hw_addr_set (dev, mac); + }else {/* * Bad mac address. At least one bios sets the mac address * to 01:23:45:67:89:ab */ dev_err (&pci_dev->dev,"Invalid MAC address detected: %pM - Please complain to your hardware vendor.\n" , - dev->dev_addr); + mac);eth_hw_addr_random (dev);dev_err (&pci_dev->dev,"Using random MAC address: %pM\n" , dev->dev_addr); --2.31.1
Re: [PATCH net-next 3/5] ethernet: tulip: remove direct netdev->dev_addr writes
In reply to Jakub KicinskiQuoted 5 lines · Jakub Kicinski
Consify the casts of
netdev->dev_addr.Convert pointless to
eth_hw_addr_set()where possible.Use local buffers in a number of places.
[]
drivers/net/ethernet/dec/tulip/de2104x.c
Quoted 1 line
drivers/net/ethernet/dec/tulip/de2104x.c +0
-0
[]
drivers/net/ethernet/dec/tulip/de2104x.c static void build_setup_frame_hash(u16 *setup_frm, struct net_device *dev) · line 670
Quoted 7 lines
drivers/net/ethernet/dec/tulip/de2104x.c +1
-1@@ -666,8 +666,8 @@ static void build_setup_frame_hash(u16 *setup_frm, struct net_device *dev) struct de_private *de = netdev_priv(dev); u16 hash_table[32]; struct netdev_hw_addr *ha; +const u16 *eaddrs; int i; -u16 *eaddrs;
Seems pointless to move the eaddrs location
drivers/net/ethernet/dec/tulip/de2104x.c static void de21041_get_srom_info(struct de_private *de) · line 1826
Quoted 7 lines
drivers/net/ethernet/dec/tulip/de2104x.c +1
-2@@ -1821,8 +1823,7 @@ static void de21041_get_srom_info(struct de_private *de) #endif /* store MAC address */ -for (i =0 ; i <6 ; i ++) - de->dev->dev_addr[i] = ee_data[i + sa_offset]; +eth_hw_addr_set (de->dev, &ee_data[i + sa_offset]);
what is the content of i here?
Perhaps you want
eth_hw_addr_set(de->dev, &ee_data[sa_offset]);
drivers/net/ethernet/dec/tulip/dmfe.c
Quoted 1 line
drivers/net/ethernet/dec/tulip/dmfe.c +0
-0
[]
drivers/net/ethernet/dec/tulip/dmfe.c static int dmfe_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) · line 479
Quoted 8 lines
drivers/net/ethernet/dec/tulip/dmfe.c +0
-0@@ -476,8 +476,7 @@ static int dmfe_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) }/* Set Node address */
drivers/net/ethernet/dec/tulip/dmfe.c +1
-2-for (i =0 ; i <6 ; i++) - dev->dev_addr[i] = db->srom[20 + i]; +eth_hw_addr_set (dev, &db->srom[20 + i]);
here too
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 9 lines · On Fri, 8 Oct 2021 10:59:08 -0700 you wrote:
Commit
406f42fa0d3c("net-next: When a bond have a massive amount of VLANs...") introduced a rbtree for faster Ethernet address look up. To maintainnetdev->dev_addrin this tree we need to make all the writes to it got through appropriate helpers.This series contains top 5 conversions in terms of LoC required to bring the driver into compliance.
[...]
Here is the summary with links:
- [net-next,1/5] ethernet: forcedeth: remove direct netdev->dev_addr writes
https://git.kernel.org/netdev/net-next/c/2b37367065c7 - [net-next,2/5] ethernet: tg3: remove direct netdev->dev_addr writes https://git.kernel.org/netdev/net-next/c/a04436b27a93 - [net-next,3/5] ethernet: tulip: remove direct netdev->dev_addr writes https://git.kernel.org/netdev/net-next/c/ca8793175564 - [net-next,4/5] ethernet: sun: remove direct netdev->dev_addr writes https://git.kernel.org/netdev/net-next/c/a7639279c93c - [net-next,5/5] ethernet: 8390: remove direct netdev->dev_addr writes https://git.kernel.org/netdev/net-next/c/8ce218b6e58a
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Quoted 11 lines · On Sat, 2021-10-09 at 11:00 +0000, [email protected] wrote:
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Quoted 7 lines · On Fri, 8 Oct 2021 10:59:08 -0700 you wrote:
Commit
406f42fa0d3c("net-next: When a bond have a massive amount of VLANs...") introduced a rbtree for faster Ethernet address look up. To maintainnetdev->dev_addrin this tree we need to make all the writes to it got through appropriate helpers.This series contains top 5 conversions in terms of LoC required to bring the driver into compliance.
[]
Quoted 2 lines
- [net-next,3/5] ethernet: tulip: remove direct
netdev->dev_addrwrites
https://git.kernel.org/netdev/net-next/c/ca8793175564
This one appears defective.
Jakub Kicinski
maintainerRe: [PATCH net-next 3/5] ethernet: tulip: remove direct netdev->dev_addr writes
In reply to Joe PerchesQuoted 21 lines · On Fri, 08 Oct 2021 19:35:11 -0700 Joe Perches wrote:
drivers/net/ethernet/dec/tulip/de2104x.c static void de21041_get_srom_info(struct de_private *de) · line 1826
Quoted 7 lines
drivers/net/ethernet/dec/tulip/de2104x.c +1
-2@@ -1821,8 +1823,7 @@ static void de21041_get_srom_info(struct de_private *de) #endif /* store MAC address */ -for (i =0 ; i <6 ; i ++) - de->dev->dev_addr[i] = ee_data[i + sa_offset]; +eth_hw_addr_set (de->dev, &ee_data[i + sa_offset]);what is the content of i here?
Perhaps you want
eth_hw_addr_set(de->dev, &ee_data[sa_offset]);drivers/net/ethernet/dec/tulip/dmfe.c
Quoted 1 line
drivers/net/ethernet/dec/tulip/dmfe.c +0
-0[]
Quoted 4 lines
drivers/net/ethernet/dec/tulip/dmfe.c +0
-0@@ -476,8 +476,7 @@ static int dmfe_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) }
Quoted 6 lines
drivers/net/ethernet/dec/tulip/dmfe.c static int dmfe_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) · line 479
Quoted 4 lines
/* Set Node address */
drivers/net/ethernet/dec/tulip/dmfe.c +1
-2-for (i =0 ; i <6 ; i++) - dev->dev_addr[i] = db->srom[20 + i]; +eth_hw_addr_set (dev, &db->srom[20 + i]);here too
Good catch, thanks.