ethtool.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952
  1. /*******************************************************************************
  2. Intel 82599 Virtual Function driver
  3. Copyright(c) 1999 - 2015 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 ixgbevf */
  20. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  21. #include <linux/types.h>
  22. #include <linux/module.h>
  23. #include <linux/slab.h>
  24. #include <linux/pci.h>
  25. #include <linux/netdevice.h>
  26. #include <linux/ethtool.h>
  27. #include <linux/vmalloc.h>
  28. #include <linux/if_vlan.h>
  29. #include <linux/uaccess.h>
  30. #include "ixgbevf.h"
  31. #define IXGBE_ALL_RAR_ENTRIES 16
  32. enum {NETDEV_STATS, IXGBEVF_STATS};
  33. struct ixgbe_stats {
  34. char stat_string[ETH_GSTRING_LEN];
  35. int type;
  36. int sizeof_stat;
  37. int stat_offset;
  38. };
  39. #define IXGBEVF_STAT(_name, _stat) { \
  40. .stat_string = _name, \
  41. .type = IXGBEVF_STATS, \
  42. .sizeof_stat = FIELD_SIZEOF(struct ixgbevf_adapter, _stat), \
  43. .stat_offset = offsetof(struct ixgbevf_adapter, _stat) \
  44. }
  45. #define IXGBEVF_NETDEV_STAT(_net_stat) { \
  46. .stat_string = #_net_stat, \
  47. .type = NETDEV_STATS, \
  48. .sizeof_stat = FIELD_SIZEOF(struct net_device_stats, _net_stat), \
  49. .stat_offset = offsetof(struct net_device_stats, _net_stat) \
  50. }
  51. static struct ixgbe_stats ixgbevf_gstrings_stats[] = {
  52. IXGBEVF_NETDEV_STAT(rx_packets),
  53. IXGBEVF_NETDEV_STAT(tx_packets),
  54. IXGBEVF_NETDEV_STAT(rx_bytes),
  55. IXGBEVF_NETDEV_STAT(tx_bytes),
  56. IXGBEVF_STAT("tx_busy", tx_busy),
  57. IXGBEVF_STAT("tx_restart_queue", restart_queue),
  58. IXGBEVF_STAT("tx_timeout_count", tx_timeout_count),
  59. IXGBEVF_NETDEV_STAT(multicast),
  60. IXGBEVF_STAT("rx_csum_offload_errors", hw_csum_rx_error),
  61. };
  62. #define IXGBEVF_QUEUE_STATS_LEN ( \
  63. (((struct ixgbevf_adapter *)netdev_priv(netdev))->num_tx_queues + \
  64. ((struct ixgbevf_adapter *)netdev_priv(netdev))->num_rx_queues) * \
  65. (sizeof(struct ixgbevf_stats) / sizeof(u64)))
  66. #define IXGBEVF_GLOBAL_STATS_LEN ARRAY_SIZE(ixgbevf_gstrings_stats)
  67. #define IXGBEVF_STATS_LEN (IXGBEVF_GLOBAL_STATS_LEN + IXGBEVF_QUEUE_STATS_LEN)
  68. static const char ixgbe_gstrings_test[][ETH_GSTRING_LEN] = {
  69. "Register test (offline)",
  70. "Link test (on/offline)"
  71. };
  72. #define IXGBEVF_TEST_LEN (sizeof(ixgbe_gstrings_test) / ETH_GSTRING_LEN)
  73. static int ixgbevf_get_settings(struct net_device *netdev,
  74. struct ethtool_cmd *ecmd)
  75. {
  76. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  77. struct ixgbe_hw *hw = &adapter->hw;
  78. u32 link_speed = 0;
  79. bool link_up;
  80. ecmd->supported = SUPPORTED_10000baseT_Full;
  81. ecmd->autoneg = AUTONEG_DISABLE;
  82. ecmd->transceiver = XCVR_DUMMY1;
  83. ecmd->port = -1;
  84. hw->mac.get_link_status = 1;
  85. hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
  86. if (link_up) {
  87. __u32 speed = SPEED_10000;
  88. switch (link_speed) {
  89. case IXGBE_LINK_SPEED_10GB_FULL:
  90. speed = SPEED_10000;
  91. break;
  92. case IXGBE_LINK_SPEED_1GB_FULL:
  93. speed = SPEED_1000;
  94. break;
  95. case IXGBE_LINK_SPEED_100_FULL:
  96. speed = SPEED_100;
  97. break;
  98. }
  99. ethtool_cmd_speed_set(ecmd, speed);
  100. ecmd->duplex = DUPLEX_FULL;
  101. } else {
  102. ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
  103. ecmd->duplex = DUPLEX_UNKNOWN;
  104. }
  105. return 0;
  106. }
  107. static u32 ixgbevf_get_msglevel(struct net_device *netdev)
  108. {
  109. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  110. return adapter->msg_enable;
  111. }
  112. static void ixgbevf_set_msglevel(struct net_device *netdev, u32 data)
  113. {
  114. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  115. adapter->msg_enable = data;
  116. }
  117. #define IXGBE_GET_STAT(_A_, _R_) (_A_->stats._R_)
  118. static int ixgbevf_get_regs_len(struct net_device *netdev)
  119. {
  120. #define IXGBE_REGS_LEN 45
  121. return IXGBE_REGS_LEN * sizeof(u32);
  122. }
  123. static void ixgbevf_get_regs(struct net_device *netdev,
  124. struct ethtool_regs *regs,
  125. void *p)
  126. {
  127. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  128. struct ixgbe_hw *hw = &adapter->hw;
  129. u32 *regs_buff = p;
  130. u32 regs_len = ixgbevf_get_regs_len(netdev);
  131. u8 i;
  132. memset(p, 0, regs_len);
  133. /* generate a number suitable for ethtool's register version */
  134. regs->version = (1u << 24) | (hw->revision_id << 16) | hw->device_id;
  135. /* General Registers */
  136. regs_buff[0] = IXGBE_READ_REG(hw, IXGBE_VFCTRL);
  137. regs_buff[1] = IXGBE_READ_REG(hw, IXGBE_VFSTATUS);
  138. regs_buff[2] = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
  139. regs_buff[3] = IXGBE_READ_REG(hw, IXGBE_VFRXMEMWRAP);
  140. regs_buff[4] = IXGBE_READ_REG(hw, IXGBE_VFFRTIMER);
  141. /* Interrupt */
  142. /* don't read EICR because it can clear interrupt causes, instead
  143. * read EICS which is a shadow but doesn't clear EICR
  144. */
  145. regs_buff[5] = IXGBE_READ_REG(hw, IXGBE_VTEICS);
  146. regs_buff[6] = IXGBE_READ_REG(hw, IXGBE_VTEICS);
  147. regs_buff[7] = IXGBE_READ_REG(hw, IXGBE_VTEIMS);
  148. regs_buff[8] = IXGBE_READ_REG(hw, IXGBE_VTEIMC);
  149. regs_buff[9] = IXGBE_READ_REG(hw, IXGBE_VTEIAC);
  150. regs_buff[10] = IXGBE_READ_REG(hw, IXGBE_VTEIAM);
  151. regs_buff[11] = IXGBE_READ_REG(hw, IXGBE_VTEITR(0));
  152. regs_buff[12] = IXGBE_READ_REG(hw, IXGBE_VTIVAR(0));
  153. regs_buff[13] = IXGBE_READ_REG(hw, IXGBE_VTIVAR_MISC);
  154. /* Receive DMA */
  155. for (i = 0; i < 2; i++)
  156. regs_buff[14 + i] = IXGBE_READ_REG(hw, IXGBE_VFRDBAL(i));
  157. for (i = 0; i < 2; i++)
  158. regs_buff[16 + i] = IXGBE_READ_REG(hw, IXGBE_VFRDBAH(i));
  159. for (i = 0; i < 2; i++)
  160. regs_buff[18 + i] = IXGBE_READ_REG(hw, IXGBE_VFRDLEN(i));
  161. for (i = 0; i < 2; i++)
  162. regs_buff[20 + i] = IXGBE_READ_REG(hw, IXGBE_VFRDH(i));
  163. for (i = 0; i < 2; i++)
  164. regs_buff[22 + i] = IXGBE_READ_REG(hw, IXGBE_VFRDT(i));
  165. for (i = 0; i < 2; i++)
  166. regs_buff[24 + i] = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i));
  167. for (i = 0; i < 2; i++)
  168. regs_buff[26 + i] = IXGBE_READ_REG(hw, IXGBE_VFSRRCTL(i));
  169. /* Receive */
  170. regs_buff[28] = IXGBE_READ_REG(hw, IXGBE_VFPSRTYPE);
  171. /* Transmit */
  172. for (i = 0; i < 2; i++)
  173. regs_buff[29 + i] = IXGBE_READ_REG(hw, IXGBE_VFTDBAL(i));
  174. for (i = 0; i < 2; i++)
  175. regs_buff[31 + i] = IXGBE_READ_REG(hw, IXGBE_VFTDBAH(i));
  176. for (i = 0; i < 2; i++)
  177. regs_buff[33 + i] = IXGBE_READ_REG(hw, IXGBE_VFTDLEN(i));
  178. for (i = 0; i < 2; i++)
  179. regs_buff[35 + i] = IXGBE_READ_REG(hw, IXGBE_VFTDH(i));
  180. for (i = 0; i < 2; i++)
  181. regs_buff[37 + i] = IXGBE_READ_REG(hw, IXGBE_VFTDT(i));
  182. for (i = 0; i < 2; i++)
  183. regs_buff[39 + i] = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(i));
  184. for (i = 0; i < 2; i++)
  185. regs_buff[41 + i] = IXGBE_READ_REG(hw, IXGBE_VFTDWBAL(i));
  186. for (i = 0; i < 2; i++)
  187. regs_buff[43 + i] = IXGBE_READ_REG(hw, IXGBE_VFTDWBAH(i));
  188. }
  189. static void ixgbevf_get_drvinfo(struct net_device *netdev,
  190. struct ethtool_drvinfo *drvinfo)
  191. {
  192. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  193. strlcpy(drvinfo->driver, ixgbevf_driver_name, sizeof(drvinfo->driver));
  194. strlcpy(drvinfo->version, ixgbevf_driver_version,
  195. sizeof(drvinfo->version));
  196. strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
  197. sizeof(drvinfo->bus_info));
  198. }
  199. static void ixgbevf_get_ringparam(struct net_device *netdev,
  200. struct ethtool_ringparam *ring)
  201. {
  202. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  203. ring->rx_max_pending = IXGBEVF_MAX_RXD;
  204. ring->tx_max_pending = IXGBEVF_MAX_TXD;
  205. ring->rx_pending = adapter->rx_ring_count;
  206. ring->tx_pending = adapter->tx_ring_count;
  207. }
  208. static int ixgbevf_set_ringparam(struct net_device *netdev,
  209. struct ethtool_ringparam *ring)
  210. {
  211. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  212. struct ixgbevf_ring *tx_ring = NULL, *rx_ring = NULL;
  213. u32 new_rx_count, new_tx_count;
  214. int i, err = 0;
  215. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  216. return -EINVAL;
  217. new_tx_count = max_t(u32, ring->tx_pending, IXGBEVF_MIN_TXD);
  218. new_tx_count = min_t(u32, new_tx_count, IXGBEVF_MAX_TXD);
  219. new_tx_count = ALIGN(new_tx_count, IXGBE_REQ_TX_DESCRIPTOR_MULTIPLE);
  220. new_rx_count = max_t(u32, ring->rx_pending, IXGBEVF_MIN_RXD);
  221. new_rx_count = min_t(u32, new_rx_count, IXGBEVF_MAX_RXD);
  222. new_rx_count = ALIGN(new_rx_count, IXGBE_REQ_RX_DESCRIPTOR_MULTIPLE);
  223. /* if nothing to do return success */
  224. if ((new_tx_count == adapter->tx_ring_count) &&
  225. (new_rx_count == adapter->rx_ring_count))
  226. return 0;
  227. while (test_and_set_bit(__IXGBEVF_RESETTING, &adapter->state))
  228. usleep_range(1000, 2000);
  229. if (!netif_running(adapter->netdev)) {
  230. for (i = 0; i < adapter->num_tx_queues; i++)
  231. adapter->tx_ring[i]->count = new_tx_count;
  232. for (i = 0; i < adapter->num_rx_queues; i++)
  233. adapter->rx_ring[i]->count = new_rx_count;
  234. adapter->tx_ring_count = new_tx_count;
  235. adapter->rx_ring_count = new_rx_count;
  236. goto clear_reset;
  237. }
  238. if (new_tx_count != adapter->tx_ring_count) {
  239. tx_ring = vmalloc(adapter->num_tx_queues * sizeof(*tx_ring));
  240. if (!tx_ring) {
  241. err = -ENOMEM;
  242. goto clear_reset;
  243. }
  244. for (i = 0; i < adapter->num_tx_queues; i++) {
  245. /* clone ring and setup updated count */
  246. tx_ring[i] = *adapter->tx_ring[i];
  247. tx_ring[i].count = new_tx_count;
  248. err = ixgbevf_setup_tx_resources(&tx_ring[i]);
  249. if (err) {
  250. while (i) {
  251. i--;
  252. ixgbevf_free_tx_resources(&tx_ring[i]);
  253. }
  254. vfree(tx_ring);
  255. tx_ring = NULL;
  256. goto clear_reset;
  257. }
  258. }
  259. }
  260. if (new_rx_count != adapter->rx_ring_count) {
  261. rx_ring = vmalloc(adapter->num_rx_queues * sizeof(*rx_ring));
  262. if (!rx_ring) {
  263. err = -ENOMEM;
  264. goto clear_reset;
  265. }
  266. for (i = 0; i < adapter->num_rx_queues; i++) {
  267. /* clone ring and setup updated count */
  268. rx_ring[i] = *adapter->rx_ring[i];
  269. rx_ring[i].count = new_rx_count;
  270. err = ixgbevf_setup_rx_resources(&rx_ring[i]);
  271. if (err) {
  272. while (i) {
  273. i--;
  274. ixgbevf_free_rx_resources(&rx_ring[i]);
  275. }
  276. vfree(rx_ring);
  277. rx_ring = NULL;
  278. goto clear_reset;
  279. }
  280. }
  281. }
  282. /* bring interface down to prepare for update */
  283. ixgbevf_down(adapter);
  284. /* Tx */
  285. if (tx_ring) {
  286. for (i = 0; i < adapter->num_tx_queues; i++) {
  287. ixgbevf_free_tx_resources(adapter->tx_ring[i]);
  288. *adapter->tx_ring[i] = tx_ring[i];
  289. }
  290. adapter->tx_ring_count = new_tx_count;
  291. vfree(tx_ring);
  292. tx_ring = NULL;
  293. }
  294. /* Rx */
  295. if (rx_ring) {
  296. for (i = 0; i < adapter->num_rx_queues; i++) {
  297. ixgbevf_free_rx_resources(adapter->rx_ring[i]);
  298. *adapter->rx_ring[i] = rx_ring[i];
  299. }
  300. adapter->rx_ring_count = new_rx_count;
  301. vfree(rx_ring);
  302. rx_ring = NULL;
  303. }
  304. /* restore interface using new values */
  305. ixgbevf_up(adapter);
  306. clear_reset:
  307. /* free Tx resources if Rx error is encountered */
  308. if (tx_ring) {
  309. for (i = 0; i < adapter->num_tx_queues; i++)
  310. ixgbevf_free_tx_resources(&tx_ring[i]);
  311. vfree(tx_ring);
  312. }
  313. clear_bit(__IXGBEVF_RESETTING, &adapter->state);
  314. return err;
  315. }
  316. static int ixgbevf_get_sset_count(struct net_device *netdev, int stringset)
  317. {
  318. switch (stringset) {
  319. case ETH_SS_TEST:
  320. return IXGBEVF_TEST_LEN;
  321. case ETH_SS_STATS:
  322. return IXGBEVF_STATS_LEN;
  323. default:
  324. return -EINVAL;
  325. }
  326. }
  327. static void ixgbevf_get_ethtool_stats(struct net_device *netdev,
  328. struct ethtool_stats *stats, u64 *data)
  329. {
  330. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  331. struct rtnl_link_stats64 temp;
  332. const struct rtnl_link_stats64 *net_stats;
  333. unsigned int start;
  334. struct ixgbevf_ring *ring;
  335. int i, j;
  336. char *p;
  337. ixgbevf_update_stats(adapter);
  338. net_stats = dev_get_stats(netdev, &temp);
  339. for (i = 0; i < IXGBEVF_GLOBAL_STATS_LEN; i++) {
  340. switch (ixgbevf_gstrings_stats[i].type) {
  341. case NETDEV_STATS:
  342. p = (char *)net_stats +
  343. ixgbevf_gstrings_stats[i].stat_offset;
  344. break;
  345. case IXGBEVF_STATS:
  346. p = (char *)adapter +
  347. ixgbevf_gstrings_stats[i].stat_offset;
  348. break;
  349. default:
  350. data[i] = 0;
  351. continue;
  352. }
  353. data[i] = (ixgbevf_gstrings_stats[i].sizeof_stat ==
  354. sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
  355. }
  356. /* populate Tx queue data */
  357. for (j = 0; j < adapter->num_tx_queues; j++) {
  358. ring = adapter->tx_ring[j];
  359. if (!ring) {
  360. data[i++] = 0;
  361. data[i++] = 0;
  362. #ifdef BP_EXTENDED_STATS
  363. data[i++] = 0;
  364. data[i++] = 0;
  365. data[i++] = 0;
  366. #endif
  367. continue;
  368. }
  369. do {
  370. start = u64_stats_fetch_begin_irq(&ring->syncp);
  371. data[i] = ring->stats.packets;
  372. data[i + 1] = ring->stats.bytes;
  373. } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
  374. i += 2;
  375. #ifdef BP_EXTENDED_STATS
  376. data[i] = ring->stats.yields;
  377. data[i + 1] = ring->stats.misses;
  378. data[i + 2] = ring->stats.cleaned;
  379. i += 3;
  380. #endif
  381. }
  382. /* populate Rx queue data */
  383. for (j = 0; j < adapter->num_rx_queues; j++) {
  384. ring = adapter->rx_ring[j];
  385. if (!ring) {
  386. data[i++] = 0;
  387. data[i++] = 0;
  388. #ifdef BP_EXTENDED_STATS
  389. data[i++] = 0;
  390. data[i++] = 0;
  391. data[i++] = 0;
  392. #endif
  393. continue;
  394. }
  395. do {
  396. start = u64_stats_fetch_begin_irq(&ring->syncp);
  397. data[i] = ring->stats.packets;
  398. data[i + 1] = ring->stats.bytes;
  399. } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
  400. i += 2;
  401. #ifdef BP_EXTENDED_STATS
  402. data[i] = ring->stats.yields;
  403. data[i + 1] = ring->stats.misses;
  404. data[i + 2] = ring->stats.cleaned;
  405. i += 3;
  406. #endif
  407. }
  408. }
  409. static void ixgbevf_get_strings(struct net_device *netdev, u32 stringset,
  410. u8 *data)
  411. {
  412. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  413. char *p = (char *)data;
  414. int i;
  415. switch (stringset) {
  416. case ETH_SS_TEST:
  417. memcpy(data, *ixgbe_gstrings_test,
  418. IXGBEVF_TEST_LEN * ETH_GSTRING_LEN);
  419. break;
  420. case ETH_SS_STATS:
  421. for (i = 0; i < IXGBEVF_GLOBAL_STATS_LEN; i++) {
  422. memcpy(p, ixgbevf_gstrings_stats[i].stat_string,
  423. ETH_GSTRING_LEN);
  424. p += ETH_GSTRING_LEN;
  425. }
  426. for (i = 0; i < adapter->num_tx_queues; i++) {
  427. sprintf(p, "tx_queue_%u_packets", i);
  428. p += ETH_GSTRING_LEN;
  429. sprintf(p, "tx_queue_%u_bytes", i);
  430. p += ETH_GSTRING_LEN;
  431. #ifdef BP_EXTENDED_STATS
  432. sprintf(p, "tx_queue_%u_bp_napi_yield", i);
  433. p += ETH_GSTRING_LEN;
  434. sprintf(p, "tx_queue_%u_bp_misses", i);
  435. p += ETH_GSTRING_LEN;
  436. sprintf(p, "tx_queue_%u_bp_cleaned", i);
  437. p += ETH_GSTRING_LEN;
  438. #endif /* BP_EXTENDED_STATS */
  439. }
  440. for (i = 0; i < adapter->num_rx_queues; i++) {
  441. sprintf(p, "rx_queue_%u_packets", i);
  442. p += ETH_GSTRING_LEN;
  443. sprintf(p, "rx_queue_%u_bytes", i);
  444. p += ETH_GSTRING_LEN;
  445. #ifdef BP_EXTENDED_STATS
  446. sprintf(p, "rx_queue_%u_bp_poll_yield", i);
  447. p += ETH_GSTRING_LEN;
  448. sprintf(p, "rx_queue_%u_bp_misses", i);
  449. p += ETH_GSTRING_LEN;
  450. sprintf(p, "rx_queue_%u_bp_cleaned", i);
  451. p += ETH_GSTRING_LEN;
  452. #endif /* BP_EXTENDED_STATS */
  453. }
  454. break;
  455. }
  456. }
  457. static int ixgbevf_link_test(struct ixgbevf_adapter *adapter, u64 *data)
  458. {
  459. struct ixgbe_hw *hw = &adapter->hw;
  460. bool link_up;
  461. u32 link_speed = 0;
  462. *data = 0;
  463. hw->mac.ops.check_link(hw, &link_speed, &link_up, true);
  464. if (!link_up)
  465. *data = 1;
  466. return *data;
  467. }
  468. /* ethtool register test data */
  469. struct ixgbevf_reg_test {
  470. u16 reg;
  471. u8 array_len;
  472. u8 test_type;
  473. u32 mask;
  474. u32 write;
  475. };
  476. /* In the hardware, registers are laid out either singly, in arrays
  477. * spaced 0x40 bytes apart, or in contiguous tables. We assume
  478. * most tests take place on arrays or single registers (handled
  479. * as a single-element array) and special-case the tables.
  480. * Table tests are always pattern tests.
  481. *
  482. * We also make provision for some required setup steps by specifying
  483. * registers to be written without any read-back testing.
  484. */
  485. #define PATTERN_TEST 1
  486. #define SET_READ_TEST 2
  487. #define WRITE_NO_TEST 3
  488. #define TABLE32_TEST 4
  489. #define TABLE64_TEST_LO 5
  490. #define TABLE64_TEST_HI 6
  491. /* default VF register test */
  492. static const struct ixgbevf_reg_test reg_test_vf[] = {
  493. { IXGBE_VFRDBAL(0), 2, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFF80 },
  494. { IXGBE_VFRDBAH(0), 2, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  495. { IXGBE_VFRDLEN(0), 2, PATTERN_TEST, 0x000FFF80, 0x000FFFFF },
  496. { IXGBE_VFRXDCTL(0), 2, WRITE_NO_TEST, 0, IXGBE_RXDCTL_ENABLE },
  497. { IXGBE_VFRDT(0), 2, PATTERN_TEST, 0x0000FFFF, 0x0000FFFF },
  498. { IXGBE_VFRXDCTL(0), 2, WRITE_NO_TEST, 0, 0 },
  499. { IXGBE_VFTDBAL(0), 2, PATTERN_TEST, 0xFFFFFF80, 0xFFFFFFFF },
  500. { IXGBE_VFTDBAH(0), 2, PATTERN_TEST, 0xFFFFFFFF, 0xFFFFFFFF },
  501. { IXGBE_VFTDLEN(0), 2, PATTERN_TEST, 0x000FFF80, 0x000FFF80 },
  502. { .reg = 0 }
  503. };
  504. static const u32 register_test_patterns[] = {
  505. 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF
  506. };
  507. static bool reg_pattern_test(struct ixgbevf_adapter *adapter, u64 *data,
  508. int reg, u32 mask, u32 write)
  509. {
  510. u32 pat, val, before;
  511. if (IXGBE_REMOVED(adapter->hw.hw_addr)) {
  512. *data = 1;
  513. return true;
  514. }
  515. for (pat = 0; pat < ARRAY_SIZE(register_test_patterns); pat++) {
  516. before = ixgbevf_read_reg(&adapter->hw, reg);
  517. ixgbe_write_reg(&adapter->hw, reg,
  518. register_test_patterns[pat] & write);
  519. val = ixgbevf_read_reg(&adapter->hw, reg);
  520. if (val != (register_test_patterns[pat] & write & mask)) {
  521. hw_dbg(&adapter->hw,
  522. "pattern test reg %04X failed: got 0x%08X expected 0x%08X\n",
  523. reg, val,
  524. register_test_patterns[pat] & write & mask);
  525. *data = reg;
  526. ixgbe_write_reg(&adapter->hw, reg, before);
  527. return true;
  528. }
  529. ixgbe_write_reg(&adapter->hw, reg, before);
  530. }
  531. return false;
  532. }
  533. static bool reg_set_and_check(struct ixgbevf_adapter *adapter, u64 *data,
  534. int reg, u32 mask, u32 write)
  535. {
  536. u32 val, before;
  537. if (IXGBE_REMOVED(adapter->hw.hw_addr)) {
  538. *data = 1;
  539. return true;
  540. }
  541. before = ixgbevf_read_reg(&adapter->hw, reg);
  542. ixgbe_write_reg(&adapter->hw, reg, write & mask);
  543. val = ixgbevf_read_reg(&adapter->hw, reg);
  544. if ((write & mask) != (val & mask)) {
  545. pr_err("set/check reg %04X test failed: got 0x%08X expected 0x%08X\n",
  546. reg, (val & mask), write & mask);
  547. *data = reg;
  548. ixgbe_write_reg(&adapter->hw, reg, before);
  549. return true;
  550. }
  551. ixgbe_write_reg(&adapter->hw, reg, before);
  552. return false;
  553. }
  554. static int ixgbevf_reg_test(struct ixgbevf_adapter *adapter, u64 *data)
  555. {
  556. const struct ixgbevf_reg_test *test;
  557. u32 i;
  558. if (IXGBE_REMOVED(adapter->hw.hw_addr)) {
  559. dev_err(&adapter->pdev->dev,
  560. "Adapter removed - register test blocked\n");
  561. *data = 1;
  562. return 1;
  563. }
  564. test = reg_test_vf;
  565. /* Perform the register test, looping through the test table
  566. * until we either fail or reach the null entry.
  567. */
  568. while (test->reg) {
  569. for (i = 0; i < test->array_len; i++) {
  570. bool b = false;
  571. switch (test->test_type) {
  572. case PATTERN_TEST:
  573. b = reg_pattern_test(adapter, data,
  574. test->reg + (i * 0x40),
  575. test->mask,
  576. test->write);
  577. break;
  578. case SET_READ_TEST:
  579. b = reg_set_and_check(adapter, data,
  580. test->reg + (i * 0x40),
  581. test->mask,
  582. test->write);
  583. break;
  584. case WRITE_NO_TEST:
  585. ixgbe_write_reg(&adapter->hw,
  586. test->reg + (i * 0x40),
  587. test->write);
  588. break;
  589. case TABLE32_TEST:
  590. b = reg_pattern_test(adapter, data,
  591. test->reg + (i * 4),
  592. test->mask,
  593. test->write);
  594. break;
  595. case TABLE64_TEST_LO:
  596. b = reg_pattern_test(adapter, data,
  597. test->reg + (i * 8),
  598. test->mask,
  599. test->write);
  600. break;
  601. case TABLE64_TEST_HI:
  602. b = reg_pattern_test(adapter, data,
  603. test->reg + 4 + (i * 8),
  604. test->mask,
  605. test->write);
  606. break;
  607. }
  608. if (b)
  609. return 1;
  610. }
  611. test++;
  612. }
  613. *data = 0;
  614. return *data;
  615. }
  616. static void ixgbevf_diag_test(struct net_device *netdev,
  617. struct ethtool_test *eth_test, u64 *data)
  618. {
  619. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  620. bool if_running = netif_running(netdev);
  621. if (IXGBE_REMOVED(adapter->hw.hw_addr)) {
  622. dev_err(&adapter->pdev->dev,
  623. "Adapter removed - test blocked\n");
  624. data[0] = 1;
  625. data[1] = 1;
  626. eth_test->flags |= ETH_TEST_FL_FAILED;
  627. return;
  628. }
  629. set_bit(__IXGBEVF_TESTING, &adapter->state);
  630. if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
  631. /* Offline tests */
  632. hw_dbg(&adapter->hw, "offline testing starting\n");
  633. /* Link test performed before hardware reset so autoneg doesn't
  634. * interfere with test result
  635. */
  636. if (ixgbevf_link_test(adapter, &data[1]))
  637. eth_test->flags |= ETH_TEST_FL_FAILED;
  638. if (if_running)
  639. /* indicate we're in test mode */
  640. ixgbevf_close(netdev);
  641. else
  642. ixgbevf_reset(adapter);
  643. hw_dbg(&adapter->hw, "register testing starting\n");
  644. if (ixgbevf_reg_test(adapter, &data[0]))
  645. eth_test->flags |= ETH_TEST_FL_FAILED;
  646. ixgbevf_reset(adapter);
  647. clear_bit(__IXGBEVF_TESTING, &adapter->state);
  648. if (if_running)
  649. ixgbevf_open(netdev);
  650. } else {
  651. hw_dbg(&adapter->hw, "online testing starting\n");
  652. /* Online tests */
  653. if (ixgbevf_link_test(adapter, &data[1]))
  654. eth_test->flags |= ETH_TEST_FL_FAILED;
  655. /* Online tests aren't run; pass by default */
  656. data[0] = 0;
  657. clear_bit(__IXGBEVF_TESTING, &adapter->state);
  658. }
  659. msleep_interruptible(4 * 1000);
  660. }
  661. static int ixgbevf_nway_reset(struct net_device *netdev)
  662. {
  663. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  664. if (netif_running(netdev))
  665. ixgbevf_reinit_locked(adapter);
  666. return 0;
  667. }
  668. static int ixgbevf_get_coalesce(struct net_device *netdev,
  669. struct ethtool_coalesce *ec)
  670. {
  671. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  672. /* only valid if in constant ITR mode */
  673. if (adapter->rx_itr_setting <= 1)
  674. ec->rx_coalesce_usecs = adapter->rx_itr_setting;
  675. else
  676. ec->rx_coalesce_usecs = adapter->rx_itr_setting >> 2;
  677. /* if in mixed Tx/Rx queues per vector mode, report only Rx settings */
  678. if (adapter->q_vector[0]->tx.count && adapter->q_vector[0]->rx.count)
  679. return 0;
  680. /* only valid if in constant ITR mode */
  681. if (adapter->tx_itr_setting <= 1)
  682. ec->tx_coalesce_usecs = adapter->tx_itr_setting;
  683. else
  684. ec->tx_coalesce_usecs = adapter->tx_itr_setting >> 2;
  685. return 0;
  686. }
  687. static int ixgbevf_set_coalesce(struct net_device *netdev,
  688. struct ethtool_coalesce *ec)
  689. {
  690. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  691. struct ixgbevf_q_vector *q_vector;
  692. int num_vectors, i;
  693. u16 tx_itr_param, rx_itr_param;
  694. /* don't accept Tx specific changes if we've got mixed RxTx vectors */
  695. if (adapter->q_vector[0]->tx.count &&
  696. adapter->q_vector[0]->rx.count && ec->tx_coalesce_usecs)
  697. return -EINVAL;
  698. if ((ec->rx_coalesce_usecs > (IXGBE_MAX_EITR >> 2)) ||
  699. (ec->tx_coalesce_usecs > (IXGBE_MAX_EITR >> 2)))
  700. return -EINVAL;
  701. if (ec->rx_coalesce_usecs > 1)
  702. adapter->rx_itr_setting = ec->rx_coalesce_usecs << 2;
  703. else
  704. adapter->rx_itr_setting = ec->rx_coalesce_usecs;
  705. if (adapter->rx_itr_setting == 1)
  706. rx_itr_param = IXGBE_20K_ITR;
  707. else
  708. rx_itr_param = adapter->rx_itr_setting;
  709. if (ec->tx_coalesce_usecs > 1)
  710. adapter->tx_itr_setting = ec->tx_coalesce_usecs << 2;
  711. else
  712. adapter->tx_itr_setting = ec->tx_coalesce_usecs;
  713. if (adapter->tx_itr_setting == 1)
  714. tx_itr_param = IXGBE_12K_ITR;
  715. else
  716. tx_itr_param = adapter->tx_itr_setting;
  717. num_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  718. for (i = 0; i < num_vectors; i++) {
  719. q_vector = adapter->q_vector[i];
  720. if (q_vector->tx.count && !q_vector->rx.count)
  721. /* Tx only */
  722. q_vector->itr = tx_itr_param;
  723. else
  724. /* Rx only or mixed */
  725. q_vector->itr = rx_itr_param;
  726. ixgbevf_write_eitr(q_vector);
  727. }
  728. return 0;
  729. }
  730. static int ixgbevf_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
  731. u32 *rules __always_unused)
  732. {
  733. struct ixgbevf_adapter *adapter = netdev_priv(dev);
  734. switch (info->cmd) {
  735. case ETHTOOL_GRXRINGS:
  736. info->data = adapter->num_rx_queues;
  737. return 0;
  738. default:
  739. hw_dbg(&adapter->hw, "Command parameters not supported\n");
  740. return -EOPNOTSUPP;
  741. }
  742. }
  743. static u32 ixgbevf_get_rxfh_indir_size(struct net_device *netdev)
  744. {
  745. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  746. if (adapter->hw.mac.type >= ixgbe_mac_X550_vf)
  747. return IXGBEVF_X550_VFRETA_SIZE;
  748. return IXGBEVF_82599_RETA_SIZE;
  749. }
  750. static u32 ixgbevf_get_rxfh_key_size(struct net_device *netdev)
  751. {
  752. return IXGBEVF_RSS_HASH_KEY_SIZE;
  753. }
  754. static int ixgbevf_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
  755. u8 *hfunc)
  756. {
  757. struct ixgbevf_adapter *adapter = netdev_priv(netdev);
  758. int err = 0;
  759. if (hfunc)
  760. *hfunc = ETH_RSS_HASH_TOP;
  761. if (adapter->hw.mac.type >= ixgbe_mac_X550_vf) {
  762. if (key)
  763. memcpy(key, adapter->rss_key, sizeof(adapter->rss_key));
  764. if (indir) {
  765. int i;
  766. for (i = 0; i < IXGBEVF_X550_VFRETA_SIZE; i++)
  767. indir[i] = adapter->rss_indir_tbl[i];
  768. }
  769. } else {
  770. /* If neither indirection table nor hash key was requested
  771. * - just return a success avoiding taking any locks.
  772. */
  773. if (!indir && !key)
  774. return 0;
  775. spin_lock_bh(&adapter->mbx_lock);
  776. if (indir)
  777. err = ixgbevf_get_reta_locked(&adapter->hw, indir,
  778. adapter->num_rx_queues);
  779. if (!err && key)
  780. err = ixgbevf_get_rss_key_locked(&adapter->hw, key);
  781. spin_unlock_bh(&adapter->mbx_lock);
  782. }
  783. return err;
  784. }
  785. static const struct ethtool_ops ixgbevf_ethtool_ops = {
  786. .get_settings = ixgbevf_get_settings,
  787. .get_drvinfo = ixgbevf_get_drvinfo,
  788. .get_regs_len = ixgbevf_get_regs_len,
  789. .get_regs = ixgbevf_get_regs,
  790. .nway_reset = ixgbevf_nway_reset,
  791. .get_link = ethtool_op_get_link,
  792. .get_ringparam = ixgbevf_get_ringparam,
  793. .set_ringparam = ixgbevf_set_ringparam,
  794. .get_msglevel = ixgbevf_get_msglevel,
  795. .set_msglevel = ixgbevf_set_msglevel,
  796. .self_test = ixgbevf_diag_test,
  797. .get_sset_count = ixgbevf_get_sset_count,
  798. .get_strings = ixgbevf_get_strings,
  799. .get_ethtool_stats = ixgbevf_get_ethtool_stats,
  800. .get_coalesce = ixgbevf_get_coalesce,
  801. .set_coalesce = ixgbevf_set_coalesce,
  802. .get_rxnfc = ixgbevf_get_rxnfc,
  803. .get_rxfh_indir_size = ixgbevf_get_rxfh_indir_size,
  804. .get_rxfh_key_size = ixgbevf_get_rxfh_key_size,
  805. .get_rxfh = ixgbevf_get_rxfh,
  806. };
  807. void ixgbevf_set_ethtool_ops(struct net_device *netdev)
  808. {
  809. netdev->ethtool_ops = &ixgbevf_ethtool_ops;
  810. }