1adfc5217SJeff Kirsher /* bnx2x_ethtool.c: Broadcom Everest network driver.
2adfc5217SJeff Kirsher  *
3247fa82bSYuval Mintz  * Copyright (c) 2007-2013 Broadcom Corporation
4adfc5217SJeff Kirsher  *
5adfc5217SJeff Kirsher  * This program is free software; you can redistribute it and/or modify
6adfc5217SJeff Kirsher  * it under the terms of the GNU General Public License as published by
7adfc5217SJeff Kirsher  * the Free Software Foundation.
8adfc5217SJeff Kirsher  *
9adfc5217SJeff Kirsher  * Maintained by: Eilon Greenstein <eilong@broadcom.com>
10adfc5217SJeff Kirsher  * Written by: Eliezer Tamir
11adfc5217SJeff Kirsher  * Based on code from Michael Chan's bnx2 driver
12adfc5217SJeff Kirsher  * UDP CSUM errata workaround by Arik Gendelman
13adfc5217SJeff Kirsher  * Slowpath and fastpath rework by Vladislav Zolotarov
14adfc5217SJeff Kirsher  * Statistics and Link management by Yitchak Gertner
15adfc5217SJeff Kirsher  *
16adfc5217SJeff Kirsher  */
17f1deab50SJoe Perches 
18f1deab50SJoe Perches #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19f1deab50SJoe Perches 
20adfc5217SJeff Kirsher #include <linux/ethtool.h>
21adfc5217SJeff Kirsher #include <linux/netdevice.h>
22adfc5217SJeff Kirsher #include <linux/types.h>
23adfc5217SJeff Kirsher #include <linux/sched.h>
24adfc5217SJeff Kirsher #include <linux/crc32.h>
25adfc5217SJeff Kirsher #include "bnx2x.h"
26adfc5217SJeff Kirsher #include "bnx2x_cmn.h"
27adfc5217SJeff Kirsher #include "bnx2x_dump.h"
28adfc5217SJeff Kirsher #include "bnx2x_init.h"
29adfc5217SJeff Kirsher 
30adfc5217SJeff Kirsher /* Note: in the format strings below %s is replaced by the queue-name which is
31adfc5217SJeff Kirsher  * either its index or 'fcoe' for the fcoe queue. Make sure the format string
32adfc5217SJeff Kirsher  * length does not exceed ETH_GSTRING_LEN - MAX_QUEUE_NAME_LEN + 2
33adfc5217SJeff Kirsher  */
34adfc5217SJeff Kirsher #define MAX_QUEUE_NAME_LEN	4
35adfc5217SJeff Kirsher static const struct {
36adfc5217SJeff Kirsher 	long offset;
37adfc5217SJeff Kirsher 	int size;
38adfc5217SJeff Kirsher 	char string[ETH_GSTRING_LEN];
39adfc5217SJeff Kirsher } bnx2x_q_stats_arr[] = {
40adfc5217SJeff Kirsher /* 1 */	{ Q_STATS_OFFSET32(total_bytes_received_hi), 8, "[%s]: rx_bytes" },
41adfc5217SJeff Kirsher 	{ Q_STATS_OFFSET32(total_unicast_packets_received_hi),
42adfc5217SJeff Kirsher 						8, "[%s]: rx_ucast_packets" },
43adfc5217SJeff Kirsher 	{ Q_STATS_OFFSET32(total_multicast_packets_received_hi),
44adfc5217SJeff Kirsher 						8, "[%s]: rx_mcast_packets" },
45adfc5217SJeff Kirsher 	{ Q_STATS_OFFSET32(total_broadcast_packets_received_hi),
46adfc5217SJeff Kirsher 						8, "[%s]: rx_bcast_packets" },
47adfc5217SJeff Kirsher 	{ Q_STATS_OFFSET32(no_buff_discard_hi),	8, "[%s]: rx_discards" },
48adfc5217SJeff Kirsher 	{ Q_STATS_OFFSET32(rx_err_discard_pkt),
49adfc5217SJeff Kirsher 					 4, "[%s]: rx_phy_ip_err_discards"},
50adfc5217SJeff Kirsher 	{ Q_STATS_OFFSET32(rx_skb_alloc_failed),
51adfc5217SJeff Kirsher 					 4, "[%s]: rx_skb_alloc_discard" },
52adfc5217SJeff Kirsher 	{ Q_STATS_OFFSET32(hw_csum_err), 4, "[%s]: rx_csum_offload_errors" },
53adfc5217SJeff Kirsher 
54adfc5217SJeff Kirsher 	{ Q_STATS_OFFSET32(total_bytes_transmitted_hi),	8, "[%s]: tx_bytes" },
55adfc5217SJeff Kirsher /* 10 */{ Q_STATS_OFFSET32(total_unicast_packets_transmitted_hi),
56adfc5217SJeff Kirsher 						8, "[%s]: tx_ucast_packets" },
57adfc5217SJeff Kirsher 	{ Q_STATS_OFFSET32(total_multicast_packets_transmitted_hi),
58adfc5217SJeff Kirsher 						8, "[%s]: tx_mcast_packets" },
59adfc5217SJeff Kirsher 	{ Q_STATS_OFFSET32(total_broadcast_packets_transmitted_hi),
60adfc5217SJeff Kirsher 						8, "[%s]: tx_bcast_packets" },
61adfc5217SJeff Kirsher 	{ Q_STATS_OFFSET32(total_tpa_aggregations_hi),
62adfc5217SJeff Kirsher 						8, "[%s]: tpa_aggregations" },
63adfc5217SJeff Kirsher 	{ Q_STATS_OFFSET32(total_tpa_aggregated_frames_hi),
64adfc5217SJeff Kirsher 					8, "[%s]: tpa_aggregated_frames"},
65c96bdc0cSDmitry Kravkov 	{ Q_STATS_OFFSET32(total_tpa_bytes_hi),	8, "[%s]: tpa_bytes"},
66c96bdc0cSDmitry Kravkov 	{ Q_STATS_OFFSET32(driver_filtered_tx_pkt),
67c96bdc0cSDmitry Kravkov 					4, "[%s]: driver_filtered_tx_pkt" }
68adfc5217SJeff Kirsher };
69adfc5217SJeff Kirsher 
70adfc5217SJeff Kirsher #define BNX2X_NUM_Q_STATS ARRAY_SIZE(bnx2x_q_stats_arr)
71adfc5217SJeff Kirsher 
72adfc5217SJeff Kirsher static const struct {
73adfc5217SJeff Kirsher 	long offset;
74adfc5217SJeff Kirsher 	int size;
75adfc5217SJeff Kirsher 	u32 flags;
76adfc5217SJeff Kirsher #define STATS_FLAGS_PORT		1
77adfc5217SJeff Kirsher #define STATS_FLAGS_FUNC		2
78adfc5217SJeff Kirsher #define STATS_FLAGS_BOTH		(STATS_FLAGS_FUNC | STATS_FLAGS_PORT)
79adfc5217SJeff Kirsher 	char string[ETH_GSTRING_LEN];
80adfc5217SJeff Kirsher } bnx2x_stats_arr[] = {
81adfc5217SJeff Kirsher /* 1 */	{ STATS_OFFSET32(total_bytes_received_hi),
82adfc5217SJeff Kirsher 				8, STATS_FLAGS_BOTH, "rx_bytes" },
83adfc5217SJeff Kirsher 	{ STATS_OFFSET32(error_bytes_received_hi),
84adfc5217SJeff Kirsher 				8, STATS_FLAGS_BOTH, "rx_error_bytes" },
85adfc5217SJeff Kirsher 	{ STATS_OFFSET32(total_unicast_packets_received_hi),
86adfc5217SJeff Kirsher 				8, STATS_FLAGS_BOTH, "rx_ucast_packets" },
87adfc5217SJeff Kirsher 	{ STATS_OFFSET32(total_multicast_packets_received_hi),
88adfc5217SJeff Kirsher 				8, STATS_FLAGS_BOTH, "rx_mcast_packets" },
89adfc5217SJeff Kirsher 	{ STATS_OFFSET32(total_broadcast_packets_received_hi),
90adfc5217SJeff Kirsher 				8, STATS_FLAGS_BOTH, "rx_bcast_packets" },
91adfc5217SJeff Kirsher 	{ STATS_OFFSET32(rx_stat_dot3statsfcserrors_hi),
92adfc5217SJeff Kirsher 				8, STATS_FLAGS_PORT, "rx_crc_errors" },
93adfc5217SJeff Kirsher 	{ STATS_OFFSET32(rx_stat_dot3statsalignmenterrors_hi),
94adfc5217SJeff Kirsher 				8, STATS_FLAGS_PORT, "rx_align_errors" },
95adfc5217SJeff Kirsher 	{ STATS_OFFSET32(rx_stat_etherstatsundersizepkts_hi),
96adfc5217SJeff Kirsher 				8, STATS_FLAGS_PORT, "rx_undersize_packets" },
97adfc5217SJeff Kirsher 	{ STATS_OFFSET32(etherstatsoverrsizepkts_hi),
98adfc5217SJeff Kirsher 				8, STATS_FLAGS_PORT, "rx_oversize_packets" },
99adfc5217SJeff Kirsher /* 10 */{ STATS_OFFSET32(rx_stat_etherstatsfragments_hi),
100adfc5217SJeff Kirsher 				8, STATS_FLAGS_PORT, "rx_fragments" },
101adfc5217SJeff Kirsher 	{ STATS_OFFSET32(rx_stat_etherstatsjabbers_hi),
102adfc5217SJeff Kirsher 				8, STATS_FLAGS_PORT, "rx_jabbers" },
103adfc5217SJeff Kirsher 	{ STATS_OFFSET32(no_buff_discard_hi),
104adfc5217SJeff Kirsher 				8, STATS_FLAGS_BOTH, "rx_discards" },
105adfc5217SJeff Kirsher 	{ STATS_OFFSET32(mac_filter_discard),
106adfc5217SJeff Kirsher 				4, STATS_FLAGS_PORT, "rx_filtered_packets" },
107adfc5217SJeff Kirsher 	{ STATS_OFFSET32(mf_tag_discard),
108adfc5217SJeff Kirsher 				4, STATS_FLAGS_PORT, "rx_mf_tag_discard" },
1090e898dd7SBarak Witkowski 	{ STATS_OFFSET32(pfc_frames_received_hi),
1100e898dd7SBarak Witkowski 				8, STATS_FLAGS_PORT, "pfc_frames_received" },
1110e898dd7SBarak Witkowski 	{ STATS_OFFSET32(pfc_frames_sent_hi),
1120e898dd7SBarak Witkowski 				8, STATS_FLAGS_PORT, "pfc_frames_sent" },
113adfc5217SJeff Kirsher 	{ STATS_OFFSET32(brb_drop_hi),
114adfc5217SJeff Kirsher 				8, STATS_FLAGS_PORT, "rx_brb_discard" },
115adfc5217SJeff Kirsher 	{ STATS_OFFSET32(brb_truncate_hi),
116adfc5217SJeff Kirsher 				8, STATS_FLAGS_PORT, "rx_brb_truncate" },
117adfc5217SJeff Kirsher 	{ STATS_OFFSET32(pause_frames_received_hi),
118adfc5217SJeff Kirsher 				8, STATS_FLAGS_PORT, "rx_pause_frames" },
119adfc5217SJeff Kirsher 	{ STATS_OFFSET32(rx_stat_maccontrolframesreceived_hi),
120adfc5217SJeff Kirsher 				8, STATS_FLAGS_PORT, "rx_mac_ctrl_frames" },
121adfc5217SJeff Kirsher 	{ STATS_OFFSET32(nig_timer_max),
122adfc5217SJeff Kirsher 			4, STATS_FLAGS_PORT, "rx_constant_pause_events" },
123adfc5217SJeff Kirsher /* 20 */{ STATS_OFFSET32(rx_err_discard_pkt),
124adfc5217SJeff Kirsher 				4, STATS_FLAGS_BOTH, "rx_phy_ip_err_discards"},
125adfc5217SJeff Kirsher 	{ STATS_OFFSET32(rx_skb_alloc_failed),
126adfc5217SJeff Kirsher 				4, STATS_FLAGS_BOTH, "rx_skb_alloc_discard" },
127adfc5217SJeff Kirsher 	{ STATS_OFFSET32(hw_csum_err),
128adfc5217SJeff Kirsher 				4, STATS_FLAGS_BOTH, "rx_csum_offload_errors" },
129adfc5217SJeff Kirsher 
130adfc5217SJeff Kirsher 	{ STATS_OFFSET32(total_bytes_transmitted_hi),
131adfc5217SJeff Kirsher 				8, STATS_FLAGS_BOTH, "tx_bytes" },
132adfc5217SJeff Kirsher 	{ STATS_OFFSET32(tx_stat_ifhcoutbadoctets_hi),
133adfc5217SJeff Kirsher 				8, STATS_FLAGS_PORT, "tx_error_bytes" },
134adfc5217SJeff Kirsher 	{ STATS_OFFSET32(total_unicast_packets_transmitted_hi),
135adfc5217SJeff Kirsher 				8, STATS_FLAGS_BOTH, "tx_ucast_packets" },
136adfc5217SJeff Kirsher 	{ STATS_OFFSET32(total_multicast_packets_transmitted_hi),
137adfc5217SJeff Kirsher 				8, STATS_FLAGS_BOTH, "tx_mcast_packets" },
138adfc5217SJeff Kirsher 	{ STATS_OFFSET32(total_broadcast_packets_transmitted_hi),
139adfc5217SJeff Kirsher 				8, STATS_FLAGS_BOTH, "tx_bcast_packets" },
140adfc5217SJeff Kirsher 	{ STATS_OFFSET32(tx_stat_dot3statsinternalmactransmiterrors_hi),
141adfc5217SJeff Kirsher 				8, STATS_FLAGS_PORT, "tx_mac_errors" },
142adfc5217SJeff Kirsher 	{ STATS_OFFSET32(rx_stat_dot3statscarriersenseerrors_hi),
143adfc5217SJeff Kirsher 				8, STATS_FLAGS_PORT, "tx_carrier_errors" },
144adfc5217SJeff Kirsher /* 30 */{ STATS_OFFSET32(tx_stat_dot3statssinglecollisionframes_hi),
145adfc5217SJeff Kirsher 				8, STATS_FLAGS_PORT, "tx_single_collisions" },
146adfc5217SJeff Kirsher 	{ STATS_OFFSET32(tx_stat_dot3statsmultiplecollisionframes_hi),
147adfc5217SJeff Kirsher 				8, STATS_FLAGS_PORT, "tx_multi_collisions" },
148adfc5217SJeff Kirsher 	{ STATS_OFFSET32(tx_stat_dot3statsdeferredtransmissions_hi),
149adfc5217SJeff Kirsher 				8, STATS_FLAGS_PORT, "tx_deferred" },
150adfc5217SJeff Kirsher 	{ STATS_OFFSET32(tx_stat_dot3statsexcessivecollisions_hi),
151adfc5217SJeff Kirsher 				8, STATS_FLAGS_PORT, "tx_excess_collisions" },
152adfc5217SJeff Kirsher 	{ STATS_OFFSET32(tx_stat_dot3statslatecollisions_hi),
153adfc5217SJeff Kirsher 				8, STATS_FLAGS_PORT, "tx_late_collisions" },
154adfc5217SJeff Kirsher 	{ STATS_OFFSET32(tx_stat_etherstatscollisions_hi),
155adfc5217SJeff Kirsher 				8, STATS_FLAGS_PORT, "tx_total_collisions" },
156adfc5217SJeff Kirsher 	{ STATS_OFFSET32(tx_stat_etherstatspkts64octets_hi),
157adfc5217SJeff Kirsher 				8, STATS_FLAGS_PORT, "tx_64_byte_packets" },
158adfc5217SJeff Kirsher 	{ STATS_OFFSET32(tx_stat_etherstatspkts65octetsto127octets_hi),
159adfc5217SJeff Kirsher 			8, STATS_FLAGS_PORT, "tx_65_to_127_byte_packets" },
160adfc5217SJeff Kirsher 	{ STATS_OFFSET32(tx_stat_etherstatspkts128octetsto255octets_hi),
161adfc5217SJeff Kirsher 			8, STATS_FLAGS_PORT, "tx_128_to_255_byte_packets" },
162adfc5217SJeff Kirsher 	{ STATS_OFFSET32(tx_stat_etherstatspkts256octetsto511octets_hi),
163adfc5217SJeff Kirsher 			8, STATS_FLAGS_PORT, "tx_256_to_511_byte_packets" },
164adfc5217SJeff Kirsher /* 40 */{ STATS_OFFSET32(tx_stat_etherstatspkts512octetsto1023octets_hi),
165adfc5217SJeff Kirsher 			8, STATS_FLAGS_PORT, "tx_512_to_1023_byte_packets" },
166adfc5217SJeff Kirsher 	{ STATS_OFFSET32(etherstatspkts1024octetsto1522octets_hi),
167adfc5217SJeff Kirsher 			8, STATS_FLAGS_PORT, "tx_1024_to_1522_byte_packets" },
168adfc5217SJeff Kirsher 	{ STATS_OFFSET32(etherstatspktsover1522octets_hi),
169adfc5217SJeff Kirsher 			8, STATS_FLAGS_PORT, "tx_1523_to_9022_byte_packets" },
170adfc5217SJeff Kirsher 	{ STATS_OFFSET32(pause_frames_sent_hi),
171adfc5217SJeff Kirsher 				8, STATS_FLAGS_PORT, "tx_pause_frames" },
172adfc5217SJeff Kirsher 	{ STATS_OFFSET32(total_tpa_aggregations_hi),
173adfc5217SJeff Kirsher 			8, STATS_FLAGS_FUNC, "tpa_aggregations" },
174adfc5217SJeff Kirsher 	{ STATS_OFFSET32(total_tpa_aggregated_frames_hi),
175adfc5217SJeff Kirsher 			8, STATS_FLAGS_FUNC, "tpa_aggregated_frames"},
176adfc5217SJeff Kirsher 	{ STATS_OFFSET32(total_tpa_bytes_hi),
1777a752993SAriel Elior 			8, STATS_FLAGS_FUNC, "tpa_bytes"},
1787a752993SAriel Elior 	{ STATS_OFFSET32(recoverable_error),
1797a752993SAriel Elior 			4, STATS_FLAGS_FUNC, "recoverable_errors" },
1807a752993SAriel Elior 	{ STATS_OFFSET32(unrecoverable_error),
1817a752993SAriel Elior 			4, STATS_FLAGS_FUNC, "unrecoverable_errors" },
182c96bdc0cSDmitry Kravkov 	{ STATS_OFFSET32(driver_filtered_tx_pkt),
183c96bdc0cSDmitry Kravkov 			4, STATS_FLAGS_FUNC, "driver_filtered_tx_pkt" },
184e9939c80SYuval Mintz 	{ STATS_OFFSET32(eee_tx_lpi),
185e9939c80SYuval Mintz 			4, STATS_FLAGS_PORT, "Tx LPI entry count"}
186adfc5217SJeff Kirsher };
187adfc5217SJeff Kirsher 
188adfc5217SJeff Kirsher #define BNX2X_NUM_STATS		ARRAY_SIZE(bnx2x_stats_arr)
18907ba6af4SMiriam Shitrit 
190adfc5217SJeff Kirsher static int bnx2x_get_port_type(struct bnx2x *bp)
191adfc5217SJeff Kirsher {
192adfc5217SJeff Kirsher 	int port_type;
193adfc5217SJeff Kirsher 	u32 phy_idx = bnx2x_get_cur_phy_idx(bp);
194adfc5217SJeff Kirsher 	switch (bp->link_params.phy[phy_idx].media_type) {
195dbef807eSYuval Mintz 	case ETH_PHY_SFPP_10G_FIBER:
196dbef807eSYuval Mintz 	case ETH_PHY_SFP_1G_FIBER:
197adfc5217SJeff Kirsher 	case ETH_PHY_XFP_FIBER:
198adfc5217SJeff Kirsher 	case ETH_PHY_KR:
199adfc5217SJeff Kirsher 	case ETH_PHY_CX4:
200adfc5217SJeff Kirsher 		port_type = PORT_FIBRE;
201adfc5217SJeff Kirsher 		break;
202adfc5217SJeff Kirsher 	case ETH_PHY_DA_TWINAX:
203adfc5217SJeff Kirsher 		port_type = PORT_DA;
204adfc5217SJeff Kirsher 		break;
205adfc5217SJeff Kirsher 	case ETH_PHY_BASE_T:
206adfc5217SJeff Kirsher 		port_type = PORT_TP;
207adfc5217SJeff Kirsher 		break;
208adfc5217SJeff Kirsher 	case ETH_PHY_NOT_PRESENT:
209adfc5217SJeff Kirsher 		port_type = PORT_NONE;
210adfc5217SJeff Kirsher 		break;
211adfc5217SJeff Kirsher 	case ETH_PHY_UNSPECIFIED:
212adfc5217SJeff Kirsher 	default:
213adfc5217SJeff Kirsher 		port_type = PORT_OTHER;
214adfc5217SJeff Kirsher 		break;
215adfc5217SJeff Kirsher 	}
216adfc5217SJeff Kirsher 	return port_type;
217adfc5217SJeff Kirsher }
218adfc5217SJeff Kirsher 
219adfc5217SJeff Kirsher static int bnx2x_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
220adfc5217SJeff Kirsher {
221adfc5217SJeff Kirsher 	struct bnx2x *bp = netdev_priv(dev);
222adfc5217SJeff Kirsher 	int cfg_idx = bnx2x_get_link_cfg_idx(bp);
223adfc5217SJeff Kirsher 
224adfc5217SJeff Kirsher 	/* Dual Media boards present all available port types */
225adfc5217SJeff Kirsher 	cmd->supported = bp->port.supported[cfg_idx] |
226adfc5217SJeff Kirsher 		(bp->port.supported[cfg_idx ^ 1] &
227adfc5217SJeff Kirsher 		 (SUPPORTED_TP | SUPPORTED_FIBRE));
228adfc5217SJeff Kirsher 	cmd->advertising = bp->port.advertising[cfg_idx];
229dbef807eSYuval Mintz 	if (bp->link_params.phy[bnx2x_get_cur_phy_idx(bp)].media_type ==
230dbef807eSYuval Mintz 	    ETH_PHY_SFP_1G_FIBER) {
231dbef807eSYuval Mintz 		cmd->supported &= ~(SUPPORTED_10000baseT_Full);
232dbef807eSYuval Mintz 		cmd->advertising &= ~(ADVERTISED_10000baseT_Full);
233dbef807eSYuval Mintz 	}
234adfc5217SJeff Kirsher 
23559694f00SYuval Mintz 	if ((bp->state == BNX2X_STATE_OPEN) && bp->link_vars.link_up &&
23659694f00SYuval Mintz 	    !(bp->flags & MF_FUNC_DIS)) {
237adfc5217SJeff Kirsher 		cmd->duplex = bp->link_vars.duplex;
238adfc5217SJeff Kirsher 
23938298461SYuval Mintz 		if (IS_MF(bp) && !BP_NOMCP(bp))
240adfc5217SJeff Kirsher 			ethtool_cmd_speed_set(cmd, bnx2x_get_mf_speed(bp));
24159694f00SYuval Mintz 		else
24259694f00SYuval Mintz 			ethtool_cmd_speed_set(cmd, bp->link_vars.line_speed);
24338298461SYuval Mintz 	} else {
24438298461SYuval Mintz 		cmd->duplex = DUPLEX_UNKNOWN;
24538298461SYuval Mintz 		ethtool_cmd_speed_set(cmd, SPEED_UNKNOWN);
24638298461SYuval Mintz 	}
247adfc5217SJeff Kirsher 
248adfc5217SJeff Kirsher 	cmd->port = bnx2x_get_port_type(bp);
249adfc5217SJeff Kirsher 
250adfc5217SJeff Kirsher 	cmd->phy_address = bp->mdio.prtad;
251adfc5217SJeff Kirsher 	cmd->transceiver = XCVR_INTERNAL;
252adfc5217SJeff Kirsher 
253adfc5217SJeff Kirsher 	if (bp->link_params.req_line_speed[cfg_idx] == SPEED_AUTO_NEG)
254adfc5217SJeff Kirsher 		cmd->autoneg = AUTONEG_ENABLE;
255adfc5217SJeff Kirsher 	else
256adfc5217SJeff Kirsher 		cmd->autoneg = AUTONEG_DISABLE;
257adfc5217SJeff Kirsher 
2589e7e8399SMintz Yuval 	/* Publish LP advertised speeds and FC */
2599e7e8399SMintz Yuval 	if (bp->link_vars.link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) {
2609e7e8399SMintz Yuval 		u32 status = bp->link_vars.link_status;
2619e7e8399SMintz Yuval 
2629e7e8399SMintz Yuval 		cmd->lp_advertising |= ADVERTISED_Autoneg;
2639e7e8399SMintz Yuval 		if (status & LINK_STATUS_LINK_PARTNER_SYMMETRIC_PAUSE)
2649e7e8399SMintz Yuval 			cmd->lp_advertising |= ADVERTISED_Pause;
2659e7e8399SMintz Yuval 		if (status & LINK_STATUS_LINK_PARTNER_ASYMMETRIC_PAUSE)
2669e7e8399SMintz Yuval 			cmd->lp_advertising |= ADVERTISED_Asym_Pause;
2679e7e8399SMintz Yuval 
2689e7e8399SMintz Yuval 		if (status & LINK_STATUS_LINK_PARTNER_10THD_CAPABLE)
2699e7e8399SMintz Yuval 			cmd->lp_advertising |= ADVERTISED_10baseT_Half;
2709e7e8399SMintz Yuval 		if (status & LINK_STATUS_LINK_PARTNER_10TFD_CAPABLE)
2719e7e8399SMintz Yuval 			cmd->lp_advertising |= ADVERTISED_10baseT_Full;
2729e7e8399SMintz Yuval 		if (status & LINK_STATUS_LINK_PARTNER_100TXHD_CAPABLE)
2739e7e8399SMintz Yuval 			cmd->lp_advertising |= ADVERTISED_100baseT_Half;
2749e7e8399SMintz Yuval 		if (status & LINK_STATUS_LINK_PARTNER_100TXFD_CAPABLE)
2759e7e8399SMintz Yuval 			cmd->lp_advertising |= ADVERTISED_100baseT_Full;
2769e7e8399SMintz Yuval 		if (status & LINK_STATUS_LINK_PARTNER_1000THD_CAPABLE)
2779e7e8399SMintz Yuval 			cmd->lp_advertising |= ADVERTISED_1000baseT_Half;
2789e7e8399SMintz Yuval 		if (status & LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE)
2799e7e8399SMintz Yuval 			cmd->lp_advertising |= ADVERTISED_1000baseT_Full;
2809e7e8399SMintz Yuval 		if (status & LINK_STATUS_LINK_PARTNER_2500XFD_CAPABLE)
2819e7e8399SMintz Yuval 			cmd->lp_advertising |= ADVERTISED_2500baseX_Full;
2829e7e8399SMintz Yuval 		if (status & LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE)
2839e7e8399SMintz Yuval 			cmd->lp_advertising |= ADVERTISED_10000baseT_Full;
284be94bea7SYaniv Rosner 		if (status & LINK_STATUS_LINK_PARTNER_20GXFD_CAPABLE)
285be94bea7SYaniv Rosner 			cmd->lp_advertising |= ADVERTISED_20000baseKR2_Full;
2869e7e8399SMintz Yuval 	}
2879e7e8399SMintz Yuval 
288adfc5217SJeff Kirsher 	cmd->maxtxpkt = 0;
289adfc5217SJeff Kirsher 	cmd->maxrxpkt = 0;
290adfc5217SJeff Kirsher 
29151c1a580SMerav Sicron 	DP(BNX2X_MSG_ETHTOOL, "ethtool_cmd: cmd %d\n"
292f1deab50SJoe Perches 	   "  supported 0x%x  advertising 0x%x  speed %u\n"
293f1deab50SJoe Perches 	   "  duplex %d  port %d  phy_address %d  transceiver %d\n"
294f1deab50SJoe Perches 	   "  autoneg %d  maxtxpkt %d  maxrxpkt %d\n",
295adfc5217SJeff Kirsher 	   cmd->cmd, cmd->supported, cmd->advertising,
296adfc5217SJeff Kirsher 	   ethtool_cmd_speed(cmd),
297adfc5217SJeff Kirsher 	   cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver,
298adfc5217SJeff Kirsher 	   cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt);
299adfc5217SJeff Kirsher 
300adfc5217SJeff Kirsher 	return 0;
301adfc5217SJeff Kirsher }
302adfc5217SJeff Kirsher 
303adfc5217SJeff Kirsher static int bnx2x_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
304adfc5217SJeff Kirsher {
305adfc5217SJeff Kirsher 	struct bnx2x *bp = netdev_priv(dev);
306adfc5217SJeff Kirsher 	u32 advertising, cfg_idx, old_multi_phy_config, new_multi_phy_config;
307dbef807eSYuval Mintz 	u32 speed, phy_idx;
308adfc5217SJeff Kirsher 
309adfc5217SJeff Kirsher 	if (IS_MF_SD(bp))
310adfc5217SJeff Kirsher 		return 0;
311adfc5217SJeff Kirsher 
31251c1a580SMerav Sicron 	DP(BNX2X_MSG_ETHTOOL, "ethtool_cmd: cmd %d\n"
313adfc5217SJeff Kirsher 	   "  supported 0x%x  advertising 0x%x  speed %u\n"
314adfc5217SJeff Kirsher 	   "  duplex %d  port %d  phy_address %d  transceiver %d\n"
315adfc5217SJeff Kirsher 	   "  autoneg %d  maxtxpkt %d  maxrxpkt %d\n",
316adfc5217SJeff Kirsher 	   cmd->cmd, cmd->supported, cmd->advertising,
317adfc5217SJeff Kirsher 	   ethtool_cmd_speed(cmd),
318adfc5217SJeff Kirsher 	   cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver,
319adfc5217SJeff Kirsher 	   cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt);
320adfc5217SJeff Kirsher 
321adfc5217SJeff Kirsher 	speed = ethtool_cmd_speed(cmd);
322adfc5217SJeff Kirsher 
32338298461SYuval Mintz 	/* If recieved a request for an unknown duplex, assume full*/
32438298461SYuval Mintz 	if (cmd->duplex == DUPLEX_UNKNOWN)
32538298461SYuval Mintz 		cmd->duplex = DUPLEX_FULL;
32638298461SYuval Mintz 
327adfc5217SJeff Kirsher 	if (IS_MF_SI(bp)) {
328adfc5217SJeff Kirsher 		u32 part;
329adfc5217SJeff Kirsher 		u32 line_speed = bp->link_vars.line_speed;
330adfc5217SJeff Kirsher 
331adfc5217SJeff Kirsher 		/* use 10G if no link detected */
332adfc5217SJeff Kirsher 		if (!line_speed)
333adfc5217SJeff Kirsher 			line_speed = 10000;
334adfc5217SJeff Kirsher 
335adfc5217SJeff Kirsher 		if (bp->common.bc_ver < REQ_BC_VER_4_SET_MF_BW) {
33651c1a580SMerav Sicron 			DP(BNX2X_MSG_ETHTOOL,
33751c1a580SMerav Sicron 			   "To set speed BC %X or higher is required, please upgrade BC\n",
338adfc5217SJeff Kirsher 			   REQ_BC_VER_4_SET_MF_BW);
339adfc5217SJeff Kirsher 			return -EINVAL;
340adfc5217SJeff Kirsher 		}
341adfc5217SJeff Kirsher 
342adfc5217SJeff Kirsher 		part = (speed * 100) / line_speed;
343adfc5217SJeff Kirsher 
344adfc5217SJeff Kirsher 		if (line_speed < speed || !part) {
34551c1a580SMerav Sicron 			DP(BNX2X_MSG_ETHTOOL,
34651c1a580SMerav Sicron 			   "Speed setting should be in a range from 1%% to 100%% of actual line speed\n");
347adfc5217SJeff Kirsher 			return -EINVAL;
348adfc5217SJeff Kirsher 		}
349adfc5217SJeff Kirsher 
350adfc5217SJeff Kirsher 		if (bp->state != BNX2X_STATE_OPEN)
351adfc5217SJeff Kirsher 			/* store value for following "load" */
352adfc5217SJeff Kirsher 			bp->pending_max = part;
353adfc5217SJeff Kirsher 		else
354adfc5217SJeff Kirsher 			bnx2x_update_max_mf_config(bp, part);
355adfc5217SJeff Kirsher 
356adfc5217SJeff Kirsher 		return 0;
357adfc5217SJeff Kirsher 	}
358adfc5217SJeff Kirsher 
359adfc5217SJeff Kirsher 	cfg_idx = bnx2x_get_link_cfg_idx(bp);
360adfc5217SJeff Kirsher 	old_multi_phy_config = bp->link_params.multi_phy_config;
361adfc5217SJeff Kirsher 	switch (cmd->port) {
362adfc5217SJeff Kirsher 	case PORT_TP:
363adfc5217SJeff Kirsher 		if (bp->port.supported[cfg_idx] & SUPPORTED_TP)
364adfc5217SJeff Kirsher 			break; /* no port change */
365adfc5217SJeff Kirsher 
366adfc5217SJeff Kirsher 		if (!(bp->port.supported[0] & SUPPORTED_TP ||
367adfc5217SJeff Kirsher 		      bp->port.supported[1] & SUPPORTED_TP)) {
36851c1a580SMerav Sicron 			DP(BNX2X_MSG_ETHTOOL, "Unsupported port type\n");
369adfc5217SJeff Kirsher 			return -EINVAL;
370adfc5217SJeff Kirsher 		}
371adfc5217SJeff Kirsher 		bp->link_params.multi_phy_config &=
372adfc5217SJeff Kirsher 			~PORT_HW_CFG_PHY_SELECTION_MASK;
373adfc5217SJeff Kirsher 		if (bp->link_params.multi_phy_config &
374adfc5217SJeff Kirsher 		    PORT_HW_CFG_PHY_SWAPPED_ENABLED)
375adfc5217SJeff Kirsher 			bp->link_params.multi_phy_config |=
376adfc5217SJeff Kirsher 			PORT_HW_CFG_PHY_SELECTION_SECOND_PHY;
377adfc5217SJeff Kirsher 		else
378adfc5217SJeff Kirsher 			bp->link_params.multi_phy_config |=
379adfc5217SJeff Kirsher 			PORT_HW_CFG_PHY_SELECTION_FIRST_PHY;
380adfc5217SJeff Kirsher 		break;
381adfc5217SJeff Kirsher 	case PORT_FIBRE:
382bfdb5823SYaniv Rosner 	case PORT_DA:
383adfc5217SJeff Kirsher 		if (bp->port.supported[cfg_idx] & SUPPORTED_FIBRE)
384adfc5217SJeff Kirsher 			break; /* no port change */
385adfc5217SJeff Kirsher 
386adfc5217SJeff Kirsher 		if (!(bp->port.supported[0] & SUPPORTED_FIBRE ||
387adfc5217SJeff Kirsher 		      bp->port.supported[1] & SUPPORTED_FIBRE)) {
38851c1a580SMerav Sicron 			DP(BNX2X_MSG_ETHTOOL, "Unsupported port type\n");
389adfc5217SJeff Kirsher 			return -EINVAL;
390adfc5217SJeff Kirsher 		}
391adfc5217SJeff Kirsher 		bp->link_params.multi_phy_config &=
392adfc5217SJeff Kirsher 			~PORT_HW_CFG_PHY_SELECTION_MASK;
393adfc5217SJeff Kirsher 		if (bp->link_params.multi_phy_config &
394adfc5217SJeff Kirsher 		    PORT_HW_CFG_PHY_SWAPPED_ENABLED)
395adfc5217SJeff Kirsher 			bp->link_params.multi_phy_config |=
396adfc5217SJeff Kirsher 			PORT_HW_CFG_PHY_SELECTION_FIRST_PHY;
397adfc5217SJeff Kirsher 		else
398adfc5217SJeff Kirsher 			bp->link_params.multi_phy_config |=
399adfc5217SJeff Kirsher 			PORT_HW_CFG_PHY_SELECTION_SECOND_PHY;
400adfc5217SJeff Kirsher 		break;
401adfc5217SJeff Kirsher 	default:
40251c1a580SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL, "Unsupported port type\n");
403adfc5217SJeff Kirsher 		return -EINVAL;
404adfc5217SJeff Kirsher 	}
4052de67439SYuval Mintz 	/* Save new config in case command complete successfully */
406adfc5217SJeff Kirsher 	new_multi_phy_config = bp->link_params.multi_phy_config;
407adfc5217SJeff Kirsher 	/* Get the new cfg_idx */
408adfc5217SJeff Kirsher 	cfg_idx = bnx2x_get_link_cfg_idx(bp);
409adfc5217SJeff Kirsher 	/* Restore old config in case command failed */
410adfc5217SJeff Kirsher 	bp->link_params.multi_phy_config = old_multi_phy_config;
41151c1a580SMerav Sicron 	DP(BNX2X_MSG_ETHTOOL, "cfg_idx = %x\n", cfg_idx);
412adfc5217SJeff Kirsher 
413adfc5217SJeff Kirsher 	if (cmd->autoneg == AUTONEG_ENABLE) {
41475318327SYaniv Rosner 		u32 an_supported_speed = bp->port.supported[cfg_idx];
41575318327SYaniv Rosner 		if (bp->link_params.phy[EXT_PHY1].type ==
41675318327SYaniv Rosner 		    PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
41775318327SYaniv Rosner 			an_supported_speed |= (SUPPORTED_100baseT_Half |
41875318327SYaniv Rosner 					       SUPPORTED_100baseT_Full);
419adfc5217SJeff Kirsher 		if (!(bp->port.supported[cfg_idx] & SUPPORTED_Autoneg)) {
42051c1a580SMerav Sicron 			DP(BNX2X_MSG_ETHTOOL, "Autoneg not supported\n");
421adfc5217SJeff Kirsher 			return -EINVAL;
422adfc5217SJeff Kirsher 		}
423adfc5217SJeff Kirsher 
424adfc5217SJeff Kirsher 		/* advertise the requested speed and duplex if supported */
42575318327SYaniv Rosner 		if (cmd->advertising & ~an_supported_speed) {
42651c1a580SMerav Sicron 			DP(BNX2X_MSG_ETHTOOL,
42751c1a580SMerav Sicron 			   "Advertisement parameters are not supported\n");
4288decf868SDavid S. Miller 			return -EINVAL;
4298decf868SDavid S. Miller 		}
430adfc5217SJeff Kirsher 
431adfc5217SJeff Kirsher 		bp->link_params.req_line_speed[cfg_idx] = SPEED_AUTO_NEG;
4328decf868SDavid S. Miller 		bp->link_params.req_duplex[cfg_idx] = cmd->duplex;
4338decf868SDavid S. Miller 		bp->port.advertising[cfg_idx] = (ADVERTISED_Autoneg |
434adfc5217SJeff Kirsher 					 cmd->advertising);
4358decf868SDavid S. Miller 		if (cmd->advertising) {
436adfc5217SJeff Kirsher 
4378decf868SDavid S. Miller 			bp->link_params.speed_cap_mask[cfg_idx] = 0;
4388decf868SDavid S. Miller 			if (cmd->advertising & ADVERTISED_10baseT_Half) {
4398decf868SDavid S. Miller 				bp->link_params.speed_cap_mask[cfg_idx] |=
4408decf868SDavid S. Miller 				PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF;
4418decf868SDavid S. Miller 			}
4428decf868SDavid S. Miller 			if (cmd->advertising & ADVERTISED_10baseT_Full)
4438decf868SDavid S. Miller 				bp->link_params.speed_cap_mask[cfg_idx] |=
4448decf868SDavid S. Miller 				PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL;
4458decf868SDavid S. Miller 
4468decf868SDavid S. Miller 			if (cmd->advertising & ADVERTISED_100baseT_Full)
4478decf868SDavid S. Miller 				bp->link_params.speed_cap_mask[cfg_idx] |=
4488decf868SDavid S. Miller 				PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL;
4498decf868SDavid S. Miller 
4508decf868SDavid S. Miller 			if (cmd->advertising & ADVERTISED_100baseT_Half) {
4518decf868SDavid S. Miller 				bp->link_params.speed_cap_mask[cfg_idx] |=
4528decf868SDavid S. Miller 				     PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF;
4538decf868SDavid S. Miller 			}
4548decf868SDavid S. Miller 			if (cmd->advertising & ADVERTISED_1000baseT_Half) {
4558decf868SDavid S. Miller 				bp->link_params.speed_cap_mask[cfg_idx] |=
4568decf868SDavid S. Miller 					PORT_HW_CFG_SPEED_CAPABILITY_D0_1G;
4578decf868SDavid S. Miller 			}
4588decf868SDavid S. Miller 			if (cmd->advertising & (ADVERTISED_1000baseT_Full |
4598decf868SDavid S. Miller 						ADVERTISED_1000baseKX_Full))
4608decf868SDavid S. Miller 				bp->link_params.speed_cap_mask[cfg_idx] |=
4618decf868SDavid S. Miller 					PORT_HW_CFG_SPEED_CAPABILITY_D0_1G;
4628decf868SDavid S. Miller 
4638decf868SDavid S. Miller 			if (cmd->advertising & (ADVERTISED_10000baseT_Full |
4648decf868SDavid S. Miller 						ADVERTISED_10000baseKX4_Full |
4658decf868SDavid S. Miller 						ADVERTISED_10000baseKR_Full))
4668decf868SDavid S. Miller 				bp->link_params.speed_cap_mask[cfg_idx] |=
4678decf868SDavid S. Miller 					PORT_HW_CFG_SPEED_CAPABILITY_D0_10G;
468be94bea7SYaniv Rosner 
469be94bea7SYaniv Rosner 			if (cmd->advertising & ADVERTISED_20000baseKR2_Full)
470be94bea7SYaniv Rosner 				bp->link_params.speed_cap_mask[cfg_idx] |=
471be94bea7SYaniv Rosner 					PORT_HW_CFG_SPEED_CAPABILITY_D0_20G;
4728decf868SDavid S. Miller 		}
473adfc5217SJeff Kirsher 	} else { /* forced speed */
474adfc5217SJeff Kirsher 		/* advertise the requested speed and duplex if supported */
475adfc5217SJeff Kirsher 		switch (speed) {
476adfc5217SJeff Kirsher 		case SPEED_10:
477adfc5217SJeff Kirsher 			if (cmd->duplex == DUPLEX_FULL) {
478adfc5217SJeff Kirsher 				if (!(bp->port.supported[cfg_idx] &
479adfc5217SJeff Kirsher 				      SUPPORTED_10baseT_Full)) {
48051c1a580SMerav Sicron 					DP(BNX2X_MSG_ETHTOOL,
481adfc5217SJeff Kirsher 					   "10M full not supported\n");
482adfc5217SJeff Kirsher 					return -EINVAL;
483adfc5217SJeff Kirsher 				}
484adfc5217SJeff Kirsher 
485adfc5217SJeff Kirsher 				advertising = (ADVERTISED_10baseT_Full |
486adfc5217SJeff Kirsher 					       ADVERTISED_TP);
487adfc5217SJeff Kirsher 			} else {
488adfc5217SJeff Kirsher 				if (!(bp->port.supported[cfg_idx] &
489adfc5217SJeff Kirsher 				      SUPPORTED_10baseT_Half)) {
49051c1a580SMerav Sicron 					DP(BNX2X_MSG_ETHTOOL,
491adfc5217SJeff Kirsher 					   "10M half not supported\n");
492adfc5217SJeff Kirsher 					return -EINVAL;
493adfc5217SJeff Kirsher 				}
494adfc5217SJeff Kirsher 
495adfc5217SJeff Kirsher 				advertising = (ADVERTISED_10baseT_Half |
496adfc5217SJeff Kirsher 					       ADVERTISED_TP);
497adfc5217SJeff Kirsher 			}
498adfc5217SJeff Kirsher 			break;
499adfc5217SJeff Kirsher 
500adfc5217SJeff Kirsher 		case SPEED_100:
501adfc5217SJeff Kirsher 			if (cmd->duplex == DUPLEX_FULL) {
502adfc5217SJeff Kirsher 				if (!(bp->port.supported[cfg_idx] &
503adfc5217SJeff Kirsher 						SUPPORTED_100baseT_Full)) {
50451c1a580SMerav Sicron 					DP(BNX2X_MSG_ETHTOOL,
505adfc5217SJeff Kirsher 					   "100M full not supported\n");
506adfc5217SJeff Kirsher 					return -EINVAL;
507adfc5217SJeff Kirsher 				}
508adfc5217SJeff Kirsher 
509adfc5217SJeff Kirsher 				advertising = (ADVERTISED_100baseT_Full |
510adfc5217SJeff Kirsher 					       ADVERTISED_TP);
511adfc5217SJeff Kirsher 			} else {
512adfc5217SJeff Kirsher 				if (!(bp->port.supported[cfg_idx] &
513adfc5217SJeff Kirsher 						SUPPORTED_100baseT_Half)) {
51451c1a580SMerav Sicron 					DP(BNX2X_MSG_ETHTOOL,
515adfc5217SJeff Kirsher 					   "100M half not supported\n");
516adfc5217SJeff Kirsher 					return -EINVAL;
517adfc5217SJeff Kirsher 				}
518adfc5217SJeff Kirsher 
519adfc5217SJeff Kirsher 				advertising = (ADVERTISED_100baseT_Half |
520adfc5217SJeff Kirsher 					       ADVERTISED_TP);
521adfc5217SJeff Kirsher 			}
522adfc5217SJeff Kirsher 			break;
523adfc5217SJeff Kirsher 
524adfc5217SJeff Kirsher 		case SPEED_1000:
525adfc5217SJeff Kirsher 			if (cmd->duplex != DUPLEX_FULL) {
52651c1a580SMerav Sicron 				DP(BNX2X_MSG_ETHTOOL,
52751c1a580SMerav Sicron 				   "1G half not supported\n");
528adfc5217SJeff Kirsher 				return -EINVAL;
529adfc5217SJeff Kirsher 			}
530adfc5217SJeff Kirsher 
531adfc5217SJeff Kirsher 			if (!(bp->port.supported[cfg_idx] &
532adfc5217SJeff Kirsher 			      SUPPORTED_1000baseT_Full)) {
53351c1a580SMerav Sicron 				DP(BNX2X_MSG_ETHTOOL,
53451c1a580SMerav Sicron 				   "1G full not supported\n");
535adfc5217SJeff Kirsher 				return -EINVAL;
536adfc5217SJeff Kirsher 			}
537adfc5217SJeff Kirsher 
538adfc5217SJeff Kirsher 			advertising = (ADVERTISED_1000baseT_Full |
539adfc5217SJeff Kirsher 				       ADVERTISED_TP);
540adfc5217SJeff Kirsher 			break;
541adfc5217SJeff Kirsher 
542adfc5217SJeff Kirsher 		case SPEED_2500:
543adfc5217SJeff Kirsher 			if (cmd->duplex != DUPLEX_FULL) {
54451c1a580SMerav Sicron 				DP(BNX2X_MSG_ETHTOOL,
545adfc5217SJeff Kirsher 				   "2.5G half not supported\n");
546adfc5217SJeff Kirsher 				return -EINVAL;
547adfc5217SJeff Kirsher 			}
548adfc5217SJeff Kirsher 
549adfc5217SJeff Kirsher 			if (!(bp->port.supported[cfg_idx]
550adfc5217SJeff Kirsher 			      & SUPPORTED_2500baseX_Full)) {
55151c1a580SMerav Sicron 				DP(BNX2X_MSG_ETHTOOL,
552adfc5217SJeff Kirsher 				   "2.5G full not supported\n");
553adfc5217SJeff Kirsher 				return -EINVAL;
554adfc5217SJeff Kirsher 			}
555adfc5217SJeff Kirsher 
556adfc5217SJeff Kirsher 			advertising = (ADVERTISED_2500baseX_Full |
557adfc5217SJeff Kirsher 				       ADVERTISED_TP);
558adfc5217SJeff Kirsher 			break;
559adfc5217SJeff Kirsher 
560adfc5217SJeff Kirsher 		case SPEED_10000:
561adfc5217SJeff Kirsher 			if (cmd->duplex != DUPLEX_FULL) {
56251c1a580SMerav Sicron 				DP(BNX2X_MSG_ETHTOOL,
56351c1a580SMerav Sicron 				   "10G half not supported\n");
564adfc5217SJeff Kirsher 				return -EINVAL;
565adfc5217SJeff Kirsher 			}
566dbef807eSYuval Mintz 			phy_idx = bnx2x_get_cur_phy_idx(bp);
567adfc5217SJeff Kirsher 			if (!(bp->port.supported[cfg_idx]
568dbef807eSYuval Mintz 			      & SUPPORTED_10000baseT_Full) ||
569dbef807eSYuval Mintz 			    (bp->link_params.phy[phy_idx].media_type ==
570dbef807eSYuval Mintz 			     ETH_PHY_SFP_1G_FIBER)) {
57151c1a580SMerav Sicron 				DP(BNX2X_MSG_ETHTOOL,
57251c1a580SMerav Sicron 				   "10G full not supported\n");
573adfc5217SJeff Kirsher 				return -EINVAL;
574adfc5217SJeff Kirsher 			}
575adfc5217SJeff Kirsher 
576adfc5217SJeff Kirsher 			advertising = (ADVERTISED_10000baseT_Full |
577adfc5217SJeff Kirsher 				       ADVERTISED_FIBRE);
578adfc5217SJeff Kirsher 			break;
579adfc5217SJeff Kirsher 
580adfc5217SJeff Kirsher 		default:
58151c1a580SMerav Sicron 			DP(BNX2X_MSG_ETHTOOL, "Unsupported speed %u\n", speed);
582adfc5217SJeff Kirsher 			return -EINVAL;
583adfc5217SJeff Kirsher 		}
584adfc5217SJeff Kirsher 
585adfc5217SJeff Kirsher 		bp->link_params.req_line_speed[cfg_idx] = speed;
586adfc5217SJeff Kirsher 		bp->link_params.req_duplex[cfg_idx] = cmd->duplex;
587adfc5217SJeff Kirsher 		bp->port.advertising[cfg_idx] = advertising;
588adfc5217SJeff Kirsher 	}
589adfc5217SJeff Kirsher 
59051c1a580SMerav Sicron 	DP(BNX2X_MSG_ETHTOOL, "req_line_speed %d\n"
591f1deab50SJoe Perches 	   "  req_duplex %d  advertising 0x%x\n",
592adfc5217SJeff Kirsher 	   bp->link_params.req_line_speed[cfg_idx],
593adfc5217SJeff Kirsher 	   bp->link_params.req_duplex[cfg_idx],
594adfc5217SJeff Kirsher 	   bp->port.advertising[cfg_idx]);
595adfc5217SJeff Kirsher 
596adfc5217SJeff Kirsher 	/* Set new config */
597adfc5217SJeff Kirsher 	bp->link_params.multi_phy_config = new_multi_phy_config;
598adfc5217SJeff Kirsher 	if (netif_running(dev)) {
599adfc5217SJeff Kirsher 		bnx2x_stats_handle(bp, STATS_EVENT_STOP);
600adfc5217SJeff Kirsher 		bnx2x_link_set(bp);
601adfc5217SJeff Kirsher 	}
602adfc5217SJeff Kirsher 
603adfc5217SJeff Kirsher 	return 0;
604adfc5217SJeff Kirsher }
605adfc5217SJeff Kirsher 
60607ba6af4SMiriam Shitrit #define DUMP_ALL_PRESETS		0x1FFF
60707ba6af4SMiriam Shitrit #define DUMP_MAX_PRESETS		13
608adfc5217SJeff Kirsher 
60907ba6af4SMiriam Shitrit static int __bnx2x_get_preset_regs_len(struct bnx2x *bp, u32 preset)
610adfc5217SJeff Kirsher {
611adfc5217SJeff Kirsher 	if (CHIP_IS_E1(bp))
61207ba6af4SMiriam Shitrit 		return dump_num_registers[0][preset-1];
613adfc5217SJeff Kirsher 	else if (CHIP_IS_E1H(bp))
61407ba6af4SMiriam Shitrit 		return dump_num_registers[1][preset-1];
615adfc5217SJeff Kirsher 	else if (CHIP_IS_E2(bp))
61607ba6af4SMiriam Shitrit 		return dump_num_registers[2][preset-1];
617adfc5217SJeff Kirsher 	else if (CHIP_IS_E3A0(bp))
61807ba6af4SMiriam Shitrit 		return dump_num_registers[3][preset-1];
619adfc5217SJeff Kirsher 	else if (CHIP_IS_E3B0(bp))
62007ba6af4SMiriam Shitrit 		return dump_num_registers[4][preset-1];
621adfc5217SJeff Kirsher 	else
62207ba6af4SMiriam Shitrit 		return 0;
623adfc5217SJeff Kirsher }
624adfc5217SJeff Kirsher 
62507ba6af4SMiriam Shitrit static int __bnx2x_get_regs_len(struct bnx2x *bp)
62607ba6af4SMiriam Shitrit {
62707ba6af4SMiriam Shitrit 	u32 preset_idx;
62807ba6af4SMiriam Shitrit 	int regdump_len = 0;
62907ba6af4SMiriam Shitrit 
63007ba6af4SMiriam Shitrit 	/* Calculate the total preset regs length */
63107ba6af4SMiriam Shitrit 	for (preset_idx = 1; preset_idx <= DUMP_MAX_PRESETS; preset_idx++)
63207ba6af4SMiriam Shitrit 		regdump_len += __bnx2x_get_preset_regs_len(bp, preset_idx);
63307ba6af4SMiriam Shitrit 
63407ba6af4SMiriam Shitrit 	return regdump_len;
63507ba6af4SMiriam Shitrit }
63607ba6af4SMiriam Shitrit 
63707ba6af4SMiriam Shitrit static int bnx2x_get_regs_len(struct net_device *dev)
63807ba6af4SMiriam Shitrit {
63907ba6af4SMiriam Shitrit 	struct bnx2x *bp = netdev_priv(dev);
64007ba6af4SMiriam Shitrit 	int regdump_len = 0;
64107ba6af4SMiriam Shitrit 
64207ba6af4SMiriam Shitrit 	regdump_len = __bnx2x_get_regs_len(bp);
64307ba6af4SMiriam Shitrit 	regdump_len *= 4;
64407ba6af4SMiriam Shitrit 	regdump_len += sizeof(struct dump_header);
64507ba6af4SMiriam Shitrit 
64607ba6af4SMiriam Shitrit 	return regdump_len;
64707ba6af4SMiriam Shitrit }
64807ba6af4SMiriam Shitrit 
64907ba6af4SMiriam Shitrit #define IS_E1_REG(chips)	((chips & DUMP_CHIP_E1) == DUMP_CHIP_E1)
65007ba6af4SMiriam Shitrit #define IS_E1H_REG(chips)	((chips & DUMP_CHIP_E1H) == DUMP_CHIP_E1H)
65107ba6af4SMiriam Shitrit #define IS_E2_REG(chips)	((chips & DUMP_CHIP_E2) == DUMP_CHIP_E2)
65207ba6af4SMiriam Shitrit #define IS_E3A0_REG(chips)	((chips & DUMP_CHIP_E3A0) == DUMP_CHIP_E3A0)
65307ba6af4SMiriam Shitrit #define IS_E3B0_REG(chips)	((chips & DUMP_CHIP_E3B0) == DUMP_CHIP_E3B0)
65407ba6af4SMiriam Shitrit 
65507ba6af4SMiriam Shitrit #define IS_REG_IN_PRESET(presets, idx)  \
65607ba6af4SMiriam Shitrit 		((presets & (1 << (idx-1))) == (1 << (idx-1)))
65707ba6af4SMiriam Shitrit 
658adfc5217SJeff Kirsher /******* Paged registers info selectors ********/
6591191cb83SEric Dumazet static const u32 *__bnx2x_get_page_addr_ar(struct bnx2x *bp)
660adfc5217SJeff Kirsher {
661adfc5217SJeff Kirsher 	if (CHIP_IS_E2(bp))
662adfc5217SJeff Kirsher 		return page_vals_e2;
663adfc5217SJeff Kirsher 	else if (CHIP_IS_E3(bp))
664adfc5217SJeff Kirsher 		return page_vals_e3;
665adfc5217SJeff Kirsher 	else
666adfc5217SJeff Kirsher 		return NULL;
667adfc5217SJeff Kirsher }
668adfc5217SJeff Kirsher 
6691191cb83SEric Dumazet static u32 __bnx2x_get_page_reg_num(struct bnx2x *bp)
670adfc5217SJeff Kirsher {
671adfc5217SJeff Kirsher 	if (CHIP_IS_E2(bp))
672adfc5217SJeff Kirsher 		return PAGE_MODE_VALUES_E2;
673adfc5217SJeff Kirsher 	else if (CHIP_IS_E3(bp))
674adfc5217SJeff Kirsher 		return PAGE_MODE_VALUES_E3;
675adfc5217SJeff Kirsher 	else
676adfc5217SJeff Kirsher 		return 0;
677adfc5217SJeff Kirsher }
678adfc5217SJeff Kirsher 
6791191cb83SEric Dumazet static const u32 *__bnx2x_get_page_write_ar(struct bnx2x *bp)
680adfc5217SJeff Kirsher {
681adfc5217SJeff Kirsher 	if (CHIP_IS_E2(bp))
682adfc5217SJeff Kirsher 		return page_write_regs_e2;
683adfc5217SJeff Kirsher 	else if (CHIP_IS_E3(bp))
684adfc5217SJeff Kirsher 		return page_write_regs_e3;
685adfc5217SJeff Kirsher 	else
686adfc5217SJeff Kirsher 		return NULL;
687adfc5217SJeff Kirsher }
688adfc5217SJeff Kirsher 
6891191cb83SEric Dumazet static u32 __bnx2x_get_page_write_num(struct bnx2x *bp)
690adfc5217SJeff Kirsher {
691adfc5217SJeff Kirsher 	if (CHIP_IS_E2(bp))
692adfc5217SJeff Kirsher 		return PAGE_WRITE_REGS_E2;
693adfc5217SJeff Kirsher 	else if (CHIP_IS_E3(bp))
694adfc5217SJeff Kirsher 		return PAGE_WRITE_REGS_E3;
695adfc5217SJeff Kirsher 	else
696adfc5217SJeff Kirsher 		return 0;
697adfc5217SJeff Kirsher }
698adfc5217SJeff Kirsher 
6991191cb83SEric Dumazet static const struct reg_addr *__bnx2x_get_page_read_ar(struct bnx2x *bp)
700adfc5217SJeff Kirsher {
701adfc5217SJeff Kirsher 	if (CHIP_IS_E2(bp))
702adfc5217SJeff Kirsher 		return page_read_regs_e2;
703adfc5217SJeff Kirsher 	else if (CHIP_IS_E3(bp))
704adfc5217SJeff Kirsher 		return page_read_regs_e3;
705adfc5217SJeff Kirsher 	else
706adfc5217SJeff Kirsher 		return NULL;
707adfc5217SJeff Kirsher }
708adfc5217SJeff Kirsher 
7091191cb83SEric Dumazet static u32 __bnx2x_get_page_read_num(struct bnx2x *bp)
710adfc5217SJeff Kirsher {
711adfc5217SJeff Kirsher 	if (CHIP_IS_E2(bp))
712adfc5217SJeff Kirsher 		return PAGE_READ_REGS_E2;
713adfc5217SJeff Kirsher 	else if (CHIP_IS_E3(bp))
714adfc5217SJeff Kirsher 		return PAGE_READ_REGS_E3;
715adfc5217SJeff Kirsher 	else
716adfc5217SJeff Kirsher 		return 0;
717adfc5217SJeff Kirsher }
718adfc5217SJeff Kirsher 
71907ba6af4SMiriam Shitrit static bool bnx2x_is_reg_in_chip(struct bnx2x *bp,
72007ba6af4SMiriam Shitrit 				       const struct reg_addr *reg_info)
721adfc5217SJeff Kirsher {
72207ba6af4SMiriam Shitrit 	if (CHIP_IS_E1(bp))
72307ba6af4SMiriam Shitrit 		return IS_E1_REG(reg_info->chips);
72407ba6af4SMiriam Shitrit 	else if (CHIP_IS_E1H(bp))
72507ba6af4SMiriam Shitrit 		return IS_E1H_REG(reg_info->chips);
72607ba6af4SMiriam Shitrit 	else if (CHIP_IS_E2(bp))
72707ba6af4SMiriam Shitrit 		return IS_E2_REG(reg_info->chips);
72807ba6af4SMiriam Shitrit 	else if (CHIP_IS_E3A0(bp))
72907ba6af4SMiriam Shitrit 		return IS_E3A0_REG(reg_info->chips);
73007ba6af4SMiriam Shitrit 	else if (CHIP_IS_E3B0(bp))
73107ba6af4SMiriam Shitrit 		return IS_E3B0_REG(reg_info->chips);
73207ba6af4SMiriam Shitrit 	else
73307ba6af4SMiriam Shitrit 		return false;
734adfc5217SJeff Kirsher }
735adfc5217SJeff Kirsher 
73607ba6af4SMiriam Shitrit 
73707ba6af4SMiriam Shitrit static bool bnx2x_is_wreg_in_chip(struct bnx2x *bp,
73807ba6af4SMiriam Shitrit 	const struct wreg_addr *wreg_info)
739adfc5217SJeff Kirsher {
74007ba6af4SMiriam Shitrit 	if (CHIP_IS_E1(bp))
74107ba6af4SMiriam Shitrit 		return IS_E1_REG(wreg_info->chips);
74207ba6af4SMiriam Shitrit 	else if (CHIP_IS_E1H(bp))
74307ba6af4SMiriam Shitrit 		return IS_E1H_REG(wreg_info->chips);
74407ba6af4SMiriam Shitrit 	else if (CHIP_IS_E2(bp))
74507ba6af4SMiriam Shitrit 		return IS_E2_REG(wreg_info->chips);
74607ba6af4SMiriam Shitrit 	else if (CHIP_IS_E3A0(bp))
74707ba6af4SMiriam Shitrit 		return IS_E3A0_REG(wreg_info->chips);
74807ba6af4SMiriam Shitrit 	else if (CHIP_IS_E3B0(bp))
74907ba6af4SMiriam Shitrit 		return IS_E3B0_REG(wreg_info->chips);
75007ba6af4SMiriam Shitrit 	else
75107ba6af4SMiriam Shitrit 		return false;
752adfc5217SJeff Kirsher }
753adfc5217SJeff Kirsher 
754adfc5217SJeff Kirsher /**
755adfc5217SJeff Kirsher  * bnx2x_read_pages_regs - read "paged" registers
756adfc5217SJeff Kirsher  *
757adfc5217SJeff Kirsher  * @bp		device handle
758adfc5217SJeff Kirsher  * @p		output buffer
759adfc5217SJeff Kirsher  *
7602de67439SYuval Mintz  * Reads "paged" memories: memories that may only be read by first writing to a
7612de67439SYuval Mintz  * specific address ("write address") and then reading from a specific address
7622de67439SYuval Mintz  * ("read address"). There may be more than one write address per "page" and
7632de67439SYuval Mintz  * more than one read address per write address.
764adfc5217SJeff Kirsher  */
76507ba6af4SMiriam Shitrit static void bnx2x_read_pages_regs(struct bnx2x *bp, u32 *p, u32 preset)
766adfc5217SJeff Kirsher {
767adfc5217SJeff Kirsher 	u32 i, j, k, n;
76807ba6af4SMiriam Shitrit 
769adfc5217SJeff Kirsher 	/* addresses of the paged registers */
770adfc5217SJeff Kirsher 	const u32 *page_addr = __bnx2x_get_page_addr_ar(bp);
771adfc5217SJeff Kirsher 	/* number of paged registers */
772adfc5217SJeff Kirsher 	int num_pages = __bnx2x_get_page_reg_num(bp);
773adfc5217SJeff Kirsher 	/* write addresses */
774adfc5217SJeff Kirsher 	const u32 *write_addr = __bnx2x_get_page_write_ar(bp);
775adfc5217SJeff Kirsher 	/* number of write addresses */
776adfc5217SJeff Kirsher 	int write_num = __bnx2x_get_page_write_num(bp);
777adfc5217SJeff Kirsher 	/* read addresses info */
778adfc5217SJeff Kirsher 	const struct reg_addr *read_addr = __bnx2x_get_page_read_ar(bp);
779adfc5217SJeff Kirsher 	/* number of read addresses */
780adfc5217SJeff Kirsher 	int read_num = __bnx2x_get_page_read_num(bp);
78107ba6af4SMiriam Shitrit 	u32 addr, size;
782adfc5217SJeff Kirsher 
783adfc5217SJeff Kirsher 	for (i = 0; i < num_pages; i++) {
784adfc5217SJeff Kirsher 		for (j = 0; j < write_num; j++) {
785adfc5217SJeff Kirsher 			REG_WR(bp, write_addr[j], page_addr[i]);
78607ba6af4SMiriam Shitrit 
78707ba6af4SMiriam Shitrit 			for (k = 0; k < read_num; k++) {
78807ba6af4SMiriam Shitrit 				if (IS_REG_IN_PRESET(read_addr[k].presets,
78907ba6af4SMiriam Shitrit 						     preset)) {
79007ba6af4SMiriam Shitrit 					size = read_addr[k].size;
79107ba6af4SMiriam Shitrit 					for (n = 0; n < size; n++) {
79207ba6af4SMiriam Shitrit 						addr = read_addr[k].addr + n*4;
79307ba6af4SMiriam Shitrit 						*p++ = REG_RD(bp, addr);
794adfc5217SJeff Kirsher 					}
795adfc5217SJeff Kirsher 				}
796adfc5217SJeff Kirsher 			}
79707ba6af4SMiriam Shitrit 		}
79807ba6af4SMiriam Shitrit 	}
79907ba6af4SMiriam Shitrit }
80007ba6af4SMiriam Shitrit 
80107ba6af4SMiriam Shitrit static int __bnx2x_get_preset_regs(struct bnx2x *bp, u32 *p, u32 preset)
80207ba6af4SMiriam Shitrit {
80307ba6af4SMiriam Shitrit 	u32 i, j, addr;
80407ba6af4SMiriam Shitrit 	const struct wreg_addr *wreg_addr_p = NULL;
80507ba6af4SMiriam Shitrit 
80607ba6af4SMiriam Shitrit 	if (CHIP_IS_E1(bp))
80707ba6af4SMiriam Shitrit 		wreg_addr_p = &wreg_addr_e1;
80807ba6af4SMiriam Shitrit 	else if (CHIP_IS_E1H(bp))
80907ba6af4SMiriam Shitrit 		wreg_addr_p = &wreg_addr_e1h;
81007ba6af4SMiriam Shitrit 	else if (CHIP_IS_E2(bp))
81107ba6af4SMiriam Shitrit 		wreg_addr_p = &wreg_addr_e2;
81207ba6af4SMiriam Shitrit 	else if (CHIP_IS_E3A0(bp))
81307ba6af4SMiriam Shitrit 		wreg_addr_p = &wreg_addr_e3;
81407ba6af4SMiriam Shitrit 	else if (CHIP_IS_E3B0(bp))
81507ba6af4SMiriam Shitrit 		wreg_addr_p = &wreg_addr_e3b0;
81607ba6af4SMiriam Shitrit 
81707ba6af4SMiriam Shitrit 	/* Read the idle_chk registers */
81807ba6af4SMiriam Shitrit 	for (i = 0; i < IDLE_REGS_COUNT; i++) {
81907ba6af4SMiriam Shitrit 		if (bnx2x_is_reg_in_chip(bp, &idle_reg_addrs[i]) &&
82007ba6af4SMiriam Shitrit 		    IS_REG_IN_PRESET(idle_reg_addrs[i].presets, preset)) {
82107ba6af4SMiriam Shitrit 			for (j = 0; j < idle_reg_addrs[i].size; j++)
82207ba6af4SMiriam Shitrit 				*p++ = REG_RD(bp, idle_reg_addrs[i].addr + j*4);
82307ba6af4SMiriam Shitrit 		}
82407ba6af4SMiriam Shitrit 	}
82507ba6af4SMiriam Shitrit 
82607ba6af4SMiriam Shitrit 	/* Read the regular registers */
82707ba6af4SMiriam Shitrit 	for (i = 0; i < REGS_COUNT; i++) {
82807ba6af4SMiriam Shitrit 		if (bnx2x_is_reg_in_chip(bp, &reg_addrs[i]) &&
82907ba6af4SMiriam Shitrit 		    IS_REG_IN_PRESET(reg_addrs[i].presets, preset)) {
83007ba6af4SMiriam Shitrit 			for (j = 0; j < reg_addrs[i].size; j++)
83107ba6af4SMiriam Shitrit 				*p++ = REG_RD(bp, reg_addrs[i].addr + j*4);
83207ba6af4SMiriam Shitrit 		}
83307ba6af4SMiriam Shitrit 	}
83407ba6af4SMiriam Shitrit 
83507ba6af4SMiriam Shitrit 	/* Read the CAM registers */
83607ba6af4SMiriam Shitrit 	if (bnx2x_is_wreg_in_chip(bp, wreg_addr_p) &&
83707ba6af4SMiriam Shitrit 	    IS_REG_IN_PRESET(wreg_addr_p->presets, preset)) {
83807ba6af4SMiriam Shitrit 		for (i = 0; i < wreg_addr_p->size; i++) {
83907ba6af4SMiriam Shitrit 			*p++ = REG_RD(bp, wreg_addr_p->addr + i*4);
84007ba6af4SMiriam Shitrit 
84107ba6af4SMiriam Shitrit 			/* In case of wreg_addr register, read additional
84207ba6af4SMiriam Shitrit 			   registers from read_regs array
84307ba6af4SMiriam Shitrit 			*/
84407ba6af4SMiriam Shitrit 			for (j = 0; j < wreg_addr_p->read_regs_count; j++) {
84507ba6af4SMiriam Shitrit 				addr = *(wreg_addr_p->read_regs);
84607ba6af4SMiriam Shitrit 				*p++ = REG_RD(bp, addr + j*4);
84707ba6af4SMiriam Shitrit 			}
84807ba6af4SMiriam Shitrit 		}
84907ba6af4SMiriam Shitrit 	}
85007ba6af4SMiriam Shitrit 
85107ba6af4SMiriam Shitrit 	/* Paged registers are supported in E2 & E3 only */
85207ba6af4SMiriam Shitrit 	if (CHIP_IS_E2(bp) || CHIP_IS_E3(bp)) {
85307ba6af4SMiriam Shitrit 		/* Read "paged" registes */
85407ba6af4SMiriam Shitrit 		bnx2x_read_pages_regs(bp, p, preset);
85507ba6af4SMiriam Shitrit 	}
85607ba6af4SMiriam Shitrit 
85707ba6af4SMiriam Shitrit 	return 0;
85807ba6af4SMiriam Shitrit }
859adfc5217SJeff Kirsher 
8601191cb83SEric Dumazet static void __bnx2x_get_regs(struct bnx2x *bp, u32 *p)
861adfc5217SJeff Kirsher {
86207ba6af4SMiriam Shitrit 	u32 preset_idx;
863adfc5217SJeff Kirsher 
86407ba6af4SMiriam Shitrit 	/* Read all registers, by reading all preset registers */
86507ba6af4SMiriam Shitrit 	for (preset_idx = 1; preset_idx <= DUMP_MAX_PRESETS; preset_idx++) {
86607ba6af4SMiriam Shitrit 		/* Skip presets with IOR */
86707ba6af4SMiriam Shitrit 		if ((preset_idx == 2) ||
86807ba6af4SMiriam Shitrit 		    (preset_idx == 5) ||
86907ba6af4SMiriam Shitrit 		    (preset_idx == 8) ||
87007ba6af4SMiriam Shitrit 		    (preset_idx == 11))
87107ba6af4SMiriam Shitrit 			continue;
87207ba6af4SMiriam Shitrit 		__bnx2x_get_preset_regs(bp, p, preset_idx);
87307ba6af4SMiriam Shitrit 		p += __bnx2x_get_preset_regs_len(bp, preset_idx);
87407ba6af4SMiriam Shitrit 	}
875adfc5217SJeff Kirsher }
876adfc5217SJeff Kirsher 
877adfc5217SJeff Kirsher static void bnx2x_get_regs(struct net_device *dev,
878adfc5217SJeff Kirsher 			   struct ethtool_regs *regs, void *_p)
879adfc5217SJeff Kirsher {
880adfc5217SJeff Kirsher 	u32 *p = _p;
881adfc5217SJeff Kirsher 	struct bnx2x *bp = netdev_priv(dev);
88207ba6af4SMiriam Shitrit 	struct dump_header dump_hdr = {0};
883adfc5217SJeff Kirsher 
88407ba6af4SMiriam Shitrit 	regs->version = 2;
885adfc5217SJeff Kirsher 	memset(p, 0, regs->len);
886adfc5217SJeff Kirsher 
887adfc5217SJeff Kirsher 	if (!netif_running(bp->dev))
888adfc5217SJeff Kirsher 		return;
889adfc5217SJeff Kirsher 
890adfc5217SJeff Kirsher 	/* Disable parity attentions as long as following dump may
891adfc5217SJeff Kirsher 	 * cause false alarms by reading never written registers. We
892adfc5217SJeff Kirsher 	 * will re-enable parity attentions right after the dump.
893adfc5217SJeff Kirsher 	 */
89407ba6af4SMiriam Shitrit 
89507ba6af4SMiriam Shitrit 	/* Disable parity on path 0 */
89607ba6af4SMiriam Shitrit 	bnx2x_pretend_func(bp, 0);
897adfc5217SJeff Kirsher 	bnx2x_disable_blocks_parity(bp);
898adfc5217SJeff Kirsher 
89907ba6af4SMiriam Shitrit 	/* Disable parity on path 1 */
90007ba6af4SMiriam Shitrit 	bnx2x_pretend_func(bp, 1);
90107ba6af4SMiriam Shitrit 	bnx2x_disable_blocks_parity(bp);
902adfc5217SJeff Kirsher 
90307ba6af4SMiriam Shitrit 	/* Return to current function */
90407ba6af4SMiriam Shitrit 	bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
905adfc5217SJeff Kirsher 
90607ba6af4SMiriam Shitrit 	dump_hdr.header_size = (sizeof(struct dump_header) / 4) - 1;
90707ba6af4SMiriam Shitrit 	dump_hdr.preset = DUMP_ALL_PRESETS;
90807ba6af4SMiriam Shitrit 	dump_hdr.version = BNX2X_DUMP_VERSION;
90907ba6af4SMiriam Shitrit 
91007ba6af4SMiriam Shitrit 	/* dump_meta_data presents OR of CHIP and PATH. */
91107ba6af4SMiriam Shitrit 	if (CHIP_IS_E1(bp)) {
91207ba6af4SMiriam Shitrit 		dump_hdr.dump_meta_data = DUMP_CHIP_E1;
91307ba6af4SMiriam Shitrit 	} else if (CHIP_IS_E1H(bp)) {
91407ba6af4SMiriam Shitrit 		dump_hdr.dump_meta_data = DUMP_CHIP_E1H;
91507ba6af4SMiriam Shitrit 	} else if (CHIP_IS_E2(bp)) {
91607ba6af4SMiriam Shitrit 		dump_hdr.dump_meta_data = DUMP_CHIP_E2 |
91707ba6af4SMiriam Shitrit 		(BP_PATH(bp) ? DUMP_PATH_1 : DUMP_PATH_0);
91807ba6af4SMiriam Shitrit 	} else if (CHIP_IS_E3A0(bp)) {
91907ba6af4SMiriam Shitrit 		dump_hdr.dump_meta_data = DUMP_CHIP_E3A0 |
92007ba6af4SMiriam Shitrit 		(BP_PATH(bp) ? DUMP_PATH_1 : DUMP_PATH_0);
92107ba6af4SMiriam Shitrit 	} else if (CHIP_IS_E3B0(bp)) {
92207ba6af4SMiriam Shitrit 		dump_hdr.dump_meta_data = DUMP_CHIP_E3B0 |
92307ba6af4SMiriam Shitrit 		(BP_PATH(bp) ? DUMP_PATH_1 : DUMP_PATH_0);
92407ba6af4SMiriam Shitrit 	}
92507ba6af4SMiriam Shitrit 
92607ba6af4SMiriam Shitrit 	memcpy(p, &dump_hdr, sizeof(struct dump_header));
92707ba6af4SMiriam Shitrit 	p += dump_hdr.header_size + 1;
928adfc5217SJeff Kirsher 
929adfc5217SJeff Kirsher 	/* Actually read the registers */
930adfc5217SJeff Kirsher 	__bnx2x_get_regs(bp, p);
931adfc5217SJeff Kirsher 
93207ba6af4SMiriam Shitrit 	/* Re-enable parity attentions on path 0 */
93307ba6af4SMiriam Shitrit 	bnx2x_pretend_func(bp, 0);
934adfc5217SJeff Kirsher 	bnx2x_clear_blocks_parity(bp);
935adfc5217SJeff Kirsher 	bnx2x_enable_blocks_parity(bp);
93607ba6af4SMiriam Shitrit 
93707ba6af4SMiriam Shitrit 	/* Re-enable parity attentions on path 1 */
93807ba6af4SMiriam Shitrit 	bnx2x_pretend_func(bp, 1);
93907ba6af4SMiriam Shitrit 	bnx2x_clear_blocks_parity(bp);
94007ba6af4SMiriam Shitrit 	bnx2x_enable_blocks_parity(bp);
94107ba6af4SMiriam Shitrit 
94207ba6af4SMiriam Shitrit 	/* Return to current function */
94307ba6af4SMiriam Shitrit 	bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
94407ba6af4SMiriam Shitrit }
94507ba6af4SMiriam Shitrit 
94607ba6af4SMiriam Shitrit static int bnx2x_get_preset_regs_len(struct net_device *dev, u32 preset)
94707ba6af4SMiriam Shitrit {
94807ba6af4SMiriam Shitrit 	struct bnx2x *bp = netdev_priv(dev);
94907ba6af4SMiriam Shitrit 	int regdump_len = 0;
95007ba6af4SMiriam Shitrit 
95107ba6af4SMiriam Shitrit 	regdump_len = __bnx2x_get_preset_regs_len(bp, preset);
95207ba6af4SMiriam Shitrit 	regdump_len *= 4;
95307ba6af4SMiriam Shitrit 	regdump_len += sizeof(struct dump_header);
95407ba6af4SMiriam Shitrit 
95507ba6af4SMiriam Shitrit 	return regdump_len;
95607ba6af4SMiriam Shitrit }
95707ba6af4SMiriam Shitrit 
95807ba6af4SMiriam Shitrit static int bnx2x_set_dump(struct net_device *dev, struct ethtool_dump *val)
95907ba6af4SMiriam Shitrit {
96007ba6af4SMiriam Shitrit 	struct bnx2x *bp = netdev_priv(dev);
96107ba6af4SMiriam Shitrit 
96207ba6af4SMiriam Shitrit 	/* Use the ethtool_dump "flag" field as the dump preset index */
96307ba6af4SMiriam Shitrit 	bp->dump_preset_idx = val->flag;
96407ba6af4SMiriam Shitrit 	return 0;
96507ba6af4SMiriam Shitrit }
96607ba6af4SMiriam Shitrit 
96707ba6af4SMiriam Shitrit static int bnx2x_get_dump_flag(struct net_device *dev,
96807ba6af4SMiriam Shitrit 			       struct ethtool_dump *dump)
96907ba6af4SMiriam Shitrit {
97007ba6af4SMiriam Shitrit 	struct bnx2x *bp = netdev_priv(dev);
97107ba6af4SMiriam Shitrit 
97207ba6af4SMiriam Shitrit 	/* Calculate the requested preset idx length */
97307ba6af4SMiriam Shitrit 	dump->len = bnx2x_get_preset_regs_len(dev, bp->dump_preset_idx);
97407ba6af4SMiriam Shitrit 	DP(BNX2X_MSG_ETHTOOL, "Get dump preset %d length=%d\n",
97507ba6af4SMiriam Shitrit 	   bp->dump_preset_idx, dump->len);
97607ba6af4SMiriam Shitrit 
97707ba6af4SMiriam Shitrit 	dump->flag = ETHTOOL_GET_DUMP_DATA;
97807ba6af4SMiriam Shitrit 	return 0;
97907ba6af4SMiriam Shitrit }
98007ba6af4SMiriam Shitrit 
98107ba6af4SMiriam Shitrit static int bnx2x_get_dump_data(struct net_device *dev,
98207ba6af4SMiriam Shitrit 			       struct ethtool_dump *dump,
98307ba6af4SMiriam Shitrit 			       void *buffer)
98407ba6af4SMiriam Shitrit {
98507ba6af4SMiriam Shitrit 	u32 *p = buffer;
98607ba6af4SMiriam Shitrit 	struct bnx2x *bp = netdev_priv(dev);
98707ba6af4SMiriam Shitrit 	struct dump_header dump_hdr = {0};
98807ba6af4SMiriam Shitrit 
98907ba6af4SMiriam Shitrit 	memset(p, 0, dump->len);
99007ba6af4SMiriam Shitrit 
99107ba6af4SMiriam Shitrit 	/* Disable parity attentions as long as following dump may
99207ba6af4SMiriam Shitrit 	 * cause false alarms by reading never written registers. We
99307ba6af4SMiriam Shitrit 	 * will re-enable parity attentions right after the dump.
99407ba6af4SMiriam Shitrit 	 */
99507ba6af4SMiriam Shitrit 
99607ba6af4SMiriam Shitrit 	/* Disable parity on path 0 */
99707ba6af4SMiriam Shitrit 	bnx2x_pretend_func(bp, 0);
99807ba6af4SMiriam Shitrit 	bnx2x_disable_blocks_parity(bp);
99907ba6af4SMiriam Shitrit 
100007ba6af4SMiriam Shitrit 	/* Disable parity on path 1 */
100107ba6af4SMiriam Shitrit 	bnx2x_pretend_func(bp, 1);
100207ba6af4SMiriam Shitrit 	bnx2x_disable_blocks_parity(bp);
100307ba6af4SMiriam Shitrit 
100407ba6af4SMiriam Shitrit 	/* Return to current function */
100507ba6af4SMiriam Shitrit 	bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
100607ba6af4SMiriam Shitrit 
100707ba6af4SMiriam Shitrit 	dump_hdr.header_size = (sizeof(struct dump_header) / 4) - 1;
100807ba6af4SMiriam Shitrit 	dump_hdr.preset = bp->dump_preset_idx;
100907ba6af4SMiriam Shitrit 	dump_hdr.version = BNX2X_DUMP_VERSION;
101007ba6af4SMiriam Shitrit 
101107ba6af4SMiriam Shitrit 	DP(BNX2X_MSG_ETHTOOL, "Get dump data of preset %d\n", dump_hdr.preset);
101207ba6af4SMiriam Shitrit 
101307ba6af4SMiriam Shitrit 	/* dump_meta_data presents OR of CHIP and PATH. */
101407ba6af4SMiriam Shitrit 	if (CHIP_IS_E1(bp)) {
101507ba6af4SMiriam Shitrit 		dump_hdr.dump_meta_data = DUMP_CHIP_E1;
101607ba6af4SMiriam Shitrit 	} else if (CHIP_IS_E1H(bp)) {
101707ba6af4SMiriam Shitrit 		dump_hdr.dump_meta_data = DUMP_CHIP_E1H;
101807ba6af4SMiriam Shitrit 	} else if (CHIP_IS_E2(bp)) {
101907ba6af4SMiriam Shitrit 		dump_hdr.dump_meta_data = DUMP_CHIP_E2 |
102007ba6af4SMiriam Shitrit 		(BP_PATH(bp) ? DUMP_PATH_1 : DUMP_PATH_0);
102107ba6af4SMiriam Shitrit 	} else if (CHIP_IS_E3A0(bp)) {
102207ba6af4SMiriam Shitrit 		dump_hdr.dump_meta_data = DUMP_CHIP_E3A0 |
102307ba6af4SMiriam Shitrit 		(BP_PATH(bp) ? DUMP_PATH_1 : DUMP_PATH_0);
102407ba6af4SMiriam Shitrit 	} else if (CHIP_IS_E3B0(bp)) {
102507ba6af4SMiriam Shitrit 		dump_hdr.dump_meta_data = DUMP_CHIP_E3B0 |
102607ba6af4SMiriam Shitrit 		(BP_PATH(bp) ? DUMP_PATH_1 : DUMP_PATH_0);
102707ba6af4SMiriam Shitrit 	}
102807ba6af4SMiriam Shitrit 
102907ba6af4SMiriam Shitrit 	memcpy(p, &dump_hdr, sizeof(struct dump_header));
103007ba6af4SMiriam Shitrit 	p += dump_hdr.header_size + 1;
103107ba6af4SMiriam Shitrit 
103207ba6af4SMiriam Shitrit 	/* Actually read the registers */
103307ba6af4SMiriam Shitrit 	__bnx2x_get_preset_regs(bp, p, dump_hdr.preset);
103407ba6af4SMiriam Shitrit 
103507ba6af4SMiriam Shitrit 	/* Re-enable parity attentions on path 0 */
103607ba6af4SMiriam Shitrit 	bnx2x_pretend_func(bp, 0);
103707ba6af4SMiriam Shitrit 	bnx2x_clear_blocks_parity(bp);
103807ba6af4SMiriam Shitrit 	bnx2x_enable_blocks_parity(bp);
103907ba6af4SMiriam Shitrit 
104007ba6af4SMiriam Shitrit 	/* Re-enable parity attentions on path 1 */
104107ba6af4SMiriam Shitrit 	bnx2x_pretend_func(bp, 1);
104207ba6af4SMiriam Shitrit 	bnx2x_clear_blocks_parity(bp);
104307ba6af4SMiriam Shitrit 	bnx2x_enable_blocks_parity(bp);
104407ba6af4SMiriam Shitrit 
104507ba6af4SMiriam Shitrit 	/* Return to current function */
104607ba6af4SMiriam Shitrit 	bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
104707ba6af4SMiriam Shitrit 
104807ba6af4SMiriam Shitrit 	return 0;
1049adfc5217SJeff Kirsher }
1050adfc5217SJeff Kirsher 
1051adfc5217SJeff Kirsher static void bnx2x_get_drvinfo(struct net_device *dev,
1052adfc5217SJeff Kirsher 			      struct ethtool_drvinfo *info)
1053adfc5217SJeff Kirsher {
1054adfc5217SJeff Kirsher 	struct bnx2x *bp = netdev_priv(dev);
1055adfc5217SJeff Kirsher 
105668aad78cSRick Jones 	strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver));
105768aad78cSRick Jones 	strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
1058adfc5217SJeff Kirsher 
10598ca5e17eSAriel Elior 	bnx2x_fill_fw_str(bp, info->fw_version, sizeof(info->fw_version));
10608ca5e17eSAriel Elior 
106168aad78cSRick Jones 	strlcpy(info->bus_info, pci_name(bp->pdev), sizeof(info->bus_info));
1062adfc5217SJeff Kirsher 	info->n_stats = BNX2X_NUM_STATS;
1063cf2c1df6SMerav Sicron 	info->testinfo_len = BNX2X_NUM_TESTS(bp);
1064adfc5217SJeff Kirsher 	info->eedump_len = bp->common.flash_size;
1065adfc5217SJeff Kirsher 	info->regdump_len = bnx2x_get_regs_len(dev);
1066adfc5217SJeff Kirsher }
1067adfc5217SJeff Kirsher 
1068adfc5217SJeff Kirsher static void bnx2x_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
1069adfc5217SJeff Kirsher {
1070adfc5217SJeff Kirsher 	struct bnx2x *bp = netdev_priv(dev);
1071adfc5217SJeff Kirsher 
1072adfc5217SJeff Kirsher 	if (bp->flags & NO_WOL_FLAG) {
1073adfc5217SJeff Kirsher 		wol->supported = 0;
1074adfc5217SJeff Kirsher 		wol->wolopts = 0;
1075adfc5217SJeff Kirsher 	} else {
1076adfc5217SJeff Kirsher 		wol->supported = WAKE_MAGIC;
1077adfc5217SJeff Kirsher 		if (bp->wol)
1078adfc5217SJeff Kirsher 			wol->wolopts = WAKE_MAGIC;
1079adfc5217SJeff Kirsher 		else
1080adfc5217SJeff Kirsher 			wol->wolopts = 0;
1081adfc5217SJeff Kirsher 	}
1082adfc5217SJeff Kirsher 	memset(&wol->sopass, 0, sizeof(wol->sopass));
1083adfc5217SJeff Kirsher }
1084adfc5217SJeff Kirsher 
1085adfc5217SJeff Kirsher static int bnx2x_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
1086adfc5217SJeff Kirsher {
1087adfc5217SJeff Kirsher 	struct bnx2x *bp = netdev_priv(dev);
1088adfc5217SJeff Kirsher 
108951c1a580SMerav Sicron 	if (wol->wolopts & ~WAKE_MAGIC) {
10902de67439SYuval Mintz 		DP(BNX2X_MSG_ETHTOOL, "WOL not supported\n");
1091adfc5217SJeff Kirsher 		return -EINVAL;
109251c1a580SMerav Sicron 	}
1093adfc5217SJeff Kirsher 
1094adfc5217SJeff Kirsher 	if (wol->wolopts & WAKE_MAGIC) {
109551c1a580SMerav Sicron 		if (bp->flags & NO_WOL_FLAG) {
10962de67439SYuval Mintz 			DP(BNX2X_MSG_ETHTOOL, "WOL not supported\n");
1097adfc5217SJeff Kirsher 			return -EINVAL;
109851c1a580SMerav Sicron 		}
1099adfc5217SJeff Kirsher 		bp->wol = 1;
1100adfc5217SJeff Kirsher 	} else
1101adfc5217SJeff Kirsher 		bp->wol = 0;
1102adfc5217SJeff Kirsher 
1103adfc5217SJeff Kirsher 	return 0;
1104adfc5217SJeff Kirsher }
1105adfc5217SJeff Kirsher 
1106adfc5217SJeff Kirsher static u32 bnx2x_get_msglevel(struct net_device *dev)
1107adfc5217SJeff Kirsher {
1108adfc5217SJeff Kirsher 	struct bnx2x *bp = netdev_priv(dev);
1109adfc5217SJeff Kirsher 
1110adfc5217SJeff Kirsher 	return bp->msg_enable;
1111adfc5217SJeff Kirsher }
1112adfc5217SJeff Kirsher 
1113adfc5217SJeff Kirsher static void bnx2x_set_msglevel(struct net_device *dev, u32 level)
1114adfc5217SJeff Kirsher {
1115adfc5217SJeff Kirsher 	struct bnx2x *bp = netdev_priv(dev);
1116adfc5217SJeff Kirsher 
1117adfc5217SJeff Kirsher 	if (capable(CAP_NET_ADMIN)) {
1118adfc5217SJeff Kirsher 		/* dump MCP trace */
1119ad5afc89SAriel Elior 		if (IS_PF(bp) && (level & BNX2X_MSG_MCP))
1120adfc5217SJeff Kirsher 			bnx2x_fw_dump_lvl(bp, KERN_INFO);
1121adfc5217SJeff Kirsher 		bp->msg_enable = level;
1122adfc5217SJeff Kirsher 	}
1123adfc5217SJeff Kirsher }
1124adfc5217SJeff Kirsher 
1125adfc5217SJeff Kirsher static int bnx2x_nway_reset(struct net_device *dev)
1126adfc5217SJeff Kirsher {
1127adfc5217SJeff Kirsher 	struct bnx2x *bp = netdev_priv(dev);
1128adfc5217SJeff Kirsher 
1129adfc5217SJeff Kirsher 	if (!bp->port.pmf)
1130adfc5217SJeff Kirsher 		return 0;
1131adfc5217SJeff Kirsher 
1132adfc5217SJeff Kirsher 	if (netif_running(dev)) {
1133adfc5217SJeff Kirsher 		bnx2x_stats_handle(bp, STATS_EVENT_STOP);
11345d07d868SYuval Mintz 		bnx2x_force_link_reset(bp);
1135adfc5217SJeff Kirsher 		bnx2x_link_set(bp);
1136adfc5217SJeff Kirsher 	}
1137adfc5217SJeff Kirsher 
1138adfc5217SJeff Kirsher 	return 0;
1139adfc5217SJeff Kirsher }
1140adfc5217SJeff Kirsher 
1141adfc5217SJeff Kirsher static u32 bnx2x_get_link(struct net_device *dev)
1142adfc5217SJeff Kirsher {
1143adfc5217SJeff Kirsher 	struct bnx2x *bp = netdev_priv(dev);
1144adfc5217SJeff Kirsher 
1145adfc5217SJeff Kirsher 	if (bp->flags & MF_FUNC_DIS || (bp->state != BNX2X_STATE_OPEN))
1146adfc5217SJeff Kirsher 		return 0;
1147adfc5217SJeff Kirsher 
1148adfc5217SJeff Kirsher 	return bp->link_vars.link_up;
1149adfc5217SJeff Kirsher }
1150adfc5217SJeff Kirsher 
1151adfc5217SJeff Kirsher static int bnx2x_get_eeprom_len(struct net_device *dev)
1152adfc5217SJeff Kirsher {
1153adfc5217SJeff Kirsher 	struct bnx2x *bp = netdev_priv(dev);
1154adfc5217SJeff Kirsher 
1155adfc5217SJeff Kirsher 	return bp->common.flash_size;
1156adfc5217SJeff Kirsher }
1157adfc5217SJeff Kirsher 
1158f16da43bSAriel Elior /* Per pf misc lock must be aquired before the per port mcp lock. Otherwise, had
1159f16da43bSAriel Elior  * we done things the other way around, if two pfs from the same port would
1160f16da43bSAriel Elior  * attempt to access nvram at the same time, we could run into a scenario such
1161f16da43bSAriel Elior  * as:
1162f16da43bSAriel Elior  * pf A takes the port lock.
1163f16da43bSAriel Elior  * pf B succeeds in taking the same lock since they are from the same port.
1164f16da43bSAriel Elior  * pf A takes the per pf misc lock. Performs eeprom access.
1165f16da43bSAriel Elior  * pf A finishes. Unlocks the per pf misc lock.
1166f16da43bSAriel Elior  * Pf B takes the lock and proceeds to perform it's own access.
1167f16da43bSAriel Elior  * pf A unlocks the per port lock, while pf B is still working (!).
1168f16da43bSAriel Elior  * mcp takes the per port lock and corrupts pf B's access (and/or has it's own
11692de67439SYuval Mintz  * access corrupted by pf B)
1170f16da43bSAriel Elior  */
1171adfc5217SJeff Kirsher static int bnx2x_acquire_nvram_lock(struct bnx2x *bp)
1172adfc5217SJeff Kirsher {
1173adfc5217SJeff Kirsher 	int port = BP_PORT(bp);
1174adfc5217SJeff Kirsher 	int count, i;
1175f16da43bSAriel Elior 	u32 val;
1176f16da43bSAriel Elior 
1177f16da43bSAriel Elior 	/* acquire HW lock: protect against other PFs in PF Direct Assignment */
1178f16da43bSAriel Elior 	bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_NVRAM);
1179adfc5217SJeff Kirsher 
1180adfc5217SJeff Kirsher 	/* adjust timeout for emulation/FPGA */
1181adfc5217SJeff Kirsher 	count = BNX2X_NVRAM_TIMEOUT_COUNT;
1182adfc5217SJeff Kirsher 	if (CHIP_REV_IS_SLOW(bp))
1183adfc5217SJeff Kirsher 		count *= 100;
1184adfc5217SJeff Kirsher 
1185adfc5217SJeff Kirsher 	/* request access to nvram interface */
1186adfc5217SJeff Kirsher 	REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
1187adfc5217SJeff Kirsher 	       (MCPR_NVM_SW_ARB_ARB_REQ_SET1 << port));
1188adfc5217SJeff Kirsher 
1189adfc5217SJeff Kirsher 	for (i = 0; i < count*10; i++) {
1190adfc5217SJeff Kirsher 		val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB);
1191adfc5217SJeff Kirsher 		if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))
1192adfc5217SJeff Kirsher 			break;
1193adfc5217SJeff Kirsher 
1194adfc5217SJeff Kirsher 		udelay(5);
1195adfc5217SJeff Kirsher 	}
1196adfc5217SJeff Kirsher 
1197adfc5217SJeff Kirsher 	if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))) {
119851c1a580SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
119951c1a580SMerav Sicron 		   "cannot get access to nvram interface\n");
1200adfc5217SJeff Kirsher 		return -EBUSY;
1201adfc5217SJeff Kirsher 	}
1202adfc5217SJeff Kirsher 
1203adfc5217SJeff Kirsher 	return 0;
1204adfc5217SJeff Kirsher }
1205adfc5217SJeff Kirsher 
1206adfc5217SJeff Kirsher static int bnx2x_release_nvram_lock(struct bnx2x *bp)
1207adfc5217SJeff Kirsher {
1208adfc5217SJeff Kirsher 	int port = BP_PORT(bp);
1209adfc5217SJeff Kirsher 	int count, i;
1210f16da43bSAriel Elior 	u32 val;
1211adfc5217SJeff Kirsher 
1212adfc5217SJeff Kirsher 	/* adjust timeout for emulation/FPGA */
1213adfc5217SJeff Kirsher 	count = BNX2X_NVRAM_TIMEOUT_COUNT;
1214adfc5217SJeff Kirsher 	if (CHIP_REV_IS_SLOW(bp))
1215adfc5217SJeff Kirsher 		count *= 100;
1216adfc5217SJeff Kirsher 
1217adfc5217SJeff Kirsher 	/* relinquish nvram interface */
1218adfc5217SJeff Kirsher 	REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
1219adfc5217SJeff Kirsher 	       (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << port));
1220adfc5217SJeff Kirsher 
1221adfc5217SJeff Kirsher 	for (i = 0; i < count*10; i++) {
1222adfc5217SJeff Kirsher 		val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB);
1223adfc5217SJeff Kirsher 		if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)))
1224adfc5217SJeff Kirsher 			break;
1225adfc5217SJeff Kirsher 
1226adfc5217SJeff Kirsher 		udelay(5);
1227adfc5217SJeff Kirsher 	}
1228adfc5217SJeff Kirsher 
1229adfc5217SJeff Kirsher 	if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)) {
123051c1a580SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
123151c1a580SMerav Sicron 		   "cannot free access to nvram interface\n");
1232adfc5217SJeff Kirsher 		return -EBUSY;
1233adfc5217SJeff Kirsher 	}
1234adfc5217SJeff Kirsher 
1235f16da43bSAriel Elior 	/* release HW lock: protect against other PFs in PF Direct Assignment */
1236f16da43bSAriel Elior 	bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_NVRAM);
1237adfc5217SJeff Kirsher 	return 0;
1238adfc5217SJeff Kirsher }
1239adfc5217SJeff Kirsher 
1240adfc5217SJeff Kirsher static void bnx2x_enable_nvram_access(struct bnx2x *bp)
1241adfc5217SJeff Kirsher {
1242adfc5217SJeff Kirsher 	u32 val;
1243adfc5217SJeff Kirsher 
1244adfc5217SJeff Kirsher 	val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
1245adfc5217SJeff Kirsher 
1246adfc5217SJeff Kirsher 	/* enable both bits, even on read */
1247adfc5217SJeff Kirsher 	REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
1248adfc5217SJeff Kirsher 	       (val | MCPR_NVM_ACCESS_ENABLE_EN |
1249adfc5217SJeff Kirsher 		      MCPR_NVM_ACCESS_ENABLE_WR_EN));
1250adfc5217SJeff Kirsher }
1251adfc5217SJeff Kirsher 
1252adfc5217SJeff Kirsher static void bnx2x_disable_nvram_access(struct bnx2x *bp)
1253adfc5217SJeff Kirsher {
1254adfc5217SJeff Kirsher 	u32 val;
1255adfc5217SJeff Kirsher 
1256adfc5217SJeff Kirsher 	val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
1257adfc5217SJeff Kirsher 
1258adfc5217SJeff Kirsher 	/* disable both bits, even after read */
1259adfc5217SJeff Kirsher 	REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
1260adfc5217SJeff Kirsher 	       (val & ~(MCPR_NVM_ACCESS_ENABLE_EN |
1261adfc5217SJeff Kirsher 			MCPR_NVM_ACCESS_ENABLE_WR_EN)));
1262adfc5217SJeff Kirsher }
1263adfc5217SJeff Kirsher 
1264adfc5217SJeff Kirsher static int bnx2x_nvram_read_dword(struct bnx2x *bp, u32 offset, __be32 *ret_val,
1265adfc5217SJeff Kirsher 				  u32 cmd_flags)
1266adfc5217SJeff Kirsher {
1267adfc5217SJeff Kirsher 	int count, i, rc;
1268adfc5217SJeff Kirsher 	u32 val;
1269adfc5217SJeff Kirsher 
1270adfc5217SJeff Kirsher 	/* build the command word */
1271adfc5217SJeff Kirsher 	cmd_flags |= MCPR_NVM_COMMAND_DOIT;
1272adfc5217SJeff Kirsher 
1273adfc5217SJeff Kirsher 	/* need to clear DONE bit separately */
1274adfc5217SJeff Kirsher 	REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
1275adfc5217SJeff Kirsher 
1276adfc5217SJeff Kirsher 	/* address of the NVRAM to read from */
1277adfc5217SJeff Kirsher 	REG_WR(bp, MCP_REG_MCPR_NVM_ADDR,
1278adfc5217SJeff Kirsher 	       (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
1279adfc5217SJeff Kirsher 
1280adfc5217SJeff Kirsher 	/* issue a read command */
1281adfc5217SJeff Kirsher 	REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
1282adfc5217SJeff Kirsher 
1283adfc5217SJeff Kirsher 	/* adjust timeout for emulation/FPGA */
1284adfc5217SJeff Kirsher 	count = BNX2X_NVRAM_TIMEOUT_COUNT;
1285adfc5217SJeff Kirsher 	if (CHIP_REV_IS_SLOW(bp))
1286adfc5217SJeff Kirsher 		count *= 100;
1287adfc5217SJeff Kirsher 
1288adfc5217SJeff Kirsher 	/* wait for completion */
1289adfc5217SJeff Kirsher 	*ret_val = 0;
1290adfc5217SJeff Kirsher 	rc = -EBUSY;
1291adfc5217SJeff Kirsher 	for (i = 0; i < count; i++) {
1292adfc5217SJeff Kirsher 		udelay(5);
1293adfc5217SJeff Kirsher 		val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND);
1294adfc5217SJeff Kirsher 
1295adfc5217SJeff Kirsher 		if (val & MCPR_NVM_COMMAND_DONE) {
1296adfc5217SJeff Kirsher 			val = REG_RD(bp, MCP_REG_MCPR_NVM_READ);
1297adfc5217SJeff Kirsher 			/* we read nvram data in cpu order
1298adfc5217SJeff Kirsher 			 * but ethtool sees it as an array of bytes
129907ba6af4SMiriam Shitrit 			 * converting to big-endian will do the work
130007ba6af4SMiriam Shitrit 			 */
1301adfc5217SJeff Kirsher 			*ret_val = cpu_to_be32(val);
1302adfc5217SJeff Kirsher 			rc = 0;
1303adfc5217SJeff Kirsher 			break;
1304adfc5217SJeff Kirsher 		}
1305adfc5217SJeff Kirsher 	}
130651c1a580SMerav Sicron 	if (rc == -EBUSY)
130751c1a580SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
130851c1a580SMerav Sicron 		   "nvram read timeout expired\n");
1309adfc5217SJeff Kirsher 	return rc;
1310adfc5217SJeff Kirsher }
1311adfc5217SJeff Kirsher 
1312adfc5217SJeff Kirsher static int bnx2x_nvram_read(struct bnx2x *bp, u32 offset, u8 *ret_buf,
1313adfc5217SJeff Kirsher 			    int buf_size)
1314adfc5217SJeff Kirsher {
1315adfc5217SJeff Kirsher 	int rc;
1316adfc5217SJeff Kirsher 	u32 cmd_flags;
1317adfc5217SJeff Kirsher 	__be32 val;
1318adfc5217SJeff Kirsher 
1319adfc5217SJeff Kirsher 	if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
132051c1a580SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
1321adfc5217SJeff Kirsher 		   "Invalid parameter: offset 0x%x  buf_size 0x%x\n",
1322adfc5217SJeff Kirsher 		   offset, buf_size);
1323adfc5217SJeff Kirsher 		return -EINVAL;
1324adfc5217SJeff Kirsher 	}
1325adfc5217SJeff Kirsher 
1326adfc5217SJeff Kirsher 	if (offset + buf_size > bp->common.flash_size) {
132751c1a580SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
132851c1a580SMerav Sicron 		   "Invalid parameter: offset (0x%x) + buf_size (0x%x) > flash_size (0x%x)\n",
1329adfc5217SJeff Kirsher 		   offset, buf_size, bp->common.flash_size);
1330adfc5217SJeff Kirsher 		return -EINVAL;
1331adfc5217SJeff Kirsher 	}
1332adfc5217SJeff Kirsher 
1333adfc5217SJeff Kirsher 	/* request access to nvram interface */
1334adfc5217SJeff Kirsher 	rc = bnx2x_acquire_nvram_lock(bp);
1335adfc5217SJeff Kirsher 	if (rc)
1336adfc5217SJeff Kirsher 		return rc;
1337adfc5217SJeff Kirsher 
1338adfc5217SJeff Kirsher 	/* enable access to nvram interface */
1339adfc5217SJeff Kirsher 	bnx2x_enable_nvram_access(bp);
1340adfc5217SJeff Kirsher 
1341adfc5217SJeff Kirsher 	/* read the first word(s) */
1342adfc5217SJeff Kirsher 	cmd_flags = MCPR_NVM_COMMAND_FIRST;
1343adfc5217SJeff Kirsher 	while ((buf_size > sizeof(u32)) && (rc == 0)) {
1344adfc5217SJeff Kirsher 		rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags);
1345adfc5217SJeff Kirsher 		memcpy(ret_buf, &val, 4);
1346adfc5217SJeff Kirsher 
1347adfc5217SJeff Kirsher 		/* advance to the next dword */
1348adfc5217SJeff Kirsher 		offset += sizeof(u32);
1349adfc5217SJeff Kirsher 		ret_buf += sizeof(u32);
1350adfc5217SJeff Kirsher 		buf_size -= sizeof(u32);
1351adfc5217SJeff Kirsher 		cmd_flags = 0;
1352adfc5217SJeff Kirsher 	}
1353adfc5217SJeff Kirsher 
1354adfc5217SJeff Kirsher 	if (rc == 0) {
1355adfc5217SJeff Kirsher 		cmd_flags |= MCPR_NVM_COMMAND_LAST;
1356adfc5217SJeff Kirsher 		rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags);
1357adfc5217SJeff Kirsher 		memcpy(ret_buf, &val, 4);
1358adfc5217SJeff Kirsher 	}
1359adfc5217SJeff Kirsher 
1360adfc5217SJeff Kirsher 	/* disable access to nvram interface */
1361adfc5217SJeff Kirsher 	bnx2x_disable_nvram_access(bp);
1362adfc5217SJeff Kirsher 	bnx2x_release_nvram_lock(bp);
1363adfc5217SJeff Kirsher 
1364adfc5217SJeff Kirsher 	return rc;
1365adfc5217SJeff Kirsher }
1366adfc5217SJeff Kirsher 
136785640952SDmitry Kravkov static int bnx2x_nvram_read32(struct bnx2x *bp, u32 offset, u32 *buf,
136885640952SDmitry Kravkov 			      int buf_size)
136985640952SDmitry Kravkov {
137085640952SDmitry Kravkov 	int rc;
137185640952SDmitry Kravkov 
137285640952SDmitry Kravkov 	rc = bnx2x_nvram_read(bp, offset, (u8 *)buf, buf_size);
137385640952SDmitry Kravkov 
137485640952SDmitry Kravkov 	if (!rc) {
137585640952SDmitry Kravkov 		__be32 *be = (__be32 *)buf;
137685640952SDmitry Kravkov 
137785640952SDmitry Kravkov 		while ((buf_size -= 4) >= 0)
137885640952SDmitry Kravkov 			*buf++ = be32_to_cpu(*be++);
137985640952SDmitry Kravkov 	}
138085640952SDmitry Kravkov 
138185640952SDmitry Kravkov 	return rc;
138285640952SDmitry Kravkov }
138385640952SDmitry Kravkov 
1384adfc5217SJeff Kirsher static int bnx2x_get_eeprom(struct net_device *dev,
1385adfc5217SJeff Kirsher 			    struct ethtool_eeprom *eeprom, u8 *eebuf)
1386adfc5217SJeff Kirsher {
1387adfc5217SJeff Kirsher 	struct bnx2x *bp = netdev_priv(dev);
1388adfc5217SJeff Kirsher 	int rc;
1389adfc5217SJeff Kirsher 
139051c1a580SMerav Sicron 	if (!netif_running(dev)) {
139151c1a580SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL  | BNX2X_MSG_NVM,
139251c1a580SMerav Sicron 		   "cannot access eeprom when the interface is down\n");
1393adfc5217SJeff Kirsher 		return -EAGAIN;
139451c1a580SMerav Sicron 	}
1395adfc5217SJeff Kirsher 
139651c1a580SMerav Sicron 	DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n"
1397f1deab50SJoe Perches 	   "  magic 0x%x  offset 0x%x (%d)  len 0x%x (%d)\n",
1398adfc5217SJeff Kirsher 	   eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset,
1399adfc5217SJeff Kirsher 	   eeprom->len, eeprom->len);
1400adfc5217SJeff Kirsher 
1401adfc5217SJeff Kirsher 	/* parameters already validated in ethtool_get_eeprom */
1402adfc5217SJeff Kirsher 
1403adfc5217SJeff Kirsher 	rc = bnx2x_nvram_read(bp, eeprom->offset, eebuf, eeprom->len);
1404adfc5217SJeff Kirsher 
1405adfc5217SJeff Kirsher 	return rc;
1406adfc5217SJeff Kirsher }
1407adfc5217SJeff Kirsher 
140824ea818eSYuval Mintz static int bnx2x_get_module_eeprom(struct net_device *dev,
140924ea818eSYuval Mintz 				   struct ethtool_eeprom *ee,
141024ea818eSYuval Mintz 				   u8 *data)
141124ea818eSYuval Mintz {
141224ea818eSYuval Mintz 	struct bnx2x *bp = netdev_priv(dev);
1413669d6996SYaniv Rosner 	int rc = -EINVAL, phy_idx;
141424ea818eSYuval Mintz 	u8 *user_data = data;
1415669d6996SYaniv Rosner 	unsigned int start_addr = ee->offset, xfer_size = 0;
141624ea818eSYuval Mintz 
141724ea818eSYuval Mintz 	if (!netif_running(dev)) {
141824ea818eSYuval Mintz 		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
141924ea818eSYuval Mintz 		   "cannot access eeprom when the interface is down\n");
142024ea818eSYuval Mintz 		return -EAGAIN;
142124ea818eSYuval Mintz 	}
142224ea818eSYuval Mintz 
142324ea818eSYuval Mintz 	phy_idx = bnx2x_get_cur_phy_idx(bp);
1424669d6996SYaniv Rosner 
1425669d6996SYaniv Rosner 	/* Read A0 section */
1426669d6996SYaniv Rosner 	if (start_addr < ETH_MODULE_SFF_8079_LEN) {
1427669d6996SYaniv Rosner 		/* Limit transfer size to the A0 section boundary */
1428669d6996SYaniv Rosner 		if (start_addr + ee->len > ETH_MODULE_SFF_8079_LEN)
1429669d6996SYaniv Rosner 			xfer_size = ETH_MODULE_SFF_8079_LEN - start_addr;
1430669d6996SYaniv Rosner 		else
1431669d6996SYaniv Rosner 			xfer_size = ee->len;
143224ea818eSYuval Mintz 		bnx2x_acquire_phy_lock(bp);
143324ea818eSYuval Mintz 		rc = bnx2x_read_sfp_module_eeprom(&bp->link_params.phy[phy_idx],
143424ea818eSYuval Mintz 						  &bp->link_params,
1435669d6996SYaniv Rosner 						  I2C_DEV_ADDR_A0,
1436669d6996SYaniv Rosner 						  start_addr,
143724ea818eSYuval Mintz 						  xfer_size,
143824ea818eSYuval Mintz 						  user_data);
1439669d6996SYaniv Rosner 		bnx2x_release_phy_lock(bp);
1440669d6996SYaniv Rosner 		if (rc) {
1441669d6996SYaniv Rosner 			DP(BNX2X_MSG_ETHTOOL, "Failed reading A0 section\n");
1442669d6996SYaniv Rosner 
1443669d6996SYaniv Rosner 			return -EINVAL;
1444669d6996SYaniv Rosner 		}
144524ea818eSYuval Mintz 		user_data += xfer_size;
1446669d6996SYaniv Rosner 		start_addr += xfer_size;
144724ea818eSYuval Mintz 	}
144824ea818eSYuval Mintz 
1449669d6996SYaniv Rosner 	/* Read A2 section */
1450669d6996SYaniv Rosner 	if ((start_addr >= ETH_MODULE_SFF_8079_LEN) &&
1451669d6996SYaniv Rosner 	    (start_addr < ETH_MODULE_SFF_8472_LEN)) {
1452669d6996SYaniv Rosner 		xfer_size = ee->len - xfer_size;
1453669d6996SYaniv Rosner 		/* Limit transfer size to the A2 section boundary */
1454669d6996SYaniv Rosner 		if (start_addr + xfer_size > ETH_MODULE_SFF_8472_LEN)
1455669d6996SYaniv Rosner 			xfer_size = ETH_MODULE_SFF_8472_LEN - start_addr;
1456669d6996SYaniv Rosner 		start_addr -= ETH_MODULE_SFF_8079_LEN;
1457669d6996SYaniv Rosner 		bnx2x_acquire_phy_lock(bp);
1458669d6996SYaniv Rosner 		rc = bnx2x_read_sfp_module_eeprom(&bp->link_params.phy[phy_idx],
1459669d6996SYaniv Rosner 						  &bp->link_params,
1460669d6996SYaniv Rosner 						  I2C_DEV_ADDR_A2,
1461669d6996SYaniv Rosner 						  start_addr,
1462669d6996SYaniv Rosner 						  xfer_size,
1463669d6996SYaniv Rosner 						  user_data);
146424ea818eSYuval Mintz 		bnx2x_release_phy_lock(bp);
1465669d6996SYaniv Rosner 		if (rc) {
1466669d6996SYaniv Rosner 			DP(BNX2X_MSG_ETHTOOL, "Failed reading A2 section\n");
1467669d6996SYaniv Rosner 			return -EINVAL;
1468669d6996SYaniv Rosner 		}
1469669d6996SYaniv Rosner 	}
147024ea818eSYuval Mintz 	return rc;
147124ea818eSYuval Mintz }
147224ea818eSYuval Mintz 
147324ea818eSYuval Mintz static int bnx2x_get_module_info(struct net_device *dev,
147424ea818eSYuval Mintz 				 struct ethtool_modinfo *modinfo)
147524ea818eSYuval Mintz {
147624ea818eSYuval Mintz 	struct bnx2x *bp = netdev_priv(dev);
1477669d6996SYaniv Rosner 	int phy_idx, rc;
1478669d6996SYaniv Rosner 	u8 sff8472_comp, diag_type;
1479669d6996SYaniv Rosner 
148024ea818eSYuval Mintz 	if (!netif_running(dev)) {
148124ea818eSYuval Mintz 		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
148224ea818eSYuval Mintz 		   "cannot access eeprom when the interface is down\n");
148324ea818eSYuval Mintz 		return -EAGAIN;
148424ea818eSYuval Mintz 	}
148524ea818eSYuval Mintz 	phy_idx = bnx2x_get_cur_phy_idx(bp);
1486669d6996SYaniv Rosner 	bnx2x_acquire_phy_lock(bp);
1487669d6996SYaniv Rosner 	rc = bnx2x_read_sfp_module_eeprom(&bp->link_params.phy[phy_idx],
1488669d6996SYaniv Rosner 					  &bp->link_params,
1489669d6996SYaniv Rosner 					  I2C_DEV_ADDR_A0,
1490669d6996SYaniv Rosner 					  SFP_EEPROM_SFF_8472_COMP_ADDR,
1491669d6996SYaniv Rosner 					  SFP_EEPROM_SFF_8472_COMP_SIZE,
1492669d6996SYaniv Rosner 					  &sff8472_comp);
1493669d6996SYaniv Rosner 	bnx2x_release_phy_lock(bp);
1494669d6996SYaniv Rosner 	if (rc) {
1495669d6996SYaniv Rosner 		DP(BNX2X_MSG_ETHTOOL, "Failed reading SFF-8472 comp field\n");
1496669d6996SYaniv Rosner 		return -EINVAL;
1497669d6996SYaniv Rosner 	}
1498669d6996SYaniv Rosner 
1499669d6996SYaniv Rosner 	bnx2x_acquire_phy_lock(bp);
1500669d6996SYaniv Rosner 	rc = bnx2x_read_sfp_module_eeprom(&bp->link_params.phy[phy_idx],
1501669d6996SYaniv Rosner 					  &bp->link_params,
1502669d6996SYaniv Rosner 					  I2C_DEV_ADDR_A0,
1503669d6996SYaniv Rosner 					  SFP_EEPROM_DIAG_TYPE_ADDR,
1504669d6996SYaniv Rosner 					  SFP_EEPROM_DIAG_TYPE_SIZE,
1505669d6996SYaniv Rosner 					  &diag_type);
1506669d6996SYaniv Rosner 	bnx2x_release_phy_lock(bp);
1507669d6996SYaniv Rosner 	if (rc) {
1508669d6996SYaniv Rosner 		DP(BNX2X_MSG_ETHTOOL, "Failed reading Diag Type field\n");
1509669d6996SYaniv Rosner 		return -EINVAL;
1510669d6996SYaniv Rosner 	}
1511669d6996SYaniv Rosner 
1512669d6996SYaniv Rosner 	if (!sff8472_comp ||
1513669d6996SYaniv Rosner 	    (diag_type & SFP_EEPROM_DIAG_ADDR_CHANGE_REQ)) {
151424ea818eSYuval Mintz 		modinfo->type = ETH_MODULE_SFF_8079;
151524ea818eSYuval Mintz 		modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
1516669d6996SYaniv Rosner 	} else {
1517669d6996SYaniv Rosner 		modinfo->type = ETH_MODULE_SFF_8472;
1518669d6996SYaniv Rosner 		modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
151924ea818eSYuval Mintz 	}
1520669d6996SYaniv Rosner 	return 0;
152124ea818eSYuval Mintz }
152224ea818eSYuval Mintz 
1523adfc5217SJeff Kirsher static int bnx2x_nvram_write_dword(struct bnx2x *bp, u32 offset, u32 val,
1524adfc5217SJeff Kirsher 				   u32 cmd_flags)
1525adfc5217SJeff Kirsher {
1526adfc5217SJeff Kirsher 	int count, i, rc;
1527adfc5217SJeff Kirsher 
1528adfc5217SJeff Kirsher 	/* build the command word */
1529adfc5217SJeff Kirsher 	cmd_flags |= MCPR_NVM_COMMAND_DOIT | MCPR_NVM_COMMAND_WR;
1530adfc5217SJeff Kirsher 
1531adfc5217SJeff Kirsher 	/* need to clear DONE bit separately */
1532adfc5217SJeff Kirsher 	REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
1533adfc5217SJeff Kirsher 
1534adfc5217SJeff Kirsher 	/* write the data */
1535adfc5217SJeff Kirsher 	REG_WR(bp, MCP_REG_MCPR_NVM_WRITE, val);
1536adfc5217SJeff Kirsher 
1537adfc5217SJeff Kirsher 	/* address of the NVRAM to write to */
1538adfc5217SJeff Kirsher 	REG_WR(bp, MCP_REG_MCPR_NVM_ADDR,
1539adfc5217SJeff Kirsher 	       (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
1540adfc5217SJeff Kirsher 
1541adfc5217SJeff Kirsher 	/* issue the write command */
1542adfc5217SJeff Kirsher 	REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
1543adfc5217SJeff Kirsher 
1544adfc5217SJeff Kirsher 	/* adjust timeout for emulation/FPGA */
1545adfc5217SJeff Kirsher 	count = BNX2X_NVRAM_TIMEOUT_COUNT;
1546adfc5217SJeff Kirsher 	if (CHIP_REV_IS_SLOW(bp))
1547adfc5217SJeff Kirsher 		count *= 100;
1548adfc5217SJeff Kirsher 
1549adfc5217SJeff Kirsher 	/* wait for completion */
1550adfc5217SJeff Kirsher 	rc = -EBUSY;
1551adfc5217SJeff Kirsher 	for (i = 0; i < count; i++) {
1552adfc5217SJeff Kirsher 		udelay(5);
1553adfc5217SJeff Kirsher 		val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND);
1554adfc5217SJeff Kirsher 		if (val & MCPR_NVM_COMMAND_DONE) {
1555adfc5217SJeff Kirsher 			rc = 0;
1556adfc5217SJeff Kirsher 			break;
1557adfc5217SJeff Kirsher 		}
1558adfc5217SJeff Kirsher 	}
1559adfc5217SJeff Kirsher 
156051c1a580SMerav Sicron 	if (rc == -EBUSY)
156151c1a580SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
156251c1a580SMerav Sicron 		   "nvram write timeout expired\n");
1563adfc5217SJeff Kirsher 	return rc;
1564adfc5217SJeff Kirsher }
1565adfc5217SJeff Kirsher 
1566adfc5217SJeff Kirsher #define BYTE_OFFSET(offset)		(8 * (offset & 0x03))
1567adfc5217SJeff Kirsher 
1568adfc5217SJeff Kirsher static int bnx2x_nvram_write1(struct bnx2x *bp, u32 offset, u8 *data_buf,
1569adfc5217SJeff Kirsher 			      int buf_size)
1570adfc5217SJeff Kirsher {
1571adfc5217SJeff Kirsher 	int rc;
1572adfc5217SJeff Kirsher 	u32 cmd_flags;
1573adfc5217SJeff Kirsher 	u32 align_offset;
1574adfc5217SJeff Kirsher 	__be32 val;
1575adfc5217SJeff Kirsher 
1576adfc5217SJeff Kirsher 	if (offset + buf_size > bp->common.flash_size) {
157751c1a580SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
157851c1a580SMerav Sicron 		   "Invalid parameter: offset (0x%x) + buf_size (0x%x) > flash_size (0x%x)\n",
1579adfc5217SJeff Kirsher 		   offset, buf_size, bp->common.flash_size);
1580adfc5217SJeff Kirsher 		return -EINVAL;
1581adfc5217SJeff Kirsher 	}
1582adfc5217SJeff Kirsher 
1583adfc5217SJeff Kirsher 	/* request access to nvram interface */
1584adfc5217SJeff Kirsher 	rc = bnx2x_acquire_nvram_lock(bp);
1585adfc5217SJeff Kirsher 	if (rc)
1586adfc5217SJeff Kirsher 		return rc;
1587adfc5217SJeff Kirsher 
1588adfc5217SJeff Kirsher 	/* enable access to nvram interface */
1589adfc5217SJeff Kirsher 	bnx2x_enable_nvram_access(bp);
1590adfc5217SJeff Kirsher 
1591adfc5217SJeff Kirsher 	cmd_flags = (MCPR_NVM_COMMAND_FIRST | MCPR_NVM_COMMAND_LAST);
1592adfc5217SJeff Kirsher 	align_offset = (offset & ~0x03);
1593adfc5217SJeff Kirsher 	rc = bnx2x_nvram_read_dword(bp, align_offset, &val, cmd_flags);
1594adfc5217SJeff Kirsher 
1595adfc5217SJeff Kirsher 	if (rc == 0) {
1596adfc5217SJeff Kirsher 		val &= ~(0xff << BYTE_OFFSET(offset));
1597adfc5217SJeff Kirsher 		val |= (*data_buf << BYTE_OFFSET(offset));
1598adfc5217SJeff Kirsher 
1599adfc5217SJeff Kirsher 		/* nvram data is returned as an array of bytes
160007ba6af4SMiriam Shitrit 		 * convert it back to cpu order
160107ba6af4SMiriam Shitrit 		 */
1602adfc5217SJeff Kirsher 		val = be32_to_cpu(val);
1603adfc5217SJeff Kirsher 
1604adfc5217SJeff Kirsher 		rc = bnx2x_nvram_write_dword(bp, align_offset, val,
1605adfc5217SJeff Kirsher 					     cmd_flags);
1606adfc5217SJeff Kirsher 	}
1607adfc5217SJeff Kirsher 
1608adfc5217SJeff Kirsher 	/* disable access to nvram interface */
1609adfc5217SJeff Kirsher 	bnx2x_disable_nvram_access(bp);
1610adfc5217SJeff Kirsher 	bnx2x_release_nvram_lock(bp);
1611adfc5217SJeff Kirsher 
1612adfc5217SJeff Kirsher 	return rc;
1613adfc5217SJeff Kirsher }
1614adfc5217SJeff Kirsher 
1615adfc5217SJeff Kirsher static int bnx2x_nvram_write(struct bnx2x *bp, u32 offset, u8 *data_buf,
1616adfc5217SJeff Kirsher 			     int buf_size)
1617adfc5217SJeff Kirsher {
1618adfc5217SJeff Kirsher 	int rc;
1619adfc5217SJeff Kirsher 	u32 cmd_flags;
1620adfc5217SJeff Kirsher 	u32 val;
1621adfc5217SJeff Kirsher 	u32 written_so_far;
1622adfc5217SJeff Kirsher 
1623adfc5217SJeff Kirsher 	if (buf_size == 1)	/* ethtool */
1624adfc5217SJeff Kirsher 		return bnx2x_nvram_write1(bp, offset, data_buf, buf_size);
1625adfc5217SJeff Kirsher 
1626adfc5217SJeff Kirsher 	if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
162751c1a580SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
1628adfc5217SJeff Kirsher 		   "Invalid parameter: offset 0x%x  buf_size 0x%x\n",
1629adfc5217SJeff Kirsher 		   offset, buf_size);
1630adfc5217SJeff Kirsher 		return -EINVAL;
1631adfc5217SJeff Kirsher 	}
1632adfc5217SJeff Kirsher 
1633adfc5217SJeff Kirsher 	if (offset + buf_size > bp->common.flash_size) {
163451c1a580SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
163551c1a580SMerav Sicron 		   "Invalid parameter: offset (0x%x) + buf_size (0x%x) > flash_size (0x%x)\n",
1636adfc5217SJeff Kirsher 		   offset, buf_size, bp->common.flash_size);
1637adfc5217SJeff Kirsher 		return -EINVAL;
1638adfc5217SJeff Kirsher 	}
1639adfc5217SJeff Kirsher 
1640adfc5217SJeff Kirsher 	/* request access to nvram interface */
1641adfc5217SJeff Kirsher 	rc = bnx2x_acquire_nvram_lock(bp);
1642adfc5217SJeff Kirsher 	if (rc)
1643adfc5217SJeff Kirsher 		return rc;
1644adfc5217SJeff Kirsher 
1645adfc5217SJeff Kirsher 	/* enable access to nvram interface */
1646adfc5217SJeff Kirsher 	bnx2x_enable_nvram_access(bp);
1647adfc5217SJeff Kirsher 
1648adfc5217SJeff Kirsher 	written_so_far = 0;
1649adfc5217SJeff Kirsher 	cmd_flags = MCPR_NVM_COMMAND_FIRST;
1650adfc5217SJeff Kirsher 	while ((written_so_far < buf_size) && (rc == 0)) {
1651adfc5217SJeff Kirsher 		if (written_so_far == (buf_size - sizeof(u32)))
1652adfc5217SJeff Kirsher 			cmd_flags |= MCPR_NVM_COMMAND_LAST;
1653adfc5217SJeff Kirsher 		else if (((offset + 4) % BNX2X_NVRAM_PAGE_SIZE) == 0)
1654adfc5217SJeff Kirsher 			cmd_flags |= MCPR_NVM_COMMAND_LAST;
1655adfc5217SJeff Kirsher 		else if ((offset % BNX2X_NVRAM_PAGE_SIZE) == 0)
1656adfc5217SJeff Kirsher 			cmd_flags |= MCPR_NVM_COMMAND_FIRST;
1657adfc5217SJeff Kirsher 
1658adfc5217SJeff Kirsher 		memcpy(&val, data_buf, 4);
1659adfc5217SJeff Kirsher 
1660adfc5217SJeff Kirsher 		rc = bnx2x_nvram_write_dword(bp, offset, val, cmd_flags);
1661adfc5217SJeff Kirsher 
1662adfc5217SJeff Kirsher 		/* advance to the next dword */
1663adfc5217SJeff Kirsher 		offset += sizeof(u32);
1664adfc5217SJeff Kirsher 		data_buf += sizeof(u32);
1665adfc5217SJeff Kirsher 		written_so_far += sizeof(u32);
1666adfc5217SJeff Kirsher 		cmd_flags = 0;
1667adfc5217SJeff Kirsher 	}
1668adfc5217SJeff Kirsher 
1669adfc5217SJeff Kirsher 	/* disable access to nvram interface */
1670adfc5217SJeff Kirsher 	bnx2x_disable_nvram_access(bp);
1671adfc5217SJeff Kirsher 	bnx2x_release_nvram_lock(bp);
1672adfc5217SJeff Kirsher 
1673adfc5217SJeff Kirsher 	return rc;
1674adfc5217SJeff Kirsher }
1675adfc5217SJeff Kirsher 
1676adfc5217SJeff Kirsher static int bnx2x_set_eeprom(struct net_device *dev,
1677adfc5217SJeff Kirsher 			    struct ethtool_eeprom *eeprom, u8 *eebuf)
1678adfc5217SJeff Kirsher {
1679adfc5217SJeff Kirsher 	struct bnx2x *bp = netdev_priv(dev);
1680adfc5217SJeff Kirsher 	int port = BP_PORT(bp);
1681adfc5217SJeff Kirsher 	int rc = 0;
1682adfc5217SJeff Kirsher 	u32 ext_phy_config;
168351c1a580SMerav Sicron 	if (!netif_running(dev)) {
168451c1a580SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
168551c1a580SMerav Sicron 		   "cannot access eeprom when the interface is down\n");
1686adfc5217SJeff Kirsher 		return -EAGAIN;
168751c1a580SMerav Sicron 	}
1688adfc5217SJeff Kirsher 
168951c1a580SMerav Sicron 	DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n"
1690f1deab50SJoe Perches 	   "  magic 0x%x  offset 0x%x (%d)  len 0x%x (%d)\n",
1691adfc5217SJeff Kirsher 	   eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset,
1692adfc5217SJeff Kirsher 	   eeprom->len, eeprom->len);
1693adfc5217SJeff Kirsher 
1694adfc5217SJeff Kirsher 	/* parameters already validated in ethtool_set_eeprom */
1695adfc5217SJeff Kirsher 
1696adfc5217SJeff Kirsher 	/* PHY eeprom can be accessed only by the PMF */
1697adfc5217SJeff Kirsher 	if ((eeprom->magic >= 0x50485900) && (eeprom->magic <= 0x504859FF) &&
169851c1a580SMerav Sicron 	    !bp->port.pmf) {
169951c1a580SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
170051c1a580SMerav Sicron 		   "wrong magic or interface is not pmf\n");
1701adfc5217SJeff Kirsher 		return -EINVAL;
170251c1a580SMerav Sicron 	}
1703adfc5217SJeff Kirsher 
1704adfc5217SJeff Kirsher 	ext_phy_config =
1705adfc5217SJeff Kirsher 		SHMEM_RD(bp,
1706adfc5217SJeff Kirsher 			 dev_info.port_hw_config[port].external_phy_config);
1707adfc5217SJeff Kirsher 
1708adfc5217SJeff Kirsher 	if (eeprom->magic == 0x50485950) {
1709adfc5217SJeff Kirsher 		/* 'PHYP' (0x50485950): prepare phy for FW upgrade */
1710adfc5217SJeff Kirsher 		bnx2x_stats_handle(bp, STATS_EVENT_STOP);
1711adfc5217SJeff Kirsher 
1712adfc5217SJeff Kirsher 		bnx2x_acquire_phy_lock(bp);
1713adfc5217SJeff Kirsher 		rc |= bnx2x_link_reset(&bp->link_params,
1714adfc5217SJeff Kirsher 				       &bp->link_vars, 0);
1715adfc5217SJeff Kirsher 		if (XGXS_EXT_PHY_TYPE(ext_phy_config) ==
1716adfc5217SJeff Kirsher 					PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101)
1717adfc5217SJeff Kirsher 			bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
1718adfc5217SJeff Kirsher 				       MISC_REGISTERS_GPIO_HIGH, port);
1719adfc5217SJeff Kirsher 		bnx2x_release_phy_lock(bp);
1720adfc5217SJeff Kirsher 		bnx2x_link_report(bp);
1721adfc5217SJeff Kirsher 
1722adfc5217SJeff Kirsher 	} else if (eeprom->magic == 0x50485952) {
1723adfc5217SJeff Kirsher 		/* 'PHYR' (0x50485952): re-init link after FW upgrade */
1724adfc5217SJeff Kirsher 		if (bp->state == BNX2X_STATE_OPEN) {
1725adfc5217SJeff Kirsher 			bnx2x_acquire_phy_lock(bp);
1726adfc5217SJeff Kirsher 			rc |= bnx2x_link_reset(&bp->link_params,
1727adfc5217SJeff Kirsher 					       &bp->link_vars, 1);
1728adfc5217SJeff Kirsher 
1729adfc5217SJeff Kirsher 			rc |= bnx2x_phy_init(&bp->link_params,
1730adfc5217SJeff Kirsher 					     &bp->link_vars);
1731adfc5217SJeff Kirsher 			bnx2x_release_phy_lock(bp);
1732adfc5217SJeff Kirsher 			bnx2x_calc_fc_adv(bp);
1733adfc5217SJeff Kirsher 		}
1734adfc5217SJeff Kirsher 	} else if (eeprom->magic == 0x53985943) {
1735adfc5217SJeff Kirsher 		/* 'PHYC' (0x53985943): PHY FW upgrade completed */
1736adfc5217SJeff Kirsher 		if (XGXS_EXT_PHY_TYPE(ext_phy_config) ==
1737adfc5217SJeff Kirsher 				       PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101) {
1738adfc5217SJeff Kirsher 
1739adfc5217SJeff Kirsher 			/* DSP Remove Download Mode */
1740adfc5217SJeff Kirsher 			bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
1741adfc5217SJeff Kirsher 				       MISC_REGISTERS_GPIO_LOW, port);
1742adfc5217SJeff Kirsher 
1743adfc5217SJeff Kirsher 			bnx2x_acquire_phy_lock(bp);
1744adfc5217SJeff Kirsher 
1745adfc5217SJeff Kirsher 			bnx2x_sfx7101_sp_sw_reset(bp,
1746adfc5217SJeff Kirsher 						&bp->link_params.phy[EXT_PHY1]);
1747adfc5217SJeff Kirsher 
1748adfc5217SJeff Kirsher 			/* wait 0.5 sec to allow it to run */
1749adfc5217SJeff Kirsher 			msleep(500);
1750adfc5217SJeff Kirsher 			bnx2x_ext_phy_hw_reset(bp, port);
1751adfc5217SJeff Kirsher 			msleep(500);
1752adfc5217SJeff Kirsher 			bnx2x_release_phy_lock(bp);
1753adfc5217SJeff Kirsher 		}
1754adfc5217SJeff Kirsher 	} else
1755adfc5217SJeff Kirsher 		rc = bnx2x_nvram_write(bp, eeprom->offset, eebuf, eeprom->len);
1756adfc5217SJeff Kirsher 
1757adfc5217SJeff Kirsher 	return rc;
1758adfc5217SJeff Kirsher }
1759adfc5217SJeff Kirsher 
1760adfc5217SJeff Kirsher static int bnx2x_get_coalesce(struct net_device *dev,
1761adfc5217SJeff Kirsher 			      struct ethtool_coalesce *coal)
1762adfc5217SJeff Kirsher {
1763adfc5217SJeff Kirsher 	struct bnx2x *bp = netdev_priv(dev);
1764adfc5217SJeff Kirsher 
1765adfc5217SJeff Kirsher 	memset(coal, 0, sizeof(struct ethtool_coalesce));
1766adfc5217SJeff Kirsher 
1767adfc5217SJeff Kirsher 	coal->rx_coalesce_usecs = bp->rx_ticks;
1768adfc5217SJeff Kirsher 	coal->tx_coalesce_usecs = bp->tx_ticks;
1769adfc5217SJeff Kirsher 
1770adfc5217SJeff Kirsher 	return 0;
1771adfc5217SJeff Kirsher }
1772adfc5217SJeff Kirsher 
1773adfc5217SJeff Kirsher static int bnx2x_set_coalesce(struct net_device *dev,
1774adfc5217SJeff Kirsher 			      struct ethtool_coalesce *coal)
1775adfc5217SJeff Kirsher {
1776adfc5217SJeff Kirsher 	struct bnx2x *bp = netdev_priv(dev);
1777adfc5217SJeff Kirsher 
1778adfc5217SJeff Kirsher 	bp->rx_ticks = (u16)coal->rx_coalesce_usecs;
1779adfc5217SJeff Kirsher 	if (bp->rx_ticks > BNX2X_MAX_COALESCE_TOUT)
1780adfc5217SJeff Kirsher 		bp->rx_ticks = BNX2X_MAX_COALESCE_TOUT;
1781adfc5217SJeff Kirsher 
1782adfc5217SJeff Kirsher 	bp->tx_ticks = (u16)coal->tx_coalesce_usecs;
1783adfc5217SJeff Kirsher 	if (bp->tx_ticks > BNX2X_MAX_COALESCE_TOUT)
1784adfc5217SJeff Kirsher 		bp->tx_ticks = BNX2X_MAX_COALESCE_TOUT;
1785adfc5217SJeff Kirsher 
1786adfc5217SJeff Kirsher 	if (netif_running(dev))
1787adfc5217SJeff Kirsher 		bnx2x_update_coalesce(bp);
1788adfc5217SJeff Kirsher 
1789adfc5217SJeff Kirsher 	return 0;
1790adfc5217SJeff Kirsher }
1791adfc5217SJeff Kirsher 
1792adfc5217SJeff Kirsher static void bnx2x_get_ringparam(struct net_device *dev,
1793adfc5217SJeff Kirsher 				struct ethtool_ringparam *ering)
1794adfc5217SJeff Kirsher {
1795adfc5217SJeff Kirsher 	struct bnx2x *bp = netdev_priv(dev);
1796adfc5217SJeff Kirsher 
1797adfc5217SJeff Kirsher 	ering->rx_max_pending = MAX_RX_AVAIL;
1798adfc5217SJeff Kirsher 
1799adfc5217SJeff Kirsher 	if (bp->rx_ring_size)
1800adfc5217SJeff Kirsher 		ering->rx_pending = bp->rx_ring_size;
1801adfc5217SJeff Kirsher 	else
1802adfc5217SJeff Kirsher 		ering->rx_pending = MAX_RX_AVAIL;
1803adfc5217SJeff Kirsher 
1804a3348722SBarak Witkowski 	ering->tx_max_pending = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
1805adfc5217SJeff Kirsher 	ering->tx_pending = bp->tx_ring_size;
1806adfc5217SJeff Kirsher }
1807adfc5217SJeff Kirsher 
1808adfc5217SJeff Kirsher static int bnx2x_set_ringparam(struct net_device *dev,
1809adfc5217SJeff Kirsher 			       struct ethtool_ringparam *ering)
1810adfc5217SJeff Kirsher {
1811adfc5217SJeff Kirsher 	struct bnx2x *bp = netdev_priv(dev);
1812adfc5217SJeff Kirsher 
181304c46736SYuval Mintz 	DP(BNX2X_MSG_ETHTOOL,
181404c46736SYuval Mintz 	   "set ring params command parameters: rx_pending = %d, tx_pending = %d\n",
181504c46736SYuval Mintz 	   ering->rx_pending, ering->tx_pending);
181604c46736SYuval Mintz 
1817adfc5217SJeff Kirsher 	if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
181851c1a580SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL,
181951c1a580SMerav Sicron 		   "Handling parity error recovery. Try again later\n");
1820adfc5217SJeff Kirsher 		return -EAGAIN;
1821adfc5217SJeff Kirsher 	}
1822adfc5217SJeff Kirsher 
1823adfc5217SJeff Kirsher 	if ((ering->rx_pending > MAX_RX_AVAIL) ||
1824adfc5217SJeff Kirsher 	    (ering->rx_pending < (bp->disable_tpa ? MIN_RX_SIZE_NONTPA :
1825adfc5217SJeff Kirsher 						    MIN_RX_SIZE_TPA)) ||
1826a3348722SBarak Witkowski 	    (ering->tx_pending > (IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL)) ||
182751c1a580SMerav Sicron 	    (ering->tx_pending <= MAX_SKB_FRAGS + 4)) {
182851c1a580SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL, "Command parameters not supported\n");
1829adfc5217SJeff Kirsher 		return -EINVAL;
183051c1a580SMerav Sicron 	}
1831adfc5217SJeff Kirsher 
1832adfc5217SJeff Kirsher 	bp->rx_ring_size = ering->rx_pending;
1833adfc5217SJeff Kirsher 	bp->tx_ring_size = ering->tx_pending;
1834adfc5217SJeff Kirsher 
1835adfc5217SJeff Kirsher 	return bnx2x_reload_if_running(dev);
1836adfc5217SJeff Kirsher }
1837adfc5217SJeff Kirsher 
1838adfc5217SJeff Kirsher static void bnx2x_get_pauseparam(struct net_device *dev,
1839adfc5217SJeff Kirsher 				 struct ethtool_pauseparam *epause)
1840adfc5217SJeff Kirsher {
1841adfc5217SJeff Kirsher 	struct bnx2x *bp = netdev_priv(dev);
1842adfc5217SJeff Kirsher 	int cfg_idx = bnx2x_get_link_cfg_idx(bp);
18439e7e8399SMintz Yuval 	int cfg_reg;
18449e7e8399SMintz Yuval 
1845adfc5217SJeff Kirsher 	epause->autoneg = (bp->link_params.req_flow_ctrl[cfg_idx] ==
1846adfc5217SJeff Kirsher 			   BNX2X_FLOW_CTRL_AUTO);
1847adfc5217SJeff Kirsher 
18489e7e8399SMintz Yuval 	if (!epause->autoneg)
1849241fb5d2SYuval Mintz 		cfg_reg = bp->link_params.req_flow_ctrl[cfg_idx];
18509e7e8399SMintz Yuval 	else
18519e7e8399SMintz Yuval 		cfg_reg = bp->link_params.req_fc_auto_adv;
18529e7e8399SMintz Yuval 
18539e7e8399SMintz Yuval 	epause->rx_pause = ((cfg_reg & BNX2X_FLOW_CTRL_RX) ==
1854adfc5217SJeff Kirsher 			    BNX2X_FLOW_CTRL_RX);
18559e7e8399SMintz Yuval 	epause->tx_pause = ((cfg_reg & BNX2X_FLOW_CTRL_TX) ==
1856adfc5217SJeff Kirsher 			    BNX2X_FLOW_CTRL_TX);
1857adfc5217SJeff Kirsher 
185851c1a580SMerav Sicron 	DP(BNX2X_MSG_ETHTOOL, "ethtool_pauseparam: cmd %d\n"
1859f1deab50SJoe Perches 	   "  autoneg %d  rx_pause %d  tx_pause %d\n",
1860adfc5217SJeff Kirsher 	   epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);
1861adfc5217SJeff Kirsher }
1862adfc5217SJeff Kirsher 
1863adfc5217SJeff Kirsher static int bnx2x_set_pauseparam(struct net_device *dev,
1864adfc5217SJeff Kirsher 				struct ethtool_pauseparam *epause)
1865adfc5217SJeff Kirsher {
1866adfc5217SJeff Kirsher 	struct bnx2x *bp = netdev_priv(dev);
1867adfc5217SJeff Kirsher 	u32 cfg_idx = bnx2x_get_link_cfg_idx(bp);
1868adfc5217SJeff Kirsher 	if (IS_MF(bp))
1869adfc5217SJeff Kirsher 		return 0;
1870adfc5217SJeff Kirsher 
187151c1a580SMerav Sicron 	DP(BNX2X_MSG_ETHTOOL, "ethtool_pauseparam: cmd %d\n"
1872f1deab50SJoe Perches 	   "  autoneg %d  rx_pause %d  tx_pause %d\n",
1873adfc5217SJeff Kirsher 	   epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);
1874adfc5217SJeff Kirsher 
1875adfc5217SJeff Kirsher 	bp->link_params.req_flow_ctrl[cfg_idx] = BNX2X_FLOW_CTRL_AUTO;
1876adfc5217SJeff Kirsher 
1877adfc5217SJeff Kirsher 	if (epause->rx_pause)
1878adfc5217SJeff Kirsher 		bp->link_params.req_flow_ctrl[cfg_idx] |= BNX2X_FLOW_CTRL_RX;
1879adfc5217SJeff Kirsher 
1880adfc5217SJeff Kirsher 	if (epause->tx_pause)
1881adfc5217SJeff Kirsher 		bp->link_params.req_flow_ctrl[cfg_idx] |= BNX2X_FLOW_CTRL_TX;
1882adfc5217SJeff Kirsher 
1883adfc5217SJeff Kirsher 	if (bp->link_params.req_flow_ctrl[cfg_idx] == BNX2X_FLOW_CTRL_AUTO)
1884adfc5217SJeff Kirsher 		bp->link_params.req_flow_ctrl[cfg_idx] = BNX2X_FLOW_CTRL_NONE;
1885adfc5217SJeff Kirsher 
1886adfc5217SJeff Kirsher 	if (epause->autoneg) {
1887adfc5217SJeff Kirsher 		if (!(bp->port.supported[cfg_idx] & SUPPORTED_Autoneg)) {
188851c1a580SMerav Sicron 			DP(BNX2X_MSG_ETHTOOL, "autoneg not supported\n");
1889adfc5217SJeff Kirsher 			return -EINVAL;
1890adfc5217SJeff Kirsher 		}
1891adfc5217SJeff Kirsher 
1892adfc5217SJeff Kirsher 		if (bp->link_params.req_line_speed[cfg_idx] == SPEED_AUTO_NEG) {
1893adfc5217SJeff Kirsher 			bp->link_params.req_flow_ctrl[cfg_idx] =
1894adfc5217SJeff Kirsher 				BNX2X_FLOW_CTRL_AUTO;
1895adfc5217SJeff Kirsher 		}
18965cd75f0cSYaniv Rosner 		bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_NONE;
18975cd75f0cSYaniv Rosner 		if (epause->rx_pause)
18985cd75f0cSYaniv Rosner 			bp->link_params.req_fc_auto_adv |= BNX2X_FLOW_CTRL_RX;
18995cd75f0cSYaniv Rosner 
19005cd75f0cSYaniv Rosner 		if (epause->tx_pause)
19015cd75f0cSYaniv Rosner 			bp->link_params.req_fc_auto_adv |= BNX2X_FLOW_CTRL_TX;
1902adfc5217SJeff Kirsher 	}
1903adfc5217SJeff Kirsher 
190451c1a580SMerav Sicron 	DP(BNX2X_MSG_ETHTOOL,
1905adfc5217SJeff Kirsher 	   "req_flow_ctrl 0x%x\n", bp->link_params.req_flow_ctrl[cfg_idx]);
1906adfc5217SJeff Kirsher 
1907adfc5217SJeff Kirsher 	if (netif_running(dev)) {
1908adfc5217SJeff Kirsher 		bnx2x_stats_handle(bp, STATS_EVENT_STOP);
1909adfc5217SJeff Kirsher 		bnx2x_link_set(bp);
1910adfc5217SJeff Kirsher 	}
1911adfc5217SJeff Kirsher 
1912adfc5217SJeff Kirsher 	return 0;
1913adfc5217SJeff Kirsher }
1914adfc5217SJeff Kirsher 
19155889335cSMerav Sicron static const char bnx2x_tests_str_arr[BNX2X_NUM_TESTS_SF][ETH_GSTRING_LEN] = {
1916cf2c1df6SMerav Sicron 	"register_test (offline)    ",
1917cf2c1df6SMerav Sicron 	"memory_test (offline)      ",
1918cf2c1df6SMerav Sicron 	"int_loopback_test (offline)",
1919cf2c1df6SMerav Sicron 	"ext_loopback_test (offline)",
1920cf2c1df6SMerav Sicron 	"nvram_test (online)        ",
1921cf2c1df6SMerav Sicron 	"interrupt_test (online)    ",
1922cf2c1df6SMerav Sicron 	"link_test (online)         "
1923adfc5217SJeff Kirsher };
1924adfc5217SJeff Kirsher 
1925e9939c80SYuval Mintz static u32 bnx2x_eee_to_adv(u32 eee_adv)
1926e9939c80SYuval Mintz {
1927e9939c80SYuval Mintz 	u32 modes = 0;
1928e9939c80SYuval Mintz 
1929e9939c80SYuval Mintz 	if (eee_adv & SHMEM_EEE_100M_ADV)
1930e9939c80SYuval Mintz 		modes |= ADVERTISED_100baseT_Full;
1931e9939c80SYuval Mintz 	if (eee_adv & SHMEM_EEE_1G_ADV)
1932e9939c80SYuval Mintz 		modes |= ADVERTISED_1000baseT_Full;
1933e9939c80SYuval Mintz 	if (eee_adv & SHMEM_EEE_10G_ADV)
1934e9939c80SYuval Mintz 		modes |= ADVERTISED_10000baseT_Full;
1935e9939c80SYuval Mintz 
1936e9939c80SYuval Mintz 	return modes;
1937e9939c80SYuval Mintz }
1938e9939c80SYuval Mintz 
1939e9939c80SYuval Mintz static u32 bnx2x_adv_to_eee(u32 modes, u32 shift)
1940e9939c80SYuval Mintz {
1941e9939c80SYuval Mintz 	u32 eee_adv = 0;
1942e9939c80SYuval Mintz 	if (modes & ADVERTISED_100baseT_Full)
1943e9939c80SYuval Mintz 		eee_adv |= SHMEM_EEE_100M_ADV;
1944e9939c80SYuval Mintz 	if (modes & ADVERTISED_1000baseT_Full)
1945e9939c80SYuval Mintz 		eee_adv |= SHMEM_EEE_1G_ADV;
1946e9939c80SYuval Mintz 	if (modes & ADVERTISED_10000baseT_Full)
1947e9939c80SYuval Mintz 		eee_adv |= SHMEM_EEE_10G_ADV;
1948e9939c80SYuval Mintz 
1949e9939c80SYuval Mintz 	return eee_adv << shift;
1950e9939c80SYuval Mintz }
1951e9939c80SYuval Mintz 
1952e9939c80SYuval Mintz static int bnx2x_get_eee(struct net_device *dev, struct ethtool_eee *edata)
1953e9939c80SYuval Mintz {
1954e9939c80SYuval Mintz 	struct bnx2x *bp = netdev_priv(dev);
1955e9939c80SYuval Mintz 	u32 eee_cfg;
1956e9939c80SYuval Mintz 
1957e9939c80SYuval Mintz 	if (!SHMEM2_HAS(bp, eee_status[BP_PORT(bp)])) {
1958e9939c80SYuval Mintz 		DP(BNX2X_MSG_ETHTOOL, "BC Version does not support EEE\n");
1959e9939c80SYuval Mintz 		return -EOPNOTSUPP;
1960e9939c80SYuval Mintz 	}
1961e9939c80SYuval Mintz 
196208e9acc2SYuval Mintz 	eee_cfg = bp->link_vars.eee_status;
1963e9939c80SYuval Mintz 
1964e9939c80SYuval Mintz 	edata->supported =
1965e9939c80SYuval Mintz 		bnx2x_eee_to_adv((eee_cfg & SHMEM_EEE_SUPPORTED_MASK) >>
1966e9939c80SYuval Mintz 				 SHMEM_EEE_SUPPORTED_SHIFT);
1967e9939c80SYuval Mintz 
1968e9939c80SYuval Mintz 	edata->advertised =
1969e9939c80SYuval Mintz 		bnx2x_eee_to_adv((eee_cfg & SHMEM_EEE_ADV_STATUS_MASK) >>
1970e9939c80SYuval Mintz 				 SHMEM_EEE_ADV_STATUS_SHIFT);
1971e9939c80SYuval Mintz 	edata->lp_advertised =
1972e9939c80SYuval Mintz 		bnx2x_eee_to_adv((eee_cfg & SHMEM_EEE_LP_ADV_STATUS_MASK) >>
1973e9939c80SYuval Mintz 				 SHMEM_EEE_LP_ADV_STATUS_SHIFT);
1974e9939c80SYuval Mintz 
1975e9939c80SYuval Mintz 	/* SHMEM value is in 16u units --> Convert to 1u units. */
1976e9939c80SYuval Mintz 	edata->tx_lpi_timer = (eee_cfg & SHMEM_EEE_TIMER_MASK) << 4;
1977e9939c80SYuval Mintz 
1978e9939c80SYuval Mintz 	edata->eee_enabled    = (eee_cfg & SHMEM_EEE_REQUESTED_BIT)	? 1 : 0;
1979e9939c80SYuval Mintz 	edata->eee_active     = (eee_cfg & SHMEM_EEE_ACTIVE_BIT)	? 1 : 0;
1980e9939c80SYuval Mintz 	edata->tx_lpi_enabled = (eee_cfg & SHMEM_EEE_LPI_REQUESTED_BIT) ? 1 : 0;
1981e9939c80SYuval Mintz 
1982e9939c80SYuval Mintz 	return 0;
1983e9939c80SYuval Mintz }
1984e9939c80SYuval Mintz 
1985e9939c80SYuval Mintz static int bnx2x_set_eee(struct net_device *dev, struct ethtool_eee *edata)
1986e9939c80SYuval Mintz {
1987e9939c80SYuval Mintz 	struct bnx2x *bp = netdev_priv(dev);
1988e9939c80SYuval Mintz 	u32 eee_cfg;
1989e9939c80SYuval Mintz 	u32 advertised;
1990e9939c80SYuval Mintz 
1991e9939c80SYuval Mintz 	if (IS_MF(bp))
1992e9939c80SYuval Mintz 		return 0;
1993e9939c80SYuval Mintz 
1994e9939c80SYuval Mintz 	if (!SHMEM2_HAS(bp, eee_status[BP_PORT(bp)])) {
1995e9939c80SYuval Mintz 		DP(BNX2X_MSG_ETHTOOL, "BC Version does not support EEE\n");
1996e9939c80SYuval Mintz 		return -EOPNOTSUPP;
1997e9939c80SYuval Mintz 	}
1998e9939c80SYuval Mintz 
199908e9acc2SYuval Mintz 	eee_cfg = bp->link_vars.eee_status;
2000e9939c80SYuval Mintz 
2001e9939c80SYuval Mintz 	if (!(eee_cfg & SHMEM_EEE_SUPPORTED_MASK)) {
2002e9939c80SYuval Mintz 		DP(BNX2X_MSG_ETHTOOL, "Board does not support EEE!\n");
2003e9939c80SYuval Mintz 		return -EOPNOTSUPP;
2004e9939c80SYuval Mintz 	}
2005e9939c80SYuval Mintz 
2006e9939c80SYuval Mintz 	advertised = bnx2x_adv_to_eee(edata->advertised,
2007e9939c80SYuval Mintz 				      SHMEM_EEE_ADV_STATUS_SHIFT);
2008e9939c80SYuval Mintz 	if ((advertised != (eee_cfg & SHMEM_EEE_ADV_STATUS_MASK))) {
2009e9939c80SYuval Mintz 		DP(BNX2X_MSG_ETHTOOL,
2010efc7ce03SMasanari Iida 		   "Direct manipulation of EEE advertisement is not supported\n");
2011e9939c80SYuval Mintz 		return -EINVAL;
2012e9939c80SYuval Mintz 	}
2013e9939c80SYuval Mintz 
2014e9939c80SYuval Mintz 	if (edata->tx_lpi_timer > EEE_MODE_TIMER_MASK) {
2015e9939c80SYuval Mintz 		DP(BNX2X_MSG_ETHTOOL,
2016e9939c80SYuval Mintz 		   "Maximal Tx Lpi timer supported is %x(u)\n",
2017e9939c80SYuval Mintz 		   EEE_MODE_TIMER_MASK);
2018e9939c80SYuval Mintz 		return -EINVAL;
2019e9939c80SYuval Mintz 	}
2020e9939c80SYuval Mintz 	if (edata->tx_lpi_enabled &&
2021e9939c80SYuval Mintz 	    (edata->tx_lpi_timer < EEE_MODE_NVRAM_AGGRESSIVE_TIME)) {
2022e9939c80SYuval Mintz 		DP(BNX2X_MSG_ETHTOOL,
2023e9939c80SYuval Mintz 		   "Minimal Tx Lpi timer supported is %d(u)\n",
2024e9939c80SYuval Mintz 		   EEE_MODE_NVRAM_AGGRESSIVE_TIME);
2025e9939c80SYuval Mintz 		return -EINVAL;
2026e9939c80SYuval Mintz 	}
2027e9939c80SYuval Mintz 
2028e9939c80SYuval Mintz 	/* All is well; Apply changes*/
2029e9939c80SYuval Mintz 	if (edata->eee_enabled)
2030e9939c80SYuval Mintz 		bp->link_params.eee_mode |= EEE_MODE_ADV_LPI;
2031e9939c80SYuval Mintz 	else
2032e9939c80SYuval Mintz 		bp->link_params.eee_mode &= ~EEE_MODE_ADV_LPI;
2033e9939c80SYuval Mintz 
2034e9939c80SYuval Mintz 	if (edata->tx_lpi_enabled)
2035e9939c80SYuval Mintz 		bp->link_params.eee_mode |= EEE_MODE_ENABLE_LPI;
2036e9939c80SYuval Mintz 	else
2037e9939c80SYuval Mintz 		bp->link_params.eee_mode &= ~EEE_MODE_ENABLE_LPI;
2038e9939c80SYuval Mintz 
2039e9939c80SYuval Mintz 	bp->link_params.eee_mode &= ~EEE_MODE_TIMER_MASK;
2040e9939c80SYuval Mintz 	bp->link_params.eee_mode |= (edata->tx_lpi_timer &
2041e9939c80SYuval Mintz 				    EEE_MODE_TIMER_MASK) |
2042e9939c80SYuval Mintz 				    EEE_MODE_OVERRIDE_NVRAM |
2043e9939c80SYuval Mintz 				    EEE_MODE_OUTPUT_TIME;
2044e9939c80SYuval Mintz 
2045e9939c80SYuval Mintz 	/* Restart link to propogate changes */
2046e9939c80SYuval Mintz 	if (netif_running(dev)) {
2047e9939c80SYuval Mintz 		bnx2x_stats_handle(bp, STATS_EVENT_STOP);
20485d07d868SYuval Mintz 		bnx2x_force_link_reset(bp);
2049e9939c80SYuval Mintz 		bnx2x_link_set(bp);
2050e9939c80SYuval Mintz 	}
2051e9939c80SYuval Mintz 
2052e9939c80SYuval Mintz 	return 0;
2053e9939c80SYuval Mintz }
2054e9939c80SYuval Mintz 
2055adfc5217SJeff Kirsher enum {
2056adfc5217SJeff Kirsher 	BNX2X_CHIP_E1_OFST = 0,
2057adfc5217SJeff Kirsher 	BNX2X_CHIP_E1H_OFST,
2058adfc5217SJeff Kirsher 	BNX2X_CHIP_E2_OFST,
2059adfc5217SJeff Kirsher 	BNX2X_CHIP_E3_OFST,
2060adfc5217SJeff Kirsher 	BNX2X_CHIP_E3B0_OFST,
2061adfc5217SJeff Kirsher 	BNX2X_CHIP_MAX_OFST
2062adfc5217SJeff Kirsher };
2063adfc5217SJeff Kirsher 
2064adfc5217SJeff Kirsher #define BNX2X_CHIP_MASK_E1	(1 << BNX2X_CHIP_E1_OFST)
2065adfc5217SJeff Kirsher #define BNX2X_CHIP_MASK_E1H	(1 << BNX2X_CHIP_E1H_OFST)
2066adfc5217SJeff Kirsher #define BNX2X_CHIP_MASK_E2	(1 << BNX2X_CHIP_E2_OFST)
2067adfc5217SJeff Kirsher #define BNX2X_CHIP_MASK_E3	(1 << BNX2X_CHIP_E3_OFST)
2068adfc5217SJeff Kirsher #define BNX2X_CHIP_MASK_E3B0	(1 << BNX2X_CHIP_E3B0_OFST)
2069adfc5217SJeff Kirsher 
2070adfc5217SJeff Kirsher #define BNX2X_CHIP_MASK_ALL	((1 << BNX2X_CHIP_MAX_OFST) - 1)
2071adfc5217SJeff Kirsher #define BNX2X_CHIP_MASK_E1X	(BNX2X_CHIP_MASK_E1 | BNX2X_CHIP_MASK_E1H)
2072adfc5217SJeff Kirsher 
2073adfc5217SJeff Kirsher static int bnx2x_test_registers(struct bnx2x *bp)
2074adfc5217SJeff Kirsher {
2075adfc5217SJeff Kirsher 	int idx, i, rc = -ENODEV;
2076adfc5217SJeff Kirsher 	u32 wr_val = 0, hw;
2077adfc5217SJeff Kirsher 	int port = BP_PORT(bp);
2078adfc5217SJeff Kirsher 	static const struct {
2079adfc5217SJeff Kirsher 		u32 hw;
2080adfc5217SJeff Kirsher 		u32 offset0;
2081adfc5217SJeff Kirsher 		u32 offset1;
2082adfc5217SJeff Kirsher 		u32 mask;
2083adfc5217SJeff Kirsher 	} reg_tbl[] = {
2084adfc5217SJeff Kirsher /* 0 */		{ BNX2X_CHIP_MASK_ALL,
2085adfc5217SJeff Kirsher 			BRB1_REG_PAUSE_LOW_THRESHOLD_0,	4, 0x000003ff },
2086adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_ALL,
2087adfc5217SJeff Kirsher 			DORQ_REG_DB_ADDR0,		4, 0xffffffff },
2088adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_E1X,
2089adfc5217SJeff Kirsher 			HC_REG_AGG_INT_0,		4, 0x000003ff },
2090adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_ALL,
2091adfc5217SJeff Kirsher 			PBF_REG_MAC_IF0_ENABLE,		4, 0x00000001 },
2092adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2 | BNX2X_CHIP_MASK_E3,
2093adfc5217SJeff Kirsher 			PBF_REG_P0_INIT_CRD,		4, 0x000007ff },
2094adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_E3B0,
2095adfc5217SJeff Kirsher 			PBF_REG_INIT_CRD_Q0,		4, 0x000007ff },
2096adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_ALL,
2097adfc5217SJeff Kirsher 			PRS_REG_CID_PORT_0,		4, 0x00ffffff },
2098adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_ALL,
2099adfc5217SJeff Kirsher 			PXP2_REG_PSWRQ_CDU0_L2P,	4, 0x000fffff },
2100adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_ALL,
2101adfc5217SJeff Kirsher 			PXP2_REG_RQ_CDU0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
2102adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_ALL,
2103adfc5217SJeff Kirsher 			PXP2_REG_PSWRQ_TM0_L2P,		4, 0x000fffff },
2104adfc5217SJeff Kirsher /* 10 */	{ BNX2X_CHIP_MASK_ALL,
2105adfc5217SJeff Kirsher 			PXP2_REG_RQ_USDM0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
2106adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_ALL,
2107adfc5217SJeff Kirsher 			PXP2_REG_PSWRQ_TSDM0_L2P,	4, 0x000fffff },
2108adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_ALL,
2109adfc5217SJeff Kirsher 			QM_REG_CONNNUM_0,		4, 0x000fffff },
2110adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_ALL,
2111adfc5217SJeff Kirsher 			TM_REG_LIN0_MAX_ACTIVE_CID,	4, 0x0003ffff },
2112adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_ALL,
2113adfc5217SJeff Kirsher 			SRC_REG_KEYRSS0_0,		40, 0xffffffff },
2114adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_ALL,
2115adfc5217SJeff Kirsher 			SRC_REG_KEYRSS0_7,		40, 0xffffffff },
2116adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_ALL,
2117adfc5217SJeff Kirsher 			XCM_REG_WU_DA_SET_TMR_CNT_FLG_CMD00, 4, 0x00000001 },
2118adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_ALL,
2119adfc5217SJeff Kirsher 			XCM_REG_WU_DA_CNT_CMD00,	4, 0x00000003 },
2120adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_ALL,
2121adfc5217SJeff Kirsher 			XCM_REG_GLB_DEL_ACK_MAX_CNT_0,	4, 0x000000ff },
2122adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_ALL,
2123adfc5217SJeff Kirsher 			NIG_REG_LLH0_T_BIT,		4, 0x00000001 },
2124adfc5217SJeff Kirsher /* 20 */	{ BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2,
2125adfc5217SJeff Kirsher 			NIG_REG_EMAC0_IN_EN,		4, 0x00000001 },
2126adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2,
2127adfc5217SJeff Kirsher 			NIG_REG_BMAC0_IN_EN,		4, 0x00000001 },
2128adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_ALL,
2129adfc5217SJeff Kirsher 			NIG_REG_XCM0_OUT_EN,		4, 0x00000001 },
2130adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_ALL,
2131adfc5217SJeff Kirsher 			NIG_REG_BRB0_OUT_EN,		4, 0x00000001 },
2132adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_ALL,
2133adfc5217SJeff Kirsher 			NIG_REG_LLH0_XCM_MASK,		4, 0x00000007 },
2134adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_ALL,
2135adfc5217SJeff Kirsher 			NIG_REG_LLH0_ACPI_PAT_6_LEN,	68, 0x000000ff },
2136adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_ALL,
2137adfc5217SJeff Kirsher 			NIG_REG_LLH0_ACPI_PAT_0_CRC,	68, 0xffffffff },
2138adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_ALL,
2139adfc5217SJeff Kirsher 			NIG_REG_LLH0_DEST_MAC_0_0,	160, 0xffffffff },
2140adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_ALL,
2141adfc5217SJeff Kirsher 			NIG_REG_LLH0_DEST_IP_0_1,	160, 0xffffffff },
2142adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_ALL,
2143adfc5217SJeff Kirsher 			NIG_REG_LLH0_IPV4_IPV6_0,	160, 0x00000001 },
2144adfc5217SJeff Kirsher /* 30 */	{ BNX2X_CHIP_MASK_ALL,
2145adfc5217SJeff Kirsher 			NIG_REG_LLH0_DEST_UDP_0,	160, 0x0000ffff },
2146adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_ALL,
2147adfc5217SJeff Kirsher 			NIG_REG_LLH0_DEST_TCP_0,	160, 0x0000ffff },
2148adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_ALL,
2149adfc5217SJeff Kirsher 			NIG_REG_LLH0_VLAN_ID_0,	160, 0x00000fff },
2150adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2,
2151adfc5217SJeff Kirsher 			NIG_REG_XGXS_SERDES0_MODE_SEL,	4, 0x00000001 },
2152adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_ALL,
2153adfc5217SJeff Kirsher 			NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0, 4, 0x00000001},
2154adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_ALL,
2155adfc5217SJeff Kirsher 			NIG_REG_STATUS_INTERRUPT_PORT0,	4, 0x07ffffff },
2156adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2,
2157adfc5217SJeff Kirsher 			NIG_REG_XGXS0_CTRL_EXTREMOTEMDIOST, 24, 0x00000001 },
2158adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2,
2159adfc5217SJeff Kirsher 			NIG_REG_SERDES0_CTRL_PHY_ADDR,	16, 0x0000001f },
2160adfc5217SJeff Kirsher 
2161adfc5217SJeff Kirsher 		{ BNX2X_CHIP_MASK_ALL, 0xffffffff, 0, 0x00000000 }
2162adfc5217SJeff Kirsher 	};
2163adfc5217SJeff Kirsher 
216451c1a580SMerav Sicron 	if (!netif_running(bp->dev)) {
216551c1a580SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
216651c1a580SMerav Sicron 		   "cannot access eeprom when the interface is down\n");
2167adfc5217SJeff Kirsher 		return rc;
216851c1a580SMerav Sicron 	}
2169adfc5217SJeff Kirsher 
2170adfc5217SJeff Kirsher 	if (CHIP_IS_E1(bp))
2171adfc5217SJeff Kirsher 		hw = BNX2X_CHIP_MASK_E1;
2172adfc5217SJeff Kirsher 	else if (CHIP_IS_E1H(bp))
2173adfc5217SJeff Kirsher 		hw = BNX2X_CHIP_MASK_E1H;
2174adfc5217SJeff Kirsher 	else if (CHIP_IS_E2(bp))
2175adfc5217SJeff Kirsher 		hw = BNX2X_CHIP_MASK_E2;
2176adfc5217SJeff Kirsher 	else if (CHIP_IS_E3B0(bp))
2177adfc5217SJeff Kirsher 		hw = BNX2X_CHIP_MASK_E3B0;
2178adfc5217SJeff Kirsher 	else /* e3 A0 */
2179adfc5217SJeff Kirsher 		hw = BNX2X_CHIP_MASK_E3;
2180adfc5217SJeff Kirsher 
2181adfc5217SJeff Kirsher 	/* Repeat the test twice:
218207ba6af4SMiriam Shitrit 	 * First by writing 0x00000000, second by writing 0xffffffff
218307ba6af4SMiriam Shitrit 	 */
2184adfc5217SJeff Kirsher 	for (idx = 0; idx < 2; idx++) {
2185adfc5217SJeff Kirsher 
2186adfc5217SJeff Kirsher 		switch (idx) {
2187adfc5217SJeff Kirsher 		case 0:
2188adfc5217SJeff Kirsher 			wr_val = 0;
2189adfc5217SJeff Kirsher 			break;
2190adfc5217SJeff Kirsher 		case 1:
2191adfc5217SJeff Kirsher 			wr_val = 0xffffffff;
2192adfc5217SJeff Kirsher 			break;
2193adfc5217SJeff Kirsher 		}
2194adfc5217SJeff Kirsher 
2195adfc5217SJeff Kirsher 		for (i = 0; reg_tbl[i].offset0 != 0xffffffff; i++) {
2196adfc5217SJeff Kirsher 			u32 offset, mask, save_val, val;
2197adfc5217SJeff Kirsher 			if (!(hw & reg_tbl[i].hw))
2198adfc5217SJeff Kirsher 				continue;
2199adfc5217SJeff Kirsher 
2200adfc5217SJeff Kirsher 			offset = reg_tbl[i].offset0 + port*reg_tbl[i].offset1;
2201adfc5217SJeff Kirsher 			mask = reg_tbl[i].mask;
2202adfc5217SJeff Kirsher 
2203adfc5217SJeff Kirsher 			save_val = REG_RD(bp, offset);
2204adfc5217SJeff Kirsher 
2205adfc5217SJeff Kirsher 			REG_WR(bp, offset, wr_val & mask);
2206adfc5217SJeff Kirsher 
2207adfc5217SJeff Kirsher 			val = REG_RD(bp, offset);
2208adfc5217SJeff Kirsher 
2209adfc5217SJeff Kirsher 			/* Restore the original register's value */
2210adfc5217SJeff Kirsher 			REG_WR(bp, offset, save_val);
2211adfc5217SJeff Kirsher 
2212adfc5217SJeff Kirsher 			/* verify value is as expected */
2213adfc5217SJeff Kirsher 			if ((val & mask) != (wr_val & mask)) {
221451c1a580SMerav Sicron 				DP(BNX2X_MSG_ETHTOOL,
2215adfc5217SJeff Kirsher 				   "offset 0x%x: val 0x%x != 0x%x mask 0x%x\n",
2216adfc5217SJeff Kirsher 				   offset, val, wr_val, mask);
2217adfc5217SJeff Kirsher 				goto test_reg_exit;
2218adfc5217SJeff Kirsher 			}
2219adfc5217SJeff Kirsher 		}
2220adfc5217SJeff Kirsher 	}
2221adfc5217SJeff Kirsher 
2222adfc5217SJeff Kirsher 	rc = 0;
2223adfc5217SJeff Kirsher 
2224adfc5217SJeff Kirsher test_reg_exit:
2225adfc5217SJeff Kirsher 	return rc;
2226adfc5217SJeff Kirsher }
2227adfc5217SJeff Kirsher 
2228adfc5217SJeff Kirsher static int bnx2x_test_memory(struct bnx2x *bp)
2229adfc5217SJeff Kirsher {
2230adfc5217SJeff Kirsher 	int i, j, rc = -ENODEV;
2231adfc5217SJeff Kirsher 	u32 val, index;
2232adfc5217SJeff Kirsher 	static const struct {
2233adfc5217SJeff Kirsher 		u32 offset;
2234adfc5217SJeff Kirsher 		int size;
2235adfc5217SJeff Kirsher 	} mem_tbl[] = {
2236adfc5217SJeff Kirsher 		{ CCM_REG_XX_DESCR_TABLE,   CCM_REG_XX_DESCR_TABLE_SIZE },
2237adfc5217SJeff Kirsher 		{ CFC_REG_ACTIVITY_COUNTER, CFC_REG_ACTIVITY_COUNTER_SIZE },
2238adfc5217SJeff Kirsher 		{ CFC_REG_LINK_LIST,        CFC_REG_LINK_LIST_SIZE },
2239adfc5217SJeff Kirsher 		{ DMAE_REG_CMD_MEM,         DMAE_REG_CMD_MEM_SIZE },
2240adfc5217SJeff Kirsher 		{ TCM_REG_XX_DESCR_TABLE,   TCM_REG_XX_DESCR_TABLE_SIZE },
2241adfc5217SJeff Kirsher 		{ UCM_REG_XX_DESCR_TABLE,   UCM_REG_XX_DESCR_TABLE_SIZE },
2242adfc5217SJeff Kirsher 		{ XCM_REG_XX_DESCR_TABLE,   XCM_REG_XX_DESCR_TABLE_SIZE },
2243adfc5217SJeff Kirsher 
2244adfc5217SJeff Kirsher 		{ 0xffffffff, 0 }
2245adfc5217SJeff Kirsher 	};
2246adfc5217SJeff Kirsher 
2247adfc5217SJeff Kirsher 	static const struct {
2248adfc5217SJeff Kirsher 		char *name;
2249adfc5217SJeff Kirsher 		u32 offset;
2250adfc5217SJeff Kirsher 		u32 hw_mask[BNX2X_CHIP_MAX_OFST];
2251adfc5217SJeff Kirsher 	} prty_tbl[] = {
2252adfc5217SJeff Kirsher 		{ "CCM_PRTY_STS",  CCM_REG_CCM_PRTY_STS,
2253adfc5217SJeff Kirsher 			{0x3ffc0, 0,   0, 0} },
2254adfc5217SJeff Kirsher 		{ "CFC_PRTY_STS",  CFC_REG_CFC_PRTY_STS,
2255adfc5217SJeff Kirsher 			{0x2,     0x2, 0, 0} },
2256adfc5217SJeff Kirsher 		{ "DMAE_PRTY_STS", DMAE_REG_DMAE_PRTY_STS,
2257adfc5217SJeff Kirsher 			{0,       0,   0, 0} },
2258adfc5217SJeff Kirsher 		{ "TCM_PRTY_STS",  TCM_REG_TCM_PRTY_STS,
2259adfc5217SJeff Kirsher 			{0x3ffc0, 0,   0, 0} },
2260adfc5217SJeff Kirsher 		{ "UCM_PRTY_STS",  UCM_REG_UCM_PRTY_STS,
2261adfc5217SJeff Kirsher 			{0x3ffc0, 0,   0, 0} },
2262adfc5217SJeff Kirsher 		{ "XCM_PRTY_STS",  XCM_REG_XCM_PRTY_STS,
2263adfc5217SJeff Kirsher 			{0x3ffc1, 0,   0, 0} },
2264adfc5217SJeff Kirsher 
2265adfc5217SJeff Kirsher 		{ NULL, 0xffffffff, {0, 0, 0, 0} }
2266adfc5217SJeff Kirsher 	};
2267adfc5217SJeff Kirsher 
226851c1a580SMerav Sicron 	if (!netif_running(bp->dev)) {
226951c1a580SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
227051c1a580SMerav Sicron 		   "cannot access eeprom when the interface is down\n");
2271adfc5217SJeff Kirsher 		return rc;
227251c1a580SMerav Sicron 	}
2273adfc5217SJeff Kirsher 
2274adfc5217SJeff Kirsher 	if (CHIP_IS_E1(bp))
2275adfc5217SJeff Kirsher 		index = BNX2X_CHIP_E1_OFST;
2276adfc5217SJeff Kirsher 	else if (CHIP_IS_E1H(bp))
2277adfc5217SJeff Kirsher 		index = BNX2X_CHIP_E1H_OFST;
2278adfc5217SJeff Kirsher 	else if (CHIP_IS_E2(bp))
2279adfc5217SJeff Kirsher 		index = BNX2X_CHIP_E2_OFST;
2280adfc5217SJeff Kirsher 	else /* e3 */
2281adfc5217SJeff Kirsher 		index = BNX2X_CHIP_E3_OFST;
2282adfc5217SJeff Kirsher 
2283adfc5217SJeff Kirsher 	/* pre-Check the parity status */
2284adfc5217SJeff Kirsher 	for (i = 0; prty_tbl[i].offset != 0xffffffff; i++) {
2285adfc5217SJeff Kirsher 		val = REG_RD(bp, prty_tbl[i].offset);
2286adfc5217SJeff Kirsher 		if (val & ~(prty_tbl[i].hw_mask[index])) {
228751c1a580SMerav Sicron 			DP(BNX2X_MSG_ETHTOOL,
2288adfc5217SJeff Kirsher 			   "%s is 0x%x\n", prty_tbl[i].name, val);
2289adfc5217SJeff Kirsher 			goto test_mem_exit;
2290adfc5217SJeff Kirsher 		}
2291adfc5217SJeff Kirsher 	}
2292adfc5217SJeff Kirsher 
2293adfc5217SJeff Kirsher 	/* Go through all the memories */
2294adfc5217SJeff Kirsher 	for (i = 0; mem_tbl[i].offset != 0xffffffff; i++)
2295adfc5217SJeff Kirsher 		for (j = 0; j < mem_tbl[i].size; j++)
2296adfc5217SJeff Kirsher 			REG_RD(bp, mem_tbl[i].offset + j*4);
2297adfc5217SJeff Kirsher 
2298adfc5217SJeff Kirsher 	/* Check the parity status */
2299adfc5217SJeff Kirsher 	for (i = 0; prty_tbl[i].offset != 0xffffffff; i++) {
2300adfc5217SJeff Kirsher 		val = REG_RD(bp, prty_tbl[i].offset);
2301adfc5217SJeff Kirsher 		if (val & ~(prty_tbl[i].hw_mask[index])) {
230251c1a580SMerav Sicron 			DP(BNX2X_MSG_ETHTOOL,
2303adfc5217SJeff Kirsher 			   "%s is 0x%x\n", prty_tbl[i].name, val);
2304adfc5217SJeff Kirsher 			goto test_mem_exit;
2305adfc5217SJeff Kirsher 		}
2306adfc5217SJeff Kirsher 	}
2307adfc5217SJeff Kirsher 
2308adfc5217SJeff Kirsher 	rc = 0;
2309adfc5217SJeff Kirsher 
2310adfc5217SJeff Kirsher test_mem_exit:
2311adfc5217SJeff Kirsher 	return rc;
2312adfc5217SJeff Kirsher }
2313adfc5217SJeff Kirsher 
2314adfc5217SJeff Kirsher static void bnx2x_wait_for_link(struct bnx2x *bp, u8 link_up, u8 is_serdes)
2315adfc5217SJeff Kirsher {
2316adfc5217SJeff Kirsher 	int cnt = 1400;
2317adfc5217SJeff Kirsher 
2318adfc5217SJeff Kirsher 	if (link_up) {
2319adfc5217SJeff Kirsher 		while (bnx2x_link_test(bp, is_serdes) && cnt--)
2320adfc5217SJeff Kirsher 			msleep(20);
2321adfc5217SJeff Kirsher 
2322adfc5217SJeff Kirsher 		if (cnt <= 0 && bnx2x_link_test(bp, is_serdes))
232351c1a580SMerav Sicron 			DP(BNX2X_MSG_ETHTOOL, "Timeout waiting for link up\n");
23248970b2e4SMerav Sicron 
23258970b2e4SMerav Sicron 		cnt = 1400;
23268970b2e4SMerav Sicron 		while (!bp->link_vars.link_up && cnt--)
23278970b2e4SMerav Sicron 			msleep(20);
23288970b2e4SMerav Sicron 
23298970b2e4SMerav Sicron 		if (cnt <= 0 && !bp->link_vars.link_up)
23308970b2e4SMerav Sicron 			DP(BNX2X_MSG_ETHTOOL,
23318970b2e4SMerav Sicron 			   "Timeout waiting for link init\n");
2332adfc5217SJeff Kirsher 	}
2333adfc5217SJeff Kirsher }
2334adfc5217SJeff Kirsher 
2335adfc5217SJeff Kirsher static int bnx2x_run_loopback(struct bnx2x *bp, int loopback_mode)
2336adfc5217SJeff Kirsher {
2337adfc5217SJeff Kirsher 	unsigned int pkt_size, num_pkts, i;
2338adfc5217SJeff Kirsher 	struct sk_buff *skb;
2339adfc5217SJeff Kirsher 	unsigned char *packet;
2340adfc5217SJeff Kirsher 	struct bnx2x_fastpath *fp_rx = &bp->fp[0];
2341adfc5217SJeff Kirsher 	struct bnx2x_fastpath *fp_tx = &bp->fp[0];
234265565884SMerav Sicron 	struct bnx2x_fp_txdata *txdata = fp_tx->txdata_ptr[0];
2343adfc5217SJeff Kirsher 	u16 tx_start_idx, tx_idx;
2344adfc5217SJeff Kirsher 	u16 rx_start_idx, rx_idx;
2345b0700b1eSDmitry Kravkov 	u16 pkt_prod, bd_prod;
2346adfc5217SJeff Kirsher 	struct sw_tx_bd *tx_buf;
2347adfc5217SJeff Kirsher 	struct eth_tx_start_bd *tx_start_bd;
2348adfc5217SJeff Kirsher 	dma_addr_t mapping;
2349adfc5217SJeff Kirsher 	union eth_rx_cqe *cqe;
2350adfc5217SJeff Kirsher 	u8 cqe_fp_flags, cqe_fp_type;
2351adfc5217SJeff Kirsher 	struct sw_rx_bd *rx_buf;
2352adfc5217SJeff Kirsher 	u16 len;
2353adfc5217SJeff Kirsher 	int rc = -ENODEV;
2354e52fcb24SEric Dumazet 	u8 *data;
23558970b2e4SMerav Sicron 	struct netdev_queue *txq = netdev_get_tx_queue(bp->dev,
23568970b2e4SMerav Sicron 						       txdata->txq_index);
2357adfc5217SJeff Kirsher 
2358adfc5217SJeff Kirsher 	/* check the loopback mode */
2359adfc5217SJeff Kirsher 	switch (loopback_mode) {
2360adfc5217SJeff Kirsher 	case BNX2X_PHY_LOOPBACK:
23618970b2e4SMerav Sicron 		if (bp->link_params.loopback_mode != LOOPBACK_XGXS) {
23628970b2e4SMerav Sicron 			DP(BNX2X_MSG_ETHTOOL, "PHY loopback not supported\n");
2363adfc5217SJeff Kirsher 			return -EINVAL;
23648970b2e4SMerav Sicron 		}
2365adfc5217SJeff Kirsher 		break;
2366adfc5217SJeff Kirsher 	case BNX2X_MAC_LOOPBACK:
236732911333SYaniv Rosner 		if (CHIP_IS_E3(bp)) {
236832911333SYaniv Rosner 			int cfg_idx = bnx2x_get_link_cfg_idx(bp);
236932911333SYaniv Rosner 			if (bp->port.supported[cfg_idx] &
237032911333SYaniv Rosner 			    (SUPPORTED_10000baseT_Full |
237132911333SYaniv Rosner 			     SUPPORTED_20000baseMLD2_Full |
237232911333SYaniv Rosner 			     SUPPORTED_20000baseKR2_Full))
237332911333SYaniv Rosner 				bp->link_params.loopback_mode = LOOPBACK_XMAC;
237432911333SYaniv Rosner 			else
237532911333SYaniv Rosner 				bp->link_params.loopback_mode = LOOPBACK_UMAC;
237632911333SYaniv Rosner 		} else
237732911333SYaniv Rosner 			bp->link_params.loopback_mode = LOOPBACK_BMAC;
237832911333SYaniv Rosner 
2379adfc5217SJeff Kirsher 		bnx2x_phy_init(&bp->link_params, &bp->link_vars);
2380adfc5217SJeff Kirsher 		break;
23818970b2e4SMerav Sicron 	case BNX2X_EXT_LOOPBACK:
23828970b2e4SMerav Sicron 		if (bp->link_params.loopback_mode != LOOPBACK_EXT) {
23838970b2e4SMerav Sicron 			DP(BNX2X_MSG_ETHTOOL,
23848970b2e4SMerav Sicron 			   "Can't configure external loopback\n");
23858970b2e4SMerav Sicron 			return -EINVAL;
23868970b2e4SMerav Sicron 		}
23878970b2e4SMerav Sicron 		break;
2388adfc5217SJeff Kirsher 	default:
238951c1a580SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL, "Command parameters not supported\n");
2390adfc5217SJeff Kirsher 		return -EINVAL;
2391adfc5217SJeff Kirsher 	}
2392adfc5217SJeff Kirsher 
2393adfc5217SJeff Kirsher 	/* prepare the loopback packet */
2394adfc5217SJeff Kirsher 	pkt_size = (((bp->dev->mtu < ETH_MAX_PACKET_SIZE) ?
2395adfc5217SJeff Kirsher 		     bp->dev->mtu : ETH_MAX_PACKET_SIZE) + ETH_HLEN);
2396adfc5217SJeff Kirsher 	skb = netdev_alloc_skb(bp->dev, fp_rx->rx_buf_size);
2397adfc5217SJeff Kirsher 	if (!skb) {
239851c1a580SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL, "Can't allocate skb\n");
2399adfc5217SJeff Kirsher 		rc = -ENOMEM;
2400adfc5217SJeff Kirsher 		goto test_loopback_exit;
2401adfc5217SJeff Kirsher 	}
2402adfc5217SJeff Kirsher 	packet = skb_put(skb, pkt_size);
2403adfc5217SJeff Kirsher 	memcpy(packet, bp->dev->dev_addr, ETH_ALEN);
2404adfc5217SJeff Kirsher 	memset(packet + ETH_ALEN, 0, ETH_ALEN);
2405adfc5217SJeff Kirsher 	memset(packet + 2*ETH_ALEN, 0x77, (ETH_HLEN - 2*ETH_ALEN));
2406adfc5217SJeff Kirsher 	for (i = ETH_HLEN; i < pkt_size; i++)
2407adfc5217SJeff Kirsher 		packet[i] = (unsigned char) (i & 0xff);
2408adfc5217SJeff Kirsher 	mapping = dma_map_single(&bp->pdev->dev, skb->data,
2409adfc5217SJeff Kirsher 				 skb_headlen(skb), DMA_TO_DEVICE);
2410adfc5217SJeff Kirsher 	if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
2411adfc5217SJeff Kirsher 		rc = -ENOMEM;
2412adfc5217SJeff Kirsher 		dev_kfree_skb(skb);
241351c1a580SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL, "Unable to map SKB\n");
2414adfc5217SJeff Kirsher 		goto test_loopback_exit;
2415adfc5217SJeff Kirsher 	}
2416adfc5217SJeff Kirsher 
2417adfc5217SJeff Kirsher 	/* send the loopback packet */
2418adfc5217SJeff Kirsher 	num_pkts = 0;
2419adfc5217SJeff Kirsher 	tx_start_idx = le16_to_cpu(*txdata->tx_cons_sb);
2420adfc5217SJeff Kirsher 	rx_start_idx = le16_to_cpu(*fp_rx->rx_cons_sb);
2421adfc5217SJeff Kirsher 
242273dbb5e1SDmitry Kravkov 	netdev_tx_sent_queue(txq, skb->len);
242373dbb5e1SDmitry Kravkov 
2424adfc5217SJeff Kirsher 	pkt_prod = txdata->tx_pkt_prod++;
2425adfc5217SJeff Kirsher 	tx_buf = &txdata->tx_buf_ring[TX_BD(pkt_prod)];
2426adfc5217SJeff Kirsher 	tx_buf->first_bd = txdata->tx_bd_prod;
2427adfc5217SJeff Kirsher 	tx_buf->skb = skb;
2428adfc5217SJeff Kirsher 	tx_buf->flags = 0;
2429adfc5217SJeff Kirsher 
2430adfc5217SJeff Kirsher 	bd_prod = TX_BD(txdata->tx_bd_prod);
2431adfc5217SJeff Kirsher 	tx_start_bd = &txdata->tx_desc_ring[bd_prod].start_bd;
2432adfc5217SJeff Kirsher 	tx_start_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
2433adfc5217SJeff Kirsher 	tx_start_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
2434adfc5217SJeff Kirsher 	tx_start_bd->nbd = cpu_to_le16(2); /* start + pbd */
2435adfc5217SJeff Kirsher 	tx_start_bd->nbytes = cpu_to_le16(skb_headlen(skb));
2436adfc5217SJeff Kirsher 	tx_start_bd->vlan_or_ethertype = cpu_to_le16(pkt_prod);
2437adfc5217SJeff Kirsher 	tx_start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
2438adfc5217SJeff Kirsher 	SET_FLAG(tx_start_bd->general_data,
2439adfc5217SJeff Kirsher 		 ETH_TX_START_BD_HDR_NBDS,
2440adfc5217SJeff Kirsher 		 1);
244196bed4b9SYuval Mintz 	SET_FLAG(tx_start_bd->general_data,
244296bed4b9SYuval Mintz 		 ETH_TX_START_BD_PARSE_NBDS,
244396bed4b9SYuval Mintz 		 0);
2444adfc5217SJeff Kirsher 
2445adfc5217SJeff Kirsher 	/* turn on parsing and get a BD */
2446adfc5217SJeff Kirsher 	bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
2447adfc5217SJeff Kirsher 
244896bed4b9SYuval Mintz 	if (CHIP_IS_E1x(bp)) {
244996bed4b9SYuval Mintz 		u16 global_data = 0;
245096bed4b9SYuval Mintz 		struct eth_tx_parse_bd_e1x  *pbd_e1x =
245196bed4b9SYuval Mintz 			&txdata->tx_desc_ring[bd_prod].parse_bd_e1x;
2452adfc5217SJeff Kirsher 		memset(pbd_e1x, 0, sizeof(struct eth_tx_parse_bd_e1x));
245396bed4b9SYuval Mintz 		SET_FLAG(global_data,
245496bed4b9SYuval Mintz 			 ETH_TX_PARSE_BD_E1X_ETH_ADDR_TYPE, UNICAST_ADDRESS);
245596bed4b9SYuval Mintz 		pbd_e1x->global_data = cpu_to_le16(global_data);
245696bed4b9SYuval Mintz 	} else {
245796bed4b9SYuval Mintz 		u32 parsing_data = 0;
245896bed4b9SYuval Mintz 		struct eth_tx_parse_bd_e2  *pbd_e2 =
245996bed4b9SYuval Mintz 			&txdata->tx_desc_ring[bd_prod].parse_bd_e2;
246096bed4b9SYuval Mintz 		memset(pbd_e2, 0, sizeof(struct eth_tx_parse_bd_e2));
246196bed4b9SYuval Mintz 		SET_FLAG(parsing_data,
246296bed4b9SYuval Mintz 			 ETH_TX_PARSE_BD_E2_ETH_ADDR_TYPE, UNICAST_ADDRESS);
246396bed4b9SYuval Mintz 		pbd_e2->parsing_data = cpu_to_le32(parsing_data);
246496bed4b9SYuval Mintz 	}
2465adfc5217SJeff Kirsher 	wmb();
2466adfc5217SJeff Kirsher 
2467adfc5217SJeff Kirsher 	txdata->tx_db.data.prod += 2;
2468adfc5217SJeff Kirsher 	barrier();
2469adfc5217SJeff Kirsher 	DOORBELL(bp, txdata->cid, txdata->tx_db.raw);
2470adfc5217SJeff Kirsher 
2471adfc5217SJeff Kirsher 	mmiowb();
2472adfc5217SJeff Kirsher 	barrier();
2473adfc5217SJeff Kirsher 
2474adfc5217SJeff Kirsher 	num_pkts++;
2475adfc5217SJeff Kirsher 	txdata->tx_bd_prod += 2; /* start + pbd */
2476adfc5217SJeff Kirsher 
2477adfc5217SJeff Kirsher 	udelay(100);
2478adfc5217SJeff Kirsher 
2479adfc5217SJeff Kirsher 	tx_idx = le16_to_cpu(*txdata->tx_cons_sb);
2480adfc5217SJeff Kirsher 	if (tx_idx != tx_start_idx + num_pkts)
2481adfc5217SJeff Kirsher 		goto test_loopback_exit;
2482adfc5217SJeff Kirsher 
2483adfc5217SJeff Kirsher 	/* Unlike HC IGU won't generate an interrupt for status block
2484adfc5217SJeff Kirsher 	 * updates that have been performed while interrupts were
2485adfc5217SJeff Kirsher 	 * disabled.
2486adfc5217SJeff Kirsher 	 */
2487adfc5217SJeff Kirsher 	if (bp->common.int_block == INT_BLOCK_IGU) {
2488adfc5217SJeff Kirsher 		/* Disable local BHes to prevent a dead-lock situation between
2489adfc5217SJeff Kirsher 		 * sch_direct_xmit() and bnx2x_run_loopback() (calling
2490adfc5217SJeff Kirsher 		 * bnx2x_tx_int()), as both are taking netif_tx_lock().
2491adfc5217SJeff Kirsher 		 */
2492adfc5217SJeff Kirsher 		local_bh_disable();
2493adfc5217SJeff Kirsher 		bnx2x_tx_int(bp, txdata);
2494adfc5217SJeff Kirsher 		local_bh_enable();
2495adfc5217SJeff Kirsher 	}
2496adfc5217SJeff Kirsher 
2497adfc5217SJeff Kirsher 	rx_idx = le16_to_cpu(*fp_rx->rx_cons_sb);
2498adfc5217SJeff Kirsher 	if (rx_idx != rx_start_idx + num_pkts)
2499adfc5217SJeff Kirsher 		goto test_loopback_exit;
2500adfc5217SJeff Kirsher 
2501b0700b1eSDmitry Kravkov 	cqe = &fp_rx->rx_comp_ring[RCQ_BD(fp_rx->rx_comp_cons)];
2502adfc5217SJeff Kirsher 	cqe_fp_flags = cqe->fast_path_cqe.type_error_flags;
2503adfc5217SJeff Kirsher 	cqe_fp_type = cqe_fp_flags & ETH_FAST_PATH_RX_CQE_TYPE;
2504adfc5217SJeff Kirsher 	if (!CQE_TYPE_FAST(cqe_fp_type) || (cqe_fp_flags & ETH_RX_ERROR_FALGS))
2505adfc5217SJeff Kirsher 		goto test_loopback_rx_exit;
2506adfc5217SJeff Kirsher 
2507621b4d66SDmitry Kravkov 	len = le16_to_cpu(cqe->fast_path_cqe.pkt_len_or_gro_seg_len);
2508adfc5217SJeff Kirsher 	if (len != pkt_size)
2509adfc5217SJeff Kirsher 		goto test_loopback_rx_exit;
2510adfc5217SJeff Kirsher 
2511adfc5217SJeff Kirsher 	rx_buf = &fp_rx->rx_buf_ring[RX_BD(fp_rx->rx_bd_cons)];
2512adfc5217SJeff Kirsher 	dma_sync_single_for_cpu(&bp->pdev->dev,
2513adfc5217SJeff Kirsher 				   dma_unmap_addr(rx_buf, mapping),
2514adfc5217SJeff Kirsher 				   fp_rx->rx_buf_size, DMA_FROM_DEVICE);
2515e52fcb24SEric Dumazet 	data = rx_buf->data + NET_SKB_PAD + cqe->fast_path_cqe.placement_offset;
2516adfc5217SJeff Kirsher 	for (i = ETH_HLEN; i < pkt_size; i++)
2517e52fcb24SEric Dumazet 		if (*(data + i) != (unsigned char) (i & 0xff))
2518adfc5217SJeff Kirsher 			goto test_loopback_rx_exit;
2519adfc5217SJeff Kirsher 
2520adfc5217SJeff Kirsher 	rc = 0;
2521adfc5217SJeff Kirsher 
2522adfc5217SJeff Kirsher test_loopback_rx_exit:
2523adfc5217SJeff Kirsher 
2524adfc5217SJeff Kirsher 	fp_rx->rx_bd_cons = NEXT_RX_IDX(fp_rx->rx_bd_cons);
2525adfc5217SJeff Kirsher 	fp_rx->rx_bd_prod = NEXT_RX_IDX(fp_rx->rx_bd_prod);
2526adfc5217SJeff Kirsher 	fp_rx->rx_comp_cons = NEXT_RCQ_IDX(fp_rx->rx_comp_cons);
2527adfc5217SJeff Kirsher 	fp_rx->rx_comp_prod = NEXT_RCQ_IDX(fp_rx->rx_comp_prod);
2528adfc5217SJeff Kirsher 
2529adfc5217SJeff Kirsher 	/* Update producers */
2530adfc5217SJeff Kirsher 	bnx2x_update_rx_prod(bp, fp_rx, fp_rx->rx_bd_prod, fp_rx->rx_comp_prod,
2531adfc5217SJeff Kirsher 			     fp_rx->rx_sge_prod);
2532adfc5217SJeff Kirsher 
2533adfc5217SJeff Kirsher test_loopback_exit:
2534adfc5217SJeff Kirsher 	bp->link_params.loopback_mode = LOOPBACK_NONE;
2535adfc5217SJeff Kirsher 
2536adfc5217SJeff Kirsher 	return rc;
2537adfc5217SJeff Kirsher }
2538adfc5217SJeff Kirsher 
2539adfc5217SJeff Kirsher static int bnx2x_test_loopback(struct bnx2x *bp)
2540adfc5217SJeff Kirsher {
2541adfc5217SJeff Kirsher 	int rc = 0, res;
2542adfc5217SJeff Kirsher 
2543adfc5217SJeff Kirsher 	if (BP_NOMCP(bp))
2544adfc5217SJeff Kirsher 		return rc;
2545adfc5217SJeff Kirsher 
2546adfc5217SJeff Kirsher 	if (!netif_running(bp->dev))
2547adfc5217SJeff Kirsher 		return BNX2X_LOOPBACK_FAILED;
2548adfc5217SJeff Kirsher 
2549adfc5217SJeff Kirsher 	bnx2x_netif_stop(bp, 1);
2550adfc5217SJeff Kirsher 	bnx2x_acquire_phy_lock(bp);
2551adfc5217SJeff Kirsher 
2552adfc5217SJeff Kirsher 	res = bnx2x_run_loopback(bp, BNX2X_PHY_LOOPBACK);
2553adfc5217SJeff Kirsher 	if (res) {
255451c1a580SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL, "  PHY loopback failed  (res %d)\n", res);
2555adfc5217SJeff Kirsher 		rc |= BNX2X_PHY_LOOPBACK_FAILED;
2556adfc5217SJeff Kirsher 	}
2557adfc5217SJeff Kirsher 
2558adfc5217SJeff Kirsher 	res = bnx2x_run_loopback(bp, BNX2X_MAC_LOOPBACK);
2559adfc5217SJeff Kirsher 	if (res) {
256051c1a580SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL, "  MAC loopback failed  (res %d)\n", res);
2561adfc5217SJeff Kirsher 		rc |= BNX2X_MAC_LOOPBACK_FAILED;
2562adfc5217SJeff Kirsher 	}
2563adfc5217SJeff Kirsher 
2564adfc5217SJeff Kirsher 	bnx2x_release_phy_lock(bp);
2565adfc5217SJeff Kirsher 	bnx2x_netif_start(bp);
2566adfc5217SJeff Kirsher 
2567adfc5217SJeff Kirsher 	return rc;
2568adfc5217SJeff Kirsher }
2569adfc5217SJeff Kirsher 
25708970b2e4SMerav Sicron static int bnx2x_test_ext_loopback(struct bnx2x *bp)
25718970b2e4SMerav Sicron {
25728970b2e4SMerav Sicron 	int rc;
25738970b2e4SMerav Sicron 	u8 is_serdes =
25748970b2e4SMerav Sicron 		(bp->link_vars.link_status & LINK_STATUS_SERDES_LINK) > 0;
25758970b2e4SMerav Sicron 
25768970b2e4SMerav Sicron 	if (BP_NOMCP(bp))
25778970b2e4SMerav Sicron 		return -ENODEV;
25788970b2e4SMerav Sicron 
25798970b2e4SMerav Sicron 	if (!netif_running(bp->dev))
25808970b2e4SMerav Sicron 		return BNX2X_EXT_LOOPBACK_FAILED;
25818970b2e4SMerav Sicron 
25825d07d868SYuval Mintz 	bnx2x_nic_unload(bp, UNLOAD_NORMAL, false);
25838970b2e4SMerav Sicron 	rc = bnx2x_nic_load(bp, LOAD_LOOPBACK_EXT);
25848970b2e4SMerav Sicron 	if (rc) {
25858970b2e4SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL,
25868970b2e4SMerav Sicron 		   "Can't perform self-test, nic_load (for external lb) failed\n");
25878970b2e4SMerav Sicron 		return -ENODEV;
25888970b2e4SMerav Sicron 	}
25898970b2e4SMerav Sicron 	bnx2x_wait_for_link(bp, 1, is_serdes);
25908970b2e4SMerav Sicron 
25918970b2e4SMerav Sicron 	bnx2x_netif_stop(bp, 1);
25928970b2e4SMerav Sicron 
25938970b2e4SMerav Sicron 	rc = bnx2x_run_loopback(bp, BNX2X_EXT_LOOPBACK);
25948970b2e4SMerav Sicron 	if (rc)
25958970b2e4SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL, "EXT loopback failed  (res %d)\n", rc);
25968970b2e4SMerav Sicron 
25978970b2e4SMerav Sicron 	bnx2x_netif_start(bp);
25988970b2e4SMerav Sicron 
25998970b2e4SMerav Sicron 	return rc;
26008970b2e4SMerav Sicron }
26018970b2e4SMerav Sicron 
2602adfc5217SJeff Kirsher #define CRC32_RESIDUAL			0xdebb20e3
2603adfc5217SJeff Kirsher 
2604adfc5217SJeff Kirsher static int bnx2x_test_nvram(struct bnx2x *bp)
2605adfc5217SJeff Kirsher {
2606adfc5217SJeff Kirsher 	static const struct {
2607adfc5217SJeff Kirsher 		int offset;
2608adfc5217SJeff Kirsher 		int size;
2609adfc5217SJeff Kirsher 	} nvram_tbl[] = {
2610adfc5217SJeff Kirsher 		{     0,  0x14 }, /* bootstrap */
2611adfc5217SJeff Kirsher 		{  0x14,  0xec }, /* dir */
2612adfc5217SJeff Kirsher 		{ 0x100, 0x350 }, /* manuf_info */
2613adfc5217SJeff Kirsher 		{ 0x450,  0xf0 }, /* feature_info */
2614adfc5217SJeff Kirsher 		{ 0x640,  0x64 }, /* upgrade_key_info */
2615adfc5217SJeff Kirsher 		{ 0x708,  0x70 }, /* manuf_key_info */
2616adfc5217SJeff Kirsher 		{     0,     0 }
2617adfc5217SJeff Kirsher 	};
261885640952SDmitry Kravkov 	u8 *buf;
2619adfc5217SJeff Kirsher 	int i, rc;
2620adfc5217SJeff Kirsher 	u32 magic, crc;
2621adfc5217SJeff Kirsher 
2622adfc5217SJeff Kirsher 	if (BP_NOMCP(bp))
2623adfc5217SJeff Kirsher 		return 0;
2624adfc5217SJeff Kirsher 
2625afa13b4bSMintz Yuval 	buf = kmalloc(0x350, GFP_KERNEL);
2626afa13b4bSMintz Yuval 	if (!buf) {
262751c1a580SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM, "kmalloc failed\n");
2628afa13b4bSMintz Yuval 		rc = -ENOMEM;
2629afa13b4bSMintz Yuval 		goto test_nvram_exit;
2630afa13b4bSMintz Yuval 	}
2631afa13b4bSMintz Yuval 
263285640952SDmitry Kravkov 	rc = bnx2x_nvram_read32(bp, 0, &magic, sizeof(magic));
2633adfc5217SJeff Kirsher 	if (rc) {
263451c1a580SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
263551c1a580SMerav Sicron 		   "magic value read (rc %d)\n", rc);
2636adfc5217SJeff Kirsher 		goto test_nvram_exit;
2637adfc5217SJeff Kirsher 	}
2638adfc5217SJeff Kirsher 
2639adfc5217SJeff Kirsher 	if (magic != 0x669955aa) {
264051c1a580SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
264151c1a580SMerav Sicron 		   "wrong magic value (0x%08x)\n", magic);
2642adfc5217SJeff Kirsher 		rc = -ENODEV;
2643adfc5217SJeff Kirsher 		goto test_nvram_exit;
2644adfc5217SJeff Kirsher 	}
2645adfc5217SJeff Kirsher 
2646adfc5217SJeff Kirsher 	for (i = 0; nvram_tbl[i].size; i++) {
2647adfc5217SJeff Kirsher 
264885640952SDmitry Kravkov 		rc = bnx2x_nvram_read(bp, nvram_tbl[i].offset, buf,
2649adfc5217SJeff Kirsher 				      nvram_tbl[i].size);
2650adfc5217SJeff Kirsher 		if (rc) {
265151c1a580SMerav Sicron 			DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
2652adfc5217SJeff Kirsher 			   "nvram_tbl[%d] read data (rc %d)\n", i, rc);
2653adfc5217SJeff Kirsher 			goto test_nvram_exit;
2654adfc5217SJeff Kirsher 		}
2655adfc5217SJeff Kirsher 
265685640952SDmitry Kravkov 		crc = ether_crc_le(nvram_tbl[i].size, buf);
2657adfc5217SJeff Kirsher 		if (crc != CRC32_RESIDUAL) {
265851c1a580SMerav Sicron 			DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
265951c1a580SMerav Sicron 			   "nvram_tbl[%d] wrong crc value (0x%08x)\n", i, crc);
2660adfc5217SJeff Kirsher 			rc = -ENODEV;
2661adfc5217SJeff Kirsher 			goto test_nvram_exit;
2662adfc5217SJeff Kirsher 		}
2663adfc5217SJeff Kirsher 	}
2664adfc5217SJeff Kirsher 
2665adfc5217SJeff Kirsher test_nvram_exit:
2666afa13b4bSMintz Yuval 	kfree(buf);
2667adfc5217SJeff Kirsher 	return rc;
2668adfc5217SJeff Kirsher }
2669adfc5217SJeff Kirsher 
2670adfc5217SJeff Kirsher /* Send an EMPTY ramrod on the first queue */
2671adfc5217SJeff Kirsher static int bnx2x_test_intr(struct bnx2x *bp)
2672adfc5217SJeff Kirsher {
26733b603066SYuval Mintz 	struct bnx2x_queue_state_params params = {NULL};
2674adfc5217SJeff Kirsher 
267551c1a580SMerav Sicron 	if (!netif_running(bp->dev)) {
267651c1a580SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
267751c1a580SMerav Sicron 		   "cannot access eeprom when the interface is down\n");
2678adfc5217SJeff Kirsher 		return -ENODEV;
267951c1a580SMerav Sicron 	}
2680adfc5217SJeff Kirsher 
268115192a8cSBarak Witkowski 	params.q_obj = &bp->sp_objs->q_obj;
2682adfc5217SJeff Kirsher 	params.cmd = BNX2X_Q_CMD_EMPTY;
2683adfc5217SJeff Kirsher 
2684adfc5217SJeff Kirsher 	__set_bit(RAMROD_COMP_WAIT, &params.ramrod_flags);
2685adfc5217SJeff Kirsher 
2686adfc5217SJeff Kirsher 	return bnx2x_queue_state_change(bp, &params);
2687adfc5217SJeff Kirsher }
2688adfc5217SJeff Kirsher 
2689adfc5217SJeff Kirsher static void bnx2x_self_test(struct net_device *dev,
2690adfc5217SJeff Kirsher 			    struct ethtool_test *etest, u64 *buf)
2691adfc5217SJeff Kirsher {
2692adfc5217SJeff Kirsher 	struct bnx2x *bp = netdev_priv(dev);
2693a336ca7cSYaniv Rosner 	u8 is_serdes, link_up;
2694a336ca7cSYaniv Rosner 	int rc, cnt = 0;
2695cf2c1df6SMerav Sicron 
2696adfc5217SJeff Kirsher 	if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
269751c1a580SMerav Sicron 		netdev_err(bp->dev,
269851c1a580SMerav Sicron 			   "Handling parity error recovery. Try again later\n");
2699adfc5217SJeff Kirsher 		etest->flags |= ETH_TEST_FL_FAILED;
2700adfc5217SJeff Kirsher 		return;
2701adfc5217SJeff Kirsher 	}
27022de67439SYuval Mintz 
27038970b2e4SMerav Sicron 	DP(BNX2X_MSG_ETHTOOL,
27048970b2e4SMerav Sicron 	   "Self-test command parameters: offline = %d, external_lb = %d\n",
27058970b2e4SMerav Sicron 	   (etest->flags & ETH_TEST_FL_OFFLINE),
27068970b2e4SMerav Sicron 	   (etest->flags & ETH_TEST_FL_EXTERNAL_LB)>>2);
2707adfc5217SJeff Kirsher 
2708cf2c1df6SMerav Sicron 	memset(buf, 0, sizeof(u64) * BNX2X_NUM_TESTS(bp));
2709adfc5217SJeff Kirsher 
2710cf2c1df6SMerav Sicron 	if (!netif_running(dev)) {
2711cf2c1df6SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL,
2712cf2c1df6SMerav Sicron 		   "Can't perform self-test when interface is down\n");
2713adfc5217SJeff Kirsher 		return;
2714cf2c1df6SMerav Sicron 	}
2715adfc5217SJeff Kirsher 
2716adfc5217SJeff Kirsher 	is_serdes = (bp->link_vars.link_status & LINK_STATUS_SERDES_LINK) > 0;
2717a336ca7cSYaniv Rosner 	link_up = bp->link_vars.link_up;
2718cf2c1df6SMerav Sicron 	/* offline tests are not supported in MF mode */
2719cf2c1df6SMerav Sicron 	if ((etest->flags & ETH_TEST_FL_OFFLINE) && !IS_MF(bp)) {
2720adfc5217SJeff Kirsher 		int port = BP_PORT(bp);
2721adfc5217SJeff Kirsher 		u32 val;
2722adfc5217SJeff Kirsher 
2723adfc5217SJeff Kirsher 		/* save current value of input enable for TX port IF */
2724adfc5217SJeff Kirsher 		val = REG_RD(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4);
2725adfc5217SJeff Kirsher 		/* disable input for TX port IF */
2726adfc5217SJeff Kirsher 		REG_WR(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4, 0);
2727adfc5217SJeff Kirsher 
27285d07d868SYuval Mintz 		bnx2x_nic_unload(bp, UNLOAD_NORMAL, false);
2729cf2c1df6SMerav Sicron 		rc = bnx2x_nic_load(bp, LOAD_DIAG);
2730cf2c1df6SMerav Sicron 		if (rc) {
2731cf2c1df6SMerav Sicron 			etest->flags |= ETH_TEST_FL_FAILED;
2732cf2c1df6SMerav Sicron 			DP(BNX2X_MSG_ETHTOOL,
2733cf2c1df6SMerav Sicron 			   "Can't perform self-test, nic_load (for offline) failed\n");
2734cf2c1df6SMerav Sicron 			return;
2735cf2c1df6SMerav Sicron 		}
2736cf2c1df6SMerav Sicron 
2737adfc5217SJeff Kirsher 		/* wait until link state is restored */
2738adfc5217SJeff Kirsher 		bnx2x_wait_for_link(bp, 1, is_serdes);
2739adfc5217SJeff Kirsher 
2740adfc5217SJeff Kirsher 		if (bnx2x_test_registers(bp) != 0) {
2741adfc5217SJeff Kirsher 			buf[0] = 1;
2742adfc5217SJeff Kirsher 			etest->flags |= ETH_TEST_FL_FAILED;
2743adfc5217SJeff Kirsher 		}
2744adfc5217SJeff Kirsher 		if (bnx2x_test_memory(bp) != 0) {
2745adfc5217SJeff Kirsher 			buf[1] = 1;
2746adfc5217SJeff Kirsher 			etest->flags |= ETH_TEST_FL_FAILED;
2747adfc5217SJeff Kirsher 		}
2748adfc5217SJeff Kirsher 
27498970b2e4SMerav Sicron 		buf[2] = bnx2x_test_loopback(bp); /* internal LB */
2750adfc5217SJeff Kirsher 		if (buf[2] != 0)
2751adfc5217SJeff Kirsher 			etest->flags |= ETH_TEST_FL_FAILED;
2752adfc5217SJeff Kirsher 
27538970b2e4SMerav Sicron 		if (etest->flags & ETH_TEST_FL_EXTERNAL_LB) {
27548970b2e4SMerav Sicron 			buf[3] = bnx2x_test_ext_loopback(bp); /* external LB */
27558970b2e4SMerav Sicron 			if (buf[3] != 0)
27568970b2e4SMerav Sicron 				etest->flags |= ETH_TEST_FL_FAILED;
27578970b2e4SMerav Sicron 			etest->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE;
27588970b2e4SMerav Sicron 		}
27598970b2e4SMerav Sicron 
27605d07d868SYuval Mintz 		bnx2x_nic_unload(bp, UNLOAD_NORMAL, false);
2761adfc5217SJeff Kirsher 
2762adfc5217SJeff Kirsher 		/* restore input for TX port IF */
2763adfc5217SJeff Kirsher 		REG_WR(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4, val);
2764cf2c1df6SMerav Sicron 		rc = bnx2x_nic_load(bp, LOAD_NORMAL);
2765cf2c1df6SMerav Sicron 		if (rc) {
2766cf2c1df6SMerav Sicron 			etest->flags |= ETH_TEST_FL_FAILED;
2767cf2c1df6SMerav Sicron 			DP(BNX2X_MSG_ETHTOOL,
2768cf2c1df6SMerav Sicron 			   "Can't perform self-test, nic_load (for online) failed\n");
2769cf2c1df6SMerav Sicron 			return;
2770cf2c1df6SMerav Sicron 		}
2771adfc5217SJeff Kirsher 		/* wait until link state is restored */
2772adfc5217SJeff Kirsher 		bnx2x_wait_for_link(bp, link_up, is_serdes);
2773adfc5217SJeff Kirsher 	}
2774adfc5217SJeff Kirsher 	if (bnx2x_test_nvram(bp) != 0) {
2775cf2c1df6SMerav Sicron 		if (!IS_MF(bp))
27768970b2e4SMerav Sicron 			buf[4] = 1;
2777cf2c1df6SMerav Sicron 		else
2778cf2c1df6SMerav Sicron 			buf[0] = 1;
2779adfc5217SJeff Kirsher 		etest->flags |= ETH_TEST_FL_FAILED;
2780adfc5217SJeff Kirsher 	}
2781adfc5217SJeff Kirsher 	if (bnx2x_test_intr(bp) != 0) {
2782cf2c1df6SMerav Sicron 		if (!IS_MF(bp))
27838970b2e4SMerav Sicron 			buf[5] = 1;
2784cf2c1df6SMerav Sicron 		else
2785cf2c1df6SMerav Sicron 			buf[1] = 1;
2786adfc5217SJeff Kirsher 		etest->flags |= ETH_TEST_FL_FAILED;
2787adfc5217SJeff Kirsher 	}
2788adfc5217SJeff Kirsher 
2789a336ca7cSYaniv Rosner 	if (link_up) {
2790a336ca7cSYaniv Rosner 		cnt = 100;
2791a336ca7cSYaniv Rosner 		while (bnx2x_link_test(bp, is_serdes) && --cnt)
2792a336ca7cSYaniv Rosner 			msleep(20);
2793a336ca7cSYaniv Rosner 	}
2794a336ca7cSYaniv Rosner 
2795a336ca7cSYaniv Rosner 	if (!cnt) {
2796cf2c1df6SMerav Sicron 		if (!IS_MF(bp))
27978970b2e4SMerav Sicron 			buf[6] = 1;
2798cf2c1df6SMerav Sicron 		else
2799cf2c1df6SMerav Sicron 			buf[2] = 1;
2800adfc5217SJeff Kirsher 		etest->flags |= ETH_TEST_FL_FAILED;
2801adfc5217SJeff Kirsher 	}
2802adfc5217SJeff Kirsher }
2803adfc5217SJeff Kirsher 
2804adfc5217SJeff Kirsher #define IS_PORT_STAT(i) \
2805adfc5217SJeff Kirsher 	((bnx2x_stats_arr[i].flags & STATS_FLAGS_BOTH) == STATS_FLAGS_PORT)
2806adfc5217SJeff Kirsher #define IS_FUNC_STAT(i)		(bnx2x_stats_arr[i].flags & STATS_FLAGS_FUNC)
2807adfc5217SJeff Kirsher #define IS_MF_MODE_STAT(bp) \
2808adfc5217SJeff Kirsher 			(IS_MF(bp) && !(bp->msg_enable & BNX2X_MSG_STATS))
2809adfc5217SJeff Kirsher 
2810adfc5217SJeff Kirsher /* ethtool statistics are displayed for all regular ethernet queues and the
2811adfc5217SJeff Kirsher  * fcoe L2 queue if not disabled
2812adfc5217SJeff Kirsher  */
28131191cb83SEric Dumazet static int bnx2x_num_stat_queues(struct bnx2x *bp)
2814adfc5217SJeff Kirsher {
2815adfc5217SJeff Kirsher 	return BNX2X_NUM_ETH_QUEUES(bp);
2816adfc5217SJeff Kirsher }
2817adfc5217SJeff Kirsher 
2818adfc5217SJeff Kirsher static int bnx2x_get_sset_count(struct net_device *dev, int stringset)
2819adfc5217SJeff Kirsher {
2820adfc5217SJeff Kirsher 	struct bnx2x *bp = netdev_priv(dev);
2821adfc5217SJeff Kirsher 	int i, num_stats;
2822adfc5217SJeff Kirsher 
2823adfc5217SJeff Kirsher 	switch (stringset) {
2824adfc5217SJeff Kirsher 	case ETH_SS_STATS:
2825adfc5217SJeff Kirsher 		if (is_multi(bp)) {
2826adfc5217SJeff Kirsher 			num_stats = bnx2x_num_stat_queues(bp) *
2827adfc5217SJeff Kirsher 						BNX2X_NUM_Q_STATS;
2828d5e83632SYuval Mintz 		} else
2829adfc5217SJeff Kirsher 			num_stats = 0;
2830d5e83632SYuval Mintz 		if (IS_MF_MODE_STAT(bp)) {
2831adfc5217SJeff Kirsher 			for (i = 0; i < BNX2X_NUM_STATS; i++)
2832adfc5217SJeff Kirsher 				if (IS_FUNC_STAT(i))
2833adfc5217SJeff Kirsher 					num_stats++;
2834adfc5217SJeff Kirsher 		} else
2835d5e83632SYuval Mintz 			num_stats += BNX2X_NUM_STATS;
2836d5e83632SYuval Mintz 
2837adfc5217SJeff Kirsher 		return num_stats;
2838adfc5217SJeff Kirsher 
2839adfc5217SJeff Kirsher 	case ETH_SS_TEST:
2840cf2c1df6SMerav Sicron 		return BNX2X_NUM_TESTS(bp);
2841adfc5217SJeff Kirsher 
2842adfc5217SJeff Kirsher 	default:
2843adfc5217SJeff Kirsher 		return -EINVAL;
2844adfc5217SJeff Kirsher 	}
2845adfc5217SJeff Kirsher }
2846adfc5217SJeff Kirsher 
2847adfc5217SJeff Kirsher static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
2848adfc5217SJeff Kirsher {
2849adfc5217SJeff Kirsher 	struct bnx2x *bp = netdev_priv(dev);
28505889335cSMerav Sicron 	int i, j, k, start;
2851adfc5217SJeff Kirsher 	char queue_name[MAX_QUEUE_NAME_LEN+1];
2852adfc5217SJeff Kirsher 
2853adfc5217SJeff Kirsher 	switch (stringset) {
2854adfc5217SJeff Kirsher 	case ETH_SS_STATS:
2855adfc5217SJeff Kirsher 		k = 0;
2856d5e83632SYuval Mintz 		if (is_multi(bp)) {
2857adfc5217SJeff Kirsher 			for_each_eth_queue(bp, i) {
2858adfc5217SJeff Kirsher 				memset(queue_name, 0, sizeof(queue_name));
2859adfc5217SJeff Kirsher 				sprintf(queue_name, "%d", i);
2860adfc5217SJeff Kirsher 				for (j = 0; j < BNX2X_NUM_Q_STATS; j++)
2861adfc5217SJeff Kirsher 					snprintf(buf + (k + j)*ETH_GSTRING_LEN,
2862adfc5217SJeff Kirsher 						ETH_GSTRING_LEN,
2863adfc5217SJeff Kirsher 						bnx2x_q_stats_arr[j].string,
2864adfc5217SJeff Kirsher 						queue_name);
2865adfc5217SJeff Kirsher 				k += BNX2X_NUM_Q_STATS;
2866adfc5217SJeff Kirsher 			}
2867d5e83632SYuval Mintz 		}
2868d5e83632SYuval Mintz 
2869d5e83632SYuval Mintz 
2870adfc5217SJeff Kirsher 		for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
2871adfc5217SJeff Kirsher 			if (IS_MF_MODE_STAT(bp) && IS_PORT_STAT(i))
2872adfc5217SJeff Kirsher 				continue;
2873d5e83632SYuval Mintz 			strcpy(buf + (k + j)*ETH_GSTRING_LEN,
2874adfc5217SJeff Kirsher 				   bnx2x_stats_arr[i].string);
2875adfc5217SJeff Kirsher 			j++;
2876adfc5217SJeff Kirsher 		}
2877d5e83632SYuval Mintz 
2878adfc5217SJeff Kirsher 		break;
2879adfc5217SJeff Kirsher 
2880adfc5217SJeff Kirsher 	case ETH_SS_TEST:
2881cf2c1df6SMerav Sicron 		/* First 4 tests cannot be done in MF mode */
2882cf2c1df6SMerav Sicron 		if (!IS_MF(bp))
2883cf2c1df6SMerav Sicron 			start = 0;
2884cf2c1df6SMerav Sicron 		else
2885cf2c1df6SMerav Sicron 			start = 4;
28865889335cSMerav Sicron 		memcpy(buf, bnx2x_tests_str_arr + start,
28875889335cSMerav Sicron 		       ETH_GSTRING_LEN * BNX2X_NUM_TESTS(bp));
2888adfc5217SJeff Kirsher 	}
2889adfc5217SJeff Kirsher }
2890adfc5217SJeff Kirsher 
2891adfc5217SJeff Kirsher static void bnx2x_get_ethtool_stats(struct net_device *dev,
2892adfc5217SJeff Kirsher 				    struct ethtool_stats *stats, u64 *buf)
2893adfc5217SJeff Kirsher {
2894adfc5217SJeff Kirsher 	struct bnx2x *bp = netdev_priv(dev);
2895adfc5217SJeff Kirsher 	u32 *hw_stats, *offset;
2896d5e83632SYuval Mintz 	int i, j, k = 0;
2897adfc5217SJeff Kirsher 
2898adfc5217SJeff Kirsher 	if (is_multi(bp)) {
2899adfc5217SJeff Kirsher 		for_each_eth_queue(bp, i) {
290015192a8cSBarak Witkowski 			hw_stats = (u32 *)&bp->fp_stats[i].eth_q_stats;
2901adfc5217SJeff Kirsher 			for (j = 0; j < BNX2X_NUM_Q_STATS; j++) {
2902adfc5217SJeff Kirsher 				if (bnx2x_q_stats_arr[j].size == 0) {
2903adfc5217SJeff Kirsher 					/* skip this counter */
2904adfc5217SJeff Kirsher 					buf[k + j] = 0;
2905adfc5217SJeff Kirsher 					continue;
2906adfc5217SJeff Kirsher 				}
2907adfc5217SJeff Kirsher 				offset = (hw_stats +
2908adfc5217SJeff Kirsher 					  bnx2x_q_stats_arr[j].offset);
2909adfc5217SJeff Kirsher 				if (bnx2x_q_stats_arr[j].size == 4) {
2910adfc5217SJeff Kirsher 					/* 4-byte counter */
2911adfc5217SJeff Kirsher 					buf[k + j] = (u64) *offset;
2912adfc5217SJeff Kirsher 					continue;
2913adfc5217SJeff Kirsher 				}
2914adfc5217SJeff Kirsher 				/* 8-byte counter */
2915adfc5217SJeff Kirsher 				buf[k + j] = HILO_U64(*offset, *(offset + 1));
2916adfc5217SJeff Kirsher 			}
2917adfc5217SJeff Kirsher 			k += BNX2X_NUM_Q_STATS;
2918adfc5217SJeff Kirsher 		}
2919adfc5217SJeff Kirsher 	}
2920d5e83632SYuval Mintz 
2921adfc5217SJeff Kirsher 	hw_stats = (u32 *)&bp->eth_stats;
2922adfc5217SJeff Kirsher 	for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
2923adfc5217SJeff Kirsher 		if (IS_MF_MODE_STAT(bp) && IS_PORT_STAT(i))
2924adfc5217SJeff Kirsher 			continue;
2925adfc5217SJeff Kirsher 		if (bnx2x_stats_arr[i].size == 0) {
2926adfc5217SJeff Kirsher 			/* skip this counter */
2927d5e83632SYuval Mintz 			buf[k + j] = 0;
2928adfc5217SJeff Kirsher 			j++;
2929adfc5217SJeff Kirsher 			continue;
2930adfc5217SJeff Kirsher 		}
2931adfc5217SJeff Kirsher 		offset = (hw_stats + bnx2x_stats_arr[i].offset);
2932adfc5217SJeff Kirsher 		if (bnx2x_stats_arr[i].size == 4) {
2933adfc5217SJeff Kirsher 			/* 4-byte counter */
2934d5e83632SYuval Mintz 			buf[k + j] = (u64) *offset;
2935adfc5217SJeff Kirsher 			j++;
2936adfc5217SJeff Kirsher 			continue;
2937adfc5217SJeff Kirsher 		}
2938adfc5217SJeff Kirsher 		/* 8-byte counter */
2939d5e83632SYuval Mintz 		buf[k + j] = HILO_U64(*offset, *(offset + 1));
2940adfc5217SJeff Kirsher 		j++;
2941adfc5217SJeff Kirsher 	}
2942adfc5217SJeff Kirsher }
2943adfc5217SJeff Kirsher 
2944adfc5217SJeff Kirsher static int bnx2x_set_phys_id(struct net_device *dev,
2945adfc5217SJeff Kirsher 			     enum ethtool_phys_id_state state)
2946adfc5217SJeff Kirsher {
2947adfc5217SJeff Kirsher 	struct bnx2x *bp = netdev_priv(dev);
2948adfc5217SJeff Kirsher 
294951c1a580SMerav Sicron 	if (!netif_running(dev)) {
295051c1a580SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
295151c1a580SMerav Sicron 		   "cannot access eeprom when the interface is down\n");
2952adfc5217SJeff Kirsher 		return -EAGAIN;
295351c1a580SMerav Sicron 	}
2954adfc5217SJeff Kirsher 
295551c1a580SMerav Sicron 	if (!bp->port.pmf) {
295651c1a580SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL, "Interface is not pmf\n");
2957adfc5217SJeff Kirsher 		return -EOPNOTSUPP;
295851c1a580SMerav Sicron 	}
2959adfc5217SJeff Kirsher 
2960adfc5217SJeff Kirsher 	switch (state) {
2961adfc5217SJeff Kirsher 	case ETHTOOL_ID_ACTIVE:
2962adfc5217SJeff Kirsher 		return 1;	/* cycle on/off once per second */
2963adfc5217SJeff Kirsher 
2964adfc5217SJeff Kirsher 	case ETHTOOL_ID_ON:
29658203c4b6SYaniv Rosner 		bnx2x_acquire_phy_lock(bp);
2966adfc5217SJeff Kirsher 		bnx2x_set_led(&bp->link_params, &bp->link_vars,
2967adfc5217SJeff Kirsher 			      LED_MODE_ON, SPEED_1000);
29688203c4b6SYaniv Rosner 		bnx2x_release_phy_lock(bp);
2969adfc5217SJeff Kirsher 		break;
2970adfc5217SJeff Kirsher 
2971adfc5217SJeff Kirsher 	case ETHTOOL_ID_OFF:
29728203c4b6SYaniv Rosner 		bnx2x_acquire_phy_lock(bp);
2973adfc5217SJeff Kirsher 		bnx2x_set_led(&bp->link_params, &bp->link_vars,
2974adfc5217SJeff Kirsher 			      LED_MODE_FRONT_PANEL_OFF, 0);
29758203c4b6SYaniv Rosner 		bnx2x_release_phy_lock(bp);
2976adfc5217SJeff Kirsher 		break;
2977adfc5217SJeff Kirsher 
2978adfc5217SJeff Kirsher 	case ETHTOOL_ID_INACTIVE:
29798203c4b6SYaniv Rosner 		bnx2x_acquire_phy_lock(bp);
2980adfc5217SJeff Kirsher 		bnx2x_set_led(&bp->link_params, &bp->link_vars,
2981adfc5217SJeff Kirsher 			      LED_MODE_OPER,
2982adfc5217SJeff Kirsher 			      bp->link_vars.line_speed);
29838203c4b6SYaniv Rosner 		bnx2x_release_phy_lock(bp);
2984adfc5217SJeff Kirsher 	}
2985adfc5217SJeff Kirsher 
2986adfc5217SJeff Kirsher 	return 0;
2987adfc5217SJeff Kirsher }
2988adfc5217SJeff Kirsher 
29895d317c6aSMerav Sicron static int bnx2x_get_rss_flags(struct bnx2x *bp, struct ethtool_rxnfc *info)
29905d317c6aSMerav Sicron {
29915d317c6aSMerav Sicron 
29925d317c6aSMerav Sicron 	switch (info->flow_type) {
29935d317c6aSMerav Sicron 	case TCP_V4_FLOW:
29945d317c6aSMerav Sicron 	case TCP_V6_FLOW:
29955d317c6aSMerav Sicron 		info->data = RXH_IP_SRC | RXH_IP_DST |
29965d317c6aSMerav Sicron 			     RXH_L4_B_0_1 | RXH_L4_B_2_3;
29975d317c6aSMerav Sicron 		break;
29985d317c6aSMerav Sicron 	case UDP_V4_FLOW:
29995d317c6aSMerav Sicron 		if (bp->rss_conf_obj.udp_rss_v4)
30005d317c6aSMerav Sicron 			info->data = RXH_IP_SRC | RXH_IP_DST |
30015d317c6aSMerav Sicron 				     RXH_L4_B_0_1 | RXH_L4_B_2_3;
30025d317c6aSMerav Sicron 		else
30035d317c6aSMerav Sicron 			info->data = RXH_IP_SRC | RXH_IP_DST;
30045d317c6aSMerav Sicron 		break;
30055d317c6aSMerav Sicron 	case UDP_V6_FLOW:
30065d317c6aSMerav Sicron 		if (bp->rss_conf_obj.udp_rss_v6)
30075d317c6aSMerav Sicron 			info->data = RXH_IP_SRC | RXH_IP_DST |
30085d317c6aSMerav Sicron 				     RXH_L4_B_0_1 | RXH_L4_B_2_3;
30095d317c6aSMerav Sicron 		else
30105d317c6aSMerav Sicron 			info->data = RXH_IP_SRC | RXH_IP_DST;
30115d317c6aSMerav Sicron 		break;
30125d317c6aSMerav Sicron 	case IPV4_FLOW:
30135d317c6aSMerav Sicron 	case IPV6_FLOW:
30145d317c6aSMerav Sicron 		info->data = RXH_IP_SRC | RXH_IP_DST;
30155d317c6aSMerav Sicron 		break;
30165d317c6aSMerav Sicron 	default:
30175d317c6aSMerav Sicron 		info->data = 0;
30185d317c6aSMerav Sicron 		break;
30195d317c6aSMerav Sicron 	}
30205d317c6aSMerav Sicron 
30215d317c6aSMerav Sicron 	return 0;
30225d317c6aSMerav Sicron }
30235d317c6aSMerav Sicron 
3024adfc5217SJeff Kirsher static int bnx2x_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
3025815c7db5SBen Hutchings 			   u32 *rules __always_unused)
3026adfc5217SJeff Kirsher {
3027adfc5217SJeff Kirsher 	struct bnx2x *bp = netdev_priv(dev);
3028adfc5217SJeff Kirsher 
3029adfc5217SJeff Kirsher 	switch (info->cmd) {
3030adfc5217SJeff Kirsher 	case ETHTOOL_GRXRINGS:
3031adfc5217SJeff Kirsher 		info->data = BNX2X_NUM_ETH_QUEUES(bp);
3032adfc5217SJeff Kirsher 		return 0;
30335d317c6aSMerav Sicron 	case ETHTOOL_GRXFH:
30345d317c6aSMerav Sicron 		return bnx2x_get_rss_flags(bp, info);
30355d317c6aSMerav Sicron 	default:
30365d317c6aSMerav Sicron 		DP(BNX2X_MSG_ETHTOOL, "Command parameters not supported\n");
30375d317c6aSMerav Sicron 		return -EOPNOTSUPP;
30385d317c6aSMerav Sicron 	}
30395d317c6aSMerav Sicron }
3040adfc5217SJeff Kirsher 
30415d317c6aSMerav Sicron static int bnx2x_set_rss_flags(struct bnx2x *bp, struct ethtool_rxnfc *info)
30425d317c6aSMerav Sicron {
30435d317c6aSMerav Sicron 	int udp_rss_requested;
30445d317c6aSMerav Sicron 
30455d317c6aSMerav Sicron 	DP(BNX2X_MSG_ETHTOOL,
30465d317c6aSMerav Sicron 	   "Set rss flags command parameters: flow type = %d, data = %llu\n",
30475d317c6aSMerav Sicron 	   info->flow_type, info->data);
30485d317c6aSMerav Sicron 
30495d317c6aSMerav Sicron 	switch (info->flow_type) {
30505d317c6aSMerav Sicron 	case TCP_V4_FLOW:
30515d317c6aSMerav Sicron 	case TCP_V6_FLOW:
30525d317c6aSMerav Sicron 		/* For TCP only 4-tupple hash is supported */
30535d317c6aSMerav Sicron 		if (info->data ^ (RXH_IP_SRC | RXH_IP_DST |
30545d317c6aSMerav Sicron 				  RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
30555d317c6aSMerav Sicron 			DP(BNX2X_MSG_ETHTOOL,
30565d317c6aSMerav Sicron 			   "Command parameters not supported\n");
30575d317c6aSMerav Sicron 			return -EINVAL;
30585d317c6aSMerav Sicron 		}
30592de67439SYuval Mintz 		return 0;
30605d317c6aSMerav Sicron 
30615d317c6aSMerav Sicron 	case UDP_V4_FLOW:
30625d317c6aSMerav Sicron 	case UDP_V6_FLOW:
30635d317c6aSMerav Sicron 		/* For UDP either 2-tupple hash or 4-tupple hash is supported */
30645d317c6aSMerav Sicron 		if (info->data == (RXH_IP_SRC | RXH_IP_DST |
30655d317c6aSMerav Sicron 				   RXH_L4_B_0_1 | RXH_L4_B_2_3))
30665d317c6aSMerav Sicron 			udp_rss_requested = 1;
30675d317c6aSMerav Sicron 		else if (info->data == (RXH_IP_SRC | RXH_IP_DST))
30685d317c6aSMerav Sicron 			udp_rss_requested = 0;
30695d317c6aSMerav Sicron 		else
30705d317c6aSMerav Sicron 			return -EINVAL;
30715d317c6aSMerav Sicron 		if ((info->flow_type == UDP_V4_FLOW) &&
30725d317c6aSMerav Sicron 		    (bp->rss_conf_obj.udp_rss_v4 != udp_rss_requested)) {
30735d317c6aSMerav Sicron 			bp->rss_conf_obj.udp_rss_v4 = udp_rss_requested;
30745d317c6aSMerav Sicron 			DP(BNX2X_MSG_ETHTOOL,
30755d317c6aSMerav Sicron 			   "rss re-configured, UDP 4-tupple %s\n",
30765d317c6aSMerav Sicron 			   udp_rss_requested ? "enabled" : "disabled");
30775d317c6aSMerav Sicron 			return bnx2x_config_rss_pf(bp, &bp->rss_conf_obj, 0);
30785d317c6aSMerav Sicron 		} else if ((info->flow_type == UDP_V6_FLOW) &&
30795d317c6aSMerav Sicron 			   (bp->rss_conf_obj.udp_rss_v6 != udp_rss_requested)) {
30805d317c6aSMerav Sicron 			bp->rss_conf_obj.udp_rss_v6 = udp_rss_requested;
30815d317c6aSMerav Sicron 			DP(BNX2X_MSG_ETHTOOL,
30825d317c6aSMerav Sicron 			   "rss re-configured, UDP 4-tupple %s\n",
30835d317c6aSMerav Sicron 			   udp_rss_requested ? "enabled" : "disabled");
3084337da3e3SDan Carpenter 			return bnx2x_config_rss_pf(bp, &bp->rss_conf_obj, 0);
30855d317c6aSMerav Sicron 		}
3086924d75abSYuval Mintz 		return 0;
3087924d75abSYuval Mintz 
30885d317c6aSMerav Sicron 	case IPV4_FLOW:
30895d317c6aSMerav Sicron 	case IPV6_FLOW:
30905d317c6aSMerav Sicron 		/* For IP only 2-tupple hash is supported */
30915d317c6aSMerav Sicron 		if (info->data ^ (RXH_IP_SRC | RXH_IP_DST)) {
30925d317c6aSMerav Sicron 			DP(BNX2X_MSG_ETHTOOL,
30935d317c6aSMerav Sicron 			   "Command parameters not supported\n");
30945d317c6aSMerav Sicron 			return -EINVAL;
30955d317c6aSMerav Sicron 		}
3096924d75abSYuval Mintz 		return 0;
3097924d75abSYuval Mintz 
30985d317c6aSMerav Sicron 	case SCTP_V4_FLOW:
30995d317c6aSMerav Sicron 	case AH_ESP_V4_FLOW:
31005d317c6aSMerav Sicron 	case AH_V4_FLOW:
31015d317c6aSMerav Sicron 	case ESP_V4_FLOW:
31025d317c6aSMerav Sicron 	case SCTP_V6_FLOW:
31035d317c6aSMerav Sicron 	case AH_ESP_V6_FLOW:
31045d317c6aSMerav Sicron 	case AH_V6_FLOW:
31055d317c6aSMerav Sicron 	case ESP_V6_FLOW:
31065d317c6aSMerav Sicron 	case IP_USER_FLOW:
31075d317c6aSMerav Sicron 	case ETHER_FLOW:
31085d317c6aSMerav Sicron 		/* RSS is not supported for these protocols */
31095d317c6aSMerav Sicron 		if (info->data) {
31105d317c6aSMerav Sicron 			DP(BNX2X_MSG_ETHTOOL,
31115d317c6aSMerav Sicron 			   "Command parameters not supported\n");
31125d317c6aSMerav Sicron 			return -EINVAL;
31135d317c6aSMerav Sicron 		}
3114924d75abSYuval Mintz 		return 0;
3115924d75abSYuval Mintz 
31165d317c6aSMerav Sicron 	default:
31175d317c6aSMerav Sicron 		return -EINVAL;
31185d317c6aSMerav Sicron 	}
31195d317c6aSMerav Sicron }
31205d317c6aSMerav Sicron 
31215d317c6aSMerav Sicron static int bnx2x_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
31225d317c6aSMerav Sicron {
31235d317c6aSMerav Sicron 	struct bnx2x *bp = netdev_priv(dev);
31245d317c6aSMerav Sicron 
31255d317c6aSMerav Sicron 	switch (info->cmd) {
31265d317c6aSMerav Sicron 	case ETHTOOL_SRXFH:
31275d317c6aSMerav Sicron 		return bnx2x_set_rss_flags(bp, info);
3128adfc5217SJeff Kirsher 	default:
312951c1a580SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL, "Command parameters not supported\n");
3130adfc5217SJeff Kirsher 		return -EOPNOTSUPP;
3131adfc5217SJeff Kirsher 	}
3132adfc5217SJeff Kirsher }
3133adfc5217SJeff Kirsher 
31347850f63fSBen Hutchings static u32 bnx2x_get_rxfh_indir_size(struct net_device *dev)
3135adfc5217SJeff Kirsher {
313696305234SDmitry Kravkov 	return T_ETH_INDIRECTION_TABLE_SIZE;
31377850f63fSBen Hutchings }
31387850f63fSBen Hutchings 
31397850f63fSBen Hutchings static int bnx2x_get_rxfh_indir(struct net_device *dev, u32 *indir)
31407850f63fSBen Hutchings {
31417850f63fSBen Hutchings 	struct bnx2x *bp = netdev_priv(dev);
3142adfc5217SJeff Kirsher 	u8 ind_table[T_ETH_INDIRECTION_TABLE_SIZE] = {0};
3143adfc5217SJeff Kirsher 	size_t i;
3144adfc5217SJeff Kirsher 
3145adfc5217SJeff Kirsher 	/* Get the current configuration of the RSS indirection table */
3146adfc5217SJeff Kirsher 	bnx2x_get_rss_ind_table(&bp->rss_conf_obj, ind_table);
3147adfc5217SJeff Kirsher 
3148adfc5217SJeff Kirsher 	/*
3149adfc5217SJeff Kirsher 	 * We can't use a memcpy() as an internal storage of an
3150adfc5217SJeff Kirsher 	 * indirection table is a u8 array while indir->ring_index
3151adfc5217SJeff Kirsher 	 * points to an array of u32.
3152adfc5217SJeff Kirsher 	 *
3153adfc5217SJeff Kirsher 	 * Indirection table contains the FW Client IDs, so we need to
3154adfc5217SJeff Kirsher 	 * align the returned table to the Client ID of the leading RSS
3155adfc5217SJeff Kirsher 	 * queue.
3156adfc5217SJeff Kirsher 	 */
31577850f63fSBen Hutchings 	for (i = 0; i < T_ETH_INDIRECTION_TABLE_SIZE; i++)
31587850f63fSBen Hutchings 		indir[i] = ind_table[i] - bp->fp->cl_id;
3159adfc5217SJeff Kirsher 
3160adfc5217SJeff Kirsher 	return 0;
3161adfc5217SJeff Kirsher }
3162adfc5217SJeff Kirsher 
31637850f63fSBen Hutchings static int bnx2x_set_rxfh_indir(struct net_device *dev, const u32 *indir)
3164adfc5217SJeff Kirsher {
3165adfc5217SJeff Kirsher 	struct bnx2x *bp = netdev_priv(dev);
3166adfc5217SJeff Kirsher 	size_t i;
3167adfc5217SJeff Kirsher 
3168adfc5217SJeff Kirsher 	for (i = 0; i < T_ETH_INDIRECTION_TABLE_SIZE; i++) {
3169adfc5217SJeff Kirsher 		/*
3170adfc5217SJeff Kirsher 		 * The same as in bnx2x_get_rxfh_indir: we can't use a memcpy()
3171adfc5217SJeff Kirsher 		 * as an internal storage of an indirection table is a u8 array
3172adfc5217SJeff Kirsher 		 * while indir->ring_index points to an array of u32.
3173adfc5217SJeff Kirsher 		 *
3174adfc5217SJeff Kirsher 		 * Indirection table contains the FW Client IDs, so we need to
3175adfc5217SJeff Kirsher 		 * align the received table to the Client ID of the leading RSS
3176adfc5217SJeff Kirsher 		 * queue
3177adfc5217SJeff Kirsher 		 */
31785d317c6aSMerav Sicron 		bp->rss_conf_obj.ind_table[i] = indir[i] + bp->fp->cl_id;
3179adfc5217SJeff Kirsher 	}
3180adfc5217SJeff Kirsher 
31815d317c6aSMerav Sicron 	return bnx2x_config_rss_eth(bp, false);
3182adfc5217SJeff Kirsher }
3183adfc5217SJeff Kirsher 
31840e8d2ec5SMerav Sicron /**
31850e8d2ec5SMerav Sicron  * bnx2x_get_channels - gets the number of RSS queues.
31860e8d2ec5SMerav Sicron  *
31870e8d2ec5SMerav Sicron  * @dev:		net device
31880e8d2ec5SMerav Sicron  * @channels:		returns the number of max / current queues
31890e8d2ec5SMerav Sicron  */
31900e8d2ec5SMerav Sicron static void bnx2x_get_channels(struct net_device *dev,
31910e8d2ec5SMerav Sicron 			       struct ethtool_channels *channels)
31920e8d2ec5SMerav Sicron {
31930e8d2ec5SMerav Sicron 	struct bnx2x *bp = netdev_priv(dev);
31940e8d2ec5SMerav Sicron 
31950e8d2ec5SMerav Sicron 	channels->max_combined = BNX2X_MAX_RSS_COUNT(bp);
31960e8d2ec5SMerav Sicron 	channels->combined_count = BNX2X_NUM_ETH_QUEUES(bp);
31970e8d2ec5SMerav Sicron }
31980e8d2ec5SMerav Sicron 
31990e8d2ec5SMerav Sicron /**
32000e8d2ec5SMerav Sicron  * bnx2x_change_num_queues - change the number of RSS queues.
32010e8d2ec5SMerav Sicron  *
32020e8d2ec5SMerav Sicron  * @bp:			bnx2x private structure
32030e8d2ec5SMerav Sicron  *
32040e8d2ec5SMerav Sicron  * Re-configure interrupt mode to get the new number of MSI-X
32050e8d2ec5SMerav Sicron  * vectors and re-add NAPI objects.
32060e8d2ec5SMerav Sicron  */
32070e8d2ec5SMerav Sicron static void bnx2x_change_num_queues(struct bnx2x *bp, int num_rss)
32080e8d2ec5SMerav Sicron {
32090e8d2ec5SMerav Sicron 	bnx2x_disable_msi(bp);
321055c11941SMerav Sicron 	bp->num_ethernet_queues = num_rss;
321155c11941SMerav Sicron 	bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
321255c11941SMerav Sicron 	BNX2X_DEV_INFO("set number of queues to %d\n", bp->num_queues);
32130e8d2ec5SMerav Sicron 	bnx2x_set_int_mode(bp);
32140e8d2ec5SMerav Sicron }
32150e8d2ec5SMerav Sicron 
32160e8d2ec5SMerav Sicron /**
32170e8d2ec5SMerav Sicron  * bnx2x_set_channels - sets the number of RSS queues.
32180e8d2ec5SMerav Sicron  *
32190e8d2ec5SMerav Sicron  * @dev:		net device
32200e8d2ec5SMerav Sicron  * @channels:		includes the number of queues requested
32210e8d2ec5SMerav Sicron  */
32220e8d2ec5SMerav Sicron static int bnx2x_set_channels(struct net_device *dev,
32230e8d2ec5SMerav Sicron 			      struct ethtool_channels *channels)
32240e8d2ec5SMerav Sicron {
32250e8d2ec5SMerav Sicron 	struct bnx2x *bp = netdev_priv(dev);
32260e8d2ec5SMerav Sicron 
32270e8d2ec5SMerav Sicron 
32280e8d2ec5SMerav Sicron 	DP(BNX2X_MSG_ETHTOOL,
32290e8d2ec5SMerav Sicron 	   "set-channels command parameters: rx = %d, tx = %d, other = %d, combined = %d\n",
32300e8d2ec5SMerav Sicron 	   channels->rx_count, channels->tx_count, channels->other_count,
32310e8d2ec5SMerav Sicron 	   channels->combined_count);
32320e8d2ec5SMerav Sicron 
32330e8d2ec5SMerav Sicron 	/* We don't support separate rx / tx channels.
32340e8d2ec5SMerav Sicron 	 * We don't allow setting 'other' channels.
32350e8d2ec5SMerav Sicron 	 */
32360e8d2ec5SMerav Sicron 	if (channels->rx_count || channels->tx_count || channels->other_count
32370e8d2ec5SMerav Sicron 	    || (channels->combined_count == 0) ||
32380e8d2ec5SMerav Sicron 	    (channels->combined_count > BNX2X_MAX_RSS_COUNT(bp))) {
32390e8d2ec5SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL, "command parameters not supported\n");
32400e8d2ec5SMerav Sicron 		return -EINVAL;
32410e8d2ec5SMerav Sicron 	}
32420e8d2ec5SMerav Sicron 
32430e8d2ec5SMerav Sicron 	/* Check if there was a change in the active parameters */
32440e8d2ec5SMerav Sicron 	if (channels->combined_count == BNX2X_NUM_ETH_QUEUES(bp)) {
32450e8d2ec5SMerav Sicron 		DP(BNX2X_MSG_ETHTOOL, "No change in active parameters\n");
32460e8d2ec5SMerav Sicron 		return 0;
32470e8d2ec5SMerav Sicron 	}
32480e8d2ec5SMerav Sicron 
32490e8d2ec5SMerav Sicron 	/* Set the requested number of queues in bp context.
32500e8d2ec5SMerav Sicron 	 * Note that the actual number of queues created during load may be
32510e8d2ec5SMerav Sicron 	 * less than requested if memory is low.
32520e8d2ec5SMerav Sicron 	 */
32530e8d2ec5SMerav Sicron 	if (unlikely(!netif_running(dev))) {
32540e8d2ec5SMerav Sicron 		bnx2x_change_num_queues(bp, channels->combined_count);
32550e8d2ec5SMerav Sicron 		return 0;
32560e8d2ec5SMerav Sicron 	}
32575d07d868SYuval Mintz 	bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
32580e8d2ec5SMerav Sicron 	bnx2x_change_num_queues(bp, channels->combined_count);
32590e8d2ec5SMerav Sicron 	return bnx2x_nic_load(bp, LOAD_NORMAL);
32600e8d2ec5SMerav Sicron }
32610e8d2ec5SMerav Sicron 
3262adfc5217SJeff Kirsher static const struct ethtool_ops bnx2x_ethtool_ops = {
3263adfc5217SJeff Kirsher 	.get_settings		= bnx2x_get_settings,
3264adfc5217SJeff Kirsher 	.set_settings		= bnx2x_set_settings,
3265adfc5217SJeff Kirsher 	.get_drvinfo		= bnx2x_get_drvinfo,
3266adfc5217SJeff Kirsher 	.get_regs_len		= bnx2x_get_regs_len,
3267adfc5217SJeff Kirsher 	.get_regs		= bnx2x_get_regs,
326807ba6af4SMiriam Shitrit 	.get_dump_flag		= bnx2x_get_dump_flag,
326907ba6af4SMiriam Shitrit 	.get_dump_data		= bnx2x_get_dump_data,
327007ba6af4SMiriam Shitrit 	.set_dump		= bnx2x_set_dump,
3271adfc5217SJeff Kirsher 	.get_wol		= bnx2x_get_wol,
3272adfc5217SJeff Kirsher 	.set_wol		= bnx2x_set_wol,
3273adfc5217SJeff Kirsher 	.get_msglevel		= bnx2x_get_msglevel,
3274adfc5217SJeff Kirsher 	.set_msglevel		= bnx2x_set_msglevel,
3275adfc5217SJeff Kirsher 	.nway_reset		= bnx2x_nway_reset,
3276adfc5217SJeff Kirsher 	.get_link		= bnx2x_get_link,
3277adfc5217SJeff Kirsher 	.get_eeprom_len		= bnx2x_get_eeprom_len,
3278adfc5217SJeff Kirsher 	.get_eeprom		= bnx2x_get_eeprom,
3279adfc5217SJeff Kirsher 	.set_eeprom		= bnx2x_set_eeprom,
3280adfc5217SJeff Kirsher 	.get_coalesce		= bnx2x_get_coalesce,
3281adfc5217SJeff Kirsher 	.set_coalesce		= bnx2x_set_coalesce,
3282adfc5217SJeff Kirsher 	.get_ringparam		= bnx2x_get_ringparam,
3283adfc5217SJeff Kirsher 	.set_ringparam		= bnx2x_set_ringparam,
3284adfc5217SJeff Kirsher 	.get_pauseparam		= bnx2x_get_pauseparam,
3285adfc5217SJeff Kirsher 	.set_pauseparam		= bnx2x_set_pauseparam,
3286adfc5217SJeff Kirsher 	.self_test		= bnx2x_self_test,
3287adfc5217SJeff Kirsher 	.get_sset_count		= bnx2x_get_sset_count,
3288adfc5217SJeff Kirsher 	.get_strings		= bnx2x_get_strings,
3289adfc5217SJeff Kirsher 	.set_phys_id		= bnx2x_set_phys_id,
3290adfc5217SJeff Kirsher 	.get_ethtool_stats	= bnx2x_get_ethtool_stats,
3291adfc5217SJeff Kirsher 	.get_rxnfc		= bnx2x_get_rxnfc,
32925d317c6aSMerav Sicron 	.set_rxnfc		= bnx2x_set_rxnfc,
32937850f63fSBen Hutchings 	.get_rxfh_indir_size	= bnx2x_get_rxfh_indir_size,
3294adfc5217SJeff Kirsher 	.get_rxfh_indir		= bnx2x_get_rxfh_indir,
3295adfc5217SJeff Kirsher 	.set_rxfh_indir		= bnx2x_set_rxfh_indir,
32960e8d2ec5SMerav Sicron 	.get_channels		= bnx2x_get_channels,
32970e8d2ec5SMerav Sicron 	.set_channels		= bnx2x_set_channels,
329824ea818eSYuval Mintz 	.get_module_info	= bnx2x_get_module_info,
329924ea818eSYuval Mintz 	.get_module_eeprom	= bnx2x_get_module_eeprom,
3300e9939c80SYuval Mintz 	.get_eee		= bnx2x_get_eee,
3301e9939c80SYuval Mintz 	.set_eee		= bnx2x_set_eee,
3302be53ce1eSRichard Cochran 	.get_ts_info		= ethtool_op_get_ts_info,
3303adfc5217SJeff Kirsher };
3304adfc5217SJeff Kirsher 
3305005a07baSAriel Elior static const struct ethtool_ops bnx2x_vf_ethtool_ops = {
3306005a07baSAriel Elior 	.get_settings		= bnx2x_get_settings,
3307005a07baSAriel Elior 	.set_settings		= bnx2x_set_settings,
3308005a07baSAriel Elior 	.get_drvinfo		= bnx2x_get_drvinfo,
3309005a07baSAriel Elior 	.get_msglevel		= bnx2x_get_msglevel,
3310005a07baSAriel Elior 	.set_msglevel		= bnx2x_set_msglevel,
3311005a07baSAriel Elior 	.get_link		= bnx2x_get_link,
3312005a07baSAriel Elior 	.get_coalesce		= bnx2x_get_coalesce,
3313005a07baSAriel Elior 	.get_ringparam		= bnx2x_get_ringparam,
3314005a07baSAriel Elior 	.set_ringparam		= bnx2x_set_ringparam,
3315005a07baSAriel Elior 	.get_sset_count		= bnx2x_get_sset_count,
3316005a07baSAriel Elior 	.get_strings		= bnx2x_get_strings,
3317005a07baSAriel Elior 	.get_ethtool_stats	= bnx2x_get_ethtool_stats,
3318005a07baSAriel Elior 	.get_rxnfc		= bnx2x_get_rxnfc,
3319005a07baSAriel Elior 	.set_rxnfc		= bnx2x_set_rxnfc,
3320005a07baSAriel Elior 	.get_rxfh_indir_size	= bnx2x_get_rxfh_indir_size,
3321005a07baSAriel Elior 	.get_rxfh_indir		= bnx2x_get_rxfh_indir,
3322005a07baSAriel Elior 	.set_rxfh_indir		= bnx2x_set_rxfh_indir,
3323005a07baSAriel Elior 	.get_channels		= bnx2x_get_channels,
3324005a07baSAriel Elior 	.set_channels		= bnx2x_set_channels,
3325005a07baSAriel Elior };
3326005a07baSAriel Elior 
3327005a07baSAriel Elior void bnx2x_set_ethtool_ops(struct bnx2x *bp, struct net_device *netdev)
3328adfc5217SJeff Kirsher {
3329005a07baSAriel Elior 	if (IS_PF(bp))
3330adfc5217SJeff Kirsher 		SET_ETHTOOL_OPS(netdev, &bnx2x_ethtool_ops);
3331005a07baSAriel Elior 	else /* vf */
3332005a07baSAriel Elior 		SET_ETHTOOL_OPS(netdev, &bnx2x_vf_ethtool_ops);
3333adfc5217SJeff Kirsher }
3334