xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/cywdhd/bcmdhd/dhd.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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  * Portions of this code are copyright (c) 2022 Cypress Semiconductor Corporation
8  *
9  * Copyright (C) 1999-2017, Broadcom Corporation
10  *
11  *      Unless you and Broadcom execute a separate written software license
12  * agreement governing use of this software, this software is licensed to you
13  * under the terms of the GNU General Public License version 2 (the "GPL"),
14  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
15  * following added to such license:
16  *
17  *      As a special exception, the copyright holders of this software give you
18  * permission to link this software with independent modules, and to copy and
19  * distribute the resulting executable under terms of your choice, provided that
20  * you also meet, for each linked independent module, the terms and conditions of
21  * the license of that module.  An independent module is a module which is not
22  * derived from this software.  The special exception does not apply to any
23  * modifications of the software.
24  *
25  *      Notwithstanding the above, under no circumstances may you combine this
26  * software in any way with any other Broadcom software provided under a license
27  * other than the GPL, without Broadcom's express prior written consent.
28  *
29  *
30  * <<Broadcom-WL-IPTag/Open:>>
31  *
32  * $Id: dhd.h 701844 2017-05-26 18:56:40Z $
33  */
34 
35 /****************
36  * Common types *
37  */
38 
39 #ifndef _dhd_h_
40 #define _dhd_h_
41 
42 #include <linux/init.h>
43 #include <linux/kernel.h>
44 #include <linux/slab.h>
45 #include <linux/skbuff.h>
46 #include <linux/netdevice.h>
47 #include <linux/etherdevice.h>
48 #include <linux/random.h>
49 #include <linux/spinlock.h>
50 #include <linux/ethtool.h>
51 #include <linux/fs.h>
52 #include <linux/proc_fs.h>
53 #include <asm/uaccess.h>
54 #include <asm/unaligned.h>
55 #if defined(CONFIG_PM_WAKELOCKS) || defined(CONFIG_HAS_WAKELOCK)
56 #include <linux/wakelock.h>
57 #endif /* CONFIG_PM_WAKELOCKS || CONFIG_HAS_WAKELOCK */
58 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
59 #include <linux/sched/types.h>
60 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) */
61 /* The kernel threading is sdio-specific */
62 struct task_struct;
63 struct sched_param;
64 #if defined(BT_OVER_SDIO)
65 #include <dhd_bt_interface.h>
66 #endif /* defined (BT_OVER_SDIO) */
67 int setScheduler(struct task_struct *p, int policy, struct sched_param *param);
68 int get_scheduler_policy(struct task_struct *p);
69 #define MAX_EVENT	16
70 
71 #define ALL_INTERFACES	0xff
72 
73 /* H2D and D2H ring dump is enabled by default */
74 #ifdef PCIE_FULL_DONGLE
75 #define DHD_DUMP_PCIE_RINGS
76 #endif /* PCIE_FULL_DONGLE */
77 
78 #include <wlioctl.h>
79 #include <bcmstdlib_s.h>
80 #include <dhdioctl.h>
81 #include <wlfc_proto.h>
82 #include <hnd_armtrap.h>
83 #if defined(DUMP_IOCTL_IOV_LIST) || defined(DHD_DEBUG)
84 #include <bcmutils.h>
85 #endif /* DUMP_IOCTL_IOV_LIST || DHD_DEBUG */
86 
87 #if defined(BCMWDF)
88 #include <wdf.h>
89 #include <WdfMiniport.h>
90 #endif /* (BCMWDF)  */
91 
92 #ifdef WL_CFGVENDOR_SEND_HANG_EVENT
93 #include <rte_ioctl.h>
94 #endif /* WL_CFGVENDOR_SEND_HANG_EVENT */
95 
96 #ifdef DHD_ERPOM
97 #include <pom.h>
98 #endif /* DHD_ERPOM */
99 
100 #include <dngl_stats.h>
101 
102 #ifdef DEBUG_DPC_THREAD_WATCHDOG
103 #define MAX_RESCHED_CNT 600
104 #endif /* DEBUG_DPC_THREAD_WATCHDOG */
105 
106 #if defined(KEEP_ALIVE)
107 /* Default KEEP_ALIVE Period is 55 sec to prevent AP from sending Keep Alive probe frame */
108 #define KEEP_ALIVE_PERIOD 55000
109 #define NULL_PKT_STR	"null_pkt"
110 #endif /* KEEP_ALIVE */
111 
112 /* By default enabled from here, later the WQ code will be removed */
113 #define DHD_USE_KTHREAD_FOR_LOGTRACE
114 
115 /*
116  * Earlier DHD used to have it own time stamp for printk and
117  * Dongle used to have its own time stamp for console messages
118  * With this flag, DHD and Dongle console messges will have same time zone
119  */
120 #define DHD_H2D_LOG_TIME_SYNC
121 /* Forward decls */
122 struct dhd_bus;
123 struct dhd_prot;
124 struct dhd_info;
125 struct dhd_ioctl;
126 struct dhd_dbg;
127 struct dhd_ts;
128 #ifdef DNGL_AXI_ERROR_LOGGING
129 struct dhd_axi_error_dump;
130 #endif /* DNGL_AXI_ERROR_LOGGING */
131 
132 /* The level of bus communication with the dongle */
133 enum dhd_bus_state {
134 	DHD_BUS_DOWN,		/* Not ready for frame transfers */
135 	DHD_BUS_LOAD,		/* Download access only (CPU reset) */
136 	DHD_BUS_DATA,		/* Ready for frame transfers */
137 	DHD_BUS_SUSPEND,	/* Bus has been suspended */
138 	DHD_BUS_DOWN_IN_PROGRESS,	/* Bus going Down */
139 };
140 
141 /* The level of bus communication with the dongle */
142 enum dhd_bus_devreset_type {
143 	DHD_BUS_DEVRESET_ON = 0,	/* ON */
144 	DHD_BUS_DEVRESET_OFF = 1,		/* OFF */
145 	DHD_BUS_DEVRESET_FLR = 2,		/* FLR */
146 	DHD_BUS_DEVRESET_FLR_FORCE_FAIL = 3,	/* FLR FORCE FAIL */
147 	DHD_BUS_DEVRESET_QUIESCE = 4,		/* FLR */
148 };
149 
150 /*
151  * Bit fields to Indicate clean up process that wait till they are finished.
152  * Future synchronizable processes can add their bit filed below and update
153  * their functionalities accordingly
154  */
155 #define DHD_BUS_BUSY_IN_TX                   0x01
156 #define DHD_BUS_BUSY_IN_SEND_PKT             0x02
157 #define DHD_BUS_BUSY_IN_DPC                  0x04
158 #define DHD_BUS_BUSY_IN_WD                   0x08
159 #define DHD_BUS_BUSY_IN_IOVAR                0x10
160 #define DHD_BUS_BUSY_IN_DHD_IOVAR            0x20
161 #define DHD_BUS_BUSY_SUSPEND_IN_PROGRESS     0x40
162 #define DHD_BUS_BUSY_RESUME_IN_PROGRESS      0x80
163 #define DHD_BUS_BUSY_RPM_SUSPEND_IN_PROGRESS 0x100
164 #define DHD_BUS_BUSY_RPM_SUSPEND_DONE        0x200
165 #define DHD_BUS_BUSY_RPM_RESUME_IN_PROGRESS  0x400
166 #define DHD_BUS_BUSY_RPM_ALL                 (DHD_BUS_BUSY_RPM_SUSPEND_DONE | \
167 		DHD_BUS_BUSY_RPM_SUSPEND_IN_PROGRESS | \
168 		DHD_BUS_BUSY_RPM_RESUME_IN_PROGRESS)
169 #define DHD_BUS_BUSY_IN_CHECKDIED            0x800
170 #define DHD_BUS_BUSY_IN_MEMDUMP				 0x1000
171 #define DHD_BUS_BUSY_IN_SSSRDUMP			 0x2000
172 #define DHD_BUS_BUSY_IN_LOGDUMP				 0x4000
173 #define DHD_BUS_BUSY_IN_HALDUMP				 0x8000
174 
175 #define DHD_BUS_BUSY_SET_IN_TX(dhdp) \
176 	(dhdp)->dhd_bus_busy_state |= DHD_BUS_BUSY_IN_TX
177 #define DHD_BUS_BUSY_SET_IN_SEND_PKT(dhdp) \
178 	(dhdp)->dhd_bus_busy_state |= DHD_BUS_BUSY_IN_SEND_PKT
179 #define DHD_BUS_BUSY_SET_IN_DPC(dhdp) \
180 	(dhdp)->dhd_bus_busy_state |= DHD_BUS_BUSY_IN_DPC
181 #define DHD_BUS_BUSY_SET_IN_WD(dhdp) \
182 	(dhdp)->dhd_bus_busy_state |= DHD_BUS_BUSY_IN_WD
183 #define DHD_BUS_BUSY_SET_IN_IOVAR(dhdp) \
184 	(dhdp)->dhd_bus_busy_state |= DHD_BUS_BUSY_IN_IOVAR
185 #define DHD_BUS_BUSY_SET_IN_DHD_IOVAR(dhdp) \
186 	(dhdp)->dhd_bus_busy_state |= DHD_BUS_BUSY_IN_DHD_IOVAR
187 #define DHD_BUS_BUSY_SET_SUSPEND_IN_PROGRESS(dhdp) \
188 	(dhdp)->dhd_bus_busy_state |= DHD_BUS_BUSY_SUSPEND_IN_PROGRESS
189 #define DHD_BUS_BUSY_SET_RESUME_IN_PROGRESS(dhdp) \
190 	(dhdp)->dhd_bus_busy_state |= DHD_BUS_BUSY_RESUME_IN_PROGRESS
191 #define DHD_BUS_BUSY_SET_RPM_SUSPEND_IN_PROGRESS(dhdp) \
192 	(dhdp)->dhd_bus_busy_state |= DHD_BUS_BUSY_RPM_SUSPEND_IN_PROGRESS
193 #define DHD_BUS_BUSY_SET_RPM_SUSPEND_DONE(dhdp) \
194 	(dhdp)->dhd_bus_busy_state |= DHD_BUS_BUSY_RPM_SUSPEND_DONE
195 #define DHD_BUS_BUSY_SET_RPM_RESUME_IN_PROGRESS(dhdp) \
196 	(dhdp)->dhd_bus_busy_state |= DHD_BUS_BUSY_RPM_RESUME_IN_PROGRESS
197 #define DHD_BUS_BUSY_SET_IN_CHECKDIED(dhdp) \
198 	(dhdp)->dhd_bus_busy_state |= DHD_BUS_BUSY_IN_CHECKDIED
199 #define DHD_BUS_BUSY_SET_IN_MEMDUMP(dhdp) \
200 	(dhdp)->dhd_bus_busy_state |= DHD_BUS_BUSY_IN_MEMDUMP
201 #define DHD_BUS_BUSY_SET_IN_SSSRDUMP(dhdp) \
202 	(dhdp)->dhd_bus_busy_state |= DHD_BUS_BUSY_IN_SSSRDUMP
203 #define DHD_BUS_BUSY_SET_IN_LOGDUMP(dhdp) \
204 	(dhdp)->dhd_bus_busy_state |= DHD_BUS_BUSY_IN_LOGDUMP
205 #define DHD_BUS_BUSY_SET_IN_HALDUMP(dhdp) \
206 	(dhdp)->dhd_bus_busy_state |= DHD_BUS_BUSY_IN_HALDUMP
207 
208 #define DHD_BUS_BUSY_CLEAR_IN_TX(dhdp) \
209 	(dhdp)->dhd_bus_busy_state &= ~DHD_BUS_BUSY_IN_TX
210 #define DHD_BUS_BUSY_CLEAR_IN_SEND_PKT(dhdp) \
211 	(dhdp)->dhd_bus_busy_state &= ~DHD_BUS_BUSY_IN_SEND_PKT
212 #define DHD_BUS_BUSY_CLEAR_IN_DPC(dhdp) \
213 	(dhdp)->dhd_bus_busy_state &= ~DHD_BUS_BUSY_IN_DPC
214 #define DHD_BUS_BUSY_CLEAR_IN_WD(dhdp) \
215 	(dhdp)->dhd_bus_busy_state &= ~DHD_BUS_BUSY_IN_WD
216 #define DHD_BUS_BUSY_CLEAR_IN_IOVAR(dhdp) \
217 	(dhdp)->dhd_bus_busy_state &= ~DHD_BUS_BUSY_IN_IOVAR
218 #define DHD_BUS_BUSY_CLEAR_IN_DHD_IOVAR(dhdp) \
219 	(dhdp)->dhd_bus_busy_state &= ~DHD_BUS_BUSY_IN_DHD_IOVAR
220 #define DHD_BUS_BUSY_CLEAR_SUSPEND_IN_PROGRESS(dhdp) \
221 	(dhdp)->dhd_bus_busy_state &= ~DHD_BUS_BUSY_SUSPEND_IN_PROGRESS
222 #define DHD_BUS_BUSY_CLEAR_RESUME_IN_PROGRESS(dhdp) \
223 	(dhdp)->dhd_bus_busy_state &= ~DHD_BUS_BUSY_RESUME_IN_PROGRESS
224 #define DHD_BUS_BUSY_CLEAR_RPM_SUSPEND_IN_PROGRESS(dhdp) \
225 	(dhdp)->dhd_bus_busy_state &= ~DHD_BUS_BUSY_RPM_SUSPEND_IN_PROGRESS
226 #define DHD_BUS_BUSY_CLEAR_RPM_SUSPEND_DONE(dhdp) \
227 	(dhdp)->dhd_bus_busy_state &= ~DHD_BUS_BUSY_RPM_SUSPEND_DONE
228 #define DHD_BUS_BUSY_CLEAR_RPM_RESUME_IN_PROGRESS(dhdp) \
229 	(dhdp)->dhd_bus_busy_state &= ~DHD_BUS_BUSY_RPM_RESUME_IN_PROGRESS
230 #define DHD_BUS_BUSY_CLEAR_IN_CHECKDIED(dhdp) \
231 	(dhdp)->dhd_bus_busy_state &= ~DHD_BUS_BUSY_IN_CHECKDIED
232 #define DHD_BUS_BUSY_CLEAR_IN_MEMDUMP(dhdp) \
233 		(dhdp)->dhd_bus_busy_state &= ~DHD_BUS_BUSY_IN_MEMDUMP
234 #define DHD_BUS_BUSY_CLEAR_IN_SSSRDUMP(dhdp) \
235 		(dhdp)->dhd_bus_busy_state &= ~DHD_BUS_BUSY_IN_SSSRDUMP
236 #define DHD_BUS_BUSY_CLEAR_IN_LOGDUMP(dhdp) \
237 		(dhdp)->dhd_bus_busy_state &= ~DHD_BUS_BUSY_IN_LOGDUMP
238 #define DHD_BUS_BUSY_CLEAR_IN_HALDUMP(dhdp) \
239 			(dhdp)->dhd_bus_busy_state &= ~DHD_BUS_BUSY_IN_HALDUMP
240 
241 #define DHD_BUS_BUSY_CHECK_IN_TX(dhdp) \
242 	((dhdp)->dhd_bus_busy_state & DHD_BUS_BUSY_IN_TX)
243 #define DHD_BUS_BUSY_CHECK_IN_SEND_PKT(dhdp) \
244 	((dhdp)->dhd_bus_busy_state & DHD_BUS_BUSY_IN_SEND_PKT)
245 #define DHD_BUS_BUSY_CHECK_IN_DPC(dhdp) \
246 	((dhdp)->dhd_bus_busy_state & DHD_BUS_BUSY_IN_DPC)
247 #define DHD_BUS_BUSY_CHECK_IN_WD(dhdp) \
248 	((dhdp)->dhd_bus_busy_state & DHD_BUS_BUSY_IN_WD)
249 #define DHD_BUS_BUSY_CHECK_IN_IOVAR(dhdp) \
250 	((dhdp)->dhd_bus_busy_state & DHD_BUS_BUSY_IN_IOVAR)
251 #define DHD_BUS_BUSY_CHECK_IN_DHD_IOVAR(dhdp) \
252 	((dhdp)->dhd_bus_busy_state & DHD_BUS_BUSY_IN_DHD_IOVAR)
253 #define DHD_BUS_BUSY_CHECK_SUSPEND_IN_PROGRESS(dhdp) \
254 	((dhdp)->dhd_bus_busy_state & DHD_BUS_BUSY_SUSPEND_IN_PROGRESS)
255 #define DHD_BUS_BUSY_CHECK_RESUME_IN_PROGRESS(dhdp) \
256 	((dhdp)->dhd_bus_busy_state & DHD_BUS_BUSY_RESUME_IN_PROGRESS)
257 #define DHD_BUS_BUSY_CHECK_RPM_SUSPEND_IN_PROGRESS(dhdp) \
258 	((dhdp)->dhd_bus_busy_state & DHD_BUS_BUSY_RPM_SUSPEND_IN_PROGRESS)
259 #define DHD_BUS_BUSY_CHECK_RPM_SUSPEND_DONE(dhdp) \
260 	((dhdp)->dhd_bus_busy_state & DHD_BUS_BUSY_RPM_SUSPEND_DONE)
261 #define DHD_BUS_BUSY_CHECK_RPM_RESUME_IN_PROGRESS(dhdp) \
262 	((dhdp)->dhd_bus_busy_state & DHD_BUS_BUSY_RPM_RESUME_IN_PROGRESS)
263 #define DHD_BUS_BUSY_CHECK_RPM_ALL(dhdp) \
264 	((dhdp)->dhd_bus_busy_state & DHD_BUS_BUSY_RPM_ALL)
265 #define DHD_BUS_BUSY_CHECK_IN_CHECKDIED(dhdp) \
266 	((dhdp)->dhd_bus_busy_state & DHD_BUS_BUSY_IN_CHECKDIED)
267 #define DHD_BUS_BUSY_CHECK_IN_MEMDUMP(dhdp) \
268 		((dhdp)->dhd_bus_busy_state & DHD_BUS_BUSY_IN_MEMDUMP)
269 #define DHD_BUS_BUSY_CHECK_IN_SSSRDUMP(dhdp) \
270 		((dhdp)->dhd_bus_busy_state & DHD_BUS_BUSY_IN_SSSRDUMP)
271 #define DHD_BUS_BUSY_CHECK_IN_LOGDUMP(dhdp) \
272 		((dhdp)->dhd_bus_busy_state & DHD_BUS_BUSY_IN_LOGDUMP)
273 #define DHD_BUS_BUSY_CHECK_IN_HALDUMP(dhdp) \
274 			((dhdp)->dhd_bus_busy_state & DHD_BUS_BUSY_IN_HALDUMP)
275 #define DHD_BUS_BUSY_CHECK_IDLE(dhdp) \
276 		((dhdp)->dhd_bus_busy_state == 0)
277 
278 #define DHD_BUS_CHECK_SUSPEND_OR_SUSPEND_IN_PROGRESS(dhdp) \
279 	((dhdp)->busstate == DHD_BUS_SUSPEND || DHD_BUS_BUSY_CHECK_SUSPEND_IN_PROGRESS(dhdp))
280 
281 #define DHD_BUS_CHECK_ANY_SUSPEND_IN_PROGRESS(dhdp) \
282 		(DHD_BUS_BUSY_CHECK_SUSPEND_IN_PROGRESS(dhdp) || \
283 		 DHD_BUS_BUSY_CHECK_RPM_SUSPEND_IN_PROGRESS(dhdp))
284 
285 #define DHD_BUS_CHECK_SUSPEND_OR_ANY_SUSPEND_IN_PROGRESS(dhdp) \
286 	((dhdp)->busstate == DHD_BUS_SUSPEND || DHD_BUS_CHECK_ANY_SUSPEND_IN_PROGRESS(dhdp))
287 
288 #define DHD_BUS_CHECK_DOWN_OR_DOWN_IN_PROGRESS(dhdp) \
289 		((dhdp)->busstate == DHD_BUS_DOWN || (dhdp)->busstate == DHD_BUS_DOWN_IN_PROGRESS)
290 
291 /* IOVar flags for common error checks */
292 #define DHD_IOVF_PWRREQ_BYPASS	(1<<0) /* flags to prevent bp access during host sleep state */
293 
294 #define MAX_MTU_SZ (1600u)
295 
296 /* (u64)result = (u64)dividend / (u64)divisor */
297 #define DIV_U64_BY_U64(dividend, divisor)	div64_u64(dividend, divisor)
298 
299 /* (u64)result = (u64)dividend / (u32)divisor */
300 #define DIV_U64_BY_U32(dividend, divisor)	div_u64(dividend, divisor)
301 
302 /* Be careful while using this, as it divides dividend also
303  * (u32)remainder = (u64)dividend % (u32)divisor
304  * (u64)dividend = (u64)dividend / (u32)divisor
305  */
306 #define DIV_AND_MOD_U64_BY_U32(dividend, divisor)	do_div(dividend, divisor)
307 
308 /* (u32)remainder = (u64)dividend % (u32)divisor */
309 #define MOD_U64_BY_U32(dividend, divisor) ({				\
310 	uint64 temp_dividend = (dividend);				\
311 	uint32 rem = DIV_AND_MOD_U64_BY_U32(temp_dividend, (divisor));	\
312 	rem;								\
313 })
314 
315 #define SEC_USEC_FMT \
316 	"%5llu.%06u"
317 
318 /* t: time in nano second */
319 #define GET_SEC_USEC(t) \
320 	DIV_U64_BY_U32(t, NSEC_PER_SEC), \
321 	((uint32)(MOD_U64_BY_U32(t, NSEC_PER_SEC) / (uint32)NSEC_PER_USEC))
322 
323 /* Download Types */
324 typedef enum download_type {
325 	FW,
326 	NVRAM,
327 	CLM_BLOB,
328 	TXCAP_BLOB
329 } download_type_t;
330 
331 /* For supporting multiple interfaces */
332 #define DHD_MAX_IFS		16
333 #define DHD_MAX_STATIC_IFS	5
334 #define DHD_DEL_IF		-0xE
335 #define DHD_BAD_IF		-0xF
336 #define DHD_DUMMY_INFO_IF	0xDEAF	/* Hack i/f to handle events from INFO Ring */
337 #define DHD_EVENT_IF DHD_DUMMY_INFO_IF
338 
339 enum dhd_op_flags {
340 /* Firmware requested operation mode */
341 	DHD_FLAG_STA_MODE				= (1 << (0)), /* STA only */
342 	DHD_FLAG_HOSTAP_MODE				= (1 << (1)), /* SOFTAP only */
343 	DHD_FLAG_P2P_MODE				= (1 << (2)), /* P2P Only */
344 	/* STA + P2P */
345 	DHD_FLAG_CONCURR_SINGLE_CHAN_MODE = (DHD_FLAG_STA_MODE | DHD_FLAG_P2P_MODE),
346 	/* STA + SoftAP */
347 	DHD_FLAG_CONCURR_STA_HOSTAP_MODE = (DHD_FLAG_STA_MODE | DHD_FLAG_HOSTAP_MODE),
348 	DHD_FLAG_CONCURR_MULTI_CHAN_MODE		= (1 << (4)), /* STA + P2P */
349 	/* Current P2P mode for P2P connection */
350 	DHD_FLAG_P2P_GC_MODE				= (1 << (5)),
351 	DHD_FLAG_P2P_GO_MODE				= (1 << (6)),
352 	DHD_FLAG_MBSS_MODE				= (1 << (7)), /* MBSS in future */
353 	DHD_FLAG_IBSS_MODE				= (1 << (8)),
354 	DHD_FLAG_MFG_MODE				= (1 << (9)),
355 	DHD_FLAG_RSDB_MODE				= (1 << (10)),
356 	DHD_FLAG_MP2P_MODE				= (1 << (11))
357 };
358 
359 #define DHD_OPMODE_SUPPORTED(dhd, opmode_flag) \
360 	(dhd ? ((((dhd_pub_t *)dhd)->op_mode)  &  opmode_flag) : -1)
361 #define DHD_OPMODE_STA_SOFTAP_CONCURR(dhd) \
362 	(dhd ? (((dhd->op_mode) & DHD_FLAG_CONCURR_STA_HOSTAP_MODE) == \
363 	DHD_FLAG_CONCURR_STA_HOSTAP_MODE) : 0)
364 
365 /* Max sequential TX/RX Control timeouts to set HANG event */
366 #ifndef MAX_CNTL_TX_TIMEOUT
367 #define MAX_CNTL_TX_TIMEOUT 2
368 #endif /* MAX_CNTL_TX_TIMEOUT */
369 #ifndef MAX_CNTL_RX_TIMEOUT
370 #define MAX_CNTL_RX_TIMEOUT 1
371 #endif /* MAX_CNTL_RX_TIMEOUT */
372 
373 #define DHD_SCAN_ASSOC_ACTIVE_TIME	40 /* ms: Embedded default Active setting from DHD */
374 #define DHD_SCAN_UNASSOC_ACTIVE_TIME 80 /* ms: Embedded def. Unassoc Active setting from DHD */
375 #define DHD_SCAN_HOME_TIME		45 /* ms: Embedded default Home time setting from DHD */
376 #define DHD_SCAN_HOME_AWAY_TIME	100 /* ms: Embedded default Home Away time setting from DHD */
377 #ifndef CUSTOM_SCAN_PASSIVE_TIME
378 #define DHD_SCAN_PASSIVE_TIME		130 /* ms: Embedded default Passive setting from DHD */
379 #else
380 #define DHD_SCAN_PASSIVE_TIME	CUSTOM_SCAN_PASSIVE_TIME /* ms: Custom Passive setting from DHD */
381 #endif	/* CUSTOM_SCAN_PASSIVE_TIME */
382 
383 #ifndef POWERUP_MAX_RETRY
384 #define POWERUP_MAX_RETRY	3 /* how many times we retry to power up the chip */
385 #endif // endif
386 #ifndef POWERUP_WAIT_MS
387 #define POWERUP_WAIT_MS		2000 /* ms: time out in waiting wifi to come up */
388 #endif // endif
389 /*
390  * MAX_NVRAMBUF_SIZE determines the size of the Buffer in the DHD that holds
391  * the NVRAM data. That is the size of the buffer pointed by bus->vars
392  * This also needs to be increased to 16K to support NVRAM size higher than 8K
393  */
394 #define MAX_NVRAMBUF_SIZE	(16 * 1024) /* max nvram buf size */
395 #define MAX_CLM_BUF_SIZE	(48 * 1024) /* max clm blob size */
396 #define MAX_TXCAP_BUF_SIZE	(16 * 1024) /* max txcap blob size */
397 #ifdef DHD_DEBUG
398 #define DHD_JOIN_MAX_TIME_DEFAULT 10000 /* ms: Max time out for joining AP */
399 #define DHD_SCAN_DEF_TIMEOUT 10000 /* ms: Max time out for scan in progress */
400 #endif /* DHD_DEBUG */
401 
402 #ifndef CONFIG_BCMDHD_CLM_PATH
403 #ifdef OEM_ANDROID
404 #define CONFIG_BCMDHD_CLM_PATH "/vendor/etc/firmware/bcmdhd_clm.blob"
405 #else
406 #define CONFIG_BCMDHD_CLM_PATH "/vendor/etc/firmware/bcmdhd_clm.blob"
407 #endif /* OEM_ANDROID */
408 #endif /* CONFIG_BCMDHD_CLM_PATH */
409 #define WL_CCODE_NULL_COUNTRY  "#n"
410 
411 #define FW_VER_STR_LEN	128
412 #define FWID_STR_LEN 256
413 #define CLM_VER_STR_LEN 128
414 #define BUS_API_REV_STR_LEN	128
415 #define FW_VER_STR "Version"
416 #define FWID_STR_1 "FWID: 01-"
417 #define FWID_STR_2 "FWID=01-"
418 extern char bus_api_revision[];
419 
420 enum dhd_bus_wake_state {
421 	WAKE_LOCK_OFF			= 0,
422 	WAKE_LOCK_PRIV			= 1,
423 	WAKE_LOCK_DPC			= 2,
424 	WAKE_LOCK_IOCTL			= 3,
425 	WAKE_LOCK_DOWNLOAD		= 4,
426 	WAKE_LOCK_TMOUT			= 5,
427 	WAKE_LOCK_WATCHDOG		= 6,
428 	WAKE_LOCK_LINK_DOWN_TMOUT	= 7,
429 	WAKE_LOCK_PNO_FIND_TMOUT	= 8,
430 	WAKE_LOCK_SOFTAP_SET		= 9,
431 	WAKE_LOCK_SOFTAP_STOP		= 10,
432 	WAKE_LOCK_SOFTAP_START		= 11,
433 	WAKE_LOCK_SOFTAP_THREAD		= 12
434 };
435 
436 enum dhd_prealloc_index {
437 	DHD_PREALLOC_PROT			= 0,
438 	DHD_PREALLOC_RXBUF			= 1,
439 	DHD_PREALLOC_DATABUF			= 2,
440 	DHD_PREALLOC_OSL_BUF			= 3,
441 	/* 4 */
442 	DHD_PREALLOC_WIPHY_ESCAN0		= 5,
443 	DHD_PREALLOC_WIPHY_ESCAN1		= 6,
444 	DHD_PREALLOC_DHD_INFO			= 7,
445 	DHD_PREALLOC_DHD_WLFC_INFO		= 8,
446 	DHD_PREALLOC_IF_FLOW_LKUP		= 9,
447 	/* 10 */
448 	DHD_PREALLOC_MEMDUMP_RAM		= 11,
449 	DHD_PREALLOC_DHD_WLFC_HANGER		= 12,
450 	DHD_PREALLOC_PKTID_MAP			= 13,
451 	DHD_PREALLOC_PKTID_MAP_IOCTL		= 14,
452 	DHD_PREALLOC_DHD_LOG_DUMP_BUF		= 15,
453 	DHD_PREALLOC_DHD_LOG_DUMP_BUF_EX	= 16,
454 	DHD_PREALLOC_DHD_PKTLOG_DUMP_BUF	= 17
455 };
456 
457 enum dhd_dongledump_mode {
458 	DUMP_DISABLED		= 0,
459 	DUMP_MEMONLY		= 1,
460 	DUMP_MEMFILE		= 2,
461 	DUMP_MEMFILE_BUGON	= 3,
462 	DUMP_MEMFILE_MAX	= 4
463 };
464 
465 enum dhd_dongledump_type {
466 	DUMP_TYPE_RESUMED_ON_TIMEOUT		= 1,
467 	DUMP_TYPE_D3_ACK_TIMEOUT		= 2,
468 	DUMP_TYPE_DONGLE_TRAP			= 3,
469 	DUMP_TYPE_MEMORY_CORRUPTION		= 4,
470 	DUMP_TYPE_PKTID_AUDIT_FAILURE		= 5,
471 	DUMP_TYPE_PKTID_INVALID			= 6,
472 	DUMP_TYPE_SCAN_TIMEOUT			= 7,
473 	DUMP_TYPE_SCAN_BUSY			= 8,
474 	DUMP_TYPE_BY_SYSDUMP			= 9,
475 	DUMP_TYPE_BY_LIVELOCK			= 10,
476 	DUMP_TYPE_AP_LINKUP_FAILURE		= 11,
477 	DUMP_TYPE_AP_ABNORMAL_ACCESS		= 12,
478 	DUMP_TYPE_CFG_VENDOR_TRIGGERED		= 13,
479 	DUMP_TYPE_RESUMED_ON_TIMEOUT_TX		= 14,
480 	DUMP_TYPE_RESUMED_ON_TIMEOUT_RX		= 15,
481 	DUMP_TYPE_RESUMED_ON_INVALID_RING_RDWR	= 16,
482 	DUMP_TYPE_TRANS_ID_MISMATCH		= 17,
483 	DUMP_TYPE_IFACE_OP_FAILURE		= 18,
484 	DUMP_TYPE_DONGLE_INIT_FAILURE		= 19,
485 	DUMP_TYPE_READ_SHM_FAIL			= 20,
486 	DUMP_TYPE_DONGLE_HOST_EVENT		= 21,
487 	DUMP_TYPE_SMMU_FAULT			= 22,
488 	DUMP_TYPE_RESUMED_UNKNOWN		= 23,
489 	DUMP_TYPE_DUE_TO_BT			= 24,
490 	DUMP_TYPE_LOGSET_BEYOND_RANGE		= 25,
491 	DUMP_TYPE_BY_USER			= 26,
492 	DUMP_TYPE_CTO_RECOVERY			= 27,
493 	DUMP_TYPE_SEQUENTIAL_PRIVCMD_ERROR	= 28,
494 	DUMP_TYPE_PROXD_TIMEOUT			= 29,
495 	DUMP_TYPE_PKTID_POOL_DEPLETED		= 30
496 };
497 
498 enum dhd_hang_reason {
499 	HANG_REASON_MASK				= 0x8000,
500 	HANG_REASON_IOCTL_RESP_TIMEOUT			= 0x8001,
501 	HANG_REASON_DONGLE_TRAP				= 0x8002,
502 	HANG_REASON_D3_ACK_TIMEOUT			= 0x8003,
503 	HANG_REASON_BUS_DOWN				= 0x8004,
504 	HANG_REASON_MSGBUF_LIVELOCK			= 0x8006,
505 	HANG_REASON_IFACE_DEL_FAILURE			= 0x8007,
506 	HANG_REASON_HT_AVAIL_ERROR			= 0x8008,
507 	HANG_REASON_PCIE_RC_LINK_UP_FAIL		= 0x8009,
508 	HANG_REASON_PCIE_PKTID_ERROR			= 0x800A,
509 	HANG_REASON_IFACE_ADD_FAILURE			= 0x800B,
510 	HANG_REASON_IOCTL_RESP_TIMEOUT_SCHED_ERROR	= 0x800C,
511 	HANG_REASON_D3_ACK_TIMEOUT_SCHED_ERROR		= 0x800D,
512 	HANG_REASON_SEQUENTIAL_PRIVCMD_ERROR		= 0x800E,
513 	HANG_REASON_PCIE_LINK_DOWN_RC_DETECT		= 0x8805,
514 	HANG_REASON_INVALID_EVENT_OR_DATA		= 0x8806,
515 	HANG_REASON_UNKNOWN				= 0x8807,
516 	HANG_REASON_PCIE_LINK_DOWN_EP_DETECT		= 0x8808,
517 	HANG_REASON_PCIE_CTO_DETECT			= 0x8809,
518 	HANG_REASON_MAX					= 0x880A
519 };
520 
521 #define WLC_E_DEAUTH_MAX_REASON 0x0FFF
522 
523 enum dhd_rsdb_scan_features {
524 	/* Downgraded scan feature for AP active */
525 	RSDB_SCAN_DOWNGRADED_AP_SCAN = 0x01,
526 	/* Downgraded scan feature for P2P Discovery */
527 	RSDB_SCAN_DOWNGRADED_P2P_DISC_SCAN = 0x02,
528 	/* Enable channel pruning for ROAM SCAN */
529 	RSDB_SCAN_DOWNGRADED_CH_PRUNE_ROAM = 0x10,
530 	/* Enable channel pruning for any SCAN */
531 	RSDB_SCAN_DOWNGRADED_CH_PRUNE_ALL  = 0x20
532 };
533 
534 #define VENDOR_SEND_HANG_EXT_INFO_LEN (800 + 1)
535 
536 #ifdef DHD_EWPR_VER2
537 #define VENDOR_SEND_HANG_EXT_INFO_VER 20181111
538 #else
539 #define VENDOR_SEND_HANG_EXT_INFO_VER 20170905
540 #endif // endif
541 
542 #define HANG_INFO_TRAP_T_NAME_MAX 6
543 #define HANG_INFO_TRAP_T_REASON_IDX 0
544 #define HANG_INFO_TRAP_T_SUBTYPE_IDX 2
545 #define HANG_INFO_TRAP_T_OFFSET_IDX 3
546 #define HANG_INFO_TRAP_T_EPC_IDX 4
547 #define HANG_FIELD_STR_MAX_LEN 9
548 #define HANG_FIELD_CNT_MAX 69
549 #define HANG_FIELD_IF_FAILURE_CNT 10
550 #define HANG_FIELD_IOCTL_RESP_TIMEOUT_CNT 8
551 #define HANG_FIELD_TRAP_T_STACK_CNT_MAX 16
552 #define HANG_FIELD_MISMATCH_CNT 10
553 #define HANG_INFO_BIGDATA_KEY_STACK_CNT 4
554 
555 #define DEBUG_DUMP_TIME_BUF_LEN (16 + 1)
556 /* delimiter between values */
557 #define HANG_KEY_DEL	' '
558 #define HANG_RAW_DEL	'_'
559 
560 #ifdef DHD_EWPR_VER2
561 #define HANG_INFO_BIGDATA_EXTRA_KEY 4
562 #define HANG_INFO_TRAP_T_EXTRA_KEY_IDX 5
563 #endif // endif
564 
565 /* Packet alignment for most efficient SDIO (can change based on platform) */
566 #ifndef DHD_SDALIGN
567 #if defined(BCMSPI)
568 #define DHD_SDALIGN 4
569 #else
570 #define DHD_SDALIGN 32
571 #endif /* BCMSPI */
572 #endif /* !DHD_SDALIGN */
573 
574 #define DHD_TX_CONTEXT_MASK 0xff
575 #define DHD_TX_START_XMIT   0x01
576 #define DHD_TX_SEND_PKT     0x02
577 #define DHD_IF_SET_TX_ACTIVE(ifp, context)	\
578     ifp->tx_paths_active |= context;
579 #define DHD_IF_CLR_TX_ACTIVE(ifp, context)	\
580     ifp->tx_paths_active &= ~context;
581 #define DHD_IF_IS_TX_ACTIVE(ifp)	\
582 	(ifp->tx_paths_active)
583 /**
584  * DMA-able buffer parameters
585  * - dmaaddr_t is 32bits on a 32bit host.
586  *   dhd_dma_buf::pa may not be used as a sh_addr_t, bcm_addr64_t or uintptr
587  * - dhd_dma_buf::_alloced is ONLY for freeing a DMA-able buffer.
588  */
589 typedef struct dhd_dma_buf {
590 	void      *va;      /* virtual address of buffer */
591 	uint32    len;      /* user requested buffer length */
592 	dmaaddr_t pa;       /* physical address of buffer */
593 	void      *dmah;    /* dma mapper handle */
594 	void      *secdma;  /* secure dma sec_cma_info handle */
595 	uint32    _alloced; /* actual size of buffer allocated with align and pad */
596 } dhd_dma_buf_t;
597 
598 /* host reordering packts logic */
599 /* followed the structure to hold the reorder buffers (void **p) */
600 typedef struct reorder_info {
601 	void **p;
602 	uint8 flow_id;
603 	uint8 cur_idx;
604 	uint8 exp_idx;
605 	uint8 max_idx;
606 	uint8 pend_pkts;
607 } reorder_info_t;
608 
609 /* throughput test packet format */
610 typedef struct tput_pkt {
611 	/* header */
612 	uint8 mac_sta[ETHER_ADDR_LEN];
613 	uint8 mac_ap[ETHER_ADDR_LEN];
614 	uint16 pkt_type;
615 	uint8 PAD[2];
616 	/* data */
617 	uint32 crc32;
618 	uint32 pkt_id;
619 	uint32 num_pkts;
620 } tput_pkt_t;
621 
622 typedef enum {
623 	TPUT_PKT_TYPE_NORMAL,
624 	TPUT_PKT_TYPE_STOP
625 } tput_pkt_type_t;
626 
627 #define TPUT_TEST_MAX_PAYLOAD 1500
628 #define TPUT_TEST_WAIT_TIMEOUT_DEFAULT 5000
629 
630 #ifdef DHDTCPACK_SUPPRESS
631 
632 enum {
633 	/* TCPACK suppress off */
634 	TCPACK_SUP_OFF,
635 	/* Replace TCPACK in txq when new coming one has higher ACK number. */
636 	TCPACK_SUP_REPLACE,
637 	/* TCPACK_SUP_REPLACE + delayed TCPACK TX unless ACK to PSH DATA.
638 	 * This will give benefits to Half-Duplex bus interface(e.g. SDIO) that
639 	 * 1. we are able to read TCP DATA packets first from the bus
640 	 * 2. TCPACKs that don't need to hurry delivered remains longer in TXQ so can be suppressed.
641 	 */
642 	TCPACK_SUP_DELAYTX,
643 	TCPACK_SUP_HOLD,
644 	TCPACK_SUP_LAST_MODE
645 };
646 #endif /* DHDTCPACK_SUPPRESS */
647 
648 #define DHD_NULL_CHK_AND_RET(cond) \
649 	if (!cond) { \
650 		DHD_ERROR(("%s " #cond " is NULL\n", __FUNCTION__)); \
651 		return; \
652 	}
653 
654 #define DHD_NULL_CHK_AND_RET_VAL(cond, value) \
655 	if (!cond) { \
656 		DHD_ERROR(("%s " #cond " is NULL\n", __FUNCTION__)); \
657 		return value; \
658 	}
659 
660 #define DHD_NULL_CHK_AND_GOTO(cond, label) \
661 	if (!cond) { \
662 		DHD_ERROR(("%s " #cond " is NULL\n", __FUNCTION__)); \
663 		goto label; \
664 	}
665 
666 /*
667  * Accumulating the queue lengths of all flowring queues in a parent object,
668  * to assert flow control, when the cummulative queue length crosses an upper
669  * threshold defined on a parent object. Upper threshold may be maintained
670  * at a station level, at an interface level, or at a dhd instance.
671  *
672  * cumm_ctr_t abstraction:
673  * cumm_ctr_t abstraction may be enhanced to use an object with a hysterisis
674  * pause on/off threshold callback.
675  * All macros use the address of the cummulative length in the parent objects.
676  *
677  * BCM_GMAC3 builds use a single perimeter lock, as opposed to a per queue lock.
678  * Cummulative counters in parent objects may be updated without spinlocks.
679  *
680  * In non BCM_GMAC3, if a cummulative queue length is desired across all flows
681  * belonging to either of (a station, or an interface or a dhd instance), then
682  * an atomic operation is required using an atomic_t cummulative counters or
683  * using a spinlock. BCM_ROUTER_DHD uses the Linux atomic_t construct.
684  */
685 
686 /* Cummulative length not supported. */
687 typedef uint32 cumm_ctr_t;
688 #define DHD_CUMM_CTR_PTR(clen)     ((cumm_ctr_t*)(clen))
689 #define DHD_CUMM_CTR(clen)         *(DHD_CUMM_CTR_PTR(clen)) /* accessor */
690 #define DHD_CUMM_CTR_READ(clen)    DHD_CUMM_CTR(clen) /* read access */
691 #define DHD_CUMM_CTR_INIT(clen)                                                \
692 	ASSERT(DHD_CUMM_CTR_PTR(clen) != DHD_CUMM_CTR_PTR(NULL));
693 #define DHD_CUMM_CTR_INCR(clen)                                                \
694 	ASSERT(DHD_CUMM_CTR_PTR(clen) != DHD_CUMM_CTR_PTR(NULL));
695 #define DHD_CUMM_CTR_DECR(clen)                                                \
696 	ASSERT(DHD_CUMM_CTR_PTR(clen) != DHD_CUMM_CTR_PTR(NULL));
697 
698 #if defined(WLTDLS) && defined(PCIE_FULL_DONGLE)
699 struct tdls_peer_node {
700 	uint8 addr[ETHER_ADDR_LEN];
701 	struct tdls_peer_node *next;
702 };
703 typedef struct tdls_peer_node tdls_peer_node_t;
704 typedef struct {
705 	tdls_peer_node_t *node;
706 	uint8 tdls_peer_count;
707 } tdls_peer_tbl_t;
708 #endif /* defined(WLTDLS) && defined(PCIE_FULL_DONGLE) */
709 
710 #ifdef DHD_LOG_DUMP
711 #define DUMP_SSSR_ATTR_START	2
712 #define DUMP_SSSR_ATTR_COUNT	6
713 
714 typedef enum {
715 	SSSR_C0_D11_BEFORE = 0,
716 	SSSR_C0_D11_AFTER = 1,
717 	SSSR_C1_D11_BEFORE = 2,
718 	SSSR_C1_D11_AFTER = 3,
719 	SSSR_DIG_BEFORE = 4,
720 	SSSR_DIG_AFTER = 5
721 } EWP_SSSR_DUMP;
722 
723 typedef enum {
724 	DLD_BUF_TYPE_GENERAL = 0,
725 	DLD_BUF_TYPE_PRESERVE = 1,
726 	DLD_BUF_TYPE_SPECIAL = 2,
727 	DLD_BUF_TYPE_ECNTRS = 3,
728 	DLD_BUF_TYPE_FILTER = 4,
729 	DLD_BUF_TYPE_ALL = 5
730 } log_dump_type_t;
731 
732 #define LOG_DUMP_MAGIC 0xDEB3DEB3
733 #define HEALTH_CHK_BUF_SIZE 256
734 
735 #ifdef EWP_ECNTRS_LOGGING
736 #define ECNTR_RING_ID 0xECDB
737 #define	ECNTR_RING_NAME	"ewp_ecntr_ring"
738 #endif /* EWP_ECNTRS_LOGGING */
739 
740 #ifdef EWP_RTT_LOGGING
741 #define	RTT_RING_ID 0xADCD
742 #define	RTT_RING_NAME	"ewp_rtt_ring"
743 #endif /* EWP_ECNTRS_LOGGING */
744 
745 #if defined(DEBUGABILITY) && defined(EWP_ECNTRS_LOGGING)
746 #error "Duplicate rings will be created since both the features are enabled"
747 #endif /* DEBUGABILITY && EWP_ECNTRS_LOGGING */
748 
749 typedef enum {
750 	LOG_DUMP_SECTION_GENERAL = 0,
751 	LOG_DUMP_SECTION_ECNTRS,
752 	LOG_DUMP_SECTION_SPECIAL,
753 	LOG_DUMP_SECTION_DHD_DUMP,
754 	LOG_DUMP_SECTION_EXT_TRAP,
755 	LOG_DUMP_SECTION_HEALTH_CHK,
756 	LOG_DUMP_SECTION_PRESERVE,
757 	LOG_DUMP_SECTION_COOKIE,
758 	LOG_DUMP_SECTION_FLOWRING,
759 	LOG_DUMP_SECTION_STATUS,
760 	LOG_DUMP_SECTION_RTT
761 } log_dump_section_type_t;
762 
763 /* Each section in the debug_dump log file shall begin with a header */
764 typedef struct {
765 	uint32 magic;  /* 0xDEB3DEB3 */
766 	uint32 type;   /* of type log_dump_section_type_t */
767 	uint64 timestamp;
768 	uint32 length;  /* length of the section that follows */
769 	uint32 pad;
770 } log_dump_section_hdr_t;
771 
772 /* below structure describe ring buffer. */
773 struct dhd_log_dump_buf
774 {
775 	spinlock_t lock;
776 	void *dhd_pub;
777 	unsigned int enable;
778 	unsigned int wraparound;
779 	unsigned long max;
780 	unsigned int remain;
781 	char* present;
782 	char* front;
783 	char* buffer;
784 };
785 
786 #define DHD_LOG_DUMP_MAX_TEMP_BUFFER_SIZE	256
787 #define DHD_LOG_DUMP_MAX_TAIL_FLUSH_SIZE (80 * 1024)
788 
789 extern void dhd_log_dump_write(int type, char *binary_data,
790 		int binary_len, const char *fmt, ...);
791 #endif /* DHD_LOG_DUMP */
792 
793 /* DEBUG_DUMP SUB COMMAND */
794 enum {
795 	CMD_DEFAULT,
796 	CMD_UNWANTED,
797 	CMD_DISCONNECTED,
798 	CMD_MAX
799 };
800 
801 #define DHD_LOG_DUMP_TS_MULTIPLIER_VALUE    60
802 #define DHD_LOG_DUMP_TS_FMT_YYMMDDHHMMSSMSMS    "%02d%02d%02d%02d%02d%02d%04d"
803 #define DHD_DEBUG_DUMP_TYPE		"debug_dump_FORUSER"
804 #define DHD_DUMP_SUBSTR_UNWANTED	"_unwanted"
805 #define DHD_DUMP_SUBSTR_DISCONNECTED	"_disconnected"
806 
807 #ifdef DNGL_AXI_ERROR_LOGGING
808 #define DHD_DUMP_AXI_ERROR_FILENAME	"axi_error"
809 #define DHD_DUMP_HAL_FILENAME_SUFFIX	"_hal"
810 #endif /* DNGL_AXI_ERROR_LOGGING */
811 
812 extern void get_debug_dump_time(char *str);
813 extern void clear_debug_dump_time(char *str);
814 #if defined(WL_CFGVENDOR_SEND_HANG_EVENT) || defined(DHD_PKT_LOGGING)
815 extern void copy_debug_dump_time(char *dest, char *src);
816 #endif /* WL_CFGVENDOR_SEND_HANG_EVENT || DHD_PKT_LOGGING */
817 
818 #define FW_LOGSET_MASK_ALL 0xFF
819 
820 #ifdef WL_MONITOR
821 #define MONPKT_EXTRA_LEN	48u
822 #endif /* WL_MONITOR */
823 
824 #define DHDIF_FWDER(dhdif)      FALSE
825 
826 #if defined(CUSTOMER_HW2) || defined(BOARD_HIKEY)
827 #define DHD_COMMON_DUMP_PATH	"/data/misc/wifi/"
828 #elif defined(OEM_ANDROID) && (defined(BOARD_PANDA) || defined(__ARM_ARCH_7A__))
829 #define DHD_COMMON_DUMP_PATH	"/data/vendor/wifi/"
830 #elif defined(OEM_ANDROID) /* For Brix Live Image */
831 #define DHD_COMMON_DUMP_PATH	"/installmedia/"
832 #else /* Default */
833 #define DHD_COMMON_DUMP_PATH	"/root/"
834 #endif // endif
835 
836 struct cntry_locales_custom {
837 	char iso_abbrev[WLC_CNTRY_BUF_SZ];      /* ISO 3166-1 country abbreviation */
838 	char custom_locale[WLC_CNTRY_BUF_SZ];   /* Custom firmware locale */
839 	int32 custom_locale_rev;                /* Custom local revisin default -1 */
840 };
841 
842 int dhd_send_msg_to_daemon(struct sk_buff *skb, void *data, int size);
843 
844 #ifdef DMAMAP_STATS
845 typedef struct dmamap_stats {
846 	uint64 txdata;
847 	uint64 txdata_sz;
848 	uint64 rxdata;
849 	uint64 rxdata_sz;
850 	uint64 ioctl_rx;
851 	uint64 ioctl_rx_sz;
852 	uint64 event_rx;
853 	uint64 event_rx_sz;
854 	uint64 info_rx;
855 	uint64 info_rx_sz;
856 	uint64 tsbuf_rx;
857 	uint64 tsbuf_rx_sz;
858 } dma_stats_t;
859 #endif /* DMAMAP_STATS */
860 
861 /*  see wlfc_proto.h for tx status details */
862 #define DHD_MAX_TX_STATUS_MSGS     9u
863 
864 #ifdef TX_STATUS_LATENCY_STATS
865 typedef struct dhd_if_tx_status_latency {
866 	/* total number of tx_status received on this interface */
867 	uint64 num_tx_status;
868 	/* cumulative tx_status latency for this interface */
869 	uint64 cum_tx_status_latency;
870 } dhd_if_tx_status_latency_t;
871 #endif /* TX_STATUS_LATENCY_STATS */
872 
873 #if defined(SHOW_LOGTRACE) && defined(DHD_USE_KTHREAD_FOR_LOGTRACE)
874 /* Timestamps to trace dhd_logtrace_thread() */
875 struct dhd_logtrace_thr_ts {
876 	uint64 entry_time;
877 	uint64 sem_down_time;
878 	uint64 flush_time;
879 	uint64 unexpected_break_time;
880 	uint64 complete_time;
881 };
882 #endif /* SHOW_LOGTRACE && DHD_USE_KTHREAD_FOR_LOGTRACE */
883 
884 /* Enable Reserve STA flowrings only for Android */
885 #if defined(OEM_ANDROID)
886 #define DHD_LIMIT_MULTI_CLIENT_FLOWRINGS
887 #endif /* OEM_ANDROID */
888 
889 typedef enum dhd_induce_error_states
890 {
891 	DHD_INDUCE_ERROR_CLEAR		= 0x0,
892 	DHD_INDUCE_IOCTL_TIMEOUT	= 0x1,
893 	DHD_INDUCE_D3_ACK_TIMEOUT	= 0x2,
894 	DHD_INDUCE_LIVELOCK		= 0x3,
895 	DHD_INDUCE_DROP_OOB_IRQ		= 0x4,
896 	DHD_INDUCE_DROP_AXI_SIG		= 0x5,
897 	DHD_INDUCE_ERROR_MAX		= 0x6
898 } dhd_induce_error_states_t;
899 
900 #ifdef DHD_HP2P
901 #define MAX_TX_HIST_BIN		16
902 #define MAX_RX_HIST_BIN		10
903 #define MAX_HP2P_FLOWS		16
904 #define HP2P_PRIO		7
905 #define HP2P_PKT_THRESH		48
906 #define HP2P_TIME_THRESH	200
907 #define HP2P_PKT_EXPIRY		40
908 #define	HP2P_TIME_SCALE		32
909 
910 typedef struct hp2p_info {
911 	void	*dhd_pub;
912 	uint16	flowid;
913 	bool	hrtimer_init;
914 	void	*ring;
915 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(5, 1, 21))
916 	struct	tasklet_hrtimer timer;
917 #else
918 	struct	hrtimer timer;
919 #endif /* (LINUX_VERSION_CODE <= KERNEL_VERSION(5, 1, 21) */
920 	uint64	num_pkt_limit;
921 	uint64	num_timer_limit;
922 	uint64	num_timer_start;
923 	uint64	tx_t0[MAX_TX_HIST_BIN];
924 	uint64	tx_t1[MAX_TX_HIST_BIN];
925 	uint64	rx_t0[MAX_RX_HIST_BIN];
926 } hp2p_info_t;
927 #endif /* DHD_HP2P */
928 
929 typedef enum {
930 	FW_UNLOADED = 0,
931 	FW_DOWNLOAD_IN_PROGRESS = 1,
932 	FW_DOWNLOAD_DONE = 2
933 } fw_download_status_t;
934 
935 /**
936  * Common structure for module and instance linkage.
937  * Instantiated once per hardware (dongle) instance that this DHD manages.
938  */
939 typedef struct dhd_pub {
940 	/* Linkage ponters */
941 	osl_t *osh;		/* OSL handle */
942 	struct dhd_bus *bus;	/* Bus module handle */
943 	struct dhd_prot *prot;	/* Protocol module handle */
944 	struct dhd_info  *info; /* Info module handle */
945 	struct dhd_dbg *dbg;	/* Debugability module handle */
946 #if defined(SHOW_LOGTRACE) && defined(DHD_USE_KTHREAD_FOR_LOGTRACE)
947 	struct dhd_logtrace_thr_ts logtrace_thr_ts;
948 #endif /* SHOW_LOGTRACE && DHD_USE_KTHREAD_FOR_LOGTRACE */
949 
950 	/* to NDIS developer, the structure dhd_common is redundant,
951 	 * please do NOT merge it back from other branches !!!
952 	 */
953 
954 	/* Internal dhd items */
955 	bool up;		/* Driver up/down (to OS) */
956 #ifdef WL_CFG80211
957 	spinlock_t up_lock;	/* Synchronization with CFG80211 down */
958 #endif /* WL_CFG80211 */
959 	bool txoff;		/* Transmit flow-controlled */
960 	bool dongle_reset;  /* TRUE = DEVRESET put dongle into reset */
961 	enum dhd_bus_state busstate;
962 	uint dhd_bus_busy_state;	/* Bus busy state */
963 	uint hdrlen;		/* Total DHD header length (proto + bus) */
964 	uint maxctl;		/* Max size rxctl request from proto to bus */
965 	uint rxsz;		/* Rx buffer size bus module should use */
966 	uint8 wme_dp;	/* wme discard priority */
967 #ifdef DNGL_AXI_ERROR_LOGGING
968 	uint32 axierror_logbuf_addr;
969 	bool axi_error;
970 	struct dhd_axi_error_dump *axi_err_dump;
971 #endif /* DNGL_AXI_ERROR_LOGGING */
972 	/* Dongle media info */
973 	bool iswl;		/* Dongle-resident driver is wl */
974 	ulong drv_version;	/* Version of dongle-resident driver */
975 	struct ether_addr mac;	/* MAC address obtained from dongle */
976 	dngl_stats_t dstats;	/* Stats for dongle-based data */
977 
978 	/* Additional stats for the bus level */
979 	ulong tx_packets;	/* Data packets sent to dongle */
980 	ulong tx_dropped;	/* Data packets dropped in dhd */
981 	ulong tx_multicast;	/* Multicast data packets sent to dongle */
982 	ulong tx_errors;	/* Errors in sending data to dongle */
983 	ulong tx_ctlpkts;	/* Control packets sent to dongle */
984 	ulong tx_ctlerrs;	/* Errors sending control frames to dongle */
985 	ulong rx_packets;	/* Packets sent up the network interface */
986 	ulong rx_multicast;	/* Multicast packets sent up the network interface */
987 	ulong rx_errors;	/* Errors processing rx data packets */
988 	ulong rx_ctlpkts;	/* Control frames processed from dongle */
989 	ulong rx_ctlerrs;	/* Errors in processing rx control frames */
990 	ulong rx_dropped;	/* Packets dropped locally (no memory) */
991 	ulong rx_flushed;  /* Packets flushed due to unscheduled sendup thread */
992 	ulong wd_dpc_sched;   /* Number of times dhd dpc scheduled by watchdog timer */
993 	ulong rx_pktgetfail; /* Number of PKTGET failures in DHD on RX */
994 	ulong tx_pktgetfail; /* Number of PKTGET failures in DHD on TX */
995 	ulong rx_readahead_cnt;	/* Number of packets where header read-ahead was used. */
996 	ulong tx_realloc;	/* Number of tx packets we had to realloc for headroom */
997 	ulong fc_packets;       /* Number of flow control pkts recvd */
998 	ulong tx_big_packets;	/* Dropped data packets that are larger than MAX_MTU_SZ */
999 #ifdef DMAMAP_STATS
1000 	/* DMA Mapping statistics */
1001 	dma_stats_t dma_stats;
1002 #endif /* DMAMAP_STATS */
1003 
1004 	/* Last error return */
1005 	int bcmerror;
1006 	uint tickcnt;
1007 
1008 	/* Last error from dongle */
1009 	int dongle_error;
1010 
1011 	uint8 country_code[WLC_CNTRY_BUF_SZ];
1012 
1013 	/* Suspend disable flag and "in suspend" flag */
1014 	int suspend_disable_flag; /* "1" to disable all extra powersaving during suspend */
1015 	int in_suspend;			/* flag set to 1 when early suspend called */
1016 #ifdef PNO_SUPPORT
1017 	int pno_enable;			/* pno status : "1" is pno enable */
1018 	int pno_suspend;		/* pno suspend status : "1" is pno suspended */
1019 #endif /* PNO_SUPPORT */
1020 	/* DTIM skip value, default 0(or 1) means wake each DTIM
1021 	 * 3 means skip 2 DTIMs and wake up 3rd DTIM(9th beacon when AP DTIM is 3)
1022 	 */
1023 	int suspend_bcn_li_dtim;         /* bcn_li_dtim value in suspend mode */
1024 #ifdef PKT_FILTER_SUPPORT
1025 	int early_suspended;	/* Early suspend status */
1026 	int dhcp_in_progress;	/* DHCP period */
1027 #endif // endif
1028 
1029 	/* Pkt filter defination */
1030 	char * pktfilter[100];
1031 	int pktfilter_count;
1032 
1033 	wl_country_t dhd_cspec;		/* Current Locale info */
1034 #ifdef CUSTOM_COUNTRY_CODE
1035 	uint dhd_cflags;
1036 #endif /* CUSTOM_COUNTRY_CODE */
1037 #if defined(DHD_BLOB_EXISTENCE_CHECK)
1038 	bool is_blob;			/* Checking for existance of Blob file */
1039 #endif /* DHD_BLOB_EXISTENCE_CHECK */
1040 	bool force_country_change;
1041 	char eventmask[WL_EVENTING_MASK_LEN];
1042 	int	op_mode;				/* STA, HostAPD, WFD, SoftAP */
1043 
1044 /* Set this to 1 to use a seperate interface (p2p0) for p2p operations.
1045  *  For ICS MR1 releases it should be disable to be compatable with ICS MR1 Framework
1046  *  see target dhd-cdc-sdmmc-panda-cfg80211-icsmr1-gpl-debug in Makefile
1047  */
1048 /* #define WL_ENABLE_P2P_IF		1 */
1049 
1050 #if defined(OEM_ANDROID)
1051 	struct mutex wl_start_stop_lock; /* lock/unlock for Android start/stop */
1052 	struct mutex wl_softap_lock;		 /* lock/unlock for any SoftAP/STA settings */
1053 #endif /* defined(OEM_ANDROID) */
1054 
1055 #ifdef PROP_TXSTATUS
1056 	bool	wlfc_enabled;
1057 	int	wlfc_mode;
1058 	void*	wlfc_state;
1059 	/*
1060 	Mode in which the dhd flow control shall operate. Must be set before
1061 	traffic starts to the device.
1062 	0 - Do not do any proptxtstatus flow control
1063 	1 - Use implied credit from a packet status
1064 	2 - Use explicit credit
1065 	3 - Only AMPDU hostreorder used. no wlfc.
1066 	*/
1067 	uint8	proptxstatus_mode;
1068 	bool	proptxstatus_txoff;
1069 	bool	proptxstatus_module_ignore;
1070 	bool	proptxstatus_credit_ignore;
1071 	bool	proptxstatus_txstatus_ignore;
1072 
1073 	bool	wlfc_rxpkt_chk;
1074 #ifdef LIMIT_BORROW
1075 	bool wlfc_borrow_allowed;
1076 #endif /* LIMIT_BORROW */
1077 	/*
1078 	 * implement below functions in each platform if needed.
1079 	 */
1080 	/* platform specific function whether to skip flow control */
1081 	bool (*skip_fc)(void * dhdp, uint8 ifx);
1082 	/* platform specific function for wlfc_enable and wlfc_deinit */
1083 	void (*plat_init)(void *dhd);
1084 	void (*plat_deinit)(void *dhd);
1085 #ifdef DHD_WLFC_THREAD
1086 	bool                wlfc_thread_go;
1087 	struct task_struct* wlfc_thread;
1088 	wait_queue_head_t   wlfc_wqhead;
1089 #endif /* DHD_WLFC_THREAD */
1090 #endif /* PROP_TXSTATUS */
1091 #ifdef PNO_SUPPORT
1092 	void *pno_state;
1093 #endif // endif
1094 #ifdef RTT_SUPPORT
1095 	void *rtt_state;
1096 #endif // endif
1097 #ifdef ROAM_AP_ENV_DETECTION
1098 	bool	roam_env_detection;
1099 #endif // endif
1100 	bool	dongle_isolation;
1101 	bool	is_pcie_watchdog_reset;
1102 
1103 /* Begin - Variables to track Bus Errors */
1104 	bool	dongle_trap_occured;	/* flag for sending HANG event to upper layer */
1105 	bool	iovar_timeout_occured;	/* flag to indicate iovar resumed on timeout */
1106 	bool	is_sched_error;		/* flag to indicate timeout due to scheduling issue */
1107 #ifdef PCIE_FULL_DONGLE
1108 	bool	d3ack_timeout_occured;	/* flag to indicate d3ack resumed on timeout */
1109 	bool	livelock_occured;	/* flag to indicate livelock occured */
1110 	bool	pktid_audit_failed;	/* flag to indicate pktid audit failure */
1111 #endif /* PCIE_FULL_DONGLE */
1112 	bool	iface_op_failed;	/* flag to indicate interface operation failed */
1113 	bool	scan_timeout_occurred;	/* flag to indicate scan has timedout */
1114 	bool	scan_busy_occurred;	/* flag to indicate scan busy occurred */
1115 #ifdef BT_OVER_SDIO
1116 	bool	is_bt_recovery_required;
1117 #endif // endif
1118 	bool	smmu_fault_occurred;	/* flag to indicate SMMU Fault */
1119 	/*
1120 	 * Add any new variables to track Bus errors above
1121 	 * this line. Also ensure that the variable is
1122 	 * cleared from dhd_clear_bus_errors
1123 	 */
1124 /* End - Variables to track Bus Errors */
1125 
1126 	int   hang_was_sent;
1127 	int   hang_was_pending;
1128 	int   rxcnt_timeout;		/* counter rxcnt timeout to send HANG */
1129 	int   txcnt_timeout;		/* counter txcnt timeout to send HANG */
1130 #ifdef BCMPCIE
1131 	int   d3ackcnt_timeout;		/* counter d3ack timeout to send HANG */
1132 #endif /* BCMPCIE */
1133 	bool hang_report;		/* enable hang report by default */
1134 	uint16 hang_reason;		/* reason codes for HANG event */
1135 #if defined(DHD_HANG_SEND_UP_TEST)
1136 	uint req_hang_type;
1137 #endif /* DHD_HANG_SEND_UP_TEST */
1138 #if defined(CONFIG_BCM_DETECT_CONSECUTIVE_HANG)
1139 	uint hang_counts;
1140 #endif /* CONFIG_BCM_DETECT_CONSECUTIVE_HANG */
1141 #ifdef WLTDLS
1142 	bool tdls_enable;
1143 #endif // endif
1144 	struct reorder_info *reorder_bufs[WLHOST_REORDERDATA_MAXFLOWS];
1145 	#define WLC_IOCTL_MAXBUF_FWCAP	1024
1146 	char  fw_capabilities[WLC_IOCTL_MAXBUF_FWCAP];
1147 	#define MAXSKBPEND 1024
1148 	void *skbbuf[MAXSKBPEND];
1149 	uint32 store_idx;
1150 	uint32 sent_idx;
1151 #ifdef DHDTCPACK_SUPPRESS
1152 	uint8 tcpack_sup_mode;		/* TCPACK suppress mode */
1153 	void *tcpack_sup_module;	/* TCPACK suppress module */
1154 	uint32 tcpack_sup_ratio;
1155 	uint32 tcpack_sup_delay;
1156 #endif /* DHDTCPACK_SUPPRESS */
1157 #if defined(ARP_OFFLOAD_SUPPORT)
1158 	uint32 arp_version;
1159 #endif // endif
1160 #if defined(BCMSUP_4WAY_HANDSHAKE)
1161 	bool fw_4way_handshake;		/* Whether firmware will to do the 4way handshake. */
1162 #endif // endif
1163 #ifdef DEBUG_DPC_THREAD_WATCHDOG
1164 	bool dhd_bug_on;
1165 #endif /* DEBUG_DPC_THREAD_WATCHDOG */
1166 #ifdef CUSTOM_SET_CPUCORE
1167 	struct task_struct * current_dpc;
1168 	struct task_struct * current_rxf;
1169 	int chan_isvht80;
1170 #endif /* CUSTOM_SET_CPUCORE */
1171 
1172 	void    *sta_pool;          /* pre-allocated pool of sta objects */
1173 	void    *staid_allocator;   /* allocator of sta indexes */
1174 #ifdef PCIE_FULL_DONGLE
1175 	bool	flow_rings_inited;	/* set this flag after initializing flow rings */
1176 #endif /* PCIE_FULL_DONGLE */
1177 	void    *flowid_allocator;  /* unique flowid allocator */
1178 	void	*flow_ring_table;   /* flow ring table, include prot and bus info */
1179 	void	*if_flow_lkup;      /* per interface flowid lkup hash table */
1180 	void    *flowid_lock;       /* per os lock for flowid info protection */
1181 	void    *flowring_list_lock;       /* per os lock for flowring list protection */
1182 	uint8	max_multi_client_flow_rings;
1183 	uint8	multi_client_flow_rings;
1184 	uint32  num_flow_rings;
1185 	cumm_ctr_t cumm_ctr;        /* cumm queue length placeholder  */
1186 	cumm_ctr_t l2cumm_ctr;      /* level 2 cumm queue length placeholder */
1187 	uint32 d2h_sync_mode;       /* D2H DMA completion sync mode */
1188 	uint8  flow_prio_map[NUMPRIO];
1189 	uint8	flow_prio_map_type;
1190 	char enable_log[MAX_EVENT];
1191 	bool dma_d2h_ring_upd_support;
1192 	bool dma_h2d_ring_upd_support;
1193 	bool dma_ring_upd_overwrite;	/* host overwrites support setting */
1194 
1195 	bool hwa_enable;
1196 	uint hwa_inited;
1197 
1198 	bool idma_enable;
1199 	uint idma_inited;
1200 
1201 	bool ifrm_enable;			/* implicit frm enable */
1202 	uint ifrm_inited;			/* implicit frm init */
1203 
1204 	bool dar_enable;		/* use DAR registers */
1205 	uint dar_inited;
1206 
1207 	bool fast_delete_ring_support;		/* fast delete ring supported */
1208 
1209 #ifdef DHD_L2_FILTER
1210 	unsigned long l2_filter_cnt;	/* for L2_FILTER ARP table timeout */
1211 #endif /* DHD_L2_FILTER */
1212 #ifdef DHD_SSSR_DUMP
1213 	bool sssr_inited;
1214 	bool sssr_dump_collected;	/* Flag to indicate sssr dump is collected */
1215 	sssr_reg_info_v1_t sssr_reg_info;
1216 	uint8 *sssr_mempool;
1217 	uint *sssr_d11_before[MAX_NUM_D11CORES];
1218 	uint *sssr_d11_after[MAX_NUM_D11CORES];
1219 	bool sssr_d11_outofreset[MAX_NUM_D11CORES];
1220 	uint *sssr_dig_buf_before;
1221 	uint *sssr_dig_buf_after;
1222 	uint32 sssr_dump_mode;
1223 	bool collect_sssr;		/* Flag to indicate SSSR dump is required */
1224 #endif /* DHD_SSSR_DUMP */
1225 	uint8 *soc_ram;
1226 	uint32 soc_ram_length;
1227 	uint32 memdump_type;
1228 #ifdef DHD_RND_DEBUG
1229 	uint8 *rnd_buf;
1230 	uint32 rnd_len;
1231 #endif /* DHD_RND_DEBUG */
1232 #ifdef DHD_FW_COREDUMP
1233 	uint32 memdump_enabled;
1234 #ifdef DHD_DEBUG_UART
1235 	bool memdump_success;
1236 #endif	/* DHD_DEBUG_UART */
1237 #endif /* DHD_FW_COREDUMP */
1238 #ifdef PCIE_FULL_DONGLE
1239 #ifdef WLTDLS
1240 	tdls_peer_tbl_t peer_tbl;
1241 #endif /* WLTDLS */
1242 	uint8 tx_in_progress;
1243 #endif /* PCIE_FULL_DONGLE */
1244 #ifdef DHD_ULP
1245 	void *dhd_ulp;
1246 #endif // endif
1247 #ifdef WLTDLS
1248 	uint32 tdls_mode;
1249 #endif // endif
1250 #ifdef GSCAN_SUPPORT
1251 	bool lazy_roam_enable;
1252 #endif // endif
1253 #if defined(PKT_FILTER_SUPPORT) && defined(APF)
1254 	bool apf_set;
1255 #endif /* PKT_FILTER_SUPPORT && APF */
1256 	void *macdbg_info;
1257 #ifdef DHD_WET
1258 	void *wet_info;
1259 #endif // endif
1260 	bool	h2d_phase_supported;
1261 	bool	force_dongletrap_on_bad_h2d_phase;
1262 	uint32	dongle_trap_data;
1263 	fw_download_status_t	fw_download_status;
1264 	trap_t	last_trap_info; /* trap info from the last trap */
1265 	uint8 rand_mac_oui[DOT11_OUI_LEN];
1266 #ifdef DHD_LOSSLESS_ROAMING
1267 	uint8 dequeue_prec_map;
1268 	uint8 prio_8021x;
1269 #endif // endif
1270 #ifdef WL_NATOE
1271 	struct dhd_nfct_info *nfct;
1272 	spinlock_t nfct_lock;
1273 #endif /* WL_NATOE */
1274 	/* timesync link */
1275 	struct dhd_ts *ts;
1276 	bool	d2h_hostrdy_supported;
1277 #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
1278 	atomic_t block_bus;
1279 #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
1280 #if defined(DBG_PKT_MON) || defined(DHD_PKT_LOGGING)
1281 	bool d11_tx_status;
1282 #endif /* DBG_PKT_MON || DHD_PKT_LOGGING */
1283 	uint16 ndo_version;	/* ND offload version supported */
1284 #ifdef NDO_CONFIG_SUPPORT
1285 	bool ndo_enable;		/* ND offload feature enable */
1286 	bool ndo_host_ip_overflow;	/* # of host ip addr exceed FW capacity */
1287 	uint32 ndo_max_host_ip;		/* # of host ip addr supported by FW */
1288 #endif /* NDO_CONFIG_SUPPORT */
1289 #if defined(DHD_LOG_DUMP)
1290 	/* buffer to hold 'dhd dump' data before dumping to file */
1291 	uint8 *concise_dbg_buf;
1292 	uint64 last_file_posn;
1293 	int logdump_periodic_flush;
1294 	/* ecounter debug ring */
1295 #ifdef EWP_ECNTRS_LOGGING
1296 	void *ecntr_dbg_ring;
1297 #endif // endif
1298 #ifdef EWP_RTT_LOGGING
1299 	void *rtt_dbg_ring;
1300 #endif // endif
1301 #ifdef DNGL_EVENT_SUPPORT
1302 	uint8 health_chk_event_data[HEALTH_CHK_BUF_SIZE];
1303 #endif // endif
1304 	void *logdump_cookie;
1305 #endif /* DHD_LOG_DUMP */
1306 	uint32 dhd_console_ms; /** interval for polling the dongle for console (log) messages */
1307 	bool ext_trap_data_supported;
1308 	uint32 *extended_trap_data;
1309 #ifdef DUMP_IOCTL_IOV_LIST
1310 	/* dump iovar list */
1311 	dll_t dump_iovlist_head;
1312 	uint8 dump_iovlist_len;
1313 #endif /* DUMP_IOCTL_IOV_LIST */
1314 #ifdef CUSTOM_SET_ANTNPM
1315 	uint32 mimo_ant_set;
1316 #endif /* CUSTOM_SET_ANTNPM */
1317 #ifdef CUSTOM_SET_OCLOFF
1318 	bool ocl_off;
1319 #endif /* CUSTOM_SET_OCLOFF */
1320 #ifdef DHD_DEBUG
1321 	/* memwaste feature */
1322 	dll_t mw_list_head; /* memwaste list head */
1323 	uint32 mw_id; /* memwaste list unique id */
1324 #endif /* DHD_DEBUG */
1325 #ifdef WLTDLS
1326 	spinlock_t tdls_lock;
1327 #endif /* WLTDLS */
1328 	uint pcie_txs_metadata_enable;
1329 	uint wbtext_policy;	/* wbtext policy of dongle */
1330 	bool wbtext_support;	/* for product policy only */
1331 	bool max_dtim_enable;	/* use MAX bcn_li_dtim value in suspend mode */
1332 	tput_test_t tput_data;
1333 	uint64 tput_start_ts;
1334 	uint64 tput_stop_ts;
1335 #ifdef WL_MONITOR
1336 	bool monitor_enable;
1337 #endif // endif
1338 #ifdef DHD_PKT_LOGGING
1339 	struct dhd_pktlog *pktlog;
1340 	char debug_dump_time_pktlog_str[DEBUG_DUMP_TIME_BUF_LEN];
1341 #endif /* DHD_PKT_LOGGING */
1342 	uint dhd_watchdog_ms_backup;
1343 	void *event_log_filter;
1344 #ifdef WL_CFGVENDOR_SEND_HANG_EVENT
1345 	char *hang_info;
1346 	int hang_info_cnt;
1347 	char debug_dump_time_hang_str[DEBUG_DUMP_TIME_BUF_LEN];
1348 #endif /* WL_CFGVENDOR_SEND_HANG_EVENT */
1349 	char debug_dump_time_str[DEBUG_DUMP_TIME_BUF_LEN];
1350 	uint32 logset_prsrv_mask;
1351 	bool wl_event_enabled;
1352 	bool logtrace_pkt_sendup;
1353 #ifdef DHD_DUMP_MNGR
1354 	struct _dhd_dump_file_manage *dump_file_manage;
1355 #endif /* DHD_DUMP_MNGR */
1356 	int debug_dump_subcmd;
1357 	uint64 debug_dump_time_sec;
1358 	bool hscb_enable;
1359 	wait_queue_head_t tx_completion_wait;
1360 	uint32 batch_tx_pkts_cmpl;
1361 	uint32 batch_tx_num_pkts;
1362 #ifdef DHD_ERPOM
1363 	bool enable_erpom;
1364 	pom_func_handler_t pom_wlan_handler;
1365 	int (*pom_func_register)(pom_func_handler_t *func);
1366 	int (*pom_func_deregister)(pom_func_handler_t *func);
1367 	int (*pom_toggle_reg_on)(uchar func_id, uchar reason);
1368 #endif /* DHD_ERPOM */
1369 #ifdef EWP_EDL
1370 	bool dongle_edl_support;
1371 	dhd_dma_buf_t edl_ring_mem;
1372 #endif /* EWP_EDL */
1373 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
1374 	struct mutex ndev_op_sync;
1375 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) */
1376 
1377 	bool debug_buf_dest_support;
1378 	uint32 debug_buf_dest_stat[DEBUG_BUF_DEST_MAX];
1379 #if defined(DHD_H2D_LOG_TIME_SYNC)
1380 #define DHD_H2D_LOG_TIME_STAMP_MATCH	(10000) /* 10 Seconds */
1381 	/*
1382 	 * Interval for updating the dongle console message time stamp with the Host (DHD)
1383 	 * time stamp
1384 	 */
1385 	uint32 dhd_rte_time_sync_ms;
1386 #endif /* DHD_H2D_LOG_TIME_SYNC */
1387 	int wlc_ver_major;
1388 	int wlc_ver_minor;
1389 #ifdef DHD_STATUS_LOGGING
1390 	void *statlog;
1391 #endif /* DHD_STATUS_LOGGING */
1392 #ifdef DHD_HP2P
1393 	bool hp2p_enable;
1394 	bool hp2p_infra_enable;
1395 	bool hp2p_capable;
1396 	bool hp2p_ts_capable;
1397 	uint16 pkt_thresh;
1398 	uint16 time_thresh;
1399 	uint16 pkt_expiry;
1400 	hp2p_info_t hp2p_info[MAX_HP2P_FLOWS];
1401 	bool hp2p_ring_active;
1402 #endif /* D2H_HP2P */
1403 #ifdef DHD_DB0TS
1404 	bool db0ts_capable;
1405 #endif /* DHD_DB0TS */
1406 	bool event_log_max_sets_queried;
1407 	uint32 event_log_max_sets;
1408 	uint16 dhd_induce_error;
1409 #ifdef CONFIG_SILENT_ROAM
1410 	bool sroam_turn_on;	/* Silent roam monitor enable flags */
1411 	bool sroamed;		/* Silent roam monitor check flags */
1412 #endif /* CONFIG_SILENT_ROAM */
1413 	bool extdtxs_in_txcpl;
1414 	bool hostrdy_after_init;
1415 #ifdef SUPPORT_SET_TID
1416 	uint8 tid_mode;
1417 	uint32 target_uid;
1418 	uint8 target_tid;
1419 #endif /* SUPPORT_SET_TID */
1420 #ifdef DHD_PKTDUMP_ROAM
1421 	void *pktcnts;
1422 #endif /* DHD_PKTDUMP_ROAM */
1423 	bool disable_dtim_in_suspend;	/* Disable set bcn_li_dtim in suspend */
1424 #ifdef REVERSE_AIFSN
1425 	bool aifsn_reverse;
1426 #endif /* REVERSE_AIFSN */
1427 } dhd_pub_t;
1428 
1429 typedef struct {
1430 	uint rxwake;
1431 	uint rcwake;
1432 #ifdef DHD_WAKE_RX_STATUS
1433 	uint rx_bcast;
1434 	uint rx_arp;
1435 	uint rx_mcast;
1436 	uint rx_multi_ipv6;
1437 	uint rx_icmpv6;
1438 	uint rx_icmpv6_ra;
1439 	uint rx_icmpv6_na;
1440 	uint rx_icmpv6_ns;
1441 	uint rx_multi_ipv4;
1442 	uint rx_multi_other;
1443 	uint rx_ucast;
1444 #endif /* DHD_WAKE_RX_STATUS */
1445 #ifdef DHD_WAKE_EVENT_STATUS
1446 	uint rc_event[WLC_E_LAST];
1447 #endif /* DHD_WAKE_EVENT_STATUS */
1448 } wake_counts_t;
1449 
1450 #if defined(PCIE_FULL_DONGLE)
1451 
1452 /* Packet Tag for PCIE Full Dongle DHD */
1453 typedef struct dhd_pkttag_fd {
1454 	uint16    flowid;   /* Flowring Id */
1455 	uint16    ifid;
1456 #ifndef DHD_PCIE_PKTID
1457 	uint16    dma_len;  /* pkt len for DMA_MAP/UNMAP */
1458 	dmaaddr_t pa;       /* physical address */
1459 	void      *dmah;    /* dma mapper handle */
1460 	void      *secdma; /* secure dma sec_cma_info handle */
1461 #endif /* !DHD_PCIE_PKTID */
1462 #if defined(TX_STATUS_LATENCY_STATS)
1463 	uint64	   q_time_us; /* time when tx pkt queued to flowring */
1464 #endif // endif
1465 	uint16     flags;
1466 } dhd_pkttag_fd_t;
1467 
1468 /* Packet Tag for DHD PCIE Full Dongle */
1469 #define DHD_PKTTAG_FD(pkt)          ((dhd_pkttag_fd_t *)(PKTTAG(pkt)))
1470 
1471 #define DHD_PKT_GET_FLOWID(pkt)     ((DHD_PKTTAG_FD(pkt))->flowid)
1472 #define DHD_PKT_SET_FLOWID(pkt, pkt_flowid) \
1473 	DHD_PKTTAG_FD(pkt)->flowid = (uint16)(pkt_flowid)
1474 
1475 #define DHD_PKT_GET_DATAOFF(pkt)    ((DHD_PKTTAG_FD(pkt))->dataoff)
1476 #define DHD_PKT_SET_DATAOFF(pkt, pkt_dataoff) \
1477 	DHD_PKTTAG_FD(pkt)->dataoff = (uint16)(pkt_dataoff)
1478 
1479 #define DHD_PKT_GET_DMA_LEN(pkt)    ((DHD_PKTTAG_FD(pkt))->dma_len)
1480 #define DHD_PKT_SET_DMA_LEN(pkt, pkt_dma_len) \
1481 	DHD_PKTTAG_FD(pkt)->dma_len = (uint16)(pkt_dma_len)
1482 
1483 #define DHD_PKT_GET_PA(pkt)         ((DHD_PKTTAG_FD(pkt))->pa)
1484 #define DHD_PKT_SET_PA(pkt, pkt_pa) \
1485 	DHD_PKTTAG_FD(pkt)->pa = (dmaaddr_t)(pkt_pa)
1486 
1487 #define DHD_PKT_GET_DMAH(pkt)       ((DHD_PKTTAG_FD(pkt))->dmah)
1488 #define DHD_PKT_SET_DMAH(pkt, pkt_dmah) \
1489 	DHD_PKTTAG_FD(pkt)->dmah = (void *)(pkt_dmah)
1490 
1491 #define DHD_PKT_GET_SECDMA(pkt)    ((DHD_PKTTAG_FD(pkt))->secdma)
1492 #define DHD_PKT_SET_SECDMA(pkt, pkt_secdma) \
1493 	DHD_PKTTAG_FD(pkt)->secdma = (void *)(pkt_secdma)
1494 
1495 #if defined(TX_STATUS_LATENCY_STATS)
1496 #define DHD_PKT_GET_QTIME(pkt)    ((DHD_PKTTAG_FD(pkt))->q_time_us)
1497 #define DHD_PKT_SET_QTIME(pkt, pkt_q_time_us) \
1498 	DHD_PKTTAG_FD(pkt)->q_time_us = (uint64)(pkt_q_time_us)
1499 #endif // endif
1500 
1501 #define DHD_PKT_GET_FLAGS(pkt)    ((DHD_PKTTAG_FD(pkt))->flags)
1502 #define DHD_PKT_SET_FLAGS(pkt, pkt_flags) \
1503 	DHD_PKTTAG_FD(pkt)->flags = (uint16)(pkt_flags)
1504 
1505 #define PKTFLAG_NO_FWD	0x8000
1506 
1507 #define DHD_PKT_FLAGS_SET_NO_FWD(pkt) \
1508 	DHD_PKTTAG_FD(pkt)->flags |= PKTFLAG_NO_FWD
1509 #define DHD_PKT_FLAGS_CLEAR_NO_FWD(pkt) \
1510 	DHD_PKTTAG_FD(pkt)->flags &= ~PKTFLAG_NO_FWD
1511 #define DHD_PKT_FLAGS_IS_NO_FWD(pkt) \
1512 	(DHD_PKTTAG_FD(pkt)->flags & PKTFLAG_NO_FWD)
1513 
1514 #endif /* PCIE_FULL_DONGLE */
1515 
1516 #if defined(BCMWDF)
1517 typedef struct {
1518 	dhd_pub_t *dhd_pub;
1519 } dhd_workitem_context_t;
1520 
1521 WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(dhd_workitem_context_t, dhd_get_dhd_workitem_context)
1522 #endif /* (BCMWDF)  */
1523 
1524 	#if defined(CONFIG_PM_SLEEP)
1525 
1526 	#define DHD_PM_RESUME_WAIT_INIT(a) DECLARE_WAIT_QUEUE_HEAD(a);
1527 	#define _DHD_PM_RESUME_WAIT(a, b) do {\
1528 			int retry = 0; \
1529 			SMP_RD_BARRIER_DEPENDS(); \
1530 			while (dhd_mmc_suspend && retry++ != b) { \
1531 				SMP_RD_BARRIER_DEPENDS(); \
1532 				wait_event_interruptible_timeout(a, !dhd_mmc_suspend, 1); \
1533 			} \
1534 		} 	while (0)
1535 	#define DHD_PM_RESUME_WAIT(a) 		_DHD_PM_RESUME_WAIT(a, 200)
1536 	#define DHD_PM_RESUME_WAIT_FOREVER(a) 	_DHD_PM_RESUME_WAIT(a, ~0)
1537 	#define DHD_PM_RESUME_RETURN_ERROR(a)   do { \
1538 			if (dhd_mmc_suspend) { \
1539 				printf("%s[%d]: mmc is still in suspend state!!!\n", \
1540 					__FUNCTION__, __LINE__); \
1541 				return a; \
1542 			} \
1543 		} while (0)
1544 	#define DHD_PM_RESUME_RETURN		do { if (dhd_mmc_suspend) return; } while (0)
1545 
1546 	#define DHD_SPINWAIT_SLEEP_INIT(a) DECLARE_WAIT_QUEUE_HEAD(a);
1547 	#define SPINWAIT_SLEEP(a, exp, us) do { \
1548 		uint countdown = (us) + 9999; \
1549 		while ((exp) && (countdown >= 10000)) { \
1550 			wait_event_interruptible_timeout(a, FALSE, 1); \
1551 			countdown -= 10000; \
1552 		} \
1553 	} while (0)
1554 
1555 	#else
1556 
1557 	#define DHD_PM_RESUME_WAIT_INIT(a)
1558 	#define DHD_PM_RESUME_WAIT(a)
1559 	#define DHD_PM_RESUME_WAIT_FOREVER(a)
1560 	#define DHD_PM_RESUME_RETURN_ERROR(a)
1561 	#define DHD_PM_RESUME_RETURN
1562 
1563 	#define DHD_SPINWAIT_SLEEP_INIT(a)
1564 	#define SPINWAIT_SLEEP(a, exp, us)  do { \
1565 		uint countdown = (us) + 9; \
1566 		while ((exp) && (countdown >= 10)) { \
1567 			OSL_DELAY(10);  \
1568 			countdown -= 10;  \
1569 		} \
1570 	} while (0)
1571 
1572 	#endif /* CONFIG_PM_SLEEP */
1573 
1574 #ifndef OSL_SLEEP
1575 #define OSL_SLEEP(ms)		OSL_DELAY(ms*1000)
1576 #endif /* OSL_SLEEP */
1577 
1578 #define DHD_IF_VIF	0x01	/* Virtual IF (Hidden from user) */
1579 
1580 #ifdef PNO_SUPPORT
1581 int dhd_pno_clean(dhd_pub_t *dhd);
1582 #endif /* PNO_SUPPORT */
1583 
1584 /*
1585  *  Wake locks are an Android power management concept. They are used by applications and services
1586  *  to request CPU resources.
1587  */
1588 #if defined(OEM_ANDROID)
1589 extern int dhd_os_wake_lock(dhd_pub_t *pub);
1590 extern int dhd_os_wake_unlock(dhd_pub_t *pub);
1591 extern int dhd_os_wake_lock_waive(dhd_pub_t *pub);
1592 extern int dhd_os_wake_lock_restore(dhd_pub_t *pub);
1593 extern void dhd_event_wake_lock(dhd_pub_t *pub);
1594 extern void dhd_event_wake_unlock(dhd_pub_t *pub);
1595 extern void dhd_pm_wake_lock_timeout(dhd_pub_t *pub, int val);
1596 extern void dhd_pm_wake_unlock(dhd_pub_t *pub);
1597 extern void dhd_txfl_wake_lock_timeout(dhd_pub_t *pub, int val);
1598 extern void dhd_txfl_wake_unlock(dhd_pub_t *pub);
1599 extern int dhd_os_wake_lock_timeout(dhd_pub_t *pub);
1600 extern int dhd_os_wake_lock_rx_timeout_enable(dhd_pub_t *pub, int val);
1601 extern int dhd_os_wake_lock_ctrl_timeout_enable(dhd_pub_t *pub, int val);
1602 extern int dhd_os_wake_lock_ctrl_timeout_cancel(dhd_pub_t *pub);
1603 extern int dhd_os_wd_wake_lock(dhd_pub_t *pub);
1604 extern int dhd_os_wd_wake_unlock(dhd_pub_t *pub);
1605 extern void dhd_os_wake_lock_init(struct dhd_info *dhd);
1606 extern void dhd_os_wake_lock_destroy(struct dhd_info *dhd);
1607 #ifdef DHD_USE_SCAN_WAKELOCK
1608 extern void dhd_os_scan_wake_lock_timeout(dhd_pub_t *pub, int val);
1609 extern void dhd_os_scan_wake_unlock(dhd_pub_t *pub);
1610 #endif /* BCMPCIE_SCAN_WAKELOCK */
1611 
MUTEX_LOCK_SOFTAP_SET_INIT(dhd_pub_t * dhdp)1612 inline static void MUTEX_LOCK_SOFTAP_SET_INIT(dhd_pub_t * dhdp)
1613 {
1614 #if defined(OEM_ANDROID)
1615 	mutex_init(&dhdp->wl_softap_lock);
1616 #endif /* OEM_ANDROID */
1617 }
1618 
MUTEX_LOCK_SOFTAP_SET(dhd_pub_t * dhdp)1619 inline static void MUTEX_LOCK_SOFTAP_SET(dhd_pub_t * dhdp)
1620 {
1621 #if defined(OEM_ANDROID)
1622 	mutex_lock(&dhdp->wl_softap_lock);
1623 #endif /* OEM_ANDROID */
1624 }
1625 
MUTEX_UNLOCK_SOFTAP_SET(dhd_pub_t * dhdp)1626 inline static void MUTEX_UNLOCK_SOFTAP_SET(dhd_pub_t * dhdp)
1627 {
1628 #if defined(OEM_ANDROID)
1629 	mutex_unlock(&dhdp->wl_softap_lock);
1630 #endif /* OEM_ANDROID */
1631 }
1632 
1633 #ifdef DHD_DEBUG_WAKE_LOCK
1634 #define DHD_OS_WAKE_LOCK(pub) \
1635 	do { \
1636 		printf("call wake_lock: %s %d\n", \
1637 			__FUNCTION__, __LINE__); \
1638 		dhd_os_wake_lock(pub); \
1639 	} while (0)
1640 #define DHD_OS_WAKE_UNLOCK(pub) \
1641 	do { \
1642 		printf("call wake_unlock: %s %d\n", \
1643 			__FUNCTION__, __LINE__); \
1644 		dhd_os_wake_unlock(pub); \
1645 	} while (0)
1646 #define DHD_EVENT_WAKE_LOCK(pub) \
1647 	do { \
1648 		printf("call event wake_lock: %s %d\n", \
1649 			__FUNCTION__, __LINE__); \
1650 		dhd_event_wake_lock(pub); \
1651 	} while (0)
1652 #define DHD_EVENT_WAKE_UNLOCK(pub) \
1653 	do { \
1654 		printf("call event wake_unlock: %s %d\n", \
1655 			__FUNCTION__, __LINE__); \
1656 		dhd_event_wake_unlock(pub); \
1657 	} while (0)
1658 #define DHD_PM_WAKE_LOCK_TIMEOUT(pub, val) \
1659 	do { \
1660 		printf("call pm_wake_timeout enable\n"); \
1661 	dhd_pm_wake_lock_timeout(pub, val); \
1662 	} while (0)
1663 #define DHD_PM_WAKE_UNLOCK(pub) \
1664 	do { \
1665 		printf("call pm_wake unlock\n"); \
1666 	dhd_pm_wake_unlock(pub); \
1667 	} while (0)
1668 #define DHD_TXFL_WAKE_LOCK_TIMEOUT(pub, val) \
1669 	do { \
1670 		printf("call pm_wake_timeout enable\n"); \
1671 		dhd_txfl_wake_lock_timeout(pub, val); \
1672 	} while (0)
1673 #define DHD_TXFL_WAKE_UNLOCK(pub) \
1674 	do { \
1675 		printf("call pm_wake unlock\n"); \
1676 		dhd_txfl_wake_unlock(pub); \
1677 	} while (0)
1678 #define DHD_OS_WAKE_LOCK_TIMEOUT(pub) \
1679 	do { \
1680 		printf("call wake_lock_timeout: %s %d\n", \
1681 			__FUNCTION__, __LINE__); \
1682 		dhd_os_wake_lock_timeout(pub); \
1683 	} while (0)
1684 #define DHD_OS_WAKE_LOCK_RX_TIMEOUT_ENABLE(pub, val) \
1685 	do { \
1686 		printf("call wake_lock_rx_timeout_enable[%d]: %s %d\n", \
1687 			val, __FUNCTION__, __LINE__); \
1688 		dhd_os_wake_lock_rx_timeout_enable(pub, val); \
1689 	} while (0)
1690 #define DHD_OS_WAKE_LOCK_CTRL_TIMEOUT_ENABLE(pub, val) \
1691 	do { \
1692 		printf("call wake_lock_ctrl_timeout_enable[%d]: %s %d\n", \
1693 			val, __FUNCTION__, __LINE__); \
1694 		dhd_os_wake_lock_ctrl_timeout_enable(pub, val); \
1695 	} while (0)
1696 #define DHD_OS_WAKE_LOCK_CTRL_TIMEOUT_CANCEL(pub) \
1697 	do { \
1698 		printf("call wake_lock_ctrl_timeout_cancel: %s %d\n", \
1699 			__FUNCTION__, __LINE__); \
1700 		dhd_os_wake_lock_ctrl_timeout_cancel(pub); \
1701 	} while (0)
1702 #define DHD_OS_WAKE_LOCK_WAIVE(pub) \
1703 	do { \
1704 		printf("call wake_lock_waive: %s %d\n", \
1705 			__FUNCTION__, __LINE__); \
1706 		dhd_os_wake_lock_waive(pub); \
1707 	} while (0)
1708 #define DHD_OS_WAKE_LOCK_RESTORE(pub) \
1709 	do { \
1710 		printf("call wake_lock_restore: %s %d\n", \
1711 			__FUNCTION__, __LINE__); \
1712 		dhd_os_wake_lock_restore(pub); \
1713 	} while (0)
1714 #define DHD_OS_WAKE_LOCK_INIT(dhd) \
1715 	do { \
1716 		printf("call wake_lock_init: %s %d\n", \
1717 			__FUNCTION__, __LINE__); \
1718 		dhd_os_wake_lock_init(dhd); \
1719 	} while (0)
1720 #define DHD_OS_WAKE_LOCK_DESTROY(dhd) \
1721 	do { \
1722 		printf("call wake_lock_destroy: %s %d\n", \
1723 			__FUNCTION__, __LINE__); \
1724 		dhd_os_wake_lock_destroy(dhd); \
1725 	} while (0)
1726 #else
1727 #define DHD_OS_WAKE_LOCK(pub)			dhd_os_wake_lock(pub)
1728 #define DHD_OS_WAKE_UNLOCK(pub)		dhd_os_wake_unlock(pub)
1729 #define DHD_EVENT_WAKE_LOCK(pub)			dhd_event_wake_lock(pub)
1730 #define DHD_EVENT_WAKE_UNLOCK(pub)		dhd_event_wake_unlock(pub)
1731 #define DHD_PM_WAKE_LOCK_TIMEOUT(pub, val)  dhd_pm_wake_lock_timeout(pub, val)
1732 #define DHD_PM_WAKE_UNLOCK(pub) 			dhd_pm_wake_unlock(pub)
1733 #define DHD_TXFL_WAKE_LOCK_TIMEOUT(pub, val)	dhd_txfl_wake_lock_timeout(pub, val)
1734 #define DHD_TXFL_WAKE_UNLOCK(pub) 			dhd_txfl_wake_unlock(pub)
1735 #define DHD_OS_WAKE_LOCK_TIMEOUT(pub)		dhd_os_wake_lock_timeout(pub)
1736 #define DHD_OS_WAKE_LOCK_RX_TIMEOUT_ENABLE(pub, val) \
1737 	dhd_os_wake_lock_rx_timeout_enable(pub, val)
1738 #define DHD_OS_WAKE_LOCK_CTRL_TIMEOUT_ENABLE(pub, val) \
1739 	dhd_os_wake_lock_ctrl_timeout_enable(pub, val)
1740 #define DHD_OS_WAKE_LOCK_CTRL_TIMEOUT_CANCEL(pub) \
1741 	dhd_os_wake_lock_ctrl_timeout_cancel(pub)
1742 #define DHD_OS_WAKE_LOCK_WAIVE(pub)			dhd_os_wake_lock_waive(pub)
1743 #define DHD_OS_WAKE_LOCK_RESTORE(pub)		dhd_os_wake_lock_restore(pub)
1744 #define DHD_OS_WAKE_LOCK_INIT(dhd)		dhd_os_wake_lock_init(dhd);
1745 #define DHD_OS_WAKE_LOCK_DESTROY(dhd)		dhd_os_wake_lock_destroy(dhd);
1746 #endif /* DHD_DEBUG_WAKE_LOCK */
1747 
1748 #define DHD_OS_WD_WAKE_LOCK(pub)		dhd_os_wd_wake_lock(pub)
1749 #define DHD_OS_WD_WAKE_UNLOCK(pub)		dhd_os_wd_wake_unlock(pub)
1750 
1751 #ifdef DHD_USE_SCAN_WAKELOCK
1752 #ifdef DHD_DEBUG_SCAN_WAKELOCK
1753 #define DHD_OS_SCAN_WAKE_LOCK_TIMEOUT(pub, val) \
1754 	do { \
1755 		printf("call wake_lock_scan: %s %d\n", \
1756 			__FUNCTION__, __LINE__); \
1757 		dhd_os_scan_wake_lock_timeout(pub, val); \
1758 	} while (0)
1759 #define DHD_OS_SCAN_WAKE_UNLOCK(pub) \
1760 	do { \
1761 		printf("call wake_unlock_scan: %s %d\n", \
1762 			__FUNCTION__, __LINE__); \
1763 		dhd_os_scan_wake_unlock(pub); \
1764 	} while (0)
1765 #else
1766 #define DHD_OS_SCAN_WAKE_LOCK_TIMEOUT(pub, val)		dhd_os_scan_wake_lock_timeout(pub, val)
1767 #define DHD_OS_SCAN_WAKE_UNLOCK(pub)			dhd_os_scan_wake_unlock(pub)
1768 #endif /* DHD_DEBUG_SCAN_WAKELOCK */
1769 #else
1770 #define DHD_OS_SCAN_WAKE_LOCK_TIMEOUT(pub, val)
1771 #define DHD_OS_SCAN_WAKE_UNLOCK(pub)
1772 #endif /* DHD_USE_SCAN_WAKELOCK */
1773 
1774 #else
1775 
1776 /* Wake lock are used in Android only (until the Linux community accepts it) */
1777 #define DHD_OS_WAKE_LOCK(pub)
1778 #define DHD_OS_WAKE_UNLOCK(pub)
1779 #define DHD_EVENT_WAKE_LOCK(pub)
1780 #define DHD_EVENT_WAKE_UNLOCK(pub)
1781 #define DHD_PM_WAKE_LOCK_TIMEOUT(pub, val)
1782 #define DHD_PM_WAKE_UNLOCK(pub)
1783 #define DHD_TXFL_WAKE_LOCK_TIMEOUT(pub, val)
1784 #define DHD_TXFL_WAKE_UNLOCK(pub)
1785 #define DHD_OS_WD_WAKE_LOCK(pub)
1786 #define DHD_OS_WD_WAKE_UNLOCK(pub)
1787 #define DHD_OS_WAKE_LOCK_TIMEOUT(pub)
1788 #define DHD_OS_WAKE_LOCK_RX_TIMEOUT_ENABLE(pub, val)	UNUSED_PARAMETER(val)
1789 #define DHD_OS_WAKE_LOCK_CTRL_TIMEOUT_ENABLE(pub, val)	UNUSED_PARAMETER(val)
1790 #define DHD_OS_WAKE_LOCK_CTRL_TIMEOUT_CANCEL(pub, val)
1791 #define DHD_OS_WAKE_LOCK_WAIVE(pub)
1792 #define DHD_OS_WAKE_LOCK_RESTORE(pub)
1793 #define DHD_OS_SCAN_WAKE_LOCK_TIMEOUT(pub, val)
1794 #define DHD_OS_SCAN_WAKE_UNLOCK(pub)
1795 #define DHD_OS_WAKE_LOCK_INIT(dhd)
1796 #define DHD_OS_WAKE_LOCK_DESTROY(dhd)
1797 
1798 #endif // endif
1799 
1800 #ifdef BCMPCIE_OOB_HOST_WAKE
1801 #define OOB_WAKE_LOCK_TIMEOUT 500
1802 extern void dhd_os_oob_irq_wake_lock_timeout(dhd_pub_t *pub, int val);
1803 extern void dhd_os_oob_irq_wake_unlock(dhd_pub_t *pub);
1804 
1805 #define DHD_OS_OOB_IRQ_WAKE_LOCK_TIMEOUT(pub, val)	dhd_os_oob_irq_wake_lock_timeout(pub, val)
1806 #define DHD_OS_OOB_IRQ_WAKE_UNLOCK(pub)			dhd_os_oob_irq_wake_unlock(pub)
1807 #endif /* BCMPCIE_OOB_HOST_WAKE */
1808 
1809 #define DHD_PACKET_TIMEOUT_MS	500
1810 #define DHD_EVENT_TIMEOUT_MS	1500
1811 #define SCAN_WAKE_LOCK_TIMEOUT	10000
1812 #define MAX_TX_TIMEOUT			500
1813 
1814 /* Enum for IOCTL recieved status */
1815 typedef enum dhd_ioctl_recieved_status
1816 {
1817 	IOCTL_WAIT = 0,
1818 	IOCTL_RETURN_ON_SUCCESS,
1819 	IOCTL_RETURN_ON_TRAP,
1820 	IOCTL_RETURN_ON_BUS_STOP,
1821 	IOCTL_RETURN_ON_ERROR
1822 } dhd_ioctl_recieved_status_t;
1823 
1824 /* interface operations (register, remove) should be atomic, use this lock to prevent race
1825  * condition among wifi on/off and interface operation functions
1826  */
1827 void dhd_net_if_lock(struct net_device *dev);
1828 void dhd_net_if_unlock(struct net_device *dev);
1829 
1830 #if defined(MULTIPLE_SUPPLICANT)
1831 #if defined(OEM_ANDROID) && defined(BCMSDIO)
1832 extern struct mutex _dhd_sdio_mutex_lock_;
1833 #endif // endif
1834 #endif /* MULTIPLE_SUPPLICANT */
1835 
1836 typedef enum dhd_attach_states
1837 {
1838 	DHD_ATTACH_STATE_INIT = 0x0,
1839 	DHD_ATTACH_STATE_NET_ALLOC = 0x1,
1840 	DHD_ATTACH_STATE_DHD_ALLOC = 0x2,
1841 	DHD_ATTACH_STATE_ADD_IF = 0x4,
1842 	DHD_ATTACH_STATE_PROT_ATTACH = 0x8,
1843 	DHD_ATTACH_STATE_WL_ATTACH = 0x10,
1844 	DHD_ATTACH_STATE_THREADS_CREATED = 0x20,
1845 	DHD_ATTACH_STATE_WAKELOCKS_INIT = 0x40,
1846 	DHD_ATTACH_STATE_CFG80211 = 0x80,
1847 	DHD_ATTACH_STATE_EARLYSUSPEND_DONE = 0x100,
1848 	DHD_ATTACH_TIMESYNC_ATTACH_DONE = 0x200,
1849 	DHD_ATTACH_LOGTRACE_INIT = 0x400,
1850 	DHD_ATTACH_STATE_LB_ATTACH_DONE = 0x800,
1851 	DHD_ATTACH_STATE_DONE = 0x1000
1852 } dhd_attach_states_t;
1853 
1854 /* Value -1 means we are unsuccessful in creating the kthread. */
1855 #define DHD_PID_KT_INVALID 	-1
1856 /* Value -2 means we are unsuccessful in both creating the kthread and tasklet */
1857 #define DHD_PID_KT_TL_INVALID	-2
1858 
1859 /* default reporting period */
1860 #define ECOUNTERS_DEFAULT_PERIOD	0
1861 
1862 /* default number of reports. '0' indicates forever */
1863 #define ECOUNTERS_NUM_REPORTS		0
1864 
1865 typedef struct ecounters_cfg {
1866 	uint16 type;
1867 	uint16 if_slice_idx;
1868 	uint16 stats_rep;
1869 } ecounters_cfg_t;
1870 
1871 typedef struct event_ecounters_cfg {
1872 	uint16 event_id;
1873 	uint16 type;
1874 	uint16 if_slice_idx;
1875 	uint16 stats_rep;
1876 } event_ecounters_cfg_t;
1877 
1878 typedef struct ecountersv2_xtlv_list_elt {
1879 	/* Not quite the exact bcm_xtlv_t type as data could be pointing to other pieces in
1880 	 * memory at the time of parsing arguments.
1881 	 */
1882 	uint16 id;
1883 	uint16 len;
1884 	uint8 *data;
1885 	struct ecountersv2_xtlv_list_elt *next;
1886 } ecountersv2_xtlv_list_elt_t;
1887 
1888 typedef struct ecountersv2_processed_xtlv_list_elt {
1889 	uint8 *data;
1890 	struct ecountersv2_processed_xtlv_list_elt *next;
1891 } ecountersv2_processed_xtlv_list_elt;
1892 
1893 /*
1894  * Exported from dhd OS modules (dhd_linux/dhd_ndis)
1895  */
1896 
1897 /* Indication from bus module regarding presence/insertion of dongle.
1898  * Return dhd_pub_t pointer, used as handle to OS module in later calls.
1899  * Returned structure should have bus and prot pointers filled in.
1900  * bus_hdrlen specifies required headroom for bus module header.
1901  */
1902 extern dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen);
1903 extern int dhd_attach_net(dhd_pub_t *dhdp, bool need_rtnl_lock);
1904 #if defined(WLP2P) && defined(WL_CFG80211)
1905 /* To allow attach/detach calls corresponding to p2p0 interface  */
1906 extern int dhd_attach_p2p(dhd_pub_t *);
1907 extern int dhd_detach_p2p(dhd_pub_t *);
1908 #endif /* WLP2P && WL_CFG80211 */
1909 extern int dhd_register_if(dhd_pub_t *dhdp, int idx, bool need_rtnl_lock);
1910 #ifdef WL_VIF_SUPPORT
1911 extern int dhd_register_vif(dhd_pub_t *dhdp);
1912 #endif /* WL_VIF_SUPPORT */
1913 
1914 /* Indication from bus module regarding removal/absence of dongle */
1915 extern void dhd_detach(dhd_pub_t *dhdp);
1916 extern void dhd_free(dhd_pub_t *dhdp);
1917 extern void dhd_clear(dhd_pub_t *dhdp);
1918 
1919 /* Indication from bus module to change flow-control state */
1920 extern void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool on);
1921 
1922 /* Store the status of a connection attempt for later retrieval by an iovar */
1923 extern void dhd_store_conn_status(uint32 event, uint32 status, uint32 reason);
1924 
1925 extern bool dhd_prec_enq(dhd_pub_t *dhdp, struct pktq *q, void *pkt, int prec);
1926 
1927 extern void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *rxp, int numpkt, uint8 chan);
1928 
1929 /* Return pointer to interface name */
1930 extern char *dhd_ifname(dhd_pub_t *dhdp, int idx);
1931 
1932 #ifdef DHD_UCODE_DOWNLOAD
1933 /* Returns the ucode path */
1934 extern char *dhd_get_ucode_path(dhd_pub_t *dhdp);
1935 #endif /* DHD_UCODE_DOWNLOAD */
1936 
1937 /* Request scheduling of the bus dpc */
1938 extern void dhd_sched_dpc(dhd_pub_t *dhdp);
1939 
1940 /* Notify tx completion */
1941 extern void dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success);
1942 #ifdef DHD_4WAYM4_FAIL_DISCONNECT
1943 extern void dhd_eap_txcomplete(dhd_pub_t *dhdp, void *txp, bool success, int ifidx);
1944 extern void dhd_cleanup_m4_state_work(dhd_pub_t *dhdp, int ifidx);
1945 #endif /* DHD_4WAYM4_FAIL_DISCONNECT */
1946 
1947 #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
1948 extern void dhd_bus_wakeup_work(dhd_pub_t *dhdp);
1949 #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
1950 
1951 #define WIFI_FEATURE_INFRA              0x0001      /* Basic infrastructure mode        */
1952 #define WIFI_FEATURE_INFRA_5G           0x0002      /* Support for 5 GHz Band           */
1953 #define WIFI_FEATURE_HOTSPOT            0x0004      /* Support for GAS/ANQP             */
1954 #define WIFI_FEATURE_P2P                0x0008      /* Wifi-Direct                      */
1955 #define WIFI_FEATURE_SOFT_AP            0x0010      /* Soft AP                          */
1956 #define WIFI_FEATURE_GSCAN              0x0020      /* Google-Scan APIs                 */
1957 #define WIFI_FEATURE_NAN                0x0040      /* Neighbor Awareness Networking    */
1958 #define WIFI_FEATURE_D2D_RTT            0x0080      /* Device-to-device RTT             */
1959 #define WIFI_FEATURE_D2AP_RTT           0x0100      /* Device-to-AP RTT                 */
1960 #define WIFI_FEATURE_BATCH_SCAN         0x0200      /* Batched Scan (legacy)            */
1961 #define WIFI_FEATURE_PNO                0x0400      /* Preferred network offload        */
1962 #define WIFI_FEATURE_ADDITIONAL_STA     0x0800      /* Support for two STAs             */
1963 #define WIFI_FEATURE_TDLS               0x1000      /* Tunnel directed link setup       */
1964 #define WIFI_FEATURE_TDLS_OFFCHANNEL    0x2000      /* Support for TDLS off channel     */
1965 #define WIFI_FEATURE_EPR                0x4000      /* Enhanced power reporting         */
1966 #define WIFI_FEATURE_AP_STA             0x8000      /* Support for AP STA Concurrency   */
1967 #define WIFI_FEATURE_LINKSTAT           0x10000     /* Support for Linkstats            */
1968 #define WIFI_FEATURE_LOGGER             0x20000     /* WiFi Logger			*/
1969 #define WIFI_FEATURE_HAL_EPNO		0x40000	    /* WiFi PNO enhanced		*/
1970 #define WIFI_FEATURE_RSSI_MONITOR	0x80000     /* RSSI Monitor			*/
1971 #define WIFI_FEATURE_MKEEP_ALIVE        0x100000    /* WiFi mkeep_alive			*/
1972 #define WIFI_FEATURE_CONFIG_NDO         0x200000	/* ND offload configure             */
1973 #define WIFI_FEATURE_TX_TRANSMIT_POWER  0x400000	/* Capture Tx transmit power levels */
1974 #define WIFI_FEATURE_CONTROL_ROAMING    0x800000	/* Enable/Disable firmware roaming */
1975 #define WIFI_FEATURE_FILTER_IE          0x1000000	/* Probe req ie filter              */
1976 #define WIFI_FEATURE_SCAN_RAND          0x2000000	/* Support MAC & Prb SN randomization */
1977 #define WIFI_FEATURE_SET_TX_POWER_LIMIT 0x4000000      /* Support Tx Power Limit setting */
1978 #define WIFI_FEATURE_USE_BODY_HEAD_SAR  0x8000000      /* Body/Head Proximity for SAR */
1979 #define WIFI_FEATURE_SET_LATENCY_MODE   0x40000000     /* Support Latency mode setting */
1980 #define WIFI_FEATURE_P2P_RAND_MAC       0x80000000     /* Support P2P MAC randomization */
1981 #define WIFI_FEATURE_INVALID            0xFFFFFFFF	/* Invalid Feature                  */
1982 
1983 #define MAX_FEATURE_SET_CONCURRRENT_GROUPS  3
1984 
1985 extern int dhd_dev_get_feature_set(struct net_device *dev);
1986 extern int dhd_dev_get_feature_set_matrix(struct net_device *dev, int num);
1987 extern int dhd_dev_cfg_rand_mac_oui(struct net_device *dev, uint8 *oui);
1988 #ifdef CUSTOM_FORCE_NODFS_FLAG
1989 extern int dhd_dev_set_nodfs(struct net_device *dev, uint nodfs);
1990 #endif /* CUSTOM_FORCE_NODFS_FLAG */
1991 #ifdef NDO_CONFIG_SUPPORT
1992 #ifndef NDO_MAX_HOST_IP_ENTRIES
1993 #define NDO_MAX_HOST_IP_ENTRIES	10
1994 #endif /* NDO_MAX_HOST_IP_ENTRIES */
1995 
1996 extern int dhd_dev_ndo_cfg(struct net_device *dev, u8 enable);
1997 extern int dhd_dev_ndo_update_inet6addr(struct net_device * dev);
1998 #endif /* NDO_CONFIG_SUPPORT */
1999 extern int dhd_set_rand_mac_oui(dhd_pub_t *dhd);
2000 #ifdef GSCAN_SUPPORT
2001 extern int dhd_dev_set_lazy_roam_cfg(struct net_device *dev,
2002              wlc_roam_exp_params_t *roam_param);
2003 extern int dhd_dev_lazy_roam_enable(struct net_device *dev, uint32 enable);
2004 extern int dhd_dev_set_lazy_roam_bssid_pref(struct net_device *dev,
2005        wl_bssid_pref_cfg_t *bssid_pref, uint32 flush);
2006 #endif /* GSCAN_SUPPORT */
2007 #if defined(GSCAN_SUPPORT) || defined(ROAMEXP_SUPPORT)
2008 extern int dhd_dev_set_blacklist_bssid(struct net_device *dev, maclist_t *blacklist,
2009     uint32 len, uint32 flush);
2010 extern int dhd_dev_set_whitelist_ssid(struct net_device *dev, wl_ssid_whitelist_t *whitelist,
2011     uint32 len, uint32 flush);
2012 #endif /* GSCAN_SUPPORT || ROAMEXP_SUPPORT */
2013 
2014 /* OS independent layer functions */
2015 extern void dhd_os_dhdiovar_lock(dhd_pub_t *pub);
2016 extern void dhd_os_dhdiovar_unlock(dhd_pub_t *pub);
2017 void dhd_os_logdump_lock(dhd_pub_t *pub);
2018 void dhd_os_logdump_unlock(dhd_pub_t *pub);
2019 extern int dhd_os_proto_block(dhd_pub_t * pub);
2020 extern int dhd_os_proto_unblock(dhd_pub_t * pub);
2021 extern int dhd_os_ioctl_resp_wait(dhd_pub_t * pub, uint * condition);
2022 extern int dhd_os_ioctl_resp_wake(dhd_pub_t * pub);
2023 extern unsigned int dhd_os_get_ioctl_resp_timeout(void);
2024 extern void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec);
2025 extern void dhd_os_ioctl_resp_lock(dhd_pub_t * pub);
2026 extern void dhd_os_ioctl_resp_unlock(dhd_pub_t * pub);
2027 #ifdef PCIE_FULL_DONGLE
2028 extern void dhd_wakeup_ioctl_event(dhd_pub_t *pub, dhd_ioctl_recieved_status_t reason);
2029 #else
dhd_wakeup_ioctl_event(dhd_pub_t * pub,dhd_ioctl_recieved_status_t reason)2030 static INLINE void dhd_wakeup_ioctl_event(dhd_pub_t *pub, dhd_ioctl_recieved_status_t reason)
2031 { printf("%s is NOT implemented for SDIO", __FUNCTION__); return; }
2032 #endif // endif
2033 #ifdef SHOW_LOGTRACE
2034 /* Bound and delay are fine tuned after several experiments and these
2035  * are the best case values to handle bombarding of console logs.
2036  */
2037 #define DHD_EVENT_LOGTRACE_BOUND 10
2038 /* since FW has event log rate health check (EVENT_LOG_RATE_HC) we can reduce
2039  * the reschedule delay to 10ms
2040 */
2041 #define DHD_EVENT_LOGTRACE_RESCHEDULE_DELAY_MS 10u
2042 extern int dhd_os_read_file(void *file, char *buf, uint32 size);
2043 extern int dhd_os_seek_file(void *file, int64 offset);
2044 void dhd_sendup_info_buf(dhd_pub_t *dhdp, uint8 *msg);
2045 #endif /* SHOW_LOGTRACE */
2046 int dhd_os_write_file_posn(void *fp, unsigned long *posn,
2047 		void *buf, unsigned long buflen);
2048 int dhd_msix_message_set(dhd_pub_t *dhdp, uint table_entry,
2049     uint message_number, bool unmask);
2050 
2051 extern void
2052 dhd_pcie_dump_core_regs(dhd_pub_t * pub, uint32 index, uint32 first_addr, uint32 last_addr);
2053 extern void wl_dhdpcie_dump_regs(void * context);
2054 
2055 extern int dhd_os_get_image_block(char * buf, int len, void * image);
2056 extern int dhd_os_get_image_size(void * image);
2057 #if defined(BT_OVER_SDIO)
2058 extern int dhd_os_gets_image(dhd_pub_t *pub, char *str, int len, void *image);
2059 extern void dhdsdio_bus_usr_cnt_inc(dhd_pub_t *pub);
2060 extern void dhdsdio_bus_usr_cnt_dec(dhd_pub_t *pub);
2061 #endif /* (BT_OVER_SDIO) */
2062 extern void *dhd_os_open_image1(dhd_pub_t *pub, char *filename); /* rev1 function signature */
2063 extern void dhd_os_close_image1(dhd_pub_t *pub, void *image);
2064 extern void dhd_os_wd_timer(void *bus, uint wdtick);
2065 #ifdef DHD_PCIE_RUNTIMEPM
2066 extern void dhd_os_runtimepm_timer(void *bus, uint tick);
2067 #endif /* DHD_PCIE_RUNTIMEPM */
2068 extern void dhd_os_sdlock(dhd_pub_t * pub);
2069 extern void dhd_os_sdunlock(dhd_pub_t * pub);
2070 extern void dhd_os_sdlock_txq(dhd_pub_t * pub);
2071 extern void dhd_os_sdunlock_txq(dhd_pub_t * pub);
2072 extern void dhd_os_sdlock_rxq(dhd_pub_t * pub);
2073 extern void dhd_os_sdunlock_rxq(dhd_pub_t * pub);
2074 extern void dhd_os_sdlock_sndup_rxq(dhd_pub_t * pub);
2075 extern void dhd_os_tracelog(const char *format, ...);
2076 #ifdef DHDTCPACK_SUPPRESS
2077 extern unsigned long dhd_os_tcpacklock(dhd_pub_t *pub);
2078 extern void dhd_os_tcpackunlock(dhd_pub_t *pub, unsigned long flags);
2079 #endif /* DHDTCPACK_SUPPRESS */
2080 
2081 extern int dhd_customer_oob_irq_map(void *adapter, unsigned long *irq_flags_ptr);
2082 extern int dhd_customer_gpio_wlan_ctrl(void *adapter, int onoff);
2083 extern int dhd_custom_get_mac_address(void *adapter, unsigned char *buf);
2084 #if defined(CUSTOM_COUNTRY_CODE)
2085 extern void get_customized_country_code(void *adapter, char *country_iso_code,
2086 	wl_country_t *cspec, u32 flags);
2087 #else
2088 extern void get_customized_country_code(void *adapter, char *country_iso_code, wl_country_t *cspec);
2089 #endif /* CUSTOM_COUNTRY_CODE */
2090 extern void dhd_os_sdunlock_sndup_rxq(dhd_pub_t * pub);
2091 extern void dhd_os_sdlock_eventq(dhd_pub_t * pub);
2092 extern void dhd_os_sdunlock_eventq(dhd_pub_t * pub);
2093 extern bool dhd_os_check_hang(dhd_pub_t *dhdp, int ifidx, int ret);
2094 extern int dhd_os_send_hang_message(dhd_pub_t *dhdp);
2095 extern void dhd_set_version_info(dhd_pub_t *pub, char *fw);
2096 extern bool dhd_os_check_if_up(dhd_pub_t *pub);
2097 extern int dhd_os_check_wakelock(dhd_pub_t *pub);
2098 extern int dhd_os_check_wakelock_all(dhd_pub_t *pub);
2099 extern int dhd_get_instance(dhd_pub_t *pub);
2100 #ifdef CUSTOM_SET_CPUCORE
2101 extern void dhd_set_cpucore(dhd_pub_t *dhd, int set);
2102 #endif /* CUSTOM_SET_CPUCORE */
2103 
2104 #if defined(KEEP_ALIVE)
2105 extern int dhd_keep_alive_onoff(dhd_pub_t *dhd);
2106 #endif /* KEEP_ALIVE */
2107 
2108 #if defined(DHD_FW_COREDUMP)
2109 void dhd_schedule_memdump(dhd_pub_t *dhdp, uint8 *buf, uint32 size);
2110 #endif /* DHD_FW_COREDUMP */
2111 
2112 void dhd_write_sssr_dump(dhd_pub_t *dhdp, uint32 dump_mode);
2113 #ifdef DNGL_AXI_ERROR_LOGGING
2114 void dhd_schedule_axi_error_dump(dhd_pub_t *dhdp, void *type);
2115 #endif /* DNGL_AXI_ERROR_LOGGING */
2116 #ifdef BCMPCIE
2117 void dhd_schedule_cto_recovery(dhd_pub_t *dhdp);
2118 #endif /* BCMPCIE */
2119 
2120 #ifdef PKT_FILTER_SUPPORT
2121 #define DHD_UNICAST_FILTER_NUM		0
2122 #define DHD_BROADCAST_FILTER_NUM	1
2123 #define DHD_MULTICAST4_FILTER_NUM	2
2124 #define DHD_MULTICAST6_FILTER_NUM	3
2125 #define DHD_MDNS_FILTER_NUM		4
2126 #define DHD_ARP_FILTER_NUM		5
2127 #define DHD_BROADCAST_ARP_FILTER_NUM	6
2128 #define DHD_IP4BCAST_DROP_FILTER_NUM	7
2129 #define DHD_LLC_STP_DROP_FILTER_NUM	8
2130 #define DHD_LLC_XID_DROP_FILTER_NUM	9
2131 #define DISCARD_IPV4_MCAST	"102 1 6 IP4_H:16 0xf0 0xe0"
2132 #define DISCARD_IPV6_MCAST	"103 1 6 IP6_H:24 0xff 0xff"
2133 #define DISCARD_IPV4_BCAST	"107 1 6 IP4_H:16 0xffffffff 0xffffffff"
2134 #define DISCARD_LLC_STP		"108 1 6 ETH_H:14 0xFFFFFFFFFFFF 0xAAAA0300000C"
2135 #define DISCARD_LLC_XID		"109 1 6 ETH_H:14 0xFFFFFF 0x0001AF"
2136 extern int dhd_os_enable_packet_filter(dhd_pub_t *dhdp, int val);
2137 extern void dhd_enable_packet_filter(int value, dhd_pub_t *dhd);
2138 extern int dhd_packet_filter_add_remove(dhd_pub_t *dhdp, int add_remove, int num);
2139 extern int net_os_enable_packet_filter(struct net_device *dev, int val);
2140 extern int net_os_rxfilter_add_remove(struct net_device *dev, int val, int num);
2141 
2142 #define MAX_PKTFLT_BUF_SIZE		2048
2143 #define MAX_PKTFLT_FIXED_PATTERN_SIZE	32
2144 #define MAX_PKTFLT_FIXED_BUF_SIZE	\
2145 	(WL_PKT_FILTER_FIXED_LEN + MAX_PKTFLT_FIXED_PATTERN_SIZE * 2)
2146 #define MAXPKT_ARG	16
2147 #endif /* PKT_FILTER_SUPPORT */
2148 
2149 #if defined(OEM_ANDROID) && defined(BCMPCIE)
2150 extern int dhd_get_suspend_bcn_li_dtim(dhd_pub_t *dhd, int *dtim_period, int *bcn_interval);
2151 #else
2152 extern int dhd_get_suspend_bcn_li_dtim(dhd_pub_t *dhd);
2153 #endif /* OEM_ANDROID && BCMPCIE */
2154 
2155 extern bool dhd_support_sta_mode(dhd_pub_t *dhd);
2156 extern int write_to_file(dhd_pub_t *dhd, uint8 *buf, int size);
2157 
2158 #ifdef RSSI_MONITOR_SUPPORT
2159 extern int dhd_dev_set_rssi_monitor_cfg(struct net_device *dev, int start,
2160              int8 max_rssi, int8 min_rssi);
2161 #endif /* RSSI_MONITOR_SUPPORT */
2162 
2163 #ifdef DHDTCPACK_SUPPRESS
2164 int dhd_dev_set_tcpack_sup_mode_cfg(struct net_device *dev, uint8 enable);
2165 #endif /* DHDTCPACK_SUPPRESS */
2166 
2167 #define DHD_RSSI_MONITOR_EVT_VERSION   1
2168 typedef struct {
2169 	uint8 version;
2170 	int8 cur_rssi;
2171 	struct ether_addr BSSID;
2172 } dhd_rssi_monitor_evt_t;
2173 
2174 typedef struct {
2175 	uint32 limit;		/* Expiration time (usec) */
2176 	uint32 increment;	/* Current expiration increment (usec) */
2177 	uint32 elapsed;		/* Current elapsed time (usec) */
2178 	uint32 tick;		/* O/S tick time (usec) */
2179 } dhd_timeout_t;
2180 
2181 #ifdef SHOW_LOGTRACE
2182 typedef struct {
2183 	uint  num_fmts;
2184 	char **fmts;
2185 	char *raw_fmts;
2186 	char *raw_sstr;
2187 	uint32 fmts_size;
2188 	uint32 raw_fmts_size;
2189 	uint32 raw_sstr_size;
2190 	uint32 ramstart;
2191 	uint32 rodata_start;
2192 	uint32 rodata_end;
2193 	char *rom_raw_sstr;
2194 	uint32 rom_raw_sstr_size;
2195 	uint32 rom_ramstart;
2196 	uint32 rom_rodata_start;
2197 	uint32 rom_rodata_end;
2198 } dhd_event_log_t;
2199 #endif /* SHOW_LOGTRACE */
2200 
2201 #ifdef KEEP_ALIVE
2202 extern int dhd_dev_start_mkeep_alive(dhd_pub_t *dhd_pub, uint8 mkeep_alive_id, uint8 *ip_pkt,
2203 	uint16 ip_pkt_len, uint8* src_mac_addr, uint8* dst_mac_addr, uint32 period_msec);
2204 extern int dhd_dev_stop_mkeep_alive(dhd_pub_t *dhd_pub, uint8 mkeep_alive_id);
2205 #endif /* KEEP_ALIVE */
2206 
2207 #if defined(PKT_FILTER_SUPPORT) && defined(APF)
2208 /*
2209  * As per Google's current implementation, there will be only one APF filter.
2210  * Therefore, userspace doesn't bother about filter id and because of that
2211  * DHD has to manage the filter id.
2212  */
2213 #define PKT_FILTER_APF_ID		200
2214 #define DHD_APF_LOCK(ndev)		dhd_apf_lock(ndev)
2215 #define DHD_APF_UNLOCK(ndev)		dhd_apf_unlock(ndev)
2216 
2217 extern void dhd_apf_lock(struct net_device *dev);
2218 extern void dhd_apf_unlock(struct net_device *dev);
2219 extern int dhd_dev_apf_get_version(struct net_device *ndev, uint32 *version);
2220 extern int dhd_dev_apf_get_max_len(struct net_device *ndev, uint32 *max_len);
2221 extern int dhd_dev_apf_add_filter(struct net_device *ndev, u8* program,
2222 	uint32 program_len);
2223 extern int dhd_dev_apf_enable_filter(struct net_device *ndev);
2224 extern int dhd_dev_apf_disable_filter(struct net_device *ndev);
2225 extern int dhd_dev_apf_delete_filter(struct net_device *ndev);
2226 #endif /* PKT_FILTER_SUPPORT && APF */
2227 
2228 extern void dhd_timeout_start(dhd_timeout_t *tmo, uint usec);
2229 extern int dhd_timeout_expired(dhd_timeout_t *tmo);
2230 
2231 extern int dhd_ifname2idx(struct dhd_info *dhd, char *name);
2232 extern int dhd_net2idx(struct dhd_info *dhd, struct net_device *net);
2233 extern struct net_device * dhd_idx2net(void *pub, int ifidx);
2234 extern int net_os_send_hang_message(struct net_device *dev);
2235 extern int net_os_send_hang_message_reason(struct net_device *dev, const char *string_num);
2236 extern bool dhd_wowl_cap(void *bus);
2237 extern int wl_host_event(dhd_pub_t *dhd_pub, int *idx, void *pktdata, uint pktlen,
2238 	wl_event_msg_t *, void **data_ptr,  void *);
2239 extern int wl_process_host_event(dhd_pub_t *dhd_pub, int *idx, void *pktdata, uint pktlen,
2240 	wl_event_msg_t *, void **data_ptr,  void *);
2241 extern void wl_event_to_host_order(wl_event_msg_t * evt);
2242 extern int wl_host_event_get_data(void *pktdata, uint pktlen, bcm_event_msg_u_t *evu);
2243 extern int dhd_wl_ioctl(dhd_pub_t *dhd_pub, int ifindex, wl_ioctl_t *ioc, void *buf, int len);
2244 extern int dhd_wl_ioctl_cmd(dhd_pub_t *dhd_pub, int cmd, void *arg, int len, uint8 set,
2245                             int ifindex);
2246 extern int dhd_wl_ioctl_get_intiovar(dhd_pub_t *dhd_pub, char *name, uint *pval,
2247 	int cmd, uint8 set, int ifidx);
2248 extern int dhd_wl_ioctl_set_intiovar(dhd_pub_t *dhd_pub, char *name, uint val,
2249 	int cmd, uint8 set, int ifidx);
2250 extern void dhd_common_init(osl_t *osh);
2251 
2252 extern int dhd_do_driver_init(struct net_device *net);
2253 extern int dhd_event_ifadd(struct dhd_info *dhd, struct wl_event_data_if *ifevent,
2254 	char *name, uint8 *mac);
2255 extern int dhd_event_ifdel(struct dhd_info *dhd, struct wl_event_data_if *ifevent,
2256 	char *name, uint8 *mac);
2257 extern int dhd_event_ifchange(struct dhd_info *dhd, struct wl_event_data_if *ifevent,
2258        char *name, uint8 *mac);
2259 extern struct net_device* dhd_allocate_if(dhd_pub_t *dhdpub, int ifidx, const char *name,
2260 	uint8 *mac, uint8 bssidx, bool need_rtnl_lock, const char *dngl_name);
2261 extern int dhd_remove_if(dhd_pub_t *dhdpub, int ifidx, bool need_rtnl_lock);
2262 #ifdef WL_STATIC_IF
2263 extern s32 dhd_update_iflist_info(dhd_pub_t *dhdp, struct net_device *ndev, int ifidx,
2264 	uint8 *mac, uint8 bssidx, const char *dngl_name, int if_state);
2265 #endif /* WL_STATIC_IF */
2266 extern void dhd_vif_add(struct dhd_info *dhd, int ifidx, char * name);
2267 extern void dhd_vif_del(struct dhd_info *dhd, int ifidx);
2268 extern void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx);
2269 extern void dhd_vif_sendup(struct dhd_info *dhd, int ifidx, uchar *cp, int len);
2270 
2271 #ifdef WL_NATOE
2272 extern int dhd_natoe_ct_event(dhd_pub_t *dhd, char *data);
2273 #endif /* WL_NATOE */
2274 
2275 /* Send packet to dongle via data channel */
2276 extern int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pkt);
2277 
2278 /* send up locally generated event */
2279 extern void dhd_sendup_event_common(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data);
2280 /* Send event to host */
2281 extern void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data);
2282 #ifdef LOG_INTO_TCPDUMP
2283 extern void dhd_sendup_log(dhd_pub_t *dhdp, void *data, int len);
2284 #endif /* LOG_INTO_TCPDUMP */
2285 #ifdef SHOW_LOGTRACE
2286 void dhd_sendup_info_buf(dhd_pub_t *dhdp, uint8 *msg);
2287 #endif // endif
2288 extern int dhd_bus_devreset(dhd_pub_t *dhdp, uint8 flag);
2289 extern uint dhd_bus_status(dhd_pub_t *dhdp);
2290 extern int  dhd_bus_start(dhd_pub_t *dhdp);
2291 extern int dhd_bus_suspend(dhd_pub_t *dhdpub);
2292 extern int dhd_bus_resume(dhd_pub_t *dhdpub, int stage);
2293 extern int dhd_bus_membytes(dhd_pub_t *dhdp, bool set, uint32 address, uint8 *data, uint size);
2294 extern void dhd_print_buf(void *pbuf, int len, int bytes_per_line);
2295 extern bool dhd_is_associated(dhd_pub_t *dhd, uint8 ifidx, int *retval);
2296 #if defined(BCMSDIO) || defined(BCMPCIE)
2297 extern uint dhd_bus_chip_id(dhd_pub_t *dhdp);
2298 extern uint dhd_bus_chiprev_id(dhd_pub_t *dhdp);
2299 extern uint dhd_bus_chippkg_id(dhd_pub_t *dhdp);
2300 #endif /* defined(BCMSDIO) || defined(BCMPCIE) */
2301 int dhd_bus_get_fw_mode(dhd_pub_t *dhdp);
2302 
2303 #if defined(KEEP_ALIVE)
2304 extern int dhd_keep_alive_onoff(dhd_pub_t *dhd);
2305 #endif /* KEEP_ALIVE */
2306 
2307 /* OS spin lock API */
2308 extern void *dhd_os_spin_lock_init(osl_t *osh);
2309 extern void dhd_os_spin_lock_deinit(osl_t *osh, void *lock);
2310 extern unsigned long dhd_os_spin_lock(void *lock);
2311 void dhd_os_spin_unlock(void *lock, unsigned long flags);
2312 
2313 /* linux is defined for DHD EFI builds also,
2314 * since its cross-compiled for EFI from linux.
2315 * dbgring_lock apis are meant only for linux
2316 * to use mutexes, other OSes will continue to
2317 * use dhd_os_spin_lock
2318 */
2319 void *dhd_os_dbgring_lock_init(osl_t *osh);
2320 void dhd_os_dbgring_lock_deinit(osl_t *osh, void *mtx);
2321 unsigned long dhd_os_dbgring_lock(void *lock);
2322 void dhd_os_dbgring_unlock(void *lock, unsigned long flags);
2323 
dhd_os_tput_test_wait(dhd_pub_t * pub,uint * condition,uint timeout_ms)2324 static INLINE int dhd_os_tput_test_wait(dhd_pub_t *pub, uint *condition,
2325 		uint timeout_ms)
2326 { return 0; }
dhd_os_tput_test_wake(dhd_pub_t * pub)2327 static INLINE int dhd_os_tput_test_wake(dhd_pub_t * pub)
2328 { return 0; }
2329 
2330 extern int dhd_os_busbusy_wait_negation(dhd_pub_t * pub, uint * condition);
2331 extern int dhd_os_busbusy_wake(dhd_pub_t * pub);
2332 extern void dhd_os_tx_completion_wake(dhd_pub_t *dhd);
2333 extern int dhd_os_busbusy_wait_condition(dhd_pub_t *pub, uint *var, uint condition);
2334 int dhd_os_busbusy_wait_bitmask(dhd_pub_t *pub, uint *var,
2335 		uint bitmask, uint condition);
2336 extern int dhd_os_d3ack_wait(dhd_pub_t * pub, uint * condition);
2337 extern int dhd_os_d3ack_wake(dhd_pub_t * pub);
2338 extern int dhd_os_dmaxfer_wait(dhd_pub_t *pub, uint *condition);
2339 extern int dhd_os_dmaxfer_wake(dhd_pub_t *pub);
2340 
2341 /*
2342  * Manage sta objects in an interface. Interface is identified by an ifindex and
2343  * sta(s) within an interfaces are managed using a MacAddress of the sta.
2344  */
2345 struct dhd_sta;
2346 extern bool dhd_sta_associated(dhd_pub_t *dhdp, uint32 bssidx, uint8 *mac);
2347 extern struct dhd_sta *dhd_find_sta(void *pub, int ifidx, void *ea);
2348 extern struct dhd_sta *dhd_findadd_sta(void *pub, int ifidx, void *ea);
2349 extern void dhd_del_all_sta(void *pub, int ifidx);
2350 extern void dhd_del_sta(void *pub, int ifidx, void *ea);
2351 extern int dhd_get_ap_isolate(dhd_pub_t *dhdp, uint32 idx);
2352 extern int dhd_set_ap_isolate(dhd_pub_t *dhdp, uint32 idx, int val);
2353 extern int dhd_bssidx2idx(dhd_pub_t *dhdp, uint32 bssidx);
2354 extern struct net_device *dhd_linux_get_primary_netdev(dhd_pub_t *dhdp);
2355 
2356 extern bool dhd_is_concurrent_mode(dhd_pub_t *dhd);
2357 int dhd_iovar(dhd_pub_t *pub, int ifidx, char *name, char *param_buf, uint param_len,
2358 		char *res_buf, uint res_len, int set);
2359 extern int dhd_getiovar(dhd_pub_t *pub, int ifidx, char *name, char *cmd_buf,
2360 		uint cmd_len, char **resptr, uint resp_len);
2361 
2362 #ifdef DHD_MCAST_REGEN
2363 extern int dhd_get_mcast_regen_bss_enable(dhd_pub_t *dhdp, uint32 idx);
2364 extern int dhd_set_mcast_regen_bss_enable(dhd_pub_t *dhdp, uint32 idx, int val);
2365 #endif // endif
2366 typedef enum cust_gpio_modes {
2367 	WLAN_RESET_ON,
2368 	WLAN_RESET_OFF,
2369 	WLAN_POWER_ON,
2370 	WLAN_POWER_OFF
2371 } cust_gpio_modes_t;
2372 
2373 typedef struct dmaxref_mem_map {
2374 	dhd_dma_buf_t *srcmem;
2375 	dhd_dma_buf_t *dstmem;
2376 } dmaxref_mem_map_t;
2377 
2378 #if defined(OEM_ANDROID)
2379 extern int wl_iw_iscan_set_scan_broadcast_prep(struct net_device *dev, uint flag);
2380 extern int wl_iw_send_priv_event(struct net_device *dev, char *flag);
2381 #endif /* defined(OEM_ANDROID) */
2382 
2383 #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
2384 extern void dhd_flush_rx_tx_wq(dhd_pub_t *dhdp);
2385 #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
2386 
2387 /*
2388  * Insmod parameters for debug/test
2389  */
2390 
2391 /* Watchdog timer interval */
2392 extern uint dhd_watchdog_ms;
2393 #ifdef DHD_PCIE_RUNTIMEPM
2394 extern uint dhd_runtimepm_ms;
2395 #endif /* DHD_PCIE_RUNTIMEPM */
2396 
2397 /** Default console output poll interval */
2398 extern uint dhd_console_ms;
2399 
2400 #if defined(DHD_DEBUG)
2401 extern uint wl_msg_level;
2402 #endif /* defined(DHD_DEBUG) */
2403 
2404 extern uint dhd_slpauto;
2405 
2406 /* Use interrupts */
2407 extern uint dhd_intr;
2408 
2409 /* Use polling */
2410 extern uint dhd_poll;
2411 
2412 /* ARP offload agent mode */
2413 extern uint dhd_arp_mode;
2414 
2415 /* ARP offload enable */
2416 extern uint dhd_arp_enable;
2417 
2418 /* Pkt filte enable control */
2419 extern uint dhd_pkt_filter_enable;
2420 
2421 /*  Pkt filter init setup */
2422 extern uint dhd_pkt_filter_init;
2423 
2424 /* Pkt filter mode control */
2425 extern uint dhd_master_mode;
2426 
2427 /* Roaming mode control */
2428 extern uint dhd_roam_disable;
2429 
2430 /* Roaming mode control */
2431 extern uint dhd_radio_up;
2432 
2433 /* TCM verification control */
2434 extern uint dhd_tcm_test_enable;
2435 
2436 /* Disable BUG_ON(1) */
2437 #ifdef DHD_FW_COREDUMP
2438 extern uint disable_bug_on;
2439 #endif /* DHD_FW_COREDUMP */
2440 
2441 /* Initial idletime ticks (may be -1 for immediate idle, 0 for no idle) */
2442 extern int dhd_idletime;
2443 #ifdef DHD_USE_IDLECOUNT
2444 #define DHD_IDLETIME_TICKS 5
2445 #else
2446 #define DHD_IDLETIME_TICKS 1
2447 #endif /* DHD_USE_IDLECOUNT */
2448 
2449 /* SDIO Drive Strength */
2450 extern uint dhd_sdiod_drive_strength;
2451 
2452 /* triggers bcm_bprintf to print to kernel log */
2453 extern bool bcm_bprintf_bypass;
2454 
2455 /* Override to force tx queueing all the time */
2456 extern uint dhd_force_tx_queueing;
2457 
2458 /* Default bcn_timeout value is 4 */
2459 #define DEFAULT_BCN_TIMEOUT_VALUE	4
2460 #ifndef CUSTOM_BCN_TIMEOUT_SETTING
2461 #define CUSTOM_BCN_TIMEOUT_SETTING	DEFAULT_BCN_TIMEOUT_VALUE
2462 #endif // endif
2463 
2464 /* Default KEEP_ALIVE Period is 55 sec to prevent AP from sending Keep Alive probe frame */
2465 #define DEFAULT_KEEP_ALIVE_VALUE 	55000 /* msec */
2466 #ifndef CUSTOM_KEEP_ALIVE_SETTING
2467 #define CUSTOM_KEEP_ALIVE_SETTING 	DEFAULT_KEEP_ALIVE_VALUE
2468 #endif /* DEFAULT_KEEP_ALIVE_VALUE */
2469 
2470 #define NULL_PKT_STR	"null_pkt"
2471 
2472 /* hooks for custom glom setting option via Makefile */
2473 #define DEFAULT_GLOM_VALUE 	-1
2474 #ifndef CUSTOM_GLOM_SETTING
2475 #define CUSTOM_GLOM_SETTING 	DEFAULT_GLOM_VALUE
2476 #endif // endif
2477 #define WL_AUTO_ROAM_TRIGGER -75
2478 /* hooks for custom Roaming Trigger  setting via Makefile */
2479 #define DEFAULT_ROAM_TRIGGER_VALUE -75 /* dBm default roam trigger all band */
2480 #define DEFAULT_ROAM_TRIGGER_SETTING 	-1
2481 #ifndef CUSTOM_ROAM_TRIGGER_SETTING
2482 #define CUSTOM_ROAM_TRIGGER_SETTING 	DEFAULT_ROAM_TRIGGER_VALUE
2483 #endif // endif
2484 
2485 /* hooks for custom Roaming Romaing  setting via Makefile */
2486 #define DEFAULT_ROAM_DELTA_VALUE  10 /* dBm default roam delta all band */
2487 #define DEFAULT_ROAM_DELTA_SETTING 	-1
2488 #ifndef CUSTOM_ROAM_DELTA_SETTING
2489 #define CUSTOM_ROAM_DELTA_SETTING 	DEFAULT_ROAM_DELTA_VALUE
2490 #endif // endif
2491 
2492 /* hooks for custom PNO Event wake lock to guarantee enough time
2493 	for the Platform to detect Event before system suspended
2494 */
2495 #define DEFAULT_PNO_EVENT_LOCK_xTIME 	2 	/* multiplay of DHD_PACKET_TIMEOUT_MS */
2496 #ifndef CUSTOM_PNO_EVENT_LOCK_xTIME
2497 #define CUSTOM_PNO_EVENT_LOCK_xTIME	 DEFAULT_PNO_EVENT_LOCK_xTIME
2498 #endif // endif
2499 /* hooks for custom dhd_dpc_prio setting option via Makefile */
2500 #define DEFAULT_DHP_DPC_PRIO  1
2501 #ifndef CUSTOM_DPC_PRIO_SETTING
2502 #define CUSTOM_DPC_PRIO_SETTING 	DEFAULT_DHP_DPC_PRIO
2503 #endif // endif
2504 
2505 #ifndef CUSTOM_LISTEN_INTERVAL
2506 #define CUSTOM_LISTEN_INTERVAL 		LISTEN_INTERVAL
2507 #endif /* CUSTOM_LISTEN_INTERVAL */
2508 
2509 #define DEFAULT_SUSPEND_BCN_LI_DTIM		3
2510 #ifndef CUSTOM_SUSPEND_BCN_LI_DTIM
2511 #define CUSTOM_SUSPEND_BCN_LI_DTIM		DEFAULT_SUSPEND_BCN_LI_DTIM
2512 #endif // endif
2513 
2514 #ifdef OEM_ANDROID
2515 #ifndef BCN_TIMEOUT_IN_SUSPEND
2516 #define BCN_TIMEOUT_IN_SUSPEND			6 /* bcn timeout value in suspend mode */
2517 #endif // endif
2518 #endif /* OEM_ANDROID */
2519 
2520 #ifndef CUSTOM_RXF_PRIO_SETTING
2521 #define CUSTOM_RXF_PRIO_SETTING		MAX((CUSTOM_DPC_PRIO_SETTING - 1), 1)
2522 #endif // endif
2523 
2524 #define DEFAULT_WIFI_TURNOFF_DELAY		0
2525 #ifndef WIFI_TURNOFF_DELAY
2526 #define WIFI_TURNOFF_DELAY		DEFAULT_WIFI_TURNOFF_DELAY
2527 #endif /* WIFI_TURNOFF_DELAY */
2528 
2529 #define DEFAULT_WIFI_TURNON_DELAY		200
2530 #ifndef WIFI_TURNON_DELAY
2531 #define WIFI_TURNON_DELAY		DEFAULT_WIFI_TURNON_DELAY
2532 #endif /* WIFI_TURNON_DELAY */
2533 
2534 #define DEFAULT_DHD_WATCHDOG_INTERVAL_MS	10 /* msec */
2535 #ifndef CUSTOM_DHD_WATCHDOG_MS
2536 #define CUSTOM_DHD_WATCHDOG_MS			DEFAULT_DHD_WATCHDOG_INTERVAL_MS
2537 #endif /* DEFAULT_DHD_WATCHDOG_INTERVAL_MS */
2538 
2539 #define DEFAULT_ASSOC_RETRY_MAX			3
2540 #ifndef CUSTOM_ASSOC_RETRY_MAX
2541 #define CUSTOM_ASSOC_RETRY_MAX			DEFAULT_ASSOC_RETRY_MAX
2542 #endif /* DEFAULT_ASSOC_RETRY_MAX */
2543 
2544 #if defined(BCMSDIO) || defined(DISABLE_FRAMEBURST)
2545 #define DEFAULT_FRAMEBURST_SET			0
2546 #else
2547 #define DEFAULT_FRAMEBURST_SET			1
2548 #endif /* BCMSDIO */
2549 
2550 #ifndef CUSTOM_FRAMEBURST_SET
2551 #define CUSTOM_FRAMEBURST_SET			DEFAULT_FRAMEBURST_SET
2552 #endif /* CUSTOM_FRAMEBURST_SET */
2553 
2554 #ifdef WLTDLS
2555 #ifndef CUSTOM_TDLS_IDLE_MODE_SETTING
2556 #define CUSTOM_TDLS_IDLE_MODE_SETTING  60000 /* 60sec to tear down TDLS of not active */
2557 #endif // endif
2558 #ifndef CUSTOM_TDLS_RSSI_THRESHOLD_HIGH
2559 #define CUSTOM_TDLS_RSSI_THRESHOLD_HIGH -70 /* rssi threshold for establishing TDLS link */
2560 #endif // endif
2561 #ifndef CUSTOM_TDLS_RSSI_THRESHOLD_LOW
2562 #define CUSTOM_TDLS_RSSI_THRESHOLD_LOW -80 /* rssi threshold for tearing down TDLS link */
2563 #endif // endif
2564 #ifndef CUSTOM_TDLS_PCKTCNT_THRESHOLD_HIGH
2565 #define CUSTOM_TDLS_PCKTCNT_THRESHOLD_HIGH 100 /* pkt/sec threshold for establishing TDLS link */
2566 #endif // endif
2567 #ifndef CUSTOM_TDLS_PCKTCNT_THRESHOLD_LOW
2568 #define CUSTOM_TDLS_PCKTCNT_THRESHOLD_LOW 10 /* pkt/sec threshold for tearing down TDLS link */
2569 #endif // endif
2570 #endif /* WLTDLS */
2571 
2572 #if defined(VSDB) || defined(ROAM_ENABLE)
2573 #define DEFAULT_BCN_TIMEOUT            8
2574 #else
2575 #define DEFAULT_BCN_TIMEOUT            4
2576 #endif // endif
2577 
2578 #ifndef CUSTOM_BCN_TIMEOUT
2579 #define CUSTOM_BCN_TIMEOUT             DEFAULT_BCN_TIMEOUT
2580 #endif // endif
2581 
2582 #define MAX_DTIM_SKIP_BEACON_INTERVAL	100 /* max allowed associated AP beacon for DTIM skip */
2583 #ifndef MAX_DTIM_ALLOWED_INTERVAL
2584 #define MAX_DTIM_ALLOWED_INTERVAL 600 /* max allowed total beacon interval for DTIM skip */
2585 #endif // endif
2586 
2587 #ifdef OEM_ANDROID
2588 #ifndef MIN_DTIM_FOR_ROAM_THRES_EXTEND
2589 #define MIN_DTIM_FOR_ROAM_THRES_EXTEND	600 /* minimum dtim interval to extend roam threshold */
2590 #endif // endif
2591 #endif /* OEM_ANDROID */
2592 
2593 #define NO_DTIM_SKIP 1
2594 #ifdef SDTEST
2595 /* Echo packet generator (SDIO), pkts/s */
2596 extern uint dhd_pktgen;
2597 
2598 /* Echo packet len (0 => sawtooth, max 1800) */
2599 extern uint dhd_pktgen_len;
2600 #define MAX_PKTGEN_LEN 1800
2601 #endif // endif
2602 
2603 /* optionally set by a module_param_string() */
2604 #define MOD_PARAM_PATHLEN	2048
2605 #define MOD_PARAM_INFOLEN	512
2606 #define MOD_PARAM_SRLEN		64
2607 
2608 #ifdef SOFTAP
2609 extern char fw_path2[MOD_PARAM_PATHLEN];
2610 #endif // endif
2611 
2612 #if defined(ANDROID_PLATFORM_VERSION)
2613 #if (ANDROID_PLATFORM_VERSION < 7)
2614 #define DHD_LEGACY_FILE_PATH
2615 #define VENDOR_PATH "/system"
2616 #elif (ANDROID_PLATFORM_VERSION == 7)
2617 #define VENDOR_PATH "/system"
2618 #elif (ANDROID_PLATFORM_VERSION >= 8)
2619 #define VENDOR_PATH "/vendor"
2620 #endif /* ANDROID_PLATFORM_VERSION < 7 */
2621 #else
2622 #define VENDOR_PATH ""
2623 #endif /* ANDROID_PLATFORM_VERSION */
2624 
2625 #if defined(ANDROID_PLATFORM_VERSION)
2626 #if (ANDROID_PLATFORM_VERSION < 9)
2627 #ifdef WL_STATIC_IF
2628 #undef WL_STATIC_IF
2629 #endif /* WL_STATIC_IF */
2630 #ifdef WL_STATIC_IFNAME_PREFIX
2631 #undef WL_STATIC_IFNAME_PREFIX
2632 #endif /* WL_STATIC_IFNAME_PREFIX */
2633 #endif /* ANDROID_PLATFORM_VERSION < 9 */
2634 #endif /* ANDROID_PLATFORM_VERSION */
2635 
2636 #if defined(DHD_LEGACY_FILE_PATH)
2637 #define PLATFORM_PATH	"/data/"
2638 #elif defined(PLATFORM_SLP)
2639 #define PLATFORM_PATH	"/opt/etc/"
2640 #else
2641 #if defined(ANDROID_PLATFORM_VERSION)
2642 #if (ANDROID_PLATFORM_VERSION >= 9)
2643 #define PLATFORM_PATH	"/data/vendor/conn/"
2644 #define DHD_MAC_ADDR_EXPORT
2645 #define DHD_ADPS_BAM_EXPORT
2646 #define DHD_EXPORT_CNTL_FILE
2647 #define DHD_SOFTAP_DUAL_IF_INFO
2648 #define DHD_SEND_HANG_PRIVCMD_ERRORS
2649 #else
2650 #define PLATFORM_PATH   "/data/misc/conn/"
2651 #endif /* ANDROID_PLATFORM_VERSION >= 9 */
2652 #else
2653 #define PLATFORM_PATH   "/data/misc/conn/"
2654 #endif /* ANDROID_PLATFORM_VERSION */
2655 #endif /* DHD_LEGACY_FILE_PATH */
2656 
2657 #ifdef DHD_MAC_ADDR_EXPORT
2658 extern struct ether_addr sysfs_mac_addr;
2659 #endif /* DHD_MAC_ADDR_EXPORT */
2660 
2661 /* Flag to indicate if we should download firmware on driver load */
2662 extern uint dhd_download_fw_on_driverload;
2663 extern int allow_delay_fwdl;
2664 
2665 extern int dhd_process_cid_mac(dhd_pub_t *dhdp, bool prepost);
2666 extern int dhd_write_file(const char *filepath, char *buf, int buf_len);
2667 extern int dhd_read_file(const char *filepath, char *buf, int buf_len);
2668 extern int dhd_write_file_and_check(const char *filepath, char *buf, int buf_len);
2669 extern int dhd_file_delete(char *path);
2670 
2671 #ifdef READ_MACADDR
2672 extern int dhd_set_macaddr_from_file(dhd_pub_t *dhdp);
2673 #else
dhd_set_macaddr_from_file(dhd_pub_t * dhdp)2674 static INLINE int dhd_set_macaddr_from_file(dhd_pub_t *dhdp) { return 0; }
2675 #endif /* READ_MACADDR */
2676 #ifdef WRITE_MACADDR
2677 extern int dhd_write_macaddr(struct ether_addr *mac);
2678 #else
dhd_write_macaddr(struct ether_addr * mac)2679 static INLINE int dhd_write_macaddr(struct ether_addr *mac) { return 0; }
2680 #endif /* WRITE_MACADDR */
2681 #ifdef USE_CID_CHECK
2682 #define MAX_VNAME_LEN		64
2683 #ifdef DHD_EXPORT_CNTL_FILE
2684 extern char cidinfostr[MAX_VNAME_LEN];
2685 #endif /* DHD_EXPORT_CNTL_FILE */
2686 extern int dhd_check_module_cid(dhd_pub_t *dhdp);
2687 extern char *dhd_get_cid_info(unsigned char *vid, int vid_length);
2688 #else
dhd_check_module_cid(dhd_pub_t * dhdp)2689 static INLINE int dhd_check_module_cid(dhd_pub_t *dhdp) { return 0; }
2690 #endif /* USE_CID_CHECK */
2691 #ifdef GET_MAC_FROM_OTP
2692 extern int dhd_check_module_mac(dhd_pub_t *dhdp);
2693 #else
dhd_check_module_mac(dhd_pub_t * dhdp)2694 static INLINE int dhd_check_module_mac(dhd_pub_t *dhdp) { return 0; }
2695 #endif /* GET_MAC_FROM_OTP */
2696 
2697 #if defined(READ_MACADDR) || defined(WRITE_MACADDR) || defined(USE_CID_CHECK) || \
2698 	defined(GET_MAC_FROM_OTP)
2699 #define DHD_USE_CISINFO
2700 #endif /* READ_MACADDR || WRITE_MACADDR || USE_CID_CHECK || GET_MAC_FROM_OTP */
2701 
2702 #ifdef DHD_USE_CISINFO
2703 int dhd_read_cis(dhd_pub_t *dhdp);
2704 void dhd_clear_cis(dhd_pub_t *dhdp);
2705 #if defined(SUPPORT_MULTIPLE_MODULE_CIS) && defined(USE_CID_CHECK)
2706 extern int dhd_check_module_b85a(void);
2707 extern int dhd_check_module_b90(void);
2708 #define BCM4359_MODULE_TYPE_B90B 1
2709 #define BCM4359_MODULE_TYPE_B90S 2
2710 #endif /* defined(SUPPORT_MULTIPLE_MODULE_CIS) && defined(USE_CID_CHECK) */
2711 #if defined(USE_CID_CHECK)
2712 extern int dhd_check_module_bcm(char *module_type, int index, bool *is_murata_fem);
2713 #endif /* defined(USE_CID_CHECK) */
2714 #else
dhd_read_cis(dhd_pub_t * dhdp)2715 static INLINE int dhd_read_cis(dhd_pub_t *dhdp) { return 0; }
dhd_clear_cis(dhd_pub_t * dhdp)2716 static INLINE void dhd_clear_cis(dhd_pub_t *dhdp) { }
2717 #endif /* DHD_USE_CISINFO */
2718 
2719 #if defined(WL_CFG80211) && defined(SUPPORT_DEEP_SLEEP)
2720 /* Flags to indicate if we distingish power off policy when
2721  * user set the memu "Keep Wi-Fi on during sleep" to "Never"
2722  */
2723 extern int trigger_deep_sleep;
2724 int dhd_deepsleep(struct net_device *dev, int flag);
2725 #endif /* WL_CFG80211 && SUPPORT_DEEP_SLEEP */
2726 
2727 extern void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar);
2728 extern void dhd_wait_event_wakeup(dhd_pub_t*dhd);
2729 
2730 #define IFLOCK_INIT(lock)       *lock = 0
2731 #define IFLOCK(lock)    while (InterlockedCompareExchange((lock), 1, 0))	\
2732 	NdisStallExecution(1);
2733 #define IFUNLOCK(lock)  InterlockedExchange((lock), 0)
2734 #define IFLOCK_FREE(lock)
2735 #define FW_SUPPORTED(dhd, capa) ((strstr(dhd->fw_capabilities, " " #capa " ") != NULL))
2736 #ifdef ARP_OFFLOAD_SUPPORT
2737 #define MAX_IPV4_ENTRIES	8
2738 void dhd_arp_offload_set(dhd_pub_t * dhd, int arp_mode);
2739 void dhd_arp_offload_enable(dhd_pub_t * dhd, int arp_enable);
2740 
2741 /* dhd_commn arp offload wrapers */
2742 void dhd_aoe_hostip_clr(dhd_pub_t *dhd, int idx);
2743 void dhd_aoe_arp_clr(dhd_pub_t *dhd, int idx);
2744 int dhd_arp_get_arp_hostip_table(dhd_pub_t *dhd, void *buf, int buflen, int idx);
2745 void dhd_arp_offload_add_ip(dhd_pub_t *dhd, uint32 ipaddr, int idx);
2746 #endif /* ARP_OFFLOAD_SUPPORT */
2747 #ifdef WLTDLS
2748 int dhd_tdls_enable(struct net_device *dev, bool tdls_on, bool auto_on, struct ether_addr *mac);
2749 int dhd_tdls_set_mode(dhd_pub_t *dhd, bool wfd_mode);
2750 #ifdef PCIE_FULL_DONGLE
2751 int dhd_tdls_update_peer_info(dhd_pub_t *dhdp, wl_event_msg_t *event);
2752 int dhd_tdls_event_handler(dhd_pub_t *dhd_pub, wl_event_msg_t *event);
2753 int dhd_free_tdls_peer_list(dhd_pub_t *dhd_pub);
2754 #endif /* PCIE_FULL_DONGLE */
2755 #endif /* WLTDLS */
2756 
2757 /* Neighbor Discovery Offload Support */
2758 extern int dhd_ndo_enable(dhd_pub_t * dhd, int ndo_enable);
2759 int dhd_ndo_add_ip(dhd_pub_t *dhd, char* ipaddr, int idx);
2760 int dhd_ndo_remove_ip(dhd_pub_t *dhd, int idx);
2761 
2762 /* Enhanced ND offload support */
2763 uint16 dhd_ndo_get_version(dhd_pub_t *dhdp);
2764 int dhd_ndo_add_ip_with_type(dhd_pub_t *dhdp, char *ipv6addr, uint8 type, int idx);
2765 int dhd_ndo_remove_ip_by_addr(dhd_pub_t *dhdp, char *ipv6addr, int idx);
2766 int dhd_ndo_remove_ip_by_type(dhd_pub_t *dhdp, uint8 type, int idx);
2767 int dhd_ndo_unsolicited_na_filter_enable(dhd_pub_t *dhdp, int enable);
2768 
2769 /* ioctl processing for nl80211 */
2770 int dhd_ioctl_process(dhd_pub_t *pub, int ifidx, struct dhd_ioctl *ioc, void *data_buf);
2771 
2772 #if defined(SUPPORT_MULTIPLE_REVISION)
2773 extern int
2774 concate_revision(struct dhd_bus *bus, char *fwpath, char *nvpath);
2775 #endif /* SUPPORT_MULTIPLE_REVISION */
2776 void dhd_bus_update_fw_nv_path(struct dhd_bus *bus, char *pfw_path, char *pnv_path);
2777 void dhd_set_bus_state(void *bus, uint32 state);
2778 
2779 /* Remove proper pkts(either one no-frag pkt or whole fragmented pkts) */
2780 typedef int (*f_droppkt_t)(dhd_pub_t *dhdp, int prec, void* p, bool bPktInQ);
2781 extern bool dhd_prec_drop_pkts(dhd_pub_t *dhdp, struct pktq *pq, int prec, f_droppkt_t fn);
2782 
2783 #ifdef PROP_TXSTATUS
2784 int dhd_os_wlfc_block(dhd_pub_t *pub);
2785 int dhd_os_wlfc_unblock(dhd_pub_t *pub);
2786 extern const uint8 prio2fifo[];
2787 #endif /* PROP_TXSTATUS */
2788 
2789 int dhd_os_socram_dump(struct net_device *dev, uint32 *dump_size);
2790 int dhd_os_get_socram_dump(struct net_device *dev, char **buf, uint32 *size);
2791 int dhd_common_socram_dump(dhd_pub_t *dhdp);
2792 
2793 int dhd_dump(dhd_pub_t *dhdp, char *buf, int buflen);
2794 
2795 int dhd_os_get_version(struct net_device *dev, bool dhd_ver, char **buf, uint32 size);
2796 void dhd_get_memdump_filename(struct net_device *ndev, char *memdump_path, int len, char *fname);
2797 uint8* dhd_os_prealloc(dhd_pub_t *dhdpub, int section, uint size, bool kmalloc_if_fail);
2798 void dhd_os_prefree(dhd_pub_t *dhdpub, void *addr, uint size);
2799 
2800 #if defined(CONFIG_DHD_USE_STATIC_BUF)
2801 #define DHD_OS_PREALLOC(dhdpub, section, size) dhd_os_prealloc(dhdpub, section, size, FALSE)
2802 #define DHD_OS_PREFREE(dhdpub, addr, size) dhd_os_prefree(dhdpub, addr, size)
2803 #else
2804 #define DHD_OS_PREALLOC(dhdpub, section, size) MALLOC(dhdpub->osh, size)
2805 #define DHD_OS_PREFREE(dhdpub, addr, size) MFREE(dhdpub->osh, addr, size)
2806 #endif /* defined(CONFIG_DHD_USE_STATIC_BUF) */
2807 
2808 #ifdef USE_WFA_CERT_CONF
2809 enum {
2810 	SET_PARAM_BUS_TXGLOM_MODE,
2811 	SET_PARAM_ROAMOFF,
2812 #ifdef USE_WL_FRAMEBURST
2813 	SET_PARAM_FRAMEBURST,
2814 #endif /* USE_WL_FRAMEBURST */
2815 #ifdef USE_WL_TXBF
2816 	SET_PARAM_TXBF,
2817 #endif /* USE_WL_TXBF */
2818 #ifdef PROP_TXSTATUS
2819 	SET_PARAM_PROPTX,
2820 	SET_PARAM_PROPTXMODE,
2821 #endif /* PROP_TXSTATUS */
2822 	PARAM_LAST_VALUE
2823 };
2824 extern int sec_get_param_wfa_cert(dhd_pub_t *dhd, int mode, uint* read_val);
2825 #ifdef DHD_EXPORT_CNTL_FILE
2826 #define VALUENOTSET 0xFFFFFFFFu
2827 extern uint32 bus_txglom;
2828 extern uint32 roam_off;
2829 #ifdef USE_WL_FRAMEBURST
2830 extern uint32 frameburst;
2831 #endif /* USE_WL_FRAMEBURST */
2832 #ifdef USE_WL_TXBF
2833 extern uint32 txbf;
2834 #endif /* USE_WL_TXBF */
2835 #ifdef PROP_TXSTATUS
2836 extern uint32 proptx;
2837 #endif /* PROP_TXSTATUS */
2838 #endif /* DHD_EXPORT_CNTL_FILE */
2839 #endif /* USE_WFA_CERT_CONF */
2840 
2841 #define dhd_add_flowid(pub, ifidx, ac_prio, ea, flowid)  do {} while (0)
2842 #define dhd_del_flowid(pub, ifidx, flowid)               do {} while (0)
2843 bool dhd_wet_chainable(dhd_pub_t *dhdp);
2844 
2845 extern unsigned long dhd_os_general_spin_lock(dhd_pub_t *pub);
2846 extern void dhd_os_general_spin_unlock(dhd_pub_t *pub, unsigned long flags);
2847 
2848 /** Miscellaenous DHD Spin Locks */
2849 
2850 /* Disable router 3GMAC bypass path perimeter lock */
2851 #define DHD_PERIM_LOCK(dhdp)              do {} while (0)
2852 #define DHD_PERIM_UNLOCK(dhdp)            do {} while (0)
2853 #define DHD_PERIM_LOCK_ALL(processor_id)    do {} while (0)
2854 #define DHD_PERIM_UNLOCK_ALL(processor_id)  do {} while (0)
2855 
2856 /* Enable DHD general spin lock/unlock */
2857 #define DHD_GENERAL_LOCK(dhdp, flags) \
2858 	(flags) = dhd_os_general_spin_lock(dhdp)
2859 #define DHD_GENERAL_UNLOCK(dhdp, flags) \
2860 	dhd_os_general_spin_unlock((dhdp), (flags))
2861 
2862 /* Enable DHD timer spin lock/unlock */
2863 #define DHD_TIMER_LOCK(lock, flags)     (flags) = dhd_os_spin_lock(lock)
2864 #define DHD_TIMER_UNLOCK(lock, flags)   dhd_os_spin_unlock(lock, (flags))
2865 
2866 /* Enable DHD flowring spin lock/unlock */
2867 #define DHD_FLOWRING_LOCK(lock, flags)     (flags) = dhd_os_spin_lock(lock)
2868 #define DHD_FLOWRING_UNLOCK(lock, flags)   dhd_os_spin_unlock((lock), (flags))
2869 
2870 /* Enable DHD common flowring info spin lock/unlock */
2871 #define DHD_FLOWID_LOCK(lock, flags)       (flags) = dhd_os_spin_lock(lock)
2872 #define DHD_FLOWID_UNLOCK(lock, flags)     dhd_os_spin_unlock((lock), (flags))
2873 
2874 /* Enable DHD common flowring list spin lock/unlock */
2875 #define DHD_FLOWRING_LIST_LOCK(lock, flags)       (flags) = dhd_os_spin_lock(lock)
2876 #define DHD_FLOWRING_LIST_UNLOCK(lock, flags)     dhd_os_spin_unlock((lock), (flags))
2877 
2878 #define DHD_SPIN_LOCK(lock, flags)	(flags) = dhd_os_spin_lock(lock)
2879 #define DHD_SPIN_UNLOCK(lock, flags)	dhd_os_spin_unlock((lock), (flags))
2880 
2881 #define DHD_RING_LOCK(lock, flags)	(flags) = dhd_os_spin_lock(lock)
2882 #define DHD_RING_UNLOCK(lock, flags)	dhd_os_spin_unlock((lock), (flags))
2883 
2884 #define DHD_BUS_LOCK(lock, flags)	(flags) = dhd_os_spin_lock(lock)
2885 #define DHD_BUS_UNLOCK(lock, flags)	dhd_os_spin_unlock((lock), (flags))
2886 
2887 /* Enable DHD backplane spin lock/unlock */
2888 #define DHD_BACKPLANE_ACCESS_LOCK(lock, flags)     (flags) = dhd_os_spin_lock(lock)
2889 #define DHD_BACKPLANE_ACCESS_UNLOCK(lock, flags)   dhd_os_spin_unlock((lock), (flags))
2890 
2891 #define DHD_BUS_INB_DW_LOCK(lock, flags)	(flags) = dhd_os_spin_lock(lock)
2892 #define DHD_BUS_INB_DW_UNLOCK(lock, flags)	dhd_os_spin_unlock((lock), (flags))
2893 
2894 /* Enable DHD TDLS peer list spin lock/unlock */
2895 #ifdef WLTDLS
2896 #define DHD_TDLS_LOCK(lock, flags)       (flags) = dhd_os_spin_lock(lock)
2897 #define DHD_TDLS_UNLOCK(lock, flags)     dhd_os_spin_unlock((lock), (flags))
2898 #endif /* WLTDLS */
2899 
2900 #define DHD_BUS_INB_DW_LOCK(lock, flags)	(flags) = dhd_os_spin_lock(lock)
2901 #define DHD_BUS_INB_DW_UNLOCK(lock, flags)	dhd_os_spin_unlock((lock), (flags))
2902 
2903 #ifdef DBG_PKT_MON
2904 /* Enable DHD PKT MON spin lock/unlock */
2905 #define DHD_PKT_MON_LOCK(lock, flags)     (flags) = dhd_os_spin_lock(lock)
2906 #define DHD_PKT_MON_UNLOCK(lock, flags)   dhd_os_spin_unlock(lock, (flags))
2907 #endif /* DBG_PKT_MON */
2908 
2909 #define DHD_LINUX_GENERAL_LOCK(dhdp, flags)	DHD_GENERAL_LOCK(dhdp, flags)
2910 #define DHD_LINUX_GENERAL_UNLOCK(dhdp, flags)	DHD_GENERAL_UNLOCK(dhdp, flags)
2911 
2912 /* linux is defined for DHD EFI builds also,
2913 * since its cross-compiled for EFI from linux
2914 */
2915 #define DHD_DBG_RING_LOCK_INIT(osh)				dhd_os_dbgring_lock_init(osh)
2916 #define DHD_DBG_RING_LOCK_DEINIT(osh, lock)		dhd_os_dbgring_lock_deinit(osh, (lock))
2917 #define DHD_DBG_RING_LOCK(lock, flags)			(flags) = dhd_os_dbgring_lock(lock)
2918 #define DHD_DBG_RING_UNLOCK(lock, flags)		dhd_os_dbgring_unlock((lock), flags)
2919 
2920 extern void dhd_dump_to_kernelog(dhd_pub_t *dhdp);
2921 
2922 extern void dhd_print_tasklet_status(dhd_pub_t *dhd);
2923 
2924 #ifdef DHD_L2_FILTER
2925 extern int dhd_get_parp_status(dhd_pub_t *dhdp, uint32 idx);
2926 extern int dhd_set_parp_status(dhd_pub_t *dhdp, uint32 idx, int val);
2927 extern int dhd_get_dhcp_unicast_status(dhd_pub_t *dhdp, uint32 idx);
2928 extern int dhd_set_dhcp_unicast_status(dhd_pub_t *dhdp, uint32 idx, int val);
2929 extern int dhd_get_block_ping_status(dhd_pub_t *dhdp, uint32 idx);
2930 extern int dhd_set_block_ping_status(dhd_pub_t *dhdp, uint32 idx, int val);
2931 extern int dhd_get_grat_arp_status(dhd_pub_t *dhdp, uint32 idx);
2932 extern int dhd_set_grat_arp_status(dhd_pub_t *dhdp, uint32 idx, int val);
2933 extern int dhd_get_block_tdls_status(dhd_pub_t *dhdp, uint32 idx);
2934 extern int dhd_set_block_tdls_status(dhd_pub_t *dhdp, uint32 idx, int val);
2935 #endif /* DHD_L2_FILTER */
2936 
2937 typedef struct wl_io_pport {
2938 	dhd_pub_t *dhd_pub;
2939 	uint ifidx;
2940 } wl_io_pport_t;
2941 
2942 typedef struct wl_evt_pport {
2943 	dhd_pub_t *dhd_pub;
2944 	int *ifidx;
2945 	void *pktdata;
2946 	uint data_len;
2947 	void **data_ptr;
2948 	void *raw_event;
2949 } wl_evt_pport_t;
2950 
2951 extern void *dhd_pub_shim(dhd_pub_t *dhd_pub);
2952 #ifdef DHD_FW_COREDUMP
2953 void* dhd_get_fwdump_buf(dhd_pub_t *dhd_pub, uint32 length);
2954 #endif /* DHD_FW_COREDUMP */
2955 
2956 #if defined(SET_RPS_CPUS)
2957 int dhd_rps_cpus_enable(struct net_device *net, int enable);
2958 int custom_rps_map_set(struct netdev_rx_queue *queue, char *buf, size_t len);
2959 void custom_rps_map_clear(struct netdev_rx_queue *queue);
2960 #define PRIMARY_INF 0
2961 #define VIRTUAL_INF 1
2962 #if defined(CONFIG_MACH_UNIVERSAL5433) || defined(CONFIG_MACH_UNIVERSAL7420) || \
2963 	defined(CONFIG_SOC_EXYNOS8890)
2964 #define RPS_CPUS_MASK "10"
2965 #define RPS_CPUS_MASK_P2P "10"
2966 #define RPS_CPUS_MASK_IBSS "10"
2967 #define RPS_CPUS_WLAN_CORE_ID 4
2968 #else
2969 #define RPS_CPUS_MASK "6"
2970 #define RPS_CPUS_MASK_P2P "6"
2971 #define RPS_CPUS_MASK_IBSS "6"
2972 #endif /* CONFIG_MACH_UNIVERSAL5433 || CONFIG_MACH_UNIVERSAL7420 || CONFIG_SOC_EXYNOS8890 */
2973 #endif // endif
2974 
2975 int dhd_get_download_buffer(dhd_pub_t	*dhd, char *file_path, download_type_t component,
2976 	char ** buffer, int *length);
2977 
2978 void dhd_free_download_buffer(dhd_pub_t	*dhd, void *buffer, int length);
2979 
2980 int dhd_download_blob(dhd_pub_t *dhd, unsigned char *buf,
2981 		uint32 len, char *iovar);
2982 
2983 int dhd_download_blob_cached(dhd_pub_t *dhd, char *file_path,
2984 	uint32 len, char *iovar);
2985 
2986 int dhd_apply_default_txcap(dhd_pub_t *dhd, char *txcap_path);
2987 int dhd_apply_default_clm(dhd_pub_t *dhd, char *clm_path);
2988 
2989 #ifdef SHOW_LOGTRACE
2990 int dhd_parse_logstrs_file(osl_t *osh, char *raw_fmts, int logstrs_size,
2991 		dhd_event_log_t *event_log);
2992 int dhd_parse_map_file(osl_t *osh, void *file, uint32 *ramstart,
2993 		uint32 *rodata_start, uint32 *rodata_end);
2994 #ifdef PCIE_FULL_DONGLE
2995 int dhd_event_logtrace_infobuf_pkt_process(dhd_pub_t *dhdp, void *pktbuf,
2996 		dhd_event_log_t *event_data);
2997 #endif /* PCIE_FULL_DONGLE */
2998 #endif /* SHOW_LOGTRACE */
2999 
3000 #define dhd_is_device_removed(x) FALSE
3001 #define dhd_os_ind_firmware_stall(x)
3002 
3003 #if defined(DHD_FW_COREDUMP)
3004 extern void dhd_get_memdump_info(dhd_pub_t *dhd);
3005 #endif /* defined(DHD_FW_COREDUMP) */
3006 #ifdef BCMASSERT_LOG
3007 extern void dhd_get_assert_info(dhd_pub_t *dhd);
3008 #else
dhd_get_assert_info(dhd_pub_t * dhd)3009 static INLINE void dhd_get_assert_info(dhd_pub_t *dhd) { }
3010 #endif /* BCMASSERT_LOG */
3011 
3012 #define DMAXFER_FREE(dhdp, dmap) dhd_schedule_dmaxfer_free(dhdp, dmap);
3013 
3014 #if defined(PCIE_FULL_DONGLE)
3015 extern void dmaxfer_free_prev_dmaaddr(dhd_pub_t *dhdp, dmaxref_mem_map_t *dmmap);
3016 void dhd_schedule_dmaxfer_free(dhd_pub_t *dhdp, dmaxref_mem_map_t *dmmap);
3017 #endif  /* PCIE_FULL_DONGLE */
3018 
3019 #define DHD_LB_STATS_NOOP	do { /* noop */ } while (0)
3020 #if defined(DHD_LB_STATS)
3021 #include <bcmutils.h>
3022 extern void dhd_lb_stats_init(dhd_pub_t *dhd);
3023 extern void dhd_lb_stats_deinit(dhd_pub_t *dhd);
3024 extern void dhd_lb_stats_dump(dhd_pub_t *dhdp, struct bcmstrbuf *strbuf);
3025 extern void dhd_lb_stats_update_napi_histo(dhd_pub_t *dhdp, uint32 count);
3026 extern void dhd_lb_stats_update_txc_histo(dhd_pub_t *dhdp, uint32 count);
3027 extern void dhd_lb_stats_update_rxc_histo(dhd_pub_t *dhdp, uint32 count);
3028 extern void dhd_lb_stats_txc_percpu_cnt_incr(dhd_pub_t *dhdp);
3029 extern void dhd_lb_stats_rxc_percpu_cnt_incr(dhd_pub_t *dhdp);
3030 #define DHD_LB_STATS_INIT(dhdp)	dhd_lb_stats_init(dhdp)
3031 #define DHD_LB_STATS_DEINIT(dhdp) dhd_lb_stats_deinit(dhdp)
3032 /* Reset is called from common layer so it takes dhd_pub_t as argument */
3033 #define DHD_LB_STATS_RESET(dhdp) dhd_lb_stats_init(dhdp)
3034 #define DHD_LB_STATS_CLR(x)	(x) = 0U
3035 #define DHD_LB_STATS_INCR(x)	(x) = (x) + 1
3036 #define DHD_LB_STATS_ADD(x, c)	(x) = (x) + (c)
3037 #define DHD_LB_STATS_PERCPU_ARR_INCR(x) \
3038 	{ \
3039 		int cpu = get_cpu(); put_cpu(); \
3040 		DHD_LB_STATS_INCR(x[cpu]); \
3041 	}
3042 #define DHD_LB_STATS_UPDATE_NAPI_HISTO(dhdp, x)	dhd_lb_stats_update_napi_histo(dhdp, x)
3043 #define DHD_LB_STATS_UPDATE_TXC_HISTO(dhdp, x)	dhd_lb_stats_update_txc_histo(dhdp, x)
3044 #define DHD_LB_STATS_UPDATE_RXC_HISTO(dhdp, x)	dhd_lb_stats_update_rxc_histo(dhdp, x)
3045 #define DHD_LB_STATS_TXC_PERCPU_CNT_INCR(dhdp)	dhd_lb_stats_txc_percpu_cnt_incr(dhdp)
3046 #define DHD_LB_STATS_RXC_PERCPU_CNT_INCR(dhdp)	dhd_lb_stats_rxc_percpu_cnt_incr(dhdp)
3047 #else /* !DHD_LB_STATS */
3048 #define DHD_LB_STATS_INIT(dhdp)	 DHD_LB_STATS_NOOP
3049 #define DHD_LB_STATS_DEINIT(dhdp) DHD_LB_STATS_NOOP
3050 #define DHD_LB_STATS_RESET(dhdp) DHD_LB_STATS_NOOP
3051 #define DHD_LB_STATS_CLR(x)	 DHD_LB_STATS_NOOP
3052 #define DHD_LB_STATS_INCR(x)	 DHD_LB_STATS_NOOP
3053 #define DHD_LB_STATS_ADD(x, c)	 DHD_LB_STATS_NOOP
3054 #define DHD_LB_STATS_PERCPU_ARR_INCR(x)	 DHD_LB_STATS_NOOP
3055 #define DHD_LB_STATS_UPDATE_NAPI_HISTO(dhd, x) DHD_LB_STATS_NOOP
3056 #define DHD_LB_STATS_UPDATE_TXC_HISTO(dhd, x) DHD_LB_STATS_NOOP
3057 #define DHD_LB_STATS_UPDATE_RXC_HISTO(dhd, x) DHD_LB_STATS_NOOP
3058 #define DHD_LB_STATS_TXC_PERCPU_CNT_INCR(dhdp) DHD_LB_STATS_NOOP
3059 #define DHD_LB_STATS_RXC_PERCPU_CNT_INCR(dhdp) DHD_LB_STATS_NOOP
3060 #endif /* !DHD_LB_STATS */
3061 
3062 #ifdef DHD_SSSR_DUMP
3063 #define DHD_SSSR_MEMPOOL_SIZE	(2 * 1024 * 1024) /* 2MB size */
3064 
3065 /* used in sssr_dump_mode */
3066 #define SSSR_DUMP_MODE_SSSR	0	/* dump both *before* and *after* files */
3067 #define SSSR_DUMP_MODE_FIS	1	/* dump *after* files only */
3068 
3069 extern int dhd_sssr_mempool_init(dhd_pub_t *dhd);
3070 extern void dhd_sssr_mempool_deinit(dhd_pub_t *dhd);
3071 extern int dhd_sssr_dump_init(dhd_pub_t *dhd);
3072 extern void dhd_sssr_dump_deinit(dhd_pub_t *dhd);
3073 extern int dhdpcie_sssr_dump(dhd_pub_t *dhd);
3074 extern void dhd_sssr_print_filepath(dhd_pub_t *dhd, char *path);
3075 
3076 #define DHD_SSSR_MEMPOOL_INIT(dhdp)	dhd_sssr_mempool_init(dhdp)
3077 #define DHD_SSSR_MEMPOOL_DEINIT(dhdp) dhd_sssr_mempool_deinit(dhdp)
3078 #define DHD_SSSR_DUMP_INIT(dhdp)	dhd_sssr_dump_init(dhdp)
3079 #define DHD_SSSR_DUMP_DEINIT(dhdp) dhd_sssr_dump_deinit(dhdp)
3080 #define DHD_SSSR_PRINT_FILEPATH(dhdp, path) dhd_sssr_print_filepath(dhdp, path)
3081 #else
3082 #define DHD_SSSR_MEMPOOL_INIT(dhdp)		do { /* noop */ } while (0)
3083 #define DHD_SSSR_MEMPOOL_DEINIT(dhdp)		do { /* noop */ } while (0)
3084 #define DHD_SSSR_DUMP_INIT(dhdp)		do { /* noop */ } while (0)
3085 #define DHD_SSSR_DUMP_DEINIT(dhdp)		do { /* noop */ } while (0)
3086 #define DHD_SSSR_PRINT_FILEPATH(dhdp, path)	do { /* noop */ } while (0)
3087 #endif /* DHD_SSSR_DUMP */
3088 
3089 #ifdef BCMPCIE
3090 extern int dhd_prot_debug_info_print(dhd_pub_t *dhd);
3091 extern bool dhd_bus_skip_clm(dhd_pub_t *dhdp);
3092 extern void dhd_pcie_dump_rc_conf_space_cap(dhd_pub_t *dhd);
3093 extern bool dhd_pcie_dump_int_regs(dhd_pub_t *dhd);
3094 #else
3095 #define dhd_prot_debug_info_print(x)
dhd_bus_skip_clm(dhd_pub_t * dhd_pub)3096 static INLINE bool dhd_bus_skip_clm(dhd_pub_t *dhd_pub)
3097 { return 0; }
3098 #endif /* BCMPCIE */
3099 
3100 fw_download_status_t dhd_fw_download_status(dhd_pub_t * dhd_pub);
3101 void dhd_show_kirqstats(dhd_pub_t *dhd);
3102 
3103 /* Bitmask used for Join Timeout */
3104 #define WLC_SSID_MASK          0x01
3105 #define WLC_WPA_MASK           0x02
3106 
3107 extern int dhd_start_join_timer(dhd_pub_t *pub);
3108 extern int dhd_stop_join_timer(dhd_pub_t *pub);
3109 extern int dhd_start_scan_timer(dhd_pub_t *pub, bool is_escan);
3110 extern int dhd_stop_scan_timer(dhd_pub_t *pub, bool is_escan, uint16 sync_id);
3111 extern int dhd_start_cmd_timer(dhd_pub_t *pub);
3112 extern int dhd_stop_cmd_timer(dhd_pub_t *pub);
3113 extern int dhd_start_bus_timer(dhd_pub_t *pub);
3114 extern int dhd_stop_bus_timer(dhd_pub_t *pub);
3115 extern uint16 dhd_get_request_id(dhd_pub_t *pub);
3116 extern int dhd_set_request_id(dhd_pub_t *pub, uint16 id, uint32 cmd);
3117 extern void dhd_set_join_error(dhd_pub_t *pub, uint32 mask);
3118 extern void dhd_clear_join_error(dhd_pub_t *pub, uint32 mask);
3119 extern void dhd_get_scan_to_val(dhd_pub_t *pub, uint32 *to_val);
3120 extern void dhd_set_scan_to_val(dhd_pub_t *pub, uint32 to_val);
3121 extern void dhd_get_join_to_val(dhd_pub_t *pub, uint32 *to_val);
3122 extern void dhd_set_join_to_val(dhd_pub_t *pub, uint32 to_val);
3123 extern void dhd_get_cmd_to_val(dhd_pub_t *pub, uint32 *to_val);
3124 extern void dhd_set_cmd_to_val(dhd_pub_t *pub, uint32 to_val);
3125 extern void dhd_get_bus_to_val(dhd_pub_t *pub, uint32 *to_val);
3126 extern void dhd_set_bus_to_val(dhd_pub_t *pub, uint32 to_val);
3127 extern int dhd_start_timesync_timer(dhd_pub_t *pub);
3128 extern int dhd_stop_timesync_timer(dhd_pub_t *pub);
3129 
3130 #ifdef DHD_PKTID_AUDIT_ENABLED
3131 void dhd_pktid_error_handler(dhd_pub_t *dhdp);
3132 #endif /* DHD_PKTID_AUDIT_ENABLED */
3133 
3134 #ifdef DHD_MAP_PKTID_LOGGING
3135 extern void dhd_pktid_logging_dump(dhd_pub_t *dhdp);
3136 #endif /* DHD_MAP_PKTID_LOGGING */
3137 
3138 #ifdef DHD_PCIE_RUNTIMEPM
3139 extern bool dhd_runtimepm_state(dhd_pub_t *dhd);
3140 extern bool dhd_runtime_bus_wake(struct dhd_bus *bus, bool wait, void *func_addr);
3141 extern bool dhdpcie_runtime_bus_wake(dhd_pub_t *dhdp, bool wait, void *func_addr);
3142 extern void dhdpcie_block_runtime_pm(dhd_pub_t *dhdp);
3143 extern bool dhdpcie_is_resume_done(dhd_pub_t *dhdp);
3144 extern void dhd_runtime_pm_disable(dhd_pub_t *dhdp);
3145 extern void dhd_runtime_pm_enable(dhd_pub_t *dhdp);
3146 /* Disable the Runtime PM and wake up if the bus is already in suspend */
3147 #define DHD_DISABLE_RUNTIME_PM(dhdp) \
3148 do { \
3149 	dhd_runtime_pm_disable(dhdp); \
3150 } while (0);
3151 
3152 /* Enable the Runtime PM */
3153 #define DHD_ENABLE_RUNTIME_PM(dhdp) \
3154 do { \
3155 	dhd_runtime_pm_enable(dhdp); \
3156 } while (0);
3157 #else
3158 #define DHD_DISABLE_RUNTIME_PM(dhdp)
3159 #define DHD_ENABLE_RUNTIME_PM(dhdp)
3160 #endif /* DHD_PCIE_RUNTIMEPM */
3161 
3162 #ifdef REVERSE_AIFSN
3163 extern int check_reverse_aifsn_condition(dhd_pub_t *dhdp, struct net_device *ndev);
3164 
3165 #define DHD_REVERSE_AIFSN(dhdp, ndev) \
3166 do { \
3167 	check_reverse_aifsn_condition(dhdp, ndev); \
3168 } while (0);
3169 #else
3170 #define DHD_REVERSE_AIFSN(dhdp, ndev)
3171 #endif /* AIFSN_REVERSE */
3172 
3173 extern bool dhd_prot_is_cmpl_ring_empty(dhd_pub_t *dhd, void *prot_info);
3174 extern void dhd_prot_dump_ring_ptrs(void *prot_info);
3175 
3176 #if defined(DHD_TRACE_WAKE_LOCK)
3177 void dhd_wk_lock_stats_dump(dhd_pub_t *dhdp);
3178 #endif // endif
3179 
3180 extern bool dhd_query_bus_erros(dhd_pub_t *dhdp);
3181 void dhd_clear_bus_errors(dhd_pub_t *dhdp);
3182 
3183 #if defined(CONFIG_64BIT)
3184 #define DHD_SUPPORT_64BIT
3185 #endif /* (linux || LINUX) && CONFIG_64BIT */
3186 
3187 #if defined(DHD_ERPOM)
3188 extern void dhd_schedule_reset(dhd_pub_t *dhdp);
3189 #else
dhd_schedule_reset(dhd_pub_t * dhdp)3190 static INLINE void dhd_schedule_reset(dhd_pub_t *dhdp) {;}
3191 #endif // endif
3192 
3193 extern void init_dhd_timeouts(dhd_pub_t *pub);
3194 extern void deinit_dhd_timeouts(dhd_pub_t *pub);
3195 
3196 typedef enum timeout_resons {
3197 	DHD_REASON_COMMAND_TO,
3198 	DHD_REASON_JOIN_TO,
3199 	DHD_REASON_SCAN_TO,
3200 	DHD_REASON_OQS_TO
3201 } timeout_reasons_t;
3202 
3203 extern void dhd_prhex(const char *msg, volatile uchar *buf, uint nbytes, uint8 dbg_level);
3204 int dhd_tput_test(dhd_pub_t *dhd, tput_test_t *tput_data);
3205 void dhd_tput_test_rx(dhd_pub_t *dhd, void *pkt);
dhd_get_max_txbufs(dhd_pub_t * dhdp)3206 static INLINE int dhd_get_max_txbufs(dhd_pub_t *dhdp)
3207 { return -1; }
3208 
3209 #ifdef FILTER_IE
3210 int dhd_read_from_file(dhd_pub_t *dhd);
3211 int dhd_parse_filter_ie(dhd_pub_t *dhd, uint8 *buf);
3212 int dhd_get_filter_ie_count(dhd_pub_t *dhd, uint8 *buf);
3213 int dhd_parse_oui(dhd_pub_t *dhd, uint8 *inbuf, uint8 *oui, int len);
3214 int dhd_check_valid_ie(dhd_pub_t *dhdp, uint8 *buf, int len);
3215 #endif /* FILTER_IE */
3216 
3217 uint16 dhd_prot_get_ioctl_trans_id(dhd_pub_t *dhdp);
3218 
3219 #ifdef SET_PCIE_IRQ_CPU_CORE
3220 enum {
3221 	PCIE_IRQ_AFFINITY_OFF = 0,
3222 	PCIE_IRQ_AFFINITY_BIG_CORE_ANY,
3223 	PCIE_IRQ_AFFINITY_BIG_CORE_EXYNOS,
3224 	PCIE_IRQ_AFFINITY_LAST
3225 };
3226 extern void dhd_set_irq_cpucore(dhd_pub_t *dhdp, int affinity_cmd);
3227 #endif /* SET_PCIE_IRQ_CPU_CORE */
3228 
3229 #if defined(DHD_HANG_SEND_UP_TEST)
3230 extern void dhd_make_hang_with_reason(struct net_device *dev, const char *string_num);
3231 #endif /* DHD_HANG_SEND_UP_TEST */
3232 
3233 #ifdef DHD_RND_DEBUG
3234 int dhd_dump_rnd_info(dhd_pub_t *dhd, uint8 *rnd_buf, uint32 rnd_len);
3235 int dhd_get_rnd_info(dhd_pub_t *dhd);
3236 #endif /* DHD_RND_DEBUG */
3237 
3238 #ifdef DHD_WAKE_STATUS
3239 wake_counts_t* dhd_get_wakecount(dhd_pub_t *dhdp);
3240 #endif /* DHD_WAKE_STATUS */
3241 extern int dhd_get_random_bytes(uint8 *buf, uint len);
3242 #if defined(DHD_BLOB_EXISTENCE_CHECK)
3243 extern void dhd_set_blob_support(dhd_pub_t *dhdp, char *fw_path);
3244 #endif /* DHD_BLOB_EXISTENCE_CHECK */
3245 
3246 /* configuration of ecounters. API's tp start/stop. currently supported only for linux */
3247 extern int dhd_ecounter_configure(dhd_pub_t *dhd, bool enable);
3248 extern int dhd_start_ecounters(dhd_pub_t *dhd);
3249 extern int dhd_stop_ecounters(dhd_pub_t *dhd);
3250 extern int dhd_start_event_ecounters(dhd_pub_t *dhd);
3251 extern int dhd_stop_event_ecounters(dhd_pub_t *dhd);
3252 
3253 int dhd_get_preserve_log_numbers(dhd_pub_t *dhd, uint32 *logset_mask);
3254 
3255 #ifdef DHD_LOG_DUMP
3256 void dhd_schedule_log_dump(dhd_pub_t *dhdp, void *type);
3257 void dhd_log_dump_trigger(dhd_pub_t *dhdp, int subcmd);
3258 int dhd_log_dump_ring_to_file(dhd_pub_t *dhdp, void *ring_ptr, void *file,
3259 		unsigned long *file_posn, log_dump_section_hdr_t *sec_hdr, char *text_hdr,
3260 		uint32 sec_type);
3261 int dhd_dump_debug_ring(dhd_pub_t *dhdp, void *ring_ptr, const void *user_buf,
3262 		log_dump_section_hdr_t *sec_hdr, char *text_hdr, int buflen, uint32 sec_type);
3263 int dhd_log_dump_cookie_to_file(dhd_pub_t *dhdp, void *fp,
3264 	const void *user_buf, unsigned long *f_pos);
3265 int dhd_log_dump_cookie(dhd_pub_t *dhdp, const void *user_buf);
3266 uint32 dhd_log_dump_cookie_len(dhd_pub_t *dhdp);
3267 int dhd_logdump_cookie_init(dhd_pub_t *dhdp, uint8 *buf, uint32 buf_size);
3268 void dhd_logdump_cookie_deinit(dhd_pub_t *dhdp);
3269 void dhd_logdump_cookie_save(dhd_pub_t *dhdp, char *cookie, char *type);
3270 int dhd_logdump_cookie_get(dhd_pub_t *dhdp, char *ret_cookie, uint32 buf_size);
3271 int dhd_logdump_cookie_count(dhd_pub_t *dhdp);
3272 int dhd_get_dld_log_dump(void *dev, dhd_pub_t *dhdp, const void *user_buf, void *fp,
3273 	uint32 len, int type, void *pos);
3274 int dhd_print_ext_trap_data(void *dev, dhd_pub_t *dhdp, const void *user_buf,
3275 	void *fp, uint32 len, void *pos);
3276 int dhd_print_dump_data(void *dev, dhd_pub_t *dhdp, const void *user_buf,
3277 	void *fp, uint32 len, void *pos);
3278 int dhd_print_cookie_data(void *dev, dhd_pub_t *dhdp, const void *user_buf,
3279 	void *fp, uint32 len, void *pos);
3280 int dhd_print_health_chk_data(void *dev, dhd_pub_t *dhdp, const void *user_buf,
3281 	void *fp, uint32 len, void *pos);
3282 int dhd_print_time_str(const void *user_buf, void *fp, uint32 len, void *pos);
3283 #ifdef DHD_DUMP_PCIE_RINGS
3284 int dhd_print_flowring_data(void *dev, dhd_pub_t *dhdp, const void *user_buf,
3285 	void *fp, uint32 len, void *pos);
3286 uint32 dhd_get_flowring_len(void *ndev, dhd_pub_t *dhdp);
3287 #endif /* DHD_DUMP_PCIE_RINGS */
3288 #ifdef DHD_STATUS_LOGGING
3289 extern int dhd_print_status_log_data(void *dev, dhd_pub_t *dhdp,
3290 	const void *user_buf, void *fp, uint32 len, void *pos);
3291 extern uint32 dhd_get_status_log_len(void *ndev, dhd_pub_t *dhdp);
3292 #endif /* DHD_STATUS_LOGGING */
3293 int dhd_print_ecntrs_data(void *dev, dhd_pub_t *dhdp, const void *user_buf,
3294 	void *fp, uint32 len, void *pos);
3295 int dhd_print_rtt_data(void *dev, dhd_pub_t *dhdp, const void *user_buf,
3296 	void *fp, uint32 len, void *pos);
3297 int dhd_get_debug_dump_file_name(void *dev, dhd_pub_t *dhdp,
3298 	char *dump_path, int size);
3299 uint32 dhd_get_ext_trap_len(void *ndev, dhd_pub_t *dhdp);
3300 uint32 dhd_get_time_str_len(void);
3301 uint32 dhd_get_health_chk_len(void *ndev, dhd_pub_t *dhdp);
3302 uint32 dhd_get_dhd_dump_len(void *ndev, dhd_pub_t *dhdp);
3303 uint32 dhd_get_cookie_log_len(void *ndev, dhd_pub_t *dhdp);
3304 uint32 dhd_get_ecntrs_len(void *ndev, dhd_pub_t *dhdp);
3305 uint32 dhd_get_rtt_len(void *ndev, dhd_pub_t *dhdp);
3306 uint32 dhd_get_dld_len(int log_type);
3307 void dhd_init_sec_hdr(log_dump_section_hdr_t *sec_hdr);
3308 extern char *dhd_log_dump_get_timestamp(void);
3309 bool dhd_log_dump_ecntr_enabled(void);
3310 bool dhd_log_dump_rtt_enabled(void);
3311 void dhd_nla_put_sssr_dump_len(void *ndev, uint32 *arr_len);
3312 int dhd_get_debug_dump(void *dev, const void *user_buf, uint32 len, int type);
3313 int
3314 dhd_sssr_dump_d11_buf_before(void *dev, const void *user_buf, uint32 len, int core);
3315 int
3316 dhd_sssr_dump_d11_buf_after(void *dev, const void *user_buf, uint32 len, int core);
3317 int
3318 dhd_sssr_dump_dig_buf_before(void *dev, const void *user_buf, uint32 len);
3319 int
3320 dhd_sssr_dump_dig_buf_after(void *dev, const void *user_buf, uint32 len);
3321 #ifdef DHD_PKT_LOGGING
3322 extern int dhd_os_get_pktlog_dump(void *dev, const void *user_buf, uint32 len);
3323 extern uint32 dhd_os_get_pktlog_dump_size(struct net_device *dev);
3324 extern void dhd_os_get_pktlogdump_filename(struct net_device *dev, char *dump_path, int len);
3325 #endif /* DHD_PKT_LOGGING */
3326 
3327 #ifdef DNGL_AXI_ERROR_LOGGING
3328 extern int dhd_os_get_axi_error_dump(void *dev, const void *user_buf, uint32 len);
3329 extern int dhd_os_get_axi_error_dump_size(struct net_device *dev);
3330 extern void dhd_os_get_axi_error_filename(struct net_device *dev, char *dump_path, int len);
3331 #endif /*  DNGL_AXI_ERROR_LOGGING */
3332 
3333 #endif /* DHD_LOG_DUMP */
3334 int dhd_export_debug_data(void *mem_buf, void *fp, const void *user_buf, int buf_len, void *pos);
3335 #define DHD_PCIE_CONFIG_SAVE(bus)	pci_save_state(bus->dev)
3336 #define DHD_PCIE_CONFIG_RESTORE(bus)	pci_restore_state(bus->dev)
3337 
3338 #ifdef BIGDATA_SOFTAP
3339 void dhd_schedule_gather_ap_stadata(void *bcm_cfg, void *ndev, const wl_event_msg_t *e);
3340 #endif /* BIGDATA_SOFTAP */
3341 
3342 typedef struct dhd_pkt_parse {
3343 	uint32 proto;	/* Network layer protocol */
3344 	uint32 t1;	/* n-tuple */
3345 	uint32 t2;
3346 } dhd_pkt_parse_t;
3347 
3348 /* ========= RING API functions : exposed to others ============= */
3349 #define DHD_RING_TYPE_FIXED		1
3350 #define DHD_RING_TYPE_SINGLE_IDX	2
3351 uint32 dhd_ring_get_hdr_size(void);
3352 void *dhd_ring_init(dhd_pub_t *dhdp, uint8 *buf, uint32 buf_size, uint32 elem_size,
3353 	uint32 elem_cnt, uint32 type);
3354 void dhd_ring_deinit(dhd_pub_t *dhdp, void *_ring);
3355 void *dhd_ring_get_first(void *_ring);
3356 void dhd_ring_free_first(void *_ring);
3357 void dhd_ring_set_read_idx(void *_ring, uint32 read_idx);
3358 void dhd_ring_set_write_idx(void *_ring, uint32 write_idx);
3359 uint32 dhd_ring_get_read_idx(void *_ring);
3360 uint32 dhd_ring_get_write_idx(void *_ring);
3361 void *dhd_ring_get_last(void *_ring);
3362 void *dhd_ring_get_next(void *_ring, void *cur);
3363 void *dhd_ring_get_prev(void *_ring, void *cur);
3364 void *dhd_ring_get_empty(void *_ring);
3365 int dhd_ring_get_cur_size(void *_ring);
3366 void dhd_ring_lock(void *ring, void *fist_ptr, void *last_ptr);
3367 void dhd_ring_lock_free(void *ring);
3368 void *dhd_ring_lock_get_first(void *_ring);
3369 void *dhd_ring_lock_get_last(void *_ring);
3370 int dhd_ring_lock_get_count(void *_ring);
3371 void dhd_ring_lock_free_first(void *ring);
3372 void dhd_ring_whole_lock(void *ring);
3373 void dhd_ring_whole_unlock(void *ring);
3374 
3375 #define DHD_DUMP_TYPE_NAME_SIZE		32
3376 #define DHD_DUMP_FILE_PATH_SIZE		256
3377 #define DHD_DUMP_FILE_COUNT_MAX		5
3378 #define DHD_DUMP_TYPE_COUNT_MAX		10
3379 
3380 #ifdef DHD_DUMP_MNGR
3381 typedef struct _DFM_elem {
3382 	char type_name[DHD_DUMP_TYPE_NAME_SIZE];
3383 	char file_path[DHD_DUMP_FILE_COUNT_MAX][DHD_DUMP_FILE_PATH_SIZE];
3384 	int file_idx;
3385 } DFM_elem_t;
3386 
3387 typedef struct _dhd_dump_file_manage {
3388 	DFM_elem_t elems[DHD_DUMP_TYPE_COUNT_MAX];
3389 } dhd_dump_file_manage_t;
3390 
3391 extern void dhd_dump_file_manage_enqueue(dhd_pub_t *dhd, char *dump_path, char *fname);
3392 #endif /* DHD_DUMP_MNGR */
3393 
3394 #ifdef PKT_FILTER_SUPPORT
3395 extern void dhd_pktfilter_offload_set(dhd_pub_t * dhd, char *arg);
3396 extern void dhd_pktfilter_offload_enable(dhd_pub_t * dhd, char *arg, int enable, int master_mode);
3397 extern void dhd_pktfilter_offload_delete(dhd_pub_t *dhd, int id);
3398 #endif // endif
3399 
3400 #ifdef DHD_DUMP_PCIE_RINGS
3401 extern int dhd_d2h_h2d_ring_dump(dhd_pub_t *dhd, void *file, const void *user_buf,
3402 	unsigned long *file_posn, bool file_write);
3403 #endif /* DHD_DUMP_PCIE_RINGS */
3404 
3405 #ifdef EWP_EDL
3406 #define DHD_EDL_RING_SIZE (D2HRING_EDL_MAX_ITEM * D2HRING_EDL_ITEMSIZE)
3407 int dhd_event_logtrace_process_edl(dhd_pub_t *dhdp, uint8 *data,
3408 		void *evt_decode_data);
3409 int dhd_edl_mem_init(dhd_pub_t *dhd);
3410 void dhd_edl_mem_deinit(dhd_pub_t *dhd);
3411 void dhd_prot_edl_ring_tcm_rd_update(dhd_pub_t *dhd);
3412 #define DHD_EDL_MEM_INIT(dhdp) dhd_edl_mem_init(dhdp)
3413 #define DHD_EDL_MEM_DEINIT(dhdp) dhd_edl_mem_deinit(dhdp)
3414 #define DHD_EDL_RING_TCM_RD_UPDATE(dhdp) \
3415 	dhd_prot_edl_ring_tcm_rd_update(dhdp)
3416 #else
3417 #define DHD_EDL_MEM_INIT(dhdp) do { /* noop */ } while (0)
3418 #define DHD_EDL_MEM_DEINIT(dhdp) do { /* noop */ } while (0)
3419 #define DHD_EDL_RING_TCM_RD_UPDATE(dhdp) do { /* noop */ } while (0)
3420 #endif /* EWP_EDL */
3421 
3422 void dhd_schedule_logtrace(void *dhd_info);
3423 int dhd_print_fw_ver_from_file(dhd_pub_t *dhdp, char *fwpath);
3424 
3425 #define HD_PREFIX_SIZE  2   /* hexadecimal prefix size */
3426 #define HD_BYTE_SIZE    2   /* hexadecimal byte size */
3427 
3428 #if defined(DHD_H2D_LOG_TIME_SYNC)
3429 void dhd_h2d_log_time_sync_deferred_wq_schedule(dhd_pub_t *dhdp);
3430 void dhd_h2d_log_time_sync(dhd_pub_t *dhdp);
3431 #endif /* DHD_H2D_LOG_TIME_SYNC */
3432 extern void dhd_cleanup_if(struct net_device *net);
3433 
3434 #ifdef DNGL_AXI_ERROR_LOGGING
3435 extern void dhd_axi_error(dhd_pub_t *dhd);
3436 #ifdef DHD_USE_WQ_FOR_DNGL_AXI_ERROR
3437 extern void dhd_axi_error_dispatch(dhd_pub_t *dhdp);
3438 #endif /* DHD_USE_WQ_FOR_DNGL_AXI_ERROR */
3439 #endif /* DNGL_AXI_ERROR_LOGGING */
3440 
3441 #ifdef DHD_HP2P
3442 extern unsigned long dhd_os_hp2plock(dhd_pub_t *pub);
3443 extern void dhd_os_hp2punlock(dhd_pub_t *pub, unsigned long flags);
3444 #endif /* DHD_HP2P */
3445 extern struct dhd_if * dhd_get_ifp(dhd_pub_t *dhdp, uint32 ifidx);
3446 
3447 #ifdef DHD_STATUS_LOGGING
3448 #include <dhd_statlog.h>
3449 #else
3450 #define ST(x)		0
3451 #define STDIR(x)	0
3452 #define DHD_STATLOG_CTRL(dhdp, stat, ifidx, reason) \
3453 	do { /* noop */ } while (0)
3454 #define DHD_STATLOG_DATA(dhdp, stat, ifidx, dir, cond) \
3455 	do { BCM_REFERENCE(cond); } while (0)
3456 #define DHD_STATLOG_DATA_RSN(dhdp, stat, ifidx, dir, reason) \
3457 	do { /* noop */ } while (0)
3458 #endif /* DHD_STATUS_LOGGING */
3459 
3460 #ifdef CONFIG_SILENT_ROAM
3461 extern int dhd_sroam_set_mon(dhd_pub_t *dhd, bool set);
3462 typedef wlc_sroam_info_v1_t wlc_sroam_info_t;
3463 #endif /* CONFIG_SILENT_ROAM */
3464 
3465 #ifdef SUPPORT_SET_TID
3466 enum dhd_set_tid_mode {
3467 	/* Disalbe changing TID */
3468 	SET_TID_OFF = 0,
3469 	/* Change TID for all UDP frames */
3470 	SET_TID_ALL_UDP,
3471 	/* Change TID for UDP frames based on UID */
3472 	SET_TID_BASED_ON_UID
3473 };
3474 extern void dhd_set_tid_based_on_uid(dhd_pub_t *dhdp, void *pkt);
3475 #endif /* SUPPORT_SET_TID */
3476 
3477 #ifdef DHD_DUMP_FILE_WRITE_FROM_KERNEL
3478 #define FILE_NAME_HAL_TAG	""
3479 #else
3480 #define FILE_NAME_HAL_TAG	"_hal" /* The tag name concatenated by HAL */
3481 #endif /* DHD_DUMP_FILE_WRITE_FROM_KERNEL */
3482 
3483 #if defined(DISABLE_HE_ENAB) || defined(CUSTOM_CONTROL_HE_ENAB)
3484 extern int dhd_control_he_enab(dhd_pub_t * dhd, uint8 he_enab);
3485 extern uint8 control_he_enab;
3486 #endif /* DISABLE_HE_ENAB  || CUSTOM_CONTROL_HE_ENAB */
3487 
3488 #if defined(BCMSDIO)
3489 void dhd_set_role(dhd_pub_t *dhdp, int role, int bssidx);
3490 #endif /* BCMSDIO */
3491 #endif /* _dhd_h_ */
3492