ethtool.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2006-2009 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 "nic.h"
  18. #include "spi.h"
  19. #include "mdio_10g.h"
  20. struct ethtool_string {
  21. char name[ETH_GSTRING_LEN];
  22. };
  23. struct efx_ethtool_stat {
  24. const char *name;
  25. enum {
  26. EFX_ETHTOOL_STAT_SOURCE_mac_stats,
  27. EFX_ETHTOOL_STAT_SOURCE_nic,
  28. EFX_ETHTOOL_STAT_SOURCE_channel
  29. } source;
  30. unsigned offset;
  31. u64(*get_stat) (void *field); /* Reader function */
  32. };
  33. /* Initialiser for a struct #efx_ethtool_stat with type-checking */
  34. #define EFX_ETHTOOL_STAT(stat_name, source_name, field, field_type, \
  35. get_stat_function) { \
  36. .name = #stat_name, \
  37. .source = EFX_ETHTOOL_STAT_SOURCE_##source_name, \
  38. .offset = ((((field_type *) 0) == \
  39. &((struct efx_##source_name *)0)->field) ? \
  40. offsetof(struct efx_##source_name, field) : \
  41. offsetof(struct efx_##source_name, field)), \
  42. .get_stat = get_stat_function, \
  43. }
  44. static u64 efx_get_uint_stat(void *field)
  45. {
  46. return *(unsigned int *)field;
  47. }
  48. static u64 efx_get_ulong_stat(void *field)
  49. {
  50. return *(unsigned long *)field;
  51. }
  52. static u64 efx_get_u64_stat(void *field)
  53. {
  54. return *(u64 *) field;
  55. }
  56. static u64 efx_get_atomic_stat(void *field)
  57. {
  58. return atomic_read((atomic_t *) field);
  59. }
  60. #define EFX_ETHTOOL_ULONG_MAC_STAT(field) \
  61. EFX_ETHTOOL_STAT(field, mac_stats, field, \
  62. unsigned long, efx_get_ulong_stat)
  63. #define EFX_ETHTOOL_U64_MAC_STAT(field) \
  64. EFX_ETHTOOL_STAT(field, mac_stats, field, \
  65. u64, efx_get_u64_stat)
  66. #define EFX_ETHTOOL_UINT_NIC_STAT(name) \
  67. EFX_ETHTOOL_STAT(name, nic, n_##name, \
  68. unsigned int, efx_get_uint_stat)
  69. #define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field) \
  70. EFX_ETHTOOL_STAT(field, nic, field, \
  71. atomic_t, efx_get_atomic_stat)
  72. #define EFX_ETHTOOL_UINT_CHANNEL_STAT(field) \
  73. EFX_ETHTOOL_STAT(field, channel, n_##field, \
  74. unsigned int, efx_get_uint_stat)
  75. static struct efx_ethtool_stat efx_ethtool_stats[] = {
  76. EFX_ETHTOOL_U64_MAC_STAT(tx_bytes),
  77. EFX_ETHTOOL_U64_MAC_STAT(tx_good_bytes),
  78. EFX_ETHTOOL_U64_MAC_STAT(tx_bad_bytes),
  79. EFX_ETHTOOL_ULONG_MAC_STAT(tx_packets),
  80. EFX_ETHTOOL_ULONG_MAC_STAT(tx_bad),
  81. EFX_ETHTOOL_ULONG_MAC_STAT(tx_pause),
  82. EFX_ETHTOOL_ULONG_MAC_STAT(tx_control),
  83. EFX_ETHTOOL_ULONG_MAC_STAT(tx_unicast),
  84. EFX_ETHTOOL_ULONG_MAC_STAT(tx_multicast),
  85. EFX_ETHTOOL_ULONG_MAC_STAT(tx_broadcast),
  86. EFX_ETHTOOL_ULONG_MAC_STAT(tx_lt64),
  87. EFX_ETHTOOL_ULONG_MAC_STAT(tx_64),
  88. EFX_ETHTOOL_ULONG_MAC_STAT(tx_65_to_127),
  89. EFX_ETHTOOL_ULONG_MAC_STAT(tx_128_to_255),
  90. EFX_ETHTOOL_ULONG_MAC_STAT(tx_256_to_511),
  91. EFX_ETHTOOL_ULONG_MAC_STAT(tx_512_to_1023),
  92. EFX_ETHTOOL_ULONG_MAC_STAT(tx_1024_to_15xx),
  93. EFX_ETHTOOL_ULONG_MAC_STAT(tx_15xx_to_jumbo),
  94. EFX_ETHTOOL_ULONG_MAC_STAT(tx_gtjumbo),
  95. EFX_ETHTOOL_ULONG_MAC_STAT(tx_collision),
  96. EFX_ETHTOOL_ULONG_MAC_STAT(tx_single_collision),
  97. EFX_ETHTOOL_ULONG_MAC_STAT(tx_multiple_collision),
  98. EFX_ETHTOOL_ULONG_MAC_STAT(tx_excessive_collision),
  99. EFX_ETHTOOL_ULONG_MAC_STAT(tx_deferred),
  100. EFX_ETHTOOL_ULONG_MAC_STAT(tx_late_collision),
  101. EFX_ETHTOOL_ULONG_MAC_STAT(tx_excessive_deferred),
  102. EFX_ETHTOOL_ULONG_MAC_STAT(tx_non_tcpudp),
  103. EFX_ETHTOOL_ULONG_MAC_STAT(tx_mac_src_error),
  104. EFX_ETHTOOL_ULONG_MAC_STAT(tx_ip_src_error),
  105. EFX_ETHTOOL_U64_MAC_STAT(rx_bytes),
  106. EFX_ETHTOOL_U64_MAC_STAT(rx_good_bytes),
  107. EFX_ETHTOOL_U64_MAC_STAT(rx_bad_bytes),
  108. EFX_ETHTOOL_ULONG_MAC_STAT(rx_packets),
  109. EFX_ETHTOOL_ULONG_MAC_STAT(rx_good),
  110. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad),
  111. EFX_ETHTOOL_ULONG_MAC_STAT(rx_pause),
  112. EFX_ETHTOOL_ULONG_MAC_STAT(rx_control),
  113. EFX_ETHTOOL_ULONG_MAC_STAT(rx_unicast),
  114. EFX_ETHTOOL_ULONG_MAC_STAT(rx_multicast),
  115. EFX_ETHTOOL_ULONG_MAC_STAT(rx_broadcast),
  116. EFX_ETHTOOL_ULONG_MAC_STAT(rx_lt64),
  117. EFX_ETHTOOL_ULONG_MAC_STAT(rx_64),
  118. EFX_ETHTOOL_ULONG_MAC_STAT(rx_65_to_127),
  119. EFX_ETHTOOL_ULONG_MAC_STAT(rx_128_to_255),
  120. EFX_ETHTOOL_ULONG_MAC_STAT(rx_256_to_511),
  121. EFX_ETHTOOL_ULONG_MAC_STAT(rx_512_to_1023),
  122. EFX_ETHTOOL_ULONG_MAC_STAT(rx_1024_to_15xx),
  123. EFX_ETHTOOL_ULONG_MAC_STAT(rx_15xx_to_jumbo),
  124. EFX_ETHTOOL_ULONG_MAC_STAT(rx_gtjumbo),
  125. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_lt64),
  126. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_64_to_15xx),
  127. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_15xx_to_jumbo),
  128. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_gtjumbo),
  129. EFX_ETHTOOL_ULONG_MAC_STAT(rx_overflow),
  130. EFX_ETHTOOL_ULONG_MAC_STAT(rx_missed),
  131. EFX_ETHTOOL_ULONG_MAC_STAT(rx_false_carrier),
  132. EFX_ETHTOOL_ULONG_MAC_STAT(rx_symbol_error),
  133. EFX_ETHTOOL_ULONG_MAC_STAT(rx_align_error),
  134. EFX_ETHTOOL_ULONG_MAC_STAT(rx_length_error),
  135. EFX_ETHTOOL_ULONG_MAC_STAT(rx_internal_error),
  136. EFX_ETHTOOL_UINT_NIC_STAT(rx_nodesc_drop_cnt),
  137. EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset),
  138. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc),
  139. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),
  140. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err),
  141. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch),
  142. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
  143. };
  144. /* Number of ethtool statistics */
  145. #define EFX_ETHTOOL_NUM_STATS ARRAY_SIZE(efx_ethtool_stats)
  146. #define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB
  147. /**************************************************************************
  148. *
  149. * Ethtool operations
  150. *
  151. **************************************************************************
  152. */
  153. /* Identify device by flashing LEDs */
  154. static int efx_ethtool_phys_id(struct net_device *net_dev, u32 count)
  155. {
  156. struct efx_nic *efx = netdev_priv(net_dev);
  157. do {
  158. efx->type->set_id_led(efx, EFX_LED_ON);
  159. schedule_timeout_interruptible(HZ / 2);
  160. efx->type->set_id_led(efx, EFX_LED_OFF);
  161. schedule_timeout_interruptible(HZ / 2);
  162. } while (!signal_pending(current) && --count != 0);
  163. efx->type->set_id_led(efx, EFX_LED_DEFAULT);
  164. return 0;
  165. }
  166. /* This must be called with rtnl_lock held. */
  167. int efx_ethtool_get_settings(struct net_device *net_dev,
  168. struct ethtool_cmd *ecmd)
  169. {
  170. struct efx_nic *efx = netdev_priv(net_dev);
  171. struct efx_link_state *link_state = &efx->link_state;
  172. mutex_lock(&efx->mac_lock);
  173. efx->phy_op->get_settings(efx, ecmd);
  174. mutex_unlock(&efx->mac_lock);
  175. /* GMAC does not support 1000Mbps HD */
  176. ecmd->supported &= ~SUPPORTED_1000baseT_Half;
  177. /* Both MACs support pause frames (bidirectional and respond-only) */
  178. ecmd->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
  179. if (LOOPBACK_INTERNAL(efx)) {
  180. ecmd->speed = link_state->speed;
  181. ecmd->duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF;
  182. }
  183. return 0;
  184. }
  185. /* This must be called with rtnl_lock held. */
  186. int efx_ethtool_set_settings(struct net_device *net_dev,
  187. struct ethtool_cmd *ecmd)
  188. {
  189. struct efx_nic *efx = netdev_priv(net_dev);
  190. int rc;
  191. /* GMAC does not support 1000Mbps HD */
  192. if (ecmd->speed == SPEED_1000 && ecmd->duplex != DUPLEX_FULL) {
  193. EFX_LOG(efx, "rejecting unsupported 1000Mbps HD"
  194. " setting\n");
  195. return -EINVAL;
  196. }
  197. mutex_lock(&efx->mac_lock);
  198. rc = efx->phy_op->set_settings(efx, ecmd);
  199. mutex_unlock(&efx->mac_lock);
  200. return rc;
  201. }
  202. static void efx_ethtool_get_drvinfo(struct net_device *net_dev,
  203. struct ethtool_drvinfo *info)
  204. {
  205. struct efx_nic *efx = netdev_priv(net_dev);
  206. strlcpy(info->driver, EFX_DRIVER_NAME, sizeof(info->driver));
  207. strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version));
  208. if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0)
  209. siena_print_fwver(efx, info->fw_version,
  210. sizeof(info->fw_version));
  211. strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
  212. }
  213. static int efx_ethtool_get_regs_len(struct net_device *net_dev)
  214. {
  215. return efx_nic_get_regs_len(netdev_priv(net_dev));
  216. }
  217. static void efx_ethtool_get_regs(struct net_device *net_dev,
  218. struct ethtool_regs *regs, void *buf)
  219. {
  220. struct efx_nic *efx = netdev_priv(net_dev);
  221. regs->version = efx->type->revision;
  222. efx_nic_get_regs(efx, buf);
  223. }
  224. /**
  225. * efx_fill_test - fill in an individual self-test entry
  226. * @test_index: Index of the test
  227. * @strings: Ethtool strings, or %NULL
  228. * @data: Ethtool test results, or %NULL
  229. * @test: Pointer to test result (used only if data != %NULL)
  230. * @unit_format: Unit name format (e.g. "chan\%d")
  231. * @unit_id: Unit id (e.g. 0 for "chan0")
  232. * @test_format: Test name format (e.g. "loopback.\%s.tx.sent")
  233. * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
  234. *
  235. * Fill in an individual self-test entry.
  236. */
  237. static void efx_fill_test(unsigned int test_index,
  238. struct ethtool_string *strings, u64 *data,
  239. int *test, const char *unit_format, int unit_id,
  240. const char *test_format, const char *test_id)
  241. {
  242. struct ethtool_string unit_str, test_str;
  243. /* Fill data value, if applicable */
  244. if (data)
  245. data[test_index] = *test;
  246. /* Fill string, if applicable */
  247. if (strings) {
  248. if (strchr(unit_format, '%'))
  249. snprintf(unit_str.name, sizeof(unit_str.name),
  250. unit_format, unit_id);
  251. else
  252. strcpy(unit_str.name, unit_format);
  253. snprintf(test_str.name, sizeof(test_str.name),
  254. test_format, test_id);
  255. snprintf(strings[test_index].name,
  256. sizeof(strings[test_index].name),
  257. "%-6s %-24s", unit_str.name, test_str.name);
  258. }
  259. }
  260. #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
  261. #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
  262. #define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
  263. #define EFX_LOOPBACK_NAME(_mode, _counter) \
  264. "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode)
  265. /**
  266. * efx_fill_loopback_test - fill in a block of loopback self-test entries
  267. * @efx: Efx NIC
  268. * @lb_tests: Efx loopback self-test results structure
  269. * @mode: Loopback test mode
  270. * @test_index: Starting index of the test
  271. * @strings: Ethtool strings, or %NULL
  272. * @data: Ethtool test results, or %NULL
  273. */
  274. static int efx_fill_loopback_test(struct efx_nic *efx,
  275. struct efx_loopback_self_tests *lb_tests,
  276. enum efx_loopback_mode mode,
  277. unsigned int test_index,
  278. struct ethtool_string *strings, u64 *data)
  279. {
  280. struct efx_tx_queue *tx_queue;
  281. efx_for_each_channel_tx_queue(tx_queue, &efx->channel[0]) {
  282. efx_fill_test(test_index++, strings, data,
  283. &lb_tests->tx_sent[tx_queue->queue],
  284. EFX_TX_QUEUE_NAME(tx_queue),
  285. EFX_LOOPBACK_NAME(mode, "tx_sent"));
  286. efx_fill_test(test_index++, strings, data,
  287. &lb_tests->tx_done[tx_queue->queue],
  288. EFX_TX_QUEUE_NAME(tx_queue),
  289. EFX_LOOPBACK_NAME(mode, "tx_done"));
  290. }
  291. efx_fill_test(test_index++, strings, data,
  292. &lb_tests->rx_good,
  293. "rx", 0,
  294. EFX_LOOPBACK_NAME(mode, "rx_good"));
  295. efx_fill_test(test_index++, strings, data,
  296. &lb_tests->rx_bad,
  297. "rx", 0,
  298. EFX_LOOPBACK_NAME(mode, "rx_bad"));
  299. return test_index;
  300. }
  301. /**
  302. * efx_ethtool_fill_self_tests - get self-test details
  303. * @efx: Efx NIC
  304. * @tests: Efx self-test results structure, or %NULL
  305. * @strings: Ethtool strings, or %NULL
  306. * @data: Ethtool test results, or %NULL
  307. */
  308. static int efx_ethtool_fill_self_tests(struct efx_nic *efx,
  309. struct efx_self_tests *tests,
  310. struct ethtool_string *strings,
  311. u64 *data)
  312. {
  313. struct efx_channel *channel;
  314. unsigned int n = 0, i;
  315. enum efx_loopback_mode mode;
  316. efx_fill_test(n++, strings, data, &tests->phy_alive,
  317. "phy", 0, "alive", NULL);
  318. efx_fill_test(n++, strings, data, &tests->nvram,
  319. "core", 0, "nvram", NULL);
  320. efx_fill_test(n++, strings, data, &tests->interrupt,
  321. "core", 0, "interrupt", NULL);
  322. /* Event queues */
  323. efx_for_each_channel(channel, efx) {
  324. efx_fill_test(n++, strings, data,
  325. &tests->eventq_dma[channel->channel],
  326. EFX_CHANNEL_NAME(channel),
  327. "eventq.dma", NULL);
  328. efx_fill_test(n++, strings, data,
  329. &tests->eventq_int[channel->channel],
  330. EFX_CHANNEL_NAME(channel),
  331. "eventq.int", NULL);
  332. efx_fill_test(n++, strings, data,
  333. &tests->eventq_poll[channel->channel],
  334. EFX_CHANNEL_NAME(channel),
  335. "eventq.poll", NULL);
  336. }
  337. efx_fill_test(n++, strings, data, &tests->registers,
  338. "core", 0, "registers", NULL);
  339. if (efx->phy_op->run_tests != NULL) {
  340. EFX_BUG_ON_PARANOID(efx->phy_op->test_name == NULL);
  341. for (i = 0; true; ++i) {
  342. const char *name;
  343. EFX_BUG_ON_PARANOID(i >= EFX_MAX_PHY_TESTS);
  344. name = efx->phy_op->test_name(efx, i);
  345. if (name == NULL)
  346. break;
  347. efx_fill_test(n++, strings, data, &tests->phy_ext[i],
  348. "phy", 0, name, NULL);
  349. }
  350. }
  351. /* Loopback tests */
  352. for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
  353. if (!(efx->loopback_modes & (1 << mode)))
  354. continue;
  355. n = efx_fill_loopback_test(efx,
  356. &tests->loopback[mode], mode, n,
  357. strings, data);
  358. }
  359. return n;
  360. }
  361. static int efx_ethtool_get_sset_count(struct net_device *net_dev,
  362. int string_set)
  363. {
  364. switch (string_set) {
  365. case ETH_SS_STATS:
  366. return EFX_ETHTOOL_NUM_STATS;
  367. case ETH_SS_TEST:
  368. return efx_ethtool_fill_self_tests(netdev_priv(net_dev),
  369. NULL, NULL, NULL);
  370. default:
  371. return -EINVAL;
  372. }
  373. }
  374. static void efx_ethtool_get_strings(struct net_device *net_dev,
  375. u32 string_set, u8 *strings)
  376. {
  377. struct efx_nic *efx = netdev_priv(net_dev);
  378. struct ethtool_string *ethtool_strings =
  379. (struct ethtool_string *)strings;
  380. int i;
  381. switch (string_set) {
  382. case ETH_SS_STATS:
  383. for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++)
  384. strncpy(ethtool_strings[i].name,
  385. efx_ethtool_stats[i].name,
  386. sizeof(ethtool_strings[i].name));
  387. break;
  388. case ETH_SS_TEST:
  389. efx_ethtool_fill_self_tests(efx, NULL,
  390. ethtool_strings, NULL);
  391. break;
  392. default:
  393. /* No other string sets */
  394. break;
  395. }
  396. }
  397. static void efx_ethtool_get_stats(struct net_device *net_dev,
  398. struct ethtool_stats *stats,
  399. u64 *data)
  400. {
  401. struct efx_nic *efx = netdev_priv(net_dev);
  402. struct efx_mac_stats *mac_stats = &efx->mac_stats;
  403. struct efx_ethtool_stat *stat;
  404. struct efx_channel *channel;
  405. int i;
  406. EFX_BUG_ON_PARANOID(stats->n_stats != EFX_ETHTOOL_NUM_STATS);
  407. /* Update MAC and NIC statistics */
  408. dev_get_stats(net_dev);
  409. /* Fill detailed statistics buffer */
  410. for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++) {
  411. stat = &efx_ethtool_stats[i];
  412. switch (stat->source) {
  413. case EFX_ETHTOOL_STAT_SOURCE_mac_stats:
  414. data[i] = stat->get_stat((void *)mac_stats +
  415. stat->offset);
  416. break;
  417. case EFX_ETHTOOL_STAT_SOURCE_nic:
  418. data[i] = stat->get_stat((void *)efx + stat->offset);
  419. break;
  420. case EFX_ETHTOOL_STAT_SOURCE_channel:
  421. data[i] = 0;
  422. efx_for_each_channel(channel, efx)
  423. data[i] += stat->get_stat((void *)channel +
  424. stat->offset);
  425. break;
  426. }
  427. }
  428. }
  429. static int efx_ethtool_set_tso(struct net_device *net_dev, u32 enable)
  430. {
  431. struct efx_nic *efx __attribute__ ((unused)) = netdev_priv(net_dev);
  432. unsigned long features;
  433. features = NETIF_F_TSO;
  434. if (efx->type->offload_features & NETIF_F_V6_CSUM)
  435. features |= NETIF_F_TSO6;
  436. if (enable)
  437. net_dev->features |= features;
  438. else
  439. net_dev->features &= ~features;
  440. return 0;
  441. }
  442. static int efx_ethtool_set_tx_csum(struct net_device *net_dev, u32 enable)
  443. {
  444. struct efx_nic *efx = netdev_priv(net_dev);
  445. unsigned long features = efx->type->offload_features & NETIF_F_ALL_CSUM;
  446. if (enable)
  447. net_dev->features |= features;
  448. else
  449. net_dev->features &= ~features;
  450. return 0;
  451. }
  452. static int efx_ethtool_set_rx_csum(struct net_device *net_dev, u32 enable)
  453. {
  454. struct efx_nic *efx = netdev_priv(net_dev);
  455. /* No way to stop the hardware doing the checks; we just
  456. * ignore the result.
  457. */
  458. efx->rx_checksum_enabled = !!enable;
  459. return 0;
  460. }
  461. static u32 efx_ethtool_get_rx_csum(struct net_device *net_dev)
  462. {
  463. struct efx_nic *efx = netdev_priv(net_dev);
  464. return efx->rx_checksum_enabled;
  465. }
  466. static void efx_ethtool_self_test(struct net_device *net_dev,
  467. struct ethtool_test *test, u64 *data)
  468. {
  469. struct efx_nic *efx = netdev_priv(net_dev);
  470. struct efx_self_tests efx_tests;
  471. int already_up;
  472. int rc;
  473. ASSERT_RTNL();
  474. if (efx->state != STATE_RUNNING) {
  475. rc = -EIO;
  476. goto fail1;
  477. }
  478. /* We need rx buffers and interrupts. */
  479. already_up = (efx->net_dev->flags & IFF_UP);
  480. if (!already_up) {
  481. rc = dev_open(efx->net_dev);
  482. if (rc) {
  483. EFX_ERR(efx, "failed opening device.\n");
  484. goto fail2;
  485. }
  486. }
  487. memset(&efx_tests, 0, sizeof(efx_tests));
  488. rc = efx_selftest(efx, &efx_tests, test->flags);
  489. if (!already_up)
  490. dev_close(efx->net_dev);
  491. EFX_LOG(efx, "%s %sline self-tests\n",
  492. rc == 0 ? "passed" : "failed",
  493. (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
  494. fail2:
  495. fail1:
  496. /* Fill ethtool results structures */
  497. efx_ethtool_fill_self_tests(efx, &efx_tests, NULL, data);
  498. if (rc)
  499. test->flags |= ETH_TEST_FL_FAILED;
  500. }
  501. /* Restart autonegotiation */
  502. static int efx_ethtool_nway_reset(struct net_device *net_dev)
  503. {
  504. struct efx_nic *efx = netdev_priv(net_dev);
  505. return mdio45_nway_restart(&efx->mdio);
  506. }
  507. static u32 efx_ethtool_get_link(struct net_device *net_dev)
  508. {
  509. struct efx_nic *efx = netdev_priv(net_dev);
  510. return efx->link_state.up;
  511. }
  512. static int efx_ethtool_get_eeprom_len(struct net_device *net_dev)
  513. {
  514. struct efx_nic *efx = netdev_priv(net_dev);
  515. struct efx_spi_device *spi = efx->spi_eeprom;
  516. if (!spi)
  517. return 0;
  518. return min(spi->size, EFX_EEPROM_BOOTCONFIG_END) -
  519. min(spi->size, EFX_EEPROM_BOOTCONFIG_START);
  520. }
  521. static int efx_ethtool_get_eeprom(struct net_device *net_dev,
  522. struct ethtool_eeprom *eeprom, u8 *buf)
  523. {
  524. struct efx_nic *efx = netdev_priv(net_dev);
  525. struct efx_spi_device *spi = efx->spi_eeprom;
  526. size_t len;
  527. int rc;
  528. rc = mutex_lock_interruptible(&efx->spi_lock);
  529. if (rc)
  530. return rc;
  531. rc = falcon_spi_read(efx, spi,
  532. eeprom->offset + EFX_EEPROM_BOOTCONFIG_START,
  533. eeprom->len, &len, buf);
  534. mutex_unlock(&efx->spi_lock);
  535. eeprom->magic = EFX_ETHTOOL_EEPROM_MAGIC;
  536. eeprom->len = len;
  537. return rc;
  538. }
  539. static int efx_ethtool_set_eeprom(struct net_device *net_dev,
  540. struct ethtool_eeprom *eeprom, u8 *buf)
  541. {
  542. struct efx_nic *efx = netdev_priv(net_dev);
  543. struct efx_spi_device *spi = efx->spi_eeprom;
  544. size_t len;
  545. int rc;
  546. if (eeprom->magic != EFX_ETHTOOL_EEPROM_MAGIC)
  547. return -EINVAL;
  548. rc = mutex_lock_interruptible(&efx->spi_lock);
  549. if (rc)
  550. return rc;
  551. rc = falcon_spi_write(efx, spi,
  552. eeprom->offset + EFX_EEPROM_BOOTCONFIG_START,
  553. eeprom->len, &len, buf);
  554. mutex_unlock(&efx->spi_lock);
  555. eeprom->len = len;
  556. return rc;
  557. }
  558. static int efx_ethtool_get_coalesce(struct net_device *net_dev,
  559. struct ethtool_coalesce *coalesce)
  560. {
  561. struct efx_nic *efx = netdev_priv(net_dev);
  562. struct efx_tx_queue *tx_queue;
  563. struct efx_channel *channel;
  564. memset(coalesce, 0, sizeof(*coalesce));
  565. /* Find lowest IRQ moderation across all used TX queues */
  566. coalesce->tx_coalesce_usecs_irq = ~((u32) 0);
  567. efx_for_each_tx_queue(tx_queue, efx) {
  568. channel = tx_queue->channel;
  569. if (channel->irq_moderation < coalesce->tx_coalesce_usecs_irq) {
  570. if (channel->channel < efx->n_rx_channels)
  571. coalesce->tx_coalesce_usecs_irq =
  572. channel->irq_moderation;
  573. else
  574. coalesce->tx_coalesce_usecs_irq = 0;
  575. }
  576. }
  577. coalesce->use_adaptive_rx_coalesce = efx->irq_rx_adaptive;
  578. coalesce->rx_coalesce_usecs_irq = efx->irq_rx_moderation;
  579. coalesce->tx_coalesce_usecs_irq *= EFX_IRQ_MOD_RESOLUTION;
  580. coalesce->rx_coalesce_usecs_irq *= EFX_IRQ_MOD_RESOLUTION;
  581. return 0;
  582. }
  583. /* Set coalescing parameters
  584. * The difficulties occur for shared channels
  585. */
  586. static int efx_ethtool_set_coalesce(struct net_device *net_dev,
  587. struct ethtool_coalesce *coalesce)
  588. {
  589. struct efx_nic *efx = netdev_priv(net_dev);
  590. struct efx_channel *channel;
  591. struct efx_tx_queue *tx_queue;
  592. unsigned tx_usecs, rx_usecs, adaptive;
  593. if (coalesce->use_adaptive_tx_coalesce)
  594. return -EOPNOTSUPP;
  595. if (coalesce->rx_coalesce_usecs || coalesce->tx_coalesce_usecs) {
  596. EFX_ERR(efx, "invalid coalescing setting. "
  597. "Only rx/tx_coalesce_usecs_irq are supported\n");
  598. return -EOPNOTSUPP;
  599. }
  600. rx_usecs = coalesce->rx_coalesce_usecs_irq;
  601. tx_usecs = coalesce->tx_coalesce_usecs_irq;
  602. adaptive = coalesce->use_adaptive_rx_coalesce;
  603. /* If the channel is shared only allow RX parameters to be set */
  604. efx_for_each_tx_queue(tx_queue, efx) {
  605. if ((tx_queue->channel->channel < efx->n_rx_channels) &&
  606. tx_usecs) {
  607. EFX_ERR(efx, "Channel is shared. "
  608. "Only RX coalescing may be set\n");
  609. return -EOPNOTSUPP;
  610. }
  611. }
  612. efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive);
  613. efx_for_each_channel(channel, efx)
  614. efx->type->push_irq_moderation(channel);
  615. return 0;
  616. }
  617. static int efx_ethtool_set_pauseparam(struct net_device *net_dev,
  618. struct ethtool_pauseparam *pause)
  619. {
  620. struct efx_nic *efx = netdev_priv(net_dev);
  621. enum efx_fc_type wanted_fc, old_fc;
  622. u32 old_adv;
  623. bool reset;
  624. int rc = 0;
  625. mutex_lock(&efx->mac_lock);
  626. wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
  627. (pause->tx_pause ? EFX_FC_TX : 0) |
  628. (pause->autoneg ? EFX_FC_AUTO : 0));
  629. if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
  630. EFX_LOG(efx, "Flow control unsupported: tx ON rx OFF\n");
  631. rc = -EINVAL;
  632. goto out;
  633. }
  634. if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising) {
  635. EFX_LOG(efx, "Autonegotiation is disabled\n");
  636. rc = -EINVAL;
  637. goto out;
  638. }
  639. /* TX flow control may automatically turn itself off if the
  640. * link partner (intermittently) stops responding to pause
  641. * frames. There isn't any indication that this has happened,
  642. * so the best we do is leave it up to the user to spot this
  643. * and fix it be cycling transmit flow control on this end. */
  644. reset = (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX);
  645. if (EFX_WORKAROUND_11482(efx) && reset) {
  646. if (efx_nic_rev(efx) == EFX_REV_FALCON_B0) {
  647. /* Recover by resetting the EM block */
  648. falcon_stop_nic_stats(efx);
  649. falcon_drain_tx_fifo(efx);
  650. efx->mac_op->reconfigure(efx);
  651. falcon_start_nic_stats(efx);
  652. } else {
  653. /* Schedule a reset to recover */
  654. efx_schedule_reset(efx, RESET_TYPE_INVISIBLE);
  655. }
  656. }
  657. old_adv = efx->link_advertising;
  658. old_fc = efx->wanted_fc;
  659. efx_link_set_wanted_fc(efx, wanted_fc);
  660. if (efx->link_advertising != old_adv ||
  661. (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) {
  662. rc = efx->phy_op->reconfigure(efx);
  663. if (rc) {
  664. EFX_ERR(efx, "Unable to advertise requested flow "
  665. "control setting\n");
  666. goto out;
  667. }
  668. }
  669. /* Reconfigure the MAC. The PHY *may* generate a link state change event
  670. * if the user just changed the advertised capabilities, but there's no
  671. * harm doing this twice */
  672. efx->mac_op->reconfigure(efx);
  673. out:
  674. mutex_unlock(&efx->mac_lock);
  675. return rc;
  676. }
  677. static void efx_ethtool_get_pauseparam(struct net_device *net_dev,
  678. struct ethtool_pauseparam *pause)
  679. {
  680. struct efx_nic *efx = netdev_priv(net_dev);
  681. pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX);
  682. pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX);
  683. pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO);
  684. }
  685. static void efx_ethtool_get_wol(struct net_device *net_dev,
  686. struct ethtool_wolinfo *wol)
  687. {
  688. struct efx_nic *efx = netdev_priv(net_dev);
  689. return efx->type->get_wol(efx, wol);
  690. }
  691. static int efx_ethtool_set_wol(struct net_device *net_dev,
  692. struct ethtool_wolinfo *wol)
  693. {
  694. struct efx_nic *efx = netdev_priv(net_dev);
  695. return efx->type->set_wol(efx, wol->wolopts);
  696. }
  697. extern int efx_ethtool_reset(struct net_device *net_dev, u32 *flags)
  698. {
  699. struct efx_nic *efx = netdev_priv(net_dev);
  700. enum reset_type method;
  701. enum {
  702. ETH_RESET_EFX_INVISIBLE = (ETH_RESET_DMA | ETH_RESET_FILTER |
  703. ETH_RESET_OFFLOAD | ETH_RESET_MAC)
  704. };
  705. /* Check for minimal reset flags */
  706. if ((*flags & ETH_RESET_EFX_INVISIBLE) != ETH_RESET_EFX_INVISIBLE)
  707. return -EINVAL;
  708. *flags ^= ETH_RESET_EFX_INVISIBLE;
  709. method = RESET_TYPE_INVISIBLE;
  710. if (*flags & ETH_RESET_PHY) {
  711. *flags ^= ETH_RESET_PHY;
  712. method = RESET_TYPE_ALL;
  713. }
  714. if ((*flags & efx->type->reset_world_flags) ==
  715. efx->type->reset_world_flags) {
  716. *flags ^= efx->type->reset_world_flags;
  717. method = RESET_TYPE_WORLD;
  718. }
  719. return efx_reset(efx, method);
  720. }
  721. const struct ethtool_ops efx_ethtool_ops = {
  722. .get_settings = efx_ethtool_get_settings,
  723. .set_settings = efx_ethtool_set_settings,
  724. .get_drvinfo = efx_ethtool_get_drvinfo,
  725. .get_regs_len = efx_ethtool_get_regs_len,
  726. .get_regs = efx_ethtool_get_regs,
  727. .nway_reset = efx_ethtool_nway_reset,
  728. .get_link = efx_ethtool_get_link,
  729. .get_eeprom_len = efx_ethtool_get_eeprom_len,
  730. .get_eeprom = efx_ethtool_get_eeprom,
  731. .set_eeprom = efx_ethtool_set_eeprom,
  732. .get_coalesce = efx_ethtool_get_coalesce,
  733. .set_coalesce = efx_ethtool_set_coalesce,
  734. .get_pauseparam = efx_ethtool_get_pauseparam,
  735. .set_pauseparam = efx_ethtool_set_pauseparam,
  736. .get_rx_csum = efx_ethtool_get_rx_csum,
  737. .set_rx_csum = efx_ethtool_set_rx_csum,
  738. .get_tx_csum = ethtool_op_get_tx_csum,
  739. /* Need to enable/disable IPv6 too */
  740. .set_tx_csum = efx_ethtool_set_tx_csum,
  741. .get_sg = ethtool_op_get_sg,
  742. .set_sg = ethtool_op_set_sg,
  743. .get_tso = ethtool_op_get_tso,
  744. /* Need to enable/disable TSO-IPv6 too */
  745. .set_tso = efx_ethtool_set_tso,
  746. .get_flags = ethtool_op_get_flags,
  747. .set_flags = ethtool_op_set_flags,
  748. .get_sset_count = efx_ethtool_get_sset_count,
  749. .self_test = efx_ethtool_self_test,
  750. .get_strings = efx_ethtool_get_strings,
  751. .phys_id = efx_ethtool_phys_id,
  752. .get_ethtool_stats = efx_ethtool_get_stats,
  753. .get_wol = efx_ethtool_get_wol,
  754. .set_wol = efx_ethtool_set_wol,
  755. .reset = efx_ethtool_reset,
  756. };