lan743x: Add support for ethtool statistics
authorBryan Whitehead <Bryan.Whitehead@microchip.com>
Mon, 23 Jul 2018 20:16:28 +0000 (16:16 -0400)
committerDavid S. Miller <davem@davemloft.net>
Mon, 23 Jul 2018 21:09:18 +0000 (14:09 -0700)
Implement ethtool statistics

Signed-off-by: Bryan Whitehead <Bryan.Whitehead@microchip.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/microchip/lan743x_ethtool.c
drivers/net/ethernet/microchip/lan743x_main.c
drivers/net/ethernet/microchip/lan743x_main.h

index 5c4582c209af7655a95561a0c02c08b3c964247a..9ed9711c7df0e1d47ffdb2d93240aa4571f84e67 100644 (file)
@@ -17,10 +17,190 @@ static void lan743x_ethtool_get_drvinfo(struct net_device *netdev,
                pci_name(adapter->pdev), sizeof(info->bus_info));
 }
 
+static const char lan743x_set0_hw_cnt_strings[][ETH_GSTRING_LEN] = {
+       "RX FCS Errors",
+       "RX Alignment Errors",
+       "Rx Fragment Errors",
+       "RX Jabber Errors",
+       "RX Undersize Frame Errors",
+       "RX Oversize Frame Errors",
+       "RX Dropped Frames",
+       "RX Unicast Byte Count",
+       "RX Broadcast Byte Count",
+       "RX Multicast Byte Count",
+       "RX Unicast Frames",
+       "RX Broadcast Frames",
+       "RX Multicast Frames",
+       "RX Pause Frames",
+       "RX 64 Byte Frames",
+       "RX 65 - 127 Byte Frames",
+       "RX 128 - 255 Byte Frames",
+       "RX 256 - 511 Bytes Frames",
+       "RX 512 - 1023 Byte Frames",
+       "RX 1024 - 1518 Byte Frames",
+       "RX Greater 1518 Byte Frames",
+};
+
+static const char lan743x_set1_sw_cnt_strings[][ETH_GSTRING_LEN] = {
+       "RX Queue 0 Frames",
+       "RX Queue 1 Frames",
+       "RX Queue 2 Frames",
+       "RX Queue 3 Frames",
+};
+
+static const char lan743x_set2_hw_cnt_strings[][ETH_GSTRING_LEN] = {
+       "RX Total Frames",
+       "EEE RX LPI Transitions",
+       "EEE RX LPI Time",
+       "RX Counter Rollover Status",
+       "TX FCS Errors",
+       "TX Excess Deferral Errors",
+       "TX Carrier Errors",
+       "TX Bad Byte Count",
+       "TX Single Collisions",
+       "TX Multiple Collisions",
+       "TX Excessive Collision",
+       "TX Late Collisions",
+       "TX Unicast Byte Count",
+       "TX Broadcast Byte Count",
+       "TX Multicast Byte Count",
+       "TX Unicast Frames",
+       "TX Broadcast Frames",
+       "TX Multicast Frames",
+       "TX Pause Frames",
+       "TX 64 Byte Frames",
+       "TX 65 - 127 Byte Frames",
+       "TX 128 - 255 Byte Frames",
+       "TX 256 - 511 Bytes Frames",
+       "TX 512 - 1023 Byte Frames",
+       "TX 1024 - 1518 Byte Frames",
+       "TX Greater 1518 Byte Frames",
+       "TX Total Frames",
+       "EEE TX LPI Transitions",
+       "EEE TX LPI Time",
+       "TX Counter Rollover Status",
+};
+
+static const u32 lan743x_set0_hw_cnt_addr[] = {
+       STAT_RX_FCS_ERRORS,
+       STAT_RX_ALIGNMENT_ERRORS,
+       STAT_RX_FRAGMENT_ERRORS,
+       STAT_RX_JABBER_ERRORS,
+       STAT_RX_UNDERSIZE_FRAME_ERRORS,
+       STAT_RX_OVERSIZE_FRAME_ERRORS,
+       STAT_RX_DROPPED_FRAMES,
+       STAT_RX_UNICAST_BYTE_COUNT,
+       STAT_RX_BROADCAST_BYTE_COUNT,
+       STAT_RX_MULTICAST_BYTE_COUNT,
+       STAT_RX_UNICAST_FRAMES,
+       STAT_RX_BROADCAST_FRAMES,
+       STAT_RX_MULTICAST_FRAMES,
+       STAT_RX_PAUSE_FRAMES,
+       STAT_RX_64_BYTE_FRAMES,
+       STAT_RX_65_127_BYTE_FRAMES,
+       STAT_RX_128_255_BYTE_FRAMES,
+       STAT_RX_256_511_BYTES_FRAMES,
+       STAT_RX_512_1023_BYTE_FRAMES,
+       STAT_RX_1024_1518_BYTE_FRAMES,
+       STAT_RX_GREATER_1518_BYTE_FRAMES,
+};
+
+static const u32 lan743x_set2_hw_cnt_addr[] = {
+       STAT_RX_TOTAL_FRAMES,
+       STAT_EEE_RX_LPI_TRANSITIONS,
+       STAT_EEE_RX_LPI_TIME,
+       STAT_RX_COUNTER_ROLLOVER_STATUS,
+       STAT_TX_FCS_ERRORS,
+       STAT_TX_EXCESS_DEFERRAL_ERRORS,
+       STAT_TX_CARRIER_ERRORS,
+       STAT_TX_BAD_BYTE_COUNT,
+       STAT_TX_SINGLE_COLLISIONS,
+       STAT_TX_MULTIPLE_COLLISIONS,
+       STAT_TX_EXCESSIVE_COLLISION,
+       STAT_TX_LATE_COLLISIONS,
+       STAT_TX_UNICAST_BYTE_COUNT,
+       STAT_TX_BROADCAST_BYTE_COUNT,
+       STAT_TX_MULTICAST_BYTE_COUNT,
+       STAT_TX_UNICAST_FRAMES,
+       STAT_TX_BROADCAST_FRAMES,
+       STAT_TX_MULTICAST_FRAMES,
+       STAT_TX_PAUSE_FRAMES,
+       STAT_TX_64_BYTE_FRAMES,
+       STAT_TX_65_127_BYTE_FRAMES,
+       STAT_TX_128_255_BYTE_FRAMES,
+       STAT_TX_256_511_BYTES_FRAMES,
+       STAT_TX_512_1023_BYTE_FRAMES,
+       STAT_TX_1024_1518_BYTE_FRAMES,
+       STAT_TX_GREATER_1518_BYTE_FRAMES,
+       STAT_TX_TOTAL_FRAMES,
+       STAT_EEE_TX_LPI_TRANSITIONS,
+       STAT_EEE_TX_LPI_TIME,
+       STAT_TX_COUNTER_ROLLOVER_STATUS
+};
+
+static void lan743x_ethtool_get_strings(struct net_device *netdev,
+                                       u32 stringset, u8 *data)
+{
+       switch (stringset) {
+       case ETH_SS_STATS:
+               memcpy(data, lan743x_set0_hw_cnt_strings,
+                      sizeof(lan743x_set0_hw_cnt_strings));
+               memcpy(&data[sizeof(lan743x_set0_hw_cnt_strings)],
+                      lan743x_set1_sw_cnt_strings,
+                      sizeof(lan743x_set1_sw_cnt_strings));
+               memcpy(&data[sizeof(lan743x_set0_hw_cnt_strings) +
+                      sizeof(lan743x_set1_sw_cnt_strings)],
+                      lan743x_set2_hw_cnt_strings,
+                      sizeof(lan743x_set2_hw_cnt_strings));
+               break;
+       }
+}
+
+static void lan743x_ethtool_get_ethtool_stats(struct net_device *netdev,
+                                             struct ethtool_stats *stats,
+                                             u64 *data)
+{
+       struct lan743x_adapter *adapter = netdev_priv(netdev);
+       int data_index = 0;
+       u32 buf;
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(lan743x_set0_hw_cnt_addr); i++) {
+               buf = lan743x_csr_read(adapter, lan743x_set0_hw_cnt_addr[i]);
+               data[data_index++] = (u64)buf;
+       }
+       for (i = 0; i < ARRAY_SIZE(adapter->rx); i++)
+               data[data_index++] = (u64)(adapter->rx[i].frame_count);
+       for (i = 0; i < ARRAY_SIZE(lan743x_set2_hw_cnt_addr); i++) {
+               buf = lan743x_csr_read(adapter, lan743x_set2_hw_cnt_addr[i]);
+               data[data_index++] = (u64)buf;
+       }
+}
+
+static int lan743x_ethtool_get_sset_count(struct net_device *netdev, int sset)
+{
+       switch (sset) {
+       case ETH_SS_STATS:
+       {
+               int ret;
+
+               ret = ARRAY_SIZE(lan743x_set0_hw_cnt_strings);
+               ret += ARRAY_SIZE(lan743x_set1_sw_cnt_strings);
+               ret += ARRAY_SIZE(lan743x_set2_hw_cnt_strings);
+               return ret;
+       }
+       default:
+               return -EOPNOTSUPP;
+       }
+}
+
 const struct ethtool_ops lan743x_ethtool_ops = {
        .get_drvinfo = lan743x_ethtool_get_drvinfo,
        .get_link = ethtool_op_get_link,
 
+       .get_strings = lan743x_ethtool_get_strings,
+       .get_ethtool_stats = lan743x_ethtool_get_ethtool_stats,
+       .get_sset_count = lan743x_ethtool_get_sset_count,
        .get_link_ksettings = phy_ethtool_get_link_ksettings,
        .set_link_ksettings = phy_ethtool_set_link_ksettings,
 };
index ade3b04b2de61ba20a2086aa97589877be22e1f7..1e2f8c67d022b4a8c94cbe32c1f42de1119c2c92 100644 (file)
@@ -54,13 +54,13 @@ return_error:
        return ret;
 }
 
-static u32 lan743x_csr_read(struct lan743x_adapter *adapter, int offset)
+u32 lan743x_csr_read(struct lan743x_adapter *adapter, int offset)
 {
        return ioread32(&adapter->csr.csr_address[offset]);
 }
 
-static void lan743x_csr_write(struct lan743x_adapter *adapter, int offset,
-                             u32 data)
+void lan743x_csr_write(struct lan743x_adapter *adapter, int offset,
+                      u32 data)
 {
        iowrite32(data, &adapter->csr.csr_address[offset]);
 }
index 73b463a9df61f31197b777f3b1db6c53e0f7509d..de4f2cceaad1b5eb5177446ab5ed4e79bfeeab07 100644 (file)
 /* MAC statistics registers */
 #define STAT_RX_FCS_ERRORS                     (0x1200)
 #define STAT_RX_ALIGNMENT_ERRORS               (0x1204)
+#define STAT_RX_FRAGMENT_ERRORS                        (0x1208)
 #define STAT_RX_JABBER_ERRORS                  (0x120C)
 #define STAT_RX_UNDERSIZE_FRAME_ERRORS         (0x1210)
 #define STAT_RX_OVERSIZE_FRAME_ERRORS          (0x1214)
 #define STAT_RX_UNICAST_BYTE_COUNT             (0x121C)
 #define STAT_RX_BROADCAST_BYTE_COUNT           (0x1220)
 #define STAT_RX_MULTICAST_BYTE_COUNT           (0x1224)
+#define STAT_RX_UNICAST_FRAMES                 (0x1228)
+#define STAT_RX_BROADCAST_FRAMES               (0x122C)
 #define STAT_RX_MULTICAST_FRAMES               (0x1230)
+#define STAT_RX_PAUSE_FRAMES                   (0x1234)
+#define STAT_RX_64_BYTE_FRAMES                 (0x1238)
+#define STAT_RX_65_127_BYTE_FRAMES             (0x123C)
+#define STAT_RX_128_255_BYTE_FRAMES            (0x1240)
+#define STAT_RX_256_511_BYTES_FRAMES           (0x1244)
+#define STAT_RX_512_1023_BYTE_FRAMES           (0x1248)
+#define STAT_RX_1024_1518_BYTE_FRAMES          (0x124C)
+#define STAT_RX_GREATER_1518_BYTE_FRAMES       (0x1250)
 #define STAT_RX_TOTAL_FRAMES                   (0x1254)
+#define STAT_EEE_RX_LPI_TRANSITIONS            (0x1258)
+#define STAT_EEE_RX_LPI_TIME                   (0x125C)
+#define STAT_RX_COUNTER_ROLLOVER_STATUS                (0x127C)
 
 #define STAT_TX_FCS_ERRORS                     (0x1280)
 #define STAT_TX_EXCESS_DEFERRAL_ERRORS         (0x1284)
 #define STAT_TX_CARRIER_ERRORS                 (0x1288)
+#define STAT_TX_BAD_BYTE_COUNT                 (0x128C)
 #define STAT_TX_SINGLE_COLLISIONS              (0x1290)
 #define STAT_TX_MULTIPLE_COLLISIONS            (0x1294)
 #define STAT_TX_EXCESSIVE_COLLISION            (0x1298)
 #define STAT_TX_UNICAST_BYTE_COUNT             (0x12A0)
 #define STAT_TX_BROADCAST_BYTE_COUNT           (0x12A4)
 #define STAT_TX_MULTICAST_BYTE_COUNT           (0x12A8)
+#define STAT_TX_UNICAST_FRAMES                 (0x12AC)
+#define STAT_TX_BROADCAST_FRAMES               (0x12B0)
 #define STAT_TX_MULTICAST_FRAMES               (0x12B4)
+#define STAT_TX_PAUSE_FRAMES                   (0x12B8)
+#define STAT_TX_64_BYTE_FRAMES                 (0x12BC)
+#define STAT_TX_65_127_BYTE_FRAMES             (0x12C0)
+#define STAT_TX_128_255_BYTE_FRAMES            (0x12C4)
+#define STAT_TX_256_511_BYTES_FRAMES           (0x12C8)
+#define STAT_TX_512_1023_BYTE_FRAMES           (0x12CC)
+#define STAT_TX_1024_1518_BYTE_FRAMES          (0x12D0)
+#define STAT_TX_GREATER_1518_BYTE_FRAMES       (0x12D4)
 #define STAT_TX_TOTAL_FRAMES                   (0x12D8)
+#define STAT_EEE_TX_LPI_TRANSITIONS            (0x12DC)
+#define STAT_EEE_TX_LPI_TIME                   (0x12E0)
+#define STAT_TX_COUNTER_ROLLOVER_STATUS                (0x12FC)
 
 /* End of Register definitions */
 
@@ -594,4 +622,7 @@ struct lan743x_rx_buffer_info {
 #define RX_PROCESS_RESULT_PACKET_RECEIVED   (1)
 #define RX_PROCESS_RESULT_PACKET_DROPPED    (2)
 
+u32 lan743x_csr_read(struct lan743x_adapter *adapter, int offset);
+void lan743x_csr_write(struct lan743x_adapter *adapter, int offset, u32 data);
+
 #endif /* _LAN743X_H */