Linux Audio

Check our new training course

Loading...
v4.17
 
   1/****************************************************************************
   2 * Driver for Solarflare network controllers and boards
   3 * Copyright 2005-2006 Fen Systems Ltd.
   4 * Copyright 2006-2013 Solarflare Communications Inc.
   5 *
   6 * This program is free software; you can redistribute it and/or modify it
   7 * under the terms of the GNU General Public License version 2 as published
   8 * by the Free Software Foundation, incorporated herein by reference.
   9 */
  10
  11#include <linux/netdevice.h>
  12#include <linux/ethtool.h>
  13#include <linux/rtnetlink.h>
  14#include <linux/in.h>
  15#include "net_driver.h"
  16#include "workarounds.h"
  17#include "selftest.h"
  18#include "efx.h"
  19#include "filter.h"
  20#include "nic.h"
  21
  22struct ef4_sw_stat_desc {
  23	const char *name;
  24	enum {
  25		EF4_ETHTOOL_STAT_SOURCE_nic,
  26		EF4_ETHTOOL_STAT_SOURCE_channel,
  27		EF4_ETHTOOL_STAT_SOURCE_tx_queue
  28	} source;
  29	unsigned offset;
  30	u64(*get_stat) (void *field); /* Reader function */
  31};
  32
  33/* Initialiser for a struct ef4_sw_stat_desc with type-checking */
  34#define EF4_ETHTOOL_STAT(stat_name, source_name, field, field_type, \
  35				get_stat_function) {			\
  36	.name = #stat_name,						\
  37	.source = EF4_ETHTOOL_STAT_SOURCE_##source_name,		\
  38	.offset = ((((field_type *) 0) ==				\
  39		      &((struct ef4_##source_name *)0)->field) ?	\
  40		    offsetof(struct ef4_##source_name, field) :		\
  41		    offsetof(struct ef4_##source_name, field)),		\
  42	.get_stat = get_stat_function,					\
  43}
  44
  45static u64 ef4_get_uint_stat(void *field)
  46{
  47	return *(unsigned int *)field;
  48}
  49
  50static u64 ef4_get_atomic_stat(void *field)
  51{
  52	return atomic_read((atomic_t *) field);
  53}
  54
  55#define EF4_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field)		\
  56	EF4_ETHTOOL_STAT(field, nic, field,			\
  57			 atomic_t, ef4_get_atomic_stat)
  58
  59#define EF4_ETHTOOL_UINT_CHANNEL_STAT(field)			\
  60	EF4_ETHTOOL_STAT(field, channel, n_##field,		\
  61			 unsigned int, ef4_get_uint_stat)
  62
  63#define EF4_ETHTOOL_UINT_TXQ_STAT(field)			\
  64	EF4_ETHTOOL_STAT(tx_##field, tx_queue, field,		\
  65			 unsigned int, ef4_get_uint_stat)
  66
  67static const struct ef4_sw_stat_desc ef4_sw_stat_desc[] = {
  68	EF4_ETHTOOL_UINT_TXQ_STAT(merge_events),
  69	EF4_ETHTOOL_UINT_TXQ_STAT(pushes),
  70	EF4_ETHTOOL_UINT_TXQ_STAT(cb_packets),
  71	EF4_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset),
  72	EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc),
  73	EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),
  74	EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err),
  75	EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch),
  76	EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
  77	EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_events),
  78	EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_packets),
  79};
  80
  81#define EF4_ETHTOOL_SW_STAT_COUNT ARRAY_SIZE(ef4_sw_stat_desc)
  82
  83#define EF4_ETHTOOL_EEPROM_MAGIC 0xEFAB
  84
  85/**************************************************************************
  86 *
  87 * Ethtool operations
  88 *
  89 **************************************************************************
  90 */
  91
  92/* Identify device by flashing LEDs */
  93static int ef4_ethtool_phys_id(struct net_device *net_dev,
  94			       enum ethtool_phys_id_state state)
  95{
  96	struct ef4_nic *efx = netdev_priv(net_dev);
  97	enum ef4_led_mode mode = EF4_LED_DEFAULT;
  98
  99	switch (state) {
 100	case ETHTOOL_ID_ON:
 101		mode = EF4_LED_ON;
 102		break;
 103	case ETHTOOL_ID_OFF:
 104		mode = EF4_LED_OFF;
 105		break;
 106	case ETHTOOL_ID_INACTIVE:
 107		mode = EF4_LED_DEFAULT;
 108		break;
 109	case ETHTOOL_ID_ACTIVE:
 110		return 1;	/* cycle on/off once per second */
 111	}
 112
 113	efx->type->set_id_led(efx, mode);
 114	return 0;
 115}
 116
 117/* This must be called with rtnl_lock held. */
 118static int
 119ef4_ethtool_get_link_ksettings(struct net_device *net_dev,
 120			       struct ethtool_link_ksettings *cmd)
 121{
 122	struct ef4_nic *efx = netdev_priv(net_dev);
 123	struct ef4_link_state *link_state = &efx->link_state;
 124
 125	mutex_lock(&efx->mac_lock);
 126	efx->phy_op->get_link_ksettings(efx, cmd);
 127	mutex_unlock(&efx->mac_lock);
 128
 129	/* Both MACs support pause frames (bidirectional and respond-only) */
 130	ethtool_link_ksettings_add_link_mode(cmd, supported, Pause);
 131	ethtool_link_ksettings_add_link_mode(cmd, supported, Asym_Pause);
 132
 133	if (LOOPBACK_INTERNAL(efx)) {
 134		cmd->base.speed = link_state->speed;
 135		cmd->base.duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF;
 136	}
 137
 138	return 0;
 139}
 140
 141/* This must be called with rtnl_lock held. */
 142static int
 143ef4_ethtool_set_link_ksettings(struct net_device *net_dev,
 144			       const struct ethtool_link_ksettings *cmd)
 145{
 146	struct ef4_nic *efx = netdev_priv(net_dev);
 147	int rc;
 148
 149	/* GMAC does not support 1000Mbps HD */
 150	if ((cmd->base.speed == SPEED_1000) &&
 151	    (cmd->base.duplex != DUPLEX_FULL)) {
 152		netif_dbg(efx, drv, efx->net_dev,
 153			  "rejecting unsupported 1000Mbps HD setting\n");
 154		return -EINVAL;
 155	}
 156
 157	mutex_lock(&efx->mac_lock);
 158	rc = efx->phy_op->set_link_ksettings(efx, cmd);
 159	mutex_unlock(&efx->mac_lock);
 160	return rc;
 161}
 162
 163static void ef4_ethtool_get_drvinfo(struct net_device *net_dev,
 164				    struct ethtool_drvinfo *info)
 165{
 166	struct ef4_nic *efx = netdev_priv(net_dev);
 167
 168	strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
 169	strlcpy(info->version, EF4_DRIVER_VERSION, sizeof(info->version));
 170	strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
 171}
 172
 173static int ef4_ethtool_get_regs_len(struct net_device *net_dev)
 174{
 175	return ef4_nic_get_regs_len(netdev_priv(net_dev));
 176}
 177
 178static void ef4_ethtool_get_regs(struct net_device *net_dev,
 179				 struct ethtool_regs *regs, void *buf)
 180{
 181	struct ef4_nic *efx = netdev_priv(net_dev);
 182
 183	regs->version = efx->type->revision;
 184	ef4_nic_get_regs(efx, buf);
 185}
 186
 187static u32 ef4_ethtool_get_msglevel(struct net_device *net_dev)
 188{
 189	struct ef4_nic *efx = netdev_priv(net_dev);
 190	return efx->msg_enable;
 191}
 192
 193static void ef4_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable)
 194{
 195	struct ef4_nic *efx = netdev_priv(net_dev);
 196	efx->msg_enable = msg_enable;
 197}
 198
 199/**
 200 * ef4_fill_test - fill in an individual self-test entry
 201 * @test_index:		Index of the test
 202 * @strings:		Ethtool strings, or %NULL
 203 * @data:		Ethtool test results, or %NULL
 204 * @test:		Pointer to test result (used only if data != %NULL)
 205 * @unit_format:	Unit name format (e.g. "chan\%d")
 206 * @unit_id:		Unit id (e.g. 0 for "chan0")
 207 * @test_format:	Test name format (e.g. "loopback.\%s.tx.sent")
 208 * @test_id:		Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
 209 *
 210 * Fill in an individual self-test entry.
 211 */
 212static void ef4_fill_test(unsigned int test_index, u8 *strings, u64 *data,
 213			  int *test, const char *unit_format, int unit_id,
 214			  const char *test_format, const char *test_id)
 215{
 216	char unit_str[ETH_GSTRING_LEN], test_str[ETH_GSTRING_LEN];
 217
 218	/* Fill data value, if applicable */
 219	if (data)
 220		data[test_index] = *test;
 221
 222	/* Fill string, if applicable */
 223	if (strings) {
 224		if (strchr(unit_format, '%'))
 225			snprintf(unit_str, sizeof(unit_str),
 226				 unit_format, unit_id);
 227		else
 228			strcpy(unit_str, unit_format);
 229		snprintf(test_str, sizeof(test_str), test_format, test_id);
 230		snprintf(strings + test_index * ETH_GSTRING_LEN,
 231			 ETH_GSTRING_LEN,
 232			 "%-6s %-24s", unit_str, test_str);
 233	}
 234}
 235
 236#define EF4_CHANNEL_NAME(_channel) "chan%d", _channel->channel
 237#define EF4_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
 238#define EF4_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
 239#define EF4_LOOPBACK_NAME(_mode, _counter)			\
 240	"loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, ef4_loopback_mode)
 241
 242/**
 243 * ef4_fill_loopback_test - fill in a block of loopback self-test entries
 244 * @efx:		Efx NIC
 245 * @lb_tests:		Efx loopback self-test results structure
 246 * @mode:		Loopback test mode
 247 * @test_index:		Starting index of the test
 248 * @strings:		Ethtool strings, or %NULL
 249 * @data:		Ethtool test results, or %NULL
 250 *
 251 * Fill in a block of loopback self-test entries.  Return new test
 252 * index.
 253 */
 254static int ef4_fill_loopback_test(struct ef4_nic *efx,
 255				  struct ef4_loopback_self_tests *lb_tests,
 256				  enum ef4_loopback_mode mode,
 257				  unsigned int test_index,
 258				  u8 *strings, u64 *data)
 259{
 260	struct ef4_channel *channel =
 261		ef4_get_channel(efx, efx->tx_channel_offset);
 262	struct ef4_tx_queue *tx_queue;
 263
 264	ef4_for_each_channel_tx_queue(tx_queue, channel) {
 265		ef4_fill_test(test_index++, strings, data,
 266			      &lb_tests->tx_sent[tx_queue->queue],
 267			      EF4_TX_QUEUE_NAME(tx_queue),
 268			      EF4_LOOPBACK_NAME(mode, "tx_sent"));
 269		ef4_fill_test(test_index++, strings, data,
 270			      &lb_tests->tx_done[tx_queue->queue],
 271			      EF4_TX_QUEUE_NAME(tx_queue),
 272			      EF4_LOOPBACK_NAME(mode, "tx_done"));
 273	}
 274	ef4_fill_test(test_index++, strings, data,
 275		      &lb_tests->rx_good,
 276		      "rx", 0,
 277		      EF4_LOOPBACK_NAME(mode, "rx_good"));
 278	ef4_fill_test(test_index++, strings, data,
 279		      &lb_tests->rx_bad,
 280		      "rx", 0,
 281		      EF4_LOOPBACK_NAME(mode, "rx_bad"));
 282
 283	return test_index;
 284}
 285
 286/**
 287 * ef4_ethtool_fill_self_tests - get self-test details
 288 * @efx:		Efx NIC
 289 * @tests:		Efx self-test results structure, or %NULL
 290 * @strings:		Ethtool strings, or %NULL
 291 * @data:		Ethtool test results, or %NULL
 292 *
 293 * Get self-test number of strings, strings, and/or test results.
 294 * Return number of strings (== number of test results).
 295 *
 296 * The reason for merging these three functions is to make sure that
 297 * they can never be inconsistent.
 298 */
 299static int ef4_ethtool_fill_self_tests(struct ef4_nic *efx,
 300				       struct ef4_self_tests *tests,
 301				       u8 *strings, u64 *data)
 302{
 303	struct ef4_channel *channel;
 304	unsigned int n = 0, i;
 305	enum ef4_loopback_mode mode;
 306
 307	ef4_fill_test(n++, strings, data, &tests->phy_alive,
 308		      "phy", 0, "alive", NULL);
 309	ef4_fill_test(n++, strings, data, &tests->nvram,
 310		      "core", 0, "nvram", NULL);
 311	ef4_fill_test(n++, strings, data, &tests->interrupt,
 312		      "core", 0, "interrupt", NULL);
 313
 314	/* Event queues */
 315	ef4_for_each_channel(channel, efx) {
 316		ef4_fill_test(n++, strings, data,
 317			      &tests->eventq_dma[channel->channel],
 318			      EF4_CHANNEL_NAME(channel),
 319			      "eventq.dma", NULL);
 320		ef4_fill_test(n++, strings, data,
 321			      &tests->eventq_int[channel->channel],
 322			      EF4_CHANNEL_NAME(channel),
 323			      "eventq.int", NULL);
 324	}
 325
 326	ef4_fill_test(n++, strings, data, &tests->memory,
 327		      "core", 0, "memory", NULL);
 328	ef4_fill_test(n++, strings, data, &tests->registers,
 329		      "core", 0, "registers", NULL);
 330
 331	if (efx->phy_op->run_tests != NULL) {
 332		EF4_BUG_ON_PARANOID(efx->phy_op->test_name == NULL);
 333
 334		for (i = 0; true; ++i) {
 335			const char *name;
 336
 337			EF4_BUG_ON_PARANOID(i >= EF4_MAX_PHY_TESTS);
 338			name = efx->phy_op->test_name(efx, i);
 339			if (name == NULL)
 340				break;
 341
 342			ef4_fill_test(n++, strings, data, &tests->phy_ext[i],
 343				      "phy", 0, name, NULL);
 344		}
 345	}
 346
 347	/* Loopback tests */
 348	for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
 349		if (!(efx->loopback_modes & (1 << mode)))
 350			continue;
 351		n = ef4_fill_loopback_test(efx,
 352					   &tests->loopback[mode], mode, n,
 353					   strings, data);
 354	}
 355
 356	return n;
 357}
 358
 359static size_t ef4_describe_per_queue_stats(struct ef4_nic *efx, u8 *strings)
 360{
 361	size_t n_stats = 0;
 362	struct ef4_channel *channel;
 363
 364	ef4_for_each_channel(channel, efx) {
 365		if (ef4_channel_has_tx_queues(channel)) {
 366			n_stats++;
 367			if (strings != NULL) {
 368				snprintf(strings, ETH_GSTRING_LEN,
 369					 "tx-%u.tx_packets",
 370					 channel->tx_queue[0].queue /
 371					 EF4_TXQ_TYPES);
 372
 373				strings += ETH_GSTRING_LEN;
 374			}
 375		}
 376	}
 377	ef4_for_each_channel(channel, efx) {
 378		if (ef4_channel_has_rx_queue(channel)) {
 379			n_stats++;
 380			if (strings != NULL) {
 381				snprintf(strings, ETH_GSTRING_LEN,
 382					 "rx-%d.rx_packets", channel->channel);
 383				strings += ETH_GSTRING_LEN;
 384			}
 385		}
 386	}
 387	return n_stats;
 388}
 389
 390static int ef4_ethtool_get_sset_count(struct net_device *net_dev,
 391				      int string_set)
 392{
 393	struct ef4_nic *efx = netdev_priv(net_dev);
 394
 395	switch (string_set) {
 396	case ETH_SS_STATS:
 397		return efx->type->describe_stats(efx, NULL) +
 398		       EF4_ETHTOOL_SW_STAT_COUNT +
 399		       ef4_describe_per_queue_stats(efx, NULL);
 400	case ETH_SS_TEST:
 401		return ef4_ethtool_fill_self_tests(efx, NULL, NULL, NULL);
 402	default:
 403		return -EINVAL;
 404	}
 405}
 406
 407static void ef4_ethtool_get_strings(struct net_device *net_dev,
 408				    u32 string_set, u8 *strings)
 409{
 410	struct ef4_nic *efx = netdev_priv(net_dev);
 411	int i;
 412
 413	switch (string_set) {
 414	case ETH_SS_STATS:
 415		strings += (efx->type->describe_stats(efx, strings) *
 416			    ETH_GSTRING_LEN);
 417		for (i = 0; i < EF4_ETHTOOL_SW_STAT_COUNT; i++)
 418			strlcpy(strings + i * ETH_GSTRING_LEN,
 419				ef4_sw_stat_desc[i].name, ETH_GSTRING_LEN);
 420		strings += EF4_ETHTOOL_SW_STAT_COUNT * ETH_GSTRING_LEN;
 421		strings += (ef4_describe_per_queue_stats(efx, strings) *
 422			    ETH_GSTRING_LEN);
 423		break;
 424	case ETH_SS_TEST:
 425		ef4_ethtool_fill_self_tests(efx, NULL, strings, NULL);
 426		break;
 427	default:
 428		/* No other string sets */
 429		break;
 430	}
 431}
 432
 433static void ef4_ethtool_get_stats(struct net_device *net_dev,
 434				  struct ethtool_stats *stats,
 435				  u64 *data)
 436{
 437	struct ef4_nic *efx = netdev_priv(net_dev);
 438	const struct ef4_sw_stat_desc *stat;
 439	struct ef4_channel *channel;
 440	struct ef4_tx_queue *tx_queue;
 441	struct ef4_rx_queue *rx_queue;
 442	int i;
 443
 444	spin_lock_bh(&efx->stats_lock);
 445
 446	/* Get NIC statistics */
 447	data += efx->type->update_stats(efx, data, NULL);
 448
 449	/* Get software statistics */
 450	for (i = 0; i < EF4_ETHTOOL_SW_STAT_COUNT; i++) {
 451		stat = &ef4_sw_stat_desc[i];
 452		switch (stat->source) {
 453		case EF4_ETHTOOL_STAT_SOURCE_nic:
 454			data[i] = stat->get_stat((void *)efx + stat->offset);
 455			break;
 456		case EF4_ETHTOOL_STAT_SOURCE_channel:
 457			data[i] = 0;
 458			ef4_for_each_channel(channel, efx)
 459				data[i] += stat->get_stat((void *)channel +
 460							  stat->offset);
 461			break;
 462		case EF4_ETHTOOL_STAT_SOURCE_tx_queue:
 463			data[i] = 0;
 464			ef4_for_each_channel(channel, efx) {
 465				ef4_for_each_channel_tx_queue(tx_queue, channel)
 466					data[i] +=
 467						stat->get_stat((void *)tx_queue
 468							       + stat->offset);
 469			}
 470			break;
 471		}
 472	}
 473	data += EF4_ETHTOOL_SW_STAT_COUNT;
 474
 475	spin_unlock_bh(&efx->stats_lock);
 476
 477	ef4_for_each_channel(channel, efx) {
 478		if (ef4_channel_has_tx_queues(channel)) {
 479			*data = 0;
 480			ef4_for_each_channel_tx_queue(tx_queue, channel) {
 481				*data += tx_queue->tx_packets;
 482			}
 483			data++;
 484		}
 485	}
 486	ef4_for_each_channel(channel, efx) {
 487		if (ef4_channel_has_rx_queue(channel)) {
 488			*data = 0;
 489			ef4_for_each_channel_rx_queue(rx_queue, channel) {
 490				*data += rx_queue->rx_packets;
 491			}
 492			data++;
 493		}
 494	}
 495}
 496
 497static void ef4_ethtool_self_test(struct net_device *net_dev,
 498				  struct ethtool_test *test, u64 *data)
 499{
 500	struct ef4_nic *efx = netdev_priv(net_dev);
 501	struct ef4_self_tests *ef4_tests;
 502	bool already_up;
 503	int rc = -ENOMEM;
 504
 505	ef4_tests = kzalloc(sizeof(*ef4_tests), GFP_KERNEL);
 506	if (!ef4_tests)
 507		goto fail;
 508
 509	if (efx->state != STATE_READY) {
 510		rc = -EBUSY;
 511		goto out;
 512	}
 513
 514	netif_info(efx, drv, efx->net_dev, "starting %sline testing\n",
 515		   (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
 516
 517	/* We need rx buffers and interrupts. */
 518	already_up = (efx->net_dev->flags & IFF_UP);
 519	if (!already_up) {
 520		rc = dev_open(efx->net_dev);
 521		if (rc) {
 522			netif_err(efx, drv, efx->net_dev,
 523				  "failed opening device.\n");
 524			goto out;
 525		}
 526	}
 527
 528	rc = ef4_selftest(efx, ef4_tests, test->flags);
 529
 530	if (!already_up)
 531		dev_close(efx->net_dev);
 532
 533	netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n",
 534		   rc == 0 ? "passed" : "failed",
 535		   (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
 536
 537out:
 538	ef4_ethtool_fill_self_tests(efx, ef4_tests, NULL, data);
 539	kfree(ef4_tests);
 540fail:
 541	if (rc)
 542		test->flags |= ETH_TEST_FL_FAILED;
 543}
 544
 545/* Restart autonegotiation */
 546static int ef4_ethtool_nway_reset(struct net_device *net_dev)
 547{
 548	struct ef4_nic *efx = netdev_priv(net_dev);
 549
 550	return mdio45_nway_restart(&efx->mdio);
 551}
 552
 553/*
 554 * Each channel has a single IRQ and moderation timer, started by any
 555 * completion (or other event).  Unless the module parameter
 556 * separate_tx_channels is set, IRQs and moderation are therefore
 557 * shared between RX and TX completions.  In this case, when RX IRQ
 558 * moderation is explicitly changed then TX IRQ moderation is
 559 * automatically changed too, but otherwise we fail if the two values
 560 * are requested to be different.
 561 *
 562 * The hardware does not support a limit on the number of completions
 563 * before an IRQ, so we do not use the max_frames fields.  We should
 564 * report and require that max_frames == (usecs != 0), but this would
 565 * invalidate existing user documentation.
 566 *
 567 * The hardware does not have distinct settings for interrupt
 568 * moderation while the previous IRQ is being handled, so we should
 569 * not use the 'irq' fields.  However, an earlier developer
 570 * misunderstood the meaning of the 'irq' fields and the driver did
 571 * not support the standard fields.  To avoid invalidating existing
 572 * user documentation, we report and accept changes through either the
 573 * standard or 'irq' fields.  If both are changed at the same time, we
 574 * prefer the standard field.
 575 *
 576 * We implement adaptive IRQ moderation, but use a different algorithm
 577 * from that assumed in the definition of struct ethtool_coalesce.
 578 * Therefore we do not use any of the adaptive moderation parameters
 579 * in it.
 580 */
 581
 582static int ef4_ethtool_get_coalesce(struct net_device *net_dev,
 583				    struct ethtool_coalesce *coalesce)
 584{
 585	struct ef4_nic *efx = netdev_priv(net_dev);
 586	unsigned int tx_usecs, rx_usecs;
 587	bool rx_adaptive;
 588
 589	ef4_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &rx_adaptive);
 590
 591	coalesce->tx_coalesce_usecs = tx_usecs;
 592	coalesce->tx_coalesce_usecs_irq = tx_usecs;
 593	coalesce->rx_coalesce_usecs = rx_usecs;
 594	coalesce->rx_coalesce_usecs_irq = rx_usecs;
 595	coalesce->use_adaptive_rx_coalesce = rx_adaptive;
 596
 597	return 0;
 598}
 599
 600static int ef4_ethtool_set_coalesce(struct net_device *net_dev,
 601				    struct ethtool_coalesce *coalesce)
 602{
 603	struct ef4_nic *efx = netdev_priv(net_dev);
 604	struct ef4_channel *channel;
 605	unsigned int tx_usecs, rx_usecs;
 606	bool adaptive, rx_may_override_tx;
 607	int rc;
 608
 609	if (coalesce->use_adaptive_tx_coalesce)
 610		return -EINVAL;
 611
 612	ef4_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &adaptive);
 613
 614	if (coalesce->rx_coalesce_usecs != rx_usecs)
 615		rx_usecs = coalesce->rx_coalesce_usecs;
 616	else
 617		rx_usecs = coalesce->rx_coalesce_usecs_irq;
 618
 619	adaptive = coalesce->use_adaptive_rx_coalesce;
 620
 621	/* If channels are shared, TX IRQ moderation can be quietly
 622	 * overridden unless it is changed from its old value.
 623	 */
 624	rx_may_override_tx = (coalesce->tx_coalesce_usecs == tx_usecs &&
 625			      coalesce->tx_coalesce_usecs_irq == tx_usecs);
 626	if (coalesce->tx_coalesce_usecs != tx_usecs)
 627		tx_usecs = coalesce->tx_coalesce_usecs;
 628	else
 629		tx_usecs = coalesce->tx_coalesce_usecs_irq;
 630
 631	rc = ef4_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive,
 632				     rx_may_override_tx);
 633	if (rc != 0)
 634		return rc;
 635
 636	ef4_for_each_channel(channel, efx)
 637		efx->type->push_irq_moderation(channel);
 638
 639	return 0;
 640}
 641
 642static void ef4_ethtool_get_ringparam(struct net_device *net_dev,
 643				      struct ethtool_ringparam *ring)
 644{
 645	struct ef4_nic *efx = netdev_priv(net_dev);
 646
 647	ring->rx_max_pending = EF4_MAX_DMAQ_SIZE;
 648	ring->tx_max_pending = EF4_MAX_DMAQ_SIZE;
 649	ring->rx_pending = efx->rxq_entries;
 650	ring->tx_pending = efx->txq_entries;
 651}
 652
 653static int ef4_ethtool_set_ringparam(struct net_device *net_dev,
 654				     struct ethtool_ringparam *ring)
 655{
 656	struct ef4_nic *efx = netdev_priv(net_dev);
 657	u32 txq_entries;
 658
 659	if (ring->rx_mini_pending || ring->rx_jumbo_pending ||
 660	    ring->rx_pending > EF4_MAX_DMAQ_SIZE ||
 661	    ring->tx_pending > EF4_MAX_DMAQ_SIZE)
 662		return -EINVAL;
 663
 664	if (ring->rx_pending < EF4_RXQ_MIN_ENT) {
 665		netif_err(efx, drv, efx->net_dev,
 666			  "RX queues cannot be smaller than %u\n",
 667			  EF4_RXQ_MIN_ENT);
 668		return -EINVAL;
 669	}
 670
 671	txq_entries = max(ring->tx_pending, EF4_TXQ_MIN_ENT(efx));
 672	if (txq_entries != ring->tx_pending)
 673		netif_warn(efx, drv, efx->net_dev,
 674			   "increasing TX queue size to minimum of %u\n",
 675			   txq_entries);
 676
 677	return ef4_realloc_channels(efx, ring->rx_pending, txq_entries);
 678}
 679
 680static int ef4_ethtool_set_pauseparam(struct net_device *net_dev,
 681				      struct ethtool_pauseparam *pause)
 682{
 683	struct ef4_nic *efx = netdev_priv(net_dev);
 684	u8 wanted_fc, old_fc;
 685	u32 old_adv;
 686	int rc = 0;
 687
 688	mutex_lock(&efx->mac_lock);
 689
 690	wanted_fc = ((pause->rx_pause ? EF4_FC_RX : 0) |
 691		     (pause->tx_pause ? EF4_FC_TX : 0) |
 692		     (pause->autoneg ? EF4_FC_AUTO : 0));
 693
 694	if ((wanted_fc & EF4_FC_TX) && !(wanted_fc & EF4_FC_RX)) {
 695		netif_dbg(efx, drv, efx->net_dev,
 696			  "Flow control unsupported: tx ON rx OFF\n");
 697		rc = -EINVAL;
 698		goto out;
 699	}
 700
 701	if ((wanted_fc & EF4_FC_AUTO) && !efx->link_advertising) {
 702		netif_dbg(efx, drv, efx->net_dev,
 703			  "Autonegotiation is disabled\n");
 704		rc = -EINVAL;
 705		goto out;
 706	}
 707
 708	/* Hook for Falcon bug 11482 workaround */
 709	if (efx->type->prepare_enable_fc_tx &&
 710	    (wanted_fc & EF4_FC_TX) && !(efx->wanted_fc & EF4_FC_TX))
 711		efx->type->prepare_enable_fc_tx(efx);
 712
 713	old_adv = efx->link_advertising;
 714	old_fc = efx->wanted_fc;
 715	ef4_link_set_wanted_fc(efx, wanted_fc);
 716	if (efx->link_advertising != old_adv ||
 717	    (efx->wanted_fc ^ old_fc) & EF4_FC_AUTO) {
 718		rc = efx->phy_op->reconfigure(efx);
 719		if (rc) {
 720			netif_err(efx, drv, efx->net_dev,
 721				  "Unable to advertise requested flow "
 722				  "control setting\n");
 723			goto out;
 724		}
 725	}
 726
 727	/* Reconfigure the MAC. The PHY *may* generate a link state change event
 728	 * if the user just changed the advertised capabilities, but there's no
 729	 * harm doing this twice */
 730	ef4_mac_reconfigure(efx);
 731
 732out:
 733	mutex_unlock(&efx->mac_lock);
 734
 735	return rc;
 736}
 737
 738static void ef4_ethtool_get_pauseparam(struct net_device *net_dev,
 739				       struct ethtool_pauseparam *pause)
 740{
 741	struct ef4_nic *efx = netdev_priv(net_dev);
 742
 743	pause->rx_pause = !!(efx->wanted_fc & EF4_FC_RX);
 744	pause->tx_pause = !!(efx->wanted_fc & EF4_FC_TX);
 745	pause->autoneg = !!(efx->wanted_fc & EF4_FC_AUTO);
 746}
 747
 748static void ef4_ethtool_get_wol(struct net_device *net_dev,
 749				struct ethtool_wolinfo *wol)
 750{
 751	struct ef4_nic *efx = netdev_priv(net_dev);
 752	return efx->type->get_wol(efx, wol);
 753}
 754
 755
 756static int ef4_ethtool_set_wol(struct net_device *net_dev,
 757			       struct ethtool_wolinfo *wol)
 758{
 759	struct ef4_nic *efx = netdev_priv(net_dev);
 760	return efx->type->set_wol(efx, wol->wolopts);
 761}
 762
 763static int ef4_ethtool_reset(struct net_device *net_dev, u32 *flags)
 764{
 765	struct ef4_nic *efx = netdev_priv(net_dev);
 766	int rc;
 767
 768	rc = efx->type->map_reset_flags(flags);
 769	if (rc < 0)
 770		return rc;
 771
 772	return ef4_reset(efx, rc);
 773}
 774
 775/* MAC address mask including only I/G bit */
 776static const u8 mac_addr_ig_mask[ETH_ALEN] __aligned(2) = {0x01, 0, 0, 0, 0, 0};
 777
 778#define IP4_ADDR_FULL_MASK	((__force __be32)~0)
 779#define IP_PROTO_FULL_MASK	0xFF
 780#define PORT_FULL_MASK		((__force __be16)~0)
 781#define ETHER_TYPE_FULL_MASK	((__force __be16)~0)
 782
 783static inline void ip6_fill_mask(__be32 *mask)
 784{
 785	mask[0] = mask[1] = mask[2] = mask[3] = ~(__be32)0;
 786}
 787
 788static int ef4_ethtool_get_class_rule(struct ef4_nic *efx,
 789				      struct ethtool_rx_flow_spec *rule)
 790{
 791	struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
 792	struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
 793	struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
 794	struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
 795	struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
 796	struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
 797	struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
 798	struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
 799	struct ethhdr *mac_entry = &rule->h_u.ether_spec;
 800	struct ethhdr *mac_mask = &rule->m_u.ether_spec;
 801	struct ef4_filter_spec spec;
 802	int rc;
 803
 804	rc = ef4_filter_get_filter_safe(efx, EF4_FILTER_PRI_MANUAL,
 805					rule->location, &spec);
 806	if (rc)
 807		return rc;
 808
 809	if (spec.dmaq_id == EF4_FILTER_RX_DMAQ_ID_DROP)
 810		rule->ring_cookie = RX_CLS_FLOW_DISC;
 811	else
 812		rule->ring_cookie = spec.dmaq_id;
 813
 814	if ((spec.match_flags & EF4_FILTER_MATCH_ETHER_TYPE) &&
 815	    spec.ether_type == htons(ETH_P_IP) &&
 816	    (spec.match_flags & EF4_FILTER_MATCH_IP_PROTO) &&
 817	    (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
 818	    !(spec.match_flags &
 819	      ~(EF4_FILTER_MATCH_ETHER_TYPE | EF4_FILTER_MATCH_OUTER_VID |
 820		EF4_FILTER_MATCH_LOC_HOST | EF4_FILTER_MATCH_REM_HOST |
 821		EF4_FILTER_MATCH_IP_PROTO |
 822		EF4_FILTER_MATCH_LOC_PORT | EF4_FILTER_MATCH_REM_PORT))) {
 823		rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
 824				   TCP_V4_FLOW : UDP_V4_FLOW);
 825		if (spec.match_flags & EF4_FILTER_MATCH_LOC_HOST) {
 826			ip_entry->ip4dst = spec.loc_host[0];
 827			ip_mask->ip4dst = IP4_ADDR_FULL_MASK;
 828		}
 829		if (spec.match_flags & EF4_FILTER_MATCH_REM_HOST) {
 830			ip_entry->ip4src = spec.rem_host[0];
 831			ip_mask->ip4src = IP4_ADDR_FULL_MASK;
 832		}
 833		if (spec.match_flags & EF4_FILTER_MATCH_LOC_PORT) {
 834			ip_entry->pdst = spec.loc_port;
 835			ip_mask->pdst = PORT_FULL_MASK;
 836		}
 837		if (spec.match_flags & EF4_FILTER_MATCH_REM_PORT) {
 838			ip_entry->psrc = spec.rem_port;
 839			ip_mask->psrc = PORT_FULL_MASK;
 840		}
 841	} else if ((spec.match_flags & EF4_FILTER_MATCH_ETHER_TYPE) &&
 842	    spec.ether_type == htons(ETH_P_IPV6) &&
 843	    (spec.match_flags & EF4_FILTER_MATCH_IP_PROTO) &&
 844	    (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
 845	    !(spec.match_flags &
 846	      ~(EF4_FILTER_MATCH_ETHER_TYPE | EF4_FILTER_MATCH_OUTER_VID |
 847		EF4_FILTER_MATCH_LOC_HOST | EF4_FILTER_MATCH_REM_HOST |
 848		EF4_FILTER_MATCH_IP_PROTO |
 849		EF4_FILTER_MATCH_LOC_PORT | EF4_FILTER_MATCH_REM_PORT))) {
 850		rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
 851				   TCP_V6_FLOW : UDP_V6_FLOW);
 852		if (spec.match_flags & EF4_FILTER_MATCH_LOC_HOST) {
 853			memcpy(ip6_entry->ip6dst, spec.loc_host,
 854			       sizeof(ip6_entry->ip6dst));
 855			ip6_fill_mask(ip6_mask->ip6dst);
 856		}
 857		if (spec.match_flags & EF4_FILTER_MATCH_REM_HOST) {
 858			memcpy(ip6_entry->ip6src, spec.rem_host,
 859			       sizeof(ip6_entry->ip6src));
 860			ip6_fill_mask(ip6_mask->ip6src);
 861		}
 862		if (spec.match_flags & EF4_FILTER_MATCH_LOC_PORT) {
 863			ip6_entry->pdst = spec.loc_port;
 864			ip6_mask->pdst = PORT_FULL_MASK;
 865		}
 866		if (spec.match_flags & EF4_FILTER_MATCH_REM_PORT) {
 867			ip6_entry->psrc = spec.rem_port;
 868			ip6_mask->psrc = PORT_FULL_MASK;
 869		}
 870	} else if (!(spec.match_flags &
 871		     ~(EF4_FILTER_MATCH_LOC_MAC | EF4_FILTER_MATCH_LOC_MAC_IG |
 872		       EF4_FILTER_MATCH_REM_MAC | EF4_FILTER_MATCH_ETHER_TYPE |
 873		       EF4_FILTER_MATCH_OUTER_VID))) {
 874		rule->flow_type = ETHER_FLOW;
 875		if (spec.match_flags &
 876		    (EF4_FILTER_MATCH_LOC_MAC | EF4_FILTER_MATCH_LOC_MAC_IG)) {
 877			ether_addr_copy(mac_entry->h_dest, spec.loc_mac);
 878			if (spec.match_flags & EF4_FILTER_MATCH_LOC_MAC)
 879				eth_broadcast_addr(mac_mask->h_dest);
 880			else
 881				ether_addr_copy(mac_mask->h_dest,
 882						mac_addr_ig_mask);
 883		}
 884		if (spec.match_flags & EF4_FILTER_MATCH_REM_MAC) {
 885			ether_addr_copy(mac_entry->h_source, spec.rem_mac);
 886			eth_broadcast_addr(mac_mask->h_source);
 887		}
 888		if (spec.match_flags & EF4_FILTER_MATCH_ETHER_TYPE) {
 889			mac_entry->h_proto = spec.ether_type;
 890			mac_mask->h_proto = ETHER_TYPE_FULL_MASK;
 891		}
 892	} else if (spec.match_flags & EF4_FILTER_MATCH_ETHER_TYPE &&
 893		   spec.ether_type == htons(ETH_P_IP) &&
 894		   !(spec.match_flags &
 895		     ~(EF4_FILTER_MATCH_ETHER_TYPE | EF4_FILTER_MATCH_OUTER_VID |
 896		       EF4_FILTER_MATCH_LOC_HOST | EF4_FILTER_MATCH_REM_HOST |
 897		       EF4_FILTER_MATCH_IP_PROTO))) {
 898		rule->flow_type = IPV4_USER_FLOW;
 899		uip_entry->ip_ver = ETH_RX_NFC_IP4;
 900		if (spec.match_flags & EF4_FILTER_MATCH_IP_PROTO) {
 901			uip_mask->proto = IP_PROTO_FULL_MASK;
 902			uip_entry->proto = spec.ip_proto;
 903		}
 904		if (spec.match_flags & EF4_FILTER_MATCH_LOC_HOST) {
 905			uip_entry->ip4dst = spec.loc_host[0];
 906			uip_mask->ip4dst = IP4_ADDR_FULL_MASK;
 907		}
 908		if (spec.match_flags & EF4_FILTER_MATCH_REM_HOST) {
 909			uip_entry->ip4src = spec.rem_host[0];
 910			uip_mask->ip4src = IP4_ADDR_FULL_MASK;
 911		}
 912	} else if (spec.match_flags & EF4_FILTER_MATCH_ETHER_TYPE &&
 913		   spec.ether_type == htons(ETH_P_IPV6) &&
 914		   !(spec.match_flags &
 915		     ~(EF4_FILTER_MATCH_ETHER_TYPE | EF4_FILTER_MATCH_OUTER_VID |
 916		       EF4_FILTER_MATCH_LOC_HOST | EF4_FILTER_MATCH_REM_HOST |
 917		       EF4_FILTER_MATCH_IP_PROTO))) {
 918		rule->flow_type = IPV6_USER_FLOW;
 919		if (spec.match_flags & EF4_FILTER_MATCH_IP_PROTO) {
 920			uip6_mask->l4_proto = IP_PROTO_FULL_MASK;
 921			uip6_entry->l4_proto = spec.ip_proto;
 922		}
 923		if (spec.match_flags & EF4_FILTER_MATCH_LOC_HOST) {
 924			memcpy(uip6_entry->ip6dst, spec.loc_host,
 925			       sizeof(uip6_entry->ip6dst));
 926			ip6_fill_mask(uip6_mask->ip6dst);
 927		}
 928		if (spec.match_flags & EF4_FILTER_MATCH_REM_HOST) {
 929			memcpy(uip6_entry->ip6src, spec.rem_host,
 930			       sizeof(uip6_entry->ip6src));
 931			ip6_fill_mask(uip6_mask->ip6src);
 932		}
 933	} else {
 934		/* The above should handle all filters that we insert */
 935		WARN_ON(1);
 936		return -EINVAL;
 937	}
 938
 939	if (spec.match_flags & EF4_FILTER_MATCH_OUTER_VID) {
 940		rule->flow_type |= FLOW_EXT;
 941		rule->h_ext.vlan_tci = spec.outer_vid;
 942		rule->m_ext.vlan_tci = htons(0xfff);
 943	}
 944
 945	return rc;
 946}
 947
 948static int
 949ef4_ethtool_get_rxnfc(struct net_device *net_dev,
 950		      struct ethtool_rxnfc *info, u32 *rule_locs)
 951{
 952	struct ef4_nic *efx = netdev_priv(net_dev);
 953
 954	switch (info->cmd) {
 955	case ETHTOOL_GRXRINGS:
 956		info->data = efx->n_rx_channels;
 957		return 0;
 958
 959	case ETHTOOL_GRXFH: {
 960		unsigned min_revision = 0;
 961
 962		info->data = 0;
 963		switch (info->flow_type) {
 964		case TCP_V4_FLOW:
 965			info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
 
 966		case UDP_V4_FLOW:
 967		case SCTP_V4_FLOW:
 968		case AH_ESP_V4_FLOW:
 969		case IPV4_FLOW:
 970			info->data |= RXH_IP_SRC | RXH_IP_DST;
 971			min_revision = EF4_REV_FALCON_B0;
 972			break;
 973		default:
 974			break;
 975		}
 976		if (ef4_nic_rev(efx) < min_revision)
 977			info->data = 0;
 978		return 0;
 979	}
 980
 981	case ETHTOOL_GRXCLSRLCNT:
 982		info->data = ef4_filter_get_rx_id_limit(efx);
 983		if (info->data == 0)
 984			return -EOPNOTSUPP;
 985		info->data |= RX_CLS_LOC_SPECIAL;
 986		info->rule_cnt =
 987			ef4_filter_count_rx_used(efx, EF4_FILTER_PRI_MANUAL);
 988		return 0;
 989
 990	case ETHTOOL_GRXCLSRULE:
 991		if (ef4_filter_get_rx_id_limit(efx) == 0)
 992			return -EOPNOTSUPP;
 993		return ef4_ethtool_get_class_rule(efx, &info->fs);
 994
 995	case ETHTOOL_GRXCLSRLALL: {
 996		s32 rc;
 997		info->data = ef4_filter_get_rx_id_limit(efx);
 998		if (info->data == 0)
 999			return -EOPNOTSUPP;
1000		rc = ef4_filter_get_rx_ids(efx, EF4_FILTER_PRI_MANUAL,
1001					   rule_locs, info->rule_cnt);
1002		if (rc < 0)
1003			return rc;
1004		info->rule_cnt = rc;
1005		return 0;
1006	}
1007
1008	default:
1009		return -EOPNOTSUPP;
1010	}
1011}
1012
1013static inline bool ip6_mask_is_full(__be32 mask[4])
1014{
1015	return !~(mask[0] & mask[1] & mask[2] & mask[3]);
1016}
1017
1018static inline bool ip6_mask_is_empty(__be32 mask[4])
1019{
1020	return !(mask[0] | mask[1] | mask[2] | mask[3]);
1021}
1022
1023static int ef4_ethtool_set_class_rule(struct ef4_nic *efx,
1024				      struct ethtool_rx_flow_spec *rule)
1025{
1026	struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
1027	struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
1028	struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
1029	struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
1030	struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
1031	struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
1032	struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
1033	struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
1034	struct ethhdr *mac_entry = &rule->h_u.ether_spec;
1035	struct ethhdr *mac_mask = &rule->m_u.ether_spec;
1036	struct ef4_filter_spec spec;
1037	int rc;
1038
1039	/* Check that user wants us to choose the location */
1040	if (rule->location != RX_CLS_LOC_ANY)
1041		return -EINVAL;
1042
1043	/* Range-check ring_cookie */
1044	if (rule->ring_cookie >= efx->n_rx_channels &&
1045	    rule->ring_cookie != RX_CLS_FLOW_DISC)
1046		return -EINVAL;
1047
1048	/* Check for unsupported extensions */
1049	if ((rule->flow_type & FLOW_EXT) &&
1050	    (rule->m_ext.vlan_etype || rule->m_ext.data[0] ||
1051	     rule->m_ext.data[1]))
1052		return -EINVAL;
1053
1054	ef4_filter_init_rx(&spec, EF4_FILTER_PRI_MANUAL,
1055			   efx->rx_scatter ? EF4_FILTER_FLAG_RX_SCATTER : 0,
1056			   (rule->ring_cookie == RX_CLS_FLOW_DISC) ?
1057			   EF4_FILTER_RX_DMAQ_ID_DROP : rule->ring_cookie);
1058
1059	switch (rule->flow_type & ~FLOW_EXT) {
1060	case TCP_V4_FLOW:
1061	case UDP_V4_FLOW:
1062		spec.match_flags = (EF4_FILTER_MATCH_ETHER_TYPE |
1063				    EF4_FILTER_MATCH_IP_PROTO);
1064		spec.ether_type = htons(ETH_P_IP);
1065		spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V4_FLOW ?
1066				 IPPROTO_TCP : IPPROTO_UDP);
1067		if (ip_mask->ip4dst) {
1068			if (ip_mask->ip4dst != IP4_ADDR_FULL_MASK)
1069				return -EINVAL;
1070			spec.match_flags |= EF4_FILTER_MATCH_LOC_HOST;
1071			spec.loc_host[0] = ip_entry->ip4dst;
1072		}
1073		if (ip_mask->ip4src) {
1074			if (ip_mask->ip4src != IP4_ADDR_FULL_MASK)
1075				return -EINVAL;
1076			spec.match_flags |= EF4_FILTER_MATCH_REM_HOST;
1077			spec.rem_host[0] = ip_entry->ip4src;
1078		}
1079		if (ip_mask->pdst) {
1080			if (ip_mask->pdst != PORT_FULL_MASK)
1081				return -EINVAL;
1082			spec.match_flags |= EF4_FILTER_MATCH_LOC_PORT;
1083			spec.loc_port = ip_entry->pdst;
1084		}
1085		if (ip_mask->psrc) {
1086			if (ip_mask->psrc != PORT_FULL_MASK)
1087				return -EINVAL;
1088			spec.match_flags |= EF4_FILTER_MATCH_REM_PORT;
1089			spec.rem_port = ip_entry->psrc;
1090		}
1091		if (ip_mask->tos)
1092			return -EINVAL;
1093		break;
1094
1095	case TCP_V6_FLOW:
1096	case UDP_V6_FLOW:
1097		spec.match_flags = (EF4_FILTER_MATCH_ETHER_TYPE |
1098				    EF4_FILTER_MATCH_IP_PROTO);
1099		spec.ether_type = htons(ETH_P_IPV6);
1100		spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V6_FLOW ?
1101				 IPPROTO_TCP : IPPROTO_UDP);
1102		if (!ip6_mask_is_empty(ip6_mask->ip6dst)) {
1103			if (!ip6_mask_is_full(ip6_mask->ip6dst))
1104				return -EINVAL;
1105			spec.match_flags |= EF4_FILTER_MATCH_LOC_HOST;
1106			memcpy(spec.loc_host, ip6_entry->ip6dst, sizeof(spec.loc_host));
1107		}
1108		if (!ip6_mask_is_empty(ip6_mask->ip6src)) {
1109			if (!ip6_mask_is_full(ip6_mask->ip6src))
1110				return -EINVAL;
1111			spec.match_flags |= EF4_FILTER_MATCH_REM_HOST;
1112			memcpy(spec.rem_host, ip6_entry->ip6src, sizeof(spec.rem_host));
1113		}
1114		if (ip6_mask->pdst) {
1115			if (ip6_mask->pdst != PORT_FULL_MASK)
1116				return -EINVAL;
1117			spec.match_flags |= EF4_FILTER_MATCH_LOC_PORT;
1118			spec.loc_port = ip6_entry->pdst;
1119		}
1120		if (ip6_mask->psrc) {
1121			if (ip6_mask->psrc != PORT_FULL_MASK)
1122				return -EINVAL;
1123			spec.match_flags |= EF4_FILTER_MATCH_REM_PORT;
1124			spec.rem_port = ip6_entry->psrc;
1125		}
1126		if (ip6_mask->tclass)
1127			return -EINVAL;
1128		break;
1129
1130	case IPV4_USER_FLOW:
1131		if (uip_mask->l4_4_bytes || uip_mask->tos || uip_mask->ip_ver ||
1132		    uip_entry->ip_ver != ETH_RX_NFC_IP4)
1133			return -EINVAL;
1134		spec.match_flags = EF4_FILTER_MATCH_ETHER_TYPE;
1135		spec.ether_type = htons(ETH_P_IP);
1136		if (uip_mask->ip4dst) {
1137			if (uip_mask->ip4dst != IP4_ADDR_FULL_MASK)
1138				return -EINVAL;
1139			spec.match_flags |= EF4_FILTER_MATCH_LOC_HOST;
1140			spec.loc_host[0] = uip_entry->ip4dst;
1141		}
1142		if (uip_mask->ip4src) {
1143			if (uip_mask->ip4src != IP4_ADDR_FULL_MASK)
1144				return -EINVAL;
1145			spec.match_flags |= EF4_FILTER_MATCH_REM_HOST;
1146			spec.rem_host[0] = uip_entry->ip4src;
1147		}
1148		if (uip_mask->proto) {
1149			if (uip_mask->proto != IP_PROTO_FULL_MASK)
1150				return -EINVAL;
1151			spec.match_flags |= EF4_FILTER_MATCH_IP_PROTO;
1152			spec.ip_proto = uip_entry->proto;
1153		}
1154		break;
1155
1156	case IPV6_USER_FLOW:
1157		if (uip6_mask->l4_4_bytes || uip6_mask->tclass)
1158			return -EINVAL;
1159		spec.match_flags = EF4_FILTER_MATCH_ETHER_TYPE;
1160		spec.ether_type = htons(ETH_P_IPV6);
1161		if (!ip6_mask_is_empty(uip6_mask->ip6dst)) {
1162			if (!ip6_mask_is_full(uip6_mask->ip6dst))
1163				return -EINVAL;
1164			spec.match_flags |= EF4_FILTER_MATCH_LOC_HOST;
1165			memcpy(spec.loc_host, uip6_entry->ip6dst, sizeof(spec.loc_host));
1166		}
1167		if (!ip6_mask_is_empty(uip6_mask->ip6src)) {
1168			if (!ip6_mask_is_full(uip6_mask->ip6src))
1169				return -EINVAL;
1170			spec.match_flags |= EF4_FILTER_MATCH_REM_HOST;
1171			memcpy(spec.rem_host, uip6_entry->ip6src, sizeof(spec.rem_host));
1172		}
1173		if (uip6_mask->l4_proto) {
1174			if (uip6_mask->l4_proto != IP_PROTO_FULL_MASK)
1175				return -EINVAL;
1176			spec.match_flags |= EF4_FILTER_MATCH_IP_PROTO;
1177			spec.ip_proto = uip6_entry->l4_proto;
1178		}
1179		break;
1180
1181	case ETHER_FLOW:
1182		if (!is_zero_ether_addr(mac_mask->h_dest)) {
1183			if (ether_addr_equal(mac_mask->h_dest,
1184					     mac_addr_ig_mask))
1185				spec.match_flags |= EF4_FILTER_MATCH_LOC_MAC_IG;
1186			else if (is_broadcast_ether_addr(mac_mask->h_dest))
1187				spec.match_flags |= EF4_FILTER_MATCH_LOC_MAC;
1188			else
1189				return -EINVAL;
1190			ether_addr_copy(spec.loc_mac, mac_entry->h_dest);
1191		}
1192		if (!is_zero_ether_addr(mac_mask->h_source)) {
1193			if (!is_broadcast_ether_addr(mac_mask->h_source))
1194				return -EINVAL;
1195			spec.match_flags |= EF4_FILTER_MATCH_REM_MAC;
1196			ether_addr_copy(spec.rem_mac, mac_entry->h_source);
1197		}
1198		if (mac_mask->h_proto) {
1199			if (mac_mask->h_proto != ETHER_TYPE_FULL_MASK)
1200				return -EINVAL;
1201			spec.match_flags |= EF4_FILTER_MATCH_ETHER_TYPE;
1202			spec.ether_type = mac_entry->h_proto;
1203		}
1204		break;
1205
1206	default:
1207		return -EINVAL;
1208	}
1209
1210	if ((rule->flow_type & FLOW_EXT) && rule->m_ext.vlan_tci) {
1211		if (rule->m_ext.vlan_tci != htons(0xfff))
1212			return -EINVAL;
1213		spec.match_flags |= EF4_FILTER_MATCH_OUTER_VID;
1214		spec.outer_vid = rule->h_ext.vlan_tci;
1215	}
1216
1217	rc = ef4_filter_insert_filter(efx, &spec, true);
1218	if (rc < 0)
1219		return rc;
1220
1221	rule->location = rc;
1222	return 0;
1223}
1224
1225static int ef4_ethtool_set_rxnfc(struct net_device *net_dev,
1226				 struct ethtool_rxnfc *info)
1227{
1228	struct ef4_nic *efx = netdev_priv(net_dev);
1229
1230	if (ef4_filter_get_rx_id_limit(efx) == 0)
1231		return -EOPNOTSUPP;
1232
1233	switch (info->cmd) {
1234	case ETHTOOL_SRXCLSRLINS:
1235		return ef4_ethtool_set_class_rule(efx, &info->fs);
1236
1237	case ETHTOOL_SRXCLSRLDEL:
1238		return ef4_filter_remove_id_safe(efx, EF4_FILTER_PRI_MANUAL,
1239						 info->fs.location);
1240
1241	default:
1242		return -EOPNOTSUPP;
1243	}
1244}
1245
1246static u32 ef4_ethtool_get_rxfh_indir_size(struct net_device *net_dev)
1247{
1248	struct ef4_nic *efx = netdev_priv(net_dev);
1249
1250	return ((ef4_nic_rev(efx) < EF4_REV_FALCON_B0 ||
1251		 efx->n_rx_channels == 1) ?
1252		0 : ARRAY_SIZE(efx->rx_indir_table));
1253}
1254
1255static int ef4_ethtool_get_rxfh(struct net_device *net_dev, u32 *indir, u8 *key,
1256				u8 *hfunc)
1257{
1258	struct ef4_nic *efx = netdev_priv(net_dev);
1259
1260	if (hfunc)
1261		*hfunc = ETH_RSS_HASH_TOP;
1262	if (indir)
1263		memcpy(indir, efx->rx_indir_table, sizeof(efx->rx_indir_table));
1264	return 0;
1265}
1266
1267static int ef4_ethtool_set_rxfh(struct net_device *net_dev, const u32 *indir,
1268				const u8 *key, const u8 hfunc)
1269{
1270	struct ef4_nic *efx = netdev_priv(net_dev);
1271
1272	/* We do not allow change in unsupported parameters */
1273	if (key ||
1274	    (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
1275		return -EOPNOTSUPP;
1276	if (!indir)
1277		return 0;
1278
1279	return efx->type->rx_push_rss_config(efx, true, indir);
1280}
1281
1282static int ef4_ethtool_get_module_eeprom(struct net_device *net_dev,
1283					 struct ethtool_eeprom *ee,
1284					 u8 *data)
1285{
1286	struct ef4_nic *efx = netdev_priv(net_dev);
1287	int ret;
1288
1289	if (!efx->phy_op || !efx->phy_op->get_module_eeprom)
1290		return -EOPNOTSUPP;
1291
1292	mutex_lock(&efx->mac_lock);
1293	ret = efx->phy_op->get_module_eeprom(efx, ee, data);
1294	mutex_unlock(&efx->mac_lock);
1295
1296	return ret;
1297}
1298
1299static int ef4_ethtool_get_module_info(struct net_device *net_dev,
1300				       struct ethtool_modinfo *modinfo)
1301{
1302	struct ef4_nic *efx = netdev_priv(net_dev);
1303	int ret;
1304
1305	if (!efx->phy_op || !efx->phy_op->get_module_info)
1306		return -EOPNOTSUPP;
1307
1308	mutex_lock(&efx->mac_lock);
1309	ret = efx->phy_op->get_module_info(efx, modinfo);
1310	mutex_unlock(&efx->mac_lock);
1311
1312	return ret;
1313}
1314
1315const struct ethtool_ops ef4_ethtool_ops = {
 
 
 
1316	.get_drvinfo		= ef4_ethtool_get_drvinfo,
1317	.get_regs_len		= ef4_ethtool_get_regs_len,
1318	.get_regs		= ef4_ethtool_get_regs,
1319	.get_msglevel		= ef4_ethtool_get_msglevel,
1320	.set_msglevel		= ef4_ethtool_set_msglevel,
1321	.nway_reset		= ef4_ethtool_nway_reset,
1322	.get_link		= ethtool_op_get_link,
1323	.get_coalesce		= ef4_ethtool_get_coalesce,
1324	.set_coalesce		= ef4_ethtool_set_coalesce,
1325	.get_ringparam		= ef4_ethtool_get_ringparam,
1326	.set_ringparam		= ef4_ethtool_set_ringparam,
1327	.get_pauseparam         = ef4_ethtool_get_pauseparam,
1328	.set_pauseparam         = ef4_ethtool_set_pauseparam,
1329	.get_sset_count		= ef4_ethtool_get_sset_count,
1330	.self_test		= ef4_ethtool_self_test,
1331	.get_strings		= ef4_ethtool_get_strings,
1332	.set_phys_id		= ef4_ethtool_phys_id,
1333	.get_ethtool_stats	= ef4_ethtool_get_stats,
1334	.get_wol                = ef4_ethtool_get_wol,
1335	.set_wol                = ef4_ethtool_set_wol,
1336	.reset			= ef4_ethtool_reset,
1337	.get_rxnfc		= ef4_ethtool_get_rxnfc,
1338	.set_rxnfc		= ef4_ethtool_set_rxnfc,
1339	.get_rxfh_indir_size	= ef4_ethtool_get_rxfh_indir_size,
1340	.get_rxfh		= ef4_ethtool_get_rxfh,
1341	.set_rxfh		= ef4_ethtool_set_rxfh,
1342	.get_module_info	= ef4_ethtool_get_module_info,
1343	.get_module_eeprom	= ef4_ethtool_get_module_eeprom,
1344	.get_link_ksettings	= ef4_ethtool_get_link_ksettings,
1345	.set_link_ksettings	= ef4_ethtool_set_link_ksettings,
1346};
v5.14.15
   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 ef4_sw_stat_desc {
  20	const char *name;
  21	enum {
  22		EF4_ETHTOOL_STAT_SOURCE_nic,
  23		EF4_ETHTOOL_STAT_SOURCE_channel,
  24		EF4_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 ef4_sw_stat_desc with type-checking */
  31#define EF4_ETHTOOL_STAT(stat_name, source_name, field, field_type, \
  32				get_stat_function) {			\
  33	.name = #stat_name,						\
  34	.source = EF4_ETHTOOL_STAT_SOURCE_##source_name,		\
  35	.offset = ((((field_type *) 0) ==				\
  36		      &((struct ef4_##source_name *)0)->field) ?	\
  37		    offsetof(struct ef4_##source_name, field) :		\
  38		    offsetof(struct ef4_##source_name, field)),		\
  39	.get_stat = get_stat_function,					\
  40}
  41
  42static u64 ef4_get_uint_stat(void *field)
  43{
  44	return *(unsigned int *)field;
  45}
  46
  47static u64 ef4_get_atomic_stat(void *field)
  48{
  49	return atomic_read((atomic_t *) field);
  50}
  51
  52#define EF4_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field)		\
  53	EF4_ETHTOOL_STAT(field, nic, field,			\
  54			 atomic_t, ef4_get_atomic_stat)
  55
  56#define EF4_ETHTOOL_UINT_CHANNEL_STAT(field)			\
  57	EF4_ETHTOOL_STAT(field, channel, n_##field,		\
  58			 unsigned int, ef4_get_uint_stat)
  59
  60#define EF4_ETHTOOL_UINT_TXQ_STAT(field)			\
  61	EF4_ETHTOOL_STAT(tx_##field, tx_queue, field,		\
  62			 unsigned int, ef4_get_uint_stat)
  63
  64static const struct ef4_sw_stat_desc ef4_sw_stat_desc[] = {
  65	EF4_ETHTOOL_UINT_TXQ_STAT(merge_events),
  66	EF4_ETHTOOL_UINT_TXQ_STAT(pushes),
  67	EF4_ETHTOOL_UINT_TXQ_STAT(cb_packets),
  68	EF4_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset),
  69	EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc),
  70	EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),
  71	EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err),
  72	EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch),
  73	EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
  74	EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_events),
  75	EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_packets),
  76};
  77
  78#define EF4_ETHTOOL_SW_STAT_COUNT ARRAY_SIZE(ef4_sw_stat_desc)
  79
  80#define EF4_ETHTOOL_EEPROM_MAGIC 0xEFAB
  81
  82/**************************************************************************
  83 *
  84 * Ethtool operations
  85 *
  86 **************************************************************************
  87 */
  88
  89/* Identify device by flashing LEDs */
  90static int ef4_ethtool_phys_id(struct net_device *net_dev,
  91			       enum ethtool_phys_id_state state)
  92{
  93	struct ef4_nic *efx = netdev_priv(net_dev);
  94	enum ef4_led_mode mode = EF4_LED_DEFAULT;
  95
  96	switch (state) {
  97	case ETHTOOL_ID_ON:
  98		mode = EF4_LED_ON;
  99		break;
 100	case ETHTOOL_ID_OFF:
 101		mode = EF4_LED_OFF;
 102		break;
 103	case ETHTOOL_ID_INACTIVE:
 104		mode = EF4_LED_DEFAULT;
 105		break;
 106	case ETHTOOL_ID_ACTIVE:
 107		return 1;	/* cycle on/off once per second */
 108	}
 109
 110	efx->type->set_id_led(efx, mode);
 111	return 0;
 112}
 113
 114/* This must be called with rtnl_lock held. */
 115static int
 116ef4_ethtool_get_link_ksettings(struct net_device *net_dev,
 117			       struct ethtool_link_ksettings *cmd)
 118{
 119	struct ef4_nic *efx = netdev_priv(net_dev);
 120	struct ef4_link_state *link_state = &efx->link_state;
 121
 122	mutex_lock(&efx->mac_lock);
 123	efx->phy_op->get_link_ksettings(efx, cmd);
 124	mutex_unlock(&efx->mac_lock);
 125
 126	/* Both MACs support pause frames (bidirectional and respond-only) */
 127	ethtool_link_ksettings_add_link_mode(cmd, supported, Pause);
 128	ethtool_link_ksettings_add_link_mode(cmd, supported, Asym_Pause);
 129
 130	if (LOOPBACK_INTERNAL(efx)) {
 131		cmd->base.speed = link_state->speed;
 132		cmd->base.duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF;
 133	}
 134
 135	return 0;
 136}
 137
 138/* This must be called with rtnl_lock held. */
 139static int
 140ef4_ethtool_set_link_ksettings(struct net_device *net_dev,
 141			       const struct ethtool_link_ksettings *cmd)
 142{
 143	struct ef4_nic *efx = netdev_priv(net_dev);
 144	int rc;
 145
 146	/* GMAC does not support 1000Mbps HD */
 147	if ((cmd->base.speed == SPEED_1000) &&
 148	    (cmd->base.duplex != DUPLEX_FULL)) {
 149		netif_dbg(efx, drv, efx->net_dev,
 150			  "rejecting unsupported 1000Mbps HD setting\n");
 151		return -EINVAL;
 152	}
 153
 154	mutex_lock(&efx->mac_lock);
 155	rc = efx->phy_op->set_link_ksettings(efx, cmd);
 156	mutex_unlock(&efx->mac_lock);
 157	return rc;
 158}
 159
 160static void ef4_ethtool_get_drvinfo(struct net_device *net_dev,
 161				    struct ethtool_drvinfo *info)
 162{
 163	struct ef4_nic *efx = netdev_priv(net_dev);
 164
 165	strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
 166	strlcpy(info->version, EF4_DRIVER_VERSION, sizeof(info->version));
 167	strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
 168}
 169
 170static int ef4_ethtool_get_regs_len(struct net_device *net_dev)
 171{
 172	return ef4_nic_get_regs_len(netdev_priv(net_dev));
 173}
 174
 175static void ef4_ethtool_get_regs(struct net_device *net_dev,
 176				 struct ethtool_regs *regs, void *buf)
 177{
 178	struct ef4_nic *efx = netdev_priv(net_dev);
 179
 180	regs->version = efx->type->revision;
 181	ef4_nic_get_regs(efx, buf);
 182}
 183
 184static u32 ef4_ethtool_get_msglevel(struct net_device *net_dev)
 185{
 186	struct ef4_nic *efx = netdev_priv(net_dev);
 187	return efx->msg_enable;
 188}
 189
 190static void ef4_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable)
 191{
 192	struct ef4_nic *efx = netdev_priv(net_dev);
 193	efx->msg_enable = msg_enable;
 194}
 195
 196/**
 197 * ef4_fill_test - fill in an individual self-test entry
 198 * @test_index:		Index of the test
 199 * @strings:		Ethtool strings, or %NULL
 200 * @data:		Ethtool test results, or %NULL
 201 * @test:		Pointer to test result (used only if data != %NULL)
 202 * @unit_format:	Unit name format (e.g. "chan\%d")
 203 * @unit_id:		Unit id (e.g. 0 for "chan0")
 204 * @test_format:	Test name format (e.g. "loopback.\%s.tx.sent")
 205 * @test_id:		Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
 206 *
 207 * Fill in an individual self-test entry.
 208 */
 209static void ef4_fill_test(unsigned int test_index, u8 *strings, u64 *data,
 210			  int *test, const char *unit_format, int unit_id,
 211			  const char *test_format, const char *test_id)
 212{
 213	char unit_str[ETH_GSTRING_LEN], test_str[ETH_GSTRING_LEN];
 214
 215	/* Fill data value, if applicable */
 216	if (data)
 217		data[test_index] = *test;
 218
 219	/* Fill string, if applicable */
 220	if (strings) {
 221		if (strchr(unit_format, '%'))
 222			snprintf(unit_str, sizeof(unit_str),
 223				 unit_format, unit_id);
 224		else
 225			strcpy(unit_str, unit_format);
 226		snprintf(test_str, sizeof(test_str), test_format, test_id);
 227		snprintf(strings + test_index * ETH_GSTRING_LEN,
 228			 ETH_GSTRING_LEN,
 229			 "%-6s %-24s", unit_str, test_str);
 230	}
 231}
 232
 233#define EF4_CHANNEL_NAME(_channel) "chan%d", _channel->channel
 234#define EF4_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
 235#define EF4_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
 236#define EF4_LOOPBACK_NAME(_mode, _counter)			\
 237	"loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, ef4_loopback_mode)
 238
 239/**
 240 * ef4_fill_loopback_test - fill in a block of loopback self-test entries
 241 * @efx:		Efx NIC
 242 * @lb_tests:		Efx loopback self-test results structure
 243 * @mode:		Loopback test mode
 244 * @test_index:		Starting index of the test
 245 * @strings:		Ethtool strings, or %NULL
 246 * @data:		Ethtool test results, or %NULL
 247 *
 248 * Fill in a block of loopback self-test entries.  Return new test
 249 * index.
 250 */
 251static int ef4_fill_loopback_test(struct ef4_nic *efx,
 252				  struct ef4_loopback_self_tests *lb_tests,
 253				  enum ef4_loopback_mode mode,
 254				  unsigned int test_index,
 255				  u8 *strings, u64 *data)
 256{
 257	struct ef4_channel *channel =
 258		ef4_get_channel(efx, efx->tx_channel_offset);
 259	struct ef4_tx_queue *tx_queue;
 260
 261	ef4_for_each_channel_tx_queue(tx_queue, channel) {
 262		ef4_fill_test(test_index++, strings, data,
 263			      &lb_tests->tx_sent[tx_queue->queue],
 264			      EF4_TX_QUEUE_NAME(tx_queue),
 265			      EF4_LOOPBACK_NAME(mode, "tx_sent"));
 266		ef4_fill_test(test_index++, strings, data,
 267			      &lb_tests->tx_done[tx_queue->queue],
 268			      EF4_TX_QUEUE_NAME(tx_queue),
 269			      EF4_LOOPBACK_NAME(mode, "tx_done"));
 270	}
 271	ef4_fill_test(test_index++, strings, data,
 272		      &lb_tests->rx_good,
 273		      "rx", 0,
 274		      EF4_LOOPBACK_NAME(mode, "rx_good"));
 275	ef4_fill_test(test_index++, strings, data,
 276		      &lb_tests->rx_bad,
 277		      "rx", 0,
 278		      EF4_LOOPBACK_NAME(mode, "rx_bad"));
 279
 280	return test_index;
 281}
 282
 283/**
 284 * ef4_ethtool_fill_self_tests - get self-test details
 285 * @efx:		Efx NIC
 286 * @tests:		Efx self-test results structure, or %NULL
 287 * @strings:		Ethtool strings, or %NULL
 288 * @data:		Ethtool test results, or %NULL
 289 *
 290 * Get self-test number of strings, strings, and/or test results.
 291 * Return number of strings (== number of test results).
 292 *
 293 * The reason for merging these three functions is to make sure that
 294 * they can never be inconsistent.
 295 */
 296static int ef4_ethtool_fill_self_tests(struct ef4_nic *efx,
 297				       struct ef4_self_tests *tests,
 298				       u8 *strings, u64 *data)
 299{
 300	struct ef4_channel *channel;
 301	unsigned int n = 0, i;
 302	enum ef4_loopback_mode mode;
 303
 304	ef4_fill_test(n++, strings, data, &tests->phy_alive,
 305		      "phy", 0, "alive", NULL);
 306	ef4_fill_test(n++, strings, data, &tests->nvram,
 307		      "core", 0, "nvram", NULL);
 308	ef4_fill_test(n++, strings, data, &tests->interrupt,
 309		      "core", 0, "interrupt", NULL);
 310
 311	/* Event queues */
 312	ef4_for_each_channel(channel, efx) {
 313		ef4_fill_test(n++, strings, data,
 314			      &tests->eventq_dma[channel->channel],
 315			      EF4_CHANNEL_NAME(channel),
 316			      "eventq.dma", NULL);
 317		ef4_fill_test(n++, strings, data,
 318			      &tests->eventq_int[channel->channel],
 319			      EF4_CHANNEL_NAME(channel),
 320			      "eventq.int", NULL);
 321	}
 322
 323	ef4_fill_test(n++, strings, data, &tests->memory,
 324		      "core", 0, "memory", NULL);
 325	ef4_fill_test(n++, strings, data, &tests->registers,
 326		      "core", 0, "registers", NULL);
 327
 328	if (efx->phy_op->run_tests != NULL) {
 329		EF4_BUG_ON_PARANOID(efx->phy_op->test_name == NULL);
 330
 331		for (i = 0; true; ++i) {
 332			const char *name;
 333
 334			EF4_BUG_ON_PARANOID(i >= EF4_MAX_PHY_TESTS);
 335			name = efx->phy_op->test_name(efx, i);
 336			if (name == NULL)
 337				break;
 338
 339			ef4_fill_test(n++, strings, data, &tests->phy_ext[i],
 340				      "phy", 0, name, NULL);
 341		}
 342	}
 343
 344	/* Loopback tests */
 345	for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
 346		if (!(efx->loopback_modes & (1 << mode)))
 347			continue;
 348		n = ef4_fill_loopback_test(efx,
 349					   &tests->loopback[mode], mode, n,
 350					   strings, data);
 351	}
 352
 353	return n;
 354}
 355
 356static size_t ef4_describe_per_queue_stats(struct ef4_nic *efx, u8 *strings)
 357{
 358	size_t n_stats = 0;
 359	struct ef4_channel *channel;
 360
 361	ef4_for_each_channel(channel, efx) {
 362		if (ef4_channel_has_tx_queues(channel)) {
 363			n_stats++;
 364			if (strings != NULL) {
 365				snprintf(strings, ETH_GSTRING_LEN,
 366					 "tx-%u.tx_packets",
 367					 channel->tx_queue[0].queue /
 368					 EF4_TXQ_TYPES);
 369
 370				strings += ETH_GSTRING_LEN;
 371			}
 372		}
 373	}
 374	ef4_for_each_channel(channel, efx) {
 375		if (ef4_channel_has_rx_queue(channel)) {
 376			n_stats++;
 377			if (strings != NULL) {
 378				snprintf(strings, ETH_GSTRING_LEN,
 379					 "rx-%d.rx_packets", channel->channel);
 380				strings += ETH_GSTRING_LEN;
 381			}
 382		}
 383	}
 384	return n_stats;
 385}
 386
 387static int ef4_ethtool_get_sset_count(struct net_device *net_dev,
 388				      int string_set)
 389{
 390	struct ef4_nic *efx = netdev_priv(net_dev);
 391
 392	switch (string_set) {
 393	case ETH_SS_STATS:
 394		return efx->type->describe_stats(efx, NULL) +
 395		       EF4_ETHTOOL_SW_STAT_COUNT +
 396		       ef4_describe_per_queue_stats(efx, NULL);
 397	case ETH_SS_TEST:
 398		return ef4_ethtool_fill_self_tests(efx, NULL, NULL, NULL);
 399	default:
 400		return -EINVAL;
 401	}
 402}
 403
 404static void ef4_ethtool_get_strings(struct net_device *net_dev,
 405				    u32 string_set, u8 *strings)
 406{
 407	struct ef4_nic *efx = netdev_priv(net_dev);
 408	int i;
 409
 410	switch (string_set) {
 411	case ETH_SS_STATS:
 412		strings += (efx->type->describe_stats(efx, strings) *
 413			    ETH_GSTRING_LEN);
 414		for (i = 0; i < EF4_ETHTOOL_SW_STAT_COUNT; i++)
 415			strlcpy(strings + i * ETH_GSTRING_LEN,
 416				ef4_sw_stat_desc[i].name, ETH_GSTRING_LEN);
 417		strings += EF4_ETHTOOL_SW_STAT_COUNT * ETH_GSTRING_LEN;
 418		strings += (ef4_describe_per_queue_stats(efx, strings) *
 419			    ETH_GSTRING_LEN);
 420		break;
 421	case ETH_SS_TEST:
 422		ef4_ethtool_fill_self_tests(efx, NULL, strings, NULL);
 423		break;
 424	default:
 425		/* No other string sets */
 426		break;
 427	}
 428}
 429
 430static void ef4_ethtool_get_stats(struct net_device *net_dev,
 431				  struct ethtool_stats *stats,
 432				  u64 *data)
 433{
 434	struct ef4_nic *efx = netdev_priv(net_dev);
 435	const struct ef4_sw_stat_desc *stat;
 436	struct ef4_channel *channel;
 437	struct ef4_tx_queue *tx_queue;
 438	struct ef4_rx_queue *rx_queue;
 439	int i;
 440
 441	spin_lock_bh(&efx->stats_lock);
 442
 443	/* Get NIC statistics */
 444	data += efx->type->update_stats(efx, data, NULL);
 445
 446	/* Get software statistics */
 447	for (i = 0; i < EF4_ETHTOOL_SW_STAT_COUNT; i++) {
 448		stat = &ef4_sw_stat_desc[i];
 449		switch (stat->source) {
 450		case EF4_ETHTOOL_STAT_SOURCE_nic:
 451			data[i] = stat->get_stat((void *)efx + stat->offset);
 452			break;
 453		case EF4_ETHTOOL_STAT_SOURCE_channel:
 454			data[i] = 0;
 455			ef4_for_each_channel(channel, efx)
 456				data[i] += stat->get_stat((void *)channel +
 457							  stat->offset);
 458			break;
 459		case EF4_ETHTOOL_STAT_SOURCE_tx_queue:
 460			data[i] = 0;
 461			ef4_for_each_channel(channel, efx) {
 462				ef4_for_each_channel_tx_queue(tx_queue, channel)
 463					data[i] +=
 464						stat->get_stat((void *)tx_queue
 465							       + stat->offset);
 466			}
 467			break;
 468		}
 469	}
 470	data += EF4_ETHTOOL_SW_STAT_COUNT;
 471
 472	spin_unlock_bh(&efx->stats_lock);
 473
 474	ef4_for_each_channel(channel, efx) {
 475		if (ef4_channel_has_tx_queues(channel)) {
 476			*data = 0;
 477			ef4_for_each_channel_tx_queue(tx_queue, channel) {
 478				*data += tx_queue->tx_packets;
 479			}
 480			data++;
 481		}
 482	}
 483	ef4_for_each_channel(channel, efx) {
 484		if (ef4_channel_has_rx_queue(channel)) {
 485			*data = 0;
 486			ef4_for_each_channel_rx_queue(rx_queue, channel) {
 487				*data += rx_queue->rx_packets;
 488			}
 489			data++;
 490		}
 491	}
 492}
 493
 494static void ef4_ethtool_self_test(struct net_device *net_dev,
 495				  struct ethtool_test *test, u64 *data)
 496{
 497	struct ef4_nic *efx = netdev_priv(net_dev);
 498	struct ef4_self_tests *ef4_tests;
 499	bool already_up;
 500	int rc = -ENOMEM;
 501
 502	ef4_tests = kzalloc(sizeof(*ef4_tests), GFP_KERNEL);
 503	if (!ef4_tests)
 504		goto fail;
 505
 506	if (efx->state != STATE_READY) {
 507		rc = -EBUSY;
 508		goto out;
 509	}
 510
 511	netif_info(efx, drv, efx->net_dev, "starting %sline testing\n",
 512		   (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
 513
 514	/* We need rx buffers and interrupts. */
 515	already_up = (efx->net_dev->flags & IFF_UP);
 516	if (!already_up) {
 517		rc = dev_open(efx->net_dev, NULL);
 518		if (rc) {
 519			netif_err(efx, drv, efx->net_dev,
 520				  "failed opening device.\n");
 521			goto out;
 522		}
 523	}
 524
 525	rc = ef4_selftest(efx, ef4_tests, test->flags);
 526
 527	if (!already_up)
 528		dev_close(efx->net_dev);
 529
 530	netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n",
 531		   rc == 0 ? "passed" : "failed",
 532		   (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
 533
 534out:
 535	ef4_ethtool_fill_self_tests(efx, ef4_tests, NULL, data);
 536	kfree(ef4_tests);
 537fail:
 538	if (rc)
 539		test->flags |= ETH_TEST_FL_FAILED;
 540}
 541
 542/* Restart autonegotiation */
 543static int ef4_ethtool_nway_reset(struct net_device *net_dev)
 544{
 545	struct ef4_nic *efx = netdev_priv(net_dev);
 546
 547	return mdio45_nway_restart(&efx->mdio);
 548}
 549
 550/*
 551 * Each channel has a single IRQ and moderation timer, started by any
 552 * completion (or other event).  Unless the module parameter
 553 * separate_tx_channels is set, IRQs and moderation are therefore
 554 * shared between RX and TX completions.  In this case, when RX IRQ
 555 * moderation is explicitly changed then TX IRQ moderation is
 556 * automatically changed too, but otherwise we fail if the two values
 557 * are requested to be different.
 558 *
 559 * The hardware does not support a limit on the number of completions
 560 * before an IRQ, so we do not use the max_frames fields.  We should
 561 * report and require that max_frames == (usecs != 0), but this would
 562 * invalidate existing user documentation.
 563 *
 564 * The hardware does not have distinct settings for interrupt
 565 * moderation while the previous IRQ is being handled, so we should
 566 * not use the 'irq' fields.  However, an earlier developer
 567 * misunderstood the meaning of the 'irq' fields and the driver did
 568 * not support the standard fields.  To avoid invalidating existing
 569 * user documentation, we report and accept changes through either the
 570 * standard or 'irq' fields.  If both are changed at the same time, we
 571 * prefer the standard field.
 572 *
 573 * We implement adaptive IRQ moderation, but use a different algorithm
 574 * from that assumed in the definition of struct ethtool_coalesce.
 575 * Therefore we do not use any of the adaptive moderation parameters
 576 * in it.
 577 */
 578
 579static int ef4_ethtool_get_coalesce(struct net_device *net_dev,
 580				    struct ethtool_coalesce *coalesce)
 581{
 582	struct ef4_nic *efx = netdev_priv(net_dev);
 583	unsigned int tx_usecs, rx_usecs;
 584	bool rx_adaptive;
 585
 586	ef4_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &rx_adaptive);
 587
 588	coalesce->tx_coalesce_usecs = tx_usecs;
 589	coalesce->tx_coalesce_usecs_irq = tx_usecs;
 590	coalesce->rx_coalesce_usecs = rx_usecs;
 591	coalesce->rx_coalesce_usecs_irq = rx_usecs;
 592	coalesce->use_adaptive_rx_coalesce = rx_adaptive;
 593
 594	return 0;
 595}
 596
 597static int ef4_ethtool_set_coalesce(struct net_device *net_dev,
 598				    struct ethtool_coalesce *coalesce)
 599{
 600	struct ef4_nic *efx = netdev_priv(net_dev);
 601	struct ef4_channel *channel;
 602	unsigned int tx_usecs, rx_usecs;
 603	bool adaptive, rx_may_override_tx;
 604	int rc;
 605
 
 
 
 606	ef4_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &adaptive);
 607
 608	if (coalesce->rx_coalesce_usecs != rx_usecs)
 609		rx_usecs = coalesce->rx_coalesce_usecs;
 610	else
 611		rx_usecs = coalesce->rx_coalesce_usecs_irq;
 612
 613	adaptive = coalesce->use_adaptive_rx_coalesce;
 614
 615	/* If channels are shared, TX IRQ moderation can be quietly
 616	 * overridden unless it is changed from its old value.
 617	 */
 618	rx_may_override_tx = (coalesce->tx_coalesce_usecs == tx_usecs &&
 619			      coalesce->tx_coalesce_usecs_irq == tx_usecs);
 620	if (coalesce->tx_coalesce_usecs != tx_usecs)
 621		tx_usecs = coalesce->tx_coalesce_usecs;
 622	else
 623		tx_usecs = coalesce->tx_coalesce_usecs_irq;
 624
 625	rc = ef4_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive,
 626				     rx_may_override_tx);
 627	if (rc != 0)
 628		return rc;
 629
 630	ef4_for_each_channel(channel, efx)
 631		efx->type->push_irq_moderation(channel);
 632
 633	return 0;
 634}
 635
 636static void ef4_ethtool_get_ringparam(struct net_device *net_dev,
 637				      struct ethtool_ringparam *ring)
 638{
 639	struct ef4_nic *efx = netdev_priv(net_dev);
 640
 641	ring->rx_max_pending = EF4_MAX_DMAQ_SIZE;
 642	ring->tx_max_pending = EF4_MAX_DMAQ_SIZE;
 643	ring->rx_pending = efx->rxq_entries;
 644	ring->tx_pending = efx->txq_entries;
 645}
 646
 647static int ef4_ethtool_set_ringparam(struct net_device *net_dev,
 648				     struct ethtool_ringparam *ring)
 649{
 650	struct ef4_nic *efx = netdev_priv(net_dev);
 651	u32 txq_entries;
 652
 653	if (ring->rx_mini_pending || ring->rx_jumbo_pending ||
 654	    ring->rx_pending > EF4_MAX_DMAQ_SIZE ||
 655	    ring->tx_pending > EF4_MAX_DMAQ_SIZE)
 656		return -EINVAL;
 657
 658	if (ring->rx_pending < EF4_RXQ_MIN_ENT) {
 659		netif_err(efx, drv, efx->net_dev,
 660			  "RX queues cannot be smaller than %u\n",
 661			  EF4_RXQ_MIN_ENT);
 662		return -EINVAL;
 663	}
 664
 665	txq_entries = max(ring->tx_pending, EF4_TXQ_MIN_ENT(efx));
 666	if (txq_entries != ring->tx_pending)
 667		netif_warn(efx, drv, efx->net_dev,
 668			   "increasing TX queue size to minimum of %u\n",
 669			   txq_entries);
 670
 671	return ef4_realloc_channels(efx, ring->rx_pending, txq_entries);
 672}
 673
 674static int ef4_ethtool_set_pauseparam(struct net_device *net_dev,
 675				      struct ethtool_pauseparam *pause)
 676{
 677	struct ef4_nic *efx = netdev_priv(net_dev);
 678	u8 wanted_fc, old_fc;
 679	u32 old_adv;
 680	int rc = 0;
 681
 682	mutex_lock(&efx->mac_lock);
 683
 684	wanted_fc = ((pause->rx_pause ? EF4_FC_RX : 0) |
 685		     (pause->tx_pause ? EF4_FC_TX : 0) |
 686		     (pause->autoneg ? EF4_FC_AUTO : 0));
 687
 688	if ((wanted_fc & EF4_FC_TX) && !(wanted_fc & EF4_FC_RX)) {
 689		netif_dbg(efx, drv, efx->net_dev,
 690			  "Flow control unsupported: tx ON rx OFF\n");
 691		rc = -EINVAL;
 692		goto out;
 693	}
 694
 695	if ((wanted_fc & EF4_FC_AUTO) && !efx->link_advertising) {
 696		netif_dbg(efx, drv, efx->net_dev,
 697			  "Autonegotiation is disabled\n");
 698		rc = -EINVAL;
 699		goto out;
 700	}
 701
 702	/* Hook for Falcon bug 11482 workaround */
 703	if (efx->type->prepare_enable_fc_tx &&
 704	    (wanted_fc & EF4_FC_TX) && !(efx->wanted_fc & EF4_FC_TX))
 705		efx->type->prepare_enable_fc_tx(efx);
 706
 707	old_adv = efx->link_advertising;
 708	old_fc = efx->wanted_fc;
 709	ef4_link_set_wanted_fc(efx, wanted_fc);
 710	if (efx->link_advertising != old_adv ||
 711	    (efx->wanted_fc ^ old_fc) & EF4_FC_AUTO) {
 712		rc = efx->phy_op->reconfigure(efx);
 713		if (rc) {
 714			netif_err(efx, drv, efx->net_dev,
 715				  "Unable to advertise requested flow "
 716				  "control setting\n");
 717			goto out;
 718		}
 719	}
 720
 721	/* Reconfigure the MAC. The PHY *may* generate a link state change event
 722	 * if the user just changed the advertised capabilities, but there's no
 723	 * harm doing this twice */
 724	ef4_mac_reconfigure(efx);
 725
 726out:
 727	mutex_unlock(&efx->mac_lock);
 728
 729	return rc;
 730}
 731
 732static void ef4_ethtool_get_pauseparam(struct net_device *net_dev,
 733				       struct ethtool_pauseparam *pause)
 734{
 735	struct ef4_nic *efx = netdev_priv(net_dev);
 736
 737	pause->rx_pause = !!(efx->wanted_fc & EF4_FC_RX);
 738	pause->tx_pause = !!(efx->wanted_fc & EF4_FC_TX);
 739	pause->autoneg = !!(efx->wanted_fc & EF4_FC_AUTO);
 740}
 741
 742static void ef4_ethtool_get_wol(struct net_device *net_dev,
 743				struct ethtool_wolinfo *wol)
 744{
 745	struct ef4_nic *efx = netdev_priv(net_dev);
 746	return efx->type->get_wol(efx, wol);
 747}
 748
 749
 750static int ef4_ethtool_set_wol(struct net_device *net_dev,
 751			       struct ethtool_wolinfo *wol)
 752{
 753	struct ef4_nic *efx = netdev_priv(net_dev);
 754	return efx->type->set_wol(efx, wol->wolopts);
 755}
 756
 757static int ef4_ethtool_reset(struct net_device *net_dev, u32 *flags)
 758{
 759	struct ef4_nic *efx = netdev_priv(net_dev);
 760	int rc;
 761
 762	rc = efx->type->map_reset_flags(flags);
 763	if (rc < 0)
 764		return rc;
 765
 766	return ef4_reset(efx, rc);
 767}
 768
 769/* MAC address mask including only I/G bit */
 770static const u8 mac_addr_ig_mask[ETH_ALEN] __aligned(2) = {0x01, 0, 0, 0, 0, 0};
 771
 772#define IP4_ADDR_FULL_MASK	((__force __be32)~0)
 773#define IP_PROTO_FULL_MASK	0xFF
 774#define PORT_FULL_MASK		((__force __be16)~0)
 775#define ETHER_TYPE_FULL_MASK	((__force __be16)~0)
 776
 777static inline void ip6_fill_mask(__be32 *mask)
 778{
 779	mask[0] = mask[1] = mask[2] = mask[3] = ~(__be32)0;
 780}
 781
 782static int ef4_ethtool_get_class_rule(struct ef4_nic *efx,
 783				      struct ethtool_rx_flow_spec *rule)
 784{
 785	struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
 786	struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
 787	struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
 788	struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
 789	struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
 790	struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
 791	struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
 792	struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
 793	struct ethhdr *mac_entry = &rule->h_u.ether_spec;
 794	struct ethhdr *mac_mask = &rule->m_u.ether_spec;
 795	struct ef4_filter_spec spec;
 796	int rc;
 797
 798	rc = ef4_filter_get_filter_safe(efx, EF4_FILTER_PRI_MANUAL,
 799					rule->location, &spec);
 800	if (rc)
 801		return rc;
 802
 803	if (spec.dmaq_id == EF4_FILTER_RX_DMAQ_ID_DROP)
 804		rule->ring_cookie = RX_CLS_FLOW_DISC;
 805	else
 806		rule->ring_cookie = spec.dmaq_id;
 807
 808	if ((spec.match_flags & EF4_FILTER_MATCH_ETHER_TYPE) &&
 809	    spec.ether_type == htons(ETH_P_IP) &&
 810	    (spec.match_flags & EF4_FILTER_MATCH_IP_PROTO) &&
 811	    (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
 812	    !(spec.match_flags &
 813	      ~(EF4_FILTER_MATCH_ETHER_TYPE | EF4_FILTER_MATCH_OUTER_VID |
 814		EF4_FILTER_MATCH_LOC_HOST | EF4_FILTER_MATCH_REM_HOST |
 815		EF4_FILTER_MATCH_IP_PROTO |
 816		EF4_FILTER_MATCH_LOC_PORT | EF4_FILTER_MATCH_REM_PORT))) {
 817		rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
 818				   TCP_V4_FLOW : UDP_V4_FLOW);
 819		if (spec.match_flags & EF4_FILTER_MATCH_LOC_HOST) {
 820			ip_entry->ip4dst = spec.loc_host[0];
 821			ip_mask->ip4dst = IP4_ADDR_FULL_MASK;
 822		}
 823		if (spec.match_flags & EF4_FILTER_MATCH_REM_HOST) {
 824			ip_entry->ip4src = spec.rem_host[0];
 825			ip_mask->ip4src = IP4_ADDR_FULL_MASK;
 826		}
 827		if (spec.match_flags & EF4_FILTER_MATCH_LOC_PORT) {
 828			ip_entry->pdst = spec.loc_port;
 829			ip_mask->pdst = PORT_FULL_MASK;
 830		}
 831		if (spec.match_flags & EF4_FILTER_MATCH_REM_PORT) {
 832			ip_entry->psrc = spec.rem_port;
 833			ip_mask->psrc = PORT_FULL_MASK;
 834		}
 835	} else if ((spec.match_flags & EF4_FILTER_MATCH_ETHER_TYPE) &&
 836	    spec.ether_type == htons(ETH_P_IPV6) &&
 837	    (spec.match_flags & EF4_FILTER_MATCH_IP_PROTO) &&
 838	    (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
 839	    !(spec.match_flags &
 840	      ~(EF4_FILTER_MATCH_ETHER_TYPE | EF4_FILTER_MATCH_OUTER_VID |
 841		EF4_FILTER_MATCH_LOC_HOST | EF4_FILTER_MATCH_REM_HOST |
 842		EF4_FILTER_MATCH_IP_PROTO |
 843		EF4_FILTER_MATCH_LOC_PORT | EF4_FILTER_MATCH_REM_PORT))) {
 844		rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
 845				   TCP_V6_FLOW : UDP_V6_FLOW);
 846		if (spec.match_flags & EF4_FILTER_MATCH_LOC_HOST) {
 847			memcpy(ip6_entry->ip6dst, spec.loc_host,
 848			       sizeof(ip6_entry->ip6dst));
 849			ip6_fill_mask(ip6_mask->ip6dst);
 850		}
 851		if (spec.match_flags & EF4_FILTER_MATCH_REM_HOST) {
 852			memcpy(ip6_entry->ip6src, spec.rem_host,
 853			       sizeof(ip6_entry->ip6src));
 854			ip6_fill_mask(ip6_mask->ip6src);
 855		}
 856		if (spec.match_flags & EF4_FILTER_MATCH_LOC_PORT) {
 857			ip6_entry->pdst = spec.loc_port;
 858			ip6_mask->pdst = PORT_FULL_MASK;
 859		}
 860		if (spec.match_flags & EF4_FILTER_MATCH_REM_PORT) {
 861			ip6_entry->psrc = spec.rem_port;
 862			ip6_mask->psrc = PORT_FULL_MASK;
 863		}
 864	} else if (!(spec.match_flags &
 865		     ~(EF4_FILTER_MATCH_LOC_MAC | EF4_FILTER_MATCH_LOC_MAC_IG |
 866		       EF4_FILTER_MATCH_REM_MAC | EF4_FILTER_MATCH_ETHER_TYPE |
 867		       EF4_FILTER_MATCH_OUTER_VID))) {
 868		rule->flow_type = ETHER_FLOW;
 869		if (spec.match_flags &
 870		    (EF4_FILTER_MATCH_LOC_MAC | EF4_FILTER_MATCH_LOC_MAC_IG)) {
 871			ether_addr_copy(mac_entry->h_dest, spec.loc_mac);
 872			if (spec.match_flags & EF4_FILTER_MATCH_LOC_MAC)
 873				eth_broadcast_addr(mac_mask->h_dest);
 874			else
 875				ether_addr_copy(mac_mask->h_dest,
 876						mac_addr_ig_mask);
 877		}
 878		if (spec.match_flags & EF4_FILTER_MATCH_REM_MAC) {
 879			ether_addr_copy(mac_entry->h_source, spec.rem_mac);
 880			eth_broadcast_addr(mac_mask->h_source);
 881		}
 882		if (spec.match_flags & EF4_FILTER_MATCH_ETHER_TYPE) {
 883			mac_entry->h_proto = spec.ether_type;
 884			mac_mask->h_proto = ETHER_TYPE_FULL_MASK;
 885		}
 886	} else if (spec.match_flags & EF4_FILTER_MATCH_ETHER_TYPE &&
 887		   spec.ether_type == htons(ETH_P_IP) &&
 888		   !(spec.match_flags &
 889		     ~(EF4_FILTER_MATCH_ETHER_TYPE | EF4_FILTER_MATCH_OUTER_VID |
 890		       EF4_FILTER_MATCH_LOC_HOST | EF4_FILTER_MATCH_REM_HOST |
 891		       EF4_FILTER_MATCH_IP_PROTO))) {
 892		rule->flow_type = IPV4_USER_FLOW;
 893		uip_entry->ip_ver = ETH_RX_NFC_IP4;
 894		if (spec.match_flags & EF4_FILTER_MATCH_IP_PROTO) {
 895			uip_mask->proto = IP_PROTO_FULL_MASK;
 896			uip_entry->proto = spec.ip_proto;
 897		}
 898		if (spec.match_flags & EF4_FILTER_MATCH_LOC_HOST) {
 899			uip_entry->ip4dst = spec.loc_host[0];
 900			uip_mask->ip4dst = IP4_ADDR_FULL_MASK;
 901		}
 902		if (spec.match_flags & EF4_FILTER_MATCH_REM_HOST) {
 903			uip_entry->ip4src = spec.rem_host[0];
 904			uip_mask->ip4src = IP4_ADDR_FULL_MASK;
 905		}
 906	} else if (spec.match_flags & EF4_FILTER_MATCH_ETHER_TYPE &&
 907		   spec.ether_type == htons(ETH_P_IPV6) &&
 908		   !(spec.match_flags &
 909		     ~(EF4_FILTER_MATCH_ETHER_TYPE | EF4_FILTER_MATCH_OUTER_VID |
 910		       EF4_FILTER_MATCH_LOC_HOST | EF4_FILTER_MATCH_REM_HOST |
 911		       EF4_FILTER_MATCH_IP_PROTO))) {
 912		rule->flow_type = IPV6_USER_FLOW;
 913		if (spec.match_flags & EF4_FILTER_MATCH_IP_PROTO) {
 914			uip6_mask->l4_proto = IP_PROTO_FULL_MASK;
 915			uip6_entry->l4_proto = spec.ip_proto;
 916		}
 917		if (spec.match_flags & EF4_FILTER_MATCH_LOC_HOST) {
 918			memcpy(uip6_entry->ip6dst, spec.loc_host,
 919			       sizeof(uip6_entry->ip6dst));
 920			ip6_fill_mask(uip6_mask->ip6dst);
 921		}
 922		if (spec.match_flags & EF4_FILTER_MATCH_REM_HOST) {
 923			memcpy(uip6_entry->ip6src, spec.rem_host,
 924			       sizeof(uip6_entry->ip6src));
 925			ip6_fill_mask(uip6_mask->ip6src);
 926		}
 927	} else {
 928		/* The above should handle all filters that we insert */
 929		WARN_ON(1);
 930		return -EINVAL;
 931	}
 932
 933	if (spec.match_flags & EF4_FILTER_MATCH_OUTER_VID) {
 934		rule->flow_type |= FLOW_EXT;
 935		rule->h_ext.vlan_tci = spec.outer_vid;
 936		rule->m_ext.vlan_tci = htons(0xfff);
 937	}
 938
 939	return rc;
 940}
 941
 942static int
 943ef4_ethtool_get_rxnfc(struct net_device *net_dev,
 944		      struct ethtool_rxnfc *info, u32 *rule_locs)
 945{
 946	struct ef4_nic *efx = netdev_priv(net_dev);
 947
 948	switch (info->cmd) {
 949	case ETHTOOL_GRXRINGS:
 950		info->data = efx->n_rx_channels;
 951		return 0;
 952
 953	case ETHTOOL_GRXFH: {
 954		unsigned min_revision = 0;
 955
 956		info->data = 0;
 957		switch (info->flow_type) {
 958		case TCP_V4_FLOW:
 959			info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
 960			fallthrough;
 961		case UDP_V4_FLOW:
 962		case SCTP_V4_FLOW:
 963		case AH_ESP_V4_FLOW:
 964		case IPV4_FLOW:
 965			info->data |= RXH_IP_SRC | RXH_IP_DST;
 966			min_revision = EF4_REV_FALCON_B0;
 967			break;
 968		default:
 969			break;
 970		}
 971		if (ef4_nic_rev(efx) < min_revision)
 972			info->data = 0;
 973		return 0;
 974	}
 975
 976	case ETHTOOL_GRXCLSRLCNT:
 977		info->data = ef4_filter_get_rx_id_limit(efx);
 978		if (info->data == 0)
 979			return -EOPNOTSUPP;
 980		info->data |= RX_CLS_LOC_SPECIAL;
 981		info->rule_cnt =
 982			ef4_filter_count_rx_used(efx, EF4_FILTER_PRI_MANUAL);
 983		return 0;
 984
 985	case ETHTOOL_GRXCLSRULE:
 986		if (ef4_filter_get_rx_id_limit(efx) == 0)
 987			return -EOPNOTSUPP;
 988		return ef4_ethtool_get_class_rule(efx, &info->fs);
 989
 990	case ETHTOOL_GRXCLSRLALL: {
 991		s32 rc;
 992		info->data = ef4_filter_get_rx_id_limit(efx);
 993		if (info->data == 0)
 994			return -EOPNOTSUPP;
 995		rc = ef4_filter_get_rx_ids(efx, EF4_FILTER_PRI_MANUAL,
 996					   rule_locs, info->rule_cnt);
 997		if (rc < 0)
 998			return rc;
 999		info->rule_cnt = rc;
1000		return 0;
1001	}
1002
1003	default:
1004		return -EOPNOTSUPP;
1005	}
1006}
1007
1008static inline bool ip6_mask_is_full(__be32 mask[4])
1009{
1010	return !~(mask[0] & mask[1] & mask[2] & mask[3]);
1011}
1012
1013static inline bool ip6_mask_is_empty(__be32 mask[4])
1014{
1015	return !(mask[0] | mask[1] | mask[2] | mask[3]);
1016}
1017
1018static int ef4_ethtool_set_class_rule(struct ef4_nic *efx,
1019				      struct ethtool_rx_flow_spec *rule)
1020{
1021	struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
1022	struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
1023	struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
1024	struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
1025	struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
1026	struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
1027	struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
1028	struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
1029	struct ethhdr *mac_entry = &rule->h_u.ether_spec;
1030	struct ethhdr *mac_mask = &rule->m_u.ether_spec;
1031	struct ef4_filter_spec spec;
1032	int rc;
1033
1034	/* Check that user wants us to choose the location */
1035	if (rule->location != RX_CLS_LOC_ANY)
1036		return -EINVAL;
1037
1038	/* Range-check ring_cookie */
1039	if (rule->ring_cookie >= efx->n_rx_channels &&
1040	    rule->ring_cookie != RX_CLS_FLOW_DISC)
1041		return -EINVAL;
1042
1043	/* Check for unsupported extensions */
1044	if ((rule->flow_type & FLOW_EXT) &&
1045	    (rule->m_ext.vlan_etype || rule->m_ext.data[0] ||
1046	     rule->m_ext.data[1]))
1047		return -EINVAL;
1048
1049	ef4_filter_init_rx(&spec, EF4_FILTER_PRI_MANUAL,
1050			   efx->rx_scatter ? EF4_FILTER_FLAG_RX_SCATTER : 0,
1051			   (rule->ring_cookie == RX_CLS_FLOW_DISC) ?
1052			   EF4_FILTER_RX_DMAQ_ID_DROP : rule->ring_cookie);
1053
1054	switch (rule->flow_type & ~FLOW_EXT) {
1055	case TCP_V4_FLOW:
1056	case UDP_V4_FLOW:
1057		spec.match_flags = (EF4_FILTER_MATCH_ETHER_TYPE |
1058				    EF4_FILTER_MATCH_IP_PROTO);
1059		spec.ether_type = htons(ETH_P_IP);
1060		spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V4_FLOW ?
1061				 IPPROTO_TCP : IPPROTO_UDP);
1062		if (ip_mask->ip4dst) {
1063			if (ip_mask->ip4dst != IP4_ADDR_FULL_MASK)
1064				return -EINVAL;
1065			spec.match_flags |= EF4_FILTER_MATCH_LOC_HOST;
1066			spec.loc_host[0] = ip_entry->ip4dst;
1067		}
1068		if (ip_mask->ip4src) {
1069			if (ip_mask->ip4src != IP4_ADDR_FULL_MASK)
1070				return -EINVAL;
1071			spec.match_flags |= EF4_FILTER_MATCH_REM_HOST;
1072			spec.rem_host[0] = ip_entry->ip4src;
1073		}
1074		if (ip_mask->pdst) {
1075			if (ip_mask->pdst != PORT_FULL_MASK)
1076				return -EINVAL;
1077			spec.match_flags |= EF4_FILTER_MATCH_LOC_PORT;
1078			spec.loc_port = ip_entry->pdst;
1079		}
1080		if (ip_mask->psrc) {
1081			if (ip_mask->psrc != PORT_FULL_MASK)
1082				return -EINVAL;
1083			spec.match_flags |= EF4_FILTER_MATCH_REM_PORT;
1084			spec.rem_port = ip_entry->psrc;
1085		}
1086		if (ip_mask->tos)
1087			return -EINVAL;
1088		break;
1089
1090	case TCP_V6_FLOW:
1091	case UDP_V6_FLOW:
1092		spec.match_flags = (EF4_FILTER_MATCH_ETHER_TYPE |
1093				    EF4_FILTER_MATCH_IP_PROTO);
1094		spec.ether_type = htons(ETH_P_IPV6);
1095		spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V6_FLOW ?
1096				 IPPROTO_TCP : IPPROTO_UDP);
1097		if (!ip6_mask_is_empty(ip6_mask->ip6dst)) {
1098			if (!ip6_mask_is_full(ip6_mask->ip6dst))
1099				return -EINVAL;
1100			spec.match_flags |= EF4_FILTER_MATCH_LOC_HOST;
1101			memcpy(spec.loc_host, ip6_entry->ip6dst, sizeof(spec.loc_host));
1102		}
1103		if (!ip6_mask_is_empty(ip6_mask->ip6src)) {
1104			if (!ip6_mask_is_full(ip6_mask->ip6src))
1105				return -EINVAL;
1106			spec.match_flags |= EF4_FILTER_MATCH_REM_HOST;
1107			memcpy(spec.rem_host, ip6_entry->ip6src, sizeof(spec.rem_host));
1108		}
1109		if (ip6_mask->pdst) {
1110			if (ip6_mask->pdst != PORT_FULL_MASK)
1111				return -EINVAL;
1112			spec.match_flags |= EF4_FILTER_MATCH_LOC_PORT;
1113			spec.loc_port = ip6_entry->pdst;
1114		}
1115		if (ip6_mask->psrc) {
1116			if (ip6_mask->psrc != PORT_FULL_MASK)
1117				return -EINVAL;
1118			spec.match_flags |= EF4_FILTER_MATCH_REM_PORT;
1119			spec.rem_port = ip6_entry->psrc;
1120		}
1121		if (ip6_mask->tclass)
1122			return -EINVAL;
1123		break;
1124
1125	case IPV4_USER_FLOW:
1126		if (uip_mask->l4_4_bytes || uip_mask->tos || uip_mask->ip_ver ||
1127		    uip_entry->ip_ver != ETH_RX_NFC_IP4)
1128			return -EINVAL;
1129		spec.match_flags = EF4_FILTER_MATCH_ETHER_TYPE;
1130		spec.ether_type = htons(ETH_P_IP);
1131		if (uip_mask->ip4dst) {
1132			if (uip_mask->ip4dst != IP4_ADDR_FULL_MASK)
1133				return -EINVAL;
1134			spec.match_flags |= EF4_FILTER_MATCH_LOC_HOST;
1135			spec.loc_host[0] = uip_entry->ip4dst;
1136		}
1137		if (uip_mask->ip4src) {
1138			if (uip_mask->ip4src != IP4_ADDR_FULL_MASK)
1139				return -EINVAL;
1140			spec.match_flags |= EF4_FILTER_MATCH_REM_HOST;
1141			spec.rem_host[0] = uip_entry->ip4src;
1142		}
1143		if (uip_mask->proto) {
1144			if (uip_mask->proto != IP_PROTO_FULL_MASK)
1145				return -EINVAL;
1146			spec.match_flags |= EF4_FILTER_MATCH_IP_PROTO;
1147			spec.ip_proto = uip_entry->proto;
1148		}
1149		break;
1150
1151	case IPV6_USER_FLOW:
1152		if (uip6_mask->l4_4_bytes || uip6_mask->tclass)
1153			return -EINVAL;
1154		spec.match_flags = EF4_FILTER_MATCH_ETHER_TYPE;
1155		spec.ether_type = htons(ETH_P_IPV6);
1156		if (!ip6_mask_is_empty(uip6_mask->ip6dst)) {
1157			if (!ip6_mask_is_full(uip6_mask->ip6dst))
1158				return -EINVAL;
1159			spec.match_flags |= EF4_FILTER_MATCH_LOC_HOST;
1160			memcpy(spec.loc_host, uip6_entry->ip6dst, sizeof(spec.loc_host));
1161		}
1162		if (!ip6_mask_is_empty(uip6_mask->ip6src)) {
1163			if (!ip6_mask_is_full(uip6_mask->ip6src))
1164				return -EINVAL;
1165			spec.match_flags |= EF4_FILTER_MATCH_REM_HOST;
1166			memcpy(spec.rem_host, uip6_entry->ip6src, sizeof(spec.rem_host));
1167		}
1168		if (uip6_mask->l4_proto) {
1169			if (uip6_mask->l4_proto != IP_PROTO_FULL_MASK)
1170				return -EINVAL;
1171			spec.match_flags |= EF4_FILTER_MATCH_IP_PROTO;
1172			spec.ip_proto = uip6_entry->l4_proto;
1173		}
1174		break;
1175
1176	case ETHER_FLOW:
1177		if (!is_zero_ether_addr(mac_mask->h_dest)) {
1178			if (ether_addr_equal(mac_mask->h_dest,
1179					     mac_addr_ig_mask))
1180				spec.match_flags |= EF4_FILTER_MATCH_LOC_MAC_IG;
1181			else if (is_broadcast_ether_addr(mac_mask->h_dest))
1182				spec.match_flags |= EF4_FILTER_MATCH_LOC_MAC;
1183			else
1184				return -EINVAL;
1185			ether_addr_copy(spec.loc_mac, mac_entry->h_dest);
1186		}
1187		if (!is_zero_ether_addr(mac_mask->h_source)) {
1188			if (!is_broadcast_ether_addr(mac_mask->h_source))
1189				return -EINVAL;
1190			spec.match_flags |= EF4_FILTER_MATCH_REM_MAC;
1191			ether_addr_copy(spec.rem_mac, mac_entry->h_source);
1192		}
1193		if (mac_mask->h_proto) {
1194			if (mac_mask->h_proto != ETHER_TYPE_FULL_MASK)
1195				return -EINVAL;
1196			spec.match_flags |= EF4_FILTER_MATCH_ETHER_TYPE;
1197			spec.ether_type = mac_entry->h_proto;
1198		}
1199		break;
1200
1201	default:
1202		return -EINVAL;
1203	}
1204
1205	if ((rule->flow_type & FLOW_EXT) && rule->m_ext.vlan_tci) {
1206		if (rule->m_ext.vlan_tci != htons(0xfff))
1207			return -EINVAL;
1208		spec.match_flags |= EF4_FILTER_MATCH_OUTER_VID;
1209		spec.outer_vid = rule->h_ext.vlan_tci;
1210	}
1211
1212	rc = ef4_filter_insert_filter(efx, &spec, true);
1213	if (rc < 0)
1214		return rc;
1215
1216	rule->location = rc;
1217	return 0;
1218}
1219
1220static int ef4_ethtool_set_rxnfc(struct net_device *net_dev,
1221				 struct ethtool_rxnfc *info)
1222{
1223	struct ef4_nic *efx = netdev_priv(net_dev);
1224
1225	if (ef4_filter_get_rx_id_limit(efx) == 0)
1226		return -EOPNOTSUPP;
1227
1228	switch (info->cmd) {
1229	case ETHTOOL_SRXCLSRLINS:
1230		return ef4_ethtool_set_class_rule(efx, &info->fs);
1231
1232	case ETHTOOL_SRXCLSRLDEL:
1233		return ef4_filter_remove_id_safe(efx, EF4_FILTER_PRI_MANUAL,
1234						 info->fs.location);
1235
1236	default:
1237		return -EOPNOTSUPP;
1238	}
1239}
1240
1241static u32 ef4_ethtool_get_rxfh_indir_size(struct net_device *net_dev)
1242{
1243	struct ef4_nic *efx = netdev_priv(net_dev);
1244
1245	return ((ef4_nic_rev(efx) < EF4_REV_FALCON_B0 ||
1246		 efx->n_rx_channels == 1) ?
1247		0 : ARRAY_SIZE(efx->rx_indir_table));
1248}
1249
1250static int ef4_ethtool_get_rxfh(struct net_device *net_dev, u32 *indir, u8 *key,
1251				u8 *hfunc)
1252{
1253	struct ef4_nic *efx = netdev_priv(net_dev);
1254
1255	if (hfunc)
1256		*hfunc = ETH_RSS_HASH_TOP;
1257	if (indir)
1258		memcpy(indir, efx->rx_indir_table, sizeof(efx->rx_indir_table));
1259	return 0;
1260}
1261
1262static int ef4_ethtool_set_rxfh(struct net_device *net_dev, const u32 *indir,
1263				const u8 *key, const u8 hfunc)
1264{
1265	struct ef4_nic *efx = netdev_priv(net_dev);
1266
1267	/* We do not allow change in unsupported parameters */
1268	if (key ||
1269	    (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
1270		return -EOPNOTSUPP;
1271	if (!indir)
1272		return 0;
1273
1274	return efx->type->rx_push_rss_config(efx, true, indir);
1275}
1276
1277static int ef4_ethtool_get_module_eeprom(struct net_device *net_dev,
1278					 struct ethtool_eeprom *ee,
1279					 u8 *data)
1280{
1281	struct ef4_nic *efx = netdev_priv(net_dev);
1282	int ret;
1283
1284	if (!efx->phy_op || !efx->phy_op->get_module_eeprom)
1285		return -EOPNOTSUPP;
1286
1287	mutex_lock(&efx->mac_lock);
1288	ret = efx->phy_op->get_module_eeprom(efx, ee, data);
1289	mutex_unlock(&efx->mac_lock);
1290
1291	return ret;
1292}
1293
1294static int ef4_ethtool_get_module_info(struct net_device *net_dev,
1295				       struct ethtool_modinfo *modinfo)
1296{
1297	struct ef4_nic *efx = netdev_priv(net_dev);
1298	int ret;
1299
1300	if (!efx->phy_op || !efx->phy_op->get_module_info)
1301		return -EOPNOTSUPP;
1302
1303	mutex_lock(&efx->mac_lock);
1304	ret = efx->phy_op->get_module_info(efx, modinfo);
1305	mutex_unlock(&efx->mac_lock);
1306
1307	return ret;
1308}
1309
1310const struct ethtool_ops ef4_ethtool_ops = {
1311	.supported_coalesce_params = ETHTOOL_COALESCE_USECS |
1312				     ETHTOOL_COALESCE_USECS_IRQ |
1313				     ETHTOOL_COALESCE_USE_ADAPTIVE_RX,
1314	.get_drvinfo		= ef4_ethtool_get_drvinfo,
1315	.get_regs_len		= ef4_ethtool_get_regs_len,
1316	.get_regs		= ef4_ethtool_get_regs,
1317	.get_msglevel		= ef4_ethtool_get_msglevel,
1318	.set_msglevel		= ef4_ethtool_set_msglevel,
1319	.nway_reset		= ef4_ethtool_nway_reset,
1320	.get_link		= ethtool_op_get_link,
1321	.get_coalesce		= ef4_ethtool_get_coalesce,
1322	.set_coalesce		= ef4_ethtool_set_coalesce,
1323	.get_ringparam		= ef4_ethtool_get_ringparam,
1324	.set_ringparam		= ef4_ethtool_set_ringparam,
1325	.get_pauseparam         = ef4_ethtool_get_pauseparam,
1326	.set_pauseparam         = ef4_ethtool_set_pauseparam,
1327	.get_sset_count		= ef4_ethtool_get_sset_count,
1328	.self_test		= ef4_ethtool_self_test,
1329	.get_strings		= ef4_ethtool_get_strings,
1330	.set_phys_id		= ef4_ethtool_phys_id,
1331	.get_ethtool_stats	= ef4_ethtool_get_stats,
1332	.get_wol                = ef4_ethtool_get_wol,
1333	.set_wol                = ef4_ethtool_set_wol,
1334	.reset			= ef4_ethtool_reset,
1335	.get_rxnfc		= ef4_ethtool_get_rxnfc,
1336	.set_rxnfc		= ef4_ethtool_set_rxnfc,
1337	.get_rxfh_indir_size	= ef4_ethtool_get_rxfh_indir_size,
1338	.get_rxfh		= ef4_ethtool_get_rxfh,
1339	.set_rxfh		= ef4_ethtool_set_rxfh,
1340	.get_module_info	= ef4_ethtool_get_module_info,
1341	.get_module_eeprom	= ef4_ethtool_get_module_eeprom,
1342	.get_link_ksettings	= ef4_ethtool_get_link_ksettings,
1343	.set_link_ksettings	= ef4_ethtool_set_link_ksettings,
1344};