Merge branch 'staging-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh...
[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         struct osl_info *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 struct osl_info *dhd_osl_attach(void *pdev, uint bustype);
281 void dhd_osl_detach(struct osl_info *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(struct osl_info *osh, struct dhd_bus *bus,
289                                 uint bus_hdrlen);
290 extern int dhd_net_attach(dhd_pub_t *dhdp, int idx);
291
292 /* Indication from bus module regarding removal/absence of dongle */
293 extern void dhd_detach(dhd_pub_t *dhdp);
294
295 /* Indication from bus module to change flow-control state */
296 extern void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool on);
297
298 extern bool dhd_prec_enq(dhd_pub_t *dhdp, struct pktq *q,
299                          struct sk_buff *pkt, int prec);
300
301 /* Receive frame for delivery to OS.  Callee disposes of rxp. */
302 extern void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx,
303                          struct sk_buff *rxp, int numpkt);
304
305 /* Return pointer to interface name */
306 extern char *dhd_ifname(dhd_pub_t *dhdp, int idx);
307
308 /* Request scheduling of the bus dpc */
309 extern void dhd_sched_dpc(dhd_pub_t *dhdp);
310
311 /* Notify tx completion */
312 extern void dhd_txcomplete(dhd_pub_t *dhdp, struct sk_buff *txp, bool success);
313
314 /* Query ioctl */
315 extern int dhdcdc_query_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf,
316                               uint len);
317
318 /* OS independent layer functions */
319 extern int dhd_os_proto_block(dhd_pub_t *pub);
320 extern int dhd_os_proto_unblock(dhd_pub_t *pub);
321 extern int dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition,
322                                   bool *pending);
323 extern int dhd_os_ioctl_resp_wake(dhd_pub_t *pub);
324 extern unsigned int dhd_os_get_ioctl_resp_timeout(void);
325 extern void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec);
326 extern void *dhd_os_open_image(char *filename);
327 extern int dhd_os_get_image_block(char *buf, int len, void *image);
328 extern void dhd_os_close_image(void *image);
329 extern void dhd_os_wd_timer(void *bus, uint wdtick);
330 extern void dhd_os_sdlock(dhd_pub_t *pub);
331 extern void dhd_os_sdunlock(dhd_pub_t *pub);
332 extern void dhd_os_sdlock_txq(dhd_pub_t *pub);
333 extern void dhd_os_sdunlock_txq(dhd_pub_t *pub);
334 extern void dhd_os_sdlock_rxq(dhd_pub_t *pub);
335 extern void dhd_os_sdunlock_rxq(dhd_pub_t *pub);
336 extern void dhd_os_sdlock_sndup_rxq(dhd_pub_t *pub);
337 extern void dhd_customer_gpio_wlan_ctrl(int onoff);
338 extern int dhd_custom_get_mac_address(unsigned char *buf);
339 extern void dhd_os_sdunlock_sndup_rxq(dhd_pub_t *pub);
340 extern void dhd_os_sdlock_eventq(dhd_pub_t *pub);
341 extern void dhd_os_sdunlock_eventq(dhd_pub_t *pub);
342 #ifdef DHD_DEBUG
343 extern int write_to_file(dhd_pub_t *dhd, u8 *buf, int size);
344 #endif                          /* DHD_DEBUG */
345 #if defined(OOB_INTR_ONLY)
346 extern int dhd_customer_oob_irq_map(unsigned long *irq_flags_ptr);
347 #endif                          /* defined(OOB_INTR_ONLY) */
348 extern void dhd_os_sdtxlock(dhd_pub_t *pub);
349 extern void dhd_os_sdtxunlock(dhd_pub_t *pub);
350
351 int setScheduler(struct task_struct *p, int policy, struct sched_param *param);
352
353 typedef struct {
354         u32 limit;              /* Expiration time (usec) */
355         u32 increment;  /* Current expiration increment (usec) */
356         u32 elapsed;            /* Current elapsed time (usec) */
357         u32 tick;               /* O/S tick time (usec) */
358 } dhd_timeout_t;
359
360 extern void dhd_timeout_start(dhd_timeout_t *tmo, uint usec);
361 extern int dhd_timeout_expired(dhd_timeout_t *tmo);
362
363 extern int dhd_ifname2idx(struct dhd_info *dhd, char *name);
364 extern u8 *dhd_bssidx2bssid(dhd_pub_t *dhd, int idx);
365 extern int wl_host_event(struct dhd_info *dhd, int *idx, void *pktdata,
366                          wl_event_msg_t *, void **data_ptr);
367 extern void wl_event_to_host_order(wl_event_msg_t *evt);
368
369 extern void dhd_common_init(void);
370
371 extern int dhd_add_if(struct dhd_info *dhd, int ifidx, void *handle,
372                       char *name, u8 *mac_addr, u32 flags, u8 bssidx);
373 extern void dhd_del_if(struct dhd_info *dhd, int ifidx);
374
375 extern void dhd_vif_add(struct dhd_info *dhd, int ifidx, char *name);
376 extern void dhd_vif_del(struct dhd_info *dhd, int ifidx);
377
378 extern void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx);
379 extern void dhd_vif_sendup(struct dhd_info *dhd, int ifidx, unsigned char * cp,
380                            int len);
381
382 /* Send packet to dongle via data channel */
383 extern int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, struct sk_buff *pkt);
384
385 /* Send event to host */
386 extern void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event,
387                              void *data);
388 extern int dhd_bus_devreset(dhd_pub_t *dhdp, u8 flag);
389 extern uint dhd_bus_status(dhd_pub_t *dhdp);
390 extern int dhd_bus_start(dhd_pub_t *dhdp);
391
392 extern void print_buf(void *pbuf, int len, int bytes_per_line);
393
394 typedef enum cust_gpio_modes {
395         WLAN_RESET_ON,
396         WLAN_RESET_OFF,
397         WLAN_POWER_ON,
398         WLAN_POWER_OFF
399 } cust_gpio_modes_t;
400 /*
401  * Insmod parameters for debug/test
402  */
403
404 /* Watchdog timer interval */
405 extern uint dhd_watchdog_ms;
406
407 #if defined(DHD_DEBUG)
408 /* Console output poll interval */
409 extern uint dhd_console_ms;
410 #endif                          /* defined(DHD_DEBUG) */
411
412 /* Use interrupts */
413 extern uint dhd_intr;
414
415 /* Use polling */
416 extern uint dhd_poll;
417
418 /* ARP offload agent mode */
419 extern uint dhd_arp_mode;
420
421 /* ARP offload enable */
422 extern uint dhd_arp_enable;
423
424 /* Pkt filte enable control */
425 extern uint dhd_pkt_filter_enable;
426
427 /*  Pkt filter init setup */
428 extern uint dhd_pkt_filter_init;
429
430 /* Pkt filter mode control */
431 extern uint dhd_master_mode;
432
433 /* Roaming mode control */
434 extern uint dhd_roam;
435
436 /* Roaming mode control */
437 extern uint dhd_radio_up;
438
439 /* Initial idletime ticks (may be -1 for immediate idle, 0 for no idle) */
440 extern int dhd_idletime;
441 #define DHD_IDLETIME_TICKS 1
442
443 /* SDIO Drive Strength */
444 extern uint dhd_sdiod_drive_strength;
445
446 /* Override to force tx queueing all the time */
447 extern uint dhd_force_tx_queueing;
448
449 #ifdef SDTEST
450 /* Echo packet generator (SDIO), pkts/s */
451 extern uint dhd_pktgen;
452
453 /* Echo packet len (0 => sawtooth, max 1800) */
454 extern uint dhd_pktgen_len;
455 #define MAX_PKTGEN_LEN 1800
456 #endif
457
458 /* optionally set by a module_param_string() */
459 #define MOD_PARAM_PATHLEN       2048
460 extern char fw_path[MOD_PARAM_PATHLEN];
461 extern char nv_path[MOD_PARAM_PATHLEN];
462
463 /* For supporting multiple interfaces */
464 #define DHD_MAX_IFS     16
465 #define DHD_DEL_IF      -0xe
466 #define DHD_BAD_IF      -0xf
467
468 extern void dhd_wait_for_event(dhd_pub_t *dhd, bool * lockvar);
469 extern void dhd_wait_event_wakeup(dhd_pub_t *dhd);
470
471 #endif                          /* _dhd_h_ */