1 /* bnx2x_ethtool.c: Broadcom Everest network driver.
3 * Copyright (c) 2007-2011 Broadcom Corporation
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.
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
18 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20 #include <linux/ethtool.h>
21 #include <linux/netdevice.h>
22 #include <linux/types.h>
23 #include <linux/sched.h>
24 #include <linux/crc32.h>
28 #include "bnx2x_cmn.h"
29 #include "bnx2x_dump.h"
30 #include "bnx2x_init.h"
33 /* Note: in the format strings below %s is replaced by the queue-name which is
34 * either its index or 'fcoe' for the fcoe queue. Make sure the format string
35 * length does not exceed ETH_GSTRING_LEN - MAX_QUEUE_NAME_LEN + 2
37 #define MAX_QUEUE_NAME_LEN 4
41 char string
[ETH_GSTRING_LEN
];
42 } bnx2x_q_stats_arr
[] = {
43 /* 1 */ { Q_STATS_OFFSET32(total_bytes_received_hi
), 8, "[%s]: rx_bytes" },
44 { Q_STATS_OFFSET32(total_unicast_packets_received_hi
),
45 8, "[%s]: rx_ucast_packets" },
46 { Q_STATS_OFFSET32(total_multicast_packets_received_hi
),
47 8, "[%s]: rx_mcast_packets" },
48 { Q_STATS_OFFSET32(total_broadcast_packets_received_hi
),
49 8, "[%s]: rx_bcast_packets" },
50 { Q_STATS_OFFSET32(no_buff_discard_hi
), 8, "[%s]: rx_discards" },
51 { Q_STATS_OFFSET32(rx_err_discard_pkt
),
52 4, "[%s]: rx_phy_ip_err_discards"},
53 { Q_STATS_OFFSET32(rx_skb_alloc_failed
),
54 4, "[%s]: rx_skb_alloc_discard" },
55 { Q_STATS_OFFSET32(hw_csum_err
), 4, "[%s]: rx_csum_offload_errors" },
57 { Q_STATS_OFFSET32(total_bytes_transmitted_hi
), 8, "[%s]: tx_bytes" },
58 /* 10 */{ Q_STATS_OFFSET32(total_unicast_packets_transmitted_hi
),
59 8, "[%s]: tx_ucast_packets" },
60 { Q_STATS_OFFSET32(total_multicast_packets_transmitted_hi
),
61 8, "[%s]: tx_mcast_packets" },
62 { Q_STATS_OFFSET32(total_broadcast_packets_transmitted_hi
),
63 8, "[%s]: tx_bcast_packets" },
64 { Q_STATS_OFFSET32(total_tpa_aggregations_hi
),
65 8, "[%s]: tpa_aggregations" },
66 { Q_STATS_OFFSET32(total_tpa_aggregated_frames_hi
),
67 8, "[%s]: tpa_aggregated_frames"},
68 { Q_STATS_OFFSET32(total_tpa_bytes_hi
), 8, "[%s]: tpa_bytes"}
71 #define BNX2X_NUM_Q_STATS ARRAY_SIZE(bnx2x_q_stats_arr)
77 #define STATS_FLAGS_PORT 1
78 #define STATS_FLAGS_FUNC 2
79 #define STATS_FLAGS_BOTH (STATS_FLAGS_FUNC | STATS_FLAGS_PORT)
80 char string
[ETH_GSTRING_LEN
];
81 } bnx2x_stats_arr
[] = {
82 /* 1 */ { STATS_OFFSET32(total_bytes_received_hi
),
83 8, STATS_FLAGS_BOTH
, "rx_bytes" },
84 { STATS_OFFSET32(error_bytes_received_hi
),
85 8, STATS_FLAGS_BOTH
, "rx_error_bytes" },
86 { STATS_OFFSET32(total_unicast_packets_received_hi
),
87 8, STATS_FLAGS_BOTH
, "rx_ucast_packets" },
88 { STATS_OFFSET32(total_multicast_packets_received_hi
),
89 8, STATS_FLAGS_BOTH
, "rx_mcast_packets" },
90 { STATS_OFFSET32(total_broadcast_packets_received_hi
),
91 8, STATS_FLAGS_BOTH
, "rx_bcast_packets" },
92 { STATS_OFFSET32(rx_stat_dot3statsfcserrors_hi
),
93 8, STATS_FLAGS_PORT
, "rx_crc_errors" },
94 { STATS_OFFSET32(rx_stat_dot3statsalignmenterrors_hi
),
95 8, STATS_FLAGS_PORT
, "rx_align_errors" },
96 { STATS_OFFSET32(rx_stat_etherstatsundersizepkts_hi
),
97 8, STATS_FLAGS_PORT
, "rx_undersize_packets" },
98 { STATS_OFFSET32(etherstatsoverrsizepkts_hi
),
99 8, STATS_FLAGS_PORT
, "rx_oversize_packets" },
100 /* 10 */{ STATS_OFFSET32(rx_stat_etherstatsfragments_hi
),
101 8, STATS_FLAGS_PORT
, "rx_fragments" },
102 { STATS_OFFSET32(rx_stat_etherstatsjabbers_hi
),
103 8, STATS_FLAGS_PORT
, "rx_jabbers" },
104 { STATS_OFFSET32(no_buff_discard_hi
),
105 8, STATS_FLAGS_BOTH
, "rx_discards" },
106 { STATS_OFFSET32(mac_filter_discard
),
107 4, STATS_FLAGS_PORT
, "rx_filtered_packets" },
108 { STATS_OFFSET32(mf_tag_discard
),
109 4, STATS_FLAGS_PORT
, "rx_mf_tag_discard" },
110 { STATS_OFFSET32(pfc_frames_received_hi
),
111 8, STATS_FLAGS_PORT
, "pfc_frames_received" },
112 { STATS_OFFSET32(pfc_frames_sent_hi
),
113 8, STATS_FLAGS_PORT
, "pfc_frames_sent" },
114 { STATS_OFFSET32(brb_drop_hi
),
115 8, STATS_FLAGS_PORT
, "rx_brb_discard" },
116 { STATS_OFFSET32(brb_truncate_hi
),
117 8, STATS_FLAGS_PORT
, "rx_brb_truncate" },
118 { STATS_OFFSET32(pause_frames_received_hi
),
119 8, STATS_FLAGS_PORT
, "rx_pause_frames" },
120 { STATS_OFFSET32(rx_stat_maccontrolframesreceived_hi
),
121 8, STATS_FLAGS_PORT
, "rx_mac_ctrl_frames" },
122 { STATS_OFFSET32(nig_timer_max
),
123 4, STATS_FLAGS_PORT
, "rx_constant_pause_events" },
124 /* 20 */{ STATS_OFFSET32(rx_err_discard_pkt
),
125 4, STATS_FLAGS_BOTH
, "rx_phy_ip_err_discards"},
126 { STATS_OFFSET32(rx_skb_alloc_failed
),
127 4, STATS_FLAGS_BOTH
, "rx_skb_alloc_discard" },
128 { STATS_OFFSET32(hw_csum_err
),
129 4, STATS_FLAGS_BOTH
, "rx_csum_offload_errors" },
131 { STATS_OFFSET32(total_bytes_transmitted_hi
),
132 8, STATS_FLAGS_BOTH
, "tx_bytes" },
133 { STATS_OFFSET32(tx_stat_ifhcoutbadoctets_hi
),
134 8, STATS_FLAGS_PORT
, "tx_error_bytes" },
135 { STATS_OFFSET32(total_unicast_packets_transmitted_hi
),
136 8, STATS_FLAGS_BOTH
, "tx_ucast_packets" },
137 { STATS_OFFSET32(total_multicast_packets_transmitted_hi
),
138 8, STATS_FLAGS_BOTH
, "tx_mcast_packets" },
139 { STATS_OFFSET32(total_broadcast_packets_transmitted_hi
),
140 8, STATS_FLAGS_BOTH
, "tx_bcast_packets" },
141 { STATS_OFFSET32(tx_stat_dot3statsinternalmactransmiterrors_hi
),
142 8, STATS_FLAGS_PORT
, "tx_mac_errors" },
143 { STATS_OFFSET32(rx_stat_dot3statscarriersenseerrors_hi
),
144 8, STATS_FLAGS_PORT
, "tx_carrier_errors" },
145 /* 30 */{ STATS_OFFSET32(tx_stat_dot3statssinglecollisionframes_hi
),
146 8, STATS_FLAGS_PORT
, "tx_single_collisions" },
147 { STATS_OFFSET32(tx_stat_dot3statsmultiplecollisionframes_hi
),
148 8, STATS_FLAGS_PORT
, "tx_multi_collisions" },
149 { STATS_OFFSET32(tx_stat_dot3statsdeferredtransmissions_hi
),
150 8, STATS_FLAGS_PORT
, "tx_deferred" },
151 { STATS_OFFSET32(tx_stat_dot3statsexcessivecollisions_hi
),
152 8, STATS_FLAGS_PORT
, "tx_excess_collisions" },
153 { STATS_OFFSET32(tx_stat_dot3statslatecollisions_hi
),
154 8, STATS_FLAGS_PORT
, "tx_late_collisions" },
155 { STATS_OFFSET32(tx_stat_etherstatscollisions_hi
),
156 8, STATS_FLAGS_PORT
, "tx_total_collisions" },
157 { STATS_OFFSET32(tx_stat_etherstatspkts64octets_hi
),
158 8, STATS_FLAGS_PORT
, "tx_64_byte_packets" },
159 { STATS_OFFSET32(tx_stat_etherstatspkts65octetsto127octets_hi
),
160 8, STATS_FLAGS_PORT
, "tx_65_to_127_byte_packets" },
161 { STATS_OFFSET32(tx_stat_etherstatspkts128octetsto255octets_hi
),
162 8, STATS_FLAGS_PORT
, "tx_128_to_255_byte_packets" },
163 { STATS_OFFSET32(tx_stat_etherstatspkts256octetsto511octets_hi
),
164 8, STATS_FLAGS_PORT
, "tx_256_to_511_byte_packets" },
165 /* 40 */{ STATS_OFFSET32(tx_stat_etherstatspkts512octetsto1023octets_hi
),
166 8, STATS_FLAGS_PORT
, "tx_512_to_1023_byte_packets" },
167 { STATS_OFFSET32(etherstatspkts1024octetsto1522octets_hi
),
168 8, STATS_FLAGS_PORT
, "tx_1024_to_1522_byte_packets" },
169 { STATS_OFFSET32(etherstatspktsover1522octets_hi
),
170 8, STATS_FLAGS_PORT
, "tx_1523_to_9022_byte_packets" },
171 { STATS_OFFSET32(pause_frames_sent_hi
),
172 8, STATS_FLAGS_PORT
, "tx_pause_frames" },
173 { STATS_OFFSET32(total_tpa_aggregations_hi
),
174 8, STATS_FLAGS_FUNC
, "tpa_aggregations" },
175 { STATS_OFFSET32(total_tpa_aggregated_frames_hi
),
176 8, STATS_FLAGS_FUNC
, "tpa_aggregated_frames"},
177 { STATS_OFFSET32(total_tpa_bytes_hi
),
178 8, STATS_FLAGS_FUNC
, "tpa_bytes"}
181 #define BNX2X_NUM_STATS ARRAY_SIZE(bnx2x_stats_arr)
182 static int bnx2x_get_port_type(struct bnx2x
*bp
)
185 u32 phy_idx
= bnx2x_get_cur_phy_idx(bp
);
186 switch (bp
->link_params
.phy
[phy_idx
].media_type
) {
187 case ETH_PHY_SFP_FIBER
:
188 case ETH_PHY_XFP_FIBER
:
191 port_type
= PORT_FIBRE
;
193 case ETH_PHY_DA_TWINAX
:
199 case ETH_PHY_NOT_PRESENT
:
200 port_type
= PORT_NONE
;
202 case ETH_PHY_UNSPECIFIED
:
204 port_type
= PORT_OTHER
;
210 static int bnx2x_get_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
212 struct bnx2x
*bp
= netdev_priv(dev
);
213 int cfg_idx
= bnx2x_get_link_cfg_idx(bp
);
215 /* Dual Media boards present all available port types */
216 cmd
->supported
= bp
->port
.supported
[cfg_idx
] |
217 (bp
->port
.supported
[cfg_idx
^ 1] &
218 (SUPPORTED_TP
| SUPPORTED_FIBRE
));
219 cmd
->advertising
= bp
->port
.advertising
[cfg_idx
];
221 if ((bp
->state
== BNX2X_STATE_OPEN
) &&
222 !(bp
->flags
& MF_FUNC_DIS
) &&
223 (bp
->link_vars
.link_up
)) {
224 ethtool_cmd_speed_set(cmd
, bp
->link_vars
.line_speed
);
225 cmd
->duplex
= bp
->link_vars
.duplex
;
227 ethtool_cmd_speed_set(
228 cmd
, bp
->link_params
.req_line_speed
[cfg_idx
]);
229 cmd
->duplex
= bp
->link_params
.req_duplex
[cfg_idx
];
233 ethtool_cmd_speed_set(cmd
, bnx2x_get_mf_speed(bp
));
235 cmd
->port
= bnx2x_get_port_type(bp
);
237 cmd
->phy_address
= bp
->mdio
.prtad
;
238 cmd
->transceiver
= XCVR_INTERNAL
;
240 if (bp
->link_params
.req_line_speed
[cfg_idx
] == SPEED_AUTO_NEG
)
241 cmd
->autoneg
= AUTONEG_ENABLE
;
243 cmd
->autoneg
= AUTONEG_DISABLE
;
248 DP(NETIF_MSG_LINK
, "ethtool_cmd: cmd %d\n"
249 " supported 0x%x advertising 0x%x speed %u\n"
250 " duplex %d port %d phy_address %d transceiver %d\n"
251 " autoneg %d maxtxpkt %d maxrxpkt %d\n",
252 cmd
->cmd
, cmd
->supported
, cmd
->advertising
,
253 ethtool_cmd_speed(cmd
),
254 cmd
->duplex
, cmd
->port
, cmd
->phy_address
, cmd
->transceiver
,
255 cmd
->autoneg
, cmd
->maxtxpkt
, cmd
->maxrxpkt
);
260 static int bnx2x_set_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
262 struct bnx2x
*bp
= netdev_priv(dev
);
263 u32 advertising
, cfg_idx
, old_multi_phy_config
, new_multi_phy_config
;
269 DP(NETIF_MSG_LINK
, "ethtool_cmd: cmd %d\n"
270 " supported 0x%x advertising 0x%x speed %u\n"
271 " duplex %d port %d phy_address %d transceiver %d\n"
272 " autoneg %d maxtxpkt %d maxrxpkt %d\n",
273 cmd
->cmd
, cmd
->supported
, cmd
->advertising
,
274 ethtool_cmd_speed(cmd
),
275 cmd
->duplex
, cmd
->port
, cmd
->phy_address
, cmd
->transceiver
,
276 cmd
->autoneg
, cmd
->maxtxpkt
, cmd
->maxrxpkt
);
278 speed
= ethtool_cmd_speed(cmd
);
282 u32 line_speed
= bp
->link_vars
.line_speed
;
284 /* use 10G if no link detected */
288 if (bp
->common
.bc_ver
< REQ_BC_VER_4_SET_MF_BW
) {
289 BNX2X_DEV_INFO("To set speed BC %X or higher "
290 "is required, please upgrade BC\n",
291 REQ_BC_VER_4_SET_MF_BW
);
295 part
= (speed
* 100) / line_speed
;
297 if (line_speed
< speed
|| !part
) {
298 BNX2X_DEV_INFO("Speed setting should be in a range "
300 "of actual line speed\n");
304 if (bp
->state
!= BNX2X_STATE_OPEN
)
305 /* store value for following "load" */
306 bp
->pending_max
= part
;
308 bnx2x_update_max_mf_config(bp
, part
);
313 cfg_idx
= bnx2x_get_link_cfg_idx(bp
);
314 old_multi_phy_config
= bp
->link_params
.multi_phy_config
;
317 if (bp
->port
.supported
[cfg_idx
] & SUPPORTED_TP
)
318 break; /* no port change */
320 if (!(bp
->port
.supported
[0] & SUPPORTED_TP
||
321 bp
->port
.supported
[1] & SUPPORTED_TP
)) {
322 DP(NETIF_MSG_LINK
, "Unsupported port type\n");
325 bp
->link_params
.multi_phy_config
&=
326 ~PORT_HW_CFG_PHY_SELECTION_MASK
;
327 if (bp
->link_params
.multi_phy_config
&
328 PORT_HW_CFG_PHY_SWAPPED_ENABLED
)
329 bp
->link_params
.multi_phy_config
|=
330 PORT_HW_CFG_PHY_SELECTION_SECOND_PHY
;
332 bp
->link_params
.multi_phy_config
|=
333 PORT_HW_CFG_PHY_SELECTION_FIRST_PHY
;
337 if (bp
->port
.supported
[cfg_idx
] & SUPPORTED_FIBRE
)
338 break; /* no port change */
340 if (!(bp
->port
.supported
[0] & SUPPORTED_FIBRE
||
341 bp
->port
.supported
[1] & SUPPORTED_FIBRE
)) {
342 DP(NETIF_MSG_LINK
, "Unsupported port type\n");
345 bp
->link_params
.multi_phy_config
&=
346 ~PORT_HW_CFG_PHY_SELECTION_MASK
;
347 if (bp
->link_params
.multi_phy_config
&
348 PORT_HW_CFG_PHY_SWAPPED_ENABLED
)
349 bp
->link_params
.multi_phy_config
|=
350 PORT_HW_CFG_PHY_SELECTION_FIRST_PHY
;
352 bp
->link_params
.multi_phy_config
|=
353 PORT_HW_CFG_PHY_SELECTION_SECOND_PHY
;
356 DP(NETIF_MSG_LINK
, "Unsupported port type\n");
359 /* Save new config in case command complete successully */
360 new_multi_phy_config
= bp
->link_params
.multi_phy_config
;
361 /* Get the new cfg_idx */
362 cfg_idx
= bnx2x_get_link_cfg_idx(bp
);
363 /* Restore old config in case command failed */
364 bp
->link_params
.multi_phy_config
= old_multi_phy_config
;
365 DP(NETIF_MSG_LINK
, "cfg_idx = %x\n", cfg_idx
);
367 if (cmd
->autoneg
== AUTONEG_ENABLE
) {
368 u32 an_supported_speed
= bp
->port
.supported
[cfg_idx
];
369 if (bp
->link_params
.phy
[EXT_PHY1
].type
==
370 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833
)
371 an_supported_speed
|= (SUPPORTED_100baseT_Half
|
372 SUPPORTED_100baseT_Full
);
373 if (!(bp
->port
.supported
[cfg_idx
] & SUPPORTED_Autoneg
)) {
374 DP(NETIF_MSG_LINK
, "Autoneg not supported\n");
378 /* advertise the requested speed and duplex if supported */
379 if (cmd
->advertising
& ~an_supported_speed
) {
380 DP(NETIF_MSG_LINK
, "Advertisement parameters "
381 "are not supported\n");
385 bp
->link_params
.req_line_speed
[cfg_idx
] = SPEED_AUTO_NEG
;
386 bp
->link_params
.req_duplex
[cfg_idx
] = cmd
->duplex
;
387 bp
->port
.advertising
[cfg_idx
] = (ADVERTISED_Autoneg
|
389 if (cmd
->advertising
) {
391 bp
->link_params
.speed_cap_mask
[cfg_idx
] = 0;
392 if (cmd
->advertising
& ADVERTISED_10baseT_Half
) {
393 bp
->link_params
.speed_cap_mask
[cfg_idx
] |=
394 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF
;
396 if (cmd
->advertising
& ADVERTISED_10baseT_Full
)
397 bp
->link_params
.speed_cap_mask
[cfg_idx
] |=
398 PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL
;
400 if (cmd
->advertising
& ADVERTISED_100baseT_Full
)
401 bp
->link_params
.speed_cap_mask
[cfg_idx
] |=
402 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL
;
404 if (cmd
->advertising
& ADVERTISED_100baseT_Half
) {
405 bp
->link_params
.speed_cap_mask
[cfg_idx
] |=
406 PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF
;
408 if (cmd
->advertising
& ADVERTISED_1000baseT_Half
) {
409 bp
->link_params
.speed_cap_mask
[cfg_idx
] |=
410 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G
;
412 if (cmd
->advertising
& (ADVERTISED_1000baseT_Full
|
413 ADVERTISED_1000baseKX_Full
))
414 bp
->link_params
.speed_cap_mask
[cfg_idx
] |=
415 PORT_HW_CFG_SPEED_CAPABILITY_D0_1G
;
417 if (cmd
->advertising
& (ADVERTISED_10000baseT_Full
|
418 ADVERTISED_10000baseKX4_Full
|
419 ADVERTISED_10000baseKR_Full
))
420 bp
->link_params
.speed_cap_mask
[cfg_idx
] |=
421 PORT_HW_CFG_SPEED_CAPABILITY_D0_10G
;
423 } else { /* forced speed */
424 /* advertise the requested speed and duplex if supported */
427 if (cmd
->duplex
== DUPLEX_FULL
) {
428 if (!(bp
->port
.supported
[cfg_idx
] &
429 SUPPORTED_10baseT_Full
)) {
431 "10M full not supported\n");
435 advertising
= (ADVERTISED_10baseT_Full
|
438 if (!(bp
->port
.supported
[cfg_idx
] &
439 SUPPORTED_10baseT_Half
)) {
441 "10M half not supported\n");
445 advertising
= (ADVERTISED_10baseT_Half
|
451 if (cmd
->duplex
== DUPLEX_FULL
) {
452 if (!(bp
->port
.supported
[cfg_idx
] &
453 SUPPORTED_100baseT_Full
)) {
455 "100M full not supported\n");
459 advertising
= (ADVERTISED_100baseT_Full
|
462 if (!(bp
->port
.supported
[cfg_idx
] &
463 SUPPORTED_100baseT_Half
)) {
465 "100M half not supported\n");
469 advertising
= (ADVERTISED_100baseT_Half
|
475 if (cmd
->duplex
!= DUPLEX_FULL
) {
476 DP(NETIF_MSG_LINK
, "1G half not supported\n");
480 if (!(bp
->port
.supported
[cfg_idx
] &
481 SUPPORTED_1000baseT_Full
)) {
482 DP(NETIF_MSG_LINK
, "1G full not supported\n");
486 advertising
= (ADVERTISED_1000baseT_Full
|
491 if (cmd
->duplex
!= DUPLEX_FULL
) {
493 "2.5G half not supported\n");
497 if (!(bp
->port
.supported
[cfg_idx
]
498 & SUPPORTED_2500baseX_Full
)) {
500 "2.5G full not supported\n");
504 advertising
= (ADVERTISED_2500baseX_Full
|
509 if (cmd
->duplex
!= DUPLEX_FULL
) {
510 DP(NETIF_MSG_LINK
, "10G half not supported\n");
514 if (!(bp
->port
.supported
[cfg_idx
]
515 & SUPPORTED_10000baseT_Full
)) {
516 DP(NETIF_MSG_LINK
, "10G full not supported\n");
520 advertising
= (ADVERTISED_10000baseT_Full
|
525 DP(NETIF_MSG_LINK
, "Unsupported speed %u\n", speed
);
529 bp
->link_params
.req_line_speed
[cfg_idx
] = speed
;
530 bp
->link_params
.req_duplex
[cfg_idx
] = cmd
->duplex
;
531 bp
->port
.advertising
[cfg_idx
] = advertising
;
534 DP(NETIF_MSG_LINK
, "req_line_speed %d\n"
535 " req_duplex %d advertising 0x%x\n",
536 bp
->link_params
.req_line_speed
[cfg_idx
],
537 bp
->link_params
.req_duplex
[cfg_idx
],
538 bp
->port
.advertising
[cfg_idx
]);
541 bp
->link_params
.multi_phy_config
= new_multi_phy_config
;
542 if (netif_running(dev
)) {
543 bnx2x_stats_handle(bp
, STATS_EVENT_STOP
);
550 #define IS_E1_ONLINE(info) (((info) & RI_E1_ONLINE) == RI_E1_ONLINE)
551 #define IS_E1H_ONLINE(info) (((info) & RI_E1H_ONLINE) == RI_E1H_ONLINE)
552 #define IS_E2_ONLINE(info) (((info) & RI_E2_ONLINE) == RI_E2_ONLINE)
553 #define IS_E3_ONLINE(info) (((info) & RI_E3_ONLINE) == RI_E3_ONLINE)
554 #define IS_E3B0_ONLINE(info) (((info) & RI_E3B0_ONLINE) == RI_E3B0_ONLINE)
556 static inline bool bnx2x_is_reg_online(struct bnx2x
*bp
,
557 const struct reg_addr
*reg_info
)
560 return IS_E1_ONLINE(reg_info
->info
);
561 else if (CHIP_IS_E1H(bp
))
562 return IS_E1H_ONLINE(reg_info
->info
);
563 else if (CHIP_IS_E2(bp
))
564 return IS_E2_ONLINE(reg_info
->info
);
565 else if (CHIP_IS_E3A0(bp
))
566 return IS_E3_ONLINE(reg_info
->info
);
567 else if (CHIP_IS_E3B0(bp
))
568 return IS_E3B0_ONLINE(reg_info
->info
);
573 /******* Paged registers info selectors ********/
574 static inline const u32
*__bnx2x_get_page_addr_ar(struct bnx2x
*bp
)
578 else if (CHIP_IS_E3(bp
))
584 static inline u32
__bnx2x_get_page_reg_num(struct bnx2x
*bp
)
587 return PAGE_MODE_VALUES_E2
;
588 else if (CHIP_IS_E3(bp
))
589 return PAGE_MODE_VALUES_E3
;
594 static inline const u32
*__bnx2x_get_page_write_ar(struct bnx2x
*bp
)
597 return page_write_regs_e2
;
598 else if (CHIP_IS_E3(bp
))
599 return page_write_regs_e3
;
604 static inline u32
__bnx2x_get_page_write_num(struct bnx2x
*bp
)
607 return PAGE_WRITE_REGS_E2
;
608 else if (CHIP_IS_E3(bp
))
609 return PAGE_WRITE_REGS_E3
;
614 static inline const struct reg_addr
*__bnx2x_get_page_read_ar(struct bnx2x
*bp
)
617 return page_read_regs_e2
;
618 else if (CHIP_IS_E3(bp
))
619 return page_read_regs_e3
;
624 static inline u32
__bnx2x_get_page_read_num(struct bnx2x
*bp
)
627 return PAGE_READ_REGS_E2
;
628 else if (CHIP_IS_E3(bp
))
629 return PAGE_READ_REGS_E3
;
634 static inline int __bnx2x_get_regs_len(struct bnx2x
*bp
)
636 int num_pages
= __bnx2x_get_page_reg_num(bp
);
637 int page_write_num
= __bnx2x_get_page_write_num(bp
);
638 const struct reg_addr
*page_read_addr
= __bnx2x_get_page_read_ar(bp
);
639 int page_read_num
= __bnx2x_get_page_read_num(bp
);
643 for (i
= 0; i
< REGS_COUNT
; i
++)
644 if (bnx2x_is_reg_online(bp
, ®_addrs
[i
]))
645 regdump_len
+= reg_addrs
[i
].size
;
647 for (i
= 0; i
< num_pages
; i
++)
648 for (j
= 0; j
< page_write_num
; j
++)
649 for (k
= 0; k
< page_read_num
; k
++)
650 if (bnx2x_is_reg_online(bp
, &page_read_addr
[k
]))
651 regdump_len
+= page_read_addr
[k
].size
;
656 static int bnx2x_get_regs_len(struct net_device
*dev
)
658 struct bnx2x
*bp
= netdev_priv(dev
);
661 regdump_len
= __bnx2x_get_regs_len(bp
);
663 regdump_len
+= sizeof(struct dump_hdr
);
669 * bnx2x_read_pages_regs - read "paged" registers
674 * Reads "paged" memories: memories that may only be read by first writing to a
675 * specific address ("write address") and then reading from a specific address
676 * ("read address"). There may be more than one write address per "page" and
677 * more than one read address per write address.
679 static inline void bnx2x_read_pages_regs(struct bnx2x
*bp
, u32
*p
)
682 /* addresses of the paged registers */
683 const u32
*page_addr
= __bnx2x_get_page_addr_ar(bp
);
684 /* number of paged registers */
685 int num_pages
= __bnx2x_get_page_reg_num(bp
);
686 /* write addresses */
687 const u32
*write_addr
= __bnx2x_get_page_write_ar(bp
);
688 /* number of write addresses */
689 int write_num
= __bnx2x_get_page_write_num(bp
);
690 /* read addresses info */
691 const struct reg_addr
*read_addr
= __bnx2x_get_page_read_ar(bp
);
692 /* number of read addresses */
693 int read_num
= __bnx2x_get_page_read_num(bp
);
695 for (i
= 0; i
< num_pages
; i
++) {
696 for (j
= 0; j
< write_num
; j
++) {
697 REG_WR(bp
, write_addr
[j
], page_addr
[i
]);
698 for (k
= 0; k
< read_num
; k
++)
699 if (bnx2x_is_reg_online(bp
, &read_addr
[k
]))
701 read_addr
[k
].size
; n
++)
703 read_addr
[k
].addr
+ n
*4);
708 static inline void __bnx2x_get_regs(struct bnx2x
*bp
, u32
*p
)
712 /* Read the regular registers */
713 for (i
= 0; i
< REGS_COUNT
; i
++)
714 if (bnx2x_is_reg_online(bp
, ®_addrs
[i
]))
715 for (j
= 0; j
< reg_addrs
[i
].size
; j
++)
716 *p
++ = REG_RD(bp
, reg_addrs
[i
].addr
+ j
*4);
718 /* Read "paged" registes */
719 bnx2x_read_pages_regs(bp
, p
);
722 static void bnx2x_get_regs(struct net_device
*dev
,
723 struct ethtool_regs
*regs
, void *_p
)
726 struct bnx2x
*bp
= netdev_priv(dev
);
727 struct dump_hdr dump_hdr
= {0};
730 memset(p
, 0, regs
->len
);
732 if (!netif_running(bp
->dev
))
735 /* Disable parity attentions as long as following dump may
736 * cause false alarms by reading never written registers. We
737 * will re-enable parity attentions right after the dump.
739 bnx2x_disable_blocks_parity(bp
);
741 dump_hdr
.hdr_size
= (sizeof(struct dump_hdr
) / 4) - 1;
742 dump_hdr
.dump_sign
= dump_sign_all
;
743 dump_hdr
.xstorm_waitp
= REG_RD(bp
, XSTORM_WAITP_ADDR
);
744 dump_hdr
.tstorm_waitp
= REG_RD(bp
, TSTORM_WAITP_ADDR
);
745 dump_hdr
.ustorm_waitp
= REG_RD(bp
, USTORM_WAITP_ADDR
);
746 dump_hdr
.cstorm_waitp
= REG_RD(bp
, CSTORM_WAITP_ADDR
);
749 dump_hdr
.info
= RI_E1_ONLINE
;
750 else if (CHIP_IS_E1H(bp
))
751 dump_hdr
.info
= RI_E1H_ONLINE
;
752 else if (!CHIP_IS_E1x(bp
))
753 dump_hdr
.info
= RI_E2_ONLINE
|
754 (BP_PATH(bp
) ? RI_PATH1_DUMP
: RI_PATH0_DUMP
);
756 memcpy(p
, &dump_hdr
, sizeof(struct dump_hdr
));
757 p
+= dump_hdr
.hdr_size
+ 1;
759 /* Actually read the registers */
760 __bnx2x_get_regs(bp
, p
);
762 /* Re-enable parity attentions */
763 bnx2x_clear_blocks_parity(bp
);
764 bnx2x_enable_blocks_parity(bp
);
767 static void bnx2x_get_drvinfo(struct net_device
*dev
,
768 struct ethtool_drvinfo
*info
)
770 struct bnx2x
*bp
= netdev_priv(dev
);
771 u8 phy_fw_ver
[PHY_FW_VER_LEN
];
773 strlcpy(info
->driver
, DRV_MODULE_NAME
, sizeof(info
->driver
));
774 strlcpy(info
->version
, DRV_MODULE_VERSION
, sizeof(info
->version
));
776 phy_fw_ver
[0] = '\0';
778 bnx2x_acquire_phy_lock(bp
);
779 bnx2x_get_ext_phy_fw_version(&bp
->link_params
,
780 (bp
->state
!= BNX2X_STATE_CLOSED
),
781 phy_fw_ver
, PHY_FW_VER_LEN
);
782 bnx2x_release_phy_lock(bp
);
785 strlcpy(info
->fw_version
, bp
->fw_ver
, sizeof(info
->fw_version
));
786 snprintf(info
->fw_version
+ strlen(bp
->fw_ver
), 32 - strlen(bp
->fw_ver
),
788 (bp
->common
.bc_ver
& 0xff0000) >> 16,
789 (bp
->common
.bc_ver
& 0xff00) >> 8,
790 (bp
->common
.bc_ver
& 0xff),
791 ((phy_fw_ver
[0] != '\0') ? " phy " : ""), phy_fw_ver
);
792 strlcpy(info
->bus_info
, pci_name(bp
->pdev
), sizeof(info
->bus_info
));
793 info
->n_stats
= BNX2X_NUM_STATS
;
794 info
->testinfo_len
= BNX2X_NUM_TESTS
;
795 info
->eedump_len
= bp
->common
.flash_size
;
796 info
->regdump_len
= bnx2x_get_regs_len(dev
);
799 static void bnx2x_get_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
801 struct bnx2x
*bp
= netdev_priv(dev
);
803 if (bp
->flags
& NO_WOL_FLAG
) {
807 wol
->supported
= WAKE_MAGIC
;
809 wol
->wolopts
= WAKE_MAGIC
;
813 memset(&wol
->sopass
, 0, sizeof(wol
->sopass
));
816 static int bnx2x_set_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
818 struct bnx2x
*bp
= netdev_priv(dev
);
820 if (wol
->wolopts
& ~WAKE_MAGIC
)
823 if (wol
->wolopts
& WAKE_MAGIC
) {
824 if (bp
->flags
& NO_WOL_FLAG
)
834 static u32
bnx2x_get_msglevel(struct net_device
*dev
)
836 struct bnx2x
*bp
= netdev_priv(dev
);
838 return bp
->msg_enable
;
841 static void bnx2x_set_msglevel(struct net_device
*dev
, u32 level
)
843 struct bnx2x
*bp
= netdev_priv(dev
);
845 if (capable(CAP_NET_ADMIN
)) {
847 if (level
& BNX2X_MSG_MCP
)
848 bnx2x_fw_dump_lvl(bp
, KERN_INFO
);
849 bp
->msg_enable
= level
;
853 static int bnx2x_nway_reset(struct net_device
*dev
)
855 struct bnx2x
*bp
= netdev_priv(dev
);
860 if (netif_running(dev
)) {
861 bnx2x_stats_handle(bp
, STATS_EVENT_STOP
);
868 static u32
bnx2x_get_link(struct net_device
*dev
)
870 struct bnx2x
*bp
= netdev_priv(dev
);
872 if (bp
->flags
& MF_FUNC_DIS
|| (bp
->state
!= BNX2X_STATE_OPEN
))
875 return bp
->link_vars
.link_up
;
878 static int bnx2x_get_eeprom_len(struct net_device
*dev
)
880 struct bnx2x
*bp
= netdev_priv(dev
);
882 return bp
->common
.flash_size
;
885 static int bnx2x_acquire_nvram_lock(struct bnx2x
*bp
)
887 int port
= BP_PORT(bp
);
891 /* adjust timeout for emulation/FPGA */
892 count
= BNX2X_NVRAM_TIMEOUT_COUNT
;
893 if (CHIP_REV_IS_SLOW(bp
))
896 /* request access to nvram interface */
897 REG_WR(bp
, MCP_REG_MCPR_NVM_SW_ARB
,
898 (MCPR_NVM_SW_ARB_ARB_REQ_SET1
<< port
));
900 for (i
= 0; i
< count
*10; i
++) {
901 val
= REG_RD(bp
, MCP_REG_MCPR_NVM_SW_ARB
);
902 if (val
& (MCPR_NVM_SW_ARB_ARB_ARB1
<< port
))
908 if (!(val
& (MCPR_NVM_SW_ARB_ARB_ARB1
<< port
))) {
909 DP(BNX2X_MSG_NVM
, "cannot get access to nvram interface\n");
916 static int bnx2x_release_nvram_lock(struct bnx2x
*bp
)
918 int port
= BP_PORT(bp
);
922 /* adjust timeout for emulation/FPGA */
923 count
= BNX2X_NVRAM_TIMEOUT_COUNT
;
924 if (CHIP_REV_IS_SLOW(bp
))
927 /* relinquish nvram interface */
928 REG_WR(bp
, MCP_REG_MCPR_NVM_SW_ARB
,
929 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1
<< port
));
931 for (i
= 0; i
< count
*10; i
++) {
932 val
= REG_RD(bp
, MCP_REG_MCPR_NVM_SW_ARB
);
933 if (!(val
& (MCPR_NVM_SW_ARB_ARB_ARB1
<< port
)))
939 if (val
& (MCPR_NVM_SW_ARB_ARB_ARB1
<< port
)) {
940 DP(BNX2X_MSG_NVM
, "cannot free access to nvram interface\n");
947 static void bnx2x_enable_nvram_access(struct bnx2x
*bp
)
951 val
= REG_RD(bp
, MCP_REG_MCPR_NVM_ACCESS_ENABLE
);
953 /* enable both bits, even on read */
954 REG_WR(bp
, MCP_REG_MCPR_NVM_ACCESS_ENABLE
,
955 (val
| MCPR_NVM_ACCESS_ENABLE_EN
|
956 MCPR_NVM_ACCESS_ENABLE_WR_EN
));
959 static void bnx2x_disable_nvram_access(struct bnx2x
*bp
)
963 val
= REG_RD(bp
, MCP_REG_MCPR_NVM_ACCESS_ENABLE
);
965 /* disable both bits, even after read */
966 REG_WR(bp
, MCP_REG_MCPR_NVM_ACCESS_ENABLE
,
967 (val
& ~(MCPR_NVM_ACCESS_ENABLE_EN
|
968 MCPR_NVM_ACCESS_ENABLE_WR_EN
)));
971 static int bnx2x_nvram_read_dword(struct bnx2x
*bp
, u32 offset
, __be32
*ret_val
,
977 /* build the command word */
978 cmd_flags
|= MCPR_NVM_COMMAND_DOIT
;
980 /* need to clear DONE bit separately */
981 REG_WR(bp
, MCP_REG_MCPR_NVM_COMMAND
, MCPR_NVM_COMMAND_DONE
);
983 /* address of the NVRAM to read from */
984 REG_WR(bp
, MCP_REG_MCPR_NVM_ADDR
,
985 (offset
& MCPR_NVM_ADDR_NVM_ADDR_VALUE
));
987 /* issue a read command */
988 REG_WR(bp
, MCP_REG_MCPR_NVM_COMMAND
, cmd_flags
);
990 /* adjust timeout for emulation/FPGA */
991 count
= BNX2X_NVRAM_TIMEOUT_COUNT
;
992 if (CHIP_REV_IS_SLOW(bp
))
995 /* wait for completion */
998 for (i
= 0; i
< count
; i
++) {
1000 val
= REG_RD(bp
, MCP_REG_MCPR_NVM_COMMAND
);
1002 if (val
& MCPR_NVM_COMMAND_DONE
) {
1003 val
= REG_RD(bp
, MCP_REG_MCPR_NVM_READ
);
1004 /* we read nvram data in cpu order
1005 * but ethtool sees it as an array of bytes
1006 * converting to big-endian will do the work */
1007 *ret_val
= cpu_to_be32(val
);
1016 static int bnx2x_nvram_read(struct bnx2x
*bp
, u32 offset
, u8
*ret_buf
,
1023 if ((offset
& 0x03) || (buf_size
& 0x03) || (buf_size
== 0)) {
1025 "Invalid parameter: offset 0x%x buf_size 0x%x\n",
1030 if (offset
+ buf_size
> bp
->common
.flash_size
) {
1031 DP(BNX2X_MSG_NVM
, "Invalid parameter: offset (0x%x) +"
1032 " buf_size (0x%x) > flash_size (0x%x)\n",
1033 offset
, buf_size
, bp
->common
.flash_size
);
1037 /* request access to nvram interface */
1038 rc
= bnx2x_acquire_nvram_lock(bp
);
1042 /* enable access to nvram interface */
1043 bnx2x_enable_nvram_access(bp
);
1045 /* read the first word(s) */
1046 cmd_flags
= MCPR_NVM_COMMAND_FIRST
;
1047 while ((buf_size
> sizeof(u32
)) && (rc
== 0)) {
1048 rc
= bnx2x_nvram_read_dword(bp
, offset
, &val
, cmd_flags
);
1049 memcpy(ret_buf
, &val
, 4);
1051 /* advance to the next dword */
1052 offset
+= sizeof(u32
);
1053 ret_buf
+= sizeof(u32
);
1054 buf_size
-= sizeof(u32
);
1059 cmd_flags
|= MCPR_NVM_COMMAND_LAST
;
1060 rc
= bnx2x_nvram_read_dword(bp
, offset
, &val
, cmd_flags
);
1061 memcpy(ret_buf
, &val
, 4);
1064 /* disable access to nvram interface */
1065 bnx2x_disable_nvram_access(bp
);
1066 bnx2x_release_nvram_lock(bp
);
1071 static int bnx2x_get_eeprom(struct net_device
*dev
,
1072 struct ethtool_eeprom
*eeprom
, u8
*eebuf
)
1074 struct bnx2x
*bp
= netdev_priv(dev
);
1077 if (!netif_running(dev
))
1080 DP(BNX2X_MSG_NVM
, "ethtool_eeprom: cmd %d\n"
1081 " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
1082 eeprom
->cmd
, eeprom
->magic
, eeprom
->offset
, eeprom
->offset
,
1083 eeprom
->len
, eeprom
->len
);
1085 /* parameters already validated in ethtool_get_eeprom */
1087 rc
= bnx2x_nvram_read(bp
, eeprom
->offset
, eebuf
, eeprom
->len
);
1092 static int bnx2x_nvram_write_dword(struct bnx2x
*bp
, u32 offset
, u32 val
,
1097 /* build the command word */
1098 cmd_flags
|= MCPR_NVM_COMMAND_DOIT
| MCPR_NVM_COMMAND_WR
;
1100 /* need to clear DONE bit separately */
1101 REG_WR(bp
, MCP_REG_MCPR_NVM_COMMAND
, MCPR_NVM_COMMAND_DONE
);
1103 /* write the data */
1104 REG_WR(bp
, MCP_REG_MCPR_NVM_WRITE
, val
);
1106 /* address of the NVRAM to write to */
1107 REG_WR(bp
, MCP_REG_MCPR_NVM_ADDR
,
1108 (offset
& MCPR_NVM_ADDR_NVM_ADDR_VALUE
));
1110 /* issue the write command */
1111 REG_WR(bp
, MCP_REG_MCPR_NVM_COMMAND
, cmd_flags
);
1113 /* adjust timeout for emulation/FPGA */
1114 count
= BNX2X_NVRAM_TIMEOUT_COUNT
;
1115 if (CHIP_REV_IS_SLOW(bp
))
1118 /* wait for completion */
1120 for (i
= 0; i
< count
; i
++) {
1122 val
= REG_RD(bp
, MCP_REG_MCPR_NVM_COMMAND
);
1123 if (val
& MCPR_NVM_COMMAND_DONE
) {
1132 #define BYTE_OFFSET(offset) (8 * (offset & 0x03))
1134 static int bnx2x_nvram_write1(struct bnx2x
*bp
, u32 offset
, u8
*data_buf
,
1142 if (offset
+ buf_size
> bp
->common
.flash_size
) {
1143 DP(BNX2X_MSG_NVM
, "Invalid parameter: offset (0x%x) +"
1144 " buf_size (0x%x) > flash_size (0x%x)\n",
1145 offset
, buf_size
, bp
->common
.flash_size
);
1149 /* request access to nvram interface */
1150 rc
= bnx2x_acquire_nvram_lock(bp
);
1154 /* enable access to nvram interface */
1155 bnx2x_enable_nvram_access(bp
);
1157 cmd_flags
= (MCPR_NVM_COMMAND_FIRST
| MCPR_NVM_COMMAND_LAST
);
1158 align_offset
= (offset
& ~0x03);
1159 rc
= bnx2x_nvram_read_dword(bp
, align_offset
, &val
, cmd_flags
);
1162 val
&= ~(0xff << BYTE_OFFSET(offset
));
1163 val
|= (*data_buf
<< BYTE_OFFSET(offset
));
1165 /* nvram data is returned as an array of bytes
1166 * convert it back to cpu order */
1167 val
= be32_to_cpu(val
);
1169 rc
= bnx2x_nvram_write_dword(bp
, align_offset
, val
,
1173 /* disable access to nvram interface */
1174 bnx2x_disable_nvram_access(bp
);
1175 bnx2x_release_nvram_lock(bp
);
1180 static int bnx2x_nvram_write(struct bnx2x
*bp
, u32 offset
, u8
*data_buf
,
1188 if (buf_size
== 1) /* ethtool */
1189 return bnx2x_nvram_write1(bp
, offset
, data_buf
, buf_size
);
1191 if ((offset
& 0x03) || (buf_size
& 0x03) || (buf_size
== 0)) {
1193 "Invalid parameter: offset 0x%x buf_size 0x%x\n",
1198 if (offset
+ buf_size
> bp
->common
.flash_size
) {
1199 DP(BNX2X_MSG_NVM
, "Invalid parameter: offset (0x%x) +"
1200 " buf_size (0x%x) > flash_size (0x%x)\n",
1201 offset
, buf_size
, bp
->common
.flash_size
);
1205 /* request access to nvram interface */
1206 rc
= bnx2x_acquire_nvram_lock(bp
);
1210 /* enable access to nvram interface */
1211 bnx2x_enable_nvram_access(bp
);
1214 cmd_flags
= MCPR_NVM_COMMAND_FIRST
;
1215 while ((written_so_far
< buf_size
) && (rc
== 0)) {
1216 if (written_so_far
== (buf_size
- sizeof(u32
)))
1217 cmd_flags
|= MCPR_NVM_COMMAND_LAST
;
1218 else if (((offset
+ 4) % BNX2X_NVRAM_PAGE_SIZE
) == 0)
1219 cmd_flags
|= MCPR_NVM_COMMAND_LAST
;
1220 else if ((offset
% BNX2X_NVRAM_PAGE_SIZE
) == 0)
1221 cmd_flags
|= MCPR_NVM_COMMAND_FIRST
;
1223 memcpy(&val
, data_buf
, 4);
1225 rc
= bnx2x_nvram_write_dword(bp
, offset
, val
, cmd_flags
);
1227 /* advance to the next dword */
1228 offset
+= sizeof(u32
);
1229 data_buf
+= sizeof(u32
);
1230 written_so_far
+= sizeof(u32
);
1234 /* disable access to nvram interface */
1235 bnx2x_disable_nvram_access(bp
);
1236 bnx2x_release_nvram_lock(bp
);
1241 static int bnx2x_set_eeprom(struct net_device
*dev
,
1242 struct ethtool_eeprom
*eeprom
, u8
*eebuf
)
1244 struct bnx2x
*bp
= netdev_priv(dev
);
1245 int port
= BP_PORT(bp
);
1248 if (!netif_running(dev
))
1251 DP(BNX2X_MSG_NVM
, "ethtool_eeprom: cmd %d\n"
1252 " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
1253 eeprom
->cmd
, eeprom
->magic
, eeprom
->offset
, eeprom
->offset
,
1254 eeprom
->len
, eeprom
->len
);
1256 /* parameters already validated in ethtool_set_eeprom */
1258 /* PHY eeprom can be accessed only by the PMF */
1259 if ((eeprom
->magic
>= 0x50485900) && (eeprom
->magic
<= 0x504859FF) &&
1265 dev_info
.port_hw_config
[port
].external_phy_config
);
1267 if (eeprom
->magic
== 0x50485950) {
1268 /* 'PHYP' (0x50485950): prepare phy for FW upgrade */
1269 bnx2x_stats_handle(bp
, STATS_EVENT_STOP
);
1271 bnx2x_acquire_phy_lock(bp
);
1272 rc
|= bnx2x_link_reset(&bp
->link_params
,
1274 if (XGXS_EXT_PHY_TYPE(ext_phy_config
) ==
1275 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101
)
1276 bnx2x_set_gpio(bp
, MISC_REGISTERS_GPIO_0
,
1277 MISC_REGISTERS_GPIO_HIGH
, port
);
1278 bnx2x_release_phy_lock(bp
);
1279 bnx2x_link_report(bp
);
1281 } else if (eeprom
->magic
== 0x50485952) {
1282 /* 'PHYR' (0x50485952): re-init link after FW upgrade */
1283 if (bp
->state
== BNX2X_STATE_OPEN
) {
1284 bnx2x_acquire_phy_lock(bp
);
1285 rc
|= bnx2x_link_reset(&bp
->link_params
,
1288 rc
|= bnx2x_phy_init(&bp
->link_params
,
1290 bnx2x_release_phy_lock(bp
);
1291 bnx2x_calc_fc_adv(bp
);
1293 } else if (eeprom
->magic
== 0x53985943) {
1294 /* 'PHYC' (0x53985943): PHY FW upgrade completed */
1295 if (XGXS_EXT_PHY_TYPE(ext_phy_config
) ==
1296 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101
) {
1298 /* DSP Remove Download Mode */
1299 bnx2x_set_gpio(bp
, MISC_REGISTERS_GPIO_0
,
1300 MISC_REGISTERS_GPIO_LOW
, port
);
1302 bnx2x_acquire_phy_lock(bp
);
1304 bnx2x_sfx7101_sp_sw_reset(bp
,
1305 &bp
->link_params
.phy
[EXT_PHY1
]);
1307 /* wait 0.5 sec to allow it to run */
1309 bnx2x_ext_phy_hw_reset(bp
, port
);
1311 bnx2x_release_phy_lock(bp
);
1314 rc
= bnx2x_nvram_write(bp
, eeprom
->offset
, eebuf
, eeprom
->len
);
1319 static int bnx2x_get_coalesce(struct net_device
*dev
,
1320 struct ethtool_coalesce
*coal
)
1322 struct bnx2x
*bp
= netdev_priv(dev
);
1324 memset(coal
, 0, sizeof(struct ethtool_coalesce
));
1326 coal
->rx_coalesce_usecs
= bp
->rx_ticks
;
1327 coal
->tx_coalesce_usecs
= bp
->tx_ticks
;
1332 static int bnx2x_set_coalesce(struct net_device
*dev
,
1333 struct ethtool_coalesce
*coal
)
1335 struct bnx2x
*bp
= netdev_priv(dev
);
1337 bp
->rx_ticks
= (u16
)coal
->rx_coalesce_usecs
;
1338 if (bp
->rx_ticks
> BNX2X_MAX_COALESCE_TOUT
)
1339 bp
->rx_ticks
= BNX2X_MAX_COALESCE_TOUT
;
1341 bp
->tx_ticks
= (u16
)coal
->tx_coalesce_usecs
;
1342 if (bp
->tx_ticks
> BNX2X_MAX_COALESCE_TOUT
)
1343 bp
->tx_ticks
= BNX2X_MAX_COALESCE_TOUT
;
1345 if (netif_running(dev
))
1346 bnx2x_update_coalesce(bp
);
1351 static void bnx2x_get_ringparam(struct net_device
*dev
,
1352 struct ethtool_ringparam
*ering
)
1354 struct bnx2x
*bp
= netdev_priv(dev
);
1356 ering
->rx_max_pending
= MAX_RX_AVAIL
;
1358 if (bp
->rx_ring_size
)
1359 ering
->rx_pending
= bp
->rx_ring_size
;
1361 ering
->rx_pending
= MAX_RX_AVAIL
;
1363 ering
->tx_max_pending
= MAX_TX_AVAIL
;
1364 ering
->tx_pending
= bp
->tx_ring_size
;
1367 static int bnx2x_set_ringparam(struct net_device
*dev
,
1368 struct ethtool_ringparam
*ering
)
1370 struct bnx2x
*bp
= netdev_priv(dev
);
1372 if (bp
->recovery_state
!= BNX2X_RECOVERY_DONE
) {
1373 pr_err("Handling parity error recovery. Try again later\n");
1377 if ((ering
->rx_pending
> MAX_RX_AVAIL
) ||
1378 (ering
->rx_pending
< (bp
->disable_tpa
? MIN_RX_SIZE_NONTPA
:
1379 MIN_RX_SIZE_TPA
)) ||
1380 (ering
->tx_pending
> MAX_TX_AVAIL
) ||
1381 (ering
->tx_pending
<= MAX_SKB_FRAGS
+ 4))
1384 bp
->rx_ring_size
= ering
->rx_pending
;
1385 bp
->tx_ring_size
= ering
->tx_pending
;
1387 return bnx2x_reload_if_running(dev
);
1390 static void bnx2x_get_pauseparam(struct net_device
*dev
,
1391 struct ethtool_pauseparam
*epause
)
1393 struct bnx2x
*bp
= netdev_priv(dev
);
1394 int cfg_idx
= bnx2x_get_link_cfg_idx(bp
);
1395 epause
->autoneg
= (bp
->link_params
.req_flow_ctrl
[cfg_idx
] ==
1396 BNX2X_FLOW_CTRL_AUTO
);
1398 epause
->rx_pause
= ((bp
->link_vars
.flow_ctrl
& BNX2X_FLOW_CTRL_RX
) ==
1399 BNX2X_FLOW_CTRL_RX
);
1400 epause
->tx_pause
= ((bp
->link_vars
.flow_ctrl
& BNX2X_FLOW_CTRL_TX
) ==
1401 BNX2X_FLOW_CTRL_TX
);
1403 DP(NETIF_MSG_LINK
, "ethtool_pauseparam: cmd %d\n"
1404 " autoneg %d rx_pause %d tx_pause %d\n",
1405 epause
->cmd
, epause
->autoneg
, epause
->rx_pause
, epause
->tx_pause
);
1408 static int bnx2x_set_pauseparam(struct net_device
*dev
,
1409 struct ethtool_pauseparam
*epause
)
1411 struct bnx2x
*bp
= netdev_priv(dev
);
1412 u32 cfg_idx
= bnx2x_get_link_cfg_idx(bp
);
1416 DP(NETIF_MSG_LINK
, "ethtool_pauseparam: cmd %d\n"
1417 " autoneg %d rx_pause %d tx_pause %d\n",
1418 epause
->cmd
, epause
->autoneg
, epause
->rx_pause
, epause
->tx_pause
);
1420 bp
->link_params
.req_flow_ctrl
[cfg_idx
] = BNX2X_FLOW_CTRL_AUTO
;
1422 if (epause
->rx_pause
)
1423 bp
->link_params
.req_flow_ctrl
[cfg_idx
] |= BNX2X_FLOW_CTRL_RX
;
1425 if (epause
->tx_pause
)
1426 bp
->link_params
.req_flow_ctrl
[cfg_idx
] |= BNX2X_FLOW_CTRL_TX
;
1428 if (bp
->link_params
.req_flow_ctrl
[cfg_idx
] == BNX2X_FLOW_CTRL_AUTO
)
1429 bp
->link_params
.req_flow_ctrl
[cfg_idx
] = BNX2X_FLOW_CTRL_NONE
;
1431 if (epause
->autoneg
) {
1432 if (!(bp
->port
.supported
[cfg_idx
] & SUPPORTED_Autoneg
)) {
1433 DP(NETIF_MSG_LINK
, "autoneg not supported\n");
1437 if (bp
->link_params
.req_line_speed
[cfg_idx
] == SPEED_AUTO_NEG
) {
1438 bp
->link_params
.req_flow_ctrl
[cfg_idx
] =
1439 BNX2X_FLOW_CTRL_AUTO
;
1444 "req_flow_ctrl 0x%x\n", bp
->link_params
.req_flow_ctrl
[cfg_idx
]);
1446 if (netif_running(dev
)) {
1447 bnx2x_stats_handle(bp
, STATS_EVENT_STOP
);
1454 static const struct {
1455 char string
[ETH_GSTRING_LEN
];
1456 } bnx2x_tests_str_arr
[BNX2X_NUM_TESTS
] = {
1457 { "register_test (offline)" },
1458 { "memory_test (offline)" },
1459 { "loopback_test (offline)" },
1460 { "nvram_test (online)" },
1461 { "interrupt_test (online)" },
1462 { "link_test (online)" },
1463 { "idle check (online)" }
1467 BNX2X_CHIP_E1_OFST
= 0,
1468 BNX2X_CHIP_E1H_OFST
,
1471 BNX2X_CHIP_E3B0_OFST
,
1475 #define BNX2X_CHIP_MASK_E1 (1 << BNX2X_CHIP_E1_OFST)
1476 #define BNX2X_CHIP_MASK_E1H (1 << BNX2X_CHIP_E1H_OFST)
1477 #define BNX2X_CHIP_MASK_E2 (1 << BNX2X_CHIP_E2_OFST)
1478 #define BNX2X_CHIP_MASK_E3 (1 << BNX2X_CHIP_E3_OFST)
1479 #define BNX2X_CHIP_MASK_E3B0 (1 << BNX2X_CHIP_E3B0_OFST)
1481 #define BNX2X_CHIP_MASK_ALL ((1 << BNX2X_CHIP_MAX_OFST) - 1)
1482 #define BNX2X_CHIP_MASK_E1X (BNX2X_CHIP_MASK_E1 | BNX2X_CHIP_MASK_E1H)
1484 static int bnx2x_test_registers(struct bnx2x
*bp
)
1486 int idx
, i
, rc
= -ENODEV
;
1488 int port
= BP_PORT(bp
);
1489 static const struct {
1495 /* 0 */ { BNX2X_CHIP_MASK_ALL
,
1496 BRB1_REG_PAUSE_LOW_THRESHOLD_0
, 4, 0x000003ff },
1497 { BNX2X_CHIP_MASK_ALL
,
1498 DORQ_REG_DB_ADDR0
, 4, 0xffffffff },
1499 { BNX2X_CHIP_MASK_E1X
,
1500 HC_REG_AGG_INT_0
, 4, 0x000003ff },
1501 { BNX2X_CHIP_MASK_ALL
,
1502 PBF_REG_MAC_IF0_ENABLE
, 4, 0x00000001 },
1503 { BNX2X_CHIP_MASK_E1X
| BNX2X_CHIP_MASK_E2
| BNX2X_CHIP_MASK_E3
,
1504 PBF_REG_P0_INIT_CRD
, 4, 0x000007ff },
1505 { BNX2X_CHIP_MASK_E3B0
,
1506 PBF_REG_INIT_CRD_Q0
, 4, 0x000007ff },
1507 { BNX2X_CHIP_MASK_ALL
,
1508 PRS_REG_CID_PORT_0
, 4, 0x00ffffff },
1509 { BNX2X_CHIP_MASK_ALL
,
1510 PXP2_REG_PSWRQ_CDU0_L2P
, 4, 0x000fffff },
1511 { BNX2X_CHIP_MASK_ALL
,
1512 PXP2_REG_RQ_CDU0_EFIRST_MEM_ADDR
, 8, 0x0003ffff },
1513 { BNX2X_CHIP_MASK_ALL
,
1514 PXP2_REG_PSWRQ_TM0_L2P
, 4, 0x000fffff },
1515 /* 10 */ { BNX2X_CHIP_MASK_ALL
,
1516 PXP2_REG_RQ_USDM0_EFIRST_MEM_ADDR
, 8, 0x0003ffff },
1517 { BNX2X_CHIP_MASK_ALL
,
1518 PXP2_REG_PSWRQ_TSDM0_L2P
, 4, 0x000fffff },
1519 { BNX2X_CHIP_MASK_ALL
,
1520 QM_REG_CONNNUM_0
, 4, 0x000fffff },
1521 { BNX2X_CHIP_MASK_ALL
,
1522 TM_REG_LIN0_MAX_ACTIVE_CID
, 4, 0x0003ffff },
1523 { BNX2X_CHIP_MASK_ALL
,
1524 SRC_REG_KEYRSS0_0
, 40, 0xffffffff },
1525 { BNX2X_CHIP_MASK_ALL
,
1526 SRC_REG_KEYRSS0_7
, 40, 0xffffffff },
1527 { BNX2X_CHIP_MASK_ALL
,
1528 XCM_REG_WU_DA_SET_TMR_CNT_FLG_CMD00
, 4, 0x00000001 },
1529 { BNX2X_CHIP_MASK_ALL
,
1530 XCM_REG_WU_DA_CNT_CMD00
, 4, 0x00000003 },
1531 { BNX2X_CHIP_MASK_ALL
,
1532 XCM_REG_GLB_DEL_ACK_MAX_CNT_0
, 4, 0x000000ff },
1533 { BNX2X_CHIP_MASK_ALL
,
1534 NIG_REG_LLH0_T_BIT
, 4, 0x00000001 },
1535 /* 20 */ { BNX2X_CHIP_MASK_E1X
| BNX2X_CHIP_MASK_E2
,
1536 NIG_REG_EMAC0_IN_EN
, 4, 0x00000001 },
1537 { BNX2X_CHIP_MASK_E1X
| BNX2X_CHIP_MASK_E2
,
1538 NIG_REG_BMAC0_IN_EN
, 4, 0x00000001 },
1539 { BNX2X_CHIP_MASK_ALL
,
1540 NIG_REG_XCM0_OUT_EN
, 4, 0x00000001 },
1541 { BNX2X_CHIP_MASK_ALL
,
1542 NIG_REG_BRB0_OUT_EN
, 4, 0x00000001 },
1543 { BNX2X_CHIP_MASK_ALL
,
1544 NIG_REG_LLH0_XCM_MASK
, 4, 0x00000007 },
1545 { BNX2X_CHIP_MASK_ALL
,
1546 NIG_REG_LLH0_ACPI_PAT_6_LEN
, 68, 0x000000ff },
1547 { BNX2X_CHIP_MASK_ALL
,
1548 NIG_REG_LLH0_ACPI_PAT_0_CRC
, 68, 0xffffffff },
1549 { BNX2X_CHIP_MASK_ALL
,
1550 NIG_REG_LLH0_DEST_MAC_0_0
, 160, 0xffffffff },
1551 { BNX2X_CHIP_MASK_ALL
,
1552 NIG_REG_LLH0_DEST_IP_0_1
, 160, 0xffffffff },
1553 { BNX2X_CHIP_MASK_ALL
,
1554 NIG_REG_LLH0_IPV4_IPV6_0
, 160, 0x00000001 },
1555 /* 30 */ { BNX2X_CHIP_MASK_ALL
,
1556 NIG_REG_LLH0_DEST_UDP_0
, 160, 0x0000ffff },
1557 { BNX2X_CHIP_MASK_ALL
,
1558 NIG_REG_LLH0_DEST_TCP_0
, 160, 0x0000ffff },
1559 { BNX2X_CHIP_MASK_ALL
,
1560 NIG_REG_LLH0_VLAN_ID_0
, 160, 0x00000fff },
1561 { BNX2X_CHIP_MASK_E1X
| BNX2X_CHIP_MASK_E2
,
1562 NIG_REG_XGXS_SERDES0_MODE_SEL
, 4, 0x00000001 },
1563 { BNX2X_CHIP_MASK_ALL
,
1564 NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0
, 4, 0x00000001},
1565 { BNX2X_CHIP_MASK_ALL
,
1566 NIG_REG_STATUS_INTERRUPT_PORT0
, 4, 0x07ffffff },
1567 { BNX2X_CHIP_MASK_E1X
| BNX2X_CHIP_MASK_E2
,
1568 NIG_REG_XGXS0_CTRL_EXTREMOTEMDIOST
, 24, 0x00000001 },
1569 { BNX2X_CHIP_MASK_E1X
| BNX2X_CHIP_MASK_E2
,
1570 NIG_REG_SERDES0_CTRL_PHY_ADDR
, 16, 0x0000001f },
1572 { BNX2X_CHIP_MASK_ALL
, 0xffffffff, 0, 0x00000000 }
1575 if (!netif_running(bp
->dev
))
1579 hw
= BNX2X_CHIP_MASK_E1
;
1580 else if (CHIP_IS_E1H(bp
))
1581 hw
= BNX2X_CHIP_MASK_E1H
;
1582 else if (CHIP_IS_E2(bp
))
1583 hw
= BNX2X_CHIP_MASK_E2
;
1584 else if (CHIP_IS_E3B0(bp
))
1585 hw
= BNX2X_CHIP_MASK_E3B0
;
1587 hw
= BNX2X_CHIP_MASK_E3
;
1589 /* Repeat the test twice:
1590 First by writing 0x00000000, second by writing 0xffffffff */
1591 for (idx
= 0; idx
< 2; idx
++) {
1598 wr_val
= 0xffffffff;
1602 for (i
= 0; reg_tbl
[i
].offset0
!= 0xffffffff; i
++) {
1603 u32 offset
, mask
, save_val
, val
;
1604 if (!(hw
& reg_tbl
[i
].hw
))
1607 offset
= reg_tbl
[i
].offset0
+ port
*reg_tbl
[i
].offset1
;
1608 mask
= reg_tbl
[i
].mask
;
1610 save_val
= REG_RD(bp
, offset
);
1612 REG_WR(bp
, offset
, wr_val
& mask
);
1614 val
= REG_RD(bp
, offset
);
1616 /* Restore the original register's value */
1617 REG_WR(bp
, offset
, save_val
);
1619 /* verify value is as expected */
1620 if ((val
& mask
) != (wr_val
& mask
)) {
1622 "offset 0x%x: val 0x%x != 0x%x mask 0x%x\n",
1623 offset
, val
, wr_val
, mask
);
1635 static int bnx2x_test_memory(struct bnx2x
*bp
)
1637 int i
, j
, rc
= -ENODEV
;
1639 static const struct {
1643 { CCM_REG_XX_DESCR_TABLE
, CCM_REG_XX_DESCR_TABLE_SIZE
},
1644 { CFC_REG_ACTIVITY_COUNTER
, CFC_REG_ACTIVITY_COUNTER_SIZE
},
1645 { CFC_REG_LINK_LIST
, CFC_REG_LINK_LIST_SIZE
},
1646 { DMAE_REG_CMD_MEM
, DMAE_REG_CMD_MEM_SIZE
},
1647 { TCM_REG_XX_DESCR_TABLE
, TCM_REG_XX_DESCR_TABLE_SIZE
},
1648 { UCM_REG_XX_DESCR_TABLE
, UCM_REG_XX_DESCR_TABLE_SIZE
},
1649 { XCM_REG_XX_DESCR_TABLE
, XCM_REG_XX_DESCR_TABLE_SIZE
},
1654 static const struct {
1657 u32 hw_mask
[BNX2X_CHIP_MAX_OFST
];
1659 { "CCM_PRTY_STS", CCM_REG_CCM_PRTY_STS
,
1660 {0x3ffc0, 0, 0, 0} },
1661 { "CFC_PRTY_STS", CFC_REG_CFC_PRTY_STS
,
1663 { "DMAE_PRTY_STS", DMAE_REG_DMAE_PRTY_STS
,
1665 { "TCM_PRTY_STS", TCM_REG_TCM_PRTY_STS
,
1666 {0x3ffc0, 0, 0, 0} },
1667 { "UCM_PRTY_STS", UCM_REG_UCM_PRTY_STS
,
1668 {0x3ffc0, 0, 0, 0} },
1669 { "XCM_PRTY_STS", XCM_REG_XCM_PRTY_STS
,
1670 {0x3ffc1, 0, 0, 0} },
1672 { NULL
, 0xffffffff, {0, 0, 0, 0} }
1675 if (!netif_running(bp
->dev
))
1679 index
= BNX2X_CHIP_E1_OFST
;
1680 else if (CHIP_IS_E1H(bp
))
1681 index
= BNX2X_CHIP_E1H_OFST
;
1682 else if (CHIP_IS_E2(bp
))
1683 index
= BNX2X_CHIP_E2_OFST
;
1685 index
= BNX2X_CHIP_E3_OFST
;
1687 /* pre-Check the parity status */
1688 for (i
= 0; prty_tbl
[i
].offset
!= 0xffffffff; i
++) {
1689 val
= REG_RD(bp
, prty_tbl
[i
].offset
);
1690 if (val
& ~(prty_tbl
[i
].hw_mask
[index
])) {
1692 "%s is 0x%x\n", prty_tbl
[i
].name
, val
);
1697 /* Go through all the memories */
1698 for (i
= 0; mem_tbl
[i
].offset
!= 0xffffffff; i
++)
1699 for (j
= 0; j
< mem_tbl
[i
].size
; j
++)
1700 REG_RD(bp
, mem_tbl
[i
].offset
+ j
*4);
1702 /* Check the parity status */
1703 for (i
= 0; prty_tbl
[i
].offset
!= 0xffffffff; i
++) {
1704 val
= REG_RD(bp
, prty_tbl
[i
].offset
);
1705 if (val
& ~(prty_tbl
[i
].hw_mask
[index
])) {
1707 "%s is 0x%x\n", prty_tbl
[i
].name
, val
);
1718 static void bnx2x_wait_for_link(struct bnx2x
*bp
, u8 link_up
, u8 is_serdes
)
1723 while (bnx2x_link_test(bp
, is_serdes
) && cnt
--)
1726 if (cnt
<= 0 && bnx2x_link_test(bp
, is_serdes
))
1727 DP(NETIF_MSG_LINK
, "Timeout waiting for link up\n");
1731 static int bnx2x_run_loopback(struct bnx2x
*bp
, int loopback_mode
)
1733 unsigned int pkt_size
, num_pkts
, i
;
1734 struct sk_buff
*skb
;
1735 unsigned char *packet
;
1736 struct bnx2x_fastpath
*fp_rx
= &bp
->fp
[0];
1737 struct bnx2x_fastpath
*fp_tx
= &bp
->fp
[0];
1738 struct bnx2x_fp_txdata
*txdata
= &fp_tx
->txdata
[0];
1739 u16 tx_start_idx
, tx_idx
;
1740 u16 rx_start_idx
, rx_idx
;
1741 u16 pkt_prod
, bd_prod
;
1742 struct sw_tx_bd
*tx_buf
;
1743 struct eth_tx_start_bd
*tx_start_bd
;
1744 struct eth_tx_parse_bd_e1x
*pbd_e1x
= NULL
;
1745 struct eth_tx_parse_bd_e2
*pbd_e2
= NULL
;
1747 union eth_rx_cqe
*cqe
;
1748 u8 cqe_fp_flags
, cqe_fp_type
;
1749 struct sw_rx_bd
*rx_buf
;
1753 struct netdev_queue
*txq
= netdev_get_tx_queue(bp
->dev
, txdata
->txq_index
);
1755 /* check the loopback mode */
1756 switch (loopback_mode
) {
1757 case BNX2X_PHY_LOOPBACK
:
1758 if (bp
->link_params
.loopback_mode
!= LOOPBACK_XGXS
)
1761 case BNX2X_MAC_LOOPBACK
:
1762 if (CHIP_IS_E3(bp
)) {
1763 int cfg_idx
= bnx2x_get_link_cfg_idx(bp
);
1764 if (bp
->port
.supported
[cfg_idx
] &
1765 (SUPPORTED_10000baseT_Full
|
1766 SUPPORTED_20000baseMLD2_Full
|
1767 SUPPORTED_20000baseKR2_Full
))
1768 bp
->link_params
.loopback_mode
= LOOPBACK_XMAC
;
1770 bp
->link_params
.loopback_mode
= LOOPBACK_UMAC
;
1772 bp
->link_params
.loopback_mode
= LOOPBACK_BMAC
;
1774 bnx2x_phy_init(&bp
->link_params
, &bp
->link_vars
);
1780 /* prepare the loopback packet */
1781 pkt_size
= (((bp
->dev
->mtu
< ETH_MAX_PACKET_SIZE
) ?
1782 bp
->dev
->mtu
: ETH_MAX_PACKET_SIZE
) + ETH_HLEN
);
1783 skb
= netdev_alloc_skb(bp
->dev
, fp_rx
->rx_buf_size
);
1786 goto test_loopback_exit
;
1788 packet
= skb_put(skb
, pkt_size
);
1789 memcpy(packet
, bp
->dev
->dev_addr
, ETH_ALEN
);
1790 memset(packet
+ ETH_ALEN
, 0, ETH_ALEN
);
1791 memset(packet
+ 2*ETH_ALEN
, 0x77, (ETH_HLEN
- 2*ETH_ALEN
));
1792 for (i
= ETH_HLEN
; i
< pkt_size
; i
++)
1793 packet
[i
] = (unsigned char) (i
& 0xff);
1794 mapping
= dma_map_single(&bp
->pdev
->dev
, skb
->data
,
1795 skb_headlen(skb
), DMA_TO_DEVICE
);
1796 if (unlikely(dma_mapping_error(&bp
->pdev
->dev
, mapping
))) {
1799 BNX2X_ERR("Unable to map SKB\n");
1800 goto test_loopback_exit
;
1803 /* send the loopback packet */
1805 tx_start_idx
= le16_to_cpu(*txdata
->tx_cons_sb
);
1806 rx_start_idx
= le16_to_cpu(*fp_rx
->rx_cons_sb
);
1808 netdev_tx_sent_queue(txq
, skb
->len
);
1810 pkt_prod
= txdata
->tx_pkt_prod
++;
1811 tx_buf
= &txdata
->tx_buf_ring
[TX_BD(pkt_prod
)];
1812 tx_buf
->first_bd
= txdata
->tx_bd_prod
;
1816 bd_prod
= TX_BD(txdata
->tx_bd_prod
);
1817 tx_start_bd
= &txdata
->tx_desc_ring
[bd_prod
].start_bd
;
1818 tx_start_bd
->addr_hi
= cpu_to_le32(U64_HI(mapping
));
1819 tx_start_bd
->addr_lo
= cpu_to_le32(U64_LO(mapping
));
1820 tx_start_bd
->nbd
= cpu_to_le16(2); /* start + pbd */
1821 tx_start_bd
->nbytes
= cpu_to_le16(skb_headlen(skb
));
1822 tx_start_bd
->vlan_or_ethertype
= cpu_to_le16(pkt_prod
);
1823 tx_start_bd
->bd_flags
.as_bitfield
= ETH_TX_BD_FLAGS_START_BD
;
1824 SET_FLAG(tx_start_bd
->general_data
,
1825 ETH_TX_START_BD_ETH_ADDR_TYPE
,
1827 SET_FLAG(tx_start_bd
->general_data
,
1828 ETH_TX_START_BD_HDR_NBDS
,
1831 /* turn on parsing and get a BD */
1832 bd_prod
= TX_BD(NEXT_TX_IDX(bd_prod
));
1834 pbd_e1x
= &txdata
->tx_desc_ring
[bd_prod
].parse_bd_e1x
;
1835 pbd_e2
= &txdata
->tx_desc_ring
[bd_prod
].parse_bd_e2
;
1837 memset(pbd_e2
, 0, sizeof(struct eth_tx_parse_bd_e2
));
1838 memset(pbd_e1x
, 0, sizeof(struct eth_tx_parse_bd_e1x
));
1842 txdata
->tx_db
.data
.prod
+= 2;
1844 DOORBELL(bp
, txdata
->cid
, txdata
->tx_db
.raw
);
1850 txdata
->tx_bd_prod
+= 2; /* start + pbd */
1854 tx_idx
= le16_to_cpu(*txdata
->tx_cons_sb
);
1855 if (tx_idx
!= tx_start_idx
+ num_pkts
)
1856 goto test_loopback_exit
;
1858 /* Unlike HC IGU won't generate an interrupt for status block
1859 * updates that have been performed while interrupts were
1862 if (bp
->common
.int_block
== INT_BLOCK_IGU
) {
1863 /* Disable local BHes to prevent a dead-lock situation between
1864 * sch_direct_xmit() and bnx2x_run_loopback() (calling
1865 * bnx2x_tx_int()), as both are taking netif_tx_lock().
1868 bnx2x_tx_int(bp
, txdata
);
1872 rx_idx
= le16_to_cpu(*fp_rx
->rx_cons_sb
);
1873 if (rx_idx
!= rx_start_idx
+ num_pkts
)
1874 goto test_loopback_exit
;
1876 cqe
= &fp_rx
->rx_comp_ring
[RCQ_BD(fp_rx
->rx_comp_cons
)];
1877 cqe_fp_flags
= cqe
->fast_path_cqe
.type_error_flags
;
1878 cqe_fp_type
= cqe_fp_flags
& ETH_FAST_PATH_RX_CQE_TYPE
;
1879 if (!CQE_TYPE_FAST(cqe_fp_type
) || (cqe_fp_flags
& ETH_RX_ERROR_FALGS
))
1880 goto test_loopback_rx_exit
;
1882 len
= le16_to_cpu(cqe
->fast_path_cqe
.pkt_len
);
1883 if (len
!= pkt_size
)
1884 goto test_loopback_rx_exit
;
1886 rx_buf
= &fp_rx
->rx_buf_ring
[RX_BD(fp_rx
->rx_bd_cons
)];
1887 dma_sync_single_for_cpu(&bp
->pdev
->dev
,
1888 dma_unmap_addr(rx_buf
, mapping
),
1889 fp_rx
->rx_buf_size
, DMA_FROM_DEVICE
);
1890 data
= rx_buf
->data
+ NET_SKB_PAD
+ cqe
->fast_path_cqe
.placement_offset
;
1891 for (i
= ETH_HLEN
; i
< pkt_size
; i
++)
1892 if (*(data
+ i
) != (unsigned char) (i
& 0xff))
1893 goto test_loopback_rx_exit
;
1897 test_loopback_rx_exit
:
1899 fp_rx
->rx_bd_cons
= NEXT_RX_IDX(fp_rx
->rx_bd_cons
);
1900 fp_rx
->rx_bd_prod
= NEXT_RX_IDX(fp_rx
->rx_bd_prod
);
1901 fp_rx
->rx_comp_cons
= NEXT_RCQ_IDX(fp_rx
->rx_comp_cons
);
1902 fp_rx
->rx_comp_prod
= NEXT_RCQ_IDX(fp_rx
->rx_comp_prod
);
1904 /* Update producers */
1905 bnx2x_update_rx_prod(bp
, fp_rx
, fp_rx
->rx_bd_prod
, fp_rx
->rx_comp_prod
,
1906 fp_rx
->rx_sge_prod
);
1909 bp
->link_params
.loopback_mode
= LOOPBACK_NONE
;
1914 static int bnx2x_test_loopback(struct bnx2x
*bp
)
1921 if (!netif_running(bp
->dev
))
1922 return BNX2X_LOOPBACK_FAILED
;
1924 bnx2x_netif_stop(bp
, 1);
1925 bnx2x_acquire_phy_lock(bp
);
1927 res
= bnx2x_run_loopback(bp
, BNX2X_PHY_LOOPBACK
);
1929 DP(NETIF_MSG_PROBE
, " PHY loopback failed (res %d)\n", res
);
1930 rc
|= BNX2X_PHY_LOOPBACK_FAILED
;
1933 res
= bnx2x_run_loopback(bp
, BNX2X_MAC_LOOPBACK
);
1935 DP(NETIF_MSG_PROBE
, " MAC loopback failed (res %d)\n", res
);
1936 rc
|= BNX2X_MAC_LOOPBACK_FAILED
;
1939 bnx2x_release_phy_lock(bp
);
1940 bnx2x_netif_start(bp
);
1945 #define CRC32_RESIDUAL 0xdebb20e3
1947 static int bnx2x_test_nvram(struct bnx2x
*bp
)
1949 static const struct {
1953 { 0, 0x14 }, /* bootstrap */
1954 { 0x14, 0xec }, /* dir */
1955 { 0x100, 0x350 }, /* manuf_info */
1956 { 0x450, 0xf0 }, /* feature_info */
1957 { 0x640, 0x64 }, /* upgrade_key_info */
1958 { 0x708, 0x70 }, /* manuf_key_info */
1961 __be32 buf
[0x350 / 4];
1962 u8
*data
= (u8
*)buf
;
1969 rc
= bnx2x_nvram_read(bp
, 0, data
, 4);
1971 DP(NETIF_MSG_PROBE
, "magic value read (rc %d)\n", rc
);
1972 goto test_nvram_exit
;
1975 magic
= be32_to_cpu(buf
[0]);
1976 if (magic
!= 0x669955aa) {
1977 DP(NETIF_MSG_PROBE
, "magic value (0x%08x)\n", magic
);
1979 goto test_nvram_exit
;
1982 for (i
= 0; nvram_tbl
[i
].size
; i
++) {
1984 rc
= bnx2x_nvram_read(bp
, nvram_tbl
[i
].offset
, data
,
1988 "nvram_tbl[%d] read data (rc %d)\n", i
, rc
);
1989 goto test_nvram_exit
;
1992 crc
= ether_crc_le(nvram_tbl
[i
].size
, data
);
1993 if (crc
!= CRC32_RESIDUAL
) {
1995 "nvram_tbl[%d] crc value (0x%08x)\n", i
, crc
);
1997 goto test_nvram_exit
;
2005 /* Send an EMPTY ramrod on the first queue */
2006 static int bnx2x_test_intr(struct bnx2x
*bp
)
2008 struct bnx2x_queue_state_params params
= {0};
2010 if (!netif_running(bp
->dev
))
2013 params
.q_obj
= &bp
->fp
->q_obj
;
2014 params
.cmd
= BNX2X_Q_CMD_EMPTY
;
2016 __set_bit(RAMROD_COMP_WAIT
, ¶ms
.ramrod_flags
);
2018 return bnx2x_queue_state_change(bp
, ¶ms
);
2021 static void bnx2x_self_test(struct net_device
*dev
,
2022 struct ethtool_test
*etest
, u64
*buf
)
2024 struct bnx2x
*bp
= netdev_priv(dev
);
2026 if (bp
->recovery_state
!= BNX2X_RECOVERY_DONE
) {
2027 pr_err("Handling parity error recovery. Try again later\n");
2028 etest
->flags
|= ETH_TEST_FL_FAILED
;
2032 memset(buf
, 0, sizeof(u64
) * BNX2X_NUM_TESTS
);
2034 if (!netif_running(dev
))
2037 /* offline tests are not supported in MF mode */
2039 etest
->flags
&= ~ETH_TEST_FL_OFFLINE
;
2040 is_serdes
= (bp
->link_vars
.link_status
& LINK_STATUS_SERDES_LINK
) > 0;
2042 if (etest
->flags
& ETH_TEST_FL_OFFLINE
) {
2043 int port
= BP_PORT(bp
);
2047 /* save current value of input enable for TX port IF */
2048 val
= REG_RD(bp
, NIG_REG_EGRESS_UMP0_IN_EN
+ port
*4);
2049 /* disable input for TX port IF */
2050 REG_WR(bp
, NIG_REG_EGRESS_UMP0_IN_EN
+ port
*4, 0);
2052 link_up
= bp
->link_vars
.link_up
;
2054 bnx2x_nic_unload(bp
, UNLOAD_NORMAL
);
2055 bnx2x_nic_load(bp
, LOAD_DIAG
);
2056 /* wait until link state is restored */
2057 bnx2x_wait_for_link(bp
, 1, is_serdes
);
2059 if (bnx2x_test_registers(bp
) != 0) {
2061 etest
->flags
|= ETH_TEST_FL_FAILED
;
2063 if (bnx2x_test_memory(bp
) != 0) {
2065 etest
->flags
|= ETH_TEST_FL_FAILED
;
2068 buf
[2] = bnx2x_test_loopback(bp
);
2070 etest
->flags
|= ETH_TEST_FL_FAILED
;
2072 bnx2x_nic_unload(bp
, UNLOAD_NORMAL
);
2074 /* restore input for TX port IF */
2075 REG_WR(bp
, NIG_REG_EGRESS_UMP0_IN_EN
+ port
*4, val
);
2077 bnx2x_nic_load(bp
, LOAD_NORMAL
);
2078 /* wait until link state is restored */
2079 bnx2x_wait_for_link(bp
, link_up
, is_serdes
);
2081 if (bnx2x_test_nvram(bp
) != 0) {
2083 etest
->flags
|= ETH_TEST_FL_FAILED
;
2085 if (bnx2x_test_intr(bp
) != 0) {
2087 etest
->flags
|= ETH_TEST_FL_FAILED
;
2090 if (bnx2x_link_test(bp
, is_serdes
) != 0) {
2092 etest
->flags
|= ETH_TEST_FL_FAILED
;
2095 #ifdef BNX2X_EXTRA_DEBUG
2096 bnx2x_panic_dump(bp
);
2100 #define IS_PORT_STAT(i) \
2101 ((bnx2x_stats_arr[i].flags & STATS_FLAGS_BOTH) == STATS_FLAGS_PORT)
2102 #define IS_FUNC_STAT(i) (bnx2x_stats_arr[i].flags & STATS_FLAGS_FUNC)
2103 #define IS_MF_MODE_STAT(bp) \
2104 (IS_MF(bp) && !(bp->msg_enable & BNX2X_MSG_STATS))
2106 /* ethtool statistics are displayed for all regular ethernet queues and the
2107 * fcoe L2 queue if not disabled
2109 static inline int bnx2x_num_stat_queues(struct bnx2x
*bp
)
2111 return BNX2X_NUM_ETH_QUEUES(bp
);
2114 static int bnx2x_get_sset_count(struct net_device
*dev
, int stringset
)
2116 struct bnx2x
*bp
= netdev_priv(dev
);
2119 switch (stringset
) {
2122 num_stats
= bnx2x_num_stat_queues(bp
) *
2126 if (IS_MF_MODE_STAT(bp
)) {
2127 for (i
= 0; i
< BNX2X_NUM_STATS
; i
++)
2128 if (IS_FUNC_STAT(i
))
2131 num_stats
+= BNX2X_NUM_STATS
;
2136 return BNX2X_NUM_TESTS
;
2143 static void bnx2x_get_strings(struct net_device
*dev
, u32 stringset
, u8
*buf
)
2145 struct bnx2x
*bp
= netdev_priv(dev
);
2147 char queue_name
[MAX_QUEUE_NAME_LEN
+1];
2149 switch (stringset
) {
2153 for_each_eth_queue(bp
, i
) {
2154 memset(queue_name
, 0, sizeof(queue_name
));
2155 sprintf(queue_name
, "%d", i
);
2156 for (j
= 0; j
< BNX2X_NUM_Q_STATS
; j
++)
2157 snprintf(buf
+ (k
+ j
)*ETH_GSTRING_LEN
,
2159 bnx2x_q_stats_arr
[j
].string
,
2161 k
+= BNX2X_NUM_Q_STATS
;
2166 for (i
= 0, j
= 0; i
< BNX2X_NUM_STATS
; i
++) {
2167 if (IS_MF_MODE_STAT(bp
) && IS_PORT_STAT(i
))
2169 strcpy(buf
+ (k
+ j
)*ETH_GSTRING_LEN
,
2170 bnx2x_stats_arr
[i
].string
);
2177 memcpy(buf
, bnx2x_tests_str_arr
, sizeof(bnx2x_tests_str_arr
));
2182 static void bnx2x_get_ethtool_stats(struct net_device
*dev
,
2183 struct ethtool_stats
*stats
, u64
*buf
)
2185 struct bnx2x
*bp
= netdev_priv(dev
);
2186 u32
*hw_stats
, *offset
;
2190 for_each_eth_queue(bp
, i
) {
2191 hw_stats
= (u32
*)&bp
->fp
[i
].eth_q_stats
;
2192 for (j
= 0; j
< BNX2X_NUM_Q_STATS
; j
++) {
2193 if (bnx2x_q_stats_arr
[j
].size
== 0) {
2194 /* skip this counter */
2198 offset
= (hw_stats
+
2199 bnx2x_q_stats_arr
[j
].offset
);
2200 if (bnx2x_q_stats_arr
[j
].size
== 4) {
2201 /* 4-byte counter */
2202 buf
[k
+ j
] = (u64
) *offset
;
2205 /* 8-byte counter */
2206 buf
[k
+ j
] = HILO_U64(*offset
, *(offset
+ 1));
2208 k
+= BNX2X_NUM_Q_STATS
;
2212 hw_stats
= (u32
*)&bp
->eth_stats
;
2213 for (i
= 0, j
= 0; i
< BNX2X_NUM_STATS
; i
++) {
2214 if (IS_MF_MODE_STAT(bp
) && IS_PORT_STAT(i
))
2216 if (bnx2x_stats_arr
[i
].size
== 0) {
2217 /* skip this counter */
2222 offset
= (hw_stats
+ bnx2x_stats_arr
[i
].offset
);
2223 if (bnx2x_stats_arr
[i
].size
== 4) {
2224 /* 4-byte counter */
2225 buf
[k
+ j
] = (u64
) *offset
;
2229 /* 8-byte counter */
2230 buf
[k
+ j
] = HILO_U64(*offset
, *(offset
+ 1));
2235 static int bnx2x_set_phys_id(struct net_device
*dev
,
2236 enum ethtool_phys_id_state state
)
2238 struct bnx2x
*bp
= netdev_priv(dev
);
2240 if (!netif_running(dev
))
2247 case ETHTOOL_ID_ACTIVE
:
2248 return 1; /* cycle on/off once per second */
2251 bnx2x_set_led(&bp
->link_params
, &bp
->link_vars
,
2252 LED_MODE_ON
, SPEED_1000
);
2255 case ETHTOOL_ID_OFF
:
2256 bnx2x_set_led(&bp
->link_params
, &bp
->link_vars
,
2257 LED_MODE_FRONT_PANEL_OFF
, 0);
2261 case ETHTOOL_ID_INACTIVE
:
2262 bnx2x_set_led(&bp
->link_params
, &bp
->link_vars
,
2264 bp
->link_vars
.line_speed
);
2270 static int bnx2x_get_rxnfc(struct net_device
*dev
, struct ethtool_rxnfc
*info
,
2271 u32
*rules __always_unused
)
2273 struct bnx2x
*bp
= netdev_priv(dev
);
2275 switch (info
->cmd
) {
2276 case ETHTOOL_GRXRINGS
:
2277 info
->data
= BNX2X_NUM_ETH_QUEUES(bp
);
2285 static u32
bnx2x_get_rxfh_indir_size(struct net_device
*dev
)
2287 struct bnx2x
*bp
= netdev_priv(dev
);
2289 return (bp
->multi_mode
== ETH_RSS_MODE_DISABLED
?
2290 0 : T_ETH_INDIRECTION_TABLE_SIZE
);
2293 static int bnx2x_get_rxfh_indir(struct net_device
*dev
, u32
*indir
)
2295 struct bnx2x
*bp
= netdev_priv(dev
);
2296 u8 ind_table
[T_ETH_INDIRECTION_TABLE_SIZE
] = {0};
2299 /* Get the current configuration of the RSS indirection table */
2300 bnx2x_get_rss_ind_table(&bp
->rss_conf_obj
, ind_table
);
2303 * We can't use a memcpy() as an internal storage of an
2304 * indirection table is a u8 array while indir->ring_index
2305 * points to an array of u32.
2307 * Indirection table contains the FW Client IDs, so we need to
2308 * align the returned table to the Client ID of the leading RSS
2311 for (i
= 0; i
< T_ETH_INDIRECTION_TABLE_SIZE
; i
++)
2312 indir
[i
] = ind_table
[i
] - bp
->fp
->cl_id
;
2317 static int bnx2x_set_rxfh_indir(struct net_device
*dev
, const u32
*indir
)
2319 struct bnx2x
*bp
= netdev_priv(dev
);
2321 u8 ind_table
[T_ETH_INDIRECTION_TABLE_SIZE
] = {0};
2323 for (i
= 0; i
< T_ETH_INDIRECTION_TABLE_SIZE
; i
++) {
2325 * The same as in bnx2x_get_rxfh_indir: we can't use a memcpy()
2326 * as an internal storage of an indirection table is a u8 array
2327 * while indir->ring_index points to an array of u32.
2329 * Indirection table contains the FW Client IDs, so we need to
2330 * align the received table to the Client ID of the leading RSS
2333 ind_table
[i
] = indir
[i
] + bp
->fp
->cl_id
;
2336 return bnx2x_config_rss_pf(bp
, ind_table
, false);
2339 static const struct ethtool_ops bnx2x_ethtool_ops
= {
2340 .get_settings
= bnx2x_get_settings
,
2341 .set_settings
= bnx2x_set_settings
,
2342 .get_drvinfo
= bnx2x_get_drvinfo
,
2343 .get_regs_len
= bnx2x_get_regs_len
,
2344 .get_regs
= bnx2x_get_regs
,
2345 .get_wol
= bnx2x_get_wol
,
2346 .set_wol
= bnx2x_set_wol
,
2347 .get_msglevel
= bnx2x_get_msglevel
,
2348 .set_msglevel
= bnx2x_set_msglevel
,
2349 .nway_reset
= bnx2x_nway_reset
,
2350 .get_link
= bnx2x_get_link
,
2351 .get_eeprom_len
= bnx2x_get_eeprom_len
,
2352 .get_eeprom
= bnx2x_get_eeprom
,
2353 .set_eeprom
= bnx2x_set_eeprom
,
2354 .get_coalesce
= bnx2x_get_coalesce
,
2355 .set_coalesce
= bnx2x_set_coalesce
,
2356 .get_ringparam
= bnx2x_get_ringparam
,
2357 .set_ringparam
= bnx2x_set_ringparam
,
2358 .get_pauseparam
= bnx2x_get_pauseparam
,
2359 .set_pauseparam
= bnx2x_set_pauseparam
,
2360 .self_test
= bnx2x_self_test
,
2361 .get_sset_count
= bnx2x_get_sset_count
,
2362 .get_strings
= bnx2x_get_strings
,
2363 .set_phys_id
= bnx2x_set_phys_id
,
2364 .get_ethtool_stats
= bnx2x_get_ethtool_stats
,
2365 .get_rxnfc
= bnx2x_get_rxnfc
,
2366 .get_rxfh_indir_size
= bnx2x_get_rxfh_indir_size
,
2367 .get_rxfh_indir
= bnx2x_get_rxfh_indir
,
2368 .set_rxfh_indir
= bnx2x_set_rxfh_indir
,
2371 void bnx2x_set_ethtool_ops(struct net_device
*netdev
)
2373 SET_ETHTOOL_OPS(netdev
, &bnx2x_ethtool_ops
);