ethtool.c 33.4 KB
Newer Older
1 2 3
/****************************************************************************
 * Driver for Solarflare Solarstorm network controllers and boards
 * Copyright 2005-2006 Fen Systems Ltd.
B
Ben Hutchings 已提交
4
 * Copyright 2006-2010 Solarflare Communications Inc.
5 6 7 8 9 10 11 12 13
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published
 * by the Free Software Foundation, incorporated herein by reference.
 */

#include <linux/netdevice.h>
#include <linux/ethtool.h>
#include <linux/rtnetlink.h>
14
#include <linux/in.h>
15
#include "net_driver.h"
B
Ben Hutchings 已提交
16
#include "workarounds.h"
17
#include "selftest.h"
18
#include "efx.h"
19
#include "filter.h"
B
Ben Hutchings 已提交
20
#include "nic.h"
21 22 23 24 25 26 27 28 29 30

struct ethtool_string {
	char name[ETH_GSTRING_LEN];
};

struct efx_ethtool_stat {
	const char *name;
	enum {
		EFX_ETHTOOL_STAT_SOURCE_mac_stats,
		EFX_ETHTOOL_STAT_SOURCE_nic,
31 32
		EFX_ETHTOOL_STAT_SOURCE_channel,
		EFX_ETHTOOL_STAT_SOURCE_tx_queue
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
	} source;
	unsigned offset;
	u64(*get_stat) (void *field); /* Reader function */
};

/* Initialiser for a struct #efx_ethtool_stat with type-checking */
#define EFX_ETHTOOL_STAT(stat_name, source_name, field, field_type, \
				get_stat_function) {			\
	.name = #stat_name,						\
	.source = EFX_ETHTOOL_STAT_SOURCE_##source_name,		\
	.offset = ((((field_type *) 0) ==				\
		      &((struct efx_##source_name *)0)->field) ?	\
		    offsetof(struct efx_##source_name, field) :		\
		    offsetof(struct efx_##source_name, field)),		\
	.get_stat = get_stat_function,					\
}

static u64 efx_get_uint_stat(void *field)
{
	return *(unsigned int *)field;
}

static u64 efx_get_u64_stat(void *field)
{
	return *(u64 *) field;
}

static u64 efx_get_atomic_stat(void *field)
{
	return atomic_read((atomic_t *) field);
}

#define EFX_ETHTOOL_U64_MAC_STAT(field)				\
66
	EFX_ETHTOOL_STAT(field, mac_stats, field,		\
67 68 69 70 71 72 73 74 75 76 77 78 79 80
			  u64, efx_get_u64_stat)

#define EFX_ETHTOOL_UINT_NIC_STAT(name)				\
	EFX_ETHTOOL_STAT(name, nic, n_##name,			\
			 unsigned int, efx_get_uint_stat)

#define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field)		\
	EFX_ETHTOOL_STAT(field, nic, field,			\
			 atomic_t, efx_get_atomic_stat)

#define EFX_ETHTOOL_UINT_CHANNEL_STAT(field)			\
	EFX_ETHTOOL_STAT(field, channel, n_##field,		\
			 unsigned int, efx_get_uint_stat)

81 82 83 84
#define EFX_ETHTOOL_UINT_TXQ_STAT(field)			\
	EFX_ETHTOOL_STAT(tx_##field, tx_queue, field,		\
			 unsigned int, efx_get_uint_stat)

85
static const struct efx_ethtool_stat efx_ethtool_stats[] = {
86 87 88
	EFX_ETHTOOL_U64_MAC_STAT(tx_bytes),
	EFX_ETHTOOL_U64_MAC_STAT(tx_good_bytes),
	EFX_ETHTOOL_U64_MAC_STAT(tx_bad_bytes),
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
	EFX_ETHTOOL_U64_MAC_STAT(tx_packets),
	EFX_ETHTOOL_U64_MAC_STAT(tx_bad),
	EFX_ETHTOOL_U64_MAC_STAT(tx_pause),
	EFX_ETHTOOL_U64_MAC_STAT(tx_control),
	EFX_ETHTOOL_U64_MAC_STAT(tx_unicast),
	EFX_ETHTOOL_U64_MAC_STAT(tx_multicast),
	EFX_ETHTOOL_U64_MAC_STAT(tx_broadcast),
	EFX_ETHTOOL_U64_MAC_STAT(tx_lt64),
	EFX_ETHTOOL_U64_MAC_STAT(tx_64),
	EFX_ETHTOOL_U64_MAC_STAT(tx_65_to_127),
	EFX_ETHTOOL_U64_MAC_STAT(tx_128_to_255),
	EFX_ETHTOOL_U64_MAC_STAT(tx_256_to_511),
	EFX_ETHTOOL_U64_MAC_STAT(tx_512_to_1023),
	EFX_ETHTOOL_U64_MAC_STAT(tx_1024_to_15xx),
	EFX_ETHTOOL_U64_MAC_STAT(tx_15xx_to_jumbo),
	EFX_ETHTOOL_U64_MAC_STAT(tx_gtjumbo),
	EFX_ETHTOOL_U64_MAC_STAT(tx_collision),
	EFX_ETHTOOL_U64_MAC_STAT(tx_single_collision),
	EFX_ETHTOOL_U64_MAC_STAT(tx_multiple_collision),
	EFX_ETHTOOL_U64_MAC_STAT(tx_excessive_collision),
	EFX_ETHTOOL_U64_MAC_STAT(tx_deferred),
	EFX_ETHTOOL_U64_MAC_STAT(tx_late_collision),
	EFX_ETHTOOL_U64_MAC_STAT(tx_excessive_deferred),
	EFX_ETHTOOL_U64_MAC_STAT(tx_non_tcpudp),
	EFX_ETHTOOL_U64_MAC_STAT(tx_mac_src_error),
	EFX_ETHTOOL_U64_MAC_STAT(tx_ip_src_error),
115 116 117 118
	EFX_ETHTOOL_UINT_TXQ_STAT(tso_bursts),
	EFX_ETHTOOL_UINT_TXQ_STAT(tso_long_headers),
	EFX_ETHTOOL_UINT_TXQ_STAT(tso_packets),
	EFX_ETHTOOL_UINT_TXQ_STAT(pushes),
119 120 121
	EFX_ETHTOOL_U64_MAC_STAT(rx_bytes),
	EFX_ETHTOOL_U64_MAC_STAT(rx_good_bytes),
	EFX_ETHTOOL_U64_MAC_STAT(rx_bad_bytes),
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
	EFX_ETHTOOL_U64_MAC_STAT(rx_packets),
	EFX_ETHTOOL_U64_MAC_STAT(rx_good),
	EFX_ETHTOOL_U64_MAC_STAT(rx_bad),
	EFX_ETHTOOL_U64_MAC_STAT(rx_pause),
	EFX_ETHTOOL_U64_MAC_STAT(rx_control),
	EFX_ETHTOOL_U64_MAC_STAT(rx_unicast),
	EFX_ETHTOOL_U64_MAC_STAT(rx_multicast),
	EFX_ETHTOOL_U64_MAC_STAT(rx_broadcast),
	EFX_ETHTOOL_U64_MAC_STAT(rx_lt64),
	EFX_ETHTOOL_U64_MAC_STAT(rx_64),
	EFX_ETHTOOL_U64_MAC_STAT(rx_65_to_127),
	EFX_ETHTOOL_U64_MAC_STAT(rx_128_to_255),
	EFX_ETHTOOL_U64_MAC_STAT(rx_256_to_511),
	EFX_ETHTOOL_U64_MAC_STAT(rx_512_to_1023),
	EFX_ETHTOOL_U64_MAC_STAT(rx_1024_to_15xx),
	EFX_ETHTOOL_U64_MAC_STAT(rx_15xx_to_jumbo),
	EFX_ETHTOOL_U64_MAC_STAT(rx_gtjumbo),
	EFX_ETHTOOL_U64_MAC_STAT(rx_bad_lt64),
	EFX_ETHTOOL_U64_MAC_STAT(rx_bad_64_to_15xx),
	EFX_ETHTOOL_U64_MAC_STAT(rx_bad_15xx_to_jumbo),
	EFX_ETHTOOL_U64_MAC_STAT(rx_bad_gtjumbo),
	EFX_ETHTOOL_U64_MAC_STAT(rx_overflow),
	EFX_ETHTOOL_U64_MAC_STAT(rx_missed),
	EFX_ETHTOOL_U64_MAC_STAT(rx_false_carrier),
	EFX_ETHTOOL_U64_MAC_STAT(rx_symbol_error),
	EFX_ETHTOOL_U64_MAC_STAT(rx_align_error),
	EFX_ETHTOOL_U64_MAC_STAT(rx_length_error),
	EFX_ETHTOOL_U64_MAC_STAT(rx_internal_error),
150 151 152 153 154
	EFX_ETHTOOL_UINT_NIC_STAT(rx_nodesc_drop_cnt),
	EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset),
	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc),
	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),
	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err),
B
Ben Hutchings 已提交
155
	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch),
156
	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
157
	EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_nodesc_trunc),
158 159 160 161 162
};

/* Number of ethtool statistics */
#define EFX_ETHTOOL_NUM_STATS ARRAY_SIZE(efx_ethtool_stats)

163 164
#define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB

165 166 167 168 169 170 171 172
/**************************************************************************
 *
 * Ethtool operations
 *
 **************************************************************************
 */

/* Identify device by flashing LEDs */
173 174
static int efx_ethtool_phys_id(struct net_device *net_dev,
			       enum ethtool_phys_id_state state)
175
{
176
	struct efx_nic *efx = netdev_priv(net_dev);
177
	enum efx_led_mode mode = EFX_LED_DEFAULT;
178

179 180 181 182 183 184 185 186 187 188
	switch (state) {
	case ETHTOOL_ID_ON:
		mode = EFX_LED_ON;
		break;
	case ETHTOOL_ID_OFF:
		mode = EFX_LED_OFF;
		break;
	case ETHTOOL_ID_INACTIVE:
		mode = EFX_LED_DEFAULT;
		break;
189 190
	case ETHTOOL_ID_ACTIVE:
		return 1;	/* cycle on/off once per second */
191
	}
192

193
	efx->type->set_id_led(efx, mode);
194 195 196 197
	return 0;
}

/* This must be called with rtnl_lock held. */
S
stephen hemminger 已提交
198 199
static int efx_ethtool_get_settings(struct net_device *net_dev,
				    struct ethtool_cmd *ecmd)
200
{
201
	struct efx_nic *efx = netdev_priv(net_dev);
B
Ben Hutchings 已提交
202
	struct efx_link_state *link_state = &efx->link_state;
203 204

	mutex_lock(&efx->mac_lock);
205
	efx->phy_op->get_settings(efx, ecmd);
206 207
	mutex_unlock(&efx->mac_lock);

208
	/* GMAC does not support 1000Mbps HD */
209
	ecmd->supported &= ~SUPPORTED_1000baseT_Half;
B
Ben Hutchings 已提交
210 211 212 213
	/* Both MACs support pause frames (bidirectional and respond-only) */
	ecmd->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;

	if (LOOPBACK_INTERNAL(efx)) {
214
		ethtool_cmd_speed_set(ecmd, link_state->speed);
B
Ben Hutchings 已提交
215 216
		ecmd->duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF;
	}
217 218

	return 0;
219 220 221
}

/* This must be called with rtnl_lock held. */
S
stephen hemminger 已提交
222 223
static int efx_ethtool_set_settings(struct net_device *net_dev,
				    struct ethtool_cmd *ecmd)
224
{
225
	struct efx_nic *efx = netdev_priv(net_dev);
226 227
	int rc;

228
	/* GMAC does not support 1000Mbps HD */
229 230
	if ((ethtool_cmd_speed(ecmd) == SPEED_1000) &&
	    (ecmd->duplex != DUPLEX_FULL)) {
231 232
		netif_dbg(efx, drv, efx->net_dev,
			  "rejecting unsupported 1000Mbps HD setting\n");
233 234 235
		return -EINVAL;
	}

236
	mutex_lock(&efx->mac_lock);
237
	rc = efx->phy_op->set_settings(efx, ecmd);
238 239 240 241 242 243 244
	mutex_unlock(&efx->mac_lock);
	return rc;
}

static void efx_ethtool_get_drvinfo(struct net_device *net_dev,
				    struct ethtool_drvinfo *info)
{
245
	struct efx_nic *efx = netdev_priv(net_dev);
246

247
	strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
248
	strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version));
249
	if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0)
250 251
		efx_mcdi_print_fwver(efx, info->fw_version,
				     sizeof(info->fw_version));
252 253 254
	strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
}

255 256 257 258 259 260 261 262 263 264 265 266 267 268
static int efx_ethtool_get_regs_len(struct net_device *net_dev)
{
	return efx_nic_get_regs_len(netdev_priv(net_dev));
}

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

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

269 270 271 272 273 274 275 276 277 278 279 280
static u32 efx_ethtool_get_msglevel(struct net_device *net_dev)
{
	struct efx_nic *efx = netdev_priv(net_dev);
	return efx->msg_enable;
}

static void efx_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable)
{
	struct efx_nic *efx = netdev_priv(net_dev);
	efx->msg_enable = msg_enable;
}

281 282 283 284 285 286
/**
 * efx_fill_test - fill in an individual self-test entry
 * @test_index:		Index of the test
 * @strings:		Ethtool strings, or %NULL
 * @data:		Ethtool test results, or %NULL
 * @test:		Pointer to test result (used only if data != %NULL)
287 288
 * @unit_format:	Unit name format (e.g. "chan\%d")
 * @unit_id:		Unit id (e.g. 0 for "chan0")
289
 * @test_format:	Test name format (e.g. "loopback.\%s.tx.sent")
290
 * @test_id:		Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
 *
 * Fill in an individual self-test entry.
 */
static void efx_fill_test(unsigned int test_index,
			  struct ethtool_string *strings, u64 *data,
			  int *test, const char *unit_format, int unit_id,
			  const char *test_format, const char *test_id)
{
	struct ethtool_string unit_str, test_str;

	/* Fill data value, if applicable */
	if (data)
		data[test_index] = *test;

	/* Fill string, if applicable */
	if (strings) {
307 308 309 310 311
		if (strchr(unit_format, '%'))
			snprintf(unit_str.name, sizeof(unit_str.name),
				 unit_format, unit_id);
		else
			strcpy(unit_str.name, unit_format);
312 313 314 315
		snprintf(test_str.name, sizeof(test_str.name),
			 test_format, test_id);
		snprintf(strings[test_index].name,
			 sizeof(strings[test_index].name),
316
			 "%-6s %-24s", unit_str.name, test_str.name);
317 318 319
	}
}

320
#define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
321 322 323
#define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
#define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
#define EFX_LOOPBACK_NAME(_mode, _counter)			\
324
	"loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode)
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340

/**
 * efx_fill_loopback_test - fill in a block of loopback self-test entries
 * @efx:		Efx NIC
 * @lb_tests:		Efx loopback self-test results structure
 * @mode:		Loopback test mode
 * @test_index:		Starting index of the test
 * @strings:		Ethtool strings, or %NULL
 * @data:		Ethtool test results, or %NULL
 */
static int efx_fill_loopback_test(struct efx_nic *efx,
				  struct efx_loopback_self_tests *lb_tests,
				  enum efx_loopback_mode mode,
				  unsigned int test_index,
				  struct ethtool_string *strings, u64 *data)
{
341 342
	struct efx_channel *channel =
		efx_get_channel(efx, efx->tx_channel_offset);
343 344
	struct efx_tx_queue *tx_queue;

345
	efx_for_each_channel_tx_queue(tx_queue, channel) {
346 347 348 349 350 351 352 353 354 355 356
		efx_fill_test(test_index++, strings, data,
			      &lb_tests->tx_sent[tx_queue->queue],
			      EFX_TX_QUEUE_NAME(tx_queue),
			      EFX_LOOPBACK_NAME(mode, "tx_sent"));
		efx_fill_test(test_index++, strings, data,
			      &lb_tests->tx_done[tx_queue->queue],
			      EFX_TX_QUEUE_NAME(tx_queue),
			      EFX_LOOPBACK_NAME(mode, "tx_done"));
	}
	efx_fill_test(test_index++, strings, data,
		      &lb_tests->rx_good,
357
		      "rx", 0,
358 359 360
		      EFX_LOOPBACK_NAME(mode, "rx_good"));
	efx_fill_test(test_index++, strings, data,
		      &lb_tests->rx_bad,
361
		      "rx", 0,
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
		      EFX_LOOPBACK_NAME(mode, "rx_bad"));

	return test_index;
}

/**
 * efx_ethtool_fill_self_tests - get self-test details
 * @efx:		Efx NIC
 * @tests:		Efx self-test results structure, or %NULL
 * @strings:		Ethtool strings, or %NULL
 * @data:		Ethtool test results, or %NULL
 */
static int efx_ethtool_fill_self_tests(struct efx_nic *efx,
				       struct efx_self_tests *tests,
				       struct ethtool_string *strings,
				       u64 *data)
{
	struct efx_channel *channel;
380
	unsigned int n = 0, i;
381 382
	enum efx_loopback_mode mode;

383 384
	efx_fill_test(n++, strings, data, &tests->phy_alive,
		      "phy", 0, "alive", NULL);
B
Ben Hutchings 已提交
385 386
	efx_fill_test(n++, strings, data, &tests->nvram,
		      "core", 0, "nvram", NULL);
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
	efx_fill_test(n++, strings, data, &tests->interrupt,
		      "core", 0, "interrupt", NULL);

	/* Event queues */
	efx_for_each_channel(channel, efx) {
		efx_fill_test(n++, strings, data,
			      &tests->eventq_dma[channel->channel],
			      EFX_CHANNEL_NAME(channel),
			      "eventq.dma", NULL);
		efx_fill_test(n++, strings, data,
			      &tests->eventq_int[channel->channel],
			      EFX_CHANNEL_NAME(channel),
			      "eventq.int", NULL);
	}

B
Ben Hutchings 已提交
402 403
	efx_fill_test(n++, strings, data, &tests->registers,
		      "core", 0, "registers", NULL);
404

405 406 407 408 409 410 411 412 413 414 415
	if (efx->phy_op->run_tests != NULL) {
		EFX_BUG_ON_PARANOID(efx->phy_op->test_name == NULL);

		for (i = 0; true; ++i) {
			const char *name;

			EFX_BUG_ON_PARANOID(i >= EFX_MAX_PHY_TESTS);
			name = efx->phy_op->test_name(efx, i);
			if (name == NULL)
				break;

416
			efx_fill_test(n++, strings, data, &tests->phy_ext[i],
417 418 419
				      "phy", 0, name, NULL);
		}
	}
420 421

	/* Loopback tests */
B
Ben Hutchings 已提交
422
	for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
423 424 425 426 427 428 429 430 431 432
		if (!(efx->loopback_modes & (1 << mode)))
			continue;
		n = efx_fill_loopback_test(efx,
					   &tests->loopback[mode], mode, n,
					   strings, data);
	}

	return n;
}

433 434
static int efx_ethtool_get_sset_count(struct net_device *net_dev,
				      int string_set)
435
{
436 437 438 439 440 441 442 443 444
	switch (string_set) {
	case ETH_SS_STATS:
		return EFX_ETHTOOL_NUM_STATS;
	case ETH_SS_TEST:
		return efx_ethtool_fill_self_tests(netdev_priv(net_dev),
						   NULL, NULL, NULL);
	default:
		return -EINVAL;
	}
445 446
}

447 448 449
static void efx_ethtool_get_strings(struct net_device *net_dev,
				    u32 string_set, u8 *strings)
{
450
	struct efx_nic *efx = netdev_priv(net_dev);
451 452 453 454
	struct ethtool_string *ethtool_strings =
		(struct ethtool_string *)strings;
	int i;

455 456
	switch (string_set) {
	case ETH_SS_STATS:
457
		for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++)
458
			strlcpy(ethtool_strings[i].name,
459 460
				efx_ethtool_stats[i].name,
				sizeof(ethtool_strings[i].name));
461 462 463 464 465 466 467 468 469
		break;
	case ETH_SS_TEST:
		efx_ethtool_fill_self_tests(efx, NULL,
					    ethtool_strings, NULL);
		break;
	default:
		/* No other string sets */
		break;
	}
470 471 472 473 474 475
}

static void efx_ethtool_get_stats(struct net_device *net_dev,
				  struct ethtool_stats *stats,
				  u64 *data)
{
476
	struct efx_nic *efx = netdev_priv(net_dev);
477
	struct efx_mac_stats *mac_stats = &efx->mac_stats;
478
	const struct efx_ethtool_stat *stat;
479
	struct efx_channel *channel;
480
	struct efx_tx_queue *tx_queue;
481 482 483 484
	int i;

	EFX_BUG_ON_PARANOID(stats->n_stats != EFX_ETHTOOL_NUM_STATS);

485 486
	spin_lock_bh(&efx->stats_lock);

487
	/* Update MAC and NIC statistics */
488
	efx->type->update_stats(efx);
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506

	/* Fill detailed statistics buffer */
	for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++) {
		stat = &efx_ethtool_stats[i];
		switch (stat->source) {
		case EFX_ETHTOOL_STAT_SOURCE_mac_stats:
			data[i] = stat->get_stat((void *)mac_stats +
						 stat->offset);
			break;
		case EFX_ETHTOOL_STAT_SOURCE_nic:
			data[i] = stat->get_stat((void *)efx + stat->offset);
			break;
		case EFX_ETHTOOL_STAT_SOURCE_channel:
			data[i] = 0;
			efx_for_each_channel(channel, efx)
				data[i] += stat->get_stat((void *)channel +
							  stat->offset);
			break;
507 508 509 510 511 512 513 514 515
		case EFX_ETHTOOL_STAT_SOURCE_tx_queue:
			data[i] = 0;
			efx_for_each_channel(channel, efx) {
				efx_for_each_channel_tx_queue(tx_queue, channel)
					data[i] +=
						stat->get_stat((void *)tx_queue
							       + stat->offset);
			}
			break;
516 517
		}
	}
518 519

	spin_unlock_bh(&efx->stats_lock);
520 521
}

522 523 524
static void efx_ethtool_self_test(struct net_device *net_dev,
				  struct ethtool_test *test, u64 *data)
{
525
	struct efx_nic *efx = netdev_priv(net_dev);
526
	struct efx_self_tests *efx_tests;
527
	int already_up;
528 529 530 531 532 533
	int rc = -ENOMEM;

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

534
	if (efx->state != STATE_READY) {
535 536 537 538
		rc = -EIO;
		goto fail1;
	}

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

542 543 544 545 546
	/* We need rx buffers and interrupts. */
	already_up = (efx->net_dev->flags & IFF_UP);
	if (!already_up) {
		rc = dev_open(efx->net_dev);
		if (rc) {
547 548
			netif_err(efx, drv, efx->net_dev,
				  "failed opening device.\n");
549
			goto fail1;
550 551 552
		}
	}

553
	rc = efx_selftest(efx, efx_tests, test->flags);
554 555 556 557

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

558 559 560
	netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n",
		   rc == 0 ? "passed" : "failed",
		   (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
561

562
fail1:
563
	/* Fill ethtool results structures */
564 565 566
	efx_ethtool_fill_self_tests(efx, efx_tests, NULL, data);
	kfree(efx_tests);
fail:
567 568 569 570
	if (rc)
		test->flags |= ETH_TEST_FL_FAILED;
}

571 572 573
/* Restart autonegotiation */
static int efx_ethtool_nway_reset(struct net_device *net_dev)
{
574
	struct efx_nic *efx = netdev_priv(net_dev);
575

576
	return mdio45_nway_restart(&efx->mdio);
577 578
}

579 580 581 582 583 584 585 586 587
/*
 * Each channel has a single IRQ and moderation timer, started by any
 * completion (or other event).  Unless the module parameter
 * separate_tx_channels is set, IRQs and moderation are therefore
 * shared between RX and TX completions.  In this case, when RX IRQ
 * moderation is explicitly changed then TX IRQ moderation is
 * automatically changed too, but otherwise we fail if the two values
 * are requested to be different.
 *
588 589 590 591 592 593 594 595 596 597 598 599 600 601
 * The hardware does not support a limit on the number of completions
 * before an IRQ, so we do not use the max_frames fields.  We should
 * report and require that max_frames == (usecs != 0), but this would
 * invalidate existing user documentation.
 *
 * The hardware does not have distinct settings for interrupt
 * moderation while the previous IRQ is being handled, so we should
 * not use the 'irq' fields.  However, an earlier developer
 * misunderstood the meaning of the 'irq' fields and the driver did
 * not support the standard fields.  To avoid invalidating existing
 * user documentation, we report and accept changes through either the
 * standard or 'irq' fields.  If both are changed at the same time, we
 * prefer the standard field.
 *
602 603 604 605 606 607
 * We implement adaptive IRQ moderation, but use a different algorithm
 * from that assumed in the definition of struct ethtool_coalesce.
 * Therefore we do not use any of the adaptive moderation parameters
 * in it.
 */

608 609 610
static int efx_ethtool_get_coalesce(struct net_device *net_dev,
				    struct ethtool_coalesce *coalesce)
{
611
	struct efx_nic *efx = netdev_priv(net_dev);
612 613
	unsigned int tx_usecs, rx_usecs;
	bool rx_adaptive;
614

615
	efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &rx_adaptive);
616

617
	coalesce->tx_coalesce_usecs = tx_usecs;
618
	coalesce->tx_coalesce_usecs_irq = tx_usecs;
619
	coalesce->rx_coalesce_usecs = rx_usecs;
620 621
	coalesce->rx_coalesce_usecs_irq = rx_usecs;
	coalesce->use_adaptive_rx_coalesce = rx_adaptive;
622

623 624 625 626 627 628
	return 0;
}

static int efx_ethtool_set_coalesce(struct net_device *net_dev,
				    struct ethtool_coalesce *coalesce)
{
629
	struct efx_nic *efx = netdev_priv(net_dev);
630
	struct efx_channel *channel;
631
	unsigned int tx_usecs, rx_usecs;
632 633
	bool adaptive, rx_may_override_tx;
	int rc;
634

635
	if (coalesce->use_adaptive_tx_coalesce)
636
		return -EINVAL;
637

638 639
	efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &adaptive);

640 641 642 643 644
	if (coalesce->rx_coalesce_usecs != rx_usecs)
		rx_usecs = coalesce->rx_coalesce_usecs;
	else
		rx_usecs = coalesce->rx_coalesce_usecs_irq;

645
	adaptive = coalesce->use_adaptive_rx_coalesce;
646

647 648 649
	/* If channels are shared, TX IRQ moderation can be quietly
	 * overridden unless it is changed from its old value.
	 */
650 651 652 653 654 655
	rx_may_override_tx = (coalesce->tx_coalesce_usecs == tx_usecs &&
			      coalesce->tx_coalesce_usecs_irq == tx_usecs);
	if (coalesce->tx_coalesce_usecs != tx_usecs)
		tx_usecs = coalesce->tx_coalesce_usecs;
	else
		tx_usecs = coalesce->tx_coalesce_usecs_irq;
656

657 658 659 660 661
	rc = efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive,
				     rx_may_override_tx);
	if (rc != 0)
		return rc;

662
	efx_for_each_channel(channel, efx)
663
		efx->type->push_irq_moderation(channel);
664 665 666 667

	return 0;
}

668 669 670 671 672 673 674 675 676 677 678 679 680 681 682
static void efx_ethtool_get_ringparam(struct net_device *net_dev,
				      struct ethtool_ringparam *ring)
{
	struct efx_nic *efx = netdev_priv(net_dev);

	ring->rx_max_pending = EFX_MAX_DMAQ_SIZE;
	ring->tx_max_pending = EFX_MAX_DMAQ_SIZE;
	ring->rx_pending = efx->rxq_entries;
	ring->tx_pending = efx->txq_entries;
}

static int efx_ethtool_set_ringparam(struct net_device *net_dev,
				     struct ethtool_ringparam *ring)
{
	struct efx_nic *efx = netdev_priv(net_dev);
683
	u32 txq_entries;
684 685 686 687 688 689

	if (ring->rx_mini_pending || ring->rx_jumbo_pending ||
	    ring->rx_pending > EFX_MAX_DMAQ_SIZE ||
	    ring->tx_pending > EFX_MAX_DMAQ_SIZE)
		return -EINVAL;

690
	if (ring->rx_pending < EFX_RXQ_MIN_ENT) {
691
		netif_err(efx, drv, efx->net_dev,
692 693
			  "RX queues cannot be smaller than %u\n",
			  EFX_RXQ_MIN_ENT);
694 695 696
		return -EINVAL;
	}

697 698 699 700 701 702 703
	txq_entries = max(ring->tx_pending, EFX_TXQ_MIN_ENT(efx));
	if (txq_entries != ring->tx_pending)
		netif_warn(efx, drv, efx->net_dev,
			   "increasing TX queue size to minimum of %u\n",
			   txq_entries);

	return efx_realloc_channels(efx, ring->rx_pending, txq_entries);
704 705
}

706 707 708
static int efx_ethtool_set_pauseparam(struct net_device *net_dev,
				      struct ethtool_pauseparam *pause)
{
709
	struct efx_nic *efx = netdev_priv(net_dev);
710
	u8 wanted_fc, old_fc;
B
Ben Hutchings 已提交
711 712 713 714
	u32 old_adv;
	int rc = 0;

	mutex_lock(&efx->mac_lock);
715

B
Ben Hutchings 已提交
716 717 718 719 720
	wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
		     (pause->tx_pause ? EFX_FC_TX : 0) |
		     (pause->autoneg ? EFX_FC_AUTO : 0));

	if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
721 722
		netif_dbg(efx, drv, efx->net_dev,
			  "Flow control unsupported: tx ON rx OFF\n");
B
Ben Hutchings 已提交
723 724
		rc = -EINVAL;
		goto out;
B
Ben Hutchings 已提交
725 726
	}

B
Ben Hutchings 已提交
727
	if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising) {
728 729
		netif_dbg(efx, drv, efx->net_dev,
			  "Autonegotiation is disabled\n");
B
Ben Hutchings 已提交
730 731
		rc = -EINVAL;
		goto out;
B
Ben Hutchings 已提交
732 733
	}

734 735 736 737
	/* Hook for Falcon bug 11482 workaround */
	if (efx->type->prepare_enable_fc_tx &&
	    (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX))
		efx->type->prepare_enable_fc_tx(efx);
B
Ben Hutchings 已提交
738

B
Ben Hutchings 已提交
739 740 741 742 743 744 745
	old_adv = efx->link_advertising;
	old_fc = efx->wanted_fc;
	efx_link_set_wanted_fc(efx, wanted_fc);
	if (efx->link_advertising != old_adv ||
	    (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) {
		rc = efx->phy_op->reconfigure(efx);
		if (rc) {
746 747 748
			netif_err(efx, drv, efx->net_dev,
				  "Unable to advertise requested flow "
				  "control setting\n");
B
Ben Hutchings 已提交
749 750 751
			goto out;
		}
	}
B
Ben Hutchings 已提交
752

B
Ben Hutchings 已提交
753 754 755
	/* Reconfigure the MAC. The PHY *may* generate a link state change event
	 * if the user just changed the advertised capabilities, but there's no
	 * harm doing this twice */
756
	efx->type->reconfigure_mac(efx);
B
Ben Hutchings 已提交
757

B
Ben Hutchings 已提交
758
out:
B
Ben Hutchings 已提交
759
	mutex_unlock(&efx->mac_lock);
760

B
Ben Hutchings 已提交
761
	return rc;
762 763 764 765 766
}

static void efx_ethtool_get_pauseparam(struct net_device *net_dev,
				       struct ethtool_pauseparam *pause)
{
767
	struct efx_nic *efx = netdev_priv(net_dev);
768

B
Ben Hutchings 已提交
769 770 771
	pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX);
	pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX);
	pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO);
772 773 774
}


775 776 777 778 779 780 781 782 783 784 785 786 787 788 789
static void efx_ethtool_get_wol(struct net_device *net_dev,
				struct ethtool_wolinfo *wol)
{
	struct efx_nic *efx = netdev_priv(net_dev);
	return efx->type->get_wol(efx, wol);
}


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

S
stephen hemminger 已提交
790
static int efx_ethtool_reset(struct net_device *net_dev, u32 *flags)
791 792
{
	struct efx_nic *efx = netdev_priv(net_dev);
793
	int rc;
794

795 796 797
	rc = efx->type->map_reset_flags(flags);
	if (rc < 0)
		return rc;
798

799
	return efx_reset(efx, rc);
800 801
}

802 803 804
/* MAC address mask including only MC flag */
static const u8 mac_addr_mc_mask[ETH_ALEN] = { 0x01, 0, 0, 0, 0, 0 };

805 806 807
#define IP4_ADDR_FULL_MASK	((__force __be32)~0)
#define PORT_FULL_MASK		((__force __be16)~0)

808 809 810 811 812
static int efx_ethtool_get_class_rule(struct efx_nic *efx,
				      struct ethtool_rx_flow_spec *rule)
{
	struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
	struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
813 814
	struct ethhdr *mac_entry = &rule->h_u.ether_spec;
	struct ethhdr *mac_mask = &rule->m_u.ether_spec;
815 816 817 818 819 820 821 822 823 824
	struct efx_filter_spec spec;
	u16 vid;
	u8 proto;
	int rc;

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

B
Ben Hutchings 已提交
825
	if (spec.dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP)
826 827 828 829
		rule->ring_cookie = RX_CLS_FLOW_DISC;
	else
		rule->ring_cookie = spec.dmaq_id;

830 831 832 833 834 835 836 837 838
	if (spec.type == EFX_FILTER_MC_DEF || spec.type == EFX_FILTER_UC_DEF) {
		rule->flow_type = ETHER_FLOW;
		memcpy(mac_mask->h_dest, mac_addr_mc_mask, ETH_ALEN);
		if (spec.type == EFX_FILTER_MC_DEF)
			memcpy(mac_entry->h_dest, mac_addr_mc_mask, ETH_ALEN);
		return 0;
	}

	rc = efx_filter_get_eth_local(&spec, &vid, mac_entry->h_dest);
839 840
	if (rc == 0) {
		rule->flow_type = ETHER_FLOW;
841
		memset(mac_mask->h_dest, ~0, ETH_ALEN);
842 843 844 845 846 847 848 849 850 851 852 853
		if (vid != EFX_FILTER_VID_UNSPEC) {
			rule->flow_type |= FLOW_EXT;
			rule->h_ext.vlan_tci = htons(vid);
			rule->m_ext.vlan_tci = htons(0xfff);
		}
		return 0;
	}

	rc = efx_filter_get_ipv4_local(&spec, &proto,
				       &ip_entry->ip4dst, &ip_entry->pdst);
	if (rc != 0) {
		rc = efx_filter_get_ipv4_full(
854 855
			&spec, &proto, &ip_entry->ip4dst, &ip_entry->pdst,
			&ip_entry->ip4src, &ip_entry->psrc);
856
		EFX_WARN_ON_PARANOID(rc);
857 858
		ip_mask->ip4src = IP4_ADDR_FULL_MASK;
		ip_mask->psrc = PORT_FULL_MASK;
859 860
	}
	rule->flow_type = (proto == IPPROTO_TCP) ? TCP_V4_FLOW : UDP_V4_FLOW;
861 862
	ip_mask->ip4dst = IP4_ADDR_FULL_MASK;
	ip_mask->pdst = PORT_FULL_MASK;
863 864 865
	return rc;
}

866 867
static int
efx_ethtool_get_rxnfc(struct net_device *net_dev,
868
		      struct ethtool_rxnfc *info, u32 *rule_locs)
869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909
{
	struct efx_nic *efx = netdev_priv(net_dev);

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

	case ETHTOOL_GRXFH: {
		unsigned min_revision = 0;

		info->data = 0;
		switch (info->flow_type) {
		case TCP_V4_FLOW:
			info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
			/* fall through */
		case UDP_V4_FLOW:
		case SCTP_V4_FLOW:
		case AH_ESP_V4_FLOW:
		case IPV4_FLOW:
			info->data |= RXH_IP_SRC | RXH_IP_DST;
			min_revision = EFX_REV_FALCON_B0;
			break;
		case TCP_V6_FLOW:
			info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
			/* fall through */
		case UDP_V6_FLOW:
		case SCTP_V6_FLOW:
		case AH_ESP_V6_FLOW:
		case IPV6_FLOW:
			info->data |= RXH_IP_SRC | RXH_IP_DST;
			min_revision = EFX_REV_SIENA_A0;
			break;
		default:
			break;
		}
		if (efx_nic_rev(efx) < min_revision)
			info->data = 0;
		return 0;
	}

910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936
	case ETHTOOL_GRXCLSRLCNT:
		info->data = efx_filter_get_rx_id_limit(efx);
		if (info->data == 0)
			return -EOPNOTSUPP;
		info->data |= RX_CLS_LOC_SPECIAL;
		info->rule_cnt =
			efx_filter_count_rx_used(efx, EFX_FILTER_PRI_MANUAL);
		return 0;

	case ETHTOOL_GRXCLSRULE:
		if (efx_filter_get_rx_id_limit(efx) == 0)
			return -EOPNOTSUPP;
		return efx_ethtool_get_class_rule(efx, &info->fs);

	case ETHTOOL_GRXCLSRLALL: {
		s32 rc;
		info->data = efx_filter_get_rx_id_limit(efx);
		if (info->data == 0)
			return -EOPNOTSUPP;
		rc = efx_filter_get_rx_ids(efx, EFX_FILTER_PRI_MANUAL,
					   rule_locs, info->rule_cnt);
		if (rc < 0)
			return rc;
		info->rule_cnt = rc;
		return 0;
	}

937 938 939 940 941
	default:
		return -EOPNOTSUPP;
	}
}

942 943
static int efx_ethtool_set_class_rule(struct efx_nic *efx,
				      struct ethtool_rx_flow_spec *rule)
944
{
945 946 947 948 949
	struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
	struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
	struct ethhdr *mac_entry = &rule->h_u.ether_spec;
	struct ethhdr *mac_mask = &rule->m_u.ether_spec;
	struct efx_filter_spec spec;
950
	int rc;
951

952
	/* Check that user wants us to choose the location */
953
	if (rule->location != RX_CLS_LOC_ANY)
954 955
		return -EINVAL;

956 957 958
	/* Range-check ring_cookie */
	if (rule->ring_cookie >= efx->n_rx_channels &&
	    rule->ring_cookie != RX_CLS_FLOW_DISC)
959 960
		return -EINVAL;

961 962
	/* Check for unsupported extensions */
	if ((rule->flow_type & FLOW_EXT) &&
963
	    (rule->m_ext.vlan_etype || rule->m_ext.data[0] ||
964 965 966
	     rule->m_ext.data[1]))
		return -EINVAL;

967 968
	efx_filter_init_rx(&spec, EFX_FILTER_PRI_MANUAL,
			   efx->rx_scatter ? EFX_FILTER_FLAG_RX_SCATTER : 0,
969
			   (rule->ring_cookie == RX_CLS_FLOW_DISC) ?
B
Ben Hutchings 已提交
970
			   EFX_FILTER_RX_DMAQ_ID_DROP : rule->ring_cookie);
971

972
	switch (rule->flow_type) {
973
	case TCP_V4_FLOW:
974
	case UDP_V4_FLOW: {
975
		u8 proto = (rule->flow_type == TCP_V4_FLOW ?
976 977
			    IPPROTO_TCP : IPPROTO_UDP);

978
		/* Must match all of destination, */
979 980
		if (!(ip_mask->ip4dst == IP4_ADDR_FULL_MASK &&
		      ip_mask->pdst == PORT_FULL_MASK))
981 982
			return -EINVAL;
		/* all or none of source, */
983 984 985
		if ((ip_mask->ip4src || ip_mask->psrc) &&
		    !(ip_mask->ip4src == IP4_ADDR_FULL_MASK &&
		      ip_mask->psrc == PORT_FULL_MASK))
986 987
			return -EINVAL;
		/* and nothing else */
988
		if (ip_mask->tos || rule->m_ext.vlan_tci)
989
			return -EINVAL;
990

991 992
		if (ip_mask->ip4src)
			rc = efx_filter_set_ipv4_full(&spec, proto,
993 994 995 996 997
						      ip_entry->ip4dst,
						      ip_entry->pdst,
						      ip_entry->ip4src,
						      ip_entry->psrc);
		else
998
			rc = efx_filter_set_ipv4_local(&spec, proto,
999 1000 1001 1002
						       ip_entry->ip4dst,
						       ip_entry->pdst);
		if (rc)
			return rc;
1003
		break;
1004 1005
	}

1006
	case ETHER_FLOW | FLOW_EXT:
1007 1008 1009 1010 1011
	case ETHER_FLOW: {
		u16 vlan_tag_mask = (rule->flow_type & FLOW_EXT ?
				     ntohs(rule->m_ext.vlan_tci) : 0);

		/* Must not match on source address or Ethertype */
1012 1013
		if (!is_zero_ether_addr(mac_mask->h_source) ||
		    mac_mask->h_proto)
1014
			return -EINVAL;
1015

1016
		/* Is it a default UC or MC filter? */
1017
		if (ether_addr_equal(mac_mask->h_dest, mac_addr_mc_mask) &&
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036
		    vlan_tag_mask == 0) {
			if (is_multicast_ether_addr(mac_entry->h_dest))
				rc = efx_filter_set_mc_def(&spec);
			else
				rc = efx_filter_set_uc_def(&spec);
		}
		/* Otherwise, it must match all of destination and all
		 * or none of VID.
		 */
		else if (is_broadcast_ether_addr(mac_mask->h_dest) &&
			 (vlan_tag_mask == 0xfff || vlan_tag_mask == 0)) {
			rc = efx_filter_set_eth_local(
				&spec,
				vlan_tag_mask ?
				ntohs(rule->h_ext.vlan_tci) : EFX_FILTER_VID_UNSPEC,
				mac_entry->h_dest);
		} else {
			rc = -EINVAL;
		}
1037 1038
		if (rc)
			return rc;
1039
		break;
1040
	}
1041

1042 1043 1044 1045
	default:
		return -EINVAL;
	}

1046 1047 1048
	rc = efx_filter_insert_filter(efx, &spec, true);
	if (rc < 0)
		return rc;
1049

1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072
	rule->location = rc;
	return 0;
}

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

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

	switch (info->cmd) {
	case ETHTOOL_SRXCLSRLINS:
		return efx_ethtool_set_class_rule(efx, &info->fs);

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

	default:
		return -EOPNOTSUPP;
	}
1073 1074
}

1075
static u32 efx_ethtool_get_rxfh_indir_size(struct net_device *net_dev)
1076 1077 1078
{
	struct efx_nic *efx = netdev_priv(net_dev);

1079 1080
	return ((efx_nic_rev(efx) < EFX_REV_FALCON_B0 ||
		 efx->n_rx_channels == 1) ?
1081 1082 1083 1084 1085 1086
		0 : ARRAY_SIZE(efx->rx_indir_table));
}

static int efx_ethtool_get_rxfh_indir(struct net_device *net_dev, u32 *indir)
{
	struct efx_nic *efx = netdev_priv(net_dev);
1087

1088
	memcpy(indir, efx->rx_indir_table, sizeof(efx->rx_indir_table));
1089 1090 1091 1092
	return 0;
}

static int efx_ethtool_set_rxfh_indir(struct net_device *net_dev,
1093
				      const u32 *indir)
1094 1095 1096
{
	struct efx_nic *efx = netdev_priv(net_dev);

1097
	memcpy(efx->rx_indir_table, indir, sizeof(efx->rx_indir_table));
1098 1099 1100 1101
	efx_nic_push_rx_indir_table(efx);
	return 0;
}

1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115
int efx_ethtool_get_ts_info(struct net_device *net_dev,
			    struct ethtool_ts_info *ts_info)
{
	struct efx_nic *efx = netdev_priv(net_dev);

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

	efx_ptp_get_ts_info(efx, ts_info);
	return 0;
}

1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148
static int efx_ethtool_get_module_eeprom(struct net_device *net_dev,
					 struct ethtool_eeprom *ee,
					 u8 *data)
{
	struct efx_nic *efx = netdev_priv(net_dev);
	int ret;

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

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

	return ret;
}

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

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

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

	return ret;
}

1149
const struct ethtool_ops efx_ethtool_ops = {
1150 1151 1152
	.get_settings		= efx_ethtool_get_settings,
	.set_settings		= efx_ethtool_set_settings,
	.get_drvinfo		= efx_ethtool_get_drvinfo,
1153 1154
	.get_regs_len		= efx_ethtool_get_regs_len,
	.get_regs		= efx_ethtool_get_regs,
1155 1156
	.get_msglevel		= efx_ethtool_get_msglevel,
	.set_msglevel		= efx_ethtool_set_msglevel,
1157
	.nway_reset		= efx_ethtool_nway_reset,
1158
	.get_link		= ethtool_op_get_link,
1159 1160
	.get_coalesce		= efx_ethtool_get_coalesce,
	.set_coalesce		= efx_ethtool_set_coalesce,
1161 1162
	.get_ringparam		= efx_ethtool_get_ringparam,
	.set_ringparam		= efx_ethtool_set_ringparam,
1163 1164
	.get_pauseparam         = efx_ethtool_get_pauseparam,
	.set_pauseparam         = efx_ethtool_set_pauseparam,
1165
	.get_sset_count		= efx_ethtool_get_sset_count,
1166
	.self_test		= efx_ethtool_self_test,
1167
	.get_strings		= efx_ethtool_get_strings,
1168
	.set_phys_id		= efx_ethtool_phys_id,
1169
	.get_ethtool_stats	= efx_ethtool_get_stats,
1170 1171
	.get_wol                = efx_ethtool_get_wol,
	.set_wol                = efx_ethtool_set_wol,
1172
	.reset			= efx_ethtool_reset,
1173
	.get_rxnfc		= efx_ethtool_get_rxnfc,
1174
	.set_rxnfc		= efx_ethtool_set_rxnfc,
1175
	.get_rxfh_indir_size	= efx_ethtool_get_rxfh_indir_size,
1176 1177
	.get_rxfh_indir		= efx_ethtool_get_rxfh_indir,
	.set_rxfh_indir		= efx_ethtool_set_rxfh_indir,
1178
	.get_ts_info		= efx_ethtool_get_ts_info,
1179 1180
	.get_module_info	= efx_ethtool_get_module_info,
	.get_module_eeprom	= efx_ethtool_get_module_eeprom,
1181
};