ethtool.c 35 KB

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