Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /****************************************************************************
0003  * Driver for Solarflare network controllers and boards
0004  * Copyright 2019 Solarflare Communications Inc.
0005  *
0006  * This program is free software; you can redistribute it and/or modify it
0007  * under the terms of the GNU General Public License version 2 as published
0008  * by the Free Software Foundation, incorporated herein by reference.
0009  */
0010 #include <linux/module.h>
0011 #include <linux/netdevice.h>
0012 #include "net_driver.h"
0013 #include "mcdi.h"
0014 #include "nic.h"
0015 #include "selftest.h"
0016 #include "rx_common.h"
0017 #include "ethtool_common.h"
0018 #include "mcdi_port_common.h"
0019 
0020 struct efx_sw_stat_desc {
0021     const char *name;
0022     enum {
0023         EFX_ETHTOOL_STAT_SOURCE_nic,
0024         EFX_ETHTOOL_STAT_SOURCE_channel,
0025         EFX_ETHTOOL_STAT_SOURCE_tx_queue
0026     } source;
0027     unsigned int offset;
0028     u64 (*get_stat)(void *field); /* Reader function */
0029 };
0030 
0031 /* Initialiser for a struct efx_sw_stat_desc with type-checking */
0032 #define EFX_ETHTOOL_STAT(stat_name, source_name, field, field_type, \
0033                 get_stat_function) {            \
0034     .name = #stat_name,                     \
0035     .source = EFX_ETHTOOL_STAT_SOURCE_##source_name,        \
0036     .offset = ((((field_type *) 0) ==               \
0037               &((struct efx_##source_name *)0)->field) ?    \
0038             offsetof(struct efx_##source_name, field) :     \
0039             offsetof(struct efx_##source_name, field)),     \
0040     .get_stat = get_stat_function,                  \
0041 }
0042 
0043 static u64 efx_get_uint_stat(void *field)
0044 {
0045     return *(unsigned int *)field;
0046 }
0047 
0048 static u64 efx_get_atomic_stat(void *field)
0049 {
0050     return atomic_read((atomic_t *) field);
0051 }
0052 
0053 #define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field)        \
0054     EFX_ETHTOOL_STAT(field, nic, field,         \
0055              atomic_t, efx_get_atomic_stat)
0056 
0057 #define EFX_ETHTOOL_UINT_CHANNEL_STAT(field)            \
0058     EFX_ETHTOOL_STAT(field, channel, n_##field,     \
0059              unsigned int, efx_get_uint_stat)
0060 #define EFX_ETHTOOL_UINT_CHANNEL_STAT_NO_N(field)       \
0061     EFX_ETHTOOL_STAT(field, channel, field,         \
0062              unsigned int, efx_get_uint_stat)
0063 
0064 #define EFX_ETHTOOL_UINT_TXQ_STAT(field)            \
0065     EFX_ETHTOOL_STAT(tx_##field, tx_queue, field,       \
0066              unsigned int, efx_get_uint_stat)
0067 
0068 static const struct efx_sw_stat_desc efx_sw_stat_desc[] = {
0069     EFX_ETHTOOL_UINT_TXQ_STAT(merge_events),
0070     EFX_ETHTOOL_UINT_TXQ_STAT(tso_bursts),
0071     EFX_ETHTOOL_UINT_TXQ_STAT(tso_long_headers),
0072     EFX_ETHTOOL_UINT_TXQ_STAT(tso_packets),
0073     EFX_ETHTOOL_UINT_TXQ_STAT(tso_fallbacks),
0074     EFX_ETHTOOL_UINT_TXQ_STAT(pushes),
0075     EFX_ETHTOOL_UINT_TXQ_STAT(pio_packets),
0076     EFX_ETHTOOL_UINT_TXQ_STAT(cb_packets),
0077     EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset),
0078     EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc),
0079     EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),
0080     EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err),
0081     EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_inner_ip_hdr_chksum_err),
0082     EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_inner_tcp_udp_chksum_err),
0083     EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_outer_ip_hdr_chksum_err),
0084     EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_outer_tcp_udp_chksum_err),
0085     EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_eth_crc_err),
0086     EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch),
0087     EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
0088     EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_events),
0089     EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_packets),
0090     EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_xdp_drops),
0091     EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_xdp_bad_drops),
0092     EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_xdp_tx),
0093     EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_xdp_redirect),
0094 #ifdef CONFIG_RFS_ACCEL
0095     EFX_ETHTOOL_UINT_CHANNEL_STAT_NO_N(rfs_filter_count),
0096     EFX_ETHTOOL_UINT_CHANNEL_STAT(rfs_succeeded),
0097     EFX_ETHTOOL_UINT_CHANNEL_STAT(rfs_failed),
0098 #endif
0099 };
0100 
0101 #define EFX_ETHTOOL_SW_STAT_COUNT ARRAY_SIZE(efx_sw_stat_desc)
0102 
0103 void efx_siena_ethtool_get_drvinfo(struct net_device *net_dev,
0104                    struct ethtool_drvinfo *info)
0105 {
0106     struct efx_nic *efx = netdev_priv(net_dev);
0107 
0108     strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
0109     efx_siena_mcdi_print_fwver(efx, info->fw_version,
0110                    sizeof(info->fw_version));
0111     strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
0112 }
0113 
0114 u32 efx_siena_ethtool_get_msglevel(struct net_device *net_dev)
0115 {
0116     struct efx_nic *efx = netdev_priv(net_dev);
0117 
0118     return efx->msg_enable;
0119 }
0120 
0121 void efx_siena_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable)
0122 {
0123     struct efx_nic *efx = netdev_priv(net_dev);
0124 
0125     efx->msg_enable = msg_enable;
0126 }
0127 
0128 void efx_siena_ethtool_get_pauseparam(struct net_device *net_dev,
0129                       struct ethtool_pauseparam *pause)
0130 {
0131     struct efx_nic *efx = netdev_priv(net_dev);
0132 
0133     pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX);
0134     pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX);
0135     pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO);
0136 }
0137 
0138 int efx_siena_ethtool_set_pauseparam(struct net_device *net_dev,
0139                      struct ethtool_pauseparam *pause)
0140 {
0141     struct efx_nic *efx = netdev_priv(net_dev);
0142     u8 wanted_fc, old_fc;
0143     u32 old_adv;
0144     int rc = 0;
0145 
0146     mutex_lock(&efx->mac_lock);
0147 
0148     wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
0149              (pause->tx_pause ? EFX_FC_TX : 0) |
0150              (pause->autoneg ? EFX_FC_AUTO : 0));
0151 
0152     if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
0153         netif_dbg(efx, drv, efx->net_dev,
0154               "Flow control unsupported: tx ON rx OFF\n");
0155         rc = -EINVAL;
0156         goto out;
0157     }
0158 
0159     if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising[0]) {
0160         netif_dbg(efx, drv, efx->net_dev,
0161               "Autonegotiation is disabled\n");
0162         rc = -EINVAL;
0163         goto out;
0164     }
0165 
0166     /* Hook for Falcon bug 11482 workaround */
0167     if (efx->type->prepare_enable_fc_tx &&
0168         (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX))
0169         efx->type->prepare_enable_fc_tx(efx);
0170 
0171     old_adv = efx->link_advertising[0];
0172     old_fc = efx->wanted_fc;
0173     efx_siena_link_set_wanted_fc(efx, wanted_fc);
0174     if (efx->link_advertising[0] != old_adv ||
0175         (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) {
0176         rc = efx_siena_mcdi_port_reconfigure(efx);
0177         if (rc) {
0178             netif_err(efx, drv, efx->net_dev,
0179                   "Unable to advertise requested flow "
0180                   "control setting\n");
0181             goto out;
0182         }
0183     }
0184 
0185     /* Reconfigure the MAC. The PHY *may* generate a link state change event
0186      * if the user just changed the advertised capabilities, but there's no
0187      * harm doing this twice */
0188     efx_siena_mac_reconfigure(efx, false);
0189 
0190 out:
0191     mutex_unlock(&efx->mac_lock);
0192 
0193     return rc;
0194 }
0195 
0196 /**
0197  * efx_fill_test - fill in an individual self-test entry
0198  * @test_index:     Index of the test
0199  * @strings:        Ethtool strings, or %NULL
0200  * @data:       Ethtool test results, or %NULL
0201  * @test:       Pointer to test result (used only if data != %NULL)
0202  * @unit_format:    Unit name format (e.g. "chan\%d")
0203  * @unit_id:        Unit id (e.g. 0 for "chan0")
0204  * @test_format:    Test name format (e.g. "loopback.\%s.tx.sent")
0205  * @test_id:        Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
0206  *
0207  * Fill in an individual self-test entry.
0208  */
0209 static void efx_fill_test(unsigned int test_index, u8 *strings, u64 *data,
0210               int *test, const char *unit_format, int unit_id,
0211               const char *test_format, const char *test_id)
0212 {
0213     char unit_str[ETH_GSTRING_LEN], test_str[ETH_GSTRING_LEN];
0214 
0215     /* Fill data value, if applicable */
0216     if (data)
0217         data[test_index] = *test;
0218 
0219     /* Fill string, if applicable */
0220     if (strings) {
0221         if (strchr(unit_format, '%'))
0222             snprintf(unit_str, sizeof(unit_str),
0223                  unit_format, unit_id);
0224         else
0225             strcpy(unit_str, unit_format);
0226         snprintf(test_str, sizeof(test_str), test_format, test_id);
0227         snprintf(strings + test_index * ETH_GSTRING_LEN,
0228              ETH_GSTRING_LEN,
0229              "%-6s %-24s", unit_str, test_str);
0230     }
0231 }
0232 
0233 #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
0234 #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->label
0235 #define EFX_LOOPBACK_NAME(_mode, _counter)          \
0236     "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_siena_loopback_mode)
0237 
0238 /**
0239  * efx_fill_loopback_test - fill in a block of loopback self-test entries
0240  * @efx:        Efx NIC
0241  * @lb_tests:       Efx loopback self-test results structure
0242  * @mode:       Loopback test mode
0243  * @test_index:     Starting index of the test
0244  * @strings:        Ethtool strings, or %NULL
0245  * @data:       Ethtool test results, or %NULL
0246  *
0247  * Fill in a block of loopback self-test entries.  Return new test
0248  * index.
0249  */
0250 static int efx_fill_loopback_test(struct efx_nic *efx,
0251                   struct efx_loopback_self_tests *lb_tests,
0252                   enum efx_loopback_mode mode,
0253                   unsigned int test_index,
0254                   u8 *strings, u64 *data)
0255 {
0256     struct efx_channel *channel =
0257         efx_get_channel(efx, efx->tx_channel_offset);
0258     struct efx_tx_queue *tx_queue;
0259 
0260     efx_for_each_channel_tx_queue(tx_queue, channel) {
0261         efx_fill_test(test_index++, strings, data,
0262                   &lb_tests->tx_sent[tx_queue->label],
0263                   EFX_TX_QUEUE_NAME(tx_queue),
0264                   EFX_LOOPBACK_NAME(mode, "tx_sent"));
0265         efx_fill_test(test_index++, strings, data,
0266                   &lb_tests->tx_done[tx_queue->label],
0267                   EFX_TX_QUEUE_NAME(tx_queue),
0268                   EFX_LOOPBACK_NAME(mode, "tx_done"));
0269     }
0270     efx_fill_test(test_index++, strings, data,
0271               &lb_tests->rx_good,
0272               "rx", 0,
0273               EFX_LOOPBACK_NAME(mode, "rx_good"));
0274     efx_fill_test(test_index++, strings, data,
0275               &lb_tests->rx_bad,
0276               "rx", 0,
0277               EFX_LOOPBACK_NAME(mode, "rx_bad"));
0278 
0279     return test_index;
0280 }
0281 
0282 /**
0283  * efx_ethtool_fill_self_tests - get self-test details
0284  * @efx:        Efx NIC
0285  * @tests:      Efx self-test results structure, or %NULL
0286  * @strings:        Ethtool strings, or %NULL
0287  * @data:       Ethtool test results, or %NULL
0288  *
0289  * Get self-test number of strings, strings, and/or test results.
0290  * Return number of strings (== number of test results).
0291  *
0292  * The reason for merging these three functions is to make sure that
0293  * they can never be inconsistent.
0294  */
0295 static int efx_ethtool_fill_self_tests(struct efx_nic *efx,
0296                        struct efx_self_tests *tests,
0297                        u8 *strings, u64 *data)
0298 {
0299     struct efx_channel *channel;
0300     unsigned int n = 0, i;
0301     enum efx_loopback_mode mode;
0302 
0303     efx_fill_test(n++, strings, data, &tests->phy_alive,
0304               "phy", 0, "alive", NULL);
0305     efx_fill_test(n++, strings, data, &tests->nvram,
0306               "core", 0, "nvram", NULL);
0307     efx_fill_test(n++, strings, data, &tests->interrupt,
0308               "core", 0, "interrupt", NULL);
0309 
0310     /* Event queues */
0311     efx_for_each_channel(channel, efx) {
0312         efx_fill_test(n++, strings, data,
0313                   &tests->eventq_dma[channel->channel],
0314                   EFX_CHANNEL_NAME(channel),
0315                   "eventq.dma", NULL);
0316         efx_fill_test(n++, strings, data,
0317                   &tests->eventq_int[channel->channel],
0318                   EFX_CHANNEL_NAME(channel),
0319                   "eventq.int", NULL);
0320     }
0321 
0322     efx_fill_test(n++, strings, data, &tests->memory,
0323               "core", 0, "memory", NULL);
0324     efx_fill_test(n++, strings, data, &tests->registers,
0325               "core", 0, "registers", NULL);
0326 
0327     for (i = 0; true; ++i) {
0328         const char *name;
0329 
0330         EFX_WARN_ON_PARANOID(i >= EFX_MAX_PHY_TESTS);
0331         name = efx_siena_mcdi_phy_test_name(efx, i);
0332         if (name == NULL)
0333             break;
0334 
0335         efx_fill_test(n++, strings, data, &tests->phy_ext[i], "phy", 0, name, NULL);
0336     }
0337 
0338     /* Loopback tests */
0339     for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
0340         if (!(efx->loopback_modes & (1 << mode)))
0341             continue;
0342         n = efx_fill_loopback_test(efx,
0343                        &tests->loopback[mode], mode, n,
0344                        strings, data);
0345     }
0346 
0347     return n;
0348 }
0349 
0350 void efx_siena_ethtool_self_test(struct net_device *net_dev,
0351                  struct ethtool_test *test, u64 *data)
0352 {
0353     struct efx_nic *efx = netdev_priv(net_dev);
0354     struct efx_self_tests *efx_tests;
0355     bool already_up;
0356     int rc = -ENOMEM;
0357 
0358     efx_tests = kzalloc(sizeof(*efx_tests), GFP_KERNEL);
0359     if (!efx_tests)
0360         goto fail;
0361 
0362     if (efx->state != STATE_READY) {
0363         rc = -EBUSY;
0364         goto out;
0365     }
0366 
0367     netif_info(efx, drv, efx->net_dev, "starting %sline testing\n",
0368            (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
0369 
0370     /* We need rx buffers and interrupts. */
0371     already_up = (efx->net_dev->flags & IFF_UP);
0372     if (!already_up) {
0373         rc = dev_open(efx->net_dev, NULL);
0374         if (rc) {
0375             netif_err(efx, drv, efx->net_dev,
0376                   "failed opening device.\n");
0377             goto out;
0378         }
0379     }
0380 
0381     rc = efx_siena_selftest(efx, efx_tests, test->flags);
0382 
0383     if (!already_up)
0384         dev_close(efx->net_dev);
0385 
0386     netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n",
0387            rc == 0 ? "passed" : "failed",
0388            (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
0389 
0390 out:
0391     efx_ethtool_fill_self_tests(efx, efx_tests, NULL, data);
0392     kfree(efx_tests);
0393 fail:
0394     if (rc)
0395         test->flags |= ETH_TEST_FL_FAILED;
0396 }
0397 
0398 static size_t efx_describe_per_queue_stats(struct efx_nic *efx, u8 *strings)
0399 {
0400     size_t n_stats = 0;
0401     struct efx_channel *channel;
0402 
0403     efx_for_each_channel(channel, efx) {
0404         if (efx_channel_has_tx_queues(channel)) {
0405             n_stats++;
0406             if (strings != NULL) {
0407                 snprintf(strings, ETH_GSTRING_LEN,
0408                      "tx-%u.tx_packets",
0409                      channel->tx_queue[0].queue /
0410                      EFX_MAX_TXQ_PER_CHANNEL);
0411 
0412                 strings += ETH_GSTRING_LEN;
0413             }
0414         }
0415     }
0416     efx_for_each_channel(channel, efx) {
0417         if (efx_channel_has_rx_queue(channel)) {
0418             n_stats++;
0419             if (strings != NULL) {
0420                 snprintf(strings, ETH_GSTRING_LEN,
0421                      "rx-%d.rx_packets", channel->channel);
0422                 strings += ETH_GSTRING_LEN;
0423             }
0424         }
0425     }
0426     if (efx->xdp_tx_queue_count && efx->xdp_tx_queues) {
0427         unsigned short xdp;
0428 
0429         for (xdp = 0; xdp < efx->xdp_tx_queue_count; xdp++) {
0430             n_stats++;
0431             if (strings) {
0432                 snprintf(strings, ETH_GSTRING_LEN,
0433                      "tx-xdp-cpu-%hu.tx_packets", xdp);
0434                 strings += ETH_GSTRING_LEN;
0435             }
0436         }
0437     }
0438 
0439     return n_stats;
0440 }
0441 
0442 int efx_siena_ethtool_get_sset_count(struct net_device *net_dev, int string_set)
0443 {
0444     struct efx_nic *efx = netdev_priv(net_dev);
0445 
0446     switch (string_set) {
0447     case ETH_SS_STATS:
0448         return efx->type->describe_stats(efx, NULL) +
0449                EFX_ETHTOOL_SW_STAT_COUNT +
0450                efx_describe_per_queue_stats(efx, NULL) +
0451                efx_siena_ptp_describe_stats(efx, NULL);
0452     case ETH_SS_TEST:
0453         return efx_ethtool_fill_self_tests(efx, NULL, NULL, NULL);
0454     default:
0455         return -EINVAL;
0456     }
0457 }
0458 
0459 void efx_siena_ethtool_get_strings(struct net_device *net_dev,
0460                    u32 string_set, u8 *strings)
0461 {
0462     struct efx_nic *efx = netdev_priv(net_dev);
0463     int i;
0464 
0465     switch (string_set) {
0466     case ETH_SS_STATS:
0467         strings += (efx->type->describe_stats(efx, strings) *
0468                 ETH_GSTRING_LEN);
0469         for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++)
0470             strlcpy(strings + i * ETH_GSTRING_LEN,
0471                 efx_sw_stat_desc[i].name, ETH_GSTRING_LEN);
0472         strings += EFX_ETHTOOL_SW_STAT_COUNT * ETH_GSTRING_LEN;
0473         strings += (efx_describe_per_queue_stats(efx, strings) *
0474                 ETH_GSTRING_LEN);
0475         efx_siena_ptp_describe_stats(efx, strings);
0476         break;
0477     case ETH_SS_TEST:
0478         efx_ethtool_fill_self_tests(efx, NULL, strings, NULL);
0479         break;
0480     default:
0481         /* No other string sets */
0482         break;
0483     }
0484 }
0485 
0486 void efx_siena_ethtool_get_stats(struct net_device *net_dev,
0487                  struct ethtool_stats *stats,
0488                  u64 *data)
0489 {
0490     struct efx_nic *efx = netdev_priv(net_dev);
0491     const struct efx_sw_stat_desc *stat;
0492     struct efx_channel *channel;
0493     struct efx_tx_queue *tx_queue;
0494     struct efx_rx_queue *rx_queue;
0495     int i;
0496 
0497     spin_lock_bh(&efx->stats_lock);
0498 
0499     /* Get NIC statistics */
0500     data += efx->type->update_stats(efx, data, NULL);
0501 
0502     /* Get software statistics */
0503     for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) {
0504         stat = &efx_sw_stat_desc[i];
0505         switch (stat->source) {
0506         case EFX_ETHTOOL_STAT_SOURCE_nic:
0507             data[i] = stat->get_stat((void *)efx + stat->offset);
0508             break;
0509         case EFX_ETHTOOL_STAT_SOURCE_channel:
0510             data[i] = 0;
0511             efx_for_each_channel(channel, efx)
0512                 data[i] += stat->get_stat((void *)channel +
0513                               stat->offset);
0514             break;
0515         case EFX_ETHTOOL_STAT_SOURCE_tx_queue:
0516             data[i] = 0;
0517             efx_for_each_channel(channel, efx) {
0518                 efx_for_each_channel_tx_queue(tx_queue, channel)
0519                     data[i] +=
0520                         stat->get_stat((void *)tx_queue
0521                                    + stat->offset);
0522             }
0523             break;
0524         }
0525     }
0526     data += EFX_ETHTOOL_SW_STAT_COUNT;
0527 
0528     spin_unlock_bh(&efx->stats_lock);
0529 
0530     efx_for_each_channel(channel, efx) {
0531         if (efx_channel_has_tx_queues(channel)) {
0532             *data = 0;
0533             efx_for_each_channel_tx_queue(tx_queue, channel) {
0534                 *data += tx_queue->tx_packets;
0535             }
0536             data++;
0537         }
0538     }
0539     efx_for_each_channel(channel, efx) {
0540         if (efx_channel_has_rx_queue(channel)) {
0541             *data = 0;
0542             efx_for_each_channel_rx_queue(rx_queue, channel) {
0543                 *data += rx_queue->rx_packets;
0544             }
0545             data++;
0546         }
0547     }
0548     if (efx->xdp_tx_queue_count && efx->xdp_tx_queues) {
0549         int xdp;
0550 
0551         for (xdp = 0; xdp < efx->xdp_tx_queue_count; xdp++) {
0552             data[0] = efx->xdp_tx_queues[xdp]->tx_packets;
0553             data++;
0554         }
0555     }
0556 
0557     efx_siena_ptp_update_stats(efx, data);
0558 }
0559 
0560 /* This must be called with rtnl_lock held. */
0561 int efx_siena_ethtool_get_link_ksettings(struct net_device *net_dev,
0562                      struct ethtool_link_ksettings *cmd)
0563 {
0564     struct efx_nic *efx = netdev_priv(net_dev);
0565     struct efx_link_state *link_state = &efx->link_state;
0566 
0567     mutex_lock(&efx->mac_lock);
0568     efx_siena_mcdi_phy_get_link_ksettings(efx, cmd);
0569     mutex_unlock(&efx->mac_lock);
0570 
0571     /* Both MACs support pause frames (bidirectional and respond-only) */
0572     ethtool_link_ksettings_add_link_mode(cmd, supported, Pause);
0573     ethtool_link_ksettings_add_link_mode(cmd, supported, Asym_Pause);
0574 
0575     if (LOOPBACK_INTERNAL(efx)) {
0576         cmd->base.speed = link_state->speed;
0577         cmd->base.duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF;
0578     }
0579 
0580     return 0;
0581 }
0582 
0583 /* This must be called with rtnl_lock held. */
0584 int
0585 efx_siena_ethtool_set_link_ksettings(struct net_device *net_dev,
0586                      const struct ethtool_link_ksettings *cmd)
0587 {
0588     struct efx_nic *efx = netdev_priv(net_dev);
0589     int rc;
0590 
0591     /* GMAC does not support 1000Mbps HD */
0592     if ((cmd->base.speed == SPEED_1000) &&
0593         (cmd->base.duplex != DUPLEX_FULL)) {
0594         netif_dbg(efx, drv, efx->net_dev,
0595               "rejecting unsupported 1000Mbps HD setting\n");
0596         return -EINVAL;
0597     }
0598 
0599     mutex_lock(&efx->mac_lock);
0600     rc = efx_siena_mcdi_phy_set_link_ksettings(efx, cmd);
0601     mutex_unlock(&efx->mac_lock);
0602     return rc;
0603 }
0604 
0605 int efx_siena_ethtool_get_fecparam(struct net_device *net_dev,
0606                    struct ethtool_fecparam *fecparam)
0607 {
0608     struct efx_nic *efx = netdev_priv(net_dev);
0609     int rc;
0610 
0611     mutex_lock(&efx->mac_lock);
0612     rc = efx_siena_mcdi_phy_get_fecparam(efx, fecparam);
0613     mutex_unlock(&efx->mac_lock);
0614 
0615     return rc;
0616 }
0617 
0618 int efx_siena_ethtool_set_fecparam(struct net_device *net_dev,
0619                    struct ethtool_fecparam *fecparam)
0620 {
0621     struct efx_nic *efx = netdev_priv(net_dev);
0622     int rc;
0623 
0624     mutex_lock(&efx->mac_lock);
0625     rc = efx_siena_mcdi_phy_set_fecparam(efx, fecparam);
0626     mutex_unlock(&efx->mac_lock);
0627 
0628     return rc;
0629 }
0630 
0631 /* MAC address mask including only I/G bit */
0632 static const u8 mac_addr_ig_mask[ETH_ALEN] __aligned(2) = {0x01, 0, 0, 0, 0, 0};
0633 
0634 #define IP4_ADDR_FULL_MASK  ((__force __be32)~0)
0635 #define IP_PROTO_FULL_MASK  0xFF
0636 #define PORT_FULL_MASK      ((__force __be16)~0)
0637 #define ETHER_TYPE_FULL_MASK    ((__force __be16)~0)
0638 
0639 static inline void ip6_fill_mask(__be32 *mask)
0640 {
0641     mask[0] = mask[1] = mask[2] = mask[3] = ~(__be32)0;
0642 }
0643 
0644 static int efx_ethtool_get_class_rule(struct efx_nic *efx,
0645                       struct ethtool_rx_flow_spec *rule,
0646                       u32 *rss_context)
0647 {
0648     struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
0649     struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
0650     struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
0651     struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
0652     struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
0653     struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
0654     struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
0655     struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
0656     struct ethhdr *mac_entry = &rule->h_u.ether_spec;
0657     struct ethhdr *mac_mask = &rule->m_u.ether_spec;
0658     struct efx_filter_spec spec;
0659     int rc;
0660 
0661     rc = efx_filter_get_filter_safe(efx, EFX_FILTER_PRI_MANUAL,
0662                     rule->location, &spec);
0663     if (rc)
0664         return rc;
0665 
0666     if (spec.dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP)
0667         rule->ring_cookie = RX_CLS_FLOW_DISC;
0668     else
0669         rule->ring_cookie = spec.dmaq_id;
0670 
0671     if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) &&
0672         spec.ether_type == htons(ETH_P_IP) &&
0673         (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) &&
0674         (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
0675         !(spec.match_flags &
0676           ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
0677         EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
0678         EFX_FILTER_MATCH_IP_PROTO |
0679         EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) {
0680         rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
0681                    TCP_V4_FLOW : UDP_V4_FLOW);
0682         if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
0683             ip_entry->ip4dst = spec.loc_host[0];
0684             ip_mask->ip4dst = IP4_ADDR_FULL_MASK;
0685         }
0686         if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
0687             ip_entry->ip4src = spec.rem_host[0];
0688             ip_mask->ip4src = IP4_ADDR_FULL_MASK;
0689         }
0690         if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) {
0691             ip_entry->pdst = spec.loc_port;
0692             ip_mask->pdst = PORT_FULL_MASK;
0693         }
0694         if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) {
0695             ip_entry->psrc = spec.rem_port;
0696             ip_mask->psrc = PORT_FULL_MASK;
0697         }
0698     } else if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) &&
0699         spec.ether_type == htons(ETH_P_IPV6) &&
0700         (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) &&
0701         (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
0702         !(spec.match_flags &
0703           ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
0704         EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
0705         EFX_FILTER_MATCH_IP_PROTO |
0706         EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) {
0707         rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
0708                    TCP_V6_FLOW : UDP_V6_FLOW);
0709         if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
0710             memcpy(ip6_entry->ip6dst, spec.loc_host,
0711                    sizeof(ip6_entry->ip6dst));
0712             ip6_fill_mask(ip6_mask->ip6dst);
0713         }
0714         if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
0715             memcpy(ip6_entry->ip6src, spec.rem_host,
0716                    sizeof(ip6_entry->ip6src));
0717             ip6_fill_mask(ip6_mask->ip6src);
0718         }
0719         if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) {
0720             ip6_entry->pdst = spec.loc_port;
0721             ip6_mask->pdst = PORT_FULL_MASK;
0722         }
0723         if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) {
0724             ip6_entry->psrc = spec.rem_port;
0725             ip6_mask->psrc = PORT_FULL_MASK;
0726         }
0727     } else if (!(spec.match_flags &
0728              ~(EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG |
0729                EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_ETHER_TYPE |
0730                EFX_FILTER_MATCH_OUTER_VID))) {
0731         rule->flow_type = ETHER_FLOW;
0732         if (spec.match_flags &
0733             (EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG)) {
0734             ether_addr_copy(mac_entry->h_dest, spec.loc_mac);
0735             if (spec.match_flags & EFX_FILTER_MATCH_LOC_MAC)
0736                 eth_broadcast_addr(mac_mask->h_dest);
0737             else
0738                 ether_addr_copy(mac_mask->h_dest,
0739                         mac_addr_ig_mask);
0740         }
0741         if (spec.match_flags & EFX_FILTER_MATCH_REM_MAC) {
0742             ether_addr_copy(mac_entry->h_source, spec.rem_mac);
0743             eth_broadcast_addr(mac_mask->h_source);
0744         }
0745         if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) {
0746             mac_entry->h_proto = spec.ether_type;
0747             mac_mask->h_proto = ETHER_TYPE_FULL_MASK;
0748         }
0749     } else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
0750            spec.ether_type == htons(ETH_P_IP) &&
0751            !(spec.match_flags &
0752              ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
0753                EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
0754                EFX_FILTER_MATCH_IP_PROTO))) {
0755         rule->flow_type = IPV4_USER_FLOW;
0756         uip_entry->ip_ver = ETH_RX_NFC_IP4;
0757         if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) {
0758             uip_mask->proto = IP_PROTO_FULL_MASK;
0759             uip_entry->proto = spec.ip_proto;
0760         }
0761         if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
0762             uip_entry->ip4dst = spec.loc_host[0];
0763             uip_mask->ip4dst = IP4_ADDR_FULL_MASK;
0764         }
0765         if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
0766             uip_entry->ip4src = spec.rem_host[0];
0767             uip_mask->ip4src = IP4_ADDR_FULL_MASK;
0768         }
0769     } else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
0770            spec.ether_type == htons(ETH_P_IPV6) &&
0771            !(spec.match_flags &
0772              ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
0773                EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
0774                EFX_FILTER_MATCH_IP_PROTO))) {
0775         rule->flow_type = IPV6_USER_FLOW;
0776         if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) {
0777             uip6_mask->l4_proto = IP_PROTO_FULL_MASK;
0778             uip6_entry->l4_proto = spec.ip_proto;
0779         }
0780         if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
0781             memcpy(uip6_entry->ip6dst, spec.loc_host,
0782                    sizeof(uip6_entry->ip6dst));
0783             ip6_fill_mask(uip6_mask->ip6dst);
0784         }
0785         if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
0786             memcpy(uip6_entry->ip6src, spec.rem_host,
0787                    sizeof(uip6_entry->ip6src));
0788             ip6_fill_mask(uip6_mask->ip6src);
0789         }
0790     } else {
0791         /* The above should handle all filters that we insert */
0792         WARN_ON(1);
0793         return -EINVAL;
0794     }
0795 
0796     if (spec.match_flags & EFX_FILTER_MATCH_OUTER_VID) {
0797         rule->flow_type |= FLOW_EXT;
0798         rule->h_ext.vlan_tci = spec.outer_vid;
0799         rule->m_ext.vlan_tci = htons(0xfff);
0800     }
0801 
0802     if (spec.flags & EFX_FILTER_FLAG_RX_RSS) {
0803         rule->flow_type |= FLOW_RSS;
0804         *rss_context = spec.rss_context;
0805     }
0806 
0807     return rc;
0808 }
0809 
0810 int efx_siena_ethtool_get_rxnfc(struct net_device *net_dev,
0811                 struct ethtool_rxnfc *info, u32 *rule_locs)
0812 {
0813     struct efx_nic *efx = netdev_priv(net_dev);
0814     u32 rss_context = 0;
0815     s32 rc = 0;
0816 
0817     switch (info->cmd) {
0818     case ETHTOOL_GRXRINGS:
0819         info->data = efx->n_rx_channels;
0820         return 0;
0821 
0822     case ETHTOOL_GRXFH: {
0823         struct efx_rss_context *ctx = &efx->rss_context;
0824         __u64 data;
0825 
0826         mutex_lock(&efx->rss_lock);
0827         if (info->flow_type & FLOW_RSS && info->rss_context) {
0828             ctx = efx_siena_find_rss_context_entry(efx,
0829                             info->rss_context);
0830             if (!ctx) {
0831                 rc = -ENOENT;
0832                 goto out_unlock;
0833             }
0834         }
0835 
0836         data = 0;
0837         if (!efx_rss_active(ctx)) /* No RSS */
0838             goto out_setdata_unlock;
0839 
0840         switch (info->flow_type & ~FLOW_RSS) {
0841         case UDP_V4_FLOW:
0842         case UDP_V6_FLOW:
0843             if (ctx->rx_hash_udp_4tuple)
0844                 data = (RXH_L4_B_0_1 | RXH_L4_B_2_3 |
0845                     RXH_IP_SRC | RXH_IP_DST);
0846             else
0847                 data = RXH_IP_SRC | RXH_IP_DST;
0848             break;
0849         case TCP_V4_FLOW:
0850         case TCP_V6_FLOW:
0851             data = (RXH_L4_B_0_1 | RXH_L4_B_2_3 |
0852                 RXH_IP_SRC | RXH_IP_DST);
0853             break;
0854         case SCTP_V4_FLOW:
0855         case SCTP_V6_FLOW:
0856         case AH_ESP_V4_FLOW:
0857         case AH_ESP_V6_FLOW:
0858         case IPV4_FLOW:
0859         case IPV6_FLOW:
0860             data = RXH_IP_SRC | RXH_IP_DST;
0861             break;
0862         default:
0863             break;
0864         }
0865 out_setdata_unlock:
0866         info->data = data;
0867 out_unlock:
0868         mutex_unlock(&efx->rss_lock);
0869         return rc;
0870     }
0871 
0872     case ETHTOOL_GRXCLSRLCNT:
0873         info->data = efx_filter_get_rx_id_limit(efx);
0874         if (info->data == 0)
0875             return -EOPNOTSUPP;
0876         info->data |= RX_CLS_LOC_SPECIAL;
0877         info->rule_cnt =
0878             efx_filter_count_rx_used(efx, EFX_FILTER_PRI_MANUAL);
0879         return 0;
0880 
0881     case ETHTOOL_GRXCLSRULE:
0882         if (efx_filter_get_rx_id_limit(efx) == 0)
0883             return -EOPNOTSUPP;
0884         rc = efx_ethtool_get_class_rule(efx, &info->fs, &rss_context);
0885         if (rc < 0)
0886             return rc;
0887         if (info->fs.flow_type & FLOW_RSS)
0888             info->rss_context = rss_context;
0889         return 0;
0890 
0891     case ETHTOOL_GRXCLSRLALL:
0892         info->data = efx_filter_get_rx_id_limit(efx);
0893         if (info->data == 0)
0894             return -EOPNOTSUPP;
0895         rc = efx_filter_get_rx_ids(efx, EFX_FILTER_PRI_MANUAL,
0896                        rule_locs, info->rule_cnt);
0897         if (rc < 0)
0898             return rc;
0899         info->rule_cnt = rc;
0900         return 0;
0901 
0902     default:
0903         return -EOPNOTSUPP;
0904     }
0905 }
0906 
0907 static inline bool ip6_mask_is_full(__be32 mask[4])
0908 {
0909     return !~(mask[0] & mask[1] & mask[2] & mask[3]);
0910 }
0911 
0912 static inline bool ip6_mask_is_empty(__be32 mask[4])
0913 {
0914     return !(mask[0] | mask[1] | mask[2] | mask[3]);
0915 }
0916 
0917 static int efx_ethtool_set_class_rule(struct efx_nic *efx,
0918                       struct ethtool_rx_flow_spec *rule,
0919                       u32 rss_context)
0920 {
0921     struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
0922     struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
0923     struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
0924     struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
0925     struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
0926     struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
0927     struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
0928     struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
0929     u32 flow_type = rule->flow_type & ~(FLOW_EXT | FLOW_RSS);
0930     struct ethhdr *mac_entry = &rule->h_u.ether_spec;
0931     struct ethhdr *mac_mask = &rule->m_u.ether_spec;
0932     enum efx_filter_flags flags = 0;
0933     struct efx_filter_spec spec;
0934     int rc;
0935 
0936     /* Check that user wants us to choose the location */
0937     if (rule->location != RX_CLS_LOC_ANY)
0938         return -EINVAL;
0939 
0940     /* Range-check ring_cookie */
0941     if (rule->ring_cookie >= efx->n_rx_channels &&
0942         rule->ring_cookie != RX_CLS_FLOW_DISC)
0943         return -EINVAL;
0944 
0945     /* Check for unsupported extensions */
0946     if ((rule->flow_type & FLOW_EXT) &&
0947         (rule->m_ext.vlan_etype || rule->m_ext.data[0] ||
0948          rule->m_ext.data[1]))
0949         return -EINVAL;
0950 
0951     if (efx->rx_scatter)
0952         flags |= EFX_FILTER_FLAG_RX_SCATTER;
0953     if (rule->flow_type & FLOW_RSS)
0954         flags |= EFX_FILTER_FLAG_RX_RSS;
0955 
0956     efx_filter_init_rx(&spec, EFX_FILTER_PRI_MANUAL, flags,
0957                (rule->ring_cookie == RX_CLS_FLOW_DISC) ?
0958                EFX_FILTER_RX_DMAQ_ID_DROP : rule->ring_cookie);
0959 
0960     if (rule->flow_type & FLOW_RSS)
0961         spec.rss_context = rss_context;
0962 
0963     switch (flow_type) {
0964     case TCP_V4_FLOW:
0965     case UDP_V4_FLOW:
0966         spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
0967                     EFX_FILTER_MATCH_IP_PROTO);
0968         spec.ether_type = htons(ETH_P_IP);
0969         spec.ip_proto = flow_type == TCP_V4_FLOW ? IPPROTO_TCP
0970                              : IPPROTO_UDP;
0971         if (ip_mask->ip4dst) {
0972             if (ip_mask->ip4dst != IP4_ADDR_FULL_MASK)
0973                 return -EINVAL;
0974             spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
0975             spec.loc_host[0] = ip_entry->ip4dst;
0976         }
0977         if (ip_mask->ip4src) {
0978             if (ip_mask->ip4src != IP4_ADDR_FULL_MASK)
0979                 return -EINVAL;
0980             spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
0981             spec.rem_host[0] = ip_entry->ip4src;
0982         }
0983         if (ip_mask->pdst) {
0984             if (ip_mask->pdst != PORT_FULL_MASK)
0985                 return -EINVAL;
0986             spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
0987             spec.loc_port = ip_entry->pdst;
0988         }
0989         if (ip_mask->psrc) {
0990             if (ip_mask->psrc != PORT_FULL_MASK)
0991                 return -EINVAL;
0992             spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
0993             spec.rem_port = ip_entry->psrc;
0994         }
0995         if (ip_mask->tos)
0996             return -EINVAL;
0997         break;
0998 
0999     case TCP_V6_FLOW:
1000     case UDP_V6_FLOW:
1001         spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
1002                     EFX_FILTER_MATCH_IP_PROTO);
1003         spec.ether_type = htons(ETH_P_IPV6);
1004         spec.ip_proto = flow_type == TCP_V6_FLOW ? IPPROTO_TCP
1005                              : IPPROTO_UDP;
1006         if (!ip6_mask_is_empty(ip6_mask->ip6dst)) {
1007             if (!ip6_mask_is_full(ip6_mask->ip6dst))
1008                 return -EINVAL;
1009             spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1010             memcpy(spec.loc_host, ip6_entry->ip6dst, sizeof(spec.loc_host));
1011         }
1012         if (!ip6_mask_is_empty(ip6_mask->ip6src)) {
1013             if (!ip6_mask_is_full(ip6_mask->ip6src))
1014                 return -EINVAL;
1015             spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1016             memcpy(spec.rem_host, ip6_entry->ip6src, sizeof(spec.rem_host));
1017         }
1018         if (ip6_mask->pdst) {
1019             if (ip6_mask->pdst != PORT_FULL_MASK)
1020                 return -EINVAL;
1021             spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
1022             spec.loc_port = ip6_entry->pdst;
1023         }
1024         if (ip6_mask->psrc) {
1025             if (ip6_mask->psrc != PORT_FULL_MASK)
1026                 return -EINVAL;
1027             spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
1028             spec.rem_port = ip6_entry->psrc;
1029         }
1030         if (ip6_mask->tclass)
1031             return -EINVAL;
1032         break;
1033 
1034     case IPV4_USER_FLOW:
1035         if (uip_mask->l4_4_bytes || uip_mask->tos || uip_mask->ip_ver ||
1036             uip_entry->ip_ver != ETH_RX_NFC_IP4)
1037             return -EINVAL;
1038         spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE;
1039         spec.ether_type = htons(ETH_P_IP);
1040         if (uip_mask->ip4dst) {
1041             if (uip_mask->ip4dst != IP4_ADDR_FULL_MASK)
1042                 return -EINVAL;
1043             spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1044             spec.loc_host[0] = uip_entry->ip4dst;
1045         }
1046         if (uip_mask->ip4src) {
1047             if (uip_mask->ip4src != IP4_ADDR_FULL_MASK)
1048                 return -EINVAL;
1049             spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1050             spec.rem_host[0] = uip_entry->ip4src;
1051         }
1052         if (uip_mask->proto) {
1053             if (uip_mask->proto != IP_PROTO_FULL_MASK)
1054                 return -EINVAL;
1055             spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO;
1056             spec.ip_proto = uip_entry->proto;
1057         }
1058         break;
1059 
1060     case IPV6_USER_FLOW:
1061         if (uip6_mask->l4_4_bytes || uip6_mask->tclass)
1062             return -EINVAL;
1063         spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE;
1064         spec.ether_type = htons(ETH_P_IPV6);
1065         if (!ip6_mask_is_empty(uip6_mask->ip6dst)) {
1066             if (!ip6_mask_is_full(uip6_mask->ip6dst))
1067                 return -EINVAL;
1068             spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1069             memcpy(spec.loc_host, uip6_entry->ip6dst, sizeof(spec.loc_host));
1070         }
1071         if (!ip6_mask_is_empty(uip6_mask->ip6src)) {
1072             if (!ip6_mask_is_full(uip6_mask->ip6src))
1073                 return -EINVAL;
1074             spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1075             memcpy(spec.rem_host, uip6_entry->ip6src, sizeof(spec.rem_host));
1076         }
1077         if (uip6_mask->l4_proto) {
1078             if (uip6_mask->l4_proto != IP_PROTO_FULL_MASK)
1079                 return -EINVAL;
1080             spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO;
1081             spec.ip_proto = uip6_entry->l4_proto;
1082         }
1083         break;
1084 
1085     case ETHER_FLOW:
1086         if (!is_zero_ether_addr(mac_mask->h_dest)) {
1087             if (ether_addr_equal(mac_mask->h_dest,
1088                          mac_addr_ig_mask))
1089                 spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC_IG;
1090             else if (is_broadcast_ether_addr(mac_mask->h_dest))
1091                 spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC;
1092             else
1093                 return -EINVAL;
1094             ether_addr_copy(spec.loc_mac, mac_entry->h_dest);
1095         }
1096         if (!is_zero_ether_addr(mac_mask->h_source)) {
1097             if (!is_broadcast_ether_addr(mac_mask->h_source))
1098                 return -EINVAL;
1099             spec.match_flags |= EFX_FILTER_MATCH_REM_MAC;
1100             ether_addr_copy(spec.rem_mac, mac_entry->h_source);
1101         }
1102         if (mac_mask->h_proto) {
1103             if (mac_mask->h_proto != ETHER_TYPE_FULL_MASK)
1104                 return -EINVAL;
1105             spec.match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
1106             spec.ether_type = mac_entry->h_proto;
1107         }
1108         break;
1109 
1110     default:
1111         return -EINVAL;
1112     }
1113 
1114     if ((rule->flow_type & FLOW_EXT) && rule->m_ext.vlan_tci) {
1115         if (rule->m_ext.vlan_tci != htons(0xfff))
1116             return -EINVAL;
1117         spec.match_flags |= EFX_FILTER_MATCH_OUTER_VID;
1118         spec.outer_vid = rule->h_ext.vlan_tci;
1119     }
1120 
1121     rc = efx_filter_insert_filter(efx, &spec, true);
1122     if (rc < 0)
1123         return rc;
1124 
1125     rule->location = rc;
1126     return 0;
1127 }
1128 
1129 int efx_siena_ethtool_set_rxnfc(struct net_device *net_dev,
1130                 struct ethtool_rxnfc *info)
1131 {
1132     struct efx_nic *efx = netdev_priv(net_dev);
1133 
1134     if (efx_filter_get_rx_id_limit(efx) == 0)
1135         return -EOPNOTSUPP;
1136 
1137     switch (info->cmd) {
1138     case ETHTOOL_SRXCLSRLINS:
1139         return efx_ethtool_set_class_rule(efx, &info->fs,
1140                           info->rss_context);
1141 
1142     case ETHTOOL_SRXCLSRLDEL:
1143         return efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_MANUAL,
1144                          info->fs.location);
1145 
1146     default:
1147         return -EOPNOTSUPP;
1148     }
1149 }
1150 
1151 u32 efx_siena_ethtool_get_rxfh_indir_size(struct net_device *net_dev)
1152 {
1153     struct efx_nic *efx = netdev_priv(net_dev);
1154 
1155     if (efx->n_rx_channels == 1)
1156         return 0;
1157     return ARRAY_SIZE(efx->rss_context.rx_indir_table);
1158 }
1159 
1160 u32 efx_siena_ethtool_get_rxfh_key_size(struct net_device *net_dev)
1161 {
1162     struct efx_nic *efx = netdev_priv(net_dev);
1163 
1164     return efx->type->rx_hash_key_size;
1165 }
1166 
1167 int efx_siena_ethtool_get_rxfh(struct net_device *net_dev, u32 *indir, u8 *key,
1168                    u8 *hfunc)
1169 {
1170     struct efx_nic *efx = netdev_priv(net_dev);
1171     int rc;
1172 
1173     rc = efx->type->rx_pull_rss_config(efx);
1174     if (rc)
1175         return rc;
1176 
1177     if (hfunc)
1178         *hfunc = ETH_RSS_HASH_TOP;
1179     if (indir)
1180         memcpy(indir, efx->rss_context.rx_indir_table,
1181                sizeof(efx->rss_context.rx_indir_table));
1182     if (key)
1183         memcpy(key, efx->rss_context.rx_hash_key,
1184                efx->type->rx_hash_key_size);
1185     return 0;
1186 }
1187 
1188 int efx_siena_ethtool_set_rxfh(struct net_device *net_dev, const u32 *indir,
1189                    const u8 *key, const u8 hfunc)
1190 {
1191     struct efx_nic *efx = netdev_priv(net_dev);
1192 
1193     /* Hash function is Toeplitz, cannot be changed */
1194     if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1195         return -EOPNOTSUPP;
1196     if (!indir && !key)
1197         return 0;
1198 
1199     if (!key)
1200         key = efx->rss_context.rx_hash_key;
1201     if (!indir)
1202         indir = efx->rss_context.rx_indir_table;
1203 
1204     return efx->type->rx_push_rss_config(efx, true, indir, key);
1205 }
1206 
1207 int efx_siena_ethtool_get_rxfh_context(struct net_device *net_dev, u32 *indir,
1208                        u8 *key, u8 *hfunc, u32 rss_context)
1209 {
1210     struct efx_nic *efx = netdev_priv(net_dev);
1211     struct efx_rss_context *ctx;
1212     int rc = 0;
1213 
1214     if (!efx->type->rx_pull_rss_context_config)
1215         return -EOPNOTSUPP;
1216 
1217     mutex_lock(&efx->rss_lock);
1218     ctx = efx_siena_find_rss_context_entry(efx, rss_context);
1219     if (!ctx) {
1220         rc = -ENOENT;
1221         goto out_unlock;
1222     }
1223     rc = efx->type->rx_pull_rss_context_config(efx, ctx);
1224     if (rc)
1225         goto out_unlock;
1226 
1227     if (hfunc)
1228         *hfunc = ETH_RSS_HASH_TOP;
1229     if (indir)
1230         memcpy(indir, ctx->rx_indir_table, sizeof(ctx->rx_indir_table));
1231     if (key)
1232         memcpy(key, ctx->rx_hash_key, efx->type->rx_hash_key_size);
1233 out_unlock:
1234     mutex_unlock(&efx->rss_lock);
1235     return rc;
1236 }
1237 
1238 int efx_siena_ethtool_set_rxfh_context(struct net_device *net_dev,
1239                        const u32 *indir, const u8 *key,
1240                        const u8 hfunc, u32 *rss_context,
1241                        bool delete)
1242 {
1243     struct efx_nic *efx = netdev_priv(net_dev);
1244     struct efx_rss_context *ctx;
1245     bool allocated = false;
1246     int rc;
1247 
1248     if (!efx->type->rx_push_rss_context_config)
1249         return -EOPNOTSUPP;
1250     /* Hash function is Toeplitz, cannot be changed */
1251     if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1252         return -EOPNOTSUPP;
1253 
1254     mutex_lock(&efx->rss_lock);
1255 
1256     if (*rss_context == ETH_RXFH_CONTEXT_ALLOC) {
1257         if (delete) {
1258             /* alloc + delete == Nothing to do */
1259             rc = -EINVAL;
1260             goto out_unlock;
1261         }
1262         ctx = efx_siena_alloc_rss_context_entry(efx);
1263         if (!ctx) {
1264             rc = -ENOMEM;
1265             goto out_unlock;
1266         }
1267         ctx->context_id = EFX_MCDI_RSS_CONTEXT_INVALID;
1268         /* Initialise indir table and key to defaults */
1269         efx_siena_set_default_rx_indir_table(efx, ctx);
1270         netdev_rss_key_fill(ctx->rx_hash_key, sizeof(ctx->rx_hash_key));
1271         allocated = true;
1272     } else {
1273         ctx = efx_siena_find_rss_context_entry(efx, *rss_context);
1274         if (!ctx) {
1275             rc = -ENOENT;
1276             goto out_unlock;
1277         }
1278     }
1279 
1280     if (delete) {
1281         /* delete this context */
1282         rc = efx->type->rx_push_rss_context_config(efx, ctx, NULL, NULL);
1283         if (!rc)
1284             efx_siena_free_rss_context_entry(ctx);
1285         goto out_unlock;
1286     }
1287 
1288     if (!key)
1289         key = ctx->rx_hash_key;
1290     if (!indir)
1291         indir = ctx->rx_indir_table;
1292 
1293     rc = efx->type->rx_push_rss_context_config(efx, ctx, indir, key);
1294     if (rc && allocated)
1295         efx_siena_free_rss_context_entry(ctx);
1296     else
1297         *rss_context = ctx->user_id;
1298 out_unlock:
1299     mutex_unlock(&efx->rss_lock);
1300     return rc;
1301 }
1302 
1303 int efx_siena_ethtool_reset(struct net_device *net_dev, u32 *flags)
1304 {
1305     struct efx_nic *efx = netdev_priv(net_dev);
1306     int rc;
1307 
1308     rc = efx->type->map_reset_flags(flags);
1309     if (rc < 0)
1310         return rc;
1311 
1312     return efx_siena_reset(efx, rc);
1313 }
1314 
1315 int efx_siena_ethtool_get_module_eeprom(struct net_device *net_dev,
1316                     struct ethtool_eeprom *ee,
1317                     u8 *data)
1318 {
1319     struct efx_nic *efx = netdev_priv(net_dev);
1320     int ret;
1321 
1322     mutex_lock(&efx->mac_lock);
1323     ret = efx_siena_mcdi_phy_get_module_eeprom(efx, ee, data);
1324     mutex_unlock(&efx->mac_lock);
1325 
1326     return ret;
1327 }
1328 
1329 int efx_siena_ethtool_get_module_info(struct net_device *net_dev,
1330                       struct ethtool_modinfo *modinfo)
1331 {
1332     struct efx_nic *efx = netdev_priv(net_dev);
1333     int ret;
1334 
1335     mutex_lock(&efx->mac_lock);
1336     ret = efx_siena_mcdi_phy_get_module_info(efx, modinfo);
1337     mutex_unlock(&efx->mac_lock);
1338 
1339     return ret;
1340 }