ethtool.c 34 KB

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