diff options
author | Ivan Vecera <ivecera@redhat.com> | 2008-09-23 18:46:29 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-10-08 18:40:51 -0400 |
commit | 7bf6bf4803df1adc927f585168d2135fb019c698 (patch) | |
tree | 1a679dc561738b620cffe0624dad4102d6ce34e0 /drivers/net | |
parent | 8d1b1fc9b97ad4de40c063ce3d213895c06fa116 (diff) |
r8169: read MAC address from EEPROM on init
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@helsinki.fi>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net')
-rw-r--r-- | drivers/net/r8169.c | 73 |
1 files changed, 72 insertions, 1 deletions
diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c index fb899c675f47..53a0ce445cc5 100644 --- a/drivers/net/r8169.c +++ b/drivers/net/r8169.c | |||
@@ -1710,6 +1710,74 @@ static void rtl_disable_msi(struct pci_dev *pdev, struct rtl8169_private *tp) | |||
1710 | } | 1710 | } |
1711 | } | 1711 | } |
1712 | 1712 | ||
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 | |||
1713 | static int __devinit | 1781 | static int __devinit |
1714 | rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) | 1782 | rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
1715 | { | 1783 | { |
@@ -1879,7 +1947,10 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
1879 | dev->do_ioctl = rtl8169_ioctl; | 1947 | dev->do_ioctl = rtl8169_ioctl; |
1880 | } | 1948 | } |
1881 | 1949 | ||
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 */ | ||
1883 | for (i = 0; i < MAC_ADDR_LEN; i++) | 1954 | for (i = 0; i < MAC_ADDR_LEN; i++) |
1884 | dev->dev_addr[i] = RTL_R8(MAC0 + i); | 1955 | dev->dev_addr[i] = RTL_R8(MAC0 + i); |
1885 | memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); | 1956 | memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); |