ethtool.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175
  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_u64_stat(void *field)
  50. {
  51. return *(u64 *) field;
  52. }
  53. static u64 efx_get_atomic_stat(void *field)
  54. {
  55. return atomic_read((atomic_t *) field);
  56. }
  57. #define EFX_ETHTOOL_U64_MAC_STAT(field) \
  58. EFX_ETHTOOL_STAT(field, mac_stats, field, \
  59. u64, efx_get_u64_stat)
  60. #define EFX_ETHTOOL_UINT_NIC_STAT(name) \
  61. EFX_ETHTOOL_STAT(name, nic, n_##name, \
  62. unsigned int, efx_get_uint_stat)
  63. #define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field) \
  64. EFX_ETHTOOL_STAT(field, nic, field, \
  65. atomic_t, efx_get_atomic_stat)
  66. #define EFX_ETHTOOL_UINT_CHANNEL_STAT(field) \
  67. EFX_ETHTOOL_STAT(field, channel, n_##field, \
  68. unsigned int, efx_get_uint_stat)
  69. #define EFX_ETHTOOL_UINT_TXQ_STAT(field) \
  70. EFX_ETHTOOL_STAT(tx_##field, tx_queue, field, \
  71. unsigned int, efx_get_uint_stat)
  72. static const struct efx_ethtool_stat efx_ethtool_stats[] = {
  73. EFX_ETHTOOL_U64_MAC_STAT(tx_bytes),
  74. EFX_ETHTOOL_U64_MAC_STAT(tx_good_bytes),
  75. EFX_ETHTOOL_U64_MAC_STAT(tx_bad_bytes),
  76. EFX_ETHTOOL_U64_MAC_STAT(tx_packets),
  77. EFX_ETHTOOL_U64_MAC_STAT(tx_bad),
  78. EFX_ETHTOOL_U64_MAC_STAT(tx_pause),
  79. EFX_ETHTOOL_U64_MAC_STAT(tx_control),
  80. EFX_ETHTOOL_U64_MAC_STAT(tx_unicast),
  81. EFX_ETHTOOL_U64_MAC_STAT(tx_multicast),
  82. EFX_ETHTOOL_U64_MAC_STAT(tx_broadcast),
  83. EFX_ETHTOOL_U64_MAC_STAT(tx_lt64),
  84. EFX_ETHTOOL_U64_MAC_STAT(tx_64),
  85. EFX_ETHTOOL_U64_MAC_STAT(tx_65_to_127),
  86. EFX_ETHTOOL_U64_MAC_STAT(tx_128_to_255),
  87. EFX_ETHTOOL_U64_MAC_STAT(tx_256_to_511),
  88. EFX_ETHTOOL_U64_MAC_STAT(tx_512_to_1023),
  89. EFX_ETHTOOL_U64_MAC_STAT(tx_1024_to_15xx),
  90. EFX_ETHTOOL_U64_MAC_STAT(tx_15xx_to_jumbo),
  91. EFX_ETHTOOL_U64_MAC_STAT(tx_gtjumbo),
  92. EFX_ETHTOOL_U64_MAC_STAT(tx_collision),
  93. EFX_ETHTOOL_U64_MAC_STAT(tx_single_collision),
  94. EFX_ETHTOOL_U64_MAC_STAT(tx_multiple_collision),
  95. EFX_ETHTOOL_U64_MAC_STAT(tx_excessive_collision),
  96. EFX_ETHTOOL_U64_MAC_STAT(tx_deferred),
  97. EFX_ETHTOOL_U64_MAC_STAT(tx_late_collision),
  98. EFX_ETHTOOL_U64_MAC_STAT(tx_excessive_deferred),
  99. EFX_ETHTOOL_U64_MAC_STAT(tx_non_tcpudp),
  100. EFX_ETHTOOL_U64_MAC_STAT(tx_mac_src_error),
  101. EFX_ETHTOOL_U64_MAC_STAT(tx_ip_src_error),
  102. EFX_ETHTOOL_UINT_TXQ_STAT(tso_bursts),
  103. EFX_ETHTOOL_UINT_TXQ_STAT(tso_long_headers),
  104. EFX_ETHTOOL_UINT_TXQ_STAT(tso_packets),
  105. EFX_ETHTOOL_UINT_TXQ_STAT(pushes),
  106. EFX_ETHTOOL_U64_MAC_STAT(rx_bytes),
  107. EFX_ETHTOOL_U64_MAC_STAT(rx_good_bytes),
  108. EFX_ETHTOOL_U64_MAC_STAT(rx_bad_bytes),
  109. EFX_ETHTOOL_U64_MAC_STAT(rx_packets),
  110. EFX_ETHTOOL_U64_MAC_STAT(rx_good),
  111. EFX_ETHTOOL_U64_MAC_STAT(rx_bad),
  112. EFX_ETHTOOL_U64_MAC_STAT(rx_pause),
  113. EFX_ETHTOOL_U64_MAC_STAT(rx_control),
  114. EFX_ETHTOOL_U64_MAC_STAT(rx_unicast),
  115. EFX_ETHTOOL_U64_MAC_STAT(rx_multicast),
  116. EFX_ETHTOOL_U64_MAC_STAT(rx_broadcast),
  117. EFX_ETHTOOL_U64_MAC_STAT(rx_lt64),
  118. EFX_ETHTOOL_U64_MAC_STAT(rx_64),
  119. EFX_ETHTOOL_U64_MAC_STAT(rx_65_to_127),
  120. EFX_ETHTOOL_U64_MAC_STAT(rx_128_to_255),
  121. EFX_ETHTOOL_U64_MAC_STAT(rx_256_to_511),
  122. EFX_ETHTOOL_U64_MAC_STAT(rx_512_to_1023),
  123. EFX_ETHTOOL_U64_MAC_STAT(rx_1024_to_15xx),
  124. EFX_ETHTOOL_U64_MAC_STAT(rx_15xx_to_jumbo),
  125. EFX_ETHTOOL_U64_MAC_STAT(rx_gtjumbo),
  126. EFX_ETHTOOL_U64_MAC_STAT(rx_bad_lt64),
  127. EFX_ETHTOOL_U64_MAC_STAT(rx_bad_64_to_15xx),
  128. EFX_ETHTOOL_U64_MAC_STAT(rx_bad_15xx_to_jumbo),
  129. EFX_ETHTOOL_U64_MAC_STAT(rx_bad_gtjumbo),
  130. EFX_ETHTOOL_U64_MAC_STAT(rx_overflow),
  131. EFX_ETHTOOL_U64_MAC_STAT(rx_missed),
  132. EFX_ETHTOOL_U64_MAC_STAT(rx_false_carrier),
  133. EFX_ETHTOOL_U64_MAC_STAT(rx_symbol_error),
  134. EFX_ETHTOOL_U64_MAC_STAT(rx_align_error),
  135. EFX_ETHTOOL_U64_MAC_STAT(rx_length_error),
  136. EFX_ETHTOOL_U64_MAC_STAT(rx_internal_error),
  137. EFX_ETHTOOL_UINT_NIC_STAT(rx_nodesc_drop_cnt),
  138. EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset),
  139. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc),
  140. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),
  141. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err),
  142. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch),
  143. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
  144. };
  145. /* Number of ethtool statistics */
  146. #define EFX_ETHTOOL_NUM_STATS ARRAY_SIZE(efx_ethtool_stats)
  147. #define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB
  148. /**************************************************************************
  149. *
  150. * Ethtool operations
  151. *
  152. **************************************************************************
  153. */
  154. /* Identify device by flashing LEDs */
  155. static int efx_ethtool_phys_id(struct net_device *net_dev,
  156. enum ethtool_phys_id_state state)
  157. {
  158. struct efx_nic *efx = netdev_priv(net_dev);
  159. enum efx_led_mode mode = EFX_LED_DEFAULT;
  160. switch (state) {
  161. case ETHTOOL_ID_ON:
  162. mode = EFX_LED_ON;
  163. break;
  164. case ETHTOOL_ID_OFF:
  165. mode = EFX_LED_OFF;
  166. break;
  167. case ETHTOOL_ID_INACTIVE:
  168. mode = EFX_LED_DEFAULT;
  169. break;
  170. case ETHTOOL_ID_ACTIVE:
  171. return 1; /* cycle on/off once per second */
  172. }
  173. efx->type->set_id_led(efx, mode);
  174. return 0;
  175. }
  176. /* This must be called with rtnl_lock held. */
  177. static int efx_ethtool_get_settings(struct net_device *net_dev,
  178. struct ethtool_cmd *ecmd)
  179. {
  180. struct efx_nic *efx = netdev_priv(net_dev);
  181. struct efx_link_state *link_state = &efx->link_state;
  182. mutex_lock(&efx->mac_lock);
  183. efx->phy_op->get_settings(efx, ecmd);
  184. mutex_unlock(&efx->mac_lock);
  185. /* GMAC does not support 1000Mbps HD */
  186. ecmd->supported &= ~SUPPORTED_1000baseT_Half;
  187. /* Both MACs support pause frames (bidirectional and respond-only) */
  188. ecmd->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
  189. if (LOOPBACK_INTERNAL(efx)) {
  190. ethtool_cmd_speed_set(ecmd, link_state->speed);
  191. ecmd->duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF;
  192. }
  193. return 0;
  194. }
  195. /* This must be called with rtnl_lock held. */
  196. static int efx_ethtool_set_settings(struct net_device *net_dev,
  197. struct ethtool_cmd *ecmd)
  198. {
  199. struct efx_nic *efx = netdev_priv(net_dev);
  200. int rc;
  201. /* GMAC does not support 1000Mbps HD */
  202. if ((ethtool_cmd_speed(ecmd) == SPEED_1000) &&
  203. (ecmd->duplex != DUPLEX_FULL)) {
  204. netif_dbg(efx, drv, efx->net_dev,
  205. "rejecting unsupported 1000Mbps HD setting\n");
  206. return -EINVAL;
  207. }
  208. mutex_lock(&efx->mac_lock);
  209. rc = efx->phy_op->set_settings(efx, ecmd);
  210. mutex_unlock(&efx->mac_lock);
  211. return rc;
  212. }
  213. static void efx_ethtool_get_drvinfo(struct net_device *net_dev,
  214. struct ethtool_drvinfo *info)
  215. {
  216. struct efx_nic *efx = netdev_priv(net_dev);
  217. strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
  218. strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version));
  219. if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0)
  220. efx_mcdi_print_fwver(efx, info->fw_version,
  221. sizeof(info->fw_version));
  222. strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
  223. }
  224. static int efx_ethtool_get_regs_len(struct net_device *net_dev)
  225. {
  226. return efx_nic_get_regs_len(netdev_priv(net_dev));
  227. }
  228. static void efx_ethtool_get_regs(struct net_device *net_dev,
  229. struct ethtool_regs *regs, void *buf)
  230. {
  231. struct efx_nic *efx = netdev_priv(net_dev);
  232. regs->version = efx->type->revision;
  233. efx_nic_get_regs(efx, buf);
  234. }
  235. static u32 efx_ethtool_get_msglevel(struct net_device *net_dev)
  236. {
  237. struct efx_nic *efx = netdev_priv(net_dev);
  238. return efx->msg_enable;
  239. }
  240. static void efx_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable)
  241. {
  242. struct efx_nic *efx = netdev_priv(net_dev);
  243. efx->msg_enable = msg_enable;
  244. }
  245. /**
  246. * efx_fill_test - fill in an individual self-test entry
  247. * @test_index: Index of the test
  248. * @strings: Ethtool strings, or %NULL
  249. * @data: Ethtool test results, or %NULL
  250. * @test: Pointer to test result (used only if data != %NULL)
  251. * @unit_format: Unit name format (e.g. "chan\%d")
  252. * @unit_id: Unit id (e.g. 0 for "chan0")
  253. * @test_format: Test name format (e.g. "loopback.\%s.tx.sent")
  254. * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
  255. *
  256. * Fill in an individual self-test entry.
  257. */
  258. static void efx_fill_test(unsigned int test_index,
  259. struct ethtool_string *strings, u64 *data,
  260. int *test, const char *unit_format, int unit_id,
  261. const char *test_format, const char *test_id)
  262. {
  263. struct ethtool_string unit_str, test_str;
  264. /* Fill data value, if applicable */
  265. if (data)
  266. data[test_index] = *test;
  267. /* Fill string, if applicable */
  268. if (strings) {
  269. if (strchr(unit_format, '%'))
  270. snprintf(unit_str.name, sizeof(unit_str.name),
  271. unit_format, unit_id);
  272. else
  273. strcpy(unit_str.name, unit_format);
  274. snprintf(test_str.name, sizeof(test_str.name),
  275. test_format, test_id);
  276. snprintf(strings[test_index].name,
  277. sizeof(strings[test_index].name),
  278. "%-6s %-24s", unit_str.name, test_str.name);
  279. }
  280. }
  281. #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
  282. #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
  283. #define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
  284. #define EFX_LOOPBACK_NAME(_mode, _counter) \
  285. "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode)
  286. /**
  287. * efx_fill_loopback_test - fill in a block of loopback self-test entries
  288. * @efx: Efx NIC
  289. * @lb_tests: Efx loopback self-test results structure
  290. * @mode: Loopback test mode
  291. * @test_index: Starting index of the test
  292. * @strings: Ethtool strings, or %NULL
  293. * @data: Ethtool test results, or %NULL
  294. */
  295. static int efx_fill_loopback_test(struct efx_nic *efx,
  296. struct efx_loopback_self_tests *lb_tests,
  297. enum efx_loopback_mode mode,
  298. unsigned int test_index,
  299. struct ethtool_string *strings, u64 *data)
  300. {
  301. struct efx_channel *channel = efx_get_channel(efx, 0);
  302. struct efx_tx_queue *tx_queue;
  303. efx_for_each_channel_tx_queue(tx_queue, channel) {
  304. efx_fill_test(test_index++, strings, data,
  305. &lb_tests->tx_sent[tx_queue->queue],
  306. EFX_TX_QUEUE_NAME(tx_queue),
  307. EFX_LOOPBACK_NAME(mode, "tx_sent"));
  308. efx_fill_test(test_index++, strings, data,
  309. &lb_tests->tx_done[tx_queue->queue],
  310. EFX_TX_QUEUE_NAME(tx_queue),
  311. EFX_LOOPBACK_NAME(mode, "tx_done"));
  312. }
  313. efx_fill_test(test_index++, strings, data,
  314. &lb_tests->rx_good,
  315. "rx", 0,
  316. EFX_LOOPBACK_NAME(mode, "rx_good"));
  317. efx_fill_test(test_index++, strings, data,
  318. &lb_tests->rx_bad,
  319. "rx", 0,
  320. EFX_LOOPBACK_NAME(mode, "rx_bad"));
  321. return test_index;
  322. }
  323. /**
  324. * efx_ethtool_fill_self_tests - get self-test details
  325. * @efx: Efx NIC
  326. * @tests: Efx self-test results structure, or %NULL
  327. * @strings: Ethtool strings, or %NULL
  328. * @data: Ethtool test results, or %NULL
  329. */
  330. static int efx_ethtool_fill_self_tests(struct efx_nic *efx,
  331. struct efx_self_tests *tests,
  332. struct ethtool_string *strings,
  333. u64 *data)
  334. {
  335. struct efx_channel *channel;
  336. unsigned int n = 0, i;
  337. enum efx_loopback_mode mode;
  338. efx_fill_test(n++, strings, data, &tests->phy_alive,
  339. "phy", 0, "alive", NULL);
  340. efx_fill_test(n++, strings, data, &tests->nvram,
  341. "core", 0, "nvram", NULL);
  342. efx_fill_test(n++, strings, data, &tests->interrupt,
  343. "core", 0, "interrupt", NULL);
  344. /* Event queues */
  345. efx_for_each_channel(channel, efx) {
  346. efx_fill_test(n++, strings, data,
  347. &tests->eventq_dma[channel->channel],
  348. EFX_CHANNEL_NAME(channel),
  349. "eventq.dma", NULL);
  350. efx_fill_test(n++, strings, data,
  351. &tests->eventq_int[channel->channel],
  352. EFX_CHANNEL_NAME(channel),
  353. "eventq.int", NULL);
  354. }
  355. efx_fill_test(n++, strings, data, &tests->registers,
  356. "core", 0, "registers", NULL);
  357. if (efx->phy_op->run_tests != NULL) {
  358. EFX_BUG_ON_PARANOID(efx->phy_op->test_name == NULL);
  359. for (i = 0; true; ++i) {
  360. const char *name;
  361. EFX_BUG_ON_PARANOID(i >= EFX_MAX_PHY_TESTS);
  362. name = efx->phy_op->test_name(efx, i);
  363. if (name == NULL)
  364. break;
  365. efx_fill_test(n++, strings, data, &tests->phy_ext[i],
  366. "phy", 0, name, NULL);
  367. }
  368. }
  369. /* Loopback tests */
  370. for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
  371. if (!(efx->loopback_modes & (1 << mode)))
  372. continue;
  373. n = efx_fill_loopback_test(efx,
  374. &tests->loopback[mode], mode, n,
  375. strings, data);
  376. }
  377. return n;
  378. }
  379. static int efx_ethtool_get_sset_count(struct net_device *net_dev,
  380. int string_set)
  381. {
  382. switch (string_set) {
  383. case ETH_SS_STATS:
  384. return EFX_ETHTOOL_NUM_STATS;
  385. case ETH_SS_TEST:
  386. return efx_ethtool_fill_self_tests(netdev_priv(net_dev),
  387. NULL, NULL, NULL);
  388. default:
  389. return -EINVAL;
  390. }
  391. }
  392. static void efx_ethtool_get_strings(struct net_device *net_dev,
  393. u32 string_set, u8 *strings)
  394. {
  395. struct efx_nic *efx = netdev_priv(net_dev);
  396. struct ethtool_string *ethtool_strings =
  397. (struct ethtool_string *)strings;
  398. int i;
  399. switch (string_set) {
  400. case ETH_SS_STATS:
  401. for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++)
  402. strncpy(ethtool_strings[i].name,
  403. efx_ethtool_stats[i].name,
  404. sizeof(ethtool_strings[i].name));
  405. break;
  406. case ETH_SS_TEST:
  407. efx_ethtool_fill_self_tests(efx, NULL,
  408. ethtool_strings, NULL);
  409. break;
  410. default:
  411. /* No other string sets */
  412. break;
  413. }
  414. }
  415. static void efx_ethtool_get_stats(struct net_device *net_dev,
  416. struct ethtool_stats *stats,
  417. u64 *data)
  418. {
  419. struct efx_nic *efx = netdev_priv(net_dev);
  420. struct efx_mac_stats *mac_stats = &efx->mac_stats;
  421. const struct efx_ethtool_stat *stat;
  422. struct efx_channel *channel;
  423. struct efx_tx_queue *tx_queue;
  424. int i;
  425. EFX_BUG_ON_PARANOID(stats->n_stats != EFX_ETHTOOL_NUM_STATS);
  426. spin_lock_bh(&efx->stats_lock);
  427. /* Update MAC and NIC statistics */
  428. efx->type->update_stats(efx);
  429. /* Fill detailed statistics buffer */
  430. for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++) {
  431. stat = &efx_ethtool_stats[i];
  432. switch (stat->source) {
  433. case EFX_ETHTOOL_STAT_SOURCE_mac_stats:
  434. data[i] = stat->get_stat((void *)mac_stats +
  435. stat->offset);
  436. break;
  437. case EFX_ETHTOOL_STAT_SOURCE_nic:
  438. data[i] = stat->get_stat((void *)efx + stat->offset);
  439. break;
  440. case EFX_ETHTOOL_STAT_SOURCE_channel:
  441. data[i] = 0;
  442. efx_for_each_channel(channel, efx)
  443. data[i] += stat->get_stat((void *)channel +
  444. stat->offset);
  445. break;
  446. case EFX_ETHTOOL_STAT_SOURCE_tx_queue:
  447. data[i] = 0;
  448. efx_for_each_channel(channel, efx) {
  449. efx_for_each_channel_tx_queue(tx_queue, channel)
  450. data[i] +=
  451. stat->get_stat((void *)tx_queue
  452. + stat->offset);
  453. }
  454. break;
  455. }
  456. }
  457. spin_unlock_bh(&efx->stats_lock);
  458. }
  459. static void efx_ethtool_self_test(struct net_device *net_dev,
  460. struct ethtool_test *test, u64 *data)
  461. {
  462. struct efx_nic *efx = netdev_priv(net_dev);
  463. struct efx_self_tests *efx_tests;
  464. int already_up;
  465. int rc = -ENOMEM;
  466. efx_tests = kzalloc(sizeof(*efx_tests), GFP_KERNEL);
  467. if (!efx_tests)
  468. goto fail;
  469. ASSERT_RTNL();
  470. if (efx->state != STATE_RUNNING) {
  471. rc = -EIO;
  472. goto fail1;
  473. }
  474. netif_info(efx, drv, efx->net_dev, "starting %sline testing\n",
  475. (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
  476. /* We need rx buffers and interrupts. */
  477. already_up = (efx->net_dev->flags & IFF_UP);
  478. if (!already_up) {
  479. rc = dev_open(efx->net_dev);
  480. if (rc) {
  481. netif_err(efx, drv, efx->net_dev,
  482. "failed opening device.\n");
  483. goto fail1;
  484. }
  485. }
  486. rc = efx_selftest(efx, efx_tests, test->flags);
  487. if (!already_up)
  488. dev_close(efx->net_dev);
  489. netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n",
  490. rc == 0 ? "passed" : "failed",
  491. (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
  492. fail1:
  493. /* Fill ethtool results structures */
  494. efx_ethtool_fill_self_tests(efx, efx_tests, NULL, data);
  495. kfree(efx_tests);
  496. fail:
  497. if (rc)
  498. test->flags |= ETH_TEST_FL_FAILED;
  499. }
  500. /* Restart autonegotiation */
  501. static int efx_ethtool_nway_reset(struct net_device *net_dev)
  502. {
  503. struct efx_nic *efx = netdev_priv(net_dev);
  504. return mdio45_nway_restart(&efx->mdio);
  505. }
  506. /*
  507. * Each channel has a single IRQ and moderation timer, started by any
  508. * completion (or other event). Unless the module parameter
  509. * separate_tx_channels is set, IRQs and moderation are therefore
  510. * shared between RX and TX completions. In this case, when RX IRQ
  511. * moderation is explicitly changed then TX IRQ moderation is
  512. * automatically changed too, but otherwise we fail if the two values
  513. * are requested to be different.
  514. *
  515. * The hardware does not support a limit on the number of completions
  516. * before an IRQ, so we do not use the max_frames fields. We should
  517. * report and require that max_frames == (usecs != 0), but this would
  518. * invalidate existing user documentation.
  519. *
  520. * The hardware does not have distinct settings for interrupt
  521. * moderation while the previous IRQ is being handled, so we should
  522. * not use the 'irq' fields. However, an earlier developer
  523. * misunderstood the meaning of the 'irq' fields and the driver did
  524. * not support the standard fields. To avoid invalidating existing
  525. * user documentation, we report and accept changes through either the
  526. * standard or 'irq' fields. If both are changed at the same time, we
  527. * prefer the standard field.
  528. *
  529. * We implement adaptive IRQ moderation, but use a different algorithm
  530. * from that assumed in the definition of struct ethtool_coalesce.
  531. * Therefore we do not use any of the adaptive moderation parameters
  532. * in it.
  533. */
  534. static int efx_ethtool_get_coalesce(struct net_device *net_dev,
  535. struct ethtool_coalesce *coalesce)
  536. {
  537. struct efx_nic *efx = netdev_priv(net_dev);
  538. unsigned int tx_usecs, rx_usecs;
  539. bool rx_adaptive;
  540. efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &rx_adaptive);
  541. coalesce->tx_coalesce_usecs = tx_usecs;
  542. coalesce->tx_coalesce_usecs_irq = tx_usecs;
  543. coalesce->rx_coalesce_usecs = rx_usecs;
  544. coalesce->rx_coalesce_usecs_irq = rx_usecs;
  545. coalesce->use_adaptive_rx_coalesce = rx_adaptive;
  546. return 0;
  547. }
  548. static int efx_ethtool_set_coalesce(struct net_device *net_dev,
  549. struct ethtool_coalesce *coalesce)
  550. {
  551. struct efx_nic *efx = netdev_priv(net_dev);
  552. struct efx_channel *channel;
  553. unsigned int tx_usecs, rx_usecs;
  554. bool adaptive, rx_may_override_tx;
  555. int rc;
  556. if (coalesce->use_adaptive_tx_coalesce)
  557. return -EINVAL;
  558. efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &adaptive);
  559. if (coalesce->rx_coalesce_usecs != rx_usecs)
  560. rx_usecs = coalesce->rx_coalesce_usecs;
  561. else
  562. rx_usecs = coalesce->rx_coalesce_usecs_irq;
  563. adaptive = coalesce->use_adaptive_rx_coalesce;
  564. /* If channels are shared, TX IRQ moderation can be quietly
  565. * overridden unless it is changed from its old value.
  566. */
  567. rx_may_override_tx = (coalesce->tx_coalesce_usecs == tx_usecs &&
  568. coalesce->tx_coalesce_usecs_irq == tx_usecs);
  569. if (coalesce->tx_coalesce_usecs != tx_usecs)
  570. tx_usecs = coalesce->tx_coalesce_usecs;
  571. else
  572. tx_usecs = coalesce->tx_coalesce_usecs_irq;
  573. rc = efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive,
  574. rx_may_override_tx);
  575. if (rc != 0)
  576. return rc;
  577. efx_for_each_channel(channel, efx)
  578. efx->type->push_irq_moderation(channel);
  579. return 0;
  580. }
  581. static void efx_ethtool_get_ringparam(struct net_device *net_dev,
  582. struct ethtool_ringparam *ring)
  583. {
  584. struct efx_nic *efx = netdev_priv(net_dev);
  585. ring->rx_max_pending = EFX_MAX_DMAQ_SIZE;
  586. ring->tx_max_pending = EFX_MAX_DMAQ_SIZE;
  587. ring->rx_pending = efx->rxq_entries;
  588. ring->tx_pending = efx->txq_entries;
  589. }
  590. static int efx_ethtool_set_ringparam(struct net_device *net_dev,
  591. struct ethtool_ringparam *ring)
  592. {
  593. struct efx_nic *efx = netdev_priv(net_dev);
  594. if (ring->rx_mini_pending || ring->rx_jumbo_pending ||
  595. ring->rx_pending > EFX_MAX_DMAQ_SIZE ||
  596. ring->tx_pending > EFX_MAX_DMAQ_SIZE)
  597. return -EINVAL;
  598. if (ring->rx_pending < EFX_MIN_RING_SIZE ||
  599. ring->tx_pending < EFX_MIN_RING_SIZE) {
  600. netif_err(efx, drv, efx->net_dev,
  601. "TX and RX queues cannot be smaller than %ld\n",
  602. EFX_MIN_RING_SIZE);
  603. return -EINVAL;
  604. }
  605. return efx_realloc_channels(efx, ring->rx_pending, ring->tx_pending);
  606. }
  607. static int efx_ethtool_set_pauseparam(struct net_device *net_dev,
  608. struct ethtool_pauseparam *pause)
  609. {
  610. struct efx_nic *efx = netdev_priv(net_dev);
  611. u8 wanted_fc, old_fc;
  612. u32 old_adv;
  613. bool reset;
  614. int rc = 0;
  615. mutex_lock(&efx->mac_lock);
  616. wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
  617. (pause->tx_pause ? EFX_FC_TX : 0) |
  618. (pause->autoneg ? EFX_FC_AUTO : 0));
  619. if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
  620. netif_dbg(efx, drv, efx->net_dev,
  621. "Flow control unsupported: tx ON rx OFF\n");
  622. rc = -EINVAL;
  623. goto out;
  624. }
  625. if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising) {
  626. netif_dbg(efx, drv, efx->net_dev,
  627. "Autonegotiation is disabled\n");
  628. rc = -EINVAL;
  629. goto out;
  630. }
  631. /* TX flow control may automatically turn itself off if the
  632. * link partner (intermittently) stops responding to pause
  633. * frames. There isn't any indication that this has happened,
  634. * so the best we do is leave it up to the user to spot this
  635. * and fix it be cycling transmit flow control on this end. */
  636. reset = (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX);
  637. if (EFX_WORKAROUND_11482(efx) && reset) {
  638. if (efx_nic_rev(efx) == EFX_REV_FALCON_B0) {
  639. /* Recover by resetting the EM block */
  640. falcon_stop_nic_stats(efx);
  641. falcon_drain_tx_fifo(efx);
  642. falcon_reconfigure_xmac(efx);
  643. falcon_start_nic_stats(efx);
  644. } else {
  645. /* Schedule a reset to recover */
  646. efx_schedule_reset(efx, RESET_TYPE_INVISIBLE);
  647. }
  648. }
  649. old_adv = efx->link_advertising;
  650. old_fc = efx->wanted_fc;
  651. efx_link_set_wanted_fc(efx, wanted_fc);
  652. if (efx->link_advertising != old_adv ||
  653. (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) {
  654. rc = efx->phy_op->reconfigure(efx);
  655. if (rc) {
  656. netif_err(efx, drv, efx->net_dev,
  657. "Unable to advertise requested flow "
  658. "control setting\n");
  659. goto out;
  660. }
  661. }
  662. /* Reconfigure the MAC. The PHY *may* generate a link state change event
  663. * if the user just changed the advertised capabilities, but there's no
  664. * harm doing this twice */
  665. efx->type->reconfigure_mac(efx);
  666. out:
  667. mutex_unlock(&efx->mac_lock);
  668. return rc;
  669. }
  670. static void efx_ethtool_get_pauseparam(struct net_device *net_dev,
  671. struct ethtool_pauseparam *pause)
  672. {
  673. struct efx_nic *efx = netdev_priv(net_dev);
  674. pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX);
  675. pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX);
  676. pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO);
  677. }
  678. static void efx_ethtool_get_wol(struct net_device *net_dev,
  679. struct ethtool_wolinfo *wol)
  680. {
  681. struct efx_nic *efx = netdev_priv(net_dev);
  682. return efx->type->get_wol(efx, wol);
  683. }
  684. static int efx_ethtool_set_wol(struct net_device *net_dev,
  685. struct ethtool_wolinfo *wol)
  686. {
  687. struct efx_nic *efx = netdev_priv(net_dev);
  688. return efx->type->set_wol(efx, wol->wolopts);
  689. }
  690. static int efx_ethtool_reset(struct net_device *net_dev, u32 *flags)
  691. {
  692. struct efx_nic *efx = netdev_priv(net_dev);
  693. int rc;
  694. rc = efx->type->map_reset_flags(flags);
  695. if (rc < 0)
  696. return rc;
  697. return efx_reset(efx, rc);
  698. }
  699. /* MAC address mask including only MC flag */
  700. static const u8 mac_addr_mc_mask[ETH_ALEN] = { 0x01, 0, 0, 0, 0, 0 };
  701. static int efx_ethtool_get_class_rule(struct efx_nic *efx,
  702. struct ethtool_rx_flow_spec *rule)
  703. {
  704. struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
  705. struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
  706. struct ethhdr *mac_entry = &rule->h_u.ether_spec;
  707. struct ethhdr *mac_mask = &rule->m_u.ether_spec;
  708. struct efx_filter_spec spec;
  709. u16 vid;
  710. u8 proto;
  711. int rc;
  712. rc = efx_filter_get_filter_safe(efx, EFX_FILTER_PRI_MANUAL,
  713. rule->location, &spec);
  714. if (rc)
  715. return rc;
  716. if (spec.dmaq_id == 0xfff)
  717. rule->ring_cookie = RX_CLS_FLOW_DISC;
  718. else
  719. rule->ring_cookie = spec.dmaq_id;
  720. if (spec.type == EFX_FILTER_MC_DEF || spec.type == EFX_FILTER_UC_DEF) {
  721. rule->flow_type = ETHER_FLOW;
  722. memcpy(mac_mask->h_dest, mac_addr_mc_mask, ETH_ALEN);
  723. if (spec.type == EFX_FILTER_MC_DEF)
  724. memcpy(mac_entry->h_dest, mac_addr_mc_mask, ETH_ALEN);
  725. return 0;
  726. }
  727. rc = efx_filter_get_eth_local(&spec, &vid, mac_entry->h_dest);
  728. if (rc == 0) {
  729. rule->flow_type = ETHER_FLOW;
  730. memset(mac_mask->h_dest, ~0, ETH_ALEN);
  731. if (vid != EFX_FILTER_VID_UNSPEC) {
  732. rule->flow_type |= FLOW_EXT;
  733. rule->h_ext.vlan_tci = htons(vid);
  734. rule->m_ext.vlan_tci = htons(0xfff);
  735. }
  736. return 0;
  737. }
  738. rc = efx_filter_get_ipv4_local(&spec, &proto,
  739. &ip_entry->ip4dst, &ip_entry->pdst);
  740. if (rc != 0) {
  741. rc = efx_filter_get_ipv4_full(
  742. &spec, &proto, &ip_entry->ip4src, &ip_entry->psrc,
  743. &ip_entry->ip4dst, &ip_entry->pdst);
  744. EFX_WARN_ON_PARANOID(rc);
  745. ip_mask->ip4src = ~0;
  746. ip_mask->psrc = ~0;
  747. }
  748. rule->flow_type = (proto == IPPROTO_TCP) ? TCP_V4_FLOW : UDP_V4_FLOW;
  749. ip_mask->ip4dst = ~0;
  750. ip_mask->pdst = ~0;
  751. return rc;
  752. }
  753. static int
  754. efx_ethtool_get_rxnfc(struct net_device *net_dev,
  755. struct ethtool_rxnfc *info, u32 *rule_locs)
  756. {
  757. struct efx_nic *efx = netdev_priv(net_dev);
  758. switch (info->cmd) {
  759. case ETHTOOL_GRXRINGS:
  760. info->data = efx->n_rx_channels;
  761. return 0;
  762. case ETHTOOL_GRXFH: {
  763. unsigned min_revision = 0;
  764. info->data = 0;
  765. switch (info->flow_type) {
  766. case TCP_V4_FLOW:
  767. info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  768. /* fall through */
  769. case UDP_V4_FLOW:
  770. case SCTP_V4_FLOW:
  771. case AH_ESP_V4_FLOW:
  772. case IPV4_FLOW:
  773. info->data |= RXH_IP_SRC | RXH_IP_DST;
  774. min_revision = EFX_REV_FALCON_B0;
  775. break;
  776. case TCP_V6_FLOW:
  777. info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  778. /* fall through */
  779. case UDP_V6_FLOW:
  780. case SCTP_V6_FLOW:
  781. case AH_ESP_V6_FLOW:
  782. case IPV6_FLOW:
  783. info->data |= RXH_IP_SRC | RXH_IP_DST;
  784. min_revision = EFX_REV_SIENA_A0;
  785. break;
  786. default:
  787. break;
  788. }
  789. if (efx_nic_rev(efx) < min_revision)
  790. info->data = 0;
  791. return 0;
  792. }
  793. case ETHTOOL_GRXCLSRLCNT:
  794. info->data = efx_filter_get_rx_id_limit(efx);
  795. if (info->data == 0)
  796. return -EOPNOTSUPP;
  797. info->data |= RX_CLS_LOC_SPECIAL;
  798. info->rule_cnt =
  799. efx_filter_count_rx_used(efx, EFX_FILTER_PRI_MANUAL);
  800. return 0;
  801. case ETHTOOL_GRXCLSRULE:
  802. if (efx_filter_get_rx_id_limit(efx) == 0)
  803. return -EOPNOTSUPP;
  804. return efx_ethtool_get_class_rule(efx, &info->fs);
  805. case ETHTOOL_GRXCLSRLALL: {
  806. s32 rc;
  807. info->data = efx_filter_get_rx_id_limit(efx);
  808. if (info->data == 0)
  809. return -EOPNOTSUPP;
  810. rc = efx_filter_get_rx_ids(efx, EFX_FILTER_PRI_MANUAL,
  811. rule_locs, info->rule_cnt);
  812. if (rc < 0)
  813. return rc;
  814. info->rule_cnt = rc;
  815. return 0;
  816. }
  817. default:
  818. return -EOPNOTSUPP;
  819. }
  820. }
  821. static int efx_ethtool_set_class_rule(struct efx_nic *efx,
  822. struct ethtool_rx_flow_spec *rule)
  823. {
  824. struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
  825. struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
  826. struct ethhdr *mac_entry = &rule->h_u.ether_spec;
  827. struct ethhdr *mac_mask = &rule->m_u.ether_spec;
  828. struct efx_filter_spec spec;
  829. int rc;
  830. /* Check that user wants us to choose the location */
  831. if (rule->location != RX_CLS_LOC_ANY &&
  832. rule->location != RX_CLS_LOC_FIRST &&
  833. rule->location != RX_CLS_LOC_LAST)
  834. return -EINVAL;
  835. /* Range-check ring_cookie */
  836. if (rule->ring_cookie >= efx->n_rx_channels &&
  837. rule->ring_cookie != RX_CLS_FLOW_DISC)
  838. return -EINVAL;
  839. /* Check for unsupported extensions */
  840. if ((rule->flow_type & FLOW_EXT) &&
  841. (rule->m_ext.vlan_etype | rule->m_ext.data[0] |
  842. rule->m_ext.data[1]))
  843. return -EINVAL;
  844. efx_filter_init_rx(&spec, EFX_FILTER_PRI_MANUAL,
  845. (rule->location == RX_CLS_LOC_FIRST) ?
  846. EFX_FILTER_FLAG_RX_OVERRIDE_IP : 0,
  847. (rule->ring_cookie == RX_CLS_FLOW_DISC) ?
  848. 0xfff : rule->ring_cookie);
  849. switch (rule->flow_type) {
  850. case TCP_V4_FLOW:
  851. case UDP_V4_FLOW: {
  852. u8 proto = (rule->flow_type == TCP_V4_FLOW ?
  853. IPPROTO_TCP : IPPROTO_UDP);
  854. /* Must match all of destination, */
  855. if ((__force u32)~ip_mask->ip4dst |
  856. (__force u16)~ip_mask->pdst)
  857. return -EINVAL;
  858. /* all or none of source, */
  859. if ((ip_mask->ip4src | ip_mask->psrc) &&
  860. ((__force u32)~ip_mask->ip4src |
  861. (__force u16)~ip_mask->psrc))
  862. return -EINVAL;
  863. /* and nothing else */
  864. if (ip_mask->tos | rule->m_ext.vlan_tci)
  865. return -EINVAL;
  866. if (ip_mask->ip4src)
  867. rc = efx_filter_set_ipv4_full(&spec, proto,
  868. ip_entry->ip4dst,
  869. ip_entry->pdst,
  870. ip_entry->ip4src,
  871. ip_entry->psrc);
  872. else
  873. rc = efx_filter_set_ipv4_local(&spec, proto,
  874. ip_entry->ip4dst,
  875. ip_entry->pdst);
  876. if (rc)
  877. return rc;
  878. break;
  879. }
  880. case ETHER_FLOW | FLOW_EXT:
  881. case ETHER_FLOW: {
  882. u16 vlan_tag_mask = (rule->flow_type & FLOW_EXT ?
  883. ntohs(rule->m_ext.vlan_tci) : 0);
  884. /* Must not match on source address or Ethertype */
  885. if (!is_zero_ether_addr(mac_mask->h_source) ||
  886. mac_mask->h_proto)
  887. return -EINVAL;
  888. /* Is it a default UC or MC filter? */
  889. if (ether_addr_equal(mac_mask->h_dest, mac_addr_mc_mask) &&
  890. vlan_tag_mask == 0) {
  891. if (is_multicast_ether_addr(mac_entry->h_dest))
  892. rc = efx_filter_set_mc_def(&spec);
  893. else
  894. rc = efx_filter_set_uc_def(&spec);
  895. }
  896. /* Otherwise, it must match all of destination and all
  897. * or none of VID.
  898. */
  899. else if (is_broadcast_ether_addr(mac_mask->h_dest) &&
  900. (vlan_tag_mask == 0xfff || vlan_tag_mask == 0)) {
  901. rc = efx_filter_set_eth_local(
  902. &spec,
  903. vlan_tag_mask ?
  904. ntohs(rule->h_ext.vlan_tci) : EFX_FILTER_VID_UNSPEC,
  905. mac_entry->h_dest);
  906. } else {
  907. rc = -EINVAL;
  908. }
  909. if (rc)
  910. return rc;
  911. break;
  912. }
  913. default:
  914. return -EINVAL;
  915. }
  916. rc = efx_filter_insert_filter(efx, &spec, true);
  917. if (rc < 0)
  918. return rc;
  919. rule->location = rc;
  920. return 0;
  921. }
  922. static int efx_ethtool_set_rxnfc(struct net_device *net_dev,
  923. struct ethtool_rxnfc *info)
  924. {
  925. struct efx_nic *efx = netdev_priv(net_dev);
  926. if (efx_filter_get_rx_id_limit(efx) == 0)
  927. return -EOPNOTSUPP;
  928. switch (info->cmd) {
  929. case ETHTOOL_SRXCLSRLINS:
  930. return efx_ethtool_set_class_rule(efx, &info->fs);
  931. case ETHTOOL_SRXCLSRLDEL:
  932. return efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_MANUAL,
  933. info->fs.location);
  934. default:
  935. return -EOPNOTSUPP;
  936. }
  937. }
  938. static u32 efx_ethtool_get_rxfh_indir_size(struct net_device *net_dev)
  939. {
  940. struct efx_nic *efx = netdev_priv(net_dev);
  941. return ((efx_nic_rev(efx) < EFX_REV_FALCON_B0 ||
  942. efx->n_rx_channels == 1) ?
  943. 0 : ARRAY_SIZE(efx->rx_indir_table));
  944. }
  945. static int efx_ethtool_get_rxfh_indir(struct net_device *net_dev, u32 *indir)
  946. {
  947. struct efx_nic *efx = netdev_priv(net_dev);
  948. memcpy(indir, efx->rx_indir_table, sizeof(efx->rx_indir_table));
  949. return 0;
  950. }
  951. static int efx_ethtool_set_rxfh_indir(struct net_device *net_dev,
  952. const u32 *indir)
  953. {
  954. struct efx_nic *efx = netdev_priv(net_dev);
  955. memcpy(efx->rx_indir_table, indir, sizeof(efx->rx_indir_table));
  956. efx_nic_push_rx_indir_table(efx);
  957. return 0;
  958. }
  959. static int efx_ethtool_get_module_eeprom(struct net_device *net_dev,
  960. struct ethtool_eeprom *ee,
  961. u8 *data)
  962. {
  963. struct efx_nic *efx = netdev_priv(net_dev);
  964. int ret;
  965. if (!efx->phy_op || !efx->phy_op->get_module_eeprom)
  966. return -EOPNOTSUPP;
  967. mutex_lock(&efx->mac_lock);
  968. ret = efx->phy_op->get_module_eeprom(efx, ee, data);
  969. mutex_unlock(&efx->mac_lock);
  970. return ret;
  971. }
  972. static int efx_ethtool_get_module_info(struct net_device *net_dev,
  973. struct ethtool_modinfo *modinfo)
  974. {
  975. struct efx_nic *efx = netdev_priv(net_dev);
  976. int ret;
  977. if (!efx->phy_op || !efx->phy_op->get_module_info)
  978. return -EOPNOTSUPP;
  979. mutex_lock(&efx->mac_lock);
  980. ret = efx->phy_op->get_module_info(efx, modinfo);
  981. mutex_unlock(&efx->mac_lock);
  982. return ret;
  983. }
  984. const struct ethtool_ops efx_ethtool_ops = {
  985. .get_settings = efx_ethtool_get_settings,
  986. .set_settings = efx_ethtool_set_settings,
  987. .get_drvinfo = efx_ethtool_get_drvinfo,
  988. .get_regs_len = efx_ethtool_get_regs_len,
  989. .get_regs = efx_ethtool_get_regs,
  990. .get_msglevel = efx_ethtool_get_msglevel,
  991. .set_msglevel = efx_ethtool_set_msglevel,
  992. .nway_reset = efx_ethtool_nway_reset,
  993. .get_link = ethtool_op_get_link,
  994. .get_coalesce = efx_ethtool_get_coalesce,
  995. .set_coalesce = efx_ethtool_set_coalesce,
  996. .get_ringparam = efx_ethtool_get_ringparam,
  997. .set_ringparam = efx_ethtool_set_ringparam,
  998. .get_pauseparam = efx_ethtool_get_pauseparam,
  999. .set_pauseparam = efx_ethtool_set_pauseparam,
  1000. .get_sset_count = efx_ethtool_get_sset_count,
  1001. .self_test = efx_ethtool_self_test,
  1002. .get_strings = efx_ethtool_get_strings,
  1003. .set_phys_id = efx_ethtool_phys_id,
  1004. .get_ethtool_stats = efx_ethtool_get_stats,
  1005. .get_wol = efx_ethtool_get_wol,
  1006. .set_wol = efx_ethtool_set_wol,
  1007. .reset = efx_ethtool_reset,
  1008. .get_rxnfc = efx_ethtool_get_rxnfc,
  1009. .set_rxnfc = efx_ethtool_set_rxnfc,
  1010. .get_rxfh_indir_size = efx_ethtool_get_rxfh_indir_size,
  1011. .get_rxfh_indir = efx_ethtool_get_rxfh_indir,
  1012. .set_rxfh_indir = efx_ethtool_set_rxfh_indir,
  1013. .get_module_info = efx_ethtool_get_module_info,
  1014. .get_module_eeprom = efx_ethtool_get_module_eeprom,
  1015. };