1 /****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
4 * Copyright 2006-2010 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(pushes
),
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_mcast_mismatch
),
78 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc
),
79 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_nodesc_trunc
),
82 #define EFX_ETHTOOL_SW_STAT_COUNT ARRAY_SIZE(efx_sw_stat_desc)
84 #define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB
86 /**************************************************************************
90 **************************************************************************
93 /* Identify device by flashing LEDs */
94 static int efx_ethtool_phys_id(struct net_device
*net_dev
,
95 enum ethtool_phys_id_state state
)
97 struct efx_nic
*efx
= netdev_priv(net_dev
);
98 enum efx_led_mode mode
= EFX_LED_DEFAULT
;
107 case ETHTOOL_ID_INACTIVE
:
108 mode
= EFX_LED_DEFAULT
;
110 case ETHTOOL_ID_ACTIVE
:
111 return 1; /* cycle on/off once per second */
114 efx
->type
->set_id_led(efx
, mode
);
118 /* This must be called with rtnl_lock held. */
119 static int efx_ethtool_get_settings(struct net_device
*net_dev
,
120 struct ethtool_cmd
*ecmd
)
122 struct efx_nic
*efx
= netdev_priv(net_dev
);
123 struct efx_link_state
*link_state
= &efx
->link_state
;
125 mutex_lock(&efx
->mac_lock
);
126 efx
->phy_op
->get_settings(efx
, ecmd
);
127 mutex_unlock(&efx
->mac_lock
);
129 /* Both MACs support pause frames (bidirectional and respond-only) */
130 ecmd
->supported
|= SUPPORTED_Pause
| SUPPORTED_Asym_Pause
;
132 if (LOOPBACK_INTERNAL(efx
)) {
133 ethtool_cmd_speed_set(ecmd
, link_state
->speed
);
134 ecmd
->duplex
= link_state
->fd
? DUPLEX_FULL
: DUPLEX_HALF
;
140 /* This must be called with rtnl_lock held. */
141 static int efx_ethtool_set_settings(struct net_device
*net_dev
,
142 struct ethtool_cmd
*ecmd
)
144 struct efx_nic
*efx
= netdev_priv(net_dev
);
147 /* GMAC does not support 1000Mbps HD */
148 if ((ethtool_cmd_speed(ecmd
) == SPEED_1000
) &&
149 (ecmd
->duplex
!= DUPLEX_FULL
)) {
150 netif_dbg(efx
, drv
, efx
->net_dev
,
151 "rejecting unsupported 1000Mbps HD setting\n");
155 mutex_lock(&efx
->mac_lock
);
156 rc
= efx
->phy_op
->set_settings(efx
, ecmd
);
157 mutex_unlock(&efx
->mac_lock
);
161 static void efx_ethtool_get_drvinfo(struct net_device
*net_dev
,
162 struct ethtool_drvinfo
*info
)
164 struct efx_nic
*efx
= netdev_priv(net_dev
);
166 strlcpy(info
->driver
, KBUILD_MODNAME
, sizeof(info
->driver
));
167 strlcpy(info
->version
, EFX_DRIVER_VERSION
, sizeof(info
->version
));
168 if (efx_nic_rev(efx
) >= EFX_REV_SIENA_A0
)
169 efx_mcdi_print_fwver(efx
, info
->fw_version
,
170 sizeof(info
->fw_version
));
171 strlcpy(info
->bus_info
, pci_name(efx
->pci_dev
), sizeof(info
->bus_info
));
174 static int efx_ethtool_get_regs_len(struct net_device
*net_dev
)
176 return efx_nic_get_regs_len(netdev_priv(net_dev
));
179 static void efx_ethtool_get_regs(struct net_device
*net_dev
,
180 struct ethtool_regs
*regs
, void *buf
)
182 struct efx_nic
*efx
= netdev_priv(net_dev
);
184 regs
->version
= efx
->type
->revision
;
185 efx_nic_get_regs(efx
, buf
);
188 static u32
efx_ethtool_get_msglevel(struct net_device
*net_dev
)
190 struct efx_nic
*efx
= netdev_priv(net_dev
);
191 return efx
->msg_enable
;
194 static void efx_ethtool_set_msglevel(struct net_device
*net_dev
, u32 msg_enable
)
196 struct efx_nic
*efx
= netdev_priv(net_dev
);
197 efx
->msg_enable
= msg_enable
;
201 * efx_fill_test - fill in an individual self-test entry
202 * @test_index: Index of the test
203 * @strings: Ethtool strings, or %NULL
204 * @data: Ethtool test results, or %NULL
205 * @test: Pointer to test result (used only if data != %NULL)
206 * @unit_format: Unit name format (e.g. "chan\%d")
207 * @unit_id: Unit id (e.g. 0 for "chan0")
208 * @test_format: Test name format (e.g. "loopback.\%s.tx.sent")
209 * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
211 * Fill in an individual self-test entry.
213 static void efx_fill_test(unsigned int test_index
, u8
*strings
, u64
*data
,
214 int *test
, const char *unit_format
, int unit_id
,
215 const char *test_format
, const char *test_id
)
217 char unit_str
[ETH_GSTRING_LEN
], test_str
[ETH_GSTRING_LEN
];
219 /* Fill data value, if applicable */
221 data
[test_index
] = *test
;
223 /* Fill string, if applicable */
225 if (strchr(unit_format
, '%'))
226 snprintf(unit_str
, sizeof(unit_str
),
227 unit_format
, unit_id
);
229 strcpy(unit_str
, unit_format
);
230 snprintf(test_str
, sizeof(test_str
), test_format
, test_id
);
231 snprintf(strings
+ test_index
* ETH_GSTRING_LEN
,
233 "%-6s %-24s", unit_str
, test_str
);
237 #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
238 #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
239 #define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
240 #define EFX_LOOPBACK_NAME(_mode, _counter) \
241 "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode)
244 * efx_fill_loopback_test - fill in a block of loopback self-test entries
246 * @lb_tests: Efx loopback self-test results structure
247 * @mode: Loopback test mode
248 * @test_index: Starting index of the test
249 * @strings: Ethtool strings, or %NULL
250 * @data: Ethtool test results, or %NULL
252 static int efx_fill_loopback_test(struct efx_nic
*efx
,
253 struct efx_loopback_self_tests
*lb_tests
,
254 enum efx_loopback_mode mode
,
255 unsigned int test_index
,
256 u8
*strings
, u64
*data
)
258 struct efx_channel
*channel
=
259 efx_get_channel(efx
, efx
->tx_channel_offset
);
260 struct efx_tx_queue
*tx_queue
;
262 efx_for_each_channel_tx_queue(tx_queue
, channel
) {
263 efx_fill_test(test_index
++, strings
, data
,
264 &lb_tests
->tx_sent
[tx_queue
->queue
],
265 EFX_TX_QUEUE_NAME(tx_queue
),
266 EFX_LOOPBACK_NAME(mode
, "tx_sent"));
267 efx_fill_test(test_index
++, strings
, data
,
268 &lb_tests
->tx_done
[tx_queue
->queue
],
269 EFX_TX_QUEUE_NAME(tx_queue
),
270 EFX_LOOPBACK_NAME(mode
, "tx_done"));
272 efx_fill_test(test_index
++, strings
, data
,
275 EFX_LOOPBACK_NAME(mode
, "rx_good"));
276 efx_fill_test(test_index
++, strings
, data
,
279 EFX_LOOPBACK_NAME(mode
, "rx_bad"));
285 * efx_ethtool_fill_self_tests - get self-test details
287 * @tests: Efx self-test results structure, or %NULL
288 * @strings: Ethtool strings, or %NULL
289 * @data: Ethtool test results, or %NULL
291 static int efx_ethtool_fill_self_tests(struct efx_nic
*efx
,
292 struct efx_self_tests
*tests
,
293 u8
*strings
, u64
*data
)
295 struct efx_channel
*channel
;
296 unsigned int n
= 0, i
;
297 enum efx_loopback_mode mode
;
299 efx_fill_test(n
++, strings
, data
, &tests
->phy_alive
,
300 "phy", 0, "alive", NULL
);
301 efx_fill_test(n
++, strings
, data
, &tests
->nvram
,
302 "core", 0, "nvram", NULL
);
303 efx_fill_test(n
++, strings
, data
, &tests
->interrupt
,
304 "core", 0, "interrupt", NULL
);
307 efx_for_each_channel(channel
, efx
) {
308 efx_fill_test(n
++, strings
, data
,
309 &tests
->eventq_dma
[channel
->channel
],
310 EFX_CHANNEL_NAME(channel
),
312 efx_fill_test(n
++, strings
, data
,
313 &tests
->eventq_int
[channel
->channel
],
314 EFX_CHANNEL_NAME(channel
),
318 efx_fill_test(n
++, strings
, data
, &tests
->registers
,
319 "core", 0, "registers", NULL
);
321 if (efx
->phy_op
->run_tests
!= NULL
) {
322 EFX_BUG_ON_PARANOID(efx
->phy_op
->test_name
== NULL
);
324 for (i
= 0; true; ++i
) {
327 EFX_BUG_ON_PARANOID(i
>= EFX_MAX_PHY_TESTS
);
328 name
= efx
->phy_op
->test_name(efx
, i
);
332 efx_fill_test(n
++, strings
, data
, &tests
->phy_ext
[i
],
333 "phy", 0, name
, NULL
);
338 for (mode
= LOOPBACK_NONE
; mode
<= LOOPBACK_TEST_MAX
; mode
++) {
339 if (!(efx
->loopback_modes
& (1 << mode
)))
341 n
= efx_fill_loopback_test(efx
,
342 &tests
->loopback
[mode
], mode
, n
,
349 static int efx_ethtool_get_sset_count(struct net_device
*net_dev
,
352 struct efx_nic
*efx
= netdev_priv(net_dev
);
354 switch (string_set
) {
356 return efx
->type
->describe_stats(efx
, NULL
) +
357 EFX_ETHTOOL_SW_STAT_COUNT
;
359 return efx_ethtool_fill_self_tests(efx
, NULL
, NULL
, NULL
);
365 static void efx_ethtool_get_strings(struct net_device
*net_dev
,
366 u32 string_set
, u8
*strings
)
368 struct efx_nic
*efx
= netdev_priv(net_dev
);
371 switch (string_set
) {
373 strings
+= (efx
->type
->describe_stats(efx
, strings
) *
375 for (i
= 0; i
< EFX_ETHTOOL_SW_STAT_COUNT
; i
++)
376 strlcpy(strings
+ i
* ETH_GSTRING_LEN
,
377 efx_sw_stat_desc
[i
].name
, ETH_GSTRING_LEN
);
380 efx_ethtool_fill_self_tests(efx
, NULL
, strings
, NULL
);
383 /* No other string sets */
388 static void efx_ethtool_get_stats(struct net_device
*net_dev
,
389 struct ethtool_stats
*stats
,
392 struct efx_nic
*efx
= netdev_priv(net_dev
);
393 const struct efx_sw_stat_desc
*stat
;
394 struct efx_channel
*channel
;
395 struct efx_tx_queue
*tx_queue
;
398 spin_lock_bh(&efx
->stats_lock
);
400 /* Get NIC statistics */
401 data
+= efx
->type
->update_stats(efx
, data
, NULL
);
403 /* Get software statistics */
404 for (i
= 0; i
< EFX_ETHTOOL_SW_STAT_COUNT
; i
++) {
405 stat
= &efx_sw_stat_desc
[i
];
406 switch (stat
->source
) {
407 case EFX_ETHTOOL_STAT_SOURCE_nic
:
408 data
[i
] = stat
->get_stat((void *)efx
+ stat
->offset
);
410 case EFX_ETHTOOL_STAT_SOURCE_channel
:
412 efx_for_each_channel(channel
, efx
)
413 data
[i
] += stat
->get_stat((void *)channel
+
416 case EFX_ETHTOOL_STAT_SOURCE_tx_queue
:
418 efx_for_each_channel(channel
, efx
) {
419 efx_for_each_channel_tx_queue(tx_queue
, channel
)
421 stat
->get_stat((void *)tx_queue
428 spin_unlock_bh(&efx
->stats_lock
);
431 static void efx_ethtool_self_test(struct net_device
*net_dev
,
432 struct ethtool_test
*test
, u64
*data
)
434 struct efx_nic
*efx
= netdev_priv(net_dev
);
435 struct efx_self_tests
*efx_tests
;
439 efx_tests
= kzalloc(sizeof(*efx_tests
), GFP_KERNEL
);
443 if (efx
->state
!= STATE_READY
) {
448 netif_info(efx
, drv
, efx
->net_dev
, "starting %sline testing\n",
449 (test
->flags
& ETH_TEST_FL_OFFLINE
) ? "off" : "on");
451 /* We need rx buffers and interrupts. */
452 already_up
= (efx
->net_dev
->flags
& IFF_UP
);
454 rc
= dev_open(efx
->net_dev
);
456 netif_err(efx
, drv
, efx
->net_dev
,
457 "failed opening device.\n");
462 rc
= efx_selftest(efx
, efx_tests
, test
->flags
);
465 dev_close(efx
->net_dev
);
467 netif_info(efx
, drv
, efx
->net_dev
, "%s %sline self-tests\n",
468 rc
== 0 ? "passed" : "failed",
469 (test
->flags
& ETH_TEST_FL_OFFLINE
) ? "off" : "on");
472 /* Fill ethtool results structures */
473 efx_ethtool_fill_self_tests(efx
, efx_tests
, NULL
, data
);
477 test
->flags
|= ETH_TEST_FL_FAILED
;
480 /* Restart autonegotiation */
481 static int efx_ethtool_nway_reset(struct net_device
*net_dev
)
483 struct efx_nic
*efx
= netdev_priv(net_dev
);
485 return mdio45_nway_restart(&efx
->mdio
);
489 * Each channel has a single IRQ and moderation timer, started by any
490 * completion (or other event). Unless the module parameter
491 * separate_tx_channels is set, IRQs and moderation are therefore
492 * shared between RX and TX completions. In this case, when RX IRQ
493 * moderation is explicitly changed then TX IRQ moderation is
494 * automatically changed too, but otherwise we fail if the two values
495 * are requested to be different.
497 * The hardware does not support a limit on the number of completions
498 * before an IRQ, so we do not use the max_frames fields. We should
499 * report and require that max_frames == (usecs != 0), but this would
500 * invalidate existing user documentation.
502 * The hardware does not have distinct settings for interrupt
503 * moderation while the previous IRQ is being handled, so we should
504 * not use the 'irq' fields. However, an earlier developer
505 * misunderstood the meaning of the 'irq' fields and the driver did
506 * not support the standard fields. To avoid invalidating existing
507 * user documentation, we report and accept changes through either the
508 * standard or 'irq' fields. If both are changed at the same time, we
509 * prefer the standard field.
511 * We implement adaptive IRQ moderation, but use a different algorithm
512 * from that assumed in the definition of struct ethtool_coalesce.
513 * Therefore we do not use any of the adaptive moderation parameters
517 static int efx_ethtool_get_coalesce(struct net_device
*net_dev
,
518 struct ethtool_coalesce
*coalesce
)
520 struct efx_nic
*efx
= netdev_priv(net_dev
);
521 unsigned int tx_usecs
, rx_usecs
;
524 efx_get_irq_moderation(efx
, &tx_usecs
, &rx_usecs
, &rx_adaptive
);
526 coalesce
->tx_coalesce_usecs
= tx_usecs
;
527 coalesce
->tx_coalesce_usecs_irq
= tx_usecs
;
528 coalesce
->rx_coalesce_usecs
= rx_usecs
;
529 coalesce
->rx_coalesce_usecs_irq
= rx_usecs
;
530 coalesce
->use_adaptive_rx_coalesce
= rx_adaptive
;
535 static int efx_ethtool_set_coalesce(struct net_device
*net_dev
,
536 struct ethtool_coalesce
*coalesce
)
538 struct efx_nic
*efx
= netdev_priv(net_dev
);
539 struct efx_channel
*channel
;
540 unsigned int tx_usecs
, rx_usecs
;
541 bool adaptive
, rx_may_override_tx
;
544 if (coalesce
->use_adaptive_tx_coalesce
)
547 efx_get_irq_moderation(efx
, &tx_usecs
, &rx_usecs
, &adaptive
);
549 if (coalesce
->rx_coalesce_usecs
!= rx_usecs
)
550 rx_usecs
= coalesce
->rx_coalesce_usecs
;
552 rx_usecs
= coalesce
->rx_coalesce_usecs_irq
;
554 adaptive
= coalesce
->use_adaptive_rx_coalesce
;
556 /* If channels are shared, TX IRQ moderation can be quietly
557 * overridden unless it is changed from its old value.
559 rx_may_override_tx
= (coalesce
->tx_coalesce_usecs
== tx_usecs
&&
560 coalesce
->tx_coalesce_usecs_irq
== tx_usecs
);
561 if (coalesce
->tx_coalesce_usecs
!= tx_usecs
)
562 tx_usecs
= coalesce
->tx_coalesce_usecs
;
564 tx_usecs
= coalesce
->tx_coalesce_usecs_irq
;
566 rc
= efx_init_irq_moderation(efx
, tx_usecs
, rx_usecs
, adaptive
,
571 efx_for_each_channel(channel
, efx
)
572 efx
->type
->push_irq_moderation(channel
);
577 static void efx_ethtool_get_ringparam(struct net_device
*net_dev
,
578 struct ethtool_ringparam
*ring
)
580 struct efx_nic
*efx
= netdev_priv(net_dev
);
582 ring
->rx_max_pending
= EFX_MAX_DMAQ_SIZE
;
583 ring
->tx_max_pending
= EFX_MAX_DMAQ_SIZE
;
584 ring
->rx_pending
= efx
->rxq_entries
;
585 ring
->tx_pending
= efx
->txq_entries
;
588 static int efx_ethtool_set_ringparam(struct net_device
*net_dev
,
589 struct ethtool_ringparam
*ring
)
591 struct efx_nic
*efx
= netdev_priv(net_dev
);
594 if (ring
->rx_mini_pending
|| ring
->rx_jumbo_pending
||
595 ring
->rx_pending
> EFX_MAX_DMAQ_SIZE
||
596 ring
->tx_pending
> EFX_MAX_DMAQ_SIZE
)
599 if (ring
->rx_pending
< EFX_RXQ_MIN_ENT
) {
600 netif_err(efx
, drv
, efx
->net_dev
,
601 "RX queues cannot be smaller than %u\n",
606 txq_entries
= max(ring
->tx_pending
, EFX_TXQ_MIN_ENT(efx
));
607 if (txq_entries
!= ring
->tx_pending
)
608 netif_warn(efx
, drv
, efx
->net_dev
,
609 "increasing TX queue size to minimum of %u\n",
612 return efx_realloc_channels(efx
, ring
->rx_pending
, txq_entries
);
615 static int efx_ethtool_set_pauseparam(struct net_device
*net_dev
,
616 struct ethtool_pauseparam
*pause
)
618 struct efx_nic
*efx
= netdev_priv(net_dev
);
619 u8 wanted_fc
, old_fc
;
623 mutex_lock(&efx
->mac_lock
);
625 wanted_fc
= ((pause
->rx_pause
? EFX_FC_RX
: 0) |
626 (pause
->tx_pause
? EFX_FC_TX
: 0) |
627 (pause
->autoneg
? EFX_FC_AUTO
: 0));
629 if ((wanted_fc
& EFX_FC_TX
) && !(wanted_fc
& EFX_FC_RX
)) {
630 netif_dbg(efx
, drv
, efx
->net_dev
,
631 "Flow control unsupported: tx ON rx OFF\n");
636 if ((wanted_fc
& EFX_FC_AUTO
) && !efx
->link_advertising
) {
637 netif_dbg(efx
, drv
, efx
->net_dev
,
638 "Autonegotiation is disabled\n");
643 /* Hook for Falcon bug 11482 workaround */
644 if (efx
->type
->prepare_enable_fc_tx
&&
645 (wanted_fc
& EFX_FC_TX
) && !(efx
->wanted_fc
& EFX_FC_TX
))
646 efx
->type
->prepare_enable_fc_tx(efx
);
648 old_adv
= efx
->link_advertising
;
649 old_fc
= efx
->wanted_fc
;
650 efx_link_set_wanted_fc(efx
, wanted_fc
);
651 if (efx
->link_advertising
!= old_adv
||
652 (efx
->wanted_fc
^ old_fc
) & EFX_FC_AUTO
) {
653 rc
= efx
->phy_op
->reconfigure(efx
);
655 netif_err(efx
, drv
, efx
->net_dev
,
656 "Unable to advertise requested flow "
657 "control setting\n");
662 /* Reconfigure the MAC. The PHY *may* generate a link state change event
663 * if the user just changed the advertised capabilities, but there's no
664 * harm doing this twice */
665 efx
->type
->reconfigure_mac(efx
);
668 mutex_unlock(&efx
->mac_lock
);
673 static void efx_ethtool_get_pauseparam(struct net_device
*net_dev
,
674 struct ethtool_pauseparam
*pause
)
676 struct efx_nic
*efx
= netdev_priv(net_dev
);
678 pause
->rx_pause
= !!(efx
->wanted_fc
& EFX_FC_RX
);
679 pause
->tx_pause
= !!(efx
->wanted_fc
& EFX_FC_TX
);
680 pause
->autoneg
= !!(efx
->wanted_fc
& EFX_FC_AUTO
);
684 static void efx_ethtool_get_wol(struct net_device
*net_dev
,
685 struct ethtool_wolinfo
*wol
)
687 struct efx_nic
*efx
= netdev_priv(net_dev
);
688 return efx
->type
->get_wol(efx
, wol
);
692 static int efx_ethtool_set_wol(struct net_device
*net_dev
,
693 struct ethtool_wolinfo
*wol
)
695 struct efx_nic
*efx
= netdev_priv(net_dev
);
696 return efx
->type
->set_wol(efx
, wol
->wolopts
);
699 static int efx_ethtool_reset(struct net_device
*net_dev
, u32
*flags
)
701 struct efx_nic
*efx
= netdev_priv(net_dev
);
704 rc
= efx
->type
->map_reset_flags(flags
);
708 return efx_reset(efx
, rc
);
711 /* MAC address mask including only I/G bit */
712 static const u8 mac_addr_ig_mask
[ETH_ALEN
] = { 0x01, 0, 0, 0, 0, 0 };
714 #define IP4_ADDR_FULL_MASK ((__force __be32)~0)
715 #define PORT_FULL_MASK ((__force __be16)~0)
716 #define ETHER_TYPE_FULL_MASK ((__force __be16)~0)
718 static int efx_ethtool_get_class_rule(struct efx_nic
*efx
,
719 struct ethtool_rx_flow_spec
*rule
)
721 struct ethtool_tcpip4_spec
*ip_entry
= &rule
->h_u
.tcp_ip4_spec
;
722 struct ethtool_tcpip4_spec
*ip_mask
= &rule
->m_u
.tcp_ip4_spec
;
723 struct ethhdr
*mac_entry
= &rule
->h_u
.ether_spec
;
724 struct ethhdr
*mac_mask
= &rule
->m_u
.ether_spec
;
725 struct efx_filter_spec spec
;
728 rc
= efx_filter_get_filter_safe(efx
, EFX_FILTER_PRI_MANUAL
,
729 rule
->location
, &spec
);
733 if (spec
.dmaq_id
== EFX_FILTER_RX_DMAQ_ID_DROP
)
734 rule
->ring_cookie
= RX_CLS_FLOW_DISC
;
736 rule
->ring_cookie
= spec
.dmaq_id
;
738 if ((spec
.match_flags
& EFX_FILTER_MATCH_ETHER_TYPE
) &&
739 spec
.ether_type
== htons(ETH_P_IP
) &&
740 (spec
.match_flags
& EFX_FILTER_MATCH_IP_PROTO
) &&
741 (spec
.ip_proto
== IPPROTO_TCP
|| spec
.ip_proto
== IPPROTO_UDP
) &&
743 ~(EFX_FILTER_MATCH_ETHER_TYPE
| EFX_FILTER_MATCH_OUTER_VID
|
744 EFX_FILTER_MATCH_LOC_HOST
| EFX_FILTER_MATCH_REM_HOST
|
745 EFX_FILTER_MATCH_IP_PROTO
|
746 EFX_FILTER_MATCH_LOC_PORT
| EFX_FILTER_MATCH_REM_PORT
))) {
747 rule
->flow_type
= ((spec
.ip_proto
== IPPROTO_TCP
) ?
748 TCP_V4_FLOW
: UDP_V4_FLOW
);
749 if (spec
.match_flags
& EFX_FILTER_MATCH_LOC_HOST
) {
750 ip_entry
->ip4dst
= spec
.loc_host
[0];
751 ip_mask
->ip4dst
= IP4_ADDR_FULL_MASK
;
753 if (spec
.match_flags
& EFX_FILTER_MATCH_REM_HOST
) {
754 ip_entry
->ip4src
= spec
.rem_host
[0];
755 ip_mask
->ip4src
= IP4_ADDR_FULL_MASK
;
757 if (spec
.match_flags
& EFX_FILTER_MATCH_LOC_PORT
) {
758 ip_entry
->pdst
= spec
.loc_port
;
759 ip_mask
->pdst
= PORT_FULL_MASK
;
761 if (spec
.match_flags
& EFX_FILTER_MATCH_REM_PORT
) {
762 ip_entry
->psrc
= spec
.rem_port
;
763 ip_mask
->psrc
= PORT_FULL_MASK
;
765 } else if (!(spec
.match_flags
&
766 ~(EFX_FILTER_MATCH_LOC_MAC
| EFX_FILTER_MATCH_LOC_MAC_IG
|
767 EFX_FILTER_MATCH_REM_MAC
| EFX_FILTER_MATCH_ETHER_TYPE
|
768 EFX_FILTER_MATCH_OUTER_VID
))) {
769 rule
->flow_type
= ETHER_FLOW
;
770 if (spec
.match_flags
&
771 (EFX_FILTER_MATCH_LOC_MAC
| EFX_FILTER_MATCH_LOC_MAC_IG
)) {
772 memcpy(mac_entry
->h_dest
, spec
.loc_mac
, ETH_ALEN
);
773 if (spec
.match_flags
& EFX_FILTER_MATCH_LOC_MAC
)
774 memset(mac_mask
->h_dest
, ~0, ETH_ALEN
);
776 memcpy(mac_mask
->h_dest
, mac_addr_ig_mask
,
779 if (spec
.match_flags
& EFX_FILTER_MATCH_REM_MAC
) {
780 memcpy(mac_entry
->h_source
, spec
.rem_mac
, ETH_ALEN
);
781 memset(mac_mask
->h_source
, ~0, ETH_ALEN
);
783 if (spec
.match_flags
& EFX_FILTER_MATCH_ETHER_TYPE
) {
784 mac_entry
->h_proto
= spec
.ether_type
;
785 mac_mask
->h_proto
= ETHER_TYPE_FULL_MASK
;
788 /* The above should handle all filters that we insert */
793 if (spec
.match_flags
& EFX_FILTER_MATCH_OUTER_VID
) {
794 rule
->flow_type
|= FLOW_EXT
;
795 rule
->h_ext
.vlan_tci
= spec
.outer_vid
;
796 rule
->m_ext
.vlan_tci
= htons(0xfff);
803 efx_ethtool_get_rxnfc(struct net_device
*net_dev
,
804 struct ethtool_rxnfc
*info
, u32
*rule_locs
)
806 struct efx_nic
*efx
= netdev_priv(net_dev
);
809 case ETHTOOL_GRXRINGS
:
810 info
->data
= efx
->n_rx_channels
;
813 case ETHTOOL_GRXFH
: {
814 unsigned min_revision
= 0;
817 switch (info
->flow_type
) {
819 info
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
825 info
->data
|= RXH_IP_SRC
| RXH_IP_DST
;
826 min_revision
= EFX_REV_FALCON_B0
;
829 info
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
835 info
->data
|= RXH_IP_SRC
| RXH_IP_DST
;
836 min_revision
= EFX_REV_SIENA_A0
;
841 if (efx_nic_rev(efx
) < min_revision
)
846 case ETHTOOL_GRXCLSRLCNT
:
847 info
->data
= efx_filter_get_rx_id_limit(efx
);
850 info
->data
|= RX_CLS_LOC_SPECIAL
;
852 efx_filter_count_rx_used(efx
, EFX_FILTER_PRI_MANUAL
);
855 case ETHTOOL_GRXCLSRULE
:
856 if (efx_filter_get_rx_id_limit(efx
) == 0)
858 return efx_ethtool_get_class_rule(efx
, &info
->fs
);
860 case ETHTOOL_GRXCLSRLALL
: {
862 info
->data
= efx_filter_get_rx_id_limit(efx
);
865 rc
= efx_filter_get_rx_ids(efx
, EFX_FILTER_PRI_MANUAL
,
866 rule_locs
, info
->rule_cnt
);
878 static int efx_ethtool_set_class_rule(struct efx_nic
*efx
,
879 struct ethtool_rx_flow_spec
*rule
)
881 struct ethtool_tcpip4_spec
*ip_entry
= &rule
->h_u
.tcp_ip4_spec
;
882 struct ethtool_tcpip4_spec
*ip_mask
= &rule
->m_u
.tcp_ip4_spec
;
883 struct ethhdr
*mac_entry
= &rule
->h_u
.ether_spec
;
884 struct ethhdr
*mac_mask
= &rule
->m_u
.ether_spec
;
885 struct efx_filter_spec spec
;
888 /* Check that user wants us to choose the location */
889 if (rule
->location
!= RX_CLS_LOC_ANY
)
892 /* Range-check ring_cookie */
893 if (rule
->ring_cookie
>= efx
->n_rx_channels
&&
894 rule
->ring_cookie
!= RX_CLS_FLOW_DISC
)
897 /* Check for unsupported extensions */
898 if ((rule
->flow_type
& FLOW_EXT
) &&
899 (rule
->m_ext
.vlan_etype
|| rule
->m_ext
.data
[0] ||
900 rule
->m_ext
.data
[1]))
903 efx_filter_init_rx(&spec
, EFX_FILTER_PRI_MANUAL
,
904 efx
->rx_scatter
? EFX_FILTER_FLAG_RX_SCATTER
: 0,
905 (rule
->ring_cookie
== RX_CLS_FLOW_DISC
) ?
906 EFX_FILTER_RX_DMAQ_ID_DROP
: rule
->ring_cookie
);
908 switch (rule
->flow_type
& ~FLOW_EXT
) {
911 spec
.match_flags
= (EFX_FILTER_MATCH_ETHER_TYPE
|
912 EFX_FILTER_MATCH_IP_PROTO
);
913 spec
.ether_type
= htons(ETH_P_IP
);
914 spec
.ip_proto
= ((rule
->flow_type
& ~FLOW_EXT
) == TCP_V4_FLOW
?
915 IPPROTO_TCP
: IPPROTO_UDP
);
916 if (ip_mask
->ip4dst
) {
917 if (ip_mask
->ip4dst
!= IP4_ADDR_FULL_MASK
)
919 spec
.match_flags
|= EFX_FILTER_MATCH_LOC_HOST
;
920 spec
.loc_host
[0] = ip_entry
->ip4dst
;
922 if (ip_mask
->ip4src
) {
923 if (ip_mask
->ip4src
!= IP4_ADDR_FULL_MASK
)
925 spec
.match_flags
|= EFX_FILTER_MATCH_REM_HOST
;
926 spec
.rem_host
[0] = ip_entry
->ip4src
;
929 if (ip_mask
->pdst
!= PORT_FULL_MASK
)
931 spec
.match_flags
|= EFX_FILTER_MATCH_LOC_PORT
;
932 spec
.loc_port
= ip_entry
->pdst
;
935 if (ip_mask
->psrc
!= PORT_FULL_MASK
)
937 spec
.match_flags
|= EFX_FILTER_MATCH_REM_PORT
;
938 spec
.rem_port
= ip_entry
->psrc
;
945 if (!is_zero_ether_addr(mac_mask
->h_dest
)) {
946 if (ether_addr_equal(mac_mask
->h_dest
,
948 spec
.match_flags
|= EFX_FILTER_MATCH_LOC_MAC_IG
;
949 else if (is_broadcast_ether_addr(mac_mask
->h_dest
))
950 spec
.match_flags
|= EFX_FILTER_MATCH_LOC_MAC
;
953 memcpy(spec
.loc_mac
, mac_entry
->h_dest
, ETH_ALEN
);
955 if (!is_zero_ether_addr(mac_mask
->h_source
)) {
956 if (!is_broadcast_ether_addr(mac_mask
->h_source
))
958 spec
.match_flags
|= EFX_FILTER_MATCH_REM_MAC
;
959 memcpy(spec
.rem_mac
, mac_entry
->h_source
, ETH_ALEN
);
961 if (mac_mask
->h_proto
) {
962 if (mac_mask
->h_proto
!= ETHER_TYPE_FULL_MASK
)
964 spec
.match_flags
|= EFX_FILTER_MATCH_ETHER_TYPE
;
965 spec
.ether_type
= mac_entry
->h_proto
;
973 if ((rule
->flow_type
& FLOW_EXT
) && rule
->m_ext
.vlan_tci
) {
974 if (rule
->m_ext
.vlan_tci
!= htons(0xfff))
976 spec
.match_flags
|= EFX_FILTER_MATCH_OUTER_VID
;
977 spec
.outer_vid
= rule
->h_ext
.vlan_tci
;
980 rc
= efx_filter_insert_filter(efx
, &spec
, true);
988 static int efx_ethtool_set_rxnfc(struct net_device
*net_dev
,
989 struct ethtool_rxnfc
*info
)
991 struct efx_nic
*efx
= netdev_priv(net_dev
);
993 if (efx_filter_get_rx_id_limit(efx
) == 0)
997 case ETHTOOL_SRXCLSRLINS
:
998 return efx_ethtool_set_class_rule(efx
, &info
->fs
);
1000 case ETHTOOL_SRXCLSRLDEL
:
1001 return efx_filter_remove_id_safe(efx
, EFX_FILTER_PRI_MANUAL
,
1009 static u32
efx_ethtool_get_rxfh_indir_size(struct net_device
*net_dev
)
1011 struct efx_nic
*efx
= netdev_priv(net_dev
);
1013 return ((efx_nic_rev(efx
) < EFX_REV_FALCON_B0
||
1014 efx
->n_rx_channels
== 1) ?
1015 0 : ARRAY_SIZE(efx
->rx_indir_table
));
1018 static int efx_ethtool_get_rxfh_indir(struct net_device
*net_dev
, u32
*indir
)
1020 struct efx_nic
*efx
= netdev_priv(net_dev
);
1022 memcpy(indir
, efx
->rx_indir_table
, sizeof(efx
->rx_indir_table
));
1026 static int efx_ethtool_set_rxfh_indir(struct net_device
*net_dev
,
1029 struct efx_nic
*efx
= netdev_priv(net_dev
);
1031 memcpy(efx
->rx_indir_table
, indir
, sizeof(efx
->rx_indir_table
));
1032 efx_nic_push_rx_indir_table(efx
);
1036 int efx_ethtool_get_ts_info(struct net_device
*net_dev
,
1037 struct ethtool_ts_info
*ts_info
)
1039 struct efx_nic
*efx
= netdev_priv(net_dev
);
1041 /* Software capabilities */
1042 ts_info
->so_timestamping
= (SOF_TIMESTAMPING_RX_SOFTWARE
|
1043 SOF_TIMESTAMPING_SOFTWARE
);
1044 ts_info
->phc_index
= -1;
1046 efx_ptp_get_ts_info(efx
, ts_info
);
1050 static int efx_ethtool_get_module_eeprom(struct net_device
*net_dev
,
1051 struct ethtool_eeprom
*ee
,
1054 struct efx_nic
*efx
= netdev_priv(net_dev
);
1057 if (!efx
->phy_op
|| !efx
->phy_op
->get_module_eeprom
)
1060 mutex_lock(&efx
->mac_lock
);
1061 ret
= efx
->phy_op
->get_module_eeprom(efx
, ee
, data
);
1062 mutex_unlock(&efx
->mac_lock
);
1067 static int efx_ethtool_get_module_info(struct net_device
*net_dev
,
1068 struct ethtool_modinfo
*modinfo
)
1070 struct efx_nic
*efx
= netdev_priv(net_dev
);
1073 if (!efx
->phy_op
|| !efx
->phy_op
->get_module_info
)
1076 mutex_lock(&efx
->mac_lock
);
1077 ret
= efx
->phy_op
->get_module_info(efx
, modinfo
);
1078 mutex_unlock(&efx
->mac_lock
);
1083 const struct ethtool_ops efx_ethtool_ops
= {
1084 .get_settings
= efx_ethtool_get_settings
,
1085 .set_settings
= efx_ethtool_set_settings
,
1086 .get_drvinfo
= efx_ethtool_get_drvinfo
,
1087 .get_regs_len
= efx_ethtool_get_regs_len
,
1088 .get_regs
= efx_ethtool_get_regs
,
1089 .get_msglevel
= efx_ethtool_get_msglevel
,
1090 .set_msglevel
= efx_ethtool_set_msglevel
,
1091 .nway_reset
= efx_ethtool_nway_reset
,
1092 .get_link
= ethtool_op_get_link
,
1093 .get_coalesce
= efx_ethtool_get_coalesce
,
1094 .set_coalesce
= efx_ethtool_set_coalesce
,
1095 .get_ringparam
= efx_ethtool_get_ringparam
,
1096 .set_ringparam
= efx_ethtool_set_ringparam
,
1097 .get_pauseparam
= efx_ethtool_get_pauseparam
,
1098 .set_pauseparam
= efx_ethtool_set_pauseparam
,
1099 .get_sset_count
= efx_ethtool_get_sset_count
,
1100 .self_test
= efx_ethtool_self_test
,
1101 .get_strings
= efx_ethtool_get_strings
,
1102 .set_phys_id
= efx_ethtool_phys_id
,
1103 .get_ethtool_stats
= efx_ethtool_get_stats
,
1104 .get_wol
= efx_ethtool_get_wol
,
1105 .set_wol
= efx_ethtool_set_wol
,
1106 .reset
= efx_ethtool_reset
,
1107 .get_rxnfc
= efx_ethtool_get_rxnfc
,
1108 .set_rxnfc
= efx_ethtool_set_rxnfc
,
1109 .get_rxfh_indir_size
= efx_ethtool_get_rxfh_indir_size
,
1110 .get_rxfh_indir
= efx_ethtool_get_rxfh_indir
,
1111 .set_rxfh_indir
= efx_ethtool_set_rxfh_indir
,
1112 .get_ts_info
= efx_ethtool_get_ts_info
,
1113 .get_module_info
= efx_ethtool_get_module_info
,
1114 .get_module_eeprom
= efx_ethtool_get_module_eeprom
,