ethtool.c 33 KB

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