ethtool.c 22 KB

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