blob: f59685a5543d4112c5bee978de94624bd1b58b4e [file] [log] [blame]
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001/*
2 * Linux network driver for Brocade Converged Network Adapter.
3 *
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
7 *
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.
12 */
13/*
14 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
15 * All rights reserved
16 * www.brocade.com
17 */
18#ifndef __BNAD_H__
19#define __BNAD_H__
20
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
28/* Fix for IA64 */
29#include <asm/checksum.h>
30#include <net/ip6_checksum.h>
31
32#include <net/ip.h>
33#include <net/tcp.h>
34
35#include "bna.h"
36
37#define BNAD_TXQ_DEPTH 2048
38#define BNAD_RXQ_DEPTH 2048
39
40#define BNAD_MAX_TXS 1
41#define BNAD_MAX_TXQ_PER_TX 8 /* 8 priority queues */
42#define BNAD_TXQ_NUM 1
43
44#define BNAD_MAX_RXS 1
45#define BNAD_MAX_RXPS_PER_RX 16
46
47/*
48 * Control structure pointed to ccb->ctrl, which
49 * determines the NAPI / LRO behavior CCB
50 * There is 1:1 corres. between ccb & ctrl
51 */
52struct bnad_rx_ctrl {
53 struct bna_ccb *ccb;
Rasesh Modybe7fa322010-12-23 21:45:01 +000054 unsigned long flags;
Rasesh Mody8b230ed2010-08-23 20:24:12 -070055 struct napi_struct napi;
56};
57
58#define BNAD_RXMODE_PROMISC_DEFAULT BNA_RXMODE_PROMISC
59
60#define BNAD_GET_TX_ID(_skb) (0)
61
62/*
63 * GLOBAL #defines (CONSTANTS)
64 */
65#define BNAD_NAME "bna"
66#define BNAD_NAME_LEN 64
67
68#define BNAD_VERSION "2.3.2.0"
69
70#define BNAD_MAILBOX_MSIX_VECTORS 1
71
72#define BNAD_STATS_TIMER_FREQ 1000 /* in msecs */
73#define BNAD_DIM_TIMER_FREQ 1000 /* in msecs */
74
75#define BNAD_MAX_Q_DEPTH 0x10000
76#define BNAD_MIN_Q_DEPTH 0x200
77
78#define BNAD_JUMBO_MTU 9000
79
80#define BNAD_NETIF_WAKE_THRESHOLD 8
81
82#define BNAD_RXQ_REFILL_THRESHOLD_SHIFT 3
83
84/* Bit positions for tcb->flags */
85#define BNAD_TXQ_FREE_SENT 0
Rasesh Modybe7fa322010-12-23 21:45:01 +000086#define BNAD_TXQ_TX_STARTED 1
Rasesh Mody8b230ed2010-08-23 20:24:12 -070087
88/* Bit positions for rcb->flags */
89#define BNAD_RXQ_REFILL 0
90#define BNAD_RXQ_STARTED 1
91
92/*
93 * DATA STRUCTURES
94 */
95
96/* enums */
97enum bnad_intr_source {
98 BNAD_INTR_TX = 1,
99 BNAD_INTR_RX = 2
100};
101
102enum bnad_link_state {
103 BNAD_LS_DOWN = 0,
104 BNAD_LS_UP = 1
105};
106
107struct bnad_completion {
108 struct completion ioc_comp;
109 struct completion ucast_comp;
110 struct completion mcast_comp;
111 struct completion tx_comp;
112 struct completion rx_comp;
113 struct completion stats_comp;
114 struct completion port_comp;
115
116 u8 ioc_comp_status;
117 u8 ucast_comp_status;
118 u8 mcast_comp_status;
119 u8 tx_comp_status;
120 u8 rx_comp_status;
121 u8 stats_comp_status;
122 u8 port_comp_status;
123};
124
125/* Tx Rx Control Stats */
126struct bnad_drv_stats {
127 u64 netif_queue_stop;
128 u64 netif_queue_wakeup;
129 u64 tso4;
130 u64 tso6;
131 u64 tso_err;
132 u64 tcpcsum_offload;
133 u64 udpcsum_offload;
134 u64 csum_help;
135 u64 csum_help_err;
136
137 u64 hw_stats_updates;
138 u64 netif_rx_schedule;
139 u64 netif_rx_complete;
140 u64 netif_rx_dropped;
141
142 u64 link_toggle;
143 u64 cee_up;
144
145 u64 rxp_info_alloc_failed;
146 u64 mbox_intr_disabled;
147 u64 mbox_intr_enabled;
148 u64 tx_unmap_q_alloc_failed;
149 u64 rx_unmap_q_alloc_failed;
150
151 u64 rxbuf_alloc_failed;
152};
153
154/* Complete driver stats */
155struct bnad_stats {
156 struct bnad_drv_stats drv_stats;
157 struct bna_stats *bna_stats;
158};
159
160/* Tx / Rx Resources */
161struct bnad_tx_res_info {
162 struct bna_res_info res_info[BNA_TX_RES_T_MAX];
163};
164
165struct bnad_rx_res_info {
166 struct bna_res_info res_info[BNA_RX_RES_T_MAX];
167};
168
169struct bnad_tx_info {
170 struct bna_tx *tx; /* 1:1 between tx_info & tx */
171 struct bna_tcb *tcb[BNAD_MAX_TXQ_PER_TX];
172} ____cacheline_aligned;
173
174struct bnad_rx_info {
175 struct bna_rx *rx; /* 1:1 between rx_info & rx */
176
177 struct bnad_rx_ctrl rx_ctrl[BNAD_MAX_RXPS_PER_RX];
178} ____cacheline_aligned;
179
180/* Unmap queues for Tx / Rx cleanup */
181struct bnad_skb_unmap {
182 struct sk_buff *skb;
183 DECLARE_PCI_UNMAP_ADDR(dma_addr)
184};
185
186struct bnad_unmap_q {
187 u32 producer_index;
188 u32 consumer_index;
189 u32 q_depth;
190 /* This should be the last one */
191 struct bnad_skb_unmap unmap_array[1];
192};
193
194/* Bit mask values for bnad->cfg_flags */
195#define BNAD_CF_DIM_ENABLED 0x01 /* DIM */
196#define BNAD_CF_PROMISC 0x02
197#define BNAD_CF_ALLMULTI 0x04
198#define BNAD_CF_MSIX 0x08 /* If in MSIx mode */
199
200/* Defines for run_flags bit-mask */
201/* Set, tested & cleared using xxx_bit() functions */
202/* Values indicated bit positions */
203#define BNAD_RF_CEE_RUNNING 1
Rasesh Modybe7fa322010-12-23 21:45:01 +0000204#define BNAD_RF_MBOX_IRQ_DISABLED 2
205#define BNAD_RF_RX_STARTED 3
206#define BNAD_RF_DIM_TIMER_RUNNING 4
207#define BNAD_RF_STATS_TIMER_RUNNING 5
208#define BNAD_RF_TX_SHUTDOWN_DELAYED 6
209#define BNAD_RF_RX_SHUTDOWN_DELAYED 7
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700210
211struct bnad {
212 struct net_device *netdev;
213
214 /* Data path */
215 struct bnad_tx_info tx_info[BNAD_MAX_TXS];
216 struct bnad_rx_info rx_info[BNAD_MAX_RXS];
217
218 struct vlan_group *vlan_grp;
219 /*
220 * These q numbers are global only because
221 * they are used to calculate MSIx vectors.
222 * Actually the exact # of queues are per Tx/Rx
223 * object.
224 */
225 u32 num_tx;
226 u32 num_rx;
227 u32 num_txq_per_tx;
228 u32 num_rxp_per_rx;
229
230 u32 txq_depth;
231 u32 rxq_depth;
232
233 u8 tx_coalescing_timeo;
234 u8 rx_coalescing_timeo;
235
236 struct bna_rx_config rx_config[BNAD_MAX_RXS];
237 struct bna_tx_config tx_config[BNAD_MAX_TXS];
238
239 u32 rx_csum;
240
241 void __iomem *bar0; /* BAR0 address */
242
243 struct bna bna;
244
245 u32 cfg_flags;
246 unsigned long run_flags;
247
248 struct pci_dev *pcidev;
249 u64 mmio_start;
250 u64 mmio_len;
251
252 u32 msix_num;
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700253 struct msix_entry *msix_table;
254
255 struct mutex conf_mutex;
256 spinlock_t bna_lock ____cacheline_aligned;
257
258 /* Timers */
259 struct timer_list ioc_timer;
260 struct timer_list dim_timer;
261 struct timer_list stats_timer;
262
263 /* Control path resources, memory & irq */
264 struct bna_res_info res_info[BNA_RES_T_MAX];
265 struct bnad_tx_res_info tx_res_info[BNAD_MAX_TXS];
266 struct bnad_rx_res_info rx_res_info[BNAD_MAX_RXS];
267
268 struct bnad_completion bnad_completions;
269
270 /* Burnt in MAC address */
271 mac_t perm_addr;
272
273 struct tasklet_struct tx_free_tasklet;
274
275 /* Statistics */
276 struct bnad_stats stats;
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700277
278 struct bnad_diag *diag;
279
280 char adapter_name[BNAD_NAME_LEN];
281 char port_name[BNAD_NAME_LEN];
282 char mbox_irq_name[BNAD_NAME_LEN];
283};
284
285/*
286 * EXTERN VARIABLES
287 */
288extern struct firmware *bfi_fw;
289extern u32 bnad_rxqs_per_cq;
290
291/*
292 * EXTERN PROTOTYPES
293 */
294extern u32 *cna_get_firmware_buf(struct pci_dev *pdev);
295/* Netdev entry point prototypes */
296extern void bnad_set_ethtool_ops(struct net_device *netdev);
297
298/* Configuration & setup */
299extern void bnad_tx_coalescing_timeo_set(struct bnad *bnad);
300extern void bnad_rx_coalescing_timeo_set(struct bnad *bnad);
301
302extern int bnad_setup_rx(struct bnad *bnad, uint rx_id);
303extern int bnad_setup_tx(struct bnad *bnad, uint tx_id);
304extern void bnad_cleanup_tx(struct bnad *bnad, uint tx_id);
305extern void bnad_cleanup_rx(struct bnad *bnad, uint rx_id);
306
307/* Timer start/stop protos */
308extern void bnad_dim_timer_start(struct bnad *bnad);
309
310/* Statistics */
Eric Dumazet250e0612010-09-02 12:45:02 -0700311extern void bnad_netdev_qstats_fill(struct bnad *bnad, struct rtnl_link_stats64 *stats);
312extern void bnad_netdev_hwstats_fill(struct bnad *bnad, struct rtnl_link_stats64 *stats);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700313
314/**
315 * MACROS
316 */
317/* To set & get the stats counters */
318#define BNAD_UPDATE_CTR(_bnad, _ctr) \
319 (((_bnad)->stats.drv_stats._ctr)++)
320
321#define BNAD_GET_CTR(_bnad, _ctr) ((_bnad)->stats.drv_stats._ctr)
322
323#define bnad_enable_rx_irq_unsafe(_ccb) \
324{ \
Rasesh Modybe7fa322010-12-23 21:45:01 +0000325 if (likely(test_bit(BNAD_RXQ_STARTED, &ccb->rcb[0]->flags))) {\
326 bna_ib_coalescing_timer_set((_ccb)->i_dbell, \
327 (_ccb)->rx_coalescing_timeo); \
328 bna_ib_ack((_ccb)->i_dbell, 0); \
329 } \
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700330}
331
332#define bnad_dim_timer_running(_bnad) \
333 (((_bnad)->cfg_flags & BNAD_CF_DIM_ENABLED) && \
334 (test_bit(BNAD_RF_DIM_TIMER_RUNNING, &((_bnad)->run_flags))))
335
336#endif /* __BNAD_H__ */