xref: /linux/drivers/net/ethernet/sfc/siena/ethtool_common.c (revision 95e96f7788d0ccea7e70322ce75b873d43124dc9)
16e173d3bSMartin Habets // SPDX-License-Identifier: GPL-2.0-only
26e173d3bSMartin Habets /****************************************************************************
36e173d3bSMartin Habets  * Driver for Solarflare network controllers and boards
46e173d3bSMartin Habets  * Copyright 2019 Solarflare Communications Inc.
56e173d3bSMartin Habets  *
66e173d3bSMartin Habets  * This program is free software; you can redistribute it and/or modify it
76e173d3bSMartin Habets  * under the terms of the GNU General Public License version 2 as published
86e173d3bSMartin Habets  * by the Free Software Foundation, incorporated herein by reference.
96e173d3bSMartin Habets  */
106e173d3bSMartin Habets #include <linux/module.h>
116e173d3bSMartin Habets #include <linux/netdevice.h>
126e173d3bSMartin Habets #include "net_driver.h"
136e173d3bSMartin Habets #include "mcdi.h"
146e173d3bSMartin Habets #include "nic.h"
156e173d3bSMartin Habets #include "selftest.h"
166e173d3bSMartin Habets #include "rx_common.h"
176e173d3bSMartin Habets #include "ethtool_common.h"
186e173d3bSMartin Habets #include "mcdi_port_common.h"
196e173d3bSMartin Habets 
206e173d3bSMartin Habets struct efx_sw_stat_desc {
216e173d3bSMartin Habets 	const char *name;
226e173d3bSMartin Habets 	enum {
236e173d3bSMartin Habets 		EFX_ETHTOOL_STAT_SOURCE_nic,
246e173d3bSMartin Habets 		EFX_ETHTOOL_STAT_SOURCE_channel,
256e173d3bSMartin Habets 		EFX_ETHTOOL_STAT_SOURCE_tx_queue
266e173d3bSMartin Habets 	} source;
276e173d3bSMartin Habets 	unsigned int offset;
286e173d3bSMartin Habets 	u64 (*get_stat)(void *field); /* Reader function */
296e173d3bSMartin Habets };
306e173d3bSMartin Habets 
316e173d3bSMartin Habets /* Initialiser for a struct efx_sw_stat_desc with type-checking */
326e173d3bSMartin Habets #define EFX_ETHTOOL_STAT(stat_name, source_name, field, field_type, \
336e173d3bSMartin Habets 				get_stat_function) {			\
346e173d3bSMartin Habets 	.name = #stat_name,						\
356e173d3bSMartin Habets 	.source = EFX_ETHTOOL_STAT_SOURCE_##source_name,		\
366e173d3bSMartin Habets 	.offset = ((((field_type *) 0) ==				\
376e173d3bSMartin Habets 		      &((struct efx_##source_name *)0)->field) ?	\
386e173d3bSMartin Habets 		    offsetof(struct efx_##source_name, field) :		\
396e173d3bSMartin Habets 		    offsetof(struct efx_##source_name, field)),		\
406e173d3bSMartin Habets 	.get_stat = get_stat_function,					\
416e173d3bSMartin Habets }
426e173d3bSMartin Habets 
436e173d3bSMartin Habets static u64 efx_get_uint_stat(void *field)
446e173d3bSMartin Habets {
456e173d3bSMartin Habets 	return *(unsigned int *)field;
466e173d3bSMartin Habets }
476e173d3bSMartin Habets 
486e173d3bSMartin Habets static u64 efx_get_atomic_stat(void *field)
496e173d3bSMartin Habets {
506e173d3bSMartin Habets 	return atomic_read((atomic_t *) field);
516e173d3bSMartin Habets }
526e173d3bSMartin Habets 
536e173d3bSMartin Habets #define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field)		\
546e173d3bSMartin Habets 	EFX_ETHTOOL_STAT(field, nic, field,			\
556e173d3bSMartin Habets 			 atomic_t, efx_get_atomic_stat)
566e173d3bSMartin Habets 
576e173d3bSMartin Habets #define EFX_ETHTOOL_UINT_CHANNEL_STAT(field)			\
586e173d3bSMartin Habets 	EFX_ETHTOOL_STAT(field, channel, n_##field,		\
596e173d3bSMartin Habets 			 unsigned int, efx_get_uint_stat)
606e173d3bSMartin Habets #define EFX_ETHTOOL_UINT_CHANNEL_STAT_NO_N(field)		\
616e173d3bSMartin Habets 	EFX_ETHTOOL_STAT(field, channel, field,			\
626e173d3bSMartin Habets 			 unsigned int, efx_get_uint_stat)
636e173d3bSMartin Habets 
646e173d3bSMartin Habets #define EFX_ETHTOOL_UINT_TXQ_STAT(field)			\
656e173d3bSMartin Habets 	EFX_ETHTOOL_STAT(tx_##field, tx_queue, field,		\
666e173d3bSMartin Habets 			 unsigned int, efx_get_uint_stat)
676e173d3bSMartin Habets 
686e173d3bSMartin Habets static const struct efx_sw_stat_desc efx_sw_stat_desc[] = {
696e173d3bSMartin Habets 	EFX_ETHTOOL_UINT_TXQ_STAT(merge_events),
706e173d3bSMartin Habets 	EFX_ETHTOOL_UINT_TXQ_STAT(tso_bursts),
716e173d3bSMartin Habets 	EFX_ETHTOOL_UINT_TXQ_STAT(tso_long_headers),
726e173d3bSMartin Habets 	EFX_ETHTOOL_UINT_TXQ_STAT(tso_packets),
736e173d3bSMartin Habets 	EFX_ETHTOOL_UINT_TXQ_STAT(tso_fallbacks),
746e173d3bSMartin Habets 	EFX_ETHTOOL_UINT_TXQ_STAT(pushes),
756e173d3bSMartin Habets 	EFX_ETHTOOL_UINT_TXQ_STAT(pio_packets),
766e173d3bSMartin Habets 	EFX_ETHTOOL_UINT_TXQ_STAT(cb_packets),
776e173d3bSMartin Habets 	EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset),
786e173d3bSMartin Habets 	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc),
796e173d3bSMartin Habets 	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),
806e173d3bSMartin Habets 	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err),
816e173d3bSMartin Habets 	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_inner_ip_hdr_chksum_err),
826e173d3bSMartin Habets 	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_inner_tcp_udp_chksum_err),
836e173d3bSMartin Habets 	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_outer_ip_hdr_chksum_err),
846e173d3bSMartin Habets 	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_outer_tcp_udp_chksum_err),
856e173d3bSMartin Habets 	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_eth_crc_err),
866e173d3bSMartin Habets 	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch),
876e173d3bSMartin Habets 	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
886e173d3bSMartin Habets 	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_events),
896e173d3bSMartin Habets 	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_packets),
906e173d3bSMartin Habets 	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_xdp_drops),
916e173d3bSMartin Habets 	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_xdp_bad_drops),
926e173d3bSMartin Habets 	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_xdp_tx),
936e173d3bSMartin Habets 	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_xdp_redirect),
946e173d3bSMartin Habets #ifdef CONFIG_RFS_ACCEL
956e173d3bSMartin Habets 	EFX_ETHTOOL_UINT_CHANNEL_STAT_NO_N(rfs_filter_count),
966e173d3bSMartin Habets 	EFX_ETHTOOL_UINT_CHANNEL_STAT(rfs_succeeded),
976e173d3bSMartin Habets 	EFX_ETHTOOL_UINT_CHANNEL_STAT(rfs_failed),
986e173d3bSMartin Habets #endif
996e173d3bSMartin Habets };
1006e173d3bSMartin Habets 
1016e173d3bSMartin Habets #define EFX_ETHTOOL_SW_STAT_COUNT ARRAY_SIZE(efx_sw_stat_desc)
1026e173d3bSMartin Habets 
103*95e96f77SMartin Habets void efx_siena_ethtool_get_drvinfo(struct net_device *net_dev,
1046e173d3bSMartin Habets 				   struct ethtool_drvinfo *info)
1056e173d3bSMartin Habets {
1066e173d3bSMartin Habets 	struct efx_nic *efx = netdev_priv(net_dev);
1076e173d3bSMartin Habets 
1086e173d3bSMartin Habets 	strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
1096e173d3bSMartin Habets 	efx_mcdi_print_fwver(efx, info->fw_version,
1106e173d3bSMartin Habets 			     sizeof(info->fw_version));
1116e173d3bSMartin Habets 	strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
1126e173d3bSMartin Habets }
1136e173d3bSMartin Habets 
114*95e96f77SMartin Habets u32 efx_siena_ethtool_get_msglevel(struct net_device *net_dev)
1156e173d3bSMartin Habets {
1166e173d3bSMartin Habets 	struct efx_nic *efx = netdev_priv(net_dev);
1176e173d3bSMartin Habets 
1186e173d3bSMartin Habets 	return efx->msg_enable;
1196e173d3bSMartin Habets }
1206e173d3bSMartin Habets 
121*95e96f77SMartin Habets void efx_siena_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable)
1226e173d3bSMartin Habets {
1236e173d3bSMartin Habets 	struct efx_nic *efx = netdev_priv(net_dev);
1246e173d3bSMartin Habets 
1256e173d3bSMartin Habets 	efx->msg_enable = msg_enable;
1266e173d3bSMartin Habets }
1276e173d3bSMartin Habets 
128*95e96f77SMartin Habets void efx_siena_ethtool_get_pauseparam(struct net_device *net_dev,
1296e173d3bSMartin Habets 				      struct ethtool_pauseparam *pause)
1306e173d3bSMartin Habets {
1316e173d3bSMartin Habets 	struct efx_nic *efx = netdev_priv(net_dev);
1326e173d3bSMartin Habets 
1336e173d3bSMartin Habets 	pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX);
1346e173d3bSMartin Habets 	pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX);
1356e173d3bSMartin Habets 	pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO);
1366e173d3bSMartin Habets }
1376e173d3bSMartin Habets 
138*95e96f77SMartin Habets int efx_siena_ethtool_set_pauseparam(struct net_device *net_dev,
1396e173d3bSMartin Habets 				     struct ethtool_pauseparam *pause)
1406e173d3bSMartin Habets {
1416e173d3bSMartin Habets 	struct efx_nic *efx = netdev_priv(net_dev);
1426e173d3bSMartin Habets 	u8 wanted_fc, old_fc;
1436e173d3bSMartin Habets 	u32 old_adv;
1446e173d3bSMartin Habets 	int rc = 0;
1456e173d3bSMartin Habets 
1466e173d3bSMartin Habets 	mutex_lock(&efx->mac_lock);
1476e173d3bSMartin Habets 
1486e173d3bSMartin Habets 	wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
1496e173d3bSMartin Habets 		     (pause->tx_pause ? EFX_FC_TX : 0) |
1506e173d3bSMartin Habets 		     (pause->autoneg ? EFX_FC_AUTO : 0));
1516e173d3bSMartin Habets 
1526e173d3bSMartin Habets 	if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
1536e173d3bSMartin Habets 		netif_dbg(efx, drv, efx->net_dev,
1546e173d3bSMartin Habets 			  "Flow control unsupported: tx ON rx OFF\n");
1556e173d3bSMartin Habets 		rc = -EINVAL;
1566e173d3bSMartin Habets 		goto out;
1576e173d3bSMartin Habets 	}
1586e173d3bSMartin Habets 
1596e173d3bSMartin Habets 	if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising[0]) {
1606e173d3bSMartin Habets 		netif_dbg(efx, drv, efx->net_dev,
1616e173d3bSMartin Habets 			  "Autonegotiation is disabled\n");
1626e173d3bSMartin Habets 		rc = -EINVAL;
1636e173d3bSMartin Habets 		goto out;
1646e173d3bSMartin Habets 	}
1656e173d3bSMartin Habets 
1666e173d3bSMartin Habets 	/* Hook for Falcon bug 11482 workaround */
1676e173d3bSMartin Habets 	if (efx->type->prepare_enable_fc_tx &&
1686e173d3bSMartin Habets 	    (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX))
1696e173d3bSMartin Habets 		efx->type->prepare_enable_fc_tx(efx);
1706e173d3bSMartin Habets 
1716e173d3bSMartin Habets 	old_adv = efx->link_advertising[0];
1726e173d3bSMartin Habets 	old_fc = efx->wanted_fc;
17371ad88f6SMartin Habets 	efx_siena_link_set_wanted_fc(efx, wanted_fc);
1746e173d3bSMartin Habets 	if (efx->link_advertising[0] != old_adv ||
1756e173d3bSMartin Habets 	    (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) {
1766e173d3bSMartin Habets 		rc = efx_mcdi_port_reconfigure(efx);
1776e173d3bSMartin Habets 		if (rc) {
1786e173d3bSMartin Habets 			netif_err(efx, drv, efx->net_dev,
1796e173d3bSMartin Habets 				  "Unable to advertise requested flow "
1806e173d3bSMartin Habets 				  "control setting\n");
1816e173d3bSMartin Habets 			goto out;
1826e173d3bSMartin Habets 		}
1836e173d3bSMartin Habets 	}
1846e173d3bSMartin Habets 
1856e173d3bSMartin Habets 	/* Reconfigure the MAC. The PHY *may* generate a link state change event
1866e173d3bSMartin Habets 	 * if the user just changed the advertised capabilities, but there's no
1876e173d3bSMartin Habets 	 * harm doing this twice */
18871ad88f6SMartin Habets 	efx_siena_mac_reconfigure(efx, false);
1896e173d3bSMartin Habets 
1906e173d3bSMartin Habets out:
1916e173d3bSMartin Habets 	mutex_unlock(&efx->mac_lock);
1926e173d3bSMartin Habets 
1936e173d3bSMartin Habets 	return rc;
1946e173d3bSMartin Habets }
1956e173d3bSMartin Habets 
1966e173d3bSMartin Habets /**
1976e173d3bSMartin Habets  * efx_fill_test - fill in an individual self-test entry
1986e173d3bSMartin Habets  * @test_index:		Index of the test
1996e173d3bSMartin Habets  * @strings:		Ethtool strings, or %NULL
2006e173d3bSMartin Habets  * @data:		Ethtool test results, or %NULL
2016e173d3bSMartin Habets  * @test:		Pointer to test result (used only if data != %NULL)
2026e173d3bSMartin Habets  * @unit_format:	Unit name format (e.g. "chan\%d")
2036e173d3bSMartin Habets  * @unit_id:		Unit id (e.g. 0 for "chan0")
2046e173d3bSMartin Habets  * @test_format:	Test name format (e.g. "loopback.\%s.tx.sent")
2056e173d3bSMartin Habets  * @test_id:		Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
2066e173d3bSMartin Habets  *
2076e173d3bSMartin Habets  * Fill in an individual self-test entry.
2086e173d3bSMartin Habets  */
2096e173d3bSMartin Habets static void efx_fill_test(unsigned int test_index, u8 *strings, u64 *data,
2106e173d3bSMartin Habets 			  int *test, const char *unit_format, int unit_id,
2116e173d3bSMartin Habets 			  const char *test_format, const char *test_id)
2126e173d3bSMartin Habets {
2136e173d3bSMartin Habets 	char unit_str[ETH_GSTRING_LEN], test_str[ETH_GSTRING_LEN];
2146e173d3bSMartin Habets 
2156e173d3bSMartin Habets 	/* Fill data value, if applicable */
2166e173d3bSMartin Habets 	if (data)
2176e173d3bSMartin Habets 		data[test_index] = *test;
2186e173d3bSMartin Habets 
2196e173d3bSMartin Habets 	/* Fill string, if applicable */
2206e173d3bSMartin Habets 	if (strings) {
2216e173d3bSMartin Habets 		if (strchr(unit_format, '%'))
2226e173d3bSMartin Habets 			snprintf(unit_str, sizeof(unit_str),
2236e173d3bSMartin Habets 				 unit_format, unit_id);
2246e173d3bSMartin Habets 		else
2256e173d3bSMartin Habets 			strcpy(unit_str, unit_format);
2266e173d3bSMartin Habets 		snprintf(test_str, sizeof(test_str), test_format, test_id);
2276e173d3bSMartin Habets 		snprintf(strings + test_index * ETH_GSTRING_LEN,
2286e173d3bSMartin Habets 			 ETH_GSTRING_LEN,
2296e173d3bSMartin Habets 			 "%-6s %-24s", unit_str, test_str);
2306e173d3bSMartin Habets 	}
2316e173d3bSMartin Habets }
2326e173d3bSMartin Habets 
2336e173d3bSMartin Habets #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
2346e173d3bSMartin Habets #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->label
2356e173d3bSMartin Habets #define EFX_LOOPBACK_NAME(_mode, _counter)			\
236*95e96f77SMartin Habets 	"loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_siena_loopback_mode)
2376e173d3bSMartin Habets 
2386e173d3bSMartin Habets /**
2396e173d3bSMartin Habets  * efx_fill_loopback_test - fill in a block of loopback self-test entries
2406e173d3bSMartin Habets  * @efx:		Efx NIC
2416e173d3bSMartin Habets  * @lb_tests:		Efx loopback self-test results structure
2426e173d3bSMartin Habets  * @mode:		Loopback test mode
2436e173d3bSMartin Habets  * @test_index:		Starting index of the test
2446e173d3bSMartin Habets  * @strings:		Ethtool strings, or %NULL
2456e173d3bSMartin Habets  * @data:		Ethtool test results, or %NULL
2466e173d3bSMartin Habets  *
2476e173d3bSMartin Habets  * Fill in a block of loopback self-test entries.  Return new test
2486e173d3bSMartin Habets  * index.
2496e173d3bSMartin Habets  */
2506e173d3bSMartin Habets static int efx_fill_loopback_test(struct efx_nic *efx,
2516e173d3bSMartin Habets 				  struct efx_loopback_self_tests *lb_tests,
2526e173d3bSMartin Habets 				  enum efx_loopback_mode mode,
2536e173d3bSMartin Habets 				  unsigned int test_index,
2546e173d3bSMartin Habets 				  u8 *strings, u64 *data)
2556e173d3bSMartin Habets {
2566e173d3bSMartin Habets 	struct efx_channel *channel =
2576e173d3bSMartin Habets 		efx_get_channel(efx, efx->tx_channel_offset);
2586e173d3bSMartin Habets 	struct efx_tx_queue *tx_queue;
2596e173d3bSMartin Habets 
2606e173d3bSMartin Habets 	efx_for_each_channel_tx_queue(tx_queue, channel) {
2616e173d3bSMartin Habets 		efx_fill_test(test_index++, strings, data,
2626e173d3bSMartin Habets 			      &lb_tests->tx_sent[tx_queue->label],
2636e173d3bSMartin Habets 			      EFX_TX_QUEUE_NAME(tx_queue),
2646e173d3bSMartin Habets 			      EFX_LOOPBACK_NAME(mode, "tx_sent"));
2656e173d3bSMartin Habets 		efx_fill_test(test_index++, strings, data,
2666e173d3bSMartin Habets 			      &lb_tests->tx_done[tx_queue->label],
2676e173d3bSMartin Habets 			      EFX_TX_QUEUE_NAME(tx_queue),
2686e173d3bSMartin Habets 			      EFX_LOOPBACK_NAME(mode, "tx_done"));
2696e173d3bSMartin Habets 	}
2706e173d3bSMartin Habets 	efx_fill_test(test_index++, strings, data,
2716e173d3bSMartin Habets 		      &lb_tests->rx_good,
2726e173d3bSMartin Habets 		      "rx", 0,
2736e173d3bSMartin Habets 		      EFX_LOOPBACK_NAME(mode, "rx_good"));
2746e173d3bSMartin Habets 	efx_fill_test(test_index++, strings, data,
2756e173d3bSMartin Habets 		      &lb_tests->rx_bad,
2766e173d3bSMartin Habets 		      "rx", 0,
2776e173d3bSMartin Habets 		      EFX_LOOPBACK_NAME(mode, "rx_bad"));
2786e173d3bSMartin Habets 
2796e173d3bSMartin Habets 	return test_index;
2806e173d3bSMartin Habets }
2816e173d3bSMartin Habets 
2826e173d3bSMartin Habets /**
2836e173d3bSMartin Habets  * efx_ethtool_fill_self_tests - get self-test details
2846e173d3bSMartin Habets  * @efx:		Efx NIC
2856e173d3bSMartin Habets  * @tests:		Efx self-test results structure, or %NULL
2866e173d3bSMartin Habets  * @strings:		Ethtool strings, or %NULL
2876e173d3bSMartin Habets  * @data:		Ethtool test results, or %NULL
2886e173d3bSMartin Habets  *
2896e173d3bSMartin Habets  * Get self-test number of strings, strings, and/or test results.
2906e173d3bSMartin Habets  * Return number of strings (== number of test results).
2916e173d3bSMartin Habets  *
2926e173d3bSMartin Habets  * The reason for merging these three functions is to make sure that
2936e173d3bSMartin Habets  * they can never be inconsistent.
2946e173d3bSMartin Habets  */
295*95e96f77SMartin Habets static int efx_ethtool_fill_self_tests(struct efx_nic *efx,
2966e173d3bSMartin Habets 				       struct efx_self_tests *tests,
2976e173d3bSMartin Habets 				       u8 *strings, u64 *data)
2986e173d3bSMartin Habets {
2996e173d3bSMartin Habets 	struct efx_channel *channel;
3006e173d3bSMartin Habets 	unsigned int n = 0, i;
3016e173d3bSMartin Habets 	enum efx_loopback_mode mode;
3026e173d3bSMartin Habets 
3036e173d3bSMartin Habets 	efx_fill_test(n++, strings, data, &tests->phy_alive,
3046e173d3bSMartin Habets 		      "phy", 0, "alive", NULL);
3056e173d3bSMartin Habets 	efx_fill_test(n++, strings, data, &tests->nvram,
3066e173d3bSMartin Habets 		      "core", 0, "nvram", NULL);
3076e173d3bSMartin Habets 	efx_fill_test(n++, strings, data, &tests->interrupt,
3086e173d3bSMartin Habets 		      "core", 0, "interrupt", NULL);
3096e173d3bSMartin Habets 
3106e173d3bSMartin Habets 	/* Event queues */
3116e173d3bSMartin Habets 	efx_for_each_channel(channel, efx) {
3126e173d3bSMartin Habets 		efx_fill_test(n++, strings, data,
3136e173d3bSMartin Habets 			      &tests->eventq_dma[channel->channel],
3146e173d3bSMartin Habets 			      EFX_CHANNEL_NAME(channel),
3156e173d3bSMartin Habets 			      "eventq.dma", NULL);
3166e173d3bSMartin Habets 		efx_fill_test(n++, strings, data,
3176e173d3bSMartin Habets 			      &tests->eventq_int[channel->channel],
3186e173d3bSMartin Habets 			      EFX_CHANNEL_NAME(channel),
3196e173d3bSMartin Habets 			      "eventq.int", NULL);
3206e173d3bSMartin Habets 	}
3216e173d3bSMartin Habets 
3226e173d3bSMartin Habets 	efx_fill_test(n++, strings, data, &tests->memory,
3236e173d3bSMartin Habets 		      "core", 0, "memory", NULL);
3246e173d3bSMartin Habets 	efx_fill_test(n++, strings, data, &tests->registers,
3256e173d3bSMartin Habets 		      "core", 0, "registers", NULL);
3266e173d3bSMartin Habets 
3276e173d3bSMartin Habets 	for (i = 0; true; ++i) {
3286e173d3bSMartin Habets 		const char *name;
3296e173d3bSMartin Habets 
3306e173d3bSMartin Habets 		EFX_WARN_ON_PARANOID(i >= EFX_MAX_PHY_TESTS);
3316e173d3bSMartin Habets 		name = efx_mcdi_phy_test_name(efx, i);
3326e173d3bSMartin Habets 		if (name == NULL)
3336e173d3bSMartin Habets 			break;
3346e173d3bSMartin Habets 
3356e173d3bSMartin Habets 		efx_fill_test(n++, strings, data, &tests->phy_ext[i], "phy", 0, name, NULL);
3366e173d3bSMartin Habets 	}
3376e173d3bSMartin Habets 
3386e173d3bSMartin Habets 	/* Loopback tests */
3396e173d3bSMartin Habets 	for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
3406e173d3bSMartin Habets 		if (!(efx->loopback_modes & (1 << mode)))
3416e173d3bSMartin Habets 			continue;
3426e173d3bSMartin Habets 		n = efx_fill_loopback_test(efx,
3436e173d3bSMartin Habets 					   &tests->loopback[mode], mode, n,
3446e173d3bSMartin Habets 					   strings, data);
3456e173d3bSMartin Habets 	}
3466e173d3bSMartin Habets 
3476e173d3bSMartin Habets 	return n;
3486e173d3bSMartin Habets }
3496e173d3bSMartin Habets 
350*95e96f77SMartin Habets void efx_siena_ethtool_self_test(struct net_device *net_dev,
351*95e96f77SMartin Habets 				 struct ethtool_test *test, u64 *data)
352*95e96f77SMartin Habets {
353*95e96f77SMartin Habets 	struct efx_nic *efx = netdev_priv(net_dev);
354*95e96f77SMartin Habets 	struct efx_self_tests *efx_tests;
355*95e96f77SMartin Habets 	bool already_up;
356*95e96f77SMartin Habets 	int rc = -ENOMEM;
357*95e96f77SMartin Habets 
358*95e96f77SMartin Habets 	efx_tests = kzalloc(sizeof(*efx_tests), GFP_KERNEL);
359*95e96f77SMartin Habets 	if (!efx_tests)
360*95e96f77SMartin Habets 		goto fail;
361*95e96f77SMartin Habets 
362*95e96f77SMartin Habets 	if (efx->state != STATE_READY) {
363*95e96f77SMartin Habets 		rc = -EBUSY;
364*95e96f77SMartin Habets 		goto out;
365*95e96f77SMartin Habets 	}
366*95e96f77SMartin Habets 
367*95e96f77SMartin Habets 	netif_info(efx, drv, efx->net_dev, "starting %sline testing\n",
368*95e96f77SMartin Habets 		   (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
369*95e96f77SMartin Habets 
370*95e96f77SMartin Habets 	/* We need rx buffers and interrupts. */
371*95e96f77SMartin Habets 	already_up = (efx->net_dev->flags & IFF_UP);
372*95e96f77SMartin Habets 	if (!already_up) {
373*95e96f77SMartin Habets 		rc = dev_open(efx->net_dev, NULL);
374*95e96f77SMartin Habets 		if (rc) {
375*95e96f77SMartin Habets 			netif_err(efx, drv, efx->net_dev,
376*95e96f77SMartin Habets 				  "failed opening device.\n");
377*95e96f77SMartin Habets 			goto out;
378*95e96f77SMartin Habets 		}
379*95e96f77SMartin Habets 	}
380*95e96f77SMartin Habets 
381*95e96f77SMartin Habets 	rc = efx_siena_selftest(efx, efx_tests, test->flags);
382*95e96f77SMartin Habets 
383*95e96f77SMartin Habets 	if (!already_up)
384*95e96f77SMartin Habets 		dev_close(efx->net_dev);
385*95e96f77SMartin Habets 
386*95e96f77SMartin Habets 	netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n",
387*95e96f77SMartin Habets 		   rc == 0 ? "passed" : "failed",
388*95e96f77SMartin Habets 		   (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
389*95e96f77SMartin Habets 
390*95e96f77SMartin Habets out:
391*95e96f77SMartin Habets 	efx_ethtool_fill_self_tests(efx, efx_tests, NULL, data);
392*95e96f77SMartin Habets 	kfree(efx_tests);
393*95e96f77SMartin Habets fail:
394*95e96f77SMartin Habets 	if (rc)
395*95e96f77SMartin Habets 		test->flags |= ETH_TEST_FL_FAILED;
396*95e96f77SMartin Habets }
397*95e96f77SMartin Habets 
3986e173d3bSMartin Habets static size_t efx_describe_per_queue_stats(struct efx_nic *efx, u8 *strings)
3996e173d3bSMartin Habets {
4006e173d3bSMartin Habets 	size_t n_stats = 0;
4016e173d3bSMartin Habets 	struct efx_channel *channel;
4026e173d3bSMartin Habets 
4036e173d3bSMartin Habets 	efx_for_each_channel(channel, efx) {
4046e173d3bSMartin Habets 		if (efx_channel_has_tx_queues(channel)) {
4056e173d3bSMartin Habets 			n_stats++;
4066e173d3bSMartin Habets 			if (strings != NULL) {
4076e173d3bSMartin Habets 				snprintf(strings, ETH_GSTRING_LEN,
4086e173d3bSMartin Habets 					 "tx-%u.tx_packets",
4096e173d3bSMartin Habets 					 channel->tx_queue[0].queue /
4106e173d3bSMartin Habets 					 EFX_MAX_TXQ_PER_CHANNEL);
4116e173d3bSMartin Habets 
4126e173d3bSMartin Habets 				strings += ETH_GSTRING_LEN;
4136e173d3bSMartin Habets 			}
4146e173d3bSMartin Habets 		}
4156e173d3bSMartin Habets 	}
4166e173d3bSMartin Habets 	efx_for_each_channel(channel, efx) {
4176e173d3bSMartin Habets 		if (efx_channel_has_rx_queue(channel)) {
4186e173d3bSMartin Habets 			n_stats++;
4196e173d3bSMartin Habets 			if (strings != NULL) {
4206e173d3bSMartin Habets 				snprintf(strings, ETH_GSTRING_LEN,
4216e173d3bSMartin Habets 					 "rx-%d.rx_packets", channel->channel);
4226e173d3bSMartin Habets 				strings += ETH_GSTRING_LEN;
4236e173d3bSMartin Habets 			}
4246e173d3bSMartin Habets 		}
4256e173d3bSMartin Habets 	}
4266e173d3bSMartin Habets 	if (efx->xdp_tx_queue_count && efx->xdp_tx_queues) {
4276e173d3bSMartin Habets 		unsigned short xdp;
4286e173d3bSMartin Habets 
4296e173d3bSMartin Habets 		for (xdp = 0; xdp < efx->xdp_tx_queue_count; xdp++) {
4306e173d3bSMartin Habets 			n_stats++;
4316e173d3bSMartin Habets 			if (strings) {
4326e173d3bSMartin Habets 				snprintf(strings, ETH_GSTRING_LEN,
4336e173d3bSMartin Habets 					 "tx-xdp-cpu-%hu.tx_packets", xdp);
4346e173d3bSMartin Habets 				strings += ETH_GSTRING_LEN;
4356e173d3bSMartin Habets 			}
4366e173d3bSMartin Habets 		}
4376e173d3bSMartin Habets 	}
4386e173d3bSMartin Habets 
4396e173d3bSMartin Habets 	return n_stats;
4406e173d3bSMartin Habets }
4416e173d3bSMartin Habets 
442*95e96f77SMartin Habets int efx_siena_ethtool_get_sset_count(struct net_device *net_dev, int string_set)
4436e173d3bSMartin Habets {
4446e173d3bSMartin Habets 	struct efx_nic *efx = netdev_priv(net_dev);
4456e173d3bSMartin Habets 
4466e173d3bSMartin Habets 	switch (string_set) {
4476e173d3bSMartin Habets 	case ETH_SS_STATS:
4486e173d3bSMartin Habets 		return efx->type->describe_stats(efx, NULL) +
4496e173d3bSMartin Habets 		       EFX_ETHTOOL_SW_STAT_COUNT +
4506e173d3bSMartin Habets 		       efx_describe_per_queue_stats(efx, NULL) +
451*95e96f77SMartin Habets 		       efx_siena_ptp_describe_stats(efx, NULL);
4526e173d3bSMartin Habets 	case ETH_SS_TEST:
4536e173d3bSMartin Habets 		return efx_ethtool_fill_self_tests(efx, NULL, NULL, NULL);
4546e173d3bSMartin Habets 	default:
4556e173d3bSMartin Habets 		return -EINVAL;
4566e173d3bSMartin Habets 	}
4576e173d3bSMartin Habets }
4586e173d3bSMartin Habets 
459*95e96f77SMartin Habets void efx_siena_ethtool_get_strings(struct net_device *net_dev,
4606e173d3bSMartin Habets 				   u32 string_set, u8 *strings)
4616e173d3bSMartin Habets {
4626e173d3bSMartin Habets 	struct efx_nic *efx = netdev_priv(net_dev);
4636e173d3bSMartin Habets 	int i;
4646e173d3bSMartin Habets 
4656e173d3bSMartin Habets 	switch (string_set) {
4666e173d3bSMartin Habets 	case ETH_SS_STATS:
4676e173d3bSMartin Habets 		strings += (efx->type->describe_stats(efx, strings) *
4686e173d3bSMartin Habets 			    ETH_GSTRING_LEN);
4696e173d3bSMartin Habets 		for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++)
4706e173d3bSMartin Habets 			strlcpy(strings + i * ETH_GSTRING_LEN,
4716e173d3bSMartin Habets 				efx_sw_stat_desc[i].name, ETH_GSTRING_LEN);
4726e173d3bSMartin Habets 		strings += EFX_ETHTOOL_SW_STAT_COUNT * ETH_GSTRING_LEN;
4736e173d3bSMartin Habets 		strings += (efx_describe_per_queue_stats(efx, strings) *
4746e173d3bSMartin Habets 			    ETH_GSTRING_LEN);
475*95e96f77SMartin Habets 		efx_siena_ptp_describe_stats(efx, strings);
4766e173d3bSMartin Habets 		break;
4776e173d3bSMartin Habets 	case ETH_SS_TEST:
4786e173d3bSMartin Habets 		efx_ethtool_fill_self_tests(efx, NULL, strings, NULL);
4796e173d3bSMartin Habets 		break;
4806e173d3bSMartin Habets 	default:
4816e173d3bSMartin Habets 		/* No other string sets */
4826e173d3bSMartin Habets 		break;
4836e173d3bSMartin Habets 	}
4846e173d3bSMartin Habets }
4856e173d3bSMartin Habets 
486*95e96f77SMartin Habets void efx_siena_ethtool_get_stats(struct net_device *net_dev,
4876e173d3bSMartin Habets 				 struct ethtool_stats *stats,
4886e173d3bSMartin Habets 				 u64 *data)
4896e173d3bSMartin Habets {
4906e173d3bSMartin Habets 	struct efx_nic *efx = netdev_priv(net_dev);
4916e173d3bSMartin Habets 	const struct efx_sw_stat_desc *stat;
4926e173d3bSMartin Habets 	struct efx_channel *channel;
4936e173d3bSMartin Habets 	struct efx_tx_queue *tx_queue;
4946e173d3bSMartin Habets 	struct efx_rx_queue *rx_queue;
4956e173d3bSMartin Habets 	int i;
4966e173d3bSMartin Habets 
4976e173d3bSMartin Habets 	spin_lock_bh(&efx->stats_lock);
4986e173d3bSMartin Habets 
4996e173d3bSMartin Habets 	/* Get NIC statistics */
5006e173d3bSMartin Habets 	data += efx->type->update_stats(efx, data, NULL);
5016e173d3bSMartin Habets 
5026e173d3bSMartin Habets 	/* Get software statistics */
5036e173d3bSMartin Habets 	for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) {
5046e173d3bSMartin Habets 		stat = &efx_sw_stat_desc[i];
5056e173d3bSMartin Habets 		switch (stat->source) {
5066e173d3bSMartin Habets 		case EFX_ETHTOOL_STAT_SOURCE_nic:
5076e173d3bSMartin Habets 			data[i] = stat->get_stat((void *)efx + stat->offset);
5086e173d3bSMartin Habets 			break;
5096e173d3bSMartin Habets 		case EFX_ETHTOOL_STAT_SOURCE_channel:
5106e173d3bSMartin Habets 			data[i] = 0;
5116e173d3bSMartin Habets 			efx_for_each_channel(channel, efx)
5126e173d3bSMartin Habets 				data[i] += stat->get_stat((void *)channel +
5136e173d3bSMartin Habets 							  stat->offset);
5146e173d3bSMartin Habets 			break;
5156e173d3bSMartin Habets 		case EFX_ETHTOOL_STAT_SOURCE_tx_queue:
5166e173d3bSMartin Habets 			data[i] = 0;
5176e173d3bSMartin Habets 			efx_for_each_channel(channel, efx) {
5186e173d3bSMartin Habets 				efx_for_each_channel_tx_queue(tx_queue, channel)
5196e173d3bSMartin Habets 					data[i] +=
5206e173d3bSMartin Habets 						stat->get_stat((void *)tx_queue
5216e173d3bSMartin Habets 							       + stat->offset);
5226e173d3bSMartin Habets 			}
5236e173d3bSMartin Habets 			break;
5246e173d3bSMartin Habets 		}
5256e173d3bSMartin Habets 	}
5266e173d3bSMartin Habets 	data += EFX_ETHTOOL_SW_STAT_COUNT;
5276e173d3bSMartin Habets 
5286e173d3bSMartin Habets 	spin_unlock_bh(&efx->stats_lock);
5296e173d3bSMartin Habets 
5306e173d3bSMartin Habets 	efx_for_each_channel(channel, efx) {
5316e173d3bSMartin Habets 		if (efx_channel_has_tx_queues(channel)) {
5326e173d3bSMartin Habets 			*data = 0;
5336e173d3bSMartin Habets 			efx_for_each_channel_tx_queue(tx_queue, channel) {
5346e173d3bSMartin Habets 				*data += tx_queue->tx_packets;
5356e173d3bSMartin Habets 			}
5366e173d3bSMartin Habets 			data++;
5376e173d3bSMartin Habets 		}
5386e173d3bSMartin Habets 	}
5396e173d3bSMartin Habets 	efx_for_each_channel(channel, efx) {
5406e173d3bSMartin Habets 		if (efx_channel_has_rx_queue(channel)) {
5416e173d3bSMartin Habets 			*data = 0;
5426e173d3bSMartin Habets 			efx_for_each_channel_rx_queue(rx_queue, channel) {
5436e173d3bSMartin Habets 				*data += rx_queue->rx_packets;
5446e173d3bSMartin Habets 			}
5456e173d3bSMartin Habets 			data++;
5466e173d3bSMartin Habets 		}
5476e173d3bSMartin Habets 	}
5486e173d3bSMartin Habets 	if (efx->xdp_tx_queue_count && efx->xdp_tx_queues) {
5496e173d3bSMartin Habets 		int xdp;
5506e173d3bSMartin Habets 
5516e173d3bSMartin Habets 		for (xdp = 0; xdp < efx->xdp_tx_queue_count; xdp++) {
5526e173d3bSMartin Habets 			data[0] = efx->xdp_tx_queues[xdp]->tx_packets;
5536e173d3bSMartin Habets 			data++;
5546e173d3bSMartin Habets 		}
5556e173d3bSMartin Habets 	}
5566e173d3bSMartin Habets 
557*95e96f77SMartin Habets 	efx_siena_ptp_update_stats(efx, data);
5586e173d3bSMartin Habets }
5596e173d3bSMartin Habets 
5606e173d3bSMartin Habets /* This must be called with rtnl_lock held. */
561*95e96f77SMartin Habets int efx_siena_ethtool_get_link_ksettings(struct net_device *net_dev,
5626e173d3bSMartin Habets 					 struct ethtool_link_ksettings *cmd)
5636e173d3bSMartin Habets {
5646e173d3bSMartin Habets 	struct efx_nic *efx = netdev_priv(net_dev);
5656e173d3bSMartin Habets 	struct efx_link_state *link_state = &efx->link_state;
5666e173d3bSMartin Habets 
5676e173d3bSMartin Habets 	mutex_lock(&efx->mac_lock);
5686e173d3bSMartin Habets 	efx_mcdi_phy_get_link_ksettings(efx, cmd);
5696e173d3bSMartin Habets 	mutex_unlock(&efx->mac_lock);
5706e173d3bSMartin Habets 
5716e173d3bSMartin Habets 	/* Both MACs support pause frames (bidirectional and respond-only) */
5726e173d3bSMartin Habets 	ethtool_link_ksettings_add_link_mode(cmd, supported, Pause);
5736e173d3bSMartin Habets 	ethtool_link_ksettings_add_link_mode(cmd, supported, Asym_Pause);
5746e173d3bSMartin Habets 
5756e173d3bSMartin Habets 	if (LOOPBACK_INTERNAL(efx)) {
5766e173d3bSMartin Habets 		cmd->base.speed = link_state->speed;
5776e173d3bSMartin Habets 		cmd->base.duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF;
5786e173d3bSMartin Habets 	}
5796e173d3bSMartin Habets 
5806e173d3bSMartin Habets 	return 0;
5816e173d3bSMartin Habets }
5826e173d3bSMartin Habets 
5836e173d3bSMartin Habets /* This must be called with rtnl_lock held. */
584*95e96f77SMartin Habets int
585*95e96f77SMartin Habets efx_siena_ethtool_set_link_ksettings(struct net_device *net_dev,
5866e173d3bSMartin Habets 				     const struct ethtool_link_ksettings *cmd)
5876e173d3bSMartin Habets {
5886e173d3bSMartin Habets 	struct efx_nic *efx = netdev_priv(net_dev);
5896e173d3bSMartin Habets 	int rc;
5906e173d3bSMartin Habets 
5916e173d3bSMartin Habets 	/* GMAC does not support 1000Mbps HD */
5926e173d3bSMartin Habets 	if ((cmd->base.speed == SPEED_1000) &&
5936e173d3bSMartin Habets 	    (cmd->base.duplex != DUPLEX_FULL)) {
5946e173d3bSMartin Habets 		netif_dbg(efx, drv, efx->net_dev,
5956e173d3bSMartin Habets 			  "rejecting unsupported 1000Mbps HD setting\n");
5966e173d3bSMartin Habets 		return -EINVAL;
5976e173d3bSMartin Habets 	}
5986e173d3bSMartin Habets 
5996e173d3bSMartin Habets 	mutex_lock(&efx->mac_lock);
6006e173d3bSMartin Habets 	rc = efx_mcdi_phy_set_link_ksettings(efx, cmd);
6016e173d3bSMartin Habets 	mutex_unlock(&efx->mac_lock);
6026e173d3bSMartin Habets 	return rc;
6036e173d3bSMartin Habets }
6046e173d3bSMartin Habets 
605*95e96f77SMartin Habets int efx_siena_ethtool_get_fecparam(struct net_device *net_dev,
6066e173d3bSMartin Habets 				   struct ethtool_fecparam *fecparam)
6076e173d3bSMartin Habets {
6086e173d3bSMartin Habets 	struct efx_nic *efx = netdev_priv(net_dev);
6096e173d3bSMartin Habets 	int rc;
6106e173d3bSMartin Habets 
6116e173d3bSMartin Habets 	mutex_lock(&efx->mac_lock);
6126e173d3bSMartin Habets 	rc = efx_mcdi_phy_get_fecparam(efx, fecparam);
6136e173d3bSMartin Habets 	mutex_unlock(&efx->mac_lock);
6146e173d3bSMartin Habets 
6156e173d3bSMartin Habets 	return rc;
6166e173d3bSMartin Habets }
6176e173d3bSMartin Habets 
618*95e96f77SMartin Habets int efx_siena_ethtool_set_fecparam(struct net_device *net_dev,
6196e173d3bSMartin Habets 				   struct ethtool_fecparam *fecparam)
6206e173d3bSMartin Habets {
6216e173d3bSMartin Habets 	struct efx_nic *efx = netdev_priv(net_dev);
6226e173d3bSMartin Habets 	int rc;
6236e173d3bSMartin Habets 
6246e173d3bSMartin Habets 	mutex_lock(&efx->mac_lock);
6256e173d3bSMartin Habets 	rc = efx_mcdi_phy_set_fecparam(efx, fecparam);
6266e173d3bSMartin Habets 	mutex_unlock(&efx->mac_lock);
6276e173d3bSMartin Habets 
6286e173d3bSMartin Habets 	return rc;
6296e173d3bSMartin Habets }
6306e173d3bSMartin Habets 
6316e173d3bSMartin Habets /* MAC address mask including only I/G bit */
6326e173d3bSMartin Habets static const u8 mac_addr_ig_mask[ETH_ALEN] __aligned(2) = {0x01, 0, 0, 0, 0, 0};
6336e173d3bSMartin Habets 
6346e173d3bSMartin Habets #define IP4_ADDR_FULL_MASK	((__force __be32)~0)
6356e173d3bSMartin Habets #define IP_PROTO_FULL_MASK	0xFF
6366e173d3bSMartin Habets #define PORT_FULL_MASK		((__force __be16)~0)
6376e173d3bSMartin Habets #define ETHER_TYPE_FULL_MASK	((__force __be16)~0)
6386e173d3bSMartin Habets 
6396e173d3bSMartin Habets static inline void ip6_fill_mask(__be32 *mask)
6406e173d3bSMartin Habets {
6416e173d3bSMartin Habets 	mask[0] = mask[1] = mask[2] = mask[3] = ~(__be32)0;
6426e173d3bSMartin Habets }
6436e173d3bSMartin Habets 
6446e173d3bSMartin Habets static int efx_ethtool_get_class_rule(struct efx_nic *efx,
6456e173d3bSMartin Habets 				      struct ethtool_rx_flow_spec *rule,
6466e173d3bSMartin Habets 				      u32 *rss_context)
6476e173d3bSMartin Habets {
6486e173d3bSMartin Habets 	struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
6496e173d3bSMartin Habets 	struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
6506e173d3bSMartin Habets 	struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
6516e173d3bSMartin Habets 	struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
6526e173d3bSMartin Habets 	struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
6536e173d3bSMartin Habets 	struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
6546e173d3bSMartin Habets 	struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
6556e173d3bSMartin Habets 	struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
6566e173d3bSMartin Habets 	struct ethhdr *mac_entry = &rule->h_u.ether_spec;
6576e173d3bSMartin Habets 	struct ethhdr *mac_mask = &rule->m_u.ether_spec;
6586e173d3bSMartin Habets 	struct efx_filter_spec spec;
6596e173d3bSMartin Habets 	int rc;
6606e173d3bSMartin Habets 
6616e173d3bSMartin Habets 	rc = efx_filter_get_filter_safe(efx, EFX_FILTER_PRI_MANUAL,
6626e173d3bSMartin Habets 					rule->location, &spec);
6636e173d3bSMartin Habets 	if (rc)
6646e173d3bSMartin Habets 		return rc;
6656e173d3bSMartin Habets 
6666e173d3bSMartin Habets 	if (spec.dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP)
6676e173d3bSMartin Habets 		rule->ring_cookie = RX_CLS_FLOW_DISC;
6686e173d3bSMartin Habets 	else
6696e173d3bSMartin Habets 		rule->ring_cookie = spec.dmaq_id;
6706e173d3bSMartin Habets 
6716e173d3bSMartin Habets 	if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) &&
6726e173d3bSMartin Habets 	    spec.ether_type == htons(ETH_P_IP) &&
6736e173d3bSMartin Habets 	    (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) &&
6746e173d3bSMartin Habets 	    (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
6756e173d3bSMartin Habets 	    !(spec.match_flags &
6766e173d3bSMartin Habets 	      ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
6776e173d3bSMartin Habets 		EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
6786e173d3bSMartin Habets 		EFX_FILTER_MATCH_IP_PROTO |
6796e173d3bSMartin Habets 		EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) {
6806e173d3bSMartin Habets 		rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
6816e173d3bSMartin Habets 				   TCP_V4_FLOW : UDP_V4_FLOW);
6826e173d3bSMartin Habets 		if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
6836e173d3bSMartin Habets 			ip_entry->ip4dst = spec.loc_host[0];
6846e173d3bSMartin Habets 			ip_mask->ip4dst = IP4_ADDR_FULL_MASK;
6856e173d3bSMartin Habets 		}
6866e173d3bSMartin Habets 		if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
6876e173d3bSMartin Habets 			ip_entry->ip4src = spec.rem_host[0];
6886e173d3bSMartin Habets 			ip_mask->ip4src = IP4_ADDR_FULL_MASK;
6896e173d3bSMartin Habets 		}
6906e173d3bSMartin Habets 		if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) {
6916e173d3bSMartin Habets 			ip_entry->pdst = spec.loc_port;
6926e173d3bSMartin Habets 			ip_mask->pdst = PORT_FULL_MASK;
6936e173d3bSMartin Habets 		}
6946e173d3bSMartin Habets 		if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) {
6956e173d3bSMartin Habets 			ip_entry->psrc = spec.rem_port;
6966e173d3bSMartin Habets 			ip_mask->psrc = PORT_FULL_MASK;
6976e173d3bSMartin Habets 		}
6986e173d3bSMartin Habets 	} else if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) &&
6996e173d3bSMartin Habets 	    spec.ether_type == htons(ETH_P_IPV6) &&
7006e173d3bSMartin Habets 	    (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) &&
7016e173d3bSMartin Habets 	    (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
7026e173d3bSMartin Habets 	    !(spec.match_flags &
7036e173d3bSMartin Habets 	      ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
7046e173d3bSMartin Habets 		EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
7056e173d3bSMartin Habets 		EFX_FILTER_MATCH_IP_PROTO |
7066e173d3bSMartin Habets 		EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) {
7076e173d3bSMartin Habets 		rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
7086e173d3bSMartin Habets 				   TCP_V6_FLOW : UDP_V6_FLOW);
7096e173d3bSMartin Habets 		if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
7106e173d3bSMartin Habets 			memcpy(ip6_entry->ip6dst, spec.loc_host,
7116e173d3bSMartin Habets 			       sizeof(ip6_entry->ip6dst));
7126e173d3bSMartin Habets 			ip6_fill_mask(ip6_mask->ip6dst);
7136e173d3bSMartin Habets 		}
7146e173d3bSMartin Habets 		if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
7156e173d3bSMartin Habets 			memcpy(ip6_entry->ip6src, spec.rem_host,
7166e173d3bSMartin Habets 			       sizeof(ip6_entry->ip6src));
7176e173d3bSMartin Habets 			ip6_fill_mask(ip6_mask->ip6src);
7186e173d3bSMartin Habets 		}
7196e173d3bSMartin Habets 		if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) {
7206e173d3bSMartin Habets 			ip6_entry->pdst = spec.loc_port;
7216e173d3bSMartin Habets 			ip6_mask->pdst = PORT_FULL_MASK;
7226e173d3bSMartin Habets 		}
7236e173d3bSMartin Habets 		if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) {
7246e173d3bSMartin Habets 			ip6_entry->psrc = spec.rem_port;
7256e173d3bSMartin Habets 			ip6_mask->psrc = PORT_FULL_MASK;
7266e173d3bSMartin Habets 		}
7276e173d3bSMartin Habets 	} else if (!(spec.match_flags &
7286e173d3bSMartin Habets 		     ~(EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG |
7296e173d3bSMartin Habets 		       EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_ETHER_TYPE |
7306e173d3bSMartin Habets 		       EFX_FILTER_MATCH_OUTER_VID))) {
7316e173d3bSMartin Habets 		rule->flow_type = ETHER_FLOW;
7326e173d3bSMartin Habets 		if (spec.match_flags &
7336e173d3bSMartin Habets 		    (EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG)) {
7346e173d3bSMartin Habets 			ether_addr_copy(mac_entry->h_dest, spec.loc_mac);
7356e173d3bSMartin Habets 			if (spec.match_flags & EFX_FILTER_MATCH_LOC_MAC)
7366e173d3bSMartin Habets 				eth_broadcast_addr(mac_mask->h_dest);
7376e173d3bSMartin Habets 			else
7386e173d3bSMartin Habets 				ether_addr_copy(mac_mask->h_dest,
7396e173d3bSMartin Habets 						mac_addr_ig_mask);
7406e173d3bSMartin Habets 		}
7416e173d3bSMartin Habets 		if (spec.match_flags & EFX_FILTER_MATCH_REM_MAC) {
7426e173d3bSMartin Habets 			ether_addr_copy(mac_entry->h_source, spec.rem_mac);
7436e173d3bSMartin Habets 			eth_broadcast_addr(mac_mask->h_source);
7446e173d3bSMartin Habets 		}
7456e173d3bSMartin Habets 		if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) {
7466e173d3bSMartin Habets 			mac_entry->h_proto = spec.ether_type;
7476e173d3bSMartin Habets 			mac_mask->h_proto = ETHER_TYPE_FULL_MASK;
7486e173d3bSMartin Habets 		}
7496e173d3bSMartin Habets 	} else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
7506e173d3bSMartin Habets 		   spec.ether_type == htons(ETH_P_IP) &&
7516e173d3bSMartin Habets 		   !(spec.match_flags &
7526e173d3bSMartin Habets 		     ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
7536e173d3bSMartin Habets 		       EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
7546e173d3bSMartin Habets 		       EFX_FILTER_MATCH_IP_PROTO))) {
7556e173d3bSMartin Habets 		rule->flow_type = IPV4_USER_FLOW;
7566e173d3bSMartin Habets 		uip_entry->ip_ver = ETH_RX_NFC_IP4;
7576e173d3bSMartin Habets 		if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) {
7586e173d3bSMartin Habets 			uip_mask->proto = IP_PROTO_FULL_MASK;
7596e173d3bSMartin Habets 			uip_entry->proto = spec.ip_proto;
7606e173d3bSMartin Habets 		}
7616e173d3bSMartin Habets 		if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
7626e173d3bSMartin Habets 			uip_entry->ip4dst = spec.loc_host[0];
7636e173d3bSMartin Habets 			uip_mask->ip4dst = IP4_ADDR_FULL_MASK;
7646e173d3bSMartin Habets 		}
7656e173d3bSMartin Habets 		if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
7666e173d3bSMartin Habets 			uip_entry->ip4src = spec.rem_host[0];
7676e173d3bSMartin Habets 			uip_mask->ip4src = IP4_ADDR_FULL_MASK;
7686e173d3bSMartin Habets 		}
7696e173d3bSMartin Habets 	} else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
7706e173d3bSMartin Habets 		   spec.ether_type == htons(ETH_P_IPV6) &&
7716e173d3bSMartin Habets 		   !(spec.match_flags &
7726e173d3bSMartin Habets 		     ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
7736e173d3bSMartin Habets 		       EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
7746e173d3bSMartin Habets 		       EFX_FILTER_MATCH_IP_PROTO))) {
7756e173d3bSMartin Habets 		rule->flow_type = IPV6_USER_FLOW;
7766e173d3bSMartin Habets 		if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) {
7776e173d3bSMartin Habets 			uip6_mask->l4_proto = IP_PROTO_FULL_MASK;
7786e173d3bSMartin Habets 			uip6_entry->l4_proto = spec.ip_proto;
7796e173d3bSMartin Habets 		}
7806e173d3bSMartin Habets 		if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
7816e173d3bSMartin Habets 			memcpy(uip6_entry->ip6dst, spec.loc_host,
7826e173d3bSMartin Habets 			       sizeof(uip6_entry->ip6dst));
7836e173d3bSMartin Habets 			ip6_fill_mask(uip6_mask->ip6dst);
7846e173d3bSMartin Habets 		}
7856e173d3bSMartin Habets 		if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
7866e173d3bSMartin Habets 			memcpy(uip6_entry->ip6src, spec.rem_host,
7876e173d3bSMartin Habets 			       sizeof(uip6_entry->ip6src));
7886e173d3bSMartin Habets 			ip6_fill_mask(uip6_mask->ip6src);
7896e173d3bSMartin Habets 		}
7906e173d3bSMartin Habets 	} else {
7916e173d3bSMartin Habets 		/* The above should handle all filters that we insert */
7926e173d3bSMartin Habets 		WARN_ON(1);
7936e173d3bSMartin Habets 		return -EINVAL;
7946e173d3bSMartin Habets 	}
7956e173d3bSMartin Habets 
7966e173d3bSMartin Habets 	if (spec.match_flags & EFX_FILTER_MATCH_OUTER_VID) {
7976e173d3bSMartin Habets 		rule->flow_type |= FLOW_EXT;
7986e173d3bSMartin Habets 		rule->h_ext.vlan_tci = spec.outer_vid;
7996e173d3bSMartin Habets 		rule->m_ext.vlan_tci = htons(0xfff);
8006e173d3bSMartin Habets 	}
8016e173d3bSMartin Habets 
8026e173d3bSMartin Habets 	if (spec.flags & EFX_FILTER_FLAG_RX_RSS) {
8036e173d3bSMartin Habets 		rule->flow_type |= FLOW_RSS;
8046e173d3bSMartin Habets 		*rss_context = spec.rss_context;
8056e173d3bSMartin Habets 	}
8066e173d3bSMartin Habets 
8076e173d3bSMartin Habets 	return rc;
8086e173d3bSMartin Habets }
8096e173d3bSMartin Habets 
810*95e96f77SMartin Habets int efx_siena_ethtool_get_rxnfc(struct net_device *net_dev,
8116e173d3bSMartin Habets 				struct ethtool_rxnfc *info, u32 *rule_locs)
8126e173d3bSMartin Habets {
8136e173d3bSMartin Habets 	struct efx_nic *efx = netdev_priv(net_dev);
8146e173d3bSMartin Habets 	u32 rss_context = 0;
8156e173d3bSMartin Habets 	s32 rc = 0;
8166e173d3bSMartin Habets 
8176e173d3bSMartin Habets 	switch (info->cmd) {
8186e173d3bSMartin Habets 	case ETHTOOL_GRXRINGS:
8196e173d3bSMartin Habets 		info->data = efx->n_rx_channels;
8206e173d3bSMartin Habets 		return 0;
8216e173d3bSMartin Habets 
8226e173d3bSMartin Habets 	case ETHTOOL_GRXFH: {
8236e173d3bSMartin Habets 		struct efx_rss_context *ctx = &efx->rss_context;
8246e173d3bSMartin Habets 		__u64 data;
8256e173d3bSMartin Habets 
8266e173d3bSMartin Habets 		mutex_lock(&efx->rss_lock);
8276e173d3bSMartin Habets 		if (info->flow_type & FLOW_RSS && info->rss_context) {
8287f9e4b2aSMartin Habets 			ctx = efx_siena_find_rss_context_entry(efx,
8297f9e4b2aSMartin Habets 							info->rss_context);
8306e173d3bSMartin Habets 			if (!ctx) {
8316e173d3bSMartin Habets 				rc = -ENOENT;
8326e173d3bSMartin Habets 				goto out_unlock;
8336e173d3bSMartin Habets 			}
8346e173d3bSMartin Habets 		}
8356e173d3bSMartin Habets 
8366e173d3bSMartin Habets 		data = 0;
8376e173d3bSMartin Habets 		if (!efx_rss_active(ctx)) /* No RSS */
8386e173d3bSMartin Habets 			goto out_setdata_unlock;
8396e173d3bSMartin Habets 
8406e173d3bSMartin Habets 		switch (info->flow_type & ~FLOW_RSS) {
8416e173d3bSMartin Habets 		case UDP_V4_FLOW:
8426e173d3bSMartin Habets 		case UDP_V6_FLOW:
8436e173d3bSMartin Habets 			if (ctx->rx_hash_udp_4tuple)
8446e173d3bSMartin Habets 				data = (RXH_L4_B_0_1 | RXH_L4_B_2_3 |
8456e173d3bSMartin Habets 					RXH_IP_SRC | RXH_IP_DST);
8466e173d3bSMartin Habets 			else
8476e173d3bSMartin Habets 				data = RXH_IP_SRC | RXH_IP_DST;
8486e173d3bSMartin Habets 			break;
8496e173d3bSMartin Habets 		case TCP_V4_FLOW:
8506e173d3bSMartin Habets 		case TCP_V6_FLOW:
8516e173d3bSMartin Habets 			data = (RXH_L4_B_0_1 | RXH_L4_B_2_3 |
8526e173d3bSMartin Habets 				RXH_IP_SRC | RXH_IP_DST);
8536e173d3bSMartin Habets 			break;
8546e173d3bSMartin Habets 		case SCTP_V4_FLOW:
8556e173d3bSMartin Habets 		case SCTP_V6_FLOW:
8566e173d3bSMartin Habets 		case AH_ESP_V4_FLOW:
8576e173d3bSMartin Habets 		case AH_ESP_V6_FLOW:
8586e173d3bSMartin Habets 		case IPV4_FLOW:
8596e173d3bSMartin Habets 		case IPV6_FLOW:
8606e173d3bSMartin Habets 			data = RXH_IP_SRC | RXH_IP_DST;
8616e173d3bSMartin Habets 			break;
8626e173d3bSMartin Habets 		default:
8636e173d3bSMartin Habets 			break;
8646e173d3bSMartin Habets 		}
8656e173d3bSMartin Habets out_setdata_unlock:
8666e173d3bSMartin Habets 		info->data = data;
8676e173d3bSMartin Habets out_unlock:
8686e173d3bSMartin Habets 		mutex_unlock(&efx->rss_lock);
8696e173d3bSMartin Habets 		return rc;
8706e173d3bSMartin Habets 	}
8716e173d3bSMartin Habets 
8726e173d3bSMartin Habets 	case ETHTOOL_GRXCLSRLCNT:
8736e173d3bSMartin Habets 		info->data = efx_filter_get_rx_id_limit(efx);
8746e173d3bSMartin Habets 		if (info->data == 0)
8756e173d3bSMartin Habets 			return -EOPNOTSUPP;
8766e173d3bSMartin Habets 		info->data |= RX_CLS_LOC_SPECIAL;
8776e173d3bSMartin Habets 		info->rule_cnt =
8786e173d3bSMartin Habets 			efx_filter_count_rx_used(efx, EFX_FILTER_PRI_MANUAL);
8796e173d3bSMartin Habets 		return 0;
8806e173d3bSMartin Habets 
8816e173d3bSMartin Habets 	case ETHTOOL_GRXCLSRULE:
8826e173d3bSMartin Habets 		if (efx_filter_get_rx_id_limit(efx) == 0)
8836e173d3bSMartin Habets 			return -EOPNOTSUPP;
8846e173d3bSMartin Habets 		rc = efx_ethtool_get_class_rule(efx, &info->fs, &rss_context);
8856e173d3bSMartin Habets 		if (rc < 0)
8866e173d3bSMartin Habets 			return rc;
8876e173d3bSMartin Habets 		if (info->fs.flow_type & FLOW_RSS)
8886e173d3bSMartin Habets 			info->rss_context = rss_context;
8896e173d3bSMartin Habets 		return 0;
8906e173d3bSMartin Habets 
8916e173d3bSMartin Habets 	case ETHTOOL_GRXCLSRLALL:
8926e173d3bSMartin Habets 		info->data = efx_filter_get_rx_id_limit(efx);
8936e173d3bSMartin Habets 		if (info->data == 0)
8946e173d3bSMartin Habets 			return -EOPNOTSUPP;
8956e173d3bSMartin Habets 		rc = efx_filter_get_rx_ids(efx, EFX_FILTER_PRI_MANUAL,
8966e173d3bSMartin Habets 					   rule_locs, info->rule_cnt);
8976e173d3bSMartin Habets 		if (rc < 0)
8986e173d3bSMartin Habets 			return rc;
8996e173d3bSMartin Habets 		info->rule_cnt = rc;
9006e173d3bSMartin Habets 		return 0;
9016e173d3bSMartin Habets 
9026e173d3bSMartin Habets 	default:
9036e173d3bSMartin Habets 		return -EOPNOTSUPP;
9046e173d3bSMartin Habets 	}
9056e173d3bSMartin Habets }
9066e173d3bSMartin Habets 
9076e173d3bSMartin Habets static inline bool ip6_mask_is_full(__be32 mask[4])
9086e173d3bSMartin Habets {
9096e173d3bSMartin Habets 	return !~(mask[0] & mask[1] & mask[2] & mask[3]);
9106e173d3bSMartin Habets }
9116e173d3bSMartin Habets 
9126e173d3bSMartin Habets static inline bool ip6_mask_is_empty(__be32 mask[4])
9136e173d3bSMartin Habets {
9146e173d3bSMartin Habets 	return !(mask[0] | mask[1] | mask[2] | mask[3]);
9156e173d3bSMartin Habets }
9166e173d3bSMartin Habets 
9176e173d3bSMartin Habets static int efx_ethtool_set_class_rule(struct efx_nic *efx,
9186e173d3bSMartin Habets 				      struct ethtool_rx_flow_spec *rule,
9196e173d3bSMartin Habets 				      u32 rss_context)
9206e173d3bSMartin Habets {
9216e173d3bSMartin Habets 	struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
9226e173d3bSMartin Habets 	struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
9236e173d3bSMartin Habets 	struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
9246e173d3bSMartin Habets 	struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
9256e173d3bSMartin Habets 	struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
9266e173d3bSMartin Habets 	struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
9276e173d3bSMartin Habets 	struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
9286e173d3bSMartin Habets 	struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
9296e173d3bSMartin Habets 	u32 flow_type = rule->flow_type & ~(FLOW_EXT | FLOW_RSS);
9306e173d3bSMartin Habets 	struct ethhdr *mac_entry = &rule->h_u.ether_spec;
9316e173d3bSMartin Habets 	struct ethhdr *mac_mask = &rule->m_u.ether_spec;
9326e173d3bSMartin Habets 	enum efx_filter_flags flags = 0;
9336e173d3bSMartin Habets 	struct efx_filter_spec spec;
9346e173d3bSMartin Habets 	int rc;
9356e173d3bSMartin Habets 
9366e173d3bSMartin Habets 	/* Check that user wants us to choose the location */
9376e173d3bSMartin Habets 	if (rule->location != RX_CLS_LOC_ANY)
9386e173d3bSMartin Habets 		return -EINVAL;
9396e173d3bSMartin Habets 
9406e173d3bSMartin Habets 	/* Range-check ring_cookie */
9416e173d3bSMartin Habets 	if (rule->ring_cookie >= efx->n_rx_channels &&
9426e173d3bSMartin Habets 	    rule->ring_cookie != RX_CLS_FLOW_DISC)
9436e173d3bSMartin Habets 		return -EINVAL;
9446e173d3bSMartin Habets 
9456e173d3bSMartin Habets 	/* Check for unsupported extensions */
9466e173d3bSMartin Habets 	if ((rule->flow_type & FLOW_EXT) &&
9476e173d3bSMartin Habets 	    (rule->m_ext.vlan_etype || rule->m_ext.data[0] ||
9486e173d3bSMartin Habets 	     rule->m_ext.data[1]))
9496e173d3bSMartin Habets 		return -EINVAL;
9506e173d3bSMartin Habets 
9516e173d3bSMartin Habets 	if (efx->rx_scatter)
9526e173d3bSMartin Habets 		flags |= EFX_FILTER_FLAG_RX_SCATTER;
9536e173d3bSMartin Habets 	if (rule->flow_type & FLOW_RSS)
9546e173d3bSMartin Habets 		flags |= EFX_FILTER_FLAG_RX_RSS;
9556e173d3bSMartin Habets 
9566e173d3bSMartin Habets 	efx_filter_init_rx(&spec, EFX_FILTER_PRI_MANUAL, flags,
9576e173d3bSMartin Habets 			   (rule->ring_cookie == RX_CLS_FLOW_DISC) ?
9586e173d3bSMartin Habets 			   EFX_FILTER_RX_DMAQ_ID_DROP : rule->ring_cookie);
9596e173d3bSMartin Habets 
9606e173d3bSMartin Habets 	if (rule->flow_type & FLOW_RSS)
9616e173d3bSMartin Habets 		spec.rss_context = rss_context;
9626e173d3bSMartin Habets 
9636e173d3bSMartin Habets 	switch (flow_type) {
9646e173d3bSMartin Habets 	case TCP_V4_FLOW:
9656e173d3bSMartin Habets 	case UDP_V4_FLOW:
9666e173d3bSMartin Habets 		spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
9676e173d3bSMartin Habets 				    EFX_FILTER_MATCH_IP_PROTO);
9686e173d3bSMartin Habets 		spec.ether_type = htons(ETH_P_IP);
9696e173d3bSMartin Habets 		spec.ip_proto = flow_type == TCP_V4_FLOW ? IPPROTO_TCP
9706e173d3bSMartin Habets 							 : IPPROTO_UDP;
9716e173d3bSMartin Habets 		if (ip_mask->ip4dst) {
9726e173d3bSMartin Habets 			if (ip_mask->ip4dst != IP4_ADDR_FULL_MASK)
9736e173d3bSMartin Habets 				return -EINVAL;
9746e173d3bSMartin Habets 			spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
9756e173d3bSMartin Habets 			spec.loc_host[0] = ip_entry->ip4dst;
9766e173d3bSMartin Habets 		}
9776e173d3bSMartin Habets 		if (ip_mask->ip4src) {
9786e173d3bSMartin Habets 			if (ip_mask->ip4src != IP4_ADDR_FULL_MASK)
9796e173d3bSMartin Habets 				return -EINVAL;
9806e173d3bSMartin Habets 			spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
9816e173d3bSMartin Habets 			spec.rem_host[0] = ip_entry->ip4src;
9826e173d3bSMartin Habets 		}
9836e173d3bSMartin Habets 		if (ip_mask->pdst) {
9846e173d3bSMartin Habets 			if (ip_mask->pdst != PORT_FULL_MASK)
9856e173d3bSMartin Habets 				return -EINVAL;
9866e173d3bSMartin Habets 			spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
9876e173d3bSMartin Habets 			spec.loc_port = ip_entry->pdst;
9886e173d3bSMartin Habets 		}
9896e173d3bSMartin Habets 		if (ip_mask->psrc) {
9906e173d3bSMartin Habets 			if (ip_mask->psrc != PORT_FULL_MASK)
9916e173d3bSMartin Habets 				return -EINVAL;
9926e173d3bSMartin Habets 			spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
9936e173d3bSMartin Habets 			spec.rem_port = ip_entry->psrc;
9946e173d3bSMartin Habets 		}
9956e173d3bSMartin Habets 		if (ip_mask->tos)
9966e173d3bSMartin Habets 			return -EINVAL;
9976e173d3bSMartin Habets 		break;
9986e173d3bSMartin Habets 
9996e173d3bSMartin Habets 	case TCP_V6_FLOW:
10006e173d3bSMartin Habets 	case UDP_V6_FLOW:
10016e173d3bSMartin Habets 		spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
10026e173d3bSMartin Habets 				    EFX_FILTER_MATCH_IP_PROTO);
10036e173d3bSMartin Habets 		spec.ether_type = htons(ETH_P_IPV6);
10046e173d3bSMartin Habets 		spec.ip_proto = flow_type == TCP_V6_FLOW ? IPPROTO_TCP
10056e173d3bSMartin Habets 							 : IPPROTO_UDP;
10066e173d3bSMartin Habets 		if (!ip6_mask_is_empty(ip6_mask->ip6dst)) {
10076e173d3bSMartin Habets 			if (!ip6_mask_is_full(ip6_mask->ip6dst))
10086e173d3bSMartin Habets 				return -EINVAL;
10096e173d3bSMartin Habets 			spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
10106e173d3bSMartin Habets 			memcpy(spec.loc_host, ip6_entry->ip6dst, sizeof(spec.loc_host));
10116e173d3bSMartin Habets 		}
10126e173d3bSMartin Habets 		if (!ip6_mask_is_empty(ip6_mask->ip6src)) {
10136e173d3bSMartin Habets 			if (!ip6_mask_is_full(ip6_mask->ip6src))
10146e173d3bSMartin Habets 				return -EINVAL;
10156e173d3bSMartin Habets 			spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
10166e173d3bSMartin Habets 			memcpy(spec.rem_host, ip6_entry->ip6src, sizeof(spec.rem_host));
10176e173d3bSMartin Habets 		}
10186e173d3bSMartin Habets 		if (ip6_mask->pdst) {
10196e173d3bSMartin Habets 			if (ip6_mask->pdst != PORT_FULL_MASK)
10206e173d3bSMartin Habets 				return -EINVAL;
10216e173d3bSMartin Habets 			spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
10226e173d3bSMartin Habets 			spec.loc_port = ip6_entry->pdst;
10236e173d3bSMartin Habets 		}
10246e173d3bSMartin Habets 		if (ip6_mask->psrc) {
10256e173d3bSMartin Habets 			if (ip6_mask->psrc != PORT_FULL_MASK)
10266e173d3bSMartin Habets 				return -EINVAL;
10276e173d3bSMartin Habets 			spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
10286e173d3bSMartin Habets 			spec.rem_port = ip6_entry->psrc;
10296e173d3bSMartin Habets 		}
10306e173d3bSMartin Habets 		if (ip6_mask->tclass)
10316e173d3bSMartin Habets 			return -EINVAL;
10326e173d3bSMartin Habets 		break;
10336e173d3bSMartin Habets 
10346e173d3bSMartin Habets 	case IPV4_USER_FLOW:
10356e173d3bSMartin Habets 		if (uip_mask->l4_4_bytes || uip_mask->tos || uip_mask->ip_ver ||
10366e173d3bSMartin Habets 		    uip_entry->ip_ver != ETH_RX_NFC_IP4)
10376e173d3bSMartin Habets 			return -EINVAL;
10386e173d3bSMartin Habets 		spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE;
10396e173d3bSMartin Habets 		spec.ether_type = htons(ETH_P_IP);
10406e173d3bSMartin Habets 		if (uip_mask->ip4dst) {
10416e173d3bSMartin Habets 			if (uip_mask->ip4dst != IP4_ADDR_FULL_MASK)
10426e173d3bSMartin Habets 				return -EINVAL;
10436e173d3bSMartin Habets 			spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
10446e173d3bSMartin Habets 			spec.loc_host[0] = uip_entry->ip4dst;
10456e173d3bSMartin Habets 		}
10466e173d3bSMartin Habets 		if (uip_mask->ip4src) {
10476e173d3bSMartin Habets 			if (uip_mask->ip4src != IP4_ADDR_FULL_MASK)
10486e173d3bSMartin Habets 				return -EINVAL;
10496e173d3bSMartin Habets 			spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
10506e173d3bSMartin Habets 			spec.rem_host[0] = uip_entry->ip4src;
10516e173d3bSMartin Habets 		}
10526e173d3bSMartin Habets 		if (uip_mask->proto) {
10536e173d3bSMartin Habets 			if (uip_mask->proto != IP_PROTO_FULL_MASK)
10546e173d3bSMartin Habets 				return -EINVAL;
10556e173d3bSMartin Habets 			spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO;
10566e173d3bSMartin Habets 			spec.ip_proto = uip_entry->proto;
10576e173d3bSMartin Habets 		}
10586e173d3bSMartin Habets 		break;
10596e173d3bSMartin Habets 
10606e173d3bSMartin Habets 	case IPV6_USER_FLOW:
10616e173d3bSMartin Habets 		if (uip6_mask->l4_4_bytes || uip6_mask->tclass)
10626e173d3bSMartin Habets 			return -EINVAL;
10636e173d3bSMartin Habets 		spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE;
10646e173d3bSMartin Habets 		spec.ether_type = htons(ETH_P_IPV6);
10656e173d3bSMartin Habets 		if (!ip6_mask_is_empty(uip6_mask->ip6dst)) {
10666e173d3bSMartin Habets 			if (!ip6_mask_is_full(uip6_mask->ip6dst))
10676e173d3bSMartin Habets 				return -EINVAL;
10686e173d3bSMartin Habets 			spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
10696e173d3bSMartin Habets 			memcpy(spec.loc_host, uip6_entry->ip6dst, sizeof(spec.loc_host));
10706e173d3bSMartin Habets 		}
10716e173d3bSMartin Habets 		if (!ip6_mask_is_empty(uip6_mask->ip6src)) {
10726e173d3bSMartin Habets 			if (!ip6_mask_is_full(uip6_mask->ip6src))
10736e173d3bSMartin Habets 				return -EINVAL;
10746e173d3bSMartin Habets 			spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
10756e173d3bSMartin Habets 			memcpy(spec.rem_host, uip6_entry->ip6src, sizeof(spec.rem_host));
10766e173d3bSMartin Habets 		}
10776e173d3bSMartin Habets 		if (uip6_mask->l4_proto) {
10786e173d3bSMartin Habets 			if (uip6_mask->l4_proto != IP_PROTO_FULL_MASK)
10796e173d3bSMartin Habets 				return -EINVAL;
10806e173d3bSMartin Habets 			spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO;
10816e173d3bSMartin Habets 			spec.ip_proto = uip6_entry->l4_proto;
10826e173d3bSMartin Habets 		}
10836e173d3bSMartin Habets 		break;
10846e173d3bSMartin Habets 
10856e173d3bSMartin Habets 	case ETHER_FLOW:
10866e173d3bSMartin Habets 		if (!is_zero_ether_addr(mac_mask->h_dest)) {
10876e173d3bSMartin Habets 			if (ether_addr_equal(mac_mask->h_dest,
10886e173d3bSMartin Habets 					     mac_addr_ig_mask))
10896e173d3bSMartin Habets 				spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC_IG;
10906e173d3bSMartin Habets 			else if (is_broadcast_ether_addr(mac_mask->h_dest))
10916e173d3bSMartin Habets 				spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC;
10926e173d3bSMartin Habets 			else
10936e173d3bSMartin Habets 				return -EINVAL;
10946e173d3bSMartin Habets 			ether_addr_copy(spec.loc_mac, mac_entry->h_dest);
10956e173d3bSMartin Habets 		}
10966e173d3bSMartin Habets 		if (!is_zero_ether_addr(mac_mask->h_source)) {
10976e173d3bSMartin Habets 			if (!is_broadcast_ether_addr(mac_mask->h_source))
10986e173d3bSMartin Habets 				return -EINVAL;
10996e173d3bSMartin Habets 			spec.match_flags |= EFX_FILTER_MATCH_REM_MAC;
11006e173d3bSMartin Habets 			ether_addr_copy(spec.rem_mac, mac_entry->h_source);
11016e173d3bSMartin Habets 		}
11026e173d3bSMartin Habets 		if (mac_mask->h_proto) {
11036e173d3bSMartin Habets 			if (mac_mask->h_proto != ETHER_TYPE_FULL_MASK)
11046e173d3bSMartin Habets 				return -EINVAL;
11056e173d3bSMartin Habets 			spec.match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
11066e173d3bSMartin Habets 			spec.ether_type = mac_entry->h_proto;
11076e173d3bSMartin Habets 		}
11086e173d3bSMartin Habets 		break;
11096e173d3bSMartin Habets 
11106e173d3bSMartin Habets 	default:
11116e173d3bSMartin Habets 		return -EINVAL;
11126e173d3bSMartin Habets 	}
11136e173d3bSMartin Habets 
11146e173d3bSMartin Habets 	if ((rule->flow_type & FLOW_EXT) && rule->m_ext.vlan_tci) {
11156e173d3bSMartin Habets 		if (rule->m_ext.vlan_tci != htons(0xfff))
11166e173d3bSMartin Habets 			return -EINVAL;
11176e173d3bSMartin Habets 		spec.match_flags |= EFX_FILTER_MATCH_OUTER_VID;
11186e173d3bSMartin Habets 		spec.outer_vid = rule->h_ext.vlan_tci;
11196e173d3bSMartin Habets 	}
11206e173d3bSMartin Habets 
11216e173d3bSMartin Habets 	rc = efx_filter_insert_filter(efx, &spec, true);
11226e173d3bSMartin Habets 	if (rc < 0)
11236e173d3bSMartin Habets 		return rc;
11246e173d3bSMartin Habets 
11256e173d3bSMartin Habets 	rule->location = rc;
11266e173d3bSMartin Habets 	return 0;
11276e173d3bSMartin Habets }
11286e173d3bSMartin Habets 
1129*95e96f77SMartin Habets int efx_siena_ethtool_set_rxnfc(struct net_device *net_dev,
11306e173d3bSMartin Habets 				struct ethtool_rxnfc *info)
11316e173d3bSMartin Habets {
11326e173d3bSMartin Habets 	struct efx_nic *efx = netdev_priv(net_dev);
11336e173d3bSMartin Habets 
11346e173d3bSMartin Habets 	if (efx_filter_get_rx_id_limit(efx) == 0)
11356e173d3bSMartin Habets 		return -EOPNOTSUPP;
11366e173d3bSMartin Habets 
11376e173d3bSMartin Habets 	switch (info->cmd) {
11386e173d3bSMartin Habets 	case ETHTOOL_SRXCLSRLINS:
11396e173d3bSMartin Habets 		return efx_ethtool_set_class_rule(efx, &info->fs,
11406e173d3bSMartin Habets 						  info->rss_context);
11416e173d3bSMartin Habets 
11426e173d3bSMartin Habets 	case ETHTOOL_SRXCLSRLDEL:
11436e173d3bSMartin Habets 		return efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_MANUAL,
11446e173d3bSMartin Habets 						 info->fs.location);
11456e173d3bSMartin Habets 
11466e173d3bSMartin Habets 	default:
11476e173d3bSMartin Habets 		return -EOPNOTSUPP;
11486e173d3bSMartin Habets 	}
11496e173d3bSMartin Habets }
11506e173d3bSMartin Habets 
1151*95e96f77SMartin Habets u32 efx_siena_ethtool_get_rxfh_indir_size(struct net_device *net_dev)
11526e173d3bSMartin Habets {
11536e173d3bSMartin Habets 	struct efx_nic *efx = netdev_priv(net_dev);
11546e173d3bSMartin Habets 
11556e173d3bSMartin Habets 	if (efx->n_rx_channels == 1)
11566e173d3bSMartin Habets 		return 0;
11576e173d3bSMartin Habets 	return ARRAY_SIZE(efx->rss_context.rx_indir_table);
11586e173d3bSMartin Habets }
11596e173d3bSMartin Habets 
1160*95e96f77SMartin Habets u32 efx_siena_ethtool_get_rxfh_key_size(struct net_device *net_dev)
11616e173d3bSMartin Habets {
11626e173d3bSMartin Habets 	struct efx_nic *efx = netdev_priv(net_dev);
11636e173d3bSMartin Habets 
11646e173d3bSMartin Habets 	return efx->type->rx_hash_key_size;
11656e173d3bSMartin Habets }
11666e173d3bSMartin Habets 
1167*95e96f77SMartin Habets int efx_siena_ethtool_get_rxfh(struct net_device *net_dev, u32 *indir, u8 *key,
11686e173d3bSMartin Habets 			       u8 *hfunc)
11696e173d3bSMartin Habets {
11706e173d3bSMartin Habets 	struct efx_nic *efx = netdev_priv(net_dev);
11716e173d3bSMartin Habets 	int rc;
11726e173d3bSMartin Habets 
11736e173d3bSMartin Habets 	rc = efx->type->rx_pull_rss_config(efx);
11746e173d3bSMartin Habets 	if (rc)
11756e173d3bSMartin Habets 		return rc;
11766e173d3bSMartin Habets 
11776e173d3bSMartin Habets 	if (hfunc)
11786e173d3bSMartin Habets 		*hfunc = ETH_RSS_HASH_TOP;
11796e173d3bSMartin Habets 	if (indir)
11806e173d3bSMartin Habets 		memcpy(indir, efx->rss_context.rx_indir_table,
11816e173d3bSMartin Habets 		       sizeof(efx->rss_context.rx_indir_table));
11826e173d3bSMartin Habets 	if (key)
11836e173d3bSMartin Habets 		memcpy(key, efx->rss_context.rx_hash_key,
11846e173d3bSMartin Habets 		       efx->type->rx_hash_key_size);
11856e173d3bSMartin Habets 	return 0;
11866e173d3bSMartin Habets }
11876e173d3bSMartin Habets 
1188*95e96f77SMartin Habets int efx_siena_ethtool_set_rxfh(struct net_device *net_dev, const u32 *indir,
11896e173d3bSMartin Habets 			       const u8 *key, const u8 hfunc)
11906e173d3bSMartin Habets {
11916e173d3bSMartin Habets 	struct efx_nic *efx = netdev_priv(net_dev);
11926e173d3bSMartin Habets 
11936e173d3bSMartin Habets 	/* Hash function is Toeplitz, cannot be changed */
11946e173d3bSMartin Habets 	if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
11956e173d3bSMartin Habets 		return -EOPNOTSUPP;
11966e173d3bSMartin Habets 	if (!indir && !key)
11976e173d3bSMartin Habets 		return 0;
11986e173d3bSMartin Habets 
11996e173d3bSMartin Habets 	if (!key)
12006e173d3bSMartin Habets 		key = efx->rss_context.rx_hash_key;
12016e173d3bSMartin Habets 	if (!indir)
12026e173d3bSMartin Habets 		indir = efx->rss_context.rx_indir_table;
12036e173d3bSMartin Habets 
12046e173d3bSMartin Habets 	return efx->type->rx_push_rss_config(efx, true, indir, key);
12056e173d3bSMartin Habets }
12066e173d3bSMartin Habets 
1207*95e96f77SMartin Habets int efx_siena_ethtool_get_rxfh_context(struct net_device *net_dev, u32 *indir,
12086e173d3bSMartin Habets 				       u8 *key, u8 *hfunc, u32 rss_context)
12096e173d3bSMartin Habets {
12106e173d3bSMartin Habets 	struct efx_nic *efx = netdev_priv(net_dev);
12116e173d3bSMartin Habets 	struct efx_rss_context *ctx;
12126e173d3bSMartin Habets 	int rc = 0;
12136e173d3bSMartin Habets 
12146e173d3bSMartin Habets 	if (!efx->type->rx_pull_rss_context_config)
12156e173d3bSMartin Habets 		return -EOPNOTSUPP;
12166e173d3bSMartin Habets 
12176e173d3bSMartin Habets 	mutex_lock(&efx->rss_lock);
12187f9e4b2aSMartin Habets 	ctx = efx_siena_find_rss_context_entry(efx, rss_context);
12196e173d3bSMartin Habets 	if (!ctx) {
12206e173d3bSMartin Habets 		rc = -ENOENT;
12216e173d3bSMartin Habets 		goto out_unlock;
12226e173d3bSMartin Habets 	}
12236e173d3bSMartin Habets 	rc = efx->type->rx_pull_rss_context_config(efx, ctx);
12246e173d3bSMartin Habets 	if (rc)
12256e173d3bSMartin Habets 		goto out_unlock;
12266e173d3bSMartin Habets 
12276e173d3bSMartin Habets 	if (hfunc)
12286e173d3bSMartin Habets 		*hfunc = ETH_RSS_HASH_TOP;
12296e173d3bSMartin Habets 	if (indir)
12306e173d3bSMartin Habets 		memcpy(indir, ctx->rx_indir_table, sizeof(ctx->rx_indir_table));
12316e173d3bSMartin Habets 	if (key)
12326e173d3bSMartin Habets 		memcpy(key, ctx->rx_hash_key, efx->type->rx_hash_key_size);
12336e173d3bSMartin Habets out_unlock:
12346e173d3bSMartin Habets 	mutex_unlock(&efx->rss_lock);
12356e173d3bSMartin Habets 	return rc;
12366e173d3bSMartin Habets }
12376e173d3bSMartin Habets 
1238*95e96f77SMartin Habets int efx_siena_ethtool_set_rxfh_context(struct net_device *net_dev,
12396e173d3bSMartin Habets 				       const u32 *indir, const u8 *key,
12406e173d3bSMartin Habets 				       const u8 hfunc, u32 *rss_context,
12416e173d3bSMartin Habets 				       bool delete)
12426e173d3bSMartin Habets {
12436e173d3bSMartin Habets 	struct efx_nic *efx = netdev_priv(net_dev);
12446e173d3bSMartin Habets 	struct efx_rss_context *ctx;
12456e173d3bSMartin Habets 	bool allocated = false;
12466e173d3bSMartin Habets 	int rc;
12476e173d3bSMartin Habets 
12486e173d3bSMartin Habets 	if (!efx->type->rx_push_rss_context_config)
12496e173d3bSMartin Habets 		return -EOPNOTSUPP;
12506e173d3bSMartin Habets 	/* Hash function is Toeplitz, cannot be changed */
12516e173d3bSMartin Habets 	if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
12526e173d3bSMartin Habets 		return -EOPNOTSUPP;
12536e173d3bSMartin Habets 
12546e173d3bSMartin Habets 	mutex_lock(&efx->rss_lock);
12556e173d3bSMartin Habets 
12566e173d3bSMartin Habets 	if (*rss_context == ETH_RXFH_CONTEXT_ALLOC) {
12576e173d3bSMartin Habets 		if (delete) {
12586e173d3bSMartin Habets 			/* alloc + delete == Nothing to do */
12596e173d3bSMartin Habets 			rc = -EINVAL;
12606e173d3bSMartin Habets 			goto out_unlock;
12616e173d3bSMartin Habets 		}
12627f9e4b2aSMartin Habets 		ctx = efx_siena_alloc_rss_context_entry(efx);
12636e173d3bSMartin Habets 		if (!ctx) {
12646e173d3bSMartin Habets 			rc = -ENOMEM;
12656e173d3bSMartin Habets 			goto out_unlock;
12666e173d3bSMartin Habets 		}
12676e173d3bSMartin Habets 		ctx->context_id = EFX_MCDI_RSS_CONTEXT_INVALID;
12686e173d3bSMartin Habets 		/* Initialise indir table and key to defaults */
12697f9e4b2aSMartin Habets 		efx_siena_set_default_rx_indir_table(efx, ctx);
12706e173d3bSMartin Habets 		netdev_rss_key_fill(ctx->rx_hash_key, sizeof(ctx->rx_hash_key));
12716e173d3bSMartin Habets 		allocated = true;
12726e173d3bSMartin Habets 	} else {
12737f9e4b2aSMartin Habets 		ctx = efx_siena_find_rss_context_entry(efx, *rss_context);
12746e173d3bSMartin Habets 		if (!ctx) {
12756e173d3bSMartin Habets 			rc = -ENOENT;
12766e173d3bSMartin Habets 			goto out_unlock;
12776e173d3bSMartin Habets 		}
12786e173d3bSMartin Habets 	}
12796e173d3bSMartin Habets 
12806e173d3bSMartin Habets 	if (delete) {
12816e173d3bSMartin Habets 		/* delete this context */
12826e173d3bSMartin Habets 		rc = efx->type->rx_push_rss_context_config(efx, ctx, NULL, NULL);
12836e173d3bSMartin Habets 		if (!rc)
12847f9e4b2aSMartin Habets 			efx_siena_free_rss_context_entry(ctx);
12856e173d3bSMartin Habets 		goto out_unlock;
12866e173d3bSMartin Habets 	}
12876e173d3bSMartin Habets 
12886e173d3bSMartin Habets 	if (!key)
12896e173d3bSMartin Habets 		key = ctx->rx_hash_key;
12906e173d3bSMartin Habets 	if (!indir)
12916e173d3bSMartin Habets 		indir = ctx->rx_indir_table;
12926e173d3bSMartin Habets 
12936e173d3bSMartin Habets 	rc = efx->type->rx_push_rss_context_config(efx, ctx, indir, key);
12946e173d3bSMartin Habets 	if (rc && allocated)
12957f9e4b2aSMartin Habets 		efx_siena_free_rss_context_entry(ctx);
12966e173d3bSMartin Habets 	else
12976e173d3bSMartin Habets 		*rss_context = ctx->user_id;
12986e173d3bSMartin Habets out_unlock:
12996e173d3bSMartin Habets 	mutex_unlock(&efx->rss_lock);
13006e173d3bSMartin Habets 	return rc;
13016e173d3bSMartin Habets }
13026e173d3bSMartin Habets 
1303*95e96f77SMartin Habets int efx_siena_ethtool_reset(struct net_device *net_dev, u32 *flags)
13046e173d3bSMartin Habets {
13056e173d3bSMartin Habets 	struct efx_nic *efx = netdev_priv(net_dev);
13066e173d3bSMartin Habets 	int rc;
13076e173d3bSMartin Habets 
13086e173d3bSMartin Habets 	rc = efx->type->map_reset_flags(flags);
13096e173d3bSMartin Habets 	if (rc < 0)
13106e173d3bSMartin Habets 		return rc;
13116e173d3bSMartin Habets 
131271ad88f6SMartin Habets 	return efx_siena_reset(efx, rc);
13136e173d3bSMartin Habets }
13146e173d3bSMartin Habets 
1315*95e96f77SMartin Habets int efx_siena_ethtool_get_module_eeprom(struct net_device *net_dev,
13166e173d3bSMartin Habets 					struct ethtool_eeprom *ee,
13176e173d3bSMartin Habets 					u8 *data)
13186e173d3bSMartin Habets {
13196e173d3bSMartin Habets 	struct efx_nic *efx = netdev_priv(net_dev);
13206e173d3bSMartin Habets 	int ret;
13216e173d3bSMartin Habets 
13226e173d3bSMartin Habets 	mutex_lock(&efx->mac_lock);
13236e173d3bSMartin Habets 	ret = efx_mcdi_phy_get_module_eeprom(efx, ee, data);
13246e173d3bSMartin Habets 	mutex_unlock(&efx->mac_lock);
13256e173d3bSMartin Habets 
13266e173d3bSMartin Habets 	return ret;
13276e173d3bSMartin Habets }
13286e173d3bSMartin Habets 
1329*95e96f77SMartin Habets int efx_siena_ethtool_get_module_info(struct net_device *net_dev,
13306e173d3bSMartin Habets 				      struct ethtool_modinfo *modinfo)
13316e173d3bSMartin Habets {
13326e173d3bSMartin Habets 	struct efx_nic *efx = netdev_priv(net_dev);
13336e173d3bSMartin Habets 	int ret;
13346e173d3bSMartin Habets 
13356e173d3bSMartin Habets 	mutex_lock(&efx->mac_lock);
13366e173d3bSMartin Habets 	ret = efx_mcdi_phy_get_module_info(efx, modinfo);
13376e173d3bSMartin Habets 	mutex_unlock(&efx->mac_lock);
13386e173d3bSMartin Habets 
13396e173d3bSMartin Habets 	return ret;
13406e173d3bSMartin Habets }
1341