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