upload tizen1.0 source
[kernel/linux-2.6.36.git] / drivers / net / wireless / bcm4330 / src / dhd / sys / dhd.h
1 /*
2  * Header file describing the internal (inter-module) DHD interfaces.
3  *
4  * Provides type definitions and function prototypes used to link the
5  * DHD OS, bus, and protocol modules.
6  *
7  * Copyright (C) 1999-2011, Broadcom Corporation
8  * 
9  *         Unless you and Broadcom execute a separate written software license
10  * agreement governing use of this software, this software is licensed to you
11  * under the terms of the GNU General Public License version 2 (the "GPL"),
12  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
13  * following added to such license:
14  * 
15  *      As a special exception, the copyright holders of this software give you
16  * permission to link this software with independent modules, and to copy and
17  * distribute the resulting executable under terms of your choice, provided that
18  * you also meet, for each linked independent module, the terms and conditions of
19  * the license of that module.  An independent module is a module which is not
20  * derived from this software.  The special exception does not apply to any
21  * modifications of the software.
22  * 
23  *      Notwithstanding the above, under no circumstances may you combine this
24  * software in any way with any other Broadcom software provided under a license
25  * other than the GPL, without Broadcom's express prior written consent.
26  *
27  * $Id: dhd.h,v 1.60.4.17 2011-01-09 08:11:56 $
28  */
29
30 /****************
31  * Common types *
32  */
33
34 #ifndef _dhd_h_
35 #define _dhd_h_
36
37 #if defined(CHROMIUMOS_COMPAT_WIRELESS)
38 #include <linux/sched.h>
39 #endif
40 #include <linux/init.h>
41 #include <linux/kernel.h>
42 #include <linux/slab.h>
43 #include <linux/skbuff.h>
44 #include <linux/netdevice.h>
45 #include <linux/etherdevice.h>
46 #include <linux/random.h>
47 #include <linux/spinlock.h>
48 #include <linux/ethtool.h>
49 #include <asm/uaccess.h>
50 #include <asm/unaligned.h>
51 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_HAS_WAKELOCK)
52 #include <linux/wakelock.h>
53 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined (CONFIG_HAS_WAKELOCK) */
54
55 /* The kernel threading is sdio-specific */
56
57 #include <wlioctl.h>
58
59
60 /* Forward decls */
61 struct dhd_bus;
62 struct dhd_prot;
63 struct dhd_info;
64 struct dhd_cmn;
65
66 /* The level of bus communication with the dongle */
67 enum dhd_bus_state {
68         DHD_BUS_DOWN,           /* Not ready for frame transfers */
69         DHD_BUS_LOAD,           /* Download access only (CPU reset) */
70         DHD_BUS_DATA            /* Ready for frame transfers */
71 };
72
73 enum dhd_bus_wake_state {
74         WAKE_LOCK_OFF,
75         WAKE_LOCK_PRIV,
76         WAKE_LOCK_DPC,
77         WAKE_LOCK_IOCTL,
78         WAKE_LOCK_DOWNLOAD,
79         WAKE_LOCK_TMOUT,
80         WAKE_LOCK_WATCHDOG,
81         WAKE_LOCK_LINK_DOWN_TMOUT,
82         WAKE_LOCK_PNO_FIND_TMOUT,
83         WAKE_LOCK_SOFTAP_SET,
84         WAKE_LOCK_SOFTAP_STOP,
85         WAKE_LOCK_SOFTAP_START,
86         WAKE_LOCK_MAX
87 };
88 enum dhd_prealloc_index {
89         DHD_PREALLOC_PROT = 0,
90         DHD_PREALLOC_RXBUF,
91         DHD_PREALLOC_DATABUF,
92         DHD_PREALLOC_OSL_BUF
93 };
94 #ifdef DHD_USE_STATIC_BUF
95 extern void * dhd_os_prealloc(int section, unsigned long size);
96 #endif
97 /* Common structure for module and instance linkage */
98 typedef struct dhd_pub {
99         /* Linkage ponters */
100         osl_t *osh;             /* OSL handle */
101         struct dhd_bus *bus;    /* Bus module handle */
102         struct dhd_prot *prot;  /* Protocol module handle */
103         struct dhd_info  *info; /* Info module handle */
104         struct dhd_cmn  *cmn;   /* dhd_common module handle */
105
106         /* Internal dhd items */
107         bool up;                /* Driver up/down (to OS) */
108         bool txoff;             /* Transmit flow-controlled */
109         bool dongle_reset;  /* TRUE = DEVRESET put dongle into reset */
110         enum dhd_bus_state busstate;
111         uint hdrlen;            /* Total DHD header length (proto + bus) */
112         uint maxctl;            /* Max size rxctl request from proto to bus */
113         uint rxsz;              /* Rx buffer size bus module should use */
114         uint8 wme_dp;   /* wme discard priority */
115
116         /* Dongle media info */
117         bool iswl;              /* Dongle-resident driver is wl */
118         ulong drv_version;      /* Version of dongle-resident driver */
119         struct ether_addr mac;  /* MAC address obtained from dongle */
120         dngl_stats_t dstats;    /* Stats for dongle-based data */
121
122         /* Additional stats for the bus level */
123         ulong tx_packets;       /* Data packets sent to dongle */
124         ulong tx_multicast;     /* Multicast data packets sent to dongle */
125         ulong tx_errors;        /* Errors in sending data to dongle */
126         ulong tx_ctlpkts;       /* Control packets sent to dongle */
127         ulong tx_ctlerrs;       /* Errors sending control frames to dongle */
128         ulong rx_packets;       /* Packets sent up the network interface */
129         ulong rx_multicast;     /* Multicast packets sent up the network interface */
130         ulong rx_errors;        /* Errors processing rx data packets */
131         ulong rx_ctlpkts;       /* Control frames processed from dongle */
132         ulong rx_ctlerrs;       /* Errors in processing rx control frames */
133         ulong rx_dropped;       /* Packets dropped locally (no memory) */
134         ulong rx_flushed;  /* Packets flushed due to unscheduled sendup thread */
135         ulong wd_dpc_sched;   /* Number of times dhd dpc scheduled by watchdog timer */
136
137         ulong rx_readahead_cnt; /* Number of packets where header read-ahead was used. */
138         ulong tx_realloc;       /* Number of tx packets we had to realloc for headroom */
139         ulong fc_packets;       /* Number of flow control pkts recvd */
140
141         /* Last error return */
142         int bcmerror;
143         uint tickcnt;
144
145         /* Last error from dongle */
146         int dongle_error;
147
148         /* Suspend disable flag and "in suspend" flag */
149         int suspend_disable_flag; /* "1" to disable all extra powersaving during suspend */
150         int in_suspend;                 /* flag set to 1 when early suspend called */
151 #ifdef PNO_SUPPORT
152         int pno_enable;                 /* pno status : "1" is pno enable */
153 #endif /* PNO_SUPPORT */
154         int dtim_skip;         /* dtim skip , default 0 means wake each dtim */
155
156         /* Pkt filter defination */
157         char * pktfilter[100];
158         int pktfilter_count;
159
160         uint8 country_code[WLC_CNTRY_BUF_SZ];
161         char eventmask[WL_EVENTING_MASK_LEN];
162         bool    dongle_isolation;
163
164 #ifdef WLMEDIA_HTSF
165         uint8 htsfdlystat_sz; /* Size of delay stats, max 255B */
166 #endif
167 } dhd_pub_t;
168
169 typedef struct dhd_cmn {
170         osl_t *osh;             /* OSL handle */
171         dhd_pub_t *dhd;
172 } dhd_cmn_t;
173
174
175 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP) && !defined(BRCM_SUSPEND)
176
177         #define DHD_PM_RESUME_WAIT_INIT(a) DECLARE_WAIT_QUEUE_HEAD(a);
178         #define _DHD_PM_RESUME_WAIT(a, b) do {\
179                         int retry = 0; \
180                         smp_mb(); \
181                         while (dhd_mmc_suspend && retry++ != b) { \
182                                 wait_event_interruptible_timeout(a, FALSE, HZ/100); \
183                         } \
184                 }       while (0)
185         #define DHD_PM_RESUME_WAIT(a)                   _DHD_PM_RESUME_WAIT(a, 30)
186         #define DHD_PM_RESUME_WAIT_FOREVER(a)   _DHD_PM_RESUME_WAIT(a, ~0)
187         #define DHD_PM_RESUME_RETURN_ERROR(a)   do { if (dhd_mmc_suspend) return a; } while (0)
188         #define DHD_PM_RESUME_RETURN            do { if (dhd_mmc_suspend) return; } while (0)
189
190         #define DHD_SPINWAIT_SLEEP_INIT(a) DECLARE_WAIT_QUEUE_HEAD(a);
191         #define SPINWAIT_SLEEP(a, exp, us) do { \
192                 uint countdown = (us) + 9999; \
193                 while ((exp) && (countdown >= 10000)) { \
194                         wait_event_interruptible_timeout(a, FALSE, HZ/100); \
195                         countdown -= 10000; \
196                 } \
197         } while (0)
198
199         #else
200
201         #define DHD_PM_RESUME_WAIT_INIT(a)
202         #define DHD_PM_RESUME_WAIT(a)
203         #define DHD_PM_RESUME_WAIT_FOREVER(a)
204         #define DHD_PM_RESUME_RETURN_ERROR(a)
205         #define DHD_PM_RESUME_RETURN
206
207         #define DHD_SPINWAIT_SLEEP_INIT(a)
208         #define SPINWAIT_SLEEP(a, exp, us)  do { \
209                 uint countdown = (us) + 9; \
210                 while ((exp) && (countdown >= 10)) { \
211                         OSL_DELAY(10);  \
212                         countdown -= 10;  \
213                 } \
214         } while (0)
215
216 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP) && !defined(BRCM_SUSPEND) */
217 #ifndef DHDTHREAD
218 #undef  SPINWAIT_SLEEP
219 #define SPINWAIT_SLEEP(a, exp, us) SPINWAIT(exp, us)
220 #endif /* DHDTHREAD */
221 #define DHD_IF_VIF      0x01    /* Virtual IF (Hidden from user) */
222
223 /*  Wakelock Functions */
224 extern int dhd_os_wake_lock(dhd_pub_t *pub);
225 extern int dhd_os_wake_unlock(dhd_pub_t *pub);
226 extern int dhd_os_wake_lock_timeout(dhd_pub_t *pub);
227 extern int dhd_os_wake_lock_timeout_enable(dhd_pub_t *pub);
228
229 /* Wake lock are used in Android only (until the Linux community accepts it) */
230 #define DHD_OS_WAKE_LOCK(pub)                           dhd_os_wake_lock(pub)
231 #define DHD_OS_WAKE_UNLOCK(pub)                         dhd_os_wake_unlock(pub)
232 #define DHD_OS_WAKE_LOCK_TIMEOUT(pub)                   dhd_os_wake_lock_timeout(pub)
233 #define DHD_OS_WAKE_LOCK_TIMEOUT_ENABLE(pub) dhd_os_wake_lock_timeout_enable(pub);
234
235
236 typedef struct dhd_if_event {
237         uint8 ifidx;
238         uint8 action;
239         uint8 flags;
240         uint8 bssidx;
241         uint8 is_AP;
242 } dhd_if_event_t;
243
244 typedef enum dhd_attach_states
245 {
246         DHD_ATTACH_STATE_INIT = 0x0,
247         DHD_ATTACH_STATE_NET_ALLOC = 0x1,
248         DHD_ATTACH_STATE_DHD_ALLOC = 0x2,
249         DHD_ATTACH_STATE_ADD_IF = 0x4,
250         DHD_ATTACH_STATE_PROT_ATTACH = 0x8,
251         DHD_ATTACH_STATE_WL_ATTACH = 0x10,
252         DHD_ATTACH_STATE_THREADS_CREATED = 0x20,
253         DHD_ATTACH_STATE_WAKELOCKS_INIT = 0x40,
254         DHD_ATTACH_STATE_CFG80211 = 0x80,
255         DHD_ATTACH_STATE_EARLYSUSPEND_DONE = 0x100,
256         DHD_ATTACH_STATE_DONE = 0x200
257 } dhd_attach_states_t;
258
259 /* Value -1 means we are unsuccessful in creating the kthread. */
260 #define DHD_PID_KT_INVALID      -1
261 /* Value -2 means we are unsuccessful in both creating the kthread and tasklet */
262 #define DHD_PID_KT_TL_INVALID   -2
263
264 /*
265  * Exported from dhd OS modules (dhd_linux/dhd_ndis)
266  */
267
268 /* To allow osl_attach/detach calls from os-independent modules */
269 osl_t *dhd_osl_attach(void *pdev, uint bustype);
270 void dhd_osl_detach(osl_t *osh);
271
272 /* Indication from bus module regarding presence/insertion of dongle.
273  * Return dhd_pub_t pointer, used as handle to OS module in later calls.
274  * Returned structure should have bus and prot pointers filled in.
275  * bus_hdrlen specifies required headroom for bus module header.
276  */
277 extern dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen);
278 extern int dhd_net_attach(dhd_pub_t *dhdp, int idx);
279
280 /* Indication from bus module regarding removal/absence of dongle */
281 extern void dhd_detach(dhd_pub_t *dhdp);
282 extern void dhd_free(dhd_pub_t *dhdp);
283
284 /* Indication from bus module to change flow-control state */
285 extern void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool on);
286
287 extern bool dhd_prec_enq(dhd_pub_t *dhdp, struct pktq *q, void *pkt, int prec);
288
289 /* Receive frame for delivery to OS.  Callee disposes of rxp. */
290 extern void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *rxp, int numpkt);
291
292 /* Return pointer to interface name */
293 extern char *dhd_ifname(dhd_pub_t *dhdp, int idx);
294
295 /* Request scheduling of the bus dpc */
296 extern void dhd_sched_dpc(dhd_pub_t *dhdp);
297
298 /* Notify tx completion */
299 extern void dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success);
300
301 /* OS independent layer functions */
302 extern int dhd_os_proto_block(dhd_pub_t * pub);
303 extern int dhd_os_proto_unblock(dhd_pub_t * pub);
304 extern int dhd_os_ioctl_resp_wait(dhd_pub_t * pub, uint * condition, bool * pending);
305 extern int dhd_os_ioctl_resp_wake(dhd_pub_t * pub);
306 extern unsigned int dhd_os_get_ioctl_resp_timeout(void);
307 extern void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec);
308 extern void * dhd_os_open_image(char * filename);
309 extern int dhd_os_get_image_block(char * buf, int len, void * image);
310 extern void dhd_os_close_image(void * image);
311 extern void dhd_os_wd_timer(void *bus, uint wdtick);
312 extern void dhd_os_sdlock(dhd_pub_t * pub);
313 extern void dhd_os_sdunlock(dhd_pub_t * pub);
314 extern void dhd_os_sdlock_txq(dhd_pub_t * pub);
315 extern void dhd_os_sdunlock_txq(dhd_pub_t * pub);
316 extern void dhd_os_sdlock_rxq(dhd_pub_t * pub);
317 extern void dhd_os_sdunlock_rxq(dhd_pub_t * pub);
318 extern void dhd_os_sdlock_sndup_rxq(dhd_pub_t * pub);
319 extern void dhd_customer_gpio_wlan_ctrl(int onoff);
320 extern int         dhd_custom_get_mac_address(unsigned char *buf);
321 extern void dhd_os_sdunlock_sndup_rxq(dhd_pub_t * pub);
322 extern void dhd_os_sdlock_eventq(dhd_pub_t * pub);
323 extern void dhd_os_sdunlock_eventq(dhd_pub_t * pub);
324 extern int dhd_os_get_wakelock(dhd_pub_t *pub);
325
326 #ifdef DHD_DEBUG
327 extern int write_to_file(dhd_pub_t *dhd, uint8 *buf, int size);
328 #endif /* DHD_DEBUG */
329 #if defined(OOB_INTR_ONLY)
330 extern int dhd_customer_oob_irq_map(unsigned long *irq_flags_ptr);
331 #endif /* defined(OOB_INTR_ONLY) */
332 extern void dhd_os_sdtxlock(dhd_pub_t * pub);
333 extern void dhd_os_sdtxunlock(dhd_pub_t * pub);
334
335 #if defined(DHDTHREAD)
336 struct task_struct;
337 struct sched_param;
338 int setScheduler(struct task_struct *p, int policy, struct sched_param *param);
339 #endif /* DHDTHREAD && DHD_GPL */
340
341 typedef struct {
342         uint32 limit;           /* Expiration time (usec) */
343         uint32 increment;       /* Current expiration increment (usec) */
344         uint32 elapsed;         /* Current elapsed time (usec) */
345         uint32 tick;            /* O/S tick time (usec) */
346 } dhd_timeout_t;
347
348 extern void dhd_timeout_start(dhd_timeout_t *tmo, uint usec);
349 extern int dhd_timeout_expired(dhd_timeout_t *tmo);
350
351 extern int dhd_ifname2idx(struct dhd_info *dhd, char *name);
352 extern int wl_host_event(dhd_pub_t *dhd_pub, int *idx, void *pktdata,
353                          wl_event_msg_t *, void **data_ptr);
354 extern void wl_event_to_host_order(wl_event_msg_t * evt);
355
356 extern int dhd_wl_ioctl(dhd_pub_t *dhd_pub, int ifindex, wl_ioctl_t *ioc, void *buf, int len);
357 extern int dhd_wl_ioctl_cmd(dhd_pub_t *dhd_pub, int cmd, void *arg, int len, uint8 set,
358                             int ifindex);
359
360 extern struct dhd_cmn *dhd_common_init(osl_t *osh);
361 extern void dhd_common_deinit(dhd_pub_t *dhd_pub);
362
363 extern int dhd_add_if(struct dhd_info *dhd, int ifidx, void *handle,
364         char *name, uint8 *mac_addr, uint32 flags, uint8 bssidx);
365 extern void dhd_del_if(struct dhd_info *dhd, int ifidx);
366
367 extern void dhd_vif_add(struct dhd_info *dhd, int ifidx, char * name);
368 extern void dhd_vif_del(struct dhd_info *dhd, int ifidx);
369
370 extern void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx);
371 extern void dhd_vif_sendup(struct dhd_info *dhd, int ifidx, uchar *cp, int len);
372
373
374 /* Send packet to dongle via data channel */
375 extern int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pkt);
376
377 /* send up locally generated event */
378 extern void dhd_sendup_event_common(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data);
379 /* Send event to host */
380 extern void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data);
381 extern int dhd_bus_devreset(dhd_pub_t *dhdp, uint8 flag);
382 extern uint dhd_bus_status(dhd_pub_t *dhdp);
383 extern int  dhd_bus_start(dhd_pub_t *dhdp);
384 extern int dhd_bus_membytes(dhd_pub_t *dhdp, bool set, uint32 address, uint8 *data, uint size);
385 extern void dhd_print_buf(void *pbuf, int len, int bytes_per_line);
386
387
388 typedef enum cust_gpio_modes {
389         WLAN_RESET_ON,
390         WLAN_RESET_OFF,
391         WLAN_POWER_ON,
392         WLAN_POWER_OFF
393 } cust_gpio_modes_t;
394
395 extern int wl_iw_iscan_set_scan_broadcast_prep(struct net_device *dev, uint flag);
396
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 extern uint wl_msg_level;
408 #endif /* defined(DHD_DEBUG) */
409
410 /* Use interrupts */
411 extern uint dhd_intr;
412
413 /* Use polling */
414 extern uint dhd_poll;
415
416 /* ARP offload agent mode */
417 extern uint dhd_arp_mode;
418
419 /* ARP offload enable */
420 extern uint dhd_arp_enable;
421
422 /* Pkt filte enable control */
423 extern uint dhd_pkt_filter_enable;
424
425 /*  Pkt filter init setup */
426 extern uint dhd_pkt_filter_init;
427
428 /* Pkt filter mode control */
429 extern uint dhd_master_mode;
430
431 /* Roaming mode control */
432 extern uint dhd_roam_disable;
433
434 /* Roaming mode control */
435 extern uint dhd_radio_up;
436
437 /* Initial idletime ticks (may be -1 for immediate idle, 0 for no idle) */
438 extern int dhd_idletime;
439 #define DHD_IDLETIME_TICKS 1
440
441 /* SDIO Drive Strength */
442 extern uint dhd_sdiod_drive_strength;
443
444 /* Override to force tx queueing all the time */
445 extern uint dhd_force_tx_queueing;
446
447 #ifdef SDTEST
448 /* Echo packet generator (SDIO), pkts/s */
449 extern uint dhd_pktgen;
450
451 /* Echo packet len (0 => sawtooth, max 1800) */
452 extern uint dhd_pktgen_len;
453 #define MAX_PKTGEN_LEN 1800
454 #endif
455
456
457 /* optionally set by a module_param_string() */
458 #define MOD_PARAM_PATHLEN       2048
459 extern char fw_path[MOD_PARAM_PATHLEN];
460 extern char nv_path[MOD_PARAM_PATHLEN];
461
462 /* For supporting multiple interfaces */
463 #define DHD_MAX_IFS     16
464 #define DHD_DEL_IF      -0xe
465 #define DHD_BAD_IF      -0xf
466
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_ */