ethtool.c 22 KB

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