Skip to content

Commit 04c7788

Browse files
thierryredingdavem330
authored andcommitted
r8169: Load MAC address from device tree if present
If the system was booted using a device tree and if the device tree contains a MAC address, use it instead of reading one from the EEPROM. This is useful in situations where the EEPROM isn't properly programmed or where the firmware wants to override the existing MAC address. Signed-off-by: Thierry Reding <treding@nvidia.com> Reviewed-by: Heiner Kallweit <hkallweit1@gmail.com> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c53f59d commit 04c7788

File tree

1 file changed

+23
-13
lines changed
  • drivers/net/ethernet/realtek

1 file changed

+23
-13
lines changed

drivers/net/ethernet/realtek/r8169.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7110,6 +7110,21 @@ static int rtl_alloc_irq(struct rtl8169_private *tp)
71107110
return pci_alloc_irq_vectors(tp->pci_dev, 1, 1, flags);
71117111
}
71127112

7113+
static void rtl_read_mac_address(struct rtl8169_private *tp,
7114+
u8 mac_addr[ETH_ALEN])
7115+
{
7116+
/* Get MAC address */
7117+
switch (tp->mac_version) {
7118+
case RTL_GIGA_MAC_VER_35 ... RTL_GIGA_MAC_VER_38:
7119+
case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51:
7120+
*(u32 *)&mac_addr[0] = rtl_eri_read(tp, 0xe0, ERIAR_EXGMAC);
7121+
*(u16 *)&mac_addr[4] = rtl_eri_read(tp, 0xe4, ERIAR_EXGMAC);
7122+
break;
7123+
default:
7124+
break;
7125+
}
7126+
}
7127+
71137128
DECLARE_RTL_COND(rtl_link_list_ready_cond)
71147129
{
71157130
return RTL_R8(tp, MCU) & LINK_LIST_RDY;
@@ -7301,6 +7316,7 @@ static int rtl_get_ether_clk(struct rtl8169_private *tp)
73017316
static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
73027317
{
73037318
const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data;
7319+
u8 mac_addr[ETH_ALEN] __aligned(4) = {};
73047320
struct rtl8169_private *tp;
73057321
struct net_device *dev;
73067322
int chipset, region, i;
@@ -7403,20 +7419,14 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
74037419
u64_stats_init(&tp->rx_stats.syncp);
74047420
u64_stats_init(&tp->tx_stats.syncp);
74057421

7406-
/* Get MAC address */
7407-
switch (tp->mac_version) {
7408-
u8 mac_addr[ETH_ALEN] __aligned(4);
7409-
case RTL_GIGA_MAC_VER_35 ... RTL_GIGA_MAC_VER_38:
7410-
case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_51:
7411-
*(u32 *)&mac_addr[0] = rtl_eri_read(tp, 0xe0, ERIAR_EXGMAC);
7412-
*(u16 *)&mac_addr[4] = rtl_eri_read(tp, 0xe4, ERIAR_EXGMAC);
7422+
/* get MAC address */
7423+
rc = eth_platform_get_mac_address(&pdev->dev, mac_addr);
7424+
if (rc)
7425+
rtl_read_mac_address(tp, mac_addr);
7426+
7427+
if (is_valid_ether_addr(mac_addr))
7428+
rtl_rar_set(tp, mac_addr);
74137429

7414-
if (is_valid_ether_addr(mac_addr))
7415-
rtl_rar_set(tp, mac_addr);
7416-
break;
7417-
default:
7418-
break;
7419-
}
74207430
for (i = 0; i < ETH_ALEN; i++)
74217431
dev->dev_addr[i] = RTL_R8(tp, MAC0 + i);
74227432

0 commit comments

Comments
 (0)