1c0c050c5SMichael Chan /* Broadcom NetXtreme-C/E network driver.
2c0c050c5SMichael Chan  *
311f15ed3SMichael Chan  * Copyright (c) 2014-2016 Broadcom Corporation
48e202366SMichael Chan  * Copyright (c) 2016-2017 Broadcom Limited
5c0c050c5SMichael Chan  *
6c0c050c5SMichael Chan  * This program is free software; you can redistribute it and/or modify
7c0c050c5SMichael Chan  * it under the terms of the GNU General Public License as published by
8c0c050c5SMichael Chan  * the Free Software Foundation.
9c0c050c5SMichael Chan  */
10c0c050c5SMichael Chan 
113ebf6f0aSRob Swindell #include <linux/ctype.h>
128ddc9aaaSMichael Chan #include <linux/stringify.h>
13c0c050c5SMichael Chan #include <linux/ethtool.h>
14c0c050c5SMichael Chan #include <linux/interrupt.h>
15c0c050c5SMichael Chan #include <linux/pci.h>
16c0c050c5SMichael Chan #include <linux/etherdevice.h>
17c0c050c5SMichael Chan #include <linux/crc32.h>
18c0c050c5SMichael Chan #include <linux/firmware.h>
196c5657d0SVasundhara Volam #include <linux/utsname.h>
206c5657d0SVasundhara Volam #include <linux/time.h>
21c0c050c5SMichael Chan #include "bnxt_hsi.h"
22c0c050c5SMichael Chan #include "bnxt.h"
23f7dc1ea6SMichael Chan #include "bnxt_xdp.h"
24c0c050c5SMichael Chan #include "bnxt_ethtool.h"
25c0c050c5SMichael Chan #include "bnxt_nvm_defs.h"	/* NVRAM content constant and structure defs */
26c0c050c5SMichael Chan #include "bnxt_fw_hdr.h"	/* Firmware hdr constant and structure defs */
276c5657d0SVasundhara Volam #include "bnxt_coredump.h"
28c0c050c5SMichael Chan #define FLASH_NVRAM_TIMEOUT	((HWRM_CMD_TIMEOUT) * 100)
295ac67d8bSRob Swindell #define FLASH_PACKAGE_TIMEOUT	((HWRM_CMD_TIMEOUT) * 200)
305ac67d8bSRob Swindell #define INSTALL_PACKAGE_TIMEOUT	((HWRM_CMD_TIMEOUT) * 200)
31c0c050c5SMichael Chan 
32c0c050c5SMichael Chan static u32 bnxt_get_msglevel(struct net_device *dev)
33c0c050c5SMichael Chan {
34c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
35c0c050c5SMichael Chan 
36c0c050c5SMichael Chan 	return bp->msg_enable;
37c0c050c5SMichael Chan }
38c0c050c5SMichael Chan 
39c0c050c5SMichael Chan static void bnxt_set_msglevel(struct net_device *dev, u32 value)
40c0c050c5SMichael Chan {
41c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
42c0c050c5SMichael Chan 
43c0c050c5SMichael Chan 	bp->msg_enable = value;
44c0c050c5SMichael Chan }
45c0c050c5SMichael Chan 
46c0c050c5SMichael Chan static int bnxt_get_coalesce(struct net_device *dev,
47c0c050c5SMichael Chan 			     struct ethtool_coalesce *coal)
48c0c050c5SMichael Chan {
49c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
5018775aa8SMichael Chan 	struct bnxt_coal *hw_coal;
5118775aa8SMichael Chan 	u16 mult;
52c0c050c5SMichael Chan 
53c0c050c5SMichael Chan 	memset(coal, 0, sizeof(*coal));
54c0c050c5SMichael Chan 
556a8788f2SAndy Gospodarek 	coal->use_adaptive_rx_coalesce = bp->flags & BNXT_FLAG_DIM;
566a8788f2SAndy Gospodarek 
5718775aa8SMichael Chan 	hw_coal = &bp->rx_coal;
5818775aa8SMichael Chan 	mult = hw_coal->bufs_per_record;
5918775aa8SMichael Chan 	coal->rx_coalesce_usecs = hw_coal->coal_ticks;
6018775aa8SMichael Chan 	coal->rx_max_coalesced_frames = hw_coal->coal_bufs / mult;
6118775aa8SMichael Chan 	coal->rx_coalesce_usecs_irq = hw_coal->coal_ticks_irq;
6218775aa8SMichael Chan 	coal->rx_max_coalesced_frames_irq = hw_coal->coal_bufs_irq / mult;
63c0c050c5SMichael Chan 
6418775aa8SMichael Chan 	hw_coal = &bp->tx_coal;
6518775aa8SMichael Chan 	mult = hw_coal->bufs_per_record;
6618775aa8SMichael Chan 	coal->tx_coalesce_usecs = hw_coal->coal_ticks;
6718775aa8SMichael Chan 	coal->tx_max_coalesced_frames = hw_coal->coal_bufs / mult;
6818775aa8SMichael Chan 	coal->tx_coalesce_usecs_irq = hw_coal->coal_ticks_irq;
6918775aa8SMichael Chan 	coal->tx_max_coalesced_frames_irq = hw_coal->coal_bufs_irq / mult;
70dfc9c94aSMichael Chan 
7151f30785SMichael Chan 	coal->stats_block_coalesce_usecs = bp->stats_coal_ticks;
7251f30785SMichael Chan 
73c0c050c5SMichael Chan 	return 0;
74c0c050c5SMichael Chan }
75c0c050c5SMichael Chan 
76c0c050c5SMichael Chan static int bnxt_set_coalesce(struct net_device *dev,
77c0c050c5SMichael Chan 			     struct ethtool_coalesce *coal)
78c0c050c5SMichael Chan {
79c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
8051f30785SMichael Chan 	bool update_stats = false;
8118775aa8SMichael Chan 	struct bnxt_coal *hw_coal;
82c0c050c5SMichael Chan 	int rc = 0;
8318775aa8SMichael Chan 	u16 mult;
84c0c050c5SMichael Chan 
856a8788f2SAndy Gospodarek 	if (coal->use_adaptive_rx_coalesce) {
866a8788f2SAndy Gospodarek 		bp->flags |= BNXT_FLAG_DIM;
876a8788f2SAndy Gospodarek 	} else {
886a8788f2SAndy Gospodarek 		if (bp->flags & BNXT_FLAG_DIM) {
896a8788f2SAndy Gospodarek 			bp->flags &= ~(BNXT_FLAG_DIM);
906a8788f2SAndy Gospodarek 			goto reset_coalesce;
916a8788f2SAndy Gospodarek 		}
926a8788f2SAndy Gospodarek 	}
936a8788f2SAndy Gospodarek 
9418775aa8SMichael Chan 	hw_coal = &bp->rx_coal;
9518775aa8SMichael Chan 	mult = hw_coal->bufs_per_record;
9618775aa8SMichael Chan 	hw_coal->coal_ticks = coal->rx_coalesce_usecs;
9718775aa8SMichael Chan 	hw_coal->coal_bufs = coal->rx_max_coalesced_frames * mult;
9818775aa8SMichael Chan 	hw_coal->coal_ticks_irq = coal->rx_coalesce_usecs_irq;
9918775aa8SMichael Chan 	hw_coal->coal_bufs_irq = coal->rx_max_coalesced_frames_irq * mult;
100c0c050c5SMichael Chan 
101de4a10efSAndy Gospodarek 	hw_coal = &bp->tx_coal;
10218775aa8SMichael Chan 	mult = hw_coal->bufs_per_record;
10318775aa8SMichael Chan 	hw_coal->coal_ticks = coal->tx_coalesce_usecs;
10418775aa8SMichael Chan 	hw_coal->coal_bufs = coal->tx_max_coalesced_frames * mult;
10518775aa8SMichael Chan 	hw_coal->coal_ticks_irq = coal->tx_coalesce_usecs_irq;
10618775aa8SMichael Chan 	hw_coal->coal_bufs_irq = coal->tx_max_coalesced_frames_irq * mult;
107dfc9c94aSMichael Chan 
10851f30785SMichael Chan 	if (bp->stats_coal_ticks != coal->stats_block_coalesce_usecs) {
10951f30785SMichael Chan 		u32 stats_ticks = coal->stats_block_coalesce_usecs;
11051f30785SMichael Chan 
111adcc331eSMichael Chan 		/* Allow 0, which means disable. */
112adcc331eSMichael Chan 		if (stats_ticks)
11351f30785SMichael Chan 			stats_ticks = clamp_t(u32, stats_ticks,
11451f30785SMichael Chan 					      BNXT_MIN_STATS_COAL_TICKS,
11551f30785SMichael Chan 					      BNXT_MAX_STATS_COAL_TICKS);
11651f30785SMichael Chan 		stats_ticks = rounddown(stats_ticks, BNXT_MIN_STATS_COAL_TICKS);
11751f30785SMichael Chan 		bp->stats_coal_ticks = stats_ticks;
118e795892eSMichael Chan 		if (bp->stats_coal_ticks)
119e795892eSMichael Chan 			bp->current_interval =
120e795892eSMichael Chan 				bp->stats_coal_ticks * HZ / 1000000;
121e795892eSMichael Chan 		else
122e795892eSMichael Chan 			bp->current_interval = BNXT_TIMER_INTERVAL;
12351f30785SMichael Chan 		update_stats = true;
12451f30785SMichael Chan 	}
12551f30785SMichael Chan 
1266a8788f2SAndy Gospodarek reset_coalesce:
12751f30785SMichael Chan 	if (netif_running(dev)) {
12851f30785SMichael Chan 		if (update_stats) {
12951f30785SMichael Chan 			rc = bnxt_close_nic(bp, true, false);
13051f30785SMichael Chan 			if (!rc)
13151f30785SMichael Chan 				rc = bnxt_open_nic(bp, true, false);
13251f30785SMichael Chan 		} else {
133c0c050c5SMichael Chan 			rc = bnxt_hwrm_set_coal(bp);
13451f30785SMichael Chan 		}
13551f30785SMichael Chan 	}
136c0c050c5SMichael Chan 
137c0c050c5SMichael Chan 	return rc;
138c0c050c5SMichael Chan }
139c0c050c5SMichael Chan 
140ee79566eSMichael Chan static const char * const bnxt_ring_stats_str[] = {
141ee79566eSMichael Chan 	"rx_ucast_packets",
142ee79566eSMichael Chan 	"rx_mcast_packets",
143ee79566eSMichael Chan 	"rx_bcast_packets",
144ee79566eSMichael Chan 	"rx_discards",
145ee79566eSMichael Chan 	"rx_drops",
146ee79566eSMichael Chan 	"rx_ucast_bytes",
147ee79566eSMichael Chan 	"rx_mcast_bytes",
148ee79566eSMichael Chan 	"rx_bcast_bytes",
149ee79566eSMichael Chan 	"tx_ucast_packets",
150ee79566eSMichael Chan 	"tx_mcast_packets",
151ee79566eSMichael Chan 	"tx_bcast_packets",
152ee79566eSMichael Chan 	"tx_discards",
153ee79566eSMichael Chan 	"tx_drops",
154ee79566eSMichael Chan 	"tx_ucast_bytes",
155ee79566eSMichael Chan 	"tx_mcast_bytes",
156ee79566eSMichael Chan 	"tx_bcast_bytes",
157ee79566eSMichael Chan };
158ee79566eSMichael Chan 
159ee79566eSMichael Chan static const char * const bnxt_ring_tpa_stats_str[] = {
160ee79566eSMichael Chan 	"tpa_packets",
161ee79566eSMichael Chan 	"tpa_bytes",
162ee79566eSMichael Chan 	"tpa_events",
163ee79566eSMichael Chan 	"tpa_aborts",
164ee79566eSMichael Chan };
165ee79566eSMichael Chan 
16678e7b866SMichael Chan static const char * const bnxt_ring_tpa2_stats_str[] = {
16778e7b866SMichael Chan 	"rx_tpa_eligible_pkt",
16878e7b866SMichael Chan 	"rx_tpa_eligible_bytes",
16978e7b866SMichael Chan 	"rx_tpa_pkt",
17078e7b866SMichael Chan 	"rx_tpa_bytes",
17178e7b866SMichael Chan 	"rx_tpa_errors",
17278e7b866SMichael Chan };
17378e7b866SMichael Chan 
174ee79566eSMichael Chan static const char * const bnxt_ring_sw_stats_str[] = {
175ee79566eSMichael Chan 	"rx_l4_csum_errors",
17619b3751fSMichael Chan 	"rx_buf_errors",
177ee79566eSMichael Chan 	"missed_irqs",
178ee79566eSMichael Chan };
179c0c050c5SMichael Chan 
1808ddc9aaaSMichael Chan #define BNXT_RX_STATS_ENTRY(counter)	\
1818ddc9aaaSMichael Chan 	{ BNXT_RX_STATS_OFFSET(counter), __stringify(counter) }
1828ddc9aaaSMichael Chan 
1838ddc9aaaSMichael Chan #define BNXT_TX_STATS_ENTRY(counter)	\
1848ddc9aaaSMichael Chan 	{ BNXT_TX_STATS_OFFSET(counter), __stringify(counter) }
1858ddc9aaaSMichael Chan 
18600db3cbaSVasundhara Volam #define BNXT_RX_STATS_EXT_ENTRY(counter)	\
18700db3cbaSVasundhara Volam 	{ BNXT_RX_STATS_EXT_OFFSET(counter), __stringify(counter) }
18800db3cbaSVasundhara Volam 
18936e53349SMichael Chan #define BNXT_TX_STATS_EXT_ENTRY(counter)	\
19036e53349SMichael Chan 	{ BNXT_TX_STATS_EXT_OFFSET(counter), __stringify(counter) }
19136e53349SMichael Chan 
19236e53349SMichael Chan #define BNXT_RX_STATS_EXT_PFC_ENTRY(n)				\
19336e53349SMichael Chan 	BNXT_RX_STATS_EXT_ENTRY(pfc_pri##n##_rx_duration_us),	\
19436e53349SMichael Chan 	BNXT_RX_STATS_EXT_ENTRY(pfc_pri##n##_rx_transitions)
19536e53349SMichael Chan 
19636e53349SMichael Chan #define BNXT_TX_STATS_EXT_PFC_ENTRY(n)				\
19736e53349SMichael Chan 	BNXT_TX_STATS_EXT_ENTRY(pfc_pri##n##_tx_duration_us),	\
19836e53349SMichael Chan 	BNXT_TX_STATS_EXT_ENTRY(pfc_pri##n##_tx_transitions)
19936e53349SMichael Chan 
20036e53349SMichael Chan #define BNXT_RX_STATS_EXT_PFC_ENTRIES				\
20136e53349SMichael Chan 	BNXT_RX_STATS_EXT_PFC_ENTRY(0),				\
20236e53349SMichael Chan 	BNXT_RX_STATS_EXT_PFC_ENTRY(1),				\
20336e53349SMichael Chan 	BNXT_RX_STATS_EXT_PFC_ENTRY(2),				\
20436e53349SMichael Chan 	BNXT_RX_STATS_EXT_PFC_ENTRY(3),				\
20536e53349SMichael Chan 	BNXT_RX_STATS_EXT_PFC_ENTRY(4),				\
20636e53349SMichael Chan 	BNXT_RX_STATS_EXT_PFC_ENTRY(5),				\
20736e53349SMichael Chan 	BNXT_RX_STATS_EXT_PFC_ENTRY(6),				\
20836e53349SMichael Chan 	BNXT_RX_STATS_EXT_PFC_ENTRY(7)
20936e53349SMichael Chan 
21036e53349SMichael Chan #define BNXT_TX_STATS_EXT_PFC_ENTRIES				\
21136e53349SMichael Chan 	BNXT_TX_STATS_EXT_PFC_ENTRY(0),				\
21236e53349SMichael Chan 	BNXT_TX_STATS_EXT_PFC_ENTRY(1),				\
21336e53349SMichael Chan 	BNXT_TX_STATS_EXT_PFC_ENTRY(2),				\
21436e53349SMichael Chan 	BNXT_TX_STATS_EXT_PFC_ENTRY(3),				\
21536e53349SMichael Chan 	BNXT_TX_STATS_EXT_PFC_ENTRY(4),				\
21636e53349SMichael Chan 	BNXT_TX_STATS_EXT_PFC_ENTRY(5),				\
21736e53349SMichael Chan 	BNXT_TX_STATS_EXT_PFC_ENTRY(6),				\
21836e53349SMichael Chan 	BNXT_TX_STATS_EXT_PFC_ENTRY(7)
21936e53349SMichael Chan 
22036e53349SMichael Chan #define BNXT_RX_STATS_EXT_COS_ENTRY(n)				\
22136e53349SMichael Chan 	BNXT_RX_STATS_EXT_ENTRY(rx_bytes_cos##n),		\
22236e53349SMichael Chan 	BNXT_RX_STATS_EXT_ENTRY(rx_packets_cos##n)
22336e53349SMichael Chan 
22436e53349SMichael Chan #define BNXT_TX_STATS_EXT_COS_ENTRY(n)				\
22536e53349SMichael Chan 	BNXT_TX_STATS_EXT_ENTRY(tx_bytes_cos##n),		\
22636e53349SMichael Chan 	BNXT_TX_STATS_EXT_ENTRY(tx_packets_cos##n)
22736e53349SMichael Chan 
22836e53349SMichael Chan #define BNXT_RX_STATS_EXT_COS_ENTRIES				\
22936e53349SMichael Chan 	BNXT_RX_STATS_EXT_COS_ENTRY(0),				\
23036e53349SMichael Chan 	BNXT_RX_STATS_EXT_COS_ENTRY(1),				\
23136e53349SMichael Chan 	BNXT_RX_STATS_EXT_COS_ENTRY(2),				\
23236e53349SMichael Chan 	BNXT_RX_STATS_EXT_COS_ENTRY(3),				\
23336e53349SMichael Chan 	BNXT_RX_STATS_EXT_COS_ENTRY(4),				\
23436e53349SMichael Chan 	BNXT_RX_STATS_EXT_COS_ENTRY(5),				\
23536e53349SMichael Chan 	BNXT_RX_STATS_EXT_COS_ENTRY(6),				\
23636e53349SMichael Chan 	BNXT_RX_STATS_EXT_COS_ENTRY(7)				\
23736e53349SMichael Chan 
23836e53349SMichael Chan #define BNXT_TX_STATS_EXT_COS_ENTRIES				\
23936e53349SMichael Chan 	BNXT_TX_STATS_EXT_COS_ENTRY(0),				\
24036e53349SMichael Chan 	BNXT_TX_STATS_EXT_COS_ENTRY(1),				\
24136e53349SMichael Chan 	BNXT_TX_STATS_EXT_COS_ENTRY(2),				\
24236e53349SMichael Chan 	BNXT_TX_STATS_EXT_COS_ENTRY(3),				\
24336e53349SMichael Chan 	BNXT_TX_STATS_EXT_COS_ENTRY(4),				\
24436e53349SMichael Chan 	BNXT_TX_STATS_EXT_COS_ENTRY(5),				\
24536e53349SMichael Chan 	BNXT_TX_STATS_EXT_COS_ENTRY(6),				\
24636e53349SMichael Chan 	BNXT_TX_STATS_EXT_COS_ENTRY(7)				\
24736e53349SMichael Chan 
2482792b5b9SMichael Chan #define BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(n)			\
2492792b5b9SMichael Chan 	BNXT_RX_STATS_EXT_ENTRY(rx_discard_bytes_cos##n),	\
2502792b5b9SMichael Chan 	BNXT_RX_STATS_EXT_ENTRY(rx_discard_packets_cos##n)
2512792b5b9SMichael Chan 
2522792b5b9SMichael Chan #define BNXT_RX_STATS_EXT_DISCARD_COS_ENTRIES				\
2532792b5b9SMichael Chan 	BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(0),				\
2542792b5b9SMichael Chan 	BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(1),				\
2552792b5b9SMichael Chan 	BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(2),				\
2562792b5b9SMichael Chan 	BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(3),				\
2572792b5b9SMichael Chan 	BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(4),				\
2582792b5b9SMichael Chan 	BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(5),				\
2592792b5b9SMichael Chan 	BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(6),				\
2602792b5b9SMichael Chan 	BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(7)
2612792b5b9SMichael Chan 
262e37fed79SMichael Chan #define BNXT_RX_STATS_PRI_ENTRY(counter, n)		\
263e37fed79SMichael Chan 	{ BNXT_RX_STATS_EXT_OFFSET(counter##_cos0),	\
264e37fed79SMichael Chan 	  __stringify(counter##_pri##n) }
265e37fed79SMichael Chan 
266e37fed79SMichael Chan #define BNXT_TX_STATS_PRI_ENTRY(counter, n)		\
267e37fed79SMichael Chan 	{ BNXT_TX_STATS_EXT_OFFSET(counter##_cos0),	\
268e37fed79SMichael Chan 	  __stringify(counter##_pri##n) }
269e37fed79SMichael Chan 
270e37fed79SMichael Chan #define BNXT_RX_STATS_PRI_ENTRIES(counter)		\
271e37fed79SMichael Chan 	BNXT_RX_STATS_PRI_ENTRY(counter, 0),		\
272e37fed79SMichael Chan 	BNXT_RX_STATS_PRI_ENTRY(counter, 1),		\
273e37fed79SMichael Chan 	BNXT_RX_STATS_PRI_ENTRY(counter, 2),		\
274e37fed79SMichael Chan 	BNXT_RX_STATS_PRI_ENTRY(counter, 3),		\
275e37fed79SMichael Chan 	BNXT_RX_STATS_PRI_ENTRY(counter, 4),		\
276e37fed79SMichael Chan 	BNXT_RX_STATS_PRI_ENTRY(counter, 5),		\
277e37fed79SMichael Chan 	BNXT_RX_STATS_PRI_ENTRY(counter, 6),		\
278e37fed79SMichael Chan 	BNXT_RX_STATS_PRI_ENTRY(counter, 7)
279e37fed79SMichael Chan 
280e37fed79SMichael Chan #define BNXT_TX_STATS_PRI_ENTRIES(counter)		\
281e37fed79SMichael Chan 	BNXT_TX_STATS_PRI_ENTRY(counter, 0),		\
282e37fed79SMichael Chan 	BNXT_TX_STATS_PRI_ENTRY(counter, 1),		\
283e37fed79SMichael Chan 	BNXT_TX_STATS_PRI_ENTRY(counter, 2),		\
284e37fed79SMichael Chan 	BNXT_TX_STATS_PRI_ENTRY(counter, 3),		\
285e37fed79SMichael Chan 	BNXT_TX_STATS_PRI_ENTRY(counter, 4),		\
286e37fed79SMichael Chan 	BNXT_TX_STATS_PRI_ENTRY(counter, 5),		\
287e37fed79SMichael Chan 	BNXT_TX_STATS_PRI_ENTRY(counter, 6),		\
288e37fed79SMichael Chan 	BNXT_TX_STATS_PRI_ENTRY(counter, 7)
289e37fed79SMichael Chan 
29055e4398dSVasundhara Volam #define BNXT_PCIE_STATS_ENTRY(counter)	\
29155e4398dSVasundhara Volam 	{ BNXT_PCIE_STATS_OFFSET(counter), __stringify(counter) }
29255e4398dSVasundhara Volam 
29320c1d28eSVasundhara Volam enum {
29420c1d28eSVasundhara Volam 	RX_TOTAL_DISCARDS,
29520c1d28eSVasundhara Volam 	TX_TOTAL_DISCARDS,
29620c1d28eSVasundhara Volam };
29720c1d28eSVasundhara Volam 
29820c1d28eSVasundhara Volam static struct {
29920c1d28eSVasundhara Volam 	u64			counter;
30020c1d28eSVasundhara Volam 	char			string[ETH_GSTRING_LEN];
30120c1d28eSVasundhara Volam } bnxt_sw_func_stats[] = {
30220c1d28eSVasundhara Volam 	{0, "rx_total_discard_pkts"},
30320c1d28eSVasundhara Volam 	{0, "tx_total_discard_pkts"},
30420c1d28eSVasundhara Volam };
30520c1d28eSVasundhara Volam 
3068ddc9aaaSMichael Chan static const struct {
3078ddc9aaaSMichael Chan 	long offset;
3088ddc9aaaSMichael Chan 	char string[ETH_GSTRING_LEN];
3098ddc9aaaSMichael Chan } bnxt_port_stats_arr[] = {
3108ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_64b_frames),
3118ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_65b_127b_frames),
3128ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_128b_255b_frames),
3138ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_256b_511b_frames),
3148ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_512b_1023b_frames),
3156fc92c33SMichael Chan 	BNXT_RX_STATS_ENTRY(rx_1024b_1518b_frames),
3168ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_good_vlan_frames),
3178ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_1519b_2047b_frames),
3188ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_2048b_4095b_frames),
3198ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_4096b_9216b_frames),
3208ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_9217b_16383b_frames),
3218ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_total_frames),
3228ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_ucast_frames),
3238ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_mcast_frames),
3248ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_bcast_frames),
3258ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_fcs_err_frames),
3268ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_ctrl_frames),
3278ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_pause_frames),
3288ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_pfc_frames),
3298ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_align_err_frames),
3308ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_ovrsz_frames),
3318ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_jbr_frames),
3328ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_mtu_err_frames),
3338ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_tagged_frames),
3348ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_double_tagged_frames),
3358ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_good_frames),
336c77192f2SMichael Chan 	BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri0),
337c77192f2SMichael Chan 	BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri1),
338c77192f2SMichael Chan 	BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri2),
339c77192f2SMichael Chan 	BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri3),
340c77192f2SMichael Chan 	BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri4),
341c77192f2SMichael Chan 	BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri5),
342c77192f2SMichael Chan 	BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri6),
343c77192f2SMichael Chan 	BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri7),
3448ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_undrsz_frames),
3458ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_eee_lpi_events),
3468ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_eee_lpi_duration),
3478ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_bytes),
3488ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_runt_bytes),
3498ddc9aaaSMichael Chan 	BNXT_RX_STATS_ENTRY(rx_runt_frames),
350699efed0SVasundhara Volam 	BNXT_RX_STATS_ENTRY(rx_stat_discard),
351699efed0SVasundhara Volam 	BNXT_RX_STATS_ENTRY(rx_stat_err),
3528ddc9aaaSMichael Chan 
3538ddc9aaaSMichael Chan 	BNXT_TX_STATS_ENTRY(tx_64b_frames),
3548ddc9aaaSMichael Chan 	BNXT_TX_STATS_ENTRY(tx_65b_127b_frames),
3558ddc9aaaSMichael Chan 	BNXT_TX_STATS_ENTRY(tx_128b_255b_frames),
3568ddc9aaaSMichael Chan 	BNXT_TX_STATS_ENTRY(tx_256b_511b_frames),
3578ddc9aaaSMichael Chan 	BNXT_TX_STATS_ENTRY(tx_512b_1023b_frames),
3586fc92c33SMichael Chan 	BNXT_TX_STATS_ENTRY(tx_1024b_1518b_frames),
3598ddc9aaaSMichael Chan 	BNXT_TX_STATS_ENTRY(tx_good_vlan_frames),
3606fc92c33SMichael Chan 	BNXT_TX_STATS_ENTRY(tx_1519b_2047b_frames),
3618ddc9aaaSMichael Chan 	BNXT_TX_STATS_ENTRY(tx_2048b_4095b_frames),
3628ddc9aaaSMichael Chan 	BNXT_TX_STATS_ENTRY(tx_4096b_9216b_frames),
3638ddc9aaaSMichael Chan 	BNXT_TX_STATS_ENTRY(tx_9217b_16383b_frames),
3648ddc9aaaSMichael Chan 	BNXT_TX_STATS_ENTRY(tx_good_frames),
3658ddc9aaaSMichael Chan 	BNXT_TX_STATS_ENTRY(tx_total_frames),
3668ddc9aaaSMichael Chan 	BNXT_TX_STATS_ENTRY(tx_ucast_frames),
3678ddc9aaaSMichael Chan 	BNXT_TX_STATS_ENTRY(tx_mcast_frames),
3688ddc9aaaSMichael Chan 	BNXT_TX_STATS_ENTRY(tx_bcast_frames),
3698ddc9aaaSMichael Chan 	BNXT_TX_STATS_ENTRY(tx_pause_frames),
3708ddc9aaaSMichael Chan 	BNXT_TX_STATS_ENTRY(tx_pfc_frames),
3718ddc9aaaSMichael Chan 	BNXT_TX_STATS_ENTRY(tx_jabber_frames),
3728ddc9aaaSMichael Chan 	BNXT_TX_STATS_ENTRY(tx_fcs_err_frames),
3738ddc9aaaSMichael Chan 	BNXT_TX_STATS_ENTRY(tx_err),
3748ddc9aaaSMichael Chan 	BNXT_TX_STATS_ENTRY(tx_fifo_underruns),
375c77192f2SMichael Chan 	BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri0),
376c77192f2SMichael Chan 	BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri1),
377c77192f2SMichael Chan 	BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri2),
378c77192f2SMichael Chan 	BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri3),
379c77192f2SMichael Chan 	BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri4),
380c77192f2SMichael Chan 	BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri5),
381c77192f2SMichael Chan 	BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri6),
382c77192f2SMichael Chan 	BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri7),
3838ddc9aaaSMichael Chan 	BNXT_TX_STATS_ENTRY(tx_eee_lpi_events),
3848ddc9aaaSMichael Chan 	BNXT_TX_STATS_ENTRY(tx_eee_lpi_duration),
3858ddc9aaaSMichael Chan 	BNXT_TX_STATS_ENTRY(tx_total_collisions),
3868ddc9aaaSMichael Chan 	BNXT_TX_STATS_ENTRY(tx_bytes),
387699efed0SVasundhara Volam 	BNXT_TX_STATS_ENTRY(tx_xthol_frames),
388699efed0SVasundhara Volam 	BNXT_TX_STATS_ENTRY(tx_stat_discard),
389699efed0SVasundhara Volam 	BNXT_TX_STATS_ENTRY(tx_stat_error),
3908ddc9aaaSMichael Chan };
3918ddc9aaaSMichael Chan 
39200db3cbaSVasundhara Volam static const struct {
39300db3cbaSVasundhara Volam 	long offset;
39400db3cbaSVasundhara Volam 	char string[ETH_GSTRING_LEN];
39500db3cbaSVasundhara Volam } bnxt_port_stats_ext_arr[] = {
39600db3cbaSVasundhara Volam 	BNXT_RX_STATS_EXT_ENTRY(link_down_events),
39700db3cbaSVasundhara Volam 	BNXT_RX_STATS_EXT_ENTRY(continuous_pause_events),
39800db3cbaSVasundhara Volam 	BNXT_RX_STATS_EXT_ENTRY(resume_pause_events),
39900db3cbaSVasundhara Volam 	BNXT_RX_STATS_EXT_ENTRY(continuous_roce_pause_events),
40000db3cbaSVasundhara Volam 	BNXT_RX_STATS_EXT_ENTRY(resume_roce_pause_events),
40136e53349SMichael Chan 	BNXT_RX_STATS_EXT_COS_ENTRIES,
40236e53349SMichael Chan 	BNXT_RX_STATS_EXT_PFC_ENTRIES,
4034a50ddc2SMichael Chan 	BNXT_RX_STATS_EXT_ENTRY(rx_bits),
4044a50ddc2SMichael Chan 	BNXT_RX_STATS_EXT_ENTRY(rx_buffer_passed_threshold),
4054a50ddc2SMichael Chan 	BNXT_RX_STATS_EXT_ENTRY(rx_pcs_symbol_err),
4064a50ddc2SMichael Chan 	BNXT_RX_STATS_EXT_ENTRY(rx_corrected_bits),
4072792b5b9SMichael Chan 	BNXT_RX_STATS_EXT_DISCARD_COS_ENTRIES,
40836e53349SMichael Chan };
40936e53349SMichael Chan 
41036e53349SMichael Chan static const struct {
41136e53349SMichael Chan 	long offset;
41236e53349SMichael Chan 	char string[ETH_GSTRING_LEN];
41336e53349SMichael Chan } bnxt_tx_port_stats_ext_arr[] = {
41436e53349SMichael Chan 	BNXT_TX_STATS_EXT_COS_ENTRIES,
41536e53349SMichael Chan 	BNXT_TX_STATS_EXT_PFC_ENTRIES,
41600db3cbaSVasundhara Volam };
41700db3cbaSVasundhara Volam 
418e37fed79SMichael Chan static const struct {
419e37fed79SMichael Chan 	long base_off;
420e37fed79SMichael Chan 	char string[ETH_GSTRING_LEN];
421e37fed79SMichael Chan } bnxt_rx_bytes_pri_arr[] = {
422e37fed79SMichael Chan 	BNXT_RX_STATS_PRI_ENTRIES(rx_bytes),
423e37fed79SMichael Chan };
424e37fed79SMichael Chan 
425e37fed79SMichael Chan static const struct {
426e37fed79SMichael Chan 	long base_off;
427e37fed79SMichael Chan 	char string[ETH_GSTRING_LEN];
428e37fed79SMichael Chan } bnxt_rx_pkts_pri_arr[] = {
429e37fed79SMichael Chan 	BNXT_RX_STATS_PRI_ENTRIES(rx_packets),
430e37fed79SMichael Chan };
431e37fed79SMichael Chan 
432e37fed79SMichael Chan static const struct {
433e37fed79SMichael Chan 	long base_off;
434e37fed79SMichael Chan 	char string[ETH_GSTRING_LEN];
435e37fed79SMichael Chan } bnxt_tx_bytes_pri_arr[] = {
436e37fed79SMichael Chan 	BNXT_TX_STATS_PRI_ENTRIES(tx_bytes),
437e37fed79SMichael Chan };
438e37fed79SMichael Chan 
439e37fed79SMichael Chan static const struct {
440e37fed79SMichael Chan 	long base_off;
441e37fed79SMichael Chan 	char string[ETH_GSTRING_LEN];
442e37fed79SMichael Chan } bnxt_tx_pkts_pri_arr[] = {
443e37fed79SMichael Chan 	BNXT_TX_STATS_PRI_ENTRIES(tx_packets),
444e37fed79SMichael Chan };
445e37fed79SMichael Chan 
44655e4398dSVasundhara Volam static const struct {
44755e4398dSVasundhara Volam 	long offset;
44855e4398dSVasundhara Volam 	char string[ETH_GSTRING_LEN];
44955e4398dSVasundhara Volam } bnxt_pcie_stats_arr[] = {
45055e4398dSVasundhara Volam 	BNXT_PCIE_STATS_ENTRY(pcie_pl_signal_integrity),
45155e4398dSVasundhara Volam 	BNXT_PCIE_STATS_ENTRY(pcie_dl_signal_integrity),
45255e4398dSVasundhara Volam 	BNXT_PCIE_STATS_ENTRY(pcie_tl_signal_integrity),
45355e4398dSVasundhara Volam 	BNXT_PCIE_STATS_ENTRY(pcie_link_integrity),
45455e4398dSVasundhara Volam 	BNXT_PCIE_STATS_ENTRY(pcie_tx_traffic_rate),
45555e4398dSVasundhara Volam 	BNXT_PCIE_STATS_ENTRY(pcie_rx_traffic_rate),
45655e4398dSVasundhara Volam 	BNXT_PCIE_STATS_ENTRY(pcie_tx_dllp_statistics),
45755e4398dSVasundhara Volam 	BNXT_PCIE_STATS_ENTRY(pcie_rx_dllp_statistics),
45855e4398dSVasundhara Volam 	BNXT_PCIE_STATS_ENTRY(pcie_equalization_time),
45955e4398dSVasundhara Volam 	BNXT_PCIE_STATS_ENTRY(pcie_ltssm_histogram[0]),
46055e4398dSVasundhara Volam 	BNXT_PCIE_STATS_ENTRY(pcie_ltssm_histogram[2]),
46155e4398dSVasundhara Volam 	BNXT_PCIE_STATS_ENTRY(pcie_recovery_histogram),
46255e4398dSVasundhara Volam };
46355e4398dSVasundhara Volam 
46420c1d28eSVasundhara Volam #define BNXT_NUM_SW_FUNC_STATS	ARRAY_SIZE(bnxt_sw_func_stats)
4658ddc9aaaSMichael Chan #define BNXT_NUM_PORT_STATS ARRAY_SIZE(bnxt_port_stats_arr)
466e37fed79SMichael Chan #define BNXT_NUM_STATS_PRI			\
467e37fed79SMichael Chan 	(ARRAY_SIZE(bnxt_rx_bytes_pri_arr) +	\
468e37fed79SMichael Chan 	 ARRAY_SIZE(bnxt_rx_pkts_pri_arr) +	\
469e37fed79SMichael Chan 	 ARRAY_SIZE(bnxt_tx_bytes_pri_arr) +	\
470e37fed79SMichael Chan 	 ARRAY_SIZE(bnxt_tx_pkts_pri_arr))
47155e4398dSVasundhara Volam #define BNXT_NUM_PCIE_STATS ARRAY_SIZE(bnxt_pcie_stats_arr)
4728ddc9aaaSMichael Chan 
47378e7b866SMichael Chan static int bnxt_get_num_tpa_ring_stats(struct bnxt *bp)
47478e7b866SMichael Chan {
47578e7b866SMichael Chan 	if (BNXT_SUPPORTS_TPA(bp)) {
47678e7b866SMichael Chan 		if (bp->max_tpa_v2)
47778e7b866SMichael Chan 			return ARRAY_SIZE(bnxt_ring_tpa2_stats_str);
47878e7b866SMichael Chan 		return ARRAY_SIZE(bnxt_ring_tpa_stats_str);
47978e7b866SMichael Chan 	}
48078e7b866SMichael Chan 	return 0;
48178e7b866SMichael Chan }
48278e7b866SMichael Chan 
483ee79566eSMichael Chan static int bnxt_get_num_ring_stats(struct bnxt *bp)
484ee79566eSMichael Chan {
485ee79566eSMichael Chan 	int num_stats;
486ee79566eSMichael Chan 
487ee79566eSMichael Chan 	num_stats = ARRAY_SIZE(bnxt_ring_stats_str) +
48878e7b866SMichael Chan 		    ARRAY_SIZE(bnxt_ring_sw_stats_str) +
48978e7b866SMichael Chan 		    bnxt_get_num_tpa_ring_stats(bp);
490ee79566eSMichael Chan 	return num_stats * bp->cp_nr_rings;
491ee79566eSMichael Chan }
492ee79566eSMichael Chan 
4935c8227d0SMichael Chan static int bnxt_get_num_stats(struct bnxt *bp)
494c0c050c5SMichael Chan {
495ee79566eSMichael Chan 	int num_stats = bnxt_get_num_ring_stats(bp);
4968ddc9aaaSMichael Chan 
49720c1d28eSVasundhara Volam 	num_stats += BNXT_NUM_SW_FUNC_STATS;
49820c1d28eSVasundhara Volam 
4998ddc9aaaSMichael Chan 	if (bp->flags & BNXT_FLAG_PORT_STATS)
5008ddc9aaaSMichael Chan 		num_stats += BNXT_NUM_PORT_STATS;
5018ddc9aaaSMichael Chan 
502e37fed79SMichael Chan 	if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) {
50336e53349SMichael Chan 		num_stats += bp->fw_rx_stats_ext_size +
50436e53349SMichael Chan 			     bp->fw_tx_stats_ext_size;
505e37fed79SMichael Chan 		if (bp->pri2cos_valid)
506e37fed79SMichael Chan 			num_stats += BNXT_NUM_STATS_PRI;
507e37fed79SMichael Chan 	}
50800db3cbaSVasundhara Volam 
50955e4398dSVasundhara Volam 	if (bp->flags & BNXT_FLAG_PCIE_STATS)
51055e4398dSVasundhara Volam 		num_stats += BNXT_NUM_PCIE_STATS;
51155e4398dSVasundhara Volam 
5128ddc9aaaSMichael Chan 	return num_stats;
5138ddc9aaaSMichael Chan }
5145c8227d0SMichael Chan 
5155c8227d0SMichael Chan static int bnxt_get_sset_count(struct net_device *dev, int sset)
5165c8227d0SMichael Chan {
5175c8227d0SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
5185c8227d0SMichael Chan 
5195c8227d0SMichael Chan 	switch (sset) {
5205c8227d0SMichael Chan 	case ETH_SS_STATS:
5215c8227d0SMichael Chan 		return bnxt_get_num_stats(bp);
522eb513658SMichael Chan 	case ETH_SS_TEST:
523eb513658SMichael Chan 		if (!bp->num_tests)
524eb513658SMichael Chan 			return -EOPNOTSUPP;
525eb513658SMichael Chan 		return bp->num_tests;
526c0c050c5SMichael Chan 	default:
527c0c050c5SMichael Chan 		return -EOPNOTSUPP;
528c0c050c5SMichael Chan 	}
529c0c050c5SMichael Chan }
530c0c050c5SMichael Chan 
531c0c050c5SMichael Chan static void bnxt_get_ethtool_stats(struct net_device *dev,
532c0c050c5SMichael Chan 				   struct ethtool_stats *stats, u64 *buf)
533c0c050c5SMichael Chan {
534c0c050c5SMichael Chan 	u32 i, j = 0;
535c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
53678e7b866SMichael Chan 	u32 stat_fields = ARRAY_SIZE(bnxt_ring_stats_str) +
53778e7b866SMichael Chan 			  bnxt_get_num_tpa_ring_stats(bp);
538c0c050c5SMichael Chan 
539fd3ab1c7SMichael Chan 	if (!bp->bnapi) {
540ee79566eSMichael Chan 		j += bnxt_get_num_ring_stats(bp) + BNXT_NUM_SW_FUNC_STATS;
541fd3ab1c7SMichael Chan 		goto skip_ring_stats;
542fd3ab1c7SMichael Chan 	}
543c0c050c5SMichael Chan 
54420c1d28eSVasundhara Volam 	for (i = 0; i < BNXT_NUM_SW_FUNC_STATS; i++)
54520c1d28eSVasundhara Volam 		bnxt_sw_func_stats[i].counter = 0;
54620c1d28eSVasundhara Volam 
547c0c050c5SMichael Chan 	for (i = 0; i < bp->cp_nr_rings; i++) {
548c0c050c5SMichael Chan 		struct bnxt_napi *bnapi = bp->bnapi[i];
549c0c050c5SMichael Chan 		struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
550c0c050c5SMichael Chan 		__le64 *hw_stats = (__le64 *)cpr->hw_stats;
551c0c050c5SMichael Chan 		int k;
552c0c050c5SMichael Chan 
553c0c050c5SMichael Chan 		for (k = 0; k < stat_fields; j++, k++)
554c0c050c5SMichael Chan 			buf[j] = le64_to_cpu(hw_stats[k]);
555c0c050c5SMichael Chan 		buf[j++] = cpr->rx_l4_csum_errors;
55619b3751fSMichael Chan 		buf[j++] = cpr->rx_buf_errors;
55783eb5c5cSMichael Chan 		buf[j++] = cpr->missed_irqs;
55820c1d28eSVasundhara Volam 
55920c1d28eSVasundhara Volam 		bnxt_sw_func_stats[RX_TOTAL_DISCARDS].counter +=
56020c1d28eSVasundhara Volam 			le64_to_cpu(cpr->hw_stats->rx_discard_pkts);
56120c1d28eSVasundhara Volam 		bnxt_sw_func_stats[TX_TOTAL_DISCARDS].counter +=
56220c1d28eSVasundhara Volam 			le64_to_cpu(cpr->hw_stats->tx_discard_pkts);
563c0c050c5SMichael Chan 	}
56420c1d28eSVasundhara Volam 
56520c1d28eSVasundhara Volam 	for (i = 0; i < BNXT_NUM_SW_FUNC_STATS; i++, j++)
56620c1d28eSVasundhara Volam 		buf[j] = bnxt_sw_func_stats[i].counter;
56720c1d28eSVasundhara Volam 
568fd3ab1c7SMichael Chan skip_ring_stats:
5698ddc9aaaSMichael Chan 	if (bp->flags & BNXT_FLAG_PORT_STATS) {
5708ddc9aaaSMichael Chan 		__le64 *port_stats = (__le64 *)bp->hw_rx_port_stats;
5718ddc9aaaSMichael Chan 
5728ddc9aaaSMichael Chan 		for (i = 0; i < BNXT_NUM_PORT_STATS; i++, j++) {
5738ddc9aaaSMichael Chan 			buf[j] = le64_to_cpu(*(port_stats +
5748ddc9aaaSMichael Chan 					       bnxt_port_stats_arr[i].offset));
5758ddc9aaaSMichael Chan 		}
5768ddc9aaaSMichael Chan 	}
57700db3cbaSVasundhara Volam 	if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) {
57836e53349SMichael Chan 		__le64 *rx_port_stats_ext = (__le64 *)bp->hw_rx_port_stats_ext;
57936e53349SMichael Chan 		__le64 *tx_port_stats_ext = (__le64 *)bp->hw_tx_port_stats_ext;
58000db3cbaSVasundhara Volam 
58136e53349SMichael Chan 		for (i = 0; i < bp->fw_rx_stats_ext_size; i++, j++) {
58236e53349SMichael Chan 			buf[j] = le64_to_cpu(*(rx_port_stats_ext +
58300db3cbaSVasundhara Volam 					    bnxt_port_stats_ext_arr[i].offset));
58400db3cbaSVasundhara Volam 		}
58536e53349SMichael Chan 		for (i = 0; i < bp->fw_tx_stats_ext_size; i++, j++) {
58636e53349SMichael Chan 			buf[j] = le64_to_cpu(*(tx_port_stats_ext +
58736e53349SMichael Chan 					bnxt_tx_port_stats_ext_arr[i].offset));
58836e53349SMichael Chan 		}
589e37fed79SMichael Chan 		if (bp->pri2cos_valid) {
590e37fed79SMichael Chan 			for (i = 0; i < 8; i++, j++) {
591e37fed79SMichael Chan 				long n = bnxt_rx_bytes_pri_arr[i].base_off +
592a24ec322SMichael Chan 					 bp->pri2cos_idx[i];
593e37fed79SMichael Chan 
594e37fed79SMichael Chan 				buf[j] = le64_to_cpu(*(rx_port_stats_ext + n));
595e37fed79SMichael Chan 			}
596e37fed79SMichael Chan 			for (i = 0; i < 8; i++, j++) {
597e37fed79SMichael Chan 				long n = bnxt_rx_pkts_pri_arr[i].base_off +
598a24ec322SMichael Chan 					 bp->pri2cos_idx[i];
599e37fed79SMichael Chan 
600e37fed79SMichael Chan 				buf[j] = le64_to_cpu(*(rx_port_stats_ext + n));
601e37fed79SMichael Chan 			}
602e37fed79SMichael Chan 			for (i = 0; i < 8; i++, j++) {
603e37fed79SMichael Chan 				long n = bnxt_tx_bytes_pri_arr[i].base_off +
604a24ec322SMichael Chan 					 bp->pri2cos_idx[i];
605e37fed79SMichael Chan 
606e37fed79SMichael Chan 				buf[j] = le64_to_cpu(*(tx_port_stats_ext + n));
607e37fed79SMichael Chan 			}
608e37fed79SMichael Chan 			for (i = 0; i < 8; i++, j++) {
609e37fed79SMichael Chan 				long n = bnxt_tx_pkts_pri_arr[i].base_off +
610a24ec322SMichael Chan 					 bp->pri2cos_idx[i];
611e37fed79SMichael Chan 
612e37fed79SMichael Chan 				buf[j] = le64_to_cpu(*(tx_port_stats_ext + n));
613e37fed79SMichael Chan 			}
614e37fed79SMichael Chan 		}
61500db3cbaSVasundhara Volam 	}
61655e4398dSVasundhara Volam 	if (bp->flags & BNXT_FLAG_PCIE_STATS) {
61755e4398dSVasundhara Volam 		__le64 *pcie_stats = (__le64 *)bp->hw_pcie_stats;
61855e4398dSVasundhara Volam 
61955e4398dSVasundhara Volam 		for (i = 0; i < BNXT_NUM_PCIE_STATS; i++, j++) {
62055e4398dSVasundhara Volam 			buf[j] = le64_to_cpu(*(pcie_stats +
62155e4398dSVasundhara Volam 					       bnxt_pcie_stats_arr[i].offset));
62255e4398dSVasundhara Volam 		}
62355e4398dSVasundhara Volam 	}
624c0c050c5SMichael Chan }
625c0c050c5SMichael Chan 
626c0c050c5SMichael Chan static void bnxt_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
627c0c050c5SMichael Chan {
628c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
62978e7b866SMichael Chan 	static const char * const *str;
630ee79566eSMichael Chan 	u32 i, j, num_str;
631c0c050c5SMichael Chan 
632c0c050c5SMichael Chan 	switch (stringset) {
633c0c050c5SMichael Chan 	case ETH_SS_STATS:
634c0c050c5SMichael Chan 		for (i = 0; i < bp->cp_nr_rings; i++) {
635ee79566eSMichael Chan 			num_str = ARRAY_SIZE(bnxt_ring_stats_str);
636ee79566eSMichael Chan 			for (j = 0; j < num_str; j++) {
637ee79566eSMichael Chan 				sprintf(buf, "[%d]: %s", i,
638ee79566eSMichael Chan 					bnxt_ring_stats_str[j]);
639c0c050c5SMichael Chan 				buf += ETH_GSTRING_LEN;
640ee79566eSMichael Chan 			}
641ee79566eSMichael Chan 			if (!BNXT_SUPPORTS_TPA(bp))
642ee79566eSMichael Chan 				goto skip_tpa_stats;
643ee79566eSMichael Chan 
64478e7b866SMichael Chan 			if (bp->max_tpa_v2) {
64578e7b866SMichael Chan 				num_str = ARRAY_SIZE(bnxt_ring_tpa2_stats_str);
64678e7b866SMichael Chan 				str = bnxt_ring_tpa2_stats_str;
64778e7b866SMichael Chan 			} else {
648ee79566eSMichael Chan 				num_str = ARRAY_SIZE(bnxt_ring_tpa_stats_str);
64978e7b866SMichael Chan 				str = bnxt_ring_tpa_stats_str;
65078e7b866SMichael Chan 			}
651ee79566eSMichael Chan 			for (j = 0; j < num_str; j++) {
65278e7b866SMichael Chan 				sprintf(buf, "[%d]: %s", i, str[j]);
653c0c050c5SMichael Chan 				buf += ETH_GSTRING_LEN;
654ee79566eSMichael Chan 			}
655ee79566eSMichael Chan skip_tpa_stats:
656ee79566eSMichael Chan 			num_str = ARRAY_SIZE(bnxt_ring_sw_stats_str);
657ee79566eSMichael Chan 			for (j = 0; j < num_str; j++) {
658ee79566eSMichael Chan 				sprintf(buf, "[%d]: %s", i,
659ee79566eSMichael Chan 					bnxt_ring_sw_stats_str[j]);
660c0c050c5SMichael Chan 				buf += ETH_GSTRING_LEN;
661ee79566eSMichael Chan 			}
662c0c050c5SMichael Chan 		}
66320c1d28eSVasundhara Volam 		for (i = 0; i < BNXT_NUM_SW_FUNC_STATS; i++) {
66420c1d28eSVasundhara Volam 			strcpy(buf, bnxt_sw_func_stats[i].string);
66520c1d28eSVasundhara Volam 			buf += ETH_GSTRING_LEN;
66620c1d28eSVasundhara Volam 		}
66720c1d28eSVasundhara Volam 
6688ddc9aaaSMichael Chan 		if (bp->flags & BNXT_FLAG_PORT_STATS) {
6698ddc9aaaSMichael Chan 			for (i = 0; i < BNXT_NUM_PORT_STATS; i++) {
6708ddc9aaaSMichael Chan 				strcpy(buf, bnxt_port_stats_arr[i].string);
6718ddc9aaaSMichael Chan 				buf += ETH_GSTRING_LEN;
6728ddc9aaaSMichael Chan 			}
6738ddc9aaaSMichael Chan 		}
67400db3cbaSVasundhara Volam 		if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) {
67536e53349SMichael Chan 			for (i = 0; i < bp->fw_rx_stats_ext_size; i++) {
67600db3cbaSVasundhara Volam 				strcpy(buf, bnxt_port_stats_ext_arr[i].string);
67700db3cbaSVasundhara Volam 				buf += ETH_GSTRING_LEN;
67800db3cbaSVasundhara Volam 			}
67936e53349SMichael Chan 			for (i = 0; i < bp->fw_tx_stats_ext_size; i++) {
68036e53349SMichael Chan 				strcpy(buf,
68136e53349SMichael Chan 				       bnxt_tx_port_stats_ext_arr[i].string);
68236e53349SMichael Chan 				buf += ETH_GSTRING_LEN;
68336e53349SMichael Chan 			}
684e37fed79SMichael Chan 			if (bp->pri2cos_valid) {
685e37fed79SMichael Chan 				for (i = 0; i < 8; i++) {
686e37fed79SMichael Chan 					strcpy(buf,
687e37fed79SMichael Chan 					       bnxt_rx_bytes_pri_arr[i].string);
688e37fed79SMichael Chan 					buf += ETH_GSTRING_LEN;
689e37fed79SMichael Chan 				}
690e37fed79SMichael Chan 				for (i = 0; i < 8; i++) {
691e37fed79SMichael Chan 					strcpy(buf,
692e37fed79SMichael Chan 					       bnxt_rx_pkts_pri_arr[i].string);
693e37fed79SMichael Chan 					buf += ETH_GSTRING_LEN;
694e37fed79SMichael Chan 				}
695e37fed79SMichael Chan 				for (i = 0; i < 8; i++) {
696e37fed79SMichael Chan 					strcpy(buf,
697e37fed79SMichael Chan 					       bnxt_tx_bytes_pri_arr[i].string);
698e37fed79SMichael Chan 					buf += ETH_GSTRING_LEN;
699e37fed79SMichael Chan 				}
700e37fed79SMichael Chan 				for (i = 0; i < 8; i++) {
701e37fed79SMichael Chan 					strcpy(buf,
702e37fed79SMichael Chan 					       bnxt_tx_pkts_pri_arr[i].string);
703e37fed79SMichael Chan 					buf += ETH_GSTRING_LEN;
704e37fed79SMichael Chan 				}
705e37fed79SMichael Chan 			}
70600db3cbaSVasundhara Volam 		}
70755e4398dSVasundhara Volam 		if (bp->flags & BNXT_FLAG_PCIE_STATS) {
70855e4398dSVasundhara Volam 			for (i = 0; i < BNXT_NUM_PCIE_STATS; i++) {
70955e4398dSVasundhara Volam 				strcpy(buf, bnxt_pcie_stats_arr[i].string);
71055e4398dSVasundhara Volam 				buf += ETH_GSTRING_LEN;
71155e4398dSVasundhara Volam 			}
71255e4398dSVasundhara Volam 		}
713c0c050c5SMichael Chan 		break;
714eb513658SMichael Chan 	case ETH_SS_TEST:
715eb513658SMichael Chan 		if (bp->num_tests)
716eb513658SMichael Chan 			memcpy(buf, bp->test_info->string,
717eb513658SMichael Chan 			       bp->num_tests * ETH_GSTRING_LEN);
718eb513658SMichael Chan 		break;
719c0c050c5SMichael Chan 	default:
720c0c050c5SMichael Chan 		netdev_err(bp->dev, "bnxt_get_strings invalid request %x\n",
721c0c050c5SMichael Chan 			   stringset);
722c0c050c5SMichael Chan 		break;
723c0c050c5SMichael Chan 	}
724c0c050c5SMichael Chan }
725c0c050c5SMichael Chan 
726c0c050c5SMichael Chan static void bnxt_get_ringparam(struct net_device *dev,
727c0c050c5SMichael Chan 			       struct ethtool_ringparam *ering)
728c0c050c5SMichael Chan {
729c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
730c0c050c5SMichael Chan 
731c0c050c5SMichael Chan 	ering->rx_max_pending = BNXT_MAX_RX_DESC_CNT;
732c0c050c5SMichael Chan 	ering->rx_jumbo_max_pending = BNXT_MAX_RX_JUM_DESC_CNT;
733c0c050c5SMichael Chan 	ering->tx_max_pending = BNXT_MAX_TX_DESC_CNT;
734c0c050c5SMichael Chan 
735c0c050c5SMichael Chan 	ering->rx_pending = bp->rx_ring_size;
736c0c050c5SMichael Chan 	ering->rx_jumbo_pending = bp->rx_agg_ring_size;
737c0c050c5SMichael Chan 	ering->tx_pending = bp->tx_ring_size;
738c0c050c5SMichael Chan }
739c0c050c5SMichael Chan 
740c0c050c5SMichael Chan static int bnxt_set_ringparam(struct net_device *dev,
741c0c050c5SMichael Chan 			      struct ethtool_ringparam *ering)
742c0c050c5SMichael Chan {
743c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
744c0c050c5SMichael Chan 
745c0c050c5SMichael Chan 	if ((ering->rx_pending > BNXT_MAX_RX_DESC_CNT) ||
746c0c050c5SMichael Chan 	    (ering->tx_pending > BNXT_MAX_TX_DESC_CNT) ||
747c0c050c5SMichael Chan 	    (ering->tx_pending <= MAX_SKB_FRAGS))
748c0c050c5SMichael Chan 		return -EINVAL;
749c0c050c5SMichael Chan 
750c0c050c5SMichael Chan 	if (netif_running(dev))
751c0c050c5SMichael Chan 		bnxt_close_nic(bp, false, false);
752c0c050c5SMichael Chan 
753c0c050c5SMichael Chan 	bp->rx_ring_size = ering->rx_pending;
754c0c050c5SMichael Chan 	bp->tx_ring_size = ering->tx_pending;
755c0c050c5SMichael Chan 	bnxt_set_ring_params(bp);
756c0c050c5SMichael Chan 
757c0c050c5SMichael Chan 	if (netif_running(dev))
758c0c050c5SMichael Chan 		return bnxt_open_nic(bp, false, false);
759c0c050c5SMichael Chan 
760c0c050c5SMichael Chan 	return 0;
761c0c050c5SMichael Chan }
762c0c050c5SMichael Chan 
763c0c050c5SMichael Chan static void bnxt_get_channels(struct net_device *dev,
764c0c050c5SMichael Chan 			      struct ethtool_channels *channel)
765c0c050c5SMichael Chan {
766c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
767db4723b3SMichael Chan 	struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
768c0c050c5SMichael Chan 	int max_rx_rings, max_tx_rings, tcs;
769db4723b3SMichael Chan 	int max_tx_sch_inputs;
770db4723b3SMichael Chan 
771db4723b3SMichael Chan 	/* Get the most up-to-date max_tx_sch_inputs. */
772f1ca94deSMichael Chan 	if (BNXT_NEW_RM(bp))
773db4723b3SMichael Chan 		bnxt_hwrm_func_resc_qcaps(bp, false);
774db4723b3SMichael Chan 	max_tx_sch_inputs = hw_resc->max_tx_sch_inputs;
775c0c050c5SMichael Chan 
7766e6c5a57SMichael Chan 	bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, true);
777db4723b3SMichael Chan 	if (max_tx_sch_inputs)
778db4723b3SMichael Chan 		max_tx_rings = min_t(int, max_tx_rings, max_tx_sch_inputs);
779a79a5276SMichael Chan 	channel->max_combined = min_t(int, max_rx_rings, max_tx_rings);
780068c9ec6SMichael Chan 
78118d6e4e2SSatish Baddipadige 	if (bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, false)) {
78218d6e4e2SSatish Baddipadige 		max_rx_rings = 0;
78318d6e4e2SSatish Baddipadige 		max_tx_rings = 0;
78418d6e4e2SSatish Baddipadige 	}
785db4723b3SMichael Chan 	if (max_tx_sch_inputs)
786db4723b3SMichael Chan 		max_tx_rings = min_t(int, max_tx_rings, max_tx_sch_inputs);
78718d6e4e2SSatish Baddipadige 
788c0c050c5SMichael Chan 	tcs = netdev_get_num_tc(dev);
789c0c050c5SMichael Chan 	if (tcs > 1)
790c0c050c5SMichael Chan 		max_tx_rings /= tcs;
791c0c050c5SMichael Chan 
792c0c050c5SMichael Chan 	channel->max_rx = max_rx_rings;
793c0c050c5SMichael Chan 	channel->max_tx = max_tx_rings;
794c0c050c5SMichael Chan 	channel->max_other = 0;
795068c9ec6SMichael Chan 	if (bp->flags & BNXT_FLAG_SHARED_RINGS) {
796068c9ec6SMichael Chan 		channel->combined_count = bp->rx_nr_rings;
79776595193SPrashant Sreedharan 		if (BNXT_CHIP_TYPE_NITRO_A0(bp))
79876595193SPrashant Sreedharan 			channel->combined_count--;
799068c9ec6SMichael Chan 	} else {
80076595193SPrashant Sreedharan 		if (!BNXT_CHIP_TYPE_NITRO_A0(bp)) {
801c0c050c5SMichael Chan 			channel->rx_count = bp->rx_nr_rings;
802c0c050c5SMichael Chan 			channel->tx_count = bp->tx_nr_rings_per_tc;
803c0c050c5SMichael Chan 		}
804068c9ec6SMichael Chan 	}
80576595193SPrashant Sreedharan }
806c0c050c5SMichael Chan 
807c0c050c5SMichael Chan static int bnxt_set_channels(struct net_device *dev,
808c0c050c5SMichael Chan 			     struct ethtool_channels *channel)
809c0c050c5SMichael Chan {
810c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
811d1e7925eSMichael Chan 	int req_tx_rings, req_rx_rings, tcs;
812068c9ec6SMichael Chan 	bool sh = false;
8135f449249SMichael Chan 	int tx_xdp = 0;
814d1e7925eSMichael Chan 	int rc = 0;
815c0c050c5SMichael Chan 
816068c9ec6SMichael Chan 	if (channel->other_count)
817c0c050c5SMichael Chan 		return -EINVAL;
818c0c050c5SMichael Chan 
819068c9ec6SMichael Chan 	if (!channel->combined_count &&
820068c9ec6SMichael Chan 	    (!channel->rx_count || !channel->tx_count))
821068c9ec6SMichael Chan 		return -EINVAL;
822068c9ec6SMichael Chan 
823068c9ec6SMichael Chan 	if (channel->combined_count &&
824068c9ec6SMichael Chan 	    (channel->rx_count || channel->tx_count))
825068c9ec6SMichael Chan 		return -EINVAL;
826068c9ec6SMichael Chan 
82776595193SPrashant Sreedharan 	if (BNXT_CHIP_TYPE_NITRO_A0(bp) && (channel->rx_count ||
82876595193SPrashant Sreedharan 					    channel->tx_count))
82976595193SPrashant Sreedharan 		return -EINVAL;
83076595193SPrashant Sreedharan 
831068c9ec6SMichael Chan 	if (channel->combined_count)
832068c9ec6SMichael Chan 		sh = true;
833068c9ec6SMichael Chan 
834c0c050c5SMichael Chan 	tcs = netdev_get_num_tc(dev);
835c0c050c5SMichael Chan 
836391be5c2SMichael Chan 	req_tx_rings = sh ? channel->combined_count : channel->tx_count;
837d1e7925eSMichael Chan 	req_rx_rings = sh ? channel->combined_count : channel->rx_count;
8385f449249SMichael Chan 	if (bp->tx_nr_rings_xdp) {
8395f449249SMichael Chan 		if (!sh) {
8405f449249SMichael Chan 			netdev_err(dev, "Only combined mode supported when XDP is enabled.\n");
8415f449249SMichael Chan 			return -EINVAL;
8425f449249SMichael Chan 		}
8435f449249SMichael Chan 		tx_xdp = req_rx_rings;
8445f449249SMichael Chan 	}
84598fdbe73SMichael Chan 	rc = bnxt_check_rings(bp, req_tx_rings, req_rx_rings, sh, tcs, tx_xdp);
846d1e7925eSMichael Chan 	if (rc) {
847d1e7925eSMichael Chan 		netdev_warn(dev, "Unable to allocate the requested rings\n");
848d1e7925eSMichael Chan 		return rc;
849391be5c2SMichael Chan 	}
850391be5c2SMichael Chan 
851c0c050c5SMichael Chan 	if (netif_running(dev)) {
852c0c050c5SMichael Chan 		if (BNXT_PF(bp)) {
853c0c050c5SMichael Chan 			/* TODO CHIMP_FW: Send message to all VF's
854c0c050c5SMichael Chan 			 * before PF unload
855c0c050c5SMichael Chan 			 */
856c0c050c5SMichael Chan 		}
857c0c050c5SMichael Chan 		rc = bnxt_close_nic(bp, true, false);
858c0c050c5SMichael Chan 		if (rc) {
859c0c050c5SMichael Chan 			netdev_err(bp->dev, "Set channel failure rc :%x\n",
860c0c050c5SMichael Chan 				   rc);
861c0c050c5SMichael Chan 			return rc;
862c0c050c5SMichael Chan 		}
863c0c050c5SMichael Chan 	}
864c0c050c5SMichael Chan 
865068c9ec6SMichael Chan 	if (sh) {
866068c9ec6SMichael Chan 		bp->flags |= BNXT_FLAG_SHARED_RINGS;
867d1e7925eSMichael Chan 		bp->rx_nr_rings = channel->combined_count;
868d1e7925eSMichael Chan 		bp->tx_nr_rings_per_tc = channel->combined_count;
869068c9ec6SMichael Chan 	} else {
870068c9ec6SMichael Chan 		bp->flags &= ~BNXT_FLAG_SHARED_RINGS;
871c0c050c5SMichael Chan 		bp->rx_nr_rings = channel->rx_count;
872c0c050c5SMichael Chan 		bp->tx_nr_rings_per_tc = channel->tx_count;
873068c9ec6SMichael Chan 	}
8745f449249SMichael Chan 	bp->tx_nr_rings_xdp = tx_xdp;
8755f449249SMichael Chan 	bp->tx_nr_rings = bp->tx_nr_rings_per_tc + tx_xdp;
876c0c050c5SMichael Chan 	if (tcs > 1)
8775f449249SMichael Chan 		bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tcs + tx_xdp;
878068c9ec6SMichael Chan 
879068c9ec6SMichael Chan 	bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
880068c9ec6SMichael Chan 			       bp->tx_nr_rings + bp->rx_nr_rings;
881068c9ec6SMichael Chan 
8822bcfa6f6SMichael Chan 	/* After changing number of rx channels, update NTUPLE feature. */
8832bcfa6f6SMichael Chan 	netdev_update_features(dev);
884c0c050c5SMichael Chan 	if (netif_running(dev)) {
885c0c050c5SMichael Chan 		rc = bnxt_open_nic(bp, true, false);
886c0c050c5SMichael Chan 		if ((!rc) && BNXT_PF(bp)) {
887c0c050c5SMichael Chan 			/* TODO CHIMP_FW: Send message to all VF's
888c0c050c5SMichael Chan 			 * to renable
889c0c050c5SMichael Chan 			 */
890c0c050c5SMichael Chan 		}
891d8c09f19SMichael Chan 	} else {
8921b3f0b75SMichael Chan 		rc = bnxt_reserve_rings(bp, true);
893c0c050c5SMichael Chan 	}
894c0c050c5SMichael Chan 
895c0c050c5SMichael Chan 	return rc;
896c0c050c5SMichael Chan }
897c0c050c5SMichael Chan 
898c0c050c5SMichael Chan #ifdef CONFIG_RFS_ACCEL
899c0c050c5SMichael Chan static int bnxt_grxclsrlall(struct bnxt *bp, struct ethtool_rxnfc *cmd,
900c0c050c5SMichael Chan 			    u32 *rule_locs)
901c0c050c5SMichael Chan {
902c0c050c5SMichael Chan 	int i, j = 0;
903c0c050c5SMichael Chan 
904c0c050c5SMichael Chan 	cmd->data = bp->ntp_fltr_count;
905c0c050c5SMichael Chan 	for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
906c0c050c5SMichael Chan 		struct hlist_head *head;
907c0c050c5SMichael Chan 		struct bnxt_ntuple_filter *fltr;
908c0c050c5SMichael Chan 
909c0c050c5SMichael Chan 		head = &bp->ntp_fltr_hash_tbl[i];
910c0c050c5SMichael Chan 		rcu_read_lock();
911c0c050c5SMichael Chan 		hlist_for_each_entry_rcu(fltr, head, hash) {
912c0c050c5SMichael Chan 			if (j == cmd->rule_cnt)
913c0c050c5SMichael Chan 				break;
914c0c050c5SMichael Chan 			rule_locs[j++] = fltr->sw_id;
915c0c050c5SMichael Chan 		}
916c0c050c5SMichael Chan 		rcu_read_unlock();
917c0c050c5SMichael Chan 		if (j == cmd->rule_cnt)
918c0c050c5SMichael Chan 			break;
919c0c050c5SMichael Chan 	}
920c0c050c5SMichael Chan 	cmd->rule_cnt = j;
921c0c050c5SMichael Chan 	return 0;
922c0c050c5SMichael Chan }
923c0c050c5SMichael Chan 
924c0c050c5SMichael Chan static int bnxt_grxclsrule(struct bnxt *bp, struct ethtool_rxnfc *cmd)
925c0c050c5SMichael Chan {
926c0c050c5SMichael Chan 	struct ethtool_rx_flow_spec *fs =
927c0c050c5SMichael Chan 		(struct ethtool_rx_flow_spec *)&cmd->fs;
928c0c050c5SMichael Chan 	struct bnxt_ntuple_filter *fltr;
929c0c050c5SMichael Chan 	struct flow_keys *fkeys;
930c0c050c5SMichael Chan 	int i, rc = -EINVAL;
931c0c050c5SMichael Chan 
932b721cfafSstephen hemminger 	if (fs->location >= BNXT_NTP_FLTR_MAX_FLTR)
933c0c050c5SMichael Chan 		return rc;
934c0c050c5SMichael Chan 
935c0c050c5SMichael Chan 	for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
936c0c050c5SMichael Chan 		struct hlist_head *head;
937c0c050c5SMichael Chan 
938c0c050c5SMichael Chan 		head = &bp->ntp_fltr_hash_tbl[i];
939c0c050c5SMichael Chan 		rcu_read_lock();
940c0c050c5SMichael Chan 		hlist_for_each_entry_rcu(fltr, head, hash) {
941c0c050c5SMichael Chan 			if (fltr->sw_id == fs->location)
942c0c050c5SMichael Chan 				goto fltr_found;
943c0c050c5SMichael Chan 		}
944c0c050c5SMichael Chan 		rcu_read_unlock();
945c0c050c5SMichael Chan 	}
946c0c050c5SMichael Chan 	return rc;
947c0c050c5SMichael Chan 
948c0c050c5SMichael Chan fltr_found:
949c0c050c5SMichael Chan 	fkeys = &fltr->fkeys;
950dda0e746SMichael Chan 	if (fkeys->basic.n_proto == htons(ETH_P_IP)) {
951c0c050c5SMichael Chan 		if (fkeys->basic.ip_proto == IPPROTO_TCP)
952c0c050c5SMichael Chan 			fs->flow_type = TCP_V4_FLOW;
953c0c050c5SMichael Chan 		else if (fkeys->basic.ip_proto == IPPROTO_UDP)
954c0c050c5SMichael Chan 			fs->flow_type = UDP_V4_FLOW;
955c0c050c5SMichael Chan 		else
956c0c050c5SMichael Chan 			goto fltr_err;
957c0c050c5SMichael Chan 
958c0c050c5SMichael Chan 		fs->h_u.tcp_ip4_spec.ip4src = fkeys->addrs.v4addrs.src;
959c0c050c5SMichael Chan 		fs->m_u.tcp_ip4_spec.ip4src = cpu_to_be32(~0);
960c0c050c5SMichael Chan 
961c0c050c5SMichael Chan 		fs->h_u.tcp_ip4_spec.ip4dst = fkeys->addrs.v4addrs.dst;
962c0c050c5SMichael Chan 		fs->m_u.tcp_ip4_spec.ip4dst = cpu_to_be32(~0);
963c0c050c5SMichael Chan 
964c0c050c5SMichael Chan 		fs->h_u.tcp_ip4_spec.psrc = fkeys->ports.src;
965c0c050c5SMichael Chan 		fs->m_u.tcp_ip4_spec.psrc = cpu_to_be16(~0);
966c0c050c5SMichael Chan 
967c0c050c5SMichael Chan 		fs->h_u.tcp_ip4_spec.pdst = fkeys->ports.dst;
968c0c050c5SMichael Chan 		fs->m_u.tcp_ip4_spec.pdst = cpu_to_be16(~0);
969dda0e746SMichael Chan 	} else {
970dda0e746SMichael Chan 		int i;
971dda0e746SMichael Chan 
972dda0e746SMichael Chan 		if (fkeys->basic.ip_proto == IPPROTO_TCP)
973dda0e746SMichael Chan 			fs->flow_type = TCP_V6_FLOW;
974dda0e746SMichael Chan 		else if (fkeys->basic.ip_proto == IPPROTO_UDP)
975dda0e746SMichael Chan 			fs->flow_type = UDP_V6_FLOW;
976dda0e746SMichael Chan 		else
977dda0e746SMichael Chan 			goto fltr_err;
978dda0e746SMichael Chan 
979dda0e746SMichael Chan 		*(struct in6_addr *)&fs->h_u.tcp_ip6_spec.ip6src[0] =
980dda0e746SMichael Chan 			fkeys->addrs.v6addrs.src;
981dda0e746SMichael Chan 		*(struct in6_addr *)&fs->h_u.tcp_ip6_spec.ip6dst[0] =
982dda0e746SMichael Chan 			fkeys->addrs.v6addrs.dst;
983dda0e746SMichael Chan 		for (i = 0; i < 4; i++) {
984dda0e746SMichael Chan 			fs->m_u.tcp_ip6_spec.ip6src[i] = cpu_to_be32(~0);
985dda0e746SMichael Chan 			fs->m_u.tcp_ip6_spec.ip6dst[i] = cpu_to_be32(~0);
986dda0e746SMichael Chan 		}
987dda0e746SMichael Chan 		fs->h_u.tcp_ip6_spec.psrc = fkeys->ports.src;
988dda0e746SMichael Chan 		fs->m_u.tcp_ip6_spec.psrc = cpu_to_be16(~0);
989dda0e746SMichael Chan 
990dda0e746SMichael Chan 		fs->h_u.tcp_ip6_spec.pdst = fkeys->ports.dst;
991dda0e746SMichael Chan 		fs->m_u.tcp_ip6_spec.pdst = cpu_to_be16(~0);
992dda0e746SMichael Chan 	}
993c0c050c5SMichael Chan 
994c0c050c5SMichael Chan 	fs->ring_cookie = fltr->rxq;
995c0c050c5SMichael Chan 	rc = 0;
996c0c050c5SMichael Chan 
997c0c050c5SMichael Chan fltr_err:
998c0c050c5SMichael Chan 	rcu_read_unlock();
999c0c050c5SMichael Chan 
1000c0c050c5SMichael Chan 	return rc;
1001c0c050c5SMichael Chan }
1002a011952aSMichael Chan #endif
1003a011952aSMichael Chan 
1004a011952aSMichael Chan static u64 get_ethtool_ipv4_rss(struct bnxt *bp)
1005a011952aSMichael Chan {
1006a011952aSMichael Chan 	if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4)
1007a011952aSMichael Chan 		return RXH_IP_SRC | RXH_IP_DST;
1008a011952aSMichael Chan 	return 0;
1009a011952aSMichael Chan }
1010a011952aSMichael Chan 
1011a011952aSMichael Chan static u64 get_ethtool_ipv6_rss(struct bnxt *bp)
1012a011952aSMichael Chan {
1013a011952aSMichael Chan 	if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6)
1014a011952aSMichael Chan 		return RXH_IP_SRC | RXH_IP_DST;
1015a011952aSMichael Chan 	return 0;
1016a011952aSMichael Chan }
1017a011952aSMichael Chan 
1018a011952aSMichael Chan static int bnxt_grxfh(struct bnxt *bp, struct ethtool_rxnfc *cmd)
1019a011952aSMichael Chan {
1020a011952aSMichael Chan 	cmd->data = 0;
1021a011952aSMichael Chan 	switch (cmd->flow_type) {
1022a011952aSMichael Chan 	case TCP_V4_FLOW:
1023a011952aSMichael Chan 		if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4)
1024a011952aSMichael Chan 			cmd->data |= RXH_IP_SRC | RXH_IP_DST |
1025a011952aSMichael Chan 				     RXH_L4_B_0_1 | RXH_L4_B_2_3;
1026a011952aSMichael Chan 		cmd->data |= get_ethtool_ipv4_rss(bp);
1027a011952aSMichael Chan 		break;
1028a011952aSMichael Chan 	case UDP_V4_FLOW:
1029a011952aSMichael Chan 		if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4)
1030a011952aSMichael Chan 			cmd->data |= RXH_IP_SRC | RXH_IP_DST |
1031a011952aSMichael Chan 				     RXH_L4_B_0_1 | RXH_L4_B_2_3;
1032a011952aSMichael Chan 		/* fall through */
1033a011952aSMichael Chan 	case SCTP_V4_FLOW:
1034a011952aSMichael Chan 	case AH_ESP_V4_FLOW:
1035a011952aSMichael Chan 	case AH_V4_FLOW:
1036a011952aSMichael Chan 	case ESP_V4_FLOW:
1037a011952aSMichael Chan 	case IPV4_FLOW:
1038a011952aSMichael Chan 		cmd->data |= get_ethtool_ipv4_rss(bp);
1039a011952aSMichael Chan 		break;
1040a011952aSMichael Chan 
1041a011952aSMichael Chan 	case TCP_V6_FLOW:
1042a011952aSMichael Chan 		if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6)
1043a011952aSMichael Chan 			cmd->data |= RXH_IP_SRC | RXH_IP_DST |
1044a011952aSMichael Chan 				     RXH_L4_B_0_1 | RXH_L4_B_2_3;
1045a011952aSMichael Chan 		cmd->data |= get_ethtool_ipv6_rss(bp);
1046a011952aSMichael Chan 		break;
1047a011952aSMichael Chan 	case UDP_V6_FLOW:
1048a011952aSMichael Chan 		if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6)
1049a011952aSMichael Chan 			cmd->data |= RXH_IP_SRC | RXH_IP_DST |
1050a011952aSMichael Chan 				     RXH_L4_B_0_1 | RXH_L4_B_2_3;
1051a011952aSMichael Chan 		/* fall through */
1052a011952aSMichael Chan 	case SCTP_V6_FLOW:
1053a011952aSMichael Chan 	case AH_ESP_V6_FLOW:
1054a011952aSMichael Chan 	case AH_V6_FLOW:
1055a011952aSMichael Chan 	case ESP_V6_FLOW:
1056a011952aSMichael Chan 	case IPV6_FLOW:
1057a011952aSMichael Chan 		cmd->data |= get_ethtool_ipv6_rss(bp);
1058a011952aSMichael Chan 		break;
1059a011952aSMichael Chan 	}
1060a011952aSMichael Chan 	return 0;
1061a011952aSMichael Chan }
1062a011952aSMichael Chan 
1063a011952aSMichael Chan #define RXH_4TUPLE (RXH_IP_SRC | RXH_IP_DST | RXH_L4_B_0_1 | RXH_L4_B_2_3)
1064a011952aSMichael Chan #define RXH_2TUPLE (RXH_IP_SRC | RXH_IP_DST)
1065a011952aSMichael Chan 
1066a011952aSMichael Chan static int bnxt_srxfh(struct bnxt *bp, struct ethtool_rxnfc *cmd)
1067a011952aSMichael Chan {
1068a011952aSMichael Chan 	u32 rss_hash_cfg = bp->rss_hash_cfg;
1069a011952aSMichael Chan 	int tuple, rc = 0;
1070a011952aSMichael Chan 
1071a011952aSMichael Chan 	if (cmd->data == RXH_4TUPLE)
1072a011952aSMichael Chan 		tuple = 4;
1073a011952aSMichael Chan 	else if (cmd->data == RXH_2TUPLE)
1074a011952aSMichael Chan 		tuple = 2;
1075a011952aSMichael Chan 	else if (!cmd->data)
1076a011952aSMichael Chan 		tuple = 0;
1077a011952aSMichael Chan 	else
1078a011952aSMichael Chan 		return -EINVAL;
1079a011952aSMichael Chan 
1080a011952aSMichael Chan 	if (cmd->flow_type == TCP_V4_FLOW) {
1081a011952aSMichael Chan 		rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4;
1082a011952aSMichael Chan 		if (tuple == 4)
1083a011952aSMichael Chan 			rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4;
1084a011952aSMichael Chan 	} else if (cmd->flow_type == UDP_V4_FLOW) {
1085a011952aSMichael Chan 		if (tuple == 4 && !(bp->flags & BNXT_FLAG_UDP_RSS_CAP))
1086a011952aSMichael Chan 			return -EINVAL;
1087a011952aSMichael Chan 		rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4;
1088a011952aSMichael Chan 		if (tuple == 4)
1089a011952aSMichael Chan 			rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4;
1090a011952aSMichael Chan 	} else if (cmd->flow_type == TCP_V6_FLOW) {
1091a011952aSMichael Chan 		rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6;
1092a011952aSMichael Chan 		if (tuple == 4)
1093a011952aSMichael Chan 			rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6;
1094a011952aSMichael Chan 	} else if (cmd->flow_type == UDP_V6_FLOW) {
1095a011952aSMichael Chan 		if (tuple == 4 && !(bp->flags & BNXT_FLAG_UDP_RSS_CAP))
1096a011952aSMichael Chan 			return -EINVAL;
1097a011952aSMichael Chan 		rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6;
1098a011952aSMichael Chan 		if (tuple == 4)
1099a011952aSMichael Chan 			rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6;
1100a011952aSMichael Chan 	} else if (tuple == 4) {
1101a011952aSMichael Chan 		return -EINVAL;
1102a011952aSMichael Chan 	}
1103a011952aSMichael Chan 
1104a011952aSMichael Chan 	switch (cmd->flow_type) {
1105a011952aSMichael Chan 	case TCP_V4_FLOW:
1106a011952aSMichael Chan 	case UDP_V4_FLOW:
1107a011952aSMichael Chan 	case SCTP_V4_FLOW:
1108a011952aSMichael Chan 	case AH_ESP_V4_FLOW:
1109a011952aSMichael Chan 	case AH_V4_FLOW:
1110a011952aSMichael Chan 	case ESP_V4_FLOW:
1111a011952aSMichael Chan 	case IPV4_FLOW:
1112a011952aSMichael Chan 		if (tuple == 2)
1113a011952aSMichael Chan 			rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4;
1114a011952aSMichael Chan 		else if (!tuple)
1115a011952aSMichael Chan 			rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4;
1116a011952aSMichael Chan 		break;
1117a011952aSMichael Chan 
1118a011952aSMichael Chan 	case TCP_V6_FLOW:
1119a011952aSMichael Chan 	case UDP_V6_FLOW:
1120a011952aSMichael Chan 	case SCTP_V6_FLOW:
1121a011952aSMichael Chan 	case AH_ESP_V6_FLOW:
1122a011952aSMichael Chan 	case AH_V6_FLOW:
1123a011952aSMichael Chan 	case ESP_V6_FLOW:
1124a011952aSMichael Chan 	case IPV6_FLOW:
1125a011952aSMichael Chan 		if (tuple == 2)
1126a011952aSMichael Chan 			rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6;
1127a011952aSMichael Chan 		else if (!tuple)
1128a011952aSMichael Chan 			rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6;
1129a011952aSMichael Chan 		break;
1130a011952aSMichael Chan 	}
1131a011952aSMichael Chan 
1132a011952aSMichael Chan 	if (bp->rss_hash_cfg == rss_hash_cfg)
1133a011952aSMichael Chan 		return 0;
1134a011952aSMichael Chan 
1135a011952aSMichael Chan 	bp->rss_hash_cfg = rss_hash_cfg;
1136a011952aSMichael Chan 	if (netif_running(bp->dev)) {
1137a011952aSMichael Chan 		bnxt_close_nic(bp, false, false);
1138a011952aSMichael Chan 		rc = bnxt_open_nic(bp, false, false);
1139a011952aSMichael Chan 	}
1140a011952aSMichael Chan 	return rc;
1141a011952aSMichael Chan }
1142c0c050c5SMichael Chan 
1143c0c050c5SMichael Chan static int bnxt_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
1144c0c050c5SMichael Chan 			  u32 *rule_locs)
1145c0c050c5SMichael Chan {
1146c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
1147c0c050c5SMichael Chan 	int rc = 0;
1148c0c050c5SMichael Chan 
1149c0c050c5SMichael Chan 	switch (cmd->cmd) {
1150a011952aSMichael Chan #ifdef CONFIG_RFS_ACCEL
1151c0c050c5SMichael Chan 	case ETHTOOL_GRXRINGS:
1152c0c050c5SMichael Chan 		cmd->data = bp->rx_nr_rings;
1153c0c050c5SMichael Chan 		break;
1154c0c050c5SMichael Chan 
1155c0c050c5SMichael Chan 	case ETHTOOL_GRXCLSRLCNT:
1156c0c050c5SMichael Chan 		cmd->rule_cnt = bp->ntp_fltr_count;
1157c0c050c5SMichael Chan 		cmd->data = BNXT_NTP_FLTR_MAX_FLTR;
1158c0c050c5SMichael Chan 		break;
1159c0c050c5SMichael Chan 
1160c0c050c5SMichael Chan 	case ETHTOOL_GRXCLSRLALL:
1161c0c050c5SMichael Chan 		rc = bnxt_grxclsrlall(bp, cmd, (u32 *)rule_locs);
1162c0c050c5SMichael Chan 		break;
1163c0c050c5SMichael Chan 
1164c0c050c5SMichael Chan 	case ETHTOOL_GRXCLSRULE:
1165c0c050c5SMichael Chan 		rc = bnxt_grxclsrule(bp, cmd);
1166c0c050c5SMichael Chan 		break;
1167a011952aSMichael Chan #endif
1168a011952aSMichael Chan 
1169a011952aSMichael Chan 	case ETHTOOL_GRXFH:
1170a011952aSMichael Chan 		rc = bnxt_grxfh(bp, cmd);
1171a011952aSMichael Chan 		break;
1172c0c050c5SMichael Chan 
1173c0c050c5SMichael Chan 	default:
1174c0c050c5SMichael Chan 		rc = -EOPNOTSUPP;
1175c0c050c5SMichael Chan 		break;
1176c0c050c5SMichael Chan 	}
1177c0c050c5SMichael Chan 
1178c0c050c5SMichael Chan 	return rc;
1179c0c050c5SMichael Chan }
1180a011952aSMichael Chan 
1181a011952aSMichael Chan static int bnxt_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
1182a011952aSMichael Chan {
1183a011952aSMichael Chan 	struct bnxt *bp = netdev_priv(dev);
1184a011952aSMichael Chan 	int rc;
1185a011952aSMichael Chan 
1186a011952aSMichael Chan 	switch (cmd->cmd) {
1187a011952aSMichael Chan 	case ETHTOOL_SRXFH:
1188a011952aSMichael Chan 		rc = bnxt_srxfh(bp, cmd);
1189a011952aSMichael Chan 		break;
1190a011952aSMichael Chan 
1191a011952aSMichael Chan 	default:
1192a011952aSMichael Chan 		rc = -EOPNOTSUPP;
1193a011952aSMichael Chan 		break;
1194a011952aSMichael Chan 	}
1195a011952aSMichael Chan 	return rc;
1196a011952aSMichael Chan }
1197c0c050c5SMichael Chan 
1198c0c050c5SMichael Chan static u32 bnxt_get_rxfh_indir_size(struct net_device *dev)
1199c0c050c5SMichael Chan {
1200c0c050c5SMichael Chan 	return HW_HASH_INDEX_SIZE;
1201c0c050c5SMichael Chan }
1202c0c050c5SMichael Chan 
1203c0c050c5SMichael Chan static u32 bnxt_get_rxfh_key_size(struct net_device *dev)
1204c0c050c5SMichael Chan {
1205c0c050c5SMichael Chan 	return HW_HASH_KEY_SIZE;
1206c0c050c5SMichael Chan }
1207c0c050c5SMichael Chan 
1208c0c050c5SMichael Chan static int bnxt_get_rxfh(struct net_device *dev, u32 *indir, u8 *key,
1209c0c050c5SMichael Chan 			 u8 *hfunc)
1210c0c050c5SMichael Chan {
1211c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
12127991cb9cSMichael Chan 	struct bnxt_vnic_info *vnic;
1213c0c050c5SMichael Chan 	int i = 0;
1214c0c050c5SMichael Chan 
1215c0c050c5SMichael Chan 	if (hfunc)
1216c0c050c5SMichael Chan 		*hfunc = ETH_RSS_HASH_TOP;
1217c0c050c5SMichael Chan 
12187991cb9cSMichael Chan 	if (!bp->vnic_info)
12197991cb9cSMichael Chan 		return 0;
12207991cb9cSMichael Chan 
12217991cb9cSMichael Chan 	vnic = &bp->vnic_info[0];
12227991cb9cSMichael Chan 	if (indir && vnic->rss_table) {
1223c0c050c5SMichael Chan 		for (i = 0; i < HW_HASH_INDEX_SIZE; i++)
1224c0c050c5SMichael Chan 			indir[i] = le16_to_cpu(vnic->rss_table[i]);
12257991cb9cSMichael Chan 	}
1226c0c050c5SMichael Chan 
12277991cb9cSMichael Chan 	if (key && vnic->rss_hash_key)
1228c0c050c5SMichael Chan 		memcpy(key, vnic->rss_hash_key, HW_HASH_KEY_SIZE);
1229c0c050c5SMichael Chan 
1230c0c050c5SMichael Chan 	return 0;
1231c0c050c5SMichael Chan }
1232c0c050c5SMichael Chan 
1233c0c050c5SMichael Chan static void bnxt_get_drvinfo(struct net_device *dev,
1234c0c050c5SMichael Chan 			     struct ethtool_drvinfo *info)
1235c0c050c5SMichael Chan {
1236c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
1237c0c050c5SMichael Chan 
1238c0c050c5SMichael Chan 	strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver));
1239431aa1ebSMichael Chan 	strlcpy(info->fw_version, bp->fw_ver_str, sizeof(info->fw_version));
1240c0c050c5SMichael Chan 	strlcpy(info->bus_info, pci_name(bp->pdev), sizeof(info->bus_info));
12415c8227d0SMichael Chan 	info->n_stats = bnxt_get_num_stats(bp);
1242eb513658SMichael Chan 	info->testinfo_len = bp->num_tests;
1243c0c050c5SMichael Chan 	/* TODO CHIMP_FW: eeprom dump details */
1244c0c050c5SMichael Chan 	info->eedump_len = 0;
1245c0c050c5SMichael Chan 	/* TODO CHIMP FW: reg dump details */
1246c0c050c5SMichael Chan 	info->regdump_len = 0;
1247c0c050c5SMichael Chan }
1248c0c050c5SMichael Chan 
12498e202366SMichael Chan static void bnxt_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
12508e202366SMichael Chan {
12518e202366SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
12528e202366SMichael Chan 
12538e202366SMichael Chan 	wol->supported = 0;
12548e202366SMichael Chan 	wol->wolopts = 0;
12558e202366SMichael Chan 	memset(&wol->sopass, 0, sizeof(wol->sopass));
12568e202366SMichael Chan 	if (bp->flags & BNXT_FLAG_WOL_CAP) {
12578e202366SMichael Chan 		wol->supported = WAKE_MAGIC;
12588e202366SMichael Chan 		if (bp->wol)
12598e202366SMichael Chan 			wol->wolopts = WAKE_MAGIC;
12608e202366SMichael Chan 	}
12618e202366SMichael Chan }
12628e202366SMichael Chan 
12635282db6cSMichael Chan static int bnxt_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
12645282db6cSMichael Chan {
12655282db6cSMichael Chan 	struct bnxt *bp = netdev_priv(dev);
12665282db6cSMichael Chan 
12675282db6cSMichael Chan 	if (wol->wolopts & ~WAKE_MAGIC)
12685282db6cSMichael Chan 		return -EINVAL;
12695282db6cSMichael Chan 
12705282db6cSMichael Chan 	if (wol->wolopts & WAKE_MAGIC) {
12715282db6cSMichael Chan 		if (!(bp->flags & BNXT_FLAG_WOL_CAP))
12725282db6cSMichael Chan 			return -EINVAL;
12735282db6cSMichael Chan 		if (!bp->wol) {
12745282db6cSMichael Chan 			if (bnxt_hwrm_alloc_wol_fltr(bp))
12755282db6cSMichael Chan 				return -EBUSY;
12765282db6cSMichael Chan 			bp->wol = 1;
12775282db6cSMichael Chan 		}
12785282db6cSMichael Chan 	} else {
12795282db6cSMichael Chan 		if (bp->wol) {
12805282db6cSMichael Chan 			if (bnxt_hwrm_free_wol_fltr(bp))
12815282db6cSMichael Chan 				return -EBUSY;
12825282db6cSMichael Chan 			bp->wol = 0;
12835282db6cSMichael Chan 		}
12845282db6cSMichael Chan 	}
12855282db6cSMichael Chan 	return 0;
12865282db6cSMichael Chan }
12875282db6cSMichael Chan 
1288170ce013SMichael Chan u32 _bnxt_fw_to_ethtool_adv_spds(u16 fw_speeds, u8 fw_pause)
1289c0c050c5SMichael Chan {
1290c0c050c5SMichael Chan 	u32 speed_mask = 0;
1291c0c050c5SMichael Chan 
1292c0c050c5SMichael Chan 	/* TODO: support 25GB, 40GB, 50GB with different cable type */
1293c0c050c5SMichael Chan 	/* set the advertised speeds */
1294c0c050c5SMichael Chan 	if (fw_speeds & BNXT_LINK_SPEED_MSK_100MB)
1295c0c050c5SMichael Chan 		speed_mask |= ADVERTISED_100baseT_Full;
1296c0c050c5SMichael Chan 	if (fw_speeds & BNXT_LINK_SPEED_MSK_1GB)
1297c0c050c5SMichael Chan 		speed_mask |= ADVERTISED_1000baseT_Full;
1298c0c050c5SMichael Chan 	if (fw_speeds & BNXT_LINK_SPEED_MSK_2_5GB)
1299c0c050c5SMichael Chan 		speed_mask |= ADVERTISED_2500baseX_Full;
1300c0c050c5SMichael Chan 	if (fw_speeds & BNXT_LINK_SPEED_MSK_10GB)
1301c0c050c5SMichael Chan 		speed_mask |= ADVERTISED_10000baseT_Full;
1302c0c050c5SMichael Chan 	if (fw_speeds & BNXT_LINK_SPEED_MSK_40GB)
13031c49c421SMichael Chan 		speed_mask |= ADVERTISED_40000baseCR4_Full;
130427c4d578SMichael Chan 
130527c4d578SMichael Chan 	if ((fw_pause & BNXT_LINK_PAUSE_BOTH) == BNXT_LINK_PAUSE_BOTH)
130627c4d578SMichael Chan 		speed_mask |= ADVERTISED_Pause;
130727c4d578SMichael Chan 	else if (fw_pause & BNXT_LINK_PAUSE_TX)
130827c4d578SMichael Chan 		speed_mask |= ADVERTISED_Asym_Pause;
130927c4d578SMichael Chan 	else if (fw_pause & BNXT_LINK_PAUSE_RX)
131027c4d578SMichael Chan 		speed_mask |= ADVERTISED_Pause | ADVERTISED_Asym_Pause;
131127c4d578SMichael Chan 
1312c0c050c5SMichael Chan 	return speed_mask;
1313c0c050c5SMichael Chan }
1314c0c050c5SMichael Chan 
131500c04a92SMichael Chan #define BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, name)\
131600c04a92SMichael Chan {									\
131700c04a92SMichael Chan 	if ((fw_speeds) & BNXT_LINK_SPEED_MSK_100MB)			\
131800c04a92SMichael Chan 		ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
131900c04a92SMichael Chan 						     100baseT_Full);	\
132000c04a92SMichael Chan 	if ((fw_speeds) & BNXT_LINK_SPEED_MSK_1GB)			\
132100c04a92SMichael Chan 		ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
132200c04a92SMichael Chan 						     1000baseT_Full);	\
132300c04a92SMichael Chan 	if ((fw_speeds) & BNXT_LINK_SPEED_MSK_10GB)			\
132400c04a92SMichael Chan 		ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
132500c04a92SMichael Chan 						     10000baseT_Full);	\
132600c04a92SMichael Chan 	if ((fw_speeds) & BNXT_LINK_SPEED_MSK_25GB)			\
132700c04a92SMichael Chan 		ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
132800c04a92SMichael Chan 						     25000baseCR_Full);	\
132900c04a92SMichael Chan 	if ((fw_speeds) & BNXT_LINK_SPEED_MSK_40GB)			\
133000c04a92SMichael Chan 		ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
133100c04a92SMichael Chan 						     40000baseCR4_Full);\
133200c04a92SMichael Chan 	if ((fw_speeds) & BNXT_LINK_SPEED_MSK_50GB)			\
133300c04a92SMichael Chan 		ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
133400c04a92SMichael Chan 						     50000baseCR2_Full);\
133538a21b34SDeepak Khungar 	if ((fw_speeds) & BNXT_LINK_SPEED_MSK_100GB)			\
133638a21b34SDeepak Khungar 		ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
133738a21b34SDeepak Khungar 						     100000baseCR4_Full);\
133800c04a92SMichael Chan 	if ((fw_pause) & BNXT_LINK_PAUSE_RX) {				\
133900c04a92SMichael Chan 		ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
134000c04a92SMichael Chan 						     Pause);		\
134100c04a92SMichael Chan 		if (!((fw_pause) & BNXT_LINK_PAUSE_TX))			\
134200c04a92SMichael Chan 			ethtool_link_ksettings_add_link_mode(		\
134300c04a92SMichael Chan 					lk_ksettings, name, Asym_Pause);\
134400c04a92SMichael Chan 	} else if ((fw_pause) & BNXT_LINK_PAUSE_TX) {			\
134500c04a92SMichael Chan 		ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
134600c04a92SMichael Chan 						     Asym_Pause);	\
134700c04a92SMichael Chan 	}								\
134800c04a92SMichael Chan }
134900c04a92SMichael Chan 
135000c04a92SMichael Chan #define BNXT_ETHTOOL_TO_FW_SPDS(fw_speeds, lk_ksettings, name)		\
135100c04a92SMichael Chan {									\
135200c04a92SMichael Chan 	if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name,	\
135300c04a92SMichael Chan 						  100baseT_Full) ||	\
135400c04a92SMichael Chan 	    ethtool_link_ksettings_test_link_mode(lk_ksettings, name,	\
135500c04a92SMichael Chan 						  100baseT_Half))	\
135600c04a92SMichael Chan 		(fw_speeds) |= BNXT_LINK_SPEED_MSK_100MB;		\
135700c04a92SMichael Chan 	if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name,	\
135800c04a92SMichael Chan 						  1000baseT_Full) ||	\
135900c04a92SMichael Chan 	    ethtool_link_ksettings_test_link_mode(lk_ksettings, name,	\
136000c04a92SMichael Chan 						  1000baseT_Half))	\
136100c04a92SMichael Chan 		(fw_speeds) |= BNXT_LINK_SPEED_MSK_1GB;			\
136200c04a92SMichael Chan 	if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name,	\
136300c04a92SMichael Chan 						  10000baseT_Full))	\
136400c04a92SMichael Chan 		(fw_speeds) |= BNXT_LINK_SPEED_MSK_10GB;		\
136500c04a92SMichael Chan 	if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name,	\
136600c04a92SMichael Chan 						  25000baseCR_Full))	\
136700c04a92SMichael Chan 		(fw_speeds) |= BNXT_LINK_SPEED_MSK_25GB;		\
136800c04a92SMichael Chan 	if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name,	\
136900c04a92SMichael Chan 						  40000baseCR4_Full))	\
137000c04a92SMichael Chan 		(fw_speeds) |= BNXT_LINK_SPEED_MSK_40GB;		\
137100c04a92SMichael Chan 	if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name,	\
137200c04a92SMichael Chan 						  50000baseCR2_Full))	\
137300c04a92SMichael Chan 		(fw_speeds) |= BNXT_LINK_SPEED_MSK_50GB;		\
137438a21b34SDeepak Khungar 	if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name,	\
137538a21b34SDeepak Khungar 						  100000baseCR4_Full))	\
137638a21b34SDeepak Khungar 		(fw_speeds) |= BNXT_LINK_SPEED_MSK_100GB;		\
137700c04a92SMichael Chan }
137800c04a92SMichael Chan 
137900c04a92SMichael Chan static void bnxt_fw_to_ethtool_advertised_spds(struct bnxt_link_info *link_info,
138000c04a92SMichael Chan 				struct ethtool_link_ksettings *lk_ksettings)
138127c4d578SMichael Chan {
138268515a18SMichael Chan 	u16 fw_speeds = link_info->advertising;
138327c4d578SMichael Chan 	u8 fw_pause = 0;
138427c4d578SMichael Chan 
138527c4d578SMichael Chan 	if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
138627c4d578SMichael Chan 		fw_pause = link_info->auto_pause_setting;
138727c4d578SMichael Chan 
138800c04a92SMichael Chan 	BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, advertising);
138927c4d578SMichael Chan }
139027c4d578SMichael Chan 
139100c04a92SMichael Chan static void bnxt_fw_to_ethtool_lp_adv(struct bnxt_link_info *link_info,
139200c04a92SMichael Chan 				struct ethtool_link_ksettings *lk_ksettings)
13933277360eSMichael Chan {
13943277360eSMichael Chan 	u16 fw_speeds = link_info->lp_auto_link_speeds;
13953277360eSMichael Chan 	u8 fw_pause = 0;
13963277360eSMichael Chan 
13973277360eSMichael Chan 	if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
13983277360eSMichael Chan 		fw_pause = link_info->lp_pause;
13993277360eSMichael Chan 
140000c04a92SMichael Chan 	BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings,
140100c04a92SMichael Chan 				lp_advertising);
14023277360eSMichael Chan }
14033277360eSMichael Chan 
140400c04a92SMichael Chan static void bnxt_fw_to_ethtool_support_spds(struct bnxt_link_info *link_info,
140500c04a92SMichael Chan 				struct ethtool_link_ksettings *lk_ksettings)
14064b32caccSMichael Chan {
14074b32caccSMichael Chan 	u16 fw_speeds = link_info->support_speeds;
14084b32caccSMichael Chan 
140900c04a92SMichael Chan 	BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, 0, lk_ksettings, supported);
14104b32caccSMichael Chan 
141100c04a92SMichael Chan 	ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, Pause);
141200c04a92SMichael Chan 	ethtool_link_ksettings_add_link_mode(lk_ksettings, supported,
141300c04a92SMichael Chan 					     Asym_Pause);
141493ed8117SMichael Chan 
141500c04a92SMichael Chan 	if (link_info->support_auto_speeds)
141600c04a92SMichael Chan 		ethtool_link_ksettings_add_link_mode(lk_ksettings, supported,
141700c04a92SMichael Chan 						     Autoneg);
141893ed8117SMichael Chan }
141993ed8117SMichael Chan 
1420c0c050c5SMichael Chan u32 bnxt_fw_to_ethtool_speed(u16 fw_link_speed)
1421c0c050c5SMichael Chan {
1422c0c050c5SMichael Chan 	switch (fw_link_speed) {
1423c0c050c5SMichael Chan 	case BNXT_LINK_SPEED_100MB:
1424c0c050c5SMichael Chan 		return SPEED_100;
1425c0c050c5SMichael Chan 	case BNXT_LINK_SPEED_1GB:
1426c0c050c5SMichael Chan 		return SPEED_1000;
1427c0c050c5SMichael Chan 	case BNXT_LINK_SPEED_2_5GB:
1428c0c050c5SMichael Chan 		return SPEED_2500;
1429c0c050c5SMichael Chan 	case BNXT_LINK_SPEED_10GB:
1430c0c050c5SMichael Chan 		return SPEED_10000;
1431c0c050c5SMichael Chan 	case BNXT_LINK_SPEED_20GB:
1432c0c050c5SMichael Chan 		return SPEED_20000;
1433c0c050c5SMichael Chan 	case BNXT_LINK_SPEED_25GB:
1434c0c050c5SMichael Chan 		return SPEED_25000;
1435c0c050c5SMichael Chan 	case BNXT_LINK_SPEED_40GB:
1436c0c050c5SMichael Chan 		return SPEED_40000;
1437c0c050c5SMichael Chan 	case BNXT_LINK_SPEED_50GB:
1438c0c050c5SMichael Chan 		return SPEED_50000;
143938a21b34SDeepak Khungar 	case BNXT_LINK_SPEED_100GB:
144038a21b34SDeepak Khungar 		return SPEED_100000;
1441c0c050c5SMichael Chan 	default:
1442c0c050c5SMichael Chan 		return SPEED_UNKNOWN;
1443c0c050c5SMichael Chan 	}
1444c0c050c5SMichael Chan }
1445c0c050c5SMichael Chan 
144600c04a92SMichael Chan static int bnxt_get_link_ksettings(struct net_device *dev,
144700c04a92SMichael Chan 				   struct ethtool_link_ksettings *lk_ksettings)
1448c0c050c5SMichael Chan {
1449c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
1450c0c050c5SMichael Chan 	struct bnxt_link_info *link_info = &bp->link_info;
145100c04a92SMichael Chan 	struct ethtool_link_settings *base = &lk_ksettings->base;
145200c04a92SMichael Chan 	u32 ethtool_speed;
1453c0c050c5SMichael Chan 
145400c04a92SMichael Chan 	ethtool_link_ksettings_zero_link_mode(lk_ksettings, supported);
1455e2dc9b6eSMichael Chan 	mutex_lock(&bp->link_lock);
145600c04a92SMichael Chan 	bnxt_fw_to_ethtool_support_spds(link_info, lk_ksettings);
1457c0c050c5SMichael Chan 
145800c04a92SMichael Chan 	ethtool_link_ksettings_zero_link_mode(lk_ksettings, advertising);
1459b763499eSMichael Chan 	if (link_info->autoneg) {
146000c04a92SMichael Chan 		bnxt_fw_to_ethtool_advertised_spds(link_info, lk_ksettings);
146100c04a92SMichael Chan 		ethtool_link_ksettings_add_link_mode(lk_ksettings,
146200c04a92SMichael Chan 						     advertising, Autoneg);
146300c04a92SMichael Chan 		base->autoneg = AUTONEG_ENABLE;
146400c04a92SMichael Chan 		base->duplex = DUPLEX_UNKNOWN;
146583d8f5e9SMichael Chan 		if (link_info->phy_link_status == BNXT_LINK_LINK) {
146683d8f5e9SMichael Chan 			bnxt_fw_to_ethtool_lp_adv(link_info, lk_ksettings);
146783d8f5e9SMichael Chan 			if (link_info->duplex & BNXT_LINK_DUPLEX_FULL)
146800c04a92SMichael Chan 				base->duplex = DUPLEX_FULL;
146929c262feSMichael Chan 			else
147000c04a92SMichael Chan 				base->duplex = DUPLEX_HALF;
147183d8f5e9SMichael Chan 		}
147283d8f5e9SMichael Chan 		ethtool_speed = bnxt_fw_to_ethtool_speed(link_info->link_speed);
1473c0c050c5SMichael Chan 	} else {
147400c04a92SMichael Chan 		base->autoneg = AUTONEG_DISABLE;
147529c262feSMichael Chan 		ethtool_speed =
147629c262feSMichael Chan 			bnxt_fw_to_ethtool_speed(link_info->req_link_speed);
147700c04a92SMichael Chan 		base->duplex = DUPLEX_HALF;
147829c262feSMichael Chan 		if (link_info->req_duplex == BNXT_LINK_DUPLEX_FULL)
147900c04a92SMichael Chan 			base->duplex = DUPLEX_FULL;
1480c0c050c5SMichael Chan 	}
148100c04a92SMichael Chan 	base->speed = ethtool_speed;
1482c0c050c5SMichael Chan 
148300c04a92SMichael Chan 	base->port = PORT_NONE;
1484c0c050c5SMichael Chan 	if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) {
148500c04a92SMichael Chan 		base->port = PORT_TP;
148600c04a92SMichael Chan 		ethtool_link_ksettings_add_link_mode(lk_ksettings, supported,
148700c04a92SMichael Chan 						     TP);
148800c04a92SMichael Chan 		ethtool_link_ksettings_add_link_mode(lk_ksettings, advertising,
148900c04a92SMichael Chan 						     TP);
1490c0c050c5SMichael Chan 	} else {
149100c04a92SMichael Chan 		ethtool_link_ksettings_add_link_mode(lk_ksettings, supported,
149200c04a92SMichael Chan 						     FIBRE);
149300c04a92SMichael Chan 		ethtool_link_ksettings_add_link_mode(lk_ksettings, advertising,
149400c04a92SMichael Chan 						     FIBRE);
1495c0c050c5SMichael Chan 
1496c0c050c5SMichael Chan 		if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_DAC)
149700c04a92SMichael Chan 			base->port = PORT_DA;
1498c0c050c5SMichael Chan 		else if (link_info->media_type ==
1499c0c050c5SMichael Chan 			 PORT_PHY_QCFG_RESP_MEDIA_TYPE_FIBRE)
150000c04a92SMichael Chan 			base->port = PORT_FIBRE;
1501c0c050c5SMichael Chan 	}
150200c04a92SMichael Chan 	base->phy_address = link_info->phy_addr;
1503e2dc9b6eSMichael Chan 	mutex_unlock(&bp->link_lock);
1504c0c050c5SMichael Chan 
1505c0c050c5SMichael Chan 	return 0;
1506c0c050c5SMichael Chan }
1507c0c050c5SMichael Chan 
150838a21b34SDeepak Khungar static u32 bnxt_get_fw_speed(struct net_device *dev, u32 ethtool_speed)
1509c0c050c5SMichael Chan {
15109d9cee08SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
15119d9cee08SMichael Chan 	struct bnxt_link_info *link_info = &bp->link_info;
15129d9cee08SMichael Chan 	u16 support_spds = link_info->support_speeds;
15139d9cee08SMichael Chan 	u32 fw_speed = 0;
15149d9cee08SMichael Chan 
1515c0c050c5SMichael Chan 	switch (ethtool_speed) {
1516c0c050c5SMichael Chan 	case SPEED_100:
15179d9cee08SMichael Chan 		if (support_spds & BNXT_LINK_SPEED_MSK_100MB)
15189d9cee08SMichael Chan 			fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100MB;
15199d9cee08SMichael Chan 		break;
1520c0c050c5SMichael Chan 	case SPEED_1000:
15219d9cee08SMichael Chan 		if (support_spds & BNXT_LINK_SPEED_MSK_1GB)
15229d9cee08SMichael Chan 			fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_1GB;
15239d9cee08SMichael Chan 		break;
1524c0c050c5SMichael Chan 	case SPEED_2500:
15259d9cee08SMichael Chan 		if (support_spds & BNXT_LINK_SPEED_MSK_2_5GB)
15269d9cee08SMichael Chan 			fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_2_5GB;
15279d9cee08SMichael Chan 		break;
1528c0c050c5SMichael Chan 	case SPEED_10000:
15299d9cee08SMichael Chan 		if (support_spds & BNXT_LINK_SPEED_MSK_10GB)
15309d9cee08SMichael Chan 			fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_10GB;
15319d9cee08SMichael Chan 		break;
1532c0c050c5SMichael Chan 	case SPEED_20000:
15339d9cee08SMichael Chan 		if (support_spds & BNXT_LINK_SPEED_MSK_20GB)
15349d9cee08SMichael Chan 			fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_20GB;
15359d9cee08SMichael Chan 		break;
1536c0c050c5SMichael Chan 	case SPEED_25000:
15379d9cee08SMichael Chan 		if (support_spds & BNXT_LINK_SPEED_MSK_25GB)
15389d9cee08SMichael Chan 			fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_25GB;
15399d9cee08SMichael Chan 		break;
1540c0c050c5SMichael Chan 	case SPEED_40000:
15419d9cee08SMichael Chan 		if (support_spds & BNXT_LINK_SPEED_MSK_40GB)
15429d9cee08SMichael Chan 			fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_40GB;
15439d9cee08SMichael Chan 		break;
1544c0c050c5SMichael Chan 	case SPEED_50000:
15459d9cee08SMichael Chan 		if (support_spds & BNXT_LINK_SPEED_MSK_50GB)
15469d9cee08SMichael Chan 			fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_50GB;
15479d9cee08SMichael Chan 		break;
154838a21b34SDeepak Khungar 	case SPEED_100000:
154938a21b34SDeepak Khungar 		if (support_spds & BNXT_LINK_SPEED_MSK_100GB)
155038a21b34SDeepak Khungar 			fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100GB;
155138a21b34SDeepak Khungar 		break;
1552c0c050c5SMichael Chan 	default:
1553c0c050c5SMichael Chan 		netdev_err(dev, "unsupported speed!\n");
1554c0c050c5SMichael Chan 		break;
1555c0c050c5SMichael Chan 	}
15569d9cee08SMichael Chan 	return fw_speed;
1557c0c050c5SMichael Chan }
1558c0c050c5SMichael Chan 
1559939f7f0cSMichael Chan u16 bnxt_get_fw_auto_link_speeds(u32 advertising)
1560c0c050c5SMichael Chan {
1561c0c050c5SMichael Chan 	u16 fw_speed_mask = 0;
1562c0c050c5SMichael Chan 
1563c0c050c5SMichael Chan 	/* only support autoneg at speed 100, 1000, and 10000 */
1564c0c050c5SMichael Chan 	if (advertising & (ADVERTISED_100baseT_Full |
1565c0c050c5SMichael Chan 			   ADVERTISED_100baseT_Half)) {
1566c0c050c5SMichael Chan 		fw_speed_mask |= BNXT_LINK_SPEED_MSK_100MB;
1567c0c050c5SMichael Chan 	}
1568c0c050c5SMichael Chan 	if (advertising & (ADVERTISED_1000baseT_Full |
1569c0c050c5SMichael Chan 			   ADVERTISED_1000baseT_Half)) {
1570c0c050c5SMichael Chan 		fw_speed_mask |= BNXT_LINK_SPEED_MSK_1GB;
1571c0c050c5SMichael Chan 	}
1572c0c050c5SMichael Chan 	if (advertising & ADVERTISED_10000baseT_Full)
1573c0c050c5SMichael Chan 		fw_speed_mask |= BNXT_LINK_SPEED_MSK_10GB;
1574c0c050c5SMichael Chan 
15751c49c421SMichael Chan 	if (advertising & ADVERTISED_40000baseCR4_Full)
15761c49c421SMichael Chan 		fw_speed_mask |= BNXT_LINK_SPEED_MSK_40GB;
15771c49c421SMichael Chan 
1578c0c050c5SMichael Chan 	return fw_speed_mask;
1579c0c050c5SMichael Chan }
1580c0c050c5SMichael Chan 
158100c04a92SMichael Chan static int bnxt_set_link_ksettings(struct net_device *dev,
158200c04a92SMichael Chan 			   const struct ethtool_link_ksettings *lk_ksettings)
1583c0c050c5SMichael Chan {
1584c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
1585c0c050c5SMichael Chan 	struct bnxt_link_info *link_info = &bp->link_info;
158600c04a92SMichael Chan 	const struct ethtool_link_settings *base = &lk_ksettings->base;
1587c0c050c5SMichael Chan 	bool set_pause = false;
158868515a18SMichael Chan 	u16 fw_advertising = 0;
158968515a18SMichael Chan 	u32 speed;
159000c04a92SMichael Chan 	int rc = 0;
1591c0c050c5SMichael Chan 
1592c7e457f4SMichael Chan 	if (!BNXT_PHY_CFG_ABLE(bp))
159300c04a92SMichael Chan 		return -EOPNOTSUPP;
1594c0c050c5SMichael Chan 
1595e2dc9b6eSMichael Chan 	mutex_lock(&bp->link_lock);
159600c04a92SMichael Chan 	if (base->autoneg == AUTONEG_ENABLE) {
159700c04a92SMichael Chan 		BNXT_ETHTOOL_TO_FW_SPDS(fw_advertising, lk_ksettings,
159800c04a92SMichael Chan 					advertising);
1599c0c050c5SMichael Chan 		link_info->autoneg |= BNXT_AUTONEG_SPEED;
1600c0c050c5SMichael Chan 		if (!fw_advertising)
160193ed8117SMichael Chan 			link_info->advertising = link_info->support_auto_speeds;
1602c0c050c5SMichael Chan 		else
1603c0c050c5SMichael Chan 			link_info->advertising = fw_advertising;
1604c0c050c5SMichael Chan 		/* any change to autoneg will cause link change, therefore the
1605c0c050c5SMichael Chan 		 * driver should put back the original pause setting in autoneg
1606c0c050c5SMichael Chan 		 */
1607c0c050c5SMichael Chan 		set_pause = true;
1608c0c050c5SMichael Chan 	} else {
16099d9cee08SMichael Chan 		u16 fw_speed;
161003efbec0SMichael Chan 		u8 phy_type = link_info->phy_type;
16119d9cee08SMichael Chan 
161203efbec0SMichael Chan 		if (phy_type == PORT_PHY_QCFG_RESP_PHY_TYPE_BASET  ||
161303efbec0SMichael Chan 		    phy_type == PORT_PHY_QCFG_RESP_PHY_TYPE_BASETE ||
161403efbec0SMichael Chan 		    link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) {
161503efbec0SMichael Chan 			netdev_err(dev, "10GBase-T devices must autoneg\n");
161603efbec0SMichael Chan 			rc = -EINVAL;
161703efbec0SMichael Chan 			goto set_setting_exit;
161803efbec0SMichael Chan 		}
161900c04a92SMichael Chan 		if (base->duplex == DUPLEX_HALF) {
1620c0c050c5SMichael Chan 			netdev_err(dev, "HALF DUPLEX is not supported!\n");
1621c0c050c5SMichael Chan 			rc = -EINVAL;
1622c0c050c5SMichael Chan 			goto set_setting_exit;
1623c0c050c5SMichael Chan 		}
162400c04a92SMichael Chan 		speed = base->speed;
16259d9cee08SMichael Chan 		fw_speed = bnxt_get_fw_speed(dev, speed);
16269d9cee08SMichael Chan 		if (!fw_speed) {
16279d9cee08SMichael Chan 			rc = -EINVAL;
16289d9cee08SMichael Chan 			goto set_setting_exit;
16299d9cee08SMichael Chan 		}
16309d9cee08SMichael Chan 		link_info->req_link_speed = fw_speed;
1631c0c050c5SMichael Chan 		link_info->req_duplex = BNXT_LINK_DUPLEX_FULL;
1632b763499eSMichael Chan 		link_info->autoneg = 0;
1633c0c050c5SMichael Chan 		link_info->advertising = 0;
1634c0c050c5SMichael Chan 	}
1635c0c050c5SMichael Chan 
1636c0c050c5SMichael Chan 	if (netif_running(dev))
1637939f7f0cSMichael Chan 		rc = bnxt_hwrm_set_link_setting(bp, set_pause, false);
1638c0c050c5SMichael Chan 
1639c0c050c5SMichael Chan set_setting_exit:
1640e2dc9b6eSMichael Chan 	mutex_unlock(&bp->link_lock);
1641c0c050c5SMichael Chan 	return rc;
1642c0c050c5SMichael Chan }
1643c0c050c5SMichael Chan 
1644c0c050c5SMichael Chan static void bnxt_get_pauseparam(struct net_device *dev,
1645c0c050c5SMichael Chan 				struct ethtool_pauseparam *epause)
1646c0c050c5SMichael Chan {
1647c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
1648c0c050c5SMichael Chan 	struct bnxt_link_info *link_info = &bp->link_info;
1649c0c050c5SMichael Chan 
1650c0c050c5SMichael Chan 	if (BNXT_VF(bp))
1651c0c050c5SMichael Chan 		return;
1652b763499eSMichael Chan 	epause->autoneg = !!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL);
16533c02d1bbSMichael Chan 	epause->rx_pause = !!(link_info->req_flow_ctrl & BNXT_LINK_PAUSE_RX);
16543c02d1bbSMichael Chan 	epause->tx_pause = !!(link_info->req_flow_ctrl & BNXT_LINK_PAUSE_TX);
1655c0c050c5SMichael Chan }
1656c0c050c5SMichael Chan 
1657c0c050c5SMichael Chan static int bnxt_set_pauseparam(struct net_device *dev,
1658c0c050c5SMichael Chan 			       struct ethtool_pauseparam *epause)
1659c0c050c5SMichael Chan {
1660c0c050c5SMichael Chan 	int rc = 0;
1661c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
1662c0c050c5SMichael Chan 	struct bnxt_link_info *link_info = &bp->link_info;
1663c0c050c5SMichael Chan 
1664c7e457f4SMichael Chan 	if (!BNXT_PHY_CFG_ABLE(bp))
166575362a3fSMichael Chan 		return -EOPNOTSUPP;
1666c0c050c5SMichael Chan 
1667c0c050c5SMichael Chan 	if (epause->autoneg) {
1668b763499eSMichael Chan 		if (!(link_info->autoneg & BNXT_AUTONEG_SPEED))
1669b763499eSMichael Chan 			return -EINVAL;
1670b763499eSMichael Chan 
1671c0c050c5SMichael Chan 		link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
1672c9ee9516SMichael Chan 		if (bp->hwrm_spec_code >= 0x10201)
1673c9ee9516SMichael Chan 			link_info->req_flow_ctrl =
1674c9ee9516SMichael Chan 				PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE;
1675c0c050c5SMichael Chan 	} else {
1676c0c050c5SMichael Chan 		/* when transition from auto pause to force pause,
1677c0c050c5SMichael Chan 		 * force a link change
1678c0c050c5SMichael Chan 		 */
1679c0c050c5SMichael Chan 		if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
1680c0c050c5SMichael Chan 			link_info->force_link_chng = true;
1681c0c050c5SMichael Chan 		link_info->autoneg &= ~BNXT_AUTONEG_FLOW_CTRL;
1682c9ee9516SMichael Chan 		link_info->req_flow_ctrl = 0;
1683c0c050c5SMichael Chan 	}
1684c0c050c5SMichael Chan 	if (epause->rx_pause)
1685c0c050c5SMichael Chan 		link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_RX;
1686c0c050c5SMichael Chan 
1687c0c050c5SMichael Chan 	if (epause->tx_pause)
1688c0c050c5SMichael Chan 		link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_TX;
1689c0c050c5SMichael Chan 
1690c0c050c5SMichael Chan 	if (netif_running(dev))
1691c0c050c5SMichael Chan 		rc = bnxt_hwrm_set_pause(bp);
1692c0c050c5SMichael Chan 	return rc;
1693c0c050c5SMichael Chan }
1694c0c050c5SMichael Chan 
1695c0c050c5SMichael Chan static u32 bnxt_get_link(struct net_device *dev)
1696c0c050c5SMichael Chan {
1697c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
1698c0c050c5SMichael Chan 
1699c0c050c5SMichael Chan 	/* TODO: handle MF, VF, driver close case */
1700c0c050c5SMichael Chan 	return bp->link_info.link_up;
1701c0c050c5SMichael Chan }
1702c0c050c5SMichael Chan 
1703b3b0ddd0SMichael Chan static void bnxt_print_admin_err(struct bnxt *bp)
1704b3b0ddd0SMichael Chan {
1705b3b0ddd0SMichael Chan 	netdev_info(bp->dev, "PF does not have admin privileges to flash or reset the device\n");
1706b3b0ddd0SMichael Chan }
1707b3b0ddd0SMichael Chan 
17085ac67d8bSRob Swindell static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal,
17095ac67d8bSRob Swindell 				u16 ext, u16 *index, u32 *item_length,
17105ac67d8bSRob Swindell 				u32 *data_length);
17115ac67d8bSRob Swindell 
1712c0c050c5SMichael Chan static int bnxt_flash_nvram(struct net_device *dev,
1713c0c050c5SMichael Chan 			    u16 dir_type,
1714c0c050c5SMichael Chan 			    u16 dir_ordinal,
1715c0c050c5SMichael Chan 			    u16 dir_ext,
1716c0c050c5SMichael Chan 			    u16 dir_attr,
1717c0c050c5SMichael Chan 			    const u8 *data,
1718c0c050c5SMichael Chan 			    size_t data_len)
1719c0c050c5SMichael Chan {
1720c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
1721c0c050c5SMichael Chan 	int rc;
1722c0c050c5SMichael Chan 	struct hwrm_nvm_write_input req = {0};
1723c0c050c5SMichael Chan 	dma_addr_t dma_handle;
1724c0c050c5SMichael Chan 	u8 *kmem;
1725c0c050c5SMichael Chan 
1726c0c050c5SMichael Chan 	bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_WRITE, -1, -1);
1727c0c050c5SMichael Chan 
1728c0c050c5SMichael Chan 	req.dir_type = cpu_to_le16(dir_type);
1729c0c050c5SMichael Chan 	req.dir_ordinal = cpu_to_le16(dir_ordinal);
1730c0c050c5SMichael Chan 	req.dir_ext = cpu_to_le16(dir_ext);
1731c0c050c5SMichael Chan 	req.dir_attr = cpu_to_le16(dir_attr);
1732c0c050c5SMichael Chan 	req.dir_data_length = cpu_to_le32(data_len);
1733c0c050c5SMichael Chan 
1734c0c050c5SMichael Chan 	kmem = dma_alloc_coherent(&bp->pdev->dev, data_len, &dma_handle,
1735c0c050c5SMichael Chan 				  GFP_KERNEL);
1736c0c050c5SMichael Chan 	if (!kmem) {
1737c0c050c5SMichael Chan 		netdev_err(dev, "dma_alloc_coherent failure, length = %u\n",
1738c0c050c5SMichael Chan 			   (unsigned)data_len);
1739c0c050c5SMichael Chan 		return -ENOMEM;
1740c0c050c5SMichael Chan 	}
1741c0c050c5SMichael Chan 	memcpy(kmem, data, data_len);
1742c0c050c5SMichael Chan 	req.host_src_addr = cpu_to_le64(dma_handle);
1743c0c050c5SMichael Chan 
1744c0c050c5SMichael Chan 	rc = hwrm_send_message(bp, &req, sizeof(req), FLASH_NVRAM_TIMEOUT);
1745c0c050c5SMichael Chan 	dma_free_coherent(&bp->pdev->dev, data_len, kmem, dma_handle);
1746c0c050c5SMichael Chan 
1747d4f1420dSMichael Chan 	if (rc == -EACCES)
1748b3b0ddd0SMichael Chan 		bnxt_print_admin_err(bp);
1749c0c050c5SMichael Chan 	return rc;
1750c0c050c5SMichael Chan }
1751c0c050c5SMichael Chan 
175295fec034SEdwin Peer static int bnxt_hwrm_firmware_reset(struct net_device *dev, u8 proc_type,
175395fec034SEdwin Peer 				    u8 self_reset, u8 flags)
1754d2d6318cSRob Swindell {
1755d2d6318cSRob Swindell 	struct hwrm_fw_reset_input req = {0};
17567c675421SVasundhara Volam 	struct bnxt *bp = netdev_priv(dev);
17577c675421SVasundhara Volam 	int rc;
1758d2d6318cSRob Swindell 
1759d2d6318cSRob Swindell 	bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_RESET, -1, -1);
1760d2d6318cSRob Swindell 
176195fec034SEdwin Peer 	req.embedded_proc_type = proc_type;
176295fec034SEdwin Peer 	req.selfrst_status = self_reset;
176395fec034SEdwin Peer 	req.flags = flags;
176495fec034SEdwin Peer 
176595fec034SEdwin Peer 	rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
176695fec034SEdwin Peer 	if (rc == -EACCES)
176795fec034SEdwin Peer 		bnxt_print_admin_err(bp);
176895fec034SEdwin Peer 	return rc;
176995fec034SEdwin Peer }
177095fec034SEdwin Peer 
177195fec034SEdwin Peer static int bnxt_firmware_reset(struct net_device *dev, u16 dir_type)
177295fec034SEdwin Peer {
177395fec034SEdwin Peer 	u8 self_reset = FW_RESET_REQ_SELFRST_STATUS_SELFRSTNONE;
177495fec034SEdwin Peer 	struct bnxt *bp = netdev_priv(dev);
177595fec034SEdwin Peer 	u8 proc_type, flags = 0;
177695fec034SEdwin Peer 
1777d2d6318cSRob Swindell 	/* TODO: Address self-reset of APE/KONG/BONO/TANG or ungraceful reset */
1778d2d6318cSRob Swindell 	/*       (e.g. when firmware isn't already running) */
1779d2d6318cSRob Swindell 	switch (dir_type) {
1780d2d6318cSRob Swindell 	case BNX_DIR_TYPE_CHIMP_PATCH:
1781d2d6318cSRob Swindell 	case BNX_DIR_TYPE_BOOTCODE:
1782d2d6318cSRob Swindell 	case BNX_DIR_TYPE_BOOTCODE_2:
178395fec034SEdwin Peer 		proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_BOOT;
1784d2d6318cSRob Swindell 		/* Self-reset ChiMP upon next PCIe reset: */
178595fec034SEdwin Peer 		self_reset = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST;
1786d2d6318cSRob Swindell 		break;
1787d2d6318cSRob Swindell 	case BNX_DIR_TYPE_APE_FW:
1788d2d6318cSRob Swindell 	case BNX_DIR_TYPE_APE_PATCH:
178995fec034SEdwin Peer 		proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_MGMT;
179008141e0bSRob Swindell 		/* Self-reset APE upon next PCIe reset: */
179195fec034SEdwin Peer 		self_reset = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST;
1792d2d6318cSRob Swindell 		break;
1793d2d6318cSRob Swindell 	case BNX_DIR_TYPE_KONG_FW:
1794d2d6318cSRob Swindell 	case BNX_DIR_TYPE_KONG_PATCH:
179595fec034SEdwin Peer 		proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_NETCTRL;
1796d2d6318cSRob Swindell 		break;
1797d2d6318cSRob Swindell 	case BNX_DIR_TYPE_BONO_FW:
1798d2d6318cSRob Swindell 	case BNX_DIR_TYPE_BONO_PATCH:
179995fec034SEdwin Peer 		proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_ROCE;
1800d2d6318cSRob Swindell 		break;
180149f7972fSVasundhara Volam 	case BNXT_FW_RESET_CHIP:
180295fec034SEdwin Peer 		proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_CHIP;
180395fec034SEdwin Peer 		self_reset = FW_RESET_REQ_SELFRST_STATUS_SELFRSTASAP;
18040a3f4e4fSVasundhara Volam 		if (bp->fw_cap & BNXT_FW_CAP_HOT_RESET)
180595fec034SEdwin Peer 			flags = FW_RESET_REQ_FLAGS_RESET_GRACEFUL;
180649f7972fSVasundhara Volam 		break;
18076502ad59SScott Branden 	case BNXT_FW_RESET_AP:
180895fec034SEdwin Peer 		proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_AP;
18096502ad59SScott Branden 		break;
1810d2d6318cSRob Swindell 	default:
1811d2d6318cSRob Swindell 		return -EINVAL;
1812d2d6318cSRob Swindell 	}
1813d2d6318cSRob Swindell 
181495fec034SEdwin Peer 	return bnxt_hwrm_firmware_reset(dev, proc_type, self_reset, flags);
1815d2d6318cSRob Swindell }
1816d2d6318cSRob Swindell 
1817c0c050c5SMichael Chan static int bnxt_flash_firmware(struct net_device *dev,
1818c0c050c5SMichael Chan 			       u16 dir_type,
1819c0c050c5SMichael Chan 			       const u8 *fw_data,
1820c0c050c5SMichael Chan 			       size_t fw_size)
1821c0c050c5SMichael Chan {
1822c0c050c5SMichael Chan 	int	rc = 0;
1823c0c050c5SMichael Chan 	u16	code_type;
1824c0c050c5SMichael Chan 	u32	stored_crc;
1825c0c050c5SMichael Chan 	u32	calculated_crc;
1826c0c050c5SMichael Chan 	struct bnxt_fw_header *header = (struct bnxt_fw_header *)fw_data;
1827c0c050c5SMichael Chan 
1828c0c050c5SMichael Chan 	switch (dir_type) {
1829c0c050c5SMichael Chan 	case BNX_DIR_TYPE_BOOTCODE:
1830c0c050c5SMichael Chan 	case BNX_DIR_TYPE_BOOTCODE_2:
1831c0c050c5SMichael Chan 		code_type = CODE_BOOT;
1832c0c050c5SMichael Chan 		break;
183393e0b4feSRob Swindell 	case BNX_DIR_TYPE_CHIMP_PATCH:
183493e0b4feSRob Swindell 		code_type = CODE_CHIMP_PATCH;
183593e0b4feSRob Swindell 		break;
18362731d70fSRob Swindell 	case BNX_DIR_TYPE_APE_FW:
18372731d70fSRob Swindell 		code_type = CODE_MCTP_PASSTHRU;
18382731d70fSRob Swindell 		break;
183993e0b4feSRob Swindell 	case BNX_DIR_TYPE_APE_PATCH:
184093e0b4feSRob Swindell 		code_type = CODE_APE_PATCH;
184193e0b4feSRob Swindell 		break;
184293e0b4feSRob Swindell 	case BNX_DIR_TYPE_KONG_FW:
184393e0b4feSRob Swindell 		code_type = CODE_KONG_FW;
184493e0b4feSRob Swindell 		break;
184593e0b4feSRob Swindell 	case BNX_DIR_TYPE_KONG_PATCH:
184693e0b4feSRob Swindell 		code_type = CODE_KONG_PATCH;
184793e0b4feSRob Swindell 		break;
184893e0b4feSRob Swindell 	case BNX_DIR_TYPE_BONO_FW:
184993e0b4feSRob Swindell 		code_type = CODE_BONO_FW;
185093e0b4feSRob Swindell 		break;
185193e0b4feSRob Swindell 	case BNX_DIR_TYPE_BONO_PATCH:
185293e0b4feSRob Swindell 		code_type = CODE_BONO_PATCH;
185393e0b4feSRob Swindell 		break;
1854c0c050c5SMichael Chan 	default:
1855c0c050c5SMichael Chan 		netdev_err(dev, "Unsupported directory entry type: %u\n",
1856c0c050c5SMichael Chan 			   dir_type);
1857c0c050c5SMichael Chan 		return -EINVAL;
1858c0c050c5SMichael Chan 	}
1859c0c050c5SMichael Chan 	if (fw_size < sizeof(struct bnxt_fw_header)) {
1860c0c050c5SMichael Chan 		netdev_err(dev, "Invalid firmware file size: %u\n",
1861c0c050c5SMichael Chan 			   (unsigned int)fw_size);
1862c0c050c5SMichael Chan 		return -EINVAL;
1863c0c050c5SMichael Chan 	}
1864c0c050c5SMichael Chan 	if (header->signature != cpu_to_le32(BNXT_FIRMWARE_BIN_SIGNATURE)) {
1865c0c050c5SMichael Chan 		netdev_err(dev, "Invalid firmware signature: %08X\n",
1866c0c050c5SMichael Chan 			   le32_to_cpu(header->signature));
1867c0c050c5SMichael Chan 		return -EINVAL;
1868c0c050c5SMichael Chan 	}
1869c0c050c5SMichael Chan 	if (header->code_type != code_type) {
1870c0c050c5SMichael Chan 		netdev_err(dev, "Expected firmware type: %d, read: %d\n",
1871c0c050c5SMichael Chan 			   code_type, header->code_type);
1872c0c050c5SMichael Chan 		return -EINVAL;
1873c0c050c5SMichael Chan 	}
1874c0c050c5SMichael Chan 	if (header->device != DEVICE_CUMULUS_FAMILY) {
1875c0c050c5SMichael Chan 		netdev_err(dev, "Expected firmware device family %d, read: %d\n",
1876c0c050c5SMichael Chan 			   DEVICE_CUMULUS_FAMILY, header->device);
1877c0c050c5SMichael Chan 		return -EINVAL;
1878c0c050c5SMichael Chan 	}
1879c0c050c5SMichael Chan 	/* Confirm the CRC32 checksum of the file: */
1880c0c050c5SMichael Chan 	stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size -
1881c0c050c5SMichael Chan 					     sizeof(stored_crc)));
1882c0c050c5SMichael Chan 	calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc));
1883c0c050c5SMichael Chan 	if (calculated_crc != stored_crc) {
1884c0c050c5SMichael Chan 		netdev_err(dev, "Firmware file CRC32 checksum (%08lX) does not match calculated checksum (%08lX)\n",
1885c0c050c5SMichael Chan 			   (unsigned long)stored_crc,
1886c0c050c5SMichael Chan 			   (unsigned long)calculated_crc);
1887c0c050c5SMichael Chan 		return -EINVAL;
1888c0c050c5SMichael Chan 	}
1889c0c050c5SMichael Chan 	rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST,
1890c0c050c5SMichael Chan 			      0, 0, fw_data, fw_size);
1891d2d6318cSRob Swindell 	if (rc == 0)	/* Firmware update successful */
1892d2d6318cSRob Swindell 		rc = bnxt_firmware_reset(dev, dir_type);
1893d2d6318cSRob Swindell 
1894c0c050c5SMichael Chan 	return rc;
1895c0c050c5SMichael Chan }
1896c0c050c5SMichael Chan 
18975ac67d8bSRob Swindell static int bnxt_flash_microcode(struct net_device *dev,
18985ac67d8bSRob Swindell 				u16 dir_type,
18995ac67d8bSRob Swindell 				const u8 *fw_data,
19005ac67d8bSRob Swindell 				size_t fw_size)
19015ac67d8bSRob Swindell {
19025ac67d8bSRob Swindell 	struct bnxt_ucode_trailer *trailer;
19035ac67d8bSRob Swindell 	u32 calculated_crc;
19045ac67d8bSRob Swindell 	u32 stored_crc;
19055ac67d8bSRob Swindell 	int rc = 0;
19065ac67d8bSRob Swindell 
19075ac67d8bSRob Swindell 	if (fw_size < sizeof(struct bnxt_ucode_trailer)) {
19085ac67d8bSRob Swindell 		netdev_err(dev, "Invalid microcode file size: %u\n",
19095ac67d8bSRob Swindell 			   (unsigned int)fw_size);
19105ac67d8bSRob Swindell 		return -EINVAL;
19115ac67d8bSRob Swindell 	}
19125ac67d8bSRob Swindell 	trailer = (struct bnxt_ucode_trailer *)(fw_data + (fw_size -
19135ac67d8bSRob Swindell 						sizeof(*trailer)));
19145ac67d8bSRob Swindell 	if (trailer->sig != cpu_to_le32(BNXT_UCODE_TRAILER_SIGNATURE)) {
19155ac67d8bSRob Swindell 		netdev_err(dev, "Invalid microcode trailer signature: %08X\n",
19165ac67d8bSRob Swindell 			   le32_to_cpu(trailer->sig));
19175ac67d8bSRob Swindell 		return -EINVAL;
19185ac67d8bSRob Swindell 	}
19195ac67d8bSRob Swindell 	if (le16_to_cpu(trailer->dir_type) != dir_type) {
19205ac67d8bSRob Swindell 		netdev_err(dev, "Expected microcode type: %d, read: %d\n",
19215ac67d8bSRob Swindell 			   dir_type, le16_to_cpu(trailer->dir_type));
19225ac67d8bSRob Swindell 		return -EINVAL;
19235ac67d8bSRob Swindell 	}
19245ac67d8bSRob Swindell 	if (le16_to_cpu(trailer->trailer_length) <
19255ac67d8bSRob Swindell 		sizeof(struct bnxt_ucode_trailer)) {
19265ac67d8bSRob Swindell 		netdev_err(dev, "Invalid microcode trailer length: %d\n",
19275ac67d8bSRob Swindell 			   le16_to_cpu(trailer->trailer_length));
19285ac67d8bSRob Swindell 		return -EINVAL;
19295ac67d8bSRob Swindell 	}
19305ac67d8bSRob Swindell 
19315ac67d8bSRob Swindell 	/* Confirm the CRC32 checksum of the file: */
19325ac67d8bSRob Swindell 	stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size -
19335ac67d8bSRob Swindell 					     sizeof(stored_crc)));
19345ac67d8bSRob Swindell 	calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc));
19355ac67d8bSRob Swindell 	if (calculated_crc != stored_crc) {
19365ac67d8bSRob Swindell 		netdev_err(dev,
19375ac67d8bSRob Swindell 			   "CRC32 (%08lX) does not match calculated: %08lX\n",
19385ac67d8bSRob Swindell 			   (unsigned long)stored_crc,
19395ac67d8bSRob Swindell 			   (unsigned long)calculated_crc);
19405ac67d8bSRob Swindell 		return -EINVAL;
19415ac67d8bSRob Swindell 	}
19425ac67d8bSRob Swindell 	rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST,
19435ac67d8bSRob Swindell 			      0, 0, fw_data, fw_size);
19445ac67d8bSRob Swindell 
19455ac67d8bSRob Swindell 	return rc;
19465ac67d8bSRob Swindell }
19475ac67d8bSRob Swindell 
1948c0c050c5SMichael Chan static bool bnxt_dir_type_is_ape_bin_format(u16 dir_type)
1949c0c050c5SMichael Chan {
1950c0c050c5SMichael Chan 	switch (dir_type) {
1951c0c050c5SMichael Chan 	case BNX_DIR_TYPE_CHIMP_PATCH:
1952c0c050c5SMichael Chan 	case BNX_DIR_TYPE_BOOTCODE:
1953c0c050c5SMichael Chan 	case BNX_DIR_TYPE_BOOTCODE_2:
1954c0c050c5SMichael Chan 	case BNX_DIR_TYPE_APE_FW:
1955c0c050c5SMichael Chan 	case BNX_DIR_TYPE_APE_PATCH:
1956c0c050c5SMichael Chan 	case BNX_DIR_TYPE_KONG_FW:
1957c0c050c5SMichael Chan 	case BNX_DIR_TYPE_KONG_PATCH:
195893e0b4feSRob Swindell 	case BNX_DIR_TYPE_BONO_FW:
195993e0b4feSRob Swindell 	case BNX_DIR_TYPE_BONO_PATCH:
1960c0c050c5SMichael Chan 		return true;
1961c0c050c5SMichael Chan 	}
1962c0c050c5SMichael Chan 
1963c0c050c5SMichael Chan 	return false;
1964c0c050c5SMichael Chan }
1965c0c050c5SMichael Chan 
19665ac67d8bSRob Swindell static bool bnxt_dir_type_is_other_exec_format(u16 dir_type)
1967c0c050c5SMichael Chan {
1968c0c050c5SMichael Chan 	switch (dir_type) {
1969c0c050c5SMichael Chan 	case BNX_DIR_TYPE_AVS:
1970c0c050c5SMichael Chan 	case BNX_DIR_TYPE_EXP_ROM_MBA:
1971c0c050c5SMichael Chan 	case BNX_DIR_TYPE_PCIE:
1972c0c050c5SMichael Chan 	case BNX_DIR_TYPE_TSCF_UCODE:
1973c0c050c5SMichael Chan 	case BNX_DIR_TYPE_EXT_PHY:
1974c0c050c5SMichael Chan 	case BNX_DIR_TYPE_CCM:
1975c0c050c5SMichael Chan 	case BNX_DIR_TYPE_ISCSI_BOOT:
1976c0c050c5SMichael Chan 	case BNX_DIR_TYPE_ISCSI_BOOT_IPV6:
1977c0c050c5SMichael Chan 	case BNX_DIR_TYPE_ISCSI_BOOT_IPV4N6:
1978c0c050c5SMichael Chan 		return true;
1979c0c050c5SMichael Chan 	}
1980c0c050c5SMichael Chan 
1981c0c050c5SMichael Chan 	return false;
1982c0c050c5SMichael Chan }
1983c0c050c5SMichael Chan 
1984c0c050c5SMichael Chan static bool bnxt_dir_type_is_executable(u16 dir_type)
1985c0c050c5SMichael Chan {
1986c0c050c5SMichael Chan 	return bnxt_dir_type_is_ape_bin_format(dir_type) ||
19875ac67d8bSRob Swindell 		bnxt_dir_type_is_other_exec_format(dir_type);
1988c0c050c5SMichael Chan }
1989c0c050c5SMichael Chan 
1990c0c050c5SMichael Chan static int bnxt_flash_firmware_from_file(struct net_device *dev,
1991c0c050c5SMichael Chan 					 u16 dir_type,
1992c0c050c5SMichael Chan 					 const char *filename)
1993c0c050c5SMichael Chan {
1994c0c050c5SMichael Chan 	const struct firmware  *fw;
1995c0c050c5SMichael Chan 	int			rc;
1996c0c050c5SMichael Chan 
1997c0c050c5SMichael Chan 	rc = request_firmware(&fw, filename, &dev->dev);
1998c0c050c5SMichael Chan 	if (rc != 0) {
1999c0c050c5SMichael Chan 		netdev_err(dev, "Error %d requesting firmware file: %s\n",
2000c0c050c5SMichael Chan 			   rc, filename);
2001c0c050c5SMichael Chan 		return rc;
2002c0c050c5SMichael Chan 	}
2003c0c050c5SMichael Chan 	if (bnxt_dir_type_is_ape_bin_format(dir_type) == true)
2004c0c050c5SMichael Chan 		rc = bnxt_flash_firmware(dev, dir_type, fw->data, fw->size);
20055ac67d8bSRob Swindell 	else if (bnxt_dir_type_is_other_exec_format(dir_type) == true)
20065ac67d8bSRob Swindell 		rc = bnxt_flash_microcode(dev, dir_type, fw->data, fw->size);
2007c0c050c5SMichael Chan 	else
2008c0c050c5SMichael Chan 		rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST,
2009c0c050c5SMichael Chan 				      0, 0, fw->data, fw->size);
2010c0c050c5SMichael Chan 	release_firmware(fw);
2011c0c050c5SMichael Chan 	return rc;
2012c0c050c5SMichael Chan }
2013c0c050c5SMichael Chan 
2014d168f328SVasundhara Volam int bnxt_flash_package_from_file(struct net_device *dev, const char *filename,
2015d168f328SVasundhara Volam 				 u32 install_type)
2016c0c050c5SMichael Chan {
20175ac67d8bSRob Swindell 	struct bnxt *bp = netdev_priv(dev);
20185ac67d8bSRob Swindell 	struct hwrm_nvm_install_update_output *resp = bp->hwrm_cmd_resp_addr;
20195ac67d8bSRob Swindell 	struct hwrm_nvm_install_update_input install = {0};
20205ac67d8bSRob Swindell 	const struct firmware *fw;
20215ac67d8bSRob Swindell 	u32 item_len;
202222630e28SEdwin Peer 	int rc = 0;
20235ac67d8bSRob Swindell 	u16 index;
20245ac67d8bSRob Swindell 
20255ac67d8bSRob Swindell 	bnxt_hwrm_fw_set_time(bp);
20265ac67d8bSRob Swindell 
20275ac67d8bSRob Swindell 	if (bnxt_find_nvram_item(dev, BNX_DIR_TYPE_UPDATE,
20285ac67d8bSRob Swindell 				 BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE,
20295ac67d8bSRob Swindell 				 &index, &item_len, NULL) != 0) {
20305ac67d8bSRob Swindell 		netdev_err(dev, "PKG update area not created in nvram\n");
20315ac67d8bSRob Swindell 		return -ENOBUFS;
20325ac67d8bSRob Swindell 	}
20335ac67d8bSRob Swindell 
20345ac67d8bSRob Swindell 	rc = request_firmware(&fw, filename, &dev->dev);
20355ac67d8bSRob Swindell 	if (rc != 0) {
20365ac67d8bSRob Swindell 		netdev_err(dev, "PKG error %d requesting file: %s\n",
20375ac67d8bSRob Swindell 			   rc, filename);
20385ac67d8bSRob Swindell 		return rc;
20395ac67d8bSRob Swindell 	}
20405ac67d8bSRob Swindell 
20415ac67d8bSRob Swindell 	if (fw->size > item_len) {
20429a005c38SJonathan Lemon 		netdev_err(dev, "PKG insufficient update area in nvram: %lu\n",
20435ac67d8bSRob Swindell 			   (unsigned long)fw->size);
20445ac67d8bSRob Swindell 		rc = -EFBIG;
20455ac67d8bSRob Swindell 	} else {
20465ac67d8bSRob Swindell 		dma_addr_t dma_handle;
20475ac67d8bSRob Swindell 		u8 *kmem;
20485ac67d8bSRob Swindell 		struct hwrm_nvm_modify_input modify = {0};
20495ac67d8bSRob Swindell 
20505ac67d8bSRob Swindell 		bnxt_hwrm_cmd_hdr_init(bp, &modify, HWRM_NVM_MODIFY, -1, -1);
20515ac67d8bSRob Swindell 
20525ac67d8bSRob Swindell 		modify.dir_idx = cpu_to_le16(index);
20535ac67d8bSRob Swindell 		modify.len = cpu_to_le32(fw->size);
20545ac67d8bSRob Swindell 
20555ac67d8bSRob Swindell 		kmem = dma_alloc_coherent(&bp->pdev->dev, fw->size,
20565ac67d8bSRob Swindell 					  &dma_handle, GFP_KERNEL);
20575ac67d8bSRob Swindell 		if (!kmem) {
20585ac67d8bSRob Swindell 			netdev_err(dev,
20595ac67d8bSRob Swindell 				   "dma_alloc_coherent failure, length = %u\n",
20605ac67d8bSRob Swindell 				   (unsigned int)fw->size);
20615ac67d8bSRob Swindell 			rc = -ENOMEM;
20625ac67d8bSRob Swindell 		} else {
20635ac67d8bSRob Swindell 			memcpy(kmem, fw->data, fw->size);
20645ac67d8bSRob Swindell 			modify.host_src_addr = cpu_to_le64(dma_handle);
20655ac67d8bSRob Swindell 
206622630e28SEdwin Peer 			rc = hwrm_send_message(bp, &modify, sizeof(modify),
20675ac67d8bSRob Swindell 					       FLASH_PACKAGE_TIMEOUT);
20685ac67d8bSRob Swindell 			dma_free_coherent(&bp->pdev->dev, fw->size, kmem,
20695ac67d8bSRob Swindell 					  dma_handle);
20705ac67d8bSRob Swindell 		}
20715ac67d8bSRob Swindell 	}
20725ac67d8bSRob Swindell 	release_firmware(fw);
207322630e28SEdwin Peer 	if (rc)
20747c675421SVasundhara Volam 		goto err_exit;
20755ac67d8bSRob Swindell 
20765ac67d8bSRob Swindell 	if ((install_type & 0xffff) == 0)
20775ac67d8bSRob Swindell 		install_type >>= 16;
20785ac67d8bSRob Swindell 	bnxt_hwrm_cmd_hdr_init(bp, &install, HWRM_NVM_INSTALL_UPDATE, -1, -1);
20795ac67d8bSRob Swindell 	install.install_type = cpu_to_le32(install_type);
20805ac67d8bSRob Swindell 
2081cb4d1d62SKshitij Soni 	mutex_lock(&bp->hwrm_cmd_lock);
208222630e28SEdwin Peer 	rc = _hwrm_send_message(bp, &install, sizeof(install),
20835ac67d8bSRob Swindell 				INSTALL_PACKAGE_TIMEOUT);
208422630e28SEdwin Peer 	if (rc) {
2085cb4d1d62SKshitij Soni 		u8 error_code = ((struct hwrm_err_output *)resp)->cmd_err;
2086cb4d1d62SKshitij Soni 
2087dd2ebf34SVasundhara Volam 		if (resp->error_code && error_code ==
2088dd2ebf34SVasundhara Volam 		    NVM_INSTALL_UPDATE_CMD_ERR_CODE_FRAG_ERR) {
2089cb4d1d62SKshitij Soni 			install.flags |= cpu_to_le16(
2090cb4d1d62SKshitij Soni 			       NVM_INSTALL_UPDATE_REQ_FLAGS_ALLOWED_TO_DEFRAG);
209122630e28SEdwin Peer 			rc = _hwrm_send_message(bp, &install, sizeof(install),
2092cb4d1d62SKshitij Soni 						INSTALL_PACKAGE_TIMEOUT);
2093dd2ebf34SVasundhara Volam 		}
209422630e28SEdwin Peer 		if (rc)
2095cb4d1d62SKshitij Soni 			goto flash_pkg_exit;
2096cb4d1d62SKshitij Soni 	}
20975ac67d8bSRob Swindell 
20985ac67d8bSRob Swindell 	if (resp->result) {
20995ac67d8bSRob Swindell 		netdev_err(dev, "PKG install error = %d, problem_item = %d\n",
21005ac67d8bSRob Swindell 			   (s8)resp->result, (int)resp->problem_item);
2101cb4d1d62SKshitij Soni 		rc = -ENOPKG;
21025ac67d8bSRob Swindell 	}
2103cb4d1d62SKshitij Soni flash_pkg_exit:
2104cb4d1d62SKshitij Soni 	mutex_unlock(&bp->hwrm_cmd_lock);
21057c675421SVasundhara Volam err_exit:
210622630e28SEdwin Peer 	if (rc == -EACCES)
2107b3b0ddd0SMichael Chan 		bnxt_print_admin_err(bp);
2108cb4d1d62SKshitij Soni 	return rc;
2109c0c050c5SMichael Chan }
2110c0c050c5SMichael Chan 
2111c0c050c5SMichael Chan static int bnxt_flash_device(struct net_device *dev,
2112c0c050c5SMichael Chan 			     struct ethtool_flash *flash)
2113c0c050c5SMichael Chan {
2114c0c050c5SMichael Chan 	if (!BNXT_PF((struct bnxt *)netdev_priv(dev))) {
2115c0c050c5SMichael Chan 		netdev_err(dev, "flashdev not supported from a virtual function\n");
2116c0c050c5SMichael Chan 		return -EINVAL;
2117c0c050c5SMichael Chan 	}
2118c0c050c5SMichael Chan 
21195ac67d8bSRob Swindell 	if (flash->region == ETHTOOL_FLASH_ALL_REGIONS ||
21205ac67d8bSRob Swindell 	    flash->region > 0xffff)
21215ac67d8bSRob Swindell 		return bnxt_flash_package_from_file(dev, flash->data,
21225ac67d8bSRob Swindell 						    flash->region);
2123c0c050c5SMichael Chan 
2124c0c050c5SMichael Chan 	return bnxt_flash_firmware_from_file(dev, flash->region, flash->data);
2125c0c050c5SMichael Chan }
2126c0c050c5SMichael Chan 
2127c0c050c5SMichael Chan static int nvm_get_dir_info(struct net_device *dev, u32 *entries, u32 *length)
2128c0c050c5SMichael Chan {
2129c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
2130c0c050c5SMichael Chan 	int rc;
2131c0c050c5SMichael Chan 	struct hwrm_nvm_get_dir_info_input req = {0};
2132c0c050c5SMichael Chan 	struct hwrm_nvm_get_dir_info_output *output = bp->hwrm_cmd_resp_addr;
2133c0c050c5SMichael Chan 
2134c0c050c5SMichael Chan 	bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_INFO, -1, -1);
2135c0c050c5SMichael Chan 
2136c0c050c5SMichael Chan 	mutex_lock(&bp->hwrm_cmd_lock);
2137c0c050c5SMichael Chan 	rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
2138c0c050c5SMichael Chan 	if (!rc) {
2139c0c050c5SMichael Chan 		*entries = le32_to_cpu(output->entries);
2140c0c050c5SMichael Chan 		*length = le32_to_cpu(output->entry_length);
2141c0c050c5SMichael Chan 	}
2142c0c050c5SMichael Chan 	mutex_unlock(&bp->hwrm_cmd_lock);
2143c0c050c5SMichael Chan 	return rc;
2144c0c050c5SMichael Chan }
2145c0c050c5SMichael Chan 
2146c0c050c5SMichael Chan static int bnxt_get_eeprom_len(struct net_device *dev)
2147c0c050c5SMichael Chan {
21484cebbacaSMichael Chan 	struct bnxt *bp = netdev_priv(dev);
21494cebbacaSMichael Chan 
21504cebbacaSMichael Chan 	if (BNXT_VF(bp))
21514cebbacaSMichael Chan 		return 0;
21524cebbacaSMichael Chan 
2153c0c050c5SMichael Chan 	/* The -1 return value allows the entire 32-bit range of offsets to be
2154c0c050c5SMichael Chan 	 * passed via the ethtool command-line utility.
2155c0c050c5SMichael Chan 	 */
2156c0c050c5SMichael Chan 	return -1;
2157c0c050c5SMichael Chan }
2158c0c050c5SMichael Chan 
2159c0c050c5SMichael Chan static int bnxt_get_nvram_directory(struct net_device *dev, u32 len, u8 *data)
2160c0c050c5SMichael Chan {
2161c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
2162c0c050c5SMichael Chan 	int rc;
2163c0c050c5SMichael Chan 	u32 dir_entries;
2164c0c050c5SMichael Chan 	u32 entry_length;
2165c0c050c5SMichael Chan 	u8 *buf;
2166c0c050c5SMichael Chan 	size_t buflen;
2167c0c050c5SMichael Chan 	dma_addr_t dma_handle;
2168c0c050c5SMichael Chan 	struct hwrm_nvm_get_dir_entries_input req = {0};
2169c0c050c5SMichael Chan 
2170c0c050c5SMichael Chan 	rc = nvm_get_dir_info(dev, &dir_entries, &entry_length);
2171c0c050c5SMichael Chan 	if (rc != 0)
2172c0c050c5SMichael Chan 		return rc;
2173c0c050c5SMichael Chan 
2174c0c050c5SMichael Chan 	/* Insert 2 bytes of directory info (count and size of entries) */
2175c0c050c5SMichael Chan 	if (len < 2)
2176c0c050c5SMichael Chan 		return -EINVAL;
2177c0c050c5SMichael Chan 
2178c0c050c5SMichael Chan 	*data++ = dir_entries;
2179c0c050c5SMichael Chan 	*data++ = entry_length;
2180c0c050c5SMichael Chan 	len -= 2;
2181c0c050c5SMichael Chan 	memset(data, 0xff, len);
2182c0c050c5SMichael Chan 
2183c0c050c5SMichael Chan 	buflen = dir_entries * entry_length;
2184c0c050c5SMichael Chan 	buf = dma_alloc_coherent(&bp->pdev->dev, buflen, &dma_handle,
2185c0c050c5SMichael Chan 				 GFP_KERNEL);
2186c0c050c5SMichael Chan 	if (!buf) {
2187c0c050c5SMichael Chan 		netdev_err(dev, "dma_alloc_coherent failure, length = %u\n",
2188c0c050c5SMichael Chan 			   (unsigned)buflen);
2189c0c050c5SMichael Chan 		return -ENOMEM;
2190c0c050c5SMichael Chan 	}
2191c0c050c5SMichael Chan 	bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_ENTRIES, -1, -1);
2192c0c050c5SMichael Chan 	req.host_dest_addr = cpu_to_le64(dma_handle);
2193c0c050c5SMichael Chan 	rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
2194c0c050c5SMichael Chan 	if (rc == 0)
2195c0c050c5SMichael Chan 		memcpy(data, buf, len > buflen ? buflen : len);
2196c0c050c5SMichael Chan 	dma_free_coherent(&bp->pdev->dev, buflen, buf, dma_handle);
2197c0c050c5SMichael Chan 	return rc;
2198c0c050c5SMichael Chan }
2199c0c050c5SMichael Chan 
2200c0c050c5SMichael Chan static int bnxt_get_nvram_item(struct net_device *dev, u32 index, u32 offset,
2201c0c050c5SMichael Chan 			       u32 length, u8 *data)
2202c0c050c5SMichael Chan {
2203c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
2204c0c050c5SMichael Chan 	int rc;
2205c0c050c5SMichael Chan 	u8 *buf;
2206c0c050c5SMichael Chan 	dma_addr_t dma_handle;
2207c0c050c5SMichael Chan 	struct hwrm_nvm_read_input req = {0};
2208c0c050c5SMichael Chan 
2209e0ad8fc5SMichael Chan 	if (!length)
2210e0ad8fc5SMichael Chan 		return -EINVAL;
2211e0ad8fc5SMichael Chan 
2212c0c050c5SMichael Chan 	buf = dma_alloc_coherent(&bp->pdev->dev, length, &dma_handle,
2213c0c050c5SMichael Chan 				 GFP_KERNEL);
2214c0c050c5SMichael Chan 	if (!buf) {
2215c0c050c5SMichael Chan 		netdev_err(dev, "dma_alloc_coherent failure, length = %u\n",
2216c0c050c5SMichael Chan 			   (unsigned)length);
2217c0c050c5SMichael Chan 		return -ENOMEM;
2218c0c050c5SMichael Chan 	}
2219c0c050c5SMichael Chan 	bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_READ, -1, -1);
2220c0c050c5SMichael Chan 	req.host_dest_addr = cpu_to_le64(dma_handle);
2221c0c050c5SMichael Chan 	req.dir_idx = cpu_to_le16(index);
2222c0c050c5SMichael Chan 	req.offset = cpu_to_le32(offset);
2223c0c050c5SMichael Chan 	req.len = cpu_to_le32(length);
2224c0c050c5SMichael Chan 
2225c0c050c5SMichael Chan 	rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
2226c0c050c5SMichael Chan 	if (rc == 0)
2227c0c050c5SMichael Chan 		memcpy(data, buf, length);
2228c0c050c5SMichael Chan 	dma_free_coherent(&bp->pdev->dev, length, buf, dma_handle);
2229c0c050c5SMichael Chan 	return rc;
2230c0c050c5SMichael Chan }
2231c0c050c5SMichael Chan 
22323ebf6f0aSRob Swindell static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal,
22333ebf6f0aSRob Swindell 				u16 ext, u16 *index, u32 *item_length,
22343ebf6f0aSRob Swindell 				u32 *data_length)
22353ebf6f0aSRob Swindell {
22363ebf6f0aSRob Swindell 	struct bnxt *bp = netdev_priv(dev);
22373ebf6f0aSRob Swindell 	int rc;
22383ebf6f0aSRob Swindell 	struct hwrm_nvm_find_dir_entry_input req = {0};
22393ebf6f0aSRob Swindell 	struct hwrm_nvm_find_dir_entry_output *output = bp->hwrm_cmd_resp_addr;
22403ebf6f0aSRob Swindell 
22413ebf6f0aSRob Swindell 	bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_FIND_DIR_ENTRY, -1, -1);
22423ebf6f0aSRob Swindell 	req.enables = 0;
22433ebf6f0aSRob Swindell 	req.dir_idx = 0;
22443ebf6f0aSRob Swindell 	req.dir_type = cpu_to_le16(type);
22453ebf6f0aSRob Swindell 	req.dir_ordinal = cpu_to_le16(ordinal);
22463ebf6f0aSRob Swindell 	req.dir_ext = cpu_to_le16(ext);
22473ebf6f0aSRob Swindell 	req.opt_ordinal = NVM_FIND_DIR_ENTRY_REQ_OPT_ORDINAL_EQ;
2248cc72f3b1SMichael Chan 	mutex_lock(&bp->hwrm_cmd_lock);
2249cc72f3b1SMichael Chan 	rc = _hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
22503ebf6f0aSRob Swindell 	if (rc == 0) {
22513ebf6f0aSRob Swindell 		if (index)
22523ebf6f0aSRob Swindell 			*index = le16_to_cpu(output->dir_idx);
22533ebf6f0aSRob Swindell 		if (item_length)
22543ebf6f0aSRob Swindell 			*item_length = le32_to_cpu(output->dir_item_length);
22553ebf6f0aSRob Swindell 		if (data_length)
22563ebf6f0aSRob Swindell 			*data_length = le32_to_cpu(output->dir_data_length);
22573ebf6f0aSRob Swindell 	}
2258cc72f3b1SMichael Chan 	mutex_unlock(&bp->hwrm_cmd_lock);
22593ebf6f0aSRob Swindell 	return rc;
22603ebf6f0aSRob Swindell }
22613ebf6f0aSRob Swindell 
22623ebf6f0aSRob Swindell static char *bnxt_parse_pkglog(int desired_field, u8 *data, size_t datalen)
22633ebf6f0aSRob Swindell {
22643ebf6f0aSRob Swindell 	char	*retval = NULL;
22653ebf6f0aSRob Swindell 	char	*p;
22663ebf6f0aSRob Swindell 	char	*value;
22673ebf6f0aSRob Swindell 	int	field = 0;
22683ebf6f0aSRob Swindell 
22693ebf6f0aSRob Swindell 	if (datalen < 1)
22703ebf6f0aSRob Swindell 		return NULL;
22713ebf6f0aSRob Swindell 	/* null-terminate the log data (removing last '\n'): */
22723ebf6f0aSRob Swindell 	data[datalen - 1] = 0;
22733ebf6f0aSRob Swindell 	for (p = data; *p != 0; p++) {
22743ebf6f0aSRob Swindell 		field = 0;
22753ebf6f0aSRob Swindell 		retval = NULL;
22763ebf6f0aSRob Swindell 		while (*p != 0 && *p != '\n') {
22773ebf6f0aSRob Swindell 			value = p;
22783ebf6f0aSRob Swindell 			while (*p != 0 && *p != '\t' && *p != '\n')
22793ebf6f0aSRob Swindell 				p++;
22803ebf6f0aSRob Swindell 			if (field == desired_field)
22813ebf6f0aSRob Swindell 				retval = value;
22823ebf6f0aSRob Swindell 			if (*p != '\t')
22833ebf6f0aSRob Swindell 				break;
22843ebf6f0aSRob Swindell 			*p = 0;
22853ebf6f0aSRob Swindell 			field++;
22863ebf6f0aSRob Swindell 			p++;
22873ebf6f0aSRob Swindell 		}
22883ebf6f0aSRob Swindell 		if (*p == 0)
22893ebf6f0aSRob Swindell 			break;
22903ebf6f0aSRob Swindell 		*p = 0;
22913ebf6f0aSRob Swindell 	}
22923ebf6f0aSRob Swindell 	return retval;
22933ebf6f0aSRob Swindell }
22943ebf6f0aSRob Swindell 
2295a60faa60SVasundhara Volam static void bnxt_get_pkgver(struct net_device *dev)
22963ebf6f0aSRob Swindell {
2297a60faa60SVasundhara Volam 	struct bnxt *bp = netdev_priv(dev);
22983ebf6f0aSRob Swindell 	u16 index = 0;
2299a60faa60SVasundhara Volam 	char *pkgver;
2300a60faa60SVasundhara Volam 	u32 pkglen;
2301a60faa60SVasundhara Volam 	u8 *pkgbuf;
2302a60faa60SVasundhara Volam 	int len;
23033ebf6f0aSRob Swindell 
23043ebf6f0aSRob Swindell 	if (bnxt_find_nvram_item(dev, BNX_DIR_TYPE_PKG_LOG,
23053ebf6f0aSRob Swindell 				 BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE,
2306a60faa60SVasundhara Volam 				 &index, NULL, &pkglen) != 0)
2307a60faa60SVasundhara Volam 		return;
23083ebf6f0aSRob Swindell 
2309a60faa60SVasundhara Volam 	pkgbuf = kzalloc(pkglen, GFP_KERNEL);
2310a60faa60SVasundhara Volam 	if (!pkgbuf) {
2311a60faa60SVasundhara Volam 		dev_err(&bp->pdev->dev, "Unable to allocate memory for pkg version, length = %u\n",
2312a60faa60SVasundhara Volam 			pkglen);
2313a60faa60SVasundhara Volam 		return;
2314a60faa60SVasundhara Volam 	}
23153ebf6f0aSRob Swindell 
2316a60faa60SVasundhara Volam 	if (bnxt_get_nvram_item(dev, index, 0, pkglen, pkgbuf))
2317a60faa60SVasundhara Volam 		goto err;
2318a60faa60SVasundhara Volam 
2319a60faa60SVasundhara Volam 	pkgver = bnxt_parse_pkglog(BNX_PKG_LOG_FIELD_IDX_PKG_VERSION, pkgbuf,
2320a60faa60SVasundhara Volam 				   pkglen);
2321a60faa60SVasundhara Volam 	if (pkgver && *pkgver != 0 && isdigit(*pkgver)) {
2322a60faa60SVasundhara Volam 		len = strlen(bp->fw_ver_str);
2323a60faa60SVasundhara Volam 		snprintf(bp->fw_ver_str + len, FW_VER_STR_LEN - len - 1,
2324a60faa60SVasundhara Volam 			 "/pkg %s", pkgver);
2325a60faa60SVasundhara Volam 	}
2326a60faa60SVasundhara Volam err:
2327a60faa60SVasundhara Volam 	kfree(pkgbuf);
23283ebf6f0aSRob Swindell }
23293ebf6f0aSRob Swindell 
2330c0c050c5SMichael Chan static int bnxt_get_eeprom(struct net_device *dev,
2331c0c050c5SMichael Chan 			   struct ethtool_eeprom *eeprom,
2332c0c050c5SMichael Chan 			   u8 *data)
2333c0c050c5SMichael Chan {
2334c0c050c5SMichael Chan 	u32 index;
2335c0c050c5SMichael Chan 	u32 offset;
2336c0c050c5SMichael Chan 
2337c0c050c5SMichael Chan 	if (eeprom->offset == 0) /* special offset value to get directory */
2338c0c050c5SMichael Chan 		return bnxt_get_nvram_directory(dev, eeprom->len, data);
2339c0c050c5SMichael Chan 
2340c0c050c5SMichael Chan 	index = eeprom->offset >> 24;
2341c0c050c5SMichael Chan 	offset = eeprom->offset & 0xffffff;
2342c0c050c5SMichael Chan 
2343c0c050c5SMichael Chan 	if (index == 0) {
2344c0c050c5SMichael Chan 		netdev_err(dev, "unsupported index value: %d\n", index);
2345c0c050c5SMichael Chan 		return -EINVAL;
2346c0c050c5SMichael Chan 	}
2347c0c050c5SMichael Chan 
2348c0c050c5SMichael Chan 	return bnxt_get_nvram_item(dev, index - 1, offset, eeprom->len, data);
2349c0c050c5SMichael Chan }
2350c0c050c5SMichael Chan 
2351c0c050c5SMichael Chan static int bnxt_erase_nvram_directory(struct net_device *dev, u8 index)
2352c0c050c5SMichael Chan {
2353c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
2354c0c050c5SMichael Chan 	struct hwrm_nvm_erase_dir_entry_input req = {0};
2355c0c050c5SMichael Chan 
2356c0c050c5SMichael Chan 	bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_ERASE_DIR_ENTRY, -1, -1);
2357c0c050c5SMichael Chan 	req.dir_idx = cpu_to_le16(index);
2358c0c050c5SMichael Chan 	return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
2359c0c050c5SMichael Chan }
2360c0c050c5SMichael Chan 
2361c0c050c5SMichael Chan static int bnxt_set_eeprom(struct net_device *dev,
2362c0c050c5SMichael Chan 			   struct ethtool_eeprom *eeprom,
2363c0c050c5SMichael Chan 			   u8 *data)
2364c0c050c5SMichael Chan {
2365c0c050c5SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
2366c0c050c5SMichael Chan 	u8 index, dir_op;
2367c0c050c5SMichael Chan 	u16 type, ext, ordinal, attr;
2368c0c050c5SMichael Chan 
2369c0c050c5SMichael Chan 	if (!BNXT_PF(bp)) {
2370c0c050c5SMichael Chan 		netdev_err(dev, "NVM write not supported from a virtual function\n");
2371c0c050c5SMichael Chan 		return -EINVAL;
2372c0c050c5SMichael Chan 	}
2373c0c050c5SMichael Chan 
2374c0c050c5SMichael Chan 	type = eeprom->magic >> 16;
2375c0c050c5SMichael Chan 
2376c0c050c5SMichael Chan 	if (type == 0xffff) { /* special value for directory operations */
2377c0c050c5SMichael Chan 		index = eeprom->magic & 0xff;
2378c0c050c5SMichael Chan 		dir_op = eeprom->magic >> 8;
2379c0c050c5SMichael Chan 		if (index == 0)
2380c0c050c5SMichael Chan 			return -EINVAL;
2381c0c050c5SMichael Chan 		switch (dir_op) {
2382c0c050c5SMichael Chan 		case 0x0e: /* erase */
2383c0c050c5SMichael Chan 			if (eeprom->offset != ~eeprom->magic)
2384c0c050c5SMichael Chan 				return -EINVAL;
2385c0c050c5SMichael Chan 			return bnxt_erase_nvram_directory(dev, index - 1);
2386c0c050c5SMichael Chan 		default:
2387c0c050c5SMichael Chan 			return -EINVAL;
2388c0c050c5SMichael Chan 		}
2389c0c050c5SMichael Chan 	}
2390c0c050c5SMichael Chan 
2391c0c050c5SMichael Chan 	/* Create or re-write an NVM item: */
2392c0c050c5SMichael Chan 	if (bnxt_dir_type_is_executable(type) == true)
23935ac67d8bSRob Swindell 		return -EOPNOTSUPP;
2394c0c050c5SMichael Chan 	ext = eeprom->magic & 0xffff;
2395c0c050c5SMichael Chan 	ordinal = eeprom->offset >> 16;
2396c0c050c5SMichael Chan 	attr = eeprom->offset & 0xffff;
2397c0c050c5SMichael Chan 
2398c0c050c5SMichael Chan 	return bnxt_flash_nvram(dev, type, ordinal, ext, attr, data,
2399c0c050c5SMichael Chan 				eeprom->len);
2400c0c050c5SMichael Chan }
2401c0c050c5SMichael Chan 
240272b34f04SMichael Chan static int bnxt_set_eee(struct net_device *dev, struct ethtool_eee *edata)
240372b34f04SMichael Chan {
240472b34f04SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
240572b34f04SMichael Chan 	struct ethtool_eee *eee = &bp->eee;
240672b34f04SMichael Chan 	struct bnxt_link_info *link_info = &bp->link_info;
240772b34f04SMichael Chan 	u32 advertising =
240872b34f04SMichael Chan 		 _bnxt_fw_to_ethtool_adv_spds(link_info->advertising, 0);
240972b34f04SMichael Chan 	int rc = 0;
241072b34f04SMichael Chan 
2411c7e457f4SMichael Chan 	if (!BNXT_PHY_CFG_ABLE(bp))
241275362a3fSMichael Chan 		return -EOPNOTSUPP;
241372b34f04SMichael Chan 
241472b34f04SMichael Chan 	if (!(bp->flags & BNXT_FLAG_EEE_CAP))
241572b34f04SMichael Chan 		return -EOPNOTSUPP;
241672b34f04SMichael Chan 
241772b34f04SMichael Chan 	if (!edata->eee_enabled)
241872b34f04SMichael Chan 		goto eee_ok;
241972b34f04SMichael Chan 
242072b34f04SMichael Chan 	if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) {
242172b34f04SMichael Chan 		netdev_warn(dev, "EEE requires autoneg\n");
242272b34f04SMichael Chan 		return -EINVAL;
242372b34f04SMichael Chan 	}
242472b34f04SMichael Chan 	if (edata->tx_lpi_enabled) {
242572b34f04SMichael Chan 		if (bp->lpi_tmr_hi && (edata->tx_lpi_timer > bp->lpi_tmr_hi ||
242672b34f04SMichael Chan 				       edata->tx_lpi_timer < bp->lpi_tmr_lo)) {
242772b34f04SMichael Chan 			netdev_warn(dev, "Valid LPI timer range is %d and %d microsecs\n",
242872b34f04SMichael Chan 				    bp->lpi_tmr_lo, bp->lpi_tmr_hi);
242972b34f04SMichael Chan 			return -EINVAL;
243072b34f04SMichael Chan 		} else if (!bp->lpi_tmr_hi) {
243172b34f04SMichael Chan 			edata->tx_lpi_timer = eee->tx_lpi_timer;
243272b34f04SMichael Chan 		}
243372b34f04SMichael Chan 	}
243472b34f04SMichael Chan 	if (!edata->advertised) {
243572b34f04SMichael Chan 		edata->advertised = advertising & eee->supported;
243672b34f04SMichael Chan 	} else if (edata->advertised & ~advertising) {
243772b34f04SMichael Chan 		netdev_warn(dev, "EEE advertised %x must be a subset of autoneg advertised speeds %x\n",
243872b34f04SMichael Chan 			    edata->advertised, advertising);
243972b34f04SMichael Chan 		return -EINVAL;
244072b34f04SMichael Chan 	}
244172b34f04SMichael Chan 
244272b34f04SMichael Chan 	eee->advertised = edata->advertised;
244372b34f04SMichael Chan 	eee->tx_lpi_enabled = edata->tx_lpi_enabled;
244472b34f04SMichael Chan 	eee->tx_lpi_timer = edata->tx_lpi_timer;
244572b34f04SMichael Chan eee_ok:
244672b34f04SMichael Chan 	eee->eee_enabled = edata->eee_enabled;
244772b34f04SMichael Chan 
244872b34f04SMichael Chan 	if (netif_running(dev))
244972b34f04SMichael Chan 		rc = bnxt_hwrm_set_link_setting(bp, false, true);
245072b34f04SMichael Chan 
245172b34f04SMichael Chan 	return rc;
245272b34f04SMichael Chan }
245372b34f04SMichael Chan 
245472b34f04SMichael Chan static int bnxt_get_eee(struct net_device *dev, struct ethtool_eee *edata)
245572b34f04SMichael Chan {
245672b34f04SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
245772b34f04SMichael Chan 
245872b34f04SMichael Chan 	if (!(bp->flags & BNXT_FLAG_EEE_CAP))
245972b34f04SMichael Chan 		return -EOPNOTSUPP;
246072b34f04SMichael Chan 
246172b34f04SMichael Chan 	*edata = bp->eee;
246272b34f04SMichael Chan 	if (!bp->eee.eee_enabled) {
246372b34f04SMichael Chan 		/* Preserve tx_lpi_timer so that the last value will be used
246472b34f04SMichael Chan 		 * by default when it is re-enabled.
246572b34f04SMichael Chan 		 */
246672b34f04SMichael Chan 		edata->advertised = 0;
246772b34f04SMichael Chan 		edata->tx_lpi_enabled = 0;
246872b34f04SMichael Chan 	}
246972b34f04SMichael Chan 
247072b34f04SMichael Chan 	if (!bp->eee.eee_active)
247172b34f04SMichael Chan 		edata->lp_advertised = 0;
247272b34f04SMichael Chan 
247372b34f04SMichael Chan 	return 0;
247472b34f04SMichael Chan }
247572b34f04SMichael Chan 
247642ee18feSAjit Khaparde static int bnxt_read_sfp_module_eeprom_info(struct bnxt *bp, u16 i2c_addr,
247742ee18feSAjit Khaparde 					    u16 page_number, u16 start_addr,
247842ee18feSAjit Khaparde 					    u16 data_length, u8 *buf)
247942ee18feSAjit Khaparde {
248042ee18feSAjit Khaparde 	struct hwrm_port_phy_i2c_read_input req = {0};
248142ee18feSAjit Khaparde 	struct hwrm_port_phy_i2c_read_output *output = bp->hwrm_cmd_resp_addr;
248242ee18feSAjit Khaparde 	int rc, byte_offset = 0;
248342ee18feSAjit Khaparde 
248442ee18feSAjit Khaparde 	bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_I2C_READ, -1, -1);
248542ee18feSAjit Khaparde 	req.i2c_slave_addr = i2c_addr;
248642ee18feSAjit Khaparde 	req.page_number = cpu_to_le16(page_number);
248742ee18feSAjit Khaparde 	req.port_id = cpu_to_le16(bp->pf.port_id);
248842ee18feSAjit Khaparde 	do {
248942ee18feSAjit Khaparde 		u16 xfer_size;
249042ee18feSAjit Khaparde 
249142ee18feSAjit Khaparde 		xfer_size = min_t(u16, data_length, BNXT_MAX_PHY_I2C_RESP_SIZE);
249242ee18feSAjit Khaparde 		data_length -= xfer_size;
249342ee18feSAjit Khaparde 		req.page_offset = cpu_to_le16(start_addr + byte_offset);
249442ee18feSAjit Khaparde 		req.data_length = xfer_size;
249542ee18feSAjit Khaparde 		req.enables = cpu_to_le32(start_addr + byte_offset ?
249642ee18feSAjit Khaparde 				 PORT_PHY_I2C_READ_REQ_ENABLES_PAGE_OFFSET : 0);
249742ee18feSAjit Khaparde 		mutex_lock(&bp->hwrm_cmd_lock);
249842ee18feSAjit Khaparde 		rc = _hwrm_send_message(bp, &req, sizeof(req),
249942ee18feSAjit Khaparde 					HWRM_CMD_TIMEOUT);
250042ee18feSAjit Khaparde 		if (!rc)
250142ee18feSAjit Khaparde 			memcpy(buf + byte_offset, output->data, xfer_size);
250242ee18feSAjit Khaparde 		mutex_unlock(&bp->hwrm_cmd_lock);
250342ee18feSAjit Khaparde 		byte_offset += xfer_size;
250442ee18feSAjit Khaparde 	} while (!rc && data_length > 0);
250542ee18feSAjit Khaparde 
250642ee18feSAjit Khaparde 	return rc;
250742ee18feSAjit Khaparde }
250842ee18feSAjit Khaparde 
250942ee18feSAjit Khaparde static int bnxt_get_module_info(struct net_device *dev,
251042ee18feSAjit Khaparde 				struct ethtool_modinfo *modinfo)
251142ee18feSAjit Khaparde {
25127328a23cSVasundhara Volam 	u8 data[SFF_DIAG_SUPPORT_OFFSET + 1];
251342ee18feSAjit Khaparde 	struct bnxt *bp = netdev_priv(dev);
251442ee18feSAjit Khaparde 	int rc;
251542ee18feSAjit Khaparde 
251642ee18feSAjit Khaparde 	/* No point in going further if phy status indicates
251742ee18feSAjit Khaparde 	 * module is not inserted or if it is powered down or
251842ee18feSAjit Khaparde 	 * if it is of type 10GBase-T
251942ee18feSAjit Khaparde 	 */
252042ee18feSAjit Khaparde 	if (bp->link_info.module_status >
252142ee18feSAjit Khaparde 		PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG)
252242ee18feSAjit Khaparde 		return -EOPNOTSUPP;
252342ee18feSAjit Khaparde 
252442ee18feSAjit Khaparde 	/* This feature is not supported in older firmware versions */
252542ee18feSAjit Khaparde 	if (bp->hwrm_spec_code < 0x10202)
252642ee18feSAjit Khaparde 		return -EOPNOTSUPP;
252742ee18feSAjit Khaparde 
25287328a23cSVasundhara Volam 	rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A0, 0, 0,
25297328a23cSVasundhara Volam 					      SFF_DIAG_SUPPORT_OFFSET + 1,
25307328a23cSVasundhara Volam 					      data);
253142ee18feSAjit Khaparde 	if (!rc) {
25327328a23cSVasundhara Volam 		u8 module_id = data[0];
25337328a23cSVasundhara Volam 		u8 diag_supported = data[SFF_DIAG_SUPPORT_OFFSET];
253442ee18feSAjit Khaparde 
253542ee18feSAjit Khaparde 		switch (module_id) {
253642ee18feSAjit Khaparde 		case SFF_MODULE_ID_SFP:
253742ee18feSAjit Khaparde 			modinfo->type = ETH_MODULE_SFF_8472;
253842ee18feSAjit Khaparde 			modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
25397328a23cSVasundhara Volam 			if (!diag_supported)
25407328a23cSVasundhara Volam 				modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN;
254142ee18feSAjit Khaparde 			break;
254242ee18feSAjit Khaparde 		case SFF_MODULE_ID_QSFP:
254342ee18feSAjit Khaparde 		case SFF_MODULE_ID_QSFP_PLUS:
254442ee18feSAjit Khaparde 			modinfo->type = ETH_MODULE_SFF_8436;
254542ee18feSAjit Khaparde 			modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN;
254642ee18feSAjit Khaparde 			break;
254742ee18feSAjit Khaparde 		case SFF_MODULE_ID_QSFP28:
254842ee18feSAjit Khaparde 			modinfo->type = ETH_MODULE_SFF_8636;
254942ee18feSAjit Khaparde 			modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN;
255042ee18feSAjit Khaparde 			break;
255142ee18feSAjit Khaparde 		default:
255242ee18feSAjit Khaparde 			rc = -EOPNOTSUPP;
255342ee18feSAjit Khaparde 			break;
255442ee18feSAjit Khaparde 		}
255542ee18feSAjit Khaparde 	}
255642ee18feSAjit Khaparde 	return rc;
255742ee18feSAjit Khaparde }
255842ee18feSAjit Khaparde 
255942ee18feSAjit Khaparde static int bnxt_get_module_eeprom(struct net_device *dev,
256042ee18feSAjit Khaparde 				  struct ethtool_eeprom *eeprom,
256142ee18feSAjit Khaparde 				  u8 *data)
256242ee18feSAjit Khaparde {
256342ee18feSAjit Khaparde 	struct bnxt *bp = netdev_priv(dev);
256442ee18feSAjit Khaparde 	u16  start = eeprom->offset, length = eeprom->len;
2565f3ea3119SColin Ian King 	int rc = 0;
256642ee18feSAjit Khaparde 
256742ee18feSAjit Khaparde 	memset(data, 0, eeprom->len);
256842ee18feSAjit Khaparde 
256942ee18feSAjit Khaparde 	/* Read A0 portion of the EEPROM */
257042ee18feSAjit Khaparde 	if (start < ETH_MODULE_SFF_8436_LEN) {
257142ee18feSAjit Khaparde 		if (start + eeprom->len > ETH_MODULE_SFF_8436_LEN)
257242ee18feSAjit Khaparde 			length = ETH_MODULE_SFF_8436_LEN - start;
257342ee18feSAjit Khaparde 		rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A0, 0,
257442ee18feSAjit Khaparde 						      start, length, data);
257542ee18feSAjit Khaparde 		if (rc)
257642ee18feSAjit Khaparde 			return rc;
257742ee18feSAjit Khaparde 		start += length;
257842ee18feSAjit Khaparde 		data += length;
257942ee18feSAjit Khaparde 		length = eeprom->len - length;
258042ee18feSAjit Khaparde 	}
258142ee18feSAjit Khaparde 
258242ee18feSAjit Khaparde 	/* Read A2 portion of the EEPROM */
258342ee18feSAjit Khaparde 	if (length) {
258442ee18feSAjit Khaparde 		start -= ETH_MODULE_SFF_8436_LEN;
2585dea521a2SChristophe JAILLET 		rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A2, 1,
2586dea521a2SChristophe JAILLET 						      start, length, data);
258742ee18feSAjit Khaparde 	}
258842ee18feSAjit Khaparde 	return rc;
258942ee18feSAjit Khaparde }
259042ee18feSAjit Khaparde 
2591ae8e98a6SDeepak Khungar static int bnxt_nway_reset(struct net_device *dev)
2592ae8e98a6SDeepak Khungar {
2593ae8e98a6SDeepak Khungar 	int rc = 0;
2594ae8e98a6SDeepak Khungar 
2595ae8e98a6SDeepak Khungar 	struct bnxt *bp = netdev_priv(dev);
2596ae8e98a6SDeepak Khungar 	struct bnxt_link_info *link_info = &bp->link_info;
2597ae8e98a6SDeepak Khungar 
2598c7e457f4SMichael Chan 	if (!BNXT_PHY_CFG_ABLE(bp))
2599ae8e98a6SDeepak Khungar 		return -EOPNOTSUPP;
2600ae8e98a6SDeepak Khungar 
2601ae8e98a6SDeepak Khungar 	if (!(link_info->autoneg & BNXT_AUTONEG_SPEED))
2602ae8e98a6SDeepak Khungar 		return -EINVAL;
2603ae8e98a6SDeepak Khungar 
2604ae8e98a6SDeepak Khungar 	if (netif_running(dev))
2605ae8e98a6SDeepak Khungar 		rc = bnxt_hwrm_set_link_setting(bp, true, false);
2606ae8e98a6SDeepak Khungar 
2607ae8e98a6SDeepak Khungar 	return rc;
2608ae8e98a6SDeepak Khungar }
2609ae8e98a6SDeepak Khungar 
26105ad2cbeeSMichael Chan static int bnxt_set_phys_id(struct net_device *dev,
26115ad2cbeeSMichael Chan 			    enum ethtool_phys_id_state state)
26125ad2cbeeSMichael Chan {
26135ad2cbeeSMichael Chan 	struct hwrm_port_led_cfg_input req = {0};
26145ad2cbeeSMichael Chan 	struct bnxt *bp = netdev_priv(dev);
26155ad2cbeeSMichael Chan 	struct bnxt_pf_info *pf = &bp->pf;
26165ad2cbeeSMichael Chan 	struct bnxt_led_cfg *led_cfg;
26175ad2cbeeSMichael Chan 	u8 led_state;
26185ad2cbeeSMichael Chan 	__le16 duration;
26199f90445cSVasundhara Volam 	int i;
26205ad2cbeeSMichael Chan 
26215ad2cbeeSMichael Chan 	if (!bp->num_leds || BNXT_VF(bp))
26225ad2cbeeSMichael Chan 		return -EOPNOTSUPP;
26235ad2cbeeSMichael Chan 
26245ad2cbeeSMichael Chan 	if (state == ETHTOOL_ID_ACTIVE) {
26255ad2cbeeSMichael Chan 		led_state = PORT_LED_CFG_REQ_LED0_STATE_BLINKALT;
26265ad2cbeeSMichael Chan 		duration = cpu_to_le16(500);
26275ad2cbeeSMichael Chan 	} else if (state == ETHTOOL_ID_INACTIVE) {
26285ad2cbeeSMichael Chan 		led_state = PORT_LED_CFG_REQ_LED1_STATE_DEFAULT;
26295ad2cbeeSMichael Chan 		duration = cpu_to_le16(0);
26305ad2cbeeSMichael Chan 	} else {
26315ad2cbeeSMichael Chan 		return -EINVAL;
26325ad2cbeeSMichael Chan 	}
26335ad2cbeeSMichael Chan 	bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_LED_CFG, -1, -1);
26345ad2cbeeSMichael Chan 	req.port_id = cpu_to_le16(pf->port_id);
26355ad2cbeeSMichael Chan 	req.num_leds = bp->num_leds;
26365ad2cbeeSMichael Chan 	led_cfg = (struct bnxt_led_cfg *)&req.led0_id;
26375ad2cbeeSMichael Chan 	for (i = 0; i < bp->num_leds; i++, led_cfg++) {
26385ad2cbeeSMichael Chan 		req.enables |= BNXT_LED_DFLT_ENABLES(i);
26395ad2cbeeSMichael Chan 		led_cfg->led_id = bp->leds[i].led_id;
26405ad2cbeeSMichael Chan 		led_cfg->led_state = led_state;
26415ad2cbeeSMichael Chan 		led_cfg->led_blink_on = duration;
26425ad2cbeeSMichael Chan 		led_cfg->led_blink_off = duration;
26435ad2cbeeSMichael Chan 		led_cfg->led_group_id = bp->leds[i].led_group_id;
26445ad2cbeeSMichael Chan 	}
26459f90445cSVasundhara Volam 	return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
26465ad2cbeeSMichael Chan }
26475ad2cbeeSMichael Chan 
264867fea463SMichael Chan static int bnxt_hwrm_selftest_irq(struct bnxt *bp, u16 cmpl_ring)
264967fea463SMichael Chan {
265067fea463SMichael Chan 	struct hwrm_selftest_irq_input req = {0};
265167fea463SMichael Chan 
265267fea463SMichael Chan 	bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_IRQ, cmpl_ring, -1);
265367fea463SMichael Chan 	return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
265467fea463SMichael Chan }
265567fea463SMichael Chan 
265667fea463SMichael Chan static int bnxt_test_irq(struct bnxt *bp)
265767fea463SMichael Chan {
265867fea463SMichael Chan 	int i;
265967fea463SMichael Chan 
266067fea463SMichael Chan 	for (i = 0; i < bp->cp_nr_rings; i++) {
266167fea463SMichael Chan 		u16 cmpl_ring = bp->grp_info[i].cp_fw_ring_id;
266267fea463SMichael Chan 		int rc;
266367fea463SMichael Chan 
266467fea463SMichael Chan 		rc = bnxt_hwrm_selftest_irq(bp, cmpl_ring);
266567fea463SMichael Chan 		if (rc)
266667fea463SMichael Chan 			return rc;
266767fea463SMichael Chan 	}
266867fea463SMichael Chan 	return 0;
266967fea463SMichael Chan }
267067fea463SMichael Chan 
2671f7dc1ea6SMichael Chan static int bnxt_hwrm_mac_loopback(struct bnxt *bp, bool enable)
2672f7dc1ea6SMichael Chan {
2673f7dc1ea6SMichael Chan 	struct hwrm_port_mac_cfg_input req = {0};
2674f7dc1ea6SMichael Chan 
2675f7dc1ea6SMichael Chan 	bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_MAC_CFG, -1, -1);
2676f7dc1ea6SMichael Chan 
2677f7dc1ea6SMichael Chan 	req.enables = cpu_to_le32(PORT_MAC_CFG_REQ_ENABLES_LPBK);
2678f7dc1ea6SMichael Chan 	if (enable)
2679f7dc1ea6SMichael Chan 		req.lpbk = PORT_MAC_CFG_REQ_LPBK_LOCAL;
2680f7dc1ea6SMichael Chan 	else
2681f7dc1ea6SMichael Chan 		req.lpbk = PORT_MAC_CFG_REQ_LPBK_NONE;
2682f7dc1ea6SMichael Chan 	return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
2683f7dc1ea6SMichael Chan }
2684f7dc1ea6SMichael Chan 
268556d37462SVasundhara Volam static int bnxt_query_force_speeds(struct bnxt *bp, u16 *force_speeds)
268656d37462SVasundhara Volam {
268756d37462SVasundhara Volam 	struct hwrm_port_phy_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
268856d37462SVasundhara Volam 	struct hwrm_port_phy_qcaps_input req = {0};
268956d37462SVasundhara Volam 	int rc;
269056d37462SVasundhara Volam 
269156d37462SVasundhara Volam 	bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCAPS, -1, -1);
269256d37462SVasundhara Volam 	mutex_lock(&bp->hwrm_cmd_lock);
269356d37462SVasundhara Volam 	rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
269456d37462SVasundhara Volam 	if (!rc)
269556d37462SVasundhara Volam 		*force_speeds = le16_to_cpu(resp->supported_speeds_force_mode);
269656d37462SVasundhara Volam 
269756d37462SVasundhara Volam 	mutex_unlock(&bp->hwrm_cmd_lock);
269856d37462SVasundhara Volam 	return rc;
269956d37462SVasundhara Volam }
270056d37462SVasundhara Volam 
270191725d89SMichael Chan static int bnxt_disable_an_for_lpbk(struct bnxt *bp,
270291725d89SMichael Chan 				    struct hwrm_port_phy_cfg_input *req)
270391725d89SMichael Chan {
270491725d89SMichael Chan 	struct bnxt_link_info *link_info = &bp->link_info;
270556d37462SVasundhara Volam 	u16 fw_advertising;
270691725d89SMichael Chan 	u16 fw_speed;
270791725d89SMichael Chan 	int rc;
270891725d89SMichael Chan 
27098a60efd1SMichael Chan 	if (!link_info->autoneg ||
27108a60efd1SMichael Chan 	    (bp->test_info->flags & BNXT_TEST_FL_AN_PHY_LPBK))
271191725d89SMichael Chan 		return 0;
271291725d89SMichael Chan 
271356d37462SVasundhara Volam 	rc = bnxt_query_force_speeds(bp, &fw_advertising);
271456d37462SVasundhara Volam 	if (rc)
271556d37462SVasundhara Volam 		return rc;
271656d37462SVasundhara Volam 
271791725d89SMichael Chan 	fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_1GB;
271883d8f5e9SMichael Chan 	if (bp->link_info.link_up)
271991725d89SMichael Chan 		fw_speed = bp->link_info.link_speed;
272091725d89SMichael Chan 	else if (fw_advertising & BNXT_LINK_SPEED_MSK_10GB)
272191725d89SMichael Chan 		fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_10GB;
272291725d89SMichael Chan 	else if (fw_advertising & BNXT_LINK_SPEED_MSK_25GB)
272391725d89SMichael Chan 		fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_25GB;
272491725d89SMichael Chan 	else if (fw_advertising & BNXT_LINK_SPEED_MSK_40GB)
272591725d89SMichael Chan 		fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_40GB;
272691725d89SMichael Chan 	else if (fw_advertising & BNXT_LINK_SPEED_MSK_50GB)
272791725d89SMichael Chan 		fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_50GB;
272891725d89SMichael Chan 
272991725d89SMichael Chan 	req->force_link_speed = cpu_to_le16(fw_speed);
273091725d89SMichael Chan 	req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE |
273191725d89SMichael Chan 				  PORT_PHY_CFG_REQ_FLAGS_RESET_PHY);
273291725d89SMichael Chan 	rc = hwrm_send_message(bp, req, sizeof(*req), HWRM_CMD_TIMEOUT);
273391725d89SMichael Chan 	req->flags = 0;
273491725d89SMichael Chan 	req->force_link_speed = cpu_to_le16(0);
273591725d89SMichael Chan 	return rc;
273691725d89SMichael Chan }
273791725d89SMichael Chan 
273855fd0cf3SMichael Chan static int bnxt_hwrm_phy_loopback(struct bnxt *bp, bool enable, bool ext)
273991725d89SMichael Chan {
274091725d89SMichael Chan 	struct hwrm_port_phy_cfg_input req = {0};
274191725d89SMichael Chan 
274291725d89SMichael Chan 	bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1);
274391725d89SMichael Chan 
274491725d89SMichael Chan 	if (enable) {
274591725d89SMichael Chan 		bnxt_disable_an_for_lpbk(bp, &req);
274655fd0cf3SMichael Chan 		if (ext)
274755fd0cf3SMichael Chan 			req.lpbk = PORT_PHY_CFG_REQ_LPBK_EXTERNAL;
274855fd0cf3SMichael Chan 		else
274991725d89SMichael Chan 			req.lpbk = PORT_PHY_CFG_REQ_LPBK_LOCAL;
275091725d89SMichael Chan 	} else {
275191725d89SMichael Chan 		req.lpbk = PORT_PHY_CFG_REQ_LPBK_NONE;
275291725d89SMichael Chan 	}
275391725d89SMichael Chan 	req.enables = cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_LPBK);
275491725d89SMichael Chan 	return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
275591725d89SMichael Chan }
275691725d89SMichael Chan 
2757e44758b7SMichael Chan static int bnxt_rx_loopback(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
2758f7dc1ea6SMichael Chan 			    u32 raw_cons, int pkt_size)
2759f7dc1ea6SMichael Chan {
2760e44758b7SMichael Chan 	struct bnxt_napi *bnapi = cpr->bnapi;
2761e44758b7SMichael Chan 	struct bnxt_rx_ring_info *rxr;
2762f7dc1ea6SMichael Chan 	struct bnxt_sw_rx_bd *rx_buf;
2763f7dc1ea6SMichael Chan 	struct rx_cmp *rxcmp;
2764f7dc1ea6SMichael Chan 	u16 cp_cons, cons;
2765f7dc1ea6SMichael Chan 	u8 *data;
2766f7dc1ea6SMichael Chan 	u32 len;
2767f7dc1ea6SMichael Chan 	int i;
2768f7dc1ea6SMichael Chan 
2769e44758b7SMichael Chan 	rxr = bnapi->rx_ring;
2770f7dc1ea6SMichael Chan 	cp_cons = RING_CMP(raw_cons);
2771f7dc1ea6SMichael Chan 	rxcmp = (struct rx_cmp *)
2772f7dc1ea6SMichael Chan 		&cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
2773f7dc1ea6SMichael Chan 	cons = rxcmp->rx_cmp_opaque;
2774f7dc1ea6SMichael Chan 	rx_buf = &rxr->rx_buf_ring[cons];
2775f7dc1ea6SMichael Chan 	data = rx_buf->data_ptr;
2776f7dc1ea6SMichael Chan 	len = le32_to_cpu(rxcmp->rx_cmp_len_flags_type) >> RX_CMP_LEN_SHIFT;
2777f7dc1ea6SMichael Chan 	if (len != pkt_size)
2778f7dc1ea6SMichael Chan 		return -EIO;
2779f7dc1ea6SMichael Chan 	i = ETH_ALEN;
2780f7dc1ea6SMichael Chan 	if (!ether_addr_equal(data + i, bnapi->bp->dev->dev_addr))
2781f7dc1ea6SMichael Chan 		return -EIO;
2782f7dc1ea6SMichael Chan 	i += ETH_ALEN;
2783f7dc1ea6SMichael Chan 	for (  ; i < pkt_size; i++) {
2784f7dc1ea6SMichael Chan 		if (data[i] != (u8)(i & 0xff))
2785f7dc1ea6SMichael Chan 			return -EIO;
2786f7dc1ea6SMichael Chan 	}
2787f7dc1ea6SMichael Chan 	return 0;
2788f7dc1ea6SMichael Chan }
2789f7dc1ea6SMichael Chan 
2790e44758b7SMichael Chan static int bnxt_poll_loopback(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
2791e44758b7SMichael Chan 			      int pkt_size)
2792f7dc1ea6SMichael Chan {
2793f7dc1ea6SMichael Chan 	struct tx_cmp *txcmp;
2794f7dc1ea6SMichael Chan 	int rc = -EIO;
2795f7dc1ea6SMichael Chan 	u32 raw_cons;
2796f7dc1ea6SMichael Chan 	u32 cons;
2797f7dc1ea6SMichael Chan 	int i;
2798f7dc1ea6SMichael Chan 
2799f7dc1ea6SMichael Chan 	raw_cons = cpr->cp_raw_cons;
2800f7dc1ea6SMichael Chan 	for (i = 0; i < 200; i++) {
2801f7dc1ea6SMichael Chan 		cons = RING_CMP(raw_cons);
2802f7dc1ea6SMichael Chan 		txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)];
2803f7dc1ea6SMichael Chan 
2804f7dc1ea6SMichael Chan 		if (!TX_CMP_VALID(txcmp, raw_cons)) {
2805f7dc1ea6SMichael Chan 			udelay(5);
2806f7dc1ea6SMichael Chan 			continue;
2807f7dc1ea6SMichael Chan 		}
2808f7dc1ea6SMichael Chan 
2809f7dc1ea6SMichael Chan 		/* The valid test of the entry must be done first before
2810f7dc1ea6SMichael Chan 		 * reading any further.
2811f7dc1ea6SMichael Chan 		 */
2812f7dc1ea6SMichael Chan 		dma_rmb();
2813f7dc1ea6SMichael Chan 		if (TX_CMP_TYPE(txcmp) == CMP_TYPE_RX_L2_CMP) {
2814e44758b7SMichael Chan 			rc = bnxt_rx_loopback(bp, cpr, raw_cons, pkt_size);
2815f7dc1ea6SMichael Chan 			raw_cons = NEXT_RAW_CMP(raw_cons);
2816f7dc1ea6SMichael Chan 			raw_cons = NEXT_RAW_CMP(raw_cons);
2817f7dc1ea6SMichael Chan 			break;
2818f7dc1ea6SMichael Chan 		}
2819f7dc1ea6SMichael Chan 		raw_cons = NEXT_RAW_CMP(raw_cons);
2820f7dc1ea6SMichael Chan 	}
2821f7dc1ea6SMichael Chan 	cpr->cp_raw_cons = raw_cons;
2822f7dc1ea6SMichael Chan 	return rc;
2823f7dc1ea6SMichael Chan }
2824f7dc1ea6SMichael Chan 
2825f7dc1ea6SMichael Chan static int bnxt_run_loopback(struct bnxt *bp)
2826f7dc1ea6SMichael Chan {
2827f7dc1ea6SMichael Chan 	struct bnxt_tx_ring_info *txr = &bp->tx_ring[0];
282884404d5fSMichael Chan 	struct bnxt_rx_ring_info *rxr = &bp->rx_ring[0];
2829e44758b7SMichael Chan 	struct bnxt_cp_ring_info *cpr;
2830f7dc1ea6SMichael Chan 	int pkt_size, i = 0;
2831f7dc1ea6SMichael Chan 	struct sk_buff *skb;
2832f7dc1ea6SMichael Chan 	dma_addr_t map;
2833f7dc1ea6SMichael Chan 	u8 *data;
2834f7dc1ea6SMichael Chan 	int rc;
2835f7dc1ea6SMichael Chan 
283684404d5fSMichael Chan 	cpr = &rxr->bnapi->cp_ring;
283784404d5fSMichael Chan 	if (bp->flags & BNXT_FLAG_CHIP_P5)
283884404d5fSMichael Chan 		cpr = cpr->cp_ring_arr[BNXT_RX_HDL];
2839f7dc1ea6SMichael Chan 	pkt_size = min(bp->dev->mtu + ETH_HLEN, bp->rx_copy_thresh);
2840f7dc1ea6SMichael Chan 	skb = netdev_alloc_skb(bp->dev, pkt_size);
2841f7dc1ea6SMichael Chan 	if (!skb)
2842f7dc1ea6SMichael Chan 		return -ENOMEM;
2843f7dc1ea6SMichael Chan 	data = skb_put(skb, pkt_size);
2844f7dc1ea6SMichael Chan 	eth_broadcast_addr(data);
2845f7dc1ea6SMichael Chan 	i += ETH_ALEN;
2846f7dc1ea6SMichael Chan 	ether_addr_copy(&data[i], bp->dev->dev_addr);
2847f7dc1ea6SMichael Chan 	i += ETH_ALEN;
2848f7dc1ea6SMichael Chan 	for ( ; i < pkt_size; i++)
2849f7dc1ea6SMichael Chan 		data[i] = (u8)(i & 0xff);
2850f7dc1ea6SMichael Chan 
2851f7dc1ea6SMichael Chan 	map = dma_map_single(&bp->pdev->dev, skb->data, pkt_size,
2852f7dc1ea6SMichael Chan 			     PCI_DMA_TODEVICE);
2853f7dc1ea6SMichael Chan 	if (dma_mapping_error(&bp->pdev->dev, map)) {
2854f7dc1ea6SMichael Chan 		dev_kfree_skb(skb);
2855f7dc1ea6SMichael Chan 		return -EIO;
2856f7dc1ea6SMichael Chan 	}
2857c1ba92a8SMichael Chan 	bnxt_xmit_bd(bp, txr, map, pkt_size);
2858f7dc1ea6SMichael Chan 
2859f7dc1ea6SMichael Chan 	/* Sync BD data before updating doorbell */
2860f7dc1ea6SMichael Chan 	wmb();
2861f7dc1ea6SMichael Chan 
2862697197e5SMichael Chan 	bnxt_db_write(bp, &txr->tx_db, txr->tx_prod);
2863e44758b7SMichael Chan 	rc = bnxt_poll_loopback(bp, cpr, pkt_size);
2864f7dc1ea6SMichael Chan 
2865f7dc1ea6SMichael Chan 	dma_unmap_single(&bp->pdev->dev, map, pkt_size, PCI_DMA_TODEVICE);
2866f7dc1ea6SMichael Chan 	dev_kfree_skb(skb);
2867f7dc1ea6SMichael Chan 	return rc;
2868f7dc1ea6SMichael Chan }
2869f7dc1ea6SMichael Chan 
2870eb513658SMichael Chan static int bnxt_run_fw_tests(struct bnxt *bp, u8 test_mask, u8 *test_results)
2871eb513658SMichael Chan {
2872eb513658SMichael Chan 	struct hwrm_selftest_exec_output *resp = bp->hwrm_cmd_resp_addr;
2873eb513658SMichael Chan 	struct hwrm_selftest_exec_input req = {0};
2874eb513658SMichael Chan 	int rc;
2875eb513658SMichael Chan 
2876eb513658SMichael Chan 	bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_EXEC, -1, -1);
2877eb513658SMichael Chan 	mutex_lock(&bp->hwrm_cmd_lock);
2878eb513658SMichael Chan 	resp->test_success = 0;
2879eb513658SMichael Chan 	req.flags = test_mask;
2880eb513658SMichael Chan 	rc = _hwrm_send_message(bp, &req, sizeof(req), bp->test_info->timeout);
2881eb513658SMichael Chan 	*test_results = resp->test_success;
2882eb513658SMichael Chan 	mutex_unlock(&bp->hwrm_cmd_lock);
2883eb513658SMichael Chan 	return rc;
2884eb513658SMichael Chan }
2885eb513658SMichael Chan 
288655fd0cf3SMichael Chan #define BNXT_DRV_TESTS			4
2887f7dc1ea6SMichael Chan #define BNXT_MACLPBK_TEST_IDX		(bp->num_tests - BNXT_DRV_TESTS)
288891725d89SMichael Chan #define BNXT_PHYLPBK_TEST_IDX		(BNXT_MACLPBK_TEST_IDX + 1)
288955fd0cf3SMichael Chan #define BNXT_EXTLPBK_TEST_IDX		(BNXT_MACLPBK_TEST_IDX + 2)
289055fd0cf3SMichael Chan #define BNXT_IRQ_TEST_IDX		(BNXT_MACLPBK_TEST_IDX + 3)
2891eb513658SMichael Chan 
2892eb513658SMichael Chan static void bnxt_self_test(struct net_device *dev, struct ethtool_test *etest,
2893eb513658SMichael Chan 			   u64 *buf)
2894eb513658SMichael Chan {
2895eb513658SMichael Chan 	struct bnxt *bp = netdev_priv(dev);
289655fd0cf3SMichael Chan 	bool do_ext_lpbk = false;
2897eb513658SMichael Chan 	bool offline = false;
2898eb513658SMichael Chan 	u8 test_results = 0;
2899eb513658SMichael Chan 	u8 test_mask = 0;
2900d27e2ca1SMichael Chan 	int rc = 0, i;
2901eb513658SMichael Chan 
2902eb513658SMichael Chan 	if (!bp->num_tests || !BNXT_SINGLE_PF(bp))
2903eb513658SMichael Chan 		return;
2904eb513658SMichael Chan 	memset(buf, 0, sizeof(u64) * bp->num_tests);
2905eb513658SMichael Chan 	if (!netif_running(dev)) {
2906eb513658SMichael Chan 		etest->flags |= ETH_TEST_FL_FAILED;
2907eb513658SMichael Chan 		return;
2908eb513658SMichael Chan 	}
2909eb513658SMichael Chan 
291055fd0cf3SMichael Chan 	if ((etest->flags & ETH_TEST_FL_EXTERNAL_LB) &&
291155fd0cf3SMichael Chan 	    (bp->test_info->flags & BNXT_TEST_FL_EXT_LPBK))
291255fd0cf3SMichael Chan 		do_ext_lpbk = true;
291355fd0cf3SMichael Chan 
2914eb513658SMichael Chan 	if (etest->flags & ETH_TEST_FL_OFFLINE) {
2915eb513658SMichael Chan 		if (bp->pf.active_vfs) {
2916eb513658SMichael Chan 			etest->flags |= ETH_TEST_FL_FAILED;
2917eb513658SMichael Chan 			netdev_warn(dev, "Offline tests cannot be run with active VFs\n");
2918eb513658SMichael Chan 			return;
2919eb513658SMichael Chan 		}
2920eb513658SMichael Chan 		offline = true;
2921eb513658SMichael Chan 	}
2922eb513658SMichael Chan 
2923eb513658SMichael Chan 	for (i = 0; i < bp->num_tests - BNXT_DRV_TESTS; i++) {
2924eb513658SMichael Chan 		u8 bit_val = 1 << i;
2925eb513658SMichael Chan 
2926eb513658SMichael Chan 		if (!(bp->test_info->offline_mask & bit_val))
2927eb513658SMichael Chan 			test_mask |= bit_val;
2928eb513658SMichael Chan 		else if (offline)
2929eb513658SMichael Chan 			test_mask |= bit_val;
2930eb513658SMichael Chan 	}
2931eb513658SMichael Chan 	if (!offline) {
2932eb513658SMichael Chan 		bnxt_run_fw_tests(bp, test_mask, &test_results);
2933eb513658SMichael Chan 	} else {
2934eb513658SMichael Chan 		rc = bnxt_close_nic(bp, false, false);
2935eb513658SMichael Chan 		if (rc)
2936eb513658SMichael Chan 			return;
2937eb513658SMichael Chan 		bnxt_run_fw_tests(bp, test_mask, &test_results);
2938f7dc1ea6SMichael Chan 
2939f7dc1ea6SMichael Chan 		buf[BNXT_MACLPBK_TEST_IDX] = 1;
2940f7dc1ea6SMichael Chan 		bnxt_hwrm_mac_loopback(bp, true);
2941f7dc1ea6SMichael Chan 		msleep(250);
2942f7dc1ea6SMichael Chan 		rc = bnxt_half_open_nic(bp);
2943f7dc1ea6SMichael Chan 		if (rc) {
2944f7dc1ea6SMichael Chan 			bnxt_hwrm_mac_loopback(bp, false);
2945f7dc1ea6SMichael Chan 			etest->flags |= ETH_TEST_FL_FAILED;
2946f7dc1ea6SMichael Chan 			return;
2947f7dc1ea6SMichael Chan 		}
2948f7dc1ea6SMichael Chan 		if (bnxt_run_loopback(bp))
2949f7dc1ea6SMichael Chan 			etest->flags |= ETH_TEST_FL_FAILED;
2950f7dc1ea6SMichael Chan 		else
2951f7dc1ea6SMichael Chan 			buf[BNXT_MACLPBK_TEST_IDX] = 0;
2952f7dc1ea6SMichael Chan 
2953f7dc1ea6SMichael Chan 		bnxt_hwrm_mac_loopback(bp, false);
295455fd0cf3SMichael Chan 		bnxt_hwrm_phy_loopback(bp, true, false);
295591725d89SMichael Chan 		msleep(1000);
295691725d89SMichael Chan 		if (bnxt_run_loopback(bp)) {
295791725d89SMichael Chan 			buf[BNXT_PHYLPBK_TEST_IDX] = 1;
295891725d89SMichael Chan 			etest->flags |= ETH_TEST_FL_FAILED;
295991725d89SMichael Chan 		}
296055fd0cf3SMichael Chan 		if (do_ext_lpbk) {
296155fd0cf3SMichael Chan 			etest->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE;
296255fd0cf3SMichael Chan 			bnxt_hwrm_phy_loopback(bp, true, true);
296355fd0cf3SMichael Chan 			msleep(1000);
296455fd0cf3SMichael Chan 			if (bnxt_run_loopback(bp)) {
296555fd0cf3SMichael Chan 				buf[BNXT_EXTLPBK_TEST_IDX] = 1;
296655fd0cf3SMichael Chan 				etest->flags |= ETH_TEST_FL_FAILED;
296755fd0cf3SMichael Chan 			}
296855fd0cf3SMichael Chan 		}
296955fd0cf3SMichael Chan 		bnxt_hwrm_phy_loopback(bp, false, false);
297091725d89SMichael Chan 		bnxt_half_close_nic(bp);
2971d27e2ca1SMichael Chan 		rc = bnxt_open_nic(bp, false, true);
2972eb513658SMichael Chan 	}
2973d27e2ca1SMichael Chan 	if (rc || bnxt_test_irq(bp)) {
297467fea463SMichael Chan 		buf[BNXT_IRQ_TEST_IDX] = 1;
297567fea463SMichael Chan 		etest->flags |= ETH_TEST_FL_FAILED;
297667fea463SMichael Chan 	}
2977eb513658SMichael Chan 	for (i = 0; i < bp->num_tests - BNXT_DRV_TESTS; i++) {
2978eb513658SMichael Chan 		u8 bit_val = 1 << i;
2979eb513658SMichael Chan 
2980eb513658SMichael Chan 		if ((test_mask & bit_val) && !(test_results & bit_val)) {
2981eb513658SMichael Chan 			buf[i] = 1;
2982eb513658SMichael Chan 			etest->flags |= ETH_TEST_FL_FAILED;
2983eb513658SMichael Chan 		}
2984eb513658SMichael Chan 	}
2985eb513658SMichael Chan }
2986eb513658SMichael Chan 
298749f7972fSVasundhara Volam static int bnxt_reset(struct net_device *dev, u32 *flags)
298849f7972fSVasundhara Volam {
298949f7972fSVasundhara Volam 	struct bnxt *bp = netdev_priv(dev);
299049f7972fSVasundhara Volam 	int rc = 0;
299149f7972fSVasundhara Volam 
299249f7972fSVasundhara Volam 	if (!BNXT_PF(bp)) {
299349f7972fSVasundhara Volam 		netdev_err(dev, "Reset is not supported from a VF\n");
299449f7972fSVasundhara Volam 		return -EOPNOTSUPP;
299549f7972fSVasundhara Volam 	}
299649f7972fSVasundhara Volam 
29970a3f4e4fSVasundhara Volam 	if (pci_vfs_assigned(bp->pdev) &&
29980a3f4e4fSVasundhara Volam 	    !(bp->fw_cap & BNXT_FW_CAP_HOT_RESET)) {
299949f7972fSVasundhara Volam 		netdev_err(dev,
300049f7972fSVasundhara Volam 			   "Reset not allowed when VFs are assigned to VMs\n");
300149f7972fSVasundhara Volam 		return -EBUSY;
300249f7972fSVasundhara Volam 	}
300349f7972fSVasundhara Volam 
300449f7972fSVasundhara Volam 	if (*flags == ETH_RESET_ALL) {
300549f7972fSVasundhara Volam 		/* This feature is not supported in older firmware versions */
300649f7972fSVasundhara Volam 		if (bp->hwrm_spec_code < 0x10803)
300749f7972fSVasundhara Volam 			return -EOPNOTSUPP;
300849f7972fSVasundhara Volam 
300949f7972fSVasundhara Volam 		rc = bnxt_firmware_reset(dev, BNXT_FW_RESET_CHIP);
30102373d8d6SScott Branden 		if (!rc) {
30110a3f4e4fSVasundhara Volam 			netdev_info(dev, "Reset request successful.\n");
30120a3f4e4fSVasundhara Volam 			if (!(bp->fw_cap & BNXT_FW_CAP_HOT_RESET))
30130a3f4e4fSVasundhara Volam 				netdev_info(dev, "Reload driver to complete reset\n");
30142373d8d6SScott Branden 			*flags = 0;
30152373d8d6SScott Branden 		}
30166502ad59SScott Branden 	} else if (*flags == ETH_RESET_AP) {
30176502ad59SScott Branden 		/* This feature is not supported in older firmware versions */
30186502ad59SScott Branden 		if (bp->hwrm_spec_code < 0x10803)
30196502ad59SScott Branden 			return -EOPNOTSUPP;
30206502ad59SScott Branden 
30216502ad59SScott Branden 		rc = bnxt_firmware_reset(dev, BNXT_FW_RESET_AP);
30222373d8d6SScott Branden 		if (!rc) {
30236502ad59SScott Branden 			netdev_info(dev, "Reset Application Processor request successful.\n");
30242373d8d6SScott Branden 			*flags = 0;
30252373d8d6SScott Branden 		}
302649f7972fSVasundhara Volam 	} else {
302749f7972fSVasundhara Volam 		rc = -EINVAL;
302849f7972fSVasundhara Volam 	}
302949f7972fSVasundhara Volam 
303049f7972fSVasundhara Volam 	return rc;
303149f7972fSVasundhara Volam }
303249f7972fSVasundhara Volam 
30336c5657d0SVasundhara Volam static int bnxt_hwrm_dbg_dma_data(struct bnxt *bp, void *msg, int msg_len,
30346c5657d0SVasundhara Volam 				  struct bnxt_hwrm_dbg_dma_info *info)
30356c5657d0SVasundhara Volam {
30366c5657d0SVasundhara Volam 	struct hwrm_dbg_cmn_output *cmn_resp = bp->hwrm_cmd_resp_addr;
30376c5657d0SVasundhara Volam 	struct hwrm_dbg_cmn_input *cmn_req = msg;
30386c5657d0SVasundhara Volam 	__le16 *seq_ptr = msg + info->seq_off;
30396c5657d0SVasundhara Volam 	u16 seq = 0, len, segs_off;
30406c5657d0SVasundhara Volam 	void *resp = cmn_resp;
30416c5657d0SVasundhara Volam 	dma_addr_t dma_handle;
30426c5657d0SVasundhara Volam 	int rc, off = 0;
30436c5657d0SVasundhara Volam 	void *dma_buf;
30446c5657d0SVasundhara Volam 
30456c5657d0SVasundhara Volam 	dma_buf = dma_alloc_coherent(&bp->pdev->dev, info->dma_len, &dma_handle,
30466c5657d0SVasundhara Volam 				     GFP_KERNEL);
30476c5657d0SVasundhara Volam 	if (!dma_buf)
30486c5657d0SVasundhara Volam 		return -ENOMEM;
30496c5657d0SVasundhara Volam 
30506c5657d0SVasundhara Volam 	segs_off = offsetof(struct hwrm_dbg_coredump_list_output,
30516c5657d0SVasundhara Volam 			    total_segments);
30526c5657d0SVasundhara Volam 	cmn_req->host_dest_addr = cpu_to_le64(dma_handle);
30536c5657d0SVasundhara Volam 	cmn_req->host_buf_len = cpu_to_le32(info->dma_len);
30546c5657d0SVasundhara Volam 	mutex_lock(&bp->hwrm_cmd_lock);
30556c5657d0SVasundhara Volam 	while (1) {
30566c5657d0SVasundhara Volam 		*seq_ptr = cpu_to_le16(seq);
30575b306bdeSVasundhara Volam 		rc = _hwrm_send_message(bp, msg, msg_len,
30585b306bdeSVasundhara Volam 					HWRM_COREDUMP_TIMEOUT);
30596c5657d0SVasundhara Volam 		if (rc)
30606c5657d0SVasundhara Volam 			break;
30616c5657d0SVasundhara Volam 
30626c5657d0SVasundhara Volam 		len = le16_to_cpu(*((__le16 *)(resp + info->data_len_off)));
30636c5657d0SVasundhara Volam 		if (!seq &&
30646c5657d0SVasundhara Volam 		    cmn_req->req_type == cpu_to_le16(HWRM_DBG_COREDUMP_LIST)) {
30656c5657d0SVasundhara Volam 			info->segs = le16_to_cpu(*((__le16 *)(resp +
30666c5657d0SVasundhara Volam 							      segs_off)));
30676c5657d0SVasundhara Volam 			if (!info->segs) {
30686c5657d0SVasundhara Volam 				rc = -EIO;
30696c5657d0SVasundhara Volam 				break;
30706c5657d0SVasundhara Volam 			}
30716c5657d0SVasundhara Volam 
30726c5657d0SVasundhara Volam 			info->dest_buf_size = info->segs *
30736c5657d0SVasundhara Volam 					sizeof(struct coredump_segment_record);
30746c5657d0SVasundhara Volam 			info->dest_buf = kmalloc(info->dest_buf_size,
30756c5657d0SVasundhara Volam 						 GFP_KERNEL);
30766c5657d0SVasundhara Volam 			if (!info->dest_buf) {
30776c5657d0SVasundhara Volam 				rc = -ENOMEM;
30786c5657d0SVasundhara Volam 				break;
30796c5657d0SVasundhara Volam 			}
30806c5657d0SVasundhara Volam 		}
30816c5657d0SVasundhara Volam 
3082c74751f4SVasundhara Volam 		if (info->dest_buf) {
3083c74751f4SVasundhara Volam 			if ((info->seg_start + off + len) <=
3084c74751f4SVasundhara Volam 			    BNXT_COREDUMP_BUF_LEN(info->buf_len)) {
30856c5657d0SVasundhara Volam 				memcpy(info->dest_buf + off, dma_buf, len);
3086c74751f4SVasundhara Volam 			} else {
3087c74751f4SVasundhara Volam 				rc = -ENOBUFS;
3088c74751f4SVasundhara Volam 				break;
3089c74751f4SVasundhara Volam 			}
3090c74751f4SVasundhara Volam 		}
30916c5657d0SVasundhara Volam 
30926c5657d0SVasundhara Volam 		if (cmn_req->req_type ==
30936c5657d0SVasundhara Volam 				cpu_to_le16(HWRM_DBG_COREDUMP_RETRIEVE))
30946c5657d0SVasundhara Volam 			info->dest_buf_size += len;
30956c5657d0SVasundhara Volam 
30966c5657d0SVasundhara Volam 		if (!(cmn_resp->flags & HWRM_DBG_CMN_FLAGS_MORE))
30976c5657d0SVasundhara Volam 			break;
30986c5657d0SVasundhara Volam 
30996c5657d0SVasundhara Volam 		seq++;
31006c5657d0SVasundhara Volam 		off += len;
31016c5657d0SVasundhara Volam 	}
31026c5657d0SVasundhara Volam 	mutex_unlock(&bp->hwrm_cmd_lock);
31036c5657d0SVasundhara Volam 	dma_free_coherent(&bp->pdev->dev, info->dma_len, dma_buf, dma_handle);
31046c5657d0SVasundhara Volam 	return rc;
31056c5657d0SVasundhara Volam }
31066c5657d0SVasundhara Volam 
31076c5657d0SVasundhara Volam static int bnxt_hwrm_dbg_coredump_list(struct bnxt *bp,
31086c5657d0SVasundhara Volam 				       struct bnxt_coredump *coredump)
31096c5657d0SVasundhara Volam {
31106c5657d0SVasundhara Volam 	struct hwrm_dbg_coredump_list_input req = {0};
31116c5657d0SVasundhara Volam 	struct bnxt_hwrm_dbg_dma_info info = {NULL};
31126c5657d0SVasundhara Volam 	int rc;
31136c5657d0SVasundhara Volam 
31146c5657d0SVasundhara Volam 	bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_DBG_COREDUMP_LIST, -1, -1);
31156c5657d0SVasundhara Volam 
31166c5657d0SVasundhara Volam 	info.dma_len = COREDUMP_LIST_BUF_LEN;
31176c5657d0SVasundhara Volam 	info.seq_off = offsetof(struct hwrm_dbg_coredump_list_input, seq_no);
31186c5657d0SVasundhara Volam 	info.data_len_off = offsetof(struct hwrm_dbg_coredump_list_output,
31196c5657d0SVasundhara Volam 				     data_len);
31206c5657d0SVasundhara Volam 
31216c5657d0SVasundhara Volam 	rc = bnxt_hwrm_dbg_dma_data(bp, &req, sizeof(req), &info);
31226c5657d0SVasundhara Volam 	if (!rc) {
31236c5657d0SVasundhara Volam 		coredump->data = info.dest_buf;
31246c5657d0SVasundhara Volam 		coredump->data_size = info.dest_buf_size;
31256c5657d0SVasundhara Volam 		coredump->total_segs = info.segs;
31266c5657d0SVasundhara Volam 	}
31276c5657d0SVasundhara Volam 	return rc;
31286c5657d0SVasundhara Volam }
31296c5657d0SVasundhara Volam 
31306c5657d0SVasundhara Volam static int bnxt_hwrm_dbg_coredump_initiate(struct bnxt *bp, u16 component_id,
31316c5657d0SVasundhara Volam 					   u16 segment_id)
31326c5657d0SVasundhara Volam {
31336c5657d0SVasundhara Volam 	struct hwrm_dbg_coredump_initiate_input req = {0};
31346c5657d0SVasundhara Volam 
31356c5657d0SVasundhara Volam 	bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_DBG_COREDUMP_INITIATE, -1, -1);
31366c5657d0SVasundhara Volam 	req.component_id = cpu_to_le16(component_id);
31376c5657d0SVasundhara Volam 	req.segment_id = cpu_to_le16(segment_id);
31386c5657d0SVasundhara Volam 
313957a8730bSVasundhara Volam 	return hwrm_send_message(bp, &req, sizeof(req), HWRM_COREDUMP_TIMEOUT);
31406c5657d0SVasundhara Volam }
31416c5657d0SVasundhara Volam 
31426c5657d0SVasundhara Volam static int bnxt_hwrm_dbg_coredump_retrieve(struct bnxt *bp, u16 component_id,
31436c5657d0SVasundhara Volam 					   u16 segment_id, u32 *seg_len,
3144c74751f4SVasundhara Volam 					   void *buf, u32 buf_len, u32 offset)
31456c5657d0SVasundhara Volam {
31466c5657d0SVasundhara Volam 	struct hwrm_dbg_coredump_retrieve_input req = {0};
31476c5657d0SVasundhara Volam 	struct bnxt_hwrm_dbg_dma_info info = {NULL};
31486c5657d0SVasundhara Volam 	int rc;
31496c5657d0SVasundhara Volam 
31506c5657d0SVasundhara Volam 	bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_DBG_COREDUMP_RETRIEVE, -1, -1);
31516c5657d0SVasundhara Volam 	req.component_id = cpu_to_le16(component_id);
31526c5657d0SVasundhara Volam 	req.segment_id = cpu_to_le16(segment_id);
31536c5657d0SVasundhara Volam 
31546c5657d0SVasundhara Volam 	info.dma_len = COREDUMP_RETRIEVE_BUF_LEN;
31556c5657d0SVasundhara Volam 	info.seq_off = offsetof(struct hwrm_dbg_coredump_retrieve_input,
31566c5657d0SVasundhara Volam 				seq_no);
31576c5657d0SVasundhara Volam 	info.data_len_off = offsetof(struct hwrm_dbg_coredump_retrieve_output,
31586c5657d0SVasundhara Volam 				     data_len);
3159c74751f4SVasundhara Volam 	if (buf) {
31606c5657d0SVasundhara Volam 		info.dest_buf = buf + offset;
3161c74751f4SVasundhara Volam 		info.buf_len = buf_len;
3162c74751f4SVasundhara Volam 		info.seg_start = offset;
3163c74751f4SVasundhara Volam 	}
31646c5657d0SVasundhara Volam 
31656c5657d0SVasundhara Volam 	rc = bnxt_hwrm_dbg_dma_data(bp, &req, sizeof(req), &info);
31666c5657d0SVasundhara Volam 	if (!rc)
31676c5657d0SVasundhara Volam 		*seg_len = info.dest_buf_size;
31686c5657d0SVasundhara Volam 
31696c5657d0SVasundhara Volam 	return rc;
31706c5657d0SVasundhara Volam }
31716c5657d0SVasundhara Volam 
31726c5657d0SVasundhara Volam static void
31736c5657d0SVasundhara Volam bnxt_fill_coredump_seg_hdr(struct bnxt *bp,
31746c5657d0SVasundhara Volam 			   struct bnxt_coredump_segment_hdr *seg_hdr,
31756c5657d0SVasundhara Volam 			   struct coredump_segment_record *seg_rec, u32 seg_len,
31766c5657d0SVasundhara Volam 			   int status, u32 duration, u32 instance)
31776c5657d0SVasundhara Volam {
31786c5657d0SVasundhara Volam 	memset(seg_hdr, 0, sizeof(*seg_hdr));
31798605212aSVasundhara Volam 	memcpy(seg_hdr->signature, "sEgM", 4);
31806c5657d0SVasundhara Volam 	if (seg_rec) {
31816c5657d0SVasundhara Volam 		seg_hdr->component_id = (__force __le32)seg_rec->component_id;
31826c5657d0SVasundhara Volam 		seg_hdr->segment_id = (__force __le32)seg_rec->segment_id;
31836c5657d0SVasundhara Volam 		seg_hdr->low_version = seg_rec->version_low;
31846c5657d0SVasundhara Volam 		seg_hdr->high_version = seg_rec->version_hi;
31856c5657d0SVasundhara Volam 	} else {
31866c5657d0SVasundhara Volam 		/* For hwrm_ver_get response Component id = 2
31876c5657d0SVasundhara Volam 		 * and Segment id = 0
31886c5657d0SVasundhara Volam 		 */
31896c5657d0SVasundhara Volam 		seg_hdr->component_id = cpu_to_le32(2);
31906c5657d0SVasundhara Volam 		seg_hdr->segment_id = 0;
31916c5657d0SVasundhara Volam 	}
31926c5657d0SVasundhara Volam 	seg_hdr->function_id = cpu_to_le16(bp->pdev->devfn);
31936c5657d0SVasundhara Volam 	seg_hdr->length = cpu_to_le32(seg_len);
31946c5657d0SVasundhara Volam 	seg_hdr->status = cpu_to_le32(status);
31956c5657d0SVasundhara Volam 	seg_hdr->duration = cpu_to_le32(duration);
31966c5657d0SVasundhara Volam 	seg_hdr->data_offset = cpu_to_le32(sizeof(*seg_hdr));
31976c5657d0SVasundhara Volam 	seg_hdr->instance = cpu_to_le32(instance);
31986c5657d0SVasundhara Volam }
31996c5657d0SVasundhara Volam 
32006c5657d0SVasundhara Volam static void
32016c5657d0SVasundhara Volam bnxt_fill_coredump_record(struct bnxt *bp, struct bnxt_coredump_record *record,
32026c5657d0SVasundhara Volam 			  time64_t start, s16 start_utc, u16 total_segs,
32036c5657d0SVasundhara Volam 			  int status)
32046c5657d0SVasundhara Volam {
32056c5657d0SVasundhara Volam 	time64_t end = ktime_get_real_seconds();
32066c5657d0SVasundhara Volam 	u32 os_ver_major = 0, os_ver_minor = 0;
32076c5657d0SVasundhara Volam 	struct tm tm;
32086c5657d0SVasundhara Volam 
32096c5657d0SVasundhara Volam 	time64_to_tm(start, 0, &tm);
32106c5657d0SVasundhara Volam 	memset(record, 0, sizeof(*record));
32118605212aSVasundhara Volam 	memcpy(record->signature, "cOrE", 4);
32126c5657d0SVasundhara Volam 	record->flags = 0;
32136c5657d0SVasundhara Volam 	record->low_version = 0;
32146c5657d0SVasundhara Volam 	record->high_version = 1;
32156c5657d0SVasundhara Volam 	record->asic_state = 0;
32163d46eee5SArnd Bergmann 	strlcpy(record->system_name, utsname()->nodename,
32173d46eee5SArnd Bergmann 		sizeof(record->system_name));
32188dc5ae2dSVasundhara Volam 	record->year = cpu_to_le16(tm.tm_year + 1900);
32198dc5ae2dSVasundhara Volam 	record->month = cpu_to_le16(tm.tm_mon + 1);
32206c5657d0SVasundhara Volam 	record->day = cpu_to_le16(tm.tm_mday);
32216c5657d0SVasundhara Volam 	record->hour = cpu_to_le16(tm.tm_hour);
32226c5657d0SVasundhara Volam 	record->minute = cpu_to_le16(tm.tm_min);
32236c5657d0SVasundhara Volam 	record->second = cpu_to_le16(tm.tm_sec);
32246c5657d0SVasundhara Volam 	record->utc_bias = cpu_to_le16(start_utc);
32256c5657d0SVasundhara Volam 	strcpy(record->commandline, "ethtool -w");
32266c5657d0SVasundhara Volam 	record->total_segments = cpu_to_le32(total_segs);
32276c5657d0SVasundhara Volam 
32286c5657d0SVasundhara Volam 	sscanf(utsname()->release, "%u.%u", &os_ver_major, &os_ver_minor);
32296c5657d0SVasundhara Volam 	record->os_ver_major = cpu_to_le32(os_ver_major);
32306c5657d0SVasundhara Volam 	record->os_ver_minor = cpu_to_le32(os_ver_minor);
32316c5657d0SVasundhara Volam 
32328605212aSVasundhara Volam 	strlcpy(record->os_name, utsname()->sysname, 32);
32336c5657d0SVasundhara Volam 	time64_to_tm(end, 0, &tm);
32346c5657d0SVasundhara Volam 	record->end_year = cpu_to_le16(tm.tm_year + 1900);
32356c5657d0SVasundhara Volam 	record->end_month = cpu_to_le16(tm.tm_mon + 1);
32366c5657d0SVasundhara Volam 	record->end_day = cpu_to_le16(tm.tm_mday);
32376c5657d0SVasundhara Volam 	record->end_hour = cpu_to_le16(tm.tm_hour);
32386c5657d0SVasundhara Volam 	record->end_minute = cpu_to_le16(tm.tm_min);
32396c5657d0SVasundhara Volam 	record->end_second = cpu_to_le16(tm.tm_sec);
32406c5657d0SVasundhara Volam 	record->end_utc_bias = cpu_to_le16(sys_tz.tz_minuteswest * 60);
32416c5657d0SVasundhara Volam 	record->asic_id1 = cpu_to_le32(bp->chip_num << 16 |
32426c5657d0SVasundhara Volam 				       bp->ver_resp.chip_rev << 8 |
32436c5657d0SVasundhara Volam 				       bp->ver_resp.chip_metal);
32446c5657d0SVasundhara Volam 	record->asic_id2 = 0;
32456c5657d0SVasundhara Volam 	record->coredump_status = cpu_to_le32(status);
32466c5657d0SVasundhara Volam 	record->ioctl_low_version = 0;
32476c5657d0SVasundhara Volam 	record->ioctl_high_version = 0;
32486c5657d0SVasundhara Volam }
32496c5657d0SVasundhara Volam 
32506c5657d0SVasundhara Volam static int bnxt_get_coredump(struct bnxt *bp, void *buf, u32 *dump_len)
32516c5657d0SVasundhara Volam {
32526c5657d0SVasundhara Volam 	u32 ver_get_resp_len = sizeof(struct hwrm_ver_get_output);
3253c74751f4SVasundhara Volam 	u32 offset = 0, seg_hdr_len, seg_record_len, buf_len = 0;
32546c5657d0SVasundhara Volam 	struct coredump_segment_record *seg_record = NULL;
32556c5657d0SVasundhara Volam 	struct bnxt_coredump_segment_hdr seg_hdr;
32566c5657d0SVasundhara Volam 	struct bnxt_coredump coredump = {NULL};
32576c5657d0SVasundhara Volam 	time64_t start_time;
32586c5657d0SVasundhara Volam 	u16 start_utc;
32596c5657d0SVasundhara Volam 	int rc = 0, i;
32606c5657d0SVasundhara Volam 
3261c74751f4SVasundhara Volam 	if (buf)
3262c74751f4SVasundhara Volam 		buf_len = *dump_len;
3263c74751f4SVasundhara Volam 
32646c5657d0SVasundhara Volam 	start_time = ktime_get_real_seconds();
32656c5657d0SVasundhara Volam 	start_utc = sys_tz.tz_minuteswest * 60;
32666c5657d0SVasundhara Volam 	seg_hdr_len = sizeof(seg_hdr);
32676c5657d0SVasundhara Volam 
32686c5657d0SVasundhara Volam 	/* First segment should be hwrm_ver_get response */
32696c5657d0SVasundhara Volam 	*dump_len = seg_hdr_len + ver_get_resp_len;
32706c5657d0SVasundhara Volam 	if (buf) {
32716c5657d0SVasundhara Volam 		bnxt_fill_coredump_seg_hdr(bp, &seg_hdr, NULL, ver_get_resp_len,
32726c5657d0SVasundhara Volam 					   0, 0, 0);
32736c5657d0SVasundhara Volam 		memcpy(buf + offset, &seg_hdr, seg_hdr_len);
32746c5657d0SVasundhara Volam 		offset += seg_hdr_len;
32756c5657d0SVasundhara Volam 		memcpy(buf + offset, &bp->ver_resp, ver_get_resp_len);
32766c5657d0SVasundhara Volam 		offset += ver_get_resp_len;
32776c5657d0SVasundhara Volam 	}
32786c5657d0SVasundhara Volam 
32796c5657d0SVasundhara Volam 	rc = bnxt_hwrm_dbg_coredump_list(bp, &coredump);
32806c5657d0SVasundhara Volam 	if (rc) {
32816c5657d0SVasundhara Volam 		netdev_err(bp->dev, "Failed to get coredump segment list\n");
32826c5657d0SVasundhara Volam 		goto err;
32836c5657d0SVasundhara Volam 	}
32846c5657d0SVasundhara Volam 
32856c5657d0SVasundhara Volam 	*dump_len += seg_hdr_len * coredump.total_segs;
32866c5657d0SVasundhara Volam 
32876c5657d0SVasundhara Volam 	seg_record = (struct coredump_segment_record *)coredump.data;
32886c5657d0SVasundhara Volam 	seg_record_len = sizeof(*seg_record);
32896c5657d0SVasundhara Volam 
32906c5657d0SVasundhara Volam 	for (i = 0; i < coredump.total_segs; i++) {
32916c5657d0SVasundhara Volam 		u16 comp_id = le16_to_cpu(seg_record->component_id);
32926c5657d0SVasundhara Volam 		u16 seg_id = le16_to_cpu(seg_record->segment_id);
32936c5657d0SVasundhara Volam 		u32 duration = 0, seg_len = 0;
32946c5657d0SVasundhara Volam 		unsigned long start, end;
32956c5657d0SVasundhara Volam 
3296c74751f4SVasundhara Volam 		if (buf && ((offset + seg_hdr_len) >
3297c74751f4SVasundhara Volam 			    BNXT_COREDUMP_BUF_LEN(buf_len))) {
3298c74751f4SVasundhara Volam 			rc = -ENOBUFS;
3299c74751f4SVasundhara Volam 			goto err;
3300c74751f4SVasundhara Volam 		}
3301c74751f4SVasundhara Volam 
33026c5657d0SVasundhara Volam 		start = jiffies;
33036c5657d0SVasundhara Volam 
33046c5657d0SVasundhara Volam 		rc = bnxt_hwrm_dbg_coredump_initiate(bp, comp_id, seg_id);
33056c5657d0SVasundhara Volam 		if (rc) {
33066c5657d0SVasundhara Volam 			netdev_err(bp->dev,
33076c5657d0SVasundhara Volam 				   "Failed to initiate coredump for seg = %d\n",
33086c5657d0SVasundhara Volam 				   seg_record->segment_id);
33096c5657d0SVasundhara Volam 			goto next_seg;
33106c5657d0SVasundhara Volam 		}
33116c5657d0SVasundhara Volam 
33126c5657d0SVasundhara Volam 		/* Write segment data into the buffer */
33136c5657d0SVasundhara Volam 		rc = bnxt_hwrm_dbg_coredump_retrieve(bp, comp_id, seg_id,
3314c74751f4SVasundhara Volam 						     &seg_len, buf, buf_len,
33156c5657d0SVasundhara Volam 						     offset + seg_hdr_len);
3316c74751f4SVasundhara Volam 		if (rc && rc == -ENOBUFS)
3317c74751f4SVasundhara Volam 			goto err;
3318c74751f4SVasundhara Volam 		else if (rc)
33196c5657d0SVasundhara Volam 			netdev_err(bp->dev,
33206c5657d0SVasundhara Volam 				   "Failed to retrieve coredump for seg = %d\n",
33216c5657d0SVasundhara Volam 				   seg_record->segment_id);
33226c5657d0SVasundhara Volam 
33236c5657d0SVasundhara Volam next_seg:
33246c5657d0SVasundhara Volam 		end = jiffies;
33256c5657d0SVasundhara Volam 		duration = jiffies_to_msecs(end - start);
33266c5657d0SVasundhara Volam 		bnxt_fill_coredump_seg_hdr(bp, &seg_hdr, seg_record, seg_len,
33276c5657d0SVasundhara Volam 					   rc, duration, 0);
33286c5657d0SVasundhara Volam 
33296c5657d0SVasundhara Volam 		if (buf) {
33306c5657d0SVasundhara Volam 			/* Write segment header into the buffer */
33316c5657d0SVasundhara Volam 			memcpy(buf + offset, &seg_hdr, seg_hdr_len);
33326c5657d0SVasundhara Volam 			offset += seg_hdr_len + seg_len;
33336c5657d0SVasundhara Volam 		}
33346c5657d0SVasundhara Volam 
33356c5657d0SVasundhara Volam 		*dump_len += seg_len;
33366c5657d0SVasundhara Volam 		seg_record =
33376c5657d0SVasundhara Volam 			(struct coredump_segment_record *)((u8 *)seg_record +
33386c5657d0SVasundhara Volam 							   seg_record_len);
33396c5657d0SVasundhara Volam 	}
33406c5657d0SVasundhara Volam 
33416c5657d0SVasundhara Volam err:
33421bbf3aedSArnd Bergmann 	if (buf)
33431bbf3aedSArnd Bergmann 		bnxt_fill_coredump_record(bp, buf + offset, start_time,
33446c5657d0SVasundhara Volam 					  start_utc, coredump.total_segs + 1,
33456c5657d0SVasundhara Volam 					  rc);
33466c5657d0SVasundhara Volam 	kfree(coredump.data);
33471bbf3aedSArnd Bergmann 	*dump_len += sizeof(struct bnxt_coredump_record);
3348c74751f4SVasundhara Volam 	if (rc == -ENOBUFS)
33499a005c38SJonathan Lemon 		netdev_err(bp->dev, "Firmware returned large coredump buffer\n");
33506c5657d0SVasundhara Volam 	return rc;
33516c5657d0SVasundhara Volam }
33526c5657d0SVasundhara Volam 
33530b0eacf3SVasundhara Volam static int bnxt_set_dump(struct net_device *dev, struct ethtool_dump *dump)
33540b0eacf3SVasundhara Volam {
33550b0eacf3SVasundhara Volam 	struct bnxt *bp = netdev_priv(dev);
33560b0eacf3SVasundhara Volam 
33570b0eacf3SVasundhara Volam 	if (dump->flag > BNXT_DUMP_CRASH) {
33580b0eacf3SVasundhara Volam 		netdev_info(dev, "Supports only Live(0) and Crash(1) dumps.\n");
33590b0eacf3SVasundhara Volam 		return -EINVAL;
33600b0eacf3SVasundhara Volam 	}
33610b0eacf3SVasundhara Volam 
33620b0eacf3SVasundhara Volam 	if (!IS_ENABLED(CONFIG_TEE_BNXT_FW) && dump->flag == BNXT_DUMP_CRASH) {
33630b0eacf3SVasundhara Volam 		netdev_info(dev, "Cannot collect crash dump as TEE_BNXT_FW config option is not enabled.\n");
33640b0eacf3SVasundhara Volam 		return -EOPNOTSUPP;
33650b0eacf3SVasundhara Volam 	}
33660b0eacf3SVasundhara Volam 
33670b0eacf3SVasundhara Volam 	bp->dump_flag = dump->flag;
33680b0eacf3SVasundhara Volam 	return 0;
33690b0eacf3SVasundhara Volam }
33700b0eacf3SVasundhara Volam 
33716c5657d0SVasundhara Volam static int bnxt_get_dump_flag(struct net_device *dev, struct ethtool_dump *dump)
33726c5657d0SVasundhara Volam {
33736c5657d0SVasundhara Volam 	struct bnxt *bp = netdev_priv(dev);
33746c5657d0SVasundhara Volam 
33756c5657d0SVasundhara Volam 	if (bp->hwrm_spec_code < 0x10801)
33766c5657d0SVasundhara Volam 		return -EOPNOTSUPP;
33776c5657d0SVasundhara Volam 
33786c5657d0SVasundhara Volam 	dump->version = bp->ver_resp.hwrm_fw_maj_8b << 24 |
33796c5657d0SVasundhara Volam 			bp->ver_resp.hwrm_fw_min_8b << 16 |
33806c5657d0SVasundhara Volam 			bp->ver_resp.hwrm_fw_bld_8b << 8 |
33816c5657d0SVasundhara Volam 			bp->ver_resp.hwrm_fw_rsvd_8b;
33826c5657d0SVasundhara Volam 
33830b0eacf3SVasundhara Volam 	dump->flag = bp->dump_flag;
33840b0eacf3SVasundhara Volam 	if (bp->dump_flag == BNXT_DUMP_CRASH)
33850b0eacf3SVasundhara Volam 		dump->len = BNXT_CRASH_DUMP_LEN;
33860b0eacf3SVasundhara Volam 	else
33870b0eacf3SVasundhara Volam 		bnxt_get_coredump(bp, NULL, &dump->len);
33880b0eacf3SVasundhara Volam 	return 0;
33896c5657d0SVasundhara Volam }
33906c5657d0SVasundhara Volam 
33916c5657d0SVasundhara Volam static int bnxt_get_dump_data(struct net_device *dev, struct ethtool_dump *dump,
33926c5657d0SVasundhara Volam 			      void *buf)
33936c5657d0SVasundhara Volam {
33946c5657d0SVasundhara Volam 	struct bnxt *bp = netdev_priv(dev);
33956c5657d0SVasundhara Volam 
33966c5657d0SVasundhara Volam 	if (bp->hwrm_spec_code < 0x10801)
33976c5657d0SVasundhara Volam 		return -EOPNOTSUPP;
33986c5657d0SVasundhara Volam 
33996c5657d0SVasundhara Volam 	memset(buf, 0, dump->len);
34006c5657d0SVasundhara Volam 
34010b0eacf3SVasundhara Volam 	dump->flag = bp->dump_flag;
34020b0eacf3SVasundhara Volam 	if (dump->flag == BNXT_DUMP_CRASH) {
34030b0eacf3SVasundhara Volam #ifdef CONFIG_TEE_BNXT_FW
34040b0eacf3SVasundhara Volam 		return tee_bnxt_copy_coredump(buf, 0, dump->len);
34050b0eacf3SVasundhara Volam #endif
34060b0eacf3SVasundhara Volam 	} else {
34076c5657d0SVasundhara Volam 		return bnxt_get_coredump(bp, buf, &dump->len);
34086c5657d0SVasundhara Volam 	}
34096c5657d0SVasundhara Volam 
34100b0eacf3SVasundhara Volam 	return 0;
34110b0eacf3SVasundhara Volam }
34120b0eacf3SVasundhara Volam 
3413eb513658SMichael Chan void bnxt_ethtool_init(struct bnxt *bp)
3414eb513658SMichael Chan {
3415eb513658SMichael Chan 	struct hwrm_selftest_qlist_output *resp = bp->hwrm_cmd_resp_addr;
3416eb513658SMichael Chan 	struct hwrm_selftest_qlist_input req = {0};
3417eb513658SMichael Chan 	struct bnxt_test_info *test_info;
3418431aa1ebSMichael Chan 	struct net_device *dev = bp->dev;
3419eb513658SMichael Chan 	int i, rc;
3420eb513658SMichael Chan 
3421691aa620SVasundhara Volam 	if (!(bp->fw_cap & BNXT_FW_CAP_PKG_VER))
3422a60faa60SVasundhara Volam 		bnxt_get_pkgver(dev);
3423431aa1ebSMichael Chan 
3424ba642ab7SMichael Chan 	bp->num_tests = 0;
3425eb513658SMichael Chan 	if (bp->hwrm_spec_code < 0x10704 || !BNXT_SINGLE_PF(bp))
3426eb513658SMichael Chan 		return;
3427eb513658SMichael Chan 
3428eb513658SMichael Chan 	bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_QLIST, -1, -1);
3429eb513658SMichael Chan 	mutex_lock(&bp->hwrm_cmd_lock);
3430eb513658SMichael Chan 	rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3431eb513658SMichael Chan 	if (rc)
3432eb513658SMichael Chan 		goto ethtool_init_exit;
3433eb513658SMichael Chan 
3434ba642ab7SMichael Chan 	test_info = bp->test_info;
3435ba642ab7SMichael Chan 	if (!test_info)
3436eb513658SMichael Chan 		test_info = kzalloc(sizeof(*bp->test_info), GFP_KERNEL);
3437eb513658SMichael Chan 	if (!test_info)
3438eb513658SMichael Chan 		goto ethtool_init_exit;
3439eb513658SMichael Chan 
3440eb513658SMichael Chan 	bp->test_info = test_info;
3441eb513658SMichael Chan 	bp->num_tests = resp->num_tests + BNXT_DRV_TESTS;
3442eb513658SMichael Chan 	if (bp->num_tests > BNXT_MAX_TEST)
3443eb513658SMichael Chan 		bp->num_tests = BNXT_MAX_TEST;
3444eb513658SMichael Chan 
3445eb513658SMichael Chan 	test_info->offline_mask = resp->offline_tests;
3446eb513658SMichael Chan 	test_info->timeout = le16_to_cpu(resp->test_timeout);
3447eb513658SMichael Chan 	if (!test_info->timeout)
3448eb513658SMichael Chan 		test_info->timeout = HWRM_CMD_TIMEOUT;
3449eb513658SMichael Chan 	for (i = 0; i < bp->num_tests; i++) {
3450eb513658SMichael Chan 		char *str = test_info->string[i];
3451eb513658SMichael Chan 		char *fw_str = resp->test0_name + i * 32;
3452eb513658SMichael Chan 
3453f7dc1ea6SMichael Chan 		if (i == BNXT_MACLPBK_TEST_IDX) {
3454f7dc1ea6SMichael Chan 			strcpy(str, "Mac loopback test (offline)");
345591725d89SMichael Chan 		} else if (i == BNXT_PHYLPBK_TEST_IDX) {
345691725d89SMichael Chan 			strcpy(str, "Phy loopback test (offline)");
345755fd0cf3SMichael Chan 		} else if (i == BNXT_EXTLPBK_TEST_IDX) {
345855fd0cf3SMichael Chan 			strcpy(str, "Ext loopback test (offline)");
345967fea463SMichael Chan 		} else if (i == BNXT_IRQ_TEST_IDX) {
346067fea463SMichael Chan 			strcpy(str, "Interrupt_test (offline)");
3461f7dc1ea6SMichael Chan 		} else {
3462eb513658SMichael Chan 			strlcpy(str, fw_str, ETH_GSTRING_LEN);
3463eb513658SMichael Chan 			strncat(str, " test", ETH_GSTRING_LEN - strlen(str));
3464eb513658SMichael Chan 			if (test_info->offline_mask & (1 << i))
3465eb513658SMichael Chan 				strncat(str, " (offline)",
3466eb513658SMichael Chan 					ETH_GSTRING_LEN - strlen(str));
3467eb513658SMichael Chan 			else
3468eb513658SMichael Chan 				strncat(str, " (online)",
3469eb513658SMichael Chan 					ETH_GSTRING_LEN - strlen(str));
3470eb513658SMichael Chan 		}
3471f7dc1ea6SMichael Chan 	}
3472eb513658SMichael Chan 
3473eb513658SMichael Chan ethtool_init_exit:
3474eb513658SMichael Chan 	mutex_unlock(&bp->hwrm_cmd_lock);
3475eb513658SMichael Chan }
3476eb513658SMichael Chan 
3477eb513658SMichael Chan void bnxt_ethtool_free(struct bnxt *bp)
3478eb513658SMichael Chan {
3479eb513658SMichael Chan 	kfree(bp->test_info);
3480eb513658SMichael Chan 	bp->test_info = NULL;
3481eb513658SMichael Chan }
3482eb513658SMichael Chan 
3483c0c050c5SMichael Chan const struct ethtool_ops bnxt_ethtool_ops = {
3484f704d243SJakub Kicinski 	.supported_coalesce_params = ETHTOOL_COALESCE_USECS |
3485f704d243SJakub Kicinski 				     ETHTOOL_COALESCE_MAX_FRAMES |
3486f704d243SJakub Kicinski 				     ETHTOOL_COALESCE_USECS_IRQ |
3487f704d243SJakub Kicinski 				     ETHTOOL_COALESCE_MAX_FRAMES_IRQ |
3488f704d243SJakub Kicinski 				     ETHTOOL_COALESCE_STATS_BLOCK_USECS |
3489f704d243SJakub Kicinski 				     ETHTOOL_COALESCE_USE_ADAPTIVE_RX,
349000c04a92SMichael Chan 	.get_link_ksettings	= bnxt_get_link_ksettings,
349100c04a92SMichael Chan 	.set_link_ksettings	= bnxt_set_link_ksettings,
3492c0c050c5SMichael Chan 	.get_pauseparam		= bnxt_get_pauseparam,
3493c0c050c5SMichael Chan 	.set_pauseparam		= bnxt_set_pauseparam,
3494c0c050c5SMichael Chan 	.get_drvinfo		= bnxt_get_drvinfo,
34958e202366SMichael Chan 	.get_wol		= bnxt_get_wol,
34965282db6cSMichael Chan 	.set_wol		= bnxt_set_wol,
3497c0c050c5SMichael Chan 	.get_coalesce		= bnxt_get_coalesce,
3498c0c050c5SMichael Chan 	.set_coalesce		= bnxt_set_coalesce,
3499c0c050c5SMichael Chan 	.get_msglevel		= bnxt_get_msglevel,
3500c0c050c5SMichael Chan 	.set_msglevel		= bnxt_set_msglevel,
3501c0c050c5SMichael Chan 	.get_sset_count		= bnxt_get_sset_count,
3502c0c050c5SMichael Chan 	.get_strings		= bnxt_get_strings,
3503c0c050c5SMichael Chan 	.get_ethtool_stats	= bnxt_get_ethtool_stats,
3504c0c050c5SMichael Chan 	.set_ringparam		= bnxt_set_ringparam,
3505c0c050c5SMichael Chan 	.get_ringparam		= bnxt_get_ringparam,
3506c0c050c5SMichael Chan 	.get_channels		= bnxt_get_channels,
3507c0c050c5SMichael Chan 	.set_channels		= bnxt_set_channels,
3508c0c050c5SMichael Chan 	.get_rxnfc		= bnxt_get_rxnfc,
3509a011952aSMichael Chan 	.set_rxnfc		= bnxt_set_rxnfc,
3510c0c050c5SMichael Chan 	.get_rxfh_indir_size    = bnxt_get_rxfh_indir_size,
3511c0c050c5SMichael Chan 	.get_rxfh_key_size      = bnxt_get_rxfh_key_size,
3512c0c050c5SMichael Chan 	.get_rxfh               = bnxt_get_rxfh,
3513c0c050c5SMichael Chan 	.flash_device		= bnxt_flash_device,
3514c0c050c5SMichael Chan 	.get_eeprom_len         = bnxt_get_eeprom_len,
3515c0c050c5SMichael Chan 	.get_eeprom             = bnxt_get_eeprom,
3516c0c050c5SMichael Chan 	.set_eeprom		= bnxt_set_eeprom,
3517c0c050c5SMichael Chan 	.get_link		= bnxt_get_link,
351872b34f04SMichael Chan 	.get_eee		= bnxt_get_eee,
351972b34f04SMichael Chan 	.set_eee		= bnxt_set_eee,
352042ee18feSAjit Khaparde 	.get_module_info	= bnxt_get_module_info,
352142ee18feSAjit Khaparde 	.get_module_eeprom	= bnxt_get_module_eeprom,
35225ad2cbeeSMichael Chan 	.nway_reset		= bnxt_nway_reset,
35235ad2cbeeSMichael Chan 	.set_phys_id		= bnxt_set_phys_id,
3524eb513658SMichael Chan 	.self_test		= bnxt_self_test,
352549f7972fSVasundhara Volam 	.reset			= bnxt_reset,
35260b0eacf3SVasundhara Volam 	.set_dump		= bnxt_set_dump,
35276c5657d0SVasundhara Volam 	.get_dump_flag		= bnxt_get_dump_flag,
35286c5657d0SVasundhara Volam 	.get_dump_data		= bnxt_get_dump_data,
3529c0c050c5SMichael Chan };
3530