Skip to content

Commit c782e20

Browse files
hkallweitdavem330
authored andcommitted
r8169: add random MAC address fallback
It was reported that the GPD MicroPC is broken in a way that no valid MAC address can be read from the network chip. The vendor driver deals with this by assigning a random MAC address as fallback. So let's do the same. Signed-off-by: Heiner Kallweit <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7424edb commit c782e20

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

drivers/net/ethernet/realtek/r8169_main.c

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6650,13 +6650,36 @@ static int rtl_get_ether_clk(struct rtl8169_private *tp)
66506650
return rc;
66516651
}
66526652

6653+
static void rtl_init_mac_address(struct rtl8169_private *tp)
6654+
{
6655+
struct net_device *dev = tp->dev;
6656+
u8 *mac_addr = dev->dev_addr;
6657+
int rc, i;
6658+
6659+
rc = eth_platform_get_mac_address(tp_to_dev(tp), mac_addr);
6660+
if (!rc)
6661+
goto done;
6662+
6663+
rtl_read_mac_address(tp, mac_addr);
6664+
if (is_valid_ether_addr(mac_addr))
6665+
goto done;
6666+
6667+
for (i = 0; i < ETH_ALEN; i++)
6668+
mac_addr[i] = RTL_R8(tp, MAC0 + i);
6669+
if (is_valid_ether_addr(mac_addr))
6670+
goto done;
6671+
6672+
eth_hw_addr_random(dev);
6673+
dev_warn(tp_to_dev(tp), "can't read MAC address, setting random one\n");
6674+
done:
6675+
rtl_rar_set(tp, mac_addr);
6676+
}
6677+
66536678
static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
66546679
{
6655-
/* align to u16 for is_valid_ether_addr() */
6656-
u8 mac_addr[ETH_ALEN] __aligned(2) = {};
66576680
struct rtl8169_private *tp;
66586681
struct net_device *dev;
6659-
int chipset, region, i;
6682+
int chipset, region;
66606683
int jumbo_max, rc;
66616684

66626685
dev = devm_alloc_etherdev(&pdev->dev, sizeof (*tp));
@@ -6748,16 +6771,7 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
67486771
u64_stats_init(&tp->rx_stats.syncp);
67496772
u64_stats_init(&tp->tx_stats.syncp);
67506773

6751-
/* get MAC address */
6752-
rc = eth_platform_get_mac_address(&pdev->dev, mac_addr);
6753-
if (rc)
6754-
rtl_read_mac_address(tp, mac_addr);
6755-
6756-
if (is_valid_ether_addr(mac_addr))
6757-
rtl_rar_set(tp, mac_addr);
6758-
6759-
for (i = 0; i < ETH_ALEN; i++)
6760-
dev->dev_addr[i] = RTL_R8(tp, MAC0 + i);
6774+
rtl_init_mac_address(tp);
67616775

67626776
dev->ethtool_ops = &rtl8169_ethtool_ops;
67636777

0 commit comments

Comments
 (0)