ethtool_common.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /****************************************************************************
  3. * Driver for Solarflare network controllers and boards
  4. * Copyright 2019 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/module.h>
  11. #include <linux/netdevice.h>
  12. #include "net_driver.h"
  13. #include "mcdi.h"
  14. #include "nic.h"
  15. #include "selftest.h"
  16. #include "rx_common.h"
  17. #include "ethtool_common.h"
  18. #include "mcdi_port_common.h"
  19. struct efx_sw_stat_desc {
  20. const char *name;
  21. enum {
  22. EFX_ETHTOOL_STAT_SOURCE_nic,
  23. EFX_ETHTOOL_STAT_SOURCE_channel,
  24. EFX_ETHTOOL_STAT_SOURCE_tx_queue
  25. } source;
  26. unsigned int offset;
  27. u64 (*get_stat)(void *field); /* Reader function */
  28. };
  29. /* Initialiser for a struct efx_sw_stat_desc with type-checking */
  30. #define EFX_ETHTOOL_STAT(stat_name, source_name, field, field_type, \
  31. get_stat_function) { \
  32. .name = #stat_name, \
  33. .source = EFX_ETHTOOL_STAT_SOURCE_##source_name, \
  34. .offset = ((((field_type *) 0) == \
  35. &((struct efx_##source_name *)0)->field) ? \
  36. offsetof(struct efx_##source_name, field) : \
  37. offsetof(struct efx_##source_name, field)), \
  38. .get_stat = get_stat_function, \
  39. }
  40. static u64 efx_get_uint_stat(void *field)
  41. {
  42. return *(unsigned int *)field;
  43. }
  44. static u64 efx_get_atomic_stat(void *field)
  45. {
  46. return atomic_read((atomic_t *) field);
  47. }
  48. #define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field) \
  49. EFX_ETHTOOL_STAT(field, nic, field, \
  50. atomic_t, efx_get_atomic_stat)
  51. #define EFX_ETHTOOL_UINT_CHANNEL_STAT(field) \
  52. EFX_ETHTOOL_STAT(field, channel, n_##field, \
  53. unsigned int, efx_get_uint_stat)
  54. #define EFX_ETHTOOL_UINT_CHANNEL_STAT_NO_N(field) \
  55. EFX_ETHTOOL_STAT(field, channel, field, \
  56. unsigned int, efx_get_uint_stat)
  57. #define EFX_ETHTOOL_UINT_TXQ_STAT(field) \
  58. EFX_ETHTOOL_STAT(tx_##field, tx_queue, field, \
  59. unsigned int, efx_get_uint_stat)
  60. static const struct efx_sw_stat_desc efx_sw_stat_desc[] = {
  61. EFX_ETHTOOL_UINT_TXQ_STAT(merge_events),
  62. EFX_ETHTOOL_UINT_TXQ_STAT(tso_bursts),
  63. EFX_ETHTOOL_UINT_TXQ_STAT(tso_long_headers),
  64. EFX_ETHTOOL_UINT_TXQ_STAT(tso_packets),
  65. EFX_ETHTOOL_UINT_TXQ_STAT(tso_fallbacks),
  66. EFX_ETHTOOL_UINT_TXQ_STAT(pushes),
  67. EFX_ETHTOOL_UINT_TXQ_STAT(pio_packets),
  68. EFX_ETHTOOL_UINT_TXQ_STAT(cb_packets),
  69. EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset),
  70. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),
  71. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err),
  72. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_inner_ip_hdr_chksum_err),
  73. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_inner_tcp_udp_chksum_err),
  74. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_outer_ip_hdr_chksum_err),
  75. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_outer_tcp_udp_chksum_err),
  76. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_eth_crc_err),
  77. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
  78. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_overlength),
  79. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_events),
  80. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_packets),
  81. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_xdp_drops),
  82. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_xdp_bad_drops),
  83. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_xdp_tx),
  84. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_xdp_redirect),
  85. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mport_bad),
  86. #ifdef CONFIG_RFS_ACCEL
  87. EFX_ETHTOOL_UINT_CHANNEL_STAT_NO_N(rfs_filter_count),
  88. EFX_ETHTOOL_UINT_CHANNEL_STAT(rfs_succeeded),
  89. EFX_ETHTOOL_UINT_CHANNEL_STAT(rfs_failed),
  90. #endif
  91. };
  92. #define EFX_ETHTOOL_SW_STAT_COUNT ARRAY_SIZE(efx_sw_stat_desc)
  93. void efx_ethtool_get_drvinfo(struct net_device *net_dev,
  94. struct ethtool_drvinfo *info)
  95. {
  96. struct efx_nic *efx = efx_netdev_priv(net_dev);
  97. strscpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
  98. efx_mcdi_print_fwver(efx, info->fw_version,
  99. sizeof(info->fw_version));
  100. strscpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
  101. }
  102. u32 efx_ethtool_get_msglevel(struct net_device *net_dev)
  103. {
  104. struct efx_nic *efx = efx_netdev_priv(net_dev);
  105. return efx->msg_enable;
  106. }
  107. void efx_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable)
  108. {
  109. struct efx_nic *efx = efx_netdev_priv(net_dev);
  110. efx->msg_enable = msg_enable;
  111. }
  112. void efx_ethtool_self_test(struct net_device *net_dev,
  113. struct ethtool_test *test, u64 *data)
  114. {
  115. struct efx_nic *efx = efx_netdev_priv(net_dev);
  116. struct efx_self_tests *efx_tests;
  117. bool already_up;
  118. int rc = -ENOMEM;
  119. efx_tests = kzalloc_obj(*efx_tests);
  120. if (!efx_tests)
  121. goto fail;
  122. if (!efx_net_active(efx->state)) {
  123. rc = -EBUSY;
  124. goto out;
  125. }
  126. netif_info(efx, drv, efx->net_dev, "starting %sline testing\n",
  127. (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
  128. /* We need rx buffers and interrupts. */
  129. already_up = (efx->net_dev->flags & IFF_UP);
  130. if (!already_up) {
  131. rc = dev_open(efx->net_dev, NULL);
  132. if (rc) {
  133. netif_err(efx, drv, efx->net_dev,
  134. "failed opening device.\n");
  135. goto out;
  136. }
  137. }
  138. rc = efx_selftest(efx, efx_tests, test->flags);
  139. if (!already_up)
  140. dev_close(efx->net_dev);
  141. netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n",
  142. rc == 0 ? "passed" : "failed",
  143. (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
  144. out:
  145. efx_ethtool_fill_self_tests(efx, efx_tests, NULL, data);
  146. kfree(efx_tests);
  147. fail:
  148. if (rc)
  149. test->flags |= ETH_TEST_FL_FAILED;
  150. }
  151. void efx_ethtool_get_pauseparam(struct net_device *net_dev,
  152. struct ethtool_pauseparam *pause)
  153. {
  154. struct efx_nic *efx = efx_netdev_priv(net_dev);
  155. pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX);
  156. pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX);
  157. pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO);
  158. }
  159. int efx_ethtool_set_pauseparam(struct net_device *net_dev,
  160. struct ethtool_pauseparam *pause)
  161. {
  162. struct efx_nic *efx = efx_netdev_priv(net_dev);
  163. u8 wanted_fc, old_fc;
  164. u32 old_adv;
  165. int rc = 0;
  166. mutex_lock(&efx->mac_lock);
  167. wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
  168. (pause->tx_pause ? EFX_FC_TX : 0) |
  169. (pause->autoneg ? EFX_FC_AUTO : 0));
  170. if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
  171. netif_dbg(efx, drv, efx->net_dev,
  172. "Flow control unsupported: tx ON rx OFF\n");
  173. rc = -EINVAL;
  174. goto out;
  175. }
  176. if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising[0]) {
  177. netif_dbg(efx, drv, efx->net_dev,
  178. "Autonegotiation is disabled\n");
  179. rc = -EINVAL;
  180. goto out;
  181. }
  182. /* Hook for Falcon bug 11482 workaround */
  183. if (efx->type->prepare_enable_fc_tx &&
  184. (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX))
  185. efx->type->prepare_enable_fc_tx(efx);
  186. old_adv = efx->link_advertising[0];
  187. old_fc = efx->wanted_fc;
  188. efx_link_set_wanted_fc(efx, wanted_fc);
  189. if (efx->link_advertising[0] != old_adv ||
  190. (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) {
  191. rc = efx_mcdi_port_reconfigure(efx);
  192. if (rc) {
  193. netif_err(efx, drv, efx->net_dev,
  194. "Unable to advertise requested flow "
  195. "control setting\n");
  196. goto out;
  197. }
  198. }
  199. /* Reconfigure the MAC. The PHY *may* generate a link state change event
  200. * if the user just changed the advertised capabilities, but there's no
  201. * harm doing this twice */
  202. efx_mac_reconfigure(efx, false);
  203. out:
  204. mutex_unlock(&efx->mac_lock);
  205. return rc;
  206. }
  207. /**
  208. * efx_fill_test - fill in an individual self-test entry
  209. * @test_index: Index of the test
  210. * @strings: Ethtool strings, or %NULL
  211. * @data: Ethtool test results, or %NULL
  212. * @test: Pointer to test result (used only if data != %NULL)
  213. * @unit_format: Unit name format (e.g. "chan\%d")
  214. * @unit_id: Unit id (e.g. 0 for "chan0")
  215. * @test_format: Test name format (e.g. "loopback.\%s.tx.sent")
  216. * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
  217. *
  218. * Fill in an individual self-test entry.
  219. */
  220. static void efx_fill_test(unsigned int test_index, u8 *strings, u64 *data,
  221. int *test, const char *unit_format, int unit_id,
  222. const char *test_format, const char *test_id)
  223. {
  224. char unit_str[ETH_GSTRING_LEN], test_str[ETH_GSTRING_LEN];
  225. /* Fill data value, if applicable */
  226. if (data)
  227. data[test_index] = *test;
  228. /* Fill string, if applicable */
  229. if (strings) {
  230. if (strchr(unit_format, '%'))
  231. snprintf(unit_str, sizeof(unit_str),
  232. unit_format, unit_id);
  233. else
  234. strcpy(unit_str, unit_format);
  235. snprintf(test_str, sizeof(test_str), test_format, test_id);
  236. snprintf(strings + test_index * ETH_GSTRING_LEN,
  237. ETH_GSTRING_LEN,
  238. "%-6s %-24s", unit_str, test_str);
  239. }
  240. }
  241. #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
  242. #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->label
  243. #define EFX_LOOPBACK_NAME(_mode, _counter) \
  244. "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode)
  245. /**
  246. * efx_fill_loopback_test - fill in a block of loopback self-test entries
  247. * @efx: Efx NIC
  248. * @lb_tests: Efx loopback self-test results structure
  249. * @mode: Loopback test mode
  250. * @test_index: Starting index of the test
  251. * @strings: Ethtool strings, or %NULL
  252. * @data: Ethtool test results, or %NULL
  253. *
  254. * Fill in a block of loopback self-test entries. Return new test
  255. * index.
  256. */
  257. static int efx_fill_loopback_test(struct efx_nic *efx,
  258. struct efx_loopback_self_tests *lb_tests,
  259. enum efx_loopback_mode mode,
  260. unsigned int test_index,
  261. u8 *strings, u64 *data)
  262. {
  263. struct efx_channel *channel =
  264. efx_get_channel(efx, efx->tx_channel_offset);
  265. struct efx_tx_queue *tx_queue;
  266. efx_for_each_channel_tx_queue(tx_queue, channel) {
  267. efx_fill_test(test_index++, strings, data,
  268. &lb_tests->tx_sent[tx_queue->label],
  269. EFX_TX_QUEUE_NAME(tx_queue),
  270. EFX_LOOPBACK_NAME(mode, "tx_sent"));
  271. efx_fill_test(test_index++, strings, data,
  272. &lb_tests->tx_done[tx_queue->label],
  273. EFX_TX_QUEUE_NAME(tx_queue),
  274. EFX_LOOPBACK_NAME(mode, "tx_done"));
  275. }
  276. efx_fill_test(test_index++, strings, data,
  277. &lb_tests->rx_good,
  278. "rx", 0,
  279. EFX_LOOPBACK_NAME(mode, "rx_good"));
  280. efx_fill_test(test_index++, strings, data,
  281. &lb_tests->rx_bad,
  282. "rx", 0,
  283. EFX_LOOPBACK_NAME(mode, "rx_bad"));
  284. return test_index;
  285. }
  286. /**
  287. * efx_ethtool_fill_self_tests - get self-test details
  288. * @efx: Efx NIC
  289. * @tests: Efx self-test results structure, or %NULL
  290. * @strings: Ethtool strings, or %NULL
  291. * @data: Ethtool test results, or %NULL
  292. *
  293. * Get self-test number of strings, strings, and/or test results.
  294. * Return number of strings (== number of test results).
  295. *
  296. * The reason for merging these three functions is to make sure that
  297. * they can never be inconsistent.
  298. */
  299. int efx_ethtool_fill_self_tests(struct efx_nic *efx,
  300. struct efx_self_tests *tests,
  301. u8 *strings, u64 *data)
  302. {
  303. struct efx_channel *channel;
  304. unsigned int n = 0, i;
  305. enum efx_loopback_mode mode;
  306. efx_fill_test(n++, strings, data, &tests->phy_alive,
  307. "phy", 0, "alive", NULL);
  308. efx_fill_test(n++, strings, data, &tests->nvram,
  309. "core", 0, "nvram", NULL);
  310. efx_fill_test(n++, strings, data, &tests->interrupt,
  311. "core", 0, "interrupt", NULL);
  312. /* Event queues */
  313. efx_for_each_channel(channel, efx) {
  314. efx_fill_test(n++, strings, data,
  315. &tests->eventq_dma[channel->channel],
  316. EFX_CHANNEL_NAME(channel),
  317. "eventq.dma", NULL);
  318. efx_fill_test(n++, strings, data,
  319. &tests->eventq_int[channel->channel],
  320. EFX_CHANNEL_NAME(channel),
  321. "eventq.int", NULL);
  322. }
  323. efx_fill_test(n++, strings, data, &tests->memory,
  324. "core", 0, "memory", NULL);
  325. efx_fill_test(n++, strings, data, &tests->registers,
  326. "core", 0, "registers", NULL);
  327. for (i = 0; true; ++i) {
  328. const char *name;
  329. EFX_WARN_ON_PARANOID(i >= EFX_MAX_PHY_TESTS);
  330. name = efx_mcdi_phy_test_name(efx, i);
  331. if (name == NULL)
  332. break;
  333. efx_fill_test(n++, strings, data, &tests->phy_ext[i], "phy", 0, name, NULL);
  334. }
  335. /* Loopback tests */
  336. for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
  337. if (!(efx->loopback_modes & (1 << mode)))
  338. continue;
  339. n = efx_fill_loopback_test(efx,
  340. &tests->loopback[mode], mode, n,
  341. strings, data);
  342. }
  343. return n;
  344. }
  345. static size_t efx_describe_per_queue_stats(struct efx_nic *efx, u8 **strings)
  346. {
  347. size_t n_stats = 0;
  348. struct efx_channel *channel;
  349. efx_for_each_channel(channel, efx) {
  350. if (efx_channel_has_tx_queues(channel)) {
  351. n_stats++;
  352. if (!strings)
  353. continue;
  354. ethtool_sprintf(strings, "tx-%u.tx_packets",
  355. channel->tx_queue[0].queue /
  356. EFX_MAX_TXQ_PER_CHANNEL);
  357. }
  358. }
  359. efx_for_each_channel(channel, efx) {
  360. if (efx_channel_has_rx_queue(channel)) {
  361. n_stats++;
  362. if (!strings)
  363. continue;
  364. ethtool_sprintf(strings, "rx-%d.rx_packets",
  365. channel->channel);
  366. }
  367. }
  368. if (efx->xdp_tx_queue_count && efx->xdp_tx_queues) {
  369. unsigned short xdp;
  370. for (xdp = 0; xdp < efx->xdp_tx_queue_count; xdp++) {
  371. n_stats++;
  372. if (!strings)
  373. continue;
  374. ethtool_sprintf(strings, "tx-xdp-cpu-%hu.tx_packets",
  375. xdp);
  376. }
  377. }
  378. return n_stats;
  379. }
  380. int efx_ethtool_get_sset_count(struct net_device *net_dev, int string_set)
  381. {
  382. struct efx_nic *efx = efx_netdev_priv(net_dev);
  383. switch (string_set) {
  384. case ETH_SS_STATS:
  385. return efx->type->describe_stats(efx, NULL) +
  386. EFX_ETHTOOL_SW_STAT_COUNT +
  387. efx_describe_per_queue_stats(efx, NULL) +
  388. efx_ptp_describe_stats(efx, NULL);
  389. case ETH_SS_TEST:
  390. return efx_ethtool_fill_self_tests(efx, NULL, NULL, NULL);
  391. default:
  392. return -EINVAL;
  393. }
  394. }
  395. void efx_ethtool_get_strings(struct net_device *net_dev,
  396. u32 string_set, u8 *strings)
  397. {
  398. struct efx_nic *efx = efx_netdev_priv(net_dev);
  399. int i;
  400. switch (string_set) {
  401. case ETH_SS_STATS:
  402. efx->type->describe_stats(efx, &strings);
  403. for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++)
  404. ethtool_puts(&strings, efx_sw_stat_desc[i].name);
  405. efx_describe_per_queue_stats(efx, &strings);
  406. efx_ptp_describe_stats(efx, &strings);
  407. break;
  408. case ETH_SS_TEST:
  409. efx_ethtool_fill_self_tests(efx, NULL, strings, NULL);
  410. break;
  411. default:
  412. /* No other string sets */
  413. break;
  414. }
  415. }
  416. void efx_ethtool_get_stats(struct net_device *net_dev,
  417. struct ethtool_stats *stats,
  418. u64 *data)
  419. {
  420. struct efx_nic *efx = efx_netdev_priv(net_dev);
  421. const struct efx_sw_stat_desc *stat;
  422. struct efx_channel *channel;
  423. struct efx_tx_queue *tx_queue;
  424. struct efx_rx_queue *rx_queue;
  425. int i;
  426. spin_lock_bh(&efx->stats_lock);
  427. /* Get NIC statistics */
  428. data += efx->type->update_stats(efx, data, NULL);
  429. /* Get software statistics */
  430. for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) {
  431. stat = &efx_sw_stat_desc[i];
  432. switch (stat->source) {
  433. case EFX_ETHTOOL_STAT_SOURCE_nic:
  434. data[i] = stat->get_stat((void *)efx + stat->offset);
  435. break;
  436. case EFX_ETHTOOL_STAT_SOURCE_channel:
  437. data[i] = 0;
  438. efx_for_each_channel(channel, efx)
  439. data[i] += stat->get_stat((void *)channel +
  440. stat->offset);
  441. break;
  442. case EFX_ETHTOOL_STAT_SOURCE_tx_queue:
  443. data[i] = 0;
  444. efx_for_each_channel(channel, efx) {
  445. efx_for_each_channel_tx_queue(tx_queue, channel)
  446. data[i] +=
  447. stat->get_stat((void *)tx_queue
  448. + stat->offset);
  449. }
  450. break;
  451. }
  452. }
  453. data += EFX_ETHTOOL_SW_STAT_COUNT;
  454. spin_unlock_bh(&efx->stats_lock);
  455. efx_for_each_channel(channel, efx) {
  456. if (efx_channel_has_tx_queues(channel)) {
  457. *data = 0;
  458. efx_for_each_channel_tx_queue(tx_queue, channel) {
  459. *data += tx_queue->tx_packets;
  460. }
  461. data++;
  462. }
  463. }
  464. efx_for_each_channel(channel, efx) {
  465. if (efx_channel_has_rx_queue(channel)) {
  466. *data = 0;
  467. efx_for_each_channel_rx_queue(rx_queue, channel) {
  468. *data += rx_queue->rx_packets;
  469. }
  470. data++;
  471. }
  472. }
  473. if (efx->xdp_tx_queue_count && efx->xdp_tx_queues) {
  474. int xdp;
  475. for (xdp = 0; xdp < efx->xdp_tx_queue_count; xdp++) {
  476. data[0] = efx->xdp_tx_queues[xdp]->tx_packets;
  477. data++;
  478. }
  479. }
  480. efx_ptp_update_stats(efx, data);
  481. }
  482. /* This must be called with rtnl_lock held. */
  483. int efx_ethtool_get_link_ksettings(struct net_device *net_dev,
  484. struct ethtool_link_ksettings *cmd)
  485. {
  486. struct efx_nic *efx = efx_netdev_priv(net_dev);
  487. struct efx_link_state *link_state = &efx->link_state;
  488. mutex_lock(&efx->mac_lock);
  489. efx_mcdi_phy_get_link_ksettings(efx, cmd);
  490. mutex_unlock(&efx->mac_lock);
  491. /* Both MACs support pause frames (bidirectional and respond-only) */
  492. ethtool_link_ksettings_add_link_mode(cmd, supported, Pause);
  493. ethtool_link_ksettings_add_link_mode(cmd, supported, Asym_Pause);
  494. if (LOOPBACK_INTERNAL(efx)) {
  495. cmd->base.speed = link_state->speed;
  496. cmd->base.duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF;
  497. }
  498. return 0;
  499. }
  500. /* This must be called with rtnl_lock held. */
  501. int efx_ethtool_set_link_ksettings(struct net_device *net_dev,
  502. const struct ethtool_link_ksettings *cmd)
  503. {
  504. struct efx_nic *efx = efx_netdev_priv(net_dev);
  505. int rc;
  506. /* GMAC does not support 1000Mbps HD */
  507. if ((cmd->base.speed == SPEED_1000) &&
  508. (cmd->base.duplex != DUPLEX_FULL)) {
  509. netif_dbg(efx, drv, efx->net_dev,
  510. "rejecting unsupported 1000Mbps HD setting\n");
  511. return -EINVAL;
  512. }
  513. mutex_lock(&efx->mac_lock);
  514. rc = efx_mcdi_phy_set_link_ksettings(efx, cmd);
  515. mutex_unlock(&efx->mac_lock);
  516. return rc;
  517. }
  518. int efx_ethtool_get_fecparam(struct net_device *net_dev,
  519. struct ethtool_fecparam *fecparam)
  520. {
  521. struct efx_nic *efx = efx_netdev_priv(net_dev);
  522. int rc;
  523. mutex_lock(&efx->mac_lock);
  524. rc = efx_mcdi_phy_get_fecparam(efx, fecparam);
  525. mutex_unlock(&efx->mac_lock);
  526. return rc;
  527. }
  528. int efx_ethtool_set_fecparam(struct net_device *net_dev,
  529. struct ethtool_fecparam *fecparam)
  530. {
  531. struct efx_nic *efx = efx_netdev_priv(net_dev);
  532. int rc;
  533. mutex_lock(&efx->mac_lock);
  534. rc = efx_mcdi_phy_set_fecparam(efx, fecparam);
  535. mutex_unlock(&efx->mac_lock);
  536. return rc;
  537. }
  538. /* MAC address mask including only I/G bit */
  539. static const u8 mac_addr_ig_mask[ETH_ALEN] __aligned(2) = {0x01, 0, 0, 0, 0, 0};
  540. #define IP4_ADDR_FULL_MASK ((__force __be32)~0)
  541. #define IP_PROTO_FULL_MASK 0xFF
  542. #define PORT_FULL_MASK ((__force __be16)~0)
  543. #define ETHER_TYPE_FULL_MASK ((__force __be16)~0)
  544. static inline void ip6_fill_mask(__be32 *mask)
  545. {
  546. mask[0] = mask[1] = mask[2] = mask[3] = ~(__be32)0;
  547. }
  548. static int efx_ethtool_get_class_rule(struct efx_nic *efx,
  549. struct ethtool_rx_flow_spec *rule,
  550. u32 *rss_context)
  551. {
  552. struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
  553. struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
  554. struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
  555. struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
  556. struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
  557. struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
  558. struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
  559. struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
  560. struct ethhdr *mac_entry = &rule->h_u.ether_spec;
  561. struct ethhdr *mac_mask = &rule->m_u.ether_spec;
  562. struct efx_filter_spec spec;
  563. int rc;
  564. rc = efx_filter_get_filter_safe(efx, EFX_FILTER_PRI_MANUAL,
  565. rule->location, &spec);
  566. if (rc)
  567. return rc;
  568. if (spec.dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP)
  569. rule->ring_cookie = RX_CLS_FLOW_DISC;
  570. else
  571. rule->ring_cookie = spec.dmaq_id;
  572. if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) &&
  573. spec.ether_type == htons(ETH_P_IP) &&
  574. (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) &&
  575. (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
  576. !(spec.match_flags &
  577. ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
  578. EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
  579. EFX_FILTER_MATCH_IP_PROTO |
  580. EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) {
  581. rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
  582. TCP_V4_FLOW : UDP_V4_FLOW);
  583. if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
  584. ip_entry->ip4dst = spec.loc_host[0];
  585. ip_mask->ip4dst = IP4_ADDR_FULL_MASK;
  586. }
  587. if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
  588. ip_entry->ip4src = spec.rem_host[0];
  589. ip_mask->ip4src = IP4_ADDR_FULL_MASK;
  590. }
  591. if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) {
  592. ip_entry->pdst = spec.loc_port;
  593. ip_mask->pdst = PORT_FULL_MASK;
  594. }
  595. if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) {
  596. ip_entry->psrc = spec.rem_port;
  597. ip_mask->psrc = PORT_FULL_MASK;
  598. }
  599. } else if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) &&
  600. spec.ether_type == htons(ETH_P_IPV6) &&
  601. (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) &&
  602. (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
  603. !(spec.match_flags &
  604. ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
  605. EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
  606. EFX_FILTER_MATCH_IP_PROTO |
  607. EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) {
  608. rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
  609. TCP_V6_FLOW : UDP_V6_FLOW);
  610. if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
  611. memcpy(ip6_entry->ip6dst, spec.loc_host,
  612. sizeof(ip6_entry->ip6dst));
  613. ip6_fill_mask(ip6_mask->ip6dst);
  614. }
  615. if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
  616. memcpy(ip6_entry->ip6src, spec.rem_host,
  617. sizeof(ip6_entry->ip6src));
  618. ip6_fill_mask(ip6_mask->ip6src);
  619. }
  620. if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) {
  621. ip6_entry->pdst = spec.loc_port;
  622. ip6_mask->pdst = PORT_FULL_MASK;
  623. }
  624. if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) {
  625. ip6_entry->psrc = spec.rem_port;
  626. ip6_mask->psrc = PORT_FULL_MASK;
  627. }
  628. } else if (!(spec.match_flags &
  629. ~(EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG |
  630. EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_ETHER_TYPE |
  631. EFX_FILTER_MATCH_OUTER_VID))) {
  632. rule->flow_type = ETHER_FLOW;
  633. if (spec.match_flags &
  634. (EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG)) {
  635. ether_addr_copy(mac_entry->h_dest, spec.loc_mac);
  636. if (spec.match_flags & EFX_FILTER_MATCH_LOC_MAC)
  637. eth_broadcast_addr(mac_mask->h_dest);
  638. else
  639. ether_addr_copy(mac_mask->h_dest,
  640. mac_addr_ig_mask);
  641. }
  642. if (spec.match_flags & EFX_FILTER_MATCH_REM_MAC) {
  643. ether_addr_copy(mac_entry->h_source, spec.rem_mac);
  644. eth_broadcast_addr(mac_mask->h_source);
  645. }
  646. if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) {
  647. mac_entry->h_proto = spec.ether_type;
  648. mac_mask->h_proto = ETHER_TYPE_FULL_MASK;
  649. }
  650. } else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
  651. spec.ether_type == htons(ETH_P_IP) &&
  652. !(spec.match_flags &
  653. ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
  654. EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
  655. EFX_FILTER_MATCH_IP_PROTO))) {
  656. rule->flow_type = IPV4_USER_FLOW;
  657. uip_entry->ip_ver = ETH_RX_NFC_IP4;
  658. if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) {
  659. uip_mask->proto = IP_PROTO_FULL_MASK;
  660. uip_entry->proto = spec.ip_proto;
  661. }
  662. if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
  663. uip_entry->ip4dst = spec.loc_host[0];
  664. uip_mask->ip4dst = IP4_ADDR_FULL_MASK;
  665. }
  666. if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
  667. uip_entry->ip4src = spec.rem_host[0];
  668. uip_mask->ip4src = IP4_ADDR_FULL_MASK;
  669. }
  670. } else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
  671. spec.ether_type == htons(ETH_P_IPV6) &&
  672. !(spec.match_flags &
  673. ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
  674. EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
  675. EFX_FILTER_MATCH_IP_PROTO))) {
  676. rule->flow_type = IPV6_USER_FLOW;
  677. if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) {
  678. uip6_mask->l4_proto = IP_PROTO_FULL_MASK;
  679. uip6_entry->l4_proto = spec.ip_proto;
  680. }
  681. if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
  682. memcpy(uip6_entry->ip6dst, spec.loc_host,
  683. sizeof(uip6_entry->ip6dst));
  684. ip6_fill_mask(uip6_mask->ip6dst);
  685. }
  686. if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
  687. memcpy(uip6_entry->ip6src, spec.rem_host,
  688. sizeof(uip6_entry->ip6src));
  689. ip6_fill_mask(uip6_mask->ip6src);
  690. }
  691. } else {
  692. /* The above should handle all filters that we insert */
  693. WARN_ON(1);
  694. return -EINVAL;
  695. }
  696. if (spec.match_flags & EFX_FILTER_MATCH_OUTER_VID) {
  697. rule->flow_type |= FLOW_EXT;
  698. rule->h_ext.vlan_tci = spec.outer_vid;
  699. rule->m_ext.vlan_tci = htons(0xfff);
  700. }
  701. if (spec.flags & EFX_FILTER_FLAG_RX_RSS) {
  702. rule->flow_type |= FLOW_RSS;
  703. *rss_context = spec.rss_context;
  704. }
  705. return rc;
  706. }
  707. int efx_ethtool_get_rxfh_fields(struct net_device *net_dev,
  708. struct ethtool_rxfh_fields *info)
  709. {
  710. struct efx_nic *efx = efx_netdev_priv(net_dev);
  711. struct efx_rss_context_priv *ctx;
  712. __u64 data;
  713. int rc = 0;
  714. ctx = &efx->rss_context.priv;
  715. if (info->rss_context) {
  716. ctx = efx_find_rss_context_entry(efx, info->rss_context);
  717. if (!ctx)
  718. return -ENOENT;
  719. }
  720. data = 0;
  721. if (!efx_rss_active(ctx)) /* No RSS */
  722. goto out_setdata_unlock;
  723. switch (info->flow_type) {
  724. case UDP_V4_FLOW:
  725. case UDP_V6_FLOW:
  726. if (ctx->rx_hash_udp_4tuple)
  727. data = (RXH_L4_B_0_1 | RXH_L4_B_2_3 |
  728. RXH_IP_SRC | RXH_IP_DST);
  729. else
  730. data = RXH_IP_SRC | RXH_IP_DST;
  731. break;
  732. case TCP_V4_FLOW:
  733. case TCP_V6_FLOW:
  734. data = (RXH_L4_B_0_1 | RXH_L4_B_2_3 |
  735. RXH_IP_SRC | RXH_IP_DST);
  736. break;
  737. case SCTP_V4_FLOW:
  738. case SCTP_V6_FLOW:
  739. case AH_ESP_V4_FLOW:
  740. case AH_ESP_V6_FLOW:
  741. case IPV4_FLOW:
  742. case IPV6_FLOW:
  743. data = RXH_IP_SRC | RXH_IP_DST;
  744. break;
  745. default:
  746. break;
  747. }
  748. out_setdata_unlock:
  749. info->data = data;
  750. return rc;
  751. }
  752. u32 efx_ethtool_get_rx_ring_count(struct net_device *net_dev)
  753. {
  754. struct efx_nic *efx = efx_netdev_priv(net_dev);
  755. return efx->n_rx_channels;
  756. }
  757. int efx_ethtool_get_rxnfc(struct net_device *net_dev,
  758. struct ethtool_rxnfc *info, u32 *rule_locs)
  759. {
  760. struct efx_nic *efx = efx_netdev_priv(net_dev);
  761. u32 rss_context = 0;
  762. s32 rc = 0;
  763. switch (info->cmd) {
  764. case ETHTOOL_GRXCLSRLCNT:
  765. info->data = efx_filter_get_rx_id_limit(efx);
  766. if (info->data == 0)
  767. return -EOPNOTSUPP;
  768. info->data |= RX_CLS_LOC_SPECIAL;
  769. info->rule_cnt =
  770. efx_filter_count_rx_used(efx, EFX_FILTER_PRI_MANUAL);
  771. return 0;
  772. case ETHTOOL_GRXCLSRULE:
  773. if (efx_filter_get_rx_id_limit(efx) == 0)
  774. return -EOPNOTSUPP;
  775. rc = efx_ethtool_get_class_rule(efx, &info->fs, &rss_context);
  776. if (rc < 0)
  777. return rc;
  778. if (info->fs.flow_type & FLOW_RSS)
  779. info->rss_context = rss_context;
  780. return 0;
  781. case ETHTOOL_GRXCLSRLALL:
  782. info->data = efx_filter_get_rx_id_limit(efx);
  783. if (info->data == 0)
  784. return -EOPNOTSUPP;
  785. rc = efx_filter_get_rx_ids(efx, EFX_FILTER_PRI_MANUAL,
  786. rule_locs, info->rule_cnt);
  787. if (rc < 0)
  788. return rc;
  789. info->rule_cnt = rc;
  790. return 0;
  791. default:
  792. return -EOPNOTSUPP;
  793. }
  794. }
  795. static inline bool ip6_mask_is_full(__be32 mask[4])
  796. {
  797. return !~(mask[0] & mask[1] & mask[2] & mask[3]);
  798. }
  799. static inline bool ip6_mask_is_empty(__be32 mask[4])
  800. {
  801. return !(mask[0] | mask[1] | mask[2] | mask[3]);
  802. }
  803. static int efx_ethtool_set_class_rule(struct efx_nic *efx,
  804. struct ethtool_rx_flow_spec *rule,
  805. u32 rss_context)
  806. {
  807. struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
  808. struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
  809. struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
  810. struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
  811. struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
  812. struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
  813. struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
  814. struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
  815. u32 flow_type = rule->flow_type & ~(FLOW_EXT | FLOW_RSS);
  816. struct ethhdr *mac_entry = &rule->h_u.ether_spec;
  817. struct ethhdr *mac_mask = &rule->m_u.ether_spec;
  818. enum efx_filter_flags flags = 0;
  819. struct efx_filter_spec spec;
  820. int rc;
  821. /* Check that user wants us to choose the location */
  822. if (rule->location != RX_CLS_LOC_ANY)
  823. return -EINVAL;
  824. /* Range-check ring_cookie */
  825. if (rule->ring_cookie >= efx->n_rx_channels &&
  826. rule->ring_cookie != RX_CLS_FLOW_DISC)
  827. return -EINVAL;
  828. /* Check for unsupported extensions */
  829. if ((rule->flow_type & FLOW_EXT) &&
  830. (rule->m_ext.vlan_etype || rule->m_ext.data[0] ||
  831. rule->m_ext.data[1]))
  832. return -EINVAL;
  833. if (efx->rx_scatter)
  834. flags |= EFX_FILTER_FLAG_RX_SCATTER;
  835. if (rule->flow_type & FLOW_RSS)
  836. flags |= EFX_FILTER_FLAG_RX_RSS;
  837. efx_filter_init_rx(&spec, EFX_FILTER_PRI_MANUAL, flags,
  838. (rule->ring_cookie == RX_CLS_FLOW_DISC) ?
  839. EFX_FILTER_RX_DMAQ_ID_DROP : rule->ring_cookie);
  840. if (rule->flow_type & FLOW_RSS)
  841. spec.rss_context = rss_context;
  842. switch (flow_type) {
  843. case TCP_V4_FLOW:
  844. case UDP_V4_FLOW:
  845. spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
  846. EFX_FILTER_MATCH_IP_PROTO);
  847. spec.ether_type = htons(ETH_P_IP);
  848. spec.ip_proto = flow_type == TCP_V4_FLOW ? IPPROTO_TCP
  849. : IPPROTO_UDP;
  850. if (ip_mask->ip4dst) {
  851. if (ip_mask->ip4dst != IP4_ADDR_FULL_MASK)
  852. return -EINVAL;
  853. spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
  854. spec.loc_host[0] = ip_entry->ip4dst;
  855. }
  856. if (ip_mask->ip4src) {
  857. if (ip_mask->ip4src != IP4_ADDR_FULL_MASK)
  858. return -EINVAL;
  859. spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
  860. spec.rem_host[0] = ip_entry->ip4src;
  861. }
  862. if (ip_mask->pdst) {
  863. if (ip_mask->pdst != PORT_FULL_MASK)
  864. return -EINVAL;
  865. spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
  866. spec.loc_port = ip_entry->pdst;
  867. }
  868. if (ip_mask->psrc) {
  869. if (ip_mask->psrc != PORT_FULL_MASK)
  870. return -EINVAL;
  871. spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
  872. spec.rem_port = ip_entry->psrc;
  873. }
  874. if (ip_mask->tos)
  875. return -EINVAL;
  876. break;
  877. case TCP_V6_FLOW:
  878. case UDP_V6_FLOW:
  879. spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
  880. EFX_FILTER_MATCH_IP_PROTO);
  881. spec.ether_type = htons(ETH_P_IPV6);
  882. spec.ip_proto = flow_type == TCP_V6_FLOW ? IPPROTO_TCP
  883. : IPPROTO_UDP;
  884. if (!ip6_mask_is_empty(ip6_mask->ip6dst)) {
  885. if (!ip6_mask_is_full(ip6_mask->ip6dst))
  886. return -EINVAL;
  887. spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
  888. memcpy(spec.loc_host, ip6_entry->ip6dst, sizeof(spec.loc_host));
  889. }
  890. if (!ip6_mask_is_empty(ip6_mask->ip6src)) {
  891. if (!ip6_mask_is_full(ip6_mask->ip6src))
  892. return -EINVAL;
  893. spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
  894. memcpy(spec.rem_host, ip6_entry->ip6src, sizeof(spec.rem_host));
  895. }
  896. if (ip6_mask->pdst) {
  897. if (ip6_mask->pdst != PORT_FULL_MASK)
  898. return -EINVAL;
  899. spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
  900. spec.loc_port = ip6_entry->pdst;
  901. }
  902. if (ip6_mask->psrc) {
  903. if (ip6_mask->psrc != PORT_FULL_MASK)
  904. return -EINVAL;
  905. spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
  906. spec.rem_port = ip6_entry->psrc;
  907. }
  908. if (ip6_mask->tclass)
  909. return -EINVAL;
  910. break;
  911. case IPV4_USER_FLOW:
  912. if (uip_mask->l4_4_bytes || uip_mask->tos || uip_mask->ip_ver ||
  913. uip_entry->ip_ver != ETH_RX_NFC_IP4)
  914. return -EINVAL;
  915. spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE;
  916. spec.ether_type = htons(ETH_P_IP);
  917. if (uip_mask->ip4dst) {
  918. if (uip_mask->ip4dst != IP4_ADDR_FULL_MASK)
  919. return -EINVAL;
  920. spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
  921. spec.loc_host[0] = uip_entry->ip4dst;
  922. }
  923. if (uip_mask->ip4src) {
  924. if (uip_mask->ip4src != IP4_ADDR_FULL_MASK)
  925. return -EINVAL;
  926. spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
  927. spec.rem_host[0] = uip_entry->ip4src;
  928. }
  929. if (uip_mask->proto) {
  930. if (uip_mask->proto != IP_PROTO_FULL_MASK)
  931. return -EINVAL;
  932. spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO;
  933. spec.ip_proto = uip_entry->proto;
  934. }
  935. break;
  936. case IPV6_USER_FLOW:
  937. if (uip6_mask->l4_4_bytes || uip6_mask->tclass)
  938. return -EINVAL;
  939. spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE;
  940. spec.ether_type = htons(ETH_P_IPV6);
  941. if (!ip6_mask_is_empty(uip6_mask->ip6dst)) {
  942. if (!ip6_mask_is_full(uip6_mask->ip6dst))
  943. return -EINVAL;
  944. spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
  945. memcpy(spec.loc_host, uip6_entry->ip6dst, sizeof(spec.loc_host));
  946. }
  947. if (!ip6_mask_is_empty(uip6_mask->ip6src)) {
  948. if (!ip6_mask_is_full(uip6_mask->ip6src))
  949. return -EINVAL;
  950. spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
  951. memcpy(spec.rem_host, uip6_entry->ip6src, sizeof(spec.rem_host));
  952. }
  953. if (uip6_mask->l4_proto) {
  954. if (uip6_mask->l4_proto != IP_PROTO_FULL_MASK)
  955. return -EINVAL;
  956. spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO;
  957. spec.ip_proto = uip6_entry->l4_proto;
  958. }
  959. break;
  960. case ETHER_FLOW:
  961. if (!is_zero_ether_addr(mac_mask->h_dest)) {
  962. if (ether_addr_equal(mac_mask->h_dest,
  963. mac_addr_ig_mask))
  964. spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC_IG;
  965. else if (is_broadcast_ether_addr(mac_mask->h_dest))
  966. spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC;
  967. else
  968. return -EINVAL;
  969. ether_addr_copy(spec.loc_mac, mac_entry->h_dest);
  970. }
  971. if (!is_zero_ether_addr(mac_mask->h_source)) {
  972. if (!is_broadcast_ether_addr(mac_mask->h_source))
  973. return -EINVAL;
  974. spec.match_flags |= EFX_FILTER_MATCH_REM_MAC;
  975. ether_addr_copy(spec.rem_mac, mac_entry->h_source);
  976. }
  977. if (mac_mask->h_proto) {
  978. if (mac_mask->h_proto != ETHER_TYPE_FULL_MASK)
  979. return -EINVAL;
  980. spec.match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
  981. spec.ether_type = mac_entry->h_proto;
  982. }
  983. break;
  984. default:
  985. return -EINVAL;
  986. }
  987. if ((rule->flow_type & FLOW_EXT) && rule->m_ext.vlan_tci) {
  988. if (rule->m_ext.vlan_tci != htons(0xfff))
  989. return -EINVAL;
  990. spec.match_flags |= EFX_FILTER_MATCH_OUTER_VID;
  991. spec.outer_vid = rule->h_ext.vlan_tci;
  992. }
  993. rc = efx_filter_insert_filter(efx, &spec, true);
  994. if (rc < 0)
  995. return rc;
  996. rule->location = rc;
  997. return 0;
  998. }
  999. int efx_ethtool_set_rxnfc(struct net_device *net_dev,
  1000. struct ethtool_rxnfc *info)
  1001. {
  1002. struct efx_nic *efx = efx_netdev_priv(net_dev);
  1003. if (efx_filter_get_rx_id_limit(efx) == 0)
  1004. return -EOPNOTSUPP;
  1005. switch (info->cmd) {
  1006. case ETHTOOL_SRXCLSRLINS:
  1007. return efx_ethtool_set_class_rule(efx, &info->fs,
  1008. info->rss_context);
  1009. case ETHTOOL_SRXCLSRLDEL:
  1010. return efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_MANUAL,
  1011. info->fs.location);
  1012. default:
  1013. return -EOPNOTSUPP;
  1014. }
  1015. }
  1016. u32 efx_ethtool_get_rxfh_indir_size(struct net_device *net_dev)
  1017. {
  1018. struct efx_nic *efx = efx_netdev_priv(net_dev);
  1019. if (efx->n_rx_channels == 1)
  1020. return 0;
  1021. return ARRAY_SIZE(efx->rss_context.rx_indir_table);
  1022. }
  1023. u32 efx_ethtool_get_rxfh_key_size(struct net_device *net_dev)
  1024. {
  1025. struct efx_nic *efx = efx_netdev_priv(net_dev);
  1026. return efx->type->rx_hash_key_size;
  1027. }
  1028. int efx_ethtool_get_rxfh(struct net_device *net_dev,
  1029. struct ethtool_rxfh_param *rxfh)
  1030. {
  1031. struct efx_nic *efx = efx_netdev_priv(net_dev);
  1032. int rc;
  1033. if (rxfh->rss_context) /* core should never call us for these */
  1034. return -EINVAL;
  1035. rc = efx->type->rx_pull_rss_config(efx);
  1036. if (rc)
  1037. return rc;
  1038. rxfh->hfunc = ETH_RSS_HASH_TOP;
  1039. if (rxfh->indir)
  1040. memcpy(rxfh->indir, efx->rss_context.rx_indir_table,
  1041. sizeof(efx->rss_context.rx_indir_table));
  1042. if (rxfh->key)
  1043. memcpy(rxfh->key, efx->rss_context.rx_hash_key,
  1044. efx->type->rx_hash_key_size);
  1045. return 0;
  1046. }
  1047. int efx_ethtool_modify_rxfh_context(struct net_device *net_dev,
  1048. struct ethtool_rxfh_context *ctx,
  1049. const struct ethtool_rxfh_param *rxfh,
  1050. struct netlink_ext_ack *extack)
  1051. {
  1052. struct efx_nic *efx = efx_netdev_priv(net_dev);
  1053. struct efx_rss_context_priv *priv;
  1054. const u32 *indir = rxfh->indir;
  1055. const u8 *key = rxfh->key;
  1056. if (!efx->type->rx_push_rss_context_config) {
  1057. NL_SET_ERR_MSG_MOD(extack,
  1058. "NIC type does not support custom contexts");
  1059. return -EOPNOTSUPP;
  1060. }
  1061. /* Hash function is Toeplitz, cannot be changed */
  1062. if (rxfh->hfunc != ETH_RSS_HASH_NO_CHANGE &&
  1063. rxfh->hfunc != ETH_RSS_HASH_TOP) {
  1064. NL_SET_ERR_MSG_MOD(extack, "Only Toeplitz hash is supported");
  1065. return -EOPNOTSUPP;
  1066. }
  1067. priv = ethtool_rxfh_context_priv(ctx);
  1068. if (!key)
  1069. key = ethtool_rxfh_context_key(ctx);
  1070. if (!indir)
  1071. indir = ethtool_rxfh_context_indir(ctx);
  1072. return efx->type->rx_push_rss_context_config(efx, priv, indir, key,
  1073. false);
  1074. }
  1075. int efx_ethtool_create_rxfh_context(struct net_device *net_dev,
  1076. struct ethtool_rxfh_context *ctx,
  1077. const struct ethtool_rxfh_param *rxfh,
  1078. struct netlink_ext_ack *extack)
  1079. {
  1080. struct efx_nic *efx = efx_netdev_priv(net_dev);
  1081. struct efx_rss_context_priv *priv;
  1082. priv = ethtool_rxfh_context_priv(ctx);
  1083. priv->context_id = EFX_MCDI_RSS_CONTEXT_INVALID;
  1084. priv->rx_hash_udp_4tuple = false;
  1085. /* Generate default indir table and/or key if not specified.
  1086. * We use ctx as a place to store these; this is fine because
  1087. * we're doing a create, so if we fail then the ctx will just
  1088. * be deleted.
  1089. */
  1090. if (!rxfh->indir)
  1091. efx_set_default_rx_indir_table(efx, ethtool_rxfh_context_indir(ctx));
  1092. if (!rxfh->key)
  1093. netdev_rss_key_fill(ethtool_rxfh_context_key(ctx),
  1094. ctx->key_size);
  1095. if (rxfh->hfunc == ETH_RSS_HASH_NO_CHANGE)
  1096. ctx->hfunc = ETH_RSS_HASH_TOP;
  1097. if (rxfh->input_xfrm == RXH_XFRM_NO_CHANGE)
  1098. ctx->input_xfrm = 0;
  1099. return efx_ethtool_modify_rxfh_context(net_dev, ctx, rxfh, extack);
  1100. }
  1101. int efx_ethtool_remove_rxfh_context(struct net_device *net_dev,
  1102. struct ethtool_rxfh_context *ctx,
  1103. u32 rss_context,
  1104. struct netlink_ext_ack *extack)
  1105. {
  1106. struct efx_nic *efx = efx_netdev_priv(net_dev);
  1107. struct efx_rss_context_priv *priv;
  1108. if (!efx->type->rx_push_rss_context_config) {
  1109. NL_SET_ERR_MSG_MOD(extack,
  1110. "NIC type does not support custom contexts");
  1111. return -EOPNOTSUPP;
  1112. }
  1113. priv = ethtool_rxfh_context_priv(ctx);
  1114. return efx->type->rx_push_rss_context_config(efx, priv, NULL, NULL,
  1115. true);
  1116. }
  1117. int efx_ethtool_set_rxfh(struct net_device *net_dev,
  1118. struct ethtool_rxfh_param *rxfh,
  1119. struct netlink_ext_ack *extack)
  1120. {
  1121. struct efx_nic *efx = efx_netdev_priv(net_dev);
  1122. u32 *indir = rxfh->indir;
  1123. u8 *key = rxfh->key;
  1124. /* Hash function is Toeplitz, cannot be changed */
  1125. if (rxfh->hfunc != ETH_RSS_HASH_NO_CHANGE &&
  1126. rxfh->hfunc != ETH_RSS_HASH_TOP)
  1127. return -EOPNOTSUPP;
  1128. /* Custom contexts should use new API */
  1129. if (WARN_ON_ONCE(rxfh->rss_context))
  1130. return -EIO;
  1131. if (!indir && !key)
  1132. return 0;
  1133. if (!key)
  1134. key = efx->rss_context.rx_hash_key;
  1135. if (!indir)
  1136. indir = efx->rss_context.rx_indir_table;
  1137. return efx->type->rx_push_rss_config(efx, true, indir, key);
  1138. }
  1139. int efx_ethtool_reset(struct net_device *net_dev, u32 *flags)
  1140. {
  1141. struct efx_nic *efx = efx_netdev_priv(net_dev);
  1142. int rc;
  1143. rc = efx->type->map_reset_flags(flags);
  1144. if (rc < 0)
  1145. return rc;
  1146. return efx_reset(efx, rc);
  1147. }
  1148. int efx_ethtool_get_module_eeprom(struct net_device *net_dev,
  1149. struct ethtool_eeprom *ee,
  1150. u8 *data)
  1151. {
  1152. struct efx_nic *efx = efx_netdev_priv(net_dev);
  1153. int ret;
  1154. mutex_lock(&efx->mac_lock);
  1155. ret = efx_mcdi_phy_get_module_eeprom(efx, ee, data);
  1156. mutex_unlock(&efx->mac_lock);
  1157. return ret;
  1158. }
  1159. int efx_ethtool_get_module_info(struct net_device *net_dev,
  1160. struct ethtool_modinfo *modinfo)
  1161. {
  1162. struct efx_nic *efx = efx_netdev_priv(net_dev);
  1163. int ret;
  1164. mutex_lock(&efx->mac_lock);
  1165. ret = efx_mcdi_phy_get_module_info(efx, modinfo);
  1166. mutex_unlock(&efx->mac_lock);
  1167. return ret;
  1168. }