ethtool.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /****************************************************************************
  3. * Driver for Solarflare network controllers and boards
  4. * Copyright 2005-2006 Fen Systems Ltd.
  5. * Copyright 2006-2013 Solarflare Communications Inc.
  6. */
  7. #include <linux/netdevice.h>
  8. #include <linux/ethtool.h>
  9. #include <linux/rtnetlink.h>
  10. #include <linux/in.h>
  11. #include "net_driver.h"
  12. #include "workarounds.h"
  13. #include "selftest.h"
  14. #include "efx.h"
  15. #include "filter.h"
  16. #include "nic.h"
  17. struct ef4_sw_stat_desc {
  18. const char *name;
  19. enum {
  20. EF4_ETHTOOL_STAT_SOURCE_nic,
  21. EF4_ETHTOOL_STAT_SOURCE_channel,
  22. EF4_ETHTOOL_STAT_SOURCE_tx_queue
  23. } source;
  24. unsigned offset;
  25. u64(*get_stat) (void *field); /* Reader function */
  26. };
  27. /* Initialiser for a struct ef4_sw_stat_desc with type-checking */
  28. #define EF4_ETHTOOL_STAT(stat_name, source_name, field, field_type, \
  29. get_stat_function) { \
  30. .name = #stat_name, \
  31. .source = EF4_ETHTOOL_STAT_SOURCE_##source_name, \
  32. .offset = ((((field_type *) 0) == \
  33. &((struct ef4_##source_name *)0)->field) ? \
  34. offsetof(struct ef4_##source_name, field) : \
  35. offsetof(struct ef4_##source_name, field)), \
  36. .get_stat = get_stat_function, \
  37. }
  38. static u64 ef4_get_uint_stat(void *field)
  39. {
  40. return *(unsigned int *)field;
  41. }
  42. static u64 ef4_get_atomic_stat(void *field)
  43. {
  44. return atomic_read((atomic_t *) field);
  45. }
  46. #define EF4_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field) \
  47. EF4_ETHTOOL_STAT(field, nic, field, \
  48. atomic_t, ef4_get_atomic_stat)
  49. #define EF4_ETHTOOL_UINT_CHANNEL_STAT(field) \
  50. EF4_ETHTOOL_STAT(field, channel, n_##field, \
  51. unsigned int, ef4_get_uint_stat)
  52. #define EF4_ETHTOOL_UINT_TXQ_STAT(field) \
  53. EF4_ETHTOOL_STAT(tx_##field, tx_queue, field, \
  54. unsigned int, ef4_get_uint_stat)
  55. static const struct ef4_sw_stat_desc ef4_sw_stat_desc[] = {
  56. EF4_ETHTOOL_UINT_TXQ_STAT(merge_events),
  57. EF4_ETHTOOL_UINT_TXQ_STAT(pushes),
  58. EF4_ETHTOOL_UINT_TXQ_STAT(cb_packets),
  59. EF4_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset),
  60. EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc),
  61. EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),
  62. EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err),
  63. EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch),
  64. EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
  65. EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_events),
  66. EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_packets),
  67. };
  68. #define EF4_ETHTOOL_SW_STAT_COUNT ARRAY_SIZE(ef4_sw_stat_desc)
  69. #define EF4_ETHTOOL_EEPROM_MAGIC 0xEFAB
  70. /**************************************************************************
  71. *
  72. * Ethtool operations
  73. *
  74. **************************************************************************
  75. */
  76. /* Identify device by flashing LEDs */
  77. static int ef4_ethtool_phys_id(struct net_device *net_dev,
  78. enum ethtool_phys_id_state state)
  79. {
  80. struct ef4_nic *efx = netdev_priv(net_dev);
  81. enum ef4_led_mode mode = EF4_LED_DEFAULT;
  82. switch (state) {
  83. case ETHTOOL_ID_ON:
  84. mode = EF4_LED_ON;
  85. break;
  86. case ETHTOOL_ID_OFF:
  87. mode = EF4_LED_OFF;
  88. break;
  89. case ETHTOOL_ID_INACTIVE:
  90. mode = EF4_LED_DEFAULT;
  91. break;
  92. case ETHTOOL_ID_ACTIVE:
  93. return 1; /* cycle on/off once per second */
  94. }
  95. efx->type->set_id_led(efx, mode);
  96. return 0;
  97. }
  98. /* This must be called with rtnl_lock held. */
  99. static int
  100. ef4_ethtool_get_link_ksettings(struct net_device *net_dev,
  101. struct ethtool_link_ksettings *cmd)
  102. {
  103. struct ef4_nic *efx = netdev_priv(net_dev);
  104. struct ef4_link_state *link_state = &efx->link_state;
  105. mutex_lock(&efx->mac_lock);
  106. efx->phy_op->get_link_ksettings(efx, cmd);
  107. mutex_unlock(&efx->mac_lock);
  108. /* Both MACs support pause frames (bidirectional and respond-only) */
  109. ethtool_link_ksettings_add_link_mode(cmd, supported, Pause);
  110. ethtool_link_ksettings_add_link_mode(cmd, supported, Asym_Pause);
  111. if (LOOPBACK_INTERNAL(efx)) {
  112. cmd->base.speed = link_state->speed;
  113. cmd->base.duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF;
  114. }
  115. return 0;
  116. }
  117. /* This must be called with rtnl_lock held. */
  118. static int
  119. ef4_ethtool_set_link_ksettings(struct net_device *net_dev,
  120. const struct ethtool_link_ksettings *cmd)
  121. {
  122. struct ef4_nic *efx = netdev_priv(net_dev);
  123. int rc;
  124. /* GMAC does not support 1000Mbps HD */
  125. if ((cmd->base.speed == SPEED_1000) &&
  126. (cmd->base.duplex != DUPLEX_FULL)) {
  127. netif_dbg(efx, drv, efx->net_dev,
  128. "rejecting unsupported 1000Mbps HD setting\n");
  129. return -EINVAL;
  130. }
  131. mutex_lock(&efx->mac_lock);
  132. rc = efx->phy_op->set_link_ksettings(efx, cmd);
  133. mutex_unlock(&efx->mac_lock);
  134. return rc;
  135. }
  136. static void ef4_ethtool_get_drvinfo(struct net_device *net_dev,
  137. struct ethtool_drvinfo *info)
  138. {
  139. struct ef4_nic *efx = netdev_priv(net_dev);
  140. strscpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
  141. strscpy(info->version, EF4_DRIVER_VERSION, sizeof(info->version));
  142. strscpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
  143. }
  144. static int ef4_ethtool_get_regs_len(struct net_device *net_dev)
  145. {
  146. return ef4_nic_get_regs_len(netdev_priv(net_dev));
  147. }
  148. static void ef4_ethtool_get_regs(struct net_device *net_dev,
  149. struct ethtool_regs *regs, void *buf)
  150. {
  151. struct ef4_nic *efx = netdev_priv(net_dev);
  152. regs->version = efx->type->revision;
  153. ef4_nic_get_regs(efx, buf);
  154. }
  155. static u32 ef4_ethtool_get_msglevel(struct net_device *net_dev)
  156. {
  157. struct ef4_nic *efx = netdev_priv(net_dev);
  158. return efx->msg_enable;
  159. }
  160. static void ef4_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable)
  161. {
  162. struct ef4_nic *efx = netdev_priv(net_dev);
  163. efx->msg_enable = msg_enable;
  164. }
  165. /**
  166. * ef4_fill_test - fill in an individual self-test entry
  167. * @test_index: Index of the test
  168. * @strings: Ethtool strings, or %NULL
  169. * @data: Ethtool test results, or %NULL
  170. * @test: Pointer to test result (used only if data != %NULL)
  171. * @unit_format: Unit name format (e.g. "chan\%d")
  172. * @unit_id: Unit id (e.g. 0 for "chan0")
  173. * @test_format: Test name format (e.g. "loopback.\%s.tx.sent")
  174. * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
  175. *
  176. * Fill in an individual self-test entry.
  177. */
  178. static void ef4_fill_test(unsigned int test_index, u8 *strings, u64 *data,
  179. int *test, const char *unit_format, int unit_id,
  180. const char *test_format, const char *test_id)
  181. {
  182. char unit_str[ETH_GSTRING_LEN], test_str[ETH_GSTRING_LEN];
  183. /* Fill data value, if applicable */
  184. if (data)
  185. data[test_index] = *test;
  186. /* Fill string, if applicable */
  187. if (strings) {
  188. if (strchr(unit_format, '%'))
  189. snprintf(unit_str, sizeof(unit_str),
  190. unit_format, unit_id);
  191. else
  192. strcpy(unit_str, unit_format);
  193. snprintf(test_str, sizeof(test_str), test_format, test_id);
  194. snprintf(strings + test_index * ETH_GSTRING_LEN,
  195. ETH_GSTRING_LEN,
  196. "%-6s %-24s", unit_str, test_str);
  197. }
  198. }
  199. #define EF4_CHANNEL_NAME(_channel) "chan%d", _channel->channel
  200. #define EF4_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
  201. #define EF4_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
  202. #define EF4_LOOPBACK_NAME(_mode, _counter) \
  203. "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, ef4_loopback_mode)
  204. /**
  205. * ef4_fill_loopback_test - fill in a block of loopback self-test entries
  206. * @efx: Efx NIC
  207. * @lb_tests: Efx loopback self-test results structure
  208. * @mode: Loopback test mode
  209. * @test_index: Starting index of the test
  210. * @strings: Ethtool strings, or %NULL
  211. * @data: Ethtool test results, or %NULL
  212. *
  213. * Fill in a block of loopback self-test entries. Return new test
  214. * index.
  215. */
  216. static int ef4_fill_loopback_test(struct ef4_nic *efx,
  217. struct ef4_loopback_self_tests *lb_tests,
  218. enum ef4_loopback_mode mode,
  219. unsigned int test_index,
  220. u8 *strings, u64 *data)
  221. {
  222. struct ef4_channel *channel =
  223. ef4_get_channel(efx, efx->tx_channel_offset);
  224. struct ef4_tx_queue *tx_queue;
  225. ef4_for_each_channel_tx_queue(tx_queue, channel) {
  226. ef4_fill_test(test_index++, strings, data,
  227. &lb_tests->tx_sent[tx_queue->queue],
  228. EF4_TX_QUEUE_NAME(tx_queue),
  229. EF4_LOOPBACK_NAME(mode, "tx_sent"));
  230. ef4_fill_test(test_index++, strings, data,
  231. &lb_tests->tx_done[tx_queue->queue],
  232. EF4_TX_QUEUE_NAME(tx_queue),
  233. EF4_LOOPBACK_NAME(mode, "tx_done"));
  234. }
  235. ef4_fill_test(test_index++, strings, data,
  236. &lb_tests->rx_good,
  237. "rx", 0,
  238. EF4_LOOPBACK_NAME(mode, "rx_good"));
  239. ef4_fill_test(test_index++, strings, data,
  240. &lb_tests->rx_bad,
  241. "rx", 0,
  242. EF4_LOOPBACK_NAME(mode, "rx_bad"));
  243. return test_index;
  244. }
  245. /**
  246. * ef4_ethtool_fill_self_tests - get self-test details
  247. * @efx: Efx NIC
  248. * @tests: Efx self-test results structure, or %NULL
  249. * @strings: Ethtool strings, or %NULL
  250. * @data: Ethtool test results, or %NULL
  251. *
  252. * Get self-test number of strings, strings, and/or test results.
  253. * Return number of strings (== number of test results).
  254. *
  255. * The reason for merging these three functions is to make sure that
  256. * they can never be inconsistent.
  257. */
  258. static int ef4_ethtool_fill_self_tests(struct ef4_nic *efx,
  259. struct ef4_self_tests *tests,
  260. u8 *strings, u64 *data)
  261. {
  262. struct ef4_channel *channel;
  263. unsigned int n = 0, i;
  264. enum ef4_loopback_mode mode;
  265. ef4_fill_test(n++, strings, data, &tests->phy_alive,
  266. "phy", 0, "alive", NULL);
  267. ef4_fill_test(n++, strings, data, &tests->nvram,
  268. "core", 0, "nvram", NULL);
  269. ef4_fill_test(n++, strings, data, &tests->interrupt,
  270. "core", 0, "interrupt", NULL);
  271. /* Event queues */
  272. ef4_for_each_channel(channel, efx) {
  273. ef4_fill_test(n++, strings, data,
  274. &tests->eventq_dma[channel->channel],
  275. EF4_CHANNEL_NAME(channel),
  276. "eventq.dma", NULL);
  277. ef4_fill_test(n++, strings, data,
  278. &tests->eventq_int[channel->channel],
  279. EF4_CHANNEL_NAME(channel),
  280. "eventq.int", NULL);
  281. }
  282. ef4_fill_test(n++, strings, data, &tests->memory,
  283. "core", 0, "memory", NULL);
  284. ef4_fill_test(n++, strings, data, &tests->registers,
  285. "core", 0, "registers", NULL);
  286. if (efx->phy_op->run_tests != NULL) {
  287. EF4_BUG_ON_PARANOID(efx->phy_op->test_name == NULL);
  288. for (i = 0; true; ++i) {
  289. const char *name;
  290. EF4_BUG_ON_PARANOID(i >= EF4_MAX_PHY_TESTS);
  291. name = efx->phy_op->test_name(efx, i);
  292. if (name == NULL)
  293. break;
  294. ef4_fill_test(n++, strings, data, &tests->phy_ext[i],
  295. "phy", 0, name, NULL);
  296. }
  297. }
  298. /* Loopback tests */
  299. for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
  300. if (!(efx->loopback_modes & (1 << mode)))
  301. continue;
  302. n = ef4_fill_loopback_test(efx,
  303. &tests->loopback[mode], mode, n,
  304. strings, data);
  305. }
  306. return n;
  307. }
  308. static size_t ef4_describe_per_queue_stats(struct ef4_nic *efx, u8 *strings)
  309. {
  310. size_t n_stats = 0;
  311. struct ef4_channel *channel;
  312. ef4_for_each_channel(channel, efx) {
  313. if (ef4_channel_has_tx_queues(channel)) {
  314. n_stats++;
  315. if (strings != NULL) {
  316. snprintf(strings, ETH_GSTRING_LEN,
  317. "tx-%u.tx_packets",
  318. channel->tx_queue[0].queue /
  319. EF4_TXQ_TYPES);
  320. strings += ETH_GSTRING_LEN;
  321. }
  322. }
  323. }
  324. ef4_for_each_channel(channel, efx) {
  325. if (ef4_channel_has_rx_queue(channel)) {
  326. n_stats++;
  327. if (strings != NULL) {
  328. snprintf(strings, ETH_GSTRING_LEN,
  329. "rx-%d.rx_packets", channel->channel);
  330. strings += ETH_GSTRING_LEN;
  331. }
  332. }
  333. }
  334. return n_stats;
  335. }
  336. static int ef4_ethtool_get_sset_count(struct net_device *net_dev,
  337. int string_set)
  338. {
  339. struct ef4_nic *efx = netdev_priv(net_dev);
  340. switch (string_set) {
  341. case ETH_SS_STATS:
  342. return efx->type->describe_stats(efx, NULL) +
  343. EF4_ETHTOOL_SW_STAT_COUNT +
  344. ef4_describe_per_queue_stats(efx, NULL);
  345. case ETH_SS_TEST:
  346. return ef4_ethtool_fill_self_tests(efx, NULL, NULL, NULL);
  347. default:
  348. return -EINVAL;
  349. }
  350. }
  351. static void ef4_ethtool_get_strings(struct net_device *net_dev,
  352. u32 string_set, u8 *strings)
  353. {
  354. struct ef4_nic *efx = netdev_priv(net_dev);
  355. int i;
  356. switch (string_set) {
  357. case ETH_SS_STATS:
  358. strings += (efx->type->describe_stats(efx, strings) *
  359. ETH_GSTRING_LEN);
  360. for (i = 0; i < EF4_ETHTOOL_SW_STAT_COUNT; i++)
  361. strscpy(strings + i * ETH_GSTRING_LEN,
  362. ef4_sw_stat_desc[i].name, ETH_GSTRING_LEN);
  363. strings += EF4_ETHTOOL_SW_STAT_COUNT * ETH_GSTRING_LEN;
  364. strings += (ef4_describe_per_queue_stats(efx, strings) *
  365. ETH_GSTRING_LEN);
  366. break;
  367. case ETH_SS_TEST:
  368. ef4_ethtool_fill_self_tests(efx, NULL, strings, NULL);
  369. break;
  370. default:
  371. /* No other string sets */
  372. break;
  373. }
  374. }
  375. static void ef4_ethtool_get_stats(struct net_device *net_dev,
  376. struct ethtool_stats *stats,
  377. u64 *data)
  378. {
  379. struct ef4_nic *efx = netdev_priv(net_dev);
  380. const struct ef4_sw_stat_desc *stat;
  381. struct ef4_channel *channel;
  382. struct ef4_tx_queue *tx_queue;
  383. struct ef4_rx_queue *rx_queue;
  384. int i;
  385. spin_lock_bh(&efx->stats_lock);
  386. /* Get NIC statistics */
  387. data += efx->type->update_stats(efx, data, NULL);
  388. /* Get software statistics */
  389. for (i = 0; i < EF4_ETHTOOL_SW_STAT_COUNT; i++) {
  390. stat = &ef4_sw_stat_desc[i];
  391. switch (stat->source) {
  392. case EF4_ETHTOOL_STAT_SOURCE_nic:
  393. data[i] = stat->get_stat((void *)efx + stat->offset);
  394. break;
  395. case EF4_ETHTOOL_STAT_SOURCE_channel:
  396. data[i] = 0;
  397. ef4_for_each_channel(channel, efx)
  398. data[i] += stat->get_stat((void *)channel +
  399. stat->offset);
  400. break;
  401. case EF4_ETHTOOL_STAT_SOURCE_tx_queue:
  402. data[i] = 0;
  403. ef4_for_each_channel(channel, efx) {
  404. ef4_for_each_channel_tx_queue(tx_queue, channel)
  405. data[i] +=
  406. stat->get_stat((void *)tx_queue
  407. + stat->offset);
  408. }
  409. break;
  410. }
  411. }
  412. data += EF4_ETHTOOL_SW_STAT_COUNT;
  413. spin_unlock_bh(&efx->stats_lock);
  414. ef4_for_each_channel(channel, efx) {
  415. if (ef4_channel_has_tx_queues(channel)) {
  416. *data = 0;
  417. ef4_for_each_channel_tx_queue(tx_queue, channel) {
  418. *data += tx_queue->tx_packets;
  419. }
  420. data++;
  421. }
  422. }
  423. ef4_for_each_channel(channel, efx) {
  424. if (ef4_channel_has_rx_queue(channel)) {
  425. *data = 0;
  426. ef4_for_each_channel_rx_queue(rx_queue, channel) {
  427. *data += rx_queue->rx_packets;
  428. }
  429. data++;
  430. }
  431. }
  432. }
  433. static void ef4_ethtool_self_test(struct net_device *net_dev,
  434. struct ethtool_test *test, u64 *data)
  435. {
  436. struct ef4_nic *efx = netdev_priv(net_dev);
  437. struct ef4_self_tests *ef4_tests;
  438. bool already_up;
  439. int rc = -ENOMEM;
  440. ef4_tests = kzalloc(sizeof(*ef4_tests), GFP_KERNEL);
  441. if (!ef4_tests)
  442. goto fail;
  443. if (efx->state != STATE_READY) {
  444. rc = -EBUSY;
  445. goto out;
  446. }
  447. netif_info(efx, drv, efx->net_dev, "starting %sline testing\n",
  448. (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
  449. /* We need rx buffers and interrupts. */
  450. already_up = (efx->net_dev->flags & IFF_UP);
  451. if (!already_up) {
  452. rc = dev_open(efx->net_dev, NULL);
  453. if (rc) {
  454. netif_err(efx, drv, efx->net_dev,
  455. "failed opening device.\n");
  456. goto out;
  457. }
  458. }
  459. rc = ef4_selftest(efx, ef4_tests, test->flags);
  460. if (!already_up)
  461. dev_close(efx->net_dev);
  462. netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n",
  463. rc == 0 ? "passed" : "failed",
  464. (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
  465. out:
  466. ef4_ethtool_fill_self_tests(efx, ef4_tests, NULL, data);
  467. kfree(ef4_tests);
  468. fail:
  469. if (rc)
  470. test->flags |= ETH_TEST_FL_FAILED;
  471. }
  472. /* Restart autonegotiation */
  473. static int ef4_ethtool_nway_reset(struct net_device *net_dev)
  474. {
  475. struct ef4_nic *efx = netdev_priv(net_dev);
  476. return mdio45_nway_restart(&efx->mdio);
  477. }
  478. /*
  479. * Each channel has a single IRQ and moderation timer, started by any
  480. * completion (or other event). Unless the module parameter
  481. * separate_tx_channels is set, IRQs and moderation are therefore
  482. * shared between RX and TX completions. In this case, when RX IRQ
  483. * moderation is explicitly changed then TX IRQ moderation is
  484. * automatically changed too, but otherwise we fail if the two values
  485. * are requested to be different.
  486. *
  487. * The hardware does not support a limit on the number of completions
  488. * before an IRQ, so we do not use the max_frames fields. We should
  489. * report and require that max_frames == (usecs != 0), but this would
  490. * invalidate existing user documentation.
  491. *
  492. * The hardware does not have distinct settings for interrupt
  493. * moderation while the previous IRQ is being handled, so we should
  494. * not use the 'irq' fields. However, an earlier developer
  495. * misunderstood the meaning of the 'irq' fields and the driver did
  496. * not support the standard fields. To avoid invalidating existing
  497. * user documentation, we report and accept changes through either the
  498. * standard or 'irq' fields. If both are changed at the same time, we
  499. * prefer the standard field.
  500. *
  501. * We implement adaptive IRQ moderation, but use a different algorithm
  502. * from that assumed in the definition of struct ethtool_coalesce.
  503. * Therefore we do not use any of the adaptive moderation parameters
  504. * in it.
  505. */
  506. static int ef4_ethtool_get_coalesce(struct net_device *net_dev,
  507. struct ethtool_coalesce *coalesce,
  508. struct kernel_ethtool_coalesce *kernel_coal,
  509. struct netlink_ext_ack *extack)
  510. {
  511. struct ef4_nic *efx = netdev_priv(net_dev);
  512. unsigned int tx_usecs, rx_usecs;
  513. bool rx_adaptive;
  514. ef4_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &rx_adaptive);
  515. coalesce->tx_coalesce_usecs = tx_usecs;
  516. coalesce->tx_coalesce_usecs_irq = tx_usecs;
  517. coalesce->rx_coalesce_usecs = rx_usecs;
  518. coalesce->rx_coalesce_usecs_irq = rx_usecs;
  519. coalesce->use_adaptive_rx_coalesce = rx_adaptive;
  520. return 0;
  521. }
  522. static int ef4_ethtool_set_coalesce(struct net_device *net_dev,
  523. struct ethtool_coalesce *coalesce,
  524. struct kernel_ethtool_coalesce *kernel_coal,
  525. struct netlink_ext_ack *extack)
  526. {
  527. struct ef4_nic *efx = netdev_priv(net_dev);
  528. struct ef4_channel *channel;
  529. unsigned int tx_usecs, rx_usecs;
  530. bool adaptive, rx_may_override_tx;
  531. int rc;
  532. ef4_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &adaptive);
  533. if (coalesce->rx_coalesce_usecs != rx_usecs)
  534. rx_usecs = coalesce->rx_coalesce_usecs;
  535. else
  536. rx_usecs = coalesce->rx_coalesce_usecs_irq;
  537. adaptive = coalesce->use_adaptive_rx_coalesce;
  538. /* If channels are shared, TX IRQ moderation can be quietly
  539. * overridden unless it is changed from its old value.
  540. */
  541. rx_may_override_tx = (coalesce->tx_coalesce_usecs == tx_usecs &&
  542. coalesce->tx_coalesce_usecs_irq == tx_usecs);
  543. if (coalesce->tx_coalesce_usecs != tx_usecs)
  544. tx_usecs = coalesce->tx_coalesce_usecs;
  545. else
  546. tx_usecs = coalesce->tx_coalesce_usecs_irq;
  547. rc = ef4_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive,
  548. rx_may_override_tx);
  549. if (rc != 0)
  550. return rc;
  551. ef4_for_each_channel(channel, efx)
  552. efx->type->push_irq_moderation(channel);
  553. return 0;
  554. }
  555. static void
  556. ef4_ethtool_get_ringparam(struct net_device *net_dev,
  557. struct ethtool_ringparam *ring,
  558. struct kernel_ethtool_ringparam *kernel_ring,
  559. struct netlink_ext_ack *extack)
  560. {
  561. struct ef4_nic *efx = netdev_priv(net_dev);
  562. ring->rx_max_pending = EF4_MAX_DMAQ_SIZE;
  563. ring->tx_max_pending = EF4_MAX_DMAQ_SIZE;
  564. ring->rx_pending = efx->rxq_entries;
  565. ring->tx_pending = efx->txq_entries;
  566. }
  567. static int
  568. ef4_ethtool_set_ringparam(struct net_device *net_dev,
  569. struct ethtool_ringparam *ring,
  570. struct kernel_ethtool_ringparam *kernel_ring,
  571. struct netlink_ext_ack *extack)
  572. {
  573. struct ef4_nic *efx = netdev_priv(net_dev);
  574. u32 txq_entries;
  575. if (ring->rx_mini_pending || ring->rx_jumbo_pending ||
  576. ring->rx_pending > EF4_MAX_DMAQ_SIZE ||
  577. ring->tx_pending > EF4_MAX_DMAQ_SIZE)
  578. return -EINVAL;
  579. if (ring->rx_pending < EF4_RXQ_MIN_ENT) {
  580. netif_err(efx, drv, efx->net_dev,
  581. "RX queues cannot be smaller than %u\n",
  582. EF4_RXQ_MIN_ENT);
  583. return -EINVAL;
  584. }
  585. txq_entries = max(ring->tx_pending, EF4_TXQ_MIN_ENT(efx));
  586. if (txq_entries != ring->tx_pending)
  587. netif_warn(efx, drv, efx->net_dev,
  588. "increasing TX queue size to minimum of %u\n",
  589. txq_entries);
  590. return ef4_realloc_channels(efx, ring->rx_pending, txq_entries);
  591. }
  592. static int ef4_ethtool_set_pauseparam(struct net_device *net_dev,
  593. struct ethtool_pauseparam *pause)
  594. {
  595. struct ef4_nic *efx = netdev_priv(net_dev);
  596. u8 wanted_fc, old_fc;
  597. u32 old_adv;
  598. int rc = 0;
  599. mutex_lock(&efx->mac_lock);
  600. wanted_fc = ((pause->rx_pause ? EF4_FC_RX : 0) |
  601. (pause->tx_pause ? EF4_FC_TX : 0) |
  602. (pause->autoneg ? EF4_FC_AUTO : 0));
  603. if ((wanted_fc & EF4_FC_TX) && !(wanted_fc & EF4_FC_RX)) {
  604. netif_dbg(efx, drv, efx->net_dev,
  605. "Flow control unsupported: tx ON rx OFF\n");
  606. rc = -EINVAL;
  607. goto out;
  608. }
  609. if ((wanted_fc & EF4_FC_AUTO) && !efx->link_advertising) {
  610. netif_dbg(efx, drv, efx->net_dev,
  611. "Autonegotiation is disabled\n");
  612. rc = -EINVAL;
  613. goto out;
  614. }
  615. /* Hook for Falcon bug 11482 workaround */
  616. if (efx->type->prepare_enable_fc_tx &&
  617. (wanted_fc & EF4_FC_TX) && !(efx->wanted_fc & EF4_FC_TX))
  618. efx->type->prepare_enable_fc_tx(efx);
  619. old_adv = efx->link_advertising;
  620. old_fc = efx->wanted_fc;
  621. ef4_link_set_wanted_fc(efx, wanted_fc);
  622. if (efx->link_advertising != old_adv ||
  623. (efx->wanted_fc ^ old_fc) & EF4_FC_AUTO) {
  624. rc = efx->phy_op->reconfigure(efx);
  625. if (rc) {
  626. netif_err(efx, drv, efx->net_dev,
  627. "Unable to advertise requested flow "
  628. "control setting\n");
  629. goto out;
  630. }
  631. }
  632. /* Reconfigure the MAC. The PHY *may* generate a link state change event
  633. * if the user just changed the advertised capabilities, but there's no
  634. * harm doing this twice */
  635. ef4_mac_reconfigure(efx);
  636. out:
  637. mutex_unlock(&efx->mac_lock);
  638. return rc;
  639. }
  640. static void ef4_ethtool_get_pauseparam(struct net_device *net_dev,
  641. struct ethtool_pauseparam *pause)
  642. {
  643. struct ef4_nic *efx = netdev_priv(net_dev);
  644. pause->rx_pause = !!(efx->wanted_fc & EF4_FC_RX);
  645. pause->tx_pause = !!(efx->wanted_fc & EF4_FC_TX);
  646. pause->autoneg = !!(efx->wanted_fc & EF4_FC_AUTO);
  647. }
  648. static void ef4_ethtool_get_wol(struct net_device *net_dev,
  649. struct ethtool_wolinfo *wol)
  650. {
  651. struct ef4_nic *efx = netdev_priv(net_dev);
  652. return efx->type->get_wol(efx, wol);
  653. }
  654. static int ef4_ethtool_set_wol(struct net_device *net_dev,
  655. struct ethtool_wolinfo *wol)
  656. {
  657. struct ef4_nic *efx = netdev_priv(net_dev);
  658. return efx->type->set_wol(efx, wol->wolopts);
  659. }
  660. static int ef4_ethtool_reset(struct net_device *net_dev, u32 *flags)
  661. {
  662. struct ef4_nic *efx = netdev_priv(net_dev);
  663. int rc;
  664. rc = efx->type->map_reset_flags(flags);
  665. if (rc < 0)
  666. return rc;
  667. return ef4_reset(efx, rc);
  668. }
  669. /* MAC address mask including only I/G bit */
  670. static const u8 mac_addr_ig_mask[ETH_ALEN] __aligned(2) = {0x01, 0, 0, 0, 0, 0};
  671. #define IP4_ADDR_FULL_MASK ((__force __be32)~0)
  672. #define IP_PROTO_FULL_MASK 0xFF
  673. #define PORT_FULL_MASK ((__force __be16)~0)
  674. #define ETHER_TYPE_FULL_MASK ((__force __be16)~0)
  675. static inline void ip6_fill_mask(__be32 *mask)
  676. {
  677. mask[0] = mask[1] = mask[2] = mask[3] = ~(__be32)0;
  678. }
  679. static int ef4_ethtool_get_class_rule(struct ef4_nic *efx,
  680. struct ethtool_rx_flow_spec *rule)
  681. {
  682. struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
  683. struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
  684. struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
  685. struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
  686. struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
  687. struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
  688. struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
  689. struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
  690. struct ethhdr *mac_entry = &rule->h_u.ether_spec;
  691. struct ethhdr *mac_mask = &rule->m_u.ether_spec;
  692. struct ef4_filter_spec spec;
  693. int rc;
  694. rc = ef4_filter_get_filter_safe(efx, EF4_FILTER_PRI_MANUAL,
  695. rule->location, &spec);
  696. if (rc)
  697. return rc;
  698. if (spec.dmaq_id == EF4_FILTER_RX_DMAQ_ID_DROP)
  699. rule->ring_cookie = RX_CLS_FLOW_DISC;
  700. else
  701. rule->ring_cookie = spec.dmaq_id;
  702. if ((spec.match_flags & EF4_FILTER_MATCH_ETHER_TYPE) &&
  703. spec.ether_type == htons(ETH_P_IP) &&
  704. (spec.match_flags & EF4_FILTER_MATCH_IP_PROTO) &&
  705. (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
  706. !(spec.match_flags &
  707. ~(EF4_FILTER_MATCH_ETHER_TYPE | EF4_FILTER_MATCH_OUTER_VID |
  708. EF4_FILTER_MATCH_LOC_HOST | EF4_FILTER_MATCH_REM_HOST |
  709. EF4_FILTER_MATCH_IP_PROTO |
  710. EF4_FILTER_MATCH_LOC_PORT | EF4_FILTER_MATCH_REM_PORT))) {
  711. rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
  712. TCP_V4_FLOW : UDP_V4_FLOW);
  713. if (spec.match_flags & EF4_FILTER_MATCH_LOC_HOST) {
  714. ip_entry->ip4dst = spec.loc_host[0];
  715. ip_mask->ip4dst = IP4_ADDR_FULL_MASK;
  716. }
  717. if (spec.match_flags & EF4_FILTER_MATCH_REM_HOST) {
  718. ip_entry->ip4src = spec.rem_host[0];
  719. ip_mask->ip4src = IP4_ADDR_FULL_MASK;
  720. }
  721. if (spec.match_flags & EF4_FILTER_MATCH_LOC_PORT) {
  722. ip_entry->pdst = spec.loc_port;
  723. ip_mask->pdst = PORT_FULL_MASK;
  724. }
  725. if (spec.match_flags & EF4_FILTER_MATCH_REM_PORT) {
  726. ip_entry->psrc = spec.rem_port;
  727. ip_mask->psrc = PORT_FULL_MASK;
  728. }
  729. } else if ((spec.match_flags & EF4_FILTER_MATCH_ETHER_TYPE) &&
  730. spec.ether_type == htons(ETH_P_IPV6) &&
  731. (spec.match_flags & EF4_FILTER_MATCH_IP_PROTO) &&
  732. (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
  733. !(spec.match_flags &
  734. ~(EF4_FILTER_MATCH_ETHER_TYPE | EF4_FILTER_MATCH_OUTER_VID |
  735. EF4_FILTER_MATCH_LOC_HOST | EF4_FILTER_MATCH_REM_HOST |
  736. EF4_FILTER_MATCH_IP_PROTO |
  737. EF4_FILTER_MATCH_LOC_PORT | EF4_FILTER_MATCH_REM_PORT))) {
  738. rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
  739. TCP_V6_FLOW : UDP_V6_FLOW);
  740. if (spec.match_flags & EF4_FILTER_MATCH_LOC_HOST) {
  741. memcpy(ip6_entry->ip6dst, spec.loc_host,
  742. sizeof(ip6_entry->ip6dst));
  743. ip6_fill_mask(ip6_mask->ip6dst);
  744. }
  745. if (spec.match_flags & EF4_FILTER_MATCH_REM_HOST) {
  746. memcpy(ip6_entry->ip6src, spec.rem_host,
  747. sizeof(ip6_entry->ip6src));
  748. ip6_fill_mask(ip6_mask->ip6src);
  749. }
  750. if (spec.match_flags & EF4_FILTER_MATCH_LOC_PORT) {
  751. ip6_entry->pdst = spec.loc_port;
  752. ip6_mask->pdst = PORT_FULL_MASK;
  753. }
  754. if (spec.match_flags & EF4_FILTER_MATCH_REM_PORT) {
  755. ip6_entry->psrc = spec.rem_port;
  756. ip6_mask->psrc = PORT_FULL_MASK;
  757. }
  758. } else if (!(spec.match_flags &
  759. ~(EF4_FILTER_MATCH_LOC_MAC | EF4_FILTER_MATCH_LOC_MAC_IG |
  760. EF4_FILTER_MATCH_REM_MAC | EF4_FILTER_MATCH_ETHER_TYPE |
  761. EF4_FILTER_MATCH_OUTER_VID))) {
  762. rule->flow_type = ETHER_FLOW;
  763. if (spec.match_flags &
  764. (EF4_FILTER_MATCH_LOC_MAC | EF4_FILTER_MATCH_LOC_MAC_IG)) {
  765. ether_addr_copy(mac_entry->h_dest, spec.loc_mac);
  766. if (spec.match_flags & EF4_FILTER_MATCH_LOC_MAC)
  767. eth_broadcast_addr(mac_mask->h_dest);
  768. else
  769. ether_addr_copy(mac_mask->h_dest,
  770. mac_addr_ig_mask);
  771. }
  772. if (spec.match_flags & EF4_FILTER_MATCH_REM_MAC) {
  773. ether_addr_copy(mac_entry->h_source, spec.rem_mac);
  774. eth_broadcast_addr(mac_mask->h_source);
  775. }
  776. if (spec.match_flags & EF4_FILTER_MATCH_ETHER_TYPE) {
  777. mac_entry->h_proto = spec.ether_type;
  778. mac_mask->h_proto = ETHER_TYPE_FULL_MASK;
  779. }
  780. } else if (spec.match_flags & EF4_FILTER_MATCH_ETHER_TYPE &&
  781. spec.ether_type == htons(ETH_P_IP) &&
  782. !(spec.match_flags &
  783. ~(EF4_FILTER_MATCH_ETHER_TYPE | EF4_FILTER_MATCH_OUTER_VID |
  784. EF4_FILTER_MATCH_LOC_HOST | EF4_FILTER_MATCH_REM_HOST |
  785. EF4_FILTER_MATCH_IP_PROTO))) {
  786. rule->flow_type = IPV4_USER_FLOW;
  787. uip_entry->ip_ver = ETH_RX_NFC_IP4;
  788. if (spec.match_flags & EF4_FILTER_MATCH_IP_PROTO) {
  789. uip_mask->proto = IP_PROTO_FULL_MASK;
  790. uip_entry->proto = spec.ip_proto;
  791. }
  792. if (spec.match_flags & EF4_FILTER_MATCH_LOC_HOST) {
  793. uip_entry->ip4dst = spec.loc_host[0];
  794. uip_mask->ip4dst = IP4_ADDR_FULL_MASK;
  795. }
  796. if (spec.match_flags & EF4_FILTER_MATCH_REM_HOST) {
  797. uip_entry->ip4src = spec.rem_host[0];
  798. uip_mask->ip4src = IP4_ADDR_FULL_MASK;
  799. }
  800. } else if (spec.match_flags & EF4_FILTER_MATCH_ETHER_TYPE &&
  801. spec.ether_type == htons(ETH_P_IPV6) &&
  802. !(spec.match_flags &
  803. ~(EF4_FILTER_MATCH_ETHER_TYPE | EF4_FILTER_MATCH_OUTER_VID |
  804. EF4_FILTER_MATCH_LOC_HOST | EF4_FILTER_MATCH_REM_HOST |
  805. EF4_FILTER_MATCH_IP_PROTO))) {
  806. rule->flow_type = IPV6_USER_FLOW;
  807. if (spec.match_flags & EF4_FILTER_MATCH_IP_PROTO) {
  808. uip6_mask->l4_proto = IP_PROTO_FULL_MASK;
  809. uip6_entry->l4_proto = spec.ip_proto;
  810. }
  811. if (spec.match_flags & EF4_FILTER_MATCH_LOC_HOST) {
  812. memcpy(uip6_entry->ip6dst, spec.loc_host,
  813. sizeof(uip6_entry->ip6dst));
  814. ip6_fill_mask(uip6_mask->ip6dst);
  815. }
  816. if (spec.match_flags & EF4_FILTER_MATCH_REM_HOST) {
  817. memcpy(uip6_entry->ip6src, spec.rem_host,
  818. sizeof(uip6_entry->ip6src));
  819. ip6_fill_mask(uip6_mask->ip6src);
  820. }
  821. } else {
  822. /* The above should handle all filters that we insert */
  823. WARN_ON(1);
  824. return -EINVAL;
  825. }
  826. if (spec.match_flags & EF4_FILTER_MATCH_OUTER_VID) {
  827. rule->flow_type |= FLOW_EXT;
  828. rule->h_ext.vlan_tci = spec.outer_vid;
  829. rule->m_ext.vlan_tci = htons(0xfff);
  830. }
  831. return rc;
  832. }
  833. static int
  834. ef4_ethtool_get_rxnfc(struct net_device *net_dev,
  835. struct ethtool_rxnfc *info, u32 *rule_locs)
  836. {
  837. struct ef4_nic *efx = netdev_priv(net_dev);
  838. switch (info->cmd) {
  839. case ETHTOOL_GRXRINGS:
  840. info->data = efx->n_rx_channels;
  841. return 0;
  842. case ETHTOOL_GRXFH: {
  843. unsigned min_revision = 0;
  844. info->data = 0;
  845. switch (info->flow_type) {
  846. case TCP_V4_FLOW:
  847. info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  848. fallthrough;
  849. case UDP_V4_FLOW:
  850. case SCTP_V4_FLOW:
  851. case AH_ESP_V4_FLOW:
  852. case IPV4_FLOW:
  853. info->data |= RXH_IP_SRC | RXH_IP_DST;
  854. min_revision = EF4_REV_FALCON_B0;
  855. break;
  856. default:
  857. break;
  858. }
  859. if (ef4_nic_rev(efx) < min_revision)
  860. info->data = 0;
  861. return 0;
  862. }
  863. case ETHTOOL_GRXCLSRLCNT:
  864. info->data = ef4_filter_get_rx_id_limit(efx);
  865. if (info->data == 0)
  866. return -EOPNOTSUPP;
  867. info->data |= RX_CLS_LOC_SPECIAL;
  868. info->rule_cnt =
  869. ef4_filter_count_rx_used(efx, EF4_FILTER_PRI_MANUAL);
  870. return 0;
  871. case ETHTOOL_GRXCLSRULE:
  872. if (ef4_filter_get_rx_id_limit(efx) == 0)
  873. return -EOPNOTSUPP;
  874. return ef4_ethtool_get_class_rule(efx, &info->fs);
  875. case ETHTOOL_GRXCLSRLALL: {
  876. s32 rc;
  877. info->data = ef4_filter_get_rx_id_limit(efx);
  878. if (info->data == 0)
  879. return -EOPNOTSUPP;
  880. rc = ef4_filter_get_rx_ids(efx, EF4_FILTER_PRI_MANUAL,
  881. rule_locs, info->rule_cnt);
  882. if (rc < 0)
  883. return rc;
  884. info->rule_cnt = rc;
  885. return 0;
  886. }
  887. default:
  888. return -EOPNOTSUPP;
  889. }
  890. }
  891. static inline bool ip6_mask_is_full(__be32 mask[4])
  892. {
  893. return !~(mask[0] & mask[1] & mask[2] & mask[3]);
  894. }
  895. static inline bool ip6_mask_is_empty(__be32 mask[4])
  896. {
  897. return !(mask[0] | mask[1] | mask[2] | mask[3]);
  898. }
  899. static int ef4_ethtool_set_class_rule(struct ef4_nic *efx,
  900. struct ethtool_rx_flow_spec *rule)
  901. {
  902. struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
  903. struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
  904. struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
  905. struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
  906. struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
  907. struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
  908. struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
  909. struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
  910. struct ethhdr *mac_entry = &rule->h_u.ether_spec;
  911. struct ethhdr *mac_mask = &rule->m_u.ether_spec;
  912. struct ef4_filter_spec spec;
  913. int rc;
  914. /* Check that user wants us to choose the location */
  915. if (rule->location != RX_CLS_LOC_ANY)
  916. return -EINVAL;
  917. /* Range-check ring_cookie */
  918. if (rule->ring_cookie >= efx->n_rx_channels &&
  919. rule->ring_cookie != RX_CLS_FLOW_DISC)
  920. return -EINVAL;
  921. /* Check for unsupported extensions */
  922. if ((rule->flow_type & FLOW_EXT) &&
  923. (rule->m_ext.vlan_etype || rule->m_ext.data[0] ||
  924. rule->m_ext.data[1]))
  925. return -EINVAL;
  926. ef4_filter_init_rx(&spec, EF4_FILTER_PRI_MANUAL,
  927. efx->rx_scatter ? EF4_FILTER_FLAG_RX_SCATTER : 0,
  928. (rule->ring_cookie == RX_CLS_FLOW_DISC) ?
  929. EF4_FILTER_RX_DMAQ_ID_DROP : rule->ring_cookie);
  930. switch (rule->flow_type & ~FLOW_EXT) {
  931. case TCP_V4_FLOW:
  932. case UDP_V4_FLOW:
  933. spec.match_flags = (EF4_FILTER_MATCH_ETHER_TYPE |
  934. EF4_FILTER_MATCH_IP_PROTO);
  935. spec.ether_type = htons(ETH_P_IP);
  936. spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V4_FLOW ?
  937. IPPROTO_TCP : IPPROTO_UDP);
  938. if (ip_mask->ip4dst) {
  939. if (ip_mask->ip4dst != IP4_ADDR_FULL_MASK)
  940. return -EINVAL;
  941. spec.match_flags |= EF4_FILTER_MATCH_LOC_HOST;
  942. spec.loc_host[0] = ip_entry->ip4dst;
  943. }
  944. if (ip_mask->ip4src) {
  945. if (ip_mask->ip4src != IP4_ADDR_FULL_MASK)
  946. return -EINVAL;
  947. spec.match_flags |= EF4_FILTER_MATCH_REM_HOST;
  948. spec.rem_host[0] = ip_entry->ip4src;
  949. }
  950. if (ip_mask->pdst) {
  951. if (ip_mask->pdst != PORT_FULL_MASK)
  952. return -EINVAL;
  953. spec.match_flags |= EF4_FILTER_MATCH_LOC_PORT;
  954. spec.loc_port = ip_entry->pdst;
  955. }
  956. if (ip_mask->psrc) {
  957. if (ip_mask->psrc != PORT_FULL_MASK)
  958. return -EINVAL;
  959. spec.match_flags |= EF4_FILTER_MATCH_REM_PORT;
  960. spec.rem_port = ip_entry->psrc;
  961. }
  962. if (ip_mask->tos)
  963. return -EINVAL;
  964. break;
  965. case TCP_V6_FLOW:
  966. case UDP_V6_FLOW:
  967. spec.match_flags = (EF4_FILTER_MATCH_ETHER_TYPE |
  968. EF4_FILTER_MATCH_IP_PROTO);
  969. spec.ether_type = htons(ETH_P_IPV6);
  970. spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V6_FLOW ?
  971. IPPROTO_TCP : IPPROTO_UDP);
  972. if (!ip6_mask_is_empty(ip6_mask->ip6dst)) {
  973. if (!ip6_mask_is_full(ip6_mask->ip6dst))
  974. return -EINVAL;
  975. spec.match_flags |= EF4_FILTER_MATCH_LOC_HOST;
  976. memcpy(spec.loc_host, ip6_entry->ip6dst, sizeof(spec.loc_host));
  977. }
  978. if (!ip6_mask_is_empty(ip6_mask->ip6src)) {
  979. if (!ip6_mask_is_full(ip6_mask->ip6src))
  980. return -EINVAL;
  981. spec.match_flags |= EF4_FILTER_MATCH_REM_HOST;
  982. memcpy(spec.rem_host, ip6_entry->ip6src, sizeof(spec.rem_host));
  983. }
  984. if (ip6_mask->pdst) {
  985. if (ip6_mask->pdst != PORT_FULL_MASK)
  986. return -EINVAL;
  987. spec.match_flags |= EF4_FILTER_MATCH_LOC_PORT;
  988. spec.loc_port = ip6_entry->pdst;
  989. }
  990. if (ip6_mask->psrc) {
  991. if (ip6_mask->psrc != PORT_FULL_MASK)
  992. return -EINVAL;
  993. spec.match_flags |= EF4_FILTER_MATCH_REM_PORT;
  994. spec.rem_port = ip6_entry->psrc;
  995. }
  996. if (ip6_mask->tclass)
  997. return -EINVAL;
  998. break;
  999. case IPV4_USER_FLOW:
  1000. if (uip_mask->l4_4_bytes || uip_mask->tos || uip_mask->ip_ver ||
  1001. uip_entry->ip_ver != ETH_RX_NFC_IP4)
  1002. return -EINVAL;
  1003. spec.match_flags = EF4_FILTER_MATCH_ETHER_TYPE;
  1004. spec.ether_type = htons(ETH_P_IP);
  1005. if (uip_mask->ip4dst) {
  1006. if (uip_mask->ip4dst != IP4_ADDR_FULL_MASK)
  1007. return -EINVAL;
  1008. spec.match_flags |= EF4_FILTER_MATCH_LOC_HOST;
  1009. spec.loc_host[0] = uip_entry->ip4dst;
  1010. }
  1011. if (uip_mask->ip4src) {
  1012. if (uip_mask->ip4src != IP4_ADDR_FULL_MASK)
  1013. return -EINVAL;
  1014. spec.match_flags |= EF4_FILTER_MATCH_REM_HOST;
  1015. spec.rem_host[0] = uip_entry->ip4src;
  1016. }
  1017. if (uip_mask->proto) {
  1018. if (uip_mask->proto != IP_PROTO_FULL_MASK)
  1019. return -EINVAL;
  1020. spec.match_flags |= EF4_FILTER_MATCH_IP_PROTO;
  1021. spec.ip_proto = uip_entry->proto;
  1022. }
  1023. break;
  1024. case IPV6_USER_FLOW:
  1025. if (uip6_mask->l4_4_bytes || uip6_mask->tclass)
  1026. return -EINVAL;
  1027. spec.match_flags = EF4_FILTER_MATCH_ETHER_TYPE;
  1028. spec.ether_type = htons(ETH_P_IPV6);
  1029. if (!ip6_mask_is_empty(uip6_mask->ip6dst)) {
  1030. if (!ip6_mask_is_full(uip6_mask->ip6dst))
  1031. return -EINVAL;
  1032. spec.match_flags |= EF4_FILTER_MATCH_LOC_HOST;
  1033. memcpy(spec.loc_host, uip6_entry->ip6dst, sizeof(spec.loc_host));
  1034. }
  1035. if (!ip6_mask_is_empty(uip6_mask->ip6src)) {
  1036. if (!ip6_mask_is_full(uip6_mask->ip6src))
  1037. return -EINVAL;
  1038. spec.match_flags |= EF4_FILTER_MATCH_REM_HOST;
  1039. memcpy(spec.rem_host, uip6_entry->ip6src, sizeof(spec.rem_host));
  1040. }
  1041. if (uip6_mask->l4_proto) {
  1042. if (uip6_mask->l4_proto != IP_PROTO_FULL_MASK)
  1043. return -EINVAL;
  1044. spec.match_flags |= EF4_FILTER_MATCH_IP_PROTO;
  1045. spec.ip_proto = uip6_entry->l4_proto;
  1046. }
  1047. break;
  1048. case ETHER_FLOW:
  1049. if (!is_zero_ether_addr(mac_mask->h_dest)) {
  1050. if (ether_addr_equal(mac_mask->h_dest,
  1051. mac_addr_ig_mask))
  1052. spec.match_flags |= EF4_FILTER_MATCH_LOC_MAC_IG;
  1053. else if (is_broadcast_ether_addr(mac_mask->h_dest))
  1054. spec.match_flags |= EF4_FILTER_MATCH_LOC_MAC;
  1055. else
  1056. return -EINVAL;
  1057. ether_addr_copy(spec.loc_mac, mac_entry->h_dest);
  1058. }
  1059. if (!is_zero_ether_addr(mac_mask->h_source)) {
  1060. if (!is_broadcast_ether_addr(mac_mask->h_source))
  1061. return -EINVAL;
  1062. spec.match_flags |= EF4_FILTER_MATCH_REM_MAC;
  1063. ether_addr_copy(spec.rem_mac, mac_entry->h_source);
  1064. }
  1065. if (mac_mask->h_proto) {
  1066. if (mac_mask->h_proto != ETHER_TYPE_FULL_MASK)
  1067. return -EINVAL;
  1068. spec.match_flags |= EF4_FILTER_MATCH_ETHER_TYPE;
  1069. spec.ether_type = mac_entry->h_proto;
  1070. }
  1071. break;
  1072. default:
  1073. return -EINVAL;
  1074. }
  1075. if ((rule->flow_type & FLOW_EXT) && rule->m_ext.vlan_tci) {
  1076. if (rule->m_ext.vlan_tci != htons(0xfff))
  1077. return -EINVAL;
  1078. spec.match_flags |= EF4_FILTER_MATCH_OUTER_VID;
  1079. spec.outer_vid = rule->h_ext.vlan_tci;
  1080. }
  1081. rc = ef4_filter_insert_filter(efx, &spec, true);
  1082. if (rc < 0)
  1083. return rc;
  1084. rule->location = rc;
  1085. return 0;
  1086. }
  1087. static int ef4_ethtool_set_rxnfc(struct net_device *net_dev,
  1088. struct ethtool_rxnfc *info)
  1089. {
  1090. struct ef4_nic *efx = netdev_priv(net_dev);
  1091. if (ef4_filter_get_rx_id_limit(efx) == 0)
  1092. return -EOPNOTSUPP;
  1093. switch (info->cmd) {
  1094. case ETHTOOL_SRXCLSRLINS:
  1095. return ef4_ethtool_set_class_rule(efx, &info->fs);
  1096. case ETHTOOL_SRXCLSRLDEL:
  1097. return ef4_filter_remove_id_safe(efx, EF4_FILTER_PRI_MANUAL,
  1098. info->fs.location);
  1099. default:
  1100. return -EOPNOTSUPP;
  1101. }
  1102. }
  1103. static u32 ef4_ethtool_get_rxfh_indir_size(struct net_device *net_dev)
  1104. {
  1105. struct ef4_nic *efx = netdev_priv(net_dev);
  1106. return ((ef4_nic_rev(efx) < EF4_REV_FALCON_B0 ||
  1107. efx->n_rx_channels == 1) ?
  1108. 0 : ARRAY_SIZE(efx->rx_indir_table));
  1109. }
  1110. static int ef4_ethtool_get_rxfh(struct net_device *net_dev, u32 *indir, u8 *key,
  1111. u8 *hfunc)
  1112. {
  1113. struct ef4_nic *efx = netdev_priv(net_dev);
  1114. if (hfunc)
  1115. *hfunc = ETH_RSS_HASH_TOP;
  1116. if (indir)
  1117. memcpy(indir, efx->rx_indir_table, sizeof(efx->rx_indir_table));
  1118. return 0;
  1119. }
  1120. static int ef4_ethtool_set_rxfh(struct net_device *net_dev, const u32 *indir,
  1121. const u8 *key, const u8 hfunc)
  1122. {
  1123. struct ef4_nic *efx = netdev_priv(net_dev);
  1124. /* We do not allow change in unsupported parameters */
  1125. if (key ||
  1126. (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
  1127. return -EOPNOTSUPP;
  1128. if (!indir)
  1129. return 0;
  1130. return efx->type->rx_push_rss_config(efx, true, indir);
  1131. }
  1132. static int ef4_ethtool_get_module_eeprom(struct net_device *net_dev,
  1133. struct ethtool_eeprom *ee,
  1134. u8 *data)
  1135. {
  1136. struct ef4_nic *efx = netdev_priv(net_dev);
  1137. int ret;
  1138. if (!efx->phy_op || !efx->phy_op->get_module_eeprom)
  1139. return -EOPNOTSUPP;
  1140. mutex_lock(&efx->mac_lock);
  1141. ret = efx->phy_op->get_module_eeprom(efx, ee, data);
  1142. mutex_unlock(&efx->mac_lock);
  1143. return ret;
  1144. }
  1145. static int ef4_ethtool_get_module_info(struct net_device *net_dev,
  1146. struct ethtool_modinfo *modinfo)
  1147. {
  1148. struct ef4_nic *efx = netdev_priv(net_dev);
  1149. int ret;
  1150. if (!efx->phy_op || !efx->phy_op->get_module_info)
  1151. return -EOPNOTSUPP;
  1152. mutex_lock(&efx->mac_lock);
  1153. ret = efx->phy_op->get_module_info(efx, modinfo);
  1154. mutex_unlock(&efx->mac_lock);
  1155. return ret;
  1156. }
  1157. const struct ethtool_ops ef4_ethtool_ops = {
  1158. .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
  1159. ETHTOOL_COALESCE_USECS_IRQ |
  1160. ETHTOOL_COALESCE_USE_ADAPTIVE_RX,
  1161. .get_drvinfo = ef4_ethtool_get_drvinfo,
  1162. .get_regs_len = ef4_ethtool_get_regs_len,
  1163. .get_regs = ef4_ethtool_get_regs,
  1164. .get_msglevel = ef4_ethtool_get_msglevel,
  1165. .set_msglevel = ef4_ethtool_set_msglevel,
  1166. .nway_reset = ef4_ethtool_nway_reset,
  1167. .get_link = ethtool_op_get_link,
  1168. .get_coalesce = ef4_ethtool_get_coalesce,
  1169. .set_coalesce = ef4_ethtool_set_coalesce,
  1170. .get_ringparam = ef4_ethtool_get_ringparam,
  1171. .set_ringparam = ef4_ethtool_set_ringparam,
  1172. .get_pauseparam = ef4_ethtool_get_pauseparam,
  1173. .set_pauseparam = ef4_ethtool_set_pauseparam,
  1174. .get_sset_count = ef4_ethtool_get_sset_count,
  1175. .self_test = ef4_ethtool_self_test,
  1176. .get_strings = ef4_ethtool_get_strings,
  1177. .set_phys_id = ef4_ethtool_phys_id,
  1178. .get_ethtool_stats = ef4_ethtool_get_stats,
  1179. .get_wol = ef4_ethtool_get_wol,
  1180. .set_wol = ef4_ethtool_set_wol,
  1181. .reset = ef4_ethtool_reset,
  1182. .get_rxnfc = ef4_ethtool_get_rxnfc,
  1183. .set_rxnfc = ef4_ethtool_set_rxnfc,
  1184. .get_rxfh_indir_size = ef4_ethtool_get_rxfh_indir_size,
  1185. .get_rxfh = ef4_ethtool_get_rxfh,
  1186. .set_rxfh = ef4_ethtool_set_rxfh,
  1187. .get_module_info = ef4_ethtool_get_module_info,
  1188. .get_module_eeprom = ef4_ethtool_get_module_eeprom,
  1189. .get_link_ksettings = ef4_ethtool_get_link_ksettings,
  1190. .set_link_ksettings = ef4_ethtool_set_link_ksettings,
  1191. };