Merge tag 'lsk-v4.4-16.06-android'
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rkwifi / 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-2016, 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  *
28  * <<Broadcom-WL-IPTag/Open:>>
29  *
30  * $Id: dhd.h 610267 2016-01-06 16:03:53Z $
31  */
32
33 /****************
34  * Common types *
35  */
36
37 #ifndef _dhd_h_
38 #define _dhd_h_
39
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 #include <dhd_buzzz.h>
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 int get_scheduler_policy(struct task_struct *p);
60 #define MAX_EVENT       16
61
62 #define ALL_INTERFACES  0xff
63
64 #include <wlioctl.h>
65 #include <wlfc_proto.h>
66 #include <hnd_pktq.h>
67
68 #if defined(BCMWDF)
69 #include <wdf.h>
70 #include <WdfMiniport.h>
71 #endif /* (BCMWDF)  */
72
73 #ifdef DEBUG_DPC_THREAD_WATCHDOG
74 #define MAX_RESCHED_CNT 600
75 #endif /* DEBUG_DPC_THREAD_WATCHDOG */
76
77 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0) && LINUX_VERSION_CODE < \
78         KERNEL_VERSION(3, 18, 0) || defined(CONFIG_BCMDHD_VENDOR_EXT))
79 #define WL_VENDOR_EXT_SUPPORT
80 #endif /* 3.13.0 <= LINUX_KERNEL_VERSION < 3.18.0 || CONFIG_BCMDHD_VENDOR_EXT */
81 #if defined(CONFIG_ANDROID) && defined(WL_VENDOR_EXT_SUPPORT)
82 #if !defined(GSCAN_SUPPORT)
83 #define GSCAN_SUPPORT
84 #endif
85 #endif /* CONFIG_ANDROID && WL_VENDOR_EXT_SUPPORT */
86
87 #if defined(KEEP_ALIVE)
88 /* Default KEEP_ALIVE Period is 55 sec to prevent AP from sending Keep Alive probe frame */
89 #define KEEP_ALIVE_PERIOD 55000
90 #define NULL_PKT_STR    "null_pkt"
91 #endif /* KEEP_ALIVE */
92
93 /* Forward decls */
94 struct dhd_bus;
95 struct dhd_prot;
96 struct dhd_info;
97 struct dhd_ioctl;
98
99 /* The level of bus communication with the dongle */
100 enum dhd_bus_state {
101         DHD_BUS_DOWN,           /* Not ready for frame transfers */
102         DHD_BUS_LOAD,           /* Download access only (CPU reset) */
103         DHD_BUS_DATA,           /* Ready for frame transfers */
104         DHD_BUS_SUSPEND,        /* Bus has been suspended */
105         DHD_BUS_DOWN_IN_PROGRESS,       /* Bus going Down */
106 };
107
108 /*
109  * Bit fields to Indicate clean up process that wait till they are finished.
110  * Future synchronizable processes can add their bit filed below and update
111  * their functionalities accordingly
112  */
113 #define DHD_BUS_BUSY_IN_TX                   0x01
114 #define DHD_BUS_BUSY_IN_SEND_PKT             0x02
115 #define DHD_BUS_BUSY_IN_DPC                  0x04
116 #define DHD_BUS_BUSY_IN_WD                   0x08
117 #define DHD_BUS_BUSY_IN_IOVAR                0x10
118 #define DHD_BUS_BUSY_IN_DHD_IOVAR            0x20
119 #define DHD_BUS_BUSY_IN_SUSPEND              0x40
120 #define DHD_BUS_BUSY_IN_RESUME               0x80
121 #define DHD_BUS_BUSY_RPM_SUSPEND_IN_PROGRESS 0x100
122 #define DHD_BUS_BUSY_RPM_SUSPEND_DONE        0x200
123 #define DHD_BUS_BUSY_RPM_RESUME_IN_PROGRESS  0x400
124 #define DHD_BUS_BUSY_RPM_ALL                 (DHD_BUS_BUSY_RPM_SUSPEND_DONE | \
125                 DHD_BUS_BUSY_RPM_SUSPEND_IN_PROGRESS | \
126                 DHD_BUS_BUSY_RPM_RESUME_IN_PROGRESS)
127
128 /* Download Types */
129 typedef enum download_type {
130         FW,
131         NVRAM
132 } download_type_t;
133
134
135 /* For supporting multiple interfaces */
136 #define DHD_MAX_IFS     16
137 #define DHD_DEL_IF      -0xE
138 #define DHD_BAD_IF      -0xF
139
140 enum dhd_op_flags {
141 /* Firmware requested operation mode */
142         DHD_FLAG_STA_MODE                               = (1 << (0)), /* STA only */
143         DHD_FLAG_HOSTAP_MODE                            = (1 << (1)), /* SOFTAP only */
144         DHD_FLAG_P2P_MODE                               = (1 << (2)), /* P2P Only */
145         /* STA + P2P */
146         DHD_FLAG_CONCURR_SINGLE_CHAN_MODE = (DHD_FLAG_STA_MODE | DHD_FLAG_P2P_MODE),
147         DHD_FLAG_CONCURR_MULTI_CHAN_MODE                = (1 << (4)), /* STA + P2P */
148         /* Current P2P mode for P2P connection */
149         DHD_FLAG_P2P_GC_MODE                            = (1 << (5)),
150         DHD_FLAG_P2P_GO_MODE                            = (1 << (6)),
151         DHD_FLAG_MBSS_MODE                              = (1 << (7)), /* MBSS in future */
152         DHD_FLAG_IBSS_MODE                              = (1 << (8)),
153         DHD_FLAG_MFG_MODE                               = (1 << (9)),
154         DHD_FLAG_RSDB_MODE                              = (1 << (10)),
155         DHD_FLAG_MP2P_MODE                              = (1 << (11))
156 };
157
158 #define DHD_OPMODE_SUPPORTED(dhd, opmode_flag) \
159         (dhd ? ((((dhd_pub_t *)dhd)->op_mode)  &  opmode_flag) : -1)
160
161 /* Max sequential TX/RX Control timeouts to set HANG event */
162 #ifndef MAX_CNTL_TX_TIMEOUT
163 #define MAX_CNTL_TX_TIMEOUT 2
164 #endif /* MAX_CNTL_TX_TIMEOUT */
165 #ifndef MAX_CNTL_RX_TIMEOUT
166 #define MAX_CNTL_RX_TIMEOUT 1
167 #endif /* MAX_CNTL_RX_TIMEOUT */
168
169 #define DHD_SCAN_ASSOC_ACTIVE_TIME      40 /* ms: Embedded default Active setting from DHD */
170 #define DHD_SCAN_UNASSOC_ACTIVE_TIME 80 /* ms: Embedded def. Unassoc Active setting from DHD */
171 #define DHD_SCAN_PASSIVE_TIME           130 /* ms: Embedded default Passive setting from DHD */
172
173 #ifndef POWERUP_MAX_RETRY
174 #define POWERUP_MAX_RETRY       1 /* how many times we retry to power up the chip */
175 #endif
176 #ifndef POWERUP_WAIT_MS
177 #define POWERUP_WAIT_MS         2000 /* ms: time out in waiting wifi to come up */
178 #endif
179 #define MAX_NVRAMBUF_SIZE       (16 * 1024) /* max nvram buf size */
180 #ifdef DHD_DEBUG
181 #define DHD_JOIN_MAX_TIME_DEFAULT 10000 /* ms: Max time out for joining AP */
182 #define DHD_SCAN_DEF_TIMEOUT 10000 /* ms: Max time out for scan in progress */
183 #endif
184
185 #define FW_VER_STR_LEN  128
186
187 enum dhd_bus_wake_state {
188         WAKE_LOCK_OFF,
189         WAKE_LOCK_PRIV,
190         WAKE_LOCK_DPC,
191         WAKE_LOCK_IOCTL,
192         WAKE_LOCK_DOWNLOAD,
193         WAKE_LOCK_TMOUT,
194         WAKE_LOCK_WATCHDOG,
195         WAKE_LOCK_LINK_DOWN_TMOUT,
196         WAKE_LOCK_PNO_FIND_TMOUT,
197         WAKE_LOCK_SOFTAP_SET,
198         WAKE_LOCK_SOFTAP_STOP,
199         WAKE_LOCK_SOFTAP_START,
200         WAKE_LOCK_SOFTAP_THREAD
201 };
202
203 enum dhd_prealloc_index {
204         DHD_PREALLOC_PROT = 0,
205         DHD_PREALLOC_RXBUF,
206         DHD_PREALLOC_DATABUF,
207         DHD_PREALLOC_OSL_BUF,
208 #if defined(STATIC_WL_PRIV_STRUCT)
209         DHD_PREALLOC_WIPHY_ESCAN0 = 5,
210 #endif /* STATIC_WL_PRIV_STRUCT */
211         DHD_PREALLOC_DHD_INFO = 7,
212         DHD_PREALLOC_DHD_WLFC_INFO = 8,
213         DHD_PREALLOC_IF_FLOW_LKUP = 9,
214         DHD_PREALLOC_MEMDUMP_BUF = 10,
215         DHD_PREALLOC_MEMDUMP_RAM = 11,
216         DHD_PREALLOC_DHD_WLFC_HANGER = 12,
217         DHD_PREALLOC_PKTID_MAP = 13,
218         DHD_PREALLOC_PKTID_MAP_IOCTL = 14,
219         DHD_PREALLOC_DHD_LOG_DUMP_BUF = 15
220 };
221
222 enum dhd_dongledump_mode {
223         DUMP_DISABLED = 0,
224         DUMP_MEMONLY,
225         DUMP_MEMFILE,
226         DUMP_MEMFILE_BUGON,
227         DUMP_MEMFILE_MAX
228 };
229
230 enum dhd_dongledump_type {
231         DUMP_TYPE_RESUMED_ON_TIMEOUT = 1,
232         DUMP_TYPE_D3_ACK_TIMEOUT,
233         DUMP_TYPE_DONGLE_TRAP,
234         DUMP_TYPE_MEMORY_CORRUPTION,
235         DUMP_TYPE_PKTID_AUDIT_FAILURE,
236         DUMP_TYPE_SCAN_TIMEOUT,
237         DUMP_TYPE_SCAN_BUSY,
238         DUMP_TYPE_BY_SYSDUMP,
239         DUMP_TYPE_BY_LIVELOCK,
240         DUMP_TYPE_AP_LINKUP_FAILURE
241 };
242
243 enum dhd_hang_reason {
244         HANG_REASON_MASK = 0x8000,
245         HANG_REASON_IOCTL_RESP_TIMEOUT = 0x8001,
246         HANG_REASON_DONGLE_TRAP = 0x8002,
247         HANG_REASON_D3_ACK_TIMEOUT = 0x8003,
248         HANG_REASON_BUS_DOWN = 0x8004,
249         HANG_REASON_PCIE_LINK_DOWN = 0x8005,
250         HANG_REASON_MSGBUF_LIVELOCK = 0x8006,
251         HANG_REASON_P2P_IFACE_DEL_FAILURE = 0x8007,
252         HANG_REASON_HT_AVAIL_ERROR = 0x8008,
253         HANG_REASON_PCIE_RC_LINK_UP_FAIL = 0x8009,
254         HANG_REASON_MAX = 0x800a
255 };
256
257 enum dhd_rsdb_scan_features {
258         /* Downgraded scan feature for AP active */
259         RSDB_SCAN_DOWNGRADED_AP_SCAN = 0x01,
260         /* Downgraded scan feature for P2P Discovery */
261         RSDB_SCAN_DOWNGRADED_P2P_DISC_SCAN = 0x02,
262         /* Enable channel pruning for ROAM SCAN */
263         RSDB_SCAN_DOWNGRADED_CH_PRUNE_ROAM = 0x10,
264         /* Enable channel pruning for any SCAN */
265         RSDB_SCAN_DOWNGRADED_CH_PRUNE_ALL  = 0x20
266 };
267
268 /* Packet alignment for most efficient SDIO (can change based on platform) */
269 #ifndef DHD_SDALIGN
270 #define DHD_SDALIGN     32
271 #endif
272
273 /**
274  * DMA-able buffer parameters
275  * - dmaaddr_t is 32bits on a 32bit host.
276  *   dhd_dma_buf::pa may not be used as a sh_addr_t, bcm_addr64_t or uintptr
277  * - dhd_dma_buf::_alloced is ONLY for freeing a DMA-able buffer.
278  */
279 typedef struct dhd_dma_buf {
280         void      *va;      /* virtual address of buffer */
281         uint32    len;      /* user requested buffer length */
282         dmaaddr_t pa;       /* physical address of buffer */
283         void      *dmah;    /* dma mapper handle */
284         void      *secdma;  /* secure dma sec_cma_info handle */
285         uint32    _alloced; /* actual size of buffer allocated with align and pad */
286 } dhd_dma_buf_t;
287
288 /* host reordering packts logic */
289 /* followed the structure to hold the reorder buffers (void **p) */
290 typedef struct reorder_info {
291         void **p;
292         uint8 flow_id;
293         uint8 cur_idx;
294         uint8 exp_idx;
295         uint8 max_idx;
296         uint8 pend_pkts;
297 } reorder_info_t;
298
299 #ifdef DHDTCPACK_SUPPRESS
300
301 enum {
302         /* TCPACK suppress off */
303         TCPACK_SUP_OFF,
304         /* Replace TCPACK in txq when new coming one has higher ACK number. */
305         TCPACK_SUP_REPLACE,
306         /* TCPACK_SUP_REPLACE + delayed TCPACK TX unless ACK to PSH DATA.
307          * This will give benefits to Half-Duplex bus interface(e.g. SDIO) that
308          * 1. we are able to read TCP DATA packets first from the bus
309          * 2. TCPACKs that don't need to hurry delivered remains longer in TXQ so can be suppressed.
310          */
311         TCPACK_SUP_DELAYTX,
312         TCPACK_SUP_HOLD,
313         TCPACK_SUP_LAST_MODE
314 };
315 #endif /* DHDTCPACK_SUPPRESS */
316
317
318 /*
319  * Accumulating the queue lengths of all flowring queues in a parent object,
320  * to assert flow control, when the cummulative queue length crosses an upper
321  * threshold defined on a parent object. Upper threshold may be maintained
322  * at a station level, at an interface level, or at a dhd instance.
323  *
324  * cumm_ctr_t abstraction:
325  * cumm_ctr_t abstraction may be enhanced to use an object with a hysterisis
326  * pause on/off threshold callback.
327  * All macros use the address of the cummulative length in the parent objects.
328  *
329  * BCM_GMAC3 builds use a single perimeter lock, as opposed to a per queue lock.
330  * Cummulative counters in parent objects may be updated without spinlocks.
331  *
332  * In non BCM_GMAC3, if a cummulative queue length is desired across all flows
333  * belonging to either of (a station, or an interface or a dhd instance), then
334  * an atomic operation is required using an atomic_t cummulative counters or
335  * using a spinlock. BCM_ROUTER_DHD uses the Linux atomic_t construct.
336  */
337
338 /* Cummulative length not supported. */
339 typedef uint32 cumm_ctr_t;
340 #define DHD_CUMM_CTR_PTR(clen)     ((cumm_ctr_t*)(clen))
341 #define DHD_CUMM_CTR(clen)         *(DHD_CUMM_CTR_PTR(clen)) /* accessor */
342 #define DHD_CUMM_CTR_READ(clen)    DHD_CUMM_CTR(clen) /* read access */
343 #define DHD_CUMM_CTR_INIT(clen)                                                \
344         ASSERT(DHD_CUMM_CTR_PTR(clen) != DHD_CUMM_CTR_PTR(NULL));
345 #define DHD_CUMM_CTR_INCR(clen)                                                \
346         ASSERT(DHD_CUMM_CTR_PTR(clen) != DHD_CUMM_CTR_PTR(NULL));
347 #define DHD_CUMM_CTR_DECR(clen)                                                \
348         ASSERT(DHD_CUMM_CTR_PTR(clen) != DHD_CUMM_CTR_PTR(NULL));
349
350 /* DMA'ing r/w indices for rings supported */
351 #ifdef BCM_INDX_TCM /* FW gets r/w indices in TCM */
352 #define DMA_INDX_ENAB(dma_indxsup)      0
353 #elif defined BCM_INDX_DMA  /* FW gets r/w indices from Host memory */
354 #define DMA_INDX_ENAB(dma_indxsup)      1
355 #else   /* r/w indices in TCM or host memory based on FW/Host agreement */
356 #define DMA_INDX_ENAB(dma_indxsup)      dma_indxsup
357 #endif  /* BCM_INDX_TCM */
358
359 #if defined(WLTDLS) && defined(PCIE_FULL_DONGLE)
360 struct tdls_peer_node {
361         uint8 addr[ETHER_ADDR_LEN];
362         struct tdls_peer_node *next;
363 };
364 typedef struct tdls_peer_node tdls_peer_node_t;
365 typedef struct {
366         tdls_peer_node_t *node;
367         uint8 tdls_peer_count;
368 } tdls_peer_tbl_t;
369 #endif /* defined(WLTDLS) && defined(PCIE_FULL_DONGLE) */
370
371 #ifdef DHD_LOG_DUMP
372 /* below structure describe ring buffer. */
373 struct dhd_log_dump_buf
374 {
375         spinlock_t lock;
376         unsigned int wraparound;
377         unsigned long max;
378         unsigned int remain;
379         char* present;
380         char* front;
381         char* buffer;
382 };
383
384 #define DHD_LOG_DUMP_BUFFER_SIZE        (1024 * 1024)
385 #define DHD_LOG_DUMP_MAX_TEMP_BUFFER_SIZE 256
386
387 extern void dhd_log_dump_print(const char *fmt, ...);
388 extern char *dhd_log_dump_get_timestamp(void);
389 #endif /* DHD_LOG_DUMP */
390 #define DHD_COMMON_DUMP_PATH    "/data/misc/wifi/log/"
391
392 /* Common structure for module and instance linkage */
393 typedef struct dhd_pub {
394         /* Linkage ponters */
395         osl_t *osh;             /* OSL handle */
396         struct dhd_bus *bus;    /* Bus module handle */
397         struct dhd_prot *prot;  /* Protocol module handle */
398         struct dhd_info  *info; /* Info module handle */
399
400         /* to NDIS developer, the structure dhd_common is redundant,
401          * please do NOT merge it back from other branches !!!
402          */
403
404
405         /* Internal dhd items */
406         bool up;                /* Driver up/down (to OS) */
407         bool txoff;             /* Transmit flow-controlled */
408         bool dongle_reset;  /* TRUE = DEVRESET put dongle into reset */
409         enum dhd_bus_state busstate;
410         uint dhd_bus_busy_state;        /* Bus busy state */
411         uint hdrlen;            /* Total DHD header length (proto + bus) */
412         uint maxctl;            /* Max size rxctl request from proto to bus */
413         uint rxsz;              /* Rx buffer size bus module should use */
414         uint8 wme_dp;   /* wme discard priority */
415
416         /* Dongle media info */
417         bool iswl;              /* Dongle-resident driver is wl */
418         ulong drv_version;      /* Version of dongle-resident driver */
419         struct ether_addr mac;  /* MAC address obtained from dongle */
420         dngl_stats_t dstats;    /* Stats for dongle-based data */
421
422         /* Additional stats for the bus level */
423         ulong tx_packets;       /* Data packets sent to dongle */
424         ulong tx_dropped;       /* Data packets dropped in dhd */
425         ulong tx_multicast;     /* Multicast data packets sent to dongle */
426         ulong tx_errors;        /* Errors in sending data to dongle */
427         ulong tx_ctlpkts;       /* Control packets sent to dongle */
428         ulong tx_ctlerrs;       /* Errors sending control frames to dongle */
429         ulong rx_packets;       /* Packets sent up the network interface */
430         ulong rx_multicast;     /* Multicast packets sent up the network interface */
431         ulong rx_errors;        /* Errors processing rx data packets */
432         ulong rx_ctlpkts;       /* Control frames processed from dongle */
433         ulong rx_ctlerrs;       /* Errors in processing rx control frames */
434         ulong rx_dropped;       /* Packets dropped locally (no memory) */
435         ulong rx_flushed;  /* Packets flushed due to unscheduled sendup thread */
436         ulong wd_dpc_sched;   /* Number of times dhd dpc scheduled by watchdog timer */
437         ulong rx_pktgetfail; /* Number of PKTGET failures in DHD on RX */
438         ulong tx_pktgetfail; /* Number of PKTGET failures in DHD on TX */
439         ulong rx_readahead_cnt; /* Number of packets where header read-ahead was used. */
440         ulong tx_realloc;       /* Number of tx packets we had to realloc for headroom */
441         ulong fc_packets;       /* Number of flow control pkts recvd */
442
443         /* Last error return */
444         int bcmerror;
445         uint tickcnt;
446
447         /* Last error from dongle */
448         int dongle_error;
449
450         uint8 country_code[WLC_CNTRY_BUF_SZ];
451
452         /* Suspend disable flag and "in suspend" flag */
453         int suspend_disable_flag; /* "1" to disable all extra powersaving during suspend */
454         int in_suspend;                 /* flag set to 1 when early suspend called */
455 #ifdef PNO_SUPPORT
456         int pno_enable;                 /* pno status : "1" is pno enable */
457         int pno_suspend;                /* pno suspend status : "1" is pno suspended */
458 #endif /* PNO_SUPPORT */
459         /* DTIM skip value, default 0(or 1) means wake each DTIM
460          * 3 means skip 2 DTIMs and wake up 3rd DTIM(9th beacon when AP DTIM is 3)
461          */
462         int suspend_bcn_li_dtim;         /* bcn_li_dtim value in suspend mode */
463 #ifdef PKT_FILTER_SUPPORT
464         int early_suspended;    /* Early suspend status */
465         int dhcp_in_progress;   /* DHCP period */
466 #endif
467
468         /* Pkt filter defination */
469         char * pktfilter[100];
470         int pktfilter_count;
471
472         wl_country_t dhd_cspec;         /* Current Locale info */
473 #ifdef CUSTOM_COUNTRY_CODE
474         u32 dhd_cflags;
475 #endif /* CUSTOM_COUNTRY_CODE */
476         bool force_country_change;
477         char eventmask[WL_EVENTING_MASK_LEN];
478         int     op_mode;                                /* STA, HostAPD, WFD, SoftAP */
479
480 /* Set this to 1 to use a seperate interface (p2p0) for p2p operations.
481  *  For ICS MR1 releases it should be disable to be compatable with ICS MR1 Framework
482  *  see target dhd-cdc-sdmmc-panda-cfg80211-icsmr1-gpl-debug in Makefile
483  */
484 /* #define WL_ENABLE_P2P_IF             1 */
485
486 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
487         struct mutex    wl_start_stop_lock; /* lock/unlock for Android start/stop */
488         struct mutex    wl_softap_lock;          /* lock/unlock for any SoftAP/STA settings */
489 #endif 
490
491 #ifdef PROP_TXSTATUS
492         bool    wlfc_enabled;
493         int     wlfc_mode;
494         void*   wlfc_state;
495         /*
496         Mode in which the dhd flow control shall operate. Must be set before
497         traffic starts to the device.
498         0 - Do not do any proptxtstatus flow control
499         1 - Use implied credit from a packet status
500         2 - Use explicit credit
501         3 - Only AMPDU hostreorder used. no wlfc.
502         */
503         uint8   proptxstatus_mode;
504         bool    proptxstatus_txoff;
505         bool    proptxstatus_module_ignore;
506         bool    proptxstatus_credit_ignore;
507         bool    proptxstatus_txstatus_ignore;
508
509         bool    wlfc_rxpkt_chk;
510         /*
511          * implement below functions in each platform if needed.
512          */
513         /* platform specific function whether to skip flow control */
514         bool (*skip_fc)(void);
515         /* platform specific function for wlfc_enable and wlfc_deinit */
516         void (*plat_init)(void *dhd);
517         void (*plat_deinit)(void *dhd);
518 #ifdef DHD_WLFC_THREAD
519         bool                wlfc_thread_go;
520         struct task_struct* wlfc_thread;
521         wait_queue_head_t   wlfc_wqhead;
522 #endif /* DHD_WLFC_THREAD */
523 #endif /* PROP_TXSTATUS */
524 #ifdef PNO_SUPPORT
525         void *pno_state;
526 #endif
527 #ifdef RTT_SUPPORT
528         void *rtt_state;
529 #endif
530         bool    dongle_isolation;
531         bool    dongle_trap_occured;    /* flag for sending HANG event to upper layer */
532         int   hang_was_sent;
533         int   rxcnt_timeout;            /* counter rxcnt timeout to send HANG */
534         int   txcnt_timeout;            /* counter txcnt timeout to send HANG */
535 #ifdef BCMPCIE
536         int   d3ackcnt_timeout;         /* counter d3ack timeout to send HANG */
537 #endif /* BCMPCIE */
538         bool hang_report;               /* enable hang report by default */
539         uint16 hang_reason;             /* reason codes for HANG event */
540 #ifdef WLMEDIA_HTSF
541         uint8 htsfdlystat_sz; /* Size of delay stats, max 255B */
542 #endif
543 #ifdef WLTDLS
544         bool tdls_enable;
545 #endif
546         struct reorder_info *reorder_bufs[WLHOST_REORDERDATA_MAXFLOWS];
547         #define WLC_IOCTL_MAXBUF_FWCAP  512
548         char  fw_capabilities[WLC_IOCTL_MAXBUF_FWCAP];
549         #define MAXSKBPEND 1024
550         void *skbbuf[MAXSKBPEND];
551         uint32 store_idx;
552         uint32 sent_idx;
553 #ifdef DHDTCPACK_SUPPRESS
554         uint8 tcpack_sup_mode;          /* TCPACK suppress mode */
555         void *tcpack_sup_module;        /* TCPACK suppress module */
556         uint32 tcpack_sup_ratio;
557         uint32 tcpack_sup_delay;
558 #endif /* DHDTCPACK_SUPPRESS */
559 #if defined(ARP_OFFLOAD_SUPPORT)
560         uint32 arp_version;
561 #endif
562 #ifdef DEBUG_DPC_THREAD_WATCHDOG
563         bool dhd_bug_on;
564 #endif /* DEBUG_DPC_THREAD_WATCHDOG */
565 #ifdef CUSTOM_SET_CPUCORE
566         struct task_struct * current_dpc;
567         struct task_struct * current_rxf;
568         int chan_isvht80;
569 #endif /* CUSTOM_SET_CPUCORE */
570
571
572         void    *sta_pool;          /* pre-allocated pool of sta objects */
573         void    *staid_allocator;   /* allocator of sta indexes */
574 #ifdef PCIE_FULL_DONGLE
575         bool    flow_rings_inited;      /* set this flag after initializing flow rings */
576 #endif /* PCIE_FULL_DONGLE */
577         void    *flowid_allocator;  /* unique flowid allocator */
578         void    *flow_ring_table;   /* flow ring table, include prot and bus info */
579         void    *if_flow_lkup;      /* per interface flowid lkup hash table */
580         void    *flowid_lock;       /* per os lock for flowid info protection */
581         void    *flowring_list_lock;       /* per os lock for flowring list protection */
582         uint32  num_flow_rings;
583         cumm_ctr_t cumm_ctr;        /* cumm queue length placeholder  */
584         uint32 d2h_sync_mode;       /* D2H DMA completion sync mode */
585         uint8  flow_prio_map[NUMPRIO];
586         uint8   flow_prio_map_type;
587         char enable_log[MAX_EVENT];
588         bool dma_d2h_ring_upd_support;
589         bool dma_h2d_ring_upd_support;
590
591 #ifdef DHD_WMF
592         bool wmf_ucast_igmp;
593 #ifdef DHD_IGMP_UCQUERY
594         bool wmf_ucast_igmp_query;
595 #endif
596 #ifdef DHD_UCAST_UPNP
597         bool wmf_ucast_upnp;
598 #endif
599 #endif /* DHD_WMF */
600 #ifdef DHD_L2_FILTER
601         unsigned long l2_filter_cnt;    /* for L2_FILTER ARP table timeout */
602 #endif /* DHD_L2_FILTER */
603         uint8 *soc_ram;
604         uint32 soc_ram_length;
605         uint32 memdump_type;
606 #ifdef DHD_FW_COREDUMP
607         uint32 memdump_enabled;
608 #endif /* DHD_FW_COREDUMP */
609 #ifdef PCIE_FULL_DONGLE
610 #ifdef WLTDLS
611         tdls_peer_tbl_t peer_tbl;
612 #endif /* WLTDLS */
613 #endif /* PCIE_FULL_DONGLE */
614 #ifdef CACHE_FW_IMAGES
615         char    *cached_fw;
616         int     cached_fw_length;
617         char    *cached_nvram;
618         int     cached_nvram_length;
619 #endif
620 #ifdef WLTDLS
621         uint32 tdls_mode;
622 #endif
623 #ifdef DHD_LOSSLESS_ROAMING
624         uint8 dequeue_prec_map;
625 #endif
626         struct mutex wl_up_lock;
627         bool is_fw_download_done;
628 #ifdef DHD_LOG_DUMP
629         struct dhd_log_dump_buf dld_buf;
630         unsigned int dld_enable;
631 #endif /* DHD_LOG_DUMP */
632         char            *conf_path;             /* module_param: path to config vars file */
633         struct dhd_conf *conf;  /* Bus module handle */
634 } dhd_pub_t;
635
636 #if defined(PCIE_FULL_DONGLE)
637
638 /* Packet Tag for PCIE Full Dongle DHD */
639 typedef struct dhd_pkttag_fd {
640         uint16    flowid;   /* Flowring Id */
641         uint16    dataoff;  /* start of packet */
642         uint16    dma_len;  /* pkt len for DMA_MAP/UNMAP */
643         dmaaddr_t pa;       /* physical address */
644         void      *dmah;    /* dma mapper handle */
645         void      *secdma; /* secure dma sec_cma_info handle */
646 } dhd_pkttag_fd_t;
647
648 /* Packet Tag for DHD PCIE Full Dongle */
649 #define DHD_PKTTAG_FD(pkt)          ((dhd_pkttag_fd_t *)(PKTTAG(pkt)))
650
651 #define DHD_PKT_GET_FLOWID(pkt)     ((DHD_PKTTAG_FD(pkt))->flowid)
652 #define DHD_PKT_SET_FLOWID(pkt, pkt_flowid) \
653         DHD_PKTTAG_FD(pkt)->flowid = (uint16)(pkt_flowid)
654
655 #define DHD_PKT_GET_DATAOFF(pkt)    ((DHD_PKTTAG_FD(pkt))->dataoff)
656 #define DHD_PKT_SET_DATAOFF(pkt, pkt_dataoff) \
657         DHD_PKTTAG_FD(pkt)->dataoff = (uint16)(pkt_dataoff)
658
659 #define DHD_PKT_GET_DMA_LEN(pkt)    ((DHD_PKTTAG_FD(pkt))->dma_len)
660 #define DHD_PKT_SET_DMA_LEN(pkt, pkt_dma_len) \
661         DHD_PKTTAG_FD(pkt)->dma_len = (uint16)(pkt_dma_len)
662
663 #define DHD_PKT_GET_PA(pkt)         ((DHD_PKTTAG_FD(pkt))->pa)
664 #define DHD_PKT_SET_PA(pkt, pkt_pa) \
665         DHD_PKTTAG_FD(pkt)->pa = (dmaaddr_t)(pkt_pa)
666
667 #define DHD_PKT_GET_DMAH(pkt)       ((DHD_PKTTAG_FD(pkt))->dmah)
668 #define DHD_PKT_SET_DMAH(pkt, pkt_dmah) \
669         DHD_PKTTAG_FD(pkt)->dmah = (void *)(pkt_dmah)
670
671 #define DHD_PKT_GET_SECDMA(pkt)    ((DHD_PKTTAG_FD(pkt))->secdma)
672 #define DHD_PKT_SET_SECDMA(pkt, pkt_secdma) \
673         DHD_PKTTAG_FD(pkt)->secdma = (void *)(pkt_secdma)
674 #endif /* PCIE_FULL_DONGLE */
675
676 #if defined(BCMWDF)
677 typedef struct {
678         dhd_pub_t *dhd_pub;
679 } dhd_workitem_context_t;
680
681 WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(dhd_workitem_context_t, dhd_get_dhd_workitem_context)
682 #endif /* (BCMWDF)  */
683
684         #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP)
685
686         #define DHD_PM_RESUME_WAIT_INIT(a) DECLARE_WAIT_QUEUE_HEAD(a);
687         #define _DHD_PM_RESUME_WAIT(a, b) do {\
688                         int retry = 0; \
689                         SMP_RD_BARRIER_DEPENDS(); \
690                         while (dhd_mmc_suspend && retry++ != b) { \
691                                 SMP_RD_BARRIER_DEPENDS(); \
692                                 wait_event_interruptible_timeout(a, !dhd_mmc_suspend, 1); \
693                         } \
694                 }       while (0)
695         #define DHD_PM_RESUME_WAIT(a)           _DHD_PM_RESUME_WAIT(a, 200)
696         #define DHD_PM_RESUME_WAIT_FOREVER(a)   _DHD_PM_RESUME_WAIT(a, ~0)
697         #define DHD_PM_RESUME_RETURN_ERROR(a)   do { \
698                         if (dhd_mmc_suspend) { \
699                                 printf("%s[%d]: mmc is still in suspend state!!!\n", \
700                                         __FUNCTION__, __LINE__); \
701                                 return a; \
702                         } \
703                 } while (0)
704         #define DHD_PM_RESUME_RETURN            do { if (dhd_mmc_suspend) return; } while (0)
705
706         #define DHD_SPINWAIT_SLEEP_INIT(a) DECLARE_WAIT_QUEUE_HEAD(a);
707         #define SPINWAIT_SLEEP(a, exp, us) do { \
708                 uint countdown = (us) + 9999; \
709                 while ((exp) && (countdown >= 10000)) { \
710                         wait_event_interruptible_timeout(a, FALSE, 1); \
711                         countdown -= 10000; \
712                 } \
713         } while (0)
714
715         #else
716
717         #define DHD_PM_RESUME_WAIT_INIT(a)
718         #define DHD_PM_RESUME_WAIT(a)
719         #define DHD_PM_RESUME_WAIT_FOREVER(a)
720         #define DHD_PM_RESUME_RETURN_ERROR(a)
721         #define DHD_PM_RESUME_RETURN
722
723         #define DHD_SPINWAIT_SLEEP_INIT(a)
724         #define SPINWAIT_SLEEP(a, exp, us)  do { \
725                 uint countdown = (us) + 9; \
726                 while ((exp) && (countdown >= 10)) { \
727                         OSL_DELAY(10);  \
728                         countdown -= 10;  \
729                 } \
730         } while (0)
731
732         #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP) */
733
734 #ifndef OSL_SLEEP
735 #define OSL_SLEEP(ms)           OSL_DELAY(ms*1000)
736 #endif /* OSL_SLEEP */
737
738 #define DHD_IF_VIF      0x01    /* Virtual IF (Hidden from user) */
739
740 #ifdef PNO_SUPPORT
741 int dhd_pno_clean(dhd_pub_t *dhd);
742 #endif /* PNO_SUPPORT */
743 /*
744  *  Wake locks are an Android power management concept. They are used by applications and services
745  *  to request CPU resources.
746  */
747 extern int dhd_os_wake_lock(dhd_pub_t *pub);
748 extern int dhd_os_wake_unlock(dhd_pub_t *pub);
749 extern int dhd_event_wake_lock(dhd_pub_t *pub);
750 extern int dhd_event_wake_unlock(dhd_pub_t *pub);
751 extern int dhd_os_wake_lock_waive(dhd_pub_t *pub);
752 extern int dhd_os_wake_lock_restore(dhd_pub_t *pub);
753 extern int dhd_os_wake_lock_timeout(dhd_pub_t *pub);
754 extern int dhd_os_wake_lock_rx_timeout_enable(dhd_pub_t *pub, int val);
755 extern int dhd_os_wake_lock_ctrl_timeout_enable(dhd_pub_t *pub, int val);
756 extern int dhd_os_wake_lock_ctrl_timeout_cancel(dhd_pub_t *pub);
757 extern int dhd_os_wd_wake_lock(dhd_pub_t *pub);
758 extern int dhd_os_wd_wake_unlock(dhd_pub_t *pub);
759 extern void dhd_os_wake_lock_init(struct dhd_info *dhd);
760 extern void dhd_os_wake_lock_destroy(struct dhd_info *dhd);
761 #ifdef BCMPCIE_OOB_HOST_WAKE
762 extern void dhd_os_oob_irq_wake_lock_timeout(dhd_pub_t *pub, int val);
763 extern void dhd_os_oob_irq_wake_unlock(dhd_pub_t *pub);
764 #endif /* BCMPCIE_OOB_HOST_WAKE */
765 #ifdef DHD_USE_SCAN_WAKELOCK
766 extern void dhd_os_scan_wake_lock_timeout(dhd_pub_t *pub, int val);
767 extern void dhd_os_scan_wake_unlock(dhd_pub_t *pub);
768 #endif /* BCMPCIE_SCAN_WAKELOCK */
769
770 inline static void MUTEX_LOCK_SOFTAP_SET_INIT(dhd_pub_t * dhdp)
771 {
772 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
773         mutex_init(&dhdp->wl_softap_lock);
774 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
775 }
776
777 inline static void MUTEX_LOCK_SOFTAP_SET(dhd_pub_t * dhdp)
778 {
779 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
780         mutex_lock(&dhdp->wl_softap_lock);
781 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
782 }
783
784 inline static void MUTEX_UNLOCK_SOFTAP_SET(dhd_pub_t * dhdp)
785 {
786 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
787         mutex_unlock(&dhdp->wl_softap_lock);
788 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
789 }
790
791 #define DHD_OS_WAKE_LOCK(pub)                   dhd_os_wake_lock(pub)
792 #define DHD_OS_WAKE_UNLOCK(pub)         dhd_os_wake_unlock(pub)
793 #define DHD_EVENT_WAKE_LOCK(pub)                        dhd_event_wake_lock(pub)
794 #define DHD_EVENT_WAKE_UNLOCK(pub)              dhd_event_wake_unlock(pub)
795 #define DHD_OS_WAKE_LOCK_TIMEOUT(pub)           dhd_os_wake_lock_timeout(pub)
796 #define DHD_OS_WAKE_LOCK_RX_TIMEOUT_ENABLE(pub, val) \
797         dhd_os_wake_lock_rx_timeout_enable(pub, val)
798 #define DHD_OS_WAKE_LOCK_CTRL_TIMEOUT_ENABLE(pub, val) \
799         dhd_os_wake_lock_ctrl_timeout_enable(pub, val)
800 #define DHD_OS_WAKE_LOCK_CTRL_TIMEOUT_CANCEL(pub) \
801         dhd_os_wake_lock_ctrl_timeout_cancel(pub)
802 #define DHD_OS_WAKE_LOCK_WAIVE(pub)                     dhd_os_wake_lock_waive(pub)
803 #define DHD_OS_WAKE_LOCK_RESTORE(pub)           dhd_os_wake_lock_restore(pub)
804 #define DHD_OS_WAKE_LOCK_INIT(dhd)              dhd_os_wake_lock_init(dhd);
805 #define DHD_OS_WAKE_LOCK_DESTROY(dhd)           dhd_os_wake_lock_destroy(dhd);
806
807 #define DHD_OS_WD_WAKE_LOCK(pub)                dhd_os_wd_wake_lock(pub)
808 #define DHD_OS_WD_WAKE_UNLOCK(pub)              dhd_os_wd_wake_unlock(pub)
809
810 #ifdef BCMPCIE_OOB_HOST_WAKE
811 #define OOB_WAKE_LOCK_TIMEOUT 500
812 #define DHD_OS_OOB_IRQ_WAKE_LOCK_TIMEOUT(pub, val)      dhd_os_oob_irq_wake_lock_timeout(pub, val)
813 #define DHD_OS_OOB_IRQ_WAKE_UNLOCK(pub)                 dhd_os_oob_irq_wake_unlock(pub)
814 #endif /* BCMPCIE_OOB_HOST_WAKE */
815 #ifdef DHD_USE_SCAN_WAKELOCK
816 #ifdef DHD_DEBUG_SCAN_WAKELOCK
817 #define DHD_OS_SCAN_WAKE_LOCK_TIMEOUT(pub, val) \
818         do { \
819                 printf("call wake_lock_scan: %s %d\n", \
820                         __FUNCTION__, __LINE__); \
821                 dhd_os_scan_wake_lock_timeout(pub, val); \
822         } while (0)
823 #define DHD_OS_SCAN_WAKE_UNLOCK(pub) \
824         do { \
825                 printf("call wake_unlock_scan: %s %d\n", \
826                         __FUNCTION__, __LINE__); \
827                 dhd_os_scan_wake_unlock(pub); \
828         } while (0)
829 #else
830 #define DHD_OS_SCAN_WAKE_LOCK_TIMEOUT(pub, val)         dhd_os_scan_wake_lock_timeout(pub, val)
831 #define DHD_OS_SCAN_WAKE_UNLOCK(pub)                    dhd_os_scan_wake_unlock(pub)
832 #endif /* DHD_DEBUG_SCAN_WAKELOCK */
833 #else
834 #define DHD_OS_SCAN_WAKE_LOCK_TIMEOUT(pub, val)
835 #define DHD_OS_SCAN_WAKE_UNLOCK(pub)
836 #endif /* DHD_USE_SCAN_WAKELOCK */
837 #define DHD_PACKET_TIMEOUT_MS   500
838 #define DHD_EVENT_TIMEOUT_MS    1500
839 #define SCAN_WAKE_LOCK_TIMEOUT  10000
840
841 /* Enum for IOCTL recieved status */
842 typedef enum dhd_ioctl_recieved_status
843 {
844         IOCTL_WAIT = 0,
845         IOCTL_RETURN_ON_SUCCESS,
846         IOCTL_RETURN_ON_TRAP,
847         IOCTL_RETURN_ON_BUS_STOP
848 } dhd_ioctl_recieved_status_t;
849
850 /* interface operations (register, remove) should be atomic, use this lock to prevent race
851  * condition among wifi on/off and interface operation functions
852  */
853 void dhd_net_if_lock(struct net_device *dev);
854 void dhd_net_if_unlock(struct net_device *dev);
855
856 #if defined(MULTIPLE_SUPPLICANT)
857 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) && 1
858 extern struct mutex _dhd_sdio_mutex_lock_;
859 #endif
860 #endif /* MULTIPLE_SUPPLICANT */
861
862 typedef enum dhd_attach_states
863 {
864         DHD_ATTACH_STATE_INIT = 0x0,
865         DHD_ATTACH_STATE_NET_ALLOC = 0x1,
866         DHD_ATTACH_STATE_DHD_ALLOC = 0x2,
867         DHD_ATTACH_STATE_ADD_IF = 0x4,
868         DHD_ATTACH_STATE_PROT_ATTACH = 0x8,
869         DHD_ATTACH_STATE_WL_ATTACH = 0x10,
870         DHD_ATTACH_STATE_THREADS_CREATED = 0x20,
871         DHD_ATTACH_STATE_WAKELOCKS_INIT = 0x40,
872         DHD_ATTACH_STATE_CFG80211 = 0x80,
873         DHD_ATTACH_STATE_EARLYSUSPEND_DONE = 0x100,
874         DHD_ATTACH_STATE_DONE = 0x200
875 } dhd_attach_states_t;
876
877 /* Value -1 means we are unsuccessful in creating the kthread. */
878 #define DHD_PID_KT_INVALID      -1
879 /* Value -2 means we are unsuccessful in both creating the kthread and tasklet */
880 #define DHD_PID_KT_TL_INVALID   -2
881
882 /*
883  * Exported from dhd OS modules (dhd_linux/dhd_ndis)
884  */
885
886 /* Indication from bus module regarding presence/insertion of dongle.
887  * Return dhd_pub_t pointer, used as handle to OS module in later calls.
888  * Returned structure should have bus and prot pointers filled in.
889  * bus_hdrlen specifies required headroom for bus module header.
890  */
891 extern dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen);
892 #if defined(WLP2P) && defined(WL_CFG80211)
893 /* To allow attach/detach calls corresponding to p2p0 interface  */
894 extern int dhd_attach_p2p(dhd_pub_t *);
895 extern int dhd_detach_p2p(dhd_pub_t *);
896 #endif /* WLP2P && WL_CFG80211 */
897 extern int dhd_register_if(dhd_pub_t *dhdp, int idx, bool need_rtnl_lock);
898
899 /* Indication from bus module regarding removal/absence of dongle */
900 extern void dhd_detach(dhd_pub_t *dhdp);
901 extern void dhd_free(dhd_pub_t *dhdp);
902 extern void dhd_clear(dhd_pub_t *dhdp);
903
904 /* Indication from bus module to change flow-control state */
905 extern void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool on);
906
907 /* Store the status of a connection attempt for later retrieval by an iovar */
908 extern void dhd_store_conn_status(uint32 event, uint32 status, uint32 reason);
909
910 extern bool dhd_prec_enq(dhd_pub_t *dhdp, struct pktq *q, void *pkt, int prec);
911
912 /* Receive frame for delivery to OS.  Callee disposes of rxp. */
913 extern void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *rxp, int numpkt, uint8 chan);
914
915 /* Return pointer to interface name */
916 extern char *dhd_ifname(dhd_pub_t *dhdp, int idx);
917
918 /* Request scheduling of the bus dpc */
919 extern void dhd_sched_dpc(dhd_pub_t *dhdp);
920
921 /* Notify tx completion */
922 extern void dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success);
923 extern void dhd_dpc_enable(dhd_pub_t *dhdp);
924
925 #define WIFI_FEATURE_INFRA              0x0001      /* Basic infrastructure mode        */
926 #define WIFI_FEATURE_INFRA_5G           0x0002      /* Support for 5 GHz Band           */
927 #define WIFI_FEATURE_HOTSPOT            0x0004      /* Support for GAS/ANQP             */
928 #define WIFI_FEATURE_P2P                0x0008      /* Wifi-Direct                      */
929 #define WIFI_FEATURE_SOFT_AP            0x0010      /* Soft AP                          */
930 #define WIFI_FEATURE_GSCAN              0x0020      /* Google-Scan APIs                 */
931 #define WIFI_FEATURE_NAN                0x0040      /* Neighbor Awareness Networking    */
932 #define WIFI_FEATURE_D2D_RTT            0x0080      /* Device-to-device RTT             */
933 #define WIFI_FEATURE_D2AP_RTT           0x0100      /* Device-to-AP RTT                 */
934 #define WIFI_FEATURE_BATCH_SCAN         0x0200      /* Batched Scan (legacy)            */
935 #define WIFI_FEATURE_PNO                0x0400      /* Preferred network offload        */
936 #define WIFI_FEATURE_ADDITIONAL_STA     0x0800      /* Support for two STAs             */
937 #define WIFI_FEATURE_TDLS               0x1000      /* Tunnel directed link setup       */
938 #define WIFI_FEATURE_TDLS_OFFCHANNEL    0x2000      /* Support for TDLS off channel     */
939 #define WIFI_FEATURE_EPR                0x4000      /* Enhanced power reporting         */
940 #define WIFI_FEATURE_AP_STA             0x8000      /* Support for AP STA Concurrency   */
941 #define WIFI_FEATURE_LINKSTAT           0x10000     /* Support for Linkstats            */
942
943 #define MAX_FEATURE_SET_CONCURRRENT_GROUPS  3
944
945 extern int dhd_dev_get_feature_set(struct net_device *dev);
946 extern int *dhd_dev_get_feature_set_matrix(struct net_device *dev,      int *num);
947 #ifdef CUSTOM_FORCE_NODFS_FLAG
948 extern int dhd_dev_set_nodfs(struct net_device *dev, uint nodfs);
949 #endif /* CUSTOM_FORCE_NODFS_FLAG */
950 /* OS independent layer functions */
951 extern void dhd_os_dhdiovar_lock(dhd_pub_t *pub);
952 extern void dhd_os_dhdiovar_unlock(dhd_pub_t *pub);
953 extern int dhd_os_proto_block(dhd_pub_t * pub);
954 extern int dhd_os_proto_unblock(dhd_pub_t * pub);
955 extern int dhd_os_ioctl_resp_wait(dhd_pub_t * pub, uint * condition);
956 extern int dhd_os_ioctl_resp_wake(dhd_pub_t * pub);
957 extern unsigned int dhd_os_get_ioctl_resp_timeout(void);
958 extern void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec);
959 extern void dhd_os_ioctl_resp_lock(dhd_pub_t * pub);
960 extern void dhd_os_ioctl_resp_unlock(dhd_pub_t * pub);
961 extern int dhd_wakeup_ioctl_event(dhd_pub_t *pub, dhd_ioctl_recieved_status_t reason);
962
963 #define DHD_OS_IOCTL_RESP_LOCK(x)
964 #define DHD_OS_IOCTL_RESP_UNLOCK(x)
965
966
967 extern int dhd_os_get_image_block(char * buf, int len, void * image);
968 extern void * dhd_os_open_image(char * filename);
969 extern void dhd_os_close_image(void * image);
970 extern void dhd_os_wd_timer(void *bus, uint wdtick);
971 #ifdef DHD_PCIE_RUNTIMEPM
972 extern void dhd_os_runtimepm_timer(void *bus, uint tick);
973 #endif /* DHD_PCIE_RUNTIMEPM */
974 extern void dhd_os_sdlock(dhd_pub_t * pub);
975 extern void dhd_os_sdunlock(dhd_pub_t * pub);
976 extern void dhd_os_sdlock_txq(dhd_pub_t * pub);
977 extern void dhd_os_sdunlock_txq(dhd_pub_t * pub);
978 extern void dhd_os_sdlock_rxq(dhd_pub_t * pub);
979 extern void dhd_os_sdunlock_rxq(dhd_pub_t * pub);
980 extern void dhd_os_sdlock_sndup_rxq(dhd_pub_t * pub);
981 #ifdef DHDTCPACK_SUPPRESS
982 extern unsigned long dhd_os_tcpacklock(dhd_pub_t *pub);
983 extern void dhd_os_tcpackunlock(dhd_pub_t *pub, unsigned long flags);
984 #endif /* DHDTCPACK_SUPPRESS */
985
986 extern int dhd_customer_oob_irq_map(void *adapter, unsigned long *irq_flags_ptr);
987 extern int dhd_customer_gpio_wlan_ctrl(void *adapter, int onoff);
988 extern int dhd_custom_get_mac_address(void *adapter, unsigned char *buf);
989 #ifdef CUSTOM_COUNTRY_CODE
990 extern void get_customized_country_code(void *adapter, char *country_iso_code,
991 wl_country_t *cspec, u32 flags);
992 #else
993 extern void get_customized_country_code(void *adapter, char *country_iso_code, wl_country_t *cspec);
994 #endif /* CUSTOM_COUNTRY_CODE */
995 extern void dhd_os_sdunlock_sndup_rxq(dhd_pub_t * pub);
996 extern void dhd_os_sdlock_eventq(dhd_pub_t * pub);
997 extern void dhd_os_sdunlock_eventq(dhd_pub_t * pub);
998 extern bool dhd_os_check_hang(dhd_pub_t *dhdp, int ifidx, int ret);
999 extern int dhd_os_send_hang_message(dhd_pub_t *dhdp);
1000 extern void dhd_set_version_info(dhd_pub_t *pub, char *fw);
1001 extern bool dhd_os_check_if_up(dhd_pub_t *pub);
1002 extern int dhd_os_check_wakelock(dhd_pub_t *pub);
1003 extern int dhd_os_check_wakelock_all(dhd_pub_t *pub);
1004 extern int dhd_get_instance(dhd_pub_t *pub);
1005 #ifdef CUSTOM_SET_CPUCORE
1006 extern void dhd_set_cpucore(dhd_pub_t *dhd, int set);
1007 #endif /* CUSTOM_SET_CPUCORE */
1008
1009 #if defined(KEEP_ALIVE)
1010 extern int dhd_keep_alive_onoff(dhd_pub_t *dhd);
1011 #endif /* KEEP_ALIVE */
1012
1013 #ifdef SUPPORT_AP_POWERSAVE
1014 extern int dhd_set_ap_powersave(dhd_pub_t *dhdp, int ifidx, int enable);
1015 #endif
1016
1017 #if defined(DHD_FW_COREDUMP)
1018 void dhd_schedule_memdump(dhd_pub_t *dhdp, uint8 *buf, uint32 size);
1019 #endif /* DHD_FW_COREDUMP */
1020
1021 #ifdef SUPPORT_AP_POWERSAVE
1022 extern int dhd_set_ap_powersave(dhd_pub_t *dhdp, int ifidx, int enable);
1023 #endif /* SUPPORT_AP_POWERSAVE */
1024
1025
1026 #ifdef PKT_FILTER_SUPPORT
1027 #define DHD_UNICAST_FILTER_NUM          0
1028 #define DHD_BROADCAST_FILTER_NUM        1
1029 #define DHD_MULTICAST4_FILTER_NUM       2
1030 #define DHD_MULTICAST6_FILTER_NUM       3
1031 #define DHD_MDNS_FILTER_NUM             4
1032 #define DHD_ARP_FILTER_NUM              5
1033 extern int      dhd_os_enable_packet_filter(dhd_pub_t *dhdp, int val);
1034 extern void dhd_enable_packet_filter(int value, dhd_pub_t *dhd);
1035 extern int net_os_enable_packet_filter(struct net_device *dev, int val);
1036 extern int net_os_rxfilter_add_remove(struct net_device *dev, int val, int num);
1037 #endif /* PKT_FILTER_SUPPORT */
1038
1039 extern int dhd_get_suspend_bcn_li_dtim(dhd_pub_t *dhd);
1040 extern bool dhd_support_sta_mode(dhd_pub_t *dhd);
1041
1042 extern int write_to_file(dhd_pub_t *dhd, uint8 *buf, int size);
1043
1044 typedef struct {
1045         uint32 limit;           /* Expiration time (usec) */
1046         uint32 increment;       /* Current expiration increment (usec) */
1047         uint32 elapsed;         /* Current elapsed time (usec) */
1048         uint32 tick;            /* O/S tick time (usec) */
1049 } dhd_timeout_t;
1050
1051 #ifdef SHOW_LOGTRACE
1052 typedef struct {
1053         int  num_fmts;
1054         char **fmts;
1055         char *raw_fmts;
1056         char *raw_sstr;
1057         uint32 ramstart;
1058         uint32 rodata_start;
1059         uint32 rodata_end;
1060         char *rom_raw_sstr;
1061         uint32 rom_ramstart;
1062         uint32 rom_rodata_start;
1063         uint32 rom_rodata_end;
1064 } dhd_event_log_t;
1065 #endif /* SHOW_LOGTRACE */
1066
1067 extern void dhd_timeout_start(dhd_timeout_t *tmo, uint usec);
1068 extern int dhd_timeout_expired(dhd_timeout_t *tmo);
1069
1070 extern int dhd_ifname2idx(struct dhd_info *dhd, char *name);
1071 extern int dhd_net2idx(struct dhd_info *dhd, struct net_device *net);
1072 extern struct net_device * dhd_idx2net(void *pub, int ifidx);
1073 extern int net_os_send_hang_message(struct net_device *dev);
1074 extern int net_os_send_hang_message_reason(struct net_device *dev, const char *string_num);
1075 extern bool dhd_wowl_cap(void *bus);
1076
1077 extern int wl_host_event(dhd_pub_t *dhd_pub, int *idx, void *pktdata,
1078                          wl_event_msg_t *, void **data_ptr,  void *);
1079 extern void wl_event_to_host_order(wl_event_msg_t * evt);
1080 extern int wl_host_event_get_data(void *pktdata, wl_event_msg_t *event, void **data_ptr);
1081
1082 extern int dhd_wl_ioctl(dhd_pub_t *dhd_pub, int ifindex, wl_ioctl_t *ioc, void *buf, int len);
1083 extern int dhd_wl_ioctl_cmd(dhd_pub_t *dhd_pub, int cmd, void *arg, int len, uint8 set,
1084                             int ifindex);
1085 extern int dhd_wl_ioctl_get_intiovar(dhd_pub_t *dhd_pub, char *name, uint *pval,
1086         int cmd, uint8 set, int ifidx);
1087 extern int dhd_wl_ioctl_set_intiovar(dhd_pub_t *dhd_pub, char *name, uint val,
1088         int cmd, uint8 set, int ifidx);
1089 extern void dhd_common_init(osl_t *osh);
1090
1091 extern int dhd_do_driver_init(struct net_device *net);
1092 extern int dhd_event_ifadd(struct dhd_info *dhd, struct wl_event_data_if *ifevent,
1093         char *name, uint8 *mac);
1094 extern int dhd_event_ifdel(struct dhd_info *dhd, struct wl_event_data_if *ifevent,
1095         char *name, uint8 *mac);
1096 extern struct net_device* dhd_allocate_if(dhd_pub_t *dhdpub, int ifidx, char *name,
1097         uint8 *mac, uint8 bssidx, bool need_rtnl_lock, char *dngl_name);
1098 extern int dhd_remove_if(dhd_pub_t *dhdpub, int ifidx, bool need_rtnl_lock);
1099 extern void dhd_vif_add(struct dhd_info *dhd, int ifidx, char * name);
1100 extern void dhd_vif_del(struct dhd_info *dhd, int ifidx);
1101 extern void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx);
1102 extern void dhd_vif_sendup(struct dhd_info *dhd, int ifidx, uchar *cp, int len);
1103
1104 /* Send packet to dongle via data channel */
1105 extern int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pkt);
1106
1107 /* send up locally generated event */
1108 extern void dhd_sendup_event_common(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data);
1109 /* Send event to host */
1110 extern void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data);
1111 #ifdef LOG_INTO_TCPDUMP
1112 extern void dhd_sendup_log(dhd_pub_t *dhdp, void *data, int len);
1113 #endif /* LOG_INTO_TCPDUMP */
1114 extern int dhd_bus_devreset(dhd_pub_t *dhdp, uint8 flag);
1115 extern uint dhd_bus_status(dhd_pub_t *dhdp);
1116 extern int  dhd_bus_start(dhd_pub_t *dhdp);
1117 extern int dhd_bus_suspend(dhd_pub_t *dhdpub);
1118 extern int dhd_bus_resume(dhd_pub_t *dhdpub, int stage);
1119 extern int dhd_bus_membytes(dhd_pub_t *dhdp, bool set, uint32 address, uint8 *data, uint size);
1120 extern void dhd_print_buf(void *pbuf, int len, int bytes_per_line);
1121 extern bool dhd_is_associated(dhd_pub_t *dhd, uint8 ifidx, int *retval);
1122 #if defined(BCMSDIO) || defined(BCMPCIE)
1123 extern uint dhd_bus_chip_id(dhd_pub_t *dhdp);
1124 extern uint dhd_bus_chiprev_id(dhd_pub_t *dhdp);
1125 extern uint dhd_bus_chippkg_id(dhd_pub_t *dhdp);
1126 #endif /* defined(BCMSDIO) || defined(BCMPCIE) */
1127
1128 #if defined(KEEP_ALIVE)
1129 extern int dhd_keep_alive_onoff(dhd_pub_t *dhd);
1130 #endif /* KEEP_ALIVE */
1131
1132 /* OS spin lock API */
1133 extern void *dhd_os_spin_lock_init(osl_t *osh);
1134 extern void dhd_os_spin_lock_deinit(osl_t *osh, void *lock);
1135 extern unsigned long dhd_os_spin_lock(void *lock);
1136 void dhd_os_spin_unlock(void *lock, unsigned long flags);
1137
1138 /*
1139  * Manage sta objects in an interface. Interface is identified by an ifindex and
1140  * sta(s) within an interfaces are managed using a MacAddress of the sta.
1141  */
1142 struct dhd_sta;
1143 extern struct dhd_sta *dhd_findadd_sta(void *pub, int ifidx, void *ea);
1144 extern void dhd_del_sta(void *pub, int ifidx, void *ea);
1145 extern int dhd_get_ap_isolate(dhd_pub_t *dhdp, uint32 idx);
1146 extern int dhd_set_ap_isolate(dhd_pub_t *dhdp, uint32 idx, int val);
1147 #if defined(BCM_GMAC3)
1148 extern int dhd_set_dev_def(dhd_pub_t *dhdp, uint32 idx, int val);
1149 #endif
1150 extern int dhd_bssidx2idx(dhd_pub_t *dhdp, uint32 bssidx);
1151 extern int dhd_os_d3ack_wait(dhd_pub_t * pub, uint * condition);
1152 extern int dhd_os_d3ack_wake(dhd_pub_t * pub);
1153 extern int dhd_os_busbusy_wait_negation(dhd_pub_t * pub, uint * condition);
1154 extern int dhd_os_busbusy_wake(dhd_pub_t * pub);
1155
1156 extern bool dhd_is_concurrent_mode(dhd_pub_t *dhd);
1157 extern int dhd_iovar(dhd_pub_t *pub, int ifidx, char *name, char *cmd_buf, uint cmd_len, int set);
1158 typedef enum cust_gpio_modes {
1159         WLAN_RESET_ON,
1160         WLAN_RESET_OFF,
1161         WLAN_POWER_ON,
1162         WLAN_POWER_OFF
1163 } cust_gpio_modes_t;
1164
1165 extern int wl_iw_iscan_set_scan_broadcast_prep(struct net_device *dev, uint flag);
1166 extern int wl_iw_send_priv_event(struct net_device *dev, char *flag);
1167 /*
1168  * Insmod parameters for debug/test
1169  */
1170
1171 /* Watchdog timer interval */
1172 extern uint dhd_watchdog_ms;
1173 extern bool dhd_os_wd_timer_enabled(void *bus);
1174
1175 #ifdef PKT_STATICS
1176 typedef struct pkt_statics {
1177         uint16  event_count;
1178         uint32  event_size;
1179         uint16  ctrl_count;
1180         uint32  ctrl_size;
1181         uint32  data_count;
1182         uint32  data_size;
1183         uint16  glom_1_count;
1184         uint16  glom_3_count;
1185         uint16  glom_3_8_count;
1186         uint16  glom_8_count;
1187         uint16  glom_count;
1188         uint32  glom_size;
1189         uint16  test_count;
1190         uint32  test_size;
1191 } pkt_statics_t;
1192 #endif
1193
1194 #ifdef DHD_PCIE_RUNTIMEPM
1195 extern uint dhd_runtimepm_ms;
1196 #endif /* DHD_PCIE_RUNTIMEPM */
1197
1198 #if defined(DHD_DEBUG)
1199 /* Console output poll interval */
1200 extern uint dhd_console_ms;
1201 #endif /* defined(DHD_DEBUG) */
1202 extern uint android_msg_level;
1203 extern uint config_msg_level;
1204 extern uint sd_msglevel;
1205 #ifdef WL_WIRELESS_EXT
1206 extern uint iw_msg_level;
1207 #endif
1208 #ifdef WL_CFG80211
1209 extern uint wl_dbg_level;
1210 #endif
1211
1212 extern uint dhd_slpauto;
1213
1214 /* Use interrupts */
1215 extern uint dhd_intr;
1216
1217 /* Use polling */
1218 extern uint dhd_poll;
1219
1220 /* ARP offload agent mode */
1221 extern uint dhd_arp_mode;
1222
1223 /* ARP offload enable */
1224 extern uint dhd_arp_enable;
1225
1226 /* Pkt filte enable control */
1227 extern uint dhd_pkt_filter_enable;
1228
1229 /*  Pkt filter init setup */
1230 extern uint dhd_pkt_filter_init;
1231
1232 /* Pkt filter mode control */
1233 extern uint dhd_master_mode;
1234
1235 /* Roaming mode control */
1236 extern uint dhd_roam_disable;
1237
1238 /* Roaming mode control */
1239 extern uint dhd_radio_up;
1240
1241 /* Initial idletime ticks (may be -1 for immediate idle, 0 for no idle) */
1242 extern int dhd_idletime;
1243 #ifdef DHD_USE_IDLECOUNT
1244 #define DHD_IDLETIME_TICKS 5
1245 #else
1246 #define DHD_IDLETIME_TICKS 1
1247 #endif /* DHD_USE_IDLECOUNT */
1248
1249 /* SDIO Drive Strength */
1250 extern uint dhd_sdiod_drive_strength;
1251
1252 /* triggers bcm_bprintf to print to kernel log */
1253 extern bool bcm_bprintf_bypass;
1254
1255 /* Override to force tx queueing all the time */
1256 extern uint dhd_force_tx_queueing;
1257 /* Default KEEP_ALIVE Period is 55 sec to prevent AP from sending Keep Alive probe frame */
1258 #define DEFAULT_KEEP_ALIVE_VALUE        55000 /* msec */
1259 #ifndef CUSTOM_KEEP_ALIVE_SETTING
1260 #define CUSTOM_KEEP_ALIVE_SETTING       DEFAULT_KEEP_ALIVE_VALUE
1261 #endif /* DEFAULT_KEEP_ALIVE_VALUE */
1262
1263 #define NULL_PKT_STR    "null_pkt"
1264
1265 /* hooks for custom glom setting option via Makefile */
1266 #define DEFAULT_GLOM_VALUE      -1
1267 #ifndef CUSTOM_GLOM_SETTING
1268 #define CUSTOM_GLOM_SETTING     DEFAULT_GLOM_VALUE
1269 #endif
1270 #define WL_AUTO_ROAM_TRIGGER -75
1271 /* hooks for custom Roaming Trigger  setting via Makefile */
1272 #define DEFAULT_ROAM_TRIGGER_VALUE -75 /* dBm default roam trigger all band */
1273 #define DEFAULT_ROAM_TRIGGER_SETTING    -1
1274 #ifndef CUSTOM_ROAM_TRIGGER_SETTING
1275 #define CUSTOM_ROAM_TRIGGER_SETTING     DEFAULT_ROAM_TRIGGER_VALUE
1276 #endif
1277
1278 /* hooks for custom Roaming Romaing  setting via Makefile */
1279 #define DEFAULT_ROAM_DELTA_VALUE  10 /* dBm default roam delta all band */
1280 #define DEFAULT_ROAM_DELTA_SETTING      -1
1281 #ifndef CUSTOM_ROAM_DELTA_SETTING
1282 #define CUSTOM_ROAM_DELTA_SETTING       DEFAULT_ROAM_DELTA_VALUE
1283 #endif
1284
1285 /* hooks for custom PNO Event wake lock to guarantee enough time
1286         for the Platform to detect Event before system suspended
1287 */
1288 #define DEFAULT_PNO_EVENT_LOCK_xTIME    2       /* multiplay of DHD_PACKET_TIMEOUT_MS */
1289 #ifndef CUSTOM_PNO_EVENT_LOCK_xTIME
1290 #define CUSTOM_PNO_EVENT_LOCK_xTIME      DEFAULT_PNO_EVENT_LOCK_xTIME
1291 #endif
1292 /* hooks for custom dhd_dpc_prio setting option via Makefile */
1293 #define DEFAULT_DHP_DPC_PRIO  1
1294 #ifndef CUSTOM_DPC_PRIO_SETTING
1295 #define CUSTOM_DPC_PRIO_SETTING         DEFAULT_DHP_DPC_PRIO
1296 #endif
1297
1298 #ifndef CUSTOM_LISTEN_INTERVAL
1299 #define CUSTOM_LISTEN_INTERVAL          LISTEN_INTERVAL
1300 #endif /* CUSTOM_LISTEN_INTERVAL */
1301
1302 #define DEFAULT_SUSPEND_BCN_LI_DTIM             3
1303 #ifndef CUSTOM_SUSPEND_BCN_LI_DTIM
1304 #define CUSTOM_SUSPEND_BCN_LI_DTIM              DEFAULT_SUSPEND_BCN_LI_DTIM
1305 #endif
1306
1307 #ifndef CUSTOM_RXF_PRIO_SETTING
1308 #define CUSTOM_RXF_PRIO_SETTING         MAX((CUSTOM_DPC_PRIO_SETTING - 1), 1)
1309 #endif
1310
1311 #define DEFAULT_WIFI_TURNOFF_DELAY              0
1312 #define WIFI_TURNOFF_DELAY              DEFAULT_WIFI_TURNOFF_DELAY
1313
1314 #define DEFAULT_WIFI_TURNON_DELAY               200
1315 #ifndef WIFI_TURNON_DELAY
1316 #define WIFI_TURNON_DELAY               DEFAULT_WIFI_TURNON_DELAY
1317 #endif /* WIFI_TURNON_DELAY */
1318
1319 #define DEFAULT_DHD_WATCHDOG_INTERVAL_MS        10 /* msec */
1320 #ifndef CUSTOM_DHD_WATCHDOG_MS
1321 #define CUSTOM_DHD_WATCHDOG_MS                  DEFAULT_DHD_WATCHDOG_INTERVAL_MS
1322 #endif /* DEFAULT_DHD_WATCHDOG_INTERVAL_MS */
1323
1324 #define DEFAULT_ASSOC_RETRY_MAX                 3
1325 #ifndef CUSTOM_ASSOC_RETRY_MAX
1326 #define CUSTOM_ASSOC_RETRY_MAX                  DEFAULT_ASSOC_RETRY_MAX
1327 #endif /* DEFAULT_ASSOC_RETRY_MAX */
1328
1329
1330 #ifdef WLTDLS
1331 #ifndef CUSTOM_TDLS_IDLE_MODE_SETTING
1332 #define CUSTOM_TDLS_IDLE_MODE_SETTING  60000 /* 60sec to tear down TDLS of not active */
1333 #endif
1334 #ifndef CUSTOM_TDLS_RSSI_THRESHOLD_HIGH
1335 #define CUSTOM_TDLS_RSSI_THRESHOLD_HIGH -70 /* rssi threshold for establishing TDLS link */
1336 #endif
1337 #ifndef CUSTOM_TDLS_RSSI_THRESHOLD_LOW
1338 #define CUSTOM_TDLS_RSSI_THRESHOLD_LOW -80 /* rssi threshold for tearing down TDLS link */
1339 #endif
1340 #endif /* WLTDLS */
1341
1342 #define DEFAULT_BCN_TIMEOUT             8
1343 #ifndef CUSTOM_BCN_TIMEOUT
1344 #define CUSTOM_BCN_TIMEOUT              DEFAULT_BCN_TIMEOUT
1345 #endif
1346
1347 #define MAX_DTIM_SKIP_BEACON_INTERVAL   100 /* max allowed associated AP beacon for DTIM skip */
1348 #ifndef MAX_DTIM_ALLOWED_INTERVAL
1349 #define MAX_DTIM_ALLOWED_INTERVAL 600 /* max allowed total beacon interval for DTIM skip */
1350 #endif
1351 #define NO_DTIM_SKIP 1
1352 #ifdef SDTEST
1353 /* Echo packet generator (SDIO), pkts/s */
1354 extern uint dhd_pktgen;
1355
1356 /* Echo packet len (0 => sawtooth, max 1800) */
1357 extern uint dhd_pktgen_len;
1358 #define MAX_PKTGEN_LEN 1800
1359 #endif
1360
1361
1362 /* optionally set by a module_param_string() */
1363 #define MOD_PARAM_PATHLEN       2048
1364 #define MOD_PARAM_INFOLEN       512
1365
1366 #ifdef SOFTAP
1367 extern char fw_path2[MOD_PARAM_PATHLEN];
1368 #endif
1369
1370 /* Flag to indicate if we should download firmware on driver load */
1371 extern uint dhd_download_fw_on_driverload;
1372 extern int allow_delay_fwdl;
1373
1374
1375 extern void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar);
1376 extern void dhd_wait_event_wakeup(dhd_pub_t*dhd);
1377
1378 #define IFLOCK_INIT(lock)       *lock = 0
1379 #define IFLOCK(lock)    while (InterlockedCompareExchange((lock), 1, 0))        \
1380         NdisStallExecution(1);
1381 #define IFUNLOCK(lock)  InterlockedExchange((lock), 0)
1382 #define IFLOCK_FREE(lock)
1383 #define FW_SUPPORTED(dhd, capa) ((strstr(dhd->fw_capabilities, " " #capa " ") != NULL))
1384 #ifdef ARP_OFFLOAD_SUPPORT
1385 #define MAX_IPV4_ENTRIES        8
1386 void dhd_arp_offload_set(dhd_pub_t * dhd, int arp_mode);
1387 void dhd_arp_offload_enable(dhd_pub_t * dhd, int arp_enable);
1388
1389 /* dhd_commn arp offload wrapers */
1390 void dhd_aoe_hostip_clr(dhd_pub_t *dhd, int idx);
1391 void dhd_aoe_arp_clr(dhd_pub_t *dhd, int idx);
1392 int dhd_arp_get_arp_hostip_table(dhd_pub_t *dhd, void *buf, int buflen, int idx);
1393 void dhd_arp_offload_add_ip(dhd_pub_t *dhd, uint32 ipaddr, int idx);
1394 #endif /* ARP_OFFLOAD_SUPPORT */
1395 #ifdef WLTDLS
1396 int dhd_tdls_enable(struct net_device *dev, bool tdls_on, bool auto_on, struct ether_addr *mac);
1397 int dhd_tdls_set_mode(dhd_pub_t *dhd, bool wfd_mode);
1398 #ifdef PCIE_FULL_DONGLE
1399 void dhd_tdls_update_peer_info(struct net_device *dev, bool connect_disconnect, uint8 *addr);
1400 #endif /* PCIE_FULL_DONGLE */
1401 #endif /* WLTDLS */
1402 /* Neighbor Discovery Offload Support */
1403 extern int dhd_ndo_enable(dhd_pub_t * dhd, int ndo_enable);
1404 int dhd_ndo_add_ip(dhd_pub_t *dhd, char* ipaddr, int idx);
1405 int dhd_ndo_remove_ip(dhd_pub_t *dhd, int idx);
1406 /* ioctl processing for nl80211 */
1407 int dhd_ioctl_process(dhd_pub_t *pub, int ifidx, struct dhd_ioctl *ioc, void *data_buf);
1408
1409 void dhd_bus_update_fw_nv_path(struct dhd_bus *bus, char *pfw_path, char *pnv_path, char *pconf_path);
1410 void dhd_set_bus_state(void *bus, uint32 state);
1411
1412 /* Remove proper pkts(either one no-frag pkt or whole fragmented pkts) */
1413 typedef int (*f_droppkt_t)(dhd_pub_t *dhdp, int prec, void* p, bool bPktInQ);
1414 extern bool dhd_prec_drop_pkts(dhd_pub_t *dhdp, struct pktq *pq, int prec, f_droppkt_t fn);
1415
1416 #ifdef PROP_TXSTATUS
1417 int dhd_os_wlfc_block(dhd_pub_t *pub);
1418 int dhd_os_wlfc_unblock(dhd_pub_t *pub);
1419 extern const uint8 prio2fifo[];
1420 #endif /* PROP_TXSTATUS */
1421
1422 uint8* dhd_os_prealloc(dhd_pub_t *dhdpub, int section, uint size, bool kmalloc_if_fail);
1423 void dhd_os_prefree(dhd_pub_t *dhdpub, void *addr, uint size);
1424
1425 int dhd_process_cid_mac(dhd_pub_t *dhdp, bool prepost);
1426
1427 #if defined(CONFIG_DHD_USE_STATIC_BUF)
1428 #define DHD_OS_PREALLOC(dhdpub, section, size) dhd_os_prealloc(dhdpub, section, size, FALSE)
1429 #define DHD_OS_PREFREE(dhdpub, addr, size) dhd_os_prefree(dhdpub, addr, size)
1430 #else
1431 #define DHD_OS_PREALLOC(dhdpub, section, size) MALLOC(dhdpub->osh, size)
1432 #define DHD_OS_PREFREE(dhdpub, addr, size) MFREE(dhdpub->osh, addr, size)
1433 #endif /* defined(CONFIG_DHD_USE_STATIC_BUF) */
1434
1435 #ifdef USE_WFA_CERT_CONF
1436 enum {
1437         SET_PARAM_BUS_TXGLOM_MODE,
1438         SET_PARAM_ROAMOFF,
1439 #ifdef USE_WL_FRAMEBURST
1440         SET_PARAM_FRAMEBURST,
1441 #endif /* USE_WL_FRAMEBURST */
1442 #ifdef USE_WL_TXBF
1443         SET_PARAM_TXBF,
1444 #endif /* USE_WL_TXBF */
1445 #ifdef PROP_TXSTATUS
1446         SET_PARAM_PROPTX,
1447         SET_PARAM_PROPTXMODE,
1448 #endif /* PROP_TXSTATUS */
1449         PARAM_LAST_VALUE
1450 };
1451 extern int sec_get_param_wfa_cert(dhd_pub_t *dhd, int mode, uint* read_val);
1452 #endif /* USE_WFA_CERT_CONF */
1453
1454 #define dhd_add_flowid(pub, ifidx, ac_prio, ea, flowid)  do {} while (0)
1455 #define dhd_del_flowid(pub, ifidx, flowid)               do {} while (0)
1456
1457 extern unsigned long dhd_os_general_spin_lock(dhd_pub_t *pub);
1458 extern void dhd_os_general_spin_unlock(dhd_pub_t *pub, unsigned long flags);
1459
1460 /** Miscellaenous DHD Spin Locks */
1461
1462 /* Disable router 3GMAC bypass path perimeter lock */
1463 #define DHD_PERIM_LOCK(dhdp)              do {} while (0)
1464 #define DHD_PERIM_UNLOCK(dhdp)            do {} while (0)
1465 #define DHD_PERIM_LOCK_ALL(processor_id)    do {} while (0)
1466 #define DHD_PERIM_UNLOCK_ALL(processor_id)  do {} while (0)
1467
1468 /* Enable DHD general spin lock/unlock */
1469 #define DHD_GENERAL_LOCK(dhdp, flags) \
1470         (flags) = dhd_os_general_spin_lock(dhdp)
1471 #define DHD_GENERAL_UNLOCK(dhdp, flags) \
1472         dhd_os_general_spin_unlock((dhdp), (flags))
1473
1474 /* Enable DHD flowring spin lock/unlock */
1475 #define DHD_FLOWRING_LOCK(lock, flags)     (flags) = dhd_os_spin_lock(lock)
1476 #define DHD_FLOWRING_UNLOCK(lock, flags)   dhd_os_spin_unlock((lock), (flags))
1477
1478 /* Enable DHD common flowring info spin lock/unlock */
1479 #define DHD_FLOWID_LOCK(lock, flags)       (flags) = dhd_os_spin_lock(lock)
1480 #define DHD_FLOWID_UNLOCK(lock, flags)     dhd_os_spin_unlock((lock), (flags))
1481
1482 /* Enable DHD common flowring list spin lock/unlock */
1483 #define DHD_FLOWRING_LIST_LOCK(lock, flags)       (flags) = dhd_os_spin_lock(lock)
1484 #define DHD_FLOWRING_LIST_UNLOCK(lock, flags)     dhd_os_spin_unlock((lock), (flags))
1485
1486 extern void dhd_dump_to_kernelog(dhd_pub_t *dhdp);
1487
1488
1489 #ifdef DHD_L2_FILTER
1490 extern int dhd_get_parp_status(dhd_pub_t *dhdp, uint32 idx);
1491 extern int dhd_set_parp_status(dhd_pub_t *dhdp, uint32 idx, int val);
1492 extern int dhd_get_dhcp_unicast_status(dhd_pub_t *dhdp, uint32 idx);
1493 extern int dhd_set_dhcp_unicast_status(dhd_pub_t *dhdp, uint32 idx, int val);
1494 extern int dhd_get_block_ping_status(dhd_pub_t *dhdp, uint32 idx);
1495 extern int dhd_set_block_ping_status(dhd_pub_t *dhdp, uint32 idx, int val);
1496 extern int dhd_get_grat_arp_status(dhd_pub_t *dhdp, uint32 idx);
1497 extern int dhd_set_grat_arp_status(dhd_pub_t *dhdp, uint32 idx, int val);
1498 #endif /* DHD_L2_FILTER */
1499
1500 typedef struct wl_io_pport {
1501         dhd_pub_t *dhd_pub;
1502         uint ifidx;
1503 } wl_io_pport_t;
1504
1505 typedef struct wl_evt_pport {
1506         dhd_pub_t *dhd_pub;
1507         int *ifidx;
1508         void *pktdata;
1509         void **data_ptr;
1510         void *raw_event;
1511 } wl_evt_pport_t;
1512
1513 extern void *dhd_pub_shim(dhd_pub_t *dhd_pub);
1514 #ifdef DHD_FW_COREDUMP
1515 void dhd_save_fwdump(dhd_pub_t *dhd_pub, void * buffer, uint32 length);
1516 #endif /* DHD_FW_COREDUMP */
1517
1518 #if defined(SET_RPS_CPUS)
1519 int dhd_rps_cpus_enable(struct net_device *net, int enable);
1520 int custom_rps_map_set(struct netdev_rx_queue *queue, char *buf, size_t len);
1521 void custom_rps_map_clear(struct netdev_rx_queue *queue);
1522 #define PRIMARY_INF 0
1523 #define VIRTUAL_INF 1
1524 #if defined(CONFIG_MACH_UNIVERSAL5433) || defined(CONFIG_MACH_UNIVERSAL7420) || \
1525         defined(CONFIG_SOC_EXYNOS8890)
1526 #define RPS_CPUS_MASK "10"
1527 #define RPS_CPUS_MASK_P2P "10"
1528 #define RPS_CPUS_MASK_IBSS "10"
1529 #define RPS_CPUS_WLAN_CORE_ID 4
1530 #else
1531 #define RPS_CPUS_MASK "6"
1532 #define RPS_CPUS_MASK_P2P "6"
1533 #define RPS_CPUS_MASK_IBSS "6"
1534 #endif /* CONFIG_MACH_UNIVERSAL5433 || CONFIG_MACH_UNIVERSAL7420 || CONFIG_SOC_EXYNOS8890 */
1535 #endif 
1536
1537 int dhd_get_download_buffer(dhd_pub_t   *dhd, char *file_path, download_type_t component,
1538         char ** buffer, int *length);
1539
1540 void dhd_free_download_buffer(dhd_pub_t *dhd, void *buffer, int length);
1541
1542 #define dhd_is_device_removed(x) FALSE
1543 #define dhd_os_ind_firmware_stall(x)
1544
1545 #ifdef DHD_FW_COREDUMP
1546 extern void dhd_get_memdump_info(dhd_pub_t *dhd);
1547 #endif /* DHD_FW_COREDUMP */
1548 #ifdef BCMASSERT_LOG
1549 extern void dhd_get_assert_info(dhd_pub_t *dhd);
1550 #endif /* BCMASSERT_LOG */
1551
1552
1553 #if defined(DHD_LB_STATS)
1554 #include <bcmutils.h>
1555 extern void dhd_lb_stats_init(dhd_pub_t *dhd);
1556 extern void dhd_lb_stats_dump(dhd_pub_t *dhdp, struct bcmstrbuf *strbuf);
1557 extern void dhd_lb_stats_update_napi_histo(dhd_pub_t *dhdp, uint32 count);
1558 extern void dhd_lb_stats_update_txc_histo(dhd_pub_t *dhdp, uint32 count);
1559 extern void dhd_lb_stats_update_rxc_histo(dhd_pub_t *dhdp, uint32 count);
1560 extern void dhd_lb_stats_txc_percpu_cnt_incr(dhd_pub_t *dhdp);
1561 extern void dhd_lb_stats_rxc_percpu_cnt_incr(dhd_pub_t *dhdp);
1562 #define DHD_LB_STATS_INIT(dhdp) dhd_lb_stats_init(dhdp)
1563 /* Reset is called from common layer so it takes dhd_pub_t as argument */
1564 #define DHD_LB_STATS_RESET(dhdp) dhd_lb_stats_init(dhdp)
1565 #define DHD_LB_STATS_CLR(x)     (x) = 0U
1566 #define DHD_LB_STATS_INCR(x)    (x) = (x) + 1
1567 #define DHD_LB_STATS_ADD(x, c)  (x) = (x) + (c)
1568 #define DHD_LB_STATS_PERCPU_ARR_INCR(x) \
1569         { \
1570                 int cpu = get_cpu(); put_cpu(); \
1571                 DHD_LB_STATS_INCR(x[cpu]); \
1572         }
1573 #define DHD_LB_STATS_UPDATE_NAPI_HISTO(dhdp, x) dhd_lb_stats_update_napi_histo(dhdp, x)
1574 #define DHD_LB_STATS_UPDATE_TXC_HISTO(dhdp, x)  dhd_lb_stats_update_txc_histo(dhdp, x)
1575 #define DHD_LB_STATS_UPDATE_RXC_HISTO(dhdp, x)  dhd_lb_stats_update_rxc_histo(dhdp, x)
1576 #define DHD_LB_STATS_TXC_PERCPU_CNT_INCR(dhdp)  dhd_lb_stats_txc_percpu_cnt_incr(dhdp)
1577 #define DHD_LB_STATS_RXC_PERCPU_CNT_INCR(dhdp)  dhd_lb_stats_rxc_percpu_cnt_incr(dhdp)
1578 #else /* !DHD_LB_STATS */
1579 #define DHD_LB_STATS_NOOP       do { /* noop */ } while (0)
1580 #define DHD_LB_STATS_INIT(dhdp)  DHD_LB_STATS_NOOP
1581 #define DHD_LB_STATS_RESET(dhdp) DHD_LB_STATS_NOOP
1582 #define DHD_LB_STATS_CLR(x)      DHD_LB_STATS_NOOP
1583 #define DHD_LB_STATS_INCR(x)     DHD_LB_STATS_NOOP
1584 #define DHD_LB_STATS_ADD(x, c)   DHD_LB_STATS_NOOP
1585 #define DHD_LB_STATS_PERCPU_ARR_INCR(x)  DHD_LB_STATS_NOOP
1586 #define DHD_LB_STATS_UPDATE_NAPI_HISTO(dhd, x) DHD_LB_STATS_NOOP
1587 #define DHD_LB_STATS_UPDATE_TXC_HISTO(dhd, x) DHD_LB_STATS_NOOP
1588 #define DHD_LB_STATS_UPDATE_RXC_HISTO(dhd, x) DHD_LB_STATS_NOOP
1589 #define DHD_LB_STATS_TXC_PERCPU_CNT_INCR(dhdp) DHD_LB_STATS_NOOP
1590 #define DHD_LB_STATS_RXC_PERCPU_CNT_INCR(dhdp) DHD_LB_STATS_NOOP
1591 #endif /* !DHD_LB_STATS */
1592
1593 #ifdef DHD_PCIE_RUNTIMEPM
1594 extern bool dhd_runtimepm_state(dhd_pub_t *dhd);
1595 extern bool dhd_runtime_bus_wake(struct dhd_bus *bus, bool wait, void *func_addr);
1596 extern bool dhdpcie_runtime_bus_wake(dhd_pub_t *dhdp, bool wait, void *func_addr);
1597 extern void dhdpcie_block_runtime_pm(dhd_pub_t *dhdp);
1598 extern bool dhdpcie_is_resume_done(dhd_pub_t *dhdp);
1599 extern void dhd_runtime_pm_disable(dhd_pub_t *dhdp);
1600 extern void dhd_runtime_pm_enable(dhd_pub_t *dhdp);
1601 /* Disable the Runtime PM and wake up if the bus is already in suspend */
1602 #define DHD_DISABLE_RUNTIME_PM(dhdp) \
1603 do { \
1604         dhd_runtime_pm_disable(dhdp); \
1605 } while (0);
1606
1607 /* Enable the Runtime PM */
1608 #define DHD_ENABLE_RUNTIME_PM(dhdp) \
1609 do { \
1610         dhd_runtime_pm_enable(dhdp); \
1611 } while (0);
1612 #else
1613 #define DHD_DISABLE_RUNTIME_PM(dhdp)
1614 #define DHD_ENABLE_RUNTIME_PM(dhdp)
1615 #endif /* DHD_PCIE_RUNTIMEPM */
1616
1617 extern void dhd_memdump_work_schedule(dhd_pub_t *dhdp, unsigned long msecs);
1618
1619 /*
1620  * Enable this macro if you want to track the calls to wake lock
1621  * This records can be printed using the following command
1622  * cat /sys/bcm-dhd/wklock_trace
1623  * DHD_TRACE_WAKE_LOCK supports over linux 2.6.0 version
1624  */
1625 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
1626 #undef DHD_TRACE_WAKE_LOCK
1627 #endif /* KERNEL_VER < KERNEL_VERSION(2, 6, 0) */
1628
1629 #if defined(DHD_TRACE_WAKE_LOCK)
1630 void dhd_wk_lock_stats_dump(dhd_pub_t *dhdp);
1631 #endif
1632
1633 extern int dhd_prot_debug_info_print(dhd_pub_t *dhd);
1634
1635 #ifdef ENABLE_TEMP_THROTTLING
1636 #define TEMP_THROTTLE_CONTROL_BIT 0xf   //Enable all feature.
1637 #endif /* ENABLE_TEMP_THROTTLING */
1638
1639 #ifdef DHD_PKTID_AUDIT_ENABLED
1640 void dhd_pktid_audit_fail_cb(dhd_pub_t *dhdp);
1641 #endif /* DHD_PKTID_AUDIT_ENABLED */
1642
1643 #endif /* _dhd_h_ */