ethtool.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029
  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_ulong_stat(void *field)
  50. {
  51. return *(unsigned long *)field;
  52. }
  53. static u64 efx_get_u64_stat(void *field)
  54. {
  55. return *(u64 *) field;
  56. }
  57. static u64 efx_get_atomic_stat(void *field)
  58. {
  59. return atomic_read((atomic_t *) field);
  60. }
  61. #define EFX_ETHTOOL_ULONG_MAC_STAT(field) \
  62. EFX_ETHTOOL_STAT(field, mac_stats, field, \
  63. unsigned long, efx_get_ulong_stat)
  64. #define EFX_ETHTOOL_U64_MAC_STAT(field) \
  65. EFX_ETHTOOL_STAT(field, mac_stats, field, \
  66. u64, efx_get_u64_stat)
  67. #define EFX_ETHTOOL_UINT_NIC_STAT(name) \
  68. EFX_ETHTOOL_STAT(name, nic, n_##name, \
  69. unsigned int, efx_get_uint_stat)
  70. #define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field) \
  71. EFX_ETHTOOL_STAT(field, nic, field, \
  72. atomic_t, efx_get_atomic_stat)
  73. #define EFX_ETHTOOL_UINT_CHANNEL_STAT(field) \
  74. EFX_ETHTOOL_STAT(field, channel, n_##field, \
  75. unsigned int, efx_get_uint_stat)
  76. #define EFX_ETHTOOL_UINT_TXQ_STAT(field) \
  77. EFX_ETHTOOL_STAT(tx_##field, tx_queue, field, \
  78. unsigned int, efx_get_uint_stat)
  79. static struct efx_ethtool_stat efx_ethtool_stats[] = {
  80. EFX_ETHTOOL_U64_MAC_STAT(tx_bytes),
  81. EFX_ETHTOOL_U64_MAC_STAT(tx_good_bytes),
  82. EFX_ETHTOOL_U64_MAC_STAT(tx_bad_bytes),
  83. EFX_ETHTOOL_ULONG_MAC_STAT(tx_packets),
  84. EFX_ETHTOOL_ULONG_MAC_STAT(tx_bad),
  85. EFX_ETHTOOL_ULONG_MAC_STAT(tx_pause),
  86. EFX_ETHTOOL_ULONG_MAC_STAT(tx_control),
  87. EFX_ETHTOOL_ULONG_MAC_STAT(tx_unicast),
  88. EFX_ETHTOOL_ULONG_MAC_STAT(tx_multicast),
  89. EFX_ETHTOOL_ULONG_MAC_STAT(tx_broadcast),
  90. EFX_ETHTOOL_ULONG_MAC_STAT(tx_lt64),
  91. EFX_ETHTOOL_ULONG_MAC_STAT(tx_64),
  92. EFX_ETHTOOL_ULONG_MAC_STAT(tx_65_to_127),
  93. EFX_ETHTOOL_ULONG_MAC_STAT(tx_128_to_255),
  94. EFX_ETHTOOL_ULONG_MAC_STAT(tx_256_to_511),
  95. EFX_ETHTOOL_ULONG_MAC_STAT(tx_512_to_1023),
  96. EFX_ETHTOOL_ULONG_MAC_STAT(tx_1024_to_15xx),
  97. EFX_ETHTOOL_ULONG_MAC_STAT(tx_15xx_to_jumbo),
  98. EFX_ETHTOOL_ULONG_MAC_STAT(tx_gtjumbo),
  99. EFX_ETHTOOL_ULONG_MAC_STAT(tx_collision),
  100. EFX_ETHTOOL_ULONG_MAC_STAT(tx_single_collision),
  101. EFX_ETHTOOL_ULONG_MAC_STAT(tx_multiple_collision),
  102. EFX_ETHTOOL_ULONG_MAC_STAT(tx_excessive_collision),
  103. EFX_ETHTOOL_ULONG_MAC_STAT(tx_deferred),
  104. EFX_ETHTOOL_ULONG_MAC_STAT(tx_late_collision),
  105. EFX_ETHTOOL_ULONG_MAC_STAT(tx_excessive_deferred),
  106. EFX_ETHTOOL_ULONG_MAC_STAT(tx_non_tcpudp),
  107. EFX_ETHTOOL_ULONG_MAC_STAT(tx_mac_src_error),
  108. EFX_ETHTOOL_ULONG_MAC_STAT(tx_ip_src_error),
  109. EFX_ETHTOOL_UINT_TXQ_STAT(tso_bursts),
  110. EFX_ETHTOOL_UINT_TXQ_STAT(tso_long_headers),
  111. EFX_ETHTOOL_UINT_TXQ_STAT(tso_packets),
  112. EFX_ETHTOOL_UINT_TXQ_STAT(pushes),
  113. EFX_ETHTOOL_U64_MAC_STAT(rx_bytes),
  114. EFX_ETHTOOL_U64_MAC_STAT(rx_good_bytes),
  115. EFX_ETHTOOL_U64_MAC_STAT(rx_bad_bytes),
  116. EFX_ETHTOOL_ULONG_MAC_STAT(rx_packets),
  117. EFX_ETHTOOL_ULONG_MAC_STAT(rx_good),
  118. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad),
  119. EFX_ETHTOOL_ULONG_MAC_STAT(rx_pause),
  120. EFX_ETHTOOL_ULONG_MAC_STAT(rx_control),
  121. EFX_ETHTOOL_ULONG_MAC_STAT(rx_unicast),
  122. EFX_ETHTOOL_ULONG_MAC_STAT(rx_multicast),
  123. EFX_ETHTOOL_ULONG_MAC_STAT(rx_broadcast),
  124. EFX_ETHTOOL_ULONG_MAC_STAT(rx_lt64),
  125. EFX_ETHTOOL_ULONG_MAC_STAT(rx_64),
  126. EFX_ETHTOOL_ULONG_MAC_STAT(rx_65_to_127),
  127. EFX_ETHTOOL_ULONG_MAC_STAT(rx_128_to_255),
  128. EFX_ETHTOOL_ULONG_MAC_STAT(rx_256_to_511),
  129. EFX_ETHTOOL_ULONG_MAC_STAT(rx_512_to_1023),
  130. EFX_ETHTOOL_ULONG_MAC_STAT(rx_1024_to_15xx),
  131. EFX_ETHTOOL_ULONG_MAC_STAT(rx_15xx_to_jumbo),
  132. EFX_ETHTOOL_ULONG_MAC_STAT(rx_gtjumbo),
  133. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_lt64),
  134. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_64_to_15xx),
  135. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_15xx_to_jumbo),
  136. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_gtjumbo),
  137. EFX_ETHTOOL_ULONG_MAC_STAT(rx_overflow),
  138. EFX_ETHTOOL_ULONG_MAC_STAT(rx_missed),
  139. EFX_ETHTOOL_ULONG_MAC_STAT(rx_false_carrier),
  140. EFX_ETHTOOL_ULONG_MAC_STAT(rx_symbol_error),
  141. EFX_ETHTOOL_ULONG_MAC_STAT(rx_align_error),
  142. EFX_ETHTOOL_ULONG_MAC_STAT(rx_length_error),
  143. EFX_ETHTOOL_ULONG_MAC_STAT(rx_internal_error),
  144. EFX_ETHTOOL_UINT_NIC_STAT(rx_nodesc_drop_cnt),
  145. EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset),
  146. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc),
  147. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),
  148. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err),
  149. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch),
  150. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
  151. };
  152. /* Number of ethtool statistics */
  153. #define EFX_ETHTOOL_NUM_STATS ARRAY_SIZE(efx_ethtool_stats)
  154. #define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB
  155. /**************************************************************************
  156. *
  157. * Ethtool operations
  158. *
  159. **************************************************************************
  160. */
  161. /* Identify device by flashing LEDs */
  162. static int efx_ethtool_phys_id(struct net_device *net_dev,
  163. enum ethtool_phys_id_state state)
  164. {
  165. struct efx_nic *efx = netdev_priv(net_dev);
  166. enum efx_led_mode mode = EFX_LED_DEFAULT;
  167. switch (state) {
  168. case ETHTOOL_ID_ON:
  169. mode = EFX_LED_ON;
  170. break;
  171. case ETHTOOL_ID_OFF:
  172. mode = EFX_LED_OFF;
  173. break;
  174. case ETHTOOL_ID_INACTIVE:
  175. mode = EFX_LED_DEFAULT;
  176. break;
  177. case ETHTOOL_ID_ACTIVE:
  178. return 1; /* cycle on/off once per second */
  179. }
  180. efx->type->set_id_led(efx, mode);
  181. return 0;
  182. }
  183. /* This must be called with rtnl_lock held. */
  184. static int efx_ethtool_get_settings(struct net_device *net_dev,
  185. struct ethtool_cmd *ecmd)
  186. {
  187. struct efx_nic *efx = netdev_priv(net_dev);
  188. struct efx_link_state *link_state = &efx->link_state;
  189. mutex_lock(&efx->mac_lock);
  190. efx->phy_op->get_settings(efx, ecmd);
  191. mutex_unlock(&efx->mac_lock);
  192. /* GMAC does not support 1000Mbps HD */
  193. ecmd->supported &= ~SUPPORTED_1000baseT_Half;
  194. /* Both MACs support pause frames (bidirectional and respond-only) */
  195. ecmd->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
  196. if (LOOPBACK_INTERNAL(efx)) {
  197. ethtool_cmd_speed_set(ecmd, link_state->speed);
  198. ecmd->duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF;
  199. }
  200. return 0;
  201. }
  202. /* This must be called with rtnl_lock held. */
  203. static int efx_ethtool_set_settings(struct net_device *net_dev,
  204. struct ethtool_cmd *ecmd)
  205. {
  206. struct efx_nic *efx = netdev_priv(net_dev);
  207. int rc;
  208. /* GMAC does not support 1000Mbps HD */
  209. if ((ethtool_cmd_speed(ecmd) == SPEED_1000) &&
  210. (ecmd->duplex != DUPLEX_FULL)) {
  211. netif_dbg(efx, drv, efx->net_dev,
  212. "rejecting unsupported 1000Mbps HD setting\n");
  213. return -EINVAL;
  214. }
  215. mutex_lock(&efx->mac_lock);
  216. rc = efx->phy_op->set_settings(efx, ecmd);
  217. mutex_unlock(&efx->mac_lock);
  218. return rc;
  219. }
  220. static void efx_ethtool_get_drvinfo(struct net_device *net_dev,
  221. struct ethtool_drvinfo *info)
  222. {
  223. struct efx_nic *efx = netdev_priv(net_dev);
  224. strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
  225. strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version));
  226. if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0)
  227. efx_mcdi_print_fwver(efx, info->fw_version,
  228. sizeof(info->fw_version));
  229. strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
  230. }
  231. static int efx_ethtool_get_regs_len(struct net_device *net_dev)
  232. {
  233. return efx_nic_get_regs_len(netdev_priv(net_dev));
  234. }
  235. static void efx_ethtool_get_regs(struct net_device *net_dev,
  236. struct ethtool_regs *regs, void *buf)
  237. {
  238. struct efx_nic *efx = netdev_priv(net_dev);
  239. regs->version = efx->type->revision;
  240. efx_nic_get_regs(efx, buf);
  241. }
  242. static u32 efx_ethtool_get_msglevel(struct net_device *net_dev)
  243. {
  244. struct efx_nic *efx = netdev_priv(net_dev);
  245. return efx->msg_enable;
  246. }
  247. static void efx_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable)
  248. {
  249. struct efx_nic *efx = netdev_priv(net_dev);
  250. efx->msg_enable = msg_enable;
  251. }
  252. /**
  253. * efx_fill_test - fill in an individual self-test entry
  254. * @test_index: Index of the test
  255. * @strings: Ethtool strings, or %NULL
  256. * @data: Ethtool test results, or %NULL
  257. * @test: Pointer to test result (used only if data != %NULL)
  258. * @unit_format: Unit name format (e.g. "chan\%d")
  259. * @unit_id: Unit id (e.g. 0 for "chan0")
  260. * @test_format: Test name format (e.g. "loopback.\%s.tx.sent")
  261. * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
  262. *
  263. * Fill in an individual self-test entry.
  264. */
  265. static void efx_fill_test(unsigned int test_index,
  266. struct ethtool_string *strings, u64 *data,
  267. int *test, const char *unit_format, int unit_id,
  268. const char *test_format, const char *test_id)
  269. {
  270. struct ethtool_string unit_str, test_str;
  271. /* Fill data value, if applicable */
  272. if (data)
  273. data[test_index] = *test;
  274. /* Fill string, if applicable */
  275. if (strings) {
  276. if (strchr(unit_format, '%'))
  277. snprintf(unit_str.name, sizeof(unit_str.name),
  278. unit_format, unit_id);
  279. else
  280. strcpy(unit_str.name, unit_format);
  281. snprintf(test_str.name, sizeof(test_str.name),
  282. test_format, test_id);
  283. snprintf(strings[test_index].name,
  284. sizeof(strings[test_index].name),
  285. "%-6s %-24s", unit_str.name, test_str.name);
  286. }
  287. }
  288. #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
  289. #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
  290. #define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
  291. #define EFX_LOOPBACK_NAME(_mode, _counter) \
  292. "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode)
  293. /**
  294. * efx_fill_loopback_test - fill in a block of loopback self-test entries
  295. * @efx: Efx NIC
  296. * @lb_tests: Efx loopback self-test results structure
  297. * @mode: Loopback test mode
  298. * @test_index: Starting index of the test
  299. * @strings: Ethtool strings, or %NULL
  300. * @data: Ethtool test results, or %NULL
  301. */
  302. static int efx_fill_loopback_test(struct efx_nic *efx,
  303. struct efx_loopback_self_tests *lb_tests,
  304. enum efx_loopback_mode mode,
  305. unsigned int test_index,
  306. struct ethtool_string *strings, u64 *data)
  307. {
  308. struct efx_channel *channel = efx_get_channel(efx, 0);
  309. struct efx_tx_queue *tx_queue;
  310. efx_for_each_channel_tx_queue(tx_queue, channel) {
  311. efx_fill_test(test_index++, strings, data,
  312. &lb_tests->tx_sent[tx_queue->queue],
  313. EFX_TX_QUEUE_NAME(tx_queue),
  314. EFX_LOOPBACK_NAME(mode, "tx_sent"));
  315. efx_fill_test(test_index++, strings, data,
  316. &lb_tests->tx_done[tx_queue->queue],
  317. EFX_TX_QUEUE_NAME(tx_queue),
  318. EFX_LOOPBACK_NAME(mode, "tx_done"));
  319. }
  320. efx_fill_test(test_index++, strings, data,
  321. &lb_tests->rx_good,
  322. "rx", 0,
  323. EFX_LOOPBACK_NAME(mode, "rx_good"));
  324. efx_fill_test(test_index++, strings, data,
  325. &lb_tests->rx_bad,
  326. "rx", 0,
  327. EFX_LOOPBACK_NAME(mode, "rx_bad"));
  328. return test_index;
  329. }
  330. /**
  331. * efx_ethtool_fill_self_tests - get self-test details
  332. * @efx: Efx NIC
  333. * @tests: Efx self-test results structure, or %NULL
  334. * @strings: Ethtool strings, or %NULL
  335. * @data: Ethtool test results, or %NULL
  336. */
  337. static int efx_ethtool_fill_self_tests(struct efx_nic *efx,
  338. struct efx_self_tests *tests,
  339. struct ethtool_string *strings,
  340. u64 *data)
  341. {
  342. struct efx_channel *channel;
  343. unsigned int n = 0, i;
  344. enum efx_loopback_mode mode;
  345. efx_fill_test(n++, strings, data, &tests->phy_alive,
  346. "phy", 0, "alive", NULL);
  347. efx_fill_test(n++, strings, data, &tests->nvram,
  348. "core", 0, "nvram", NULL);
  349. efx_fill_test(n++, strings, data, &tests->interrupt,
  350. "core", 0, "interrupt", NULL);
  351. /* Event queues */
  352. efx_for_each_channel(channel, efx) {
  353. efx_fill_test(n++, strings, data,
  354. &tests->eventq_dma[channel->channel],
  355. EFX_CHANNEL_NAME(channel),
  356. "eventq.dma", NULL);
  357. efx_fill_test(n++, strings, data,
  358. &tests->eventq_int[channel->channel],
  359. EFX_CHANNEL_NAME(channel),
  360. "eventq.int", NULL);
  361. efx_fill_test(n++, strings, data,
  362. &tests->eventq_poll[channel->channel],
  363. EFX_CHANNEL_NAME(channel),
  364. "eventq.poll", NULL);
  365. }
  366. efx_fill_test(n++, strings, data, &tests->registers,
  367. "core", 0, "registers", NULL);
  368. if (efx->phy_op->run_tests != NULL) {
  369. EFX_BUG_ON_PARANOID(efx->phy_op->test_name == NULL);
  370. for (i = 0; true; ++i) {
  371. const char *name;
  372. EFX_BUG_ON_PARANOID(i >= EFX_MAX_PHY_TESTS);
  373. name = efx->phy_op->test_name(efx, i);
  374. if (name == NULL)
  375. break;
  376. efx_fill_test(n++, strings, data, &tests->phy_ext[i],
  377. "phy", 0, name, NULL);
  378. }
  379. }
  380. /* Loopback tests */
  381. for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
  382. if (!(efx->loopback_modes & (1 << mode)))
  383. continue;
  384. n = efx_fill_loopback_test(efx,
  385. &tests->loopback[mode], mode, n,
  386. strings, data);
  387. }
  388. return n;
  389. }
  390. static int efx_ethtool_get_sset_count(struct net_device *net_dev,
  391. int string_set)
  392. {
  393. switch (string_set) {
  394. case ETH_SS_STATS:
  395. return EFX_ETHTOOL_NUM_STATS;
  396. case ETH_SS_TEST:
  397. return efx_ethtool_fill_self_tests(netdev_priv(net_dev),
  398. NULL, NULL, NULL);
  399. default:
  400. return -EINVAL;
  401. }
  402. }
  403. static void efx_ethtool_get_strings(struct net_device *net_dev,
  404. u32 string_set, u8 *strings)
  405. {
  406. struct efx_nic *efx = netdev_priv(net_dev);
  407. struct ethtool_string *ethtool_strings =
  408. (struct ethtool_string *)strings;
  409. int i;
  410. switch (string_set) {
  411. case ETH_SS_STATS:
  412. for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++)
  413. strncpy(ethtool_strings[i].name,
  414. efx_ethtool_stats[i].name,
  415. sizeof(ethtool_strings[i].name));
  416. break;
  417. case ETH_SS_TEST:
  418. efx_ethtool_fill_self_tests(efx, NULL,
  419. ethtool_strings, NULL);
  420. break;
  421. default:
  422. /* No other string sets */
  423. break;
  424. }
  425. }
  426. static void efx_ethtool_get_stats(struct net_device *net_dev,
  427. struct ethtool_stats *stats,
  428. u64 *data)
  429. {
  430. struct efx_nic *efx = netdev_priv(net_dev);
  431. struct efx_mac_stats *mac_stats = &efx->mac_stats;
  432. struct efx_ethtool_stat *stat;
  433. struct efx_channel *channel;
  434. struct efx_tx_queue *tx_queue;
  435. struct rtnl_link_stats64 temp;
  436. int i;
  437. EFX_BUG_ON_PARANOID(stats->n_stats != EFX_ETHTOOL_NUM_STATS);
  438. /* Update MAC and NIC statistics */
  439. dev_get_stats(net_dev, &temp);
  440. /* Fill detailed statistics buffer */
  441. for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++) {
  442. stat = &efx_ethtool_stats[i];
  443. switch (stat->source) {
  444. case EFX_ETHTOOL_STAT_SOURCE_mac_stats:
  445. data[i] = stat->get_stat((void *)mac_stats +
  446. stat->offset);
  447. break;
  448. case EFX_ETHTOOL_STAT_SOURCE_nic:
  449. data[i] = stat->get_stat((void *)efx + stat->offset);
  450. break;
  451. case EFX_ETHTOOL_STAT_SOURCE_channel:
  452. data[i] = 0;
  453. efx_for_each_channel(channel, efx)
  454. data[i] += stat->get_stat((void *)channel +
  455. stat->offset);
  456. break;
  457. case EFX_ETHTOOL_STAT_SOURCE_tx_queue:
  458. data[i] = 0;
  459. efx_for_each_channel(channel, efx) {
  460. efx_for_each_channel_tx_queue(tx_queue, channel)
  461. data[i] +=
  462. stat->get_stat((void *)tx_queue
  463. + stat->offset);
  464. }
  465. break;
  466. }
  467. }
  468. }
  469. static void efx_ethtool_self_test(struct net_device *net_dev,
  470. struct ethtool_test *test, u64 *data)
  471. {
  472. struct efx_nic *efx = netdev_priv(net_dev);
  473. struct efx_self_tests *efx_tests;
  474. int already_up;
  475. int rc = -ENOMEM;
  476. efx_tests = kzalloc(sizeof(*efx_tests), GFP_KERNEL);
  477. if (!efx_tests)
  478. goto fail;
  479. ASSERT_RTNL();
  480. if (efx->state != STATE_RUNNING) {
  481. rc = -EIO;
  482. goto fail1;
  483. }
  484. netif_info(efx, drv, efx->net_dev, "starting %sline testing\n",
  485. (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
  486. /* We need rx buffers and interrupts. */
  487. already_up = (efx->net_dev->flags & IFF_UP);
  488. if (!already_up) {
  489. rc = dev_open(efx->net_dev);
  490. if (rc) {
  491. netif_err(efx, drv, efx->net_dev,
  492. "failed opening device.\n");
  493. goto fail1;
  494. }
  495. }
  496. rc = efx_selftest(efx, efx_tests, test->flags);
  497. if (!already_up)
  498. dev_close(efx->net_dev);
  499. netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n",
  500. rc == 0 ? "passed" : "failed",
  501. (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
  502. fail1:
  503. /* Fill ethtool results structures */
  504. efx_ethtool_fill_self_tests(efx, efx_tests, NULL, data);
  505. kfree(efx_tests);
  506. fail:
  507. if (rc)
  508. test->flags |= ETH_TEST_FL_FAILED;
  509. }
  510. /* Restart autonegotiation */
  511. static int efx_ethtool_nway_reset(struct net_device *net_dev)
  512. {
  513. struct efx_nic *efx = netdev_priv(net_dev);
  514. return mdio45_nway_restart(&efx->mdio);
  515. }
  516. static int efx_ethtool_get_coalesce(struct net_device *net_dev,
  517. struct ethtool_coalesce *coalesce)
  518. {
  519. struct efx_nic *efx = netdev_priv(net_dev);
  520. struct efx_channel *channel;
  521. memset(coalesce, 0, sizeof(*coalesce));
  522. /* Find lowest IRQ moderation across all used TX queues */
  523. coalesce->tx_coalesce_usecs_irq = ~((u32) 0);
  524. efx_for_each_channel(channel, efx) {
  525. if (!efx_channel_has_tx_queues(channel))
  526. continue;
  527. if (channel->irq_moderation < coalesce->tx_coalesce_usecs_irq) {
  528. if (channel->channel < efx->n_rx_channels)
  529. coalesce->tx_coalesce_usecs_irq =
  530. channel->irq_moderation;
  531. else
  532. coalesce->tx_coalesce_usecs_irq = 0;
  533. }
  534. }
  535. coalesce->use_adaptive_rx_coalesce = efx->irq_rx_adaptive;
  536. coalesce->rx_coalesce_usecs_irq = efx->irq_rx_moderation;
  537. coalesce->tx_coalesce_usecs_irq *= EFX_IRQ_MOD_RESOLUTION;
  538. coalesce->rx_coalesce_usecs_irq *= EFX_IRQ_MOD_RESOLUTION;
  539. return 0;
  540. }
  541. /* Set coalescing parameters
  542. * The difficulties occur for shared channels
  543. */
  544. static int efx_ethtool_set_coalesce(struct net_device *net_dev,
  545. struct ethtool_coalesce *coalesce)
  546. {
  547. struct efx_nic *efx = netdev_priv(net_dev);
  548. struct efx_channel *channel;
  549. unsigned tx_usecs, rx_usecs, adaptive;
  550. if (coalesce->use_adaptive_tx_coalesce)
  551. return -EOPNOTSUPP;
  552. if (coalesce->rx_coalesce_usecs || coalesce->tx_coalesce_usecs) {
  553. netif_err(efx, drv, efx->net_dev, "invalid coalescing setting. "
  554. "Only rx/tx_coalesce_usecs_irq are supported\n");
  555. return -EOPNOTSUPP;
  556. }
  557. rx_usecs = coalesce->rx_coalesce_usecs_irq;
  558. tx_usecs = coalesce->tx_coalesce_usecs_irq;
  559. adaptive = coalesce->use_adaptive_rx_coalesce;
  560. /* If the channel is shared only allow RX parameters to be set */
  561. efx_for_each_channel(channel, efx) {
  562. if (efx_channel_has_rx_queue(channel) &&
  563. efx_channel_has_tx_queues(channel) &&
  564. tx_usecs) {
  565. netif_err(efx, drv, efx->net_dev, "Channel is shared. "
  566. "Only RX coalescing may be set\n");
  567. return -EOPNOTSUPP;
  568. }
  569. }
  570. efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive);
  571. efx_for_each_channel(channel, efx)
  572. efx->type->push_irq_moderation(channel);
  573. return 0;
  574. }
  575. static void efx_ethtool_get_ringparam(struct net_device *net_dev,
  576. struct ethtool_ringparam *ring)
  577. {
  578. struct efx_nic *efx = netdev_priv(net_dev);
  579. ring->rx_max_pending = EFX_MAX_DMAQ_SIZE;
  580. ring->tx_max_pending = EFX_MAX_DMAQ_SIZE;
  581. ring->rx_mini_max_pending = 0;
  582. ring->rx_jumbo_max_pending = 0;
  583. ring->rx_pending = efx->rxq_entries;
  584. ring->tx_pending = efx->txq_entries;
  585. ring->rx_mini_pending = 0;
  586. ring->rx_jumbo_pending = 0;
  587. }
  588. static int efx_ethtool_set_ringparam(struct net_device *net_dev,
  589. struct ethtool_ringparam *ring)
  590. {
  591. struct efx_nic *efx = netdev_priv(net_dev);
  592. if (ring->rx_mini_pending || ring->rx_jumbo_pending ||
  593. ring->rx_pending > EFX_MAX_DMAQ_SIZE ||
  594. ring->tx_pending > EFX_MAX_DMAQ_SIZE)
  595. return -EINVAL;
  596. if (ring->rx_pending < EFX_MIN_RING_SIZE ||
  597. ring->tx_pending < EFX_MIN_RING_SIZE) {
  598. netif_err(efx, drv, efx->net_dev,
  599. "TX and RX queues cannot be smaller than %ld\n",
  600. EFX_MIN_RING_SIZE);
  601. return -EINVAL;
  602. }
  603. return efx_realloc_channels(efx, ring->rx_pending, ring->tx_pending);
  604. }
  605. static int efx_ethtool_set_pauseparam(struct net_device *net_dev,
  606. struct ethtool_pauseparam *pause)
  607. {
  608. struct efx_nic *efx = netdev_priv(net_dev);
  609. u8 wanted_fc, old_fc;
  610. u32 old_adv;
  611. bool reset;
  612. int rc = 0;
  613. mutex_lock(&efx->mac_lock);
  614. wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
  615. (pause->tx_pause ? EFX_FC_TX : 0) |
  616. (pause->autoneg ? EFX_FC_AUTO : 0));
  617. if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
  618. netif_dbg(efx, drv, efx->net_dev,
  619. "Flow control unsupported: tx ON rx OFF\n");
  620. rc = -EINVAL;
  621. goto out;
  622. }
  623. if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising) {
  624. netif_dbg(efx, drv, efx->net_dev,
  625. "Autonegotiation is disabled\n");
  626. rc = -EINVAL;
  627. goto out;
  628. }
  629. /* TX flow control may automatically turn itself off if the
  630. * link partner (intermittently) stops responding to pause
  631. * frames. There isn't any indication that this has happened,
  632. * so the best we do is leave it up to the user to spot this
  633. * and fix it be cycling transmit flow control on this end. */
  634. reset = (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX);
  635. if (EFX_WORKAROUND_11482(efx) && reset) {
  636. if (efx_nic_rev(efx) == EFX_REV_FALCON_B0) {
  637. /* Recover by resetting the EM block */
  638. falcon_stop_nic_stats(efx);
  639. falcon_drain_tx_fifo(efx);
  640. efx->mac_op->reconfigure(efx);
  641. falcon_start_nic_stats(efx);
  642. } else {
  643. /* Schedule a reset to recover */
  644. efx_schedule_reset(efx, RESET_TYPE_INVISIBLE);
  645. }
  646. }
  647. old_adv = efx->link_advertising;
  648. old_fc = efx->wanted_fc;
  649. efx_link_set_wanted_fc(efx, wanted_fc);
  650. if (efx->link_advertising != old_adv ||
  651. (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) {
  652. rc = efx->phy_op->reconfigure(efx);
  653. if (rc) {
  654. netif_err(efx, drv, efx->net_dev,
  655. "Unable to advertise requested flow "
  656. "control setting\n");
  657. goto out;
  658. }
  659. }
  660. /* Reconfigure the MAC. The PHY *may* generate a link state change event
  661. * if the user just changed the advertised capabilities, but there's no
  662. * harm doing this twice */
  663. efx->mac_op->reconfigure(efx);
  664. out:
  665. mutex_unlock(&efx->mac_lock);
  666. return rc;
  667. }
  668. static void efx_ethtool_get_pauseparam(struct net_device *net_dev,
  669. struct ethtool_pauseparam *pause)
  670. {
  671. struct efx_nic *efx = netdev_priv(net_dev);
  672. pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX);
  673. pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX);
  674. pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO);
  675. }
  676. static void efx_ethtool_get_wol(struct net_device *net_dev,
  677. struct ethtool_wolinfo *wol)
  678. {
  679. struct efx_nic *efx = netdev_priv(net_dev);
  680. return efx->type->get_wol(efx, wol);
  681. }
  682. static int efx_ethtool_set_wol(struct net_device *net_dev,
  683. struct ethtool_wolinfo *wol)
  684. {
  685. struct efx_nic *efx = netdev_priv(net_dev);
  686. return efx->type->set_wol(efx, wol->wolopts);
  687. }
  688. static int efx_ethtool_reset(struct net_device *net_dev, u32 *flags)
  689. {
  690. struct efx_nic *efx = netdev_priv(net_dev);
  691. enum reset_type method;
  692. enum {
  693. ETH_RESET_EFX_INVISIBLE = (ETH_RESET_DMA | ETH_RESET_FILTER |
  694. ETH_RESET_OFFLOAD | ETH_RESET_MAC)
  695. };
  696. /* Check for minimal reset flags */
  697. if ((*flags & ETH_RESET_EFX_INVISIBLE) != ETH_RESET_EFX_INVISIBLE)
  698. return -EINVAL;
  699. *flags ^= ETH_RESET_EFX_INVISIBLE;
  700. method = RESET_TYPE_INVISIBLE;
  701. if (*flags & ETH_RESET_PHY) {
  702. *flags ^= ETH_RESET_PHY;
  703. method = RESET_TYPE_ALL;
  704. }
  705. if ((*flags & efx->type->reset_world_flags) ==
  706. efx->type->reset_world_flags) {
  707. *flags ^= efx->type->reset_world_flags;
  708. method = RESET_TYPE_WORLD;
  709. }
  710. return efx_reset(efx, method);
  711. }
  712. static int
  713. efx_ethtool_get_rxnfc(struct net_device *net_dev,
  714. struct ethtool_rxnfc *info, void *rules __always_unused)
  715. {
  716. struct efx_nic *efx = netdev_priv(net_dev);
  717. switch (info->cmd) {
  718. case ETHTOOL_GRXRINGS:
  719. info->data = efx->n_rx_channels;
  720. return 0;
  721. case ETHTOOL_GRXFH: {
  722. unsigned min_revision = 0;
  723. info->data = 0;
  724. switch (info->flow_type) {
  725. case TCP_V4_FLOW:
  726. info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  727. /* fall through */
  728. case UDP_V4_FLOW:
  729. case SCTP_V4_FLOW:
  730. case AH_ESP_V4_FLOW:
  731. case IPV4_FLOW:
  732. info->data |= RXH_IP_SRC | RXH_IP_DST;
  733. min_revision = EFX_REV_FALCON_B0;
  734. break;
  735. case TCP_V6_FLOW:
  736. info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  737. /* fall through */
  738. case UDP_V6_FLOW:
  739. case SCTP_V6_FLOW:
  740. case AH_ESP_V6_FLOW:
  741. case IPV6_FLOW:
  742. info->data |= RXH_IP_SRC | RXH_IP_DST;
  743. min_revision = EFX_REV_SIENA_A0;
  744. break;
  745. default:
  746. break;
  747. }
  748. if (efx_nic_rev(efx) < min_revision)
  749. info->data = 0;
  750. return 0;
  751. }
  752. default:
  753. return -EOPNOTSUPP;
  754. }
  755. }
  756. static int efx_ethtool_set_rx_ntuple(struct net_device *net_dev,
  757. struct ethtool_rx_ntuple *ntuple)
  758. {
  759. struct efx_nic *efx = netdev_priv(net_dev);
  760. struct ethtool_tcpip4_spec *ip_entry = &ntuple->fs.h_u.tcp_ip4_spec;
  761. struct ethtool_tcpip4_spec *ip_mask = &ntuple->fs.m_u.tcp_ip4_spec;
  762. struct ethhdr *mac_entry = &ntuple->fs.h_u.ether_spec;
  763. struct ethhdr *mac_mask = &ntuple->fs.m_u.ether_spec;
  764. struct efx_filter_spec filter;
  765. int rc;
  766. /* Range-check action */
  767. if (ntuple->fs.action < ETHTOOL_RXNTUPLE_ACTION_CLEAR ||
  768. ntuple->fs.action >= (s32)efx->n_rx_channels)
  769. return -EINVAL;
  770. if (~ntuple->fs.data_mask)
  771. return -EINVAL;
  772. efx_filter_init_rx(&filter, EFX_FILTER_PRI_MANUAL, 0,
  773. (ntuple->fs.action == ETHTOOL_RXNTUPLE_ACTION_DROP) ?
  774. 0xfff : ntuple->fs.action);
  775. switch (ntuple->fs.flow_type) {
  776. case TCP_V4_FLOW:
  777. case UDP_V4_FLOW: {
  778. u8 proto = (ntuple->fs.flow_type == TCP_V4_FLOW ?
  779. IPPROTO_TCP : IPPROTO_UDP);
  780. /* Must match all of destination, */
  781. if (ip_mask->ip4dst | ip_mask->pdst)
  782. return -EINVAL;
  783. /* all or none of source, */
  784. if ((ip_mask->ip4src | ip_mask->psrc) &&
  785. ((__force u32)~ip_mask->ip4src |
  786. (__force u16)~ip_mask->psrc))
  787. return -EINVAL;
  788. /* and nothing else */
  789. if ((u8)~ip_mask->tos | (u16)~ntuple->fs.vlan_tag_mask)
  790. return -EINVAL;
  791. if (!ip_mask->ip4src)
  792. rc = efx_filter_set_ipv4_full(&filter, proto,
  793. ip_entry->ip4dst,
  794. ip_entry->pdst,
  795. ip_entry->ip4src,
  796. ip_entry->psrc);
  797. else
  798. rc = efx_filter_set_ipv4_local(&filter, proto,
  799. ip_entry->ip4dst,
  800. ip_entry->pdst);
  801. if (rc)
  802. return rc;
  803. break;
  804. }
  805. case ETHER_FLOW:
  806. /* Must match all of destination, */
  807. if (!is_zero_ether_addr(mac_mask->h_dest))
  808. return -EINVAL;
  809. /* all or none of VID, */
  810. if (ntuple->fs.vlan_tag_mask != 0xf000 &&
  811. ntuple->fs.vlan_tag_mask != 0xffff)
  812. return -EINVAL;
  813. /* and nothing else */
  814. if (!is_broadcast_ether_addr(mac_mask->h_source) ||
  815. mac_mask->h_proto != htons(0xffff))
  816. return -EINVAL;
  817. rc = efx_filter_set_eth_local(
  818. &filter,
  819. (ntuple->fs.vlan_tag_mask == 0xf000) ?
  820. ntuple->fs.vlan_tag : EFX_FILTER_VID_UNSPEC,
  821. mac_entry->h_dest);
  822. if (rc)
  823. return rc;
  824. break;
  825. default:
  826. return -EINVAL;
  827. }
  828. if (ntuple->fs.action == ETHTOOL_RXNTUPLE_ACTION_CLEAR)
  829. return efx_filter_remove_filter(efx, &filter);
  830. rc = efx_filter_insert_filter(efx, &filter, true);
  831. return rc < 0 ? rc : 0;
  832. }
  833. static int efx_ethtool_get_rxfh_indir(struct net_device *net_dev,
  834. struct ethtool_rxfh_indir *indir)
  835. {
  836. struct efx_nic *efx = netdev_priv(net_dev);
  837. size_t copy_size =
  838. min_t(size_t, indir->size, ARRAY_SIZE(efx->rx_indir_table));
  839. if (efx_nic_rev(efx) < EFX_REV_FALCON_B0)
  840. return -EOPNOTSUPP;
  841. indir->size = ARRAY_SIZE(efx->rx_indir_table);
  842. memcpy(indir->ring_index, efx->rx_indir_table,
  843. copy_size * sizeof(indir->ring_index[0]));
  844. return 0;
  845. }
  846. static int efx_ethtool_set_rxfh_indir(struct net_device *net_dev,
  847. const struct ethtool_rxfh_indir *indir)
  848. {
  849. struct efx_nic *efx = netdev_priv(net_dev);
  850. size_t i;
  851. if (efx_nic_rev(efx) < EFX_REV_FALCON_B0)
  852. return -EOPNOTSUPP;
  853. /* Validate size and indices */
  854. if (indir->size != ARRAY_SIZE(efx->rx_indir_table))
  855. return -EINVAL;
  856. for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); i++)
  857. if (indir->ring_index[i] >= efx->n_rx_channels)
  858. return -EINVAL;
  859. memcpy(efx->rx_indir_table, indir->ring_index,
  860. sizeof(efx->rx_indir_table));
  861. efx_nic_push_rx_indir_table(efx);
  862. return 0;
  863. }
  864. const struct ethtool_ops efx_ethtool_ops = {
  865. .get_settings = efx_ethtool_get_settings,
  866. .set_settings = efx_ethtool_set_settings,
  867. .get_drvinfo = efx_ethtool_get_drvinfo,
  868. .get_regs_len = efx_ethtool_get_regs_len,
  869. .get_regs = efx_ethtool_get_regs,
  870. .get_msglevel = efx_ethtool_get_msglevel,
  871. .set_msglevel = efx_ethtool_set_msglevel,
  872. .nway_reset = efx_ethtool_nway_reset,
  873. .get_link = ethtool_op_get_link,
  874. .get_coalesce = efx_ethtool_get_coalesce,
  875. .set_coalesce = efx_ethtool_set_coalesce,
  876. .get_ringparam = efx_ethtool_get_ringparam,
  877. .set_ringparam = efx_ethtool_set_ringparam,
  878. .get_pauseparam = efx_ethtool_get_pauseparam,
  879. .set_pauseparam = efx_ethtool_set_pauseparam,
  880. .get_sset_count = efx_ethtool_get_sset_count,
  881. .self_test = efx_ethtool_self_test,
  882. .get_strings = efx_ethtool_get_strings,
  883. .set_phys_id = efx_ethtool_phys_id,
  884. .get_ethtool_stats = efx_ethtool_get_stats,
  885. .get_wol = efx_ethtool_get_wol,
  886. .set_wol = efx_ethtool_set_wol,
  887. .reset = efx_ethtool_reset,
  888. .get_rxnfc = efx_ethtool_get_rxnfc,
  889. .set_rx_ntuple = efx_ethtool_set_rx_ntuple,
  890. .get_rxfh_indir = efx_ethtool_get_rxfh_indir,
  891. .set_rxfh_indir = efx_ethtool_set_rxfh_indir,
  892. };