ethtool.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. /*******************************************************************************
  2. Intel(R) 82576 Virtual Function Linux driver
  3. Copyright(c) 2009 - 2012 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, see <http://www.gnu.org/licenses/>.
  13. The full GNU General Public License is included in this distribution in
  14. the file called "COPYING".
  15. Contact Information:
  16. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  17. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  18. *******************************************************************************/
  19. /* ethtool support for igbvf */
  20. #include <linux/netdevice.h>
  21. #include <linux/ethtool.h>
  22. #include <linux/pci.h>
  23. #include <linux/vmalloc.h>
  24. #include <linux/delay.h>
  25. #include "igbvf.h"
  26. #include <linux/if_vlan.h>
  27. struct igbvf_stats {
  28. char stat_string[ETH_GSTRING_LEN];
  29. int sizeof_stat;
  30. int stat_offset;
  31. int base_stat_offset;
  32. };
  33. #define IGBVF_STAT(current, base) \
  34. sizeof(((struct igbvf_adapter *)0)->current), \
  35. offsetof(struct igbvf_adapter, current), \
  36. offsetof(struct igbvf_adapter, base)
  37. static const struct igbvf_stats igbvf_gstrings_stats[] = {
  38. { "rx_packets", IGBVF_STAT(stats.gprc, stats.base_gprc) },
  39. { "tx_packets", IGBVF_STAT(stats.gptc, stats.base_gptc) },
  40. { "rx_bytes", IGBVF_STAT(stats.gorc, stats.base_gorc) },
  41. { "tx_bytes", IGBVF_STAT(stats.gotc, stats.base_gotc) },
  42. { "multicast", IGBVF_STAT(stats.mprc, stats.base_mprc) },
  43. { "lbrx_bytes", IGBVF_STAT(stats.gorlbc, stats.base_gorlbc) },
  44. { "lbrx_packets", IGBVF_STAT(stats.gprlbc, stats.base_gprlbc) },
  45. { "tx_restart_queue", IGBVF_STAT(restart_queue, zero_base) },
  46. { "rx_long_byte_count", IGBVF_STAT(stats.gorc, stats.base_gorc) },
  47. { "rx_csum_offload_good", IGBVF_STAT(hw_csum_good, zero_base) },
  48. { "rx_csum_offload_errors", IGBVF_STAT(hw_csum_err, zero_base) },
  49. { "rx_header_split", IGBVF_STAT(rx_hdr_split, zero_base) },
  50. { "alloc_rx_buff_failed", IGBVF_STAT(alloc_rx_buff_failed, zero_base) },
  51. };
  52. #define IGBVF_GLOBAL_STATS_LEN ARRAY_SIZE(igbvf_gstrings_stats)
  53. static const char igbvf_gstrings_test[][ETH_GSTRING_LEN] = {
  54. "Link test (on/offline)"
  55. };
  56. #define IGBVF_TEST_LEN ARRAY_SIZE(igbvf_gstrings_test)
  57. static int igbvf_get_settings(struct net_device *netdev,
  58. struct ethtool_cmd *ecmd)
  59. {
  60. struct igbvf_adapter *adapter = netdev_priv(netdev);
  61. struct e1000_hw *hw = &adapter->hw;
  62. u32 status;
  63. ecmd->supported = SUPPORTED_1000baseT_Full;
  64. ecmd->advertising = ADVERTISED_1000baseT_Full;
  65. ecmd->port = -1;
  66. ecmd->transceiver = XCVR_DUMMY1;
  67. status = er32(STATUS);
  68. if (status & E1000_STATUS_LU) {
  69. if (status & E1000_STATUS_SPEED_1000)
  70. ethtool_cmd_speed_set(ecmd, SPEED_1000);
  71. else if (status & E1000_STATUS_SPEED_100)
  72. ethtool_cmd_speed_set(ecmd, SPEED_100);
  73. else
  74. ethtool_cmd_speed_set(ecmd, SPEED_10);
  75. if (status & E1000_STATUS_FD)
  76. ecmd->duplex = DUPLEX_FULL;
  77. else
  78. ecmd->duplex = DUPLEX_HALF;
  79. } else {
  80. ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
  81. ecmd->duplex = DUPLEX_UNKNOWN;
  82. }
  83. ecmd->autoneg = AUTONEG_DISABLE;
  84. return 0;
  85. }
  86. static int igbvf_set_settings(struct net_device *netdev,
  87. struct ethtool_cmd *ecmd)
  88. {
  89. return -EOPNOTSUPP;
  90. }
  91. static void igbvf_get_pauseparam(struct net_device *netdev,
  92. struct ethtool_pauseparam *pause)
  93. {
  94. }
  95. static int igbvf_set_pauseparam(struct net_device *netdev,
  96. struct ethtool_pauseparam *pause)
  97. {
  98. return -EOPNOTSUPP;
  99. }
  100. static u32 igbvf_get_msglevel(struct net_device *netdev)
  101. {
  102. struct igbvf_adapter *adapter = netdev_priv(netdev);
  103. return adapter->msg_enable;
  104. }
  105. static void igbvf_set_msglevel(struct net_device *netdev, u32 data)
  106. {
  107. struct igbvf_adapter *adapter = netdev_priv(netdev);
  108. adapter->msg_enable = data;
  109. }
  110. static int igbvf_get_regs_len(struct net_device *netdev)
  111. {
  112. #define IGBVF_REGS_LEN 8
  113. return IGBVF_REGS_LEN * sizeof(u32);
  114. }
  115. static void igbvf_get_regs(struct net_device *netdev,
  116. struct ethtool_regs *regs, void *p)
  117. {
  118. struct igbvf_adapter *adapter = netdev_priv(netdev);
  119. struct e1000_hw *hw = &adapter->hw;
  120. u32 *regs_buff = p;
  121. memset(p, 0, IGBVF_REGS_LEN * sizeof(u32));
  122. regs->version = (1u << 24) |
  123. (adapter->pdev->revision << 16) |
  124. adapter->pdev->device;
  125. regs_buff[0] = er32(CTRL);
  126. regs_buff[1] = er32(STATUS);
  127. regs_buff[2] = er32(RDLEN(0));
  128. regs_buff[3] = er32(RDH(0));
  129. regs_buff[4] = er32(RDT(0));
  130. regs_buff[5] = er32(TDLEN(0));
  131. regs_buff[6] = er32(TDH(0));
  132. regs_buff[7] = er32(TDT(0));
  133. }
  134. static int igbvf_get_eeprom_len(struct net_device *netdev)
  135. {
  136. return 0;
  137. }
  138. static int igbvf_get_eeprom(struct net_device *netdev,
  139. struct ethtool_eeprom *eeprom, u8 *bytes)
  140. {
  141. return -EOPNOTSUPP;
  142. }
  143. static int igbvf_set_eeprom(struct net_device *netdev,
  144. struct ethtool_eeprom *eeprom, u8 *bytes)
  145. {
  146. return -EOPNOTSUPP;
  147. }
  148. static void igbvf_get_drvinfo(struct net_device *netdev,
  149. struct ethtool_drvinfo *drvinfo)
  150. {
  151. struct igbvf_adapter *adapter = netdev_priv(netdev);
  152. strlcpy(drvinfo->driver, igbvf_driver_name, sizeof(drvinfo->driver));
  153. strlcpy(drvinfo->version, igbvf_driver_version,
  154. sizeof(drvinfo->version));
  155. strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
  156. sizeof(drvinfo->bus_info));
  157. }
  158. static void igbvf_get_ringparam(struct net_device *netdev,
  159. struct ethtool_ringparam *ring)
  160. {
  161. struct igbvf_adapter *adapter = netdev_priv(netdev);
  162. struct igbvf_ring *tx_ring = adapter->tx_ring;
  163. struct igbvf_ring *rx_ring = adapter->rx_ring;
  164. ring->rx_max_pending = IGBVF_MAX_RXD;
  165. ring->tx_max_pending = IGBVF_MAX_TXD;
  166. ring->rx_pending = rx_ring->count;
  167. ring->tx_pending = tx_ring->count;
  168. }
  169. static int igbvf_set_ringparam(struct net_device *netdev,
  170. struct ethtool_ringparam *ring)
  171. {
  172. struct igbvf_adapter *adapter = netdev_priv(netdev);
  173. struct igbvf_ring *temp_ring;
  174. int err = 0;
  175. u32 new_rx_count, new_tx_count;
  176. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  177. return -EINVAL;
  178. new_rx_count = max_t(u32, ring->rx_pending, IGBVF_MIN_RXD);
  179. new_rx_count = min_t(u32, new_rx_count, IGBVF_MAX_RXD);
  180. new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE);
  181. new_tx_count = max_t(u32, ring->tx_pending, IGBVF_MIN_TXD);
  182. new_tx_count = min_t(u32, new_tx_count, IGBVF_MAX_TXD);
  183. new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE);
  184. if ((new_tx_count == adapter->tx_ring->count) &&
  185. (new_rx_count == adapter->rx_ring->count)) {
  186. /* nothing to do */
  187. return 0;
  188. }
  189. while (test_and_set_bit(__IGBVF_RESETTING, &adapter->state))
  190. usleep_range(1000, 2000);
  191. if (!netif_running(adapter->netdev)) {
  192. adapter->tx_ring->count = new_tx_count;
  193. adapter->rx_ring->count = new_rx_count;
  194. goto clear_reset;
  195. }
  196. temp_ring = vmalloc(sizeof(struct igbvf_ring));
  197. if (!temp_ring) {
  198. err = -ENOMEM;
  199. goto clear_reset;
  200. }
  201. igbvf_down(adapter);
  202. /* We can't just free everything and then setup again,
  203. * because the ISRs in MSI-X mode get passed pointers
  204. * to the Tx and Rx ring structs.
  205. */
  206. if (new_tx_count != adapter->tx_ring->count) {
  207. memcpy(temp_ring, adapter->tx_ring, sizeof(struct igbvf_ring));
  208. temp_ring->count = new_tx_count;
  209. err = igbvf_setup_tx_resources(adapter, temp_ring);
  210. if (err)
  211. goto err_setup;
  212. igbvf_free_tx_resources(adapter->tx_ring);
  213. memcpy(adapter->tx_ring, temp_ring, sizeof(struct igbvf_ring));
  214. }
  215. if (new_rx_count != adapter->rx_ring->count) {
  216. memcpy(temp_ring, adapter->rx_ring, sizeof(struct igbvf_ring));
  217. temp_ring->count = new_rx_count;
  218. err = igbvf_setup_rx_resources(adapter, temp_ring);
  219. if (err)
  220. goto err_setup;
  221. igbvf_free_rx_resources(adapter->rx_ring);
  222. memcpy(adapter->rx_ring, temp_ring, sizeof(struct igbvf_ring));
  223. }
  224. err_setup:
  225. igbvf_up(adapter);
  226. vfree(temp_ring);
  227. clear_reset:
  228. clear_bit(__IGBVF_RESETTING, &adapter->state);
  229. return err;
  230. }
  231. static int igbvf_link_test(struct igbvf_adapter *adapter, u64 *data)
  232. {
  233. struct e1000_hw *hw = &adapter->hw;
  234. *data = 0;
  235. hw->mac.ops.check_for_link(hw);
  236. if (!(er32(STATUS) & E1000_STATUS_LU))
  237. *data = 1;
  238. return *data;
  239. }
  240. static void igbvf_diag_test(struct net_device *netdev,
  241. struct ethtool_test *eth_test, u64 *data)
  242. {
  243. struct igbvf_adapter *adapter = netdev_priv(netdev);
  244. set_bit(__IGBVF_TESTING, &adapter->state);
  245. /* Link test performed before hardware reset so autoneg doesn't
  246. * interfere with test result
  247. */
  248. if (igbvf_link_test(adapter, &data[0]))
  249. eth_test->flags |= ETH_TEST_FL_FAILED;
  250. clear_bit(__IGBVF_TESTING, &adapter->state);
  251. msleep_interruptible(4 * 1000);
  252. }
  253. static void igbvf_get_wol(struct net_device *netdev,
  254. struct ethtool_wolinfo *wol)
  255. {
  256. wol->supported = 0;
  257. wol->wolopts = 0;
  258. }
  259. static int igbvf_set_wol(struct net_device *netdev,
  260. struct ethtool_wolinfo *wol)
  261. {
  262. return -EOPNOTSUPP;
  263. }
  264. static int igbvf_get_coalesce(struct net_device *netdev,
  265. struct ethtool_coalesce *ec)
  266. {
  267. struct igbvf_adapter *adapter = netdev_priv(netdev);
  268. if (adapter->requested_itr <= 3)
  269. ec->rx_coalesce_usecs = adapter->requested_itr;
  270. else
  271. ec->rx_coalesce_usecs = adapter->current_itr >> 2;
  272. return 0;
  273. }
  274. static int igbvf_set_coalesce(struct net_device *netdev,
  275. struct ethtool_coalesce *ec)
  276. {
  277. struct igbvf_adapter *adapter = netdev_priv(netdev);
  278. struct e1000_hw *hw = &adapter->hw;
  279. if ((ec->rx_coalesce_usecs >= IGBVF_MIN_ITR_USECS) &&
  280. (ec->rx_coalesce_usecs <= IGBVF_MAX_ITR_USECS)) {
  281. adapter->current_itr = ec->rx_coalesce_usecs << 2;
  282. adapter->requested_itr = 1000000000 /
  283. (adapter->current_itr * 256);
  284. } else if ((ec->rx_coalesce_usecs == 3) ||
  285. (ec->rx_coalesce_usecs == 2)) {
  286. adapter->current_itr = IGBVF_START_ITR;
  287. adapter->requested_itr = ec->rx_coalesce_usecs;
  288. } else if (ec->rx_coalesce_usecs == 0) {
  289. /* The user's desire is to turn off interrupt throttling
  290. * altogether, but due to HW limitations, we can't do that.
  291. * Instead we set a very small value in EITR, which would
  292. * allow ~967k interrupts per second, but allow the adapter's
  293. * internal clocking to still function properly.
  294. */
  295. adapter->current_itr = 4;
  296. adapter->requested_itr = 1000000000 /
  297. (adapter->current_itr * 256);
  298. } else {
  299. return -EINVAL;
  300. }
  301. writel(adapter->current_itr,
  302. hw->hw_addr + adapter->rx_ring->itr_register);
  303. return 0;
  304. }
  305. static int igbvf_nway_reset(struct net_device *netdev)
  306. {
  307. struct igbvf_adapter *adapter = netdev_priv(netdev);
  308. if (netif_running(netdev))
  309. igbvf_reinit_locked(adapter);
  310. return 0;
  311. }
  312. static void igbvf_get_ethtool_stats(struct net_device *netdev,
  313. struct ethtool_stats *stats,
  314. u64 *data)
  315. {
  316. struct igbvf_adapter *adapter = netdev_priv(netdev);
  317. int i;
  318. igbvf_update_stats(adapter);
  319. for (i = 0; i < IGBVF_GLOBAL_STATS_LEN; i++) {
  320. char *p = (char *)adapter +
  321. igbvf_gstrings_stats[i].stat_offset;
  322. char *b = (char *)adapter +
  323. igbvf_gstrings_stats[i].base_stat_offset;
  324. data[i] = ((igbvf_gstrings_stats[i].sizeof_stat ==
  325. sizeof(u64)) ? (*(u64 *)p - *(u64 *)b) :
  326. (*(u32 *)p - *(u32 *)b));
  327. }
  328. }
  329. static int igbvf_get_sset_count(struct net_device *dev, int stringset)
  330. {
  331. switch (stringset) {
  332. case ETH_SS_TEST:
  333. return IGBVF_TEST_LEN;
  334. case ETH_SS_STATS:
  335. return IGBVF_GLOBAL_STATS_LEN;
  336. default:
  337. return -EINVAL;
  338. }
  339. }
  340. static void igbvf_get_strings(struct net_device *netdev, u32 stringset,
  341. u8 *data)
  342. {
  343. u8 *p = data;
  344. int i;
  345. switch (stringset) {
  346. case ETH_SS_TEST:
  347. memcpy(data, *igbvf_gstrings_test, sizeof(igbvf_gstrings_test));
  348. break;
  349. case ETH_SS_STATS:
  350. for (i = 0; i < IGBVF_GLOBAL_STATS_LEN; i++) {
  351. memcpy(p, igbvf_gstrings_stats[i].stat_string,
  352. ETH_GSTRING_LEN);
  353. p += ETH_GSTRING_LEN;
  354. }
  355. break;
  356. }
  357. }
  358. static const struct ethtool_ops igbvf_ethtool_ops = {
  359. .get_settings = igbvf_get_settings,
  360. .set_settings = igbvf_set_settings,
  361. .get_drvinfo = igbvf_get_drvinfo,
  362. .get_regs_len = igbvf_get_regs_len,
  363. .get_regs = igbvf_get_regs,
  364. .get_wol = igbvf_get_wol,
  365. .set_wol = igbvf_set_wol,
  366. .get_msglevel = igbvf_get_msglevel,
  367. .set_msglevel = igbvf_set_msglevel,
  368. .nway_reset = igbvf_nway_reset,
  369. .get_link = ethtool_op_get_link,
  370. .get_eeprom_len = igbvf_get_eeprom_len,
  371. .get_eeprom = igbvf_get_eeprom,
  372. .set_eeprom = igbvf_set_eeprom,
  373. .get_ringparam = igbvf_get_ringparam,
  374. .set_ringparam = igbvf_set_ringparam,
  375. .get_pauseparam = igbvf_get_pauseparam,
  376. .set_pauseparam = igbvf_set_pauseparam,
  377. .self_test = igbvf_diag_test,
  378. .get_sset_count = igbvf_get_sset_count,
  379. .get_strings = igbvf_get_strings,
  380. .get_ethtool_stats = igbvf_get_ethtool_stats,
  381. .get_coalesce = igbvf_get_coalesce,
  382. .set_coalesce = igbvf_set_coalesce,
  383. };
  384. void igbvf_set_ethtool_ops(struct net_device *netdev)
  385. {
  386. netdev->ethtool_ops = &igbvf_ethtool_ops;
  387. }