blob: 1ddf1ff61e7052cd36613dfd0e5c18296fd5d871 [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 *
27 * $Id: dhd.h,v 1.32.4.7.2.4.14.49.4.7 2010/11/12 22:48:36 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 */
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
167 uint8 country_code[WLC_CNTRY_BUF_SZ];
168 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
217/* Wakelock Functions */
218extern int dhd_os_wake_lock(dhd_pub_t *pub);
219extern int dhd_os_wake_unlock(dhd_pub_t *pub);
220extern int dhd_os_wake_lock_timeout(dhd_pub_t *pub);
221extern int dhd_os_wake_lock_timeout_enable(dhd_pub_t *pub);
222
223extern void dhd_os_start_lock(dhd_pub_t *pub);
224extern void dhd_os_start_unlock(dhd_pub_t *pub);
225extern unsigned long dhd_os_spin_lock(dhd_pub_t *pub);
226extern void dhd_os_spin_unlock(dhd_pub_t *pub, unsigned long flags);
227
228typedef struct dhd_if_event {
229 uint8 ifidx;
230 uint8 action;
231 uint8 flags;
232 uint8 bssidx;
233} dhd_if_event_t;
234
235/*
236 * Exported from dhd OS modules (dhd_linux/dhd_ndis)
237 */
238
239/* To allow osl_attach/detach calls from os-independent modules */
240osl_t *dhd_osl_attach(void *pdev, uint bustype);
241void dhd_osl_detach(osl_t *osh);
242
243/* Indication from bus module regarding presence/insertion of dongle.
244 * Return dhd_pub_t pointer, used as handle to OS module in later calls.
245 * Returned structure should have bus and prot pointers filled in.
246 * bus_hdrlen specifies required headroom for bus module header.
247 */
248extern dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen);
249extern int dhd_net_attach(dhd_pub_t *dhdp, int idx);
250
251/* Indication from bus module regarding removal/absence of dongle */
252extern void dhd_detach(dhd_pub_t *dhdp);
253
254/* Indication from bus module to change flow-control state */
255extern void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool on);
256
257extern bool dhd_prec_enq(dhd_pub_t *dhdp, struct pktq *q, void *pkt, int prec);
258
259/* Receive frame for delivery to OS. Callee disposes of rxp. */
260extern void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *rxp, int numpkt);
261
262/* Return pointer to interface name */
263extern char *dhd_ifname(dhd_pub_t *dhdp, int idx);
264
265/* Request scheduling of the bus dpc */
266extern void dhd_sched_dpc(dhd_pub_t *dhdp);
267
268/* Notify tx completion */
269extern void dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success);
270
271/* Query ioctl */
272extern int dhdcdc_query_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf, uint len);
273
274/* OS independent layer functions */
275extern int dhd_os_proto_block(dhd_pub_t * pub);
276extern int dhd_os_proto_unblock(dhd_pub_t * pub);
277extern int dhd_os_ioctl_resp_wait(dhd_pub_t * pub, uint * condition, bool * pending);
278extern int dhd_os_ioctl_resp_wake(dhd_pub_t * pub);
279extern unsigned int dhd_os_get_ioctl_resp_timeout(void);
280extern void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec);
281extern void * dhd_os_open_image(char * filename);
282extern int dhd_os_get_image_block(char * buf, int len, void * image);
283extern void dhd_os_close_image(void * image);
284extern void dhd_os_wd_timer(void *bus, uint wdtick);
285extern void dhd_os_sdlock(dhd_pub_t * pub);
286extern void dhd_os_sdunlock(dhd_pub_t * pub);
287extern void dhd_os_sdlock_txq(dhd_pub_t * pub);
288extern void dhd_os_sdunlock_txq(dhd_pub_t * pub);
289extern void dhd_os_sdlock_rxq(dhd_pub_t * pub);
290extern void dhd_os_sdunlock_rxq(dhd_pub_t * pub);
291extern void dhd_os_sdlock_sndup_rxq(dhd_pub_t * pub);
292extern void dhd_customer_gpio_wlan_ctrl(int onoff);
293extern int dhd_custom_get_mac_address(unsigned char *buf);
294extern void dhd_os_sdunlock_sndup_rxq(dhd_pub_t * pub);
295extern void dhd_os_sdlock_eventq(dhd_pub_t * pub);
296extern void dhd_os_sdunlock_eventq(dhd_pub_t * pub);
297#ifdef DHD_DEBUG
298extern int write_to_file(dhd_pub_t *dhd, uint8 *buf, int size);
299#endif /* DHD_DEBUG */
300#if defined(OOB_INTR_ONLY)
301extern int dhd_customer_oob_irq_map(unsigned long *irq_flags_ptr);
302#endif /* defined(OOB_INTR_ONLY) */
303extern void dhd_os_sdtxlock(dhd_pub_t * pub);
304extern void dhd_os_sdtxunlock(dhd_pub_t * pub);
305
306int setScheduler(struct task_struct *p, int policy, struct sched_param *param);
307
308typedef struct {
309 uint32 limit; /* Expiration time (usec) */
310 uint32 increment; /* Current expiration increment (usec) */
311 uint32 elapsed; /* Current elapsed time (usec) */
312 uint32 tick; /* O/S tick time (usec) */
313} dhd_timeout_t;
314
315extern void dhd_timeout_start(dhd_timeout_t *tmo, uint usec);
316extern int dhd_timeout_expired(dhd_timeout_t *tmo);
317
318extern int dhd_ifname2idx(struct dhd_info *dhd, char *name);
319extern uint8 *dhd_bssidx2bssid(dhd_pub_t *dhd, int idx);
320extern int wl_host_event(struct dhd_info *dhd, int *idx, void *pktdata,
321 wl_event_msg_t *, void **data_ptr);
322extern void wl_event_to_host_order(wl_event_msg_t * evt);
323
324extern void dhd_common_init(void);
325
326extern int dhd_add_if(struct dhd_info *dhd, int ifidx, void *handle,
327 char *name, uint8 *mac_addr, uint32 flags, uint8 bssidx);
328extern void dhd_del_if(struct dhd_info *dhd, int ifidx);
329
330extern void dhd_vif_add(struct dhd_info *dhd, int ifidx, char * name);
331extern void dhd_vif_del(struct dhd_info *dhd, int ifidx);
332
333extern void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx);
334extern void dhd_vif_sendup(struct dhd_info *dhd, int ifidx, uchar *cp, int len);
335
336
337/* Send packet to dongle via data channel */
338extern int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pkt);
339
340/* Send event to host */
341extern void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data);
342extern int dhd_bus_devreset(dhd_pub_t *dhdp, uint8 flag);
343extern uint dhd_bus_status(dhd_pub_t *dhdp);
344extern int dhd_bus_start(dhd_pub_t *dhdp);
345
346extern void print_buf(void *pbuf, int len, int bytes_per_line);
347
348
349typedef enum cust_gpio_modes {
350 WLAN_RESET_ON,
351 WLAN_RESET_OFF,
352 WLAN_POWER_ON,
353 WLAN_POWER_OFF
354} cust_gpio_modes_t;
355
356extern int wl_iw_iscan_set_scan_broadcast_prep(struct net_device *dev, uint flag);
357extern int wl_iw_send_priv_event(struct net_device *dev, char *flag);
358extern int net_os_send_hang_message(struct net_device *dev);
359
360/*
361 * Insmod parameters for debug/test
362 */
363
364/* Watchdog timer interval */
365extern uint dhd_watchdog_ms;
366
367#if defined(DHD_DEBUG)
368/* Console output poll interval */
369extern uint dhd_console_ms;
370#endif /* defined(DHD_DEBUG) */
371
372/* Use interrupts */
373extern uint dhd_intr;
374
375/* Use polling */
376extern uint dhd_poll;
377
378/* ARP offload agent mode */
379extern uint dhd_arp_mode;
380
381/* ARP offload enable */
382extern uint dhd_arp_enable;
383
384/* Pkt filte enable control */
385extern uint dhd_pkt_filter_enable;
386
387/* Pkt filter init setup */
388extern uint dhd_pkt_filter_init;
389
390/* Pkt filter mode control */
391extern uint dhd_master_mode;
392
393/* Roaming mode control */
394extern uint dhd_roam;
395
396/* Roaming mode control */
397extern uint dhd_radio_up;
398
399/* Initial idletime ticks (may be -1 for immediate idle, 0 for no idle) */
400extern int dhd_idletime;
401#define DHD_IDLETIME_TICKS 1
402
403/* SDIO Drive Strength */
404extern uint dhd_sdiod_drive_strength;
405
406/* Override to force tx queueing all the time */
407extern uint dhd_force_tx_queueing;
408
409/* Default KEEP_ALIVE Period is 55 sec to prevent AP from sending Keep Alive probe frame */
410#define KEEP_ALIVE_PERIOD 55000
411#define NULL_PKT_STR "null_pkt"
412
413#ifdef SDTEST
414/* Echo packet generator (SDIO), pkts/s */
415extern uint dhd_pktgen;
416
417/* Echo packet len (0 => sawtooth, max 1800) */
418extern uint dhd_pktgen_len;
419#define MAX_PKTGEN_LEN 1800
420#endif
421
422
423/* optionally set by a module_param_string() */
424#define MOD_PARAM_PATHLEN 2048
425extern char fw_path[MOD_PARAM_PATHLEN];
426extern char nv_path[MOD_PARAM_PATHLEN];
427
428/* For supporting multiple interfaces */
429#define DHD_MAX_IFS 16
430#define DHD_DEL_IF -0xe
431#define DHD_BAD_IF -0xf
432
433
434extern void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar);
435extern void dhd_wait_event_wakeup(dhd_pub_t*dhd);
436
437#endif /* _dhd_h_ */