fjes_ethtool.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * FUJITSU Extended Socket Network Device driver
  3. * Copyright (c) 2015 FUJITSU LIMITED
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, see <http://www.gnu.org/licenses/>.
  16. *
  17. * The full GNU General Public License is included in this distribution in
  18. * the file called "COPYING".
  19. *
  20. */
  21. /* ethtool support for fjes */
  22. #include <linux/vmalloc.h>
  23. #include <linux/netdevice.h>
  24. #include <linux/ethtool.h>
  25. #include <linux/platform_device.h>
  26. #include "fjes.h"
  27. struct fjes_stats {
  28. char stat_string[ETH_GSTRING_LEN];
  29. int sizeof_stat;
  30. int stat_offset;
  31. };
  32. #define FJES_STAT(name, stat) { \
  33. .stat_string = name, \
  34. .sizeof_stat = FIELD_SIZEOF(struct fjes_adapter, stat), \
  35. .stat_offset = offsetof(struct fjes_adapter, stat) \
  36. }
  37. static const struct fjes_stats fjes_gstrings_stats[] = {
  38. FJES_STAT("rx_packets", stats64.rx_packets),
  39. FJES_STAT("tx_packets", stats64.tx_packets),
  40. FJES_STAT("rx_bytes", stats64.rx_bytes),
  41. FJES_STAT("tx_bytes", stats64.rx_bytes),
  42. FJES_STAT("rx_dropped", stats64.rx_dropped),
  43. FJES_STAT("tx_dropped", stats64.tx_dropped),
  44. };
  45. static void fjes_get_ethtool_stats(struct net_device *netdev,
  46. struct ethtool_stats *stats, u64 *data)
  47. {
  48. struct fjes_adapter *adapter = netdev_priv(netdev);
  49. char *p;
  50. int i;
  51. for (i = 0; i < ARRAY_SIZE(fjes_gstrings_stats); i++) {
  52. p = (char *)adapter + fjes_gstrings_stats[i].stat_offset;
  53. data[i] = (fjes_gstrings_stats[i].sizeof_stat == sizeof(u64))
  54. ? *(u64 *)p : *(u32 *)p;
  55. }
  56. }
  57. static void fjes_get_strings(struct net_device *netdev,
  58. u32 stringset, u8 *data)
  59. {
  60. u8 *p = data;
  61. int i;
  62. switch (stringset) {
  63. case ETH_SS_STATS:
  64. for (i = 0; i < ARRAY_SIZE(fjes_gstrings_stats); i++) {
  65. memcpy(p, fjes_gstrings_stats[i].stat_string,
  66. ETH_GSTRING_LEN);
  67. p += ETH_GSTRING_LEN;
  68. }
  69. break;
  70. }
  71. }
  72. static int fjes_get_sset_count(struct net_device *netdev, int sset)
  73. {
  74. switch (sset) {
  75. case ETH_SS_STATS:
  76. return ARRAY_SIZE(fjes_gstrings_stats);
  77. default:
  78. return -EOPNOTSUPP;
  79. }
  80. }
  81. static void fjes_get_drvinfo(struct net_device *netdev,
  82. struct ethtool_drvinfo *drvinfo)
  83. {
  84. struct fjes_adapter *adapter = netdev_priv(netdev);
  85. struct platform_device *plat_dev;
  86. plat_dev = adapter->plat_dev;
  87. strlcpy(drvinfo->driver, fjes_driver_name, sizeof(drvinfo->driver));
  88. strlcpy(drvinfo->version, fjes_driver_version,
  89. sizeof(drvinfo->version));
  90. strlcpy(drvinfo->fw_version, "none", sizeof(drvinfo->fw_version));
  91. snprintf(drvinfo->bus_info, sizeof(drvinfo->bus_info),
  92. "platform:%s", plat_dev->name);
  93. }
  94. static int fjes_get_settings(struct net_device *netdev,
  95. struct ethtool_cmd *ecmd)
  96. {
  97. ecmd->supported = 0;
  98. ecmd->advertising = 0;
  99. ecmd->duplex = DUPLEX_FULL;
  100. ecmd->autoneg = AUTONEG_DISABLE;
  101. ecmd->transceiver = XCVR_DUMMY1;
  102. ecmd->port = PORT_NONE;
  103. ethtool_cmd_speed_set(ecmd, 20000); /* 20Gb/s */
  104. return 0;
  105. }
  106. static const struct ethtool_ops fjes_ethtool_ops = {
  107. .get_settings = fjes_get_settings,
  108. .get_drvinfo = fjes_get_drvinfo,
  109. .get_ethtool_stats = fjes_get_ethtool_stats,
  110. .get_strings = fjes_get_strings,
  111. .get_sset_count = fjes_get_sset_count,
  112. };
  113. void fjes_set_ethtool_ops(struct net_device *netdev)
  114. {
  115. netdev->ethtool_ops = &fjes_ethtool_ops;
  116. }