fjes_ethtool.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. #define FJES_EP_STATS_LEN 14
  46. #define FJES_STATS_LEN \
  47. (ARRAY_SIZE(fjes_gstrings_stats) + \
  48. ((&((struct fjes_adapter *)netdev_priv(netdev))->hw)->max_epid - 1) * \
  49. FJES_EP_STATS_LEN)
  50. static void fjes_get_ethtool_stats(struct net_device *netdev,
  51. struct ethtool_stats *stats, u64 *data)
  52. {
  53. struct fjes_adapter *adapter = netdev_priv(netdev);
  54. struct fjes_hw *hw = &adapter->hw;
  55. int epidx;
  56. char *p;
  57. int i;
  58. for (i = 0; i < ARRAY_SIZE(fjes_gstrings_stats); i++) {
  59. p = (char *)adapter + fjes_gstrings_stats[i].stat_offset;
  60. data[i] = (fjes_gstrings_stats[i].sizeof_stat == sizeof(u64))
  61. ? *(u64 *)p : *(u32 *)p;
  62. }
  63. for (epidx = 0; epidx < hw->max_epid; epidx++) {
  64. if (epidx == hw->my_epid)
  65. continue;
  66. data[i++] = hw->ep_shm_info[epidx].ep_stats
  67. .com_regist_buf_exec;
  68. data[i++] = hw->ep_shm_info[epidx].ep_stats
  69. .com_unregist_buf_exec;
  70. data[i++] = hw->ep_shm_info[epidx].ep_stats.send_intr_rx;
  71. data[i++] = hw->ep_shm_info[epidx].ep_stats.send_intr_unshare;
  72. data[i++] = hw->ep_shm_info[epidx].ep_stats
  73. .send_intr_zoneupdate;
  74. data[i++] = hw->ep_shm_info[epidx].ep_stats.recv_intr_rx;
  75. data[i++] = hw->ep_shm_info[epidx].ep_stats.recv_intr_unshare;
  76. data[i++] = hw->ep_shm_info[epidx].ep_stats.recv_intr_stop;
  77. data[i++] = hw->ep_shm_info[epidx].ep_stats
  78. .recv_intr_zoneupdate;
  79. data[i++] = hw->ep_shm_info[epidx].ep_stats.tx_buffer_full;
  80. data[i++] = hw->ep_shm_info[epidx].ep_stats
  81. .tx_dropped_not_shared;
  82. data[i++] = hw->ep_shm_info[epidx].ep_stats
  83. .tx_dropped_ver_mismatch;
  84. data[i++] = hw->ep_shm_info[epidx].ep_stats
  85. .tx_dropped_buf_size_mismatch;
  86. data[i++] = hw->ep_shm_info[epidx].ep_stats
  87. .tx_dropped_vlanid_mismatch;
  88. }
  89. }
  90. static void fjes_get_strings(struct net_device *netdev,
  91. u32 stringset, u8 *data)
  92. {
  93. struct fjes_adapter *adapter = netdev_priv(netdev);
  94. struct fjes_hw *hw = &adapter->hw;
  95. u8 *p = data;
  96. int i;
  97. switch (stringset) {
  98. case ETH_SS_STATS:
  99. for (i = 0; i < ARRAY_SIZE(fjes_gstrings_stats); i++) {
  100. memcpy(p, fjes_gstrings_stats[i].stat_string,
  101. ETH_GSTRING_LEN);
  102. p += ETH_GSTRING_LEN;
  103. }
  104. for (i = 0; i < hw->max_epid; i++) {
  105. if (i == hw->my_epid)
  106. continue;
  107. sprintf(p, "ep%u_com_regist_buf_exec", i);
  108. p += ETH_GSTRING_LEN;
  109. sprintf(p, "ep%u_com_unregist_buf_exec", i);
  110. p += ETH_GSTRING_LEN;
  111. sprintf(p, "ep%u_send_intr_rx", i);
  112. p += ETH_GSTRING_LEN;
  113. sprintf(p, "ep%u_send_intr_unshare", i);
  114. p += ETH_GSTRING_LEN;
  115. sprintf(p, "ep%u_send_intr_zoneupdate", i);
  116. p += ETH_GSTRING_LEN;
  117. sprintf(p, "ep%u_recv_intr_rx", i);
  118. p += ETH_GSTRING_LEN;
  119. sprintf(p, "ep%u_recv_intr_unshare", i);
  120. p += ETH_GSTRING_LEN;
  121. sprintf(p, "ep%u_recv_intr_stop", i);
  122. p += ETH_GSTRING_LEN;
  123. sprintf(p, "ep%u_recv_intr_zoneupdate", i);
  124. p += ETH_GSTRING_LEN;
  125. sprintf(p, "ep%u_tx_buffer_full", i);
  126. p += ETH_GSTRING_LEN;
  127. sprintf(p, "ep%u_tx_dropped_not_shared", i);
  128. p += ETH_GSTRING_LEN;
  129. sprintf(p, "ep%u_tx_dropped_ver_mismatch", i);
  130. p += ETH_GSTRING_LEN;
  131. sprintf(p, "ep%u_tx_dropped_buf_size_mismatch", i);
  132. p += ETH_GSTRING_LEN;
  133. sprintf(p, "ep%u_tx_dropped_vlanid_mismatch", i);
  134. p += ETH_GSTRING_LEN;
  135. }
  136. break;
  137. }
  138. }
  139. static int fjes_get_sset_count(struct net_device *netdev, int sset)
  140. {
  141. switch (sset) {
  142. case ETH_SS_STATS:
  143. return FJES_STATS_LEN;
  144. default:
  145. return -EOPNOTSUPP;
  146. }
  147. }
  148. static void fjes_get_drvinfo(struct net_device *netdev,
  149. struct ethtool_drvinfo *drvinfo)
  150. {
  151. struct fjes_adapter *adapter = netdev_priv(netdev);
  152. struct platform_device *plat_dev;
  153. plat_dev = adapter->plat_dev;
  154. strlcpy(drvinfo->driver, fjes_driver_name, sizeof(drvinfo->driver));
  155. strlcpy(drvinfo->version, fjes_driver_version,
  156. sizeof(drvinfo->version));
  157. strlcpy(drvinfo->fw_version, "none", sizeof(drvinfo->fw_version));
  158. snprintf(drvinfo->bus_info, sizeof(drvinfo->bus_info),
  159. "platform:%s", plat_dev->name);
  160. }
  161. static int fjes_get_settings(struct net_device *netdev,
  162. struct ethtool_cmd *ecmd)
  163. {
  164. ecmd->supported = 0;
  165. ecmd->advertising = 0;
  166. ecmd->duplex = DUPLEX_FULL;
  167. ecmd->autoneg = AUTONEG_DISABLE;
  168. ecmd->transceiver = XCVR_DUMMY1;
  169. ecmd->port = PORT_NONE;
  170. ethtool_cmd_speed_set(ecmd, 20000); /* 20Gb/s */
  171. return 0;
  172. }
  173. static int fjes_get_regs_len(struct net_device *netdev)
  174. {
  175. #define FJES_REGS_LEN 37
  176. return FJES_REGS_LEN * sizeof(u32);
  177. }
  178. static void fjes_get_regs(struct net_device *netdev,
  179. struct ethtool_regs *regs, void *p)
  180. {
  181. struct fjes_adapter *adapter = netdev_priv(netdev);
  182. struct fjes_hw *hw = &adapter->hw;
  183. u32 *regs_buff = p;
  184. memset(p, 0, FJES_REGS_LEN * sizeof(u32));
  185. regs->version = 1;
  186. /* Information registers */
  187. regs_buff[0] = rd32(XSCT_OWNER_EPID);
  188. regs_buff[1] = rd32(XSCT_MAX_EP);
  189. /* Device Control registers */
  190. regs_buff[4] = rd32(XSCT_DCTL);
  191. /* Command Control registers */
  192. regs_buff[8] = rd32(XSCT_CR);
  193. regs_buff[9] = rd32(XSCT_CS);
  194. regs_buff[10] = rd32(XSCT_SHSTSAL);
  195. regs_buff[11] = rd32(XSCT_SHSTSAH);
  196. regs_buff[13] = rd32(XSCT_REQBL);
  197. regs_buff[14] = rd32(XSCT_REQBAL);
  198. regs_buff[15] = rd32(XSCT_REQBAH);
  199. regs_buff[17] = rd32(XSCT_RESPBL);
  200. regs_buff[18] = rd32(XSCT_RESPBAL);
  201. regs_buff[19] = rd32(XSCT_RESPBAH);
  202. /* Interrupt Control registers */
  203. regs_buff[32] = rd32(XSCT_IS);
  204. regs_buff[33] = rd32(XSCT_IMS);
  205. regs_buff[34] = rd32(XSCT_IMC);
  206. regs_buff[35] = rd32(XSCT_IG);
  207. regs_buff[36] = rd32(XSCT_ICTL);
  208. }
  209. static int fjes_set_dump(struct net_device *netdev, struct ethtool_dump *dump)
  210. {
  211. struct fjes_adapter *adapter = netdev_priv(netdev);
  212. struct fjes_hw *hw = &adapter->hw;
  213. int ret = 0;
  214. if (dump->flag) {
  215. if (hw->debug_mode)
  216. return -EPERM;
  217. hw->debug_mode = dump->flag;
  218. /* enable debug mode */
  219. mutex_lock(&hw->hw_info.lock);
  220. ret = fjes_hw_start_debug(hw);
  221. mutex_unlock(&hw->hw_info.lock);
  222. if (ret)
  223. hw->debug_mode = 0;
  224. } else {
  225. if (!hw->debug_mode)
  226. return -EPERM;
  227. /* disable debug mode */
  228. mutex_lock(&hw->hw_info.lock);
  229. ret = fjes_hw_stop_debug(hw);
  230. mutex_unlock(&hw->hw_info.lock);
  231. }
  232. return ret;
  233. }
  234. static int fjes_get_dump_flag(struct net_device *netdev,
  235. struct ethtool_dump *dump)
  236. {
  237. struct fjes_adapter *adapter = netdev_priv(netdev);
  238. struct fjes_hw *hw = &adapter->hw;
  239. dump->len = hw->hw_info.trace_size;
  240. dump->version = 1;
  241. dump->flag = hw->debug_mode;
  242. return 0;
  243. }
  244. static int fjes_get_dump_data(struct net_device *netdev,
  245. struct ethtool_dump *dump, void *buf)
  246. {
  247. struct fjes_adapter *adapter = netdev_priv(netdev);
  248. struct fjes_hw *hw = &adapter->hw;
  249. int ret = 0;
  250. if (hw->hw_info.trace)
  251. memcpy(buf, hw->hw_info.trace, hw->hw_info.trace_size);
  252. else
  253. ret = -EPERM;
  254. return ret;
  255. }
  256. static const struct ethtool_ops fjes_ethtool_ops = {
  257. .get_settings = fjes_get_settings,
  258. .get_drvinfo = fjes_get_drvinfo,
  259. .get_ethtool_stats = fjes_get_ethtool_stats,
  260. .get_strings = fjes_get_strings,
  261. .get_sset_count = fjes_get_sset_count,
  262. .get_regs = fjes_get_regs,
  263. .get_regs_len = fjes_get_regs_len,
  264. .set_dump = fjes_set_dump,
  265. .get_dump_flag = fjes_get_dump_flag,
  266. .get_dump_data = fjes_get_dump_data,
  267. };
  268. void fjes_set_ethtool_ops(struct net_device *netdev)
  269. {
  270. netdev->ethtool_ops = &fjes_ethtool_ops;
  271. }