• 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-2009, 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.25 2009/10/27 04:41:56 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 NDIS60
63 #include <wdf.h>
64 #include <WdfMiniport.h>
65 #endif /* NDIS60 */
66 
67 /* Forward decls */
68 struct dhd_bus;
69 struct dhd_prot;
70 struct dhd_info;
71 
72 /* The level of bus communication with the dongle */
73 enum dhd_bus_state {
74 	DHD_BUS_DOWN,		/* Not ready for frame transfers */
75 	DHD_BUS_LOAD,		/* Download access only (CPU reset) */
76 	DHD_BUS_DATA		/* Ready for frame transfers */
77 };
78 
79 enum dhd_bus_wake_state {
80 	WAKE_LOCK_OFF,
81 	WAKE_LOCK_PRIV,
82 	WAKE_LOCK_DPC,
83 	WAKE_LOCK_IOCTL,
84 	WAKE_LOCK_DOWNLOAD,
85 	WAKE_LOCK_TMOUT,
86 	WAKE_LOCK_WATCHDOG,
87 	WAKE_LOCK_LINK_DOWN_TMOUT,
88 	WAKE_LOCK_MAX
89 };
90 enum dhd_prealloc_index {
91 	DHD_PREALLOC_PROT = 0,
92 	DHD_PREALLOC_RXBUF,
93 	DHD_PREALLOC_DATABUF,
94 	DHD_PREALLOC_OSL_BUF
95 };
96 #ifdef DHD_USE_STATIC_BUF
97 extern void * dhd_os_prealloc(int section, unsigned long size);
98 #endif
99 /* Common structure for module and instance linkage */
100 typedef struct dhd_pub {
101 	/* Linkage ponters */
102 	osl_t *osh;		/* OSL handle */
103 	struct dhd_bus *bus;	/* Bus module handle */
104 	struct dhd_prot *prot;	/* Protocol module handle */
105 	struct dhd_info  *info; /* Info module handle */
106 
107 	/* Internal dhd items */
108 	bool up;		/* Driver up/down (to OS) */
109 	bool txoff;		/* Transmit flow-controlled */
110 	bool dongle_reset;  /* TRUE = DEVRESET put dongle into reset */
111 	enum dhd_bus_state busstate;
112 	uint hdrlen;		/* Total DHD header length (proto + bus) */
113 	uint maxctl;		/* Max size rxctl request from proto to bus */
114 	uint rxsz;		/* Rx buffer size bus module should use */
115 	uint8 wme_dp;	/* wme discard priority */
116 
117 	/* Dongle media info */
118 	bool iswl;		/* Dongle-resident driver is wl */
119 	ulong drv_version;	/* Version of dongle-resident driver */
120 	struct ether_addr mac;	/* MAC address obtained from dongle */
121 	dngl_stats_t dstats;	/* Stats for dongle-based data */
122 
123 	/* Additional stats for the bus level */
124 	ulong tx_packets;	/* Data packets sent to dongle */
125 	ulong tx_multicast;	/* Multicast data packets sent to dongle */
126 	ulong tx_errors;	/* Errors in sending data to dongle */
127 	ulong tx_ctlpkts;	/* Control packets sent to dongle */
128 	ulong tx_ctlerrs;	/* Errors sending control frames to dongle */
129 	ulong rx_packets;	/* Packets sent up the network interface */
130 	ulong rx_multicast;	/* Multicast packets sent up the network interface */
131 	ulong rx_errors;	/* Errors processing rx data packets */
132 	ulong rx_ctlpkts;	/* Control frames processed from dongle */
133 	ulong rx_ctlerrs;	/* Errors in processing rx control frames */
134 	ulong rx_dropped;	/* Packets dropped locally (no memory) */
135 	ulong rx_flushed;  /* Packets flushed due to unscheduled sendup thread */
136 	ulong wd_dpc_sched;   /* Number of times dhd dpc scheduled by watchdog timer */
137 
138 	ulong rx_readahead_cnt;	/* Number of packets where header read-ahead was used. */
139 	ulong tx_realloc;	/* Number of tx packets we had to realloc for headroom */
140 	ulong fc_packets;       /* Number of flow control pkts recvd */
141 
142 	/* Last error return */
143 	int bcmerror;
144 	uint tickcnt;
145 
146 	/* Last error from dongle */
147 	int dongle_error;
148 
149 	uint8 country_code[WLC_CNTRY_BUF_SZ];
150 } dhd_pub_t;
151 
152 #ifdef NDIS60
153 
154 typedef struct _wdf_device_info {
155 	dhd_pub_t *dhd;
156 } wdf_device_info_t;
157 
158 WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(wdf_device_info_t, dhd_get_wdf_device_info)
159 
160 
161 #endif /* NDIS60 */
162 
163 	#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP)
164 
165 	#define DHD_PM_RESUME_WAIT_INIT(a) DECLARE_WAIT_QUEUE_HEAD(a);
166 	#define _DHD_PM_RESUME_WAIT(a, b) do {\
167 			int retry = 0; \
168 			while (dhd_mmc_suspend && retry++ != b) { \
169 				wait_event_timeout(a, FALSE, HZ/100); \
170 			} \
171 		} 	while (0)
172 	#define DHD_PM_RESUME_WAIT(a) 			_DHD_PM_RESUME_WAIT(a, 30)
173 	#define DHD_PM_RESUME_WAIT_FOREVER(a) 	_DHD_PM_RESUME_WAIT(a, ~0)
174 	#define DHD_PM_RESUME_RETURN_ERROR(a)	do { if (dhd_mmc_suspend) return a; } while (0)
175 	#define DHD_PM_RESUME_RETURN		do { if (dhd_mmc_suspend) return; } while (0)
176 
177 	#define DHD_SPINWAIT_SLEEP_INIT(a) DECLARE_WAIT_QUEUE_HEAD(a);
178 	#define SPINWAIT_SLEEP(a, exp, us) do { \
179 		uint countdown = (us) + 9; \
180 		while ((exp) && (countdown >= 10)) { \
181 			wait_event_timeout(a, FALSE, HZ/100); \
182 			countdown -= 10; \
183 		} \
184 	} while (0)
185 
186 	#else
187 
188 	#define DHD_PM_RESUME_WAIT_INIT(a)
189 	#define DHD_PM_RESUME_WAIT(a)
190 	#define DHD_PM_RESUME_WAIT_FOREVER(a)
191 	#define DHD_PM_RESUME_RETURN_ERROR(a)
192 	#define DHD_PM_RESUME_RETURN
193 
194 	#define DHD_SPINWAIT_SLEEP_INIT(a)
195 	#define SPINWAIT_SLEEP(a, exp, us)  do { \
196 		uint countdown = (us) + 9; \
197 		while ((exp) && (countdown >= 10)) { \
198 			OSL_DELAY(10);  \
199 			countdown -= 10;  \
200 		} \
201 	} while (0)
202 
203 	#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP) */
204 #define DHD_IF_VIF	0x01	/* Virtual IF (Hidden from user) */
205 
206 /* Wakelock Functions */
207 extern int dhd_os_wake_lock(dhd_pub_t *pub);
208 extern int dhd_os_wake_unlock(dhd_pub_t *pub);
209 extern int dhd_os_wake_lock_timeout(dhd_pub_t *pub);
210 extern int dhd_os_wake_lock_timeout_enable(dhd_pub_t *pub);
211 
212 typedef struct dhd_if_event {
213 	uint8 ifidx;
214 	uint8 action;
215 	uint8 flags;
216 	uint8 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 osl_t *dhd_osl_attach(void *pdev, uint bustype);
225 void dhd_osl_detach(osl_t *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(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen);
233 extern int dhd_net_attach(dhd_pub_t *dhdp, int idx);
234 
235 /* Indication from bus module regarding removal/absence of dongle */
236 extern void dhd_detach(dhd_pub_t *dhdp);
237 
238 /* Indication from bus module to change flow-control state */
239 extern void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool on);
240 
241 extern bool dhd_prec_enq(dhd_pub_t *dhdp, struct pktq *q, void *pkt, int prec);
242 
243 /* Receive frame for delivery to OS.  Callee disposes of rxp. */
244 extern void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *rxp, int numpkt);
245 
246 /* Return pointer to interface name */
247 extern char *dhd_ifname(dhd_pub_t *dhdp, int idx);
248 
249 /* Request scheduling of the bus dpc */
250 extern void dhd_sched_dpc(dhd_pub_t *dhdp);
251 
252 /* Notify tx completion */
253 extern void dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success);
254 
255 /* Query ioctl */
256 extern int  dhdcdc_query_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf, uint len);
257 
258 /* OS independent layer functions */
259 extern int dhd_os_proto_block(dhd_pub_t * pub);
260 extern int dhd_os_proto_unblock(dhd_pub_t * pub);
261 extern int dhd_os_ioctl_resp_wait(dhd_pub_t * pub, uint * condition, bool * pending);
262 extern int dhd_os_ioctl_resp_wake(dhd_pub_t * pub);
263 extern unsigned int dhd_os_get_ioctl_resp_timeout(void);
264 extern void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec);
265 extern void * dhd_os_open_image(char * filename);
266 extern int dhd_os_get_image_block(char * buf, int len, void * image);
267 extern void dhd_os_close_image(void * image);
268 extern void dhd_os_wd_timer(void *bus, uint wdtick);
269 extern void dhd_os_sdlock(dhd_pub_t * pub);
270 extern void dhd_os_sdunlock(dhd_pub_t * pub);
271 extern void dhd_os_sdlock_txq(dhd_pub_t * pub);
272 extern void dhd_os_sdunlock_txq(dhd_pub_t * pub);
273 extern void dhd_os_sdlock_rxq(dhd_pub_t * pub);
274 extern void dhd_os_sdunlock_rxq(dhd_pub_t * pub);
275 extern void dhd_os_sdlock_sndup_rxq(dhd_pub_t * pub);
276 extern void dhd_customer_gpio_wlan_ctrl(int onoff);
277 extern void dhd_os_sdunlock_sndup_rxq(dhd_pub_t * pub);
278 #if defined(OOB_INTR_ONLY)
279 extern int dhd_customer_oob_irq_map(void);
280 #endif /* defined(OOB_INTR_ONLY) */
281 extern void dhd_os_sdtxlock(dhd_pub_t * pub);
282 extern void dhd_os_sdtxunlock(dhd_pub_t * pub);
283 
284 int setScheduler(struct task_struct *p, int policy, struct sched_param *param);
285 
286 typedef struct {
287 	uint32 limit;		/* Expiration time (usec) */
288 	uint32 increment;	/* Current expiration increment (usec) */
289 	uint32 elapsed;		/* Current elapsed time (usec) */
290 	uint32 tick;		/* O/S tick time (usec) */
291 } dhd_timeout_t;
292 
293 extern void dhd_timeout_start(dhd_timeout_t *tmo, uint usec);
294 extern int dhd_timeout_expired(dhd_timeout_t *tmo);
295 
296 extern int dhd_ifname2idx(struct dhd_info *dhd, char *name);
297 extern uint8 *dhd_bssidx2bssid(dhd_pub_t *dhd, int idx);
298 extern int wl_host_event(struct dhd_info *dhd, int *idx, void *pktdata,
299                          wl_event_msg_t *, void **data_ptr);
300 extern void wl_event_to_host_order(wl_event_msg_t * evt);
301 
302 extern void dhd_common_init(void);
303 
304 extern int dhd_add_if(struct dhd_info *dhd, int ifidx, void *handle,
305 	char *name, uint8 *mac_addr, uint32 flags, uint8 bssidx);
306 extern void dhd_del_if(struct dhd_info *dhd, int ifidx);
307 
308 extern void dhd_vif_add(struct dhd_info *dhd, int ifidx, char * name);
309 extern void dhd_vif_del(struct dhd_info *dhd, int ifidx);
310 
311 extern void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx);
312 extern void dhd_vif_sendup(struct dhd_info *dhd, int ifidx, uchar *cp, int len);
313 
314 
315 /* Send packet to dongle via data channel */
316 extern int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pkt);
317 
318 /* Send event to host */
319 extern void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data);
320 extern int dhd_bus_devreset(dhd_pub_t *dhdp, uint8 flag);
321 extern uint dhd_bus_status(dhd_pub_t *dhdp);
322 extern int  dhd_bus_start(dhd_pub_t *dhdp);
323 
324 
325 
326 typedef enum cust_gpio_modes {
327 	WLAN_RESET_ON,
328 	WLAN_RESET_OFF,
329 	WLAN_POWER_ON,
330 	WLAN_POWER_OFF
331 } cust_gpio_modes_t;
332 /*
333  * Insmod parameters for debug/test
334  */
335 
336 /* Watchdog timer interval */
337 extern uint dhd_watchdog_ms;
338 
339 
340 /* Use interrupts */
341 extern uint dhd_intr;
342 
343 /* Use polling */
344 extern uint dhd_poll;
345 
346 /* Initial idletime ticks (may be -1 for immediate idle, 0 for no idle) */
347 extern int dhd_idletime;
348 #define DHD_IDLETIME_TICKS 1
349 
350 /* SDIO Drive Strength */
351 extern uint dhd_sdiod_drive_strength;
352 
353 /* Override to force tx queueing all the time */
354 extern uint dhd_force_tx_queueing;
355 
356 #ifdef SDTEST
357 /* Echo packet generator (SDIO), pkts/s */
358 extern uint dhd_pktgen;
359 
360 /* Echo packet len (0 => sawtooth, max 1800) */
361 extern uint dhd_pktgen_len;
362 #define MAX_PKTGEN_LEN 1800
363 #endif
364 
365 
366 /* optionally set by a module_param_string() */
367 #define MOD_PARAM_PATHLEN	2048
368 extern char fw_path[MOD_PARAM_PATHLEN];
369 extern char nv_path[MOD_PARAM_PATHLEN];
370 
371 /* For supporting multiple interfaces */
372 #define DHD_MAX_IFS	16
373 #define DHD_DEL_IF	-0xe
374 #define DHD_BAD_IF	-0xf
375 
376 #ifdef APSTA_PINGTEST
377 #define MAX_GUEST 8
378 #endif
379 
380 extern void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar);
381 extern void dhd_wait_event_wakeup(dhd_pub_t*dhd);
382 
383 #endif /* _dhd_h_ */
384