Merge branch 'x86-platform-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[pandora-kernel.git] / drivers / staging / brcm80211 / brcmfmac / dhd.h
1 /*
2  * Copyright (c) 2010 Broadcom Corporation
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 /****************
18  * Common types *
19  */
20
21 #ifndef _dhd_h_
22 #define _dhd_h_
23
24 #include <linux/sched.h>
25 #include <linux/init.h>
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
28 #include <linux/skbuff.h>
29 #include <linux/netdevice.h>
30 #include <linux/etherdevice.h>
31 #include <linux/random.h>
32 #include <linux/spinlock.h>
33 #include <linux/ethtool.h>
34 #include <asm/uaccess.h>
35 #include <asm/unaligned.h>
36 #if defined(CONFIG_HAS_WAKELOCK)
37 #include <linux/wakelock.h>
38 #endif                  /* defined (CONFIG_HAS_WAKELOCK) */
39 /* The kernel threading is sdio-specific */
40
41 #include <wlioctl.h>
42
43 /* Forward decls */
44 struct dhd_bus;
45 struct dhd_prot;
46 struct dhd_info;
47
48 /* The level of bus communication with the dongle */
49 enum dhd_bus_state {
50         DHD_BUS_DOWN,           /* Not ready for frame transfers */
51         DHD_BUS_LOAD,           /* Download access only (CPU reset) */
52         DHD_BUS_DATA            /* Ready for frame transfers */
53 };
54
55 enum dhd_bus_wake_state {
56         WAKE_LOCK_OFF,
57         WAKE_LOCK_PRIV,
58         WAKE_LOCK_DPC,
59         WAKE_LOCK_IOCTL,
60         WAKE_LOCK_DOWNLOAD,
61         WAKE_LOCK_TMOUT,
62         WAKE_LOCK_WATCHDOG,
63         WAKE_LOCK_LINK_DOWN_TMOUT,
64         WAKE_LOCK_PNO_FIND_TMOUT,
65         WAKE_LOCK_SOFTAP_SET,
66         WAKE_LOCK_SOFTAP_STOP,
67         WAKE_LOCK_SOFTAP_START,
68         WAKE_LOCK_MAX
69 };
70 enum dhd_prealloc_index {
71         DHD_PREALLOC_PROT = 0,
72         DHD_PREALLOC_RXBUF,
73         DHD_PREALLOC_DATABUF,
74         DHD_PREALLOC_OSL_BUF
75 };
76
77 /* Common structure for module and instance linkage */
78 typedef struct dhd_pub {
79         /* Linkage ponters */
80         osl_t *osh;             /* OSL handle */
81         struct dhd_bus *bus;    /* Bus module handle */
82         struct dhd_prot *prot;  /* Protocol module handle */
83         struct dhd_info *info;  /* Info module handle */
84
85         /* Internal dhd items */
86         bool up;                /* Driver up/down (to OS) */
87         bool txoff;             /* Transmit flow-controlled */
88         bool dongle_reset;      /* true = DEVRESET put dongle into reset */
89         enum dhd_bus_state busstate;
90         uint hdrlen;            /* Total DHD header length (proto + bus) */
91         uint maxctl;            /* Max size rxctl request from proto to bus */
92         uint rxsz;              /* Rx buffer size bus module should use */
93         u8 wme_dp;              /* wme discard priority */
94
95         /* Dongle media info */
96         bool iswl;              /* Dongle-resident driver is wl */
97         unsigned long drv_version;      /* Version of dongle-resident driver */
98         struct ether_addr mac;  /* MAC address obtained from dongle */
99         dngl_stats_t dstats;    /* Stats for dongle-based data */
100
101         /* Additional stats for the bus level */
102         unsigned long tx_packets;       /* Data packets sent to dongle */
103         unsigned long tx_multicast;     /* Multicast data packets sent to dongle */
104         unsigned long tx_errors;        /* Errors in sending data to dongle */
105         unsigned long tx_ctlpkts;       /* Control packets sent to dongle */
106         unsigned long tx_ctlerrs;       /* Errors sending control frames to dongle */
107         unsigned long rx_packets;       /* Packets sent up the network interface */
108         unsigned long rx_multicast;     /* Multicast packets sent up the network
109                                          interface */
110         unsigned long rx_errors;        /* Errors processing rx data packets */
111         unsigned long rx_ctlpkts;       /* Control frames processed from dongle */
112         unsigned long rx_ctlerrs;       /* Errors in processing rx control frames */
113         unsigned long rx_dropped;       /* Packets dropped locally (no memory) */
114         unsigned long rx_flushed;       /* Packets flushed due to
115                                 unscheduled sendup thread */
116         unsigned long wd_dpc_sched;     /* Number of times dhd dpc scheduled by
117                                          watchdog timer */
118
119         unsigned long rx_readahead_cnt; /* Number of packets where header read-ahead
120                                          was used. */
121         unsigned long tx_realloc;       /* Number of tx packets we had to realloc for
122                                          headroom */
123         unsigned long fc_packets;       /* Number of flow control pkts recvd */
124
125         /* Last error return */
126         int bcmerror;
127         uint tickcnt;
128
129         /* Last error from dongle */
130         int dongle_error;
131
132         /* Suspend disable flag  flag */
133         int suspend_disable_flag;       /* "1" to disable all extra powersaving
134                                          during suspend */
135         int in_suspend;         /* flag set to 1 when early suspend called */
136 #ifdef PNO_SUPPORT
137         int pno_enable;         /* pno status : "1" is pno enable */
138 #endif                          /* PNO_SUPPORT */
139         int dtim_skip;          /* dtim skip , default 0 means wake each dtim */
140
141         /* Pkt filter defination */
142         char *pktfilter[100];
143         int pktfilter_count;
144
145         u8 country_code[WLC_CNTRY_BUF_SZ];
146         char eventmask[WL_EVENTING_MASK_LEN];
147
148 #if defined(CONFIG_HAS_WAKELOCK)
149         struct wake_lock wakelock[WAKE_LOCK_MAX];
150 #endif          /*  defined (CONFIG_HAS_WAKELOCK) */
151 } dhd_pub_t;
152
153 #if defined(CONFIG_PM_SLEEP)
154
155 #define DHD_PM_RESUME_WAIT_INIT(a) DECLARE_WAIT_QUEUE_HEAD(a);
156 #define _DHD_PM_RESUME_WAIT(a, b) do {\
157                         int retry = 0; \
158                         while (dhd_mmc_suspend && retry++ != b) { \
159                                 wait_event_timeout(a, false, HZ/100); \
160                         } \
161                 }       while (0)
162 #define DHD_PM_RESUME_WAIT(a)   _DHD_PM_RESUME_WAIT(a, 30)
163 #define DHD_PM_RESUME_WAIT_FOREVER(a)   _DHD_PM_RESUME_WAIT(a, ~0)
164 #define DHD_PM_RESUME_RETURN_ERROR(a)   \
165         do { if (dhd_mmc_suspend) return a; } while (0)
166 #define DHD_PM_RESUME_RETURN    do { if (dhd_mmc_suspend) return; } while (0)
167
168 #define DHD_SPINWAIT_SLEEP_INIT(a) DECLARE_WAIT_QUEUE_HEAD(a);
169 #define SPINWAIT_SLEEP(a, exp, us) do { \
170                 uint countdown = (us) + 9999; \
171                 while ((exp) && (countdown >= 10000)) { \
172                         wait_event_timeout(a, false, HZ/100); \
173                         countdown -= 10000; \
174                 } \
175         } while (0)
176
177 #else
178
179 #define DHD_PM_RESUME_WAIT_INIT(a)
180 #define DHD_PM_RESUME_WAIT(a)
181 #define DHD_PM_RESUME_WAIT_FOREVER(a)
182 #define DHD_PM_RESUME_RETURN_ERROR(a)
183 #define DHD_PM_RESUME_RETURN
184
185 #define DHD_SPINWAIT_SLEEP_INIT(a)
186 #define SPINWAIT_SLEEP(a, exp, us)  do { \
187                 uint countdown = (us) + 9; \
188                 while ((exp) && (countdown >= 10)) { \
189                         udelay(10);  \
190                         countdown -= 10;  \
191                 } \
192         } while (0)
193
194 #endif  /* defined(CONFIG_PM_SLEEP) */
195 #define DHD_IF_VIF      0x01    /* Virtual IF (Hidden from user) */
196
197 static inline void MUTEX_LOCK_INIT(dhd_pub_t *dhdp)
198 {
199 }
200
201 static inline void MUTEX_LOCK(dhd_pub_t *dhdp)
202 {
203 }
204
205 static inline void MUTEX_UNLOCK(dhd_pub_t *dhdp)
206 {
207 }
208
209 static inline void MUTEX_LOCK_SOFTAP_SET_INIT(dhd_pub_t *dhdp)
210 {
211 }
212
213 static inline void MUTEX_LOCK_SOFTAP_SET(dhd_pub_t *dhdp)
214 {
215 }
216
217 static inline void MUTEX_UNLOCK_SOFTAP_SET(dhd_pub_t *dhdp)
218 {
219 }
220
221 static inline void MUTEX_LOCK_WL_SCAN_SET_INIT(void)
222 {
223 }
224
225 static inline void MUTEX_LOCK_WL_SCAN_SET(void)
226 {
227 }
228
229 static inline void MUTEX_UNLOCK_WL_SCAN_SET(void)
230 {
231 }
232
233 static inline void WAKE_LOCK_INIT(dhd_pub_t *dhdp, int index, char *y)
234 {
235 #if defined(CONFIG_HAS_WAKELOCK)
236         wake_lock_init(&dhdp->wakelock[index], WAKE_LOCK_SUSPEND, y);
237 #endif  /* defined (CONFIG_HAS_WAKELOCK) */
238 }
239
240 static inline void WAKE_LOCK(dhd_pub_t *dhdp, int index)
241 {
242 #if defined(CONFIG_HAS_WAKELOCK)
243         wake_lock(&dhdp->wakelock[index]);
244 #endif  /* defined (CONFIG_HAS_WAKELOCK) */
245 }
246
247 static inline void WAKE_UNLOCK(dhd_pub_t *dhdp, int index)
248 {
249 #if defined(CONFIG_HAS_WAKELOCK)
250         wake_unlock(&dhdp->wakelock[index]);
251 #endif  /* defined (CONFIG_HAS_WAKELOCK) */
252 }
253
254 static inline void WAKE_LOCK_TIMEOUT(dhd_pub_t *dhdp, int index, long time)
255 {
256 #if defined(CONFIG_HAS_WAKELOCK)
257         wake_lock_timeout(&dhdp->wakelock[index], time);
258 #endif  /* defined (CONFIG_HAS_WAKELOCK) */
259 }
260
261 static inline void WAKE_LOCK_DESTROY(dhd_pub_t *dhdp, int index)
262 {
263 #if defined(CONFIG_HAS_WAKELOCK)
264         wake_lock_destroy(&dhdp->wakelock[index]);
265 #endif /* defined (CONFIG_HAS_WAKELOCK) */
266 }
267
268 typedef struct dhd_if_event {
269         u8 ifidx;
270         u8 action;
271         u8 flags;
272         u8 bssidx;
273 } dhd_if_event_t;
274
275 /*
276  * Exported from dhd OS modules (dhd_linux/dhd_ndis)
277  */
278
279 /* To allow osl_attach/detach calls from os-independent modules */
280 osl_t *dhd_osl_attach(void *pdev, uint bustype);
281 void dhd_osl_detach(osl_t *osh);
282
283 /* Indication from bus module regarding presence/insertion of dongle.
284  * Return dhd_pub_t pointer, used as handle to OS module in later calls.
285  * Returned structure should have bus and prot pointers filled in.
286  * bus_hdrlen specifies required headroom for bus module header.
287  */
288 extern dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen);
289 extern int dhd_net_attach(dhd_pub_t *dhdp, int idx);
290
291 /* Indication from bus module regarding removal/absence of dongle */
292 extern void dhd_detach(dhd_pub_t *dhdp);
293
294 /* Indication from bus module to change flow-control state */
295 extern void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool on);
296
297 extern bool dhd_prec_enq(dhd_pub_t *dhdp, struct pktq *q, void *pkt, int prec);
298
299 /* Receive frame for delivery to OS.  Callee disposes of rxp. */
300 extern void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *rxp, int numpkt);
301
302 /* Return pointer to interface name */
303 extern char *dhd_ifname(dhd_pub_t *dhdp, int idx);
304
305 /* Request scheduling of the bus dpc */
306 extern void dhd_sched_dpc(dhd_pub_t *dhdp);
307
308 /* Notify tx completion */
309 extern void dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success);
310
311 /* Query ioctl */
312 extern int dhdcdc_query_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf,
313                               uint len);
314
315 /* OS independent layer functions */
316 extern int dhd_os_proto_block(dhd_pub_t *pub);
317 extern int dhd_os_proto_unblock(dhd_pub_t *pub);
318 extern int dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition,
319                                   bool *pending);
320 extern int dhd_os_ioctl_resp_wake(dhd_pub_t *pub);
321 extern unsigned int dhd_os_get_ioctl_resp_timeout(void);
322 extern void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec);
323 extern void *dhd_os_open_image(char *filename);
324 extern int dhd_os_get_image_block(char *buf, int len, void *image);
325 extern void dhd_os_close_image(void *image);
326 extern void dhd_os_wd_timer(void *bus, uint wdtick);
327 extern void dhd_os_sdlock(dhd_pub_t *pub);
328 extern void dhd_os_sdunlock(dhd_pub_t *pub);
329 extern void dhd_os_sdlock_txq(dhd_pub_t *pub);
330 extern void dhd_os_sdunlock_txq(dhd_pub_t *pub);
331 extern void dhd_os_sdlock_rxq(dhd_pub_t *pub);
332 extern void dhd_os_sdunlock_rxq(dhd_pub_t *pub);
333 extern void dhd_os_sdlock_sndup_rxq(dhd_pub_t *pub);
334 extern void dhd_customer_gpio_wlan_ctrl(int onoff);
335 extern int dhd_custom_get_mac_address(unsigned char *buf);
336 extern void dhd_os_sdunlock_sndup_rxq(dhd_pub_t *pub);
337 extern void dhd_os_sdlock_eventq(dhd_pub_t *pub);
338 extern void dhd_os_sdunlock_eventq(dhd_pub_t *pub);
339 #ifdef DHD_DEBUG
340 extern int write_to_file(dhd_pub_t *dhd, u8 *buf, int size);
341 #endif                          /* DHD_DEBUG */
342 #if defined(OOB_INTR_ONLY)
343 extern int dhd_customer_oob_irq_map(unsigned long *irq_flags_ptr);
344 #endif                          /* defined(OOB_INTR_ONLY) */
345 extern void dhd_os_sdtxlock(dhd_pub_t *pub);
346 extern void dhd_os_sdtxunlock(dhd_pub_t *pub);
347
348 int setScheduler(struct task_struct *p, int policy, struct sched_param *param);
349
350 typedef struct {
351         u32 limit;              /* Expiration time (usec) */
352         u32 increment;  /* Current expiration increment (usec) */
353         u32 elapsed;            /* Current elapsed time (usec) */
354         u32 tick;               /* O/S tick time (usec) */
355 } dhd_timeout_t;
356
357 extern void dhd_timeout_start(dhd_timeout_t *tmo, uint usec);
358 extern int dhd_timeout_expired(dhd_timeout_t *tmo);
359
360 extern int dhd_ifname2idx(struct dhd_info *dhd, char *name);
361 extern u8 *dhd_bssidx2bssid(dhd_pub_t *dhd, int idx);
362 extern int wl_host_event(struct dhd_info *dhd, int *idx, void *pktdata,
363                          wl_event_msg_t *, void **data_ptr);
364 extern void wl_event_to_host_order(wl_event_msg_t *evt);
365
366 extern void dhd_common_init(void);
367
368 extern int dhd_add_if(struct dhd_info *dhd, int ifidx, void *handle,
369                       char *name, u8 *mac_addr, u32 flags, u8 bssidx);
370 extern void dhd_del_if(struct dhd_info *dhd, int ifidx);
371
372 extern void dhd_vif_add(struct dhd_info *dhd, int ifidx, char *name);
373 extern void dhd_vif_del(struct dhd_info *dhd, int ifidx);
374
375 extern void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx);
376 extern void dhd_vif_sendup(struct dhd_info *dhd, int ifidx, unsigned char * cp,
377                            int len);
378
379 /* Send packet to dongle via data channel */
380 extern int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pkt);
381
382 /* Send event to host */
383 extern void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event,
384                              void *data);
385 extern int dhd_bus_devreset(dhd_pub_t *dhdp, u8 flag);
386 extern uint dhd_bus_status(dhd_pub_t *dhdp);
387 extern int dhd_bus_start(dhd_pub_t *dhdp);
388
389 extern void print_buf(void *pbuf, int len, int bytes_per_line);
390
391 typedef enum cust_gpio_modes {
392         WLAN_RESET_ON,
393         WLAN_RESET_OFF,
394         WLAN_POWER_ON,
395         WLAN_POWER_OFF
396 } cust_gpio_modes_t;
397 /*
398  * Insmod parameters for debug/test
399  */
400
401 /* Watchdog timer interval */
402 extern uint dhd_watchdog_ms;
403
404 #if defined(DHD_DEBUG)
405 /* Console output poll interval */
406 extern uint dhd_console_ms;
407 #endif                          /* defined(DHD_DEBUG) */
408
409 /* Use interrupts */
410 extern uint dhd_intr;
411
412 /* Use polling */
413 extern uint dhd_poll;
414
415 /* ARP offload agent mode */
416 extern uint dhd_arp_mode;
417
418 /* ARP offload enable */
419 extern uint dhd_arp_enable;
420
421 /* Pkt filte enable control */
422 extern uint dhd_pkt_filter_enable;
423
424 /*  Pkt filter init setup */
425 extern uint dhd_pkt_filter_init;
426
427 /* Pkt filter mode control */
428 extern uint dhd_master_mode;
429
430 /* Roaming mode control */
431 extern uint dhd_roam;
432
433 /* Roaming mode control */
434 extern uint dhd_radio_up;
435
436 /* Initial idletime ticks (may be -1 for immediate idle, 0 for no idle) */
437 extern int dhd_idletime;
438 #define DHD_IDLETIME_TICKS 1
439
440 /* SDIO Drive Strength */
441 extern uint dhd_sdiod_drive_strength;
442
443 /* Override to force tx queueing all the time */
444 extern uint dhd_force_tx_queueing;
445
446 #ifdef SDTEST
447 /* Echo packet generator (SDIO), pkts/s */
448 extern uint dhd_pktgen;
449
450 /* Echo packet len (0 => sawtooth, max 1800) */
451 extern uint dhd_pktgen_len;
452 #define MAX_PKTGEN_LEN 1800
453 #endif
454
455 /* optionally set by a module_param_string() */
456 #define MOD_PARAM_PATHLEN       2048
457 extern char fw_path[MOD_PARAM_PATHLEN];
458 extern char nv_path[MOD_PARAM_PATHLEN];
459
460 /* For supporting multiple interfaces */
461 #define DHD_MAX_IFS     16
462 #define DHD_DEL_IF      -0xe
463 #define DHD_BAD_IF      -0xf
464
465 extern void dhd_wait_for_event(dhd_pub_t *dhd, bool * lockvar);
466 extern void dhd_wait_event_wakeup(dhd_pub_t *dhd);
467
468 #endif                          /* _dhd_h_ */