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 mode */
1471 if (IS_MF_STORAGE_SD(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));
1905 bp->state = BNX2X_STATE_OPENING_WAIT4_PORT;
1906 rc = bnx2x_func_start(bp);
1908 BNX2X_ERR("Function start failed!\n");
1909 bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
1910 LOAD_ERROR_EXIT(bp, load_error3);
1913 /* Send LOAD_DONE command to MCP */
1914 if (!BP_NOMCP(bp)) {
1915 load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
1917 BNX2X_ERR("MCP response failure, aborting\n");
1919 LOAD_ERROR_EXIT(bp, load_error3);
1923 rc = bnx2x_setup_leading(bp);
1925 BNX2X_ERR("Setup leading failed!\n");
1926 LOAD_ERROR_EXIT(bp, load_error3);
1930 /* Enable Timer scan */
1931 REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 1);
1934 for_each_nondefault_queue(bp, i) {
1935 rc = bnx2x_setup_queue(bp, &bp->fp[i], 0);
1937 BNX2X_ERR("Queue setup failed\n");
1938 LOAD_ERROR_EXIT(bp, load_error4);
1942 rc = bnx2x_init_rss_pf(bp);
1944 BNX2X_ERR("PF RSS init failed\n");
1945 LOAD_ERROR_EXIT(bp, load_error4);
1948 /* Now when Clients are configured we are ready to work */
1949 bp->state = BNX2X_STATE_OPEN;
1951 /* Configure a ucast MAC */
1952 rc = bnx2x_set_eth_mac(bp, true);
1954 BNX2X_ERR("Setting Ethernet MAC failed\n");
1955 LOAD_ERROR_EXIT(bp, load_error4);
1958 if (bp->pending_max) {
1959 bnx2x_update_max_mf_config(bp, bp->pending_max);
1960 bp->pending_max = 0;
1964 bnx2x_initial_phy_init(bp, load_mode);
1966 /* Start fast path */
1968 /* Initialize Rx filter. */
1969 netif_addr_lock_bh(bp->dev);
1970 bnx2x_set_rx_mode(bp->dev);
1971 netif_addr_unlock_bh(bp->dev);
1974 switch (load_mode) {
1976 /* Tx queue should be only reenabled */
1977 netif_tx_wake_all_queues(bp->dev);
1981 netif_tx_start_all_queues(bp->dev);
1982 smp_mb__after_clear_bit();
1986 bp->state = BNX2X_STATE_DIAG;
1994 bnx2x_update_drv_flags(bp, 1 << DRV_FLAGS_DCB_CONFIGURED, 0);
1996 bnx2x__link_status_update(bp);
1998 /* start the timer */
1999 mod_timer(&bp->timer, jiffies + bp->current_interval);
2002 /* re-read iscsi info */
2003 bnx2x_get_iscsi_info(bp);
2004 bnx2x_setup_cnic_irq_info(bp);
2005 if (bp->state == BNX2X_STATE_OPEN)
2006 bnx2x_cnic_notify(bp, CNIC_CTL_START_CMD);
2009 /* mark driver is loaded in shmem2 */
2010 if (SHMEM2_HAS(bp, drv_capabilities_flag)) {
2012 val = SHMEM2_RD(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
2013 SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
2014 val | DRV_FLAGS_CAPABILITIES_LOADED_SUPPORTED |
2015 DRV_FLAGS_CAPABILITIES_LOADED_L2);
2018 /* Wait for all pending SP commands to complete */
2019 if (!bnx2x_wait_sp_comp(bp, ~0x0UL)) {
2020 BNX2X_ERR("Timeout waiting for SP elements to complete\n");
2021 bnx2x_nic_unload(bp, UNLOAD_CLOSE);
2025 bnx2x_dcbx_init(bp);
2028 #ifndef BNX2X_STOP_ON_ERROR
2031 /* Disable Timer scan */
2032 REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
2035 bnx2x_int_disable_sync(bp, 1);
2037 /* Clean queueable objects */
2038 bnx2x_squeeze_objects(bp);
2040 /* Free SKBs, SGEs, TPA pool and driver internals */
2041 bnx2x_free_skbs(bp);
2042 for_each_rx_queue(bp, i)
2043 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
2048 if (!BP_NOMCP(bp)) {
2049 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
2050 bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
2055 bnx2x_napi_disable(bp);
2056 /* clear pf_load status, as it was already set */
2057 bnx2x_clear_pf_load(bp);
2062 #endif /* ! BNX2X_STOP_ON_ERROR */
2065 /* must be called with rtnl_lock */
2066 int bnx2x_nic_unload(struct bnx2x *bp, int unload_mode)
2069 bool global = false;
2071 /* mark driver is unloaded in shmem2 */
2072 if (SHMEM2_HAS(bp, drv_capabilities_flag)) {
2074 val = SHMEM2_RD(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
2075 SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
2076 val & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
2079 if ((bp->state == BNX2X_STATE_CLOSED) ||
2080 (bp->state == BNX2X_STATE_ERROR)) {
2081 /* We can get here if the driver has been unloaded
2082 * during parity error recovery and is either waiting for a
2083 * leader to complete or for other functions to unload and
2084 * then ifdown has been issued. In this case we want to
2085 * unload and let other functions to complete a recovery
2088 bp->recovery_state = BNX2X_RECOVERY_DONE;
2090 bnx2x_release_leader_lock(bp);
2093 DP(NETIF_MSG_IFDOWN, "Releasing a leadership...\n");
2094 BNX2X_ERR("Can't unload in closed or error state\n");
2099 * It's important to set the bp->state to the value different from
2100 * BNX2X_STATE_OPEN and only then stop the Tx. Otherwise bnx2x_tx_int()
2101 * may restart the Tx from the NAPI context (see bnx2x_tx_int()).
2103 bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
2107 bnx2x_tx_disable(bp);
2110 bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
2113 bp->rx_mode = BNX2X_RX_MODE_NONE;
2115 del_timer_sync(&bp->timer);
2117 /* Set ALWAYS_ALIVE bit in shmem */
2118 bp->fw_drv_pulse_wr_seq |= DRV_PULSE_ALWAYS_ALIVE;
2120 bnx2x_drv_pulse(bp);
2122 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
2123 bnx2x_save_statistics(bp);
2125 /* Cleanup the chip if needed */
2126 if (unload_mode != UNLOAD_RECOVERY)
2127 bnx2x_chip_cleanup(bp, unload_mode);
2129 /* Send the UNLOAD_REQUEST to the MCP */
2130 bnx2x_send_unload_req(bp, unload_mode);
2133 * Prevent transactions to host from the functions on the
2134 * engine that doesn't reset global blocks in case of global
2135 * attention once gloabl blocks are reset and gates are opened
2136 * (the engine which leader will perform the recovery
2139 if (!CHIP_IS_E1x(bp))
2140 bnx2x_pf_disable(bp);
2142 /* Disable HW interrupts, NAPI */
2143 bnx2x_netif_stop(bp, 1);
2148 /* Report UNLOAD_DONE to MCP */
2149 bnx2x_send_unload_done(bp);
2153 * At this stage no more interrupts will arrive so we may safly clean
2154 * the queueable objects here in case they failed to get cleaned so far.
2156 bnx2x_squeeze_objects(bp);
2158 /* There should be no more pending SP commands at this stage */
2163 /* Free SKBs, SGEs, TPA pool and driver internals */
2164 bnx2x_free_skbs(bp);
2165 for_each_rx_queue(bp, i)
2166 bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
2170 bp->state = BNX2X_STATE_CLOSED;
2172 /* Check if there are pending parity attentions. If there are - set
2173 * RECOVERY_IN_PROGRESS.
2175 if (bnx2x_chk_parity_attn(bp, &global, false)) {
2176 bnx2x_set_reset_in_progress(bp);
2178 /* Set RESET_IS_GLOBAL if needed */
2180 bnx2x_set_reset_global(bp);
2184 /* The last driver must disable a "close the gate" if there is no
2185 * parity attention or "process kill" pending.
2187 if (!bnx2x_clear_pf_load(bp) && bnx2x_reset_is_done(bp, BP_PATH(bp)))
2188 bnx2x_disable_close_the_gate(bp);
2193 int bnx2x_set_power_state(struct bnx2x *bp, pci_power_t state)
2197 /* If there is no power capability, silently succeed */
2199 BNX2X_DEV_INFO("No power capability. Breaking.\n");
2203 pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmcsr);
2207 pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
2208 ((pmcsr & ~PCI_PM_CTRL_STATE_MASK) |
2209 PCI_PM_CTRL_PME_STATUS));
2211 if (pmcsr & PCI_PM_CTRL_STATE_MASK)
2212 /* delay required during transition out of D3hot */
2217 /* If there are other clients above don't
2218 shut down the power */
2219 if (atomic_read(&bp->pdev->enable_cnt) != 1)
2221 /* Don't shut down the power for emulation and FPGA */
2222 if (CHIP_REV_IS_SLOW(bp))
2225 pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
2229 pmcsr |= PCI_PM_CTRL_PME_ENABLE;
2231 pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
2234 /* No more memory access after this point until
2235 * device is brought back to D0.
2240 dev_err(&bp->pdev->dev, "Can't support state = %d\n", state);
2247 * net_device service functions
2249 int bnx2x_poll(struct napi_struct *napi, int budget)
2253 struct bnx2x_fastpath *fp = container_of(napi, struct bnx2x_fastpath,
2255 struct bnx2x *bp = fp->bp;
2258 #ifdef BNX2X_STOP_ON_ERROR
2259 if (unlikely(bp->panic)) {
2260 napi_complete(napi);
2265 for_each_cos_in_tx_queue(fp, cos)
2266 if (bnx2x_tx_queue_has_work(&fp->txdata[cos]))
2267 bnx2x_tx_int(bp, &fp->txdata[cos]);
2270 if (bnx2x_has_rx_work(fp)) {
2271 work_done += bnx2x_rx_int(fp, budget - work_done);
2273 /* must not complete if we consumed full budget */
2274 if (work_done >= budget)
2278 /* Fall out from the NAPI loop if needed */
2279 if (!(bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
2281 /* No need to update SB for FCoE L2 ring as long as
2282 * it's connected to the default SB and the SB
2283 * has been updated when NAPI was scheduled.
2285 if (IS_FCOE_FP(fp)) {
2286 napi_complete(napi);
2291 bnx2x_update_fpsb_idx(fp);
2292 /* bnx2x_has_rx_work() reads the status block,
2293 * thus we need to ensure that status block indices
2294 * have been actually read (bnx2x_update_fpsb_idx)
2295 * prior to this check (bnx2x_has_rx_work) so that
2296 * we won't write the "newer" value of the status block
2297 * to IGU (if there was a DMA right after
2298 * bnx2x_has_rx_work and if there is no rmb, the memory
2299 * reading (bnx2x_update_fpsb_idx) may be postponed
2300 * to right before bnx2x_ack_sb). In this case there
2301 * will never be another interrupt until there is
2302 * another update of the status block, while there
2303 * is still unhandled work.
2307 if (!(bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
2308 napi_complete(napi);
2309 /* Re-enable interrupts */
2310 DP(NETIF_MSG_RX_STATUS,
2311 "Update index to %d\n", fp->fp_hc_idx);
2312 bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID,
2313 le16_to_cpu(fp->fp_hc_idx),
2323 /* we split the first BD into headers and data BDs
2324 * to ease the pain of our fellow microcode engineers
2325 * we use one mapping for both BDs
2326 * So far this has only been observed to happen
2327 * in Other Operating Systems(TM)
2329 static noinline u16 bnx2x_tx_split(struct bnx2x *bp,
2330 struct bnx2x_fp_txdata *txdata,
2331 struct sw_tx_bd *tx_buf,
2332 struct eth_tx_start_bd **tx_bd, u16 hlen,
2333 u16 bd_prod, int nbd)
2335 struct eth_tx_start_bd *h_tx_bd = *tx_bd;
2336 struct eth_tx_bd *d_tx_bd;
2338 int old_len = le16_to_cpu(h_tx_bd->nbytes);
2340 /* first fix first BD */
2341 h_tx_bd->nbd = cpu_to_le16(nbd);
2342 h_tx_bd->nbytes = cpu_to_le16(hlen);
2344 DP(NETIF_MSG_TX_QUEUED, "TSO split header size is %d (%x:%x) nbd %d\n",
2345 h_tx_bd->nbytes, h_tx_bd->addr_hi, h_tx_bd->addr_lo, h_tx_bd->nbd);
2347 /* now get a new data BD
2348 * (after the pbd) and fill it */
2349 bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
2350 d_tx_bd = &txdata->tx_desc_ring[bd_prod].reg_bd;
2352 mapping = HILO_U64(le32_to_cpu(h_tx_bd->addr_hi),
2353 le32_to_cpu(h_tx_bd->addr_lo)) + hlen;
2355 d_tx_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
2356 d_tx_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
2357 d_tx_bd->nbytes = cpu_to_le16(old_len - hlen);
2359 /* this marks the BD as one that has no individual mapping */
2360 tx_buf->flags |= BNX2X_TSO_SPLIT_BD;
2362 DP(NETIF_MSG_TX_QUEUED,
2363 "TSO split data size is %d (%x:%x)\n",
2364 d_tx_bd->nbytes, d_tx_bd->addr_hi, d_tx_bd->addr_lo);
2367 *tx_bd = (struct eth_tx_start_bd *)d_tx_bd;
2372 static inline u16 bnx2x_csum_fix(unsigned char *t_header, u16 csum, s8 fix)
2375 csum = (u16) ~csum_fold(csum_sub(csum,
2376 csum_partial(t_header - fix, fix, 0)));
2379 csum = (u16) ~csum_fold(csum_add(csum,
2380 csum_partial(t_header, -fix, 0)));
2382 return swab16(csum);
2385 static inline u32 bnx2x_xmit_type(struct bnx2x *bp, struct sk_buff *skb)
2389 if (skb->ip_summed != CHECKSUM_PARTIAL)
2393 if (vlan_get_protocol(skb) == htons(ETH_P_IPV6)) {
2395 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
2396 rc |= XMIT_CSUM_TCP;
2400 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
2401 rc |= XMIT_CSUM_TCP;
2405 if (skb_is_gso_v6(skb))
2406 rc |= XMIT_GSO_V6 | XMIT_CSUM_TCP | XMIT_CSUM_V6;
2407 else if (skb_is_gso(skb))
2408 rc |= XMIT_GSO_V4 | XMIT_CSUM_V4 | XMIT_CSUM_TCP;
2413 #if (MAX_SKB_FRAGS >= MAX_FETCH_BD - 3)
2414 /* check if packet requires linearization (packet is too fragmented)
2415 no need to check fragmentation if page size > 8K (there will be no
2416 violation to FW restrictions) */
2417 static int bnx2x_pkt_req_lin(struct bnx2x *bp, struct sk_buff *skb,
2422 int first_bd_sz = 0;
2424 /* 3 = 1 (for linear data BD) + 2 (for PBD and last BD) */
2425 if (skb_shinfo(skb)->nr_frags >= (MAX_FETCH_BD - 3)) {
2427 if (xmit_type & XMIT_GSO) {
2428 unsigned short lso_mss = skb_shinfo(skb)->gso_size;
2429 /* Check if LSO packet needs to be copied:
2430 3 = 1 (for headers BD) + 2 (for PBD and last BD) */
2431 int wnd_size = MAX_FETCH_BD - 3;
2432 /* Number of windows to check */
2433 int num_wnds = skb_shinfo(skb)->nr_frags - wnd_size;
2438 /* Headers length */
2439 hlen = (int)(skb_transport_header(skb) - skb->data) +
2442 /* Amount of data (w/o headers) on linear part of SKB*/
2443 first_bd_sz = skb_headlen(skb) - hlen;
2445 wnd_sum = first_bd_sz;
2447 /* Calculate the first sum - it's special */
2448 for (frag_idx = 0; frag_idx < wnd_size - 1; frag_idx++)
2450 skb_frag_size(&skb_shinfo(skb)->frags[frag_idx]);
2452 /* If there was data on linear skb data - check it */
2453 if (first_bd_sz > 0) {
2454 if (unlikely(wnd_sum < lso_mss)) {
2459 wnd_sum -= first_bd_sz;
2462 /* Others are easier: run through the frag list and
2463 check all windows */
2464 for (wnd_idx = 0; wnd_idx <= num_wnds; wnd_idx++) {
2466 skb_frag_size(&skb_shinfo(skb)->frags[wnd_idx + wnd_size - 1]);
2468 if (unlikely(wnd_sum < lso_mss)) {
2473 skb_frag_size(&skb_shinfo(skb)->frags[wnd_idx]);
2476 /* in non-LSO too fragmented packet should always
2483 if (unlikely(to_copy))
2484 DP(NETIF_MSG_TX_QUEUED,
2485 "Linearization IS REQUIRED for %s packet. num_frags %d hlen %d first_bd_sz %d\n",
2486 (xmit_type & XMIT_GSO) ? "LSO" : "non-LSO",
2487 skb_shinfo(skb)->nr_frags, hlen, first_bd_sz);
2493 static inline void bnx2x_set_pbd_gso_e2(struct sk_buff *skb, u32 *parsing_data,
2496 *parsing_data |= (skb_shinfo(skb)->gso_size <<
2497 ETH_TX_PARSE_BD_E2_LSO_MSS_SHIFT) &
2498 ETH_TX_PARSE_BD_E2_LSO_MSS;
2499 if ((xmit_type & XMIT_GSO_V6) &&
2500 (ipv6_hdr(skb)->nexthdr == NEXTHDR_IPV6))
2501 *parsing_data |= ETH_TX_PARSE_BD_E2_IPV6_WITH_EXT_HDR;
2505 * bnx2x_set_pbd_gso - update PBD in GSO case.
2509 * @xmit_type: xmit flags
2511 static inline void bnx2x_set_pbd_gso(struct sk_buff *skb,
2512 struct eth_tx_parse_bd_e1x *pbd,
2515 pbd->lso_mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
2516 pbd->tcp_send_seq = swab32(tcp_hdr(skb)->seq);
2517 pbd->tcp_flags = pbd_tcp_flags(skb);
2519 if (xmit_type & XMIT_GSO_V4) {
2520 pbd->ip_id = swab16(ip_hdr(skb)->id);
2521 pbd->tcp_pseudo_csum =
2522 swab16(~csum_tcpudp_magic(ip_hdr(skb)->saddr,
2524 0, IPPROTO_TCP, 0));
2527 pbd->tcp_pseudo_csum =
2528 swab16(~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
2529 &ipv6_hdr(skb)->daddr,
2530 0, IPPROTO_TCP, 0));
2532 pbd->global_data |= ETH_TX_PARSE_BD_E1X_PSEUDO_CS_WITHOUT_LEN;
2536 * bnx2x_set_pbd_csum_e2 - update PBD with checksum and return header length
2538 * @bp: driver handle
2540 * @parsing_data: data to be updated
2541 * @xmit_type: xmit flags
2545 static inline u8 bnx2x_set_pbd_csum_e2(struct bnx2x *bp, struct sk_buff *skb,
2546 u32 *parsing_data, u32 xmit_type)
2549 ((((u8 *)skb_transport_header(skb) - skb->data) >> 1) <<
2550 ETH_TX_PARSE_BD_E2_TCP_HDR_START_OFFSET_W_SHIFT) &
2551 ETH_TX_PARSE_BD_E2_TCP_HDR_START_OFFSET_W;
2553 if (xmit_type & XMIT_CSUM_TCP) {
2554 *parsing_data |= ((tcp_hdrlen(skb) / 4) <<
2555 ETH_TX_PARSE_BD_E2_TCP_HDR_LENGTH_DW_SHIFT) &
2556 ETH_TX_PARSE_BD_E2_TCP_HDR_LENGTH_DW;
2558 return skb_transport_header(skb) + tcp_hdrlen(skb) - skb->data;
2560 /* We support checksum offload for TCP and UDP only.
2561 * No need to pass the UDP header length - it's a constant.
2563 return skb_transport_header(skb) +
2564 sizeof(struct udphdr) - skb->data;
2567 static inline void bnx2x_set_sbd_csum(struct bnx2x *bp, struct sk_buff *skb,
2568 struct eth_tx_start_bd *tx_start_bd, u32 xmit_type)
2570 tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_L4_CSUM;
2572 if (xmit_type & XMIT_CSUM_V4)
2573 tx_start_bd->bd_flags.as_bitfield |=
2574 ETH_TX_BD_FLAGS_IP_CSUM;
2576 tx_start_bd->bd_flags.as_bitfield |=
2577 ETH_TX_BD_FLAGS_IPV6;
2579 if (!(xmit_type & XMIT_CSUM_TCP))
2580 tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_IS_UDP;
2584 * bnx2x_set_pbd_csum - update PBD with checksum and return header length
2586 * @bp: driver handle
2588 * @pbd: parse BD to be updated
2589 * @xmit_type: xmit flags
2591 static inline u8 bnx2x_set_pbd_csum(struct bnx2x *bp, struct sk_buff *skb,
2592 struct eth_tx_parse_bd_e1x *pbd,
2595 u8 hlen = (skb_network_header(skb) - skb->data) >> 1;
2597 /* for now NS flag is not used in Linux */
2599 (hlen | ((skb->protocol == cpu_to_be16(ETH_P_8021Q)) <<
2600 ETH_TX_PARSE_BD_E1X_LLC_SNAP_EN_SHIFT));
2602 pbd->ip_hlen_w = (skb_transport_header(skb) -
2603 skb_network_header(skb)) >> 1;
2605 hlen += pbd->ip_hlen_w;
2607 /* We support checksum offload for TCP and UDP only */
2608 if (xmit_type & XMIT_CSUM_TCP)
2609 hlen += tcp_hdrlen(skb) / 2;
2611 hlen += sizeof(struct udphdr) / 2;
2613 pbd->total_hlen_w = cpu_to_le16(hlen);
2616 if (xmit_type & XMIT_CSUM_TCP) {
2617 pbd->tcp_pseudo_csum = swab16(tcp_hdr(skb)->check);
2620 s8 fix = SKB_CS_OFF(skb); /* signed! */
2622 DP(NETIF_MSG_TX_QUEUED,
2623 "hlen %d fix %d csum before fix %x\n",
2624 le16_to_cpu(pbd->total_hlen_w), fix, SKB_CS(skb));
2626 /* HW bug: fixup the CSUM */
2627 pbd->tcp_pseudo_csum =
2628 bnx2x_csum_fix(skb_transport_header(skb),
2631 DP(NETIF_MSG_TX_QUEUED, "csum after fix %x\n",
2632 pbd->tcp_pseudo_csum);
2638 /* called with netif_tx_lock
2639 * bnx2x_tx_int() runs without netif_tx_lock unless it needs to call
2640 * netif_wake_queue()
2642 netdev_tx_t bnx2x_start_xmit(struct sk_buff *skb, struct net_device *dev)
2644 struct bnx2x *bp = netdev_priv(dev);
2646 struct bnx2x_fastpath *fp;
2647 struct netdev_queue *txq;
2648 struct bnx2x_fp_txdata *txdata;
2649 struct sw_tx_bd *tx_buf;
2650 struct eth_tx_start_bd *tx_start_bd, *first_bd;
2651 struct eth_tx_bd *tx_data_bd, *total_pkt_bd = NULL;
2652 struct eth_tx_parse_bd_e1x *pbd_e1x = NULL;
2653 struct eth_tx_parse_bd_e2 *pbd_e2 = NULL;
2654 u32 pbd_e2_parsing_data = 0;
2655 u16 pkt_prod, bd_prod;
2656 int nbd, txq_index, fp_index, txdata_index;
2658 u32 xmit_type = bnx2x_xmit_type(bp, skb);
2661 __le16 pkt_size = 0;
2663 u8 mac_type = UNICAST_ADDRESS;
2665 #ifdef BNX2X_STOP_ON_ERROR
2666 if (unlikely(bp->panic))
2667 return NETDEV_TX_BUSY;
2670 txq_index = skb_get_queue_mapping(skb);
2671 txq = netdev_get_tx_queue(dev, txq_index);
2673 BUG_ON(txq_index >= MAX_ETH_TXQ_IDX(bp) + FCOE_PRESENT);
2675 /* decode the fastpath index and the cos index from the txq */
2676 fp_index = TXQ_TO_FP(txq_index);
2677 txdata_index = TXQ_TO_COS(txq_index);
2681 * Override the above for the FCoE queue:
2682 * - FCoE fp entry is right after the ETH entries.
2683 * - FCoE L2 queue uses bp->txdata[0] only.
2685 if (unlikely(!NO_FCOE(bp) && (txq_index ==
2686 bnx2x_fcoe_tx(bp, txq_index)))) {
2687 fp_index = FCOE_IDX;
2692 /* enable this debug print to view the transmission queue being used
2693 DP(NETIF_MSG_TX_QUEUED, "indices: txq %d, fp %d, txdata %d\n",
2694 txq_index, fp_index, txdata_index); */
2696 /* locate the fastpath and the txdata */
2697 fp = &bp->fp[fp_index];
2698 txdata = &fp->txdata[txdata_index];
2700 /* enable this debug print to view the tranmission details
2701 DP(NETIF_MSG_TX_QUEUED,
2702 "transmitting packet cid %d fp index %d txdata_index %d tx_data ptr %p fp pointer %p\n",
2703 txdata->cid, fp_index, txdata_index, txdata, fp); */
2705 if (unlikely(bnx2x_tx_avail(bp, txdata) <
2706 (skb_shinfo(skb)->nr_frags + 3))) {
2707 fp->eth_q_stats.driver_xoff++;
2708 netif_tx_stop_queue(txq);
2709 BNX2X_ERR("BUG! Tx ring full when queue awake!\n");
2710 return NETDEV_TX_BUSY;
2713 DP(NETIF_MSG_TX_QUEUED,
2714 "queue[%d]: SKB: summed %x protocol %x protocol(%x,%x) gso type %x xmit_type %x\n",
2715 txq_index, skb->ip_summed, skb->protocol, ipv6_hdr(skb)->nexthdr,
2716 ip_hdr(skb)->protocol, skb_shinfo(skb)->gso_type, xmit_type);
2718 eth = (struct ethhdr *)skb->data;
2720 /* set flag according to packet type (UNICAST_ADDRESS is default)*/
2721 if (unlikely(is_multicast_ether_addr(eth->h_dest))) {
2722 if (is_broadcast_ether_addr(eth->h_dest))
2723 mac_type = BROADCAST_ADDRESS;
2725 mac_type = MULTICAST_ADDRESS;
2728 #if (MAX_SKB_FRAGS >= MAX_FETCH_BD - 3)
2729 /* First, check if we need to linearize the skb (due to FW
2730 restrictions). No need to check fragmentation if page size > 8K
2731 (there will be no violation to FW restrictions) */
2732 if (bnx2x_pkt_req_lin(bp, skb, xmit_type)) {
2733 /* Statistics of linearization */
2735 if (skb_linearize(skb) != 0) {
2736 DP(NETIF_MSG_TX_QUEUED,
2737 "SKB linearization failed - silently dropping this SKB\n");
2738 dev_kfree_skb_any(skb);
2739 return NETDEV_TX_OK;
2743 /* Map skb linear data for DMA */
2744 mapping = dma_map_single(&bp->pdev->dev, skb->data,
2745 skb_headlen(skb), DMA_TO_DEVICE);
2746 if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
2747 DP(NETIF_MSG_TX_QUEUED,
2748 "SKB mapping failed - silently dropping this SKB\n");
2749 dev_kfree_skb_any(skb);
2750 return NETDEV_TX_OK;
2753 Please read carefully. First we use one BD which we mark as start,
2754 then we have a parsing info BD (used for TSO or xsum),
2755 and only then we have the rest of the TSO BDs.
2756 (don't forget to mark the last one as last,
2757 and to unmap only AFTER you write to the BD ...)
2758 And above all, all pdb sizes are in words - NOT DWORDS!
2761 /* get current pkt produced now - advance it just before sending packet
2762 * since mapping of pages may fail and cause packet to be dropped
2764 pkt_prod = txdata->tx_pkt_prod;
2765 bd_prod = TX_BD(txdata->tx_bd_prod);
2767 /* get a tx_buf and first BD
2768 * tx_start_bd may be changed during SPLIT,
2769 * but first_bd will always stay first
2771 tx_buf = &txdata->tx_buf_ring[TX_BD(pkt_prod)];
2772 tx_start_bd = &txdata->tx_desc_ring[bd_prod].start_bd;
2773 first_bd = tx_start_bd;
2775 tx_start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
2776 SET_FLAG(tx_start_bd->general_data, ETH_TX_START_BD_ETH_ADDR_TYPE,
2780 SET_FLAG(tx_start_bd->general_data, ETH_TX_START_BD_HDR_NBDS, 1);
2782 /* remember the first BD of the packet */
2783 tx_buf->first_bd = txdata->tx_bd_prod;
2787 DP(NETIF_MSG_TX_QUEUED,
2788 "sending pkt %u @%p next_idx %u bd %u @%p\n",
2789 pkt_prod, tx_buf, txdata->tx_pkt_prod, bd_prod, tx_start_bd);
2791 if (vlan_tx_tag_present(skb)) {
2792 tx_start_bd->vlan_or_ethertype =
2793 cpu_to_le16(vlan_tx_tag_get(skb));
2794 tx_start_bd->bd_flags.as_bitfield |=
2795 (X_ETH_OUTBAND_VLAN << ETH_TX_BD_FLAGS_VLAN_MODE_SHIFT);
2797 tx_start_bd->vlan_or_ethertype = cpu_to_le16(pkt_prod);
2799 /* turn on parsing and get a BD */
2800 bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
2802 if (xmit_type & XMIT_CSUM)
2803 bnx2x_set_sbd_csum(bp, skb, tx_start_bd, xmit_type);
2805 if (!CHIP_IS_E1x(bp)) {
2806 pbd_e2 = &txdata->tx_desc_ring[bd_prod].parse_bd_e2;
2807 memset(pbd_e2, 0, sizeof(struct eth_tx_parse_bd_e2));
2808 /* Set PBD in checksum offload case */
2809 if (xmit_type & XMIT_CSUM)
2810 hlen = bnx2x_set_pbd_csum_e2(bp, skb,
2811 &pbd_e2_parsing_data,
2815 * fill in the MAC addresses in the PBD - for local
2818 bnx2x_set_fw_mac_addr(&pbd_e2->src_mac_addr_hi,
2819 &pbd_e2->src_mac_addr_mid,
2820 &pbd_e2->src_mac_addr_lo,
2822 bnx2x_set_fw_mac_addr(&pbd_e2->dst_mac_addr_hi,
2823 &pbd_e2->dst_mac_addr_mid,
2824 &pbd_e2->dst_mac_addr_lo,
2828 pbd_e1x = &txdata->tx_desc_ring[bd_prod].parse_bd_e1x;
2829 memset(pbd_e1x, 0, sizeof(struct eth_tx_parse_bd_e1x));
2830 /* Set PBD in checksum offload case */
2831 if (xmit_type & XMIT_CSUM)
2832 hlen = bnx2x_set_pbd_csum(bp, skb, pbd_e1x, xmit_type);
2836 /* Setup the data pointer of the first BD of the packet */
2837 tx_start_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
2838 tx_start_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
2839 nbd = 2; /* start_bd + pbd + frags (updated when pages are mapped) */
2840 tx_start_bd->nbytes = cpu_to_le16(skb_headlen(skb));
2841 pkt_size = tx_start_bd->nbytes;
2843 DP(NETIF_MSG_TX_QUEUED,
2844 "first bd @%p addr (%x:%x) nbd %d nbytes %d flags %x vlan %x\n",
2845 tx_start_bd, tx_start_bd->addr_hi, tx_start_bd->addr_lo,
2846 le16_to_cpu(tx_start_bd->nbd), le16_to_cpu(tx_start_bd->nbytes),
2847 tx_start_bd->bd_flags.as_bitfield,
2848 le16_to_cpu(tx_start_bd->vlan_or_ethertype));
2850 if (xmit_type & XMIT_GSO) {
2852 DP(NETIF_MSG_TX_QUEUED,
2853 "TSO packet len %d hlen %d total len %d tso size %d\n",
2854 skb->len, hlen, skb_headlen(skb),
2855 skb_shinfo(skb)->gso_size);
2857 tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_SW_LSO;
2859 if (unlikely(skb_headlen(skb) > hlen))
2860 bd_prod = bnx2x_tx_split(bp, txdata, tx_buf,
2863 if (!CHIP_IS_E1x(bp))
2864 bnx2x_set_pbd_gso_e2(skb, &pbd_e2_parsing_data,
2867 bnx2x_set_pbd_gso(skb, pbd_e1x, xmit_type);
2870 /* Set the PBD's parsing_data field if not zero
2871 * (for the chips newer than 57711).
2873 if (pbd_e2_parsing_data)
2874 pbd_e2->parsing_data = cpu_to_le32(pbd_e2_parsing_data);
2876 tx_data_bd = (struct eth_tx_bd *)tx_start_bd;
2878 /* Handle fragmented skb */
2879 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
2880 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
2882 mapping = skb_frag_dma_map(&bp->pdev->dev, frag, 0,
2883 skb_frag_size(frag), DMA_TO_DEVICE);
2884 if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
2885 unsigned int pkts_compl = 0, bytes_compl = 0;
2887 DP(NETIF_MSG_TX_QUEUED,
2888 "Unable to map page - dropping packet...\n");
2890 /* we need unmap all buffers already mapped
2892 * first_bd->nbd need to be properly updated
2893 * before call to bnx2x_free_tx_pkt
2895 first_bd->nbd = cpu_to_le16(nbd);
2896 bnx2x_free_tx_pkt(bp, txdata,
2897 TX_BD(txdata->tx_pkt_prod),
2898 &pkts_compl, &bytes_compl);
2899 return NETDEV_TX_OK;
2902 bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
2903 tx_data_bd = &txdata->tx_desc_ring[bd_prod].reg_bd;
2904 if (total_pkt_bd == NULL)
2905 total_pkt_bd = &txdata->tx_desc_ring[bd_prod].reg_bd;
2907 tx_data_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
2908 tx_data_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
2909 tx_data_bd->nbytes = cpu_to_le16(skb_frag_size(frag));
2910 le16_add_cpu(&pkt_size, skb_frag_size(frag));
2913 DP(NETIF_MSG_TX_QUEUED,
2914 "frag %d bd @%p addr (%x:%x) nbytes %d\n",
2915 i, tx_data_bd, tx_data_bd->addr_hi, tx_data_bd->addr_lo,
2916 le16_to_cpu(tx_data_bd->nbytes));
2919 DP(NETIF_MSG_TX_QUEUED, "last bd @%p\n", tx_data_bd);
2921 /* update with actual num BDs */
2922 first_bd->nbd = cpu_to_le16(nbd);
2924 bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
2926 /* now send a tx doorbell, counting the next BD
2927 * if the packet contains or ends with it
2929 if (TX_BD_POFF(bd_prod) < nbd)
2932 /* total_pkt_bytes should be set on the first data BD if
2933 * it's not an LSO packet and there is more than one
2934 * data BD. In this case pkt_size is limited by an MTU value.
2935 * However we prefer to set it for an LSO packet (while we don't
2936 * have to) in order to save some CPU cycles in a none-LSO
2937 * case, when we much more care about them.
2939 if (total_pkt_bd != NULL)
2940 total_pkt_bd->total_pkt_bytes = pkt_size;
2943 DP(NETIF_MSG_TX_QUEUED,
2944 "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",
2945 pbd_e1x, pbd_e1x->global_data, pbd_e1x->ip_hlen_w,
2946 pbd_e1x->ip_id, pbd_e1x->lso_mss, pbd_e1x->tcp_flags,
2947 pbd_e1x->tcp_pseudo_csum, pbd_e1x->tcp_send_seq,
2948 le16_to_cpu(pbd_e1x->total_hlen_w));
2950 DP(NETIF_MSG_TX_QUEUED,
2951 "PBD (E2) @%p dst %x %x %x src %x %x %x parsing_data %x\n",
2952 pbd_e2, pbd_e2->dst_mac_addr_hi, pbd_e2->dst_mac_addr_mid,
2953 pbd_e2->dst_mac_addr_lo, pbd_e2->src_mac_addr_hi,
2954 pbd_e2->src_mac_addr_mid, pbd_e2->src_mac_addr_lo,
2955 pbd_e2->parsing_data);
2956 DP(NETIF_MSG_TX_QUEUED, "doorbell: nbd %d bd %u\n", nbd, bd_prod);
2958 netdev_tx_sent_queue(txq, skb->len);
2960 txdata->tx_pkt_prod++;
2962 * Make sure that the BD data is updated before updating the producer
2963 * since FW might read the BD right after the producer is updated.
2964 * This is only applicable for weak-ordered memory model archs such
2965 * as IA-64. The following barrier is also mandatory since FW will
2966 * assumes packets must have BDs.
2970 txdata->tx_db.data.prod += nbd;
2973 DOORBELL(bp, txdata->cid, txdata->tx_db.raw);
2977 txdata->tx_bd_prod += nbd;
2979 if (unlikely(bnx2x_tx_avail(bp, txdata) < MAX_SKB_FRAGS + 3)) {
2980 netif_tx_stop_queue(txq);
2982 /* paired memory barrier is in bnx2x_tx_int(), we have to keep
2983 * ordering of set_bit() in netif_tx_stop_queue() and read of
2987 fp->eth_q_stats.driver_xoff++;
2988 if (bnx2x_tx_avail(bp, txdata) >= MAX_SKB_FRAGS + 3)
2989 netif_tx_wake_queue(txq);
2993 return NETDEV_TX_OK;
2997 * bnx2x_setup_tc - routine to configure net_device for multi tc
2999 * @netdev: net device to configure
3000 * @tc: number of traffic classes to enable
3002 * callback connected to the ndo_setup_tc function pointer
3004 int bnx2x_setup_tc(struct net_device *dev, u8 num_tc)
3006 int cos, prio, count, offset;
3007 struct bnx2x *bp = netdev_priv(dev);
3009 /* setup tc must be called under rtnl lock */
3012 /* no traffic classes requested. aborting */
3014 netdev_reset_tc(dev);
3018 /* requested to support too many traffic classes */
3019 if (num_tc > bp->max_cos) {
3020 BNX2X_ERR("support for too many traffic classes requested: %d. max supported is %d\n",
3021 num_tc, bp->max_cos);
3025 /* declare amount of supported traffic classes */
3026 if (netdev_set_num_tc(dev, num_tc)) {
3027 BNX2X_ERR("failed to declare %d traffic classes\n", num_tc);
3031 /* configure priority to traffic class mapping */
3032 for (prio = 0; prio < BNX2X_MAX_PRIORITY; prio++) {
3033 netdev_set_prio_tc_map(dev, prio, bp->prio_to_cos[prio]);
3034 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
3035 "mapping priority %d to tc %d\n",
3036 prio, bp->prio_to_cos[prio]);
3040 /* Use this configuration to diffrentiate tc0 from other COSes
3041 This can be used for ets or pfc, and save the effort of setting
3042 up a multio class queue disc or negotiating DCBX with a switch
3043 netdev_set_prio_tc_map(dev, 0, 0);
3044 DP(BNX2X_MSG_SP, "mapping priority %d to tc %d\n", 0, 0);
3045 for (prio = 1; prio < 16; prio++) {
3046 netdev_set_prio_tc_map(dev, prio, 1);
3047 DP(BNX2X_MSG_SP, "mapping priority %d to tc %d\n", prio, 1);
3050 /* configure traffic class to transmission queue mapping */
3051 for (cos = 0; cos < bp->max_cos; cos++) {
3052 count = BNX2X_NUM_ETH_QUEUES(bp);
3053 offset = cos * MAX_TXQS_PER_COS;
3054 netdev_set_tc_queue(dev, cos, count, offset);
3055 DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
3056 "mapping tc %d to offset %d count %d\n",
3057 cos, offset, count);
3063 /* called with rtnl_lock */
3064 int bnx2x_change_mac_addr(struct net_device *dev, void *p)
3066 struct sockaddr *addr = p;
3067 struct bnx2x *bp = netdev_priv(dev);
3070 if (!bnx2x_is_valid_ether_addr(bp, addr->sa_data)) {
3071 BNX2X_ERR("Requested MAC address is not valid\n");
3076 if (IS_MF_STORAGE_SD(bp) && !is_zero_ether_addr(addr->sa_data)) {
3077 BNX2X_ERR("Can't configure non-zero address on iSCSI or FCoE functions in MF-SD mode\n");
3082 if (netif_running(dev)) {
3083 rc = bnx2x_set_eth_mac(bp, false);
3088 dev->addr_assign_type &= ~NET_ADDR_RANDOM;
3089 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
3091 if (netif_running(dev))
3092 rc = bnx2x_set_eth_mac(bp, true);
3097 static void bnx2x_free_fp_mem_at(struct bnx2x *bp, int fp_index)
3099 union host_hc_status_block *sb = &bnx2x_fp(bp, fp_index, status_blk);
3100 struct bnx2x_fastpath *fp = &bp->fp[fp_index];
3105 if (IS_FCOE_IDX(fp_index)) {
3106 memset(sb, 0, sizeof(union host_hc_status_block));
3107 fp->status_blk_mapping = 0;
3112 if (!CHIP_IS_E1x(bp))
3113 BNX2X_PCI_FREE(sb->e2_sb,
3114 bnx2x_fp(bp, fp_index,
3115 status_blk_mapping),
3116 sizeof(struct host_hc_status_block_e2));
3118 BNX2X_PCI_FREE(sb->e1x_sb,
3119 bnx2x_fp(bp, fp_index,
3120 status_blk_mapping),
3121 sizeof(struct host_hc_status_block_e1x));
3126 if (!skip_rx_queue(bp, fp_index)) {
3127 bnx2x_free_rx_bds(fp);
3129 /* fastpath rx rings: rx_buf rx_desc rx_comp */
3130 BNX2X_FREE(bnx2x_fp(bp, fp_index, rx_buf_ring));
3131 BNX2X_PCI_FREE(bnx2x_fp(bp, fp_index, rx_desc_ring),
3132 bnx2x_fp(bp, fp_index, rx_desc_mapping),
3133 sizeof(struct eth_rx_bd) * NUM_RX_BD);
3135 BNX2X_PCI_FREE(bnx2x_fp(bp, fp_index, rx_comp_ring),
3136 bnx2x_fp(bp, fp_index, rx_comp_mapping),
3137 sizeof(struct eth_fast_path_rx_cqe) *
3141 BNX2X_FREE(bnx2x_fp(bp, fp_index, rx_page_ring));
3142 BNX2X_PCI_FREE(bnx2x_fp(bp, fp_index, rx_sge_ring),
3143 bnx2x_fp(bp, fp_index, rx_sge_mapping),
3144 BCM_PAGE_SIZE * NUM_RX_SGE_PAGES);
3148 if (!skip_tx_queue(bp, fp_index)) {
3149 /* fastpath tx rings: tx_buf tx_desc */
3150 for_each_cos_in_tx_queue(fp, cos) {
3151 struct bnx2x_fp_txdata *txdata = &fp->txdata[cos];
3153 DP(NETIF_MSG_IFDOWN,
3154 "freeing tx memory of fp %d cos %d cid %d\n",
3155 fp_index, cos, txdata->cid);
3157 BNX2X_FREE(txdata->tx_buf_ring);
3158 BNX2X_PCI_FREE(txdata->tx_desc_ring,
3159 txdata->tx_desc_mapping,
3160 sizeof(union eth_tx_bd_types) * NUM_TX_BD);
3163 /* end of fastpath */
3166 void bnx2x_free_fp_mem(struct bnx2x *bp)
3169 for_each_queue(bp, i)
3170 bnx2x_free_fp_mem_at(bp, i);
3173 static inline void set_sb_shortcuts(struct bnx2x *bp, int index)
3175 union host_hc_status_block status_blk = bnx2x_fp(bp, index, status_blk);
3176 if (!CHIP_IS_E1x(bp)) {
3177 bnx2x_fp(bp, index, sb_index_values) =
3178 (__le16 *)status_blk.e2_sb->sb.index_values;
3179 bnx2x_fp(bp, index, sb_running_index) =
3180 (__le16 *)status_blk.e2_sb->sb.running_index;
3182 bnx2x_fp(bp, index, sb_index_values) =
3183 (__le16 *)status_blk.e1x_sb->sb.index_values;
3184 bnx2x_fp(bp, index, sb_running_index) =
3185 (__le16 *)status_blk.e1x_sb->sb.running_index;
3189 static int bnx2x_alloc_fp_mem_at(struct bnx2x *bp, int index)
3191 union host_hc_status_block *sb;
3192 struct bnx2x_fastpath *fp = &bp->fp[index];
3195 int rx_ring_size = 0;
3198 if (!bp->rx_ring_size && IS_MF_STORAGE_SD(bp)) {
3199 rx_ring_size = MIN_RX_SIZE_NONTPA;
3200 bp->rx_ring_size = rx_ring_size;
3203 if (!bp->rx_ring_size) {
3204 u32 cfg = SHMEM_RD(bp,
3205 dev_info.port_hw_config[BP_PORT(bp)].default_cfg);
3207 rx_ring_size = MAX_RX_AVAIL/BNX2X_NUM_RX_QUEUES(bp);
3209 /* Dercease ring size for 1G functions */
3210 if ((cfg & PORT_HW_CFG_NET_SERDES_IF_MASK) ==
3211 PORT_HW_CFG_NET_SERDES_IF_SGMII)
3214 /* allocate at least number of buffers required by FW */
3215 rx_ring_size = max_t(int, bp->disable_tpa ? MIN_RX_SIZE_NONTPA :
3216 MIN_RX_SIZE_TPA, rx_ring_size);
3218 bp->rx_ring_size = rx_ring_size;
3219 } else /* if rx_ring_size specified - use it */
3220 rx_ring_size = bp->rx_ring_size;
3223 sb = &bnx2x_fp(bp, index, status_blk);
3225 if (!IS_FCOE_IDX(index)) {
3228 if (!CHIP_IS_E1x(bp))
3229 BNX2X_PCI_ALLOC(sb->e2_sb,
3230 &bnx2x_fp(bp, index, status_blk_mapping),
3231 sizeof(struct host_hc_status_block_e2));
3233 BNX2X_PCI_ALLOC(sb->e1x_sb,
3234 &bnx2x_fp(bp, index, status_blk_mapping),
3235 sizeof(struct host_hc_status_block_e1x));
3240 /* FCoE Queue uses Default SB and doesn't ACK the SB, thus no need to
3241 * set shortcuts for it.
3243 if (!IS_FCOE_IDX(index))
3244 set_sb_shortcuts(bp, index);
3247 if (!skip_tx_queue(bp, index)) {
3248 /* fastpath tx rings: tx_buf tx_desc */
3249 for_each_cos_in_tx_queue(fp, cos) {
3250 struct bnx2x_fp_txdata *txdata = &fp->txdata[cos];
3253 "allocating tx memory of fp %d cos %d\n",
3256 BNX2X_ALLOC(txdata->tx_buf_ring,
3257 sizeof(struct sw_tx_bd) * NUM_TX_BD);
3258 BNX2X_PCI_ALLOC(txdata->tx_desc_ring,
3259 &txdata->tx_desc_mapping,
3260 sizeof(union eth_tx_bd_types) * NUM_TX_BD);
3265 if (!skip_rx_queue(bp, index)) {
3266 /* fastpath rx rings: rx_buf rx_desc rx_comp */
3267 BNX2X_ALLOC(bnx2x_fp(bp, index, rx_buf_ring),
3268 sizeof(struct sw_rx_bd) * NUM_RX_BD);
3269 BNX2X_PCI_ALLOC(bnx2x_fp(bp, index, rx_desc_ring),
3270 &bnx2x_fp(bp, index, rx_desc_mapping),
3271 sizeof(struct eth_rx_bd) * NUM_RX_BD);
3273 BNX2X_PCI_ALLOC(bnx2x_fp(bp, index, rx_comp_ring),
3274 &bnx2x_fp(bp, index, rx_comp_mapping),
3275 sizeof(struct eth_fast_path_rx_cqe) *
3279 BNX2X_ALLOC(bnx2x_fp(bp, index, rx_page_ring),
3280 sizeof(struct sw_rx_page) * NUM_RX_SGE);
3281 BNX2X_PCI_ALLOC(bnx2x_fp(bp, index, rx_sge_ring),
3282 &bnx2x_fp(bp, index, rx_sge_mapping),
3283 BCM_PAGE_SIZE * NUM_RX_SGE_PAGES);
3285 bnx2x_set_next_page_rx_bd(fp);
3288 bnx2x_set_next_page_rx_cq(fp);
3291 ring_size = bnx2x_alloc_rx_bds(fp, rx_ring_size);
3292 if (ring_size < rx_ring_size)
3298 /* handles low memory cases */
3300 BNX2X_ERR("Unable to allocate full memory for queue %d (size %d)\n",
3302 /* FW will drop all packets if queue is not big enough,
3303 * In these cases we disable the queue
3304 * Min size is different for OOO, TPA and non-TPA queues
3306 if (ring_size < (fp->disable_tpa ?
3307 MIN_RX_SIZE_NONTPA : MIN_RX_SIZE_TPA)) {
3308 /* release memory allocated for this queue */
3309 bnx2x_free_fp_mem_at(bp, index);
3315 int bnx2x_alloc_fp_mem(struct bnx2x *bp)
3320 * 1. Allocate FP for leading - fatal if error
3321 * 2. {CNIC} Allocate FCoE FP - fatal if error
3322 * 3. {CNIC} Allocate OOO + FWD - disable OOO if error
3323 * 4. Allocate RSS - fix number of queues if error
3327 if (bnx2x_alloc_fp_mem_at(bp, 0))
3333 if (bnx2x_alloc_fp_mem_at(bp, FCOE_IDX))
3334 /* we will fail load process instead of mark
3341 for_each_nondefault_eth_queue(bp, i)
3342 if (bnx2x_alloc_fp_mem_at(bp, i))
3345 /* handle memory failures */
3346 if (i != BNX2X_NUM_ETH_QUEUES(bp)) {
3347 int delta = BNX2X_NUM_ETH_QUEUES(bp) - i;
3352 * move non eth FPs next to last eth FP
3353 * must be done in that order
3354 * FCOE_IDX < FWD_IDX < OOO_IDX
3357 /* move FCoE fp even NO_FCOE_FLAG is on */
3358 bnx2x_move_fp(bp, FCOE_IDX, FCOE_IDX - delta);
3360 bp->num_queues -= delta;
3361 BNX2X_ERR("Adjusted num of queues from %d to %d\n",
3362 bp->num_queues + delta, bp->num_queues);
3368 void bnx2x_free_mem_bp(struct bnx2x *bp)
3371 kfree(bp->msix_table);
3375 int __devinit bnx2x_alloc_mem_bp(struct bnx2x *bp)
3377 struct bnx2x_fastpath *fp;
3378 struct msix_entry *tbl;
3379 struct bnx2x_ilt *ilt;
3380 int msix_table_size = 0;
3383 * The biggest MSI-X table we might need is as a maximum number of fast
3384 * path IGU SBs plus default SB (for PF).
3386 msix_table_size = bp->igu_sb_cnt + 1;
3388 /* fp array: RSS plus CNIC related L2 queues */
3389 fp = kcalloc(BNX2X_MAX_RSS_COUNT(bp) + NON_ETH_CONTEXT_USE,
3390 sizeof(*fp), GFP_KERNEL);
3396 tbl = kcalloc(msix_table_size, sizeof(*tbl), GFP_KERNEL);
3399 bp->msix_table = tbl;
3402 ilt = kzalloc(sizeof(*ilt), GFP_KERNEL);
3409 bnx2x_free_mem_bp(bp);
3414 int bnx2x_reload_if_running(struct net_device *dev)
3416 struct bnx2x *bp = netdev_priv(dev);
3418 if (unlikely(!netif_running(dev)))
3421 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
3422 return bnx2x_nic_load(bp, LOAD_NORMAL);
3425 int bnx2x_get_cur_phy_idx(struct bnx2x *bp)
3427 u32 sel_phy_idx = 0;
3428 if (bp->link_params.num_phys <= 1)
3431 if (bp->link_vars.link_up) {
3432 sel_phy_idx = EXT_PHY1;
3433 /* In case link is SERDES, check if the EXT_PHY2 is the one */
3434 if ((bp->link_vars.link_status & LINK_STATUS_SERDES_LINK) &&
3435 (bp->link_params.phy[EXT_PHY2].supported & SUPPORTED_FIBRE))
3436 sel_phy_idx = EXT_PHY2;
3439 switch (bnx2x_phy_selection(&bp->link_params)) {
3440 case PORT_HW_CFG_PHY_SELECTION_HARDWARE_DEFAULT:
3441 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY:
3442 case PORT_HW_CFG_PHY_SELECTION_FIRST_PHY_PRIORITY:
3443 sel_phy_idx = EXT_PHY1;
3445 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY:
3446 case PORT_HW_CFG_PHY_SELECTION_SECOND_PHY_PRIORITY:
3447 sel_phy_idx = EXT_PHY2;
3455 int bnx2x_get_link_cfg_idx(struct bnx2x *bp)
3457 u32 sel_phy_idx = bnx2x_get_cur_phy_idx(bp);
3459 * The selected actived PHY is always after swapping (in case PHY
3460 * swapping is enabled). So when swapping is enabled, we need to reverse
3464 if (bp->link_params.multi_phy_config &
3465 PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
3466 if (sel_phy_idx == EXT_PHY1)
3467 sel_phy_idx = EXT_PHY2;
3468 else if (sel_phy_idx == EXT_PHY2)
3469 sel_phy_idx = EXT_PHY1;
3471 return LINK_CONFIG_IDX(sel_phy_idx);
3474 #if defined(NETDEV_FCOE_WWNN) && defined(BCM_CNIC)
3475 int bnx2x_fcoe_get_wwn(struct net_device *dev, u64 *wwn, int type)
3477 struct bnx2x *bp = netdev_priv(dev);
3478 struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
3481 case NETDEV_FCOE_WWNN:
3482 *wwn = HILO_U64(cp->fcoe_wwn_node_name_hi,
3483 cp->fcoe_wwn_node_name_lo);
3485 case NETDEV_FCOE_WWPN:
3486 *wwn = HILO_U64(cp->fcoe_wwn_port_name_hi,
3487 cp->fcoe_wwn_port_name_lo);
3490 BNX2X_ERR("Wrong WWN type requested - %d\n", type);
3498 /* called with rtnl_lock */
3499 int bnx2x_change_mtu(struct net_device *dev, int new_mtu)
3501 struct bnx2x *bp = netdev_priv(dev);
3503 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
3504 BNX2X_ERR("Can't perform change MTU during parity recovery\n");
3508 if ((new_mtu > ETH_MAX_JUMBO_PACKET_SIZE) ||
3509 ((new_mtu + ETH_HLEN) < ETH_MIN_PACKET_SIZE)) {
3510 BNX2X_ERR("Can't support requested MTU size\n");
3514 /* This does not race with packet allocation
3515 * because the actual alloc size is
3516 * only updated as part of load
3520 bp->gro_check = bnx2x_need_gro_check(new_mtu);
3522 return bnx2x_reload_if_running(dev);
3525 netdev_features_t bnx2x_fix_features(struct net_device *dev,
3526 netdev_features_t features)
3528 struct bnx2x *bp = netdev_priv(dev);
3530 /* TPA requires Rx CSUM offloading */
3531 if (!(features & NETIF_F_RXCSUM) || bp->disable_tpa) {
3532 features &= ~NETIF_F_LRO;
3533 features &= ~NETIF_F_GRO;
3539 int bnx2x_set_features(struct net_device *dev, netdev_features_t features)
3541 struct bnx2x *bp = netdev_priv(dev);
3542 u32 flags = bp->flags;
3543 bool bnx2x_reload = false;
3545 if (features & NETIF_F_LRO)
3546 flags |= TPA_ENABLE_FLAG;
3548 flags &= ~TPA_ENABLE_FLAG;
3550 if (features & NETIF_F_GRO)
3551 flags |= GRO_ENABLE_FLAG;
3553 flags &= ~GRO_ENABLE_FLAG;
3555 if (features & NETIF_F_LOOPBACK) {
3556 if (bp->link_params.loopback_mode != LOOPBACK_BMAC) {
3557 bp->link_params.loopback_mode = LOOPBACK_BMAC;
3558 bnx2x_reload = true;
3561 if (bp->link_params.loopback_mode != LOOPBACK_NONE) {
3562 bp->link_params.loopback_mode = LOOPBACK_NONE;
3563 bnx2x_reload = true;
3567 if (flags ^ bp->flags) {
3569 bnx2x_reload = true;
3573 if (bp->recovery_state == BNX2X_RECOVERY_DONE)
3574 return bnx2x_reload_if_running(dev);
3575 /* else: bnx2x_nic_load() will be called at end of recovery */
3581 void bnx2x_tx_timeout(struct net_device *dev)
3583 struct bnx2x *bp = netdev_priv(dev);
3585 #ifdef BNX2X_STOP_ON_ERROR
3590 smp_mb__before_clear_bit();
3591 set_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state);
3592 smp_mb__after_clear_bit();
3594 /* This allows the netif to be shutdown gracefully before resetting */
3595 schedule_delayed_work(&bp->sp_rtnl_task, 0);
3598 int bnx2x_suspend(struct pci_dev *pdev, pm_message_t state)
3600 struct net_device *dev = pci_get_drvdata(pdev);
3604 dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
3607 bp = netdev_priv(dev);
3611 pci_save_state(pdev);
3613 if (!netif_running(dev)) {
3618 netif_device_detach(dev);
3620 bnx2x_nic_unload(bp, UNLOAD_CLOSE);
3622 bnx2x_set_power_state(bp, pci_choose_state(pdev, state));
3629 int bnx2x_resume(struct pci_dev *pdev)
3631 struct net_device *dev = pci_get_drvdata(pdev);
3636 dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
3639 bp = netdev_priv(dev);
3641 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
3642 BNX2X_ERR("Handling parity error recovery. Try again later\n");
3648 pci_restore_state(pdev);
3650 if (!netif_running(dev)) {
3655 bnx2x_set_power_state(bp, PCI_D0);
3656 netif_device_attach(dev);
3658 rc = bnx2x_nic_load(bp, LOAD_OPEN);
3666 void bnx2x_set_ctx_validation(struct bnx2x *bp, struct eth_context *cxt,
3669 /* ustorm cxt validation */
3670 cxt->ustorm_ag_context.cdu_usage =
3671 CDU_RSRVD_VALUE_TYPE_A(HW_CID(bp, cid),
3672 CDU_REGION_NUMBER_UCM_AG, ETH_CONNECTION_TYPE);
3673 /* xcontext validation */
3674 cxt->xstorm_ag_context.cdu_reserved =
3675 CDU_RSRVD_VALUE_TYPE_A(HW_CID(bp, cid),
3676 CDU_REGION_NUMBER_XCM_AG, ETH_CONNECTION_TYPE);
3679 static inline void storm_memset_hc_timeout(struct bnx2x *bp, u8 port,
3680 u8 fw_sb_id, u8 sb_index,
3684 u32 addr = BAR_CSTRORM_INTMEM +
3685 CSTORM_STATUS_BLOCK_DATA_TIMEOUT_OFFSET(fw_sb_id, sb_index);
3686 REG_WR8(bp, addr, ticks);
3688 "port %x fw_sb_id %d sb_index %d ticks %d\n",
3689 port, fw_sb_id, sb_index, ticks);
3692 static inline void storm_memset_hc_disable(struct bnx2x *bp, u8 port,
3693 u16 fw_sb_id, u8 sb_index,
3696 u32 enable_flag = disable ? 0 : (1 << HC_INDEX_DATA_HC_ENABLED_SHIFT);
3697 u32 addr = BAR_CSTRORM_INTMEM +
3698 CSTORM_STATUS_BLOCK_DATA_FLAGS_OFFSET(fw_sb_id, sb_index);
3699 u16 flags = REG_RD16(bp, addr);
3701 flags &= ~HC_INDEX_DATA_HC_ENABLED;
3702 flags |= enable_flag;
3703 REG_WR16(bp, addr, flags);
3705 "port %x fw_sb_id %d sb_index %d disable %d\n",
3706 port, fw_sb_id, sb_index, disable);
3709 void bnx2x_update_coalesce_sb_index(struct bnx2x *bp, u8 fw_sb_id,
3710 u8 sb_index, u8 disable, u16 usec)
3712 int port = BP_PORT(bp);
3713 u8 ticks = usec / BNX2X_BTR;
3715 storm_memset_hc_timeout(bp, port, fw_sb_id, sb_index, ticks);
3717 disable = disable ? 1 : (usec ? 0 : 1);
3718 storm_memset_hc_disable(bp, port, fw_sb_id, sb_index, disable);