ethtool.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2006-2010 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 <linux/in.h>
  14. #include "net_driver.h"
  15. #include "workarounds.h"
  16. #include "selftest.h"
  17. #include "efx.h"
  18. #include "filter.h"
  19. #include "nic.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. EFX_ETHTOOL_STAT_SOURCE_tx_queue
  30. } source;
  31. unsigned offset;
  32. u64(*get_stat) (void *field); /* Reader function */
  33. };
  34. /* Initialiser for a struct #efx_ethtool_stat with type-checking */
  35. #define EFX_ETHTOOL_STAT(stat_name, source_name, field, field_type, \
  36. get_stat_function) { \
  37. .name = #stat_name, \
  38. .source = EFX_ETHTOOL_STAT_SOURCE_##source_name, \
  39. .offset = ((((field_type *) 0) == \
  40. &((struct efx_##source_name *)0)->field) ? \
  41. offsetof(struct efx_##source_name, field) : \
  42. offsetof(struct efx_##source_name, field)), \
  43. .get_stat = get_stat_function, \
  44. }
  45. static u64 efx_get_uint_stat(void *field)
  46. {
  47. return *(unsigned int *)field;
  48. }
  49. static u64 efx_get_ulong_stat(void *field)
  50. {
  51. return *(unsigned long *)field;
  52. }
  53. static u64 efx_get_u64_stat(void *field)
  54. {
  55. return *(u64 *) field;
  56. }
  57. static u64 efx_get_atomic_stat(void *field)
  58. {
  59. return atomic_read((atomic_t *) field);
  60. }
  61. #define EFX_ETHTOOL_ULONG_MAC_STAT(field) \
  62. EFX_ETHTOOL_STAT(field, mac_stats, field, \
  63. unsigned long, efx_get_ulong_stat)
  64. #define EFX_ETHTOOL_U64_MAC_STAT(field) \
  65. EFX_ETHTOOL_STAT(field, mac_stats, field, \
  66. u64, efx_get_u64_stat)
  67. #define EFX_ETHTOOL_UINT_NIC_STAT(name) \
  68. EFX_ETHTOOL_STAT(name, nic, n_##name, \
  69. unsigned int, efx_get_uint_stat)
  70. #define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field) \
  71. EFX_ETHTOOL_STAT(field, nic, field, \
  72. atomic_t, efx_get_atomic_stat)
  73. #define EFX_ETHTOOL_UINT_CHANNEL_STAT(field) \
  74. EFX_ETHTOOL_STAT(field, channel, n_##field, \
  75. unsigned int, efx_get_uint_stat)
  76. #define EFX_ETHTOOL_UINT_TXQ_STAT(field) \
  77. EFX_ETHTOOL_STAT(tx_##field, tx_queue, field, \
  78. unsigned int, efx_get_uint_stat)
  79. static struct efx_ethtool_stat efx_ethtool_stats[] = {
  80. EFX_ETHTOOL_U64_MAC_STAT(tx_bytes),
  81. EFX_ETHTOOL_U64_MAC_STAT(tx_good_bytes),
  82. EFX_ETHTOOL_U64_MAC_STAT(tx_bad_bytes),
  83. EFX_ETHTOOL_ULONG_MAC_STAT(tx_packets),
  84. EFX_ETHTOOL_ULONG_MAC_STAT(tx_bad),
  85. EFX_ETHTOOL_ULONG_MAC_STAT(tx_pause),
  86. EFX_ETHTOOL_ULONG_MAC_STAT(tx_control),
  87. EFX_ETHTOOL_ULONG_MAC_STAT(tx_unicast),
  88. EFX_ETHTOOL_ULONG_MAC_STAT(tx_multicast),
  89. EFX_ETHTOOL_ULONG_MAC_STAT(tx_broadcast),
  90. EFX_ETHTOOL_ULONG_MAC_STAT(tx_lt64),
  91. EFX_ETHTOOL_ULONG_MAC_STAT(tx_64),
  92. EFX_ETHTOOL_ULONG_MAC_STAT(tx_65_to_127),
  93. EFX_ETHTOOL_ULONG_MAC_STAT(tx_128_to_255),
  94. EFX_ETHTOOL_ULONG_MAC_STAT(tx_256_to_511),
  95. EFX_ETHTOOL_ULONG_MAC_STAT(tx_512_to_1023),
  96. EFX_ETHTOOL_ULONG_MAC_STAT(tx_1024_to_15xx),
  97. EFX_ETHTOOL_ULONG_MAC_STAT(tx_15xx_to_jumbo),
  98. EFX_ETHTOOL_ULONG_MAC_STAT(tx_gtjumbo),
  99. EFX_ETHTOOL_ULONG_MAC_STAT(tx_collision),
  100. EFX_ETHTOOL_ULONG_MAC_STAT(tx_single_collision),
  101. EFX_ETHTOOL_ULONG_MAC_STAT(tx_multiple_collision),
  102. EFX_ETHTOOL_ULONG_MAC_STAT(tx_excessive_collision),
  103. EFX_ETHTOOL_ULONG_MAC_STAT(tx_deferred),
  104. EFX_ETHTOOL_ULONG_MAC_STAT(tx_late_collision),
  105. EFX_ETHTOOL_ULONG_MAC_STAT(tx_excessive_deferred),
  106. EFX_ETHTOOL_ULONG_MAC_STAT(tx_non_tcpudp),
  107. EFX_ETHTOOL_ULONG_MAC_STAT(tx_mac_src_error),
  108. EFX_ETHTOOL_ULONG_MAC_STAT(tx_ip_src_error),
  109. EFX_ETHTOOL_UINT_TXQ_STAT(tso_bursts),
  110. EFX_ETHTOOL_UINT_TXQ_STAT(tso_long_headers),
  111. EFX_ETHTOOL_UINT_TXQ_STAT(tso_packets),
  112. EFX_ETHTOOL_UINT_TXQ_STAT(pushes),
  113. EFX_ETHTOOL_U64_MAC_STAT(rx_bytes),
  114. EFX_ETHTOOL_U64_MAC_STAT(rx_good_bytes),
  115. EFX_ETHTOOL_U64_MAC_STAT(rx_bad_bytes),
  116. EFX_ETHTOOL_ULONG_MAC_STAT(rx_packets),
  117. EFX_ETHTOOL_ULONG_MAC_STAT(rx_good),
  118. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad),
  119. EFX_ETHTOOL_ULONG_MAC_STAT(rx_pause),
  120. EFX_ETHTOOL_ULONG_MAC_STAT(rx_control),
  121. EFX_ETHTOOL_ULONG_MAC_STAT(rx_unicast),
  122. EFX_ETHTOOL_ULONG_MAC_STAT(rx_multicast),
  123. EFX_ETHTOOL_ULONG_MAC_STAT(rx_broadcast),
  124. EFX_ETHTOOL_ULONG_MAC_STAT(rx_lt64),
  125. EFX_ETHTOOL_ULONG_MAC_STAT(rx_64),
  126. EFX_ETHTOOL_ULONG_MAC_STAT(rx_65_to_127),
  127. EFX_ETHTOOL_ULONG_MAC_STAT(rx_128_to_255),
  128. EFX_ETHTOOL_ULONG_MAC_STAT(rx_256_to_511),
  129. EFX_ETHTOOL_ULONG_MAC_STAT(rx_512_to_1023),
  130. EFX_ETHTOOL_ULONG_MAC_STAT(rx_1024_to_15xx),
  131. EFX_ETHTOOL_ULONG_MAC_STAT(rx_15xx_to_jumbo),
  132. EFX_ETHTOOL_ULONG_MAC_STAT(rx_gtjumbo),
  133. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_lt64),
  134. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_64_to_15xx),
  135. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_15xx_to_jumbo),
  136. EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_gtjumbo),
  137. EFX_ETHTOOL_ULONG_MAC_STAT(rx_overflow),
  138. EFX_ETHTOOL_ULONG_MAC_STAT(rx_missed),
  139. EFX_ETHTOOL_ULONG_MAC_STAT(rx_false_carrier),
  140. EFX_ETHTOOL_ULONG_MAC_STAT(rx_symbol_error),
  141. EFX_ETHTOOL_ULONG_MAC_STAT(rx_align_error),
  142. EFX_ETHTOOL_ULONG_MAC_STAT(rx_length_error),
  143. EFX_ETHTOOL_ULONG_MAC_STAT(rx_internal_error),
  144. EFX_ETHTOOL_UINT_NIC_STAT(rx_nodesc_drop_cnt),
  145. EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset),
  146. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc),
  147. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),
  148. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err),
  149. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch),
  150. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
  151. };
  152. /* Number of ethtool statistics */
  153. #define EFX_ETHTOOL_NUM_STATS ARRAY_SIZE(efx_ethtool_stats)
  154. #define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB
  155. /**************************************************************************
  156. *
  157. * Ethtool operations
  158. *
  159. **************************************************************************
  160. */
  161. /* Identify device by flashing LEDs */
  162. static int efx_ethtool_phys_id(struct net_device *net_dev,
  163. enum ethtool_phys_id_state state)
  164. {
  165. struct efx_nic *efx = netdev_priv(net_dev);
  166. enum efx_led_mode mode = EFX_LED_DEFAULT;
  167. switch (state) {
  168. case ETHTOOL_ID_ON:
  169. mode = EFX_LED_ON;
  170. break;
  171. case ETHTOOL_ID_OFF:
  172. mode = EFX_LED_OFF;
  173. break;
  174. case ETHTOOL_ID_INACTIVE:
  175. mode = EFX_LED_DEFAULT;
  176. break;
  177. case ETHTOOL_ID_ACTIVE:
  178. return 1; /* cycle on/off once per second */
  179. }
  180. efx->type->set_id_led(efx, mode);
  181. return 0;
  182. }
  183. /* This must be called with rtnl_lock held. */
  184. static int efx_ethtool_get_settings(struct net_device *net_dev,
  185. struct ethtool_cmd *ecmd)
  186. {
  187. struct efx_nic *efx = netdev_priv(net_dev);
  188. struct efx_link_state *link_state = &efx->link_state;
  189. mutex_lock(&efx->mac_lock);
  190. efx->phy_op->get_settings(efx, ecmd);
  191. mutex_unlock(&efx->mac_lock);
  192. /* GMAC does not support 1000Mbps HD */
  193. ecmd->supported &= ~SUPPORTED_1000baseT_Half;
  194. /* Both MACs support pause frames (bidirectional and respond-only) */
  195. ecmd->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
  196. if (LOOPBACK_INTERNAL(efx)) {
  197. ethtool_cmd_speed_set(ecmd, link_state->speed);
  198. ecmd->duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF;
  199. }
  200. return 0;
  201. }
  202. /* This must be called with rtnl_lock held. */
  203. static int efx_ethtool_set_settings(struct net_device *net_dev,
  204. struct ethtool_cmd *ecmd)
  205. {
  206. struct efx_nic *efx = netdev_priv(net_dev);
  207. int rc;
  208. /* GMAC does not support 1000Mbps HD */
  209. if ((ethtool_cmd_speed(ecmd) == SPEED_1000) &&
  210. (ecmd->duplex != DUPLEX_FULL)) {
  211. netif_dbg(efx, drv, efx->net_dev,
  212. "rejecting unsupported 1000Mbps HD setting\n");
  213. return -EINVAL;
  214. }
  215. mutex_lock(&efx->mac_lock);
  216. rc = efx->phy_op->set_settings(efx, ecmd);
  217. mutex_unlock(&efx->mac_lock);
  218. return rc;
  219. }
  220. static void efx_ethtool_get_drvinfo(struct net_device *net_dev,
  221. struct ethtool_drvinfo *info)
  222. {
  223. struct efx_nic *efx = netdev_priv(net_dev);
  224. strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
  225. strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version));
  226. if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0)
  227. efx_mcdi_print_fwver(efx, info->fw_version,
  228. sizeof(info->fw_version));
  229. strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
  230. }
  231. static int efx_ethtool_get_regs_len(struct net_device *net_dev)
  232. {
  233. return efx_nic_get_regs_len(netdev_priv(net_dev));
  234. }
  235. static void efx_ethtool_get_regs(struct net_device *net_dev,
  236. struct ethtool_regs *regs, void *buf)
  237. {
  238. struct efx_nic *efx = netdev_priv(net_dev);
  239. regs->version = efx->type->revision;
  240. efx_nic_get_regs(efx, buf);
  241. }
  242. static u32 efx_ethtool_get_msglevel(struct net_device *net_dev)
  243. {
  244. struct efx_nic *efx = netdev_priv(net_dev);
  245. return efx->msg_enable;
  246. }
  247. static void efx_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable)
  248. {
  249. struct efx_nic *efx = netdev_priv(net_dev);
  250. efx->msg_enable = msg_enable;
  251. }
  252. /**
  253. * efx_fill_test - fill in an individual self-test entry
  254. * @test_index: Index of the test
  255. * @strings: Ethtool strings, or %NULL
  256. * @data: Ethtool test results, or %NULL
  257. * @test: Pointer to test result (used only if data != %NULL)
  258. * @unit_format: Unit name format (e.g. "chan\%d")
  259. * @unit_id: Unit id (e.g. 0 for "chan0")
  260. * @test_format: Test name format (e.g. "loopback.\%s.tx.sent")
  261. * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
  262. *
  263. * Fill in an individual self-test entry.
  264. */
  265. static void efx_fill_test(unsigned int test_index,
  266. struct ethtool_string *strings, u64 *data,
  267. int *test, const char *unit_format, int unit_id,
  268. const char *test_format, const char *test_id)
  269. {
  270. struct ethtool_string unit_str, test_str;
  271. /* Fill data value, if applicable */
  272. if (data)
  273. data[test_index] = *test;
  274. /* Fill string, if applicable */
  275. if (strings) {
  276. if (strchr(unit_format, '%'))
  277. snprintf(unit_str.name, sizeof(unit_str.name),
  278. unit_format, unit_id);
  279. else
  280. strcpy(unit_str.name, unit_format);
  281. snprintf(test_str.name, sizeof(test_str.name),
  282. test_format, test_id);
  283. snprintf(strings[test_index].name,
  284. sizeof(strings[test_index].name),
  285. "%-6s %-24s", unit_str.name, test_str.name);
  286. }
  287. }
  288. #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
  289. #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
  290. #define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
  291. #define EFX_LOOPBACK_NAME(_mode, _counter) \
  292. "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode)
  293. /**
  294. * efx_fill_loopback_test - fill in a block of loopback self-test entries
  295. * @efx: Efx NIC
  296. * @lb_tests: Efx loopback self-test results structure
  297. * @mode: Loopback test mode
  298. * @test_index: Starting index of the test
  299. * @strings: Ethtool strings, or %NULL
  300. * @data: Ethtool test results, or %NULL
  301. */
  302. static int efx_fill_loopback_test(struct efx_nic *efx,
  303. struct efx_loopback_self_tests *lb_tests,
  304. enum efx_loopback_mode mode,
  305. unsigned int test_index,
  306. struct ethtool_string *strings, u64 *data)
  307. {
  308. struct efx_channel *channel = efx_get_channel(efx, 0);
  309. struct efx_tx_queue *tx_queue;
  310. efx_for_each_channel_tx_queue(tx_queue, channel) {
  311. efx_fill_test(test_index++, strings, data,
  312. &lb_tests->tx_sent[tx_queue->queue],
  313. EFX_TX_QUEUE_NAME(tx_queue),
  314. EFX_LOOPBACK_NAME(mode, "tx_sent"));
  315. efx_fill_test(test_index++, strings, data,
  316. &lb_tests->tx_done[tx_queue->queue],
  317. EFX_TX_QUEUE_NAME(tx_queue),
  318. EFX_LOOPBACK_NAME(mode, "tx_done"));
  319. }
  320. efx_fill_test(test_index++, strings, data,
  321. &lb_tests->rx_good,
  322. "rx", 0,
  323. EFX_LOOPBACK_NAME(mode, "rx_good"));
  324. efx_fill_test(test_index++, strings, data,
  325. &lb_tests->rx_bad,
  326. "rx", 0,
  327. EFX_LOOPBACK_NAME(mode, "rx_bad"));
  328. return test_index;
  329. }
  330. /**
  331. * efx_ethtool_fill_self_tests - get self-test details
  332. * @efx: Efx NIC
  333. * @tests: Efx self-test results structure, or %NULL
  334. * @strings: Ethtool strings, or %NULL
  335. * @data: Ethtool test results, or %NULL
  336. */
  337. static int efx_ethtool_fill_self_tests(struct efx_nic *efx,
  338. struct efx_self_tests *tests,
  339. struct ethtool_string *strings,
  340. u64 *data)
  341. {
  342. struct efx_channel *channel;
  343. unsigned int n = 0, i;
  344. enum efx_loopback_mode mode;
  345. efx_fill_test(n++, strings, data, &tests->phy_alive,
  346. "phy", 0, "alive", NULL);
  347. efx_fill_test(n++, strings, data, &tests->nvram,
  348. "core", 0, "nvram", NULL);
  349. efx_fill_test(n++, strings, data, &tests->interrupt,
  350. "core", 0, "interrupt", NULL);
  351. /* Event queues */
  352. efx_for_each_channel(channel, efx) {
  353. efx_fill_test(n++, strings, data,
  354. &tests->eventq_dma[channel->channel],
  355. EFX_CHANNEL_NAME(channel),
  356. "eventq.dma", NULL);
  357. efx_fill_test(n++, strings, data,
  358. &tests->eventq_int[channel->channel],
  359. EFX_CHANNEL_NAME(channel),
  360. "eventq.int", NULL);
  361. efx_fill_test(n++, strings, data,
  362. &tests->eventq_poll[channel->channel],
  363. EFX_CHANNEL_NAME(channel),
  364. "eventq.poll", NULL);
  365. }
  366. efx_fill_test(n++, strings, data, &tests->registers,
  367. "core", 0, "registers", NULL);
  368. if (efx->phy_op->run_tests != NULL) {
  369. EFX_BUG_ON_PARANOID(efx->phy_op->test_name == NULL);
  370. for (i = 0; true; ++i) {
  371. const char *name;
  372. EFX_BUG_ON_PARANOID(i >= EFX_MAX_PHY_TESTS);
  373. name = efx->phy_op->test_name(efx, i);
  374. if (name == NULL)
  375. break;
  376. efx_fill_test(n++, strings, data, &tests->phy_ext[i],
  377. "phy", 0, name, NULL);
  378. }
  379. }
  380. /* Loopback tests */
  381. for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
  382. if (!(efx->loopback_modes & (1 << mode)))
  383. continue;
  384. n = efx_fill_loopback_test(efx,
  385. &tests->loopback[mode], mode, n,
  386. strings, data);
  387. }
  388. return n;
  389. }
  390. static int efx_ethtool_get_sset_count(struct net_device *net_dev,
  391. int string_set)
  392. {
  393. switch (string_set) {
  394. case ETH_SS_STATS:
  395. return EFX_ETHTOOL_NUM_STATS;
  396. case ETH_SS_TEST:
  397. return efx_ethtool_fill_self_tests(netdev_priv(net_dev),
  398. NULL, NULL, NULL);
  399. default:
  400. return -EINVAL;
  401. }
  402. }
  403. static void efx_ethtool_get_strings(struct net_device *net_dev,
  404. u32 string_set, u8 *strings)
  405. {
  406. struct efx_nic *efx = netdev_priv(net_dev);
  407. struct ethtool_string *ethtool_strings =
  408. (struct ethtool_string *)strings;
  409. int i;
  410. switch (string_set) {
  411. case ETH_SS_STATS:
  412. for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++)
  413. strncpy(ethtool_strings[i].name,
  414. efx_ethtool_stats[i].name,
  415. sizeof(ethtool_strings[i].name));
  416. break;
  417. case ETH_SS_TEST:
  418. efx_ethtool_fill_self_tests(efx, NULL,
  419. ethtool_strings, NULL);
  420. break;
  421. default:
  422. /* No other string sets */
  423. break;
  424. }
  425. }
  426. static void efx_ethtool_get_stats(struct net_device *net_dev,
  427. struct ethtool_stats *stats,
  428. u64 *data)
  429. {
  430. struct efx_nic *efx = netdev_priv(net_dev);
  431. struct efx_mac_stats *mac_stats = &efx->mac_stats;
  432. struct efx_ethtool_stat *stat;
  433. struct efx_channel *channel;
  434. struct efx_tx_queue *tx_queue;
  435. struct rtnl_link_stats64 temp;
  436. int i;
  437. EFX_BUG_ON_PARANOID(stats->n_stats != EFX_ETHTOOL_NUM_STATS);
  438. /* Update MAC and NIC statistics */
  439. dev_get_stats(net_dev, &temp);
  440. /* Fill detailed statistics buffer */
  441. for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++) {
  442. stat = &efx_ethtool_stats[i];
  443. switch (stat->source) {
  444. case EFX_ETHTOOL_STAT_SOURCE_mac_stats:
  445. data[i] = stat->get_stat((void *)mac_stats +
  446. stat->offset);
  447. break;
  448. case EFX_ETHTOOL_STAT_SOURCE_nic:
  449. data[i] = stat->get_stat((void *)efx + stat->offset);
  450. break;
  451. case EFX_ETHTOOL_STAT_SOURCE_channel:
  452. data[i] = 0;
  453. efx_for_each_channel(channel, efx)
  454. data[i] += stat->get_stat((void *)channel +
  455. stat->offset);
  456. break;
  457. case EFX_ETHTOOL_STAT_SOURCE_tx_queue:
  458. data[i] = 0;
  459. efx_for_each_channel(channel, efx) {
  460. efx_for_each_channel_tx_queue(tx_queue, channel)
  461. data[i] +=
  462. stat->get_stat((void *)tx_queue
  463. + stat->offset);
  464. }
  465. break;
  466. }
  467. }
  468. }
  469. static void efx_ethtool_self_test(struct net_device *net_dev,
  470. struct ethtool_test *test, u64 *data)
  471. {
  472. struct efx_nic *efx = netdev_priv(net_dev);
  473. struct efx_self_tests *efx_tests;
  474. int already_up;
  475. int rc = -ENOMEM;
  476. efx_tests = kzalloc(sizeof(*efx_tests), GFP_KERNEL);
  477. if (!efx_tests)
  478. goto fail;
  479. ASSERT_RTNL();
  480. if (efx->state != STATE_RUNNING) {
  481. rc = -EIO;
  482. goto fail1;
  483. }
  484. netif_info(efx, drv, efx->net_dev, "starting %sline testing\n",
  485. (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
  486. /* We need rx buffers and interrupts. */
  487. already_up = (efx->net_dev->flags & IFF_UP);
  488. if (!already_up) {
  489. rc = dev_open(efx->net_dev);
  490. if (rc) {
  491. netif_err(efx, drv, efx->net_dev,
  492. "failed opening device.\n");
  493. goto fail1;
  494. }
  495. }
  496. rc = efx_selftest(efx, efx_tests, test->flags);
  497. if (!already_up)
  498. dev_close(efx->net_dev);
  499. netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n",
  500. rc == 0 ? "passed" : "failed",
  501. (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
  502. fail1:
  503. /* Fill ethtool results structures */
  504. efx_ethtool_fill_self_tests(efx, efx_tests, NULL, data);
  505. kfree(efx_tests);
  506. fail:
  507. if (rc)
  508. test->flags |= ETH_TEST_FL_FAILED;
  509. }
  510. /* Restart autonegotiation */
  511. static int efx_ethtool_nway_reset(struct net_device *net_dev)
  512. {
  513. struct efx_nic *efx = netdev_priv(net_dev);
  514. return mdio45_nway_restart(&efx->mdio);
  515. }
  516. static int efx_ethtool_get_coalesce(struct net_device *net_dev,
  517. struct ethtool_coalesce *coalesce)
  518. {
  519. struct efx_nic *efx = netdev_priv(net_dev);
  520. struct efx_channel *channel;
  521. memset(coalesce, 0, sizeof(*coalesce));
  522. /* Find lowest IRQ moderation across all used TX queues */
  523. coalesce->tx_coalesce_usecs_irq = ~((u32) 0);
  524. efx_for_each_channel(channel, efx) {
  525. if (!efx_channel_has_tx_queues(channel))
  526. continue;
  527. if (channel->irq_moderation < coalesce->tx_coalesce_usecs_irq) {
  528. if (channel->channel < efx->n_rx_channels)
  529. coalesce->tx_coalesce_usecs_irq =
  530. channel->irq_moderation;
  531. else
  532. coalesce->tx_coalesce_usecs_irq = 0;
  533. }
  534. }
  535. coalesce->use_adaptive_rx_coalesce = efx->irq_rx_adaptive;
  536. coalesce->rx_coalesce_usecs_irq = efx->irq_rx_moderation;
  537. coalesce->tx_coalesce_usecs_irq *= EFX_IRQ_MOD_RESOLUTION;
  538. coalesce->rx_coalesce_usecs_irq *= EFX_IRQ_MOD_RESOLUTION;
  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. unsigned int tx_usecs, rx_usecs;
  550. bool adaptive;
  551. if (coalesce->use_adaptive_tx_coalesce)
  552. return -EINVAL;
  553. if (coalesce->rx_coalesce_usecs || coalesce->tx_coalesce_usecs) {
  554. netif_err(efx, drv, efx->net_dev, "invalid coalescing setting. "
  555. "Only rx/tx_coalesce_usecs_irq are supported\n");
  556. return -EINVAL;
  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_channel(channel, efx) {
  563. if (efx_channel_has_rx_queue(channel) &&
  564. efx_channel_has_tx_queues(channel) &&
  565. tx_usecs) {
  566. netif_err(efx, drv, efx->net_dev, "Channel is shared. "
  567. "Only RX coalescing may be set\n");
  568. return -EINVAL;
  569. }
  570. }
  571. efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive);
  572. efx_for_each_channel(channel, efx)
  573. efx->type->push_irq_moderation(channel);
  574. return 0;
  575. }
  576. static void efx_ethtool_get_ringparam(struct net_device *net_dev,
  577. struct ethtool_ringparam *ring)
  578. {
  579. struct efx_nic *efx = netdev_priv(net_dev);
  580. ring->rx_max_pending = EFX_MAX_DMAQ_SIZE;
  581. ring->tx_max_pending = EFX_MAX_DMAQ_SIZE;
  582. ring->rx_mini_max_pending = 0;
  583. ring->rx_jumbo_max_pending = 0;
  584. ring->rx_pending = efx->rxq_entries;
  585. ring->tx_pending = efx->txq_entries;
  586. ring->rx_mini_pending = 0;
  587. ring->rx_jumbo_pending = 0;
  588. }
  589. static int efx_ethtool_set_ringparam(struct net_device *net_dev,
  590. struct ethtool_ringparam *ring)
  591. {
  592. struct efx_nic *efx = netdev_priv(net_dev);
  593. if (ring->rx_mini_pending || ring->rx_jumbo_pending ||
  594. ring->rx_pending > EFX_MAX_DMAQ_SIZE ||
  595. ring->tx_pending > EFX_MAX_DMAQ_SIZE)
  596. return -EINVAL;
  597. if (ring->rx_pending < EFX_MIN_RING_SIZE ||
  598. ring->tx_pending < EFX_MIN_RING_SIZE) {
  599. netif_err(efx, drv, efx->net_dev,
  600. "TX and RX queues cannot be smaller than %ld\n",
  601. EFX_MIN_RING_SIZE);
  602. return -EINVAL;
  603. }
  604. return efx_realloc_channels(efx, ring->rx_pending, ring->tx_pending);
  605. }
  606. static int efx_ethtool_set_pauseparam(struct net_device *net_dev,
  607. struct ethtool_pauseparam *pause)
  608. {
  609. struct efx_nic *efx = netdev_priv(net_dev);
  610. u8 wanted_fc, old_fc;
  611. u32 old_adv;
  612. bool reset;
  613. int rc = 0;
  614. mutex_lock(&efx->mac_lock);
  615. wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
  616. (pause->tx_pause ? EFX_FC_TX : 0) |
  617. (pause->autoneg ? EFX_FC_AUTO : 0));
  618. if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
  619. netif_dbg(efx, drv, efx->net_dev,
  620. "Flow control unsupported: tx ON rx OFF\n");
  621. rc = -EINVAL;
  622. goto out;
  623. }
  624. if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising) {
  625. netif_dbg(efx, drv, efx->net_dev,
  626. "Autonegotiation is disabled\n");
  627. rc = -EINVAL;
  628. goto out;
  629. }
  630. /* TX flow control may automatically turn itself off if the
  631. * link partner (intermittently) stops responding to pause
  632. * frames. There isn't any indication that this has happened,
  633. * so the best we do is leave it up to the user to spot this
  634. * and fix it be cycling transmit flow control on this end. */
  635. reset = (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX);
  636. if (EFX_WORKAROUND_11482(efx) && reset) {
  637. if (efx_nic_rev(efx) == EFX_REV_FALCON_B0) {
  638. /* Recover by resetting the EM block */
  639. falcon_stop_nic_stats(efx);
  640. falcon_drain_tx_fifo(efx);
  641. efx->mac_op->reconfigure(efx);
  642. falcon_start_nic_stats(efx);
  643. } else {
  644. /* Schedule a reset to recover */
  645. efx_schedule_reset(efx, RESET_TYPE_INVISIBLE);
  646. }
  647. }
  648. old_adv = efx->link_advertising;
  649. old_fc = efx->wanted_fc;
  650. efx_link_set_wanted_fc(efx, wanted_fc);
  651. if (efx->link_advertising != old_adv ||
  652. (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) {
  653. rc = efx->phy_op->reconfigure(efx);
  654. if (rc) {
  655. netif_err(efx, drv, efx->net_dev,
  656. "Unable to advertise requested flow "
  657. "control setting\n");
  658. goto out;
  659. }
  660. }
  661. /* Reconfigure the MAC. The PHY *may* generate a link state change event
  662. * if the user just changed the advertised capabilities, but there's no
  663. * harm doing this twice */
  664. efx->mac_op->reconfigure(efx);
  665. out:
  666. mutex_unlock(&efx->mac_lock);
  667. return rc;
  668. }
  669. static void efx_ethtool_get_pauseparam(struct net_device *net_dev,
  670. struct ethtool_pauseparam *pause)
  671. {
  672. struct efx_nic *efx = netdev_priv(net_dev);
  673. pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX);
  674. pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX);
  675. pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO);
  676. }
  677. static void efx_ethtool_get_wol(struct net_device *net_dev,
  678. struct ethtool_wolinfo *wol)
  679. {
  680. struct efx_nic *efx = netdev_priv(net_dev);
  681. return efx->type->get_wol(efx, wol);
  682. }
  683. static int efx_ethtool_set_wol(struct net_device *net_dev,
  684. struct ethtool_wolinfo *wol)
  685. {
  686. struct efx_nic *efx = netdev_priv(net_dev);
  687. return efx->type->set_wol(efx, wol->wolopts);
  688. }
  689. static int efx_ethtool_reset(struct net_device *net_dev, u32 *flags)
  690. {
  691. struct efx_nic *efx = netdev_priv(net_dev);
  692. int rc;
  693. rc = efx->type->map_reset_flags(flags);
  694. if (rc < 0)
  695. return rc;
  696. return efx_reset(efx, rc);
  697. }
  698. static int
  699. efx_ethtool_get_rxnfc(struct net_device *net_dev,
  700. struct ethtool_rxnfc *info, void *rules __always_unused)
  701. {
  702. struct efx_nic *efx = netdev_priv(net_dev);
  703. switch (info->cmd) {
  704. case ETHTOOL_GRXRINGS:
  705. info->data = efx->n_rx_channels;
  706. return 0;
  707. case ETHTOOL_GRXFH: {
  708. unsigned min_revision = 0;
  709. info->data = 0;
  710. switch (info->flow_type) {
  711. case TCP_V4_FLOW:
  712. info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  713. /* fall through */
  714. case UDP_V4_FLOW:
  715. case SCTP_V4_FLOW:
  716. case AH_ESP_V4_FLOW:
  717. case IPV4_FLOW:
  718. info->data |= RXH_IP_SRC | RXH_IP_DST;
  719. min_revision = EFX_REV_FALCON_B0;
  720. break;
  721. case TCP_V6_FLOW:
  722. info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  723. /* fall through */
  724. case UDP_V6_FLOW:
  725. case SCTP_V6_FLOW:
  726. case AH_ESP_V6_FLOW:
  727. case IPV6_FLOW:
  728. info->data |= RXH_IP_SRC | RXH_IP_DST;
  729. min_revision = EFX_REV_SIENA_A0;
  730. break;
  731. default:
  732. break;
  733. }
  734. if (efx_nic_rev(efx) < min_revision)
  735. info->data = 0;
  736. return 0;
  737. }
  738. default:
  739. return -EOPNOTSUPP;
  740. }
  741. }
  742. static int efx_ethtool_set_rx_ntuple(struct net_device *net_dev,
  743. struct ethtool_rx_ntuple *ntuple)
  744. {
  745. struct efx_nic *efx = netdev_priv(net_dev);
  746. struct ethtool_tcpip4_spec *ip_entry = &ntuple->fs.h_u.tcp_ip4_spec;
  747. struct ethtool_tcpip4_spec *ip_mask = &ntuple->fs.m_u.tcp_ip4_spec;
  748. struct ethhdr *mac_entry = &ntuple->fs.h_u.ether_spec;
  749. struct ethhdr *mac_mask = &ntuple->fs.m_u.ether_spec;
  750. struct efx_filter_spec filter;
  751. int rc;
  752. /* Range-check action */
  753. if (ntuple->fs.action < ETHTOOL_RXNTUPLE_ACTION_CLEAR ||
  754. ntuple->fs.action >= (s32)efx->n_rx_channels)
  755. return -EINVAL;
  756. if (~ntuple->fs.data_mask)
  757. return -EINVAL;
  758. efx_filter_init_rx(&filter, EFX_FILTER_PRI_MANUAL, 0,
  759. (ntuple->fs.action == ETHTOOL_RXNTUPLE_ACTION_DROP) ?
  760. 0xfff : ntuple->fs.action);
  761. switch (ntuple->fs.flow_type) {
  762. case TCP_V4_FLOW:
  763. case UDP_V4_FLOW: {
  764. u8 proto = (ntuple->fs.flow_type == TCP_V4_FLOW ?
  765. IPPROTO_TCP : IPPROTO_UDP);
  766. /* Must match all of destination, */
  767. if (ip_mask->ip4dst | ip_mask->pdst)
  768. return -EINVAL;
  769. /* all or none of source, */
  770. if ((ip_mask->ip4src | ip_mask->psrc) &&
  771. ((__force u32)~ip_mask->ip4src |
  772. (__force u16)~ip_mask->psrc))
  773. return -EINVAL;
  774. /* and nothing else */
  775. if ((u8)~ip_mask->tos | (u16)~ntuple->fs.vlan_tag_mask)
  776. return -EINVAL;
  777. if (!ip_mask->ip4src)
  778. rc = efx_filter_set_ipv4_full(&filter, proto,
  779. ip_entry->ip4dst,
  780. ip_entry->pdst,
  781. ip_entry->ip4src,
  782. ip_entry->psrc);
  783. else
  784. rc = efx_filter_set_ipv4_local(&filter, proto,
  785. ip_entry->ip4dst,
  786. ip_entry->pdst);
  787. if (rc)
  788. return rc;
  789. break;
  790. }
  791. case ETHER_FLOW:
  792. /* Must match all of destination, */
  793. if (!is_zero_ether_addr(mac_mask->h_dest))
  794. return -EINVAL;
  795. /* all or none of VID, */
  796. if (ntuple->fs.vlan_tag_mask != 0xf000 &&
  797. ntuple->fs.vlan_tag_mask != 0xffff)
  798. return -EINVAL;
  799. /* and nothing else */
  800. if (!is_broadcast_ether_addr(mac_mask->h_source) ||
  801. mac_mask->h_proto != htons(0xffff))
  802. return -EINVAL;
  803. rc = efx_filter_set_eth_local(
  804. &filter,
  805. (ntuple->fs.vlan_tag_mask == 0xf000) ?
  806. ntuple->fs.vlan_tag : EFX_FILTER_VID_UNSPEC,
  807. mac_entry->h_dest);
  808. if (rc)
  809. return rc;
  810. break;
  811. default:
  812. return -EINVAL;
  813. }
  814. if (ntuple->fs.action == ETHTOOL_RXNTUPLE_ACTION_CLEAR)
  815. return efx_filter_remove_filter(efx, &filter);
  816. rc = efx_filter_insert_filter(efx, &filter, true);
  817. return rc < 0 ? rc : 0;
  818. }
  819. static int efx_ethtool_get_rxfh_indir(struct net_device *net_dev,
  820. struct ethtool_rxfh_indir *indir)
  821. {
  822. struct efx_nic *efx = netdev_priv(net_dev);
  823. size_t copy_size =
  824. min_t(size_t, indir->size, ARRAY_SIZE(efx->rx_indir_table));
  825. if (efx_nic_rev(efx) < EFX_REV_FALCON_B0)
  826. return -EOPNOTSUPP;
  827. indir->size = ARRAY_SIZE(efx->rx_indir_table);
  828. memcpy(indir->ring_index, efx->rx_indir_table,
  829. copy_size * sizeof(indir->ring_index[0]));
  830. return 0;
  831. }
  832. static int efx_ethtool_set_rxfh_indir(struct net_device *net_dev,
  833. const struct ethtool_rxfh_indir *indir)
  834. {
  835. struct efx_nic *efx = netdev_priv(net_dev);
  836. size_t i;
  837. if (efx_nic_rev(efx) < EFX_REV_FALCON_B0)
  838. return -EOPNOTSUPP;
  839. /* Validate size and indices */
  840. if (indir->size != ARRAY_SIZE(efx->rx_indir_table))
  841. return -EINVAL;
  842. for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); i++)
  843. if (indir->ring_index[i] >= efx->n_rx_channels)
  844. return -EINVAL;
  845. memcpy(efx->rx_indir_table, indir->ring_index,
  846. sizeof(efx->rx_indir_table));
  847. efx_nic_push_rx_indir_table(efx);
  848. return 0;
  849. }
  850. const struct ethtool_ops efx_ethtool_ops = {
  851. .get_settings = efx_ethtool_get_settings,
  852. .set_settings = efx_ethtool_set_settings,
  853. .get_drvinfo = efx_ethtool_get_drvinfo,
  854. .get_regs_len = efx_ethtool_get_regs_len,
  855. .get_regs = efx_ethtool_get_regs,
  856. .get_msglevel = efx_ethtool_get_msglevel,
  857. .set_msglevel = efx_ethtool_set_msglevel,
  858. .nway_reset = efx_ethtool_nway_reset,
  859. .get_link = ethtool_op_get_link,
  860. .get_coalesce = efx_ethtool_get_coalesce,
  861. .set_coalesce = efx_ethtool_set_coalesce,
  862. .get_ringparam = efx_ethtool_get_ringparam,
  863. .set_ringparam = efx_ethtool_set_ringparam,
  864. .get_pauseparam = efx_ethtool_get_pauseparam,
  865. .set_pauseparam = efx_ethtool_set_pauseparam,
  866. .get_sset_count = efx_ethtool_get_sset_count,
  867. .self_test = efx_ethtool_self_test,
  868. .get_strings = efx_ethtool_get_strings,
  869. .set_phys_id = efx_ethtool_phys_id,
  870. .get_ethtool_stats = efx_ethtool_get_stats,
  871. .get_wol = efx_ethtool_get_wol,
  872. .set_wol = efx_ethtool_set_wol,
  873. .reset = efx_ethtool_reset,
  874. .get_rxnfc = efx_ethtool_get_rxnfc,
  875. .set_rx_ntuple = efx_ethtool_set_rx_ntuple,
  876. .get_rxfh_indir = efx_ethtool_get_rxfh_indir,
  877. .set_rxfh_indir = efx_ethtool_set_rxfh_indir,
  878. };