ethtool.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385
  1. /****************************************************************************
  2. * Driver for Solarflare network controllers and boards
  3. * Copyright 2005-2006 Fen Systems Ltd.
  4. * Copyright 2006-2013 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 efx_sw_stat_desc {
  21. const char *name;
  22. enum {
  23. EFX_ETHTOOL_STAT_SOURCE_nic,
  24. EFX_ETHTOOL_STAT_SOURCE_channel,
  25. EFX_ETHTOOL_STAT_SOURCE_tx_queue
  26. } source;
  27. unsigned offset;
  28. u64(*get_stat) (void *field); /* Reader function */
  29. };
  30. /* Initialiser for a struct efx_sw_stat_desc with type-checking */
  31. #define EFX_ETHTOOL_STAT(stat_name, source_name, field, field_type, \
  32. get_stat_function) { \
  33. .name = #stat_name, \
  34. .source = EFX_ETHTOOL_STAT_SOURCE_##source_name, \
  35. .offset = ((((field_type *) 0) == \
  36. &((struct efx_##source_name *)0)->field) ? \
  37. offsetof(struct efx_##source_name, field) : \
  38. offsetof(struct efx_##source_name, field)), \
  39. .get_stat = get_stat_function, \
  40. }
  41. static u64 efx_get_uint_stat(void *field)
  42. {
  43. return *(unsigned int *)field;
  44. }
  45. static u64 efx_get_atomic_stat(void *field)
  46. {
  47. return atomic_read((atomic_t *) field);
  48. }
  49. #define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field) \
  50. EFX_ETHTOOL_STAT(field, nic, field, \
  51. atomic_t, efx_get_atomic_stat)
  52. #define EFX_ETHTOOL_UINT_CHANNEL_STAT(field) \
  53. EFX_ETHTOOL_STAT(field, channel, n_##field, \
  54. unsigned int, efx_get_uint_stat)
  55. #define EFX_ETHTOOL_UINT_TXQ_STAT(field) \
  56. EFX_ETHTOOL_STAT(tx_##field, tx_queue, field, \
  57. unsigned int, efx_get_uint_stat)
  58. static const struct efx_sw_stat_desc efx_sw_stat_desc[] = {
  59. EFX_ETHTOOL_UINT_TXQ_STAT(merge_events),
  60. EFX_ETHTOOL_UINT_TXQ_STAT(tso_bursts),
  61. EFX_ETHTOOL_UINT_TXQ_STAT(tso_long_headers),
  62. EFX_ETHTOOL_UINT_TXQ_STAT(tso_packets),
  63. EFX_ETHTOOL_UINT_TXQ_STAT(tso_fallbacks),
  64. EFX_ETHTOOL_UINT_TXQ_STAT(pushes),
  65. EFX_ETHTOOL_UINT_TXQ_STAT(pio_packets),
  66. EFX_ETHTOOL_UINT_TXQ_STAT(cb_packets),
  67. EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset),
  68. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc),
  69. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),
  70. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err),
  71. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch),
  72. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
  73. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_events),
  74. EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_packets),
  75. };
  76. #define EFX_ETHTOOL_SW_STAT_COUNT ARRAY_SIZE(efx_sw_stat_desc)
  77. #define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB
  78. /**************************************************************************
  79. *
  80. * Ethtool operations
  81. *
  82. **************************************************************************
  83. */
  84. /* Identify device by flashing LEDs */
  85. static int efx_ethtool_phys_id(struct net_device *net_dev,
  86. enum ethtool_phys_id_state state)
  87. {
  88. struct efx_nic *efx = netdev_priv(net_dev);
  89. enum efx_led_mode mode = EFX_LED_DEFAULT;
  90. switch (state) {
  91. case ETHTOOL_ID_ON:
  92. mode = EFX_LED_ON;
  93. break;
  94. case ETHTOOL_ID_OFF:
  95. mode = EFX_LED_OFF;
  96. break;
  97. case ETHTOOL_ID_INACTIVE:
  98. mode = EFX_LED_DEFAULT;
  99. break;
  100. case ETHTOOL_ID_ACTIVE:
  101. return 1; /* cycle on/off once per second */
  102. }
  103. efx->type->set_id_led(efx, mode);
  104. return 0;
  105. }
  106. /* This must be called with rtnl_lock held. */
  107. static int efx_ethtool_get_settings(struct net_device *net_dev,
  108. struct ethtool_cmd *ecmd)
  109. {
  110. struct efx_nic *efx = netdev_priv(net_dev);
  111. struct efx_link_state *link_state = &efx->link_state;
  112. mutex_lock(&efx->mac_lock);
  113. efx->phy_op->get_settings(efx, ecmd);
  114. mutex_unlock(&efx->mac_lock);
  115. /* Both MACs support pause frames (bidirectional and respond-only) */
  116. ecmd->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
  117. if (LOOPBACK_INTERNAL(efx)) {
  118. ethtool_cmd_speed_set(ecmd, link_state->speed);
  119. ecmd->duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF;
  120. }
  121. return 0;
  122. }
  123. /* This must be called with rtnl_lock held. */
  124. static int efx_ethtool_set_settings(struct net_device *net_dev,
  125. struct ethtool_cmd *ecmd)
  126. {
  127. struct efx_nic *efx = netdev_priv(net_dev);
  128. int rc;
  129. /* GMAC does not support 1000Mbps HD */
  130. if ((ethtool_cmd_speed(ecmd) == SPEED_1000) &&
  131. (ecmd->duplex != DUPLEX_FULL)) {
  132. netif_dbg(efx, drv, efx->net_dev,
  133. "rejecting unsupported 1000Mbps HD setting\n");
  134. return -EINVAL;
  135. }
  136. mutex_lock(&efx->mac_lock);
  137. rc = efx->phy_op->set_settings(efx, ecmd);
  138. mutex_unlock(&efx->mac_lock);
  139. return rc;
  140. }
  141. static void efx_ethtool_get_drvinfo(struct net_device *net_dev,
  142. struct ethtool_drvinfo *info)
  143. {
  144. struct efx_nic *efx = netdev_priv(net_dev);
  145. strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
  146. strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version));
  147. if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0)
  148. efx_mcdi_print_fwver(efx, info->fw_version,
  149. sizeof(info->fw_version));
  150. strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
  151. }
  152. static int efx_ethtool_get_regs_len(struct net_device *net_dev)
  153. {
  154. return efx_nic_get_regs_len(netdev_priv(net_dev));
  155. }
  156. static void efx_ethtool_get_regs(struct net_device *net_dev,
  157. struct ethtool_regs *regs, void *buf)
  158. {
  159. struct efx_nic *efx = netdev_priv(net_dev);
  160. regs->version = efx->type->revision;
  161. efx_nic_get_regs(efx, buf);
  162. }
  163. static u32 efx_ethtool_get_msglevel(struct net_device *net_dev)
  164. {
  165. struct efx_nic *efx = netdev_priv(net_dev);
  166. return efx->msg_enable;
  167. }
  168. static void efx_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable)
  169. {
  170. struct efx_nic *efx = netdev_priv(net_dev);
  171. efx->msg_enable = msg_enable;
  172. }
  173. /**
  174. * efx_fill_test - fill in an individual self-test entry
  175. * @test_index: Index of the test
  176. * @strings: Ethtool strings, or %NULL
  177. * @data: Ethtool test results, or %NULL
  178. * @test: Pointer to test result (used only if data != %NULL)
  179. * @unit_format: Unit name format (e.g. "chan\%d")
  180. * @unit_id: Unit id (e.g. 0 for "chan0")
  181. * @test_format: Test name format (e.g. "loopback.\%s.tx.sent")
  182. * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
  183. *
  184. * Fill in an individual self-test entry.
  185. */
  186. static void efx_fill_test(unsigned int test_index, u8 *strings, u64 *data,
  187. int *test, const char *unit_format, int unit_id,
  188. const char *test_format, const char *test_id)
  189. {
  190. char unit_str[ETH_GSTRING_LEN], test_str[ETH_GSTRING_LEN];
  191. /* Fill data value, if applicable */
  192. if (data)
  193. data[test_index] = *test;
  194. /* Fill string, if applicable */
  195. if (strings) {
  196. if (strchr(unit_format, '%'))
  197. snprintf(unit_str, sizeof(unit_str),
  198. unit_format, unit_id);
  199. else
  200. strcpy(unit_str, unit_format);
  201. snprintf(test_str, sizeof(test_str), test_format, test_id);
  202. snprintf(strings + test_index * ETH_GSTRING_LEN,
  203. ETH_GSTRING_LEN,
  204. "%-6s %-24s", unit_str, test_str);
  205. }
  206. }
  207. #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
  208. #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
  209. #define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
  210. #define EFX_LOOPBACK_NAME(_mode, _counter) \
  211. "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode)
  212. /**
  213. * efx_fill_loopback_test - fill in a block of loopback self-test entries
  214. * @efx: Efx NIC
  215. * @lb_tests: Efx loopback self-test results structure
  216. * @mode: Loopback test mode
  217. * @test_index: Starting index of the test
  218. * @strings: Ethtool strings, or %NULL
  219. * @data: Ethtool test results, or %NULL
  220. *
  221. * Fill in a block of loopback self-test entries. Return new test
  222. * index.
  223. */
  224. static int efx_fill_loopback_test(struct efx_nic *efx,
  225. struct efx_loopback_self_tests *lb_tests,
  226. enum efx_loopback_mode mode,
  227. unsigned int test_index,
  228. u8 *strings, u64 *data)
  229. {
  230. struct efx_channel *channel =
  231. efx_get_channel(efx, efx->tx_channel_offset);
  232. struct efx_tx_queue *tx_queue;
  233. efx_for_each_channel_tx_queue(tx_queue, channel) {
  234. efx_fill_test(test_index++, strings, data,
  235. &lb_tests->tx_sent[tx_queue->queue],
  236. EFX_TX_QUEUE_NAME(tx_queue),
  237. EFX_LOOPBACK_NAME(mode, "tx_sent"));
  238. efx_fill_test(test_index++, strings, data,
  239. &lb_tests->tx_done[tx_queue->queue],
  240. EFX_TX_QUEUE_NAME(tx_queue),
  241. EFX_LOOPBACK_NAME(mode, "tx_done"));
  242. }
  243. efx_fill_test(test_index++, strings, data,
  244. &lb_tests->rx_good,
  245. "rx", 0,
  246. EFX_LOOPBACK_NAME(mode, "rx_good"));
  247. efx_fill_test(test_index++, strings, data,
  248. &lb_tests->rx_bad,
  249. "rx", 0,
  250. EFX_LOOPBACK_NAME(mode, "rx_bad"));
  251. return test_index;
  252. }
  253. /**
  254. * efx_ethtool_fill_self_tests - get self-test details
  255. * @efx: Efx NIC
  256. * @tests: Efx self-test results structure, or %NULL
  257. * @strings: Ethtool strings, or %NULL
  258. * @data: Ethtool test results, or %NULL
  259. *
  260. * Get self-test number of strings, strings, and/or test results.
  261. * Return number of strings (== number of test results).
  262. *
  263. * The reason for merging these three functions is to make sure that
  264. * they can never be inconsistent.
  265. */
  266. static int efx_ethtool_fill_self_tests(struct efx_nic *efx,
  267. struct efx_self_tests *tests,
  268. u8 *strings, u64 *data)
  269. {
  270. struct efx_channel *channel;
  271. unsigned int n = 0, i;
  272. enum efx_loopback_mode mode;
  273. efx_fill_test(n++, strings, data, &tests->phy_alive,
  274. "phy", 0, "alive", NULL);
  275. efx_fill_test(n++, strings, data, &tests->nvram,
  276. "core", 0, "nvram", NULL);
  277. efx_fill_test(n++, strings, data, &tests->interrupt,
  278. "core", 0, "interrupt", NULL);
  279. /* Event queues */
  280. efx_for_each_channel(channel, efx) {
  281. efx_fill_test(n++, strings, data,
  282. &tests->eventq_dma[channel->channel],
  283. EFX_CHANNEL_NAME(channel),
  284. "eventq.dma", NULL);
  285. efx_fill_test(n++, strings, data,
  286. &tests->eventq_int[channel->channel],
  287. EFX_CHANNEL_NAME(channel),
  288. "eventq.int", NULL);
  289. }
  290. efx_fill_test(n++, strings, data, &tests->memory,
  291. "core", 0, "memory", NULL);
  292. efx_fill_test(n++, strings, data, &tests->registers,
  293. "core", 0, "registers", NULL);
  294. if (efx->phy_op->run_tests != NULL) {
  295. EFX_BUG_ON_PARANOID(efx->phy_op->test_name == NULL);
  296. for (i = 0; true; ++i) {
  297. const char *name;
  298. EFX_BUG_ON_PARANOID(i >= EFX_MAX_PHY_TESTS);
  299. name = efx->phy_op->test_name(efx, i);
  300. if (name == NULL)
  301. break;
  302. efx_fill_test(n++, strings, data, &tests->phy_ext[i],
  303. "phy", 0, name, NULL);
  304. }
  305. }
  306. /* Loopback tests */
  307. for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
  308. if (!(efx->loopback_modes & (1 << mode)))
  309. continue;
  310. n = efx_fill_loopback_test(efx,
  311. &tests->loopback[mode], mode, n,
  312. strings, data);
  313. }
  314. return n;
  315. }
  316. static size_t efx_describe_per_queue_stats(struct efx_nic *efx, u8 *strings)
  317. {
  318. size_t n_stats = 0;
  319. struct efx_channel *channel;
  320. efx_for_each_channel(channel, efx) {
  321. if (efx_channel_has_tx_queues(channel)) {
  322. n_stats++;
  323. if (strings != NULL) {
  324. snprintf(strings, ETH_GSTRING_LEN,
  325. "tx-%u.tx_packets",
  326. channel->tx_queue[0].queue /
  327. EFX_TXQ_TYPES);
  328. strings += ETH_GSTRING_LEN;
  329. }
  330. }
  331. }
  332. efx_for_each_channel(channel, efx) {
  333. if (efx_channel_has_rx_queue(channel)) {
  334. n_stats++;
  335. if (strings != NULL) {
  336. snprintf(strings, ETH_GSTRING_LEN,
  337. "rx-%d.rx_packets", channel->channel);
  338. strings += ETH_GSTRING_LEN;
  339. }
  340. }
  341. }
  342. return n_stats;
  343. }
  344. static int efx_ethtool_get_sset_count(struct net_device *net_dev,
  345. int string_set)
  346. {
  347. struct efx_nic *efx = netdev_priv(net_dev);
  348. switch (string_set) {
  349. case ETH_SS_STATS:
  350. return efx->type->describe_stats(efx, NULL) +
  351. EFX_ETHTOOL_SW_STAT_COUNT +
  352. efx_describe_per_queue_stats(efx, NULL) +
  353. efx_ptp_describe_stats(efx, NULL);
  354. case ETH_SS_TEST:
  355. return efx_ethtool_fill_self_tests(efx, NULL, NULL, NULL);
  356. default:
  357. return -EINVAL;
  358. }
  359. }
  360. static void efx_ethtool_get_strings(struct net_device *net_dev,
  361. u32 string_set, u8 *strings)
  362. {
  363. struct efx_nic *efx = netdev_priv(net_dev);
  364. int i;
  365. switch (string_set) {
  366. case ETH_SS_STATS:
  367. strings += (efx->type->describe_stats(efx, strings) *
  368. ETH_GSTRING_LEN);
  369. for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++)
  370. strlcpy(strings + i * ETH_GSTRING_LEN,
  371. efx_sw_stat_desc[i].name, ETH_GSTRING_LEN);
  372. strings += EFX_ETHTOOL_SW_STAT_COUNT * ETH_GSTRING_LEN;
  373. strings += (efx_describe_per_queue_stats(efx, strings) *
  374. ETH_GSTRING_LEN);
  375. efx_ptp_describe_stats(efx, strings);
  376. break;
  377. case ETH_SS_TEST:
  378. efx_ethtool_fill_self_tests(efx, NULL, strings, NULL);
  379. break;
  380. default:
  381. /* No other string sets */
  382. break;
  383. }
  384. }
  385. static void efx_ethtool_get_stats(struct net_device *net_dev,
  386. struct ethtool_stats *stats,
  387. u64 *data)
  388. {
  389. struct efx_nic *efx = netdev_priv(net_dev);
  390. const struct efx_sw_stat_desc *stat;
  391. struct efx_channel *channel;
  392. struct efx_tx_queue *tx_queue;
  393. struct efx_rx_queue *rx_queue;
  394. int i;
  395. spin_lock_bh(&efx->stats_lock);
  396. /* Get NIC statistics */
  397. data += efx->type->update_stats(efx, data, NULL);
  398. /* Get software statistics */
  399. for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) {
  400. stat = &efx_sw_stat_desc[i];
  401. switch (stat->source) {
  402. case EFX_ETHTOOL_STAT_SOURCE_nic:
  403. data[i] = stat->get_stat((void *)efx + stat->offset);
  404. break;
  405. case EFX_ETHTOOL_STAT_SOURCE_channel:
  406. data[i] = 0;
  407. efx_for_each_channel(channel, efx)
  408. data[i] += stat->get_stat((void *)channel +
  409. stat->offset);
  410. break;
  411. case EFX_ETHTOOL_STAT_SOURCE_tx_queue:
  412. data[i] = 0;
  413. efx_for_each_channel(channel, efx) {
  414. efx_for_each_channel_tx_queue(tx_queue, channel)
  415. data[i] +=
  416. stat->get_stat((void *)tx_queue
  417. + stat->offset);
  418. }
  419. break;
  420. }
  421. }
  422. data += EFX_ETHTOOL_SW_STAT_COUNT;
  423. spin_unlock_bh(&efx->stats_lock);
  424. efx_for_each_channel(channel, efx) {
  425. if (efx_channel_has_tx_queues(channel)) {
  426. *data = 0;
  427. efx_for_each_channel_tx_queue(tx_queue, channel) {
  428. *data += tx_queue->tx_packets;
  429. }
  430. data++;
  431. }
  432. }
  433. efx_for_each_channel(channel, efx) {
  434. if (efx_channel_has_rx_queue(channel)) {
  435. *data = 0;
  436. efx_for_each_channel_rx_queue(rx_queue, channel) {
  437. *data += rx_queue->rx_packets;
  438. }
  439. data++;
  440. }
  441. }
  442. efx_ptp_update_stats(efx, data);
  443. }
  444. static void efx_ethtool_self_test(struct net_device *net_dev,
  445. struct ethtool_test *test, u64 *data)
  446. {
  447. struct efx_nic *efx = netdev_priv(net_dev);
  448. struct efx_self_tests *efx_tests;
  449. bool already_up;
  450. int rc = -ENOMEM;
  451. efx_tests = kzalloc(sizeof(*efx_tests), GFP_KERNEL);
  452. if (!efx_tests)
  453. goto fail;
  454. if (efx->state != STATE_READY) {
  455. rc = -EBUSY;
  456. goto out;
  457. }
  458. netif_info(efx, drv, efx->net_dev, "starting %sline testing\n",
  459. (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
  460. /* We need rx buffers and interrupts. */
  461. already_up = (efx->net_dev->flags & IFF_UP);
  462. if (!already_up) {
  463. rc = dev_open(efx->net_dev);
  464. if (rc) {
  465. netif_err(efx, drv, efx->net_dev,
  466. "failed opening device.\n");
  467. goto out;
  468. }
  469. }
  470. rc = efx_selftest(efx, efx_tests, test->flags);
  471. if (!already_up)
  472. dev_close(efx->net_dev);
  473. netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n",
  474. rc == 0 ? "passed" : "failed",
  475. (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
  476. out:
  477. efx_ethtool_fill_self_tests(efx, efx_tests, NULL, data);
  478. kfree(efx_tests);
  479. fail:
  480. if (rc)
  481. test->flags |= ETH_TEST_FL_FAILED;
  482. }
  483. /* Restart autonegotiation */
  484. static int efx_ethtool_nway_reset(struct net_device *net_dev)
  485. {
  486. struct efx_nic *efx = netdev_priv(net_dev);
  487. return mdio45_nway_restart(&efx->mdio);
  488. }
  489. /*
  490. * Each channel has a single IRQ and moderation timer, started by any
  491. * completion (or other event). Unless the module parameter
  492. * separate_tx_channels is set, IRQs and moderation are therefore
  493. * shared between RX and TX completions. In this case, when RX IRQ
  494. * moderation is explicitly changed then TX IRQ moderation is
  495. * automatically changed too, but otherwise we fail if the two values
  496. * are requested to be different.
  497. *
  498. * The hardware does not support a limit on the number of completions
  499. * before an IRQ, so we do not use the max_frames fields. We should
  500. * report and require that max_frames == (usecs != 0), but this would
  501. * invalidate existing user documentation.
  502. *
  503. * The hardware does not have distinct settings for interrupt
  504. * moderation while the previous IRQ is being handled, so we should
  505. * not use the 'irq' fields. However, an earlier developer
  506. * misunderstood the meaning of the 'irq' fields and the driver did
  507. * not support the standard fields. To avoid invalidating existing
  508. * user documentation, we report and accept changes through either the
  509. * standard or 'irq' fields. If both are changed at the same time, we
  510. * prefer the standard field.
  511. *
  512. * We implement adaptive IRQ moderation, but use a different algorithm
  513. * from that assumed in the definition of struct ethtool_coalesce.
  514. * Therefore we do not use any of the adaptive moderation parameters
  515. * in it.
  516. */
  517. static int efx_ethtool_get_coalesce(struct net_device *net_dev,
  518. struct ethtool_coalesce *coalesce)
  519. {
  520. struct efx_nic *efx = netdev_priv(net_dev);
  521. unsigned int tx_usecs, rx_usecs;
  522. bool rx_adaptive;
  523. efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &rx_adaptive);
  524. coalesce->tx_coalesce_usecs = tx_usecs;
  525. coalesce->tx_coalesce_usecs_irq = tx_usecs;
  526. coalesce->rx_coalesce_usecs = rx_usecs;
  527. coalesce->rx_coalesce_usecs_irq = rx_usecs;
  528. coalesce->use_adaptive_rx_coalesce = rx_adaptive;
  529. return 0;
  530. }
  531. static int efx_ethtool_set_coalesce(struct net_device *net_dev,
  532. struct ethtool_coalesce *coalesce)
  533. {
  534. struct efx_nic *efx = netdev_priv(net_dev);
  535. struct efx_channel *channel;
  536. unsigned int tx_usecs, rx_usecs;
  537. bool adaptive, rx_may_override_tx;
  538. int rc;
  539. if (coalesce->use_adaptive_tx_coalesce)
  540. return -EINVAL;
  541. efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &adaptive);
  542. if (coalesce->rx_coalesce_usecs != rx_usecs)
  543. rx_usecs = coalesce->rx_coalesce_usecs;
  544. else
  545. rx_usecs = coalesce->rx_coalesce_usecs_irq;
  546. adaptive = coalesce->use_adaptive_rx_coalesce;
  547. /* If channels are shared, TX IRQ moderation can be quietly
  548. * overridden unless it is changed from its old value.
  549. */
  550. rx_may_override_tx = (coalesce->tx_coalesce_usecs == tx_usecs &&
  551. coalesce->tx_coalesce_usecs_irq == tx_usecs);
  552. if (coalesce->tx_coalesce_usecs != tx_usecs)
  553. tx_usecs = coalesce->tx_coalesce_usecs;
  554. else
  555. tx_usecs = coalesce->tx_coalesce_usecs_irq;
  556. rc = efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive,
  557. rx_may_override_tx);
  558. if (rc != 0)
  559. return rc;
  560. efx_for_each_channel(channel, efx)
  561. efx->type->push_irq_moderation(channel);
  562. return 0;
  563. }
  564. static void efx_ethtool_get_ringparam(struct net_device *net_dev,
  565. struct ethtool_ringparam *ring)
  566. {
  567. struct efx_nic *efx = netdev_priv(net_dev);
  568. ring->rx_max_pending = EFX_MAX_DMAQ_SIZE;
  569. ring->tx_max_pending = EFX_TXQ_MAX_ENT(efx);
  570. ring->rx_pending = efx->rxq_entries;
  571. ring->tx_pending = efx->txq_entries;
  572. }
  573. static int efx_ethtool_set_ringparam(struct net_device *net_dev,
  574. struct ethtool_ringparam *ring)
  575. {
  576. struct efx_nic *efx = netdev_priv(net_dev);
  577. u32 txq_entries;
  578. if (ring->rx_mini_pending || ring->rx_jumbo_pending ||
  579. ring->rx_pending > EFX_MAX_DMAQ_SIZE ||
  580. ring->tx_pending > EFX_TXQ_MAX_ENT(efx))
  581. return -EINVAL;
  582. if (ring->rx_pending < EFX_RXQ_MIN_ENT) {
  583. netif_err(efx, drv, efx->net_dev,
  584. "RX queues cannot be smaller than %u\n",
  585. EFX_RXQ_MIN_ENT);
  586. return -EINVAL;
  587. }
  588. txq_entries = max(ring->tx_pending, EFX_TXQ_MIN_ENT(efx));
  589. if (txq_entries != ring->tx_pending)
  590. netif_warn(efx, drv, efx->net_dev,
  591. "increasing TX queue size to minimum of %u\n",
  592. txq_entries);
  593. return efx_realloc_channels(efx, ring->rx_pending, txq_entries);
  594. }
  595. static int efx_ethtool_set_pauseparam(struct net_device *net_dev,
  596. struct ethtool_pauseparam *pause)
  597. {
  598. struct efx_nic *efx = netdev_priv(net_dev);
  599. u8 wanted_fc, old_fc;
  600. u32 old_adv;
  601. int rc = 0;
  602. mutex_lock(&efx->mac_lock);
  603. wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
  604. (pause->tx_pause ? EFX_FC_TX : 0) |
  605. (pause->autoneg ? EFX_FC_AUTO : 0));
  606. if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
  607. netif_dbg(efx, drv, efx->net_dev,
  608. "Flow control unsupported: tx ON rx OFF\n");
  609. rc = -EINVAL;
  610. goto out;
  611. }
  612. if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising) {
  613. netif_dbg(efx, drv, efx->net_dev,
  614. "Autonegotiation is disabled\n");
  615. rc = -EINVAL;
  616. goto out;
  617. }
  618. /* Hook for Falcon bug 11482 workaround */
  619. if (efx->type->prepare_enable_fc_tx &&
  620. (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX))
  621. efx->type->prepare_enable_fc_tx(efx);
  622. old_adv = efx->link_advertising;
  623. old_fc = efx->wanted_fc;
  624. efx_link_set_wanted_fc(efx, wanted_fc);
  625. if (efx->link_advertising != old_adv ||
  626. (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) {
  627. rc = efx->phy_op->reconfigure(efx);
  628. if (rc) {
  629. netif_err(efx, drv, efx->net_dev,
  630. "Unable to advertise requested flow "
  631. "control setting\n");
  632. goto out;
  633. }
  634. }
  635. /* Reconfigure the MAC. The PHY *may* generate a link state change event
  636. * if the user just changed the advertised capabilities, but there's no
  637. * harm doing this twice */
  638. efx_mac_reconfigure(efx);
  639. out:
  640. mutex_unlock(&efx->mac_lock);
  641. return rc;
  642. }
  643. static void efx_ethtool_get_pauseparam(struct net_device *net_dev,
  644. struct ethtool_pauseparam *pause)
  645. {
  646. struct efx_nic *efx = netdev_priv(net_dev);
  647. pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX);
  648. pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX);
  649. pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO);
  650. }
  651. static void efx_ethtool_get_wol(struct net_device *net_dev,
  652. struct ethtool_wolinfo *wol)
  653. {
  654. struct efx_nic *efx = netdev_priv(net_dev);
  655. return efx->type->get_wol(efx, wol);
  656. }
  657. static int efx_ethtool_set_wol(struct net_device *net_dev,
  658. struct ethtool_wolinfo *wol)
  659. {
  660. struct efx_nic *efx = netdev_priv(net_dev);
  661. return efx->type->set_wol(efx, wol->wolopts);
  662. }
  663. static int efx_ethtool_reset(struct net_device *net_dev, u32 *flags)
  664. {
  665. struct efx_nic *efx = netdev_priv(net_dev);
  666. int rc;
  667. rc = efx->type->map_reset_flags(flags);
  668. if (rc < 0)
  669. return rc;
  670. return efx_reset(efx, rc);
  671. }
  672. /* MAC address mask including only I/G bit */
  673. static const u8 mac_addr_ig_mask[ETH_ALEN] __aligned(2) = {0x01, 0, 0, 0, 0, 0};
  674. #define IP4_ADDR_FULL_MASK ((__force __be32)~0)
  675. #define IP_PROTO_FULL_MASK 0xFF
  676. #define PORT_FULL_MASK ((__force __be16)~0)
  677. #define ETHER_TYPE_FULL_MASK ((__force __be16)~0)
  678. static inline void ip6_fill_mask(__be32 *mask)
  679. {
  680. mask[0] = mask[1] = mask[2] = mask[3] = ~(__be32)0;
  681. }
  682. static int efx_ethtool_get_class_rule(struct efx_nic *efx,
  683. struct ethtool_rx_flow_spec *rule)
  684. {
  685. struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
  686. struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
  687. struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
  688. struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
  689. struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
  690. struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
  691. struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
  692. struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
  693. struct ethhdr *mac_entry = &rule->h_u.ether_spec;
  694. struct ethhdr *mac_mask = &rule->m_u.ether_spec;
  695. struct efx_filter_spec spec;
  696. int rc;
  697. rc = efx_filter_get_filter_safe(efx, EFX_FILTER_PRI_MANUAL,
  698. rule->location, &spec);
  699. if (rc)
  700. return rc;
  701. if (spec.dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP)
  702. rule->ring_cookie = RX_CLS_FLOW_DISC;
  703. else
  704. rule->ring_cookie = spec.dmaq_id;
  705. if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) &&
  706. spec.ether_type == htons(ETH_P_IP) &&
  707. (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) &&
  708. (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
  709. !(spec.match_flags &
  710. ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
  711. EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
  712. EFX_FILTER_MATCH_IP_PROTO |
  713. EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) {
  714. rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
  715. TCP_V4_FLOW : UDP_V4_FLOW);
  716. if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
  717. ip_entry->ip4dst = spec.loc_host[0];
  718. ip_mask->ip4dst = IP4_ADDR_FULL_MASK;
  719. }
  720. if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
  721. ip_entry->ip4src = spec.rem_host[0];
  722. ip_mask->ip4src = IP4_ADDR_FULL_MASK;
  723. }
  724. if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) {
  725. ip_entry->pdst = spec.loc_port;
  726. ip_mask->pdst = PORT_FULL_MASK;
  727. }
  728. if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) {
  729. ip_entry->psrc = spec.rem_port;
  730. ip_mask->psrc = PORT_FULL_MASK;
  731. }
  732. } else if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) &&
  733. spec.ether_type == htons(ETH_P_IPV6) &&
  734. (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) &&
  735. (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
  736. !(spec.match_flags &
  737. ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
  738. EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
  739. EFX_FILTER_MATCH_IP_PROTO |
  740. EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) {
  741. rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
  742. TCP_V6_FLOW : UDP_V6_FLOW);
  743. if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
  744. memcpy(ip6_entry->ip6dst, spec.loc_host,
  745. sizeof(ip6_entry->ip6dst));
  746. ip6_fill_mask(ip6_mask->ip6dst);
  747. }
  748. if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
  749. memcpy(ip6_entry->ip6src, spec.rem_host,
  750. sizeof(ip6_entry->ip6src));
  751. ip6_fill_mask(ip6_mask->ip6src);
  752. }
  753. if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) {
  754. ip6_entry->pdst = spec.loc_port;
  755. ip6_mask->pdst = PORT_FULL_MASK;
  756. }
  757. if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) {
  758. ip6_entry->psrc = spec.rem_port;
  759. ip6_mask->psrc = PORT_FULL_MASK;
  760. }
  761. } else if (!(spec.match_flags &
  762. ~(EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG |
  763. EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_ETHER_TYPE |
  764. EFX_FILTER_MATCH_OUTER_VID))) {
  765. rule->flow_type = ETHER_FLOW;
  766. if (spec.match_flags &
  767. (EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG)) {
  768. ether_addr_copy(mac_entry->h_dest, spec.loc_mac);
  769. if (spec.match_flags & EFX_FILTER_MATCH_LOC_MAC)
  770. eth_broadcast_addr(mac_mask->h_dest);
  771. else
  772. ether_addr_copy(mac_mask->h_dest,
  773. mac_addr_ig_mask);
  774. }
  775. if (spec.match_flags & EFX_FILTER_MATCH_REM_MAC) {
  776. ether_addr_copy(mac_entry->h_source, spec.rem_mac);
  777. eth_broadcast_addr(mac_mask->h_source);
  778. }
  779. if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) {
  780. mac_entry->h_proto = spec.ether_type;
  781. mac_mask->h_proto = ETHER_TYPE_FULL_MASK;
  782. }
  783. } else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
  784. spec.ether_type == htons(ETH_P_IP) &&
  785. !(spec.match_flags &
  786. ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
  787. EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
  788. EFX_FILTER_MATCH_IP_PROTO))) {
  789. rule->flow_type = IPV4_USER_FLOW;
  790. uip_entry->ip_ver = ETH_RX_NFC_IP4;
  791. if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) {
  792. uip_mask->proto = IP_PROTO_FULL_MASK;
  793. uip_entry->proto = spec.ip_proto;
  794. }
  795. if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
  796. uip_entry->ip4dst = spec.loc_host[0];
  797. uip_mask->ip4dst = IP4_ADDR_FULL_MASK;
  798. }
  799. if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
  800. uip_entry->ip4src = spec.rem_host[0];
  801. uip_mask->ip4src = IP4_ADDR_FULL_MASK;
  802. }
  803. } else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
  804. spec.ether_type == htons(ETH_P_IPV6) &&
  805. !(spec.match_flags &
  806. ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
  807. EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
  808. EFX_FILTER_MATCH_IP_PROTO))) {
  809. rule->flow_type = IPV6_USER_FLOW;
  810. if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) {
  811. uip6_mask->l4_proto = IP_PROTO_FULL_MASK;
  812. uip6_entry->l4_proto = spec.ip_proto;
  813. }
  814. if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
  815. memcpy(uip6_entry->ip6dst, spec.loc_host,
  816. sizeof(uip6_entry->ip6dst));
  817. ip6_fill_mask(uip6_mask->ip6dst);
  818. }
  819. if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
  820. memcpy(uip6_entry->ip6src, spec.rem_host,
  821. sizeof(uip6_entry->ip6src));
  822. ip6_fill_mask(uip6_mask->ip6src);
  823. }
  824. } else {
  825. /* The above should handle all filters that we insert */
  826. WARN_ON(1);
  827. return -EINVAL;
  828. }
  829. if (spec.match_flags & EFX_FILTER_MATCH_OUTER_VID) {
  830. rule->flow_type |= FLOW_EXT;
  831. rule->h_ext.vlan_tci = spec.outer_vid;
  832. rule->m_ext.vlan_tci = htons(0xfff);
  833. }
  834. return rc;
  835. }
  836. static int
  837. efx_ethtool_get_rxnfc(struct net_device *net_dev,
  838. struct ethtool_rxnfc *info, u32 *rule_locs)
  839. {
  840. struct efx_nic *efx = netdev_priv(net_dev);
  841. switch (info->cmd) {
  842. case ETHTOOL_GRXRINGS:
  843. info->data = efx->n_rx_channels;
  844. return 0;
  845. case ETHTOOL_GRXFH: {
  846. unsigned min_revision = 0;
  847. info->data = 0;
  848. switch (info->flow_type) {
  849. case UDP_V4_FLOW:
  850. if (efx->rx_hash_udp_4tuple)
  851. /* fall through */
  852. case TCP_V4_FLOW:
  853. info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  854. /* fall through */
  855. case SCTP_V4_FLOW:
  856. case AH_ESP_V4_FLOW:
  857. case IPV4_FLOW:
  858. info->data |= RXH_IP_SRC | RXH_IP_DST;
  859. min_revision = EFX_REV_FALCON_B0;
  860. break;
  861. case UDP_V6_FLOW:
  862. if (efx->rx_hash_udp_4tuple)
  863. /* fall through */
  864. case TCP_V6_FLOW:
  865. info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  866. /* fall through */
  867. case SCTP_V6_FLOW:
  868. case AH_ESP_V6_FLOW:
  869. case IPV6_FLOW:
  870. info->data |= RXH_IP_SRC | RXH_IP_DST;
  871. min_revision = EFX_REV_SIENA_A0;
  872. break;
  873. default:
  874. break;
  875. }
  876. if (efx_nic_rev(efx) < min_revision)
  877. info->data = 0;
  878. return 0;
  879. }
  880. case ETHTOOL_GRXCLSRLCNT:
  881. info->data = efx_filter_get_rx_id_limit(efx);
  882. if (info->data == 0)
  883. return -EOPNOTSUPP;
  884. info->data |= RX_CLS_LOC_SPECIAL;
  885. info->rule_cnt =
  886. efx_filter_count_rx_used(efx, EFX_FILTER_PRI_MANUAL);
  887. return 0;
  888. case ETHTOOL_GRXCLSRULE:
  889. if (efx_filter_get_rx_id_limit(efx) == 0)
  890. return -EOPNOTSUPP;
  891. return efx_ethtool_get_class_rule(efx, &info->fs);
  892. case ETHTOOL_GRXCLSRLALL: {
  893. s32 rc;
  894. info->data = efx_filter_get_rx_id_limit(efx);
  895. if (info->data == 0)
  896. return -EOPNOTSUPP;
  897. rc = efx_filter_get_rx_ids(efx, EFX_FILTER_PRI_MANUAL,
  898. rule_locs, info->rule_cnt);
  899. if (rc < 0)
  900. return rc;
  901. info->rule_cnt = rc;
  902. return 0;
  903. }
  904. default:
  905. return -EOPNOTSUPP;
  906. }
  907. }
  908. static inline bool ip6_mask_is_full(__be32 mask[4])
  909. {
  910. return !~(mask[0] & mask[1] & mask[2] & mask[3]);
  911. }
  912. static inline bool ip6_mask_is_empty(__be32 mask[4])
  913. {
  914. return !(mask[0] | mask[1] | mask[2] | mask[3]);
  915. }
  916. static int efx_ethtool_set_class_rule(struct efx_nic *efx,
  917. struct ethtool_rx_flow_spec *rule)
  918. {
  919. struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
  920. struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
  921. struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
  922. struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
  923. struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
  924. struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
  925. struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
  926. struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
  927. struct ethhdr *mac_entry = &rule->h_u.ether_spec;
  928. struct ethhdr *mac_mask = &rule->m_u.ether_spec;
  929. struct efx_filter_spec spec;
  930. int rc;
  931. /* Check that user wants us to choose the location */
  932. if (rule->location != RX_CLS_LOC_ANY)
  933. return -EINVAL;
  934. /* Range-check ring_cookie */
  935. if (rule->ring_cookie >= efx->n_rx_channels &&
  936. rule->ring_cookie != RX_CLS_FLOW_DISC)
  937. return -EINVAL;
  938. /* Check for unsupported extensions */
  939. if ((rule->flow_type & FLOW_EXT) &&
  940. (rule->m_ext.vlan_etype || rule->m_ext.data[0] ||
  941. rule->m_ext.data[1]))
  942. return -EINVAL;
  943. efx_filter_init_rx(&spec, EFX_FILTER_PRI_MANUAL,
  944. efx->rx_scatter ? EFX_FILTER_FLAG_RX_SCATTER : 0,
  945. (rule->ring_cookie == RX_CLS_FLOW_DISC) ?
  946. EFX_FILTER_RX_DMAQ_ID_DROP : rule->ring_cookie);
  947. switch (rule->flow_type & ~FLOW_EXT) {
  948. case TCP_V4_FLOW:
  949. case UDP_V4_FLOW:
  950. spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
  951. EFX_FILTER_MATCH_IP_PROTO);
  952. spec.ether_type = htons(ETH_P_IP);
  953. spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V4_FLOW ?
  954. IPPROTO_TCP : IPPROTO_UDP);
  955. if (ip_mask->ip4dst) {
  956. if (ip_mask->ip4dst != IP4_ADDR_FULL_MASK)
  957. return -EINVAL;
  958. spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
  959. spec.loc_host[0] = ip_entry->ip4dst;
  960. }
  961. if (ip_mask->ip4src) {
  962. if (ip_mask->ip4src != IP4_ADDR_FULL_MASK)
  963. return -EINVAL;
  964. spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
  965. spec.rem_host[0] = ip_entry->ip4src;
  966. }
  967. if (ip_mask->pdst) {
  968. if (ip_mask->pdst != PORT_FULL_MASK)
  969. return -EINVAL;
  970. spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
  971. spec.loc_port = ip_entry->pdst;
  972. }
  973. if (ip_mask->psrc) {
  974. if (ip_mask->psrc != PORT_FULL_MASK)
  975. return -EINVAL;
  976. spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
  977. spec.rem_port = ip_entry->psrc;
  978. }
  979. if (ip_mask->tos)
  980. return -EINVAL;
  981. break;
  982. case TCP_V6_FLOW:
  983. case UDP_V6_FLOW:
  984. spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
  985. EFX_FILTER_MATCH_IP_PROTO);
  986. spec.ether_type = htons(ETH_P_IPV6);
  987. spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V6_FLOW ?
  988. IPPROTO_TCP : IPPROTO_UDP);
  989. if (!ip6_mask_is_empty(ip6_mask->ip6dst)) {
  990. if (!ip6_mask_is_full(ip6_mask->ip6dst))
  991. return -EINVAL;
  992. spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
  993. memcpy(spec.loc_host, ip6_entry->ip6dst, sizeof(spec.loc_host));
  994. }
  995. if (!ip6_mask_is_empty(ip6_mask->ip6src)) {
  996. if (!ip6_mask_is_full(ip6_mask->ip6src))
  997. return -EINVAL;
  998. spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
  999. memcpy(spec.rem_host, ip6_entry->ip6src, sizeof(spec.rem_host));
  1000. }
  1001. if (ip6_mask->pdst) {
  1002. if (ip6_mask->pdst != PORT_FULL_MASK)
  1003. return -EINVAL;
  1004. spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
  1005. spec.loc_port = ip6_entry->pdst;
  1006. }
  1007. if (ip6_mask->psrc) {
  1008. if (ip6_mask->psrc != PORT_FULL_MASK)
  1009. return -EINVAL;
  1010. spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
  1011. spec.rem_port = ip6_entry->psrc;
  1012. }
  1013. if (ip6_mask->tclass)
  1014. return -EINVAL;
  1015. break;
  1016. case IPV4_USER_FLOW:
  1017. if (uip_mask->l4_4_bytes || uip_mask->tos || uip_mask->ip_ver ||
  1018. uip_entry->ip_ver != ETH_RX_NFC_IP4)
  1019. return -EINVAL;
  1020. spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE;
  1021. spec.ether_type = htons(ETH_P_IP);
  1022. if (uip_mask->ip4dst) {
  1023. if (uip_mask->ip4dst != IP4_ADDR_FULL_MASK)
  1024. return -EINVAL;
  1025. spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
  1026. spec.loc_host[0] = uip_entry->ip4dst;
  1027. }
  1028. if (uip_mask->ip4src) {
  1029. if (uip_mask->ip4src != IP4_ADDR_FULL_MASK)
  1030. return -EINVAL;
  1031. spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
  1032. spec.rem_host[0] = uip_entry->ip4src;
  1033. }
  1034. if (uip_mask->proto) {
  1035. if (uip_mask->proto != IP_PROTO_FULL_MASK)
  1036. return -EINVAL;
  1037. spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO;
  1038. spec.ip_proto = uip_entry->proto;
  1039. }
  1040. break;
  1041. case IPV6_USER_FLOW:
  1042. if (uip6_mask->l4_4_bytes || uip6_mask->tclass)
  1043. return -EINVAL;
  1044. spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE;
  1045. spec.ether_type = htons(ETH_P_IPV6);
  1046. if (!ip6_mask_is_empty(uip6_mask->ip6dst)) {
  1047. if (!ip6_mask_is_full(uip6_mask->ip6dst))
  1048. return -EINVAL;
  1049. spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
  1050. memcpy(spec.loc_host, uip6_entry->ip6dst, sizeof(spec.loc_host));
  1051. }
  1052. if (!ip6_mask_is_empty(uip6_mask->ip6src)) {
  1053. if (!ip6_mask_is_full(uip6_mask->ip6src))
  1054. return -EINVAL;
  1055. spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
  1056. memcpy(spec.rem_host, uip6_entry->ip6src, sizeof(spec.rem_host));
  1057. }
  1058. if (uip6_mask->l4_proto) {
  1059. if (uip6_mask->l4_proto != IP_PROTO_FULL_MASK)
  1060. return -EINVAL;
  1061. spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO;
  1062. spec.ip_proto = uip6_entry->l4_proto;
  1063. }
  1064. break;
  1065. case ETHER_FLOW:
  1066. if (!is_zero_ether_addr(mac_mask->h_dest)) {
  1067. if (ether_addr_equal(mac_mask->h_dest,
  1068. mac_addr_ig_mask))
  1069. spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC_IG;
  1070. else if (is_broadcast_ether_addr(mac_mask->h_dest))
  1071. spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC;
  1072. else
  1073. return -EINVAL;
  1074. ether_addr_copy(spec.loc_mac, mac_entry->h_dest);
  1075. }
  1076. if (!is_zero_ether_addr(mac_mask->h_source)) {
  1077. if (!is_broadcast_ether_addr(mac_mask->h_source))
  1078. return -EINVAL;
  1079. spec.match_flags |= EFX_FILTER_MATCH_REM_MAC;
  1080. ether_addr_copy(spec.rem_mac, mac_entry->h_source);
  1081. }
  1082. if (mac_mask->h_proto) {
  1083. if (mac_mask->h_proto != ETHER_TYPE_FULL_MASK)
  1084. return -EINVAL;
  1085. spec.match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
  1086. spec.ether_type = mac_entry->h_proto;
  1087. }
  1088. break;
  1089. default:
  1090. return -EINVAL;
  1091. }
  1092. if ((rule->flow_type & FLOW_EXT) && rule->m_ext.vlan_tci) {
  1093. if (rule->m_ext.vlan_tci != htons(0xfff))
  1094. return -EINVAL;
  1095. spec.match_flags |= EFX_FILTER_MATCH_OUTER_VID;
  1096. spec.outer_vid = rule->h_ext.vlan_tci;
  1097. }
  1098. rc = efx_filter_insert_filter(efx, &spec, true);
  1099. if (rc < 0)
  1100. return rc;
  1101. rule->location = rc;
  1102. return 0;
  1103. }
  1104. static int efx_ethtool_set_rxnfc(struct net_device *net_dev,
  1105. struct ethtool_rxnfc *info)
  1106. {
  1107. struct efx_nic *efx = netdev_priv(net_dev);
  1108. if (efx_filter_get_rx_id_limit(efx) == 0)
  1109. return -EOPNOTSUPP;
  1110. switch (info->cmd) {
  1111. case ETHTOOL_SRXCLSRLINS:
  1112. return efx_ethtool_set_class_rule(efx, &info->fs);
  1113. case ETHTOOL_SRXCLSRLDEL:
  1114. return efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_MANUAL,
  1115. info->fs.location);
  1116. default:
  1117. return -EOPNOTSUPP;
  1118. }
  1119. }
  1120. static u32 efx_ethtool_get_rxfh_indir_size(struct net_device *net_dev)
  1121. {
  1122. struct efx_nic *efx = netdev_priv(net_dev);
  1123. return ((efx_nic_rev(efx) < EFX_REV_FALCON_B0 ||
  1124. efx->n_rx_channels == 1) ?
  1125. 0 : ARRAY_SIZE(efx->rx_indir_table));
  1126. }
  1127. static int efx_ethtool_get_rxfh(struct net_device *net_dev, u32 *indir, u8 *key,
  1128. u8 *hfunc)
  1129. {
  1130. struct efx_nic *efx = netdev_priv(net_dev);
  1131. if (hfunc)
  1132. *hfunc = ETH_RSS_HASH_TOP;
  1133. if (indir)
  1134. memcpy(indir, efx->rx_indir_table, sizeof(efx->rx_indir_table));
  1135. return 0;
  1136. }
  1137. static int efx_ethtool_set_rxfh(struct net_device *net_dev, const u32 *indir,
  1138. const u8 *key, const u8 hfunc)
  1139. {
  1140. struct efx_nic *efx = netdev_priv(net_dev);
  1141. /* We do not allow change in unsupported parameters */
  1142. if (key ||
  1143. (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
  1144. return -EOPNOTSUPP;
  1145. if (!indir)
  1146. return 0;
  1147. return efx->type->rx_push_rss_config(efx, true, indir);
  1148. }
  1149. static int efx_ethtool_get_ts_info(struct net_device *net_dev,
  1150. struct ethtool_ts_info *ts_info)
  1151. {
  1152. struct efx_nic *efx = netdev_priv(net_dev);
  1153. /* Software capabilities */
  1154. ts_info->so_timestamping = (SOF_TIMESTAMPING_RX_SOFTWARE |
  1155. SOF_TIMESTAMPING_SOFTWARE);
  1156. ts_info->phc_index = -1;
  1157. efx_ptp_get_ts_info(efx, ts_info);
  1158. return 0;
  1159. }
  1160. static int efx_ethtool_get_module_eeprom(struct net_device *net_dev,
  1161. struct ethtool_eeprom *ee,
  1162. u8 *data)
  1163. {
  1164. struct efx_nic *efx = netdev_priv(net_dev);
  1165. int ret;
  1166. if (!efx->phy_op || !efx->phy_op->get_module_eeprom)
  1167. return -EOPNOTSUPP;
  1168. mutex_lock(&efx->mac_lock);
  1169. ret = efx->phy_op->get_module_eeprom(efx, ee, data);
  1170. mutex_unlock(&efx->mac_lock);
  1171. return ret;
  1172. }
  1173. static int efx_ethtool_get_module_info(struct net_device *net_dev,
  1174. struct ethtool_modinfo *modinfo)
  1175. {
  1176. struct efx_nic *efx = netdev_priv(net_dev);
  1177. int ret;
  1178. if (!efx->phy_op || !efx->phy_op->get_module_info)
  1179. return -EOPNOTSUPP;
  1180. mutex_lock(&efx->mac_lock);
  1181. ret = efx->phy_op->get_module_info(efx, modinfo);
  1182. mutex_unlock(&efx->mac_lock);
  1183. return ret;
  1184. }
  1185. const struct ethtool_ops efx_ethtool_ops = {
  1186. .get_settings = efx_ethtool_get_settings,
  1187. .set_settings = efx_ethtool_set_settings,
  1188. .get_drvinfo = efx_ethtool_get_drvinfo,
  1189. .get_regs_len = efx_ethtool_get_regs_len,
  1190. .get_regs = efx_ethtool_get_regs,
  1191. .get_msglevel = efx_ethtool_get_msglevel,
  1192. .set_msglevel = efx_ethtool_set_msglevel,
  1193. .nway_reset = efx_ethtool_nway_reset,
  1194. .get_link = ethtool_op_get_link,
  1195. .get_coalesce = efx_ethtool_get_coalesce,
  1196. .set_coalesce = efx_ethtool_set_coalesce,
  1197. .get_ringparam = efx_ethtool_get_ringparam,
  1198. .set_ringparam = efx_ethtool_set_ringparam,
  1199. .get_pauseparam = efx_ethtool_get_pauseparam,
  1200. .set_pauseparam = efx_ethtool_set_pauseparam,
  1201. .get_sset_count = efx_ethtool_get_sset_count,
  1202. .self_test = efx_ethtool_self_test,
  1203. .get_strings = efx_ethtool_get_strings,
  1204. .set_phys_id = efx_ethtool_phys_id,
  1205. .get_ethtool_stats = efx_ethtool_get_stats,
  1206. .get_wol = efx_ethtool_get_wol,
  1207. .set_wol = efx_ethtool_set_wol,
  1208. .reset = efx_ethtool_reset,
  1209. .get_rxnfc = efx_ethtool_get_rxnfc,
  1210. .set_rxnfc = efx_ethtool_set_rxnfc,
  1211. .get_rxfh_indir_size = efx_ethtool_get_rxfh_indir_size,
  1212. .get_rxfh = efx_ethtool_get_rxfh,
  1213. .set_rxfh = efx_ethtool_set_rxfh,
  1214. .get_ts_info = efx_ethtool_get_ts_info,
  1215. .get_module_info = efx_ethtool_get_module_info,
  1216. .get_module_eeprom = efx_ethtool_get_module_eeprom,
  1217. };