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 ef4_sw_stat_desc
{
25 EF4_ETHTOOL_STAT_SOURCE_nic
,
26 EF4_ETHTOOL_STAT_SOURCE_channel
,
27 EF4_ETHTOOL_STAT_SOURCE_tx_queue
30 u64(*get_stat
) (void *field
); /* Reader function */
33 /* Initialiser for a struct ef4_sw_stat_desc with type-checking */
34 #define EF4_ETHTOOL_STAT(stat_name, source_name, field, field_type, \
35 get_stat_function) { \
37 .source = EF4_ETHTOOL_STAT_SOURCE_##source_name, \
38 .offset = ((((field_type *) 0) == \
39 &((struct ef4_##source_name *)0)->field) ? \
40 offsetof(struct ef4_##source_name, field) : \
41 offsetof(struct ef4_##source_name, field)), \
42 .get_stat = get_stat_function, \
45 static u64
ef4_get_uint_stat(void *field
)
47 return *(unsigned int *)field
;
50 static u64
ef4_get_atomic_stat(void *field
)
52 return atomic_read((atomic_t
*) field
);
55 #define EF4_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field) \
56 EF4_ETHTOOL_STAT(field, nic, field, \
57 atomic_t, ef4_get_atomic_stat)
59 #define EF4_ETHTOOL_UINT_CHANNEL_STAT(field) \
60 EF4_ETHTOOL_STAT(field, channel, n_##field, \
61 unsigned int, ef4_get_uint_stat)
63 #define EF4_ETHTOOL_UINT_TXQ_STAT(field) \
64 EF4_ETHTOOL_STAT(tx_##field, tx_queue, field, \
65 unsigned int, ef4_get_uint_stat)
67 static const struct ef4_sw_stat_desc ef4_sw_stat_desc
[] = {
68 EF4_ETHTOOL_UINT_TXQ_STAT(merge_events
),
69 EF4_ETHTOOL_UINT_TXQ_STAT(pushes
),
70 EF4_ETHTOOL_UINT_TXQ_STAT(cb_packets
),
71 EF4_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset
),
72 EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc
),
73 EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err
),
74 EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err
),
75 EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch
),
76 EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc
),
77 EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_events
),
78 EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_packets
),
81 #define EF4_ETHTOOL_SW_STAT_COUNT ARRAY_SIZE(ef4_sw_stat_desc)
83 #define EF4_ETHTOOL_EEPROM_MAGIC 0xEFAB
85 /**************************************************************************
89 **************************************************************************
92 /* Identify device by flashing LEDs */
93 static int ef4_ethtool_phys_id(struct net_device
*net_dev
,
94 enum ethtool_phys_id_state state
)
96 struct ef4_nic
*efx
= netdev_priv(net_dev
);
97 enum ef4_led_mode mode
= EF4_LED_DEFAULT
;
106 case ETHTOOL_ID_INACTIVE
:
107 mode
= EF4_LED_DEFAULT
;
109 case ETHTOOL_ID_ACTIVE
:
110 return 1; /* cycle on/off once per second */
113 efx
->type
->set_id_led(efx
, mode
);
117 /* This must be called with rtnl_lock held. */
119 ef4_ethtool_get_link_ksettings(struct net_device
*net_dev
,
120 struct ethtool_link_ksettings
*cmd
)
122 struct ef4_nic
*efx
= netdev_priv(net_dev
);
123 struct ef4_link_state
*link_state
= &efx
->link_state
;
125 mutex_lock(&efx
->mac_lock
);
126 efx
->phy_op
->get_link_ksettings(efx
, cmd
);
127 mutex_unlock(&efx
->mac_lock
);
129 /* Both MACs support pause frames (bidirectional and respond-only) */
130 ethtool_link_ksettings_add_link_mode(cmd
, supported
, Pause
);
131 ethtool_link_ksettings_add_link_mode(cmd
, supported
, Asym_Pause
);
133 if (LOOPBACK_INTERNAL(efx
)) {
134 cmd
->base
.speed
= link_state
->speed
;
135 cmd
->base
.duplex
= link_state
->fd
? DUPLEX_FULL
: DUPLEX_HALF
;
141 /* This must be called with rtnl_lock held. */
143 ef4_ethtool_set_link_ksettings(struct net_device
*net_dev
,
144 const struct ethtool_link_ksettings
*cmd
)
146 struct ef4_nic
*efx
= netdev_priv(net_dev
);
149 /* GMAC does not support 1000Mbps HD */
150 if ((cmd
->base
.speed
== SPEED_1000
) &&
151 (cmd
->base
.duplex
!= DUPLEX_FULL
)) {
152 netif_dbg(efx
, drv
, efx
->net_dev
,
153 "rejecting unsupported 1000Mbps HD setting\n");
157 mutex_lock(&efx
->mac_lock
);
158 rc
= efx
->phy_op
->set_link_ksettings(efx
, cmd
);
159 mutex_unlock(&efx
->mac_lock
);
163 static void ef4_ethtool_get_drvinfo(struct net_device
*net_dev
,
164 struct ethtool_drvinfo
*info
)
166 struct ef4_nic
*efx
= netdev_priv(net_dev
);
168 strlcpy(info
->driver
, KBUILD_MODNAME
, sizeof(info
->driver
));
169 strlcpy(info
->version
, EF4_DRIVER_VERSION
, sizeof(info
->version
));
170 strlcpy(info
->bus_info
, pci_name(efx
->pci_dev
), sizeof(info
->bus_info
));
173 static int ef4_ethtool_get_regs_len(struct net_device
*net_dev
)
175 return ef4_nic_get_regs_len(netdev_priv(net_dev
));
178 static void ef4_ethtool_get_regs(struct net_device
*net_dev
,
179 struct ethtool_regs
*regs
, void *buf
)
181 struct ef4_nic
*efx
= netdev_priv(net_dev
);
183 regs
->version
= efx
->type
->revision
;
184 ef4_nic_get_regs(efx
, buf
);
187 static u32
ef4_ethtool_get_msglevel(struct net_device
*net_dev
)
189 struct ef4_nic
*efx
= netdev_priv(net_dev
);
190 return efx
->msg_enable
;
193 static void ef4_ethtool_set_msglevel(struct net_device
*net_dev
, u32 msg_enable
)
195 struct ef4_nic
*efx
= netdev_priv(net_dev
);
196 efx
->msg_enable
= msg_enable
;
200 * ef4_fill_test - fill in an individual self-test entry
201 * @test_index: Index of the test
202 * @strings: Ethtool strings, or %NULL
203 * @data: Ethtool test results, or %NULL
204 * @test: Pointer to test result (used only if data != %NULL)
205 * @unit_format: Unit name format (e.g. "chan\%d")
206 * @unit_id: Unit id (e.g. 0 for "chan0")
207 * @test_format: Test name format (e.g. "loopback.\%s.tx.sent")
208 * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
210 * Fill in an individual self-test entry.
212 static void ef4_fill_test(unsigned int test_index
, u8
*strings
, u64
*data
,
213 int *test
, const char *unit_format
, int unit_id
,
214 const char *test_format
, const char *test_id
)
216 char unit_str
[ETH_GSTRING_LEN
], test_str
[ETH_GSTRING_LEN
];
218 /* Fill data value, if applicable */
220 data
[test_index
] = *test
;
222 /* Fill string, if applicable */
224 if (strchr(unit_format
, '%'))
225 snprintf(unit_str
, sizeof(unit_str
),
226 unit_format
, unit_id
);
228 strcpy(unit_str
, unit_format
);
229 snprintf(test_str
, sizeof(test_str
), test_format
, test_id
);
230 snprintf(strings
+ test_index
* ETH_GSTRING_LEN
,
232 "%-6s %-24s", unit_str
, test_str
);
236 #define EF4_CHANNEL_NAME(_channel) "chan%d", _channel->channel
237 #define EF4_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
238 #define EF4_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
239 #define EF4_LOOPBACK_NAME(_mode, _counter) \
240 "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, ef4_loopback_mode)
243 * ef4_fill_loopback_test - fill in a block of loopback self-test entries
245 * @lb_tests: Efx loopback self-test results structure
246 * @mode: Loopback test mode
247 * @test_index: Starting index of the test
248 * @strings: Ethtool strings, or %NULL
249 * @data: Ethtool test results, or %NULL
251 * Fill in a block of loopback self-test entries. Return new test
254 static int ef4_fill_loopback_test(struct ef4_nic
*efx
,
255 struct ef4_loopback_self_tests
*lb_tests
,
256 enum ef4_loopback_mode mode
,
257 unsigned int test_index
,
258 u8
*strings
, u64
*data
)
260 struct ef4_channel
*channel
=
261 ef4_get_channel(efx
, efx
->tx_channel_offset
);
262 struct ef4_tx_queue
*tx_queue
;
264 ef4_for_each_channel_tx_queue(tx_queue
, channel
) {
265 ef4_fill_test(test_index
++, strings
, data
,
266 &lb_tests
->tx_sent
[tx_queue
->queue
],
267 EF4_TX_QUEUE_NAME(tx_queue
),
268 EF4_LOOPBACK_NAME(mode
, "tx_sent"));
269 ef4_fill_test(test_index
++, strings
, data
,
270 &lb_tests
->tx_done
[tx_queue
->queue
],
271 EF4_TX_QUEUE_NAME(tx_queue
),
272 EF4_LOOPBACK_NAME(mode
, "tx_done"));
274 ef4_fill_test(test_index
++, strings
, data
,
277 EF4_LOOPBACK_NAME(mode
, "rx_good"));
278 ef4_fill_test(test_index
++, strings
, data
,
281 EF4_LOOPBACK_NAME(mode
, "rx_bad"));
287 * ef4_ethtool_fill_self_tests - get self-test details
289 * @tests: Efx self-test results structure, or %NULL
290 * @strings: Ethtool strings, or %NULL
291 * @data: Ethtool test results, or %NULL
293 * Get self-test number of strings, strings, and/or test results.
294 * Return number of strings (== number of test results).
296 * The reason for merging these three functions is to make sure that
297 * they can never be inconsistent.
299 static int ef4_ethtool_fill_self_tests(struct ef4_nic
*efx
,
300 struct ef4_self_tests
*tests
,
301 u8
*strings
, u64
*data
)
303 struct ef4_channel
*channel
;
304 unsigned int n
= 0, i
;
305 enum ef4_loopback_mode mode
;
307 ef4_fill_test(n
++, strings
, data
, &tests
->phy_alive
,
308 "phy", 0, "alive", NULL
);
309 ef4_fill_test(n
++, strings
, data
, &tests
->nvram
,
310 "core", 0, "nvram", NULL
);
311 ef4_fill_test(n
++, strings
, data
, &tests
->interrupt
,
312 "core", 0, "interrupt", NULL
);
315 ef4_for_each_channel(channel
, efx
) {
316 ef4_fill_test(n
++, strings
, data
,
317 &tests
->eventq_dma
[channel
->channel
],
318 EF4_CHANNEL_NAME(channel
),
320 ef4_fill_test(n
++, strings
, data
,
321 &tests
->eventq_int
[channel
->channel
],
322 EF4_CHANNEL_NAME(channel
),
326 ef4_fill_test(n
++, strings
, data
, &tests
->memory
,
327 "core", 0, "memory", NULL
);
328 ef4_fill_test(n
++, strings
, data
, &tests
->registers
,
329 "core", 0, "registers", NULL
);
331 if (efx
->phy_op
->run_tests
!= NULL
) {
332 EF4_BUG_ON_PARANOID(efx
->phy_op
->test_name
== NULL
);
334 for (i
= 0; true; ++i
) {
337 EF4_BUG_ON_PARANOID(i
>= EF4_MAX_PHY_TESTS
);
338 name
= efx
->phy_op
->test_name(efx
, i
);
342 ef4_fill_test(n
++, strings
, data
, &tests
->phy_ext
[i
],
343 "phy", 0, name
, NULL
);
348 for (mode
= LOOPBACK_NONE
; mode
<= LOOPBACK_TEST_MAX
; mode
++) {
349 if (!(efx
->loopback_modes
& (1 << mode
)))
351 n
= ef4_fill_loopback_test(efx
,
352 &tests
->loopback
[mode
], mode
, n
,
359 static size_t ef4_describe_per_queue_stats(struct ef4_nic
*efx
, u8
*strings
)
362 struct ef4_channel
*channel
;
364 ef4_for_each_channel(channel
, efx
) {
365 if (ef4_channel_has_tx_queues(channel
)) {
367 if (strings
!= NULL
) {
368 snprintf(strings
, ETH_GSTRING_LEN
,
370 channel
->tx_queue
[0].queue
/
373 strings
+= ETH_GSTRING_LEN
;
377 ef4_for_each_channel(channel
, efx
) {
378 if (ef4_channel_has_rx_queue(channel
)) {
380 if (strings
!= NULL
) {
381 snprintf(strings
, ETH_GSTRING_LEN
,
382 "rx-%d.rx_packets", channel
->channel
);
383 strings
+= ETH_GSTRING_LEN
;
390 static int ef4_ethtool_get_sset_count(struct net_device
*net_dev
,
393 struct ef4_nic
*efx
= netdev_priv(net_dev
);
395 switch (string_set
) {
397 return efx
->type
->describe_stats(efx
, NULL
) +
398 EF4_ETHTOOL_SW_STAT_COUNT
+
399 ef4_describe_per_queue_stats(efx
, NULL
);
401 return ef4_ethtool_fill_self_tests(efx
, NULL
, NULL
, NULL
);
407 static void ef4_ethtool_get_strings(struct net_device
*net_dev
,
408 u32 string_set
, u8
*strings
)
410 struct ef4_nic
*efx
= netdev_priv(net_dev
);
413 switch (string_set
) {
415 strings
+= (efx
->type
->describe_stats(efx
, strings
) *
417 for (i
= 0; i
< EF4_ETHTOOL_SW_STAT_COUNT
; i
++)
418 strlcpy(strings
+ i
* ETH_GSTRING_LEN
,
419 ef4_sw_stat_desc
[i
].name
, ETH_GSTRING_LEN
);
420 strings
+= EF4_ETHTOOL_SW_STAT_COUNT
* ETH_GSTRING_LEN
;
421 strings
+= (ef4_describe_per_queue_stats(efx
, strings
) *
425 ef4_ethtool_fill_self_tests(efx
, NULL
, strings
, NULL
);
428 /* No other string sets */
433 static void ef4_ethtool_get_stats(struct net_device
*net_dev
,
434 struct ethtool_stats
*stats
,
437 struct ef4_nic
*efx
= netdev_priv(net_dev
);
438 const struct ef4_sw_stat_desc
*stat
;
439 struct ef4_channel
*channel
;
440 struct ef4_tx_queue
*tx_queue
;
441 struct ef4_rx_queue
*rx_queue
;
444 spin_lock_bh(&efx
->stats_lock
);
446 /* Get NIC statistics */
447 data
+= efx
->type
->update_stats(efx
, data
, NULL
);
449 /* Get software statistics */
450 for (i
= 0; i
< EF4_ETHTOOL_SW_STAT_COUNT
; i
++) {
451 stat
= &ef4_sw_stat_desc
[i
];
452 switch (stat
->source
) {
453 case EF4_ETHTOOL_STAT_SOURCE_nic
:
454 data
[i
] = stat
->get_stat((void *)efx
+ stat
->offset
);
456 case EF4_ETHTOOL_STAT_SOURCE_channel
:
458 ef4_for_each_channel(channel
, efx
)
459 data
[i
] += stat
->get_stat((void *)channel
+
462 case EF4_ETHTOOL_STAT_SOURCE_tx_queue
:
464 ef4_for_each_channel(channel
, efx
) {
465 ef4_for_each_channel_tx_queue(tx_queue
, channel
)
467 stat
->get_stat((void *)tx_queue
473 data
+= EF4_ETHTOOL_SW_STAT_COUNT
;
475 spin_unlock_bh(&efx
->stats_lock
);
477 ef4_for_each_channel(channel
, efx
) {
478 if (ef4_channel_has_tx_queues(channel
)) {
480 ef4_for_each_channel_tx_queue(tx_queue
, channel
) {
481 *data
+= tx_queue
->tx_packets
;
486 ef4_for_each_channel(channel
, efx
) {
487 if (ef4_channel_has_rx_queue(channel
)) {
489 ef4_for_each_channel_rx_queue(rx_queue
, channel
) {
490 *data
+= rx_queue
->rx_packets
;
497 static void ef4_ethtool_self_test(struct net_device
*net_dev
,
498 struct ethtool_test
*test
, u64
*data
)
500 struct ef4_nic
*efx
= netdev_priv(net_dev
);
501 struct ef4_self_tests
*ef4_tests
;
505 ef4_tests
= kzalloc(sizeof(*ef4_tests
), GFP_KERNEL
);
509 if (efx
->state
!= STATE_READY
) {
514 netif_info(efx
, drv
, efx
->net_dev
, "starting %sline testing\n",
515 (test
->flags
& ETH_TEST_FL_OFFLINE
) ? "off" : "on");
517 /* We need rx buffers and interrupts. */
518 already_up
= (efx
->net_dev
->flags
& IFF_UP
);
520 rc
= dev_open(efx
->net_dev
);
522 netif_err(efx
, drv
, efx
->net_dev
,
523 "failed opening device.\n");
528 rc
= ef4_selftest(efx
, ef4_tests
, test
->flags
);
531 dev_close(efx
->net_dev
);
533 netif_info(efx
, drv
, efx
->net_dev
, "%s %sline self-tests\n",
534 rc
== 0 ? "passed" : "failed",
535 (test
->flags
& ETH_TEST_FL_OFFLINE
) ? "off" : "on");
538 ef4_ethtool_fill_self_tests(efx
, ef4_tests
, NULL
, data
);
542 test
->flags
|= ETH_TEST_FL_FAILED
;
545 /* Restart autonegotiation */
546 static int ef4_ethtool_nway_reset(struct net_device
*net_dev
)
548 struct ef4_nic
*efx
= netdev_priv(net_dev
);
550 return mdio45_nway_restart(&efx
->mdio
);
554 * Each channel has a single IRQ and moderation timer, started by any
555 * completion (or other event). Unless the module parameter
556 * separate_tx_channels is set, IRQs and moderation are therefore
557 * shared between RX and TX completions. In this case, when RX IRQ
558 * moderation is explicitly changed then TX IRQ moderation is
559 * automatically changed too, but otherwise we fail if the two values
560 * are requested to be different.
562 * The hardware does not support a limit on the number of completions
563 * before an IRQ, so we do not use the max_frames fields. We should
564 * report and require that max_frames == (usecs != 0), but this would
565 * invalidate existing user documentation.
567 * The hardware does not have distinct settings for interrupt
568 * moderation while the previous IRQ is being handled, so we should
569 * not use the 'irq' fields. However, an earlier developer
570 * misunderstood the meaning of the 'irq' fields and the driver did
571 * not support the standard fields. To avoid invalidating existing
572 * user documentation, we report and accept changes through either the
573 * standard or 'irq' fields. If both are changed at the same time, we
574 * prefer the standard field.
576 * We implement adaptive IRQ moderation, but use a different algorithm
577 * from that assumed in the definition of struct ethtool_coalesce.
578 * Therefore we do not use any of the adaptive moderation parameters
582 static int ef4_ethtool_get_coalesce(struct net_device
*net_dev
,
583 struct ethtool_coalesce
*coalesce
)
585 struct ef4_nic
*efx
= netdev_priv(net_dev
);
586 unsigned int tx_usecs
, rx_usecs
;
589 ef4_get_irq_moderation(efx
, &tx_usecs
, &rx_usecs
, &rx_adaptive
);
591 coalesce
->tx_coalesce_usecs
= tx_usecs
;
592 coalesce
->tx_coalesce_usecs_irq
= tx_usecs
;
593 coalesce
->rx_coalesce_usecs
= rx_usecs
;
594 coalesce
->rx_coalesce_usecs_irq
= rx_usecs
;
595 coalesce
->use_adaptive_rx_coalesce
= rx_adaptive
;
600 static int ef4_ethtool_set_coalesce(struct net_device
*net_dev
,
601 struct ethtool_coalesce
*coalesce
)
603 struct ef4_nic
*efx
= netdev_priv(net_dev
);
604 struct ef4_channel
*channel
;
605 unsigned int tx_usecs
, rx_usecs
;
606 bool adaptive
, rx_may_override_tx
;
609 if (coalesce
->use_adaptive_tx_coalesce
)
612 ef4_get_irq_moderation(efx
, &tx_usecs
, &rx_usecs
, &adaptive
);
614 if (coalesce
->rx_coalesce_usecs
!= rx_usecs
)
615 rx_usecs
= coalesce
->rx_coalesce_usecs
;
617 rx_usecs
= coalesce
->rx_coalesce_usecs_irq
;
619 adaptive
= coalesce
->use_adaptive_rx_coalesce
;
621 /* If channels are shared, TX IRQ moderation can be quietly
622 * overridden unless it is changed from its old value.
624 rx_may_override_tx
= (coalesce
->tx_coalesce_usecs
== tx_usecs
&&
625 coalesce
->tx_coalesce_usecs_irq
== tx_usecs
);
626 if (coalesce
->tx_coalesce_usecs
!= tx_usecs
)
627 tx_usecs
= coalesce
->tx_coalesce_usecs
;
629 tx_usecs
= coalesce
->tx_coalesce_usecs_irq
;
631 rc
= ef4_init_irq_moderation(efx
, tx_usecs
, rx_usecs
, adaptive
,
636 ef4_for_each_channel(channel
, efx
)
637 efx
->type
->push_irq_moderation(channel
);
642 static void ef4_ethtool_get_ringparam(struct net_device
*net_dev
,
643 struct ethtool_ringparam
*ring
)
645 struct ef4_nic
*efx
= netdev_priv(net_dev
);
647 ring
->rx_max_pending
= EF4_MAX_DMAQ_SIZE
;
648 ring
->tx_max_pending
= EF4_MAX_DMAQ_SIZE
;
649 ring
->rx_pending
= efx
->rxq_entries
;
650 ring
->tx_pending
= efx
->txq_entries
;
653 static int ef4_ethtool_set_ringparam(struct net_device
*net_dev
,
654 struct ethtool_ringparam
*ring
)
656 struct ef4_nic
*efx
= netdev_priv(net_dev
);
659 if (ring
->rx_mini_pending
|| ring
->rx_jumbo_pending
||
660 ring
->rx_pending
> EF4_MAX_DMAQ_SIZE
||
661 ring
->tx_pending
> EF4_MAX_DMAQ_SIZE
)
664 if (ring
->rx_pending
< EF4_RXQ_MIN_ENT
) {
665 netif_err(efx
, drv
, efx
->net_dev
,
666 "RX queues cannot be smaller than %u\n",
671 txq_entries
= max(ring
->tx_pending
, EF4_TXQ_MIN_ENT(efx
));
672 if (txq_entries
!= ring
->tx_pending
)
673 netif_warn(efx
, drv
, efx
->net_dev
,
674 "increasing TX queue size to minimum of %u\n",
677 return ef4_realloc_channels(efx
, ring
->rx_pending
, txq_entries
);
680 static int ef4_ethtool_set_pauseparam(struct net_device
*net_dev
,
681 struct ethtool_pauseparam
*pause
)
683 struct ef4_nic
*efx
= netdev_priv(net_dev
);
684 u8 wanted_fc
, old_fc
;
688 mutex_lock(&efx
->mac_lock
);
690 wanted_fc
= ((pause
->rx_pause
? EF4_FC_RX
: 0) |
691 (pause
->tx_pause
? EF4_FC_TX
: 0) |
692 (pause
->autoneg
? EF4_FC_AUTO
: 0));
694 if ((wanted_fc
& EF4_FC_TX
) && !(wanted_fc
& EF4_FC_RX
)) {
695 netif_dbg(efx
, drv
, efx
->net_dev
,
696 "Flow control unsupported: tx ON rx OFF\n");
701 if ((wanted_fc
& EF4_FC_AUTO
) && !efx
->link_advertising
) {
702 netif_dbg(efx
, drv
, efx
->net_dev
,
703 "Autonegotiation is disabled\n");
708 /* Hook for Falcon bug 11482 workaround */
709 if (efx
->type
->prepare_enable_fc_tx
&&
710 (wanted_fc
& EF4_FC_TX
) && !(efx
->wanted_fc
& EF4_FC_TX
))
711 efx
->type
->prepare_enable_fc_tx(efx
);
713 old_adv
= efx
->link_advertising
;
714 old_fc
= efx
->wanted_fc
;
715 ef4_link_set_wanted_fc(efx
, wanted_fc
);
716 if (efx
->link_advertising
!= old_adv
||
717 (efx
->wanted_fc
^ old_fc
) & EF4_FC_AUTO
) {
718 rc
= efx
->phy_op
->reconfigure(efx
);
720 netif_err(efx
, drv
, efx
->net_dev
,
721 "Unable to advertise requested flow "
722 "control setting\n");
727 /* Reconfigure the MAC. The PHY *may* generate a link state change event
728 * if the user just changed the advertised capabilities, but there's no
729 * harm doing this twice */
730 ef4_mac_reconfigure(efx
);
733 mutex_unlock(&efx
->mac_lock
);
738 static void ef4_ethtool_get_pauseparam(struct net_device
*net_dev
,
739 struct ethtool_pauseparam
*pause
)
741 struct ef4_nic
*efx
= netdev_priv(net_dev
);
743 pause
->rx_pause
= !!(efx
->wanted_fc
& EF4_FC_RX
);
744 pause
->tx_pause
= !!(efx
->wanted_fc
& EF4_FC_TX
);
745 pause
->autoneg
= !!(efx
->wanted_fc
& EF4_FC_AUTO
);
748 static void ef4_ethtool_get_wol(struct net_device
*net_dev
,
749 struct ethtool_wolinfo
*wol
)
751 struct ef4_nic
*efx
= netdev_priv(net_dev
);
752 return efx
->type
->get_wol(efx
, wol
);
756 static int ef4_ethtool_set_wol(struct net_device
*net_dev
,
757 struct ethtool_wolinfo
*wol
)
759 struct ef4_nic
*efx
= netdev_priv(net_dev
);
760 return efx
->type
->set_wol(efx
, wol
->wolopts
);
763 static int ef4_ethtool_reset(struct net_device
*net_dev
, u32
*flags
)
765 struct ef4_nic
*efx
= netdev_priv(net_dev
);
768 rc
= efx
->type
->map_reset_flags(flags
);
772 return ef4_reset(efx
, rc
);
775 /* MAC address mask including only I/G bit */
776 static const u8 mac_addr_ig_mask
[ETH_ALEN
] __aligned(2) = {0x01, 0, 0, 0, 0, 0};
778 #define IP4_ADDR_FULL_MASK ((__force __be32)~0)
779 #define IP_PROTO_FULL_MASK 0xFF
780 #define PORT_FULL_MASK ((__force __be16)~0)
781 #define ETHER_TYPE_FULL_MASK ((__force __be16)~0)
783 static inline void ip6_fill_mask(__be32
*mask
)
785 mask
[0] = mask
[1] = mask
[2] = mask
[3] = ~(__be32
)0;
788 static int ef4_ethtool_get_class_rule(struct ef4_nic
*efx
,
789 struct ethtool_rx_flow_spec
*rule
)
791 struct ethtool_tcpip4_spec
*ip_entry
= &rule
->h_u
.tcp_ip4_spec
;
792 struct ethtool_tcpip4_spec
*ip_mask
= &rule
->m_u
.tcp_ip4_spec
;
793 struct ethtool_usrip4_spec
*uip_entry
= &rule
->h_u
.usr_ip4_spec
;
794 struct ethtool_usrip4_spec
*uip_mask
= &rule
->m_u
.usr_ip4_spec
;
795 struct ethtool_tcpip6_spec
*ip6_entry
= &rule
->h_u
.tcp_ip6_spec
;
796 struct ethtool_tcpip6_spec
*ip6_mask
= &rule
->m_u
.tcp_ip6_spec
;
797 struct ethtool_usrip6_spec
*uip6_entry
= &rule
->h_u
.usr_ip6_spec
;
798 struct ethtool_usrip6_spec
*uip6_mask
= &rule
->m_u
.usr_ip6_spec
;
799 struct ethhdr
*mac_entry
= &rule
->h_u
.ether_spec
;
800 struct ethhdr
*mac_mask
= &rule
->m_u
.ether_spec
;
801 struct ef4_filter_spec spec
;
804 rc
= ef4_filter_get_filter_safe(efx
, EF4_FILTER_PRI_MANUAL
,
805 rule
->location
, &spec
);
809 if (spec
.dmaq_id
== EF4_FILTER_RX_DMAQ_ID_DROP
)
810 rule
->ring_cookie
= RX_CLS_FLOW_DISC
;
812 rule
->ring_cookie
= spec
.dmaq_id
;
814 if ((spec
.match_flags
& EF4_FILTER_MATCH_ETHER_TYPE
) &&
815 spec
.ether_type
== htons(ETH_P_IP
) &&
816 (spec
.match_flags
& EF4_FILTER_MATCH_IP_PROTO
) &&
817 (spec
.ip_proto
== IPPROTO_TCP
|| spec
.ip_proto
== IPPROTO_UDP
) &&
819 ~(EF4_FILTER_MATCH_ETHER_TYPE
| EF4_FILTER_MATCH_OUTER_VID
|
820 EF4_FILTER_MATCH_LOC_HOST
| EF4_FILTER_MATCH_REM_HOST
|
821 EF4_FILTER_MATCH_IP_PROTO
|
822 EF4_FILTER_MATCH_LOC_PORT
| EF4_FILTER_MATCH_REM_PORT
))) {
823 rule
->flow_type
= ((spec
.ip_proto
== IPPROTO_TCP
) ?
824 TCP_V4_FLOW
: UDP_V4_FLOW
);
825 if (spec
.match_flags
& EF4_FILTER_MATCH_LOC_HOST
) {
826 ip_entry
->ip4dst
= spec
.loc_host
[0];
827 ip_mask
->ip4dst
= IP4_ADDR_FULL_MASK
;
829 if (spec
.match_flags
& EF4_FILTER_MATCH_REM_HOST
) {
830 ip_entry
->ip4src
= spec
.rem_host
[0];
831 ip_mask
->ip4src
= IP4_ADDR_FULL_MASK
;
833 if (spec
.match_flags
& EF4_FILTER_MATCH_LOC_PORT
) {
834 ip_entry
->pdst
= spec
.loc_port
;
835 ip_mask
->pdst
= PORT_FULL_MASK
;
837 if (spec
.match_flags
& EF4_FILTER_MATCH_REM_PORT
) {
838 ip_entry
->psrc
= spec
.rem_port
;
839 ip_mask
->psrc
= PORT_FULL_MASK
;
841 } else if ((spec
.match_flags
& EF4_FILTER_MATCH_ETHER_TYPE
) &&
842 spec
.ether_type
== htons(ETH_P_IPV6
) &&
843 (spec
.match_flags
& EF4_FILTER_MATCH_IP_PROTO
) &&
844 (spec
.ip_proto
== IPPROTO_TCP
|| spec
.ip_proto
== IPPROTO_UDP
) &&
846 ~(EF4_FILTER_MATCH_ETHER_TYPE
| EF4_FILTER_MATCH_OUTER_VID
|
847 EF4_FILTER_MATCH_LOC_HOST
| EF4_FILTER_MATCH_REM_HOST
|
848 EF4_FILTER_MATCH_IP_PROTO
|
849 EF4_FILTER_MATCH_LOC_PORT
| EF4_FILTER_MATCH_REM_PORT
))) {
850 rule
->flow_type
= ((spec
.ip_proto
== IPPROTO_TCP
) ?
851 TCP_V6_FLOW
: UDP_V6_FLOW
);
852 if (spec
.match_flags
& EF4_FILTER_MATCH_LOC_HOST
) {
853 memcpy(ip6_entry
->ip6dst
, spec
.loc_host
,
854 sizeof(ip6_entry
->ip6dst
));
855 ip6_fill_mask(ip6_mask
->ip6dst
);
857 if (spec
.match_flags
& EF4_FILTER_MATCH_REM_HOST
) {
858 memcpy(ip6_entry
->ip6src
, spec
.rem_host
,
859 sizeof(ip6_entry
->ip6src
));
860 ip6_fill_mask(ip6_mask
->ip6src
);
862 if (spec
.match_flags
& EF4_FILTER_MATCH_LOC_PORT
) {
863 ip6_entry
->pdst
= spec
.loc_port
;
864 ip6_mask
->pdst
= PORT_FULL_MASK
;
866 if (spec
.match_flags
& EF4_FILTER_MATCH_REM_PORT
) {
867 ip6_entry
->psrc
= spec
.rem_port
;
868 ip6_mask
->psrc
= PORT_FULL_MASK
;
870 } else if (!(spec
.match_flags
&
871 ~(EF4_FILTER_MATCH_LOC_MAC
| EF4_FILTER_MATCH_LOC_MAC_IG
|
872 EF4_FILTER_MATCH_REM_MAC
| EF4_FILTER_MATCH_ETHER_TYPE
|
873 EF4_FILTER_MATCH_OUTER_VID
))) {
874 rule
->flow_type
= ETHER_FLOW
;
875 if (spec
.match_flags
&
876 (EF4_FILTER_MATCH_LOC_MAC
| EF4_FILTER_MATCH_LOC_MAC_IG
)) {
877 ether_addr_copy(mac_entry
->h_dest
, spec
.loc_mac
);
878 if (spec
.match_flags
& EF4_FILTER_MATCH_LOC_MAC
)
879 eth_broadcast_addr(mac_mask
->h_dest
);
881 ether_addr_copy(mac_mask
->h_dest
,
884 if (spec
.match_flags
& EF4_FILTER_MATCH_REM_MAC
) {
885 ether_addr_copy(mac_entry
->h_source
, spec
.rem_mac
);
886 eth_broadcast_addr(mac_mask
->h_source
);
888 if (spec
.match_flags
& EF4_FILTER_MATCH_ETHER_TYPE
) {
889 mac_entry
->h_proto
= spec
.ether_type
;
890 mac_mask
->h_proto
= ETHER_TYPE_FULL_MASK
;
892 } else if (spec
.match_flags
& EF4_FILTER_MATCH_ETHER_TYPE
&&
893 spec
.ether_type
== htons(ETH_P_IP
) &&
895 ~(EF4_FILTER_MATCH_ETHER_TYPE
| EF4_FILTER_MATCH_OUTER_VID
|
896 EF4_FILTER_MATCH_LOC_HOST
| EF4_FILTER_MATCH_REM_HOST
|
897 EF4_FILTER_MATCH_IP_PROTO
))) {
898 rule
->flow_type
= IPV4_USER_FLOW
;
899 uip_entry
->ip_ver
= ETH_RX_NFC_IP4
;
900 if (spec
.match_flags
& EF4_FILTER_MATCH_IP_PROTO
) {
901 uip_mask
->proto
= IP_PROTO_FULL_MASK
;
902 uip_entry
->proto
= spec
.ip_proto
;
904 if (spec
.match_flags
& EF4_FILTER_MATCH_LOC_HOST
) {
905 uip_entry
->ip4dst
= spec
.loc_host
[0];
906 uip_mask
->ip4dst
= IP4_ADDR_FULL_MASK
;
908 if (spec
.match_flags
& EF4_FILTER_MATCH_REM_HOST
) {
909 uip_entry
->ip4src
= spec
.rem_host
[0];
910 uip_mask
->ip4src
= IP4_ADDR_FULL_MASK
;
912 } else if (spec
.match_flags
& EF4_FILTER_MATCH_ETHER_TYPE
&&
913 spec
.ether_type
== htons(ETH_P_IPV6
) &&
915 ~(EF4_FILTER_MATCH_ETHER_TYPE
| EF4_FILTER_MATCH_OUTER_VID
|
916 EF4_FILTER_MATCH_LOC_HOST
| EF4_FILTER_MATCH_REM_HOST
|
917 EF4_FILTER_MATCH_IP_PROTO
))) {
918 rule
->flow_type
= IPV6_USER_FLOW
;
919 if (spec
.match_flags
& EF4_FILTER_MATCH_IP_PROTO
) {
920 uip6_mask
->l4_proto
= IP_PROTO_FULL_MASK
;
921 uip6_entry
->l4_proto
= spec
.ip_proto
;
923 if (spec
.match_flags
& EF4_FILTER_MATCH_LOC_HOST
) {
924 memcpy(uip6_entry
->ip6dst
, spec
.loc_host
,
925 sizeof(uip6_entry
->ip6dst
));
926 ip6_fill_mask(uip6_mask
->ip6dst
);
928 if (spec
.match_flags
& EF4_FILTER_MATCH_REM_HOST
) {
929 memcpy(uip6_entry
->ip6src
, spec
.rem_host
,
930 sizeof(uip6_entry
->ip6src
));
931 ip6_fill_mask(uip6_mask
->ip6src
);
934 /* The above should handle all filters that we insert */
939 if (spec
.match_flags
& EF4_FILTER_MATCH_OUTER_VID
) {
940 rule
->flow_type
|= FLOW_EXT
;
941 rule
->h_ext
.vlan_tci
= spec
.outer_vid
;
942 rule
->m_ext
.vlan_tci
= htons(0xfff);
949 ef4_ethtool_get_rxnfc(struct net_device
*net_dev
,
950 struct ethtool_rxnfc
*info
, u32
*rule_locs
)
952 struct ef4_nic
*efx
= netdev_priv(net_dev
);
955 case ETHTOOL_GRXRINGS
:
956 info
->data
= efx
->n_rx_channels
;
959 case ETHTOOL_GRXFH
: {
960 unsigned min_revision
= 0;
963 switch (info
->flow_type
) {
965 info
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
970 info
->data
|= RXH_IP_SRC
| RXH_IP_DST
;
971 min_revision
= EF4_REV_FALCON_B0
;
976 if (ef4_nic_rev(efx
) < min_revision
)
981 case ETHTOOL_GRXCLSRLCNT
:
982 info
->data
= ef4_filter_get_rx_id_limit(efx
);
985 info
->data
|= RX_CLS_LOC_SPECIAL
;
987 ef4_filter_count_rx_used(efx
, EF4_FILTER_PRI_MANUAL
);
990 case ETHTOOL_GRXCLSRULE
:
991 if (ef4_filter_get_rx_id_limit(efx
) == 0)
993 return ef4_ethtool_get_class_rule(efx
, &info
->fs
);
995 case ETHTOOL_GRXCLSRLALL
: {
997 info
->data
= ef4_filter_get_rx_id_limit(efx
);
1000 rc
= ef4_filter_get_rx_ids(efx
, EF4_FILTER_PRI_MANUAL
,
1001 rule_locs
, info
->rule_cnt
);
1004 info
->rule_cnt
= rc
;
1013 static inline bool ip6_mask_is_full(__be32 mask
[4])
1015 return !~(mask
[0] & mask
[1] & mask
[2] & mask
[3]);
1018 static inline bool ip6_mask_is_empty(__be32 mask
[4])
1020 return !(mask
[0] | mask
[1] | mask
[2] | mask
[3]);
1023 static int ef4_ethtool_set_class_rule(struct ef4_nic
*efx
,
1024 struct ethtool_rx_flow_spec
*rule
)
1026 struct ethtool_tcpip4_spec
*ip_entry
= &rule
->h_u
.tcp_ip4_spec
;
1027 struct ethtool_tcpip4_spec
*ip_mask
= &rule
->m_u
.tcp_ip4_spec
;
1028 struct ethtool_usrip4_spec
*uip_entry
= &rule
->h_u
.usr_ip4_spec
;
1029 struct ethtool_usrip4_spec
*uip_mask
= &rule
->m_u
.usr_ip4_spec
;
1030 struct ethtool_tcpip6_spec
*ip6_entry
= &rule
->h_u
.tcp_ip6_spec
;
1031 struct ethtool_tcpip6_spec
*ip6_mask
= &rule
->m_u
.tcp_ip6_spec
;
1032 struct ethtool_usrip6_spec
*uip6_entry
= &rule
->h_u
.usr_ip6_spec
;
1033 struct ethtool_usrip6_spec
*uip6_mask
= &rule
->m_u
.usr_ip6_spec
;
1034 struct ethhdr
*mac_entry
= &rule
->h_u
.ether_spec
;
1035 struct ethhdr
*mac_mask
= &rule
->m_u
.ether_spec
;
1036 struct ef4_filter_spec spec
;
1039 /* Check that user wants us to choose the location */
1040 if (rule
->location
!= RX_CLS_LOC_ANY
)
1043 /* Range-check ring_cookie */
1044 if (rule
->ring_cookie
>= efx
->n_rx_channels
&&
1045 rule
->ring_cookie
!= RX_CLS_FLOW_DISC
)
1048 /* Check for unsupported extensions */
1049 if ((rule
->flow_type
& FLOW_EXT
) &&
1050 (rule
->m_ext
.vlan_etype
|| rule
->m_ext
.data
[0] ||
1051 rule
->m_ext
.data
[1]))
1054 ef4_filter_init_rx(&spec
, EF4_FILTER_PRI_MANUAL
,
1055 efx
->rx_scatter
? EF4_FILTER_FLAG_RX_SCATTER
: 0,
1056 (rule
->ring_cookie
== RX_CLS_FLOW_DISC
) ?
1057 EF4_FILTER_RX_DMAQ_ID_DROP
: rule
->ring_cookie
);
1059 switch (rule
->flow_type
& ~FLOW_EXT
) {
1062 spec
.match_flags
= (EF4_FILTER_MATCH_ETHER_TYPE
|
1063 EF4_FILTER_MATCH_IP_PROTO
);
1064 spec
.ether_type
= htons(ETH_P_IP
);
1065 spec
.ip_proto
= ((rule
->flow_type
& ~FLOW_EXT
) == TCP_V4_FLOW
?
1066 IPPROTO_TCP
: IPPROTO_UDP
);
1067 if (ip_mask
->ip4dst
) {
1068 if (ip_mask
->ip4dst
!= IP4_ADDR_FULL_MASK
)
1070 spec
.match_flags
|= EF4_FILTER_MATCH_LOC_HOST
;
1071 spec
.loc_host
[0] = ip_entry
->ip4dst
;
1073 if (ip_mask
->ip4src
) {
1074 if (ip_mask
->ip4src
!= IP4_ADDR_FULL_MASK
)
1076 spec
.match_flags
|= EF4_FILTER_MATCH_REM_HOST
;
1077 spec
.rem_host
[0] = ip_entry
->ip4src
;
1079 if (ip_mask
->pdst
) {
1080 if (ip_mask
->pdst
!= PORT_FULL_MASK
)
1082 spec
.match_flags
|= EF4_FILTER_MATCH_LOC_PORT
;
1083 spec
.loc_port
= ip_entry
->pdst
;
1085 if (ip_mask
->psrc
) {
1086 if (ip_mask
->psrc
!= PORT_FULL_MASK
)
1088 spec
.match_flags
|= EF4_FILTER_MATCH_REM_PORT
;
1089 spec
.rem_port
= ip_entry
->psrc
;
1097 spec
.match_flags
= (EF4_FILTER_MATCH_ETHER_TYPE
|
1098 EF4_FILTER_MATCH_IP_PROTO
);
1099 spec
.ether_type
= htons(ETH_P_IPV6
);
1100 spec
.ip_proto
= ((rule
->flow_type
& ~FLOW_EXT
) == TCP_V6_FLOW
?
1101 IPPROTO_TCP
: IPPROTO_UDP
);
1102 if (!ip6_mask_is_empty(ip6_mask
->ip6dst
)) {
1103 if (!ip6_mask_is_full(ip6_mask
->ip6dst
))
1105 spec
.match_flags
|= EF4_FILTER_MATCH_LOC_HOST
;
1106 memcpy(spec
.loc_host
, ip6_entry
->ip6dst
, sizeof(spec
.loc_host
));
1108 if (!ip6_mask_is_empty(ip6_mask
->ip6src
)) {
1109 if (!ip6_mask_is_full(ip6_mask
->ip6src
))
1111 spec
.match_flags
|= EF4_FILTER_MATCH_REM_HOST
;
1112 memcpy(spec
.rem_host
, ip6_entry
->ip6src
, sizeof(spec
.rem_host
));
1114 if (ip6_mask
->pdst
) {
1115 if (ip6_mask
->pdst
!= PORT_FULL_MASK
)
1117 spec
.match_flags
|= EF4_FILTER_MATCH_LOC_PORT
;
1118 spec
.loc_port
= ip6_entry
->pdst
;
1120 if (ip6_mask
->psrc
) {
1121 if (ip6_mask
->psrc
!= PORT_FULL_MASK
)
1123 spec
.match_flags
|= EF4_FILTER_MATCH_REM_PORT
;
1124 spec
.rem_port
= ip6_entry
->psrc
;
1126 if (ip6_mask
->tclass
)
1130 case IPV4_USER_FLOW
:
1131 if (uip_mask
->l4_4_bytes
|| uip_mask
->tos
|| uip_mask
->ip_ver
||
1132 uip_entry
->ip_ver
!= ETH_RX_NFC_IP4
)
1134 spec
.match_flags
= EF4_FILTER_MATCH_ETHER_TYPE
;
1135 spec
.ether_type
= htons(ETH_P_IP
);
1136 if (uip_mask
->ip4dst
) {
1137 if (uip_mask
->ip4dst
!= IP4_ADDR_FULL_MASK
)
1139 spec
.match_flags
|= EF4_FILTER_MATCH_LOC_HOST
;
1140 spec
.loc_host
[0] = uip_entry
->ip4dst
;
1142 if (uip_mask
->ip4src
) {
1143 if (uip_mask
->ip4src
!= IP4_ADDR_FULL_MASK
)
1145 spec
.match_flags
|= EF4_FILTER_MATCH_REM_HOST
;
1146 spec
.rem_host
[0] = uip_entry
->ip4src
;
1148 if (uip_mask
->proto
) {
1149 if (uip_mask
->proto
!= IP_PROTO_FULL_MASK
)
1151 spec
.match_flags
|= EF4_FILTER_MATCH_IP_PROTO
;
1152 spec
.ip_proto
= uip_entry
->proto
;
1156 case IPV6_USER_FLOW
:
1157 if (uip6_mask
->l4_4_bytes
|| uip6_mask
->tclass
)
1159 spec
.match_flags
= EF4_FILTER_MATCH_ETHER_TYPE
;
1160 spec
.ether_type
= htons(ETH_P_IPV6
);
1161 if (!ip6_mask_is_empty(uip6_mask
->ip6dst
)) {
1162 if (!ip6_mask_is_full(uip6_mask
->ip6dst
))
1164 spec
.match_flags
|= EF4_FILTER_MATCH_LOC_HOST
;
1165 memcpy(spec
.loc_host
, uip6_entry
->ip6dst
, sizeof(spec
.loc_host
));
1167 if (!ip6_mask_is_empty(uip6_mask
->ip6src
)) {
1168 if (!ip6_mask_is_full(uip6_mask
->ip6src
))
1170 spec
.match_flags
|= EF4_FILTER_MATCH_REM_HOST
;
1171 memcpy(spec
.rem_host
, uip6_entry
->ip6src
, sizeof(spec
.rem_host
));
1173 if (uip6_mask
->l4_proto
) {
1174 if (uip6_mask
->l4_proto
!= IP_PROTO_FULL_MASK
)
1176 spec
.match_flags
|= EF4_FILTER_MATCH_IP_PROTO
;
1177 spec
.ip_proto
= uip6_entry
->l4_proto
;
1182 if (!is_zero_ether_addr(mac_mask
->h_dest
)) {
1183 if (ether_addr_equal(mac_mask
->h_dest
,
1185 spec
.match_flags
|= EF4_FILTER_MATCH_LOC_MAC_IG
;
1186 else if (is_broadcast_ether_addr(mac_mask
->h_dest
))
1187 spec
.match_flags
|= EF4_FILTER_MATCH_LOC_MAC
;
1190 ether_addr_copy(spec
.loc_mac
, mac_entry
->h_dest
);
1192 if (!is_zero_ether_addr(mac_mask
->h_source
)) {
1193 if (!is_broadcast_ether_addr(mac_mask
->h_source
))
1195 spec
.match_flags
|= EF4_FILTER_MATCH_REM_MAC
;
1196 ether_addr_copy(spec
.rem_mac
, mac_entry
->h_source
);
1198 if (mac_mask
->h_proto
) {
1199 if (mac_mask
->h_proto
!= ETHER_TYPE_FULL_MASK
)
1201 spec
.match_flags
|= EF4_FILTER_MATCH_ETHER_TYPE
;
1202 spec
.ether_type
= mac_entry
->h_proto
;
1210 if ((rule
->flow_type
& FLOW_EXT
) && rule
->m_ext
.vlan_tci
) {
1211 if (rule
->m_ext
.vlan_tci
!= htons(0xfff))
1213 spec
.match_flags
|= EF4_FILTER_MATCH_OUTER_VID
;
1214 spec
.outer_vid
= rule
->h_ext
.vlan_tci
;
1217 rc
= ef4_filter_insert_filter(efx
, &spec
, true);
1221 rule
->location
= rc
;
1225 static int ef4_ethtool_set_rxnfc(struct net_device
*net_dev
,
1226 struct ethtool_rxnfc
*info
)
1228 struct ef4_nic
*efx
= netdev_priv(net_dev
);
1230 if (ef4_filter_get_rx_id_limit(efx
) == 0)
1233 switch (info
->cmd
) {
1234 case ETHTOOL_SRXCLSRLINS
:
1235 return ef4_ethtool_set_class_rule(efx
, &info
->fs
);
1237 case ETHTOOL_SRXCLSRLDEL
:
1238 return ef4_filter_remove_id_safe(efx
, EF4_FILTER_PRI_MANUAL
,
1246 static u32
ef4_ethtool_get_rxfh_indir_size(struct net_device
*net_dev
)
1248 struct ef4_nic
*efx
= netdev_priv(net_dev
);
1250 return ((ef4_nic_rev(efx
) < EF4_REV_FALCON_B0
||
1251 efx
->n_rx_channels
== 1) ?
1252 0 : ARRAY_SIZE(efx
->rx_indir_table
));
1255 static int ef4_ethtool_get_rxfh(struct net_device
*net_dev
, u32
*indir
, u8
*key
,
1258 struct ef4_nic
*efx
= netdev_priv(net_dev
);
1261 *hfunc
= ETH_RSS_HASH_TOP
;
1263 memcpy(indir
, efx
->rx_indir_table
, sizeof(efx
->rx_indir_table
));
1267 static int ef4_ethtool_set_rxfh(struct net_device
*net_dev
, const u32
*indir
,
1268 const u8
*key
, const u8 hfunc
)
1270 struct ef4_nic
*efx
= netdev_priv(net_dev
);
1272 /* We do not allow change in unsupported parameters */
1274 (hfunc
!= ETH_RSS_HASH_NO_CHANGE
&& hfunc
!= ETH_RSS_HASH_TOP
))
1279 return efx
->type
->rx_push_rss_config(efx
, true, indir
);
1282 static int ef4_ethtool_get_module_eeprom(struct net_device
*net_dev
,
1283 struct ethtool_eeprom
*ee
,
1286 struct ef4_nic
*efx
= netdev_priv(net_dev
);
1289 if (!efx
->phy_op
|| !efx
->phy_op
->get_module_eeprom
)
1292 mutex_lock(&efx
->mac_lock
);
1293 ret
= efx
->phy_op
->get_module_eeprom(efx
, ee
, data
);
1294 mutex_unlock(&efx
->mac_lock
);
1299 static int ef4_ethtool_get_module_info(struct net_device
*net_dev
,
1300 struct ethtool_modinfo
*modinfo
)
1302 struct ef4_nic
*efx
= netdev_priv(net_dev
);
1305 if (!efx
->phy_op
|| !efx
->phy_op
->get_module_info
)
1308 mutex_lock(&efx
->mac_lock
);
1309 ret
= efx
->phy_op
->get_module_info(efx
, modinfo
);
1310 mutex_unlock(&efx
->mac_lock
);
1315 const struct ethtool_ops ef4_ethtool_ops
= {
1316 .get_drvinfo
= ef4_ethtool_get_drvinfo
,
1317 .get_regs_len
= ef4_ethtool_get_regs_len
,
1318 .get_regs
= ef4_ethtool_get_regs
,
1319 .get_msglevel
= ef4_ethtool_get_msglevel
,
1320 .set_msglevel
= ef4_ethtool_set_msglevel
,
1321 .nway_reset
= ef4_ethtool_nway_reset
,
1322 .get_link
= ethtool_op_get_link
,
1323 .get_coalesce
= ef4_ethtool_get_coalesce
,
1324 .set_coalesce
= ef4_ethtool_set_coalesce
,
1325 .get_ringparam
= ef4_ethtool_get_ringparam
,
1326 .set_ringparam
= ef4_ethtool_set_ringparam
,
1327 .get_pauseparam
= ef4_ethtool_get_pauseparam
,
1328 .set_pauseparam
= ef4_ethtool_set_pauseparam
,
1329 .get_sset_count
= ef4_ethtool_get_sset_count
,
1330 .self_test
= ef4_ethtool_self_test
,
1331 .get_strings
= ef4_ethtool_get_strings
,
1332 .set_phys_id
= ef4_ethtool_phys_id
,
1333 .get_ethtool_stats
= ef4_ethtool_get_stats
,
1334 .get_wol
= ef4_ethtool_get_wol
,
1335 .set_wol
= ef4_ethtool_set_wol
,
1336 .reset
= ef4_ethtool_reset
,
1337 .get_rxnfc
= ef4_ethtool_get_rxnfc
,
1338 .set_rxnfc
= ef4_ethtool_set_rxnfc
,
1339 .get_rxfh_indir_size
= ef4_ethtool_get_rxfh_indir_size
,
1340 .get_rxfh
= ef4_ethtool_get_rxfh
,
1341 .set_rxfh
= ef4_ethtool_set_rxfh
,
1342 .get_module_info
= ef4_ethtool_get_module_info
,
1343 .get_module_eeprom
= ef4_ethtool_get_module_eeprom
,
1344 .get_link_ksettings
= ef4_ethtool_get_link_ksettings
,
1345 .set_link_ksettings
= ef4_ethtool_set_link_ksettings
,