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