ethtool.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2006-2010 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 <linux/in.h>
  14. #include "net_driver.h"
  15. #include "workarounds.h"
  16. #include "selftest.h"
  17. #include "efx.h"
  18. #include "filter.h"
  19. #include "nic.h"
  20. struct ethtool_string {
  21. char name[ETH_GSTRING_LEN];
  22. };
  23. struct efx_ethtool_stat {
  24. const char *name;
  25. enum {
  26. EFX_ETHTOOL_STAT_SOURCE_mac_stats,
  27. EFX_ETHTOOL_STAT_SOURCE_nic,
  28. EFX_ETHTOOL_STAT_SOURCE_channel,
  29. EFX_ETHTOOL_STAT_SOURCE_tx_queue
  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_u64_stat(void *field)
  50. {
  51. return *(u64 *) field;
  52. }
  53. static u64 efx_get_atomic_stat(void *field)
  54. {
  55. return atomic_read((atomic_t *) field);
  56. }
  57. #define EFX_ETHTOOL_U64_MAC_STAT(field) \
  58. EFX_ETHTOOL_STAT(field, mac_stats, field, \
  59. u64, efx_get_u64_stat)
  60. #define EFX_ETHTOOL_UINT_NIC_STAT(name) \
  61. EFX_ETHTOOL_STAT(name, nic, n_##name, \
  62. unsigned int, efx_get_uint_stat)
  63. #define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field) \
  64. EFX_ETHTOOL_STAT(field, nic, field, \
  65. atomic_t, efx_get_atomic_stat)
  66. #define EFX_ETHTOOL_UINT_CHANNEL_STAT(field) \
  67. EFX_ETHTOOL_STAT(field, channel, n_##field, \
  68. unsigned int, efx_get_uint_stat)
  69. #define EFX_ETHTOOL_UINT_TXQ_STAT(field) \
  70. EFX_ETHTOOL_STAT(tx_##field, tx_queue, field, \
  71. unsigned int, efx_get_uint_stat)
  72. static const struct efx_ethtool_stat efx_ethtool_stats[] = {
  73. EFX_ETHTOOL_U64_MAC_STAT(tx_bytes),
  74. EFX_ETHTOOL_U64_MAC_STAT(tx_good_bytes),
  75. EFX_ETHTOOL_U64_MAC_STAT(tx_bad_bytes),
  76. EFX_ETHTOOL_U64_MAC_STAT(tx_packets),
  77. EFX_ETHTOOL_U64_MAC_STAT(tx_bad),
  78. EFX_ETHTOOL_U64_MAC_STAT(tx_pause),
  79. EFX_ETHTOOL_U64_MAC_STAT(tx_control),
  80. EFX_ETHTOOL_U64_MAC_STAT(tx_unicast),
  81. EFX_ETHTOOL_U64_MAC_STAT(tx_multicast),
  82. EFX_ETHTOOL_U64_MAC_STAT(tx_broadcast),
  83. EFX_ETHTOOL_U64_MAC_STAT(tx_lt64),
  84. EFX_ETHTOOL_U64_MAC_STAT(tx_64),
  85. EFX_ETHTOOL_U64_MAC_STAT(tx_65_to_127),
  86. EFX_ETHTOOL_U64_MAC_STAT(tx_128_to_255),
  87. EFX_ETHTOOL_U64_MAC_STAT(tx_256_to_511),
  88. EFX_ETHTOOL_U64_MAC_STAT(tx_512_to_1023),
  89. EFX_ETHTOOL_U64_MAC_STAT(tx_1024_to_15xx),
  90. EFX_ETHTOOL_U64_MAC_STAT(tx_15xx_to_jumbo),
  91. EFX_ETHTOOL_U64_MAC_STAT(tx_gtjumbo),
  92. EFX_ETHTOOL_U64_MAC_STAT(tx_collision),
  93. EFX_ETHTOOL_U64_MAC_STAT(tx_single_collision),
  94. EFX_ETHTOOL_U64_MAC_STAT(tx_multiple_collision),
  95. EFX_ETHTOOL_U64_MAC_STAT(tx_excessive_collision),
  96. EFX_ETHTOOL_U64_MAC_STAT(tx_deferred),
  97. EFX_ETHTOOL_U64_MAC_STAT(tx_late_collision),
  98. EFX_ETHTOOL_U64_MAC_STAT(tx_excessive_deferred),
  99. EFX_ETHTOOL_U64_MAC_STAT(tx_non_tcpudp),
  100. EFX_ETHTOOL_U64_MAC_STAT(tx_mac_src_error),
  101. EFX_ETHTOOL_U64_MAC_STAT(tx_ip_src_error),
  102. EFX_ETHTOOL_UINT_TXQ_STAT(tso_bursts),
  103. EFX_ETHTOOL_UINT_TXQ_STAT(tso_long_headers),
  104. EFX_ETHTOOL_UINT_TXQ_STAT(tso_packets),
  105. EFX_ETHTOOL_UINT_TXQ_STAT(pushes),
  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_U64_MAC_STAT(rx_packets),
  110. EFX_ETHTOOL_U64_MAC_STAT(rx_good),
  111. EFX_ETHTOOL_U64_MAC_STAT(rx_bad),
  112. EFX_ETHTOOL_U64_MAC_STAT(rx_pause),
  113. EFX_ETHTOOL_U64_MAC_STAT(rx_control),
  114. EFX_ETHTOOL_U64_MAC_STAT(rx_unicast),
  115. EFX_ETHTOOL_U64_MAC_STAT(rx_multicast),
  116. EFX_ETHTOOL_U64_MAC_STAT(rx_broadcast),
  117. EFX_ETHTOOL_U64_MAC_STAT(rx_lt64),
  118. EFX_ETHTOOL_U64_MAC_STAT(rx_64),
  119. EFX_ETHTOOL_U64_MAC_STAT(rx_65_to_127),
  120. EFX_ETHTOOL_U64_MAC_STAT(rx_128_to_255),
  121. EFX_ETHTOOL_U64_MAC_STAT(rx_256_to_511),
  122. EFX_ETHTOOL_U64_MAC_STAT(rx_512_to_1023),
  123. EFX_ETHTOOL_U64_MAC_STAT(rx_1024_to_15xx),
  124. EFX_ETHTOOL_U64_MAC_STAT(rx_15xx_to_jumbo),
  125. EFX_ETHTOOL_U64_MAC_STAT(rx_gtjumbo),
  126. EFX_ETHTOOL_U64_MAC_STAT(rx_bad_lt64),
  127. EFX_ETHTOOL_U64_MAC_STAT(rx_bad_64_to_15xx),
  128. EFX_ETHTOOL_U64_MAC_STAT(rx_bad_15xx_to_jumbo),
  129. EFX_ETHTOOL_U64_MAC_STAT(rx_bad_gtjumbo),
  130. EFX_ETHTOOL_U64_MAC_STAT(rx_overflow),
  131. EFX_ETHTOOL_U64_MAC_STAT(rx_missed),
  132. EFX_ETHTOOL_U64_MAC_STAT(rx_false_carrier),
  133. EFX_ETHTOOL_U64_MAC_STAT(rx_symbol_error),
  134. EFX_ETHTOOL_U64_MAC_STAT(rx_align_error),
  135. EFX_ETHTOOL_U64_MAC_STAT(rx_length_error),
  136. EFX_ETHTOOL_U64_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,
  156. enum ethtool_phys_id_state state)
  157. {
  158. struct efx_nic *efx = netdev_priv(net_dev);
  159. enum efx_led_mode mode = EFX_LED_DEFAULT;
  160. switch (state) {
  161. case ETHTOOL_ID_ON:
  162. mode = EFX_LED_ON;
  163. break;
  164. case ETHTOOL_ID_OFF:
  165. mode = EFX_LED_OFF;
  166. break;
  167. case ETHTOOL_ID_INACTIVE:
  168. mode = EFX_LED_DEFAULT;
  169. break;
  170. case ETHTOOL_ID_ACTIVE:
  171. return 1; /* cycle on/off once per second */
  172. }
  173. efx->type->set_id_led(efx, mode);
  174. return 0;
  175. }
  176. /* This must be called with rtnl_lock held. */
  177. static int efx_ethtool_get_settings(struct net_device *net_dev,
  178. struct ethtool_cmd *ecmd)
  179. {
  180. struct efx_nic *efx = netdev_priv(net_dev);
  181. struct efx_link_state *link_state = &efx->link_state;
  182. mutex_lock(&efx->mac_lock);
  183. efx->phy_op->get_settings(efx, ecmd);
  184. mutex_unlock(&efx->mac_lock);
  185. /* GMAC does not support 1000Mbps HD */
  186. ecmd->supported &= ~SUPPORTED_1000baseT_Half;
  187. /* Both MACs support pause frames (bidirectional and respond-only) */
  188. ecmd->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
  189. if (LOOPBACK_INTERNAL(efx)) {
  190. ethtool_cmd_speed_set(ecmd, link_state->speed);
  191. ecmd->duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF;
  192. }
  193. return 0;
  194. }
  195. /* This must be called with rtnl_lock held. */
  196. static int efx_ethtool_set_settings(struct net_device *net_dev,
  197. struct ethtool_cmd *ecmd)
  198. {
  199. struct efx_nic *efx = netdev_priv(net_dev);
  200. int rc;
  201. /* GMAC does not support 1000Mbps HD */
  202. if ((ethtool_cmd_speed(ecmd) == SPEED_1000) &&
  203. (ecmd->duplex != DUPLEX_FULL)) {
  204. netif_dbg(efx, drv, efx->net_dev,
  205. "rejecting unsupported 1000Mbps HD setting\n");
  206. return -EINVAL;
  207. }
  208. mutex_lock(&efx->mac_lock);
  209. rc = efx->phy_op->set_settings(efx, ecmd);
  210. mutex_unlock(&efx->mac_lock);
  211. return rc;
  212. }
  213. static void efx_ethtool_get_drvinfo(struct net_device *net_dev,
  214. struct ethtool_drvinfo *info)
  215. {
  216. struct efx_nic *efx = netdev_priv(net_dev);
  217. strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
  218. strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version));
  219. if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0)
  220. efx_mcdi_print_fwver(efx, info->fw_version,
  221. sizeof(info->fw_version));
  222. strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
  223. }
  224. static int efx_ethtool_get_regs_len(struct net_device *net_dev)
  225. {
  226. return efx_nic_get_regs_len(netdev_priv(net_dev));
  227. }
  228. static void efx_ethtool_get_regs(struct net_device *net_dev,
  229. struct ethtool_regs *regs, void *buf)
  230. {
  231. struct efx_nic *efx = netdev_priv(net_dev);
  232. regs->version = efx->type->revision;
  233. efx_nic_get_regs(efx, buf);
  234. }
  235. static u32 efx_ethtool_get_msglevel(struct net_device *net_dev)
  236. {
  237. struct efx_nic *efx = netdev_priv(net_dev);
  238. return efx->msg_enable;
  239. }
  240. static void efx_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable)
  241. {
  242. struct efx_nic *efx = netdev_priv(net_dev);
  243. efx->msg_enable = msg_enable;
  244. }
  245. /**
  246. * efx_fill_test - fill in an individual self-test entry
  247. * @test_index: Index of the test
  248. * @strings: Ethtool strings, or %NULL
  249. * @data: Ethtool test results, or %NULL
  250. * @test: Pointer to test result (used only if data != %NULL)
  251. * @unit_format: Unit name format (e.g. "chan\%d")
  252. * @unit_id: Unit id (e.g. 0 for "chan0")
  253. * @test_format: Test name format (e.g. "loopback.\%s.tx.sent")
  254. * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
  255. *
  256. * Fill in an individual self-test entry.
  257. */
  258. static void efx_fill_test(unsigned int test_index,
  259. struct ethtool_string *strings, u64 *data,
  260. int *test, const char *unit_format, int unit_id,
  261. const char *test_format, const char *test_id)
  262. {
  263. struct ethtool_string unit_str, test_str;
  264. /* Fill data value, if applicable */
  265. if (data)
  266. data[test_index] = *test;
  267. /* Fill string, if applicable */
  268. if (strings) {
  269. if (strchr(unit_format, '%'))
  270. snprintf(unit_str.name, sizeof(unit_str.name),
  271. unit_format, unit_id);
  272. else
  273. strcpy(unit_str.name, unit_format);
  274. snprintf(test_str.name, sizeof(test_str.name),
  275. test_format, test_id);
  276. snprintf(strings[test_index].name,
  277. sizeof(strings[test_index].name),
  278. "%-6s %-24s", unit_str.name, test_str.name);
  279. }
  280. }
  281. #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
  282. #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
  283. #define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
  284. #define EFX_LOOPBACK_NAME(_mode, _counter) \
  285. "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode)
  286. /**
  287. * efx_fill_loopback_test - fill in a block of loopback self-test entries
  288. * @efx: Efx NIC
  289. * @lb_tests: Efx loopback self-test results structure
  290. * @mode: Loopback test mode
  291. * @test_index: Starting index of the test
  292. * @strings: Ethtool strings, or %NULL
  293. * @data: Ethtool test results, or %NULL
  294. */
  295. static int efx_fill_loopback_test(struct efx_nic *efx,
  296. struct efx_loopback_self_tests *lb_tests,
  297. enum efx_loopback_mode mode,
  298. unsigned int test_index,
  299. struct ethtool_string *strings, u64 *data)
  300. {
  301. struct efx_channel *channel =
  302. efx_get_channel(efx, efx->tx_channel_offset);
  303. struct efx_tx_queue *tx_queue;
  304. efx_for_each_channel_tx_queue(tx_queue, channel) {
  305. efx_fill_test(test_index++, strings, data,
  306. &lb_tests->tx_sent[tx_queue->queue],
  307. EFX_TX_QUEUE_NAME(tx_queue),
  308. EFX_LOOPBACK_NAME(mode, "tx_sent"));
  309. efx_fill_test(test_index++, strings, data,
  310. &lb_tests->tx_done[tx_queue->queue],
  311. EFX_TX_QUEUE_NAME(tx_queue),
  312. EFX_LOOPBACK_NAME(mode, "tx_done"));
  313. }
  314. efx_fill_test(test_index++, strings, data,
  315. &lb_tests->rx_good,
  316. "rx", 0,
  317. EFX_LOOPBACK_NAME(mode, "rx_good"));
  318. efx_fill_test(test_index++, strings, data,
  319. &lb_tests->rx_bad,
  320. "rx", 0,
  321. EFX_LOOPBACK_NAME(mode, "rx_bad"));
  322. return test_index;
  323. }
  324. /**
  325. * efx_ethtool_fill_self_tests - get self-test details
  326. * @efx: Efx NIC
  327. * @tests: Efx self-test results structure, or %NULL
  328. * @strings: Ethtool strings, or %NULL
  329. * @data: Ethtool test results, or %NULL
  330. */
  331. static int efx_ethtool_fill_self_tests(struct efx_nic *efx,
  332. struct efx_self_tests *tests,
  333. struct ethtool_string *strings,
  334. u64 *data)
  335. {
  336. struct efx_channel *channel;
  337. unsigned int n = 0, i;
  338. enum efx_loopback_mode mode;
  339. efx_fill_test(n++, strings, data, &tests->phy_alive,
  340. "phy", 0, "alive", NULL);
  341. efx_fill_test(n++, strings, data, &tests->nvram,
  342. "core", 0, "nvram", NULL);
  343. efx_fill_test(n++, strings, data, &tests->interrupt,
  344. "core", 0, "interrupt", NULL);
  345. /* Event queues */
  346. efx_for_each_channel(channel, efx) {
  347. efx_fill_test(n++, strings, data,
  348. &tests->eventq_dma[channel->channel],
  349. EFX_CHANNEL_NAME(channel),
  350. "eventq.dma", NULL);
  351. efx_fill_test(n++, strings, data,
  352. &tests->eventq_int[channel->channel],
  353. EFX_CHANNEL_NAME(channel),
  354. "eventq.int", NULL);
  355. }
  356. efx_fill_test(n++, strings, data, &tests->registers,
  357. "core", 0, "registers", NULL);
  358. if (efx->phy_op->run_tests != NULL) {
  359. EFX_BUG_ON_PARANOID(efx->phy_op->test_name == NULL);
  360. for (i = 0; true; ++i) {
  361. const char *name;
  362. EFX_BUG_ON_PARANOID(i >= EFX_MAX_PHY_TESTS);
  363. name = efx->phy_op->test_name(efx, i);
  364. if (name == NULL)
  365. break;
  366. efx_fill_test(n++, strings, data, &tests->phy_ext[i],
  367. "phy", 0, name, NULL);
  368. }
  369. }
  370. /* Loopback tests */
  371. for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
  372. if (!(efx->loopback_modes & (1 << mode)))
  373. continue;
  374. n = efx_fill_loopback_test(efx,
  375. &tests->loopback[mode], mode, n,
  376. strings, data);
  377. }
  378. return n;
  379. }
  380. static int efx_ethtool_get_sset_count(struct net_device *net_dev,
  381. int string_set)
  382. {
  383. switch (string_set) {
  384. case ETH_SS_STATS:
  385. return EFX_ETHTOOL_NUM_STATS;
  386. case ETH_SS_TEST:
  387. return efx_ethtool_fill_self_tests(netdev_priv(net_dev),
  388. NULL, NULL, NULL);
  389. default:
  390. return -EINVAL;
  391. }
  392. }
  393. static void efx_ethtool_get_strings(struct net_device *net_dev,
  394. u32 string_set, u8 *strings)
  395. {
  396. struct efx_nic *efx = netdev_priv(net_dev);
  397. struct ethtool_string *ethtool_strings =
  398. (struct ethtool_string *)strings;
  399. int i;
  400. switch (string_set) {
  401. case ETH_SS_STATS:
  402. for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++)
  403. strlcpy(ethtool_strings[i].name,
  404. efx_ethtool_stats[i].name,
  405. sizeof(ethtool_strings[i].name));
  406. break;
  407. case ETH_SS_TEST:
  408. efx_ethtool_fill_self_tests(efx, NULL,
  409. ethtool_strings, NULL);
  410. break;
  411. default:
  412. /* No other string sets */
  413. break;
  414. }
  415. }
  416. static void efx_ethtool_get_stats(struct net_device *net_dev,
  417. struct ethtool_stats *stats,
  418. u64 *data)
  419. {
  420. struct efx_nic *efx = netdev_priv(net_dev);
  421. struct efx_mac_stats *mac_stats = &efx->mac_stats;
  422. const struct efx_ethtool_stat *stat;
  423. struct efx_channel *channel;
  424. struct efx_tx_queue *tx_queue;
  425. int i;
  426. EFX_BUG_ON_PARANOID(stats->n_stats != EFX_ETHTOOL_NUM_STATS);
  427. spin_lock_bh(&efx->stats_lock);
  428. /* Update MAC and NIC statistics */
  429. efx->type->update_stats(efx);
  430. /* Fill detailed statistics buffer */
  431. for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++) {
  432. stat = &efx_ethtool_stats[i];
  433. switch (stat->source) {
  434. case EFX_ETHTOOL_STAT_SOURCE_mac_stats:
  435. data[i] = stat->get_stat((void *)mac_stats +
  436. stat->offset);
  437. break;
  438. case EFX_ETHTOOL_STAT_SOURCE_nic:
  439. data[i] = stat->get_stat((void *)efx + stat->offset);
  440. break;
  441. case EFX_ETHTOOL_STAT_SOURCE_channel:
  442. data[i] = 0;
  443. efx_for_each_channel(channel, efx)
  444. data[i] += stat->get_stat((void *)channel +
  445. stat->offset);
  446. break;
  447. case EFX_ETHTOOL_STAT_SOURCE_tx_queue:
  448. data[i] = 0;
  449. efx_for_each_channel(channel, efx) {
  450. efx_for_each_channel_tx_queue(tx_queue, channel)
  451. data[i] +=
  452. stat->get_stat((void *)tx_queue
  453. + stat->offset);
  454. }
  455. break;
  456. }
  457. }
  458. spin_unlock_bh(&efx->stats_lock);
  459. }
  460. static void efx_ethtool_self_test(struct net_device *net_dev,
  461. struct ethtool_test *test, u64 *data)
  462. {
  463. struct efx_nic *efx = netdev_priv(net_dev);
  464. struct efx_self_tests *efx_tests;
  465. int already_up;
  466. int rc = -ENOMEM;
  467. efx_tests = kzalloc(sizeof(*efx_tests), GFP_KERNEL);
  468. if (!efx_tests)
  469. goto fail;
  470. if (efx->state != STATE_READY) {
  471. rc = -EIO;
  472. goto fail1;
  473. }
  474. netif_info(efx, drv, efx->net_dev, "starting %sline testing\n",
  475. (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
  476. /* We need rx buffers and interrupts. */
  477. already_up = (efx->net_dev->flags & IFF_UP);
  478. if (!already_up) {
  479. rc = dev_open(efx->net_dev);
  480. if (rc) {
  481. netif_err(efx, drv, efx->net_dev,
  482. "failed opening device.\n");
  483. goto fail1;
  484. }
  485. }
  486. rc = efx_selftest(efx, efx_tests, test->flags);
  487. if (!already_up)
  488. dev_close(efx->net_dev);
  489. netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n",
  490. rc == 0 ? "passed" : "failed",
  491. (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
  492. fail1:
  493. /* Fill ethtool results structures */
  494. efx_ethtool_fill_self_tests(efx, efx_tests, NULL, data);
  495. kfree(efx_tests);
  496. fail:
  497. if (rc)
  498. test->flags |= ETH_TEST_FL_FAILED;
  499. }
  500. /* Restart autonegotiation */
  501. static int efx_ethtool_nway_reset(struct net_device *net_dev)
  502. {
  503. struct efx_nic *efx = netdev_priv(net_dev);
  504. return mdio45_nway_restart(&efx->mdio);
  505. }
  506. /*
  507. * Each channel has a single IRQ and moderation timer, started by any
  508. * completion (or other event). Unless the module parameter
  509. * separate_tx_channels is set, IRQs and moderation are therefore
  510. * shared between RX and TX completions. In this case, when RX IRQ
  511. * moderation is explicitly changed then TX IRQ moderation is
  512. * automatically changed too, but otherwise we fail if the two values
  513. * are requested to be different.
  514. *
  515. * The hardware does not support a limit on the number of completions
  516. * before an IRQ, so we do not use the max_frames fields. We should
  517. * report and require that max_frames == (usecs != 0), but this would
  518. * invalidate existing user documentation.
  519. *
  520. * The hardware does not have distinct settings for interrupt
  521. * moderation while the previous IRQ is being handled, so we should
  522. * not use the 'irq' fields. However, an earlier developer
  523. * misunderstood the meaning of the 'irq' fields and the driver did
  524. * not support the standard fields. To avoid invalidating existing
  525. * user documentation, we report and accept changes through either the
  526. * standard or 'irq' fields. If both are changed at the same time, we
  527. * prefer the standard field.
  528. *
  529. * We implement adaptive IRQ moderation, but use a different algorithm
  530. * from that assumed in the definition of struct ethtool_coalesce.
  531. * Therefore we do not use any of the adaptive moderation parameters
  532. * in it.
  533. */
  534. static int efx_ethtool_get_coalesce(struct net_device *net_dev,
  535. struct ethtool_coalesce *coalesce)
  536. {
  537. struct efx_nic *efx = netdev_priv(net_dev);
  538. unsigned int tx_usecs, rx_usecs;
  539. bool rx_adaptive;
  540. efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &rx_adaptive);
  541. coalesce->tx_coalesce_usecs = tx_usecs;
  542. coalesce->tx_coalesce_usecs_irq = tx_usecs;
  543. coalesce->rx_coalesce_usecs = rx_usecs;
  544. coalesce->rx_coalesce_usecs_irq = rx_usecs;
  545. coalesce->use_adaptive_rx_coalesce = rx_adaptive;
  546. return 0;
  547. }
  548. static int efx_ethtool_set_coalesce(struct net_device *net_dev,
  549. struct ethtool_coalesce *coalesce)
  550. {
  551. struct efx_nic *efx = netdev_priv(net_dev);
  552. struct efx_channel *channel;
  553. unsigned int tx_usecs, rx_usecs;
  554. bool adaptive, rx_may_override_tx;
  555. int rc;
  556. if (coalesce->use_adaptive_tx_coalesce)
  557. return -EINVAL;
  558. efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &adaptive);
  559. if (coalesce->rx_coalesce_usecs != rx_usecs)
  560. rx_usecs = coalesce->rx_coalesce_usecs;
  561. else
  562. rx_usecs = coalesce->rx_coalesce_usecs_irq;
  563. adaptive = coalesce->use_adaptive_rx_coalesce;
  564. /* If channels are shared, TX IRQ moderation can be quietly
  565. * overridden unless it is changed from its old value.
  566. */
  567. rx_may_override_tx = (coalesce->tx_coalesce_usecs == tx_usecs &&
  568. coalesce->tx_coalesce_usecs_irq == tx_usecs);
  569. if (coalesce->tx_coalesce_usecs != tx_usecs)
  570. tx_usecs = coalesce->tx_coalesce_usecs;
  571. else
  572. tx_usecs = coalesce->tx_coalesce_usecs_irq;
  573. rc = efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive,
  574. rx_may_override_tx);
  575. if (rc != 0)
  576. return rc;
  577. efx_for_each_channel(channel, efx)
  578. efx->type->push_irq_moderation(channel);
  579. return 0;
  580. }
  581. static void efx_ethtool_get_ringparam(struct net_device *net_dev,
  582. struct ethtool_ringparam *ring)
  583. {
  584. struct efx_nic *efx = netdev_priv(net_dev);
  585. ring->rx_max_pending = EFX_MAX_DMAQ_SIZE;
  586. ring->tx_max_pending = EFX_MAX_DMAQ_SIZE;
  587. ring->rx_pending = efx->rxq_entries;
  588. ring->tx_pending = efx->txq_entries;
  589. }
  590. static int efx_ethtool_set_ringparam(struct net_device *net_dev,
  591. struct ethtool_ringparam *ring)
  592. {
  593. struct efx_nic *efx = netdev_priv(net_dev);
  594. u32 txq_entries;
  595. if (ring->rx_mini_pending || ring->rx_jumbo_pending ||
  596. ring->rx_pending > EFX_MAX_DMAQ_SIZE ||
  597. ring->tx_pending > EFX_MAX_DMAQ_SIZE)
  598. return -EINVAL;
  599. if (ring->rx_pending < EFX_RXQ_MIN_ENT) {
  600. netif_err(efx, drv, efx->net_dev,
  601. "RX queues cannot be smaller than %u\n",
  602. EFX_RXQ_MIN_ENT);
  603. return -EINVAL;
  604. }
  605. txq_entries = max(ring->tx_pending, EFX_TXQ_MIN_ENT(efx));
  606. if (txq_entries != ring->tx_pending)
  607. netif_warn(efx, drv, efx->net_dev,
  608. "increasing TX queue size to minimum of %u\n",
  609. txq_entries);
  610. return efx_realloc_channels(efx, ring->rx_pending, txq_entries);
  611. }
  612. static int efx_ethtool_set_pauseparam(struct net_device *net_dev,
  613. struct ethtool_pauseparam *pause)
  614. {
  615. struct efx_nic *efx = netdev_priv(net_dev);
  616. u8 wanted_fc, old_fc;
  617. u32 old_adv;
  618. bool reset;
  619. int rc = 0;
  620. mutex_lock(&efx->mac_lock);
  621. wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
  622. (pause->tx_pause ? EFX_FC_TX : 0) |
  623. (pause->autoneg ? EFX_FC_AUTO : 0));
  624. if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
  625. netif_dbg(efx, drv, efx->net_dev,
  626. "Flow control unsupported: tx ON rx OFF\n");
  627. rc = -EINVAL;
  628. goto out;
  629. }
  630. if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising) {
  631. netif_dbg(efx, drv, efx->net_dev,
  632. "Autonegotiation is disabled\n");
  633. rc = -EINVAL;
  634. goto out;
  635. }
  636. /* TX flow control may automatically turn itself off if the
  637. * link partner (intermittently) stops responding to pause
  638. * frames. There isn't any indication that this has happened,
  639. * so the best we do is leave it up to the user to spot this
  640. * and fix it be cycling transmit flow control on this end. */
  641. reset = (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX);
  642. if (EFX_WORKAROUND_11482(efx) && reset) {
  643. if (efx_nic_rev(efx) == EFX_REV_FALCON_B0) {
  644. /* Recover by resetting the EM block */
  645. falcon_stop_nic_stats(efx);
  646. falcon_drain_tx_fifo(efx);
  647. falcon_reconfigure_xmac(efx);
  648. falcon_start_nic_stats(efx);
  649. } else {
  650. /* Schedule a reset to recover */
  651. efx_schedule_reset(efx, RESET_TYPE_INVISIBLE);
  652. }
  653. }
  654. old_adv = efx->link_advertising;
  655. old_fc = efx->wanted_fc;
  656. efx_link_set_wanted_fc(efx, wanted_fc);
  657. if (efx->link_advertising != old_adv ||
  658. (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) {
  659. rc = efx->phy_op->reconfigure(efx);
  660. if (rc) {
  661. netif_err(efx, drv, efx->net_dev,
  662. "Unable to advertise requested flow "
  663. "control setting\n");
  664. goto out;
  665. }
  666. }
  667. /* Reconfigure the MAC. The PHY *may* generate a link state change event
  668. * if the user just changed the advertised capabilities, but there's no
  669. * harm doing this twice */
  670. efx->type->reconfigure_mac(efx);
  671. out:
  672. mutex_unlock(&efx->mac_lock);
  673. return rc;
  674. }
  675. static void efx_ethtool_get_pauseparam(struct net_device *net_dev,
  676. struct ethtool_pauseparam *pause)
  677. {
  678. struct efx_nic *efx = netdev_priv(net_dev);
  679. pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX);
  680. pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX);
  681. pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO);
  682. }
  683. static void efx_ethtool_get_wol(struct net_device *net_dev,
  684. struct ethtool_wolinfo *wol)
  685. {
  686. struct efx_nic *efx = netdev_priv(net_dev);
  687. return efx->type->get_wol(efx, wol);
  688. }
  689. static int efx_ethtool_set_wol(struct net_device *net_dev,
  690. struct ethtool_wolinfo *wol)
  691. {
  692. struct efx_nic *efx = netdev_priv(net_dev);
  693. return efx->type->set_wol(efx, wol->wolopts);
  694. }
  695. static int efx_ethtool_reset(struct net_device *net_dev, u32 *flags)
  696. {
  697. struct efx_nic *efx = netdev_priv(net_dev);
  698. int rc;
  699. rc = efx->type->map_reset_flags(flags);
  700. if (rc < 0)
  701. return rc;
  702. return efx_reset(efx, rc);
  703. }
  704. /* MAC address mask including only MC flag */
  705. static const u8 mac_addr_mc_mask[ETH_ALEN] = { 0x01, 0, 0, 0, 0, 0 };
  706. #define IP4_ADDR_FULL_MASK ((__force __be32)~0)
  707. #define PORT_FULL_MASK ((__force __be16)~0)
  708. static int efx_ethtool_get_class_rule(struct efx_nic *efx,
  709. struct ethtool_rx_flow_spec *rule)
  710. {
  711. struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
  712. struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
  713. struct ethhdr *mac_entry = &rule->h_u.ether_spec;
  714. struct ethhdr *mac_mask = &rule->m_u.ether_spec;
  715. struct efx_filter_spec spec;
  716. u16 vid;
  717. u8 proto;
  718. int rc;
  719. rc = efx_filter_get_filter_safe(efx, EFX_FILTER_PRI_MANUAL,
  720. rule->location, &spec);
  721. if (rc)
  722. return rc;
  723. if (spec.dmaq_id == 0xfff)
  724. rule->ring_cookie = RX_CLS_FLOW_DISC;
  725. else
  726. rule->ring_cookie = spec.dmaq_id;
  727. if (spec.type == EFX_FILTER_MC_DEF || spec.type == EFX_FILTER_UC_DEF) {
  728. rule->flow_type = ETHER_FLOW;
  729. memcpy(mac_mask->h_dest, mac_addr_mc_mask, ETH_ALEN);
  730. if (spec.type == EFX_FILTER_MC_DEF)
  731. memcpy(mac_entry->h_dest, mac_addr_mc_mask, ETH_ALEN);
  732. return 0;
  733. }
  734. rc = efx_filter_get_eth_local(&spec, &vid, mac_entry->h_dest);
  735. if (rc == 0) {
  736. rule->flow_type = ETHER_FLOW;
  737. memset(mac_mask->h_dest, ~0, ETH_ALEN);
  738. if (vid != EFX_FILTER_VID_UNSPEC) {
  739. rule->flow_type |= FLOW_EXT;
  740. rule->h_ext.vlan_tci = htons(vid);
  741. rule->m_ext.vlan_tci = htons(0xfff);
  742. }
  743. return 0;
  744. }
  745. rc = efx_filter_get_ipv4_local(&spec, &proto,
  746. &ip_entry->ip4dst, &ip_entry->pdst);
  747. if (rc != 0) {
  748. rc = efx_filter_get_ipv4_full(
  749. &spec, &proto, &ip_entry->ip4dst, &ip_entry->pdst,
  750. &ip_entry->ip4src, &ip_entry->psrc);
  751. EFX_WARN_ON_PARANOID(rc);
  752. ip_mask->ip4src = IP4_ADDR_FULL_MASK;
  753. ip_mask->psrc = PORT_FULL_MASK;
  754. }
  755. rule->flow_type = (proto == IPPROTO_TCP) ? TCP_V4_FLOW : UDP_V4_FLOW;
  756. ip_mask->ip4dst = IP4_ADDR_FULL_MASK;
  757. ip_mask->pdst = PORT_FULL_MASK;
  758. return rc;
  759. }
  760. static int
  761. efx_ethtool_get_rxnfc(struct net_device *net_dev,
  762. struct ethtool_rxnfc *info, u32 *rule_locs)
  763. {
  764. struct efx_nic *efx = netdev_priv(net_dev);
  765. switch (info->cmd) {
  766. case ETHTOOL_GRXRINGS:
  767. info->data = efx->n_rx_channels;
  768. return 0;
  769. case ETHTOOL_GRXFH: {
  770. unsigned min_revision = 0;
  771. info->data = 0;
  772. switch (info->flow_type) {
  773. case TCP_V4_FLOW:
  774. info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  775. /* fall through */
  776. case UDP_V4_FLOW:
  777. case SCTP_V4_FLOW:
  778. case AH_ESP_V4_FLOW:
  779. case IPV4_FLOW:
  780. info->data |= RXH_IP_SRC | RXH_IP_DST;
  781. min_revision = EFX_REV_FALCON_B0;
  782. break;
  783. case TCP_V6_FLOW:
  784. info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  785. /* fall through */
  786. case UDP_V6_FLOW:
  787. case SCTP_V6_FLOW:
  788. case AH_ESP_V6_FLOW:
  789. case IPV6_FLOW:
  790. info->data |= RXH_IP_SRC | RXH_IP_DST;
  791. min_revision = EFX_REV_SIENA_A0;
  792. break;
  793. default:
  794. break;
  795. }
  796. if (efx_nic_rev(efx) < min_revision)
  797. info->data = 0;
  798. return 0;
  799. }
  800. case ETHTOOL_GRXCLSRLCNT:
  801. info->data = efx_filter_get_rx_id_limit(efx);
  802. if (info->data == 0)
  803. return -EOPNOTSUPP;
  804. info->data |= RX_CLS_LOC_SPECIAL;
  805. info->rule_cnt =
  806. efx_filter_count_rx_used(efx, EFX_FILTER_PRI_MANUAL);
  807. return 0;
  808. case ETHTOOL_GRXCLSRULE:
  809. if (efx_filter_get_rx_id_limit(efx) == 0)
  810. return -EOPNOTSUPP;
  811. return efx_ethtool_get_class_rule(efx, &info->fs);
  812. case ETHTOOL_GRXCLSRLALL: {
  813. s32 rc;
  814. info->data = efx_filter_get_rx_id_limit(efx);
  815. if (info->data == 0)
  816. return -EOPNOTSUPP;
  817. rc = efx_filter_get_rx_ids(efx, EFX_FILTER_PRI_MANUAL,
  818. rule_locs, info->rule_cnt);
  819. if (rc < 0)
  820. return rc;
  821. info->rule_cnt = rc;
  822. return 0;
  823. }
  824. default:
  825. return -EOPNOTSUPP;
  826. }
  827. }
  828. static int efx_ethtool_set_class_rule(struct efx_nic *efx,
  829. struct ethtool_rx_flow_spec *rule)
  830. {
  831. struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
  832. struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
  833. struct ethhdr *mac_entry = &rule->h_u.ether_spec;
  834. struct ethhdr *mac_mask = &rule->m_u.ether_spec;
  835. struct efx_filter_spec spec;
  836. int rc;
  837. /* Check that user wants us to choose the location */
  838. if (rule->location != RX_CLS_LOC_ANY)
  839. return -EINVAL;
  840. /* Range-check ring_cookie */
  841. if (rule->ring_cookie >= efx->n_rx_channels &&
  842. rule->ring_cookie != RX_CLS_FLOW_DISC)
  843. return -EINVAL;
  844. /* Check for unsupported extensions */
  845. if ((rule->flow_type & FLOW_EXT) &&
  846. (rule->m_ext.vlan_etype || rule->m_ext.data[0] ||
  847. rule->m_ext.data[1]))
  848. return -EINVAL;
  849. efx_filter_init_rx(&spec, EFX_FILTER_PRI_MANUAL, 0,
  850. (rule->ring_cookie == RX_CLS_FLOW_DISC) ?
  851. 0xfff : rule->ring_cookie);
  852. switch (rule->flow_type) {
  853. case TCP_V4_FLOW:
  854. case UDP_V4_FLOW: {
  855. u8 proto = (rule->flow_type == TCP_V4_FLOW ?
  856. IPPROTO_TCP : IPPROTO_UDP);
  857. /* Must match all of destination, */
  858. if (!(ip_mask->ip4dst == IP4_ADDR_FULL_MASK &&
  859. ip_mask->pdst == PORT_FULL_MASK))
  860. return -EINVAL;
  861. /* all or none of source, */
  862. if ((ip_mask->ip4src || ip_mask->psrc) &&
  863. !(ip_mask->ip4src == IP4_ADDR_FULL_MASK &&
  864. ip_mask->psrc == PORT_FULL_MASK))
  865. return -EINVAL;
  866. /* and nothing else */
  867. if (ip_mask->tos || rule->m_ext.vlan_tci)
  868. return -EINVAL;
  869. if (ip_mask->ip4src)
  870. rc = efx_filter_set_ipv4_full(&spec, proto,
  871. ip_entry->ip4dst,
  872. ip_entry->pdst,
  873. ip_entry->ip4src,
  874. ip_entry->psrc);
  875. else
  876. rc = efx_filter_set_ipv4_local(&spec, proto,
  877. ip_entry->ip4dst,
  878. ip_entry->pdst);
  879. if (rc)
  880. return rc;
  881. break;
  882. }
  883. case ETHER_FLOW | FLOW_EXT:
  884. case ETHER_FLOW: {
  885. u16 vlan_tag_mask = (rule->flow_type & FLOW_EXT ?
  886. ntohs(rule->m_ext.vlan_tci) : 0);
  887. /* Must not match on source address or Ethertype */
  888. if (!is_zero_ether_addr(mac_mask->h_source) ||
  889. mac_mask->h_proto)
  890. return -EINVAL;
  891. /* Is it a default UC or MC filter? */
  892. if (ether_addr_equal(mac_mask->h_dest, mac_addr_mc_mask) &&
  893. vlan_tag_mask == 0) {
  894. if (is_multicast_ether_addr(mac_entry->h_dest))
  895. rc = efx_filter_set_mc_def(&spec);
  896. else
  897. rc = efx_filter_set_uc_def(&spec);
  898. }
  899. /* Otherwise, it must match all of destination and all
  900. * or none of VID.
  901. */
  902. else if (is_broadcast_ether_addr(mac_mask->h_dest) &&
  903. (vlan_tag_mask == 0xfff || vlan_tag_mask == 0)) {
  904. rc = efx_filter_set_eth_local(
  905. &spec,
  906. vlan_tag_mask ?
  907. ntohs(rule->h_ext.vlan_tci) : EFX_FILTER_VID_UNSPEC,
  908. mac_entry->h_dest);
  909. } else {
  910. rc = -EINVAL;
  911. }
  912. if (rc)
  913. return rc;
  914. break;
  915. }
  916. default:
  917. return -EINVAL;
  918. }
  919. rc = efx_filter_insert_filter(efx, &spec, true);
  920. if (rc < 0)
  921. return rc;
  922. rule->location = rc;
  923. return 0;
  924. }
  925. static int efx_ethtool_set_rxnfc(struct net_device *net_dev,
  926. struct ethtool_rxnfc *info)
  927. {
  928. struct efx_nic *efx = netdev_priv(net_dev);
  929. if (efx_filter_get_rx_id_limit(efx) == 0)
  930. return -EOPNOTSUPP;
  931. switch (info->cmd) {
  932. case ETHTOOL_SRXCLSRLINS:
  933. return efx_ethtool_set_class_rule(efx, &info->fs);
  934. case ETHTOOL_SRXCLSRLDEL:
  935. return efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_MANUAL,
  936. info->fs.location);
  937. default:
  938. return -EOPNOTSUPP;
  939. }
  940. }
  941. static u32 efx_ethtool_get_rxfh_indir_size(struct net_device *net_dev)
  942. {
  943. struct efx_nic *efx = netdev_priv(net_dev);
  944. return ((efx_nic_rev(efx) < EFX_REV_FALCON_B0 ||
  945. efx->n_rx_channels == 1) ?
  946. 0 : ARRAY_SIZE(efx->rx_indir_table));
  947. }
  948. static int efx_ethtool_get_rxfh_indir(struct net_device *net_dev, u32 *indir)
  949. {
  950. struct efx_nic *efx = netdev_priv(net_dev);
  951. memcpy(indir, efx->rx_indir_table, sizeof(efx->rx_indir_table));
  952. return 0;
  953. }
  954. static int efx_ethtool_set_rxfh_indir(struct net_device *net_dev,
  955. const u32 *indir)
  956. {
  957. struct efx_nic *efx = netdev_priv(net_dev);
  958. memcpy(efx->rx_indir_table, indir, sizeof(efx->rx_indir_table));
  959. efx_nic_push_rx_indir_table(efx);
  960. return 0;
  961. }
  962. static int efx_ethtool_get_module_eeprom(struct net_device *net_dev,
  963. struct ethtool_eeprom *ee,
  964. u8 *data)
  965. {
  966. struct efx_nic *efx = netdev_priv(net_dev);
  967. int ret;
  968. if (!efx->phy_op || !efx->phy_op->get_module_eeprom)
  969. return -EOPNOTSUPP;
  970. mutex_lock(&efx->mac_lock);
  971. ret = efx->phy_op->get_module_eeprom(efx, ee, data);
  972. mutex_unlock(&efx->mac_lock);
  973. return ret;
  974. }
  975. static int efx_ethtool_get_module_info(struct net_device *net_dev,
  976. struct ethtool_modinfo *modinfo)
  977. {
  978. struct efx_nic *efx = netdev_priv(net_dev);
  979. int ret;
  980. if (!efx->phy_op || !efx->phy_op->get_module_info)
  981. return -EOPNOTSUPP;
  982. mutex_lock(&efx->mac_lock);
  983. ret = efx->phy_op->get_module_info(efx, modinfo);
  984. mutex_unlock(&efx->mac_lock);
  985. return ret;
  986. }
  987. const struct ethtool_ops efx_ethtool_ops = {
  988. .get_settings = efx_ethtool_get_settings,
  989. .set_settings = efx_ethtool_set_settings,
  990. .get_drvinfo = efx_ethtool_get_drvinfo,
  991. .get_regs_len = efx_ethtool_get_regs_len,
  992. .get_regs = efx_ethtool_get_regs,
  993. .get_msglevel = efx_ethtool_get_msglevel,
  994. .set_msglevel = efx_ethtool_set_msglevel,
  995. .nway_reset = efx_ethtool_nway_reset,
  996. .get_link = ethtool_op_get_link,
  997. .get_coalesce = efx_ethtool_get_coalesce,
  998. .set_coalesce = efx_ethtool_set_coalesce,
  999. .get_ringparam = efx_ethtool_get_ringparam,
  1000. .set_ringparam = efx_ethtool_set_ringparam,
  1001. .get_pauseparam = efx_ethtool_get_pauseparam,
  1002. .set_pauseparam = efx_ethtool_set_pauseparam,
  1003. .get_sset_count = efx_ethtool_get_sset_count,
  1004. .self_test = efx_ethtool_self_test,
  1005. .get_strings = efx_ethtool_get_strings,
  1006. .set_phys_id = efx_ethtool_phys_id,
  1007. .get_ethtool_stats = efx_ethtool_get_stats,
  1008. .get_wol = efx_ethtool_get_wol,
  1009. .set_wol = efx_ethtool_set_wol,
  1010. .reset = efx_ethtool_reset,
  1011. .get_rxnfc = efx_ethtool_get_rxnfc,
  1012. .set_rxnfc = efx_ethtool_set_rxnfc,
  1013. .get_rxfh_indir_size = efx_ethtool_get_rxfh_indir_size,
  1014. .get_rxfh_indir = efx_ethtool_get_rxfh_indir,
  1015. .set_rxfh_indir = efx_ethtool_set_rxfh_indir,
  1016. .get_ts_info = efx_ptp_get_ts_info,
  1017. .get_module_info = efx_ethtool_get_module_info,
  1018. .get_module_eeprom = efx_ethtool_get_module_eeprom,
  1019. };