Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0-only
  2/****************************************************************************
  3 * Driver for Solarflare network controllers and boards
  4 * Copyright 2005-2006 Fen Systems Ltd.
  5 * Copyright 2006-2013 Solarflare Communications Inc.
  6 */
  7
  8#include <linux/netdevice.h>
  9#include <linux/ethtool.h>
 10#include <linux/rtnetlink.h>
 11#include <linux/in.h>
 12#include "net_driver.h"
 13#include "workarounds.h"
 14#include "selftest.h"
 15#include "efx.h"
 16#include "efx_channels.h"
 17#include "rx_common.h"
 18#include "tx_common.h"
 19#include "ethtool_common.h"
 20#include "filter.h"
 21#include "nic.h"
 22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 23#define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB
 24
 25/**************************************************************************
 26 *
 27 * Ethtool operations
 28 *
 29 **************************************************************************
 30 */
 31
 32/* Identify device by flashing LEDs */
 33static int efx_ethtool_phys_id(struct net_device *net_dev,
 34			       enum ethtool_phys_id_state state)
 35{
 36	struct efx_nic *efx = efx_netdev_priv(net_dev);
 37	enum efx_led_mode mode = EFX_LED_DEFAULT;
 38
 39	switch (state) {
 40	case ETHTOOL_ID_ON:
 41		mode = EFX_LED_ON;
 42		break;
 43	case ETHTOOL_ID_OFF:
 44		mode = EFX_LED_OFF;
 45		break;
 46	case ETHTOOL_ID_INACTIVE:
 47		mode = EFX_LED_DEFAULT;
 48		break;
 49	case ETHTOOL_ID_ACTIVE:
 50		return 1;	/* cycle on/off once per second */
 51	}
 52
 53	return efx_mcdi_set_id_led(efx, mode);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 54}
 55
 56static int efx_ethtool_get_regs_len(struct net_device *net_dev)
 57{
 58	return efx_nic_get_regs_len(efx_netdev_priv(net_dev));
 59}
 60
 61static void efx_ethtool_get_regs(struct net_device *net_dev,
 62				 struct ethtool_regs *regs, void *buf)
 63{
 64	struct efx_nic *efx = efx_netdev_priv(net_dev);
 65
 66	regs->version = efx->type->revision;
 67	efx_nic_get_regs(efx, buf);
 68}
 69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 70/*
 71 * Each channel has a single IRQ and moderation timer, started by any
 72 * completion (or other event).  Unless the module parameter
 73 * separate_tx_channels is set, IRQs and moderation are therefore
 74 * shared between RX and TX completions.  In this case, when RX IRQ
 75 * moderation is explicitly changed then TX IRQ moderation is
 76 * automatically changed too, but otherwise we fail if the two values
 77 * are requested to be different.
 78 *
 79 * The hardware does not support a limit on the number of completions
 80 * before an IRQ, so we do not use the max_frames fields.  We should
 81 * report and require that max_frames == (usecs != 0), but this would
 82 * invalidate existing user documentation.
 83 *
 84 * The hardware does not have distinct settings for interrupt
 85 * moderation while the previous IRQ is being handled, so we should
 86 * not use the 'irq' fields.  However, an earlier developer
 87 * misunderstood the meaning of the 'irq' fields and the driver did
 88 * not support the standard fields.  To avoid invalidating existing
 89 * user documentation, we report and accept changes through either the
 90 * standard or 'irq' fields.  If both are changed at the same time, we
 91 * prefer the standard field.
 92 *
 93 * We implement adaptive IRQ moderation, but use a different algorithm
 94 * from that assumed in the definition of struct ethtool_coalesce.
 95 * Therefore we do not use any of the adaptive moderation parameters
 96 * in it.
 97 */
 98
 99static int efx_ethtool_get_coalesce(struct net_device *net_dev,
100				    struct ethtool_coalesce *coalesce,
101				    struct kernel_ethtool_coalesce *kernel_coal,
102				    struct netlink_ext_ack *extack)
103{
104	struct efx_nic *efx = efx_netdev_priv(net_dev);
105	unsigned int tx_usecs, rx_usecs;
106	bool rx_adaptive;
107
108	efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &rx_adaptive);
109
110	coalesce->tx_coalesce_usecs = tx_usecs;
111	coalesce->tx_coalesce_usecs_irq = tx_usecs;
112	coalesce->rx_coalesce_usecs = rx_usecs;
113	coalesce->rx_coalesce_usecs_irq = rx_usecs;
114	coalesce->use_adaptive_rx_coalesce = rx_adaptive;
115
116	return 0;
117}
118
119static int efx_ethtool_set_coalesce(struct net_device *net_dev,
120				    struct ethtool_coalesce *coalesce,
121				    struct kernel_ethtool_coalesce *kernel_coal,
122				    struct netlink_ext_ack *extack)
123{
124	struct efx_nic *efx = efx_netdev_priv(net_dev);
125	struct efx_channel *channel;
126	unsigned int tx_usecs, rx_usecs;
127	bool adaptive, rx_may_override_tx;
128	int rc;
129
 
 
 
130	efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &adaptive);
131
132	if (coalesce->rx_coalesce_usecs != rx_usecs)
133		rx_usecs = coalesce->rx_coalesce_usecs;
134	else
135		rx_usecs = coalesce->rx_coalesce_usecs_irq;
136
137	adaptive = coalesce->use_adaptive_rx_coalesce;
138
139	/* If channels are shared, TX IRQ moderation can be quietly
140	 * overridden unless it is changed from its old value.
141	 */
142	rx_may_override_tx = (coalesce->tx_coalesce_usecs == tx_usecs &&
143			      coalesce->tx_coalesce_usecs_irq == tx_usecs);
144	if (coalesce->tx_coalesce_usecs != tx_usecs)
145		tx_usecs = coalesce->tx_coalesce_usecs;
146	else
147		tx_usecs = coalesce->tx_coalesce_usecs_irq;
148
149	rc = efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive,
150				     rx_may_override_tx);
151	if (rc != 0)
152		return rc;
153
154	efx_for_each_channel(channel, efx)
155		efx->type->push_irq_moderation(channel);
156
157	return 0;
158}
159
160static void
161efx_ethtool_get_ringparam(struct net_device *net_dev,
162			  struct ethtool_ringparam *ring,
163			  struct kernel_ethtool_ringparam *kernel_ring,
164			  struct netlink_ext_ack *extack)
165{
166	struct efx_nic *efx = efx_netdev_priv(net_dev);
167
168	ring->rx_max_pending = EFX_MAX_DMAQ_SIZE;
169	ring->tx_max_pending = EFX_TXQ_MAX_ENT(efx);
170	ring->rx_pending = efx->rxq_entries;
171	ring->tx_pending = efx->txq_entries;
172}
173
174static int
175efx_ethtool_set_ringparam(struct net_device *net_dev,
176			  struct ethtool_ringparam *ring,
177			  struct kernel_ethtool_ringparam *kernel_ring,
178			  struct netlink_ext_ack *extack)
179{
180	struct efx_nic *efx = efx_netdev_priv(net_dev);
181	u32 txq_entries;
182
183	if (ring->rx_mini_pending || ring->rx_jumbo_pending ||
184	    ring->rx_pending > EFX_MAX_DMAQ_SIZE ||
185	    ring->tx_pending > EFX_TXQ_MAX_ENT(efx))
186		return -EINVAL;
187
188	if (ring->rx_pending < EFX_RXQ_MIN_ENT) {
189		netif_err(efx, drv, efx->net_dev,
190			  "RX queues cannot be smaller than %u\n",
191			  EFX_RXQ_MIN_ENT);
192		return -EINVAL;
193	}
194
195	txq_entries = max(ring->tx_pending, EFX_TXQ_MIN_ENT(efx));
196	if (txq_entries != ring->tx_pending)
197		netif_warn(efx, drv, efx->net_dev,
198			   "increasing TX queue size to minimum of %u\n",
199			   txq_entries);
200
201	return efx_realloc_channels(efx, ring->rx_pending, txq_entries);
202}
203
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204static void efx_ethtool_get_wol(struct net_device *net_dev,
205				struct ethtool_wolinfo *wol)
206{
207	struct efx_nic *efx = efx_netdev_priv(net_dev);
208	return efx->type->get_wol(efx, wol);
209}
210
211
212static int efx_ethtool_set_wol(struct net_device *net_dev,
213			       struct ethtool_wolinfo *wol)
214{
215	struct efx_nic *efx = efx_netdev_priv(net_dev);
216	return efx->type->set_wol(efx, wol->wolopts);
217}
218
219static void efx_ethtool_get_fec_stats(struct net_device *net_dev,
220				      struct ethtool_fec_stats *fec_stats)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221{
222	struct efx_nic *efx = efx_netdev_priv(net_dev);
 
223
224	if (efx->type->get_fec_stats)
225		efx->type->get_fec_stats(efx, fec_stats);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226}
227
228static int efx_ethtool_get_ts_info(struct net_device *net_dev,
229				   struct ethtool_ts_info *ts_info)
230{
231	struct efx_nic *efx = efx_netdev_priv(net_dev);
232
233	/* Software capabilities */
234	ts_info->so_timestamping = (SOF_TIMESTAMPING_RX_SOFTWARE |
235				    SOF_TIMESTAMPING_SOFTWARE);
236	ts_info->phc_index = -1;
237
238	efx_ptp_get_ts_info(efx, ts_info);
239	return 0;
240}
241
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242const struct ethtool_ops efx_ethtool_ops = {
243	.cap_rss_ctx_supported	= true,
244	.supported_coalesce_params = ETHTOOL_COALESCE_USECS |
245				     ETHTOOL_COALESCE_USECS_IRQ |
246				     ETHTOOL_COALESCE_USE_ADAPTIVE_RX,
247	.get_drvinfo		= efx_ethtool_get_drvinfo,
248	.get_regs_len		= efx_ethtool_get_regs_len,
249	.get_regs		= efx_ethtool_get_regs,
250	.get_msglevel		= efx_ethtool_get_msglevel,
251	.set_msglevel		= efx_ethtool_set_msglevel,
 
252	.get_link		= ethtool_op_get_link,
253	.get_coalesce		= efx_ethtool_get_coalesce,
254	.set_coalesce		= efx_ethtool_set_coalesce,
255	.get_ringparam		= efx_ethtool_get_ringparam,
256	.set_ringparam		= efx_ethtool_set_ringparam,
257	.get_pauseparam         = efx_ethtool_get_pauseparam,
258	.set_pauseparam         = efx_ethtool_set_pauseparam,
259	.get_sset_count		= efx_ethtool_get_sset_count,
260	.self_test		= efx_ethtool_self_test,
261	.get_strings		= efx_ethtool_get_strings,
262	.set_phys_id		= efx_ethtool_phys_id,
263	.get_ethtool_stats	= efx_ethtool_get_stats,
264	.get_wol                = efx_ethtool_get_wol,
265	.set_wol                = efx_ethtool_set_wol,
266	.reset			= efx_ethtool_reset,
267	.get_rxnfc		= efx_ethtool_get_rxnfc,
268	.set_rxnfc		= efx_ethtool_set_rxnfc,
269	.get_rxfh_indir_size	= efx_ethtool_get_rxfh_indir_size,
270	.get_rxfh_key_size	= efx_ethtool_get_rxfh_key_size,
271	.get_rxfh		= efx_ethtool_get_rxfh,
272	.set_rxfh		= efx_ethtool_set_rxfh,
 
 
273	.get_ts_info		= efx_ethtool_get_ts_info,
274	.get_module_info	= efx_ethtool_get_module_info,
275	.get_module_eeprom	= efx_ethtool_get_module_eeprom,
276	.get_link_ksettings	= efx_ethtool_get_link_ksettings,
277	.set_link_ksettings	= efx_ethtool_set_link_ksettings,
278	.get_fec_stats		= efx_ethtool_get_fec_stats,
279	.get_fecparam		= efx_ethtool_get_fecparam,
280	.set_fecparam		= efx_ethtool_set_fecparam,
281};
v5.4
   1// SPDX-License-Identifier: GPL-2.0-only
   2/****************************************************************************
   3 * Driver for Solarflare network controllers and boards
   4 * Copyright 2005-2006 Fen Systems Ltd.
   5 * Copyright 2006-2013 Solarflare Communications Inc.
   6 */
   7
   8#include <linux/netdevice.h>
   9#include <linux/ethtool.h>
  10#include <linux/rtnetlink.h>
  11#include <linux/in.h>
  12#include "net_driver.h"
  13#include "workarounds.h"
  14#include "selftest.h"
  15#include "efx.h"
 
 
 
 
  16#include "filter.h"
  17#include "nic.h"
  18
  19struct efx_sw_stat_desc {
  20	const char *name;
  21	enum {
  22		EFX_ETHTOOL_STAT_SOURCE_nic,
  23		EFX_ETHTOOL_STAT_SOURCE_channel,
  24		EFX_ETHTOOL_STAT_SOURCE_tx_queue
  25	} source;
  26	unsigned offset;
  27	u64(*get_stat) (void *field); /* Reader function */
  28};
  29
  30/* Initialiser for a struct efx_sw_stat_desc with type-checking */
  31#define EFX_ETHTOOL_STAT(stat_name, source_name, field, field_type, \
  32				get_stat_function) {			\
  33	.name = #stat_name,						\
  34	.source = EFX_ETHTOOL_STAT_SOURCE_##source_name,		\
  35	.offset = ((((field_type *) 0) ==				\
  36		      &((struct efx_##source_name *)0)->field) ?	\
  37		    offsetof(struct efx_##source_name, field) :		\
  38		    offsetof(struct efx_##source_name, field)),		\
  39	.get_stat = get_stat_function,					\
  40}
  41
  42static u64 efx_get_uint_stat(void *field)
  43{
  44	return *(unsigned int *)field;
  45}
  46
  47static u64 efx_get_atomic_stat(void *field)
  48{
  49	return atomic_read((atomic_t *) field);
  50}
  51
  52#define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field)		\
  53	EFX_ETHTOOL_STAT(field, nic, field,			\
  54			 atomic_t, efx_get_atomic_stat)
  55
  56#define EFX_ETHTOOL_UINT_CHANNEL_STAT(field)			\
  57	EFX_ETHTOOL_STAT(field, channel, n_##field,		\
  58			 unsigned int, efx_get_uint_stat)
  59
  60#define EFX_ETHTOOL_UINT_TXQ_STAT(field)			\
  61	EFX_ETHTOOL_STAT(tx_##field, tx_queue, field,		\
  62			 unsigned int, efx_get_uint_stat)
  63
  64static const struct efx_sw_stat_desc efx_sw_stat_desc[] = {
  65	EFX_ETHTOOL_UINT_TXQ_STAT(merge_events),
  66	EFX_ETHTOOL_UINT_TXQ_STAT(tso_bursts),
  67	EFX_ETHTOOL_UINT_TXQ_STAT(tso_long_headers),
  68	EFX_ETHTOOL_UINT_TXQ_STAT(tso_packets),
  69	EFX_ETHTOOL_UINT_TXQ_STAT(tso_fallbacks),
  70	EFX_ETHTOOL_UINT_TXQ_STAT(pushes),
  71	EFX_ETHTOOL_UINT_TXQ_STAT(pio_packets),
  72	EFX_ETHTOOL_UINT_TXQ_STAT(cb_packets),
  73	EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset),
  74	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc),
  75	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),
  76	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err),
  77	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_inner_ip_hdr_chksum_err),
  78	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_inner_tcp_udp_chksum_err),
  79	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_outer_ip_hdr_chksum_err),
  80	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_outer_tcp_udp_chksum_err),
  81	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_eth_crc_err),
  82	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch),
  83	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
  84	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_events),
  85	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_packets),
  86};
  87
  88#define EFX_ETHTOOL_SW_STAT_COUNT ARRAY_SIZE(efx_sw_stat_desc)
  89
  90#define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB
  91
  92/**************************************************************************
  93 *
  94 * Ethtool operations
  95 *
  96 **************************************************************************
  97 */
  98
  99/* Identify device by flashing LEDs */
 100static int efx_ethtool_phys_id(struct net_device *net_dev,
 101			       enum ethtool_phys_id_state state)
 102{
 103	struct efx_nic *efx = netdev_priv(net_dev);
 104	enum efx_led_mode mode = EFX_LED_DEFAULT;
 105
 106	switch (state) {
 107	case ETHTOOL_ID_ON:
 108		mode = EFX_LED_ON;
 109		break;
 110	case ETHTOOL_ID_OFF:
 111		mode = EFX_LED_OFF;
 112		break;
 113	case ETHTOOL_ID_INACTIVE:
 114		mode = EFX_LED_DEFAULT;
 115		break;
 116	case ETHTOOL_ID_ACTIVE:
 117		return 1;	/* cycle on/off once per second */
 118	}
 119
 120	efx->type->set_id_led(efx, mode);
 121	return 0;
 122}
 123
 124/* This must be called with rtnl_lock held. */
 125static int
 126efx_ethtool_get_link_ksettings(struct net_device *net_dev,
 127			       struct ethtool_link_ksettings *cmd)
 128{
 129	struct efx_nic *efx = netdev_priv(net_dev);
 130	struct efx_link_state *link_state = &efx->link_state;
 131	u32 supported;
 132
 133	mutex_lock(&efx->mac_lock);
 134	efx->phy_op->get_link_ksettings(efx, cmd);
 135	mutex_unlock(&efx->mac_lock);
 136
 137	/* Both MACs support pause frames (bidirectional and respond-only) */
 138	ethtool_convert_link_mode_to_legacy_u32(&supported,
 139						cmd->link_modes.supported);
 140
 141	supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
 142
 143	ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
 144						supported);
 145
 146	if (LOOPBACK_INTERNAL(efx)) {
 147		cmd->base.speed = link_state->speed;
 148		cmd->base.duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF;
 149	}
 150
 151	return 0;
 152}
 153
 154/* This must be called with rtnl_lock held. */
 155static int
 156efx_ethtool_set_link_ksettings(struct net_device *net_dev,
 157			       const struct ethtool_link_ksettings *cmd)
 158{
 159	struct efx_nic *efx = netdev_priv(net_dev);
 160	int rc;
 161
 162	/* GMAC does not support 1000Mbps HD */
 163	if ((cmd->base.speed == SPEED_1000) &&
 164	    (cmd->base.duplex != DUPLEX_FULL)) {
 165		netif_dbg(efx, drv, efx->net_dev,
 166			  "rejecting unsupported 1000Mbps HD setting\n");
 167		return -EINVAL;
 168	}
 169
 170	mutex_lock(&efx->mac_lock);
 171	rc = efx->phy_op->set_link_ksettings(efx, cmd);
 172	mutex_unlock(&efx->mac_lock);
 173	return rc;
 174}
 175
 176static void efx_ethtool_get_drvinfo(struct net_device *net_dev,
 177				    struct ethtool_drvinfo *info)
 178{
 179	struct efx_nic *efx = netdev_priv(net_dev);
 180
 181	strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
 182	strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version));
 183	efx_mcdi_print_fwver(efx, info->fw_version,
 184			     sizeof(info->fw_version));
 185	strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
 186}
 187
 188static int efx_ethtool_get_regs_len(struct net_device *net_dev)
 189{
 190	return efx_nic_get_regs_len(netdev_priv(net_dev));
 191}
 192
 193static void efx_ethtool_get_regs(struct net_device *net_dev,
 194				 struct ethtool_regs *regs, void *buf)
 195{
 196	struct efx_nic *efx = netdev_priv(net_dev);
 197
 198	regs->version = efx->type->revision;
 199	efx_nic_get_regs(efx, buf);
 200}
 201
 202static u32 efx_ethtool_get_msglevel(struct net_device *net_dev)
 203{
 204	struct efx_nic *efx = netdev_priv(net_dev);
 205	return efx->msg_enable;
 206}
 207
 208static void efx_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable)
 209{
 210	struct efx_nic *efx = netdev_priv(net_dev);
 211	efx->msg_enable = msg_enable;
 212}
 213
 214/**
 215 * efx_fill_test - fill in an individual self-test entry
 216 * @test_index:		Index of the test
 217 * @strings:		Ethtool strings, or %NULL
 218 * @data:		Ethtool test results, or %NULL
 219 * @test:		Pointer to test result (used only if data != %NULL)
 220 * @unit_format:	Unit name format (e.g. "chan\%d")
 221 * @unit_id:		Unit id (e.g. 0 for "chan0")
 222 * @test_format:	Test name format (e.g. "loopback.\%s.tx.sent")
 223 * @test_id:		Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
 224 *
 225 * Fill in an individual self-test entry.
 226 */
 227static void efx_fill_test(unsigned int test_index, u8 *strings, u64 *data,
 228			  int *test, const char *unit_format, int unit_id,
 229			  const char *test_format, const char *test_id)
 230{
 231	char unit_str[ETH_GSTRING_LEN], test_str[ETH_GSTRING_LEN];
 232
 233	/* Fill data value, if applicable */
 234	if (data)
 235		data[test_index] = *test;
 236
 237	/* Fill string, if applicable */
 238	if (strings) {
 239		if (strchr(unit_format, '%'))
 240			snprintf(unit_str, sizeof(unit_str),
 241				 unit_format, unit_id);
 242		else
 243			strcpy(unit_str, unit_format);
 244		snprintf(test_str, sizeof(test_str), test_format, test_id);
 245		snprintf(strings + test_index * ETH_GSTRING_LEN,
 246			 ETH_GSTRING_LEN,
 247			 "%-6s %-24s", unit_str, test_str);
 248	}
 249}
 250
 251#define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
 252#define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
 253#define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
 254#define EFX_LOOPBACK_NAME(_mode, _counter)			\
 255	"loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode)
 256
 257/**
 258 * efx_fill_loopback_test - fill in a block of loopback self-test entries
 259 * @efx:		Efx NIC
 260 * @lb_tests:		Efx loopback self-test results structure
 261 * @mode:		Loopback test mode
 262 * @test_index:		Starting index of the test
 263 * @strings:		Ethtool strings, or %NULL
 264 * @data:		Ethtool test results, or %NULL
 265 *
 266 * Fill in a block of loopback self-test entries.  Return new test
 267 * index.
 268 */
 269static int efx_fill_loopback_test(struct efx_nic *efx,
 270				  struct efx_loopback_self_tests *lb_tests,
 271				  enum efx_loopback_mode mode,
 272				  unsigned int test_index,
 273				  u8 *strings, u64 *data)
 274{
 275	struct efx_channel *channel =
 276		efx_get_channel(efx, efx->tx_channel_offset);
 277	struct efx_tx_queue *tx_queue;
 278
 279	efx_for_each_channel_tx_queue(tx_queue, channel) {
 280		efx_fill_test(test_index++, strings, data,
 281			      &lb_tests->tx_sent[tx_queue->queue],
 282			      EFX_TX_QUEUE_NAME(tx_queue),
 283			      EFX_LOOPBACK_NAME(mode, "tx_sent"));
 284		efx_fill_test(test_index++, strings, data,
 285			      &lb_tests->tx_done[tx_queue->queue],
 286			      EFX_TX_QUEUE_NAME(tx_queue),
 287			      EFX_LOOPBACK_NAME(mode, "tx_done"));
 288	}
 289	efx_fill_test(test_index++, strings, data,
 290		      &lb_tests->rx_good,
 291		      "rx", 0,
 292		      EFX_LOOPBACK_NAME(mode, "rx_good"));
 293	efx_fill_test(test_index++, strings, data,
 294		      &lb_tests->rx_bad,
 295		      "rx", 0,
 296		      EFX_LOOPBACK_NAME(mode, "rx_bad"));
 297
 298	return test_index;
 299}
 300
 301/**
 302 * efx_ethtool_fill_self_tests - get self-test details
 303 * @efx:		Efx NIC
 304 * @tests:		Efx self-test results structure, or %NULL
 305 * @strings:		Ethtool strings, or %NULL
 306 * @data:		Ethtool test results, or %NULL
 307 *
 308 * Get self-test number of strings, strings, and/or test results.
 309 * Return number of strings (== number of test results).
 310 *
 311 * The reason for merging these three functions is to make sure that
 312 * they can never be inconsistent.
 313 */
 314static int efx_ethtool_fill_self_tests(struct efx_nic *efx,
 315				       struct efx_self_tests *tests,
 316				       u8 *strings, u64 *data)
 317{
 318	struct efx_channel *channel;
 319	unsigned int n = 0, i;
 320	enum efx_loopback_mode mode;
 321
 322	efx_fill_test(n++, strings, data, &tests->phy_alive,
 323		      "phy", 0, "alive", NULL);
 324	efx_fill_test(n++, strings, data, &tests->nvram,
 325		      "core", 0, "nvram", NULL);
 326	efx_fill_test(n++, strings, data, &tests->interrupt,
 327		      "core", 0, "interrupt", NULL);
 328
 329	/* Event queues */
 330	efx_for_each_channel(channel, efx) {
 331		efx_fill_test(n++, strings, data,
 332			      &tests->eventq_dma[channel->channel],
 333			      EFX_CHANNEL_NAME(channel),
 334			      "eventq.dma", NULL);
 335		efx_fill_test(n++, strings, data,
 336			      &tests->eventq_int[channel->channel],
 337			      EFX_CHANNEL_NAME(channel),
 338			      "eventq.int", NULL);
 339	}
 340
 341	efx_fill_test(n++, strings, data, &tests->memory,
 342		      "core", 0, "memory", NULL);
 343	efx_fill_test(n++, strings, data, &tests->registers,
 344		      "core", 0, "registers", NULL);
 345
 346	if (efx->phy_op->run_tests != NULL) {
 347		EFX_WARN_ON_PARANOID(efx->phy_op->test_name == NULL);
 348
 349		for (i = 0; true; ++i) {
 350			const char *name;
 351
 352			EFX_WARN_ON_PARANOID(i >= EFX_MAX_PHY_TESTS);
 353			name = efx->phy_op->test_name(efx, i);
 354			if (name == NULL)
 355				break;
 356
 357			efx_fill_test(n++, strings, data, &tests->phy_ext[i],
 358				      "phy", 0, name, NULL);
 359		}
 360	}
 361
 362	/* Loopback tests */
 363	for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
 364		if (!(efx->loopback_modes & (1 << mode)))
 365			continue;
 366		n = efx_fill_loopback_test(efx,
 367					   &tests->loopback[mode], mode, n,
 368					   strings, data);
 369	}
 370
 371	return n;
 372}
 373
 374static size_t efx_describe_per_queue_stats(struct efx_nic *efx, u8 *strings)
 375{
 376	size_t n_stats = 0;
 377	struct efx_channel *channel;
 378
 379	efx_for_each_channel(channel, efx) {
 380		if (efx_channel_has_tx_queues(channel)) {
 381			n_stats++;
 382			if (strings != NULL) {
 383				snprintf(strings, ETH_GSTRING_LEN,
 384					 "tx-%u.tx_packets",
 385					 channel->tx_queue[0].queue /
 386					 EFX_TXQ_TYPES);
 387
 388				strings += ETH_GSTRING_LEN;
 389			}
 390		}
 391	}
 392	efx_for_each_channel(channel, efx) {
 393		if (efx_channel_has_rx_queue(channel)) {
 394			n_stats++;
 395			if (strings != NULL) {
 396				snprintf(strings, ETH_GSTRING_LEN,
 397					 "rx-%d.rx_packets", channel->channel);
 398				strings += ETH_GSTRING_LEN;
 399			}
 400		}
 401	}
 402	return n_stats;
 403}
 404
 405static int efx_ethtool_get_sset_count(struct net_device *net_dev,
 406				      int string_set)
 407{
 408	struct efx_nic *efx = netdev_priv(net_dev);
 409
 410	switch (string_set) {
 411	case ETH_SS_STATS:
 412		return efx->type->describe_stats(efx, NULL) +
 413		       EFX_ETHTOOL_SW_STAT_COUNT +
 414		       efx_describe_per_queue_stats(efx, NULL) +
 415		       efx_ptp_describe_stats(efx, NULL);
 416	case ETH_SS_TEST:
 417		return efx_ethtool_fill_self_tests(efx, NULL, NULL, NULL);
 418	default:
 419		return -EINVAL;
 420	}
 421}
 422
 423static void efx_ethtool_get_strings(struct net_device *net_dev,
 424				    u32 string_set, u8 *strings)
 425{
 426	struct efx_nic *efx = netdev_priv(net_dev);
 427	int i;
 428
 429	switch (string_set) {
 430	case ETH_SS_STATS:
 431		strings += (efx->type->describe_stats(efx, strings) *
 432			    ETH_GSTRING_LEN);
 433		for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++)
 434			strlcpy(strings + i * ETH_GSTRING_LEN,
 435				efx_sw_stat_desc[i].name, ETH_GSTRING_LEN);
 436		strings += EFX_ETHTOOL_SW_STAT_COUNT * ETH_GSTRING_LEN;
 437		strings += (efx_describe_per_queue_stats(efx, strings) *
 438			    ETH_GSTRING_LEN);
 439		efx_ptp_describe_stats(efx, strings);
 440		break;
 441	case ETH_SS_TEST:
 442		efx_ethtool_fill_self_tests(efx, NULL, strings, NULL);
 443		break;
 444	default:
 445		/* No other string sets */
 446		break;
 447	}
 448}
 449
 450static void efx_ethtool_get_stats(struct net_device *net_dev,
 451				  struct ethtool_stats *stats,
 452				  u64 *data)
 453{
 454	struct efx_nic *efx = netdev_priv(net_dev);
 455	const struct efx_sw_stat_desc *stat;
 456	struct efx_channel *channel;
 457	struct efx_tx_queue *tx_queue;
 458	struct efx_rx_queue *rx_queue;
 459	int i;
 460
 461	spin_lock_bh(&efx->stats_lock);
 462
 463	/* Get NIC statistics */
 464	data += efx->type->update_stats(efx, data, NULL);
 465
 466	/* Get software statistics */
 467	for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) {
 468		stat = &efx_sw_stat_desc[i];
 469		switch (stat->source) {
 470		case EFX_ETHTOOL_STAT_SOURCE_nic:
 471			data[i] = stat->get_stat((void *)efx + stat->offset);
 472			break;
 473		case EFX_ETHTOOL_STAT_SOURCE_channel:
 474			data[i] = 0;
 475			efx_for_each_channel(channel, efx)
 476				data[i] += stat->get_stat((void *)channel +
 477							  stat->offset);
 478			break;
 479		case EFX_ETHTOOL_STAT_SOURCE_tx_queue:
 480			data[i] = 0;
 481			efx_for_each_channel(channel, efx) {
 482				efx_for_each_channel_tx_queue(tx_queue, channel)
 483					data[i] +=
 484						stat->get_stat((void *)tx_queue
 485							       + stat->offset);
 486			}
 487			break;
 488		}
 489	}
 490	data += EFX_ETHTOOL_SW_STAT_COUNT;
 491
 492	spin_unlock_bh(&efx->stats_lock);
 493
 494	efx_for_each_channel(channel, efx) {
 495		if (efx_channel_has_tx_queues(channel)) {
 496			*data = 0;
 497			efx_for_each_channel_tx_queue(tx_queue, channel) {
 498				*data += tx_queue->tx_packets;
 499			}
 500			data++;
 501		}
 502	}
 503	efx_for_each_channel(channel, efx) {
 504		if (efx_channel_has_rx_queue(channel)) {
 505			*data = 0;
 506			efx_for_each_channel_rx_queue(rx_queue, channel) {
 507				*data += rx_queue->rx_packets;
 508			}
 509			data++;
 510		}
 511	}
 512
 513	efx_ptp_update_stats(efx, data);
 514}
 515
 516static void efx_ethtool_self_test(struct net_device *net_dev,
 517				  struct ethtool_test *test, u64 *data)
 518{
 519	struct efx_nic *efx = netdev_priv(net_dev);
 520	struct efx_self_tests *efx_tests;
 521	bool already_up;
 522	int rc = -ENOMEM;
 523
 524	efx_tests = kzalloc(sizeof(*efx_tests), GFP_KERNEL);
 525	if (!efx_tests)
 526		goto fail;
 527
 528	if (efx->state != STATE_READY) {
 529		rc = -EBUSY;
 530		goto out;
 531	}
 532
 533	netif_info(efx, drv, efx->net_dev, "starting %sline testing\n",
 534		   (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
 535
 536	/* We need rx buffers and interrupts. */
 537	already_up = (efx->net_dev->flags & IFF_UP);
 538	if (!already_up) {
 539		rc = dev_open(efx->net_dev, NULL);
 540		if (rc) {
 541			netif_err(efx, drv, efx->net_dev,
 542				  "failed opening device.\n");
 543			goto out;
 544		}
 545	}
 546
 547	rc = efx_selftest(efx, efx_tests, test->flags);
 548
 549	if (!already_up)
 550		dev_close(efx->net_dev);
 551
 552	netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n",
 553		   rc == 0 ? "passed" : "failed",
 554		   (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
 555
 556out:
 557	efx_ethtool_fill_self_tests(efx, efx_tests, NULL, data);
 558	kfree(efx_tests);
 559fail:
 560	if (rc)
 561		test->flags |= ETH_TEST_FL_FAILED;
 562}
 563
 564/* Restart autonegotiation */
 565static int efx_ethtool_nway_reset(struct net_device *net_dev)
 566{
 567	struct efx_nic *efx = netdev_priv(net_dev);
 568
 569	return mdio45_nway_restart(&efx->mdio);
 570}
 571
 572/*
 573 * Each channel has a single IRQ and moderation timer, started by any
 574 * completion (or other event).  Unless the module parameter
 575 * separate_tx_channels is set, IRQs and moderation are therefore
 576 * shared between RX and TX completions.  In this case, when RX IRQ
 577 * moderation is explicitly changed then TX IRQ moderation is
 578 * automatically changed too, but otherwise we fail if the two values
 579 * are requested to be different.
 580 *
 581 * The hardware does not support a limit on the number of completions
 582 * before an IRQ, so we do not use the max_frames fields.  We should
 583 * report and require that max_frames == (usecs != 0), but this would
 584 * invalidate existing user documentation.
 585 *
 586 * The hardware does not have distinct settings for interrupt
 587 * moderation while the previous IRQ is being handled, so we should
 588 * not use the 'irq' fields.  However, an earlier developer
 589 * misunderstood the meaning of the 'irq' fields and the driver did
 590 * not support the standard fields.  To avoid invalidating existing
 591 * user documentation, we report and accept changes through either the
 592 * standard or 'irq' fields.  If both are changed at the same time, we
 593 * prefer the standard field.
 594 *
 595 * We implement adaptive IRQ moderation, but use a different algorithm
 596 * from that assumed in the definition of struct ethtool_coalesce.
 597 * Therefore we do not use any of the adaptive moderation parameters
 598 * in it.
 599 */
 600
 601static int efx_ethtool_get_coalesce(struct net_device *net_dev,
 602				    struct ethtool_coalesce *coalesce)
 
 
 603{
 604	struct efx_nic *efx = netdev_priv(net_dev);
 605	unsigned int tx_usecs, rx_usecs;
 606	bool rx_adaptive;
 607
 608	efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &rx_adaptive);
 609
 610	coalesce->tx_coalesce_usecs = tx_usecs;
 611	coalesce->tx_coalesce_usecs_irq = tx_usecs;
 612	coalesce->rx_coalesce_usecs = rx_usecs;
 613	coalesce->rx_coalesce_usecs_irq = rx_usecs;
 614	coalesce->use_adaptive_rx_coalesce = rx_adaptive;
 615
 616	return 0;
 617}
 618
 619static int efx_ethtool_set_coalesce(struct net_device *net_dev,
 620				    struct ethtool_coalesce *coalesce)
 
 
 621{
 622	struct efx_nic *efx = netdev_priv(net_dev);
 623	struct efx_channel *channel;
 624	unsigned int tx_usecs, rx_usecs;
 625	bool adaptive, rx_may_override_tx;
 626	int rc;
 627
 628	if (coalesce->use_adaptive_tx_coalesce)
 629		return -EINVAL;
 630
 631	efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &adaptive);
 632
 633	if (coalesce->rx_coalesce_usecs != rx_usecs)
 634		rx_usecs = coalesce->rx_coalesce_usecs;
 635	else
 636		rx_usecs = coalesce->rx_coalesce_usecs_irq;
 637
 638	adaptive = coalesce->use_adaptive_rx_coalesce;
 639
 640	/* If channels are shared, TX IRQ moderation can be quietly
 641	 * overridden unless it is changed from its old value.
 642	 */
 643	rx_may_override_tx = (coalesce->tx_coalesce_usecs == tx_usecs &&
 644			      coalesce->tx_coalesce_usecs_irq == tx_usecs);
 645	if (coalesce->tx_coalesce_usecs != tx_usecs)
 646		tx_usecs = coalesce->tx_coalesce_usecs;
 647	else
 648		tx_usecs = coalesce->tx_coalesce_usecs_irq;
 649
 650	rc = efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive,
 651				     rx_may_override_tx);
 652	if (rc != 0)
 653		return rc;
 654
 655	efx_for_each_channel(channel, efx)
 656		efx->type->push_irq_moderation(channel);
 657
 658	return 0;
 659}
 660
 661static void efx_ethtool_get_ringparam(struct net_device *net_dev,
 662				      struct ethtool_ringparam *ring)
 
 
 
 663{
 664	struct efx_nic *efx = netdev_priv(net_dev);
 665
 666	ring->rx_max_pending = EFX_MAX_DMAQ_SIZE;
 667	ring->tx_max_pending = EFX_TXQ_MAX_ENT(efx);
 668	ring->rx_pending = efx->rxq_entries;
 669	ring->tx_pending = efx->txq_entries;
 670}
 671
 672static int efx_ethtool_set_ringparam(struct net_device *net_dev,
 673				     struct ethtool_ringparam *ring)
 
 
 
 674{
 675	struct efx_nic *efx = netdev_priv(net_dev);
 676	u32 txq_entries;
 677
 678	if (ring->rx_mini_pending || ring->rx_jumbo_pending ||
 679	    ring->rx_pending > EFX_MAX_DMAQ_SIZE ||
 680	    ring->tx_pending > EFX_TXQ_MAX_ENT(efx))
 681		return -EINVAL;
 682
 683	if (ring->rx_pending < EFX_RXQ_MIN_ENT) {
 684		netif_err(efx, drv, efx->net_dev,
 685			  "RX queues cannot be smaller than %u\n",
 686			  EFX_RXQ_MIN_ENT);
 687		return -EINVAL;
 688	}
 689
 690	txq_entries = max(ring->tx_pending, EFX_TXQ_MIN_ENT(efx));
 691	if (txq_entries != ring->tx_pending)
 692		netif_warn(efx, drv, efx->net_dev,
 693			   "increasing TX queue size to minimum of %u\n",
 694			   txq_entries);
 695
 696	return efx_realloc_channels(efx, ring->rx_pending, txq_entries);
 697}
 698
 699static int efx_ethtool_set_pauseparam(struct net_device *net_dev,
 700				      struct ethtool_pauseparam *pause)
 701{
 702	struct efx_nic *efx = netdev_priv(net_dev);
 703	u8 wanted_fc, old_fc;
 704	u32 old_adv;
 705	int rc = 0;
 706
 707	mutex_lock(&efx->mac_lock);
 708
 709	wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
 710		     (pause->tx_pause ? EFX_FC_TX : 0) |
 711		     (pause->autoneg ? EFX_FC_AUTO : 0));
 712
 713	if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
 714		netif_dbg(efx, drv, efx->net_dev,
 715			  "Flow control unsupported: tx ON rx OFF\n");
 716		rc = -EINVAL;
 717		goto out;
 718	}
 719
 720	if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising[0]) {
 721		netif_dbg(efx, drv, efx->net_dev,
 722			  "Autonegotiation is disabled\n");
 723		rc = -EINVAL;
 724		goto out;
 725	}
 726
 727	/* Hook for Falcon bug 11482 workaround */
 728	if (efx->type->prepare_enable_fc_tx &&
 729	    (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX))
 730		efx->type->prepare_enable_fc_tx(efx);
 731
 732	old_adv = efx->link_advertising[0];
 733	old_fc = efx->wanted_fc;
 734	efx_link_set_wanted_fc(efx, wanted_fc);
 735	if (efx->link_advertising[0] != old_adv ||
 736	    (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) {
 737		rc = efx->phy_op->reconfigure(efx);
 738		if (rc) {
 739			netif_err(efx, drv, efx->net_dev,
 740				  "Unable to advertise requested flow "
 741				  "control setting\n");
 742			goto out;
 743		}
 744	}
 745
 746	/* Reconfigure the MAC. The PHY *may* generate a link state change event
 747	 * if the user just changed the advertised capabilities, but there's no
 748	 * harm doing this twice */
 749	efx_mac_reconfigure(efx);
 750
 751out:
 752	mutex_unlock(&efx->mac_lock);
 753
 754	return rc;
 755}
 756
 757static void efx_ethtool_get_pauseparam(struct net_device *net_dev,
 758				       struct ethtool_pauseparam *pause)
 759{
 760	struct efx_nic *efx = netdev_priv(net_dev);
 761
 762	pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX);
 763	pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX);
 764	pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO);
 765}
 766
 767static void efx_ethtool_get_wol(struct net_device *net_dev,
 768				struct ethtool_wolinfo *wol)
 769{
 770	struct efx_nic *efx = netdev_priv(net_dev);
 771	return efx->type->get_wol(efx, wol);
 772}
 773
 774
 775static int efx_ethtool_set_wol(struct net_device *net_dev,
 776			       struct ethtool_wolinfo *wol)
 777{
 778	struct efx_nic *efx = netdev_priv(net_dev);
 779	return efx->type->set_wol(efx, wol->wolopts);
 780}
 781
 782static int efx_ethtool_reset(struct net_device *net_dev, u32 *flags)
 783{
 784	struct efx_nic *efx = netdev_priv(net_dev);
 785	int rc;
 786
 787	rc = efx->type->map_reset_flags(flags);
 788	if (rc < 0)
 789		return rc;
 790
 791	return efx_reset(efx, rc);
 792}
 793
 794/* MAC address mask including only I/G bit */
 795static const u8 mac_addr_ig_mask[ETH_ALEN] __aligned(2) = {0x01, 0, 0, 0, 0, 0};
 796
 797#define IP4_ADDR_FULL_MASK	((__force __be32)~0)
 798#define IP_PROTO_FULL_MASK	0xFF
 799#define PORT_FULL_MASK		((__force __be16)~0)
 800#define ETHER_TYPE_FULL_MASK	((__force __be16)~0)
 801
 802static inline void ip6_fill_mask(__be32 *mask)
 803{
 804	mask[0] = mask[1] = mask[2] = mask[3] = ~(__be32)0;
 805}
 806
 807static int efx_ethtool_get_class_rule(struct efx_nic *efx,
 808				      struct ethtool_rx_flow_spec *rule,
 809				      u32 *rss_context)
 810{
 811	struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
 812	struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
 813	struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
 814	struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
 815	struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
 816	struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
 817	struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
 818	struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
 819	struct ethhdr *mac_entry = &rule->h_u.ether_spec;
 820	struct ethhdr *mac_mask = &rule->m_u.ether_spec;
 821	struct efx_filter_spec spec;
 822	int rc;
 823
 824	rc = efx_filter_get_filter_safe(efx, EFX_FILTER_PRI_MANUAL,
 825					rule->location, &spec);
 826	if (rc)
 827		return rc;
 828
 829	if (spec.dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP)
 830		rule->ring_cookie = RX_CLS_FLOW_DISC;
 831	else
 832		rule->ring_cookie = spec.dmaq_id;
 833
 834	if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) &&
 835	    spec.ether_type == htons(ETH_P_IP) &&
 836	    (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) &&
 837	    (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
 838	    !(spec.match_flags &
 839	      ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
 840		EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
 841		EFX_FILTER_MATCH_IP_PROTO |
 842		EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) {
 843		rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
 844				   TCP_V4_FLOW : UDP_V4_FLOW);
 845		if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
 846			ip_entry->ip4dst = spec.loc_host[0];
 847			ip_mask->ip4dst = IP4_ADDR_FULL_MASK;
 848		}
 849		if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
 850			ip_entry->ip4src = spec.rem_host[0];
 851			ip_mask->ip4src = IP4_ADDR_FULL_MASK;
 852		}
 853		if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) {
 854			ip_entry->pdst = spec.loc_port;
 855			ip_mask->pdst = PORT_FULL_MASK;
 856		}
 857		if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) {
 858			ip_entry->psrc = spec.rem_port;
 859			ip_mask->psrc = PORT_FULL_MASK;
 860		}
 861	} else if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) &&
 862	    spec.ether_type == htons(ETH_P_IPV6) &&
 863	    (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) &&
 864	    (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
 865	    !(spec.match_flags &
 866	      ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
 867		EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
 868		EFX_FILTER_MATCH_IP_PROTO |
 869		EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) {
 870		rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
 871				   TCP_V6_FLOW : UDP_V6_FLOW);
 872		if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
 873			memcpy(ip6_entry->ip6dst, spec.loc_host,
 874			       sizeof(ip6_entry->ip6dst));
 875			ip6_fill_mask(ip6_mask->ip6dst);
 876		}
 877		if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
 878			memcpy(ip6_entry->ip6src, spec.rem_host,
 879			       sizeof(ip6_entry->ip6src));
 880			ip6_fill_mask(ip6_mask->ip6src);
 881		}
 882		if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) {
 883			ip6_entry->pdst = spec.loc_port;
 884			ip6_mask->pdst = PORT_FULL_MASK;
 885		}
 886		if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) {
 887			ip6_entry->psrc = spec.rem_port;
 888			ip6_mask->psrc = PORT_FULL_MASK;
 889		}
 890	} else if (!(spec.match_flags &
 891		     ~(EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG |
 892		       EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_ETHER_TYPE |
 893		       EFX_FILTER_MATCH_OUTER_VID))) {
 894		rule->flow_type = ETHER_FLOW;
 895		if (spec.match_flags &
 896		    (EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG)) {
 897			ether_addr_copy(mac_entry->h_dest, spec.loc_mac);
 898			if (spec.match_flags & EFX_FILTER_MATCH_LOC_MAC)
 899				eth_broadcast_addr(mac_mask->h_dest);
 900			else
 901				ether_addr_copy(mac_mask->h_dest,
 902						mac_addr_ig_mask);
 903		}
 904		if (spec.match_flags & EFX_FILTER_MATCH_REM_MAC) {
 905			ether_addr_copy(mac_entry->h_source, spec.rem_mac);
 906			eth_broadcast_addr(mac_mask->h_source);
 907		}
 908		if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) {
 909			mac_entry->h_proto = spec.ether_type;
 910			mac_mask->h_proto = ETHER_TYPE_FULL_MASK;
 911		}
 912	} else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
 913		   spec.ether_type == htons(ETH_P_IP) &&
 914		   !(spec.match_flags &
 915		     ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
 916		       EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
 917		       EFX_FILTER_MATCH_IP_PROTO))) {
 918		rule->flow_type = IPV4_USER_FLOW;
 919		uip_entry->ip_ver = ETH_RX_NFC_IP4;
 920		if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) {
 921			uip_mask->proto = IP_PROTO_FULL_MASK;
 922			uip_entry->proto = spec.ip_proto;
 923		}
 924		if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
 925			uip_entry->ip4dst = spec.loc_host[0];
 926			uip_mask->ip4dst = IP4_ADDR_FULL_MASK;
 927		}
 928		if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
 929			uip_entry->ip4src = spec.rem_host[0];
 930			uip_mask->ip4src = IP4_ADDR_FULL_MASK;
 931		}
 932	} else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
 933		   spec.ether_type == htons(ETH_P_IPV6) &&
 934		   !(spec.match_flags &
 935		     ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
 936		       EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
 937		       EFX_FILTER_MATCH_IP_PROTO))) {
 938		rule->flow_type = IPV6_USER_FLOW;
 939		if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) {
 940			uip6_mask->l4_proto = IP_PROTO_FULL_MASK;
 941			uip6_entry->l4_proto = spec.ip_proto;
 942		}
 943		if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
 944			memcpy(uip6_entry->ip6dst, spec.loc_host,
 945			       sizeof(uip6_entry->ip6dst));
 946			ip6_fill_mask(uip6_mask->ip6dst);
 947		}
 948		if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
 949			memcpy(uip6_entry->ip6src, spec.rem_host,
 950			       sizeof(uip6_entry->ip6src));
 951			ip6_fill_mask(uip6_mask->ip6src);
 952		}
 953	} else {
 954		/* The above should handle all filters that we insert */
 955		WARN_ON(1);
 956		return -EINVAL;
 957	}
 958
 959	if (spec.match_flags & EFX_FILTER_MATCH_OUTER_VID) {
 960		rule->flow_type |= FLOW_EXT;
 961		rule->h_ext.vlan_tci = spec.outer_vid;
 962		rule->m_ext.vlan_tci = htons(0xfff);
 963	}
 964
 965	if (spec.flags & EFX_FILTER_FLAG_RX_RSS) {
 966		rule->flow_type |= FLOW_RSS;
 967		*rss_context = spec.rss_context;
 968	}
 969
 970	return rc;
 971}
 972
 973static int
 974efx_ethtool_get_rxnfc(struct net_device *net_dev,
 975		      struct ethtool_rxnfc *info, u32 *rule_locs)
 976{
 977	struct efx_nic *efx = netdev_priv(net_dev);
 978	u32 rss_context = 0;
 979	s32 rc = 0;
 980
 981	switch (info->cmd) {
 982	case ETHTOOL_GRXRINGS:
 983		info->data = efx->n_rx_channels;
 984		return 0;
 985
 986	case ETHTOOL_GRXFH: {
 987		struct efx_rss_context *ctx = &efx->rss_context;
 988
 989		mutex_lock(&efx->rss_lock);
 990		if (info->flow_type & FLOW_RSS && info->rss_context) {
 991			ctx = efx_find_rss_context_entry(efx, info->rss_context);
 992			if (!ctx) {
 993				rc = -ENOENT;
 994				goto out_unlock;
 995			}
 996		}
 997		info->data = 0;
 998		if (!efx_rss_active(ctx)) /* No RSS */
 999			goto out_unlock;
1000		switch (info->flow_type & ~FLOW_RSS) {
1001		case UDP_V4_FLOW:
1002			if (ctx->rx_hash_udp_4tuple)
1003				/* fall through */
1004		case TCP_V4_FLOW:
1005				info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1006			/* fall through */
1007		case SCTP_V4_FLOW:
1008		case AH_ESP_V4_FLOW:
1009		case IPV4_FLOW:
1010			info->data |= RXH_IP_SRC | RXH_IP_DST;
1011			break;
1012		case UDP_V6_FLOW:
1013			if (ctx->rx_hash_udp_4tuple)
1014				/* fall through */
1015		case TCP_V6_FLOW:
1016				info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1017			/* fall through */
1018		case SCTP_V6_FLOW:
1019		case AH_ESP_V6_FLOW:
1020		case IPV6_FLOW:
1021			info->data |= RXH_IP_SRC | RXH_IP_DST;
1022			break;
1023		default:
1024			break;
1025		}
1026out_unlock:
1027		mutex_unlock(&efx->rss_lock);
1028		return rc;
1029	}
1030
1031	case ETHTOOL_GRXCLSRLCNT:
1032		info->data = efx_filter_get_rx_id_limit(efx);
1033		if (info->data == 0)
1034			return -EOPNOTSUPP;
1035		info->data |= RX_CLS_LOC_SPECIAL;
1036		info->rule_cnt =
1037			efx_filter_count_rx_used(efx, EFX_FILTER_PRI_MANUAL);
1038		return 0;
1039
1040	case ETHTOOL_GRXCLSRULE:
1041		if (efx_filter_get_rx_id_limit(efx) == 0)
1042			return -EOPNOTSUPP;
1043		rc = efx_ethtool_get_class_rule(efx, &info->fs, &rss_context);
1044		if (rc < 0)
1045			return rc;
1046		if (info->fs.flow_type & FLOW_RSS)
1047			info->rss_context = rss_context;
1048		return 0;
1049
1050	case ETHTOOL_GRXCLSRLALL:
1051		info->data = efx_filter_get_rx_id_limit(efx);
1052		if (info->data == 0)
1053			return -EOPNOTSUPP;
1054		rc = efx_filter_get_rx_ids(efx, EFX_FILTER_PRI_MANUAL,
1055					   rule_locs, info->rule_cnt);
1056		if (rc < 0)
1057			return rc;
1058		info->rule_cnt = rc;
1059		return 0;
1060
1061	default:
1062		return -EOPNOTSUPP;
1063	}
1064}
1065
1066static inline bool ip6_mask_is_full(__be32 mask[4])
1067{
1068	return !~(mask[0] & mask[1] & mask[2] & mask[3]);
1069}
1070
1071static inline bool ip6_mask_is_empty(__be32 mask[4])
1072{
1073	return !(mask[0] | mask[1] | mask[2] | mask[3]);
1074}
1075
1076static int efx_ethtool_set_class_rule(struct efx_nic *efx,
1077				      struct ethtool_rx_flow_spec *rule,
1078				      u32 rss_context)
1079{
1080	struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
1081	struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
1082	struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
1083	struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
1084	struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
1085	struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
1086	struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
1087	struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
1088	u32 flow_type = rule->flow_type & ~(FLOW_EXT | FLOW_RSS);
1089	struct ethhdr *mac_entry = &rule->h_u.ether_spec;
1090	struct ethhdr *mac_mask = &rule->m_u.ether_spec;
1091	enum efx_filter_flags flags = 0;
1092	struct efx_filter_spec spec;
1093	int rc;
1094
1095	/* Check that user wants us to choose the location */
1096	if (rule->location != RX_CLS_LOC_ANY)
1097		return -EINVAL;
1098
1099	/* Range-check ring_cookie */
1100	if (rule->ring_cookie >= efx->n_rx_channels &&
1101	    rule->ring_cookie != RX_CLS_FLOW_DISC)
1102		return -EINVAL;
1103
1104	/* Check for unsupported extensions */
1105	if ((rule->flow_type & FLOW_EXT) &&
1106	    (rule->m_ext.vlan_etype || rule->m_ext.data[0] ||
1107	     rule->m_ext.data[1]))
1108		return -EINVAL;
1109
1110	if (efx->rx_scatter)
1111		flags |= EFX_FILTER_FLAG_RX_SCATTER;
1112	if (rule->flow_type & FLOW_RSS)
1113		flags |= EFX_FILTER_FLAG_RX_RSS;
1114
1115	efx_filter_init_rx(&spec, EFX_FILTER_PRI_MANUAL, flags,
1116			   (rule->ring_cookie == RX_CLS_FLOW_DISC) ?
1117			   EFX_FILTER_RX_DMAQ_ID_DROP : rule->ring_cookie);
1118
1119	if (rule->flow_type & FLOW_RSS)
1120		spec.rss_context = rss_context;
1121
1122	switch (flow_type) {
1123	case TCP_V4_FLOW:
1124	case UDP_V4_FLOW:
1125		spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
1126				    EFX_FILTER_MATCH_IP_PROTO);
1127		spec.ether_type = htons(ETH_P_IP);
1128		spec.ip_proto = flow_type == TCP_V4_FLOW ? IPPROTO_TCP
1129							 : IPPROTO_UDP;
1130		if (ip_mask->ip4dst) {
1131			if (ip_mask->ip4dst != IP4_ADDR_FULL_MASK)
1132				return -EINVAL;
1133			spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1134			spec.loc_host[0] = ip_entry->ip4dst;
1135		}
1136		if (ip_mask->ip4src) {
1137			if (ip_mask->ip4src != IP4_ADDR_FULL_MASK)
1138				return -EINVAL;
1139			spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1140			spec.rem_host[0] = ip_entry->ip4src;
1141		}
1142		if (ip_mask->pdst) {
1143			if (ip_mask->pdst != PORT_FULL_MASK)
1144				return -EINVAL;
1145			spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
1146			spec.loc_port = ip_entry->pdst;
1147		}
1148		if (ip_mask->psrc) {
1149			if (ip_mask->psrc != PORT_FULL_MASK)
1150				return -EINVAL;
1151			spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
1152			spec.rem_port = ip_entry->psrc;
1153		}
1154		if (ip_mask->tos)
1155			return -EINVAL;
1156		break;
1157
1158	case TCP_V6_FLOW:
1159	case UDP_V6_FLOW:
1160		spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
1161				    EFX_FILTER_MATCH_IP_PROTO);
1162		spec.ether_type = htons(ETH_P_IPV6);
1163		spec.ip_proto = flow_type == TCP_V6_FLOW ? IPPROTO_TCP
1164							 : IPPROTO_UDP;
1165		if (!ip6_mask_is_empty(ip6_mask->ip6dst)) {
1166			if (!ip6_mask_is_full(ip6_mask->ip6dst))
1167				return -EINVAL;
1168			spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1169			memcpy(spec.loc_host, ip6_entry->ip6dst, sizeof(spec.loc_host));
1170		}
1171		if (!ip6_mask_is_empty(ip6_mask->ip6src)) {
1172			if (!ip6_mask_is_full(ip6_mask->ip6src))
1173				return -EINVAL;
1174			spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1175			memcpy(spec.rem_host, ip6_entry->ip6src, sizeof(spec.rem_host));
1176		}
1177		if (ip6_mask->pdst) {
1178			if (ip6_mask->pdst != PORT_FULL_MASK)
1179				return -EINVAL;
1180			spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
1181			spec.loc_port = ip6_entry->pdst;
1182		}
1183		if (ip6_mask->psrc) {
1184			if (ip6_mask->psrc != PORT_FULL_MASK)
1185				return -EINVAL;
1186			spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
1187			spec.rem_port = ip6_entry->psrc;
1188		}
1189		if (ip6_mask->tclass)
1190			return -EINVAL;
1191		break;
1192
1193	case IPV4_USER_FLOW:
1194		if (uip_mask->l4_4_bytes || uip_mask->tos || uip_mask->ip_ver ||
1195		    uip_entry->ip_ver != ETH_RX_NFC_IP4)
1196			return -EINVAL;
1197		spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE;
1198		spec.ether_type = htons(ETH_P_IP);
1199		if (uip_mask->ip4dst) {
1200			if (uip_mask->ip4dst != IP4_ADDR_FULL_MASK)
1201				return -EINVAL;
1202			spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1203			spec.loc_host[0] = uip_entry->ip4dst;
1204		}
1205		if (uip_mask->ip4src) {
1206			if (uip_mask->ip4src != IP4_ADDR_FULL_MASK)
1207				return -EINVAL;
1208			spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1209			spec.rem_host[0] = uip_entry->ip4src;
1210		}
1211		if (uip_mask->proto) {
1212			if (uip_mask->proto != IP_PROTO_FULL_MASK)
1213				return -EINVAL;
1214			spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO;
1215			spec.ip_proto = uip_entry->proto;
1216		}
1217		break;
1218
1219	case IPV6_USER_FLOW:
1220		if (uip6_mask->l4_4_bytes || uip6_mask->tclass)
1221			return -EINVAL;
1222		spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE;
1223		spec.ether_type = htons(ETH_P_IPV6);
1224		if (!ip6_mask_is_empty(uip6_mask->ip6dst)) {
1225			if (!ip6_mask_is_full(uip6_mask->ip6dst))
1226				return -EINVAL;
1227			spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1228			memcpy(spec.loc_host, uip6_entry->ip6dst, sizeof(spec.loc_host));
1229		}
1230		if (!ip6_mask_is_empty(uip6_mask->ip6src)) {
1231			if (!ip6_mask_is_full(uip6_mask->ip6src))
1232				return -EINVAL;
1233			spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1234			memcpy(spec.rem_host, uip6_entry->ip6src, sizeof(spec.rem_host));
1235		}
1236		if (uip6_mask->l4_proto) {
1237			if (uip6_mask->l4_proto != IP_PROTO_FULL_MASK)
1238				return -EINVAL;
1239			spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO;
1240			spec.ip_proto = uip6_entry->l4_proto;
1241		}
1242		break;
1243
1244	case ETHER_FLOW:
1245		if (!is_zero_ether_addr(mac_mask->h_dest)) {
1246			if (ether_addr_equal(mac_mask->h_dest,
1247					     mac_addr_ig_mask))
1248				spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC_IG;
1249			else if (is_broadcast_ether_addr(mac_mask->h_dest))
1250				spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC;
1251			else
1252				return -EINVAL;
1253			ether_addr_copy(spec.loc_mac, mac_entry->h_dest);
1254		}
1255		if (!is_zero_ether_addr(mac_mask->h_source)) {
1256			if (!is_broadcast_ether_addr(mac_mask->h_source))
1257				return -EINVAL;
1258			spec.match_flags |= EFX_FILTER_MATCH_REM_MAC;
1259			ether_addr_copy(spec.rem_mac, mac_entry->h_source);
1260		}
1261		if (mac_mask->h_proto) {
1262			if (mac_mask->h_proto != ETHER_TYPE_FULL_MASK)
1263				return -EINVAL;
1264			spec.match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
1265			spec.ether_type = mac_entry->h_proto;
1266		}
1267		break;
1268
1269	default:
1270		return -EINVAL;
1271	}
1272
1273	if ((rule->flow_type & FLOW_EXT) && rule->m_ext.vlan_tci) {
1274		if (rule->m_ext.vlan_tci != htons(0xfff))
1275			return -EINVAL;
1276		spec.match_flags |= EFX_FILTER_MATCH_OUTER_VID;
1277		spec.outer_vid = rule->h_ext.vlan_tci;
1278	}
1279
1280	rc = efx_filter_insert_filter(efx, &spec, true);
1281	if (rc < 0)
1282		return rc;
1283
1284	rule->location = rc;
1285	return 0;
1286}
1287
1288static int efx_ethtool_set_rxnfc(struct net_device *net_dev,
1289				 struct ethtool_rxnfc *info)
1290{
1291	struct efx_nic *efx = netdev_priv(net_dev);
1292
1293	if (efx_filter_get_rx_id_limit(efx) == 0)
1294		return -EOPNOTSUPP;
1295
1296	switch (info->cmd) {
1297	case ETHTOOL_SRXCLSRLINS:
1298		return efx_ethtool_set_class_rule(efx, &info->fs,
1299						  info->rss_context);
1300
1301	case ETHTOOL_SRXCLSRLDEL:
1302		return efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_MANUAL,
1303						 info->fs.location);
1304
1305	default:
1306		return -EOPNOTSUPP;
1307	}
1308}
1309
1310static u32 efx_ethtool_get_rxfh_indir_size(struct net_device *net_dev)
1311{
1312	struct efx_nic *efx = netdev_priv(net_dev);
1313
1314	if (efx->n_rx_channels == 1)
1315		return 0;
1316	return ARRAY_SIZE(efx->rss_context.rx_indir_table);
1317}
1318
1319static u32 efx_ethtool_get_rxfh_key_size(struct net_device *net_dev)
1320{
1321	struct efx_nic *efx = netdev_priv(net_dev);
1322
1323	return efx->type->rx_hash_key_size;
1324}
1325
1326static int efx_ethtool_get_rxfh(struct net_device *net_dev, u32 *indir, u8 *key,
1327				u8 *hfunc)
1328{
1329	struct efx_nic *efx = netdev_priv(net_dev);
1330	int rc;
1331
1332	rc = efx->type->rx_pull_rss_config(efx);
1333	if (rc)
1334		return rc;
1335
1336	if (hfunc)
1337		*hfunc = ETH_RSS_HASH_TOP;
1338	if (indir)
1339		memcpy(indir, efx->rss_context.rx_indir_table,
1340		       sizeof(efx->rss_context.rx_indir_table));
1341	if (key)
1342		memcpy(key, efx->rss_context.rx_hash_key,
1343		       efx->type->rx_hash_key_size);
1344	return 0;
1345}
1346
1347static int efx_ethtool_set_rxfh(struct net_device *net_dev, const u32 *indir,
1348				const u8 *key, const u8 hfunc)
1349{
1350	struct efx_nic *efx = netdev_priv(net_dev);
1351
1352	/* Hash function is Toeplitz, cannot be changed */
1353	if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1354		return -EOPNOTSUPP;
1355	if (!indir && !key)
1356		return 0;
1357
1358	if (!key)
1359		key = efx->rss_context.rx_hash_key;
1360	if (!indir)
1361		indir = efx->rss_context.rx_indir_table;
1362
1363	return efx->type->rx_push_rss_config(efx, true, indir, key);
1364}
1365
1366static int efx_ethtool_get_rxfh_context(struct net_device *net_dev, u32 *indir,
1367					u8 *key, u8 *hfunc, u32 rss_context)
1368{
1369	struct efx_nic *efx = netdev_priv(net_dev);
1370	struct efx_rss_context *ctx;
1371	int rc = 0;
1372
1373	if (!efx->type->rx_pull_rss_context_config)
1374		return -EOPNOTSUPP;
1375
1376	mutex_lock(&efx->rss_lock);
1377	ctx = efx_find_rss_context_entry(efx, rss_context);
1378	if (!ctx) {
1379		rc = -ENOENT;
1380		goto out_unlock;
1381	}
1382	rc = efx->type->rx_pull_rss_context_config(efx, ctx);
1383	if (rc)
1384		goto out_unlock;
1385
1386	if (hfunc)
1387		*hfunc = ETH_RSS_HASH_TOP;
1388	if (indir)
1389		memcpy(indir, ctx->rx_indir_table, sizeof(ctx->rx_indir_table));
1390	if (key)
1391		memcpy(key, ctx->rx_hash_key, efx->type->rx_hash_key_size);
1392out_unlock:
1393	mutex_unlock(&efx->rss_lock);
1394	return rc;
1395}
1396
1397static int efx_ethtool_set_rxfh_context(struct net_device *net_dev,
1398					const u32 *indir, const u8 *key,
1399					const u8 hfunc, u32 *rss_context,
1400					bool delete)
1401{
1402	struct efx_nic *efx = netdev_priv(net_dev);
1403	struct efx_rss_context *ctx;
1404	bool allocated = false;
1405	int rc;
1406
1407	if (!efx->type->rx_push_rss_context_config)
1408		return -EOPNOTSUPP;
1409	/* Hash function is Toeplitz, cannot be changed */
1410	if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1411		return -EOPNOTSUPP;
1412
1413	mutex_lock(&efx->rss_lock);
1414
1415	if (*rss_context == ETH_RXFH_CONTEXT_ALLOC) {
1416		if (delete) {
1417			/* alloc + delete == Nothing to do */
1418			rc = -EINVAL;
1419			goto out_unlock;
1420		}
1421		ctx = efx_alloc_rss_context_entry(efx);
1422		if (!ctx) {
1423			rc = -ENOMEM;
1424			goto out_unlock;
1425		}
1426		ctx->context_id = EFX_EF10_RSS_CONTEXT_INVALID;
1427		/* Initialise indir table and key to defaults */
1428		efx_set_default_rx_indir_table(efx, ctx);
1429		netdev_rss_key_fill(ctx->rx_hash_key, sizeof(ctx->rx_hash_key));
1430		allocated = true;
1431	} else {
1432		ctx = efx_find_rss_context_entry(efx, *rss_context);
1433		if (!ctx) {
1434			rc = -ENOENT;
1435			goto out_unlock;
1436		}
1437	}
1438
1439	if (delete) {
1440		/* delete this context */
1441		rc = efx->type->rx_push_rss_context_config(efx, ctx, NULL, NULL);
1442		if (!rc)
1443			efx_free_rss_context_entry(ctx);
1444		goto out_unlock;
1445	}
1446
1447	if (!key)
1448		key = ctx->rx_hash_key;
1449	if (!indir)
1450		indir = ctx->rx_indir_table;
1451
1452	rc = efx->type->rx_push_rss_context_config(efx, ctx, indir, key);
1453	if (rc && allocated)
1454		efx_free_rss_context_entry(ctx);
1455	else
1456		*rss_context = ctx->user_id;
1457out_unlock:
1458	mutex_unlock(&efx->rss_lock);
1459	return rc;
1460}
1461
1462static int efx_ethtool_get_ts_info(struct net_device *net_dev,
1463				   struct ethtool_ts_info *ts_info)
1464{
1465	struct efx_nic *efx = netdev_priv(net_dev);
1466
1467	/* Software capabilities */
1468	ts_info->so_timestamping = (SOF_TIMESTAMPING_RX_SOFTWARE |
1469				    SOF_TIMESTAMPING_SOFTWARE);
1470	ts_info->phc_index = -1;
1471
1472	efx_ptp_get_ts_info(efx, ts_info);
1473	return 0;
1474}
1475
1476static int efx_ethtool_get_module_eeprom(struct net_device *net_dev,
1477					 struct ethtool_eeprom *ee,
1478					 u8 *data)
1479{
1480	struct efx_nic *efx = netdev_priv(net_dev);
1481	int ret;
1482
1483	if (!efx->phy_op || !efx->phy_op->get_module_eeprom)
1484		return -EOPNOTSUPP;
1485
1486	mutex_lock(&efx->mac_lock);
1487	ret = efx->phy_op->get_module_eeprom(efx, ee, data);
1488	mutex_unlock(&efx->mac_lock);
1489
1490	return ret;
1491}
1492
1493static int efx_ethtool_get_module_info(struct net_device *net_dev,
1494				       struct ethtool_modinfo *modinfo)
1495{
1496	struct efx_nic *efx = netdev_priv(net_dev);
1497	int ret;
1498
1499	if (!efx->phy_op || !efx->phy_op->get_module_info)
1500		return -EOPNOTSUPP;
1501
1502	mutex_lock(&efx->mac_lock);
1503	ret = efx->phy_op->get_module_info(efx, modinfo);
1504	mutex_unlock(&efx->mac_lock);
1505
1506	return ret;
1507}
1508
1509static int efx_ethtool_get_fecparam(struct net_device *net_dev,
1510				    struct ethtool_fecparam *fecparam)
1511{
1512	struct efx_nic *efx = netdev_priv(net_dev);
1513	int rc;
1514
1515	if (!efx->phy_op || !efx->phy_op->get_fecparam)
1516		return -EOPNOTSUPP;
1517	mutex_lock(&efx->mac_lock);
1518	rc = efx->phy_op->get_fecparam(efx, fecparam);
1519	mutex_unlock(&efx->mac_lock);
1520
1521	return rc;
1522}
1523
1524static int efx_ethtool_set_fecparam(struct net_device *net_dev,
1525				    struct ethtool_fecparam *fecparam)
1526{
1527	struct efx_nic *efx = netdev_priv(net_dev);
1528	int rc;
1529
1530	if (!efx->phy_op || !efx->phy_op->get_fecparam)
1531		return -EOPNOTSUPP;
1532	mutex_lock(&efx->mac_lock);
1533	rc = efx->phy_op->set_fecparam(efx, fecparam);
1534	mutex_unlock(&efx->mac_lock);
1535
1536	return rc;
1537}
1538
1539const struct ethtool_ops efx_ethtool_ops = {
 
 
 
 
1540	.get_drvinfo		= efx_ethtool_get_drvinfo,
1541	.get_regs_len		= efx_ethtool_get_regs_len,
1542	.get_regs		= efx_ethtool_get_regs,
1543	.get_msglevel		= efx_ethtool_get_msglevel,
1544	.set_msglevel		= efx_ethtool_set_msglevel,
1545	.nway_reset		= efx_ethtool_nway_reset,
1546	.get_link		= ethtool_op_get_link,
1547	.get_coalesce		= efx_ethtool_get_coalesce,
1548	.set_coalesce		= efx_ethtool_set_coalesce,
1549	.get_ringparam		= efx_ethtool_get_ringparam,
1550	.set_ringparam		= efx_ethtool_set_ringparam,
1551	.get_pauseparam         = efx_ethtool_get_pauseparam,
1552	.set_pauseparam         = efx_ethtool_set_pauseparam,
1553	.get_sset_count		= efx_ethtool_get_sset_count,
1554	.self_test		= efx_ethtool_self_test,
1555	.get_strings		= efx_ethtool_get_strings,
1556	.set_phys_id		= efx_ethtool_phys_id,
1557	.get_ethtool_stats	= efx_ethtool_get_stats,
1558	.get_wol                = efx_ethtool_get_wol,
1559	.set_wol                = efx_ethtool_set_wol,
1560	.reset			= efx_ethtool_reset,
1561	.get_rxnfc		= efx_ethtool_get_rxnfc,
1562	.set_rxnfc		= efx_ethtool_set_rxnfc,
1563	.get_rxfh_indir_size	= efx_ethtool_get_rxfh_indir_size,
1564	.get_rxfh_key_size	= efx_ethtool_get_rxfh_key_size,
1565	.get_rxfh		= efx_ethtool_get_rxfh,
1566	.set_rxfh		= efx_ethtool_set_rxfh,
1567	.get_rxfh_context	= efx_ethtool_get_rxfh_context,
1568	.set_rxfh_context	= efx_ethtool_set_rxfh_context,
1569	.get_ts_info		= efx_ethtool_get_ts_info,
1570	.get_module_info	= efx_ethtool_get_module_info,
1571	.get_module_eeprom	= efx_ethtool_get_module_eeprom,
1572	.get_link_ksettings	= efx_ethtool_get_link_ksettings,
1573	.set_link_ksettings	= efx_ethtool_set_link_ksettings,
 
1574	.get_fecparam		= efx_ethtool_get_fecparam,
1575	.set_fecparam		= efx_ethtool_set_fecparam,
1576};