Staging: brcm80211: s/ulong/unsigned long/
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / brcm80211 / brcmfmac / dhd.h
blobbcbb2f12b3330d7a17fbc5fe04dd6974f7d440b5
1 /*
2 * Copyright (c) 2010 Broadcom Corporation
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.
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.
17 /****************
18 * Common types *
21 #ifndef _dhd_h_
22 #define _dhd_h_
24 #if defined(LINUX)
25 #include <linux/sched.h>
26 #include <linux/init.h>
27 #include <linux/kernel.h>
28 #include <linux/slab.h>
29 #include <linux/skbuff.h>
30 #include <linux/netdevice.h>
31 #include <linux/etherdevice.h>
32 #include <linux/random.h>
33 #include <linux/spinlock.h>
34 #include <linux/ethtool.h>
35 #include <asm/uaccess.h>
36 #include <asm/unaligned.h>
37 #if defined(CONFIG_HAS_WAKELOCK)
38 #include <linux/wakelock.h>
39 #endif /* defined (CONFIG_HAS_WAKELOCK) */
40 /* The kernel threading is sdio-specific */
41 #else /* LINUX */
42 #define ENOMEM 1
43 #define EFAULT 2
44 #define EINVAL 3
45 #define EIO 4
46 #define ETIMEDOUT 5
47 #define ERESTARTSYS 6
48 #endif /* LINUX */
50 #include <wlioctl.h>
52 /* Forward decls */
53 struct dhd_bus;
54 struct dhd_prot;
55 struct dhd_info;
57 /* The level of bus communication with the dongle */
58 enum dhd_bus_state {
59 DHD_BUS_DOWN, /* Not ready for frame transfers */
60 DHD_BUS_LOAD, /* Download access only (CPU reset) */
61 DHD_BUS_DATA /* Ready for frame transfers */
64 enum dhd_bus_wake_state {
65 WAKE_LOCK_OFF,
66 WAKE_LOCK_PRIV,
67 WAKE_LOCK_DPC,
68 WAKE_LOCK_IOCTL,
69 WAKE_LOCK_DOWNLOAD,
70 WAKE_LOCK_TMOUT,
71 WAKE_LOCK_WATCHDOG,
72 WAKE_LOCK_LINK_DOWN_TMOUT,
73 WAKE_LOCK_PNO_FIND_TMOUT,
74 WAKE_LOCK_SOFTAP_SET,
75 WAKE_LOCK_SOFTAP_STOP,
76 WAKE_LOCK_SOFTAP_START,
77 WAKE_LOCK_MAX
79 enum dhd_prealloc_index {
80 DHD_PREALLOC_PROT = 0,
81 DHD_PREALLOC_RXBUF,
82 DHD_PREALLOC_DATABUF,
83 DHD_PREALLOC_OSL_BUF
85 #ifdef DHD_USE_STATIC_BUF
86 extern void *dhd_os_prealloc(int section, unsigned long size);
87 #endif
88 /* Common structure for module and instance linkage */
89 typedef struct dhd_pub {
90 /* Linkage ponters */
91 osl_t *osh; /* OSL handle */
92 struct dhd_bus *bus; /* Bus module handle */
93 struct dhd_prot *prot; /* Protocol module handle */
94 struct dhd_info *info; /* Info module handle */
96 /* Internal dhd items */
97 bool up; /* Driver up/down (to OS) */
98 bool txoff; /* Transmit flow-controlled */
99 bool dongle_reset; /* TRUE = DEVRESET put dongle into reset */
100 enum dhd_bus_state busstate;
101 uint hdrlen; /* Total DHD header length (proto + bus) */
102 uint maxctl; /* Max size rxctl request from proto to bus */
103 uint rxsz; /* Rx buffer size bus module should use */
104 u8 wme_dp; /* wme discard priority */
106 /* Dongle media info */
107 bool iswl; /* Dongle-resident driver is wl */
108 unsigned long drv_version; /* Version of dongle-resident driver */
109 struct ether_addr mac; /* MAC address obtained from dongle */
110 dngl_stats_t dstats; /* Stats for dongle-based data */
112 /* Additional stats for the bus level */
113 unsigned long tx_packets; /* Data packets sent to dongle */
114 unsigned long tx_multicast; /* Multicast data packets sent to dongle */
115 unsigned long tx_errors; /* Errors in sending data to dongle */
116 unsigned long tx_ctlpkts; /* Control packets sent to dongle */
117 unsigned long tx_ctlerrs; /* Errors sending control frames to dongle */
118 unsigned long rx_packets; /* Packets sent up the network interface */
119 unsigned long rx_multicast; /* Multicast packets sent up the network
120 interface */
121 unsigned long rx_errors; /* Errors processing rx data packets */
122 unsigned long rx_ctlpkts; /* Control frames processed from dongle */
123 unsigned long rx_ctlerrs; /* Errors in processing rx control frames */
124 unsigned long rx_dropped; /* Packets dropped locally (no memory) */
125 unsigned long rx_flushed; /* Packets flushed due to
126 unscheduled sendup thread */
127 unsigned long wd_dpc_sched; /* Number of times dhd dpc scheduled by
128 watchdog timer */
130 unsigned long rx_readahead_cnt; /* Number of packets where header read-ahead
131 was used. */
132 unsigned long tx_realloc; /* Number of tx packets we had to realloc for
133 headroom */
134 unsigned long fc_packets; /* Number of flow control pkts recvd */
136 /* Last error return */
137 int bcmerror;
138 uint tickcnt;
140 /* Last error from dongle */
141 int dongle_error;
143 /* Suspend disable flag flag */
144 int suspend_disable_flag; /* "1" to disable all extra powersaving
145 during suspend */
146 int in_suspend; /* flag set to 1 when early suspend called */
147 #ifdef PNO_SUPPORT
148 int pno_enable; /* pno status : "1" is pno enable */
149 #endif /* PNO_SUPPORT */
150 int dtim_skip; /* dtim skip , default 0 means wake each dtim */
152 /* Pkt filter defination */
153 char *pktfilter[100];
154 int pktfilter_count;
156 u8 country_code[WLC_CNTRY_BUF_SZ];
157 char eventmask[WL_EVENTING_MASK_LEN];
159 #if defined(CONFIG_HAS_WAKELOCK)
160 struct wake_lock wakelock[WAKE_LOCK_MAX];
161 #endif /* defined (CONFIG_HAS_WAKELOCK) */
162 } dhd_pub_t;
164 #if defined(CONFIG_PM_SLEEP)
166 #define DHD_PM_RESUME_WAIT_INIT(a) DECLARE_WAIT_QUEUE_HEAD(a);
167 #define _DHD_PM_RESUME_WAIT(a, b) do {\
168 int retry = 0; \
169 while (dhd_mmc_suspend && retry++ != b) { \
170 wait_event_timeout(a, FALSE, HZ/100); \
172 } while (0)
173 #define DHD_PM_RESUME_WAIT(a) _DHD_PM_RESUME_WAIT(a, 30)
174 #define DHD_PM_RESUME_WAIT_FOREVER(a) _DHD_PM_RESUME_WAIT(a, ~0)
175 #define DHD_PM_RESUME_RETURN_ERROR(a) \
176 do { if (dhd_mmc_suspend) return a; } while (0)
177 #define DHD_PM_RESUME_RETURN do { if (dhd_mmc_suspend) return; } while (0)
179 #define DHD_SPINWAIT_SLEEP_INIT(a) DECLARE_WAIT_QUEUE_HEAD(a);
180 #define SPINWAIT_SLEEP(a, exp, us) do { \
181 uint countdown = (us) + 9999; \
182 while ((exp) && (countdown >= 10000)) { \
183 wait_event_timeout(a, FALSE, HZ/100); \
184 countdown -= 10000; \
186 } while (0)
188 #else
190 #define DHD_PM_RESUME_WAIT_INIT(a)
191 #define DHD_PM_RESUME_WAIT(a)
192 #define DHD_PM_RESUME_WAIT_FOREVER(a)
193 #define DHD_PM_RESUME_RETURN_ERROR(a)
194 #define DHD_PM_RESUME_RETURN
196 #define DHD_SPINWAIT_SLEEP_INIT(a)
197 #define SPINWAIT_SLEEP(a, exp, us) do { \
198 uint countdown = (us) + 9; \
199 while ((exp) && (countdown >= 10)) { \
200 OSL_DELAY(10); \
201 countdown -= 10; \
203 } while (0)
205 #endif /* defined(CONFIG_PM_SLEEP) */
206 #define DHD_IF_VIF 0x01 /* Virtual IF (Hidden from user) */
208 static inline void MUTEX_LOCK_INIT(dhd_pub_t *dhdp)
212 static inline void MUTEX_LOCK(dhd_pub_t *dhdp)
216 static inline void MUTEX_UNLOCK(dhd_pub_t *dhdp)
220 static inline void MUTEX_LOCK_SOFTAP_SET_INIT(dhd_pub_t *dhdp)
224 static inline void MUTEX_LOCK_SOFTAP_SET(dhd_pub_t *dhdp)
228 static inline void MUTEX_UNLOCK_SOFTAP_SET(dhd_pub_t *dhdp)
232 static inline void MUTEX_LOCK_WL_SCAN_SET_INIT(void)
236 static inline void MUTEX_LOCK_WL_SCAN_SET(void)
240 static inline void MUTEX_UNLOCK_WL_SCAN_SET(void)
244 static inline void WAKE_LOCK_INIT(dhd_pub_t *dhdp, int index, char *y)
246 #if defined(CONFIG_HAS_WAKELOCK)
247 wake_lock_init(&dhdp->wakelock[index], WAKE_LOCK_SUSPEND, y);
248 #endif /* defined (CONFIG_HAS_WAKELOCK) */
251 static inline void WAKE_LOCK(dhd_pub_t *dhdp, int index)
253 #if defined(CONFIG_HAS_WAKELOCK)
254 wake_lock(&dhdp->wakelock[index]);
255 #endif /* defined (CONFIG_HAS_WAKELOCK) */
258 static inline void WAKE_UNLOCK(dhd_pub_t *dhdp, int index)
260 #if defined(CONFIG_HAS_WAKELOCK)
261 wake_unlock(&dhdp->wakelock[index]);
262 #endif /* defined (CONFIG_HAS_WAKELOCK) */
265 static inline void WAKE_LOCK_TIMEOUT(dhd_pub_t *dhdp, int index, long time)
267 #if defined(CONFIG_HAS_WAKELOCK)
268 wake_lock_timeout(&dhdp->wakelock[index], time);
269 #endif /* defined (CONFIG_HAS_WAKELOCK) */
272 static inline void WAKE_LOCK_DESTROY(dhd_pub_t *dhdp, int index)
274 #if defined(CONFIG_HAS_WAKELOCK)
275 wake_lock_destroy(&dhdp->wakelock[index]);
276 #endif /* defined (CONFIG_HAS_WAKELOCK) */
279 typedef struct dhd_if_event {
280 u8 ifidx;
281 u8 action;
282 u8 flags;
283 u8 bssidx;
284 } dhd_if_event_t;
287 * Exported from dhd OS modules (dhd_linux/dhd_ndis)
290 /* To allow osl_attach/detach calls from os-independent modules */
291 osl_t *dhd_osl_attach(void *pdev, uint bustype);
292 void dhd_osl_detach(osl_t *osh);
294 /* Indication from bus module regarding presence/insertion of dongle.
295 * Return dhd_pub_t pointer, used as handle to OS module in later calls.
296 * Returned structure should have bus and prot pointers filled in.
297 * bus_hdrlen specifies required headroom for bus module header.
299 extern dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen);
300 extern int dhd_net_attach(dhd_pub_t *dhdp, int idx);
302 /* Indication from bus module regarding removal/absence of dongle */
303 extern void dhd_detach(dhd_pub_t *dhdp);
305 /* Indication from bus module to change flow-control state */
306 extern void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool on);
308 extern bool dhd_prec_enq(dhd_pub_t *dhdp, struct pktq *q, void *pkt, int prec);
310 /* Receive frame for delivery to OS. Callee disposes of rxp. */
311 extern void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *rxp, int numpkt);
313 /* Return pointer to interface name */
314 extern char *dhd_ifname(dhd_pub_t *dhdp, int idx);
316 /* Request scheduling of the bus dpc */
317 extern void dhd_sched_dpc(dhd_pub_t *dhdp);
319 /* Notify tx completion */
320 extern void dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success);
322 /* Query ioctl */
323 extern int dhdcdc_query_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf,
324 uint len);
326 /* OS independent layer functions */
327 extern int dhd_os_proto_block(dhd_pub_t *pub);
328 extern int dhd_os_proto_unblock(dhd_pub_t *pub);
329 extern int dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition,
330 bool *pending);
331 extern int dhd_os_ioctl_resp_wake(dhd_pub_t *pub);
332 extern unsigned int dhd_os_get_ioctl_resp_timeout(void);
333 extern void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec);
334 extern void *dhd_os_open_image(char *filename);
335 extern int dhd_os_get_image_block(char *buf, int len, void *image);
336 extern void dhd_os_close_image(void *image);
337 extern void dhd_os_wd_timer(void *bus, uint wdtick);
338 extern void dhd_os_sdlock(dhd_pub_t *pub);
339 extern void dhd_os_sdunlock(dhd_pub_t *pub);
340 extern void dhd_os_sdlock_txq(dhd_pub_t *pub);
341 extern void dhd_os_sdunlock_txq(dhd_pub_t *pub);
342 extern void dhd_os_sdlock_rxq(dhd_pub_t *pub);
343 extern void dhd_os_sdunlock_rxq(dhd_pub_t *pub);
344 extern void dhd_os_sdlock_sndup_rxq(dhd_pub_t *pub);
345 extern void dhd_customer_gpio_wlan_ctrl(int onoff);
346 extern int dhd_custom_get_mac_address(unsigned char *buf);
347 extern void dhd_os_sdunlock_sndup_rxq(dhd_pub_t *pub);
348 extern void dhd_os_sdlock_eventq(dhd_pub_t *pub);
349 extern void dhd_os_sdunlock_eventq(dhd_pub_t *pub);
350 #ifdef DHD_DEBUG
351 extern int write_to_file(dhd_pub_t *dhd, u8 *buf, int size);
352 #endif /* DHD_DEBUG */
353 #if defined(OOB_INTR_ONLY)
354 extern int dhd_customer_oob_irq_map(unsigned long *irq_flags_ptr);
355 #endif /* defined(OOB_INTR_ONLY) */
356 extern void dhd_os_sdtxlock(dhd_pub_t *pub);
357 extern void dhd_os_sdtxunlock(dhd_pub_t *pub);
359 int setScheduler(struct task_struct *p, int policy, struct sched_param *param);
361 typedef struct {
362 uint32 limit; /* Expiration time (usec) */
363 uint32 increment; /* Current expiration increment (usec) */
364 uint32 elapsed; /* Current elapsed time (usec) */
365 uint32 tick; /* O/S tick time (usec) */
366 } dhd_timeout_t;
368 extern void dhd_timeout_start(dhd_timeout_t *tmo, uint usec);
369 extern int dhd_timeout_expired(dhd_timeout_t *tmo);
371 extern int dhd_ifname2idx(struct dhd_info *dhd, char *name);
372 extern u8 *dhd_bssidx2bssid(dhd_pub_t *dhd, int idx);
373 extern int wl_host_event(struct dhd_info *dhd, int *idx, void *pktdata,
374 wl_event_msg_t *, void **data_ptr);
375 extern void wl_event_to_host_order(wl_event_msg_t *evt);
377 extern void dhd_common_init(void);
379 extern int dhd_add_if(struct dhd_info *dhd, int ifidx, void *handle,
380 char *name, u8 *mac_addr, uint32 flags, u8 bssidx);
381 extern void dhd_del_if(struct dhd_info *dhd, int ifidx);
383 extern void dhd_vif_add(struct dhd_info *dhd, int ifidx, char *name);
384 extern void dhd_vif_del(struct dhd_info *dhd, int ifidx);
386 extern void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx);
387 extern void dhd_vif_sendup(struct dhd_info *dhd, int ifidx, unsigned char * cp,
388 int len);
390 /* Send packet to dongle via data channel */
391 extern int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pkt);
393 /* Send event to host */
394 extern void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event,
395 void *data);
396 extern int dhd_bus_devreset(dhd_pub_t *dhdp, u8 flag);
397 extern uint dhd_bus_status(dhd_pub_t *dhdp);
398 extern int dhd_bus_start(dhd_pub_t *dhdp);
400 extern void print_buf(void *pbuf, int len, int bytes_per_line);
402 typedef enum cust_gpio_modes {
403 WLAN_RESET_ON,
404 WLAN_RESET_OFF,
405 WLAN_POWER_ON,
406 WLAN_POWER_OFF
407 } cust_gpio_modes_t;
409 * Insmod parameters for debug/test
412 /* Watchdog timer interval */
413 extern uint dhd_watchdog_ms;
415 #if defined(DHD_DEBUG)
416 /* Console output poll interval */
417 extern uint dhd_console_ms;
418 #endif /* defined(DHD_DEBUG) */
420 /* Use interrupts */
421 extern uint dhd_intr;
423 /* Use polling */
424 extern uint dhd_poll;
426 /* ARP offload agent mode */
427 extern uint dhd_arp_mode;
429 /* ARP offload enable */
430 extern uint dhd_arp_enable;
432 /* Pkt filte enable control */
433 extern uint dhd_pkt_filter_enable;
435 /* Pkt filter init setup */
436 extern uint dhd_pkt_filter_init;
438 /* Pkt filter mode control */
439 extern uint dhd_master_mode;
441 /* Roaming mode control */
442 extern uint dhd_roam;
444 /* Roaming mode control */
445 extern uint dhd_radio_up;
447 /* Initial idletime ticks (may be -1 for immediate idle, 0 for no idle) */
448 extern int dhd_idletime;
449 #define DHD_IDLETIME_TICKS 1
451 /* SDIO Drive Strength */
452 extern uint dhd_sdiod_drive_strength;
454 /* Override to force tx queueing all the time */
455 extern uint dhd_force_tx_queueing;
457 #ifdef SDTEST
458 /* Echo packet generator (SDIO), pkts/s */
459 extern uint dhd_pktgen;
461 /* Echo packet len (0 => sawtooth, max 1800) */
462 extern uint dhd_pktgen_len;
463 #define MAX_PKTGEN_LEN 1800
464 #endif
466 /* optionally set by a module_param_string() */
467 #define MOD_PARAM_PATHLEN 2048
468 extern char fw_path[MOD_PARAM_PATHLEN];
469 extern char nv_path[MOD_PARAM_PATHLEN];
471 /* For supporting multiple interfaces */
472 #define DHD_MAX_IFS 16
473 #define DHD_DEL_IF -0xe
474 #define DHD_BAD_IF -0xf
476 extern void dhd_wait_for_event(dhd_pub_t *dhd, bool * lockvar);
477 extern void dhd_wait_event_wakeup(dhd_pub_t *dhd);
479 #endif /* _dhd_h_ */