ethtool.c 39 KB

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