OSDN Git Service

3b4dc7a220c07166b53840a923a40862823626bd
[android-x86/kernel.git] / drivers / net / wireless / bcmdhd / dhd.h
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-2011, 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 333052 2012-05-12 02:09:28Z $
28  */
29
30 /****************
31  * Common types *
32  */
33
34 #ifndef _dhd_h_
35 #define _dhd_h_
36
37 #if defined(CHROMIUMOS_COMPAT_WIRELESS)
38 #include <linux/sched.h>
39 #endif
40 #include <linux/init.h>
41 #include <linux/kernel.h>
42 #include <linux/slab.h>
43 #include <linux/skbuff.h>
44 #include <linux/netdevice.h>
45 #include <linux/etherdevice.h>
46 #include <linux/random.h>
47 #include <linux/spinlock.h>
48 #include <linux/ethtool.h>
49 #include <asm/uaccess.h>
50 #include <asm/unaligned.h>
51 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_HAS_WAKELOCK)
52 #include <linux/wakelock.h>
53 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined (CONFIG_HAS_WAKELOCK) */
54
55 /* The kernel threading is sdio-specific */
56 struct task_struct;
57 struct sched_param;
58 int setScheduler(struct task_struct *p, int policy, struct sched_param *param);
59
60 #define ALL_INTERFACES  0xff
61
62 #include <wlioctl.h>
63
64
65 /* Forward decls */
66 struct dhd_bus;
67 struct dhd_prot;
68 struct dhd_info;
69 struct dhd_cmn;
70
71 /* The level of bus communication with the dongle */
72 enum dhd_bus_state {
73         DHD_BUS_DOWN,           /* Not ready for frame transfers */
74         DHD_BUS_LOAD,           /* Download access only (CPU reset) */
75         DHD_BUS_DATA            /* Ready for frame transfers */
76 };
77
78 /* Firmware requested operation mode */
79 #define STA_MASK                        0x0001
80 #define HOSTAPD_MASK            0x0002
81 #define WFD_MASK                        0x0004
82 #define SOFTAP_FW_MASK  0x0008
83 #define P2P_GO_ENABLED          0x0010
84 #define P2P_GC_ENABLED          0x0020
85 #define CONCURENT_MASK          0x00F0
86
87 #define MANUFACTRING_FW         "WLTEST"
88
89 /* max sequential rxcntl timeouts to set HANG event */
90 #define MAX_CNTL_TIMEOUT  2
91
92 #define DHD_SCAN_ACTIVE_TIME     40 /* ms : Embedded default Active setting from DHD Driver */
93 #define DHD_SCAN_PASSIVE_TIME   130 /* ms: Embedded default Passive setting from DHD Driver */
94
95 #define DHD_BEACON_TIMEOUT_NORMAL       4
96 #define DHD_BEACON_TIMEOUT_HIGH         10
97
98 enum dhd_bus_wake_state {
99         WAKE_LOCK_OFF,
100         WAKE_LOCK_PRIV,
101         WAKE_LOCK_DPC,
102         WAKE_LOCK_IOCTL,
103         WAKE_LOCK_DOWNLOAD,
104         WAKE_LOCK_TMOUT,
105         WAKE_LOCK_WATCHDOG,
106         WAKE_LOCK_LINK_DOWN_TMOUT,
107         WAKE_LOCK_PNO_FIND_TMOUT,
108         WAKE_LOCK_SOFTAP_SET,
109         WAKE_LOCK_SOFTAP_STOP,
110         WAKE_LOCK_SOFTAP_START,
111         WAKE_LOCK_SOFTAP_THREAD,
112         WAKE_LOCK_MAX
113 };
114
115 enum dhd_prealloc_index {
116         DHD_PREALLOC_PROT = 0,
117         DHD_PREALLOC_RXBUF,
118         DHD_PREALLOC_DATABUF,
119         DHD_PREALLOC_OSL_BUF
120 };
121
122 typedef enum  {
123         DHD_IF_NONE = 0,
124         DHD_IF_ADD,
125         DHD_IF_DEL,
126         DHD_IF_CHANGE,
127         DHD_IF_DELETING
128 } dhd_if_state_t;
129
130 #if defined(CONFIG_DHD_USE_STATIC_BUF)
131
132 uint8* dhd_os_prealloc(void *osh, int section, uint size);
133 void dhd_os_prefree(void *osh, void *addr, uint size);
134 #define DHD_OS_PREALLOC(osh, section, size) dhd_os_prealloc(osh, section, size)
135 #define DHD_OS_PREFREE(osh, addr, size) dhd_os_prefree(osh, addr, size)
136
137 #else
138
139 #define DHD_OS_PREALLOC(osh, section, size) MALLOC(osh, size)
140 #define DHD_OS_PREFREE(osh, addr, size) MFREE(osh, addr, size)
141
142 #endif /* defined(CONFIG_DHD_USE_STATIC_BUF) */
143
144 /* Packet alignment for most efficient SDIO (can change based on platform) */
145 #ifndef DHD_SDALIGN
146 #define DHD_SDALIGN     32
147 #endif
148
149 /* Common structure for module and instance linkage */
150 typedef struct dhd_pub {
151         /* Linkage ponters */
152         osl_t *osh;             /* OSL handle */
153         struct dhd_bus *bus;    /* Bus module handle */
154         struct dhd_prot *prot;  /* Protocol module handle */
155         struct dhd_info  *info; /* Info module handle */
156         struct dhd_cmn  *cmn;   /* dhd_common module handle */
157
158         /* Internal dhd items */
159         bool up;                /* Driver up/down (to OS) */
160         bool txoff;             /* Transmit flow-controlled */
161         bool dongle_reset;  /* TRUE = DEVRESET put dongle into reset */
162         enum dhd_bus_state busstate;
163         uint hdrlen;            /* Total DHD header length (proto + bus) */
164         uint maxctl;            /* Max size rxctl request from proto to bus */
165         uint rxsz;              /* Rx buffer size bus module should use */
166         uint8 wme_dp;   /* wme discard priority */
167
168         /* Dongle media info */
169         bool iswl;              /* Dongle-resident driver is wl */
170         ulong drv_version;      /* Version of dongle-resident driver */
171         struct ether_addr mac;  /* MAC address obtained from dongle */
172         dngl_stats_t dstats;    /* Stats for dongle-based data */
173
174         /* Additional stats for the bus level */
175         ulong tx_packets;       /* Data packets sent to dongle */
176         ulong tx_multicast;     /* Multicast data packets sent to dongle */
177         ulong tx_errors;        /* Errors in sending data to dongle */
178         ulong tx_ctlpkts;       /* Control packets sent to dongle */
179         ulong tx_ctlerrs;       /* Errors sending control frames to dongle */
180         ulong rx_packets;       /* Packets sent up the network interface */
181         ulong rx_multicast;     /* Multicast packets sent up the network interface */
182         ulong rx_errors;        /* Errors processing rx data packets */
183         ulong rx_ctlpkts;       /* Control frames processed from dongle */
184         ulong rx_ctlerrs;       /* Errors in processing rx control frames */
185         ulong rx_dropped;       /* Packets dropped locally (no memory) */
186         ulong rx_flushed;  /* Packets flushed due to unscheduled sendup thread */
187         ulong wd_dpc_sched;   /* Number of times dhd dpc scheduled by watchdog timer */
188
189         ulong rx_readahead_cnt; /* Number of packets where header read-ahead was used. */
190         ulong tx_realloc;       /* Number of tx packets we had to realloc for headroom */
191         ulong fc_packets;       /* Number of flow control pkts recvd */
192
193         /* Last error return */
194         int bcmerror;
195         uint tickcnt;
196
197         /* Last error from dongle */
198         int dongle_error;
199
200         /* Suspend disable flag and "in suspend" flag */
201         int suspend_disable_flag; /* "1" to disable all extra powersaving during suspend */
202         int in_suspend;                 /* flag set to 1 when early suspend called */
203 #ifdef PNO_SUPPORT
204         int pno_enable;                 /* pno status : "1" is pno enable */
205 #endif /* PNO_SUPPORT */
206         int dtim_skip;         /* dtim skip , default 0 means wake each dtim */
207
208         /* Pkt filter defination */
209         char * pktfilter[100];
210         int pktfilter_count;
211
212         wl_country_t dhd_cspec;         /* Current Locale info */
213         char eventmask[WL_EVENTING_MASK_LEN];
214         int     op_mode;                                /* STA, HostAPD, WFD, SoftAP */
215
216 /* Set this to 1 to use a seperate interface (p2p0) for p2p operations.
217  *  For ICS MR1 releases it should be disable to be compatable with ICS MR1 Framework
218  *  see target dhd-cdc-sdmmc-panda-cfg80211-icsmr1-gpl-debug in Makefile
219  */
220
221 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) && 1
222         struct mutex    wl_start_stop_lock; /* lock/unlock for Android start/stop */
223         struct mutex    wl_softap_lock;          /* lock/unlock for any SoftAP/STA settings */
224 #endif 
225
226         uint16  maxdatablks;
227 #ifdef PROP_TXSTATUS
228         int   wlfc_enabled;
229         void* wlfc_state;
230 #endif
231         bool    dongle_isolation;
232         int   hang_was_sent;
233         int   rxcnt_timeout;            /* counter rxcnt timeout to send HANG */
234         int   txcnt_timeout;            /* counter txcnt timeout to send HANG */
235 #ifdef WLMEDIA_HTSF
236         uint8 htsfdlystat_sz; /* Size of delay stats, max 255B */
237 #endif
238 } dhd_pub_t;
239
240 typedef struct dhd_cmn {
241         osl_t *osh;             /* OSL handle */
242         dhd_pub_t *dhd;
243 } dhd_cmn_t;
244
245
246         #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP)
247
248         #define DHD_PM_RESUME_WAIT_INIT(a) DECLARE_WAIT_QUEUE_HEAD(a);
249         #define _DHD_PM_RESUME_WAIT(a, b) do {\
250                         int retry = 0; \
251                         SMP_RD_BARRIER_DEPENDS(); \
252                         while (dhd_mmc_suspend && retry++ != b) { \
253                                 SMP_RD_BARRIER_DEPENDS(); \
254                                 wait_event_interruptible_timeout(a, !dhd_mmc_suspend, HZ/100); \
255                         } \
256                 } while (0)
257         #define DHD_PM_RESUME_WAIT(a)           _DHD_PM_RESUME_WAIT(a, 200)
258         #define DHD_PM_RESUME_WAIT_FOREVER(a)   _DHD_PM_RESUME_WAIT(a, ~0)
259         #define DHD_PM_RESUME_RETURN_ERROR(a)   do { if (dhd_mmc_suspend) return a; } while (0)
260         #define DHD_PM_RESUME_RETURN            do { if (dhd_mmc_suspend) return; } while (0)
261
262         #define DHD_SPINWAIT_SLEEP_INIT(a) DECLARE_WAIT_QUEUE_HEAD(a);
263         #define SPINWAIT_SLEEP(a, exp, us) do { \
264                 uint countdown = (us) + 9999; \
265                 while ((exp) && (countdown >= 10000)) { \
266                         wait_event_interruptible_timeout(a, FALSE, HZ/100); \
267                         countdown -= 10000; \
268                 } \
269         } while (0)
270
271         #else
272
273         #define DHD_PM_RESUME_WAIT_INIT(a)
274         #define DHD_PM_RESUME_WAIT(a)
275         #define DHD_PM_RESUME_WAIT_FOREVER(a)
276         #define DHD_PM_RESUME_RETURN_ERROR(a)
277         #define DHD_PM_RESUME_RETURN
278
279         #define DHD_SPINWAIT_SLEEP_INIT(a)
280         #define SPINWAIT_SLEEP(a, exp, us)  do { \
281                 uint countdown = (us) + 9; \
282                 while ((exp) && (countdown >= 10)) { \
283                         OSL_DELAY(10);  \
284                         countdown -= 10;  \
285                 } \
286         } while (0)
287
288         #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP) */
289 #ifndef DHDTHREAD
290 #undef  SPINWAIT_SLEEP
291 #define SPINWAIT_SLEEP(a, exp, us) SPINWAIT(exp, us)
292 #endif /* DHDTHREAD */
293 #define DHD_IF_VIF      0x01    /* Virtual IF (Hidden from user) */
294
295 unsigned long dhd_os_spin_lock(dhd_pub_t *pub);
296 void dhd_os_spin_unlock(dhd_pub_t *pub, unsigned long flags);
297
298 /*  Wakelock Functions */
299 extern int dhd_os_wake_lock(dhd_pub_t *pub);
300 extern int dhd_os_wake_unlock(dhd_pub_t *pub);
301 extern int dhd_os_wake_lock_timeout(dhd_pub_t *pub);
302 extern int dhd_os_wake_lock_rx_timeout_enable(dhd_pub_t *pub, int val);
303 extern int dhd_os_wake_lock_ctrl_timeout_enable(dhd_pub_t *pub, int val);
304
305 inline static void MUTEX_LOCK_SOFTAP_SET_INIT(dhd_pub_t * dhdp)
306 {
307 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) && 1
308         mutex_init(&dhdp->wl_softap_lock);
309 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
310 }
311
312 inline static void MUTEX_LOCK_SOFTAP_SET(dhd_pub_t * dhdp)
313 {
314 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) && 1
315         mutex_lock(&dhdp->wl_softap_lock);
316 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
317 }
318
319 inline static void MUTEX_UNLOCK_SOFTAP_SET(dhd_pub_t * dhdp)
320 {
321 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) && 1
322         mutex_unlock(&dhdp->wl_softap_lock);
323 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
324 }
325
326 #define DHD_OS_WAKE_LOCK(pub)                   dhd_os_wake_lock(pub)
327 #define DHD_OS_WAKE_UNLOCK(pub)                 dhd_os_wake_unlock(pub)
328 #define DHD_OS_WAKE_LOCK_TIMEOUT(pub)           dhd_os_wake_lock_timeout(pub)
329 #define DHD_OS_WAKE_LOCK_RX_TIMEOUT_ENABLE(pub, val)    dhd_os_wake_lock_rx_timeout_enable(pub, val)
330 #define DHD_OS_WAKE_LOCK_CTRL_TIMEOUT_ENABLE(pub, val)  dhd_os_wake_lock_ctrl_timeout_enable(pub, val)
331 #define DHD_PACKET_TIMEOUT_MS   1000
332 #define DHD_EVENT_TIMEOUT_MS    1500
333
334 /* interface operations (register, remove) should be atomic, use this lock to prevent race
335  * condition among wifi on/off and interface operation functions
336  */
337 void dhd_net_if_lock(struct net_device *dev);
338 void dhd_net_if_unlock(struct net_device *dev);
339
340 typedef struct dhd_if_event {
341         uint8 ifidx;
342         uint8 action;
343         uint8 flags;
344         uint8 bssidx;
345         uint8 is_AP;
346 } dhd_if_event_t;
347
348 typedef enum dhd_attach_states
349 {
350         DHD_ATTACH_STATE_INIT = 0x0,
351         DHD_ATTACH_STATE_NET_ALLOC = 0x1,
352         DHD_ATTACH_STATE_DHD_ALLOC = 0x2,
353         DHD_ATTACH_STATE_ADD_IF = 0x4,
354         DHD_ATTACH_STATE_PROT_ATTACH = 0x8,
355         DHD_ATTACH_STATE_WL_ATTACH = 0x10,
356         DHD_ATTACH_STATE_THREADS_CREATED = 0x20,
357         DHD_ATTACH_STATE_WAKELOCKS_INIT = 0x40,
358         DHD_ATTACH_STATE_CFG80211 = 0x80,
359         DHD_ATTACH_STATE_EARLYSUSPEND_DONE = 0x100,
360         DHD_ATTACH_STATE_DONE = 0x200
361 } dhd_attach_states_t;
362
363 /* Value -1 means we are unsuccessful in creating the kthread. */
364 #define DHD_PID_KT_INVALID      -1
365 /* Value -2 means we are unsuccessful in both creating the kthread and tasklet */
366 #define DHD_PID_KT_TL_INVALID   -2
367
368 /*
369  * Exported from dhd OS modules (dhd_linux/dhd_ndis)
370  */
371
372 /* To allow osl_attach/detach calls from os-independent modules */
373 osl_t *dhd_osl_attach(void *pdev, uint bustype);
374 void dhd_osl_detach(osl_t *osh);
375
376 /* Indication from bus module regarding presence/insertion of dongle.
377  * Return dhd_pub_t pointer, used as handle to OS module in later calls.
378  * Returned structure should have bus and prot pointers filled in.
379  * bus_hdrlen specifies required headroom for bus module header.
380  */
381 extern dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen);
382 #if defined(WLP2P) && defined(WL_CFG80211)
383 /* To allow attach/detach calls corresponding to p2p0 interface  */
384 extern int dhd_attach_p2p(dhd_pub_t *);
385 extern int dhd_detach_p2p(dhd_pub_t *);
386 #endif /* WLP2P && WL_CFG80211 */
387 extern int dhd_net_attach(dhd_pub_t *dhdp, int idx);
388
389 /* Indication from bus module regarding removal/absence of dongle */
390 extern void dhd_detach(dhd_pub_t *dhdp);
391 extern void dhd_free(dhd_pub_t *dhdp);
392
393 /* Indication from bus module to change flow-control state */
394 extern void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool on);
395
396 extern bool dhd_prec_enq(dhd_pub_t *dhdp, struct pktq *q, void *pkt, int prec);
397
398 /* Receive frame for delivery to OS.  Callee disposes of rxp. */
399 extern void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *rxp, int numpkt, uint8 chan);
400
401 /* Return pointer to interface name */
402 extern char *dhd_ifname(dhd_pub_t *dhdp, int idx);
403
404 /* Request scheduling of the bus dpc */
405 extern void dhd_sched_dpc(dhd_pub_t *dhdp);
406
407 /* Notify tx completion */
408 extern void dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success);
409
410 /* OS independent layer functions */
411 extern int dhd_os_proto_block(dhd_pub_t * pub);
412 extern int dhd_os_proto_unblock(dhd_pub_t * pub);
413 extern int dhd_os_ioctl_resp_wait(dhd_pub_t * pub, uint * condition, bool * pending);
414 extern int dhd_os_ioctl_resp_wake(dhd_pub_t * pub);
415 extern unsigned int dhd_os_get_ioctl_resp_timeout(void);
416 extern void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec);
417 extern void * dhd_os_open_image(char * filename);
418 extern int dhd_os_get_image_block(char * buf, int len, void * image);
419 extern void dhd_os_close_image(void * image);
420 extern void dhd_os_wd_timer(void *bus, uint wdtick);
421 extern void dhd_os_sdlock(dhd_pub_t * pub);
422 extern void dhd_os_sdunlock(dhd_pub_t * pub);
423 extern void dhd_os_sdlock_txq(dhd_pub_t * pub);
424 extern void dhd_os_sdunlock_txq(dhd_pub_t * pub);
425 extern void dhd_os_sdlock_rxq(dhd_pub_t * pub);
426 extern void dhd_os_sdunlock_rxq(dhd_pub_t * pub);
427 extern void dhd_os_sdlock_sndup_rxq(dhd_pub_t * pub);
428 extern void dhd_customer_gpio_wlan_ctrl(int onoff);
429 extern int dhd_custom_get_mac_address(unsigned char *buf);
430 extern void dhd_os_sdunlock_sndup_rxq(dhd_pub_t * pub);
431 extern void dhd_os_sdlock_eventq(dhd_pub_t * pub);
432 extern void dhd_os_sdunlock_eventq(dhd_pub_t * pub);
433 extern bool dhd_os_check_hang(dhd_pub_t *dhdp, int ifidx, int ret);
434
435 #ifdef PNO_SUPPORT
436 extern int dhd_pno_enable(dhd_pub_t *dhd, int pfn_enabled);
437 extern int dhd_pno_clean(dhd_pub_t *dhd);
438 extern int dhd_pno_set(dhd_pub_t *dhd, wlc_ssid_t* ssids_local, int nssid,
439                        ushort  scan_fr, int pno_repeat, int pno_freq_expo_max);
440 extern int dhd_pno_set_ex(dhd_pub_t *dhd, wl_pfn_t* ssidnet, int nssid,
441                                 ushort pno_interval, int pno_repeat, int pno_expo_max, int pno_lost_time);
442 extern int dhd_pno_get_status(dhd_pub_t *dhd);
443 extern int dhd_dev_pno_reset(struct net_device *dev);
444 extern int dhd_dev_pno_set(struct net_device *dev, wlc_ssid_t* ssids_local,
445                            int nssid, ushort  scan_fr, int pno_repeat, int pno_freq_expo_max);
446 extern int dhd_dev_pno_set_ex(struct net_device *dev, wl_pfn_t* ssidnet, int nssid,
447                                 ushort  pno_interval, int pno_repeat, int pno_expo_max, int pno_lost_time);
448 extern int dhd_dev_pno_enable(struct net_device *dev,  int pfn_enabled);
449 extern int dhd_dev_get_pno_status(struct net_device *dev);
450 #endif /* PNO_SUPPORT */
451
452 #define DHD_UNICAST_FILTER_NUM          0
453 #define DHD_BROADCAST_FILTER_NUM        1
454 #define DHD_MULTICAST4_FILTER_NUM       2
455 #define DHD_MULTICAST6_FILTER_NUM       3
456 #define DHD_MDNS_FILTER_NUM             4
457 extern int dhd_os_set_packet_filter(dhd_pub_t *dhdp, int val);
458 extern int net_os_set_packet_filter(struct net_device *dev, int val);
459 extern int net_os_rxfilter_add_remove(struct net_device *dev, int val, int num);
460
461 extern int dhd_get_dtim_skip(dhd_pub_t *dhd);
462 extern bool dhd_check_ap_wfd_mode_set(dhd_pub_t *dhd);
463
464 #ifdef DHD_DEBUG
465 extern int write_to_file(dhd_pub_t *dhd, uint8 *buf, int size);
466 #endif /* DHD_DEBUG */
467 #if defined(OOB_INTR_ONLY)
468 extern int dhd_customer_oob_irq_map(unsigned long *irq_flags_ptr);
469 #endif /* defined(OOB_INTR_ONLY) */
470 extern void dhd_os_sdtxlock(dhd_pub_t * pub);
471 extern void dhd_os_sdtxunlock(dhd_pub_t * pub);
472
473 typedef struct {
474         uint32 limit;           /* Expiration time (usec) */
475         uint32 increment;       /* Current expiration increment (usec) */
476         uint32 elapsed;         /* Current elapsed time (usec) */
477         uint32 tick;            /* O/S tick time (usec) */
478 } dhd_timeout_t;
479
480 extern void dhd_timeout_start(dhd_timeout_t *tmo, uint usec);
481 extern int dhd_timeout_expired(dhd_timeout_t *tmo);
482
483 extern int dhd_ifname2idx(struct dhd_info *dhd, char *name);
484 extern int dhd_net2idx(struct dhd_info *dhd, struct net_device *net);
485 extern struct net_device * dhd_idx2net(void *pub, int ifidx);
486 extern int wl_host_event(dhd_pub_t *dhd_pub, int *idx, void *pktdata,
487                          wl_event_msg_t *, void **data_ptr);
488 extern void wl_event_to_host_order(wl_event_msg_t * evt);
489
490 extern int dhd_wl_ioctl(dhd_pub_t *dhd_pub, int ifindex, wl_ioctl_t *ioc, void *buf, int len);
491 extern int dhd_wl_ioctl_cmd(dhd_pub_t *dhd_pub, int cmd, void *arg, int len, uint8 set,
492                             int ifindex);
493
494 extern struct dhd_cmn *dhd_common_init(osl_t *osh);
495 extern void dhd_common_deinit(dhd_pub_t *dhd_pub, dhd_cmn_t *sa_cmn);
496
497 extern int dhd_do_driver_init(struct net_device *net);
498 extern int dhd_add_if(struct dhd_info *dhd, int ifidx, void *handle,
499         char *name, uint8 *mac_addr, uint32 flags, uint8 bssidx);
500 extern void dhd_del_if(struct dhd_info *dhd, int ifidx);
501
502 extern void dhd_vif_add(struct dhd_info *dhd, int ifidx, char * name);
503 extern void dhd_vif_del(struct dhd_info *dhd, int ifidx);
504
505 extern void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx);
506 extern void dhd_vif_sendup(struct dhd_info *dhd, int ifidx, uchar *cp, int len);
507
508
509 /* Send packet to dongle via data channel */
510 extern int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pkt);
511
512 /* send up locally generated event */
513 extern void dhd_sendup_event_common(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data);
514 /* Send event to host */
515 extern void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data);
516 extern int dhd_bus_devreset(dhd_pub_t *dhdp, uint8 flag);
517 extern uint dhd_bus_status(dhd_pub_t *dhdp);
518 extern int  dhd_bus_start(dhd_pub_t *dhdp);
519 extern int dhd_bus_membytes(dhd_pub_t *dhdp, bool set, uint32 address, uint8 *data, uint size);
520 extern void dhd_print_buf(void *pbuf, int len, int bytes_per_line);
521 extern bool dhd_is_associated(dhd_pub_t *dhd, void *bss_buf, int *retval);
522 extern uint dhd_bus_chip_id(dhd_pub_t *dhdp);
523
524 #if defined(KEEP_ALIVE)
525 extern int dhd_keep_alive_onoff(dhd_pub_t *dhd);
526 #endif /* KEEP_ALIVE */
527
528 #ifdef ARP_OFFLOAD_SUPPORT
529 extern void dhd_arp_offload_set(dhd_pub_t * dhd, int arp_mode);
530 extern void dhd_arp_offload_enable(dhd_pub_t * dhd, int arp_enable);
531 #endif /* ARP_OFFLOAD_SUPPORT */
532
533
534 typedef enum cust_gpio_modes {
535         WLAN_RESET_ON,
536         WLAN_RESET_OFF,
537         WLAN_POWER_ON,
538         WLAN_POWER_OFF
539 } cust_gpio_modes_t;
540
541 extern int wl_iw_iscan_set_scan_broadcast_prep(struct net_device *dev, uint flag);
542 extern int wl_iw_send_priv_event(struct net_device *dev, char *flag);
543 /*
544  * Insmod parameters for debug/test
545  */
546
547 /* Watchdog timer interval */
548 extern uint dhd_watchdog_ms;
549
550 #if defined(DHD_DEBUG)
551 /* Console output poll interval */
552 extern uint dhd_console_ms;
553 extern uint wl_msg_level;
554 #endif /* defined(DHD_DEBUG) */
555
556 /* Use interrupts */
557 extern uint dhd_intr;
558
559 /* Use polling */
560 extern uint dhd_poll;
561
562 /* ARP offload agent mode */
563 extern uint dhd_arp_mode;
564
565 /* ARP offload enable */
566 extern uint dhd_arp_enable;
567
568 /* Pkt filte enable control */
569 extern uint dhd_pkt_filter_enable;
570
571 /*  Pkt filter init setup */
572 extern uint dhd_pkt_filter_init;
573
574 /* Pkt filter mode control */
575 extern uint dhd_master_mode;
576
577 /* Roaming mode control */
578 extern uint dhd_roam_disable;
579
580 /* Roaming mode control */
581 extern uint dhd_radio_up;
582
583 /* Initial idletime ticks (may be -1 for immediate idle, 0 for no idle) */
584 extern int dhd_idletime;
585 #define DHD_IDLETIME_TICKS 1
586
587 /* SDIO Drive Strength */
588 extern uint dhd_sdiod_drive_strength;
589
590 /* Override to force tx queueing all the time */
591 extern uint dhd_force_tx_queueing;
592 /* Default KEEP_ALIVE Period is 55 sec to prevent AP from sending Keep Alive probe frame */
593 #define KEEP_ALIVE_PERIOD 55000
594 #define NULL_PKT_STR    "null_pkt"
595
596 #ifdef SDTEST
597 /* Echo packet generator (SDIO), pkts/s */
598 extern uint dhd_pktgen;
599
600 /* Echo packet len (0 => sawtooth, max 1800) */
601 extern uint dhd_pktgen_len;
602 #define MAX_PKTGEN_LEN 1800
603 #endif
604
605
606 /* optionally set by a module_param_string() */
607 #define MOD_PARAM_PATHLEN       2048
608 extern char fw_path[MOD_PARAM_PATHLEN];
609 extern char nv_path[MOD_PARAM_PATHLEN];
610
611 #ifdef SOFTAP
612 extern char fw_path2[MOD_PARAM_PATHLEN];
613 #endif
614
615 /* Flag to indicate if we should download firmware on driver load */
616 extern uint dhd_download_fw_on_driverload;
617
618 /* For supporting multiple interfaces */
619 #define DHD_MAX_IFS     16
620 #define DHD_DEL_IF      -0xe
621 #define DHD_BAD_IF      -0xf
622
623 #ifdef PROP_TXSTATUS
624 /* Please be mindful that total pkttag space is 32 octets only */
625 typedef struct dhd_pkttag {
626         /*
627         b[11 ] - 1 = this packet was sent in response to one time packet request,
628         do not increment credit on status for this one. [WLFC_CTL_TYPE_MAC_REQUEST_PACKET].
629         b[10 ] - 1 = signal-only-packet to firmware [i.e. nothing to piggyback on]
630         b[9  ] - 1 = packet is host->firmware (transmit direction)
631                - 0 = packet received from firmware (firmware->host)
632         b[8  ] - 1 = packet was sent due to credit_request (pspoll),
633                      packet does not count against FIFO credit.
634                - 0 = normal transaction, packet counts against FIFO credit
635         b[7  ] - 1 = AP, 0 = STA
636         b[6:4] - AC FIFO number
637         b[3:0] - interface index
638         */
639         uint16  if_flags;
640         /* destination MAC address for this packet so that not every
641         module needs to open the packet to find this
642         */
643         uint8   dstn_ether[ETHER_ADDR_LEN];
644         /*
645         This 32-bit goes from host to device for every packet.
646         */
647         uint32  htod_tag;
648         /* bus specific stuff */
649         union {
650                 struct {
651                         void* stuff;
652                         uint32 thing1;
653                         uint32 thing2;
654                 } sd;
655                 struct {
656                         void* bus;
657                         void* urb;
658                 } usb;
659         } bus_specific;
660 } dhd_pkttag_t;
661
662 #define DHD_PKTTAG_SET_H2DTAG(tag, h2dvalue)    ((dhd_pkttag_t*)(tag))->htod_tag = (h2dvalue)
663 #define DHD_PKTTAG_H2DTAG(tag)                                  (((dhd_pkttag_t*)(tag))->htod_tag)
664
665 #define DHD_PKTTAG_IFMASK               0xf
666 #define DHD_PKTTAG_IFTYPE_MASK  0x1
667 #define DHD_PKTTAG_IFTYPE_SHIFT 7
668 #define DHD_PKTTAG_FIFO_MASK    0x7
669 #define DHD_PKTTAG_FIFO_SHIFT   4
670
671 #define DHD_PKTTAG_SIGNALONLY_MASK                      0x1
672 #define DHD_PKTTAG_SIGNALONLY_SHIFT                     10
673
674 #define DHD_PKTTAG_ONETIMEPKTRQST_MASK          0x1
675 #define DHD_PKTTAG_ONETIMEPKTRQST_SHIFT         11
676
677 #define DHD_PKTTAG_PKTDIR_MASK                  0x1
678 #define DHD_PKTTAG_PKTDIR_SHIFT                 9
679
680 #define DHD_PKTTAG_CREDITCHECK_MASK             0x1
681 #define DHD_PKTTAG_CREDITCHECK_SHIFT    8
682
683 #define DHD_PKTTAG_INVALID_FIFOID 0x7
684
685 #define DHD_PKTTAG_SETFIFO(tag, fifo)   ((dhd_pkttag_t*)(tag))->if_flags = \
686         (((dhd_pkttag_t*)(tag))->if_flags & ~(DHD_PKTTAG_FIFO_MASK << DHD_PKTTAG_FIFO_SHIFT)) | \
687         (((fifo) & DHD_PKTTAG_FIFO_MASK) << DHD_PKTTAG_FIFO_SHIFT)
688 #define DHD_PKTTAG_FIFO(tag)                    ((((dhd_pkttag_t*)(tag))->if_flags >> \
689         DHD_PKTTAG_FIFO_SHIFT) & DHD_PKTTAG_FIFO_MASK)
690
691 #define DHD_PKTTAG_SETIF(tag, if)       ((dhd_pkttag_t*)(tag))->if_flags = \
692         (((dhd_pkttag_t*)(tag))->if_flags & ~DHD_PKTTAG_IFMASK) | ((if) & DHD_PKTTAG_IFMASK)
693 #define DHD_PKTTAG_IF(tag)      (((dhd_pkttag_t*)(tag))->if_flags & DHD_PKTTAG_IFMASK)
694
695 #define DHD_PKTTAG_SETIFTYPE(tag, isAP) ((dhd_pkttag_t*)(tag))->if_flags = \
696         (((dhd_pkttag_t*)(tag))->if_flags & \
697         ~(DHD_PKTTAG_IFTYPE_MASK << DHD_PKTTAG_IFTYPE_SHIFT)) | \
698         (((isAP) & DHD_PKTTAG_IFTYPE_MASK) << DHD_PKTTAG_IFTYPE_SHIFT)
699 #define DHD_PKTTAG_IFTYPE(tag)  ((((dhd_pkttag_t*)(tag))->if_flags >> \
700         DHD_PKTTAG_IFTYPE_SHIFT) & DHD_PKTTAG_IFTYPE_MASK)
701
702 #define DHD_PKTTAG_SETCREDITCHECK(tag, check)   ((dhd_pkttag_t*)(tag))->if_flags = \
703         (((dhd_pkttag_t*)(tag))->if_flags & \
704         ~(DHD_PKTTAG_CREDITCHECK_MASK << DHD_PKTTAG_CREDITCHECK_SHIFT)) | \
705         (((check) & DHD_PKTTAG_CREDITCHECK_MASK) << DHD_PKTTAG_CREDITCHECK_SHIFT)
706 #define DHD_PKTTAG_CREDITCHECK(tag)     ((((dhd_pkttag_t*)(tag))->if_flags >> \
707         DHD_PKTTAG_CREDITCHECK_SHIFT) & DHD_PKTTAG_CREDITCHECK_MASK)
708
709 #define DHD_PKTTAG_SETPKTDIR(tag, dir)  ((dhd_pkttag_t*)(tag))->if_flags = \
710         (((dhd_pkttag_t*)(tag))->if_flags & \
711         ~(DHD_PKTTAG_PKTDIR_MASK << DHD_PKTTAG_PKTDIR_SHIFT)) | \
712         (((dir) & DHD_PKTTAG_PKTDIR_MASK) << DHD_PKTTAG_PKTDIR_SHIFT)
713 #define DHD_PKTTAG_PKTDIR(tag)  ((((dhd_pkttag_t*)(tag))->if_flags >> \
714         DHD_PKTTAG_PKTDIR_SHIFT) & DHD_PKTTAG_PKTDIR_MASK)
715
716 #define DHD_PKTTAG_SETSIGNALONLY(tag, signalonly)       ((dhd_pkttag_t*)(tag))->if_flags = \
717         (((dhd_pkttag_t*)(tag))->if_flags & \
718         ~(DHD_PKTTAG_SIGNALONLY_MASK << DHD_PKTTAG_SIGNALONLY_SHIFT)) | \
719         (((signalonly) & DHD_PKTTAG_SIGNALONLY_MASK) << DHD_PKTTAG_SIGNALONLY_SHIFT)
720 #define DHD_PKTTAG_SIGNALONLY(tag)      ((((dhd_pkttag_t*)(tag))->if_flags >> \
721         DHD_PKTTAG_SIGNALONLY_SHIFT) & DHD_PKTTAG_SIGNALONLY_MASK)
722
723 #define DHD_PKTTAG_SETONETIMEPKTRQST(tag)       ((dhd_pkttag_t*)(tag))->if_flags = \
724         (((dhd_pkttag_t*)(tag))->if_flags & \
725         ~(DHD_PKTTAG_ONETIMEPKTRQST_MASK << DHD_PKTTAG_ONETIMEPKTRQST_SHIFT)) | \
726         (1 << DHD_PKTTAG_ONETIMEPKTRQST_SHIFT)
727 #define DHD_PKTTAG_ONETIMEPKTRQST(tag)  ((((dhd_pkttag_t*)(tag))->if_flags >> \
728         DHD_PKTTAG_ONETIMEPKTRQST_SHIFT) & DHD_PKTTAG_ONETIMEPKTRQST_MASK)
729
730 #define DHD_PKTTAG_SETDSTN(tag, dstn_MAC_ea)    memcpy(((dhd_pkttag_t*)((tag)))->dstn_ether, \
731         (dstn_MAC_ea), ETHER_ADDR_LEN)
732 #define DHD_PKTTAG_DSTN(tag)    ((dhd_pkttag_t*)(tag))->dstn_ether
733
734 typedef int (*f_commitpkt_t)(void* ctx, void* p);
735
736 #ifdef PROP_TXSTATUS_DEBUG
737 #define DHD_WLFC_CTRINC_MAC_CLOSE(entry)        do { (entry)->closed_ct++; } while (0)
738 #define DHD_WLFC_CTRINC_MAC_OPEN(entry)         do { (entry)->opened_ct++; } while (0)
739 #else
740 #define DHD_WLFC_CTRINC_MAC_CLOSE(entry)        do {} while (0)
741 #define DHD_WLFC_CTRINC_MAC_OPEN(entry)         do {} while (0)
742 #endif
743
744 #endif /* PROP_TXSTATUS */
745
746 extern void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar);
747 extern void dhd_wait_event_wakeup(dhd_pub_t*dhd);
748
749 #ifdef ARP_OFFLOAD_SUPPORT
750 #define MAX_IPV4_ENTRIES        8
751 /* dhd_commn arp offload wrapers */
752 void dhd_aoe_hostip_clr(dhd_pub_t *dhd);
753 void dhd_aoe_arp_clr(dhd_pub_t *dhd);
754 int dhd_arp_get_arp_hostip_table(dhd_pub_t *dhd, void *buf, int buflen);
755 void dhd_arp_offload_add_ip(dhd_pub_t *dhd, uint32 ipaddr);
756 #endif /* ARP_OFFLOAD_SUPPORT */
757
758 #endif /* _dhd_h_ */