Merge branch 'sh-latest' of git://git.kernel.org/pub/scm/linux/kernel/git/lethal...
[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 <linux/suspend.h>
35 #include <asm/uaccess.h>
36 #include <asm/unaligned.h>
37 /* The kernel threading is sdio-specific */
38
39 #include <wlioctl.h>
40
41 /* Forward decls */
42 struct dhd_bus;
43 struct dhd_prot;
44 struct dhd_info;
45
46 /* The level of bus communication with the dongle */
47 enum dhd_bus_state {
48         DHD_BUS_DOWN,           /* Not ready for frame transfers */
49         DHD_BUS_LOAD,           /* Download access only (CPU reset) */
50         DHD_BUS_DATA            /* Ready for frame transfers */
51 };
52
53 /* Common structure for module and instance linkage */
54 typedef struct dhd_pub {
55         /* Linkage ponters */
56         struct dhd_bus *bus;    /* Bus module handle */
57         struct dhd_prot *prot;  /* Protocol module handle */
58         struct dhd_info *info;  /* Info module handle */
59
60         /* Internal dhd items */
61         bool up;                /* Driver up/down (to OS) */
62         bool txoff;             /* Transmit flow-controlled */
63         bool dongle_reset;      /* true = DEVRESET put dongle into reset */
64         enum dhd_bus_state busstate;
65         uint hdrlen;            /* Total DHD header length (proto + bus) */
66         uint maxctl;            /* Max size rxctl request from proto to bus */
67         uint rxsz;              /* Rx buffer size bus module should use */
68         u8 wme_dp;              /* wme discard priority */
69
70         /* Dongle media info */
71         bool iswl;              /* Dongle-resident driver is wl */
72         unsigned long drv_version;      /* Version of dongle-resident driver */
73         u8 mac[ETH_ALEN];                       /* MAC address obtained from dongle */
74         dngl_stats_t dstats;            /* Stats for dongle-based data */
75
76         /* Additional stats for the bus level */
77         unsigned long tx_packets;       /* Data packets sent to dongle */
78         unsigned long tx_multicast;     /* Multicast data packets sent to dongle */
79         unsigned long tx_errors;        /* Errors in sending data to dongle */
80         unsigned long tx_ctlpkts;       /* Control packets sent to dongle */
81         unsigned long tx_ctlerrs;       /* Errors sending control frames to dongle */
82         unsigned long rx_packets;       /* Packets sent up the network interface */
83         unsigned long rx_multicast;     /* Multicast packets sent up the network
84                                          interface */
85         unsigned long rx_errors;        /* Errors processing rx data packets */
86         unsigned long rx_ctlpkts;       /* Control frames processed from dongle */
87         unsigned long rx_ctlerrs;       /* Errors in processing rx control frames */
88         unsigned long rx_dropped;       /* Packets dropped locally (no memory) */
89         unsigned long rx_flushed;       /* Packets flushed due to
90                                 unscheduled sendup thread */
91         unsigned long wd_dpc_sched;     /* Number of times dhd dpc scheduled by
92                                          watchdog timer */
93
94         unsigned long rx_readahead_cnt; /* Number of packets where header read-ahead
95                                          was used. */
96         unsigned long tx_realloc;       /* Number of tx packets we had to realloc for
97                                          headroom */
98         unsigned long fc_packets;       /* Number of flow control pkts recvd */
99
100         /* Last error return */
101         int bcmerror;
102         uint tickcnt;
103
104         /* Last error from dongle */
105         int dongle_error;
106
107         /* Suspend disable flag  flag */
108         int suspend_disable_flag;       /* "1" to disable all extra powersaving
109                                          during suspend */
110         int in_suspend;         /* flag set to 1 when early suspend called */
111 #ifdef PNO_SUPPORT
112         int pno_enable;         /* pno status : "1" is pno enable */
113 #endif                          /* PNO_SUPPORT */
114         int dtim_skip;          /* dtim skip , default 0 means wake each dtim */
115
116         /* Pkt filter defination */
117         char *pktfilter[100];
118         int pktfilter_count;
119
120         u8 country_code[WLC_CNTRY_BUF_SZ];
121         char eventmask[WL_EVENTING_MASK_LEN];
122
123 } dhd_pub_t;
124
125 #if defined(CONFIG_PM_SLEEP)
126 extern atomic_t dhd_mmc_suspend;
127 #define DHD_PM_RESUME_WAIT_INIT(a) DECLARE_WAIT_QUEUE_HEAD(a);
128 #define _DHD_PM_RESUME_WAIT(a, b) do { \
129                 int retry = 0; \
130                 while (atomic_read(&dhd_mmc_suspend) && retry++ != b) { \
131                         wait_event_timeout(a, false, HZ/100); \
132                 } \
133         }       while (0)
134 #define DHD_PM_RESUME_WAIT(a)   _DHD_PM_RESUME_WAIT(a, 30)
135 #define DHD_PM_RESUME_WAIT_FOREVER(a)   _DHD_PM_RESUME_WAIT(a, ~0)
136 #define DHD_PM_RESUME_RETURN_ERROR(a)   \
137         do { if (atomic_read(&dhd_mmc_suspend)) return a; } while (0)
138 #define DHD_PM_RESUME_RETURN    do { \
139         if (atomic_read(&dhd_mmc_suspend)) \
140                 return; \
141         } while (0)
142
143 #define DHD_SPINWAIT_SLEEP_INIT(a) DECLARE_WAIT_QUEUE_HEAD(a);
144 #define SPINWAIT_SLEEP(a, exp, us) do { \
145                 uint countdown = (us) + 9999; \
146                 while ((exp) && (countdown >= 10000)) { \
147                         wait_event_timeout(a, false, HZ/100); \
148                         countdown -= 10000; \
149                 } \
150         } while (0)
151
152 #else
153
154 #define DHD_PM_RESUME_WAIT_INIT(a)
155 #define DHD_PM_RESUME_WAIT(a)
156 #define DHD_PM_RESUME_WAIT_FOREVER(a)
157 #define DHD_PM_RESUME_RETURN_ERROR(a)
158 #define DHD_PM_RESUME_RETURN
159
160 #define DHD_SPINWAIT_SLEEP_INIT(a)
161 #define SPINWAIT_SLEEP(a, exp, us)  do { \
162                 uint countdown = (us) + 9; \
163                 while ((exp) && (countdown >= 10)) { \
164                         udelay(10);  \
165                         countdown -= 10;  \
166                 } \
167         } while (0)
168
169 #endif  /* defined(CONFIG_PM_SLEEP) */
170 #define DHD_IF_VIF      0x01    /* Virtual IF (Hidden from user) */
171
172 static inline void MUTEX_LOCK_INIT(dhd_pub_t *dhdp)
173 {
174 }
175
176 static inline void MUTEX_LOCK(dhd_pub_t *dhdp)
177 {
178 }
179
180 static inline void MUTEX_UNLOCK(dhd_pub_t *dhdp)
181 {
182 }
183
184 static inline void MUTEX_LOCK_SOFTAP_SET_INIT(dhd_pub_t *dhdp)
185 {
186 }
187
188 static inline void MUTEX_LOCK_SOFTAP_SET(dhd_pub_t *dhdp)
189 {
190 }
191
192 static inline void MUTEX_UNLOCK_SOFTAP_SET(dhd_pub_t *dhdp)
193 {
194 }
195
196 static inline void MUTEX_LOCK_WL_SCAN_SET_INIT(void)
197 {
198 }
199
200 static inline void MUTEX_LOCK_WL_SCAN_SET(void)
201 {
202 }
203
204 static inline void MUTEX_UNLOCK_WL_SCAN_SET(void)
205 {
206 }
207
208 typedef struct dhd_if_event {
209         u8 ifidx;
210         u8 action;
211         u8 flags;
212         u8 bssidx;
213 } dhd_if_event_t;
214
215 /*
216  * Exported from dhd OS modules (dhd_linux/dhd_ndis)
217  */
218
219 /* Indication from bus module regarding presence/insertion of dongle.
220  * Return dhd_pub_t pointer, used as handle to OS module in later calls.
221  * Returned structure should have bus and prot pointers filled in.
222  * bus_hdrlen specifies required headroom for bus module header.
223  */
224 extern dhd_pub_t *dhd_attach(struct dhd_bus *bus,
225                                 uint bus_hdrlen);
226 extern int dhd_net_attach(dhd_pub_t *dhdp, int idx);
227
228 /* Indication from bus module regarding removal/absence of dongle */
229 extern void dhd_detach(dhd_pub_t *dhdp);
230
231 /* Indication from bus module to change flow-control state */
232 extern void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool on);
233
234 extern bool dhd_prec_enq(dhd_pub_t *dhdp, struct pktq *q,
235                          struct sk_buff *pkt, int prec);
236
237 /* Receive frame for delivery to OS.  Callee disposes of rxp. */
238 extern void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx,
239                          struct sk_buff *rxp, int numpkt);
240
241 /* Return pointer to interface name */
242 extern char *dhd_ifname(dhd_pub_t *dhdp, int idx);
243
244 /* Request scheduling of the bus dpc */
245 extern void dhd_sched_dpc(dhd_pub_t *dhdp);
246
247 /* Notify tx completion */
248 extern void dhd_txcomplete(dhd_pub_t *dhdp, struct sk_buff *txp, bool success);
249
250 /* Query ioctl */
251 extern int dhdcdc_query_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf,
252                               uint len);
253
254 /* OS independent layer functions */
255 extern int dhd_os_proto_block(dhd_pub_t *pub);
256 extern int dhd_os_proto_unblock(dhd_pub_t *pub);
257 extern int dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition,
258                                   bool *pending);
259 extern int dhd_os_ioctl_resp_wake(dhd_pub_t *pub);
260 extern unsigned int dhd_os_get_ioctl_resp_timeout(void);
261 extern void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec);
262 extern void *dhd_os_open_image(char *filename);
263 extern int dhd_os_get_image_block(char *buf, int len, void *image);
264 extern void dhd_os_close_image(void *image);
265 extern void dhd_os_wd_timer(void *bus, uint wdtick);
266 extern void dhd_os_sdlock(dhd_pub_t *pub);
267 extern void dhd_os_sdunlock(dhd_pub_t *pub);
268 extern void dhd_os_sdlock_txq(dhd_pub_t *pub);
269 extern void dhd_os_sdunlock_txq(dhd_pub_t *pub);
270 extern void dhd_os_sdlock_rxq(dhd_pub_t *pub);
271 extern void dhd_os_sdunlock_rxq(dhd_pub_t *pub);
272 extern void dhd_os_sdlock_sndup_rxq(dhd_pub_t *pub);
273 extern void dhd_customer_gpio_wlan_ctrl(int onoff);
274 extern int dhd_custom_get_mac_address(unsigned char *buf);
275 extern void dhd_os_sdunlock_sndup_rxq(dhd_pub_t *pub);
276 extern void dhd_os_sdlock_eventq(dhd_pub_t *pub);
277 extern void dhd_os_sdunlock_eventq(dhd_pub_t *pub);
278 #ifdef DHD_DEBUG
279 extern int write_to_file(dhd_pub_t *dhd, u8 *buf, int size);
280 #endif                          /* DHD_DEBUG */
281 #if defined(OOB_INTR_ONLY)
282 extern int dhd_customer_oob_irq_map(unsigned long *irq_flags_ptr);
283 #endif                          /* defined(OOB_INTR_ONLY) */
284 extern void dhd_os_sdtxlock(dhd_pub_t *pub);
285 extern void dhd_os_sdtxunlock(dhd_pub_t *pub);
286
287 int setScheduler(struct task_struct *p, int policy, struct sched_param *param);
288
289 typedef struct {
290         u32 limit;              /* Expiration time (usec) */
291         u32 increment;  /* Current expiration increment (usec) */
292         u32 elapsed;            /* Current elapsed time (usec) */
293         u32 tick;               /* O/S tick time (usec) */
294 } dhd_timeout_t;
295
296 extern void dhd_timeout_start(dhd_timeout_t *tmo, uint usec);
297 extern int dhd_timeout_expired(dhd_timeout_t *tmo);
298
299 extern int dhd_ifname2idx(struct dhd_info *dhd, char *name);
300 extern u8 *dhd_bssidx2bssid(dhd_pub_t *dhd, int idx);
301 extern int wl_host_event(struct dhd_info *dhd, int *idx, void *pktdata,
302                          wl_event_msg_t *, void **data_ptr);
303
304 extern void dhd_common_init(void);
305
306 extern int dhd_add_if(struct dhd_info *dhd, int ifidx, void *handle,
307                       char *name, u8 *mac_addr, u32 flags, u8 bssidx);
308 extern void dhd_del_if(struct dhd_info *dhd, int ifidx);
309
310 extern void dhd_vif_add(struct dhd_info *dhd, int ifidx, char *name);
311 extern void dhd_vif_del(struct dhd_info *dhd, int ifidx);
312
313 extern void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx);
314 extern void dhd_vif_sendup(struct dhd_info *dhd, int ifidx, unsigned char * cp,
315                            int len);
316
317 /* Send packet to dongle via data channel */
318 extern int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, struct sk_buff *pkt);
319
320 /* Send event to host */
321 extern void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event,
322                              void *data);
323 extern int dhd_bus_devreset(dhd_pub_t *dhdp, u8 flag);
324 extern uint dhd_bus_status(dhd_pub_t *dhdp);
325 extern int dhd_bus_start(dhd_pub_t *dhdp);
326
327 enum cust_gpio_modes {
328         WLAN_RESET_ON,
329         WLAN_RESET_OFF,
330         WLAN_POWER_ON,
331         WLAN_POWER_OFF
332 };
333 /*
334  * Insmod parameters for debug/test
335  */
336
337 /* Watchdog timer interval */
338 extern uint dhd_watchdog_ms;
339
340 #if defined(DHD_DEBUG)
341 /* Console output poll interval */
342 extern uint dhd_console_ms;
343 #endif                          /* defined(DHD_DEBUG) */
344
345 /* Use interrupts */
346 extern uint dhd_intr;
347
348 /* Use polling */
349 extern uint dhd_poll;
350
351 /* ARP offload agent mode */
352 extern uint dhd_arp_mode;
353
354 /* ARP offload enable */
355 extern uint dhd_arp_enable;
356
357 /* Pkt filte enable control */
358 extern uint dhd_pkt_filter_enable;
359
360 /*  Pkt filter init setup */
361 extern uint dhd_pkt_filter_init;
362
363 /* Pkt filter mode control */
364 extern uint dhd_master_mode;
365
366 /* Roaming mode control */
367 extern uint dhd_roam;
368
369 /* Roaming mode control */
370 extern uint dhd_radio_up;
371
372 /* Initial idletime ticks (may be -1 for immediate idle, 0 for no idle) */
373 extern int dhd_idletime;
374 #define DHD_IDLETIME_TICKS 1
375
376 /* SDIO Drive Strength */
377 extern uint dhd_sdiod_drive_strength;
378
379 /* Override to force tx queueing all the time */
380 extern uint dhd_force_tx_queueing;
381
382 #ifdef SDTEST
383 /* Echo packet generator (SDIO), pkts/s */
384 extern uint dhd_pktgen;
385
386 /* Echo packet len (0 => sawtooth, max 1800) */
387 extern uint dhd_pktgen_len;
388 #define MAX_PKTGEN_LEN 1800
389 #endif
390
391 /* optionally set by a module_param_string() */
392 #define MOD_PARAM_PATHLEN       2048
393 extern char fw_path[MOD_PARAM_PATHLEN];
394 extern char nv_path[MOD_PARAM_PATHLEN];
395
396 /* For supporting multiple interfaces */
397 #define DHD_MAX_IFS     16
398 #define DHD_DEL_IF      -0xe
399 #define DHD_BAD_IF      -0xf
400
401 extern void dhd_wait_for_event(dhd_pub_t *dhd, bool * lockvar);
402 extern void dhd_wait_event_wakeup(dhd_pub_t *dhd);
403
404 extern u32 g_assert_type;
405
406 #ifdef BCMDBG
407 #define ASSERT(exp) \
408           do { if (!(exp)) osl_assert(#exp, __FILE__, __LINE__); } while (0)
409 extern void osl_assert(char *exp, char *file, int line);
410 #else
411 #define ASSERT(exp)     do {} while (0)
412 #endif  /* defined(BCMDBG) */
413
414 #endif                          /* _dhd_h_ */