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