1 /****************************************************************************
2 * Driver for Solarflare network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
4 * Copyright 2006-2013 Solarflare Communications Inc.
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.
11 #include <linux/netdevice.h>
12 #include <linux/ethtool.h>
13 #include <linux/rtnetlink.h>
15 #include "net_driver.h"
16 #include "workarounds.h"
22 struct efx_sw_stat_desc
{
25 EFX_ETHTOOL_STAT_SOURCE_nic
,
26 EFX_ETHTOOL_STAT_SOURCE_channel
,
27 EFX_ETHTOOL_STAT_SOURCE_tx_queue
30 u64(*get_stat
) (void *field
); /* Reader function */
33 /* Initialiser for a struct efx_sw_stat_desc with type-checking */
34 #define EFX_ETHTOOL_STAT(stat_name, source_name, field, field_type, \
35 get_stat_function) { \
37 .source = EFX_ETHTOOL_STAT_SOURCE_##source_name, \
38 .offset = ((((field_type *) 0) == \
39 &((struct efx_##source_name *)0)->field) ? \
40 offsetof(struct efx_##source_name, field) : \
41 offsetof(struct efx_##source_name, field)), \
42 .get_stat = get_stat_function, \
45 static u64
efx_get_uint_stat(void *field
)
47 return *(unsigned int *)field
;
50 static u64
efx_get_atomic_stat(void *field
)
52 return atomic_read((atomic_t
*) field
);
55 #define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field) \
56 EFX_ETHTOOL_STAT(field, nic, field, \
57 atomic_t, efx_get_atomic_stat)
59 #define EFX_ETHTOOL_UINT_CHANNEL_STAT(field) \
60 EFX_ETHTOOL_STAT(field, channel, n_##field, \
61 unsigned int, efx_get_uint_stat)
63 #define EFX_ETHTOOL_UINT_TXQ_STAT(field) \
64 EFX_ETHTOOL_STAT(tx_##field, tx_queue, field, \
65 unsigned int, efx_get_uint_stat)
67 static const struct efx_sw_stat_desc efx_sw_stat_desc
[] = {
68 EFX_ETHTOOL_UINT_TXQ_STAT(merge_events
),
69 EFX_ETHTOOL_UINT_TXQ_STAT(tso_bursts
),
70 EFX_ETHTOOL_UINT_TXQ_STAT(tso_long_headers
),
71 EFX_ETHTOOL_UINT_TXQ_STAT(tso_packets
),
72 EFX_ETHTOOL_UINT_TXQ_STAT(tso_fallbacks
),
73 EFX_ETHTOOL_UINT_TXQ_STAT(pushes
),
74 EFX_ETHTOOL_UINT_TXQ_STAT(pio_packets
),
75 EFX_ETHTOOL_UINT_TXQ_STAT(cb_packets
),
76 EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset
),
77 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc
),
78 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err
),
79 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err
),
80 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch
),
81 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc
),
82 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_events
),
83 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_packets
),
86 #define EFX_ETHTOOL_SW_STAT_COUNT ARRAY_SIZE(efx_sw_stat_desc)
88 #define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB
90 /**************************************************************************
94 **************************************************************************
97 /* Identify device by flashing LEDs */
98 static int efx_ethtool_phys_id(struct net_device
*net_dev
,
99 enum ethtool_phys_id_state state
)
101 struct efx_nic
*efx
= netdev_priv(net_dev
);
102 enum efx_led_mode mode
= EFX_LED_DEFAULT
;
111 case ETHTOOL_ID_INACTIVE
:
112 mode
= EFX_LED_DEFAULT
;
114 case ETHTOOL_ID_ACTIVE
:
115 return 1; /* cycle on/off once per second */
118 efx
->type
->set_id_led(efx
, mode
);
122 /* This must be called with rtnl_lock held. */
124 efx_ethtool_get_link_ksettings(struct net_device
*net_dev
,
125 struct ethtool_link_ksettings
*cmd
)
127 struct efx_nic
*efx
= netdev_priv(net_dev
);
128 struct efx_link_state
*link_state
= &efx
->link_state
;
131 mutex_lock(&efx
->mac_lock
);
132 efx
->phy_op
->get_link_ksettings(efx
, cmd
);
133 mutex_unlock(&efx
->mac_lock
);
135 /* Both MACs support pause frames (bidirectional and respond-only) */
136 ethtool_convert_link_mode_to_legacy_u32(&supported
,
137 cmd
->link_modes
.supported
);
139 supported
|= SUPPORTED_Pause
| SUPPORTED_Asym_Pause
;
141 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.supported
,
144 if (LOOPBACK_INTERNAL(efx
)) {
145 cmd
->base
.speed
= link_state
->speed
;
146 cmd
->base
.duplex
= link_state
->fd
? DUPLEX_FULL
: DUPLEX_HALF
;
152 /* This must be called with rtnl_lock held. */
154 efx_ethtool_set_link_ksettings(struct net_device
*net_dev
,
155 const struct ethtool_link_ksettings
*cmd
)
157 struct efx_nic
*efx
= netdev_priv(net_dev
);
160 /* GMAC does not support 1000Mbps HD */
161 if ((cmd
->base
.speed
== SPEED_1000
) &&
162 (cmd
->base
.duplex
!= DUPLEX_FULL
)) {
163 netif_dbg(efx
, drv
, efx
->net_dev
,
164 "rejecting unsupported 1000Mbps HD setting\n");
168 mutex_lock(&efx
->mac_lock
);
169 rc
= efx
->phy_op
->set_link_ksettings(efx
, cmd
);
170 mutex_unlock(&efx
->mac_lock
);
174 static void efx_ethtool_get_drvinfo(struct net_device
*net_dev
,
175 struct ethtool_drvinfo
*info
)
177 struct efx_nic
*efx
= netdev_priv(net_dev
);
179 strlcpy(info
->driver
, KBUILD_MODNAME
, sizeof(info
->driver
));
180 strlcpy(info
->version
, EFX_DRIVER_VERSION
, sizeof(info
->version
));
181 efx_mcdi_print_fwver(efx
, info
->fw_version
,
182 sizeof(info
->fw_version
));
183 strlcpy(info
->bus_info
, pci_name(efx
->pci_dev
), sizeof(info
->bus_info
));
186 static int efx_ethtool_get_regs_len(struct net_device
*net_dev
)
188 return efx_nic_get_regs_len(netdev_priv(net_dev
));
191 static void efx_ethtool_get_regs(struct net_device
*net_dev
,
192 struct ethtool_regs
*regs
, void *buf
)
194 struct efx_nic
*efx
= netdev_priv(net_dev
);
196 regs
->version
= efx
->type
->revision
;
197 efx_nic_get_regs(efx
, buf
);
200 static u32
efx_ethtool_get_msglevel(struct net_device
*net_dev
)
202 struct efx_nic
*efx
= netdev_priv(net_dev
);
203 return efx
->msg_enable
;
206 static void efx_ethtool_set_msglevel(struct net_device
*net_dev
, u32 msg_enable
)
208 struct efx_nic
*efx
= netdev_priv(net_dev
);
209 efx
->msg_enable
= msg_enable
;
213 * efx_fill_test - fill in an individual self-test entry
214 * @test_index: Index of the test
215 * @strings: Ethtool strings, or %NULL
216 * @data: Ethtool test results, or %NULL
217 * @test: Pointer to test result (used only if data != %NULL)
218 * @unit_format: Unit name format (e.g. "chan\%d")
219 * @unit_id: Unit id (e.g. 0 for "chan0")
220 * @test_format: Test name format (e.g. "loopback.\%s.tx.sent")
221 * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
223 * Fill in an individual self-test entry.
225 static void efx_fill_test(unsigned int test_index
, u8
*strings
, u64
*data
,
226 int *test
, const char *unit_format
, int unit_id
,
227 const char *test_format
, const char *test_id
)
229 char unit_str
[ETH_GSTRING_LEN
], test_str
[ETH_GSTRING_LEN
];
231 /* Fill data value, if applicable */
233 data
[test_index
] = *test
;
235 /* Fill string, if applicable */
237 if (strchr(unit_format
, '%'))
238 snprintf(unit_str
, sizeof(unit_str
),
239 unit_format
, unit_id
);
241 strcpy(unit_str
, unit_format
);
242 snprintf(test_str
, sizeof(test_str
), test_format
, test_id
);
243 snprintf(strings
+ test_index
* ETH_GSTRING_LEN
,
245 "%-6s %-24s", unit_str
, test_str
);
249 #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
250 #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
251 #define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
252 #define EFX_LOOPBACK_NAME(_mode, _counter) \
253 "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode)
256 * efx_fill_loopback_test - fill in a block of loopback self-test entries
258 * @lb_tests: Efx loopback self-test results structure
259 * @mode: Loopback test mode
260 * @test_index: Starting index of the test
261 * @strings: Ethtool strings, or %NULL
262 * @data: Ethtool test results, or %NULL
264 * Fill in a block of loopback self-test entries. Return new test
267 static int efx_fill_loopback_test(struct efx_nic
*efx
,
268 struct efx_loopback_self_tests
*lb_tests
,
269 enum efx_loopback_mode mode
,
270 unsigned int test_index
,
271 u8
*strings
, u64
*data
)
273 struct efx_channel
*channel
=
274 efx_get_channel(efx
, efx
->tx_channel_offset
);
275 struct efx_tx_queue
*tx_queue
;
277 efx_for_each_channel_tx_queue(tx_queue
, channel
) {
278 efx_fill_test(test_index
++, strings
, data
,
279 &lb_tests
->tx_sent
[tx_queue
->queue
],
280 EFX_TX_QUEUE_NAME(tx_queue
),
281 EFX_LOOPBACK_NAME(mode
, "tx_sent"));
282 efx_fill_test(test_index
++, strings
, data
,
283 &lb_tests
->tx_done
[tx_queue
->queue
],
284 EFX_TX_QUEUE_NAME(tx_queue
),
285 EFX_LOOPBACK_NAME(mode
, "tx_done"));
287 efx_fill_test(test_index
++, strings
, data
,
290 EFX_LOOPBACK_NAME(mode
, "rx_good"));
291 efx_fill_test(test_index
++, strings
, data
,
294 EFX_LOOPBACK_NAME(mode
, "rx_bad"));
300 * efx_ethtool_fill_self_tests - get self-test details
302 * @tests: Efx self-test results structure, or %NULL
303 * @strings: Ethtool strings, or %NULL
304 * @data: Ethtool test results, or %NULL
306 * Get self-test number of strings, strings, and/or test results.
307 * Return number of strings (== number of test results).
309 * The reason for merging these three functions is to make sure that
310 * they can never be inconsistent.
312 static int efx_ethtool_fill_self_tests(struct efx_nic
*efx
,
313 struct efx_self_tests
*tests
,
314 u8
*strings
, u64
*data
)
316 struct efx_channel
*channel
;
317 unsigned int n
= 0, i
;
318 enum efx_loopback_mode mode
;
320 efx_fill_test(n
++, strings
, data
, &tests
->phy_alive
,
321 "phy", 0, "alive", NULL
);
322 efx_fill_test(n
++, strings
, data
, &tests
->nvram
,
323 "core", 0, "nvram", NULL
);
324 efx_fill_test(n
++, strings
, data
, &tests
->interrupt
,
325 "core", 0, "interrupt", NULL
);
328 efx_for_each_channel(channel
, efx
) {
329 efx_fill_test(n
++, strings
, data
,
330 &tests
->eventq_dma
[channel
->channel
],
331 EFX_CHANNEL_NAME(channel
),
333 efx_fill_test(n
++, strings
, data
,
334 &tests
->eventq_int
[channel
->channel
],
335 EFX_CHANNEL_NAME(channel
),
339 efx_fill_test(n
++, strings
, data
, &tests
->memory
,
340 "core", 0, "memory", NULL
);
341 efx_fill_test(n
++, strings
, data
, &tests
->registers
,
342 "core", 0, "registers", NULL
);
344 if (efx
->phy_op
->run_tests
!= NULL
) {
345 EFX_WARN_ON_PARANOID(efx
->phy_op
->test_name
== NULL
);
347 for (i
= 0; true; ++i
) {
350 EFX_WARN_ON_PARANOID(i
>= EFX_MAX_PHY_TESTS
);
351 name
= efx
->phy_op
->test_name(efx
, i
);
355 efx_fill_test(n
++, strings
, data
, &tests
->phy_ext
[i
],
356 "phy", 0, name
, NULL
);
361 for (mode
= LOOPBACK_NONE
; mode
<= LOOPBACK_TEST_MAX
; mode
++) {
362 if (!(efx
->loopback_modes
& (1 << mode
)))
364 n
= efx_fill_loopback_test(efx
,
365 &tests
->loopback
[mode
], mode
, n
,
372 static size_t efx_describe_per_queue_stats(struct efx_nic
*efx
, u8
*strings
)
375 struct efx_channel
*channel
;
377 efx_for_each_channel(channel
, efx
) {
378 if (efx_channel_has_tx_queues(channel
)) {
380 if (strings
!= NULL
) {
381 snprintf(strings
, ETH_GSTRING_LEN
,
383 channel
->tx_queue
[0].queue
/
386 strings
+= ETH_GSTRING_LEN
;
390 efx_for_each_channel(channel
, efx
) {
391 if (efx_channel_has_rx_queue(channel
)) {
393 if (strings
!= NULL
) {
394 snprintf(strings
, ETH_GSTRING_LEN
,
395 "rx-%d.rx_packets", channel
->channel
);
396 strings
+= ETH_GSTRING_LEN
;
403 static int efx_ethtool_get_sset_count(struct net_device
*net_dev
,
406 struct efx_nic
*efx
= netdev_priv(net_dev
);
408 switch (string_set
) {
410 return efx
->type
->describe_stats(efx
, NULL
) +
411 EFX_ETHTOOL_SW_STAT_COUNT
+
412 efx_describe_per_queue_stats(efx
, NULL
) +
413 efx_ptp_describe_stats(efx
, NULL
);
415 return efx_ethtool_fill_self_tests(efx
, NULL
, NULL
, NULL
);
421 static void efx_ethtool_get_strings(struct net_device
*net_dev
,
422 u32 string_set
, u8
*strings
)
424 struct efx_nic
*efx
= netdev_priv(net_dev
);
427 switch (string_set
) {
429 strings
+= (efx
->type
->describe_stats(efx
, strings
) *
431 for (i
= 0; i
< EFX_ETHTOOL_SW_STAT_COUNT
; i
++)
432 strlcpy(strings
+ i
* ETH_GSTRING_LEN
,
433 efx_sw_stat_desc
[i
].name
, ETH_GSTRING_LEN
);
434 strings
+= EFX_ETHTOOL_SW_STAT_COUNT
* ETH_GSTRING_LEN
;
435 strings
+= (efx_describe_per_queue_stats(efx
, strings
) *
437 efx_ptp_describe_stats(efx
, strings
);
440 efx_ethtool_fill_self_tests(efx
, NULL
, strings
, NULL
);
443 /* No other string sets */
448 static void efx_ethtool_get_stats(struct net_device
*net_dev
,
449 struct ethtool_stats
*stats
,
452 struct efx_nic
*efx
= netdev_priv(net_dev
);
453 const struct efx_sw_stat_desc
*stat
;
454 struct efx_channel
*channel
;
455 struct efx_tx_queue
*tx_queue
;
456 struct efx_rx_queue
*rx_queue
;
459 spin_lock_bh(&efx
->stats_lock
);
461 /* Get NIC statistics */
462 data
+= efx
->type
->update_stats(efx
, data
, NULL
);
464 /* Get software statistics */
465 for (i
= 0; i
< EFX_ETHTOOL_SW_STAT_COUNT
; i
++) {
466 stat
= &efx_sw_stat_desc
[i
];
467 switch (stat
->source
) {
468 case EFX_ETHTOOL_STAT_SOURCE_nic
:
469 data
[i
] = stat
->get_stat((void *)efx
+ stat
->offset
);
471 case EFX_ETHTOOL_STAT_SOURCE_channel
:
473 efx_for_each_channel(channel
, efx
)
474 data
[i
] += stat
->get_stat((void *)channel
+
477 case EFX_ETHTOOL_STAT_SOURCE_tx_queue
:
479 efx_for_each_channel(channel
, efx
) {
480 efx_for_each_channel_tx_queue(tx_queue
, channel
)
482 stat
->get_stat((void *)tx_queue
488 data
+= EFX_ETHTOOL_SW_STAT_COUNT
;
490 spin_unlock_bh(&efx
->stats_lock
);
492 efx_for_each_channel(channel
, efx
) {
493 if (efx_channel_has_tx_queues(channel
)) {
495 efx_for_each_channel_tx_queue(tx_queue
, channel
) {
496 *data
+= tx_queue
->tx_packets
;
501 efx_for_each_channel(channel
, efx
) {
502 if (efx_channel_has_rx_queue(channel
)) {
504 efx_for_each_channel_rx_queue(rx_queue
, channel
) {
505 *data
+= rx_queue
->rx_packets
;
511 efx_ptp_update_stats(efx
, data
);
514 static void efx_ethtool_self_test(struct net_device
*net_dev
,
515 struct ethtool_test
*test
, u64
*data
)
517 struct efx_nic
*efx
= netdev_priv(net_dev
);
518 struct efx_self_tests
*efx_tests
;
522 efx_tests
= kzalloc(sizeof(*efx_tests
), GFP_KERNEL
);
526 if (efx
->state
!= STATE_READY
) {
531 netif_info(efx
, drv
, efx
->net_dev
, "starting %sline testing\n",
532 (test
->flags
& ETH_TEST_FL_OFFLINE
) ? "off" : "on");
534 /* We need rx buffers and interrupts. */
535 already_up
= (efx
->net_dev
->flags
& IFF_UP
);
537 rc
= dev_open(efx
->net_dev
);
539 netif_err(efx
, drv
, efx
->net_dev
,
540 "failed opening device.\n");
545 rc
= efx_selftest(efx
, efx_tests
, test
->flags
);
548 dev_close(efx
->net_dev
);
550 netif_info(efx
, drv
, efx
->net_dev
, "%s %sline self-tests\n",
551 rc
== 0 ? "passed" : "failed",
552 (test
->flags
& ETH_TEST_FL_OFFLINE
) ? "off" : "on");
555 efx_ethtool_fill_self_tests(efx
, efx_tests
, NULL
, data
);
559 test
->flags
|= ETH_TEST_FL_FAILED
;
562 /* Restart autonegotiation */
563 static int efx_ethtool_nway_reset(struct net_device
*net_dev
)
565 struct efx_nic
*efx
= netdev_priv(net_dev
);
567 return mdio45_nway_restart(&efx
->mdio
);
571 * Each channel has a single IRQ and moderation timer, started by any
572 * completion (or other event). Unless the module parameter
573 * separate_tx_channels is set, IRQs and moderation are therefore
574 * shared between RX and TX completions. In this case, when RX IRQ
575 * moderation is explicitly changed then TX IRQ moderation is
576 * automatically changed too, but otherwise we fail if the two values
577 * are requested to be different.
579 * The hardware does not support a limit on the number of completions
580 * before an IRQ, so we do not use the max_frames fields. We should
581 * report and require that max_frames == (usecs != 0), but this would
582 * invalidate existing user documentation.
584 * The hardware does not have distinct settings for interrupt
585 * moderation while the previous IRQ is being handled, so we should
586 * not use the 'irq' fields. However, an earlier developer
587 * misunderstood the meaning of the 'irq' fields and the driver did
588 * not support the standard fields. To avoid invalidating existing
589 * user documentation, we report and accept changes through either the
590 * standard or 'irq' fields. If both are changed at the same time, we
591 * prefer the standard field.
593 * We implement adaptive IRQ moderation, but use a different algorithm
594 * from that assumed in the definition of struct ethtool_coalesce.
595 * Therefore we do not use any of the adaptive moderation parameters
599 static int efx_ethtool_get_coalesce(struct net_device
*net_dev
,
600 struct ethtool_coalesce
*coalesce
)
602 struct efx_nic
*efx
= netdev_priv(net_dev
);
603 unsigned int tx_usecs
, rx_usecs
;
606 efx_get_irq_moderation(efx
, &tx_usecs
, &rx_usecs
, &rx_adaptive
);
608 coalesce
->tx_coalesce_usecs
= tx_usecs
;
609 coalesce
->tx_coalesce_usecs_irq
= tx_usecs
;
610 coalesce
->rx_coalesce_usecs
= rx_usecs
;
611 coalesce
->rx_coalesce_usecs_irq
= rx_usecs
;
612 coalesce
->use_adaptive_rx_coalesce
= rx_adaptive
;
617 static int efx_ethtool_set_coalesce(struct net_device
*net_dev
,
618 struct ethtool_coalesce
*coalesce
)
620 struct efx_nic
*efx
= netdev_priv(net_dev
);
621 struct efx_channel
*channel
;
622 unsigned int tx_usecs
, rx_usecs
;
623 bool adaptive
, rx_may_override_tx
;
626 if (coalesce
->use_adaptive_tx_coalesce
)
629 efx_get_irq_moderation(efx
, &tx_usecs
, &rx_usecs
, &adaptive
);
631 if (coalesce
->rx_coalesce_usecs
!= rx_usecs
)
632 rx_usecs
= coalesce
->rx_coalesce_usecs
;
634 rx_usecs
= coalesce
->rx_coalesce_usecs_irq
;
636 adaptive
= coalesce
->use_adaptive_rx_coalesce
;
638 /* If channels are shared, TX IRQ moderation can be quietly
639 * overridden unless it is changed from its old value.
641 rx_may_override_tx
= (coalesce
->tx_coalesce_usecs
== tx_usecs
&&
642 coalesce
->tx_coalesce_usecs_irq
== tx_usecs
);
643 if (coalesce
->tx_coalesce_usecs
!= tx_usecs
)
644 tx_usecs
= coalesce
->tx_coalesce_usecs
;
646 tx_usecs
= coalesce
->tx_coalesce_usecs_irq
;
648 rc
= efx_init_irq_moderation(efx
, tx_usecs
, rx_usecs
, adaptive
,
653 efx_for_each_channel(channel
, efx
)
654 efx
->type
->push_irq_moderation(channel
);
659 static void efx_ethtool_get_ringparam(struct net_device
*net_dev
,
660 struct ethtool_ringparam
*ring
)
662 struct efx_nic
*efx
= netdev_priv(net_dev
);
664 ring
->rx_max_pending
= EFX_MAX_DMAQ_SIZE
;
665 ring
->tx_max_pending
= EFX_TXQ_MAX_ENT(efx
);
666 ring
->rx_pending
= efx
->rxq_entries
;
667 ring
->tx_pending
= efx
->txq_entries
;
670 static int efx_ethtool_set_ringparam(struct net_device
*net_dev
,
671 struct ethtool_ringparam
*ring
)
673 struct efx_nic
*efx
= netdev_priv(net_dev
);
676 if (ring
->rx_mini_pending
|| ring
->rx_jumbo_pending
||
677 ring
->rx_pending
> EFX_MAX_DMAQ_SIZE
||
678 ring
->tx_pending
> EFX_TXQ_MAX_ENT(efx
))
681 if (ring
->rx_pending
< EFX_RXQ_MIN_ENT
) {
682 netif_err(efx
, drv
, efx
->net_dev
,
683 "RX queues cannot be smaller than %u\n",
688 txq_entries
= max(ring
->tx_pending
, EFX_TXQ_MIN_ENT(efx
));
689 if (txq_entries
!= ring
->tx_pending
)
690 netif_warn(efx
, drv
, efx
->net_dev
,
691 "increasing TX queue size to minimum of %u\n",
694 return efx_realloc_channels(efx
, ring
->rx_pending
, txq_entries
);
697 static int efx_ethtool_set_pauseparam(struct net_device
*net_dev
,
698 struct ethtool_pauseparam
*pause
)
700 struct efx_nic
*efx
= netdev_priv(net_dev
);
701 u8 wanted_fc
, old_fc
;
705 mutex_lock(&efx
->mac_lock
);
707 wanted_fc
= ((pause
->rx_pause
? EFX_FC_RX
: 0) |
708 (pause
->tx_pause
? EFX_FC_TX
: 0) |
709 (pause
->autoneg
? EFX_FC_AUTO
: 0));
711 if ((wanted_fc
& EFX_FC_TX
) && !(wanted_fc
& EFX_FC_RX
)) {
712 netif_dbg(efx
, drv
, efx
->net_dev
,
713 "Flow control unsupported: tx ON rx OFF\n");
718 if ((wanted_fc
& EFX_FC_AUTO
) && !efx
->link_advertising
) {
719 netif_dbg(efx
, drv
, efx
->net_dev
,
720 "Autonegotiation is disabled\n");
725 /* Hook for Falcon bug 11482 workaround */
726 if (efx
->type
->prepare_enable_fc_tx
&&
727 (wanted_fc
& EFX_FC_TX
) && !(efx
->wanted_fc
& EFX_FC_TX
))
728 efx
->type
->prepare_enable_fc_tx(efx
);
730 old_adv
= efx
->link_advertising
;
731 old_fc
= efx
->wanted_fc
;
732 efx_link_set_wanted_fc(efx
, wanted_fc
);
733 if (efx
->link_advertising
!= old_adv
||
734 (efx
->wanted_fc
^ old_fc
) & EFX_FC_AUTO
) {
735 rc
= efx
->phy_op
->reconfigure(efx
);
737 netif_err(efx
, drv
, efx
->net_dev
,
738 "Unable to advertise requested flow "
739 "control setting\n");
744 /* Reconfigure the MAC. The PHY *may* generate a link state change event
745 * if the user just changed the advertised capabilities, but there's no
746 * harm doing this twice */
747 efx_mac_reconfigure(efx
);
750 mutex_unlock(&efx
->mac_lock
);
755 static void efx_ethtool_get_pauseparam(struct net_device
*net_dev
,
756 struct ethtool_pauseparam
*pause
)
758 struct efx_nic
*efx
= netdev_priv(net_dev
);
760 pause
->rx_pause
= !!(efx
->wanted_fc
& EFX_FC_RX
);
761 pause
->tx_pause
= !!(efx
->wanted_fc
& EFX_FC_TX
);
762 pause
->autoneg
= !!(efx
->wanted_fc
& EFX_FC_AUTO
);
765 static void efx_ethtool_get_wol(struct net_device
*net_dev
,
766 struct ethtool_wolinfo
*wol
)
768 struct efx_nic
*efx
= netdev_priv(net_dev
);
769 return efx
->type
->get_wol(efx
, wol
);
773 static int efx_ethtool_set_wol(struct net_device
*net_dev
,
774 struct ethtool_wolinfo
*wol
)
776 struct efx_nic
*efx
= netdev_priv(net_dev
);
777 return efx
->type
->set_wol(efx
, wol
->wolopts
);
780 static int efx_ethtool_reset(struct net_device
*net_dev
, u32
*flags
)
782 struct efx_nic
*efx
= netdev_priv(net_dev
);
785 rc
= efx
->type
->map_reset_flags(flags
);
789 return efx_reset(efx
, rc
);
792 /* MAC address mask including only I/G bit */
793 static const u8 mac_addr_ig_mask
[ETH_ALEN
] __aligned(2) = {0x01, 0, 0, 0, 0, 0};
795 #define IP4_ADDR_FULL_MASK ((__force __be32)~0)
796 #define IP_PROTO_FULL_MASK 0xFF
797 #define PORT_FULL_MASK ((__force __be16)~0)
798 #define ETHER_TYPE_FULL_MASK ((__force __be16)~0)
800 static inline void ip6_fill_mask(__be32
*mask
)
802 mask
[0] = mask
[1] = mask
[2] = mask
[3] = ~(__be32
)0;
805 static int efx_ethtool_get_class_rule(struct efx_nic
*efx
,
806 struct ethtool_rx_flow_spec
*rule
)
808 struct ethtool_tcpip4_spec
*ip_entry
= &rule
->h_u
.tcp_ip4_spec
;
809 struct ethtool_tcpip4_spec
*ip_mask
= &rule
->m_u
.tcp_ip4_spec
;
810 struct ethtool_usrip4_spec
*uip_entry
= &rule
->h_u
.usr_ip4_spec
;
811 struct ethtool_usrip4_spec
*uip_mask
= &rule
->m_u
.usr_ip4_spec
;
812 struct ethtool_tcpip6_spec
*ip6_entry
= &rule
->h_u
.tcp_ip6_spec
;
813 struct ethtool_tcpip6_spec
*ip6_mask
= &rule
->m_u
.tcp_ip6_spec
;
814 struct ethtool_usrip6_spec
*uip6_entry
= &rule
->h_u
.usr_ip6_spec
;
815 struct ethtool_usrip6_spec
*uip6_mask
= &rule
->m_u
.usr_ip6_spec
;
816 struct ethhdr
*mac_entry
= &rule
->h_u
.ether_spec
;
817 struct ethhdr
*mac_mask
= &rule
->m_u
.ether_spec
;
818 struct efx_filter_spec spec
;
821 rc
= efx_filter_get_filter_safe(efx
, EFX_FILTER_PRI_MANUAL
,
822 rule
->location
, &spec
);
826 if (spec
.dmaq_id
== EFX_FILTER_RX_DMAQ_ID_DROP
)
827 rule
->ring_cookie
= RX_CLS_FLOW_DISC
;
829 rule
->ring_cookie
= spec
.dmaq_id
;
831 if ((spec
.match_flags
& EFX_FILTER_MATCH_ETHER_TYPE
) &&
832 spec
.ether_type
== htons(ETH_P_IP
) &&
833 (spec
.match_flags
& EFX_FILTER_MATCH_IP_PROTO
) &&
834 (spec
.ip_proto
== IPPROTO_TCP
|| spec
.ip_proto
== IPPROTO_UDP
) &&
836 ~(EFX_FILTER_MATCH_ETHER_TYPE
| EFX_FILTER_MATCH_OUTER_VID
|
837 EFX_FILTER_MATCH_LOC_HOST
| EFX_FILTER_MATCH_REM_HOST
|
838 EFX_FILTER_MATCH_IP_PROTO
|
839 EFX_FILTER_MATCH_LOC_PORT
| EFX_FILTER_MATCH_REM_PORT
))) {
840 rule
->flow_type
= ((spec
.ip_proto
== IPPROTO_TCP
) ?
841 TCP_V4_FLOW
: UDP_V4_FLOW
);
842 if (spec
.match_flags
& EFX_FILTER_MATCH_LOC_HOST
) {
843 ip_entry
->ip4dst
= spec
.loc_host
[0];
844 ip_mask
->ip4dst
= IP4_ADDR_FULL_MASK
;
846 if (spec
.match_flags
& EFX_FILTER_MATCH_REM_HOST
) {
847 ip_entry
->ip4src
= spec
.rem_host
[0];
848 ip_mask
->ip4src
= IP4_ADDR_FULL_MASK
;
850 if (spec
.match_flags
& EFX_FILTER_MATCH_LOC_PORT
) {
851 ip_entry
->pdst
= spec
.loc_port
;
852 ip_mask
->pdst
= PORT_FULL_MASK
;
854 if (spec
.match_flags
& EFX_FILTER_MATCH_REM_PORT
) {
855 ip_entry
->psrc
= spec
.rem_port
;
856 ip_mask
->psrc
= PORT_FULL_MASK
;
858 } else if ((spec
.match_flags
& EFX_FILTER_MATCH_ETHER_TYPE
) &&
859 spec
.ether_type
== htons(ETH_P_IPV6
) &&
860 (spec
.match_flags
& EFX_FILTER_MATCH_IP_PROTO
) &&
861 (spec
.ip_proto
== IPPROTO_TCP
|| spec
.ip_proto
== IPPROTO_UDP
) &&
863 ~(EFX_FILTER_MATCH_ETHER_TYPE
| EFX_FILTER_MATCH_OUTER_VID
|
864 EFX_FILTER_MATCH_LOC_HOST
| EFX_FILTER_MATCH_REM_HOST
|
865 EFX_FILTER_MATCH_IP_PROTO
|
866 EFX_FILTER_MATCH_LOC_PORT
| EFX_FILTER_MATCH_REM_PORT
))) {
867 rule
->flow_type
= ((spec
.ip_proto
== IPPROTO_TCP
) ?
868 TCP_V6_FLOW
: UDP_V6_FLOW
);
869 if (spec
.match_flags
& EFX_FILTER_MATCH_LOC_HOST
) {
870 memcpy(ip6_entry
->ip6dst
, spec
.loc_host
,
871 sizeof(ip6_entry
->ip6dst
));
872 ip6_fill_mask(ip6_mask
->ip6dst
);
874 if (spec
.match_flags
& EFX_FILTER_MATCH_REM_HOST
) {
875 memcpy(ip6_entry
->ip6src
, spec
.rem_host
,
876 sizeof(ip6_entry
->ip6src
));
877 ip6_fill_mask(ip6_mask
->ip6src
);
879 if (spec
.match_flags
& EFX_FILTER_MATCH_LOC_PORT
) {
880 ip6_entry
->pdst
= spec
.loc_port
;
881 ip6_mask
->pdst
= PORT_FULL_MASK
;
883 if (spec
.match_flags
& EFX_FILTER_MATCH_REM_PORT
) {
884 ip6_entry
->psrc
= spec
.rem_port
;
885 ip6_mask
->psrc
= PORT_FULL_MASK
;
887 } else if (!(spec
.match_flags
&
888 ~(EFX_FILTER_MATCH_LOC_MAC
| EFX_FILTER_MATCH_LOC_MAC_IG
|
889 EFX_FILTER_MATCH_REM_MAC
| EFX_FILTER_MATCH_ETHER_TYPE
|
890 EFX_FILTER_MATCH_OUTER_VID
))) {
891 rule
->flow_type
= ETHER_FLOW
;
892 if (spec
.match_flags
&
893 (EFX_FILTER_MATCH_LOC_MAC
| EFX_FILTER_MATCH_LOC_MAC_IG
)) {
894 ether_addr_copy(mac_entry
->h_dest
, spec
.loc_mac
);
895 if (spec
.match_flags
& EFX_FILTER_MATCH_LOC_MAC
)
896 eth_broadcast_addr(mac_mask
->h_dest
);
898 ether_addr_copy(mac_mask
->h_dest
,
901 if (spec
.match_flags
& EFX_FILTER_MATCH_REM_MAC
) {
902 ether_addr_copy(mac_entry
->h_source
, spec
.rem_mac
);
903 eth_broadcast_addr(mac_mask
->h_source
);
905 if (spec
.match_flags
& EFX_FILTER_MATCH_ETHER_TYPE
) {
906 mac_entry
->h_proto
= spec
.ether_type
;
907 mac_mask
->h_proto
= ETHER_TYPE_FULL_MASK
;
909 } else if (spec
.match_flags
& EFX_FILTER_MATCH_ETHER_TYPE
&&
910 spec
.ether_type
== htons(ETH_P_IP
) &&
912 ~(EFX_FILTER_MATCH_ETHER_TYPE
| EFX_FILTER_MATCH_OUTER_VID
|
913 EFX_FILTER_MATCH_LOC_HOST
| EFX_FILTER_MATCH_REM_HOST
|
914 EFX_FILTER_MATCH_IP_PROTO
))) {
915 rule
->flow_type
= IPV4_USER_FLOW
;
916 uip_entry
->ip_ver
= ETH_RX_NFC_IP4
;
917 if (spec
.match_flags
& EFX_FILTER_MATCH_IP_PROTO
) {
918 uip_mask
->proto
= IP_PROTO_FULL_MASK
;
919 uip_entry
->proto
= spec
.ip_proto
;
921 if (spec
.match_flags
& EFX_FILTER_MATCH_LOC_HOST
) {
922 uip_entry
->ip4dst
= spec
.loc_host
[0];
923 uip_mask
->ip4dst
= IP4_ADDR_FULL_MASK
;
925 if (spec
.match_flags
& EFX_FILTER_MATCH_REM_HOST
) {
926 uip_entry
->ip4src
= spec
.rem_host
[0];
927 uip_mask
->ip4src
= IP4_ADDR_FULL_MASK
;
929 } else if (spec
.match_flags
& EFX_FILTER_MATCH_ETHER_TYPE
&&
930 spec
.ether_type
== htons(ETH_P_IPV6
) &&
932 ~(EFX_FILTER_MATCH_ETHER_TYPE
| EFX_FILTER_MATCH_OUTER_VID
|
933 EFX_FILTER_MATCH_LOC_HOST
| EFX_FILTER_MATCH_REM_HOST
|
934 EFX_FILTER_MATCH_IP_PROTO
))) {
935 rule
->flow_type
= IPV6_USER_FLOW
;
936 if (spec
.match_flags
& EFX_FILTER_MATCH_IP_PROTO
) {
937 uip6_mask
->l4_proto
= IP_PROTO_FULL_MASK
;
938 uip6_entry
->l4_proto
= spec
.ip_proto
;
940 if (spec
.match_flags
& EFX_FILTER_MATCH_LOC_HOST
) {
941 memcpy(uip6_entry
->ip6dst
, spec
.loc_host
,
942 sizeof(uip6_entry
->ip6dst
));
943 ip6_fill_mask(uip6_mask
->ip6dst
);
945 if (spec
.match_flags
& EFX_FILTER_MATCH_REM_HOST
) {
946 memcpy(uip6_entry
->ip6src
, spec
.rem_host
,
947 sizeof(uip6_entry
->ip6src
));
948 ip6_fill_mask(uip6_mask
->ip6src
);
951 /* The above should handle all filters that we insert */
956 if (spec
.match_flags
& EFX_FILTER_MATCH_OUTER_VID
) {
957 rule
->flow_type
|= FLOW_EXT
;
958 rule
->h_ext
.vlan_tci
= spec
.outer_vid
;
959 rule
->m_ext
.vlan_tci
= htons(0xfff);
966 efx_ethtool_get_rxnfc(struct net_device
*net_dev
,
967 struct ethtool_rxnfc
*info
, u32
*rule_locs
)
969 struct efx_nic
*efx
= netdev_priv(net_dev
);
972 case ETHTOOL_GRXRINGS
:
973 info
->data
= efx
->n_rx_channels
;
976 case ETHTOOL_GRXFH
: {
978 if (!efx
->rss_active
) /* No RSS */
980 switch (info
->flow_type
) {
982 if (efx
->rx_hash_udp_4tuple
)
985 info
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
990 info
->data
|= RXH_IP_SRC
| RXH_IP_DST
;
993 if (efx
->rx_hash_udp_4tuple
)
996 info
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
1001 info
->data
|= RXH_IP_SRC
| RXH_IP_DST
;
1009 case ETHTOOL_GRXCLSRLCNT
:
1010 info
->data
= efx_filter_get_rx_id_limit(efx
);
1011 if (info
->data
== 0)
1013 info
->data
|= RX_CLS_LOC_SPECIAL
;
1015 efx_filter_count_rx_used(efx
, EFX_FILTER_PRI_MANUAL
);
1018 case ETHTOOL_GRXCLSRULE
:
1019 if (efx_filter_get_rx_id_limit(efx
) == 0)
1021 return efx_ethtool_get_class_rule(efx
, &info
->fs
);
1023 case ETHTOOL_GRXCLSRLALL
: {
1025 info
->data
= efx_filter_get_rx_id_limit(efx
);
1026 if (info
->data
== 0)
1028 rc
= efx_filter_get_rx_ids(efx
, EFX_FILTER_PRI_MANUAL
,
1029 rule_locs
, info
->rule_cnt
);
1032 info
->rule_cnt
= rc
;
1041 static inline bool ip6_mask_is_full(__be32 mask
[4])
1043 return !~(mask
[0] & mask
[1] & mask
[2] & mask
[3]);
1046 static inline bool ip6_mask_is_empty(__be32 mask
[4])
1048 return !(mask
[0] | mask
[1] | mask
[2] | mask
[3]);
1051 static int efx_ethtool_set_class_rule(struct efx_nic
*efx
,
1052 struct ethtool_rx_flow_spec
*rule
)
1054 struct ethtool_tcpip4_spec
*ip_entry
= &rule
->h_u
.tcp_ip4_spec
;
1055 struct ethtool_tcpip4_spec
*ip_mask
= &rule
->m_u
.tcp_ip4_spec
;
1056 struct ethtool_usrip4_spec
*uip_entry
= &rule
->h_u
.usr_ip4_spec
;
1057 struct ethtool_usrip4_spec
*uip_mask
= &rule
->m_u
.usr_ip4_spec
;
1058 struct ethtool_tcpip6_spec
*ip6_entry
= &rule
->h_u
.tcp_ip6_spec
;
1059 struct ethtool_tcpip6_spec
*ip6_mask
= &rule
->m_u
.tcp_ip6_spec
;
1060 struct ethtool_usrip6_spec
*uip6_entry
= &rule
->h_u
.usr_ip6_spec
;
1061 struct ethtool_usrip6_spec
*uip6_mask
= &rule
->m_u
.usr_ip6_spec
;
1062 struct ethhdr
*mac_entry
= &rule
->h_u
.ether_spec
;
1063 struct ethhdr
*mac_mask
= &rule
->m_u
.ether_spec
;
1064 struct efx_filter_spec spec
;
1067 /* Check that user wants us to choose the location */
1068 if (rule
->location
!= RX_CLS_LOC_ANY
)
1071 /* Range-check ring_cookie */
1072 if (rule
->ring_cookie
>= efx
->n_rx_channels
&&
1073 rule
->ring_cookie
!= RX_CLS_FLOW_DISC
)
1076 /* Check for unsupported extensions */
1077 if ((rule
->flow_type
& FLOW_EXT
) &&
1078 (rule
->m_ext
.vlan_etype
|| rule
->m_ext
.data
[0] ||
1079 rule
->m_ext
.data
[1]))
1082 efx_filter_init_rx(&spec
, EFX_FILTER_PRI_MANUAL
,
1083 efx
->rx_scatter
? EFX_FILTER_FLAG_RX_SCATTER
: 0,
1084 (rule
->ring_cookie
== RX_CLS_FLOW_DISC
) ?
1085 EFX_FILTER_RX_DMAQ_ID_DROP
: rule
->ring_cookie
);
1087 switch (rule
->flow_type
& ~FLOW_EXT
) {
1090 spec
.match_flags
= (EFX_FILTER_MATCH_ETHER_TYPE
|
1091 EFX_FILTER_MATCH_IP_PROTO
);
1092 spec
.ether_type
= htons(ETH_P_IP
);
1093 spec
.ip_proto
= ((rule
->flow_type
& ~FLOW_EXT
) == TCP_V4_FLOW
?
1094 IPPROTO_TCP
: IPPROTO_UDP
);
1095 if (ip_mask
->ip4dst
) {
1096 if (ip_mask
->ip4dst
!= IP4_ADDR_FULL_MASK
)
1098 spec
.match_flags
|= EFX_FILTER_MATCH_LOC_HOST
;
1099 spec
.loc_host
[0] = ip_entry
->ip4dst
;
1101 if (ip_mask
->ip4src
) {
1102 if (ip_mask
->ip4src
!= IP4_ADDR_FULL_MASK
)
1104 spec
.match_flags
|= EFX_FILTER_MATCH_REM_HOST
;
1105 spec
.rem_host
[0] = ip_entry
->ip4src
;
1107 if (ip_mask
->pdst
) {
1108 if (ip_mask
->pdst
!= PORT_FULL_MASK
)
1110 spec
.match_flags
|= EFX_FILTER_MATCH_LOC_PORT
;
1111 spec
.loc_port
= ip_entry
->pdst
;
1113 if (ip_mask
->psrc
) {
1114 if (ip_mask
->psrc
!= PORT_FULL_MASK
)
1116 spec
.match_flags
|= EFX_FILTER_MATCH_REM_PORT
;
1117 spec
.rem_port
= ip_entry
->psrc
;
1125 spec
.match_flags
= (EFX_FILTER_MATCH_ETHER_TYPE
|
1126 EFX_FILTER_MATCH_IP_PROTO
);
1127 spec
.ether_type
= htons(ETH_P_IPV6
);
1128 spec
.ip_proto
= ((rule
->flow_type
& ~FLOW_EXT
) == TCP_V6_FLOW
?
1129 IPPROTO_TCP
: IPPROTO_UDP
);
1130 if (!ip6_mask_is_empty(ip6_mask
->ip6dst
)) {
1131 if (!ip6_mask_is_full(ip6_mask
->ip6dst
))
1133 spec
.match_flags
|= EFX_FILTER_MATCH_LOC_HOST
;
1134 memcpy(spec
.loc_host
, ip6_entry
->ip6dst
, sizeof(spec
.loc_host
));
1136 if (!ip6_mask_is_empty(ip6_mask
->ip6src
)) {
1137 if (!ip6_mask_is_full(ip6_mask
->ip6src
))
1139 spec
.match_flags
|= EFX_FILTER_MATCH_REM_HOST
;
1140 memcpy(spec
.rem_host
, ip6_entry
->ip6src
, sizeof(spec
.rem_host
));
1142 if (ip6_mask
->pdst
) {
1143 if (ip6_mask
->pdst
!= PORT_FULL_MASK
)
1145 spec
.match_flags
|= EFX_FILTER_MATCH_LOC_PORT
;
1146 spec
.loc_port
= ip6_entry
->pdst
;
1148 if (ip6_mask
->psrc
) {
1149 if (ip6_mask
->psrc
!= PORT_FULL_MASK
)
1151 spec
.match_flags
|= EFX_FILTER_MATCH_REM_PORT
;
1152 spec
.rem_port
= ip6_entry
->psrc
;
1154 if (ip6_mask
->tclass
)
1158 case IPV4_USER_FLOW
:
1159 if (uip_mask
->l4_4_bytes
|| uip_mask
->tos
|| uip_mask
->ip_ver
||
1160 uip_entry
->ip_ver
!= ETH_RX_NFC_IP4
)
1162 spec
.match_flags
= EFX_FILTER_MATCH_ETHER_TYPE
;
1163 spec
.ether_type
= htons(ETH_P_IP
);
1164 if (uip_mask
->ip4dst
) {
1165 if (uip_mask
->ip4dst
!= IP4_ADDR_FULL_MASK
)
1167 spec
.match_flags
|= EFX_FILTER_MATCH_LOC_HOST
;
1168 spec
.loc_host
[0] = uip_entry
->ip4dst
;
1170 if (uip_mask
->ip4src
) {
1171 if (uip_mask
->ip4src
!= IP4_ADDR_FULL_MASK
)
1173 spec
.match_flags
|= EFX_FILTER_MATCH_REM_HOST
;
1174 spec
.rem_host
[0] = uip_entry
->ip4src
;
1176 if (uip_mask
->proto
) {
1177 if (uip_mask
->proto
!= IP_PROTO_FULL_MASK
)
1179 spec
.match_flags
|= EFX_FILTER_MATCH_IP_PROTO
;
1180 spec
.ip_proto
= uip_entry
->proto
;
1184 case IPV6_USER_FLOW
:
1185 if (uip6_mask
->l4_4_bytes
|| uip6_mask
->tclass
)
1187 spec
.match_flags
= EFX_FILTER_MATCH_ETHER_TYPE
;
1188 spec
.ether_type
= htons(ETH_P_IPV6
);
1189 if (!ip6_mask_is_empty(uip6_mask
->ip6dst
)) {
1190 if (!ip6_mask_is_full(uip6_mask
->ip6dst
))
1192 spec
.match_flags
|= EFX_FILTER_MATCH_LOC_HOST
;
1193 memcpy(spec
.loc_host
, uip6_entry
->ip6dst
, sizeof(spec
.loc_host
));
1195 if (!ip6_mask_is_empty(uip6_mask
->ip6src
)) {
1196 if (!ip6_mask_is_full(uip6_mask
->ip6src
))
1198 spec
.match_flags
|= EFX_FILTER_MATCH_REM_HOST
;
1199 memcpy(spec
.rem_host
, uip6_entry
->ip6src
, sizeof(spec
.rem_host
));
1201 if (uip6_mask
->l4_proto
) {
1202 if (uip6_mask
->l4_proto
!= IP_PROTO_FULL_MASK
)
1204 spec
.match_flags
|= EFX_FILTER_MATCH_IP_PROTO
;
1205 spec
.ip_proto
= uip6_entry
->l4_proto
;
1210 if (!is_zero_ether_addr(mac_mask
->h_dest
)) {
1211 if (ether_addr_equal(mac_mask
->h_dest
,
1213 spec
.match_flags
|= EFX_FILTER_MATCH_LOC_MAC_IG
;
1214 else if (is_broadcast_ether_addr(mac_mask
->h_dest
))
1215 spec
.match_flags
|= EFX_FILTER_MATCH_LOC_MAC
;
1218 ether_addr_copy(spec
.loc_mac
, mac_entry
->h_dest
);
1220 if (!is_zero_ether_addr(mac_mask
->h_source
)) {
1221 if (!is_broadcast_ether_addr(mac_mask
->h_source
))
1223 spec
.match_flags
|= EFX_FILTER_MATCH_REM_MAC
;
1224 ether_addr_copy(spec
.rem_mac
, mac_entry
->h_source
);
1226 if (mac_mask
->h_proto
) {
1227 if (mac_mask
->h_proto
!= ETHER_TYPE_FULL_MASK
)
1229 spec
.match_flags
|= EFX_FILTER_MATCH_ETHER_TYPE
;
1230 spec
.ether_type
= mac_entry
->h_proto
;
1238 if ((rule
->flow_type
& FLOW_EXT
) && rule
->m_ext
.vlan_tci
) {
1239 if (rule
->m_ext
.vlan_tci
!= htons(0xfff))
1241 spec
.match_flags
|= EFX_FILTER_MATCH_OUTER_VID
;
1242 spec
.outer_vid
= rule
->h_ext
.vlan_tci
;
1245 rc
= efx_filter_insert_filter(efx
, &spec
, true);
1249 rule
->location
= rc
;
1253 static int efx_ethtool_set_rxnfc(struct net_device
*net_dev
,
1254 struct ethtool_rxnfc
*info
)
1256 struct efx_nic
*efx
= netdev_priv(net_dev
);
1258 if (efx_filter_get_rx_id_limit(efx
) == 0)
1261 switch (info
->cmd
) {
1262 case ETHTOOL_SRXCLSRLINS
:
1263 return efx_ethtool_set_class_rule(efx
, &info
->fs
);
1265 case ETHTOOL_SRXCLSRLDEL
:
1266 return efx_filter_remove_id_safe(efx
, EFX_FILTER_PRI_MANUAL
,
1274 static u32
efx_ethtool_get_rxfh_indir_size(struct net_device
*net_dev
)
1276 struct efx_nic
*efx
= netdev_priv(net_dev
);
1278 return (efx
->n_rx_channels
== 1) ? 0 : ARRAY_SIZE(efx
->rx_indir_table
);
1281 static int efx_ethtool_get_rxfh(struct net_device
*net_dev
, u32
*indir
, u8
*key
,
1284 struct efx_nic
*efx
= netdev_priv(net_dev
);
1287 *hfunc
= ETH_RSS_HASH_TOP
;
1289 memcpy(indir
, efx
->rx_indir_table
, sizeof(efx
->rx_indir_table
));
1293 static int efx_ethtool_set_rxfh(struct net_device
*net_dev
, const u32
*indir
,
1294 const u8
*key
, const u8 hfunc
)
1296 struct efx_nic
*efx
= netdev_priv(net_dev
);
1298 /* We do not allow change in unsupported parameters */
1300 (hfunc
!= ETH_RSS_HASH_NO_CHANGE
&& hfunc
!= ETH_RSS_HASH_TOP
))
1305 return efx
->type
->rx_push_rss_config(efx
, true, indir
);
1308 static int efx_ethtool_get_ts_info(struct net_device
*net_dev
,
1309 struct ethtool_ts_info
*ts_info
)
1311 struct efx_nic
*efx
= netdev_priv(net_dev
);
1313 /* Software capabilities */
1314 ts_info
->so_timestamping
= (SOF_TIMESTAMPING_RX_SOFTWARE
|
1315 SOF_TIMESTAMPING_SOFTWARE
);
1316 ts_info
->phc_index
= -1;
1318 efx_ptp_get_ts_info(efx
, ts_info
);
1322 static int efx_ethtool_get_module_eeprom(struct net_device
*net_dev
,
1323 struct ethtool_eeprom
*ee
,
1326 struct efx_nic
*efx
= netdev_priv(net_dev
);
1329 if (!efx
->phy_op
|| !efx
->phy_op
->get_module_eeprom
)
1332 mutex_lock(&efx
->mac_lock
);
1333 ret
= efx
->phy_op
->get_module_eeprom(efx
, ee
, data
);
1334 mutex_unlock(&efx
->mac_lock
);
1339 static int efx_ethtool_get_module_info(struct net_device
*net_dev
,
1340 struct ethtool_modinfo
*modinfo
)
1342 struct efx_nic
*efx
= netdev_priv(net_dev
);
1345 if (!efx
->phy_op
|| !efx
->phy_op
->get_module_info
)
1348 mutex_lock(&efx
->mac_lock
);
1349 ret
= efx
->phy_op
->get_module_info(efx
, modinfo
);
1350 mutex_unlock(&efx
->mac_lock
);
1355 const struct ethtool_ops efx_ethtool_ops
= {
1356 .get_drvinfo
= efx_ethtool_get_drvinfo
,
1357 .get_regs_len
= efx_ethtool_get_regs_len
,
1358 .get_regs
= efx_ethtool_get_regs
,
1359 .get_msglevel
= efx_ethtool_get_msglevel
,
1360 .set_msglevel
= efx_ethtool_set_msglevel
,
1361 .nway_reset
= efx_ethtool_nway_reset
,
1362 .get_link
= ethtool_op_get_link
,
1363 .get_coalesce
= efx_ethtool_get_coalesce
,
1364 .set_coalesce
= efx_ethtool_set_coalesce
,
1365 .get_ringparam
= efx_ethtool_get_ringparam
,
1366 .set_ringparam
= efx_ethtool_set_ringparam
,
1367 .get_pauseparam
= efx_ethtool_get_pauseparam
,
1368 .set_pauseparam
= efx_ethtool_set_pauseparam
,
1369 .get_sset_count
= efx_ethtool_get_sset_count
,
1370 .self_test
= efx_ethtool_self_test
,
1371 .get_strings
= efx_ethtool_get_strings
,
1372 .set_phys_id
= efx_ethtool_phys_id
,
1373 .get_ethtool_stats
= efx_ethtool_get_stats
,
1374 .get_wol
= efx_ethtool_get_wol
,
1375 .set_wol
= efx_ethtool_set_wol
,
1376 .reset
= efx_ethtool_reset
,
1377 .get_rxnfc
= efx_ethtool_get_rxnfc
,
1378 .set_rxnfc
= efx_ethtool_set_rxnfc
,
1379 .get_rxfh_indir_size
= efx_ethtool_get_rxfh_indir_size
,
1380 .get_rxfh
= efx_ethtool_get_rxfh
,
1381 .set_rxfh
= efx_ethtool_set_rxfh
,
1382 .get_ts_info
= efx_ethtool_get_ts_info
,
1383 .get_module_info
= efx_ethtool_get_module_info
,
1384 .get_module_eeprom
= efx_ethtool_get_module_eeprom
,
1385 .get_link_ksettings
= efx_ethtool_get_link_ksettings
,
1386 .set_link_ksettings
= efx_ethtool_set_link_ksettings
,