ethtool.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * Applied Micro X-Gene SoC Ethernet v2 Driver
  3. *
  4. * Copyright (c) 2017, Applied Micro Circuits Corporation
  5. * Author(s): Iyappan Subramanian <isubramanian@apm.com>
  6. * Keyur Chudgar <kchudgar@apm.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include "main.h"
  22. #define XGE_STAT(m) { #m, offsetof(struct xge_pdata, stats.m) }
  23. #define XGE_EXTD_STAT(m, n) \
  24. { \
  25. #m, \
  26. n, \
  27. 0 \
  28. }
  29. static const struct xge_gstrings_stats gstrings_stats[] = {
  30. XGE_STAT(rx_packets),
  31. XGE_STAT(tx_packets),
  32. XGE_STAT(rx_bytes),
  33. XGE_STAT(tx_bytes),
  34. XGE_STAT(rx_errors)
  35. };
  36. static struct xge_gstrings_extd_stats gstrings_extd_stats[] = {
  37. XGE_EXTD_STAT(tx_rx_64b_frame_cntr, TR64),
  38. XGE_EXTD_STAT(tx_rx_127b_frame_cntr, TR127),
  39. XGE_EXTD_STAT(tx_rx_255b_frame_cntr, TR255),
  40. XGE_EXTD_STAT(tx_rx_511b_frame_cntr, TR511),
  41. XGE_EXTD_STAT(tx_rx_1023b_frame_cntr, TR1K),
  42. XGE_EXTD_STAT(tx_rx_1518b_frame_cntr, TRMAX),
  43. XGE_EXTD_STAT(tx_rx_1522b_frame_cntr, TRMGV),
  44. XGE_EXTD_STAT(rx_fcs_error_cntr, RFCS),
  45. XGE_EXTD_STAT(rx_multicast_pkt_cntr, RMCA),
  46. XGE_EXTD_STAT(rx_broadcast_pkt_cntr, RBCA),
  47. XGE_EXTD_STAT(rx_ctrl_frame_pkt_cntr, RXCF),
  48. XGE_EXTD_STAT(rx_pause_frame_pkt_cntr, RXPF),
  49. XGE_EXTD_STAT(rx_unk_opcode_cntr, RXUO),
  50. XGE_EXTD_STAT(rx_align_err_cntr, RALN),
  51. XGE_EXTD_STAT(rx_frame_len_err_cntr, RFLR),
  52. XGE_EXTD_STAT(rx_code_err_cntr, RCDE),
  53. XGE_EXTD_STAT(rx_carrier_sense_err_cntr, RCSE),
  54. XGE_EXTD_STAT(rx_undersize_pkt_cntr, RUND),
  55. XGE_EXTD_STAT(rx_oversize_pkt_cntr, ROVR),
  56. XGE_EXTD_STAT(rx_fragments_cntr, RFRG),
  57. XGE_EXTD_STAT(rx_jabber_cntr, RJBR),
  58. XGE_EXTD_STAT(rx_dropped_pkt_cntr, RDRP),
  59. XGE_EXTD_STAT(tx_multicast_pkt_cntr, TMCA),
  60. XGE_EXTD_STAT(tx_broadcast_pkt_cntr, TBCA),
  61. XGE_EXTD_STAT(tx_pause_ctrl_frame_cntr, TXPF),
  62. XGE_EXTD_STAT(tx_defer_pkt_cntr, TDFR),
  63. XGE_EXTD_STAT(tx_excv_defer_pkt_cntr, TEDF),
  64. XGE_EXTD_STAT(tx_single_col_pkt_cntr, TSCL),
  65. XGE_EXTD_STAT(tx_multi_col_pkt_cntr, TMCL),
  66. XGE_EXTD_STAT(tx_late_col_pkt_cntr, TLCL),
  67. XGE_EXTD_STAT(tx_excv_col_pkt_cntr, TXCL),
  68. XGE_EXTD_STAT(tx_total_col_cntr, TNCL),
  69. XGE_EXTD_STAT(tx_pause_frames_hnrd_cntr, TPFH),
  70. XGE_EXTD_STAT(tx_drop_frame_cntr, TDRP),
  71. XGE_EXTD_STAT(tx_jabber_frame_cntr, TJBR),
  72. XGE_EXTD_STAT(tx_fcs_error_cntr, TFCS),
  73. XGE_EXTD_STAT(tx_ctrl_frame_cntr, TXCF),
  74. XGE_EXTD_STAT(tx_oversize_frame_cntr, TOVR),
  75. XGE_EXTD_STAT(tx_undersize_frame_cntr, TUND),
  76. XGE_EXTD_STAT(tx_fragments_cntr, TFRG)
  77. };
  78. #define XGE_STATS_LEN ARRAY_SIZE(gstrings_stats)
  79. #define XGE_EXTD_STATS_LEN ARRAY_SIZE(gstrings_extd_stats)
  80. static void xge_mac_get_extd_stats(struct xge_pdata *pdata)
  81. {
  82. u32 data;
  83. int i;
  84. for (i = 0; i < XGE_EXTD_STATS_LEN; i++) {
  85. data = xge_rd_csr(pdata, gstrings_extd_stats[i].addr);
  86. gstrings_extd_stats[i].value += data;
  87. }
  88. }
  89. static void xge_get_drvinfo(struct net_device *ndev,
  90. struct ethtool_drvinfo *info)
  91. {
  92. struct xge_pdata *pdata = netdev_priv(ndev);
  93. struct platform_device *pdev = pdata->pdev;
  94. strcpy(info->driver, "xgene-enet-v2");
  95. strcpy(info->version, XGENE_ENET_V2_VERSION);
  96. snprintf(info->fw_version, ETHTOOL_FWVERS_LEN, "N/A");
  97. sprintf(info->bus_info, "%s", pdev->name);
  98. }
  99. static void xge_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
  100. {
  101. u8 *p = data;
  102. int i;
  103. if (stringset != ETH_SS_STATS)
  104. return;
  105. for (i = 0; i < XGE_STATS_LEN; i++) {
  106. memcpy(p, gstrings_stats[i].name, ETH_GSTRING_LEN);
  107. p += ETH_GSTRING_LEN;
  108. }
  109. for (i = 0; i < XGE_EXTD_STATS_LEN; i++) {
  110. memcpy(p, gstrings_extd_stats[i].name, ETH_GSTRING_LEN);
  111. p += ETH_GSTRING_LEN;
  112. }
  113. }
  114. static int xge_get_sset_count(struct net_device *ndev, int sset)
  115. {
  116. if (sset != ETH_SS_STATS)
  117. return -EINVAL;
  118. return XGE_STATS_LEN + XGE_EXTD_STATS_LEN;
  119. }
  120. static void xge_get_ethtool_stats(struct net_device *ndev,
  121. struct ethtool_stats *dummy,
  122. u64 *data)
  123. {
  124. void *pdata = netdev_priv(ndev);
  125. int i;
  126. for (i = 0; i < XGE_STATS_LEN; i++)
  127. *data++ = *(u64 *)(pdata + gstrings_stats[i].offset);
  128. xge_mac_get_extd_stats(pdata);
  129. for (i = 0; i < XGE_EXTD_STATS_LEN; i++)
  130. *data++ = gstrings_extd_stats[i].value;
  131. }
  132. static int xge_get_link_ksettings(struct net_device *ndev,
  133. struct ethtool_link_ksettings *cmd)
  134. {
  135. struct phy_device *phydev = ndev->phydev;
  136. if (!phydev)
  137. return -ENODEV;
  138. phy_ethtool_ksettings_get(phydev, cmd);
  139. return 0;
  140. }
  141. static int xge_set_link_ksettings(struct net_device *ndev,
  142. const struct ethtool_link_ksettings *cmd)
  143. {
  144. struct phy_device *phydev = ndev->phydev;
  145. if (!phydev)
  146. return -ENODEV;
  147. return phy_ethtool_ksettings_set(phydev, cmd);
  148. }
  149. static const struct ethtool_ops xge_ethtool_ops = {
  150. .get_drvinfo = xge_get_drvinfo,
  151. .get_link = ethtool_op_get_link,
  152. .get_strings = xge_get_strings,
  153. .get_sset_count = xge_get_sset_count,
  154. .get_ethtool_stats = xge_get_ethtool_stats,
  155. .get_link_ksettings = xge_get_link_ksettings,
  156. .set_link_ksettings = xge_set_link_ksettings,
  157. };
  158. void xge_set_ethtool_ops(struct net_device *ndev)
  159. {
  160. ndev->ethtool_ops = &xge_ethtool_ops;
  161. }