@@ -637,6 +637,9 @@ enum rtl_register_content {
/* _TBICSRBit */
TBILinkOK = 0x02000000,
+ /* ResetCounterCommand */
+ CounterReset = 0x1,
+
/* DumpCounterCommand */
CounterDump = 0x8,
@@ -2188,6 +2191,31 @@ static int rtl8169_get_sset_count(struct net_device *dev, int sset)
}
}
+DECLARE_RTL_COND(rtl_reset_counters_cond)
+{
+ void __iomem *ioaddr = tp->mmio_addr;
+
+ return RTL_R32(CounterAddrLow) & CounterReset;
+}
+
+static void rtl8169_reset_counters(struct net_device *dev)
+{
+ struct rtl8169_private *tp = netdev_priv(dev);
+ void __iomem *ioaddr = tp->mmio_addr;
+
+ /*
+ * Versions prior to RTL_GIGA_MAC_VER_19 don't support resetting the
+ * tally counters.
+ */
+ if (tp->mac_version >= RTL_GIGA_MAC_VER_19) {
+ RTL_W32(CounterAddrHigh, 0);
+ RTL_W32(CounterAddrLow, CounterReset);
+ if (!rtl_udelay_loop_wait_low(tp, &rtl_reset_counters_cond,
+ 10, 1000))
+ netif_warn(tp, hw, dev, "counter reset failed\n");
+ }
+}
+
DECLARE_RTL_COND(rtl_counters_cond)
{
void __iomem *ioaddr = tp->mmio_addr;
@@ -2234,11 +2262,10 @@ static void rtl8169_init_tc_counter_offset(struct net_device *dev)
struct rtl8169_private *tp = netdev_priv(dev);
/*
- * rtl8169_init_tc_counter_offset is called from rtl_open. The tally
- * counters are only reset by a power cycle, while the counter values
- * collected by the driver are reset at every driver unload/load cycle.
- * There's also no (documented?) way to reset the tally counters
- * programatically.
+ * rtl8169_init_tc_counter_offset is called from rtl_open. On chip
+ * versions prior to RTL_GIGA_MAC_VER_19 the tally counters are only
+ * reset by a power cycle, while the counter values collected by the
+ * driver are reset at every driver unload/load cycle.
*
* To make sure the HW values returned by @get_stats64 match the SW
* values, we collect the initial values at first open(*) and use them
@@ -2252,6 +2279,8 @@ static void rtl8169_init_tc_counter_offset(struct net_device *dev)
if (tp->tc_offset.inited)
return;
+ rtl8169_reset_counters(dev);
+
rtl8169_update_counters(dev);
tp->tc_offset.tx_errors = tp->counters.tx_errors;