ethtool.c 33.4 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0-only
2
/****************************************************************************
B
Ben Hutchings 已提交
3
 * Driver for Solarflare network controllers and boards
4
 * Copyright 2005-2006 Fen Systems Ltd.
B
Ben Hutchings 已提交
5
 * Copyright 2006-2013 Solarflare Communications Inc.
6 7 8 9 10
 */

#include <linux/netdevice.h>
#include <linux/ethtool.h>
#include <linux/rtnetlink.h>
11
#include <linux/in.h>
12
#include "net_driver.h"
B
Ben Hutchings 已提交
13
#include "workarounds.h"
14
#include "selftest.h"
15
#include "efx.h"
16 17 18
#include "efx_channels.h"
#include "rx_common.h"
#include "tx_common.h"
19
#include "ethtool_common.h"
20
#include "filter.h"
B
Ben Hutchings 已提交
21
#include "nic.h"
22

23 24
#define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB

25 26 27 28 29 30 31 32
/**************************************************************************
 *
 * Ethtool operations
 *
 **************************************************************************
 */

/* Identify device by flashing LEDs */
33 34
static int efx_ethtool_phys_id(struct net_device *net_dev,
			       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 40 41 42 43 44 45 46 47 48
	switch (state) {
	case ETHTOOL_ID_ON:
		mode = EFX_LED_ON;
		break;
	case ETHTOOL_ID_OFF:
		mode = EFX_LED_OFF;
		break;
	case ETHTOOL_ID_INACTIVE:
		mode = EFX_LED_DEFAULT;
		break;
49 50
	case ETHTOOL_ID_ACTIVE:
		return 1;	/* cycle on/off once per second */
51
	}
52

53
	efx->type->set_id_led(efx, mode);
54 55 56 57
	return 0;
}

/* This must be called with rtnl_lock held. */
58 59 60
static int
efx_ethtool_get_link_ksettings(struct net_device *net_dev,
			       struct ethtool_link_ksettings *cmd)
61
{
62
	struct efx_nic *efx = netdev_priv(net_dev);
B
Ben Hutchings 已提交
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 69
	mutex_unlock(&efx->mac_lock);

B
Ben Hutchings 已提交
70
	/* Both MACs support pause frames (bidirectional and respond-only) */
71 72 73 74 75 76 77
	ethtool_convert_link_mode_to_legacy_u32(&supported,
						cmd->link_modes.supported);

	supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;

	ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
						supported);
B
Ben Hutchings 已提交
78 79

	if (LOOPBACK_INTERNAL(efx)) {
80 81
		cmd->base.speed = link_state->speed;
		cmd->base.duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF;
B
Ben Hutchings 已提交
82
	}
83 84

	return 0;
85 86 87
}

/* This must be called with rtnl_lock held. */
88 89 90
static int
efx_ethtool_set_link_ksettings(struct net_device *net_dev,
			       const struct ethtool_link_ksettings *cmd)
91
{
92
	struct efx_nic *efx = netdev_priv(net_dev);
93 94
	int rc;

95
	/* GMAC does not support 1000Mbps HD */
96 97
	if ((cmd->base.speed == SPEED_1000) &&
	    (cmd->base.duplex != DUPLEX_FULL)) {
98 99
		netif_dbg(efx, drv, efx->net_dev,
			  "rejecting unsupported 1000Mbps HD setting\n");
100 101 102
		return -EINVAL;
	}

103
	mutex_lock(&efx->mac_lock);
104
	rc = efx->phy_op->set_link_ksettings(efx, cmd);
105 106 107 108
	mutex_unlock(&efx->mac_lock);
	return rc;
}

109 110 111 112 113 114 115 116 117 118 119 120 121 122
static int efx_ethtool_get_regs_len(struct net_device *net_dev)
{
	return efx_nic_get_regs_len(netdev_priv(net_dev));
}

static void efx_ethtool_get_regs(struct net_device *net_dev,
				 struct ethtool_regs *regs, void *buf)
{
	struct efx_nic *efx = netdev_priv(net_dev);

	regs->version = efx->type->revision;
	efx_nic_get_regs(efx, buf);
}

123 124 125
static void efx_ethtool_self_test(struct net_device *net_dev,
				  struct ethtool_test *test, u64 *data)
{
126
	struct efx_nic *efx = netdev_priv(net_dev);
127
	struct efx_self_tests *efx_tests;
128
	bool already_up;
129 130 131 132 133 134
	int rc = -ENOMEM;

	efx_tests = kzalloc(sizeof(*efx_tests), GFP_KERNEL);
	if (!efx_tests)
		goto fail;

135
	if (efx->state != STATE_READY) {
136
		rc = -EBUSY;
137
		goto out;
138 139
	}

140 141 142
	netif_info(efx, drv, efx->net_dev, "starting %sline testing\n",
		   (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");

143 144 145
	/* We need rx buffers and interrupts. */
	already_up = (efx->net_dev->flags & IFF_UP);
	if (!already_up) {
146
		rc = dev_open(efx->net_dev, NULL);
147
		if (rc) {
148 149
			netif_err(efx, drv, efx->net_dev,
				  "failed opening device.\n");
150
			goto out;
151 152 153
		}
	}

154
	rc = efx_selftest(efx, efx_tests, test->flags);
155 156 157 158

	if (!already_up)
		dev_close(efx->net_dev);

159 160 161
	netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n",
		   rc == 0 ? "passed" : "failed",
		   (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
162

163
out:
164 165 166
	efx_ethtool_fill_self_tests(efx, efx_tests, NULL, data);
	kfree(efx_tests);
fail:
167 168 169 170
	if (rc)
		test->flags |= ETH_TEST_FL_FAILED;
}

171 172 173
/* Restart autonegotiation */
static int efx_ethtool_nway_reset(struct net_device *net_dev)
{
174
	struct efx_nic *efx = netdev_priv(net_dev);
175

176
	return mdio45_nway_restart(&efx->mdio);
177 178
}

179 180 181 182 183 184 185 186 187
/*
 * Each channel has a single IRQ and moderation timer, started by any
 * completion (or other event).  Unless the module parameter
 * separate_tx_channels is set, IRQs and moderation are therefore
 * shared between RX and TX completions.  In this case, when RX IRQ
 * moderation is explicitly changed then TX IRQ moderation is
 * automatically changed too, but otherwise we fail if the two values
 * are requested to be different.
 *
188 189 190 191 192 193 194 195 196 197 198 199 200 201
 * The hardware does not support a limit on the number of completions
 * before an IRQ, so we do not use the max_frames fields.  We should
 * report and require that max_frames == (usecs != 0), but this would
 * invalidate existing user documentation.
 *
 * The hardware does not have distinct settings for interrupt
 * moderation while the previous IRQ is being handled, so we should
 * not use the 'irq' fields.  However, an earlier developer
 * misunderstood the meaning of the 'irq' fields and the driver did
 * not support the standard fields.  To avoid invalidating existing
 * user documentation, we report and accept changes through either the
 * standard or 'irq' fields.  If both are changed at the same time, we
 * prefer the standard field.
 *
202 203 204 205 206 207
 * We implement adaptive IRQ moderation, but use a different algorithm
 * from that assumed in the definition of struct ethtool_coalesce.
 * Therefore we do not use any of the adaptive moderation parameters
 * in it.
 */

208 209 210
static int efx_ethtool_get_coalesce(struct net_device *net_dev,
				    struct ethtool_coalesce *coalesce)
{
211
	struct efx_nic *efx = netdev_priv(net_dev);
212 213
	unsigned int tx_usecs, rx_usecs;
	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 221
	coalesce->rx_coalesce_usecs_irq = rx_usecs;
	coalesce->use_adaptive_rx_coalesce = rx_adaptive;
222

223 224 225 226 227 228
	return 0;
}

static int efx_ethtool_set_coalesce(struct net_device *net_dev,
				    struct ethtool_coalesce *coalesce)
{
229
	struct efx_nic *efx = netdev_priv(net_dev);
230
	struct efx_channel *channel;
231
	unsigned int tx_usecs, rx_usecs;
232 233
	bool adaptive, rx_may_override_tx;
	int rc;
234

235 236
	efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &adaptive);

237 238 239 240 241
	if (coalesce->rx_coalesce_usecs != rx_usecs)
		rx_usecs = coalesce->rx_coalesce_usecs;
	else
		rx_usecs = coalesce->rx_coalesce_usecs_irq;

242
	adaptive = coalesce->use_adaptive_rx_coalesce;
243

244 245 246
	/* If channels are shared, TX IRQ moderation can be quietly
	 * overridden unless it is changed from its old value.
	 */
247 248 249 250 251 252
	rx_may_override_tx = (coalesce->tx_coalesce_usecs == tx_usecs &&
			      coalesce->tx_coalesce_usecs_irq == tx_usecs);
	if (coalesce->tx_coalesce_usecs != tx_usecs)
		tx_usecs = coalesce->tx_coalesce_usecs;
	else
		tx_usecs = coalesce->tx_coalesce_usecs_irq;
253

254 255 256 257 258
	rc = efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive,
				     rx_may_override_tx);
	if (rc != 0)
		return rc;

259
	efx_for_each_channel(channel, efx)
260
		efx->type->push_irq_moderation(channel);
261 262 263 264

	return 0;
}

265 266 267 268 269 270
static void efx_ethtool_get_ringparam(struct net_device *net_dev,
				      struct ethtool_ringparam *ring)
{
	struct efx_nic *efx = netdev_priv(net_dev);

	ring->rx_max_pending = EFX_MAX_DMAQ_SIZE;
271
	ring->tx_max_pending = EFX_TXQ_MAX_ENT(efx);
272 273 274 275 276 277 278 279
	ring->rx_pending = efx->rxq_entries;
	ring->tx_pending = efx->txq_entries;
}

static int efx_ethtool_set_ringparam(struct net_device *net_dev,
				     struct ethtool_ringparam *ring)
{
	struct efx_nic *efx = netdev_priv(net_dev);
280
	u32 txq_entries;
281 282 283

	if (ring->rx_mini_pending || ring->rx_jumbo_pending ||
	    ring->rx_pending > EFX_MAX_DMAQ_SIZE ||
284
	    ring->tx_pending > EFX_TXQ_MAX_ENT(efx))
285 286
		return -EINVAL;

287
	if (ring->rx_pending < EFX_RXQ_MIN_ENT) {
288
		netif_err(efx, drv, efx->net_dev,
289 290
			  "RX queues cannot be smaller than %u\n",
			  EFX_RXQ_MIN_ENT);
291 292 293
		return -EINVAL;
	}

294 295 296 297 298 299 300
	txq_entries = max(ring->tx_pending, EFX_TXQ_MIN_ENT(efx));
	if (txq_entries != ring->tx_pending)
		netif_warn(efx, drv, efx->net_dev,
			   "increasing TX queue size to minimum of %u\n",
			   txq_entries);

	return efx_realloc_channels(efx, ring->rx_pending, txq_entries);
301 302
}

303 304 305
static int efx_ethtool_set_pauseparam(struct net_device *net_dev,
				      struct ethtool_pauseparam *pause)
{
306
	struct efx_nic *efx = netdev_priv(net_dev);
307
	u8 wanted_fc, old_fc;
B
Ben Hutchings 已提交
308 309 310 311
	u32 old_adv;
	int rc = 0;

	mutex_lock(&efx->mac_lock);
312

B
Ben Hutchings 已提交
313 314 315 316 317
	wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
		     (pause->tx_pause ? EFX_FC_TX : 0) |
		     (pause->autoneg ? EFX_FC_AUTO : 0));

	if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
318 319
		netif_dbg(efx, drv, efx->net_dev,
			  "Flow control unsupported: tx ON rx OFF\n");
B
Ben Hutchings 已提交
320 321
		rc = -EINVAL;
		goto out;
B
Ben Hutchings 已提交
322 323
	}

324
	if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising[0]) {
325 326
		netif_dbg(efx, drv, efx->net_dev,
			  "Autonegotiation is disabled\n");
B
Ben Hutchings 已提交
327 328
		rc = -EINVAL;
		goto out;
B
Ben Hutchings 已提交
329 330
	}

331 332 333 334
	/* Hook for Falcon bug 11482 workaround */
	if (efx->type->prepare_enable_fc_tx &&
	    (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX))
		efx->type->prepare_enable_fc_tx(efx);
B
Ben Hutchings 已提交
335

336
	old_adv = efx->link_advertising[0];
B
Ben Hutchings 已提交
337 338
	old_fc = efx->wanted_fc;
	efx_link_set_wanted_fc(efx, wanted_fc);
339
	if (efx->link_advertising[0] != old_adv ||
B
Ben Hutchings 已提交
340 341 342
	    (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) {
		rc = efx->phy_op->reconfigure(efx);
		if (rc) {
343 344 345
			netif_err(efx, drv, efx->net_dev,
				  "Unable to advertise requested flow "
				  "control setting\n");
B
Ben Hutchings 已提交
346 347 348
			goto out;
		}
	}
B
Ben Hutchings 已提交
349

B
Ben Hutchings 已提交
350 351 352
	/* Reconfigure the MAC. The PHY *may* generate a link state change event
	 * if the user just changed the advertised capabilities, but there's no
	 * harm doing this twice */
353
	efx_mac_reconfigure(efx);
B
Ben Hutchings 已提交
354

B
Ben Hutchings 已提交
355
out:
B
Ben Hutchings 已提交
356
	mutex_unlock(&efx->mac_lock);
357

B
Ben Hutchings 已提交
358
	return rc;
359 360
}

361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
static void efx_ethtool_get_wol(struct net_device *net_dev,
				struct ethtool_wolinfo *wol)
{
	struct efx_nic *efx = netdev_priv(net_dev);
	return efx->type->get_wol(efx, wol);
}


static int efx_ethtool_set_wol(struct net_device *net_dev,
			       struct ethtool_wolinfo *wol)
{
	struct efx_nic *efx = netdev_priv(net_dev);
	return efx->type->set_wol(efx, wol->wolopts);
}

S
stephen hemminger 已提交
376
static int efx_ethtool_reset(struct net_device *net_dev, u32 *flags)
377 378
{
	struct efx_nic *efx = netdev_priv(net_dev);
379
	int rc;
380

381 382 383
	rc = efx->type->map_reset_flags(flags);
	if (rc < 0)
		return rc;
384

385
	return efx_reset(efx, rc);
386 387
}

388
/* MAC address mask including only I/G bit */
389
static const u8 mac_addr_ig_mask[ETH_ALEN] __aligned(2) = {0x01, 0, 0, 0, 0, 0};
390

391
#define IP4_ADDR_FULL_MASK	((__force __be32)~0)
392
#define IP_PROTO_FULL_MASK	0xFF
393
#define PORT_FULL_MASK		((__force __be16)~0)
394
#define ETHER_TYPE_FULL_MASK	((__force __be16)~0)
395

396 397 398 399 400
static inline void ip6_fill_mask(__be32 *mask)
{
	mask[0] = mask[1] = mask[2] = mask[3] = ~(__be32)0;
}

401
static int efx_ethtool_get_class_rule(struct efx_nic *efx,
402 403
				      struct ethtool_rx_flow_spec *rule,
				      u32 *rss_context)
404 405 406
{
	struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
	struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
407 408 409 410 411 412
	struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
	struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
	struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
	struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
	struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
	struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
413 414
	struct ethhdr *mac_entry = &rule->h_u.ether_spec;
	struct ethhdr *mac_mask = &rule->m_u.ether_spec;
415 416 417 418 419 420 421 422
	struct efx_filter_spec spec;
	int rc;

	rc = efx_filter_get_filter_safe(efx, EFX_FILTER_PRI_MANUAL,
					rule->location, &spec);
	if (rc)
		return rc;

B
Ben Hutchings 已提交
423
	if (spec.dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP)
424 425 426 427
		rule->ring_cookie = RX_CLS_FLOW_DISC;
	else
		rule->ring_cookie = spec.dmaq_id;

428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
	if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) &&
	    spec.ether_type == htons(ETH_P_IP) &&
	    (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) &&
	    (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
	    !(spec.match_flags &
	      ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
		EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
		EFX_FILTER_MATCH_IP_PROTO |
		EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) {
		rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
				   TCP_V4_FLOW : UDP_V4_FLOW);
		if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
			ip_entry->ip4dst = spec.loc_host[0];
			ip_mask->ip4dst = IP4_ADDR_FULL_MASK;
		}
		if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
			ip_entry->ip4src = spec.rem_host[0];
			ip_mask->ip4src = IP4_ADDR_FULL_MASK;
		}
		if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) {
			ip_entry->pdst = spec.loc_port;
			ip_mask->pdst = PORT_FULL_MASK;
		}
		if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) {
			ip_entry->psrc = spec.rem_port;
			ip_mask->psrc = PORT_FULL_MASK;
		}
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
	} else if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) &&
	    spec.ether_type == htons(ETH_P_IPV6) &&
	    (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) &&
	    (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
	    !(spec.match_flags &
	      ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
		EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
		EFX_FILTER_MATCH_IP_PROTO |
		EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) {
		rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
				   TCP_V6_FLOW : UDP_V6_FLOW);
		if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
			memcpy(ip6_entry->ip6dst, spec.loc_host,
			       sizeof(ip6_entry->ip6dst));
			ip6_fill_mask(ip6_mask->ip6dst);
		}
		if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
			memcpy(ip6_entry->ip6src, spec.rem_host,
			       sizeof(ip6_entry->ip6src));
			ip6_fill_mask(ip6_mask->ip6src);
		}
		if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) {
			ip6_entry->pdst = spec.loc_port;
			ip6_mask->pdst = PORT_FULL_MASK;
		}
		if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) {
			ip6_entry->psrc = spec.rem_port;
			ip6_mask->psrc = PORT_FULL_MASK;
		}
484 485 486 487
	} else if (!(spec.match_flags &
		     ~(EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG |
		       EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_ETHER_TYPE |
		       EFX_FILTER_MATCH_OUTER_VID))) {
488
		rule->flow_type = ETHER_FLOW;
489 490
		if (spec.match_flags &
		    (EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG)) {
491
			ether_addr_copy(mac_entry->h_dest, spec.loc_mac);
492
			if (spec.match_flags & EFX_FILTER_MATCH_LOC_MAC)
493
				eth_broadcast_addr(mac_mask->h_dest);
494
			else
495 496
				ether_addr_copy(mac_mask->h_dest,
						mac_addr_ig_mask);
497
		}
498
		if (spec.match_flags & EFX_FILTER_MATCH_REM_MAC) {
499 500
			ether_addr_copy(mac_entry->h_source, spec.rem_mac);
			eth_broadcast_addr(mac_mask->h_source);
501 502 503 504 505
		}
		if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) {
			mac_entry->h_proto = spec.ether_type;
			mac_mask->h_proto = ETHER_TYPE_FULL_MASK;
		}
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546
	} else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
		   spec.ether_type == htons(ETH_P_IP) &&
		   !(spec.match_flags &
		     ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
		       EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
		       EFX_FILTER_MATCH_IP_PROTO))) {
		rule->flow_type = IPV4_USER_FLOW;
		uip_entry->ip_ver = ETH_RX_NFC_IP4;
		if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) {
			uip_mask->proto = IP_PROTO_FULL_MASK;
			uip_entry->proto = spec.ip_proto;
		}
		if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
			uip_entry->ip4dst = spec.loc_host[0];
			uip_mask->ip4dst = IP4_ADDR_FULL_MASK;
		}
		if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
			uip_entry->ip4src = spec.rem_host[0];
			uip_mask->ip4src = IP4_ADDR_FULL_MASK;
		}
	} else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
		   spec.ether_type == htons(ETH_P_IPV6) &&
		   !(spec.match_flags &
		     ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
		       EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
		       EFX_FILTER_MATCH_IP_PROTO))) {
		rule->flow_type = IPV6_USER_FLOW;
		if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) {
			uip6_mask->l4_proto = IP_PROTO_FULL_MASK;
			uip6_entry->l4_proto = spec.ip_proto;
		}
		if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
			memcpy(uip6_entry->ip6dst, spec.loc_host,
			       sizeof(uip6_entry->ip6dst));
			ip6_fill_mask(uip6_mask->ip6dst);
		}
		if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
			memcpy(uip6_entry->ip6src, spec.rem_host,
			       sizeof(uip6_entry->ip6src));
			ip6_fill_mask(uip6_mask->ip6src);
		}
547 548 549 550
	} else {
		/* The above should handle all filters that we insert */
		WARN_ON(1);
		return -EINVAL;
551 552
	}

553 554 555 556
	if (spec.match_flags & EFX_FILTER_MATCH_OUTER_VID) {
		rule->flow_type |= FLOW_EXT;
		rule->h_ext.vlan_tci = spec.outer_vid;
		rule->m_ext.vlan_tci = htons(0xfff);
557
	}
558

559 560 561 562 563
	if (spec.flags & EFX_FILTER_FLAG_RX_RSS) {
		rule->flow_type |= FLOW_RSS;
		*rss_context = spec.rss_context;
	}

564 565 566
	return rc;
}

567 568
static int
efx_ethtool_get_rxnfc(struct net_device *net_dev,
569
		      struct ethtool_rxnfc *info, u32 *rule_locs)
570 571
{
	struct efx_nic *efx = netdev_priv(net_dev);
572
	u32 rss_context = 0;
573
	s32 rc = 0;
574 575 576 577 578 579 580

	switch (info->cmd) {
	case ETHTOOL_GRXRINGS:
		info->data = efx->n_rx_channels;
		return 0;

	case ETHTOOL_GRXFH: {
581
		struct efx_rss_context *ctx = &efx->rss_context;
582
		__u64 data;
583

584
		mutex_lock(&efx->rss_lock);
585
		if (info->flow_type & FLOW_RSS && info->rss_context) {
586 587 588 589 590
			ctx = efx_find_rss_context_entry(efx, info->rss_context);
			if (!ctx) {
				rc = -ENOENT;
				goto out_unlock;
			}
591
		}
592 593

		data = 0;
594
		if (!efx_rss_active(ctx)) /* No RSS */
595 596
			goto out_setdata_unlock;

597
		switch (info->flow_type & ~FLOW_RSS) {
598 599
		case UDP_V4_FLOW:
		case UDP_V6_FLOW:
600
			if (ctx->rx_hash_udp_4tuple)
601 602 603 604 605 606
				data = (RXH_L4_B_0_1 | RXH_L4_B_2_3 |
					RXH_IP_SRC | RXH_IP_DST);
			else
				data = RXH_IP_SRC | RXH_IP_DST;
			break;
		case TCP_V4_FLOW:
607
		case TCP_V6_FLOW:
608 609 610 611
			data = (RXH_L4_B_0_1 | RXH_L4_B_2_3 |
				RXH_IP_SRC | RXH_IP_DST);
			break;
		case SCTP_V4_FLOW:
612
		case SCTP_V6_FLOW:
613
		case AH_ESP_V4_FLOW:
614
		case AH_ESP_V6_FLOW:
615
		case IPV4_FLOW:
616
		case IPV6_FLOW:
617
			data = RXH_IP_SRC | RXH_IP_DST;
618 619 620 621
			break;
		default:
			break;
		}
622 623
out_setdata_unlock:
		info->data = data;
624 625 626
out_unlock:
		mutex_unlock(&efx->rss_lock);
		return rc;
627 628
	}

629 630 631 632 633 634 635 636 637 638 639 640
	case ETHTOOL_GRXCLSRLCNT:
		info->data = efx_filter_get_rx_id_limit(efx);
		if (info->data == 0)
			return -EOPNOTSUPP;
		info->data |= RX_CLS_LOC_SPECIAL;
		info->rule_cnt =
			efx_filter_count_rx_used(efx, EFX_FILTER_PRI_MANUAL);
		return 0;

	case ETHTOOL_GRXCLSRULE:
		if (efx_filter_get_rx_id_limit(efx) == 0)
			return -EOPNOTSUPP;
641 642 643 644 645 646
		rc = efx_ethtool_get_class_rule(efx, &info->fs, &rss_context);
		if (rc < 0)
			return rc;
		if (info->fs.flow_type & FLOW_RSS)
			info->rss_context = rss_context;
		return 0;
647

648
	case ETHTOOL_GRXCLSRLALL:
649 650 651 652 653 654 655 656 657 658
		info->data = efx_filter_get_rx_id_limit(efx);
		if (info->data == 0)
			return -EOPNOTSUPP;
		rc = efx_filter_get_rx_ids(efx, EFX_FILTER_PRI_MANUAL,
					   rule_locs, info->rule_cnt);
		if (rc < 0)
			return rc;
		info->rule_cnt = rc;
		return 0;

659 660 661 662 663
	default:
		return -EOPNOTSUPP;
	}
}

664 665 666 667 668 669 670 671 672 673
static inline bool ip6_mask_is_full(__be32 mask[4])
{
	return !~(mask[0] & mask[1] & mask[2] & mask[3]);
}

static inline bool ip6_mask_is_empty(__be32 mask[4])
{
	return !(mask[0] | mask[1] | mask[2] | mask[3]);
}

674
static int efx_ethtool_set_class_rule(struct efx_nic *efx,
675 676
				      struct ethtool_rx_flow_spec *rule,
				      u32 rss_context)
677
{
678 679
	struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
	struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
680 681 682 683 684 685
	struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
	struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
	struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
	struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
	struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
	struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
686
	u32 flow_type = rule->flow_type & ~(FLOW_EXT | FLOW_RSS);
687 688
	struct ethhdr *mac_entry = &rule->h_u.ether_spec;
	struct ethhdr *mac_mask = &rule->m_u.ether_spec;
689
	enum efx_filter_flags flags = 0;
690
	struct efx_filter_spec spec;
691
	int rc;
692

693
	/* Check that user wants us to choose the location */
694
	if (rule->location != RX_CLS_LOC_ANY)
695 696
		return -EINVAL;

697 698 699
	/* Range-check ring_cookie */
	if (rule->ring_cookie >= efx->n_rx_channels &&
	    rule->ring_cookie != RX_CLS_FLOW_DISC)
700 701
		return -EINVAL;

702 703
	/* Check for unsupported extensions */
	if ((rule->flow_type & FLOW_EXT) &&
704
	    (rule->m_ext.vlan_etype || rule->m_ext.data[0] ||
705 706 707
	     rule->m_ext.data[1]))
		return -EINVAL;

708 709 710 711 712 713
	if (efx->rx_scatter)
		flags |= EFX_FILTER_FLAG_RX_SCATTER;
	if (rule->flow_type & FLOW_RSS)
		flags |= EFX_FILTER_FLAG_RX_RSS;

	efx_filter_init_rx(&spec, EFX_FILTER_PRI_MANUAL, flags,
714
			   (rule->ring_cookie == RX_CLS_FLOW_DISC) ?
B
Ben Hutchings 已提交
715
			   EFX_FILTER_RX_DMAQ_ID_DROP : rule->ring_cookie);
716

717 718 719
	if (rule->flow_type & FLOW_RSS)
		spec.rss_context = rss_context;

720
	switch (flow_type) {
721
	case TCP_V4_FLOW:
722 723 724 725
	case UDP_V4_FLOW:
		spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
				    EFX_FILTER_MATCH_IP_PROTO);
		spec.ether_type = htons(ETH_P_IP);
726 727
		spec.ip_proto = flow_type == TCP_V4_FLOW ? IPPROTO_TCP
							 : IPPROTO_UDP;
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752
		if (ip_mask->ip4dst) {
			if (ip_mask->ip4dst != IP4_ADDR_FULL_MASK)
				return -EINVAL;
			spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
			spec.loc_host[0] = ip_entry->ip4dst;
		}
		if (ip_mask->ip4src) {
			if (ip_mask->ip4src != IP4_ADDR_FULL_MASK)
				return -EINVAL;
			spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
			spec.rem_host[0] = ip_entry->ip4src;
		}
		if (ip_mask->pdst) {
			if (ip_mask->pdst != PORT_FULL_MASK)
				return -EINVAL;
			spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
			spec.loc_port = ip_entry->pdst;
		}
		if (ip_mask->psrc) {
			if (ip_mask->psrc != PORT_FULL_MASK)
				return -EINVAL;
			spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
			spec.rem_port = ip_entry->psrc;
		}
		if (ip_mask->tos)
753 754
			return -EINVAL;
		break;
755

756 757 758 759 760
	case TCP_V6_FLOW:
	case UDP_V6_FLOW:
		spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
				    EFX_FILTER_MATCH_IP_PROTO);
		spec.ether_type = htons(ETH_P_IPV6);
761 762
		spec.ip_proto = flow_type == TCP_V6_FLOW ? IPPROTO_TCP
							 : IPPROTO_UDP;
763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841
		if (!ip6_mask_is_empty(ip6_mask->ip6dst)) {
			if (!ip6_mask_is_full(ip6_mask->ip6dst))
				return -EINVAL;
			spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
			memcpy(spec.loc_host, ip6_entry->ip6dst, sizeof(spec.loc_host));
		}
		if (!ip6_mask_is_empty(ip6_mask->ip6src)) {
			if (!ip6_mask_is_full(ip6_mask->ip6src))
				return -EINVAL;
			spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
			memcpy(spec.rem_host, ip6_entry->ip6src, sizeof(spec.rem_host));
		}
		if (ip6_mask->pdst) {
			if (ip6_mask->pdst != PORT_FULL_MASK)
				return -EINVAL;
			spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
			spec.loc_port = ip6_entry->pdst;
		}
		if (ip6_mask->psrc) {
			if (ip6_mask->psrc != PORT_FULL_MASK)
				return -EINVAL;
			spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
			spec.rem_port = ip6_entry->psrc;
		}
		if (ip6_mask->tclass)
			return -EINVAL;
		break;

	case IPV4_USER_FLOW:
		if (uip_mask->l4_4_bytes || uip_mask->tos || uip_mask->ip_ver ||
		    uip_entry->ip_ver != ETH_RX_NFC_IP4)
			return -EINVAL;
		spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE;
		spec.ether_type = htons(ETH_P_IP);
		if (uip_mask->ip4dst) {
			if (uip_mask->ip4dst != IP4_ADDR_FULL_MASK)
				return -EINVAL;
			spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
			spec.loc_host[0] = uip_entry->ip4dst;
		}
		if (uip_mask->ip4src) {
			if (uip_mask->ip4src != IP4_ADDR_FULL_MASK)
				return -EINVAL;
			spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
			spec.rem_host[0] = uip_entry->ip4src;
		}
		if (uip_mask->proto) {
			if (uip_mask->proto != IP_PROTO_FULL_MASK)
				return -EINVAL;
			spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO;
			spec.ip_proto = uip_entry->proto;
		}
		break;

	case IPV6_USER_FLOW:
		if (uip6_mask->l4_4_bytes || uip6_mask->tclass)
			return -EINVAL;
		spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE;
		spec.ether_type = htons(ETH_P_IPV6);
		if (!ip6_mask_is_empty(uip6_mask->ip6dst)) {
			if (!ip6_mask_is_full(uip6_mask->ip6dst))
				return -EINVAL;
			spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
			memcpy(spec.loc_host, uip6_entry->ip6dst, sizeof(spec.loc_host));
		}
		if (!ip6_mask_is_empty(uip6_mask->ip6src)) {
			if (!ip6_mask_is_full(uip6_mask->ip6src))
				return -EINVAL;
			spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
			memcpy(spec.rem_host, uip6_entry->ip6src, sizeof(spec.rem_host));
		}
		if (uip6_mask->l4_proto) {
			if (uip6_mask->l4_proto != IP_PROTO_FULL_MASK)
				return -EINVAL;
			spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO;
			spec.ip_proto = uip6_entry->l4_proto;
		}
		break;

842 843 844 845 846 847 848
	case ETHER_FLOW:
		if (!is_zero_ether_addr(mac_mask->h_dest)) {
			if (ether_addr_equal(mac_mask->h_dest,
					     mac_addr_ig_mask))
				spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC_IG;
			else if (is_broadcast_ether_addr(mac_mask->h_dest))
				spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC;
849
			else
850
				return -EINVAL;
851
			ether_addr_copy(spec.loc_mac, mac_entry->h_dest);
852
		}
853 854 855 856
		if (!is_zero_ether_addr(mac_mask->h_source)) {
			if (!is_broadcast_ether_addr(mac_mask->h_source))
				return -EINVAL;
			spec.match_flags |= EFX_FILTER_MATCH_REM_MAC;
857
			ether_addr_copy(spec.rem_mac, mac_entry->h_source);
858 859 860 861 862 863
		}
		if (mac_mask->h_proto) {
			if (mac_mask->h_proto != ETHER_TYPE_FULL_MASK)
				return -EINVAL;
			spec.match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
			spec.ether_type = mac_entry->h_proto;
864
		}
865
		break;
866

867 868 869 870
	default:
		return -EINVAL;
	}

871 872 873 874 875 876 877
	if ((rule->flow_type & FLOW_EXT) && rule->m_ext.vlan_tci) {
		if (rule->m_ext.vlan_tci != htons(0xfff))
			return -EINVAL;
		spec.match_flags |= EFX_FILTER_MATCH_OUTER_VID;
		spec.outer_vid = rule->h_ext.vlan_tci;
	}

878 879 880
	rc = efx_filter_insert_filter(efx, &spec, true);
	if (rc < 0)
		return rc;
881

882 883 884 885 886 887 888 889 890 891 892 893 894 895
	rule->location = rc;
	return 0;
}

static int efx_ethtool_set_rxnfc(struct net_device *net_dev,
				 struct ethtool_rxnfc *info)
{
	struct efx_nic *efx = netdev_priv(net_dev);

	if (efx_filter_get_rx_id_limit(efx) == 0)
		return -EOPNOTSUPP;

	switch (info->cmd) {
	case ETHTOOL_SRXCLSRLINS:
896 897
		return efx_ethtool_set_class_rule(efx, &info->fs,
						  info->rss_context);
898 899 900 901 902 903 904 905

	case ETHTOOL_SRXCLSRLDEL:
		return efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_MANUAL,
						 info->fs.location);

	default:
		return -EOPNOTSUPP;
	}
906 907
}

908
static u32 efx_ethtool_get_rxfh_indir_size(struct net_device *net_dev)
909 910 911
{
	struct efx_nic *efx = netdev_priv(net_dev);

912 913 914
	if (efx->n_rx_channels == 1)
		return 0;
	return ARRAY_SIZE(efx->rss_context.rx_indir_table);
915 916
}

917 918 919 920 921 922 923
static u32 efx_ethtool_get_rxfh_key_size(struct net_device *net_dev)
{
	struct efx_nic *efx = netdev_priv(net_dev);

	return efx->type->rx_hash_key_size;
}

924 925
static int efx_ethtool_get_rxfh(struct net_device *net_dev, u32 *indir, u8 *key,
				u8 *hfunc)
926 927
{
	struct efx_nic *efx = netdev_priv(net_dev);
928 929 930 931 932
	int rc;

	rc = efx->type->rx_pull_rss_config(efx);
	if (rc)
		return rc;
933

934 935 936
	if (hfunc)
		*hfunc = ETH_RSS_HASH_TOP;
	if (indir)
937 938
		memcpy(indir, efx->rss_context.rx_indir_table,
		       sizeof(efx->rss_context.rx_indir_table));
939
	if (key)
940 941
		memcpy(key, efx->rss_context.rx_hash_key,
		       efx->type->rx_hash_key_size);
942 943 944
	return 0;
}

945 946
static int efx_ethtool_set_rxfh(struct net_device *net_dev, const u32 *indir,
				const u8 *key, const u8 hfunc)
947 948 949
{
	struct efx_nic *efx = netdev_priv(net_dev);

950 951
	/* Hash function is Toeplitz, cannot be changed */
	if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
952
		return -EOPNOTSUPP;
953
	if (!indir && !key)
954
		return 0;
955

956
	if (!key)
957
		key = efx->rss_context.rx_hash_key;
958
	if (!indir)
959
		indir = efx->rss_context.rx_indir_table;
960 961

	return efx->type->rx_push_rss_config(efx, true, indir, key);
962 963
}

964 965 966 967 968
static int efx_ethtool_get_rxfh_context(struct net_device *net_dev, u32 *indir,
					u8 *key, u8 *hfunc, u32 rss_context)
{
	struct efx_nic *efx = netdev_priv(net_dev);
	struct efx_rss_context *ctx;
969
	int rc = 0;
970 971 972

	if (!efx->type->rx_pull_rss_context_config)
		return -EOPNOTSUPP;
973 974 975 976 977 978 979

	mutex_lock(&efx->rss_lock);
	ctx = efx_find_rss_context_entry(efx, rss_context);
	if (!ctx) {
		rc = -ENOENT;
		goto out_unlock;
	}
980 981
	rc = efx->type->rx_pull_rss_context_config(efx, ctx);
	if (rc)
982
		goto out_unlock;
983 984 985 986 987 988 989

	if (hfunc)
		*hfunc = ETH_RSS_HASH_TOP;
	if (indir)
		memcpy(indir, ctx->rx_indir_table, sizeof(ctx->rx_indir_table));
	if (key)
		memcpy(key, ctx->rx_hash_key, efx->type->rx_hash_key_size);
990 991 992
out_unlock:
	mutex_unlock(&efx->rss_lock);
	return rc;
993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
}

static int efx_ethtool_set_rxfh_context(struct net_device *net_dev,
					const u32 *indir, const u8 *key,
					const u8 hfunc, u32 *rss_context,
					bool delete)
{
	struct efx_nic *efx = netdev_priv(net_dev);
	struct efx_rss_context *ctx;
	bool allocated = false;
	int rc;

	if (!efx->type->rx_push_rss_context_config)
		return -EOPNOTSUPP;
	/* Hash function is Toeplitz, cannot be changed */
	if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
		return -EOPNOTSUPP;
1010 1011 1012

	mutex_lock(&efx->rss_lock);

1013
	if (*rss_context == ETH_RXFH_CONTEXT_ALLOC) {
1014
		if (delete) {
1015
			/* alloc + delete == Nothing to do */
1016 1017 1018 1019 1020 1021 1022 1023
			rc = -EINVAL;
			goto out_unlock;
		}
		ctx = efx_alloc_rss_context_entry(efx);
		if (!ctx) {
			rc = -ENOMEM;
			goto out_unlock;
		}
A
Alex Maftei (amaftei) 已提交
1024
		ctx->context_id = EFX_MCDI_RSS_CONTEXT_INVALID;
1025 1026 1027 1028 1029
		/* Initialise indir table and key to defaults */
		efx_set_default_rx_indir_table(efx, ctx);
		netdev_rss_key_fill(ctx->rx_hash_key, sizeof(ctx->rx_hash_key));
		allocated = true;
	} else {
1030 1031 1032 1033 1034
		ctx = efx_find_rss_context_entry(efx, *rss_context);
		if (!ctx) {
			rc = -ENOENT;
			goto out_unlock;
		}
1035 1036 1037 1038 1039 1040 1041
	}

	if (delete) {
		/* delete this context */
		rc = efx->type->rx_push_rss_context_config(efx, ctx, NULL, NULL);
		if (!rc)
			efx_free_rss_context_entry(ctx);
1042
		goto out_unlock;
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054
	}

	if (!key)
		key = ctx->rx_hash_key;
	if (!indir)
		indir = ctx->rx_indir_table;

	rc = efx->type->rx_push_rss_context_config(efx, ctx, indir, key);
	if (rc && allocated)
		efx_free_rss_context_entry(ctx);
	else
		*rss_context = ctx->user_id;
1055 1056
out_unlock:
	mutex_unlock(&efx->rss_lock);
1057 1058 1059
	return rc;
}

1060 1061
static int efx_ethtool_get_ts_info(struct net_device *net_dev,
				   struct ethtool_ts_info *ts_info)
1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
{
	struct efx_nic *efx = netdev_priv(net_dev);

	/* Software capabilities */
	ts_info->so_timestamping = (SOF_TIMESTAMPING_RX_SOFTWARE |
				    SOF_TIMESTAMPING_SOFTWARE);
	ts_info->phc_index = -1;

	efx_ptp_get_ts_info(efx, ts_info);
	return 0;
}

1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106
static int efx_ethtool_get_module_eeprom(struct net_device *net_dev,
					 struct ethtool_eeprom *ee,
					 u8 *data)
{
	struct efx_nic *efx = netdev_priv(net_dev);
	int ret;

	if (!efx->phy_op || !efx->phy_op->get_module_eeprom)
		return -EOPNOTSUPP;

	mutex_lock(&efx->mac_lock);
	ret = efx->phy_op->get_module_eeprom(efx, ee, data);
	mutex_unlock(&efx->mac_lock);

	return ret;
}

static int efx_ethtool_get_module_info(struct net_device *net_dev,
				       struct ethtool_modinfo *modinfo)
{
	struct efx_nic *efx = netdev_priv(net_dev);
	int ret;

	if (!efx->phy_op || !efx->phy_op->get_module_info)
		return -EOPNOTSUPP;

	mutex_lock(&efx->mac_lock);
	ret = efx->phy_op->get_module_info(efx, modinfo);
	mutex_unlock(&efx->mac_lock);

	return ret;
}

1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136
static int efx_ethtool_get_fecparam(struct net_device *net_dev,
				    struct ethtool_fecparam *fecparam)
{
	struct efx_nic *efx = netdev_priv(net_dev);
	int rc;

	if (!efx->phy_op || !efx->phy_op->get_fecparam)
		return -EOPNOTSUPP;
	mutex_lock(&efx->mac_lock);
	rc = efx->phy_op->get_fecparam(efx, fecparam);
	mutex_unlock(&efx->mac_lock);

	return rc;
}

static int efx_ethtool_set_fecparam(struct net_device *net_dev,
				    struct ethtool_fecparam *fecparam)
{
	struct efx_nic *efx = netdev_priv(net_dev);
	int rc;

	if (!efx->phy_op || !efx->phy_op->get_fecparam)
		return -EOPNOTSUPP;
	mutex_lock(&efx->mac_lock);
	rc = efx->phy_op->set_fecparam(efx, fecparam);
	mutex_unlock(&efx->mac_lock);

	return rc;
}

1137
const struct ethtool_ops efx_ethtool_ops = {
1138 1139 1140
	.supported_coalesce_params = ETHTOOL_COALESCE_USECS |
				     ETHTOOL_COALESCE_USECS_IRQ |
				     ETHTOOL_COALESCE_USE_ADAPTIVE_RX,
1141
	.get_drvinfo		= efx_ethtool_get_drvinfo,
1142 1143
	.get_regs_len		= efx_ethtool_get_regs_len,
	.get_regs		= efx_ethtool_get_regs,
1144 1145
	.get_msglevel		= efx_ethtool_get_msglevel,
	.set_msglevel		= efx_ethtool_set_msglevel,
1146
	.nway_reset		= efx_ethtool_nway_reset,
1147
	.get_link		= ethtool_op_get_link,
1148 1149
	.get_coalesce		= efx_ethtool_get_coalesce,
	.set_coalesce		= efx_ethtool_set_coalesce,
1150 1151
	.get_ringparam		= efx_ethtool_get_ringparam,
	.set_ringparam		= efx_ethtool_set_ringparam,
1152 1153
	.get_pauseparam         = efx_ethtool_get_pauseparam,
	.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 1160
	.get_wol                = efx_ethtool_get_wol,
	.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 1167
	.get_rxfh		= efx_ethtool_get_rxfh,
	.set_rxfh		= efx_ethtool_set_rxfh,
1168 1169
	.get_rxfh_context	= efx_ethtool_get_rxfh_context,
	.set_rxfh_context	= efx_ethtool_set_rxfh_context,
1170
	.get_ts_info		= efx_ethtool_get_ts_info,
1171 1172
	.get_module_info	= efx_ethtool_get_module_info,
	.get_module_eeprom	= efx_ethtool_get_module_eeprom,
1173 1174
	.get_link_ksettings	= efx_ethtool_get_link_ksettings,
	.set_link_ksettings	= efx_ethtool_set_link_ksettings,
1175 1176
	.get_fecparam		= efx_ethtool_get_fecparam,
	.set_fecparam		= efx_ethtool_set_fecparam,
1177
};