be_ethtool.c 35.6 KB
Newer Older
S
Sathya Perla 已提交
1
/*
V
Vasundhara Volam 已提交
2
 * Copyright (C) 2005 - 2014 Emulex
S
Sathya Perla 已提交
3 4 5 6 7 8 9 10
 * All rights reserved.
 *
 * 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.  The full GNU General
 * Public License is included in this distribution in the file called COPYING.
 *
 * Contact Information:
11
 * linux-drivers@emulex.com
S
Sathya Perla 已提交
12
 *
13 14 15
 * Emulex
 * 3333 Susan Street
 * Costa Mesa, CA 92626
S
Sathya Perla 已提交
16 17 18
 */

#include "be.h"
19
#include "be_cmds.h"
S
Sathya Perla 已提交
20 21 22 23 24 25 26 27 28
#include <linux/ethtool.h>

struct be_ethtool_stat {
	char desc[ETH_GSTRING_LEN];
	int type;
	int size;
	int offset;
};

29
enum {DRVSTAT_TX, DRVSTAT_RX, DRVSTAT};
S
Sathya Perla 已提交
30 31
#define FIELDINFO(_struct, field) FIELD_SIZEOF(_struct, field), \
					offsetof(_struct, field)
32 33 34 35
#define DRVSTAT_TX_INFO(field)	#field, DRVSTAT_TX,\
					FIELDINFO(struct be_tx_stats, field)
#define DRVSTAT_RX_INFO(field)	#field, DRVSTAT_RX,\
					FIELDINFO(struct be_rx_stats, field)
36
#define	DRVSTAT_INFO(field)	#field, DRVSTAT,\
37
					FIELDINFO(struct be_drv_stats, field)
S
Sathya Perla 已提交
38 39

static const struct be_ethtool_stat et_stats[] = {
40 41 42 43
	{DRVSTAT_INFO(rx_crc_errors)},
	{DRVSTAT_INFO(rx_alignment_symbol_errors)},
	{DRVSTAT_INFO(rx_pause_frames)},
	{DRVSTAT_INFO(rx_control_frames)},
44 45 46
	/* Received packets dropped when the Ethernet length field
	 * is not equal to the actual Ethernet data length.
	 */
47
	{DRVSTAT_INFO(rx_in_range_errors)},
48 49 50
	/* Received packets dropped when their length field is >= 1501 bytes
	 * and <= 1535 bytes.
	 */
51
	{DRVSTAT_INFO(rx_out_range_errors)},
52
	/* Received packets dropped when they are longer than 9216 bytes */
53
	{DRVSTAT_INFO(rx_frame_too_long)},
54 55 56
	/* Received packets dropped when they don't pass the unicast or
	 * multicast address filtering.
	 */
57
	{DRVSTAT_INFO(rx_address_filtered)},
58 59 60
	/* Received packets dropped when IP packet length field is less than
	 * the IP header length field.
	 */
61
	{DRVSTAT_INFO(rx_dropped_too_small)},
62 63 64
	/* Received packets dropped when IP length field is greater than
	 * the actual packet length.
	 */
65
	{DRVSTAT_INFO(rx_dropped_too_short)},
66 67 68
	/* Received packets dropped when the IP header length field is less
	 * than 5.
	 */
69
	{DRVSTAT_INFO(rx_dropped_header_too_small)},
70 71 72 73
	/* Received packets dropped when the TCP header length field is less
	 * than 5 or the TCP header length + IP header length is more
	 * than IP packet length.
	 */
74 75
	{DRVSTAT_INFO(rx_dropped_tcp_length)},
	{DRVSTAT_INFO(rx_dropped_runt)},
76 77 78 79
	/* Number of received packets dropped when a fifo for descriptors going
	 * into the packet demux block overflows. In normal operation, this
	 * fifo must never overflow.
	 */
80
	{DRVSTAT_INFO(rxpp_fifo_overflow_drop)},
81 82 83 84 85
	/* Received packets dropped when the RX block runs out of space in
	 * one of its input FIFOs. This could happen due a long burst of
	 * minimum-sized (64b) frames in the receive path.
	 * This counter may also be erroneously incremented rarely.
	 */
86 87 88 89 90 91 92
	{DRVSTAT_INFO(rx_input_fifo_overflow_drop)},
	{DRVSTAT_INFO(rx_ip_checksum_errs)},
	{DRVSTAT_INFO(rx_tcp_checksum_errs)},
	{DRVSTAT_INFO(rx_udp_checksum_errs)},
	{DRVSTAT_INFO(tx_pauseframes)},
	{DRVSTAT_INFO(tx_controlframes)},
	{DRVSTAT_INFO(rx_priority_pause_frames)},
93
	{DRVSTAT_INFO(tx_priority_pauseframes)},
94 95 96
	/* Received packets dropped when an internal fifo going into
	 * main packet buffer tank (PMEM) overflows.
	 */
97 98
	{DRVSTAT_INFO(pmem_fifo_overflow_drop)},
	{DRVSTAT_INFO(jabber_events)},
99 100 101
	/* Received packets dropped due to lack of available HW packet buffers
	 * used to temporarily hold the received packets.
	 */
102
	{DRVSTAT_INFO(rx_drops_no_pbuf)},
103 104 105
	/* Received packets dropped due to input receive buffer
	 * descriptor fifo overflowing.
	 */
106
	{DRVSTAT_INFO(rx_drops_no_erx_descr)},
107 108 109 110
	/* Packets dropped because the internal FIFO to the offloaded TCP
	 * receive processing block is full. This could happen only for
	 * offloaded iSCSI or FCoE trarffic.
	 */
111
	{DRVSTAT_INFO(rx_drops_no_tpre_descr)},
112 113 114 115
	/* Received packets dropped when they need more than 8
	 * receive buffers. This cannot happen as the driver configures
	 * 2048 byte receive buffers.
	 */
116 117
	{DRVSTAT_INFO(rx_drops_too_many_frags)},
	{DRVSTAT_INFO(forwarded_packets)},
118 119 120
	/* Received packets dropped when the frame length
	 * is more than 9018 bytes
	 */
121
	{DRVSTAT_INFO(rx_drops_mtu)},
122 123
	/* Number of dma mapping errors */
	{DRVSTAT_INFO(dma_map_errors)},
124
	/* Number of packets dropped due to random early drop function */
125
	{DRVSTAT_INFO(eth_red_drops)},
126 127 128 129 130 131
	{DRVSTAT_INFO(be_on_die_temperature)},
	{DRVSTAT_INFO(rx_roce_bytes_lsd)},
	{DRVSTAT_INFO(rx_roce_bytes_msd)},
	{DRVSTAT_INFO(rx_roce_frames)},
	{DRVSTAT_INFO(roce_drops_payload_len)},
	{DRVSTAT_INFO(roce_drops_crc)}
S
Sathya Perla 已提交
132
};
133

S
Sathya Perla 已提交
134 135
#define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)

136 137 138
/* Stats related to multi RX queues: get_stats routine assumes bytes, pkts
 * are first and second members respectively.
 */
139
static const struct be_ethtool_stat et_rx_stats[] = {
140 141
	{DRVSTAT_RX_INFO(rx_bytes)},/* If moving this member see above note */
	{DRVSTAT_RX_INFO(rx_pkts)}, /* If moving this member see above note */
142
	{DRVSTAT_RX_INFO(rx_compl)},
143
	{DRVSTAT_RX_INFO(rx_compl_err)},
144
	{DRVSTAT_RX_INFO(rx_mcast_pkts)},
145 146 147
	/* Number of page allocation failures while posting receive buffers
	 * to HW.
	 */
148
	{DRVSTAT_RX_INFO(rx_post_fail)},
149
	/* Recevied packets dropped due to skb allocation failure */
150
	{DRVSTAT_RX_INFO(rx_drops_no_skbs)},
151 152 153
	/* Received packets dropped due to lack of available fetched buffers
	 * posted by the driver.
	 */
154
	{DRVSTAT_RX_INFO(rx_drops_no_frags)}
155
};
156

157 158
#define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats))

159 160 161
/* Stats related to multi TX queues: get_stats routine assumes compl is the
 * first member
 */
162
static const struct be_ethtool_stat et_tx_stats[] = {
163
	{DRVSTAT_TX_INFO(tx_compl)}, /* If moving this member see above note */
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
	/* This counter is incremented when the HW encounters an error while
	 * parsing the packet header of an outgoing TX request. This counter is
	 * applicable only for BE2, BE3 and Skyhawk based adapters.
	 */
	{DRVSTAT_TX_INFO(tx_hdr_parse_err)},
	/* This counter is incremented when an error occurs in the DMA
	 * operation associated with the TX request from the host to the device.
	 */
	{DRVSTAT_TX_INFO(tx_dma_err)},
	/* This counter is incremented when MAC or VLAN spoof checking is
	 * enabled on the interface and the TX request fails the spoof check
	 * in HW.
	 */
	{DRVSTAT_TX_INFO(tx_spoof_check_err)},
	/* This counter is incremented when the HW encounters an error while
	 * performing TSO offload. This counter is applicable only for Lancer
	 * adapters.
	 */
	{DRVSTAT_TX_INFO(tx_tso_err)},
	/* This counter is incremented when the HW detects Q-in-Q style VLAN
	 * tagging in a packet and such tagging is not expected on the outgoing
	 * interface. This counter is applicable only for Lancer adapters.
	 */
	{DRVSTAT_TX_INFO(tx_qinq_err)},
	/* This counter is incremented when the HW detects parity errors in the
	 * packet data. This counter is applicable only for Lancer adapters.
	 */
	{DRVSTAT_TX_INFO(tx_internal_parity_err)},
192 193
	{DRVSTAT_TX_INFO(tx_bytes)},
	{DRVSTAT_TX_INFO(tx_pkts)},
194
	/* Number of skbs queued for trasmission by the driver */
195
	{DRVSTAT_TX_INFO(tx_reqs)},
196 197 198
	/* Number of times the TX queue was stopped due to lack
	 * of spaces in the TXQ.
	 */
199 200 201
	{DRVSTAT_TX_INFO(tx_stops)},
	/* Pkts dropped in the driver's transmit path */
	{DRVSTAT_TX_INFO(tx_drv_drops)}
202
};
203

204 205
#define ETHTOOL_TXSTATS_NUM (ARRAY_SIZE(et_tx_stats))

206 207 208 209
static const char et_self_tests[][ETH_GSTRING_LEN] = {
	"MAC Loopback test",
	"PHY Loopback test",
	"External Loopback test",
210
	"DDR DMA test",
211
	"Link test"
212 213 214 215 216 217
};

#define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests)
#define BE_MAC_LOOPBACK 0x0
#define BE_PHY_LOOPBACK 0x1
#define BE_ONE_PORT_EXT_LOOPBACK 0x2
218
#define BE_NO_LOOPBACK 0xff
219

220
static void be_get_drvinfo(struct net_device *netdev,
221
			   struct ethtool_drvinfo *drvinfo)
S
Sathya Perla 已提交
222 223 224
{
	struct be_adapter *adapter = netdev_priv(netdev);

225 226
	strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
	strlcpy(drvinfo->version, DRV_VER, sizeof(drvinfo->version));
S
Somnath Kotur 已提交
227
	if (!memcmp(adapter->fw_ver, adapter->fw_on_flash, FW_VER_LEN))
228 229 230 231
		strlcpy(drvinfo->fw_version, adapter->fw_ver,
			sizeof(drvinfo->fw_version));
	else
		snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
S
Somnath Kotur 已提交
232
			 "%s [%s]", adapter->fw_ver, adapter->fw_on_flash);
233

234 235
	strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
		sizeof(drvinfo->bus_info));
S
Sathya Perla 已提交
236 237 238 239 240
	drvinfo->testinfo_len = 0;
	drvinfo->regdump_len = 0;
	drvinfo->eedump_len = 0;
}

241
static u32 lancer_cmd_get_file_len(struct be_adapter *adapter, u8 *file_name)
242 243 244 245 246 247 248 249 250
{
	u32 data_read = 0, eof;
	u8 addn_status;
	struct be_dma_mem data_len_cmd;
	int status;

	memset(&data_len_cmd, 0, sizeof(data_len_cmd));
	/* data_offset and data_size should be 0 to get reg len */
	status = lancer_cmd_read_object(adapter, &data_len_cmd, 0, 0,
251 252
					file_name, &data_read, &eof,
					&addn_status);
253 254 255 256

	return data_read;
}

257 258
static int lancer_cmd_read_file(struct be_adapter *adapter, u8 *file_name,
				u32 buf_len, void *buf)
259 260 261 262 263 264 265 266 267
{
	struct be_dma_mem read_cmd;
	u32 read_len = 0, total_read_len = 0, chunk_size;
	u32 eof = 0;
	u8 addn_status;
	int status = 0;

	read_cmd.size = LANCER_READ_FILE_CHUNK;
	read_cmd.va = pci_alloc_consistent(adapter->pdev, read_cmd.size,
268
					   &read_cmd.dma);
269 270 271

	if (!read_cmd.va) {
		dev_err(&adapter->pdev->dev,
272
			"Memory allocation failure while reading dump\n");
273 274 275 276 277
		return -ENOMEM;
	}

	while ((total_read_len < buf_len) && !eof) {
		chunk_size = min_t(u32, (buf_len - total_read_len),
K
Kalesh AP 已提交
278
				   LANCER_READ_FILE_CHUNK);
279 280
		chunk_size = ALIGN(chunk_size, 4);
		status = lancer_cmd_read_object(adapter, &read_cmd, chunk_size,
281 282
						total_read_len, file_name,
						&read_len, &eof, &addn_status);
283 284 285 286 287 288 289 290 291 292
		if (!status) {
			memcpy(buf + total_read_len, read_cmd.va, read_len);
			total_read_len += read_len;
			eof &= LANCER_READ_FILE_EOF_MASK;
		} else {
			status = -EIO;
			break;
		}
	}
	pci_free_consistent(adapter->pdev, read_cmd.size, read_cmd.va,
293
			    read_cmd.dma);
294 295 296 297

	return status;
}

298
static int be_get_reg_len(struct net_device *netdev)
299 300 301 302
{
	struct be_adapter *adapter = netdev_priv(netdev);
	u32 log_size = 0;

303 304 305
	if (!check_privilege(adapter, MAX_PRIVILEGES))
		return 0;

306 307 308
	if (be_physfn(adapter)) {
		if (lancer_chip(adapter))
			log_size = lancer_cmd_get_file_len(adapter,
309
							   LANCER_FW_DUMP_FILE);
310 311 312
		else
			be_cmd_get_reg_len(adapter, &log_size);
	}
313 314 315 316 317 318 319 320
	return log_size;
}

static void
be_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *buf)
{
	struct be_adapter *adapter = netdev_priv(netdev);

321 322
	if (be_physfn(adapter)) {
		memset(buf, 0, regs->len);
323 324
		if (lancer_chip(adapter))
			lancer_cmd_read_file(adapter, LANCER_FW_DUMP_FILE,
325
					     regs->len, buf);
326 327
		else
			be_cmd_get_regs(adapter, regs->len, buf);
328
	}
329 330
}

S
Sathya Perla 已提交
331 332
static int be_get_coalesce(struct net_device *netdev,
			   struct ethtool_coalesce *et)
S
Sathya Perla 已提交
333 334
{
	struct be_adapter *adapter = netdev_priv(netdev);
335
	struct be_aic_obj *aic = &adapter->aic_obj[0];
S
Sathya Perla 已提交
336

337 338 339
	et->rx_coalesce_usecs = aic->prev_eqd;
	et->rx_coalesce_usecs_high = aic->max_eqd;
	et->rx_coalesce_usecs_low = aic->min_eqd;
S
Sathya Perla 已提交
340

341 342 343
	et->tx_coalesce_usecs = aic->prev_eqd;
	et->tx_coalesce_usecs_high = aic->max_eqd;
	et->tx_coalesce_usecs_low = aic->min_eqd;
S
Sathya Perla 已提交
344

345 346
	et->use_adaptive_rx_coalesce = aic->enable;
	et->use_adaptive_tx_coalesce = aic->enable;
S
Sathya Perla 已提交
347 348 349 350

	return 0;
}

S
Sathya Perla 已提交
351 352
/* TX attributes are ignored. Only RX attributes are considered
 * eqd cmd is issued in the worker thread.
S
Sathya Perla 已提交
353
 */
S
Sathya Perla 已提交
354 355
static int be_set_coalesce(struct net_device *netdev,
			   struct ethtool_coalesce *et)
S
Sathya Perla 已提交
356 357
{
	struct be_adapter *adapter = netdev_priv(netdev);
358
	struct be_aic_obj *aic = &adapter->aic_obj[0];
S
Sathya Perla 已提交
359 360 361 362
	struct be_eq_obj *eqo;
	int i;

	for_all_evt_queues(adapter, eqo, i) {
363 364 365 366 367 368
		aic->enable = et->use_adaptive_rx_coalesce;
		aic->max_eqd = min(et->rx_coalesce_usecs_high, BE_MAX_EQD);
		aic->min_eqd = min(et->rx_coalesce_usecs_low, aic->max_eqd);
		aic->et_eqd = min(et->rx_coalesce_usecs, aic->max_eqd);
		aic->et_eqd = max(aic->et_eqd, aic->min_eqd);
		aic++;
S
Sathya Perla 已提交
369 370 371 372 373
	}

	return 0;
}

374 375
static void be_get_ethtool_stats(struct net_device *netdev,
				 struct ethtool_stats *stats, uint64_t *data)
S
Sathya Perla 已提交
376 377
{
	struct be_adapter *adapter = netdev_priv(netdev);
378
	struct be_rx_obj *rxo;
379
	struct be_tx_obj *txo;
380
	void *p;
381
	unsigned int i, j, base = 0, start;
S
Sathya Perla 已提交
382 383

	for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
384
		p = (u8 *)&adapter->drv_stats + et_stats[i].offset;
385
		data[i] = *(u32 *)p;
S
Sathya Perla 已提交
386
	}
387
	base += ETHTOOL_STATS_NUM;
388 389

	for_all_rx_queues(adapter, rxo, j) {
390 391 392
		struct be_rx_stats *stats = rx_stats(rxo);

		do {
393
			start = u64_stats_fetch_begin_irq(&stats->sync);
394 395
			data[base] = stats->rx_bytes;
			data[base + 1] = stats->rx_pkts;
396
		} while (u64_stats_fetch_retry_irq(&stats->sync, start));
397 398 399 400

		for (i = 2; i < ETHTOOL_RXSTATS_NUM; i++) {
			p = (u8 *)stats + et_rx_stats[i].offset;
			data[base + i] = *(u32 *)p;
401
		}
402
		base += ETHTOOL_RXSTATS_NUM;
403
	}
404 405

	for_all_tx_queues(adapter, txo, j) {
406 407 408
		struct be_tx_stats *stats = tx_stats(txo);

		do {
409
			start = u64_stats_fetch_begin_irq(&stats->sync_compl);
410
			data[base] = stats->tx_compl;
411
		} while (u64_stats_fetch_retry_irq(&stats->sync_compl, start));
412 413

		do {
414
			start = u64_stats_fetch_begin_irq(&stats->sync);
415 416 417 418 419 420
			for (i = 1; i < ETHTOOL_TXSTATS_NUM; i++) {
				p = (u8 *)stats + et_tx_stats[i].offset;
				data[base + i] =
					(et_tx_stats[i].size == sizeof(u64)) ?
						*(u64 *)p : *(u32 *)p;
			}
421
		} while (u64_stats_fetch_retry_irq(&stats->sync, start));
422
		base += ETHTOOL_TXSTATS_NUM;
423
	}
S
Sathya Perla 已提交
424 425
}

426 427
static void be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
				uint8_t *data)
S
Sathya Perla 已提交
428
{
429 430 431
	struct be_adapter *adapter = netdev_priv(netdev);
	int i, j;

S
Sathya Perla 已提交
432 433 434 435 436 437
	switch (stringset) {
	case ETH_SS_STATS:
		for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
			memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
			data += ETH_GSTRING_LEN;
		}
438 439 440 441 442 443 444
		for (i = 0; i < adapter->num_rx_qs; i++) {
			for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) {
				sprintf(data, "rxq%d: %s", i,
					et_rx_stats[j].desc);
				data += ETH_GSTRING_LEN;
			}
		}
445 446 447 448 449 450 451
		for (i = 0; i < adapter->num_tx_qs; i++) {
			for (j = 0; j < ETHTOOL_TXSTATS_NUM; j++) {
				sprintf(data, "txq%d: %s", i,
					et_tx_stats[j].desc);
				data += ETH_GSTRING_LEN;
			}
		}
S
Sathya Perla 已提交
452
		break;
453 454 455 456 457 458
	case ETH_SS_TEST:
		for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
			memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
			data += ETH_GSTRING_LEN;
		}
		break;
S
Sathya Perla 已提交
459 460 461
	}
}

462
static int be_get_sset_count(struct net_device *netdev, int stringset)
S
Sathya Perla 已提交
463
{
464 465
	struct be_adapter *adapter = netdev_priv(netdev);

466
	switch (stringset) {
467 468
	case ETH_SS_TEST:
		return ETHTOOL_TESTS_NUM;
469
	case ETH_SS_STATS:
470
		return ETHTOOL_STATS_NUM +
471 472
			adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM +
			adapter->num_tx_qs * ETHTOOL_TXSTATS_NUM;
473 474 475
	default:
		return -EINVAL;
	}
S
Sathya Perla 已提交
476 477
}

478
static u32 be_get_port_type(struct be_adapter *adapter)
A
Ajit Khaparde 已提交
479 480 481
{
	u32 port;

482
	switch (adapter->phy.interface_type) {
A
Ajit Khaparde 已提交
483 484 485 486 487 488
	case PHY_TYPE_BASET_1GB:
	case PHY_TYPE_BASEX_1GB:
	case PHY_TYPE_SGMII:
		port = PORT_TP;
		break;
	case PHY_TYPE_SFP_PLUS_10GB:
489 490 491 492 493 494 495 496 497 498
		if (adapter->phy.cable_type & SFP_PLUS_COPPER_CABLE)
			port = PORT_DA;
		else
			port = PORT_FIBRE;
		break;
	case PHY_TYPE_QSFP:
		if (adapter->phy.cable_type & QSFP_PLUS_CR4_CABLE)
			port = PORT_DA;
		else
			port = PORT_FIBRE;
A
Ajit Khaparde 已提交
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
		break;
	case PHY_TYPE_XFP_10GB:
	case PHY_TYPE_SFP_1GB:
		port = PORT_FIBRE;
		break;
	case PHY_TYPE_BASET_10GB:
		port = PORT_TP;
		break;
	default:
		port = PORT_OTHER;
	}

	return port;
}

514
static u32 convert_to_et_setting(struct be_adapter *adapter, u32 if_speeds)
A
Ajit Khaparde 已提交
515 516 517
{
	u32 val = 0;

518
	switch (adapter->phy.interface_type) {
A
Ajit Khaparde 已提交
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
	case PHY_TYPE_BASET_1GB:
	case PHY_TYPE_BASEX_1GB:
	case PHY_TYPE_SGMII:
		val |= SUPPORTED_TP;
		if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
			val |= SUPPORTED_1000baseT_Full;
		if (if_speeds & BE_SUPPORTED_SPEED_100MBPS)
			val |= SUPPORTED_100baseT_Full;
		if (if_speeds & BE_SUPPORTED_SPEED_10MBPS)
			val |= SUPPORTED_10baseT_Full;
		break;
	case PHY_TYPE_KX4_10GB:
		val |= SUPPORTED_Backplane;
		if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
			val |= SUPPORTED_1000baseKX_Full;
		if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
			val |= SUPPORTED_10000baseKX4_Full;
		break;
537 538 539 540 541 542 543
	case PHY_TYPE_KR2_20GB:
		val |= SUPPORTED_Backplane;
		if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
			val |= SUPPORTED_10000baseKR_Full;
		if (if_speeds & BE_SUPPORTED_SPEED_20GBPS)
			val |= SUPPORTED_20000baseKR2_Full;
		break;
A
Ajit Khaparde 已提交
544 545 546 547
	case PHY_TYPE_KR_10GB:
		val |= SUPPORTED_Backplane |
				SUPPORTED_10000baseKR_Full;
		break;
548 549 550 551 552 553 554
	case PHY_TYPE_KR4_40GB:
		val |= SUPPORTED_Backplane;
		if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
			val |= SUPPORTED_10000baseKR_Full;
		if (if_speeds & BE_SUPPORTED_SPEED_40GBPS)
			val |= SUPPORTED_40000baseKR4_Full;
		break;
555 556 557 558 559 560 561 562 563 564 565 566 567 568
	case PHY_TYPE_QSFP:
		if (if_speeds & BE_SUPPORTED_SPEED_40GBPS) {
			switch (adapter->phy.cable_type) {
			case QSFP_PLUS_CR4_CABLE:
				val |= SUPPORTED_40000baseCR4_Full;
				break;
			case QSFP_PLUS_LR4_CABLE:
				val |= SUPPORTED_40000baseLR4_Full;
				break;
			default:
				val |= SUPPORTED_40000baseSR4_Full;
				break;
			}
		}
A
Ajit Khaparde 已提交
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
	case PHY_TYPE_SFP_PLUS_10GB:
	case PHY_TYPE_XFP_10GB:
	case PHY_TYPE_SFP_1GB:
		val |= SUPPORTED_FIBRE;
		if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
			val |= SUPPORTED_10000baseT_Full;
		if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
			val |= SUPPORTED_1000baseT_Full;
		break;
	case PHY_TYPE_BASET_10GB:
		val |= SUPPORTED_TP;
		if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
			val |= SUPPORTED_10000baseT_Full;
		if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
			val |= SUPPORTED_1000baseT_Full;
		if (if_speeds & BE_SUPPORTED_SPEED_100MBPS)
			val |= SUPPORTED_100baseT_Full;
		break;
	default:
		val |= SUPPORTED_TP;
	}

	return val;
}

bool be_pause_supported(struct be_adapter *adapter)
{
	return (adapter->phy.interface_type == PHY_TYPE_SFP_PLUS_10GB ||
		adapter->phy.interface_type == PHY_TYPE_XFP_10GB) ?
		false : true;
}

S
Sathya Perla 已提交
601 602
static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
{
603
	struct be_adapter *adapter = netdev_priv(netdev);
604
	u8 link_status;
605
	u16 link_speed = 0;
606
	int status;
607 608
	u32 auto_speeds;
	u32 fixed_speeds;
609

610 611 612 613 614 615
	if (adapter->phy.link_speed < 0) {
		status = be_cmd_link_status_query(adapter, &link_speed,
						  &link_status, 0);
		if (!status)
			be_link_status_update(adapter, link_status);
		ethtool_cmd_speed_set(ecmd, link_speed);
A
Ajit Khaparde 已提交
616 617

		status = be_cmd_get_phy_info(adapter);
618 619 620
		if (!status) {
			auto_speeds = adapter->phy.auto_speeds_supported;
			fixed_speeds = adapter->phy.fixed_speeds_supported;
621 622

			be_cmd_query_cable_type(adapter);
623 624

			ecmd->supported =
625
				convert_to_et_setting(adapter,
626 627 628
						      auto_speeds |
						      fixed_speeds);
			ecmd->advertising =
629
				convert_to_et_setting(adapter, auto_speeds);
630

631
			ecmd->port = be_get_port_type(adapter);
632 633 634 635 636 637

			if (adapter->phy.auto_speeds_supported) {
				ecmd->supported |= SUPPORTED_Autoneg;
				ecmd->autoneg = AUTONEG_ENABLE;
				ecmd->advertising |= ADVERTISED_Autoneg;
			}
A
Ajit Khaparde 已提交
638 639

			ecmd->supported |= SUPPORTED_Pause;
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
			if (be_pause_supported(adapter))
				ecmd->advertising |= ADVERTISED_Pause;

			switch (adapter->phy.interface_type) {
			case PHY_TYPE_KR_10GB:
			case PHY_TYPE_KX4_10GB:
				ecmd->transceiver = XCVR_INTERNAL;
				break;
			default:
				ecmd->transceiver = XCVR_EXTERNAL;
				break;
			}
		} else {
			ecmd->port = PORT_OTHER;
			ecmd->autoneg = AUTONEG_DISABLE;
			ecmd->transceiver = XCVR_DUMMY1;
656
		}
657 658

		/* Save for future use */
A
Ajit Khaparde 已提交
659 660 661 662 663 664
		adapter->phy.link_speed = ethtool_cmd_speed(ecmd);
		adapter->phy.port_type = ecmd->port;
		adapter->phy.transceiver = ecmd->transceiver;
		adapter->phy.autoneg = ecmd->autoneg;
		adapter->phy.advertising = ecmd->advertising;
		adapter->phy.supported = ecmd->supported;
665
	} else {
A
Ajit Khaparde 已提交
666 667 668 669 670 671
		ethtool_cmd_speed_set(ecmd, adapter->phy.link_speed);
		ecmd->port = adapter->phy.port_type;
		ecmd->transceiver = adapter->phy.transceiver;
		ecmd->autoneg = adapter->phy.autoneg;
		ecmd->advertising = adapter->phy.advertising;
		ecmd->supported = adapter->phy.supported;
672
	}
673

674
	ecmd->duplex = netif_carrier_ok(netdev) ? DUPLEX_FULL : DUPLEX_UNKNOWN;
675
	ecmd->phy_address = adapter->port_num;
676

S
Sathya Perla 已提交
677 678 679
	return 0;
}

680 681
static void be_get_ringparam(struct net_device *netdev,
			     struct ethtool_ringparam *ring)
S
Sathya Perla 已提交
682 683 684
{
	struct be_adapter *adapter = netdev_priv(netdev);

685 686 687 688
	ring->rx_max_pending = adapter->rx_obj[0].q.len;
	ring->rx_pending = adapter->rx_obj[0].q.len;
	ring->tx_max_pending = adapter->tx_obj[0].q.len;
	ring->tx_pending = adapter->tx_obj[0].q.len;
S
Sathya Perla 已提交
689 690 691 692 693 694 695
}

static void
be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
{
	struct be_adapter *adapter = netdev_priv(netdev);

696
	be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
A
Ajit Khaparde 已提交
697
	ecmd->autoneg = adapter->phy.fc_autoneg;
S
Sathya Perla 已提交
698 699 700 701 702 703 704 705
}

static int
be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
{
	struct be_adapter *adapter = netdev_priv(netdev);
	int status;

706
	if (ecmd->autoneg != adapter->phy.fc_autoneg)
S
Sathya Perla 已提交
707 708
		return -EINVAL;

709 710 711
	status = be_cmd_set_flow_control(adapter, ecmd->tx_pause,
					 ecmd->rx_pause);
	if (status) {
V
Vasundhara Volam 已提交
712
		dev_warn(&adapter->pdev->dev, "Pause param set failed\n");
713 714
		return be_cmd_status(status);
	}
S
Sathya Perla 已提交
715

716 717 718
	adapter->tx_fc = ecmd->tx_pause;
	adapter->rx_fc = ecmd->rx_pause;
	return 0;
S
Sathya Perla 已提交
719 720
}

721 722
static int be_set_phys_id(struct net_device *netdev,
			  enum ethtool_phys_id_state state)
723 724 725
{
	struct be_adapter *adapter = netdev_priv(netdev);

726 727 728 729
	switch (state) {
	case ETHTOOL_ID_ACTIVE:
		be_cmd_get_beacon_state(adapter, adapter->hba_port_num,
					&adapter->beacon_state);
730
		return 1;	/* cycle on/off once per second */
731

732 733 734 735
	case ETHTOOL_ID_ON:
		be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
					BEACON_STATE_ENABLED);
		break;
736

737 738 739 740
	case ETHTOOL_ID_OFF:
		be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
					BEACON_STATE_DISABLED);
		break;
741

742 743 744 745
	case ETHTOOL_ID_INACTIVE:
		be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
					adapter->beacon_state);
	}
746

747
	return 0;
748 749
}

750 751 752 753 754 755
static int be_set_dump(struct net_device *netdev, struct ethtool_dump *dump)
{
	struct be_adapter *adapter = netdev_priv(netdev);
	struct device *dev = &adapter->pdev->dev;
	int status;

756 757
	if (!lancer_chip(adapter) ||
	    !check_privilege(adapter, MAX_PRIVILEGES))
758 759 760 761 762 763
		return -EOPNOTSUPP;

	switch (dump->flag) {
	case LANCER_INITIATE_FW_DUMP:
		status = lancer_initiate_dump(adapter);
		if (!status)
764
			dev_info(dev, "FW dump initiated successfully\n");
765
		break;
766 767 768 769 770
	case LANCER_DELETE_FW_DUMP:
		status = lancer_delete_dump(adapter);
		if (!status)
			dev_info(dev, "FW dump deleted successfully\n");
	break;
771 772 773 774 775 776
	default:
		dev_err(dev, "Invalid dump level: 0x%x\n", dump->flag);
		return -EINVAL;
	}
	return status;
}
777

778
static void be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
779 780 781
{
	struct be_adapter *adapter = netdev_priv(netdev);

S
Suresh Reddy 已提交
782
	if (adapter->wol_cap & BE_WOL_CAP) {
783
		wol->supported |= WAKE_MAGIC;
S
Suresh Reddy 已提交
784
		if (adapter->wol_en)
785
			wol->wolopts |= WAKE_MAGIC;
S
Suresh Reddy 已提交
786
	} else {
787
		wol->wolopts = 0;
S
Suresh Reddy 已提交
788
	}
789 790 791
	memset(&wol->sopass, 0, sizeof(wol->sopass));
}

792
static int be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
793 794 795 796
{
	struct be_adapter *adapter = netdev_priv(netdev);

	if (wol->wolopts & ~WAKE_MAGIC)
797 798
		return -EOPNOTSUPP;

S
Suresh Reddy 已提交
799
	if (!(adapter->wol_cap & BE_WOL_CAP)) {
800 801 802
		dev_warn(&adapter->pdev->dev, "WOL not supported\n");
		return -EOPNOTSUPP;
	}
803

804
	if (wol->wolopts & WAKE_MAGIC)
S
Suresh Reddy 已提交
805
		adapter->wol_en = true;
806
	else
S
Suresh Reddy 已提交
807
		adapter->wol_en = false;
808 809 810 811

	return 0;
}

812
static int be_test_ddr_dma(struct be_adapter *adapter)
813 814 815
{
	int ret, i;
	struct be_dma_mem ddrdma_cmd;
J
Joe Perches 已提交
816 817 818
	static const u64 pattern[2] = {
		0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
	};
819 820

	ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
I
Ivan Vecera 已提交
821 822
	ddrdma_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, ddrdma_cmd.size,
					   &ddrdma_cmd.dma, GFP_KERNEL);
823
	if (!ddrdma_cmd.va)
824 825 826 827
		return -ENOMEM;

	for (i = 0; i < 2; i++) {
		ret = be_cmd_ddr_dma_test(adapter, pattern[i],
828
					  4096, &ddrdma_cmd);
829 830 831 832 833
		if (ret != 0)
			goto err;
	}

err:
I
Ivan Vecera 已提交
834 835
	dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va,
			  ddrdma_cmd.dma);
836
	return be_cmd_status(ret);
837 838
}

839
static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
840
			    u64 *status)
841
{
842
	be_cmd_set_loopback(adapter, adapter->hba_port_num, loopback_type, 1);
843
	*status = be_cmd_loopback_test(adapter, adapter->hba_port_num,
844 845
				       loopback_type, 1500, 2, 0xabc);
	be_cmd_set_loopback(adapter, adapter->hba_port_num, BE_NO_LOOPBACK, 1);
846 847 848
	return *status;
}

849 850
static void be_self_test(struct net_device *netdev, struct ethtool_test *test,
			 u64 *data)
851 852
{
	struct be_adapter *adapter = netdev_priv(netdev);
853 854
	int status;
	u8 link_status = 0;
855

856 857 858 859 860 861
	if (adapter->function_caps & BE_FUNCTION_CAPS_SUPER_NIC) {
		dev_err(&adapter->pdev->dev, "Self test not supported\n");
		test->flags |= ETH_TEST_FL_FAILED;
		return;
	}

862 863 864
	memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);

	if (test->flags & ETH_TEST_FL_OFFLINE) {
865
		if (be_loopback_test(adapter, BE_MAC_LOOPBACK, &data[0]) != 0)
866
			test->flags |= ETH_TEST_FL_FAILED;
867

868
		if (be_loopback_test(adapter, BE_PHY_LOOPBACK, &data[1]) != 0)
869
			test->flags |= ETH_TEST_FL_FAILED;
870 871 872 873 874 875

		if (test->flags & ETH_TEST_FL_EXTERNAL_LB) {
			if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
					     &data[2]) != 0)
				test->flags |= ETH_TEST_FL_FAILED;
			test->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE;
876
		}
877
	}
878

879
	if (!lancer_chip(adapter) && be_test_ddr_dma(adapter) != 0) {
880 881
		data[3] = 1;
		test->flags |= ETH_TEST_FL_FAILED;
882 883
	}

884 885
	status = be_cmd_link_status_query(adapter, NULL, &link_status, 0);
	if (status) {
886 887
		test->flags |= ETH_TEST_FL_FAILED;
		data[4] = -1;
888
	} else if (!link_status) {
889
		test->flags |= ETH_TEST_FL_FAILED;
890 891
		data[4] = 1;
	}
892 893
}

894
static int be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
895 896 897
{
	struct be_adapter *adapter = netdev_priv(netdev);

898
	return be_load_fw(adapter, efl->data);
899 900
}

901
static int be_get_eeprom_len(struct net_device *netdev)
902
{
903
	struct be_adapter *adapter = netdev_priv(netdev);
904 905 906 907

	if (!check_privilege(adapter, MAX_PRIVILEGES))
		return 0;

908 909 910
	if (lancer_chip(adapter)) {
		if (be_physfn(adapter))
			return lancer_cmd_get_file_len(adapter,
911
						       LANCER_VPD_PF_FILE);
912 913
		else
			return lancer_cmd_get_file_len(adapter,
914
						       LANCER_VPD_VF_FILE);
915 916 917
	} else {
		return BE_READ_SEEPROM_LEN;
	}
918 919
}

920 921
static int be_read_eeprom(struct net_device *netdev,
			  struct ethtool_eeprom *eeprom, uint8_t *data)
922 923 924 925 926 927 928 929 930
{
	struct be_adapter *adapter = netdev_priv(netdev);
	struct be_dma_mem eeprom_cmd;
	struct be_cmd_resp_seeprom_read *resp;
	int status;

	if (!eeprom->len)
		return -EINVAL;

931 932 933
	if (lancer_chip(adapter)) {
		if (be_physfn(adapter))
			return lancer_cmd_read_file(adapter, LANCER_VPD_PF_FILE,
934
						    eeprom->len, data);
935 936
		else
			return lancer_cmd_read_file(adapter, LANCER_VPD_VF_FILE,
937
						    eeprom->len, data);
938 939
	}

940 941 942 943
	eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);

	memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
	eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
I
Ivan Vecera 已提交
944 945
	eeprom_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, eeprom_cmd.size,
					   &eeprom_cmd.dma, GFP_KERNEL);
946

947
	if (!eeprom_cmd.va)
948 949 950 951 952
		return -ENOMEM;

	status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);

	if (!status) {
953
		resp = eeprom_cmd.va;
954
		memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
955
	}
I
Ivan Vecera 已提交
956 957
	dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va,
			  eeprom_cmd.dma);
958

959
	return be_cmd_status(status);
960 961
}

962 963 964 965 966 967 968 969 970 971 972 973 974 975 976
static u32 be_get_msg_level(struct net_device *netdev)
{
	struct be_adapter *adapter = netdev_priv(netdev);

	return adapter->msg_enable;
}

static void be_set_msg_level(struct net_device *netdev, u32 level)
{
	struct be_adapter *adapter = netdev_priv(netdev);

	if (adapter->msg_enable == level)
		return;

	if ((level & NETIF_MSG_HW) != (adapter->msg_enable & NETIF_MSG_HW))
977 978 979 980
		if (BEx_chip(adapter))
			be_cmd_set_fw_log_level(adapter, level & NETIF_MSG_HW ?
						FW_LOG_LEVEL_DEFAULT :
						FW_LOG_LEVEL_FATAL);
981 982 983
	adapter->msg_enable = level;
}

984 985 986 987 988 989
static u64 be_get_rss_hash_opts(struct be_adapter *adapter, u64 flow_type)
{
	u64 data = 0;

	switch (flow_type) {
	case TCP_V4_FLOW:
990
		if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV4)
991
			data |= RXH_IP_DST | RXH_IP_SRC;
992
		if (adapter->rss_info.rss_flags & RSS_ENABLE_TCP_IPV4)
993 994 995
			data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
		break;
	case UDP_V4_FLOW:
996
		if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV4)
997
			data |= RXH_IP_DST | RXH_IP_SRC;
998
		if (adapter->rss_info.rss_flags & RSS_ENABLE_UDP_IPV4)
999 1000 1001
			data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
		break;
	case TCP_V6_FLOW:
1002
		if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV6)
1003
			data |= RXH_IP_DST | RXH_IP_SRC;
1004
		if (adapter->rss_info.rss_flags & RSS_ENABLE_TCP_IPV6)
1005 1006 1007
			data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
		break;
	case UDP_V6_FLOW:
1008
		if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV6)
1009
			data |= RXH_IP_DST | RXH_IP_SRC;
1010
		if (adapter->rss_info.rss_flags & RSS_ENABLE_UDP_IPV6)
1011 1012 1013 1014 1015 1016 1017 1018
			data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
		break;
	}

	return data;
}

static int be_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1019
			u32 *rule_locs)
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048
{
	struct be_adapter *adapter = netdev_priv(netdev);

	if (!be_multi_rxq(adapter)) {
		dev_info(&adapter->pdev->dev,
			 "ethtool::get_rxnfc: RX flow hashing is disabled\n");
		return -EINVAL;
	}

	switch (cmd->cmd) {
	case ETHTOOL_GRXFH:
		cmd->data = be_get_rss_hash_opts(adapter, cmd->flow_type);
		break;
	case ETHTOOL_GRXRINGS:
		cmd->data = adapter->num_rx_qs - 1;
		break;
	default:
		return -EINVAL;
	}

	return 0;
}

static int be_set_rss_hash_opts(struct be_adapter *adapter,
				struct ethtool_rxnfc *cmd)
{
	struct be_rx_obj *rxo;
	int status = 0, i, j;
	u8 rsstable[128];
1049
	u32 rss_flags = adapter->rss_info.rss_flags;
1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095

	if (cmd->data != L3_RSS_FLAGS &&
	    cmd->data != (L3_RSS_FLAGS | L4_RSS_FLAGS))
		return -EINVAL;

	switch (cmd->flow_type) {
	case TCP_V4_FLOW:
		if (cmd->data == L3_RSS_FLAGS)
			rss_flags &= ~RSS_ENABLE_TCP_IPV4;
		else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
			rss_flags |= RSS_ENABLE_IPV4 |
					RSS_ENABLE_TCP_IPV4;
		break;
	case TCP_V6_FLOW:
		if (cmd->data == L3_RSS_FLAGS)
			rss_flags &= ~RSS_ENABLE_TCP_IPV6;
		else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
			rss_flags |= RSS_ENABLE_IPV6 |
					RSS_ENABLE_TCP_IPV6;
		break;
	case UDP_V4_FLOW:
		if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) &&
		    BEx_chip(adapter))
			return -EINVAL;

		if (cmd->data == L3_RSS_FLAGS)
			rss_flags &= ~RSS_ENABLE_UDP_IPV4;
		else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
			rss_flags |= RSS_ENABLE_IPV4 |
					RSS_ENABLE_UDP_IPV4;
		break;
	case UDP_V6_FLOW:
		if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) &&
		    BEx_chip(adapter))
			return -EINVAL;

		if (cmd->data == L3_RSS_FLAGS)
			rss_flags &= ~RSS_ENABLE_UDP_IPV6;
		else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
			rss_flags |= RSS_ENABLE_IPV6 |
					RSS_ENABLE_UDP_IPV6;
		break;
	default:
		return -EINVAL;
	}

1096
	if (rss_flags == adapter->rss_info.rss_flags)
1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107
		return status;

	if (be_multi_rxq(adapter)) {
		for (j = 0; j < 128; j += adapter->num_rx_qs - 1) {
			for_all_rss_queues(adapter, rxo, i) {
				if ((j + i) >= 128)
					break;
				rsstable[j + i] = rxo->rss_id;
			}
		}
	}
1108 1109 1110

	status = be_cmd_rss_config(adapter, adapter->rss_info.rsstable,
				   rss_flags, 128, adapter->rss_info.rss_hkey);
1111
	if (!status)
1112
		adapter->rss_info.rss_flags = rss_flags;
1113

1114
	return be_cmd_status(status);
1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138
}

static int be_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
{
	struct be_adapter *adapter = netdev_priv(netdev);
	int status = 0;

	if (!be_multi_rxq(adapter)) {
		dev_err(&adapter->pdev->dev,
			"ethtool::set_rxnfc: RX flow hashing is disabled\n");
		return -EINVAL;
	}

	switch (cmd->cmd) {
	case ETHTOOL_SRXFH:
		status = be_set_rss_hash_opts(adapter, cmd);
		break;
	default:
		return -EINVAL;
	}

	return status;
}

1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151
static void be_get_channels(struct net_device *netdev,
			    struct ethtool_channels *ch)
{
	struct be_adapter *adapter = netdev_priv(netdev);

	ch->combined_count = adapter->num_evt_qs;
	ch->max_combined = be_max_qs(adapter);
}

static int be_set_channels(struct net_device  *netdev,
			   struct ethtool_channels *ch)
{
	struct be_adapter *adapter = netdev_priv(netdev);
1152
	int status;
1153 1154 1155 1156 1157 1158 1159

	if (ch->rx_count || ch->tx_count || ch->other_count ||
	    !ch->combined_count || ch->combined_count > be_max_qs(adapter))
		return -EINVAL;

	adapter->cfg_num_qs = ch->combined_count;

1160 1161
	status = be_update_queues(adapter);
	return be_cmd_status(status);
1162 1163
}

1164 1165 1166 1167 1168 1169 1170 1171 1172 1173
static u32 be_get_rxfh_indir_size(struct net_device *netdev)
{
	return RSS_INDIR_TABLE_LEN;
}

static u32 be_get_rxfh_key_size(struct net_device *netdev)
{
	return RSS_HASH_KEY_LEN;
}

1174 1175
static int be_get_rxfh(struct net_device *netdev, u32 *indir, u8 *hkey,
		       u8 *hfunc)
1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188
{
	struct be_adapter *adapter = netdev_priv(netdev);
	int i;
	struct rss_info *rss = &adapter->rss_info;

	if (indir) {
		for (i = 0; i < RSS_INDIR_TABLE_LEN; i++)
			indir[i] = rss->rss_queue[i];
	}

	if (hkey)
		memcpy(hkey, rss->rss_hkey, RSS_HASH_KEY_LEN);

1189 1190 1191
	if (hfunc)
		*hfunc = ETH_RSS_HASH_TOP;

1192 1193 1194
	return 0;
}

1195
static int be_set_rxfh(struct net_device *netdev, const u32 *indir,
1196
		       const u8 *hkey, const u8 hfunc)
1197 1198 1199 1200 1201
{
	int rc = 0, i, j;
	struct be_adapter *adapter = netdev_priv(netdev);
	u8 rsstable[RSS_INDIR_TABLE_LEN];

1202 1203 1204 1205
	/* We do not allow change in unsupported parameters */
	if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
		return -EOPNOTSUPP;

1206 1207
	if (indir) {
		struct be_rx_obj *rxo;
1208

1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223
		for (i = 0; i < RSS_INDIR_TABLE_LEN; i++) {
			j = indir[i];
			rxo = &adapter->rx_obj[j];
			rsstable[i] = rxo->rss_id;
			adapter->rss_info.rss_queue[i] = j;
		}
	} else {
		memcpy(rsstable, adapter->rss_info.rsstable,
		       RSS_INDIR_TABLE_LEN);
	}

	if (!hkey)
		hkey =  adapter->rss_info.rss_hkey;

	rc = be_cmd_rss_config(adapter, rsstable,
K
Kalesh AP 已提交
1224 1225
			       adapter->rss_info.rss_flags,
			       RSS_INDIR_TABLE_LEN, hkey);
1226 1227 1228 1229 1230 1231 1232 1233 1234 1235
	if (rc) {
		adapter->rss_info.rss_flags = RSS_ENABLE_NONE;
		return -EIO;
	}
	memcpy(adapter->rss_info.rss_hkey, hkey, RSS_HASH_KEY_LEN);
	memcpy(adapter->rss_info.rsstable, rsstable,
	       RSS_INDIR_TABLE_LEN);
	return 0;
}

1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287
static int be_get_module_info(struct net_device *netdev,
			      struct ethtool_modinfo *modinfo)
{
	struct be_adapter *adapter = netdev_priv(netdev);
	u8 page_data[PAGE_DATA_LEN];
	int status;

	if (!check_privilege(adapter, MAX_PRIVILEGES))
		return -EOPNOTSUPP;

	status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
						   page_data);
	if (!status) {
		if (!page_data[SFP_PLUS_SFF_8472_COMP]) {
			modinfo->type = ETH_MODULE_SFF_8079;
			modinfo->eeprom_len = PAGE_DATA_LEN;
		} else {
			modinfo->type = ETH_MODULE_SFF_8472;
			modinfo->eeprom_len = 2 * PAGE_DATA_LEN;
		}
	}
	return be_cmd_status(status);
}

static int be_get_module_eeprom(struct net_device *netdev,
				struct ethtool_eeprom *eeprom, u8 *data)
{
	struct be_adapter *adapter = netdev_priv(netdev);
	int status;

	if (!check_privilege(adapter, MAX_PRIVILEGES))
		return -EOPNOTSUPP;

	status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
						   data);
	if (status)
		goto err;

	if (eeprom->offset + eeprom->len > PAGE_DATA_LEN) {
		status = be_cmd_read_port_transceiver_data(adapter,
							   TR_PAGE_A2,
							   data +
							   PAGE_DATA_LEN);
		if (status)
			goto err;
	}
	if (eeprom->offset)
		memcpy(data, data + eeprom->offset, eeprom->len);
err:
	return be_cmd_status(status);
}

1288
const struct ethtool_ops be_ethtool_ops = {
S
Sathya Perla 已提交
1289 1290
	.get_settings = be_get_settings,
	.get_drvinfo = be_get_drvinfo,
1291 1292
	.get_wol = be_get_wol,
	.set_wol = be_set_wol,
S
Sathya Perla 已提交
1293
	.get_link = ethtool_op_get_link,
1294 1295
	.get_eeprom_len = be_get_eeprom_len,
	.get_eeprom = be_read_eeprom,
S
Sathya Perla 已提交
1296 1297 1298 1299 1300 1301
	.get_coalesce = be_get_coalesce,
	.set_coalesce = be_set_coalesce,
	.get_ringparam = be_get_ringparam,
	.get_pauseparam = be_get_pauseparam,
	.set_pauseparam = be_set_pauseparam,
	.get_strings = be_get_stat_strings,
1302
	.set_phys_id = be_set_phys_id,
1303
	.set_dump = be_set_dump,
1304 1305
	.get_msglevel = be_get_msg_level,
	.set_msglevel = be_set_msg_level,
1306
	.get_sset_count = be_get_sset_count,
S
Sathya Perla 已提交
1307
	.get_ethtool_stats = be_get_ethtool_stats,
1308 1309
	.get_regs_len = be_get_reg_len,
	.get_regs = be_get_regs,
1310
	.flash_device = be_do_flash,
1311
	.self_test = be_self_test,
1312 1313
	.get_rxnfc = be_get_rxnfc,
	.set_rxnfc = be_set_rxnfc,
1314 1315 1316 1317
	.get_rxfh_indir_size = be_get_rxfh_indir_size,
	.get_rxfh_key_size = be_get_rxfh_key_size,
	.get_rxfh = be_get_rxfh,
	.set_rxfh = be_set_rxfh,
1318
	.get_channels = be_get_channels,
1319 1320 1321
	.set_channels = be_set_channels,
	.get_module_info = be_get_module_info,
	.get_module_eeprom = be_get_module_eeprom
S
Sathya Perla 已提交
1322
};