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"
34 * bnx2x_move_fp - move content of the fastpath structure.
37 * @from: source FP index
38 * @to: destination FP index
40 * Makes sure the contents of the bp->fp[to].napi is kept
41 * intact. This is done by first copying the napi struct from
42 * the target to the source, and then mem copying the entire
43 * source onto the target
45 static inline void bnx2x_move_fp(struct bnx2x *bp, int from, int to)
47 struct bnx2x_fastpath *from_fp = &bp->fp[from];
48 struct bnx2x_fastpath *to_fp = &bp->fp[to];
50 /* Copy the NAPI object as it has been already initialized */
51 from_fp->napi = to_fp->napi;
53 /* Move bnx2x_fastpath contents */
54 memcpy(to_fp, from_fp, sizeof(*to_fp));
58 int load_count[2][3] = { {0} }; /* per-path: 0-common, 1-port0, 2-port1 */
60 /* free skb in the packet ring at pos idx
61 * return idx of last bd freed
63 static u16 bnx2x_free_tx_pkt(struct bnx2x *bp, struct bnx2x_fp_txdata *txdata,
64 u16 idx, unsigned int *pkts_compl,
65 unsigned int *bytes_compl)
67 struct sw_tx_bd *tx_buf = &txdata->tx_buf_ring[idx];
68 struct eth_tx_start_bd *tx_start_bd;
69 struct eth_tx_bd *tx_data_bd;
70 struct sk_buff *skb = tx_buf->skb;
71 u16 bd_idx = TX_BD(tx_buf->first_bd), new_cons;
74 /* prefetch skb end pointer to speedup dev_kfree_skb() */
77 DP(NETIF_MSG_TX_DONE, "fp[%d]: pkt_idx %d buff @(%p)->skb %p\n",
78 txdata->txq_index, idx, tx_buf, skb);
81 tx_start_bd = &txdata->tx_desc_ring[bd_idx].start_bd;
82 dma_unmap_single(&bp->pdev->dev, BD_UNMAP_ADDR(tx_start_bd),
83 BD_UNMAP_LEN(tx_start_bd), DMA_TO_DEVICE);
86 nbd = le16_to_cpu(tx_start_bd->nbd) - 1;
87 #ifdef BNX2X_STOP_ON_ERROR
88 if ((nbd - 1) > (MAX_SKB_FRAGS + 2)) {
89 BNX2X_ERR("BAD nbd!\n");
93 new_cons = nbd + tx_buf->first_bd;
96 bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
98 /* Skip a parse bd... */
100 bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
102 /* ...and the TSO split header bd since they have no mapping */
103 if (tx_buf->flags & BNX2X_TSO_SPLIT_BD) {
105 bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
111 tx_data_bd = &txdata->tx_desc_ring[bd_idx].reg_bd;
112 dma_unmap_page(&bp->pdev->dev, BD_UNMAP_ADDR(tx_data_bd),
113 BD_UNMAP_LEN(tx_data_bd), DMA_TO_DEVICE);
115 bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
122 (*bytes_compl) += skb->len;
125 dev_kfree_skb_any(skb);
126 tx_buf->first_bd = 0;
132 int bnx2x_tx_int(struct bnx2x *bp, struct bnx2x_fp_txdata *txdata)
134 struct netdev_queue *txq;
135 u16 hw_cons, sw_cons, bd_cons = txdata->tx_bd_cons;
136 unsigned int pkts_compl = 0, bytes_compl = 0;
138 #ifdef BNX2X_STOP_ON_ERROR
139 if (unlikely(bp->panic))
143 txq = netdev_get_tx_queue(bp->dev, txdata->txq_index);
144 hw_cons = le16_to_cpu(*txdata->tx_cons_sb);
145 sw_cons = txdata->tx_pkt_cons;
147 while (sw_cons != hw_cons) {
150 pkt_cons = TX_BD(sw_cons);
152 DP(NETIF_MSG_TX_DONE,
153 "queue[%d]: hw_cons %u sw_cons %u pkt_cons %u\n",
154 txdata->txq_index, hw_cons, sw_cons, pkt_cons);
156 bd_cons = bnx2x_free_tx_pkt(bp, txdata, pkt_cons,
157 &pkts_compl, &bytes_compl);
162 netdev_tx_completed_queue(txq, pkts_compl, bytes_compl);
164 txdata->tx_pkt_cons = sw_cons;
165 txdata->tx_bd_cons = bd_cons;
167 /* Need to make the tx_bd_cons update visible to start_xmit()
168 * before checking for netif_tx_queue_stopped(). Without the
169 * memory barrier, there is a small possibility that
170 * start_xmit() will miss it and cause the queue to be stopped
172 * On the other hand we need an rmb() here to ensure the proper
173 * ordering of bit testing in the following
174 * netif_tx_queue_stopped(txq) call.
178 if (unlikely(netif_tx_queue_stopped(txq))) {
179 /* Taking tx_lock() is needed to prevent reenabling the queue
180 * while it's empty. This could have happen if rx_action() gets
181 * suspended in bnx2x_tx_int() after the condition before
182 * netif_tx_wake_queue(), while tx_action (bnx2x_start_xmit()):
184 * stops the queue->sees fresh tx_bd_cons->releases the queue->
185 * sends some packets consuming the whole queue again->
189 __netif_tx_lock(txq, smp_processor_id());
191 if ((netif_tx_queue_stopped(txq)) &&
192 (bp->state == BNX2X_STATE_OPEN) &&
193 (bnx2x_tx_avail(bp, txdata) >= MAX_SKB_FRAGS + 3))
194 netif_tx_wake_queue(txq);
196 __netif_tx_unlock(txq);
201 static inline void bnx2x_update_last_max_sge(struct bnx2x_fastpath *fp,
204 u16 last_max = fp->last_max_sge;
206 if (SUB_S16(idx, last_max) > 0)
207 fp->last_max_sge = idx;
210 static inline void bnx2x_update_sge_prod(struct bnx2x_fastpath *fp,
212 struct eth_end_agg_rx_cqe *cqe)
214 struct bnx2x *bp = fp->bp;
215 u16 last_max, last_elem, first_elem;
222 /* First mark all used pages */
223 for (i = 0; i < sge_len; i++)
224 BIT_VEC64_CLEAR_BIT(fp->sge_mask,
225 RX_SGE(le16_to_cpu(cqe->sgl_or_raw_data.sgl[i])));
227 DP(NETIF_MSG_RX_STATUS, "fp_cqe->sgl[%d] = %d\n",
228 sge_len - 1, le16_to_cpu(cqe->sgl_or_raw_data.sgl[sge_len - 1]));
230 /* Here we assume that the last SGE index is the biggest */
231 prefetch((void *)(fp->sge_mask));
232 bnx2x_update_last_max_sge(fp,
233 le16_to_cpu(cqe->sgl_or_raw_data.sgl[sge_len - 1]));
235 last_max = RX_SGE(fp->last_max_sge);
236 last_elem = last_max >> BIT_VEC64_ELEM_SHIFT;
237 first_elem = RX_SGE(fp->rx_sge_prod) >> BIT_VEC64_ELEM_SHIFT;
239 /* If ring is not full */
240 if (last_elem + 1 != first_elem)
243 /* Now update the prod */
244 for (i = first_elem; i != last_elem; i = NEXT_SGE_MASK_ELEM(i)) {
245 if (likely(fp->sge_mask[i]))
248 fp->sge_mask[i] = BIT_VEC64_ELEM_ONE_MASK;
249 delta += BIT_VEC64_ELEM_SZ;
253 fp->rx_sge_prod += delta;
254 /* clear page-end entries */
255 bnx2x_clear_sge_mask_next_elems(fp);
258 DP(NETIF_MSG_RX_STATUS,
259 "fp->last_max_sge = %d fp->rx_sge_prod = %d\n",
260 fp->last_max_sge, fp->rx_sge_prod);
263 /* Set Toeplitz hash value in the skb using the value from the
264 * CQE (calculated by HW).
266 static u32 bnx2x_get_rxhash(const struct bnx2x *bp,
267 const struct eth_fast_path_rx_cqe *cqe)
269 /* Set Toeplitz hash from CQE */
270 if ((bp->dev->features & NETIF_F_RXHASH) &&
271 (cqe->status_flags & ETH_FAST_PATH_RX_CQE_RSS_HASH_FLG))
272 return le32_to_cpu(cqe->rss_hash_result);
276 static void bnx2x_tpa_start(struct bnx2x_fastpath *fp, u16 queue,
278 struct eth_fast_path_rx_cqe *cqe)
280 struct bnx2x *bp = fp->bp;
281 struct sw_rx_bd *cons_rx_buf = &fp->rx_buf_ring[cons];
282 struct sw_rx_bd *prod_rx_buf = &fp->rx_buf_ring[prod];
283 struct eth_rx_bd *prod_bd = &fp->rx_desc_ring[prod];
285 struct bnx2x_agg_info *tpa_info = &fp->tpa_info[queue];
286 struct sw_rx_bd *first_buf = &tpa_info->first_buf;
288 /* print error if current state != stop */
289 if (tpa_info->tpa_state != BNX2X_TPA_STOP)
290 BNX2X_ERR("start of bin not in stop [%d]\n", queue);
292 /* Try to map an empty data buffer from the aggregation info */
293 mapping = dma_map_single(&bp->pdev->dev,
294 first_buf->data + NET_SKB_PAD,
295 fp->rx_buf_size, DMA_FROM_DEVICE);
297 * ...if it fails - move the skb from the consumer to the producer
298 * and set the current aggregation state as ERROR to drop it
299 * when TPA_STOP arrives.
302 if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
303 /* Move the BD from the consumer to the producer */
304 bnx2x_reuse_rx_data(fp, cons, prod);
305 tpa_info->tpa_state = BNX2X_TPA_ERROR;
309 /* move empty data from pool to prod */
310 prod_rx_buf->data = first_buf->data;
311 dma_unmap_addr_set(prod_rx_buf, mapping, mapping);
312 /* point prod_bd to new data */
313 prod_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
314 prod_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
316 /* move partial skb from cons to pool (don't unmap yet) */
317 *first_buf = *cons_rx_buf;
319 /* mark bin state as START */
320 tpa_info->parsing_flags =
321 le16_to_cpu(cqe->pars_flags.flags);
322 tpa_info->vlan_tag = le16_to_cpu(cqe->vlan_tag);
323 tpa_info->tpa_state = BNX2X_TPA_START;
324 tpa_info->len_on_bd = le16_to_cpu(cqe->len_on_bd);
325 tpa_info->placement_offset = cqe->placement_offset;
326 tpa_info->rxhash = bnx2x_get_rxhash(bp, cqe);
327 if (fp->mode == TPA_MODE_GRO) {
328 u16 gro_size = le16_to_cpu(cqe->pkt_len_or_gro_seg_len);
329 tpa_info->full_page =
330 SGE_PAGE_SIZE * PAGES_PER_SGE / gro_size * gro_size;
332 * FW 7.2.16 BUG workaround:
333 * if SGE size is (exactly) multiple gro_size
334 * fw will place one less frag on SGE.
335 * the calculation is done only for potentially
338 if (unlikely(bp->gro_check))
339 if (!(SGE_PAGE_SIZE * PAGES_PER_SGE % gro_size))
340 tpa_info->full_page -= gro_size;
341 tpa_info->gro_size = gro_size;
344 #ifdef BNX2X_STOP_ON_ERROR
345 fp->tpa_queue_used |= (1 << queue);
346 #ifdef _ASM_GENERIC_INT_L64_H
347 DP(NETIF_MSG_RX_STATUS, "fp->tpa_queue_used = 0x%lx\n",
349 DP(NETIF_MSG_RX_STATUS, "fp->tpa_queue_used = 0x%llx\n",
355 /* Timestamp option length allowed for TPA aggregation:
357 * nop nop kind length echo val
359 #define TPA_TSTAMP_OPT_LEN 12
361 * bnx2x_set_lro_mss - calculate the approximate value of the MSS
364 * @parsing_flags: parsing flags from the START CQE
365 * @len_on_bd: total length of the first packet for the
368 * Approximate value of the MSS for this aggregation calculated using
369 * the first packet of it.
371 static inline u16 bnx2x_set_lro_mss(struct bnx2x *bp, u16 parsing_flags,
375 * TPA arrgregation won't have either IP options or TCP options
376 * other than timestamp or IPv6 extension headers.
378 u16 hdrs_len = ETH_HLEN + sizeof(struct tcphdr);
380 if (GET_FLAG(parsing_flags, PARSING_FLAGS_OVER_ETHERNET_PROTOCOL) ==
381 PRS_FLAG_OVERETH_IPV6)
382 hdrs_len += sizeof(struct ipv6hdr);
384 hdrs_len += sizeof(struct iphdr);
387 /* Check if there was a TCP timestamp, if there is it's will
388 * always be 12 bytes length: nop nop kind length echo val.
390 * Otherwise FW would close the aggregation.
392 if (parsing_flags & PARSING_FLAGS_TIME_STAMP_EXIST_FLAG)
393 hdrs_len += TPA_TSTAMP_OPT_LEN;
395 return len_on_bd - hdrs_len;
398 static int bnx2x_fill_frag_skb(struct bnx2x *bp, struct bnx2x_fastpath *fp,
399 struct bnx2x_agg_info *tpa_info,
402 struct eth_end_agg_rx_cqe *cqe,
405 struct sw_rx_page *rx_pg, old_rx_pg;
406 u32 i, frag_len, frag_size;
407 int err, j, frag_id = 0;
408 u16 len_on_bd = tpa_info->len_on_bd;
409 u16 full_page = 0, gro_size = 0;
411 frag_size = le16_to_cpu(cqe->pkt_len) - len_on_bd;
413 if (fp->mode == TPA_MODE_GRO) {
414 gro_size = tpa_info->gro_size;
415 full_page = tpa_info->full_page;
418 /* This is needed in order to enable forwarding support */
420 skb_shinfo(skb)->gso_size = bnx2x_set_lro_mss(bp,
421 tpa_info->parsing_flags, len_on_bd);
424 if (fp->mode == TPA_MODE_GRO)
425 skb_shinfo(skb)->gso_type =
426 (GET_FLAG(tpa_info->parsing_flags,
427 PARSING_FLAGS_OVER_ETHERNET_PROTOCOL) ==
428 PRS_FLAG_OVERETH_IPV6) ?
429 SKB_GSO_TCPV6 : SKB_GSO_TCPV4;
433 #ifdef BNX2X_STOP_ON_ERROR
434 if (pages > min_t(u32, 8, MAX_SKB_FRAGS)*SGE_PAGE_SIZE*PAGES_PER_SGE) {
435 BNX2X_ERR("SGL length is too long: %d. CQE index is %d\n",
437 BNX2X_ERR("cqe->pkt_len = %d\n", cqe->pkt_len);
443 /* Run through the SGL and compose the fragmented skb */
444 for (i = 0, j = 0; i < pages; i += PAGES_PER_SGE, j++) {
445 u16 sge_idx = RX_SGE(le16_to_cpu(cqe->sgl_or_raw_data.sgl[j]));
447 /* FW gives the indices of the SGE as if the ring is an array
448 (meaning that "next" element will consume 2 indices) */
449 if (fp->mode == TPA_MODE_GRO)
450 frag_len = min_t(u32, frag_size, (u32)full_page);
452 frag_len = min_t(u32, frag_size,
453 (u32)(SGE_PAGE_SIZE * PAGES_PER_SGE));
455 rx_pg = &fp->rx_page_ring[sge_idx];
458 /* If we fail to allocate a substitute page, we simply stop
459 where we are and drop the whole packet */
460 err = bnx2x_alloc_rx_sge(bp, fp, sge_idx);
462 fp->eth_q_stats.rx_skb_alloc_failed++;
466 /* Unmap the page as we r going to pass it to the stack */
467 dma_unmap_page(&bp->pdev->dev,
468 dma_unmap_addr(&old_rx_pg, mapping),
469 SGE_PAGE_SIZE*PAGES_PER_SGE, DMA_FROM_DEVICE);
470 /* Add one frag and update the appropriate fields in the skb */
471 if (fp->mode == TPA_MODE_LRO)
472 skb_fill_page_desc(skb, j, old_rx_pg.page, 0, frag_len);
476 for (rem = frag_len; rem > 0; rem -= gro_size) {
477 int len = rem > gro_size ? gro_size : rem;
478 skb_fill_page_desc(skb, frag_id++,
479 old_rx_pg.page, offset, len);
481 get_page(old_rx_pg.page);
486 skb->data_len += frag_len;
487 skb->truesize += SGE_PAGE_SIZE * PAGES_PER_SGE;
488 skb->len += frag_len;
490 frag_size -= frag_len;
496 static inline void bnx2x_tpa_stop(struct bnx2x *bp, struct bnx2x_fastpath *fp,
497 struct bnx2x_agg_info *tpa_info,
499 struct eth_end_agg_rx_cqe *cqe,
502 struct sw_rx_bd *rx_buf = &tpa_info->first_buf;
503 u8 pad = tpa_info->placement_offset;
504 u16 len = tpa_info->len_on_bd;
505 struct sk_buff *skb = NULL;
506 u8 *new_data, *data = rx_buf->data;
507 u8 old_tpa_state = tpa_info->tpa_state;
509 tpa_info->tpa_state = BNX2X_TPA_STOP;
511 /* If we there was an error during the handling of the TPA_START -
512 * drop this aggregation.
514 if (old_tpa_state == BNX2X_TPA_ERROR)
517 /* Try to allocate the new data */
518 new_data = kmalloc(fp->rx_buf_size + NET_SKB_PAD, GFP_ATOMIC);
520 /* Unmap skb in the pool anyway, as we are going to change
521 pool entry status to BNX2X_TPA_STOP even if new skb allocation
523 dma_unmap_single(&bp->pdev->dev, dma_unmap_addr(rx_buf, mapping),
524 fp->rx_buf_size, DMA_FROM_DEVICE);
525 if (likely(new_data))
526 skb = build_skb(data);
529 #ifdef BNX2X_STOP_ON_ERROR
530 if (pad + len > fp->rx_buf_size) {
531 BNX2X_ERR("skb_put is about to fail... pad %d len %d rx_buf_size %d\n",
532 pad, len, fp->rx_buf_size);
538 skb_reserve(skb, pad + NET_SKB_PAD);
540 skb->rxhash = tpa_info->rxhash;
542 skb->protocol = eth_type_trans(skb, bp->dev);
543 skb->ip_summed = CHECKSUM_UNNECESSARY;
545 if (!bnx2x_fill_frag_skb(bp, fp, tpa_info, pages,
546 skb, cqe, cqe_idx)) {
547 if (tpa_info->parsing_flags & PARSING_FLAGS_VLAN)
548 __vlan_hwaccel_put_tag(skb, tpa_info->vlan_tag);
549 napi_gro_receive(&fp->napi, skb);
551 DP(NETIF_MSG_RX_STATUS,
552 "Failed to allocate new pages - dropping packet!\n");
553 dev_kfree_skb_any(skb);
557 /* put new data in bin */
558 rx_buf->data = new_data;
564 /* drop the packet and keep the buffer in the bin */
565 DP(NETIF_MSG_RX_STATUS,
566 "Failed to allocate or map a new skb - dropping packet!\n");
567 fp->eth_q_stats.rx_skb_alloc_failed++;
571 int bnx2x_rx_int(struct bnx2x_fastpath *fp, int budget)
573 struct bnx2x *bp = fp->bp;
574 u16 bd_cons, bd_prod, bd_prod_fw, comp_ring_cons;
575 u16 hw_comp_cons, sw_comp_cons, sw_comp_prod;
578 #ifdef BNX2X_STOP_ON_ERROR
579 if (unlikely(bp->panic))
583 /* CQ "next element" is of the size of the regular element,
584 that's why it's ok here */
585 hw_comp_cons = le16_to_cpu(*fp->rx_cons_sb);
586 if ((hw_comp_cons & MAX_RCQ_DESC_CNT) == MAX_RCQ_DESC_CNT)
589 bd_cons = fp->rx_bd_cons;
590 bd_prod = fp->rx_bd_prod;
591 bd_prod_fw = bd_prod;
592 sw_comp_cons = fp->rx_comp_cons;
593 sw_comp_prod = fp->rx_comp_prod;
595 /* Memory barrier necessary as speculative reads of the rx
596 * buffer can be ahead of the index in the status block
600 DP(NETIF_MSG_RX_STATUS,
601 "queue[%d]: hw_comp_cons %u sw_comp_cons %u\n",
602 fp->index, hw_comp_cons, sw_comp_cons);
604 while (sw_comp_cons != hw_comp_cons) {
605 struct sw_rx_bd *rx_buf = NULL;
607 union eth_rx_cqe *cqe;
608 struct eth_fast_path_rx_cqe *cqe_fp;
610 enum eth_rx_cqe_type cqe_fp_type;
614 #ifdef BNX2X_STOP_ON_ERROR
615 if (unlikely(bp->panic))
619 comp_ring_cons = RCQ_BD(sw_comp_cons);
620 bd_prod = RX_BD(bd_prod);
621 bd_cons = RX_BD(bd_cons);
623 cqe = &fp->rx_comp_ring[comp_ring_cons];
624 cqe_fp = &cqe->fast_path_cqe;
625 cqe_fp_flags = cqe_fp->type_error_flags;
626 cqe_fp_type = cqe_fp_flags & ETH_FAST_PATH_RX_CQE_TYPE;
628 DP(NETIF_MSG_RX_STATUS,
629 "CQE type %x err %x status %x queue %x vlan %x len %u\n",
630 CQE_TYPE(cqe_fp_flags),
631 cqe_fp_flags, cqe_fp->status_flags,
632 le32_to_cpu(cqe_fp->rss_hash_result),
633 le16_to_cpu(cqe_fp->vlan_tag),
634 le16_to_cpu(cqe_fp->pkt_len_or_gro_seg_len));
636 /* is this a slowpath msg? */
637 if (unlikely(CQE_TYPE_SLOW(cqe_fp_type))) {
638 bnx2x_sp_event(fp, cqe);
642 rx_buf = &fp->rx_buf_ring[bd_cons];
645 if (!CQE_TYPE_FAST(cqe_fp_type)) {
646 struct bnx2x_agg_info *tpa_info;
647 u16 frag_size, pages;
648 #ifdef BNX2X_STOP_ON_ERROR
650 if (fp->disable_tpa &&
651 (CQE_TYPE_START(cqe_fp_type) ||
652 CQE_TYPE_STOP(cqe_fp_type)))
653 BNX2X_ERR("START/STOP packet while disable_tpa type %x\n",
654 CQE_TYPE(cqe_fp_type));
657 if (CQE_TYPE_START(cqe_fp_type)) {
658 u16 queue = cqe_fp->queue_index;
659 DP(NETIF_MSG_RX_STATUS,
660 "calling tpa_start on queue %d\n",
663 bnx2x_tpa_start(fp, queue,
670 queue = cqe->end_agg_cqe.queue_index;
671 tpa_info = &fp->tpa_info[queue];
672 DP(NETIF_MSG_RX_STATUS,
673 "calling tpa_stop on queue %d\n",
676 frag_size = le16_to_cpu(cqe->end_agg_cqe.pkt_len) -
679 if (fp->mode == TPA_MODE_GRO)
680 pages = (frag_size + tpa_info->full_page - 1) /
683 pages = SGE_PAGE_ALIGN(frag_size) >>
686 bnx2x_tpa_stop(bp, fp, tpa_info, pages,
687 &cqe->end_agg_cqe, comp_ring_cons);
688 #ifdef BNX2X_STOP_ON_ERROR
693 bnx2x_update_sge_prod(fp, pages, &cqe->end_agg_cqe);
697 len = le16_to_cpu(cqe_fp->pkt_len_or_gro_seg_len);
698 pad = cqe_fp->placement_offset;
699 dma_sync_single_for_cpu(&bp->pdev->dev,
700 dma_unmap_addr(rx_buf, mapping),
701 pad + RX_COPY_THRESH,
704 prefetch(data + pad); /* speedup eth_type_trans() */
705 /* is this an error packet? */
706 if (unlikely(cqe_fp_flags & ETH_RX_ERROR_FALGS)) {
707 DP(NETIF_MSG_RX_ERR | NETIF_MSG_RX_STATUS,
708 "ERROR flags %x rx packet %u\n",
709 cqe_fp_flags, sw_comp_cons);
710 fp->eth_q_stats.rx_err_discard_pkt++;
714 /* Since we don't have a jumbo ring
715 * copy small packets if mtu > 1500
717 if ((bp->dev->mtu > ETH_MAX_PACKET_SIZE) &&
718 (len <= RX_COPY_THRESH)) {
719 skb = netdev_alloc_skb_ip_align(bp->dev, len);
721 DP(NETIF_MSG_RX_ERR | NETIF_MSG_RX_STATUS,
722 "ERROR packet dropped because of alloc failure\n");
723 fp->eth_q_stats.rx_skb_alloc_failed++;
726 memcpy(skb->data, data + pad, len);
727 bnx2x_reuse_rx_data(fp, bd_cons, bd_prod);
729 if (likely(bnx2x_alloc_rx_data(bp, fp, bd_prod) == 0)) {
730 dma_unmap_single(&bp->pdev->dev,
731 dma_unmap_addr(rx_buf, mapping),
734 skb = build_skb(data);
735 if (unlikely(!skb)) {
737 fp->eth_q_stats.rx_skb_alloc_failed++;
740 skb_reserve(skb, pad);
742 DP(NETIF_MSG_RX_ERR | NETIF_MSG_RX_STATUS,
743 "ERROR packet dropped because of alloc failure\n");
744 fp->eth_q_stats.rx_skb_alloc_failed++;
746 bnx2x_reuse_rx_data(fp, bd_cons, bd_prod);
752 skb->protocol = eth_type_trans(skb, bp->dev);
754 /* Set Toeplitz hash for a none-LRO skb */
755 skb->rxhash = bnx2x_get_rxhash(bp, cqe_fp);
757 skb_checksum_none_assert(skb);
759 if (bp->dev->features & NETIF_F_RXCSUM) {
761 if (likely(BNX2X_RX_CSUM_OK(cqe)))
762 skb->ip_summed = CHECKSUM_UNNECESSARY;
764 fp->eth_q_stats.hw_csum_err++;
767 skb_record_rx_queue(skb, fp->rx_queue);
769 if (le16_to_cpu(cqe_fp->pars_flags.flags) &
771 __vlan_hwaccel_put_tag(skb,
772 le16_to_cpu(cqe_fp->vlan_tag));
773 napi_gro_receive(&fp->napi, skb);
779 bd_cons = NEXT_RX_IDX(bd_cons);
780 bd_prod = NEXT_RX_IDX(bd_prod);
781 bd_prod_fw = NEXT_RX_IDX(bd_prod_fw);
784 sw_comp_prod = NEXT_RCQ_IDX(sw_comp_prod);
785 sw_comp_cons = NEXT_RCQ_IDX(sw_comp_cons);
787 if (rx_pkt == budget)
791 fp->rx_bd_cons = bd_cons;
792 fp->rx_bd_prod = bd_prod_fw;
793 fp->rx_comp_cons = sw_comp_cons;
794 fp->rx_comp_prod = sw_comp_prod;
796 /* Update producers */
797 bnx2x_update_rx_prod(bp, fp, bd_prod_fw, sw_comp_prod,
800 fp->rx_pkt += rx_pkt;
806 static irqreturn_t bnx2x_msix_fp_int(int irq, void *fp_cookie)
808 struct bnx2x_fastpath *fp = fp_cookie;
809 struct bnx2x *bp = fp->bp;
813 "got an MSI-X interrupt on IDX:SB [fp %d fw_sd %d igusb %d]\n",
814 fp->index, fp->fw_sb_id, fp->igu_sb_id);
815 bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0, IGU_INT_DISABLE, 0);
817 #ifdef BNX2X_STOP_ON_ERROR
818 if (unlikely(bp->panic))
822 /* Handle Rx and Tx according to MSI-X vector */
823 prefetch(fp->rx_cons_sb);
825 for_each_cos_in_tx_queue(fp, cos)
826 prefetch(fp->txdata[cos].tx_cons_sb);
828 prefetch(&fp->sb_running_index[SM_RX_ID]);
829 napi_schedule(&bnx2x_fp(bp, fp->index, napi));
834 /* HW Lock for shared dual port PHYs */
835 void bnx2x_acquire_phy_lock(struct bnx2x *bp)
837 mutex_lock(&bp->port.phy_mutex);
839 if (bp->port.need_hw_lock)
840 bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_MDIO);
843 void bnx2x_release_phy_lock(struct bnx2x *bp)
845 if (bp->port.need_hw_lock)
846 bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_MDIO);
848 mutex_unlock(&bp->port.phy_mutex);
851 /* calculates MF speed according to current linespeed and MF configuration */
852 u16 bnx2x_get_mf_speed(struct bnx2x *bp)
854 u16 line_speed = bp->link_vars.line_speed;
856 u16 maxCfg = bnx2x_extract_max_cfg(bp,
857 bp->mf_config[BP_VN(bp)]);
859 /* Calculate the current MAX line speed limit for the MF
863 line_speed = (line_speed * maxCfg) / 100;
865 u16 vn_max_rate = maxCfg * 100;
867 if (vn_max_rate < line_speed)
868 line_speed = vn_max_rate;
876 * bnx2x_fill_report_data - fill link report data to report
879 * @data: link state to update
881 * It uses a none-atomic bit operations because is called under the mutex.
883 static inline void bnx2x_fill_report_data(struct bnx2x *bp,
884 struct bnx2x_link_report_data *data)
886 u16 line_speed = bnx2x_get_mf_speed(bp);
888 memset(data, 0, sizeof(*data));
890 /* Fill the report data: efective line speed */
891 data->line_speed = line_speed;
894 if (!bp->link_vars.link_up || (bp->flags & MF_FUNC_DIS))
895 __set_bit(BNX2X_LINK_REPORT_LINK_DOWN,
896 &data->link_report_flags);
899 if (bp->link_vars.duplex == DUPLEX_FULL)
900 __set_bit(BNX2X_LINK_REPORT_FD, &data->link_report_flags);
902 /* Rx Flow Control is ON */
903 if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_RX)
904 __set_bit(BNX2X_LINK_REPORT_RX_FC_ON, &data->link_report_flags);
906 /* Tx Flow Control is ON */
907 if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
908 __set_bit(BNX2X_LINK_REPORT_TX_FC_ON, &data->link_report_flags);
912 * bnx2x_link_report - report link status to OS.
916 * Calls the __bnx2x_link_report() under the same locking scheme
917 * as a link/PHY state managing code to ensure a consistent link
921 void bnx2x_link_report(struct bnx2x *bp)
923 bnx2x_acquire_phy_lock(bp);
924 __bnx2x_link_report(bp);
925 bnx2x_release_phy_lock(bp);
929 * __bnx2x_link_report - report link status to OS.
933 * None atomic inmlementation.
934 * Should be called under the phy_lock.
936 void __bnx2x_link_report(struct bnx2x *bp)
938 struct bnx2x_link_report_data cur_data;
942 bnx2x_read_mf_cfg(bp);
944 /* Read the current link report info */
945 bnx2x_fill_report_data(bp, &cur_data);
947 /* Don't report link down or exactly the same link status twice */
948 if (!memcmp(&cur_data, &bp->last_reported_link, sizeof(cur_data)) ||
949 (test_bit(BNX2X_LINK_REPORT_LINK_DOWN,
950 &bp->last_reported_link.link_report_flags) &&
951 test_bit(BNX2X_LINK_REPORT_LINK_DOWN,
952 &cur_data.link_report_flags)))
957 /* We are going to report a new link parameters now -
958 * remember the current data for the next time.
960 memcpy(&bp->last_reported_link, &cur_data, sizeof(cur_data));
962 if (test_bit(BNX2X_LINK_REPORT_LINK_DOWN,
963 &cur_data.link_report_flags)) {
964 netif_carrier_off(bp->dev);
965 netdev_err(bp->dev, "NIC Link is Down\n");
971 netif_carrier_on(bp->dev);
973 if (test_and_clear_bit(BNX2X_LINK_REPORT_FD,
974 &cur_data.link_report_flags))
979 /* Handle the FC at the end so that only these flags would be
980 * possibly set. This way we may easily check if there is no FC
983 if (cur_data.link_report_flags) {
984 if (test_bit(BNX2X_LINK_REPORT_RX_FC_ON,
985 &cur_data.link_report_flags)) {
986 if (test_bit(BNX2X_LINK_REPORT_TX_FC_ON,
987 &cur_data.link_report_flags))
988 flow = "ON - receive & transmit";
990 flow = "ON - receive";
992 flow = "ON - transmit";
997 netdev_info(bp->dev, "NIC Link is Up, %d Mbps %s duplex, Flow control: %s\n",
998 cur_data.line_speed, duplex, flow);
1002 void bnx2x_init_rx_rings(struct bnx2x *bp)
1004 int func = BP_FUNC(bp);
1008 /* Allocate TPA resources */
1009 for_each_rx_queue(bp, j) {
1010 struct bnx2x_fastpath *fp = &bp->fp[j];
1013 "mtu %d rx_buf_size %d\n", bp->dev->mtu, fp->rx_buf_size);
1015 if (!fp->disable_tpa) {
1016 /* Fill the per-aggregtion pool */
1017 for (i = 0; i < MAX_AGG_QS(bp); i++) {
1018 struct bnx2x_agg_info *tpa_info =
1020 struct sw_rx_bd *first_buf =
1021 &tpa_info->first_buf;
1023 first_buf->data = kmalloc(fp->rx_buf_size + NET_SKB_PAD,
1025 if (!first_buf->data) {
1026 BNX2X_ERR("Failed to allocate TPA skb pool for queue[%d] - disabling TPA on this queue!\n",
1028 bnx2x_free_tpa_pool(bp, fp, i);
1029 fp->disable_tpa = 1;
1032 dma_unmap_addr_set(first_buf, mapping, 0);
1033 tpa_info->tpa_state = BNX2X_TPA_STOP;
1036 /* "next page" elements initialization */
1037 bnx2x_set_next_page_sgl(fp);
1039 /* set SGEs bit mask */
1040 bnx2x_init_sge_ring_bit_mask(fp);
1042 /* Allocate SGEs and initialize the ring elements */
1043 for (i = 0, ring_prod = 0;
1044 i < MAX_RX_SGE_CNT*NUM_RX_SGE_PAGES; i++) {
1046 if (bnx2x_alloc_rx_sge(bp, fp, ring_prod) < 0) {
1047 BNX2X_ERR("was only able to allocate %d rx sges\n",
1049 BNX2X_ERR("disabling TPA for queue[%d]\n",
1051 /* Cleanup already allocated elements */
1052 bnx2x_free_rx_sge_range(bp, fp,
1054 bnx2x_free_tpa_pool(bp, fp,
1056 fp->disable_tpa = 1;
1060 ring_prod = NEXT_SGE_IDX(ring_prod);
1063 fp->rx_sge_prod = ring_prod;
1067 for_each_rx_queue(bp, j) {
1068 struct bnx2x_fastpath *fp = &bp->fp[j];
1072 /* Activate BD ring */
1074 * this will generate an interrupt (to the TSTORM)
1075 * must only be done after chip is initialized
1077 bnx2x_update_rx_prod(bp, fp, fp->rx_bd_prod, fp->rx_comp_prod,
1083 if (CHIP_IS_E1(bp)) {
1084 REG_WR(bp, BAR_USTRORM_INTMEM +
1085 USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(func),
1086 U64_LO(fp->rx_comp_mapping));
1087 REG_WR(bp, BAR_USTRORM_INTMEM +
1088 USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(func) + 4,
1089 U64_HI(fp->rx_comp_mapping));
1094 static void bnx2x_free_tx_skbs(struct bnx2x *bp)
1099 for_each_tx_queue(bp, i) {
1100 struct bnx2x_fastpath *fp = &bp->fp[i];
1101 for_each_cos_in_tx_queue(fp, cos) {
1102 struct bnx2x_fp_txdata *txdata = &fp->txdata[cos];
1103 unsigned pkts_compl = 0, bytes_compl = 0;
1105 u16 sw_prod = txdata->tx_pkt_prod;
1106 u16 sw_cons = txdata->tx_pkt_cons;
1108 while (sw_cons != sw_prod) {
1109 bnx2x_free_tx_pkt(bp, txdata, TX_BD(sw_cons),
1110 &pkts_compl, &bytes_compl);
1113 netdev_tx_reset_queue(
1114 netdev_get_tx_queue(bp->dev, txdata->txq_index));
1119 static void bnx2x_free_rx_bds(struct bnx2x_fastpath *fp)
1121 struct bnx2x *bp = fp->bp;
1124 /* ring wasn't allocated */
1125 if (fp->rx_buf_ring == NULL)
1128 for (i = 0; i < NUM_RX_BD; i++) {
1129 struct sw_rx_bd *rx_buf = &fp->rx_buf_ring[i];
1130 u8 *data = rx_buf->data;
1134 dma_unmap_single(&bp->pdev->dev,
1135 dma_unmap_addr(rx_buf, mapping),
1136 fp->rx_buf_size, DMA_FROM_DEVICE);
1138 rx_buf->data = NULL;
1143 static void bnx2x_free_rx_skbs(struct bnx2x *bp)
1147 for_each_rx_queue(bp, j) {
1148 struct bnx2x_fastpath *fp = &bp->fp[j];
1150 bnx2x_free_rx_bds(fp);
1152 if (!fp->disable_tpa)
1153 bnx2x_free_tpa_pool(bp, fp, MAX_AGG_QS(bp));
1157 void bnx2x_free_skbs(struct bnx2x *bp)
1159 bnx2x_free_tx_skbs(bp);
1160 bnx2x_free_rx_skbs(bp);
1163 void bnx2x_update_max_mf_config(struct bnx2x *bp, u32 value)
1165 /* load old values */
1166 u32 mf_cfg = bp->mf_config[BP_VN(bp)];
1168 if (value != bnx2x_extract_max_cfg(bp, mf_cfg)) {
1169 /* leave all but MAX value */
1170 mf_cfg &= ~FUNC_MF_CFG_MAX_BW_MASK;
1172 /* set new MAX value */
1173 mf_cfg |= (value << FUNC_MF_CFG_MAX_BW_SHIFT)
1174 & FUNC_MF_CFG_MAX_BW_MASK;
1176 bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW, mf_cfg);
1181 * bnx2x_free_msix_irqs - free previously requested MSI-X IRQ vectors
1183 * @bp: driver handle
1184 * @nvecs: number of vectors to be released
1186 static void bnx2x_free_msix_irqs(struct bnx2x *bp, int nvecs)
1190 if (nvecs == offset)
1192 free_irq(bp->msix_table[offset].vector, bp->dev);
1193 DP(NETIF_MSG_IFDOWN, "released sp irq (%d)\n",
1194 bp->msix_table[offset].vector);
1197 if (nvecs == offset)
1202 for_each_eth_queue(bp, i) {
1203 if (nvecs == offset)
1205 DP(NETIF_MSG_IFDOWN, "about to release fp #%d->%d irq\n",
1206 i, bp->msix_table[offset].vector);
1208 free_irq(bp->msix_table[offset++].vector, &bp->fp[i]);
1212 void bnx2x_free_irq(struct bnx2x *bp)
1214 if (bp->flags & USING_MSIX_FLAG &&
1215 !(bp->flags & USING_SINGLE_MSIX_FLAG))
1216 bnx2x_free_msix_irqs(bp, BNX2X_NUM_ETH_QUEUES(bp) +
1219 free_irq(bp->dev->irq, bp->dev);
1222 int __devinit bnx2x_enable_msix(struct bnx2x *bp)
1224 int msix_vec = 0, i, rc, req_cnt;
1226 bp->msix_table[msix_vec].entry = msix_vec;
1227 BNX2X_DEV_INFO("msix_table[0].entry = %d (slowpath)\n",
1228 bp->msix_table[0].entry);
1232 bp->msix_table[msix_vec].entry = msix_vec;
1233 BNX2X_DEV_INFO("msix_table[%d].entry = %d (CNIC)\n",
1234 bp->msix_table[msix_vec].entry, bp->msix_table[msix_vec].entry);
1237 /* We need separate vectors for ETH queues only (not FCoE) */
1238 for_each_eth_queue(bp, i) {
1239 bp->msix_table[msix_vec].entry = msix_vec;
1240 BNX2X_DEV_INFO("msix_table[%d].entry = %d (fastpath #%u)\n",
1241 msix_vec, msix_vec, i);
1245 req_cnt = BNX2X_NUM_ETH_QUEUES(bp) + CNIC_PRESENT + 1;
1247 rc = pci_enable_msix(bp->pdev, &bp->msix_table[0], req_cnt);
1250 * reconfigure number of tx/rx queues according to available
1253 if (rc >= BNX2X_MIN_MSIX_VEC_CNT) {
1254 /* how less vectors we will have? */
1255 int diff = req_cnt - rc;
1257 BNX2X_DEV_INFO("Trying to use less MSI-X vectors: %d\n", rc);
1259 rc = pci_enable_msix(bp->pdev, &bp->msix_table[0], rc);
1262 BNX2X_DEV_INFO("MSI-X is not attainable rc %d\n", rc);
1266 * decrease number of queues by number of unallocated entries
1268 bp->num_queues -= diff;
1270 BNX2X_DEV_INFO("New queue configuration set: %d\n",
1272 } else if (rc > 0) {
1273 /* Get by with single vector */
1274 rc = pci_enable_msix(bp->pdev, &bp->msix_table[0], 1);
1276 BNX2X_DEV_INFO("Single MSI-X is not attainable rc %d\n",
1281 BNX2X_DEV_INFO("Using single MSI-X vector\n");
1282 bp->flags |= USING_SINGLE_MSIX_FLAG;
1284 } else if (rc < 0) {
1285 BNX2X_DEV_INFO("MSI-X is not attainable rc %d\n", rc);
1289 bp->flags |= USING_MSIX_FLAG;
1294 /* fall to INTx if not enough memory */
1296 bp->flags |= DISABLE_MSI_FLAG;
1301 static int bnx2x_req_msix_irqs(struct bnx2x *bp)
1303 int i, rc, offset = 0;
1305 rc = request_irq(bp->msix_table[offset++].vector,
1306 bnx2x_msix_sp_int, 0,
1307 bp->dev->name, bp->dev);
1309 BNX2X_ERR("request sp irq failed\n");
1316 for_each_eth_queue(bp, i) {
1317 struct bnx2x_fastpath *fp = &bp->fp[i];
1318 snprintf(fp->name, sizeof(fp->name), "%s-fp-%d",
1321 rc = request_irq(bp->msix_table[offset].vector,
1322 bnx2x_msix_fp_int, 0, fp->name, fp);
1324 BNX2X_ERR("request fp #%d irq (%d) failed rc %d\n", i,
1325 bp->msix_table[offset].vector, rc);
1326 bnx2x_free_msix_irqs(bp, offset);
1333 i = BNX2X_NUM_ETH_QUEUES(bp);
1334 offset = 1 + CNIC_PRESENT;
1335 netdev_info(bp->dev, "using MSI-X IRQs: sp %d fp[%d] %d ... fp[%d] %d\n",
1336 bp->msix_table[0].vector,
1337 0, bp->msix_table[offset].vector,
1338 i - 1, bp->msix_table[offset + i - 1].vector);
1343 int bnx2x_enable_msi(struct bnx2x *bp)
1347 rc = pci_enable_msi(bp->pdev);
1349 BNX2X_DEV_INFO("MSI is not attainable\n");
1352 bp->flags |= USING_MSI_FLAG;
1357 static int bnx2x_req_irq(struct bnx2x *bp)
1359 unsigned long flags;
1362 if (bp->flags & (USING_MSI_FLAG | USING_MSIX_FLAG))
1365 flags = IRQF_SHARED;
1367 if (bp->flags & USING_MSIX_FLAG)
1368 irq = bp->msix_table[0].vector;
1370 irq = bp->pdev->irq;
1372 return request_irq(irq, bnx2x_interrupt, flags, bp->dev->name, bp->dev);
1375 static inline int bnx2x_setup_irqs(struct bnx2x *bp)
1378 if (bp->flags & USING_MSIX_FLAG &&
1379 !(bp->flags & USING_SINGLE_MSIX_FLAG)) {
1380 rc = bnx2x_req_msix_irqs(bp);
1385 rc = bnx2x_req_irq(bp);
1387 BNX2X_ERR("IRQ request failed rc %d, aborting\n", rc);
1390 if (bp->flags & USING_MSI_FLAG) {
1391 bp->dev->irq = bp->pdev->irq;
1392 netdev_info(bp->dev, "using MSI IRQ %d\n",
1395 if (bp->flags & USING_MSIX_FLAG) {
1396 bp->dev->irq = bp->msix_table[0].vector;
1397 netdev_info(bp->dev, "using MSIX IRQ %d\n",
1405 static inline void bnx2x_napi_enable(struct bnx2x *bp)
1409 for_each_rx_queue(bp, i)
1410 napi_enable(&bnx2x_fp(bp, i, napi));
1413 static inline void bnx2x_napi_disable(struct bnx2x *bp)
1417 for_each_rx_queue(bp, i)
1418 napi_disable(&bnx2x_fp(bp, i, napi));
1421 void bnx2x_netif_start(struct bnx2x *bp)
1423 if (netif_running(bp->dev)) {
1424 bnx2x_napi_enable(bp);
1425 bnx2x_int_enable(bp);
1426 if (bp->state == BNX2X_STATE_OPEN)
1427 netif_tx_wake_all_queues(bp->dev);
1431 void bnx2x_netif_stop(struct bnx2x *bp, int disable_hw)
1433 bnx2x_int_disable_sync(bp, disable_hw);
1434 bnx2x_napi_disable(bp);
1437 u16 bnx2x_select_queue(struct net_device *dev, struct sk_buff *skb)
1439 struct bnx2x *bp = netdev_priv(dev);
1443 struct ethhdr *hdr = (struct ethhdr *)skb->data;
1444 u16 ether_type = ntohs(hdr->h_proto);
1446 /* Skip VLAN tag if present */
1447 if (ether_type == ETH_P_8021Q) {
1448 struct vlan_ethhdr *vhdr =
1449 (struct vlan_ethhdr *)skb->data;
1451 ether_type = ntohs(vhdr->h_vlan_encapsulated_proto);
1454 /* If ethertype is FCoE or FIP - use FCoE ring */
1455 if ((ether_type == ETH_P_FCOE) || (ether_type == ETH_P_FIP))
1456 return bnx2x_fcoe_tx(bp, txq_index);
1459 /* select a non-FCoE queue */
1460 return __skb_tx_hash(dev, skb, BNX2X_NUM_ETH_QUEUES(bp));
1464 void bnx2x_set_num_queues(struct bnx2x *bp)
1467 bp->num_queues = bnx2x_calc_num_queues(bp);
1470 /* override in STORAGE SD modes */
1471 if (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))
1474 /* Add special queues */
1475 bp->num_queues += NON_ETH_CONTEXT_USE;
1479 * bnx2x_set_real_num_queues - configure netdev->real_num_[tx,rx]_queues
1481 * @bp: Driver handle
1483 * We currently support for at most 16 Tx queues for each CoS thus we will
1484 * allocate a multiple of 16 for ETH L2 rings according to the value of the
1487 * If there is an FCoE L2 queue the appropriate Tx queue will have the next
1488 * index after all ETH L2 indices.
1490 * If the actual number of Tx queues (for each CoS) is less than 16 then there
1491 * will be the holes at the end of each group of 16 ETh L2 indices (0..15,
1492 * 16..31,...) with indicies that are not coupled with any real Tx queue.
1494 * The proper configuration of skb->queue_mapping is handled by
1495 * bnx2x_select_queue() and __skb_tx_hash().
1497 * bnx2x_setup_tc() takes care of the proper TC mappings so that __skb_tx_hash()
1498 * will return a proper Tx index if TC is enabled (netdev->num_tc > 0).
1500 static inline int bnx2x_set_real_num_queues(struct bnx2x *bp)
1504 tx = MAX_TXQS_PER_COS * bp->max_cos;
1505 rx = BNX2X_NUM_ETH_QUEUES(bp);
1507 /* account for fcoe queue */
1515 rc = netif_set_real_num_tx_queues(bp->dev, tx);
1517 BNX2X_ERR("Failed to set real number of Tx queues: %d\n", rc);
1520 rc = netif_set_real_num_rx_queues(bp->dev, rx);
1522 BNX2X_ERR("Failed to set real number of Rx queues: %d\n", rc);
1526 DP(NETIF_MSG_IFUP, "Setting real num queues to (tx, rx) (%d, %d)\n",
1532 static inline void bnx2x_set_rx_buf_size(struct bnx2x *bp)
1536 for_each_queue(bp, i) {
1537 struct bnx2x_fastpath *fp = &bp->fp[i];
1540 /* Always use a mini-jumbo MTU for the FCoE L2 ring */
1543 * Although there are no IP frames expected to arrive to
1544 * this ring we still want to add an
1545 * IP_HEADER_ALIGNMENT_PADDING to prevent a buffer
1548 mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
1551 fp->rx_buf_size = BNX2X_FW_RX_ALIGN_START +
1552 IP_HEADER_ALIGNMENT_PADDING +
1555 BNX2X_FW_RX_ALIGN_END;
1556 /* Note : rx_buf_size doesnt take into account NET_SKB_PAD */
1560 static inline int bnx2x_init_rss_pf(struct bnx2x *bp)
1563 u8 ind_table[T_ETH_INDIRECTION_TABLE_SIZE] = {0};
1564 u8 num_eth_queues = BNX2X_NUM_ETH_QUEUES(bp);
1566 /* Prepare the initial contents fo the indirection table if RSS is
1569 for (i = 0; i < sizeof(ind_table); i++)
1572 ethtool_rxfh_indir_default(i, num_eth_queues);
1575 * For 57710 and 57711 SEARCHER configuration (rss_keys) is
1576 * per-port, so if explicit configuration is needed , do it only
1579 * For 57712 and newer on the other hand it's a per-function
1582 return bnx2x_config_rss_eth(bp, ind_table,
1583 bp->port.pmf || !CHIP_IS_E1x(bp));
1586 int bnx2x_config_rss_pf(struct bnx2x *bp, struct bnx2x_rss_config_obj *rss_obj,
1587 u8 *ind_table, bool config_hash)
1589 struct bnx2x_config_rss_params params = {NULL};
1592 /* Although RSS is meaningless when there is a single HW queue we
1593 * still need it enabled in order to have HW Rx hash generated.
1595 * if (!is_eth_multi(bp))
1596 * bp->multi_mode = ETH_RSS_MODE_DISABLED;
1599 params.rss_obj = rss_obj;
1601 __set_bit(RAMROD_COMP_WAIT, ¶ms.ramrod_flags);
1603 __set_bit(BNX2X_RSS_MODE_REGULAR, ¶ms.rss_flags);
1605 /* RSS configuration */
1606 __set_bit(BNX2X_RSS_IPV4, ¶ms.rss_flags);
1607 __set_bit(BNX2X_RSS_IPV4_TCP, ¶ms.rss_flags);
1608 __set_bit(BNX2X_RSS_IPV6, ¶ms.rss_flags);
1609 __set_bit(BNX2X_RSS_IPV6_TCP, ¶ms.rss_flags);
1612 params.rss_result_mask = MULTI_MASK;
1614 memcpy(params.ind_table, ind_table, sizeof(params.ind_table));
1618 for (i = 0; i < sizeof(params.rss_key) / 4; i++)
1619 params.rss_key[i] = random32();
1621 __set_bit(BNX2X_RSS_SET_SRCH, ¶ms.rss_flags);
1624 return bnx2x_config_rss(bp, ¶ms);
1627 static inline int bnx2x_init_hw(struct bnx2x *bp, u32 load_code)
1629 struct bnx2x_func_state_params func_params = {NULL};
1631 /* Prepare parameters for function state transitions */
1632 __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
1634 func_params.f_obj = &bp->func_obj;
1635 func_params.cmd = BNX2X_F_CMD_HW_INIT;
1637 func_params.params.hw_init.load_phase = load_code;
1639 return bnx2x_func_state_change(bp, &func_params);
1643 * Cleans the object that have internal lists without sending
1644 * ramrods. Should be run when interrutps are disabled.
1646 static void bnx2x_squeeze_objects(struct bnx2x *bp)
1649 unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
1650 struct bnx2x_mcast_ramrod_params rparam = {NULL};
1651 struct bnx2x_vlan_mac_obj *mac_obj = &bp->fp->mac_obj;
1653 /***************** Cleanup MACs' object first *************************/
1655 /* Wait for completion of requested */
1656 __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
1657 /* Perform a dry cleanup */
1658 __set_bit(RAMROD_DRV_CLR_ONLY, &ramrod_flags);
1660 /* Clean ETH primary MAC */
1661 __set_bit(BNX2X_ETH_MAC, &vlan_mac_flags);
1662 rc = mac_obj->delete_all(bp, &bp->fp->mac_obj, &vlan_mac_flags,
1665 BNX2X_ERR("Failed to clean ETH MACs: %d\n", rc);
1667 /* Cleanup UC list */
1669 __set_bit(BNX2X_UC_LIST_MAC, &vlan_mac_flags);
1670 rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags,
1673 BNX2X_ERR("Failed to clean UC list MACs: %d\n", rc);
1675 /***************** Now clean mcast object *****************************/
1676 rparam.mcast_obj = &bp->mcast_obj;
1677 __set_bit(RAMROD_DRV_CLR_ONLY, &rparam.ramrod_flags);
1679 /* Add a DEL command... */
1680 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
1682 BNX2X_ERR("Failed to add a new DEL command to a multi-cast object: %d\n",
1685 /* ...and wait until all pending commands are cleared */
1686 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
1689 BNX2X_ERR("Failed to clean multi-cast object: %d\n",
1694 rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
1698 #ifndef BNX2X_STOP_ON_ERROR
1699 #define LOAD_ERROR_EXIT(bp, label) \
1701 (bp)->state = BNX2X_STATE_ERROR; \
1705 #define LOAD_ERROR_EXIT(bp, label) \
1707 (bp)->state = BNX2X_STATE_ERROR; \
1713 bool bnx2x_test_firmware_version(struct bnx2x *bp, bool is_err)
1715 /* build FW version dword */
1716 u32 my_fw = (BCM_5710_FW_MAJOR_VERSION) +
1717 (BCM_5710_FW_MINOR_VERSION << 8) +
1718 (BCM_5710_FW_REVISION_VERSION << 16) +
1719 (BCM_5710_FW_ENGINEERING_VERSION << 24);
1721 /* read loaded FW from chip */
1722 u32 loaded_fw = REG_RD(bp, XSEM_REG_PRAM);
1724 DP(NETIF_MSG_IFUP, "loaded fw %x, my fw %x\n", loaded_fw, my_fw);
1726 if (loaded_fw != my_fw) {
1728 BNX2X_ERR("bnx2x with FW %x was already loaded, which mismatches my %x FW. aborting\n",
1736 /* must be called with rtnl_lock */
1737 int bnx2x_nic_load(struct bnx2x *bp, int load_mode)
1739 int port = BP_PORT(bp);
1743 #ifdef BNX2X_STOP_ON_ERROR
1744 if (unlikely(bp->panic)) {
1745 BNX2X_ERR("Can't load NIC when there is panic\n");
1750 bp->state = BNX2X_STATE_OPENING_WAIT4_LOAD;
1752 /* Set the initial link reported state to link down */
1753 bnx2x_acquire_phy_lock(bp);
1754 memset(&bp->last_reported_link, 0, sizeof(bp->last_reported_link));
1755 __set_bit(BNX2X_LINK_REPORT_LINK_DOWN,
1756 &bp->last_reported_link.link_report_flags);
1757 bnx2x_release_phy_lock(bp);
1759 /* must be called before memory allocation and HW init */
1760 bnx2x_ilt_set_info(bp);
1763 * Zero fastpath structures preserving invariants like napi, which are
1764 * allocated only once, fp index, max_cos, bp pointer.
1765 * Also set fp->disable_tpa.
1767 DP(NETIF_MSG_IFUP, "num queues: %d", bp->num_queues);
1768 for_each_queue(bp, i)
1772 /* Set the receive queues buffer size */
1773 bnx2x_set_rx_buf_size(bp);
1775 if (bnx2x_alloc_mem(bp))
1778 /* As long as bnx2x_alloc_mem() may possibly update
1779 * bp->num_queues, bnx2x_set_real_num_queues() should always
1782 rc = bnx2x_set_real_num_queues(bp);
1784 BNX2X_ERR("Unable to set real_num_queues\n");
1785 LOAD_ERROR_EXIT(bp, load_error0);
1788 /* configure multi cos mappings in kernel.
1789 * this configuration may be overriden by a multi class queue discipline
1790 * or by a dcbx negotiation result.
1792 bnx2x_setup_tc(bp->dev, bp->max_cos);
1794 bnx2x_napi_enable(bp);
1796 /* set pf load just before approaching the MCP */
1797 bnx2x_set_pf_load(bp);
1799 /* Send LOAD_REQUEST command to MCP
1800 * Returns the type of LOAD command:
1801 * if it is the first port to be initialized
1802 * common blocks should be initialized, otherwise - not
1804 if (!BP_NOMCP(bp)) {
1807 (SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
1808 DRV_MSG_SEQ_NUMBER_MASK);
1809 BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
1811 /* Get current FW pulse sequence */
1812 bp->fw_drv_pulse_wr_seq =
1813 (SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb) &
1814 DRV_PULSE_SEQ_MASK);
1815 BNX2X_DEV_INFO("drv_pulse 0x%x\n", bp->fw_drv_pulse_wr_seq);
1817 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ, 0);
1819 BNX2X_ERR("MCP response failure, aborting\n");
1821 LOAD_ERROR_EXIT(bp, load_error1);
1823 if (load_code == FW_MSG_CODE_DRV_LOAD_REFUSED) {
1824 BNX2X_ERR("Driver load refused\n");
1825 rc = -EBUSY; /* other port in diagnostic mode */
1826 LOAD_ERROR_EXIT(bp, load_error1);
1828 if (load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP &&
1829 load_code != FW_MSG_CODE_DRV_LOAD_COMMON) {
1830 /* abort nic load if version mismatch */
1831 if (!bnx2x_test_firmware_version(bp, true)) {
1833 LOAD_ERROR_EXIT(bp, load_error2);
1838 int path = BP_PATH(bp);
1840 DP(NETIF_MSG_IFUP, "NO MCP - load counts[%d] %d, %d, %d\n",
1841 path, load_count[path][0], load_count[path][1],
1842 load_count[path][2]);
1843 load_count[path][0]++;
1844 load_count[path][1 + port]++;
1845 DP(NETIF_MSG_IFUP, "NO MCP - new load counts[%d] %d, %d, %d\n",
1846 path, load_count[path][0], load_count[path][1],
1847 load_count[path][2]);
1848 if (load_count[path][0] == 1)
1849 load_code = FW_MSG_CODE_DRV_LOAD_COMMON;
1850 else if (load_count[path][1 + port] == 1)
1851 load_code = FW_MSG_CODE_DRV_LOAD_PORT;
1853 load_code = FW_MSG_CODE_DRV_LOAD_FUNCTION;
1856 if ((load_code == FW_MSG_CODE_DRV_LOAD_COMMON) ||
1857 (load_code == FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) ||
1858 (load_code == FW_MSG_CODE_DRV_LOAD_PORT)) {
1861 * We need the barrier to ensure the ordering between the
1862 * writing to bp->port.pmf here and reading it from the
1863 * bnx2x_periodic_task().
1869 DP(NETIF_MSG_IFUP, "pmf %d\n", bp->port.pmf);
1871 /* Init Function state controlling object */
1872 bnx2x__init_func_obj(bp);
1875 rc = bnx2x_init_hw(bp, load_code);
1877 BNX2X_ERR("HW init failed, aborting\n");
1878 bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
1879 LOAD_ERROR_EXIT(bp, load_error2);
1882 /* Connect to IRQs */
1883 rc = bnx2x_setup_irqs(bp);
1885 BNX2X_ERR("IRQs setup failed\n");
1886 bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
1887 LOAD_ERROR_EXIT(bp, load_error2);
1890 /* Setup NIC internals and enable interrupts */
1891 bnx2x_nic_init(bp, load_code);
1893 /* Init per-function objects */
1894 bnx2x_init_bp_objs(bp);
1896 if (((load_code == FW_MSG_CODE_DRV_LOAD_COMMON) ||
1897 (load_code == FW_MSG_CODE_DRV_LOAD_COMMON_CHIP)) &&
1898 (bp->common.shmem2_base)) {
1899 if (SHMEM2_HAS(bp, dcc_support))
1900 SHMEM2_WR(bp, dcc_support,
1901 (SHMEM_DCC_SUPPORT_DISABLE_ENABLE_PF_TLV |
1902 SHMEM_DCC_SUPPORT_BANDWIDTH_ALLOCATION_TLV));
1903 if (SHMEM2_HAS(bp, afex_driver_support))
1904 SHMEM2_WR(bp, afex_driver_support,
1905 SHMEM_AFEX_SUPPORTED_VERSION_ONE);
1908 /* Set AFEX default VLAN tag to an invalid value */
1909 bp->afex_def_vlan_tag = -1;
1911 bp->state = BNX2X_STATE_OPENING_WAIT4_PORT;
1912 rc = bnx2x_func_start(bp);
1914 BNX2X_ERR("Function start failed!\n");
1915 bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
1916 LOAD_ERROR_EXIT(bp, load_error3);
1919 /* Send LOAD_DONE command to MCP */
1920 if (!BP_NOMCP(bp)) {
1921 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
1923 BNX2X_ERR("MCP response failure, aborting\n");
1925 LOAD_ERROR_EXIT(bp, load_error3);
1929 rc = bnx2x_setup_leading(bp);
1931 BNX2X_ERR("Setup leading failed!\n");
1932 LOAD_ERROR_EXIT(bp, load_error3);
1936 /* Enable Timer scan */
1937 REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 1);
1940 for_each_nondefault_queue(bp, i) {
1941 rc = bnx2x_setup_queue(bp, &bp->fp[i], 0);
1943 BNX2X_ERR("Queue setup failed\n");
1944 LOAD_ERROR_EXIT(bp, load_error4);
1948 rc = bnx2x_init_rss_pf(bp);
1950 BNX2X_ERR("PF RSS init failed\n");
1951 LOAD_ERROR_EXIT(bp, load_error4);
1954 /* Now when Clients are configured we are ready to work */
1955 bp->state = BNX2X_STATE_OPEN;
1957 /* Configure a ucast MAC */
1958 rc = bnx2x_set_eth_mac(bp, true);
1960 BNX2X_ERR("Setting Ethernet MAC failed\n");
1961 LOAD_ERROR_EXIT(bp, load_error4);
1964 if (bp->pending_max) {
1965 bnx2x_update_max_mf_config(bp, bp->pending_max);
1966 bp->pending_max = 0;
1970 bnx2x_initial_phy_init(bp, load_mode);
1972 /* Start fast path */
1974 /* Initialize Rx filter. */
1975 netif_addr_lock_bh(bp->dev);
1976 bnx2x_set_rx_mode(bp->dev);
1977 netif_addr_unlock_bh(bp->dev);
1980 switch (load_mode) {
1982 /* Tx queue should be only reenabled */
1983 netif_tx_wake_all_queues(bp->dev);
1987 netif_tx_start_all_queues(bp->dev);
1988 smp_mb__after_clear_bit();
1992 bp->state = BNX2X_STATE_DIAG;
2000 bnx2x_update_drv_flags(bp, 1 << DRV_FLAGS_DCB_CONFIGURED, 0);
2002 bnx2x__link_status_update(bp);
2004 /* start the timer */
2005 mod_timer(&bp->timer, jiffies + bp->current_interval);
2008 /* re-read iscsi info */
2009 bnx2x_get_iscsi_info(bp);
2010 bnx2x_setup_cnic_irq_info(bp);
2011 if (bp->state == BNX2X_STATE_OPEN)
2012 bnx2x_cnic_notify(bp, CNIC_CTL_START_CMD);
2015 /* mark driver is loaded in shmem2 */
2016 if (SHMEM2_HAS(bp, drv_capabilities_flag)) {
2018 val = SHMEM2_RD(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
2019 SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
2020 val | DRV_FLAGS_CAPABILITIES_LOADED_SUPPORTED |
2021 DRV_FLAGS_CAPABILITIES_LOADED_L2);
2024 /* Wait for all pending SP commands to complete */
2025 if (!bnx2x_wait_sp_comp(bp, ~0x0UL)) {
2026 BNX2X_ERR("Timeout waiting for SP elements to complete\n");
2027 bnx2x_nic_unload(bp, UNLOAD_CLOSE);
2031 bnx2x_dcbx_init(bp);
2034 #ifndef BNX2X_STOP_ON_ERROR
2037 /* Disable Timer scan */
2038 REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
2041 bnx2x_int_disable_sync(bp, 1);
2043 /* Clean queueable objects */
2044 bnx2x_squeeze_objects(bp);
2046 /* Free SKBs, SGEs, TPA pool and driver internals */
2047 bnx2x_free_skbs(bp);
2048 for_each_rx_queue(bp, i)
2049 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
2054 if (!BP_NOMCP(bp)) {
2055 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
2056 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
2061 bnx2x_napi_disable(bp);
2062 /* clear pf_load status, as it was already set */
2063 bnx2x_clear_pf_load(bp);
2068 #endif /* ! BNX2X_STOP_ON_ERROR */
2071 /* must be called with rtnl_lock */
2072 int bnx2x_nic_unload(struct bnx2x *bp, int unload_mode)
2075 bool global = false;
2077 /* mark driver is unloaded in shmem2 */
2078 if (SHMEM2_HAS(bp, drv_capabilities_flag)) {
2080 val = SHMEM2_RD(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
2081 SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
2082 val & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
2085 if ((bp->state == BNX2X_STATE_CLOSED) ||
2086 (bp->state == BNX2X_STATE_ERROR)) {
2087 /* We can get here if the driver has been unloaded
2088 * during parity error recovery and is either waiting for a
2089 * leader to complete or for other functions to unload and
2090 * then ifdown has been issued. In this case we want to
2091 * unload and let other functions to complete a recovery
2094 bp->recovery_state = BNX2X_RECOVERY_DONE;
2096 bnx2x_release_leader_lock(bp);
2099 DP(NETIF_MSG_IFDOWN, "Releasing a leadership...\n");
2100 BNX2X_ERR("Can't unload in closed or error state\n");
2105 * It's important to set the bp->state to the value different from
2106 * BNX2X_STATE_OPEN and only then stop the Tx. Otherwise bnx2x_tx_int()
2107 * may restart the Tx from the NAPI context (see bnx2x_tx_int()).
2109 bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
2113 bnx2x_tx_disable(bp);
2116 bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
2119 bp->rx_mode = BNX2X_RX_MODE_NONE;
2121 del_timer_sync(&bp->timer);
2123 /* Set ALWAYS_ALIVE bit in shmem */
2124 bp->fw_drv_pulse_wr_seq |= DRV_PULSE_ALWAYS_ALIVE;
2126 bnx2x_drv_pulse(bp);
2128 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2129 bnx2x_save_statistics(bp);
2131 /* Cleanup the chip if needed */
2132 if (unload_mode != UNLOAD_RECOVERY)
2133 bnx2x_chip_cleanup(bp, unload_mode);
2135 /* Send the UNLOAD_REQUEST to the MCP */
2136 bnx2x_send_unload_req(bp, unload_mode);
2139 * Prevent transactions to host from the functions on the
2140 * engine that doesn't reset global blocks in case of global
2141 * attention once gloabl blocks are reset and gates are opened
2142 * (the engine which leader will perform the recovery
2145 if (!CHIP_IS_E1x(bp))
2146 bnx2x_pf_disable(bp);
2148 /* Disable HW interrupts, NAPI */
2149 bnx2x_netif_stop(bp, 1);
2154 /* Report UNLOAD_DONE to MCP */
2155 bnx2x_send_unload_done(bp);
2159 * At this stage no more interrupts will arrive so we may safly clean
2160 * the queueable objects here in case they failed to get cleaned so far.
2162 bnx2x_squeeze_objects(bp);
2164 /* There should be no more pending SP commands at this stage */
2169 /* Free SKBs, SGEs, TPA pool and driver internals */
2170 bnx2x_free_skbs(bp);
2171 for_each_rx_queue(bp, i)
2172 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
2176 bp->state = BNX2X_STATE_CLOSED;
2178 /* Check if there are pending parity attentions. If there are - set
2179 * RECOVERY_IN_PROGRESS.
2181 if (bnx2x_chk_parity_attn(bp, &global, false)) {
2182 bnx2x_set_reset_in_progress(bp);
2184 /* Set RESET_IS_GLOBAL if needed */
2186 bnx2x_set_reset_global(bp);
2190 /* The last driver must disable a "close the gate" if there is no
2191 * parity attention or "process kill" pending.
2193 if (!bnx2x_clear_pf_load(bp) && bnx2x_reset_is_done(bp, BP_PATH(bp)))
2194 bnx2x_disable_close_the_gate(bp);
2199 int bnx2x_set_power_state(struct bnx2x *bp, pci_power_t state)
2203 /* If there is no power capability, silently succeed */
2205 BNX2X_DEV_INFO("No power capability. Breaking.\n");
2209 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmcsr);
2213 pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
2214 ((pmcsr & ~PCI_PM_CTRL_STATE_MASK) |
2215 PCI_PM_CTRL_PME_STATUS));
2217 if (pmcsr & PCI_PM_CTRL_STATE_MASK)
2218 /* delay required during transition out of D3hot */
2223 /* If there are other clients above don't
2224 shut down the power */
2225 if (atomic_read(&bp->pdev->enable_cnt) != 1)
2227 /* Don't shut down the power for emulation and FPGA */
2228 if (CHIP_REV_IS_SLOW(bp))
2231 pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
2235 pmcsr |= PCI_PM_CTRL_PME_ENABLE;
2237 pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
2240 /* No more memory access after this point until
2241 * device is brought back to D0.
2246 dev_err(&bp->pdev->dev, "Can't support state = %d\n", state);
2253 * net_device service functions
2255 int bnx2x_poll(struct napi_struct *napi, int budget)
2259 struct bnx2x_fastpath *fp = container_of(napi, struct bnx2x_fastpath,
2261 struct bnx2x *bp = fp->bp;
2264 #ifdef BNX2X_STOP_ON_ERROR
2265 if (unlikely(bp->panic)) {
2266 napi_complete(napi);
2271 for_each_cos_in_tx_queue(fp, cos)
2272 if (bnx2x_tx_queue_has_work(&fp->txdata[cos]))
2273 bnx2x_tx_int(bp, &fp->txdata[cos]);
2276 if (bnx2x_has_rx_work(fp)) {
2277 work_done += bnx2x_rx_int(fp, budget - work_done);
2279 /* must not complete if we consumed full budget */
2280 if (work_done >= budget)
2284 /* Fall out from the NAPI loop if needed */
2285 if (!(bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
2287 /* No need to update SB for FCoE L2 ring as long as
2288 * it's connected to the default SB and the SB
2289 * has been updated when NAPI was scheduled.
2291 if (IS_FCOE_FP(fp)) {
2292 napi_complete(napi);
2297 bnx2x_update_fpsb_idx(fp);
2298 /* bnx2x_has_rx_work() reads the status block,
2299 * thus we need to ensure that status block indices
2300 * have been actually read (bnx2x_update_fpsb_idx)
2301 * prior to this check (bnx2x_has_rx_work) so that
2302 * we won't write the "newer" value of the status block
2303 * to IGU (if there was a DMA right after
2304 * bnx2x_has_rx_work and if there is no rmb, the memory
2305 * reading (bnx2x_update_fpsb_idx) may be postponed
2306 * to right before bnx2x_ack_sb). In this case there
2307 * will never be another interrupt until there is
2308 * another update of the status block, while there
2309 * is still unhandled work.
2313 if (!(bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
2314 napi_complete(napi);
2315 /* Re-enable interrupts */
2316 DP(NETIF_MSG_RX_STATUS,
2317 "Update index to %d\n", fp->fp_hc_idx);
2318 bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID,
2319 le16_to_cpu(fp->fp_hc_idx),
2329 /* we split the first BD into headers and data BDs
2330 * to ease the pain of our fellow microcode engineers
2331 * we use one mapping for both BDs
2332 * So far this has only been observed to happen
2333 * in Other Operating Systems(TM)
2335 static noinline u16 bnx2x_tx_split(struct bnx2x *bp,
2336 struct bnx2x_fp_txdata *txdata,
2337 struct sw_tx_bd *tx_buf,
2338 struct eth_tx_start_bd **tx_bd, u16 hlen,
2339 u16 bd_prod, int nbd)
2341 struct eth_tx_start_bd *h_tx_bd = *tx_bd;
2342 struct eth_tx_bd *d_tx_bd;
2344 int old_len = le16_to_cpu(h_tx_bd->nbytes);
2346 /* first fix first BD */
2347 h_tx_bd->nbd = cpu_to_le16(nbd);
2348 h_tx_bd->nbytes = cpu_to_le16(hlen);
2350 DP(NETIF_MSG_TX_QUEUED, "TSO split header size is %d (%x:%x) nbd %d\n",
2351 h_tx_bd->nbytes, h_tx_bd->addr_hi, h_tx_bd->addr_lo, h_tx_bd->nbd);
2353 /* now get a new data BD
2354 * (after the pbd) and fill it */
2355 bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
2356 d_tx_bd = &txdata->tx_desc_ring[bd_prod].reg_bd;
2358 mapping = HILO_U64(le32_to_cpu(h_tx_bd->addr_hi),
2359 le32_to_cpu(h_tx_bd->addr_lo)) + hlen;
2361 d_tx_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
2362 d_tx_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
2363 d_tx_bd->nbytes = cpu_to_le16(old_len - hlen);
2365 /* this marks the BD as one that has no individual mapping */
2366 tx_buf->flags |= BNX2X_TSO_SPLIT_BD;
2368 DP(NETIF_MSG_TX_QUEUED,
2369 "TSO split data size is %d (%x:%x)\n",
2370 d_tx_bd->nbytes, d_tx_bd->addr_hi, d_tx_bd->addr_lo);
2373 *tx_bd = (struct eth_tx_start_bd *)d_tx_bd;
2378 static inline u16 bnx2x_csum_fix(unsigned char *t_header, u16 csum, s8 fix)
2381 csum = (u16) ~csum_fold(csum_sub(csum,
2382 csum_partial(t_header - fix, fix, 0)));
2385 csum = (u16) ~csum_fold(csum_add(csum,
2386 csum_partial(t_header, -fix, 0)));
2388 return swab16(csum);
2391 static inline u32 bnx2x_xmit_type(struct bnx2x *bp, struct sk_buff *skb)
2395 if (skb->ip_summed != CHECKSUM_PARTIAL)
2399 if (vlan_get_protocol(skb) == htons(ETH_P_IPV6)) {
2401 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
2402 rc |= XMIT_CSUM_TCP;
2406 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
2407 rc |= XMIT_CSUM_TCP;
2411 if (skb_is_gso_v6(skb))
2412 rc |= XMIT_GSO_V6 | XMIT_CSUM_TCP | XMIT_CSUM_V6;
2413 else if (skb_is_gso(skb))
2414 rc |= XMIT_GSO_V4 | XMIT_CSUM_V4 | XMIT_CSUM_TCP;
2419 #if (MAX_SKB_FRAGS >= MAX_FETCH_BD - 3)
2420 /* check if packet requires linearization (packet is too fragmented)
2421 no need to check fragmentation if page size > 8K (there will be no
2422 violation to FW restrictions) */
2423 static int bnx2x_pkt_req_lin(struct bnx2x *bp, struct sk_buff *skb,
2428 int first_bd_sz = 0;
2430 /* 3 = 1 (for linear data BD) + 2 (for PBD and last BD) */
2431 if (skb_shinfo(skb)->nr_frags >= (MAX_FETCH_BD - 3)) {
2433 if (xmit_type & XMIT_GSO) {
2434 unsigned short lso_mss = skb_shinfo(skb)->gso_size;
2435 /* Check if LSO packet needs to be copied:
2436 3 = 1 (for headers BD) + 2 (for PBD and last BD) */
2437 int wnd_size = MAX_FETCH_BD - 3;
2438 /* Number of windows to check */
2439 int num_wnds = skb_shinfo(skb)->nr_frags - wnd_size;
2444 /* Headers length */
2445 hlen = (int)(skb_transport_header(skb) - skb->data) +
2448 /* Amount of data (w/o headers) on linear part of SKB*/
2449 first_bd_sz = skb_headlen(skb) - hlen;
2451 wnd_sum = first_bd_sz;
2453 /* Calculate the first sum - it's special */
2454 for (frag_idx = 0; frag_idx < wnd_size - 1; frag_idx++)
2456 skb_frag_size(&skb_shinfo(skb)->frags[frag_idx]);
2458 /* If there was data on linear skb data - check it */
2459 if (first_bd_sz > 0) {
2460 if (unlikely(wnd_sum < lso_mss)) {
2465 wnd_sum -= first_bd_sz;
2468 /* Others are easier: run through the frag list and
2469 check all windows */
2470 for (wnd_idx = 0; wnd_idx <= num_wnds; wnd_idx++) {
2472 skb_frag_size(&skb_shinfo(skb)->frags[wnd_idx + wnd_size - 1]);
2474 if (unlikely(wnd_sum < lso_mss)) {
2479 skb_frag_size(&skb_shinfo(skb)->frags[wnd_idx]);
2482 /* in non-LSO too fragmented packet should always
2489 if (unlikely(to_copy))
2490 DP(NETIF_MSG_TX_QUEUED,
2491 "Linearization IS REQUIRED for %s packet. num_frags %d hlen %d first_bd_sz %d\n",
2492 (xmit_type & XMIT_GSO) ? "LSO" : "non-LSO",
2493 skb_shinfo(skb)->nr_frags, hlen, first_bd_sz);
2499 static inline void bnx2x_set_pbd_gso_e2(struct sk_buff *skb, u32 *parsing_data,
2502 *parsing_data |= (skb_shinfo(skb)->gso_size <<
2503 ETH_TX_PARSE_BD_E2_LSO_MSS_SHIFT) &
2504 ETH_TX_PARSE_BD_E2_LSO_MSS;
2505 if ((xmit_type & XMIT_GSO_V6) &&
2506 (ipv6_hdr(skb)->nexthdr == NEXTHDR_IPV6))
2507 *parsing_data |= ETH_TX_PARSE_BD_E2_IPV6_WITH_EXT_HDR;
2511 * bnx2x_set_pbd_gso - update PBD in GSO case.
2515 * @xmit_type: xmit flags
2517 static inline void bnx2x_set_pbd_gso(struct sk_buff *skb,
2518 struct eth_tx_parse_bd_e1x *pbd,
2521 pbd->lso_mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
2522 pbd->tcp_send_seq = swab32(tcp_hdr(skb)->seq);
2523 pbd->tcp_flags = pbd_tcp_flags(skb);
2525 if (xmit_type & XMIT_GSO_V4) {
2526 pbd->ip_id = swab16(ip_hdr(skb)->id);
2527 pbd->tcp_pseudo_csum =
2528 swab16(~csum_tcpudp_magic(ip_hdr(skb)->saddr,
2530 0, IPPROTO_TCP, 0));
2533 pbd->tcp_pseudo_csum =
2534 swab16(~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
2535 &ipv6_hdr(skb)->daddr,
2536 0, IPPROTO_TCP, 0));
2538 pbd->global_data |= ETH_TX_PARSE_BD_E1X_PSEUDO_CS_WITHOUT_LEN;
2542 * bnx2x_set_pbd_csum_e2 - update PBD with checksum and return header length
2544 * @bp: driver handle
2546 * @parsing_data: data to be updated
2547 * @xmit_type: xmit flags
2551 static inline u8 bnx2x_set_pbd_csum_e2(struct bnx2x *bp, struct sk_buff *skb,
2552 u32 *parsing_data, u32 xmit_type)
2555 ((((u8 *)skb_transport_header(skb) - skb->data) >> 1) <<
2556 ETH_TX_PARSE_BD_E2_TCP_HDR_START_OFFSET_W_SHIFT) &
2557 ETH_TX_PARSE_BD_E2_TCP_HDR_START_OFFSET_W;
2559 if (xmit_type & XMIT_CSUM_TCP) {
2560 *parsing_data |= ((tcp_hdrlen(skb) / 4) <<
2561 ETH_TX_PARSE_BD_E2_TCP_HDR_LENGTH_DW_SHIFT) &
2562 ETH_TX_PARSE_BD_E2_TCP_HDR_LENGTH_DW;
2564 return skb_transport_header(skb) + tcp_hdrlen(skb) - skb->data;
2566 /* We support checksum offload for TCP and UDP only.
2567 * No need to pass the UDP header length - it's a constant.
2569 return skb_transport_header(skb) +
2570 sizeof(struct udphdr) - skb->data;
2573 static inline void bnx2x_set_sbd_csum(struct bnx2x *bp, struct sk_buff *skb,
2574 struct eth_tx_start_bd *tx_start_bd, u32 xmit_type)
2576 tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_L4_CSUM;
2578 if (xmit_type & XMIT_CSUM_V4)
2579 tx_start_bd->bd_flags.as_bitfield |=
2580 ETH_TX_BD_FLAGS_IP_CSUM;
2582 tx_start_bd->bd_flags.as_bitfield |=
2583 ETH_TX_BD_FLAGS_IPV6;
2585 if (!(xmit_type & XMIT_CSUM_TCP))
2586 tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_IS_UDP;
2590 * bnx2x_set_pbd_csum - update PBD with checksum and return header length
2592 * @bp: driver handle
2594 * @pbd: parse BD to be updated
2595 * @xmit_type: xmit flags
2597 static inline u8 bnx2x_set_pbd_csum(struct bnx2x *bp, struct sk_buff *skb,
2598 struct eth_tx_parse_bd_e1x *pbd,
2601 u8 hlen = (skb_network_header(skb) - skb->data) >> 1;
2603 /* for now NS flag is not used in Linux */
2605 (hlen | ((skb->protocol == cpu_to_be16(ETH_P_8021Q)) <<
2606 ETH_TX_PARSE_BD_E1X_LLC_SNAP_EN_SHIFT));
2608 pbd->ip_hlen_w = (skb_transport_header(skb) -
2609 skb_network_header(skb)) >> 1;
2611 hlen += pbd->ip_hlen_w;
2613 /* We support checksum offload for TCP and UDP only */
2614 if (xmit_type & XMIT_CSUM_TCP)
2615 hlen += tcp_hdrlen(skb) / 2;
2617 hlen += sizeof(struct udphdr) / 2;
2619 pbd->total_hlen_w = cpu_to_le16(hlen);
2622 if (xmit_type & XMIT_CSUM_TCP) {
2623 pbd->tcp_pseudo_csum = swab16(tcp_hdr(skb)->check);
2626 s8 fix = SKB_CS_OFF(skb); /* signed! */
2628 DP(NETIF_MSG_TX_QUEUED,
2629 "hlen %d fix %d csum before fix %x\n",
2630 le16_to_cpu(pbd->total_hlen_w), fix, SKB_CS(skb));
2632 /* HW bug: fixup the CSUM */
2633 pbd->tcp_pseudo_csum =
2634 bnx2x_csum_fix(skb_transport_header(skb),
2637 DP(NETIF_MSG_TX_QUEUED, "csum after fix %x\n",
2638 pbd->tcp_pseudo_csum);
2644 /* called with netif_tx_lock
2645 * bnx2x_tx_int() runs without netif_tx_lock unless it needs to call
2646 * netif_wake_queue()
2648 netdev_tx_t bnx2x_start_xmit(struct sk_buff *skb, struct net_device *dev)
2650 struct bnx2x *bp = netdev_priv(dev);
2652 struct bnx2x_fastpath *fp;
2653 struct netdev_queue *txq;
2654 struct bnx2x_fp_txdata *txdata;
2655 struct sw_tx_bd *tx_buf;
2656 struct eth_tx_start_bd *tx_start_bd, *first_bd;
2657 struct eth_tx_bd *tx_data_bd, *total_pkt_bd = NULL;
2658 struct eth_tx_parse_bd_e1x *pbd_e1x = NULL;
2659 struct eth_tx_parse_bd_e2 *pbd_e2 = NULL;
2660 u32 pbd_e2_parsing_data = 0;
2661 u16 pkt_prod, bd_prod;
2662 int nbd, txq_index, fp_index, txdata_index;
2664 u32 xmit_type = bnx2x_xmit_type(bp, skb);
2667 __le16 pkt_size = 0;
2669 u8 mac_type = UNICAST_ADDRESS;
2671 #ifdef BNX2X_STOP_ON_ERROR
2672 if (unlikely(bp->panic))
2673 return NETDEV_TX_BUSY;
2676 txq_index = skb_get_queue_mapping(skb);
2677 txq = netdev_get_tx_queue(dev, txq_index);
2679 BUG_ON(txq_index >= MAX_ETH_TXQ_IDX(bp) + FCOE_PRESENT);
2681 /* decode the fastpath index and the cos index from the txq */
2682 fp_index = TXQ_TO_FP(txq_index);
2683 txdata_index = TXQ_TO_COS(txq_index);
2687 * Override the above for the FCoE queue:
2688 * - FCoE fp entry is right after the ETH entries.
2689 * - FCoE L2 queue uses bp->txdata[0] only.
2691 if (unlikely(!NO_FCOE(bp) && (txq_index ==
2692 bnx2x_fcoe_tx(bp, txq_index)))) {
2693 fp_index = FCOE_IDX;
2698 /* enable this debug print to view the transmission queue being used
2699 DP(NETIF_MSG_TX_QUEUED, "indices: txq %d, fp %d, txdata %d\n",
2700 txq_index, fp_index, txdata_index); */
2702 /* locate the fastpath and the txdata */
2703 fp = &bp->fp[fp_index];
2704 txdata = &fp->txdata[txdata_index];
2706 /* enable this debug print to view the tranmission details
2707 DP(NETIF_MSG_TX_QUEUED,
2708 "transmitting packet cid %d fp index %d txdata_index %d tx_data ptr %p fp pointer %p\n",
2709 txdata->cid, fp_index, txdata_index, txdata, fp); */
2711 if (unlikely(bnx2x_tx_avail(bp, txdata) <
2712 (skb_shinfo(skb)->nr_frags + 3))) {
2713 fp->eth_q_stats.driver_xoff++;
2714 netif_tx_stop_queue(txq);
2715 BNX2X_ERR("BUG! Tx ring full when queue awake!\n");
2716 return NETDEV_TX_BUSY;
2719 DP(NETIF_MSG_TX_QUEUED,
2720 "queue[%d]: SKB: summed %x protocol %x protocol(%x,%x) gso type %x xmit_type %x\n",
2721 txq_index, skb->ip_summed, skb->protocol, ipv6_hdr(skb)->nexthdr,
2722 ip_hdr(skb)->protocol, skb_shinfo(skb)->gso_type, xmit_type);
2724 eth = (struct ethhdr *)skb->data;
2726 /* set flag according to packet type (UNICAST_ADDRESS is default)*/
2727 if (unlikely(is_multicast_ether_addr(eth->h_dest))) {
2728 if (is_broadcast_ether_addr(eth->h_dest))
2729 mac_type = BROADCAST_ADDRESS;
2731 mac_type = MULTICAST_ADDRESS;
2734 #if (MAX_SKB_FRAGS >= MAX_FETCH_BD - 3)
2735 /* First, check if we need to linearize the skb (due to FW
2736 restrictions). No need to check fragmentation if page size > 8K
2737 (there will be no violation to FW restrictions) */
2738 if (bnx2x_pkt_req_lin(bp, skb, xmit_type)) {
2739 /* Statistics of linearization */
2741 if (skb_linearize(skb) != 0) {
2742 DP(NETIF_MSG_TX_QUEUED,
2743 "SKB linearization failed - silently dropping this SKB\n");
2744 dev_kfree_skb_any(skb);
2745 return NETDEV_TX_OK;
2749 /* Map skb linear data for DMA */
2750 mapping = dma_map_single(&bp->pdev->dev, skb->data,
2751 skb_headlen(skb), DMA_TO_DEVICE);
2752 if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
2753 DP(NETIF_MSG_TX_QUEUED,
2754 "SKB mapping failed - silently dropping this SKB\n");
2755 dev_kfree_skb_any(skb);
2756 return NETDEV_TX_OK;
2759 Please read carefully. First we use one BD which we mark as start,
2760 then we have a parsing info BD (used for TSO or xsum),
2761 and only then we have the rest of the TSO BDs.
2762 (don't forget to mark the last one as last,
2763 and to unmap only AFTER you write to the BD ...)
2764 And above all, all pdb sizes are in words - NOT DWORDS!
2767 /* get current pkt produced now - advance it just before sending packet
2768 * since mapping of pages may fail and cause packet to be dropped
2770 pkt_prod = txdata->tx_pkt_prod;
2771 bd_prod = TX_BD(txdata->tx_bd_prod);
2773 /* get a tx_buf and first BD
2774 * tx_start_bd may be changed during SPLIT,
2775 * but first_bd will always stay first
2777 tx_buf = &txdata->tx_buf_ring[TX_BD(pkt_prod)];
2778 tx_start_bd = &txdata->tx_desc_ring[bd_prod].start_bd;
2779 first_bd = tx_start_bd;
2781 tx_start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
2782 SET_FLAG(tx_start_bd->general_data, ETH_TX_START_BD_ETH_ADDR_TYPE,
2786 SET_FLAG(tx_start_bd->general_data, ETH_TX_START_BD_HDR_NBDS, 1);
2788 /* remember the first BD of the packet */
2789 tx_buf->first_bd = txdata->tx_bd_prod;
2793 DP(NETIF_MSG_TX_QUEUED,
2794 "sending pkt %u @%p next_idx %u bd %u @%p\n",
2795 pkt_prod, tx_buf, txdata->tx_pkt_prod, bd_prod, tx_start_bd);
2797 if (vlan_tx_tag_present(skb)) {
2798 tx_start_bd->vlan_or_ethertype =
2799 cpu_to_le16(vlan_tx_tag_get(skb));
2800 tx_start_bd->bd_flags.as_bitfield |=
2801 (X_ETH_OUTBAND_VLAN << ETH_TX_BD_FLAGS_VLAN_MODE_SHIFT);
2803 tx_start_bd->vlan_or_ethertype = cpu_to_le16(pkt_prod);
2805 /* turn on parsing and get a BD */
2806 bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
2808 if (xmit_type & XMIT_CSUM)
2809 bnx2x_set_sbd_csum(bp, skb, tx_start_bd, xmit_type);
2811 if (!CHIP_IS_E1x(bp)) {
2812 pbd_e2 = &txdata->tx_desc_ring[bd_prod].parse_bd_e2;
2813 memset(pbd_e2, 0, sizeof(struct eth_tx_parse_bd_e2));
2814 /* Set PBD in checksum offload case */
2815 if (xmit_type & XMIT_CSUM)
2816 hlen = bnx2x_set_pbd_csum_e2(bp, skb,
2817 &pbd_e2_parsing_data,
2821 * fill in the MAC addresses in the PBD - for local
2824 bnx2x_set_fw_mac_addr(&pbd_e2->src_mac_addr_hi,
2825 &pbd_e2->src_mac_addr_mid,
2826 &pbd_e2->src_mac_addr_lo,
2828 bnx2x_set_fw_mac_addr(&pbd_e2->dst_mac_addr_hi,
2829 &pbd_e2->dst_mac_addr_mid,
2830 &pbd_e2->dst_mac_addr_lo,
2834 pbd_e1x = &txdata->tx_desc_ring[bd_prod].parse_bd_e1x;
2835 memset(pbd_e1x, 0, sizeof(struct eth_tx_parse_bd_e1x));
2836 /* Set PBD in checksum offload case */
2837 if (xmit_type & XMIT_CSUM)
2838 hlen = bnx2x_set_pbd_csum(bp, skb, pbd_e1x, xmit_type);
2842 /* Setup the data pointer of the first BD of the packet */
2843 tx_start_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
2844 tx_start_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
2845 nbd = 2; /* start_bd + pbd + frags (updated when pages are mapped) */
2846 tx_start_bd->nbytes = cpu_to_le16(skb_headlen(skb));
2847 pkt_size = tx_start_bd->nbytes;
2849 DP(NETIF_MSG_TX_QUEUED,
2850 "first bd @%p addr (%x:%x) nbd %d nbytes %d flags %x vlan %x\n",
2851 tx_start_bd, tx_start_bd->addr_hi, tx_start_bd->addr_lo,
2852 le16_to_cpu(tx_start_bd->nbd), le16_to_cpu(tx_start_bd->nbytes),
2853 tx_start_bd->bd_flags.as_bitfield,
2854 le16_to_cpu(tx_start_bd->vlan_or_ethertype));
2856 if (xmit_type & XMIT_GSO) {
2858 DP(NETIF_MSG_TX_QUEUED,
2859 "TSO packet len %d hlen %d total len %d tso size %d\n",
2860 skb->len, hlen, skb_headlen(skb),
2861 skb_shinfo(skb)->gso_size);
2863 tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_SW_LSO;
2865 if (unlikely(skb_headlen(skb) > hlen))
2866 bd_prod = bnx2x_tx_split(bp, txdata, tx_buf,
2869 if (!CHIP_IS_E1x(bp))
2870 bnx2x_set_pbd_gso_e2(skb, &pbd_e2_parsing_data,
2873 bnx2x_set_pbd_gso(skb, pbd_e1x, xmit_type);
2876 /* Set the PBD's parsing_data field if not zero
2877 * (for the chips newer than 57711).
2879 if (pbd_e2_parsing_data)
2880 pbd_e2->parsing_data = cpu_to_le32(pbd_e2_parsing_data);
2882 tx_data_bd = (struct eth_tx_bd *)tx_start_bd;
2884 /* Handle fragmented skb */
2885 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
2886 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
2888 mapping = skb_frag_dma_map(&bp->pdev->dev, frag, 0,
2889 skb_frag_size(frag), DMA_TO_DEVICE);
2890 if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
2891 unsigned int pkts_compl = 0, bytes_compl = 0;
2893 DP(NETIF_MSG_TX_QUEUED,
2894 "Unable to map page - dropping packet...\n");
2896 /* we need unmap all buffers already mapped
2898 * first_bd->nbd need to be properly updated
2899 * before call to bnx2x_free_tx_pkt
2901 first_bd->nbd = cpu_to_le16(nbd);
2902 bnx2x_free_tx_pkt(bp, txdata,
2903 TX_BD(txdata->tx_pkt_prod),
2904 &pkts_compl, &bytes_compl);
2905 return NETDEV_TX_OK;
2908 bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
2909 tx_data_bd = &txdata->tx_desc_ring[bd_prod].reg_bd;
2910 if (total_pkt_bd == NULL)
2911 total_pkt_bd = &txdata->tx_desc_ring[bd_prod].reg_bd;
2913 tx_data_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
2914 tx_data_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
2915 tx_data_bd->nbytes = cpu_to_le16(skb_frag_size(frag));
2916 le16_add_cpu(&pkt_size, skb_frag_size(frag));
2919 DP(NETIF_MSG_TX_QUEUED,
2920 "frag %d bd @%p addr (%x:%x) nbytes %d\n",
2921 i, tx_data_bd, tx_data_bd->addr_hi, tx_data_bd->addr_lo,
2922 le16_to_cpu(tx_data_bd->nbytes));
2925 DP(NETIF_MSG_TX_QUEUED, "last bd @%p\n", tx_data_bd);
2927 /* update with actual num BDs */
2928 first_bd->nbd = cpu_to_le16(nbd);
2930 bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
2932 /* now send a tx doorbell, counting the next BD
2933 * if the packet contains or ends with it
2935 if (TX_BD_POFF(bd_prod) < nbd)
2938 /* total_pkt_bytes should be set on the first data BD if
2939 * it's not an LSO packet and there is more than one
2940 * data BD. In this case pkt_size is limited by an MTU value.
2941 * However we prefer to set it for an LSO packet (while we don't
2942 * have to) in order to save some CPU cycles in a none-LSO
2943 * case, when we much more care about them.
2945 if (total_pkt_bd != NULL)
2946 total_pkt_bd->total_pkt_bytes = pkt_size;
2949 DP(NETIF_MSG_TX_QUEUED,
2950 "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",
2951 pbd_e1x, pbd_e1x->global_data, pbd_e1x->ip_hlen_w,
2952 pbd_e1x->ip_id, pbd_e1x->lso_mss, pbd_e1x->tcp_flags,
2953 pbd_e1x->tcp_pseudo_csum, pbd_e1x->tcp_send_seq,
2954 le16_to_cpu(pbd_e1x->total_hlen_w));
2956 DP(NETIF_MSG_TX_QUEUED,
2957 "PBD (E2) @%p dst %x %x %x src %x %x %x parsing_data %x\n",
2958 pbd_e2, pbd_e2->dst_mac_addr_hi, pbd_e2->dst_mac_addr_mid,
2959 pbd_e2->dst_mac_addr_lo, pbd_e2->src_mac_addr_hi,
2960 pbd_e2->src_mac_addr_mid, pbd_e2->src_mac_addr_lo,
2961 pbd_e2->parsing_data);
2962 DP(NETIF_MSG_TX_QUEUED, "doorbell: nbd %d bd %u\n", nbd, bd_prod);
2964 netdev_tx_sent_queue(txq, skb->len);
2966 txdata->tx_pkt_prod++;
2968 * Make sure that the BD data is updated before updating the producer
2969 * since FW might read the BD right after the producer is updated.
2970 * This is only applicable for weak-ordered memory model archs such
2971 * as IA-64. The following barrier is also mandatory since FW will
2972 * assumes packets must have BDs.
2976 txdata->tx_db.data.prod += nbd;
2979 DOORBELL(bp, txdata->cid, txdata->tx_db.raw);
2983 txdata->tx_bd_prod += nbd;
2985 if (unlikely(bnx2x_tx_avail(bp, txdata) < MAX_SKB_FRAGS + 3)) {
2986 netif_tx_stop_queue(txq);
2988 /* paired memory barrier is in bnx2x_tx_int(), we have to keep
2989 * ordering of set_bit() in netif_tx_stop_queue() and read of
2993 fp->eth_q_stats.driver_xoff++;
2994 if (bnx2x_tx_avail(bp, txdata) >= MAX_SKB_FRAGS + 3)
2995 netif_tx_wake_queue(txq);
2999 return NETDEV_TX_OK;
3003 * bnx2x_setup_tc - routine to configure net_device for multi tc
3005 * @netdev: net device to configure
3006 * @tc: number of traffic classes to enable
3008 * callback connected to the ndo_setup_tc function pointer
3010 int bnx2x_setup_tc(struct net_device *dev, u8 num_tc)
3012 int cos, prio, count, offset;
3013 struct bnx2x *bp = netdev_priv(dev);
3015 /* setup tc must be called under rtnl lock */
3018 /* no traffic classes requested. aborting */
3020 netdev_reset_tc(dev);
3024 /* requested to support too many traffic classes */
3025 if (num_tc > bp->max_cos) {
3026 BNX2X_ERR("support for too many traffic classes requested: %d. max supported is %d\n",
3027 num_tc, bp->max_cos);
3031 /* declare amount of supported traffic classes */
3032 if (netdev_set_num_tc(dev, num_tc)) {
3033 BNX2X_ERR("failed to declare %d traffic classes\n", num_tc);
3037 /* configure priority to traffic class mapping */
3038 for (prio = 0; prio < BNX2X_MAX_PRIORITY; prio++) {
3039 netdev_set_prio_tc_map(dev, prio, bp->prio_to_cos[prio]);
3040 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
3041 "mapping priority %d to tc %d\n",
3042 prio, bp->prio_to_cos[prio]);
3046 /* Use this configuration to diffrentiate tc0 from other COSes
3047 This can be used for ets or pfc, and save the effort of setting
3048 up a multio class queue disc or negotiating DCBX with a switch
3049 netdev_set_prio_tc_map(dev, 0, 0);
3050 DP(BNX2X_MSG_SP, "mapping priority %d to tc %d\n", 0, 0);
3051 for (prio = 1; prio < 16; prio++) {
3052 netdev_set_prio_tc_map(dev, prio, 1);
3053 DP(BNX2X_MSG_SP, "mapping priority %d to tc %d\n", prio, 1);
3056 /* configure traffic class to transmission queue mapping */
3057 for (cos = 0; cos < bp->max_cos; cos++) {
3058 count = BNX2X_NUM_ETH_QUEUES(bp);
3059 offset = cos * MAX_TXQS_PER_COS;
3060 netdev_set_tc_queue(dev, cos, count, offset);
3061 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
3062 "mapping tc %d to offset %d count %d\n",
3063 cos, offset, count);
3069 /* called with rtnl_lock */
3070 int bnx2x_change_mac_addr(struct net_device *dev, void *p)
3072 struct sockaddr *addr = p;
3073 struct bnx2x *bp = netdev_priv(dev);
3076 if (!bnx2x_is_valid_ether_addr(bp, addr->sa_data)) {
3077 BNX2X_ERR("Requested MAC address is not valid\n");
3082 if ((IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp)) &&
3083 !is_zero_ether_addr(addr->sa_data)) {
3084 BNX2X_ERR("Can't configure non-zero address on iSCSI or FCoE functions in MF-SD mode\n");
3089 if (netif_running(dev)) {
3090 rc = bnx2x_set_eth_mac(bp, false);
3095 dev->addr_assign_type &= ~NET_ADDR_RANDOM;
3096 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
3098 if (netif_running(dev))
3099 rc = bnx2x_set_eth_mac(bp, true);
3104 static void bnx2x_free_fp_mem_at(struct bnx2x *bp, int fp_index)
3106 union host_hc_status_block *sb = &bnx2x_fp(bp, fp_index, status_blk);
3107 struct bnx2x_fastpath *fp = &bp->fp[fp_index];
3112 if (IS_FCOE_IDX(fp_index)) {
3113 memset(sb, 0, sizeof(union host_hc_status_block));
3114 fp->status_blk_mapping = 0;
3119 if (!CHIP_IS_E1x(bp))
3120 BNX2X_PCI_FREE(sb->e2_sb,
3121 bnx2x_fp(bp, fp_index,
3122 status_blk_mapping),
3123 sizeof(struct host_hc_status_block_e2));
3125 BNX2X_PCI_FREE(sb->e1x_sb,
3126 bnx2x_fp(bp, fp_index,
3127 status_blk_mapping),
3128 sizeof(struct host_hc_status_block_e1x));
3133 if (!skip_rx_queue(bp, fp_index)) {
3134 bnx2x_free_rx_bds(fp);
3136 /* fastpath rx rings: rx_buf rx_desc rx_comp */
3137 BNX2X_FREE(bnx2x_fp(bp, fp_index, rx_buf_ring));
3138 BNX2X_PCI_FREE(bnx2x_fp(bp, fp_index, rx_desc_ring),
3139 bnx2x_fp(bp, fp_index, rx_desc_mapping),
3140 sizeof(struct eth_rx_bd) * NUM_RX_BD);
3142 BNX2X_PCI_FREE(bnx2x_fp(bp, fp_index, rx_comp_ring),
3143 bnx2x_fp(bp, fp_index, rx_comp_mapping),
3144 sizeof(struct eth_fast_path_rx_cqe) *
3148 BNX2X_FREE(bnx2x_fp(bp, fp_index, rx_page_ring));
3149 BNX2X_PCI_FREE(bnx2x_fp(bp, fp_index, rx_sge_ring),
3150 bnx2x_fp(bp, fp_index, rx_sge_mapping),
3151 BCM_PAGE_SIZE * NUM_RX_SGE_PAGES);
3155 if (!skip_tx_queue(bp, fp_index)) {
3156 /* fastpath tx rings: tx_buf tx_desc */
3157 for_each_cos_in_tx_queue(fp, cos) {
3158 struct bnx2x_fp_txdata *txdata = &fp->txdata[cos];
3160 DP(NETIF_MSG_IFDOWN,
3161 "freeing tx memory of fp %d cos %d cid %d\n",
3162 fp_index, cos, txdata->cid);
3164 BNX2X_FREE(txdata->tx_buf_ring);
3165 BNX2X_PCI_FREE(txdata->tx_desc_ring,
3166 txdata->tx_desc_mapping,
3167 sizeof(union eth_tx_bd_types) * NUM_TX_BD);
3170 /* end of fastpath */
3173 void bnx2x_free_fp_mem(struct bnx2x *bp)
3176 for_each_queue(bp, i)
3177 bnx2x_free_fp_mem_at(bp, i);
3180 static inline void set_sb_shortcuts(struct bnx2x *bp, int index)
3182 union host_hc_status_block status_blk = bnx2x_fp(bp, index, status_blk);
3183 if (!CHIP_IS_E1x(bp)) {
3184 bnx2x_fp(bp, index, sb_index_values) =
3185 (__le16 *)status_blk.e2_sb->sb.index_values;
3186 bnx2x_fp(bp, index, sb_running_index) =
3187 (__le16 *)status_blk.e2_sb->sb.running_index;
3189 bnx2x_fp(bp, index, sb_index_values) =
3190 (__le16 *)status_blk.e1x_sb->sb.index_values;
3191 bnx2x_fp(bp, index, sb_running_index) =
3192 (__le16 *)status_blk.e1x_sb->sb.running_index;
3196 static int bnx2x_alloc_fp_mem_at(struct bnx2x *bp, int index)
3198 union host_hc_status_block *sb;
3199 struct bnx2x_fastpath *fp = &bp->fp[index];
3202 int rx_ring_size = 0;
3205 if (!bp->rx_ring_size &&
3206 (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
3207 rx_ring_size = MIN_RX_SIZE_NONTPA;
3208 bp->rx_ring_size = rx_ring_size;
3211 if (!bp->rx_ring_size) {
3212 u32 cfg = SHMEM_RD(bp,
3213 dev_info.port_hw_config[BP_PORT(bp)].default_cfg);
3215 rx_ring_size = MAX_RX_AVAIL/BNX2X_NUM_RX_QUEUES(bp);
3217 /* Dercease ring size for 1G functions */
3218 if ((cfg & PORT_HW_CFG_NET_SERDES_IF_MASK) ==
3219 PORT_HW_CFG_NET_SERDES_IF_SGMII)
3222 /* allocate at least number of buffers required by FW */
3223 rx_ring_size = max_t(int, bp->disable_tpa ? MIN_RX_SIZE_NONTPA :
3224 MIN_RX_SIZE_TPA, rx_ring_size);
3226 bp->rx_ring_size = rx_ring_size;
3227 } else /* if rx_ring_size specified - use it */
3228 rx_ring_size = bp->rx_ring_size;
3231 sb = &bnx2x_fp(bp, index, status_blk);
3233 if (!IS_FCOE_IDX(index)) {
3236 if (!CHIP_IS_E1x(bp))
3237 BNX2X_PCI_ALLOC(sb->e2_sb,
3238 &bnx2x_fp(bp, index, status_blk_mapping),
3239 sizeof(struct host_hc_status_block_e2));
3241 BNX2X_PCI_ALLOC(sb->e1x_sb,
3242 &bnx2x_fp(bp, index, status_blk_mapping),
3243 sizeof(struct host_hc_status_block_e1x));
3248 /* FCoE Queue uses Default SB and doesn't ACK the SB, thus no need to
3249 * set shortcuts for it.
3251 if (!IS_FCOE_IDX(index))
3252 set_sb_shortcuts(bp, index);
3255 if (!skip_tx_queue(bp, index)) {
3256 /* fastpath tx rings: tx_buf tx_desc */
3257 for_each_cos_in_tx_queue(fp, cos) {
3258 struct bnx2x_fp_txdata *txdata = &fp->txdata[cos];
3261 "allocating tx memory of fp %d cos %d\n",
3264 BNX2X_ALLOC(txdata->tx_buf_ring,
3265 sizeof(struct sw_tx_bd) * NUM_TX_BD);
3266 BNX2X_PCI_ALLOC(txdata->tx_desc_ring,
3267 &txdata->tx_desc_mapping,
3268 sizeof(union eth_tx_bd_types) * NUM_TX_BD);
3273 if (!skip_rx_queue(bp, index)) {
3274 /* fastpath rx rings: rx_buf rx_desc rx_comp */
3275 BNX2X_ALLOC(bnx2x_fp(bp, index, rx_buf_ring),
3276 sizeof(struct sw_rx_bd) * NUM_RX_BD);
3277 BNX2X_PCI_ALLOC(bnx2x_fp(bp, index, rx_desc_ring),
3278 &bnx2x_fp(bp, index, rx_desc_mapping),
3279 sizeof(struct eth_rx_bd) * NUM_RX_BD);
3281 BNX2X_PCI_ALLOC(bnx2x_fp(bp, index, rx_comp_ring),
3282 &bnx2x_fp(bp, index, rx_comp_mapping),
3283 sizeof(struct eth_fast_path_rx_cqe) *
3287 BNX2X_ALLOC(bnx2x_fp(bp, index, rx_page_ring),
3288 sizeof(struct sw_rx_page) * NUM_RX_SGE);
3289 BNX2X_PCI_ALLOC(bnx2x_fp(bp, index, rx_sge_ring),
3290 &bnx2x_fp(bp, index, rx_sge_mapping),
3291 BCM_PAGE_SIZE * NUM_RX_SGE_PAGES);
3293 bnx2x_set_next_page_rx_bd(fp);
3296 bnx2x_set_next_page_rx_cq(fp);
3299 ring_size = bnx2x_alloc_rx_bds(fp, rx_ring_size);
3300 if (ring_size < rx_ring_size)
3306 /* handles low memory cases */
3308 BNX2X_ERR("Unable to allocate full memory for queue %d (size %d)\n",
3310 /* FW will drop all packets if queue is not big enough,
3311 * In these cases we disable the queue
3312 * Min size is different for OOO, TPA and non-TPA queues
3314 if (ring_size < (fp->disable_tpa ?
3315 MIN_RX_SIZE_NONTPA : MIN_RX_SIZE_TPA)) {
3316 /* release memory allocated for this queue */
3317 bnx2x_free_fp_mem_at(bp, index);
3323 int bnx2x_alloc_fp_mem(struct bnx2x *bp)
3328 * 1. Allocate FP for leading - fatal if error
3329 * 2. {CNIC} Allocate FCoE FP - fatal if error
3330 * 3. {CNIC} Allocate OOO + FWD - disable OOO if error
3331 * 4. Allocate RSS - fix number of queues if error
3335 if (bnx2x_alloc_fp_mem_at(bp, 0))
3341 if (bnx2x_alloc_fp_mem_at(bp, FCOE_IDX))
3342 /* we will fail load process instead of mark
3349 for_each_nondefault_eth_queue(bp, i)
3350 if (bnx2x_alloc_fp_mem_at(bp, i))
3353 /* handle memory failures */
3354 if (i != BNX2X_NUM_ETH_QUEUES(bp)) {
3355 int delta = BNX2X_NUM_ETH_QUEUES(bp) - i;
3360 * move non eth FPs next to last eth FP
3361 * must be done in that order
3362 * FCOE_IDX < FWD_IDX < OOO_IDX
3365 /* move FCoE fp even NO_FCOE_FLAG is on */
3366 bnx2x_move_fp(bp, FCOE_IDX, FCOE_IDX - delta);
3368 bp->num_queues -= delta;
3369 BNX2X_ERR("Adjusted num of queues from %d to %d\n",
3370 bp->num_queues + delta, bp->num_queues);
3376 void bnx2x_free_mem_bp(struct bnx2x *bp)
3379 kfree(bp->msix_table);
3383 int __devinit bnx2x_alloc_mem_bp(struct bnx2x *bp)
3385 struct bnx2x_fastpath *fp;
3386 struct msix_entry *tbl;
3387 struct bnx2x_ilt *ilt;
3388 int msix_table_size = 0;
3391 * The biggest MSI-X table we might need is as a maximum number of fast
3392 * path IGU SBs plus default SB (for PF).
3394 msix_table_size = bp->igu_sb_cnt + 1;
3396 /* fp array: RSS plus CNIC related L2 queues */
3397 fp = kcalloc(BNX2X_MAX_RSS_COUNT(bp) + NON_ETH_CONTEXT_USE,
3398 sizeof(*fp), GFP_KERNEL);
3404 tbl = kcalloc(msix_table_size, sizeof(*tbl), GFP_KERNEL);
3407 bp->msix_table = tbl;
3410 ilt = kzalloc(sizeof(*ilt), GFP_KERNEL);
3417 bnx2x_free_mem_bp(bp);
3422 int bnx2x_reload_if_running(struct net_device *dev)
3424 struct bnx2x *bp = netdev_priv(dev);
3426 if (unlikely(!netif_running(dev)))
3429 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
3430 return bnx2x_nic_load(bp, LOAD_NORMAL);
3433 int bnx2x_get_cur_phy_idx(struct bnx2x *bp)
3435 u32 sel_phy_idx = 0;
3436 if (bp->link_params.num_phys <= 1)
3439 if (bp->link_vars.link_up) {
3440 sel_phy_idx = EXT_PHY1;
3441 /* In case link is SERDES, check if the EXT_PHY2 is the one */
3442 if ((bp->link_vars.link_status & LINK_STATUS_SERDES_LINK) &&
3443 (bp->link_params.phy[EXT_PHY2].supported & SUPPORTED_FIBRE))
3444 sel_phy_idx = EXT_PHY2;
3447 switch (bnx2x_phy_selection(&bp->link_params)) {
3448 case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
3449 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
3450 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
3451 sel_phy_idx = EXT_PHY1;
3453 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
3454 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
3455 sel_phy_idx = EXT_PHY2;
3463 int bnx2x_get_link_cfg_idx(struct bnx2x *bp)
3465 u32 sel_phy_idx = bnx2x_get_cur_phy_idx(bp);
3467 * The selected actived PHY is always after swapping (in case PHY
3468 * swapping is enabled). So when swapping is enabled, we need to reverse
3472 if (bp->link_params.multi_phy_config &
3473 PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
3474 if (sel_phy_idx == EXT_PHY1)
3475 sel_phy_idx = EXT_PHY2;
3476 else if (sel_phy_idx == EXT_PHY2)
3477 sel_phy_idx = EXT_PHY1;
3479 return LINK_CONFIG_IDX(sel_phy_idx);
3482 #if defined(NETDEV_FCOE_WWNN) && defined(BCM_CNIC)
3483 int bnx2x_fcoe_get_wwn(struct net_device *dev, u64 *wwn, int type)
3485 struct bnx2x *bp = netdev_priv(dev);
3486 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
3489 case NETDEV_FCOE_WWNN:
3490 *wwn = HILO_U64(cp->fcoe_wwn_node_name_hi,
3491 cp->fcoe_wwn_node_name_lo);
3493 case NETDEV_FCOE_WWPN:
3494 *wwn = HILO_U64(cp->fcoe_wwn_port_name_hi,
3495 cp->fcoe_wwn_port_name_lo);
3498 BNX2X_ERR("Wrong WWN type requested - %d\n", type);
3506 /* called with rtnl_lock */
3507 int bnx2x_change_mtu(struct net_device *dev, int new_mtu)
3509 struct bnx2x *bp = netdev_priv(dev);
3511 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
3512 BNX2X_ERR("Can't perform change MTU during parity recovery\n");
3516 if ((new_mtu > ETH_MAX_JUMBO_PACKET_SIZE) ||
3517 ((new_mtu + ETH_HLEN) < ETH_MIN_PACKET_SIZE)) {
3518 BNX2X_ERR("Can't support requested MTU size\n");
3522 /* This does not race with packet allocation
3523 * because the actual alloc size is
3524 * only updated as part of load
3528 bp->gro_check = bnx2x_need_gro_check(new_mtu);
3530 return bnx2x_reload_if_running(dev);
3533 netdev_features_t bnx2x_fix_features(struct net_device *dev,
3534 netdev_features_t features)
3536 struct bnx2x *bp = netdev_priv(dev);
3538 /* TPA requires Rx CSUM offloading */
3539 if (!(features & NETIF_F_RXCSUM) || bp->disable_tpa) {
3540 features &= ~NETIF_F_LRO;
3541 features &= ~NETIF_F_GRO;
3547 int bnx2x_set_features(struct net_device *dev, netdev_features_t features)
3549 struct bnx2x *bp = netdev_priv(dev);
3550 u32 flags = bp->flags;
3551 bool bnx2x_reload = false;
3553 if (features & NETIF_F_LRO)
3554 flags |= TPA_ENABLE_FLAG;
3556 flags &= ~TPA_ENABLE_FLAG;
3558 if (features & NETIF_F_GRO)
3559 flags |= GRO_ENABLE_FLAG;
3561 flags &= ~GRO_ENABLE_FLAG;
3563 if (features & NETIF_F_LOOPBACK) {
3564 if (bp->link_params.loopback_mode != LOOPBACK_BMAC) {
3565 bp->link_params.loopback_mode = LOOPBACK_BMAC;
3566 bnx2x_reload = true;
3569 if (bp->link_params.loopback_mode != LOOPBACK_NONE) {
3570 bp->link_params.loopback_mode = LOOPBACK_NONE;
3571 bnx2x_reload = true;
3575 if (flags ^ bp->flags) {
3577 bnx2x_reload = true;
3581 if (bp->recovery_state == BNX2X_RECOVERY_DONE)
3582 return bnx2x_reload_if_running(dev);
3583 /* else: bnx2x_nic_load() will be called at end of recovery */
3589 void bnx2x_tx_timeout(struct net_device *dev)
3591 struct bnx2x *bp = netdev_priv(dev);
3593 #ifdef BNX2X_STOP_ON_ERROR
3598 smp_mb__before_clear_bit();
3599 set_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state);
3600 smp_mb__after_clear_bit();
3602 /* This allows the netif to be shutdown gracefully before resetting */
3603 schedule_delayed_work(&bp->sp_rtnl_task, 0);
3606 int bnx2x_suspend(struct pci_dev *pdev, pm_message_t state)
3608 struct net_device *dev = pci_get_drvdata(pdev);
3612 dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
3615 bp = netdev_priv(dev);
3619 pci_save_state(pdev);
3621 if (!netif_running(dev)) {
3626 netif_device_detach(dev);
3628 bnx2x_nic_unload(bp, UNLOAD_CLOSE);
3630 bnx2x_set_power_state(bp, pci_choose_state(pdev, state));
3637 int bnx2x_resume(struct pci_dev *pdev)
3639 struct net_device *dev = pci_get_drvdata(pdev);
3644 dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
3647 bp = netdev_priv(dev);
3649 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
3650 BNX2X_ERR("Handling parity error recovery. Try again later\n");
3656 pci_restore_state(pdev);
3658 if (!netif_running(dev)) {
3663 bnx2x_set_power_state(bp, PCI_D0);
3664 netif_device_attach(dev);
3666 rc = bnx2x_nic_load(bp, LOAD_OPEN);
3674 void bnx2x_set_ctx_validation(struct bnx2x *bp, struct eth_context *cxt,
3677 /* ustorm cxt validation */
3678 cxt->ustorm_ag_context.cdu_usage =
3679 CDU_RSRVD_VALUE_TYPE_A(HW_CID(bp, cid),
3680 CDU_REGION_NUMBER_UCM_AG, ETH_CONNECTION_TYPE);
3681 /* xcontext validation */
3682 cxt->xstorm_ag_context.cdu_reserved =
3683 CDU_RSRVD_VALUE_TYPE_A(HW_CID(bp, cid),
3684 CDU_REGION_NUMBER_XCM_AG, ETH_CONNECTION_TYPE);
3687 static inline void storm_memset_hc_timeout(struct bnx2x *bp, u8 port,
3688 u8 fw_sb_id, u8 sb_index,
3692 u32 addr = BAR_CSTRORM_INTMEM +
3693 CSTORM_STATUS_BLOCK_DATA_TIMEOUT_OFFSET(fw_sb_id, sb_index);
3694 REG_WR8(bp, addr, ticks);
3696 "port %x fw_sb_id %d sb_index %d ticks %d\n",
3697 port, fw_sb_id, sb_index, ticks);
3700 static inline void storm_memset_hc_disable(struct bnx2x *bp, u8 port,
3701 u16 fw_sb_id, u8 sb_index,
3704 u32 enable_flag = disable ? 0 : (1 << HC_INDEX_DATA_HC_ENABLED_SHIFT);
3705 u32 addr = BAR_CSTRORM_INTMEM +
3706 CSTORM_STATUS_BLOCK_DATA_FLAGS_OFFSET(fw_sb_id, sb_index);
3707 u16 flags = REG_RD16(bp, addr);
3709 flags &= ~HC_INDEX_DATA_HC_ENABLED;
3710 flags |= enable_flag;
3711 REG_WR16(bp, addr, flags);
3713 "port %x fw_sb_id %d sb_index %d disable %d\n",
3714 port, fw_sb_id, sb_index, disable);
3717 void bnx2x_update_coalesce_sb_index(struct bnx2x *bp, u8 fw_sb_id,
3718 u8 sb_index, u8 disable, u16 usec)
3720 int port = BP_PORT(bp);
3721 u8 ticks = usec / BNX2X_BTR;
3723 storm_memset_hc_timeout(bp, port, fw_sb_id, sb_index, ticks);
3725 disable = disable ? 1 : (usec ? 0 : 1);
3726 storm_memset_hc_disable(bp, port, fw_sb_id, sb_index, disable);