ethtool.c 39 KB

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