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.c93
1 files changed, 58 insertions, 35 deletions
diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
index 2c73ca606b3..0771eb6fc6e 100644
--- a/drivers/net/r8169.c
+++ b/drivers/net/r8169.c
@@ -437,6 +437,22 @@ enum features {
437 RTL_FEATURE_GMII = (1 << 2), 437 RTL_FEATURE_GMII = (1 << 2),
438}; 438};
439 439
440struct rtl8169_counters {
441 __le64 tx_packets;
442 __le64 rx_packets;
443 __le64 tx_errors;
444 __le32 rx_errors;
445 __le16 rx_missed;
446 __le16 align_errors;
447 __le32 tx_one_collision;
448 __le32 tx_multi_collision;
449 __le64 rx_unicast;
450 __le64 rx_broadcast;
451 __le32 rx_multicast;
452 __le16 tx_aborted;
453 __le16 tx_underun;
454};
455
440struct rtl8169_private { 456struct rtl8169_private {
441 void __iomem *mmio_addr; /* memory map physical address */ 457 void __iomem *mmio_addr; /* memory map physical address */
442 struct pci_dev *pci_dev; /* Index of PCI device */ 458 struct pci_dev *pci_dev; /* Index of PCI device */
@@ -480,6 +496,7 @@ struct rtl8169_private {
480 unsigned features; 496 unsigned features;
481 497
482 struct mii_if_info mii; 498 struct mii_if_info mii;
499 struct rtl8169_counters counters;
483}; 500};
484 501
485MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>"); 502MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>");
@@ -1100,22 +1117,6 @@ static const char rtl8169_gstrings[][ETH_GSTRING_LEN] = {
1100 "tx_underrun", 1117 "tx_underrun",
1101}; 1118};
1102 1119
1103struct rtl8169_counters {
1104 __le64 tx_packets;
1105 __le64 rx_packets;
1106 __le64 tx_errors;
1107 __le32 rx_errors;
1108 __le16 rx_missed;
1109 __le16 align_errors;
1110 __le32 tx_one_collision;
1111 __le32 tx_multi_collision;
1112 __le64 rx_unicast;
1113 __le64 rx_broadcast;
1114 __le32 rx_multicast;
1115 __le16 tx_aborted;
1116 __le16 tx_underun;
1117};
1118
1119static int rtl8169_get_sset_count(struct net_device *dev, int sset) 1120static int rtl8169_get_sset_count(struct net_device *dev, int sset)
1120{ 1121{
1121 switch (sset) { 1122 switch (sset) {
@@ -1126,16 +1127,21 @@ static int rtl8169_get_sset_count(struct net_device *dev, int sset)
1126 } 1127 }
1127} 1128}
1128 1129
1129static void rtl8169_get_ethtool_stats(struct net_device *dev, 1130static void rtl8169_update_counters(struct net_device *dev)
1130 struct ethtool_stats *stats, u64 *data)
1131{ 1131{
1132 struct rtl8169_private *tp = netdev_priv(dev); 1132 struct rtl8169_private *tp = netdev_priv(dev);
1133 void __iomem *ioaddr = tp->mmio_addr; 1133 void __iomem *ioaddr = tp->mmio_addr;
1134 struct rtl8169_counters *counters; 1134 struct rtl8169_counters *counters;
1135 dma_addr_t paddr; 1135 dma_addr_t paddr;
1136 u32 cmd; 1136 u32 cmd;
1137 int wait = 1000;
1137 1138
1138 ASSERT_RTNL(); 1139 /*
1140 * Some chips are unable to dump tally counters when the receiver
1141 * is disabled.
1142 */
1143 if ((RTL_R8(ChipCmd) & CmdRxEnb) == 0)
1144 return;
1139 1145
1140 counters = pci_alloc_consistent(tp->pci_dev, sizeof(*counters), &paddr); 1146 counters = pci_alloc_consistent(tp->pci_dev, sizeof(*counters), &paddr);
1141 if (!counters) 1147 if (!counters)
@@ -1146,31 +1152,45 @@ static void rtl8169_get_ethtool_stats(struct net_device *dev,
1146 RTL_W32(CounterAddrLow, cmd); 1152 RTL_W32(CounterAddrLow, cmd);
1147 RTL_W32(CounterAddrLow, cmd | CounterDump); 1153 RTL_W32(CounterAddrLow, cmd | CounterDump);
1148 1154
1149 while (RTL_R32(CounterAddrLow) & CounterDump) { 1155 while (wait--) {
1150 if (msleep_interruptible(1)) 1156 if ((RTL_R32(CounterAddrLow) & CounterDump) == 0) {
1157 /* copy updated counters */
1158 memcpy(&tp->counters, counters, sizeof(*counters));
1151 break; 1159 break;
1160 }
1161 udelay(10);
1152 } 1162 }
1153 1163
1154 RTL_W32(CounterAddrLow, 0); 1164 RTL_W32(CounterAddrLow, 0);
1155 RTL_W32(CounterAddrHigh, 0); 1165 RTL_W32(CounterAddrHigh, 0);
1156 1166
1157 data[0] = le64_to_cpu(counters->tx_packets);
1158 data[1] = le64_to_cpu(counters->rx_packets);
1159 data[2] = le64_to_cpu(counters->tx_errors);
1160 data[3] = le32_to_cpu(counters->rx_errors);
1161 data[4] = le16_to_cpu(counters->rx_missed);
1162 data[5] = le16_to_cpu(counters->align_errors);
1163 data[6] = le32_to_cpu(counters->tx_one_collision);
1164 data[7] = le32_to_cpu(counters->tx_multi_collision);
1165 data[8] = le64_to_cpu(counters->rx_unicast);
1166 data[9] = le64_to_cpu(counters->rx_broadcast);
1167 data[10] = le32_to_cpu(counters->rx_multicast);
1168 data[11] = le16_to_cpu(counters->tx_aborted);
1169 data[12] = le16_to_cpu(counters->tx_underun);
1170
1171 pci_free_consistent(tp->pci_dev, sizeof(*counters), counters, paddr); 1167 pci_free_consistent(tp->pci_dev, sizeof(*counters), counters, paddr);
1172} 1168}
1173 1169
1170static void rtl8169_get_ethtool_stats(struct net_device *dev,
1171 struct ethtool_stats *stats, u64 *data)
1172{
1173 struct rtl8169_private *tp = netdev_priv(dev);
1174
1175 ASSERT_RTNL();
1176
1177 rtl8169_update_counters(dev);
1178
1179 data[0] = le64_to_cpu(tp->counters.tx_packets);
1180 data[1] = le64_to_cpu(tp->counters.rx_packets);
1181 data[2] = le64_to_cpu(tp->counters.tx_errors);
1182 data[3] = le32_to_cpu(tp->counters.rx_errors);
1183 data[4] = le16_to_cpu(tp->counters.rx_missed);
1184 data[5] = le16_to_cpu(tp->counters.align_errors);
1185 data[6] = le32_to_cpu(tp->counters.tx_one_collision);
1186 data[7] = le32_to_cpu(tp->counters.tx_multi_collision);
1187 data[8] = le64_to_cpu(tp->counters.rx_unicast);
1188 data[9] = le64_to_cpu(tp->counters.rx_broadcast);
1189 data[10] = le32_to_cpu(tp->counters.rx_multicast);
1190 data[11] = le16_to_cpu(tp->counters.tx_aborted);
1191 data[12] = le16_to_cpu(tp->counters.tx_underun);
1192}
1193
1174static void rtl8169_get_strings(struct net_device *dev, u32 stringset, u8 *data) 1194static void rtl8169_get_strings(struct net_device *dev, u32 stringset, u8 *data)
1175{ 1195{
1176 switch(stringset) { 1196 switch(stringset) {
@@ -3682,6 +3702,9 @@ static int rtl8169_close(struct net_device *dev)
3682 struct rtl8169_private *tp = netdev_priv(dev); 3702 struct rtl8169_private *tp = netdev_priv(dev);
3683 struct pci_dev *pdev = tp->pci_dev; 3703 struct pci_dev *pdev = tp->pci_dev;
3684 3704
3705 /* update counters before going down */
3706 rtl8169_update_counters(dev);
3707
3685 rtl8169_down(dev); 3708 rtl8169_down(dev);
3686 3709
3687 free_irq(dev->irq, dev); 3710 free_irq(dev->irq, dev);