2 * Linux network driver for Brocade 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-2010 Brocade Communications Systems, Inc.
18 #include <linux/netdevice.h>
19 #include <linux/skbuff.h>
20 #include <linux/etherdevice.h>
22 #include <linux/ethtool.h>
23 #include <linux/if_vlan.h>
24 #include <linux/if_ether.h>
31 static DEFINE_MUTEX(bnad_fwimg_mutex
);
36 static uint bnad_msix_disable
;
37 module_param(bnad_msix_disable
, uint
, 0444);
38 MODULE_PARM_DESC(bnad_msix_disable
, "Disable MSIX mode");
40 static uint bnad_ioc_auto_recover
= 1;
41 module_param(bnad_ioc_auto_recover
, uint
, 0444);
42 MODULE_PARM_DESC(bnad_ioc_auto_recover
, "Enable / Disable auto recovery");
47 u32 bnad_rxqs_per_cq
= 2;
49 static const u8 bnad_bcast_addr
[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
54 #define BNAD_TX_UNMAPQ_DEPTH (bnad->txq_depth * 2)
56 #define BNAD_RX_UNMAPQ_DEPTH (bnad->rxq_depth)
58 #define BNAD_GET_MBOX_IRQ(_bnad) \
59 (((_bnad)->cfg_flags & BNAD_CF_MSIX) ? \
60 ((_bnad)->msix_table[(_bnad)->msix_num - 1].vector) : \
61 ((_bnad)->pcidev->irq))
63 #define BNAD_FILL_UNMAPQ_MEM_REQ(_res_info, _num, _depth) \
65 (_res_info)->res_type = BNA_RES_T_MEM; \
66 (_res_info)->res_u.mem_info.mem_type = BNA_MEM_T_KVA; \
67 (_res_info)->res_u.mem_info.num = (_num); \
68 (_res_info)->res_u.mem_info.len = \
69 sizeof(struct bnad_unmap_q) + \
70 (sizeof(struct bnad_skb_unmap) * ((_depth) - 1)); \
73 #define BNAD_TXRX_SYNC_MDELAY 250 /* 250 msecs */
76 * Reinitialize completions in CQ, once Rx is taken down
79 bnad_cq_cmpl_init(struct bnad
*bnad
, struct bna_ccb
*ccb
)
81 struct bna_cq_entry
*cmpl
, *next_cmpl
;
82 unsigned int wi_range
, wis
= 0, ccb_prod
= 0;
85 BNA_CQ_QPGE_PTR_GET(ccb_prod
, ccb
->sw_qpt
, cmpl
,
88 for (i
= 0; i
< ccb
->q_depth
; i
++) {
90 if (likely(--wi_range
))
93 BNA_QE_INDX_ADD(ccb_prod
, wis
, ccb
->q_depth
);
95 BNA_CQ_QPGE_PTR_GET(ccb_prod
, ccb
->sw_qpt
,
104 * Frees all pending Tx Bufs
105 * At this point no activity is expected on the Q,
106 * so DMA unmap & freeing is fine.
109 bnad_free_all_txbufs(struct bnad
*bnad
,
113 struct bnad_unmap_q
*unmap_q
= tcb
->unmap_q
;
114 struct bnad_skb_unmap
*unmap_array
;
115 struct sk_buff
*skb
= NULL
;
118 unmap_array
= unmap_q
->unmap_array
;
121 while (unmap_cons
< unmap_q
->q_depth
) {
122 skb
= unmap_array
[unmap_cons
].skb
;
127 unmap_array
[unmap_cons
].skb
= NULL
;
129 pci_unmap_single(bnad
->pcidev
,
130 pci_unmap_addr(&unmap_array
[unmap_cons
],
131 dma_addr
), skb_headlen(skb
),
134 pci_unmap_addr_set(&unmap_array
[unmap_cons
], dma_addr
, 0);
135 if (++unmap_cons
>= unmap_q
->q_depth
)
138 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
139 pci_unmap_page(bnad
->pcidev
,
140 pci_unmap_addr(&unmap_array
[unmap_cons
],
142 skb_shinfo(skb
)->frags
[i
].size
,
144 pci_unmap_addr_set(&unmap_array
[unmap_cons
], dma_addr
,
146 if (++unmap_cons
>= unmap_q
->q_depth
)
149 dev_kfree_skb_any(skb
);
153 /* Data Path Handlers */
156 * bnad_free_txbufs : Frees the Tx bufs on Tx completion
157 * Can be called in a) Interrupt context
162 bnad_free_txbufs(struct bnad
*bnad
,
165 u32 sent_packets
= 0, sent_bytes
= 0;
166 u16 wis
, unmap_cons
, updated_hw_cons
;
167 struct bnad_unmap_q
*unmap_q
= tcb
->unmap_q
;
168 struct bnad_skb_unmap
*unmap_array
;
173 * Just return if TX is stopped. This check is useful
174 * when bnad_free_txbufs() runs out of a tasklet scheduled
175 * before bnad_cb_tx_cleanup() cleared BNAD_TXQ_TX_STARTED bit
176 * but this routine runs actually after the cleanup has been
179 if (!test_bit(BNAD_TXQ_TX_STARTED
, &tcb
->flags
))
182 updated_hw_cons
= *(tcb
->hw_consumer_index
);
184 wis
= BNA_Q_INDEX_CHANGE(tcb
->consumer_index
,
185 updated_hw_cons
, tcb
->q_depth
);
187 BUG_ON(!(wis
<= BNA_QE_IN_USE_CNT(tcb
, tcb
->q_depth
)));
189 unmap_array
= unmap_q
->unmap_array
;
190 unmap_cons
= unmap_q
->consumer_index
;
192 prefetch(&unmap_array
[unmap_cons
+ 1]);
194 skb
= unmap_array
[unmap_cons
].skb
;
196 unmap_array
[unmap_cons
].skb
= NULL
;
199 sent_bytes
+= skb
->len
;
200 wis
-= BNA_TXQ_WI_NEEDED(1 + skb_shinfo(skb
)->nr_frags
);
202 pci_unmap_single(bnad
->pcidev
,
203 pci_unmap_addr(&unmap_array
[unmap_cons
],
204 dma_addr
), skb_headlen(skb
),
206 pci_unmap_addr_set(&unmap_array
[unmap_cons
], dma_addr
, 0);
207 BNA_QE_INDX_ADD(unmap_cons
, 1, unmap_q
->q_depth
);
209 prefetch(&unmap_array
[unmap_cons
+ 1]);
210 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
211 prefetch(&unmap_array
[unmap_cons
+ 1]);
213 pci_unmap_page(bnad
->pcidev
,
214 pci_unmap_addr(&unmap_array
[unmap_cons
],
216 skb_shinfo(skb
)->frags
[i
].size
,
218 pci_unmap_addr_set(&unmap_array
[unmap_cons
], dma_addr
,
220 BNA_QE_INDX_ADD(unmap_cons
, 1, unmap_q
->q_depth
);
222 dev_kfree_skb_any(skb
);
225 /* Update consumer pointers. */
226 tcb
->consumer_index
= updated_hw_cons
;
227 unmap_q
->consumer_index
= unmap_cons
;
229 tcb
->txq
->tx_packets
+= sent_packets
;
230 tcb
->txq
->tx_bytes
+= sent_bytes
;
235 /* Tx Free Tasklet function */
236 /* Frees for all the tcb's in all the Tx's */
238 * Scheduled from sending context, so that
239 * the fat Tx lock is not held for too long
240 * in the sending context.
243 bnad_tx_free_tasklet(unsigned long bnad_ptr
)
245 struct bnad
*bnad
= (struct bnad
*)bnad_ptr
;
250 for (i
= 0; i
< bnad
->num_tx
; i
++) {
251 for (j
= 0; j
< bnad
->num_txq_per_tx
; j
++) {
252 tcb
= bnad
->tx_info
[i
].tcb
[j
];
255 if (((u16
) (*tcb
->hw_consumer_index
) !=
256 tcb
->consumer_index
) &&
257 (!test_and_set_bit(BNAD_TXQ_FREE_SENT
,
259 acked
= bnad_free_txbufs(bnad
, tcb
);
260 if (likely(test_bit(BNAD_TXQ_TX_STARTED
,
262 bna_ib_ack(tcb
->i_dbell
, acked
);
263 smp_mb__before_clear_bit();
264 clear_bit(BNAD_TXQ_FREE_SENT
, &tcb
->flags
);
266 if (unlikely(!test_bit(BNAD_TXQ_TX_STARTED
,
269 if (netif_queue_stopped(bnad
->netdev
)) {
270 if (acked
&& netif_carrier_ok(bnad
->netdev
) &&
271 BNA_QE_FREE_CNT(tcb
, tcb
->q_depth
) >=
272 BNAD_NETIF_WAKE_THRESHOLD
) {
273 netif_wake_queue(bnad
->netdev
);
275 /* Counters for individual TxQs? */
276 BNAD_UPDATE_CTR(bnad
,
285 bnad_tx(struct bnad
*bnad
, struct bna_tcb
*tcb
)
287 struct net_device
*netdev
= bnad
->netdev
;
290 if (test_and_set_bit(BNAD_TXQ_FREE_SENT
, &tcb
->flags
))
293 sent
= bnad_free_txbufs(bnad
, tcb
);
295 if (netif_queue_stopped(netdev
) &&
296 netif_carrier_ok(netdev
) &&
297 BNA_QE_FREE_CNT(tcb
, tcb
->q_depth
) >=
298 BNAD_NETIF_WAKE_THRESHOLD
) {
299 if (test_bit(BNAD_TXQ_TX_STARTED
, &tcb
->flags
)) {
300 netif_wake_queue(netdev
);
301 BNAD_UPDATE_CTR(bnad
, netif_queue_wakeup
);
306 if (likely(test_bit(BNAD_TXQ_TX_STARTED
, &tcb
->flags
)))
307 bna_ib_ack(tcb
->i_dbell
, sent
);
309 smp_mb__before_clear_bit();
310 clear_bit(BNAD_TXQ_FREE_SENT
, &tcb
->flags
);
315 /* MSIX Tx Completion Handler */
317 bnad_msix_tx(int irq
, void *data
)
319 struct bna_tcb
*tcb
= (struct bna_tcb
*)data
;
320 struct bnad
*bnad
= tcb
->bnad
;
328 bnad_reset_rcb(struct bnad
*bnad
, struct bna_rcb
*rcb
)
330 struct bnad_unmap_q
*unmap_q
= rcb
->unmap_q
;
332 rcb
->producer_index
= 0;
333 rcb
->consumer_index
= 0;
335 unmap_q
->producer_index
= 0;
336 unmap_q
->consumer_index
= 0;
340 bnad_free_all_rxbufs(struct bnad
*bnad
, struct bna_rcb
*rcb
)
342 struct bnad_unmap_q
*unmap_q
;
346 unmap_q
= rcb
->unmap_q
;
347 for (unmap_cons
= 0; unmap_cons
< unmap_q
->q_depth
; unmap_cons
++) {
348 skb
= unmap_q
->unmap_array
[unmap_cons
].skb
;
351 unmap_q
->unmap_array
[unmap_cons
].skb
= NULL
;
352 pci_unmap_single(bnad
->pcidev
, pci_unmap_addr(&unmap_q
->
353 unmap_array
[unmap_cons
],
354 dma_addr
), rcb
->rxq
->buffer_size
,
358 bnad_reset_rcb(bnad
, rcb
);
362 bnad_alloc_n_post_rxbufs(struct bnad
*bnad
, struct bna_rcb
*rcb
)
364 u16 to_alloc
, alloced
, unmap_prod
, wi_range
;
365 struct bnad_unmap_q
*unmap_q
= rcb
->unmap_q
;
366 struct bnad_skb_unmap
*unmap_array
;
367 struct bna_rxq_entry
*rxent
;
373 BNA_QE_FREE_CNT(unmap_q
, unmap_q
->q_depth
);
375 unmap_array
= unmap_q
->unmap_array
;
376 unmap_prod
= unmap_q
->producer_index
;
378 BNA_RXQ_QPGE_PTR_GET(unmap_prod
, rcb
->sw_qpt
, rxent
, wi_range
);
382 BNA_RXQ_QPGE_PTR_GET(unmap_prod
, rcb
->sw_qpt
, rxent
,
385 skb
= alloc_skb(rcb
->rxq
->buffer_size
+ NET_IP_ALIGN
,
387 if (unlikely(!skb
)) {
388 BNAD_UPDATE_CTR(bnad
, rxbuf_alloc_failed
);
391 skb
->dev
= bnad
->netdev
;
392 skb_reserve(skb
, NET_IP_ALIGN
);
393 unmap_array
[unmap_prod
].skb
= skb
;
394 dma_addr
= pci_map_single(bnad
->pcidev
, skb
->data
,
395 rcb
->rxq
->buffer_size
, PCI_DMA_FROMDEVICE
);
396 pci_unmap_addr_set(&unmap_array
[unmap_prod
], dma_addr
,
398 BNA_SET_DMA_ADDR(dma_addr
, &rxent
->host_addr
);
399 BNA_QE_INDX_ADD(unmap_prod
, 1, unmap_q
->q_depth
);
407 if (likely(alloced
)) {
408 unmap_q
->producer_index
= unmap_prod
;
409 rcb
->producer_index
= unmap_prod
;
411 if (likely(test_bit(BNAD_RXQ_STARTED
, &rcb
->flags
)))
412 bna_rxq_prod_indx_doorbell(rcb
);
417 bnad_refill_rxq(struct bnad
*bnad
, struct bna_rcb
*rcb
)
419 struct bnad_unmap_q
*unmap_q
= rcb
->unmap_q
;
421 if (!test_and_set_bit(BNAD_RXQ_REFILL
, &rcb
->flags
)) {
422 if (BNA_QE_FREE_CNT(unmap_q
, unmap_q
->q_depth
)
423 >> BNAD_RXQ_REFILL_THRESHOLD_SHIFT
)
424 bnad_alloc_n_post_rxbufs(bnad
, rcb
);
425 smp_mb__before_clear_bit();
426 clear_bit(BNAD_RXQ_REFILL
, &rcb
->flags
);
431 bnad_poll_cq(struct bnad
*bnad
, struct bna_ccb
*ccb
, int budget
)
433 struct bna_cq_entry
*cmpl
, *next_cmpl
;
434 struct bna_rcb
*rcb
= NULL
;
435 unsigned int wi_range
, packets
= 0, wis
= 0;
436 struct bnad_unmap_q
*unmap_q
;
439 u32 qid0
= ccb
->rcb
[0]->rxq
->rxq_id
;
440 struct bna_pkt_rate
*pkt_rt
= &ccb
->pkt_rate
;
442 if (!test_bit(BNAD_RXQ_STARTED
, &ccb
->rcb
[0]->flags
))
445 prefetch(bnad
->netdev
);
446 BNA_CQ_QPGE_PTR_GET(ccb
->producer_index
, ccb
->sw_qpt
, cmpl
,
448 BUG_ON(!(wi_range
<= ccb
->q_depth
));
449 while (cmpl
->valid
&& packets
< budget
) {
451 BNA_UPDATE_PKT_CNT(pkt_rt
, ntohs(cmpl
->length
));
453 if (qid0
== cmpl
->rxq_id
)
458 unmap_q
= rcb
->unmap_q
;
460 skb
= unmap_q
->unmap_array
[unmap_q
->consumer_index
].skb
;
462 unmap_q
->unmap_array
[unmap_q
->consumer_index
].skb
= NULL
;
463 pci_unmap_single(bnad
->pcidev
,
464 pci_unmap_addr(&unmap_q
->
465 unmap_array
[unmap_q
->
468 rcb
->rxq
->buffer_size
,
470 BNA_QE_INDX_ADD(unmap_q
->consumer_index
, 1, unmap_q
->q_depth
);
472 /* Should be more efficient ? Performance ? */
473 BNA_QE_INDX_ADD(rcb
->consumer_index
, 1, rcb
->q_depth
);
476 if (likely(--wi_range
))
477 next_cmpl
= cmpl
+ 1;
479 BNA_QE_INDX_ADD(ccb
->producer_index
, wis
, ccb
->q_depth
);
481 BNA_CQ_QPGE_PTR_GET(ccb
->producer_index
, ccb
->sw_qpt
,
482 next_cmpl
, wi_range
);
483 BUG_ON(!(wi_range
<= ccb
->q_depth
));
487 flags
= ntohl(cmpl
->flags
);
490 (BNA_CQ_EF_MAC_ERROR
| BNA_CQ_EF_FCS_ERROR
|
491 BNA_CQ_EF_TOO_LONG
))) {
492 dev_kfree_skb_any(skb
);
493 rcb
->rxq
->rx_packets_with_error
++;
497 skb_put(skb
, ntohs(cmpl
->length
));
500 (((flags
& BNA_CQ_EF_IPV4
) &&
501 (flags
& BNA_CQ_EF_L3_CKSUM_OK
)) ||
502 (flags
& BNA_CQ_EF_IPV6
)) &&
503 (flags
& (BNA_CQ_EF_TCP
| BNA_CQ_EF_UDP
)) &&
504 (flags
& BNA_CQ_EF_L4_CKSUM_OK
)))
505 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
507 skb_checksum_none_assert(skb
);
509 rcb
->rxq
->rx_packets
++;
510 rcb
->rxq
->rx_bytes
+= skb
->len
;
511 skb
->protocol
= eth_type_trans(skb
, bnad
->netdev
);
513 if (bnad
->vlan_grp
&& (flags
& BNA_CQ_EF_VLAN
)) {
514 struct bnad_rx_ctrl
*rx_ctrl
=
515 (struct bnad_rx_ctrl
*)ccb
->ctrl
;
516 if (skb
->ip_summed
== CHECKSUM_UNNECESSARY
)
517 vlan_gro_receive(&rx_ctrl
->napi
, bnad
->vlan_grp
,
518 ntohs(cmpl
->vlan_tag
), skb
);
520 vlan_hwaccel_receive_skb(skb
,
522 ntohs(cmpl
->vlan_tag
));
524 } else { /* Not VLAN tagged/stripped */
525 struct bnad_rx_ctrl
*rx_ctrl
=
526 (struct bnad_rx_ctrl
*)ccb
->ctrl
;
527 if (skb
->ip_summed
== CHECKSUM_UNNECESSARY
)
528 napi_gro_receive(&rx_ctrl
->napi
, skb
);
530 netif_receive_skb(skb
);
538 BNA_QE_INDX_ADD(ccb
->producer_index
, wis
, ccb
->q_depth
);
541 if (likely(test_bit(BNAD_RXQ_STARTED
, &ccb
->rcb
[0]->flags
)))
542 bna_ib_ack(ccb
->i_dbell
, packets
);
543 bnad_refill_rxq(bnad
, ccb
->rcb
[0]);
545 bnad_refill_rxq(bnad
, ccb
->rcb
[1]);
547 if (likely(test_bit(BNAD_RXQ_STARTED
, &ccb
->rcb
[0]->flags
)))
548 bna_ib_ack(ccb
->i_dbell
, 0);
555 bnad_disable_rx_irq(struct bnad
*bnad
, struct bna_ccb
*ccb
)
557 if (unlikely(!test_bit(BNAD_RXQ_STARTED
, &ccb
->rcb
[0]->flags
)))
560 bna_ib_coalescing_timer_set(ccb
->i_dbell
, 0);
561 bna_ib_ack(ccb
->i_dbell
, 0);
565 bnad_enable_rx_irq(struct bnad
*bnad
, struct bna_ccb
*ccb
)
569 /* Because of polling context */
570 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
571 bnad_enable_rx_irq_unsafe(ccb
);
572 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
576 bnad_netif_rx_schedule_poll(struct bnad
*bnad
, struct bna_ccb
*ccb
)
578 struct bnad_rx_ctrl
*rx_ctrl
= (struct bnad_rx_ctrl
*)(ccb
->ctrl
);
579 struct napi_struct
*napi
= &rx_ctrl
->napi
;
581 if (likely(napi_schedule_prep(napi
))) {
582 bnad_disable_rx_irq(bnad
, ccb
);
583 __napi_schedule(napi
);
585 BNAD_UPDATE_CTR(bnad
, netif_rx_schedule
);
588 /* MSIX Rx Path Handler */
590 bnad_msix_rx(int irq
, void *data
)
592 struct bna_ccb
*ccb
= (struct bna_ccb
*)data
;
593 struct bnad
*bnad
= ccb
->bnad
;
595 bnad_netif_rx_schedule_poll(bnad
, ccb
);
600 /* Interrupt handlers */
602 /* Mbox Interrupt Handlers */
604 bnad_msix_mbox_handler(int irq
, void *data
)
608 struct bnad
*bnad
= (struct bnad
*)data
;
610 if (unlikely(test_bit(BNAD_RF_MBOX_IRQ_DISABLED
, &bnad
->run_flags
)))
613 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
615 bna_intr_status_get(&bnad
->bna
, intr_status
);
617 if (BNA_IS_MBOX_ERR_INTR(intr_status
))
618 bna_mbox_handler(&bnad
->bna
, intr_status
);
620 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
626 bnad_isr(int irq
, void *data
)
631 struct bnad
*bnad
= (struct bnad
*)data
;
632 struct bnad_rx_info
*rx_info
;
633 struct bnad_rx_ctrl
*rx_ctrl
;
635 if (unlikely(test_bit(BNAD_RF_MBOX_IRQ_DISABLED
, &bnad
->run_flags
)))
638 bna_intr_status_get(&bnad
->bna
, intr_status
);
640 if (unlikely(!intr_status
))
643 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
645 if (BNA_IS_MBOX_ERR_INTR(intr_status
))
646 bna_mbox_handler(&bnad
->bna
, intr_status
);
648 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
650 if (!BNA_IS_INTX_DATA_INTR(intr_status
))
653 /* Process data interrupts */
655 for (i
= 0; i
< bnad
->num_tx
; i
++) {
656 for (j
= 0; j
< bnad
->num_txq_per_tx
; j
++)
657 bnad_tx(bnad
, bnad
->tx_info
[i
].tcb
[j
]);
660 for (i
= 0; i
< bnad
->num_rx
; i
++) {
661 rx_info
= &bnad
->rx_info
[i
];
664 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++) {
665 rx_ctrl
= &rx_info
->rx_ctrl
[j
];
667 bnad_netif_rx_schedule_poll(bnad
,
675 * Called in interrupt / callback context
676 * with bna_lock held, so cfg_flags access is OK
679 bnad_enable_mbox_irq(struct bnad
*bnad
)
681 clear_bit(BNAD_RF_MBOX_IRQ_DISABLED
, &bnad
->run_flags
);
683 BNAD_UPDATE_CTR(bnad
, mbox_intr_enabled
);
687 * Called with bnad->bna_lock held b'cos of
688 * bnad->cfg_flags access.
691 bnad_disable_mbox_irq(struct bnad
*bnad
)
693 set_bit(BNAD_RF_MBOX_IRQ_DISABLED
, &bnad
->run_flags
);
695 BNAD_UPDATE_CTR(bnad
, mbox_intr_disabled
);
699 bnad_set_netdev_perm_addr(struct bnad
*bnad
)
701 struct net_device
*netdev
= bnad
->netdev
;
703 memcpy(netdev
->perm_addr
, &bnad
->perm_addr
, netdev
->addr_len
);
704 if (is_zero_ether_addr(netdev
->dev_addr
))
705 memcpy(netdev
->dev_addr
, &bnad
->perm_addr
, netdev
->addr_len
);
708 /* Control Path Handlers */
712 bnad_cb_device_enable_mbox_intr(struct bnad
*bnad
)
714 bnad_enable_mbox_irq(bnad
);
718 bnad_cb_device_disable_mbox_intr(struct bnad
*bnad
)
720 bnad_disable_mbox_irq(bnad
);
724 bnad_cb_device_enabled(struct bnad
*bnad
, enum bna_cb_status status
)
726 complete(&bnad
->bnad_completions
.ioc_comp
);
727 bnad
->bnad_completions
.ioc_comp_status
= status
;
731 bnad_cb_device_disabled(struct bnad
*bnad
, enum bna_cb_status status
)
733 complete(&bnad
->bnad_completions
.ioc_comp
);
734 bnad
->bnad_completions
.ioc_comp_status
= status
;
738 bnad_cb_port_disabled(void *arg
, enum bna_cb_status status
)
740 struct bnad
*bnad
= (struct bnad
*)arg
;
742 complete(&bnad
->bnad_completions
.port_comp
);
744 netif_carrier_off(bnad
->netdev
);
748 bnad_cb_port_link_status(struct bnad
*bnad
,
749 enum bna_link_status link_status
)
753 link_up
= (link_status
== BNA_LINK_UP
) || (link_status
== BNA_CEE_UP
);
755 if (link_status
== BNA_CEE_UP
) {
756 set_bit(BNAD_RF_CEE_RUNNING
, &bnad
->run_flags
);
757 BNAD_UPDATE_CTR(bnad
, cee_up
);
759 clear_bit(BNAD_RF_CEE_RUNNING
, &bnad
->run_flags
);
762 if (!netif_carrier_ok(bnad
->netdev
)) {
763 struct bna_tcb
*tcb
= bnad
->tx_info
[0].tcb
[0];
766 pr_warn("bna: %s link up\n",
768 netif_carrier_on(bnad
->netdev
);
769 BNAD_UPDATE_CTR(bnad
, link_toggle
);
770 if (test_bit(BNAD_TXQ_TX_STARTED
, &tcb
->flags
)) {
771 /* Force an immediate Transmit Schedule */
772 pr_info("bna: %s TX_STARTED\n",
774 netif_wake_queue(bnad
->netdev
);
775 BNAD_UPDATE_CTR(bnad
, netif_queue_wakeup
);
777 netif_stop_queue(bnad
->netdev
);
778 BNAD_UPDATE_CTR(bnad
, netif_queue_stop
);
782 if (netif_carrier_ok(bnad
->netdev
)) {
783 pr_warn("bna: %s link down\n",
785 netif_carrier_off(bnad
->netdev
);
786 BNAD_UPDATE_CTR(bnad
, link_toggle
);
792 bnad_cb_tx_disabled(void *arg
, struct bna_tx
*tx
,
793 enum bna_cb_status status
)
795 struct bnad
*bnad
= (struct bnad
*)arg
;
797 complete(&bnad
->bnad_completions
.tx_comp
);
801 bnad_cb_tcb_setup(struct bnad
*bnad
, struct bna_tcb
*tcb
)
803 struct bnad_tx_info
*tx_info
=
804 (struct bnad_tx_info
*)tcb
->txq
->tx
->priv
;
805 struct bnad_unmap_q
*unmap_q
= tcb
->unmap_q
;
807 tx_info
->tcb
[tcb
->id
] = tcb
;
808 unmap_q
->producer_index
= 0;
809 unmap_q
->consumer_index
= 0;
810 unmap_q
->q_depth
= BNAD_TX_UNMAPQ_DEPTH
;
814 bnad_cb_tcb_destroy(struct bnad
*bnad
, struct bna_tcb
*tcb
)
816 struct bnad_tx_info
*tx_info
=
817 (struct bnad_tx_info
*)tcb
->txq
->tx
->priv
;
818 struct bnad_unmap_q
*unmap_q
= tcb
->unmap_q
;
820 while (test_and_set_bit(BNAD_TXQ_FREE_SENT
, &tcb
->flags
))
823 bnad_free_all_txbufs(bnad
, tcb
);
825 unmap_q
->producer_index
= 0;
826 unmap_q
->consumer_index
= 0;
828 smp_mb__before_clear_bit();
829 clear_bit(BNAD_TXQ_FREE_SENT
, &tcb
->flags
);
831 tx_info
->tcb
[tcb
->id
] = NULL
;
835 bnad_cb_rcb_setup(struct bnad
*bnad
, struct bna_rcb
*rcb
)
837 struct bnad_unmap_q
*unmap_q
= rcb
->unmap_q
;
839 unmap_q
->producer_index
= 0;
840 unmap_q
->consumer_index
= 0;
841 unmap_q
->q_depth
= BNAD_RX_UNMAPQ_DEPTH
;
845 bnad_cb_rcb_destroy(struct bnad
*bnad
, struct bna_rcb
*rcb
)
847 bnad_free_all_rxbufs(bnad
, rcb
);
851 bnad_cb_ccb_setup(struct bnad
*bnad
, struct bna_ccb
*ccb
)
853 struct bnad_rx_info
*rx_info
=
854 (struct bnad_rx_info
*)ccb
->cq
->rx
->priv
;
856 rx_info
->rx_ctrl
[ccb
->id
].ccb
= ccb
;
857 ccb
->ctrl
= &rx_info
->rx_ctrl
[ccb
->id
];
861 bnad_cb_ccb_destroy(struct bnad
*bnad
, struct bna_ccb
*ccb
)
863 struct bnad_rx_info
*rx_info
=
864 (struct bnad_rx_info
*)ccb
->cq
->rx
->priv
;
866 rx_info
->rx_ctrl
[ccb
->id
].ccb
= NULL
;
870 bnad_cb_tx_stall(struct bnad
*bnad
, struct bna_tcb
*tcb
)
872 struct bnad_tx_info
*tx_info
=
873 (struct bnad_tx_info
*)tcb
->txq
->tx
->priv
;
875 if (tx_info
!= &bnad
->tx_info
[0])
878 clear_bit(BNAD_TXQ_TX_STARTED
, &tcb
->flags
);
879 netif_stop_queue(bnad
->netdev
);
880 pr_info("bna: %s TX_STOPPED\n", bnad
->netdev
->name
);
884 bnad_cb_tx_resume(struct bnad
*bnad
, struct bna_tcb
*tcb
)
886 struct bnad_unmap_q
*unmap_q
= tcb
->unmap_q
;
888 if (test_bit(BNAD_TXQ_TX_STARTED
, &tcb
->flags
))
891 clear_bit(BNAD_RF_TX_SHUTDOWN_DELAYED
, &bnad
->run_flags
);
893 while (test_and_set_bit(BNAD_TXQ_FREE_SENT
, &tcb
->flags
))
896 bnad_free_all_txbufs(bnad
, tcb
);
898 unmap_q
->producer_index
= 0;
899 unmap_q
->consumer_index
= 0;
901 smp_mb__before_clear_bit();
902 clear_bit(BNAD_TXQ_FREE_SENT
, &tcb
->flags
);
905 * Workaround for first device enable failure & we
906 * get a 0 MAC address. We try to get the MAC address
909 if (is_zero_ether_addr(&bnad
->perm_addr
.mac
[0])) {
910 bna_port_mac_get(&bnad
->bna
.port
, &bnad
->perm_addr
);
911 bnad_set_netdev_perm_addr(bnad
);
914 set_bit(BNAD_TXQ_TX_STARTED
, &tcb
->flags
);
916 if (netif_carrier_ok(bnad
->netdev
)) {
917 pr_info("bna: %s TX_STARTED\n", bnad
->netdev
->name
);
918 netif_wake_queue(bnad
->netdev
);
919 BNAD_UPDATE_CTR(bnad
, netif_queue_wakeup
);
924 bnad_cb_tx_cleanup(struct bnad
*bnad
, struct bna_tcb
*tcb
)
926 /* Delay only once for the whole Tx Path Shutdown */
927 if (!test_and_set_bit(BNAD_RF_TX_SHUTDOWN_DELAYED
, &bnad
->run_flags
))
928 mdelay(BNAD_TXRX_SYNC_MDELAY
);
932 bnad_cb_rx_cleanup(struct bnad
*bnad
,
935 clear_bit(BNAD_RXQ_STARTED
, &ccb
->rcb
[0]->flags
);
938 clear_bit(BNAD_RXQ_STARTED
, &ccb
->rcb
[1]->flags
);
940 if (!test_and_set_bit(BNAD_RF_RX_SHUTDOWN_DELAYED
, &bnad
->run_flags
))
941 mdelay(BNAD_TXRX_SYNC_MDELAY
);
945 bnad_cb_rx_post(struct bnad
*bnad
, struct bna_rcb
*rcb
)
947 struct bnad_unmap_q
*unmap_q
= rcb
->unmap_q
;
949 clear_bit(BNAD_RF_RX_SHUTDOWN_DELAYED
, &bnad
->run_flags
);
951 if (rcb
== rcb
->cq
->ccb
->rcb
[0])
952 bnad_cq_cmpl_init(bnad
, rcb
->cq
->ccb
);
954 bnad_free_all_rxbufs(bnad
, rcb
);
956 set_bit(BNAD_RXQ_STARTED
, &rcb
->flags
);
958 /* Now allocate & post buffers for this RCB */
959 /* !!Allocation in callback context */
960 if (!test_and_set_bit(BNAD_RXQ_REFILL
, &rcb
->flags
)) {
961 if (BNA_QE_FREE_CNT(unmap_q
, unmap_q
->q_depth
)
962 >> BNAD_RXQ_REFILL_THRESHOLD_SHIFT
)
963 bnad_alloc_n_post_rxbufs(bnad
, rcb
);
964 smp_mb__before_clear_bit();
965 clear_bit(BNAD_RXQ_REFILL
, &rcb
->flags
);
970 bnad_cb_rx_disabled(void *arg
, struct bna_rx
*rx
,
971 enum bna_cb_status status
)
973 struct bnad
*bnad
= (struct bnad
*)arg
;
975 complete(&bnad
->bnad_completions
.rx_comp
);
979 bnad_cb_rx_mcast_add(struct bnad
*bnad
, struct bna_rx
*rx
,
980 enum bna_cb_status status
)
982 bnad
->bnad_completions
.mcast_comp_status
= status
;
983 complete(&bnad
->bnad_completions
.mcast_comp
);
987 bnad_cb_stats_get(struct bnad
*bnad
, enum bna_cb_status status
,
988 struct bna_stats
*stats
)
990 if (status
== BNA_CB_SUCCESS
)
991 BNAD_UPDATE_CTR(bnad
, hw_stats_updates
);
993 if (!netif_running(bnad
->netdev
) ||
994 !test_bit(BNAD_RF_STATS_TIMER_RUNNING
, &bnad
->run_flags
))
997 mod_timer(&bnad
->stats_timer
,
998 jiffies
+ msecs_to_jiffies(BNAD_STATS_TIMER_FREQ
));
1001 /* Resource allocation, free functions */
1004 bnad_mem_free(struct bnad
*bnad
,
1005 struct bna_mem_info
*mem_info
)
1010 if (mem_info
->mdl
== NULL
)
1013 for (i
= 0; i
< mem_info
->num
; i
++) {
1014 if (mem_info
->mdl
[i
].kva
!= NULL
) {
1015 if (mem_info
->mem_type
== BNA_MEM_T_DMA
) {
1016 BNA_GET_DMA_ADDR(&(mem_info
->mdl
[i
].dma
),
1018 pci_free_consistent(bnad
->pcidev
,
1019 mem_info
->mdl
[i
].len
,
1020 mem_info
->mdl
[i
].kva
, dma_pa
);
1022 kfree(mem_info
->mdl
[i
].kva
);
1025 kfree(mem_info
->mdl
);
1026 mem_info
->mdl
= NULL
;
1030 bnad_mem_alloc(struct bnad
*bnad
,
1031 struct bna_mem_info
*mem_info
)
1036 if ((mem_info
->num
== 0) || (mem_info
->len
== 0)) {
1037 mem_info
->mdl
= NULL
;
1041 mem_info
->mdl
= kcalloc(mem_info
->num
, sizeof(struct bna_mem_descr
),
1043 if (mem_info
->mdl
== NULL
)
1046 if (mem_info
->mem_type
== BNA_MEM_T_DMA
) {
1047 for (i
= 0; i
< mem_info
->num
; i
++) {
1048 mem_info
->mdl
[i
].len
= mem_info
->len
;
1049 mem_info
->mdl
[i
].kva
=
1050 pci_alloc_consistent(bnad
->pcidev
,
1051 mem_info
->len
, &dma_pa
);
1053 if (mem_info
->mdl
[i
].kva
== NULL
)
1056 BNA_SET_DMA_ADDR(dma_pa
,
1057 &(mem_info
->mdl
[i
].dma
));
1060 for (i
= 0; i
< mem_info
->num
; i
++) {
1061 mem_info
->mdl
[i
].len
= mem_info
->len
;
1062 mem_info
->mdl
[i
].kva
= kzalloc(mem_info
->len
,
1064 if (mem_info
->mdl
[i
].kva
== NULL
)
1072 bnad_mem_free(bnad
, mem_info
);
1076 /* Free IRQ for Mailbox */
1078 bnad_mbox_irq_free(struct bnad
*bnad
,
1079 struct bna_intr_info
*intr_info
)
1082 unsigned long flags
;
1084 if (intr_info
->idl
== NULL
)
1087 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1088 bnad_disable_mbox_irq(bnad
);
1089 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1091 irq
= BNAD_GET_MBOX_IRQ(bnad
);
1092 free_irq(irq
, bnad
);
1094 kfree(intr_info
->idl
);
1098 * Allocates IRQ for Mailbox, but keep it disabled
1099 * This will be enabled once we get the mbox enable callback
1103 bnad_mbox_irq_alloc(struct bnad
*bnad
,
1104 struct bna_intr_info
*intr_info
)
1107 unsigned long flags
;
1109 irq_handler_t irq_handler
;
1111 /* Mbox should use only 1 vector */
1113 intr_info
->idl
= kzalloc(sizeof(*(intr_info
->idl
)), GFP_KERNEL
);
1114 if (!intr_info
->idl
)
1117 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1118 if (bnad
->cfg_flags
& BNAD_CF_MSIX
) {
1119 irq_handler
= (irq_handler_t
)bnad_msix_mbox_handler
;
1120 irq
= bnad
->msix_table
[bnad
->msix_num
- 1].vector
;
1122 intr_info
->intr_type
= BNA_INTR_T_MSIX
;
1123 intr_info
->idl
[0].vector
= bnad
->msix_num
- 1;
1125 irq_handler
= (irq_handler_t
)bnad_isr
;
1126 irq
= bnad
->pcidev
->irq
;
1127 flags
= IRQF_SHARED
;
1128 intr_info
->intr_type
= BNA_INTR_T_INTX
;
1129 /* intr_info->idl.vector = 0 ? */
1131 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1133 sprintf(bnad
->mbox_irq_name
, "%s", BNAD_NAME
);
1136 * Set the Mbox IRQ disable flag, so that the IRQ handler
1137 * called from request_irq() for SHARED IRQs do not execute
1139 set_bit(BNAD_RF_MBOX_IRQ_DISABLED
, &bnad
->run_flags
);
1141 BNAD_UPDATE_CTR(bnad
, mbox_intr_disabled
);
1143 err
= request_irq(irq
, irq_handler
, flags
,
1144 bnad
->mbox_irq_name
, bnad
);
1147 kfree(intr_info
->idl
);
1148 intr_info
->idl
= NULL
;
1155 bnad_txrx_irq_free(struct bnad
*bnad
, struct bna_intr_info
*intr_info
)
1157 kfree(intr_info
->idl
);
1158 intr_info
->idl
= NULL
;
1161 /* Allocates Interrupt Descriptor List for MSIX/INT-X vectors */
1163 bnad_txrx_irq_alloc(struct bnad
*bnad
, enum bnad_intr_source src
,
1164 uint txrx_id
, struct bna_intr_info
*intr_info
)
1166 int i
, vector_start
= 0;
1168 unsigned long flags
;
1170 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1171 cfg_flags
= bnad
->cfg_flags
;
1172 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1174 if (cfg_flags
& BNAD_CF_MSIX
) {
1175 intr_info
->intr_type
= BNA_INTR_T_MSIX
;
1176 intr_info
->idl
= kcalloc(intr_info
->num
,
1177 sizeof(struct bna_intr_descr
),
1179 if (!intr_info
->idl
)
1184 vector_start
= txrx_id
;
1188 vector_start
= bnad
->num_tx
* bnad
->num_txq_per_tx
+
1196 for (i
= 0; i
< intr_info
->num
; i
++)
1197 intr_info
->idl
[i
].vector
= vector_start
+ i
;
1199 intr_info
->intr_type
= BNA_INTR_T_INTX
;
1201 intr_info
->idl
= kcalloc(intr_info
->num
,
1202 sizeof(struct bna_intr_descr
),
1204 if (!intr_info
->idl
)
1209 intr_info
->idl
[0].vector
= 0x1; /* Bit mask : Tx IB */
1213 intr_info
->idl
[0].vector
= 0x2; /* Bit mask : Rx IB */
1221 * NOTE: Should be called for MSIX only
1222 * Unregisters Tx MSIX vector(s) from the kernel
1225 bnad_tx_msix_unregister(struct bnad
*bnad
, struct bnad_tx_info
*tx_info
,
1231 for (i
= 0; i
< num_txqs
; i
++) {
1232 if (tx_info
->tcb
[i
] == NULL
)
1235 vector_num
= tx_info
->tcb
[i
]->intr_vector
;
1236 free_irq(bnad
->msix_table
[vector_num
].vector
, tx_info
->tcb
[i
]);
1241 * NOTE: Should be called for MSIX only
1242 * Registers Tx MSIX vector(s) and ISR(s), cookie with the kernel
1245 bnad_tx_msix_register(struct bnad
*bnad
, struct bnad_tx_info
*tx_info
,
1246 uint tx_id
, int num_txqs
)
1252 for (i
= 0; i
< num_txqs
; i
++) {
1253 vector_num
= tx_info
->tcb
[i
]->intr_vector
;
1254 sprintf(tx_info
->tcb
[i
]->name
, "%s TXQ %d", bnad
->netdev
->name
,
1255 tx_id
+ tx_info
->tcb
[i
]->id
);
1256 err
= request_irq(bnad
->msix_table
[vector_num
].vector
,
1257 (irq_handler_t
)bnad_msix_tx
, 0,
1258 tx_info
->tcb
[i
]->name
,
1268 bnad_tx_msix_unregister(bnad
, tx_info
, (i
- 1));
1273 * NOTE: Should be called for MSIX only
1274 * Unregisters Rx MSIX vector(s) from the kernel
1277 bnad_rx_msix_unregister(struct bnad
*bnad
, struct bnad_rx_info
*rx_info
,
1283 for (i
= 0; i
< num_rxps
; i
++) {
1284 if (rx_info
->rx_ctrl
[i
].ccb
== NULL
)
1287 vector_num
= rx_info
->rx_ctrl
[i
].ccb
->intr_vector
;
1288 free_irq(bnad
->msix_table
[vector_num
].vector
,
1289 rx_info
->rx_ctrl
[i
].ccb
);
1294 * NOTE: Should be called for MSIX only
1295 * Registers Tx MSIX vector(s) and ISR(s), cookie with the kernel
1298 bnad_rx_msix_register(struct bnad
*bnad
, struct bnad_rx_info
*rx_info
,
1299 uint rx_id
, int num_rxps
)
1305 for (i
= 0; i
< num_rxps
; i
++) {
1306 vector_num
= rx_info
->rx_ctrl
[i
].ccb
->intr_vector
;
1307 sprintf(rx_info
->rx_ctrl
[i
].ccb
->name
, "%s CQ %d",
1309 rx_id
+ rx_info
->rx_ctrl
[i
].ccb
->id
);
1310 err
= request_irq(bnad
->msix_table
[vector_num
].vector
,
1311 (irq_handler_t
)bnad_msix_rx
, 0,
1312 rx_info
->rx_ctrl
[i
].ccb
->name
,
1313 rx_info
->rx_ctrl
[i
].ccb
);
1322 bnad_rx_msix_unregister(bnad
, rx_info
, (i
- 1));
1326 /* Free Tx object Resources */
1328 bnad_tx_res_free(struct bnad
*bnad
, struct bna_res_info
*res_info
)
1332 for (i
= 0; i
< BNA_TX_RES_T_MAX
; i
++) {
1333 if (res_info
[i
].res_type
== BNA_RES_T_MEM
)
1334 bnad_mem_free(bnad
, &res_info
[i
].res_u
.mem_info
);
1335 else if (res_info
[i
].res_type
== BNA_RES_T_INTR
)
1336 bnad_txrx_irq_free(bnad
, &res_info
[i
].res_u
.intr_info
);
1340 /* Allocates memory and interrupt resources for Tx object */
1342 bnad_tx_res_alloc(struct bnad
*bnad
, struct bna_res_info
*res_info
,
1347 for (i
= 0; i
< BNA_TX_RES_T_MAX
; i
++) {
1348 if (res_info
[i
].res_type
== BNA_RES_T_MEM
)
1349 err
= bnad_mem_alloc(bnad
,
1350 &res_info
[i
].res_u
.mem_info
);
1351 else if (res_info
[i
].res_type
== BNA_RES_T_INTR
)
1352 err
= bnad_txrx_irq_alloc(bnad
, BNAD_INTR_TX
, tx_id
,
1353 &res_info
[i
].res_u
.intr_info
);
1360 bnad_tx_res_free(bnad
, res_info
);
1364 /* Free Rx object Resources */
1366 bnad_rx_res_free(struct bnad
*bnad
, struct bna_res_info
*res_info
)
1370 for (i
= 0; i
< BNA_RX_RES_T_MAX
; i
++) {
1371 if (res_info
[i
].res_type
== BNA_RES_T_MEM
)
1372 bnad_mem_free(bnad
, &res_info
[i
].res_u
.mem_info
);
1373 else if (res_info
[i
].res_type
== BNA_RES_T_INTR
)
1374 bnad_txrx_irq_free(bnad
, &res_info
[i
].res_u
.intr_info
);
1378 /* Allocates memory and interrupt resources for Rx object */
1380 bnad_rx_res_alloc(struct bnad
*bnad
, struct bna_res_info
*res_info
,
1385 /* All memory needs to be allocated before setup_ccbs */
1386 for (i
= 0; i
< BNA_RX_RES_T_MAX
; i
++) {
1387 if (res_info
[i
].res_type
== BNA_RES_T_MEM
)
1388 err
= bnad_mem_alloc(bnad
,
1389 &res_info
[i
].res_u
.mem_info
);
1390 else if (res_info
[i
].res_type
== BNA_RES_T_INTR
)
1391 err
= bnad_txrx_irq_alloc(bnad
, BNAD_INTR_RX
, rx_id
,
1392 &res_info
[i
].res_u
.intr_info
);
1399 bnad_rx_res_free(bnad
, res_info
);
1403 /* Timer callbacks */
1406 bnad_ioc_timeout(unsigned long data
)
1408 struct bnad
*bnad
= (struct bnad
*)data
;
1409 unsigned long flags
;
1411 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1412 bfa_nw_ioc_timeout((void *) &bnad
->bna
.device
.ioc
);
1413 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1417 bnad_ioc_hb_check(unsigned long data
)
1419 struct bnad
*bnad
= (struct bnad
*)data
;
1420 unsigned long flags
;
1422 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1423 bfa_nw_ioc_hb_check((void *) &bnad
->bna
.device
.ioc
);
1424 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1428 bnad_iocpf_timeout(unsigned long data
)
1430 struct bnad
*bnad
= (struct bnad
*)data
;
1431 unsigned long flags
;
1433 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1434 bfa_nw_iocpf_timeout((void *) &bnad
->bna
.device
.ioc
);
1435 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1439 bnad_iocpf_sem_timeout(unsigned long data
)
1441 struct bnad
*bnad
= (struct bnad
*)data
;
1442 unsigned long flags
;
1444 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1445 bfa_nw_iocpf_sem_timeout((void *) &bnad
->bna
.device
.ioc
);
1446 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1450 * All timer routines use bnad->bna_lock to protect against
1451 * the following race, which may occur in case of no locking:
1459 /* b) Dynamic Interrupt Moderation Timer */
1461 bnad_dim_timeout(unsigned long data
)
1463 struct bnad
*bnad
= (struct bnad
*)data
;
1464 struct bnad_rx_info
*rx_info
;
1465 struct bnad_rx_ctrl
*rx_ctrl
;
1467 unsigned long flags
;
1469 if (!netif_carrier_ok(bnad
->netdev
))
1472 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1473 for (i
= 0; i
< bnad
->num_rx
; i
++) {
1474 rx_info
= &bnad
->rx_info
[i
];
1477 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++) {
1478 rx_ctrl
= &rx_info
->rx_ctrl
[j
];
1481 bna_rx_dim_update(rx_ctrl
->ccb
);
1485 /* Check for BNAD_CF_DIM_ENABLED, does not eleminate a race */
1486 if (test_bit(BNAD_RF_DIM_TIMER_RUNNING
, &bnad
->run_flags
))
1487 mod_timer(&bnad
->dim_timer
,
1488 jiffies
+ msecs_to_jiffies(BNAD_DIM_TIMER_FREQ
));
1489 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1492 /* c) Statistics Timer */
1494 bnad_stats_timeout(unsigned long data
)
1496 struct bnad
*bnad
= (struct bnad
*)data
;
1497 unsigned long flags
;
1499 if (!netif_running(bnad
->netdev
) ||
1500 !test_bit(BNAD_RF_STATS_TIMER_RUNNING
, &bnad
->run_flags
))
1503 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1504 bna_stats_get(&bnad
->bna
);
1505 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1509 * Set up timer for DIM
1510 * Called with bnad->bna_lock held
1513 bnad_dim_timer_start(struct bnad
*bnad
)
1515 if (bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
&&
1516 !test_bit(BNAD_RF_DIM_TIMER_RUNNING
, &bnad
->run_flags
)) {
1517 setup_timer(&bnad
->dim_timer
, bnad_dim_timeout
,
1518 (unsigned long)bnad
);
1519 set_bit(BNAD_RF_DIM_TIMER_RUNNING
, &bnad
->run_flags
);
1520 mod_timer(&bnad
->dim_timer
,
1521 jiffies
+ msecs_to_jiffies(BNAD_DIM_TIMER_FREQ
));
1526 * Set up timer for statistics
1527 * Called with mutex_lock(&bnad->conf_mutex) held
1530 bnad_stats_timer_start(struct bnad
*bnad
)
1532 unsigned long flags
;
1534 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1535 if (!test_and_set_bit(BNAD_RF_STATS_TIMER_RUNNING
, &bnad
->run_flags
)) {
1536 setup_timer(&bnad
->stats_timer
, bnad_stats_timeout
,
1537 (unsigned long)bnad
);
1538 mod_timer(&bnad
->stats_timer
,
1539 jiffies
+ msecs_to_jiffies(BNAD_STATS_TIMER_FREQ
));
1541 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1545 * Stops the stats timer
1546 * Called with mutex_lock(&bnad->conf_mutex) held
1549 bnad_stats_timer_stop(struct bnad
*bnad
)
1552 unsigned long flags
;
1554 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1555 if (test_and_clear_bit(BNAD_RF_STATS_TIMER_RUNNING
, &bnad
->run_flags
))
1557 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1559 del_timer_sync(&bnad
->stats_timer
);
1565 bnad_netdev_mc_list_get(struct net_device
*netdev
, u8
*mc_list
)
1567 int i
= 1; /* Index 0 has broadcast address */
1568 struct netdev_hw_addr
*mc_addr
;
1570 netdev_for_each_mc_addr(mc_addr
, netdev
) {
1571 memcpy(&mc_list
[i
* ETH_ALEN
], &mc_addr
->addr
[0],
1578 bnad_napi_poll_rx(struct napi_struct
*napi
, int budget
)
1580 struct bnad_rx_ctrl
*rx_ctrl
=
1581 container_of(napi
, struct bnad_rx_ctrl
, napi
);
1582 struct bna_ccb
*ccb
;
1590 if (!netif_carrier_ok(bnad
->netdev
))
1593 rcvd
= bnad_poll_cq(bnad
, ccb
, budget
);
1598 napi_complete((napi
));
1600 BNAD_UPDATE_CTR(bnad
, netif_rx_complete
);
1602 bnad_enable_rx_irq(bnad
, ccb
);
1607 bnad_napi_enable(struct bnad
*bnad
, u32 rx_id
)
1609 struct bnad_rx_ctrl
*rx_ctrl
;
1612 /* Initialize & enable NAPI */
1613 for (i
= 0; i
< bnad
->num_rxp_per_rx
; i
++) {
1614 rx_ctrl
= &bnad
->rx_info
[rx_id
].rx_ctrl
[i
];
1616 netif_napi_add(bnad
->netdev
, &rx_ctrl
->napi
,
1617 bnad_napi_poll_rx
, 64);
1619 napi_enable(&rx_ctrl
->napi
);
1624 bnad_napi_disable(struct bnad
*bnad
, u32 rx_id
)
1628 /* First disable and then clean up */
1629 for (i
= 0; i
< bnad
->num_rxp_per_rx
; i
++) {
1630 napi_disable(&bnad
->rx_info
[rx_id
].rx_ctrl
[i
].napi
);
1631 netif_napi_del(&bnad
->rx_info
[rx_id
].rx_ctrl
[i
].napi
);
1635 /* Should be held with conf_lock held */
1637 bnad_cleanup_tx(struct bnad
*bnad
, uint tx_id
)
1639 struct bnad_tx_info
*tx_info
= &bnad
->tx_info
[tx_id
];
1640 struct bna_res_info
*res_info
= &bnad
->tx_res_info
[tx_id
].res_info
[0];
1641 unsigned long flags
;
1646 init_completion(&bnad
->bnad_completions
.tx_comp
);
1647 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1648 bna_tx_disable(tx_info
->tx
, BNA_HARD_CLEANUP
, bnad_cb_tx_disabled
);
1649 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1650 wait_for_completion(&bnad
->bnad_completions
.tx_comp
);
1652 if (tx_info
->tcb
[0]->intr_type
== BNA_INTR_T_MSIX
)
1653 bnad_tx_msix_unregister(bnad
, tx_info
,
1654 bnad
->num_txq_per_tx
);
1656 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1657 bna_tx_destroy(tx_info
->tx
);
1658 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1663 tasklet_kill(&bnad
->tx_free_tasklet
);
1665 bnad_tx_res_free(bnad
, res_info
);
1668 /* Should be held with conf_lock held */
1670 bnad_setup_tx(struct bnad
*bnad
, uint tx_id
)
1673 struct bnad_tx_info
*tx_info
= &bnad
->tx_info
[tx_id
];
1674 struct bna_res_info
*res_info
= &bnad
->tx_res_info
[tx_id
].res_info
[0];
1675 struct bna_intr_info
*intr_info
=
1676 &res_info
[BNA_TX_RES_INTR_T_TXCMPL
].res_u
.intr_info
;
1677 struct bna_tx_config
*tx_config
= &bnad
->tx_config
[tx_id
];
1678 struct bna_tx_event_cbfn tx_cbfn
;
1680 unsigned long flags
;
1682 /* Initialize the Tx object configuration */
1683 tx_config
->num_txq
= bnad
->num_txq_per_tx
;
1684 tx_config
->txq_depth
= bnad
->txq_depth
;
1685 tx_config
->tx_type
= BNA_TX_T_REGULAR
;
1687 /* Initialize the tx event handlers */
1688 tx_cbfn
.tcb_setup_cbfn
= bnad_cb_tcb_setup
;
1689 tx_cbfn
.tcb_destroy_cbfn
= bnad_cb_tcb_destroy
;
1690 tx_cbfn
.tx_stall_cbfn
= bnad_cb_tx_stall
;
1691 tx_cbfn
.tx_resume_cbfn
= bnad_cb_tx_resume
;
1692 tx_cbfn
.tx_cleanup_cbfn
= bnad_cb_tx_cleanup
;
1694 /* Get BNA's resource requirement for one tx object */
1695 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1696 bna_tx_res_req(bnad
->num_txq_per_tx
,
1697 bnad
->txq_depth
, res_info
);
1698 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1700 /* Fill Unmap Q memory requirements */
1701 BNAD_FILL_UNMAPQ_MEM_REQ(
1702 &res_info
[BNA_TX_RES_MEM_T_UNMAPQ
],
1703 bnad
->num_txq_per_tx
,
1704 BNAD_TX_UNMAPQ_DEPTH
);
1706 /* Allocate resources */
1707 err
= bnad_tx_res_alloc(bnad
, res_info
, tx_id
);
1711 /* Ask BNA to create one Tx object, supplying required resources */
1712 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1713 tx
= bna_tx_create(&bnad
->bna
, bnad
, tx_config
, &tx_cbfn
, res_info
,
1715 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1720 /* Register ISR for the Tx object */
1721 if (intr_info
->intr_type
== BNA_INTR_T_MSIX
) {
1722 err
= bnad_tx_msix_register(bnad
, tx_info
,
1723 tx_id
, bnad
->num_txq_per_tx
);
1728 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1730 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1735 bnad_tx_res_free(bnad
, res_info
);
1739 /* Setup the rx config for bna_rx_create */
1740 /* bnad decides the configuration */
1742 bnad_init_rx_config(struct bnad
*bnad
, struct bna_rx_config
*rx_config
)
1744 rx_config
->rx_type
= BNA_RX_T_REGULAR
;
1745 rx_config
->num_paths
= bnad
->num_rxp_per_rx
;
1747 if (bnad
->num_rxp_per_rx
> 1) {
1748 rx_config
->rss_status
= BNA_STATUS_T_ENABLED
;
1749 rx_config
->rss_config
.hash_type
=
1754 rx_config
->rss_config
.hash_mask
=
1755 bnad
->num_rxp_per_rx
- 1;
1756 get_random_bytes(rx_config
->rss_config
.toeplitz_hash_key
,
1757 sizeof(rx_config
->rss_config
.toeplitz_hash_key
));
1759 rx_config
->rss_status
= BNA_STATUS_T_DISABLED
;
1760 memset(&rx_config
->rss_config
, 0,
1761 sizeof(rx_config
->rss_config
));
1763 rx_config
->rxp_type
= BNA_RXP_SLR
;
1764 rx_config
->q_depth
= bnad
->rxq_depth
;
1766 rx_config
->small_buff_size
= BFI_SMALL_RXBUF_SIZE
;
1768 rx_config
->vlan_strip_status
= BNA_STATUS_T_ENABLED
;
1771 /* Called with mutex_lock(&bnad->conf_mutex) held */
1773 bnad_cleanup_rx(struct bnad
*bnad
, uint rx_id
)
1775 struct bnad_rx_info
*rx_info
= &bnad
->rx_info
[rx_id
];
1776 struct bna_rx_config
*rx_config
= &bnad
->rx_config
[rx_id
];
1777 struct bna_res_info
*res_info
= &bnad
->rx_res_info
[rx_id
].res_info
[0];
1778 unsigned long flags
;
1779 int dim_timer_del
= 0;
1785 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1786 dim_timer_del
= bnad_dim_timer_running(bnad
);
1788 clear_bit(BNAD_RF_DIM_TIMER_RUNNING
, &bnad
->run_flags
);
1789 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1791 del_timer_sync(&bnad
->dim_timer
);
1794 bnad_napi_disable(bnad
, rx_id
);
1796 init_completion(&bnad
->bnad_completions
.rx_comp
);
1797 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1798 bna_rx_disable(rx_info
->rx
, BNA_HARD_CLEANUP
, bnad_cb_rx_disabled
);
1799 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1800 wait_for_completion(&bnad
->bnad_completions
.rx_comp
);
1802 if (rx_info
->rx_ctrl
[0].ccb
->intr_type
== BNA_INTR_T_MSIX
)
1803 bnad_rx_msix_unregister(bnad
, rx_info
, rx_config
->num_paths
);
1805 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1806 bna_rx_destroy(rx_info
->rx
);
1807 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1811 bnad_rx_res_free(bnad
, res_info
);
1814 /* Called with mutex_lock(&bnad->conf_mutex) held */
1816 bnad_setup_rx(struct bnad
*bnad
, uint rx_id
)
1819 struct bnad_rx_info
*rx_info
= &bnad
->rx_info
[rx_id
];
1820 struct bna_res_info
*res_info
= &bnad
->rx_res_info
[rx_id
].res_info
[0];
1821 struct bna_intr_info
*intr_info
=
1822 &res_info
[BNA_RX_RES_T_INTR
].res_u
.intr_info
;
1823 struct bna_rx_config
*rx_config
= &bnad
->rx_config
[rx_id
];
1824 struct bna_rx_event_cbfn rx_cbfn
;
1826 unsigned long flags
;
1828 /* Initialize the Rx object configuration */
1829 bnad_init_rx_config(bnad
, rx_config
);
1831 /* Initialize the Rx event handlers */
1832 rx_cbfn
.rcb_setup_cbfn
= bnad_cb_rcb_setup
;
1833 rx_cbfn
.rcb_destroy_cbfn
= bnad_cb_rcb_destroy
;
1834 rx_cbfn
.rcb_destroy_cbfn
= NULL
;
1835 rx_cbfn
.ccb_setup_cbfn
= bnad_cb_ccb_setup
;
1836 rx_cbfn
.ccb_destroy_cbfn
= bnad_cb_ccb_destroy
;
1837 rx_cbfn
.rx_cleanup_cbfn
= bnad_cb_rx_cleanup
;
1838 rx_cbfn
.rx_post_cbfn
= bnad_cb_rx_post
;
1840 /* Get BNA's resource requirement for one Rx object */
1841 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1842 bna_rx_res_req(rx_config
, res_info
);
1843 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1845 /* Fill Unmap Q memory requirements */
1846 BNAD_FILL_UNMAPQ_MEM_REQ(
1847 &res_info
[BNA_RX_RES_MEM_T_UNMAPQ
],
1848 rx_config
->num_paths
+
1849 ((rx_config
->rxp_type
== BNA_RXP_SINGLE
) ? 0 :
1850 rx_config
->num_paths
), BNAD_RX_UNMAPQ_DEPTH
);
1852 /* Allocate resource */
1853 err
= bnad_rx_res_alloc(bnad
, res_info
, rx_id
);
1857 /* Ask BNA to create one Rx object, supplying required resources */
1858 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1859 rx
= bna_rx_create(&bnad
->bna
, bnad
, rx_config
, &rx_cbfn
, res_info
,
1861 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1866 /* Register ISR for the Rx object */
1867 if (intr_info
->intr_type
== BNA_INTR_T_MSIX
) {
1868 err
= bnad_rx_msix_register(bnad
, rx_info
, rx_id
,
1869 rx_config
->num_paths
);
1875 bnad_napi_enable(bnad
, rx_id
);
1877 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1879 /* Set up Dynamic Interrupt Moderation Vector */
1880 if (bnad
->cfg_flags
& BNAD_CF_DIM_ENABLED
)
1881 bna_rx_dim_reconfig(&bnad
->bna
, bna_napi_dim_vector
);
1883 /* Enable VLAN filtering only on the default Rx */
1884 bna_rx_vlanfilter_enable(rx
);
1886 /* Start the DIM timer */
1887 bnad_dim_timer_start(bnad
);
1891 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1896 bnad_cleanup_rx(bnad
, rx_id
);
1900 /* Called with conf_lock & bnad->bna_lock held */
1902 bnad_tx_coalescing_timeo_set(struct bnad
*bnad
)
1904 struct bnad_tx_info
*tx_info
;
1906 tx_info
= &bnad
->tx_info
[0];
1910 bna_tx_coalescing_timeo_set(tx_info
->tx
, bnad
->tx_coalescing_timeo
);
1913 /* Called with conf_lock & bnad->bna_lock held */
1915 bnad_rx_coalescing_timeo_set(struct bnad
*bnad
)
1917 struct bnad_rx_info
*rx_info
;
1920 for (i
= 0; i
< bnad
->num_rx
; i
++) {
1921 rx_info
= &bnad
->rx_info
[i
];
1924 bna_rx_coalescing_timeo_set(rx_info
->rx
,
1925 bnad
->rx_coalescing_timeo
);
1930 * Called with bnad->bna_lock held
1933 bnad_mac_addr_set_locked(struct bnad
*bnad
, u8
*mac_addr
)
1937 if (!is_valid_ether_addr(mac_addr
))
1938 return -EADDRNOTAVAIL
;
1940 /* If datapath is down, pretend everything went through */
1941 if (!bnad
->rx_info
[0].rx
)
1944 ret
= bna_rx_ucast_set(bnad
->rx_info
[0].rx
, mac_addr
, NULL
);
1945 if (ret
!= BNA_CB_SUCCESS
)
1946 return -EADDRNOTAVAIL
;
1951 /* Should be called with conf_lock held */
1953 bnad_enable_default_bcast(struct bnad
*bnad
)
1955 struct bnad_rx_info
*rx_info
= &bnad
->rx_info
[0];
1957 unsigned long flags
;
1959 init_completion(&bnad
->bnad_completions
.mcast_comp
);
1961 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1962 ret
= bna_rx_mcast_add(rx_info
->rx
, (u8
*)bnad_bcast_addr
,
1963 bnad_cb_rx_mcast_add
);
1964 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1966 if (ret
== BNA_CB_SUCCESS
)
1967 wait_for_completion(&bnad
->bnad_completions
.mcast_comp
);
1971 if (bnad
->bnad_completions
.mcast_comp_status
!= BNA_CB_SUCCESS
)
1977 /* Called with bnad_conf_lock() held */
1979 bnad_restore_vlans(struct bnad
*bnad
, u32 rx_id
)
1982 unsigned long flags
;
1984 if (!bnad
->vlan_grp
)
1987 BUG_ON(!(VLAN_N_VID
== (BFI_MAX_VLAN
+ 1)));
1989 for (vlan_id
= 0; vlan_id
< VLAN_N_VID
; vlan_id
++) {
1990 if (!vlan_group_get_device(bnad
->vlan_grp
, vlan_id
))
1992 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
1993 bna_rx_vlan_add(bnad
->rx_info
[rx_id
].rx
, vlan_id
);
1994 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
1998 /* Statistics utilities */
2000 bnad_netdev_qstats_fill(struct bnad
*bnad
, struct rtnl_link_stats64
*stats
)
2004 for (i
= 0; i
< bnad
->num_rx
; i
++) {
2005 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++) {
2006 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
) {
2007 stats
->rx_packets
+= bnad
->rx_info
[i
].
2008 rx_ctrl
[j
].ccb
->rcb
[0]->rxq
->rx_packets
;
2009 stats
->rx_bytes
+= bnad
->rx_info
[i
].
2010 rx_ctrl
[j
].ccb
->rcb
[0]->rxq
->rx_bytes
;
2011 if (bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->rcb
[1] &&
2012 bnad
->rx_info
[i
].rx_ctrl
[j
].ccb
->
2014 stats
->rx_packets
+=
2015 bnad
->rx_info
[i
].rx_ctrl
[j
].
2016 ccb
->rcb
[1]->rxq
->rx_packets
;
2018 bnad
->rx_info
[i
].rx_ctrl
[j
].
2019 ccb
->rcb
[1]->rxq
->rx_bytes
;
2024 for (i
= 0; i
< bnad
->num_tx
; i
++) {
2025 for (j
= 0; j
< bnad
->num_txq_per_tx
; j
++) {
2026 if (bnad
->tx_info
[i
].tcb
[j
]) {
2027 stats
->tx_packets
+=
2028 bnad
->tx_info
[i
].tcb
[j
]->txq
->tx_packets
;
2030 bnad
->tx_info
[i
].tcb
[j
]->txq
->tx_bytes
;
2037 * Must be called with the bna_lock held.
2040 bnad_netdev_hwstats_fill(struct bnad
*bnad
, struct rtnl_link_stats64
*stats
)
2042 struct bfi_ll_stats_mac
*mac_stats
;
2046 mac_stats
= &bnad
->stats
.bna_stats
->hw_stats
->mac_stats
;
2048 mac_stats
->rx_fcs_error
+ mac_stats
->rx_alignment_error
+
2049 mac_stats
->rx_frame_length_error
+ mac_stats
->rx_code_error
+
2050 mac_stats
->rx_undersize
;
2051 stats
->tx_errors
= mac_stats
->tx_fcs_error
+
2052 mac_stats
->tx_undersize
;
2053 stats
->rx_dropped
= mac_stats
->rx_drop
;
2054 stats
->tx_dropped
= mac_stats
->tx_drop
;
2055 stats
->multicast
= mac_stats
->rx_multicast
;
2056 stats
->collisions
= mac_stats
->tx_total_collision
;
2058 stats
->rx_length_errors
= mac_stats
->rx_frame_length_error
;
2060 /* receive ring buffer overflow ?? */
2062 stats
->rx_crc_errors
= mac_stats
->rx_fcs_error
;
2063 stats
->rx_frame_errors
= mac_stats
->rx_alignment_error
;
2064 /* recv'r fifo overrun */
2065 bmap
= (u64
)bnad
->stats
.bna_stats
->rxf_bmap
[0] |
2066 ((u64
)bnad
->stats
.bna_stats
->rxf_bmap
[1] << 32);
2067 for (i
= 0; bmap
&& (i
< BFI_LL_RXF_ID_MAX
); i
++) {
2069 stats
->rx_fifo_errors
+=
2070 bnad
->stats
.bna_stats
->
2071 hw_stats
->rxf_stats
[i
].frame_drops
;
2079 bnad_mbox_irq_sync(struct bnad
*bnad
)
2082 unsigned long flags
;
2084 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2085 if (bnad
->cfg_flags
& BNAD_CF_MSIX
)
2086 irq
= bnad
->msix_table
[bnad
->msix_num
- 1].vector
;
2088 irq
= bnad
->pcidev
->irq
;
2089 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2091 synchronize_irq(irq
);
2094 /* Utility used by bnad_start_xmit, for doing TSO */
2096 bnad_tso_prepare(struct bnad
*bnad
, struct sk_buff
*skb
)
2100 /* SKB_GSO_TCPV4 and SKB_GSO_TCPV6 is defined since 2.6.18. */
2101 BUG_ON(!(skb_shinfo(skb
)->gso_type
== SKB_GSO_TCPV4
||
2102 skb_shinfo(skb
)->gso_type
== SKB_GSO_TCPV6
));
2103 if (skb_header_cloned(skb
)) {
2104 err
= pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
2106 BNAD_UPDATE_CTR(bnad
, tso_err
);
2112 * For TSO, the TCP checksum field is seeded with pseudo-header sum
2113 * excluding the length field.
2115 if (skb
->protocol
== htons(ETH_P_IP
)) {
2116 struct iphdr
*iph
= ip_hdr(skb
);
2118 /* Do we really need these? */
2122 tcp_hdr(skb
)->check
=
2123 ~csum_tcpudp_magic(iph
->saddr
, iph
->daddr
, 0,
2125 BNAD_UPDATE_CTR(bnad
, tso4
);
2127 struct ipv6hdr
*ipv6h
= ipv6_hdr(skb
);
2129 BUG_ON(!(skb
->protocol
== htons(ETH_P_IPV6
)));
2130 ipv6h
->payload_len
= 0;
2131 tcp_hdr(skb
)->check
=
2132 ~csum_ipv6_magic(&ipv6h
->saddr
, &ipv6h
->daddr
, 0,
2134 BNAD_UPDATE_CTR(bnad
, tso6
);
2141 * Initialize Q numbers depending on Rx Paths
2142 * Called with bnad->bna_lock held, because of cfg_flags
2146 bnad_q_num_init(struct bnad
*bnad
)
2150 rxps
= min((uint
)num_online_cpus(),
2151 (uint
)(BNAD_MAX_RXS
* BNAD_MAX_RXPS_PER_RX
));
2153 if (!(bnad
->cfg_flags
& BNAD_CF_MSIX
))
2154 rxps
= 1; /* INTx */
2158 bnad
->num_rxp_per_rx
= rxps
;
2159 bnad
->num_txq_per_tx
= BNAD_TXQ_NUM
;
2163 * Adjusts the Q numbers, given a number of msix vectors
2164 * Give preference to RSS as opposed to Tx priority Queues,
2165 * in such a case, just use 1 Tx Q
2166 * Called with bnad->bna_lock held b'cos of cfg_flags access
2169 bnad_q_num_adjust(struct bnad
*bnad
, int msix_vectors
)
2171 bnad
->num_txq_per_tx
= 1;
2172 if ((msix_vectors
>= (bnad
->num_tx
* bnad
->num_txq_per_tx
) +
2173 bnad_rxqs_per_cq
+ BNAD_MAILBOX_MSIX_VECTORS
) &&
2174 (bnad
->cfg_flags
& BNAD_CF_MSIX
)) {
2175 bnad
->num_rxp_per_rx
= msix_vectors
-
2176 (bnad
->num_tx
* bnad
->num_txq_per_tx
) -
2177 BNAD_MAILBOX_MSIX_VECTORS
;
2179 bnad
->num_rxp_per_rx
= 1;
2182 /* Enable / disable device */
2184 bnad_device_disable(struct bnad
*bnad
)
2186 unsigned long flags
;
2188 init_completion(&bnad
->bnad_completions
.ioc_comp
);
2190 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2191 bna_device_disable(&bnad
->bna
.device
, BNA_HARD_CLEANUP
);
2192 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2194 wait_for_completion(&bnad
->bnad_completions
.ioc_comp
);
2198 bnad_device_enable(struct bnad
*bnad
)
2201 unsigned long flags
;
2203 init_completion(&bnad
->bnad_completions
.ioc_comp
);
2205 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2206 bna_device_enable(&bnad
->bna
.device
);
2207 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2209 wait_for_completion(&bnad
->bnad_completions
.ioc_comp
);
2211 if (bnad
->bnad_completions
.ioc_comp_status
)
2212 err
= bnad
->bnad_completions
.ioc_comp_status
;
2217 /* Free BNA resources */
2219 bnad_res_free(struct bnad
*bnad
)
2222 struct bna_res_info
*res_info
= &bnad
->res_info
[0];
2224 for (i
= 0; i
< BNA_RES_T_MAX
; i
++) {
2225 if (res_info
[i
].res_type
== BNA_RES_T_MEM
)
2226 bnad_mem_free(bnad
, &res_info
[i
].res_u
.mem_info
);
2228 bnad_mbox_irq_free(bnad
, &res_info
[i
].res_u
.intr_info
);
2232 /* Allocates memory and interrupt resources for BNA */
2234 bnad_res_alloc(struct bnad
*bnad
)
2237 struct bna_res_info
*res_info
= &bnad
->res_info
[0];
2239 for (i
= 0; i
< BNA_RES_T_MAX
; i
++) {
2240 if (res_info
[i
].res_type
== BNA_RES_T_MEM
)
2241 err
= bnad_mem_alloc(bnad
, &res_info
[i
].res_u
.mem_info
);
2243 err
= bnad_mbox_irq_alloc(bnad
,
2244 &res_info
[i
].res_u
.intr_info
);
2251 bnad_res_free(bnad
);
2255 /* Interrupt enable / disable */
2257 bnad_enable_msix(struct bnad
*bnad
)
2260 unsigned long flags
;
2262 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2263 if (!(bnad
->cfg_flags
& BNAD_CF_MSIX
)) {
2264 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2267 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2269 if (bnad
->msix_table
)
2273 kcalloc(bnad
->msix_num
, sizeof(struct msix_entry
), GFP_KERNEL
);
2275 if (!bnad
->msix_table
)
2278 for (i
= 0; i
< bnad
->msix_num
; i
++)
2279 bnad
->msix_table
[i
].entry
= i
;
2281 ret
= pci_enable_msix(bnad
->pcidev
, bnad
->msix_table
, bnad
->msix_num
);
2283 /* Not enough MSI-X vectors. */
2285 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2286 /* ret = #of vectors that we got */
2287 bnad_q_num_adjust(bnad
, ret
);
2288 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2290 bnad
->msix_num
= (bnad
->num_tx
* bnad
->num_txq_per_tx
)
2292 * bnad
->num_rxp_per_rx
) +
2293 BNAD_MAILBOX_MSIX_VECTORS
;
2295 /* Try once more with adjusted numbers */
2296 /* If this fails, fall back to INTx */
2297 ret
= pci_enable_msix(bnad
->pcidev
, bnad
->msix_table
,
2308 kfree(bnad
->msix_table
);
2309 bnad
->msix_table
= NULL
;
2311 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2312 bnad
->cfg_flags
&= ~BNAD_CF_MSIX
;
2313 bnad_q_num_init(bnad
);
2314 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2318 bnad_disable_msix(struct bnad
*bnad
)
2321 unsigned long flags
;
2323 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2324 cfg_flags
= bnad
->cfg_flags
;
2325 if (bnad
->cfg_flags
& BNAD_CF_MSIX
)
2326 bnad
->cfg_flags
&= ~BNAD_CF_MSIX
;
2327 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2329 if (cfg_flags
& BNAD_CF_MSIX
) {
2330 pci_disable_msix(bnad
->pcidev
);
2331 kfree(bnad
->msix_table
);
2332 bnad
->msix_table
= NULL
;
2336 /* Netdev entry points */
2338 bnad_open(struct net_device
*netdev
)
2341 struct bnad
*bnad
= netdev_priv(netdev
);
2342 struct bna_pause_config pause_config
;
2344 unsigned long flags
;
2346 mutex_lock(&bnad
->conf_mutex
);
2349 err
= bnad_setup_tx(bnad
, 0);
2354 err
= bnad_setup_rx(bnad
, 0);
2359 pause_config
.tx_pause
= 0;
2360 pause_config
.rx_pause
= 0;
2362 mtu
= ETH_HLEN
+ bnad
->netdev
->mtu
+ ETH_FCS_LEN
;
2364 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2365 bna_port_mtu_set(&bnad
->bna
.port
, mtu
, NULL
);
2366 bna_port_pause_config(&bnad
->bna
.port
, &pause_config
, NULL
);
2367 bna_port_enable(&bnad
->bna
.port
);
2368 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2370 /* Enable broadcast */
2371 bnad_enable_default_bcast(bnad
);
2373 /* Restore VLANs, if any */
2374 bnad_restore_vlans(bnad
, 0);
2376 /* Set the UCAST address */
2377 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2378 bnad_mac_addr_set_locked(bnad
, netdev
->dev_addr
);
2379 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2381 /* Start the stats timer */
2382 bnad_stats_timer_start(bnad
);
2384 mutex_unlock(&bnad
->conf_mutex
);
2389 bnad_cleanup_tx(bnad
, 0);
2392 mutex_unlock(&bnad
->conf_mutex
);
2397 bnad_stop(struct net_device
*netdev
)
2399 struct bnad
*bnad
= netdev_priv(netdev
);
2400 unsigned long flags
;
2402 mutex_lock(&bnad
->conf_mutex
);
2404 /* Stop the stats timer */
2405 bnad_stats_timer_stop(bnad
);
2407 init_completion(&bnad
->bnad_completions
.port_comp
);
2409 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2410 bna_port_disable(&bnad
->bna
.port
, BNA_HARD_CLEANUP
,
2411 bnad_cb_port_disabled
);
2412 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2414 wait_for_completion(&bnad
->bnad_completions
.port_comp
);
2416 bnad_cleanup_tx(bnad
, 0);
2417 bnad_cleanup_rx(bnad
, 0);
2419 /* Synchronize mailbox IRQ */
2420 bnad_mbox_irq_sync(bnad
);
2422 mutex_unlock(&bnad
->conf_mutex
);
2429 * bnad_start_xmit : Netdev entry point for Transmit
2430 * Called under lock held by net_device
2433 bnad_start_xmit(struct sk_buff
*skb
, struct net_device
*netdev
)
2435 struct bnad
*bnad
= netdev_priv(netdev
);
2437 u16 txq_prod
, vlan_tag
= 0;
2438 u32 unmap_prod
, wis
, wis_used
, wi_range
;
2439 u32 vectors
, vect_id
, i
, acked
;
2443 struct bnad_tx_info
*tx_info
;
2444 struct bna_tcb
*tcb
;
2445 struct bnad_unmap_q
*unmap_q
;
2446 dma_addr_t dma_addr
;
2447 struct bna_txq_entry
*txqent
;
2448 bna_txq_wi_ctrl_flag_t flags
;
2451 (skb
->len
<= ETH_HLEN
|| skb
->len
> BFI_TX_MAX_DATA_PER_PKT
)) {
2453 return NETDEV_TX_OK
;
2458 tx_info
= &bnad
->tx_info
[tx_id
];
2459 tcb
= tx_info
->tcb
[tx_id
];
2460 unmap_q
= tcb
->unmap_q
;
2463 * Takes care of the Tx that is scheduled between clearing the flag
2464 * and the netif_stop_queue() call.
2466 if (unlikely(!test_bit(BNAD_TXQ_TX_STARTED
, &tcb
->flags
))) {
2468 return NETDEV_TX_OK
;
2471 vectors
= 1 + skb_shinfo(skb
)->nr_frags
;
2472 if (vectors
> BFI_TX_MAX_VECTORS_PER_PKT
) {
2474 return NETDEV_TX_OK
;
2476 wis
= BNA_TXQ_WI_NEEDED(vectors
); /* 4 vectors per work item */
2479 (wis
> BNA_QE_FREE_CNT(tcb
, tcb
->q_depth
) ||
2480 vectors
> BNA_QE_FREE_CNT(unmap_q
, unmap_q
->q_depth
))) {
2481 if ((u16
) (*tcb
->hw_consumer_index
) !=
2482 tcb
->consumer_index
&&
2483 !test_and_set_bit(BNAD_TXQ_FREE_SENT
, &tcb
->flags
)) {
2484 acked
= bnad_free_txbufs(bnad
, tcb
);
2485 if (likely(test_bit(BNAD_TXQ_TX_STARTED
, &tcb
->flags
)))
2486 bna_ib_ack(tcb
->i_dbell
, acked
);
2487 smp_mb__before_clear_bit();
2488 clear_bit(BNAD_TXQ_FREE_SENT
, &tcb
->flags
);
2490 netif_stop_queue(netdev
);
2491 BNAD_UPDATE_CTR(bnad
, netif_queue_stop
);
2496 * Check again to deal with race condition between
2497 * netif_stop_queue here, and netif_wake_queue in
2498 * interrupt handler which is not inside netif tx lock.
2501 (wis
> BNA_QE_FREE_CNT(tcb
, tcb
->q_depth
) ||
2502 vectors
> BNA_QE_FREE_CNT(unmap_q
, unmap_q
->q_depth
))) {
2503 BNAD_UPDATE_CTR(bnad
, netif_queue_stop
);
2504 return NETDEV_TX_BUSY
;
2506 netif_wake_queue(netdev
);
2507 BNAD_UPDATE_CTR(bnad
, netif_queue_wakeup
);
2511 unmap_prod
= unmap_q
->producer_index
;
2516 txq_prod
= tcb
->producer_index
;
2517 BNA_TXQ_QPGE_PTR_GET(txq_prod
, tcb
->sw_qpt
, txqent
, wi_range
);
2518 BUG_ON(!(wi_range
<= tcb
->q_depth
));
2519 txqent
->hdr
.wi
.reserved
= 0;
2520 txqent
->hdr
.wi
.num_vectors
= vectors
;
2521 txqent
->hdr
.wi
.opcode
=
2522 htons((skb_is_gso(skb
) ? BNA_TXQ_WI_SEND_LSO
:
2525 if (vlan_tx_tag_present(skb
)) {
2526 vlan_tag
= (u16
) vlan_tx_tag_get(skb
);
2527 flags
|= (BNA_TXQ_WI_CF_INS_PRIO
| BNA_TXQ_WI_CF_INS_VLAN
);
2529 if (test_bit(BNAD_RF_CEE_RUNNING
, &bnad
->run_flags
)) {
2531 (tcb
->priority
& 0x7) << 13 | (vlan_tag
& 0x1fff);
2532 flags
|= (BNA_TXQ_WI_CF_INS_PRIO
| BNA_TXQ_WI_CF_INS_VLAN
);
2535 txqent
->hdr
.wi
.vlan_tag
= htons(vlan_tag
);
2537 if (skb_is_gso(skb
)) {
2538 err
= bnad_tso_prepare(bnad
, skb
);
2541 return NETDEV_TX_OK
;
2543 txqent
->hdr
.wi
.lso_mss
= htons(skb_is_gso(skb
));
2544 flags
|= (BNA_TXQ_WI_CF_IP_CKSUM
| BNA_TXQ_WI_CF_TCP_CKSUM
);
2545 txqent
->hdr
.wi
.l4_hdr_size_n_offset
=
2546 htons(BNA_TXQ_WI_L4_HDR_N_OFFSET
2547 (tcp_hdrlen(skb
) >> 2,
2548 skb_transport_offset(skb
)));
2549 } else if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
2552 txqent
->hdr
.wi
.lso_mss
= 0;
2554 if (skb
->protocol
== htons(ETH_P_IP
))
2555 proto
= ip_hdr(skb
)->protocol
;
2556 else if (skb
->protocol
== htons(ETH_P_IPV6
)) {
2557 /* nexthdr may not be TCP immediately. */
2558 proto
= ipv6_hdr(skb
)->nexthdr
;
2560 if (proto
== IPPROTO_TCP
) {
2561 flags
|= BNA_TXQ_WI_CF_TCP_CKSUM
;
2562 txqent
->hdr
.wi
.l4_hdr_size_n_offset
=
2563 htons(BNA_TXQ_WI_L4_HDR_N_OFFSET
2564 (0, skb_transport_offset(skb
)));
2566 BNAD_UPDATE_CTR(bnad
, tcpcsum_offload
);
2568 BUG_ON(!(skb_headlen(skb
) >=
2569 skb_transport_offset(skb
) + tcp_hdrlen(skb
)));
2571 } else if (proto
== IPPROTO_UDP
) {
2572 flags
|= BNA_TXQ_WI_CF_UDP_CKSUM
;
2573 txqent
->hdr
.wi
.l4_hdr_size_n_offset
=
2574 htons(BNA_TXQ_WI_L4_HDR_N_OFFSET
2575 (0, skb_transport_offset(skb
)));
2577 BNAD_UPDATE_CTR(bnad
, udpcsum_offload
);
2579 BUG_ON(!(skb_headlen(skb
) >=
2580 skb_transport_offset(skb
) +
2581 sizeof(struct udphdr
)));
2583 err
= skb_checksum_help(skb
);
2584 BNAD_UPDATE_CTR(bnad
, csum_help
);
2587 BNAD_UPDATE_CTR(bnad
, csum_help_err
);
2588 return NETDEV_TX_OK
;
2592 txqent
->hdr
.wi
.lso_mss
= 0;
2593 txqent
->hdr
.wi
.l4_hdr_size_n_offset
= 0;
2596 txqent
->hdr
.wi
.flags
= htons(flags
);
2598 txqent
->hdr
.wi
.frame_length
= htonl(skb
->len
);
2600 unmap_q
->unmap_array
[unmap_prod
].skb
= skb
;
2601 BUG_ON(!(skb_headlen(skb
) <= BFI_TX_MAX_DATA_PER_VECTOR
));
2602 txqent
->vector
[vect_id
].length
= htons(skb_headlen(skb
));
2603 dma_addr
= pci_map_single(bnad
->pcidev
, skb
->data
, skb_headlen(skb
),
2605 pci_unmap_addr_set(&unmap_q
->unmap_array
[unmap_prod
], dma_addr
,
2608 BNA_SET_DMA_ADDR(dma_addr
, &txqent
->vector
[vect_id
].host_addr
);
2609 BNA_QE_INDX_ADD(unmap_prod
, 1, unmap_q
->q_depth
);
2611 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
2612 struct skb_frag_struct
*frag
= &skb_shinfo(skb
)->frags
[i
];
2613 u32 size
= frag
->size
;
2615 if (++vect_id
== BFI_TX_MAX_VECTORS_PER_WI
) {
2620 BNA_QE_INDX_ADD(txq_prod
, wis_used
,
2623 BNA_TXQ_QPGE_PTR_GET(txq_prod
, tcb
->sw_qpt
,
2625 BUG_ON(!(wi_range
<= tcb
->q_depth
));
2628 txqent
->hdr
.wi_ext
.opcode
= htons(BNA_TXQ_WI_EXTENSION
);
2631 BUG_ON(!(size
<= BFI_TX_MAX_DATA_PER_VECTOR
));
2632 txqent
->vector
[vect_id
].length
= htons(size
);
2634 pci_map_page(bnad
->pcidev
, frag
->page
,
2635 frag
->page_offset
, size
,
2637 pci_unmap_addr_set(&unmap_q
->unmap_array
[unmap_prod
], dma_addr
,
2639 BNA_SET_DMA_ADDR(dma_addr
, &txqent
->vector
[vect_id
].host_addr
);
2640 BNA_QE_INDX_ADD(unmap_prod
, 1, unmap_q
->q_depth
);
2643 unmap_q
->producer_index
= unmap_prod
;
2644 BNA_QE_INDX_ADD(txq_prod
, wis_used
, tcb
->q_depth
);
2645 tcb
->producer_index
= txq_prod
;
2649 if (unlikely(!test_bit(BNAD_TXQ_TX_STARTED
, &tcb
->flags
)))
2650 return NETDEV_TX_OK
;
2652 bna_txq_prod_indx_doorbell(tcb
);
2654 if ((u16
) (*tcb
->hw_consumer_index
) != tcb
->consumer_index
)
2655 tasklet_schedule(&bnad
->tx_free_tasklet
);
2657 return NETDEV_TX_OK
;
2661 * Used spin_lock to synchronize reading of stats structures, which
2662 * is written by BNA under the same lock.
2664 static struct rtnl_link_stats64
*
2665 bnad_get_stats64(struct net_device
*netdev
, struct rtnl_link_stats64
*stats
)
2667 struct bnad
*bnad
= netdev_priv(netdev
);
2668 unsigned long flags
;
2670 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2672 bnad_netdev_qstats_fill(bnad
, stats
);
2673 bnad_netdev_hwstats_fill(bnad
, stats
);
2675 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2681 bnad_set_rx_mode(struct net_device
*netdev
)
2683 struct bnad
*bnad
= netdev_priv(netdev
);
2684 u32 new_mask
, valid_mask
;
2685 unsigned long flags
;
2687 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2689 new_mask
= valid_mask
= 0;
2691 if (netdev
->flags
& IFF_PROMISC
) {
2692 if (!(bnad
->cfg_flags
& BNAD_CF_PROMISC
)) {
2693 new_mask
= BNAD_RXMODE_PROMISC_DEFAULT
;
2694 valid_mask
= BNAD_RXMODE_PROMISC_DEFAULT
;
2695 bnad
->cfg_flags
|= BNAD_CF_PROMISC
;
2698 if (bnad
->cfg_flags
& BNAD_CF_PROMISC
) {
2699 new_mask
= ~BNAD_RXMODE_PROMISC_DEFAULT
;
2700 valid_mask
= BNAD_RXMODE_PROMISC_DEFAULT
;
2701 bnad
->cfg_flags
&= ~BNAD_CF_PROMISC
;
2705 if (netdev
->flags
& IFF_ALLMULTI
) {
2706 if (!(bnad
->cfg_flags
& BNAD_CF_ALLMULTI
)) {
2707 new_mask
|= BNA_RXMODE_ALLMULTI
;
2708 valid_mask
|= BNA_RXMODE_ALLMULTI
;
2709 bnad
->cfg_flags
|= BNAD_CF_ALLMULTI
;
2712 if (bnad
->cfg_flags
& BNAD_CF_ALLMULTI
) {
2713 new_mask
&= ~BNA_RXMODE_ALLMULTI
;
2714 valid_mask
|= BNA_RXMODE_ALLMULTI
;
2715 bnad
->cfg_flags
&= ~BNAD_CF_ALLMULTI
;
2719 bna_rx_mode_set(bnad
->rx_info
[0].rx
, new_mask
, valid_mask
, NULL
);
2721 if (!netdev_mc_empty(netdev
)) {
2723 int mc_count
= netdev_mc_count(netdev
);
2725 /* Index 0 holds the broadcast address */
2727 kzalloc((mc_count
+ 1) * ETH_ALEN
,
2732 memcpy(&mcaddr_list
[0], &bnad_bcast_addr
[0], ETH_ALEN
);
2734 /* Copy rest of the MC addresses */
2735 bnad_netdev_mc_list_get(netdev
, mcaddr_list
);
2737 bna_rx_mcast_listset(bnad
->rx_info
[0].rx
, mc_count
+ 1,
2740 /* Should we enable BNAD_CF_ALLMULTI for err != 0 ? */
2744 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2748 * bna_lock is used to sync writes to netdev->addr
2749 * conf_lock cannot be used since this call may be made
2750 * in a non-blocking context.
2753 bnad_set_mac_address(struct net_device
*netdev
, void *mac_addr
)
2756 struct bnad
*bnad
= netdev_priv(netdev
);
2757 struct sockaddr
*sa
= (struct sockaddr
*)mac_addr
;
2758 unsigned long flags
;
2760 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2762 err
= bnad_mac_addr_set_locked(bnad
, sa
->sa_data
);
2765 memcpy(netdev
->dev_addr
, sa
->sa_data
, netdev
->addr_len
);
2767 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2773 bnad_change_mtu(struct net_device
*netdev
, int new_mtu
)
2776 unsigned long flags
;
2778 struct bnad
*bnad
= netdev_priv(netdev
);
2780 if (new_mtu
+ ETH_HLEN
< ETH_ZLEN
|| new_mtu
> BNAD_JUMBO_MTU
)
2783 mutex_lock(&bnad
->conf_mutex
);
2785 netdev
->mtu
= new_mtu
;
2787 mtu
= ETH_HLEN
+ new_mtu
+ ETH_FCS_LEN
;
2789 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2790 bna_port_mtu_set(&bnad
->bna
.port
, mtu
, NULL
);
2791 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2793 mutex_unlock(&bnad
->conf_mutex
);
2798 bnad_vlan_rx_register(struct net_device
*netdev
,
2799 struct vlan_group
*vlan_grp
)
2801 struct bnad
*bnad
= netdev_priv(netdev
);
2803 mutex_lock(&bnad
->conf_mutex
);
2804 bnad
->vlan_grp
= vlan_grp
;
2805 mutex_unlock(&bnad
->conf_mutex
);
2809 bnad_vlan_rx_add_vid(struct net_device
*netdev
,
2812 struct bnad
*bnad
= netdev_priv(netdev
);
2813 unsigned long flags
;
2815 if (!bnad
->rx_info
[0].rx
)
2818 mutex_lock(&bnad
->conf_mutex
);
2820 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2821 bna_rx_vlan_add(bnad
->rx_info
[0].rx
, vid
);
2822 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2824 mutex_unlock(&bnad
->conf_mutex
);
2828 bnad_vlan_rx_kill_vid(struct net_device
*netdev
,
2831 struct bnad
*bnad
= netdev_priv(netdev
);
2832 unsigned long flags
;
2834 if (!bnad
->rx_info
[0].rx
)
2837 mutex_lock(&bnad
->conf_mutex
);
2839 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2840 bna_rx_vlan_del(bnad
->rx_info
[0].rx
, vid
);
2841 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2843 mutex_unlock(&bnad
->conf_mutex
);
2846 #ifdef CONFIG_NET_POLL_CONTROLLER
2848 bnad_netpoll(struct net_device
*netdev
)
2850 struct bnad
*bnad
= netdev_priv(netdev
);
2851 struct bnad_rx_info
*rx_info
;
2852 struct bnad_rx_ctrl
*rx_ctrl
;
2856 if (!(bnad
->cfg_flags
& BNAD_CF_MSIX
)) {
2857 bna_intx_disable(&bnad
->bna
, curr_mask
);
2858 bnad_isr(bnad
->pcidev
->irq
, netdev
);
2859 bna_intx_enable(&bnad
->bna
, curr_mask
);
2861 for (i
= 0; i
< bnad
->num_rx
; i
++) {
2862 rx_info
= &bnad
->rx_info
[i
];
2865 for (j
= 0; j
< bnad
->num_rxp_per_rx
; j
++) {
2866 rx_ctrl
= &rx_info
->rx_ctrl
[j
];
2868 bnad_disable_rx_irq(bnad
,
2870 bnad_netif_rx_schedule_poll(bnad
,
2879 static const struct net_device_ops bnad_netdev_ops
= {
2880 .ndo_open
= bnad_open
,
2881 .ndo_stop
= bnad_stop
,
2882 .ndo_start_xmit
= bnad_start_xmit
,
2883 .ndo_get_stats64
= bnad_get_stats64
,
2884 .ndo_set_rx_mode
= bnad_set_rx_mode
,
2885 .ndo_set_multicast_list
= bnad_set_rx_mode
,
2886 .ndo_validate_addr
= eth_validate_addr
,
2887 .ndo_set_mac_address
= bnad_set_mac_address
,
2888 .ndo_change_mtu
= bnad_change_mtu
,
2889 .ndo_vlan_rx_register
= bnad_vlan_rx_register
,
2890 .ndo_vlan_rx_add_vid
= bnad_vlan_rx_add_vid
,
2891 .ndo_vlan_rx_kill_vid
= bnad_vlan_rx_kill_vid
,
2892 #ifdef CONFIG_NET_POLL_CONTROLLER
2893 .ndo_poll_controller
= bnad_netpoll
2898 bnad_netdev_init(struct bnad
*bnad
, bool using_dac
)
2900 struct net_device
*netdev
= bnad
->netdev
;
2902 netdev
->features
|= NETIF_F_IPV6_CSUM
;
2903 netdev
->features
|= NETIF_F_TSO
;
2904 netdev
->features
|= NETIF_F_TSO6
;
2906 netdev
->features
|= NETIF_F_GRO
;
2907 pr_warn("bna: GRO enabled, using kernel stack GRO\n");
2909 netdev
->features
|= NETIF_F_SG
| NETIF_F_IP_CSUM
;
2912 netdev
->features
|= NETIF_F_HIGHDMA
;
2915 NETIF_F_HW_VLAN_TX
| NETIF_F_HW_VLAN_RX
|
2916 NETIF_F_HW_VLAN_FILTER
;
2918 netdev
->vlan_features
= netdev
->features
;
2919 netdev
->mem_start
= bnad
->mmio_start
;
2920 netdev
->mem_end
= bnad
->mmio_start
+ bnad
->mmio_len
- 1;
2922 netdev
->netdev_ops
= &bnad_netdev_ops
;
2923 bnad_set_ethtool_ops(netdev
);
2927 * 1. Initialize the bnad structure
2928 * 2. Setup netdev pointer in pci_dev
2929 * 3. Initialze Tx free tasklet
2930 * 4. Initialize no. of TxQ & CQs & MSIX vectors
2933 bnad_init(struct bnad
*bnad
,
2934 struct pci_dev
*pdev
, struct net_device
*netdev
)
2936 unsigned long flags
;
2938 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
2939 pci_set_drvdata(pdev
, netdev
);
2941 bnad
->netdev
= netdev
;
2942 bnad
->pcidev
= pdev
;
2943 bnad
->mmio_start
= pci_resource_start(pdev
, 0);
2944 bnad
->mmio_len
= pci_resource_len(pdev
, 0);
2945 bnad
->bar0
= ioremap_nocache(bnad
->mmio_start
, bnad
->mmio_len
);
2947 dev_err(&pdev
->dev
, "ioremap for bar0 failed\n");
2948 pci_set_drvdata(pdev
, NULL
);
2951 pr_info("bar0 mapped to %p, len %llu\n", bnad
->bar0
,
2952 (unsigned long long) bnad
->mmio_len
);
2954 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
2955 if (!bnad_msix_disable
)
2956 bnad
->cfg_flags
= BNAD_CF_MSIX
;
2958 bnad
->cfg_flags
|= BNAD_CF_DIM_ENABLED
;
2960 bnad_q_num_init(bnad
);
2961 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
2963 bnad
->msix_num
= (bnad
->num_tx
* bnad
->num_txq_per_tx
) +
2964 (bnad
->num_rx
* bnad
->num_rxp_per_rx
) +
2965 BNAD_MAILBOX_MSIX_VECTORS
;
2967 bnad
->txq_depth
= BNAD_TXQ_DEPTH
;
2968 bnad
->rxq_depth
= BNAD_RXQ_DEPTH
;
2969 bnad
->rx_csum
= true;
2971 bnad
->tx_coalescing_timeo
= BFI_TX_COALESCING_TIMEO
;
2972 bnad
->rx_coalescing_timeo
= BFI_RX_COALESCING_TIMEO
;
2974 tasklet_init(&bnad
->tx_free_tasklet
, bnad_tx_free_tasklet
,
2975 (unsigned long)bnad
);
2981 * Must be called after bnad_pci_uninit()
2982 * so that iounmap() and pci_set_drvdata(NULL)
2983 * happens only after PCI uninitialization.
2986 bnad_uninit(struct bnad
*bnad
)
2989 iounmap(bnad
->bar0
);
2990 pci_set_drvdata(bnad
->pcidev
, NULL
);
2995 a) Per device mutes used for serializing configuration
2996 changes from OS interface
2997 b) spin lock used to protect bna state machine
3000 bnad_lock_init(struct bnad
*bnad
)
3002 spin_lock_init(&bnad
->bna_lock
);
3003 mutex_init(&bnad
->conf_mutex
);
3007 bnad_lock_uninit(struct bnad
*bnad
)
3009 mutex_destroy(&bnad
->conf_mutex
);
3012 /* PCI Initialization */
3014 bnad_pci_init(struct bnad
*bnad
,
3015 struct pci_dev
*pdev
, bool *using_dac
)
3019 err
= pci_enable_device(pdev
);
3022 err
= pci_request_regions(pdev
, BNAD_NAME
);
3024 goto disable_device
;
3025 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) &&
3026 !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64))) {
3029 err
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
3031 err
= pci_set_consistent_dma_mask(pdev
,
3034 goto release_regions
;
3038 pci_set_master(pdev
);
3042 pci_release_regions(pdev
);
3044 pci_disable_device(pdev
);
3050 bnad_pci_uninit(struct pci_dev
*pdev
)
3052 pci_release_regions(pdev
);
3053 pci_disable_device(pdev
);
3056 static int __devinit
3057 bnad_pci_probe(struct pci_dev
*pdev
,
3058 const struct pci_device_id
*pcidev_id
)
3060 bool using_dac
= false;
3064 struct net_device
*netdev
;
3065 struct bfa_pcidev pcidev_info
;
3066 unsigned long flags
;
3068 pr_info("bnad_pci_probe : (0x%p, 0x%p) PCI Func : (%d)\n",
3069 pdev
, pcidev_id
, PCI_FUNC(pdev
->devfn
));
3071 mutex_lock(&bnad_fwimg_mutex
);
3072 if (!cna_get_firmware_buf(pdev
)) {
3073 mutex_unlock(&bnad_fwimg_mutex
);
3074 pr_warn("Failed to load Firmware Image!\n");
3077 mutex_unlock(&bnad_fwimg_mutex
);
3080 * Allocates sizeof(struct net_device + struct bnad)
3081 * bnad = netdev->priv
3083 netdev
= alloc_etherdev(sizeof(struct bnad
));
3085 dev_err(&pdev
->dev
, "alloc_etherdev failed\n");
3089 bnad
= netdev_priv(netdev
);
3092 * PCI initialization
3093 * Output : using_dac = 1 for 64 bit DMA
3094 * = 0 for 32 bit DMA
3096 err
= bnad_pci_init(bnad
, pdev
, &using_dac
);
3100 bnad_lock_init(bnad
);
3102 * Initialize bnad structure
3103 * Setup relation between pci_dev & netdev
3104 * Init Tx free tasklet
3106 err
= bnad_init(bnad
, pdev
, netdev
);
3109 /* Initialize netdev structure, set up ethtool ops */
3110 bnad_netdev_init(bnad
, using_dac
);
3112 /* Set link to down state */
3113 netif_carrier_off(netdev
);
3115 bnad_enable_msix(bnad
);
3117 /* Get resource requirement form bna */
3118 bna_res_req(&bnad
->res_info
[0]);
3120 /* Allocate resources from bna */
3121 err
= bnad_res_alloc(bnad
);
3127 /* Setup pcidev_info for bna_init() */
3128 pcidev_info
.pci_slot
= PCI_SLOT(bnad
->pcidev
->devfn
);
3129 pcidev_info
.pci_func
= PCI_FUNC(bnad
->pcidev
->devfn
);
3130 pcidev_info
.device_id
= bnad
->pcidev
->device
;
3131 pcidev_info
.pci_bar_kva
= bnad
->bar0
;
3133 mutex_lock(&bnad
->conf_mutex
);
3135 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
3136 bna_init(bna
, bnad
, &pcidev_info
, &bnad
->res_info
[0]);
3137 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
3139 bnad
->stats
.bna_stats
= &bna
->stats
;
3142 setup_timer(&bnad
->bna
.device
.ioc
.ioc_timer
, bnad_ioc_timeout
,
3143 ((unsigned long)bnad
));
3144 setup_timer(&bnad
->bna
.device
.ioc
.hb_timer
, bnad_ioc_hb_check
,
3145 ((unsigned long)bnad
));
3146 setup_timer(&bnad
->bna
.device
.ioc
.iocpf_timer
, bnad_iocpf_timeout
,
3147 ((unsigned long)bnad
));
3148 setup_timer(&bnad
->bna
.device
.ioc
.sem_timer
, bnad_iocpf_sem_timeout
,
3149 ((unsigned long)bnad
));
3151 /* Now start the timer before calling IOC */
3152 mod_timer(&bnad
->bna
.device
.ioc
.iocpf_timer
,
3153 jiffies
+ msecs_to_jiffies(BNA_IOC_TIMER_FREQ
));
3157 * Don't care even if err != 0, bna state machine will
3160 err
= bnad_device_enable(bnad
);
3162 /* Get the burnt-in mac */
3163 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
3164 bna_port_mac_get(&bna
->port
, &bnad
->perm_addr
);
3165 bnad_set_netdev_perm_addr(bnad
);
3166 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
3168 mutex_unlock(&bnad
->conf_mutex
);
3170 /* Finally, reguister with net_device layer */
3171 err
= register_netdev(netdev
);
3173 pr_err("BNA : Registering with netdev failed\n");
3174 goto disable_device
;
3180 mutex_lock(&bnad
->conf_mutex
);
3181 bnad_device_disable(bnad
);
3182 del_timer_sync(&bnad
->bna
.device
.ioc
.ioc_timer
);
3183 del_timer_sync(&bnad
->bna
.device
.ioc
.sem_timer
);
3184 del_timer_sync(&bnad
->bna
.device
.ioc
.hb_timer
);
3185 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
3187 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
3188 mutex_unlock(&bnad
->conf_mutex
);
3190 bnad_res_free(bnad
);
3191 bnad_disable_msix(bnad
);
3193 bnad_pci_uninit(pdev
);
3194 bnad_lock_uninit(bnad
);
3197 free_netdev(netdev
);
3201 static void __devexit
3202 bnad_pci_remove(struct pci_dev
*pdev
)
3204 struct net_device
*netdev
= pci_get_drvdata(pdev
);
3207 unsigned long flags
;
3212 pr_info("%s bnad_pci_remove\n", netdev
->name
);
3213 bnad
= netdev_priv(netdev
);
3216 unregister_netdev(netdev
);
3218 mutex_lock(&bnad
->conf_mutex
);
3219 bnad_device_disable(bnad
);
3220 del_timer_sync(&bnad
->bna
.device
.ioc
.ioc_timer
);
3221 del_timer_sync(&bnad
->bna
.device
.ioc
.sem_timer
);
3222 del_timer_sync(&bnad
->bna
.device
.ioc
.hb_timer
);
3223 spin_lock_irqsave(&bnad
->bna_lock
, flags
);
3225 spin_unlock_irqrestore(&bnad
->bna_lock
, flags
);
3226 mutex_unlock(&bnad
->conf_mutex
);
3228 bnad_res_free(bnad
);
3229 bnad_disable_msix(bnad
);
3230 bnad_pci_uninit(pdev
);
3231 bnad_lock_uninit(bnad
);
3233 free_netdev(netdev
);
3236 static const struct pci_device_id bnad_pci_id_table
[] = {
3238 PCI_DEVICE(PCI_VENDOR_ID_BROCADE
,
3239 PCI_DEVICE_ID_BROCADE_CT
),
3240 .class = PCI_CLASS_NETWORK_ETHERNET
<< 8,
3241 .class_mask
= 0xffff00
3245 MODULE_DEVICE_TABLE(pci
, bnad_pci_id_table
);
3247 static struct pci_driver bnad_pci_driver
= {
3249 .id_table
= bnad_pci_id_table
,
3250 .probe
= bnad_pci_probe
,
3251 .remove
= __devexit_p(bnad_pci_remove
),
3255 bnad_module_init(void)
3259 pr_info("Brocade 10G Ethernet driver\n");
3261 bfa_nw_ioc_auto_recover(bnad_ioc_auto_recover
);
3263 err
= pci_register_driver(&bnad_pci_driver
);
3265 pr_err("bna : PCI registration failed in module init "
3274 bnad_module_exit(void)
3276 pci_unregister_driver(&bnad_pci_driver
);
3279 release_firmware(bfi_fw
);
3282 module_init(bnad_module_init
);
3283 module_exit(bnad_module_exit
);
3285 MODULE_AUTHOR("Brocade");
3286 MODULE_LICENSE("GPL");
3287 MODULE_DESCRIPTION("Brocade 10G PCIe Ethernet driver");
3288 MODULE_VERSION(BNAD_VERSION
);
3289 MODULE_FIRMWARE(CNA_FW_FILE_CT
);