bna: TX Queue Depth Fix
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / net / ethernet / brocade / bna / bnad.h
blob6c42c1441679e9caebc834c22c48c80c2f2fdff8
1 /*
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.
15 * All rights reserved
16 * www.brocade.com
18 #ifndef __BNAD_H__
19 #define __BNAD_H__
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>
29 /* Fix for IA64 */
30 #include <asm/checksum.h>
31 #include <net/ip6_checksum.h>
33 #include <net/ip.h>
34 #include <net/tcp.h>
36 #include "bna.h"
38 #define BNAD_TXQ_DEPTH 2048
39 #define BNAD_RXQ_DEPTH 2048
41 #define BNAD_MAX_TX 1
42 #define BNAD_MAX_TXQ_PER_TX 8 /* 8 priority queues */
43 #define BNAD_TXQ_NUM 1
45 #define BNAD_MAX_RX 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
54 struct bnad_rx_ctrl {
55 struct bna_ccb *ccb;
56 struct bnad *bnad;
57 unsigned long flags;
58 struct napi_struct napi;
59 u64 rx_intr_ctr;
60 u64 rx_poll_ctr;
61 u64 rx_schedule;
62 u64 rx_keep_poll;
63 u64 rx_complete;
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.0.2.0"
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_MAX_Q_DEPTH 0x10000
87 #define BNAD_MIN_Q_DEPTH 0x200
89 #define BNAD_MAX_RXQ_DEPTH (BNAD_MAX_Q_DEPTH / bnad_rxqs_per_cq)
90 /* keeping MAX TX and RX Q depth equal */
91 #define BNAD_MAX_TXQ_DEPTH BNAD_MAX_RXQ_DEPTH
93 #define BNAD_JUMBO_MTU 9000
95 #define BNAD_NETIF_WAKE_THRESHOLD 8
97 #define BNAD_RXQ_REFILL_THRESHOLD_SHIFT 3
99 /* Bit positions for tcb->flags */
100 #define BNAD_TXQ_FREE_SENT 0
101 #define BNAD_TXQ_TX_STARTED 1
103 /* Bit positions for rcb->flags */
104 #define BNAD_RXQ_REFILL 0
105 #define BNAD_RXQ_STARTED 1
107 /* Resource limits */
108 #define BNAD_NUM_TXQ (bnad->num_tx * bnad->num_txq_per_tx)
109 #define BNAD_NUM_RXP (bnad->num_rx * bnad->num_rxp_per_rx)
112 * DATA STRUCTURES
115 /* enums */
116 enum bnad_intr_source {
117 BNAD_INTR_TX = 1,
118 BNAD_INTR_RX = 2
121 enum bnad_link_state {
122 BNAD_LS_DOWN = 0,
123 BNAD_LS_UP = 1
126 struct bnad_completion {
127 struct completion ioc_comp;
128 struct completion ucast_comp;
129 struct completion mcast_comp;
130 struct completion tx_comp;
131 struct completion rx_comp;
132 struct completion stats_comp;
133 struct completion enet_comp;
134 struct completion mtu_comp;
136 u8 ioc_comp_status;
137 u8 ucast_comp_status;
138 u8 mcast_comp_status;
139 u8 tx_comp_status;
140 u8 rx_comp_status;
141 u8 stats_comp_status;
142 u8 port_comp_status;
143 u8 mtu_comp_status;
146 /* Tx Rx Control Stats */
147 struct bnad_drv_stats {
148 u64 netif_queue_stop;
149 u64 netif_queue_wakeup;
150 u64 netif_queue_stopped;
151 u64 tso4;
152 u64 tso6;
153 u64 tso_err;
154 u64 tcpcsum_offload;
155 u64 udpcsum_offload;
156 u64 csum_help;
157 u64 tx_skb_too_short;
158 u64 tx_skb_stopping;
159 u64 tx_skb_max_vectors;
160 u64 tx_skb_mss_too_long;
161 u64 tx_skb_tso_too_short;
162 u64 tx_skb_tso_prepare;
163 u64 tx_skb_non_tso_too_long;
164 u64 tx_skb_tcp_hdr;
165 u64 tx_skb_udp_hdr;
166 u64 tx_skb_csum_err;
167 u64 tx_skb_headlen_too_long;
168 u64 tx_skb_headlen_zero;
169 u64 tx_skb_frag_zero;
170 u64 tx_skb_len_mismatch;
172 u64 hw_stats_updates;
173 u64 netif_rx_dropped;
175 u64 link_toggle;
176 u64 cee_toggle;
178 u64 rxp_info_alloc_failed;
179 u64 mbox_intr_disabled;
180 u64 mbox_intr_enabled;
181 u64 tx_unmap_q_alloc_failed;
182 u64 rx_unmap_q_alloc_failed;
184 u64 rxbuf_alloc_failed;
187 /* Complete driver stats */
188 struct bnad_stats {
189 struct bnad_drv_stats drv_stats;
190 struct bna_stats *bna_stats;
193 /* Tx / Rx Resources */
194 struct bnad_tx_res_info {
195 struct bna_res_info res_info[BNA_TX_RES_T_MAX];
198 struct bnad_rx_res_info {
199 struct bna_res_info res_info[BNA_RX_RES_T_MAX];
202 struct bnad_tx_info {
203 struct bna_tx *tx; /* 1:1 between tx_info & tx */
204 struct bna_tcb *tcb[BNAD_MAX_TXQ_PER_TX];
205 u32 tx_id;
206 } ____cacheline_aligned;
208 struct bnad_rx_info {
209 struct bna_rx *rx; /* 1:1 between rx_info & rx */
211 struct bnad_rx_ctrl rx_ctrl[BNAD_MAX_RXP_PER_RX];
212 u32 rx_id;
213 } ____cacheline_aligned;
215 /* Unmap queues for Tx / Rx cleanup */
216 struct bnad_skb_unmap {
217 struct sk_buff *skb;
218 DEFINE_DMA_UNMAP_ADDR(dma_addr);
221 struct bnad_unmap_q {
222 u32 producer_index;
223 u32 consumer_index;
224 u32 q_depth;
225 /* This should be the last one */
226 struct bnad_skb_unmap unmap_array[1];
229 /* Bit mask values for bnad->cfg_flags */
230 #define BNAD_CF_DIM_ENABLED 0x01 /* DIM */
231 #define BNAD_CF_PROMISC 0x02
232 #define BNAD_CF_ALLMULTI 0x04
233 #define BNAD_CF_MSIX 0x08 /* If in MSIx mode */
235 /* Defines for run_flags bit-mask */
236 /* Set, tested & cleared using xxx_bit() functions */
237 /* Values indicated bit positions */
238 #define BNAD_RF_CEE_RUNNING 0
239 #define BNAD_RF_MTU_SET 1
240 #define BNAD_RF_MBOX_IRQ_DISABLED 2
241 #define BNAD_RF_NETDEV_REGISTERED 3
242 #define BNAD_RF_DIM_TIMER_RUNNING 4
243 #define BNAD_RF_STATS_TIMER_RUNNING 5
244 #define BNAD_RF_TX_PRIO_SET 6
247 /* Define for Fast Path flags */
248 /* Defined as bit positions */
249 #define BNAD_FP_IN_RX_PATH 0
251 struct bnad {
252 struct net_device *netdev;
254 /* Data path */
255 struct bnad_tx_info tx_info[BNAD_MAX_TX];
256 struct bnad_rx_info rx_info[BNAD_MAX_RX];
258 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
260 * These q numbers are global only because
261 * they are used to calculate MSIx vectors.
262 * Actually the exact # of queues are per Tx/Rx
263 * object.
265 u32 num_tx;
266 u32 num_rx;
267 u32 num_txq_per_tx;
268 u32 num_rxp_per_rx;
270 u32 txq_depth;
271 u32 rxq_depth;
273 u8 tx_coalescing_timeo;
274 u8 rx_coalescing_timeo;
276 struct bna_rx_config rx_config[BNAD_MAX_RX];
277 struct bna_tx_config tx_config[BNAD_MAX_TX];
279 void __iomem *bar0; /* BAR0 address */
281 struct bna bna;
283 u32 cfg_flags;
284 unsigned long run_flags;
286 struct pci_dev *pcidev;
287 u64 mmio_start;
288 u64 mmio_len;
290 u32 msix_num;
291 struct msix_entry *msix_table;
293 struct mutex conf_mutex;
294 spinlock_t bna_lock ____cacheline_aligned;
296 /* Timers */
297 struct timer_list ioc_timer;
298 struct timer_list dim_timer;
299 struct timer_list stats_timer;
301 /* Control path resources, memory & irq */
302 struct bna_res_info res_info[BNA_RES_T_MAX];
303 struct bna_res_info mod_res_info[BNA_MOD_RES_T_MAX];
304 struct bnad_tx_res_info tx_res_info[BNAD_MAX_TX];
305 struct bnad_rx_res_info rx_res_info[BNAD_MAX_RX];
307 struct bnad_completion bnad_completions;
309 /* Burnt in MAC address */
310 mac_t perm_addr;
312 struct tasklet_struct tx_free_tasklet;
314 /* Statistics */
315 struct bnad_stats stats;
317 struct bnad_diag *diag;
319 char adapter_name[BNAD_NAME_LEN];
320 char port_name[BNAD_NAME_LEN];
321 char mbox_irq_name[BNAD_NAME_LEN];
325 * EXTERN VARIABLES
327 extern struct firmware *bfi_fw;
328 extern u32 bnad_rxqs_per_cq;
331 * EXTERN PROTOTYPES
333 extern u32 *cna_get_firmware_buf(struct pci_dev *pdev);
334 /* Netdev entry point prototypes */
335 extern void bnad_set_rx_mode(struct net_device *netdev);
336 extern struct net_device_stats *bnad_get_netdev_stats(
337 struct net_device *netdev);
338 extern int bnad_mac_addr_set_locked(struct bnad *bnad, u8 *mac_addr);
339 extern int bnad_enable_default_bcast(struct bnad *bnad);
340 extern void bnad_restore_vlans(struct bnad *bnad, u32 rx_id);
341 extern void bnad_set_ethtool_ops(struct net_device *netdev);
343 /* Configuration & setup */
344 extern void bnad_tx_coalescing_timeo_set(struct bnad *bnad);
345 extern void bnad_rx_coalescing_timeo_set(struct bnad *bnad);
347 extern int bnad_setup_rx(struct bnad *bnad, u32 rx_id);
348 extern int bnad_setup_tx(struct bnad *bnad, u32 tx_id);
349 extern void bnad_cleanup_tx(struct bnad *bnad, u32 tx_id);
350 extern void bnad_cleanup_rx(struct bnad *bnad, u32 rx_id);
352 /* Timer start/stop protos */
353 extern void bnad_dim_timer_start(struct bnad *bnad);
355 /* Statistics */
356 extern void bnad_netdev_qstats_fill(struct bnad *bnad,
357 struct rtnl_link_stats64 *stats);
358 extern void bnad_netdev_hwstats_fill(struct bnad *bnad,
359 struct rtnl_link_stats64 *stats);
362 * MACROS
364 /* To set & get the stats counters */
365 #define BNAD_UPDATE_CTR(_bnad, _ctr) \
366 (((_bnad)->stats.drv_stats._ctr)++)
368 #define BNAD_GET_CTR(_bnad, _ctr) ((_bnad)->stats.drv_stats._ctr)
370 #define bnad_enable_rx_irq_unsafe(_ccb) \
372 if (likely(test_bit(BNAD_RXQ_STARTED, &(_ccb)->rcb[0]->flags))) {\
373 bna_ib_coalescing_timer_set((_ccb)->i_dbell, \
374 (_ccb)->rx_coalescing_timeo); \
375 bna_ib_ack((_ccb)->i_dbell, 0); \
379 #endif /* __BNAD_H__ */