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_inner_ip_hdr_chksum_err),
81 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_inner_tcp_udp_chksum_err),
82 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_outer_ip_hdr_chksum_err),
83 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_outer_tcp_udp_chksum_err),
84 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_eth_crc_err),
85 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch),
86 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
87 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_events),
88 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_packets),
91 #define EFX_ETHTOOL_SW_STAT_COUNT ARRAY_SIZE(efx_sw_stat_desc)
93 #define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB
95 /**************************************************************************
99 **************************************************************************
102 /* Identify device by flashing LEDs */
103 static int efx_ethtool_phys_id(struct net_device *net_dev,
104 enum ethtool_phys_id_state state)
106 struct efx_nic *efx = netdev_priv(net_dev);
107 enum efx_led_mode mode = EFX_LED_DEFAULT;
116 case ETHTOOL_ID_INACTIVE:
117 mode = EFX_LED_DEFAULT;
119 case ETHTOOL_ID_ACTIVE:
120 return 1; /* cycle on/off once per second */
123 efx->type->set_id_led(efx, mode);
127 /* This must be called with rtnl_lock held. */
129 efx_ethtool_get_link_ksettings(struct net_device *net_dev,
130 struct ethtool_link_ksettings *cmd)
132 struct efx_nic *efx = netdev_priv(net_dev);
133 struct efx_link_state *link_state = &efx->link_state;
135 mutex_lock(&efx->mac_lock);
136 efx->phy_op->get_link_ksettings(efx, cmd);
137 mutex_unlock(&efx->mac_lock);
139 /* Both MACs support pause frames (bidirectional and respond-only) */
140 ethtool_link_ksettings_add_link_mode(cmd, supported, Pause);
141 ethtool_link_ksettings_add_link_mode(cmd, supported, Asym_Pause);
143 if (LOOPBACK_INTERNAL(efx)) {
144 cmd->base.speed = link_state->speed;
145 cmd->base.duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF;
151 /* This must be called with rtnl_lock held. */
153 efx_ethtool_set_link_ksettings(struct net_device *net_dev,
154 const struct ethtool_link_ksettings *cmd)
156 struct efx_nic *efx = netdev_priv(net_dev);
159 /* GMAC does not support 1000Mbps HD */
160 if ((cmd->base.speed == SPEED_1000) &&
161 (cmd->base.duplex != DUPLEX_FULL)) {
162 netif_dbg(efx, drv, efx->net_dev,
163 "rejecting unsupported 1000Mbps HD setting\n");
167 mutex_lock(&efx->mac_lock);
168 rc = efx->phy_op->set_link_ksettings(efx, cmd);
169 mutex_unlock(&efx->mac_lock);
173 static void efx_ethtool_get_drvinfo(struct net_device *net_dev,
174 struct ethtool_drvinfo *info)
176 struct efx_nic *efx = netdev_priv(net_dev);
178 strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
179 strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version));
180 efx_mcdi_print_fwver(efx, info->fw_version,
181 sizeof(info->fw_version));
182 strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
185 static int efx_ethtool_get_regs_len(struct net_device *net_dev)
187 return efx_nic_get_regs_len(netdev_priv(net_dev));
190 static void efx_ethtool_get_regs(struct net_device *net_dev,
191 struct ethtool_regs *regs, void *buf)
193 struct efx_nic *efx = netdev_priv(net_dev);
195 regs->version = efx->type->revision;
196 efx_nic_get_regs(efx, buf);
199 static u32 efx_ethtool_get_msglevel(struct net_device *net_dev)
201 struct efx_nic *efx = netdev_priv(net_dev);
202 return efx->msg_enable;
205 static void efx_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable)
207 struct efx_nic *efx = netdev_priv(net_dev);
208 efx->msg_enable = msg_enable;
212 * efx_fill_test - fill in an individual self-test entry
213 * @test_index: Index of the test
214 * @strings: Ethtool strings, or %NULL
215 * @data: Ethtool test results, or %NULL
216 * @test: Pointer to test result (used only if data != %NULL)
217 * @unit_format: Unit name format (e.g. "chan\%d")
218 * @unit_id: Unit id (e.g. 0 for "chan0")
219 * @test_format: Test name format (e.g. "loopback.\%s.tx.sent")
220 * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
222 * Fill in an individual self-test entry.
224 static void efx_fill_test(unsigned int test_index, u8 *strings, u64 *data,
225 int *test, const char *unit_format, int unit_id,
226 const char *test_format, const char *test_id)
228 char unit_str[ETH_GSTRING_LEN], test_str[ETH_GSTRING_LEN];
230 /* Fill data value, if applicable */
232 data[test_index] = *test;
234 /* Fill string, if applicable */
236 if (strchr(unit_format, '%'))
237 snprintf(unit_str, sizeof(unit_str),
238 unit_format, unit_id);
240 strcpy(unit_str, unit_format);
241 snprintf(test_str, sizeof(test_str), test_format, test_id);
242 snprintf(strings + test_index * ETH_GSTRING_LEN,
244 "%-6s %-24s", unit_str, test_str);
248 #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
249 #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
250 #define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
251 #define EFX_LOOPBACK_NAME(_mode, _counter) \
252 "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode)
255 * efx_fill_loopback_test - fill in a block of loopback self-test entries
257 * @lb_tests: Efx loopback self-test results structure
258 * @mode: Loopback test mode
259 * @test_index: Starting index of the test
260 * @strings: Ethtool strings, or %NULL
261 * @data: Ethtool test results, or %NULL
263 * Fill in a block of loopback self-test entries. Return new test
266 static int efx_fill_loopback_test(struct efx_nic *efx,
267 struct efx_loopback_self_tests *lb_tests,
268 enum efx_loopback_mode mode,
269 unsigned int test_index,
270 u8 *strings, u64 *data)
272 struct efx_channel *channel =
273 efx_get_channel(efx, efx->tx_channel_offset);
274 struct efx_tx_queue *tx_queue;
276 efx_for_each_channel_tx_queue(tx_queue, channel) {
277 efx_fill_test(test_index++, strings, data,
278 &lb_tests->tx_sent[tx_queue->queue],
279 EFX_TX_QUEUE_NAME(tx_queue),
280 EFX_LOOPBACK_NAME(mode, "tx_sent"));
281 efx_fill_test(test_index++, strings, data,
282 &lb_tests->tx_done[tx_queue->queue],
283 EFX_TX_QUEUE_NAME(tx_queue),
284 EFX_LOOPBACK_NAME(mode, "tx_done"));
286 efx_fill_test(test_index++, strings, data,
289 EFX_LOOPBACK_NAME(mode, "rx_good"));
290 efx_fill_test(test_index++, strings, data,
293 EFX_LOOPBACK_NAME(mode, "rx_bad"));
299 * efx_ethtool_fill_self_tests - get self-test details
301 * @tests: Efx self-test results structure, or %NULL
302 * @strings: Ethtool strings, or %NULL
303 * @data: Ethtool test results, or %NULL
305 * Get self-test number of strings, strings, and/or test results.
306 * Return number of strings (== number of test results).
308 * The reason for merging these three functions is to make sure that
309 * they can never be inconsistent.
311 static int efx_ethtool_fill_self_tests(struct efx_nic *efx,
312 struct efx_self_tests *tests,
313 u8 *strings, u64 *data)
315 struct efx_channel *channel;
316 unsigned int n = 0, i;
317 enum efx_loopback_mode mode;
319 efx_fill_test(n++, strings, data, &tests->phy_alive,
320 "phy", 0, "alive", NULL);
321 efx_fill_test(n++, strings, data, &tests->nvram,
322 "core", 0, "nvram", NULL);
323 efx_fill_test(n++, strings, data, &tests->interrupt,
324 "core", 0, "interrupt", NULL);
327 efx_for_each_channel(channel, efx) {
328 efx_fill_test(n++, strings, data,
329 &tests->eventq_dma[channel->channel],
330 EFX_CHANNEL_NAME(channel),
332 efx_fill_test(n++, strings, data,
333 &tests->eventq_int[channel->channel],
334 EFX_CHANNEL_NAME(channel),
338 efx_fill_test(n++, strings, data, &tests->memory,
339 "core", 0, "memory", NULL);
340 efx_fill_test(n++, strings, data, &tests->registers,
341 "core", 0, "registers", NULL);
343 if (efx->phy_op->run_tests != NULL) {
344 EFX_WARN_ON_PARANOID(efx->phy_op->test_name == NULL);
346 for (i = 0; true; ++i) {
349 EFX_WARN_ON_PARANOID(i >= EFX_MAX_PHY_TESTS);
350 name = efx->phy_op->test_name(efx, i);
354 efx_fill_test(n++, strings, data, &tests->phy_ext[i],
355 "phy", 0, name, NULL);
360 for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
361 if (!(efx->loopback_modes & (1 << mode)))
363 n = efx_fill_loopback_test(efx,
364 &tests->loopback[mode], mode, n,
371 static size_t efx_describe_per_queue_stats(struct efx_nic *efx, u8 *strings)
374 struct efx_channel *channel;
376 efx_for_each_channel(channel, efx) {
377 if (efx_channel_has_tx_queues(channel)) {
379 if (strings != NULL) {
380 snprintf(strings, ETH_GSTRING_LEN,
382 channel->tx_queue[0].queue /
385 strings += ETH_GSTRING_LEN;
389 efx_for_each_channel(channel, efx) {
390 if (efx_channel_has_rx_queue(channel)) {
392 if (strings != NULL) {
393 snprintf(strings, ETH_GSTRING_LEN,
394 "rx-%d.rx_packets", channel->channel);
395 strings += ETH_GSTRING_LEN;
402 static int efx_ethtool_get_sset_count(struct net_device *net_dev,
405 struct efx_nic *efx = netdev_priv(net_dev);
407 switch (string_set) {
409 return efx->type->describe_stats(efx, NULL) +
410 EFX_ETHTOOL_SW_STAT_COUNT +
411 efx_describe_per_queue_stats(efx, NULL) +
412 efx_ptp_describe_stats(efx, NULL);
414 return efx_ethtool_fill_self_tests(efx, NULL, NULL, NULL);
420 static void efx_ethtool_get_strings(struct net_device *net_dev,
421 u32 string_set, u8 *strings)
423 struct efx_nic *efx = netdev_priv(net_dev);
426 switch (string_set) {
428 strings += (efx->type->describe_stats(efx, strings) *
430 for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++)
431 strlcpy(strings + i * ETH_GSTRING_LEN,
432 efx_sw_stat_desc[i].name, ETH_GSTRING_LEN);
433 strings += EFX_ETHTOOL_SW_STAT_COUNT * ETH_GSTRING_LEN;
434 strings += (efx_describe_per_queue_stats(efx, strings) *
436 efx_ptp_describe_stats(efx, strings);
439 efx_ethtool_fill_self_tests(efx, NULL, strings, NULL);
442 /* No other string sets */
447 static void efx_ethtool_get_stats(struct net_device *net_dev,
448 struct ethtool_stats *stats,
451 struct efx_nic *efx = netdev_priv(net_dev);
452 const struct efx_sw_stat_desc *stat;
453 struct efx_channel *channel;
454 struct efx_tx_queue *tx_queue;
455 struct efx_rx_queue *rx_queue;
458 spin_lock_bh(&efx->stats_lock);
460 /* Get NIC statistics */
461 data += efx->type->update_stats(efx, data, NULL);
463 /* Get software statistics */
464 for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) {
465 stat = &efx_sw_stat_desc[i];
466 switch (stat->source) {
467 case EFX_ETHTOOL_STAT_SOURCE_nic:
468 data[i] = stat->get_stat((void *)efx + stat->offset);
470 case EFX_ETHTOOL_STAT_SOURCE_channel:
472 efx_for_each_channel(channel, efx)
473 data[i] += stat->get_stat((void *)channel +
476 case EFX_ETHTOOL_STAT_SOURCE_tx_queue:
478 efx_for_each_channel(channel, efx) {
479 efx_for_each_channel_tx_queue(tx_queue, channel)
481 stat->get_stat((void *)tx_queue
487 data += EFX_ETHTOOL_SW_STAT_COUNT;
489 spin_unlock_bh(&efx->stats_lock);
491 efx_for_each_channel(channel, efx) {
492 if (efx_channel_has_tx_queues(channel)) {
494 efx_for_each_channel_tx_queue(tx_queue, channel) {
495 *data += tx_queue->tx_packets;
500 efx_for_each_channel(channel, efx) {
501 if (efx_channel_has_rx_queue(channel)) {
503 efx_for_each_channel_rx_queue(rx_queue, channel) {
504 *data += rx_queue->rx_packets;
510 efx_ptp_update_stats(efx, data);
513 static void efx_ethtool_self_test(struct net_device *net_dev,
514 struct ethtool_test *test, u64 *data)
516 struct efx_nic *efx = netdev_priv(net_dev);
517 struct efx_self_tests *efx_tests;
521 efx_tests = kzalloc(sizeof(*efx_tests), GFP_KERNEL);
525 if (efx->state != STATE_READY) {
530 netif_info(efx, drv, efx->net_dev, "starting %sline testing\n",
531 (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
533 /* We need rx buffers and interrupts. */
534 already_up = (efx->net_dev->flags & IFF_UP);
536 rc = dev_open(efx->net_dev);
538 netif_err(efx, drv, efx->net_dev,
539 "failed opening device.\n");
544 rc = efx_selftest(efx, efx_tests, test->flags);
547 dev_close(efx->net_dev);
549 netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n",
550 rc == 0 ? "passed" : "failed",
551 (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
554 efx_ethtool_fill_self_tests(efx, efx_tests, NULL, data);
558 test->flags |= ETH_TEST_FL_FAILED;
561 /* Restart autonegotiation */
562 static int efx_ethtool_nway_reset(struct net_device *net_dev)
564 struct efx_nic *efx = netdev_priv(net_dev);
566 return mdio45_nway_restart(&efx->mdio);
570 * Each channel has a single IRQ and moderation timer, started by any
571 * completion (or other event). Unless the module parameter
572 * separate_tx_channels is set, IRQs and moderation are therefore
573 * shared between RX and TX completions. In this case, when RX IRQ
574 * moderation is explicitly changed then TX IRQ moderation is
575 * automatically changed too, but otherwise we fail if the two values
576 * are requested to be different.
578 * The hardware does not support a limit on the number of completions
579 * before an IRQ, so we do not use the max_frames fields. We should
580 * report and require that max_frames == (usecs != 0), but this would
581 * invalidate existing user documentation.
583 * The hardware does not have distinct settings for interrupt
584 * moderation while the previous IRQ is being handled, so we should
585 * not use the 'irq' fields. However, an earlier developer
586 * misunderstood the meaning of the 'irq' fields and the driver did
587 * not support the standard fields. To avoid invalidating existing
588 * user documentation, we report and accept changes through either the
589 * standard or 'irq' fields. If both are changed at the same time, we
590 * prefer the standard field.
592 * We implement adaptive IRQ moderation, but use a different algorithm
593 * from that assumed in the definition of struct ethtool_coalesce.
594 * Therefore we do not use any of the adaptive moderation parameters
598 static int efx_ethtool_get_coalesce(struct net_device *net_dev,
599 struct ethtool_coalesce *coalesce)
601 struct efx_nic *efx = netdev_priv(net_dev);
602 unsigned int tx_usecs, rx_usecs;
605 efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &rx_adaptive);
607 coalesce->tx_coalesce_usecs = tx_usecs;
608 coalesce->tx_coalesce_usecs_irq = tx_usecs;
609 coalesce->rx_coalesce_usecs = rx_usecs;
610 coalesce->rx_coalesce_usecs_irq = rx_usecs;
611 coalesce->use_adaptive_rx_coalesce = rx_adaptive;
616 static int efx_ethtool_set_coalesce(struct net_device *net_dev,
617 struct ethtool_coalesce *coalesce)
619 struct efx_nic *efx = netdev_priv(net_dev);
620 struct efx_channel *channel;
621 unsigned int tx_usecs, rx_usecs;
622 bool adaptive, rx_may_override_tx;
625 if (coalesce->use_adaptive_tx_coalesce)
628 efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &adaptive);
630 if (coalesce->rx_coalesce_usecs != rx_usecs)
631 rx_usecs = coalesce->rx_coalesce_usecs;
633 rx_usecs = coalesce->rx_coalesce_usecs_irq;
635 adaptive = coalesce->use_adaptive_rx_coalesce;
637 /* If channels are shared, TX IRQ moderation can be quietly
638 * overridden unless it is changed from its old value.
640 rx_may_override_tx = (coalesce->tx_coalesce_usecs == tx_usecs &&
641 coalesce->tx_coalesce_usecs_irq == tx_usecs);
642 if (coalesce->tx_coalesce_usecs != tx_usecs)
643 tx_usecs = coalesce->tx_coalesce_usecs;
645 tx_usecs = coalesce->tx_coalesce_usecs_irq;
647 rc = efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive,
652 efx_for_each_channel(channel, efx)
653 efx->type->push_irq_moderation(channel);
658 static void efx_ethtool_get_ringparam(struct net_device *net_dev,
659 struct ethtool_ringparam *ring)
661 struct efx_nic *efx = netdev_priv(net_dev);
663 ring->rx_max_pending = EFX_MAX_DMAQ_SIZE;
664 ring->tx_max_pending = EFX_TXQ_MAX_ENT(efx);
665 ring->rx_pending = efx->rxq_entries;
666 ring->tx_pending = efx->txq_entries;
669 static int efx_ethtool_set_ringparam(struct net_device *net_dev,
670 struct ethtool_ringparam *ring)
672 struct efx_nic *efx = netdev_priv(net_dev);
675 if (ring->rx_mini_pending || ring->rx_jumbo_pending ||
676 ring->rx_pending > EFX_MAX_DMAQ_SIZE ||
677 ring->tx_pending > EFX_TXQ_MAX_ENT(efx))
680 if (ring->rx_pending < EFX_RXQ_MIN_ENT) {
681 netif_err(efx, drv, efx->net_dev,
682 "RX queues cannot be smaller than %u\n",
687 txq_entries = max(ring->tx_pending, EFX_TXQ_MIN_ENT(efx));
688 if (txq_entries != ring->tx_pending)
689 netif_warn(efx, drv, efx->net_dev,
690 "increasing TX queue size to minimum of %u\n",
693 return efx_realloc_channels(efx, ring->rx_pending, txq_entries);
696 static int efx_ethtool_set_pauseparam(struct net_device *net_dev,
697 struct ethtool_pauseparam *pause)
699 struct efx_nic *efx = netdev_priv(net_dev);
700 u8 wanted_fc, old_fc;
704 mutex_lock(&efx->mac_lock);
706 wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
707 (pause->tx_pause ? EFX_FC_TX : 0) |
708 (pause->autoneg ? EFX_FC_AUTO : 0));
710 if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
711 netif_dbg(efx, drv, efx->net_dev,
712 "Flow control unsupported: tx ON rx OFF\n");
717 if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising[0]) {
718 netif_dbg(efx, drv, efx->net_dev,
719 "Autonegotiation is disabled\n");
724 /* Hook for Falcon bug 11482 workaround */
725 if (efx->type->prepare_enable_fc_tx &&
726 (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX))
727 efx->type->prepare_enable_fc_tx(efx);
729 old_adv = efx->link_advertising[0];
730 old_fc = efx->wanted_fc;
731 efx_link_set_wanted_fc(efx, wanted_fc);
732 if (efx->link_advertising[0] != old_adv ||
733 (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) {
734 rc = efx->phy_op->reconfigure(efx);
736 netif_err(efx, drv, efx->net_dev,
737 "Unable to advertise requested flow "
738 "control setting\n");
743 /* Reconfigure the MAC. The PHY *may* generate a link state change event
744 * if the user just changed the advertised capabilities, but there's no
745 * harm doing this twice */
746 efx_mac_reconfigure(efx);
749 mutex_unlock(&efx->mac_lock);
754 static void efx_ethtool_get_pauseparam(struct net_device *net_dev,
755 struct ethtool_pauseparam *pause)
757 struct efx_nic *efx = netdev_priv(net_dev);
759 pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX);
760 pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX);
761 pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO);
764 static void efx_ethtool_get_wol(struct net_device *net_dev,
765 struct ethtool_wolinfo *wol)
767 struct efx_nic *efx = netdev_priv(net_dev);
768 return efx->type->get_wol(efx, wol);
772 static int efx_ethtool_set_wol(struct net_device *net_dev,
773 struct ethtool_wolinfo *wol)
775 struct efx_nic *efx = netdev_priv(net_dev);
776 return efx->type->set_wol(efx, wol->wolopts);
779 static int efx_ethtool_reset(struct net_device *net_dev, u32 *flags)
781 struct efx_nic *efx = netdev_priv(net_dev);
784 rc = efx->type->map_reset_flags(flags);
788 return efx_reset(efx, rc);
791 /* MAC address mask including only I/G bit */
792 static const u8 mac_addr_ig_mask[ETH_ALEN] __aligned(2) = {0x01, 0, 0, 0, 0, 0};
794 #define IP4_ADDR_FULL_MASK ((__force __be32)~0)
795 #define IP_PROTO_FULL_MASK 0xFF
796 #define PORT_FULL_MASK ((__force __be16)~0)
797 #define ETHER_TYPE_FULL_MASK ((__force __be16)~0)
799 static inline void ip6_fill_mask(__be32 *mask)
801 mask[0] = mask[1] = mask[2] = mask[3] = ~(__be32)0;
804 static int efx_ethtool_get_class_rule(struct efx_nic *efx,
805 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);
962 if (spec.flags & EFX_FILTER_FLAG_RX_RSS) {
963 rule->flow_type |= FLOW_RSS;
964 *rss_context = spec.rss_context;
971 efx_ethtool_get_rxnfc(struct net_device *net_dev,
972 struct ethtool_rxnfc *info, u32 *rule_locs)
974 struct efx_nic *efx = netdev_priv(net_dev);
979 case ETHTOOL_GRXRINGS:
980 info->data = efx->n_rx_channels;
983 case ETHTOOL_GRXFH: {
984 struct efx_rss_context *ctx = &efx->rss_context;
986 mutex_lock(&efx->rss_lock);
987 if (info->flow_type & FLOW_RSS && info->rss_context) {
988 ctx = efx_find_rss_context_entry(efx, info->rss_context);
995 if (!efx_rss_active(ctx)) /* No RSS */
997 switch (info->flow_type & ~FLOW_RSS) {
999 if (ctx->rx_hash_udp_4tuple)
1002 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1005 case AH_ESP_V4_FLOW:
1007 info->data |= RXH_IP_SRC | RXH_IP_DST;
1010 if (ctx->rx_hash_udp_4tuple)
1013 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1016 case AH_ESP_V6_FLOW:
1018 info->data |= RXH_IP_SRC | RXH_IP_DST;
1024 mutex_unlock(&efx->rss_lock);
1028 case ETHTOOL_GRXCLSRLCNT:
1029 info->data = efx_filter_get_rx_id_limit(efx);
1030 if (info->data == 0)
1032 info->data |= RX_CLS_LOC_SPECIAL;
1034 efx_filter_count_rx_used(efx, EFX_FILTER_PRI_MANUAL);
1037 case ETHTOOL_GRXCLSRULE:
1038 if (efx_filter_get_rx_id_limit(efx) == 0)
1040 rc = efx_ethtool_get_class_rule(efx, &info->fs, &rss_context);
1043 if (info->fs.flow_type & FLOW_RSS)
1044 info->rss_context = rss_context;
1047 case ETHTOOL_GRXCLSRLALL:
1048 info->data = efx_filter_get_rx_id_limit(efx);
1049 if (info->data == 0)
1051 rc = efx_filter_get_rx_ids(efx, EFX_FILTER_PRI_MANUAL,
1052 rule_locs, info->rule_cnt);
1055 info->rule_cnt = rc;
1063 static inline bool ip6_mask_is_full(__be32 mask[4])
1065 return !~(mask[0] & mask[1] & mask[2] & mask[3]);
1068 static inline bool ip6_mask_is_empty(__be32 mask[4])
1070 return !(mask[0] | mask[1] | mask[2] | mask[3]);
1073 static int efx_ethtool_set_class_rule(struct efx_nic *efx,
1074 struct ethtool_rx_flow_spec *rule,
1077 struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
1078 struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
1079 struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
1080 struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
1081 struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
1082 struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
1083 struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
1084 struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
1085 u32 flow_type = rule->flow_type & ~(FLOW_EXT | FLOW_RSS);
1086 struct ethhdr *mac_entry = &rule->h_u.ether_spec;
1087 struct ethhdr *mac_mask = &rule->m_u.ether_spec;
1088 enum efx_filter_flags flags = 0;
1089 struct efx_filter_spec spec;
1092 /* Check that user wants us to choose the location */
1093 if (rule->location != RX_CLS_LOC_ANY)
1096 /* Range-check ring_cookie */
1097 if (rule->ring_cookie >= efx->n_rx_channels &&
1098 rule->ring_cookie != RX_CLS_FLOW_DISC)
1101 /* Check for unsupported extensions */
1102 if ((rule->flow_type & FLOW_EXT) &&
1103 (rule->m_ext.vlan_etype || rule->m_ext.data[0] ||
1104 rule->m_ext.data[1]))
1107 if (efx->rx_scatter)
1108 flags |= EFX_FILTER_FLAG_RX_SCATTER;
1109 if (rule->flow_type & FLOW_RSS)
1110 flags |= EFX_FILTER_FLAG_RX_RSS;
1112 efx_filter_init_rx(&spec, EFX_FILTER_PRI_MANUAL, flags,
1113 (rule->ring_cookie == RX_CLS_FLOW_DISC) ?
1114 EFX_FILTER_RX_DMAQ_ID_DROP : rule->ring_cookie);
1116 if (rule->flow_type & FLOW_RSS)
1117 spec.rss_context = rss_context;
1119 switch (flow_type) {
1122 spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
1123 EFX_FILTER_MATCH_IP_PROTO);
1124 spec.ether_type = htons(ETH_P_IP);
1125 spec.ip_proto = flow_type == TCP_V4_FLOW ? IPPROTO_TCP
1127 if (ip_mask->ip4dst) {
1128 if (ip_mask->ip4dst != IP4_ADDR_FULL_MASK)
1130 spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1131 spec.loc_host[0] = ip_entry->ip4dst;
1133 if (ip_mask->ip4src) {
1134 if (ip_mask->ip4src != IP4_ADDR_FULL_MASK)
1136 spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1137 spec.rem_host[0] = ip_entry->ip4src;
1139 if (ip_mask->pdst) {
1140 if (ip_mask->pdst != PORT_FULL_MASK)
1142 spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
1143 spec.loc_port = ip_entry->pdst;
1145 if (ip_mask->psrc) {
1146 if (ip_mask->psrc != PORT_FULL_MASK)
1148 spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
1149 spec.rem_port = ip_entry->psrc;
1157 spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
1158 EFX_FILTER_MATCH_IP_PROTO);
1159 spec.ether_type = htons(ETH_P_IPV6);
1160 spec.ip_proto = flow_type == TCP_V6_FLOW ? IPPROTO_TCP
1162 if (!ip6_mask_is_empty(ip6_mask->ip6dst)) {
1163 if (!ip6_mask_is_full(ip6_mask->ip6dst))
1165 spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1166 memcpy(spec.loc_host, ip6_entry->ip6dst, sizeof(spec.loc_host));
1168 if (!ip6_mask_is_empty(ip6_mask->ip6src)) {
1169 if (!ip6_mask_is_full(ip6_mask->ip6src))
1171 spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1172 memcpy(spec.rem_host, ip6_entry->ip6src, sizeof(spec.rem_host));
1174 if (ip6_mask->pdst) {
1175 if (ip6_mask->pdst != PORT_FULL_MASK)
1177 spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
1178 spec.loc_port = ip6_entry->pdst;
1180 if (ip6_mask->psrc) {
1181 if (ip6_mask->psrc != PORT_FULL_MASK)
1183 spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
1184 spec.rem_port = ip6_entry->psrc;
1186 if (ip6_mask->tclass)
1190 case IPV4_USER_FLOW:
1191 if (uip_mask->l4_4_bytes || uip_mask->tos || uip_mask->ip_ver ||
1192 uip_entry->ip_ver != ETH_RX_NFC_IP4)
1194 spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE;
1195 spec.ether_type = htons(ETH_P_IP);
1196 if (uip_mask->ip4dst) {
1197 if (uip_mask->ip4dst != IP4_ADDR_FULL_MASK)
1199 spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1200 spec.loc_host[0] = uip_entry->ip4dst;
1202 if (uip_mask->ip4src) {
1203 if (uip_mask->ip4src != IP4_ADDR_FULL_MASK)
1205 spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1206 spec.rem_host[0] = uip_entry->ip4src;
1208 if (uip_mask->proto) {
1209 if (uip_mask->proto != IP_PROTO_FULL_MASK)
1211 spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO;
1212 spec.ip_proto = uip_entry->proto;
1216 case IPV6_USER_FLOW:
1217 if (uip6_mask->l4_4_bytes || uip6_mask->tclass)
1219 spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE;
1220 spec.ether_type = htons(ETH_P_IPV6);
1221 if (!ip6_mask_is_empty(uip6_mask->ip6dst)) {
1222 if (!ip6_mask_is_full(uip6_mask->ip6dst))
1224 spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1225 memcpy(spec.loc_host, uip6_entry->ip6dst, sizeof(spec.loc_host));
1227 if (!ip6_mask_is_empty(uip6_mask->ip6src)) {
1228 if (!ip6_mask_is_full(uip6_mask->ip6src))
1230 spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1231 memcpy(spec.rem_host, uip6_entry->ip6src, sizeof(spec.rem_host));
1233 if (uip6_mask->l4_proto) {
1234 if (uip6_mask->l4_proto != IP_PROTO_FULL_MASK)
1236 spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO;
1237 spec.ip_proto = uip6_entry->l4_proto;
1242 if (!is_zero_ether_addr(mac_mask->h_dest)) {
1243 if (ether_addr_equal(mac_mask->h_dest,
1245 spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC_IG;
1246 else if (is_broadcast_ether_addr(mac_mask->h_dest))
1247 spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC;
1250 ether_addr_copy(spec.loc_mac, mac_entry->h_dest);
1252 if (!is_zero_ether_addr(mac_mask->h_source)) {
1253 if (!is_broadcast_ether_addr(mac_mask->h_source))
1255 spec.match_flags |= EFX_FILTER_MATCH_REM_MAC;
1256 ether_addr_copy(spec.rem_mac, mac_entry->h_source);
1258 if (mac_mask->h_proto) {
1259 if (mac_mask->h_proto != ETHER_TYPE_FULL_MASK)
1261 spec.match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
1262 spec.ether_type = mac_entry->h_proto;
1270 if ((rule->flow_type & FLOW_EXT) && rule->m_ext.vlan_tci) {
1271 if (rule->m_ext.vlan_tci != htons(0xfff))
1273 spec.match_flags |= EFX_FILTER_MATCH_OUTER_VID;
1274 spec.outer_vid = rule->h_ext.vlan_tci;
1277 rc = efx_filter_insert_filter(efx, &spec, true);
1281 rule->location = rc;
1285 static int efx_ethtool_set_rxnfc(struct net_device *net_dev,
1286 struct ethtool_rxnfc *info)
1288 struct efx_nic *efx = netdev_priv(net_dev);
1290 if (efx_filter_get_rx_id_limit(efx) == 0)
1293 switch (info->cmd) {
1294 case ETHTOOL_SRXCLSRLINS:
1295 return efx_ethtool_set_class_rule(efx, &info->fs,
1298 case ETHTOOL_SRXCLSRLDEL:
1299 return efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_MANUAL,
1307 static u32 efx_ethtool_get_rxfh_indir_size(struct net_device *net_dev)
1309 struct efx_nic *efx = netdev_priv(net_dev);
1311 if (efx->n_rx_channels == 1)
1313 return ARRAY_SIZE(efx->rss_context.rx_indir_table);
1316 static u32 efx_ethtool_get_rxfh_key_size(struct net_device *net_dev)
1318 struct efx_nic *efx = netdev_priv(net_dev);
1320 return efx->type->rx_hash_key_size;
1323 static int efx_ethtool_get_rxfh(struct net_device *net_dev, u32 *indir, u8 *key,
1326 struct efx_nic *efx = netdev_priv(net_dev);
1329 rc = efx->type->rx_pull_rss_config(efx);
1334 *hfunc = ETH_RSS_HASH_TOP;
1336 memcpy(indir, efx->rss_context.rx_indir_table,
1337 sizeof(efx->rss_context.rx_indir_table));
1339 memcpy(key, efx->rss_context.rx_hash_key,
1340 efx->type->rx_hash_key_size);
1344 static int efx_ethtool_set_rxfh(struct net_device *net_dev, const u32 *indir,
1345 const u8 *key, const u8 hfunc)
1347 struct efx_nic *efx = netdev_priv(net_dev);
1349 /* Hash function is Toeplitz, cannot be changed */
1350 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1356 key = efx->rss_context.rx_hash_key;
1358 indir = efx->rss_context.rx_indir_table;
1360 return efx->type->rx_push_rss_config(efx, true, indir, key);
1363 static int efx_ethtool_get_rxfh_context(struct net_device *net_dev, u32 *indir,
1364 u8 *key, u8 *hfunc, u32 rss_context)
1366 struct efx_nic *efx = netdev_priv(net_dev);
1367 struct efx_rss_context *ctx;
1370 if (!efx->type->rx_pull_rss_context_config)
1373 mutex_lock(&efx->rss_lock);
1374 ctx = efx_find_rss_context_entry(efx, rss_context);
1379 rc = efx->type->rx_pull_rss_context_config(efx, ctx);
1384 *hfunc = ETH_RSS_HASH_TOP;
1386 memcpy(indir, ctx->rx_indir_table, sizeof(ctx->rx_indir_table));
1388 memcpy(key, ctx->rx_hash_key, efx->type->rx_hash_key_size);
1390 mutex_unlock(&efx->rss_lock);
1394 static int efx_ethtool_set_rxfh_context(struct net_device *net_dev,
1395 const u32 *indir, const u8 *key,
1396 const u8 hfunc, u32 *rss_context,
1399 struct efx_nic *efx = netdev_priv(net_dev);
1400 struct efx_rss_context *ctx;
1401 bool allocated = false;
1404 if (!efx->type->rx_push_rss_context_config)
1406 /* Hash function is Toeplitz, cannot be changed */
1407 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1410 mutex_lock(&efx->rss_lock);
1412 if (*rss_context == ETH_RXFH_CONTEXT_ALLOC) {
1414 /* alloc + delete == Nothing to do */
1418 ctx = efx_alloc_rss_context_entry(efx);
1423 ctx->context_id = EFX_EF10_RSS_CONTEXT_INVALID;
1424 /* Initialise indir table and key to defaults */
1425 efx_set_default_rx_indir_table(efx, ctx);
1426 netdev_rss_key_fill(ctx->rx_hash_key, sizeof(ctx->rx_hash_key));
1429 ctx = efx_find_rss_context_entry(efx, *rss_context);
1437 /* delete this context */
1438 rc = efx->type->rx_push_rss_context_config(efx, ctx, NULL, NULL);
1440 efx_free_rss_context_entry(ctx);
1445 key = ctx->rx_hash_key;
1447 indir = ctx->rx_indir_table;
1449 rc = efx->type->rx_push_rss_context_config(efx, ctx, indir, key);
1450 if (rc && allocated)
1451 efx_free_rss_context_entry(ctx);
1453 *rss_context = ctx->user_id;
1455 mutex_unlock(&efx->rss_lock);
1459 static int efx_ethtool_get_ts_info(struct net_device *net_dev,
1460 struct ethtool_ts_info *ts_info)
1462 struct efx_nic *efx = netdev_priv(net_dev);
1464 /* Software capabilities */
1465 ts_info->so_timestamping = (SOF_TIMESTAMPING_RX_SOFTWARE |
1466 SOF_TIMESTAMPING_SOFTWARE);
1467 ts_info->phc_index = -1;
1469 efx_ptp_get_ts_info(efx, ts_info);
1473 static int efx_ethtool_get_module_eeprom(struct net_device *net_dev,
1474 struct ethtool_eeprom *ee,
1477 struct efx_nic *efx = netdev_priv(net_dev);
1480 if (!efx->phy_op || !efx->phy_op->get_module_eeprom)
1483 mutex_lock(&efx->mac_lock);
1484 ret = efx->phy_op->get_module_eeprom(efx, ee, data);
1485 mutex_unlock(&efx->mac_lock);
1490 static int efx_ethtool_get_module_info(struct net_device *net_dev,
1491 struct ethtool_modinfo *modinfo)
1493 struct efx_nic *efx = netdev_priv(net_dev);
1496 if (!efx->phy_op || !efx->phy_op->get_module_info)
1499 mutex_lock(&efx->mac_lock);
1500 ret = efx->phy_op->get_module_info(efx, modinfo);
1501 mutex_unlock(&efx->mac_lock);
1506 static int efx_ethtool_get_fecparam(struct net_device *net_dev,
1507 struct ethtool_fecparam *fecparam)
1509 struct efx_nic *efx = netdev_priv(net_dev);
1512 if (!efx->phy_op || !efx->phy_op->get_fecparam)
1514 mutex_lock(&efx->mac_lock);
1515 rc = efx->phy_op->get_fecparam(efx, fecparam);
1516 mutex_unlock(&efx->mac_lock);
1521 static int efx_ethtool_set_fecparam(struct net_device *net_dev,
1522 struct ethtool_fecparam *fecparam)
1524 struct efx_nic *efx = netdev_priv(net_dev);
1527 if (!efx->phy_op || !efx->phy_op->get_fecparam)
1529 mutex_lock(&efx->mac_lock);
1530 rc = efx->phy_op->set_fecparam(efx, fecparam);
1531 mutex_unlock(&efx->mac_lock);
1536 const struct ethtool_ops efx_ethtool_ops = {
1537 .get_drvinfo = efx_ethtool_get_drvinfo,
1538 .get_regs_len = efx_ethtool_get_regs_len,
1539 .get_regs = efx_ethtool_get_regs,
1540 .get_msglevel = efx_ethtool_get_msglevel,
1541 .set_msglevel = efx_ethtool_set_msglevel,
1542 .nway_reset = efx_ethtool_nway_reset,
1543 .get_link = ethtool_op_get_link,
1544 .get_coalesce = efx_ethtool_get_coalesce,
1545 .set_coalesce = efx_ethtool_set_coalesce,
1546 .get_ringparam = efx_ethtool_get_ringparam,
1547 .set_ringparam = efx_ethtool_set_ringparam,
1548 .get_pauseparam = efx_ethtool_get_pauseparam,
1549 .set_pauseparam = efx_ethtool_set_pauseparam,
1550 .get_sset_count = efx_ethtool_get_sset_count,
1551 .self_test = efx_ethtool_self_test,
1552 .get_strings = efx_ethtool_get_strings,
1553 .set_phys_id = efx_ethtool_phys_id,
1554 .get_ethtool_stats = efx_ethtool_get_stats,
1555 .get_wol = efx_ethtool_get_wol,
1556 .set_wol = efx_ethtool_set_wol,
1557 .reset = efx_ethtool_reset,
1558 .get_rxnfc = efx_ethtool_get_rxnfc,
1559 .set_rxnfc = efx_ethtool_set_rxnfc,
1560 .get_rxfh_indir_size = efx_ethtool_get_rxfh_indir_size,
1561 .get_rxfh_key_size = efx_ethtool_get_rxfh_key_size,
1562 .get_rxfh = efx_ethtool_get_rxfh,
1563 .set_rxfh = efx_ethtool_set_rxfh,
1564 .get_rxfh_context = efx_ethtool_get_rxfh_context,
1565 .set_rxfh_context = efx_ethtool_set_rxfh_context,
1566 .get_ts_info = efx_ethtool_get_ts_info,
1567 .get_module_info = efx_ethtool_get_module_info,
1568 .get_module_eeprom = efx_ethtool_get_module_eeprom,
1569 .get_link_ksettings = efx_ethtool_get_link_ksettings,
1570 .set_link_ksettings = efx_ethtool_set_link_ksettings,
1571 .get_fecparam = efx_ethtool_get_fecparam,
1572 .set_fecparam = efx_ethtool_set_fecparam,