2 * Linux network driver for QLogic BR-series Converged Network Adapter.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License (GPL) Version 2 as
6 * published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
14 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
15 * Copyright (c) 2014-2015 QLogic Corporation
19 #include <linux/bitops.h>
20 #include <linux/netdevice.h>
21 #include <linux/skbuff.h>
22 #include <linux/etherdevice.h>
24 #include <linux/ethtool.h>
25 #include <linux/if_vlan.h>
26 #include <linux/if_ether.h>
28 #include <linux/prefetch.h>
29 #include <linux/module.h>
35 static DEFINE_MUTEX(bnad_fwimg_mutex
);
40 static uint bnad_msix_disable
;
41 module_param(bnad_msix_disable
, uint
, 0444);
42 MODULE_PARM_DESC(bnad_msix_disable
, "Disable MSIX mode");
44 static uint bnad_ioc_auto_recover
= 1;
45 module_param(bnad_ioc_auto_recover
, uint
, 0444);
46 MODULE_PARM_DESC(bnad_ioc_auto_recover
, "Enable / Disable auto recovery");
48 static uint bna_debugfs_enable
= 1;
49 module_param(bna_debugfs_enable
, uint
, S_IRUGO
| S_IWUSR
);
50 MODULE_PARM_DESC(bna_debugfs_enable
, "Enables debugfs feature, default=1,"
51 " Range[false:0|true:1]");
56 static u32 bnad_rxqs_per_cq
= 2;
58 static struct mutex bnad_list_mutex
;
59 static LIST_HEAD(bnad_list
);
60 static const u8 bnad_bcast_addr
[] __aligned(2) =
61 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
66 #define BNAD_GET_MBOX_IRQ(_bnad) \
67 (((_bnad)->cfg_flags & BNAD_CF_MSIX) ? \
68 ((_bnad)->msix_table[BNAD_MAILBOX_MSIX_INDEX].vector) : \
69 ((_bnad)->pcidev->irq))
71 #define BNAD_FILL_UNMAPQ_MEM_REQ(_res_info, _num, _size) \
73 (_res_info)->res_type = BNA_RES_T_MEM; \
74 (_res_info)->res_u.mem_info.mem_type = BNA_MEM_T_KVA; \
75 (_res_info)->res_u.mem_info.num = (_num); \
76 (_res_info)->res_u.mem_info.len = (_size); \
80 bnad_add_to_list(struct bnad
*bnad
)
82 mutex_lock(&bnad_list_mutex
);
83 list_add_tail(&bnad
->list_entry
, &bnad_list
);
85 mutex_unlock(&bnad_list_mutex
);
89 bnad_remove_from_list(struct bnad
*bnad
)
91 mutex_lock(&bnad_list_mutex
);
92 list_del(&bnad
->list_entry
);
93 mutex_unlock(&bnad_list_mutex
);
97 * Reinitialize completions in CQ, once Rx is taken down
100 bnad_cq_cleanup(struct bnad
*bnad
, struct bna_ccb
*ccb
)
102 struct bna_cq_entry
*cmpl
;
105 for (i
= 0; i
< ccb
->q_depth
; i
++) {
106 cmpl
= &((struct bna_cq_entry
*)ccb
->sw_q
)[i
];
111 /* Tx Datapath functions */
114 /* Caller should ensure that the entry at unmap_q[index] is valid */
116 bnad_tx_buff_unmap(struct bnad
*bnad
,
117 struct bnad_tx_unmap
*unmap_q
,
118 u32 q_depth
, u32 index
)
120 struct bnad_tx_unmap
*unmap
;
124 unmap
= &unmap_q
[index
];
125 nvecs
= unmap
->nvecs
;
130 dma_unmap_single(&bnad
->pcidev
->dev
,
131 dma_unmap_addr(&unmap
->vectors
[0], dma_addr
),
132 skb_headlen(skb
), DMA_TO_DEVICE
);
133 dma_unmap_addr_set(&unmap
->vectors
[0], dma_addr
, 0);
139 if (vector
== BFI_TX_MAX_VECTORS_PER_WI
) {
141 BNA_QE_INDX_INC(index
, q_depth
);
142 unmap
= &unmap_q
[index
];
145 dma_unmap_page(&bnad
->pcidev
->dev
,
146 dma_unmap_addr(&unmap
->vectors
[vector
], dma_addr
),
147 dma_unmap_len(&unmap
->vectors
[vector
], dma_len
),
149 dma_unmap_addr_set(&unmap
->vectors
[vector
], dma_addr
, 0);
153 BNA_QE_INDX_INC(index
, q_depth
);
159 * Frees all pending Tx Bufs
160 * At this point no activity is expected on the Q,
161 * so DMA unmap & freeing is fine.
164 bnad_txq_cleanup(struct bnad
*bnad
, struct bna_tcb
*tcb
)
166 struct bnad_tx_unmap
*unmap_q
= tcb
->unmap_q
;
170 for (i
= 0; i
< tcb
->q_depth
; i
++) {
171 skb
= unmap_q
[i
].skb
;
174 bnad_tx_buff_unmap(bnad
, unmap_q
, tcb
->q_depth
, i
);
176 dev_kfree_skb_any(skb
);
181 * bnad_txcmpl_process : Frees the Tx bufs on Tx completion
182 * Can be called in a) Interrupt context
186 bnad_txcmpl_process(struct bnad
*bnad
, struct bna_tcb
*tcb
)
188 u32 sent_packets
= 0, sent_bytes
= 0;
189 u32 wis
, unmap_wis
, hw_cons
, cons
, q_depth
;
190 struct bnad_tx_unmap
*unmap_q
= tcb
->unmap_q
;
191 struct bnad_tx_unmap
*unmap
;
194 /* Just return if TX is stopped */
195 if (!test_bit(BNAD_TXQ_TX_STARTED
, &tcb
->flags
))
198 hw_cons
= *(tcb
->hw_consumer_index
);
199 cons
= tcb
->consumer_index
;
200 q_depth
= tcb
->q_depth
;
202 wis
= BNA_Q_INDEX_CHANGE(cons
, hw_cons
, q_depth
);
203 BUG_ON(!(wis
<= BNA_QE_IN_USE_CNT(tcb
, tcb
->q_depth
)));
206 unmap
= &unmap_q
[cons
];
211 sent_bytes
+= skb
->len
;
213 unmap_wis
= BNA_TXQ_WI_NEEDED(unmap
->nvecs
);
216 cons
= bnad_tx_buff_unmap(bnad
, unmap_q
, q_depth
, cons
);
217 dev_kfree_skb_any(skb
);
220 /* Update consumer pointers. */
221 tcb
->consumer_index
= hw_cons
;
223 tcb
->txq
->tx_packets
+= sent_packets
;
224 tcb
->txq
->tx_bytes
+= sent_bytes
;
230 bnad_tx_complete(struct bnad
*bnad
, struct bna_tcb
*tcb
)
232 struct net_device
*netdev
= bnad
->netdev
;
235 if (test_and_set_bit(BNAD_TXQ_FREE_SENT
, &tcb
->flags
))
238 sent
= bnad_txcmpl_process(bnad
, tcb
);
240 if (netif_queue_stopped(netdev
) &&
241 netif_carrier_ok(netdev
) &&
242 BNA_QE_FREE_CNT(tcb
, tcb
->q_depth
) >=
243 BNAD_NETIF_WAKE_THRESHOLD
) {
244 if (test_bit(BNAD_TXQ_TX_STARTED
, &tcb
->flags
)) {
245 netif_wake_queue(netdev
);
246 BNAD_UPDATE_CTR(bnad
, netif_queue_wakeup
);
251 if (likely(test_bit(BNAD_TXQ_TX_STARTED
, &tcb
->flags
)))
252 bna_ib_ack(tcb
->i_dbell
, sent
);
254 smp_mb__before_atomic();
255 clear_bit(BNAD_TXQ_FREE_SENT
, &tcb
->flags
);
260 /* MSIX Tx Completion Handler */
262 bnad_msix_tx(int irq
, void *data
)
264 struct bna_tcb
*tcb
= (struct bna_tcb
*)data
;
265 struct bnad
*bnad
= tcb
->bnad
;
267 bnad_tx_complete(bnad
, tcb
);
273 bnad_rxq_alloc_uninit(struct bnad
*bnad
, struct bna_rcb
*rcb
)
275 struct bnad_rx_unmap_q
*unmap_q
= rcb
->unmap_q
;
277 unmap_q
->reuse_pi
= -1;
278 unmap_q
->alloc_order
= -1;
279 unmap_q
->map_size
= 0;
280 unmap_q
->type
= BNAD_RXBUF_NONE
;
283 /* Default is page-based allocation. Multi-buffer support - TBD */
285 bnad_rxq_alloc_init(struct bnad
*bnad
, struct bna_rcb
*rcb
)
287 struct bnad_rx_unmap_q
*unmap_q
= rcb
->unmap_q
;
290 bnad_rxq_alloc_uninit(bnad
, rcb
);
292 order
= get_order(rcb
->rxq
->buffer_size
);
294 unmap_q
->type
= BNAD_RXBUF_PAGE
;
296 if (bna_is_small_rxq(rcb
->id
)) {
297 unmap_q
->alloc_order
= 0;
298 unmap_q
->map_size
= rcb
->rxq
->buffer_size
;
300 if (rcb
->rxq
->multi_buffer
) {
301 unmap_q
->alloc_order
= 0;
302 unmap_q
->map_size
= rcb
->rxq
->buffer_size
;
303 unmap_q
->type
= BNAD_RXBUF_MULTI_BUFF
;
305 unmap_q
->alloc_order
= order
;
307 (rcb
->rxq
->buffer_size
> 2048) ?
308 PAGE_SIZE
<< order
: 2048;
312 BUG_ON((PAGE_SIZE
<< order
) % unmap_q
->map_size
);
318 bnad_rxq_cleanup_page(struct bnad
*bnad
, struct bnad_rx_unmap
*unmap
)
323 dma_unmap_page(&bnad
->pcidev
->dev
,
324 dma_unmap_addr(&unmap
->vector
, dma_addr
),
325 unmap
->vector
.len
, DMA_FROM_DEVICE
);
326 put_page(unmap
->page
);
328 dma_unmap_addr_set(&unmap
->vector
, dma_addr
, 0);
329 unmap
->vector
.len
= 0;
333 bnad_rxq_cleanup_skb(struct bnad
*bnad
, struct bnad_rx_unmap
*unmap
)
338 dma_unmap_single(&bnad
->pcidev
->dev
,
339 dma_unmap_addr(&unmap
->vector
, dma_addr
),
340 unmap
->vector
.len
, DMA_FROM_DEVICE
);
341 dev_kfree_skb_any(unmap
->skb
);
343 dma_unmap_addr_set(&unmap
->vector
, dma_addr
, 0);
344 unmap
->vector
.len
= 0;
348 bnad_rxq_cleanup(struct bnad
*bnad
, struct bna_rcb
*rcb
)
350 struct bnad_rx_unmap_q
*unmap_q
= rcb
->unmap_q
;
353 for (i
= 0; i
< rcb
->q_depth
; i
++) {
354 struct bnad_rx_unmap
*unmap
= &unmap_q
->unmap
[i
];
356 if (BNAD_RXBUF_IS_SK_BUFF(unmap_q
->type
))
357 bnad_rxq_cleanup_skb(bnad
, unmap
);
359 bnad_rxq_cleanup_page(bnad
, unmap
);
361 bnad_rxq_alloc_uninit(bnad
, rcb
);
365 bnad_rxq_refill_page(struct bnad
*bnad
, struct bna_rcb
*rcb
, u32 nalloc
)
367 u32 alloced
, prod
, q_depth
;
368 struct bnad_rx_unmap_q
*unmap_q
= rcb
->unmap_q
;
369 struct bnad_rx_unmap
*unmap
, *prev
;
370 struct bna_rxq_entry
*rxent
;
372 u32 page_offset
, alloc_size
;
375 prod
= rcb
->producer_index
;
376 q_depth
= rcb
->q_depth
;
378 alloc_size
= PAGE_SIZE
<< unmap_q
->alloc_order
;
382 unmap
= &unmap_q
->unmap
[prod
];
384 if (unmap_q
->reuse_pi
< 0) {
385 page
= alloc_pages(GFP_ATOMIC
| __GFP_COMP
,
386 unmap_q
->alloc_order
);
389 prev
= &unmap_q
->unmap
[unmap_q
->reuse_pi
];
391 page_offset
= prev
->page_offset
+ unmap_q
->map_size
;
395 if (unlikely(!page
)) {
396 BNAD_UPDATE_CTR(bnad
, rxbuf_alloc_failed
);
397 rcb
->rxq
->rxbuf_alloc_failed
++;
401 dma_addr
= dma_map_page(&bnad
->pcidev
->dev
, page
, page_offset
,
402 unmap_q
->map_size
, DMA_FROM_DEVICE
);
403 if (dma_mapping_error(&bnad
->pcidev
->dev
, dma_addr
)) {
405 BNAD_UPDATE_CTR(bnad
, rxbuf_map_failed
);
406 rcb
->rxq
->rxbuf_map_failed
++;
411 unmap
->page_offset
= page_offset
;
412 dma_unmap_addr_set(&unmap
->vector
, dma_addr
, dma_addr
);
413 unmap
->vector
.len
= unmap_q
->map_size
;
414 page_offset
+= unmap_q
->map_size
;
416 if (page_offset
< alloc_size
)
417 unmap_q
->reuse_pi
= prod
;
419 unmap_q
->reuse_pi
= -1;
421 rxent
= &((struct bna_rxq_entry
*)rcb
->sw_q
)[prod
];
422 BNA_SET_DMA_ADDR(dma_addr
, &rxent
->host_addr
);
423 BNA_QE_INDX_INC(prod
, q_depth
);
428 if (likely(alloced
)) {
429 rcb
->producer_index
= prod
;
431 if (likely(test_bit(BNAD_RXQ_POST_OK
, &rcb
->flags
)))
432 bna_rxq_prod_indx_doorbell(rcb
);
439 bnad_rxq_refill_skb(struct bnad
*bnad
, struct bna_rcb
*rcb
, u32 nalloc
)
441 u32 alloced
, prod
, q_depth
, buff_sz
;
442 struct bnad_rx_unmap_q
*unmap_q
= rcb
->unmap_q
;
443 struct bnad_rx_unmap
*unmap
;
444 struct bna_rxq_entry
*rxent
;
448 buff_sz
= rcb
->rxq
->buffer_size
;
449 prod
= rcb
->producer_index
;
450 q_depth
= rcb
->q_depth
;
454 unmap
= &unmap_q
->unmap
[prod
];
456 skb
= netdev_alloc_skb_ip_align(bnad
->netdev
, buff_sz
);
458 if (unlikely(!skb
)) {
459 BNAD_UPDATE_CTR(bnad
, rxbuf_alloc_failed
);
460 rcb
->rxq
->rxbuf_alloc_failed
++;
464 dma_addr
= dma_map_single(&bnad
->pcidev
->dev
, skb
->data
,
465 buff_sz
, DMA_FROM_DEVICE
);
466 if (dma_mapping_error(&bnad
->pcidev
->dev
, dma_addr
)) {
467 dev_kfree_skb_any(skb
);
468 BNAD_UPDATE_CTR(bnad
, rxbuf_map_failed
);
469 rcb
->rxq
->rxbuf_map_failed
++;
474 dma_unmap_addr_set(&unmap
->vector
, dma_addr
, dma_addr
);
475 unmap
->vector
.len
= buff_sz
;
477 rxent
= &((struct bna_rxq_entry
*)rcb
->sw_q
)[prod
];
478 BNA_SET_DMA_ADDR(dma_addr
, &rxent
->host_addr
);
479 BNA_QE_INDX_INC(prod
, q_depth
);
484 if (likely(alloced
)) {
485 rcb
->producer_index
= prod
;
487 if (likely(test_bit(BNAD_RXQ_POST_OK
, &rcb
->flags
)))
488 bna_rxq_prod_indx_doorbell(rcb
);
495 bnad_rxq_post(struct bnad
*bnad
, struct bna_rcb
*rcb
)
497 struct bnad_rx_unmap_q
*unmap_q
= rcb
->unmap_q
;
500 to_alloc
= BNA_QE_FREE_CNT(rcb
, rcb
->q_depth
);
501 if (!(to_alloc
>> BNAD_RXQ_REFILL_THRESHOLD_SHIFT
))
504 if (BNAD_RXBUF_IS_SK_BUFF(unmap_q
->type
))
505 bnad_rxq_refill_skb(bnad
, rcb
, to_alloc
);
507 bnad_rxq_refill_page(bnad
, rcb
, to_alloc
);
510 #define flags_cksum_prot_mask (BNA_CQ_EF_IPV4 | BNA_CQ_EF_L3_CKSUM_OK | \
512 BNA_CQ_EF_TCP | BNA_CQ_EF_UDP | \
513 BNA_CQ_EF_L4_CKSUM_OK)
515 #define flags_tcp4 (BNA_CQ_EF_IPV4 | BNA_CQ_EF_L3_CKSUM_OK | \
516 BNA_CQ_EF_TCP | BNA_CQ_EF_L4_CKSUM_OK)
517 #define flags_tcp6 (BNA_CQ_EF_IPV6 | \
518 BNA_CQ_EF_TCP | BNA_CQ_EF_L4_CKSUM_OK)
519 #define flags_udp4 (BNA_CQ_EF_IPV4 | BNA_CQ_EF_L3_CKSUM_OK | \
520 BNA_CQ_EF_UDP | BNA_CQ_EF_L4_CKSUM_OK)
521 #define flags_udp6 (BNA_CQ_EF_IPV6 | \
522 BNA_CQ_EF_UDP | BNA_CQ_EF_L4_CKSUM_OK)
525 bnad_cq_drop_packet(struct bnad
*bnad
, struct bna_rcb
*rcb
,
526 u32 sop_ci
, u32 nvecs
)
528 struct bnad_rx_unmap_q
*unmap_q
;
529 struct bnad_rx_unmap
*unmap
;
532 unmap_q
= rcb
->unmap_q
;
533 for (vec
= 0, ci
= sop_ci
; vec
< nvecs
; vec
++) {
534 unmap
= &unmap_q
->unmap
[ci
];
535 BNA_QE_INDX_INC(ci
, rcb
->q_depth
);
537 if (BNAD_RXBUF_IS_SK_BUFF(unmap_q
->type
))
538 bnad_rxq_cleanup_skb(bnad
, unmap
);
540 bnad_rxq_cleanup_page(bnad
, unmap
);
545 bnad_cq_setup_skb_frags(struct bna_rcb
*rcb
, struct sk_buff
*skb
,
546 u32 sop_ci
, u32 nvecs
, u32 last_fraglen
)
549 u32 ci
, vec
, len
, totlen
= 0;
550 struct bnad_rx_unmap_q
*unmap_q
;
551 struct bnad_rx_unmap
*unmap
;
553 unmap_q
= rcb
->unmap_q
;
556 /* prefetch header */
557 prefetch(page_address(unmap_q
->unmap
[sop_ci
].page
) +
558 unmap_q
->unmap
[sop_ci
].page_offset
);
560 for (vec
= 1, ci
= sop_ci
; vec
<= nvecs
; vec
++) {
561 unmap
= &unmap_q
->unmap
[ci
];
562 BNA_QE_INDX_INC(ci
, rcb
->q_depth
);
564 dma_unmap_page(&bnad
->pcidev
->dev
,
565 dma_unmap_addr(&unmap
->vector
, dma_addr
),
566 unmap
->vector
.len
, DMA_FROM_DEVICE
);
568 len
= (vec
== nvecs
) ?
569 last_fraglen
: unmap
->vector
.len
;
570 skb
->truesize
+= unmap
->vector
.len
;
573 skb_fill_page_desc(skb
, skb_shinfo(skb
)->nr_frags
,
574 unmap
->page
, unmap
->page_offset
, len
);
577 unmap
->vector
.len
= 0;
581 skb
->data_len
+= totlen
;
585 bnad_cq_setup_skb(struct bnad
*bnad
, struct sk_buff
*skb
,
586 struct bnad_rx_unmap
*unmap
, u32 len
)
590 dma_unmap_single(&bnad
->pcidev
->dev
,
591 dma_unmap_addr(&unmap
->vector
, dma_addr
),
592 unmap
->vector
.len
, DMA_FROM_DEVICE
);
595 skb
->protocol
= eth_type_trans(skb
, bnad
->netdev
);
598 unmap
->vector
.len
= 0;
602 bnad_cq_process(struct bnad
*bnad
, struct bna_ccb
*ccb
, int budget
)
604 struct bna_cq_entry
*cq
, *cmpl
, *next_cmpl
;
605 struct bna_rcb
*rcb
= NULL
;
606 struct bnad_rx_unmap_q
*unmap_q
;
607 struct bnad_rx_unmap
*unmap
= NULL
;
608 struct sk_buff
*skb
= NULL
;
609 struct bna_pkt_rate
*pkt_rt
= &ccb
->pkt_rate
;
610 struct bnad_rx_ctrl
*rx_ctrl
= ccb
->ctrl
;
611 u32 packets
= 0, len
= 0, totlen
= 0;
612 u32 pi
, vec
, sop_ci
= 0, nvecs
= 0;
613 u32 flags
, masked_flags
;
615 prefetch(bnad
->netdev
);
619 while (packets
< budget
) {
620 cmpl
= &cq
[ccb
->producer_index
];
623 /* The 'valid' field is set by the adapter, only after writing
624 * the other fields of completion entry. Hence, do not load
625 * other fields of completion entry *before* the 'valid' is
626 * loaded. Adding the rmb() here prevents the compiler and/or
627 * CPU from reordering the reads which would potentially result
628 * in reading stale values in completion entry.
632 BNA_UPDATE_PKT_CNT(pkt_rt
, ntohs(cmpl
->length
));
634 if (bna_is_small_rxq(cmpl
->rxq_id
))
639 unmap_q
= rcb
->unmap_q
;
641 /* start of packet ci */
642 sop_ci
= rcb
->consumer_index
;
644 if (BNAD_RXBUF_IS_SK_BUFF(unmap_q
->type
)) {
645 unmap
= &unmap_q
->unmap
[sop_ci
];
648 skb
= napi_get_frags(&rx_ctrl
->napi
);
654 flags
= ntohl(cmpl
->flags
);
655 len
= ntohs(cmpl
->length
);
659 /* Check all the completions for this frame.
660 * busy-wait doesn't help much, break here.
662 if (BNAD_RXBUF_IS_MULTI_BUFF(unmap_q
->type
) &&
663 (flags
& BNA_CQ_EF_EOP
) == 0) {
664 pi
= ccb
->producer_index
;
666 BNA_QE_INDX_INC(pi
, ccb
->q_depth
);
669 if (!next_cmpl
->valid
)
671 /* The 'valid' field is set by the adapter, only
672 * after writing the other fields of completion
673 * entry. Hence, do not load other fields of
674 * completion entry *before* the 'valid' is
675 * loaded. Adding the rmb() here prevents the
676 * compiler and/or CPU from reordering the reads
677 * which would potentially result in reading
678 * stale values in completion entry.
682 len
= ntohs(next_cmpl
->length
);
683 flags
= ntohl(next_cmpl
->flags
);
687 } while ((flags
& BNA_CQ_EF_EOP
) == 0);
689 if (!next_cmpl
->valid
)
694 /* TODO: BNA_CQ_EF_LOCAL ? */
695 if (unlikely(flags
& (BNA_CQ_EF_MAC_ERROR
|
696 BNA_CQ_EF_FCS_ERROR
|
697 BNA_CQ_EF_TOO_LONG
))) {
698 bnad_cq_drop_packet(bnad
, rcb
, sop_ci
, nvecs
);
699 rcb
->rxq
->rx_packets_with_error
++;
704 if (BNAD_RXBUF_IS_SK_BUFF(unmap_q
->type
))
705 bnad_cq_setup_skb(bnad
, skb
, unmap
, len
);
707 bnad_cq_setup_skb_frags(rcb
, skb
, sop_ci
, nvecs
, len
);
709 rcb
->rxq
->rx_packets
++;
710 rcb
->rxq
->rx_bytes
+= totlen
;
711 ccb
->bytes_per_intr
+= totlen
;
713 masked_flags
= flags
& flags_cksum_prot_mask
;
716 ((bnad
->netdev
->features
& NETIF_F_RXCSUM
) &&
717 ((masked_flags
== flags_tcp4
) ||
718 (masked_flags
== flags_udp4
) ||
719 (masked_flags
== flags_tcp6
) ||
720 (masked_flags
== flags_udp6
))))
721 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
723 skb_checksum_none_assert(skb
);
725 if ((flags
& BNA_CQ_EF_VLAN
) &&
726 (bnad
->netdev
->features
& NETIF_F_HW_VLAN_CTAG_RX
))
727 __vlan_hwaccel_put_tag(skb
, htons(ETH_P_8021Q
), ntohs(cmpl
->vlan_tag
));
729 if (BNAD_RXBUF_IS_SK_BUFF(unmap_q
->type
))
730 netif_receive_skb(skb
);
732 napi_gro_frags(&rx_ctrl
->napi
);
735 BNA_QE_INDX_ADD(rcb
->consumer_index
, nvecs
, rcb
->q_depth
);
736 for (vec
= 0; vec
< nvecs
; vec
++) {
737 cmpl
= &cq
[ccb
->producer_index
];
739 BNA_QE_INDX_INC(ccb
->producer_index
, ccb
->q_depth
);
743 napi_gro_flush(&rx_ctrl
->napi
, false);
744 if (likely(test_bit(BNAD_RXQ_STARTED
, &ccb
->rcb
[0]->flags
)))
745 bna_ib_ack_disable_irq(ccb
->i_dbell
, packets
);
747 bnad_rxq_post(bnad
, ccb
->rcb
[0]);
749 bnad_rxq_post(bnad
, ccb
->rcb
[1]);
755 bnad_netif_rx_schedule_poll(struct bnad
*bnad
, struct bna_ccb
*ccb
)
757 struct bnad_rx_ctrl
*rx_ctrl
= (struct bnad_rx_ctrl
*)(ccb
->ctrl
);
758 struct napi_struct
*napi
= &rx_ctrl
->napi
;
760 if (likely(napi_schedule_prep(napi
))) {
761 __napi_schedule(napi
);
762 rx_ctrl
->rx_schedule
++;
766 /* MSIX Rx Path Handler */
768 bnad_msix_rx(int irq
, void *data
)
770 struct bna_ccb
*ccb
= (struct bna_ccb
*)data
;
773 ((struct bnad_rx_ctrl
*)ccb
->ctrl
)->rx_intr_ctr
++;
774 bnad_netif_rx_schedule_poll(ccb
->bnad
, ccb
);
780 /* Interrupt handlers */
782 /* Mbox Interrupt Handlers */
784 bnad_msix_mbox_handler(int irq
, void *data
)
788 struct bnad
*bnad
= (struct bnad
*)data
;
790 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
791 if (unlikely(test_bit(BNAD_RF_MBOX_IRQ_DISABLED
, &bnad
->run_flags
))) {
792 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
796 bna_intr_status_get(&bnad
->bna
, intr_status
);
798 if (BNA_IS_MBOX_ERR_INTR(&bnad
->bna
, intr_status
))
799 bna_mbox_handler(&bnad
->bna
, intr_status
);
801 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
807 bnad_isr(int irq
, void *data
)
812 struct bnad
*bnad
= (struct bnad
*)data
;
813 struct bnad_rx_info
*rx_info
;
814 struct bnad_rx_ctrl
*rx_ctrl
;
815 struct bna_tcb
*tcb
= NULL
;
817 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
818 if (unlikely(test_bit(BNAD_RF_MBOX_IRQ_DISABLED
, &bnad
->run_flags
))) {
819 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
823 bna_intr_status_get(&bnad
->bna
, intr_status
);
825 if (unlikely(!intr_status
)) {
826 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
830 if (BNA_IS_MBOX_ERR_INTR(&bnad
->bna
, intr_status
))
831 bna_mbox_handler(&bnad
->bna
, intr_status
);
833 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
835 if (!BNA_IS_INTX_DATA_INTR(intr_status
))
838 /* Process data interrupts */
840 for (i
= 0; i
< bnad
->num_tx
; i
++) {
841 for (j
= 0; j
< bnad
->num_txq_per_tx
; j
++) {
842 tcb
= bnad
->tx_info
[i
].tcb
[j
];
843 if (tcb
&& test_bit(BNAD_TXQ_TX_STARTED
, &tcb
->flags
))
844 bnad_tx_complete(bnad
, bnad
->tx_info
[i
].tcb
[j
]);
848 for (i
= 0; i
< bnad
->num_rx
; i
++) {
849 rx_info
= &bnad
->rx_info
[i
];
852 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++) {
853 rx_ctrl
= &rx_info
->rx_ctrl
[j
];
855 bnad_netif_rx_schedule_poll(bnad
,
863 * Called in interrupt / callback context
864 * with bna_lock held, so cfg_flags access is OK
867 bnad_enable_mbox_irq(struct bnad
*bnad
)
869 clear_bit(BNAD_RF_MBOX_IRQ_DISABLED
, &bnad
->run_flags
);
871 BNAD_UPDATE_CTR(bnad
, mbox_intr_enabled
);
875 * Called with bnad->bna_lock held b'cos of
876 * bnad->cfg_flags access.
879 bnad_disable_mbox_irq(struct bnad
*bnad
)
881 set_bit(BNAD_RF_MBOX_IRQ_DISABLED
, &bnad
->run_flags
);
883 BNAD_UPDATE_CTR(bnad
, mbox_intr_disabled
);
887 bnad_set_netdev_perm_addr(struct bnad
*bnad
)
889 struct net_device
*netdev
= bnad
->netdev
;
891 ether_addr_copy(netdev
->perm_addr
, bnad
->perm_addr
);
892 if (is_zero_ether_addr(netdev
->dev_addr
))
893 ether_addr_copy(netdev
->dev_addr
, bnad
->perm_addr
);
896 /* Control Path Handlers */
900 bnad_cb_mbox_intr_enable(struct bnad
*bnad
)
902 bnad_enable_mbox_irq(bnad
);
906 bnad_cb_mbox_intr_disable(struct bnad
*bnad
)
908 bnad_disable_mbox_irq(bnad
);
912 bnad_cb_ioceth_ready(struct bnad
*bnad
)
914 bnad
->bnad_completions
.ioc_comp_status
= BNA_CB_SUCCESS
;
915 complete(&bnad
->bnad_completions
.ioc_comp
);
919 bnad_cb_ioceth_failed(struct bnad
*bnad
)
921 bnad
->bnad_completions
.ioc_comp_status
= BNA_CB_FAIL
;
922 complete(&bnad
->bnad_completions
.ioc_comp
);
926 bnad_cb_ioceth_disabled(struct bnad
*bnad
)
928 bnad
->bnad_completions
.ioc_comp_status
= BNA_CB_SUCCESS
;
929 complete(&bnad
->bnad_completions
.ioc_comp
);
933 bnad_cb_enet_disabled(void *arg
)
935 struct bnad
*bnad
= (struct bnad
*)arg
;
937 netif_carrier_off(bnad
->netdev
);
938 complete(&bnad
->bnad_completions
.enet_comp
);
942 bnad_cb_ethport_link_status(struct bnad
*bnad
,
943 enum bna_link_status link_status
)
945 bool link_up
= false;
947 link_up
= (link_status
== BNA_LINK_UP
) || (link_status
== BNA_CEE_UP
);
949 if (link_status
== BNA_CEE_UP
) {
950 if (!test_bit(BNAD_RF_CEE_RUNNING
, &bnad
->run_flags
))
951 BNAD_UPDATE_CTR(bnad
, cee_toggle
);
952 set_bit(BNAD_RF_CEE_RUNNING
, &bnad
->run_flags
);
954 if (test_bit(BNAD_RF_CEE_RUNNING
, &bnad
->run_flags
))
955 BNAD_UPDATE_CTR(bnad
, cee_toggle
);
956 clear_bit(BNAD_RF_CEE_RUNNING
, &bnad
->run_flags
);
960 if (!netif_carrier_ok(bnad
->netdev
)) {
962 netdev_info(bnad
->netdev
, "link up\n");
963 netif_carrier_on(bnad
->netdev
);
964 BNAD_UPDATE_CTR(bnad
, link_toggle
);
965 for (tx_id
= 0; tx_id
< bnad
->num_tx
; tx_id
++) {
966 for (tcb_id
= 0; tcb_id
< bnad
->num_txq_per_tx
;
968 struct bna_tcb
*tcb
=
969 bnad
->tx_info
[tx_id
].tcb
[tcb_id
];
976 if (test_bit(BNAD_TXQ_TX_STARTED
,
980 * Transmit Schedule */
984 BNAD_UPDATE_CTR(bnad
,
990 BNAD_UPDATE_CTR(bnad
,
997 if (netif_carrier_ok(bnad
->netdev
)) {
998 netdev_info(bnad
->netdev
, "link down\n");
999 netif_carrier_off(bnad
->netdev
);
1000 BNAD_UPDATE_CTR(bnad
, link_toggle
);
1006 bnad_cb_tx_disabled(void *arg
, struct bna_tx
*tx
)
1008 struct bnad
*bnad
= (struct bnad
*)arg
;
1010 complete(&bnad
->bnad_completions
.tx_comp
);
1014 bnad_cb_tcb_setup(struct bnad
*bnad
, struct bna_tcb
*tcb
)
1016 struct bnad_tx_info
*tx_info
=
1017 (struct bnad_tx_info
*)tcb
->txq
->tx
->priv
;
1020 tx_info
->tcb
[tcb
->id
] = tcb
;
1024 bnad_cb_tcb_destroy(struct bnad
*bnad
, struct bna_tcb
*tcb
)
1026 struct bnad_tx_info
*tx_info
=
1027 (struct bnad_tx_info
*)tcb
->txq
->tx
->priv
;
1029 tx_info
->tcb
[tcb
->id
] = NULL
;
1034 bnad_cb_ccb_setup(struct bnad
*bnad
, struct bna_ccb
*ccb
)
1036 struct bnad_rx_info
*rx_info
=
1037 (struct bnad_rx_info
*)ccb
->cq
->rx
->priv
;
1039 rx_info
->rx_ctrl
[ccb
->id
].ccb
= ccb
;
1040 ccb
->ctrl
= &rx_info
->rx_ctrl
[ccb
->id
];
1044 bnad_cb_ccb_destroy(struct bnad
*bnad
, struct bna_ccb
*ccb
)
1046 struct bnad_rx_info
*rx_info
=
1047 (struct bnad_rx_info
*)ccb
->cq
->rx
->priv
;
1049 rx_info
->rx_ctrl
[ccb
->id
].ccb
= NULL
;
1053 bnad_cb_tx_stall(struct bnad
*bnad
, struct bna_tx
*tx
)
1055 struct bnad_tx_info
*tx_info
=
1056 (struct bnad_tx_info
*)tx
->priv
;
1057 struct bna_tcb
*tcb
;
1061 for (i
= 0; i
< BNAD_MAX_TXQ_PER_TX
; i
++) {
1062 tcb
= tx_info
->tcb
[i
];
1066 clear_bit(BNAD_TXQ_TX_STARTED
, &tcb
->flags
);
1067 netif_stop_subqueue(bnad
->netdev
, txq_id
);
1072 bnad_cb_tx_resume(struct bnad
*bnad
, struct bna_tx
*tx
)
1074 struct bnad_tx_info
*tx_info
= (struct bnad_tx_info
*)tx
->priv
;
1075 struct bna_tcb
*tcb
;
1079 for (i
= 0; i
< BNAD_MAX_TXQ_PER_TX
; i
++) {
1080 tcb
= tx_info
->tcb
[i
];
1085 BUG_ON(test_bit(BNAD_TXQ_TX_STARTED
, &tcb
->flags
));
1086 set_bit(BNAD_TXQ_TX_STARTED
, &tcb
->flags
);
1087 BUG_ON(*(tcb
->hw_consumer_index
) != 0);
1089 if (netif_carrier_ok(bnad
->netdev
)) {
1090 netif_wake_subqueue(bnad
->netdev
, txq_id
);
1091 BNAD_UPDATE_CTR(bnad
, netif_queue_wakeup
);
1096 * Workaround for first ioceth enable failure & we
1097 * get a 0 MAC address. We try to get the MAC address
1100 if (is_zero_ether_addr(bnad
->perm_addr
)) {
1101 bna_enet_perm_mac_get(&bnad
->bna
.enet
, bnad
->perm_addr
);
1102 bnad_set_netdev_perm_addr(bnad
);
1107 * Free all TxQs buffers and then notify TX_E_CLEANUP_DONE to Tx fsm.
1110 bnad_tx_cleanup(struct delayed_work
*work
)
1112 struct bnad_tx_info
*tx_info
=
1113 container_of(work
, struct bnad_tx_info
, tx_cleanup_work
);
1114 struct bnad
*bnad
= NULL
;
1115 struct bna_tcb
*tcb
;
1116 unsigned long flags
;
1119 for (i
= 0; i
< BNAD_MAX_TXQ_PER_TX
; i
++) {
1120 tcb
= tx_info
->tcb
[i
];
1126 if (test_and_set_bit(BNAD_TXQ_FREE_SENT
, &tcb
->flags
)) {
1131 bnad_txq_cleanup(bnad
, tcb
);
1133 smp_mb__before_atomic();
1134 clear_bit(BNAD_TXQ_FREE_SENT
, &tcb
->flags
);
1138 queue_delayed_work(bnad
->work_q
, &tx_info
->tx_cleanup_work
,
1139 msecs_to_jiffies(1));
1143 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1144 bna_tx_cleanup_complete(tx_info
->tx
);
1145 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1149 bnad_cb_tx_cleanup(struct bnad
*bnad
, struct bna_tx
*tx
)
1151 struct bnad_tx_info
*tx_info
= (struct bnad_tx_info
*)tx
->priv
;
1152 struct bna_tcb
*tcb
;
1155 for (i
= 0; i
< BNAD_MAX_TXQ_PER_TX
; i
++) {
1156 tcb
= tx_info
->tcb
[i
];
1161 queue_delayed_work(bnad
->work_q
, &tx_info
->tx_cleanup_work
, 0);
1165 bnad_cb_rx_stall(struct bnad
*bnad
, struct bna_rx
*rx
)
1167 struct bnad_rx_info
*rx_info
= (struct bnad_rx_info
*)rx
->priv
;
1168 struct bna_ccb
*ccb
;
1169 struct bnad_rx_ctrl
*rx_ctrl
;
1172 for (i
= 0; i
< BNAD_MAX_RXP_PER_RX
; i
++) {
1173 rx_ctrl
= &rx_info
->rx_ctrl
[i
];
1178 clear_bit(BNAD_RXQ_POST_OK
, &ccb
->rcb
[0]->flags
);
1181 clear_bit(BNAD_RXQ_POST_OK
, &ccb
->rcb
[1]->flags
);
1186 * Free all RxQs buffers and then notify RX_E_CLEANUP_DONE to Rx fsm.
1189 bnad_rx_cleanup(void *work
)
1191 struct bnad_rx_info
*rx_info
=
1192 container_of(work
, struct bnad_rx_info
, rx_cleanup_work
);
1193 struct bnad_rx_ctrl
*rx_ctrl
;
1194 struct bnad
*bnad
= NULL
;
1195 unsigned long flags
;
1198 for (i
= 0; i
< BNAD_MAX_RXP_PER_RX
; i
++) {
1199 rx_ctrl
= &rx_info
->rx_ctrl
[i
];
1204 bnad
= rx_ctrl
->ccb
->bnad
;
1207 * Wait till the poll handler has exited
1208 * and nothing can be scheduled anymore
1210 napi_disable(&rx_ctrl
->napi
);
1212 bnad_cq_cleanup(bnad
, rx_ctrl
->ccb
);
1213 bnad_rxq_cleanup(bnad
, rx_ctrl
->ccb
->rcb
[0]);
1214 if (rx_ctrl
->ccb
->rcb
[1])
1215 bnad_rxq_cleanup(bnad
, rx_ctrl
->ccb
->rcb
[1]);
1218 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1219 bna_rx_cleanup_complete(rx_info
->rx
);
1220 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1224 bnad_cb_rx_cleanup(struct bnad
*bnad
, struct bna_rx
*rx
)
1226 struct bnad_rx_info
*rx_info
= (struct bnad_rx_info
*)rx
->priv
;
1227 struct bna_ccb
*ccb
;
1228 struct bnad_rx_ctrl
*rx_ctrl
;
1231 for (i
= 0; i
< BNAD_MAX_RXP_PER_RX
; i
++) {
1232 rx_ctrl
= &rx_info
->rx_ctrl
[i
];
1237 clear_bit(BNAD_RXQ_STARTED
, &ccb
->rcb
[0]->flags
);
1240 clear_bit(BNAD_RXQ_STARTED
, &ccb
->rcb
[1]->flags
);
1243 queue_work(bnad
->work_q
, &rx_info
->rx_cleanup_work
);
1247 bnad_cb_rx_post(struct bnad
*bnad
, struct bna_rx
*rx
)
1249 struct bnad_rx_info
*rx_info
= (struct bnad_rx_info
*)rx
->priv
;
1250 struct bna_ccb
*ccb
;
1251 struct bna_rcb
*rcb
;
1252 struct bnad_rx_ctrl
*rx_ctrl
;
1255 for (i
= 0; i
< BNAD_MAX_RXP_PER_RX
; i
++) {
1256 rx_ctrl
= &rx_info
->rx_ctrl
[i
];
1261 napi_enable(&rx_ctrl
->napi
);
1263 for (j
= 0; j
< BNAD_MAX_RXQ_PER_RXP
; j
++) {
1268 bnad_rxq_alloc_init(bnad
, rcb
);
1269 set_bit(BNAD_RXQ_STARTED
, &rcb
->flags
);
1270 set_bit(BNAD_RXQ_POST_OK
, &rcb
->flags
);
1271 bnad_rxq_post(bnad
, rcb
);
1277 bnad_cb_rx_disabled(void *arg
, struct bna_rx
*rx
)
1279 struct bnad
*bnad
= (struct bnad
*)arg
;
1281 complete(&bnad
->bnad_completions
.rx_comp
);
1285 bnad_cb_rx_mcast_add(struct bnad
*bnad
, struct bna_rx
*rx
)
1287 bnad
->bnad_completions
.mcast_comp_status
= BNA_CB_SUCCESS
;
1288 complete(&bnad
->bnad_completions
.mcast_comp
);
1292 bnad_cb_stats_get(struct bnad
*bnad
, enum bna_cb_status status
,
1293 struct bna_stats
*stats
)
1295 if (status
== BNA_CB_SUCCESS
)
1296 BNAD_UPDATE_CTR(bnad
, hw_stats_updates
);
1298 if (!netif_running(bnad
->netdev
) ||
1299 !test_bit(BNAD_RF_STATS_TIMER_RUNNING
, &bnad
->run_flags
))
1302 mod_timer(&bnad
->stats_timer
,
1303 jiffies
+ msecs_to_jiffies(BNAD_STATS_TIMER_FREQ
));
1307 bnad_cb_enet_mtu_set(struct bnad
*bnad
)
1309 bnad
->bnad_completions
.mtu_comp_status
= BNA_CB_SUCCESS
;
1310 complete(&bnad
->bnad_completions
.mtu_comp
);
1314 bnad_cb_completion(void *arg
, enum bfa_status status
)
1316 struct bnad_iocmd_comp
*iocmd_comp
=
1317 (struct bnad_iocmd_comp
*)arg
;
1319 iocmd_comp
->comp_status
= (u32
) status
;
1320 complete(&iocmd_comp
->comp
);
1323 /* Resource allocation, free functions */
1326 bnad_mem_free(struct bnad
*bnad
,
1327 struct bna_mem_info
*mem_info
)
1332 if (mem_info
->mdl
== NULL
)
1335 for (i
= 0; i
< mem_info
->num
; i
++) {
1336 if (mem_info
->mdl
[i
].kva
!= NULL
) {
1337 if (mem_info
->mem_type
== BNA_MEM_T_DMA
) {
1338 BNA_GET_DMA_ADDR(&(mem_info
->mdl
[i
].dma
),
1340 dma_free_coherent(&bnad
->pcidev
->dev
,
1341 mem_info
->mdl
[i
].len
,
1342 mem_info
->mdl
[i
].kva
, dma_pa
);
1344 kfree(mem_info
->mdl
[i
].kva
);
1347 kfree(mem_info
->mdl
);
1348 mem_info
->mdl
= NULL
;
1352 bnad_mem_alloc(struct bnad
*bnad
,
1353 struct bna_mem_info
*mem_info
)
1358 if ((mem_info
->num
== 0) || (mem_info
->len
== 0)) {
1359 mem_info
->mdl
= NULL
;
1363 mem_info
->mdl
= kcalloc(mem_info
->num
, sizeof(struct bna_mem_descr
),
1365 if (mem_info
->mdl
== NULL
)
1368 if (mem_info
->mem_type
== BNA_MEM_T_DMA
) {
1369 for (i
= 0; i
< mem_info
->num
; i
++) {
1370 mem_info
->mdl
[i
].len
= mem_info
->len
;
1371 mem_info
->mdl
[i
].kva
=
1372 dma_alloc_coherent(&bnad
->pcidev
->dev
,
1373 mem_info
->len
, &dma_pa
,
1375 if (mem_info
->mdl
[i
].kva
== NULL
)
1378 BNA_SET_DMA_ADDR(dma_pa
,
1379 &(mem_info
->mdl
[i
].dma
));
1382 for (i
= 0; i
< mem_info
->num
; i
++) {
1383 mem_info
->mdl
[i
].len
= mem_info
->len
;
1384 mem_info
->mdl
[i
].kva
= kzalloc(mem_info
->len
,
1386 if (mem_info
->mdl
[i
].kva
== NULL
)
1394 bnad_mem_free(bnad
, mem_info
);
1398 /* Free IRQ for Mailbox */
1400 bnad_mbox_irq_free(struct bnad
*bnad
)
1403 unsigned long flags
;
1405 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1406 bnad_disable_mbox_irq(bnad
);
1407 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1409 irq
= BNAD_GET_MBOX_IRQ(bnad
);
1410 free_irq(irq
, bnad
);
1414 * Allocates IRQ for Mailbox, but keep it disabled
1415 * This will be enabled once we get the mbox enable callback
1419 bnad_mbox_irq_alloc(struct bnad
*bnad
)
1422 unsigned long irq_flags
, flags
;
1424 irq_handler_t irq_handler
;
1426 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1427 if (bnad
->cfg_flags
& BNAD_CF_MSIX
) {
1428 irq_handler
= (irq_handler_t
)bnad_msix_mbox_handler
;
1429 irq
= bnad
->msix_table
[BNAD_MAILBOX_MSIX_INDEX
].vector
;
1432 irq_handler
= (irq_handler_t
)bnad_isr
;
1433 irq
= bnad
->pcidev
->irq
;
1434 irq_flags
= IRQF_SHARED
;
1437 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1438 sprintf(bnad
->mbox_irq_name
, "%s", BNAD_NAME
);
1441 * Set the Mbox IRQ disable flag, so that the IRQ handler
1442 * called from request_irq() for SHARED IRQs do not execute
1444 set_bit(BNAD_RF_MBOX_IRQ_DISABLED
, &bnad
->run_flags
);
1446 BNAD_UPDATE_CTR(bnad
, mbox_intr_disabled
);
1448 err
= request_irq(irq
, irq_handler
, irq_flags
,
1449 bnad
->mbox_irq_name
, bnad
);
1455 bnad_txrx_irq_free(struct bnad
*bnad
, struct bna_intr_info
*intr_info
)
1457 kfree(intr_info
->idl
);
1458 intr_info
->idl
= NULL
;
1461 /* Allocates Interrupt Descriptor List for MSIX/INT-X vectors */
1463 bnad_txrx_irq_alloc(struct bnad
*bnad
, enum bnad_intr_source src
,
1464 u32 txrx_id
, struct bna_intr_info
*intr_info
)
1466 int i
, vector_start
= 0;
1468 unsigned long flags
;
1470 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1471 cfg_flags
= bnad
->cfg_flags
;
1472 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1474 if (cfg_flags
& BNAD_CF_MSIX
) {
1475 intr_info
->intr_type
= BNA_INTR_T_MSIX
;
1476 intr_info
->idl
= kcalloc(intr_info
->num
,
1477 sizeof(struct bna_intr_descr
),
1479 if (!intr_info
->idl
)
1484 vector_start
= BNAD_MAILBOX_MSIX_VECTORS
+ txrx_id
;
1488 vector_start
= BNAD_MAILBOX_MSIX_VECTORS
+
1489 (bnad
->num_tx
* bnad
->num_txq_per_tx
) +
1497 for (i
= 0; i
< intr_info
->num
; i
++)
1498 intr_info
->idl
[i
].vector
= vector_start
+ i
;
1500 intr_info
->intr_type
= BNA_INTR_T_INTX
;
1502 intr_info
->idl
= kcalloc(intr_info
->num
,
1503 sizeof(struct bna_intr_descr
),
1505 if (!intr_info
->idl
)
1510 intr_info
->idl
[0].vector
= BNAD_INTX_TX_IB_BITMASK
;
1514 intr_info
->idl
[0].vector
= BNAD_INTX_RX_IB_BITMASK
;
1521 /* NOTE: Should be called for MSIX only
1522 * Unregisters Tx MSIX vector(s) from the kernel
1525 bnad_tx_msix_unregister(struct bnad
*bnad
, struct bnad_tx_info
*tx_info
,
1531 for (i
= 0; i
< num_txqs
; i
++) {
1532 if (tx_info
->tcb
[i
] == NULL
)
1535 vector_num
= tx_info
->tcb
[i
]->intr_vector
;
1536 free_irq(bnad
->msix_table
[vector_num
].vector
, tx_info
->tcb
[i
]);
1540 /* NOTE: Should be called for MSIX only
1541 * Registers Tx MSIX vector(s) and ISR(s), cookie with the kernel
1544 bnad_tx_msix_register(struct bnad
*bnad
, struct bnad_tx_info
*tx_info
,
1545 u32 tx_id
, int num_txqs
)
1551 for (i
= 0; i
< num_txqs
; i
++) {
1552 vector_num
= tx_info
->tcb
[i
]->intr_vector
;
1553 sprintf(tx_info
->tcb
[i
]->name
, "%s TXQ %d", bnad
->netdev
->name
,
1554 tx_id
+ tx_info
->tcb
[i
]->id
);
1555 err
= request_irq(bnad
->msix_table
[vector_num
].vector
,
1556 (irq_handler_t
)bnad_msix_tx
, 0,
1557 tx_info
->tcb
[i
]->name
,
1567 bnad_tx_msix_unregister(bnad
, tx_info
, (i
- 1));
1571 /* NOTE: Should be called for MSIX only
1572 * Unregisters Rx MSIX vector(s) from the kernel
1575 bnad_rx_msix_unregister(struct bnad
*bnad
, struct bnad_rx_info
*rx_info
,
1581 for (i
= 0; i
< num_rxps
; i
++) {
1582 if (rx_info
->rx_ctrl
[i
].ccb
== NULL
)
1585 vector_num
= rx_info
->rx_ctrl
[i
].ccb
->intr_vector
;
1586 free_irq(bnad
->msix_table
[vector_num
].vector
,
1587 rx_info
->rx_ctrl
[i
].ccb
);
1591 /* NOTE: Should be called for MSIX only
1592 * Registers Tx MSIX vector(s) and ISR(s), cookie with the kernel
1595 bnad_rx_msix_register(struct bnad
*bnad
, struct bnad_rx_info
*rx_info
,
1596 u32 rx_id
, int num_rxps
)
1602 for (i
= 0; i
< num_rxps
; i
++) {
1603 vector_num
= rx_info
->rx_ctrl
[i
].ccb
->intr_vector
;
1604 sprintf(rx_info
->rx_ctrl
[i
].ccb
->name
, "%s CQ %d",
1606 rx_id
+ rx_info
->rx_ctrl
[i
].ccb
->id
);
1607 err
= request_irq(bnad
->msix_table
[vector_num
].vector
,
1608 (irq_handler_t
)bnad_msix_rx
, 0,
1609 rx_info
->rx_ctrl
[i
].ccb
->name
,
1610 rx_info
->rx_ctrl
[i
].ccb
);
1619 bnad_rx_msix_unregister(bnad
, rx_info
, (i
- 1));
1623 /* Free Tx object Resources */
1625 bnad_tx_res_free(struct bnad
*bnad
, struct bna_res_info
*res_info
)
1629 for (i
= 0; i
< BNA_TX_RES_T_MAX
; i
++) {
1630 if (res_info
[i
].res_type
== BNA_RES_T_MEM
)
1631 bnad_mem_free(bnad
, &res_info
[i
].res_u
.mem_info
);
1632 else if (res_info
[i
].res_type
== BNA_RES_T_INTR
)
1633 bnad_txrx_irq_free(bnad
, &res_info
[i
].res_u
.intr_info
);
1637 /* Allocates memory and interrupt resources for Tx object */
1639 bnad_tx_res_alloc(struct bnad
*bnad
, struct bna_res_info
*res_info
,
1644 for (i
= 0; i
< BNA_TX_RES_T_MAX
; i
++) {
1645 if (res_info
[i
].res_type
== BNA_RES_T_MEM
)
1646 err
= bnad_mem_alloc(bnad
,
1647 &res_info
[i
].res_u
.mem_info
);
1648 else if (res_info
[i
].res_type
== BNA_RES_T_INTR
)
1649 err
= bnad_txrx_irq_alloc(bnad
, BNAD_INTR_TX
, tx_id
,
1650 &res_info
[i
].res_u
.intr_info
);
1657 bnad_tx_res_free(bnad
, res_info
);
1661 /* Free Rx object Resources */
1663 bnad_rx_res_free(struct bnad
*bnad
, struct bna_res_info
*res_info
)
1667 for (i
= 0; i
< BNA_RX_RES_T_MAX
; i
++) {
1668 if (res_info
[i
].res_type
== BNA_RES_T_MEM
)
1669 bnad_mem_free(bnad
, &res_info
[i
].res_u
.mem_info
);
1670 else if (res_info
[i
].res_type
== BNA_RES_T_INTR
)
1671 bnad_txrx_irq_free(bnad
, &res_info
[i
].res_u
.intr_info
);
1675 /* Allocates memory and interrupt resources for Rx object */
1677 bnad_rx_res_alloc(struct bnad
*bnad
, struct bna_res_info
*res_info
,
1682 /* All memory needs to be allocated before setup_ccbs */
1683 for (i
= 0; i
< BNA_RX_RES_T_MAX
; i
++) {
1684 if (res_info
[i
].res_type
== BNA_RES_T_MEM
)
1685 err
= bnad_mem_alloc(bnad
,
1686 &res_info
[i
].res_u
.mem_info
);
1687 else if (res_info
[i
].res_type
== BNA_RES_T_INTR
)
1688 err
= bnad_txrx_irq_alloc(bnad
, BNAD_INTR_RX
, rx_id
,
1689 &res_info
[i
].res_u
.intr_info
);
1696 bnad_rx_res_free(bnad
, res_info
);
1700 /* Timer callbacks */
1703 bnad_ioc_timeout(unsigned long data
)
1705 struct bnad
*bnad
= (struct bnad
*)data
;
1706 unsigned long flags
;
1708 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1709 bfa_nw_ioc_timeout(&bnad
->bna
.ioceth
.ioc
);
1710 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1714 bnad_ioc_hb_check(unsigned long data
)
1716 struct bnad
*bnad
= (struct bnad
*)data
;
1717 unsigned long flags
;
1719 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1720 bfa_nw_ioc_hb_check(&bnad
->bna
.ioceth
.ioc
);
1721 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1725 bnad_iocpf_timeout(unsigned long data
)
1727 struct bnad
*bnad
= (struct bnad
*)data
;
1728 unsigned long flags
;
1730 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1731 bfa_nw_iocpf_timeout(&bnad
->bna
.ioceth
.ioc
);
1732 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1736 bnad_iocpf_sem_timeout(unsigned long data
)
1738 struct bnad
*bnad
= (struct bnad
*)data
;
1739 unsigned long flags
;
1741 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1742 bfa_nw_iocpf_sem_timeout(&bnad
->bna
.ioceth
.ioc
);
1743 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1747 * All timer routines use bnad->bna_lock to protect against
1748 * the following race, which may occur in case of no locking:
1756 /* b) Dynamic Interrupt Moderation Timer */
1758 bnad_dim_timeout(unsigned long data
)
1760 struct bnad
*bnad
= (struct bnad
*)data
;
1761 struct bnad_rx_info
*rx_info
;
1762 struct bnad_rx_ctrl
*rx_ctrl
;
1764 unsigned long flags
;
1766 if (!netif_carrier_ok(bnad
->netdev
))
1769 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1770 for (i
= 0; i
< bnad
->num_rx
; i
++) {
1771 rx_info
= &bnad
->rx_info
[i
];
1774 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++) {
1775 rx_ctrl
= &rx_info
->rx_ctrl
[j
];
1778 bna_rx_dim_update(rx_ctrl
->ccb
);
1782 /* Check for BNAD_CF_DIM_ENABLED, does not eleminate a race */
1783 if (test_bit(BNAD_RF_DIM_TIMER_RUNNING
, &bnad
->run_flags
))
1784 mod_timer(&bnad
->dim_timer
,
1785 jiffies
+ msecs_to_jiffies(BNAD_DIM_TIMER_FREQ
));
1786 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1789 /* c) Statistics Timer */
1791 bnad_stats_timeout(unsigned long data
)
1793 struct bnad
*bnad
= (struct bnad
*)data
;
1794 unsigned long flags
;
1796 if (!netif_running(bnad
->netdev
) ||
1797 !test_bit(BNAD_RF_STATS_TIMER_RUNNING
, &bnad
->run_flags
))
1800 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1801 bna_hw_stats_get(&bnad
->bna
);
1802 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1806 * Set up timer for DIM
1807 * Called with bnad->bna_lock held
1810 bnad_dim_timer_start(struct bnad
*bnad
)
1812 if (bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
&&
1813 !test_bit(BNAD_RF_DIM_TIMER_RUNNING
, &bnad
->run_flags
)) {
1814 setup_timer(&bnad
->dim_timer
, bnad_dim_timeout
,
1815 (unsigned long)bnad
);
1816 set_bit(BNAD_RF_DIM_TIMER_RUNNING
, &bnad
->run_flags
);
1817 mod_timer(&bnad
->dim_timer
,
1818 jiffies
+ msecs_to_jiffies(BNAD_DIM_TIMER_FREQ
));
1823 * Set up timer for statistics
1824 * Called with mutex_lock(&bnad->conf_mutex) held
1827 bnad_stats_timer_start(struct bnad
*bnad
)
1829 unsigned long flags
;
1831 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1832 if (!test_and_set_bit(BNAD_RF_STATS_TIMER_RUNNING
, &bnad
->run_flags
)) {
1833 setup_timer(&bnad
->stats_timer
, bnad_stats_timeout
,
1834 (unsigned long)bnad
);
1835 mod_timer(&bnad
->stats_timer
,
1836 jiffies
+ msecs_to_jiffies(BNAD_STATS_TIMER_FREQ
));
1838 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1842 * Stops the stats timer
1843 * Called with mutex_lock(&bnad->conf_mutex) held
1846 bnad_stats_timer_stop(struct bnad
*bnad
)
1849 unsigned long flags
;
1851 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1852 if (test_and_clear_bit(BNAD_RF_STATS_TIMER_RUNNING
, &bnad
->run_flags
))
1854 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1856 del_timer_sync(&bnad
->stats_timer
);
1862 bnad_netdev_mc_list_get(struct net_device
*netdev
, u8
*mc_list
)
1864 int i
= 1; /* Index 0 has broadcast address */
1865 struct netdev_hw_addr
*mc_addr
;
1867 netdev_for_each_mc_addr(mc_addr
, netdev
) {
1868 ether_addr_copy(&mc_list
[i
* ETH_ALEN
], &mc_addr
->addr
[0]);
1874 bnad_napi_poll_rx(struct napi_struct
*napi
, int budget
)
1876 struct bnad_rx_ctrl
*rx_ctrl
=
1877 container_of(napi
, struct bnad_rx_ctrl
, napi
);
1878 struct bnad
*bnad
= rx_ctrl
->bnad
;
1881 rx_ctrl
->rx_poll_ctr
++;
1883 if (!netif_carrier_ok(bnad
->netdev
))
1886 rcvd
= bnad_cq_process(bnad
, rx_ctrl
->ccb
, budget
);
1891 napi_complete(napi
);
1893 rx_ctrl
->rx_complete
++;
1896 bnad_enable_rx_irq_unsafe(rx_ctrl
->ccb
);
1901 #define BNAD_NAPI_POLL_QUOTA 64
1903 bnad_napi_add(struct bnad
*bnad
, u32 rx_id
)
1905 struct bnad_rx_ctrl
*rx_ctrl
;
1908 /* Initialize & enable NAPI */
1909 for (i
= 0; i
< bnad
->num_rxp_per_rx
; i
++) {
1910 rx_ctrl
= &bnad
->rx_info
[rx_id
].rx_ctrl
[i
];
1911 netif_napi_add(bnad
->netdev
, &rx_ctrl
->napi
,
1912 bnad_napi_poll_rx
, BNAD_NAPI_POLL_QUOTA
);
1917 bnad_napi_delete(struct bnad
*bnad
, u32 rx_id
)
1921 /* First disable and then clean up */
1922 for (i
= 0; i
< bnad
->num_rxp_per_rx
; i
++)
1923 netif_napi_del(&bnad
->rx_info
[rx_id
].rx_ctrl
[i
].napi
);
1926 /* Should be held with conf_lock held */
1928 bnad_destroy_tx(struct bnad
*bnad
, u32 tx_id
)
1930 struct bnad_tx_info
*tx_info
= &bnad
->tx_info
[tx_id
];
1931 struct bna_res_info
*res_info
= &bnad
->tx_res_info
[tx_id
].res_info
[0];
1932 unsigned long flags
;
1937 init_completion(&bnad
->bnad_completions
.tx_comp
);
1938 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1939 bna_tx_disable(tx_info
->tx
, BNA_HARD_CLEANUP
, bnad_cb_tx_disabled
);
1940 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1941 wait_for_completion(&bnad
->bnad_completions
.tx_comp
);
1943 if (tx_info
->tcb
[0]->intr_type
== BNA_INTR_T_MSIX
)
1944 bnad_tx_msix_unregister(bnad
, tx_info
,
1945 bnad
->num_txq_per_tx
);
1947 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1948 bna_tx_destroy(tx_info
->tx
);
1949 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1954 bnad_tx_res_free(bnad
, res_info
);
1957 /* Should be held with conf_lock held */
1959 bnad_setup_tx(struct bnad
*bnad
, u32 tx_id
)
1962 struct bnad_tx_info
*tx_info
= &bnad
->tx_info
[tx_id
];
1963 struct bna_res_info
*res_info
= &bnad
->tx_res_info
[tx_id
].res_info
[0];
1964 struct bna_intr_info
*intr_info
=
1965 &res_info
[BNA_TX_RES_INTR_T_TXCMPL
].res_u
.intr_info
;
1966 struct bna_tx_config
*tx_config
= &bnad
->tx_config
[tx_id
];
1967 static const struct bna_tx_event_cbfn tx_cbfn
= {
1968 .tcb_setup_cbfn
= bnad_cb_tcb_setup
,
1969 .tcb_destroy_cbfn
= bnad_cb_tcb_destroy
,
1970 .tx_stall_cbfn
= bnad_cb_tx_stall
,
1971 .tx_resume_cbfn
= bnad_cb_tx_resume
,
1972 .tx_cleanup_cbfn
= bnad_cb_tx_cleanup
,
1976 unsigned long flags
;
1978 tx_info
->tx_id
= tx_id
;
1980 /* Initialize the Tx object configuration */
1981 tx_config
->num_txq
= bnad
->num_txq_per_tx
;
1982 tx_config
->txq_depth
= bnad
->txq_depth
;
1983 tx_config
->tx_type
= BNA_TX_T_REGULAR
;
1984 tx_config
->coalescing_timeo
= bnad
->tx_coalescing_timeo
;
1986 /* Get BNA's resource requirement for one tx object */
1987 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1988 bna_tx_res_req(bnad
->num_txq_per_tx
,
1989 bnad
->txq_depth
, res_info
);
1990 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1992 /* Fill Unmap Q memory requirements */
1993 BNAD_FILL_UNMAPQ_MEM_REQ(&res_info
[BNA_TX_RES_MEM_T_UNMAPQ
],
1994 bnad
->num_txq_per_tx
, (sizeof(struct bnad_tx_unmap
) *
1997 /* Allocate resources */
1998 err
= bnad_tx_res_alloc(bnad
, res_info
, tx_id
);
2002 /* Ask BNA to create one Tx object, supplying required resources */
2003 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2004 tx
= bna_tx_create(&bnad
->bna
, bnad
, tx_config
, &tx_cbfn
, res_info
,
2006 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2013 INIT_DELAYED_WORK(&tx_info
->tx_cleanup_work
,
2014 (work_func_t
)bnad_tx_cleanup
);
2016 /* Register ISR for the Tx object */
2017 if (intr_info
->intr_type
== BNA_INTR_T_MSIX
) {
2018 err
= bnad_tx_msix_register(bnad
, tx_info
,
2019 tx_id
, bnad
->num_txq_per_tx
);
2024 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2026 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2031 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2032 bna_tx_destroy(tx_info
->tx
);
2033 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2037 bnad_tx_res_free(bnad
, res_info
);
2041 /* Setup the rx config for bna_rx_create */
2042 /* bnad decides the configuration */
2044 bnad_init_rx_config(struct bnad
*bnad
, struct bna_rx_config
*rx_config
)
2046 memset(rx_config
, 0, sizeof(*rx_config
));
2047 rx_config
->rx_type
= BNA_RX_T_REGULAR
;
2048 rx_config
->num_paths
= bnad
->num_rxp_per_rx
;
2049 rx_config
->coalescing_timeo
= bnad
->rx_coalescing_timeo
;
2051 if (bnad
->num_rxp_per_rx
> 1) {
2052 rx_config
->rss_status
= BNA_STATUS_T_ENABLED
;
2053 rx_config
->rss_config
.hash_type
=
2054 (BFI_ENET_RSS_IPV6
|
2055 BFI_ENET_RSS_IPV6_TCP
|
2057 BFI_ENET_RSS_IPV4_TCP
);
2058 rx_config
->rss_config
.hash_mask
=
2059 bnad
->num_rxp_per_rx
- 1;
2060 netdev_rss_key_fill(rx_config
->rss_config
.toeplitz_hash_key
,
2061 sizeof(rx_config
->rss_config
.toeplitz_hash_key
));
2063 rx_config
->rss_status
= BNA_STATUS_T_DISABLED
;
2064 memset(&rx_config
->rss_config
, 0,
2065 sizeof(rx_config
->rss_config
));
2068 rx_config
->frame_size
= BNAD_FRAME_SIZE(bnad
->netdev
->mtu
);
2069 rx_config
->q0_multi_buf
= BNA_STATUS_T_DISABLED
;
2071 /* BNA_RXP_SINGLE - one data-buffer queue
2072 * BNA_RXP_SLR - one small-buffer and one large-buffer queues
2073 * BNA_RXP_HDS - one header-buffer and one data-buffer queues
2075 /* TODO: configurable param for queue type */
2076 rx_config
->rxp_type
= BNA_RXP_SLR
;
2078 if (BNAD_PCI_DEV_IS_CAT2(bnad
) &&
2079 rx_config
->frame_size
> 4096) {
2080 /* though size_routing_enable is set in SLR,
2081 * small packets may get routed to same rxq.
2082 * set buf_size to 2048 instead of PAGE_SIZE.
2084 rx_config
->q0_buf_size
= 2048;
2085 /* this should be in multiples of 2 */
2086 rx_config
->q0_num_vecs
= 4;
2087 rx_config
->q0_depth
= bnad
->rxq_depth
* rx_config
->q0_num_vecs
;
2088 rx_config
->q0_multi_buf
= BNA_STATUS_T_ENABLED
;
2090 rx_config
->q0_buf_size
= rx_config
->frame_size
;
2091 rx_config
->q0_num_vecs
= 1;
2092 rx_config
->q0_depth
= bnad
->rxq_depth
;
2095 /* initialize for q1 for BNA_RXP_SLR/BNA_RXP_HDS */
2096 if (rx_config
->rxp_type
== BNA_RXP_SLR
) {
2097 rx_config
->q1_depth
= bnad
->rxq_depth
;
2098 rx_config
->q1_buf_size
= BFI_SMALL_RXBUF_SIZE
;
2101 rx_config
->vlan_strip_status
=
2102 (bnad
->netdev
->features
& NETIF_F_HW_VLAN_CTAG_RX
) ?
2103 BNA_STATUS_T_ENABLED
: BNA_STATUS_T_DISABLED
;
2107 bnad_rx_ctrl_init(struct bnad
*bnad
, u32 rx_id
)
2109 struct bnad_rx_info
*rx_info
= &bnad
->rx_info
[rx_id
];
2112 for (i
= 0; i
< bnad
->num_rxp_per_rx
; i
++)
2113 rx_info
->rx_ctrl
[i
].bnad
= bnad
;
2116 /* Called with mutex_lock(&bnad->conf_mutex) held */
2118 bnad_reinit_rx(struct bnad
*bnad
)
2120 struct net_device
*netdev
= bnad
->netdev
;
2121 u32 err
= 0, current_err
= 0;
2122 u32 rx_id
= 0, count
= 0;
2123 unsigned long flags
;
2125 /* destroy and create new rx objects */
2126 for (rx_id
= 0; rx_id
< bnad
->num_rx
; rx_id
++) {
2127 if (!bnad
->rx_info
[rx_id
].rx
)
2129 bnad_destroy_rx(bnad
, rx_id
);
2132 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2133 bna_enet_mtu_set(&bnad
->bna
.enet
,
2134 BNAD_FRAME_SIZE(bnad
->netdev
->mtu
), NULL
);
2135 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2137 for (rx_id
= 0; rx_id
< bnad
->num_rx
; rx_id
++) {
2139 current_err
= bnad_setup_rx(bnad
, rx_id
);
2140 if (current_err
&& !err
) {
2142 netdev_err(netdev
, "RXQ:%u setup failed\n", rx_id
);
2146 /* restore rx configuration */
2147 if (bnad
->rx_info
[0].rx
&& !err
) {
2148 bnad_restore_vlans(bnad
, 0);
2149 bnad_enable_default_bcast(bnad
);
2150 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2151 bnad_mac_addr_set_locked(bnad
, netdev
->dev_addr
);
2152 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2153 bnad_set_rx_mode(netdev
);
2159 /* Called with bnad_conf_lock() held */
2161 bnad_destroy_rx(struct bnad
*bnad
, u32 rx_id
)
2163 struct bnad_rx_info
*rx_info
= &bnad
->rx_info
[rx_id
];
2164 struct bna_rx_config
*rx_config
= &bnad
->rx_config
[rx_id
];
2165 struct bna_res_info
*res_info
= &bnad
->rx_res_info
[rx_id
].res_info
[0];
2166 unsigned long flags
;
2173 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2174 if (bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
&&
2175 test_bit(BNAD_RF_DIM_TIMER_RUNNING
, &bnad
->run_flags
)) {
2176 clear_bit(BNAD_RF_DIM_TIMER_RUNNING
, &bnad
->run_flags
);
2179 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2181 del_timer_sync(&bnad
->dim_timer
);
2184 init_completion(&bnad
->bnad_completions
.rx_comp
);
2185 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2186 bna_rx_disable(rx_info
->rx
, BNA_HARD_CLEANUP
, bnad_cb_rx_disabled
);
2187 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2188 wait_for_completion(&bnad
->bnad_completions
.rx_comp
);
2190 if (rx_info
->rx_ctrl
[0].ccb
->intr_type
== BNA_INTR_T_MSIX
)
2191 bnad_rx_msix_unregister(bnad
, rx_info
, rx_config
->num_paths
);
2193 bnad_napi_delete(bnad
, rx_id
);
2195 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2196 bna_rx_destroy(rx_info
->rx
);
2200 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2202 bnad_rx_res_free(bnad
, res_info
);
2205 /* Called with mutex_lock(&bnad->conf_mutex) held */
2207 bnad_setup_rx(struct bnad
*bnad
, u32 rx_id
)
2210 struct bnad_rx_info
*rx_info
= &bnad
->rx_info
[rx_id
];
2211 struct bna_res_info
*res_info
= &bnad
->rx_res_info
[rx_id
].res_info
[0];
2212 struct bna_intr_info
*intr_info
=
2213 &res_info
[BNA_RX_RES_T_INTR
].res_u
.intr_info
;
2214 struct bna_rx_config
*rx_config
= &bnad
->rx_config
[rx_id
];
2215 static const struct bna_rx_event_cbfn rx_cbfn
= {
2216 .rcb_setup_cbfn
= NULL
,
2217 .rcb_destroy_cbfn
= NULL
,
2218 .ccb_setup_cbfn
= bnad_cb_ccb_setup
,
2219 .ccb_destroy_cbfn
= bnad_cb_ccb_destroy
,
2220 .rx_stall_cbfn
= bnad_cb_rx_stall
,
2221 .rx_cleanup_cbfn
= bnad_cb_rx_cleanup
,
2222 .rx_post_cbfn
= bnad_cb_rx_post
,
2225 unsigned long flags
;
2227 rx_info
->rx_id
= rx_id
;
2229 /* Initialize the Rx object configuration */
2230 bnad_init_rx_config(bnad
, rx_config
);
2232 /* Get BNA's resource requirement for one Rx object */
2233 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2234 bna_rx_res_req(rx_config
, res_info
);
2235 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2237 /* Fill Unmap Q memory requirements */
2238 BNAD_FILL_UNMAPQ_MEM_REQ(&res_info
[BNA_RX_RES_MEM_T_UNMAPDQ
],
2239 rx_config
->num_paths
,
2240 (rx_config
->q0_depth
*
2241 sizeof(struct bnad_rx_unmap
)) +
2242 sizeof(struct bnad_rx_unmap_q
));
2244 if (rx_config
->rxp_type
!= BNA_RXP_SINGLE
) {
2245 BNAD_FILL_UNMAPQ_MEM_REQ(&res_info
[BNA_RX_RES_MEM_T_UNMAPHQ
],
2246 rx_config
->num_paths
,
2247 (rx_config
->q1_depth
*
2248 sizeof(struct bnad_rx_unmap
) +
2249 sizeof(struct bnad_rx_unmap_q
)));
2251 /* Allocate resource */
2252 err
= bnad_rx_res_alloc(bnad
, res_info
, rx_id
);
2256 bnad_rx_ctrl_init(bnad
, rx_id
);
2258 /* Ask BNA to create one Rx object, supplying required resources */
2259 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2260 rx
= bna_rx_create(&bnad
->bna
, bnad
, rx_config
, &rx_cbfn
, res_info
,
2264 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2268 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2270 INIT_WORK(&rx_info
->rx_cleanup_work
,
2271 (work_func_t
)(bnad_rx_cleanup
));
2274 * Init NAPI, so that state is set to NAPI_STATE_SCHED,
2275 * so that IRQ handler cannot schedule NAPI at this point.
2277 bnad_napi_add(bnad
, rx_id
);
2279 /* Register ISR for the Rx object */
2280 if (intr_info
->intr_type
== BNA_INTR_T_MSIX
) {
2281 err
= bnad_rx_msix_register(bnad
, rx_info
, rx_id
,
2282 rx_config
->num_paths
);
2287 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2289 /* Set up Dynamic Interrupt Moderation Vector */
2290 if (bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
)
2291 bna_rx_dim_reconfig(&bnad
->bna
, bna_napi_dim_vector
);
2293 /* Enable VLAN filtering only on the default Rx */
2294 bna_rx_vlanfilter_enable(rx
);
2296 /* Start the DIM timer */
2297 bnad_dim_timer_start(bnad
);
2301 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2306 bnad_destroy_rx(bnad
, rx_id
);
2310 /* Called with conf_lock & bnad->bna_lock held */
2312 bnad_tx_coalescing_timeo_set(struct bnad
*bnad
)
2314 struct bnad_tx_info
*tx_info
;
2316 tx_info
= &bnad
->tx_info
[0];
2320 bna_tx_coalescing_timeo_set(tx_info
->tx
, bnad
->tx_coalescing_timeo
);
2323 /* Called with conf_lock & bnad->bna_lock held */
2325 bnad_rx_coalescing_timeo_set(struct bnad
*bnad
)
2327 struct bnad_rx_info
*rx_info
;
2330 for (i
= 0; i
< bnad
->num_rx
; i
++) {
2331 rx_info
= &bnad
->rx_info
[i
];
2334 bna_rx_coalescing_timeo_set(rx_info
->rx
,
2335 bnad
->rx_coalescing_timeo
);
2340 * Called with bnad->bna_lock held
2343 bnad_mac_addr_set_locked(struct bnad
*bnad
, const u8
*mac_addr
)
2347 if (!is_valid_ether_addr(mac_addr
))
2348 return -EADDRNOTAVAIL
;
2350 /* If datapath is down, pretend everything went through */
2351 if (!bnad
->rx_info
[0].rx
)
2354 ret
= bna_rx_ucast_set(bnad
->rx_info
[0].rx
, mac_addr
);
2355 if (ret
!= BNA_CB_SUCCESS
)
2356 return -EADDRNOTAVAIL
;
2361 /* Should be called with conf_lock held */
2363 bnad_enable_default_bcast(struct bnad
*bnad
)
2365 struct bnad_rx_info
*rx_info
= &bnad
->rx_info
[0];
2367 unsigned long flags
;
2369 init_completion(&bnad
->bnad_completions
.mcast_comp
);
2371 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2372 ret
= bna_rx_mcast_add(rx_info
->rx
, bnad_bcast_addr
,
2373 bnad_cb_rx_mcast_add
);
2374 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2376 if (ret
== BNA_CB_SUCCESS
)
2377 wait_for_completion(&bnad
->bnad_completions
.mcast_comp
);
2381 if (bnad
->bnad_completions
.mcast_comp_status
!= BNA_CB_SUCCESS
)
2387 /* Called with mutex_lock(&bnad->conf_mutex) held */
2389 bnad_restore_vlans(struct bnad
*bnad
, u32 rx_id
)
2392 unsigned long flags
;
2394 for_each_set_bit(vid
, bnad
->active_vlans
, VLAN_N_VID
) {
2395 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2396 bna_rx_vlan_add(bnad
->rx_info
[rx_id
].rx
, vid
);
2397 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2401 /* Statistics utilities */
2403 bnad_netdev_qstats_fill(struct bnad
*bnad
, struct rtnl_link_stats64
*stats
)
2407 for (i
= 0; i
< bnad
->num_rx
; i
++) {
2408 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++) {
2409 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
) {
2410 stats
->rx_packets
+= bnad
->rx_info
[i
].
2411 rx_ctrl
[j
].ccb
->rcb
[0]->rxq
->rx_packets
;
2412 stats
->rx_bytes
+= bnad
->rx_info
[i
].
2413 rx_ctrl
[j
].ccb
->rcb
[0]->rxq
->rx_bytes
;
2414 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[1] &&
2415 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->
2417 stats
->rx_packets
+=
2418 bnad
->rx_info
[i
].rx_ctrl
[j
].
2419 ccb
->rcb
[1]->rxq
->rx_packets
;
2421 bnad
->rx_info
[i
].rx_ctrl
[j
].
2422 ccb
->rcb
[1]->rxq
->rx_bytes
;
2427 for (i
= 0; i
< bnad
->num_tx
; i
++) {
2428 for (j
= 0; j
< bnad
->num_txq_per_tx
; j
++) {
2429 if (bnad
->tx_info
[i
].tcb
[j
]) {
2430 stats
->tx_packets
+=
2431 bnad
->tx_info
[i
].tcb
[j
]->txq
->tx_packets
;
2433 bnad
->tx_info
[i
].tcb
[j
]->txq
->tx_bytes
;
2440 * Must be called with the bna_lock held.
2443 bnad_netdev_hwstats_fill(struct bnad
*bnad
, struct rtnl_link_stats64
*stats
)
2445 struct bfi_enet_stats_mac
*mac_stats
;
2449 mac_stats
= &bnad
->stats
.bna_stats
->hw_stats
.mac_stats
;
2451 mac_stats
->rx_fcs_error
+ mac_stats
->rx_alignment_error
+
2452 mac_stats
->rx_frame_length_error
+ mac_stats
->rx_code_error
+
2453 mac_stats
->rx_undersize
;
2454 stats
->tx_errors
= mac_stats
->tx_fcs_error
+
2455 mac_stats
->tx_undersize
;
2456 stats
->rx_dropped
= mac_stats
->rx_drop
;
2457 stats
->tx_dropped
= mac_stats
->tx_drop
;
2458 stats
->multicast
= mac_stats
->rx_multicast
;
2459 stats
->collisions
= mac_stats
->tx_total_collision
;
2461 stats
->rx_length_errors
= mac_stats
->rx_frame_length_error
;
2463 /* receive ring buffer overflow ?? */
2465 stats
->rx_crc_errors
= mac_stats
->rx_fcs_error
;
2466 stats
->rx_frame_errors
= mac_stats
->rx_alignment_error
;
2467 /* recv'r fifo overrun */
2468 bmap
= bna_rx_rid_mask(&bnad
->bna
);
2469 for (i
= 0; bmap
; i
++) {
2471 stats
->rx_fifo_errors
+=
2472 bnad
->stats
.bna_stats
->
2473 hw_stats
.rxf_stats
[i
].frame_drops
;
2481 bnad_mbox_irq_sync(struct bnad
*bnad
)
2484 unsigned long flags
;
2486 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2487 if (bnad
->cfg_flags
& BNAD_CF_MSIX
)
2488 irq
= bnad
->msix_table
[BNAD_MAILBOX_MSIX_INDEX
].vector
;
2490 irq
= bnad
->pcidev
->irq
;
2491 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2493 synchronize_irq(irq
);
2496 /* Utility used by bnad_start_xmit, for doing TSO */
2498 bnad_tso_prepare(struct bnad
*bnad
, struct sk_buff
*skb
)
2502 err
= skb_cow_head(skb
, 0);
2504 BNAD_UPDATE_CTR(bnad
, tso_err
);
2509 * For TSO, the TCP checksum field is seeded with pseudo-header sum
2510 * excluding the length field.
2512 if (vlan_get_protocol(skb
) == htons(ETH_P_IP
)) {
2513 struct iphdr
*iph
= ip_hdr(skb
);
2515 /* Do we really need these? */
2519 tcp_hdr(skb
)->check
=
2520 ~csum_tcpudp_magic(iph
->saddr
, iph
->daddr
, 0,
2522 BNAD_UPDATE_CTR(bnad
, tso4
);
2524 struct ipv6hdr
*ipv6h
= ipv6_hdr(skb
);
2526 ipv6h
->payload_len
= 0;
2527 tcp_hdr(skb
)->check
=
2528 ~csum_ipv6_magic(&ipv6h
->saddr
, &ipv6h
->daddr
, 0,
2530 BNAD_UPDATE_CTR(bnad
, tso6
);
2537 * Initialize Q numbers depending on Rx Paths
2538 * Called with bnad->bna_lock held, because of cfg_flags
2542 bnad_q_num_init(struct bnad
*bnad
)
2546 rxps
= min((uint
)num_online_cpus(),
2547 (uint
)(BNAD_MAX_RX
* BNAD_MAX_RXP_PER_RX
));
2549 if (!(bnad
->cfg_flags
& BNAD_CF_MSIX
))
2550 rxps
= 1; /* INTx */
2554 bnad
->num_rxp_per_rx
= rxps
;
2555 bnad
->num_txq_per_tx
= BNAD_TXQ_NUM
;
2559 * Adjusts the Q numbers, given a number of msix vectors
2560 * Give preference to RSS as opposed to Tx priority Queues,
2561 * in such a case, just use 1 Tx Q
2562 * Called with bnad->bna_lock held b'cos of cfg_flags access
2565 bnad_q_num_adjust(struct bnad
*bnad
, int msix_vectors
, int temp
)
2567 bnad
->num_txq_per_tx
= 1;
2568 if ((msix_vectors
>= (bnad
->num_tx
* bnad
->num_txq_per_tx
) +
2569 bnad_rxqs_per_cq
+ BNAD_MAILBOX_MSIX_VECTORS
) &&
2570 (bnad
->cfg_flags
& BNAD_CF_MSIX
)) {
2571 bnad
->num_rxp_per_rx
= msix_vectors
-
2572 (bnad
->num_tx
* bnad
->num_txq_per_tx
) -
2573 BNAD_MAILBOX_MSIX_VECTORS
;
2575 bnad
->num_rxp_per_rx
= 1;
2578 /* Enable / disable ioceth */
2580 bnad_ioceth_disable(struct bnad
*bnad
)
2582 unsigned long flags
;
2585 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2586 init_completion(&bnad
->bnad_completions
.ioc_comp
);
2587 bna_ioceth_disable(&bnad
->bna
.ioceth
, BNA_HARD_CLEANUP
);
2588 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2590 wait_for_completion_timeout(&bnad
->bnad_completions
.ioc_comp
,
2591 msecs_to_jiffies(BNAD_IOCETH_TIMEOUT
));
2593 err
= bnad
->bnad_completions
.ioc_comp_status
;
2598 bnad_ioceth_enable(struct bnad
*bnad
)
2601 unsigned long flags
;
2603 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2604 init_completion(&bnad
->bnad_completions
.ioc_comp
);
2605 bnad
->bnad_completions
.ioc_comp_status
= BNA_CB_WAITING
;
2606 bna_ioceth_enable(&bnad
->bna
.ioceth
);
2607 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2609 wait_for_completion_timeout(&bnad
->bnad_completions
.ioc_comp
,
2610 msecs_to_jiffies(BNAD_IOCETH_TIMEOUT
));
2612 err
= bnad
->bnad_completions
.ioc_comp_status
;
2617 /* Free BNA resources */
2619 bnad_res_free(struct bnad
*bnad
, struct bna_res_info
*res_info
,
2624 for (i
= 0; i
< res_val_max
; i
++)
2625 bnad_mem_free(bnad
, &res_info
[i
].res_u
.mem_info
);
2628 /* Allocates memory and interrupt resources for BNA */
2630 bnad_res_alloc(struct bnad
*bnad
, struct bna_res_info
*res_info
,
2635 for (i
= 0; i
< res_val_max
; i
++) {
2636 err
= bnad_mem_alloc(bnad
, &res_info
[i
].res_u
.mem_info
);
2643 bnad_res_free(bnad
, res_info
, res_val_max
);
2647 /* Interrupt enable / disable */
2649 bnad_enable_msix(struct bnad
*bnad
)
2652 unsigned long flags
;
2654 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2655 if (!(bnad
->cfg_flags
& BNAD_CF_MSIX
)) {
2656 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2659 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2661 if (bnad
->msix_table
)
2665 kcalloc(bnad
->msix_num
, sizeof(struct msix_entry
), GFP_KERNEL
);
2667 if (!bnad
->msix_table
)
2670 for (i
= 0; i
< bnad
->msix_num
; i
++)
2671 bnad
->msix_table
[i
].entry
= i
;
2673 ret
= pci_enable_msix_range(bnad
->pcidev
, bnad
->msix_table
,
2677 } else if (ret
< bnad
->msix_num
) {
2678 dev_warn(&bnad
->pcidev
->dev
,
2679 "%d MSI-X vectors allocated < %d requested\n",
2680 ret
, bnad
->msix_num
);
2682 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2683 /* ret = #of vectors that we got */
2684 bnad_q_num_adjust(bnad
, (ret
- BNAD_MAILBOX_MSIX_VECTORS
) / 2,
2685 (ret
- BNAD_MAILBOX_MSIX_VECTORS
) / 2);
2686 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2688 bnad
->msix_num
= BNAD_NUM_TXQ
+ BNAD_NUM_RXP
+
2689 BNAD_MAILBOX_MSIX_VECTORS
;
2691 if (bnad
->msix_num
> ret
) {
2692 pci_disable_msix(bnad
->pcidev
);
2697 pci_intx(bnad
->pcidev
, 0);
2702 dev_warn(&bnad
->pcidev
->dev
,
2703 "MSI-X enable failed - operating in INTx mode\n");
2705 kfree(bnad
->msix_table
);
2706 bnad
->msix_table
= NULL
;
2708 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2709 bnad
->cfg_flags
&= ~BNAD_CF_MSIX
;
2710 bnad_q_num_init(bnad
);
2711 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2715 bnad_disable_msix(struct bnad
*bnad
)
2718 unsigned long flags
;
2720 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2721 cfg_flags
= bnad
->cfg_flags
;
2722 if (bnad
->cfg_flags
& BNAD_CF_MSIX
)
2723 bnad
->cfg_flags
&= ~BNAD_CF_MSIX
;
2724 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2726 if (cfg_flags
& BNAD_CF_MSIX
) {
2727 pci_disable_msix(bnad
->pcidev
);
2728 kfree(bnad
->msix_table
);
2729 bnad
->msix_table
= NULL
;
2733 /* Netdev entry points */
2735 bnad_open(struct net_device
*netdev
)
2738 struct bnad
*bnad
= netdev_priv(netdev
);
2739 struct bna_pause_config pause_config
;
2740 unsigned long flags
;
2742 mutex_lock(&bnad
->conf_mutex
);
2745 err
= bnad_setup_tx(bnad
, 0);
2750 err
= bnad_setup_rx(bnad
, 0);
2755 pause_config
.tx_pause
= 0;
2756 pause_config
.rx_pause
= 0;
2758 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2759 bna_enet_mtu_set(&bnad
->bna
.enet
,
2760 BNAD_FRAME_SIZE(bnad
->netdev
->mtu
), NULL
);
2761 bna_enet_pause_config(&bnad
->bna
.enet
, &pause_config
);
2762 bna_enet_enable(&bnad
->bna
.enet
);
2763 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2765 /* Enable broadcast */
2766 bnad_enable_default_bcast(bnad
);
2768 /* Restore VLANs, if any */
2769 bnad_restore_vlans(bnad
, 0);
2771 /* Set the UCAST address */
2772 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2773 bnad_mac_addr_set_locked(bnad
, netdev
->dev_addr
);
2774 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2776 /* Start the stats timer */
2777 bnad_stats_timer_start(bnad
);
2779 mutex_unlock(&bnad
->conf_mutex
);
2784 bnad_destroy_tx(bnad
, 0);
2787 mutex_unlock(&bnad
->conf_mutex
);
2792 bnad_stop(struct net_device
*netdev
)
2794 struct bnad
*bnad
= netdev_priv(netdev
);
2795 unsigned long flags
;
2797 mutex_lock(&bnad
->conf_mutex
);
2799 /* Stop the stats timer */
2800 bnad_stats_timer_stop(bnad
);
2802 init_completion(&bnad
->bnad_completions
.enet_comp
);
2804 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2805 bna_enet_disable(&bnad
->bna
.enet
, BNA_HARD_CLEANUP
,
2806 bnad_cb_enet_disabled
);
2807 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2809 wait_for_completion(&bnad
->bnad_completions
.enet_comp
);
2811 bnad_destroy_tx(bnad
, 0);
2812 bnad_destroy_rx(bnad
, 0);
2814 /* Synchronize mailbox IRQ */
2815 bnad_mbox_irq_sync(bnad
);
2817 mutex_unlock(&bnad
->conf_mutex
);
2823 /* Returns 0 for success */
2825 bnad_txq_wi_prepare(struct bnad
*bnad
, struct bna_tcb
*tcb
,
2826 struct sk_buff
*skb
, struct bna_txq_entry
*txqent
)
2832 if (skb_vlan_tag_present(skb
)) {
2833 vlan_tag
= (u16
)skb_vlan_tag_get(skb
);
2834 flags
|= (BNA_TXQ_WI_CF_INS_PRIO
| BNA_TXQ_WI_CF_INS_VLAN
);
2836 if (test_bit(BNAD_RF_CEE_RUNNING
, &bnad
->run_flags
)) {
2837 vlan_tag
= ((tcb
->priority
& 0x7) << VLAN_PRIO_SHIFT
)
2838 | (vlan_tag
& 0x1fff);
2839 flags
|= (BNA_TXQ_WI_CF_INS_PRIO
| BNA_TXQ_WI_CF_INS_VLAN
);
2841 txqent
->hdr
.wi
.vlan_tag
= htons(vlan_tag
);
2843 if (skb_is_gso(skb
)) {
2844 gso_size
= skb_shinfo(skb
)->gso_size
;
2845 if (unlikely(gso_size
> bnad
->netdev
->mtu
)) {
2846 BNAD_UPDATE_CTR(bnad
, tx_skb_mss_too_long
);
2849 if (unlikely((gso_size
+ skb_transport_offset(skb
) +
2850 tcp_hdrlen(skb
)) >= skb
->len
)) {
2851 txqent
->hdr
.wi
.opcode
= htons(BNA_TXQ_WI_SEND
);
2852 txqent
->hdr
.wi
.lso_mss
= 0;
2853 BNAD_UPDATE_CTR(bnad
, tx_skb_tso_too_short
);
2855 txqent
->hdr
.wi
.opcode
= htons(BNA_TXQ_WI_SEND_LSO
);
2856 txqent
->hdr
.wi
.lso_mss
= htons(gso_size
);
2859 if (bnad_tso_prepare(bnad
, skb
)) {
2860 BNAD_UPDATE_CTR(bnad
, tx_skb_tso_prepare
);
2864 flags
|= (BNA_TXQ_WI_CF_IP_CKSUM
| BNA_TXQ_WI_CF_TCP_CKSUM
);
2865 txqent
->hdr
.wi
.l4_hdr_size_n_offset
=
2866 htons(BNA_TXQ_WI_L4_HDR_N_OFFSET(
2867 tcp_hdrlen(skb
) >> 2, skb_transport_offset(skb
)));
2869 txqent
->hdr
.wi
.opcode
= htons(BNA_TXQ_WI_SEND
);
2870 txqent
->hdr
.wi
.lso_mss
= 0;
2872 if (unlikely(skb
->len
> (bnad
->netdev
->mtu
+ VLAN_ETH_HLEN
))) {
2873 BNAD_UPDATE_CTR(bnad
, tx_skb_non_tso_too_long
);
2877 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
2878 __be16 net_proto
= vlan_get_protocol(skb
);
2881 if (net_proto
== htons(ETH_P_IP
))
2882 proto
= ip_hdr(skb
)->protocol
;
2883 #ifdef NETIF_F_IPV6_CSUM
2884 else if (net_proto
== htons(ETH_P_IPV6
)) {
2885 /* nexthdr may not be TCP immediately. */
2886 proto
= ipv6_hdr(skb
)->nexthdr
;
2889 if (proto
== IPPROTO_TCP
) {
2890 flags
|= BNA_TXQ_WI_CF_TCP_CKSUM
;
2891 txqent
->hdr
.wi
.l4_hdr_size_n_offset
=
2892 htons(BNA_TXQ_WI_L4_HDR_N_OFFSET
2893 (0, skb_transport_offset(skb
)));
2895 BNAD_UPDATE_CTR(bnad
, tcpcsum_offload
);
2897 if (unlikely(skb_headlen(skb
) <
2898 skb_transport_offset(skb
) +
2900 BNAD_UPDATE_CTR(bnad
, tx_skb_tcp_hdr
);
2903 } else if (proto
== IPPROTO_UDP
) {
2904 flags
|= BNA_TXQ_WI_CF_UDP_CKSUM
;
2905 txqent
->hdr
.wi
.l4_hdr_size_n_offset
=
2906 htons(BNA_TXQ_WI_L4_HDR_N_OFFSET
2907 (0, skb_transport_offset(skb
)));
2909 BNAD_UPDATE_CTR(bnad
, udpcsum_offload
);
2910 if (unlikely(skb_headlen(skb
) <
2911 skb_transport_offset(skb
) +
2912 sizeof(struct udphdr
))) {
2913 BNAD_UPDATE_CTR(bnad
, tx_skb_udp_hdr
);
2918 BNAD_UPDATE_CTR(bnad
, tx_skb_csum_err
);
2922 txqent
->hdr
.wi
.l4_hdr_size_n_offset
= 0;
2925 txqent
->hdr
.wi
.flags
= htons(flags
);
2926 txqent
->hdr
.wi
.frame_length
= htonl(skb
->len
);
2932 * bnad_start_xmit : Netdev entry point for Transmit
2933 * Called under lock held by net_device
2936 bnad_start_xmit(struct sk_buff
*skb
, struct net_device
*netdev
)
2938 struct bnad
*bnad
= netdev_priv(netdev
);
2940 struct bna_tcb
*tcb
= NULL
;
2941 struct bnad_tx_unmap
*unmap_q
, *unmap
, *head_unmap
;
2942 u32 prod
, q_depth
, vect_id
;
2943 u32 wis
, vectors
, len
;
2945 dma_addr_t dma_addr
;
2946 struct bna_txq_entry
*txqent
;
2948 len
= skb_headlen(skb
);
2950 /* Sanity checks for the skb */
2952 if (unlikely(skb
->len
<= ETH_HLEN
)) {
2953 dev_kfree_skb_any(skb
);
2954 BNAD_UPDATE_CTR(bnad
, tx_skb_too_short
);
2955 return NETDEV_TX_OK
;
2957 if (unlikely(len
> BFI_TX_MAX_DATA_PER_VECTOR
)) {
2958 dev_kfree_skb_any(skb
);
2959 BNAD_UPDATE_CTR(bnad
, tx_skb_headlen_zero
);
2960 return NETDEV_TX_OK
;
2962 if (unlikely(len
== 0)) {
2963 dev_kfree_skb_any(skb
);
2964 BNAD_UPDATE_CTR(bnad
, tx_skb_headlen_zero
);
2965 return NETDEV_TX_OK
;
2968 tcb
= bnad
->tx_info
[0].tcb
[txq_id
];
2971 * Takes care of the Tx that is scheduled between clearing the flag
2972 * and the netif_tx_stop_all_queues() call.
2974 if (unlikely(!tcb
|| !test_bit(BNAD_TXQ_TX_STARTED
, &tcb
->flags
))) {
2975 dev_kfree_skb_any(skb
);
2976 BNAD_UPDATE_CTR(bnad
, tx_skb_stopping
);
2977 return NETDEV_TX_OK
;
2980 q_depth
= tcb
->q_depth
;
2981 prod
= tcb
->producer_index
;
2982 unmap_q
= tcb
->unmap_q
;
2984 vectors
= 1 + skb_shinfo(skb
)->nr_frags
;
2985 wis
= BNA_TXQ_WI_NEEDED(vectors
); /* 4 vectors per work item */
2987 if (unlikely(vectors
> BFI_TX_MAX_VECTORS_PER_PKT
)) {
2988 dev_kfree_skb_any(skb
);
2989 BNAD_UPDATE_CTR(bnad
, tx_skb_max_vectors
);
2990 return NETDEV_TX_OK
;
2993 /* Check for available TxQ resources */
2994 if (unlikely(wis
> BNA_QE_FREE_CNT(tcb
, q_depth
))) {
2995 if ((*tcb
->hw_consumer_index
!= tcb
->consumer_index
) &&
2996 !test_and_set_bit(BNAD_TXQ_FREE_SENT
, &tcb
->flags
)) {
2998 sent
= bnad_txcmpl_process(bnad
, tcb
);
2999 if (likely(test_bit(BNAD_TXQ_TX_STARTED
, &tcb
->flags
)))
3000 bna_ib_ack(tcb
->i_dbell
, sent
);
3001 smp_mb__before_atomic();
3002 clear_bit(BNAD_TXQ_FREE_SENT
, &tcb
->flags
);
3004 netif_stop_queue(netdev
);
3005 BNAD_UPDATE_CTR(bnad
, netif_queue_stop
);
3010 * Check again to deal with race condition between
3011 * netif_stop_queue here, and netif_wake_queue in
3012 * interrupt handler which is not inside netif tx lock.
3014 if (likely(wis
> BNA_QE_FREE_CNT(tcb
, q_depth
))) {
3015 BNAD_UPDATE_CTR(bnad
, netif_queue_stop
);
3016 return NETDEV_TX_BUSY
;
3018 netif_wake_queue(netdev
);
3019 BNAD_UPDATE_CTR(bnad
, netif_queue_wakeup
);
3023 txqent
= &((struct bna_txq_entry
*)tcb
->sw_q
)[prod
];
3024 head_unmap
= &unmap_q
[prod
];
3026 /* Program the opcode, flags, frame_len, num_vectors in WI */
3027 if (bnad_txq_wi_prepare(bnad
, tcb
, skb
, txqent
)) {
3028 dev_kfree_skb_any(skb
);
3029 return NETDEV_TX_OK
;
3031 txqent
->hdr
.wi
.reserved
= 0;
3032 txqent
->hdr
.wi
.num_vectors
= vectors
;
3034 head_unmap
->skb
= skb
;
3035 head_unmap
->nvecs
= 0;
3037 /* Program the vectors */
3039 dma_addr
= dma_map_single(&bnad
->pcidev
->dev
, skb
->data
,
3040 len
, DMA_TO_DEVICE
);
3041 if (dma_mapping_error(&bnad
->pcidev
->dev
, dma_addr
)) {
3042 dev_kfree_skb_any(skb
);
3043 BNAD_UPDATE_CTR(bnad
, tx_skb_map_failed
);
3044 return NETDEV_TX_OK
;
3046 BNA_SET_DMA_ADDR(dma_addr
, &txqent
->vector
[0].host_addr
);
3047 txqent
->vector
[0].length
= htons(len
);
3048 dma_unmap_addr_set(&unmap
->vectors
[0], dma_addr
, dma_addr
);
3049 head_unmap
->nvecs
++;
3051 for (i
= 0, vect_id
= 0; i
< vectors
- 1; i
++) {
3052 const struct skb_frag_struct
*frag
= &skb_shinfo(skb
)->frags
[i
];
3053 u32 size
= skb_frag_size(frag
);
3055 if (unlikely(size
== 0)) {
3056 /* Undo the changes starting at tcb->producer_index */
3057 bnad_tx_buff_unmap(bnad
, unmap_q
, q_depth
,
3058 tcb
->producer_index
);
3059 dev_kfree_skb_any(skb
);
3060 BNAD_UPDATE_CTR(bnad
, tx_skb_frag_zero
);
3061 return NETDEV_TX_OK
;
3067 if (vect_id
== BFI_TX_MAX_VECTORS_PER_WI
) {
3069 BNA_QE_INDX_INC(prod
, q_depth
);
3070 txqent
= &((struct bna_txq_entry
*)tcb
->sw_q
)[prod
];
3071 txqent
->hdr
.wi_ext
.opcode
= htons(BNA_TXQ_WI_EXTENSION
);
3072 unmap
= &unmap_q
[prod
];
3075 dma_addr
= skb_frag_dma_map(&bnad
->pcidev
->dev
, frag
,
3076 0, size
, DMA_TO_DEVICE
);
3077 if (dma_mapping_error(&bnad
->pcidev
->dev
, dma_addr
)) {
3078 /* Undo the changes starting at tcb->producer_index */
3079 bnad_tx_buff_unmap(bnad
, unmap_q
, q_depth
,
3080 tcb
->producer_index
);
3081 dev_kfree_skb_any(skb
);
3082 BNAD_UPDATE_CTR(bnad
, tx_skb_map_failed
);
3083 return NETDEV_TX_OK
;
3086 dma_unmap_len_set(&unmap
->vectors
[vect_id
], dma_len
, size
);
3087 BNA_SET_DMA_ADDR(dma_addr
, &txqent
->vector
[vect_id
].host_addr
);
3088 txqent
->vector
[vect_id
].length
= htons(size
);
3089 dma_unmap_addr_set(&unmap
->vectors
[vect_id
], dma_addr
,
3091 head_unmap
->nvecs
++;
3094 if (unlikely(len
!= skb
->len
)) {
3095 /* Undo the changes starting at tcb->producer_index */
3096 bnad_tx_buff_unmap(bnad
, unmap_q
, q_depth
, tcb
->producer_index
);
3097 dev_kfree_skb_any(skb
);
3098 BNAD_UPDATE_CTR(bnad
, tx_skb_len_mismatch
);
3099 return NETDEV_TX_OK
;
3102 BNA_QE_INDX_INC(prod
, q_depth
);
3103 tcb
->producer_index
= prod
;
3107 if (unlikely(!test_bit(BNAD_TXQ_TX_STARTED
, &tcb
->flags
)))
3108 return NETDEV_TX_OK
;
3110 skb_tx_timestamp(skb
);
3112 bna_txq_prod_indx_doorbell(tcb
);
3115 return NETDEV_TX_OK
;
3119 * Used spin_lock to synchronize reading of stats structures, which
3120 * is written by BNA under the same lock.
3122 static struct rtnl_link_stats64
*
3123 bnad_get_stats64(struct net_device
*netdev
, struct rtnl_link_stats64
*stats
)
3125 struct bnad
*bnad
= netdev_priv(netdev
);
3126 unsigned long flags
;
3128 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
3130 bnad_netdev_qstats_fill(bnad
, stats
);
3131 bnad_netdev_hwstats_fill(bnad
, stats
);
3133 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
3139 bnad_set_rx_ucast_fltr(struct bnad
*bnad
)
3141 struct net_device
*netdev
= bnad
->netdev
;
3142 int uc_count
= netdev_uc_count(netdev
);
3143 enum bna_cb_status ret
;
3145 struct netdev_hw_addr
*ha
;
3148 if (netdev_uc_empty(bnad
->netdev
)) {
3149 bna_rx_ucast_listset(bnad
->rx_info
[0].rx
, 0, NULL
);
3153 if (uc_count
> bna_attr(&bnad
->bna
)->num_ucmac
)
3156 mac_list
= kzalloc(uc_count
* ETH_ALEN
, GFP_ATOMIC
);
3157 if (mac_list
== NULL
)
3161 netdev_for_each_uc_addr(ha
, netdev
) {
3162 ether_addr_copy(&mac_list
[entry
* ETH_ALEN
], &ha
->addr
[0]);
3166 ret
= bna_rx_ucast_listset(bnad
->rx_info
[0].rx
, entry
, mac_list
);
3169 if (ret
!= BNA_CB_SUCCESS
)
3174 /* ucast packets not in UCAM are routed to default function */
3176 bnad
->cfg_flags
|= BNAD_CF_DEFAULT
;
3177 bna_rx_ucast_listset(bnad
->rx_info
[0].rx
, 0, NULL
);
3181 bnad_set_rx_mcast_fltr(struct bnad
*bnad
)
3183 struct net_device
*netdev
= bnad
->netdev
;
3184 int mc_count
= netdev_mc_count(netdev
);
3185 enum bna_cb_status ret
;
3188 if (netdev
->flags
& IFF_ALLMULTI
)
3191 if (netdev_mc_empty(netdev
))
3194 if (mc_count
> bna_attr(&bnad
->bna
)->num_mcmac
)
3197 mac_list
= kzalloc((mc_count
+ 1) * ETH_ALEN
, GFP_ATOMIC
);
3199 if (mac_list
== NULL
)
3202 ether_addr_copy(&mac_list
[0], &bnad_bcast_addr
[0]);
3204 /* copy rest of the MCAST addresses */
3205 bnad_netdev_mc_list_get(netdev
, mac_list
);
3206 ret
= bna_rx_mcast_listset(bnad
->rx_info
[0].rx
, mc_count
+ 1, mac_list
);
3209 if (ret
!= BNA_CB_SUCCESS
)
3215 bnad
->cfg_flags
|= BNAD_CF_ALLMULTI
;
3216 bna_rx_mcast_delall(bnad
->rx_info
[0].rx
);
3220 bnad_set_rx_mode(struct net_device
*netdev
)
3222 struct bnad
*bnad
= netdev_priv(netdev
);
3223 enum bna_rxmode new_mode
, mode_mask
;
3224 unsigned long flags
;
3226 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
3228 if (bnad
->rx_info
[0].rx
== NULL
) {
3229 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
3233 /* clear bnad flags to update it with new settings */
3234 bnad
->cfg_flags
&= ~(BNAD_CF_PROMISC
| BNAD_CF_DEFAULT
|
3238 if (netdev
->flags
& IFF_PROMISC
) {
3239 new_mode
|= BNAD_RXMODE_PROMISC_DEFAULT
;
3240 bnad
->cfg_flags
|= BNAD_CF_PROMISC
;
3242 bnad_set_rx_mcast_fltr(bnad
);
3244 if (bnad
->cfg_flags
& BNAD_CF_ALLMULTI
)
3245 new_mode
|= BNA_RXMODE_ALLMULTI
;
3247 bnad_set_rx_ucast_fltr(bnad
);
3249 if (bnad
->cfg_flags
& BNAD_CF_DEFAULT
)
3250 new_mode
|= BNA_RXMODE_DEFAULT
;
3253 mode_mask
= BNA_RXMODE_PROMISC
| BNA_RXMODE_DEFAULT
|
3254 BNA_RXMODE_ALLMULTI
;
3255 bna_rx_mode_set(bnad
->rx_info
[0].rx
, new_mode
, mode_mask
);
3257 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
3261 * bna_lock is used to sync writes to netdev->addr
3262 * conf_lock cannot be used since this call may be made
3263 * in a non-blocking context.
3266 bnad_set_mac_address(struct net_device
*netdev
, void *addr
)
3269 struct bnad
*bnad
= netdev_priv(netdev
);
3270 struct sockaddr
*sa
= (struct sockaddr
*)addr
;
3271 unsigned long flags
;
3273 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
3275 err
= bnad_mac_addr_set_locked(bnad
, sa
->sa_data
);
3277 ether_addr_copy(netdev
->dev_addr
, sa
->sa_data
);
3279 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
3285 bnad_mtu_set(struct bnad
*bnad
, int frame_size
)
3287 unsigned long flags
;
3289 init_completion(&bnad
->bnad_completions
.mtu_comp
);
3291 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
3292 bna_enet_mtu_set(&bnad
->bna
.enet
, frame_size
, bnad_cb_enet_mtu_set
);
3293 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
3295 wait_for_completion(&bnad
->bnad_completions
.mtu_comp
);
3297 return bnad
->bnad_completions
.mtu_comp_status
;
3301 bnad_change_mtu(struct net_device
*netdev
, int new_mtu
)
3304 struct bnad
*bnad
= netdev_priv(netdev
);
3305 u32 rx_count
= 0, frame
, new_frame
;
3307 if (new_mtu
+ ETH_HLEN
< ETH_ZLEN
|| new_mtu
> BNAD_JUMBO_MTU
)
3310 mutex_lock(&bnad
->conf_mutex
);
3313 netdev
->mtu
= new_mtu
;
3315 frame
= BNAD_FRAME_SIZE(mtu
);
3316 new_frame
= BNAD_FRAME_SIZE(new_mtu
);
3318 /* check if multi-buffer needs to be enabled */
3319 if (BNAD_PCI_DEV_IS_CAT2(bnad
) &&
3320 netif_running(bnad
->netdev
)) {
3321 /* only when transition is over 4K */
3322 if ((frame
<= 4096 && new_frame
> 4096) ||
3323 (frame
> 4096 && new_frame
<= 4096))
3324 rx_count
= bnad_reinit_rx(bnad
);
3327 /* rx_count > 0 - new rx created
3328 * - Linux set err = 0 and return
3330 err
= bnad_mtu_set(bnad
, new_frame
);
3334 mutex_unlock(&bnad
->conf_mutex
);
3339 bnad_vlan_rx_add_vid(struct net_device
*netdev
, __be16 proto
, u16 vid
)
3341 struct bnad
*bnad
= netdev_priv(netdev
);
3342 unsigned long flags
;
3344 if (!bnad
->rx_info
[0].rx
)
3347 mutex_lock(&bnad
->conf_mutex
);
3349 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
3350 bna_rx_vlan_add(bnad
->rx_info
[0].rx
, vid
);
3351 set_bit(vid
, bnad
->active_vlans
);
3352 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
3354 mutex_unlock(&bnad
->conf_mutex
);
3360 bnad_vlan_rx_kill_vid(struct net_device
*netdev
, __be16 proto
, u16 vid
)
3362 struct bnad
*bnad
= netdev_priv(netdev
);
3363 unsigned long flags
;
3365 if (!bnad
->rx_info
[0].rx
)
3368 mutex_lock(&bnad
->conf_mutex
);
3370 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
3371 clear_bit(vid
, bnad
->active_vlans
);
3372 bna_rx_vlan_del(bnad
->rx_info
[0].rx
, vid
);
3373 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
3375 mutex_unlock(&bnad
->conf_mutex
);
3380 static int bnad_set_features(struct net_device
*dev
, netdev_features_t features
)
3382 struct bnad
*bnad
= netdev_priv(dev
);
3383 netdev_features_t changed
= features
^ dev
->features
;
3385 if ((changed
& NETIF_F_HW_VLAN_CTAG_RX
) && netif_running(dev
)) {
3386 unsigned long flags
;
3388 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
3390 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
3391 bna_rx_vlan_strip_enable(bnad
->rx_info
[0].rx
);
3393 bna_rx_vlan_strip_disable(bnad
->rx_info
[0].rx
);
3395 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
3401 #ifdef CONFIG_NET_POLL_CONTROLLER
3403 bnad_netpoll(struct net_device
*netdev
)
3405 struct bnad
*bnad
= netdev_priv(netdev
);
3406 struct bnad_rx_info
*rx_info
;
3407 struct bnad_rx_ctrl
*rx_ctrl
;
3411 if (!(bnad
->cfg_flags
& BNAD_CF_MSIX
)) {
3412 bna_intx_disable(&bnad
->bna
, curr_mask
);
3413 bnad_isr(bnad
->pcidev
->irq
, netdev
);
3414 bna_intx_enable(&bnad
->bna
, curr_mask
);
3417 * Tx processing may happen in sending context, so no need
3418 * to explicitly process completions here
3422 for (i
= 0; i
< bnad
->num_rx
; i
++) {
3423 rx_info
= &bnad
->rx_info
[i
];
3426 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++) {
3427 rx_ctrl
= &rx_info
->rx_ctrl
[j
];
3429 bnad_netif_rx_schedule_poll(bnad
,
3437 static const struct net_device_ops bnad_netdev_ops
= {
3438 .ndo_open
= bnad_open
,
3439 .ndo_stop
= bnad_stop
,
3440 .ndo_start_xmit
= bnad_start_xmit
,
3441 .ndo_get_stats64
= bnad_get_stats64
,
3442 .ndo_set_rx_mode
= bnad_set_rx_mode
,
3443 .ndo_validate_addr
= eth_validate_addr
,
3444 .ndo_set_mac_address
= bnad_set_mac_address
,
3445 .ndo_change_mtu
= bnad_change_mtu
,
3446 .ndo_vlan_rx_add_vid
= bnad_vlan_rx_add_vid
,
3447 .ndo_vlan_rx_kill_vid
= bnad_vlan_rx_kill_vid
,
3448 .ndo_set_features
= bnad_set_features
,
3449 #ifdef CONFIG_NET_POLL_CONTROLLER
3450 .ndo_poll_controller
= bnad_netpoll
3455 bnad_netdev_init(struct bnad
*bnad
, bool using_dac
)
3457 struct net_device
*netdev
= bnad
->netdev
;
3459 netdev
->hw_features
= NETIF_F_SG
| NETIF_F_RXCSUM
|
3460 NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
|
3461 NETIF_F_TSO
| NETIF_F_TSO6
| NETIF_F_HW_VLAN_CTAG_TX
|
3462 NETIF_F_HW_VLAN_CTAG_RX
;
3464 netdev
->vlan_features
= NETIF_F_SG
| NETIF_F_HIGHDMA
|
3465 NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
|
3466 NETIF_F_TSO
| NETIF_F_TSO6
;
3468 netdev
->features
|= netdev
->hw_features
| NETIF_F_HW_VLAN_CTAG_FILTER
;
3471 netdev
->features
|= NETIF_F_HIGHDMA
;
3473 netdev
->mem_start
= bnad
->mmio_start
;
3474 netdev
->mem_end
= bnad
->mmio_start
+ bnad
->mmio_len
- 1;
3476 netdev
->netdev_ops
= &bnad_netdev_ops
;
3477 bnad_set_ethtool_ops(netdev
);
3481 * 1. Initialize the bnad structure
3482 * 2. Setup netdev pointer in pci_dev
3483 * 3. Initialize no. of TxQ & CQs & MSIX vectors
3484 * 4. Initialize work queue.
3487 bnad_init(struct bnad
*bnad
,
3488 struct pci_dev
*pdev
, struct net_device
*netdev
)
3490 unsigned long flags
;
3492 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
3493 pci_set_drvdata(pdev
, netdev
);
3495 bnad
->netdev
= netdev
;
3496 bnad
->pcidev
= pdev
;
3497 bnad
->mmio_start
= pci_resource_start(pdev
, 0);
3498 bnad
->mmio_len
= pci_resource_len(pdev
, 0);
3499 bnad
->bar0
= ioremap_nocache(bnad
->mmio_start
, bnad
->mmio_len
);
3501 dev_err(&pdev
->dev
, "ioremap for bar0 failed\n");
3504 dev_info(&pdev
->dev
, "bar0 mapped to %p, len %llu\n", bnad
->bar0
,
3505 (unsigned long long) bnad
->mmio_len
);
3507 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
3508 if (!bnad_msix_disable
)
3509 bnad
->cfg_flags
= BNAD_CF_MSIX
;
3511 bnad
->cfg_flags
|= BNAD_CF_DIM_ENABLED
;
3513 bnad_q_num_init(bnad
);
3514 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
3516 bnad
->msix_num
= (bnad
->num_tx
* bnad
->num_txq_per_tx
) +
3517 (bnad
->num_rx
* bnad
->num_rxp_per_rx
) +
3518 BNAD_MAILBOX_MSIX_VECTORS
;
3520 bnad
->txq_depth
= BNAD_TXQ_DEPTH
;
3521 bnad
->rxq_depth
= BNAD_RXQ_DEPTH
;
3523 bnad
->tx_coalescing_timeo
= BFI_TX_COALESCING_TIMEO
;
3524 bnad
->rx_coalescing_timeo
= BFI_RX_COALESCING_TIMEO
;
3526 sprintf(bnad
->wq_name
, "%s_wq_%d", BNAD_NAME
, bnad
->id
);
3527 bnad
->work_q
= create_singlethread_workqueue(bnad
->wq_name
);
3528 if (!bnad
->work_q
) {
3529 iounmap(bnad
->bar0
);
3537 * Must be called after bnad_pci_uninit()
3538 * so that iounmap() and pci_set_drvdata(NULL)
3539 * happens only after PCI uninitialization.
3542 bnad_uninit(struct bnad
*bnad
)
3545 flush_workqueue(bnad
->work_q
);
3546 destroy_workqueue(bnad
->work_q
);
3547 bnad
->work_q
= NULL
;
3551 iounmap(bnad
->bar0
);
3556 a) Per ioceth mutes used for serializing configuration
3557 changes from OS interface
3558 b) spin lock used to protect bna state machine
3561 bnad_lock_init(struct bnad
*bnad
)
3563 spin_lock_init(&bnad
->bna_lock
);
3564 mutex_init(&bnad
->conf_mutex
);
3565 mutex_init(&bnad_list_mutex
);
3569 bnad_lock_uninit(struct bnad
*bnad
)
3571 mutex_destroy(&bnad
->conf_mutex
);
3572 mutex_destroy(&bnad_list_mutex
);
3575 /* PCI Initialization */
3577 bnad_pci_init(struct bnad
*bnad
,
3578 struct pci_dev
*pdev
, bool *using_dac
)
3582 err
= pci_enable_device(pdev
);
3585 err
= pci_request_regions(pdev
, BNAD_NAME
);
3587 goto disable_device
;
3588 if (!dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64))) {
3591 err
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
3593 goto release_regions
;
3596 pci_set_master(pdev
);
3600 pci_release_regions(pdev
);
3602 pci_disable_device(pdev
);
3608 bnad_pci_uninit(struct pci_dev
*pdev
)
3610 pci_release_regions(pdev
);
3611 pci_disable_device(pdev
);
3615 bnad_pci_probe(struct pci_dev
*pdev
,
3616 const struct pci_device_id
*pcidev_id
)
3622 struct net_device
*netdev
;
3623 struct bfa_pcidev pcidev_info
;
3624 unsigned long flags
;
3626 mutex_lock(&bnad_fwimg_mutex
);
3627 if (!cna_get_firmware_buf(pdev
)) {
3628 mutex_unlock(&bnad_fwimg_mutex
);
3629 dev_err(&pdev
->dev
, "failed to load firmware image!\n");
3632 mutex_unlock(&bnad_fwimg_mutex
);
3635 * Allocates sizeof(struct net_device + struct bnad)
3636 * bnad = netdev->priv
3638 netdev
= alloc_etherdev(sizeof(struct bnad
));
3643 bnad
= netdev_priv(netdev
);
3644 bnad_lock_init(bnad
);
3645 bnad_add_to_list(bnad
);
3647 mutex_lock(&bnad
->conf_mutex
);
3649 * PCI initialization
3650 * Output : using_dac = 1 for 64 bit DMA
3651 * = 0 for 32 bit DMA
3654 err
= bnad_pci_init(bnad
, pdev
, &using_dac
);
3659 * Initialize bnad structure
3660 * Setup relation between pci_dev & netdev
3662 err
= bnad_init(bnad
, pdev
, netdev
);
3666 /* Initialize netdev structure, set up ethtool ops */
3667 bnad_netdev_init(bnad
, using_dac
);
3669 /* Set link to down state */
3670 netif_carrier_off(netdev
);
3672 /* Setup the debugfs node for this bfad */
3673 if (bna_debugfs_enable
)
3674 bnad_debugfs_init(bnad
);
3676 /* Get resource requirement form bna */
3677 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
3678 bna_res_req(&bnad
->res_info
[0]);
3679 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
3681 /* Allocate resources from bna */
3682 err
= bnad_res_alloc(bnad
, &bnad
->res_info
[0], BNA_RES_T_MAX
);
3688 /* Setup pcidev_info for bna_init() */
3689 pcidev_info
.pci_slot
= PCI_SLOT(bnad
->pcidev
->devfn
);
3690 pcidev_info
.pci_func
= PCI_FUNC(bnad
->pcidev
->devfn
);
3691 pcidev_info
.device_id
= bnad
->pcidev
->device
;
3692 pcidev_info
.pci_bar_kva
= bnad
->bar0
;
3694 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
3695 bna_init(bna
, bnad
, &pcidev_info
, &bnad
->res_info
[0]);
3696 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
3698 bnad
->stats
.bna_stats
= &bna
->stats
;
3700 bnad_enable_msix(bnad
);
3701 err
= bnad_mbox_irq_alloc(bnad
);
3706 setup_timer(&bnad
->bna
.ioceth
.ioc
.ioc_timer
, bnad_ioc_timeout
,
3707 (unsigned long)bnad
);
3708 setup_timer(&bnad
->bna
.ioceth
.ioc
.hb_timer
, bnad_ioc_hb_check
,
3709 (unsigned long)bnad
);
3710 setup_timer(&bnad
->bna
.ioceth
.ioc
.iocpf_timer
, bnad_iocpf_timeout
,
3711 (unsigned long)bnad
);
3712 setup_timer(&bnad
->bna
.ioceth
.ioc
.sem_timer
, bnad_iocpf_sem_timeout
,
3713 (unsigned long)bnad
);
3717 * If the call back comes with error, we bail out.
3718 * This is a catastrophic error.
3720 err
= bnad_ioceth_enable(bnad
);
3722 dev_err(&pdev
->dev
, "initialization failed err=%d\n", err
);
3726 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
3727 if (bna_num_txq_set(bna
, BNAD_NUM_TXQ
+ 1) ||
3728 bna_num_rxp_set(bna
, BNAD_NUM_RXP
+ 1)) {
3729 bnad_q_num_adjust(bnad
, bna_attr(bna
)->num_txq
- 1,
3730 bna_attr(bna
)->num_rxp
- 1);
3731 if (bna_num_txq_set(bna
, BNAD_NUM_TXQ
+ 1) ||
3732 bna_num_rxp_set(bna
, BNAD_NUM_RXP
+ 1))
3735 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
3737 goto disable_ioceth
;
3739 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
3740 bna_mod_res_req(&bnad
->bna
, &bnad
->mod_res_info
[0]);
3741 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
3743 err
= bnad_res_alloc(bnad
, &bnad
->mod_res_info
[0], BNA_MOD_RES_T_MAX
);
3746 goto disable_ioceth
;
3749 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
3750 bna_mod_init(&bnad
->bna
, &bnad
->mod_res_info
[0]);
3751 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
3753 /* Get the burnt-in mac */
3754 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
3755 bna_enet_perm_mac_get(&bna
->enet
, bnad
->perm_addr
);
3756 bnad_set_netdev_perm_addr(bnad
);
3757 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
3759 mutex_unlock(&bnad
->conf_mutex
);
3761 /* Finally, reguister with net_device layer */
3762 err
= register_netdev(netdev
);
3764 dev_err(&pdev
->dev
, "registering net device failed\n");
3767 set_bit(BNAD_RF_NETDEV_REGISTERED
, &bnad
->run_flags
);
3772 mutex_unlock(&bnad
->conf_mutex
);
3776 mutex_lock(&bnad
->conf_mutex
);
3777 bnad_res_free(bnad
, &bnad
->mod_res_info
[0], BNA_MOD_RES_T_MAX
);
3779 bnad_ioceth_disable(bnad
);
3780 del_timer_sync(&bnad
->bna
.ioceth
.ioc
.ioc_timer
);
3781 del_timer_sync(&bnad
->bna
.ioceth
.ioc
.sem_timer
);
3782 del_timer_sync(&bnad
->bna
.ioceth
.ioc
.hb_timer
);
3783 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
3785 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
3786 bnad_mbox_irq_free(bnad
);
3787 bnad_disable_msix(bnad
);
3789 bnad_res_free(bnad
, &bnad
->res_info
[0], BNA_RES_T_MAX
);
3791 /* Remove the debugfs node for this bnad */
3792 kfree(bnad
->regdata
);
3793 bnad_debugfs_uninit(bnad
);
3796 bnad_pci_uninit(pdev
);
3798 mutex_unlock(&bnad
->conf_mutex
);
3799 bnad_remove_from_list(bnad
);
3800 bnad_lock_uninit(bnad
);
3801 free_netdev(netdev
);
3806 bnad_pci_remove(struct pci_dev
*pdev
)
3808 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3811 unsigned long flags
;
3816 bnad
= netdev_priv(netdev
);
3819 if (test_and_clear_bit(BNAD_RF_NETDEV_REGISTERED
, &bnad
->run_flags
))
3820 unregister_netdev(netdev
);
3822 mutex_lock(&bnad
->conf_mutex
);
3823 bnad_ioceth_disable(bnad
);
3824 del_timer_sync(&bnad
->bna
.ioceth
.ioc
.ioc_timer
);
3825 del_timer_sync(&bnad
->bna
.ioceth
.ioc
.sem_timer
);
3826 del_timer_sync(&bnad
->bna
.ioceth
.ioc
.hb_timer
);
3827 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
3829 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
3831 bnad_res_free(bnad
, &bnad
->mod_res_info
[0], BNA_MOD_RES_T_MAX
);
3832 bnad_res_free(bnad
, &bnad
->res_info
[0], BNA_RES_T_MAX
);
3833 bnad_mbox_irq_free(bnad
);
3834 bnad_disable_msix(bnad
);
3835 bnad_pci_uninit(pdev
);
3836 mutex_unlock(&bnad
->conf_mutex
);
3837 bnad_remove_from_list(bnad
);
3838 bnad_lock_uninit(bnad
);
3839 /* Remove the debugfs node for this bnad */
3840 kfree(bnad
->regdata
);
3841 bnad_debugfs_uninit(bnad
);
3843 free_netdev(netdev
);
3846 static const struct pci_device_id bnad_pci_id_table
[] = {
3848 PCI_DEVICE(PCI_VENDOR_ID_BROCADE
,
3849 PCI_DEVICE_ID_BROCADE_CT
),
3850 .class = PCI_CLASS_NETWORK_ETHERNET
<< 8,
3851 .class_mask
= 0xffff00
3854 PCI_DEVICE(PCI_VENDOR_ID_BROCADE
,
3855 BFA_PCI_DEVICE_ID_CT2
),
3856 .class = PCI_CLASS_NETWORK_ETHERNET
<< 8,
3857 .class_mask
= 0xffff00
3862 MODULE_DEVICE_TABLE(pci
, bnad_pci_id_table
);
3864 static struct pci_driver bnad_pci_driver
= {
3866 .id_table
= bnad_pci_id_table
,
3867 .probe
= bnad_pci_probe
,
3868 .remove
= bnad_pci_remove
,
3872 bnad_module_init(void)
3876 pr_info("bna: QLogic BR-series 10G Ethernet driver - version: %s\n",
3879 bfa_nw_ioc_auto_recover(bnad_ioc_auto_recover
);
3881 err
= pci_register_driver(&bnad_pci_driver
);
3883 pr_err("bna: PCI driver registration failed err=%d\n", err
);
3891 bnad_module_exit(void)
3893 pci_unregister_driver(&bnad_pci_driver
);
3894 release_firmware(bfi_fw
);
3897 module_init(bnad_module_init
);
3898 module_exit(bnad_module_exit
);
3900 MODULE_AUTHOR("Brocade");
3901 MODULE_LICENSE("GPL");
3902 MODULE_DESCRIPTION("QLogic BR-series 10G PCIe Ethernet driver");
3903 MODULE_VERSION(BNAD_VERSION
);
3904 MODULE_FIRMWARE(CNA_FW_FILE_CT
);
3905 MODULE_FIRMWARE(CNA_FW_FILE_CT2
);