Linux Audio

Check our new training course

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