[CIFS] Fix memory overwrite when saving nativeFileSystem field during mount
[sfrench/cifs-2.6.git] / drivers / staging / benet / benet.h
1 /*
2  * Copyright (C) 2005 - 2008 ServerEngines
3  * All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License version 2
7  * as published by the Free Software Foundation.  The full GNU General
8  * Public License is included in this distribution in the file called COPYING.
9  *
10  * Contact Information:
11  * linux-drivers@serverengines.com
12  *
13  * ServerEngines
14  * 209 N. Fair Oaks Ave
15  * Sunnyvale, CA 94085
16  */
17 #ifndef _BENET_H_
18 #define _BENET_H_
19
20 #include <linux/pci.h>
21 #include <linux/netdevice.h>
22 #include <linux/inet_lro.h>
23 #include "hwlib.h"
24
25 #define _SA_MODULE_NAME "net-driver"
26
27 #define VLAN_VALID_BIT          0x8000
28 #define BE_NUM_VLAN_SUPPORTED   32
29 #define BE_PORT_LINK_DOWN       0000
30 #define BE_PORT_LINK_UP         0001
31 #define BE_MAX_TX_FRAG_COUNT            (30)
32
33 /* Flag bits for send operation */
34 #define IPCS            (1 << 0)        /* Enable IP checksum offload */
35 #define UDPCS           (1 << 1)        /* Enable UDP checksum offload */
36 #define TCPCS           (1 << 2)        /* Enable TCP checksum offload */
37 #define LSO             (1 << 3)        /* Enable Large Segment  offload */
38 #define ETHVLAN         (1 << 4)        /* Enable VLAN insert */
39 #define ETHEVENT        (1 << 5)        /* Generate  event on completion */
40 #define ETHCOMPLETE     (1 << 6)        /* Generate completion when done */
41 #define IPSEC           (1 << 7)        /* Enable IPSEC */
42 #define FORWARD         (1 << 8)        /* Send the packet in forwarding path */
43 #define FIN             (1 << 9)        /* Issue FIN segment */
44
45 #define BE_MAX_MTU      8974
46
47 #define BE_MAX_LRO_DESCRIPTORS                  8
48 #define BE_LRO_MAX_PKTS                         64
49 #define BE_MAX_FRAGS_PER_FRAME                  6
50
51 extern const char be_drvr_ver[];
52 extern char be_fw_ver[];
53 extern char be_driver_name[];
54
55 extern struct ethtool_ops be_ethtool_ops;
56
57 #define BE_DEV_STATE_NONE 0
58 #define BE_DEV_STATE_INIT 1
59 #define BE_DEV_STATE_OPEN 2
60 #define BE_DEV_STATE_SUSPEND 3
61
62 /* This structure is used to describe physical fragments to use
63  * for DMAing data from NIC.
64  */
65 struct be_recv_buffer {
66         struct list_head rxb_list;      /* for maintaining a linked list */
67         void *rxb_va;           /* buffer virtual address */
68         u32 rxb_pa_lo;          /* low part of physical address */
69         u32 rxb_pa_hi;          /* high part of physical address */
70         u32 rxb_len;            /* length of recv buffer */
71         void *rxb_ctxt;         /* context for OSM driver to use */
72 };
73
74 /*
75  * fragment list to describe scattered data.
76  */
77 struct be_tx_frag_list {
78         u32 txb_len;            /* Size of this fragment */
79         u32 txb_pa_lo;          /* Lower 32 bits of 64 bit physical addr */
80         u32 txb_pa_hi;          /* Higher 32 bits of 64 bit physical addr */
81 };
82
83 struct be_rx_page_info {
84         struct page *page;
85         dma_addr_t bus;
86         u16 page_offset;
87 };
88
89 /*
90  *  This structure is the main tracking structure for a NIC interface.
91  */
92 struct be_net_object {
93         /* MCC Ring - used to send fwcmds to embedded ARM processor */
94         struct MCC_WRB_AMAP *mcc_q;     /* VA of the start of the ring */
95         u32 mcc_q_len;                  /* # of WRB entries in this ring */
96         u32 mcc_q_size;
97         u32 mcc_q_hd;                   /* MCC ring head */
98         u8 mcc_q_created;               /* flag to help cleanup */
99         struct be_mcc_object mcc_q_obj; /* BECLIB's MCC ring Object */
100         dma_addr_t mcc_q_bus;           /* DMA'ble bus address */
101
102         /* MCC Completion Ring - FW responses to fwcmds sent from MCC ring */
103         struct MCC_CQ_ENTRY_AMAP *mcc_cq; /* VA of the start of the ring */
104         u32 mcc_cq_len;                 /* # of compl. entries in this ring */
105         u32 mcc_cq_size;
106         u32 mcc_cq_tl;                  /* compl. ring tail */
107         u8 mcc_cq_created;              /* flag to help cleanup */
108         struct be_cq_object mcc_cq_obj; /* BECLIB's MCC compl. ring object */
109         u32 mcc_cq_id;                  /* MCC ring ID */
110         dma_addr_t mcc_cq_bus;          /* DMA'ble bus address */
111
112         struct ring_desc mb_rd;         /* RD for MCC_MAIL_BOX */
113         void *mb_ptr;                   /* mailbox ptr to be freed  */
114         dma_addr_t mb_bus;              /* DMA'ble bus address */
115         u32 mb_size;
116
117         /* BEClib uses an array of context objects to track outstanding
118          * requests to the MCC.  We need allocate the same number of
119          * conext entries as the number of entries in the MCC WRB ring
120          */
121         u32 mcc_wrb_ctxt_size;
122         void *mcc_wrb_ctxt;             /* pointer to the context area */
123         u32 mcc_wrb_ctxtLen;            /* Number of entries in the context */
124         /*
125          * NIC send request ring - used for xmitting raw ether frames.
126          */
127         struct ETH_WRB_AMAP *tx_q;      /* VA of the start of the ring */
128         u32 tx_q_len;                   /* # if entries in the send ring */
129         u32 tx_q_size;
130         u32 tx_q_hd;                    /* Head index. Next req. goes here */
131         u32 tx_q_tl;                    /* Tail indx. oldest outstanding req. */
132         u8 tx_q_created;                /* flag to help cleanup */
133         struct be_ethsq_object tx_q_obj;/* BECLIB's send Q handle */
134         dma_addr_t tx_q_bus;            /* DMA'ble bus address */
135         u32 tx_q_id;                    /* send queue ring ID */
136         u32 tx_q_port;                  /* 0 no binding, 1 port A,  2 port B */
137         atomic_t tx_q_used;             /* # of WRBs used */
138         /* ptr to an array in which we store context info for each send req. */
139         void **tx_ctxt;
140         /*
141          * NIC Send compl. ring - completion status for all NIC frames xmitted.
142          */
143         struct ETH_TX_COMPL_AMAP *tx_cq;/* VA of start of the ring */
144         u32 txcq_len;                   /* # of entries in the ring */
145         u32 tx_cq_size;
146         /*
147          * index into compl ring where the host expects next completion entry
148          */
149         u32 tx_cq_tl;
150         u32 tx_cq_id;                   /* completion queue id */
151         u8 tx_cq_created;               /* flag to help cleanup */
152         struct be_cq_object tx_cq_obj;
153         dma_addr_t tx_cq_bus;           /* DMA'ble bus address */
154         /*
155          * Event Queue - all completion entries post events here.
156          */
157         struct EQ_ENTRY_AMAP *event_q;  /* VA of start of event queue */
158         u32 event_q_len;                /* # of entries */
159         u32 event_q_size;
160         u32 event_q_tl;                 /* Tail of the event queue */
161         u32 event_q_id;                 /* Event queue ID */
162         u8 event_q_created;             /* flag to help cleanup */
163         struct be_eq_object event_q_obj; /* Queue handle */
164         dma_addr_t event_q_bus;         /* DMA'ble bus address */
165         /*
166          * NIC receive queue - Data buffers to be used for receiving unicast,
167          * broadcast and multi-cast frames  are posted here.
168          */
169         struct ETH_RX_D_AMAP *rx_q;     /* VA of start of the queue */
170         u32 rx_q_len;                   /* # of entries */
171         u32 rx_q_size;
172         u32 rx_q_hd;                    /* Head of the queue */
173         atomic_t rx_q_posted;           /* number of posted buffers */
174         u32 rx_q_id;                    /* queue ID */
175         u8 rx_q_created;                /* flag to help cleanup */
176         struct be_ethrq_object rx_q_obj;        /* NIC RX queue handle */
177         dma_addr_t rx_q_bus;            /* DMA'ble bus address */
178         /*
179          * Pointer to an array of opaque context object for use by OSM driver
180          */
181         void **rx_ctxt;
182         /*
183          * NIC unicast RX completion queue - all unicast ether frame completion
184          * statuses from BE come here.
185          */
186         struct ETH_RX_COMPL_AMAP *rx_cq;        /* VA of start of the queue */
187         u32 rx_cq_len;          /* # of entries */
188         u32 rx_cq_size;
189         u32 rx_cq_tl;                   /* Tail of the queue */
190         u32 rx_cq_id;                   /* queue ID */
191         u8 rx_cq_created;               /* flag to help cleanup */
192         struct be_cq_object rx_cq_obj;  /* queue handle */
193         dma_addr_t rx_cq_bus;           /* DMA'ble bus address */
194         struct be_function_object fn_obj;       /* function object   */
195         bool    fn_obj_created;
196         u32 rx_buf_size;                /* Size of the RX buffers */
197
198         struct net_device *netdev;
199         struct be_recv_buffer eth_rx_bufs[256]; /* to pass Rx buffer
200                                                            addresses */
201         struct be_adapter *adapter;     /* Pointer to OSM adapter */
202         u32 devno;              /* OSM, network dev no. */
203         u32 use_port;           /* Current active port */
204         struct be_rx_page_info *rx_page_info;   /* Array of Rx buf pages */
205         u32 rx_pg_info_hd;      /* Head of queue */
206         int rxbuf_post_fail;    /* RxBuff posting fail count */
207         bool rx_pg_shared;      /* Is an allocsted page shared as two frags ? */
208         struct vlan_group *vlan_grp;
209         u32 num_vlans;          /* Number of vlans in BE's filter */
210         u16 vlan_tag[BE_NUM_VLAN_SUPPORTED]; /* vlans currently configured */
211         struct napi_struct napi;
212         struct net_lro_mgr lro_mgr;
213         struct net_lro_desc lro_desc[BE_MAX_LRO_DESCRIPTORS];
214 };
215
216 #define NET_FH(np)       (&(np)->fn_obj)
217
218 /*
219  * BE driver statistics.
220  */
221 struct be_drvr_stat {
222         u32 bes_tx_reqs;        /* number of TX requests initiated */
223         u32 bes_tx_fails;       /* number of TX requests that failed */
224         u32 bes_fwd_reqs;       /* number of send reqs through forwarding i/f */
225         u32 bes_tx_wrbs;        /* number of tx WRBs used */
226
227         u32 bes_ints;           /* number of interrupts */
228         u32 bes_polls;          /* number of times NAPI called poll function */
229         u32 bes_events;         /* total evet entries processed */
230         u32 bes_tx_events;      /* number of tx completion events  */
231         u32 bes_rx_events;      /* number of ucast rx completion events  */
232         u32 bes_tx_compl;       /* number of tx completion entries processed */
233         u32 bes_rx_compl;       /* number of rx completion entries
234                                    processed */
235         u32 bes_ethrx_post_fail;        /* number of ethrx buffer alloc
236                                            failures */
237         /*
238          * number of non ether type II frames dropped where
239          * frame len > length field of Mac Hdr
240          */
241         u32 bes_802_3_dropped_frames;
242         /*
243          * number of non ether type II frames malformed where
244          * in frame len < length field of Mac Hdr
245          */
246         u32 bes_802_3_malformed_frames;
247         u32 bes_ips;            /*  interrupts / sec */
248         u32 bes_prev_ints;      /* bes_ints at last IPS calculation  */
249         u16 bes_eth_tx_rate;    /*  ETH TX rate - Mb/sec */
250         u16 bes_eth_rx_rate;    /*  ETH RX rate - Mb/sec */
251         u32 bes_rx_coal;        /* Num pkts coalasced */
252         u32 bes_rx_flush;       /* Num times coalasced */
253         u32 bes_link_change_physical;   /*Num of times physical link changed */
254         u32 bes_link_change_virtual;    /*Num of times virtual link changed */
255         u32 bes_rx_misc_pkts;   /* Misc pkts received */
256 };
257
258 /* Maximum interrupt delay (in microseconds) allowed */
259 #define MAX_EQD                         120
260
261 /*
262  * timer to prevent system shutdown hang for ever if h/w stops responding
263  */
264 struct be_timer_ctxt {
265         atomic_t get_stat_flag;
266         struct timer_list get_stats_timer;
267         unsigned long get_stat_sem_addr;
268 } ;
269
270 /* This structure is the main BladeEngine driver context.  */
271 struct be_adapter {
272         struct net_device *netdevp;
273         struct be_drvr_stat be_stat;
274         struct net_device_stats benet_stats;
275
276         /* PCI BAR mapped addresses */
277         u8 __iomem *csr_va;     /* CSR */
278         u8 __iomem *db_va;      /* Door  Bell  */
279         u8 __iomem *pci_va;     /* PCI Config */
280
281         struct tasklet_struct sts_handler;
282         struct timer_list cq_timer;
283         spinlock_t int_lock;    /* to protect the isr field in adapter */
284
285         struct FWCMD_ETH_GET_STATISTICS *eth_statsp;
286         /*
287          * This will enable the use of ethtool to enable or disable
288          * Checksum on Rx pkts to be obeyed or disobeyed.
289          * If this is true = 1, then whatever is the checksum on the
290          * Received pkt as per BE, it will be given to the stack.
291          * Else the stack will re calculate it.
292          */
293         bool rx_csum;
294         /*
295          * This will enable the use of ethtool to enable or disable
296          * Coalese on Rx pkts to be obeyed or disobeyed.
297          * If this is grater than 0 and less than 16 then coalascing
298          * is enabled else it is disabled
299          */
300         u32 max_rx_coal;
301         struct pci_dev *pdev;   /* Pointer to OS's PCI dvice */
302
303         spinlock_t txq_lock;    /* to stop/wake queue based on tx_q_used */
304
305         u32 isr;                /* copy of Intr status reg. */
306
307         u32 port0_link_sts;     /* Port 0 link status */
308         u32 port1_link_sts;     /* port 1 list status */
309         struct BE_LINK_STATUS *be_link_sts;
310
311         /* pointer to the first netobject of this adapter */
312         struct be_net_object *net_obj;
313
314         /*  Flags to indicate what to clean up */
315         bool tasklet_started;
316         bool isr_registered;
317         /*
318          * adaptive interrupt coalescing (AIC) related
319          */
320         bool enable_aic;        /* 1 if AIC is enabled */
321         u16 min_eqd;            /* minimum EQ delay in usec */
322         u16 max_eqd;            /* minimum EQ delay in usec */
323         u16 cur_eqd;            /* current EQ delay in usec */
324         /*
325          * book keeping for interrupt / sec and TX/RX rate calculation
326          */
327         ulong ips_jiffies;      /* jiffies at last IPS calc */
328         u32 eth_tx_bytes;
329         ulong eth_tx_jiffies;
330         u32 eth_rx_bytes;
331         ulong eth_rx_jiffies;
332
333         struct semaphore get_eth_stat_sem;
334
335         /* timer ctxt to prevent shutdown hanging due to un-responsive BE */
336         struct be_timer_ctxt timer_ctxt;
337
338 #define BE_MAX_MSIX_VECTORS             32
339 #define BE_MAX_REQ_MSIX_VECTORS         1 /* only one EQ in Linux driver */
340         struct msix_entry msix_entries[BE_MAX_MSIX_VECTORS];
341         bool msix_enabled;
342         bool dma_64bit_cap;     /* the Device DAC capable  or not */
343         u8 dev_state;   /* The current state of the device */
344         u8 dev_pm_state; /* The State of device before going to suspend */
345 };
346
347 /*
348  * Every second we look at the ints/sec and adjust eq_delay
349  * between adapter->min_eqd and adapter->max_eqd to keep the ints/sec between
350  * IPS_HI_WM and IPS_LO_WM.
351  */
352 #define IPS_HI_WM       18000
353 #define IPS_LO_WM       8000
354
355
356 static inline void index_adv(u32 *index, u32 val,  u32 limit)
357 {
358         BUG_ON(limit & (limit-1));
359         *index = (*index + val) & (limit - 1);
360 }
361
362 static inline void index_inc(u32 *index, u32 limit)
363 {
364         BUG_ON(limit & (limit-1));
365         *index = (*index + 1) & (limit - 1);
366 }
367
368 static inline void be_adv_eq_tl(struct be_net_object *pnob)
369 {
370         index_inc(&pnob->event_q_tl, pnob->event_q_len);
371 }
372
373 static inline void be_adv_txq_hd(struct be_net_object *pnob)
374 {
375         index_inc(&pnob->tx_q_hd, pnob->tx_q_len);
376 }
377
378 static inline void be_adv_txq_tl(struct be_net_object *pnob)
379 {
380         index_inc(&pnob->tx_q_tl, pnob->tx_q_len);
381 }
382
383 static inline void be_adv_txcq_tl(struct be_net_object *pnob)
384 {
385         index_inc(&pnob->tx_cq_tl, pnob->txcq_len);
386 }
387
388 static inline void be_adv_rxq_hd(struct be_net_object *pnob)
389 {
390         index_inc(&pnob->rx_q_hd, pnob->rx_q_len);
391 }
392
393 static inline void be_adv_rxcq_tl(struct be_net_object *pnob)
394 {
395         index_inc(&pnob->rx_cq_tl, pnob->rx_cq_len);
396 }
397
398 static inline u32 tx_compl_lastwrb_idx_get(struct be_net_object *pnob)
399 {
400         return (pnob->tx_q_tl + *(u32 *)&pnob->tx_ctxt[pnob->tx_q_tl] - 1)
401                     & (pnob->tx_q_len - 1);
402 }
403
404 int benet_init(struct net_device *);
405 int be_ethtool_ioctl(struct net_device *, struct ifreq *);
406 struct net_device_stats *benet_get_stats(struct net_device *);
407 void be_process_intr(unsigned long context);
408 irqreturn_t be_int(int irq, void *dev);
409 void be_post_eth_rx_buffs(struct be_net_object *);
410 void be_get_stat_cb(void *, int, struct MCC_WRB_AMAP *);
411 void be_get_stats_timer_handler(unsigned long);
412 void be_wait_nic_tx_cmplx_cmpl(struct be_net_object *);
413 void be_print_link_info(struct BE_LINK_STATUS *);
414 void be_update_link_status(struct be_adapter *);
415 void be_init_procfs(struct be_adapter *);
416 void be_cleanup_procfs(struct be_adapter *);
417 int be_poll(struct napi_struct *, int);
418 struct ETH_RX_COMPL_AMAP *be_get_rx_cmpl(struct be_net_object *);
419 void be_notify_cmpl(struct be_net_object *, int, int, int);
420 void be_enable_intr(struct be_net_object *);
421 void be_enable_eq_intr(struct be_net_object *);
422 void be_disable_intr(struct be_net_object *);
423 void be_disable_eq_intr(struct be_net_object *);
424 int be_set_uc_mac_adr(struct be_net_object *, u8, u8, u8,
425                     u8 *, mcc_wrb_cqe_callback, void *);
426 int be_get_flow_ctl(struct be_function_object *pFnObj, bool *, bool *);
427 void process_one_tx_compl(struct be_net_object *pnob, u32 end_idx);
428
429 #endif /* _BENET_H_ */