070-v4.8-0002-bgmac-Add-support-for-ethtool-statistics.patch 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. From f6613d4fa937fa8388f2c1cb4e69ccc25e9e2336 Mon Sep 17 00:00:00 2001
  2. From: Florian Fainelli <f.fainelli@gmail.com>
  3. Date: Tue, 7 Jun 2016 15:06:14 -0700
  4. Subject: [PATCH 2/3] bgmac: Add support for ethtool statistics
  5. Read the statistics from the BGMAC's builtin MAC and return them to
  6. user-space using the standard ethtool helpers.
  7. Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
  8. Signed-off-by: David S. Miller <davem@davemloft.net>
  9. ---
  10. drivers/net/ethernet/broadcom/bgmac.c | 124 ++++++++++++++++++++++++++++++++++
  11. drivers/net/ethernet/broadcom/bgmac.h | 4 +-
  12. 2 files changed, 126 insertions(+), 2 deletions(-)
  13. --- a/drivers/net/ethernet/broadcom/bgmac.c
  14. +++ b/drivers/net/ethernet/broadcom/bgmac.c
  15. @@ -1387,6 +1387,127 @@ static const struct net_device_ops bgmac
  16. * ethtool_ops
  17. **************************************************/
  18. +struct bgmac_stat {
  19. + u8 size;
  20. + u32 offset;
  21. + const char *name;
  22. +};
  23. +
  24. +static struct bgmac_stat bgmac_get_strings_stats[] = {
  25. + { 8, BGMAC_TX_GOOD_OCTETS, "tx_good_octets" },
  26. + { 4, BGMAC_TX_GOOD_PKTS, "tx_good" },
  27. + { 8, BGMAC_TX_OCTETS, "tx_octets" },
  28. + { 4, BGMAC_TX_PKTS, "tx_pkts" },
  29. + { 4, BGMAC_TX_BROADCAST_PKTS, "tx_broadcast" },
  30. + { 4, BGMAC_TX_MULTICAST_PKTS, "tx_multicast" },
  31. + { 4, BGMAC_TX_LEN_64, "tx_64" },
  32. + { 4, BGMAC_TX_LEN_65_TO_127, "tx_65_127" },
  33. + { 4, BGMAC_TX_LEN_128_TO_255, "tx_128_255" },
  34. + { 4, BGMAC_TX_LEN_256_TO_511, "tx_256_511" },
  35. + { 4, BGMAC_TX_LEN_512_TO_1023, "tx_512_1023" },
  36. + { 4, BGMAC_TX_LEN_1024_TO_1522, "tx_1024_1522" },
  37. + { 4, BGMAC_TX_LEN_1523_TO_2047, "tx_1523_2047" },
  38. + { 4, BGMAC_TX_LEN_2048_TO_4095, "tx_2048_4095" },
  39. + { 4, BGMAC_TX_LEN_4096_TO_8191, "tx_4096_8191" },
  40. + { 4, BGMAC_TX_LEN_8192_TO_MAX, "tx_8192_max" },
  41. + { 4, BGMAC_TX_JABBER_PKTS, "tx_jabber" },
  42. + { 4, BGMAC_TX_OVERSIZE_PKTS, "tx_oversize" },
  43. + { 4, BGMAC_TX_FRAGMENT_PKTS, "tx_fragment" },
  44. + { 4, BGMAC_TX_UNDERRUNS, "tx_underruns" },
  45. + { 4, BGMAC_TX_TOTAL_COLS, "tx_total_cols" },
  46. + { 4, BGMAC_TX_SINGLE_COLS, "tx_single_cols" },
  47. + { 4, BGMAC_TX_MULTIPLE_COLS, "tx_multiple_cols" },
  48. + { 4, BGMAC_TX_EXCESSIVE_COLS, "tx_excessive_cols" },
  49. + { 4, BGMAC_TX_LATE_COLS, "tx_late_cols" },
  50. + { 4, BGMAC_TX_DEFERED, "tx_defered" },
  51. + { 4, BGMAC_TX_CARRIER_LOST, "tx_carrier_lost" },
  52. + { 4, BGMAC_TX_PAUSE_PKTS, "tx_pause" },
  53. + { 4, BGMAC_TX_UNI_PKTS, "tx_unicast" },
  54. + { 4, BGMAC_TX_Q0_PKTS, "tx_q0" },
  55. + { 8, BGMAC_TX_Q0_OCTETS, "tx_q0_octets" },
  56. + { 4, BGMAC_TX_Q1_PKTS, "tx_q1" },
  57. + { 8, BGMAC_TX_Q1_OCTETS, "tx_q1_octets" },
  58. + { 4, BGMAC_TX_Q2_PKTS, "tx_q2" },
  59. + { 8, BGMAC_TX_Q2_OCTETS, "tx_q2_octets" },
  60. + { 4, BGMAC_TX_Q3_PKTS, "tx_q3" },
  61. + { 8, BGMAC_TX_Q3_OCTETS, "tx_q3_octets" },
  62. + { 8, BGMAC_RX_GOOD_OCTETS, "rx_good_octets" },
  63. + { 4, BGMAC_RX_GOOD_PKTS, "rx_good" },
  64. + { 8, BGMAC_RX_OCTETS, "rx_octets" },
  65. + { 4, BGMAC_RX_PKTS, "rx_pkts" },
  66. + { 4, BGMAC_RX_BROADCAST_PKTS, "rx_broadcast" },
  67. + { 4, BGMAC_RX_MULTICAST_PKTS, "rx_multicast" },
  68. + { 4, BGMAC_RX_LEN_64, "rx_64" },
  69. + { 4, BGMAC_RX_LEN_65_TO_127, "rx_65_127" },
  70. + { 4, BGMAC_RX_LEN_128_TO_255, "rx_128_255" },
  71. + { 4, BGMAC_RX_LEN_256_TO_511, "rx_256_511" },
  72. + { 4, BGMAC_RX_LEN_512_TO_1023, "rx_512_1023" },
  73. + { 4, BGMAC_RX_LEN_1024_TO_1522, "rx_1024_1522" },
  74. + { 4, BGMAC_RX_LEN_1523_TO_2047, "rx_1523_2047" },
  75. + { 4, BGMAC_RX_LEN_2048_TO_4095, "rx_2048_4095" },
  76. + { 4, BGMAC_RX_LEN_4096_TO_8191, "rx_4096_8191" },
  77. + { 4, BGMAC_RX_LEN_8192_TO_MAX, "rx_8192_max" },
  78. + { 4, BGMAC_RX_JABBER_PKTS, "rx_jabber" },
  79. + { 4, BGMAC_RX_OVERSIZE_PKTS, "rx_oversize" },
  80. + { 4, BGMAC_RX_FRAGMENT_PKTS, "rx_fragment" },
  81. + { 4, BGMAC_RX_MISSED_PKTS, "rx_missed" },
  82. + { 4, BGMAC_RX_CRC_ALIGN_ERRS, "rx_crc_align" },
  83. + { 4, BGMAC_RX_UNDERSIZE, "rx_undersize" },
  84. + { 4, BGMAC_RX_CRC_ERRS, "rx_crc" },
  85. + { 4, BGMAC_RX_ALIGN_ERRS, "rx_align" },
  86. + { 4, BGMAC_RX_SYMBOL_ERRS, "rx_symbol" },
  87. + { 4, BGMAC_RX_PAUSE_PKTS, "rx_pause" },
  88. + { 4, BGMAC_RX_NONPAUSE_PKTS, "rx_nonpause" },
  89. + { 4, BGMAC_RX_SACHANGES, "rx_sa_changes" },
  90. + { 4, BGMAC_RX_UNI_PKTS, "rx_unicast" },
  91. +};
  92. +
  93. +#define BGMAC_STATS_LEN ARRAY_SIZE(bgmac_get_strings_stats)
  94. +
  95. +static int bgmac_get_sset_count(struct net_device *dev, int string_set)
  96. +{
  97. + switch (string_set) {
  98. + case ETH_SS_STATS:
  99. + return BGMAC_STATS_LEN;
  100. + }
  101. +
  102. + return -EOPNOTSUPP;
  103. +}
  104. +
  105. +static void bgmac_get_strings(struct net_device *dev, u32 stringset,
  106. + u8 *data)
  107. +{
  108. + int i;
  109. +
  110. + if (stringset != ETH_SS_STATS)
  111. + return;
  112. +
  113. + for (i = 0; i < BGMAC_STATS_LEN; i++)
  114. + strlcpy(data + i * ETH_GSTRING_LEN,
  115. + bgmac_get_strings_stats[i].name, ETH_GSTRING_LEN);
  116. +}
  117. +
  118. +static void bgmac_get_ethtool_stats(struct net_device *dev,
  119. + struct ethtool_stats *ss, uint64_t *data)
  120. +{
  121. + struct bgmac *bgmac = netdev_priv(dev);
  122. + const struct bgmac_stat *s;
  123. + unsigned int i;
  124. + u64 val;
  125. +
  126. + if (!netif_running(dev))
  127. + return;
  128. +
  129. + for (i = 0; i < BGMAC_STATS_LEN; i++) {
  130. + s = &bgmac_get_strings_stats[i];
  131. + val = 0;
  132. + if (s->size == 8)
  133. + val = (u64)bgmac_read(bgmac, s->offset + 4) << 32;
  134. + val |= bgmac_read(bgmac, s->offset);
  135. + data[i] = val;
  136. + }
  137. +}
  138. +
  139. static int bgmac_get_settings(struct net_device *net_dev,
  140. struct ethtool_cmd *cmd)
  141. {
  142. @@ -1411,6 +1532,9 @@ static void bgmac_get_drvinfo(struct net
  143. }
  144. static const struct ethtool_ops bgmac_ethtool_ops = {
  145. + .get_strings = bgmac_get_strings,
  146. + .get_sset_count = bgmac_get_sset_count,
  147. + .get_ethtool_stats = bgmac_get_ethtool_stats,
  148. .get_settings = bgmac_get_settings,
  149. .set_settings = bgmac_set_settings,
  150. .get_drvinfo = bgmac_get_drvinfo,
  151. --- a/drivers/net/ethernet/broadcom/bgmac.h
  152. +++ b/drivers/net/ethernet/broadcom/bgmac.h
  153. @@ -123,7 +123,7 @@
  154. #define BGMAC_TX_LEN_1024_TO_1522 0x334
  155. #define BGMAC_TX_LEN_1523_TO_2047 0x338
  156. #define BGMAC_TX_LEN_2048_TO_4095 0x33c
  157. -#define BGMAC_TX_LEN_4095_TO_8191 0x340
  158. +#define BGMAC_TX_LEN_4096_TO_8191 0x340
  159. #define BGMAC_TX_LEN_8192_TO_MAX 0x344
  160. #define BGMAC_TX_JABBER_PKTS 0x348 /* Error */
  161. #define BGMAC_TX_OVERSIZE_PKTS 0x34c /* Error */
  162. @@ -166,7 +166,7 @@
  163. #define BGMAC_RX_LEN_1024_TO_1522 0x3e4
  164. #define BGMAC_RX_LEN_1523_TO_2047 0x3e8
  165. #define BGMAC_RX_LEN_2048_TO_4095 0x3ec
  166. -#define BGMAC_RX_LEN_4095_TO_8191 0x3f0
  167. +#define BGMAC_RX_LEN_4096_TO_8191 0x3f0
  168. #define BGMAC_RX_LEN_8192_TO_MAX 0x3f4
  169. #define BGMAC_RX_JABBER_PKTS 0x3f8 /* Error */
  170. #define BGMAC_RX_OVERSIZE_PKTS 0x3fc /* Error */