ethtool.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012
  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_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. #define EFX_ETHTOOL_UINT_TXQ_STAT(field) \
  77. EFX_ETHTOOL_STAT(tx_##field, tx_queue, field, \
  78. unsigned int, efx_get_uint_stat)
  79. static struct efx_ethtool_stat efx_ethtool_stats[] = {
  80. EFX_ETHTOOL_U64_MAC_STAT(tx_bytes),
  81. EFX_ETHTOOL_U64_MAC_STAT(tx_good_bytes),
  82. EFX_ETHTOOL_U64_MAC_STAT(tx_bad_bytes),
  83. EFX_ETHTOOL_ULONG_MAC_STAT(tx_packets),
  84. EFX_ETHTOOL_ULONG_MAC_STAT(tx_bad),
  85. EFX_ETHTOOL_ULONG_MAC_STAT(tx_pause),
  86. EFX_ETHTOOL_ULONG_MAC_STAT(tx_control),
  87. EFX_ETHTOOL_ULONG_MAC_STAT(tx_unicast),
  88. EFX_ETHTOOL_ULONG_MAC_STAT(tx_multicast),
  89. EFX_ETHTOOL_ULONG_MAC_STAT(tx_broadcast),
  90. EFX_ETHTOOL_ULONG_MAC_STAT(tx_lt64),
  91. EFX_ETHTOOL_ULONG_MAC_STAT(tx_64),
  92. EFX_ETHTOOL_ULONG_MAC_STAT(tx_65_to_127),
  93. EFX_ETHTOOL_ULONG_MAC_STAT(tx_128_to_255),
  94. EFX_ETHTOOL_ULONG_MAC_STAT(tx_256_to_511),
  95. EFX_ETHTOOL_ULONG_MAC_STAT(tx_512_to_1023),
  96. EFX_ETHTOOL_ULONG_MAC_STAT(tx_1024_to_15xx),
  97. EFX_ETHTOOL_ULONG_MAC_STAT(tx_15xx_to_jumbo),
  98. EFX_ETHTOOL_ULONG_MAC_STAT(tx_gtjumbo),
  99. EFX_ETHTOOL_ULONG_MAC_STAT(tx_collision),
  100. EFX_ETHTOOL_ULONG_MAC_STAT(tx_single_collision),
  101. EFX_ETHTOOL_ULONG_MAC_STAT(tx_multiple_collision),
  102. EFX_ETHTOOL_ULONG_MAC_STAT(tx_excessive_collision),
  103. EFX_ETHTOOL_ULONG_MAC_STAT(tx_deferred),
  104. EFX_ETHTOOL_ULONG_MAC_STAT(tx_late_collision),
  105. EFX_ETHTOOL_ULONG_MAC_STAT(tx_excessive_deferred),
  106. EFX_ETHTOOL_ULONG_MAC_STAT(tx_non_tcpudp),
  107. EFX_ETHTOOL_ULONG_MAC_STAT(tx_mac_src_error),
  108. EFX_ETHTOOL_ULONG_MAC_STAT(tx_ip_src_error),
  109. EFX_ETHTOOL_UINT_TXQ_STAT(tso_bursts),
  110. EFX_ETHTOOL_UINT_TXQ_STAT(tso_long_headers),
  111. EFX_ETHTOOL_UINT_TXQ_STAT(tso_packets),
  112. EFX_ETHTOOL_UINT_TXQ_STAT(pushes),
  113. EFX_ETHTOOL_U64_MAC_STAT(rx_bytes),
  114. EFX_ETHTOOL_U64_MAC_STAT(rx_good_bytes),
  115. EFX_ETHTOOL_U64_MAC_STAT(rx_bad_bytes),
  116. EFX_ETHTOOL_ULONG_MAC_STAT(rx_packets),
  117. EFX_ETHTOOL_ULONG_MAC_STAT(rx_good),
  118. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad),
  119. EFX_ETHTOOL_ULONG_MAC_STAT(rx_pause),
  120. EFX_ETHTOOL_ULONG_MAC_STAT(rx_control),
  121. EFX_ETHTOOL_ULONG_MAC_STAT(rx_unicast),
  122. EFX_ETHTOOL_ULONG_MAC_STAT(rx_multicast),
  123. EFX_ETHTOOL_ULONG_MAC_STAT(rx_broadcast),
  124. EFX_ETHTOOL_ULONG_MAC_STAT(rx_lt64),
  125. EFX_ETHTOOL_ULONG_MAC_STAT(rx_64),
  126. EFX_ETHTOOL_ULONG_MAC_STAT(rx_65_to_127),
  127. EFX_ETHTOOL_ULONG_MAC_STAT(rx_128_to_255),
  128. EFX_ETHTOOL_ULONG_MAC_STAT(rx_256_to_511),
  129. EFX_ETHTOOL_ULONG_MAC_STAT(rx_512_to_1023),
  130. EFX_ETHTOOL_ULONG_MAC_STAT(rx_1024_to_15xx),
  131. EFX_ETHTOOL_ULONG_MAC_STAT(rx_15xx_to_jumbo),
  132. EFX_ETHTOOL_ULONG_MAC_STAT(rx_gtjumbo),
  133. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_lt64),
  134. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_64_to_15xx),
  135. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_15xx_to_jumbo),
  136. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_gtjumbo),
  137. EFX_ETHTOOL_ULONG_MAC_STAT(rx_overflow),
  138. EFX_ETHTOOL_ULONG_MAC_STAT(rx_missed),
  139. EFX_ETHTOOL_ULONG_MAC_STAT(rx_false_carrier),
  140. EFX_ETHTOOL_ULONG_MAC_STAT(rx_symbol_error),
  141. EFX_ETHTOOL_ULONG_MAC_STAT(rx_align_error),
  142. EFX_ETHTOOL_ULONG_MAC_STAT(rx_length_error),
  143. EFX_ETHTOOL_ULONG_MAC_STAT(rx_internal_error),
  144. EFX_ETHTOOL_UINT_NIC_STAT(rx_nodesc_drop_cnt),
  145. EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset),
  146. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc),
  147. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),
  148. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err),
  149. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch),
  150. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
  151. };
  152. /* Number of ethtool statistics */
  153. #define EFX_ETHTOOL_NUM_STATS ARRAY_SIZE(efx_ethtool_stats)
  154. #define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB
  155. /**************************************************************************
  156. *
  157. * Ethtool operations
  158. *
  159. **************************************************************************
  160. */
  161. /* Identify device by flashing LEDs */
  162. static int efx_ethtool_phys_id(struct net_device *net_dev,
  163. enum ethtool_phys_id_state state)
  164. {
  165. struct efx_nic *efx = netdev_priv(net_dev);
  166. enum efx_led_mode mode = EFX_LED_DEFAULT;
  167. switch (state) {
  168. case ETHTOOL_ID_ON:
  169. mode = EFX_LED_ON;
  170. break;
  171. case ETHTOOL_ID_OFF:
  172. mode = EFX_LED_OFF;
  173. break;
  174. case ETHTOOL_ID_INACTIVE:
  175. mode = EFX_LED_DEFAULT;
  176. break;
  177. case ETHTOOL_ID_ACTIVE:
  178. return 1; /* cycle on/off once per second */
  179. }
  180. efx->type->set_id_led(efx, mode);
  181. return 0;
  182. }
  183. /* This must be called with rtnl_lock held. */
  184. static int efx_ethtool_get_settings(struct net_device *net_dev,
  185. struct ethtool_cmd *ecmd)
  186. {
  187. struct efx_nic *efx = netdev_priv(net_dev);
  188. struct efx_link_state *link_state = &efx->link_state;
  189. mutex_lock(&efx->mac_lock);
  190. efx->phy_op->get_settings(efx, ecmd);
  191. mutex_unlock(&efx->mac_lock);
  192. /* GMAC does not support 1000Mbps HD */
  193. ecmd->supported &= ~SUPPORTED_1000baseT_Half;
  194. /* Both MACs support pause frames (bidirectional and respond-only) */
  195. ecmd->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
  196. if (LOOPBACK_INTERNAL(efx)) {
  197. ethtool_cmd_speed_set(ecmd, link_state->speed);
  198. ecmd->duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF;
  199. }
  200. return 0;
  201. }
  202. /* This must be called with rtnl_lock held. */
  203. static int efx_ethtool_set_settings(struct net_device *net_dev,
  204. struct ethtool_cmd *ecmd)
  205. {
  206. struct efx_nic *efx = netdev_priv(net_dev);
  207. int rc;
  208. /* GMAC does not support 1000Mbps HD */
  209. if ((ethtool_cmd_speed(ecmd) == SPEED_1000) &&
  210. (ecmd->duplex != DUPLEX_FULL)) {
  211. netif_dbg(efx, drv, efx->net_dev,
  212. "rejecting unsupported 1000Mbps HD setting\n");
  213. return -EINVAL;
  214. }
  215. mutex_lock(&efx->mac_lock);
  216. rc = efx->phy_op->set_settings(efx, ecmd);
  217. mutex_unlock(&efx->mac_lock);
  218. return rc;
  219. }
  220. static void efx_ethtool_get_drvinfo(struct net_device *net_dev,
  221. struct ethtool_drvinfo *info)
  222. {
  223. struct efx_nic *efx = netdev_priv(net_dev);
  224. strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
  225. strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version));
  226. if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0)
  227. efx_mcdi_print_fwver(efx, info->fw_version,
  228. sizeof(info->fw_version));
  229. strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
  230. }
  231. static int efx_ethtool_get_regs_len(struct net_device *net_dev)
  232. {
  233. return efx_nic_get_regs_len(netdev_priv(net_dev));
  234. }
  235. static void efx_ethtool_get_regs(struct net_device *net_dev,
  236. struct ethtool_regs *regs, void *buf)
  237. {
  238. struct efx_nic *efx = netdev_priv(net_dev);
  239. regs->version = efx->type->revision;
  240. efx_nic_get_regs(efx, buf);
  241. }
  242. static u32 efx_ethtool_get_msglevel(struct net_device *net_dev)
  243. {
  244. struct efx_nic *efx = netdev_priv(net_dev);
  245. return efx->msg_enable;
  246. }
  247. static void efx_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable)
  248. {
  249. struct efx_nic *efx = netdev_priv(net_dev);
  250. efx->msg_enable = msg_enable;
  251. }
  252. /**
  253. * efx_fill_test - fill in an individual self-test entry
  254. * @test_index: Index of the test
  255. * @strings: Ethtool strings, or %NULL
  256. * @data: Ethtool test results, or %NULL
  257. * @test: Pointer to test result (used only if data != %NULL)
  258. * @unit_format: Unit name format (e.g. "chan\%d")
  259. * @unit_id: Unit id (e.g. 0 for "chan0")
  260. * @test_format: Test name format (e.g. "loopback.\%s.tx.sent")
  261. * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
  262. *
  263. * Fill in an individual self-test entry.
  264. */
  265. static void efx_fill_test(unsigned int test_index,
  266. struct ethtool_string *strings, u64 *data,
  267. int *test, const char *unit_format, int unit_id,
  268. const char *test_format, const char *test_id)
  269. {
  270. struct ethtool_string unit_str, test_str;
  271. /* Fill data value, if applicable */
  272. if (data)
  273. data[test_index] = *test;
  274. /* Fill string, if applicable */
  275. if (strings) {
  276. if (strchr(unit_format, '%'))
  277. snprintf(unit_str.name, sizeof(unit_str.name),
  278. unit_format, unit_id);
  279. else
  280. strcpy(unit_str.name, unit_format);
  281. snprintf(test_str.name, sizeof(test_str.name),
  282. test_format, test_id);
  283. snprintf(strings[test_index].name,
  284. sizeof(strings[test_index].name),
  285. "%-6s %-24s", unit_str.name, test_str.name);
  286. }
  287. }
  288. #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
  289. #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
  290. #define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
  291. #define EFX_LOOPBACK_NAME(_mode, _counter) \
  292. "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode)
  293. /**
  294. * efx_fill_loopback_test - fill in a block of loopback self-test entries
  295. * @efx: Efx NIC
  296. * @lb_tests: Efx loopback self-test results structure
  297. * @mode: Loopback test mode
  298. * @test_index: Starting index of the test
  299. * @strings: Ethtool strings, or %NULL
  300. * @data: Ethtool test results, or %NULL
  301. */
  302. static int efx_fill_loopback_test(struct efx_nic *efx,
  303. struct efx_loopback_self_tests *lb_tests,
  304. enum efx_loopback_mode mode,
  305. unsigned int test_index,
  306. struct ethtool_string *strings, u64 *data)
  307. {
  308. struct efx_channel *channel = efx_get_channel(efx, 0);
  309. struct efx_tx_queue *tx_queue;
  310. efx_for_each_channel_tx_queue(tx_queue, channel) {
  311. efx_fill_test(test_index++, strings, data,
  312. &lb_tests->tx_sent[tx_queue->queue],
  313. EFX_TX_QUEUE_NAME(tx_queue),
  314. EFX_LOOPBACK_NAME(mode, "tx_sent"));
  315. efx_fill_test(test_index++, strings, data,
  316. &lb_tests->tx_done[tx_queue->queue],
  317. EFX_TX_QUEUE_NAME(tx_queue),
  318. EFX_LOOPBACK_NAME(mode, "tx_done"));
  319. }
  320. efx_fill_test(test_index++, strings, data,
  321. &lb_tests->rx_good,
  322. "rx", 0,
  323. EFX_LOOPBACK_NAME(mode, "rx_good"));
  324. efx_fill_test(test_index++, strings, data,
  325. &lb_tests->rx_bad,
  326. "rx", 0,
  327. EFX_LOOPBACK_NAME(mode, "rx_bad"));
  328. return test_index;
  329. }
  330. /**
  331. * efx_ethtool_fill_self_tests - get self-test details
  332. * @efx: Efx NIC
  333. * @tests: Efx self-test results structure, or %NULL
  334. * @strings: Ethtool strings, or %NULL
  335. * @data: Ethtool test results, or %NULL
  336. */
  337. static int efx_ethtool_fill_self_tests(struct efx_nic *efx,
  338. struct efx_self_tests *tests,
  339. struct ethtool_string *strings,
  340. u64 *data)
  341. {
  342. struct efx_channel *channel;
  343. unsigned int n = 0, i;
  344. enum efx_loopback_mode mode;
  345. efx_fill_test(n++, strings, data, &tests->phy_alive,
  346. "phy", 0, "alive", NULL);
  347. efx_fill_test(n++, strings, data, &tests->nvram,
  348. "core", 0, "nvram", NULL);
  349. efx_fill_test(n++, strings, data, &tests->interrupt,
  350. "core", 0, "interrupt", NULL);
  351. /* Event queues */
  352. efx_for_each_channel(channel, efx) {
  353. efx_fill_test(n++, strings, data,
  354. &tests->eventq_dma[channel->channel],
  355. EFX_CHANNEL_NAME(channel),
  356. "eventq.dma", NULL);
  357. efx_fill_test(n++, strings, data,
  358. &tests->eventq_int[channel->channel],
  359. EFX_CHANNEL_NAME(channel),
  360. "eventq.int", NULL);
  361. efx_fill_test(n++, strings, data,
  362. &tests->eventq_poll[channel->channel],
  363. EFX_CHANNEL_NAME(channel),
  364. "eventq.poll", NULL);
  365. }
  366. efx_fill_test(n++, strings, data, &tests->registers,
  367. "core", 0, "registers", NULL);
  368. if (efx->phy_op->run_tests != NULL) {
  369. EFX_BUG_ON_PARANOID(efx->phy_op->test_name == NULL);
  370. for (i = 0; true; ++i) {
  371. const char *name;
  372. EFX_BUG_ON_PARANOID(i >= EFX_MAX_PHY_TESTS);
  373. name = efx->phy_op->test_name(efx, i);
  374. if (name == NULL)
  375. break;
  376. efx_fill_test(n++, strings, data, &tests->phy_ext[i],
  377. "phy", 0, name, NULL);
  378. }
  379. }
  380. /* Loopback tests */
  381. for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
  382. if (!(efx->loopback_modes & (1 << mode)))
  383. continue;
  384. n = efx_fill_loopback_test(efx,
  385. &tests->loopback[mode], mode, n,
  386. strings, data);
  387. }
  388. return n;
  389. }
  390. static int efx_ethtool_get_sset_count(struct net_device *net_dev,
  391. int string_set)
  392. {
  393. switch (string_set) {
  394. case ETH_SS_STATS:
  395. return EFX_ETHTOOL_NUM_STATS;
  396. case ETH_SS_TEST:
  397. return efx_ethtool_fill_self_tests(netdev_priv(net_dev),
  398. NULL, NULL, NULL);
  399. default:
  400. return -EINVAL;
  401. }
  402. }
  403. static void efx_ethtool_get_strings(struct net_device *net_dev,
  404. u32 string_set, u8 *strings)
  405. {
  406. struct efx_nic *efx = netdev_priv(net_dev);
  407. struct ethtool_string *ethtool_strings =
  408. (struct ethtool_string *)strings;
  409. int i;
  410. switch (string_set) {
  411. case ETH_SS_STATS:
  412. for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++)
  413. strncpy(ethtool_strings[i].name,
  414. efx_ethtool_stats[i].name,
  415. sizeof(ethtool_strings[i].name));
  416. break;
  417. case ETH_SS_TEST:
  418. efx_ethtool_fill_self_tests(efx, NULL,
  419. ethtool_strings, NULL);
  420. break;
  421. default:
  422. /* No other string sets */
  423. break;
  424. }
  425. }
  426. static void efx_ethtool_get_stats(struct net_device *net_dev,
  427. struct ethtool_stats *stats,
  428. u64 *data)
  429. {
  430. struct efx_nic *efx = netdev_priv(net_dev);
  431. struct efx_mac_stats *mac_stats = &efx->mac_stats;
  432. struct efx_ethtool_stat *stat;
  433. struct efx_channel *channel;
  434. struct efx_tx_queue *tx_queue;
  435. struct rtnl_link_stats64 temp;
  436. int i;
  437. EFX_BUG_ON_PARANOID(stats->n_stats != EFX_ETHTOOL_NUM_STATS);
  438. /* Update MAC and NIC statistics */
  439. dev_get_stats(net_dev, &temp);
  440. /* Fill detailed statistics buffer */
  441. for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++) {
  442. stat = &efx_ethtool_stats[i];
  443. switch (stat->source) {
  444. case EFX_ETHTOOL_STAT_SOURCE_mac_stats:
  445. data[i] = stat->get_stat((void *)mac_stats +
  446. stat->offset);
  447. break;
  448. case EFX_ETHTOOL_STAT_SOURCE_nic:
  449. data[i] = stat->get_stat((void *)efx + stat->offset);
  450. break;
  451. case EFX_ETHTOOL_STAT_SOURCE_channel:
  452. data[i] = 0;
  453. efx_for_each_channel(channel, efx)
  454. data[i] += stat->get_stat((void *)channel +
  455. stat->offset);
  456. break;
  457. case EFX_ETHTOOL_STAT_SOURCE_tx_queue:
  458. data[i] = 0;
  459. efx_for_each_channel(channel, efx) {
  460. efx_for_each_channel_tx_queue(tx_queue, channel)
  461. data[i] +=
  462. stat->get_stat((void *)tx_queue
  463. + stat->offset);
  464. }
  465. break;
  466. }
  467. }
  468. }
  469. static void efx_ethtool_self_test(struct net_device *net_dev,
  470. struct ethtool_test *test, u64 *data)
  471. {
  472. struct efx_nic *efx = netdev_priv(net_dev);
  473. struct efx_self_tests *efx_tests;
  474. int already_up;
  475. int rc = -ENOMEM;
  476. efx_tests = kzalloc(sizeof(*efx_tests), GFP_KERNEL);
  477. if (!efx_tests)
  478. goto fail;
  479. ASSERT_RTNL();
  480. if (efx->state != STATE_RUNNING) {
  481. rc = -EIO;
  482. goto fail1;
  483. }
  484. netif_info(efx, drv, efx->net_dev, "starting %sline testing\n",
  485. (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
  486. /* We need rx buffers and interrupts. */
  487. already_up = (efx->net_dev->flags & IFF_UP);
  488. if (!already_up) {
  489. rc = dev_open(efx->net_dev);
  490. if (rc) {
  491. netif_err(efx, drv, efx->net_dev,
  492. "failed opening device.\n");
  493. goto fail1;
  494. }
  495. }
  496. rc = efx_selftest(efx, efx_tests, test->flags);
  497. if (!already_up)
  498. dev_close(efx->net_dev);
  499. netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n",
  500. rc == 0 ? "passed" : "failed",
  501. (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
  502. fail1:
  503. /* Fill ethtool results structures */
  504. efx_ethtool_fill_self_tests(efx, efx_tests, NULL, data);
  505. kfree(efx_tests);
  506. fail:
  507. if (rc)
  508. test->flags |= ETH_TEST_FL_FAILED;
  509. }
  510. /* Restart autonegotiation */
  511. static int efx_ethtool_nway_reset(struct net_device *net_dev)
  512. {
  513. struct efx_nic *efx = netdev_priv(net_dev);
  514. return mdio45_nway_restart(&efx->mdio);
  515. }
  516. static int efx_ethtool_get_coalesce(struct net_device *net_dev,
  517. struct ethtool_coalesce *coalesce)
  518. {
  519. struct efx_nic *efx = netdev_priv(net_dev);
  520. struct efx_channel *channel;
  521. memset(coalesce, 0, sizeof(*coalesce));
  522. /* Find lowest IRQ moderation across all used TX queues */
  523. coalesce->tx_coalesce_usecs_irq = ~((u32) 0);
  524. efx_for_each_channel(channel, efx) {
  525. if (!efx_channel_has_tx_queues(channel))
  526. continue;
  527. if (channel->irq_moderation < coalesce->tx_coalesce_usecs_irq) {
  528. if (channel->channel < efx->n_rx_channels)
  529. coalesce->tx_coalesce_usecs_irq =
  530. channel->irq_moderation;
  531. else
  532. coalesce->tx_coalesce_usecs_irq = 0;
  533. }
  534. }
  535. coalesce->use_adaptive_rx_coalesce = efx->irq_rx_adaptive;
  536. coalesce->rx_coalesce_usecs_irq = efx->irq_rx_moderation;
  537. coalesce->tx_coalesce_usecs_irq *= EFX_IRQ_MOD_RESOLUTION;
  538. coalesce->rx_coalesce_usecs_irq *= EFX_IRQ_MOD_RESOLUTION;
  539. return 0;
  540. }
  541. /* Set coalescing parameters
  542. * The difficulties occur for shared channels
  543. */
  544. static int efx_ethtool_set_coalesce(struct net_device *net_dev,
  545. struct ethtool_coalesce *coalesce)
  546. {
  547. struct efx_nic *efx = netdev_priv(net_dev);
  548. struct efx_channel *channel;
  549. unsigned tx_usecs, rx_usecs, adaptive;
  550. if (coalesce->use_adaptive_tx_coalesce)
  551. return -EOPNOTSUPP;
  552. if (coalesce->rx_coalesce_usecs || coalesce->tx_coalesce_usecs) {
  553. netif_err(efx, drv, efx->net_dev, "invalid coalescing setting. "
  554. "Only rx/tx_coalesce_usecs_irq are supported\n");
  555. return -EOPNOTSUPP;
  556. }
  557. rx_usecs = coalesce->rx_coalesce_usecs_irq;
  558. tx_usecs = coalesce->tx_coalesce_usecs_irq;
  559. adaptive = coalesce->use_adaptive_rx_coalesce;
  560. /* If the channel is shared only allow RX parameters to be set */
  561. efx_for_each_channel(channel, efx) {
  562. if (efx_channel_has_rx_queue(channel) &&
  563. efx_channel_has_tx_queues(channel) &&
  564. tx_usecs) {
  565. netif_err(efx, drv, efx->net_dev, "Channel is shared. "
  566. "Only RX coalescing may be set\n");
  567. return -EOPNOTSUPP;
  568. }
  569. }
  570. efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive);
  571. efx_for_each_channel(channel, efx)
  572. efx->type->push_irq_moderation(channel);
  573. return 0;
  574. }
  575. static void efx_ethtool_get_ringparam(struct net_device *net_dev,
  576. struct ethtool_ringparam *ring)
  577. {
  578. struct efx_nic *efx = netdev_priv(net_dev);
  579. ring->rx_max_pending = EFX_MAX_DMAQ_SIZE;
  580. ring->tx_max_pending = EFX_MAX_DMAQ_SIZE;
  581. ring->rx_mini_max_pending = 0;
  582. ring->rx_jumbo_max_pending = 0;
  583. ring->rx_pending = efx->rxq_entries;
  584. ring->tx_pending = efx->txq_entries;
  585. ring->rx_mini_pending = 0;
  586. ring->rx_jumbo_pending = 0;
  587. }
  588. static int efx_ethtool_set_ringparam(struct net_device *net_dev,
  589. struct ethtool_ringparam *ring)
  590. {
  591. struct efx_nic *efx = netdev_priv(net_dev);
  592. if (ring->rx_mini_pending || ring->rx_jumbo_pending ||
  593. ring->rx_pending > EFX_MAX_DMAQ_SIZE ||
  594. ring->tx_pending > EFX_MAX_DMAQ_SIZE)
  595. return -EINVAL;
  596. if (ring->rx_pending < EFX_MIN_RING_SIZE ||
  597. ring->tx_pending < EFX_MIN_RING_SIZE) {
  598. netif_err(efx, drv, efx->net_dev,
  599. "TX and RX queues cannot be smaller than %ld\n",
  600. EFX_MIN_RING_SIZE);
  601. return -EINVAL;
  602. }
  603. return efx_realloc_channels(efx, ring->rx_pending, ring->tx_pending);
  604. }
  605. static int efx_ethtool_set_pauseparam(struct net_device *net_dev,
  606. struct ethtool_pauseparam *pause)
  607. {
  608. struct efx_nic *efx = netdev_priv(net_dev);
  609. u8 wanted_fc, old_fc;
  610. u32 old_adv;
  611. bool reset;
  612. int rc = 0;
  613. mutex_lock(&efx->mac_lock);
  614. wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
  615. (pause->tx_pause ? EFX_FC_TX : 0) |
  616. (pause->autoneg ? EFX_FC_AUTO : 0));
  617. if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
  618. netif_dbg(efx, drv, efx->net_dev,
  619. "Flow control unsupported: tx ON rx OFF\n");
  620. rc = -EINVAL;
  621. goto out;
  622. }
  623. if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising) {
  624. netif_dbg(efx, drv, efx->net_dev,
  625. "Autonegotiation is disabled\n");
  626. rc = -EINVAL;
  627. goto out;
  628. }
  629. /* TX flow control may automatically turn itself off if the
  630. * link partner (intermittently) stops responding to pause
  631. * frames. There isn't any indication that this has happened,
  632. * so the best we do is leave it up to the user to spot this
  633. * and fix it be cycling transmit flow control on this end. */
  634. reset = (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX);
  635. if (EFX_WORKAROUND_11482(efx) && reset) {
  636. if (efx_nic_rev(efx) == EFX_REV_FALCON_B0) {
  637. /* Recover by resetting the EM block */
  638. falcon_stop_nic_stats(efx);
  639. falcon_drain_tx_fifo(efx);
  640. efx->mac_op->reconfigure(efx);
  641. falcon_start_nic_stats(efx);
  642. } else {
  643. /* Schedule a reset to recover */
  644. efx_schedule_reset(efx, RESET_TYPE_INVISIBLE);
  645. }
  646. }
  647. old_adv = efx->link_advertising;
  648. old_fc = efx->wanted_fc;
  649. efx_link_set_wanted_fc(efx, wanted_fc);
  650. if (efx->link_advertising != old_adv ||
  651. (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) {
  652. rc = efx->phy_op->reconfigure(efx);
  653. if (rc) {
  654. netif_err(efx, drv, efx->net_dev,
  655. "Unable to advertise requested flow "
  656. "control setting\n");
  657. goto out;
  658. }
  659. }
  660. /* Reconfigure the MAC. The PHY *may* generate a link state change event
  661. * if the user just changed the advertised capabilities, but there's no
  662. * harm doing this twice */
  663. efx->mac_op->reconfigure(efx);
  664. out:
  665. mutex_unlock(&efx->mac_lock);
  666. return rc;
  667. }
  668. static void efx_ethtool_get_pauseparam(struct net_device *net_dev,
  669. struct ethtool_pauseparam *pause)
  670. {
  671. struct efx_nic *efx = netdev_priv(net_dev);
  672. pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX);
  673. pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX);
  674. pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO);
  675. }
  676. static void efx_ethtool_get_wol(struct net_device *net_dev,
  677. struct ethtool_wolinfo *wol)
  678. {
  679. struct efx_nic *efx = netdev_priv(net_dev);
  680. return efx->type->get_wol(efx, wol);
  681. }
  682. static int efx_ethtool_set_wol(struct net_device *net_dev,
  683. struct ethtool_wolinfo *wol)
  684. {
  685. struct efx_nic *efx = netdev_priv(net_dev);
  686. return efx->type->set_wol(efx, wol->wolopts);
  687. }
  688. static int efx_ethtool_reset(struct net_device *net_dev, u32 *flags)
  689. {
  690. struct efx_nic *efx = netdev_priv(net_dev);
  691. int rc;
  692. rc = efx->type->map_reset_flags(flags);
  693. if (rc < 0)
  694. return rc;
  695. return efx_reset(efx, rc);
  696. }
  697. static int
  698. efx_ethtool_get_rxnfc(struct net_device *net_dev,
  699. struct ethtool_rxnfc *info, void *rules __always_unused)
  700. {
  701. struct efx_nic *efx = netdev_priv(net_dev);
  702. switch (info->cmd) {
  703. case ETHTOOL_GRXRINGS:
  704. info->data = efx->n_rx_channels;
  705. return 0;
  706. case ETHTOOL_GRXFH: {
  707. unsigned min_revision = 0;
  708. info->data = 0;
  709. switch (info->flow_type) {
  710. case TCP_V4_FLOW:
  711. info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  712. /* fall through */
  713. case UDP_V4_FLOW:
  714. case SCTP_V4_FLOW:
  715. case AH_ESP_V4_FLOW:
  716. case IPV4_FLOW:
  717. info->data |= RXH_IP_SRC | RXH_IP_DST;
  718. min_revision = EFX_REV_FALCON_B0;
  719. break;
  720. case TCP_V6_FLOW:
  721. info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  722. /* fall through */
  723. case UDP_V6_FLOW:
  724. case SCTP_V6_FLOW:
  725. case AH_ESP_V6_FLOW:
  726. case IPV6_FLOW:
  727. info->data |= RXH_IP_SRC | RXH_IP_DST;
  728. min_revision = EFX_REV_SIENA_A0;
  729. break;
  730. default:
  731. break;
  732. }
  733. if (efx_nic_rev(efx) < min_revision)
  734. info->data = 0;
  735. return 0;
  736. }
  737. default:
  738. return -EOPNOTSUPP;
  739. }
  740. }
  741. static int efx_ethtool_set_rx_ntuple(struct net_device *net_dev,
  742. struct ethtool_rx_ntuple *ntuple)
  743. {
  744. struct efx_nic *efx = netdev_priv(net_dev);
  745. struct ethtool_tcpip4_spec *ip_entry = &ntuple->fs.h_u.tcp_ip4_spec;
  746. struct ethtool_tcpip4_spec *ip_mask = &ntuple->fs.m_u.tcp_ip4_spec;
  747. struct ethhdr *mac_entry = &ntuple->fs.h_u.ether_spec;
  748. struct ethhdr *mac_mask = &ntuple->fs.m_u.ether_spec;
  749. struct efx_filter_spec filter;
  750. int rc;
  751. /* Range-check action */
  752. if (ntuple->fs.action < ETHTOOL_RXNTUPLE_ACTION_CLEAR ||
  753. ntuple->fs.action >= (s32)efx->n_rx_channels)
  754. return -EINVAL;
  755. if (~ntuple->fs.data_mask)
  756. return -EINVAL;
  757. efx_filter_init_rx(&filter, EFX_FILTER_PRI_MANUAL, 0,
  758. (ntuple->fs.action == ETHTOOL_RXNTUPLE_ACTION_DROP) ?
  759. 0xfff : ntuple->fs.action);
  760. switch (ntuple->fs.flow_type) {
  761. case TCP_V4_FLOW:
  762. case UDP_V4_FLOW: {
  763. u8 proto = (ntuple->fs.flow_type == TCP_V4_FLOW ?
  764. IPPROTO_TCP : IPPROTO_UDP);
  765. /* Must match all of destination, */
  766. if (ip_mask->ip4dst | ip_mask->pdst)
  767. return -EINVAL;
  768. /* all or none of source, */
  769. if ((ip_mask->ip4src | ip_mask->psrc) &&
  770. ((__force u32)~ip_mask->ip4src |
  771. (__force u16)~ip_mask->psrc))
  772. return -EINVAL;
  773. /* and nothing else */
  774. if ((u8)~ip_mask->tos | (u16)~ntuple->fs.vlan_tag_mask)
  775. return -EINVAL;
  776. if (!ip_mask->ip4src)
  777. rc = efx_filter_set_ipv4_full(&filter, proto,
  778. ip_entry->ip4dst,
  779. ip_entry->pdst,
  780. ip_entry->ip4src,
  781. ip_entry->psrc);
  782. else
  783. rc = efx_filter_set_ipv4_local(&filter, proto,
  784. ip_entry->ip4dst,
  785. ip_entry->pdst);
  786. if (rc)
  787. return rc;
  788. break;
  789. }
  790. case ETHER_FLOW:
  791. /* Must match all of destination, */
  792. if (!is_zero_ether_addr(mac_mask->h_dest))
  793. return -EINVAL;
  794. /* all or none of VID, */
  795. if (ntuple->fs.vlan_tag_mask != 0xf000 &&
  796. ntuple->fs.vlan_tag_mask != 0xffff)
  797. return -EINVAL;
  798. /* and nothing else */
  799. if (!is_broadcast_ether_addr(mac_mask->h_source) ||
  800. mac_mask->h_proto != htons(0xffff))
  801. return -EINVAL;
  802. rc = efx_filter_set_eth_local(
  803. &filter,
  804. (ntuple->fs.vlan_tag_mask == 0xf000) ?
  805. ntuple->fs.vlan_tag : EFX_FILTER_VID_UNSPEC,
  806. mac_entry->h_dest);
  807. if (rc)
  808. return rc;
  809. break;
  810. default:
  811. return -EINVAL;
  812. }
  813. if (ntuple->fs.action == ETHTOOL_RXNTUPLE_ACTION_CLEAR)
  814. return efx_filter_remove_filter(efx, &filter);
  815. rc = efx_filter_insert_filter(efx, &filter, true);
  816. return rc < 0 ? rc : 0;
  817. }
  818. static int efx_ethtool_get_rxfh_indir(struct net_device *net_dev,
  819. struct ethtool_rxfh_indir *indir)
  820. {
  821. struct efx_nic *efx = netdev_priv(net_dev);
  822. size_t copy_size =
  823. min_t(size_t, indir->size, ARRAY_SIZE(efx->rx_indir_table));
  824. if (efx_nic_rev(efx) < EFX_REV_FALCON_B0)
  825. return -EOPNOTSUPP;
  826. indir->size = ARRAY_SIZE(efx->rx_indir_table);
  827. memcpy(indir->ring_index, efx->rx_indir_table,
  828. copy_size * sizeof(indir->ring_index[0]));
  829. return 0;
  830. }
  831. static int efx_ethtool_set_rxfh_indir(struct net_device *net_dev,
  832. const struct ethtool_rxfh_indir *indir)
  833. {
  834. struct efx_nic *efx = netdev_priv(net_dev);
  835. size_t i;
  836. if (efx_nic_rev(efx) < EFX_REV_FALCON_B0)
  837. return -EOPNOTSUPP;
  838. /* Validate size and indices */
  839. if (indir->size != ARRAY_SIZE(efx->rx_indir_table))
  840. return -EINVAL;
  841. for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); i++)
  842. if (indir->ring_index[i] >= efx->n_rx_channels)
  843. return -EINVAL;
  844. memcpy(efx->rx_indir_table, indir->ring_index,
  845. sizeof(efx->rx_indir_table));
  846. efx_nic_push_rx_indir_table(efx);
  847. return 0;
  848. }
  849. const struct ethtool_ops efx_ethtool_ops = {
  850. .get_settings = efx_ethtool_get_settings,
  851. .set_settings = efx_ethtool_set_settings,
  852. .get_drvinfo = efx_ethtool_get_drvinfo,
  853. .get_regs_len = efx_ethtool_get_regs_len,
  854. .get_regs = efx_ethtool_get_regs,
  855. .get_msglevel = efx_ethtool_get_msglevel,
  856. .set_msglevel = efx_ethtool_set_msglevel,
  857. .nway_reset = efx_ethtool_nway_reset,
  858. .get_link = ethtool_op_get_link,
  859. .get_coalesce = efx_ethtool_get_coalesce,
  860. .set_coalesce = efx_ethtool_set_coalesce,
  861. .get_ringparam = efx_ethtool_get_ringparam,
  862. .set_ringparam = efx_ethtool_set_ringparam,
  863. .get_pauseparam = efx_ethtool_get_pauseparam,
  864. .set_pauseparam = efx_ethtool_set_pauseparam,
  865. .get_sset_count = efx_ethtool_get_sset_count,
  866. .self_test = efx_ethtool_self_test,
  867. .get_strings = efx_ethtool_get_strings,
  868. .set_phys_id = efx_ethtool_phys_id,
  869. .get_ethtool_stats = efx_ethtool_get_stats,
  870. .get_wol = efx_ethtool_get_wol,
  871. .set_wol = efx_ethtool_set_wol,
  872. .reset = efx_ethtool_reset,
  873. .get_rxnfc = efx_ethtool_get_rxnfc,
  874. .set_rx_ntuple = efx_ethtool_set_rx_ntuple,
  875. .get_rxfh_indir = efx_ethtool_get_rxfh_indir,
  876. .set_rxfh_indir = efx_ethtool_set_rxfh_indir,
  877. };