ethtool_common.c 38 KB

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