ethtool.c 20 KB

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