/drivers/net/wireless/bcm4329/dhd.h
C Header | 465 lines | 294 code | 85 blank | 86 comment | 15 complexity | f6e473c1057449ad836a60ebde294b10 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
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.4.9 2011/01/14 22:40:45 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 <linux/sched.h>
48#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 int hang_was_sent; /* flag that message was send at least once */
160#ifdef PNO_SUPPORT
161 int pno_enable; /* pno status : "1" is pno enable */
162#endif /* PNO_SUPPORT */
163 int dtim_skip; /* dtim skip , default 0 means wake each dtim */
164
165 /* Pkt filter defination */
166 char * pktfilter[100];
167 int pktfilter_count;
168
169 wl_country_t dhd_cspec; /* Current Locale info */
170 char eventmask[WL_EVENTING_MASK_LEN];
171
172} dhd_pub_t;
173
174#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP)
175
176 #define DHD_PM_RESUME_WAIT_INIT(a) DECLARE_WAIT_QUEUE_HEAD(a);
177 #define _DHD_PM_RESUME_WAIT(a, b) do { \
178 int retry = 0; \
179 smp_mb(); \
180 while (dhd_mmc_suspend && retry++ != b) { \
181 wait_event_interruptible_timeout(a, FALSE, HZ/100); \
182 } \
183 } while (0)
184 #define DHD_PM_RESUME_WAIT(a) _DHD_PM_RESUME_WAIT(a, 200)
185 #define DHD_PM_RESUME_WAIT_FOREVER(a) _DHD_PM_RESUME_WAIT(a, ~0)
186 #define DHD_PM_RESUME_RETURN_ERROR(a) do { if (dhd_mmc_suspend) return a; } while (0)
187 #define DHD_PM_RESUME_RETURN do { if (dhd_mmc_suspend) return; } while (0)
188
189 #define DHD_SPINWAIT_SLEEP_INIT(a) DECLARE_WAIT_QUEUE_HEAD(a);
190 #define SPINWAIT_SLEEP(a, exp, us) do { \
191 uint countdown = (us) + 9999; \
192 while ((exp) && (countdown >= 10000)) { \
193 wait_event_interruptible_timeout(a, FALSE, HZ/100); \
194 countdown -= 10000; \
195 } \
196 } while (0)
197
198#else
199
200 #define DHD_PM_RESUME_WAIT_INIT(a)
201 #define DHD_PM_RESUME_WAIT(a)
202 #define DHD_PM_RESUME_WAIT_FOREVER(a)
203 #define DHD_PM_RESUME_RETURN_ERROR(a)
204 #define DHD_PM_RESUME_RETURN
205
206 #define DHD_SPINWAIT_SLEEP_INIT(a)
207 #define SPINWAIT_SLEEP(a, exp, us) do { \
208 uint countdown = (us) + 9; \
209 while ((exp) && (countdown >= 10)) { \
210 OSL_DELAY(10); \
211 countdown -= 10; \
212 } \
213 } while (0)
214
215#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP) */
216
217#define DHD_IF_VIF 0x01 /* Virtual IF (Hidden from user) */
218
219inline static void NETIF_ADDR_LOCK(struct net_device *dev)
220{
221#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
222 netif_addr_lock_bh(dev);
223#endif
224}
225
226inline static void NETIF_ADDR_UNLOCK(struct net_device *dev)
227{
228#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
229 netif_addr_unlock_bh(dev);
230#endif
231}
232
233/* Wakelock Functions */
234extern int dhd_os_wake_lock(dhd_pub_t *pub);
235extern int dhd_os_wake_unlock(dhd_pub_t *pub);
236extern int dhd_os_wake_lock_timeout(dhd_pub_t *pub);
237extern int dhd_os_wake_lock_timeout_enable(dhd_pub_t *pub);
238
239extern void dhd_os_start_lock(dhd_pub_t *pub);
240extern void dhd_os_start_unlock(dhd_pub_t *pub);
241extern unsigned long dhd_os_spin_lock(dhd_pub_t *pub);
242extern void dhd_os_spin_unlock(dhd_pub_t *pub, unsigned long flags);
243
244typedef struct dhd_if_event {
245 uint8 ifidx;
246 uint8 action;
247 uint8 flags;
248 uint8 bssidx;
249} dhd_if_event_t;
250
251/*
252 * Exported from dhd OS modules (dhd_linux/dhd_ndis)
253 */
254
255/* To allow osl_attach/detach calls from os-independent modules */
256osl_t *dhd_osl_attach(void *pdev, uint bustype);
257void dhd_osl_detach(osl_t *osh);
258
259/* Indication from bus module regarding presence/insertion of dongle.
260 * Return dhd_pub_t pointer, used as handle to OS module in later calls.
261 * Returned structure should have bus and prot pointers filled in.
262 * bus_hdrlen specifies required headroom for bus module header.
263 */
264extern dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen);
265extern int dhd_net_attach(dhd_pub_t *dhdp, int idx);
266
267/* Indication from bus module regarding removal/absence of dongle */
268extern void dhd_detach(dhd_pub_t *dhdp);
269
270/* Indication from bus module to change flow-control state */
271extern void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool on);
272
273extern bool dhd_prec_enq(dhd_pub_t *dhdp, struct pktq *q, void *pkt, int prec);
274
275/* Receive frame for delivery to OS. Callee disposes of rxp. */
276extern void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *rxp, int numpkt);
277
278/* Return pointer to interface name */
279extern char *dhd_ifname(dhd_pub_t *dhdp, int idx);
280
281/* Request scheduling of the bus dpc */
282extern void dhd_sched_dpc(dhd_pub_t *dhdp);
283
284/* Notify tx completion */
285extern void dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success);
286
287/* Query ioctl */
288extern int dhdcdc_query_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf, uint len);
289
290/* OS independent layer functions */
291extern int dhd_os_proto_block(dhd_pub_t * pub);
292extern int dhd_os_proto_unblock(dhd_pub_t * pub);
293extern int dhd_os_ioctl_resp_wait(dhd_pub_t * pub, uint * condition, bool * pending);
294extern int dhd_os_ioctl_resp_wake(dhd_pub_t * pub);
295extern unsigned int dhd_os_get_ioctl_resp_timeout(void);
296extern void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec);
297extern void * dhd_os_open_image(char * filename);
298extern int dhd_os_get_image_block(char * buf, int len, void * image);
299extern void dhd_os_close_image(void * image);
300extern void dhd_os_wd_timer(void *bus, uint wdtick);
301extern void dhd_os_sdlock(dhd_pub_t * pub);
302extern void dhd_os_sdunlock(dhd_pub_t * pub);
303extern void dhd_os_sdlock_txq(dhd_pub_t * pub);
304extern void dhd_os_sdunlock_txq(dhd_pub_t * pub);
305extern void dhd_os_sdlock_rxq(dhd_pub_t * pub);
306extern void dhd_os_sdunlock_rxq(dhd_pub_t * pub);
307extern void dhd_os_sdlock_sndup_rxq(dhd_pub_t * pub);
308extern void dhd_customer_gpio_wlan_ctrl(int onoff);
309extern int dhd_custom_get_mac_address(unsigned char *buf);
310extern void dhd_os_sdunlock_sndup_rxq(dhd_pub_t * pub);
311extern void dhd_os_sdlock_eventq(dhd_pub_t * pub);
312extern void dhd_os_sdunlock_eventq(dhd_pub_t * pub);
313#ifdef DHD_DEBUG
314extern int write_to_file(dhd_pub_t *dhd, uint8 *buf, int size);
315#endif /* DHD_DEBUG */
316#if defined(OOB_INTR_ONLY)
317extern int dhd_customer_oob_irq_map(unsigned long *irq_flags_ptr);
318#endif /* defined(OOB_INTR_ONLY) */
319extern void dhd_os_sdtxlock(dhd_pub_t * pub);
320extern void dhd_os_sdtxunlock(dhd_pub_t * pub);
321
322int setScheduler(struct task_struct *p, int policy, struct sched_param *param);
323
324typedef struct {
325 uint32 limit; /* Expiration time (usec) */
326 uint32 increment; /* Current expiration increment (usec) */
327 uint32 elapsed; /* Current elapsed time (usec) */
328 uint32 tick; /* O/S tick time (usec) */
329} dhd_timeout_t;
330
331extern void dhd_timeout_start(dhd_timeout_t *tmo, uint usec);
332extern int dhd_timeout_expired(dhd_timeout_t *tmo);
333
334extern int dhd_ifname2idx(struct dhd_info *dhd, char *name);
335extern uint8 *dhd_bssidx2bssid(dhd_pub_t *dhd, int idx);
336extern int wl_host_event(struct dhd_info *dhd, int *idx, void *pktdata,
337 wl_event_msg_t *, void **data_ptr);
338extern void wl_event_to_host_order(wl_event_msg_t * evt);
339
340extern void dhd_common_init(void);
341
342extern int dhd_add_if(struct dhd_info *dhd, int ifidx, void *handle,
343 char *name, uint8 *mac_addr, uint32 flags, uint8 bssidx);
344extern void dhd_del_if(struct dhd_info *dhd, int ifidx);
345
346extern void dhd_vif_add(struct dhd_info *dhd, int ifidx, char * name);
347extern void dhd_vif_del(struct dhd_info *dhd, int ifidx);
348
349extern void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx);
350extern void dhd_vif_sendup(struct dhd_info *dhd, int ifidx, uchar *cp, int len);
351
352
353/* Send packet to dongle via data channel */
354extern int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pkt);
355
356/* Send event to host */
357extern void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data);
358extern int dhd_bus_devreset(dhd_pub_t *dhdp, uint8 flag);
359extern uint dhd_bus_status(dhd_pub_t *dhdp);
360extern int dhd_bus_start(dhd_pub_t *dhdp);
361
362extern void print_buf(void *pbuf, int len, int bytes_per_line);
363
364
365typedef enum cust_gpio_modes {
366 WLAN_RESET_ON,
367 WLAN_RESET_OFF,
368 WLAN_POWER_ON,
369 WLAN_POWER_OFF
370} cust_gpio_modes_t;
371
372extern int wl_iw_iscan_set_scan_broadcast_prep(struct net_device *dev, uint flag);
373extern int wl_iw_send_priv_event(struct net_device *dev, char *flag);
374extern int net_os_send_hang_message(struct net_device *dev);
375
376/*
377 * Insmod parameters for debug/test
378 */
379
380/* Watchdog timer interval */
381extern uint dhd_watchdog_ms;
382
383#if defined(DHD_DEBUG)
384/* Console output poll interval */
385extern uint dhd_console_ms;
386#endif /* defined(DHD_DEBUG) */
387
388/* Use interrupts */
389extern uint dhd_intr;
390
391/* Use polling */
392extern uint dhd_poll;
393
394/* ARP offload agent mode */
395extern uint dhd_arp_mode;
396
397/* ARP offload enable */
398extern uint dhd_arp_enable;
399
400/* Pkt filte enable control */
401extern uint dhd_pkt_filter_enable;
402
403/* Pkt filter init setup */
404extern uint dhd_pkt_filter_init;
405
406/* Pkt filter mode control */
407extern uint dhd_master_mode;
408
409/* Roaming mode control */
410extern uint dhd_roam;
411
412/* Roaming mode control */
413extern uint dhd_radio_up;
414
415/* Initial idletime ticks (may be -1 for immediate idle, 0 for no idle) */
416extern int dhd_idletime;
417#define DHD_IDLETIME_TICKS 1
418
419/* SDIO Drive Strength */
420extern uint dhd_sdiod_drive_strength;
421
422/* Override to force tx queueing all the time */
423extern uint dhd_force_tx_queueing;
424
425/* Default KEEP_ALIVE Period is 55 sec to prevent AP from sending Keep Alive probe frame */
426#define KEEP_ALIVE_PERIOD 55000
427#define NULL_PKT_STR "null_pkt"
428
429#ifdef SDTEST
430/* Echo packet generator (SDIO), pkts/s */
431extern uint dhd_pktgen;
432
433/* Echo packet len (0 => sawtooth, max 1800) */
434extern uint dhd_pktgen_len;
435#define MAX_PKTGEN_LEN 1800
436#endif
437
438
439/* optionally set by a module_param_string() */
440#define MOD_PARAM_PATHLEN 2048
441extern char fw_path[MOD_PARAM_PATHLEN];
442extern char nv_path[MOD_PARAM_PATHLEN];
443
444/* For supporting multiple interfaces */
445#define DHD_MAX_IFS 16
446#define DHD_DEL_IF -0xe
447#define DHD_BAD_IF -0xf
448
449
450extern void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar);
451extern void dhd_wait_event_wakeup(dhd_pub_t*dhd);
452
453/* dhd_commn arp offload wrapers */
454extern void dhd_arp_cleanup(dhd_pub_t *dhd);
455int dhd_arp_get_arp_hostip_table(dhd_pub_t *dhd, void *buf, int buflen);
456void dhd_arp_offload_add_ip(dhd_pub_t *dhd, u32 ipaddr);
457
458#define DHD_UNICAST_FILTER_NUM 0
459#define DHD_BROADCAST_FILTER_NUM 1
460#define DHD_MULTICAST4_FILTER_NUM 2
461#define DHD_MULTICAST6_FILTER_NUM 3
462extern int net_os_set_packet_filter(struct net_device *dev, int val);
463extern int net_os_rxfilter_add_remove(struct net_device *dev, int val, int num);
464
465#endif /* _dhd_h_ */