From 1c055e55a242a33e574e48be530e06770a210dcd Mon Sep 17 00:00:00 2001 From: hc <hc@nodka.com> Date: Mon, 19 Feb 2024 03:26:26 +0000 Subject: [PATCH] add r8169 read mac form eeprom --- kernel/drivers/net/ethernet/realtek/r8169_main.c | 47 ++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 40 insertions(+), 7 deletions(-) diff --git a/kernel/drivers/net/ethernet/realtek/r8169_main.c b/kernel/drivers/net/ethernet/realtek/r8169_main.c index 28850f7..0e4dea1 100644 --- a/kernel/drivers/net/ethernet/realtek/r8169_main.c +++ b/kernel/drivers/net/ethernet/realtek/r8169_main.c @@ -2098,6 +2098,9 @@ /* Adjust EEE LED frequency */ if (tp->mac_version != RTL_GIGA_MAC_VER_38) RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); + printk("r8169 EEE_LED value init: %x\n", RTL_R16(tp, 0x18)); + RTL_W16(tp, 0x18, 0x0248); + printk("r8169 EEE_LED write: %x\n", RTL_R16(tp, 0x18)); rtl_eri_set_bits(tp, 0x1b0, 0x0003); } @@ -5298,31 +5301,36 @@ u8 *mac_addr = dev->dev_addr; int rc; + rtl_read_mac_address(tp, mac_addr); + if (is_valid_ether_addr(mac_addr)) + goto done; + + if (is_valid_ether_addr(mac_addr)) + goto done; + rc = eth_platform_get_mac_address(tp_to_dev(tp), mac_addr); if (!rc) - goto done; - - rtl_read_mac_address(tp, mac_addr); - if (is_valid_ether_addr(mac_addr)) goto done; rtl_read_mac_from_reg(tp, mac_addr, MAC0); if (is_valid_ether_addr(mac_addr)) goto done; - eth_hw_addr_random(dev); + //eth_hw_addr_random(dev); dev_warn(tp_to_dev(tp), "can't read MAC address, setting random one\n"); done: rtl_rar_set(tp, mac_addr); } +extern ssize_t at24_mac1_read(unsigned char* mac); static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) { struct rtl8169_private *tp; - int jumbo_max, region, rc; + int jumbo_max, region, rc, i; enum mac_version chipset; struct net_device *dev; u16 xid; + unsigned char mac[6]; dev = devm_alloc_etherdev(&pdev->dev, sizeof (*tp)); if (!dev) @@ -5416,6 +5424,30 @@ u64_stats_init(&tp->tx_stats.syncp); rtl_init_mac_address(tp); + + for (i = 0; i < ETH_ALEN; i++) + dev->dev_addr[i] = RTL_R8(tp, MAC0 + i); + memset(mac, 0x00, 6); + at24_mac1_read(mac); + + if ((mac[0] == 0x68) && (mac[1] == 0xed)) + { + printk("rtl811h mac read from eeprom success!!\n"); + for (i = 0; i < ETH_ALEN; i++) + dev->dev_addr[i] = mac[i]; + } + else + { + printk("rtl811h mac read from eeprom error!!\n"); + dev->dev_addr[0] = 0x66; + dev->dev_addr[1] = 0xED; + dev->dev_addr[2] = 0xB5; + dev->dev_addr[3] = 0x64; + dev->dev_addr[4] = 0x72; + dev->dev_addr[5] = 0x2c; + } + + rtl_rar_set(tp, dev->dev_addr); dev->ethtool_ops = &rtl8169_ethtool_ops; @@ -5518,4 +5550,5 @@ #endif }; -module_pci_driver(rtl8169_pci_driver); +//module_pci_driver(rtl8169_pci_driver); +module_pci_driver2(rtl8169_pci_driver); -- Gitblit v1.6.2