Skip to content

Commit 7bf6bf4

Browse files
iveceradavem330
authored andcommitted
r8169: read MAC address from EEPROM on init
Reviewed-by: Ilpo Järvinen <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8d1b1fc commit 7bf6bf4

File tree

1 file changed

+72
-1
lines changed

1 file changed

+72
-1
lines changed

drivers/net/r8169.c

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1710,6 +1710,74 @@ static void rtl_disable_msi(struct pci_dev *pdev, struct rtl8169_private *tp)
17101710
}
17111711
}
17121712

1713+
static int rtl_eeprom_read(struct pci_dev *pdev, int cap, int addr, __le32 *val)
1714+
{
1715+
int ret, count = 100;
1716+
u16 status = 0;
1717+
u32 value;
1718+
1719+
ret = pci_write_config_word(pdev, cap + PCI_VPD_ADDR, addr);
1720+
if (ret < 0)
1721+
return ret;
1722+
1723+
do {
1724+
udelay(10);
1725+
ret = pci_read_config_word(pdev, cap + PCI_VPD_ADDR, &status);
1726+
if (ret < 0)
1727+
return ret;
1728+
} while (!(status & PCI_VPD_ADDR_F) && --count);
1729+
1730+
if (!(status & PCI_VPD_ADDR_F))
1731+
return -ETIMEDOUT;
1732+
1733+
ret = pci_read_config_dword(pdev, cap + PCI_VPD_DATA, &value);
1734+
if (ret < 0)
1735+
return ret;
1736+
1737+
*val = cpu_to_le32(value);
1738+
1739+
return 0;
1740+
}
1741+
1742+
static void rtl_init_mac_address(struct rtl8169_private *tp,
1743+
void __iomem *ioaddr)
1744+
{
1745+
struct pci_dev *pdev = tp->pci_dev;
1746+
u8 cfg1;
1747+
int vpd_cap;
1748+
u8 mac[8];
1749+
DECLARE_MAC_BUF(buf);
1750+
1751+
cfg1 = RTL_R8(Config1);
1752+
if (!(cfg1 & VPD)) {
1753+
dprintk("VPD access not enabled, enabling\n");
1754+
RTL_W8(Cfg9346, Cfg9346_Unlock);
1755+
RTL_W8(Config1, cfg1 | VPD);
1756+
RTL_W8(Cfg9346, Cfg9346_Lock);
1757+
}
1758+
1759+
vpd_cap = pci_find_capability(pdev, PCI_CAP_ID_VPD);
1760+
if (!vpd_cap)
1761+
return;
1762+
1763+
/* MAC address is stored in EEPROM at offset 0x0e
1764+
* Realtek says: "The VPD address does not have to be a DWORD-aligned
1765+
* address as defined in the PCI 2.2 Specifications, but the VPD data
1766+
* is always consecutive 4-byte data starting from the VPD address
1767+
* specified."
1768+
*/
1769+
if (rtl_eeprom_read(pdev, vpd_cap, 0x000e, (__le32*)&mac[0]) < 0 ||
1770+
rtl_eeprom_read(pdev, vpd_cap, 0x0012, (__le32*)&mac[4]) < 0) {
1771+
dprintk("Reading MAC address from EEPROM failed\n");
1772+
return;
1773+
}
1774+
1775+
dprintk("MAC address found in EEPROM: %s\n", print_mac(buf, mac));
1776+
1777+
/* Write MAC address */
1778+
rtl_rar_set(tp, mac);
1779+
}
1780+
17131781
static int __devinit
17141782
rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
17151783
{
@@ -1879,7 +1947,10 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
18791947
dev->do_ioctl = rtl8169_ioctl;
18801948
}
18811949

1882-
/* Get MAC address. FIXME: read EEPROM */
1950+
/* Read MAC address from EEPROM */
1951+
rtl_init_mac_address(tp, ioaddr);
1952+
1953+
/* Get MAC address */
18831954
for (i = 0; i < MAC_ADDR_LEN; i++)
18841955
dev->dev_addr[i] = RTL_R8(MAC0 + i);
18851956
memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);

0 commit comments

Comments
 (0)