2 * Header file describing the internal (inter-module) DHD interfaces.
4 * Provides type definitions and function prototypes used to link the
5 * DHD OS, bus, and protocol modules.
7 * Copyright (C) 1999-2010, Broadcom Corporation
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:
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.
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.
27 * $Id: dhd.h,v 1.32.4.7.2.4.14.49.4.9 2011/01/14 22:40:45 Exp $
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>
50 /* The kernel threading is sdio-specific */
63 #ifndef DHD_DEBUG_TRAP
64 #define DHD_DEBUG_TRAP
73 /* The level of bus communication with the dongle */
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 */
80 enum dhd_bus_wake_state {
88 WAKE_LOCK_LINK_DOWN_TMOUT,
89 WAKE_LOCK_PNO_FIND_TMOUT,
91 WAKE_LOCK_SOFTAP_STOP,
92 WAKE_LOCK_SOFTAP_START,
93 WAKE_LOCK_SOFTAP_THREAD,
96 enum dhd_prealloc_index {
97 DHD_PREALLOC_PROT = 0,
102 #ifdef DHD_USE_STATIC_BUF
103 extern void * dhd_os_prealloc(int section, unsigned long size);
105 /* Common structure for module and instance linkage */
106 typedef 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 */
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 */
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 */
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 */
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 */
148 /* Last error return */
152 /* Last error from dongle */
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 */
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 */
163 /* Pkt filter defination */
164 char * pktfilter[100];
167 wl_country_t dhd_cspec; /* Current Locale info */
168 char eventmask[WL_EVENTING_MASK_LEN];
172 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP)
174 #define DHD_PM_RESUME_WAIT_INIT(a) DECLARE_WAIT_QUEUE_HEAD(a);
175 #define _DHD_PM_RESUME_WAIT(a, b) do { \
178 while (dhd_mmc_suspend && retry++ != b) { \
179 wait_event_interruptible_timeout(a, FALSE, HZ/100); \
182 #define DHD_PM_RESUME_WAIT(a) _DHD_PM_RESUME_WAIT(a, 200)
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)
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; \
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
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)) { \
213 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP) */
215 #define DHD_IF_VIF 0x01 /* Virtual IF (Hidden from user) */
217 inline static void NETIF_ADDR_LOCK(struct net_device *dev)
219 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
220 netif_addr_lock_bh(dev);
224 inline static void NETIF_ADDR_UNLOCK(struct net_device *dev)
226 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29))
227 netif_addr_unlock_bh(dev);
231 /* Wakelock Functions */
232 extern int dhd_os_wake_lock(dhd_pub_t *pub);
233 extern int dhd_os_wake_unlock(dhd_pub_t *pub);
234 extern int dhd_os_wake_lock_timeout(dhd_pub_t *pub);
235 extern int dhd_os_wake_lock_timeout_enable(dhd_pub_t *pub);
237 extern void dhd_os_start_lock(dhd_pub_t *pub);
238 extern void dhd_os_start_unlock(dhd_pub_t *pub);
239 extern unsigned long dhd_os_spin_lock(dhd_pub_t *pub);
240 extern void dhd_os_spin_unlock(dhd_pub_t *pub, unsigned long flags);
242 typedef struct dhd_if_event {
250 * Exported from dhd OS modules (dhd_linux/dhd_ndis)
253 /* To allow osl_attach/detach calls from os-independent modules */
254 osl_t *dhd_osl_attach(void *pdev, uint bustype);
255 void dhd_osl_detach(osl_t *osh);
257 /* Indication from bus module regarding presence/insertion of dongle.
258 * Return dhd_pub_t pointer, used as handle to OS module in later calls.
259 * Returned structure should have bus and prot pointers filled in.
260 * bus_hdrlen specifies required headroom for bus module header.
262 extern dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen);
263 extern int dhd_net_attach(dhd_pub_t *dhdp, int idx);
265 /* Indication from bus module regarding removal/absence of dongle */
266 extern void dhd_detach(dhd_pub_t *dhdp);
268 /* Indication from bus module to change flow-control state */
269 extern void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool on);
271 extern bool dhd_prec_enq(dhd_pub_t *dhdp, struct pktq *q, void *pkt, int prec);
273 /* Receive frame for delivery to OS. Callee disposes of rxp. */
274 extern void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *rxp, int numpkt);
276 /* Return pointer to interface name */
277 extern char *dhd_ifname(dhd_pub_t *dhdp, int idx);
279 /* Request scheduling of the bus dpc */
280 extern void dhd_sched_dpc(dhd_pub_t *dhdp);
282 /* Notify tx completion */
283 extern void dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success);
286 extern int dhdcdc_query_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf, uint len);
288 /* OS independent layer functions */
289 extern int dhd_os_proto_block(dhd_pub_t * pub);
290 extern int dhd_os_proto_unblock(dhd_pub_t * pub);
291 extern int dhd_os_ioctl_resp_wait(dhd_pub_t * pub, uint * condition, bool * pending);
292 extern int dhd_os_ioctl_resp_wake(dhd_pub_t * pub);
293 extern unsigned int dhd_os_get_ioctl_resp_timeout(void);
294 extern void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec);
295 extern void * dhd_os_open_image(char * filename);
296 extern int dhd_os_get_image_block(char * buf, int len, void * image);
297 extern void dhd_os_close_image(void * image);
298 extern void dhd_os_wd_timer(void *bus, uint wdtick);
299 extern void dhd_os_sdlock(dhd_pub_t * pub);
300 extern void dhd_os_sdunlock(dhd_pub_t * pub);
301 extern void dhd_os_sdlock_txq(dhd_pub_t * pub);
302 extern void dhd_os_sdunlock_txq(dhd_pub_t * pub);
303 extern void dhd_os_sdlock_rxq(dhd_pub_t * pub);
304 extern void dhd_os_sdunlock_rxq(dhd_pub_t * pub);
305 extern void dhd_os_sdlock_sndup_rxq(dhd_pub_t * pub);
306 extern void dhd_customer_gpio_wlan_ctrl(int onoff);
307 extern int dhd_custom_get_mac_address(unsigned char *buf);
308 extern void dhd_os_sdunlock_sndup_rxq(dhd_pub_t * pub);
309 extern void dhd_os_sdlock_eventq(dhd_pub_t * pub);
310 extern void dhd_os_sdunlock_eventq(dhd_pub_t * pub);
312 extern int write_to_file(dhd_pub_t *dhd, uint8 *buf, int size);
313 #endif /* DHD_DEBUG */
314 #if defined(OOB_INTR_ONLY)
315 extern int dhd_customer_oob_irq_map(unsigned long *irq_flags_ptr);
316 #endif /* defined(OOB_INTR_ONLY) */
317 extern void dhd_os_sdtxlock(dhd_pub_t * pub);
318 extern void dhd_os_sdtxunlock(dhd_pub_t * pub);
320 int setScheduler(struct task_struct *p, int policy, struct sched_param *param);
323 uint32 limit; /* Expiration time (usec) */
324 uint32 increment; /* Current expiration increment (usec) */
325 uint32 elapsed; /* Current elapsed time (usec) */
326 uint32 tick; /* O/S tick time (usec) */
329 extern void dhd_timeout_start(dhd_timeout_t *tmo, uint usec);
330 extern int dhd_timeout_expired(dhd_timeout_t *tmo);
332 extern int dhd_ifname2idx(struct dhd_info *dhd, char *name);
333 extern uint8 *dhd_bssidx2bssid(dhd_pub_t *dhd, int idx);
334 extern int wl_host_event(struct dhd_info *dhd, int *idx, void *pktdata,
335 wl_event_msg_t *, void **data_ptr);
336 extern void wl_event_to_host_order(wl_event_msg_t * evt);
338 extern void dhd_common_init(void);
340 extern int dhd_add_if(struct dhd_info *dhd, int ifidx, void *handle,
341 char *name, uint8 *mac_addr, uint32 flags, uint8 bssidx);
342 extern void dhd_del_if(struct dhd_info *dhd, int ifidx);
344 extern void dhd_vif_add(struct dhd_info *dhd, int ifidx, char * name);
345 extern void dhd_vif_del(struct dhd_info *dhd, int ifidx);
347 extern void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx);
348 extern void dhd_vif_sendup(struct dhd_info *dhd, int ifidx, uchar *cp, int len);
351 /* Send packet to dongle via data channel */
352 extern int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pkt);
354 /* Send event to host */
355 extern void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data);
356 extern int dhd_bus_devreset(dhd_pub_t *dhdp, uint8 flag);
357 extern uint dhd_bus_status(dhd_pub_t *dhdp);
358 extern int dhd_bus_start(dhd_pub_t *dhdp);
360 extern void print_buf(void *pbuf, int len, int bytes_per_line);
363 typedef enum cust_gpio_modes {
370 extern int wl_iw_iscan_set_scan_broadcast_prep(struct net_device *dev, uint flag);
371 extern int wl_iw_send_priv_event(struct net_device *dev, char *flag);
372 extern int net_os_send_hang_message(struct net_device *dev);
375 * Insmod parameters for debug/test
378 /* Watchdog timer interval */
379 extern uint dhd_watchdog_ms;
381 #if defined(DHD_DEBUG)
382 /* Console output poll interval */
383 extern uint dhd_console_ms;
384 #endif /* defined(DHD_DEBUG) */
387 extern uint dhd_intr;
390 extern uint dhd_poll;
392 /* ARP offload agent mode */
393 extern uint dhd_arp_mode;
395 /* ARP offload enable */
396 extern uint dhd_arp_enable;
398 /* Pkt filte enable control */
399 extern uint dhd_pkt_filter_enable;
401 /* Pkt filter init setup */
402 extern uint dhd_pkt_filter_init;
404 /* Pkt filter mode control */
405 extern uint dhd_master_mode;
407 /* Roaming mode control */
408 extern uint dhd_roam;
410 /* Roaming mode control */
411 extern uint dhd_radio_up;
413 /* Initial idletime ticks (may be -1 for immediate idle, 0 for no idle) */
414 extern int dhd_idletime;
415 #define DHD_IDLETIME_TICKS 1
417 /* SDIO Drive Strength */
418 extern uint dhd_sdiod_drive_strength;
420 /* Override to force tx queueing all the time */
421 extern uint dhd_force_tx_queueing;
423 /* Default KEEP_ALIVE Period is 55 sec to prevent AP from sending Keep Alive probe frame */
424 #define KEEP_ALIVE_PERIOD 55000
425 #define NULL_PKT_STR "null_pkt"
428 /* Echo packet generator (SDIO), pkts/s */
429 extern uint dhd_pktgen;
431 /* Echo packet len (0 => sawtooth, max 1800) */
432 extern uint dhd_pktgen_len;
433 #define MAX_PKTGEN_LEN 1800
437 /* optionally set by a module_param_string() */
438 #define MOD_PARAM_PATHLEN 2048
439 extern char fw_path[MOD_PARAM_PATHLEN];
440 extern char nv_path[MOD_PARAM_PATHLEN];
442 /* For supporting multiple interfaces */
443 #define DHD_MAX_IFS 16
444 #define DHD_DEL_IF -0xe
445 #define DHD_BAD_IF -0xf
448 extern void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar);
449 extern void dhd_wait_event_wakeup(dhd_pub_t*dhd);
451 /* dhd_commn arp offload wrapers */
452 extern void dhd_arp_cleanup(dhd_pub_t *dhd);
453 int dhd_arp_get_arp_hostip_table(dhd_pub_t *dhd, void *buf, int buflen);
454 void dhd_arp_offload_add_ip(dhd_pub_t *dhd, u32 ipaddr);