]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - drivers/net/r8169.c
r8169: new phy init parameters for the 8168b
[mirror_ubuntu-bionic-kernel.git] / drivers / net / r8169.c
index fb899c675f47528403b7f3b50af0acf79bae23a6..8086bacabcf318e005a06c501405c1e1a48b2eea 100644 (file)
@@ -759,6 +759,7 @@ static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
                tp->features |= RTL_FEATURE_WOL;
        else
                tp->features &= ~RTL_FEATURE_WOL;
+       device_set_wakeup_enable(&tp->pci_dev->dev, wol->wolopts);
 
        spin_unlock_irq(&tp->lock);
 
@@ -864,9 +865,13 @@ static int rtl8169_set_speed_xmii(struct net_device *dev,
 
        auto_nego |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
 
-       if ((tp->mac_version == RTL_GIGA_MAC_VER_12) ||
-           (tp->mac_version == RTL_GIGA_MAC_VER_17)) {
-               /* Vendor specific (0x1f) and reserved (0x0e) MII registers. */
+       if ((tp->mac_version == RTL_GIGA_MAC_VER_11) ||
+           (tp->mac_version == RTL_GIGA_MAC_VER_12) ||
+           (tp->mac_version >= RTL_GIGA_MAC_VER_17)) {
+               /*
+                * Wake up the PHY.
+                * Vendor specific (0x1f) and reserved (0x0e) MII registers.
+                */
                mdio_write(ioaddr, 0x1f, 0x0000);
                mdio_write(ioaddr, 0x0e, 0x0000);
        }
@@ -1345,6 +1350,30 @@ static void rtl8169sb_hw_phy_config(void __iomem *ioaddr)
        rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
 }
 
+static void rtl8168bb_hw_phy_config(void __iomem *ioaddr)
+{
+       struct phy_reg phy_reg_init[] = {
+               { 0x10, 0xf41b },
+               { 0x1f, 0x0000 }
+       };
+
+       mdio_write(ioaddr, 0x1f, 0x0001);
+       mdio_patch(ioaddr, 0x16, 1 << 0);
+
+       rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
+}
+
+static void rtl8168bef_hw_phy_config(void __iomem *ioaddr)
+{
+       struct phy_reg phy_reg_init[] = {
+               { 0x1f, 0x0001 },
+               { 0x10, 0xf41b },
+               { 0x1f, 0x0000 }
+       };
+
+       rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
+}
+
 static void rtl8168cp_hw_phy_config(void __iomem *ioaddr)
 {
        struct phy_reg phy_reg_init[] = {
@@ -1374,26 +1403,45 @@ static void rtl8168c_hw_phy_config(void __iomem *ioaddr)
                { 0x1f, 0x0003 },
                { 0x12, 0xc096 },
                { 0x16, 0x000a },
-               { 0x1f, 0x0000 }
+               { 0x1f, 0x0000 },
+               { 0x1f, 0x0000 },
+               { 0x09, 0x2000 },
+               { 0x09, 0x0000 }
        };
 
        rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
+
+       mdio_patch(ioaddr, 0x14, 1 << 5);
+       mdio_patch(ioaddr, 0x0d, 1 << 5);
+       mdio_write(ioaddr, 0x1f, 0x0000);
 }
 
 static void rtl8168cx_hw_phy_config(void __iomem *ioaddr)
 {
        struct phy_reg phy_reg_init[] = {
-               { 0x1f, 0x0000 },
+               { 0x1f, 0x0001 },
                { 0x12, 0x2300 },
-               { 0x1f, 0x0003 },
-               { 0x16, 0x0f0a },
-               { 0x1f, 0x0000 },
+               { 0x03, 0x802f },
+               { 0x02, 0x4f02 },
+               { 0x01, 0x0409 },
+               { 0x00, 0xf099 },
+               { 0x04, 0x9800 },
+               { 0x04, 0x9000 },
+               { 0x1d, 0x3d98 },
                { 0x1f, 0x0002 },
                { 0x0c, 0x7eb8 },
+               { 0x06, 0x0761 },
+               { 0x1f, 0x0003 },
+               { 0x16, 0x0f0a },
                { 0x1f, 0x0000 }
        };
 
        rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init));
+
+       mdio_patch(ioaddr, 0x16, 1 << 0);
+       mdio_patch(ioaddr, 0x14, 1 << 5);
+       mdio_patch(ioaddr, 0x0d, 1 << 5);
+       mdio_write(ioaddr, 0x1f, 0x0000);
 }
 
 static void rtl8102e_hw_phy_config(void __iomem *ioaddr)
@@ -1434,6 +1482,15 @@ static void rtl_hw_phy_config(struct net_device *dev)
        case RTL_GIGA_MAC_VER_09:
                rtl8102e_hw_phy_config(ioaddr);
                break;
+       case RTL_GIGA_MAC_VER_11:
+               rtl8168bb_hw_phy_config(ioaddr);
+               break;
+       case RTL_GIGA_MAC_VER_12:
+               rtl8168bef_hw_phy_config(ioaddr);
+               break;
+       case RTL_GIGA_MAC_VER_17:
+               rtl8168bef_hw_phy_config(ioaddr);
+               break;
        case RTL_GIGA_MAC_VER_18:
                rtl8168cp_hw_phy_config(ioaddr);
                break;
@@ -1710,6 +1767,74 @@ static void rtl_disable_msi(struct pci_dev *pdev, struct rtl8169_private *tp)
        }
 }
 
+static int rtl_eeprom_read(struct pci_dev *pdev, int cap, int addr, __le32 *val)
+{
+       int ret, count = 100;
+       u16 status = 0;
+       u32 value;
+
+       ret = pci_write_config_word(pdev, cap + PCI_VPD_ADDR, addr);
+       if (ret < 0)
+               return ret;
+
+       do {
+               udelay(10);
+               ret = pci_read_config_word(pdev, cap + PCI_VPD_ADDR, &status);
+               if (ret < 0)
+                       return ret;
+       } while (!(status & PCI_VPD_ADDR_F) && --count);
+
+       if (!(status & PCI_VPD_ADDR_F))
+               return -ETIMEDOUT;
+
+       ret = pci_read_config_dword(pdev, cap + PCI_VPD_DATA, &value);
+       if (ret < 0)
+               return ret;
+
+       *val = cpu_to_le32(value);
+
+       return 0;
+}
+
+static void rtl_init_mac_address(struct rtl8169_private *tp,
+                                void __iomem *ioaddr)
+{
+       struct pci_dev *pdev = tp->pci_dev;
+       u8 cfg1;
+       int vpd_cap;
+       u8 mac[8];
+       DECLARE_MAC_BUF(buf);
+
+       cfg1 = RTL_R8(Config1);
+       if (!(cfg1  & VPD)) {
+               dprintk("VPD access not enabled, enabling\n");
+               RTL_W8(Cfg9346, Cfg9346_Unlock);
+               RTL_W8(Config1, cfg1 | VPD);
+               RTL_W8(Cfg9346, Cfg9346_Lock);
+       }
+
+       vpd_cap = pci_find_capability(pdev, PCI_CAP_ID_VPD);
+       if (!vpd_cap)
+               return;
+
+       /* MAC address is stored in EEPROM at offset 0x0e
+        * Realtek says: "The VPD address does not have to be a DWORD-aligned
+        * address as defined in the PCI 2.2 Specifications, but the VPD data
+        * is always consecutive 4-byte data starting from the VPD address
+        * specified."
+        */
+       if (rtl_eeprom_read(pdev, vpd_cap, 0x000e, (__le32*)&mac[0]) < 0 ||
+           rtl_eeprom_read(pdev, vpd_cap, 0x0012, (__le32*)&mac[4]) < 0) {
+               dprintk("Reading MAC address from EEPROM failed\n");
+               return;
+       }
+
+       dprintk("MAC address found in EEPROM: %s\n", print_mac(buf, mac));
+
+       /* Write MAC address */
+       rtl_rar_set(tp, mac);
+}
+
 static int __devinit
 rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
@@ -1857,6 +1982,10 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        RTL_W8(Cfg9346, Cfg9346_Unlock);
        RTL_W8(Config1, RTL_R8(Config1) | PMEnable);
        RTL_W8(Config5, RTL_R8(Config5) & PMEStatus);
+       if ((RTL_R8(Config3) & (LinkUp | MagicPacket)) != 0)
+               tp->features |= RTL_FEATURE_WOL;
+       if ((RTL_R8(Config5) & (UWF | BWF | MWF)) != 0)
+               tp->features |= RTL_FEATURE_WOL;
        tp->features |= rtl_try_msi(pdev, ioaddr, cfg);
        RTL_W8(Cfg9346, Cfg9346_Lock);
 
@@ -1879,7 +2008,11 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
                dev->do_ioctl = rtl8169_ioctl;
        }
 
-       /* Get MAC address.  FIXME: read EEPROM */
+       spin_lock_init(&tp->lock);
+
+       rtl_init_mac_address(tp, ioaddr);
+
+       /* Get MAC address */
        for (i = 0; i < MAC_ADDR_LEN; i++)
                dev->dev_addr[i] = RTL_R8(MAC0 + i);
        memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
@@ -1919,8 +2052,6 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        tp->timer.data = (unsigned long) dev;
        tp->timer.function = rtl8169_phy_timer;
 
-       spin_lock_init(&tp->lock);
-
        rc = register_netdev(dev);
        if (rc < 0)
                goto err_out_msi_5;
@@ -1942,6 +2073,7 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        }
 
        rtl8169_init_phy(dev, tp);
+       device_set_wakeup_enable(&pdev->dev, tp->features & RTL_FEATURE_WOL);
 
 out:
        return rc;