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