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.
21 #include <linux/rtnetlink.h>
22 #include <linux/workqueue.h>
23 #include <linux/ipv6.h>
24 #include <linux/etherdevice.h>
25 #include <linux/mutex.h>
26 #include <linux/firmware.h>
29 #include <asm/checksum.h>
30 #include <net/ip6_checksum.h>
37 #define BNAD_TXQ_DEPTH 2048
38 #define BNAD_RXQ_DEPTH 2048
40 #define BNAD_MAX_TXS 1
41 #define BNAD_MAX_TXQ_PER_TX 8 /* 8 priority queues */
42 #define BNAD_TXQ_NUM 1
44 #define BNAD_MAX_RXS 1
45 #define BNAD_MAX_RXPS_PER_RX 16
48 * Control structure pointed to ccb->ctrl, which
49 * determines the NAPI / LRO behavior CCB
50 * There is 1:1 corres. between ccb & ctrl
54 struct napi_struct napi
;
57 #define BNAD_RXMODE_PROMISC_DEFAULT BNA_RXMODE_PROMISC
59 #define BNAD_GET_TX_ID(_skb) (0)
62 * GLOBAL #defines (CONSTANTS)
64 #define BNAD_NAME "bna"
65 #define BNAD_NAME_LEN 64
67 #define BNAD_VERSION "2.3.2.0"
69 #define BNAD_MAILBOX_MSIX_VECTORS 1
71 #define BNAD_STATS_TIMER_FREQ 1000 /* in msecs */
72 #define BNAD_DIM_TIMER_FREQ 1000 /* in msecs */
74 #define BNAD_MAX_Q_DEPTH 0x10000
75 #define BNAD_MIN_Q_DEPTH 0x200
77 #define BNAD_JUMBO_MTU 9000
79 #define BNAD_NETIF_WAKE_THRESHOLD 8
81 #define BNAD_RXQ_REFILL_THRESHOLD_SHIFT 3
83 /* Bit positions for tcb->flags */
84 #define BNAD_TXQ_FREE_SENT 0
86 /* Bit positions for rcb->flags */
87 #define BNAD_RXQ_REFILL 0
88 #define BNAD_RXQ_STARTED 1
95 enum bnad_intr_source
{
100 enum bnad_link_state
{
105 struct bnad_completion
{
106 struct completion ioc_comp
;
107 struct completion ucast_comp
;
108 struct completion mcast_comp
;
109 struct completion tx_comp
;
110 struct completion rx_comp
;
111 struct completion stats_comp
;
112 struct completion port_comp
;
115 u8 ucast_comp_status
;
116 u8 mcast_comp_status
;
119 u8 stats_comp_status
;
123 /* Tx Rx Control Stats */
124 struct bnad_drv_stats
{
125 u64 netif_queue_stop
;
126 u64 netif_queue_wakeup
;
135 u64 hw_stats_updates
;
136 u64 netif_rx_schedule
;
137 u64 netif_rx_complete
;
138 u64 netif_rx_dropped
;
143 u64 rxp_info_alloc_failed
;
144 u64 mbox_intr_disabled
;
145 u64 mbox_intr_enabled
;
146 u64 tx_unmap_q_alloc_failed
;
147 u64 rx_unmap_q_alloc_failed
;
149 u64 rxbuf_alloc_failed
;
152 /* Complete driver stats */
154 struct bnad_drv_stats drv_stats
;
155 struct bna_stats
*bna_stats
;
158 /* Tx / Rx Resources */
159 struct bnad_tx_res_info
{
160 struct bna_res_info res_info
[BNA_TX_RES_T_MAX
];
163 struct bnad_rx_res_info
{
164 struct bna_res_info res_info
[BNA_RX_RES_T_MAX
];
167 struct bnad_tx_info
{
168 struct bna_tx
*tx
; /* 1:1 between tx_info & tx */
169 struct bna_tcb
*tcb
[BNAD_MAX_TXQ_PER_TX
];
170 } ____cacheline_aligned
;
172 struct bnad_rx_info
{
173 struct bna_rx
*rx
; /* 1:1 between rx_info & rx */
175 struct bnad_rx_ctrl rx_ctrl
[BNAD_MAX_RXPS_PER_RX
];
176 } ____cacheline_aligned
;
178 /* Unmap queues for Tx / Rx cleanup */
179 struct bnad_skb_unmap
{
181 DECLARE_PCI_UNMAP_ADDR(dma_addr
)
184 struct bnad_unmap_q
{
188 /* This should be the last one */
189 struct bnad_skb_unmap unmap_array
[1];
192 /* Bit mask values for bnad->cfg_flags */
193 #define BNAD_CF_DIM_ENABLED 0x01 /* DIM */
194 #define BNAD_CF_PROMISC 0x02
195 #define BNAD_CF_ALLMULTI 0x04
196 #define BNAD_CF_MSIX 0x08 /* If in MSIx mode */
198 /* Defines for run_flags bit-mask */
199 /* Set, tested & cleared using xxx_bit() functions */
200 /* Values indicated bit positions */
201 #define BNAD_RF_CEE_RUNNING 1
202 #define BNAD_RF_HW_ERROR 2
203 #define BNAD_RF_MBOX_IRQ_DISABLED 3
204 #define BNAD_RF_TX_STARTED 4
205 #define BNAD_RF_RX_STARTED 5
206 #define BNAD_RF_DIM_TIMER_RUNNING 6
207 #define BNAD_RF_STATS_TIMER_RUNNING 7
210 struct net_device
*netdev
;
213 struct bnad_tx_info tx_info
[BNAD_MAX_TXS
];
214 struct bnad_rx_info rx_info
[BNAD_MAX_RXS
];
216 struct vlan_group
*vlan_grp
;
218 * These q numbers are global only because
219 * they are used to calculate MSIx vectors.
220 * Actually the exact # of queues are per Tx/Rx
231 u8 tx_coalescing_timeo
;
232 u8 rx_coalescing_timeo
;
234 struct bna_rx_config rx_config
[BNAD_MAX_RXS
];
235 struct bna_tx_config tx_config
[BNAD_MAX_TXS
];
239 void __iomem
*bar0
; /* BAR0 address */
244 unsigned long run_flags
;
246 struct pci_dev
*pcidev
;
251 struct msix_entry
*msix_table
;
253 struct mutex conf_mutex
;
254 spinlock_t bna_lock ____cacheline_aligned
;
257 struct timer_list ioc_timer
;
258 struct timer_list dim_timer
;
259 struct timer_list stats_timer
;
261 /* Control path resources, memory & irq */
262 struct bna_res_info res_info
[BNA_RES_T_MAX
];
263 struct bnad_tx_res_info tx_res_info
[BNAD_MAX_TXS
];
264 struct bnad_rx_res_info rx_res_info
[BNAD_MAX_RXS
];
266 struct bnad_completion bnad_completions
;
268 /* Burnt in MAC address */
271 struct tasklet_struct tx_free_tasklet
;
274 struct bnad_stats stats
;
276 struct bnad_diag
*diag
;
278 char adapter_name
[BNAD_NAME_LEN
];
279 char port_name
[BNAD_NAME_LEN
];
280 char mbox_irq_name
[BNAD_NAME_LEN
];
286 extern struct firmware
*bfi_fw
;
287 extern u32 bnad_rxqs_per_cq
;
292 extern u32
*cna_get_firmware_buf(struct pci_dev
*pdev
);
293 /* Netdev entry point prototypes */
294 extern void bnad_set_ethtool_ops(struct net_device
*netdev
);
296 /* Configuration & setup */
297 extern void bnad_tx_coalescing_timeo_set(struct bnad
*bnad
);
298 extern void bnad_rx_coalescing_timeo_set(struct bnad
*bnad
);
300 extern int bnad_setup_rx(struct bnad
*bnad
, uint rx_id
);
301 extern int bnad_setup_tx(struct bnad
*bnad
, uint tx_id
);
302 extern void bnad_cleanup_tx(struct bnad
*bnad
, uint tx_id
);
303 extern void bnad_cleanup_rx(struct bnad
*bnad
, uint rx_id
);
305 /* Timer start/stop protos */
306 extern void bnad_dim_timer_start(struct bnad
*bnad
);
309 extern void bnad_netdev_qstats_fill(struct bnad
*bnad
, struct rtnl_link_stats64
*stats
);
310 extern void bnad_netdev_hwstats_fill(struct bnad
*bnad
, struct rtnl_link_stats64
*stats
);
315 /* To set & get the stats counters */
316 #define BNAD_UPDATE_CTR(_bnad, _ctr) \
317 (((_bnad)->stats.drv_stats._ctr)++)
319 #define BNAD_GET_CTR(_bnad, _ctr) ((_bnad)->stats.drv_stats._ctr)
321 #define bnad_enable_rx_irq_unsafe(_ccb) \
323 bna_ib_coalescing_timer_set((_ccb)->i_dbell, \
324 (_ccb)->rx_coalescing_timeo); \
325 bna_ib_ack((_ccb)->i_dbell, 0); \
328 #define bnad_dim_timer_running(_bnad) \
329 (((_bnad)->cfg_flags & BNAD_CF_DIM_ENABLED) && \
330 (test_bit(BNAD_RF_DIM_TIMER_RUNNING, &((_bnad)->run_flags))))
332 #endif /* __BNAD_H__ */