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