aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/r8169.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/r8169.c')
-rw-r--r--drivers/net/r8169.c216
1 files changed, 120 insertions, 96 deletions
diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
index 8247a945a1d9..e94316b7868b 100644
--- a/drivers/net/r8169.c
+++ b/drivers/net/r8169.c
@@ -94,6 +94,7 @@ static const int multicast_filter_limit = 32;
94#define RTL_R32(reg) ((unsigned long) readl (ioaddr + (reg))) 94#define RTL_R32(reg) ((unsigned long) readl (ioaddr + (reg)))
95 95
96enum mac_version { 96enum mac_version {
97 RTL_GIGA_MAC_NONE = 0x00,
97 RTL_GIGA_MAC_VER_01 = 0x01, // 8169 98 RTL_GIGA_MAC_VER_01 = 0x01, // 8169
98 RTL_GIGA_MAC_VER_02 = 0x02, // 8169S 99 RTL_GIGA_MAC_VER_02 = 0x02, // 8169S
99 RTL_GIGA_MAC_VER_03 = 0x03, // 8110S 100 RTL_GIGA_MAC_VER_03 = 0x03, // 8110S
@@ -479,7 +480,6 @@ struct rtl8169_private {
479 u16 intr_event; 480 u16 intr_event;
480 u16 napi_event; 481 u16 napi_event;
481 u16 intr_mask; 482 u16 intr_mask;
482 int phy_auto_nego_reg;
483 int phy_1000_ctrl_reg; 483 int phy_1000_ctrl_reg;
484#ifdef CONFIG_R8169_VLAN 484#ifdef CONFIG_R8169_VLAN
485 struct vlan_group *vlgrp; 485 struct vlan_group *vlgrp;
@@ -844,76 +844,81 @@ static int rtl8169_set_speed_xmii(struct net_device *dev,
844{ 844{
845 struct rtl8169_private *tp = netdev_priv(dev); 845 struct rtl8169_private *tp = netdev_priv(dev);
846 void __iomem *ioaddr = tp->mmio_addr; 846 void __iomem *ioaddr = tp->mmio_addr;
847 int auto_nego, giga_ctrl; 847 int giga_ctrl, bmcr;
848
849 auto_nego = mdio_read(ioaddr, MII_ADVERTISE);
850 auto_nego &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL |
851 ADVERTISE_100HALF | ADVERTISE_100FULL);
852 giga_ctrl = mdio_read(ioaddr, MII_CTRL1000);
853 giga_ctrl &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF);
854 848
855 if (autoneg == AUTONEG_ENABLE) { 849 if (autoneg == AUTONEG_ENABLE) {
850 int auto_nego;
851
852 auto_nego = mdio_read(ioaddr, MII_ADVERTISE);
856 auto_nego |= (ADVERTISE_10HALF | ADVERTISE_10FULL | 853 auto_nego |= (ADVERTISE_10HALF | ADVERTISE_10FULL |
857 ADVERTISE_100HALF | ADVERTISE_100FULL); 854 ADVERTISE_100HALF | ADVERTISE_100FULL);
858 giga_ctrl |= ADVERTISE_1000FULL | ADVERTISE_1000HALF; 855 auto_nego |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
859 } else {
860 if (speed == SPEED_10)
861 auto_nego |= ADVERTISE_10HALF | ADVERTISE_10FULL;
862 else if (speed == SPEED_100)
863 auto_nego |= ADVERTISE_100HALF | ADVERTISE_100FULL;
864 else if (speed == SPEED_1000)
865 giga_ctrl |= ADVERTISE_1000FULL | ADVERTISE_1000HALF;
866
867 if (duplex == DUPLEX_HALF)
868 auto_nego &= ~(ADVERTISE_10FULL | ADVERTISE_100FULL);
869
870 if (duplex == DUPLEX_FULL)
871 auto_nego &= ~(ADVERTISE_10HALF | ADVERTISE_100HALF);
872 856
873 /* This tweak comes straight from Realtek's driver. */ 857 giga_ctrl = mdio_read(ioaddr, MII_CTRL1000);
874 if ((speed == SPEED_100) && (duplex == DUPLEX_HALF) && 858 giga_ctrl &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF);
875 ((tp->mac_version == RTL_GIGA_MAC_VER_13) ||
876 (tp->mac_version == RTL_GIGA_MAC_VER_16))) {
877 auto_nego = ADVERTISE_100HALF | ADVERTISE_CSMA;
878 }
879 }
880 859
881 /* The 8100e/8101e/8102e do Fast Ethernet only. */ 860 /* The 8100e/8101e/8102e do Fast Ethernet only. */
882 if ((tp->mac_version == RTL_GIGA_MAC_VER_07) || 861 if ((tp->mac_version != RTL_GIGA_MAC_VER_07) &&
883 (tp->mac_version == RTL_GIGA_MAC_VER_08) || 862 (tp->mac_version != RTL_GIGA_MAC_VER_08) &&
884 (tp->mac_version == RTL_GIGA_MAC_VER_09) || 863 (tp->mac_version != RTL_GIGA_MAC_VER_09) &&
885 (tp->mac_version == RTL_GIGA_MAC_VER_10) || 864 (tp->mac_version != RTL_GIGA_MAC_VER_10) &&
886 (tp->mac_version == RTL_GIGA_MAC_VER_13) || 865 (tp->mac_version != RTL_GIGA_MAC_VER_13) &&
887 (tp->mac_version == RTL_GIGA_MAC_VER_14) || 866 (tp->mac_version != RTL_GIGA_MAC_VER_14) &&
888 (tp->mac_version == RTL_GIGA_MAC_VER_15) || 867 (tp->mac_version != RTL_GIGA_MAC_VER_15) &&
889 (tp->mac_version == RTL_GIGA_MAC_VER_16)) { 868 (tp->mac_version != RTL_GIGA_MAC_VER_16)) {
890 if ((giga_ctrl & (ADVERTISE_1000FULL | ADVERTISE_1000HALF)) && 869 giga_ctrl |= ADVERTISE_1000FULL | ADVERTISE_1000HALF;
891 netif_msg_link(tp)) { 870 } else if (netif_msg_link(tp)) {
892 printk(KERN_INFO "%s: PHY does not support 1000Mbps.\n", 871 printk(KERN_INFO "%s: PHY does not support 1000Mbps.\n",
893 dev->name); 872 dev->name);
894 } 873 }
895 giga_ctrl &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF);
896 }
897 874
898 auto_nego |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; 875 bmcr = BMCR_ANENABLE | BMCR_ANRESTART;
876
877 if ((tp->mac_version == RTL_GIGA_MAC_VER_11) ||
878 (tp->mac_version == RTL_GIGA_MAC_VER_12) ||
879 (tp->mac_version >= RTL_GIGA_MAC_VER_17)) {
880 /*
881 * Wake up the PHY.
882 * Vendor specific (0x1f) and reserved (0x0e) MII
883 * registers.
884 */
885 mdio_write(ioaddr, 0x1f, 0x0000);
886 mdio_write(ioaddr, 0x0e, 0x0000);
887 }
888
889 mdio_write(ioaddr, MII_ADVERTISE, auto_nego);
890 mdio_write(ioaddr, MII_CTRL1000, giga_ctrl);
891 } else {
892 giga_ctrl = 0;
893
894 if (speed == SPEED_10)
895 bmcr = 0;
896 else if (speed == SPEED_100)
897 bmcr = BMCR_SPEED100;
898 else
899 return -EINVAL;
900
901 if (duplex == DUPLEX_FULL)
902 bmcr |= BMCR_FULLDPLX;
899 903
900 if ((tp->mac_version == RTL_GIGA_MAC_VER_11) ||
901 (tp->mac_version == RTL_GIGA_MAC_VER_12) ||
902 (tp->mac_version >= RTL_GIGA_MAC_VER_17)) {
903 /*
904 * Wake up the PHY.
905 * Vendor specific (0x1f) and reserved (0x0e) MII registers.
906 */
907 mdio_write(ioaddr, 0x1f, 0x0000); 904 mdio_write(ioaddr, 0x1f, 0x0000);
908 mdio_write(ioaddr, 0x0e, 0x0000);
909 } 905 }
910 906
911 tp->phy_auto_nego_reg = auto_nego;
912 tp->phy_1000_ctrl_reg = giga_ctrl; 907 tp->phy_1000_ctrl_reg = giga_ctrl;
913 908
914 mdio_write(ioaddr, MII_ADVERTISE, auto_nego); 909 mdio_write(ioaddr, MII_BMCR, bmcr);
915 mdio_write(ioaddr, MII_CTRL1000, giga_ctrl); 910
916 mdio_write(ioaddr, MII_BMCR, BMCR_ANENABLE | BMCR_ANRESTART); 911 if ((tp->mac_version == RTL_GIGA_MAC_VER_02) ||
912 (tp->mac_version == RTL_GIGA_MAC_VER_03)) {
913 if ((speed == SPEED_100) && (autoneg != AUTONEG_ENABLE)) {
914 mdio_write(ioaddr, 0x17, 0x2138);
915 mdio_write(ioaddr, 0x0e, 0x0260);
916 } else {
917 mdio_write(ioaddr, 0x17, 0x2108);
918 mdio_write(ioaddr, 0x0e, 0x0000);
919 }
920 }
921
917 return 0; 922 return 0;
918} 923}
919 924
@@ -1296,7 +1301,8 @@ static void rtl8169_get_mac_version(struct rtl8169_private *tp,
1296 { 0xfc800000, 0x00800000, RTL_GIGA_MAC_VER_02 }, 1301 { 0xfc800000, 0x00800000, RTL_GIGA_MAC_VER_02 },
1297 { 0xfc800000, 0x00000000, RTL_GIGA_MAC_VER_01 }, 1302 { 0xfc800000, 0x00000000, RTL_GIGA_MAC_VER_01 },
1298 1303
1299 { 0x00000000, 0x00000000, RTL_GIGA_MAC_VER_01 } /* Catch-all */ 1304 /* Catch-all */
1305 { 0x00000000, 0x00000000, RTL_GIGA_MAC_NONE }
1300 }, *p = mac_info; 1306 }, *p = mac_info;
1301 u32 reg; 1307 u32 reg;
1302 1308
@@ -1304,12 +1310,6 @@ static void rtl8169_get_mac_version(struct rtl8169_private *tp,
1304 while ((reg & p->mask) != p->val) 1310 while ((reg & p->mask) != p->val)
1305 p++; 1311 p++;
1306 tp->mac_version = p->mac_version; 1312 tp->mac_version = p->mac_version;
1307
1308 if (p->mask == 0x00000000) {
1309 struct pci_dev *pdev = tp->pci_dev;
1310
1311 dev_info(&pdev->dev, "unknown MAC (%08x)\n", reg);
1312 }
1313} 1313}
1314 1314
1315static void rtl8169_print_mac_version(struct rtl8169_private *tp) 1315static void rtl8169_print_mac_version(struct rtl8169_private *tp)
@@ -1885,6 +1885,7 @@ static const struct rtl_cfg_info {
1885 u16 intr_event; 1885 u16 intr_event;
1886 u16 napi_event; 1886 u16 napi_event;
1887 unsigned features; 1887 unsigned features;
1888 u8 default_ver;
1888} rtl_cfg_infos [] = { 1889} rtl_cfg_infos [] = {
1889 [RTL_CFG_0] = { 1890 [RTL_CFG_0] = {
1890 .hw_start = rtl_hw_start_8169, 1891 .hw_start = rtl_hw_start_8169,
@@ -1893,7 +1894,8 @@ static const struct rtl_cfg_info {
1893 .intr_event = SYSErr | LinkChg | RxOverflow | 1894 .intr_event = SYSErr | LinkChg | RxOverflow |
1894 RxFIFOOver | TxErr | TxOK | RxOK | RxErr, 1895 RxFIFOOver | TxErr | TxOK | RxOK | RxErr,
1895 .napi_event = RxFIFOOver | TxErr | TxOK | RxOK | RxOverflow, 1896 .napi_event = RxFIFOOver | TxErr | TxOK | RxOK | RxOverflow,
1896 .features = RTL_FEATURE_GMII 1897 .features = RTL_FEATURE_GMII,
1898 .default_ver = RTL_GIGA_MAC_VER_01,
1897 }, 1899 },
1898 [RTL_CFG_1] = { 1900 [RTL_CFG_1] = {
1899 .hw_start = rtl_hw_start_8168, 1901 .hw_start = rtl_hw_start_8168,
@@ -1902,7 +1904,8 @@ static const struct rtl_cfg_info {
1902 .intr_event = SYSErr | LinkChg | RxOverflow | 1904 .intr_event = SYSErr | LinkChg | RxOverflow |
1903 TxErr | TxOK | RxOK | RxErr, 1905 TxErr | TxOK | RxOK | RxErr,
1904 .napi_event = TxErr | TxOK | RxOK | RxOverflow, 1906 .napi_event = TxErr | TxOK | RxOK | RxOverflow,
1905 .features = RTL_FEATURE_GMII | RTL_FEATURE_MSI 1907 .features = RTL_FEATURE_GMII | RTL_FEATURE_MSI,
1908 .default_ver = RTL_GIGA_MAC_VER_11,
1906 }, 1909 },
1907 [RTL_CFG_2] = { 1910 [RTL_CFG_2] = {
1908 .hw_start = rtl_hw_start_8101, 1911 .hw_start = rtl_hw_start_8101,
@@ -1911,7 +1914,8 @@ static const struct rtl_cfg_info {
1911 .intr_event = SYSErr | LinkChg | RxOverflow | PCSTimeout | 1914 .intr_event = SYSErr | LinkChg | RxOverflow | PCSTimeout |
1912 RxFIFOOver | TxErr | TxOK | RxOK | RxErr, 1915 RxFIFOOver | TxErr | TxOK | RxOK | RxErr,
1913 .napi_event = RxFIFOOver | TxErr | TxOK | RxOK | RxOverflow, 1916 .napi_event = RxFIFOOver | TxErr | TxOK | RxOK | RxOverflow,
1914 .features = RTL_FEATURE_MSI 1917 .features = RTL_FEATURE_MSI,
1918 .default_ver = RTL_GIGA_MAC_VER_13,
1915 } 1919 }
1916}; 1920};
1917 1921
@@ -2092,6 +2096,15 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
2092 /* Identify chip attached to board */ 2096 /* Identify chip attached to board */
2093 rtl8169_get_mac_version(tp, ioaddr); 2097 rtl8169_get_mac_version(tp, ioaddr);
2094 2098
2099 /* Use appropriate default if unknown */
2100 if (tp->mac_version == RTL_GIGA_MAC_NONE) {
2101 if (netif_msg_probe(tp)) {
2102 dev_notice(&pdev->dev,
2103 "unknown MAC, using family default\n");
2104 }
2105 tp->mac_version = cfg->default_ver;
2106 }
2107
2095 rtl8169_print_mac_version(tp); 2108 rtl8169_print_mac_version(tp);
2096 2109
2097 for (i = 0; i < ARRAY_SIZE(rtl_chip_info); i++) { 2110 for (i = 0; i < ARRAY_SIZE(rtl_chip_info); i++) {
@@ -2099,13 +2112,9 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
2099 break; 2112 break;
2100 } 2113 }
2101 if (i == ARRAY_SIZE(rtl_chip_info)) { 2114 if (i == ARRAY_SIZE(rtl_chip_info)) {
2102 /* Unknown chip: assume array element #0, original RTL-8169 */ 2115 dev_err(&pdev->dev,
2103 if (netif_msg_probe(tp)) { 2116 "driver bug, MAC version not found in rtl_chip_info\n");
2104 dev_printk(KERN_DEBUG, &pdev->dev, 2117 goto err_out_msi_5;
2105 "unknown chip version, assuming %s\n",
2106 rtl_chip_info[0].name);
2107 }
2108 i = 0;
2109 } 2118 }
2110 tp->chipset = i; 2119 tp->chipset = i;
2111 2120
@@ -3270,8 +3279,6 @@ static int rtl8169_start_xmit(struct sk_buff *skb, struct net_device *dev)
3270 status = opts1 | len | (RingEnd * !((entry + 1) % NUM_TX_DESC)); 3279 status = opts1 | len | (RingEnd * !((entry + 1) % NUM_TX_DESC));
3271 txd->opts1 = cpu_to_le32(status); 3280 txd->opts1 = cpu_to_le32(status);
3272 3281
3273 dev->trans_start = jiffies;
3274
3275 tp->cur_tx += frags + 1; 3282 tp->cur_tx += frags + 1;
3276 3283
3277 smp_wmb(); 3284 smp_wmb();
@@ -3803,16 +3810,13 @@ static struct net_device_stats *rtl8169_get_stats(struct net_device *dev)
3803 return &dev->stats; 3810 return &dev->stats;
3804} 3811}
3805 3812
3806#ifdef CONFIG_PM 3813static void rtl8169_net_suspend(struct net_device *dev)
3807
3808static int rtl8169_suspend(struct pci_dev *pdev, pm_message_t state)
3809{ 3814{
3810 struct net_device *dev = pci_get_drvdata(pdev);
3811 struct rtl8169_private *tp = netdev_priv(dev); 3815 struct rtl8169_private *tp = netdev_priv(dev);
3812 void __iomem *ioaddr = tp->mmio_addr; 3816 void __iomem *ioaddr = tp->mmio_addr;
3813 3817
3814 if (!netif_running(dev)) 3818 if (!netif_running(dev))
3815 goto out_pci_suspend; 3819 return;
3816 3820
3817 netif_device_detach(dev); 3821 netif_device_detach(dev);
3818 netif_stop_queue(dev); 3822 netif_stop_queue(dev);
@@ -3824,24 +3828,25 @@ static int rtl8169_suspend(struct pci_dev *pdev, pm_message_t state)
3824 rtl8169_rx_missed(dev, ioaddr); 3828 rtl8169_rx_missed(dev, ioaddr);
3825 3829
3826 spin_unlock_irq(&tp->lock); 3830 spin_unlock_irq(&tp->lock);
3831}
3827 3832
3828out_pci_suspend: 3833#ifdef CONFIG_PM
3829 pci_save_state(pdev); 3834
3830 pci_enable_wake(pdev, pci_choose_state(pdev, state), 3835static int rtl8169_suspend(struct device *device)
3831 (tp->features & RTL_FEATURE_WOL) ? 1 : 0); 3836{
3832 pci_set_power_state(pdev, pci_choose_state(pdev, state)); 3837 struct pci_dev *pdev = to_pci_dev(device);
3838 struct net_device *dev = pci_get_drvdata(pdev);
3839
3840 rtl8169_net_suspend(dev);
3833 3841
3834 return 0; 3842 return 0;
3835} 3843}
3836 3844
3837static int rtl8169_resume(struct pci_dev *pdev) 3845static int rtl8169_resume(struct device *device)
3838{ 3846{
3847 struct pci_dev *pdev = to_pci_dev(device);
3839 struct net_device *dev = pci_get_drvdata(pdev); 3848 struct net_device *dev = pci_get_drvdata(pdev);
3840 3849
3841 pci_set_power_state(pdev, PCI_D0);
3842 pci_restore_state(pdev);
3843 pci_enable_wake(pdev, PCI_D0, 0);
3844
3845 if (!netif_running(dev)) 3850 if (!netif_running(dev))
3846 goto out; 3851 goto out;
3847 3852
@@ -3852,23 +3857,42 @@ out:
3852 return 0; 3857 return 0;
3853} 3858}
3854 3859
3860static struct dev_pm_ops rtl8169_pm_ops = {
3861 .suspend = rtl8169_suspend,
3862 .resume = rtl8169_resume,
3863 .freeze = rtl8169_suspend,
3864 .thaw = rtl8169_resume,
3865 .poweroff = rtl8169_suspend,
3866 .restore = rtl8169_resume,
3867};
3868
3869#define RTL8169_PM_OPS (&rtl8169_pm_ops)
3870
3871#else /* !CONFIG_PM */
3872
3873#define RTL8169_PM_OPS NULL
3874
3875#endif /* !CONFIG_PM */
3876
3855static void rtl_shutdown(struct pci_dev *pdev) 3877static void rtl_shutdown(struct pci_dev *pdev)
3856{ 3878{
3857 rtl8169_suspend(pdev, PMSG_SUSPEND); 3879 struct net_device *dev = pci_get_drvdata(pdev);
3858} 3880
3881 rtl8169_net_suspend(dev);
3859 3882
3860#endif /* CONFIG_PM */ 3883 if (system_state == SYSTEM_POWER_OFF) {
3884 pci_wake_from_d3(pdev, true);
3885 pci_set_power_state(pdev, PCI_D3hot);
3886 }
3887}
3861 3888
3862static struct pci_driver rtl8169_pci_driver = { 3889static struct pci_driver rtl8169_pci_driver = {
3863 .name = MODULENAME, 3890 .name = MODULENAME,
3864 .id_table = rtl8169_pci_tbl, 3891 .id_table = rtl8169_pci_tbl,
3865 .probe = rtl8169_init_one, 3892 .probe = rtl8169_init_one,
3866 .remove = __devexit_p(rtl8169_remove_one), 3893 .remove = __devexit_p(rtl8169_remove_one),
3867#ifdef CONFIG_PM
3868 .suspend = rtl8169_suspend,
3869 .resume = rtl8169_resume,
3870 .shutdown = rtl_shutdown, 3894 .shutdown = rtl_shutdown,
3871#endif 3895 .driver.pm = RTL8169_PM_OPS,
3872}; 3896};
3873 3897
3874static int __init rtl8169_init_module(void) 3898static int __init rtl8169_init_module(void)