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