ethtool_common.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235
  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. #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_siena_ethtool_get_drvinfo(struct net_device *net_dev,
  94. struct ethtool_drvinfo *info)
  95. {
  96. struct efx_nic *efx = netdev_priv(net_dev);
  97. strscpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
  98. efx_siena_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_siena_ethtool_get_msglevel(struct net_device *net_dev)
  103. {
  104. struct efx_nic *efx = netdev_priv(net_dev);
  105. return efx->msg_enable;
  106. }
  107. void efx_siena_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable)
  108. {
  109. struct efx_nic *efx = netdev_priv(net_dev);
  110. efx->msg_enable = msg_enable;
  111. }
  112. void efx_siena_ethtool_get_pauseparam(struct net_device *net_dev,
  113. struct ethtool_pauseparam *pause)
  114. {
  115. struct efx_nic *efx = netdev_priv(net_dev);
  116. pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX);
  117. pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX);
  118. pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO);
  119. }
  120. int efx_siena_ethtool_set_pauseparam(struct net_device *net_dev,
  121. struct ethtool_pauseparam *pause)
  122. {
  123. struct efx_nic *efx = netdev_priv(net_dev);
  124. u8 wanted_fc, old_fc;
  125. u32 old_adv;
  126. int rc = 0;
  127. mutex_lock(&efx->mac_lock);
  128. wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
  129. (pause->tx_pause ? EFX_FC_TX : 0) |
  130. (pause->autoneg ? EFX_FC_AUTO : 0));
  131. if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
  132. netif_dbg(efx, drv, efx->net_dev,
  133. "Flow control unsupported: tx ON rx OFF\n");
  134. rc = -EINVAL;
  135. goto out;
  136. }
  137. if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising[0]) {
  138. netif_dbg(efx, drv, efx->net_dev,
  139. "Autonegotiation is disabled\n");
  140. rc = -EINVAL;
  141. goto out;
  142. }
  143. /* Hook for Falcon bug 11482 workaround */
  144. if (efx->type->prepare_enable_fc_tx &&
  145. (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX))
  146. efx->type->prepare_enable_fc_tx(efx);
  147. old_adv = efx->link_advertising[0];
  148. old_fc = efx->wanted_fc;
  149. efx_siena_link_set_wanted_fc(efx, wanted_fc);
  150. if (efx->link_advertising[0] != old_adv ||
  151. (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) {
  152. rc = efx_siena_mcdi_port_reconfigure(efx);
  153. if (rc) {
  154. netif_err(efx, drv, efx->net_dev,
  155. "Unable to advertise requested flow "
  156. "control setting\n");
  157. goto out;
  158. }
  159. }
  160. /* Reconfigure the MAC. The PHY *may* generate a link state change event
  161. * if the user just changed the advertised capabilities, but there's no
  162. * harm doing this twice */
  163. efx_siena_mac_reconfigure(efx, false);
  164. out:
  165. mutex_unlock(&efx->mac_lock);
  166. return rc;
  167. }
  168. /**
  169. * efx_fill_test - fill in an individual self-test entry
  170. * @test_index: Index of the test
  171. * @strings: Ethtool strings, or %NULL
  172. * @data: Ethtool test results, or %NULL
  173. * @test: Pointer to test result (used only if data != %NULL)
  174. * @unit_format: Unit name format (e.g. "chan\%d")
  175. * @unit_id: Unit id (e.g. 0 for "chan0")
  176. * @test_format: Test name format (e.g. "loopback.\%s.tx.sent")
  177. * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
  178. *
  179. * Fill in an individual self-test entry.
  180. */
  181. static void efx_fill_test(unsigned int test_index, u8 *strings, u64 *data,
  182. int *test, const char *unit_format, int unit_id,
  183. const char *test_format, const char *test_id)
  184. {
  185. char unit_str[ETH_GSTRING_LEN], test_str[ETH_GSTRING_LEN];
  186. /* Fill data value, if applicable */
  187. if (data)
  188. data[test_index] = *test;
  189. /* Fill string, if applicable */
  190. if (strings) {
  191. if (strchr(unit_format, '%'))
  192. snprintf(unit_str, sizeof(unit_str),
  193. unit_format, unit_id);
  194. else
  195. strcpy(unit_str, unit_format);
  196. snprintf(test_str, sizeof(test_str), test_format, test_id);
  197. snprintf(strings + test_index * ETH_GSTRING_LEN,
  198. ETH_GSTRING_LEN,
  199. "%-6s %-24s", unit_str, test_str);
  200. }
  201. }
  202. #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
  203. #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->label
  204. #define EFX_LOOPBACK_NAME(_mode, _counter) \
  205. "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_siena_loopback_mode)
  206. /**
  207. * efx_fill_loopback_test - fill in a block of loopback self-test entries
  208. * @efx: Efx NIC
  209. * @lb_tests: Efx loopback self-test results structure
  210. * @mode: Loopback test mode
  211. * @test_index: Starting index of the test
  212. * @strings: Ethtool strings, or %NULL
  213. * @data: Ethtool test results, or %NULL
  214. *
  215. * Fill in a block of loopback self-test entries. Return new test
  216. * index.
  217. */
  218. static int efx_fill_loopback_test(struct efx_nic *efx,
  219. struct efx_loopback_self_tests *lb_tests,
  220. enum efx_loopback_mode mode,
  221. unsigned int test_index,
  222. u8 *strings, u64 *data)
  223. {
  224. struct efx_channel *channel =
  225. efx_get_channel(efx, efx->tx_channel_offset);
  226. struct efx_tx_queue *tx_queue;
  227. efx_for_each_channel_tx_queue(tx_queue, channel) {
  228. efx_fill_test(test_index++, strings, data,
  229. &lb_tests->tx_sent[tx_queue->label],
  230. EFX_TX_QUEUE_NAME(tx_queue),
  231. EFX_LOOPBACK_NAME(mode, "tx_sent"));
  232. efx_fill_test(test_index++, strings, data,
  233. &lb_tests->tx_done[tx_queue->label],
  234. EFX_TX_QUEUE_NAME(tx_queue),
  235. EFX_LOOPBACK_NAME(mode, "tx_done"));
  236. }
  237. efx_fill_test(test_index++, strings, data,
  238. &lb_tests->rx_good,
  239. "rx", 0,
  240. EFX_LOOPBACK_NAME(mode, "rx_good"));
  241. efx_fill_test(test_index++, strings, data,
  242. &lb_tests->rx_bad,
  243. "rx", 0,
  244. EFX_LOOPBACK_NAME(mode, "rx_bad"));
  245. return test_index;
  246. }
  247. /**
  248. * efx_ethtool_fill_self_tests - get self-test details
  249. * @efx: Efx NIC
  250. * @tests: Efx self-test results structure, or %NULL
  251. * @strings: Ethtool strings, or %NULL
  252. * @data: Ethtool test results, or %NULL
  253. *
  254. * Get self-test number of strings, strings, and/or test results.
  255. * Return number of strings (== number of test results).
  256. *
  257. * The reason for merging these three functions is to make sure that
  258. * they can never be inconsistent.
  259. */
  260. static int efx_ethtool_fill_self_tests(struct efx_nic *efx,
  261. struct efx_self_tests *tests,
  262. u8 *strings, u64 *data)
  263. {
  264. struct efx_channel *channel;
  265. unsigned int n = 0, i;
  266. enum efx_loopback_mode mode;
  267. efx_fill_test(n++, strings, data, &tests->phy_alive,
  268. "phy", 0, "alive", NULL);
  269. efx_fill_test(n++, strings, data, &tests->nvram,
  270. "core", 0, "nvram", NULL);
  271. efx_fill_test(n++, strings, data, &tests->interrupt,
  272. "core", 0, "interrupt", NULL);
  273. /* Event queues */
  274. efx_for_each_channel(channel, efx) {
  275. efx_fill_test(n++, strings, data,
  276. &tests->eventq_dma[channel->channel],
  277. EFX_CHANNEL_NAME(channel),
  278. "eventq.dma", NULL);
  279. efx_fill_test(n++, strings, data,
  280. &tests->eventq_int[channel->channel],
  281. EFX_CHANNEL_NAME(channel),
  282. "eventq.int", NULL);
  283. }
  284. efx_fill_test(n++, strings, data, &tests->memory,
  285. "core", 0, "memory", NULL);
  286. efx_fill_test(n++, strings, data, &tests->registers,
  287. "core", 0, "registers", NULL);
  288. for (i = 0; true; ++i) {
  289. const char *name;
  290. EFX_WARN_ON_PARANOID(i >= EFX_MAX_PHY_TESTS);
  291. name = efx_siena_mcdi_phy_test_name(efx, i);
  292. if (name == NULL)
  293. break;
  294. efx_fill_test(n++, strings, data, &tests->phy_ext[i], "phy", 0, name, NULL);
  295. }
  296. /* Loopback tests */
  297. for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
  298. if (!(efx->loopback_modes & (1 << mode)))
  299. continue;
  300. n = efx_fill_loopback_test(efx,
  301. &tests->loopback[mode], mode, n,
  302. strings, data);
  303. }
  304. return n;
  305. }
  306. void efx_siena_ethtool_self_test(struct net_device *net_dev,
  307. struct ethtool_test *test, u64 *data)
  308. {
  309. struct efx_nic *efx = netdev_priv(net_dev);
  310. struct efx_self_tests *efx_tests;
  311. bool already_up;
  312. int rc = -ENOMEM;
  313. efx_tests = kzalloc(sizeof(*efx_tests), GFP_KERNEL);
  314. if (!efx_tests)
  315. goto fail;
  316. if (efx->state != STATE_READY) {
  317. rc = -EBUSY;
  318. goto out;
  319. }
  320. netif_info(efx, drv, efx->net_dev, "starting %sline testing\n",
  321. (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
  322. /* We need rx buffers and interrupts. */
  323. already_up = (efx->net_dev->flags & IFF_UP);
  324. if (!already_up) {
  325. rc = dev_open(efx->net_dev, NULL);
  326. if (rc) {
  327. netif_err(efx, drv, efx->net_dev,
  328. "failed opening device.\n");
  329. goto out;
  330. }
  331. }
  332. rc = efx_siena_selftest(efx, efx_tests, test->flags);
  333. if (!already_up)
  334. dev_close(efx->net_dev);
  335. netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n",
  336. rc == 0 ? "passed" : "failed",
  337. (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
  338. out:
  339. efx_ethtool_fill_self_tests(efx, efx_tests, NULL, data);
  340. kfree(efx_tests);
  341. fail:
  342. if (rc)
  343. test->flags |= ETH_TEST_FL_FAILED;
  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 != NULL) {
  353. snprintf(strings, ETH_GSTRING_LEN,
  354. "tx-%u.tx_packets",
  355. channel->tx_queue[0].queue /
  356. EFX_MAX_TXQ_PER_CHANNEL);
  357. strings += ETH_GSTRING_LEN;
  358. }
  359. }
  360. }
  361. efx_for_each_channel(channel, efx) {
  362. if (efx_channel_has_rx_queue(channel)) {
  363. n_stats++;
  364. if (strings != NULL) {
  365. snprintf(strings, ETH_GSTRING_LEN,
  366. "rx-%d.rx_packets", channel->channel);
  367. strings += ETH_GSTRING_LEN;
  368. }
  369. }
  370. }
  371. if (efx->xdp_tx_queue_count && efx->xdp_tx_queues) {
  372. unsigned short xdp;
  373. for (xdp = 0; xdp < efx->xdp_tx_queue_count; xdp++) {
  374. n_stats++;
  375. if (strings) {
  376. snprintf(strings, ETH_GSTRING_LEN,
  377. "tx-xdp-cpu-%hu.tx_packets", xdp);
  378. strings += ETH_GSTRING_LEN;
  379. }
  380. }
  381. }
  382. return n_stats;
  383. }
  384. int efx_siena_ethtool_get_sset_count(struct net_device *net_dev, int string_set)
  385. {
  386. struct efx_nic *efx = netdev_priv(net_dev);
  387. switch (string_set) {
  388. case ETH_SS_STATS:
  389. return efx->type->describe_stats(efx, NULL) +
  390. EFX_ETHTOOL_SW_STAT_COUNT +
  391. efx_describe_per_queue_stats(efx, NULL) +
  392. efx_siena_ptp_describe_stats(efx, NULL);
  393. case ETH_SS_TEST:
  394. return efx_ethtool_fill_self_tests(efx, NULL, NULL, NULL);
  395. default:
  396. return -EINVAL;
  397. }
  398. }
  399. void efx_siena_ethtool_get_strings(struct net_device *net_dev,
  400. u32 string_set, u8 *strings)
  401. {
  402. struct efx_nic *efx = netdev_priv(net_dev);
  403. int i;
  404. switch (string_set) {
  405. case ETH_SS_STATS:
  406. strings += (efx->type->describe_stats(efx, strings) *
  407. ETH_GSTRING_LEN);
  408. for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++)
  409. strscpy(strings + i * ETH_GSTRING_LEN,
  410. efx_sw_stat_desc[i].name, ETH_GSTRING_LEN);
  411. strings += EFX_ETHTOOL_SW_STAT_COUNT * ETH_GSTRING_LEN;
  412. strings += (efx_describe_per_queue_stats(efx, strings) *
  413. ETH_GSTRING_LEN);
  414. efx_siena_ptp_describe_stats(efx, strings);
  415. break;
  416. case ETH_SS_TEST:
  417. efx_ethtool_fill_self_tests(efx, NULL, strings, NULL);
  418. break;
  419. default:
  420. /* No other string sets */
  421. break;
  422. }
  423. }
  424. void efx_siena_ethtool_get_stats(struct net_device *net_dev,
  425. struct ethtool_stats *stats,
  426. u64 *data)
  427. {
  428. struct efx_nic *efx = netdev_priv(net_dev);
  429. const struct efx_sw_stat_desc *stat;
  430. struct efx_channel *channel;
  431. struct efx_tx_queue *tx_queue;
  432. struct efx_rx_queue *rx_queue;
  433. int i;
  434. spin_lock_bh(&efx->stats_lock);
  435. /* Get NIC statistics */
  436. data += efx->type->update_stats(efx, data, NULL);
  437. /* Get software statistics */
  438. for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) {
  439. stat = &efx_sw_stat_desc[i];
  440. switch (stat->source) {
  441. case EFX_ETHTOOL_STAT_SOURCE_nic:
  442. data[i] = stat->get_stat((void *)efx + stat->offset);
  443. break;
  444. case EFX_ETHTOOL_STAT_SOURCE_channel:
  445. data[i] = 0;
  446. efx_for_each_channel(channel, efx)
  447. data[i] += stat->get_stat((void *)channel +
  448. stat->offset);
  449. break;
  450. case EFX_ETHTOOL_STAT_SOURCE_tx_queue:
  451. data[i] = 0;
  452. efx_for_each_channel(channel, efx) {
  453. efx_for_each_channel_tx_queue(tx_queue, channel)
  454. data[i] +=
  455. stat->get_stat((void *)tx_queue
  456. + stat->offset);
  457. }
  458. break;
  459. }
  460. }
  461. data += EFX_ETHTOOL_SW_STAT_COUNT;
  462. spin_unlock_bh(&efx->stats_lock);
  463. efx_for_each_channel(channel, efx) {
  464. if (efx_channel_has_tx_queues(channel)) {
  465. *data = 0;
  466. efx_for_each_channel_tx_queue(tx_queue, channel) {
  467. *data += tx_queue->tx_packets;
  468. }
  469. data++;
  470. }
  471. }
  472. efx_for_each_channel(channel, efx) {
  473. if (efx_channel_has_rx_queue(channel)) {
  474. *data = 0;
  475. efx_for_each_channel_rx_queue(rx_queue, channel) {
  476. *data += rx_queue->rx_packets;
  477. }
  478. data++;
  479. }
  480. }
  481. if (efx->xdp_tx_queue_count && efx->xdp_tx_queues) {
  482. int xdp;
  483. for (xdp = 0; xdp < efx->xdp_tx_queue_count; xdp++) {
  484. data[0] = efx->xdp_tx_queues[xdp]->tx_packets;
  485. data++;
  486. }
  487. }
  488. efx_siena_ptp_update_stats(efx, data);
  489. }
  490. /* This must be called with rtnl_lock held. */
  491. int efx_siena_ethtool_get_link_ksettings(struct net_device *net_dev,
  492. struct ethtool_link_ksettings *cmd)
  493. {
  494. struct efx_nic *efx = netdev_priv(net_dev);
  495. struct efx_link_state *link_state = &efx->link_state;
  496. mutex_lock(&efx->mac_lock);
  497. efx_siena_mcdi_phy_get_link_ksettings(efx, cmd);
  498. mutex_unlock(&efx->mac_lock);
  499. /* Both MACs support pause frames (bidirectional and respond-only) */
  500. ethtool_link_ksettings_add_link_mode(cmd, supported, Pause);
  501. ethtool_link_ksettings_add_link_mode(cmd, supported, Asym_Pause);
  502. if (LOOPBACK_INTERNAL(efx)) {
  503. cmd->base.speed = link_state->speed;
  504. cmd->base.duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF;
  505. }
  506. return 0;
  507. }
  508. /* This must be called with rtnl_lock held. */
  509. int
  510. efx_siena_ethtool_set_link_ksettings(struct net_device *net_dev,
  511. const struct ethtool_link_ksettings *cmd)
  512. {
  513. struct efx_nic *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_siena_mcdi_phy_set_link_ksettings(efx, cmd);
  524. mutex_unlock(&efx->mac_lock);
  525. return rc;
  526. }
  527. int efx_siena_ethtool_get_fecparam(struct net_device *net_dev,
  528. struct ethtool_fecparam *fecparam)
  529. {
  530. struct efx_nic *efx = netdev_priv(net_dev);
  531. int rc;
  532. mutex_lock(&efx->mac_lock);
  533. rc = efx_siena_mcdi_phy_get_fecparam(efx, fecparam);
  534. mutex_unlock(&efx->mac_lock);
  535. return rc;
  536. }
  537. int efx_siena_ethtool_set_fecparam(struct net_device *net_dev,
  538. struct ethtool_fecparam *fecparam)
  539. {
  540. struct efx_nic *efx = netdev_priv(net_dev);
  541. int rc;
  542. mutex_lock(&efx->mac_lock);
  543. rc = efx_siena_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_siena_ethtool_get_rxnfc(struct net_device *net_dev,
  717. struct ethtool_rxnfc *info, u32 *rule_locs)
  718. {
  719. struct efx_nic *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. __u64 data;
  728. data = 0;
  729. if (!efx_rss_active(&efx->rss_context)) /* No RSS */
  730. goto out_setdata;
  731. switch (info->flow_type) {
  732. case UDP_V4_FLOW:
  733. case UDP_V6_FLOW:
  734. if (efx->rss_context.rx_hash_udp_4tuple)
  735. data = (RXH_L4_B_0_1 | RXH_L4_B_2_3 |
  736. RXH_IP_SRC | RXH_IP_DST);
  737. else
  738. data = RXH_IP_SRC | RXH_IP_DST;
  739. break;
  740. case TCP_V4_FLOW:
  741. case TCP_V6_FLOW:
  742. data = (RXH_L4_B_0_1 | RXH_L4_B_2_3 |
  743. RXH_IP_SRC | RXH_IP_DST);
  744. break;
  745. case SCTP_V4_FLOW:
  746. case SCTP_V6_FLOW:
  747. case AH_ESP_V4_FLOW:
  748. case AH_ESP_V6_FLOW:
  749. case IPV4_FLOW:
  750. case IPV6_FLOW:
  751. data = RXH_IP_SRC | RXH_IP_DST;
  752. break;
  753. default:
  754. break;
  755. }
  756. out_setdata:
  757. info->data = data;
  758. return rc;
  759. }
  760. case ETHTOOL_GRXCLSRLCNT:
  761. info->data = efx_filter_get_rx_id_limit(efx);
  762. if (info->data == 0)
  763. return -EOPNOTSUPP;
  764. info->data |= RX_CLS_LOC_SPECIAL;
  765. info->rule_cnt =
  766. efx_filter_count_rx_used(efx, EFX_FILTER_PRI_MANUAL);
  767. return 0;
  768. case ETHTOOL_GRXCLSRULE:
  769. if (efx_filter_get_rx_id_limit(efx) == 0)
  770. return -EOPNOTSUPP;
  771. rc = efx_ethtool_get_class_rule(efx, &info->fs, &rss_context);
  772. if (rc < 0)
  773. return rc;
  774. if (info->fs.flow_type & FLOW_RSS)
  775. info->rss_context = rss_context;
  776. return 0;
  777. case ETHTOOL_GRXCLSRLALL:
  778. info->data = efx_filter_get_rx_id_limit(efx);
  779. if (info->data == 0)
  780. return -EOPNOTSUPP;
  781. rc = efx_filter_get_rx_ids(efx, EFX_FILTER_PRI_MANUAL,
  782. rule_locs, info->rule_cnt);
  783. if (rc < 0)
  784. return rc;
  785. info->rule_cnt = rc;
  786. return 0;
  787. default:
  788. return -EOPNOTSUPP;
  789. }
  790. }
  791. static inline bool ip6_mask_is_full(__be32 mask[4])
  792. {
  793. return !~(mask[0] & mask[1] & mask[2] & mask[3]);
  794. }
  795. static inline bool ip6_mask_is_empty(__be32 mask[4])
  796. {
  797. return !(mask[0] | mask[1] | mask[2] | mask[3]);
  798. }
  799. static int efx_ethtool_set_class_rule(struct efx_nic *efx,
  800. struct ethtool_rx_flow_spec *rule,
  801. u32 rss_context)
  802. {
  803. struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
  804. struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
  805. struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
  806. struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
  807. struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
  808. struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
  809. struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
  810. struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
  811. u32 flow_type = rule->flow_type & ~(FLOW_EXT | FLOW_RSS);
  812. struct ethhdr *mac_entry = &rule->h_u.ether_spec;
  813. struct ethhdr *mac_mask = &rule->m_u.ether_spec;
  814. enum efx_filter_flags flags = 0;
  815. struct efx_filter_spec spec;
  816. int rc;
  817. /* Check that user wants us to choose the location */
  818. if (rule->location != RX_CLS_LOC_ANY)
  819. return -EINVAL;
  820. /* Range-check ring_cookie */
  821. if (rule->ring_cookie >= efx->n_rx_channels &&
  822. rule->ring_cookie != RX_CLS_FLOW_DISC)
  823. return -EINVAL;
  824. /* Check for unsupported extensions */
  825. if ((rule->flow_type & FLOW_EXT) &&
  826. (rule->m_ext.vlan_etype || rule->m_ext.data[0] ||
  827. rule->m_ext.data[1]))
  828. return -EINVAL;
  829. if (efx->rx_scatter)
  830. flags |= EFX_FILTER_FLAG_RX_SCATTER;
  831. if (rule->flow_type & FLOW_RSS)
  832. flags |= EFX_FILTER_FLAG_RX_RSS;
  833. efx_filter_init_rx(&spec, EFX_FILTER_PRI_MANUAL, flags,
  834. (rule->ring_cookie == RX_CLS_FLOW_DISC) ?
  835. EFX_FILTER_RX_DMAQ_ID_DROP : rule->ring_cookie);
  836. if (rule->flow_type & FLOW_RSS)
  837. spec.rss_context = rss_context;
  838. switch (flow_type) {
  839. case TCP_V4_FLOW:
  840. case UDP_V4_FLOW:
  841. spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
  842. EFX_FILTER_MATCH_IP_PROTO);
  843. spec.ether_type = htons(ETH_P_IP);
  844. spec.ip_proto = flow_type == TCP_V4_FLOW ? IPPROTO_TCP
  845. : IPPROTO_UDP;
  846. if (ip_mask->ip4dst) {
  847. if (ip_mask->ip4dst != IP4_ADDR_FULL_MASK)
  848. return -EINVAL;
  849. spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
  850. spec.loc_host[0] = ip_entry->ip4dst;
  851. }
  852. if (ip_mask->ip4src) {
  853. if (ip_mask->ip4src != IP4_ADDR_FULL_MASK)
  854. return -EINVAL;
  855. spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
  856. spec.rem_host[0] = ip_entry->ip4src;
  857. }
  858. if (ip_mask->pdst) {
  859. if (ip_mask->pdst != PORT_FULL_MASK)
  860. return -EINVAL;
  861. spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
  862. spec.loc_port = ip_entry->pdst;
  863. }
  864. if (ip_mask->psrc) {
  865. if (ip_mask->psrc != PORT_FULL_MASK)
  866. return -EINVAL;
  867. spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
  868. spec.rem_port = ip_entry->psrc;
  869. }
  870. if (ip_mask->tos)
  871. return -EINVAL;
  872. break;
  873. case TCP_V6_FLOW:
  874. case UDP_V6_FLOW:
  875. spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
  876. EFX_FILTER_MATCH_IP_PROTO);
  877. spec.ether_type = htons(ETH_P_IPV6);
  878. spec.ip_proto = flow_type == TCP_V6_FLOW ? IPPROTO_TCP
  879. : IPPROTO_UDP;
  880. if (!ip6_mask_is_empty(ip6_mask->ip6dst)) {
  881. if (!ip6_mask_is_full(ip6_mask->ip6dst))
  882. return -EINVAL;
  883. spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
  884. memcpy(spec.loc_host, ip6_entry->ip6dst, sizeof(spec.loc_host));
  885. }
  886. if (!ip6_mask_is_empty(ip6_mask->ip6src)) {
  887. if (!ip6_mask_is_full(ip6_mask->ip6src))
  888. return -EINVAL;
  889. spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
  890. memcpy(spec.rem_host, ip6_entry->ip6src, sizeof(spec.rem_host));
  891. }
  892. if (ip6_mask->pdst) {
  893. if (ip6_mask->pdst != PORT_FULL_MASK)
  894. return -EINVAL;
  895. spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
  896. spec.loc_port = ip6_entry->pdst;
  897. }
  898. if (ip6_mask->psrc) {
  899. if (ip6_mask->psrc != PORT_FULL_MASK)
  900. return -EINVAL;
  901. spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
  902. spec.rem_port = ip6_entry->psrc;
  903. }
  904. if (ip6_mask->tclass)
  905. return -EINVAL;
  906. break;
  907. case IPV4_USER_FLOW:
  908. if (uip_mask->l4_4_bytes || uip_mask->tos || uip_mask->ip_ver ||
  909. uip_entry->ip_ver != ETH_RX_NFC_IP4)
  910. return -EINVAL;
  911. spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE;
  912. spec.ether_type = htons(ETH_P_IP);
  913. if (uip_mask->ip4dst) {
  914. if (uip_mask->ip4dst != IP4_ADDR_FULL_MASK)
  915. return -EINVAL;
  916. spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
  917. spec.loc_host[0] = uip_entry->ip4dst;
  918. }
  919. if (uip_mask->ip4src) {
  920. if (uip_mask->ip4src != IP4_ADDR_FULL_MASK)
  921. return -EINVAL;
  922. spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
  923. spec.rem_host[0] = uip_entry->ip4src;
  924. }
  925. if (uip_mask->proto) {
  926. if (uip_mask->proto != IP_PROTO_FULL_MASK)
  927. return -EINVAL;
  928. spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO;
  929. spec.ip_proto = uip_entry->proto;
  930. }
  931. break;
  932. case IPV6_USER_FLOW:
  933. if (uip6_mask->l4_4_bytes || uip6_mask->tclass)
  934. return -EINVAL;
  935. spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE;
  936. spec.ether_type = htons(ETH_P_IPV6);
  937. if (!ip6_mask_is_empty(uip6_mask->ip6dst)) {
  938. if (!ip6_mask_is_full(uip6_mask->ip6dst))
  939. return -EINVAL;
  940. spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
  941. memcpy(spec.loc_host, uip6_entry->ip6dst, sizeof(spec.loc_host));
  942. }
  943. if (!ip6_mask_is_empty(uip6_mask->ip6src)) {
  944. if (!ip6_mask_is_full(uip6_mask->ip6src))
  945. return -EINVAL;
  946. spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
  947. memcpy(spec.rem_host, uip6_entry->ip6src, sizeof(spec.rem_host));
  948. }
  949. if (uip6_mask->l4_proto) {
  950. if (uip6_mask->l4_proto != IP_PROTO_FULL_MASK)
  951. return -EINVAL;
  952. spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO;
  953. spec.ip_proto = uip6_entry->l4_proto;
  954. }
  955. break;
  956. case ETHER_FLOW:
  957. if (!is_zero_ether_addr(mac_mask->h_dest)) {
  958. if (ether_addr_equal(mac_mask->h_dest,
  959. mac_addr_ig_mask))
  960. spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC_IG;
  961. else if (is_broadcast_ether_addr(mac_mask->h_dest))
  962. spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC;
  963. else
  964. return -EINVAL;
  965. ether_addr_copy(spec.loc_mac, mac_entry->h_dest);
  966. }
  967. if (!is_zero_ether_addr(mac_mask->h_source)) {
  968. if (!is_broadcast_ether_addr(mac_mask->h_source))
  969. return -EINVAL;
  970. spec.match_flags |= EFX_FILTER_MATCH_REM_MAC;
  971. ether_addr_copy(spec.rem_mac, mac_entry->h_source);
  972. }
  973. if (mac_mask->h_proto) {
  974. if (mac_mask->h_proto != ETHER_TYPE_FULL_MASK)
  975. return -EINVAL;
  976. spec.match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
  977. spec.ether_type = mac_entry->h_proto;
  978. }
  979. break;
  980. default:
  981. return -EINVAL;
  982. }
  983. if ((rule->flow_type & FLOW_EXT) && rule->m_ext.vlan_tci) {
  984. if (rule->m_ext.vlan_tci != htons(0xfff))
  985. return -EINVAL;
  986. spec.match_flags |= EFX_FILTER_MATCH_OUTER_VID;
  987. spec.outer_vid = rule->h_ext.vlan_tci;
  988. }
  989. rc = efx_filter_insert_filter(efx, &spec, true);
  990. if (rc < 0)
  991. return rc;
  992. rule->location = rc;
  993. return 0;
  994. }
  995. int efx_siena_ethtool_set_rxnfc(struct net_device *net_dev,
  996. struct ethtool_rxnfc *info)
  997. {
  998. struct efx_nic *efx = netdev_priv(net_dev);
  999. if (efx_filter_get_rx_id_limit(efx) == 0)
  1000. return -EOPNOTSUPP;
  1001. switch (info->cmd) {
  1002. case ETHTOOL_SRXCLSRLINS:
  1003. return efx_ethtool_set_class_rule(efx, &info->fs,
  1004. info->rss_context);
  1005. case ETHTOOL_SRXCLSRLDEL:
  1006. return efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_MANUAL,
  1007. info->fs.location);
  1008. default:
  1009. return -EOPNOTSUPP;
  1010. }
  1011. }
  1012. u32 efx_siena_ethtool_get_rxfh_indir_size(struct net_device *net_dev)
  1013. {
  1014. struct efx_nic *efx = netdev_priv(net_dev);
  1015. if (efx->n_rx_channels == 1)
  1016. return 0;
  1017. return ARRAY_SIZE(efx->rss_context.rx_indir_table);
  1018. }
  1019. u32 efx_siena_ethtool_get_rxfh_key_size(struct net_device *net_dev)
  1020. {
  1021. struct efx_nic *efx = netdev_priv(net_dev);
  1022. return efx->type->rx_hash_key_size;
  1023. }
  1024. int efx_siena_ethtool_get_rxfh(struct net_device *net_dev,
  1025. struct ethtool_rxfh_param *rxfh)
  1026. {
  1027. struct efx_nic *efx = netdev_priv(net_dev);
  1028. int rc;
  1029. rc = efx->type->rx_pull_rss_config(efx);
  1030. if (rc)
  1031. return rc;
  1032. rxfh->hfunc = ETH_RSS_HASH_TOP;
  1033. if (rxfh->indir)
  1034. memcpy(rxfh->indir, efx->rss_context.rx_indir_table,
  1035. sizeof(efx->rss_context.rx_indir_table));
  1036. if (rxfh->key)
  1037. memcpy(rxfh->key, efx->rss_context.rx_hash_key,
  1038. efx->type->rx_hash_key_size);
  1039. return 0;
  1040. }
  1041. int efx_siena_ethtool_set_rxfh(struct net_device *net_dev,
  1042. struct ethtool_rxfh_param *rxfh,
  1043. struct netlink_ext_ack *extack)
  1044. {
  1045. struct efx_nic *efx = netdev_priv(net_dev);
  1046. u32 *indir = rxfh->indir;
  1047. u8 *key = rxfh->key;
  1048. /* Hash function is Toeplitz, cannot be changed */
  1049. if (rxfh->hfunc != ETH_RSS_HASH_NO_CHANGE &&
  1050. rxfh->hfunc != ETH_RSS_HASH_TOP)
  1051. return -EOPNOTSUPP;
  1052. if (!indir && !key)
  1053. return 0;
  1054. if (!key)
  1055. key = efx->rss_context.rx_hash_key;
  1056. if (!indir)
  1057. indir = efx->rss_context.rx_indir_table;
  1058. return efx->type->rx_push_rss_config(efx, true, indir, key);
  1059. }
  1060. int efx_siena_ethtool_reset(struct net_device *net_dev, u32 *flags)
  1061. {
  1062. struct efx_nic *efx = netdev_priv(net_dev);
  1063. int rc;
  1064. rc = efx->type->map_reset_flags(flags);
  1065. if (rc < 0)
  1066. return rc;
  1067. return efx_siena_reset(efx, rc);
  1068. }
  1069. int efx_siena_ethtool_get_module_eeprom(struct net_device *net_dev,
  1070. struct ethtool_eeprom *ee,
  1071. u8 *data)
  1072. {
  1073. struct efx_nic *efx = netdev_priv(net_dev);
  1074. int ret;
  1075. mutex_lock(&efx->mac_lock);
  1076. ret = efx_siena_mcdi_phy_get_module_eeprom(efx, ee, data);
  1077. mutex_unlock(&efx->mac_lock);
  1078. return ret;
  1079. }
  1080. int efx_siena_ethtool_get_module_info(struct net_device *net_dev,
  1081. struct ethtool_modinfo *modinfo)
  1082. {
  1083. struct efx_nic *efx = netdev_priv(net_dev);
  1084. int ret;
  1085. mutex_lock(&efx->mac_lock);
  1086. ret = efx_siena_mcdi_phy_get_module_info(efx, modinfo);
  1087. mutex_unlock(&efx->mac_lock);
  1088. return ret;
  1089. }