1 // SPDX-License-Identifier: GPL-2.0-only
2 /****************************************************************************
3 * Driver for Solarflare network controllers and boards
4 * Copyright 2005-2006 Fen Systems Ltd.
5 * Copyright 2006-2013 Solarflare Communications Inc.
8 #include <linux/netdevice.h>
9 #include <linux/ethtool.h>
10 #include <linux/rtnetlink.h>
12 #include "net_driver.h"
13 #include "workarounds.h"
19 struct efx_sw_stat_desc {
22 EFX_ETHTOOL_STAT_SOURCE_nic,
23 EFX_ETHTOOL_STAT_SOURCE_channel,
24 EFX_ETHTOOL_STAT_SOURCE_tx_queue
27 u64(*get_stat) (void *field); /* Reader function */
30 /* Initialiser for a struct efx_sw_stat_desc with type-checking */
31 #define EFX_ETHTOOL_STAT(stat_name, source_name, field, field_type, \
32 get_stat_function) { \
34 .source = EFX_ETHTOOL_STAT_SOURCE_##source_name, \
35 .offset = ((((field_type *) 0) == \
36 &((struct efx_##source_name *)0)->field) ? \
37 offsetof(struct efx_##source_name, field) : \
38 offsetof(struct efx_##source_name, field)), \
39 .get_stat = get_stat_function, \
42 static u64 efx_get_uint_stat(void *field)
44 return *(unsigned int *)field;
47 static u64 efx_get_atomic_stat(void *field)
49 return atomic_read((atomic_t *) field);
52 #define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field) \
53 EFX_ETHTOOL_STAT(field, nic, field, \
54 atomic_t, efx_get_atomic_stat)
56 #define EFX_ETHTOOL_UINT_CHANNEL_STAT(field) \
57 EFX_ETHTOOL_STAT(field, channel, n_##field, \
58 unsigned int, efx_get_uint_stat)
60 #define EFX_ETHTOOL_UINT_TXQ_STAT(field) \
61 EFX_ETHTOOL_STAT(tx_##field, tx_queue, field, \
62 unsigned int, efx_get_uint_stat)
64 static const struct efx_sw_stat_desc efx_sw_stat_desc[] = {
65 EFX_ETHTOOL_UINT_TXQ_STAT(merge_events),
66 EFX_ETHTOOL_UINT_TXQ_STAT(tso_bursts),
67 EFX_ETHTOOL_UINT_TXQ_STAT(tso_long_headers),
68 EFX_ETHTOOL_UINT_TXQ_STAT(tso_packets),
69 EFX_ETHTOOL_UINT_TXQ_STAT(tso_fallbacks),
70 EFX_ETHTOOL_UINT_TXQ_STAT(pushes),
71 EFX_ETHTOOL_UINT_TXQ_STAT(pio_packets),
72 EFX_ETHTOOL_UINT_TXQ_STAT(cb_packets),
73 EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset),
74 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc),
75 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),
76 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err),
77 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_inner_ip_hdr_chksum_err),
78 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_inner_tcp_udp_chksum_err),
79 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_outer_ip_hdr_chksum_err),
80 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_outer_tcp_udp_chksum_err),
81 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_eth_crc_err),
82 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch),
83 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
84 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_events),
85 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_packets),
88 #define EFX_ETHTOOL_SW_STAT_COUNT ARRAY_SIZE(efx_sw_stat_desc)
90 #define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB
92 /**************************************************************************
96 **************************************************************************
99 /* Identify device by flashing LEDs */
100 static int efx_ethtool_phys_id(struct net_device *net_dev,
101 enum ethtool_phys_id_state state)
103 struct efx_nic *efx = netdev_priv(net_dev);
104 enum efx_led_mode mode = EFX_LED_DEFAULT;
113 case ETHTOOL_ID_INACTIVE:
114 mode = EFX_LED_DEFAULT;
116 case ETHTOOL_ID_ACTIVE:
117 return 1; /* cycle on/off once per second */
120 efx->type->set_id_led(efx, mode);
124 /* This must be called with rtnl_lock held. */
126 efx_ethtool_get_link_ksettings(struct net_device *net_dev,
127 struct ethtool_link_ksettings *cmd)
129 struct efx_nic *efx = netdev_priv(net_dev);
130 struct efx_link_state *link_state = &efx->link_state;
133 mutex_lock(&efx->mac_lock);
134 efx->phy_op->get_link_ksettings(efx, cmd);
135 mutex_unlock(&efx->mac_lock);
137 /* Both MACs support pause frames (bidirectional and respond-only) */
138 ethtool_convert_link_mode_to_legacy_u32(&supported,
139 cmd->link_modes.supported);
141 supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
143 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
146 if (LOOPBACK_INTERNAL(efx)) {
147 cmd->base.speed = link_state->speed;
148 cmd->base.duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF;
154 /* This must be called with rtnl_lock held. */
156 efx_ethtool_set_link_ksettings(struct net_device *net_dev,
157 const struct ethtool_link_ksettings *cmd)
159 struct efx_nic *efx = netdev_priv(net_dev);
162 /* GMAC does not support 1000Mbps HD */
163 if ((cmd->base.speed == SPEED_1000) &&
164 (cmd->base.duplex != DUPLEX_FULL)) {
165 netif_dbg(efx, drv, efx->net_dev,
166 "rejecting unsupported 1000Mbps HD setting\n");
170 mutex_lock(&efx->mac_lock);
171 rc = efx->phy_op->set_link_ksettings(efx, cmd);
172 mutex_unlock(&efx->mac_lock);
176 static void efx_ethtool_get_drvinfo(struct net_device *net_dev,
177 struct ethtool_drvinfo *info)
179 struct efx_nic *efx = netdev_priv(net_dev);
181 strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
182 strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version));
183 efx_mcdi_print_fwver(efx, info->fw_version,
184 sizeof(info->fw_version));
185 strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
188 static int efx_ethtool_get_regs_len(struct net_device *net_dev)
190 return efx_nic_get_regs_len(netdev_priv(net_dev));
193 static void efx_ethtool_get_regs(struct net_device *net_dev,
194 struct ethtool_regs *regs, void *buf)
196 struct efx_nic *efx = netdev_priv(net_dev);
198 regs->version = efx->type->revision;
199 efx_nic_get_regs(efx, buf);
202 static u32 efx_ethtool_get_msglevel(struct net_device *net_dev)
204 struct efx_nic *efx = netdev_priv(net_dev);
205 return efx->msg_enable;
208 static void efx_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable)
210 struct efx_nic *efx = netdev_priv(net_dev);
211 efx->msg_enable = msg_enable;
215 * efx_fill_test - fill in an individual self-test entry
216 * @test_index: Index of the test
217 * @strings: Ethtool strings, or %NULL
218 * @data: Ethtool test results, or %NULL
219 * @test: Pointer to test result (used only if data != %NULL)
220 * @unit_format: Unit name format (e.g. "chan\%d")
221 * @unit_id: Unit id (e.g. 0 for "chan0")
222 * @test_format: Test name format (e.g. "loopback.\%s.tx.sent")
223 * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
225 * Fill in an individual self-test entry.
227 static void efx_fill_test(unsigned int test_index, u8 *strings, u64 *data,
228 int *test, const char *unit_format, int unit_id,
229 const char *test_format, const char *test_id)
231 char unit_str[ETH_GSTRING_LEN], test_str[ETH_GSTRING_LEN];
233 /* Fill data value, if applicable */
235 data[test_index] = *test;
237 /* Fill string, if applicable */
239 if (strchr(unit_format, '%'))
240 snprintf(unit_str, sizeof(unit_str),
241 unit_format, unit_id);
243 strcpy(unit_str, unit_format);
244 snprintf(test_str, sizeof(test_str), test_format, test_id);
245 snprintf(strings + test_index * ETH_GSTRING_LEN,
247 "%-6s %-24s", unit_str, test_str);
251 #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
252 #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
253 #define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
254 #define EFX_LOOPBACK_NAME(_mode, _counter) \
255 "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode)
258 * efx_fill_loopback_test - fill in a block of loopback self-test entries
260 * @lb_tests: Efx loopback self-test results structure
261 * @mode: Loopback test mode
262 * @test_index: Starting index of the test
263 * @strings: Ethtool strings, or %NULL
264 * @data: Ethtool test results, or %NULL
266 * Fill in a block of loopback self-test entries. Return new test
269 static int efx_fill_loopback_test(struct efx_nic *efx,
270 struct efx_loopback_self_tests *lb_tests,
271 enum efx_loopback_mode mode,
272 unsigned int test_index,
273 u8 *strings, u64 *data)
275 struct efx_channel *channel =
276 efx_get_channel(efx, efx->tx_channel_offset);
277 struct efx_tx_queue *tx_queue;
279 efx_for_each_channel_tx_queue(tx_queue, channel) {
280 efx_fill_test(test_index++, strings, data,
281 &lb_tests->tx_sent[tx_queue->queue],
282 EFX_TX_QUEUE_NAME(tx_queue),
283 EFX_LOOPBACK_NAME(mode, "tx_sent"));
284 efx_fill_test(test_index++, strings, data,
285 &lb_tests->tx_done[tx_queue->queue],
286 EFX_TX_QUEUE_NAME(tx_queue),
287 EFX_LOOPBACK_NAME(mode, "tx_done"));
289 efx_fill_test(test_index++, strings, data,
292 EFX_LOOPBACK_NAME(mode, "rx_good"));
293 efx_fill_test(test_index++, strings, data,
296 EFX_LOOPBACK_NAME(mode, "rx_bad"));
302 * efx_ethtool_fill_self_tests - get self-test details
304 * @tests: Efx self-test results structure, or %NULL
305 * @strings: Ethtool strings, or %NULL
306 * @data: Ethtool test results, or %NULL
308 * Get self-test number of strings, strings, and/or test results.
309 * Return number of strings (== number of test results).
311 * The reason for merging these three functions is to make sure that
312 * they can never be inconsistent.
314 static int efx_ethtool_fill_self_tests(struct efx_nic *efx,
315 struct efx_self_tests *tests,
316 u8 *strings, u64 *data)
318 struct efx_channel *channel;
319 unsigned int n = 0, i;
320 enum efx_loopback_mode mode;
322 efx_fill_test(n++, strings, data, &tests->phy_alive,
323 "phy", 0, "alive", NULL);
324 efx_fill_test(n++, strings, data, &tests->nvram,
325 "core", 0, "nvram", NULL);
326 efx_fill_test(n++, strings, data, &tests->interrupt,
327 "core", 0, "interrupt", NULL);
330 efx_for_each_channel(channel, efx) {
331 efx_fill_test(n++, strings, data,
332 &tests->eventq_dma[channel->channel],
333 EFX_CHANNEL_NAME(channel),
335 efx_fill_test(n++, strings, data,
336 &tests->eventq_int[channel->channel],
337 EFX_CHANNEL_NAME(channel),
341 efx_fill_test(n++, strings, data, &tests->memory,
342 "core", 0, "memory", NULL);
343 efx_fill_test(n++, strings, data, &tests->registers,
344 "core", 0, "registers", NULL);
346 if (efx->phy_op->run_tests != NULL) {
347 EFX_WARN_ON_PARANOID(efx->phy_op->test_name == NULL);
349 for (i = 0; true; ++i) {
352 EFX_WARN_ON_PARANOID(i >= EFX_MAX_PHY_TESTS);
353 name = efx->phy_op->test_name(efx, i);
357 efx_fill_test(n++, strings, data, &tests->phy_ext[i],
358 "phy", 0, name, NULL);
363 for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
364 if (!(efx->loopback_modes & (1 << mode)))
366 n = efx_fill_loopback_test(efx,
367 &tests->loopback[mode], mode, n,
374 static size_t efx_describe_per_queue_stats(struct efx_nic *efx, u8 *strings)
377 struct efx_channel *channel;
379 efx_for_each_channel(channel, efx) {
380 if (efx_channel_has_tx_queues(channel)) {
382 if (strings != NULL) {
383 snprintf(strings, ETH_GSTRING_LEN,
385 channel->tx_queue[0].queue /
388 strings += ETH_GSTRING_LEN;
392 efx_for_each_channel(channel, efx) {
393 if (efx_channel_has_rx_queue(channel)) {
395 if (strings != NULL) {
396 snprintf(strings, ETH_GSTRING_LEN,
397 "rx-%d.rx_packets", channel->channel);
398 strings += ETH_GSTRING_LEN;
405 static int efx_ethtool_get_sset_count(struct net_device *net_dev,
408 struct efx_nic *efx = netdev_priv(net_dev);
410 switch (string_set) {
412 return efx->type->describe_stats(efx, NULL) +
413 EFX_ETHTOOL_SW_STAT_COUNT +
414 efx_describe_per_queue_stats(efx, NULL) +
415 efx_ptp_describe_stats(efx, NULL);
417 return efx_ethtool_fill_self_tests(efx, NULL, NULL, NULL);
423 static void efx_ethtool_get_strings(struct net_device *net_dev,
424 u32 string_set, u8 *strings)
426 struct efx_nic *efx = netdev_priv(net_dev);
429 switch (string_set) {
431 strings += (efx->type->describe_stats(efx, strings) *
433 for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++)
434 strlcpy(strings + i * ETH_GSTRING_LEN,
435 efx_sw_stat_desc[i].name, ETH_GSTRING_LEN);
436 strings += EFX_ETHTOOL_SW_STAT_COUNT * ETH_GSTRING_LEN;
437 strings += (efx_describe_per_queue_stats(efx, strings) *
439 efx_ptp_describe_stats(efx, strings);
442 efx_ethtool_fill_self_tests(efx, NULL, strings, NULL);
445 /* No other string sets */
450 static void efx_ethtool_get_stats(struct net_device *net_dev,
451 struct ethtool_stats *stats,
454 struct efx_nic *efx = netdev_priv(net_dev);
455 const struct efx_sw_stat_desc *stat;
456 struct efx_channel *channel;
457 struct efx_tx_queue *tx_queue;
458 struct efx_rx_queue *rx_queue;
461 spin_lock_bh(&efx->stats_lock);
463 /* Get NIC statistics */
464 data += efx->type->update_stats(efx, data, NULL);
466 /* Get software statistics */
467 for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) {
468 stat = &efx_sw_stat_desc[i];
469 switch (stat->source) {
470 case EFX_ETHTOOL_STAT_SOURCE_nic:
471 data[i] = stat->get_stat((void *)efx + stat->offset);
473 case EFX_ETHTOOL_STAT_SOURCE_channel:
475 efx_for_each_channel(channel, efx)
476 data[i] += stat->get_stat((void *)channel +
479 case EFX_ETHTOOL_STAT_SOURCE_tx_queue:
481 efx_for_each_channel(channel, efx) {
482 efx_for_each_channel_tx_queue(tx_queue, channel)
484 stat->get_stat((void *)tx_queue
490 data += EFX_ETHTOOL_SW_STAT_COUNT;
492 spin_unlock_bh(&efx->stats_lock);
494 efx_for_each_channel(channel, efx) {
495 if (efx_channel_has_tx_queues(channel)) {
497 efx_for_each_channel_tx_queue(tx_queue, channel) {
498 *data += tx_queue->tx_packets;
503 efx_for_each_channel(channel, efx) {
504 if (efx_channel_has_rx_queue(channel)) {
506 efx_for_each_channel_rx_queue(rx_queue, channel) {
507 *data += rx_queue->rx_packets;
513 efx_ptp_update_stats(efx, data);
516 static void efx_ethtool_self_test(struct net_device *net_dev,
517 struct ethtool_test *test, u64 *data)
519 struct efx_nic *efx = netdev_priv(net_dev);
520 struct efx_self_tests *efx_tests;
524 efx_tests = kzalloc(sizeof(*efx_tests), GFP_KERNEL);
528 if (efx->state != STATE_READY) {
533 netif_info(efx, drv, efx->net_dev, "starting %sline testing\n",
534 (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
536 /* We need rx buffers and interrupts. */
537 already_up = (efx->net_dev->flags & IFF_UP);
539 rc = dev_open(efx->net_dev, NULL);
541 netif_err(efx, drv, efx->net_dev,
542 "failed opening device.\n");
547 rc = efx_selftest(efx, efx_tests, test->flags);
550 dev_close(efx->net_dev);
552 netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n",
553 rc == 0 ? "passed" : "failed",
554 (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
557 efx_ethtool_fill_self_tests(efx, efx_tests, NULL, data);
561 test->flags |= ETH_TEST_FL_FAILED;
564 /* Restart autonegotiation */
565 static int efx_ethtool_nway_reset(struct net_device *net_dev)
567 struct efx_nic *efx = netdev_priv(net_dev);
569 return mdio45_nway_restart(&efx->mdio);
573 * Each channel has a single IRQ and moderation timer, started by any
574 * completion (or other event). Unless the module parameter
575 * separate_tx_channels is set, IRQs and moderation are therefore
576 * shared between RX and TX completions. In this case, when RX IRQ
577 * moderation is explicitly changed then TX IRQ moderation is
578 * automatically changed too, but otherwise we fail if the two values
579 * are requested to be different.
581 * The hardware does not support a limit on the number of completions
582 * before an IRQ, so we do not use the max_frames fields. We should
583 * report and require that max_frames == (usecs != 0), but this would
584 * invalidate existing user documentation.
586 * The hardware does not have distinct settings for interrupt
587 * moderation while the previous IRQ is being handled, so we should
588 * not use the 'irq' fields. However, an earlier developer
589 * misunderstood the meaning of the 'irq' fields and the driver did
590 * not support the standard fields. To avoid invalidating existing
591 * user documentation, we report and accept changes through either the
592 * standard or 'irq' fields. If both are changed at the same time, we
593 * prefer the standard field.
595 * We implement adaptive IRQ moderation, but use a different algorithm
596 * from that assumed in the definition of struct ethtool_coalesce.
597 * Therefore we do not use any of the adaptive moderation parameters
601 static int efx_ethtool_get_coalesce(struct net_device *net_dev,
602 struct ethtool_coalesce *coalesce)
604 struct efx_nic *efx = netdev_priv(net_dev);
605 unsigned int tx_usecs, rx_usecs;
608 efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &rx_adaptive);
610 coalesce->tx_coalesce_usecs = tx_usecs;
611 coalesce->tx_coalesce_usecs_irq = tx_usecs;
612 coalesce->rx_coalesce_usecs = rx_usecs;
613 coalesce->rx_coalesce_usecs_irq = rx_usecs;
614 coalesce->use_adaptive_rx_coalesce = rx_adaptive;
619 static int efx_ethtool_set_coalesce(struct net_device *net_dev,
620 struct ethtool_coalesce *coalesce)
622 struct efx_nic *efx = netdev_priv(net_dev);
623 struct efx_channel *channel;
624 unsigned int tx_usecs, rx_usecs;
625 bool adaptive, rx_may_override_tx;
628 if (coalesce->use_adaptive_tx_coalesce)
631 efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &adaptive);
633 if (coalesce->rx_coalesce_usecs != rx_usecs)
634 rx_usecs = coalesce->rx_coalesce_usecs;
636 rx_usecs = coalesce->rx_coalesce_usecs_irq;
638 adaptive = coalesce->use_adaptive_rx_coalesce;
640 /* If channels are shared, TX IRQ moderation can be quietly
641 * overridden unless it is changed from its old value.
643 rx_may_override_tx = (coalesce->tx_coalesce_usecs == tx_usecs &&
644 coalesce->tx_coalesce_usecs_irq == tx_usecs);
645 if (coalesce->tx_coalesce_usecs != tx_usecs)
646 tx_usecs = coalesce->tx_coalesce_usecs;
648 tx_usecs = coalesce->tx_coalesce_usecs_irq;
650 rc = efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive,
655 efx_for_each_channel(channel, efx)
656 efx->type->push_irq_moderation(channel);
661 static void efx_ethtool_get_ringparam(struct net_device *net_dev,
662 struct ethtool_ringparam *ring)
664 struct efx_nic *efx = netdev_priv(net_dev);
666 ring->rx_max_pending = EFX_MAX_DMAQ_SIZE;
667 ring->tx_max_pending = EFX_TXQ_MAX_ENT(efx);
668 ring->rx_pending = efx->rxq_entries;
669 ring->tx_pending = efx->txq_entries;
672 static int efx_ethtool_set_ringparam(struct net_device *net_dev,
673 struct ethtool_ringparam *ring)
675 struct efx_nic *efx = netdev_priv(net_dev);
678 if (ring->rx_mini_pending || ring->rx_jumbo_pending ||
679 ring->rx_pending > EFX_MAX_DMAQ_SIZE ||
680 ring->tx_pending > EFX_TXQ_MAX_ENT(efx))
683 if (ring->rx_pending < EFX_RXQ_MIN_ENT) {
684 netif_err(efx, drv, efx->net_dev,
685 "RX queues cannot be smaller than %u\n",
690 txq_entries = max(ring->tx_pending, EFX_TXQ_MIN_ENT(efx));
691 if (txq_entries != ring->tx_pending)
692 netif_warn(efx, drv, efx->net_dev,
693 "increasing TX queue size to minimum of %u\n",
696 return efx_realloc_channels(efx, ring->rx_pending, txq_entries);
699 static int efx_ethtool_set_pauseparam(struct net_device *net_dev,
700 struct ethtool_pauseparam *pause)
702 struct efx_nic *efx = netdev_priv(net_dev);
703 u8 wanted_fc, old_fc;
707 mutex_lock(&efx->mac_lock);
709 wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
710 (pause->tx_pause ? EFX_FC_TX : 0) |
711 (pause->autoneg ? EFX_FC_AUTO : 0));
713 if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
714 netif_dbg(efx, drv, efx->net_dev,
715 "Flow control unsupported: tx ON rx OFF\n");
720 if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising[0]) {
721 netif_dbg(efx, drv, efx->net_dev,
722 "Autonegotiation is disabled\n");
727 /* Hook for Falcon bug 11482 workaround */
728 if (efx->type->prepare_enable_fc_tx &&
729 (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX))
730 efx->type->prepare_enable_fc_tx(efx);
732 old_adv = efx->link_advertising[0];
733 old_fc = efx->wanted_fc;
734 efx_link_set_wanted_fc(efx, wanted_fc);
735 if (efx->link_advertising[0] != old_adv ||
736 (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) {
737 rc = efx->phy_op->reconfigure(efx);
739 netif_err(efx, drv, efx->net_dev,
740 "Unable to advertise requested flow "
741 "control setting\n");
746 /* Reconfigure the MAC. The PHY *may* generate a link state change event
747 * if the user just changed the advertised capabilities, but there's no
748 * harm doing this twice */
749 efx_mac_reconfigure(efx);
752 mutex_unlock(&efx->mac_lock);
757 static void efx_ethtool_get_pauseparam(struct net_device *net_dev,
758 struct ethtool_pauseparam *pause)
760 struct efx_nic *efx = netdev_priv(net_dev);
762 pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX);
763 pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX);
764 pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO);
767 static void efx_ethtool_get_wol(struct net_device *net_dev,
768 struct ethtool_wolinfo *wol)
770 struct efx_nic *efx = netdev_priv(net_dev);
771 return efx->type->get_wol(efx, wol);
775 static int efx_ethtool_set_wol(struct net_device *net_dev,
776 struct ethtool_wolinfo *wol)
778 struct efx_nic *efx = netdev_priv(net_dev);
779 return efx->type->set_wol(efx, wol->wolopts);
782 static int efx_ethtool_reset(struct net_device *net_dev, u32 *flags)
784 struct efx_nic *efx = netdev_priv(net_dev);
787 rc = efx->type->map_reset_flags(flags);
791 return efx_reset(efx, rc);
794 /* MAC address mask including only I/G bit */
795 static const u8 mac_addr_ig_mask[ETH_ALEN] __aligned(2) = {0x01, 0, 0, 0, 0, 0};
797 #define IP4_ADDR_FULL_MASK ((__force __be32)~0)
798 #define IP_PROTO_FULL_MASK 0xFF
799 #define PORT_FULL_MASK ((__force __be16)~0)
800 #define ETHER_TYPE_FULL_MASK ((__force __be16)~0)
802 static inline void ip6_fill_mask(__be32 *mask)
804 mask[0] = mask[1] = mask[2] = mask[3] = ~(__be32)0;
807 static int efx_ethtool_get_class_rule(struct efx_nic *efx,
808 struct ethtool_rx_flow_spec *rule,
811 struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
812 struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
813 struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
814 struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
815 struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
816 struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
817 struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
818 struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
819 struct ethhdr *mac_entry = &rule->h_u.ether_spec;
820 struct ethhdr *mac_mask = &rule->m_u.ether_spec;
821 struct efx_filter_spec spec;
824 rc = efx_filter_get_filter_safe(efx, EFX_FILTER_PRI_MANUAL,
825 rule->location, &spec);
829 if (spec.dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP)
830 rule->ring_cookie = RX_CLS_FLOW_DISC;
832 rule->ring_cookie = spec.dmaq_id;
834 if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) &&
835 spec.ether_type == htons(ETH_P_IP) &&
836 (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) &&
837 (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
839 ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
840 EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
841 EFX_FILTER_MATCH_IP_PROTO |
842 EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) {
843 rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
844 TCP_V4_FLOW : UDP_V4_FLOW);
845 if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
846 ip_entry->ip4dst = spec.loc_host[0];
847 ip_mask->ip4dst = IP4_ADDR_FULL_MASK;
849 if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
850 ip_entry->ip4src = spec.rem_host[0];
851 ip_mask->ip4src = IP4_ADDR_FULL_MASK;
853 if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) {
854 ip_entry->pdst = spec.loc_port;
855 ip_mask->pdst = PORT_FULL_MASK;
857 if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) {
858 ip_entry->psrc = spec.rem_port;
859 ip_mask->psrc = PORT_FULL_MASK;
861 } else if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) &&
862 spec.ether_type == htons(ETH_P_IPV6) &&
863 (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) &&
864 (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
866 ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
867 EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
868 EFX_FILTER_MATCH_IP_PROTO |
869 EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) {
870 rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
871 TCP_V6_FLOW : UDP_V6_FLOW);
872 if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
873 memcpy(ip6_entry->ip6dst, spec.loc_host,
874 sizeof(ip6_entry->ip6dst));
875 ip6_fill_mask(ip6_mask->ip6dst);
877 if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
878 memcpy(ip6_entry->ip6src, spec.rem_host,
879 sizeof(ip6_entry->ip6src));
880 ip6_fill_mask(ip6_mask->ip6src);
882 if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) {
883 ip6_entry->pdst = spec.loc_port;
884 ip6_mask->pdst = PORT_FULL_MASK;
886 if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) {
887 ip6_entry->psrc = spec.rem_port;
888 ip6_mask->psrc = PORT_FULL_MASK;
890 } else if (!(spec.match_flags &
891 ~(EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG |
892 EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_ETHER_TYPE |
893 EFX_FILTER_MATCH_OUTER_VID))) {
894 rule->flow_type = ETHER_FLOW;
895 if (spec.match_flags &
896 (EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG)) {
897 ether_addr_copy(mac_entry->h_dest, spec.loc_mac);
898 if (spec.match_flags & EFX_FILTER_MATCH_LOC_MAC)
899 eth_broadcast_addr(mac_mask->h_dest);
901 ether_addr_copy(mac_mask->h_dest,
904 if (spec.match_flags & EFX_FILTER_MATCH_REM_MAC) {
905 ether_addr_copy(mac_entry->h_source, spec.rem_mac);
906 eth_broadcast_addr(mac_mask->h_source);
908 if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) {
909 mac_entry->h_proto = spec.ether_type;
910 mac_mask->h_proto = ETHER_TYPE_FULL_MASK;
912 } else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
913 spec.ether_type == htons(ETH_P_IP) &&
915 ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
916 EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
917 EFX_FILTER_MATCH_IP_PROTO))) {
918 rule->flow_type = IPV4_USER_FLOW;
919 uip_entry->ip_ver = ETH_RX_NFC_IP4;
920 if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) {
921 uip_mask->proto = IP_PROTO_FULL_MASK;
922 uip_entry->proto = spec.ip_proto;
924 if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
925 uip_entry->ip4dst = spec.loc_host[0];
926 uip_mask->ip4dst = IP4_ADDR_FULL_MASK;
928 if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
929 uip_entry->ip4src = spec.rem_host[0];
930 uip_mask->ip4src = IP4_ADDR_FULL_MASK;
932 } else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
933 spec.ether_type == htons(ETH_P_IPV6) &&
935 ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
936 EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
937 EFX_FILTER_MATCH_IP_PROTO))) {
938 rule->flow_type = IPV6_USER_FLOW;
939 if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) {
940 uip6_mask->l4_proto = IP_PROTO_FULL_MASK;
941 uip6_entry->l4_proto = spec.ip_proto;
943 if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
944 memcpy(uip6_entry->ip6dst, spec.loc_host,
945 sizeof(uip6_entry->ip6dst));
946 ip6_fill_mask(uip6_mask->ip6dst);
948 if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
949 memcpy(uip6_entry->ip6src, spec.rem_host,
950 sizeof(uip6_entry->ip6src));
951 ip6_fill_mask(uip6_mask->ip6src);
954 /* The above should handle all filters that we insert */
959 if (spec.match_flags & EFX_FILTER_MATCH_OUTER_VID) {
960 rule->flow_type |= FLOW_EXT;
961 rule->h_ext.vlan_tci = spec.outer_vid;
962 rule->m_ext.vlan_tci = htons(0xfff);
965 if (spec.flags & EFX_FILTER_FLAG_RX_RSS) {
966 rule->flow_type |= FLOW_RSS;
967 *rss_context = spec.rss_context;
974 efx_ethtool_get_rxnfc(struct net_device *net_dev,
975 struct ethtool_rxnfc *info, u32 *rule_locs)
977 struct efx_nic *efx = netdev_priv(net_dev);
982 case ETHTOOL_GRXRINGS:
983 info->data = efx->n_rx_channels;
986 case ETHTOOL_GRXFH: {
987 struct efx_rss_context *ctx = &efx->rss_context;
989 mutex_lock(&efx->rss_lock);
990 if (info->flow_type & FLOW_RSS && info->rss_context) {
991 ctx = efx_find_rss_context_entry(efx, info->rss_context);
998 if (!efx_rss_active(ctx)) /* No RSS */
1000 switch (info->flow_type & ~FLOW_RSS) {
1002 if (ctx->rx_hash_udp_4tuple)
1005 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1008 case AH_ESP_V4_FLOW:
1010 info->data |= RXH_IP_SRC | RXH_IP_DST;
1013 if (ctx->rx_hash_udp_4tuple)
1016 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1019 case AH_ESP_V6_FLOW:
1021 info->data |= RXH_IP_SRC | RXH_IP_DST;
1027 mutex_unlock(&efx->rss_lock);
1031 case ETHTOOL_GRXCLSRLCNT:
1032 info->data = efx_filter_get_rx_id_limit(efx);
1033 if (info->data == 0)
1035 info->data |= RX_CLS_LOC_SPECIAL;
1037 efx_filter_count_rx_used(efx, EFX_FILTER_PRI_MANUAL);
1040 case ETHTOOL_GRXCLSRULE:
1041 if (efx_filter_get_rx_id_limit(efx) == 0)
1043 rc = efx_ethtool_get_class_rule(efx, &info->fs, &rss_context);
1046 if (info->fs.flow_type & FLOW_RSS)
1047 info->rss_context = rss_context;
1050 case ETHTOOL_GRXCLSRLALL:
1051 info->data = efx_filter_get_rx_id_limit(efx);
1052 if (info->data == 0)
1054 rc = efx_filter_get_rx_ids(efx, EFX_FILTER_PRI_MANUAL,
1055 rule_locs, info->rule_cnt);
1058 info->rule_cnt = rc;
1066 static inline bool ip6_mask_is_full(__be32 mask[4])
1068 return !~(mask[0] & mask[1] & mask[2] & mask[3]);
1071 static inline bool ip6_mask_is_empty(__be32 mask[4])
1073 return !(mask[0] | mask[1] | mask[2] | mask[3]);
1076 static int efx_ethtool_set_class_rule(struct efx_nic *efx,
1077 struct ethtool_rx_flow_spec *rule,
1080 struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
1081 struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
1082 struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
1083 struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
1084 struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
1085 struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
1086 struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
1087 struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
1088 u32 flow_type = rule->flow_type & ~(FLOW_EXT | FLOW_RSS);
1089 struct ethhdr *mac_entry = &rule->h_u.ether_spec;
1090 struct ethhdr *mac_mask = &rule->m_u.ether_spec;
1091 enum efx_filter_flags flags = 0;
1092 struct efx_filter_spec spec;
1095 /* Check that user wants us to choose the location */
1096 if (rule->location != RX_CLS_LOC_ANY)
1099 /* Range-check ring_cookie */
1100 if (rule->ring_cookie >= efx->n_rx_channels &&
1101 rule->ring_cookie != RX_CLS_FLOW_DISC)
1104 /* Check for unsupported extensions */
1105 if ((rule->flow_type & FLOW_EXT) &&
1106 (rule->m_ext.vlan_etype || rule->m_ext.data[0] ||
1107 rule->m_ext.data[1]))
1110 if (efx->rx_scatter)
1111 flags |= EFX_FILTER_FLAG_RX_SCATTER;
1112 if (rule->flow_type & FLOW_RSS)
1113 flags |= EFX_FILTER_FLAG_RX_RSS;
1115 efx_filter_init_rx(&spec, EFX_FILTER_PRI_MANUAL, flags,
1116 (rule->ring_cookie == RX_CLS_FLOW_DISC) ?
1117 EFX_FILTER_RX_DMAQ_ID_DROP : rule->ring_cookie);
1119 if (rule->flow_type & FLOW_RSS)
1120 spec.rss_context = rss_context;
1122 switch (flow_type) {
1125 spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
1126 EFX_FILTER_MATCH_IP_PROTO);
1127 spec.ether_type = htons(ETH_P_IP);
1128 spec.ip_proto = flow_type == TCP_V4_FLOW ? IPPROTO_TCP
1130 if (ip_mask->ip4dst) {
1131 if (ip_mask->ip4dst != IP4_ADDR_FULL_MASK)
1133 spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1134 spec.loc_host[0] = ip_entry->ip4dst;
1136 if (ip_mask->ip4src) {
1137 if (ip_mask->ip4src != IP4_ADDR_FULL_MASK)
1139 spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1140 spec.rem_host[0] = ip_entry->ip4src;
1142 if (ip_mask->pdst) {
1143 if (ip_mask->pdst != PORT_FULL_MASK)
1145 spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
1146 spec.loc_port = ip_entry->pdst;
1148 if (ip_mask->psrc) {
1149 if (ip_mask->psrc != PORT_FULL_MASK)
1151 spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
1152 spec.rem_port = ip_entry->psrc;
1160 spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
1161 EFX_FILTER_MATCH_IP_PROTO);
1162 spec.ether_type = htons(ETH_P_IPV6);
1163 spec.ip_proto = flow_type == TCP_V6_FLOW ? IPPROTO_TCP
1165 if (!ip6_mask_is_empty(ip6_mask->ip6dst)) {
1166 if (!ip6_mask_is_full(ip6_mask->ip6dst))
1168 spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1169 memcpy(spec.loc_host, ip6_entry->ip6dst, sizeof(spec.loc_host));
1171 if (!ip6_mask_is_empty(ip6_mask->ip6src)) {
1172 if (!ip6_mask_is_full(ip6_mask->ip6src))
1174 spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1175 memcpy(spec.rem_host, ip6_entry->ip6src, sizeof(spec.rem_host));
1177 if (ip6_mask->pdst) {
1178 if (ip6_mask->pdst != PORT_FULL_MASK)
1180 spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
1181 spec.loc_port = ip6_entry->pdst;
1183 if (ip6_mask->psrc) {
1184 if (ip6_mask->psrc != PORT_FULL_MASK)
1186 spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
1187 spec.rem_port = ip6_entry->psrc;
1189 if (ip6_mask->tclass)
1193 case IPV4_USER_FLOW:
1194 if (uip_mask->l4_4_bytes || uip_mask->tos || uip_mask->ip_ver ||
1195 uip_entry->ip_ver != ETH_RX_NFC_IP4)
1197 spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE;
1198 spec.ether_type = htons(ETH_P_IP);
1199 if (uip_mask->ip4dst) {
1200 if (uip_mask->ip4dst != IP4_ADDR_FULL_MASK)
1202 spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1203 spec.loc_host[0] = uip_entry->ip4dst;
1205 if (uip_mask->ip4src) {
1206 if (uip_mask->ip4src != IP4_ADDR_FULL_MASK)
1208 spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1209 spec.rem_host[0] = uip_entry->ip4src;
1211 if (uip_mask->proto) {
1212 if (uip_mask->proto != IP_PROTO_FULL_MASK)
1214 spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO;
1215 spec.ip_proto = uip_entry->proto;
1219 case IPV6_USER_FLOW:
1220 if (uip6_mask->l4_4_bytes || uip6_mask->tclass)
1222 spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE;
1223 spec.ether_type = htons(ETH_P_IPV6);
1224 if (!ip6_mask_is_empty(uip6_mask->ip6dst)) {
1225 if (!ip6_mask_is_full(uip6_mask->ip6dst))
1227 spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1228 memcpy(spec.loc_host, uip6_entry->ip6dst, sizeof(spec.loc_host));
1230 if (!ip6_mask_is_empty(uip6_mask->ip6src)) {
1231 if (!ip6_mask_is_full(uip6_mask->ip6src))
1233 spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1234 memcpy(spec.rem_host, uip6_entry->ip6src, sizeof(spec.rem_host));
1236 if (uip6_mask->l4_proto) {
1237 if (uip6_mask->l4_proto != IP_PROTO_FULL_MASK)
1239 spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO;
1240 spec.ip_proto = uip6_entry->l4_proto;
1245 if (!is_zero_ether_addr(mac_mask->h_dest)) {
1246 if (ether_addr_equal(mac_mask->h_dest,
1248 spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC_IG;
1249 else if (is_broadcast_ether_addr(mac_mask->h_dest))
1250 spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC;
1253 ether_addr_copy(spec.loc_mac, mac_entry->h_dest);
1255 if (!is_zero_ether_addr(mac_mask->h_source)) {
1256 if (!is_broadcast_ether_addr(mac_mask->h_source))
1258 spec.match_flags |= EFX_FILTER_MATCH_REM_MAC;
1259 ether_addr_copy(spec.rem_mac, mac_entry->h_source);
1261 if (mac_mask->h_proto) {
1262 if (mac_mask->h_proto != ETHER_TYPE_FULL_MASK)
1264 spec.match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
1265 spec.ether_type = mac_entry->h_proto;
1273 if ((rule->flow_type & FLOW_EXT) && rule->m_ext.vlan_tci) {
1274 if (rule->m_ext.vlan_tci != htons(0xfff))
1276 spec.match_flags |= EFX_FILTER_MATCH_OUTER_VID;
1277 spec.outer_vid = rule->h_ext.vlan_tci;
1280 rc = efx_filter_insert_filter(efx, &spec, true);
1284 rule->location = rc;
1288 static int efx_ethtool_set_rxnfc(struct net_device *net_dev,
1289 struct ethtool_rxnfc *info)
1291 struct efx_nic *efx = netdev_priv(net_dev);
1293 if (efx_filter_get_rx_id_limit(efx) == 0)
1296 switch (info->cmd) {
1297 case ETHTOOL_SRXCLSRLINS:
1298 return efx_ethtool_set_class_rule(efx, &info->fs,
1301 case ETHTOOL_SRXCLSRLDEL:
1302 return efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_MANUAL,
1310 static u32 efx_ethtool_get_rxfh_indir_size(struct net_device *net_dev)
1312 struct efx_nic *efx = netdev_priv(net_dev);
1314 if (efx->n_rx_channels == 1)
1316 return ARRAY_SIZE(efx->rss_context.rx_indir_table);
1319 static u32 efx_ethtool_get_rxfh_key_size(struct net_device *net_dev)
1321 struct efx_nic *efx = netdev_priv(net_dev);
1323 return efx->type->rx_hash_key_size;
1326 static int efx_ethtool_get_rxfh(struct net_device *net_dev, u32 *indir, u8 *key,
1329 struct efx_nic *efx = netdev_priv(net_dev);
1332 rc = efx->type->rx_pull_rss_config(efx);
1337 *hfunc = ETH_RSS_HASH_TOP;
1339 memcpy(indir, efx->rss_context.rx_indir_table,
1340 sizeof(efx->rss_context.rx_indir_table));
1342 memcpy(key, efx->rss_context.rx_hash_key,
1343 efx->type->rx_hash_key_size);
1347 static int efx_ethtool_set_rxfh(struct net_device *net_dev, const u32 *indir,
1348 const u8 *key, const u8 hfunc)
1350 struct efx_nic *efx = netdev_priv(net_dev);
1352 /* Hash function is Toeplitz, cannot be changed */
1353 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1359 key = efx->rss_context.rx_hash_key;
1361 indir = efx->rss_context.rx_indir_table;
1363 return efx->type->rx_push_rss_config(efx, true, indir, key);
1366 static int efx_ethtool_get_rxfh_context(struct net_device *net_dev, u32 *indir,
1367 u8 *key, u8 *hfunc, u32 rss_context)
1369 struct efx_nic *efx = netdev_priv(net_dev);
1370 struct efx_rss_context *ctx;
1373 if (!efx->type->rx_pull_rss_context_config)
1376 mutex_lock(&efx->rss_lock);
1377 ctx = efx_find_rss_context_entry(efx, rss_context);
1382 rc = efx->type->rx_pull_rss_context_config(efx, ctx);
1387 *hfunc = ETH_RSS_HASH_TOP;
1389 memcpy(indir, ctx->rx_indir_table, sizeof(ctx->rx_indir_table));
1391 memcpy(key, ctx->rx_hash_key, efx->type->rx_hash_key_size);
1393 mutex_unlock(&efx->rss_lock);
1397 static int efx_ethtool_set_rxfh_context(struct net_device *net_dev,
1398 const u32 *indir, const u8 *key,
1399 const u8 hfunc, u32 *rss_context,
1402 struct efx_nic *efx = netdev_priv(net_dev);
1403 struct efx_rss_context *ctx;
1404 bool allocated = false;
1407 if (!efx->type->rx_push_rss_context_config)
1409 /* Hash function is Toeplitz, cannot be changed */
1410 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1413 mutex_lock(&efx->rss_lock);
1415 if (*rss_context == ETH_RXFH_CONTEXT_ALLOC) {
1417 /* alloc + delete == Nothing to do */
1421 ctx = efx_alloc_rss_context_entry(efx);
1426 ctx->context_id = EFX_EF10_RSS_CONTEXT_INVALID;
1427 /* Initialise indir table and key to defaults */
1428 efx_set_default_rx_indir_table(efx, ctx);
1429 netdev_rss_key_fill(ctx->rx_hash_key, sizeof(ctx->rx_hash_key));
1432 ctx = efx_find_rss_context_entry(efx, *rss_context);
1440 /* delete this context */
1441 rc = efx->type->rx_push_rss_context_config(efx, ctx, NULL, NULL);
1443 efx_free_rss_context_entry(ctx);
1448 key = ctx->rx_hash_key;
1450 indir = ctx->rx_indir_table;
1452 rc = efx->type->rx_push_rss_context_config(efx, ctx, indir, key);
1453 if (rc && allocated)
1454 efx_free_rss_context_entry(ctx);
1456 *rss_context = ctx->user_id;
1458 mutex_unlock(&efx->rss_lock);
1462 static int efx_ethtool_get_ts_info(struct net_device *net_dev,
1463 struct ethtool_ts_info *ts_info)
1465 struct efx_nic *efx = netdev_priv(net_dev);
1467 /* Software capabilities */
1468 ts_info->so_timestamping = (SOF_TIMESTAMPING_RX_SOFTWARE |
1469 SOF_TIMESTAMPING_SOFTWARE);
1470 ts_info->phc_index = -1;
1472 efx_ptp_get_ts_info(efx, ts_info);
1476 static int efx_ethtool_get_module_eeprom(struct net_device *net_dev,
1477 struct ethtool_eeprom *ee,
1480 struct efx_nic *efx = netdev_priv(net_dev);
1483 if (!efx->phy_op || !efx->phy_op->get_module_eeprom)
1486 mutex_lock(&efx->mac_lock);
1487 ret = efx->phy_op->get_module_eeprom(efx, ee, data);
1488 mutex_unlock(&efx->mac_lock);
1493 static int efx_ethtool_get_module_info(struct net_device *net_dev,
1494 struct ethtool_modinfo *modinfo)
1496 struct efx_nic *efx = netdev_priv(net_dev);
1499 if (!efx->phy_op || !efx->phy_op->get_module_info)
1502 mutex_lock(&efx->mac_lock);
1503 ret = efx->phy_op->get_module_info(efx, modinfo);
1504 mutex_unlock(&efx->mac_lock);
1509 static int efx_ethtool_get_fecparam(struct net_device *net_dev,
1510 struct ethtool_fecparam *fecparam)
1512 struct efx_nic *efx = netdev_priv(net_dev);
1515 if (!efx->phy_op || !efx->phy_op->get_fecparam)
1517 mutex_lock(&efx->mac_lock);
1518 rc = efx->phy_op->get_fecparam(efx, fecparam);
1519 mutex_unlock(&efx->mac_lock);
1524 static int efx_ethtool_set_fecparam(struct net_device *net_dev,
1525 struct ethtool_fecparam *fecparam)
1527 struct efx_nic *efx = netdev_priv(net_dev);
1530 if (!efx->phy_op || !efx->phy_op->get_fecparam)
1532 mutex_lock(&efx->mac_lock);
1533 rc = efx->phy_op->set_fecparam(efx, fecparam);
1534 mutex_unlock(&efx->mac_lock);
1539 const struct ethtool_ops efx_ethtool_ops = {
1540 .get_drvinfo = efx_ethtool_get_drvinfo,
1541 .get_regs_len = efx_ethtool_get_regs_len,
1542 .get_regs = efx_ethtool_get_regs,
1543 .get_msglevel = efx_ethtool_get_msglevel,
1544 .set_msglevel = efx_ethtool_set_msglevel,
1545 .nway_reset = efx_ethtool_nway_reset,
1546 .get_link = ethtool_op_get_link,
1547 .get_coalesce = efx_ethtool_get_coalesce,
1548 .set_coalesce = efx_ethtool_set_coalesce,
1549 .get_ringparam = efx_ethtool_get_ringparam,
1550 .set_ringparam = efx_ethtool_set_ringparam,
1551 .get_pauseparam = efx_ethtool_get_pauseparam,
1552 .set_pauseparam = efx_ethtool_set_pauseparam,
1553 .get_sset_count = efx_ethtool_get_sset_count,
1554 .self_test = efx_ethtool_self_test,
1555 .get_strings = efx_ethtool_get_strings,
1556 .set_phys_id = efx_ethtool_phys_id,
1557 .get_ethtool_stats = efx_ethtool_get_stats,
1558 .get_wol = efx_ethtool_get_wol,
1559 .set_wol = efx_ethtool_set_wol,
1560 .reset = efx_ethtool_reset,
1561 .get_rxnfc = efx_ethtool_get_rxnfc,
1562 .set_rxnfc = efx_ethtool_set_rxnfc,
1563 .get_rxfh_indir_size = efx_ethtool_get_rxfh_indir_size,
1564 .get_rxfh_key_size = efx_ethtool_get_rxfh_key_size,
1565 .get_rxfh = efx_ethtool_get_rxfh,
1566 .set_rxfh = efx_ethtool_set_rxfh,
1567 .get_rxfh_context = efx_ethtool_get_rxfh_context,
1568 .set_rxfh_context = efx_ethtool_set_rxfh_context,
1569 .get_ts_info = efx_ethtool_get_ts_info,
1570 .get_module_info = efx_ethtool_get_module_info,
1571 .get_module_eeprom = efx_ethtool_get_module_eeprom,
1572 .get_link_ksettings = efx_ethtool_get_link_ksettings,
1573 .set_link_ksettings = efx_ethtool_set_link_ksettings,
1574 .get_fecparam = efx_ethtool_get_fecparam,
1575 .set_fecparam = efx_ethtool_set_fecparam,