xref: /linux/drivers/net/ethernet/sfc/ethtool.c (revision 65c93628599dff4cd7cfb70130d1f6a2203731ea)
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 */
33 static int efx_ethtool_phys_id(struct net_device *net_dev,
34 			       enum ethtool_phys_id_state state)
35 {
36 	struct efx_nic *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 	efx->type->set_id_led(efx, mode);
54 	return 0;
55 }
56 
57 /* This must be called with rtnl_lock held. */
58 static int
59 efx_ethtool_get_link_ksettings(struct net_device *net_dev,
60 			       struct ethtool_link_ksettings *cmd)
61 {
62 	struct efx_nic *efx = netdev_priv(net_dev);
63 	struct efx_link_state *link_state = &efx->link_state;
64 	u32 supported;
65 
66 	mutex_lock(&efx->mac_lock);
67 	efx->phy_op->get_link_ksettings(efx, cmd);
68 	mutex_unlock(&efx->mac_lock);
69 
70 	/* Both MACs support pause frames (bidirectional and respond-only) */
71 	ethtool_convert_link_mode_to_legacy_u32(&supported,
72 						cmd->link_modes.supported);
73 
74 	supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
75 
76 	ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
77 						supported);
78 
79 	if (LOOPBACK_INTERNAL(efx)) {
80 		cmd->base.speed = link_state->speed;
81 		cmd->base.duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF;
82 	}
83 
84 	return 0;
85 }
86 
87 /* This must be called with rtnl_lock held. */
88 static int
89 efx_ethtool_set_link_ksettings(struct net_device *net_dev,
90 			       const struct ethtool_link_ksettings *cmd)
91 {
92 	struct efx_nic *efx = netdev_priv(net_dev);
93 	int rc;
94 
95 	/* GMAC does not support 1000Mbps HD */
96 	if ((cmd->base.speed == SPEED_1000) &&
97 	    (cmd->base.duplex != DUPLEX_FULL)) {
98 		netif_dbg(efx, drv, efx->net_dev,
99 			  "rejecting unsupported 1000Mbps HD setting\n");
100 		return -EINVAL;
101 	}
102 
103 	mutex_lock(&efx->mac_lock);
104 	rc = efx->phy_op->set_link_ksettings(efx, cmd);
105 	mutex_unlock(&efx->mac_lock);
106 	return rc;
107 }
108 
109 static int efx_ethtool_get_regs_len(struct net_device *net_dev)
110 {
111 	return efx_nic_get_regs_len(netdev_priv(net_dev));
112 }
113 
114 static void efx_ethtool_get_regs(struct net_device *net_dev,
115 				 struct ethtool_regs *regs, void *buf)
116 {
117 	struct efx_nic *efx = netdev_priv(net_dev);
118 
119 	regs->version = efx->type->revision;
120 	efx_nic_get_regs(efx, buf);
121 }
122 
123 static void efx_ethtool_self_test(struct net_device *net_dev,
124 				  struct ethtool_test *test, u64 *data)
125 {
126 	struct efx_nic *efx = netdev_priv(net_dev);
127 	struct efx_self_tests *efx_tests;
128 	bool already_up;
129 	int rc = -ENOMEM;
130 
131 	efx_tests = kzalloc(sizeof(*efx_tests), GFP_KERNEL);
132 	if (!efx_tests)
133 		goto fail;
134 
135 	if (efx->state != STATE_READY) {
136 		rc = -EBUSY;
137 		goto out;
138 	}
139 
140 	netif_info(efx, drv, efx->net_dev, "starting %sline testing\n",
141 		   (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
142 
143 	/* We need rx buffers and interrupts. */
144 	already_up = (efx->net_dev->flags & IFF_UP);
145 	if (!already_up) {
146 		rc = dev_open(efx->net_dev, NULL);
147 		if (rc) {
148 			netif_err(efx, drv, efx->net_dev,
149 				  "failed opening device.\n");
150 			goto out;
151 		}
152 	}
153 
154 	rc = efx_selftest(efx, efx_tests, test->flags);
155 
156 	if (!already_up)
157 		dev_close(efx->net_dev);
158 
159 	netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n",
160 		   rc == 0 ? "passed" : "failed",
161 		   (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
162 
163 out:
164 	efx_ethtool_fill_self_tests(efx, efx_tests, NULL, data);
165 	kfree(efx_tests);
166 fail:
167 	if (rc)
168 		test->flags |= ETH_TEST_FL_FAILED;
169 }
170 
171 /* Restart autonegotiation */
172 static int efx_ethtool_nway_reset(struct net_device *net_dev)
173 {
174 	struct efx_nic *efx = netdev_priv(net_dev);
175 
176 	return mdio45_nway_restart(&efx->mdio);
177 }
178 
179 /*
180  * Each channel has a single IRQ and moderation timer, started by any
181  * completion (or other event).  Unless the module parameter
182  * separate_tx_channels is set, IRQs and moderation are therefore
183  * shared between RX and TX completions.  In this case, when RX IRQ
184  * moderation is explicitly changed then TX IRQ moderation is
185  * automatically changed too, but otherwise we fail if the two values
186  * are requested to be different.
187  *
188  * The hardware does not support a limit on the number of completions
189  * before an IRQ, so we do not use the max_frames fields.  We should
190  * report and require that max_frames == (usecs != 0), but this would
191  * invalidate existing user documentation.
192  *
193  * The hardware does not have distinct settings for interrupt
194  * moderation while the previous IRQ is being handled, so we should
195  * not use the 'irq' fields.  However, an earlier developer
196  * misunderstood the meaning of the 'irq' fields and the driver did
197  * not support the standard fields.  To avoid invalidating existing
198  * user documentation, we report and accept changes through either the
199  * standard or 'irq' fields.  If both are changed at the same time, we
200  * prefer the standard field.
201  *
202  * We implement adaptive IRQ moderation, but use a different algorithm
203  * from that assumed in the definition of struct ethtool_coalesce.
204  * Therefore we do not use any of the adaptive moderation parameters
205  * in it.
206  */
207 
208 static int efx_ethtool_get_coalesce(struct net_device *net_dev,
209 				    struct ethtool_coalesce *coalesce)
210 {
211 	struct efx_nic *efx = netdev_priv(net_dev);
212 	unsigned int tx_usecs, rx_usecs;
213 	bool rx_adaptive;
214 
215 	efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &rx_adaptive);
216 
217 	coalesce->tx_coalesce_usecs = tx_usecs;
218 	coalesce->tx_coalesce_usecs_irq = tx_usecs;
219 	coalesce->rx_coalesce_usecs = rx_usecs;
220 	coalesce->rx_coalesce_usecs_irq = rx_usecs;
221 	coalesce->use_adaptive_rx_coalesce = rx_adaptive;
222 
223 	return 0;
224 }
225 
226 static int efx_ethtool_set_coalesce(struct net_device *net_dev,
227 				    struct ethtool_coalesce *coalesce)
228 {
229 	struct efx_nic *efx = netdev_priv(net_dev);
230 	struct efx_channel *channel;
231 	unsigned int tx_usecs, rx_usecs;
232 	bool adaptive, rx_may_override_tx;
233 	int rc;
234 
235 	if (coalesce->use_adaptive_tx_coalesce)
236 		return -EINVAL;
237 
238 	efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &adaptive);
239 
240 	if (coalesce->rx_coalesce_usecs != rx_usecs)
241 		rx_usecs = coalesce->rx_coalesce_usecs;
242 	else
243 		rx_usecs = coalesce->rx_coalesce_usecs_irq;
244 
245 	adaptive = coalesce->use_adaptive_rx_coalesce;
246 
247 	/* If channels are shared, TX IRQ moderation can be quietly
248 	 * overridden unless it is changed from its old value.
249 	 */
250 	rx_may_override_tx = (coalesce->tx_coalesce_usecs == tx_usecs &&
251 			      coalesce->tx_coalesce_usecs_irq == tx_usecs);
252 	if (coalesce->tx_coalesce_usecs != tx_usecs)
253 		tx_usecs = coalesce->tx_coalesce_usecs;
254 	else
255 		tx_usecs = coalesce->tx_coalesce_usecs_irq;
256 
257 	rc = efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive,
258 				     rx_may_override_tx);
259 	if (rc != 0)
260 		return rc;
261 
262 	efx_for_each_channel(channel, efx)
263 		efx->type->push_irq_moderation(channel);
264 
265 	return 0;
266 }
267 
268 static void efx_ethtool_get_ringparam(struct net_device *net_dev,
269 				      struct ethtool_ringparam *ring)
270 {
271 	struct efx_nic *efx = netdev_priv(net_dev);
272 
273 	ring->rx_max_pending = EFX_MAX_DMAQ_SIZE;
274 	ring->tx_max_pending = EFX_TXQ_MAX_ENT(efx);
275 	ring->rx_pending = efx->rxq_entries;
276 	ring->tx_pending = efx->txq_entries;
277 }
278 
279 static int efx_ethtool_set_ringparam(struct net_device *net_dev,
280 				     struct ethtool_ringparam *ring)
281 {
282 	struct efx_nic *efx = netdev_priv(net_dev);
283 	u32 txq_entries;
284 
285 	if (ring->rx_mini_pending || ring->rx_jumbo_pending ||
286 	    ring->rx_pending > EFX_MAX_DMAQ_SIZE ||
287 	    ring->tx_pending > EFX_TXQ_MAX_ENT(efx))
288 		return -EINVAL;
289 
290 	if (ring->rx_pending < EFX_RXQ_MIN_ENT) {
291 		netif_err(efx, drv, efx->net_dev,
292 			  "RX queues cannot be smaller than %u\n",
293 			  EFX_RXQ_MIN_ENT);
294 		return -EINVAL;
295 	}
296 
297 	txq_entries = max(ring->tx_pending, EFX_TXQ_MIN_ENT(efx));
298 	if (txq_entries != ring->tx_pending)
299 		netif_warn(efx, drv, efx->net_dev,
300 			   "increasing TX queue size to minimum of %u\n",
301 			   txq_entries);
302 
303 	return efx_realloc_channels(efx, ring->rx_pending, txq_entries);
304 }
305 
306 static int efx_ethtool_set_pauseparam(struct net_device *net_dev,
307 				      struct ethtool_pauseparam *pause)
308 {
309 	struct efx_nic *efx = netdev_priv(net_dev);
310 	u8 wanted_fc, old_fc;
311 	u32 old_adv;
312 	int rc = 0;
313 
314 	mutex_lock(&efx->mac_lock);
315 
316 	wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
317 		     (pause->tx_pause ? EFX_FC_TX : 0) |
318 		     (pause->autoneg ? EFX_FC_AUTO : 0));
319 
320 	if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
321 		netif_dbg(efx, drv, efx->net_dev,
322 			  "Flow control unsupported: tx ON rx OFF\n");
323 		rc = -EINVAL;
324 		goto out;
325 	}
326 
327 	if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising[0]) {
328 		netif_dbg(efx, drv, efx->net_dev,
329 			  "Autonegotiation is disabled\n");
330 		rc = -EINVAL;
331 		goto out;
332 	}
333 
334 	/* Hook for Falcon bug 11482 workaround */
335 	if (efx->type->prepare_enable_fc_tx &&
336 	    (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX))
337 		efx->type->prepare_enable_fc_tx(efx);
338 
339 	old_adv = efx->link_advertising[0];
340 	old_fc = efx->wanted_fc;
341 	efx_link_set_wanted_fc(efx, wanted_fc);
342 	if (efx->link_advertising[0] != old_adv ||
343 	    (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) {
344 		rc = efx->phy_op->reconfigure(efx);
345 		if (rc) {
346 			netif_err(efx, drv, efx->net_dev,
347 				  "Unable to advertise requested flow "
348 				  "control setting\n");
349 			goto out;
350 		}
351 	}
352 
353 	/* Reconfigure the MAC. The PHY *may* generate a link state change event
354 	 * if the user just changed the advertised capabilities, but there's no
355 	 * harm doing this twice */
356 	efx_mac_reconfigure(efx);
357 
358 out:
359 	mutex_unlock(&efx->mac_lock);
360 
361 	return rc;
362 }
363 
364 static void efx_ethtool_get_wol(struct net_device *net_dev,
365 				struct ethtool_wolinfo *wol)
366 {
367 	struct efx_nic *efx = netdev_priv(net_dev);
368 	return efx->type->get_wol(efx, wol);
369 }
370 
371 
372 static int efx_ethtool_set_wol(struct net_device *net_dev,
373 			       struct ethtool_wolinfo *wol)
374 {
375 	struct efx_nic *efx = netdev_priv(net_dev);
376 	return efx->type->set_wol(efx, wol->wolopts);
377 }
378 
379 static int efx_ethtool_reset(struct net_device *net_dev, u32 *flags)
380 {
381 	struct efx_nic *efx = netdev_priv(net_dev);
382 	int rc;
383 
384 	rc = efx->type->map_reset_flags(flags);
385 	if (rc < 0)
386 		return rc;
387 
388 	return efx_reset(efx, rc);
389 }
390 
391 /* MAC address mask including only I/G bit */
392 static const u8 mac_addr_ig_mask[ETH_ALEN] __aligned(2) = {0x01, 0, 0, 0, 0, 0};
393 
394 #define IP4_ADDR_FULL_MASK	((__force __be32)~0)
395 #define IP_PROTO_FULL_MASK	0xFF
396 #define PORT_FULL_MASK		((__force __be16)~0)
397 #define ETHER_TYPE_FULL_MASK	((__force __be16)~0)
398 
399 static inline void ip6_fill_mask(__be32 *mask)
400 {
401 	mask[0] = mask[1] = mask[2] = mask[3] = ~(__be32)0;
402 }
403 
404 static int efx_ethtool_get_class_rule(struct efx_nic *efx,
405 				      struct ethtool_rx_flow_spec *rule,
406 				      u32 *rss_context)
407 {
408 	struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
409 	struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
410 	struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
411 	struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
412 	struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
413 	struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
414 	struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
415 	struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
416 	struct ethhdr *mac_entry = &rule->h_u.ether_spec;
417 	struct ethhdr *mac_mask = &rule->m_u.ether_spec;
418 	struct efx_filter_spec spec;
419 	int rc;
420 
421 	rc = efx_filter_get_filter_safe(efx, EFX_FILTER_PRI_MANUAL,
422 					rule->location, &spec);
423 	if (rc)
424 		return rc;
425 
426 	if (spec.dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP)
427 		rule->ring_cookie = RX_CLS_FLOW_DISC;
428 	else
429 		rule->ring_cookie = spec.dmaq_id;
430 
431 	if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) &&
432 	    spec.ether_type == htons(ETH_P_IP) &&
433 	    (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) &&
434 	    (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
435 	    !(spec.match_flags &
436 	      ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
437 		EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
438 		EFX_FILTER_MATCH_IP_PROTO |
439 		EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) {
440 		rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
441 				   TCP_V4_FLOW : UDP_V4_FLOW);
442 		if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
443 			ip_entry->ip4dst = spec.loc_host[0];
444 			ip_mask->ip4dst = IP4_ADDR_FULL_MASK;
445 		}
446 		if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
447 			ip_entry->ip4src = spec.rem_host[0];
448 			ip_mask->ip4src = IP4_ADDR_FULL_MASK;
449 		}
450 		if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) {
451 			ip_entry->pdst = spec.loc_port;
452 			ip_mask->pdst = PORT_FULL_MASK;
453 		}
454 		if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) {
455 			ip_entry->psrc = spec.rem_port;
456 			ip_mask->psrc = PORT_FULL_MASK;
457 		}
458 	} else if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) &&
459 	    spec.ether_type == htons(ETH_P_IPV6) &&
460 	    (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) &&
461 	    (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
462 	    !(spec.match_flags &
463 	      ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
464 		EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
465 		EFX_FILTER_MATCH_IP_PROTO |
466 		EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) {
467 		rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
468 				   TCP_V6_FLOW : UDP_V6_FLOW);
469 		if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
470 			memcpy(ip6_entry->ip6dst, spec.loc_host,
471 			       sizeof(ip6_entry->ip6dst));
472 			ip6_fill_mask(ip6_mask->ip6dst);
473 		}
474 		if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
475 			memcpy(ip6_entry->ip6src, spec.rem_host,
476 			       sizeof(ip6_entry->ip6src));
477 			ip6_fill_mask(ip6_mask->ip6src);
478 		}
479 		if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) {
480 			ip6_entry->pdst = spec.loc_port;
481 			ip6_mask->pdst = PORT_FULL_MASK;
482 		}
483 		if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) {
484 			ip6_entry->psrc = spec.rem_port;
485 			ip6_mask->psrc = PORT_FULL_MASK;
486 		}
487 	} else if (!(spec.match_flags &
488 		     ~(EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG |
489 		       EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_ETHER_TYPE |
490 		       EFX_FILTER_MATCH_OUTER_VID))) {
491 		rule->flow_type = ETHER_FLOW;
492 		if (spec.match_flags &
493 		    (EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG)) {
494 			ether_addr_copy(mac_entry->h_dest, spec.loc_mac);
495 			if (spec.match_flags & EFX_FILTER_MATCH_LOC_MAC)
496 				eth_broadcast_addr(mac_mask->h_dest);
497 			else
498 				ether_addr_copy(mac_mask->h_dest,
499 						mac_addr_ig_mask);
500 		}
501 		if (spec.match_flags & EFX_FILTER_MATCH_REM_MAC) {
502 			ether_addr_copy(mac_entry->h_source, spec.rem_mac);
503 			eth_broadcast_addr(mac_mask->h_source);
504 		}
505 		if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) {
506 			mac_entry->h_proto = spec.ether_type;
507 			mac_mask->h_proto = ETHER_TYPE_FULL_MASK;
508 		}
509 	} else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
510 		   spec.ether_type == htons(ETH_P_IP) &&
511 		   !(spec.match_flags &
512 		     ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
513 		       EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
514 		       EFX_FILTER_MATCH_IP_PROTO))) {
515 		rule->flow_type = IPV4_USER_FLOW;
516 		uip_entry->ip_ver = ETH_RX_NFC_IP4;
517 		if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) {
518 			uip_mask->proto = IP_PROTO_FULL_MASK;
519 			uip_entry->proto = spec.ip_proto;
520 		}
521 		if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
522 			uip_entry->ip4dst = spec.loc_host[0];
523 			uip_mask->ip4dst = IP4_ADDR_FULL_MASK;
524 		}
525 		if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
526 			uip_entry->ip4src = spec.rem_host[0];
527 			uip_mask->ip4src = IP4_ADDR_FULL_MASK;
528 		}
529 	} else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
530 		   spec.ether_type == htons(ETH_P_IPV6) &&
531 		   !(spec.match_flags &
532 		     ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
533 		       EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
534 		       EFX_FILTER_MATCH_IP_PROTO))) {
535 		rule->flow_type = IPV6_USER_FLOW;
536 		if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) {
537 			uip6_mask->l4_proto = IP_PROTO_FULL_MASK;
538 			uip6_entry->l4_proto = spec.ip_proto;
539 		}
540 		if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
541 			memcpy(uip6_entry->ip6dst, spec.loc_host,
542 			       sizeof(uip6_entry->ip6dst));
543 			ip6_fill_mask(uip6_mask->ip6dst);
544 		}
545 		if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
546 			memcpy(uip6_entry->ip6src, spec.rem_host,
547 			       sizeof(uip6_entry->ip6src));
548 			ip6_fill_mask(uip6_mask->ip6src);
549 		}
550 	} else {
551 		/* The above should handle all filters that we insert */
552 		WARN_ON(1);
553 		return -EINVAL;
554 	}
555 
556 	if (spec.match_flags & EFX_FILTER_MATCH_OUTER_VID) {
557 		rule->flow_type |= FLOW_EXT;
558 		rule->h_ext.vlan_tci = spec.outer_vid;
559 		rule->m_ext.vlan_tci = htons(0xfff);
560 	}
561 
562 	if (spec.flags & EFX_FILTER_FLAG_RX_RSS) {
563 		rule->flow_type |= FLOW_RSS;
564 		*rss_context = spec.rss_context;
565 	}
566 
567 	return rc;
568 }
569 
570 static int
571 efx_ethtool_get_rxnfc(struct net_device *net_dev,
572 		      struct ethtool_rxnfc *info, u32 *rule_locs)
573 {
574 	struct efx_nic *efx = netdev_priv(net_dev);
575 	u32 rss_context = 0;
576 	s32 rc = 0;
577 
578 	switch (info->cmd) {
579 	case ETHTOOL_GRXRINGS:
580 		info->data = efx->n_rx_channels;
581 		return 0;
582 
583 	case ETHTOOL_GRXFH: {
584 		struct efx_rss_context *ctx = &efx->rss_context;
585 		__u64 data;
586 
587 		mutex_lock(&efx->rss_lock);
588 		if (info->flow_type & FLOW_RSS && info->rss_context) {
589 			ctx = efx_find_rss_context_entry(efx, info->rss_context);
590 			if (!ctx) {
591 				rc = -ENOENT;
592 				goto out_unlock;
593 			}
594 		}
595 
596 		data = 0;
597 		if (!efx_rss_active(ctx)) /* No RSS */
598 			goto out_setdata_unlock;
599 
600 		switch (info->flow_type & ~FLOW_RSS) {
601 		case UDP_V4_FLOW:
602 		case UDP_V6_FLOW:
603 			if (ctx->rx_hash_udp_4tuple)
604 				data = (RXH_L4_B_0_1 | RXH_L4_B_2_3 |
605 					RXH_IP_SRC | RXH_IP_DST);
606 			else
607 				data = RXH_IP_SRC | RXH_IP_DST;
608 			break;
609 		case TCP_V4_FLOW:
610 		case TCP_V6_FLOW:
611 			data = (RXH_L4_B_0_1 | RXH_L4_B_2_3 |
612 				RXH_IP_SRC | RXH_IP_DST);
613 			break;
614 		case SCTP_V4_FLOW:
615 		case SCTP_V6_FLOW:
616 		case AH_ESP_V4_FLOW:
617 		case AH_ESP_V6_FLOW:
618 		case IPV4_FLOW:
619 		case IPV6_FLOW:
620 			data = RXH_IP_SRC | RXH_IP_DST;
621 			break;
622 		default:
623 			break;
624 		}
625 out_setdata_unlock:
626 		info->data = data;
627 out_unlock:
628 		mutex_unlock(&efx->rss_lock);
629 		return rc;
630 	}
631 
632 	case ETHTOOL_GRXCLSRLCNT:
633 		info->data = efx_filter_get_rx_id_limit(efx);
634 		if (info->data == 0)
635 			return -EOPNOTSUPP;
636 		info->data |= RX_CLS_LOC_SPECIAL;
637 		info->rule_cnt =
638 			efx_filter_count_rx_used(efx, EFX_FILTER_PRI_MANUAL);
639 		return 0;
640 
641 	case ETHTOOL_GRXCLSRULE:
642 		if (efx_filter_get_rx_id_limit(efx) == 0)
643 			return -EOPNOTSUPP;
644 		rc = efx_ethtool_get_class_rule(efx, &info->fs, &rss_context);
645 		if (rc < 0)
646 			return rc;
647 		if (info->fs.flow_type & FLOW_RSS)
648 			info->rss_context = rss_context;
649 		return 0;
650 
651 	case ETHTOOL_GRXCLSRLALL:
652 		info->data = efx_filter_get_rx_id_limit(efx);
653 		if (info->data == 0)
654 			return -EOPNOTSUPP;
655 		rc = efx_filter_get_rx_ids(efx, EFX_FILTER_PRI_MANUAL,
656 					   rule_locs, info->rule_cnt);
657 		if (rc < 0)
658 			return rc;
659 		info->rule_cnt = rc;
660 		return 0;
661 
662 	default:
663 		return -EOPNOTSUPP;
664 	}
665 }
666 
667 static inline bool ip6_mask_is_full(__be32 mask[4])
668 {
669 	return !~(mask[0] & mask[1] & mask[2] & mask[3]);
670 }
671 
672 static inline bool ip6_mask_is_empty(__be32 mask[4])
673 {
674 	return !(mask[0] | mask[1] | mask[2] | mask[3]);
675 }
676 
677 static int efx_ethtool_set_class_rule(struct efx_nic *efx,
678 				      struct ethtool_rx_flow_spec *rule,
679 				      u32 rss_context)
680 {
681 	struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
682 	struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
683 	struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
684 	struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
685 	struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
686 	struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
687 	struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
688 	struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
689 	u32 flow_type = rule->flow_type & ~(FLOW_EXT | FLOW_RSS);
690 	struct ethhdr *mac_entry = &rule->h_u.ether_spec;
691 	struct ethhdr *mac_mask = &rule->m_u.ether_spec;
692 	enum efx_filter_flags flags = 0;
693 	struct efx_filter_spec spec;
694 	int rc;
695 
696 	/* Check that user wants us to choose the location */
697 	if (rule->location != RX_CLS_LOC_ANY)
698 		return -EINVAL;
699 
700 	/* Range-check ring_cookie */
701 	if (rule->ring_cookie >= efx->n_rx_channels &&
702 	    rule->ring_cookie != RX_CLS_FLOW_DISC)
703 		return -EINVAL;
704 
705 	/* Check for unsupported extensions */
706 	if ((rule->flow_type & FLOW_EXT) &&
707 	    (rule->m_ext.vlan_etype || rule->m_ext.data[0] ||
708 	     rule->m_ext.data[1]))
709 		return -EINVAL;
710 
711 	if (efx->rx_scatter)
712 		flags |= EFX_FILTER_FLAG_RX_SCATTER;
713 	if (rule->flow_type & FLOW_RSS)
714 		flags |= EFX_FILTER_FLAG_RX_RSS;
715 
716 	efx_filter_init_rx(&spec, EFX_FILTER_PRI_MANUAL, flags,
717 			   (rule->ring_cookie == RX_CLS_FLOW_DISC) ?
718 			   EFX_FILTER_RX_DMAQ_ID_DROP : rule->ring_cookie);
719 
720 	if (rule->flow_type & FLOW_RSS)
721 		spec.rss_context = rss_context;
722 
723 	switch (flow_type) {
724 	case TCP_V4_FLOW:
725 	case UDP_V4_FLOW:
726 		spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
727 				    EFX_FILTER_MATCH_IP_PROTO);
728 		spec.ether_type = htons(ETH_P_IP);
729 		spec.ip_proto = flow_type == TCP_V4_FLOW ? IPPROTO_TCP
730 							 : IPPROTO_UDP;
731 		if (ip_mask->ip4dst) {
732 			if (ip_mask->ip4dst != IP4_ADDR_FULL_MASK)
733 				return -EINVAL;
734 			spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
735 			spec.loc_host[0] = ip_entry->ip4dst;
736 		}
737 		if (ip_mask->ip4src) {
738 			if (ip_mask->ip4src != IP4_ADDR_FULL_MASK)
739 				return -EINVAL;
740 			spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
741 			spec.rem_host[0] = ip_entry->ip4src;
742 		}
743 		if (ip_mask->pdst) {
744 			if (ip_mask->pdst != PORT_FULL_MASK)
745 				return -EINVAL;
746 			spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
747 			spec.loc_port = ip_entry->pdst;
748 		}
749 		if (ip_mask->psrc) {
750 			if (ip_mask->psrc != PORT_FULL_MASK)
751 				return -EINVAL;
752 			spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
753 			spec.rem_port = ip_entry->psrc;
754 		}
755 		if (ip_mask->tos)
756 			return -EINVAL;
757 		break;
758 
759 	case TCP_V6_FLOW:
760 	case UDP_V6_FLOW:
761 		spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
762 				    EFX_FILTER_MATCH_IP_PROTO);
763 		spec.ether_type = htons(ETH_P_IPV6);
764 		spec.ip_proto = flow_type == TCP_V6_FLOW ? IPPROTO_TCP
765 							 : IPPROTO_UDP;
766 		if (!ip6_mask_is_empty(ip6_mask->ip6dst)) {
767 			if (!ip6_mask_is_full(ip6_mask->ip6dst))
768 				return -EINVAL;
769 			spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
770 			memcpy(spec.loc_host, ip6_entry->ip6dst, sizeof(spec.loc_host));
771 		}
772 		if (!ip6_mask_is_empty(ip6_mask->ip6src)) {
773 			if (!ip6_mask_is_full(ip6_mask->ip6src))
774 				return -EINVAL;
775 			spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
776 			memcpy(spec.rem_host, ip6_entry->ip6src, sizeof(spec.rem_host));
777 		}
778 		if (ip6_mask->pdst) {
779 			if (ip6_mask->pdst != PORT_FULL_MASK)
780 				return -EINVAL;
781 			spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
782 			spec.loc_port = ip6_entry->pdst;
783 		}
784 		if (ip6_mask->psrc) {
785 			if (ip6_mask->psrc != PORT_FULL_MASK)
786 				return -EINVAL;
787 			spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
788 			spec.rem_port = ip6_entry->psrc;
789 		}
790 		if (ip6_mask->tclass)
791 			return -EINVAL;
792 		break;
793 
794 	case IPV4_USER_FLOW:
795 		if (uip_mask->l4_4_bytes || uip_mask->tos || uip_mask->ip_ver ||
796 		    uip_entry->ip_ver != ETH_RX_NFC_IP4)
797 			return -EINVAL;
798 		spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE;
799 		spec.ether_type = htons(ETH_P_IP);
800 		if (uip_mask->ip4dst) {
801 			if (uip_mask->ip4dst != IP4_ADDR_FULL_MASK)
802 				return -EINVAL;
803 			spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
804 			spec.loc_host[0] = uip_entry->ip4dst;
805 		}
806 		if (uip_mask->ip4src) {
807 			if (uip_mask->ip4src != IP4_ADDR_FULL_MASK)
808 				return -EINVAL;
809 			spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
810 			spec.rem_host[0] = uip_entry->ip4src;
811 		}
812 		if (uip_mask->proto) {
813 			if (uip_mask->proto != IP_PROTO_FULL_MASK)
814 				return -EINVAL;
815 			spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO;
816 			spec.ip_proto = uip_entry->proto;
817 		}
818 		break;
819 
820 	case IPV6_USER_FLOW:
821 		if (uip6_mask->l4_4_bytes || uip6_mask->tclass)
822 			return -EINVAL;
823 		spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE;
824 		spec.ether_type = htons(ETH_P_IPV6);
825 		if (!ip6_mask_is_empty(uip6_mask->ip6dst)) {
826 			if (!ip6_mask_is_full(uip6_mask->ip6dst))
827 				return -EINVAL;
828 			spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
829 			memcpy(spec.loc_host, uip6_entry->ip6dst, sizeof(spec.loc_host));
830 		}
831 		if (!ip6_mask_is_empty(uip6_mask->ip6src)) {
832 			if (!ip6_mask_is_full(uip6_mask->ip6src))
833 				return -EINVAL;
834 			spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
835 			memcpy(spec.rem_host, uip6_entry->ip6src, sizeof(spec.rem_host));
836 		}
837 		if (uip6_mask->l4_proto) {
838 			if (uip6_mask->l4_proto != IP_PROTO_FULL_MASK)
839 				return -EINVAL;
840 			spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO;
841 			spec.ip_proto = uip6_entry->l4_proto;
842 		}
843 		break;
844 
845 	case ETHER_FLOW:
846 		if (!is_zero_ether_addr(mac_mask->h_dest)) {
847 			if (ether_addr_equal(mac_mask->h_dest,
848 					     mac_addr_ig_mask))
849 				spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC_IG;
850 			else if (is_broadcast_ether_addr(mac_mask->h_dest))
851 				spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC;
852 			else
853 				return -EINVAL;
854 			ether_addr_copy(spec.loc_mac, mac_entry->h_dest);
855 		}
856 		if (!is_zero_ether_addr(mac_mask->h_source)) {
857 			if (!is_broadcast_ether_addr(mac_mask->h_source))
858 				return -EINVAL;
859 			spec.match_flags |= EFX_FILTER_MATCH_REM_MAC;
860 			ether_addr_copy(spec.rem_mac, mac_entry->h_source);
861 		}
862 		if (mac_mask->h_proto) {
863 			if (mac_mask->h_proto != ETHER_TYPE_FULL_MASK)
864 				return -EINVAL;
865 			spec.match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
866 			spec.ether_type = mac_entry->h_proto;
867 		}
868 		break;
869 
870 	default:
871 		return -EINVAL;
872 	}
873 
874 	if ((rule->flow_type & FLOW_EXT) && rule->m_ext.vlan_tci) {
875 		if (rule->m_ext.vlan_tci != htons(0xfff))
876 			return -EINVAL;
877 		spec.match_flags |= EFX_FILTER_MATCH_OUTER_VID;
878 		spec.outer_vid = rule->h_ext.vlan_tci;
879 	}
880 
881 	rc = efx_filter_insert_filter(efx, &spec, true);
882 	if (rc < 0)
883 		return rc;
884 
885 	rule->location = rc;
886 	return 0;
887 }
888 
889 static int efx_ethtool_set_rxnfc(struct net_device *net_dev,
890 				 struct ethtool_rxnfc *info)
891 {
892 	struct efx_nic *efx = netdev_priv(net_dev);
893 
894 	if (efx_filter_get_rx_id_limit(efx) == 0)
895 		return -EOPNOTSUPP;
896 
897 	switch (info->cmd) {
898 	case ETHTOOL_SRXCLSRLINS:
899 		return efx_ethtool_set_class_rule(efx, &info->fs,
900 						  info->rss_context);
901 
902 	case ETHTOOL_SRXCLSRLDEL:
903 		return efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_MANUAL,
904 						 info->fs.location);
905 
906 	default:
907 		return -EOPNOTSUPP;
908 	}
909 }
910 
911 static u32 efx_ethtool_get_rxfh_indir_size(struct net_device *net_dev)
912 {
913 	struct efx_nic *efx = netdev_priv(net_dev);
914 
915 	if (efx->n_rx_channels == 1)
916 		return 0;
917 	return ARRAY_SIZE(efx->rss_context.rx_indir_table);
918 }
919 
920 static u32 efx_ethtool_get_rxfh_key_size(struct net_device *net_dev)
921 {
922 	struct efx_nic *efx = netdev_priv(net_dev);
923 
924 	return efx->type->rx_hash_key_size;
925 }
926 
927 static int efx_ethtool_get_rxfh(struct net_device *net_dev, u32 *indir, u8 *key,
928 				u8 *hfunc)
929 {
930 	struct efx_nic *efx = netdev_priv(net_dev);
931 	int rc;
932 
933 	rc = efx->type->rx_pull_rss_config(efx);
934 	if (rc)
935 		return rc;
936 
937 	if (hfunc)
938 		*hfunc = ETH_RSS_HASH_TOP;
939 	if (indir)
940 		memcpy(indir, efx->rss_context.rx_indir_table,
941 		       sizeof(efx->rss_context.rx_indir_table));
942 	if (key)
943 		memcpy(key, efx->rss_context.rx_hash_key,
944 		       efx->type->rx_hash_key_size);
945 	return 0;
946 }
947 
948 static int efx_ethtool_set_rxfh(struct net_device *net_dev, const u32 *indir,
949 				const u8 *key, const u8 hfunc)
950 {
951 	struct efx_nic *efx = netdev_priv(net_dev);
952 
953 	/* Hash function is Toeplitz, cannot be changed */
954 	if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
955 		return -EOPNOTSUPP;
956 	if (!indir && !key)
957 		return 0;
958 
959 	if (!key)
960 		key = efx->rss_context.rx_hash_key;
961 	if (!indir)
962 		indir = efx->rss_context.rx_indir_table;
963 
964 	return efx->type->rx_push_rss_config(efx, true, indir, key);
965 }
966 
967 static int efx_ethtool_get_rxfh_context(struct net_device *net_dev, u32 *indir,
968 					u8 *key, u8 *hfunc, u32 rss_context)
969 {
970 	struct efx_nic *efx = netdev_priv(net_dev);
971 	struct efx_rss_context *ctx;
972 	int rc = 0;
973 
974 	if (!efx->type->rx_pull_rss_context_config)
975 		return -EOPNOTSUPP;
976 
977 	mutex_lock(&efx->rss_lock);
978 	ctx = efx_find_rss_context_entry(efx, rss_context);
979 	if (!ctx) {
980 		rc = -ENOENT;
981 		goto out_unlock;
982 	}
983 	rc = efx->type->rx_pull_rss_context_config(efx, ctx);
984 	if (rc)
985 		goto out_unlock;
986 
987 	if (hfunc)
988 		*hfunc = ETH_RSS_HASH_TOP;
989 	if (indir)
990 		memcpy(indir, ctx->rx_indir_table, sizeof(ctx->rx_indir_table));
991 	if (key)
992 		memcpy(key, ctx->rx_hash_key, efx->type->rx_hash_key_size);
993 out_unlock:
994 	mutex_unlock(&efx->rss_lock);
995 	return rc;
996 }
997 
998 static int efx_ethtool_set_rxfh_context(struct net_device *net_dev,
999 					const u32 *indir, const u8 *key,
1000 					const u8 hfunc, u32 *rss_context,
1001 					bool delete)
1002 {
1003 	struct efx_nic *efx = netdev_priv(net_dev);
1004 	struct efx_rss_context *ctx;
1005 	bool allocated = false;
1006 	int rc;
1007 
1008 	if (!efx->type->rx_push_rss_context_config)
1009 		return -EOPNOTSUPP;
1010 	/* Hash function is Toeplitz, cannot be changed */
1011 	if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1012 		return -EOPNOTSUPP;
1013 
1014 	mutex_lock(&efx->rss_lock);
1015 
1016 	if (*rss_context == ETH_RXFH_CONTEXT_ALLOC) {
1017 		if (delete) {
1018 			/* alloc + delete == Nothing to do */
1019 			rc = -EINVAL;
1020 			goto out_unlock;
1021 		}
1022 		ctx = efx_alloc_rss_context_entry(efx);
1023 		if (!ctx) {
1024 			rc = -ENOMEM;
1025 			goto out_unlock;
1026 		}
1027 		ctx->context_id = EFX_MCDI_RSS_CONTEXT_INVALID;
1028 		/* Initialise indir table and key to defaults */
1029 		efx_set_default_rx_indir_table(efx, ctx);
1030 		netdev_rss_key_fill(ctx->rx_hash_key, sizeof(ctx->rx_hash_key));
1031 		allocated = true;
1032 	} else {
1033 		ctx = efx_find_rss_context_entry(efx, *rss_context);
1034 		if (!ctx) {
1035 			rc = -ENOENT;
1036 			goto out_unlock;
1037 		}
1038 	}
1039 
1040 	if (delete) {
1041 		/* delete this context */
1042 		rc = efx->type->rx_push_rss_context_config(efx, ctx, NULL, NULL);
1043 		if (!rc)
1044 			efx_free_rss_context_entry(ctx);
1045 		goto out_unlock;
1046 	}
1047 
1048 	if (!key)
1049 		key = ctx->rx_hash_key;
1050 	if (!indir)
1051 		indir = ctx->rx_indir_table;
1052 
1053 	rc = efx->type->rx_push_rss_context_config(efx, ctx, indir, key);
1054 	if (rc && allocated)
1055 		efx_free_rss_context_entry(ctx);
1056 	else
1057 		*rss_context = ctx->user_id;
1058 out_unlock:
1059 	mutex_unlock(&efx->rss_lock);
1060 	return rc;
1061 }
1062 
1063 static int efx_ethtool_get_ts_info(struct net_device *net_dev,
1064 				   struct ethtool_ts_info *ts_info)
1065 {
1066 	struct efx_nic *efx = netdev_priv(net_dev);
1067 
1068 	/* Software capabilities */
1069 	ts_info->so_timestamping = (SOF_TIMESTAMPING_RX_SOFTWARE |
1070 				    SOF_TIMESTAMPING_SOFTWARE);
1071 	ts_info->phc_index = -1;
1072 
1073 	efx_ptp_get_ts_info(efx, ts_info);
1074 	return 0;
1075 }
1076 
1077 static int efx_ethtool_get_module_eeprom(struct net_device *net_dev,
1078 					 struct ethtool_eeprom *ee,
1079 					 u8 *data)
1080 {
1081 	struct efx_nic *efx = netdev_priv(net_dev);
1082 	int ret;
1083 
1084 	if (!efx->phy_op || !efx->phy_op->get_module_eeprom)
1085 		return -EOPNOTSUPP;
1086 
1087 	mutex_lock(&efx->mac_lock);
1088 	ret = efx->phy_op->get_module_eeprom(efx, ee, data);
1089 	mutex_unlock(&efx->mac_lock);
1090 
1091 	return ret;
1092 }
1093 
1094 static int efx_ethtool_get_module_info(struct net_device *net_dev,
1095 				       struct ethtool_modinfo *modinfo)
1096 {
1097 	struct efx_nic *efx = netdev_priv(net_dev);
1098 	int ret;
1099 
1100 	if (!efx->phy_op || !efx->phy_op->get_module_info)
1101 		return -EOPNOTSUPP;
1102 
1103 	mutex_lock(&efx->mac_lock);
1104 	ret = efx->phy_op->get_module_info(efx, modinfo);
1105 	mutex_unlock(&efx->mac_lock);
1106 
1107 	return ret;
1108 }
1109 
1110 static int efx_ethtool_get_fecparam(struct net_device *net_dev,
1111 				    struct ethtool_fecparam *fecparam)
1112 {
1113 	struct efx_nic *efx = netdev_priv(net_dev);
1114 	int rc;
1115 
1116 	if (!efx->phy_op || !efx->phy_op->get_fecparam)
1117 		return -EOPNOTSUPP;
1118 	mutex_lock(&efx->mac_lock);
1119 	rc = efx->phy_op->get_fecparam(efx, fecparam);
1120 	mutex_unlock(&efx->mac_lock);
1121 
1122 	return rc;
1123 }
1124 
1125 static int efx_ethtool_set_fecparam(struct net_device *net_dev,
1126 				    struct ethtool_fecparam *fecparam)
1127 {
1128 	struct efx_nic *efx = netdev_priv(net_dev);
1129 	int rc;
1130 
1131 	if (!efx->phy_op || !efx->phy_op->get_fecparam)
1132 		return -EOPNOTSUPP;
1133 	mutex_lock(&efx->mac_lock);
1134 	rc = efx->phy_op->set_fecparam(efx, fecparam);
1135 	mutex_unlock(&efx->mac_lock);
1136 
1137 	return rc;
1138 }
1139 
1140 const struct ethtool_ops efx_ethtool_ops = {
1141 	.get_drvinfo		= efx_ethtool_get_drvinfo,
1142 	.get_regs_len		= efx_ethtool_get_regs_len,
1143 	.get_regs		= efx_ethtool_get_regs,
1144 	.get_msglevel		= efx_ethtool_get_msglevel,
1145 	.set_msglevel		= efx_ethtool_set_msglevel,
1146 	.nway_reset		= efx_ethtool_nway_reset,
1147 	.get_link		= ethtool_op_get_link,
1148 	.get_coalesce		= efx_ethtool_get_coalesce,
1149 	.set_coalesce		= efx_ethtool_set_coalesce,
1150 	.get_ringparam		= efx_ethtool_get_ringparam,
1151 	.set_ringparam		= efx_ethtool_set_ringparam,
1152 	.get_pauseparam         = efx_ethtool_get_pauseparam,
1153 	.set_pauseparam         = efx_ethtool_set_pauseparam,
1154 	.get_sset_count		= efx_ethtool_get_sset_count,
1155 	.self_test		= efx_ethtool_self_test,
1156 	.get_strings		= efx_ethtool_get_strings,
1157 	.set_phys_id		= efx_ethtool_phys_id,
1158 	.get_ethtool_stats	= efx_ethtool_get_stats,
1159 	.get_wol                = efx_ethtool_get_wol,
1160 	.set_wol                = efx_ethtool_set_wol,
1161 	.reset			= efx_ethtool_reset,
1162 	.get_rxnfc		= efx_ethtool_get_rxnfc,
1163 	.set_rxnfc		= efx_ethtool_set_rxnfc,
1164 	.get_rxfh_indir_size	= efx_ethtool_get_rxfh_indir_size,
1165 	.get_rxfh_key_size	= efx_ethtool_get_rxfh_key_size,
1166 	.get_rxfh		= efx_ethtool_get_rxfh,
1167 	.set_rxfh		= efx_ethtool_set_rxfh,
1168 	.get_rxfh_context	= efx_ethtool_get_rxfh_context,
1169 	.set_rxfh_context	= efx_ethtool_set_rxfh_context,
1170 	.get_ts_info		= efx_ethtool_get_ts_info,
1171 	.get_module_info	= efx_ethtool_get_module_info,
1172 	.get_module_eeprom	= efx_ethtool_get_module_eeprom,
1173 	.get_link_ksettings	= efx_ethtool_get_link_ksettings,
1174 	.set_link_ksettings	= efx_ethtool_set_link_ksettings,
1175 	.get_fecparam		= efx_ethtool_get_fecparam,
1176 	.set_fecparam		= efx_ethtool_set_fecparam,
1177 };
1178