1 /* bnx2x_cmn.c: Broadcom Everest network driver.
3 * Copyright (c) 2007-2012 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/etherdevice.h>
21 #include <linux/if_vlan.h>
22 #include <linux/interrupt.h>
25 #include <net/ip6_checksum.h>
26 #include <linux/prefetch.h>
27 #include "bnx2x_cmn.h"
28 #include "bnx2x_init.h"
32 * bnx2x_move_fp - move content of the fastpath structure.
35 * @from: source FP index
36 * @to: destination FP index
38 * Makes sure the contents of the bp->fp[to].napi is kept
39 * intact. This is done by first copying the napi struct from
40 * the target to the source, and then mem copying the entire
41 * source onto the target. Update txdata pointers and related
44 static inline void bnx2x_move_fp(struct bnx2x
*bp
, int from
, int to
)
46 struct bnx2x_fastpath
*from_fp
= &bp
->fp
[from
];
47 struct bnx2x_fastpath
*to_fp
= &bp
->fp
[to
];
48 struct bnx2x_sp_objs
*from_sp_objs
= &bp
->sp_objs
[from
];
49 struct bnx2x_sp_objs
*to_sp_objs
= &bp
->sp_objs
[to
];
50 struct bnx2x_fp_stats
*from_fp_stats
= &bp
->fp_stats
[from
];
51 struct bnx2x_fp_stats
*to_fp_stats
= &bp
->fp_stats
[to
];
52 int old_max_eth_txqs
, new_max_eth_txqs
;
53 int old_txdata_index
= 0, new_txdata_index
= 0;
55 /* Copy the NAPI object as it has been already initialized */
56 from_fp
->napi
= to_fp
->napi
;
58 /* Move bnx2x_fastpath contents */
59 memcpy(to_fp
, from_fp
, sizeof(*to_fp
));
62 /* move sp_objs contents as well, as their indices match fp ones */
63 memcpy(to_sp_objs
, from_sp_objs
, sizeof(*to_sp_objs
));
65 /* move fp_stats contents as well, as their indices match fp ones */
66 memcpy(to_fp_stats
, from_fp_stats
, sizeof(*to_fp_stats
));
68 /* Update txdata pointers in fp and move txdata content accordingly:
69 * Each fp consumes 'max_cos' txdata structures, so the index should be
70 * decremented by max_cos x delta.
73 old_max_eth_txqs
= BNX2X_NUM_ETH_QUEUES(bp
) * (bp
)->max_cos
;
74 new_max_eth_txqs
= (BNX2X_NUM_ETH_QUEUES(bp
) - from
+ to
) *
76 if (from
== FCOE_IDX(bp
)) {
77 old_txdata_index
= old_max_eth_txqs
+ FCOE_TXQ_IDX_OFFSET
;
78 new_txdata_index
= new_max_eth_txqs
+ FCOE_TXQ_IDX_OFFSET
;
81 memcpy(&bp
->bnx2x_txq
[old_txdata_index
],
82 &bp
->bnx2x_txq
[new_txdata_index
],
83 sizeof(struct bnx2x_fp_txdata
));
84 to_fp
->txdata_ptr
[0] = &bp
->bnx2x_txq
[new_txdata_index
];
88 * bnx2x_fill_fw_str - Fill buffer with FW version string.
91 * @buf: character buffer to fill with the fw name
92 * @buf_len: length of the above buffer
95 void bnx2x_fill_fw_str(struct bnx2x
*bp
, char *buf
, size_t buf_len
)
98 u8 phy_fw_ver
[PHY_FW_VER_LEN
];
100 phy_fw_ver
[0] = '\0';
101 bnx2x_get_ext_phy_fw_version(&bp
->link_params
,
102 phy_fw_ver
, PHY_FW_VER_LEN
);
103 strlcpy(buf
, bp
->fw_ver
, buf_len
);
104 snprintf(buf
+ strlen(bp
->fw_ver
), 32 - strlen(bp
->fw_ver
),
106 (bp
->common
.bc_ver
& 0xff0000) >> 16,
107 (bp
->common
.bc_ver
& 0xff00) >> 8,
108 (bp
->common
.bc_ver
& 0xff),
109 ((phy_fw_ver
[0] != '\0') ? " phy " : ""), phy_fw_ver
);
111 bnx2x_vf_fill_fw_str(bp
, buf
, buf_len
);
115 int load_count
[2][3] = { {0} }; /* per-path: 0-common, 1-port0, 2-port1 */
117 /* free skb in the packet ring at pos idx
118 * return idx of last bd freed
120 static u16
bnx2x_free_tx_pkt(struct bnx2x
*bp
, struct bnx2x_fp_txdata
*txdata
,
121 u16 idx
, unsigned int *pkts_compl
,
122 unsigned int *bytes_compl
)
124 struct sw_tx_bd
*tx_buf
= &txdata
->tx_buf_ring
[idx
];
125 struct eth_tx_start_bd
*tx_start_bd
;
126 struct eth_tx_bd
*tx_data_bd
;
127 struct sk_buff
*skb
= tx_buf
->skb
;
128 u16 bd_idx
= TX_BD(tx_buf
->first_bd
), new_cons
;
131 /* prefetch skb end pointer to speedup dev_kfree_skb() */
134 DP(NETIF_MSG_TX_DONE
, "fp[%d]: pkt_idx %d buff @(%p)->skb %p\n",
135 txdata
->txq_index
, idx
, tx_buf
, skb
);
138 tx_start_bd
= &txdata
->tx_desc_ring
[bd_idx
].start_bd
;
139 dma_unmap_single(&bp
->pdev
->dev
, BD_UNMAP_ADDR(tx_start_bd
),
140 BD_UNMAP_LEN(tx_start_bd
), DMA_TO_DEVICE
);
143 nbd
= le16_to_cpu(tx_start_bd
->nbd
) - 1;
144 #ifdef BNX2X_STOP_ON_ERROR
145 if ((nbd
- 1) > (MAX_SKB_FRAGS
+ 2)) {
146 BNX2X_ERR("BAD nbd!\n");
150 new_cons
= nbd
+ tx_buf
->first_bd
;
152 /* Get the next bd */
153 bd_idx
= TX_BD(NEXT_TX_IDX(bd_idx
));
155 /* Skip a parse bd... */
157 bd_idx
= TX_BD(NEXT_TX_IDX(bd_idx
));
159 /* ...and the TSO split header bd since they have no mapping */
160 if (tx_buf
->flags
& BNX2X_TSO_SPLIT_BD
) {
162 bd_idx
= TX_BD(NEXT_TX_IDX(bd_idx
));
168 tx_data_bd
= &txdata
->tx_desc_ring
[bd_idx
].reg_bd
;
169 dma_unmap_page(&bp
->pdev
->dev
, BD_UNMAP_ADDR(tx_data_bd
),
170 BD_UNMAP_LEN(tx_data_bd
), DMA_TO_DEVICE
);
172 bd_idx
= TX_BD(NEXT_TX_IDX(bd_idx
));
179 (*bytes_compl
) += skb
->len
;
182 dev_kfree_skb_any(skb
);
183 tx_buf
->first_bd
= 0;
189 int bnx2x_tx_int(struct bnx2x
*bp
, struct bnx2x_fp_txdata
*txdata
)
191 struct netdev_queue
*txq
;
192 u16 hw_cons
, sw_cons
, bd_cons
= txdata
->tx_bd_cons
;
193 unsigned int pkts_compl
= 0, bytes_compl
= 0;
195 #ifdef BNX2X_STOP_ON_ERROR
196 if (unlikely(bp
->panic
))
200 txq
= netdev_get_tx_queue(bp
->dev
, txdata
->txq_index
);
201 hw_cons
= le16_to_cpu(*txdata
->tx_cons_sb
);
202 sw_cons
= txdata
->tx_pkt_cons
;
204 while (sw_cons
!= hw_cons
) {
207 pkt_cons
= TX_BD(sw_cons
);
209 DP(NETIF_MSG_TX_DONE
,
210 "queue[%d]: hw_cons %u sw_cons %u pkt_cons %u\n",
211 txdata
->txq_index
, hw_cons
, sw_cons
, pkt_cons
);
213 bd_cons
= bnx2x_free_tx_pkt(bp
, txdata
, pkt_cons
,
214 &pkts_compl
, &bytes_compl
);
219 netdev_tx_completed_queue(txq
, pkts_compl
, bytes_compl
);
221 txdata
->tx_pkt_cons
= sw_cons
;
222 txdata
->tx_bd_cons
= bd_cons
;
224 /* Need to make the tx_bd_cons update visible to start_xmit()
225 * before checking for netif_tx_queue_stopped(). Without the
226 * memory barrier, there is a small possibility that
227 * start_xmit() will miss it and cause the queue to be stopped
229 * On the other hand we need an rmb() here to ensure the proper
230 * ordering of bit testing in the following
231 * netif_tx_queue_stopped(txq) call.
235 if (unlikely(netif_tx_queue_stopped(txq
))) {
236 /* Taking tx_lock() is needed to prevent reenabling the queue
237 * while it's empty. This could have happen if rx_action() gets
238 * suspended in bnx2x_tx_int() after the condition before
239 * netif_tx_wake_queue(), while tx_action (bnx2x_start_xmit()):
241 * stops the queue->sees fresh tx_bd_cons->releases the queue->
242 * sends some packets consuming the whole queue again->
246 __netif_tx_lock(txq
, smp_processor_id());
248 if ((netif_tx_queue_stopped(txq
)) &&
249 (bp
->state
== BNX2X_STATE_OPEN
) &&
250 (bnx2x_tx_avail(bp
, txdata
) >= MAX_DESC_PER_TX_PKT
))
251 netif_tx_wake_queue(txq
);
253 __netif_tx_unlock(txq
);
258 static inline void bnx2x_update_last_max_sge(struct bnx2x_fastpath
*fp
,
261 u16 last_max
= fp
->last_max_sge
;
263 if (SUB_S16(idx
, last_max
) > 0)
264 fp
->last_max_sge
= idx
;
267 static inline void bnx2x_update_sge_prod(struct bnx2x_fastpath
*fp
,
269 struct eth_end_agg_rx_cqe
*cqe
)
271 struct bnx2x
*bp
= fp
->bp
;
272 u16 last_max
, last_elem
, first_elem
;
279 /* First mark all used pages */
280 for (i
= 0; i
< sge_len
; i
++)
281 BIT_VEC64_CLEAR_BIT(fp
->sge_mask
,
282 RX_SGE(le16_to_cpu(cqe
->sgl_or_raw_data
.sgl
[i
])));
284 DP(NETIF_MSG_RX_STATUS
, "fp_cqe->sgl[%d] = %d\n",
285 sge_len
- 1, le16_to_cpu(cqe
->sgl_or_raw_data
.sgl
[sge_len
- 1]));
287 /* Here we assume that the last SGE index is the biggest */
288 prefetch((void *)(fp
->sge_mask
));
289 bnx2x_update_last_max_sge(fp
,
290 le16_to_cpu(cqe
->sgl_or_raw_data
.sgl
[sge_len
- 1]));
292 last_max
= RX_SGE(fp
->last_max_sge
);
293 last_elem
= last_max
>> BIT_VEC64_ELEM_SHIFT
;
294 first_elem
= RX_SGE(fp
->rx_sge_prod
) >> BIT_VEC64_ELEM_SHIFT
;
296 /* If ring is not full */
297 if (last_elem
+ 1 != first_elem
)
300 /* Now update the prod */
301 for (i
= first_elem
; i
!= last_elem
; i
= NEXT_SGE_MASK_ELEM(i
)) {
302 if (likely(fp
->sge_mask
[i
]))
305 fp
->sge_mask
[i
] = BIT_VEC64_ELEM_ONE_MASK
;
306 delta
+= BIT_VEC64_ELEM_SZ
;
310 fp
->rx_sge_prod
+= delta
;
311 /* clear page-end entries */
312 bnx2x_clear_sge_mask_next_elems(fp
);
315 DP(NETIF_MSG_RX_STATUS
,
316 "fp->last_max_sge = %d fp->rx_sge_prod = %d\n",
317 fp
->last_max_sge
, fp
->rx_sge_prod
);
320 /* Set Toeplitz hash value in the skb using the value from the
321 * CQE (calculated by HW).
323 static u32
bnx2x_get_rxhash(const struct bnx2x
*bp
,
324 const struct eth_fast_path_rx_cqe
*cqe
,
327 /* Set Toeplitz hash from CQE */
328 if ((bp
->dev
->features
& NETIF_F_RXHASH
) &&
329 (cqe
->status_flags
& ETH_FAST_PATH_RX_CQE_RSS_HASH_FLG
)) {
330 enum eth_rss_hash_type htype
;
332 htype
= cqe
->status_flags
& ETH_FAST_PATH_RX_CQE_RSS_HASH_TYPE
;
333 *l4_rxhash
= (htype
== TCP_IPV4_HASH_TYPE
) ||
334 (htype
== TCP_IPV6_HASH_TYPE
);
335 return le32_to_cpu(cqe
->rss_hash_result
);
341 static void bnx2x_tpa_start(struct bnx2x_fastpath
*fp
, u16 queue
,
343 struct eth_fast_path_rx_cqe
*cqe
)
345 struct bnx2x
*bp
= fp
->bp
;
346 struct sw_rx_bd
*cons_rx_buf
= &fp
->rx_buf_ring
[cons
];
347 struct sw_rx_bd
*prod_rx_buf
= &fp
->rx_buf_ring
[prod
];
348 struct eth_rx_bd
*prod_bd
= &fp
->rx_desc_ring
[prod
];
350 struct bnx2x_agg_info
*tpa_info
= &fp
->tpa_info
[queue
];
351 struct sw_rx_bd
*first_buf
= &tpa_info
->first_buf
;
353 /* print error if current state != stop */
354 if (tpa_info
->tpa_state
!= BNX2X_TPA_STOP
)
355 BNX2X_ERR("start of bin not in stop [%d]\n", queue
);
357 /* Try to map an empty data buffer from the aggregation info */
358 mapping
= dma_map_single(&bp
->pdev
->dev
,
359 first_buf
->data
+ NET_SKB_PAD
,
360 fp
->rx_buf_size
, DMA_FROM_DEVICE
);
362 * ...if it fails - move the skb from the consumer to the producer
363 * and set the current aggregation state as ERROR to drop it
364 * when TPA_STOP arrives.
367 if (unlikely(dma_mapping_error(&bp
->pdev
->dev
, mapping
))) {
368 /* Move the BD from the consumer to the producer */
369 bnx2x_reuse_rx_data(fp
, cons
, prod
);
370 tpa_info
->tpa_state
= BNX2X_TPA_ERROR
;
374 /* move empty data from pool to prod */
375 prod_rx_buf
->data
= first_buf
->data
;
376 dma_unmap_addr_set(prod_rx_buf
, mapping
, mapping
);
377 /* point prod_bd to new data */
378 prod_bd
->addr_hi
= cpu_to_le32(U64_HI(mapping
));
379 prod_bd
->addr_lo
= cpu_to_le32(U64_LO(mapping
));
381 /* move partial skb from cons to pool (don't unmap yet) */
382 *first_buf
= *cons_rx_buf
;
384 /* mark bin state as START */
385 tpa_info
->parsing_flags
=
386 le16_to_cpu(cqe
->pars_flags
.flags
);
387 tpa_info
->vlan_tag
= le16_to_cpu(cqe
->vlan_tag
);
388 tpa_info
->tpa_state
= BNX2X_TPA_START
;
389 tpa_info
->len_on_bd
= le16_to_cpu(cqe
->len_on_bd
);
390 tpa_info
->placement_offset
= cqe
->placement_offset
;
391 tpa_info
->rxhash
= bnx2x_get_rxhash(bp
, cqe
, &tpa_info
->l4_rxhash
);
392 if (fp
->mode
== TPA_MODE_GRO
) {
393 u16 gro_size
= le16_to_cpu(cqe
->pkt_len_or_gro_seg_len
);
394 tpa_info
->full_page
=
395 SGE_PAGE_SIZE
* PAGES_PER_SGE
/ gro_size
* gro_size
;
396 tpa_info
->gro_size
= gro_size
;
399 #ifdef BNX2X_STOP_ON_ERROR
400 fp
->tpa_queue_used
|= (1 << queue
);
401 #ifdef _ASM_GENERIC_INT_L64_H
402 DP(NETIF_MSG_RX_STATUS
, "fp->tpa_queue_used = 0x%lx\n",
404 DP(NETIF_MSG_RX_STATUS
, "fp->tpa_queue_used = 0x%llx\n",
410 /* Timestamp option length allowed for TPA aggregation:
412 * nop nop kind length echo val
414 #define TPA_TSTAMP_OPT_LEN 12
416 * bnx2x_set_lro_mss - calculate the approximate value of the MSS
419 * @parsing_flags: parsing flags from the START CQE
420 * @len_on_bd: total length of the first packet for the
423 * Approximate value of the MSS for this aggregation calculated using
424 * the first packet of it.
426 static u16
bnx2x_set_lro_mss(struct bnx2x
*bp
, u16 parsing_flags
,
430 * TPA arrgregation won't have either IP options or TCP options
431 * other than timestamp or IPv6 extension headers.
433 u16 hdrs_len
= ETH_HLEN
+ sizeof(struct tcphdr
);
435 if (GET_FLAG(parsing_flags
, PARSING_FLAGS_OVER_ETHERNET_PROTOCOL
) ==
436 PRS_FLAG_OVERETH_IPV6
)
437 hdrs_len
+= sizeof(struct ipv6hdr
);
439 hdrs_len
+= sizeof(struct iphdr
);
442 /* Check if there was a TCP timestamp, if there is it's will
443 * always be 12 bytes length: nop nop kind length echo val.
445 * Otherwise FW would close the aggregation.
447 if (parsing_flags
& PARSING_FLAGS_TIME_STAMP_EXIST_FLAG
)
448 hdrs_len
+= TPA_TSTAMP_OPT_LEN
;
450 return len_on_bd
- hdrs_len
;
453 static int bnx2x_alloc_rx_sge(struct bnx2x
*bp
,
454 struct bnx2x_fastpath
*fp
, u16 index
)
456 struct page
*page
= alloc_pages(GFP_ATOMIC
, PAGES_PER_SGE_SHIFT
);
457 struct sw_rx_page
*sw_buf
= &fp
->rx_page_ring
[index
];
458 struct eth_rx_sge
*sge
= &fp
->rx_sge_ring
[index
];
461 if (unlikely(page
== NULL
)) {
462 BNX2X_ERR("Can't alloc sge\n");
466 mapping
= dma_map_page(&bp
->pdev
->dev
, page
, 0,
467 SGE_PAGE_SIZE
*PAGES_PER_SGE
, DMA_FROM_DEVICE
);
468 if (unlikely(dma_mapping_error(&bp
->pdev
->dev
, mapping
))) {
469 __free_pages(page
, PAGES_PER_SGE_SHIFT
);
470 BNX2X_ERR("Can't map sge\n");
475 dma_unmap_addr_set(sw_buf
, mapping
, mapping
);
477 sge
->addr_hi
= cpu_to_le32(U64_HI(mapping
));
478 sge
->addr_lo
= cpu_to_le32(U64_LO(mapping
));
483 static int bnx2x_fill_frag_skb(struct bnx2x
*bp
, struct bnx2x_fastpath
*fp
,
484 struct bnx2x_agg_info
*tpa_info
,
487 struct eth_end_agg_rx_cqe
*cqe
,
490 struct sw_rx_page
*rx_pg
, old_rx_pg
;
491 u32 i
, frag_len
, frag_size
;
492 int err
, j
, frag_id
= 0;
493 u16 len_on_bd
= tpa_info
->len_on_bd
;
494 u16 full_page
= 0, gro_size
= 0;
496 frag_size
= le16_to_cpu(cqe
->pkt_len
) - len_on_bd
;
498 if (fp
->mode
== TPA_MODE_GRO
) {
499 gro_size
= tpa_info
->gro_size
;
500 full_page
= tpa_info
->full_page
;
503 /* This is needed in order to enable forwarding support */
505 skb_shinfo(skb
)->gso_size
= bnx2x_set_lro_mss(bp
,
506 tpa_info
->parsing_flags
, len_on_bd
);
509 if (fp
->mode
== TPA_MODE_GRO
)
510 skb_shinfo(skb
)->gso_type
=
511 (GET_FLAG(tpa_info
->parsing_flags
,
512 PARSING_FLAGS_OVER_ETHERNET_PROTOCOL
) ==
513 PRS_FLAG_OVERETH_IPV6
) ?
514 SKB_GSO_TCPV6
: SKB_GSO_TCPV4
;
518 #ifdef BNX2X_STOP_ON_ERROR
519 if (pages
> min_t(u32
, 8, MAX_SKB_FRAGS
)*SGE_PAGE_SIZE
*PAGES_PER_SGE
) {
520 BNX2X_ERR("SGL length is too long: %d. CQE index is %d\n",
522 BNX2X_ERR("cqe->pkt_len = %d\n", cqe
->pkt_len
);
528 /* Run through the SGL and compose the fragmented skb */
529 for (i
= 0, j
= 0; i
< pages
; i
+= PAGES_PER_SGE
, j
++) {
530 u16 sge_idx
= RX_SGE(le16_to_cpu(cqe
->sgl_or_raw_data
.sgl
[j
]));
532 /* FW gives the indices of the SGE as if the ring is an array
533 (meaning that "next" element will consume 2 indices) */
534 if (fp
->mode
== TPA_MODE_GRO
)
535 frag_len
= min_t(u32
, frag_size
, (u32
)full_page
);
537 frag_len
= min_t(u32
, frag_size
,
538 (u32
)(SGE_PAGE_SIZE
* PAGES_PER_SGE
));
540 rx_pg
= &fp
->rx_page_ring
[sge_idx
];
543 /* If we fail to allocate a substitute page, we simply stop
544 where we are and drop the whole packet */
545 err
= bnx2x_alloc_rx_sge(bp
, fp
, sge_idx
);
547 bnx2x_fp_qstats(bp
, fp
)->rx_skb_alloc_failed
++;
551 /* Unmap the page as we r going to pass it to the stack */
552 dma_unmap_page(&bp
->pdev
->dev
,
553 dma_unmap_addr(&old_rx_pg
, mapping
),
554 SGE_PAGE_SIZE
*PAGES_PER_SGE
, DMA_FROM_DEVICE
);
555 /* Add one frag and update the appropriate fields in the skb */
556 if (fp
->mode
== TPA_MODE_LRO
)
557 skb_fill_page_desc(skb
, j
, old_rx_pg
.page
, 0, frag_len
);
561 for (rem
= frag_len
; rem
> 0; rem
-= gro_size
) {
562 int len
= rem
> gro_size
? gro_size
: rem
;
563 skb_fill_page_desc(skb
, frag_id
++,
564 old_rx_pg
.page
, offset
, len
);
566 get_page(old_rx_pg
.page
);
571 skb
->data_len
+= frag_len
;
572 skb
->truesize
+= SGE_PAGE_SIZE
* PAGES_PER_SGE
;
573 skb
->len
+= frag_len
;
575 frag_size
-= frag_len
;
581 static void bnx2x_frag_free(const struct bnx2x_fastpath
*fp
, void *data
)
583 if (fp
->rx_frag_size
)
584 put_page(virt_to_head_page(data
));
589 static void *bnx2x_frag_alloc(const struct bnx2x_fastpath
*fp
)
591 if (fp
->rx_frag_size
)
592 return netdev_alloc_frag(fp
->rx_frag_size
);
594 return kmalloc(fp
->rx_buf_size
+ NET_SKB_PAD
, GFP_ATOMIC
);
598 static void bnx2x_tpa_stop(struct bnx2x
*bp
, struct bnx2x_fastpath
*fp
,
599 struct bnx2x_agg_info
*tpa_info
,
601 struct eth_end_agg_rx_cqe
*cqe
,
604 struct sw_rx_bd
*rx_buf
= &tpa_info
->first_buf
;
605 u8 pad
= tpa_info
->placement_offset
;
606 u16 len
= tpa_info
->len_on_bd
;
607 struct sk_buff
*skb
= NULL
;
608 u8
*new_data
, *data
= rx_buf
->data
;
609 u8 old_tpa_state
= tpa_info
->tpa_state
;
611 tpa_info
->tpa_state
= BNX2X_TPA_STOP
;
613 /* If we there was an error during the handling of the TPA_START -
614 * drop this aggregation.
616 if (old_tpa_state
== BNX2X_TPA_ERROR
)
619 /* Try to allocate the new data */
620 new_data
= bnx2x_frag_alloc(fp
);
621 /* Unmap skb in the pool anyway, as we are going to change
622 pool entry status to BNX2X_TPA_STOP even if new skb allocation
624 dma_unmap_single(&bp
->pdev
->dev
, dma_unmap_addr(rx_buf
, mapping
),
625 fp
->rx_buf_size
, DMA_FROM_DEVICE
);
626 if (likely(new_data
))
627 skb
= build_skb(data
, fp
->rx_frag_size
);
630 #ifdef BNX2X_STOP_ON_ERROR
631 if (pad
+ len
> fp
->rx_buf_size
) {
632 BNX2X_ERR("skb_put is about to fail... pad %d len %d rx_buf_size %d\n",
633 pad
, len
, fp
->rx_buf_size
);
639 skb_reserve(skb
, pad
+ NET_SKB_PAD
);
641 skb
->rxhash
= tpa_info
->rxhash
;
642 skb
->l4_rxhash
= tpa_info
->l4_rxhash
;
644 skb
->protocol
= eth_type_trans(skb
, bp
->dev
);
645 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
647 if (!bnx2x_fill_frag_skb(bp
, fp
, tpa_info
, pages
,
648 skb
, cqe
, cqe_idx
)) {
649 if (tpa_info
->parsing_flags
& PARSING_FLAGS_VLAN
)
650 __vlan_hwaccel_put_tag(skb
, tpa_info
->vlan_tag
);
651 napi_gro_receive(&fp
->napi
, skb
);
653 DP(NETIF_MSG_RX_STATUS
,
654 "Failed to allocate new pages - dropping packet!\n");
655 dev_kfree_skb_any(skb
);
659 /* put new data in bin */
660 rx_buf
->data
= new_data
;
664 bnx2x_frag_free(fp
, new_data
);
666 /* drop the packet and keep the buffer in the bin */
667 DP(NETIF_MSG_RX_STATUS
,
668 "Failed to allocate or map a new skb - dropping packet!\n");
669 bnx2x_fp_stats(bp
, fp
)->eth_q_stats
.rx_skb_alloc_failed
++;
672 static int bnx2x_alloc_rx_data(struct bnx2x
*bp
,
673 struct bnx2x_fastpath
*fp
, u16 index
)
676 struct sw_rx_bd
*rx_buf
= &fp
->rx_buf_ring
[index
];
677 struct eth_rx_bd
*rx_bd
= &fp
->rx_desc_ring
[index
];
680 data
= bnx2x_frag_alloc(fp
);
681 if (unlikely(data
== NULL
))
684 mapping
= dma_map_single(&bp
->pdev
->dev
, data
+ NET_SKB_PAD
,
687 if (unlikely(dma_mapping_error(&bp
->pdev
->dev
, mapping
))) {
688 bnx2x_frag_free(fp
, data
);
689 BNX2X_ERR("Can't map rx data\n");
694 dma_unmap_addr_set(rx_buf
, mapping
, mapping
);
696 rx_bd
->addr_hi
= cpu_to_le32(U64_HI(mapping
));
697 rx_bd
->addr_lo
= cpu_to_le32(U64_LO(mapping
));
703 void bnx2x_csum_validate(struct sk_buff
*skb
, union eth_rx_cqe
*cqe
,
704 struct bnx2x_fastpath
*fp
,
705 struct bnx2x_eth_q_stats
*qstats
)
707 /* Do nothing if no L4 csum validation was done.
708 * We do not check whether IP csum was validated. For IPv4 we assume
709 * that if the card got as far as validating the L4 csum, it also
710 * validated the IP csum. IPv6 has no IP csum.
712 if (cqe
->fast_path_cqe
.status_flags
&
713 ETH_FAST_PATH_RX_CQE_L4_XSUM_NO_VALIDATION_FLG
)
716 /* If L4 validation was done, check if an error was found. */
718 if (cqe
->fast_path_cqe
.type_error_flags
&
719 (ETH_FAST_PATH_RX_CQE_IP_BAD_XSUM_FLG
|
720 ETH_FAST_PATH_RX_CQE_L4_BAD_XSUM_FLG
))
721 qstats
->hw_csum_err
++;
723 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
726 int bnx2x_rx_int(struct bnx2x_fastpath
*fp
, int budget
)
728 struct bnx2x
*bp
= fp
->bp
;
729 u16 bd_cons
, bd_prod
, bd_prod_fw
, comp_ring_cons
;
730 u16 hw_comp_cons
, sw_comp_cons
, sw_comp_prod
;
733 #ifdef BNX2X_STOP_ON_ERROR
734 if (unlikely(bp
->panic
))
738 /* CQ "next element" is of the size of the regular element,
739 that's why it's ok here */
740 hw_comp_cons
= le16_to_cpu(*fp
->rx_cons_sb
);
741 if ((hw_comp_cons
& MAX_RCQ_DESC_CNT
) == MAX_RCQ_DESC_CNT
)
744 bd_cons
= fp
->rx_bd_cons
;
745 bd_prod
= fp
->rx_bd_prod
;
746 bd_prod_fw
= bd_prod
;
747 sw_comp_cons
= fp
->rx_comp_cons
;
748 sw_comp_prod
= fp
->rx_comp_prod
;
750 /* Memory barrier necessary as speculative reads of the rx
751 * buffer can be ahead of the index in the status block
755 DP(NETIF_MSG_RX_STATUS
,
756 "queue[%d]: hw_comp_cons %u sw_comp_cons %u\n",
757 fp
->index
, hw_comp_cons
, sw_comp_cons
);
759 while (sw_comp_cons
!= hw_comp_cons
) {
760 struct sw_rx_bd
*rx_buf
= NULL
;
762 union eth_rx_cqe
*cqe
;
763 struct eth_fast_path_rx_cqe
*cqe_fp
;
765 enum eth_rx_cqe_type cqe_fp_type
;
770 #ifdef BNX2X_STOP_ON_ERROR
771 if (unlikely(bp
->panic
))
775 comp_ring_cons
= RCQ_BD(sw_comp_cons
);
776 bd_prod
= RX_BD(bd_prod
);
777 bd_cons
= RX_BD(bd_cons
);
779 cqe
= &fp
->rx_comp_ring
[comp_ring_cons
];
780 cqe_fp
= &cqe
->fast_path_cqe
;
781 cqe_fp_flags
= cqe_fp
->type_error_flags
;
782 cqe_fp_type
= cqe_fp_flags
& ETH_FAST_PATH_RX_CQE_TYPE
;
784 DP(NETIF_MSG_RX_STATUS
,
785 "CQE type %x err %x status %x queue %x vlan %x len %u\n",
786 CQE_TYPE(cqe_fp_flags
),
787 cqe_fp_flags
, cqe_fp
->status_flags
,
788 le32_to_cpu(cqe_fp
->rss_hash_result
),
789 le16_to_cpu(cqe_fp
->vlan_tag
),
790 le16_to_cpu(cqe_fp
->pkt_len_or_gro_seg_len
));
792 /* is this a slowpath msg? */
793 if (unlikely(CQE_TYPE_SLOW(cqe_fp_type
))) {
794 bnx2x_sp_event(fp
, cqe
);
798 rx_buf
= &fp
->rx_buf_ring
[bd_cons
];
801 if (!CQE_TYPE_FAST(cqe_fp_type
)) {
802 struct bnx2x_agg_info
*tpa_info
;
803 u16 frag_size
, pages
;
804 #ifdef BNX2X_STOP_ON_ERROR
806 if (fp
->disable_tpa
&&
807 (CQE_TYPE_START(cqe_fp_type
) ||
808 CQE_TYPE_STOP(cqe_fp_type
)))
809 BNX2X_ERR("START/STOP packet while disable_tpa type %x\n",
810 CQE_TYPE(cqe_fp_type
));
813 if (CQE_TYPE_START(cqe_fp_type
)) {
814 u16 queue
= cqe_fp
->queue_index
;
815 DP(NETIF_MSG_RX_STATUS
,
816 "calling tpa_start on queue %d\n",
819 bnx2x_tpa_start(fp
, queue
,
826 queue
= cqe
->end_agg_cqe
.queue_index
;
827 tpa_info
= &fp
->tpa_info
[queue
];
828 DP(NETIF_MSG_RX_STATUS
,
829 "calling tpa_stop on queue %d\n",
832 frag_size
= le16_to_cpu(cqe
->end_agg_cqe
.pkt_len
) -
835 if (fp
->mode
== TPA_MODE_GRO
)
836 pages
= (frag_size
+ tpa_info
->full_page
- 1) /
839 pages
= SGE_PAGE_ALIGN(frag_size
) >>
842 bnx2x_tpa_stop(bp
, fp
, tpa_info
, pages
,
843 &cqe
->end_agg_cqe
, comp_ring_cons
);
844 #ifdef BNX2X_STOP_ON_ERROR
849 bnx2x_update_sge_prod(fp
, pages
, &cqe
->end_agg_cqe
);
853 len
= le16_to_cpu(cqe_fp
->pkt_len_or_gro_seg_len
);
854 pad
= cqe_fp
->placement_offset
;
855 dma_sync_single_for_cpu(&bp
->pdev
->dev
,
856 dma_unmap_addr(rx_buf
, mapping
),
857 pad
+ RX_COPY_THRESH
,
860 prefetch(data
+ pad
); /* speedup eth_type_trans() */
861 /* is this an error packet? */
862 if (unlikely(cqe_fp_flags
& ETH_RX_ERROR_FALGS
)) {
863 DP(NETIF_MSG_RX_ERR
| NETIF_MSG_RX_STATUS
,
864 "ERROR flags %x rx packet %u\n",
865 cqe_fp_flags
, sw_comp_cons
);
866 bnx2x_fp_qstats(bp
, fp
)->rx_err_discard_pkt
++;
870 /* Since we don't have a jumbo ring
871 * copy small packets if mtu > 1500
873 if ((bp
->dev
->mtu
> ETH_MAX_PACKET_SIZE
) &&
874 (len
<= RX_COPY_THRESH
)) {
875 skb
= netdev_alloc_skb_ip_align(bp
->dev
, len
);
877 DP(NETIF_MSG_RX_ERR
| NETIF_MSG_RX_STATUS
,
878 "ERROR packet dropped because of alloc failure\n");
879 bnx2x_fp_qstats(bp
, fp
)->rx_skb_alloc_failed
++;
882 memcpy(skb
->data
, data
+ pad
, len
);
883 bnx2x_reuse_rx_data(fp
, bd_cons
, bd_prod
);
885 if (likely(bnx2x_alloc_rx_data(bp
, fp
, bd_prod
) == 0)) {
886 dma_unmap_single(&bp
->pdev
->dev
,
887 dma_unmap_addr(rx_buf
, mapping
),
890 skb
= build_skb(data
, fp
->rx_frag_size
);
891 if (unlikely(!skb
)) {
892 bnx2x_frag_free(fp
, data
);
893 bnx2x_fp_qstats(bp
, fp
)->
894 rx_skb_alloc_failed
++;
897 skb_reserve(skb
, pad
);
899 DP(NETIF_MSG_RX_ERR
| NETIF_MSG_RX_STATUS
,
900 "ERROR packet dropped because of alloc failure\n");
901 bnx2x_fp_qstats(bp
, fp
)->rx_skb_alloc_failed
++;
903 bnx2x_reuse_rx_data(fp
, bd_cons
, bd_prod
);
909 skb
->protocol
= eth_type_trans(skb
, bp
->dev
);
911 /* Set Toeplitz hash for a none-LRO skb */
912 skb
->rxhash
= bnx2x_get_rxhash(bp
, cqe_fp
, &l4_rxhash
);
913 skb
->l4_rxhash
= l4_rxhash
;
915 skb_checksum_none_assert(skb
);
917 if (bp
->dev
->features
& NETIF_F_RXCSUM
)
918 bnx2x_csum_validate(skb
, cqe
, fp
,
919 bnx2x_fp_qstats(bp
, fp
));
921 skb_record_rx_queue(skb
, fp
->rx_queue
);
923 if (le16_to_cpu(cqe_fp
->pars_flags
.flags
) &
925 __vlan_hwaccel_put_tag(skb
,
926 le16_to_cpu(cqe_fp
->vlan_tag
));
927 napi_gro_receive(&fp
->napi
, skb
);
933 bd_cons
= NEXT_RX_IDX(bd_cons
);
934 bd_prod
= NEXT_RX_IDX(bd_prod
);
935 bd_prod_fw
= NEXT_RX_IDX(bd_prod_fw
);
938 sw_comp_prod
= NEXT_RCQ_IDX(sw_comp_prod
);
939 sw_comp_cons
= NEXT_RCQ_IDX(sw_comp_cons
);
941 if (rx_pkt
== budget
)
945 fp
->rx_bd_cons
= bd_cons
;
946 fp
->rx_bd_prod
= bd_prod_fw
;
947 fp
->rx_comp_cons
= sw_comp_cons
;
948 fp
->rx_comp_prod
= sw_comp_prod
;
950 /* Update producers */
951 bnx2x_update_rx_prod(bp
, fp
, bd_prod_fw
, sw_comp_prod
,
954 fp
->rx_pkt
+= rx_pkt
;
960 static irqreturn_t
bnx2x_msix_fp_int(int irq
, void *fp_cookie
)
962 struct bnx2x_fastpath
*fp
= fp_cookie
;
963 struct bnx2x
*bp
= fp
->bp
;
967 "got an MSI-X interrupt on IDX:SB [fp %d fw_sd %d igusb %d]\n",
968 fp
->index
, fp
->fw_sb_id
, fp
->igu_sb_id
);
969 bnx2x_ack_sb(bp
, fp
->igu_sb_id
, USTORM_ID
, 0, IGU_INT_DISABLE
, 0);
971 #ifdef BNX2X_STOP_ON_ERROR
972 if (unlikely(bp
->panic
))
976 /* Handle Rx and Tx according to MSI-X vector */
977 prefetch(fp
->rx_cons_sb
);
979 for_each_cos_in_tx_queue(fp
, cos
)
980 prefetch(fp
->txdata_ptr
[cos
]->tx_cons_sb
);
982 prefetch(&fp
->sb_running_index
[SM_RX_ID
]);
983 napi_schedule(&bnx2x_fp(bp
, fp
->index
, napi
));
988 /* HW Lock for shared dual port PHYs */
989 void bnx2x_acquire_phy_lock(struct bnx2x
*bp
)
991 mutex_lock(&bp
->port
.phy_mutex
);
993 bnx2x_acquire_hw_lock(bp
, HW_LOCK_RESOURCE_MDIO
);
996 void bnx2x_release_phy_lock(struct bnx2x
*bp
)
998 bnx2x_release_hw_lock(bp
, HW_LOCK_RESOURCE_MDIO
);
1000 mutex_unlock(&bp
->port
.phy_mutex
);
1003 /* calculates MF speed according to current linespeed and MF configuration */
1004 u16
bnx2x_get_mf_speed(struct bnx2x
*bp
)
1006 u16 line_speed
= bp
->link_vars
.line_speed
;
1008 u16 maxCfg
= bnx2x_extract_max_cfg(bp
,
1009 bp
->mf_config
[BP_VN(bp
)]);
1011 /* Calculate the current MAX line speed limit for the MF
1015 line_speed
= (line_speed
* maxCfg
) / 100;
1016 else { /* SD mode */
1017 u16 vn_max_rate
= maxCfg
* 100;
1019 if (vn_max_rate
< line_speed
)
1020 line_speed
= vn_max_rate
;
1028 * bnx2x_fill_report_data - fill link report data to report
1030 * @bp: driver handle
1031 * @data: link state to update
1033 * It uses a none-atomic bit operations because is called under the mutex.
1035 static void bnx2x_fill_report_data(struct bnx2x
*bp
,
1036 struct bnx2x_link_report_data
*data
)
1038 u16 line_speed
= bnx2x_get_mf_speed(bp
);
1040 memset(data
, 0, sizeof(*data
));
1042 /* Fill the report data: efective line speed */
1043 data
->line_speed
= line_speed
;
1046 if (!bp
->link_vars
.link_up
|| (bp
->flags
& MF_FUNC_DIS
))
1047 __set_bit(BNX2X_LINK_REPORT_LINK_DOWN
,
1048 &data
->link_report_flags
);
1051 if (bp
->link_vars
.duplex
== DUPLEX_FULL
)
1052 __set_bit(BNX2X_LINK_REPORT_FD
, &data
->link_report_flags
);
1054 /* Rx Flow Control is ON */
1055 if (bp
->link_vars
.flow_ctrl
& BNX2X_FLOW_CTRL_RX
)
1056 __set_bit(BNX2X_LINK_REPORT_RX_FC_ON
, &data
->link_report_flags
);
1058 /* Tx Flow Control is ON */
1059 if (bp
->link_vars
.flow_ctrl
& BNX2X_FLOW_CTRL_TX
)
1060 __set_bit(BNX2X_LINK_REPORT_TX_FC_ON
, &data
->link_report_flags
);
1064 * bnx2x_link_report - report link status to OS.
1066 * @bp: driver handle
1068 * Calls the __bnx2x_link_report() under the same locking scheme
1069 * as a link/PHY state managing code to ensure a consistent link
1073 void bnx2x_link_report(struct bnx2x
*bp
)
1075 bnx2x_acquire_phy_lock(bp
);
1076 __bnx2x_link_report(bp
);
1077 bnx2x_release_phy_lock(bp
);
1081 * __bnx2x_link_report - report link status to OS.
1083 * @bp: driver handle
1085 * None atomic inmlementation.
1086 * Should be called under the phy_lock.
1088 void __bnx2x_link_report(struct bnx2x
*bp
)
1090 struct bnx2x_link_report_data cur_data
;
1093 if (IS_PF(bp
) && !CHIP_IS_E1(bp
))
1094 bnx2x_read_mf_cfg(bp
);
1096 /* Read the current link report info */
1097 bnx2x_fill_report_data(bp
, &cur_data
);
1099 /* Don't report link down or exactly the same link status twice */
1100 if (!memcmp(&cur_data
, &bp
->last_reported_link
, sizeof(cur_data
)) ||
1101 (test_bit(BNX2X_LINK_REPORT_LINK_DOWN
,
1102 &bp
->last_reported_link
.link_report_flags
) &&
1103 test_bit(BNX2X_LINK_REPORT_LINK_DOWN
,
1104 &cur_data
.link_report_flags
)))
1109 /* We are going to report a new link parameters now -
1110 * remember the current data for the next time.
1112 memcpy(&bp
->last_reported_link
, &cur_data
, sizeof(cur_data
));
1114 if (test_bit(BNX2X_LINK_REPORT_LINK_DOWN
,
1115 &cur_data
.link_report_flags
)) {
1116 netif_carrier_off(bp
->dev
);
1117 netdev_err(bp
->dev
, "NIC Link is Down\n");
1123 netif_carrier_on(bp
->dev
);
1125 if (test_and_clear_bit(BNX2X_LINK_REPORT_FD
,
1126 &cur_data
.link_report_flags
))
1131 /* Handle the FC at the end so that only these flags would be
1132 * possibly set. This way we may easily check if there is no FC
1135 if (cur_data
.link_report_flags
) {
1136 if (test_bit(BNX2X_LINK_REPORT_RX_FC_ON
,
1137 &cur_data
.link_report_flags
)) {
1138 if (test_bit(BNX2X_LINK_REPORT_TX_FC_ON
,
1139 &cur_data
.link_report_flags
))
1140 flow
= "ON - receive & transmit";
1142 flow
= "ON - receive";
1144 flow
= "ON - transmit";
1149 netdev_info(bp
->dev
, "NIC Link is Up, %d Mbps %s duplex, Flow control: %s\n",
1150 cur_data
.line_speed
, duplex
, flow
);
1154 static void bnx2x_set_next_page_sgl(struct bnx2x_fastpath
*fp
)
1158 for (i
= 1; i
<= NUM_RX_SGE_PAGES
; i
++) {
1159 struct eth_rx_sge
*sge
;
1161 sge
= &fp
->rx_sge_ring
[RX_SGE_CNT
* i
- 2];
1163 cpu_to_le32(U64_HI(fp
->rx_sge_mapping
+
1164 BCM_PAGE_SIZE
*(i
% NUM_RX_SGE_PAGES
)));
1167 cpu_to_le32(U64_LO(fp
->rx_sge_mapping
+
1168 BCM_PAGE_SIZE
*(i
% NUM_RX_SGE_PAGES
)));
1172 static void bnx2x_free_tpa_pool(struct bnx2x
*bp
,
1173 struct bnx2x_fastpath
*fp
, int last
)
1177 for (i
= 0; i
< last
; i
++) {
1178 struct bnx2x_agg_info
*tpa_info
= &fp
->tpa_info
[i
];
1179 struct sw_rx_bd
*first_buf
= &tpa_info
->first_buf
;
1180 u8
*data
= first_buf
->data
;
1183 DP(NETIF_MSG_IFDOWN
, "tpa bin %d empty on free\n", i
);
1186 if (tpa_info
->tpa_state
== BNX2X_TPA_START
)
1187 dma_unmap_single(&bp
->pdev
->dev
,
1188 dma_unmap_addr(first_buf
, mapping
),
1189 fp
->rx_buf_size
, DMA_FROM_DEVICE
);
1190 bnx2x_frag_free(fp
, data
);
1191 first_buf
->data
= NULL
;
1195 void bnx2x_init_rx_rings_cnic(struct bnx2x
*bp
)
1199 for_each_rx_queue_cnic(bp
, j
) {
1200 struct bnx2x_fastpath
*fp
= &bp
->fp
[j
];
1204 /* Activate BD ring */
1206 * this will generate an interrupt (to the TSTORM)
1207 * must only be done after chip is initialized
1209 bnx2x_update_rx_prod(bp
, fp
, fp
->rx_bd_prod
, fp
->rx_comp_prod
,
1214 void bnx2x_init_rx_rings(struct bnx2x
*bp
)
1216 int func
= BP_FUNC(bp
);
1220 /* Allocate TPA resources */
1221 for_each_eth_queue(bp
, j
) {
1222 struct bnx2x_fastpath
*fp
= &bp
->fp
[j
];
1225 "mtu %d rx_buf_size %d\n", bp
->dev
->mtu
, fp
->rx_buf_size
);
1227 if (!fp
->disable_tpa
) {
1228 /* Fill the per-aggregtion pool */
1229 for (i
= 0; i
< MAX_AGG_QS(bp
); i
++) {
1230 struct bnx2x_agg_info
*tpa_info
=
1232 struct sw_rx_bd
*first_buf
=
1233 &tpa_info
->first_buf
;
1235 first_buf
->data
= bnx2x_frag_alloc(fp
);
1236 if (!first_buf
->data
) {
1237 BNX2X_ERR("Failed to allocate TPA skb pool for queue[%d] - disabling TPA on this queue!\n",
1239 bnx2x_free_tpa_pool(bp
, fp
, i
);
1240 fp
->disable_tpa
= 1;
1243 dma_unmap_addr_set(first_buf
, mapping
, 0);
1244 tpa_info
->tpa_state
= BNX2X_TPA_STOP
;
1247 /* "next page" elements initialization */
1248 bnx2x_set_next_page_sgl(fp
);
1250 /* set SGEs bit mask */
1251 bnx2x_init_sge_ring_bit_mask(fp
);
1253 /* Allocate SGEs and initialize the ring elements */
1254 for (i
= 0, ring_prod
= 0;
1255 i
< MAX_RX_SGE_CNT
*NUM_RX_SGE_PAGES
; i
++) {
1257 if (bnx2x_alloc_rx_sge(bp
, fp
, ring_prod
) < 0) {
1258 BNX2X_ERR("was only able to allocate %d rx sges\n",
1260 BNX2X_ERR("disabling TPA for queue[%d]\n",
1262 /* Cleanup already allocated elements */
1263 bnx2x_free_rx_sge_range(bp
, fp
,
1265 bnx2x_free_tpa_pool(bp
, fp
,
1267 fp
->disable_tpa
= 1;
1271 ring_prod
= NEXT_SGE_IDX(ring_prod
);
1274 fp
->rx_sge_prod
= ring_prod
;
1278 for_each_eth_queue(bp
, j
) {
1279 struct bnx2x_fastpath
*fp
= &bp
->fp
[j
];
1283 /* Activate BD ring */
1285 * this will generate an interrupt (to the TSTORM)
1286 * must only be done after chip is initialized
1288 bnx2x_update_rx_prod(bp
, fp
, fp
->rx_bd_prod
, fp
->rx_comp_prod
,
1294 if (CHIP_IS_E1(bp
)) {
1295 REG_WR(bp
, BAR_USTRORM_INTMEM
+
1296 USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(func
),
1297 U64_LO(fp
->rx_comp_mapping
));
1298 REG_WR(bp
, BAR_USTRORM_INTMEM
+
1299 USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(func
) + 4,
1300 U64_HI(fp
->rx_comp_mapping
));
1305 static void bnx2x_free_tx_skbs_queue(struct bnx2x_fastpath
*fp
)
1308 struct bnx2x
*bp
= fp
->bp
;
1310 for_each_cos_in_tx_queue(fp
, cos
) {
1311 struct bnx2x_fp_txdata
*txdata
= fp
->txdata_ptr
[cos
];
1312 unsigned pkts_compl
= 0, bytes_compl
= 0;
1314 u16 sw_prod
= txdata
->tx_pkt_prod
;
1315 u16 sw_cons
= txdata
->tx_pkt_cons
;
1317 while (sw_cons
!= sw_prod
) {
1318 bnx2x_free_tx_pkt(bp
, txdata
, TX_BD(sw_cons
),
1319 &pkts_compl
, &bytes_compl
);
1323 netdev_tx_reset_queue(
1324 netdev_get_tx_queue(bp
->dev
,
1325 txdata
->txq_index
));
1329 static void bnx2x_free_tx_skbs_cnic(struct bnx2x
*bp
)
1333 for_each_tx_queue_cnic(bp
, i
) {
1334 bnx2x_free_tx_skbs_queue(&bp
->fp
[i
]);
1338 static void bnx2x_free_tx_skbs(struct bnx2x
*bp
)
1342 for_each_eth_queue(bp
, i
) {
1343 bnx2x_free_tx_skbs_queue(&bp
->fp
[i
]);
1347 static void bnx2x_free_rx_bds(struct bnx2x_fastpath
*fp
)
1349 struct bnx2x
*bp
= fp
->bp
;
1352 /* ring wasn't allocated */
1353 if (fp
->rx_buf_ring
== NULL
)
1356 for (i
= 0; i
< NUM_RX_BD
; i
++) {
1357 struct sw_rx_bd
*rx_buf
= &fp
->rx_buf_ring
[i
];
1358 u8
*data
= rx_buf
->data
;
1362 dma_unmap_single(&bp
->pdev
->dev
,
1363 dma_unmap_addr(rx_buf
, mapping
),
1364 fp
->rx_buf_size
, DMA_FROM_DEVICE
);
1366 rx_buf
->data
= NULL
;
1367 bnx2x_frag_free(fp
, data
);
1371 static void bnx2x_free_rx_skbs_cnic(struct bnx2x
*bp
)
1375 for_each_rx_queue_cnic(bp
, j
) {
1376 bnx2x_free_rx_bds(&bp
->fp
[j
]);
1380 static void bnx2x_free_rx_skbs(struct bnx2x
*bp
)
1384 for_each_eth_queue(bp
, j
) {
1385 struct bnx2x_fastpath
*fp
= &bp
->fp
[j
];
1387 bnx2x_free_rx_bds(fp
);
1389 if (!fp
->disable_tpa
)
1390 bnx2x_free_tpa_pool(bp
, fp
, MAX_AGG_QS(bp
));
1394 void bnx2x_free_skbs_cnic(struct bnx2x
*bp
)
1396 bnx2x_free_tx_skbs_cnic(bp
);
1397 bnx2x_free_rx_skbs_cnic(bp
);
1400 void bnx2x_free_skbs(struct bnx2x
*bp
)
1402 bnx2x_free_tx_skbs(bp
);
1403 bnx2x_free_rx_skbs(bp
);
1406 void bnx2x_update_max_mf_config(struct bnx2x
*bp
, u32 value
)
1408 /* load old values */
1409 u32 mf_cfg
= bp
->mf_config
[BP_VN(bp
)];
1411 if (value
!= bnx2x_extract_max_cfg(bp
, mf_cfg
)) {
1412 /* leave all but MAX value */
1413 mf_cfg
&= ~FUNC_MF_CFG_MAX_BW_MASK
;
1415 /* set new MAX value */
1416 mf_cfg
|= (value
<< FUNC_MF_CFG_MAX_BW_SHIFT
)
1417 & FUNC_MF_CFG_MAX_BW_MASK
;
1419 bnx2x_fw_command(bp
, DRV_MSG_CODE_SET_MF_BW
, mf_cfg
);
1424 * bnx2x_free_msix_irqs - free previously requested MSI-X IRQ vectors
1426 * @bp: driver handle
1427 * @nvecs: number of vectors to be released
1429 static void bnx2x_free_msix_irqs(struct bnx2x
*bp
, int nvecs
)
1433 if (nvecs
== offset
)
1436 /* VFs don't have a default SB */
1438 free_irq(bp
->msix_table
[offset
].vector
, bp
->dev
);
1439 DP(NETIF_MSG_IFDOWN
, "released sp irq (%d)\n",
1440 bp
->msix_table
[offset
].vector
);
1444 if (CNIC_SUPPORT(bp
)) {
1445 if (nvecs
== offset
)
1450 for_each_eth_queue(bp
, i
) {
1451 if (nvecs
== offset
)
1453 DP(NETIF_MSG_IFDOWN
, "about to release fp #%d->%d irq\n",
1454 i
, bp
->msix_table
[offset
].vector
);
1456 free_irq(bp
->msix_table
[offset
++].vector
, &bp
->fp
[i
]);
1460 void bnx2x_free_irq(struct bnx2x
*bp
)
1462 if (bp
->flags
& USING_MSIX_FLAG
&&
1463 !(bp
->flags
& USING_SINGLE_MSIX_FLAG
)) {
1464 int nvecs
= BNX2X_NUM_ETH_QUEUES(bp
) + CNIC_SUPPORT(bp
);
1466 /* vfs don't have a default status block */
1470 bnx2x_free_msix_irqs(bp
, nvecs
);
1472 free_irq(bp
->dev
->irq
, bp
->dev
);
1476 int bnx2x_enable_msix(struct bnx2x
*bp
)
1478 int msix_vec
= 0, i
, rc
;
1480 /* VFs don't have a default status block */
1482 bp
->msix_table
[msix_vec
].entry
= msix_vec
;
1483 BNX2X_DEV_INFO("msix_table[0].entry = %d (slowpath)\n",
1484 bp
->msix_table
[0].entry
);
1488 /* Cnic requires an msix vector for itself */
1489 if (CNIC_SUPPORT(bp
)) {
1490 bp
->msix_table
[msix_vec
].entry
= msix_vec
;
1491 BNX2X_DEV_INFO("msix_table[%d].entry = %d (CNIC)\n",
1492 msix_vec
, bp
->msix_table
[msix_vec
].entry
);
1496 /* We need separate vectors for ETH queues only (not FCoE) */
1497 for_each_eth_queue(bp
, i
) {
1498 bp
->msix_table
[msix_vec
].entry
= msix_vec
;
1499 BNX2X_DEV_INFO("msix_table[%d].entry = %d (fastpath #%u)\n",
1500 msix_vec
, msix_vec
, i
);
1504 DP(BNX2X_MSG_SP
, "about to request enable msix with %d vectors\n",
1507 rc
= pci_enable_msix(bp
->pdev
, &bp
->msix_table
[0], msix_vec
);
1510 * reconfigure number of tx/rx queues according to available
1513 if (rc
>= BNX2X_MIN_MSIX_VEC_CNT(bp
)) {
1514 /* how less vectors we will have? */
1515 int diff
= msix_vec
- rc
;
1517 BNX2X_DEV_INFO("Trying to use less MSI-X vectors: %d\n", rc
);
1519 rc
= pci_enable_msix(bp
->pdev
, &bp
->msix_table
[0], rc
);
1522 BNX2X_DEV_INFO("MSI-X is not attainable rc %d\n", rc
);
1526 * decrease number of queues by number of unallocated entries
1528 bp
->num_ethernet_queues
-= diff
;
1529 bp
->num_queues
= bp
->num_ethernet_queues
+ bp
->num_cnic_queues
;
1531 BNX2X_DEV_INFO("New queue configuration set: %d\n",
1533 } else if (rc
> 0) {
1534 /* Get by with single vector */
1535 rc
= pci_enable_msix(bp
->pdev
, &bp
->msix_table
[0], 1);
1537 BNX2X_DEV_INFO("Single MSI-X is not attainable rc %d\n",
1542 BNX2X_DEV_INFO("Using single MSI-X vector\n");
1543 bp
->flags
|= USING_SINGLE_MSIX_FLAG
;
1545 BNX2X_DEV_INFO("set number of queues to 1\n");
1546 bp
->num_ethernet_queues
= 1;
1547 bp
->num_queues
= bp
->num_ethernet_queues
+ bp
->num_cnic_queues
;
1548 } else if (rc
< 0) {
1549 BNX2X_DEV_INFO("MSI-X is not attainable rc %d\n", rc
);
1553 bp
->flags
|= USING_MSIX_FLAG
;
1558 /* fall to INTx if not enough memory */
1560 bp
->flags
|= DISABLE_MSI_FLAG
;
1565 static int bnx2x_req_msix_irqs(struct bnx2x
*bp
)
1567 int i
, rc
, offset
= 0;
1569 /* no default status block for vf */
1571 rc
= request_irq(bp
->msix_table
[offset
++].vector
,
1572 bnx2x_msix_sp_int
, 0,
1573 bp
->dev
->name
, bp
->dev
);
1575 BNX2X_ERR("request sp irq failed\n");
1580 if (CNIC_SUPPORT(bp
))
1583 for_each_eth_queue(bp
, i
) {
1584 struct bnx2x_fastpath
*fp
= &bp
->fp
[i
];
1585 snprintf(fp
->name
, sizeof(fp
->name
), "%s-fp-%d",
1588 rc
= request_irq(bp
->msix_table
[offset
].vector
,
1589 bnx2x_msix_fp_int
, 0, fp
->name
, fp
);
1591 BNX2X_ERR("request fp #%d irq (%d) failed rc %d\n", i
,
1592 bp
->msix_table
[offset
].vector
, rc
);
1593 bnx2x_free_msix_irqs(bp
, offset
);
1600 i
= BNX2X_NUM_ETH_QUEUES(bp
);
1602 offset
= 1 + CNIC_SUPPORT(bp
);
1603 netdev_info(bp
->dev
,
1604 "using MSI-X IRQs: sp %d fp[%d] %d ... fp[%d] %d\n",
1605 bp
->msix_table
[0].vector
,
1606 0, bp
->msix_table
[offset
].vector
,
1607 i
- 1, bp
->msix_table
[offset
+ i
- 1].vector
);
1609 offset
= CNIC_SUPPORT(bp
);
1610 netdev_info(bp
->dev
,
1611 "using MSI-X IRQs: fp[%d] %d ... fp[%d] %d\n",
1612 0, bp
->msix_table
[offset
].vector
,
1613 i
- 1, bp
->msix_table
[offset
+ i
- 1].vector
);
1618 int bnx2x_enable_msi(struct bnx2x
*bp
)
1622 rc
= pci_enable_msi(bp
->pdev
);
1624 BNX2X_DEV_INFO("MSI is not attainable\n");
1627 bp
->flags
|= USING_MSI_FLAG
;
1632 static int bnx2x_req_irq(struct bnx2x
*bp
)
1634 unsigned long flags
;
1637 if (bp
->flags
& (USING_MSI_FLAG
| USING_MSIX_FLAG
))
1640 flags
= IRQF_SHARED
;
1642 if (bp
->flags
& USING_MSIX_FLAG
)
1643 irq
= bp
->msix_table
[0].vector
;
1645 irq
= bp
->pdev
->irq
;
1647 return request_irq(irq
, bnx2x_interrupt
, flags
, bp
->dev
->name
, bp
->dev
);
1650 static int bnx2x_setup_irqs(struct bnx2x
*bp
)
1653 if (bp
->flags
& USING_MSIX_FLAG
&&
1654 !(bp
->flags
& USING_SINGLE_MSIX_FLAG
)) {
1655 rc
= bnx2x_req_msix_irqs(bp
);
1660 rc
= bnx2x_req_irq(bp
);
1662 BNX2X_ERR("IRQ request failed rc %d, aborting\n", rc
);
1665 if (bp
->flags
& USING_MSI_FLAG
) {
1666 bp
->dev
->irq
= bp
->pdev
->irq
;
1667 netdev_info(bp
->dev
, "using MSI IRQ %d\n",
1670 if (bp
->flags
& USING_MSIX_FLAG
) {
1671 bp
->dev
->irq
= bp
->msix_table
[0].vector
;
1672 netdev_info(bp
->dev
, "using MSIX IRQ %d\n",
1680 static void bnx2x_napi_enable_cnic(struct bnx2x
*bp
)
1684 for_each_rx_queue_cnic(bp
, i
)
1685 napi_enable(&bnx2x_fp(bp
, i
, napi
));
1688 static void bnx2x_napi_enable(struct bnx2x
*bp
)
1692 for_each_eth_queue(bp
, i
)
1693 napi_enable(&bnx2x_fp(bp
, i
, napi
));
1696 static void bnx2x_napi_disable_cnic(struct bnx2x
*bp
)
1700 for_each_rx_queue_cnic(bp
, i
)
1701 napi_disable(&bnx2x_fp(bp
, i
, napi
));
1704 static void bnx2x_napi_disable(struct bnx2x
*bp
)
1708 for_each_eth_queue(bp
, i
)
1709 napi_disable(&bnx2x_fp(bp
, i
, napi
));
1712 void bnx2x_netif_start(struct bnx2x
*bp
)
1714 if (netif_running(bp
->dev
)) {
1715 bnx2x_napi_enable(bp
);
1716 if (CNIC_LOADED(bp
))
1717 bnx2x_napi_enable_cnic(bp
);
1718 bnx2x_int_enable(bp
);
1719 if (bp
->state
== BNX2X_STATE_OPEN
)
1720 netif_tx_wake_all_queues(bp
->dev
);
1724 void bnx2x_netif_stop(struct bnx2x
*bp
, int disable_hw
)
1726 bnx2x_int_disable_sync(bp
, disable_hw
);
1727 bnx2x_napi_disable(bp
);
1728 if (CNIC_LOADED(bp
))
1729 bnx2x_napi_disable_cnic(bp
);
1732 u16
bnx2x_select_queue(struct net_device
*dev
, struct sk_buff
*skb
)
1734 struct bnx2x
*bp
= netdev_priv(dev
);
1736 if (CNIC_LOADED(bp
) && !NO_FCOE(bp
)) {
1737 struct ethhdr
*hdr
= (struct ethhdr
*)skb
->data
;
1738 u16 ether_type
= ntohs(hdr
->h_proto
);
1740 /* Skip VLAN tag if present */
1741 if (ether_type
== ETH_P_8021Q
) {
1742 struct vlan_ethhdr
*vhdr
=
1743 (struct vlan_ethhdr
*)skb
->data
;
1745 ether_type
= ntohs(vhdr
->h_vlan_encapsulated_proto
);
1748 /* If ethertype is FCoE or FIP - use FCoE ring */
1749 if ((ether_type
== ETH_P_FCOE
) || (ether_type
== ETH_P_FIP
))
1750 return bnx2x_fcoe_tx(bp
, txq_index
);
1753 /* select a non-FCoE queue */
1754 return __skb_tx_hash(dev
, skb
, BNX2X_NUM_ETH_QUEUES(bp
));
1758 void bnx2x_set_num_queues(struct bnx2x
*bp
)
1761 bp
->num_ethernet_queues
= bnx2x_calc_num_queues(bp
);
1763 /* override in STORAGE SD modes */
1764 if (IS_MF_STORAGE_SD(bp
) || IS_MF_FCOE_AFEX(bp
))
1765 bp
->num_ethernet_queues
= 1;
1767 /* Add special queues */
1768 bp
->num_cnic_queues
= CNIC_SUPPORT(bp
); /* For FCOE */
1769 bp
->num_queues
= bp
->num_ethernet_queues
+ bp
->num_cnic_queues
;
1771 BNX2X_DEV_INFO("set number of queues to %d\n", bp
->num_queues
);
1775 * bnx2x_set_real_num_queues - configure netdev->real_num_[tx,rx]_queues
1777 * @bp: Driver handle
1779 * We currently support for at most 16 Tx queues for each CoS thus we will
1780 * allocate a multiple of 16 for ETH L2 rings according to the value of the
1783 * If there is an FCoE L2 queue the appropriate Tx queue will have the next
1784 * index after all ETH L2 indices.
1786 * If the actual number of Tx queues (for each CoS) is less than 16 then there
1787 * will be the holes at the end of each group of 16 ETh L2 indices (0..15,
1788 * 16..31,...) with indicies that are not coupled with any real Tx queue.
1790 * The proper configuration of skb->queue_mapping is handled by
1791 * bnx2x_select_queue() and __skb_tx_hash().
1793 * bnx2x_setup_tc() takes care of the proper TC mappings so that __skb_tx_hash()
1794 * will return a proper Tx index if TC is enabled (netdev->num_tc > 0).
1796 static int bnx2x_set_real_num_queues(struct bnx2x
*bp
, int include_cnic
)
1800 tx
= BNX2X_NUM_ETH_QUEUES(bp
) * bp
->max_cos
;
1801 rx
= BNX2X_NUM_ETH_QUEUES(bp
);
1803 /* account for fcoe queue */
1804 if (include_cnic
&& !NO_FCOE(bp
)) {
1809 rc
= netif_set_real_num_tx_queues(bp
->dev
, tx
);
1811 BNX2X_ERR("Failed to set real number of Tx queues: %d\n", rc
);
1814 rc
= netif_set_real_num_rx_queues(bp
->dev
, rx
);
1816 BNX2X_ERR("Failed to set real number of Rx queues: %d\n", rc
);
1820 DP(NETIF_MSG_IFUP
, "Setting real num queues to (tx, rx) (%d, %d)\n",
1826 static void bnx2x_set_rx_buf_size(struct bnx2x
*bp
)
1830 for_each_queue(bp
, i
) {
1831 struct bnx2x_fastpath
*fp
= &bp
->fp
[i
];
1834 /* Always use a mini-jumbo MTU for the FCoE L2 ring */
1837 * Although there are no IP frames expected to arrive to
1838 * this ring we still want to add an
1839 * IP_HEADER_ALIGNMENT_PADDING to prevent a buffer
1842 mtu
= BNX2X_FCOE_MINI_JUMBO_MTU
;
1845 fp
->rx_buf_size
= BNX2X_FW_RX_ALIGN_START
+
1846 IP_HEADER_ALIGNMENT_PADDING
+
1849 BNX2X_FW_RX_ALIGN_END
;
1850 /* Note : rx_buf_size doesnt take into account NET_SKB_PAD */
1851 if (fp
->rx_buf_size
+ NET_SKB_PAD
<= PAGE_SIZE
)
1852 fp
->rx_frag_size
= fp
->rx_buf_size
+ NET_SKB_PAD
;
1854 fp
->rx_frag_size
= 0;
1858 static int bnx2x_init_rss_pf(struct bnx2x
*bp
)
1861 u8 num_eth_queues
= BNX2X_NUM_ETH_QUEUES(bp
);
1863 /* Prepare the initial contents fo the indirection table if RSS is
1866 for (i
= 0; i
< sizeof(bp
->rss_conf_obj
.ind_table
); i
++)
1867 bp
->rss_conf_obj
.ind_table
[i
] =
1869 ethtool_rxfh_indir_default(i
, num_eth_queues
);
1872 * For 57710 and 57711 SEARCHER configuration (rss_keys) is
1873 * per-port, so if explicit configuration is needed , do it only
1876 * For 57712 and newer on the other hand it's a per-function
1879 return bnx2x_config_rss_eth(bp
, bp
->port
.pmf
|| !CHIP_IS_E1x(bp
));
1882 int bnx2x_config_rss_pf(struct bnx2x
*bp
, struct bnx2x_rss_config_obj
*rss_obj
,
1885 struct bnx2x_config_rss_params params
= {NULL
};
1887 /* Although RSS is meaningless when there is a single HW queue we
1888 * still need it enabled in order to have HW Rx hash generated.
1890 * if (!is_eth_multi(bp))
1891 * bp->multi_mode = ETH_RSS_MODE_DISABLED;
1894 params
.rss_obj
= rss_obj
;
1896 __set_bit(RAMROD_COMP_WAIT
, ¶ms
.ramrod_flags
);
1898 __set_bit(BNX2X_RSS_MODE_REGULAR
, ¶ms
.rss_flags
);
1900 /* RSS configuration */
1901 __set_bit(BNX2X_RSS_IPV4
, ¶ms
.rss_flags
);
1902 __set_bit(BNX2X_RSS_IPV4_TCP
, ¶ms
.rss_flags
);
1903 __set_bit(BNX2X_RSS_IPV6
, ¶ms
.rss_flags
);
1904 __set_bit(BNX2X_RSS_IPV6_TCP
, ¶ms
.rss_flags
);
1905 if (rss_obj
->udp_rss_v4
)
1906 __set_bit(BNX2X_RSS_IPV4_UDP
, ¶ms
.rss_flags
);
1907 if (rss_obj
->udp_rss_v6
)
1908 __set_bit(BNX2X_RSS_IPV6_UDP
, ¶ms
.rss_flags
);
1911 params
.rss_result_mask
= MULTI_MASK
;
1913 memcpy(params
.ind_table
, rss_obj
->ind_table
, sizeof(params
.ind_table
));
1917 prandom_bytes(params
.rss_key
, sizeof(params
.rss_key
));
1918 __set_bit(BNX2X_RSS_SET_SRCH
, ¶ms
.rss_flags
);
1921 return bnx2x_config_rss(bp
, ¶ms
);
1924 static int bnx2x_init_hw(struct bnx2x
*bp
, u32 load_code
)
1926 struct bnx2x_func_state_params func_params
= {NULL
};
1928 /* Prepare parameters for function state transitions */
1929 __set_bit(RAMROD_COMP_WAIT
, &func_params
.ramrod_flags
);
1931 func_params
.f_obj
= &bp
->func_obj
;
1932 func_params
.cmd
= BNX2X_F_CMD_HW_INIT
;
1934 func_params
.params
.hw_init
.load_phase
= load_code
;
1936 return bnx2x_func_state_change(bp
, &func_params
);
1940 * Cleans the object that have internal lists without sending
1941 * ramrods. Should be run when interrutps are disabled.
1943 static void bnx2x_squeeze_objects(struct bnx2x
*bp
)
1946 unsigned long ramrod_flags
= 0, vlan_mac_flags
= 0;
1947 struct bnx2x_mcast_ramrod_params rparam
= {NULL
};
1948 struct bnx2x_vlan_mac_obj
*mac_obj
= &bp
->sp_objs
->mac_obj
;
1950 /***************** Cleanup MACs' object first *************************/
1952 /* Wait for completion of requested */
1953 __set_bit(RAMROD_COMP_WAIT
, &ramrod_flags
);
1954 /* Perform a dry cleanup */
1955 __set_bit(RAMROD_DRV_CLR_ONLY
, &ramrod_flags
);
1957 /* Clean ETH primary MAC */
1958 __set_bit(BNX2X_ETH_MAC
, &vlan_mac_flags
);
1959 rc
= mac_obj
->delete_all(bp
, &bp
->sp_objs
->mac_obj
, &vlan_mac_flags
,
1962 BNX2X_ERR("Failed to clean ETH MACs: %d\n", rc
);
1964 /* Cleanup UC list */
1966 __set_bit(BNX2X_UC_LIST_MAC
, &vlan_mac_flags
);
1967 rc
= mac_obj
->delete_all(bp
, mac_obj
, &vlan_mac_flags
,
1970 BNX2X_ERR("Failed to clean UC list MACs: %d\n", rc
);
1972 /***************** Now clean mcast object *****************************/
1973 rparam
.mcast_obj
= &bp
->mcast_obj
;
1974 __set_bit(RAMROD_DRV_CLR_ONLY
, &rparam
.ramrod_flags
);
1976 /* Add a DEL command... */
1977 rc
= bnx2x_config_mcast(bp
, &rparam
, BNX2X_MCAST_CMD_DEL
);
1979 BNX2X_ERR("Failed to add a new DEL command to a multi-cast object: %d\n",
1982 /* ...and wait until all pending commands are cleared */
1983 rc
= bnx2x_config_mcast(bp
, &rparam
, BNX2X_MCAST_CMD_CONT
);
1986 BNX2X_ERR("Failed to clean multi-cast object: %d\n",
1991 rc
= bnx2x_config_mcast(bp
, &rparam
, BNX2X_MCAST_CMD_CONT
);
1995 #ifndef BNX2X_STOP_ON_ERROR
1996 #define LOAD_ERROR_EXIT(bp, label) \
1998 (bp)->state = BNX2X_STATE_ERROR; \
2002 #define LOAD_ERROR_EXIT_CNIC(bp, label) \
2004 bp->cnic_loaded = false; \
2007 #else /*BNX2X_STOP_ON_ERROR*/
2008 #define LOAD_ERROR_EXIT(bp, label) \
2010 (bp)->state = BNX2X_STATE_ERROR; \
2014 #define LOAD_ERROR_EXIT_CNIC(bp, label) \
2016 bp->cnic_loaded = false; \
2020 #endif /*BNX2X_STOP_ON_ERROR*/
2022 static void bnx2x_free_fw_stats_mem(struct bnx2x
*bp
)
2024 BNX2X_PCI_FREE(bp
->fw_stats
, bp
->fw_stats_mapping
,
2025 bp
->fw_stats_data_sz
+ bp
->fw_stats_req_sz
);
2029 static int bnx2x_alloc_fw_stats_mem(struct bnx2x
*bp
)
2031 int num_groups
, vf_headroom
= 0;
2032 int is_fcoe_stats
= NO_FCOE(bp
) ? 0 : 1;
2034 /* number of queues for statistics is number of eth queues + FCoE */
2035 u8 num_queue_stats
= BNX2X_NUM_ETH_QUEUES(bp
) + is_fcoe_stats
;
2037 /* Total number of FW statistics requests =
2038 * 1 for port stats + 1 for PF stats + potential 2 for FCoE (fcoe proper
2039 * and fcoe l2 queue) stats + num of queues (which includes another 1
2040 * for fcoe l2 queue if applicable)
2042 bp
->fw_stats_num
= 2 + is_fcoe_stats
+ num_queue_stats
;
2044 /* vf stats appear in the request list, but their data is allocated by
2045 * the VFs themselves. We don't include them in the bp->fw_stats_num as
2046 * it is used to determine where to place the vf stats queries in the
2050 vf_headroom
= bnx2x_vf_headroom(bp
);
2052 /* Request is built from stats_query_header and an array of
2053 * stats_query_cmd_group each of which contains
2054 * STATS_QUERY_CMD_COUNT rules. The real number or requests is
2055 * configured in the stats_query_header.
2058 (((bp
->fw_stats_num
+ vf_headroom
) / STATS_QUERY_CMD_COUNT
) +
2059 (((bp
->fw_stats_num
+ vf_headroom
) % STATS_QUERY_CMD_COUNT
) ?
2062 DP(BNX2X_MSG_SP
, "stats fw_stats_num %d, vf headroom %d, num_groups %d\n",
2063 bp
->fw_stats_num
, vf_headroom
, num_groups
);
2064 bp
->fw_stats_req_sz
= sizeof(struct stats_query_header
) +
2065 num_groups
* sizeof(struct stats_query_cmd_group
);
2067 /* Data for statistics requests + stats_counter
2068 * stats_counter holds per-STORM counters that are incremented
2069 * when STORM has finished with the current request.
2070 * memory for FCoE offloaded statistics are counted anyway,
2071 * even if they will not be sent.
2072 * VF stats are not accounted for here as the data of VF stats is stored
2073 * in memory allocated by the VF, not here.
2075 bp
->fw_stats_data_sz
= sizeof(struct per_port_stats
) +
2076 sizeof(struct per_pf_stats
) +
2077 sizeof(struct fcoe_statistics_params
) +
2078 sizeof(struct per_queue_stats
) * num_queue_stats
+
2079 sizeof(struct stats_counter
);
2081 BNX2X_PCI_ALLOC(bp
->fw_stats
, &bp
->fw_stats_mapping
,
2082 bp
->fw_stats_data_sz
+ bp
->fw_stats_req_sz
);
2085 bp
->fw_stats_req
= (struct bnx2x_fw_stats_req
*)bp
->fw_stats
;
2086 bp
->fw_stats_req_mapping
= bp
->fw_stats_mapping
;
2087 bp
->fw_stats_data
= (struct bnx2x_fw_stats_data
*)
2088 ((u8
*)bp
->fw_stats
+ bp
->fw_stats_req_sz
);
2089 bp
->fw_stats_data_mapping
= bp
->fw_stats_mapping
+
2090 bp
->fw_stats_req_sz
;
2092 DP(BNX2X_MSG_SP
, "statistics request base address set to %x %x",
2093 U64_HI(bp
->fw_stats_req_mapping
),
2094 U64_LO(bp
->fw_stats_req_mapping
));
2095 DP(BNX2X_MSG_SP
, "statistics data base address set to %x %x",
2096 U64_HI(bp
->fw_stats_data_mapping
),
2097 U64_LO(bp
->fw_stats_data_mapping
));
2101 bnx2x_free_fw_stats_mem(bp
);
2102 BNX2X_ERR("Can't allocate FW stats memory\n");
2106 /* send load request to mcp and analyze response */
2107 static int bnx2x_nic_load_request(struct bnx2x
*bp
, u32
*load_code
)
2111 (SHMEM_RD(bp
, func_mb
[BP_FW_MB_IDX(bp
)].drv_mb_header
) &
2112 DRV_MSG_SEQ_NUMBER_MASK
);
2113 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp
->fw_seq
);
2115 /* Get current FW pulse sequence */
2116 bp
->fw_drv_pulse_wr_seq
=
2117 (SHMEM_RD(bp
, func_mb
[BP_FW_MB_IDX(bp
)].drv_pulse_mb
) &
2118 DRV_PULSE_SEQ_MASK
);
2119 BNX2X_DEV_INFO("drv_pulse 0x%x\n", bp
->fw_drv_pulse_wr_seq
);
2122 (*load_code
) = bnx2x_fw_command(bp
, DRV_MSG_CODE_LOAD_REQ
,
2123 DRV_MSG_CODE_LOAD_REQ_WITH_LFA
);
2125 /* if mcp fails to respond we must abort */
2126 if (!(*load_code
)) {
2127 BNX2X_ERR("MCP response failure, aborting\n");
2131 /* If mcp refused (e.g. other port is in diagnostic mode) we
2134 if ((*load_code
) == FW_MSG_CODE_DRV_LOAD_REFUSED
) {
2135 BNX2X_ERR("MCP refused load request, aborting\n");
2141 /* check whether another PF has already loaded FW to chip. In
2142 * virtualized environments a pf from another VM may have already
2143 * initialized the device including loading FW
2145 int bnx2x_nic_load_analyze_req(struct bnx2x
*bp
, u32 load_code
)
2147 /* is another pf loaded on this engine? */
2148 if (load_code
!= FW_MSG_CODE_DRV_LOAD_COMMON_CHIP
&&
2149 load_code
!= FW_MSG_CODE_DRV_LOAD_COMMON
) {
2150 /* build my FW version dword */
2151 u32 my_fw
= (BCM_5710_FW_MAJOR_VERSION
) +
2152 (BCM_5710_FW_MINOR_VERSION
<< 8) +
2153 (BCM_5710_FW_REVISION_VERSION
<< 16) +
2154 (BCM_5710_FW_ENGINEERING_VERSION
<< 24);
2156 /* read loaded FW from chip */
2157 u32 loaded_fw
= REG_RD(bp
, XSEM_REG_PRAM
);
2159 DP(BNX2X_MSG_SP
, "loaded fw %x, my fw %x\n",
2162 /* abort nic load if version mismatch */
2163 if (my_fw
!= loaded_fw
) {
2164 BNX2X_ERR("bnx2x with FW %x was already loaded which mismatches my %x FW. aborting\n",
2172 /* returns the "mcp load_code" according to global load_count array */
2173 static int bnx2x_nic_load_no_mcp(struct bnx2x
*bp
, int port
)
2175 int path
= BP_PATH(bp
);
2177 DP(NETIF_MSG_IFUP
, "NO MCP - load counts[%d] %d, %d, %d\n",
2178 path
, load_count
[path
][0], load_count
[path
][1],
2179 load_count
[path
][2]);
2180 load_count
[path
][0]++;
2181 load_count
[path
][1 + port
]++;
2182 DP(NETIF_MSG_IFUP
, "NO MCP - new load counts[%d] %d, %d, %d\n",
2183 path
, load_count
[path
][0], load_count
[path
][1],
2184 load_count
[path
][2]);
2185 if (load_count
[path
][0] == 1)
2186 return FW_MSG_CODE_DRV_LOAD_COMMON
;
2187 else if (load_count
[path
][1 + port
] == 1)
2188 return FW_MSG_CODE_DRV_LOAD_PORT
;
2190 return FW_MSG_CODE_DRV_LOAD_FUNCTION
;
2193 /* mark PMF if applicable */
2194 static void bnx2x_nic_load_pmf(struct bnx2x
*bp
, u32 load_code
)
2196 if ((load_code
== FW_MSG_CODE_DRV_LOAD_COMMON
) ||
2197 (load_code
== FW_MSG_CODE_DRV_LOAD_COMMON_CHIP
) ||
2198 (load_code
== FW_MSG_CODE_DRV_LOAD_PORT
)) {
2200 /* We need the barrier to ensure the ordering between the
2201 * writing to bp->port.pmf here and reading it from the
2202 * bnx2x_periodic_task().
2209 DP(NETIF_MSG_LINK
, "pmf %d\n", bp
->port
.pmf
);
2212 static void bnx2x_nic_load_afex_dcc(struct bnx2x
*bp
, int load_code
)
2214 if (((load_code
== FW_MSG_CODE_DRV_LOAD_COMMON
) ||
2215 (load_code
== FW_MSG_CODE_DRV_LOAD_COMMON_CHIP
)) &&
2216 (bp
->common
.shmem2_base
)) {
2217 if (SHMEM2_HAS(bp
, dcc_support
))
2218 SHMEM2_WR(bp
, dcc_support
,
2219 (SHMEM_DCC_SUPPORT_DISABLE_ENABLE_PF_TLV
|
2220 SHMEM_DCC_SUPPORT_BANDWIDTH_ALLOCATION_TLV
));
2221 if (SHMEM2_HAS(bp
, afex_driver_support
))
2222 SHMEM2_WR(bp
, afex_driver_support
,
2223 SHMEM_AFEX_SUPPORTED_VERSION_ONE
);
2226 /* Set AFEX default VLAN tag to an invalid value */
2227 bp
->afex_def_vlan_tag
= -1;
2231 * bnx2x_bz_fp - zero content of the fastpath structure.
2233 * @bp: driver handle
2234 * @index: fastpath index to be zeroed
2236 * Makes sure the contents of the bp->fp[index].napi is kept
2239 static void bnx2x_bz_fp(struct bnx2x
*bp
, int index
)
2241 struct bnx2x_fastpath
*fp
= &bp
->fp
[index
];
2242 struct bnx2x_fp_stats
*fp_stats
= &bp
->fp_stats
[index
];
2245 struct napi_struct orig_napi
= fp
->napi
;
2246 struct bnx2x_agg_info
*orig_tpa_info
= fp
->tpa_info
;
2247 /* bzero bnx2x_fastpath contents */
2248 if (bp
->stats_init
) {
2249 memset(fp
->tpa_info
, 0, sizeof(*fp
->tpa_info
));
2250 memset(fp
, 0, sizeof(*fp
));
2252 /* Keep Queue statistics */
2253 struct bnx2x_eth_q_stats
*tmp_eth_q_stats
;
2254 struct bnx2x_eth_q_stats_old
*tmp_eth_q_stats_old
;
2256 tmp_eth_q_stats
= kzalloc(sizeof(struct bnx2x_eth_q_stats
),
2258 if (tmp_eth_q_stats
)
2259 memcpy(tmp_eth_q_stats
, &fp_stats
->eth_q_stats
,
2260 sizeof(struct bnx2x_eth_q_stats
));
2262 tmp_eth_q_stats_old
=
2263 kzalloc(sizeof(struct bnx2x_eth_q_stats_old
),
2265 if (tmp_eth_q_stats_old
)
2266 memcpy(tmp_eth_q_stats_old
, &fp_stats
->eth_q_stats_old
,
2267 sizeof(struct bnx2x_eth_q_stats_old
));
2269 memset(fp
->tpa_info
, 0, sizeof(*fp
->tpa_info
));
2270 memset(fp
, 0, sizeof(*fp
));
2272 if (tmp_eth_q_stats
) {
2273 memcpy(&fp_stats
->eth_q_stats
, tmp_eth_q_stats
,
2274 sizeof(struct bnx2x_eth_q_stats
));
2275 kfree(tmp_eth_q_stats
);
2278 if (tmp_eth_q_stats_old
) {
2279 memcpy(&fp_stats
->eth_q_stats_old
, tmp_eth_q_stats_old
,
2280 sizeof(struct bnx2x_eth_q_stats_old
));
2281 kfree(tmp_eth_q_stats_old
);
2286 /* Restore the NAPI object as it has been already initialized */
2287 fp
->napi
= orig_napi
;
2288 fp
->tpa_info
= orig_tpa_info
;
2292 fp
->max_cos
= bp
->max_cos
;
2294 /* Special queues support only one CoS */
2297 /* Init txdata pointers */
2299 fp
->txdata_ptr
[0] = &bp
->bnx2x_txq
[FCOE_TXQ_IDX(bp
)];
2301 for_each_cos_in_tx_queue(fp
, cos
)
2302 fp
->txdata_ptr
[cos
] = &bp
->bnx2x_txq
[cos
*
2303 BNX2X_NUM_ETH_QUEUES(bp
) + index
];
2306 * set the tpa flag for each queue. The tpa flag determines the queue
2307 * minimal size so it must be set prior to queue memory allocation
2309 fp
->disable_tpa
= !(bp
->flags
& TPA_ENABLE_FLAG
||
2310 (bp
->flags
& GRO_ENABLE_FLAG
&&
2311 bnx2x_mtu_allows_gro(bp
->dev
->mtu
)));
2312 if (bp
->flags
& TPA_ENABLE_FLAG
)
2313 fp
->mode
= TPA_MODE_LRO
;
2314 else if (bp
->flags
& GRO_ENABLE_FLAG
)
2315 fp
->mode
= TPA_MODE_GRO
;
2317 /* We don't want TPA on an FCoE L2 ring */
2319 fp
->disable_tpa
= 1;
2322 int bnx2x_load_cnic(struct bnx2x
*bp
)
2324 int i
, rc
, port
= BP_PORT(bp
);
2326 DP(NETIF_MSG_IFUP
, "Starting CNIC-related load\n");
2328 mutex_init(&bp
->cnic_mutex
);
2331 rc
= bnx2x_alloc_mem_cnic(bp
);
2333 BNX2X_ERR("Unable to allocate bp memory for cnic\n");
2334 LOAD_ERROR_EXIT_CNIC(bp
, load_error_cnic0
);
2338 rc
= bnx2x_alloc_fp_mem_cnic(bp
);
2340 BNX2X_ERR("Unable to allocate memory for cnic fps\n");
2341 LOAD_ERROR_EXIT_CNIC(bp
, load_error_cnic0
);
2344 /* Update the number of queues with the cnic queues */
2345 rc
= bnx2x_set_real_num_queues(bp
, 1);
2347 BNX2X_ERR("Unable to set real_num_queues including cnic\n");
2348 LOAD_ERROR_EXIT_CNIC(bp
, load_error_cnic0
);
2351 /* Add all CNIC NAPI objects */
2352 bnx2x_add_all_napi_cnic(bp
);
2353 DP(NETIF_MSG_IFUP
, "cnic napi added\n");
2354 bnx2x_napi_enable_cnic(bp
);
2356 rc
= bnx2x_init_hw_func_cnic(bp
);
2358 LOAD_ERROR_EXIT_CNIC(bp
, load_error_cnic1
);
2360 bnx2x_nic_init_cnic(bp
);
2363 /* Enable Timer scan */
2364 REG_WR(bp
, TM_REG_EN_LINEAR0_TIMER
+ port
*4, 1);
2366 /* setup cnic queues */
2367 for_each_cnic_queue(bp
, i
) {
2368 rc
= bnx2x_setup_queue(bp
, &bp
->fp
[i
], 0);
2370 BNX2X_ERR("Queue setup failed\n");
2371 LOAD_ERROR_EXIT(bp
, load_error_cnic2
);
2376 /* Initialize Rx filter. */
2377 netif_addr_lock_bh(bp
->dev
);
2378 bnx2x_set_rx_mode(bp
->dev
);
2379 netif_addr_unlock_bh(bp
->dev
);
2381 /* re-read iscsi info */
2382 bnx2x_get_iscsi_info(bp
);
2383 bnx2x_setup_cnic_irq_info(bp
);
2384 bnx2x_setup_cnic_info(bp
);
2385 bp
->cnic_loaded
= true;
2386 if (bp
->state
== BNX2X_STATE_OPEN
)
2387 bnx2x_cnic_notify(bp
, CNIC_CTL_START_CMD
);
2390 DP(NETIF_MSG_IFUP
, "Ending successfully CNIC-related load\n");
2394 #ifndef BNX2X_STOP_ON_ERROR
2396 /* Disable Timer scan */
2397 REG_WR(bp
, TM_REG_EN_LINEAR0_TIMER
+ port
*4, 0);
2400 bnx2x_napi_disable_cnic(bp
);
2401 /* Update the number of queues without the cnic queues */
2402 rc
= bnx2x_set_real_num_queues(bp
, 0);
2404 BNX2X_ERR("Unable to set real_num_queues not including cnic\n");
2406 BNX2X_ERR("CNIC-related load failed\n");
2407 bnx2x_free_fp_mem_cnic(bp
);
2408 bnx2x_free_mem_cnic(bp
);
2410 #endif /* ! BNX2X_STOP_ON_ERROR */
2414 /* must be called with rtnl_lock */
2415 int bnx2x_nic_load(struct bnx2x
*bp
, int load_mode
)
2417 int port
= BP_PORT(bp
);
2418 int i
, rc
= 0, load_code
= 0;
2420 DP(NETIF_MSG_IFUP
, "Starting NIC load\n");
2422 "CNIC is %s\n", CNIC_ENABLED(bp
) ? "enabled" : "disabled");
2424 #ifdef BNX2X_STOP_ON_ERROR
2425 if (unlikely(bp
->panic
)) {
2426 BNX2X_ERR("Can't load NIC when there is panic\n");
2431 bp
->state
= BNX2X_STATE_OPENING_WAIT4_LOAD
;
2433 /* Set the initial link reported state to link down */
2434 bnx2x_acquire_phy_lock(bp
);
2435 memset(&bp
->last_reported_link
, 0, sizeof(bp
->last_reported_link
));
2436 __set_bit(BNX2X_LINK_REPORT_LINK_DOWN
,
2437 &bp
->last_reported_link
.link_report_flags
);
2438 bnx2x_release_phy_lock(bp
);
2441 /* must be called before memory allocation and HW init */
2442 bnx2x_ilt_set_info(bp
);
2445 * Zero fastpath structures preserving invariants like napi, which are
2446 * allocated only once, fp index, max_cos, bp pointer.
2447 * Also set fp->disable_tpa and txdata_ptr.
2449 DP(NETIF_MSG_IFUP
, "num queues: %d", bp
->num_queues
);
2450 for_each_queue(bp
, i
)
2452 memset(bp
->bnx2x_txq
, 0, (BNX2X_MAX_RSS_COUNT(bp
) * BNX2X_MULTI_TX_COS
+
2453 bp
->num_cnic_queues
) *
2454 sizeof(struct bnx2x_fp_txdata
));
2456 bp
->fcoe_init
= false;
2458 /* Set the receive queues buffer size */
2459 bnx2x_set_rx_buf_size(bp
);
2462 rc
= bnx2x_alloc_mem(bp
);
2464 BNX2X_ERR("Unable to allocate bp memory\n");
2469 /* Allocated memory for FW statistics */
2470 if (bnx2x_alloc_fw_stats_mem(bp
))
2471 LOAD_ERROR_EXIT(bp
, load_error0
);
2473 /* need to be done after alloc mem, since it's self adjusting to amount
2474 * of memory available for RSS queues
2476 rc
= bnx2x_alloc_fp_mem(bp
);
2478 BNX2X_ERR("Unable to allocate memory for fps\n");
2479 LOAD_ERROR_EXIT(bp
, load_error0
);
2482 /* request pf to initialize status blocks */
2484 rc
= bnx2x_vfpf_init(bp
);
2486 LOAD_ERROR_EXIT(bp
, load_error0
);
2489 /* As long as bnx2x_alloc_mem() may possibly update
2490 * bp->num_queues, bnx2x_set_real_num_queues() should always
2491 * come after it. At this stage cnic queues are not counted.
2493 rc
= bnx2x_set_real_num_queues(bp
, 0);
2495 BNX2X_ERR("Unable to set real_num_queues\n");
2496 LOAD_ERROR_EXIT(bp
, load_error0
);
2499 /* configure multi cos mappings in kernel.
2500 * this configuration may be overriden by a multi class queue discipline
2501 * or by a dcbx negotiation result.
2503 bnx2x_setup_tc(bp
->dev
, bp
->max_cos
);
2505 /* Add all NAPI objects */
2506 bnx2x_add_all_napi(bp
);
2507 DP(NETIF_MSG_IFUP
, "napi added\n");
2508 bnx2x_napi_enable(bp
);
2511 /* set pf load just before approaching the MCP */
2512 bnx2x_set_pf_load(bp
);
2514 /* if mcp exists send load request and analyze response */
2515 if (!BP_NOMCP(bp
)) {
2516 /* attempt to load pf */
2517 rc
= bnx2x_nic_load_request(bp
, &load_code
);
2519 LOAD_ERROR_EXIT(bp
, load_error1
);
2521 /* what did mcp say? */
2522 rc
= bnx2x_nic_load_analyze_req(bp
, load_code
);
2524 bnx2x_fw_command(bp
, DRV_MSG_CODE_LOAD_DONE
, 0);
2525 LOAD_ERROR_EXIT(bp
, load_error2
);
2528 load_code
= bnx2x_nic_load_no_mcp(bp
, port
);
2531 /* mark pmf if applicable */
2532 bnx2x_nic_load_pmf(bp
, load_code
);
2534 /* Init Function state controlling object */
2535 bnx2x__init_func_obj(bp
);
2538 rc
= bnx2x_init_hw(bp
, load_code
);
2540 BNX2X_ERR("HW init failed, aborting\n");
2541 bnx2x_fw_command(bp
, DRV_MSG_CODE_LOAD_DONE
, 0);
2542 LOAD_ERROR_EXIT(bp
, load_error2
);
2546 /* Connect to IRQs */
2547 rc
= bnx2x_setup_irqs(bp
);
2549 BNX2X_ERR("setup irqs failed\n");
2551 bnx2x_fw_command(bp
, DRV_MSG_CODE_LOAD_DONE
, 0);
2552 LOAD_ERROR_EXIT(bp
, load_error2
);
2555 /* Setup NIC internals and enable interrupts */
2556 bnx2x_nic_init(bp
, load_code
);
2558 /* Init per-function objects */
2560 bnx2x_init_bp_objs(bp
);
2561 bnx2x_iov_nic_init(bp
);
2563 /* Set AFEX default VLAN tag to an invalid value */
2564 bp
->afex_def_vlan_tag
= -1;
2565 bnx2x_nic_load_afex_dcc(bp
, load_code
);
2566 bp
->state
= BNX2X_STATE_OPENING_WAIT4_PORT
;
2567 rc
= bnx2x_func_start(bp
);
2569 BNX2X_ERR("Function start failed!\n");
2570 bnx2x_fw_command(bp
, DRV_MSG_CODE_LOAD_DONE
, 0);
2572 LOAD_ERROR_EXIT(bp
, load_error3
);
2575 /* Send LOAD_DONE command to MCP */
2576 if (!BP_NOMCP(bp
)) {
2577 load_code
= bnx2x_fw_command(bp
,
2578 DRV_MSG_CODE_LOAD_DONE
, 0);
2580 BNX2X_ERR("MCP response failure, aborting\n");
2582 LOAD_ERROR_EXIT(bp
, load_error3
);
2586 /* setup the leading queue */
2587 rc
= bnx2x_setup_leading(bp
);
2589 BNX2X_ERR("Setup leading failed!\n");
2590 LOAD_ERROR_EXIT(bp
, load_error3
);
2593 /* set up the rest of the queues */
2594 for_each_nondefault_eth_queue(bp
, i
) {
2595 rc
= bnx2x_setup_queue(bp
, &bp
->fp
[i
], 0);
2597 BNX2X_ERR("Queue setup failed\n");
2598 LOAD_ERROR_EXIT(bp
, load_error3
);
2603 rc
= bnx2x_init_rss_pf(bp
);
2605 BNX2X_ERR("PF RSS init failed\n");
2606 LOAD_ERROR_EXIT(bp
, load_error3
);
2610 for_each_eth_queue(bp
, i
) {
2611 rc
= bnx2x_vfpf_setup_q(bp
, i
);
2613 BNX2X_ERR("Queue setup failed\n");
2614 LOAD_ERROR_EXIT(bp
, load_error3
);
2619 /* Now when Clients are configured we are ready to work */
2620 bp
->state
= BNX2X_STATE_OPEN
;
2622 /* Configure a ucast MAC */
2624 rc
= bnx2x_set_eth_mac(bp
, true);
2626 rc
= bnx2x_vfpf_set_mac(bp
);
2628 BNX2X_ERR("Setting Ethernet MAC failed\n");
2629 LOAD_ERROR_EXIT(bp
, load_error3
);
2632 if (IS_PF(bp
) && bp
->pending_max
) {
2633 bnx2x_update_max_mf_config(bp
, bp
->pending_max
);
2634 bp
->pending_max
= 0;
2638 rc
= bnx2x_initial_phy_init(bp
, load_mode
);
2640 LOAD_ERROR_EXIT(bp
, load_error3
);
2642 bp
->link_params
.feature_config_flags
&= ~FEATURE_CONFIG_BOOT_FROM_SAN
;
2644 /* Start fast path */
2646 /* Initialize Rx filter. */
2647 netif_addr_lock_bh(bp
->dev
);
2648 bnx2x_set_rx_mode(bp
->dev
);
2649 netif_addr_unlock_bh(bp
->dev
);
2652 switch (load_mode
) {
2654 /* Tx queue should be only reenabled */
2655 netif_tx_wake_all_queues(bp
->dev
);
2659 netif_tx_start_all_queues(bp
->dev
);
2660 smp_mb__after_clear_bit();
2664 case LOAD_LOOPBACK_EXT
:
2665 bp
->state
= BNX2X_STATE_DIAG
;
2673 bnx2x_update_drv_flags(bp
, 1 << DRV_FLAGS_PORT_MASK
, 0);
2675 bnx2x__link_status_update(bp
);
2677 /* start the timer */
2678 mod_timer(&bp
->timer
, jiffies
+ bp
->current_interval
);
2680 if (CNIC_ENABLED(bp
))
2681 bnx2x_load_cnic(bp
);
2683 if (IS_PF(bp
) && SHMEM2_HAS(bp
, drv_capabilities_flag
)) {
2684 /* mark driver is loaded in shmem2 */
2686 val
= SHMEM2_RD(bp
, drv_capabilities_flag
[BP_FW_MB_IDX(bp
)]);
2687 SHMEM2_WR(bp
, drv_capabilities_flag
[BP_FW_MB_IDX(bp
)],
2688 val
| DRV_FLAGS_CAPABILITIES_LOADED_SUPPORTED
|
2689 DRV_FLAGS_CAPABILITIES_LOADED_L2
);
2692 /* Wait for all pending SP commands to complete */
2693 if (IS_PF(bp
) && !bnx2x_wait_sp_comp(bp
, ~0x0UL
)) {
2694 BNX2X_ERR("Timeout waiting for SP elements to complete\n");
2695 bnx2x_nic_unload(bp
, UNLOAD_CLOSE
, false);
2699 /* If PMF - send ADMIN DCBX msg to MFW to initiate DCBX FSM */
2700 if (bp
->port
.pmf
&& (bp
->state
!= BNX2X_STATE_DIAG
))
2701 bnx2x_dcbx_init(bp
, false);
2703 DP(NETIF_MSG_IFUP
, "Ending successfully NIC load\n");
2707 #ifndef BNX2X_STOP_ON_ERROR
2710 bnx2x_int_disable_sync(bp
, 1);
2712 /* Clean queueable objects */
2713 bnx2x_squeeze_objects(bp
);
2716 /* Free SKBs, SGEs, TPA pool and driver internals */
2717 bnx2x_free_skbs(bp
);
2718 for_each_rx_queue(bp
, i
)
2719 bnx2x_free_rx_sge_range(bp
, bp
->fp
+ i
, NUM_RX_SGE
);
2724 if (IS_PF(bp
) && !BP_NOMCP(bp
)) {
2725 bnx2x_fw_command(bp
, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP
, 0);
2726 bnx2x_fw_command(bp
, DRV_MSG_CODE_UNLOAD_DONE
, 0);
2731 bnx2x_napi_disable(bp
);
2733 /* clear pf_load status, as it was already set */
2735 bnx2x_clear_pf_load(bp
);
2737 bnx2x_free_fp_mem(bp
);
2738 bnx2x_free_fw_stats_mem(bp
);
2742 #endif /* ! BNX2X_STOP_ON_ERROR */
2745 static int bnx2x_drain_tx_queues(struct bnx2x
*bp
)
2749 /* Wait until tx fastpath tasks complete */
2750 for_each_tx_queue(bp
, i
) {
2751 struct bnx2x_fastpath
*fp
= &bp
->fp
[i
];
2753 for_each_cos_in_tx_queue(fp
, cos
)
2754 rc
= bnx2x_clean_tx_queue(bp
, fp
->txdata_ptr
[cos
]);
2761 /* must be called with rtnl_lock */
2762 int bnx2x_nic_unload(struct bnx2x
*bp
, int unload_mode
, bool keep_link
)
2765 bool global
= false;
2767 DP(NETIF_MSG_IFUP
, "Starting NIC unload\n");
2769 /* mark driver is unloaded in shmem2 */
2770 if (IS_PF(bp
) && SHMEM2_HAS(bp
, drv_capabilities_flag
)) {
2772 val
= SHMEM2_RD(bp
, drv_capabilities_flag
[BP_FW_MB_IDX(bp
)]);
2773 SHMEM2_WR(bp
, drv_capabilities_flag
[BP_FW_MB_IDX(bp
)],
2774 val
& ~DRV_FLAGS_CAPABILITIES_LOADED_L2
);
2778 (bp
->state
== BNX2X_STATE_CLOSED
||
2779 bp
->state
== BNX2X_STATE_ERROR
)) {
2780 /* We can get here if the driver has been unloaded
2781 * during parity error recovery and is either waiting for a
2782 * leader to complete or for other functions to unload and
2783 * then ifdown has been issued. In this case we want to
2784 * unload and let other functions to complete a recovery
2787 bp
->recovery_state
= BNX2X_RECOVERY_DONE
;
2789 bnx2x_release_leader_lock(bp
);
2792 DP(NETIF_MSG_IFDOWN
, "Releasing a leadership...\n");
2793 BNX2X_ERR("Can't unload in closed or error state\n");
2798 * It's important to set the bp->state to the value different from
2799 * BNX2X_STATE_OPEN and only then stop the Tx. Otherwise bnx2x_tx_int()
2800 * may restart the Tx from the NAPI context (see bnx2x_tx_int()).
2802 bp
->state
= BNX2X_STATE_CLOSING_WAIT4_HALT
;
2805 if (CNIC_LOADED(bp
))
2806 bnx2x_cnic_notify(bp
, CNIC_CTL_STOP_CMD
);
2809 bnx2x_tx_disable(bp
);
2810 netdev_reset_tc(bp
->dev
);
2812 bp
->rx_mode
= BNX2X_RX_MODE_NONE
;
2814 del_timer_sync(&bp
->timer
);
2817 /* Set ALWAYS_ALIVE bit in shmem */
2818 bp
->fw_drv_pulse_wr_seq
|= DRV_PULSE_ALWAYS_ALIVE
;
2819 bnx2x_drv_pulse(bp
);
2820 bnx2x_stats_handle(bp
, STATS_EVENT_STOP
);
2821 bnx2x_save_statistics(bp
);
2824 /* wait till consumers catch up with producers in all queues */
2825 bnx2x_drain_tx_queues(bp
);
2827 /* if VF indicate to PF this function is going down (PF will delete sp
2828 * elements and clear initializations
2831 bnx2x_vfpf_close_vf(bp
);
2832 else if (unload_mode
!= UNLOAD_RECOVERY
)
2833 /* if this is a normal/close unload need to clean up chip*/
2834 bnx2x_chip_cleanup(bp
, unload_mode
, keep_link
);
2836 /* Send the UNLOAD_REQUEST to the MCP */
2837 bnx2x_send_unload_req(bp
, unload_mode
);
2840 * Prevent transactions to host from the functions on the
2841 * engine that doesn't reset global blocks in case of global
2842 * attention once gloabl blocks are reset and gates are opened
2843 * (the engine which leader will perform the recovery
2846 if (!CHIP_IS_E1x(bp
))
2847 bnx2x_pf_disable(bp
);
2849 /* Disable HW interrupts, NAPI */
2850 bnx2x_netif_stop(bp
, 1);
2851 /* Delete all NAPI objects */
2852 bnx2x_del_all_napi(bp
);
2853 if (CNIC_LOADED(bp
))
2854 bnx2x_del_all_napi_cnic(bp
);
2858 /* Report UNLOAD_DONE to MCP */
2859 bnx2x_send_unload_done(bp
, false);
2863 * At this stage no more interrupts will arrive so we may safly clean
2864 * the queueable objects here in case they failed to get cleaned so far.
2867 bnx2x_squeeze_objects(bp
);
2869 /* There should be no more pending SP commands at this stage */
2874 /* Free SKBs, SGEs, TPA pool and driver internals */
2875 bnx2x_free_skbs(bp
);
2876 if (CNIC_LOADED(bp
))
2877 bnx2x_free_skbs_cnic(bp
);
2878 for_each_rx_queue(bp
, i
)
2879 bnx2x_free_rx_sge_range(bp
, bp
->fp
+ i
, NUM_RX_SGE
);
2881 bnx2x_free_fp_mem(bp
);
2882 if (CNIC_LOADED(bp
))
2883 bnx2x_free_fp_mem_cnic(bp
);
2887 if (CNIC_LOADED(bp
))
2888 bnx2x_free_mem_cnic(bp
);
2890 bp
->state
= BNX2X_STATE_CLOSED
;
2891 bp
->cnic_loaded
= false;
2893 /* Check if there are pending parity attentions. If there are - set
2894 * RECOVERY_IN_PROGRESS.
2896 if (IS_PF(bp
) && bnx2x_chk_parity_attn(bp
, &global
, false)) {
2897 bnx2x_set_reset_in_progress(bp
);
2899 /* Set RESET_IS_GLOBAL if needed */
2901 bnx2x_set_reset_global(bp
);
2905 /* The last driver must disable a "close the gate" if there is no
2906 * parity attention or "process kill" pending.
2909 !bnx2x_clear_pf_load(bp
) &&
2910 bnx2x_reset_is_done(bp
, BP_PATH(bp
)))
2911 bnx2x_disable_close_the_gate(bp
);
2913 DP(NETIF_MSG_IFUP
, "Ending NIC unload\n");
2918 int bnx2x_set_power_state(struct bnx2x
*bp
, pci_power_t state
)
2922 /* If there is no power capability, silently succeed */
2924 BNX2X_DEV_INFO("No power capability. Breaking.\n");
2928 pci_read_config_word(bp
->pdev
, bp
->pm_cap
+ PCI_PM_CTRL
, &pmcsr
);
2932 pci_write_config_word(bp
->pdev
, bp
->pm_cap
+ PCI_PM_CTRL
,
2933 ((pmcsr
& ~PCI_PM_CTRL_STATE_MASK
) |
2934 PCI_PM_CTRL_PME_STATUS
));
2936 if (pmcsr
& PCI_PM_CTRL_STATE_MASK
)
2937 /* delay required during transition out of D3hot */
2942 /* If there are other clients above don't
2943 shut down the power */
2944 if (atomic_read(&bp
->pdev
->enable_cnt
) != 1)
2946 /* Don't shut down the power for emulation and FPGA */
2947 if (CHIP_REV_IS_SLOW(bp
))
2950 pmcsr
&= ~PCI_PM_CTRL_STATE_MASK
;
2954 pmcsr
|= PCI_PM_CTRL_PME_ENABLE
;
2956 pci_write_config_word(bp
->pdev
, bp
->pm_cap
+ PCI_PM_CTRL
,
2959 /* No more memory access after this point until
2960 * device is brought back to D0.
2965 dev_err(&bp
->pdev
->dev
, "Can't support state = %d\n", state
);
2972 * net_device service functions
2974 int bnx2x_poll(struct napi_struct
*napi
, int budget
)
2978 struct bnx2x_fastpath
*fp
= container_of(napi
, struct bnx2x_fastpath
,
2980 struct bnx2x
*bp
= fp
->bp
;
2983 #ifdef BNX2X_STOP_ON_ERROR
2984 if (unlikely(bp
->panic
)) {
2985 napi_complete(napi
);
2990 for_each_cos_in_tx_queue(fp
, cos
)
2991 if (bnx2x_tx_queue_has_work(fp
->txdata_ptr
[cos
]))
2992 bnx2x_tx_int(bp
, fp
->txdata_ptr
[cos
]);
2995 if (bnx2x_has_rx_work(fp
)) {
2996 work_done
+= bnx2x_rx_int(fp
, budget
- work_done
);
2998 /* must not complete if we consumed full budget */
2999 if (work_done
>= budget
)
3003 /* Fall out from the NAPI loop if needed */
3004 if (!(bnx2x_has_rx_work(fp
) || bnx2x_has_tx_work(fp
))) {
3006 /* No need to update SB for FCoE L2 ring as long as
3007 * it's connected to the default SB and the SB
3008 * has been updated when NAPI was scheduled.
3010 if (IS_FCOE_FP(fp
)) {
3011 napi_complete(napi
);
3014 bnx2x_update_fpsb_idx(fp
);
3015 /* bnx2x_has_rx_work() reads the status block,
3016 * thus we need to ensure that status block indices
3017 * have been actually read (bnx2x_update_fpsb_idx)
3018 * prior to this check (bnx2x_has_rx_work) so that
3019 * we won't write the "newer" value of the status block
3020 * to IGU (if there was a DMA right after
3021 * bnx2x_has_rx_work and if there is no rmb, the memory
3022 * reading (bnx2x_update_fpsb_idx) may be postponed
3023 * to right before bnx2x_ack_sb). In this case there
3024 * will never be another interrupt until there is
3025 * another update of the status block, while there
3026 * is still unhandled work.
3030 if (!(bnx2x_has_rx_work(fp
) || bnx2x_has_tx_work(fp
))) {
3031 napi_complete(napi
);
3032 /* Re-enable interrupts */
3033 DP(NETIF_MSG_RX_STATUS
,
3034 "Update index to %d\n", fp
->fp_hc_idx
);
3035 bnx2x_ack_sb(bp
, fp
->igu_sb_id
, USTORM_ID
,
3036 le16_to_cpu(fp
->fp_hc_idx
),
3046 /* we split the first BD into headers and data BDs
3047 * to ease the pain of our fellow microcode engineers
3048 * we use one mapping for both BDs
3050 static noinline u16
bnx2x_tx_split(struct bnx2x
*bp
,
3051 struct bnx2x_fp_txdata
*txdata
,
3052 struct sw_tx_bd
*tx_buf
,
3053 struct eth_tx_start_bd
**tx_bd
, u16 hlen
,
3054 u16 bd_prod
, int nbd
)
3056 struct eth_tx_start_bd
*h_tx_bd
= *tx_bd
;
3057 struct eth_tx_bd
*d_tx_bd
;
3059 int old_len
= le16_to_cpu(h_tx_bd
->nbytes
);
3061 /* first fix first BD */
3062 h_tx_bd
->nbd
= cpu_to_le16(nbd
);
3063 h_tx_bd
->nbytes
= cpu_to_le16(hlen
);
3065 DP(NETIF_MSG_TX_QUEUED
, "TSO split header size is %d (%x:%x) nbd %d\n",
3066 h_tx_bd
->nbytes
, h_tx_bd
->addr_hi
, h_tx_bd
->addr_lo
, h_tx_bd
->nbd
);
3068 /* now get a new data BD
3069 * (after the pbd) and fill it */
3070 bd_prod
= TX_BD(NEXT_TX_IDX(bd_prod
));
3071 d_tx_bd
= &txdata
->tx_desc_ring
[bd_prod
].reg_bd
;
3073 mapping
= HILO_U64(le32_to_cpu(h_tx_bd
->addr_hi
),
3074 le32_to_cpu(h_tx_bd
->addr_lo
)) + hlen
;
3076 d_tx_bd
->addr_hi
= cpu_to_le32(U64_HI(mapping
));
3077 d_tx_bd
->addr_lo
= cpu_to_le32(U64_LO(mapping
));
3078 d_tx_bd
->nbytes
= cpu_to_le16(old_len
- hlen
);
3080 /* this marks the BD as one that has no individual mapping */
3081 tx_buf
->flags
|= BNX2X_TSO_SPLIT_BD
;
3083 DP(NETIF_MSG_TX_QUEUED
,
3084 "TSO split data size is %d (%x:%x)\n",
3085 d_tx_bd
->nbytes
, d_tx_bd
->addr_hi
, d_tx_bd
->addr_lo
);
3088 *tx_bd
= (struct eth_tx_start_bd
*)d_tx_bd
;
3093 static inline u16
bnx2x_csum_fix(unsigned char *t_header
, u16 csum
, s8 fix
)
3096 csum
= (u16
) ~csum_fold(csum_sub(csum
,
3097 csum_partial(t_header
- fix
, fix
, 0)));
3100 csum
= (u16
) ~csum_fold(csum_add(csum
,
3101 csum_partial(t_header
, -fix
, 0)));
3103 return swab16(csum
);
3106 static inline u32
bnx2x_xmit_type(struct bnx2x
*bp
, struct sk_buff
*skb
)
3110 if (skb
->ip_summed
!= CHECKSUM_PARTIAL
)
3114 if (vlan_get_protocol(skb
) == htons(ETH_P_IPV6
)) {
3116 if (ipv6_hdr(skb
)->nexthdr
== IPPROTO_TCP
)
3117 rc
|= XMIT_CSUM_TCP
;
3121 if (ip_hdr(skb
)->protocol
== IPPROTO_TCP
)
3122 rc
|= XMIT_CSUM_TCP
;
3126 if (skb_is_gso_v6(skb
))
3127 rc
|= XMIT_GSO_V6
| XMIT_CSUM_TCP
| XMIT_CSUM_V6
;
3128 else if (skb_is_gso(skb
))
3129 rc
|= XMIT_GSO_V4
| XMIT_CSUM_V4
| XMIT_CSUM_TCP
;
3134 #if (MAX_SKB_FRAGS >= MAX_FETCH_BD - 3)
3135 /* check if packet requires linearization (packet is too fragmented)
3136 no need to check fragmentation if page size > 8K (there will be no
3137 violation to FW restrictions) */
3138 static int bnx2x_pkt_req_lin(struct bnx2x
*bp
, struct sk_buff
*skb
,
3143 int first_bd_sz
= 0;
3145 /* 3 = 1 (for linear data BD) + 2 (for PBD and last BD) */
3146 if (skb_shinfo(skb
)->nr_frags
>= (MAX_FETCH_BD
- 3)) {
3148 if (xmit_type
& XMIT_GSO
) {
3149 unsigned short lso_mss
= skb_shinfo(skb
)->gso_size
;
3150 /* Check if LSO packet needs to be copied:
3151 3 = 1 (for headers BD) + 2 (for PBD and last BD) */
3152 int wnd_size
= MAX_FETCH_BD
- 3;
3153 /* Number of windows to check */
3154 int num_wnds
= skb_shinfo(skb
)->nr_frags
- wnd_size
;
3159 /* Headers length */
3160 hlen
= (int)(skb_transport_header(skb
) - skb
->data
) +
3163 /* Amount of data (w/o headers) on linear part of SKB*/
3164 first_bd_sz
= skb_headlen(skb
) - hlen
;
3166 wnd_sum
= first_bd_sz
;
3168 /* Calculate the first sum - it's special */
3169 for (frag_idx
= 0; frag_idx
< wnd_size
- 1; frag_idx
++)
3171 skb_frag_size(&skb_shinfo(skb
)->frags
[frag_idx
]);
3173 /* If there was data on linear skb data - check it */
3174 if (first_bd_sz
> 0) {
3175 if (unlikely(wnd_sum
< lso_mss
)) {
3180 wnd_sum
-= first_bd_sz
;
3183 /* Others are easier: run through the frag list and
3184 check all windows */
3185 for (wnd_idx
= 0; wnd_idx
<= num_wnds
; wnd_idx
++) {
3187 skb_frag_size(&skb_shinfo(skb
)->frags
[wnd_idx
+ wnd_size
- 1]);
3189 if (unlikely(wnd_sum
< lso_mss
)) {
3194 skb_frag_size(&skb_shinfo(skb
)->frags
[wnd_idx
]);
3197 /* in non-LSO too fragmented packet should always
3204 if (unlikely(to_copy
))
3205 DP(NETIF_MSG_TX_QUEUED
,
3206 "Linearization IS REQUIRED for %s packet. num_frags %d hlen %d first_bd_sz %d\n",
3207 (xmit_type
& XMIT_GSO
) ? "LSO" : "non-LSO",
3208 skb_shinfo(skb
)->nr_frags
, hlen
, first_bd_sz
);
3214 static inline void bnx2x_set_pbd_gso_e2(struct sk_buff
*skb
, u32
*parsing_data
,
3217 *parsing_data
|= (skb_shinfo(skb
)->gso_size
<<
3218 ETH_TX_PARSE_BD_E2_LSO_MSS_SHIFT
) &
3219 ETH_TX_PARSE_BD_E2_LSO_MSS
;
3220 if ((xmit_type
& XMIT_GSO_V6
) &&
3221 (ipv6_hdr(skb
)->nexthdr
== NEXTHDR_IPV6
))
3222 *parsing_data
|= ETH_TX_PARSE_BD_E2_IPV6_WITH_EXT_HDR
;
3226 * bnx2x_set_pbd_gso - update PBD in GSO case.
3230 * @xmit_type: xmit flags
3232 static inline void bnx2x_set_pbd_gso(struct sk_buff
*skb
,
3233 struct eth_tx_parse_bd_e1x
*pbd
,
3236 pbd
->lso_mss
= cpu_to_le16(skb_shinfo(skb
)->gso_size
);
3237 pbd
->tcp_send_seq
= swab32(tcp_hdr(skb
)->seq
);
3238 pbd
->tcp_flags
= pbd_tcp_flags(skb
);
3240 if (xmit_type
& XMIT_GSO_V4
) {
3241 pbd
->ip_id
= swab16(ip_hdr(skb
)->id
);
3242 pbd
->tcp_pseudo_csum
=
3243 swab16(~csum_tcpudp_magic(ip_hdr(skb
)->saddr
,
3245 0, IPPROTO_TCP
, 0));
3248 pbd
->tcp_pseudo_csum
=
3249 swab16(~csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
,
3250 &ipv6_hdr(skb
)->daddr
,
3251 0, IPPROTO_TCP
, 0));
3253 pbd
->global_data
|= ETH_TX_PARSE_BD_E1X_PSEUDO_CS_WITHOUT_LEN
;
3257 * bnx2x_set_pbd_csum_e2 - update PBD with checksum and return header length
3259 * @bp: driver handle
3261 * @parsing_data: data to be updated
3262 * @xmit_type: xmit flags
3266 static inline u8
bnx2x_set_pbd_csum_e2(struct bnx2x
*bp
, struct sk_buff
*skb
,
3267 u32
*parsing_data
, u32 xmit_type
)
3270 ((((u8
*)skb_transport_header(skb
) - skb
->data
) >> 1) <<
3271 ETH_TX_PARSE_BD_E2_TCP_HDR_START_OFFSET_W_SHIFT
) &
3272 ETH_TX_PARSE_BD_E2_TCP_HDR_START_OFFSET_W
;
3274 if (xmit_type
& XMIT_CSUM_TCP
) {
3275 *parsing_data
|= ((tcp_hdrlen(skb
) / 4) <<
3276 ETH_TX_PARSE_BD_E2_TCP_HDR_LENGTH_DW_SHIFT
) &
3277 ETH_TX_PARSE_BD_E2_TCP_HDR_LENGTH_DW
;
3279 return skb_transport_header(skb
) + tcp_hdrlen(skb
) - skb
->data
;
3281 /* We support checksum offload for TCP and UDP only.
3282 * No need to pass the UDP header length - it's a constant.
3284 return skb_transport_header(skb
) +
3285 sizeof(struct udphdr
) - skb
->data
;
3288 static inline void bnx2x_set_sbd_csum(struct bnx2x
*bp
, struct sk_buff
*skb
,
3289 struct eth_tx_start_bd
*tx_start_bd
, u32 xmit_type
)
3291 tx_start_bd
->bd_flags
.as_bitfield
|= ETH_TX_BD_FLAGS_L4_CSUM
;
3293 if (xmit_type
& XMIT_CSUM_V4
)
3294 tx_start_bd
->bd_flags
.as_bitfield
|=
3295 ETH_TX_BD_FLAGS_IP_CSUM
;
3297 tx_start_bd
->bd_flags
.as_bitfield
|=
3298 ETH_TX_BD_FLAGS_IPV6
;
3300 if (!(xmit_type
& XMIT_CSUM_TCP
))
3301 tx_start_bd
->bd_flags
.as_bitfield
|= ETH_TX_BD_FLAGS_IS_UDP
;
3305 * bnx2x_set_pbd_csum - update PBD with checksum and return header length
3307 * @bp: driver handle
3309 * @pbd: parse BD to be updated
3310 * @xmit_type: xmit flags
3312 static inline u8
bnx2x_set_pbd_csum(struct bnx2x
*bp
, struct sk_buff
*skb
,
3313 struct eth_tx_parse_bd_e1x
*pbd
,
3316 u8 hlen
= (skb_network_header(skb
) - skb
->data
) >> 1;
3318 /* for now NS flag is not used in Linux */
3320 (hlen
| ((skb
->protocol
== cpu_to_be16(ETH_P_8021Q
)) <<
3321 ETH_TX_PARSE_BD_E1X_LLC_SNAP_EN_SHIFT
));
3323 pbd
->ip_hlen_w
= (skb_transport_header(skb
) -
3324 skb_network_header(skb
)) >> 1;
3326 hlen
+= pbd
->ip_hlen_w
;
3328 /* We support checksum offload for TCP and UDP only */
3329 if (xmit_type
& XMIT_CSUM_TCP
)
3330 hlen
+= tcp_hdrlen(skb
) / 2;
3332 hlen
+= sizeof(struct udphdr
) / 2;
3334 pbd
->total_hlen_w
= cpu_to_le16(hlen
);
3337 if (xmit_type
& XMIT_CSUM_TCP
) {
3338 pbd
->tcp_pseudo_csum
= swab16(tcp_hdr(skb
)->check
);
3341 s8 fix
= SKB_CS_OFF(skb
); /* signed! */
3343 DP(NETIF_MSG_TX_QUEUED
,
3344 "hlen %d fix %d csum before fix %x\n",
3345 le16_to_cpu(pbd
->total_hlen_w
), fix
, SKB_CS(skb
));
3347 /* HW bug: fixup the CSUM */
3348 pbd
->tcp_pseudo_csum
=
3349 bnx2x_csum_fix(skb_transport_header(skb
),
3352 DP(NETIF_MSG_TX_QUEUED
, "csum after fix %x\n",
3353 pbd
->tcp_pseudo_csum
);
3359 /* called with netif_tx_lock
3360 * bnx2x_tx_int() runs without netif_tx_lock unless it needs to call
3361 * netif_wake_queue()
3363 netdev_tx_t
bnx2x_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
3365 struct bnx2x
*bp
= netdev_priv(dev
);
3367 struct netdev_queue
*txq
;
3368 struct bnx2x_fp_txdata
*txdata
;
3369 struct sw_tx_bd
*tx_buf
;
3370 struct eth_tx_start_bd
*tx_start_bd
, *first_bd
;
3371 struct eth_tx_bd
*tx_data_bd
, *total_pkt_bd
= NULL
;
3372 struct eth_tx_parse_bd_e1x
*pbd_e1x
= NULL
;
3373 struct eth_tx_parse_bd_e2
*pbd_e2
= NULL
;
3374 u32 pbd_e2_parsing_data
= 0;
3375 u16 pkt_prod
, bd_prod
;
3378 u32 xmit_type
= bnx2x_xmit_type(bp
, skb
);
3381 __le16 pkt_size
= 0;
3383 u8 mac_type
= UNICAST_ADDRESS
;
3385 #ifdef BNX2X_STOP_ON_ERROR
3386 if (unlikely(bp
->panic
))
3387 return NETDEV_TX_BUSY
;
3390 txq_index
= skb_get_queue_mapping(skb
);
3391 txq
= netdev_get_tx_queue(dev
, txq_index
);
3393 BUG_ON(txq_index
>= MAX_ETH_TXQ_IDX(bp
) + (CNIC_LOADED(bp
) ? 1 : 0));
3395 txdata
= &bp
->bnx2x_txq
[txq_index
];
3397 /* enable this debug print to view the transmission queue being used
3398 DP(NETIF_MSG_TX_QUEUED, "indices: txq %d, fp %d, txdata %d\n",
3399 txq_index, fp_index, txdata_index); */
3401 /* enable this debug print to view the tranmission details
3402 DP(NETIF_MSG_TX_QUEUED,
3403 "transmitting packet cid %d fp index %d txdata_index %d tx_data ptr %p fp pointer %p\n",
3404 txdata->cid, fp_index, txdata_index, txdata, fp); */
3406 if (unlikely(bnx2x_tx_avail(bp
, txdata
) <
3407 skb_shinfo(skb
)->nr_frags
+
3409 NEXT_CNT_PER_TX_PKT(MAX_BDS_PER_TX_PKT
))) {
3410 /* Handle special storage cases separately */
3411 if (txdata
->tx_ring_size
== 0) {
3412 struct bnx2x_eth_q_stats
*q_stats
=
3413 bnx2x_fp_qstats(bp
, txdata
->parent_fp
);
3414 q_stats
->driver_filtered_tx_pkt
++;
3416 return NETDEV_TX_OK
;
3418 bnx2x_fp_qstats(bp
, txdata
->parent_fp
)->driver_xoff
++;
3419 netif_tx_stop_queue(txq
);
3420 BNX2X_ERR("BUG! Tx ring full when queue awake!\n");
3422 return NETDEV_TX_BUSY
;
3425 DP(NETIF_MSG_TX_QUEUED
,
3426 "queue[%d]: SKB: summed %x protocol %x protocol(%x,%x) gso type %x xmit_type %x\n",
3427 txq_index
, skb
->ip_summed
, skb
->protocol
, ipv6_hdr(skb
)->nexthdr
,
3428 ip_hdr(skb
)->protocol
, skb_shinfo(skb
)->gso_type
, xmit_type
);
3430 eth
= (struct ethhdr
*)skb
->data
;
3432 /* set flag according to packet type (UNICAST_ADDRESS is default)*/
3433 if (unlikely(is_multicast_ether_addr(eth
->h_dest
))) {
3434 if (is_broadcast_ether_addr(eth
->h_dest
))
3435 mac_type
= BROADCAST_ADDRESS
;
3437 mac_type
= MULTICAST_ADDRESS
;
3440 #if (MAX_SKB_FRAGS >= MAX_FETCH_BD - 3)
3441 /* First, check if we need to linearize the skb (due to FW
3442 restrictions). No need to check fragmentation if page size > 8K
3443 (there will be no violation to FW restrictions) */
3444 if (bnx2x_pkt_req_lin(bp
, skb
, xmit_type
)) {
3445 /* Statistics of linearization */
3447 if (skb_linearize(skb
) != 0) {
3448 DP(NETIF_MSG_TX_QUEUED
,
3449 "SKB linearization failed - silently dropping this SKB\n");
3450 dev_kfree_skb_any(skb
);
3451 return NETDEV_TX_OK
;
3455 /* Map skb linear data for DMA */
3456 mapping
= dma_map_single(&bp
->pdev
->dev
, skb
->data
,
3457 skb_headlen(skb
), DMA_TO_DEVICE
);
3458 if (unlikely(dma_mapping_error(&bp
->pdev
->dev
, mapping
))) {
3459 DP(NETIF_MSG_TX_QUEUED
,
3460 "SKB mapping failed - silently dropping this SKB\n");
3461 dev_kfree_skb_any(skb
);
3462 return NETDEV_TX_OK
;
3465 Please read carefully. First we use one BD which we mark as start,
3466 then we have a parsing info BD (used for TSO or xsum),
3467 and only then we have the rest of the TSO BDs.
3468 (don't forget to mark the last one as last,
3469 and to unmap only AFTER you write to the BD ...)
3470 And above all, all pdb sizes are in words - NOT DWORDS!
3473 /* get current pkt produced now - advance it just before sending packet
3474 * since mapping of pages may fail and cause packet to be dropped
3476 pkt_prod
= txdata
->tx_pkt_prod
;
3477 bd_prod
= TX_BD(txdata
->tx_bd_prod
);
3479 /* get a tx_buf and first BD
3480 * tx_start_bd may be changed during SPLIT,
3481 * but first_bd will always stay first
3483 tx_buf
= &txdata
->tx_buf_ring
[TX_BD(pkt_prod
)];
3484 tx_start_bd
= &txdata
->tx_desc_ring
[bd_prod
].start_bd
;
3485 first_bd
= tx_start_bd
;
3487 tx_start_bd
->bd_flags
.as_bitfield
= ETH_TX_BD_FLAGS_START_BD
;
3488 SET_FLAG(tx_start_bd
->general_data
,
3489 ETH_TX_START_BD_PARSE_NBDS
,
3493 SET_FLAG(tx_start_bd
->general_data
, ETH_TX_START_BD_HDR_NBDS
, 1);
3495 /* remember the first BD of the packet */
3496 tx_buf
->first_bd
= txdata
->tx_bd_prod
;
3500 DP(NETIF_MSG_TX_QUEUED
,
3501 "sending pkt %u @%p next_idx %u bd %u @%p\n",
3502 pkt_prod
, tx_buf
, txdata
->tx_pkt_prod
, bd_prod
, tx_start_bd
);
3504 if (vlan_tx_tag_present(skb
)) {
3505 tx_start_bd
->vlan_or_ethertype
=
3506 cpu_to_le16(vlan_tx_tag_get(skb
));
3507 tx_start_bd
->bd_flags
.as_bitfield
|=
3508 (X_ETH_OUTBAND_VLAN
<< ETH_TX_BD_FLAGS_VLAN_MODE_SHIFT
);
3510 /* when transmitting in a vf, start bd must hold the ethertype
3511 * for fw to enforce it
3514 tx_start_bd
->vlan_or_ethertype
=
3515 cpu_to_le16(ntohs(eth
->h_proto
));
3517 /* used by FW for packet accounting */
3518 tx_start_bd
->vlan_or_ethertype
= cpu_to_le16(pkt_prod
);
3522 /* turn on parsing and get a BD */
3523 bd_prod
= TX_BD(NEXT_TX_IDX(bd_prod
));
3525 if (xmit_type
& XMIT_CSUM
)
3526 bnx2x_set_sbd_csum(bp
, skb
, tx_start_bd
, xmit_type
);
3528 if (!CHIP_IS_E1x(bp
)) {
3529 pbd_e2
= &txdata
->tx_desc_ring
[bd_prod
].parse_bd_e2
;
3530 memset(pbd_e2
, 0, sizeof(struct eth_tx_parse_bd_e2
));
3531 /* Set PBD in checksum offload case */
3532 if (xmit_type
& XMIT_CSUM
)
3533 hlen
= bnx2x_set_pbd_csum_e2(bp
, skb
,
3534 &pbd_e2_parsing_data
,
3537 if (IS_MF_SI(bp
) || IS_VF(bp
)) {
3538 /* fill in the MAC addresses in the PBD - for local
3541 bnx2x_set_fw_mac_addr(&pbd_e2
->src_mac_addr_hi
,
3542 &pbd_e2
->src_mac_addr_mid
,
3543 &pbd_e2
->src_mac_addr_lo
,
3545 bnx2x_set_fw_mac_addr(&pbd_e2
->dst_mac_addr_hi
,
3546 &pbd_e2
->dst_mac_addr_mid
,
3547 &pbd_e2
->dst_mac_addr_lo
,
3551 SET_FLAG(pbd_e2_parsing_data
,
3552 ETH_TX_PARSE_BD_E2_ETH_ADDR_TYPE
, mac_type
);
3554 u16 global_data
= 0;
3555 pbd_e1x
= &txdata
->tx_desc_ring
[bd_prod
].parse_bd_e1x
;
3556 memset(pbd_e1x
, 0, sizeof(struct eth_tx_parse_bd_e1x
));
3557 /* Set PBD in checksum offload case */
3558 if (xmit_type
& XMIT_CSUM
)
3559 hlen
= bnx2x_set_pbd_csum(bp
, skb
, pbd_e1x
, xmit_type
);
3561 SET_FLAG(global_data
,
3562 ETH_TX_PARSE_BD_E1X_ETH_ADDR_TYPE
, mac_type
);
3563 pbd_e1x
->global_data
|= cpu_to_le16(global_data
);
3566 /* Setup the data pointer of the first BD of the packet */
3567 tx_start_bd
->addr_hi
= cpu_to_le32(U64_HI(mapping
));
3568 tx_start_bd
->addr_lo
= cpu_to_le32(U64_LO(mapping
));
3569 nbd
= 2; /* start_bd + pbd + frags (updated when pages are mapped) */
3570 tx_start_bd
->nbytes
= cpu_to_le16(skb_headlen(skb
));
3571 pkt_size
= tx_start_bd
->nbytes
;
3573 DP(NETIF_MSG_TX_QUEUED
,
3574 "first bd @%p addr (%x:%x) nbd %d nbytes %d flags %x vlan %x\n",
3575 tx_start_bd
, tx_start_bd
->addr_hi
, tx_start_bd
->addr_lo
,
3576 le16_to_cpu(tx_start_bd
->nbd
), le16_to_cpu(tx_start_bd
->nbytes
),
3577 tx_start_bd
->bd_flags
.as_bitfield
,
3578 le16_to_cpu(tx_start_bd
->vlan_or_ethertype
));
3580 if (xmit_type
& XMIT_GSO
) {
3582 DP(NETIF_MSG_TX_QUEUED
,
3583 "TSO packet len %d hlen %d total len %d tso size %d\n",
3584 skb
->len
, hlen
, skb_headlen(skb
),
3585 skb_shinfo(skb
)->gso_size
);
3587 tx_start_bd
->bd_flags
.as_bitfield
|= ETH_TX_BD_FLAGS_SW_LSO
;
3589 if (unlikely(skb_headlen(skb
) > hlen
))
3590 bd_prod
= bnx2x_tx_split(bp
, txdata
, tx_buf
,
3593 if (!CHIP_IS_E1x(bp
))
3594 bnx2x_set_pbd_gso_e2(skb
, &pbd_e2_parsing_data
,
3597 bnx2x_set_pbd_gso(skb
, pbd_e1x
, xmit_type
);
3600 /* Set the PBD's parsing_data field if not zero
3601 * (for the chips newer than 57711).
3603 if (pbd_e2_parsing_data
)
3604 pbd_e2
->parsing_data
= cpu_to_le32(pbd_e2_parsing_data
);
3606 tx_data_bd
= (struct eth_tx_bd
*)tx_start_bd
;
3608 /* Handle fragmented skb */
3609 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
3610 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[i
];
3612 mapping
= skb_frag_dma_map(&bp
->pdev
->dev
, frag
, 0,
3613 skb_frag_size(frag
), DMA_TO_DEVICE
);
3614 if (unlikely(dma_mapping_error(&bp
->pdev
->dev
, mapping
))) {
3615 unsigned int pkts_compl
= 0, bytes_compl
= 0;
3617 DP(NETIF_MSG_TX_QUEUED
,
3618 "Unable to map page - dropping packet...\n");
3620 /* we need unmap all buffers already mapped
3622 * first_bd->nbd need to be properly updated
3623 * before call to bnx2x_free_tx_pkt
3625 first_bd
->nbd
= cpu_to_le16(nbd
);
3626 bnx2x_free_tx_pkt(bp
, txdata
,
3627 TX_BD(txdata
->tx_pkt_prod
),
3628 &pkts_compl
, &bytes_compl
);
3629 return NETDEV_TX_OK
;
3632 bd_prod
= TX_BD(NEXT_TX_IDX(bd_prod
));
3633 tx_data_bd
= &txdata
->tx_desc_ring
[bd_prod
].reg_bd
;
3634 if (total_pkt_bd
== NULL
)
3635 total_pkt_bd
= &txdata
->tx_desc_ring
[bd_prod
].reg_bd
;
3637 tx_data_bd
->addr_hi
= cpu_to_le32(U64_HI(mapping
));
3638 tx_data_bd
->addr_lo
= cpu_to_le32(U64_LO(mapping
));
3639 tx_data_bd
->nbytes
= cpu_to_le16(skb_frag_size(frag
));
3640 le16_add_cpu(&pkt_size
, skb_frag_size(frag
));
3643 DP(NETIF_MSG_TX_QUEUED
,
3644 "frag %d bd @%p addr (%x:%x) nbytes %d\n",
3645 i
, tx_data_bd
, tx_data_bd
->addr_hi
, tx_data_bd
->addr_lo
,
3646 le16_to_cpu(tx_data_bd
->nbytes
));
3649 DP(NETIF_MSG_TX_QUEUED
, "last bd @%p\n", tx_data_bd
);
3651 /* update with actual num BDs */
3652 first_bd
->nbd
= cpu_to_le16(nbd
);
3654 bd_prod
= TX_BD(NEXT_TX_IDX(bd_prod
));
3656 /* now send a tx doorbell, counting the next BD
3657 * if the packet contains or ends with it
3659 if (TX_BD_POFF(bd_prod
) < nbd
)
3662 /* total_pkt_bytes should be set on the first data BD if
3663 * it's not an LSO packet and there is more than one
3664 * data BD. In this case pkt_size is limited by an MTU value.
3665 * However we prefer to set it for an LSO packet (while we don't
3666 * have to) in order to save some CPU cycles in a none-LSO
3667 * case, when we much more care about them.
3669 if (total_pkt_bd
!= NULL
)
3670 total_pkt_bd
->total_pkt_bytes
= pkt_size
;
3673 DP(NETIF_MSG_TX_QUEUED
,
3674 "PBD (E1X) @%p ip_data %x ip_hlen %u ip_id %u lso_mss %u tcp_flags %x xsum %x seq %u hlen %u\n",
3675 pbd_e1x
, pbd_e1x
->global_data
, pbd_e1x
->ip_hlen_w
,
3676 pbd_e1x
->ip_id
, pbd_e1x
->lso_mss
, pbd_e1x
->tcp_flags
,
3677 pbd_e1x
->tcp_pseudo_csum
, pbd_e1x
->tcp_send_seq
,
3678 le16_to_cpu(pbd_e1x
->total_hlen_w
));
3680 DP(NETIF_MSG_TX_QUEUED
,
3681 "PBD (E2) @%p dst %x %x %x src %x %x %x parsing_data %x\n",
3682 pbd_e2
, pbd_e2
->dst_mac_addr_hi
, pbd_e2
->dst_mac_addr_mid
,
3683 pbd_e2
->dst_mac_addr_lo
, pbd_e2
->src_mac_addr_hi
,
3684 pbd_e2
->src_mac_addr_mid
, pbd_e2
->src_mac_addr_lo
,
3685 pbd_e2
->parsing_data
);
3686 DP(NETIF_MSG_TX_QUEUED
, "doorbell: nbd %d bd %u\n", nbd
, bd_prod
);
3688 netdev_tx_sent_queue(txq
, skb
->len
);
3690 skb_tx_timestamp(skb
);
3692 txdata
->tx_pkt_prod
++;
3694 * Make sure that the BD data is updated before updating the producer
3695 * since FW might read the BD right after the producer is updated.
3696 * This is only applicable for weak-ordered memory model archs such
3697 * as IA-64. The following barrier is also mandatory since FW will
3698 * assumes packets must have BDs.
3702 txdata
->tx_db
.data
.prod
+= nbd
;
3705 DOORBELL(bp
, txdata
->cid
, txdata
->tx_db
.raw
);
3709 txdata
->tx_bd_prod
+= nbd
;
3711 if (unlikely(bnx2x_tx_avail(bp
, txdata
) < MAX_DESC_PER_TX_PKT
)) {
3712 netif_tx_stop_queue(txq
);
3714 /* paired memory barrier is in bnx2x_tx_int(), we have to keep
3715 * ordering of set_bit() in netif_tx_stop_queue() and read of
3719 bnx2x_fp_qstats(bp
, txdata
->parent_fp
)->driver_xoff
++;
3720 if (bnx2x_tx_avail(bp
, txdata
) >= MAX_DESC_PER_TX_PKT
)
3721 netif_tx_wake_queue(txq
);
3725 return NETDEV_TX_OK
;
3729 * bnx2x_setup_tc - routine to configure net_device for multi tc
3731 * @netdev: net device to configure
3732 * @tc: number of traffic classes to enable
3734 * callback connected to the ndo_setup_tc function pointer
3736 int bnx2x_setup_tc(struct net_device
*dev
, u8 num_tc
)
3738 int cos
, prio
, count
, offset
;
3739 struct bnx2x
*bp
= netdev_priv(dev
);
3741 /* setup tc must be called under rtnl lock */
3744 /* no traffic classes requested. aborting */
3746 netdev_reset_tc(dev
);
3750 /* requested to support too many traffic classes */
3751 if (num_tc
> bp
->max_cos
) {
3752 BNX2X_ERR("support for too many traffic classes requested: %d. max supported is %d\n",
3753 num_tc
, bp
->max_cos
);
3757 /* declare amount of supported traffic classes */
3758 if (netdev_set_num_tc(dev
, num_tc
)) {
3759 BNX2X_ERR("failed to declare %d traffic classes\n", num_tc
);
3763 /* configure priority to traffic class mapping */
3764 for (prio
= 0; prio
< BNX2X_MAX_PRIORITY
; prio
++) {
3765 netdev_set_prio_tc_map(dev
, prio
, bp
->prio_to_cos
[prio
]);
3766 DP(BNX2X_MSG_SP
| NETIF_MSG_IFUP
,
3767 "mapping priority %d to tc %d\n",
3768 prio
, bp
->prio_to_cos
[prio
]);
3772 /* Use this configuration to diffrentiate tc0 from other COSes
3773 This can be used for ets or pfc, and save the effort of setting
3774 up a multio class queue disc or negotiating DCBX with a switch
3775 netdev_set_prio_tc_map(dev, 0, 0);
3776 DP(BNX2X_MSG_SP, "mapping priority %d to tc %d\n", 0, 0);
3777 for (prio = 1; prio < 16; prio++) {
3778 netdev_set_prio_tc_map(dev, prio, 1);
3779 DP(BNX2X_MSG_SP, "mapping priority %d to tc %d\n", prio, 1);
3782 /* configure traffic class to transmission queue mapping */
3783 for (cos
= 0; cos
< bp
->max_cos
; cos
++) {
3784 count
= BNX2X_NUM_ETH_QUEUES(bp
);
3785 offset
= cos
* BNX2X_NUM_NON_CNIC_QUEUES(bp
);
3786 netdev_set_tc_queue(dev
, cos
, count
, offset
);
3787 DP(BNX2X_MSG_SP
| NETIF_MSG_IFUP
,
3788 "mapping tc %d to offset %d count %d\n",
3789 cos
, offset
, count
);
3795 /* called with rtnl_lock */
3796 int bnx2x_change_mac_addr(struct net_device
*dev
, void *p
)
3798 struct sockaddr
*addr
= p
;
3799 struct bnx2x
*bp
= netdev_priv(dev
);
3802 if (!bnx2x_is_valid_ether_addr(bp
, addr
->sa_data
)) {
3803 BNX2X_ERR("Requested MAC address is not valid\n");
3807 if ((IS_MF_STORAGE_SD(bp
) || IS_MF_FCOE_AFEX(bp
)) &&
3808 !is_zero_ether_addr(addr
->sa_data
)) {
3809 BNX2X_ERR("Can't configure non-zero address on iSCSI or FCoE functions in MF-SD mode\n");
3813 if (netif_running(dev
)) {
3814 rc
= bnx2x_set_eth_mac(bp
, false);
3819 memcpy(dev
->dev_addr
, addr
->sa_data
, dev
->addr_len
);
3821 if (netif_running(dev
))
3822 rc
= bnx2x_set_eth_mac(bp
, true);
3827 static void bnx2x_free_fp_mem_at(struct bnx2x
*bp
, int fp_index
)
3829 union host_hc_status_block
*sb
= &bnx2x_fp(bp
, fp_index
, status_blk
);
3830 struct bnx2x_fastpath
*fp
= &bp
->fp
[fp_index
];
3835 if (IS_FCOE_IDX(fp_index
)) {
3836 memset(sb
, 0, sizeof(union host_hc_status_block
));
3837 fp
->status_blk_mapping
= 0;
3840 if (!CHIP_IS_E1x(bp
))
3841 BNX2X_PCI_FREE(sb
->e2_sb
,
3842 bnx2x_fp(bp
, fp_index
,
3843 status_blk_mapping
),
3844 sizeof(struct host_hc_status_block_e2
));
3846 BNX2X_PCI_FREE(sb
->e1x_sb
,
3847 bnx2x_fp(bp
, fp_index
,
3848 status_blk_mapping
),
3849 sizeof(struct host_hc_status_block_e1x
));
3853 if (!skip_rx_queue(bp
, fp_index
)) {
3854 bnx2x_free_rx_bds(fp
);
3856 /* fastpath rx rings: rx_buf rx_desc rx_comp */
3857 BNX2X_FREE(bnx2x_fp(bp
, fp_index
, rx_buf_ring
));
3858 BNX2X_PCI_FREE(bnx2x_fp(bp
, fp_index
, rx_desc_ring
),
3859 bnx2x_fp(bp
, fp_index
, rx_desc_mapping
),
3860 sizeof(struct eth_rx_bd
) * NUM_RX_BD
);
3862 BNX2X_PCI_FREE(bnx2x_fp(bp
, fp_index
, rx_comp_ring
),
3863 bnx2x_fp(bp
, fp_index
, rx_comp_mapping
),
3864 sizeof(struct eth_fast_path_rx_cqe
) *
3868 BNX2X_FREE(bnx2x_fp(bp
, fp_index
, rx_page_ring
));
3869 BNX2X_PCI_FREE(bnx2x_fp(bp
, fp_index
, rx_sge_ring
),
3870 bnx2x_fp(bp
, fp_index
, rx_sge_mapping
),
3871 BCM_PAGE_SIZE
* NUM_RX_SGE_PAGES
);
3875 if (!skip_tx_queue(bp
, fp_index
)) {
3876 /* fastpath tx rings: tx_buf tx_desc */
3877 for_each_cos_in_tx_queue(fp
, cos
) {
3878 struct bnx2x_fp_txdata
*txdata
= fp
->txdata_ptr
[cos
];
3880 DP(NETIF_MSG_IFDOWN
,
3881 "freeing tx memory of fp %d cos %d cid %d\n",
3882 fp_index
, cos
, txdata
->cid
);
3884 BNX2X_FREE(txdata
->tx_buf_ring
);
3885 BNX2X_PCI_FREE(txdata
->tx_desc_ring
,
3886 txdata
->tx_desc_mapping
,
3887 sizeof(union eth_tx_bd_types
) * NUM_TX_BD
);
3890 /* end of fastpath */
3893 void bnx2x_free_fp_mem_cnic(struct bnx2x
*bp
)
3896 for_each_cnic_queue(bp
, i
)
3897 bnx2x_free_fp_mem_at(bp
, i
);
3900 void bnx2x_free_fp_mem(struct bnx2x
*bp
)
3903 for_each_eth_queue(bp
, i
)
3904 bnx2x_free_fp_mem_at(bp
, i
);
3907 static void set_sb_shortcuts(struct bnx2x
*bp
, int index
)
3909 union host_hc_status_block status_blk
= bnx2x_fp(bp
, index
, status_blk
);
3910 if (!CHIP_IS_E1x(bp
)) {
3911 bnx2x_fp(bp
, index
, sb_index_values
) =
3912 (__le16
*)status_blk
.e2_sb
->sb
.index_values
;
3913 bnx2x_fp(bp
, index
, sb_running_index
) =
3914 (__le16
*)status_blk
.e2_sb
->sb
.running_index
;
3916 bnx2x_fp(bp
, index
, sb_index_values
) =
3917 (__le16
*)status_blk
.e1x_sb
->sb
.index_values
;
3918 bnx2x_fp(bp
, index
, sb_running_index
) =
3919 (__le16
*)status_blk
.e1x_sb
->sb
.running_index
;
3923 /* Returns the number of actually allocated BDs */
3924 static int bnx2x_alloc_rx_bds(struct bnx2x_fastpath
*fp
,
3927 struct bnx2x
*bp
= fp
->bp
;
3928 u16 ring_prod
, cqe_ring_prod
;
3929 int i
, failure_cnt
= 0;
3931 fp
->rx_comp_cons
= 0;
3932 cqe_ring_prod
= ring_prod
= 0;
3934 /* This routine is called only during fo init so
3935 * fp->eth_q_stats.rx_skb_alloc_failed = 0
3937 for (i
= 0; i
< rx_ring_size
; i
++) {
3938 if (bnx2x_alloc_rx_data(bp
, fp
, ring_prod
) < 0) {
3942 ring_prod
= NEXT_RX_IDX(ring_prod
);
3943 cqe_ring_prod
= NEXT_RCQ_IDX(cqe_ring_prod
);
3944 WARN_ON(ring_prod
<= (i
- failure_cnt
));
3948 BNX2X_ERR("was only able to allocate %d rx skbs on queue[%d]\n",
3949 i
- failure_cnt
, fp
->index
);
3951 fp
->rx_bd_prod
= ring_prod
;
3952 /* Limit the CQE producer by the CQE ring size */
3953 fp
->rx_comp_prod
= min_t(u16
, NUM_RCQ_RINGS
*RCQ_DESC_CNT
,
3955 fp
->rx_pkt
= fp
->rx_calls
= 0;
3957 bnx2x_fp_stats(bp
, fp
)->eth_q_stats
.rx_skb_alloc_failed
+= failure_cnt
;
3959 return i
- failure_cnt
;
3962 static void bnx2x_set_next_page_rx_cq(struct bnx2x_fastpath
*fp
)
3966 for (i
= 1; i
<= NUM_RCQ_RINGS
; i
++) {
3967 struct eth_rx_cqe_next_page
*nextpg
;
3969 nextpg
= (struct eth_rx_cqe_next_page
*)
3970 &fp
->rx_comp_ring
[RCQ_DESC_CNT
* i
- 1];
3972 cpu_to_le32(U64_HI(fp
->rx_comp_mapping
+
3973 BCM_PAGE_SIZE
*(i
% NUM_RCQ_RINGS
)));
3975 cpu_to_le32(U64_LO(fp
->rx_comp_mapping
+
3976 BCM_PAGE_SIZE
*(i
% NUM_RCQ_RINGS
)));
3980 static int bnx2x_alloc_fp_mem_at(struct bnx2x
*bp
, int index
)
3982 union host_hc_status_block
*sb
;
3983 struct bnx2x_fastpath
*fp
= &bp
->fp
[index
];
3986 int rx_ring_size
= 0;
3988 if (!bp
->rx_ring_size
&&
3989 (IS_MF_STORAGE_SD(bp
) || IS_MF_FCOE_AFEX(bp
))) {
3990 rx_ring_size
= MIN_RX_SIZE_NONTPA
;
3991 bp
->rx_ring_size
= rx_ring_size
;
3992 } else if (!bp
->rx_ring_size
) {
3993 rx_ring_size
= MAX_RX_AVAIL
/BNX2X_NUM_RX_QUEUES(bp
);
3995 if (CHIP_IS_E3(bp
)) {
3996 u32 cfg
= SHMEM_RD(bp
,
3997 dev_info
.port_hw_config
[BP_PORT(bp
)].
4000 /* Decrease ring size for 1G functions */
4001 if ((cfg
& PORT_HW_CFG_NET_SERDES_IF_MASK
) ==
4002 PORT_HW_CFG_NET_SERDES_IF_SGMII
)
4006 /* allocate at least number of buffers required by FW */
4007 rx_ring_size
= max_t(int, bp
->disable_tpa
? MIN_RX_SIZE_NONTPA
:
4008 MIN_RX_SIZE_TPA
, rx_ring_size
);
4010 bp
->rx_ring_size
= rx_ring_size
;
4011 } else /* if rx_ring_size specified - use it */
4012 rx_ring_size
= bp
->rx_ring_size
;
4015 sb
= &bnx2x_fp(bp
, index
, status_blk
);
4017 if (!IS_FCOE_IDX(index
)) {
4019 if (!CHIP_IS_E1x(bp
))
4020 BNX2X_PCI_ALLOC(sb
->e2_sb
,
4021 &bnx2x_fp(bp
, index
, status_blk_mapping
),
4022 sizeof(struct host_hc_status_block_e2
));
4024 BNX2X_PCI_ALLOC(sb
->e1x_sb
,
4025 &bnx2x_fp(bp
, index
, status_blk_mapping
),
4026 sizeof(struct host_hc_status_block_e1x
));
4029 /* FCoE Queue uses Default SB and doesn't ACK the SB, thus no need to
4030 * set shortcuts for it.
4032 if (!IS_FCOE_IDX(index
))
4033 set_sb_shortcuts(bp
, index
);
4036 if (!skip_tx_queue(bp
, index
)) {
4037 /* fastpath tx rings: tx_buf tx_desc */
4038 for_each_cos_in_tx_queue(fp
, cos
) {
4039 struct bnx2x_fp_txdata
*txdata
= fp
->txdata_ptr
[cos
];
4042 "allocating tx memory of fp %d cos %d\n",
4045 BNX2X_ALLOC(txdata
->tx_buf_ring
,
4046 sizeof(struct sw_tx_bd
) * NUM_TX_BD
);
4047 BNX2X_PCI_ALLOC(txdata
->tx_desc_ring
,
4048 &txdata
->tx_desc_mapping
,
4049 sizeof(union eth_tx_bd_types
) * NUM_TX_BD
);
4054 if (!skip_rx_queue(bp
, index
)) {
4055 /* fastpath rx rings: rx_buf rx_desc rx_comp */
4056 BNX2X_ALLOC(bnx2x_fp(bp
, index
, rx_buf_ring
),
4057 sizeof(struct sw_rx_bd
) * NUM_RX_BD
);
4058 BNX2X_PCI_ALLOC(bnx2x_fp(bp
, index
, rx_desc_ring
),
4059 &bnx2x_fp(bp
, index
, rx_desc_mapping
),
4060 sizeof(struct eth_rx_bd
) * NUM_RX_BD
);
4062 BNX2X_PCI_ALLOC(bnx2x_fp(bp
, index
, rx_comp_ring
),
4063 &bnx2x_fp(bp
, index
, rx_comp_mapping
),
4064 sizeof(struct eth_fast_path_rx_cqe
) *
4068 BNX2X_ALLOC(bnx2x_fp(bp
, index
, rx_page_ring
),
4069 sizeof(struct sw_rx_page
) * NUM_RX_SGE
);
4070 BNX2X_PCI_ALLOC(bnx2x_fp(bp
, index
, rx_sge_ring
),
4071 &bnx2x_fp(bp
, index
, rx_sge_mapping
),
4072 BCM_PAGE_SIZE
* NUM_RX_SGE_PAGES
);
4074 bnx2x_set_next_page_rx_bd(fp
);
4077 bnx2x_set_next_page_rx_cq(fp
);
4080 ring_size
= bnx2x_alloc_rx_bds(fp
, rx_ring_size
);
4081 if (ring_size
< rx_ring_size
)
4087 /* handles low memory cases */
4089 BNX2X_ERR("Unable to allocate full memory for queue %d (size %d)\n",
4091 /* FW will drop all packets if queue is not big enough,
4092 * In these cases we disable the queue
4093 * Min size is different for OOO, TPA and non-TPA queues
4095 if (ring_size
< (fp
->disable_tpa
?
4096 MIN_RX_SIZE_NONTPA
: MIN_RX_SIZE_TPA
)) {
4097 /* release memory allocated for this queue */
4098 bnx2x_free_fp_mem_at(bp
, index
);
4104 int bnx2x_alloc_fp_mem_cnic(struct bnx2x
*bp
)
4108 if (bnx2x_alloc_fp_mem_at(bp
, FCOE_IDX(bp
)))
4109 /* we will fail load process instead of mark
4117 int bnx2x_alloc_fp_mem(struct bnx2x
*bp
)
4121 /* 1. Allocate FP for leading - fatal if error
4122 * 2. Allocate RSS - fix number of queues if error
4126 if (bnx2x_alloc_fp_mem_at(bp
, 0))
4130 for_each_nondefault_eth_queue(bp
, i
)
4131 if (bnx2x_alloc_fp_mem_at(bp
, i
))
4134 /* handle memory failures */
4135 if (i
!= BNX2X_NUM_ETH_QUEUES(bp
)) {
4136 int delta
= BNX2X_NUM_ETH_QUEUES(bp
) - i
;
4139 if (CNIC_SUPPORT(bp
))
4140 /* move non eth FPs next to last eth FP
4141 * must be done in that order
4142 * FCOE_IDX < FWD_IDX < OOO_IDX
4145 /* move FCoE fp even NO_FCOE_FLAG is on */
4146 bnx2x_move_fp(bp
, FCOE_IDX(bp
), FCOE_IDX(bp
) - delta
);
4147 bp
->num_ethernet_queues
-= delta
;
4148 bp
->num_queues
= bp
->num_ethernet_queues
+
4149 bp
->num_cnic_queues
;
4150 BNX2X_ERR("Adjusted num of queues from %d to %d\n",
4151 bp
->num_queues
+ delta
, bp
->num_queues
);
4157 void bnx2x_free_mem_bp(struct bnx2x
*bp
)
4159 kfree(bp
->fp
->tpa_info
);
4162 kfree(bp
->fp_stats
);
4163 kfree(bp
->bnx2x_txq
);
4164 kfree(bp
->msix_table
);
4168 int bnx2x_alloc_mem_bp(struct bnx2x
*bp
)
4170 struct bnx2x_fastpath
*fp
;
4171 struct msix_entry
*tbl
;
4172 struct bnx2x_ilt
*ilt
;
4173 int msix_table_size
= 0;
4174 int fp_array_size
, txq_array_size
;
4178 * The biggest MSI-X table we might need is as a maximum number of fast
4179 * path IGU SBs plus default SB (for PF).
4181 msix_table_size
= bp
->igu_sb_cnt
;
4184 BNX2X_DEV_INFO("msix_table_size %d\n", msix_table_size
);
4186 /* fp array: RSS plus CNIC related L2 queues */
4187 fp_array_size
= BNX2X_MAX_RSS_COUNT(bp
) + CNIC_SUPPORT(bp
);
4188 BNX2X_DEV_INFO("fp_array_size %d", fp_array_size
);
4190 fp
= kcalloc(fp_array_size
, sizeof(*fp
), GFP_KERNEL
);
4193 for (i
= 0; i
< fp_array_size
; i
++) {
4195 kcalloc(ETH_MAX_AGGREGATION_QUEUES_E1H_E2
,
4196 sizeof(struct bnx2x_agg_info
), GFP_KERNEL
);
4197 if (!(fp
[i
].tpa_info
))
4203 /* allocate sp objs */
4204 bp
->sp_objs
= kcalloc(fp_array_size
, sizeof(struct bnx2x_sp_objs
),
4209 /* allocate fp_stats */
4210 bp
->fp_stats
= kcalloc(fp_array_size
, sizeof(struct bnx2x_fp_stats
),
4215 /* Allocate memory for the transmission queues array */
4217 BNX2X_MAX_RSS_COUNT(bp
) * BNX2X_MULTI_TX_COS
+ CNIC_SUPPORT(bp
);
4218 BNX2X_DEV_INFO("txq_array_size %d", txq_array_size
);
4220 bp
->bnx2x_txq
= kcalloc(txq_array_size
, sizeof(struct bnx2x_fp_txdata
),
4226 tbl
= kcalloc(msix_table_size
, sizeof(*tbl
), GFP_KERNEL
);
4229 bp
->msix_table
= tbl
;
4232 ilt
= kzalloc(sizeof(*ilt
), GFP_KERNEL
);
4239 bnx2x_free_mem_bp(bp
);
4244 int bnx2x_reload_if_running(struct net_device
*dev
)
4246 struct bnx2x
*bp
= netdev_priv(dev
);
4248 if (unlikely(!netif_running(dev
)))
4251 bnx2x_nic_unload(bp
, UNLOAD_NORMAL
, true);
4252 return bnx2x_nic_load(bp
, LOAD_NORMAL
);
4255 int bnx2x_get_cur_phy_idx(struct bnx2x
*bp
)
4257 u32 sel_phy_idx
= 0;
4258 if (bp
->link_params
.num_phys
<= 1)
4261 if (bp
->link_vars
.link_up
) {
4262 sel_phy_idx
= EXT_PHY1
;
4263 /* In case link is SERDES, check if the EXT_PHY2 is the one */
4264 if ((bp
->link_vars
.link_status
& LINK_STATUS_SERDES_LINK
) &&
4265 (bp
->link_params
.phy
[EXT_PHY2
].supported
& SUPPORTED_FIBRE
))
4266 sel_phy_idx
= EXT_PHY2
;
4269 switch (bnx2x_phy_selection(&bp
->link_params
)) {
4270 case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT
:
4271 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY
:
4272 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY
:
4273 sel_phy_idx
= EXT_PHY1
;
4275 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY
:
4276 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY
:
4277 sel_phy_idx
= EXT_PHY2
;
4285 int bnx2x_get_link_cfg_idx(struct bnx2x
*bp
)
4287 u32 sel_phy_idx
= bnx2x_get_cur_phy_idx(bp
);
4289 * The selected actived PHY is always after swapping (in case PHY
4290 * swapping is enabled). So when swapping is enabled, we need to reverse
4294 if (bp
->link_params
.multi_phy_config
&
4295 PORT_HW_CFG_PHY_SWAPPED_ENABLED
) {
4296 if (sel_phy_idx
== EXT_PHY1
)
4297 sel_phy_idx
= EXT_PHY2
;
4298 else if (sel_phy_idx
== EXT_PHY2
)
4299 sel_phy_idx
= EXT_PHY1
;
4301 return LINK_CONFIG_IDX(sel_phy_idx
);
4304 #ifdef NETDEV_FCOE_WWNN
4305 int bnx2x_fcoe_get_wwn(struct net_device
*dev
, u64
*wwn
, int type
)
4307 struct bnx2x
*bp
= netdev_priv(dev
);
4308 struct cnic_eth_dev
*cp
= &bp
->cnic_eth_dev
;
4311 case NETDEV_FCOE_WWNN
:
4312 *wwn
= HILO_U64(cp
->fcoe_wwn_node_name_hi
,
4313 cp
->fcoe_wwn_node_name_lo
);
4315 case NETDEV_FCOE_WWPN
:
4316 *wwn
= HILO_U64(cp
->fcoe_wwn_port_name_hi
,
4317 cp
->fcoe_wwn_port_name_lo
);
4320 BNX2X_ERR("Wrong WWN type requested - %d\n", type
);
4328 /* called with rtnl_lock */
4329 int bnx2x_change_mtu(struct net_device
*dev
, int new_mtu
)
4331 struct bnx2x
*bp
= netdev_priv(dev
);
4333 if (bp
->recovery_state
!= BNX2X_RECOVERY_DONE
) {
4334 BNX2X_ERR("Can't perform change MTU during parity recovery\n");
4338 if ((new_mtu
> ETH_MAX_JUMBO_PACKET_SIZE
) ||
4339 ((new_mtu
+ ETH_HLEN
) < ETH_MIN_PACKET_SIZE
)) {
4340 BNX2X_ERR("Can't support requested MTU size\n");
4344 /* This does not race with packet allocation
4345 * because the actual alloc size is
4346 * only updated as part of load
4350 return bnx2x_reload_if_running(dev
);
4353 netdev_features_t
bnx2x_fix_features(struct net_device
*dev
,
4354 netdev_features_t features
)
4356 struct bnx2x
*bp
= netdev_priv(dev
);
4358 /* TPA requires Rx CSUM offloading */
4359 if (!(features
& NETIF_F_RXCSUM
) || bp
->disable_tpa
) {
4360 features
&= ~NETIF_F_LRO
;
4361 features
&= ~NETIF_F_GRO
;
4367 int bnx2x_set_features(struct net_device
*dev
, netdev_features_t features
)
4369 struct bnx2x
*bp
= netdev_priv(dev
);
4370 u32 flags
= bp
->flags
;
4371 bool bnx2x_reload
= false;
4373 if (features
& NETIF_F_LRO
)
4374 flags
|= TPA_ENABLE_FLAG
;
4376 flags
&= ~TPA_ENABLE_FLAG
;
4378 if (features
& NETIF_F_GRO
)
4379 flags
|= GRO_ENABLE_FLAG
;
4381 flags
&= ~GRO_ENABLE_FLAG
;
4383 if (features
& NETIF_F_LOOPBACK
) {
4384 if (bp
->link_params
.loopback_mode
!= LOOPBACK_BMAC
) {
4385 bp
->link_params
.loopback_mode
= LOOPBACK_BMAC
;
4386 bnx2x_reload
= true;
4389 if (bp
->link_params
.loopback_mode
!= LOOPBACK_NONE
) {
4390 bp
->link_params
.loopback_mode
= LOOPBACK_NONE
;
4391 bnx2x_reload
= true;
4395 if (flags
^ bp
->flags
) {
4397 bnx2x_reload
= true;
4401 if (bp
->recovery_state
== BNX2X_RECOVERY_DONE
)
4402 return bnx2x_reload_if_running(dev
);
4403 /* else: bnx2x_nic_load() will be called at end of recovery */
4409 void bnx2x_tx_timeout(struct net_device
*dev
)
4411 struct bnx2x
*bp
= netdev_priv(dev
);
4413 #ifdef BNX2X_STOP_ON_ERROR
4418 smp_mb__before_clear_bit();
4419 set_bit(BNX2X_SP_RTNL_TX_TIMEOUT
, &bp
->sp_rtnl_state
);
4420 smp_mb__after_clear_bit();
4422 /* This allows the netif to be shutdown gracefully before resetting */
4423 schedule_delayed_work(&bp
->sp_rtnl_task
, 0);
4426 int bnx2x_suspend(struct pci_dev
*pdev
, pm_message_t state
)
4428 struct net_device
*dev
= pci_get_drvdata(pdev
);
4432 dev_err(&pdev
->dev
, "BAD net device from bnx2x_init_one\n");
4435 bp
= netdev_priv(dev
);
4439 pci_save_state(pdev
);
4441 if (!netif_running(dev
)) {
4446 netif_device_detach(dev
);
4448 bnx2x_nic_unload(bp
, UNLOAD_CLOSE
, false);
4450 bnx2x_set_power_state(bp
, pci_choose_state(pdev
, state
));
4457 int bnx2x_resume(struct pci_dev
*pdev
)
4459 struct net_device
*dev
= pci_get_drvdata(pdev
);
4464 dev_err(&pdev
->dev
, "BAD net device from bnx2x_init_one\n");
4467 bp
= netdev_priv(dev
);
4469 if (bp
->recovery_state
!= BNX2X_RECOVERY_DONE
) {
4470 BNX2X_ERR("Handling parity error recovery. Try again later\n");
4476 pci_restore_state(pdev
);
4478 if (!netif_running(dev
)) {
4483 bnx2x_set_power_state(bp
, PCI_D0
);
4484 netif_device_attach(dev
);
4486 rc
= bnx2x_nic_load(bp
, LOAD_OPEN
);
4494 void bnx2x_set_ctx_validation(struct bnx2x
*bp
, struct eth_context
*cxt
,
4497 /* ustorm cxt validation */
4498 cxt
->ustorm_ag_context
.cdu_usage
=
4499 CDU_RSRVD_VALUE_TYPE_A(HW_CID(bp
, cid
),
4500 CDU_REGION_NUMBER_UCM_AG
, ETH_CONNECTION_TYPE
);
4501 /* xcontext validation */
4502 cxt
->xstorm_ag_context
.cdu_reserved
=
4503 CDU_RSRVD_VALUE_TYPE_A(HW_CID(bp
, cid
),
4504 CDU_REGION_NUMBER_XCM_AG
, ETH_CONNECTION_TYPE
);
4507 static void storm_memset_hc_timeout(struct bnx2x
*bp
, u8 port
,
4508 u8 fw_sb_id
, u8 sb_index
,
4512 u32 addr
= BAR_CSTRORM_INTMEM
+
4513 CSTORM_STATUS_BLOCK_DATA_TIMEOUT_OFFSET(fw_sb_id
, sb_index
);
4514 REG_WR8(bp
, addr
, ticks
);
4516 "port %x fw_sb_id %d sb_index %d ticks %d\n",
4517 port
, fw_sb_id
, sb_index
, ticks
);
4520 static void storm_memset_hc_disable(struct bnx2x
*bp
, u8 port
,
4521 u16 fw_sb_id
, u8 sb_index
,
4524 u32 enable_flag
= disable
? 0 : (1 << HC_INDEX_DATA_HC_ENABLED_SHIFT
);
4525 u32 addr
= BAR_CSTRORM_INTMEM
+
4526 CSTORM_STATUS_BLOCK_DATA_FLAGS_OFFSET(fw_sb_id
, sb_index
);
4527 u16 flags
= REG_RD16(bp
, addr
);
4529 flags
&= ~HC_INDEX_DATA_HC_ENABLED
;
4530 flags
|= enable_flag
;
4531 REG_WR16(bp
, addr
, flags
);
4533 "port %x fw_sb_id %d sb_index %d disable %d\n",
4534 port
, fw_sb_id
, sb_index
, disable
);
4537 void bnx2x_update_coalesce_sb_index(struct bnx2x
*bp
, u8 fw_sb_id
,
4538 u8 sb_index
, u8 disable
, u16 usec
)
4540 int port
= BP_PORT(bp
);
4541 u8 ticks
= usec
/ BNX2X_BTR
;
4543 storm_memset_hc_timeout(bp
, port
, fw_sb_id
, sb_index
, ticks
);
4545 disable
= disable
? 1 : (usec
? 0 : 1);
4546 storm_memset_hc_disable(bp
, port
, fw_sb_id
, sb_index
, disable
);