xref: /OK3568_Linux_fs/external/rkwifibt/drivers/infineon/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) 2021 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 "/etc/wifi/bcmdhd_clm.blob"
405 #else
406 #define CONFIG_BCMDHD_CLM_PATH "/var/run/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(CONFIG_DHD_PLAT_ROCKCHIP)
829 #define DHD_COMMON_DUMP_PATH	"/data/misc/wifi/"
830 #elif defined(OEM_ANDROID) && (defined(BOARD_PANDA) || defined(__ARM_ARCH_7A__))
831 #define DHD_COMMON_DUMP_PATH	"/data/vendor/wifi/"
832 #elif defined(OEM_ANDROID) /* For Brix Live Image */
833 #define DHD_COMMON_DUMP_PATH	"/installmedia/"
834 #else /* Default */
835 #define DHD_COMMON_DUMP_PATH	"/root/"
836 #endif // endif
837 
838 struct cntry_locales_custom {
839 	char iso_abbrev[WLC_CNTRY_BUF_SZ];      /* ISO 3166-1 country abbreviation */
840 	char custom_locale[WLC_CNTRY_BUF_SZ];   /* Custom firmware locale */
841 	int32 custom_locale_rev;                /* Custom local revisin default -1 */
842 };
843 
844 int dhd_send_msg_to_daemon(struct sk_buff *skb, void *data, int size);
845 
846 #ifdef DMAMAP_STATS
847 typedef struct dmamap_stats {
848 	uint64 txdata;
849 	uint64 txdata_sz;
850 	uint64 rxdata;
851 	uint64 rxdata_sz;
852 	uint64 ioctl_rx;
853 	uint64 ioctl_rx_sz;
854 	uint64 event_rx;
855 	uint64 event_rx_sz;
856 	uint64 info_rx;
857 	uint64 info_rx_sz;
858 	uint64 tsbuf_rx;
859 	uint64 tsbuf_rx_sz;
860 } dma_stats_t;
861 #endif /* DMAMAP_STATS */
862 
863 /*  see wlfc_proto.h for tx status details */
864 #define DHD_MAX_TX_STATUS_MSGS     9u
865 
866 #ifdef TX_STATUS_LATENCY_STATS
867 typedef struct dhd_if_tx_status_latency {
868 	/* total number of tx_status received on this interface */
869 	uint64 num_tx_status;
870 	/* cumulative tx_status latency for this interface */
871 	uint64 cum_tx_status_latency;
872 } dhd_if_tx_status_latency_t;
873 #endif /* TX_STATUS_LATENCY_STATS */
874 
875 #if defined(SHOW_LOGTRACE) && defined(DHD_USE_KTHREAD_FOR_LOGTRACE)
876 /* Timestamps to trace dhd_logtrace_thread() */
877 struct dhd_logtrace_thr_ts {
878 	uint64 entry_time;
879 	uint64 sem_down_time;
880 	uint64 flush_time;
881 	uint64 unexpected_break_time;
882 	uint64 complete_time;
883 };
884 #endif /* SHOW_LOGTRACE && DHD_USE_KTHREAD_FOR_LOGTRACE */
885 
886 /* Enable Reserve STA flowrings only for Android */
887 #if defined(OEM_ANDROID)
888 #define DHD_LIMIT_MULTI_CLIENT_FLOWRINGS
889 #endif /* OEM_ANDROID */
890 
891 typedef enum dhd_induce_error_states
892 {
893 	DHD_INDUCE_ERROR_CLEAR		= 0x0,
894 	DHD_INDUCE_IOCTL_TIMEOUT	= 0x1,
895 	DHD_INDUCE_D3_ACK_TIMEOUT	= 0x2,
896 	DHD_INDUCE_LIVELOCK		= 0x3,
897 	DHD_INDUCE_DROP_OOB_IRQ		= 0x4,
898 	DHD_INDUCE_DROP_AXI_SIG		= 0x5,
899 	DHD_INDUCE_ERROR_MAX		= 0x6
900 } dhd_induce_error_states_t;
901 
902 #ifdef DHD_HP2P
903 #define MAX_TX_HIST_BIN		16
904 #define MAX_RX_HIST_BIN		10
905 #define MAX_HP2P_FLOWS		16
906 #define HP2P_PRIO		7
907 #define HP2P_PKT_THRESH		48
908 #define HP2P_TIME_THRESH	200
909 #define HP2P_PKT_EXPIRY		40
910 #define	HP2P_TIME_SCALE		32
911 
912 typedef struct hp2p_info {
913 	void	*dhd_pub;
914 	uint16	flowid;
915 	bool	hrtimer_init;
916 	void	*ring;
917 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(5, 1, 21))
918 	struct	tasklet_hrtimer timer;
919 #else
920 	struct	hrtimer timer;
921 #endif /* (LINUX_VERSION_CODE <= KERNEL_VERSION(5, 1, 21) */
922 	uint64	num_pkt_limit;
923 	uint64	num_timer_limit;
924 	uint64	num_timer_start;
925 	uint64	tx_t0[MAX_TX_HIST_BIN];
926 	uint64	tx_t1[MAX_TX_HIST_BIN];
927 	uint64	rx_t0[MAX_RX_HIST_BIN];
928 } hp2p_info_t;
929 #endif /* DHD_HP2P */
930 
931 typedef enum {
932 	FW_UNLOADED = 0,
933 	FW_DOWNLOAD_IN_PROGRESS = 1,
934 	FW_DOWNLOAD_DONE = 2
935 } fw_download_status_t;
936 
937 /**
938  * Common structure for module and instance linkage.
939  * Instantiated once per hardware (dongle) instance that this DHD manages.
940  */
941 typedef struct dhd_pub {
942 	/* Linkage ponters */
943 	osl_t *osh;		/* OSL handle */
944 	struct dhd_bus *bus;	/* Bus module handle */
945 	struct dhd_prot *prot;	/* Protocol module handle */
946 	struct dhd_info  *info; /* Info module handle */
947 	struct dhd_dbg *dbg;	/* Debugability module handle */
948 #if defined(SHOW_LOGTRACE) && defined(DHD_USE_KTHREAD_FOR_LOGTRACE)
949 	struct dhd_logtrace_thr_ts logtrace_thr_ts;
950 #endif /* SHOW_LOGTRACE && DHD_USE_KTHREAD_FOR_LOGTRACE */
951 
952 	/* to NDIS developer, the structure dhd_common is redundant,
953 	 * please do NOT merge it back from other branches !!!
954 	 */
955 
956 	/* Internal dhd items */
957 	bool up;		/* Driver up/down (to OS) */
958 #ifdef WL_CFG80211
959 	spinlock_t up_lock;	/* Synchronization with CFG80211 down */
960 #endif /* WL_CFG80211 */
961 	bool txoff;		/* Transmit flow-controlled */
962 	bool dongle_reset;  /* TRUE = DEVRESET put dongle into reset */
963 	enum dhd_bus_state busstate;
964 	uint dhd_bus_busy_state;	/* Bus busy state */
965 	uint hdrlen;		/* Total DHD header length (proto + bus) */
966 	uint maxctl;		/* Max size rxctl request from proto to bus */
967 	uint rxsz;		/* Rx buffer size bus module should use */
968 	uint8 wme_dp;	/* wme discard priority */
969 #ifdef DNGL_AXI_ERROR_LOGGING
970 	uint32 axierror_logbuf_addr;
971 	bool axi_error;
972 	struct dhd_axi_error_dump *axi_err_dump;
973 #endif /* DNGL_AXI_ERROR_LOGGING */
974 	/* Dongle media info */
975 	bool iswl;		/* Dongle-resident driver is wl */
976 	ulong drv_version;	/* Version of dongle-resident driver */
977 	struct ether_addr mac;	/* MAC address obtained from dongle */
978 	dngl_stats_t dstats;	/* Stats for dongle-based data */
979 
980 	/* Additional stats for the bus level */
981 	ulong tx_packets;	/* Data packets sent to dongle */
982 	ulong tx_dropped;	/* Data packets dropped in dhd */
983 	ulong tx_multicast;	/* Multicast data packets sent to dongle */
984 	ulong tx_errors;	/* Errors in sending data to dongle */
985 	ulong tx_ctlpkts;	/* Control packets sent to dongle */
986 	ulong tx_ctlerrs;	/* Errors sending control frames to dongle */
987 	ulong rx_packets;	/* Packets sent up the network interface */
988 	ulong rx_multicast;	/* Multicast packets sent up the network interface */
989 	ulong rx_errors;	/* Errors processing rx data packets */
990 	ulong rx_ctlpkts;	/* Control frames processed from dongle */
991 	ulong rx_ctlerrs;	/* Errors in processing rx control frames */
992 	ulong rx_dropped;	/* Packets dropped locally (no memory) */
993 	ulong rx_flushed;  /* Packets flushed due to unscheduled sendup thread */
994 	ulong wd_dpc_sched;   /* Number of times dhd dpc scheduled by watchdog timer */
995 	ulong rx_pktgetfail; /* Number of PKTGET failures in DHD on RX */
996 	ulong tx_pktgetfail; /* Number of PKTGET failures in DHD on TX */
997 	ulong rx_readahead_cnt;	/* Number of packets where header read-ahead was used. */
998 	ulong tx_realloc;	/* Number of tx packets we had to realloc for headroom */
999 	ulong fc_packets;       /* Number of flow control pkts recvd */
1000 	ulong tx_big_packets;	/* Dropped data packets that are larger than MAX_MTU_SZ */
1001 #ifdef DMAMAP_STATS
1002 	/* DMA Mapping statistics */
1003 	dma_stats_t dma_stats;
1004 #endif /* DMAMAP_STATS */
1005 
1006 	/* Last error return */
1007 	int bcmerror;
1008 	uint tickcnt;
1009 
1010 	/* Last error from dongle */
1011 	int dongle_error;
1012 
1013 	uint8 country_code[WLC_CNTRY_BUF_SZ];
1014 
1015 	/* Suspend disable flag and "in suspend" flag */
1016 	int suspend_disable_flag; /* "1" to disable all extra powersaving during suspend */
1017 	int in_suspend;			/* flag set to 1 when early suspend called */
1018 #ifdef PNO_SUPPORT
1019 	int pno_enable;			/* pno status : "1" is pno enable */
1020 	int pno_suspend;		/* pno suspend status : "1" is pno suspended */
1021 #endif /* PNO_SUPPORT */
1022 	/* DTIM skip value, default 0(or 1) means wake each DTIM
1023 	 * 3 means skip 2 DTIMs and wake up 3rd DTIM(9th beacon when AP DTIM is 3)
1024 	 */
1025 	int suspend_bcn_li_dtim;         /* bcn_li_dtim value in suspend mode */
1026 #ifdef PKT_FILTER_SUPPORT
1027 	int early_suspended;	/* Early suspend status */
1028 	int dhcp_in_progress;	/* DHCP period */
1029 #endif // endif
1030 
1031 	/* Pkt filter defination */
1032 	char * pktfilter[100];
1033 	int pktfilter_count;
1034 
1035 	wl_country_t dhd_cspec;		/* Current Locale info */
1036 #ifdef CUSTOM_COUNTRY_CODE
1037 	uint dhd_cflags;
1038 #endif /* CUSTOM_COUNTRY_CODE */
1039 #if defined(DHD_BLOB_EXISTENCE_CHECK)
1040 	bool is_blob;			/* Checking for existance of Blob file */
1041 #endif /* DHD_BLOB_EXISTENCE_CHECK */
1042 	bool force_country_change;
1043 	char eventmask[WL_EVENTING_MASK_LEN];
1044 	int	op_mode;				/* STA, HostAPD, WFD, SoftAP */
1045 
1046 /* Set this to 1 to use a seperate interface (p2p0) for p2p operations.
1047  *  For ICS MR1 releases it should be disable to be compatable with ICS MR1 Framework
1048  *  see target dhd-cdc-sdmmc-panda-cfg80211-icsmr1-gpl-debug in Makefile
1049  */
1050 /* #define WL_ENABLE_P2P_IF		1 */
1051 
1052 #if defined(OEM_ANDROID)
1053 	struct mutex wl_start_stop_lock; /* lock/unlock for Android start/stop */
1054 	struct mutex wl_softap_lock;		 /* lock/unlock for any SoftAP/STA settings */
1055 #endif /* defined(OEM_ANDROID) */
1056 
1057 #ifdef PROP_TXSTATUS
1058 	bool	wlfc_enabled;
1059 	int	wlfc_mode;
1060 	void*	wlfc_state;
1061 	/*
1062 	Mode in which the dhd flow control shall operate. Must be set before
1063 	traffic starts to the device.
1064 	0 - Do not do any proptxtstatus flow control
1065 	1 - Use implied credit from a packet status
1066 	2 - Use explicit credit
1067 	3 - Only AMPDU hostreorder used. no wlfc.
1068 	*/
1069 	uint8	proptxstatus_mode;
1070 	bool	proptxstatus_txoff;
1071 	bool	proptxstatus_module_ignore;
1072 	bool	proptxstatus_credit_ignore;
1073 	bool	proptxstatus_txstatus_ignore;
1074 
1075 	bool	wlfc_rxpkt_chk;
1076 #ifdef LIMIT_BORROW
1077 	bool wlfc_borrow_allowed;
1078 #endif /* LIMIT_BORROW */
1079 	/*
1080 	 * implement below functions in each platform if needed.
1081 	 */
1082 	/* platform specific function whether to skip flow control */
1083 	bool (*skip_fc)(void * dhdp, uint8 ifx);
1084 	/* platform specific function for wlfc_enable and wlfc_deinit */
1085 	void (*plat_init)(void *dhd);
1086 	void (*plat_deinit)(void *dhd);
1087 #ifdef DHD_WLFC_THREAD
1088 	bool                wlfc_thread_go;
1089 	struct task_struct* wlfc_thread;
1090 	wait_queue_head_t   wlfc_wqhead;
1091 #endif /* DHD_WLFC_THREAD */
1092 #endif /* PROP_TXSTATUS */
1093 #ifdef PNO_SUPPORT
1094 	void *pno_state;
1095 #endif // endif
1096 #ifdef RTT_SUPPORT
1097 	void *rtt_state;
1098 #endif // endif
1099 #ifdef ROAM_AP_ENV_DETECTION
1100 	bool	roam_env_detection;
1101 #endif // endif
1102 	bool	dongle_isolation;
1103 	bool	is_pcie_watchdog_reset;
1104 
1105 /* Begin - Variables to track Bus Errors */
1106 	bool	dongle_trap_occured;	/* flag for sending HANG event to upper layer */
1107 	bool	iovar_timeout_occured;	/* flag to indicate iovar resumed on timeout */
1108 	bool	is_sched_error;		/* flag to indicate timeout due to scheduling issue */
1109 #ifdef PCIE_FULL_DONGLE
1110 	bool	d3ack_timeout_occured;	/* flag to indicate d3ack resumed on timeout */
1111 	bool	livelock_occured;	/* flag to indicate livelock occured */
1112 	bool	pktid_audit_failed;	/* flag to indicate pktid audit failure */
1113 #endif /* PCIE_FULL_DONGLE */
1114 	bool	iface_op_failed;	/* flag to indicate interface operation failed */
1115 	bool	scan_timeout_occurred;	/* flag to indicate scan has timedout */
1116 	bool	scan_busy_occurred;	/* flag to indicate scan busy occurred */
1117 #ifdef BT_OVER_SDIO
1118 	bool	is_bt_recovery_required;
1119 #endif // endif
1120 	bool	smmu_fault_occurred;	/* flag to indicate SMMU Fault */
1121 	/*
1122 	 * Add any new variables to track Bus errors above
1123 	 * this line. Also ensure that the variable is
1124 	 * cleared from dhd_clear_bus_errors
1125 	 */
1126 /* End - Variables to track Bus Errors */
1127 
1128 	int   hang_was_sent;
1129 	int   hang_was_pending;
1130 	int   rxcnt_timeout;		/* counter rxcnt timeout to send HANG */
1131 	int   txcnt_timeout;		/* counter txcnt timeout to send HANG */
1132 #ifdef BCMPCIE
1133 	int   d3ackcnt_timeout;		/* counter d3ack timeout to send HANG */
1134 #endif /* BCMPCIE */
1135 	bool hang_report;		/* enable hang report by default */
1136 	uint16 hang_reason;		/* reason codes for HANG event */
1137 #if defined(DHD_HANG_SEND_UP_TEST)
1138 	uint req_hang_type;
1139 #endif /* DHD_HANG_SEND_UP_TEST */
1140 #if defined(CONFIG_BCM_DETECT_CONSECUTIVE_HANG)
1141 	uint hang_counts;
1142 #endif /* CONFIG_BCM_DETECT_CONSECUTIVE_HANG */
1143 #ifdef WLTDLS
1144 	bool tdls_enable;
1145 #endif // endif
1146 	struct reorder_info *reorder_bufs[WLHOST_REORDERDATA_MAXFLOWS];
1147 	#define WLC_IOCTL_MAXBUF_FWCAP	1024
1148 	char  fw_capabilities[WLC_IOCTL_MAXBUF_FWCAP];
1149 	#define MAXSKBPEND 1024
1150 	void *skbbuf[MAXSKBPEND];
1151 	uint32 store_idx;
1152 	uint32 sent_idx;
1153 #ifdef DHDTCPACK_SUPPRESS
1154 	uint8 tcpack_sup_mode;		/* TCPACK suppress mode */
1155 	void *tcpack_sup_module;	/* TCPACK suppress module */
1156 	uint32 tcpack_sup_ratio;
1157 	uint32 tcpack_sup_delay;
1158 #endif /* DHDTCPACK_SUPPRESS */
1159 #if defined(ARP_OFFLOAD_SUPPORT)
1160 	uint32 arp_version;
1161 #endif // endif
1162 #if defined(BCMSUP_4WAY_HANDSHAKE)
1163 	bool fw_4way_handshake;		/* Whether firmware will to do the 4way handshake. */
1164 #endif // endif
1165 #ifdef DEBUG_DPC_THREAD_WATCHDOG
1166 	bool dhd_bug_on;
1167 #endif /* DEBUG_DPC_THREAD_WATCHDOG */
1168 #ifdef CUSTOM_SET_CPUCORE
1169 	struct task_struct * current_dpc;
1170 	struct task_struct * current_rxf;
1171 	int chan_isvht80;
1172 #endif /* CUSTOM_SET_CPUCORE */
1173 
1174 	void    *sta_pool;          /* pre-allocated pool of sta objects */
1175 	void    *staid_allocator;   /* allocator of sta indexes */
1176 #ifdef PCIE_FULL_DONGLE
1177 	bool	flow_rings_inited;	/* set this flag after initializing flow rings */
1178 #endif /* PCIE_FULL_DONGLE */
1179 	void    *flowid_allocator;  /* unique flowid allocator */
1180 	void	*flow_ring_table;   /* flow ring table, include prot and bus info */
1181 	void	*if_flow_lkup;      /* per interface flowid lkup hash table */
1182 	void    *flowid_lock;       /* per os lock for flowid info protection */
1183 	void    *flowring_list_lock;       /* per os lock for flowring list protection */
1184 	uint8	max_multi_client_flow_rings;
1185 	uint8	multi_client_flow_rings;
1186 	uint32  num_flow_rings;
1187 	cumm_ctr_t cumm_ctr;        /* cumm queue length placeholder  */
1188 	cumm_ctr_t l2cumm_ctr;      /* level 2 cumm queue length placeholder */
1189 	uint32 d2h_sync_mode;       /* D2H DMA completion sync mode */
1190 	uint8  flow_prio_map[NUMPRIO];
1191 	uint8	flow_prio_map_type;
1192 	char enable_log[MAX_EVENT];
1193 	bool dma_d2h_ring_upd_support;
1194 	bool dma_h2d_ring_upd_support;
1195 	bool dma_ring_upd_overwrite;	/* host overwrites support setting */
1196 
1197 	bool hwa_enable;
1198 	uint hwa_inited;
1199 
1200 	bool idma_enable;
1201 	uint idma_inited;
1202 
1203 	bool ifrm_enable;			/* implicit frm enable */
1204 	uint ifrm_inited;			/* implicit frm init */
1205 
1206 	bool dar_enable;		/* use DAR registers */
1207 	uint dar_inited;
1208 
1209 	bool fast_delete_ring_support;		/* fast delete ring supported */
1210 
1211 #ifdef DHD_L2_FILTER
1212 	unsigned long l2_filter_cnt;	/* for L2_FILTER ARP table timeout */
1213 #endif /* DHD_L2_FILTER */
1214 #ifdef DHD_SSSR_DUMP
1215 	bool sssr_inited;
1216 	bool sssr_dump_collected;	/* Flag to indicate sssr dump is collected */
1217 	sssr_reg_info_v1_t sssr_reg_info;
1218 	uint8 *sssr_mempool;
1219 	uint *sssr_d11_before[MAX_NUM_D11CORES];
1220 	uint *sssr_d11_after[MAX_NUM_D11CORES];
1221 	bool sssr_d11_outofreset[MAX_NUM_D11CORES];
1222 	uint *sssr_dig_buf_before;
1223 	uint *sssr_dig_buf_after;
1224 	uint32 sssr_dump_mode;
1225 	bool collect_sssr;		/* Flag to indicate SSSR dump is required */
1226 #endif /* DHD_SSSR_DUMP */
1227 	uint8 *soc_ram;
1228 	uint32 soc_ram_length;
1229 	uint32 memdump_type;
1230 #ifdef DHD_RND_DEBUG
1231 	uint8 *rnd_buf;
1232 	uint32 rnd_len;
1233 #endif /* DHD_RND_DEBUG */
1234 #ifdef DHD_FW_COREDUMP
1235 	uint32 memdump_enabled;
1236 #ifdef DHD_DEBUG_UART
1237 	bool memdump_success;
1238 #endif	/* DHD_DEBUG_UART */
1239 #endif /* DHD_FW_COREDUMP */
1240 #ifdef PCIE_FULL_DONGLE
1241 #ifdef WLTDLS
1242 	tdls_peer_tbl_t peer_tbl;
1243 #endif /* WLTDLS */
1244 	uint8 tx_in_progress;
1245 #endif /* PCIE_FULL_DONGLE */
1246 #ifdef DHD_ULP
1247 	void *dhd_ulp;
1248 #endif // endif
1249 #ifdef WLTDLS
1250 	uint32 tdls_mode;
1251 #endif // endif
1252 #ifdef GSCAN_SUPPORT
1253 	bool lazy_roam_enable;
1254 #endif // endif
1255 #if defined(PKT_FILTER_SUPPORT) && defined(APF)
1256 	bool apf_set;
1257 #endif /* PKT_FILTER_SUPPORT && APF */
1258 	void *macdbg_info;
1259 #ifdef DHD_WET
1260 	void *wet_info;
1261 #endif // endif
1262 	bool	h2d_phase_supported;
1263 	bool	force_dongletrap_on_bad_h2d_phase;
1264 	uint32	dongle_trap_data;
1265 	fw_download_status_t	fw_download_status;
1266 	trap_t	last_trap_info; /* trap info from the last trap */
1267 	uint8 rand_mac_oui[DOT11_OUI_LEN];
1268 #ifdef DHD_LOSSLESS_ROAMING
1269 	uint8 dequeue_prec_map;
1270 	uint8 prio_8021x;
1271 #endif // endif
1272 #ifdef WL_NATOE
1273 	struct dhd_nfct_info *nfct;
1274 	spinlock_t nfct_lock;
1275 #endif /* WL_NATOE */
1276 	/* timesync link */
1277 	struct dhd_ts *ts;
1278 	bool	d2h_hostrdy_supported;
1279 #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
1280 	atomic_t block_bus;
1281 #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
1282 #if defined(DBG_PKT_MON) || defined(DHD_PKT_LOGGING)
1283 	bool d11_tx_status;
1284 #endif /* DBG_PKT_MON || DHD_PKT_LOGGING */
1285 	uint16 ndo_version;	/* ND offload version supported */
1286 #ifdef NDO_CONFIG_SUPPORT
1287 	bool ndo_enable;		/* ND offload feature enable */
1288 	bool ndo_host_ip_overflow;	/* # of host ip addr exceed FW capacity */
1289 	uint32 ndo_max_host_ip;		/* # of host ip addr supported by FW */
1290 #endif /* NDO_CONFIG_SUPPORT */
1291 #if defined(DHD_LOG_DUMP)
1292 	/* buffer to hold 'dhd dump' data before dumping to file */
1293 	uint8 *concise_dbg_buf;
1294 	uint64 last_file_posn;
1295 	int logdump_periodic_flush;
1296 	/* ecounter debug ring */
1297 #ifdef EWP_ECNTRS_LOGGING
1298 	void *ecntr_dbg_ring;
1299 #endif // endif
1300 #ifdef EWP_RTT_LOGGING
1301 	void *rtt_dbg_ring;
1302 #endif // endif
1303 #ifdef DNGL_EVENT_SUPPORT
1304 	uint8 health_chk_event_data[HEALTH_CHK_BUF_SIZE];
1305 #endif // endif
1306 	void *logdump_cookie;
1307 #endif /* DHD_LOG_DUMP */
1308 	uint32 dhd_console_ms; /** interval for polling the dongle for console (log) messages */
1309 	bool ext_trap_data_supported;
1310 	uint32 *extended_trap_data;
1311 #ifdef DUMP_IOCTL_IOV_LIST
1312 	/* dump iovar list */
1313 	dll_t dump_iovlist_head;
1314 	uint8 dump_iovlist_len;
1315 #endif /* DUMP_IOCTL_IOV_LIST */
1316 #ifdef CUSTOM_SET_ANTNPM
1317 	uint32 mimo_ant_set;
1318 #endif /* CUSTOM_SET_ANTNPM */
1319 #ifdef CUSTOM_SET_OCLOFF
1320 	bool ocl_off;
1321 #endif /* CUSTOM_SET_OCLOFF */
1322 #ifdef DHD_DEBUG
1323 	/* memwaste feature */
1324 	dll_t mw_list_head; /* memwaste list head */
1325 	uint32 mw_id; /* memwaste list unique id */
1326 #endif /* DHD_DEBUG */
1327 #ifdef WLTDLS
1328 	spinlock_t tdls_lock;
1329 #endif /* WLTDLS */
1330 	uint pcie_txs_metadata_enable;
1331 	uint wbtext_policy;	/* wbtext policy of dongle */
1332 	bool wbtext_support;	/* for product policy only */
1333 	bool max_dtim_enable;	/* use MAX bcn_li_dtim value in suspend mode */
1334 	tput_test_t tput_data;
1335 	uint64 tput_start_ts;
1336 	uint64 tput_stop_ts;
1337 #ifdef WL_MONITOR
1338 	bool monitor_enable;
1339 #endif // endif
1340 #ifdef DHD_PKT_LOGGING
1341 	struct dhd_pktlog *pktlog;
1342 	char debug_dump_time_pktlog_str[DEBUG_DUMP_TIME_BUF_LEN];
1343 #endif /* DHD_PKT_LOGGING */
1344 	uint dhd_watchdog_ms_backup;
1345 	void *event_log_filter;
1346 #ifdef WL_CFGVENDOR_SEND_HANG_EVENT
1347 	char *hang_info;
1348 	int hang_info_cnt;
1349 	char debug_dump_time_hang_str[DEBUG_DUMP_TIME_BUF_LEN];
1350 #endif /* WL_CFGVENDOR_SEND_HANG_EVENT */
1351 	char debug_dump_time_str[DEBUG_DUMP_TIME_BUF_LEN];
1352 	uint32 logset_prsrv_mask;
1353 	bool wl_event_enabled;
1354 	bool logtrace_pkt_sendup;
1355 #ifdef DHD_DUMP_MNGR
1356 	struct _dhd_dump_file_manage *dump_file_manage;
1357 #endif /* DHD_DUMP_MNGR */
1358 	int debug_dump_subcmd;
1359 	uint64 debug_dump_time_sec;
1360 	bool hscb_enable;
1361 	wait_queue_head_t tx_completion_wait;
1362 	uint32 batch_tx_pkts_cmpl;
1363 	uint32 batch_tx_num_pkts;
1364 #ifdef DHD_ERPOM
1365 	bool enable_erpom;
1366 	pom_func_handler_t pom_wlan_handler;
1367 	int (*pom_func_register)(pom_func_handler_t *func);
1368 	int (*pom_func_deregister)(pom_func_handler_t *func);
1369 	int (*pom_toggle_reg_on)(uchar func_id, uchar reason);
1370 #endif /* DHD_ERPOM */
1371 #ifdef EWP_EDL
1372 	bool dongle_edl_support;
1373 	dhd_dma_buf_t edl_ring_mem;
1374 #endif /* EWP_EDL */
1375 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
1376 	struct mutex ndev_op_sync;
1377 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) */
1378 
1379 	bool debug_buf_dest_support;
1380 	uint32 debug_buf_dest_stat[DEBUG_BUF_DEST_MAX];
1381 #if defined(DHD_H2D_LOG_TIME_SYNC)
1382 #define DHD_H2D_LOG_TIME_STAMP_MATCH	(10000) /* 10 Seconds */
1383 	/*
1384 	 * Interval for updating the dongle console message time stamp with the Host (DHD)
1385 	 * time stamp
1386 	 */
1387 	uint32 dhd_rte_time_sync_ms;
1388 #endif /* DHD_H2D_LOG_TIME_SYNC */
1389 	int wlc_ver_major;
1390 	int wlc_ver_minor;
1391 #ifdef DHD_STATUS_LOGGING
1392 	void *statlog;
1393 #endif /* DHD_STATUS_LOGGING */
1394 #ifdef DHD_HP2P
1395 	bool hp2p_enable;
1396 	bool hp2p_infra_enable;
1397 	bool hp2p_capable;
1398 	bool hp2p_ts_capable;
1399 	uint16 pkt_thresh;
1400 	uint16 time_thresh;
1401 	uint16 pkt_expiry;
1402 	hp2p_info_t hp2p_info[MAX_HP2P_FLOWS];
1403 	bool hp2p_ring_active;
1404 #endif /* D2H_HP2P */
1405 #ifdef DHD_DB0TS
1406 	bool db0ts_capable;
1407 #endif /* DHD_DB0TS */
1408 	bool event_log_max_sets_queried;
1409 	uint32 event_log_max_sets;
1410 	uint16 dhd_induce_error;
1411 #ifdef CONFIG_SILENT_ROAM
1412 	bool sroam_turn_on;	/* Silent roam monitor enable flags */
1413 	bool sroamed;		/* Silent roam monitor check flags */
1414 #endif /* CONFIG_SILENT_ROAM */
1415 	bool extdtxs_in_txcpl;
1416 	bool hostrdy_after_init;
1417 #ifdef SUPPORT_SET_TID
1418 	uint8 tid_mode;
1419 	uint32 target_uid;
1420 	uint8 target_tid;
1421 #endif /* SUPPORT_SET_TID */
1422 #ifdef DHD_PKTDUMP_ROAM
1423 	void *pktcnts;
1424 #endif /* DHD_PKTDUMP_ROAM */
1425 	bool disable_dtim_in_suspend;	/* Disable set bcn_li_dtim in suspend */
1426 #ifdef REVERSE_AIFSN
1427 	bool aifsn_reverse;
1428 #endif /* REVERSE_AIFSN */
1429 } dhd_pub_t;
1430 
1431 typedef struct {
1432 	uint rxwake;
1433 	uint rcwake;
1434 #ifdef DHD_WAKE_RX_STATUS
1435 	uint rx_bcast;
1436 	uint rx_arp;
1437 	uint rx_mcast;
1438 	uint rx_multi_ipv6;
1439 	uint rx_icmpv6;
1440 	uint rx_icmpv6_ra;
1441 	uint rx_icmpv6_na;
1442 	uint rx_icmpv6_ns;
1443 	uint rx_multi_ipv4;
1444 	uint rx_multi_other;
1445 	uint rx_ucast;
1446 #endif /* DHD_WAKE_RX_STATUS */
1447 #ifdef DHD_WAKE_EVENT_STATUS
1448 	uint rc_event[WLC_E_LAST];
1449 #endif /* DHD_WAKE_EVENT_STATUS */
1450 } wake_counts_t;
1451 
1452 #if defined(PCIE_FULL_DONGLE)
1453 
1454 /* Packet Tag for PCIE Full Dongle DHD */
1455 typedef struct dhd_pkttag_fd {
1456 	uint16    flowid;   /* Flowring Id */
1457 	uint16    ifid;
1458 #ifndef DHD_PCIE_PKTID
1459 	uint16    dma_len;  /* pkt len for DMA_MAP/UNMAP */
1460 	dmaaddr_t pa;       /* physical address */
1461 	void      *dmah;    /* dma mapper handle */
1462 	void      *secdma; /* secure dma sec_cma_info handle */
1463 #endif /* !DHD_PCIE_PKTID */
1464 #if defined(TX_STATUS_LATENCY_STATS)
1465 	uint64	   q_time_us; /* time when tx pkt queued to flowring */
1466 #endif // endif
1467 	uint16     flags;
1468 } dhd_pkttag_fd_t;
1469 
1470 /* Packet Tag for DHD PCIE Full Dongle */
1471 #define DHD_PKTTAG_FD(pkt)          ((dhd_pkttag_fd_t *)(PKTTAG(pkt)))
1472 
1473 #define DHD_PKT_GET_FLOWID(pkt)     ((DHD_PKTTAG_FD(pkt))->flowid)
1474 #define DHD_PKT_SET_FLOWID(pkt, pkt_flowid) \
1475 	DHD_PKTTAG_FD(pkt)->flowid = (uint16)(pkt_flowid)
1476 
1477 #define DHD_PKT_GET_DATAOFF(pkt)    ((DHD_PKTTAG_FD(pkt))->dataoff)
1478 #define DHD_PKT_SET_DATAOFF(pkt, pkt_dataoff) \
1479 	DHD_PKTTAG_FD(pkt)->dataoff = (uint16)(pkt_dataoff)
1480 
1481 #define DHD_PKT_GET_DMA_LEN(pkt)    ((DHD_PKTTAG_FD(pkt))->dma_len)
1482 #define DHD_PKT_SET_DMA_LEN(pkt, pkt_dma_len) \
1483 	DHD_PKTTAG_FD(pkt)->dma_len = (uint16)(pkt_dma_len)
1484 
1485 #define DHD_PKT_GET_PA(pkt)         ((DHD_PKTTAG_FD(pkt))->pa)
1486 #define DHD_PKT_SET_PA(pkt, pkt_pa) \
1487 	DHD_PKTTAG_FD(pkt)->pa = (dmaaddr_t)(pkt_pa)
1488 
1489 #define DHD_PKT_GET_DMAH(pkt)       ((DHD_PKTTAG_FD(pkt))->dmah)
1490 #define DHD_PKT_SET_DMAH(pkt, pkt_dmah) \
1491 	DHD_PKTTAG_FD(pkt)->dmah = (void *)(pkt_dmah)
1492 
1493 #define DHD_PKT_GET_SECDMA(pkt)    ((DHD_PKTTAG_FD(pkt))->secdma)
1494 #define DHD_PKT_SET_SECDMA(pkt, pkt_secdma) \
1495 	DHD_PKTTAG_FD(pkt)->secdma = (void *)(pkt_secdma)
1496 
1497 #if defined(TX_STATUS_LATENCY_STATS)
1498 #define DHD_PKT_GET_QTIME(pkt)    ((DHD_PKTTAG_FD(pkt))->q_time_us)
1499 #define DHD_PKT_SET_QTIME(pkt, pkt_q_time_us) \
1500 	DHD_PKTTAG_FD(pkt)->q_time_us = (uint64)(pkt_q_time_us)
1501 #endif // endif
1502 
1503 #define DHD_PKT_GET_FLAGS(pkt)    ((DHD_PKTTAG_FD(pkt))->flags)
1504 #define DHD_PKT_SET_FLAGS(pkt, pkt_flags) \
1505 	DHD_PKTTAG_FD(pkt)->flags = (uint16)(pkt_flags)
1506 
1507 #define PKTFLAG_NO_FWD	0x8000
1508 
1509 #define DHD_PKT_FLAGS_SET_NO_FWD(pkt) \
1510 	DHD_PKTTAG_FD(pkt)->flags |= PKTFLAG_NO_FWD
1511 #define DHD_PKT_FLAGS_CLEAR_NO_FWD(pkt) \
1512 	DHD_PKTTAG_FD(pkt)->flags &= ~PKTFLAG_NO_FWD
1513 #define DHD_PKT_FLAGS_IS_NO_FWD(pkt) \
1514 	(DHD_PKTTAG_FD(pkt)->flags & PKTFLAG_NO_FWD)
1515 
1516 #endif /* PCIE_FULL_DONGLE */
1517 
1518 #if defined(BCMWDF)
1519 typedef struct {
1520 	dhd_pub_t *dhd_pub;
1521 } dhd_workitem_context_t;
1522 
1523 WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(dhd_workitem_context_t, dhd_get_dhd_workitem_context)
1524 #endif /* (BCMWDF)  */
1525 
1526 	#if defined(CONFIG_PM_SLEEP)
1527 
1528 	#define DHD_PM_RESUME_WAIT_INIT(a) DECLARE_WAIT_QUEUE_HEAD(a);
1529 	#define _DHD_PM_RESUME_WAIT(a, b) do {\
1530 			int retry = 0; \
1531 			SMP_RD_BARRIER_DEPENDS(); \
1532 			while (dhd_mmc_suspend && retry++ != b) { \
1533 				SMP_RD_BARRIER_DEPENDS(); \
1534 				wait_event_interruptible_timeout(a, !dhd_mmc_suspend, 1); \
1535 			} \
1536 		} 	while (0)
1537 	#define DHD_PM_RESUME_WAIT(a) 		_DHD_PM_RESUME_WAIT(a, 200)
1538 	#define DHD_PM_RESUME_WAIT_FOREVER(a) 	_DHD_PM_RESUME_WAIT(a, ~0)
1539 	#define DHD_PM_RESUME_RETURN_ERROR(a)   do { \
1540 			if (dhd_mmc_suspend) { \
1541 				printf("%s[%d]: mmc is still in suspend state!!!\n", \
1542 					__FUNCTION__, __LINE__); \
1543 				return a; \
1544 			} \
1545 		} while (0)
1546 	#define DHD_PM_RESUME_RETURN		do { if (dhd_mmc_suspend) return; } while (0)
1547 
1548 	#define DHD_SPINWAIT_SLEEP_INIT(a) DECLARE_WAIT_QUEUE_HEAD(a);
1549 	#define SPINWAIT_SLEEP(a, exp, us) do { \
1550 		uint countdown = (us) + 9999; \
1551 		while ((exp) && (countdown >= 10000)) { \
1552 			wait_event_interruptible_timeout(a, FALSE, 1); \
1553 			countdown -= 10000; \
1554 		} \
1555 	} while (0)
1556 
1557 	#else
1558 
1559 	#define DHD_PM_RESUME_WAIT_INIT(a)
1560 	#define DHD_PM_RESUME_WAIT(a)
1561 	#define DHD_PM_RESUME_WAIT_FOREVER(a)
1562 	#define DHD_PM_RESUME_RETURN_ERROR(a)
1563 	#define DHD_PM_RESUME_RETURN
1564 
1565 	#define DHD_SPINWAIT_SLEEP_INIT(a)
1566 	#define SPINWAIT_SLEEP(a, exp, us)  do { \
1567 		uint countdown = (us) + 9; \
1568 		while ((exp) && (countdown >= 10)) { \
1569 			OSL_DELAY(10);  \
1570 			countdown -= 10;  \
1571 		} \
1572 	} while (0)
1573 
1574 	#endif /* CONFIG_PM_SLEEP */
1575 
1576 #ifndef OSL_SLEEP
1577 #define OSL_SLEEP(ms)		OSL_DELAY(ms*1000)
1578 #endif /* OSL_SLEEP */
1579 
1580 #define DHD_IF_VIF	0x01	/* Virtual IF (Hidden from user) */
1581 
1582 #ifdef PNO_SUPPORT
1583 int dhd_pno_clean(dhd_pub_t *dhd);
1584 #endif /* PNO_SUPPORT */
1585 
1586 /*
1587  *  Wake locks are an Android power management concept. They are used by applications and services
1588  *  to request CPU resources.
1589  */
1590 #if defined(OEM_ANDROID)
1591 extern int dhd_os_wake_lock(dhd_pub_t *pub);
1592 extern int dhd_os_wake_unlock(dhd_pub_t *pub);
1593 extern int dhd_os_wake_lock_waive(dhd_pub_t *pub);
1594 extern int dhd_os_wake_lock_restore(dhd_pub_t *pub);
1595 extern void dhd_event_wake_lock(dhd_pub_t *pub);
1596 extern void dhd_event_wake_unlock(dhd_pub_t *pub);
1597 extern void dhd_pm_wake_lock_timeout(dhd_pub_t *pub, int val);
1598 extern void dhd_pm_wake_unlock(dhd_pub_t *pub);
1599 extern void dhd_txfl_wake_lock_timeout(dhd_pub_t *pub, int val);
1600 extern void dhd_txfl_wake_unlock(dhd_pub_t *pub);
1601 extern int dhd_os_wake_lock_timeout(dhd_pub_t *pub);
1602 extern int dhd_os_wake_lock_rx_timeout_enable(dhd_pub_t *pub, int val);
1603 extern int dhd_os_wake_lock_ctrl_timeout_enable(dhd_pub_t *pub, int val);
1604 extern int dhd_os_wake_lock_ctrl_timeout_cancel(dhd_pub_t *pub);
1605 extern int dhd_os_wd_wake_lock(dhd_pub_t *pub);
1606 extern int dhd_os_wd_wake_unlock(dhd_pub_t *pub);
1607 extern void dhd_os_wake_lock_init(struct dhd_info *dhd);
1608 extern void dhd_os_wake_lock_destroy(struct dhd_info *dhd);
1609 #ifdef DHD_USE_SCAN_WAKELOCK
1610 extern void dhd_os_scan_wake_lock_timeout(dhd_pub_t *pub, int val);
1611 extern void dhd_os_scan_wake_unlock(dhd_pub_t *pub);
1612 #endif /* BCMPCIE_SCAN_WAKELOCK */
1613 
MUTEX_LOCK_SOFTAP_SET_INIT(dhd_pub_t * dhdp)1614 inline static void MUTEX_LOCK_SOFTAP_SET_INIT(dhd_pub_t * dhdp)
1615 {
1616 #if defined(OEM_ANDROID)
1617 	mutex_init(&dhdp->wl_softap_lock);
1618 #endif /* OEM_ANDROID */
1619 }
1620 
MUTEX_LOCK_SOFTAP_SET(dhd_pub_t * dhdp)1621 inline static void MUTEX_LOCK_SOFTAP_SET(dhd_pub_t * dhdp)
1622 {
1623 #if defined(OEM_ANDROID)
1624 	mutex_lock(&dhdp->wl_softap_lock);
1625 #endif /* OEM_ANDROID */
1626 }
1627 
MUTEX_UNLOCK_SOFTAP_SET(dhd_pub_t * dhdp)1628 inline static void MUTEX_UNLOCK_SOFTAP_SET(dhd_pub_t * dhdp)
1629 {
1630 #if defined(OEM_ANDROID)
1631 	mutex_unlock(&dhdp->wl_softap_lock);
1632 #endif /* OEM_ANDROID */
1633 }
1634 
1635 #ifdef DHD_DEBUG_WAKE_LOCK
1636 #define DHD_OS_WAKE_LOCK(pub) \
1637 	do { \
1638 		printf("call wake_lock: %s %d\n", \
1639 			__FUNCTION__, __LINE__); \
1640 		dhd_os_wake_lock(pub); \
1641 	} while (0)
1642 #define DHD_OS_WAKE_UNLOCK(pub) \
1643 	do { \
1644 		printf("call wake_unlock: %s %d\n", \
1645 			__FUNCTION__, __LINE__); \
1646 		dhd_os_wake_unlock(pub); \
1647 	} while (0)
1648 #define DHD_EVENT_WAKE_LOCK(pub) \
1649 	do { \
1650 		printf("call event wake_lock: %s %d\n", \
1651 			__FUNCTION__, __LINE__); \
1652 		dhd_event_wake_lock(pub); \
1653 	} while (0)
1654 #define DHD_EVENT_WAKE_UNLOCK(pub) \
1655 	do { \
1656 		printf("call event wake_unlock: %s %d\n", \
1657 			__FUNCTION__, __LINE__); \
1658 		dhd_event_wake_unlock(pub); \
1659 	} while (0)
1660 #define DHD_PM_WAKE_LOCK_TIMEOUT(pub, val) \
1661 	do { \
1662 		printf("call pm_wake_timeout enable\n"); \
1663 	dhd_pm_wake_lock_timeout(pub, val); \
1664 	} while (0)
1665 #define DHD_PM_WAKE_UNLOCK(pub) \
1666 	do { \
1667 		printf("call pm_wake unlock\n"); \
1668 	dhd_pm_wake_unlock(pub); \
1669 	} while (0)
1670 #define DHD_TXFL_WAKE_LOCK_TIMEOUT(pub, val) \
1671 	do { \
1672 		printf("call pm_wake_timeout enable\n"); \
1673 		dhd_txfl_wake_lock_timeout(pub, val); \
1674 	} while (0)
1675 #define DHD_TXFL_WAKE_UNLOCK(pub) \
1676 	do { \
1677 		printf("call pm_wake unlock\n"); \
1678 		dhd_txfl_wake_unlock(pub); \
1679 	} while (0)
1680 #define DHD_OS_WAKE_LOCK_TIMEOUT(pub) \
1681 	do { \
1682 		printf("call wake_lock_timeout: %s %d\n", \
1683 			__FUNCTION__, __LINE__); \
1684 		dhd_os_wake_lock_timeout(pub); \
1685 	} while (0)
1686 #define DHD_OS_WAKE_LOCK_RX_TIMEOUT_ENABLE(pub, val) \
1687 	do { \
1688 		printf("call wake_lock_rx_timeout_enable[%d]: %s %d\n", \
1689 			val, __FUNCTION__, __LINE__); \
1690 		dhd_os_wake_lock_rx_timeout_enable(pub, val); \
1691 	} while (0)
1692 #define DHD_OS_WAKE_LOCK_CTRL_TIMEOUT_ENABLE(pub, val) \
1693 	do { \
1694 		printf("call wake_lock_ctrl_timeout_enable[%d]: %s %d\n", \
1695 			val, __FUNCTION__, __LINE__); \
1696 		dhd_os_wake_lock_ctrl_timeout_enable(pub, val); \
1697 	} while (0)
1698 #define DHD_OS_WAKE_LOCK_CTRL_TIMEOUT_CANCEL(pub) \
1699 	do { \
1700 		printf("call wake_lock_ctrl_timeout_cancel: %s %d\n", \
1701 			__FUNCTION__, __LINE__); \
1702 		dhd_os_wake_lock_ctrl_timeout_cancel(pub); \
1703 	} while (0)
1704 #define DHD_OS_WAKE_LOCK_WAIVE(pub) \
1705 	do { \
1706 		printf("call wake_lock_waive: %s %d\n", \
1707 			__FUNCTION__, __LINE__); \
1708 		dhd_os_wake_lock_waive(pub); \
1709 	} while (0)
1710 #define DHD_OS_WAKE_LOCK_RESTORE(pub) \
1711 	do { \
1712 		printf("call wake_lock_restore: %s %d\n", \
1713 			__FUNCTION__, __LINE__); \
1714 		dhd_os_wake_lock_restore(pub); \
1715 	} while (0)
1716 #define DHD_OS_WAKE_LOCK_INIT(dhd) \
1717 	do { \
1718 		printf("call wake_lock_init: %s %d\n", \
1719 			__FUNCTION__, __LINE__); \
1720 		dhd_os_wake_lock_init(dhd); \
1721 	} while (0)
1722 #define DHD_OS_WAKE_LOCK_DESTROY(dhd) \
1723 	do { \
1724 		printf("call wake_lock_destroy: %s %d\n", \
1725 			__FUNCTION__, __LINE__); \
1726 		dhd_os_wake_lock_destroy(dhd); \
1727 	} while (0)
1728 #else
1729 #define DHD_OS_WAKE_LOCK(pub)			dhd_os_wake_lock(pub)
1730 #define DHD_OS_WAKE_UNLOCK(pub)		dhd_os_wake_unlock(pub)
1731 #define DHD_EVENT_WAKE_LOCK(pub)			dhd_event_wake_lock(pub)
1732 #define DHD_EVENT_WAKE_UNLOCK(pub)		dhd_event_wake_unlock(pub)
1733 #define DHD_PM_WAKE_LOCK_TIMEOUT(pub, val)  dhd_pm_wake_lock_timeout(pub, val)
1734 #define DHD_PM_WAKE_UNLOCK(pub) 			dhd_pm_wake_unlock(pub)
1735 #define DHD_TXFL_WAKE_LOCK_TIMEOUT(pub, val)	dhd_txfl_wake_lock_timeout(pub, val)
1736 #define DHD_TXFL_WAKE_UNLOCK(pub) 			dhd_txfl_wake_unlock(pub)
1737 #define DHD_OS_WAKE_LOCK_TIMEOUT(pub)		dhd_os_wake_lock_timeout(pub)
1738 #define DHD_OS_WAKE_LOCK_RX_TIMEOUT_ENABLE(pub, val) \
1739 	dhd_os_wake_lock_rx_timeout_enable(pub, val)
1740 #define DHD_OS_WAKE_LOCK_CTRL_TIMEOUT_ENABLE(pub, val) \
1741 	dhd_os_wake_lock_ctrl_timeout_enable(pub, val)
1742 #define DHD_OS_WAKE_LOCK_CTRL_TIMEOUT_CANCEL(pub) \
1743 	dhd_os_wake_lock_ctrl_timeout_cancel(pub)
1744 #define DHD_OS_WAKE_LOCK_WAIVE(pub)			dhd_os_wake_lock_waive(pub)
1745 #define DHD_OS_WAKE_LOCK_RESTORE(pub)		dhd_os_wake_lock_restore(pub)
1746 #define DHD_OS_WAKE_LOCK_INIT(dhd)		dhd_os_wake_lock_init(dhd);
1747 #define DHD_OS_WAKE_LOCK_DESTROY(dhd)		dhd_os_wake_lock_destroy(dhd);
1748 #endif /* DHD_DEBUG_WAKE_LOCK */
1749 
1750 #define DHD_OS_WD_WAKE_LOCK(pub)		dhd_os_wd_wake_lock(pub)
1751 #define DHD_OS_WD_WAKE_UNLOCK(pub)		dhd_os_wd_wake_unlock(pub)
1752 
1753 #ifdef DHD_USE_SCAN_WAKELOCK
1754 #ifdef DHD_DEBUG_SCAN_WAKELOCK
1755 #define DHD_OS_SCAN_WAKE_LOCK_TIMEOUT(pub, val) \
1756 	do { \
1757 		printf("call wake_lock_scan: %s %d\n", \
1758 			__FUNCTION__, __LINE__); \
1759 		dhd_os_scan_wake_lock_timeout(pub, val); \
1760 	} while (0)
1761 #define DHD_OS_SCAN_WAKE_UNLOCK(pub) \
1762 	do { \
1763 		printf("call wake_unlock_scan: %s %d\n", \
1764 			__FUNCTION__, __LINE__); \
1765 		dhd_os_scan_wake_unlock(pub); \
1766 	} while (0)
1767 #else
1768 #define DHD_OS_SCAN_WAKE_LOCK_TIMEOUT(pub, val)		dhd_os_scan_wake_lock_timeout(pub, val)
1769 #define DHD_OS_SCAN_WAKE_UNLOCK(pub)			dhd_os_scan_wake_unlock(pub)
1770 #endif /* DHD_DEBUG_SCAN_WAKELOCK */
1771 #else
1772 #define DHD_OS_SCAN_WAKE_LOCK_TIMEOUT(pub, val)
1773 #define DHD_OS_SCAN_WAKE_UNLOCK(pub)
1774 #endif /* DHD_USE_SCAN_WAKELOCK */
1775 
1776 #else
1777 
1778 /* Wake lock are used in Android only (until the Linux community accepts it) */
1779 #define DHD_OS_WAKE_LOCK(pub)
1780 #define DHD_OS_WAKE_UNLOCK(pub)
1781 #define DHD_EVENT_WAKE_LOCK(pub)
1782 #define DHD_EVENT_WAKE_UNLOCK(pub)
1783 #define DHD_PM_WAKE_LOCK_TIMEOUT(pub, val)
1784 #define DHD_PM_WAKE_UNLOCK(pub)
1785 #define DHD_TXFL_WAKE_LOCK_TIMEOUT(pub, val)
1786 #define DHD_TXFL_WAKE_UNLOCK(pub)
1787 #define DHD_OS_WD_WAKE_LOCK(pub)
1788 #define DHD_OS_WD_WAKE_UNLOCK(pub)
1789 #define DHD_OS_WAKE_LOCK_TIMEOUT(pub)
1790 #define DHD_OS_WAKE_LOCK_RX_TIMEOUT_ENABLE(pub, val)	UNUSED_PARAMETER(val)
1791 #define DHD_OS_WAKE_LOCK_CTRL_TIMEOUT_ENABLE(pub, val)	UNUSED_PARAMETER(val)
1792 #define DHD_OS_WAKE_LOCK_CTRL_TIMEOUT_CANCEL(pub, val)
1793 #define DHD_OS_WAKE_LOCK_WAIVE(pub)
1794 #define DHD_OS_WAKE_LOCK_RESTORE(pub)
1795 #define DHD_OS_SCAN_WAKE_LOCK_TIMEOUT(pub, val)
1796 #define DHD_OS_SCAN_WAKE_UNLOCK(pub)
1797 #define DHD_OS_WAKE_LOCK_INIT(dhd)
1798 #define DHD_OS_WAKE_LOCK_DESTROY(dhd)
1799 
1800 #endif // endif
1801 
1802 #ifdef BCMPCIE_OOB_HOST_WAKE
1803 #define OOB_WAKE_LOCK_TIMEOUT 500
1804 extern void dhd_os_oob_irq_wake_lock_timeout(dhd_pub_t *pub, int val);
1805 extern void dhd_os_oob_irq_wake_unlock(dhd_pub_t *pub);
1806 
1807 #define DHD_OS_OOB_IRQ_WAKE_LOCK_TIMEOUT(pub, val)	dhd_os_oob_irq_wake_lock_timeout(pub, val)
1808 #define DHD_OS_OOB_IRQ_WAKE_UNLOCK(pub)			dhd_os_oob_irq_wake_unlock(pub)
1809 #endif /* BCMPCIE_OOB_HOST_WAKE */
1810 
1811 #define DHD_PACKET_TIMEOUT_MS	500
1812 #define DHD_EVENT_TIMEOUT_MS	1500
1813 #define SCAN_WAKE_LOCK_TIMEOUT	10000
1814 #define MAX_TX_TIMEOUT			500
1815 
1816 /* Enum for IOCTL recieved status */
1817 typedef enum dhd_ioctl_recieved_status
1818 {
1819 	IOCTL_WAIT = 0,
1820 	IOCTL_RETURN_ON_SUCCESS,
1821 	IOCTL_RETURN_ON_TRAP,
1822 	IOCTL_RETURN_ON_BUS_STOP,
1823 	IOCTL_RETURN_ON_ERROR
1824 } dhd_ioctl_recieved_status_t;
1825 
1826 /* interface operations (register, remove) should be atomic, use this lock to prevent race
1827  * condition among wifi on/off and interface operation functions
1828  */
1829 void dhd_net_if_lock(struct net_device *dev);
1830 void dhd_net_if_unlock(struct net_device *dev);
1831 
1832 #if defined(MULTIPLE_SUPPLICANT)
1833 #if defined(OEM_ANDROID) && defined(BCMSDIO)
1834 extern struct mutex _dhd_sdio_mutex_lock_;
1835 #endif // endif
1836 #endif /* MULTIPLE_SUPPLICANT */
1837 
1838 typedef enum dhd_attach_states
1839 {
1840 	DHD_ATTACH_STATE_INIT = 0x0,
1841 	DHD_ATTACH_STATE_NET_ALLOC = 0x1,
1842 	DHD_ATTACH_STATE_DHD_ALLOC = 0x2,
1843 	DHD_ATTACH_STATE_ADD_IF = 0x4,
1844 	DHD_ATTACH_STATE_PROT_ATTACH = 0x8,
1845 	DHD_ATTACH_STATE_WL_ATTACH = 0x10,
1846 	DHD_ATTACH_STATE_THREADS_CREATED = 0x20,
1847 	DHD_ATTACH_STATE_WAKELOCKS_INIT = 0x40,
1848 	DHD_ATTACH_STATE_CFG80211 = 0x80,
1849 	DHD_ATTACH_STATE_EARLYSUSPEND_DONE = 0x100,
1850 	DHD_ATTACH_TIMESYNC_ATTACH_DONE = 0x200,
1851 	DHD_ATTACH_LOGTRACE_INIT = 0x400,
1852 	DHD_ATTACH_STATE_LB_ATTACH_DONE = 0x800,
1853 	DHD_ATTACH_STATE_DONE = 0x1000
1854 } dhd_attach_states_t;
1855 
1856 /* Value -1 means we are unsuccessful in creating the kthread. */
1857 #define DHD_PID_KT_INVALID 	-1
1858 /* Value -2 means we are unsuccessful in both creating the kthread and tasklet */
1859 #define DHD_PID_KT_TL_INVALID	-2
1860 
1861 /* default reporting period */
1862 #define ECOUNTERS_DEFAULT_PERIOD	0
1863 
1864 /* default number of reports. '0' indicates forever */
1865 #define ECOUNTERS_NUM_REPORTS		0
1866 
1867 typedef struct ecounters_cfg {
1868 	uint16 type;
1869 	uint16 if_slice_idx;
1870 	uint16 stats_rep;
1871 } ecounters_cfg_t;
1872 
1873 typedef struct event_ecounters_cfg {
1874 	uint16 event_id;
1875 	uint16 type;
1876 	uint16 if_slice_idx;
1877 	uint16 stats_rep;
1878 } event_ecounters_cfg_t;
1879 
1880 typedef struct ecountersv2_xtlv_list_elt {
1881 	/* Not quite the exact bcm_xtlv_t type as data could be pointing to other pieces in
1882 	 * memory at the time of parsing arguments.
1883 	 */
1884 	uint16 id;
1885 	uint16 len;
1886 	uint8 *data;
1887 	struct ecountersv2_xtlv_list_elt *next;
1888 } ecountersv2_xtlv_list_elt_t;
1889 
1890 typedef struct ecountersv2_processed_xtlv_list_elt {
1891 	uint8 *data;
1892 	struct ecountersv2_processed_xtlv_list_elt *next;
1893 } ecountersv2_processed_xtlv_list_elt;
1894 
1895 /*
1896  * Exported from dhd OS modules (dhd_linux/dhd_ndis)
1897  */
1898 
1899 /* Indication from bus module regarding presence/insertion of dongle.
1900  * Return dhd_pub_t pointer, used as handle to OS module in later calls.
1901  * Returned structure should have bus and prot pointers filled in.
1902  * bus_hdrlen specifies required headroom for bus module header.
1903  */
1904 extern dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen);
1905 extern int dhd_attach_net(dhd_pub_t *dhdp, bool need_rtnl_lock);
1906 #if defined(WLP2P) && defined(WL_CFG80211)
1907 /* To allow attach/detach calls corresponding to p2p0 interface  */
1908 extern int dhd_attach_p2p(dhd_pub_t *);
1909 extern int dhd_detach_p2p(dhd_pub_t *);
1910 #endif /* WLP2P && WL_CFG80211 */
1911 extern int dhd_register_if(dhd_pub_t *dhdp, int idx, bool need_rtnl_lock);
1912 #ifdef WL_VIF_SUPPORT
1913 extern int dhd_register_vif(dhd_pub_t *dhdp);
1914 #endif /* WL_VIF_SUPPORT */
1915 
1916 /* Indication from bus module regarding removal/absence of dongle */
1917 extern void dhd_detach(dhd_pub_t *dhdp);
1918 extern void dhd_free(dhd_pub_t *dhdp);
1919 extern void dhd_clear(dhd_pub_t *dhdp);
1920 
1921 /* Indication from bus module to change flow-control state */
1922 extern void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool on);
1923 
1924 /* Store the status of a connection attempt for later retrieval by an iovar */
1925 extern void dhd_store_conn_status(uint32 event, uint32 status, uint32 reason);
1926 
1927 extern bool dhd_prec_enq(dhd_pub_t *dhdp, struct pktq *q, void *pkt, int prec);
1928 
1929 extern void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *rxp, int numpkt, uint8 chan);
1930 
1931 /* Return pointer to interface name */
1932 extern char *dhd_ifname(dhd_pub_t *dhdp, int idx);
1933 
1934 #ifdef DHD_UCODE_DOWNLOAD
1935 /* Returns the ucode path */
1936 extern char *dhd_get_ucode_path(dhd_pub_t *dhdp);
1937 #endif /* DHD_UCODE_DOWNLOAD */
1938 
1939 /* Request scheduling of the bus dpc */
1940 extern void dhd_sched_dpc(dhd_pub_t *dhdp);
1941 
1942 /* Notify tx completion */
1943 extern void dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success);
1944 #ifdef DHD_4WAYM4_FAIL_DISCONNECT
1945 extern void dhd_eap_txcomplete(dhd_pub_t *dhdp, void *txp, bool success, int ifidx);
1946 extern void dhd_cleanup_m4_state_work(dhd_pub_t *dhdp, int ifidx);
1947 #endif /* DHD_4WAYM4_FAIL_DISCONNECT */
1948 
1949 #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
1950 extern void dhd_bus_wakeup_work(dhd_pub_t *dhdp);
1951 #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
1952 
1953 #define WIFI_FEATURE_INFRA              0x0001      /* Basic infrastructure mode        */
1954 #define WIFI_FEATURE_INFRA_5G           0x0002      /* Support for 5 GHz Band           */
1955 #define WIFI_FEATURE_HOTSPOT            0x0004      /* Support for GAS/ANQP             */
1956 #define WIFI_FEATURE_P2P                0x0008      /* Wifi-Direct                      */
1957 #define WIFI_FEATURE_SOFT_AP            0x0010      /* Soft AP                          */
1958 #define WIFI_FEATURE_GSCAN              0x0020      /* Google-Scan APIs                 */
1959 #define WIFI_FEATURE_NAN                0x0040      /* Neighbor Awareness Networking    */
1960 #define WIFI_FEATURE_D2D_RTT            0x0080      /* Device-to-device RTT             */
1961 #define WIFI_FEATURE_D2AP_RTT           0x0100      /* Device-to-AP RTT                 */
1962 #define WIFI_FEATURE_BATCH_SCAN         0x0200      /* Batched Scan (legacy)            */
1963 #define WIFI_FEATURE_PNO                0x0400      /* Preferred network offload        */
1964 #define WIFI_FEATURE_ADDITIONAL_STA     0x0800      /* Support for two STAs             */
1965 #define WIFI_FEATURE_TDLS               0x1000      /* Tunnel directed link setup       */
1966 #define WIFI_FEATURE_TDLS_OFFCHANNEL    0x2000      /* Support for TDLS off channel     */
1967 #define WIFI_FEATURE_EPR                0x4000      /* Enhanced power reporting         */
1968 #define WIFI_FEATURE_AP_STA             0x8000      /* Support for AP STA Concurrency   */
1969 #define WIFI_FEATURE_LINKSTAT           0x10000     /* Support for Linkstats            */
1970 #define WIFI_FEATURE_LOGGER             0x20000     /* WiFi Logger			*/
1971 #define WIFI_FEATURE_HAL_EPNO		0x40000	    /* WiFi PNO enhanced		*/
1972 #define WIFI_FEATURE_RSSI_MONITOR	0x80000     /* RSSI Monitor			*/
1973 #define WIFI_FEATURE_MKEEP_ALIVE        0x100000    /* WiFi mkeep_alive			*/
1974 #define WIFI_FEATURE_CONFIG_NDO         0x200000	/* ND offload configure             */
1975 #define WIFI_FEATURE_TX_TRANSMIT_POWER  0x400000	/* Capture Tx transmit power levels */
1976 #define WIFI_FEATURE_CONTROL_ROAMING    0x800000	/* Enable/Disable firmware roaming */
1977 #define WIFI_FEATURE_FILTER_IE          0x1000000	/* Probe req ie filter              */
1978 #define WIFI_FEATURE_SCAN_RAND          0x2000000	/* Support MAC & Prb SN randomization */
1979 #define WIFI_FEATURE_SET_TX_POWER_LIMIT 0x4000000      /* Support Tx Power Limit setting */
1980 #define WIFI_FEATURE_USE_BODY_HEAD_SAR  0x8000000      /* Body/Head Proximity for SAR */
1981 #define WIFI_FEATURE_SET_LATENCY_MODE   0x40000000     /* Support Latency mode setting */
1982 #define WIFI_FEATURE_P2P_RAND_MAC       0x80000000     /* Support P2P MAC randomization */
1983 #define WIFI_FEATURE_INVALID            0xFFFFFFFF	/* Invalid Feature                  */
1984 
1985 #define MAX_FEATURE_SET_CONCURRRENT_GROUPS  3
1986 
1987 extern int dhd_dev_get_feature_set(struct net_device *dev);
1988 extern int dhd_dev_get_feature_set_matrix(struct net_device *dev, int num);
1989 extern int dhd_dev_cfg_rand_mac_oui(struct net_device *dev, uint8 *oui);
1990 #ifdef CUSTOM_FORCE_NODFS_FLAG
1991 extern int dhd_dev_set_nodfs(struct net_device *dev, uint nodfs);
1992 #endif /* CUSTOM_FORCE_NODFS_FLAG */
1993 #ifdef NDO_CONFIG_SUPPORT
1994 #ifndef NDO_MAX_HOST_IP_ENTRIES
1995 #define NDO_MAX_HOST_IP_ENTRIES	10
1996 #endif /* NDO_MAX_HOST_IP_ENTRIES */
1997 
1998 extern int dhd_dev_ndo_cfg(struct net_device *dev, u8 enable);
1999 extern int dhd_dev_ndo_update_inet6addr(struct net_device * dev);
2000 #endif /* NDO_CONFIG_SUPPORT */
2001 extern int dhd_set_rand_mac_oui(dhd_pub_t *dhd);
2002 #ifdef GSCAN_SUPPORT
2003 extern int dhd_dev_set_lazy_roam_cfg(struct net_device *dev,
2004              wlc_roam_exp_params_t *roam_param);
2005 extern int dhd_dev_lazy_roam_enable(struct net_device *dev, uint32 enable);
2006 extern int dhd_dev_set_lazy_roam_bssid_pref(struct net_device *dev,
2007        wl_bssid_pref_cfg_t *bssid_pref, uint32 flush);
2008 #endif /* GSCAN_SUPPORT */
2009 #if defined(GSCAN_SUPPORT) || defined(ROAMEXP_SUPPORT)
2010 extern int dhd_dev_set_blacklist_bssid(struct net_device *dev, maclist_t *blacklist,
2011     uint32 len, uint32 flush);
2012 extern int dhd_dev_set_whitelist_ssid(struct net_device *dev, wl_ssid_whitelist_t *whitelist,
2013     uint32 len, uint32 flush);
2014 #endif /* GSCAN_SUPPORT || ROAMEXP_SUPPORT */
2015 
2016 /* OS independent layer functions */
2017 extern void dhd_os_dhdiovar_lock(dhd_pub_t *pub);
2018 extern void dhd_os_dhdiovar_unlock(dhd_pub_t *pub);
2019 void dhd_os_logdump_lock(dhd_pub_t *pub);
2020 void dhd_os_logdump_unlock(dhd_pub_t *pub);
2021 extern int dhd_os_proto_block(dhd_pub_t * pub);
2022 extern int dhd_os_proto_unblock(dhd_pub_t * pub);
2023 extern int dhd_os_ioctl_resp_wait(dhd_pub_t * pub, uint * condition);
2024 extern int dhd_os_ioctl_resp_wake(dhd_pub_t * pub);
2025 extern unsigned int dhd_os_get_ioctl_resp_timeout(void);
2026 extern void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec);
2027 extern void dhd_os_ioctl_resp_lock(dhd_pub_t * pub);
2028 extern void dhd_os_ioctl_resp_unlock(dhd_pub_t * pub);
2029 #ifdef PCIE_FULL_DONGLE
2030 extern void dhd_wakeup_ioctl_event(dhd_pub_t *pub, dhd_ioctl_recieved_status_t reason);
2031 #else
dhd_wakeup_ioctl_event(dhd_pub_t * pub,dhd_ioctl_recieved_status_t reason)2032 static INLINE void dhd_wakeup_ioctl_event(dhd_pub_t *pub, dhd_ioctl_recieved_status_t reason)
2033 { printf("%s is NOT implemented for SDIO", __FUNCTION__); return; }
2034 #endif // endif
2035 #ifdef SHOW_LOGTRACE
2036 /* Bound and delay are fine tuned after several experiments and these
2037  * are the best case values to handle bombarding of console logs.
2038  */
2039 #define DHD_EVENT_LOGTRACE_BOUND 10
2040 /* since FW has event log rate health check (EVENT_LOG_RATE_HC) we can reduce
2041  * the reschedule delay to 10ms
2042 */
2043 #define DHD_EVENT_LOGTRACE_RESCHEDULE_DELAY_MS 10u
2044 extern int dhd_os_read_file(void *file, char *buf, uint32 size);
2045 extern int dhd_os_seek_file(void *file, int64 offset);
2046 void dhd_sendup_info_buf(dhd_pub_t *dhdp, uint8 *msg);
2047 #endif /* SHOW_LOGTRACE */
2048 int dhd_os_write_file_posn(void *fp, unsigned long *posn,
2049 		void *buf, unsigned long buflen);
2050 int dhd_msix_message_set(dhd_pub_t *dhdp, uint table_entry,
2051     uint message_number, bool unmask);
2052 
2053 extern void
2054 dhd_pcie_dump_core_regs(dhd_pub_t * pub, uint32 index, uint32 first_addr, uint32 last_addr);
2055 extern void wl_dhdpcie_dump_regs(void * context);
2056 
2057 extern int dhd_os_get_image_block(char * buf, int len, void * image);
2058 extern int dhd_os_get_image_size(void * image);
2059 #if defined(BT_OVER_SDIO)
2060 extern int dhd_os_gets_image(dhd_pub_t *pub, char *str, int len, void *image);
2061 extern void dhdsdio_bus_usr_cnt_inc(dhd_pub_t *pub);
2062 extern void dhdsdio_bus_usr_cnt_dec(dhd_pub_t *pub);
2063 #endif /* (BT_OVER_SDIO) */
2064 extern void *dhd_os_open_image1(dhd_pub_t *pub, char *filename); /* rev1 function signature */
2065 extern void dhd_os_close_image1(dhd_pub_t *pub, void *image);
2066 extern void dhd_os_wd_timer(void *bus, uint wdtick);
2067 #ifdef DHD_PCIE_RUNTIMEPM
2068 extern void dhd_os_runtimepm_timer(void *bus, uint tick);
2069 #endif /* DHD_PCIE_RUNTIMEPM */
2070 extern void dhd_os_sdlock(dhd_pub_t * pub);
2071 extern void dhd_os_sdunlock(dhd_pub_t * pub);
2072 extern void dhd_os_sdlock_txq(dhd_pub_t * pub);
2073 extern void dhd_os_sdunlock_txq(dhd_pub_t * pub);
2074 extern void dhd_os_sdlock_rxq(dhd_pub_t * pub);
2075 extern void dhd_os_sdunlock_rxq(dhd_pub_t * pub);
2076 extern void dhd_os_sdlock_sndup_rxq(dhd_pub_t * pub);
2077 extern void dhd_os_tracelog(const char *format, ...);
2078 #ifdef DHDTCPACK_SUPPRESS
2079 extern unsigned long dhd_os_tcpacklock(dhd_pub_t *pub);
2080 extern void dhd_os_tcpackunlock(dhd_pub_t *pub, unsigned long flags);
2081 #endif /* DHDTCPACK_SUPPRESS */
2082 
2083 extern int dhd_customer_oob_irq_map(void *adapter, unsigned long *irq_flags_ptr);
2084 extern int dhd_customer_gpio_wlan_ctrl(void *adapter, int onoff);
2085 extern int dhd_custom_get_mac_address(void *adapter, unsigned char *buf);
2086 #if defined(CUSTOM_COUNTRY_CODE)
2087 extern void get_customized_country_code(void *adapter, char *country_iso_code,
2088 	wl_country_t *cspec, u32 flags);
2089 #else
2090 extern void get_customized_country_code(void *adapter, char *country_iso_code, wl_country_t *cspec);
2091 #endif /* CUSTOM_COUNTRY_CODE */
2092 extern void dhd_os_sdunlock_sndup_rxq(dhd_pub_t * pub);
2093 extern void dhd_os_sdlock_eventq(dhd_pub_t * pub);
2094 extern void dhd_os_sdunlock_eventq(dhd_pub_t * pub);
2095 extern bool dhd_os_check_hang(dhd_pub_t *dhdp, int ifidx, int ret);
2096 extern int dhd_os_send_hang_message(dhd_pub_t *dhdp);
2097 extern void dhd_set_version_info(dhd_pub_t *pub, char *fw);
2098 extern bool dhd_os_check_if_up(dhd_pub_t *pub);
2099 extern int dhd_os_check_wakelock(dhd_pub_t *pub);
2100 extern int dhd_os_check_wakelock_all(dhd_pub_t *pub);
2101 extern int dhd_get_instance(dhd_pub_t *pub);
2102 #ifdef CUSTOM_SET_CPUCORE
2103 extern void dhd_set_cpucore(dhd_pub_t *dhd, int set);
2104 #endif /* CUSTOM_SET_CPUCORE */
2105 
2106 #if defined(KEEP_ALIVE)
2107 extern int dhd_keep_alive_onoff(dhd_pub_t *dhd);
2108 #endif /* KEEP_ALIVE */
2109 
2110 #if defined(DHD_FW_COREDUMP)
2111 void dhd_schedule_memdump(dhd_pub_t *dhdp, uint8 *buf, uint32 size);
2112 #endif /* DHD_FW_COREDUMP */
2113 
2114 void dhd_write_sssr_dump(dhd_pub_t *dhdp, uint32 dump_mode);
2115 #ifdef DNGL_AXI_ERROR_LOGGING
2116 void dhd_schedule_axi_error_dump(dhd_pub_t *dhdp, void *type);
2117 #endif /* DNGL_AXI_ERROR_LOGGING */
2118 #ifdef BCMPCIE
2119 void dhd_schedule_cto_recovery(dhd_pub_t *dhdp);
2120 #endif /* BCMPCIE */
2121 
2122 #ifdef PKT_FILTER_SUPPORT
2123 #define DHD_UNICAST_FILTER_NUM		0
2124 #define DHD_BROADCAST_FILTER_NUM	1
2125 #define DHD_MULTICAST4_FILTER_NUM	2
2126 #define DHD_MULTICAST6_FILTER_NUM	3
2127 #define DHD_MDNS_FILTER_NUM		4
2128 #define DHD_ARP_FILTER_NUM		5
2129 #define DHD_BROADCAST_ARP_FILTER_NUM	6
2130 #define DHD_IP4BCAST_DROP_FILTER_NUM	7
2131 #define DHD_LLC_STP_DROP_FILTER_NUM	8
2132 #define DHD_LLC_XID_DROP_FILTER_NUM	9
2133 #define DISCARD_IPV4_MCAST	"102 1 6 IP4_H:16 0xf0 0xe0"
2134 #define DISCARD_IPV6_MCAST	"103 1 6 IP6_H:24 0xff 0xff"
2135 #define DISCARD_IPV4_BCAST	"107 1 6 IP4_H:16 0xffffffff 0xffffffff"
2136 #define DISCARD_LLC_STP		"108 1 6 ETH_H:14 0xFFFFFFFFFFFF 0xAAAA0300000C"
2137 #define DISCARD_LLC_XID		"109 1 6 ETH_H:14 0xFFFFFF 0x0001AF"
2138 extern int dhd_os_enable_packet_filter(dhd_pub_t *dhdp, int val);
2139 extern void dhd_enable_packet_filter(int value, dhd_pub_t *dhd);
2140 extern int dhd_packet_filter_add_remove(dhd_pub_t *dhdp, int add_remove, int num);
2141 extern int net_os_enable_packet_filter(struct net_device *dev, int val);
2142 extern int net_os_rxfilter_add_remove(struct net_device *dev, int val, int num);
2143 
2144 #define MAX_PKTFLT_BUF_SIZE		2048
2145 #define MAX_PKTFLT_FIXED_PATTERN_SIZE	32
2146 #define MAX_PKTFLT_FIXED_BUF_SIZE	\
2147 	(WL_PKT_FILTER_FIXED_LEN + MAX_PKTFLT_FIXED_PATTERN_SIZE * 2)
2148 #define MAXPKT_ARG	16
2149 #endif /* PKT_FILTER_SUPPORT */
2150 
2151 #if defined(OEM_ANDROID) && defined(BCMPCIE)
2152 extern int dhd_get_suspend_bcn_li_dtim(dhd_pub_t *dhd, int *dtim_period, int *bcn_interval);
2153 #else
2154 extern int dhd_get_suspend_bcn_li_dtim(dhd_pub_t *dhd);
2155 #endif /* OEM_ANDROID && BCMPCIE */
2156 
2157 extern bool dhd_support_sta_mode(dhd_pub_t *dhd);
2158 extern int write_to_file(dhd_pub_t *dhd, uint8 *buf, int size);
2159 
2160 #ifdef RSSI_MONITOR_SUPPORT
2161 extern int dhd_dev_set_rssi_monitor_cfg(struct net_device *dev, int start,
2162              int8 max_rssi, int8 min_rssi);
2163 #endif /* RSSI_MONITOR_SUPPORT */
2164 
2165 #ifdef DHDTCPACK_SUPPRESS
2166 int dhd_dev_set_tcpack_sup_mode_cfg(struct net_device *dev, uint8 enable);
2167 #endif /* DHDTCPACK_SUPPRESS */
2168 
2169 #define DHD_RSSI_MONITOR_EVT_VERSION   1
2170 typedef struct {
2171 	uint8 version;
2172 	int8 cur_rssi;
2173 	struct ether_addr BSSID;
2174 } dhd_rssi_monitor_evt_t;
2175 
2176 typedef struct {
2177 	uint32 limit;		/* Expiration time (usec) */
2178 	uint32 increment;	/* Current expiration increment (usec) */
2179 	uint32 elapsed;		/* Current elapsed time (usec) */
2180 	uint32 tick;		/* O/S tick time (usec) */
2181 } dhd_timeout_t;
2182 
2183 #ifdef SHOW_LOGTRACE
2184 typedef struct {
2185 	uint  num_fmts;
2186 	char **fmts;
2187 	char *raw_fmts;
2188 	char *raw_sstr;
2189 	uint32 fmts_size;
2190 	uint32 raw_fmts_size;
2191 	uint32 raw_sstr_size;
2192 	uint32 ramstart;
2193 	uint32 rodata_start;
2194 	uint32 rodata_end;
2195 	char *rom_raw_sstr;
2196 	uint32 rom_raw_sstr_size;
2197 	uint32 rom_ramstart;
2198 	uint32 rom_rodata_start;
2199 	uint32 rom_rodata_end;
2200 } dhd_event_log_t;
2201 #endif /* SHOW_LOGTRACE */
2202 
2203 #ifdef KEEP_ALIVE
2204 extern int dhd_dev_start_mkeep_alive(dhd_pub_t *dhd_pub, uint8 mkeep_alive_id, uint8 *ip_pkt,
2205 	uint16 ip_pkt_len, uint8* src_mac_addr, uint8* dst_mac_addr, uint32 period_msec);
2206 extern int dhd_dev_stop_mkeep_alive(dhd_pub_t *dhd_pub, uint8 mkeep_alive_id);
2207 #endif /* KEEP_ALIVE */
2208 
2209 #if defined(PKT_FILTER_SUPPORT) && defined(APF)
2210 /*
2211  * As per Google's current implementation, there will be only one APF filter.
2212  * Therefore, userspace doesn't bother about filter id and because of that
2213  * DHD has to manage the filter id.
2214  */
2215 #define PKT_FILTER_APF_ID		200
2216 #define DHD_APF_LOCK(ndev)		dhd_apf_lock(ndev)
2217 #define DHD_APF_UNLOCK(ndev)		dhd_apf_unlock(ndev)
2218 
2219 extern void dhd_apf_lock(struct net_device *dev);
2220 extern void dhd_apf_unlock(struct net_device *dev);
2221 extern int dhd_dev_apf_get_version(struct net_device *ndev, uint32 *version);
2222 extern int dhd_dev_apf_get_max_len(struct net_device *ndev, uint32 *max_len);
2223 extern int dhd_dev_apf_add_filter(struct net_device *ndev, u8* program,
2224 	uint32 program_len);
2225 extern int dhd_dev_apf_enable_filter(struct net_device *ndev);
2226 extern int dhd_dev_apf_disable_filter(struct net_device *ndev);
2227 extern int dhd_dev_apf_delete_filter(struct net_device *ndev);
2228 #endif /* PKT_FILTER_SUPPORT && APF */
2229 
2230 extern void dhd_timeout_start(dhd_timeout_t *tmo, uint usec);
2231 extern int dhd_timeout_expired(dhd_timeout_t *tmo);
2232 
2233 extern int dhd_ifname2idx(struct dhd_info *dhd, char *name);
2234 extern int dhd_net2idx(struct dhd_info *dhd, struct net_device *net);
2235 extern struct net_device * dhd_idx2net(void *pub, int ifidx);
2236 extern int net_os_send_hang_message(struct net_device *dev);
2237 extern int net_os_send_hang_message_reason(struct net_device *dev, const char *string_num);
2238 extern bool dhd_wowl_cap(void *bus);
2239 extern int wl_host_event(dhd_pub_t *dhd_pub, int *idx, void *pktdata, uint pktlen,
2240 	wl_event_msg_t *, void **data_ptr,  void *);
2241 extern int wl_process_host_event(dhd_pub_t *dhd_pub, int *idx, void *pktdata, uint pktlen,
2242 	wl_event_msg_t *, void **data_ptr,  void *);
2243 extern void wl_event_to_host_order(wl_event_msg_t * evt);
2244 extern int wl_host_event_get_data(void *pktdata, uint pktlen, bcm_event_msg_u_t *evu);
2245 extern int dhd_wl_ioctl(dhd_pub_t *dhd_pub, int ifindex, wl_ioctl_t *ioc, void *buf, int len);
2246 extern int dhd_wl_ioctl_cmd(dhd_pub_t *dhd_pub, int cmd, void *arg, int len, uint8 set,
2247                             int ifindex);
2248 extern int dhd_wl_ioctl_get_intiovar(dhd_pub_t *dhd_pub, char *name, uint *pval,
2249 	int cmd, uint8 set, int ifidx);
2250 extern int dhd_wl_ioctl_set_intiovar(dhd_pub_t *dhd_pub, char *name, uint val,
2251 	int cmd, uint8 set, int ifidx);
2252 extern void dhd_common_init(osl_t *osh);
2253 
2254 extern int dhd_do_driver_init(struct net_device *net);
2255 extern int dhd_event_ifadd(struct dhd_info *dhd, struct wl_event_data_if *ifevent,
2256 	char *name, uint8 *mac);
2257 extern int dhd_event_ifdel(struct dhd_info *dhd, struct wl_event_data_if *ifevent,
2258 	char *name, uint8 *mac);
2259 extern int dhd_event_ifchange(struct dhd_info *dhd, struct wl_event_data_if *ifevent,
2260        char *name, uint8 *mac);
2261 extern struct net_device* dhd_allocate_if(dhd_pub_t *dhdpub, int ifidx, const char *name,
2262 	uint8 *mac, uint8 bssidx, bool need_rtnl_lock, const char *dngl_name);
2263 extern int dhd_remove_if(dhd_pub_t *dhdpub, int ifidx, bool need_rtnl_lock);
2264 #ifdef WL_STATIC_IF
2265 extern s32 dhd_update_iflist_info(dhd_pub_t *dhdp, struct net_device *ndev, int ifidx,
2266 	uint8 *mac, uint8 bssidx, const char *dngl_name, int if_state);
2267 #endif /* WL_STATIC_IF */
2268 extern void dhd_vif_add(struct dhd_info *dhd, int ifidx, char * name);
2269 extern void dhd_vif_del(struct dhd_info *dhd, int ifidx);
2270 extern void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx);
2271 extern void dhd_vif_sendup(struct dhd_info *dhd, int ifidx, uchar *cp, int len);
2272 
2273 #ifdef WL_NATOE
2274 extern int dhd_natoe_ct_event(dhd_pub_t *dhd, char *data);
2275 #endif /* WL_NATOE */
2276 
2277 /* Send packet to dongle via data channel */
2278 extern int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pkt);
2279 
2280 /* send up locally generated event */
2281 extern void dhd_sendup_event_common(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data);
2282 /* Send event to host */
2283 extern void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data);
2284 #ifdef LOG_INTO_TCPDUMP
2285 extern void dhd_sendup_log(dhd_pub_t *dhdp, void *data, int len);
2286 #endif /* LOG_INTO_TCPDUMP */
2287 #ifdef SHOW_LOGTRACE
2288 void dhd_sendup_info_buf(dhd_pub_t *dhdp, uint8 *msg);
2289 #endif // endif
2290 extern int dhd_bus_devreset(dhd_pub_t *dhdp, uint8 flag);
2291 extern uint dhd_bus_status(dhd_pub_t *dhdp);
2292 extern int  dhd_bus_start(dhd_pub_t *dhdp);
2293 extern int dhd_bus_suspend(dhd_pub_t *dhdpub);
2294 extern int dhd_bus_resume(dhd_pub_t *dhdpub, int stage);
2295 extern int dhd_bus_membytes(dhd_pub_t *dhdp, bool set, uint32 address, uint8 *data, uint size);
2296 extern void dhd_print_buf(void *pbuf, int len, int bytes_per_line);
2297 extern bool dhd_is_associated(dhd_pub_t *dhd, uint8 ifidx, int *retval);
2298 #if defined(BCMSDIO) || defined(BCMPCIE)
2299 extern uint dhd_bus_chip_id(dhd_pub_t *dhdp);
2300 extern uint dhd_bus_chiprev_id(dhd_pub_t *dhdp);
2301 extern uint dhd_bus_chippkg_id(dhd_pub_t *dhdp);
2302 #ifdef DHD_MAP_CHIP_FIRMWARE_PATH
2303 extern uint dhd_bus_chipmodule_id(dhd_pub_t *dhdp);
2304 #endif /* DHD_MAP_CHIP_FIRMWARE_PATH */
2305 #endif /* defined(BCMSDIO) || defined(BCMPCIE) */
2306 int dhd_bus_get_fw_mode(dhd_pub_t *dhdp);
2307 
2308 #if defined(KEEP_ALIVE)
2309 extern int dhd_keep_alive_onoff(dhd_pub_t *dhd);
2310 #endif /* KEEP_ALIVE */
2311 
2312 /* OS spin lock API */
2313 extern void *dhd_os_spin_lock_init(osl_t *osh);
2314 extern void dhd_os_spin_lock_deinit(osl_t *osh, void *lock);
2315 extern unsigned long dhd_os_spin_lock(void *lock);
2316 void dhd_os_spin_unlock(void *lock, unsigned long flags);
2317 
2318 /* linux is defined for DHD EFI builds also,
2319 * since its cross-compiled for EFI from linux.
2320 * dbgring_lock apis are meant only for linux
2321 * to use mutexes, other OSes will continue to
2322 * use dhd_os_spin_lock
2323 */
2324 void *dhd_os_dbgring_lock_init(osl_t *osh);
2325 void dhd_os_dbgring_lock_deinit(osl_t *osh, void *mtx);
2326 unsigned long dhd_os_dbgring_lock(void *lock);
2327 void dhd_os_dbgring_unlock(void *lock, unsigned long flags);
2328 
dhd_os_tput_test_wait(dhd_pub_t * pub,uint * condition,uint timeout_ms)2329 static INLINE int dhd_os_tput_test_wait(dhd_pub_t *pub, uint *condition,
2330 		uint timeout_ms)
2331 { return 0; }
dhd_os_tput_test_wake(dhd_pub_t * pub)2332 static INLINE int dhd_os_tput_test_wake(dhd_pub_t * pub)
2333 { return 0; }
2334 
2335 extern int dhd_os_busbusy_wait_negation(dhd_pub_t * pub, uint * condition);
2336 extern int dhd_os_busbusy_wake(dhd_pub_t * pub);
2337 extern void dhd_os_tx_completion_wake(dhd_pub_t *dhd);
2338 extern int dhd_os_busbusy_wait_condition(dhd_pub_t *pub, uint *var, uint condition);
2339 int dhd_os_busbusy_wait_bitmask(dhd_pub_t *pub, uint *var,
2340 		uint bitmask, uint condition);
2341 extern int dhd_os_d3ack_wait(dhd_pub_t * pub, uint * condition);
2342 extern int dhd_os_d3ack_wake(dhd_pub_t * pub);
2343 extern int dhd_os_dmaxfer_wait(dhd_pub_t *pub, uint *condition);
2344 extern int dhd_os_dmaxfer_wake(dhd_pub_t *pub);
2345 
2346 /*
2347  * Manage sta objects in an interface. Interface is identified by an ifindex and
2348  * sta(s) within an interfaces are managed using a MacAddress of the sta.
2349  */
2350 struct dhd_sta;
2351 extern bool dhd_sta_associated(dhd_pub_t *dhdp, uint32 bssidx, uint8 *mac);
2352 extern struct dhd_sta *dhd_find_sta(void *pub, int ifidx, void *ea);
2353 extern struct dhd_sta *dhd_findadd_sta(void *pub, int ifidx, void *ea);
2354 extern void dhd_del_all_sta(void *pub, int ifidx);
2355 extern void dhd_del_sta(void *pub, int ifidx, void *ea);
2356 extern int dhd_get_ap_isolate(dhd_pub_t *dhdp, uint32 idx);
2357 extern int dhd_set_ap_isolate(dhd_pub_t *dhdp, uint32 idx, int val);
2358 extern int dhd_bssidx2idx(dhd_pub_t *dhdp, uint32 bssidx);
2359 extern struct net_device *dhd_linux_get_primary_netdev(dhd_pub_t *dhdp);
2360 
2361 extern bool dhd_is_concurrent_mode(dhd_pub_t *dhd);
2362 int dhd_iovar(dhd_pub_t *pub, int ifidx, char *name, char *param_buf, uint param_len,
2363 		char *res_buf, uint res_len, int set);
2364 extern int dhd_getiovar(dhd_pub_t *pub, int ifidx, char *name, char *cmd_buf,
2365 		uint cmd_len, char **resptr, uint resp_len);
2366 
2367 #ifdef DHD_MCAST_REGEN
2368 extern int dhd_get_mcast_regen_bss_enable(dhd_pub_t *dhdp, uint32 idx);
2369 extern int dhd_set_mcast_regen_bss_enable(dhd_pub_t *dhdp, uint32 idx, int val);
2370 #endif // endif
2371 typedef enum cust_gpio_modes {
2372 	WLAN_RESET_ON,
2373 	WLAN_RESET_OFF,
2374 	WLAN_POWER_ON,
2375 	WLAN_POWER_OFF
2376 } cust_gpio_modes_t;
2377 
2378 typedef struct dmaxref_mem_map {
2379 	dhd_dma_buf_t *srcmem;
2380 	dhd_dma_buf_t *dstmem;
2381 } dmaxref_mem_map_t;
2382 
2383 #if defined(OEM_ANDROID)
2384 extern int wl_iw_iscan_set_scan_broadcast_prep(struct net_device *dev, uint flag);
2385 extern int wl_iw_send_priv_event(struct net_device *dev, char *flag);
2386 #endif /* defined(OEM_ANDROID) */
2387 
2388 #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
2389 extern void dhd_flush_rx_tx_wq(dhd_pub_t *dhdp);
2390 #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
2391 
2392 /*
2393  * Insmod parameters for debug/test
2394  */
2395 
2396 /* Watchdog timer interval */
2397 extern uint dhd_watchdog_ms;
2398 #ifdef DHD_PCIE_RUNTIMEPM
2399 extern uint dhd_runtimepm_ms;
2400 #endif /* DHD_PCIE_RUNTIMEPM */
2401 
2402 /** Default console output poll interval */
2403 extern uint dhd_console_ms;
2404 
2405 #if defined(DHD_DEBUG)
2406 extern uint wl_msg_level;
2407 #endif /* defined(DHD_DEBUG) */
2408 
2409 extern uint dhd_slpauto;
2410 
2411 /* Use interrupts */
2412 extern uint dhd_intr;
2413 
2414 /* Use polling */
2415 extern uint dhd_poll;
2416 
2417 /* ARP offload agent mode */
2418 extern uint dhd_arp_mode;
2419 
2420 /* ARP offload enable */
2421 extern uint dhd_arp_enable;
2422 
2423 /* Pkt filte enable control */
2424 extern uint dhd_pkt_filter_enable;
2425 
2426 /*  Pkt filter init setup */
2427 extern uint dhd_pkt_filter_init;
2428 
2429 /* Pkt filter mode control */
2430 extern uint dhd_master_mode;
2431 
2432 /* Roaming mode control */
2433 extern uint dhd_roam_disable;
2434 
2435 /* Roaming mode control */
2436 extern uint dhd_radio_up;
2437 
2438 /* TCM verification control */
2439 extern uint dhd_tcm_test_enable;
2440 
2441 /* Disable BUG_ON(1) */
2442 #ifdef DHD_FW_COREDUMP
2443 extern uint disable_bug_on;
2444 #endif /* DHD_FW_COREDUMP */
2445 
2446 /* Initial idletime ticks (may be -1 for immediate idle, 0 for no idle) */
2447 extern int dhd_idletime;
2448 #ifdef DHD_USE_IDLECOUNT
2449 #define DHD_IDLETIME_TICKS 5
2450 #else
2451 #define DHD_IDLETIME_TICKS 1
2452 #endif /* DHD_USE_IDLECOUNT */
2453 
2454 /* SDIO Drive Strength */
2455 extern uint dhd_sdiod_drive_strength;
2456 
2457 /* triggers bcm_bprintf to print to kernel log */
2458 extern bool bcm_bprintf_bypass;
2459 
2460 /* Override to force tx queueing all the time */
2461 extern uint dhd_force_tx_queueing;
2462 
2463 /* Default bcn_timeout value is 4 */
2464 #define DEFAULT_BCN_TIMEOUT_VALUE	4
2465 #ifndef CUSTOM_BCN_TIMEOUT_SETTING
2466 #define CUSTOM_BCN_TIMEOUT_SETTING	DEFAULT_BCN_TIMEOUT_VALUE
2467 #endif // endif
2468 
2469 /* Default KEEP_ALIVE Period is 55 sec to prevent AP from sending Keep Alive probe frame */
2470 #define DEFAULT_KEEP_ALIVE_VALUE 	55000 /* msec */
2471 #ifndef CUSTOM_KEEP_ALIVE_SETTING
2472 #define CUSTOM_KEEP_ALIVE_SETTING 	DEFAULT_KEEP_ALIVE_VALUE
2473 #endif /* DEFAULT_KEEP_ALIVE_VALUE */
2474 
2475 #define NULL_PKT_STR	"null_pkt"
2476 
2477 /* hooks for custom glom setting option via Makefile */
2478 #define DEFAULT_GLOM_VALUE 	-1
2479 #ifndef CUSTOM_GLOM_SETTING
2480 #define CUSTOM_GLOM_SETTING 	DEFAULT_GLOM_VALUE
2481 #endif // endif
2482 #define WL_AUTO_ROAM_TRIGGER -75
2483 /* hooks for custom Roaming Trigger  setting via Makefile */
2484 #define DEFAULT_ROAM_TRIGGER_VALUE -75 /* dBm default roam trigger all band */
2485 #define DEFAULT_ROAM_TRIGGER_SETTING 	-1
2486 #ifndef CUSTOM_ROAM_TRIGGER_SETTING
2487 #define CUSTOM_ROAM_TRIGGER_SETTING 	DEFAULT_ROAM_TRIGGER_VALUE
2488 #endif // endif
2489 
2490 /* hooks for custom Roaming Romaing  setting via Makefile */
2491 #define DEFAULT_ROAM_DELTA_VALUE  10 /* dBm default roam delta all band */
2492 #define DEFAULT_ROAM_DELTA_SETTING 	-1
2493 #ifndef CUSTOM_ROAM_DELTA_SETTING
2494 #define CUSTOM_ROAM_DELTA_SETTING 	DEFAULT_ROAM_DELTA_VALUE
2495 #endif // endif
2496 
2497 /* hooks for custom PNO Event wake lock to guarantee enough time
2498 	for the Platform to detect Event before system suspended
2499 */
2500 #define DEFAULT_PNO_EVENT_LOCK_xTIME 	2 	/* multiplay of DHD_PACKET_TIMEOUT_MS */
2501 #ifndef CUSTOM_PNO_EVENT_LOCK_xTIME
2502 #define CUSTOM_PNO_EVENT_LOCK_xTIME	 DEFAULT_PNO_EVENT_LOCK_xTIME
2503 #endif // endif
2504 /* hooks for custom dhd_dpc_prio setting option via Makefile */
2505 #define DEFAULT_DHP_DPC_PRIO  1
2506 #ifndef CUSTOM_DPC_PRIO_SETTING
2507 #define CUSTOM_DPC_PRIO_SETTING 	DEFAULT_DHP_DPC_PRIO
2508 #endif // endif
2509 
2510 #ifndef CUSTOM_LISTEN_INTERVAL
2511 #define CUSTOM_LISTEN_INTERVAL 		LISTEN_INTERVAL
2512 #endif /* CUSTOM_LISTEN_INTERVAL */
2513 
2514 #define DEFAULT_SUSPEND_BCN_LI_DTIM		3
2515 #ifndef CUSTOM_SUSPEND_BCN_LI_DTIM
2516 #define CUSTOM_SUSPEND_BCN_LI_DTIM		DEFAULT_SUSPEND_BCN_LI_DTIM
2517 #endif // endif
2518 
2519 #ifdef OEM_ANDROID
2520 #ifndef BCN_TIMEOUT_IN_SUSPEND
2521 #define BCN_TIMEOUT_IN_SUSPEND			6 /* bcn timeout value in suspend mode */
2522 #endif // endif
2523 #endif /* OEM_ANDROID */
2524 
2525 #ifndef CUSTOM_RXF_PRIO_SETTING
2526 #define CUSTOM_RXF_PRIO_SETTING		MAX((CUSTOM_DPC_PRIO_SETTING - 1), 1)
2527 #endif // endif
2528 
2529 #define DEFAULT_WIFI_TURNOFF_DELAY		0
2530 #ifndef WIFI_TURNOFF_DELAY
2531 #define WIFI_TURNOFF_DELAY		DEFAULT_WIFI_TURNOFF_DELAY
2532 #endif /* WIFI_TURNOFF_DELAY */
2533 
2534 #define DEFAULT_WIFI_TURNON_DELAY		200
2535 #ifndef WIFI_TURNON_DELAY
2536 #define WIFI_TURNON_DELAY		DEFAULT_WIFI_TURNON_DELAY
2537 #endif /* WIFI_TURNON_DELAY */
2538 
2539 #define DEFAULT_DHD_WATCHDOG_INTERVAL_MS	10 /* msec */
2540 #ifndef CUSTOM_DHD_WATCHDOG_MS
2541 #define CUSTOM_DHD_WATCHDOG_MS			DEFAULT_DHD_WATCHDOG_INTERVAL_MS
2542 #endif /* DEFAULT_DHD_WATCHDOG_INTERVAL_MS */
2543 
2544 #define DEFAULT_ASSOC_RETRY_MAX			3
2545 #ifndef CUSTOM_ASSOC_RETRY_MAX
2546 #define CUSTOM_ASSOC_RETRY_MAX			DEFAULT_ASSOC_RETRY_MAX
2547 #endif /* DEFAULT_ASSOC_RETRY_MAX */
2548 
2549 #if defined(BCMSDIO) || defined(DISABLE_FRAMEBURST)
2550 #define DEFAULT_FRAMEBURST_SET			0
2551 #else
2552 #define DEFAULT_FRAMEBURST_SET			1
2553 #endif /* BCMSDIO */
2554 
2555 #ifndef CUSTOM_FRAMEBURST_SET
2556 #define CUSTOM_FRAMEBURST_SET			DEFAULT_FRAMEBURST_SET
2557 #endif /* CUSTOM_FRAMEBURST_SET */
2558 
2559 #ifdef WLTDLS
2560 #ifndef CUSTOM_TDLS_IDLE_MODE_SETTING
2561 #define CUSTOM_TDLS_IDLE_MODE_SETTING  60000 /* 60sec to tear down TDLS of not active */
2562 #endif // endif
2563 #ifndef CUSTOM_TDLS_RSSI_THRESHOLD_HIGH
2564 #define CUSTOM_TDLS_RSSI_THRESHOLD_HIGH -70 /* rssi threshold for establishing TDLS link */
2565 #endif // endif
2566 #ifndef CUSTOM_TDLS_RSSI_THRESHOLD_LOW
2567 #define CUSTOM_TDLS_RSSI_THRESHOLD_LOW -80 /* rssi threshold for tearing down TDLS link */
2568 #endif // endif
2569 #ifndef CUSTOM_TDLS_PCKTCNT_THRESHOLD_HIGH
2570 #define CUSTOM_TDLS_PCKTCNT_THRESHOLD_HIGH 100 /* pkt/sec threshold for establishing TDLS link */
2571 #endif // endif
2572 #ifndef CUSTOM_TDLS_PCKTCNT_THRESHOLD_LOW
2573 #define CUSTOM_TDLS_PCKTCNT_THRESHOLD_LOW 10 /* pkt/sec threshold for tearing down TDLS link */
2574 #endif // endif
2575 #endif /* WLTDLS */
2576 
2577 #if defined(VSDB) || defined(ROAM_ENABLE)
2578 #define DEFAULT_BCN_TIMEOUT            8
2579 #else
2580 #define DEFAULT_BCN_TIMEOUT            4
2581 #endif // endif
2582 
2583 #ifndef CUSTOM_BCN_TIMEOUT
2584 #define CUSTOM_BCN_TIMEOUT             DEFAULT_BCN_TIMEOUT
2585 #endif // endif
2586 
2587 #define MAX_DTIM_SKIP_BEACON_INTERVAL	100 /* max allowed associated AP beacon for DTIM skip */
2588 #ifndef MAX_DTIM_ALLOWED_INTERVAL
2589 #define MAX_DTIM_ALLOWED_INTERVAL 600 /* max allowed total beacon interval for DTIM skip */
2590 #endif // endif
2591 
2592 #ifdef OEM_ANDROID
2593 #ifndef MIN_DTIM_FOR_ROAM_THRES_EXTEND
2594 #define MIN_DTIM_FOR_ROAM_THRES_EXTEND	600 /* minimum dtim interval to extend roam threshold */
2595 #endif // endif
2596 #endif /* OEM_ANDROID */
2597 
2598 #define NO_DTIM_SKIP 1
2599 #ifdef SDTEST
2600 /* Echo packet generator (SDIO), pkts/s */
2601 extern uint dhd_pktgen;
2602 
2603 /* Echo packet len (0 => sawtooth, max 1800) */
2604 extern uint dhd_pktgen_len;
2605 #define MAX_PKTGEN_LEN 1800
2606 #endif // endif
2607 
2608 /* optionally set by a module_param_string() */
2609 #define MOD_PARAM_PATHLEN	2048
2610 #define MOD_PARAM_INFOLEN	512
2611 #define MOD_PARAM_SRLEN		64
2612 
2613 #ifdef SOFTAP
2614 extern char fw_path2[MOD_PARAM_PATHLEN];
2615 #endif // endif
2616 
2617 #if defined(ANDROID_PLATFORM_VERSION)
2618 #if (ANDROID_PLATFORM_VERSION < 7)
2619 #define DHD_LEGACY_FILE_PATH
2620 #define VENDOR_PATH "/system"
2621 #elif (ANDROID_PLATFORM_VERSION == 7)
2622 #define VENDOR_PATH "/system"
2623 #elif (ANDROID_PLATFORM_VERSION >= 8)
2624 #define VENDOR_PATH "/vendor"
2625 #endif /* ANDROID_PLATFORM_VERSION < 7 */
2626 #else
2627 #define VENDOR_PATH ""
2628 #endif /* ANDROID_PLATFORM_VERSION */
2629 
2630 #if defined(ANDROID_PLATFORM_VERSION)
2631 #if (ANDROID_PLATFORM_VERSION < 9)
2632 #ifdef WL_STATIC_IF
2633 #undef WL_STATIC_IF
2634 #endif /* WL_STATIC_IF */
2635 #ifdef WL_STATIC_IFNAME_PREFIX
2636 #undef WL_STATIC_IFNAME_PREFIX
2637 #endif /* WL_STATIC_IFNAME_PREFIX */
2638 #endif /* ANDROID_PLATFORM_VERSION < 9 */
2639 #endif /* ANDROID_PLATFORM_VERSION */
2640 
2641 #if defined(DHD_LEGACY_FILE_PATH)
2642 #define PLATFORM_PATH	"/data/"
2643 #elif defined(PLATFORM_SLP)
2644 #define PLATFORM_PATH	"/opt/etc/"
2645 #else
2646 #if defined(ANDROID_PLATFORM_VERSION)
2647 #if (ANDROID_PLATFORM_VERSION >= 9)
2648 #define PLATFORM_PATH	"/data/vendor/conn/"
2649 #define DHD_MAC_ADDR_EXPORT
2650 #define DHD_ADPS_BAM_EXPORT
2651 #define DHD_EXPORT_CNTL_FILE
2652 #define DHD_SOFTAP_DUAL_IF_INFO
2653 #define DHD_SEND_HANG_PRIVCMD_ERRORS
2654 #else
2655 #define PLATFORM_PATH   "/data/misc/conn/"
2656 #endif /* ANDROID_PLATFORM_VERSION >= 9 */
2657 #else
2658 #define PLATFORM_PATH   "/data/misc/conn/"
2659 #endif /* ANDROID_PLATFORM_VERSION */
2660 #endif /* DHD_LEGACY_FILE_PATH */
2661 
2662 #ifdef DHD_MAC_ADDR_EXPORT
2663 extern struct ether_addr sysfs_mac_addr;
2664 #endif /* DHD_MAC_ADDR_EXPORT */
2665 
2666 /* Flag to indicate if we should download firmware on driver load */
2667 extern uint dhd_download_fw_on_driverload;
2668 extern int allow_delay_fwdl;
2669 
2670 extern int dhd_process_cid_mac(dhd_pub_t *dhdp, bool prepost);
2671 extern int dhd_write_file(const char *filepath, char *buf, int buf_len);
2672 extern int dhd_read_file(const char *filepath, char *buf, int buf_len);
2673 extern int dhd_write_file_and_check(const char *filepath, char *buf, int buf_len);
2674 extern int dhd_file_delete(char *path);
2675 
2676 #ifdef READ_MACADDR
2677 extern int dhd_set_macaddr_from_file(dhd_pub_t *dhdp);
2678 #else
dhd_set_macaddr_from_file(dhd_pub_t * dhdp)2679 static INLINE int dhd_set_macaddr_from_file(dhd_pub_t *dhdp) { return 0; }
2680 #endif /* READ_MACADDR */
2681 #ifdef WRITE_MACADDR
2682 extern int dhd_write_macaddr(struct ether_addr *mac);
2683 #else
dhd_write_macaddr(struct ether_addr * mac)2684 static INLINE int dhd_write_macaddr(struct ether_addr *mac) { return 0; }
2685 #endif /* WRITE_MACADDR */
2686 #ifdef USE_CID_CHECK
2687 #define MAX_VNAME_LEN		64
2688 #ifdef DHD_EXPORT_CNTL_FILE
2689 extern char cidinfostr[MAX_VNAME_LEN];
2690 #endif /* DHD_EXPORT_CNTL_FILE */
2691 extern int dhd_check_module_cid(dhd_pub_t *dhdp);
2692 extern char *dhd_get_cid_info(unsigned char *vid, int vid_length);
2693 #else
dhd_check_module_cid(dhd_pub_t * dhdp)2694 static INLINE int dhd_check_module_cid(dhd_pub_t *dhdp) { return 0; }
2695 #endif /* USE_CID_CHECK */
2696 #ifdef GET_MAC_FROM_OTP
2697 extern int dhd_check_module_mac(dhd_pub_t *dhdp);
2698 #else
dhd_check_module_mac(dhd_pub_t * dhdp)2699 static INLINE int dhd_check_module_mac(dhd_pub_t *dhdp) { return 0; }
2700 #endif /* GET_MAC_FROM_OTP */
2701 
2702 #if defined(READ_MACADDR) || defined(WRITE_MACADDR) || defined(USE_CID_CHECK) || \
2703 	defined(GET_MAC_FROM_OTP)
2704 #define DHD_USE_CISINFO
2705 #endif /* READ_MACADDR || WRITE_MACADDR || USE_CID_CHECK || GET_MAC_FROM_OTP */
2706 
2707 #ifdef DHD_USE_CISINFO
2708 int dhd_read_cis(dhd_pub_t *dhdp);
2709 void dhd_clear_cis(dhd_pub_t *dhdp);
2710 #if defined(SUPPORT_MULTIPLE_MODULE_CIS) && defined(USE_CID_CHECK)
2711 extern int dhd_check_module_b85a(void);
2712 extern int dhd_check_module_b90(void);
2713 #define BCM4359_MODULE_TYPE_B90B 1
2714 #define BCM4359_MODULE_TYPE_B90S 2
2715 #endif /* defined(SUPPORT_MULTIPLE_MODULE_CIS) && defined(USE_CID_CHECK) */
2716 #if defined(USE_CID_CHECK)
2717 extern int dhd_check_module_bcm(char *module_type, int index, bool *is_murata_fem);
2718 #endif /* defined(USE_CID_CHECK) */
2719 #else
dhd_read_cis(dhd_pub_t * dhdp)2720 static INLINE int dhd_read_cis(dhd_pub_t *dhdp) { return 0; }
dhd_clear_cis(dhd_pub_t * dhdp)2721 static INLINE void dhd_clear_cis(dhd_pub_t *dhdp) { }
2722 #endif /* DHD_USE_CISINFO */
2723 
2724 #if defined(WL_CFG80211) && defined(SUPPORT_DEEP_SLEEP)
2725 /* Flags to indicate if we distingish power off policy when
2726  * user set the memu "Keep Wi-Fi on during sleep" to "Never"
2727  */
2728 extern int trigger_deep_sleep;
2729 int dhd_deepsleep(struct net_device *dev, int flag);
2730 #endif /* WL_CFG80211 && SUPPORT_DEEP_SLEEP */
2731 
2732 extern void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar);
2733 extern void dhd_wait_event_wakeup(dhd_pub_t*dhd);
2734 
2735 #define IFLOCK_INIT(lock)       *lock = 0
2736 #define IFLOCK(lock)    while (InterlockedCompareExchange((lock), 1, 0))	\
2737 	NdisStallExecution(1);
2738 #define IFUNLOCK(lock)  InterlockedExchange((lock), 0)
2739 #define IFLOCK_FREE(lock)
2740 #define FW_SUPPORTED(dhd, capa) ((strstr(dhd->fw_capabilities, " " #capa " ") != NULL))
2741 #ifdef ARP_OFFLOAD_SUPPORT
2742 #define MAX_IPV4_ENTRIES	8
2743 void dhd_arp_offload_set(dhd_pub_t * dhd, int arp_mode);
2744 void dhd_arp_offload_enable(dhd_pub_t * dhd, int arp_enable);
2745 
2746 /* dhd_commn arp offload wrapers */
2747 void dhd_aoe_hostip_clr(dhd_pub_t *dhd, int idx);
2748 void dhd_aoe_arp_clr(dhd_pub_t *dhd, int idx);
2749 int dhd_arp_get_arp_hostip_table(dhd_pub_t *dhd, void *buf, int buflen, int idx);
2750 void dhd_arp_offload_add_ip(dhd_pub_t *dhd, uint32 ipaddr, int idx);
2751 #endif /* ARP_OFFLOAD_SUPPORT */
2752 #ifdef WLTDLS
2753 int dhd_tdls_enable(struct net_device *dev, bool tdls_on, bool auto_on, struct ether_addr *mac);
2754 int dhd_tdls_set_mode(dhd_pub_t *dhd, bool wfd_mode);
2755 #ifdef PCIE_FULL_DONGLE
2756 int dhd_tdls_update_peer_info(dhd_pub_t *dhdp, wl_event_msg_t *event);
2757 int dhd_tdls_event_handler(dhd_pub_t *dhd_pub, wl_event_msg_t *event);
2758 int dhd_free_tdls_peer_list(dhd_pub_t *dhd_pub);
2759 #endif /* PCIE_FULL_DONGLE */
2760 #endif /* WLTDLS */
2761 
2762 /* Neighbor Discovery Offload Support */
2763 extern int dhd_ndo_enable(dhd_pub_t * dhd, int ndo_enable);
2764 int dhd_ndo_add_ip(dhd_pub_t *dhd, char* ipaddr, int idx);
2765 int dhd_ndo_remove_ip(dhd_pub_t *dhd, int idx);
2766 
2767 /* Enhanced ND offload support */
2768 uint16 dhd_ndo_get_version(dhd_pub_t *dhdp);
2769 int dhd_ndo_add_ip_with_type(dhd_pub_t *dhdp, char *ipv6addr, uint8 type, int idx);
2770 int dhd_ndo_remove_ip_by_addr(dhd_pub_t *dhdp, char *ipv6addr, int idx);
2771 int dhd_ndo_remove_ip_by_type(dhd_pub_t *dhdp, uint8 type, int idx);
2772 int dhd_ndo_unsolicited_na_filter_enable(dhd_pub_t *dhdp, int enable);
2773 
2774 /* ioctl processing for nl80211 */
2775 int dhd_ioctl_process(dhd_pub_t *pub, int ifidx, struct dhd_ioctl *ioc, void *data_buf);
2776 
2777 #if defined(SUPPORT_MULTIPLE_REVISION)
2778 extern int
2779 concate_revision(struct dhd_bus *bus, char *fwpath, char *nvpath);
2780 #endif /* SUPPORT_MULTIPLE_REVISION */
2781 void dhd_bus_update_fw_nv_path(struct dhd_bus *bus, char *pfw_path, char *pnv_path);
2782 void dhd_set_bus_state(void *bus, uint32 state);
2783 
2784 /* Remove proper pkts(either one no-frag pkt or whole fragmented pkts) */
2785 typedef int (*f_droppkt_t)(dhd_pub_t *dhdp, int prec, void* p, bool bPktInQ);
2786 extern bool dhd_prec_drop_pkts(dhd_pub_t *dhdp, struct pktq *pq, int prec, f_droppkt_t fn);
2787 
2788 #ifdef PROP_TXSTATUS
2789 int dhd_os_wlfc_block(dhd_pub_t *pub);
2790 int dhd_os_wlfc_unblock(dhd_pub_t *pub);
2791 extern const uint8 prio2fifo[];
2792 #endif /* PROP_TXSTATUS */
2793 
2794 int dhd_os_socram_dump(struct net_device *dev, uint32 *dump_size);
2795 int dhd_os_get_socram_dump(struct net_device *dev, char **buf, uint32 *size);
2796 int dhd_common_socram_dump(dhd_pub_t *dhdp);
2797 
2798 int dhd_dump(dhd_pub_t *dhdp, char *buf, int buflen);
2799 
2800 int dhd_os_get_version(struct net_device *dev, bool dhd_ver, char **buf, uint32 size);
2801 void dhd_get_memdump_filename(struct net_device *ndev, char *memdump_path, int len, char *fname);
2802 uint8* dhd_os_prealloc(dhd_pub_t *dhdpub, int section, uint size, bool kmalloc_if_fail);
2803 void dhd_os_prefree(dhd_pub_t *dhdpub, void *addr, uint size);
2804 
2805 #if defined(CONFIG_DHD_USE_STATIC_BUF)
2806 #define DHD_OS_PREALLOC(dhdpub, section, size) dhd_os_prealloc(dhdpub, section, size, FALSE)
2807 #define DHD_OS_PREFREE(dhdpub, addr, size) dhd_os_prefree(dhdpub, addr, size)
2808 #else
2809 #define DHD_OS_PREALLOC(dhdpub, section, size) MALLOC(dhdpub->osh, size)
2810 #define DHD_OS_PREFREE(dhdpub, addr, size) MFREE(dhdpub->osh, addr, size)
2811 #endif /* defined(CONFIG_DHD_USE_STATIC_BUF) */
2812 
2813 #ifdef USE_WFA_CERT_CONF
2814 enum {
2815 	SET_PARAM_BUS_TXGLOM_MODE,
2816 	SET_PARAM_ROAMOFF,
2817 #ifdef USE_WL_FRAMEBURST
2818 	SET_PARAM_FRAMEBURST,
2819 #endif /* USE_WL_FRAMEBURST */
2820 #ifdef USE_WL_TXBF
2821 	SET_PARAM_TXBF,
2822 #endif /* USE_WL_TXBF */
2823 #ifdef PROP_TXSTATUS
2824 	SET_PARAM_PROPTX,
2825 	SET_PARAM_PROPTXMODE,
2826 #endif /* PROP_TXSTATUS */
2827 	PARAM_LAST_VALUE
2828 };
2829 extern int sec_get_param_wfa_cert(dhd_pub_t *dhd, int mode, uint* read_val);
2830 #ifdef DHD_EXPORT_CNTL_FILE
2831 #define VALUENOTSET 0xFFFFFFFFu
2832 extern uint32 bus_txglom;
2833 extern uint32 roam_off;
2834 #ifdef USE_WL_FRAMEBURST
2835 extern uint32 frameburst;
2836 #endif /* USE_WL_FRAMEBURST */
2837 #ifdef USE_WL_TXBF
2838 extern uint32 txbf;
2839 #endif /* USE_WL_TXBF */
2840 #ifdef PROP_TXSTATUS
2841 extern uint32 proptx;
2842 #endif /* PROP_TXSTATUS */
2843 #endif /* DHD_EXPORT_CNTL_FILE */
2844 #endif /* USE_WFA_CERT_CONF */
2845 
2846 #define dhd_add_flowid(pub, ifidx, ac_prio, ea, flowid)  do {} while (0)
2847 #define dhd_del_flowid(pub, ifidx, flowid)               do {} while (0)
2848 bool dhd_wet_chainable(dhd_pub_t *dhdp);
2849 
2850 extern unsigned long dhd_os_general_spin_lock(dhd_pub_t *pub);
2851 extern void dhd_os_general_spin_unlock(dhd_pub_t *pub, unsigned long flags);
2852 
2853 /** Miscellaenous DHD Spin Locks */
2854 
2855 /* Disable router 3GMAC bypass path perimeter lock */
2856 #define DHD_PERIM_LOCK(dhdp)              do {} while (0)
2857 #define DHD_PERIM_UNLOCK(dhdp)            do {} while (0)
2858 #define DHD_PERIM_LOCK_ALL(processor_id)    do {} while (0)
2859 #define DHD_PERIM_UNLOCK_ALL(processor_id)  do {} while (0)
2860 
2861 /* Enable DHD general spin lock/unlock */
2862 #define DHD_GENERAL_LOCK(dhdp, flags) \
2863 	(flags) = dhd_os_general_spin_lock(dhdp)
2864 #define DHD_GENERAL_UNLOCK(dhdp, flags) \
2865 	dhd_os_general_spin_unlock((dhdp), (flags))
2866 
2867 /* Enable DHD timer spin lock/unlock */
2868 #define DHD_TIMER_LOCK(lock, flags)     (flags) = dhd_os_spin_lock(lock)
2869 #define DHD_TIMER_UNLOCK(lock, flags)   dhd_os_spin_unlock(lock, (flags))
2870 
2871 /* Enable DHD flowring spin lock/unlock */
2872 #define DHD_FLOWRING_LOCK(lock, flags)     (flags) = dhd_os_spin_lock(lock)
2873 #define DHD_FLOWRING_UNLOCK(lock, flags)   dhd_os_spin_unlock((lock), (flags))
2874 
2875 /* Enable DHD common flowring info spin lock/unlock */
2876 #define DHD_FLOWID_LOCK(lock, flags)       (flags) = dhd_os_spin_lock(lock)
2877 #define DHD_FLOWID_UNLOCK(lock, flags)     dhd_os_spin_unlock((lock), (flags))
2878 
2879 /* Enable DHD common flowring list spin lock/unlock */
2880 #define DHD_FLOWRING_LIST_LOCK(lock, flags)       (flags) = dhd_os_spin_lock(lock)
2881 #define DHD_FLOWRING_LIST_UNLOCK(lock, flags)     dhd_os_spin_unlock((lock), (flags))
2882 
2883 #define DHD_SPIN_LOCK(lock, flags)	(flags) = dhd_os_spin_lock(lock)
2884 #define DHD_SPIN_UNLOCK(lock, flags)	dhd_os_spin_unlock((lock), (flags))
2885 
2886 #define DHD_RING_LOCK(lock, flags)	(flags) = dhd_os_spin_lock(lock)
2887 #define DHD_RING_UNLOCK(lock, flags)	dhd_os_spin_unlock((lock), (flags))
2888 
2889 #define DHD_BUS_LOCK(lock, flags)	(flags) = dhd_os_spin_lock(lock)
2890 #define DHD_BUS_UNLOCK(lock, flags)	dhd_os_spin_unlock((lock), (flags))
2891 
2892 /* Enable DHD backplane spin lock/unlock */
2893 #define DHD_BACKPLANE_ACCESS_LOCK(lock, flags)     (flags) = dhd_os_spin_lock(lock)
2894 #define DHD_BACKPLANE_ACCESS_UNLOCK(lock, flags)   dhd_os_spin_unlock((lock), (flags))
2895 
2896 #define DHD_BUS_INB_DW_LOCK(lock, flags)	(flags) = dhd_os_spin_lock(lock)
2897 #define DHD_BUS_INB_DW_UNLOCK(lock, flags)	dhd_os_spin_unlock((lock), (flags))
2898 
2899 /* Enable DHD TDLS peer list spin lock/unlock */
2900 #ifdef WLTDLS
2901 #define DHD_TDLS_LOCK(lock, flags)       (flags) = dhd_os_spin_lock(lock)
2902 #define DHD_TDLS_UNLOCK(lock, flags)     dhd_os_spin_unlock((lock), (flags))
2903 #endif /* WLTDLS */
2904 
2905 #define DHD_BUS_INB_DW_LOCK(lock, flags)	(flags) = dhd_os_spin_lock(lock)
2906 #define DHD_BUS_INB_DW_UNLOCK(lock, flags)	dhd_os_spin_unlock((lock), (flags))
2907 
2908 #ifdef DBG_PKT_MON
2909 /* Enable DHD PKT MON spin lock/unlock */
2910 #define DHD_PKT_MON_LOCK(lock, flags)     (flags) = dhd_os_spin_lock(lock)
2911 #define DHD_PKT_MON_UNLOCK(lock, flags)   dhd_os_spin_unlock(lock, (flags))
2912 #endif /* DBG_PKT_MON */
2913 
2914 #define DHD_LINUX_GENERAL_LOCK(dhdp, flags)	DHD_GENERAL_LOCK(dhdp, flags)
2915 #define DHD_LINUX_GENERAL_UNLOCK(dhdp, flags)	DHD_GENERAL_UNLOCK(dhdp, flags)
2916 
2917 /* linux is defined for DHD EFI builds also,
2918 * since its cross-compiled for EFI from linux
2919 */
2920 #define DHD_DBG_RING_LOCK_INIT(osh)				dhd_os_dbgring_lock_init(osh)
2921 #define DHD_DBG_RING_LOCK_DEINIT(osh, lock)		dhd_os_dbgring_lock_deinit(osh, (lock))
2922 #define DHD_DBG_RING_LOCK(lock, flags)			(flags) = dhd_os_dbgring_lock(lock)
2923 #define DHD_DBG_RING_UNLOCK(lock, flags)		dhd_os_dbgring_unlock((lock), flags)
2924 
2925 extern void dhd_dump_to_kernelog(dhd_pub_t *dhdp);
2926 
2927 extern void dhd_print_tasklet_status(dhd_pub_t *dhd);
2928 
2929 #ifdef DHD_L2_FILTER
2930 extern int dhd_get_parp_status(dhd_pub_t *dhdp, uint32 idx);
2931 extern int dhd_set_parp_status(dhd_pub_t *dhdp, uint32 idx, int val);
2932 extern int dhd_get_dhcp_unicast_status(dhd_pub_t *dhdp, uint32 idx);
2933 extern int dhd_set_dhcp_unicast_status(dhd_pub_t *dhdp, uint32 idx, int val);
2934 extern int dhd_get_block_ping_status(dhd_pub_t *dhdp, uint32 idx);
2935 extern int dhd_set_block_ping_status(dhd_pub_t *dhdp, uint32 idx, int val);
2936 extern int dhd_get_grat_arp_status(dhd_pub_t *dhdp, uint32 idx);
2937 extern int dhd_set_grat_arp_status(dhd_pub_t *dhdp, uint32 idx, int val);
2938 extern int dhd_get_block_tdls_status(dhd_pub_t *dhdp, uint32 idx);
2939 extern int dhd_set_block_tdls_status(dhd_pub_t *dhdp, uint32 idx, int val);
2940 #endif /* DHD_L2_FILTER */
2941 
2942 typedef struct wl_io_pport {
2943 	dhd_pub_t *dhd_pub;
2944 	uint ifidx;
2945 } wl_io_pport_t;
2946 
2947 typedef struct wl_evt_pport {
2948 	dhd_pub_t *dhd_pub;
2949 	int *ifidx;
2950 	void *pktdata;
2951 	uint data_len;
2952 	void **data_ptr;
2953 	void *raw_event;
2954 } wl_evt_pport_t;
2955 
2956 extern void *dhd_pub_shim(dhd_pub_t *dhd_pub);
2957 #ifdef DHD_FW_COREDUMP
2958 void* dhd_get_fwdump_buf(dhd_pub_t *dhd_pub, uint32 length);
2959 #endif /* DHD_FW_COREDUMP */
2960 
2961 #if defined(SET_RPS_CPUS)
2962 int dhd_rps_cpus_enable(struct net_device *net, int enable);
2963 int custom_rps_map_set(struct netdev_rx_queue *queue, char *buf, size_t len);
2964 void custom_rps_map_clear(struct netdev_rx_queue *queue);
2965 #define PRIMARY_INF 0
2966 #define VIRTUAL_INF 1
2967 #if defined(CONFIG_MACH_UNIVERSAL5433) || defined(CONFIG_MACH_UNIVERSAL7420) || \
2968 	defined(CONFIG_SOC_EXYNOS8890)
2969 #define RPS_CPUS_MASK "10"
2970 #define RPS_CPUS_MASK_P2P "10"
2971 #define RPS_CPUS_MASK_IBSS "10"
2972 #define RPS_CPUS_WLAN_CORE_ID 4
2973 #else
2974 #define RPS_CPUS_MASK "6"
2975 #define RPS_CPUS_MASK_P2P "6"
2976 #define RPS_CPUS_MASK_IBSS "6"
2977 #endif /* CONFIG_MACH_UNIVERSAL5433 || CONFIG_MACH_UNIVERSAL7420 || CONFIG_SOC_EXYNOS8890 */
2978 #endif // endif
2979 
2980 int dhd_get_download_buffer(dhd_pub_t	*dhd, char *file_path, download_type_t component,
2981 	char ** buffer, int *length);
2982 
2983 void dhd_free_download_buffer(dhd_pub_t	*dhd, void *buffer, int length);
2984 
2985 int dhd_download_blob(dhd_pub_t *dhd, unsigned char *buf,
2986 		uint32 len, char *iovar);
2987 
2988 int dhd_download_blob_cached(dhd_pub_t *dhd, char *file_path,
2989 	uint32 len, char *iovar);
2990 
2991 int dhd_apply_default_txcap(dhd_pub_t *dhd, char *txcap_path);
2992 int dhd_apply_default_clm(dhd_pub_t *dhd, char *clm_path);
2993 
2994 #ifdef SHOW_LOGTRACE
2995 int dhd_parse_logstrs_file(osl_t *osh, char *raw_fmts, int logstrs_size,
2996 		dhd_event_log_t *event_log);
2997 int dhd_parse_map_file(osl_t *osh, void *file, uint32 *ramstart,
2998 		uint32 *rodata_start, uint32 *rodata_end);
2999 #ifdef PCIE_FULL_DONGLE
3000 int dhd_event_logtrace_infobuf_pkt_process(dhd_pub_t *dhdp, void *pktbuf,
3001 		dhd_event_log_t *event_data);
3002 #endif /* PCIE_FULL_DONGLE */
3003 #endif /* SHOW_LOGTRACE */
3004 
3005 #define dhd_is_device_removed(x) FALSE
3006 #define dhd_os_ind_firmware_stall(x)
3007 
3008 #if defined(DHD_FW_COREDUMP)
3009 extern void dhd_get_memdump_info(dhd_pub_t *dhd);
3010 #endif /* defined(DHD_FW_COREDUMP) */
3011 #ifdef BCMASSERT_LOG
3012 extern void dhd_get_assert_info(dhd_pub_t *dhd);
3013 #else
dhd_get_assert_info(dhd_pub_t * dhd)3014 static INLINE void dhd_get_assert_info(dhd_pub_t *dhd) { }
3015 #endif /* BCMASSERT_LOG */
3016 
3017 #define DMAXFER_FREE(dhdp, dmap) dhd_schedule_dmaxfer_free(dhdp, dmap);
3018 
3019 #if defined(PCIE_FULL_DONGLE)
3020 extern void dmaxfer_free_prev_dmaaddr(dhd_pub_t *dhdp, dmaxref_mem_map_t *dmmap);
3021 void dhd_schedule_dmaxfer_free(dhd_pub_t *dhdp, dmaxref_mem_map_t *dmmap);
3022 #endif  /* PCIE_FULL_DONGLE */
3023 
3024 #define DHD_LB_STATS_NOOP	do { /* noop */ } while (0)
3025 #if defined(DHD_LB_STATS)
3026 #include <bcmutils.h>
3027 extern void dhd_lb_stats_init(dhd_pub_t *dhd);
3028 extern void dhd_lb_stats_deinit(dhd_pub_t *dhd);
3029 extern void dhd_lb_stats_dump(dhd_pub_t *dhdp, struct bcmstrbuf *strbuf);
3030 extern void dhd_lb_stats_update_napi_histo(dhd_pub_t *dhdp, uint32 count);
3031 extern void dhd_lb_stats_update_txc_histo(dhd_pub_t *dhdp, uint32 count);
3032 extern void dhd_lb_stats_update_rxc_histo(dhd_pub_t *dhdp, uint32 count);
3033 extern void dhd_lb_stats_txc_percpu_cnt_incr(dhd_pub_t *dhdp);
3034 extern void dhd_lb_stats_rxc_percpu_cnt_incr(dhd_pub_t *dhdp);
3035 #define DHD_LB_STATS_INIT(dhdp)	dhd_lb_stats_init(dhdp)
3036 #define DHD_LB_STATS_DEINIT(dhdp) dhd_lb_stats_deinit(dhdp)
3037 /* Reset is called from common layer so it takes dhd_pub_t as argument */
3038 #define DHD_LB_STATS_RESET(dhdp) dhd_lb_stats_init(dhdp)
3039 #define DHD_LB_STATS_CLR(x)	(x) = 0U
3040 #define DHD_LB_STATS_INCR(x)	(x) = (x) + 1
3041 #define DHD_LB_STATS_ADD(x, c)	(x) = (x) + (c)
3042 #define DHD_LB_STATS_PERCPU_ARR_INCR(x) \
3043 	{ \
3044 		int cpu = get_cpu(); put_cpu(); \
3045 		DHD_LB_STATS_INCR(x[cpu]); \
3046 	}
3047 #define DHD_LB_STATS_UPDATE_NAPI_HISTO(dhdp, x)	dhd_lb_stats_update_napi_histo(dhdp, x)
3048 #define DHD_LB_STATS_UPDATE_TXC_HISTO(dhdp, x)	dhd_lb_stats_update_txc_histo(dhdp, x)
3049 #define DHD_LB_STATS_UPDATE_RXC_HISTO(dhdp, x)	dhd_lb_stats_update_rxc_histo(dhdp, x)
3050 #define DHD_LB_STATS_TXC_PERCPU_CNT_INCR(dhdp)	dhd_lb_stats_txc_percpu_cnt_incr(dhdp)
3051 #define DHD_LB_STATS_RXC_PERCPU_CNT_INCR(dhdp)	dhd_lb_stats_rxc_percpu_cnt_incr(dhdp)
3052 #else /* !DHD_LB_STATS */
3053 #define DHD_LB_STATS_INIT(dhdp)	 DHD_LB_STATS_NOOP
3054 #define DHD_LB_STATS_DEINIT(dhdp) DHD_LB_STATS_NOOP
3055 #define DHD_LB_STATS_RESET(dhdp) DHD_LB_STATS_NOOP
3056 #define DHD_LB_STATS_CLR(x)	 DHD_LB_STATS_NOOP
3057 #define DHD_LB_STATS_INCR(x)	 DHD_LB_STATS_NOOP
3058 #define DHD_LB_STATS_ADD(x, c)	 DHD_LB_STATS_NOOP
3059 #define DHD_LB_STATS_PERCPU_ARR_INCR(x)	 DHD_LB_STATS_NOOP
3060 #define DHD_LB_STATS_UPDATE_NAPI_HISTO(dhd, x) DHD_LB_STATS_NOOP
3061 #define DHD_LB_STATS_UPDATE_TXC_HISTO(dhd, x) DHD_LB_STATS_NOOP
3062 #define DHD_LB_STATS_UPDATE_RXC_HISTO(dhd, x) DHD_LB_STATS_NOOP
3063 #define DHD_LB_STATS_TXC_PERCPU_CNT_INCR(dhdp) DHD_LB_STATS_NOOP
3064 #define DHD_LB_STATS_RXC_PERCPU_CNT_INCR(dhdp) DHD_LB_STATS_NOOP
3065 #endif /* !DHD_LB_STATS */
3066 
3067 #ifdef DHD_SSSR_DUMP
3068 #define DHD_SSSR_MEMPOOL_SIZE	(2 * 1024 * 1024) /* 2MB size */
3069 
3070 /* used in sssr_dump_mode */
3071 #define SSSR_DUMP_MODE_SSSR	0	/* dump both *before* and *after* files */
3072 #define SSSR_DUMP_MODE_FIS	1	/* dump *after* files only */
3073 
3074 extern int dhd_sssr_mempool_init(dhd_pub_t *dhd);
3075 extern void dhd_sssr_mempool_deinit(dhd_pub_t *dhd);
3076 extern int dhd_sssr_dump_init(dhd_pub_t *dhd);
3077 extern void dhd_sssr_dump_deinit(dhd_pub_t *dhd);
3078 extern int dhdpcie_sssr_dump(dhd_pub_t *dhd);
3079 extern void dhd_sssr_print_filepath(dhd_pub_t *dhd, char *path);
3080 
3081 #define DHD_SSSR_MEMPOOL_INIT(dhdp)	dhd_sssr_mempool_init(dhdp)
3082 #define DHD_SSSR_MEMPOOL_DEINIT(dhdp) dhd_sssr_mempool_deinit(dhdp)
3083 #define DHD_SSSR_DUMP_INIT(dhdp)	dhd_sssr_dump_init(dhdp)
3084 #define DHD_SSSR_DUMP_DEINIT(dhdp) dhd_sssr_dump_deinit(dhdp)
3085 #define DHD_SSSR_PRINT_FILEPATH(dhdp, path) dhd_sssr_print_filepath(dhdp, path)
3086 #else
3087 #define DHD_SSSR_MEMPOOL_INIT(dhdp)		do { /* noop */ } while (0)
3088 #define DHD_SSSR_MEMPOOL_DEINIT(dhdp)		do { /* noop */ } while (0)
3089 #define DHD_SSSR_DUMP_INIT(dhdp)		do { /* noop */ } while (0)
3090 #define DHD_SSSR_DUMP_DEINIT(dhdp)		do { /* noop */ } while (0)
3091 #define DHD_SSSR_PRINT_FILEPATH(dhdp, path)	do { /* noop */ } while (0)
3092 #endif /* DHD_SSSR_DUMP */
3093 
3094 #ifdef BCMPCIE
3095 extern int dhd_prot_debug_info_print(dhd_pub_t *dhd);
3096 extern bool dhd_bus_skip_clm(dhd_pub_t *dhdp);
3097 extern void dhd_pcie_dump_rc_conf_space_cap(dhd_pub_t *dhd);
3098 extern bool dhd_pcie_dump_int_regs(dhd_pub_t *dhd);
3099 #else
3100 #define dhd_prot_debug_info_print(x)
dhd_bus_skip_clm(dhd_pub_t * dhd_pub)3101 static INLINE bool dhd_bus_skip_clm(dhd_pub_t *dhd_pub)
3102 { return 0; }
3103 #endif /* BCMPCIE */
3104 
3105 fw_download_status_t dhd_fw_download_status(dhd_pub_t * dhd_pub);
3106 void dhd_show_kirqstats(dhd_pub_t *dhd);
3107 
3108 /* Bitmask used for Join Timeout */
3109 #define WLC_SSID_MASK          0x01
3110 #define WLC_WPA_MASK           0x02
3111 
3112 extern int dhd_start_join_timer(dhd_pub_t *pub);
3113 extern int dhd_stop_join_timer(dhd_pub_t *pub);
3114 extern int dhd_start_scan_timer(dhd_pub_t *pub, bool is_escan);
3115 extern int dhd_stop_scan_timer(dhd_pub_t *pub, bool is_escan, uint16 sync_id);
3116 extern int dhd_start_cmd_timer(dhd_pub_t *pub);
3117 extern int dhd_stop_cmd_timer(dhd_pub_t *pub);
3118 extern int dhd_start_bus_timer(dhd_pub_t *pub);
3119 extern int dhd_stop_bus_timer(dhd_pub_t *pub);
3120 extern uint16 dhd_get_request_id(dhd_pub_t *pub);
3121 extern int dhd_set_request_id(dhd_pub_t *pub, uint16 id, uint32 cmd);
3122 extern void dhd_set_join_error(dhd_pub_t *pub, uint32 mask);
3123 extern void dhd_clear_join_error(dhd_pub_t *pub, uint32 mask);
3124 extern void dhd_get_scan_to_val(dhd_pub_t *pub, uint32 *to_val);
3125 extern void dhd_set_scan_to_val(dhd_pub_t *pub, uint32 to_val);
3126 extern void dhd_get_join_to_val(dhd_pub_t *pub, uint32 *to_val);
3127 extern void dhd_set_join_to_val(dhd_pub_t *pub, uint32 to_val);
3128 extern void dhd_get_cmd_to_val(dhd_pub_t *pub, uint32 *to_val);
3129 extern void dhd_set_cmd_to_val(dhd_pub_t *pub, uint32 to_val);
3130 extern void dhd_get_bus_to_val(dhd_pub_t *pub, uint32 *to_val);
3131 extern void dhd_set_bus_to_val(dhd_pub_t *pub, uint32 to_val);
3132 extern int dhd_start_timesync_timer(dhd_pub_t *pub);
3133 extern int dhd_stop_timesync_timer(dhd_pub_t *pub);
3134 
3135 #ifdef DHD_PKTID_AUDIT_ENABLED
3136 void dhd_pktid_error_handler(dhd_pub_t *dhdp);
3137 #endif /* DHD_PKTID_AUDIT_ENABLED */
3138 
3139 #ifdef DHD_MAP_PKTID_LOGGING
3140 extern void dhd_pktid_logging_dump(dhd_pub_t *dhdp);
3141 #endif /* DHD_MAP_PKTID_LOGGING */
3142 
3143 #ifdef DHD_PCIE_RUNTIMEPM
3144 extern bool dhd_runtimepm_state(dhd_pub_t *dhd);
3145 extern bool dhd_runtime_bus_wake(struct dhd_bus *bus, bool wait, void *func_addr);
3146 extern bool dhdpcie_runtime_bus_wake(dhd_pub_t *dhdp, bool wait, void *func_addr);
3147 extern void dhdpcie_block_runtime_pm(dhd_pub_t *dhdp);
3148 extern bool dhdpcie_is_resume_done(dhd_pub_t *dhdp);
3149 extern void dhd_runtime_pm_disable(dhd_pub_t *dhdp);
3150 extern void dhd_runtime_pm_enable(dhd_pub_t *dhdp);
3151 /* Disable the Runtime PM and wake up if the bus is already in suspend */
3152 #define DHD_DISABLE_RUNTIME_PM(dhdp) \
3153 do { \
3154 	dhd_runtime_pm_disable(dhdp); \
3155 } while (0);
3156 
3157 /* Enable the Runtime PM */
3158 #define DHD_ENABLE_RUNTIME_PM(dhdp) \
3159 do { \
3160 	dhd_runtime_pm_enable(dhdp); \
3161 } while (0);
3162 #else
3163 #define DHD_DISABLE_RUNTIME_PM(dhdp)
3164 #define DHD_ENABLE_RUNTIME_PM(dhdp)
3165 #endif /* DHD_PCIE_RUNTIMEPM */
3166 
3167 #ifdef REVERSE_AIFSN
3168 extern int check_reverse_aifsn_condition(dhd_pub_t *dhdp, struct net_device *ndev);
3169 
3170 #define DHD_REVERSE_AIFSN(dhdp, ndev) \
3171 do { \
3172 	check_reverse_aifsn_condition(dhdp, ndev); \
3173 } while (0);
3174 #else
3175 #define DHD_REVERSE_AIFSN(dhdp, ndev)
3176 #endif /* AIFSN_REVERSE */
3177 
3178 extern bool dhd_prot_is_cmpl_ring_empty(dhd_pub_t *dhd, void *prot_info);
3179 extern void dhd_prot_dump_ring_ptrs(void *prot_info);
3180 
3181 #if defined(DHD_TRACE_WAKE_LOCK)
3182 void dhd_wk_lock_stats_dump(dhd_pub_t *dhdp);
3183 #endif // endif
3184 
3185 extern bool dhd_query_bus_erros(dhd_pub_t *dhdp);
3186 void dhd_clear_bus_errors(dhd_pub_t *dhdp);
3187 
3188 #if defined(CONFIG_64BIT)
3189 #define DHD_SUPPORT_64BIT
3190 #endif /* (linux || LINUX) && CONFIG_64BIT */
3191 
3192 #if defined(DHD_ERPOM)
3193 extern void dhd_schedule_reset(dhd_pub_t *dhdp);
3194 #else
dhd_schedule_reset(dhd_pub_t * dhdp)3195 static INLINE void dhd_schedule_reset(dhd_pub_t *dhdp) {;}
3196 #endif // endif
3197 
3198 extern void init_dhd_timeouts(dhd_pub_t *pub);
3199 extern void deinit_dhd_timeouts(dhd_pub_t *pub);
3200 
3201 typedef enum timeout_resons {
3202 	DHD_REASON_COMMAND_TO,
3203 	DHD_REASON_JOIN_TO,
3204 	DHD_REASON_SCAN_TO,
3205 	DHD_REASON_OQS_TO
3206 } timeout_reasons_t;
3207 
3208 extern void dhd_prhex(const char *msg, volatile uchar *buf, uint nbytes, uint8 dbg_level);
3209 int dhd_tput_test(dhd_pub_t *dhd, tput_test_t *tput_data);
3210 void dhd_tput_test_rx(dhd_pub_t *dhd, void *pkt);
dhd_get_max_txbufs(dhd_pub_t * dhdp)3211 static INLINE int dhd_get_max_txbufs(dhd_pub_t *dhdp)
3212 { return -1; }
3213 
3214 #ifdef FILTER_IE
3215 int dhd_read_from_file(dhd_pub_t *dhd);
3216 int dhd_parse_filter_ie(dhd_pub_t *dhd, uint8 *buf);
3217 int dhd_get_filter_ie_count(dhd_pub_t *dhd, uint8 *buf);
3218 int dhd_parse_oui(dhd_pub_t *dhd, uint8 *inbuf, uint8 *oui, int len);
3219 int dhd_check_valid_ie(dhd_pub_t *dhdp, uint8 *buf, int len);
3220 #endif /* FILTER_IE */
3221 
3222 uint16 dhd_prot_get_ioctl_trans_id(dhd_pub_t *dhdp);
3223 
3224 #ifdef SET_PCIE_IRQ_CPU_CORE
3225 enum {
3226 	PCIE_IRQ_AFFINITY_OFF = 0,
3227 	PCIE_IRQ_AFFINITY_BIG_CORE_ANY,
3228 	PCIE_IRQ_AFFINITY_BIG_CORE_EXYNOS,
3229 	PCIE_IRQ_AFFINITY_LAST
3230 };
3231 extern void dhd_set_irq_cpucore(dhd_pub_t *dhdp, int affinity_cmd);
3232 #endif /* SET_PCIE_IRQ_CPU_CORE */
3233 
3234 #if defined(DHD_HANG_SEND_UP_TEST)
3235 extern void dhd_make_hang_with_reason(struct net_device *dev, const char *string_num);
3236 #endif /* DHD_HANG_SEND_UP_TEST */
3237 
3238 #ifdef DHD_RND_DEBUG
3239 int dhd_dump_rnd_info(dhd_pub_t *dhd, uint8 *rnd_buf, uint32 rnd_len);
3240 int dhd_get_rnd_info(dhd_pub_t *dhd);
3241 #endif /* DHD_RND_DEBUG */
3242 
3243 #ifdef DHD_WAKE_STATUS
3244 wake_counts_t* dhd_get_wakecount(dhd_pub_t *dhdp);
3245 #endif /* DHD_WAKE_STATUS */
3246 extern int dhd_get_random_bytes(uint8 *buf, uint len);
3247 #if defined(DHD_BLOB_EXISTENCE_CHECK)
3248 extern void dhd_set_blob_support(dhd_pub_t *dhdp, char *fw_path);
3249 #endif /* DHD_BLOB_EXISTENCE_CHECK */
3250 
3251 /* configuration of ecounters. API's tp start/stop. currently supported only for linux */
3252 extern int dhd_ecounter_configure(dhd_pub_t *dhd, bool enable);
3253 extern int dhd_start_ecounters(dhd_pub_t *dhd);
3254 extern int dhd_stop_ecounters(dhd_pub_t *dhd);
3255 extern int dhd_start_event_ecounters(dhd_pub_t *dhd);
3256 extern int dhd_stop_event_ecounters(dhd_pub_t *dhd);
3257 
3258 int dhd_get_preserve_log_numbers(dhd_pub_t *dhd, uint32 *logset_mask);
3259 
3260 #ifdef DHD_LOG_DUMP
3261 void dhd_schedule_log_dump(dhd_pub_t *dhdp, void *type);
3262 void dhd_log_dump_trigger(dhd_pub_t *dhdp, int subcmd);
3263 int dhd_log_dump_ring_to_file(dhd_pub_t *dhdp, void *ring_ptr, void *file,
3264 		unsigned long *file_posn, log_dump_section_hdr_t *sec_hdr, char *text_hdr,
3265 		uint32 sec_type);
3266 int dhd_dump_debug_ring(dhd_pub_t *dhdp, void *ring_ptr, const void *user_buf,
3267 		log_dump_section_hdr_t *sec_hdr, char *text_hdr, int buflen, uint32 sec_type);
3268 int dhd_log_dump_cookie_to_file(dhd_pub_t *dhdp, void *fp,
3269 	const void *user_buf, unsigned long *f_pos);
3270 int dhd_log_dump_cookie(dhd_pub_t *dhdp, const void *user_buf);
3271 uint32 dhd_log_dump_cookie_len(dhd_pub_t *dhdp);
3272 int dhd_logdump_cookie_init(dhd_pub_t *dhdp, uint8 *buf, uint32 buf_size);
3273 void dhd_logdump_cookie_deinit(dhd_pub_t *dhdp);
3274 void dhd_logdump_cookie_save(dhd_pub_t *dhdp, char *cookie, char *type);
3275 int dhd_logdump_cookie_get(dhd_pub_t *dhdp, char *ret_cookie, uint32 buf_size);
3276 int dhd_logdump_cookie_count(dhd_pub_t *dhdp);
3277 int dhd_get_dld_log_dump(void *dev, dhd_pub_t *dhdp, const void *user_buf, void *fp,
3278 	uint32 len, int type, void *pos);
3279 int dhd_print_ext_trap_data(void *dev, dhd_pub_t *dhdp, const void *user_buf,
3280 	void *fp, uint32 len, void *pos);
3281 int dhd_print_dump_data(void *dev, dhd_pub_t *dhdp, const void *user_buf,
3282 	void *fp, uint32 len, void *pos);
3283 int dhd_print_cookie_data(void *dev, dhd_pub_t *dhdp, const void *user_buf,
3284 	void *fp, uint32 len, void *pos);
3285 int dhd_print_health_chk_data(void *dev, dhd_pub_t *dhdp, const void *user_buf,
3286 	void *fp, uint32 len, void *pos);
3287 int dhd_print_time_str(const void *user_buf, void *fp, uint32 len, void *pos);
3288 #ifdef DHD_DUMP_PCIE_RINGS
3289 int dhd_print_flowring_data(void *dev, dhd_pub_t *dhdp, const void *user_buf,
3290 	void *fp, uint32 len, void *pos);
3291 uint32 dhd_get_flowring_len(void *ndev, dhd_pub_t *dhdp);
3292 #endif /* DHD_DUMP_PCIE_RINGS */
3293 #ifdef DHD_STATUS_LOGGING
3294 extern int dhd_print_status_log_data(void *dev, dhd_pub_t *dhdp,
3295 	const void *user_buf, void *fp, uint32 len, void *pos);
3296 extern uint32 dhd_get_status_log_len(void *ndev, dhd_pub_t *dhdp);
3297 #endif /* DHD_STATUS_LOGGING */
3298 int dhd_print_ecntrs_data(void *dev, dhd_pub_t *dhdp, const void *user_buf,
3299 	void *fp, uint32 len, void *pos);
3300 int dhd_print_rtt_data(void *dev, dhd_pub_t *dhdp, const void *user_buf,
3301 	void *fp, uint32 len, void *pos);
3302 int dhd_get_debug_dump_file_name(void *dev, dhd_pub_t *dhdp,
3303 	char *dump_path, int size);
3304 uint32 dhd_get_ext_trap_len(void *ndev, dhd_pub_t *dhdp);
3305 uint32 dhd_get_time_str_len(void);
3306 uint32 dhd_get_health_chk_len(void *ndev, dhd_pub_t *dhdp);
3307 uint32 dhd_get_dhd_dump_len(void *ndev, dhd_pub_t *dhdp);
3308 uint32 dhd_get_cookie_log_len(void *ndev, dhd_pub_t *dhdp);
3309 uint32 dhd_get_ecntrs_len(void *ndev, dhd_pub_t *dhdp);
3310 uint32 dhd_get_rtt_len(void *ndev, dhd_pub_t *dhdp);
3311 uint32 dhd_get_dld_len(int log_type);
3312 void dhd_init_sec_hdr(log_dump_section_hdr_t *sec_hdr);
3313 extern char *dhd_log_dump_get_timestamp(void);
3314 bool dhd_log_dump_ecntr_enabled(void);
3315 bool dhd_log_dump_rtt_enabled(void);
3316 void dhd_nla_put_sssr_dump_len(void *ndev, uint32 *arr_len);
3317 int dhd_get_debug_dump(void *dev, const void *user_buf, uint32 len, int type);
3318 int
3319 dhd_sssr_dump_d11_buf_before(void *dev, const void *user_buf, uint32 len, int core);
3320 int
3321 dhd_sssr_dump_d11_buf_after(void *dev, const void *user_buf, uint32 len, int core);
3322 int
3323 dhd_sssr_dump_dig_buf_before(void *dev, const void *user_buf, uint32 len);
3324 int
3325 dhd_sssr_dump_dig_buf_after(void *dev, const void *user_buf, uint32 len);
3326 #ifdef DHD_PKT_LOGGING
3327 extern int dhd_os_get_pktlog_dump(void *dev, const void *user_buf, uint32 len);
3328 extern uint32 dhd_os_get_pktlog_dump_size(struct net_device *dev);
3329 extern void dhd_os_get_pktlogdump_filename(struct net_device *dev, char *dump_path, int len);
3330 #endif /* DHD_PKT_LOGGING */
3331 
3332 #ifdef DNGL_AXI_ERROR_LOGGING
3333 extern int dhd_os_get_axi_error_dump(void *dev, const void *user_buf, uint32 len);
3334 extern int dhd_os_get_axi_error_dump_size(struct net_device *dev);
3335 extern void dhd_os_get_axi_error_filename(struct net_device *dev, char *dump_path, int len);
3336 #endif /*  DNGL_AXI_ERROR_LOGGING */
3337 
3338 #endif /* DHD_LOG_DUMP */
3339 int dhd_export_debug_data(void *mem_buf, void *fp, const void *user_buf, int buf_len, void *pos);
3340 #define DHD_PCIE_CONFIG_SAVE(bus)	pci_save_state(bus->dev)
3341 #define DHD_PCIE_CONFIG_RESTORE(bus)	pci_restore_state(bus->dev)
3342 
3343 #ifdef BIGDATA_SOFTAP
3344 void dhd_schedule_gather_ap_stadata(void *bcm_cfg, void *ndev, const wl_event_msg_t *e);
3345 #endif /* BIGDATA_SOFTAP */
3346 
3347 typedef struct dhd_pkt_parse {
3348 	uint32 proto;	/* Network layer protocol */
3349 	uint32 t1;	/* n-tuple */
3350 	uint32 t2;
3351 } dhd_pkt_parse_t;
3352 
3353 /* ========= RING API functions : exposed to others ============= */
3354 #define DHD_RING_TYPE_FIXED		1
3355 #define DHD_RING_TYPE_SINGLE_IDX	2
3356 uint32 dhd_ring_get_hdr_size(void);
3357 void *dhd_ring_init(dhd_pub_t *dhdp, uint8 *buf, uint32 buf_size, uint32 elem_size,
3358 	uint32 elem_cnt, uint32 type);
3359 void dhd_ring_deinit(dhd_pub_t *dhdp, void *_ring);
3360 void *dhd_ring_get_first(void *_ring);
3361 void dhd_ring_free_first(void *_ring);
3362 void dhd_ring_set_read_idx(void *_ring, uint32 read_idx);
3363 void dhd_ring_set_write_idx(void *_ring, uint32 write_idx);
3364 uint32 dhd_ring_get_read_idx(void *_ring);
3365 uint32 dhd_ring_get_write_idx(void *_ring);
3366 void *dhd_ring_get_last(void *_ring);
3367 void *dhd_ring_get_next(void *_ring, void *cur);
3368 void *dhd_ring_get_prev(void *_ring, void *cur);
3369 void *dhd_ring_get_empty(void *_ring);
3370 int dhd_ring_get_cur_size(void *_ring);
3371 void dhd_ring_lock(void *ring, void *fist_ptr, void *last_ptr);
3372 void dhd_ring_lock_free(void *ring);
3373 void *dhd_ring_lock_get_first(void *_ring);
3374 void *dhd_ring_lock_get_last(void *_ring);
3375 int dhd_ring_lock_get_count(void *_ring);
3376 void dhd_ring_lock_free_first(void *ring);
3377 void dhd_ring_whole_lock(void *ring);
3378 void dhd_ring_whole_unlock(void *ring);
3379 
3380 #define DHD_DUMP_TYPE_NAME_SIZE		32
3381 #define DHD_DUMP_FILE_PATH_SIZE		256
3382 #define DHD_DUMP_FILE_COUNT_MAX		5
3383 #define DHD_DUMP_TYPE_COUNT_MAX		10
3384 
3385 #ifdef DHD_DUMP_MNGR
3386 typedef struct _DFM_elem {
3387 	char type_name[DHD_DUMP_TYPE_NAME_SIZE];
3388 	char file_path[DHD_DUMP_FILE_COUNT_MAX][DHD_DUMP_FILE_PATH_SIZE];
3389 	int file_idx;
3390 } DFM_elem_t;
3391 
3392 typedef struct _dhd_dump_file_manage {
3393 	DFM_elem_t elems[DHD_DUMP_TYPE_COUNT_MAX];
3394 } dhd_dump_file_manage_t;
3395 
3396 extern void dhd_dump_file_manage_enqueue(dhd_pub_t *dhd, char *dump_path, char *fname);
3397 #endif /* DHD_DUMP_MNGR */
3398 
3399 #ifdef PKT_FILTER_SUPPORT
3400 extern void dhd_pktfilter_offload_set(dhd_pub_t * dhd, char *arg);
3401 extern void dhd_pktfilter_offload_enable(dhd_pub_t * dhd, char *arg, int enable, int master_mode);
3402 extern void dhd_pktfilter_offload_delete(dhd_pub_t *dhd, int id);
3403 #endif // endif
3404 
3405 #ifdef DHD_DUMP_PCIE_RINGS
3406 extern int dhd_d2h_h2d_ring_dump(dhd_pub_t *dhd, void *file, const void *user_buf,
3407 	unsigned long *file_posn, bool file_write);
3408 #endif /* DHD_DUMP_PCIE_RINGS */
3409 
3410 #ifdef EWP_EDL
3411 #define DHD_EDL_RING_SIZE (D2HRING_EDL_MAX_ITEM * D2HRING_EDL_ITEMSIZE)
3412 int dhd_event_logtrace_process_edl(dhd_pub_t *dhdp, uint8 *data,
3413 		void *evt_decode_data);
3414 int dhd_edl_mem_init(dhd_pub_t *dhd);
3415 void dhd_edl_mem_deinit(dhd_pub_t *dhd);
3416 void dhd_prot_edl_ring_tcm_rd_update(dhd_pub_t *dhd);
3417 #define DHD_EDL_MEM_INIT(dhdp) dhd_edl_mem_init(dhdp)
3418 #define DHD_EDL_MEM_DEINIT(dhdp) dhd_edl_mem_deinit(dhdp)
3419 #define DHD_EDL_RING_TCM_RD_UPDATE(dhdp) \
3420 	dhd_prot_edl_ring_tcm_rd_update(dhdp)
3421 #else
3422 #define DHD_EDL_MEM_INIT(dhdp) do { /* noop */ } while (0)
3423 #define DHD_EDL_MEM_DEINIT(dhdp) do { /* noop */ } while (0)
3424 #define DHD_EDL_RING_TCM_RD_UPDATE(dhdp) do { /* noop */ } while (0)
3425 #endif /* EWP_EDL */
3426 
3427 void dhd_schedule_logtrace(void *dhd_info);
3428 int dhd_print_fw_ver_from_file(dhd_pub_t *dhdp, char *fwpath);
3429 
3430 #define HD_PREFIX_SIZE  2   /* hexadecimal prefix size */
3431 #define HD_BYTE_SIZE    2   /* hexadecimal byte size */
3432 
3433 #if defined(DHD_H2D_LOG_TIME_SYNC)
3434 void dhd_h2d_log_time_sync_deferred_wq_schedule(dhd_pub_t *dhdp);
3435 void dhd_h2d_log_time_sync(dhd_pub_t *dhdp);
3436 #endif /* DHD_H2D_LOG_TIME_SYNC */
3437 extern void dhd_cleanup_if(struct net_device *net);
3438 
3439 #ifdef DNGL_AXI_ERROR_LOGGING
3440 extern void dhd_axi_error(dhd_pub_t *dhd);
3441 #ifdef DHD_USE_WQ_FOR_DNGL_AXI_ERROR
3442 extern void dhd_axi_error_dispatch(dhd_pub_t *dhdp);
3443 #endif /* DHD_USE_WQ_FOR_DNGL_AXI_ERROR */
3444 #endif /* DNGL_AXI_ERROR_LOGGING */
3445 
3446 #ifdef DHD_HP2P
3447 extern unsigned long dhd_os_hp2plock(dhd_pub_t *pub);
3448 extern void dhd_os_hp2punlock(dhd_pub_t *pub, unsigned long flags);
3449 #endif /* DHD_HP2P */
3450 extern struct dhd_if * dhd_get_ifp(dhd_pub_t *dhdp, uint32 ifidx);
3451 
3452 #ifdef DHD_STATUS_LOGGING
3453 #include <dhd_statlog.h>
3454 #else
3455 #define ST(x)		0
3456 #define STDIR(x)	0
3457 #define DHD_STATLOG_CTRL(dhdp, stat, ifidx, reason) \
3458 	do { /* noop */ } while (0)
3459 #define DHD_STATLOG_DATA(dhdp, stat, ifidx, dir, cond) \
3460 	do { BCM_REFERENCE(cond); } while (0)
3461 #define DHD_STATLOG_DATA_RSN(dhdp, stat, ifidx, dir, reason) \
3462 	do { /* noop */ } while (0)
3463 #endif /* DHD_STATUS_LOGGING */
3464 
3465 #ifdef CONFIG_SILENT_ROAM
3466 extern int dhd_sroam_set_mon(dhd_pub_t *dhd, bool set);
3467 typedef wlc_sroam_info_v1_t wlc_sroam_info_t;
3468 #endif /* CONFIG_SILENT_ROAM */
3469 
3470 #ifdef SUPPORT_SET_TID
3471 enum dhd_set_tid_mode {
3472 	/* Disalbe changing TID */
3473 	SET_TID_OFF = 0,
3474 	/* Change TID for all UDP frames */
3475 	SET_TID_ALL_UDP,
3476 	/* Change TID for UDP frames based on UID */
3477 	SET_TID_BASED_ON_UID
3478 };
3479 extern void dhd_set_tid_based_on_uid(dhd_pub_t *dhdp, void *pkt);
3480 #endif /* SUPPORT_SET_TID */
3481 
3482 #ifdef DHD_DUMP_FILE_WRITE_FROM_KERNEL
3483 #define FILE_NAME_HAL_TAG	""
3484 #else
3485 #define FILE_NAME_HAL_TAG	"_hal" /* The tag name concatenated by HAL */
3486 #endif /* DHD_DUMP_FILE_WRITE_FROM_KERNEL */
3487 
3488 #if defined(DISABLE_HE_ENAB) || defined(CUSTOM_CONTROL_HE_ENAB)
3489 extern int dhd_control_he_enab(dhd_pub_t * dhd, uint8 he_enab);
3490 extern uint8 control_he_enab;
3491 #endif /* DISABLE_HE_ENAB  || CUSTOM_CONTROL_HE_ENAB */
3492 
3493 #if defined(BCMSDIO)
3494 void dhd_set_role(dhd_pub_t *dhdp, int role, int bssidx);
3495 #endif /* BCMSDIO */
3496 #endif /* _dhd_h_ */
3497