xref: /openbmc/linux/drivers/net/ethernet/emulex/benet/be_ethtool.c (revision 029f7f3b8701cc7aca8bdb31f0c7edd6a479e357)
1 /*
2  * Copyright (C) 2005 - 2015 Emulex
3  * All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License version 2
7  * as published by the Free Software Foundation.  The full GNU General
8  * Public License is included in this distribution in the file called COPYING.
9  *
10  * Contact Information:
11  * linux-drivers@emulex.com
12  *
13  * Emulex
14  * 3333 Susan Street
15  * Costa Mesa, CA 92626
16  */
17 
18 #include "be.h"
19 #include "be_cmds.h"
20 #include <linux/ethtool.h>
21 
22 struct be_ethtool_stat {
23 	char desc[ETH_GSTRING_LEN];
24 	int type;
25 	int size;
26 	int offset;
27 };
28 
29 enum {DRVSTAT_TX, DRVSTAT_RX, DRVSTAT};
30 #define FIELDINFO(_struct, field) FIELD_SIZEOF(_struct, field), \
31 					offsetof(_struct, field)
32 #define DRVSTAT_TX_INFO(field)	#field, DRVSTAT_TX,\
33 					FIELDINFO(struct be_tx_stats, field)
34 #define DRVSTAT_RX_INFO(field)	#field, DRVSTAT_RX,\
35 					FIELDINFO(struct be_rx_stats, field)
36 #define	DRVSTAT_INFO(field)	#field, DRVSTAT,\
37 					FIELDINFO(struct be_drv_stats, field)
38 
39 static const struct be_ethtool_stat et_stats[] = {
40 	{DRVSTAT_INFO(rx_crc_errors)},
41 	{DRVSTAT_INFO(rx_alignment_symbol_errors)},
42 	{DRVSTAT_INFO(rx_pause_frames)},
43 	{DRVSTAT_INFO(rx_control_frames)},
44 	/* Received packets dropped when the Ethernet length field
45 	 * is not equal to the actual Ethernet data length.
46 	 */
47 	{DRVSTAT_INFO(rx_in_range_errors)},
48 	/* Received packets dropped when their length field is >= 1501 bytes
49 	 * and <= 1535 bytes.
50 	 */
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 	/* Received packets dropped when they don't pass the unicast or
55 	 * multicast address filtering.
56 	 */
57 	{DRVSTAT_INFO(rx_address_filtered)},
58 	/* Received packets dropped when IP packet length field is less than
59 	 * the IP header length field.
60 	 */
61 	{DRVSTAT_INFO(rx_dropped_too_small)},
62 	/* Received packets dropped when IP length field is greater than
63 	 * the actual packet length.
64 	 */
65 	{DRVSTAT_INFO(rx_dropped_too_short)},
66 	/* Received packets dropped when the IP header length field is less
67 	 * than 5.
68 	 */
69 	{DRVSTAT_INFO(rx_dropped_header_too_small)},
70 	/* Received packets dropped when the TCP header length field is less
71 	 * than 5 or the TCP header length + IP header length is more
72 	 * than IP packet length.
73 	 */
74 	{DRVSTAT_INFO(rx_dropped_tcp_length)},
75 	{DRVSTAT_INFO(rx_dropped_runt)},
76 	/* Number of received packets dropped when a fifo for descriptors going
77 	 * into the packet demux block overflows. In normal operation, this
78 	 * fifo must never overflow.
79 	 */
80 	{DRVSTAT_INFO(rxpp_fifo_overflow_drop)},
81 	/* Received packets dropped when the RX block runs out of space in
82 	 * one of its input FIFOs. This could happen due a long burst of
83 	 * minimum-sized (64b) frames in the receive path.
84 	 * This counter may also be erroneously incremented rarely.
85 	 */
86 	{DRVSTAT_INFO(rx_input_fifo_overflow_drop)},
87 	{DRVSTAT_INFO(rx_ip_checksum_errs)},
88 	{DRVSTAT_INFO(rx_tcp_checksum_errs)},
89 	{DRVSTAT_INFO(rx_udp_checksum_errs)},
90 	{DRVSTAT_INFO(tx_pauseframes)},
91 	{DRVSTAT_INFO(tx_controlframes)},
92 	{DRVSTAT_INFO(rx_priority_pause_frames)},
93 	{DRVSTAT_INFO(tx_priority_pauseframes)},
94 	/* Received packets dropped when an internal fifo going into
95 	 * main packet buffer tank (PMEM) overflows.
96 	 */
97 	{DRVSTAT_INFO(pmem_fifo_overflow_drop)},
98 	{DRVSTAT_INFO(jabber_events)},
99 	/* Received packets dropped due to lack of available HW packet buffers
100 	 * used to temporarily hold the received packets.
101 	 */
102 	{DRVSTAT_INFO(rx_drops_no_pbuf)},
103 	/* Received packets dropped due to input receive buffer
104 	 * descriptor fifo overflowing.
105 	 */
106 	{DRVSTAT_INFO(rx_drops_no_erx_descr)},
107 	/* Packets dropped because the internal FIFO to the offloaded TCP
108 	 * receive processing block is full. This could happen only for
109 	 * offloaded iSCSI or FCoE trarffic.
110 	 */
111 	{DRVSTAT_INFO(rx_drops_no_tpre_descr)},
112 	/* Received packets dropped when they need more than 8
113 	 * receive buffers. This cannot happen as the driver configures
114 	 * 2048 byte receive buffers.
115 	 */
116 	{DRVSTAT_INFO(rx_drops_too_many_frags)},
117 	{DRVSTAT_INFO(forwarded_packets)},
118 	/* Received packets dropped when the frame length
119 	 * is more than 9018 bytes
120 	 */
121 	{DRVSTAT_INFO(rx_drops_mtu)},
122 	/* Number of dma mapping errors */
123 	{DRVSTAT_INFO(dma_map_errors)},
124 	/* Number of packets dropped due to random early drop function */
125 	{DRVSTAT_INFO(eth_red_drops)},
126 	{DRVSTAT_INFO(rx_roce_bytes_lsd)},
127 	{DRVSTAT_INFO(rx_roce_bytes_msd)},
128 	{DRVSTAT_INFO(rx_roce_frames)},
129 	{DRVSTAT_INFO(roce_drops_payload_len)},
130 	{DRVSTAT_INFO(roce_drops_crc)}
131 };
132 
133 #define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)
134 
135 /* Stats related to multi RX queues: get_stats routine assumes bytes, pkts
136  * are first and second members respectively.
137  */
138 static const struct be_ethtool_stat et_rx_stats[] = {
139 	{DRVSTAT_RX_INFO(rx_bytes)},/* If moving this member see above note */
140 	{DRVSTAT_RX_INFO(rx_pkts)}, /* If moving this member see above note */
141 	{DRVSTAT_RX_INFO(rx_vxlan_offload_pkts)},
142 	{DRVSTAT_RX_INFO(rx_compl)},
143 	{DRVSTAT_RX_INFO(rx_compl_err)},
144 	{DRVSTAT_RX_INFO(rx_mcast_pkts)},
145 	/* Number of page allocation failures while posting receive buffers
146 	 * to HW.
147 	 */
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 	/* Received packets dropped due to lack of available fetched buffers
152 	 * posted by the driver.
153 	 */
154 	{DRVSTAT_RX_INFO(rx_drops_no_frags)}
155 };
156 
157 #define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats))
158 
159 /* Stats related to multi TX queues: get_stats routine assumes compl is the
160  * first member
161  */
162 static const struct be_ethtool_stat et_tx_stats[] = {
163 	{DRVSTAT_TX_INFO(tx_compl)}, /* If moving this member see above note */
164 	/* This counter is incremented when the HW encounters an error while
165 	 * parsing the packet header of an outgoing TX request. This counter is
166 	 * applicable only for BE2, BE3 and Skyhawk based adapters.
167 	 */
168 	{DRVSTAT_TX_INFO(tx_hdr_parse_err)},
169 	/* This counter is incremented when an error occurs in the DMA
170 	 * operation associated with the TX request from the host to the device.
171 	 */
172 	{DRVSTAT_TX_INFO(tx_dma_err)},
173 	/* This counter is incremented when MAC or VLAN spoof checking is
174 	 * enabled on the interface and the TX request fails the spoof check
175 	 * in HW.
176 	 */
177 	{DRVSTAT_TX_INFO(tx_spoof_check_err)},
178 	/* This counter is incremented when the HW encounters an error while
179 	 * performing TSO offload. This counter is applicable only for Lancer
180 	 * adapters.
181 	 */
182 	{DRVSTAT_TX_INFO(tx_tso_err)},
183 	/* This counter is incremented when the HW detects Q-in-Q style VLAN
184 	 * tagging in a packet and such tagging is not expected on the outgoing
185 	 * interface. This counter is applicable only for Lancer adapters.
186 	 */
187 	{DRVSTAT_TX_INFO(tx_qinq_err)},
188 	/* This counter is incremented when the HW detects parity errors in the
189 	 * packet data. This counter is applicable only for Lancer adapters.
190 	 */
191 	{DRVSTAT_TX_INFO(tx_internal_parity_err)},
192 	{DRVSTAT_TX_INFO(tx_bytes)},
193 	{DRVSTAT_TX_INFO(tx_pkts)},
194 	{DRVSTAT_TX_INFO(tx_vxlan_offload_pkts)},
195 	/* Number of skbs queued for trasmission by the driver */
196 	{DRVSTAT_TX_INFO(tx_reqs)},
197 	/* Number of times the TX queue was stopped due to lack
198 	 * of spaces in the TXQ.
199 	 */
200 	{DRVSTAT_TX_INFO(tx_stops)},
201 	/* Pkts dropped in the driver's transmit path */
202 	{DRVSTAT_TX_INFO(tx_drv_drops)}
203 };
204 
205 #define ETHTOOL_TXSTATS_NUM (ARRAY_SIZE(et_tx_stats))
206 
207 static const char et_self_tests[][ETH_GSTRING_LEN] = {
208 	"MAC Loopback test",
209 	"PHY Loopback test",
210 	"External Loopback test",
211 	"DDR DMA test",
212 	"Link test"
213 };
214 
215 #define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests)
216 #define BE_MAC_LOOPBACK 0x0
217 #define BE_PHY_LOOPBACK 0x1
218 #define BE_ONE_PORT_EXT_LOOPBACK 0x2
219 #define BE_NO_LOOPBACK 0xff
220 
221 static void be_get_drvinfo(struct net_device *netdev,
222 			   struct ethtool_drvinfo *drvinfo)
223 {
224 	struct be_adapter *adapter = netdev_priv(netdev);
225 
226 	strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
227 	strlcpy(drvinfo->version, DRV_VER, sizeof(drvinfo->version));
228 	if (!memcmp(adapter->fw_ver, adapter->fw_on_flash, FW_VER_LEN))
229 		strlcpy(drvinfo->fw_version, adapter->fw_ver,
230 			sizeof(drvinfo->fw_version));
231 	else
232 		snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
233 			 "%s [%s]", adapter->fw_ver, adapter->fw_on_flash);
234 
235 	strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
236 		sizeof(drvinfo->bus_info));
237 }
238 
239 static u32 lancer_cmd_get_file_len(struct be_adapter *adapter, u8 *file_name)
240 {
241 	u32 data_read = 0, eof;
242 	u8 addn_status;
243 	struct be_dma_mem data_len_cmd;
244 
245 	memset(&data_len_cmd, 0, sizeof(data_len_cmd));
246 	/* data_offset and data_size should be 0 to get reg len */
247 	lancer_cmd_read_object(adapter, &data_len_cmd, 0, 0, file_name,
248 			       &data_read, &eof, &addn_status);
249 
250 	return data_read;
251 }
252 
253 static int lancer_cmd_read_file(struct be_adapter *adapter, u8 *file_name,
254 				u32 buf_len, void *buf)
255 {
256 	struct be_dma_mem read_cmd;
257 	u32 read_len = 0, total_read_len = 0, chunk_size;
258 	u32 eof = 0;
259 	u8 addn_status;
260 	int status = 0;
261 
262 	read_cmd.size = LANCER_READ_FILE_CHUNK;
263 	read_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, read_cmd.size,
264 					  &read_cmd.dma, GFP_ATOMIC);
265 
266 	if (!read_cmd.va) {
267 		dev_err(&adapter->pdev->dev,
268 			"Memory allocation failure while reading dump\n");
269 		return -ENOMEM;
270 	}
271 
272 	while ((total_read_len < buf_len) && !eof) {
273 		chunk_size = min_t(u32, (buf_len - total_read_len),
274 				   LANCER_READ_FILE_CHUNK);
275 		chunk_size = ALIGN(chunk_size, 4);
276 		status = lancer_cmd_read_object(adapter, &read_cmd, chunk_size,
277 						total_read_len, file_name,
278 						&read_len, &eof, &addn_status);
279 		if (!status) {
280 			memcpy(buf + total_read_len, read_cmd.va, read_len);
281 			total_read_len += read_len;
282 			eof &= LANCER_READ_FILE_EOF_MASK;
283 		} else {
284 			status = -EIO;
285 			break;
286 		}
287 	}
288 	dma_free_coherent(&adapter->pdev->dev, read_cmd.size, read_cmd.va,
289 			  read_cmd.dma);
290 
291 	return status;
292 }
293 
294 static int be_get_reg_len(struct net_device *netdev)
295 {
296 	struct be_adapter *adapter = netdev_priv(netdev);
297 	u32 log_size = 0;
298 
299 	if (!check_privilege(adapter, MAX_PRIVILEGES))
300 		return 0;
301 
302 	if (be_physfn(adapter)) {
303 		if (lancer_chip(adapter))
304 			log_size = lancer_cmd_get_file_len(adapter,
305 							   LANCER_FW_DUMP_FILE);
306 		else
307 			be_cmd_get_reg_len(adapter, &log_size);
308 	}
309 	return log_size;
310 }
311 
312 static void
313 be_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *buf)
314 {
315 	struct be_adapter *adapter = netdev_priv(netdev);
316 
317 	if (be_physfn(adapter)) {
318 		memset(buf, 0, regs->len);
319 		if (lancer_chip(adapter))
320 			lancer_cmd_read_file(adapter, LANCER_FW_DUMP_FILE,
321 					     regs->len, buf);
322 		else
323 			be_cmd_get_regs(adapter, regs->len, buf);
324 	}
325 }
326 
327 static int be_get_coalesce(struct net_device *netdev,
328 			   struct ethtool_coalesce *et)
329 {
330 	struct be_adapter *adapter = netdev_priv(netdev);
331 	struct be_aic_obj *aic = &adapter->aic_obj[0];
332 
333 	et->rx_coalesce_usecs = aic->prev_eqd;
334 	et->rx_coalesce_usecs_high = aic->max_eqd;
335 	et->rx_coalesce_usecs_low = aic->min_eqd;
336 
337 	et->tx_coalesce_usecs = aic->prev_eqd;
338 	et->tx_coalesce_usecs_high = aic->max_eqd;
339 	et->tx_coalesce_usecs_low = aic->min_eqd;
340 
341 	et->use_adaptive_rx_coalesce = aic->enable;
342 	et->use_adaptive_tx_coalesce = aic->enable;
343 
344 	return 0;
345 }
346 
347 /* TX attributes are ignored. Only RX attributes are considered
348  * eqd cmd is issued in the worker thread.
349  */
350 static int be_set_coalesce(struct net_device *netdev,
351 			   struct ethtool_coalesce *et)
352 {
353 	struct be_adapter *adapter = netdev_priv(netdev);
354 	struct be_aic_obj *aic = &adapter->aic_obj[0];
355 	struct be_eq_obj *eqo;
356 	int i;
357 
358 	for_all_evt_queues(adapter, eqo, i) {
359 		aic->enable = et->use_adaptive_rx_coalesce;
360 		aic->max_eqd = min(et->rx_coalesce_usecs_high, BE_MAX_EQD);
361 		aic->min_eqd = min(et->rx_coalesce_usecs_low, aic->max_eqd);
362 		aic->et_eqd = min(et->rx_coalesce_usecs, aic->max_eqd);
363 		aic->et_eqd = max(aic->et_eqd, aic->min_eqd);
364 		aic++;
365 	}
366 
367 	/* For Skyhawk, the EQD setting happens via EQ_DB when AIC is enabled.
368 	 * When AIC is disabled, persistently force set EQD value via the
369 	 * FW cmd, so that we don't have to calculate the delay multiplier
370 	 * encode value each time EQ_DB is rung
371 	 */
372 	if (!et->use_adaptive_rx_coalesce && skyhawk_chip(adapter))
373 		be_eqd_update(adapter, true);
374 
375 	return 0;
376 }
377 
378 static void be_get_ethtool_stats(struct net_device *netdev,
379 				 struct ethtool_stats *stats, uint64_t *data)
380 {
381 	struct be_adapter *adapter = netdev_priv(netdev);
382 	struct be_rx_obj *rxo;
383 	struct be_tx_obj *txo;
384 	void *p;
385 	unsigned int i, j, base = 0, start;
386 
387 	for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
388 		p = (u8 *)&adapter->drv_stats + et_stats[i].offset;
389 		data[i] = *(u32 *)p;
390 	}
391 	base += ETHTOOL_STATS_NUM;
392 
393 	for_all_rx_queues(adapter, rxo, j) {
394 		struct be_rx_stats *stats = rx_stats(rxo);
395 
396 		do {
397 			start = u64_stats_fetch_begin_irq(&stats->sync);
398 			data[base] = stats->rx_bytes;
399 			data[base + 1] = stats->rx_pkts;
400 		} while (u64_stats_fetch_retry_irq(&stats->sync, start));
401 
402 		for (i = 2; i < ETHTOOL_RXSTATS_NUM; i++) {
403 			p = (u8 *)stats + et_rx_stats[i].offset;
404 			data[base + i] = *(u32 *)p;
405 		}
406 		base += ETHTOOL_RXSTATS_NUM;
407 	}
408 
409 	for_all_tx_queues(adapter, txo, j) {
410 		struct be_tx_stats *stats = tx_stats(txo);
411 
412 		do {
413 			start = u64_stats_fetch_begin_irq(&stats->sync_compl);
414 			data[base] = stats->tx_compl;
415 		} while (u64_stats_fetch_retry_irq(&stats->sync_compl, start));
416 
417 		do {
418 			start = u64_stats_fetch_begin_irq(&stats->sync);
419 			for (i = 1; i < ETHTOOL_TXSTATS_NUM; i++) {
420 				p = (u8 *)stats + et_tx_stats[i].offset;
421 				data[base + i] =
422 					(et_tx_stats[i].size == sizeof(u64)) ?
423 						*(u64 *)p : *(u32 *)p;
424 			}
425 		} while (u64_stats_fetch_retry_irq(&stats->sync, start));
426 		base += ETHTOOL_TXSTATS_NUM;
427 	}
428 }
429 
430 static void be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
431 				uint8_t *data)
432 {
433 	struct be_adapter *adapter = netdev_priv(netdev);
434 	int i, j;
435 
436 	switch (stringset) {
437 	case ETH_SS_STATS:
438 		for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
439 			memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
440 			data += ETH_GSTRING_LEN;
441 		}
442 		for (i = 0; i < adapter->num_rx_qs; i++) {
443 			for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) {
444 				sprintf(data, "rxq%d: %s", i,
445 					et_rx_stats[j].desc);
446 				data += ETH_GSTRING_LEN;
447 			}
448 		}
449 		for (i = 0; i < adapter->num_tx_qs; i++) {
450 			for (j = 0; j < ETHTOOL_TXSTATS_NUM; j++) {
451 				sprintf(data, "txq%d: %s", i,
452 					et_tx_stats[j].desc);
453 				data += ETH_GSTRING_LEN;
454 			}
455 		}
456 		break;
457 	case ETH_SS_TEST:
458 		for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
459 			memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
460 			data += ETH_GSTRING_LEN;
461 		}
462 		break;
463 	}
464 }
465 
466 static int be_get_sset_count(struct net_device *netdev, int stringset)
467 {
468 	struct be_adapter *adapter = netdev_priv(netdev);
469 
470 	switch (stringset) {
471 	case ETH_SS_TEST:
472 		return ETHTOOL_TESTS_NUM;
473 	case ETH_SS_STATS:
474 		return ETHTOOL_STATS_NUM +
475 			adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM +
476 			adapter->num_tx_qs * ETHTOOL_TXSTATS_NUM;
477 	default:
478 		return -EINVAL;
479 	}
480 }
481 
482 static u32 be_get_port_type(struct be_adapter *adapter)
483 {
484 	u32 port;
485 
486 	switch (adapter->phy.interface_type) {
487 	case PHY_TYPE_BASET_1GB:
488 	case PHY_TYPE_BASEX_1GB:
489 	case PHY_TYPE_SGMII:
490 		port = PORT_TP;
491 		break;
492 	case PHY_TYPE_SFP_PLUS_10GB:
493 		if (adapter->phy.cable_type & SFP_PLUS_COPPER_CABLE)
494 			port = PORT_DA;
495 		else
496 			port = PORT_FIBRE;
497 		break;
498 	case PHY_TYPE_QSFP:
499 		if (adapter->phy.cable_type & QSFP_PLUS_CR4_CABLE)
500 			port = PORT_DA;
501 		else
502 			port = PORT_FIBRE;
503 		break;
504 	case PHY_TYPE_XFP_10GB:
505 	case PHY_TYPE_SFP_1GB:
506 		port = PORT_FIBRE;
507 		break;
508 	case PHY_TYPE_BASET_10GB:
509 		port = PORT_TP;
510 		break;
511 	default:
512 		port = PORT_OTHER;
513 	}
514 
515 	return port;
516 }
517 
518 static u32 convert_to_et_setting(struct be_adapter *adapter, u32 if_speeds)
519 {
520 	u32 val = 0;
521 
522 	switch (adapter->phy.interface_type) {
523 	case PHY_TYPE_BASET_1GB:
524 	case PHY_TYPE_BASEX_1GB:
525 	case PHY_TYPE_SGMII:
526 		val |= SUPPORTED_TP;
527 		if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
528 			val |= SUPPORTED_1000baseT_Full;
529 		if (if_speeds & BE_SUPPORTED_SPEED_100MBPS)
530 			val |= SUPPORTED_100baseT_Full;
531 		if (if_speeds & BE_SUPPORTED_SPEED_10MBPS)
532 			val |= SUPPORTED_10baseT_Full;
533 		break;
534 	case PHY_TYPE_KX4_10GB:
535 		val |= SUPPORTED_Backplane;
536 		if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
537 			val |= SUPPORTED_1000baseKX_Full;
538 		if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
539 			val |= SUPPORTED_10000baseKX4_Full;
540 		break;
541 	case PHY_TYPE_KR2_20GB:
542 		val |= SUPPORTED_Backplane;
543 		if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
544 			val |= SUPPORTED_10000baseKR_Full;
545 		if (if_speeds & BE_SUPPORTED_SPEED_20GBPS)
546 			val |= SUPPORTED_20000baseKR2_Full;
547 		break;
548 	case PHY_TYPE_KR_10GB:
549 		val |= SUPPORTED_Backplane |
550 				SUPPORTED_10000baseKR_Full;
551 		break;
552 	case PHY_TYPE_KR4_40GB:
553 		val |= SUPPORTED_Backplane;
554 		if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
555 			val |= SUPPORTED_10000baseKR_Full;
556 		if (if_speeds & BE_SUPPORTED_SPEED_40GBPS)
557 			val |= SUPPORTED_40000baseKR4_Full;
558 		break;
559 	case PHY_TYPE_QSFP:
560 		if (if_speeds & BE_SUPPORTED_SPEED_40GBPS) {
561 			switch (adapter->phy.cable_type) {
562 			case QSFP_PLUS_CR4_CABLE:
563 				val |= SUPPORTED_40000baseCR4_Full;
564 				break;
565 			case QSFP_PLUS_LR4_CABLE:
566 				val |= SUPPORTED_40000baseLR4_Full;
567 				break;
568 			default:
569 				val |= SUPPORTED_40000baseSR4_Full;
570 				break;
571 			}
572 		}
573 	case PHY_TYPE_SFP_PLUS_10GB:
574 	case PHY_TYPE_XFP_10GB:
575 	case PHY_TYPE_SFP_1GB:
576 		val |= SUPPORTED_FIBRE;
577 		if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
578 			val |= SUPPORTED_10000baseT_Full;
579 		if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
580 			val |= SUPPORTED_1000baseT_Full;
581 		break;
582 	case PHY_TYPE_BASET_10GB:
583 		val |= SUPPORTED_TP;
584 		if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
585 			val |= SUPPORTED_10000baseT_Full;
586 		if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
587 			val |= SUPPORTED_1000baseT_Full;
588 		if (if_speeds & BE_SUPPORTED_SPEED_100MBPS)
589 			val |= SUPPORTED_100baseT_Full;
590 		break;
591 	default:
592 		val |= SUPPORTED_TP;
593 	}
594 
595 	return val;
596 }
597 
598 bool be_pause_supported(struct be_adapter *adapter)
599 {
600 	return (adapter->phy.interface_type == PHY_TYPE_SFP_PLUS_10GB ||
601 		adapter->phy.interface_type == PHY_TYPE_XFP_10GB) ?
602 		false : true;
603 }
604 
605 static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
606 {
607 	struct be_adapter *adapter = netdev_priv(netdev);
608 	u8 link_status;
609 	u16 link_speed = 0;
610 	int status;
611 	u32 auto_speeds;
612 	u32 fixed_speeds;
613 
614 	if (adapter->phy.link_speed < 0) {
615 		status = be_cmd_link_status_query(adapter, &link_speed,
616 						  &link_status, 0);
617 		if (!status)
618 			be_link_status_update(adapter, link_status);
619 		ethtool_cmd_speed_set(ecmd, link_speed);
620 
621 		status = be_cmd_get_phy_info(adapter);
622 		if (!status) {
623 			auto_speeds = adapter->phy.auto_speeds_supported;
624 			fixed_speeds = adapter->phy.fixed_speeds_supported;
625 
626 			be_cmd_query_cable_type(adapter);
627 
628 			ecmd->supported =
629 				convert_to_et_setting(adapter,
630 						      auto_speeds |
631 						      fixed_speeds);
632 			ecmd->advertising =
633 				convert_to_et_setting(adapter, auto_speeds);
634 
635 			ecmd->port = be_get_port_type(adapter);
636 
637 			if (adapter->phy.auto_speeds_supported) {
638 				ecmd->supported |= SUPPORTED_Autoneg;
639 				ecmd->autoneg = AUTONEG_ENABLE;
640 				ecmd->advertising |= ADVERTISED_Autoneg;
641 			}
642 
643 			ecmd->supported |= SUPPORTED_Pause;
644 			if (be_pause_supported(adapter))
645 				ecmd->advertising |= ADVERTISED_Pause;
646 
647 			switch (adapter->phy.interface_type) {
648 			case PHY_TYPE_KR_10GB:
649 			case PHY_TYPE_KX4_10GB:
650 				ecmd->transceiver = XCVR_INTERNAL;
651 				break;
652 			default:
653 				ecmd->transceiver = XCVR_EXTERNAL;
654 				break;
655 			}
656 		} else {
657 			ecmd->port = PORT_OTHER;
658 			ecmd->autoneg = AUTONEG_DISABLE;
659 			ecmd->transceiver = XCVR_DUMMY1;
660 		}
661 
662 		/* Save for future use */
663 		adapter->phy.link_speed = ethtool_cmd_speed(ecmd);
664 		adapter->phy.port_type = ecmd->port;
665 		adapter->phy.transceiver = ecmd->transceiver;
666 		adapter->phy.autoneg = ecmd->autoneg;
667 		adapter->phy.advertising = ecmd->advertising;
668 		adapter->phy.supported = ecmd->supported;
669 	} else {
670 		ethtool_cmd_speed_set(ecmd, adapter->phy.link_speed);
671 		ecmd->port = adapter->phy.port_type;
672 		ecmd->transceiver = adapter->phy.transceiver;
673 		ecmd->autoneg = adapter->phy.autoneg;
674 		ecmd->advertising = adapter->phy.advertising;
675 		ecmd->supported = adapter->phy.supported;
676 	}
677 
678 	ecmd->duplex = netif_carrier_ok(netdev) ? DUPLEX_FULL : DUPLEX_UNKNOWN;
679 	ecmd->phy_address = adapter->port_num;
680 
681 	return 0;
682 }
683 
684 static void be_get_ringparam(struct net_device *netdev,
685 			     struct ethtool_ringparam *ring)
686 {
687 	struct be_adapter *adapter = netdev_priv(netdev);
688 
689 	ring->rx_max_pending = adapter->rx_obj[0].q.len;
690 	ring->rx_pending = adapter->rx_obj[0].q.len;
691 	ring->tx_max_pending = adapter->tx_obj[0].q.len;
692 	ring->tx_pending = adapter->tx_obj[0].q.len;
693 }
694 
695 static void
696 be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
697 {
698 	struct be_adapter *adapter = netdev_priv(netdev);
699 
700 	be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
701 	ecmd->autoneg = adapter->phy.fc_autoneg;
702 }
703 
704 static int
705 be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
706 {
707 	struct be_adapter *adapter = netdev_priv(netdev);
708 	int status;
709 
710 	if (ecmd->autoneg != adapter->phy.fc_autoneg)
711 		return -EINVAL;
712 
713 	status = be_cmd_set_flow_control(adapter, ecmd->tx_pause,
714 					 ecmd->rx_pause);
715 	if (status) {
716 		dev_warn(&adapter->pdev->dev, "Pause param set failed\n");
717 		return be_cmd_status(status);
718 	}
719 
720 	adapter->tx_fc = ecmd->tx_pause;
721 	adapter->rx_fc = ecmd->rx_pause;
722 	return 0;
723 }
724 
725 static int be_set_phys_id(struct net_device *netdev,
726 			  enum ethtool_phys_id_state state)
727 {
728 	struct be_adapter *adapter = netdev_priv(netdev);
729 
730 	switch (state) {
731 	case ETHTOOL_ID_ACTIVE:
732 		be_cmd_get_beacon_state(adapter, adapter->hba_port_num,
733 					&adapter->beacon_state);
734 		return 1;	/* cycle on/off once per second */
735 
736 	case ETHTOOL_ID_ON:
737 		be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
738 					BEACON_STATE_ENABLED);
739 		break;
740 
741 	case ETHTOOL_ID_OFF:
742 		be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
743 					BEACON_STATE_DISABLED);
744 		break;
745 
746 	case ETHTOOL_ID_INACTIVE:
747 		be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
748 					adapter->beacon_state);
749 	}
750 
751 	return 0;
752 }
753 
754 static int be_set_dump(struct net_device *netdev, struct ethtool_dump *dump)
755 {
756 	struct be_adapter *adapter = netdev_priv(netdev);
757 	struct device *dev = &adapter->pdev->dev;
758 	int status;
759 
760 	if (!lancer_chip(adapter) ||
761 	    !check_privilege(adapter, MAX_PRIVILEGES))
762 		return -EOPNOTSUPP;
763 
764 	switch (dump->flag) {
765 	case LANCER_INITIATE_FW_DUMP:
766 		status = lancer_initiate_dump(adapter);
767 		if (!status)
768 			dev_info(dev, "FW dump initiated successfully\n");
769 		break;
770 	case LANCER_DELETE_FW_DUMP:
771 		status = lancer_delete_dump(adapter);
772 		if (!status)
773 			dev_info(dev, "FW dump deleted successfully\n");
774 	break;
775 	default:
776 		dev_err(dev, "Invalid dump level: 0x%x\n", dump->flag);
777 		return -EINVAL;
778 	}
779 	return status;
780 }
781 
782 static void be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
783 {
784 	struct be_adapter *adapter = netdev_priv(netdev);
785 
786 	if (adapter->wol_cap & BE_WOL_CAP) {
787 		wol->supported |= WAKE_MAGIC;
788 		if (adapter->wol_en)
789 			wol->wolopts |= WAKE_MAGIC;
790 	} else {
791 		wol->wolopts = 0;
792 	}
793 	memset(&wol->sopass, 0, sizeof(wol->sopass));
794 }
795 
796 static int be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
797 {
798 	struct be_adapter *adapter = netdev_priv(netdev);
799 
800 	if (wol->wolopts & ~WAKE_MAGIC)
801 		return -EOPNOTSUPP;
802 
803 	if (!(adapter->wol_cap & BE_WOL_CAP)) {
804 		dev_warn(&adapter->pdev->dev, "WOL not supported\n");
805 		return -EOPNOTSUPP;
806 	}
807 
808 	if (wol->wolopts & WAKE_MAGIC)
809 		adapter->wol_en = true;
810 	else
811 		adapter->wol_en = false;
812 
813 	return 0;
814 }
815 
816 static int be_test_ddr_dma(struct be_adapter *adapter)
817 {
818 	int ret, i;
819 	struct be_dma_mem ddrdma_cmd;
820 	static const u64 pattern[2] = {
821 		0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
822 	};
823 
824 	ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
825 	ddrdma_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev,
826 					    ddrdma_cmd.size, &ddrdma_cmd.dma,
827 					    GFP_KERNEL);
828 	if (!ddrdma_cmd.va)
829 		return -ENOMEM;
830 
831 	for (i = 0; i < 2; i++) {
832 		ret = be_cmd_ddr_dma_test(adapter, pattern[i],
833 					  4096, &ddrdma_cmd);
834 		if (ret != 0)
835 			goto err;
836 	}
837 
838 err:
839 	dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va,
840 			  ddrdma_cmd.dma);
841 	return be_cmd_status(ret);
842 }
843 
844 static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
845 			    u64 *status)
846 {
847 	int ret;
848 
849 	ret = be_cmd_set_loopback(adapter, adapter->hba_port_num,
850 				  loopback_type, 1);
851 	if (ret)
852 		return ret;
853 
854 	*status = be_cmd_loopback_test(adapter, adapter->hba_port_num,
855 				       loopback_type, 1500, 2, 0xabc);
856 
857 	ret = be_cmd_set_loopback(adapter, adapter->hba_port_num,
858 				  BE_NO_LOOPBACK, 1);
859 	if (ret)
860 		return ret;
861 
862 	return *status;
863 }
864 
865 static void be_self_test(struct net_device *netdev, struct ethtool_test *test,
866 			 u64 *data)
867 {
868 	struct be_adapter *adapter = netdev_priv(netdev);
869 	int status;
870 	u8 link_status = 0;
871 
872 	if (adapter->function_caps & BE_FUNCTION_CAPS_SUPER_NIC) {
873 		dev_err(&adapter->pdev->dev, "Self test not supported\n");
874 		test->flags |= ETH_TEST_FL_FAILED;
875 		return;
876 	}
877 
878 	memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
879 
880 	if (test->flags & ETH_TEST_FL_OFFLINE) {
881 		if (be_loopback_test(adapter, BE_MAC_LOOPBACK, &data[0]) != 0)
882 			test->flags |= ETH_TEST_FL_FAILED;
883 
884 		if (be_loopback_test(adapter, BE_PHY_LOOPBACK, &data[1]) != 0)
885 			test->flags |= ETH_TEST_FL_FAILED;
886 
887 		if (test->flags & ETH_TEST_FL_EXTERNAL_LB) {
888 			if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
889 					     &data[2]) != 0)
890 				test->flags |= ETH_TEST_FL_FAILED;
891 			test->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE;
892 		}
893 	}
894 
895 	if (!lancer_chip(adapter) && be_test_ddr_dma(adapter) != 0) {
896 		data[3] = 1;
897 		test->flags |= ETH_TEST_FL_FAILED;
898 	}
899 
900 	status = be_cmd_link_status_query(adapter, NULL, &link_status, 0);
901 	if (status) {
902 		test->flags |= ETH_TEST_FL_FAILED;
903 		data[4] = -1;
904 	} else if (!link_status) {
905 		test->flags |= ETH_TEST_FL_FAILED;
906 		data[4] = 1;
907 	}
908 }
909 
910 static int be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
911 {
912 	struct be_adapter *adapter = netdev_priv(netdev);
913 
914 	return be_load_fw(adapter, efl->data);
915 }
916 
917 static int be_get_eeprom_len(struct net_device *netdev)
918 {
919 	struct be_adapter *adapter = netdev_priv(netdev);
920 
921 	if (!check_privilege(adapter, MAX_PRIVILEGES))
922 		return 0;
923 
924 	if (lancer_chip(adapter)) {
925 		if (be_physfn(adapter))
926 			return lancer_cmd_get_file_len(adapter,
927 						       LANCER_VPD_PF_FILE);
928 		else
929 			return lancer_cmd_get_file_len(adapter,
930 						       LANCER_VPD_VF_FILE);
931 	} else {
932 		return BE_READ_SEEPROM_LEN;
933 	}
934 }
935 
936 static int be_read_eeprom(struct net_device *netdev,
937 			  struct ethtool_eeprom *eeprom, uint8_t *data)
938 {
939 	struct be_adapter *adapter = netdev_priv(netdev);
940 	struct be_dma_mem eeprom_cmd;
941 	struct be_cmd_resp_seeprom_read *resp;
942 	int status;
943 
944 	if (!eeprom->len)
945 		return -EINVAL;
946 
947 	if (lancer_chip(adapter)) {
948 		if (be_physfn(adapter))
949 			return lancer_cmd_read_file(adapter, LANCER_VPD_PF_FILE,
950 						    eeprom->len, data);
951 		else
952 			return lancer_cmd_read_file(adapter, LANCER_VPD_VF_FILE,
953 						    eeprom->len, data);
954 	}
955 
956 	eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
957 
958 	memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
959 	eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
960 	eeprom_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev,
961 					    eeprom_cmd.size, &eeprom_cmd.dma,
962 					    GFP_KERNEL);
963 
964 	if (!eeprom_cmd.va)
965 		return -ENOMEM;
966 
967 	status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
968 
969 	if (!status) {
970 		resp = eeprom_cmd.va;
971 		memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
972 	}
973 	dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va,
974 			  eeprom_cmd.dma);
975 
976 	return be_cmd_status(status);
977 }
978 
979 static u32 be_get_msg_level(struct net_device *netdev)
980 {
981 	struct be_adapter *adapter = netdev_priv(netdev);
982 
983 	return adapter->msg_enable;
984 }
985 
986 static void be_set_msg_level(struct net_device *netdev, u32 level)
987 {
988 	struct be_adapter *adapter = netdev_priv(netdev);
989 
990 	if (adapter->msg_enable == level)
991 		return;
992 
993 	if ((level & NETIF_MSG_HW) != (adapter->msg_enable & NETIF_MSG_HW))
994 		if (BEx_chip(adapter))
995 			be_cmd_set_fw_log_level(adapter, level & NETIF_MSG_HW ?
996 						FW_LOG_LEVEL_DEFAULT :
997 						FW_LOG_LEVEL_FATAL);
998 	adapter->msg_enable = level;
999 }
1000 
1001 static u64 be_get_rss_hash_opts(struct be_adapter *adapter, u64 flow_type)
1002 {
1003 	u64 data = 0;
1004 
1005 	switch (flow_type) {
1006 	case TCP_V4_FLOW:
1007 		if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV4)
1008 			data |= RXH_IP_DST | RXH_IP_SRC;
1009 		if (adapter->rss_info.rss_flags & RSS_ENABLE_TCP_IPV4)
1010 			data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1011 		break;
1012 	case UDP_V4_FLOW:
1013 		if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV4)
1014 			data |= RXH_IP_DST | RXH_IP_SRC;
1015 		if (adapter->rss_info.rss_flags & RSS_ENABLE_UDP_IPV4)
1016 			data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1017 		break;
1018 	case TCP_V6_FLOW:
1019 		if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV6)
1020 			data |= RXH_IP_DST | RXH_IP_SRC;
1021 		if (adapter->rss_info.rss_flags & RSS_ENABLE_TCP_IPV6)
1022 			data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1023 		break;
1024 	case UDP_V6_FLOW:
1025 		if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV6)
1026 			data |= RXH_IP_DST | RXH_IP_SRC;
1027 		if (adapter->rss_info.rss_flags & RSS_ENABLE_UDP_IPV6)
1028 			data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1029 		break;
1030 	}
1031 
1032 	return data;
1033 }
1034 
1035 static int be_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1036 			u32 *rule_locs)
1037 {
1038 	struct be_adapter *adapter = netdev_priv(netdev);
1039 
1040 	if (!be_multi_rxq(adapter)) {
1041 		dev_info(&adapter->pdev->dev,
1042 			 "ethtool::get_rxnfc: RX flow hashing is disabled\n");
1043 		return -EINVAL;
1044 	}
1045 
1046 	switch (cmd->cmd) {
1047 	case ETHTOOL_GRXFH:
1048 		cmd->data = be_get_rss_hash_opts(adapter, cmd->flow_type);
1049 		break;
1050 	case ETHTOOL_GRXRINGS:
1051 		cmd->data = adapter->num_rx_qs - 1;
1052 		break;
1053 	default:
1054 		return -EINVAL;
1055 	}
1056 
1057 	return 0;
1058 }
1059 
1060 static int be_set_rss_hash_opts(struct be_adapter *adapter,
1061 				struct ethtool_rxnfc *cmd)
1062 {
1063 	int status;
1064 	u32 rss_flags = adapter->rss_info.rss_flags;
1065 
1066 	if (cmd->data != L3_RSS_FLAGS &&
1067 	    cmd->data != (L3_RSS_FLAGS | L4_RSS_FLAGS))
1068 		return -EINVAL;
1069 
1070 	switch (cmd->flow_type) {
1071 	case TCP_V4_FLOW:
1072 		if (cmd->data == L3_RSS_FLAGS)
1073 			rss_flags &= ~RSS_ENABLE_TCP_IPV4;
1074 		else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1075 			rss_flags |= RSS_ENABLE_IPV4 |
1076 					RSS_ENABLE_TCP_IPV4;
1077 		break;
1078 	case TCP_V6_FLOW:
1079 		if (cmd->data == L3_RSS_FLAGS)
1080 			rss_flags &= ~RSS_ENABLE_TCP_IPV6;
1081 		else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1082 			rss_flags |= RSS_ENABLE_IPV6 |
1083 					RSS_ENABLE_TCP_IPV6;
1084 		break;
1085 	case UDP_V4_FLOW:
1086 		if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) &&
1087 		    BEx_chip(adapter))
1088 			return -EINVAL;
1089 
1090 		if (cmd->data == L3_RSS_FLAGS)
1091 			rss_flags &= ~RSS_ENABLE_UDP_IPV4;
1092 		else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1093 			rss_flags |= RSS_ENABLE_IPV4 |
1094 					RSS_ENABLE_UDP_IPV4;
1095 		break;
1096 	case UDP_V6_FLOW:
1097 		if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) &&
1098 		    BEx_chip(adapter))
1099 			return -EINVAL;
1100 
1101 		if (cmd->data == L3_RSS_FLAGS)
1102 			rss_flags &= ~RSS_ENABLE_UDP_IPV6;
1103 		else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1104 			rss_flags |= RSS_ENABLE_IPV6 |
1105 					RSS_ENABLE_UDP_IPV6;
1106 		break;
1107 	default:
1108 		return -EINVAL;
1109 	}
1110 
1111 	if (rss_flags == adapter->rss_info.rss_flags)
1112 		return 0;
1113 
1114 	status = be_cmd_rss_config(adapter, adapter->rss_info.rsstable,
1115 				   rss_flags, RSS_INDIR_TABLE_LEN,
1116 				   adapter->rss_info.rss_hkey);
1117 	if (!status)
1118 		adapter->rss_info.rss_flags = rss_flags;
1119 
1120 	return be_cmd_status(status);
1121 }
1122 
1123 static int be_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1124 {
1125 	struct be_adapter *adapter = netdev_priv(netdev);
1126 	int status = 0;
1127 
1128 	if (!be_multi_rxq(adapter)) {
1129 		dev_err(&adapter->pdev->dev,
1130 			"ethtool::set_rxnfc: RX flow hashing is disabled\n");
1131 		return -EINVAL;
1132 	}
1133 
1134 	switch (cmd->cmd) {
1135 	case ETHTOOL_SRXFH:
1136 		status = be_set_rss_hash_opts(adapter, cmd);
1137 		break;
1138 	default:
1139 		return -EINVAL;
1140 	}
1141 
1142 	return status;
1143 }
1144 
1145 static void be_get_channels(struct net_device *netdev,
1146 			    struct ethtool_channels *ch)
1147 {
1148 	struct be_adapter *adapter = netdev_priv(netdev);
1149 
1150 	ch->combined_count = adapter->num_evt_qs;
1151 	ch->max_combined = be_max_qs(adapter);
1152 }
1153 
1154 static int be_set_channels(struct net_device  *netdev,
1155 			   struct ethtool_channels *ch)
1156 {
1157 	struct be_adapter *adapter = netdev_priv(netdev);
1158 	int status;
1159 
1160 	if (ch->rx_count || ch->tx_count || ch->other_count ||
1161 	    !ch->combined_count || ch->combined_count > be_max_qs(adapter))
1162 		return -EINVAL;
1163 
1164 	adapter->cfg_num_qs = ch->combined_count;
1165 
1166 	status = be_update_queues(adapter);
1167 	return be_cmd_status(status);
1168 }
1169 
1170 static u32 be_get_rxfh_indir_size(struct net_device *netdev)
1171 {
1172 	return RSS_INDIR_TABLE_LEN;
1173 }
1174 
1175 static u32 be_get_rxfh_key_size(struct net_device *netdev)
1176 {
1177 	return RSS_HASH_KEY_LEN;
1178 }
1179 
1180 static int be_get_rxfh(struct net_device *netdev, u32 *indir, u8 *hkey,
1181 		       u8 *hfunc)
1182 {
1183 	struct be_adapter *adapter = netdev_priv(netdev);
1184 	int i;
1185 	struct rss_info *rss = &adapter->rss_info;
1186 
1187 	if (indir) {
1188 		for (i = 0; i < RSS_INDIR_TABLE_LEN; i++)
1189 			indir[i] = rss->rss_queue[i];
1190 	}
1191 
1192 	if (hkey)
1193 		memcpy(hkey, rss->rss_hkey, RSS_HASH_KEY_LEN);
1194 
1195 	if (hfunc)
1196 		*hfunc = ETH_RSS_HASH_TOP;
1197 
1198 	return 0;
1199 }
1200 
1201 static int be_set_rxfh(struct net_device *netdev, const u32 *indir,
1202 		       const u8 *hkey, const u8 hfunc)
1203 {
1204 	int rc = 0, i, j;
1205 	struct be_adapter *adapter = netdev_priv(netdev);
1206 	u8 rsstable[RSS_INDIR_TABLE_LEN];
1207 
1208 	/* We do not allow change in unsupported parameters */
1209 	if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1210 		return -EOPNOTSUPP;
1211 
1212 	if (indir) {
1213 		struct be_rx_obj *rxo;
1214 
1215 		for (i = 0; i < RSS_INDIR_TABLE_LEN; i++) {
1216 			j = indir[i];
1217 			rxo = &adapter->rx_obj[j];
1218 			rsstable[i] = rxo->rss_id;
1219 			adapter->rss_info.rss_queue[i] = j;
1220 		}
1221 	} else {
1222 		memcpy(rsstable, adapter->rss_info.rsstable,
1223 		       RSS_INDIR_TABLE_LEN);
1224 	}
1225 
1226 	if (!hkey)
1227 		hkey =  adapter->rss_info.rss_hkey;
1228 
1229 	rc = be_cmd_rss_config(adapter, rsstable,
1230 			       adapter->rss_info.rss_flags,
1231 			       RSS_INDIR_TABLE_LEN, hkey);
1232 	if (rc) {
1233 		adapter->rss_info.rss_flags = RSS_ENABLE_NONE;
1234 		return -EIO;
1235 	}
1236 	memcpy(adapter->rss_info.rss_hkey, hkey, RSS_HASH_KEY_LEN);
1237 	memcpy(adapter->rss_info.rsstable, rsstable,
1238 	       RSS_INDIR_TABLE_LEN);
1239 	return 0;
1240 }
1241 
1242 static int be_get_module_info(struct net_device *netdev,
1243 			      struct ethtool_modinfo *modinfo)
1244 {
1245 	struct be_adapter *adapter = netdev_priv(netdev);
1246 	u8 page_data[PAGE_DATA_LEN];
1247 	int status;
1248 
1249 	if (!check_privilege(adapter, MAX_PRIVILEGES))
1250 		return -EOPNOTSUPP;
1251 
1252 	status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
1253 						   page_data);
1254 	if (!status) {
1255 		if (!page_data[SFP_PLUS_SFF_8472_COMP]) {
1256 			modinfo->type = ETH_MODULE_SFF_8079;
1257 			modinfo->eeprom_len = PAGE_DATA_LEN;
1258 		} else {
1259 			modinfo->type = ETH_MODULE_SFF_8472;
1260 			modinfo->eeprom_len = 2 * PAGE_DATA_LEN;
1261 		}
1262 	}
1263 	return be_cmd_status(status);
1264 }
1265 
1266 static int be_get_module_eeprom(struct net_device *netdev,
1267 				struct ethtool_eeprom *eeprom, u8 *data)
1268 {
1269 	struct be_adapter *adapter = netdev_priv(netdev);
1270 	int status;
1271 
1272 	if (!check_privilege(adapter, MAX_PRIVILEGES))
1273 		return -EOPNOTSUPP;
1274 
1275 	status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
1276 						   data);
1277 	if (status)
1278 		goto err;
1279 
1280 	if (eeprom->offset + eeprom->len > PAGE_DATA_LEN) {
1281 		status = be_cmd_read_port_transceiver_data(adapter,
1282 							   TR_PAGE_A2,
1283 							   data +
1284 							   PAGE_DATA_LEN);
1285 		if (status)
1286 			goto err;
1287 	}
1288 	if (eeprom->offset)
1289 		memcpy(data, data + eeprom->offset, eeprom->len);
1290 err:
1291 	return be_cmd_status(status);
1292 }
1293 
1294 const struct ethtool_ops be_ethtool_ops = {
1295 	.get_settings = be_get_settings,
1296 	.get_drvinfo = be_get_drvinfo,
1297 	.get_wol = be_get_wol,
1298 	.set_wol = be_set_wol,
1299 	.get_link = ethtool_op_get_link,
1300 	.get_eeprom_len = be_get_eeprom_len,
1301 	.get_eeprom = be_read_eeprom,
1302 	.get_coalesce = be_get_coalesce,
1303 	.set_coalesce = be_set_coalesce,
1304 	.get_ringparam = be_get_ringparam,
1305 	.get_pauseparam = be_get_pauseparam,
1306 	.set_pauseparam = be_set_pauseparam,
1307 	.get_strings = be_get_stat_strings,
1308 	.set_phys_id = be_set_phys_id,
1309 	.set_dump = be_set_dump,
1310 	.get_msglevel = be_get_msg_level,
1311 	.set_msglevel = be_set_msg_level,
1312 	.get_sset_count = be_get_sset_count,
1313 	.get_ethtool_stats = be_get_ethtool_stats,
1314 	.get_regs_len = be_get_reg_len,
1315 	.get_regs = be_get_regs,
1316 	.flash_device = be_do_flash,
1317 	.self_test = be_self_test,
1318 	.get_rxnfc = be_get_rxnfc,
1319 	.set_rxnfc = be_set_rxnfc,
1320 	.get_rxfh_indir_size = be_get_rxfh_indir_size,
1321 	.get_rxfh_key_size = be_get_rxfh_key_size,
1322 	.get_rxfh = be_get_rxfh,
1323 	.set_rxfh = be_set_rxfh,
1324 	.get_channels = be_get_channels,
1325 	.set_channels = be_set_channels,
1326 	.get_module_info = be_get_module_info,
1327 	.get_module_eeprom = be_get_module_eeprom
1328 };
1329