ethtool.c 40 KB

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