1 /* bnx2x_ethtool.c: Broadcom Everest network driver.
3 * Copyright (c) 2007-2010 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
17 #include <linux/ethtool.h>
18 #include <linux/netdevice.h>
19 #include <linux/types.h>
20 #include <linux/sched.h>
21 #include <linux/crc32.h>
25 #include "bnx2x_cmn.h"
26 #include "bnx2x_dump.h"
27 #include "bnx2x_init.h"
29 /* Note: in the format strings below %s is replaced by the queue-name which is
30 * either its index or 'fcoe' for the fcoe queue. Make sure the format string
31 * length does not exceed ETH_GSTRING_LEN - MAX_QUEUE_NAME_LEN + 2
33 #define MAX_QUEUE_NAME_LEN 4
37 char string
[ETH_GSTRING_LEN
];
38 } bnx2x_q_stats_arr
[] = {
39 /* 1 */ { Q_STATS_OFFSET32(total_bytes_received_hi
), 8, "[%s]: rx_bytes" },
40 { Q_STATS_OFFSET32(error_bytes_received_hi
),
41 8, "[%s]: rx_error_bytes" },
42 { Q_STATS_OFFSET32(total_unicast_packets_received_hi
),
43 8, "[%s]: rx_ucast_packets" },
44 { Q_STATS_OFFSET32(total_multicast_packets_received_hi
),
45 8, "[%s]: rx_mcast_packets" },
46 { Q_STATS_OFFSET32(total_broadcast_packets_received_hi
),
47 8, "[%s]: rx_bcast_packets" },
48 { Q_STATS_OFFSET32(no_buff_discard_hi
), 8, "[%s]: rx_discards" },
49 { Q_STATS_OFFSET32(rx_err_discard_pkt
),
50 4, "[%s]: rx_phy_ip_err_discards"},
51 { Q_STATS_OFFSET32(rx_skb_alloc_failed
),
52 4, "[%s]: rx_skb_alloc_discard" },
53 { Q_STATS_OFFSET32(hw_csum_err
), 4, "[%s]: rx_csum_offload_errors" },
55 /* 10 */{ Q_STATS_OFFSET32(total_bytes_transmitted_hi
), 8, "[%s]: tx_bytes" },
56 { Q_STATS_OFFSET32(total_unicast_packets_transmitted_hi
),
57 8, "[%s]: tx_ucast_packets" },
58 { Q_STATS_OFFSET32(total_multicast_packets_transmitted_hi
),
59 8, "[%s]: tx_mcast_packets" },
60 { Q_STATS_OFFSET32(total_broadcast_packets_transmitted_hi
),
61 8, "[%s]: tx_bcast_packets" }
64 #define BNX2X_NUM_Q_STATS ARRAY_SIZE(bnx2x_q_stats_arr)
70 #define STATS_FLAGS_PORT 1
71 #define STATS_FLAGS_FUNC 2
72 #define STATS_FLAGS_BOTH (STATS_FLAGS_FUNC | STATS_FLAGS_PORT)
73 char string
[ETH_GSTRING_LEN
];
74 } bnx2x_stats_arr
[] = {
75 /* 1 */ { STATS_OFFSET32(total_bytes_received_hi
),
76 8, STATS_FLAGS_BOTH
, "rx_bytes" },
77 { STATS_OFFSET32(error_bytes_received_hi
),
78 8, STATS_FLAGS_BOTH
, "rx_error_bytes" },
79 { STATS_OFFSET32(total_unicast_packets_received_hi
),
80 8, STATS_FLAGS_BOTH
, "rx_ucast_packets" },
81 { STATS_OFFSET32(total_multicast_packets_received_hi
),
82 8, STATS_FLAGS_BOTH
, "rx_mcast_packets" },
83 { STATS_OFFSET32(total_broadcast_packets_received_hi
),
84 8, STATS_FLAGS_BOTH
, "rx_bcast_packets" },
85 { STATS_OFFSET32(rx_stat_dot3statsfcserrors_hi
),
86 8, STATS_FLAGS_PORT
, "rx_crc_errors" },
87 { STATS_OFFSET32(rx_stat_dot3statsalignmenterrors_hi
),
88 8, STATS_FLAGS_PORT
, "rx_align_errors" },
89 { STATS_OFFSET32(rx_stat_etherstatsundersizepkts_hi
),
90 8, STATS_FLAGS_PORT
, "rx_undersize_packets" },
91 { STATS_OFFSET32(etherstatsoverrsizepkts_hi
),
92 8, STATS_FLAGS_PORT
, "rx_oversize_packets" },
93 /* 10 */{ STATS_OFFSET32(rx_stat_etherstatsfragments_hi
),
94 8, STATS_FLAGS_PORT
, "rx_fragments" },
95 { STATS_OFFSET32(rx_stat_etherstatsjabbers_hi
),
96 8, STATS_FLAGS_PORT
, "rx_jabbers" },
97 { STATS_OFFSET32(no_buff_discard_hi
),
98 8, STATS_FLAGS_BOTH
, "rx_discards" },
99 { STATS_OFFSET32(mac_filter_discard
),
100 4, STATS_FLAGS_PORT
, "rx_filtered_packets" },
101 { STATS_OFFSET32(xxoverflow_discard
),
102 4, STATS_FLAGS_PORT
, "rx_fw_discards" },
103 { STATS_OFFSET32(brb_drop_hi
),
104 8, STATS_FLAGS_PORT
, "rx_brb_discard" },
105 { STATS_OFFSET32(brb_truncate_hi
),
106 8, STATS_FLAGS_PORT
, "rx_brb_truncate" },
107 { STATS_OFFSET32(pause_frames_received_hi
),
108 8, STATS_FLAGS_PORT
, "rx_pause_frames" },
109 { STATS_OFFSET32(rx_stat_maccontrolframesreceived_hi
),
110 8, STATS_FLAGS_PORT
, "rx_mac_ctrl_frames" },
111 { STATS_OFFSET32(nig_timer_max
),
112 4, STATS_FLAGS_PORT
, "rx_constant_pause_events" },
113 /* 20 */{ STATS_OFFSET32(rx_err_discard_pkt
),
114 4, STATS_FLAGS_BOTH
, "rx_phy_ip_err_discards"},
115 { STATS_OFFSET32(rx_skb_alloc_failed
),
116 4, STATS_FLAGS_BOTH
, "rx_skb_alloc_discard" },
117 { STATS_OFFSET32(hw_csum_err
),
118 4, STATS_FLAGS_BOTH
, "rx_csum_offload_errors" },
120 { STATS_OFFSET32(total_bytes_transmitted_hi
),
121 8, STATS_FLAGS_BOTH
, "tx_bytes" },
122 { STATS_OFFSET32(tx_stat_ifhcoutbadoctets_hi
),
123 8, STATS_FLAGS_PORT
, "tx_error_bytes" },
124 { STATS_OFFSET32(total_unicast_packets_transmitted_hi
),
125 8, STATS_FLAGS_BOTH
, "tx_ucast_packets" },
126 { STATS_OFFSET32(total_multicast_packets_transmitted_hi
),
127 8, STATS_FLAGS_BOTH
, "tx_mcast_packets" },
128 { STATS_OFFSET32(total_broadcast_packets_transmitted_hi
),
129 8, STATS_FLAGS_BOTH
, "tx_bcast_packets" },
130 { STATS_OFFSET32(tx_stat_dot3statsinternalmactransmiterrors_hi
),
131 8, STATS_FLAGS_PORT
, "tx_mac_errors" },
132 { STATS_OFFSET32(rx_stat_dot3statscarriersenseerrors_hi
),
133 8, STATS_FLAGS_PORT
, "tx_carrier_errors" },
134 /* 30 */{ STATS_OFFSET32(tx_stat_dot3statssinglecollisionframes_hi
),
135 8, STATS_FLAGS_PORT
, "tx_single_collisions" },
136 { STATS_OFFSET32(tx_stat_dot3statsmultiplecollisionframes_hi
),
137 8, STATS_FLAGS_PORT
, "tx_multi_collisions" },
138 { STATS_OFFSET32(tx_stat_dot3statsdeferredtransmissions_hi
),
139 8, STATS_FLAGS_PORT
, "tx_deferred" },
140 { STATS_OFFSET32(tx_stat_dot3statsexcessivecollisions_hi
),
141 8, STATS_FLAGS_PORT
, "tx_excess_collisions" },
142 { STATS_OFFSET32(tx_stat_dot3statslatecollisions_hi
),
143 8, STATS_FLAGS_PORT
, "tx_late_collisions" },
144 { STATS_OFFSET32(tx_stat_etherstatscollisions_hi
),
145 8, STATS_FLAGS_PORT
, "tx_total_collisions" },
146 { STATS_OFFSET32(tx_stat_etherstatspkts64octets_hi
),
147 8, STATS_FLAGS_PORT
, "tx_64_byte_packets" },
148 { STATS_OFFSET32(tx_stat_etherstatspkts65octetsto127octets_hi
),
149 8, STATS_FLAGS_PORT
, "tx_65_to_127_byte_packets" },
150 { STATS_OFFSET32(tx_stat_etherstatspkts128octetsto255octets_hi
),
151 8, STATS_FLAGS_PORT
, "tx_128_to_255_byte_packets" },
152 { STATS_OFFSET32(tx_stat_etherstatspkts256octetsto511octets_hi
),
153 8, STATS_FLAGS_PORT
, "tx_256_to_511_byte_packets" },
154 /* 40 */{ STATS_OFFSET32(tx_stat_etherstatspkts512octetsto1023octets_hi
),
155 8, STATS_FLAGS_PORT
, "tx_512_to_1023_byte_packets" },
156 { STATS_OFFSET32(etherstatspkts1024octetsto1522octets_hi
),
157 8, STATS_FLAGS_PORT
, "tx_1024_to_1522_byte_packets" },
158 { STATS_OFFSET32(etherstatspktsover1522octets_hi
),
159 8, STATS_FLAGS_PORT
, "tx_1523_to_9022_byte_packets" },
160 { STATS_OFFSET32(pause_frames_sent_hi
),
161 8, STATS_FLAGS_PORT
, "tx_pause_frames" }
164 #define BNX2X_NUM_STATS ARRAY_SIZE(bnx2x_stats_arr)
166 static int bnx2x_get_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
168 struct bnx2x
*bp
= netdev_priv(dev
);
169 int cfg_idx
= bnx2x_get_link_cfg_idx(bp
);
170 /* Dual Media boards present all available port types */
171 cmd
->supported
= bp
->port
.supported
[cfg_idx
] |
172 (bp
->port
.supported
[cfg_idx
^ 1] &
173 (SUPPORTED_TP
| SUPPORTED_FIBRE
));
174 cmd
->advertising
= bp
->port
.advertising
[cfg_idx
];
176 if ((bp
->state
== BNX2X_STATE_OPEN
) &&
177 !(bp
->flags
& MF_FUNC_DIS
) &&
178 (bp
->link_vars
.link_up
)) {
179 cmd
->speed
= bp
->link_vars
.line_speed
;
180 cmd
->duplex
= bp
->link_vars
.duplex
;
183 cmd
->speed
= bp
->link_params
.req_line_speed
[cfg_idx
];
184 cmd
->duplex
= bp
->link_params
.req_duplex
[cfg_idx
];
188 cmd
->speed
= bnx2x_get_mf_speed(bp
);
190 if (bp
->port
.supported
[cfg_idx
] & SUPPORTED_TP
)
192 else if (bp
->port
.supported
[cfg_idx
] & SUPPORTED_FIBRE
)
193 cmd
->port
= PORT_FIBRE
;
195 BNX2X_ERR("XGXS PHY Failure detected\n");
197 cmd
->phy_address
= bp
->mdio
.prtad
;
198 cmd
->transceiver
= XCVR_INTERNAL
;
200 if (bp
->link_params
.req_line_speed
[cfg_idx
] == SPEED_AUTO_NEG
)
201 cmd
->autoneg
= AUTONEG_ENABLE
;
203 cmd
->autoneg
= AUTONEG_DISABLE
;
208 DP(NETIF_MSG_LINK
, "ethtool_cmd: cmd %d\n"
209 DP_LEVEL
" supported 0x%x advertising 0x%x speed %d\n"
210 DP_LEVEL
" duplex %d port %d phy_address %d transceiver %d\n"
211 DP_LEVEL
" autoneg %d maxtxpkt %d maxrxpkt %d\n",
212 cmd
->cmd
, cmd
->supported
, cmd
->advertising
, cmd
->speed
,
213 cmd
->duplex
, cmd
->port
, cmd
->phy_address
, cmd
->transceiver
,
214 cmd
->autoneg
, cmd
->maxtxpkt
, cmd
->maxrxpkt
);
219 static int bnx2x_set_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
221 struct bnx2x
*bp
= netdev_priv(dev
);
222 u32 advertising
, cfg_idx
, old_multi_phy_config
, new_multi_phy_config
;
228 DP(NETIF_MSG_LINK
, "ethtool_cmd: cmd %d\n"
229 " supported 0x%x advertising 0x%x speed %d speed_hi %d\n"
230 " duplex %d port %d phy_address %d transceiver %d\n"
231 " autoneg %d maxtxpkt %d maxrxpkt %d\n",
232 cmd
->cmd
, cmd
->supported
, cmd
->advertising
, cmd
->speed
,
234 cmd
->duplex
, cmd
->port
, cmd
->phy_address
, cmd
->transceiver
,
235 cmd
->autoneg
, cmd
->maxtxpkt
, cmd
->maxrxpkt
);
238 speed
|= (cmd
->speed_hi
<< 16);
242 u32 line_speed
= bp
->link_vars
.line_speed
;
244 /* use 10G if no link detected */
248 if (bp
->common
.bc_ver
< REQ_BC_VER_4_SET_MF_BW
) {
249 BNX2X_DEV_INFO("To set speed BC %X or higher "
250 "is required, please upgrade BC\n",
251 REQ_BC_VER_4_SET_MF_BW
);
255 part
= (speed
* 100) / line_speed
;
257 if (line_speed
< speed
|| !part
) {
258 BNX2X_DEV_INFO("Speed setting should be in a range "
260 "of actual line speed\n");
264 if (bp
->state
!= BNX2X_STATE_OPEN
)
265 /* store value for following "load" */
266 bp
->pending_max
= part
;
268 bnx2x_update_max_mf_config(bp
, part
);
273 cfg_idx
= bnx2x_get_link_cfg_idx(bp
);
274 old_multi_phy_config
= bp
->link_params
.multi_phy_config
;
277 if (bp
->port
.supported
[cfg_idx
] & SUPPORTED_TP
)
278 break; /* no port change */
280 if (!(bp
->port
.supported
[0] & SUPPORTED_TP
||
281 bp
->port
.supported
[1] & SUPPORTED_TP
)) {
282 DP(NETIF_MSG_LINK
, "Unsupported port type\n");
285 bp
->link_params
.multi_phy_config
&=
286 ~PORT_HW_CFG_PHY_SELECTION_MASK
;
287 if (bp
->link_params
.multi_phy_config
&
288 PORT_HW_CFG_PHY_SWAPPED_ENABLED
)
289 bp
->link_params
.multi_phy_config
|=
290 PORT_HW_CFG_PHY_SELECTION_SECOND_PHY
;
292 bp
->link_params
.multi_phy_config
|=
293 PORT_HW_CFG_PHY_SELECTION_FIRST_PHY
;
296 if (bp
->port
.supported
[cfg_idx
] & SUPPORTED_FIBRE
)
297 break; /* no port change */
299 if (!(bp
->port
.supported
[0] & SUPPORTED_FIBRE
||
300 bp
->port
.supported
[1] & SUPPORTED_FIBRE
)) {
301 DP(NETIF_MSG_LINK
, "Unsupported port type\n");
304 bp
->link_params
.multi_phy_config
&=
305 ~PORT_HW_CFG_PHY_SELECTION_MASK
;
306 if (bp
->link_params
.multi_phy_config
&
307 PORT_HW_CFG_PHY_SWAPPED_ENABLED
)
308 bp
->link_params
.multi_phy_config
|=
309 PORT_HW_CFG_PHY_SELECTION_FIRST_PHY
;
311 bp
->link_params
.multi_phy_config
|=
312 PORT_HW_CFG_PHY_SELECTION_SECOND_PHY
;
315 DP(NETIF_MSG_LINK
, "Unsupported port type\n");
318 /* Save new config in case command complete successuly */
319 new_multi_phy_config
= bp
->link_params
.multi_phy_config
;
320 /* Get the new cfg_idx */
321 cfg_idx
= bnx2x_get_link_cfg_idx(bp
);
322 /* Restore old config in case command failed */
323 bp
->link_params
.multi_phy_config
= old_multi_phy_config
;
324 DP(NETIF_MSG_LINK
, "cfg_idx = %x\n", cfg_idx
);
326 if (cmd
->autoneg
== AUTONEG_ENABLE
) {
327 if (!(bp
->port
.supported
[cfg_idx
] & SUPPORTED_Autoneg
)) {
328 DP(NETIF_MSG_LINK
, "Autoneg not supported\n");
332 /* advertise the requested speed and duplex if supported */
333 cmd
->advertising
&= bp
->port
.supported
[cfg_idx
];
335 bp
->link_params
.req_line_speed
[cfg_idx
] = SPEED_AUTO_NEG
;
336 bp
->link_params
.req_duplex
[cfg_idx
] = DUPLEX_FULL
;
337 bp
->port
.advertising
[cfg_idx
] |= (ADVERTISED_Autoneg
|
340 } else { /* forced speed */
341 /* advertise the requested speed and duplex if supported */
344 if (cmd
->duplex
== DUPLEX_FULL
) {
345 if (!(bp
->port
.supported
[cfg_idx
] &
346 SUPPORTED_10baseT_Full
)) {
348 "10M full not supported\n");
352 advertising
= (ADVERTISED_10baseT_Full
|
355 if (!(bp
->port
.supported
[cfg_idx
] &
356 SUPPORTED_10baseT_Half
)) {
358 "10M half not supported\n");
362 advertising
= (ADVERTISED_10baseT_Half
|
368 if (cmd
->duplex
== DUPLEX_FULL
) {
369 if (!(bp
->port
.supported
[cfg_idx
] &
370 SUPPORTED_100baseT_Full
)) {
372 "100M full not supported\n");
376 advertising
= (ADVERTISED_100baseT_Full
|
379 if (!(bp
->port
.supported
[cfg_idx
] &
380 SUPPORTED_100baseT_Half
)) {
382 "100M half not supported\n");
386 advertising
= (ADVERTISED_100baseT_Half
|
392 if (cmd
->duplex
!= DUPLEX_FULL
) {
393 DP(NETIF_MSG_LINK
, "1G half not supported\n");
397 if (!(bp
->port
.supported
[cfg_idx
] &
398 SUPPORTED_1000baseT_Full
)) {
399 DP(NETIF_MSG_LINK
, "1G full not supported\n");
403 advertising
= (ADVERTISED_1000baseT_Full
|
408 if (cmd
->duplex
!= DUPLEX_FULL
) {
410 "2.5G half not supported\n");
414 if (!(bp
->port
.supported
[cfg_idx
]
415 & SUPPORTED_2500baseX_Full
)) {
417 "2.5G full not supported\n");
421 advertising
= (ADVERTISED_2500baseX_Full
|
426 if (cmd
->duplex
!= DUPLEX_FULL
) {
427 DP(NETIF_MSG_LINK
, "10G half not supported\n");
431 if (!(bp
->port
.supported
[cfg_idx
]
432 & SUPPORTED_10000baseT_Full
)) {
433 DP(NETIF_MSG_LINK
, "10G full not supported\n");
437 advertising
= (ADVERTISED_10000baseT_Full
|
442 DP(NETIF_MSG_LINK
, "Unsupported speed %d\n", speed
);
446 bp
->link_params
.req_line_speed
[cfg_idx
] = speed
;
447 bp
->link_params
.req_duplex
[cfg_idx
] = cmd
->duplex
;
448 bp
->port
.advertising
[cfg_idx
] = advertising
;
451 DP(NETIF_MSG_LINK
, "req_line_speed %d\n"
452 DP_LEVEL
" req_duplex %d advertising 0x%x\n",
453 bp
->link_params
.req_line_speed
[cfg_idx
],
454 bp
->link_params
.req_duplex
[cfg_idx
],
455 bp
->port
.advertising
[cfg_idx
]);
458 bp
->link_params
.multi_phy_config
= new_multi_phy_config
;
459 if (netif_running(dev
)) {
460 bnx2x_stats_handle(bp
, STATS_EVENT_STOP
);
467 #define IS_E1_ONLINE(info) (((info) & RI_E1_ONLINE) == RI_E1_ONLINE)
468 #define IS_E1H_ONLINE(info) (((info) & RI_E1H_ONLINE) == RI_E1H_ONLINE)
469 #define IS_E2_ONLINE(info) (((info) & RI_E2_ONLINE) == RI_E2_ONLINE)
471 static int bnx2x_get_regs_len(struct net_device
*dev
)
473 struct bnx2x
*bp
= netdev_priv(dev
);
477 if (CHIP_IS_E1(bp
)) {
478 for (i
= 0; i
< REGS_COUNT
; i
++)
479 if (IS_E1_ONLINE(reg_addrs
[i
].info
))
480 regdump_len
+= reg_addrs
[i
].size
;
482 for (i
= 0; i
< WREGS_COUNT_E1
; i
++)
483 if (IS_E1_ONLINE(wreg_addrs_e1
[i
].info
))
484 regdump_len
+= wreg_addrs_e1
[i
].size
*
485 (1 + wreg_addrs_e1
[i
].read_regs_count
);
487 } else if (CHIP_IS_E1H(bp
)) {
488 for (i
= 0; i
< REGS_COUNT
; i
++)
489 if (IS_E1H_ONLINE(reg_addrs
[i
].info
))
490 regdump_len
+= reg_addrs
[i
].size
;
492 for (i
= 0; i
< WREGS_COUNT_E1H
; i
++)
493 if (IS_E1H_ONLINE(wreg_addrs_e1h
[i
].info
))
494 regdump_len
+= wreg_addrs_e1h
[i
].size
*
495 (1 + wreg_addrs_e1h
[i
].read_regs_count
);
496 } else if (CHIP_IS_E2(bp
)) {
497 for (i
= 0; i
< REGS_COUNT
; i
++)
498 if (IS_E2_ONLINE(reg_addrs
[i
].info
))
499 regdump_len
+= reg_addrs
[i
].size
;
501 for (i
= 0; i
< WREGS_COUNT_E2
; i
++)
502 if (IS_E2_ONLINE(wreg_addrs_e2
[i
].info
))
503 regdump_len
+= wreg_addrs_e2
[i
].size
*
504 (1 + wreg_addrs_e2
[i
].read_regs_count
);
506 for (i
= 0; i
< PAGE_MODE_VALUES_E2
; i
++)
507 for (j
= 0; j
< PAGE_WRITE_REGS_E2
; j
++) {
508 for (k
= 0; k
< PAGE_READ_REGS_E2
; k
++)
509 if (IS_E2_ONLINE(page_read_regs_e2
[k
].
512 page_read_regs_e2
[k
].size
;
516 regdump_len
+= sizeof(struct dump_hdr
);
521 static inline void bnx2x_read_pages_regs_e2(struct bnx2x
*bp
, u32
*p
)
525 for (i
= 0; i
< PAGE_MODE_VALUES_E2
; i
++) {
526 for (j
= 0; j
< PAGE_WRITE_REGS_E2
; j
++) {
527 REG_WR(bp
, page_write_regs_e2
[j
], page_vals_e2
[i
]);
528 for (k
= 0; k
< PAGE_READ_REGS_E2
; k
++)
529 if (IS_E2_ONLINE(page_read_regs_e2
[k
].info
))
531 page_read_regs_e2
[k
].size
; n
++)
533 page_read_regs_e2
[k
].addr
+ n
*4);
538 static void bnx2x_get_regs(struct net_device
*dev
,
539 struct ethtool_regs
*regs
, void *_p
)
542 struct bnx2x
*bp
= netdev_priv(dev
);
543 struct dump_hdr dump_hdr
= {0};
546 memset(p
, 0, regs
->len
);
548 if (!netif_running(bp
->dev
))
551 /* Disable parity attentions as long as following dump may
552 * cause false alarms by reading never written registers. We
553 * will re-enable parity attentions right after the dump.
555 bnx2x_disable_blocks_parity(bp
);
557 dump_hdr
.hdr_size
= (sizeof(struct dump_hdr
) / 4) - 1;
558 dump_hdr
.dump_sign
= dump_sign_all
;
559 dump_hdr
.xstorm_waitp
= REG_RD(bp
, XSTORM_WAITP_ADDR
);
560 dump_hdr
.tstorm_waitp
= REG_RD(bp
, TSTORM_WAITP_ADDR
);
561 dump_hdr
.ustorm_waitp
= REG_RD(bp
, USTORM_WAITP_ADDR
);
562 dump_hdr
.cstorm_waitp
= REG_RD(bp
, CSTORM_WAITP_ADDR
);
565 dump_hdr
.info
= RI_E1_ONLINE
;
566 else if (CHIP_IS_E1H(bp
))
567 dump_hdr
.info
= RI_E1H_ONLINE
;
568 else if (CHIP_IS_E2(bp
))
569 dump_hdr
.info
= RI_E2_ONLINE
|
570 (BP_PATH(bp
) ? RI_PATH1_DUMP
: RI_PATH0_DUMP
);
572 memcpy(p
, &dump_hdr
, sizeof(struct dump_hdr
));
573 p
+= dump_hdr
.hdr_size
+ 1;
575 if (CHIP_IS_E1(bp
)) {
576 for (i
= 0; i
< REGS_COUNT
; i
++)
577 if (IS_E1_ONLINE(reg_addrs
[i
].info
))
578 for (j
= 0; j
< reg_addrs
[i
].size
; j
++)
580 reg_addrs
[i
].addr
+ j
*4);
582 } else if (CHIP_IS_E1H(bp
)) {
583 for (i
= 0; i
< REGS_COUNT
; i
++)
584 if (IS_E1H_ONLINE(reg_addrs
[i
].info
))
585 for (j
= 0; j
< reg_addrs
[i
].size
; j
++)
587 reg_addrs
[i
].addr
+ j
*4);
589 } else if (CHIP_IS_E2(bp
)) {
590 for (i
= 0; i
< REGS_COUNT
; i
++)
591 if (IS_E2_ONLINE(reg_addrs
[i
].info
))
592 for (j
= 0; j
< reg_addrs
[i
].size
; j
++)
594 reg_addrs
[i
].addr
+ j
*4);
596 bnx2x_read_pages_regs_e2(bp
, p
);
598 /* Re-enable parity attentions */
599 bnx2x_clear_blocks_parity(bp
);
600 if (CHIP_PARITY_ENABLED(bp
))
601 bnx2x_enable_blocks_parity(bp
);
604 #define PHY_FW_VER_LEN 20
606 static void bnx2x_get_drvinfo(struct net_device
*dev
,
607 struct ethtool_drvinfo
*info
)
609 struct bnx2x
*bp
= netdev_priv(dev
);
610 u8 phy_fw_ver
[PHY_FW_VER_LEN
];
612 strcpy(info
->driver
, DRV_MODULE_NAME
);
613 strcpy(info
->version
, DRV_MODULE_VERSION
);
615 phy_fw_ver
[0] = '\0';
617 bnx2x_acquire_phy_lock(bp
);
618 bnx2x_get_ext_phy_fw_version(&bp
->link_params
,
619 (bp
->state
!= BNX2X_STATE_CLOSED
),
620 phy_fw_ver
, PHY_FW_VER_LEN
);
621 bnx2x_release_phy_lock(bp
);
624 strncpy(info
->fw_version
, bp
->fw_ver
, 32);
625 snprintf(info
->fw_version
+ strlen(bp
->fw_ver
), 32 - strlen(bp
->fw_ver
),
627 (bp
->common
.bc_ver
& 0xff0000) >> 16,
628 (bp
->common
.bc_ver
& 0xff00) >> 8,
629 (bp
->common
.bc_ver
& 0xff),
630 ((phy_fw_ver
[0] != '\0') ? " phy " : ""), phy_fw_ver
);
631 strcpy(info
->bus_info
, pci_name(bp
->pdev
));
632 info
->n_stats
= BNX2X_NUM_STATS
;
633 info
->testinfo_len
= BNX2X_NUM_TESTS
;
634 info
->eedump_len
= bp
->common
.flash_size
;
635 info
->regdump_len
= bnx2x_get_regs_len(dev
);
638 static void bnx2x_get_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
640 struct bnx2x
*bp
= netdev_priv(dev
);
642 if (bp
->flags
& NO_WOL_FLAG
) {
646 wol
->supported
= WAKE_MAGIC
;
648 wol
->wolopts
= WAKE_MAGIC
;
652 memset(&wol
->sopass
, 0, sizeof(wol
->sopass
));
655 static int bnx2x_set_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
657 struct bnx2x
*bp
= netdev_priv(dev
);
659 if (wol
->wolopts
& ~WAKE_MAGIC
)
662 if (wol
->wolopts
& WAKE_MAGIC
) {
663 if (bp
->flags
& NO_WOL_FLAG
)
673 static u32
bnx2x_get_msglevel(struct net_device
*dev
)
675 struct bnx2x
*bp
= netdev_priv(dev
);
677 return bp
->msg_enable
;
680 static void bnx2x_set_msglevel(struct net_device
*dev
, u32 level
)
682 struct bnx2x
*bp
= netdev_priv(dev
);
684 if (capable(CAP_NET_ADMIN
))
685 bp
->msg_enable
= level
;
688 static int bnx2x_nway_reset(struct net_device
*dev
)
690 struct bnx2x
*bp
= netdev_priv(dev
);
695 if (netif_running(dev
)) {
696 bnx2x_stats_handle(bp
, STATS_EVENT_STOP
);
703 static u32
bnx2x_get_link(struct net_device
*dev
)
705 struct bnx2x
*bp
= netdev_priv(dev
);
707 if (bp
->flags
& MF_FUNC_DIS
|| (bp
->state
!= BNX2X_STATE_OPEN
))
710 return bp
->link_vars
.link_up
;
713 static int bnx2x_get_eeprom_len(struct net_device
*dev
)
715 struct bnx2x
*bp
= netdev_priv(dev
);
717 return bp
->common
.flash_size
;
720 static int bnx2x_acquire_nvram_lock(struct bnx2x
*bp
)
722 int port
= BP_PORT(bp
);
726 /* adjust timeout for emulation/FPGA */
727 count
= NVRAM_TIMEOUT_COUNT
;
728 if (CHIP_REV_IS_SLOW(bp
))
731 /* request access to nvram interface */
732 REG_WR(bp
, MCP_REG_MCPR_NVM_SW_ARB
,
733 (MCPR_NVM_SW_ARB_ARB_REQ_SET1
<< port
));
735 for (i
= 0; i
< count
*10; i
++) {
736 val
= REG_RD(bp
, MCP_REG_MCPR_NVM_SW_ARB
);
737 if (val
& (MCPR_NVM_SW_ARB_ARB_ARB1
<< port
))
743 if (!(val
& (MCPR_NVM_SW_ARB_ARB_ARB1
<< port
))) {
744 DP(BNX2X_MSG_NVM
, "cannot get access to nvram interface\n");
751 static int bnx2x_release_nvram_lock(struct bnx2x
*bp
)
753 int port
= BP_PORT(bp
);
757 /* adjust timeout for emulation/FPGA */
758 count
= NVRAM_TIMEOUT_COUNT
;
759 if (CHIP_REV_IS_SLOW(bp
))
762 /* relinquish nvram interface */
763 REG_WR(bp
, MCP_REG_MCPR_NVM_SW_ARB
,
764 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1
<< port
));
766 for (i
= 0; i
< count
*10; i
++) {
767 val
= REG_RD(bp
, MCP_REG_MCPR_NVM_SW_ARB
);
768 if (!(val
& (MCPR_NVM_SW_ARB_ARB_ARB1
<< port
)))
774 if (val
& (MCPR_NVM_SW_ARB_ARB_ARB1
<< port
)) {
775 DP(BNX2X_MSG_NVM
, "cannot free access to nvram interface\n");
782 static void bnx2x_enable_nvram_access(struct bnx2x
*bp
)
786 val
= REG_RD(bp
, MCP_REG_MCPR_NVM_ACCESS_ENABLE
);
788 /* enable both bits, even on read */
789 REG_WR(bp
, MCP_REG_MCPR_NVM_ACCESS_ENABLE
,
790 (val
| MCPR_NVM_ACCESS_ENABLE_EN
|
791 MCPR_NVM_ACCESS_ENABLE_WR_EN
));
794 static void bnx2x_disable_nvram_access(struct bnx2x
*bp
)
798 val
= REG_RD(bp
, MCP_REG_MCPR_NVM_ACCESS_ENABLE
);
800 /* disable both bits, even after read */
801 REG_WR(bp
, MCP_REG_MCPR_NVM_ACCESS_ENABLE
,
802 (val
& ~(MCPR_NVM_ACCESS_ENABLE_EN
|
803 MCPR_NVM_ACCESS_ENABLE_WR_EN
)));
806 static int bnx2x_nvram_read_dword(struct bnx2x
*bp
, u32 offset
, __be32
*ret_val
,
812 /* build the command word */
813 cmd_flags
|= MCPR_NVM_COMMAND_DOIT
;
815 /* need to clear DONE bit separately */
816 REG_WR(bp
, MCP_REG_MCPR_NVM_COMMAND
, MCPR_NVM_COMMAND_DONE
);
818 /* address of the NVRAM to read from */
819 REG_WR(bp
, MCP_REG_MCPR_NVM_ADDR
,
820 (offset
& MCPR_NVM_ADDR_NVM_ADDR_VALUE
));
822 /* issue a read command */
823 REG_WR(bp
, MCP_REG_MCPR_NVM_COMMAND
, cmd_flags
);
825 /* adjust timeout for emulation/FPGA */
826 count
= NVRAM_TIMEOUT_COUNT
;
827 if (CHIP_REV_IS_SLOW(bp
))
830 /* wait for completion */
833 for (i
= 0; i
< count
; i
++) {
835 val
= REG_RD(bp
, MCP_REG_MCPR_NVM_COMMAND
);
837 if (val
& MCPR_NVM_COMMAND_DONE
) {
838 val
= REG_RD(bp
, MCP_REG_MCPR_NVM_READ
);
839 /* we read nvram data in cpu order
840 * but ethtool sees it as an array of bytes
841 * converting to big-endian will do the work */
842 *ret_val
= cpu_to_be32(val
);
851 static int bnx2x_nvram_read(struct bnx2x
*bp
, u32 offset
, u8
*ret_buf
,
858 if ((offset
& 0x03) || (buf_size
& 0x03) || (buf_size
== 0)) {
860 "Invalid parameter: offset 0x%x buf_size 0x%x\n",
865 if (offset
+ buf_size
> bp
->common
.flash_size
) {
866 DP(BNX2X_MSG_NVM
, "Invalid parameter: offset (0x%x) +"
867 " buf_size (0x%x) > flash_size (0x%x)\n",
868 offset
, buf_size
, bp
->common
.flash_size
);
872 /* request access to nvram interface */
873 rc
= bnx2x_acquire_nvram_lock(bp
);
877 /* enable access to nvram interface */
878 bnx2x_enable_nvram_access(bp
);
880 /* read the first word(s) */
881 cmd_flags
= MCPR_NVM_COMMAND_FIRST
;
882 while ((buf_size
> sizeof(u32
)) && (rc
== 0)) {
883 rc
= bnx2x_nvram_read_dword(bp
, offset
, &val
, cmd_flags
);
884 memcpy(ret_buf
, &val
, 4);
886 /* advance to the next dword */
887 offset
+= sizeof(u32
);
888 ret_buf
+= sizeof(u32
);
889 buf_size
-= sizeof(u32
);
894 cmd_flags
|= MCPR_NVM_COMMAND_LAST
;
895 rc
= bnx2x_nvram_read_dword(bp
, offset
, &val
, cmd_flags
);
896 memcpy(ret_buf
, &val
, 4);
899 /* disable access to nvram interface */
900 bnx2x_disable_nvram_access(bp
);
901 bnx2x_release_nvram_lock(bp
);
906 static int bnx2x_get_eeprom(struct net_device
*dev
,
907 struct ethtool_eeprom
*eeprom
, u8
*eebuf
)
909 struct bnx2x
*bp
= netdev_priv(dev
);
912 if (!netif_running(dev
))
915 DP(BNX2X_MSG_NVM
, "ethtool_eeprom: cmd %d\n"
916 DP_LEVEL
" magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
917 eeprom
->cmd
, eeprom
->magic
, eeprom
->offset
, eeprom
->offset
,
918 eeprom
->len
, eeprom
->len
);
920 /* parameters already validated in ethtool_get_eeprom */
922 rc
= bnx2x_nvram_read(bp
, eeprom
->offset
, eebuf
, eeprom
->len
);
927 static int bnx2x_nvram_write_dword(struct bnx2x
*bp
, u32 offset
, u32 val
,
932 /* build the command word */
933 cmd_flags
|= MCPR_NVM_COMMAND_DOIT
| MCPR_NVM_COMMAND_WR
;
935 /* need to clear DONE bit separately */
936 REG_WR(bp
, MCP_REG_MCPR_NVM_COMMAND
, MCPR_NVM_COMMAND_DONE
);
939 REG_WR(bp
, MCP_REG_MCPR_NVM_WRITE
, val
);
941 /* address of the NVRAM to write to */
942 REG_WR(bp
, MCP_REG_MCPR_NVM_ADDR
,
943 (offset
& MCPR_NVM_ADDR_NVM_ADDR_VALUE
));
945 /* issue the write command */
946 REG_WR(bp
, MCP_REG_MCPR_NVM_COMMAND
, cmd_flags
);
948 /* adjust timeout for emulation/FPGA */
949 count
= NVRAM_TIMEOUT_COUNT
;
950 if (CHIP_REV_IS_SLOW(bp
))
953 /* wait for completion */
955 for (i
= 0; i
< count
; i
++) {
957 val
= REG_RD(bp
, MCP_REG_MCPR_NVM_COMMAND
);
958 if (val
& MCPR_NVM_COMMAND_DONE
) {
967 #define BYTE_OFFSET(offset) (8 * (offset & 0x03))
969 static int bnx2x_nvram_write1(struct bnx2x
*bp
, u32 offset
, u8
*data_buf
,
977 if (offset
+ buf_size
> bp
->common
.flash_size
) {
978 DP(BNX2X_MSG_NVM
, "Invalid parameter: offset (0x%x) +"
979 " buf_size (0x%x) > flash_size (0x%x)\n",
980 offset
, buf_size
, bp
->common
.flash_size
);
984 /* request access to nvram interface */
985 rc
= bnx2x_acquire_nvram_lock(bp
);
989 /* enable access to nvram interface */
990 bnx2x_enable_nvram_access(bp
);
992 cmd_flags
= (MCPR_NVM_COMMAND_FIRST
| MCPR_NVM_COMMAND_LAST
);
993 align_offset
= (offset
& ~0x03);
994 rc
= bnx2x_nvram_read_dword(bp
, align_offset
, &val
, cmd_flags
);
997 val
&= ~(0xff << BYTE_OFFSET(offset
));
998 val
|= (*data_buf
<< BYTE_OFFSET(offset
));
1000 /* nvram data is returned as an array of bytes
1001 * convert it back to cpu order */
1002 val
= be32_to_cpu(val
);
1004 rc
= bnx2x_nvram_write_dword(bp
, align_offset
, val
,
1008 /* disable access to nvram interface */
1009 bnx2x_disable_nvram_access(bp
);
1010 bnx2x_release_nvram_lock(bp
);
1015 static int bnx2x_nvram_write(struct bnx2x
*bp
, u32 offset
, u8
*data_buf
,
1023 if (buf_size
== 1) /* ethtool */
1024 return bnx2x_nvram_write1(bp
, offset
, data_buf
, buf_size
);
1026 if ((offset
& 0x03) || (buf_size
& 0x03) || (buf_size
== 0)) {
1028 "Invalid parameter: offset 0x%x buf_size 0x%x\n",
1033 if (offset
+ buf_size
> bp
->common
.flash_size
) {
1034 DP(BNX2X_MSG_NVM
, "Invalid parameter: offset (0x%x) +"
1035 " buf_size (0x%x) > flash_size (0x%x)\n",
1036 offset
, buf_size
, bp
->common
.flash_size
);
1040 /* request access to nvram interface */
1041 rc
= bnx2x_acquire_nvram_lock(bp
);
1045 /* enable access to nvram interface */
1046 bnx2x_enable_nvram_access(bp
);
1049 cmd_flags
= MCPR_NVM_COMMAND_FIRST
;
1050 while ((written_so_far
< buf_size
) && (rc
== 0)) {
1051 if (written_so_far
== (buf_size
- sizeof(u32
)))
1052 cmd_flags
|= MCPR_NVM_COMMAND_LAST
;
1053 else if (((offset
+ 4) % NVRAM_PAGE_SIZE
) == 0)
1054 cmd_flags
|= MCPR_NVM_COMMAND_LAST
;
1055 else if ((offset
% NVRAM_PAGE_SIZE
) == 0)
1056 cmd_flags
|= MCPR_NVM_COMMAND_FIRST
;
1058 memcpy(&val
, data_buf
, 4);
1060 rc
= bnx2x_nvram_write_dword(bp
, offset
, val
, cmd_flags
);
1062 /* advance to the next dword */
1063 offset
+= sizeof(u32
);
1064 data_buf
+= sizeof(u32
);
1065 written_so_far
+= sizeof(u32
);
1069 /* disable access to nvram interface */
1070 bnx2x_disable_nvram_access(bp
);
1071 bnx2x_release_nvram_lock(bp
);
1076 static int bnx2x_set_eeprom(struct net_device
*dev
,
1077 struct ethtool_eeprom
*eeprom
, u8
*eebuf
)
1079 struct bnx2x
*bp
= netdev_priv(dev
);
1080 int port
= BP_PORT(bp
);
1083 if (!netif_running(dev
))
1086 DP(BNX2X_MSG_NVM
, "ethtool_eeprom: cmd %d\n"
1087 DP_LEVEL
" magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
1088 eeprom
->cmd
, eeprom
->magic
, eeprom
->offset
, eeprom
->offset
,
1089 eeprom
->len
, eeprom
->len
);
1091 /* parameters already validated in ethtool_set_eeprom */
1093 /* PHY eeprom can be accessed only by the PMF */
1094 if ((eeprom
->magic
>= 0x50485900) && (eeprom
->magic
<= 0x504859FF) &&
1100 dev_info
.port_hw_config
[port
].external_phy_config
);
1102 if (eeprom
->magic
== 0x50485950) {
1103 /* 'PHYP' (0x50485950): prepare phy for FW upgrade */
1104 bnx2x_stats_handle(bp
, STATS_EVENT_STOP
);
1106 bnx2x_acquire_phy_lock(bp
);
1107 rc
|= bnx2x_link_reset(&bp
->link_params
,
1109 if (XGXS_EXT_PHY_TYPE(ext_phy_config
) ==
1110 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101
)
1111 bnx2x_set_gpio(bp
, MISC_REGISTERS_GPIO_0
,
1112 MISC_REGISTERS_GPIO_HIGH
, port
);
1113 bnx2x_release_phy_lock(bp
);
1114 bnx2x_link_report(bp
);
1116 } else if (eeprom
->magic
== 0x50485952) {
1117 /* 'PHYR' (0x50485952): re-init link after FW upgrade */
1118 if (bp
->state
== BNX2X_STATE_OPEN
) {
1119 bnx2x_acquire_phy_lock(bp
);
1120 rc
|= bnx2x_link_reset(&bp
->link_params
,
1123 rc
|= bnx2x_phy_init(&bp
->link_params
,
1125 bnx2x_release_phy_lock(bp
);
1126 bnx2x_calc_fc_adv(bp
);
1128 } else if (eeprom
->magic
== 0x53985943) {
1129 /* 'PHYC' (0x53985943): PHY FW upgrade completed */
1130 if (XGXS_EXT_PHY_TYPE(ext_phy_config
) ==
1131 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101
) {
1133 /* DSP Remove Download Mode */
1134 bnx2x_set_gpio(bp
, MISC_REGISTERS_GPIO_0
,
1135 MISC_REGISTERS_GPIO_LOW
, port
);
1137 bnx2x_acquire_phy_lock(bp
);
1139 bnx2x_sfx7101_sp_sw_reset(bp
,
1140 &bp
->link_params
.phy
[EXT_PHY1
]);
1142 /* wait 0.5 sec to allow it to run */
1144 bnx2x_ext_phy_hw_reset(bp
, port
);
1146 bnx2x_release_phy_lock(bp
);
1149 rc
= bnx2x_nvram_write(bp
, eeprom
->offset
, eebuf
, eeprom
->len
);
1154 static int bnx2x_get_coalesce(struct net_device
*dev
,
1155 struct ethtool_coalesce
*coal
)
1157 struct bnx2x
*bp
= netdev_priv(dev
);
1159 memset(coal
, 0, sizeof(struct ethtool_coalesce
));
1161 coal
->rx_coalesce_usecs
= bp
->rx_ticks
;
1162 coal
->tx_coalesce_usecs
= bp
->tx_ticks
;
1167 static int bnx2x_set_coalesce(struct net_device
*dev
,
1168 struct ethtool_coalesce
*coal
)
1170 struct bnx2x
*bp
= netdev_priv(dev
);
1172 bp
->rx_ticks
= (u16
)coal
->rx_coalesce_usecs
;
1173 if (bp
->rx_ticks
> BNX2X_MAX_COALESCE_TOUT
)
1174 bp
->rx_ticks
= BNX2X_MAX_COALESCE_TOUT
;
1176 bp
->tx_ticks
= (u16
)coal
->tx_coalesce_usecs
;
1177 if (bp
->tx_ticks
> BNX2X_MAX_COALESCE_TOUT
)
1178 bp
->tx_ticks
= BNX2X_MAX_COALESCE_TOUT
;
1180 if (netif_running(dev
))
1181 bnx2x_update_coalesce(bp
);
1186 static void bnx2x_get_ringparam(struct net_device
*dev
,
1187 struct ethtool_ringparam
*ering
)
1189 struct bnx2x
*bp
= netdev_priv(dev
);
1191 ering
->rx_max_pending
= MAX_RX_AVAIL
;
1192 ering
->rx_mini_max_pending
= 0;
1193 ering
->rx_jumbo_max_pending
= 0;
1195 if (bp
->rx_ring_size
)
1196 ering
->rx_pending
= bp
->rx_ring_size
;
1198 if (bp
->state
== BNX2X_STATE_OPEN
&& bp
->num_queues
)
1199 ering
->rx_pending
= MAX_RX_AVAIL
/bp
->num_queues
;
1201 ering
->rx_pending
= MAX_RX_AVAIL
;
1203 ering
->rx_mini_pending
= 0;
1204 ering
->rx_jumbo_pending
= 0;
1206 ering
->tx_max_pending
= MAX_TX_AVAIL
;
1207 ering
->tx_pending
= bp
->tx_ring_size
;
1210 static int bnx2x_set_ringparam(struct net_device
*dev
,
1211 struct ethtool_ringparam
*ering
)
1213 struct bnx2x
*bp
= netdev_priv(dev
);
1216 if (bp
->recovery_state
!= BNX2X_RECOVERY_DONE
) {
1217 printk(KERN_ERR
"Handling parity error recovery. Try again later\n");
1221 if ((ering
->rx_pending
> MAX_RX_AVAIL
) ||
1222 (ering
->rx_pending
< MIN_RX_AVAIL
) ||
1223 (ering
->tx_pending
> MAX_TX_AVAIL
) ||
1224 (ering
->tx_pending
<= MAX_SKB_FRAGS
+ 4))
1227 bp
->rx_ring_size
= ering
->rx_pending
;
1228 bp
->tx_ring_size
= ering
->tx_pending
;
1230 if (netif_running(dev
)) {
1231 bnx2x_nic_unload(bp
, UNLOAD_NORMAL
);
1232 rc
= bnx2x_nic_load(bp
, LOAD_NORMAL
);
1238 static void bnx2x_get_pauseparam(struct net_device
*dev
,
1239 struct ethtool_pauseparam
*epause
)
1241 struct bnx2x
*bp
= netdev_priv(dev
);
1242 int cfg_idx
= bnx2x_get_link_cfg_idx(bp
);
1243 epause
->autoneg
= (bp
->link_params
.req_flow_ctrl
[cfg_idx
] ==
1244 BNX2X_FLOW_CTRL_AUTO
);
1246 epause
->rx_pause
= ((bp
->link_vars
.flow_ctrl
& BNX2X_FLOW_CTRL_RX
) ==
1247 BNX2X_FLOW_CTRL_RX
);
1248 epause
->tx_pause
= ((bp
->link_vars
.flow_ctrl
& BNX2X_FLOW_CTRL_TX
) ==
1249 BNX2X_FLOW_CTRL_TX
);
1251 DP(NETIF_MSG_LINK
, "ethtool_pauseparam: cmd %d\n"
1252 DP_LEVEL
" autoneg %d rx_pause %d tx_pause %d\n",
1253 epause
->cmd
, epause
->autoneg
, epause
->rx_pause
, epause
->tx_pause
);
1256 static int bnx2x_set_pauseparam(struct net_device
*dev
,
1257 struct ethtool_pauseparam
*epause
)
1259 struct bnx2x
*bp
= netdev_priv(dev
);
1260 u32 cfg_idx
= bnx2x_get_link_cfg_idx(bp
);
1264 DP(NETIF_MSG_LINK
, "ethtool_pauseparam: cmd %d\n"
1265 DP_LEVEL
" autoneg %d rx_pause %d tx_pause %d\n",
1266 epause
->cmd
, epause
->autoneg
, epause
->rx_pause
, epause
->tx_pause
);
1268 bp
->link_params
.req_flow_ctrl
[cfg_idx
] = BNX2X_FLOW_CTRL_AUTO
;
1270 if (epause
->rx_pause
)
1271 bp
->link_params
.req_flow_ctrl
[cfg_idx
] |= BNX2X_FLOW_CTRL_RX
;
1273 if (epause
->tx_pause
)
1274 bp
->link_params
.req_flow_ctrl
[cfg_idx
] |= BNX2X_FLOW_CTRL_TX
;
1276 if (bp
->link_params
.req_flow_ctrl
[cfg_idx
] == BNX2X_FLOW_CTRL_AUTO
)
1277 bp
->link_params
.req_flow_ctrl
[cfg_idx
] = BNX2X_FLOW_CTRL_NONE
;
1279 if (epause
->autoneg
) {
1280 if (!(bp
->port
.supported
[cfg_idx
] & SUPPORTED_Autoneg
)) {
1281 DP(NETIF_MSG_LINK
, "autoneg not supported\n");
1285 if (bp
->link_params
.req_line_speed
[cfg_idx
] == SPEED_AUTO_NEG
) {
1286 bp
->link_params
.req_flow_ctrl
[cfg_idx
] =
1287 BNX2X_FLOW_CTRL_AUTO
;
1292 "req_flow_ctrl 0x%x\n", bp
->link_params
.req_flow_ctrl
[cfg_idx
]);
1294 if (netif_running(dev
)) {
1295 bnx2x_stats_handle(bp
, STATS_EVENT_STOP
);
1302 static int bnx2x_set_flags(struct net_device
*dev
, u32 data
)
1304 struct bnx2x
*bp
= netdev_priv(dev
);
1308 if (bp
->recovery_state
!= BNX2X_RECOVERY_DONE
) {
1309 printk(KERN_ERR
"Handling parity error recovery. Try again later\n");
1313 if (!(data
& ETH_FLAG_RXVLAN
))
1316 if ((data
& ETH_FLAG_LRO
) && bp
->rx_csum
&& bp
->disable_tpa
)
1319 rc
= ethtool_op_set_flags(dev
, data
, ETH_FLAG_LRO
| ETH_FLAG_RXVLAN
|
1320 ETH_FLAG_TXVLAN
| ETH_FLAG_RXHASH
);
1324 /* TPA requires Rx CSUM offloading */
1325 if ((data
& ETH_FLAG_LRO
) && bp
->rx_csum
) {
1326 if (!(bp
->flags
& TPA_ENABLE_FLAG
)) {
1327 bp
->flags
|= TPA_ENABLE_FLAG
;
1330 } else if (bp
->flags
& TPA_ENABLE_FLAG
) {
1331 dev
->features
&= ~NETIF_F_LRO
;
1332 bp
->flags
&= ~TPA_ENABLE_FLAG
;
1336 if (changed
&& netif_running(dev
)) {
1337 bnx2x_nic_unload(bp
, UNLOAD_NORMAL
);
1338 rc
= bnx2x_nic_load(bp
, LOAD_NORMAL
);
1344 static u32
bnx2x_get_rx_csum(struct net_device
*dev
)
1346 struct bnx2x
*bp
= netdev_priv(dev
);
1351 static int bnx2x_set_rx_csum(struct net_device
*dev
, u32 data
)
1353 struct bnx2x
*bp
= netdev_priv(dev
);
1356 if (bp
->recovery_state
!= BNX2X_RECOVERY_DONE
) {
1357 printk(KERN_ERR
"Handling parity error recovery. Try again later\n");
1363 /* Disable TPA, when Rx CSUM is disabled. Otherwise all
1364 TPA'ed packets will be discarded due to wrong TCP CSUM */
1366 u32 flags
= ethtool_op_get_flags(dev
);
1368 rc
= bnx2x_set_flags(dev
, (flags
& ~ETH_FLAG_LRO
));
1374 static int bnx2x_set_tso(struct net_device
*dev
, u32 data
)
1377 dev
->features
|= (NETIF_F_TSO
| NETIF_F_TSO_ECN
);
1378 dev
->features
|= NETIF_F_TSO6
;
1380 dev
->features
&= ~(NETIF_F_TSO
| NETIF_F_TSO_ECN
);
1381 dev
->features
&= ~NETIF_F_TSO6
;
1387 static const struct {
1388 char string
[ETH_GSTRING_LEN
];
1389 } bnx2x_tests_str_arr
[BNX2X_NUM_TESTS
] = {
1390 { "register_test (offline)" },
1391 { "memory_test (offline)" },
1392 { "loopback_test (offline)" },
1393 { "nvram_test (online)" },
1394 { "interrupt_test (online)" },
1395 { "link_test (online)" },
1396 { "idle check (online)" }
1399 static int bnx2x_test_registers(struct bnx2x
*bp
)
1401 int idx
, i
, rc
= -ENODEV
;
1403 int port
= BP_PORT(bp
);
1404 static const struct {
1409 /* 0 */ { BRB1_REG_PAUSE_LOW_THRESHOLD_0
, 4, 0x000003ff },
1410 { DORQ_REG_DB_ADDR0
, 4, 0xffffffff },
1411 { HC_REG_AGG_INT_0
, 4, 0x000003ff },
1412 { PBF_REG_MAC_IF0_ENABLE
, 4, 0x00000001 },
1413 { PBF_REG_P0_INIT_CRD
, 4, 0x000007ff },
1414 { PRS_REG_CID_PORT_0
, 4, 0x00ffffff },
1415 { PXP2_REG_PSWRQ_CDU0_L2P
, 4, 0x000fffff },
1416 { PXP2_REG_RQ_CDU0_EFIRST_MEM_ADDR
, 8, 0x0003ffff },
1417 { PXP2_REG_PSWRQ_TM0_L2P
, 4, 0x000fffff },
1418 { PXP2_REG_RQ_USDM0_EFIRST_MEM_ADDR
, 8, 0x0003ffff },
1419 /* 10 */ { PXP2_REG_PSWRQ_TSDM0_L2P
, 4, 0x000fffff },
1420 { QM_REG_CONNNUM_0
, 4, 0x000fffff },
1421 { TM_REG_LIN0_MAX_ACTIVE_CID
, 4, 0x0003ffff },
1422 { SRC_REG_KEYRSS0_0
, 40, 0xffffffff },
1423 { SRC_REG_KEYRSS0_7
, 40, 0xffffffff },
1424 { XCM_REG_WU_DA_SET_TMR_CNT_FLG_CMD00
, 4, 0x00000001 },
1425 { XCM_REG_WU_DA_CNT_CMD00
, 4, 0x00000003 },
1426 { XCM_REG_GLB_DEL_ACK_MAX_CNT_0
, 4, 0x000000ff },
1427 { NIG_REG_LLH0_T_BIT
, 4, 0x00000001 },
1428 { NIG_REG_EMAC0_IN_EN
, 4, 0x00000001 },
1429 /* 20 */ { NIG_REG_BMAC0_IN_EN
, 4, 0x00000001 },
1430 { NIG_REG_XCM0_OUT_EN
, 4, 0x00000001 },
1431 { NIG_REG_BRB0_OUT_EN
, 4, 0x00000001 },
1432 { NIG_REG_LLH0_XCM_MASK
, 4, 0x00000007 },
1433 { NIG_REG_LLH0_ACPI_PAT_6_LEN
, 68, 0x000000ff },
1434 { NIG_REG_LLH0_ACPI_PAT_0_CRC
, 68, 0xffffffff },
1435 { NIG_REG_LLH0_DEST_MAC_0_0
, 160, 0xffffffff },
1436 { NIG_REG_LLH0_DEST_IP_0_1
, 160, 0xffffffff },
1437 { NIG_REG_LLH0_IPV4_IPV6_0
, 160, 0x00000001 },
1438 { NIG_REG_LLH0_DEST_UDP_0
, 160, 0x0000ffff },
1439 /* 30 */ { NIG_REG_LLH0_DEST_TCP_0
, 160, 0x0000ffff },
1440 { NIG_REG_LLH0_VLAN_ID_0
, 160, 0x00000fff },
1441 { NIG_REG_XGXS_SERDES0_MODE_SEL
, 4, 0x00000001 },
1442 { NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0
, 4, 0x00000001 },
1443 { NIG_REG_STATUS_INTERRUPT_PORT0
, 4, 0x07ffffff },
1444 { NIG_REG_XGXS0_CTRL_EXTREMOTEMDIOST
, 24, 0x00000001 },
1445 { NIG_REG_SERDES0_CTRL_PHY_ADDR
, 16, 0x0000001f },
1447 { 0xffffffff, 0, 0x00000000 }
1450 if (!netif_running(bp
->dev
))
1453 /* Repeat the test twice:
1454 First by writing 0x00000000, second by writing 0xffffffff */
1455 for (idx
= 0; idx
< 2; idx
++) {
1462 wr_val
= 0xffffffff;
1466 for (i
= 0; reg_tbl
[i
].offset0
!= 0xffffffff; i
++) {
1467 u32 offset
, mask
, save_val
, val
;
1468 if (CHIP_IS_E2(bp
) &&
1469 reg_tbl
[i
].offset0
== HC_REG_AGG_INT_0
)
1472 offset
= reg_tbl
[i
].offset0
+ port
*reg_tbl
[i
].offset1
;
1473 mask
= reg_tbl
[i
].mask
;
1475 save_val
= REG_RD(bp
, offset
);
1477 REG_WR(bp
, offset
, wr_val
& mask
);
1479 val
= REG_RD(bp
, offset
);
1481 /* Restore the original register's value */
1482 REG_WR(bp
, offset
, save_val
);
1484 /* verify value is as expected */
1485 if ((val
& mask
) != (wr_val
& mask
)) {
1487 "offset 0x%x: val 0x%x != 0x%x mask 0x%x\n",
1488 offset
, val
, wr_val
, mask
);
1500 static int bnx2x_test_memory(struct bnx2x
*bp
)
1502 int i
, j
, rc
= -ENODEV
;
1504 static const struct {
1508 { CCM_REG_XX_DESCR_TABLE
, CCM_REG_XX_DESCR_TABLE_SIZE
},
1509 { CFC_REG_ACTIVITY_COUNTER
, CFC_REG_ACTIVITY_COUNTER_SIZE
},
1510 { CFC_REG_LINK_LIST
, CFC_REG_LINK_LIST_SIZE
},
1511 { DMAE_REG_CMD_MEM
, DMAE_REG_CMD_MEM_SIZE
},
1512 { TCM_REG_XX_DESCR_TABLE
, TCM_REG_XX_DESCR_TABLE_SIZE
},
1513 { UCM_REG_XX_DESCR_TABLE
, UCM_REG_XX_DESCR_TABLE_SIZE
},
1514 { XCM_REG_XX_DESCR_TABLE
, XCM_REG_XX_DESCR_TABLE_SIZE
},
1518 static const struct {
1525 { "CCM_PRTY_STS", CCM_REG_CCM_PRTY_STS
, 0x3ffc0, 0, 0 },
1526 { "CFC_PRTY_STS", CFC_REG_CFC_PRTY_STS
, 0x2, 0x2, 0 },
1527 { "DMAE_PRTY_STS", DMAE_REG_DMAE_PRTY_STS
, 0, 0, 0 },
1528 { "TCM_PRTY_STS", TCM_REG_TCM_PRTY_STS
, 0x3ffc0, 0, 0 },
1529 { "UCM_PRTY_STS", UCM_REG_UCM_PRTY_STS
, 0x3ffc0, 0, 0 },
1530 { "XCM_PRTY_STS", XCM_REG_XCM_PRTY_STS
, 0x3ffc1, 0, 0 },
1532 { NULL
, 0xffffffff, 0, 0, 0 }
1535 if (!netif_running(bp
->dev
))
1538 /* pre-Check the parity status */
1539 for (i
= 0; prty_tbl
[i
].offset
!= 0xffffffff; i
++) {
1540 val
= REG_RD(bp
, prty_tbl
[i
].offset
);
1541 if ((CHIP_IS_E1(bp
) && (val
& ~(prty_tbl
[i
].e1_mask
))) ||
1542 (CHIP_IS_E1H(bp
) && (val
& ~(prty_tbl
[i
].e1h_mask
))) ||
1543 (CHIP_IS_E2(bp
) && (val
& ~(prty_tbl
[i
].e2_mask
)))) {
1545 "%s is 0x%x\n", prty_tbl
[i
].name
, val
);
1550 /* Go through all the memories */
1551 for (i
= 0; mem_tbl
[i
].offset
!= 0xffffffff; i
++)
1552 for (j
= 0; j
< mem_tbl
[i
].size
; j
++)
1553 REG_RD(bp
, mem_tbl
[i
].offset
+ j
*4);
1555 /* Check the parity status */
1556 for (i
= 0; prty_tbl
[i
].offset
!= 0xffffffff; i
++) {
1557 val
= REG_RD(bp
, prty_tbl
[i
].offset
);
1558 if ((CHIP_IS_E1(bp
) && (val
& ~(prty_tbl
[i
].e1_mask
))) ||
1559 (CHIP_IS_E1H(bp
) && (val
& ~(prty_tbl
[i
].e1h_mask
))) ||
1560 (CHIP_IS_E2(bp
) && (val
& ~(prty_tbl
[i
].e2_mask
)))) {
1562 "%s is 0x%x\n", prty_tbl
[i
].name
, val
);
1573 static void bnx2x_wait_for_link(struct bnx2x
*bp
, u8 link_up
, u8 is_serdes
)
1578 while (bnx2x_link_test(bp
, is_serdes
) && cnt
--)
1582 static int bnx2x_run_loopback(struct bnx2x
*bp
, int loopback_mode
, u8 link_up
)
1584 unsigned int pkt_size
, num_pkts
, i
;
1585 struct sk_buff
*skb
;
1586 unsigned char *packet
;
1587 struct bnx2x_fastpath
*fp_rx
= &bp
->fp
[0];
1588 struct bnx2x_fastpath
*fp_tx
= &bp
->fp
[0];
1589 u16 tx_start_idx
, tx_idx
;
1590 u16 rx_start_idx
, rx_idx
;
1591 u16 pkt_prod
, bd_prod
;
1592 struct sw_tx_bd
*tx_buf
;
1593 struct eth_tx_start_bd
*tx_start_bd
;
1594 struct eth_tx_parse_bd_e1x
*pbd_e1x
= NULL
;
1595 struct eth_tx_parse_bd_e2
*pbd_e2
= NULL
;
1597 union eth_rx_cqe
*cqe
;
1599 struct sw_rx_bd
*rx_buf
;
1603 /* check the loopback mode */
1604 switch (loopback_mode
) {
1605 case BNX2X_PHY_LOOPBACK
:
1606 if (bp
->link_params
.loopback_mode
!= LOOPBACK_XGXS
)
1609 case BNX2X_MAC_LOOPBACK
:
1610 bp
->link_params
.loopback_mode
= LOOPBACK_BMAC
;
1611 bnx2x_phy_init(&bp
->link_params
, &bp
->link_vars
);
1617 /* prepare the loopback packet */
1618 pkt_size
= (((bp
->dev
->mtu
< ETH_MAX_PACKET_SIZE
) ?
1619 bp
->dev
->mtu
: ETH_MAX_PACKET_SIZE
) + ETH_HLEN
);
1620 skb
= netdev_alloc_skb(bp
->dev
, fp_rx
->rx_buf_size
);
1623 goto test_loopback_exit
;
1625 packet
= skb_put(skb
, pkt_size
);
1626 memcpy(packet
, bp
->dev
->dev_addr
, ETH_ALEN
);
1627 memset(packet
+ ETH_ALEN
, 0, ETH_ALEN
);
1628 memset(packet
+ 2*ETH_ALEN
, 0x77, (ETH_HLEN
- 2*ETH_ALEN
));
1629 for (i
= ETH_HLEN
; i
< pkt_size
; i
++)
1630 packet
[i
] = (unsigned char) (i
& 0xff);
1632 /* send the loopback packet */
1634 tx_start_idx
= le16_to_cpu(*fp_tx
->tx_cons_sb
);
1635 rx_start_idx
= le16_to_cpu(*fp_rx
->rx_cons_sb
);
1637 pkt_prod
= fp_tx
->tx_pkt_prod
++;
1638 tx_buf
= &fp_tx
->tx_buf_ring
[TX_BD(pkt_prod
)];
1639 tx_buf
->first_bd
= fp_tx
->tx_bd_prod
;
1643 bd_prod
= TX_BD(fp_tx
->tx_bd_prod
);
1644 tx_start_bd
= &fp_tx
->tx_desc_ring
[bd_prod
].start_bd
;
1645 mapping
= dma_map_single(&bp
->pdev
->dev
, skb
->data
,
1646 skb_headlen(skb
), DMA_TO_DEVICE
);
1647 tx_start_bd
->addr_hi
= cpu_to_le32(U64_HI(mapping
));
1648 tx_start_bd
->addr_lo
= cpu_to_le32(U64_LO(mapping
));
1649 tx_start_bd
->nbd
= cpu_to_le16(2); /* start + pbd */
1650 tx_start_bd
->nbytes
= cpu_to_le16(skb_headlen(skb
));
1651 tx_start_bd
->vlan_or_ethertype
= cpu_to_le16(pkt_prod
);
1652 tx_start_bd
->bd_flags
.as_bitfield
= ETH_TX_BD_FLAGS_START_BD
;
1653 SET_FLAG(tx_start_bd
->general_data
,
1654 ETH_TX_START_BD_ETH_ADDR_TYPE
,
1656 SET_FLAG(tx_start_bd
->general_data
,
1657 ETH_TX_START_BD_HDR_NBDS
,
1660 /* turn on parsing and get a BD */
1661 bd_prod
= TX_BD(NEXT_TX_IDX(bd_prod
));
1663 pbd_e1x
= &fp_tx
->tx_desc_ring
[bd_prod
].parse_bd_e1x
;
1664 pbd_e2
= &fp_tx
->tx_desc_ring
[bd_prod
].parse_bd_e2
;
1666 memset(pbd_e2
, 0, sizeof(struct eth_tx_parse_bd_e2
));
1667 memset(pbd_e1x
, 0, sizeof(struct eth_tx_parse_bd_e1x
));
1671 fp_tx
->tx_db
.data
.prod
+= 2;
1673 DOORBELL(bp
, fp_tx
->index
, fp_tx
->tx_db
.raw
);
1678 fp_tx
->tx_bd_prod
+= 2; /* start + pbd */
1682 tx_idx
= le16_to_cpu(*fp_tx
->tx_cons_sb
);
1683 if (tx_idx
!= tx_start_idx
+ num_pkts
)
1684 goto test_loopback_exit
;
1686 /* Unlike HC IGU won't generate an interrupt for status block
1687 * updates that have been performed while interrupts were
1690 if (bp
->common
.int_block
== INT_BLOCK_IGU
) {
1691 /* Disable local BHes to prevent a dead-lock situation between
1692 * sch_direct_xmit() and bnx2x_run_loopback() (calling
1693 * bnx2x_tx_int()), as both are taking netif_tx_lock().
1696 bnx2x_tx_int(fp_tx
);
1700 rx_idx
= le16_to_cpu(*fp_rx
->rx_cons_sb
);
1701 if (rx_idx
!= rx_start_idx
+ num_pkts
)
1702 goto test_loopback_exit
;
1704 cqe
= &fp_rx
->rx_comp_ring
[RCQ_BD(fp_rx
->rx_comp_cons
)];
1705 cqe_fp_flags
= cqe
->fast_path_cqe
.type_error_flags
;
1706 if (CQE_TYPE(cqe_fp_flags
) || (cqe_fp_flags
& ETH_RX_ERROR_FALGS
))
1707 goto test_loopback_rx_exit
;
1709 len
= le16_to_cpu(cqe
->fast_path_cqe
.pkt_len
);
1710 if (len
!= pkt_size
)
1711 goto test_loopback_rx_exit
;
1713 rx_buf
= &fp_rx
->rx_buf_ring
[RX_BD(fp_rx
->rx_bd_cons
)];
1715 skb_reserve(skb
, cqe
->fast_path_cqe
.placement_offset
);
1716 for (i
= ETH_HLEN
; i
< pkt_size
; i
++)
1717 if (*(skb
->data
+ i
) != (unsigned char) (i
& 0xff))
1718 goto test_loopback_rx_exit
;
1722 test_loopback_rx_exit
:
1724 fp_rx
->rx_bd_cons
= NEXT_RX_IDX(fp_rx
->rx_bd_cons
);
1725 fp_rx
->rx_bd_prod
= NEXT_RX_IDX(fp_rx
->rx_bd_prod
);
1726 fp_rx
->rx_comp_cons
= NEXT_RCQ_IDX(fp_rx
->rx_comp_cons
);
1727 fp_rx
->rx_comp_prod
= NEXT_RCQ_IDX(fp_rx
->rx_comp_prod
);
1729 /* Update producers */
1730 bnx2x_update_rx_prod(bp
, fp_rx
, fp_rx
->rx_bd_prod
, fp_rx
->rx_comp_prod
,
1731 fp_rx
->rx_sge_prod
);
1734 bp
->link_params
.loopback_mode
= LOOPBACK_NONE
;
1739 static int bnx2x_test_loopback(struct bnx2x
*bp
, u8 link_up
)
1746 if (!netif_running(bp
->dev
))
1747 return BNX2X_LOOPBACK_FAILED
;
1749 bnx2x_netif_stop(bp
, 1);
1750 bnx2x_acquire_phy_lock(bp
);
1752 res
= bnx2x_run_loopback(bp
, BNX2X_PHY_LOOPBACK
, link_up
);
1754 DP(NETIF_MSG_PROBE
, " PHY loopback failed (res %d)\n", res
);
1755 rc
|= BNX2X_PHY_LOOPBACK_FAILED
;
1758 res
= bnx2x_run_loopback(bp
, BNX2X_MAC_LOOPBACK
, link_up
);
1760 DP(NETIF_MSG_PROBE
, " MAC loopback failed (res %d)\n", res
);
1761 rc
|= BNX2X_MAC_LOOPBACK_FAILED
;
1764 bnx2x_release_phy_lock(bp
);
1765 bnx2x_netif_start(bp
);
1770 #define CRC32_RESIDUAL 0xdebb20e3
1772 static int bnx2x_test_nvram(struct bnx2x
*bp
)
1774 static const struct {
1778 { 0, 0x14 }, /* bootstrap */
1779 { 0x14, 0xec }, /* dir */
1780 { 0x100, 0x350 }, /* manuf_info */
1781 { 0x450, 0xf0 }, /* feature_info */
1782 { 0x640, 0x64 }, /* upgrade_key_info */
1783 { 0x708, 0x70 }, /* manuf_key_info */
1786 __be32 buf
[0x350 / 4];
1787 u8
*data
= (u8
*)buf
;
1794 rc
= bnx2x_nvram_read(bp
, 0, data
, 4);
1796 DP(NETIF_MSG_PROBE
, "magic value read (rc %d)\n", rc
);
1797 goto test_nvram_exit
;
1800 magic
= be32_to_cpu(buf
[0]);
1801 if (magic
!= 0x669955aa) {
1802 DP(NETIF_MSG_PROBE
, "magic value (0x%08x)\n", magic
);
1804 goto test_nvram_exit
;
1807 for (i
= 0; nvram_tbl
[i
].size
; i
++) {
1809 rc
= bnx2x_nvram_read(bp
, nvram_tbl
[i
].offset
, data
,
1813 "nvram_tbl[%d] read data (rc %d)\n", i
, rc
);
1814 goto test_nvram_exit
;
1817 crc
= ether_crc_le(nvram_tbl
[i
].size
, data
);
1818 if (crc
!= CRC32_RESIDUAL
) {
1820 "nvram_tbl[%d] crc value (0x%08x)\n", i
, crc
);
1822 goto test_nvram_exit
;
1830 static int bnx2x_test_intr(struct bnx2x
*bp
)
1832 struct mac_configuration_cmd
*config
= bnx2x_sp(bp
, mac_config
);
1835 if (!netif_running(bp
->dev
))
1838 config
->hdr
.length
= 0;
1840 config
->hdr
.offset
= (BP_PORT(bp
) ? 32 : 0);
1842 config
->hdr
.offset
= BP_FUNC(bp
);
1843 config
->hdr
.client_id
= bp
->fp
->cl_id
;
1844 config
->hdr
.reserved1
= 0;
1846 bp
->set_mac_pending
= 1;
1848 rc
= bnx2x_sp_post(bp
, RAMROD_CMD_ID_COMMON_SET_MAC
, 0,
1849 U64_HI(bnx2x_sp_mapping(bp
, mac_config
)),
1850 U64_LO(bnx2x_sp_mapping(bp
, mac_config
)), 1);
1852 for (i
= 0; i
< 10; i
++) {
1853 if (!bp
->set_mac_pending
)
1856 msleep_interruptible(10);
1865 static void bnx2x_self_test(struct net_device
*dev
,
1866 struct ethtool_test
*etest
, u64
*buf
)
1868 struct bnx2x
*bp
= netdev_priv(dev
);
1870 if (bp
->recovery_state
!= BNX2X_RECOVERY_DONE
) {
1871 printk(KERN_ERR
"Handling parity error recovery. Try again later\n");
1872 etest
->flags
|= ETH_TEST_FL_FAILED
;
1876 memset(buf
, 0, sizeof(u64
) * BNX2X_NUM_TESTS
);
1878 if (!netif_running(dev
))
1881 /* offline tests are not supported in MF mode */
1883 etest
->flags
&= ~ETH_TEST_FL_OFFLINE
;
1884 is_serdes
= (bp
->link_vars
.link_status
& LINK_STATUS_SERDES_LINK
) > 0;
1886 if (etest
->flags
& ETH_TEST_FL_OFFLINE
) {
1887 int port
= BP_PORT(bp
);
1891 /* save current value of input enable for TX port IF */
1892 val
= REG_RD(bp
, NIG_REG_EGRESS_UMP0_IN_EN
+ port
*4);
1893 /* disable input for TX port IF */
1894 REG_WR(bp
, NIG_REG_EGRESS_UMP0_IN_EN
+ port
*4, 0);
1896 link_up
= bp
->link_vars
.link_up
;
1898 bnx2x_nic_unload(bp
, UNLOAD_NORMAL
);
1899 bnx2x_nic_load(bp
, LOAD_DIAG
);
1900 /* wait until link state is restored */
1901 bnx2x_wait_for_link(bp
, link_up
, is_serdes
);
1903 if (bnx2x_test_registers(bp
) != 0) {
1905 etest
->flags
|= ETH_TEST_FL_FAILED
;
1907 if (bnx2x_test_memory(bp
) != 0) {
1909 etest
->flags
|= ETH_TEST_FL_FAILED
;
1912 buf
[2] = bnx2x_test_loopback(bp
, link_up
);
1914 etest
->flags
|= ETH_TEST_FL_FAILED
;
1916 bnx2x_nic_unload(bp
, UNLOAD_NORMAL
);
1918 /* restore input for TX port IF */
1919 REG_WR(bp
, NIG_REG_EGRESS_UMP0_IN_EN
+ port
*4, val
);
1921 bnx2x_nic_load(bp
, LOAD_NORMAL
);
1922 /* wait until link state is restored */
1923 bnx2x_wait_for_link(bp
, link_up
, is_serdes
);
1925 if (bnx2x_test_nvram(bp
) != 0) {
1927 etest
->flags
|= ETH_TEST_FL_FAILED
;
1929 if (bnx2x_test_intr(bp
) != 0) {
1931 etest
->flags
|= ETH_TEST_FL_FAILED
;
1934 if (bnx2x_link_test(bp
, is_serdes
) != 0) {
1936 etest
->flags
|= ETH_TEST_FL_FAILED
;
1939 #ifdef BNX2X_EXTRA_DEBUG
1940 bnx2x_panic_dump(bp
);
1944 #define IS_PORT_STAT(i) \
1945 ((bnx2x_stats_arr[i].flags & STATS_FLAGS_BOTH) == STATS_FLAGS_PORT)
1946 #define IS_FUNC_STAT(i) (bnx2x_stats_arr[i].flags & STATS_FLAGS_FUNC)
1947 #define IS_MF_MODE_STAT(bp) \
1948 (IS_MF(bp) && !(bp->msg_enable & BNX2X_MSG_STATS))
1950 static int bnx2x_get_sset_count(struct net_device
*dev
, int stringset
)
1952 struct bnx2x
*bp
= netdev_priv(dev
);
1955 switch (stringset
) {
1958 num_stats
= BNX2X_NUM_STAT_QUEUES(bp
) *
1960 if (!IS_MF_MODE_STAT(bp
))
1961 num_stats
+= BNX2X_NUM_STATS
;
1963 if (IS_MF_MODE_STAT(bp
)) {
1965 for (i
= 0; i
< BNX2X_NUM_STATS
; i
++)
1966 if (IS_FUNC_STAT(i
))
1969 num_stats
= BNX2X_NUM_STATS
;
1974 return BNX2X_NUM_TESTS
;
1981 static void bnx2x_get_strings(struct net_device
*dev
, u32 stringset
, u8
*buf
)
1983 struct bnx2x
*bp
= netdev_priv(dev
);
1985 char queue_name
[MAX_QUEUE_NAME_LEN
+1];
1987 switch (stringset
) {
1991 for_each_napi_queue(bp
, i
) {
1992 memset(queue_name
, 0, sizeof(queue_name
));
1995 sprintf(queue_name
, "fcoe");
1997 sprintf(queue_name
, "%d", i
);
1999 for (j
= 0; j
< BNX2X_NUM_Q_STATS
; j
++)
2000 snprintf(buf
+ (k
+ j
)*ETH_GSTRING_LEN
,
2002 bnx2x_q_stats_arr
[j
].string
,
2004 k
+= BNX2X_NUM_Q_STATS
;
2006 if (IS_MF_MODE_STAT(bp
))
2008 for (j
= 0; j
< BNX2X_NUM_STATS
; j
++)
2009 strcpy(buf
+ (k
+ j
)*ETH_GSTRING_LEN
,
2010 bnx2x_stats_arr
[j
].string
);
2012 for (i
= 0, j
= 0; i
< BNX2X_NUM_STATS
; i
++) {
2013 if (IS_MF_MODE_STAT(bp
) && IS_PORT_STAT(i
))
2015 strcpy(buf
+ j
*ETH_GSTRING_LEN
,
2016 bnx2x_stats_arr
[i
].string
);
2023 memcpy(buf
, bnx2x_tests_str_arr
, sizeof(bnx2x_tests_str_arr
));
2028 static void bnx2x_get_ethtool_stats(struct net_device
*dev
,
2029 struct ethtool_stats
*stats
, u64
*buf
)
2031 struct bnx2x
*bp
= netdev_priv(dev
);
2032 u32
*hw_stats
, *offset
;
2037 for_each_napi_queue(bp
, i
) {
2038 hw_stats
= (u32
*)&bp
->fp
[i
].eth_q_stats
;
2039 for (j
= 0; j
< BNX2X_NUM_Q_STATS
; j
++) {
2040 if (bnx2x_q_stats_arr
[j
].size
== 0) {
2041 /* skip this counter */
2045 offset
= (hw_stats
+
2046 bnx2x_q_stats_arr
[j
].offset
);
2047 if (bnx2x_q_stats_arr
[j
].size
== 4) {
2048 /* 4-byte counter */
2049 buf
[k
+ j
] = (u64
) *offset
;
2052 /* 8-byte counter */
2053 buf
[k
+ j
] = HILO_U64(*offset
, *(offset
+ 1));
2055 k
+= BNX2X_NUM_Q_STATS
;
2057 if (IS_MF_MODE_STAT(bp
))
2059 hw_stats
= (u32
*)&bp
->eth_stats
;
2060 for (j
= 0; j
< BNX2X_NUM_STATS
; j
++) {
2061 if (bnx2x_stats_arr
[j
].size
== 0) {
2062 /* skip this counter */
2066 offset
= (hw_stats
+ bnx2x_stats_arr
[j
].offset
);
2067 if (bnx2x_stats_arr
[j
].size
== 4) {
2068 /* 4-byte counter */
2069 buf
[k
+ j
] = (u64
) *offset
;
2072 /* 8-byte counter */
2073 buf
[k
+ j
] = HILO_U64(*offset
, *(offset
+ 1));
2076 hw_stats
= (u32
*)&bp
->eth_stats
;
2077 for (i
= 0, j
= 0; i
< BNX2X_NUM_STATS
; i
++) {
2078 if (IS_MF_MODE_STAT(bp
) && IS_PORT_STAT(i
))
2080 if (bnx2x_stats_arr
[i
].size
== 0) {
2081 /* skip this counter */
2086 offset
= (hw_stats
+ bnx2x_stats_arr
[i
].offset
);
2087 if (bnx2x_stats_arr
[i
].size
== 4) {
2088 /* 4-byte counter */
2089 buf
[j
] = (u64
) *offset
;
2093 /* 8-byte counter */
2094 buf
[j
] = HILO_U64(*offset
, *(offset
+ 1));
2100 static int bnx2x_phys_id(struct net_device
*dev
, u32 data
)
2102 struct bnx2x
*bp
= netdev_priv(dev
);
2105 if (!netif_running(dev
))
2114 for (i
= 0; i
< (data
* 2); i
++) {
2116 bnx2x_set_led(&bp
->link_params
, &bp
->link_vars
,
2117 LED_MODE_ON
, SPEED_1000
);
2119 bnx2x_set_led(&bp
->link_params
, &bp
->link_vars
,
2120 LED_MODE_FRONT_PANEL_OFF
, 0);
2122 msleep_interruptible(500);
2123 if (signal_pending(current
))
2127 bnx2x_set_led(&bp
->link_params
, &bp
->link_vars
,
2128 LED_MODE_OPER
, bp
->link_vars
.line_speed
);
2133 static int bnx2x_get_rxnfc(struct net_device
*dev
, struct ethtool_rxnfc
*info
,
2134 void *rules __always_unused
)
2136 struct bnx2x
*bp
= netdev_priv(dev
);
2138 switch (info
->cmd
) {
2139 case ETHTOOL_GRXRINGS
:
2140 info
->data
= BNX2X_NUM_ETH_QUEUES(bp
);
2148 static int bnx2x_get_rxfh_indir(struct net_device
*dev
,
2149 struct ethtool_rxfh_indir
*indir
)
2151 struct bnx2x
*bp
= netdev_priv(dev
);
2153 min_t(size_t, indir
->size
, TSTORM_INDIRECTION_TABLE_SIZE
);
2155 if (bp
->multi_mode
== ETH_RSS_MODE_DISABLED
)
2158 indir
->size
= TSTORM_INDIRECTION_TABLE_SIZE
;
2159 memcpy(indir
->ring_index
, bp
->rx_indir_table
,
2160 copy_size
* sizeof(bp
->rx_indir_table
[0]));
2164 static int bnx2x_set_rxfh_indir(struct net_device
*dev
,
2165 const struct ethtool_rxfh_indir
*indir
)
2167 struct bnx2x
*bp
= netdev_priv(dev
);
2170 if (bp
->multi_mode
== ETH_RSS_MODE_DISABLED
)
2173 /* Validate size and indices */
2174 if (indir
->size
!= TSTORM_INDIRECTION_TABLE_SIZE
)
2176 for (i
= 0; i
< TSTORM_INDIRECTION_TABLE_SIZE
; i
++)
2177 if (indir
->ring_index
[i
] >= BNX2X_NUM_ETH_QUEUES(bp
))
2180 memcpy(bp
->rx_indir_table
, indir
->ring_index
,
2181 indir
->size
* sizeof(bp
->rx_indir_table
[0]));
2182 bnx2x_push_indir_table(bp
);
2186 static const struct ethtool_ops bnx2x_ethtool_ops
= {
2187 .get_settings
= bnx2x_get_settings
,
2188 .set_settings
= bnx2x_set_settings
,
2189 .get_drvinfo
= bnx2x_get_drvinfo
,
2190 .get_regs_len
= bnx2x_get_regs_len
,
2191 .get_regs
= bnx2x_get_regs
,
2192 .get_wol
= bnx2x_get_wol
,
2193 .set_wol
= bnx2x_set_wol
,
2194 .get_msglevel
= bnx2x_get_msglevel
,
2195 .set_msglevel
= bnx2x_set_msglevel
,
2196 .nway_reset
= bnx2x_nway_reset
,
2197 .get_link
= bnx2x_get_link
,
2198 .get_eeprom_len
= bnx2x_get_eeprom_len
,
2199 .get_eeprom
= bnx2x_get_eeprom
,
2200 .set_eeprom
= bnx2x_set_eeprom
,
2201 .get_coalesce
= bnx2x_get_coalesce
,
2202 .set_coalesce
= bnx2x_set_coalesce
,
2203 .get_ringparam
= bnx2x_get_ringparam
,
2204 .set_ringparam
= bnx2x_set_ringparam
,
2205 .get_pauseparam
= bnx2x_get_pauseparam
,
2206 .set_pauseparam
= bnx2x_set_pauseparam
,
2207 .get_rx_csum
= bnx2x_get_rx_csum
,
2208 .set_rx_csum
= bnx2x_set_rx_csum
,
2209 .get_tx_csum
= ethtool_op_get_tx_csum
,
2210 .set_tx_csum
= ethtool_op_set_tx_hw_csum
,
2211 .set_flags
= bnx2x_set_flags
,
2212 .get_flags
= ethtool_op_get_flags
,
2213 .get_sg
= ethtool_op_get_sg
,
2214 .set_sg
= ethtool_op_set_sg
,
2215 .get_tso
= ethtool_op_get_tso
,
2216 .set_tso
= bnx2x_set_tso
,
2217 .self_test
= bnx2x_self_test
,
2218 .get_sset_count
= bnx2x_get_sset_count
,
2219 .get_strings
= bnx2x_get_strings
,
2220 .phys_id
= bnx2x_phys_id
,
2221 .get_ethtool_stats
= bnx2x_get_ethtool_stats
,
2222 .get_rxnfc
= bnx2x_get_rxnfc
,
2223 .get_rxfh_indir
= bnx2x_get_rxfh_indir
,
2224 .set_rxfh_indir
= bnx2x_set_rxfh_indir
,
2227 void bnx2x_set_ethtool_ops(struct net_device
*netdev
)
2229 SET_ETHTOOL_OPS(netdev
, &bnx2x_ethtool_ops
);