blob: ed2b49a0c5a540332f17daea3a0ca6bc815e8cca [file] [log] [blame]
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001/* bnx2x_ethtool.c: Broadcom Everest network driver.
2 *
Ariel Elior85b26ea2012-01-26 06:01:54 +00003 * Copyright (c) 2007-2012 Broadcom Corporation
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation.
8 *
9 * Maintained by: Eilon Greenstein <eilong@broadcom.com>
10 * Written by: Eliezer Tamir
11 * Based on code from Michael Chan's bnx2 driver
12 * UDP CSUM errata workaround by Arik Gendelman
13 * Slowpath and fastpath rework by Vladislav Zolotarov
14 * Statistics and Link management by Yitchak Gertner
15 *
16 */
Joe Perchesf1deab52011-08-14 12:16:21 +000017
18#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +000020#include <linux/ethtool.h>
21#include <linux/netdevice.h>
22#include <linux/types.h>
23#include <linux/sched.h>
24#include <linux/crc32.h>
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +000025#include "bnx2x.h"
26#include "bnx2x_cmn.h"
27#include "bnx2x_dump.h"
Vladislav Zolotarov4a33bc02011-01-09 02:20:04 +000028#include "bnx2x_init.h"
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +000029
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000030/* Note: in the format strings below %s is replaced by the queue-name which is
31 * either its index or 'fcoe' for the fcoe queue. Make sure the format string
32 * length does not exceed ETH_GSTRING_LEN - MAX_QUEUE_NAME_LEN + 2
33 */
34#define MAX_QUEUE_NAME_LEN 4
35static const struct {
36 long offset;
37 int size;
38 char string[ETH_GSTRING_LEN];
39} bnx2x_q_stats_arr[] = {
40/* 1 */ { Q_STATS_OFFSET32(total_bytes_received_hi), 8, "[%s]: rx_bytes" },
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000041 { Q_STATS_OFFSET32(total_unicast_packets_received_hi),
42 8, "[%s]: rx_ucast_packets" },
43 { Q_STATS_OFFSET32(total_multicast_packets_received_hi),
44 8, "[%s]: rx_mcast_packets" },
45 { Q_STATS_OFFSET32(total_broadcast_packets_received_hi),
46 8, "[%s]: rx_bcast_packets" },
47 { Q_STATS_OFFSET32(no_buff_discard_hi), 8, "[%s]: rx_discards" },
48 { Q_STATS_OFFSET32(rx_err_discard_pkt),
49 4, "[%s]: rx_phy_ip_err_discards"},
50 { Q_STATS_OFFSET32(rx_skb_alloc_failed),
51 4, "[%s]: rx_skb_alloc_discard" },
52 { Q_STATS_OFFSET32(hw_csum_err), 4, "[%s]: rx_csum_offload_errors" },
53
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030054 { Q_STATS_OFFSET32(total_bytes_transmitted_hi), 8, "[%s]: tx_bytes" },
55/* 10 */{ Q_STATS_OFFSET32(total_unicast_packets_transmitted_hi),
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000056 8, "[%s]: tx_ucast_packets" },
57 { Q_STATS_OFFSET32(total_multicast_packets_transmitted_hi),
58 8, "[%s]: tx_mcast_packets" },
59 { Q_STATS_OFFSET32(total_broadcast_packets_transmitted_hi),
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030060 8, "[%s]: tx_bcast_packets" },
61 { Q_STATS_OFFSET32(total_tpa_aggregations_hi),
62 8, "[%s]: tpa_aggregations" },
63 { Q_STATS_OFFSET32(total_tpa_aggregated_frames_hi),
64 8, "[%s]: tpa_aggregated_frames"},
65 { Q_STATS_OFFSET32(total_tpa_bytes_hi), 8, "[%s]: tpa_bytes"}
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +000066};
67
68#define BNX2X_NUM_Q_STATS ARRAY_SIZE(bnx2x_q_stats_arr)
69
70static const struct {
71 long offset;
72 int size;
73 u32 flags;
74#define STATS_FLAGS_PORT 1
75#define STATS_FLAGS_FUNC 2
76#define STATS_FLAGS_BOTH (STATS_FLAGS_FUNC | STATS_FLAGS_PORT)
77 char string[ETH_GSTRING_LEN];
78} bnx2x_stats_arr[] = {
79/* 1 */ { STATS_OFFSET32(total_bytes_received_hi),
80 8, STATS_FLAGS_BOTH, "rx_bytes" },
81 { STATS_OFFSET32(error_bytes_received_hi),
82 8, STATS_FLAGS_BOTH, "rx_error_bytes" },
83 { STATS_OFFSET32(total_unicast_packets_received_hi),
84 8, STATS_FLAGS_BOTH, "rx_ucast_packets" },
85 { STATS_OFFSET32(total_multicast_packets_received_hi),
86 8, STATS_FLAGS_BOTH, "rx_mcast_packets" },
87 { STATS_OFFSET32(total_broadcast_packets_received_hi),
88 8, STATS_FLAGS_BOTH, "rx_bcast_packets" },
89 { STATS_OFFSET32(rx_stat_dot3statsfcserrors_hi),
90 8, STATS_FLAGS_PORT, "rx_crc_errors" },
91 { STATS_OFFSET32(rx_stat_dot3statsalignmenterrors_hi),
92 8, STATS_FLAGS_PORT, "rx_align_errors" },
93 { STATS_OFFSET32(rx_stat_etherstatsundersizepkts_hi),
94 8, STATS_FLAGS_PORT, "rx_undersize_packets" },
95 { STATS_OFFSET32(etherstatsoverrsizepkts_hi),
96 8, STATS_FLAGS_PORT, "rx_oversize_packets" },
97/* 10 */{ STATS_OFFSET32(rx_stat_etherstatsfragments_hi),
98 8, STATS_FLAGS_PORT, "rx_fragments" },
99 { STATS_OFFSET32(rx_stat_etherstatsjabbers_hi),
100 8, STATS_FLAGS_PORT, "rx_jabbers" },
101 { STATS_OFFSET32(no_buff_discard_hi),
102 8, STATS_FLAGS_BOTH, "rx_discards" },
103 { STATS_OFFSET32(mac_filter_discard),
104 4, STATS_FLAGS_PORT, "rx_filtered_packets" },
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300105 { STATS_OFFSET32(mf_tag_discard),
106 4, STATS_FLAGS_PORT, "rx_mf_tag_discard" },
Barak Witkowski0e898dd2011-12-05 21:52:22 +0000107 { STATS_OFFSET32(pfc_frames_received_hi),
108 8, STATS_FLAGS_PORT, "pfc_frames_received" },
109 { STATS_OFFSET32(pfc_frames_sent_hi),
110 8, STATS_FLAGS_PORT, "pfc_frames_sent" },
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +0000111 { STATS_OFFSET32(brb_drop_hi),
112 8, STATS_FLAGS_PORT, "rx_brb_discard" },
113 { STATS_OFFSET32(brb_truncate_hi),
114 8, STATS_FLAGS_PORT, "rx_brb_truncate" },
115 { STATS_OFFSET32(pause_frames_received_hi),
116 8, STATS_FLAGS_PORT, "rx_pause_frames" },
117 { STATS_OFFSET32(rx_stat_maccontrolframesreceived_hi),
118 8, STATS_FLAGS_PORT, "rx_mac_ctrl_frames" },
119 { STATS_OFFSET32(nig_timer_max),
120 4, STATS_FLAGS_PORT, "rx_constant_pause_events" },
121/* 20 */{ STATS_OFFSET32(rx_err_discard_pkt),
122 4, STATS_FLAGS_BOTH, "rx_phy_ip_err_discards"},
123 { STATS_OFFSET32(rx_skb_alloc_failed),
124 4, STATS_FLAGS_BOTH, "rx_skb_alloc_discard" },
125 { STATS_OFFSET32(hw_csum_err),
126 4, STATS_FLAGS_BOTH, "rx_csum_offload_errors" },
127
128 { STATS_OFFSET32(total_bytes_transmitted_hi),
129 8, STATS_FLAGS_BOTH, "tx_bytes" },
130 { STATS_OFFSET32(tx_stat_ifhcoutbadoctets_hi),
131 8, STATS_FLAGS_PORT, "tx_error_bytes" },
132 { STATS_OFFSET32(total_unicast_packets_transmitted_hi),
133 8, STATS_FLAGS_BOTH, "tx_ucast_packets" },
134 { STATS_OFFSET32(total_multicast_packets_transmitted_hi),
135 8, STATS_FLAGS_BOTH, "tx_mcast_packets" },
136 { STATS_OFFSET32(total_broadcast_packets_transmitted_hi),
137 8, STATS_FLAGS_BOTH, "tx_bcast_packets" },
138 { STATS_OFFSET32(tx_stat_dot3statsinternalmactransmiterrors_hi),
139 8, STATS_FLAGS_PORT, "tx_mac_errors" },
140 { STATS_OFFSET32(rx_stat_dot3statscarriersenseerrors_hi),
141 8, STATS_FLAGS_PORT, "tx_carrier_errors" },
142/* 30 */{ STATS_OFFSET32(tx_stat_dot3statssinglecollisionframes_hi),
143 8, STATS_FLAGS_PORT, "tx_single_collisions" },
144 { STATS_OFFSET32(tx_stat_dot3statsmultiplecollisionframes_hi),
145 8, STATS_FLAGS_PORT, "tx_multi_collisions" },
146 { STATS_OFFSET32(tx_stat_dot3statsdeferredtransmissions_hi),
147 8, STATS_FLAGS_PORT, "tx_deferred" },
148 { STATS_OFFSET32(tx_stat_dot3statsexcessivecollisions_hi),
149 8, STATS_FLAGS_PORT, "tx_excess_collisions" },
150 { STATS_OFFSET32(tx_stat_dot3statslatecollisions_hi),
151 8, STATS_FLAGS_PORT, "tx_late_collisions" },
152 { STATS_OFFSET32(tx_stat_etherstatscollisions_hi),
153 8, STATS_FLAGS_PORT, "tx_total_collisions" },
154 { STATS_OFFSET32(tx_stat_etherstatspkts64octets_hi),
155 8, STATS_FLAGS_PORT, "tx_64_byte_packets" },
156 { STATS_OFFSET32(tx_stat_etherstatspkts65octetsto127octets_hi),
157 8, STATS_FLAGS_PORT, "tx_65_to_127_byte_packets" },
158 { STATS_OFFSET32(tx_stat_etherstatspkts128octetsto255octets_hi),
159 8, STATS_FLAGS_PORT, "tx_128_to_255_byte_packets" },
160 { STATS_OFFSET32(tx_stat_etherstatspkts256octetsto511octets_hi),
161 8, STATS_FLAGS_PORT, "tx_256_to_511_byte_packets" },
162/* 40 */{ STATS_OFFSET32(tx_stat_etherstatspkts512octetsto1023octets_hi),
163 8, STATS_FLAGS_PORT, "tx_512_to_1023_byte_packets" },
164 { STATS_OFFSET32(etherstatspkts1024octetsto1522octets_hi),
165 8, STATS_FLAGS_PORT, "tx_1024_to_1522_byte_packets" },
166 { STATS_OFFSET32(etherstatspktsover1522octets_hi),
167 8, STATS_FLAGS_PORT, "tx_1523_to_9022_byte_packets" },
168 { STATS_OFFSET32(pause_frames_sent_hi),
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300169 8, STATS_FLAGS_PORT, "tx_pause_frames" },
170 { STATS_OFFSET32(total_tpa_aggregations_hi),
171 8, STATS_FLAGS_FUNC, "tpa_aggregations" },
172 { STATS_OFFSET32(total_tpa_aggregated_frames_hi),
173 8, STATS_FLAGS_FUNC, "tpa_aggregated_frames"},
174 { STATS_OFFSET32(total_tpa_bytes_hi),
Ariel Elior7a752992012-01-26 06:01:53 +0000175 8, STATS_FLAGS_FUNC, "tpa_bytes"},
176 { STATS_OFFSET32(recoverable_error),
177 4, STATS_FLAGS_FUNC, "recoverable_errors" },
178 { STATS_OFFSET32(unrecoverable_error),
179 4, STATS_FLAGS_FUNC, "unrecoverable_errors" },
Yuval Mintze9939c82012-06-06 17:13:08 +0000180 { STATS_OFFSET32(eee_tx_lpi),
181 4, STATS_FLAGS_PORT, "Tx LPI entry count"}
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +0000182};
183
184#define BNX2X_NUM_STATS ARRAY_SIZE(bnx2x_stats_arr)
Yaniv Rosner1ac9e422011-05-31 21:26:11 +0000185static int bnx2x_get_port_type(struct bnx2x *bp)
186{
187 int port_type;
188 u32 phy_idx = bnx2x_get_cur_phy_idx(bp);
189 switch (bp->link_params.phy[phy_idx].media_type) {
190 case ETH_PHY_SFP_FIBER:
191 case ETH_PHY_XFP_FIBER:
192 case ETH_PHY_KR:
193 case ETH_PHY_CX4:
194 port_type = PORT_FIBRE;
195 break;
196 case ETH_PHY_DA_TWINAX:
197 port_type = PORT_DA;
198 break;
199 case ETH_PHY_BASE_T:
200 port_type = PORT_TP;
201 break;
202 case ETH_PHY_NOT_PRESENT:
203 port_type = PORT_NONE;
204 break;
205 case ETH_PHY_UNSPECIFIED:
206 default:
207 port_type = PORT_OTHER;
208 break;
209 }
210 return port_type;
211}
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +0000212
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000213static int bnx2x_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
214{
215 struct bnx2x *bp = netdev_priv(dev);
Yaniv Rosnera22f0782010-09-07 11:41:20 +0000216 int cfg_idx = bnx2x_get_link_cfg_idx(bp);
David Decotignyb3337e42011-04-14 16:11:34 +0000217
Yaniv Rosnera22f0782010-09-07 11:41:20 +0000218 /* Dual Media boards present all available port types */
219 cmd->supported = bp->port.supported[cfg_idx] |
220 (bp->port.supported[cfg_idx ^ 1] &
221 (SUPPORTED_TP | SUPPORTED_FIBRE));
222 cmd->advertising = bp->port.advertising[cfg_idx];
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000223
Yuval Mintz38298462012-03-12 08:53:12 +0000224 if ((bp->state == BNX2X_STATE_OPEN) && (bp->link_vars.link_up)) {
225 if (!(bp->flags & MF_FUNC_DIS)) {
226 ethtool_cmd_speed_set(cmd, bp->link_vars.line_speed);
227 cmd->duplex = bp->link_vars.duplex;
228 } else {
229 ethtool_cmd_speed_set(
230 cmd, bp->link_params.req_line_speed[cfg_idx]);
231 cmd->duplex = bp->link_params.req_duplex[cfg_idx];
232 }
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000233
Yuval Mintz38298462012-03-12 08:53:12 +0000234 if (IS_MF(bp) && !BP_NOMCP(bp))
235 ethtool_cmd_speed_set(cmd, bnx2x_get_mf_speed(bp));
236 } else {
237 cmd->duplex = DUPLEX_UNKNOWN;
238 ethtool_cmd_speed_set(cmd, SPEED_UNKNOWN);
239 }
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000240
Yaniv Rosner1ac9e422011-05-31 21:26:11 +0000241 cmd->port = bnx2x_get_port_type(bp);
Yaniv Rosnera22f0782010-09-07 11:41:20 +0000242
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000243 cmd->phy_address = bp->mdio.prtad;
244 cmd->transceiver = XCVR_INTERNAL;
245
Yaniv Rosnera22f0782010-09-07 11:41:20 +0000246 if (bp->link_params.req_line_speed[cfg_idx] == SPEED_AUTO_NEG)
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000247 cmd->autoneg = AUTONEG_ENABLE;
248 else
249 cmd->autoneg = AUTONEG_DISABLE;
250
Mintz Yuval9e7e8392012-02-15 02:10:24 +0000251 /* Publish LP advertised speeds and FC */
252 if (bp->link_vars.link_status & LINK_STATUS_AUTO_NEGOTIATE_COMPLETE) {
253 u32 status = bp->link_vars.link_status;
254
255 cmd->lp_advertising |= ADVERTISED_Autoneg;
256 if (status & LINK_STATUS_LINK_PARTNER_SYMMETRIC_PAUSE)
257 cmd->lp_advertising |= ADVERTISED_Pause;
258 if (status & LINK_STATUS_LINK_PARTNER_ASYMMETRIC_PAUSE)
259 cmd->lp_advertising |= ADVERTISED_Asym_Pause;
260
261 if (status & LINK_STATUS_LINK_PARTNER_10THD_CAPABLE)
262 cmd->lp_advertising |= ADVERTISED_10baseT_Half;
263 if (status & LINK_STATUS_LINK_PARTNER_10TFD_CAPABLE)
264 cmd->lp_advertising |= ADVERTISED_10baseT_Full;
265 if (status & LINK_STATUS_LINK_PARTNER_100TXHD_CAPABLE)
266 cmd->lp_advertising |= ADVERTISED_100baseT_Half;
267 if (status & LINK_STATUS_LINK_PARTNER_100TXFD_CAPABLE)
268 cmd->lp_advertising |= ADVERTISED_100baseT_Full;
269 if (status & LINK_STATUS_LINK_PARTNER_1000THD_CAPABLE)
270 cmd->lp_advertising |= ADVERTISED_1000baseT_Half;
271 if (status & LINK_STATUS_LINK_PARTNER_1000TFD_CAPABLE)
272 cmd->lp_advertising |= ADVERTISED_1000baseT_Full;
273 if (status & LINK_STATUS_LINK_PARTNER_2500XFD_CAPABLE)
274 cmd->lp_advertising |= ADVERTISED_2500baseX_Full;
275 if (status & LINK_STATUS_LINK_PARTNER_10GXFD_CAPABLE)
276 cmd->lp_advertising |= ADVERTISED_10000baseT_Full;
277 }
278
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000279 cmd->maxtxpkt = 0;
280 cmd->maxrxpkt = 0;
281
Merav Sicron51c1a582012-03-18 10:33:38 +0000282 DP(BNX2X_MSG_ETHTOOL, "ethtool_cmd: cmd %d\n"
Joe Perchesf1deab52011-08-14 12:16:21 +0000283 " supported 0x%x advertising 0x%x speed %u\n"
284 " duplex %d port %d phy_address %d transceiver %d\n"
285 " autoneg %d maxtxpkt %d maxrxpkt %d\n",
David Decotignyb3337e42011-04-14 16:11:34 +0000286 cmd->cmd, cmd->supported, cmd->advertising,
287 ethtool_cmd_speed(cmd),
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000288 cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver,
289 cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt);
290
291 return 0;
292}
293
294static int bnx2x_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
295{
296 struct bnx2x *bp = netdev_priv(dev);
Yaniv Rosnera22f0782010-09-07 11:41:20 +0000297 u32 advertising, cfg_idx, old_multi_phy_config, new_multi_phy_config;
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -0800298 u32 speed;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000299
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -0800300 if (IS_MF_SD(bp))
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000301 return 0;
302
Merav Sicron51c1a582012-03-18 10:33:38 +0000303 DP(BNX2X_MSG_ETHTOOL, "ethtool_cmd: cmd %d\n"
David Decotignyb3337e42011-04-14 16:11:34 +0000304 " supported 0x%x advertising 0x%x speed %u\n"
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -0800305 " duplex %d port %d phy_address %d transceiver %d\n"
306 " autoneg %d maxtxpkt %d maxrxpkt %d\n",
David Decotignyb3337e42011-04-14 16:11:34 +0000307 cmd->cmd, cmd->supported, cmd->advertising,
308 ethtool_cmd_speed(cmd),
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000309 cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver,
310 cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt);
311
David Decotignyb3337e42011-04-14 16:11:34 +0000312 speed = ethtool_cmd_speed(cmd);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -0800313
Yuval Mintz38298462012-03-12 08:53:12 +0000314 /* If recieved a request for an unknown duplex, assume full*/
315 if (cmd->duplex == DUPLEX_UNKNOWN)
316 cmd->duplex = DUPLEX_FULL;
317
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -0800318 if (IS_MF_SI(bp)) {
Dmitry Kravkove3835b92011-03-06 10:50:44 +0000319 u32 part;
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -0800320 u32 line_speed = bp->link_vars.line_speed;
321
322 /* use 10G if no link detected */
323 if (!line_speed)
324 line_speed = 10000;
325
326 if (bp->common.bc_ver < REQ_BC_VER_4_SET_MF_BW) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000327 DP(BNX2X_MSG_ETHTOOL,
328 "To set speed BC %X or higher is required, please upgrade BC\n",
329 REQ_BC_VER_4_SET_MF_BW);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -0800330 return -EINVAL;
331 }
Dmitry Kravkove3835b92011-03-06 10:50:44 +0000332
Dmitry Kravkovfaa6fcb2011-02-28 03:37:20 +0000333 part = (speed * 100) / line_speed;
Dmitry Kravkove3835b92011-03-06 10:50:44 +0000334
Dmitry Kravkovfaa6fcb2011-02-28 03:37:20 +0000335 if (line_speed < speed || !part) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000336 DP(BNX2X_MSG_ETHTOOL,
337 "Speed setting should be in a range from 1%% to 100%% of actual line speed\n");
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -0800338 return -EINVAL;
339 }
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -0800340
Dmitry Kravkove3835b92011-03-06 10:50:44 +0000341 if (bp->state != BNX2X_STATE_OPEN)
342 /* store value for following "load" */
343 bp->pending_max = part;
344 else
345 bnx2x_update_max_mf_config(bp, part);
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -0800346
Dmitry Kravkov0793f83f2010-12-01 12:39:28 -0800347 return 0;
348 }
349
Yaniv Rosnera22f0782010-09-07 11:41:20 +0000350 cfg_idx = bnx2x_get_link_cfg_idx(bp);
351 old_multi_phy_config = bp->link_params.multi_phy_config;
352 switch (cmd->port) {
353 case PORT_TP:
354 if (bp->port.supported[cfg_idx] & SUPPORTED_TP)
355 break; /* no port change */
356
357 if (!(bp->port.supported[0] & SUPPORTED_TP ||
358 bp->port.supported[1] & SUPPORTED_TP)) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000359 DP(BNX2X_MSG_ETHTOOL, "Unsupported port type\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +0000360 return -EINVAL;
361 }
362 bp->link_params.multi_phy_config &=
363 ~PORT_HW_CFG_PHY_SELECTION_MASK;
364 if (bp->link_params.multi_phy_config &
365 PORT_HW_CFG_PHY_SWAPPED_ENABLED)
366 bp->link_params.multi_phy_config |=
367 PORT_HW_CFG_PHY_SELECTION_SECOND_PHY;
368 else
369 bp->link_params.multi_phy_config |=
370 PORT_HW_CFG_PHY_SELECTION_FIRST_PHY;
371 break;
372 case PORT_FIBRE:
Yaniv Rosnerbfdb5822011-10-27 05:13:52 +0000373 case PORT_DA:
Yaniv Rosnera22f0782010-09-07 11:41:20 +0000374 if (bp->port.supported[cfg_idx] & SUPPORTED_FIBRE)
375 break; /* no port change */
376
377 if (!(bp->port.supported[0] & SUPPORTED_FIBRE ||
378 bp->port.supported[1] & SUPPORTED_FIBRE)) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000379 DP(BNX2X_MSG_ETHTOOL, "Unsupported port type\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +0000380 return -EINVAL;
381 }
382 bp->link_params.multi_phy_config &=
383 ~PORT_HW_CFG_PHY_SELECTION_MASK;
384 if (bp->link_params.multi_phy_config &
385 PORT_HW_CFG_PHY_SWAPPED_ENABLED)
386 bp->link_params.multi_phy_config |=
387 PORT_HW_CFG_PHY_SELECTION_FIRST_PHY;
388 else
389 bp->link_params.multi_phy_config |=
390 PORT_HW_CFG_PHY_SELECTION_SECOND_PHY;
391 break;
392 default:
Merav Sicron51c1a582012-03-18 10:33:38 +0000393 DP(BNX2X_MSG_ETHTOOL, "Unsupported port type\n");
Yaniv Rosnera22f0782010-09-07 11:41:20 +0000394 return -EINVAL;
395 }
Yaniv Rosner2f751a82011-11-28 00:49:52 +0000396 /* Save new config in case command complete successully */
Yaniv Rosnera22f0782010-09-07 11:41:20 +0000397 new_multi_phy_config = bp->link_params.multi_phy_config;
398 /* Get the new cfg_idx */
399 cfg_idx = bnx2x_get_link_cfg_idx(bp);
400 /* Restore old config in case command failed */
401 bp->link_params.multi_phy_config = old_multi_phy_config;
Merav Sicron51c1a582012-03-18 10:33:38 +0000402 DP(BNX2X_MSG_ETHTOOL, "cfg_idx = %x\n", cfg_idx);
Yaniv Rosnera22f0782010-09-07 11:41:20 +0000403
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000404 if (cmd->autoneg == AUTONEG_ENABLE) {
Yaniv Rosner75318322012-01-17 02:33:27 +0000405 u32 an_supported_speed = bp->port.supported[cfg_idx];
406 if (bp->link_params.phy[EXT_PHY1].type ==
407 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
408 an_supported_speed |= (SUPPORTED_100baseT_Half |
409 SUPPORTED_100baseT_Full);
Yaniv Rosnera22f0782010-09-07 11:41:20 +0000410 if (!(bp->port.supported[cfg_idx] & SUPPORTED_Autoneg)) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000411 DP(BNX2X_MSG_ETHTOOL, "Autoneg not supported\n");
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000412 return -EINVAL;
413 }
414
415 /* advertise the requested speed and duplex if supported */
Yaniv Rosner75318322012-01-17 02:33:27 +0000416 if (cmd->advertising & ~an_supported_speed) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000417 DP(BNX2X_MSG_ETHTOOL,
418 "Advertisement parameters are not supported\n");
David S. Miller8decf862011-09-22 03:23:13 -0400419 return -EINVAL;
420 }
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000421
Yaniv Rosnera22f0782010-09-07 11:41:20 +0000422 bp->link_params.req_line_speed[cfg_idx] = SPEED_AUTO_NEG;
David S. Miller8decf862011-09-22 03:23:13 -0400423 bp->link_params.req_duplex[cfg_idx] = cmd->duplex;
424 bp->port.advertising[cfg_idx] = (ADVERTISED_Autoneg |
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000425 cmd->advertising);
David S. Miller8decf862011-09-22 03:23:13 -0400426 if (cmd->advertising) {
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000427
David S. Miller8decf862011-09-22 03:23:13 -0400428 bp->link_params.speed_cap_mask[cfg_idx] = 0;
429 if (cmd->advertising & ADVERTISED_10baseT_Half) {
430 bp->link_params.speed_cap_mask[cfg_idx] |=
431 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF;
432 }
433 if (cmd->advertising & ADVERTISED_10baseT_Full)
434 bp->link_params.speed_cap_mask[cfg_idx] |=
435 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL;
436
437 if (cmd->advertising & ADVERTISED_100baseT_Full)
438 bp->link_params.speed_cap_mask[cfg_idx] |=
439 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL;
440
441 if (cmd->advertising & ADVERTISED_100baseT_Half) {
442 bp->link_params.speed_cap_mask[cfg_idx] |=
443 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF;
444 }
445 if (cmd->advertising & ADVERTISED_1000baseT_Half) {
446 bp->link_params.speed_cap_mask[cfg_idx] |=
447 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G;
448 }
449 if (cmd->advertising & (ADVERTISED_1000baseT_Full |
450 ADVERTISED_1000baseKX_Full))
451 bp->link_params.speed_cap_mask[cfg_idx] |=
452 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G;
453
454 if (cmd->advertising & (ADVERTISED_10000baseT_Full |
455 ADVERTISED_10000baseKX4_Full |
456 ADVERTISED_10000baseKR_Full))
457 bp->link_params.speed_cap_mask[cfg_idx] |=
458 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G;
459 }
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000460 } else { /* forced speed */
461 /* advertise the requested speed and duplex if supported */
Yaniv Rosnera22f0782010-09-07 11:41:20 +0000462 switch (speed) {
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000463 case SPEED_10:
464 if (cmd->duplex == DUPLEX_FULL) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +0000465 if (!(bp->port.supported[cfg_idx] &
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000466 SUPPORTED_10baseT_Full)) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000467 DP(BNX2X_MSG_ETHTOOL,
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000468 "10M full not supported\n");
469 return -EINVAL;
470 }
471
472 advertising = (ADVERTISED_10baseT_Full |
473 ADVERTISED_TP);
474 } else {
Yaniv Rosnera22f0782010-09-07 11:41:20 +0000475 if (!(bp->port.supported[cfg_idx] &
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000476 SUPPORTED_10baseT_Half)) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000477 DP(BNX2X_MSG_ETHTOOL,
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000478 "10M half not supported\n");
479 return -EINVAL;
480 }
481
482 advertising = (ADVERTISED_10baseT_Half |
483 ADVERTISED_TP);
484 }
485 break;
486
487 case SPEED_100:
488 if (cmd->duplex == DUPLEX_FULL) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +0000489 if (!(bp->port.supported[cfg_idx] &
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000490 SUPPORTED_100baseT_Full)) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000491 DP(BNX2X_MSG_ETHTOOL,
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000492 "100M full not supported\n");
493 return -EINVAL;
494 }
495
496 advertising = (ADVERTISED_100baseT_Full |
497 ADVERTISED_TP);
498 } else {
Yaniv Rosnera22f0782010-09-07 11:41:20 +0000499 if (!(bp->port.supported[cfg_idx] &
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000500 SUPPORTED_100baseT_Half)) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000501 DP(BNX2X_MSG_ETHTOOL,
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000502 "100M half not supported\n");
503 return -EINVAL;
504 }
505
506 advertising = (ADVERTISED_100baseT_Half |
507 ADVERTISED_TP);
508 }
509 break;
510
511 case SPEED_1000:
512 if (cmd->duplex != DUPLEX_FULL) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000513 DP(BNX2X_MSG_ETHTOOL,
514 "1G half not supported\n");
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000515 return -EINVAL;
516 }
517
Yaniv Rosnera22f0782010-09-07 11:41:20 +0000518 if (!(bp->port.supported[cfg_idx] &
519 SUPPORTED_1000baseT_Full)) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000520 DP(BNX2X_MSG_ETHTOOL,
521 "1G full not supported\n");
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000522 return -EINVAL;
523 }
524
525 advertising = (ADVERTISED_1000baseT_Full |
526 ADVERTISED_TP);
527 break;
528
529 case SPEED_2500:
530 if (cmd->duplex != DUPLEX_FULL) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000531 DP(BNX2X_MSG_ETHTOOL,
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000532 "2.5G half not supported\n");
533 return -EINVAL;
534 }
535
Yaniv Rosnera22f0782010-09-07 11:41:20 +0000536 if (!(bp->port.supported[cfg_idx]
537 & SUPPORTED_2500baseX_Full)) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000538 DP(BNX2X_MSG_ETHTOOL,
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000539 "2.5G full not supported\n");
540 return -EINVAL;
541 }
542
543 advertising = (ADVERTISED_2500baseX_Full |
544 ADVERTISED_TP);
545 break;
546
547 case SPEED_10000:
548 if (cmd->duplex != DUPLEX_FULL) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000549 DP(BNX2X_MSG_ETHTOOL,
550 "10G half not supported\n");
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000551 return -EINVAL;
552 }
553
Yaniv Rosnera22f0782010-09-07 11:41:20 +0000554 if (!(bp->port.supported[cfg_idx]
555 & SUPPORTED_10000baseT_Full)) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000556 DP(BNX2X_MSG_ETHTOOL,
557 "10G full not supported\n");
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000558 return -EINVAL;
559 }
560
561 advertising = (ADVERTISED_10000baseT_Full |
562 ADVERTISED_FIBRE);
563 break;
564
565 default:
Merav Sicron51c1a582012-03-18 10:33:38 +0000566 DP(BNX2X_MSG_ETHTOOL, "Unsupported speed %u\n", speed);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000567 return -EINVAL;
568 }
569
Yaniv Rosnera22f0782010-09-07 11:41:20 +0000570 bp->link_params.req_line_speed[cfg_idx] = speed;
571 bp->link_params.req_duplex[cfg_idx] = cmd->duplex;
572 bp->port.advertising[cfg_idx] = advertising;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000573 }
574
Merav Sicron51c1a582012-03-18 10:33:38 +0000575 DP(BNX2X_MSG_ETHTOOL, "req_line_speed %d\n"
Joe Perchesf1deab52011-08-14 12:16:21 +0000576 " req_duplex %d advertising 0x%x\n",
Yaniv Rosnera22f0782010-09-07 11:41:20 +0000577 bp->link_params.req_line_speed[cfg_idx],
578 bp->link_params.req_duplex[cfg_idx],
579 bp->port.advertising[cfg_idx]);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000580
Yaniv Rosnera22f0782010-09-07 11:41:20 +0000581 /* Set new config */
582 bp->link_params.multi_phy_config = new_multi_phy_config;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000583 if (netif_running(dev)) {
584 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
585 bnx2x_link_set(bp);
586 }
587
588 return 0;
589}
590
591#define IS_E1_ONLINE(info) (((info) & RI_E1_ONLINE) == RI_E1_ONLINE)
592#define IS_E1H_ONLINE(info) (((info) & RI_E1H_ONLINE) == RI_E1H_ONLINE)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000593#define IS_E2_ONLINE(info) (((info) & RI_E2_ONLINE) == RI_E2_ONLINE)
Vladislav Zolotarov0fea29c2011-07-21 07:57:23 +0000594#define IS_E3_ONLINE(info) (((info) & RI_E3_ONLINE) == RI_E3_ONLINE)
595#define IS_E3B0_ONLINE(info) (((info) & RI_E3B0_ONLINE) == RI_E3B0_ONLINE)
596
Eric Dumazet1191cb82012-04-27 21:39:21 +0000597static bool bnx2x_is_reg_online(struct bnx2x *bp,
598 const struct reg_addr *reg_info)
Vladislav Zolotarov0fea29c2011-07-21 07:57:23 +0000599{
600 if (CHIP_IS_E1(bp))
601 return IS_E1_ONLINE(reg_info->info);
602 else if (CHIP_IS_E1H(bp))
603 return IS_E1H_ONLINE(reg_info->info);
604 else if (CHIP_IS_E2(bp))
605 return IS_E2_ONLINE(reg_info->info);
606 else if (CHIP_IS_E3A0(bp))
607 return IS_E3_ONLINE(reg_info->info);
608 else if (CHIP_IS_E3B0(bp))
609 return IS_E3B0_ONLINE(reg_info->info);
610 else
611 return false;
612}
613
614/******* Paged registers info selectors ********/
Eric Dumazet1191cb82012-04-27 21:39:21 +0000615static const u32 *__bnx2x_get_page_addr_ar(struct bnx2x *bp)
Vladislav Zolotarov0fea29c2011-07-21 07:57:23 +0000616{
617 if (CHIP_IS_E2(bp))
618 return page_vals_e2;
619 else if (CHIP_IS_E3(bp))
620 return page_vals_e3;
621 else
622 return NULL;
623}
624
Eric Dumazet1191cb82012-04-27 21:39:21 +0000625static u32 __bnx2x_get_page_reg_num(struct bnx2x *bp)
Vladislav Zolotarov0fea29c2011-07-21 07:57:23 +0000626{
627 if (CHIP_IS_E2(bp))
628 return PAGE_MODE_VALUES_E2;
629 else if (CHIP_IS_E3(bp))
630 return PAGE_MODE_VALUES_E3;
631 else
632 return 0;
633}
634
Eric Dumazet1191cb82012-04-27 21:39:21 +0000635static const u32 *__bnx2x_get_page_write_ar(struct bnx2x *bp)
Vladislav Zolotarov0fea29c2011-07-21 07:57:23 +0000636{
637 if (CHIP_IS_E2(bp))
638 return page_write_regs_e2;
639 else if (CHIP_IS_E3(bp))
640 return page_write_regs_e3;
641 else
642 return NULL;
643}
644
Eric Dumazet1191cb82012-04-27 21:39:21 +0000645static u32 __bnx2x_get_page_write_num(struct bnx2x *bp)
Vladislav Zolotarov0fea29c2011-07-21 07:57:23 +0000646{
647 if (CHIP_IS_E2(bp))
648 return PAGE_WRITE_REGS_E2;
649 else if (CHIP_IS_E3(bp))
650 return PAGE_WRITE_REGS_E3;
651 else
652 return 0;
653}
654
Eric Dumazet1191cb82012-04-27 21:39:21 +0000655static const struct reg_addr *__bnx2x_get_page_read_ar(struct bnx2x *bp)
Vladislav Zolotarov0fea29c2011-07-21 07:57:23 +0000656{
657 if (CHIP_IS_E2(bp))
658 return page_read_regs_e2;
659 else if (CHIP_IS_E3(bp))
660 return page_read_regs_e3;
661 else
662 return NULL;
663}
664
Eric Dumazet1191cb82012-04-27 21:39:21 +0000665static u32 __bnx2x_get_page_read_num(struct bnx2x *bp)
Vladislav Zolotarov0fea29c2011-07-21 07:57:23 +0000666{
667 if (CHIP_IS_E2(bp))
668 return PAGE_READ_REGS_E2;
669 else if (CHIP_IS_E3(bp))
670 return PAGE_READ_REGS_E3;
671 else
672 return 0;
673}
674
Eric Dumazet1191cb82012-04-27 21:39:21 +0000675static int __bnx2x_get_regs_len(struct bnx2x *bp)
Vladislav Zolotarov0fea29c2011-07-21 07:57:23 +0000676{
677 int num_pages = __bnx2x_get_page_reg_num(bp);
678 int page_write_num = __bnx2x_get_page_write_num(bp);
679 const struct reg_addr *page_read_addr = __bnx2x_get_page_read_ar(bp);
680 int page_read_num = __bnx2x_get_page_read_num(bp);
681 int regdump_len = 0;
682 int i, j, k;
683
684 for (i = 0; i < REGS_COUNT; i++)
685 if (bnx2x_is_reg_online(bp, &reg_addrs[i]))
686 regdump_len += reg_addrs[i].size;
687
688 for (i = 0; i < num_pages; i++)
689 for (j = 0; j < page_write_num; j++)
690 for (k = 0; k < page_read_num; k++)
691 if (bnx2x_is_reg_online(bp, &page_read_addr[k]))
692 regdump_len += page_read_addr[k].size;
693
694 return regdump_len;
695}
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000696
697static int bnx2x_get_regs_len(struct net_device *dev)
698{
699 struct bnx2x *bp = netdev_priv(dev);
700 int regdump_len = 0;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000701
Vladislav Zolotarov0fea29c2011-07-21 07:57:23 +0000702 regdump_len = __bnx2x_get_regs_len(bp);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000703 regdump_len *= 4;
704 regdump_len += sizeof(struct dump_hdr);
705
706 return regdump_len;
707}
708
Vladislav Zolotarov0fea29c2011-07-21 07:57:23 +0000709/**
710 * bnx2x_read_pages_regs - read "paged" registers
711 *
712 * @bp device handle
713 * @p output buffer
714 *
715 * Reads "paged" memories: memories that may only be read by first writing to a
716 * specific address ("write address") and then reading from a specific address
717 * ("read address"). There may be more than one write address per "page" and
718 * more than one read address per write address.
719 */
Eric Dumazet1191cb82012-04-27 21:39:21 +0000720static void bnx2x_read_pages_regs(struct bnx2x *bp, u32 *p)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000721{
722 u32 i, j, k, n;
Vladislav Zolotarov0fea29c2011-07-21 07:57:23 +0000723 /* addresses of the paged registers */
724 const u32 *page_addr = __bnx2x_get_page_addr_ar(bp);
725 /* number of paged registers */
726 int num_pages = __bnx2x_get_page_reg_num(bp);
727 /* write addresses */
728 const u32 *write_addr = __bnx2x_get_page_write_ar(bp);
729 /* number of write addresses */
730 int write_num = __bnx2x_get_page_write_num(bp);
731 /* read addresses info */
732 const struct reg_addr *read_addr = __bnx2x_get_page_read_ar(bp);
733 /* number of read addresses */
734 int read_num = __bnx2x_get_page_read_num(bp);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000735
Vladislav Zolotarov0fea29c2011-07-21 07:57:23 +0000736 for (i = 0; i < num_pages; i++) {
737 for (j = 0; j < write_num; j++) {
738 REG_WR(bp, write_addr[j], page_addr[i]);
739 for (k = 0; k < read_num; k++)
740 if (bnx2x_is_reg_online(bp, &read_addr[k]))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000741 for (n = 0; n <
Vladislav Zolotarov0fea29c2011-07-21 07:57:23 +0000742 read_addr[k].size; n++)
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000743 *p++ = REG_RD(bp,
Vladislav Zolotarov0fea29c2011-07-21 07:57:23 +0000744 read_addr[k].addr + n*4);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000745 }
746 }
747}
748
Eric Dumazet1191cb82012-04-27 21:39:21 +0000749static void __bnx2x_get_regs(struct bnx2x *bp, u32 *p)
Vladislav Zolotarov0fea29c2011-07-21 07:57:23 +0000750{
751 u32 i, j;
752
753 /* Read the regular registers */
754 for (i = 0; i < REGS_COUNT; i++)
755 if (bnx2x_is_reg_online(bp, &reg_addrs[i]))
756 for (j = 0; j < reg_addrs[i].size; j++)
757 *p++ = REG_RD(bp, reg_addrs[i].addr + j*4);
758
759 /* Read "paged" registes */
760 bnx2x_read_pages_regs(bp, p);
761}
762
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000763static void bnx2x_get_regs(struct net_device *dev,
764 struct ethtool_regs *regs, void *_p)
765{
Vladislav Zolotarov0fea29c2011-07-21 07:57:23 +0000766 u32 *p = _p;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000767 struct bnx2x *bp = netdev_priv(dev);
768 struct dump_hdr dump_hdr = {0};
769
770 regs->version = 0;
771 memset(p, 0, regs->len);
772
773 if (!netif_running(bp->dev))
774 return;
775
Vladislav Zolotarov4a33bc02011-01-09 02:20:04 +0000776 /* Disable parity attentions as long as following dump may
777 * cause false alarms by reading never written registers. We
778 * will re-enable parity attentions right after the dump.
779 */
780 bnx2x_disable_blocks_parity(bp);
781
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000782 dump_hdr.hdr_size = (sizeof(struct dump_hdr) / 4) - 1;
783 dump_hdr.dump_sign = dump_sign_all;
784 dump_hdr.xstorm_waitp = REG_RD(bp, XSTORM_WAITP_ADDR);
785 dump_hdr.tstorm_waitp = REG_RD(bp, TSTORM_WAITP_ADDR);
786 dump_hdr.ustorm_waitp = REG_RD(bp, USTORM_WAITP_ADDR);
787 dump_hdr.cstorm_waitp = REG_RD(bp, CSTORM_WAITP_ADDR);
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000788
789 if (CHIP_IS_E1(bp))
790 dump_hdr.info = RI_E1_ONLINE;
791 else if (CHIP_IS_E1H(bp))
792 dump_hdr.info = RI_E1H_ONLINE;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300793 else if (!CHIP_IS_E1x(bp))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000794 dump_hdr.info = RI_E2_ONLINE |
795 (BP_PATH(bp) ? RI_PATH1_DUMP : RI_PATH0_DUMP);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000796
797 memcpy(p, &dump_hdr, sizeof(struct dump_hdr));
798 p += dump_hdr.hdr_size + 1;
799
Vladislav Zolotarov0fea29c2011-07-21 07:57:23 +0000800 /* Actually read the registers */
801 __bnx2x_get_regs(bp, p);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000802
Vladislav Zolotarov4a33bc02011-01-09 02:20:04 +0000803 /* Re-enable parity attentions */
804 bnx2x_clear_blocks_parity(bp);
Vladislav Zolotarovc9ee9202011-06-14 01:33:51 +0000805 bnx2x_enable_blocks_parity(bp);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000806}
807
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000808static void bnx2x_get_drvinfo(struct net_device *dev,
809 struct ethtool_drvinfo *info)
810{
811 struct bnx2x *bp = netdev_priv(dev);
812 u8 phy_fw_ver[PHY_FW_VER_LEN];
813
Rick Jones68aad782011-11-07 13:29:27 +0000814 strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver));
815 strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000816
817 phy_fw_ver[0] = '\0';
Mintz Yuvala1e785e2012-02-15 02:10:32 +0000818 bnx2x_get_ext_phy_fw_version(&bp->link_params,
819 phy_fw_ver, PHY_FW_VER_LEN);
Rick Jones68aad782011-11-07 13:29:27 +0000820 strlcpy(info->fw_version, bp->fw_ver, sizeof(info->fw_version));
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000821 snprintf(info->fw_version + strlen(bp->fw_ver), 32 - strlen(bp->fw_ver),
822 "bc %d.%d.%d%s%s",
823 (bp->common.bc_ver & 0xff0000) >> 16,
824 (bp->common.bc_ver & 0xff00) >> 8,
825 (bp->common.bc_ver & 0xff),
826 ((phy_fw_ver[0] != '\0') ? " phy " : ""), phy_fw_ver);
Rick Jones68aad782011-11-07 13:29:27 +0000827 strlcpy(info->bus_info, pci_name(bp->pdev), sizeof(info->bus_info));
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000828 info->n_stats = BNX2X_NUM_STATS;
Merav Sicroncf2c1df62012-06-19 07:48:23 +0000829 info->testinfo_len = BNX2X_NUM_TESTS(bp);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000830 info->eedump_len = bp->common.flash_size;
831 info->regdump_len = bnx2x_get_regs_len(dev);
832}
833
834static void bnx2x_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
835{
836 struct bnx2x *bp = netdev_priv(dev);
837
838 if (bp->flags & NO_WOL_FLAG) {
839 wol->supported = 0;
840 wol->wolopts = 0;
841 } else {
842 wol->supported = WAKE_MAGIC;
843 if (bp->wol)
844 wol->wolopts = WAKE_MAGIC;
845 else
846 wol->wolopts = 0;
847 }
848 memset(&wol->sopass, 0, sizeof(wol->sopass));
849}
850
851static int bnx2x_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
852{
853 struct bnx2x *bp = netdev_priv(dev);
854
Merav Sicron51c1a582012-03-18 10:33:38 +0000855 if (wol->wolopts & ~WAKE_MAGIC) {
856 DP(BNX2X_MSG_ETHTOOL, "WOL not supproted\n");
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000857 return -EINVAL;
Merav Sicron51c1a582012-03-18 10:33:38 +0000858 }
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000859
860 if (wol->wolopts & WAKE_MAGIC) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000861 if (bp->flags & NO_WOL_FLAG) {
862 DP(BNX2X_MSG_ETHTOOL, "WOL not supproted\n");
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000863 return -EINVAL;
Merav Sicron51c1a582012-03-18 10:33:38 +0000864 }
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000865 bp->wol = 1;
866 } else
867 bp->wol = 0;
868
869 return 0;
870}
871
872static u32 bnx2x_get_msglevel(struct net_device *dev)
873{
874 struct bnx2x *bp = netdev_priv(dev);
875
876 return bp->msg_enable;
877}
878
879static void bnx2x_set_msglevel(struct net_device *dev, u32 level)
880{
881 struct bnx2x *bp = netdev_priv(dev);
882
Dmitry Kravkov7a25cc72011-06-14 01:33:25 +0000883 if (capable(CAP_NET_ADMIN)) {
884 /* dump MCP trace */
885 if (level & BNX2X_MSG_MCP)
886 bnx2x_fw_dump_lvl(bp, KERN_INFO);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000887 bp->msg_enable = level;
Dmitry Kravkov7a25cc72011-06-14 01:33:25 +0000888 }
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000889}
890
891static int bnx2x_nway_reset(struct net_device *dev)
892{
893 struct bnx2x *bp = netdev_priv(dev);
894
895 if (!bp->port.pmf)
896 return 0;
897
898 if (netif_running(dev)) {
899 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
900 bnx2x_link_set(bp);
901 }
902
903 return 0;
904}
905
906static u32 bnx2x_get_link(struct net_device *dev)
907{
908 struct bnx2x *bp = netdev_priv(dev);
909
Dmitry Kravkovf2e08992010-10-06 03:28:26 +0000910 if (bp->flags & MF_FUNC_DIS || (bp->state != BNX2X_STATE_OPEN))
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000911 return 0;
912
913 return bp->link_vars.link_up;
914}
915
916static int bnx2x_get_eeprom_len(struct net_device *dev)
917{
918 struct bnx2x *bp = netdev_priv(dev);
919
920 return bp->common.flash_size;
921}
922
Ariel Eliorf16da432012-01-26 06:01:50 +0000923/* Per pf misc lock must be aquired before the per port mcp lock. Otherwise, had
924 * we done things the other way around, if two pfs from the same port would
925 * attempt to access nvram at the same time, we could run into a scenario such
926 * as:
927 * pf A takes the port lock.
928 * pf B succeeds in taking the same lock since they are from the same port.
929 * pf A takes the per pf misc lock. Performs eeprom access.
930 * pf A finishes. Unlocks the per pf misc lock.
931 * Pf B takes the lock and proceeds to perform it's own access.
932 * pf A unlocks the per port lock, while pf B is still working (!).
933 * mcp takes the per port lock and corrupts pf B's access (and/or has it's own
934 * acess corrupted by pf B).*
935 */
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000936static int bnx2x_acquire_nvram_lock(struct bnx2x *bp)
937{
938 int port = BP_PORT(bp);
939 int count, i;
Ariel Eliorf16da432012-01-26 06:01:50 +0000940 u32 val;
941
942 /* acquire HW lock: protect against other PFs in PF Direct Assignment */
943 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_NVRAM);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000944
945 /* adjust timeout for emulation/FPGA */
Dmitry Kravkov754a2f52011-06-14 01:34:02 +0000946 count = BNX2X_NVRAM_TIMEOUT_COUNT;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000947 if (CHIP_REV_IS_SLOW(bp))
948 count *= 100;
949
950 /* request access to nvram interface */
951 REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
952 (MCPR_NVM_SW_ARB_ARB_REQ_SET1 << port));
953
954 for (i = 0; i < count*10; i++) {
955 val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB);
956 if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))
957 break;
958
959 udelay(5);
960 }
961
962 if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000963 DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
964 "cannot get access to nvram interface\n");
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000965 return -EBUSY;
966 }
967
968 return 0;
969}
970
971static int bnx2x_release_nvram_lock(struct bnx2x *bp)
972{
973 int port = BP_PORT(bp);
974 int count, i;
Ariel Eliorf16da432012-01-26 06:01:50 +0000975 u32 val;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000976
977 /* adjust timeout for emulation/FPGA */
Dmitry Kravkov754a2f52011-06-14 01:34:02 +0000978 count = BNX2X_NVRAM_TIMEOUT_COUNT;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000979 if (CHIP_REV_IS_SLOW(bp))
980 count *= 100;
981
982 /* relinquish nvram interface */
983 REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
984 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << port));
985
986 for (i = 0; i < count*10; i++) {
987 val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB);
988 if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)))
989 break;
990
991 udelay(5);
992 }
993
994 if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000995 DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
996 "cannot free access to nvram interface\n");
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000997 return -EBUSY;
998 }
999
Ariel Eliorf16da432012-01-26 06:01:50 +00001000 /* release HW lock: protect against other PFs in PF Direct Assignment */
1001 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_NVRAM);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001002 return 0;
1003}
1004
1005static void bnx2x_enable_nvram_access(struct bnx2x *bp)
1006{
1007 u32 val;
1008
1009 val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
1010
1011 /* enable both bits, even on read */
1012 REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
1013 (val | MCPR_NVM_ACCESS_ENABLE_EN |
1014 MCPR_NVM_ACCESS_ENABLE_WR_EN));
1015}
1016
1017static void bnx2x_disable_nvram_access(struct bnx2x *bp)
1018{
1019 u32 val;
1020
1021 val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
1022
1023 /* disable both bits, even after read */
1024 REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
1025 (val & ~(MCPR_NVM_ACCESS_ENABLE_EN |
1026 MCPR_NVM_ACCESS_ENABLE_WR_EN)));
1027}
1028
1029static int bnx2x_nvram_read_dword(struct bnx2x *bp, u32 offset, __be32 *ret_val,
1030 u32 cmd_flags)
1031{
1032 int count, i, rc;
1033 u32 val;
1034
1035 /* build the command word */
1036 cmd_flags |= MCPR_NVM_COMMAND_DOIT;
1037
1038 /* need to clear DONE bit separately */
1039 REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
1040
1041 /* address of the NVRAM to read from */
1042 REG_WR(bp, MCP_REG_MCPR_NVM_ADDR,
1043 (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
1044
1045 /* issue a read command */
1046 REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
1047
1048 /* adjust timeout for emulation/FPGA */
Dmitry Kravkov754a2f52011-06-14 01:34:02 +00001049 count = BNX2X_NVRAM_TIMEOUT_COUNT;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001050 if (CHIP_REV_IS_SLOW(bp))
1051 count *= 100;
1052
1053 /* wait for completion */
1054 *ret_val = 0;
1055 rc = -EBUSY;
1056 for (i = 0; i < count; i++) {
1057 udelay(5);
1058 val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND);
1059
1060 if (val & MCPR_NVM_COMMAND_DONE) {
1061 val = REG_RD(bp, MCP_REG_MCPR_NVM_READ);
1062 /* we read nvram data in cpu order
1063 * but ethtool sees it as an array of bytes
1064 * converting to big-endian will do the work */
1065 *ret_val = cpu_to_be32(val);
1066 rc = 0;
1067 break;
1068 }
1069 }
Merav Sicron51c1a582012-03-18 10:33:38 +00001070 if (rc == -EBUSY)
1071 DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
1072 "nvram read timeout expired\n");
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001073 return rc;
1074}
1075
1076static int bnx2x_nvram_read(struct bnx2x *bp, u32 offset, u8 *ret_buf,
1077 int buf_size)
1078{
1079 int rc;
1080 u32 cmd_flags;
1081 __be32 val;
1082
1083 if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001084 DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001085 "Invalid parameter: offset 0x%x buf_size 0x%x\n",
1086 offset, buf_size);
1087 return -EINVAL;
1088 }
1089
1090 if (offset + buf_size > bp->common.flash_size) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001091 DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
1092 "Invalid parameter: offset (0x%x) + buf_size (0x%x) > flash_size (0x%x)\n",
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001093 offset, buf_size, bp->common.flash_size);
1094 return -EINVAL;
1095 }
1096
1097 /* request access to nvram interface */
1098 rc = bnx2x_acquire_nvram_lock(bp);
1099 if (rc)
1100 return rc;
1101
1102 /* enable access to nvram interface */
1103 bnx2x_enable_nvram_access(bp);
1104
1105 /* read the first word(s) */
1106 cmd_flags = MCPR_NVM_COMMAND_FIRST;
1107 while ((buf_size > sizeof(u32)) && (rc == 0)) {
1108 rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags);
1109 memcpy(ret_buf, &val, 4);
1110
1111 /* advance to the next dword */
1112 offset += sizeof(u32);
1113 ret_buf += sizeof(u32);
1114 buf_size -= sizeof(u32);
1115 cmd_flags = 0;
1116 }
1117
1118 if (rc == 0) {
1119 cmd_flags |= MCPR_NVM_COMMAND_LAST;
1120 rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags);
1121 memcpy(ret_buf, &val, 4);
1122 }
1123
1124 /* disable access to nvram interface */
1125 bnx2x_disable_nvram_access(bp);
1126 bnx2x_release_nvram_lock(bp);
1127
1128 return rc;
1129}
1130
1131static int bnx2x_get_eeprom(struct net_device *dev,
1132 struct ethtool_eeprom *eeprom, u8 *eebuf)
1133{
1134 struct bnx2x *bp = netdev_priv(dev);
1135 int rc;
1136
Merav Sicron51c1a582012-03-18 10:33:38 +00001137 if (!netif_running(dev)) {
1138 DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
1139 "cannot access eeprom when the interface is down\n");
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001140 return -EAGAIN;
Merav Sicron51c1a582012-03-18 10:33:38 +00001141 }
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001142
Merav Sicron51c1a582012-03-18 10:33:38 +00001143 DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n"
Joe Perchesf1deab52011-08-14 12:16:21 +00001144 " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001145 eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset,
1146 eeprom->len, eeprom->len);
1147
1148 /* parameters already validated in ethtool_get_eeprom */
1149
1150 rc = bnx2x_nvram_read(bp, eeprom->offset, eebuf, eeprom->len);
1151
1152 return rc;
1153}
1154
1155static int bnx2x_nvram_write_dword(struct bnx2x *bp, u32 offset, u32 val,
1156 u32 cmd_flags)
1157{
1158 int count, i, rc;
1159
1160 /* build the command word */
1161 cmd_flags |= MCPR_NVM_COMMAND_DOIT | MCPR_NVM_COMMAND_WR;
1162
1163 /* need to clear DONE bit separately */
1164 REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
1165
1166 /* write the data */
1167 REG_WR(bp, MCP_REG_MCPR_NVM_WRITE, val);
1168
1169 /* address of the NVRAM to write to */
1170 REG_WR(bp, MCP_REG_MCPR_NVM_ADDR,
1171 (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
1172
1173 /* issue the write command */
1174 REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
1175
1176 /* adjust timeout for emulation/FPGA */
Dmitry Kravkov754a2f52011-06-14 01:34:02 +00001177 count = BNX2X_NVRAM_TIMEOUT_COUNT;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001178 if (CHIP_REV_IS_SLOW(bp))
1179 count *= 100;
1180
1181 /* wait for completion */
1182 rc = -EBUSY;
1183 for (i = 0; i < count; i++) {
1184 udelay(5);
1185 val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND);
1186 if (val & MCPR_NVM_COMMAND_DONE) {
1187 rc = 0;
1188 break;
1189 }
1190 }
1191
Merav Sicron51c1a582012-03-18 10:33:38 +00001192 if (rc == -EBUSY)
1193 DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
1194 "nvram write timeout expired\n");
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001195 return rc;
1196}
1197
1198#define BYTE_OFFSET(offset) (8 * (offset & 0x03))
1199
1200static int bnx2x_nvram_write1(struct bnx2x *bp, u32 offset, u8 *data_buf,
1201 int buf_size)
1202{
1203 int rc;
1204 u32 cmd_flags;
1205 u32 align_offset;
1206 __be32 val;
1207
1208 if (offset + buf_size > bp->common.flash_size) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001209 DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
1210 "Invalid parameter: offset (0x%x) + buf_size (0x%x) > flash_size (0x%x)\n",
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001211 offset, buf_size, bp->common.flash_size);
1212 return -EINVAL;
1213 }
1214
1215 /* request access to nvram interface */
1216 rc = bnx2x_acquire_nvram_lock(bp);
1217 if (rc)
1218 return rc;
1219
1220 /* enable access to nvram interface */
1221 bnx2x_enable_nvram_access(bp);
1222
1223 cmd_flags = (MCPR_NVM_COMMAND_FIRST | MCPR_NVM_COMMAND_LAST);
1224 align_offset = (offset & ~0x03);
1225 rc = bnx2x_nvram_read_dword(bp, align_offset, &val, cmd_flags);
1226
1227 if (rc == 0) {
1228 val &= ~(0xff << BYTE_OFFSET(offset));
1229 val |= (*data_buf << BYTE_OFFSET(offset));
1230
1231 /* nvram data is returned as an array of bytes
1232 * convert it back to cpu order */
1233 val = be32_to_cpu(val);
1234
1235 rc = bnx2x_nvram_write_dword(bp, align_offset, val,
1236 cmd_flags);
1237 }
1238
1239 /* disable access to nvram interface */
1240 bnx2x_disable_nvram_access(bp);
1241 bnx2x_release_nvram_lock(bp);
1242
1243 return rc;
1244}
1245
1246static int bnx2x_nvram_write(struct bnx2x *bp, u32 offset, u8 *data_buf,
1247 int buf_size)
1248{
1249 int rc;
1250 u32 cmd_flags;
1251 u32 val;
1252 u32 written_so_far;
1253
1254 if (buf_size == 1) /* ethtool */
1255 return bnx2x_nvram_write1(bp, offset, data_buf, buf_size);
1256
1257 if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001258 DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001259 "Invalid parameter: offset 0x%x buf_size 0x%x\n",
1260 offset, buf_size);
1261 return -EINVAL;
1262 }
1263
1264 if (offset + buf_size > bp->common.flash_size) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001265 DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
1266 "Invalid parameter: offset (0x%x) + buf_size (0x%x) > flash_size (0x%x)\n",
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001267 offset, buf_size, bp->common.flash_size);
1268 return -EINVAL;
1269 }
1270
1271 /* request access to nvram interface */
1272 rc = bnx2x_acquire_nvram_lock(bp);
1273 if (rc)
1274 return rc;
1275
1276 /* enable access to nvram interface */
1277 bnx2x_enable_nvram_access(bp);
1278
1279 written_so_far = 0;
1280 cmd_flags = MCPR_NVM_COMMAND_FIRST;
1281 while ((written_so_far < buf_size) && (rc == 0)) {
1282 if (written_so_far == (buf_size - sizeof(u32)))
1283 cmd_flags |= MCPR_NVM_COMMAND_LAST;
Dmitry Kravkov754a2f52011-06-14 01:34:02 +00001284 else if (((offset + 4) % BNX2X_NVRAM_PAGE_SIZE) == 0)
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001285 cmd_flags |= MCPR_NVM_COMMAND_LAST;
Dmitry Kravkov754a2f52011-06-14 01:34:02 +00001286 else if ((offset % BNX2X_NVRAM_PAGE_SIZE) == 0)
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001287 cmd_flags |= MCPR_NVM_COMMAND_FIRST;
1288
1289 memcpy(&val, data_buf, 4);
1290
1291 rc = bnx2x_nvram_write_dword(bp, offset, val, cmd_flags);
1292
1293 /* advance to the next dword */
1294 offset += sizeof(u32);
1295 data_buf += sizeof(u32);
1296 written_so_far += sizeof(u32);
1297 cmd_flags = 0;
1298 }
1299
1300 /* disable access to nvram interface */
1301 bnx2x_disable_nvram_access(bp);
1302 bnx2x_release_nvram_lock(bp);
1303
1304 return rc;
1305}
1306
1307static int bnx2x_set_eeprom(struct net_device *dev,
1308 struct ethtool_eeprom *eeprom, u8 *eebuf)
1309{
1310 struct bnx2x *bp = netdev_priv(dev);
1311 int port = BP_PORT(bp);
1312 int rc = 0;
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001313 u32 ext_phy_config;
Merav Sicron51c1a582012-03-18 10:33:38 +00001314 if (!netif_running(dev)) {
1315 DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
1316 "cannot access eeprom when the interface is down\n");
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001317 return -EAGAIN;
Merav Sicron51c1a582012-03-18 10:33:38 +00001318 }
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001319
Merav Sicron51c1a582012-03-18 10:33:38 +00001320 DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n"
Joe Perchesf1deab52011-08-14 12:16:21 +00001321 " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001322 eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset,
1323 eeprom->len, eeprom->len);
1324
1325 /* parameters already validated in ethtool_set_eeprom */
1326
1327 /* PHY eeprom can be accessed only by the PMF */
1328 if ((eeprom->magic >= 0x50485900) && (eeprom->magic <= 0x504859FF) &&
Merav Sicron51c1a582012-03-18 10:33:38 +00001329 !bp->port.pmf) {
1330 DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
1331 "wrong magic or interface is not pmf\n");
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001332 return -EINVAL;
Merav Sicron51c1a582012-03-18 10:33:38 +00001333 }
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001334
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001335 ext_phy_config =
1336 SHMEM_RD(bp,
1337 dev_info.port_hw_config[port].external_phy_config);
1338
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001339 if (eeprom->magic == 0x50485950) {
1340 /* 'PHYP' (0x50485950): prepare phy for FW upgrade */
1341 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
1342
1343 bnx2x_acquire_phy_lock(bp);
1344 rc |= bnx2x_link_reset(&bp->link_params,
1345 &bp->link_vars, 0);
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001346 if (XGXS_EXT_PHY_TYPE(ext_phy_config) ==
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001347 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101)
1348 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
1349 MISC_REGISTERS_GPIO_HIGH, port);
1350 bnx2x_release_phy_lock(bp);
1351 bnx2x_link_report(bp);
1352
1353 } else if (eeprom->magic == 0x50485952) {
1354 /* 'PHYR' (0x50485952): re-init link after FW upgrade */
1355 if (bp->state == BNX2X_STATE_OPEN) {
1356 bnx2x_acquire_phy_lock(bp);
1357 rc |= bnx2x_link_reset(&bp->link_params,
1358 &bp->link_vars, 1);
1359
1360 rc |= bnx2x_phy_init(&bp->link_params,
1361 &bp->link_vars);
1362 bnx2x_release_phy_lock(bp);
1363 bnx2x_calc_fc_adv(bp);
1364 }
1365 } else if (eeprom->magic == 0x53985943) {
1366 /* 'PHYC' (0x53985943): PHY FW upgrade completed */
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001367 if (XGXS_EXT_PHY_TYPE(ext_phy_config) ==
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001368 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101) {
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001369
1370 /* DSP Remove Download Mode */
1371 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
1372 MISC_REGISTERS_GPIO_LOW, port);
1373
1374 bnx2x_acquire_phy_lock(bp);
1375
Yaniv Rosnere10bc842010-09-07 11:40:50 +00001376 bnx2x_sfx7101_sp_sw_reset(bp,
1377 &bp->link_params.phy[EXT_PHY1]);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001378
1379 /* wait 0.5 sec to allow it to run */
1380 msleep(500);
1381 bnx2x_ext_phy_hw_reset(bp, port);
1382 msleep(500);
1383 bnx2x_release_phy_lock(bp);
1384 }
1385 } else
1386 rc = bnx2x_nvram_write(bp, eeprom->offset, eebuf, eeprom->len);
1387
1388 return rc;
1389}
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00001390
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001391static int bnx2x_get_coalesce(struct net_device *dev,
1392 struct ethtool_coalesce *coal)
1393{
1394 struct bnx2x *bp = netdev_priv(dev);
1395
1396 memset(coal, 0, sizeof(struct ethtool_coalesce));
1397
1398 coal->rx_coalesce_usecs = bp->rx_ticks;
1399 coal->tx_coalesce_usecs = bp->tx_ticks;
1400
1401 return 0;
1402}
1403
1404static int bnx2x_set_coalesce(struct net_device *dev,
1405 struct ethtool_coalesce *coal)
1406{
1407 struct bnx2x *bp = netdev_priv(dev);
1408
1409 bp->rx_ticks = (u16)coal->rx_coalesce_usecs;
1410 if (bp->rx_ticks > BNX2X_MAX_COALESCE_TOUT)
1411 bp->rx_ticks = BNX2X_MAX_COALESCE_TOUT;
1412
1413 bp->tx_ticks = (u16)coal->tx_coalesce_usecs;
1414 if (bp->tx_ticks > BNX2X_MAX_COALESCE_TOUT)
1415 bp->tx_ticks = BNX2X_MAX_COALESCE_TOUT;
1416
1417 if (netif_running(dev))
1418 bnx2x_update_coalesce(bp);
1419
1420 return 0;
1421}
1422
1423static void bnx2x_get_ringparam(struct net_device *dev,
1424 struct ethtool_ringparam *ering)
1425{
1426 struct bnx2x *bp = netdev_priv(dev);
1427
1428 ering->rx_max_pending = MAX_RX_AVAIL;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001429
Dmitry Kravkov25141582010-09-12 05:48:28 +00001430 if (bp->rx_ring_size)
1431 ering->rx_pending = bp->rx_ring_size;
1432 else
David S. Miller8decf862011-09-22 03:23:13 -04001433 ering->rx_pending = MAX_RX_AVAIL;
Dmitry Kravkov25141582010-09-12 05:48:28 +00001434
Barak Witkowskia3348722012-04-23 03:04:46 +00001435 ering->tx_max_pending = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001436 ering->tx_pending = bp->tx_ring_size;
1437}
1438
1439static int bnx2x_set_ringparam(struct net_device *dev,
1440 struct ethtool_ringparam *ering)
1441{
1442 struct bnx2x *bp = netdev_priv(dev);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001443
1444 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001445 DP(BNX2X_MSG_ETHTOOL,
1446 "Handling parity error recovery. Try again later\n");
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001447 return -EAGAIN;
1448 }
1449
1450 if ((ering->rx_pending > MAX_RX_AVAIL) ||
Dmitry Kravkovb3b83c32011-05-04 23:50:33 +00001451 (ering->rx_pending < (bp->disable_tpa ? MIN_RX_SIZE_NONTPA :
1452 MIN_RX_SIZE_TPA)) ||
Barak Witkowskia3348722012-04-23 03:04:46 +00001453 (ering->tx_pending > (IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL)) ||
Merav Sicron51c1a582012-03-18 10:33:38 +00001454 (ering->tx_pending <= MAX_SKB_FRAGS + 4)) {
1455 DP(BNX2X_MSG_ETHTOOL, "Command parameters not supported\n");
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001456 return -EINVAL;
Merav Sicron51c1a582012-03-18 10:33:38 +00001457 }
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001458
1459 bp->rx_ring_size = ering->rx_pending;
1460 bp->tx_ring_size = ering->tx_pending;
1461
Dmitry Kravkova9fccec2011-06-14 01:33:30 +00001462 return bnx2x_reload_if_running(dev);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001463}
1464
1465static void bnx2x_get_pauseparam(struct net_device *dev,
1466 struct ethtool_pauseparam *epause)
1467{
1468 struct bnx2x *bp = netdev_priv(dev);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00001469 int cfg_idx = bnx2x_get_link_cfg_idx(bp);
Mintz Yuval9e7e8392012-02-15 02:10:24 +00001470 int cfg_reg;
1471
Yaniv Rosnera22f0782010-09-07 11:41:20 +00001472 epause->autoneg = (bp->link_params.req_flow_ctrl[cfg_idx] ==
1473 BNX2X_FLOW_CTRL_AUTO);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001474
Mintz Yuval9e7e8392012-02-15 02:10:24 +00001475 if (!epause->autoneg)
Yuval Mintz241fb5d2012-03-12 08:53:13 +00001476 cfg_reg = bp->link_params.req_flow_ctrl[cfg_idx];
Mintz Yuval9e7e8392012-02-15 02:10:24 +00001477 else
1478 cfg_reg = bp->link_params.req_fc_auto_adv;
1479
1480 epause->rx_pause = ((cfg_reg & BNX2X_FLOW_CTRL_RX) ==
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001481 BNX2X_FLOW_CTRL_RX);
Mintz Yuval9e7e8392012-02-15 02:10:24 +00001482 epause->tx_pause = ((cfg_reg & BNX2X_FLOW_CTRL_TX) ==
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001483 BNX2X_FLOW_CTRL_TX);
1484
Merav Sicron51c1a582012-03-18 10:33:38 +00001485 DP(BNX2X_MSG_ETHTOOL, "ethtool_pauseparam: cmd %d\n"
Joe Perchesf1deab52011-08-14 12:16:21 +00001486 " autoneg %d rx_pause %d tx_pause %d\n",
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001487 epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);
1488}
1489
1490static int bnx2x_set_pauseparam(struct net_device *dev,
1491 struct ethtool_pauseparam *epause)
1492{
1493 struct bnx2x *bp = netdev_priv(dev);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00001494 u32 cfg_idx = bnx2x_get_link_cfg_idx(bp);
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00001495 if (IS_MF(bp))
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001496 return 0;
1497
Merav Sicron51c1a582012-03-18 10:33:38 +00001498 DP(BNX2X_MSG_ETHTOOL, "ethtool_pauseparam: cmd %d\n"
Joe Perchesf1deab52011-08-14 12:16:21 +00001499 " autoneg %d rx_pause %d tx_pause %d\n",
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001500 epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);
1501
Yaniv Rosnera22f0782010-09-07 11:41:20 +00001502 bp->link_params.req_flow_ctrl[cfg_idx] = BNX2X_FLOW_CTRL_AUTO;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001503
1504 if (epause->rx_pause)
Yaniv Rosnera22f0782010-09-07 11:41:20 +00001505 bp->link_params.req_flow_ctrl[cfg_idx] |= BNX2X_FLOW_CTRL_RX;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001506
1507 if (epause->tx_pause)
Yaniv Rosnera22f0782010-09-07 11:41:20 +00001508 bp->link_params.req_flow_ctrl[cfg_idx] |= BNX2X_FLOW_CTRL_TX;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001509
Yaniv Rosnera22f0782010-09-07 11:41:20 +00001510 if (bp->link_params.req_flow_ctrl[cfg_idx] == BNX2X_FLOW_CTRL_AUTO)
1511 bp->link_params.req_flow_ctrl[cfg_idx] = BNX2X_FLOW_CTRL_NONE;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001512
1513 if (epause->autoneg) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00001514 if (!(bp->port.supported[cfg_idx] & SUPPORTED_Autoneg)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001515 DP(BNX2X_MSG_ETHTOOL, "autoneg not supported\n");
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001516 return -EINVAL;
1517 }
1518
Yaniv Rosnera22f0782010-09-07 11:41:20 +00001519 if (bp->link_params.req_line_speed[cfg_idx] == SPEED_AUTO_NEG) {
1520 bp->link_params.req_flow_ctrl[cfg_idx] =
1521 BNX2X_FLOW_CTRL_AUTO;
1522 }
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001523 }
1524
Merav Sicron51c1a582012-03-18 10:33:38 +00001525 DP(BNX2X_MSG_ETHTOOL,
Yaniv Rosnera22f0782010-09-07 11:41:20 +00001526 "req_flow_ctrl 0x%x\n", bp->link_params.req_flow_ctrl[cfg_idx]);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001527
1528 if (netif_running(dev)) {
1529 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
1530 bnx2x_link_set(bp);
1531 }
1532
1533 return 0;
1534}
1535
Merav Sicroncf2c1df62012-06-19 07:48:23 +00001536char *bnx2x_tests_str_arr[BNX2X_NUM_TESTS_SF] = {
1537 "register_test (offline) ",
1538 "memory_test (offline) ",
1539 "int_loopback_test (offline)",
1540 "ext_loopback_test (offline)",
1541 "nvram_test (online) ",
1542 "interrupt_test (online) ",
1543 "link_test (online) "
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001544};
1545
Yuval Mintze9939c82012-06-06 17:13:08 +00001546static u32 bnx2x_eee_to_adv(u32 eee_adv)
1547{
1548 u32 modes = 0;
1549
1550 if (eee_adv & SHMEM_EEE_100M_ADV)
1551 modes |= ADVERTISED_100baseT_Full;
1552 if (eee_adv & SHMEM_EEE_1G_ADV)
1553 modes |= ADVERTISED_1000baseT_Full;
1554 if (eee_adv & SHMEM_EEE_10G_ADV)
1555 modes |= ADVERTISED_10000baseT_Full;
1556
1557 return modes;
1558}
1559
1560static u32 bnx2x_adv_to_eee(u32 modes, u32 shift)
1561{
1562 u32 eee_adv = 0;
1563 if (modes & ADVERTISED_100baseT_Full)
1564 eee_adv |= SHMEM_EEE_100M_ADV;
1565 if (modes & ADVERTISED_1000baseT_Full)
1566 eee_adv |= SHMEM_EEE_1G_ADV;
1567 if (modes & ADVERTISED_10000baseT_Full)
1568 eee_adv |= SHMEM_EEE_10G_ADV;
1569
1570 return eee_adv << shift;
1571}
1572
1573static int bnx2x_get_eee(struct net_device *dev, struct ethtool_eee *edata)
1574{
1575 struct bnx2x *bp = netdev_priv(dev);
1576 u32 eee_cfg;
1577
1578 if (!SHMEM2_HAS(bp, eee_status[BP_PORT(bp)])) {
1579 DP(BNX2X_MSG_ETHTOOL, "BC Version does not support EEE\n");
1580 return -EOPNOTSUPP;
1581 }
1582
1583 eee_cfg = SHMEM2_RD(bp, eee_status[BP_PORT(bp)]);
1584
1585 edata->supported =
1586 bnx2x_eee_to_adv((eee_cfg & SHMEM_EEE_SUPPORTED_MASK) >>
1587 SHMEM_EEE_SUPPORTED_SHIFT);
1588
1589 edata->advertised =
1590 bnx2x_eee_to_adv((eee_cfg & SHMEM_EEE_ADV_STATUS_MASK) >>
1591 SHMEM_EEE_ADV_STATUS_SHIFT);
1592 edata->lp_advertised =
1593 bnx2x_eee_to_adv((eee_cfg & SHMEM_EEE_LP_ADV_STATUS_MASK) >>
1594 SHMEM_EEE_LP_ADV_STATUS_SHIFT);
1595
1596 /* SHMEM value is in 16u units --> Convert to 1u units. */
1597 edata->tx_lpi_timer = (eee_cfg & SHMEM_EEE_TIMER_MASK) << 4;
1598
1599 edata->eee_enabled = (eee_cfg & SHMEM_EEE_REQUESTED_BIT) ? 1 : 0;
1600 edata->eee_active = (eee_cfg & SHMEM_EEE_ACTIVE_BIT) ? 1 : 0;
1601 edata->tx_lpi_enabled = (eee_cfg & SHMEM_EEE_LPI_REQUESTED_BIT) ? 1 : 0;
1602
1603 return 0;
1604}
1605
1606static int bnx2x_set_eee(struct net_device *dev, struct ethtool_eee *edata)
1607{
1608 struct bnx2x *bp = netdev_priv(dev);
1609 u32 eee_cfg;
1610 u32 advertised;
1611
1612 if (IS_MF(bp))
1613 return 0;
1614
1615 if (!SHMEM2_HAS(bp, eee_status[BP_PORT(bp)])) {
1616 DP(BNX2X_MSG_ETHTOOL, "BC Version does not support EEE\n");
1617 return -EOPNOTSUPP;
1618 }
1619
1620 eee_cfg = SHMEM2_RD(bp, eee_status[BP_PORT(bp)]);
1621
1622 if (!(eee_cfg & SHMEM_EEE_SUPPORTED_MASK)) {
1623 DP(BNX2X_MSG_ETHTOOL, "Board does not support EEE!\n");
1624 return -EOPNOTSUPP;
1625 }
1626
1627 advertised = bnx2x_adv_to_eee(edata->advertised,
1628 SHMEM_EEE_ADV_STATUS_SHIFT);
1629 if ((advertised != (eee_cfg & SHMEM_EEE_ADV_STATUS_MASK))) {
1630 DP(BNX2X_MSG_ETHTOOL,
1631 "Direct manipulation of EEE advertisment is not supported\n");
1632 return -EINVAL;
1633 }
1634
1635 if (edata->tx_lpi_timer > EEE_MODE_TIMER_MASK) {
1636 DP(BNX2X_MSG_ETHTOOL,
1637 "Maximal Tx Lpi timer supported is %x(u)\n",
1638 EEE_MODE_TIMER_MASK);
1639 return -EINVAL;
1640 }
1641 if (edata->tx_lpi_enabled &&
1642 (edata->tx_lpi_timer < EEE_MODE_NVRAM_AGGRESSIVE_TIME)) {
1643 DP(BNX2X_MSG_ETHTOOL,
1644 "Minimal Tx Lpi timer supported is %d(u)\n",
1645 EEE_MODE_NVRAM_AGGRESSIVE_TIME);
1646 return -EINVAL;
1647 }
1648
1649 /* All is well; Apply changes*/
1650 if (edata->eee_enabled)
1651 bp->link_params.eee_mode |= EEE_MODE_ADV_LPI;
1652 else
1653 bp->link_params.eee_mode &= ~EEE_MODE_ADV_LPI;
1654
1655 if (edata->tx_lpi_enabled)
1656 bp->link_params.eee_mode |= EEE_MODE_ENABLE_LPI;
1657 else
1658 bp->link_params.eee_mode &= ~EEE_MODE_ENABLE_LPI;
1659
1660 bp->link_params.eee_mode &= ~EEE_MODE_TIMER_MASK;
1661 bp->link_params.eee_mode |= (edata->tx_lpi_timer &
1662 EEE_MODE_TIMER_MASK) |
1663 EEE_MODE_OVERRIDE_NVRAM |
1664 EEE_MODE_OUTPUT_TIME;
1665
1666 /* Restart link to propogate changes */
1667 if (netif_running(dev)) {
1668 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
1669 bnx2x_link_set(bp);
1670 }
1671
1672 return 0;
1673}
1674
1675
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001676enum {
1677 BNX2X_CHIP_E1_OFST = 0,
1678 BNX2X_CHIP_E1H_OFST,
1679 BNX2X_CHIP_E2_OFST,
1680 BNX2X_CHIP_E3_OFST,
1681 BNX2X_CHIP_E3B0_OFST,
1682 BNX2X_CHIP_MAX_OFST
1683};
1684
1685#define BNX2X_CHIP_MASK_E1 (1 << BNX2X_CHIP_E1_OFST)
1686#define BNX2X_CHIP_MASK_E1H (1 << BNX2X_CHIP_E1H_OFST)
1687#define BNX2X_CHIP_MASK_E2 (1 << BNX2X_CHIP_E2_OFST)
1688#define BNX2X_CHIP_MASK_E3 (1 << BNX2X_CHIP_E3_OFST)
1689#define BNX2X_CHIP_MASK_E3B0 (1 << BNX2X_CHIP_E3B0_OFST)
1690
1691#define BNX2X_CHIP_MASK_ALL ((1 << BNX2X_CHIP_MAX_OFST) - 1)
1692#define BNX2X_CHIP_MASK_E1X (BNX2X_CHIP_MASK_E1 | BNX2X_CHIP_MASK_E1H)
1693
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001694static int bnx2x_test_registers(struct bnx2x *bp)
1695{
1696 int idx, i, rc = -ENODEV;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001697 u32 wr_val = 0, hw;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001698 int port = BP_PORT(bp);
1699 static const struct {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001700 u32 hw;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001701 u32 offset0;
1702 u32 offset1;
1703 u32 mask;
1704 } reg_tbl[] = {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001705/* 0 */ { BNX2X_CHIP_MASK_ALL,
1706 BRB1_REG_PAUSE_LOW_THRESHOLD_0, 4, 0x000003ff },
1707 { BNX2X_CHIP_MASK_ALL,
1708 DORQ_REG_DB_ADDR0, 4, 0xffffffff },
1709 { BNX2X_CHIP_MASK_E1X,
1710 HC_REG_AGG_INT_0, 4, 0x000003ff },
1711 { BNX2X_CHIP_MASK_ALL,
1712 PBF_REG_MAC_IF0_ENABLE, 4, 0x00000001 },
1713 { BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2 | BNX2X_CHIP_MASK_E3,
1714 PBF_REG_P0_INIT_CRD, 4, 0x000007ff },
1715 { BNX2X_CHIP_MASK_E3B0,
1716 PBF_REG_INIT_CRD_Q0, 4, 0x000007ff },
1717 { BNX2X_CHIP_MASK_ALL,
1718 PRS_REG_CID_PORT_0, 4, 0x00ffffff },
1719 { BNX2X_CHIP_MASK_ALL,
1720 PXP2_REG_PSWRQ_CDU0_L2P, 4, 0x000fffff },
1721 { BNX2X_CHIP_MASK_ALL,
1722 PXP2_REG_RQ_CDU0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
1723 { BNX2X_CHIP_MASK_ALL,
1724 PXP2_REG_PSWRQ_TM0_L2P, 4, 0x000fffff },
1725/* 10 */ { BNX2X_CHIP_MASK_ALL,
1726 PXP2_REG_RQ_USDM0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
1727 { BNX2X_CHIP_MASK_ALL,
1728 PXP2_REG_PSWRQ_TSDM0_L2P, 4, 0x000fffff },
1729 { BNX2X_CHIP_MASK_ALL,
1730 QM_REG_CONNNUM_0, 4, 0x000fffff },
1731 { BNX2X_CHIP_MASK_ALL,
1732 TM_REG_LIN0_MAX_ACTIVE_CID, 4, 0x0003ffff },
1733 { BNX2X_CHIP_MASK_ALL,
1734 SRC_REG_KEYRSS0_0, 40, 0xffffffff },
1735 { BNX2X_CHIP_MASK_ALL,
1736 SRC_REG_KEYRSS0_7, 40, 0xffffffff },
1737 { BNX2X_CHIP_MASK_ALL,
1738 XCM_REG_WU_DA_SET_TMR_CNT_FLG_CMD00, 4, 0x00000001 },
1739 { BNX2X_CHIP_MASK_ALL,
1740 XCM_REG_WU_DA_CNT_CMD00, 4, 0x00000003 },
1741 { BNX2X_CHIP_MASK_ALL,
1742 XCM_REG_GLB_DEL_ACK_MAX_CNT_0, 4, 0x000000ff },
1743 { BNX2X_CHIP_MASK_ALL,
1744 NIG_REG_LLH0_T_BIT, 4, 0x00000001 },
1745/* 20 */ { BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2,
1746 NIG_REG_EMAC0_IN_EN, 4, 0x00000001 },
1747 { BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2,
1748 NIG_REG_BMAC0_IN_EN, 4, 0x00000001 },
1749 { BNX2X_CHIP_MASK_ALL,
1750 NIG_REG_XCM0_OUT_EN, 4, 0x00000001 },
1751 { BNX2X_CHIP_MASK_ALL,
1752 NIG_REG_BRB0_OUT_EN, 4, 0x00000001 },
1753 { BNX2X_CHIP_MASK_ALL,
1754 NIG_REG_LLH0_XCM_MASK, 4, 0x00000007 },
1755 { BNX2X_CHIP_MASK_ALL,
1756 NIG_REG_LLH0_ACPI_PAT_6_LEN, 68, 0x000000ff },
1757 { BNX2X_CHIP_MASK_ALL,
1758 NIG_REG_LLH0_ACPI_PAT_0_CRC, 68, 0xffffffff },
1759 { BNX2X_CHIP_MASK_ALL,
1760 NIG_REG_LLH0_DEST_MAC_0_0, 160, 0xffffffff },
1761 { BNX2X_CHIP_MASK_ALL,
1762 NIG_REG_LLH0_DEST_IP_0_1, 160, 0xffffffff },
1763 { BNX2X_CHIP_MASK_ALL,
1764 NIG_REG_LLH0_IPV4_IPV6_0, 160, 0x00000001 },
1765/* 30 */ { BNX2X_CHIP_MASK_ALL,
1766 NIG_REG_LLH0_DEST_UDP_0, 160, 0x0000ffff },
1767 { BNX2X_CHIP_MASK_ALL,
1768 NIG_REG_LLH0_DEST_TCP_0, 160, 0x0000ffff },
1769 { BNX2X_CHIP_MASK_ALL,
1770 NIG_REG_LLH0_VLAN_ID_0, 160, 0x00000fff },
1771 { BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2,
1772 NIG_REG_XGXS_SERDES0_MODE_SEL, 4, 0x00000001 },
1773 { BNX2X_CHIP_MASK_ALL,
1774 NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0, 4, 0x00000001},
1775 { BNX2X_CHIP_MASK_ALL,
1776 NIG_REG_STATUS_INTERRUPT_PORT0, 4, 0x07ffffff },
1777 { BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2,
1778 NIG_REG_XGXS0_CTRL_EXTREMOTEMDIOST, 24, 0x00000001 },
1779 { BNX2X_CHIP_MASK_E1X | BNX2X_CHIP_MASK_E2,
1780 NIG_REG_SERDES0_CTRL_PHY_ADDR, 16, 0x0000001f },
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001781
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001782 { BNX2X_CHIP_MASK_ALL, 0xffffffff, 0, 0x00000000 }
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001783 };
1784
Merav Sicron51c1a582012-03-18 10:33:38 +00001785 if (!netif_running(bp->dev)) {
1786 DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
1787 "cannot access eeprom when the interface is down\n");
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001788 return rc;
Merav Sicron51c1a582012-03-18 10:33:38 +00001789 }
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001790
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001791 if (CHIP_IS_E1(bp))
1792 hw = BNX2X_CHIP_MASK_E1;
1793 else if (CHIP_IS_E1H(bp))
1794 hw = BNX2X_CHIP_MASK_E1H;
1795 else if (CHIP_IS_E2(bp))
1796 hw = BNX2X_CHIP_MASK_E2;
1797 else if (CHIP_IS_E3B0(bp))
1798 hw = BNX2X_CHIP_MASK_E3B0;
1799 else /* e3 A0 */
1800 hw = BNX2X_CHIP_MASK_E3;
1801
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001802 /* Repeat the test twice:
1803 First by writing 0x00000000, second by writing 0xffffffff */
1804 for (idx = 0; idx < 2; idx++) {
1805
1806 switch (idx) {
1807 case 0:
1808 wr_val = 0;
1809 break;
1810 case 1:
1811 wr_val = 0xffffffff;
1812 break;
1813 }
1814
1815 for (i = 0; reg_tbl[i].offset0 != 0xffffffff; i++) {
1816 u32 offset, mask, save_val, val;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001817 if (!(hw & reg_tbl[i].hw))
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001818 continue;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001819
1820 offset = reg_tbl[i].offset0 + port*reg_tbl[i].offset1;
1821 mask = reg_tbl[i].mask;
1822
1823 save_val = REG_RD(bp, offset);
1824
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00001825 REG_WR(bp, offset, wr_val & mask);
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00001826
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001827 val = REG_RD(bp, offset);
1828
1829 /* Restore the original register's value */
1830 REG_WR(bp, offset, save_val);
1831
1832 /* verify value is as expected */
1833 if ((val & mask) != (wr_val & mask)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001834 DP(BNX2X_MSG_ETHTOOL,
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001835 "offset 0x%x: val 0x%x != 0x%x mask 0x%x\n",
1836 offset, val, wr_val, mask);
1837 goto test_reg_exit;
1838 }
1839 }
1840 }
1841
1842 rc = 0;
1843
1844test_reg_exit:
1845 return rc;
1846}
1847
1848static int bnx2x_test_memory(struct bnx2x *bp)
1849{
1850 int i, j, rc = -ENODEV;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001851 u32 val, index;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001852 static const struct {
1853 u32 offset;
1854 int size;
1855 } mem_tbl[] = {
1856 { CCM_REG_XX_DESCR_TABLE, CCM_REG_XX_DESCR_TABLE_SIZE },
1857 { CFC_REG_ACTIVITY_COUNTER, CFC_REG_ACTIVITY_COUNTER_SIZE },
1858 { CFC_REG_LINK_LIST, CFC_REG_LINK_LIST_SIZE },
1859 { DMAE_REG_CMD_MEM, DMAE_REG_CMD_MEM_SIZE },
1860 { TCM_REG_XX_DESCR_TABLE, TCM_REG_XX_DESCR_TABLE_SIZE },
1861 { UCM_REG_XX_DESCR_TABLE, UCM_REG_XX_DESCR_TABLE_SIZE },
1862 { XCM_REG_XX_DESCR_TABLE, XCM_REG_XX_DESCR_TABLE_SIZE },
1863
1864 { 0xffffffff, 0 }
1865 };
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001866
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001867 static const struct {
1868 char *name;
1869 u32 offset;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001870 u32 hw_mask[BNX2X_CHIP_MAX_OFST];
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001871 } prty_tbl[] = {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001872 { "CCM_PRTY_STS", CCM_REG_CCM_PRTY_STS,
1873 {0x3ffc0, 0, 0, 0} },
1874 { "CFC_PRTY_STS", CFC_REG_CFC_PRTY_STS,
1875 {0x2, 0x2, 0, 0} },
1876 { "DMAE_PRTY_STS", DMAE_REG_DMAE_PRTY_STS,
1877 {0, 0, 0, 0} },
1878 { "TCM_PRTY_STS", TCM_REG_TCM_PRTY_STS,
1879 {0x3ffc0, 0, 0, 0} },
1880 { "UCM_PRTY_STS", UCM_REG_UCM_PRTY_STS,
1881 {0x3ffc0, 0, 0, 0} },
1882 { "XCM_PRTY_STS", XCM_REG_XCM_PRTY_STS,
1883 {0x3ffc1, 0, 0, 0} },
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001884
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001885 { NULL, 0xffffffff, {0, 0, 0, 0} }
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001886 };
1887
Merav Sicron51c1a582012-03-18 10:33:38 +00001888 if (!netif_running(bp->dev)) {
1889 DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
1890 "cannot access eeprom when the interface is down\n");
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001891 return rc;
Merav Sicron51c1a582012-03-18 10:33:38 +00001892 }
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001893
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001894 if (CHIP_IS_E1(bp))
1895 index = BNX2X_CHIP_E1_OFST;
1896 else if (CHIP_IS_E1H(bp))
1897 index = BNX2X_CHIP_E1H_OFST;
1898 else if (CHIP_IS_E2(bp))
1899 index = BNX2X_CHIP_E2_OFST;
1900 else /* e3 */
1901 index = BNX2X_CHIP_E3_OFST;
1902
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001903 /* pre-Check the parity status */
1904 for (i = 0; prty_tbl[i].offset != 0xffffffff; i++) {
1905 val = REG_RD(bp, prty_tbl[i].offset);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001906 if (val & ~(prty_tbl[i].hw_mask[index])) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001907 DP(BNX2X_MSG_ETHTOOL,
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001908 "%s is 0x%x\n", prty_tbl[i].name, val);
1909 goto test_mem_exit;
1910 }
1911 }
1912
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001913 /* Go through all the memories */
1914 for (i = 0; mem_tbl[i].offset != 0xffffffff; i++)
1915 for (j = 0; j < mem_tbl[i].size; j++)
1916 REG_RD(bp, mem_tbl[i].offset + j*4);
1917
1918 /* Check the parity status */
1919 for (i = 0; prty_tbl[i].offset != 0xffffffff; i++) {
1920 val = REG_RD(bp, prty_tbl[i].offset);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001921 if (val & ~(prty_tbl[i].hw_mask[index])) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001922 DP(BNX2X_MSG_ETHTOOL,
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001923 "%s is 0x%x\n", prty_tbl[i].name, val);
1924 goto test_mem_exit;
1925 }
1926 }
1927
1928 rc = 0;
1929
1930test_mem_exit:
1931 return rc;
1932}
1933
Yaniv Rosnera22f0782010-09-07 11:41:20 +00001934static void bnx2x_wait_for_link(struct bnx2x *bp, u8 link_up, u8 is_serdes)
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001935{
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001936 int cnt = 1400;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001937
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001938 if (link_up) {
Yaniv Rosnera22f0782010-09-07 11:41:20 +00001939 while (bnx2x_link_test(bp, is_serdes) && cnt--)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001940 msleep(20);
1941
1942 if (cnt <= 0 && bnx2x_link_test(bp, is_serdes))
Merav Sicron51c1a582012-03-18 10:33:38 +00001943 DP(BNX2X_MSG_ETHTOOL, "Timeout waiting for link up\n");
Merav Sicron8970b2e2012-06-19 07:48:22 +00001944
1945 cnt = 1400;
1946 while (!bp->link_vars.link_up && cnt--)
1947 msleep(20);
1948
1949 if (cnt <= 0 && !bp->link_vars.link_up)
1950 DP(BNX2X_MSG_ETHTOOL,
1951 "Timeout waiting for link init\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001952 }
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001953}
1954
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001955static int bnx2x_run_loopback(struct bnx2x *bp, int loopback_mode)
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001956{
1957 unsigned int pkt_size, num_pkts, i;
1958 struct sk_buff *skb;
1959 unsigned char *packet;
1960 struct bnx2x_fastpath *fp_rx = &bp->fp[0];
1961 struct bnx2x_fastpath *fp_tx = &bp->fp[0];
Ariel Elior6383c0b2011-07-14 08:31:57 +00001962 struct bnx2x_fp_txdata *txdata = &fp_tx->txdata[0];
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001963 u16 tx_start_idx, tx_idx;
1964 u16 rx_start_idx, rx_idx;
Dmitry Kravkovb0700b12012-01-23 07:31:53 +00001965 u16 pkt_prod, bd_prod;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001966 struct sw_tx_bd *tx_buf;
1967 struct eth_tx_start_bd *tx_start_bd;
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00001968 struct eth_tx_parse_bd_e1x *pbd_e1x = NULL;
1969 struct eth_tx_parse_bd_e2 *pbd_e2 = NULL;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001970 dma_addr_t mapping;
1971 union eth_rx_cqe *cqe;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001972 u8 cqe_fp_flags, cqe_fp_type;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001973 struct sw_rx_bd *rx_buf;
1974 u16 len;
1975 int rc = -ENODEV;
Eric Dumazete52fcb22011-11-14 06:05:34 +00001976 u8 *data;
Merav Sicron8970b2e2012-06-19 07:48:22 +00001977 struct netdev_queue *txq = netdev_get_tx_queue(bp->dev,
1978 txdata->txq_index);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001979
1980 /* check the loopback mode */
1981 switch (loopback_mode) {
1982 case BNX2X_PHY_LOOPBACK:
Merav Sicron8970b2e2012-06-19 07:48:22 +00001983 if (bp->link_params.loopback_mode != LOOPBACK_XGXS) {
1984 DP(BNX2X_MSG_ETHTOOL, "PHY loopback not supported\n");
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001985 return -EINVAL;
Merav Sicron8970b2e2012-06-19 07:48:22 +00001986 }
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001987 break;
1988 case BNX2X_MAC_LOOPBACK:
Yaniv Rosner32911332011-11-28 00:49:51 +00001989 if (CHIP_IS_E3(bp)) {
1990 int cfg_idx = bnx2x_get_link_cfg_idx(bp);
1991 if (bp->port.supported[cfg_idx] &
1992 (SUPPORTED_10000baseT_Full |
1993 SUPPORTED_20000baseMLD2_Full |
1994 SUPPORTED_20000baseKR2_Full))
1995 bp->link_params.loopback_mode = LOOPBACK_XMAC;
1996 else
1997 bp->link_params.loopback_mode = LOOPBACK_UMAC;
1998 } else
1999 bp->link_params.loopback_mode = LOOPBACK_BMAC;
2000
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002001 bnx2x_phy_init(&bp->link_params, &bp->link_vars);
2002 break;
Merav Sicron8970b2e2012-06-19 07:48:22 +00002003 case BNX2X_EXT_LOOPBACK:
2004 if (bp->link_params.loopback_mode != LOOPBACK_EXT) {
2005 DP(BNX2X_MSG_ETHTOOL,
2006 "Can't configure external loopback\n");
2007 return -EINVAL;
2008 }
2009 break;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002010 default:
Merav Sicron51c1a582012-03-18 10:33:38 +00002011 DP(BNX2X_MSG_ETHTOOL, "Command parameters not supported\n");
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002012 return -EINVAL;
2013 }
2014
2015 /* prepare the loopback packet */
2016 pkt_size = (((bp->dev->mtu < ETH_MAX_PACKET_SIZE) ?
2017 bp->dev->mtu : ETH_MAX_PACKET_SIZE) + ETH_HLEN);
Vladislav Zolotarova8c94b92011-02-06 11:21:02 -08002018 skb = netdev_alloc_skb(bp->dev, fp_rx->rx_buf_size);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002019 if (!skb) {
Merav Sicron51c1a582012-03-18 10:33:38 +00002020 DP(BNX2X_MSG_ETHTOOL, "Can't allocate skb\n");
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002021 rc = -ENOMEM;
2022 goto test_loopback_exit;
2023 }
2024 packet = skb_put(skb, pkt_size);
2025 memcpy(packet, bp->dev->dev_addr, ETH_ALEN);
2026 memset(packet + ETH_ALEN, 0, ETH_ALEN);
2027 memset(packet + 2*ETH_ALEN, 0x77, (ETH_HLEN - 2*ETH_ALEN));
2028 for (i = ETH_HLEN; i < pkt_size; i++)
2029 packet[i] = (unsigned char) (i & 0xff);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002030 mapping = dma_map_single(&bp->pdev->dev, skb->data,
2031 skb_headlen(skb), DMA_TO_DEVICE);
2032 if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
2033 rc = -ENOMEM;
2034 dev_kfree_skb(skb);
Merav Sicron51c1a582012-03-18 10:33:38 +00002035 DP(BNX2X_MSG_ETHTOOL, "Unable to map SKB\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002036 goto test_loopback_exit;
2037 }
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002038
2039 /* send the loopback packet */
2040 num_pkts = 0;
Ariel Elior6383c0b2011-07-14 08:31:57 +00002041 tx_start_idx = le16_to_cpu(*txdata->tx_cons_sb);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002042 rx_start_idx = le16_to_cpu(*fp_rx->rx_cons_sb);
2043
Dmitry Kravkov73dbb5e2011-12-06 02:05:12 +00002044 netdev_tx_sent_queue(txq, skb->len);
2045
Ariel Elior6383c0b2011-07-14 08:31:57 +00002046 pkt_prod = txdata->tx_pkt_prod++;
2047 tx_buf = &txdata->tx_buf_ring[TX_BD(pkt_prod)];
2048 tx_buf->first_bd = txdata->tx_bd_prod;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002049 tx_buf->skb = skb;
2050 tx_buf->flags = 0;
2051
Ariel Elior6383c0b2011-07-14 08:31:57 +00002052 bd_prod = TX_BD(txdata->tx_bd_prod);
2053 tx_start_bd = &txdata->tx_desc_ring[bd_prod].start_bd;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002054 tx_start_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
2055 tx_start_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
2056 tx_start_bd->nbd = cpu_to_le16(2); /* start + pbd */
2057 tx_start_bd->nbytes = cpu_to_le16(skb_headlen(skb));
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002058 tx_start_bd->vlan_or_ethertype = cpu_to_le16(pkt_prod);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002059 tx_start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002060 SET_FLAG(tx_start_bd->general_data,
2061 ETH_TX_START_BD_ETH_ADDR_TYPE,
2062 UNICAST_ADDRESS);
2063 SET_FLAG(tx_start_bd->general_data,
2064 ETH_TX_START_BD_HDR_NBDS,
2065 1);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002066
2067 /* turn on parsing and get a BD */
2068 bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00002069
Ariel Elior6383c0b2011-07-14 08:31:57 +00002070 pbd_e1x = &txdata->tx_desc_ring[bd_prod].parse_bd_e1x;
2071 pbd_e2 = &txdata->tx_desc_ring[bd_prod].parse_bd_e2;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002072
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002073 memset(pbd_e2, 0, sizeof(struct eth_tx_parse_bd_e2));
Dmitry Kravkov523224a2010-10-06 03:23:26 +00002074 memset(pbd_e1x, 0, sizeof(struct eth_tx_parse_bd_e1x));
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002075
2076 wmb();
2077
Ariel Elior6383c0b2011-07-14 08:31:57 +00002078 txdata->tx_db.data.prod += 2;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002079 barrier();
Ariel Elior6383c0b2011-07-14 08:31:57 +00002080 DOORBELL(bp, txdata->cid, txdata->tx_db.raw);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002081
2082 mmiowb();
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002083 barrier();
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002084
2085 num_pkts++;
Ariel Elior6383c0b2011-07-14 08:31:57 +00002086 txdata->tx_bd_prod += 2; /* start + pbd */
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002087
2088 udelay(100);
2089
Ariel Elior6383c0b2011-07-14 08:31:57 +00002090 tx_idx = le16_to_cpu(*txdata->tx_cons_sb);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002091 if (tx_idx != tx_start_idx + num_pkts)
2092 goto test_loopback_exit;
2093
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002094 /* Unlike HC IGU won't generate an interrupt for status block
2095 * updates that have been performed while interrupts were
2096 * disabled.
2097 */
Eric Dumazete1210d12010-11-24 03:45:10 +00002098 if (bp->common.int_block == INT_BLOCK_IGU) {
2099 /* Disable local BHes to prevent a dead-lock situation between
2100 * sch_direct_xmit() and bnx2x_run_loopback() (calling
2101 * bnx2x_tx_int()), as both are taking netif_tx_lock().
2102 */
2103 local_bh_disable();
Ariel Elior6383c0b2011-07-14 08:31:57 +00002104 bnx2x_tx_int(bp, txdata);
Eric Dumazete1210d12010-11-24 03:45:10 +00002105 local_bh_enable();
2106 }
Dmitry Kravkovf2e08992010-10-06 03:28:26 +00002107
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002108 rx_idx = le16_to_cpu(*fp_rx->rx_cons_sb);
2109 if (rx_idx != rx_start_idx + num_pkts)
2110 goto test_loopback_exit;
2111
Dmitry Kravkovb0700b12012-01-23 07:31:53 +00002112 cqe = &fp_rx->rx_comp_ring[RCQ_BD(fp_rx->rx_comp_cons)];
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002113 cqe_fp_flags = cqe->fast_path_cqe.type_error_flags;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002114 cqe_fp_type = cqe_fp_flags & ETH_FAST_PATH_RX_CQE_TYPE;
2115 if (!CQE_TYPE_FAST(cqe_fp_type) || (cqe_fp_flags & ETH_RX_ERROR_FALGS))
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002116 goto test_loopback_rx_exit;
2117
Dmitry Kravkov621b4d62012-02-20 09:59:08 +00002118 len = le16_to_cpu(cqe->fast_path_cqe.pkt_len_or_gro_seg_len);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002119 if (len != pkt_size)
2120 goto test_loopback_rx_exit;
2121
2122 rx_buf = &fp_rx->rx_buf_ring[RX_BD(fp_rx->rx_bd_cons)];
Vladislav Zolotarov9924caf2011-07-19 01:37:42 +00002123 dma_sync_single_for_cpu(&bp->pdev->dev,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002124 dma_unmap_addr(rx_buf, mapping),
2125 fp_rx->rx_buf_size, DMA_FROM_DEVICE);
Eric Dumazete52fcb22011-11-14 06:05:34 +00002126 data = rx_buf->data + NET_SKB_PAD + cqe->fast_path_cqe.placement_offset;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002127 for (i = ETH_HLEN; i < pkt_size; i++)
Eric Dumazete52fcb22011-11-14 06:05:34 +00002128 if (*(data + i) != (unsigned char) (i & 0xff))
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002129 goto test_loopback_rx_exit;
2130
2131 rc = 0;
2132
2133test_loopback_rx_exit:
2134
2135 fp_rx->rx_bd_cons = NEXT_RX_IDX(fp_rx->rx_bd_cons);
2136 fp_rx->rx_bd_prod = NEXT_RX_IDX(fp_rx->rx_bd_prod);
2137 fp_rx->rx_comp_cons = NEXT_RCQ_IDX(fp_rx->rx_comp_cons);
2138 fp_rx->rx_comp_prod = NEXT_RCQ_IDX(fp_rx->rx_comp_prod);
2139
2140 /* Update producers */
2141 bnx2x_update_rx_prod(bp, fp_rx, fp_rx->rx_bd_prod, fp_rx->rx_comp_prod,
2142 fp_rx->rx_sge_prod);
2143
2144test_loopback_exit:
2145 bp->link_params.loopback_mode = LOOPBACK_NONE;
2146
2147 return rc;
2148}
2149
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002150static int bnx2x_test_loopback(struct bnx2x *bp)
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002151{
2152 int rc = 0, res;
2153
2154 if (BP_NOMCP(bp))
2155 return rc;
2156
2157 if (!netif_running(bp->dev))
2158 return BNX2X_LOOPBACK_FAILED;
2159
2160 bnx2x_netif_stop(bp, 1);
2161 bnx2x_acquire_phy_lock(bp);
2162
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002163 res = bnx2x_run_loopback(bp, BNX2X_PHY_LOOPBACK);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002164 if (res) {
Merav Sicron51c1a582012-03-18 10:33:38 +00002165 DP(BNX2X_MSG_ETHTOOL, " PHY loopback failed (res %d)\n", res);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002166 rc |= BNX2X_PHY_LOOPBACK_FAILED;
2167 }
2168
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002169 res = bnx2x_run_loopback(bp, BNX2X_MAC_LOOPBACK);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002170 if (res) {
Merav Sicron51c1a582012-03-18 10:33:38 +00002171 DP(BNX2X_MSG_ETHTOOL, " MAC loopback failed (res %d)\n", res);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002172 rc |= BNX2X_MAC_LOOPBACK_FAILED;
2173 }
2174
2175 bnx2x_release_phy_lock(bp);
2176 bnx2x_netif_start(bp);
2177
2178 return rc;
2179}
2180
Merav Sicron8970b2e2012-06-19 07:48:22 +00002181static int bnx2x_test_ext_loopback(struct bnx2x *bp)
2182{
2183 int rc;
2184 u8 is_serdes =
2185 (bp->link_vars.link_status & LINK_STATUS_SERDES_LINK) > 0;
2186
2187 if (BP_NOMCP(bp))
2188 return -ENODEV;
2189
2190 if (!netif_running(bp->dev))
2191 return BNX2X_EXT_LOOPBACK_FAILED;
2192
2193 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
2194 rc = bnx2x_nic_load(bp, LOAD_LOOPBACK_EXT);
2195 if (rc) {
2196 DP(BNX2X_MSG_ETHTOOL,
2197 "Can't perform self-test, nic_load (for external lb) failed\n");
2198 return -ENODEV;
2199 }
2200 bnx2x_wait_for_link(bp, 1, is_serdes);
2201
2202 bnx2x_netif_stop(bp, 1);
2203
2204 rc = bnx2x_run_loopback(bp, BNX2X_EXT_LOOPBACK);
2205 if (rc)
2206 DP(BNX2X_MSG_ETHTOOL, "EXT loopback failed (res %d)\n", rc);
2207
2208 bnx2x_netif_start(bp);
2209
2210 return rc;
2211}
2212
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002213#define CRC32_RESIDUAL 0xdebb20e3
2214
2215static int bnx2x_test_nvram(struct bnx2x *bp)
2216{
2217 static const struct {
2218 int offset;
2219 int size;
2220 } nvram_tbl[] = {
2221 { 0, 0x14 }, /* bootstrap */
2222 { 0x14, 0xec }, /* dir */
2223 { 0x100, 0x350 }, /* manuf_info */
2224 { 0x450, 0xf0 }, /* feature_info */
2225 { 0x640, 0x64 }, /* upgrade_key_info */
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002226 { 0x708, 0x70 }, /* manuf_key_info */
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002227 { 0, 0 }
2228 };
Mintz Yuvalafa13b42012-02-15 02:10:27 +00002229 __be32 *buf;
2230 u8 *data;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002231 int i, rc;
2232 u32 magic, crc;
2233
2234 if (BP_NOMCP(bp))
2235 return 0;
2236
Mintz Yuvalafa13b42012-02-15 02:10:27 +00002237 buf = kmalloc(0x350, GFP_KERNEL);
2238 if (!buf) {
Merav Sicron51c1a582012-03-18 10:33:38 +00002239 DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM, "kmalloc failed\n");
Mintz Yuvalafa13b42012-02-15 02:10:27 +00002240 rc = -ENOMEM;
2241 goto test_nvram_exit;
2242 }
2243 data = (u8 *)buf;
2244
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002245 rc = bnx2x_nvram_read(bp, 0, data, 4);
2246 if (rc) {
Merav Sicron51c1a582012-03-18 10:33:38 +00002247 DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
2248 "magic value read (rc %d)\n", rc);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002249 goto test_nvram_exit;
2250 }
2251
2252 magic = be32_to_cpu(buf[0]);
2253 if (magic != 0x669955aa) {
Merav Sicron51c1a582012-03-18 10:33:38 +00002254 DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
2255 "wrong magic value (0x%08x)\n", magic);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002256 rc = -ENODEV;
2257 goto test_nvram_exit;
2258 }
2259
2260 for (i = 0; nvram_tbl[i].size; i++) {
2261
2262 rc = bnx2x_nvram_read(bp, nvram_tbl[i].offset, data,
2263 nvram_tbl[i].size);
2264 if (rc) {
Merav Sicron51c1a582012-03-18 10:33:38 +00002265 DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002266 "nvram_tbl[%d] read data (rc %d)\n", i, rc);
2267 goto test_nvram_exit;
2268 }
2269
2270 crc = ether_crc_le(nvram_tbl[i].size, data);
2271 if (crc != CRC32_RESIDUAL) {
Merav Sicron51c1a582012-03-18 10:33:38 +00002272 DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
2273 "nvram_tbl[%d] wrong crc value (0x%08x)\n", i, crc);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002274 rc = -ENODEV;
2275 goto test_nvram_exit;
2276 }
2277 }
2278
2279test_nvram_exit:
Mintz Yuvalafa13b42012-02-15 02:10:27 +00002280 kfree(buf);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002281 return rc;
2282}
2283
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002284/* Send an EMPTY ramrod on the first queue */
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002285static int bnx2x_test_intr(struct bnx2x *bp)
2286{
Yuval Mintz3b603062012-03-18 10:33:39 +00002287 struct bnx2x_queue_state_params params = {NULL};
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002288
Merav Sicron51c1a582012-03-18 10:33:38 +00002289 if (!netif_running(bp->dev)) {
2290 DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
2291 "cannot access eeprom when the interface is down\n");
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002292 return -ENODEV;
Merav Sicron51c1a582012-03-18 10:33:38 +00002293 }
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002294
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002295 params.q_obj = &bp->fp->q_obj;
2296 params.cmd = BNX2X_Q_CMD_EMPTY;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002297
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002298 __set_bit(RAMROD_COMP_WAIT, &params.ramrod_flags);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002299
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002300 return bnx2x_queue_state_change(bp, &params);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002301}
2302
2303static void bnx2x_self_test(struct net_device *dev,
2304 struct ethtool_test *etest, u64 *buf)
2305{
2306 struct bnx2x *bp = netdev_priv(dev);
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002307 u8 is_serdes;
Merav Sicroncf2c1df62012-06-19 07:48:23 +00002308 int rc;
2309
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002310 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
Merav Sicron51c1a582012-03-18 10:33:38 +00002311 netdev_err(bp->dev,
2312 "Handling parity error recovery. Try again later\n");
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002313 etest->flags |= ETH_TEST_FL_FAILED;
2314 return;
2315 }
Merav Sicron8970b2e2012-06-19 07:48:22 +00002316 DP(BNX2X_MSG_ETHTOOL,
2317 "Self-test command parameters: offline = %d, external_lb = %d\n",
2318 (etest->flags & ETH_TEST_FL_OFFLINE),
2319 (etest->flags & ETH_TEST_FL_EXTERNAL_LB)>>2);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002320
Merav Sicroncf2c1df62012-06-19 07:48:23 +00002321 memset(buf, 0, sizeof(u64) * BNX2X_NUM_TESTS(bp));
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002322
Merav Sicroncf2c1df62012-06-19 07:48:23 +00002323 if (!netif_running(dev)) {
2324 DP(BNX2X_MSG_ETHTOOL,
2325 "Can't perform self-test when interface is down\n");
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002326 return;
Merav Sicroncf2c1df62012-06-19 07:48:23 +00002327 }
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002328
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002329 is_serdes = (bp->link_vars.link_status & LINK_STATUS_SERDES_LINK) > 0;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002330
Merav Sicroncf2c1df62012-06-19 07:48:23 +00002331 /* offline tests are not supported in MF mode */
2332 if ((etest->flags & ETH_TEST_FL_OFFLINE) && !IS_MF(bp)) {
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002333 int port = BP_PORT(bp);
2334 u32 val;
2335 u8 link_up;
2336
2337 /* save current value of input enable for TX port IF */
2338 val = REG_RD(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4);
2339 /* disable input for TX port IF */
2340 REG_WR(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4, 0);
2341
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002342 link_up = bp->link_vars.link_up;
2343
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002344 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
Merav Sicroncf2c1df62012-06-19 07:48:23 +00002345 rc = bnx2x_nic_load(bp, LOAD_DIAG);
2346 if (rc) {
2347 etest->flags |= ETH_TEST_FL_FAILED;
2348 DP(BNX2X_MSG_ETHTOOL,
2349 "Can't perform self-test, nic_load (for offline) failed\n");
2350 return;
2351 }
2352
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002353 /* wait until link state is restored */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002354 bnx2x_wait_for_link(bp, 1, is_serdes);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002355
2356 if (bnx2x_test_registers(bp) != 0) {
2357 buf[0] = 1;
2358 etest->flags |= ETH_TEST_FL_FAILED;
2359 }
2360 if (bnx2x_test_memory(bp) != 0) {
2361 buf[1] = 1;
2362 etest->flags |= ETH_TEST_FL_FAILED;
2363 }
Dmitry Kravkovf85582f2010-10-06 03:34:21 +00002364
Merav Sicron8970b2e2012-06-19 07:48:22 +00002365 buf[2] = bnx2x_test_loopback(bp); /* internal LB */
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002366 if (buf[2] != 0)
2367 etest->flags |= ETH_TEST_FL_FAILED;
2368
Merav Sicron8970b2e2012-06-19 07:48:22 +00002369 if (etest->flags & ETH_TEST_FL_EXTERNAL_LB) {
2370 buf[3] = bnx2x_test_ext_loopback(bp); /* external LB */
2371 if (buf[3] != 0)
2372 etest->flags |= ETH_TEST_FL_FAILED;
2373 etest->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE;
2374 }
2375
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002376 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
2377
2378 /* restore input for TX port IF */
2379 REG_WR(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4, val);
Merav Sicroncf2c1df62012-06-19 07:48:23 +00002380 rc = bnx2x_nic_load(bp, LOAD_NORMAL);
2381 if (rc) {
2382 etest->flags |= ETH_TEST_FL_FAILED;
2383 DP(BNX2X_MSG_ETHTOOL,
2384 "Can't perform self-test, nic_load (for online) failed\n");
2385 return;
2386 }
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002387 /* wait until link state is restored */
Yaniv Rosnera22f0782010-09-07 11:41:20 +00002388 bnx2x_wait_for_link(bp, link_up, is_serdes);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002389 }
2390 if (bnx2x_test_nvram(bp) != 0) {
Merav Sicroncf2c1df62012-06-19 07:48:23 +00002391 if (!IS_MF(bp))
2392 buf[4] = 1;
2393 else
2394 buf[0] = 1;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002395 etest->flags |= ETH_TEST_FL_FAILED;
2396 }
2397 if (bnx2x_test_intr(bp) != 0) {
Merav Sicroncf2c1df62012-06-19 07:48:23 +00002398 if (!IS_MF(bp))
2399 buf[5] = 1;
2400 else
2401 buf[1] = 1;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002402 etest->flags |= ETH_TEST_FL_FAILED;
2403 }
Dmitry Kravkov633ac362011-02-28 03:37:12 +00002404
2405 if (bnx2x_link_test(bp, is_serdes) != 0) {
Merav Sicroncf2c1df62012-06-19 07:48:23 +00002406 if (!IS_MF(bp))
2407 buf[6] = 1;
2408 else
2409 buf[2] = 1;
Dmitry Kravkov633ac362011-02-28 03:37:12 +00002410 etest->flags |= ETH_TEST_FL_FAILED;
2411 }
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002412
2413#ifdef BNX2X_EXTRA_DEBUG
2414 bnx2x_panic_dump(bp);
2415#endif
2416}
2417
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002418#define IS_PORT_STAT(i) \
2419 ((bnx2x_stats_arr[i].flags & STATS_FLAGS_BOTH) == STATS_FLAGS_PORT)
2420#define IS_FUNC_STAT(i) (bnx2x_stats_arr[i].flags & STATS_FLAGS_FUNC)
Dmitry Kravkovfb3bff12010-10-06 03:26:40 +00002421#define IS_MF_MODE_STAT(bp) \
2422 (IS_MF(bp) && !(bp->msg_enable & BNX2X_MSG_STATS))
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002423
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002424/* ethtool statistics are displayed for all regular ethernet queues and the
2425 * fcoe L2 queue if not disabled
2426 */
Eric Dumazet1191cb82012-04-27 21:39:21 +00002427static int bnx2x_num_stat_queues(struct bnx2x *bp)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002428{
2429 return BNX2X_NUM_ETH_QUEUES(bp);
2430}
2431
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002432static int bnx2x_get_sset_count(struct net_device *dev, int stringset)
2433{
2434 struct bnx2x *bp = netdev_priv(dev);
2435 int i, num_stats;
2436
2437 switch (stringset) {
2438 case ETH_SS_STATS:
2439 if (is_multi(bp)) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002440 num_stats = bnx2x_num_stat_queues(bp) *
Yuval Mintzd5e83632012-01-23 07:31:52 +00002441 BNX2X_NUM_Q_STATS;
2442 } else
2443 num_stats = 0;
2444 if (IS_MF_MODE_STAT(bp)) {
2445 for (i = 0; i < BNX2X_NUM_STATS; i++)
2446 if (IS_FUNC_STAT(i))
2447 num_stats++;
2448 } else
2449 num_stats += BNX2X_NUM_STATS;
2450
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002451 return num_stats;
2452
2453 case ETH_SS_TEST:
Merav Sicroncf2c1df62012-06-19 07:48:23 +00002454 return BNX2X_NUM_TESTS(bp);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002455
2456 default:
2457 return -EINVAL;
2458 }
2459}
2460
2461static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
2462{
2463 struct bnx2x *bp = netdev_priv(dev);
Merav Sicroncf2c1df62012-06-19 07:48:23 +00002464 int i, j, k, offset, start;
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00002465 char queue_name[MAX_QUEUE_NAME_LEN+1];
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002466
2467 switch (stringset) {
2468 case ETH_SS_STATS:
Yuval Mintzd5e83632012-01-23 07:31:52 +00002469 k = 0;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002470 if (is_multi(bp)) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002471 for_each_eth_queue(bp, i) {
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00002472 memset(queue_name, 0, sizeof(queue_name));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002473 sprintf(queue_name, "%d", i);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002474 for (j = 0; j < BNX2X_NUM_Q_STATS; j++)
Vladislav Zolotarovec6ba942010-12-13 05:44:01 +00002475 snprintf(buf + (k + j)*ETH_GSTRING_LEN,
2476 ETH_GSTRING_LEN,
2477 bnx2x_q_stats_arr[j].string,
2478 queue_name);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002479 k += BNX2X_NUM_Q_STATS;
2480 }
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002481 }
Yuval Mintzd5e83632012-01-23 07:31:52 +00002482
2483
2484 for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
2485 if (IS_MF_MODE_STAT(bp) && IS_PORT_STAT(i))
2486 continue;
2487 strcpy(buf + (k + j)*ETH_GSTRING_LEN,
2488 bnx2x_stats_arr[i].string);
2489 j++;
2490 }
2491
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002492 break;
2493
2494 case ETH_SS_TEST:
Merav Sicroncf2c1df62012-06-19 07:48:23 +00002495 /* First 4 tests cannot be done in MF mode */
2496 if (!IS_MF(bp))
2497 start = 0;
2498 else
2499 start = 4;
2500 for (i = 0, j = start; j < (start + BNX2X_NUM_TESTS(bp));
2501 i++, j++) {
2502 offset = sprintf(buf+32*i, "%s",
2503 bnx2x_tests_str_arr[j]);
2504 *(buf+offset) = '\0';
2505 }
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002506 break;
2507 }
2508}
2509
2510static void bnx2x_get_ethtool_stats(struct net_device *dev,
2511 struct ethtool_stats *stats, u64 *buf)
2512{
2513 struct bnx2x *bp = netdev_priv(dev);
2514 u32 *hw_stats, *offset;
Yuval Mintzd5e83632012-01-23 07:31:52 +00002515 int i, j, k = 0;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002516
2517 if (is_multi(bp)) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002518 for_each_eth_queue(bp, i) {
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002519 hw_stats = (u32 *)&bp->fp[i].eth_q_stats;
2520 for (j = 0; j < BNX2X_NUM_Q_STATS; j++) {
2521 if (bnx2x_q_stats_arr[j].size == 0) {
2522 /* skip this counter */
2523 buf[k + j] = 0;
2524 continue;
2525 }
2526 offset = (hw_stats +
2527 bnx2x_q_stats_arr[j].offset);
2528 if (bnx2x_q_stats_arr[j].size == 4) {
2529 /* 4-byte counter */
2530 buf[k + j] = (u64) *offset;
2531 continue;
2532 }
2533 /* 8-byte counter */
2534 buf[k + j] = HILO_U64(*offset, *(offset + 1));
2535 }
2536 k += BNX2X_NUM_Q_STATS;
2537 }
Yuval Mintzd5e83632012-01-23 07:31:52 +00002538 }
2539
2540 hw_stats = (u32 *)&bp->eth_stats;
2541 for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
2542 if (IS_MF_MODE_STAT(bp) && IS_PORT_STAT(i))
2543 continue;
2544 if (bnx2x_stats_arr[i].size == 0) {
2545 /* skip this counter */
2546 buf[k + j] = 0;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002547 j++;
Yuval Mintzd5e83632012-01-23 07:31:52 +00002548 continue;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002549 }
Yuval Mintzd5e83632012-01-23 07:31:52 +00002550 offset = (hw_stats + bnx2x_stats_arr[i].offset);
2551 if (bnx2x_stats_arr[i].size == 4) {
2552 /* 4-byte counter */
2553 buf[k + j] = (u64) *offset;
2554 j++;
2555 continue;
2556 }
2557 /* 8-byte counter */
2558 buf[k + j] = HILO_U64(*offset, *(offset + 1));
2559 j++;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002560 }
2561}
2562
stephen hemminger32d36132011-04-04 11:06:37 +00002563static int bnx2x_set_phys_id(struct net_device *dev,
2564 enum ethtool_phys_id_state state)
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002565{
2566 struct bnx2x *bp = netdev_priv(dev);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002567
Merav Sicron51c1a582012-03-18 10:33:38 +00002568 if (!netif_running(dev)) {
2569 DP(BNX2X_MSG_ETHTOOL | BNX2X_MSG_NVM,
2570 "cannot access eeprom when the interface is down\n");
stephen hemminger32d36132011-04-04 11:06:37 +00002571 return -EAGAIN;
Merav Sicron51c1a582012-03-18 10:33:38 +00002572 }
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002573
Merav Sicron51c1a582012-03-18 10:33:38 +00002574 if (!bp->port.pmf) {
2575 DP(BNX2X_MSG_ETHTOOL, "Interface is not pmf\n");
stephen hemminger32d36132011-04-04 11:06:37 +00002576 return -EOPNOTSUPP;
Merav Sicron51c1a582012-03-18 10:33:38 +00002577 }
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002578
stephen hemminger32d36132011-04-04 11:06:37 +00002579 switch (state) {
2580 case ETHTOOL_ID_ACTIVE:
Allan, Bruce Wfce55922011-04-13 13:09:10 +00002581 return 1; /* cycle on/off once per second */
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002582
stephen hemminger32d36132011-04-04 11:06:37 +00002583 case ETHTOOL_ID_ON:
2584 bnx2x_set_led(&bp->link_params, &bp->link_vars,
David S. Millere1943422011-04-19 00:21:33 -07002585 LED_MODE_ON, SPEED_1000);
stephen hemminger32d36132011-04-04 11:06:37 +00002586 break;
2587
2588 case ETHTOOL_ID_OFF:
2589 bnx2x_set_led(&bp->link_params, &bp->link_vars,
David S. Millere1943422011-04-19 00:21:33 -07002590 LED_MODE_FRONT_PANEL_OFF, 0);
stephen hemminger32d36132011-04-04 11:06:37 +00002591
2592 break;
2593
2594 case ETHTOOL_ID_INACTIVE:
David S. Millere1943422011-04-19 00:21:33 -07002595 bnx2x_set_led(&bp->link_params, &bp->link_vars,
2596 LED_MODE_OPER,
2597 bp->link_vars.line_speed);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002598 }
2599
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002600 return 0;
2601}
2602
Tom Herbertab532cf2011-02-16 10:27:02 +00002603static int bnx2x_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
Ben Hutchings815c7db2011-09-06 13:49:12 +00002604 u32 *rules __always_unused)
Tom Herbertab532cf2011-02-16 10:27:02 +00002605{
2606 struct bnx2x *bp = netdev_priv(dev);
2607
2608 switch (info->cmd) {
2609 case ETHTOOL_GRXRINGS:
2610 info->data = BNX2X_NUM_ETH_QUEUES(bp);
2611 return 0;
2612
2613 default:
Merav Sicron51c1a582012-03-18 10:33:38 +00002614 DP(BNX2X_MSG_ETHTOOL, "Command parameters not supported\n");
Tom Herbertab532cf2011-02-16 10:27:02 +00002615 return -EOPNOTSUPP;
2616 }
2617}
2618
Ben Hutchings7850f632011-12-15 13:55:01 +00002619static u32 bnx2x_get_rxfh_indir_size(struct net_device *dev)
Tom Herbertab532cf2011-02-16 10:27:02 +00002620{
Dmitry Kravkov96305232012-04-03 18:41:30 +00002621 return T_ETH_INDIRECTION_TABLE_SIZE;
Ben Hutchings7850f632011-12-15 13:55:01 +00002622}
2623
2624static int bnx2x_get_rxfh_indir(struct net_device *dev, u32 *indir)
2625{
2626 struct bnx2x *bp = netdev_priv(dev);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002627 u8 ind_table[T_ETH_INDIRECTION_TABLE_SIZE] = {0};
2628 size_t i;
Tom Herbertab532cf2011-02-16 10:27:02 +00002629
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002630 /* Get the current configuration of the RSS indirection table */
2631 bnx2x_get_rss_ind_table(&bp->rss_conf_obj, ind_table);
2632
2633 /*
2634 * We can't use a memcpy() as an internal storage of an
2635 * indirection table is a u8 array while indir->ring_index
2636 * points to an array of u32.
2637 *
2638 * Indirection table contains the FW Client IDs, so we need to
2639 * align the returned table to the Client ID of the leading RSS
2640 * queue.
2641 */
Ben Hutchings7850f632011-12-15 13:55:01 +00002642 for (i = 0; i < T_ETH_INDIRECTION_TABLE_SIZE; i++)
2643 indir[i] = ind_table[i] - bp->fp->cl_id;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002644
Tom Herbertab532cf2011-02-16 10:27:02 +00002645 return 0;
2646}
2647
Ben Hutchings7850f632011-12-15 13:55:01 +00002648static int bnx2x_set_rxfh_indir(struct net_device *dev, const u32 *indir)
Tom Herbertab532cf2011-02-16 10:27:02 +00002649{
2650 struct bnx2x *bp = netdev_priv(dev);
2651 size_t i;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002652 u8 ind_table[T_ETH_INDIRECTION_TABLE_SIZE] = {0};
Tom Herbertab532cf2011-02-16 10:27:02 +00002653
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002654 for (i = 0; i < T_ETH_INDIRECTION_TABLE_SIZE; i++) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002655 /*
2656 * The same as in bnx2x_get_rxfh_indir: we can't use a memcpy()
2657 * as an internal storage of an indirection table is a u8 array
2658 * while indir->ring_index points to an array of u32.
2659 *
2660 * Indirection table contains the FW Client IDs, so we need to
2661 * align the received table to the Client ID of the leading RSS
2662 * queue
2663 */
Ben Hutchings7850f632011-12-15 13:55:01 +00002664 ind_table[i] = indir[i] + bp->fp->cl_id;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002665 }
2666
Dmitry Kravkov96305232012-04-03 18:41:30 +00002667 return bnx2x_config_rss_eth(bp, ind_table, false);
Tom Herbertab532cf2011-02-16 10:27:02 +00002668}
2669
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002670static const struct ethtool_ops bnx2x_ethtool_ops = {
2671 .get_settings = bnx2x_get_settings,
2672 .set_settings = bnx2x_set_settings,
2673 .get_drvinfo = bnx2x_get_drvinfo,
2674 .get_regs_len = bnx2x_get_regs_len,
2675 .get_regs = bnx2x_get_regs,
2676 .get_wol = bnx2x_get_wol,
2677 .set_wol = bnx2x_set_wol,
2678 .get_msglevel = bnx2x_get_msglevel,
2679 .set_msglevel = bnx2x_set_msglevel,
2680 .nway_reset = bnx2x_nway_reset,
2681 .get_link = bnx2x_get_link,
2682 .get_eeprom_len = bnx2x_get_eeprom_len,
2683 .get_eeprom = bnx2x_get_eeprom,
2684 .set_eeprom = bnx2x_set_eeprom,
2685 .get_coalesce = bnx2x_get_coalesce,
2686 .set_coalesce = bnx2x_set_coalesce,
2687 .get_ringparam = bnx2x_get_ringparam,
2688 .set_ringparam = bnx2x_set_ringparam,
2689 .get_pauseparam = bnx2x_get_pauseparam,
2690 .set_pauseparam = bnx2x_set_pauseparam,
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002691 .self_test = bnx2x_self_test,
2692 .get_sset_count = bnx2x_get_sset_count,
2693 .get_strings = bnx2x_get_strings,
stephen hemminger32d36132011-04-04 11:06:37 +00002694 .set_phys_id = bnx2x_set_phys_id,
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002695 .get_ethtool_stats = bnx2x_get_ethtool_stats,
Tom Herbertab532cf2011-02-16 10:27:02 +00002696 .get_rxnfc = bnx2x_get_rxnfc,
Ben Hutchings7850f632011-12-15 13:55:01 +00002697 .get_rxfh_indir_size = bnx2x_get_rxfh_indir_size,
Tom Herbertab532cf2011-02-16 10:27:02 +00002698 .get_rxfh_indir = bnx2x_get_rxfh_indir,
2699 .set_rxfh_indir = bnx2x_set_rxfh_indir,
Yuval Mintze9939c82012-06-06 17:13:08 +00002700 .get_eee = bnx2x_get_eee,
2701 .set_eee = bnx2x_set_eee,
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00002702};
2703
2704void bnx2x_set_ethtool_ops(struct net_device *netdev)
2705{
2706 SET_ETHTOOL_OPS(netdev, &bnx2x_ethtool_ops);
2707}