ethtool.c 35 KB

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