ethtool.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2006-2009 Solarflare Communications Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published
  8. * by the Free Software Foundation, incorporated herein by reference.
  9. */
  10. #include <linux/netdevice.h>
  11. #include <linux/ethtool.h>
  12. #include <linux/rtnetlink.h>
  13. #include "net_driver.h"
  14. #include "workarounds.h"
  15. #include "selftest.h"
  16. #include "efx.h"
  17. #include "filter.h"
  18. #include "nic.h"
  19. #include "spi.h"
  20. #include "mdio_10g.h"
  21. struct ethtool_string {
  22. char name[ETH_GSTRING_LEN];
  23. };
  24. struct efx_ethtool_stat {
  25. const char *name;
  26. enum {
  27. EFX_ETHTOOL_STAT_SOURCE_mac_stats,
  28. EFX_ETHTOOL_STAT_SOURCE_nic,
  29. EFX_ETHTOOL_STAT_SOURCE_channel
  30. } source;
  31. unsigned offset;
  32. u64(*get_stat) (void *field); /* Reader function */
  33. };
  34. /* Initialiser for a struct #efx_ethtool_stat with type-checking */
  35. #define EFX_ETHTOOL_STAT(stat_name, source_name, field, field_type, \
  36. get_stat_function) { \
  37. .name = #stat_name, \
  38. .source = EFX_ETHTOOL_STAT_SOURCE_##source_name, \
  39. .offset = ((((field_type *) 0) == \
  40. &((struct efx_##source_name *)0)->field) ? \
  41. offsetof(struct efx_##source_name, field) : \
  42. offsetof(struct efx_##source_name, field)), \
  43. .get_stat = get_stat_function, \
  44. }
  45. static u64 efx_get_uint_stat(void *field)
  46. {
  47. return *(unsigned int *)field;
  48. }
  49. static u64 efx_get_ulong_stat(void *field)
  50. {
  51. return *(unsigned long *)field;
  52. }
  53. static u64 efx_get_u64_stat(void *field)
  54. {
  55. return *(u64 *) field;
  56. }
  57. static u64 efx_get_atomic_stat(void *field)
  58. {
  59. return atomic_read((atomic_t *) field);
  60. }
  61. #define EFX_ETHTOOL_ULONG_MAC_STAT(field) \
  62. EFX_ETHTOOL_STAT(field, mac_stats, field, \
  63. unsigned long, efx_get_ulong_stat)
  64. #define EFX_ETHTOOL_U64_MAC_STAT(field) \
  65. EFX_ETHTOOL_STAT(field, mac_stats, field, \
  66. u64, efx_get_u64_stat)
  67. #define EFX_ETHTOOL_UINT_NIC_STAT(name) \
  68. EFX_ETHTOOL_STAT(name, nic, n_##name, \
  69. unsigned int, efx_get_uint_stat)
  70. #define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field) \
  71. EFX_ETHTOOL_STAT(field, nic, field, \
  72. atomic_t, efx_get_atomic_stat)
  73. #define EFX_ETHTOOL_UINT_CHANNEL_STAT(field) \
  74. EFX_ETHTOOL_STAT(field, channel, n_##field, \
  75. unsigned int, efx_get_uint_stat)
  76. static struct efx_ethtool_stat efx_ethtool_stats[] = {
  77. EFX_ETHTOOL_U64_MAC_STAT(tx_bytes),
  78. EFX_ETHTOOL_U64_MAC_STAT(tx_good_bytes),
  79. EFX_ETHTOOL_U64_MAC_STAT(tx_bad_bytes),
  80. EFX_ETHTOOL_ULONG_MAC_STAT(tx_packets),
  81. EFX_ETHTOOL_ULONG_MAC_STAT(tx_bad),
  82. EFX_ETHTOOL_ULONG_MAC_STAT(tx_pause),
  83. EFX_ETHTOOL_ULONG_MAC_STAT(tx_control),
  84. EFX_ETHTOOL_ULONG_MAC_STAT(tx_unicast),
  85. EFX_ETHTOOL_ULONG_MAC_STAT(tx_multicast),
  86. EFX_ETHTOOL_ULONG_MAC_STAT(tx_broadcast),
  87. EFX_ETHTOOL_ULONG_MAC_STAT(tx_lt64),
  88. EFX_ETHTOOL_ULONG_MAC_STAT(tx_64),
  89. EFX_ETHTOOL_ULONG_MAC_STAT(tx_65_to_127),
  90. EFX_ETHTOOL_ULONG_MAC_STAT(tx_128_to_255),
  91. EFX_ETHTOOL_ULONG_MAC_STAT(tx_256_to_511),
  92. EFX_ETHTOOL_ULONG_MAC_STAT(tx_512_to_1023),
  93. EFX_ETHTOOL_ULONG_MAC_STAT(tx_1024_to_15xx),
  94. EFX_ETHTOOL_ULONG_MAC_STAT(tx_15xx_to_jumbo),
  95. EFX_ETHTOOL_ULONG_MAC_STAT(tx_gtjumbo),
  96. EFX_ETHTOOL_ULONG_MAC_STAT(tx_collision),
  97. EFX_ETHTOOL_ULONG_MAC_STAT(tx_single_collision),
  98. EFX_ETHTOOL_ULONG_MAC_STAT(tx_multiple_collision),
  99. EFX_ETHTOOL_ULONG_MAC_STAT(tx_excessive_collision),
  100. EFX_ETHTOOL_ULONG_MAC_STAT(tx_deferred),
  101. EFX_ETHTOOL_ULONG_MAC_STAT(tx_late_collision),
  102. EFX_ETHTOOL_ULONG_MAC_STAT(tx_excessive_deferred),
  103. EFX_ETHTOOL_ULONG_MAC_STAT(tx_non_tcpudp),
  104. EFX_ETHTOOL_ULONG_MAC_STAT(tx_mac_src_error),
  105. EFX_ETHTOOL_ULONG_MAC_STAT(tx_ip_src_error),
  106. EFX_ETHTOOL_U64_MAC_STAT(rx_bytes),
  107. EFX_ETHTOOL_U64_MAC_STAT(rx_good_bytes),
  108. EFX_ETHTOOL_U64_MAC_STAT(rx_bad_bytes),
  109. EFX_ETHTOOL_ULONG_MAC_STAT(rx_packets),
  110. EFX_ETHTOOL_ULONG_MAC_STAT(rx_good),
  111. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad),
  112. EFX_ETHTOOL_ULONG_MAC_STAT(rx_pause),
  113. EFX_ETHTOOL_ULONG_MAC_STAT(rx_control),
  114. EFX_ETHTOOL_ULONG_MAC_STAT(rx_unicast),
  115. EFX_ETHTOOL_ULONG_MAC_STAT(rx_multicast),
  116. EFX_ETHTOOL_ULONG_MAC_STAT(rx_broadcast),
  117. EFX_ETHTOOL_ULONG_MAC_STAT(rx_lt64),
  118. EFX_ETHTOOL_ULONG_MAC_STAT(rx_64),
  119. EFX_ETHTOOL_ULONG_MAC_STAT(rx_65_to_127),
  120. EFX_ETHTOOL_ULONG_MAC_STAT(rx_128_to_255),
  121. EFX_ETHTOOL_ULONG_MAC_STAT(rx_256_to_511),
  122. EFX_ETHTOOL_ULONG_MAC_STAT(rx_512_to_1023),
  123. EFX_ETHTOOL_ULONG_MAC_STAT(rx_1024_to_15xx),
  124. EFX_ETHTOOL_ULONG_MAC_STAT(rx_15xx_to_jumbo),
  125. EFX_ETHTOOL_ULONG_MAC_STAT(rx_gtjumbo),
  126. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_lt64),
  127. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_64_to_15xx),
  128. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_15xx_to_jumbo),
  129. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_gtjumbo),
  130. EFX_ETHTOOL_ULONG_MAC_STAT(rx_overflow),
  131. EFX_ETHTOOL_ULONG_MAC_STAT(rx_missed),
  132. EFX_ETHTOOL_ULONG_MAC_STAT(rx_false_carrier),
  133. EFX_ETHTOOL_ULONG_MAC_STAT(rx_symbol_error),
  134. EFX_ETHTOOL_ULONG_MAC_STAT(rx_align_error),
  135. EFX_ETHTOOL_ULONG_MAC_STAT(rx_length_error),
  136. EFX_ETHTOOL_ULONG_MAC_STAT(rx_internal_error),
  137. EFX_ETHTOOL_UINT_NIC_STAT(rx_nodesc_drop_cnt),
  138. EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset),
  139. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc),
  140. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),
  141. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err),
  142. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch),
  143. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
  144. };
  145. /* Number of ethtool statistics */
  146. #define EFX_ETHTOOL_NUM_STATS ARRAY_SIZE(efx_ethtool_stats)
  147. #define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB
  148. /**************************************************************************
  149. *
  150. * Ethtool operations
  151. *
  152. **************************************************************************
  153. */
  154. /* Identify device by flashing LEDs */
  155. static int efx_ethtool_phys_id(struct net_device *net_dev, u32 count)
  156. {
  157. struct efx_nic *efx = netdev_priv(net_dev);
  158. do {
  159. efx->type->set_id_led(efx, EFX_LED_ON);
  160. schedule_timeout_interruptible(HZ / 2);
  161. efx->type->set_id_led(efx, EFX_LED_OFF);
  162. schedule_timeout_interruptible(HZ / 2);
  163. } while (!signal_pending(current) && --count != 0);
  164. efx->type->set_id_led(efx, EFX_LED_DEFAULT);
  165. return 0;
  166. }
  167. /* This must be called with rtnl_lock held. */
  168. static int efx_ethtool_get_settings(struct net_device *net_dev,
  169. struct ethtool_cmd *ecmd)
  170. {
  171. struct efx_nic *efx = netdev_priv(net_dev);
  172. struct efx_link_state *link_state = &efx->link_state;
  173. mutex_lock(&efx->mac_lock);
  174. efx->phy_op->get_settings(efx, ecmd);
  175. mutex_unlock(&efx->mac_lock);
  176. /* GMAC does not support 1000Mbps HD */
  177. ecmd->supported &= ~SUPPORTED_1000baseT_Half;
  178. /* Both MACs support pause frames (bidirectional and respond-only) */
  179. ecmd->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
  180. if (LOOPBACK_INTERNAL(efx)) {
  181. ecmd->speed = link_state->speed;
  182. ecmd->duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF;
  183. }
  184. return 0;
  185. }
  186. /* This must be called with rtnl_lock held. */
  187. static int efx_ethtool_set_settings(struct net_device *net_dev,
  188. struct ethtool_cmd *ecmd)
  189. {
  190. struct efx_nic *efx = netdev_priv(net_dev);
  191. int rc;
  192. /* GMAC does not support 1000Mbps HD */
  193. if (ecmd->speed == SPEED_1000 && ecmd->duplex != DUPLEX_FULL) {
  194. netif_dbg(efx, drv, efx->net_dev,
  195. "rejecting unsupported 1000Mbps HD setting\n");
  196. return -EINVAL;
  197. }
  198. mutex_lock(&efx->mac_lock);
  199. rc = efx->phy_op->set_settings(efx, ecmd);
  200. mutex_unlock(&efx->mac_lock);
  201. return rc;
  202. }
  203. static void efx_ethtool_get_drvinfo(struct net_device *net_dev,
  204. struct ethtool_drvinfo *info)
  205. {
  206. struct efx_nic *efx = netdev_priv(net_dev);
  207. strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
  208. strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version));
  209. if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0)
  210. siena_print_fwver(efx, info->fw_version,
  211. sizeof(info->fw_version));
  212. strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
  213. }
  214. static int efx_ethtool_get_regs_len(struct net_device *net_dev)
  215. {
  216. return efx_nic_get_regs_len(netdev_priv(net_dev));
  217. }
  218. static void efx_ethtool_get_regs(struct net_device *net_dev,
  219. struct ethtool_regs *regs, void *buf)
  220. {
  221. struct efx_nic *efx = netdev_priv(net_dev);
  222. regs->version = efx->type->revision;
  223. efx_nic_get_regs(efx, buf);
  224. }
  225. static u32 efx_ethtool_get_msglevel(struct net_device *net_dev)
  226. {
  227. struct efx_nic *efx = netdev_priv(net_dev);
  228. return efx->msg_enable;
  229. }
  230. static void efx_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable)
  231. {
  232. struct efx_nic *efx = netdev_priv(net_dev);
  233. efx->msg_enable = msg_enable;
  234. }
  235. /**
  236. * efx_fill_test - fill in an individual self-test entry
  237. * @test_index: Index of the test
  238. * @strings: Ethtool strings, or %NULL
  239. * @data: Ethtool test results, or %NULL
  240. * @test: Pointer to test result (used only if data != %NULL)
  241. * @unit_format: Unit name format (e.g. "chan\%d")
  242. * @unit_id: Unit id (e.g. 0 for "chan0")
  243. * @test_format: Test name format (e.g. "loopback.\%s.tx.sent")
  244. * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
  245. *
  246. * Fill in an individual self-test entry.
  247. */
  248. static void efx_fill_test(unsigned int test_index,
  249. struct ethtool_string *strings, u64 *data,
  250. int *test, const char *unit_format, int unit_id,
  251. const char *test_format, const char *test_id)
  252. {
  253. struct ethtool_string unit_str, test_str;
  254. /* Fill data value, if applicable */
  255. if (data)
  256. data[test_index] = *test;
  257. /* Fill string, if applicable */
  258. if (strings) {
  259. if (strchr(unit_format, '%'))
  260. snprintf(unit_str.name, sizeof(unit_str.name),
  261. unit_format, unit_id);
  262. else
  263. strcpy(unit_str.name, unit_format);
  264. snprintf(test_str.name, sizeof(test_str.name),
  265. test_format, test_id);
  266. snprintf(strings[test_index].name,
  267. sizeof(strings[test_index].name),
  268. "%-6s %-24s", unit_str.name, test_str.name);
  269. }
  270. }
  271. #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
  272. #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
  273. #define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
  274. #define EFX_LOOPBACK_NAME(_mode, _counter) \
  275. "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode)
  276. /**
  277. * efx_fill_loopback_test - fill in a block of loopback self-test entries
  278. * @efx: Efx NIC
  279. * @lb_tests: Efx loopback self-test results structure
  280. * @mode: Loopback test mode
  281. * @test_index: Starting index of the test
  282. * @strings: Ethtool strings, or %NULL
  283. * @data: Ethtool test results, or %NULL
  284. */
  285. static int efx_fill_loopback_test(struct efx_nic *efx,
  286. struct efx_loopback_self_tests *lb_tests,
  287. enum efx_loopback_mode mode,
  288. unsigned int test_index,
  289. struct ethtool_string *strings, u64 *data)
  290. {
  291. struct efx_channel *channel = efx_get_channel(efx, 0);
  292. struct efx_tx_queue *tx_queue;
  293. efx_for_each_channel_tx_queue(tx_queue, channel) {
  294. efx_fill_test(test_index++, strings, data,
  295. &lb_tests->tx_sent[tx_queue->queue],
  296. EFX_TX_QUEUE_NAME(tx_queue),
  297. EFX_LOOPBACK_NAME(mode, "tx_sent"));
  298. efx_fill_test(test_index++, strings, data,
  299. &lb_tests->tx_done[tx_queue->queue],
  300. EFX_TX_QUEUE_NAME(tx_queue),
  301. EFX_LOOPBACK_NAME(mode, "tx_done"));
  302. }
  303. efx_fill_test(test_index++, strings, data,
  304. &lb_tests->rx_good,
  305. "rx", 0,
  306. EFX_LOOPBACK_NAME(mode, "rx_good"));
  307. efx_fill_test(test_index++, strings, data,
  308. &lb_tests->rx_bad,
  309. "rx", 0,
  310. EFX_LOOPBACK_NAME(mode, "rx_bad"));
  311. return test_index;
  312. }
  313. /**
  314. * efx_ethtool_fill_self_tests - get self-test details
  315. * @efx: Efx NIC
  316. * @tests: Efx self-test results structure, or %NULL
  317. * @strings: Ethtool strings, or %NULL
  318. * @data: Ethtool test results, or %NULL
  319. */
  320. static int efx_ethtool_fill_self_tests(struct efx_nic *efx,
  321. struct efx_self_tests *tests,
  322. struct ethtool_string *strings,
  323. u64 *data)
  324. {
  325. struct efx_channel *channel;
  326. unsigned int n = 0, i;
  327. enum efx_loopback_mode mode;
  328. efx_fill_test(n++, strings, data, &tests->phy_alive,
  329. "phy", 0, "alive", NULL);
  330. efx_fill_test(n++, strings, data, &tests->nvram,
  331. "core", 0, "nvram", NULL);
  332. efx_fill_test(n++, strings, data, &tests->interrupt,
  333. "core", 0, "interrupt", NULL);
  334. /* Event queues */
  335. efx_for_each_channel(channel, efx) {
  336. efx_fill_test(n++, strings, data,
  337. &tests->eventq_dma[channel->channel],
  338. EFX_CHANNEL_NAME(channel),
  339. "eventq.dma", NULL);
  340. efx_fill_test(n++, strings, data,
  341. &tests->eventq_int[channel->channel],
  342. EFX_CHANNEL_NAME(channel),
  343. "eventq.int", NULL);
  344. efx_fill_test(n++, strings, data,
  345. &tests->eventq_poll[channel->channel],
  346. EFX_CHANNEL_NAME(channel),
  347. "eventq.poll", NULL);
  348. }
  349. efx_fill_test(n++, strings, data, &tests->registers,
  350. "core", 0, "registers", NULL);
  351. if (efx->phy_op->run_tests != NULL) {
  352. EFX_BUG_ON_PARANOID(efx->phy_op->test_name == NULL);
  353. for (i = 0; true; ++i) {
  354. const char *name;
  355. EFX_BUG_ON_PARANOID(i >= EFX_MAX_PHY_TESTS);
  356. name = efx->phy_op->test_name(efx, i);
  357. if (name == NULL)
  358. break;
  359. efx_fill_test(n++, strings, data, &tests->phy_ext[i],
  360. "phy", 0, name, NULL);
  361. }
  362. }
  363. /* Loopback tests */
  364. for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
  365. if (!(efx->loopback_modes & (1 << mode)))
  366. continue;
  367. n = efx_fill_loopback_test(efx,
  368. &tests->loopback[mode], mode, n,
  369. strings, data);
  370. }
  371. return n;
  372. }
  373. static int efx_ethtool_get_sset_count(struct net_device *net_dev,
  374. int string_set)
  375. {
  376. switch (string_set) {
  377. case ETH_SS_STATS:
  378. return EFX_ETHTOOL_NUM_STATS;
  379. case ETH_SS_TEST:
  380. return efx_ethtool_fill_self_tests(netdev_priv(net_dev),
  381. NULL, NULL, NULL);
  382. default:
  383. return -EINVAL;
  384. }
  385. }
  386. static void efx_ethtool_get_strings(struct net_device *net_dev,
  387. u32 string_set, u8 *strings)
  388. {
  389. struct efx_nic *efx = netdev_priv(net_dev);
  390. struct ethtool_string *ethtool_strings =
  391. (struct ethtool_string *)strings;
  392. int i;
  393. switch (string_set) {
  394. case ETH_SS_STATS:
  395. for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++)
  396. strncpy(ethtool_strings[i].name,
  397. efx_ethtool_stats[i].name,
  398. sizeof(ethtool_strings[i].name));
  399. break;
  400. case ETH_SS_TEST:
  401. efx_ethtool_fill_self_tests(efx, NULL,
  402. ethtool_strings, NULL);
  403. break;
  404. default:
  405. /* No other string sets */
  406. break;
  407. }
  408. }
  409. static void efx_ethtool_get_stats(struct net_device *net_dev,
  410. struct ethtool_stats *stats,
  411. u64 *data)
  412. {
  413. struct efx_nic *efx = netdev_priv(net_dev);
  414. struct efx_mac_stats *mac_stats = &efx->mac_stats;
  415. struct efx_ethtool_stat *stat;
  416. struct efx_channel *channel;
  417. struct rtnl_link_stats64 temp;
  418. int i;
  419. EFX_BUG_ON_PARANOID(stats->n_stats != EFX_ETHTOOL_NUM_STATS);
  420. /* Update MAC and NIC statistics */
  421. dev_get_stats(net_dev, &temp);
  422. /* Fill detailed statistics buffer */
  423. for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++) {
  424. stat = &efx_ethtool_stats[i];
  425. switch (stat->source) {
  426. case EFX_ETHTOOL_STAT_SOURCE_mac_stats:
  427. data[i] = stat->get_stat((void *)mac_stats +
  428. stat->offset);
  429. break;
  430. case EFX_ETHTOOL_STAT_SOURCE_nic:
  431. data[i] = stat->get_stat((void *)efx + stat->offset);
  432. break;
  433. case EFX_ETHTOOL_STAT_SOURCE_channel:
  434. data[i] = 0;
  435. efx_for_each_channel(channel, efx)
  436. data[i] += stat->get_stat((void *)channel +
  437. stat->offset);
  438. break;
  439. }
  440. }
  441. }
  442. static int efx_ethtool_set_tso(struct net_device *net_dev, u32 enable)
  443. {
  444. struct efx_nic *efx __attribute__ ((unused)) = netdev_priv(net_dev);
  445. unsigned long features;
  446. features = NETIF_F_TSO;
  447. if (efx->type->offload_features & NETIF_F_V6_CSUM)
  448. features |= NETIF_F_TSO6;
  449. if (enable)
  450. net_dev->features |= features;
  451. else
  452. net_dev->features &= ~features;
  453. return 0;
  454. }
  455. static int efx_ethtool_set_tx_csum(struct net_device *net_dev, u32 enable)
  456. {
  457. struct efx_nic *efx = netdev_priv(net_dev);
  458. unsigned long features = efx->type->offload_features & NETIF_F_ALL_CSUM;
  459. if (enable)
  460. net_dev->features |= features;
  461. else
  462. net_dev->features &= ~features;
  463. return 0;
  464. }
  465. static int efx_ethtool_set_rx_csum(struct net_device *net_dev, u32 enable)
  466. {
  467. struct efx_nic *efx = netdev_priv(net_dev);
  468. /* No way to stop the hardware doing the checks; we just
  469. * ignore the result.
  470. */
  471. efx->rx_checksum_enabled = !!enable;
  472. return 0;
  473. }
  474. static u32 efx_ethtool_get_rx_csum(struct net_device *net_dev)
  475. {
  476. struct efx_nic *efx = netdev_priv(net_dev);
  477. return efx->rx_checksum_enabled;
  478. }
  479. static int efx_ethtool_set_flags(struct net_device *net_dev, u32 data)
  480. {
  481. struct efx_nic *efx = netdev_priv(net_dev);
  482. u32 supported = (efx->type->offload_features &
  483. (ETH_FLAG_RXHASH | ETH_FLAG_NTUPLE));
  484. int rc;
  485. rc = ethtool_op_set_flags(net_dev, data, supported);
  486. if (rc)
  487. return rc;
  488. if (!(data & ETH_FLAG_NTUPLE)) {
  489. efx_filter_table_clear(efx, EFX_FILTER_TABLE_RX_IP,
  490. EFX_FILTER_PRI_MANUAL);
  491. efx_filter_table_clear(efx, EFX_FILTER_TABLE_RX_MAC,
  492. EFX_FILTER_PRI_MANUAL);
  493. }
  494. return 0;
  495. }
  496. static void efx_ethtool_self_test(struct net_device *net_dev,
  497. struct ethtool_test *test, u64 *data)
  498. {
  499. struct efx_nic *efx = netdev_priv(net_dev);
  500. struct efx_self_tests efx_tests;
  501. int already_up;
  502. int rc;
  503. ASSERT_RTNL();
  504. if (efx->state != STATE_RUNNING) {
  505. rc = -EIO;
  506. goto fail1;
  507. }
  508. /* We need rx buffers and interrupts. */
  509. already_up = (efx->net_dev->flags & IFF_UP);
  510. if (!already_up) {
  511. rc = dev_open(efx->net_dev);
  512. if (rc) {
  513. netif_err(efx, drv, efx->net_dev,
  514. "failed opening device.\n");
  515. goto fail2;
  516. }
  517. }
  518. memset(&efx_tests, 0, sizeof(efx_tests));
  519. rc = efx_selftest(efx, &efx_tests, test->flags);
  520. if (!already_up)
  521. dev_close(efx->net_dev);
  522. netif_dbg(efx, drv, efx->net_dev, "%s %sline self-tests\n",
  523. rc == 0 ? "passed" : "failed",
  524. (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
  525. fail2:
  526. fail1:
  527. /* Fill ethtool results structures */
  528. efx_ethtool_fill_self_tests(efx, &efx_tests, NULL, data);
  529. if (rc)
  530. test->flags |= ETH_TEST_FL_FAILED;
  531. }
  532. /* Restart autonegotiation */
  533. static int efx_ethtool_nway_reset(struct net_device *net_dev)
  534. {
  535. struct efx_nic *efx = netdev_priv(net_dev);
  536. return mdio45_nway_restart(&efx->mdio);
  537. }
  538. static u32 efx_ethtool_get_link(struct net_device *net_dev)
  539. {
  540. struct efx_nic *efx = netdev_priv(net_dev);
  541. return efx->link_state.up;
  542. }
  543. static int efx_ethtool_get_eeprom_len(struct net_device *net_dev)
  544. {
  545. struct efx_nic *efx = netdev_priv(net_dev);
  546. struct efx_spi_device *spi = efx->spi_eeprom;
  547. if (!spi)
  548. return 0;
  549. return min(spi->size, EFX_EEPROM_BOOTCONFIG_END) -
  550. min(spi->size, EFX_EEPROM_BOOTCONFIG_START);
  551. }
  552. static int efx_ethtool_get_eeprom(struct net_device *net_dev,
  553. struct ethtool_eeprom *eeprom, u8 *buf)
  554. {
  555. struct efx_nic *efx = netdev_priv(net_dev);
  556. struct efx_spi_device *spi = efx->spi_eeprom;
  557. size_t len;
  558. int rc;
  559. rc = mutex_lock_interruptible(&efx->spi_lock);
  560. if (rc)
  561. return rc;
  562. rc = falcon_spi_read(efx, spi,
  563. eeprom->offset + EFX_EEPROM_BOOTCONFIG_START,
  564. eeprom->len, &len, buf);
  565. mutex_unlock(&efx->spi_lock);
  566. eeprom->magic = EFX_ETHTOOL_EEPROM_MAGIC;
  567. eeprom->len = len;
  568. return rc;
  569. }
  570. static int efx_ethtool_set_eeprom(struct net_device *net_dev,
  571. struct ethtool_eeprom *eeprom, u8 *buf)
  572. {
  573. struct efx_nic *efx = netdev_priv(net_dev);
  574. struct efx_spi_device *spi = efx->spi_eeprom;
  575. size_t len;
  576. int rc;
  577. if (eeprom->magic != EFX_ETHTOOL_EEPROM_MAGIC)
  578. return -EINVAL;
  579. rc = mutex_lock_interruptible(&efx->spi_lock);
  580. if (rc)
  581. return rc;
  582. rc = falcon_spi_write(efx, spi,
  583. eeprom->offset + EFX_EEPROM_BOOTCONFIG_START,
  584. eeprom->len, &len, buf);
  585. mutex_unlock(&efx->spi_lock);
  586. eeprom->len = len;
  587. return rc;
  588. }
  589. static int efx_ethtool_get_coalesce(struct net_device *net_dev,
  590. struct ethtool_coalesce *coalesce)
  591. {
  592. struct efx_nic *efx = netdev_priv(net_dev);
  593. struct efx_channel *channel;
  594. memset(coalesce, 0, sizeof(*coalesce));
  595. /* Find lowest IRQ moderation across all used TX queues */
  596. coalesce->tx_coalesce_usecs_irq = ~((u32) 0);
  597. efx_for_each_channel(channel, efx) {
  598. if (!efx_channel_get_tx_queue(channel, 0))
  599. continue;
  600. if (channel->irq_moderation < coalesce->tx_coalesce_usecs_irq) {
  601. if (channel->channel < efx->n_rx_channels)
  602. coalesce->tx_coalesce_usecs_irq =
  603. channel->irq_moderation;
  604. else
  605. coalesce->tx_coalesce_usecs_irq = 0;
  606. }
  607. }
  608. coalesce->use_adaptive_rx_coalesce = efx->irq_rx_adaptive;
  609. coalesce->rx_coalesce_usecs_irq = efx->irq_rx_moderation;
  610. coalesce->tx_coalesce_usecs_irq *= EFX_IRQ_MOD_RESOLUTION;
  611. coalesce->rx_coalesce_usecs_irq *= EFX_IRQ_MOD_RESOLUTION;
  612. return 0;
  613. }
  614. /* Set coalescing parameters
  615. * The difficulties occur for shared channels
  616. */
  617. static int efx_ethtool_set_coalesce(struct net_device *net_dev,
  618. struct ethtool_coalesce *coalesce)
  619. {
  620. struct efx_nic *efx = netdev_priv(net_dev);
  621. struct efx_channel *channel;
  622. unsigned tx_usecs, rx_usecs, adaptive;
  623. if (coalesce->use_adaptive_tx_coalesce)
  624. return -EOPNOTSUPP;
  625. if (coalesce->rx_coalesce_usecs || coalesce->tx_coalesce_usecs) {
  626. netif_err(efx, drv, efx->net_dev, "invalid coalescing setting. "
  627. "Only rx/tx_coalesce_usecs_irq are supported\n");
  628. return -EOPNOTSUPP;
  629. }
  630. rx_usecs = coalesce->rx_coalesce_usecs_irq;
  631. tx_usecs = coalesce->tx_coalesce_usecs_irq;
  632. adaptive = coalesce->use_adaptive_rx_coalesce;
  633. /* If the channel is shared only allow RX parameters to be set */
  634. efx_for_each_channel(channel, efx) {
  635. if (efx_channel_get_rx_queue(channel) &&
  636. efx_channel_get_tx_queue(channel, 0) &&
  637. tx_usecs) {
  638. netif_err(efx, drv, efx->net_dev, "Channel is shared. "
  639. "Only RX coalescing may be set\n");
  640. return -EOPNOTSUPP;
  641. }
  642. }
  643. efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive);
  644. efx_for_each_channel(channel, efx)
  645. efx->type->push_irq_moderation(channel);
  646. return 0;
  647. }
  648. static void efx_ethtool_get_ringparam(struct net_device *net_dev,
  649. struct ethtool_ringparam *ring)
  650. {
  651. struct efx_nic *efx = netdev_priv(net_dev);
  652. ring->rx_max_pending = EFX_MAX_DMAQ_SIZE;
  653. ring->tx_max_pending = EFX_MAX_DMAQ_SIZE;
  654. ring->rx_mini_max_pending = 0;
  655. ring->rx_jumbo_max_pending = 0;
  656. ring->rx_pending = efx->rxq_entries;
  657. ring->tx_pending = efx->txq_entries;
  658. ring->rx_mini_pending = 0;
  659. ring->rx_jumbo_pending = 0;
  660. }
  661. static int efx_ethtool_set_ringparam(struct net_device *net_dev,
  662. struct ethtool_ringparam *ring)
  663. {
  664. struct efx_nic *efx = netdev_priv(net_dev);
  665. if (ring->rx_mini_pending || ring->rx_jumbo_pending ||
  666. ring->rx_pending > EFX_MAX_DMAQ_SIZE ||
  667. ring->tx_pending > EFX_MAX_DMAQ_SIZE)
  668. return -EINVAL;
  669. if (ring->rx_pending < EFX_MIN_RING_SIZE ||
  670. ring->tx_pending < EFX_MIN_RING_SIZE) {
  671. netif_err(efx, drv, efx->net_dev,
  672. "TX and RX queues cannot be smaller than %ld\n",
  673. EFX_MIN_RING_SIZE);
  674. return -EINVAL;
  675. }
  676. return efx_realloc_channels(efx, ring->rx_pending, ring->tx_pending);
  677. }
  678. static int efx_ethtool_set_pauseparam(struct net_device *net_dev,
  679. struct ethtool_pauseparam *pause)
  680. {
  681. struct efx_nic *efx = netdev_priv(net_dev);
  682. enum efx_fc_type wanted_fc, old_fc;
  683. u32 old_adv;
  684. bool reset;
  685. int rc = 0;
  686. mutex_lock(&efx->mac_lock);
  687. wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
  688. (pause->tx_pause ? EFX_FC_TX : 0) |
  689. (pause->autoneg ? EFX_FC_AUTO : 0));
  690. if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
  691. netif_dbg(efx, drv, efx->net_dev,
  692. "Flow control unsupported: tx ON rx OFF\n");
  693. rc = -EINVAL;
  694. goto out;
  695. }
  696. if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising) {
  697. netif_dbg(efx, drv, efx->net_dev,
  698. "Autonegotiation is disabled\n");
  699. rc = -EINVAL;
  700. goto out;
  701. }
  702. /* TX flow control may automatically turn itself off if the
  703. * link partner (intermittently) stops responding to pause
  704. * frames. There isn't any indication that this has happened,
  705. * so the best we do is leave it up to the user to spot this
  706. * and fix it be cycling transmit flow control on this end. */
  707. reset = (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX);
  708. if (EFX_WORKAROUND_11482(efx) && reset) {
  709. if (efx_nic_rev(efx) == EFX_REV_FALCON_B0) {
  710. /* Recover by resetting the EM block */
  711. falcon_stop_nic_stats(efx);
  712. falcon_drain_tx_fifo(efx);
  713. efx->mac_op->reconfigure(efx);
  714. falcon_start_nic_stats(efx);
  715. } else {
  716. /* Schedule a reset to recover */
  717. efx_schedule_reset(efx, RESET_TYPE_INVISIBLE);
  718. }
  719. }
  720. old_adv = efx->link_advertising;
  721. old_fc = efx->wanted_fc;
  722. efx_link_set_wanted_fc(efx, wanted_fc);
  723. if (efx->link_advertising != old_adv ||
  724. (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) {
  725. rc = efx->phy_op->reconfigure(efx);
  726. if (rc) {
  727. netif_err(efx, drv, efx->net_dev,
  728. "Unable to advertise requested flow "
  729. "control setting\n");
  730. goto out;
  731. }
  732. }
  733. /* Reconfigure the MAC. The PHY *may* generate a link state change event
  734. * if the user just changed the advertised capabilities, but there's no
  735. * harm doing this twice */
  736. efx->mac_op->reconfigure(efx);
  737. out:
  738. mutex_unlock(&efx->mac_lock);
  739. return rc;
  740. }
  741. static void efx_ethtool_get_pauseparam(struct net_device *net_dev,
  742. struct ethtool_pauseparam *pause)
  743. {
  744. struct efx_nic *efx = netdev_priv(net_dev);
  745. pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX);
  746. pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX);
  747. pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO);
  748. }
  749. static void efx_ethtool_get_wol(struct net_device *net_dev,
  750. struct ethtool_wolinfo *wol)
  751. {
  752. struct efx_nic *efx = netdev_priv(net_dev);
  753. return efx->type->get_wol(efx, wol);
  754. }
  755. static int efx_ethtool_set_wol(struct net_device *net_dev,
  756. struct ethtool_wolinfo *wol)
  757. {
  758. struct efx_nic *efx = netdev_priv(net_dev);
  759. return efx->type->set_wol(efx, wol->wolopts);
  760. }
  761. static int efx_ethtool_reset(struct net_device *net_dev, u32 *flags)
  762. {
  763. struct efx_nic *efx = netdev_priv(net_dev);
  764. enum reset_type method;
  765. enum {
  766. ETH_RESET_EFX_INVISIBLE = (ETH_RESET_DMA | ETH_RESET_FILTER |
  767. ETH_RESET_OFFLOAD | ETH_RESET_MAC)
  768. };
  769. /* Check for minimal reset flags */
  770. if ((*flags & ETH_RESET_EFX_INVISIBLE) != ETH_RESET_EFX_INVISIBLE)
  771. return -EINVAL;
  772. *flags ^= ETH_RESET_EFX_INVISIBLE;
  773. method = RESET_TYPE_INVISIBLE;
  774. if (*flags & ETH_RESET_PHY) {
  775. *flags ^= ETH_RESET_PHY;
  776. method = RESET_TYPE_ALL;
  777. }
  778. if ((*flags & efx->type->reset_world_flags) ==
  779. efx->type->reset_world_flags) {
  780. *flags ^= efx->type->reset_world_flags;
  781. method = RESET_TYPE_WORLD;
  782. }
  783. return efx_reset(efx, method);
  784. }
  785. static int
  786. efx_ethtool_get_rxnfc(struct net_device *net_dev,
  787. struct ethtool_rxnfc *info, void *rules __always_unused)
  788. {
  789. struct efx_nic *efx = netdev_priv(net_dev);
  790. switch (info->cmd) {
  791. case ETHTOOL_GRXRINGS:
  792. info->data = efx->n_rx_channels;
  793. return 0;
  794. case ETHTOOL_GRXFH: {
  795. unsigned min_revision = 0;
  796. info->data = 0;
  797. switch (info->flow_type) {
  798. case TCP_V4_FLOW:
  799. info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  800. /* fall through */
  801. case UDP_V4_FLOW:
  802. case SCTP_V4_FLOW:
  803. case AH_ESP_V4_FLOW:
  804. case IPV4_FLOW:
  805. info->data |= RXH_IP_SRC | RXH_IP_DST;
  806. min_revision = EFX_REV_FALCON_B0;
  807. break;
  808. case TCP_V6_FLOW:
  809. info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  810. /* fall through */
  811. case UDP_V6_FLOW:
  812. case SCTP_V6_FLOW:
  813. case AH_ESP_V6_FLOW:
  814. case IPV6_FLOW:
  815. info->data |= RXH_IP_SRC | RXH_IP_DST;
  816. min_revision = EFX_REV_SIENA_A0;
  817. break;
  818. default:
  819. break;
  820. }
  821. if (efx_nic_rev(efx) < min_revision)
  822. info->data = 0;
  823. return 0;
  824. }
  825. default:
  826. return -EOPNOTSUPP;
  827. }
  828. }
  829. static int efx_ethtool_set_rx_ntuple(struct net_device *net_dev,
  830. struct ethtool_rx_ntuple *ntuple)
  831. {
  832. struct efx_nic *efx = netdev_priv(net_dev);
  833. struct ethtool_tcpip4_spec *ip_entry = &ntuple->fs.h_u.tcp_ip4_spec;
  834. struct ethtool_tcpip4_spec *ip_mask = &ntuple->fs.m_u.tcp_ip4_spec;
  835. struct ethhdr *mac_entry = &ntuple->fs.h_u.ether_spec;
  836. struct ethhdr *mac_mask = &ntuple->fs.m_u.ether_spec;
  837. struct efx_filter_spec filter;
  838. /* Range-check action */
  839. if (ntuple->fs.action < ETHTOOL_RXNTUPLE_ACTION_CLEAR ||
  840. ntuple->fs.action >= (s32)efx->n_rx_channels)
  841. return -EINVAL;
  842. if (~ntuple->fs.data_mask)
  843. return -EINVAL;
  844. switch (ntuple->fs.flow_type) {
  845. case TCP_V4_FLOW:
  846. case UDP_V4_FLOW:
  847. /* Must match all of destination, */
  848. if (ip_mask->ip4dst | ip_mask->pdst)
  849. return -EINVAL;
  850. /* all or none of source, */
  851. if ((ip_mask->ip4src | ip_mask->psrc) &&
  852. ((__force u32)~ip_mask->ip4src |
  853. (__force u16)~ip_mask->psrc))
  854. return -EINVAL;
  855. /* and nothing else */
  856. if ((u8)~ip_mask->tos | (u16)~ntuple->fs.vlan_tag_mask)
  857. return -EINVAL;
  858. break;
  859. case ETHER_FLOW:
  860. /* Must match all of destination, */
  861. if (!is_zero_ether_addr(mac_mask->h_dest))
  862. return -EINVAL;
  863. /* all or none of VID, */
  864. if (ntuple->fs.vlan_tag_mask != 0xf000 &&
  865. ntuple->fs.vlan_tag_mask != 0xffff)
  866. return -EINVAL;
  867. /* and nothing else */
  868. if (!is_broadcast_ether_addr(mac_mask->h_source) ||
  869. mac_mask->h_proto != htons(0xffff))
  870. return -EINVAL;
  871. break;
  872. default:
  873. return -EINVAL;
  874. }
  875. filter.priority = EFX_FILTER_PRI_MANUAL;
  876. filter.flags = 0;
  877. switch (ntuple->fs.flow_type) {
  878. case TCP_V4_FLOW:
  879. if (!ip_mask->ip4src)
  880. efx_filter_set_rx_tcp_full(&filter,
  881. htonl(ip_entry->ip4src),
  882. htons(ip_entry->psrc),
  883. htonl(ip_entry->ip4dst),
  884. htons(ip_entry->pdst));
  885. else
  886. efx_filter_set_rx_tcp_wild(&filter,
  887. htonl(ip_entry->ip4dst),
  888. htons(ip_entry->pdst));
  889. break;
  890. case UDP_V4_FLOW:
  891. if (!ip_mask->ip4src)
  892. efx_filter_set_rx_udp_full(&filter,
  893. htonl(ip_entry->ip4src),
  894. htons(ip_entry->psrc),
  895. htonl(ip_entry->ip4dst),
  896. htons(ip_entry->pdst));
  897. else
  898. efx_filter_set_rx_udp_wild(&filter,
  899. htonl(ip_entry->ip4dst),
  900. htons(ip_entry->pdst));
  901. break;
  902. case ETHER_FLOW:
  903. if (ntuple->fs.vlan_tag_mask == 0xf000)
  904. efx_filter_set_rx_mac_full(&filter,
  905. ntuple->fs.vlan_tag & 0xfff,
  906. mac_entry->h_dest);
  907. else
  908. efx_filter_set_rx_mac_wild(&filter, mac_entry->h_dest);
  909. break;
  910. }
  911. if (ntuple->fs.action == ETHTOOL_RXNTUPLE_ACTION_CLEAR) {
  912. return efx_filter_remove_filter(efx, &filter);
  913. } else {
  914. if (ntuple->fs.action == ETHTOOL_RXNTUPLE_ACTION_DROP)
  915. filter.dmaq_id = 0xfff;
  916. else
  917. filter.dmaq_id = ntuple->fs.action;
  918. return efx_filter_insert_filter(efx, &filter, true);
  919. }
  920. }
  921. static int efx_ethtool_get_rxfh_indir(struct net_device *net_dev,
  922. struct ethtool_rxfh_indir *indir)
  923. {
  924. struct efx_nic *efx = netdev_priv(net_dev);
  925. size_t copy_size =
  926. min_t(size_t, indir->size, ARRAY_SIZE(efx->rx_indir_table));
  927. if (efx_nic_rev(efx) < EFX_REV_FALCON_B0)
  928. return -EOPNOTSUPP;
  929. indir->size = ARRAY_SIZE(efx->rx_indir_table);
  930. memcpy(indir->ring_index, efx->rx_indir_table,
  931. copy_size * sizeof(indir->ring_index[0]));
  932. return 0;
  933. }
  934. static int efx_ethtool_set_rxfh_indir(struct net_device *net_dev,
  935. const struct ethtool_rxfh_indir *indir)
  936. {
  937. struct efx_nic *efx = netdev_priv(net_dev);
  938. size_t i;
  939. if (efx_nic_rev(efx) < EFX_REV_FALCON_B0)
  940. return -EOPNOTSUPP;
  941. /* Validate size and indices */
  942. if (indir->size != ARRAY_SIZE(efx->rx_indir_table))
  943. return -EINVAL;
  944. for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); i++)
  945. if (indir->ring_index[i] >= efx->n_rx_channels)
  946. return -EINVAL;
  947. memcpy(efx->rx_indir_table, indir->ring_index,
  948. sizeof(efx->rx_indir_table));
  949. efx_nic_push_rx_indir_table(efx);
  950. return 0;
  951. }
  952. const struct ethtool_ops efx_ethtool_ops = {
  953. .get_settings = efx_ethtool_get_settings,
  954. .set_settings = efx_ethtool_set_settings,
  955. .get_drvinfo = efx_ethtool_get_drvinfo,
  956. .get_regs_len = efx_ethtool_get_regs_len,
  957. .get_regs = efx_ethtool_get_regs,
  958. .get_msglevel = efx_ethtool_get_msglevel,
  959. .set_msglevel = efx_ethtool_set_msglevel,
  960. .nway_reset = efx_ethtool_nway_reset,
  961. .get_link = efx_ethtool_get_link,
  962. .get_eeprom_len = efx_ethtool_get_eeprom_len,
  963. .get_eeprom = efx_ethtool_get_eeprom,
  964. .set_eeprom = efx_ethtool_set_eeprom,
  965. .get_coalesce = efx_ethtool_get_coalesce,
  966. .set_coalesce = efx_ethtool_set_coalesce,
  967. .get_ringparam = efx_ethtool_get_ringparam,
  968. .set_ringparam = efx_ethtool_set_ringparam,
  969. .get_pauseparam = efx_ethtool_get_pauseparam,
  970. .set_pauseparam = efx_ethtool_set_pauseparam,
  971. .get_rx_csum = efx_ethtool_get_rx_csum,
  972. .set_rx_csum = efx_ethtool_set_rx_csum,
  973. .get_tx_csum = ethtool_op_get_tx_csum,
  974. /* Need to enable/disable IPv6 too */
  975. .set_tx_csum = efx_ethtool_set_tx_csum,
  976. .get_sg = ethtool_op_get_sg,
  977. .set_sg = ethtool_op_set_sg,
  978. .get_tso = ethtool_op_get_tso,
  979. /* Need to enable/disable TSO-IPv6 too */
  980. .set_tso = efx_ethtool_set_tso,
  981. .get_flags = ethtool_op_get_flags,
  982. .set_flags = efx_ethtool_set_flags,
  983. .get_sset_count = efx_ethtool_get_sset_count,
  984. .self_test = efx_ethtool_self_test,
  985. .get_strings = efx_ethtool_get_strings,
  986. .phys_id = efx_ethtool_phys_id,
  987. .get_ethtool_stats = efx_ethtool_get_stats,
  988. .get_wol = efx_ethtool_get_wol,
  989. .set_wol = efx_ethtool_set_wol,
  990. .reset = efx_ethtool_reset,
  991. .get_rxnfc = efx_ethtool_get_rxnfc,
  992. .set_rx_ntuple = efx_ethtool_set_rx_ntuple,
  993. .get_rxfh_indir = efx_ethtool_get_rxfh_indir,
  994. .set_rxfh_indir = efx_ethtool_set_rxfh_indir,
  995. };