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>
27 #include <linux/if_vlan.h>
30 #include <asm/checksum.h>
31 #include <net/ip6_checksum.h>
38 #define BNAD_TXQ_DEPTH 2048
39 #define BNAD_RXQ_DEPTH 2048
42 #define BNAD_MAX_TXQ_PER_TX 8 /* 8 priority queues */
43 #define BNAD_TXQ_NUM 1
46 #define BNAD_MAX_RXP_PER_RX 16
47 #define BNAD_MAX_RXQ_PER_RXP 2
50 * Control structure pointed to ccb->ctrl, which
51 * determines the NAPI / LRO behavior CCB
52 * There is 1:1 corres. between ccb & ctrl
58 struct napi_struct napi;
66 #define BNAD_RXMODE_PROMISC_DEFAULT BNA_RXMODE_PROMISC
69 * GLOBAL #defines (CONSTANTS)
71 #define BNAD_NAME "bna"
72 #define BNAD_NAME_LEN 64
74 #define BNAD_VERSION "3.2.21.1"
76 #define BNAD_MAILBOX_MSIX_INDEX 0
77 #define BNAD_MAILBOX_MSIX_VECTORS 1
78 #define BNAD_INTX_TX_IB_BITMASK 0x1
79 #define BNAD_INTX_RX_IB_BITMASK 0x2
81 #define BNAD_STATS_TIMER_FREQ 1000 /* in msecs */
82 #define BNAD_DIM_TIMER_FREQ 1000 /* in msecs */
84 #define BNAD_IOCETH_TIMEOUT 10000
86 #define BNAD_MIN_Q_DEPTH 512
87 #define BNAD_MAX_RXQ_DEPTH 2048
88 #define BNAD_MAX_TXQ_DEPTH 2048
90 #define BNAD_JUMBO_MTU 9000
92 #define BNAD_NETIF_WAKE_THRESHOLD 8
94 #define BNAD_RXQ_REFILL_THRESHOLD_SHIFT 3
96 /* Bit positions for tcb->flags */
97 #define BNAD_TXQ_FREE_SENT 0
98 #define BNAD_TXQ_TX_STARTED 1
100 /* Bit positions for rcb->flags */
101 #define BNAD_RXQ_STARTED 0
102 #define BNAD_RXQ_POST_OK 1
104 /* Resource limits */
105 #define BNAD_NUM_TXQ (bnad->num_tx * bnad->num_txq_per_tx)
106 #define BNAD_NUM_RXP (bnad->num_rx * bnad->num_rxp_per_rx)
113 enum bnad_intr_source {
118 enum bnad_link_state {
123 struct bnad_iocmd_comp {
125 struct completion comp;
129 struct bnad_completion {
130 struct completion ioc_comp;
131 struct completion ucast_comp;
132 struct completion mcast_comp;
133 struct completion tx_comp;
134 struct completion rx_comp;
135 struct completion stats_comp;
136 struct completion enet_comp;
137 struct completion mtu_comp;
140 u8 ucast_comp_status;
141 u8 mcast_comp_status;
144 u8 stats_comp_status;
149 /* Tx Rx Control Stats */
150 struct bnad_drv_stats {
151 u64 netif_queue_stop;
152 u64 netif_queue_wakeup;
153 u64 netif_queue_stopped;
160 u64 tx_skb_too_short;
162 u64 tx_skb_max_vectors;
163 u64 tx_skb_mss_too_long;
164 u64 tx_skb_tso_too_short;
165 u64 tx_skb_tso_prepare;
166 u64 tx_skb_non_tso_too_long;
170 u64 tx_skb_headlen_too_long;
171 u64 tx_skb_headlen_zero;
172 u64 tx_skb_frag_zero;
173 u64 tx_skb_len_mismatch;
175 u64 hw_stats_updates;
176 u64 netif_rx_dropped;
181 u64 rxp_info_alloc_failed;
182 u64 mbox_intr_disabled;
183 u64 mbox_intr_enabled;
184 u64 tx_unmap_q_alloc_failed;
185 u64 rx_unmap_q_alloc_failed;
187 u64 rxbuf_alloc_failed;
190 /* Complete driver stats */
192 struct bnad_drv_stats drv_stats;
193 struct bna_stats *bna_stats;
196 /* Tx / Rx Resources */
197 struct bnad_tx_res_info {
198 struct bna_res_info res_info[BNA_TX_RES_T_MAX];
201 struct bnad_rx_res_info {
202 struct bna_res_info res_info[BNA_RX_RES_T_MAX];
205 struct bnad_tx_info {
206 struct bna_tx *tx; /* 1:1 between tx_info & tx */
207 struct bna_tcb *tcb[BNAD_MAX_TXQ_PER_TX];
209 struct delayed_work tx_cleanup_work;
210 } ____cacheline_aligned;
212 struct bnad_rx_info {
213 struct bna_rx *rx; /* 1:1 between rx_info & rx */
215 struct bnad_rx_ctrl rx_ctrl[BNAD_MAX_RXP_PER_RX];
217 struct work_struct rx_cleanup_work;
218 } ____cacheline_aligned;
220 struct bnad_tx_vector {
221 DEFINE_DMA_UNMAP_ADDR(dma_addr);
224 struct bnad_tx_unmap {
227 struct bnad_tx_vector vectors[BFI_TX_MAX_VECTORS_PER_WI];
230 struct bnad_rx_vector {
231 DEFINE_DMA_UNMAP_ADDR(dma_addr);
235 struct bnad_rx_unmap {
239 struct bnad_rx_vector vector;
242 enum bnad_rxbuf_type {
249 #define BNAD_RXBUF_IS_PAGE(_type) ((_type) == BNAD_RXBUF_PAGE)
251 struct bnad_rx_unmap_q {
255 enum bnad_rxbuf_type type;
256 struct bnad_rx_unmap unmap[0];
259 /* Bit mask values for bnad->cfg_flags */
260 #define BNAD_CF_DIM_ENABLED 0x01 /* DIM */
261 #define BNAD_CF_PROMISC 0x02
262 #define BNAD_CF_ALLMULTI 0x04
263 #define BNAD_CF_MSIX 0x08 /* If in MSIx mode */
265 /* Defines for run_flags bit-mask */
266 /* Set, tested & cleared using xxx_bit() functions */
267 /* Values indicated bit positions */
268 #define BNAD_RF_CEE_RUNNING 0
269 #define BNAD_RF_MTU_SET 1
270 #define BNAD_RF_MBOX_IRQ_DISABLED 2
271 #define BNAD_RF_NETDEV_REGISTERED 3
272 #define BNAD_RF_DIM_TIMER_RUNNING 4
273 #define BNAD_RF_STATS_TIMER_RUNNING 5
274 #define BNAD_RF_TX_PRIO_SET 6
277 struct net_device *netdev;
279 struct list_head list_entry;
282 struct bnad_tx_info tx_info[BNAD_MAX_TX];
283 struct bnad_rx_info rx_info[BNAD_MAX_RX];
285 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
287 * These q numbers are global only because
288 * they are used to calculate MSIx vectors.
289 * Actually the exact # of queues are per Tx/Rx
300 u8 tx_coalescing_timeo;
301 u8 rx_coalescing_timeo;
303 struct bna_rx_config rx_config[BNAD_MAX_RX] ____cacheline_aligned;
304 struct bna_tx_config tx_config[BNAD_MAX_TX] ____cacheline_aligned;
306 void __iomem *bar0; /* BAR0 address */
311 unsigned long run_flags;
313 struct pci_dev *pcidev;
318 struct msix_entry *msix_table;
320 struct mutex conf_mutex;
321 spinlock_t bna_lock ____cacheline_aligned;
324 struct timer_list ioc_timer;
325 struct timer_list dim_timer;
326 struct timer_list stats_timer;
328 /* Control path resources, memory & irq */
329 struct bna_res_info res_info[BNA_RES_T_MAX];
330 struct bna_res_info mod_res_info[BNA_MOD_RES_T_MAX];
331 struct bnad_tx_res_info tx_res_info[BNAD_MAX_TX];
332 struct bnad_rx_res_info rx_res_info[BNAD_MAX_RX];
334 struct bnad_completion bnad_completions;
336 /* Burnt in MAC address */
339 struct workqueue_struct *work_q;
342 struct bnad_stats stats;
344 struct bnad_diag *diag;
346 char adapter_name[BNAD_NAME_LEN];
347 char port_name[BNAD_NAME_LEN];
348 char mbox_irq_name[BNAD_NAME_LEN];
349 char wq_name[BNAD_NAME_LEN];
351 /* debugfs specific data */
354 struct dentry *bnad_dentry_files[5];
355 struct dentry *port_debugfs_root;
358 struct bnad_drvinfo {
359 struct bfa_ioc_attr ioc_attr;
360 struct bfa_cee_attr cee_attr;
361 struct bfa_flash_attr flash_attr;
369 extern const struct firmware *bfi_fw;
370 extern u32 bnad_rxqs_per_cq;
375 extern u32 *cna_get_firmware_buf(struct pci_dev *pdev);
376 /* Netdev entry point prototypes */
377 extern void bnad_set_rx_mode(struct net_device *netdev);
378 extern struct net_device_stats *bnad_get_netdev_stats(
379 struct net_device *netdev);
380 extern int bnad_mac_addr_set_locked(struct bnad *bnad, u8 *mac_addr);
381 extern int bnad_enable_default_bcast(struct bnad *bnad);
382 extern void bnad_restore_vlans(struct bnad *bnad, u32 rx_id);
383 extern void bnad_set_ethtool_ops(struct net_device *netdev);
384 extern void bnad_cb_completion(void *arg, enum bfa_status status);
386 /* Configuration & setup */
387 extern void bnad_tx_coalescing_timeo_set(struct bnad *bnad);
388 extern void bnad_rx_coalescing_timeo_set(struct bnad *bnad);
390 extern int bnad_setup_rx(struct bnad *bnad, u32 rx_id);
391 extern int bnad_setup_tx(struct bnad *bnad, u32 tx_id);
392 extern void bnad_destroy_tx(struct bnad *bnad, u32 tx_id);
393 extern void bnad_destroy_rx(struct bnad *bnad, u32 rx_id);
395 /* Timer start/stop protos */
396 extern void bnad_dim_timer_start(struct bnad *bnad);
399 extern void bnad_netdev_qstats_fill(struct bnad *bnad,
400 struct rtnl_link_stats64 *stats);
401 extern void bnad_netdev_hwstats_fill(struct bnad *bnad,
402 struct rtnl_link_stats64 *stats);
405 void bnad_debugfs_init(struct bnad *bnad);
406 void bnad_debugfs_uninit(struct bnad *bnad);
409 /* To set & get the stats counters */
410 #define BNAD_UPDATE_CTR(_bnad, _ctr) \
411 (((_bnad)->stats.drv_stats._ctr)++)
413 #define BNAD_GET_CTR(_bnad, _ctr) ((_bnad)->stats.drv_stats._ctr)
415 #define bnad_enable_rx_irq_unsafe(_ccb) \
417 if (likely(test_bit(BNAD_RXQ_STARTED, &(_ccb)->rcb[0]->flags))) {\
418 bna_ib_coalescing_timer_set((_ccb)->i_dbell, \
419 (_ccb)->rx_coalescing_timeo); \
420 bna_ib_ack((_ccb)->i_dbell, 0); \
424 #endif /* __BNAD_H__ */