be_ethtool.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. /*
  2. * Copyright (C) 2005 - 2009 ServerEngines
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License version 2
  7. * as published by the Free Software Foundation. The full GNU General
  8. * Public License is included in this distribution in the file called COPYING.
  9. *
  10. * Contact Information:
  11. * linux-drivers@serverengines.com
  12. *
  13. * ServerEngines
  14. * 209 N. Fair Oaks Ave
  15. * Sunnyvale, CA 94085
  16. */
  17. #include "be.h"
  18. #include <linux/ethtool.h>
  19. struct be_ethtool_stat {
  20. char desc[ETH_GSTRING_LEN];
  21. int type;
  22. int size;
  23. int offset;
  24. };
  25. enum {NETSTAT, PORTSTAT, MISCSTAT, DRVSTAT, ERXSTAT};
  26. #define FIELDINFO(_struct, field) FIELD_SIZEOF(_struct, field), \
  27. offsetof(_struct, field)
  28. #define NETSTAT_INFO(field) #field, NETSTAT,\
  29. FIELDINFO(struct net_device_stats,\
  30. field)
  31. #define DRVSTAT_INFO(field) #field, DRVSTAT,\
  32. FIELDINFO(struct be_drvr_stats, field)
  33. #define MISCSTAT_INFO(field) #field, MISCSTAT,\
  34. FIELDINFO(struct be_rxf_stats, field)
  35. #define PORTSTAT_INFO(field) #field, PORTSTAT,\
  36. FIELDINFO(struct be_port_rxf_stats, \
  37. field)
  38. #define ERXSTAT_INFO(field) #field, ERXSTAT,\
  39. FIELDINFO(struct be_erx_stats, field)
  40. static const struct be_ethtool_stat et_stats[] = {
  41. {NETSTAT_INFO(rx_packets)},
  42. {NETSTAT_INFO(tx_packets)},
  43. {NETSTAT_INFO(rx_bytes)},
  44. {NETSTAT_INFO(tx_bytes)},
  45. {NETSTAT_INFO(rx_errors)},
  46. {NETSTAT_INFO(tx_errors)},
  47. {NETSTAT_INFO(rx_dropped)},
  48. {NETSTAT_INFO(tx_dropped)},
  49. {DRVSTAT_INFO(be_tx_reqs)},
  50. {DRVSTAT_INFO(be_tx_stops)},
  51. {DRVSTAT_INFO(be_fwd_reqs)},
  52. {DRVSTAT_INFO(be_tx_wrbs)},
  53. {DRVSTAT_INFO(be_polls)},
  54. {DRVSTAT_INFO(be_tx_events)},
  55. {DRVSTAT_INFO(be_rx_events)},
  56. {DRVSTAT_INFO(be_tx_compl)},
  57. {DRVSTAT_INFO(be_rx_compl)},
  58. {DRVSTAT_INFO(be_ethrx_post_fail)},
  59. {DRVSTAT_INFO(be_802_3_dropped_frames)},
  60. {DRVSTAT_INFO(be_802_3_malformed_frames)},
  61. {DRVSTAT_INFO(be_tx_rate)},
  62. {DRVSTAT_INFO(be_rx_rate)},
  63. {PORTSTAT_INFO(rx_unicast_frames)},
  64. {PORTSTAT_INFO(rx_multicast_frames)},
  65. {PORTSTAT_INFO(rx_broadcast_frames)},
  66. {PORTSTAT_INFO(rx_crc_errors)},
  67. {PORTSTAT_INFO(rx_alignment_symbol_errors)},
  68. {PORTSTAT_INFO(rx_pause_frames)},
  69. {PORTSTAT_INFO(rx_control_frames)},
  70. {PORTSTAT_INFO(rx_in_range_errors)},
  71. {PORTSTAT_INFO(rx_out_range_errors)},
  72. {PORTSTAT_INFO(rx_frame_too_long)},
  73. {PORTSTAT_INFO(rx_address_match_errors)},
  74. {PORTSTAT_INFO(rx_vlan_mismatch)},
  75. {PORTSTAT_INFO(rx_dropped_too_small)},
  76. {PORTSTAT_INFO(rx_dropped_too_short)},
  77. {PORTSTAT_INFO(rx_dropped_header_too_small)},
  78. {PORTSTAT_INFO(rx_dropped_tcp_length)},
  79. {PORTSTAT_INFO(rx_dropped_runt)},
  80. {PORTSTAT_INFO(rx_fifo_overflow)},
  81. {PORTSTAT_INFO(rx_input_fifo_overflow)},
  82. {PORTSTAT_INFO(rx_ip_checksum_errs)},
  83. {PORTSTAT_INFO(rx_tcp_checksum_errs)},
  84. {PORTSTAT_INFO(rx_udp_checksum_errs)},
  85. {PORTSTAT_INFO(rx_non_rss_packets)},
  86. {PORTSTAT_INFO(rx_ipv4_packets)},
  87. {PORTSTAT_INFO(rx_ipv6_packets)},
  88. {PORTSTAT_INFO(tx_unicastframes)},
  89. {PORTSTAT_INFO(tx_multicastframes)},
  90. {PORTSTAT_INFO(tx_broadcastframes)},
  91. {PORTSTAT_INFO(tx_pauseframes)},
  92. {PORTSTAT_INFO(tx_controlframes)},
  93. {MISCSTAT_INFO(rx_drops_no_pbuf)},
  94. {MISCSTAT_INFO(rx_drops_no_txpb)},
  95. {MISCSTAT_INFO(rx_drops_no_erx_descr)},
  96. {MISCSTAT_INFO(rx_drops_no_tpre_descr)},
  97. {MISCSTAT_INFO(rx_drops_too_many_frags)},
  98. {MISCSTAT_INFO(rx_drops_invalid_ring)},
  99. {MISCSTAT_INFO(forwarded_packets)},
  100. {MISCSTAT_INFO(rx_drops_mtu)},
  101. {ERXSTAT_INFO(rx_drops_no_fragments)},
  102. };
  103. #define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)
  104. static void
  105. be_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
  106. {
  107. struct be_adapter *adapter = netdev_priv(netdev);
  108. strcpy(drvinfo->driver, DRV_NAME);
  109. strcpy(drvinfo->version, DRV_VER);
  110. strncpy(drvinfo->fw_version, adapter->fw_ver, FW_VER_LEN);
  111. strcpy(drvinfo->bus_info, pci_name(adapter->pdev));
  112. drvinfo->testinfo_len = 0;
  113. drvinfo->regdump_len = 0;
  114. drvinfo->eedump_len = 0;
  115. }
  116. static int
  117. be_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
  118. {
  119. struct be_adapter *adapter = netdev_priv(netdev);
  120. struct be_eq_obj *rx_eq = &adapter->rx_eq;
  121. struct be_eq_obj *tx_eq = &adapter->tx_eq;
  122. coalesce->rx_coalesce_usecs = rx_eq->cur_eqd;
  123. coalesce->rx_coalesce_usecs_high = rx_eq->max_eqd;
  124. coalesce->rx_coalesce_usecs_low = rx_eq->min_eqd;
  125. coalesce->tx_coalesce_usecs = tx_eq->cur_eqd;
  126. coalesce->tx_coalesce_usecs_high = tx_eq->max_eqd;
  127. coalesce->tx_coalesce_usecs_low = tx_eq->min_eqd;
  128. coalesce->use_adaptive_rx_coalesce = rx_eq->enable_aic;
  129. coalesce->use_adaptive_tx_coalesce = tx_eq->enable_aic;
  130. return 0;
  131. }
  132. /*
  133. * This routine is used to set interrup coalescing delay
  134. */
  135. static int
  136. be_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
  137. {
  138. struct be_adapter *adapter = netdev_priv(netdev);
  139. struct be_ctrl_info *ctrl = &adapter->ctrl;
  140. struct be_eq_obj *rx_eq = &adapter->rx_eq;
  141. struct be_eq_obj *tx_eq = &adapter->tx_eq;
  142. u32 tx_max, tx_min, tx_cur;
  143. u32 rx_max, rx_min, rx_cur;
  144. int status = 0;
  145. if (coalesce->use_adaptive_tx_coalesce == 1)
  146. return -EINVAL;
  147. /* if AIC is being turned on now, start with an EQD of 0 */
  148. if (rx_eq->enable_aic == 0 &&
  149. coalesce->use_adaptive_rx_coalesce == 1) {
  150. rx_eq->cur_eqd = 0;
  151. }
  152. rx_eq->enable_aic = coalesce->use_adaptive_rx_coalesce;
  153. rx_max = coalesce->rx_coalesce_usecs_high;
  154. rx_min = coalesce->rx_coalesce_usecs_low;
  155. rx_cur = coalesce->rx_coalesce_usecs;
  156. tx_max = coalesce->tx_coalesce_usecs_high;
  157. tx_min = coalesce->tx_coalesce_usecs_low;
  158. tx_cur = coalesce->tx_coalesce_usecs;
  159. if (tx_cur > BE_MAX_EQD)
  160. tx_cur = BE_MAX_EQD;
  161. if (tx_eq->cur_eqd != tx_cur) {
  162. status = be_cmd_modify_eqd(ctrl, tx_eq->q.id, tx_cur);
  163. if (!status)
  164. tx_eq->cur_eqd = tx_cur;
  165. }
  166. if (rx_eq->enable_aic) {
  167. if (rx_max > BE_MAX_EQD)
  168. rx_max = BE_MAX_EQD;
  169. if (rx_min > rx_max)
  170. rx_min = rx_max;
  171. rx_eq->max_eqd = rx_max;
  172. rx_eq->min_eqd = rx_min;
  173. if (rx_eq->cur_eqd > rx_max)
  174. rx_eq->cur_eqd = rx_max;
  175. if (rx_eq->cur_eqd < rx_min)
  176. rx_eq->cur_eqd = rx_min;
  177. } else {
  178. if (rx_cur > BE_MAX_EQD)
  179. rx_cur = BE_MAX_EQD;
  180. if (rx_eq->cur_eqd != rx_cur) {
  181. status = be_cmd_modify_eqd(ctrl, rx_eq->q.id, rx_cur);
  182. if (!status)
  183. rx_eq->cur_eqd = rx_cur;
  184. }
  185. }
  186. return 0;
  187. }
  188. static u32 be_get_rx_csum(struct net_device *netdev)
  189. {
  190. struct be_adapter *adapter = netdev_priv(netdev);
  191. return adapter->rx_csum;
  192. }
  193. static int be_set_rx_csum(struct net_device *netdev, uint32_t data)
  194. {
  195. struct be_adapter *adapter = netdev_priv(netdev);
  196. if (data)
  197. adapter->rx_csum = true;
  198. else
  199. adapter->rx_csum = false;
  200. return 0;
  201. }
  202. static void
  203. be_get_ethtool_stats(struct net_device *netdev,
  204. struct ethtool_stats *stats, uint64_t *data)
  205. {
  206. struct be_adapter *adapter = netdev_priv(netdev);
  207. struct be_drvr_stats *drvr_stats = &adapter->stats.drvr_stats;
  208. struct be_hw_stats *hw_stats = hw_stats_from_cmd(adapter->stats.cmd.va);
  209. struct be_rxf_stats *rxf_stats = &hw_stats->rxf;
  210. struct be_port_rxf_stats *port_stats =
  211. &rxf_stats->port[adapter->port_num];
  212. struct net_device_stats *net_stats = &adapter->stats.net_stats;
  213. struct be_erx_stats *erx_stats = &hw_stats->erx;
  214. void *p = NULL;
  215. int i;
  216. for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
  217. switch (et_stats[i].type) {
  218. case NETSTAT:
  219. p = net_stats;
  220. break;
  221. case DRVSTAT:
  222. p = drvr_stats;
  223. break;
  224. case PORTSTAT:
  225. p = port_stats;
  226. break;
  227. case MISCSTAT:
  228. p = rxf_stats;
  229. break;
  230. case ERXSTAT: /* Currently only one ERX stat is provided */
  231. p = (u32 *)erx_stats + adapter->rx_obj.q.id;
  232. break;
  233. }
  234. p = (u8 *)p + et_stats[i].offset;
  235. data[i] = (et_stats[i].size == sizeof(u64)) ?
  236. *(u64 *)p: *(u32 *)p;
  237. }
  238. return;
  239. }
  240. static void
  241. be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
  242. uint8_t *data)
  243. {
  244. int i;
  245. switch (stringset) {
  246. case ETH_SS_STATS:
  247. for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
  248. memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
  249. data += ETH_GSTRING_LEN;
  250. }
  251. break;
  252. }
  253. }
  254. static int be_get_stats_count(struct net_device *netdev)
  255. {
  256. return ETHTOOL_STATS_NUM;
  257. }
  258. static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
  259. {
  260. ecmd->speed = SPEED_10000;
  261. ecmd->duplex = DUPLEX_FULL;
  262. ecmd->autoneg = AUTONEG_DISABLE;
  263. return 0;
  264. }
  265. static void
  266. be_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
  267. {
  268. struct be_adapter *adapter = netdev_priv(netdev);
  269. ring->rx_max_pending = adapter->rx_obj.q.len;
  270. ring->tx_max_pending = adapter->tx_obj.q.len;
  271. ring->rx_pending = atomic_read(&adapter->rx_obj.q.used);
  272. ring->tx_pending = atomic_read(&adapter->tx_obj.q.used);
  273. }
  274. static void
  275. be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
  276. {
  277. struct be_adapter *adapter = netdev_priv(netdev);
  278. be_cmd_get_flow_control(&adapter->ctrl, &ecmd->tx_pause,
  279. &ecmd->rx_pause);
  280. ecmd->autoneg = 0;
  281. }
  282. static int
  283. be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
  284. {
  285. struct be_adapter *adapter = netdev_priv(netdev);
  286. int status;
  287. if (ecmd->autoneg != 0)
  288. return -EINVAL;
  289. status = be_cmd_set_flow_control(&adapter->ctrl, ecmd->tx_pause,
  290. ecmd->rx_pause);
  291. if (!status)
  292. dev_warn(&adapter->pdev->dev, "Pause param set failed.\n");
  293. return status;
  294. }
  295. struct ethtool_ops be_ethtool_ops = {
  296. .get_settings = be_get_settings,
  297. .get_drvinfo = be_get_drvinfo,
  298. .get_link = ethtool_op_get_link,
  299. .get_coalesce = be_get_coalesce,
  300. .set_coalesce = be_set_coalesce,
  301. .get_ringparam = be_get_ringparam,
  302. .get_pauseparam = be_get_pauseparam,
  303. .set_pauseparam = be_set_pauseparam,
  304. .get_rx_csum = be_get_rx_csum,
  305. .set_rx_csum = be_set_rx_csum,
  306. .get_tx_csum = ethtool_op_get_tx_csum,
  307. .set_tx_csum = ethtool_op_set_tx_csum,
  308. .get_sg = ethtool_op_get_sg,
  309. .set_sg = ethtool_op_set_sg,
  310. .get_tso = ethtool_op_get_tso,
  311. .set_tso = ethtool_op_set_tso,
  312. .get_strings = be_get_stat_strings,
  313. .get_stats_count = be_get_stats_count,
  314. .get_ethtool_stats = be_get_ethtool_stats,
  315. };