ethtool.c 29 KB

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