Skip to content

Commit a04436b

Browse files
kuba-moodavem330
authored andcommitted
ethernet: tg3: remove direct netdev->dev_addr writes
tg3 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. Signed-off-by: Jakub Kicinski <kuba@kernel.org> Reviewed-by: Michael Chan <michael.chan@broadcom.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 2b37367 commit a04436b

File tree

1 file changed

+25
-23
lines changed
  • drivers/net/ethernet/broadcom

1 file changed

+25
-23
lines changed

drivers/net/ethernet/broadcom/tg3.c

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3942,7 +3942,8 @@ static int tg3_load_tso_firmware(struct tg3 *tp)
39423942
}
39433943

39443944
/* tp->lock is held. */
3945-
static void __tg3_set_one_mac_addr(struct tg3 *tp, u8 *mac_addr, int index)
3945+
static void __tg3_set_one_mac_addr(struct tg3 *tp, const u8 *mac_addr,
3946+
int index)
39463947
{
39473948
u32 addr_high, addr_low;
39483949

@@ -16910,19 +16911,18 @@ static int tg3_get_invariants(struct tg3 *tp, const struct pci_device_id *ent)
1691016911
return err;
1691116912
}
1691216913

16913-
static int tg3_get_device_address(struct tg3 *tp)
16914+
static int tg3_get_device_address(struct tg3 *tp, u8 *addr)
1691416915
{
16915-
struct net_device *dev = tp->dev;
1691616916
u32 hi, lo, mac_offset;
1691716917
int addr_ok = 0;
1691816918
int err;
1691916919

16920-
if (!eth_platform_get_mac_address(&tp->pdev->dev, dev->dev_addr))
16920+
if (!eth_platform_get_mac_address(&tp->pdev->dev, addr))
1692116921
return 0;
1692216922

1692316923
if (tg3_flag(tp, IS_SSB_CORE)) {
16924-
err = ssb_gige_get_macaddr(tp->pdev, &dev->dev_addr[0]);
16925-
if (!err && is_valid_ether_addr(&dev->dev_addr[0]))
16924+
err = ssb_gige_get_macaddr(tp->pdev, addr);
16925+
if (!err && is_valid_ether_addr(addr))
1692616926
return 0;
1692716927
}
1692816928

@@ -16946,41 +16946,41 @@ static int tg3_get_device_address(struct tg3 *tp)
1694616946
/* First try to get it from MAC address mailbox. */
1694716947
tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi);
1694816948
if ((hi >> 16) == 0x484b) {
16949-
dev->dev_addr[0] = (hi >> 8) & 0xff;
16950-
dev->dev_addr[1] = (hi >> 0) & 0xff;
16949+
addr[0] = (hi >> 8) & 0xff;
16950+
addr[1] = (hi >> 0) & 0xff;
1695116951

1695216952
tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_LOW_MBOX, &lo);
16953-
dev->dev_addr[2] = (lo >> 24) & 0xff;
16954-
dev->dev_addr[3] = (lo >> 16) & 0xff;
16955-
dev->dev_addr[4] = (lo >> 8) & 0xff;
16956-
dev->dev_addr[5] = (lo >> 0) & 0xff;
16953+
addr[2] = (lo >> 24) & 0xff;
16954+
addr[3] = (lo >> 16) & 0xff;
16955+
addr[4] = (lo >> 8) & 0xff;
16956+
addr[5] = (lo >> 0) & 0xff;
1695716957

1695816958
/* Some old bootcode may report a 0 MAC address in SRAM */
16959-
addr_ok = is_valid_ether_addr(&dev->dev_addr[0]);
16959+
addr_ok = is_valid_ether_addr(addr);
1696016960
}
1696116961
if (!addr_ok) {
1696216962
/* Next, try NVRAM. */
1696316963
if (!tg3_flag(tp, NO_NVRAM) &&
1696416964
!tg3_nvram_read_be32(tp, mac_offset + 0, &hi) &&
1696516965
!tg3_nvram_read_be32(tp, mac_offset + 4, &lo)) {
16966-
memcpy(&dev->dev_addr[0], ((char *)&hi) + 2, 2);
16967-
memcpy(&dev->dev_addr[2], (char *)&lo, sizeof(lo));
16966+
memcpy(&addr[0], ((char *)&hi) + 2, 2);
16967+
memcpy(&addr[2], (char *)&lo, sizeof(lo));
1696816968
}
1696916969
/* Finally just fetch it out of the MAC control regs. */
1697016970
else {
1697116971
hi = tr32(MAC_ADDR_0_HIGH);
1697216972
lo = tr32(MAC_ADDR_0_LOW);
1697316973

16974-
dev->dev_addr[5] = lo & 0xff;
16975-
dev->dev_addr[4] = (lo >> 8) & 0xff;
16976-
dev->dev_addr[3] = (lo >> 16) & 0xff;
16977-
dev->dev_addr[2] = (lo >> 24) & 0xff;
16978-
dev->dev_addr[1] = hi & 0xff;
16979-
dev->dev_addr[0] = (hi >> 8) & 0xff;
16974+
addr[5] = lo & 0xff;
16975+
addr[4] = (lo >> 8) & 0xff;
16976+
addr[3] = (lo >> 16) & 0xff;
16977+
addr[2] = (lo >> 24) & 0xff;
16978+
addr[1] = hi & 0xff;
16979+
addr[0] = (hi >> 8) & 0xff;
1698016980
}
1698116981
}
1698216982

16983-
if (!is_valid_ether_addr(&dev->dev_addr[0]))
16983+
if (!is_valid_ether_addr(addr))
1698416984
return -EINVAL;
1698516985
return 0;
1698616986
}
@@ -17556,6 +17556,7 @@ static int tg3_init_one(struct pci_dev *pdev,
1755617556
char str[40];
1755717557
u64 dma_mask, persist_dma_mask;
1755817558
netdev_features_t features = 0;
17559+
u8 addr[ETH_ALEN] __aligned(2);
1755917560

1756017561
err = pci_enable_device(pdev);
1756117562
if (err) {
@@ -17778,12 +17779,13 @@ static int tg3_init_one(struct pci_dev *pdev,
1777817779
tp->rx_pending = 63;
1777917780
}
1778017781

17781-
err = tg3_get_device_address(tp);
17782+
err = tg3_get_device_address(tp, addr);
1778217783
if (err) {
1778317784
dev_err(&pdev->dev,
1778417785
"Could not obtain valid ethernet address, aborting\n");
1778517786
goto err_out_apeunmap;
1778617787
}
17788+
eth_hw_addr_set(dev, addr);
1778717789

1778817790
intmbx = MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW;
1778917791
rcvmbx = MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW;

0 commit comments

Comments
 (0)