be_ethtool.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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 "be_cmds.h"
  19. #include <linux/ethtool.h>
  20. struct be_ethtool_stat {
  21. char desc[ETH_GSTRING_LEN];
  22. int type;
  23. int size;
  24. int offset;
  25. };
  26. enum {NETSTAT, PORTSTAT, MISCSTAT, DRVSTAT, ERXSTAT};
  27. #define FIELDINFO(_struct, field) FIELD_SIZEOF(_struct, field), \
  28. offsetof(_struct, field)
  29. #define NETSTAT_INFO(field) #field, NETSTAT,\
  30. FIELDINFO(struct net_device_stats,\
  31. field)
  32. #define DRVSTAT_INFO(field) #field, DRVSTAT,\
  33. FIELDINFO(struct be_drvr_stats, field)
  34. #define MISCSTAT_INFO(field) #field, MISCSTAT,\
  35. FIELDINFO(struct be_rxf_stats, field)
  36. #define PORTSTAT_INFO(field) #field, PORTSTAT,\
  37. FIELDINFO(struct be_port_rxf_stats, \
  38. field)
  39. #define ERXSTAT_INFO(field) #field, ERXSTAT,\
  40. FIELDINFO(struct be_erx_stats, field)
  41. static const struct be_ethtool_stat et_stats[] = {
  42. {NETSTAT_INFO(rx_packets)},
  43. {NETSTAT_INFO(tx_packets)},
  44. {NETSTAT_INFO(rx_bytes)},
  45. {NETSTAT_INFO(tx_bytes)},
  46. {NETSTAT_INFO(rx_errors)},
  47. {NETSTAT_INFO(tx_errors)},
  48. {NETSTAT_INFO(rx_dropped)},
  49. {NETSTAT_INFO(tx_dropped)},
  50. {DRVSTAT_INFO(be_tx_reqs)},
  51. {DRVSTAT_INFO(be_tx_stops)},
  52. {DRVSTAT_INFO(be_fwd_reqs)},
  53. {DRVSTAT_INFO(be_tx_wrbs)},
  54. {DRVSTAT_INFO(be_rx_polls)},
  55. {DRVSTAT_INFO(be_tx_events)},
  56. {DRVSTAT_INFO(be_rx_events)},
  57. {DRVSTAT_INFO(be_tx_compl)},
  58. {DRVSTAT_INFO(be_rx_compl)},
  59. {DRVSTAT_INFO(be_ethrx_post_fail)},
  60. {DRVSTAT_INFO(be_802_3_dropped_frames)},
  61. {DRVSTAT_INFO(be_802_3_malformed_frames)},
  62. {DRVSTAT_INFO(be_tx_rate)},
  63. {DRVSTAT_INFO(be_rx_rate)},
  64. {PORTSTAT_INFO(rx_unicast_frames)},
  65. {PORTSTAT_INFO(rx_multicast_frames)},
  66. {PORTSTAT_INFO(rx_broadcast_frames)},
  67. {PORTSTAT_INFO(rx_crc_errors)},
  68. {PORTSTAT_INFO(rx_alignment_symbol_errors)},
  69. {PORTSTAT_INFO(rx_pause_frames)},
  70. {PORTSTAT_INFO(rx_control_frames)},
  71. {PORTSTAT_INFO(rx_in_range_errors)},
  72. {PORTSTAT_INFO(rx_out_range_errors)},
  73. {PORTSTAT_INFO(rx_frame_too_long)},
  74. {PORTSTAT_INFO(rx_address_match_errors)},
  75. {PORTSTAT_INFO(rx_vlan_mismatch)},
  76. {PORTSTAT_INFO(rx_dropped_too_small)},
  77. {PORTSTAT_INFO(rx_dropped_too_short)},
  78. {PORTSTAT_INFO(rx_dropped_header_too_small)},
  79. {PORTSTAT_INFO(rx_dropped_tcp_length)},
  80. {PORTSTAT_INFO(rx_dropped_runt)},
  81. {PORTSTAT_INFO(rx_fifo_overflow)},
  82. {PORTSTAT_INFO(rx_input_fifo_overflow)},
  83. {PORTSTAT_INFO(rx_ip_checksum_errs)},
  84. {PORTSTAT_INFO(rx_tcp_checksum_errs)},
  85. {PORTSTAT_INFO(rx_udp_checksum_errs)},
  86. {PORTSTAT_INFO(rx_non_rss_packets)},
  87. {PORTSTAT_INFO(rx_ipv4_packets)},
  88. {PORTSTAT_INFO(rx_ipv6_packets)},
  89. {PORTSTAT_INFO(tx_unicastframes)},
  90. {PORTSTAT_INFO(tx_multicastframes)},
  91. {PORTSTAT_INFO(tx_broadcastframes)},
  92. {PORTSTAT_INFO(tx_pauseframes)},
  93. {PORTSTAT_INFO(tx_controlframes)},
  94. {MISCSTAT_INFO(rx_drops_no_pbuf)},
  95. {MISCSTAT_INFO(rx_drops_no_txpb)},
  96. {MISCSTAT_INFO(rx_drops_no_erx_descr)},
  97. {MISCSTAT_INFO(rx_drops_no_tpre_descr)},
  98. {MISCSTAT_INFO(rx_drops_too_many_frags)},
  99. {MISCSTAT_INFO(rx_drops_invalid_ring)},
  100. {MISCSTAT_INFO(forwarded_packets)},
  101. {MISCSTAT_INFO(rx_drops_mtu)},
  102. {ERXSTAT_INFO(rx_drops_no_fragments)},
  103. };
  104. #define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)
  105. static void
  106. be_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
  107. {
  108. struct be_adapter *adapter = netdev_priv(netdev);
  109. strcpy(drvinfo->driver, DRV_NAME);
  110. strcpy(drvinfo->version, DRV_VER);
  111. strncpy(drvinfo->fw_version, adapter->fw_ver, FW_VER_LEN);
  112. strcpy(drvinfo->bus_info, pci_name(adapter->pdev));
  113. drvinfo->testinfo_len = 0;
  114. drvinfo->regdump_len = 0;
  115. drvinfo->eedump_len = 0;
  116. }
  117. static int
  118. be_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
  119. {
  120. struct be_adapter *adapter = netdev_priv(netdev);
  121. struct be_eq_obj *rx_eq = &adapter->rx_eq;
  122. struct be_eq_obj *tx_eq = &adapter->tx_eq;
  123. coalesce->rx_coalesce_usecs = rx_eq->cur_eqd;
  124. coalesce->rx_coalesce_usecs_high = rx_eq->max_eqd;
  125. coalesce->rx_coalesce_usecs_low = rx_eq->min_eqd;
  126. coalesce->tx_coalesce_usecs = tx_eq->cur_eqd;
  127. coalesce->tx_coalesce_usecs_high = tx_eq->max_eqd;
  128. coalesce->tx_coalesce_usecs_low = tx_eq->min_eqd;
  129. coalesce->use_adaptive_rx_coalesce = rx_eq->enable_aic;
  130. coalesce->use_adaptive_tx_coalesce = tx_eq->enable_aic;
  131. return 0;
  132. }
  133. /*
  134. * This routine is used to set interrup coalescing delay
  135. */
  136. static int
  137. be_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
  138. {
  139. struct be_adapter *adapter = netdev_priv(netdev);
  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(adapter, 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(adapter, rx_eq->q.id,
  182. rx_cur);
  183. if (!status)
  184. rx_eq->cur_eqd = rx_cur;
  185. }
  186. }
  187. return 0;
  188. }
  189. static u32 be_get_rx_csum(struct net_device *netdev)
  190. {
  191. struct be_adapter *adapter = netdev_priv(netdev);
  192. return adapter->rx_csum;
  193. }
  194. static int be_set_rx_csum(struct net_device *netdev, uint32_t data)
  195. {
  196. struct be_adapter *adapter = netdev_priv(netdev);
  197. if (data)
  198. adapter->rx_csum = true;
  199. else
  200. adapter->rx_csum = false;
  201. return 0;
  202. }
  203. static void
  204. be_get_ethtool_stats(struct net_device *netdev,
  205. struct ethtool_stats *stats, uint64_t *data)
  206. {
  207. struct be_adapter *adapter = netdev_priv(netdev);
  208. struct be_drvr_stats *drvr_stats = &adapter->stats.drvr_stats;
  209. struct be_hw_stats *hw_stats = hw_stats_from_cmd(adapter->stats.cmd.va);
  210. struct be_rxf_stats *rxf_stats = &hw_stats->rxf;
  211. struct be_port_rxf_stats *port_stats =
  212. &rxf_stats->port[adapter->port_num];
  213. struct net_device_stats *net_stats = &netdev->stats;
  214. struct be_erx_stats *erx_stats = &hw_stats->erx;
  215. void *p = NULL;
  216. int i;
  217. for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
  218. switch (et_stats[i].type) {
  219. case NETSTAT:
  220. p = net_stats;
  221. break;
  222. case DRVSTAT:
  223. p = drvr_stats;
  224. break;
  225. case PORTSTAT:
  226. p = port_stats;
  227. break;
  228. case MISCSTAT:
  229. p = rxf_stats;
  230. break;
  231. case ERXSTAT: /* Currently only one ERX stat is provided */
  232. p = (u32 *)erx_stats + adapter->rx_obj.q.id;
  233. break;
  234. }
  235. p = (u8 *)p + et_stats[i].offset;
  236. data[i] = (et_stats[i].size == sizeof(u64)) ?
  237. *(u64 *)p: *(u32 *)p;
  238. }
  239. return;
  240. }
  241. static void
  242. be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
  243. uint8_t *data)
  244. {
  245. int i;
  246. switch (stringset) {
  247. case ETH_SS_STATS:
  248. for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
  249. memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
  250. data += ETH_GSTRING_LEN;
  251. }
  252. break;
  253. }
  254. }
  255. static int be_get_sset_count(struct net_device *netdev, int stringset)
  256. {
  257. switch (stringset) {
  258. case ETH_SS_STATS:
  259. return ETHTOOL_STATS_NUM;
  260. default:
  261. return -EINVAL;
  262. }
  263. }
  264. static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
  265. {
  266. struct be_adapter *adapter = netdev_priv(netdev);
  267. u8 mac_speed = 0, connector = 0;
  268. u16 link_speed = 0;
  269. bool link_up = false;
  270. int status;
  271. if (adapter->link_speed < 0) {
  272. status = be_cmd_link_status_query(adapter, &link_up,
  273. &mac_speed, &link_speed);
  274. /* link_speed is in units of 10 Mbps */
  275. if (link_speed) {
  276. ecmd->speed = link_speed*10;
  277. } else {
  278. switch (mac_speed) {
  279. case PHY_LINK_SPEED_1GBPS:
  280. ecmd->speed = SPEED_1000;
  281. break;
  282. case PHY_LINK_SPEED_10GBPS:
  283. ecmd->speed = SPEED_10000;
  284. break;
  285. }
  286. }
  287. status = be_cmd_read_port_type(adapter, adapter->port_num,
  288. &connector);
  289. switch (connector) {
  290. case 7:
  291. ecmd->port = PORT_FIBRE;
  292. break;
  293. default:
  294. ecmd->port = PORT_TP;
  295. break;
  296. }
  297. /* Save for future use */
  298. adapter->link_speed = ecmd->speed;
  299. adapter->port_type = ecmd->port;
  300. } else {
  301. ecmd->speed = adapter->link_speed;
  302. ecmd->port = adapter->port_type;
  303. }
  304. ecmd->duplex = DUPLEX_FULL;
  305. ecmd->autoneg = AUTONEG_DISABLE;
  306. ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_TP);
  307. ecmd->phy_address = adapter->port_num;
  308. ecmd->transceiver = XCVR_INTERNAL;
  309. return 0;
  310. }
  311. static void
  312. be_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
  313. {
  314. struct be_adapter *adapter = netdev_priv(netdev);
  315. ring->rx_max_pending = adapter->rx_obj.q.len;
  316. ring->tx_max_pending = adapter->tx_obj.q.len;
  317. ring->rx_pending = atomic_read(&adapter->rx_obj.q.used);
  318. ring->tx_pending = atomic_read(&adapter->tx_obj.q.used);
  319. }
  320. static void
  321. be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
  322. {
  323. struct be_adapter *adapter = netdev_priv(netdev);
  324. be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
  325. ecmd->autoneg = 0;
  326. }
  327. static int
  328. be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
  329. {
  330. struct be_adapter *adapter = netdev_priv(netdev);
  331. int status;
  332. if (ecmd->autoneg != 0)
  333. return -EINVAL;
  334. adapter->tx_fc = ecmd->tx_pause;
  335. adapter->rx_fc = ecmd->rx_pause;
  336. status = be_cmd_set_flow_control(adapter,
  337. adapter->tx_fc, adapter->rx_fc);
  338. if (status)
  339. dev_warn(&adapter->pdev->dev, "Pause param set failed.\n");
  340. return status;
  341. }
  342. static int
  343. be_phys_id(struct net_device *netdev, u32 data)
  344. {
  345. struct be_adapter *adapter = netdev_priv(netdev);
  346. int status;
  347. u32 cur;
  348. be_cmd_get_beacon_state(adapter, adapter->port_num, &cur);
  349. if (cur == BEACON_STATE_ENABLED)
  350. return 0;
  351. if (data < 2)
  352. data = 2;
  353. status = be_cmd_set_beacon_state(adapter, adapter->port_num, 0, 0,
  354. BEACON_STATE_ENABLED);
  355. set_current_state(TASK_INTERRUPTIBLE);
  356. schedule_timeout(data*HZ);
  357. status = be_cmd_set_beacon_state(adapter, adapter->port_num, 0, 0,
  358. BEACON_STATE_DISABLED);
  359. return status;
  360. }
  361. static int
  362. be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
  363. {
  364. struct be_adapter *adapter = netdev_priv(netdev);
  365. char file_name[ETHTOOL_FLASH_MAX_FILENAME];
  366. u32 region;
  367. file_name[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
  368. strcpy(file_name, efl->data);
  369. region = efl->region;
  370. return be_load_fw(adapter, file_name);
  371. }
  372. const struct ethtool_ops be_ethtool_ops = {
  373. .get_settings = be_get_settings,
  374. .get_drvinfo = be_get_drvinfo,
  375. .get_link = ethtool_op_get_link,
  376. .get_coalesce = be_get_coalesce,
  377. .set_coalesce = be_set_coalesce,
  378. .get_ringparam = be_get_ringparam,
  379. .get_pauseparam = be_get_pauseparam,
  380. .set_pauseparam = be_set_pauseparam,
  381. .get_rx_csum = be_get_rx_csum,
  382. .set_rx_csum = be_set_rx_csum,
  383. .get_tx_csum = ethtool_op_get_tx_csum,
  384. .set_tx_csum = ethtool_op_set_tx_hw_csum,
  385. .get_sg = ethtool_op_get_sg,
  386. .set_sg = ethtool_op_set_sg,
  387. .get_tso = ethtool_op_get_tso,
  388. .set_tso = ethtool_op_set_tso,
  389. .get_strings = be_get_stat_strings,
  390. .phys_id = be_phys_id,
  391. .get_sset_count = be_get_sset_count,
  392. .get_ethtool_stats = be_get_ethtool_stats,
  393. .flash_device = be_do_flash,
  394. };