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