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