ethtool.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2006-2008 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/mdio.h>
  13. #include <linux/rtnetlink.h>
  14. #include "net_driver.h"
  15. #include "workarounds.h"
  16. #include "selftest.h"
  17. #include "efx.h"
  18. #include "falcon.h"
  19. #include "spi.h"
  20. #include "mdio_10g.h"
  21. struct ethtool_string {
  22. char name[ETH_GSTRING_LEN];
  23. };
  24. struct efx_ethtool_stat {
  25. const char *name;
  26. enum {
  27. EFX_ETHTOOL_STAT_SOURCE_mac_stats,
  28. EFX_ETHTOOL_STAT_SOURCE_nic,
  29. EFX_ETHTOOL_STAT_SOURCE_channel
  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. static struct efx_ethtool_stat efx_ethtool_stats[] = {
  77. EFX_ETHTOOL_U64_MAC_STAT(tx_bytes),
  78. EFX_ETHTOOL_U64_MAC_STAT(tx_good_bytes),
  79. EFX_ETHTOOL_U64_MAC_STAT(tx_bad_bytes),
  80. EFX_ETHTOOL_ULONG_MAC_STAT(tx_packets),
  81. EFX_ETHTOOL_ULONG_MAC_STAT(tx_bad),
  82. EFX_ETHTOOL_ULONG_MAC_STAT(tx_pause),
  83. EFX_ETHTOOL_ULONG_MAC_STAT(tx_control),
  84. EFX_ETHTOOL_ULONG_MAC_STAT(tx_unicast),
  85. EFX_ETHTOOL_ULONG_MAC_STAT(tx_multicast),
  86. EFX_ETHTOOL_ULONG_MAC_STAT(tx_broadcast),
  87. EFX_ETHTOOL_ULONG_MAC_STAT(tx_lt64),
  88. EFX_ETHTOOL_ULONG_MAC_STAT(tx_64),
  89. EFX_ETHTOOL_ULONG_MAC_STAT(tx_65_to_127),
  90. EFX_ETHTOOL_ULONG_MAC_STAT(tx_128_to_255),
  91. EFX_ETHTOOL_ULONG_MAC_STAT(tx_256_to_511),
  92. EFX_ETHTOOL_ULONG_MAC_STAT(tx_512_to_1023),
  93. EFX_ETHTOOL_ULONG_MAC_STAT(tx_1024_to_15xx),
  94. EFX_ETHTOOL_ULONG_MAC_STAT(tx_15xx_to_jumbo),
  95. EFX_ETHTOOL_ULONG_MAC_STAT(tx_gtjumbo),
  96. EFX_ETHTOOL_ULONG_MAC_STAT(tx_collision),
  97. EFX_ETHTOOL_ULONG_MAC_STAT(tx_single_collision),
  98. EFX_ETHTOOL_ULONG_MAC_STAT(tx_multiple_collision),
  99. EFX_ETHTOOL_ULONG_MAC_STAT(tx_excessive_collision),
  100. EFX_ETHTOOL_ULONG_MAC_STAT(tx_deferred),
  101. EFX_ETHTOOL_ULONG_MAC_STAT(tx_late_collision),
  102. EFX_ETHTOOL_ULONG_MAC_STAT(tx_excessive_deferred),
  103. EFX_ETHTOOL_ULONG_MAC_STAT(tx_non_tcpudp),
  104. EFX_ETHTOOL_ULONG_MAC_STAT(tx_mac_src_error),
  105. EFX_ETHTOOL_ULONG_MAC_STAT(tx_ip_src_error),
  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_ULONG_MAC_STAT(rx_packets),
  110. EFX_ETHTOOL_ULONG_MAC_STAT(rx_good),
  111. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad),
  112. EFX_ETHTOOL_ULONG_MAC_STAT(rx_pause),
  113. EFX_ETHTOOL_ULONG_MAC_STAT(rx_control),
  114. EFX_ETHTOOL_ULONG_MAC_STAT(rx_unicast),
  115. EFX_ETHTOOL_ULONG_MAC_STAT(rx_multicast),
  116. EFX_ETHTOOL_ULONG_MAC_STAT(rx_broadcast),
  117. EFX_ETHTOOL_ULONG_MAC_STAT(rx_lt64),
  118. EFX_ETHTOOL_ULONG_MAC_STAT(rx_64),
  119. EFX_ETHTOOL_ULONG_MAC_STAT(rx_65_to_127),
  120. EFX_ETHTOOL_ULONG_MAC_STAT(rx_128_to_255),
  121. EFX_ETHTOOL_ULONG_MAC_STAT(rx_256_to_511),
  122. EFX_ETHTOOL_ULONG_MAC_STAT(rx_512_to_1023),
  123. EFX_ETHTOOL_ULONG_MAC_STAT(rx_1024_to_15xx),
  124. EFX_ETHTOOL_ULONG_MAC_STAT(rx_15xx_to_jumbo),
  125. EFX_ETHTOOL_ULONG_MAC_STAT(rx_gtjumbo),
  126. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_lt64),
  127. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_64_to_15xx),
  128. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_15xx_to_jumbo),
  129. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_gtjumbo),
  130. EFX_ETHTOOL_ULONG_MAC_STAT(rx_overflow),
  131. EFX_ETHTOOL_ULONG_MAC_STAT(rx_missed),
  132. EFX_ETHTOOL_ULONG_MAC_STAT(rx_false_carrier),
  133. EFX_ETHTOOL_ULONG_MAC_STAT(rx_symbol_error),
  134. EFX_ETHTOOL_ULONG_MAC_STAT(rx_align_error),
  135. EFX_ETHTOOL_ULONG_MAC_STAT(rx_length_error),
  136. EFX_ETHTOOL_ULONG_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_frm_trunc),
  143. };
  144. /* Number of ethtool statistics */
  145. #define EFX_ETHTOOL_NUM_STATS ARRAY_SIZE(efx_ethtool_stats)
  146. #define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB
  147. /**************************************************************************
  148. *
  149. * Ethtool operations
  150. *
  151. **************************************************************************
  152. */
  153. /* Identify device by flashing LEDs */
  154. static int efx_ethtool_phys_id(struct net_device *net_dev, u32 count)
  155. {
  156. struct efx_nic *efx = netdev_priv(net_dev);
  157. do {
  158. falcon_board(efx)->set_id_led(efx, EFX_LED_ON);
  159. schedule_timeout_interruptible(HZ / 2);
  160. falcon_board(efx)->set_id_led(efx, EFX_LED_OFF);
  161. schedule_timeout_interruptible(HZ / 2);
  162. } while (!signal_pending(current) && --count != 0);
  163. falcon_board(efx)->set_id_led(efx, EFX_LED_DEFAULT);
  164. return 0;
  165. }
  166. /* This must be called with rtnl_lock held. */
  167. int efx_ethtool_get_settings(struct net_device *net_dev,
  168. struct ethtool_cmd *ecmd)
  169. {
  170. struct efx_nic *efx = netdev_priv(net_dev);
  171. mutex_lock(&efx->mac_lock);
  172. efx->phy_op->get_settings(efx, ecmd);
  173. mutex_unlock(&efx->mac_lock);
  174. /* Falcon GMAC does not support 1000Mbps HD */
  175. ecmd->supported &= ~SUPPORTED_1000baseT_Half;
  176. return 0;
  177. }
  178. /* This must be called with rtnl_lock held. */
  179. int efx_ethtool_set_settings(struct net_device *net_dev,
  180. struct ethtool_cmd *ecmd)
  181. {
  182. struct efx_nic *efx = netdev_priv(net_dev);
  183. int rc;
  184. /* Falcon GMAC does not support 1000Mbps HD */
  185. if (ecmd->speed == SPEED_1000 && ecmd->duplex != DUPLEX_FULL) {
  186. EFX_LOG(efx, "rejecting unsupported 1000Mbps HD"
  187. " setting\n");
  188. return -EINVAL;
  189. }
  190. mutex_lock(&efx->mac_lock);
  191. rc = efx->phy_op->set_settings(efx, ecmd);
  192. mutex_unlock(&efx->mac_lock);
  193. if (!rc)
  194. efx_reconfigure_port(efx);
  195. return rc;
  196. }
  197. static void efx_ethtool_get_drvinfo(struct net_device *net_dev,
  198. struct ethtool_drvinfo *info)
  199. {
  200. struct efx_nic *efx = netdev_priv(net_dev);
  201. strlcpy(info->driver, EFX_DRIVER_NAME, sizeof(info->driver));
  202. strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version));
  203. strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
  204. }
  205. /**
  206. * efx_fill_test - fill in an individual self-test entry
  207. * @test_index: Index of the test
  208. * @strings: Ethtool strings, or %NULL
  209. * @data: Ethtool test results, or %NULL
  210. * @test: Pointer to test result (used only if data != %NULL)
  211. * @unit_format: Unit name format (e.g. "chan\%d")
  212. * @unit_id: Unit id (e.g. 0 for "chan0")
  213. * @test_format: Test name format (e.g. "loopback.\%s.tx.sent")
  214. * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
  215. *
  216. * Fill in an individual self-test entry.
  217. */
  218. static void efx_fill_test(unsigned int test_index,
  219. struct ethtool_string *strings, u64 *data,
  220. int *test, const char *unit_format, int unit_id,
  221. const char *test_format, const char *test_id)
  222. {
  223. struct ethtool_string unit_str, test_str;
  224. /* Fill data value, if applicable */
  225. if (data)
  226. data[test_index] = *test;
  227. /* Fill string, if applicable */
  228. if (strings) {
  229. if (strchr(unit_format, '%'))
  230. snprintf(unit_str.name, sizeof(unit_str.name),
  231. unit_format, unit_id);
  232. else
  233. strcpy(unit_str.name, unit_format);
  234. snprintf(test_str.name, sizeof(test_str.name),
  235. test_format, test_id);
  236. snprintf(strings[test_index].name,
  237. sizeof(strings[test_index].name),
  238. "%-6s %-24s", unit_str.name, test_str.name);
  239. }
  240. }
  241. #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
  242. #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
  243. #define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
  244. #define EFX_LOOPBACK_NAME(_mode, _counter) \
  245. "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode)
  246. /**
  247. * efx_fill_loopback_test - fill in a block of loopback self-test entries
  248. * @efx: Efx NIC
  249. * @lb_tests: Efx loopback self-test results structure
  250. * @mode: Loopback test mode
  251. * @test_index: Starting index of the test
  252. * @strings: Ethtool strings, or %NULL
  253. * @data: Ethtool test results, or %NULL
  254. */
  255. static int efx_fill_loopback_test(struct efx_nic *efx,
  256. struct efx_loopback_self_tests *lb_tests,
  257. enum efx_loopback_mode mode,
  258. unsigned int test_index,
  259. struct ethtool_string *strings, u64 *data)
  260. {
  261. struct efx_tx_queue *tx_queue;
  262. efx_for_each_tx_queue(tx_queue, efx) {
  263. efx_fill_test(test_index++, strings, data,
  264. &lb_tests->tx_sent[tx_queue->queue],
  265. EFX_TX_QUEUE_NAME(tx_queue),
  266. EFX_LOOPBACK_NAME(mode, "tx_sent"));
  267. efx_fill_test(test_index++, strings, data,
  268. &lb_tests->tx_done[tx_queue->queue],
  269. EFX_TX_QUEUE_NAME(tx_queue),
  270. EFX_LOOPBACK_NAME(mode, "tx_done"));
  271. }
  272. efx_fill_test(test_index++, strings, data,
  273. &lb_tests->rx_good,
  274. "rx", 0,
  275. EFX_LOOPBACK_NAME(mode, "rx_good"));
  276. efx_fill_test(test_index++, strings, data,
  277. &lb_tests->rx_bad,
  278. "rx", 0,
  279. EFX_LOOPBACK_NAME(mode, "rx_bad"));
  280. return test_index;
  281. }
  282. /**
  283. * efx_ethtool_fill_self_tests - get self-test details
  284. * @efx: Efx NIC
  285. * @tests: Efx self-test results structure, or %NULL
  286. * @strings: Ethtool strings, or %NULL
  287. * @data: Ethtool test results, or %NULL
  288. */
  289. static int efx_ethtool_fill_self_tests(struct efx_nic *efx,
  290. struct efx_self_tests *tests,
  291. struct ethtool_string *strings,
  292. u64 *data)
  293. {
  294. struct efx_channel *channel;
  295. unsigned int n = 0, i;
  296. enum efx_loopback_mode mode;
  297. efx_fill_test(n++, strings, data, &tests->mdio,
  298. "core", 0, "mdio", NULL);
  299. efx_fill_test(n++, strings, data, &tests->nvram,
  300. "core", 0, "nvram", NULL);
  301. efx_fill_test(n++, strings, data, &tests->interrupt,
  302. "core", 0, "interrupt", NULL);
  303. /* Event queues */
  304. efx_for_each_channel(channel, efx) {
  305. efx_fill_test(n++, strings, data,
  306. &tests->eventq_dma[channel->channel],
  307. EFX_CHANNEL_NAME(channel),
  308. "eventq.dma", NULL);
  309. efx_fill_test(n++, strings, data,
  310. &tests->eventq_int[channel->channel],
  311. EFX_CHANNEL_NAME(channel),
  312. "eventq.int", NULL);
  313. efx_fill_test(n++, strings, data,
  314. &tests->eventq_poll[channel->channel],
  315. EFX_CHANNEL_NAME(channel),
  316. "eventq.poll", NULL);
  317. }
  318. efx_fill_test(n++, strings, data, &tests->registers,
  319. "core", 0, "registers", NULL);
  320. for (i = 0; i < efx->phy_op->num_tests; i++)
  321. efx_fill_test(n++, strings, data, &tests->phy[i],
  322. "phy", 0, efx->phy_op->test_names[i], NULL);
  323. /* Loopback tests */
  324. for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
  325. if (!(efx->loopback_modes & (1 << mode)))
  326. continue;
  327. n = efx_fill_loopback_test(efx,
  328. &tests->loopback[mode], mode, n,
  329. strings, data);
  330. }
  331. return n;
  332. }
  333. static int efx_ethtool_get_sset_count(struct net_device *net_dev,
  334. int string_set)
  335. {
  336. switch (string_set) {
  337. case ETH_SS_STATS:
  338. return EFX_ETHTOOL_NUM_STATS;
  339. case ETH_SS_TEST:
  340. return efx_ethtool_fill_self_tests(netdev_priv(net_dev),
  341. NULL, NULL, NULL);
  342. default:
  343. return -EINVAL;
  344. }
  345. }
  346. static void efx_ethtool_get_strings(struct net_device *net_dev,
  347. u32 string_set, u8 *strings)
  348. {
  349. struct efx_nic *efx = netdev_priv(net_dev);
  350. struct ethtool_string *ethtool_strings =
  351. (struct ethtool_string *)strings;
  352. int i;
  353. switch (string_set) {
  354. case ETH_SS_STATS:
  355. for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++)
  356. strncpy(ethtool_strings[i].name,
  357. efx_ethtool_stats[i].name,
  358. sizeof(ethtool_strings[i].name));
  359. break;
  360. case ETH_SS_TEST:
  361. efx_ethtool_fill_self_tests(efx, NULL,
  362. ethtool_strings, NULL);
  363. break;
  364. default:
  365. /* No other string sets */
  366. break;
  367. }
  368. }
  369. static void efx_ethtool_get_stats(struct net_device *net_dev,
  370. struct ethtool_stats *stats,
  371. u64 *data)
  372. {
  373. struct efx_nic *efx = netdev_priv(net_dev);
  374. struct efx_mac_stats *mac_stats = &efx->mac_stats;
  375. struct efx_ethtool_stat *stat;
  376. struct efx_channel *channel;
  377. int i;
  378. EFX_BUG_ON_PARANOID(stats->n_stats != EFX_ETHTOOL_NUM_STATS);
  379. /* Update MAC and NIC statistics */
  380. dev_get_stats(net_dev);
  381. /* Fill detailed statistics buffer */
  382. for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++) {
  383. stat = &efx_ethtool_stats[i];
  384. switch (stat->source) {
  385. case EFX_ETHTOOL_STAT_SOURCE_mac_stats:
  386. data[i] = stat->get_stat((void *)mac_stats +
  387. stat->offset);
  388. break;
  389. case EFX_ETHTOOL_STAT_SOURCE_nic:
  390. data[i] = stat->get_stat((void *)efx + stat->offset);
  391. break;
  392. case EFX_ETHTOOL_STAT_SOURCE_channel:
  393. data[i] = 0;
  394. efx_for_each_channel(channel, efx)
  395. data[i] += stat->get_stat((void *)channel +
  396. stat->offset);
  397. break;
  398. }
  399. }
  400. }
  401. static int efx_ethtool_set_rx_csum(struct net_device *net_dev, u32 enable)
  402. {
  403. struct efx_nic *efx = netdev_priv(net_dev);
  404. /* No way to stop the hardware doing the checks; we just
  405. * ignore the result.
  406. */
  407. efx->rx_checksum_enabled = !!enable;
  408. return 0;
  409. }
  410. static u32 efx_ethtool_get_rx_csum(struct net_device *net_dev)
  411. {
  412. struct efx_nic *efx = netdev_priv(net_dev);
  413. return efx->rx_checksum_enabled;
  414. }
  415. static void efx_ethtool_self_test(struct net_device *net_dev,
  416. struct ethtool_test *test, u64 *data)
  417. {
  418. struct efx_nic *efx = netdev_priv(net_dev);
  419. struct efx_self_tests efx_tests;
  420. int already_up;
  421. int rc;
  422. ASSERT_RTNL();
  423. if (efx->state != STATE_RUNNING) {
  424. rc = -EIO;
  425. goto fail1;
  426. }
  427. /* We need rx buffers and interrupts. */
  428. already_up = (efx->net_dev->flags & IFF_UP);
  429. if (!already_up) {
  430. rc = dev_open(efx->net_dev);
  431. if (rc) {
  432. EFX_ERR(efx, "failed opening device.\n");
  433. goto fail2;
  434. }
  435. }
  436. memset(&efx_tests, 0, sizeof(efx_tests));
  437. rc = efx_selftest(efx, &efx_tests, test->flags);
  438. if (!already_up)
  439. dev_close(efx->net_dev);
  440. EFX_LOG(efx, "%s %sline self-tests\n",
  441. rc == 0 ? "passed" : "failed",
  442. (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
  443. fail2:
  444. fail1:
  445. /* Fill ethtool results structures */
  446. efx_ethtool_fill_self_tests(efx, &efx_tests, NULL, data);
  447. if (rc)
  448. test->flags |= ETH_TEST_FL_FAILED;
  449. }
  450. /* Restart autonegotiation */
  451. static int efx_ethtool_nway_reset(struct net_device *net_dev)
  452. {
  453. struct efx_nic *efx = netdev_priv(net_dev);
  454. return mdio45_nway_restart(&efx->mdio);
  455. }
  456. static u32 efx_ethtool_get_link(struct net_device *net_dev)
  457. {
  458. struct efx_nic *efx = netdev_priv(net_dev);
  459. return efx->link_state.up;
  460. }
  461. static int efx_ethtool_get_eeprom_len(struct net_device *net_dev)
  462. {
  463. struct efx_nic *efx = netdev_priv(net_dev);
  464. struct efx_spi_device *spi = efx->spi_eeprom;
  465. if (!spi)
  466. return 0;
  467. return min(spi->size, EFX_EEPROM_BOOTCONFIG_END) -
  468. min(spi->size, EFX_EEPROM_BOOTCONFIG_START);
  469. }
  470. static int efx_ethtool_get_eeprom(struct net_device *net_dev,
  471. struct ethtool_eeprom *eeprom, u8 *buf)
  472. {
  473. struct efx_nic *efx = netdev_priv(net_dev);
  474. struct efx_spi_device *spi = efx->spi_eeprom;
  475. size_t len;
  476. int rc;
  477. rc = mutex_lock_interruptible(&efx->spi_lock);
  478. if (rc)
  479. return rc;
  480. rc = falcon_spi_read(spi, eeprom->offset + EFX_EEPROM_BOOTCONFIG_START,
  481. eeprom->len, &len, buf);
  482. mutex_unlock(&efx->spi_lock);
  483. eeprom->magic = EFX_ETHTOOL_EEPROM_MAGIC;
  484. eeprom->len = len;
  485. return rc;
  486. }
  487. static int efx_ethtool_set_eeprom(struct net_device *net_dev,
  488. struct ethtool_eeprom *eeprom, u8 *buf)
  489. {
  490. struct efx_nic *efx = netdev_priv(net_dev);
  491. struct efx_spi_device *spi = efx->spi_eeprom;
  492. size_t len;
  493. int rc;
  494. if (eeprom->magic != EFX_ETHTOOL_EEPROM_MAGIC)
  495. return -EINVAL;
  496. rc = mutex_lock_interruptible(&efx->spi_lock);
  497. if (rc)
  498. return rc;
  499. rc = falcon_spi_write(spi, eeprom->offset + EFX_EEPROM_BOOTCONFIG_START,
  500. eeprom->len, &len, buf);
  501. mutex_unlock(&efx->spi_lock);
  502. eeprom->len = len;
  503. return rc;
  504. }
  505. static int efx_ethtool_get_coalesce(struct net_device *net_dev,
  506. struct ethtool_coalesce *coalesce)
  507. {
  508. struct efx_nic *efx = netdev_priv(net_dev);
  509. struct efx_tx_queue *tx_queue;
  510. struct efx_channel *channel;
  511. memset(coalesce, 0, sizeof(*coalesce));
  512. /* Find lowest IRQ moderation across all used TX queues */
  513. coalesce->tx_coalesce_usecs_irq = ~((u32) 0);
  514. efx_for_each_tx_queue(tx_queue, efx) {
  515. channel = tx_queue->channel;
  516. if (channel->irq_moderation < coalesce->tx_coalesce_usecs_irq) {
  517. if (channel->used_flags != EFX_USED_BY_RX_TX)
  518. coalesce->tx_coalesce_usecs_irq =
  519. channel->irq_moderation;
  520. else
  521. coalesce->tx_coalesce_usecs_irq = 0;
  522. }
  523. }
  524. coalesce->use_adaptive_rx_coalesce = efx->irq_rx_adaptive;
  525. coalesce->rx_coalesce_usecs_irq = efx->irq_rx_moderation;
  526. coalesce->tx_coalesce_usecs_irq *= FALCON_IRQ_MOD_RESOLUTION;
  527. coalesce->rx_coalesce_usecs_irq *= FALCON_IRQ_MOD_RESOLUTION;
  528. return 0;
  529. }
  530. /* Set coalescing parameters
  531. * The difficulties occur for shared channels
  532. */
  533. static int efx_ethtool_set_coalesce(struct net_device *net_dev,
  534. struct ethtool_coalesce *coalesce)
  535. {
  536. struct efx_nic *efx = netdev_priv(net_dev);
  537. struct efx_channel *channel;
  538. struct efx_tx_queue *tx_queue;
  539. unsigned tx_usecs, rx_usecs, adaptive;
  540. if (coalesce->use_adaptive_tx_coalesce)
  541. return -EOPNOTSUPP;
  542. if (coalesce->rx_coalesce_usecs || coalesce->tx_coalesce_usecs) {
  543. EFX_ERR(efx, "invalid coalescing setting. "
  544. "Only rx/tx_coalesce_usecs_irq are supported\n");
  545. return -EOPNOTSUPP;
  546. }
  547. rx_usecs = coalesce->rx_coalesce_usecs_irq;
  548. tx_usecs = coalesce->tx_coalesce_usecs_irq;
  549. adaptive = coalesce->use_adaptive_rx_coalesce;
  550. /* If the channel is shared only allow RX parameters to be set */
  551. efx_for_each_tx_queue(tx_queue, efx) {
  552. if ((tx_queue->channel->used_flags == EFX_USED_BY_RX_TX) &&
  553. tx_usecs) {
  554. EFX_ERR(efx, "Channel is shared. "
  555. "Only RX coalescing may be set\n");
  556. return -EOPNOTSUPP;
  557. }
  558. }
  559. efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive);
  560. efx_for_each_channel(channel, efx)
  561. falcon_set_int_moderation(channel);
  562. return 0;
  563. }
  564. static int efx_ethtool_set_pauseparam(struct net_device *net_dev,
  565. struct ethtool_pauseparam *pause)
  566. {
  567. struct efx_nic *efx = netdev_priv(net_dev);
  568. enum efx_fc_type wanted_fc;
  569. bool reset;
  570. wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
  571. (pause->tx_pause ? EFX_FC_TX : 0) |
  572. (pause->autoneg ? EFX_FC_AUTO : 0));
  573. if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
  574. EFX_LOG(efx, "Flow control unsupported: tx ON rx OFF\n");
  575. return -EINVAL;
  576. }
  577. if (!(efx->phy_op->mmds & MDIO_DEVS_AN) &&
  578. (wanted_fc & EFX_FC_AUTO)) {
  579. EFX_LOG(efx, "PHY does not support flow control "
  580. "autonegotiation\n");
  581. return -EINVAL;
  582. }
  583. /* TX flow control may automatically turn itself off if the
  584. * link partner (intermittently) stops responding to pause
  585. * frames. There isn't any indication that this has happened,
  586. * so the best we do is leave it up to the user to spot this
  587. * and fix it be cycling transmit flow control on this end. */
  588. reset = (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX);
  589. if (EFX_WORKAROUND_11482(efx) && reset) {
  590. if (falcon_rev(efx) >= FALCON_REV_B0) {
  591. /* Recover by resetting the EM block */
  592. if (efx->link_state.up)
  593. falcon_drain_tx_fifo(efx);
  594. } else {
  595. /* Schedule a reset to recover */
  596. efx_schedule_reset(efx, RESET_TYPE_INVISIBLE);
  597. }
  598. }
  599. /* Try to push the pause parameters */
  600. mutex_lock(&efx->mac_lock);
  601. efx->wanted_fc = wanted_fc;
  602. if (efx->phy_op->mmds & MDIO_DEVS_AN)
  603. mdio45_ethtool_spauseparam_an(&efx->mdio, pause);
  604. __efx_reconfigure_port(efx);
  605. mutex_unlock(&efx->mac_lock);
  606. return 0;
  607. }
  608. static void efx_ethtool_get_pauseparam(struct net_device *net_dev,
  609. struct ethtool_pauseparam *pause)
  610. {
  611. struct efx_nic *efx = netdev_priv(net_dev);
  612. pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX);
  613. pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX);
  614. pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO);
  615. }
  616. const struct ethtool_ops efx_ethtool_ops = {
  617. .get_settings = efx_ethtool_get_settings,
  618. .set_settings = efx_ethtool_set_settings,
  619. .get_drvinfo = efx_ethtool_get_drvinfo,
  620. .nway_reset = efx_ethtool_nway_reset,
  621. .get_link = efx_ethtool_get_link,
  622. .get_eeprom_len = efx_ethtool_get_eeprom_len,
  623. .get_eeprom = efx_ethtool_get_eeprom,
  624. .set_eeprom = efx_ethtool_set_eeprom,
  625. .get_coalesce = efx_ethtool_get_coalesce,
  626. .set_coalesce = efx_ethtool_set_coalesce,
  627. .get_pauseparam = efx_ethtool_get_pauseparam,
  628. .set_pauseparam = efx_ethtool_set_pauseparam,
  629. .get_rx_csum = efx_ethtool_get_rx_csum,
  630. .set_rx_csum = efx_ethtool_set_rx_csum,
  631. .get_tx_csum = ethtool_op_get_tx_csum,
  632. .set_tx_csum = ethtool_op_set_tx_csum,
  633. .get_sg = ethtool_op_get_sg,
  634. .set_sg = ethtool_op_set_sg,
  635. .get_tso = ethtool_op_get_tso,
  636. .set_tso = ethtool_op_set_tso,
  637. .get_flags = ethtool_op_get_flags,
  638. .set_flags = ethtool_op_set_flags,
  639. .get_sset_count = efx_ethtool_get_sset_count,
  640. .self_test = efx_ethtool_self_test,
  641. .get_strings = efx_ethtool_get_strings,
  642. .phys_id = efx_ethtool_phys_id,
  643. .get_ethtool_stats = efx_ethtool_get_stats,
  644. };