ethtool.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  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/rtnetlink.h>
  13. #include "net_driver.h"
  14. #include "selftest.h"
  15. #include "efx.h"
  16. #include "ethtool.h"
  17. #include "falcon.h"
  18. #include "gmii.h"
  19. #include "mac.h"
  20. const char *efx_loopback_mode_names[] = {
  21. [LOOPBACK_NONE] = "NONE",
  22. [LOOPBACK_MAC] = "MAC",
  23. [LOOPBACK_XGMII] = "XGMII",
  24. [LOOPBACK_XGXS] = "XGXS",
  25. [LOOPBACK_XAUI] = "XAUI",
  26. [LOOPBACK_PHY] = "PHY",
  27. [LOOPBACK_PHYXS] = "PHY(XS)",
  28. [LOOPBACK_PCS] = "PHY(PCS)",
  29. [LOOPBACK_PMAPMD] = "PHY(PMAPMD)",
  30. [LOOPBACK_NETWORK] = "NETWORK",
  31. };
  32. struct ethtool_string {
  33. char name[ETH_GSTRING_LEN];
  34. };
  35. struct efx_ethtool_stat {
  36. const char *name;
  37. enum {
  38. EFX_ETHTOOL_STAT_SOURCE_mac_stats,
  39. EFX_ETHTOOL_STAT_SOURCE_nic,
  40. EFX_ETHTOOL_STAT_SOURCE_channel
  41. } source;
  42. unsigned offset;
  43. u64(*get_stat) (void *field); /* Reader function */
  44. };
  45. /* Initialiser for a struct #efx_ethtool_stat with type-checking */
  46. #define EFX_ETHTOOL_STAT(stat_name, source_name, field, field_type, \
  47. get_stat_function) { \
  48. .name = #stat_name, \
  49. .source = EFX_ETHTOOL_STAT_SOURCE_##source_name, \
  50. .offset = ((((field_type *) 0) == \
  51. &((struct efx_##source_name *)0)->field) ? \
  52. offsetof(struct efx_##source_name, field) : \
  53. offsetof(struct efx_##source_name, field)), \
  54. .get_stat = get_stat_function, \
  55. }
  56. static u64 efx_get_uint_stat(void *field)
  57. {
  58. return *(unsigned int *)field;
  59. }
  60. static u64 efx_get_ulong_stat(void *field)
  61. {
  62. return *(unsigned long *)field;
  63. }
  64. static u64 efx_get_u64_stat(void *field)
  65. {
  66. return *(u64 *) field;
  67. }
  68. static u64 efx_get_atomic_stat(void *field)
  69. {
  70. return atomic_read((atomic_t *) field);
  71. }
  72. #define EFX_ETHTOOL_ULONG_MAC_STAT(field) \
  73. EFX_ETHTOOL_STAT(field, mac_stats, field, \
  74. unsigned long, efx_get_ulong_stat)
  75. #define EFX_ETHTOOL_U64_MAC_STAT(field) \
  76. EFX_ETHTOOL_STAT(field, mac_stats, field, \
  77. u64, efx_get_u64_stat)
  78. #define EFX_ETHTOOL_UINT_NIC_STAT(name) \
  79. EFX_ETHTOOL_STAT(name, nic, n_##name, \
  80. unsigned int, efx_get_uint_stat)
  81. #define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field) \
  82. EFX_ETHTOOL_STAT(field, nic, field, \
  83. atomic_t, efx_get_atomic_stat)
  84. #define EFX_ETHTOOL_UINT_CHANNEL_STAT(field) \
  85. EFX_ETHTOOL_STAT(field, channel, n_##field, \
  86. unsigned int, efx_get_uint_stat)
  87. static struct efx_ethtool_stat efx_ethtool_stats[] = {
  88. EFX_ETHTOOL_U64_MAC_STAT(tx_bytes),
  89. EFX_ETHTOOL_U64_MAC_STAT(tx_good_bytes),
  90. EFX_ETHTOOL_U64_MAC_STAT(tx_bad_bytes),
  91. EFX_ETHTOOL_ULONG_MAC_STAT(tx_packets),
  92. EFX_ETHTOOL_ULONG_MAC_STAT(tx_bad),
  93. EFX_ETHTOOL_ULONG_MAC_STAT(tx_pause),
  94. EFX_ETHTOOL_ULONG_MAC_STAT(tx_control),
  95. EFX_ETHTOOL_ULONG_MAC_STAT(tx_unicast),
  96. EFX_ETHTOOL_ULONG_MAC_STAT(tx_multicast),
  97. EFX_ETHTOOL_ULONG_MAC_STAT(tx_broadcast),
  98. EFX_ETHTOOL_ULONG_MAC_STAT(tx_lt64),
  99. EFX_ETHTOOL_ULONG_MAC_STAT(tx_64),
  100. EFX_ETHTOOL_ULONG_MAC_STAT(tx_65_to_127),
  101. EFX_ETHTOOL_ULONG_MAC_STAT(tx_128_to_255),
  102. EFX_ETHTOOL_ULONG_MAC_STAT(tx_256_to_511),
  103. EFX_ETHTOOL_ULONG_MAC_STAT(tx_512_to_1023),
  104. EFX_ETHTOOL_ULONG_MAC_STAT(tx_1024_to_15xx),
  105. EFX_ETHTOOL_ULONG_MAC_STAT(tx_15xx_to_jumbo),
  106. EFX_ETHTOOL_ULONG_MAC_STAT(tx_gtjumbo),
  107. EFX_ETHTOOL_ULONG_MAC_STAT(tx_collision),
  108. EFX_ETHTOOL_ULONG_MAC_STAT(tx_single_collision),
  109. EFX_ETHTOOL_ULONG_MAC_STAT(tx_multiple_collision),
  110. EFX_ETHTOOL_ULONG_MAC_STAT(tx_excessive_collision),
  111. EFX_ETHTOOL_ULONG_MAC_STAT(tx_deferred),
  112. EFX_ETHTOOL_ULONG_MAC_STAT(tx_late_collision),
  113. EFX_ETHTOOL_ULONG_MAC_STAT(tx_excessive_deferred),
  114. EFX_ETHTOOL_ULONG_MAC_STAT(tx_non_tcpudp),
  115. EFX_ETHTOOL_ULONG_MAC_STAT(tx_mac_src_error),
  116. EFX_ETHTOOL_ULONG_MAC_STAT(tx_ip_src_error),
  117. EFX_ETHTOOL_U64_MAC_STAT(rx_bytes),
  118. EFX_ETHTOOL_U64_MAC_STAT(rx_good_bytes),
  119. EFX_ETHTOOL_U64_MAC_STAT(rx_bad_bytes),
  120. EFX_ETHTOOL_ULONG_MAC_STAT(rx_packets),
  121. EFX_ETHTOOL_ULONG_MAC_STAT(rx_good),
  122. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad),
  123. EFX_ETHTOOL_ULONG_MAC_STAT(rx_pause),
  124. EFX_ETHTOOL_ULONG_MAC_STAT(rx_control),
  125. EFX_ETHTOOL_ULONG_MAC_STAT(rx_unicast),
  126. EFX_ETHTOOL_ULONG_MAC_STAT(rx_multicast),
  127. EFX_ETHTOOL_ULONG_MAC_STAT(rx_broadcast),
  128. EFX_ETHTOOL_ULONG_MAC_STAT(rx_lt64),
  129. EFX_ETHTOOL_ULONG_MAC_STAT(rx_64),
  130. EFX_ETHTOOL_ULONG_MAC_STAT(rx_65_to_127),
  131. EFX_ETHTOOL_ULONG_MAC_STAT(rx_128_to_255),
  132. EFX_ETHTOOL_ULONG_MAC_STAT(rx_256_to_511),
  133. EFX_ETHTOOL_ULONG_MAC_STAT(rx_512_to_1023),
  134. EFX_ETHTOOL_ULONG_MAC_STAT(rx_1024_to_15xx),
  135. EFX_ETHTOOL_ULONG_MAC_STAT(rx_15xx_to_jumbo),
  136. EFX_ETHTOOL_ULONG_MAC_STAT(rx_gtjumbo),
  137. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_lt64),
  138. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_64_to_15xx),
  139. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_15xx_to_jumbo),
  140. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_gtjumbo),
  141. EFX_ETHTOOL_ULONG_MAC_STAT(rx_overflow),
  142. EFX_ETHTOOL_ULONG_MAC_STAT(rx_missed),
  143. EFX_ETHTOOL_ULONG_MAC_STAT(rx_false_carrier),
  144. EFX_ETHTOOL_ULONG_MAC_STAT(rx_symbol_error),
  145. EFX_ETHTOOL_ULONG_MAC_STAT(rx_align_error),
  146. EFX_ETHTOOL_ULONG_MAC_STAT(rx_length_error),
  147. EFX_ETHTOOL_ULONG_MAC_STAT(rx_internal_error),
  148. EFX_ETHTOOL_UINT_NIC_STAT(rx_nodesc_drop_cnt),
  149. EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset),
  150. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc),
  151. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),
  152. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err),
  153. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
  154. };
  155. /* Number of ethtool statistics */
  156. #define EFX_ETHTOOL_NUM_STATS ARRAY_SIZE(efx_ethtool_stats)
  157. /**************************************************************************
  158. *
  159. * Ethtool operations
  160. *
  161. **************************************************************************
  162. */
  163. /* Identify device by flashing LEDs */
  164. static int efx_ethtool_phys_id(struct net_device *net_dev, u32 seconds)
  165. {
  166. struct efx_nic *efx = netdev_priv(net_dev);
  167. efx->board_info.blink(efx, 1);
  168. schedule_timeout_interruptible(seconds * HZ);
  169. efx->board_info.blink(efx, 0);
  170. return 0;
  171. }
  172. /* This must be called with rtnl_lock held. */
  173. int efx_ethtool_get_settings(struct net_device *net_dev,
  174. struct ethtool_cmd *ecmd)
  175. {
  176. struct efx_nic *efx = netdev_priv(net_dev);
  177. int rc;
  178. mutex_lock(&efx->mac_lock);
  179. rc = falcon_xmac_get_settings(efx, ecmd);
  180. mutex_unlock(&efx->mac_lock);
  181. return rc;
  182. }
  183. /* This must be called with rtnl_lock held. */
  184. int efx_ethtool_set_settings(struct net_device *net_dev,
  185. struct ethtool_cmd *ecmd)
  186. {
  187. struct efx_nic *efx = netdev_priv(net_dev);
  188. int rc;
  189. mutex_lock(&efx->mac_lock);
  190. rc = falcon_xmac_set_settings(efx, ecmd);
  191. mutex_unlock(&efx->mac_lock);
  192. if (!rc)
  193. efx_reconfigure_port(efx);
  194. return rc;
  195. }
  196. static void efx_ethtool_get_drvinfo(struct net_device *net_dev,
  197. struct ethtool_drvinfo *info)
  198. {
  199. struct efx_nic *efx = netdev_priv(net_dev);
  200. strlcpy(info->driver, EFX_DRIVER_NAME, sizeof(info->driver));
  201. strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version));
  202. strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
  203. }
  204. /**
  205. * efx_fill_test - fill in an individual self-test entry
  206. * @test_index: Index of the test
  207. * @strings: Ethtool strings, or %NULL
  208. * @data: Ethtool test results, or %NULL
  209. * @test: Pointer to test result (used only if data != %NULL)
  210. * @unit_format: Unit name format (e.g. "channel\%d")
  211. * @unit_id: Unit id (e.g. 0 for "channel0")
  212. * @test_format: Test name format (e.g. "loopback.\%s.tx.sent")
  213. * @test_id: Test id (e.g. "PHY" for "loopback.PHY.tx_sent")
  214. *
  215. * Fill in an individual self-test entry.
  216. */
  217. static void efx_fill_test(unsigned int test_index,
  218. struct ethtool_string *strings, u64 *data,
  219. int *test, const char *unit_format, int unit_id,
  220. const char *test_format, const char *test_id)
  221. {
  222. struct ethtool_string unit_str, test_str;
  223. /* Fill data value, if applicable */
  224. if (data)
  225. data[test_index] = *test;
  226. /* Fill string, if applicable */
  227. if (strings) {
  228. snprintf(unit_str.name, sizeof(unit_str.name),
  229. unit_format, unit_id);
  230. snprintf(test_str.name, sizeof(test_str.name),
  231. test_format, test_id);
  232. snprintf(strings[test_index].name,
  233. sizeof(strings[test_index].name),
  234. "%-9s%-17s", unit_str.name, test_str.name);
  235. }
  236. }
  237. #define EFX_PORT_NAME "port%d", 0
  238. #define EFX_CHANNEL_NAME(_channel) "channel%d", _channel->channel
  239. #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
  240. #define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
  241. #define EFX_LOOPBACK_NAME(_mode, _counter) \
  242. "loopback.%s." _counter, LOOPBACK_MODE_NAME(mode)
  243. /**
  244. * efx_fill_loopback_test - fill in a block of loopback self-test entries
  245. * @efx: Efx NIC
  246. * @lb_tests: Efx loopback self-test results structure
  247. * @mode: Loopback test mode
  248. * @test_index: Starting index of the test
  249. * @strings: Ethtool strings, or %NULL
  250. * @data: Ethtool test results, or %NULL
  251. */
  252. static int efx_fill_loopback_test(struct efx_nic *efx,
  253. struct efx_loopback_self_tests *lb_tests,
  254. enum efx_loopback_mode mode,
  255. unsigned int test_index,
  256. struct ethtool_string *strings, u64 *data)
  257. {
  258. struct efx_tx_queue *tx_queue;
  259. efx_for_each_tx_queue(tx_queue, efx) {
  260. efx_fill_test(test_index++, strings, data,
  261. &lb_tests->tx_sent[tx_queue->queue],
  262. EFX_TX_QUEUE_NAME(tx_queue),
  263. EFX_LOOPBACK_NAME(mode, "tx_sent"));
  264. efx_fill_test(test_index++, strings, data,
  265. &lb_tests->tx_done[tx_queue->queue],
  266. EFX_TX_QUEUE_NAME(tx_queue),
  267. EFX_LOOPBACK_NAME(mode, "tx_done"));
  268. }
  269. efx_fill_test(test_index++, strings, data,
  270. &lb_tests->rx_good,
  271. EFX_PORT_NAME,
  272. EFX_LOOPBACK_NAME(mode, "rx_good"));
  273. efx_fill_test(test_index++, strings, data,
  274. &lb_tests->rx_bad,
  275. EFX_PORT_NAME,
  276. EFX_LOOPBACK_NAME(mode, "rx_bad"));
  277. return test_index;
  278. }
  279. /**
  280. * efx_ethtool_fill_self_tests - get self-test details
  281. * @efx: Efx NIC
  282. * @tests: Efx self-test results structure, or %NULL
  283. * @strings: Ethtool strings, or %NULL
  284. * @data: Ethtool test results, or %NULL
  285. */
  286. static int efx_ethtool_fill_self_tests(struct efx_nic *efx,
  287. struct efx_self_tests *tests,
  288. struct ethtool_string *strings,
  289. u64 *data)
  290. {
  291. struct efx_channel *channel;
  292. unsigned int n = 0;
  293. enum efx_loopback_mode mode;
  294. /* Interrupt */
  295. efx_fill_test(n++, strings, data, &tests->interrupt,
  296. "core", 0, "interrupt", NULL);
  297. /* Event queues */
  298. efx_for_each_channel(channel, efx) {
  299. efx_fill_test(n++, strings, data,
  300. &tests->eventq_dma[channel->channel],
  301. EFX_CHANNEL_NAME(channel),
  302. "eventq.dma", NULL);
  303. efx_fill_test(n++, strings, data,
  304. &tests->eventq_int[channel->channel],
  305. EFX_CHANNEL_NAME(channel),
  306. "eventq.int", NULL);
  307. efx_fill_test(n++, strings, data,
  308. &tests->eventq_poll[channel->channel],
  309. EFX_CHANNEL_NAME(channel),
  310. "eventq.poll", NULL);
  311. }
  312. /* PHY presence */
  313. efx_fill_test(n++, strings, data, &tests->phy_ok,
  314. EFX_PORT_NAME, "phy_ok", NULL);
  315. /* Loopback tests */
  316. efx_fill_test(n++, strings, data, &tests->loopback_speed,
  317. EFX_PORT_NAME, "loopback.speed", NULL);
  318. efx_fill_test(n++, strings, data, &tests->loopback_full_duplex,
  319. EFX_PORT_NAME, "loopback.full_duplex", NULL);
  320. for (mode = LOOPBACK_NONE; mode < LOOPBACK_TEST_MAX; mode++) {
  321. if (!(efx->loopback_modes & (1 << mode)))
  322. continue;
  323. n = efx_fill_loopback_test(efx,
  324. &tests->loopback[mode], mode, n,
  325. strings, data);
  326. }
  327. return n;
  328. }
  329. static int efx_ethtool_get_stats_count(struct net_device *net_dev)
  330. {
  331. return EFX_ETHTOOL_NUM_STATS;
  332. }
  333. static int efx_ethtool_self_test_count(struct net_device *net_dev)
  334. {
  335. struct efx_nic *efx = netdev_priv(net_dev);
  336. return efx_ethtool_fill_self_tests(efx, NULL, NULL, NULL);
  337. }
  338. static void efx_ethtool_get_strings(struct net_device *net_dev,
  339. u32 string_set, u8 *strings)
  340. {
  341. struct efx_nic *efx = netdev_priv(net_dev);
  342. struct ethtool_string *ethtool_strings =
  343. (struct ethtool_string *)strings;
  344. int i;
  345. switch (string_set) {
  346. case ETH_SS_STATS:
  347. for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++)
  348. strncpy(ethtool_strings[i].name,
  349. efx_ethtool_stats[i].name,
  350. sizeof(ethtool_strings[i].name));
  351. break;
  352. case ETH_SS_TEST:
  353. efx_ethtool_fill_self_tests(efx, NULL,
  354. ethtool_strings, NULL);
  355. break;
  356. default:
  357. /* No other string sets */
  358. break;
  359. }
  360. }
  361. static void efx_ethtool_get_stats(struct net_device *net_dev,
  362. struct ethtool_stats *stats,
  363. u64 *data)
  364. {
  365. struct efx_nic *efx = netdev_priv(net_dev);
  366. struct efx_mac_stats *mac_stats = &efx->mac_stats;
  367. struct efx_ethtool_stat *stat;
  368. struct efx_channel *channel;
  369. int i;
  370. EFX_BUG_ON_PARANOID(stats->n_stats != EFX_ETHTOOL_NUM_STATS);
  371. /* Update MAC and NIC statistics */
  372. net_dev->get_stats(net_dev);
  373. /* Fill detailed statistics buffer */
  374. for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++) {
  375. stat = &efx_ethtool_stats[i];
  376. switch (stat->source) {
  377. case EFX_ETHTOOL_STAT_SOURCE_mac_stats:
  378. data[i] = stat->get_stat((void *)mac_stats +
  379. stat->offset);
  380. break;
  381. case EFX_ETHTOOL_STAT_SOURCE_nic:
  382. data[i] = stat->get_stat((void *)efx + stat->offset);
  383. break;
  384. case EFX_ETHTOOL_STAT_SOURCE_channel:
  385. data[i] = 0;
  386. efx_for_each_channel(channel, efx)
  387. data[i] += stat->get_stat((void *)channel +
  388. stat->offset);
  389. break;
  390. }
  391. }
  392. }
  393. static int efx_ethtool_set_rx_csum(struct net_device *net_dev, u32 enable)
  394. {
  395. struct efx_nic *efx = netdev_priv(net_dev);
  396. /* No way to stop the hardware doing the checks; we just
  397. * ignore the result.
  398. */
  399. efx->rx_checksum_enabled = (enable ? 1 : 0);
  400. return 0;
  401. }
  402. static u32 efx_ethtool_get_rx_csum(struct net_device *net_dev)
  403. {
  404. struct efx_nic *efx = netdev_priv(net_dev);
  405. return efx->rx_checksum_enabled;
  406. }
  407. static void efx_ethtool_self_test(struct net_device *net_dev,
  408. struct ethtool_test *test, u64 *data)
  409. {
  410. struct efx_nic *efx = netdev_priv(net_dev);
  411. struct efx_self_tests efx_tests;
  412. int offline, already_up;
  413. int rc;
  414. ASSERT_RTNL();
  415. if (efx->state != STATE_RUNNING) {
  416. rc = -EIO;
  417. goto fail1;
  418. }
  419. /* We need rx buffers and interrupts. */
  420. already_up = (efx->net_dev->flags & IFF_UP);
  421. if (!already_up) {
  422. rc = dev_open(efx->net_dev);
  423. if (rc) {
  424. EFX_ERR(efx, "failed opening device.\n");
  425. goto fail2;
  426. }
  427. }
  428. memset(&efx_tests, 0, sizeof(efx_tests));
  429. offline = (test->flags & ETH_TEST_FL_OFFLINE);
  430. /* Perform online self tests first */
  431. rc = efx_online_test(efx, &efx_tests);
  432. if (rc)
  433. goto out;
  434. /* Perform offline tests only if online tests passed */
  435. if (offline) {
  436. /* Stop the kernel from sending packets during the test. */
  437. efx_stop_queue(efx);
  438. rc = efx_flush_queues(efx);
  439. if (!rc)
  440. rc = efx_offline_test(efx, &efx_tests,
  441. efx->loopback_modes);
  442. efx_wake_queue(efx);
  443. }
  444. out:
  445. if (!already_up)
  446. dev_close(efx->net_dev);
  447. EFX_LOG(efx, "%s all %sline self-tests\n",
  448. rc == 0 ? "passed" : "failed", offline ? "off" : "on");
  449. fail2:
  450. fail1:
  451. /* Fill ethtool results structures */
  452. efx_ethtool_fill_self_tests(efx, &efx_tests, NULL, data);
  453. if (rc)
  454. test->flags |= ETH_TEST_FL_FAILED;
  455. }
  456. /* Restart autonegotiation */
  457. static int efx_ethtool_nway_reset(struct net_device *net_dev)
  458. {
  459. struct efx_nic *efx = netdev_priv(net_dev);
  460. return mii_nway_restart(&efx->mii);
  461. }
  462. static u32 efx_ethtool_get_link(struct net_device *net_dev)
  463. {
  464. struct efx_nic *efx = netdev_priv(net_dev);
  465. return efx->link_up;
  466. }
  467. static int efx_ethtool_get_coalesce(struct net_device *net_dev,
  468. struct ethtool_coalesce *coalesce)
  469. {
  470. struct efx_nic *efx = netdev_priv(net_dev);
  471. struct efx_tx_queue *tx_queue;
  472. struct efx_rx_queue *rx_queue;
  473. struct efx_channel *channel;
  474. memset(coalesce, 0, sizeof(*coalesce));
  475. /* Find lowest IRQ moderation across all used TX queues */
  476. coalesce->tx_coalesce_usecs_irq = ~((u32) 0);
  477. efx_for_each_tx_queue(tx_queue, efx) {
  478. channel = tx_queue->channel;
  479. if (channel->irq_moderation < coalesce->tx_coalesce_usecs_irq) {
  480. if (channel->used_flags != EFX_USED_BY_RX_TX)
  481. coalesce->tx_coalesce_usecs_irq =
  482. channel->irq_moderation;
  483. else
  484. coalesce->tx_coalesce_usecs_irq = 0;
  485. }
  486. }
  487. /* Find lowest IRQ moderation across all used RX queues */
  488. coalesce->rx_coalesce_usecs_irq = ~((u32) 0);
  489. efx_for_each_rx_queue(rx_queue, efx) {
  490. channel = rx_queue->channel;
  491. if (channel->irq_moderation < coalesce->rx_coalesce_usecs_irq)
  492. coalesce->rx_coalesce_usecs_irq =
  493. channel->irq_moderation;
  494. }
  495. return 0;
  496. }
  497. /* Set coalescing parameters
  498. * The difficulties occur for shared channels
  499. */
  500. static int efx_ethtool_set_coalesce(struct net_device *net_dev,
  501. struct ethtool_coalesce *coalesce)
  502. {
  503. struct efx_nic *efx = netdev_priv(net_dev);
  504. struct efx_channel *channel;
  505. struct efx_tx_queue *tx_queue;
  506. unsigned tx_usecs, rx_usecs;
  507. if (coalesce->use_adaptive_rx_coalesce ||
  508. coalesce->use_adaptive_tx_coalesce)
  509. return -EOPNOTSUPP;
  510. if (coalesce->rx_coalesce_usecs || coalesce->tx_coalesce_usecs) {
  511. EFX_ERR(efx, "invalid coalescing setting. "
  512. "Only rx/tx_coalesce_usecs_irq are supported\n");
  513. return -EOPNOTSUPP;
  514. }
  515. rx_usecs = coalesce->rx_coalesce_usecs_irq;
  516. tx_usecs = coalesce->tx_coalesce_usecs_irq;
  517. /* If the channel is shared only allow RX parameters to be set */
  518. efx_for_each_tx_queue(tx_queue, efx) {
  519. if ((tx_queue->channel->used_flags == EFX_USED_BY_RX_TX) &&
  520. tx_usecs) {
  521. EFX_ERR(efx, "Channel is shared. "
  522. "Only RX coalescing may be set\n");
  523. return -EOPNOTSUPP;
  524. }
  525. }
  526. efx_init_irq_moderation(efx, tx_usecs, rx_usecs);
  527. /* Reset channel to pick up new moderation value. Note that
  528. * this may change the value of the irq_moderation field
  529. * (e.g. to allow for hardware timer granularity).
  530. */
  531. efx_for_each_channel(channel, efx)
  532. falcon_set_int_moderation(channel);
  533. return 0;
  534. }
  535. static int efx_ethtool_set_pauseparam(struct net_device *net_dev,
  536. struct ethtool_pauseparam *pause)
  537. {
  538. struct efx_nic *efx = netdev_priv(net_dev);
  539. enum efx_fc_type flow_control = efx->flow_control;
  540. int rc;
  541. flow_control &= ~(EFX_FC_RX | EFX_FC_TX | EFX_FC_AUTO);
  542. flow_control |= pause->rx_pause ? EFX_FC_RX : 0;
  543. flow_control |= pause->tx_pause ? EFX_FC_TX : 0;
  544. flow_control |= pause->autoneg ? EFX_FC_AUTO : 0;
  545. /* Try to push the pause parameters */
  546. mutex_lock(&efx->mac_lock);
  547. rc = falcon_xmac_set_pause(efx, flow_control);
  548. mutex_unlock(&efx->mac_lock);
  549. if (!rc)
  550. efx_reconfigure_port(efx);
  551. return rc;
  552. }
  553. static void efx_ethtool_get_pauseparam(struct net_device *net_dev,
  554. struct ethtool_pauseparam *pause)
  555. {
  556. struct efx_nic *efx = netdev_priv(net_dev);
  557. pause->rx_pause = (efx->flow_control & EFX_FC_RX) ? 1 : 0;
  558. pause->tx_pause = (efx->flow_control & EFX_FC_TX) ? 1 : 0;
  559. pause->autoneg = (efx->flow_control & EFX_FC_AUTO) ? 1 : 0;
  560. }
  561. struct ethtool_ops efx_ethtool_ops = {
  562. .get_settings = efx_ethtool_get_settings,
  563. .set_settings = efx_ethtool_set_settings,
  564. .get_drvinfo = efx_ethtool_get_drvinfo,
  565. .nway_reset = efx_ethtool_nway_reset,
  566. .get_link = efx_ethtool_get_link,
  567. .get_coalesce = efx_ethtool_get_coalesce,
  568. .set_coalesce = efx_ethtool_set_coalesce,
  569. .get_pauseparam = efx_ethtool_get_pauseparam,
  570. .set_pauseparam = efx_ethtool_set_pauseparam,
  571. .get_rx_csum = efx_ethtool_get_rx_csum,
  572. .set_rx_csum = efx_ethtool_set_rx_csum,
  573. .get_tx_csum = ethtool_op_get_tx_csum,
  574. .set_tx_csum = ethtool_op_set_tx_csum,
  575. .get_sg = ethtool_op_get_sg,
  576. .set_sg = ethtool_op_set_sg,
  577. .get_tso = ethtool_op_get_tso,
  578. .set_tso = ethtool_op_set_tso,
  579. .get_flags = ethtool_op_get_flags,
  580. .set_flags = ethtool_op_set_flags,
  581. .self_test_count = efx_ethtool_self_test_count,
  582. .self_test = efx_ethtool_self_test,
  583. .get_strings = efx_ethtool_get_strings,
  584. .phys_id = efx_ethtool_phys_id,
  585. .get_stats_count = efx_ethtool_get_stats_count,
  586. .get_ethtool_stats = efx_ethtool_get_stats,
  587. };