1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Broadcom Dongle Host Driver (DHD), Linux-specific network interface
4 * Basically selected code segments from usb-cdc.c and usb-rndis.c
5 *
6 * Copyright (C) 1999-2019, Broadcom.
7 *
8 * Unless you and Broadcom execute a separate written software license
9 * agreement governing use of this software, this software is licensed to you
10 * under the terms of the GNU General Public License version 2 (the "GPL"),
11 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
12 * following added to such license:
13 *
14 * As a special exception, the copyright holders of this software give you
15 * permission to link this software with independent modules, and to copy and
16 * distribute the resulting executable under terms of your choice, provided that
17 * you also meet, for each linked independent module, the terms and conditions of
18 * the license of that module. An independent module is a module which is not
19 * derived from this software. The special exception does not apply to any
20 * modifications of the software.
21 *
22 * Notwithstanding the above, under no circumstances may you combine this
23 * software in any way with any other Broadcom software provided under a license
24 * other than the GPL, without Broadcom's express prior written consent.
25 *
26 *
27 * <<Broadcom-WL-IPTag/Open:>>
28 *
29 * $Id: dhd_linux.c 822756 2019-05-30 13:20:26Z $
30 */
31
32 #include <typedefs.h>
33 #include <linuxver.h>
34 #include <osl.h>
35 #include <bcmstdlib_s.h>
36 #ifdef SHOW_LOGTRACE
37 #include <linux/syscalls.h>
38 #include <event_log.h>
39 #endif /* SHOW_LOGTRACE */
40
41 #if defined(PCIE_FULL_DONGLE) || defined(SHOW_LOGTRACE)
42 #include <bcmmsgbuf.h>
43 #endif /* PCIE_FULL_DONGLE */
44
45 #include <linux/init.h>
46 #include <linux/kernel.h>
47 #include <linux/slab.h>
48 #include <linux/skbuff.h>
49 #include <linux/netdevice.h>
50 #include <linux/inetdevice.h>
51 #include <linux/rtnetlink.h>
52 #include <linux/etherdevice.h>
53 #include <linux/random.h>
54 #include <linux/spinlock.h>
55 #include <linux/ethtool.h>
56 #include <linux/fcntl.h>
57 #include <linux/fs.h>
58 #include <linux/ip.h>
59 #include <linux/reboot.h>
60 #include <linux/notifier.h>
61 #include <linux/irq.h>
62 #include <net/addrconf.h>
63 #ifdef ENABLE_ADAPTIVE_SCHED
64 #include <linux/cpufreq.h>
65 #endif /* ENABLE_ADAPTIVE_SCHED */
66 #include <linux/rtc.h>
67 #include <linux/namei.h>
68 #include <linux/uaccess.h>
69 #include <asm/unaligned.h>
70 #include <dhd_linux_priv.h>
71
72 #include <epivers.h>
73 #include <bcmutils.h>
74 #include <bcmendian.h>
75 #include <bcmdevs.h>
76 #include <bcmiov.h>
77
78 #include <ethernet.h>
79 #include <bcmevent.h>
80 #include <vlan.h>
81 #include <802.3.h>
82
83 #include <dhd_linux_wq.h>
84 #include <dhd.h>
85 #include <dhd_linux.h>
86 #include <dhd_linux_pktdump.h>
87 #ifdef DHD_WET
88 #include <dhd_wet.h>
89 #endif /* DHD_WET */
90 #ifdef PCIE_FULL_DONGLE
91 #include <dhd_flowring.h>
92 #endif // endif
93 #include <dhd_bus.h>
94 #include <dhd_proto.h>
95 #include <dhd_config.h>
96 #ifdef WL_ESCAN
97 #include <wl_escan.h>
98 #endif
99 #include <dhd_dbg.h>
100 #include <dhd_dbg_ring.h>
101 #include <dhd_debug.h>
102 #ifdef CONFIG_HAS_WAKELOCK
103 #include <linux/wakelock.h>
104 #endif // endif
105 #if defined(WL_CFG80211)
106 #include <wl_cfg80211.h>
107 #endif /* WL_CFG80211 */
108 #ifdef PNO_SUPPORT
109 #include <dhd_pno.h>
110 #endif // endif
111 #ifdef RTT_SUPPORT
112 #include <dhd_rtt.h>
113 #endif // endif
114
115 #ifdef CSI_SUPPORT
116 #include <dhd_csi.h>
117 #endif /* CSI_SUPPORT */
118
119 #ifdef CONFIG_COMPAT
120 #include <linux/compat.h>
121 #endif // endif
122
123 #if defined(CONFIG_SOC_EXYNOS8895) || defined(CONFIG_SOC_EXYNOS9810) || \
124 defined(CONFIG_SOC_EXYNOS9820)
125 #include <linux/exynos-pci-ctrl.h>
126 #endif /* CONFIG_SOC_EXYNOS8895 || CONFIG_SOC_EXYNOS9810 || CONFIG_SOC_EXYNOS9820 */
127
128 #ifdef DHD_L2_FILTER
129 #include <bcmicmp.h>
130 #include <bcm_l2_filter.h>
131 #include <dhd_l2_filter.h>
132 #endif /* DHD_L2_FILTER */
133
134 #ifdef DHD_PSTA
135 #include <dhd_psta.h>
136 #endif /* DHD_PSTA */
137
138 #ifdef AMPDU_VO_ENABLE
139 #include <802.1d.h>
140 #endif /* AMPDU_VO_ENABLE */
141
142 #if defined(DHDTCPACK_SUPPRESS) || defined(DHDTCPSYNC_FLOOD_BLK)
143 #include <dhd_ip.h>
144 #endif /* DHDTCPACK_SUPPRESS || DHDTCPSYNC_FLOOD_BLK */
145 #include <dhd_daemon.h>
146 #ifdef DHD_4WAYM4_FAIL_DISCONNECT
147 #include <eapol.h>
148 #endif /* DHD_4WAYM4_FAIL_DISCONNECT */
149 #ifdef DHD_DEBUG_PAGEALLOC
150 typedef void (*page_corrupt_cb_t)(void *handle, void *addr_corrupt, size_t len);
151 void dhd_page_corrupt_cb(void *handle, void *addr_corrupt, size_t len);
152 extern void register_page_corrupt_cb(page_corrupt_cb_t cb, void* handle);
153 #endif /* DHD_DEBUG_PAGEALLOC */
154
155 #define IP_PROT_RESERVED 0xFF
156
157 #ifdef DHD_4WAYM4_FAIL_DISCONNECT
158 static void dhd_m4_state_handler(struct work_struct * work);
159 #endif /* DHD_4WAYM4_FAIL_DISCONNECT */
160
161 #ifdef DHDTCPSYNC_FLOOD_BLK
162 static void dhd_blk_tsfl_handler(struct work_struct * work);
163 #endif /* DHDTCPSYNC_FLOOD_BLK */
164
165 #ifdef WL_NATOE
166 #include <dhd_linux_nfct.h>
167 #endif /* WL_NATOE */
168
169 #if defined(SOFTAP)
170 extern bool ap_cfg_running;
171 extern bool ap_fw_loaded;
172 #endif // endif
173
174 #ifdef FIX_CPU_MIN_CLOCK
175 #include <linux/pm_qos.h>
176 #endif /* FIX_CPU_MIN_CLOCK */
177
178 #ifdef SET_RANDOM_MAC_SOFTAP
179 #ifndef CONFIG_DHD_SET_RANDOM_MAC_VAL
180 #define CONFIG_DHD_SET_RANDOM_MAC_VAL 0x001A11
181 #endif // endif
182 static u32 vendor_oui = CONFIG_DHD_SET_RANDOM_MAC_VAL;
183 #endif /* SET_RANDOM_MAC_SOFTAP */
184
185 #ifdef ENABLE_ADAPTIVE_SCHED
186 #define DEFAULT_CPUFREQ_THRESH 1000000 /* threshold frequency : 1000000 = 1GHz */
187 #ifndef CUSTOM_CPUFREQ_THRESH
188 #define CUSTOM_CPUFREQ_THRESH DEFAULT_CPUFREQ_THRESH
189 #endif /* CUSTOM_CPUFREQ_THRESH */
190 #endif /* ENABLE_ADAPTIVE_SCHED */
191
192 /* enable HOSTIP cache update from the host side when an eth0:N is up */
193 #define AOE_IP_ALIAS_SUPPORT 1
194
195 #ifdef PROP_TXSTATUS
196 #include <wlfc_proto.h>
197 #include <dhd_wlfc.h>
198 #endif // endif
199
200 #include <wl_android.h>
201
202 /* Maximum STA per radio */
203 #define DHD_MAX_STA 32
204
205 const uint8 wme_fifo2ac[] = { 0, 1, 2, 3, 1, 1 };
206 const uint8 prio2fifo[8] = { 1, 0, 0, 1, 2, 2, 3, 3 };
207 #define WME_PRIO2AC(prio) wme_fifo2ac[prio2fifo[(prio)]]
208
209 #ifdef ARP_OFFLOAD_SUPPORT
210 void aoe_update_host_ipv4_table(dhd_pub_t *dhd_pub, u32 ipa, bool add, int idx);
211 static int dhd_inetaddr_notifier_call(struct notifier_block *this,
212 unsigned long event, void *ptr);
213 static struct notifier_block dhd_inetaddr_notifier = {
214 .notifier_call = dhd_inetaddr_notifier_call
215 };
216 /* to make sure we won't register the same notifier twice, otherwise a loop is likely to be
217 * created in kernel notifier link list (with 'next' pointing to itself)
218 */
219 static bool dhd_inetaddr_notifier_registered = FALSE;
220 #endif /* ARP_OFFLOAD_SUPPORT */
221
222 #if defined(CONFIG_IPV6) && defined(IPV6_NDO_SUPPORT)
223 int dhd_inet6addr_notifier_call(struct notifier_block *this,
224 unsigned long event, void *ptr);
225 static struct notifier_block dhd_inet6addr_notifier = {
226 .notifier_call = dhd_inet6addr_notifier_call
227 };
228 /* to make sure we won't register the same notifier twice, otherwise a loop is likely to be
229 * created in kernel notifier link list (with 'next' pointing to itself)
230 */
231 static bool dhd_inet6addr_notifier_registered = FALSE;
232 #endif /* CONFIG_IPV6 && IPV6_NDO_SUPPORT */
233
234 #ifdef CONFIG_AP6XXX_WIFI6_HDF
235 #define DHD_DEV_PRIV_CFG(dev) DHD_DEV_PRIV(dev)
236 #else
237 #define DHD_DEV_PRIV_CFG(dev) netdev_priv(dev)
238 #endif
239
240 #if defined(CONFIG_PM_SLEEP)
241 #include <linux/suspend.h>
242 volatile bool dhd_mmc_suspend = FALSE;
243 DECLARE_WAIT_QUEUE_HEAD(dhd_dpc_wait);
244 #endif /* defined(CONFIG_PM_SLEEP) */
245
246 #if defined(OOB_INTR_ONLY) || defined(BCMSPI_ANDROID) || defined(FORCE_WOWLAN)
247 extern void dhd_enable_oob_intr(struct dhd_bus *bus, bool enable);
248 #endif /* defined(OOB_INTR_ONLY) || defined(BCMSPI_ANDROID) */
249 static void dhd_hang_process(struct work_struct *work_data);
250 MODULE_LICENSE("GPL and additional rights");
251
252 #if defined(MULTIPLE_SUPPLICANT)
253 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
254 DEFINE_MUTEX(_dhd_mutex_lock_);
255 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) */
256 #endif
257 static int dhd_suspend_resume_helper(struct dhd_info *dhd, int val, int force);
258
259 #ifdef CONFIG_BCM_DETECT_CONSECUTIVE_HANG
260 #define MAX_CONSECUTIVE_HANG_COUNTS 5
261 #endif /* CONFIG_BCM_DETECT_CONSECUTIVE_HANG */
262
263 #include <dhd_bus.h>
264
265 #ifdef DHD_ULP
266 #include <dhd_ulp.h>
267 #endif /* DHD_ULP */
268
269 #ifndef PROP_TXSTATUS
270 #define DBUS_RX_BUFFER_SIZE_DHD(net) (net->mtu + net->hard_header_len + dhd->pub.hdrlen)
271 #else
272 #define DBUS_RX_BUFFER_SIZE_DHD(net) (net->mtu + net->hard_header_len + dhd->pub.hdrlen + 128)
273 #endif // endif
274
275 #ifdef PROP_TXSTATUS
276 extern bool dhd_wlfc_skip_fc(void * dhdp, uint8 idx);
277 extern void dhd_wlfc_plat_init(void *dhd);
278 extern void dhd_wlfc_plat_deinit(void *dhd);
279 #endif /* PROP_TXSTATUS */
280 #ifdef USE_DYNAMIC_F2_BLKSIZE
281 extern uint sd_f2_blocksize;
282 extern int dhdsdio_func_blocksize(dhd_pub_t *dhd, int function_num, int block_size);
283 #endif /* USE_DYNAMIC_F2_BLKSIZE */
284
285 /* Linux wireless extension support */
286 #if defined(WL_WIRELESS_EXT)
287 #include <wl_iw.h>
288 extern wl_iw_extra_params_t g_wl_iw_params;
289 #endif /* defined(WL_WIRELESS_EXT) */
290
291 #ifdef CONFIG_PARTIALSUSPEND_SLP
292 #include <linux/partialsuspend_slp.h>
293 #define CONFIG_HAS_EARLYSUSPEND
294 #define DHD_USE_EARLYSUSPEND
295 #define register_early_suspend register_pre_suspend
296 #define unregister_early_suspend unregister_pre_suspend
297 #define early_suspend pre_suspend
298 #define EARLY_SUSPEND_LEVEL_BLANK_SCREEN 50
299 #else
300 #if defined(CONFIG_HAS_EARLYSUSPEND) && defined(DHD_USE_EARLYSUSPEND)
301 #include <linux/earlysuspend.h>
302 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) && defined(DHD_USE_EARLYSUSPEND) */
303 #endif /* CONFIG_PARTIALSUSPEND_SLP */
304
305 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
306 #include <linux/nl80211.h>
307 #endif /* OEM_ANDROID && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0)) */
308
309 #if defined(PKT_FILTER_SUPPORT) && defined(APF)
310 static int __dhd_apf_add_filter(struct net_device *ndev, uint32 filter_id,
311 u8* program, uint32 program_len);
312 static int __dhd_apf_config_filter(struct net_device *ndev, uint32 filter_id,
313 uint32 mode, uint32 enable);
314 static int __dhd_apf_delete_filter(struct net_device *ndev, uint32 filter_id);
315 #endif /* PKT_FILTER_SUPPORT && APF */
316
317 #if defined(WL_CFG80211) && defined(DHD_FILE_DUMP_EVENT) && defined(DHD_FW_COREDUMP)
318 static int dhd_wait_for_file_dump(dhd_pub_t *dhdp);
319 #endif /* WL_CFG80211 && DHD_FILE_DUMP_EVENT && DHD_FW_COREDUMP */
320
321 #if defined(ARGOS_NOTIFY_CB)
322 /* ARGOS notifer data */
323 static struct notifier_block argos_wifi; /* STA */
324 static struct notifier_block argos_p2p; /* P2P */
325 argos_rps_ctrl argos_rps_ctrl_data;
326 #endif // endif
327
328 #ifdef DHD_FW_COREDUMP
329 static int dhd_mem_dump(void *dhd_info, void *event_info, u8 event);
330 #endif /* DHD_FW_COREDUMP */
331
332 #ifdef DHD_LOG_DUMP
333
334 struct dhd_log_dump_buf g_dld_buf[DLD_BUFFER_NUM];
335
336 /* Only header for log dump buffers is stored in array
337 * header for sections like 'dhd dump', 'ext trap'
338 * etc, is not in the array, because they are not log
339 * ring buffers
340 */
341 dld_hdr_t dld_hdrs[DLD_BUFFER_NUM] = {
342 {GENERAL_LOG_HDR, LOG_DUMP_SECTION_GENERAL},
343 {PRESERVE_LOG_HDR, LOG_DUMP_SECTION_PRESERVE},
344 {SPECIAL_LOG_HDR, LOG_DUMP_SECTION_SPECIAL}
345 };
346
347 static int dld_buf_size[DLD_BUFFER_NUM] = {
348 LOG_DUMP_GENERAL_MAX_BUFSIZE, /* DLD_BUF_TYPE_GENERAL */
349 LOG_DUMP_PRESERVE_MAX_BUFSIZE, /* DLD_BUF_TYPE_PRESERVE */
350 LOG_DUMP_SPECIAL_MAX_BUFSIZE, /* DLD_BUF_TYPE_SPECIAL */
351 };
352
353 static void dhd_log_dump_init(dhd_pub_t *dhd);
354 static void dhd_log_dump_deinit(dhd_pub_t *dhd);
355 static void dhd_log_dump(void *handle, void *event_info, u8 event);
356 static int do_dhd_log_dump(dhd_pub_t *dhdp, log_dump_type_t *type);
357 static int dhd_log_flush(dhd_pub_t *dhdp, log_dump_type_t *type);
358 static void dhd_get_time_str(dhd_pub_t *dhdp, char *time_str, int size);
359 void dhd_get_debug_dump_len(void *handle, struct sk_buff *skb, void *event_info, u8 event);
360 void cfgvendor_log_dump_len(dhd_pub_t *dhdp, log_dump_type_t *type, struct sk_buff *skb);
361 static void dhd_print_buf_addr(dhd_pub_t *dhdp, char *name, void *buf, unsigned int size);
362 static void dhd_log_dump_buf_addr(dhd_pub_t *dhdp, log_dump_type_t *type);
363 #endif /* DHD_LOG_DUMP */
364
365 #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
366 #include <linux/workqueue.h>
367 #include <linux/pm_runtime.h>
368 #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
369
370 #ifdef DHD_DEBUG_UART
371 #include <linux/kmod.h>
372 #define DHD_DEBUG_UART_EXEC_PATH "/system/bin/wldu"
373 static void dhd_debug_uart_exec_rd(void *handle, void *event_info, u8 event);
374 static void dhd_debug_uart_exec(dhd_pub_t *dhdp, char *cmd);
375 #endif /* DHD_DEBUG_UART */
376
377 static int dhd_reboot_callback(struct notifier_block *this, unsigned long code, void *unused);
378 static struct notifier_block dhd_reboot_notifier = {
379 .notifier_call = dhd_reboot_callback,
380 .priority = 1,
381 };
382
383 #ifdef BCMPCIE
384 static int is_reboot = 0;
385 #endif /* BCMPCIE */
386
387 dhd_pub_t *g_dhd_pub = NULL;
388
389 #if defined(BT_OVER_SDIO)
390 #include "dhd_bt_interface.h"
391 #endif /* defined (BT_OVER_SDIO) */
392
393 #ifdef WL_STATIC_IF
394 bool dhd_is_static_ndev(dhd_pub_t *dhdp, struct net_device *ndev);
395 #endif /* WL_STATIC_IF */
396
397 atomic_t exit_in_progress = ATOMIC_INIT(0);
398
399 static void dhd_process_daemon_msg(struct sk_buff *skb);
400 static void dhd_destroy_to_notifier_skt(void);
401 static int dhd_create_to_notifier_skt(void);
402 static struct sock *nl_to_event_sk = NULL;
403 int sender_pid = 0;
404
405 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0))
406 struct netlink_kernel_cfg dhd_netlink_cfg = {
407 .groups = 1,
408 .input = dhd_process_daemon_msg,
409 };
410 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0)) */
411
412 #if defined(BT_OVER_SDIO)
413 /* Flag to indicate if driver is initialized */
414 uint dhd_driver_init_done = TRUE;
415 #else
416 /* Flag to indicate if driver is initialized */
417 uint dhd_driver_init_done = FALSE;
418 #endif // endif
419 /* Flag to indicate if we should download firmware on driver load */
420 uint dhd_download_fw_on_driverload = TRUE;
421
422 /* Definitions to provide path to the firmware and nvram
423 * example nvram_path[MOD_PARAM_PATHLEN]="/projects/wlan/nvram.txt"
424 */
425 char firmware_path[MOD_PARAM_PATHLEN];
426 char nvram_path[MOD_PARAM_PATHLEN];
427 char clm_path[MOD_PARAM_PATHLEN];
428 char config_path[MOD_PARAM_PATHLEN];
429 #ifdef DHD_UCODE_DOWNLOAD
430 char ucode_path[MOD_PARAM_PATHLEN];
431 #endif /* DHD_UCODE_DOWNLOAD */
432
433 module_param_string(clm_path, clm_path, MOD_PARAM_PATHLEN, 0660);
434
435 /* backup buffer for firmware and nvram path */
436 char fw_bak_path[MOD_PARAM_PATHLEN];
437 char nv_bak_path[MOD_PARAM_PATHLEN];
438
439 /* information string to keep firmware, chio, cheip version info visiable from log */
440 char info_string[MOD_PARAM_INFOLEN];
441 module_param_string(info_string, info_string, MOD_PARAM_INFOLEN, 0444);
442 int op_mode = 0;
443 int disable_proptx = 0;
444 module_param(op_mode, int, 0644);
445 extern int wl_control_wl_start(struct net_device *dev);
446 #if defined(BCMLXSDMMC) || defined(BCMDBUS)
447 struct semaphore dhd_registration_sem;
448 #endif /* BCMXSDMMC */
449
450 #ifdef DHD_LOG_DUMP
451 int logdump_max_filesize = LOG_DUMP_MAX_FILESIZE;
452 module_param(logdump_max_filesize, int, 0644);
453 int logdump_max_bufsize = LOG_DUMP_GENERAL_MAX_BUFSIZE;
454 module_param(logdump_max_bufsize, int, 0644);
455 int logdump_prsrv_tailsize = DHD_LOG_DUMP_MAX_TAIL_FLUSH_SIZE;
456 int logdump_periodic_flush = FALSE;
457 module_param(logdump_periodic_flush, int, 0644);
458 #ifdef EWP_ECNTRS_LOGGING
459 int logdump_ecntr_enable = TRUE;
460 #else
461 int logdump_ecntr_enable = FALSE;
462 #endif /* EWP_ECNTRS_LOGGING */
463 module_param(logdump_ecntr_enable, int, 0644);
464 #ifdef EWP_RTT_LOGGING
465 int logdump_rtt_enable = TRUE;
466 #else
467 int logdump_rtt_enable = FALSE;
468 #endif /* EWP_RTT_LOGGING */
469 module_param(logdump_rtt_enable, int, 0644);
470 #endif /* DHD_LOG_DUMP */
471 #ifdef EWP_EDL
472 int host_edl_support = TRUE;
473 module_param(host_edl_support, int, 0644);
474 #endif // endif
475
476 /* deferred handlers */
477 static void dhd_ifadd_event_handler(void *handle, void *event_info, u8 event);
478 static void dhd_ifdel_event_handler(void *handle, void *event_info, u8 event);
479 static void dhd_set_mac_addr_handler(void *handle, void *event_info, u8 event);
480 static void dhd_set_mcast_list_handler(void *handle, void *event_info, u8 event);
481 #ifdef WL_NATOE
482 static void dhd_natoe_ct_event_hanlder(void *handle, void *event_info, u8 event);
483 static void dhd_natoe_ct_ioctl_handler(void *handle, void *event_info, uint8 event);
484 #endif /* WL_NATOE */
485
486 #ifdef DHD_UPDATE_INTF_MAC
487 static void dhd_ifupdate_event_handler(void *handle, void *event_info, u8 event);
488 #endif /* DHD_UPDATE_INTF_MAC */
489 #if defined(CONFIG_IPV6) && defined(IPV6_NDO_SUPPORT)
490 static void dhd_inet6_work_handler(void *dhd_info, void *event_data, u8 event);
491 #endif /* CONFIG_IPV6 && IPV6_NDO_SUPPORT */
492 #ifdef WL_CFG80211
493 extern void dhd_netdev_free(struct net_device *ndev);
494 #endif /* WL_CFG80211 */
495 static dhd_if_t * dhd_get_ifp_by_ndev(dhd_pub_t *dhdp, struct net_device *ndev);
496
497 #if defined(WLDWDS) && defined(FOURADDR_AUTO_BRG)
498 static void dhd_bridge_dev_set(dhd_info_t * dhd, int ifidx, struct net_device * dev);
499 #endif /* defiend(WLDWDS) && defined(FOURADDR_AUTO_BRG) */
500
501 #if (defined(DHD_WET) || defined(DHD_MCAST_REGEN) || defined(DHD_L2_FILTER))
502 /* update rx_pkt_chainable state of dhd interface */
503 static void dhd_update_rx_pkt_chainable_state(dhd_pub_t* dhdp, uint32 idx);
504 #endif /* DHD_WET || DHD_MCAST_REGEN || DHD_L2_FILTER */
505
506 /* Error bits */
507 module_param(dhd_msg_level, int, 0);
508 #if defined(WL_WIRELESS_EXT)
509 module_param(iw_msg_level, int, 0);
510 #endif
511 #ifdef WL_CFG80211
512 module_param(wl_dbg_level, int, 0);
513 #endif
514 module_param(android_msg_level, int, 0);
515 module_param(config_msg_level, int, 0);
516
517 #ifdef ARP_OFFLOAD_SUPPORT
518 /* ARP offload enable */
519 uint dhd_arp_enable = TRUE;
520 module_param(dhd_arp_enable, uint, 0);
521
522 /* ARP offload agent mode : Enable ARP Host Auto-Reply and ARP Peer Auto-Reply */
523
524 #ifdef ENABLE_ARP_SNOOP_MODE
525 uint dhd_arp_mode = (ARP_OL_AGENT | ARP_OL_PEER_AUTO_REPLY | ARP_OL_SNOOP | ARP_OL_HOST_AUTO_REPLY |
526 ARP_OL_UPDATE_HOST_CACHE);
527 #else
528 uint dhd_arp_mode = ARP_OL_AGENT | ARP_OL_PEER_AUTO_REPLY | ARP_OL_UPDATE_HOST_CACHE;
529 #endif /* ENABLE_ARP_SNOOP_MODE */
530
531 module_param(dhd_arp_mode, uint, 0);
532 #endif /* ARP_OFFLOAD_SUPPORT */
533
534 /* Disable Prop tx */
535 module_param(disable_proptx, int, 0644);
536 /* load firmware and/or nvram values from the filesystem */
537 module_param_string(firmware_path, firmware_path, MOD_PARAM_PATHLEN, 0660);
538 module_param_string(nvram_path, nvram_path, MOD_PARAM_PATHLEN, 0660);
539 module_param_string(config_path, config_path, MOD_PARAM_PATHLEN, 0);
540 #ifdef DHD_UCODE_DOWNLOAD
541 module_param_string(ucode_path, ucode_path, MOD_PARAM_PATHLEN, 0660);
542 #endif /* DHD_UCODE_DOWNLOAD */
543
544 /* wl event forwarding */
545 #ifdef WL_EVENT_ENAB
546 uint wl_event_enable = true;
547 #else
548 uint wl_event_enable = false;
549 #endif /* WL_EVENT_ENAB */
550 module_param(wl_event_enable, uint, 0660);
551
552 /* wl event forwarding */
553 #ifdef LOGTRACE_PKT_SENDUP
554 uint logtrace_pkt_sendup = true;
555 #else
556 uint logtrace_pkt_sendup = false;
557 #endif /* LOGTRACE_PKT_SENDUP */
558 module_param(logtrace_pkt_sendup, uint, 0660);
559
560 /* Watchdog interval */
561 /* extend watchdog expiration to 2 seconds when DPC is running */
562 #define WATCHDOG_EXTEND_INTERVAL (2000)
563
564 uint dhd_watchdog_ms = CUSTOM_DHD_WATCHDOG_MS;
565 module_param(dhd_watchdog_ms, uint, 0);
566
567 #if defined(DHD_DEBUG)
568 /* Console poll interval */
569 uint dhd_console_ms = 0;
570 module_param(dhd_console_ms, uint, 0644);
571 #else
572 uint dhd_console_ms = 0;
573 #endif /* DHD_DEBUG */
574
575 uint dhd_slpauto = TRUE;
576 module_param(dhd_slpauto, uint, 0);
577
578 #ifdef PKT_FILTER_SUPPORT
579 /* Global Pkt filter enable control */
580 uint dhd_pkt_filter_enable = TRUE;
581 module_param(dhd_pkt_filter_enable, uint, 0);
582 #endif // endif
583
584 /* Pkt filter init setup */
585 uint dhd_pkt_filter_init = 0;
586 module_param(dhd_pkt_filter_init, uint, 0);
587
588 /* Pkt filter mode control */
589 #ifdef GAN_LITE_NAT_KEEPALIVE_FILTER
590 uint dhd_master_mode = FALSE;
591 #else
592 uint dhd_master_mode = FALSE;
593 #endif /* GAN_LITE_NAT_KEEPALIVE_FILTER */
594 module_param(dhd_master_mode, uint, 0);
595
596 int dhd_watchdog_prio = 0;
597 module_param(dhd_watchdog_prio, int, 0);
598
599 /* DPC thread priority */
600 int dhd_dpc_prio = CUSTOM_DPC_PRIO_SETTING;
601 module_param(dhd_dpc_prio, int, 0);
602
603 /* RX frame thread priority */
604 int dhd_rxf_prio = CUSTOM_RXF_PRIO_SETTING;
605 module_param(dhd_rxf_prio, int, 0);
606
607 #if !defined(BCMDBUS)
608 extern int dhd_dongle_ramsize;
609 module_param(dhd_dongle_ramsize, int, 0);
610 #endif /* !BCMDBUS */
611
612 #ifdef WL_CFG80211
613 int passive_channel_skip = 0;
614 module_param(passive_channel_skip, int, (S_IRUSR|S_IWUSR));
615 #endif /* WL_CFG80211 */
616
617 #ifdef DHD_MSI_SUPPORT
618 uint enable_msi = TRUE;
619 module_param(enable_msi, uint, 0);
620 #endif /* PCIE_FULL_DONGLE */
621
622 #ifdef DHD_SSSR_DUMP
623 int dhdpcie_sssr_dump_get_before_after_len(dhd_pub_t *dhd, uint32 *arr_len);
624 extern uint support_sssr_dump;
625 module_param(support_sssr_dump, uint, 0);
626 #endif /* DHD_SSSR_DUMP */
627
628 /* Keep track of number of instances */
629 static int dhd_found = 0;
630 static int instance_base = 0; /* Starting instance number */
631 module_param(instance_base, int, 0644);
632
633 #if defined(DHD_LB_RXP)
634 static int dhd_napi_weight = 32;
635 module_param(dhd_napi_weight, int, 0644);
636 #endif /* DHD_LB_RXP */
637
638 #ifdef PCIE_FULL_DONGLE
639 extern int h2d_max_txpost;
640 module_param(h2d_max_txpost, int, 0644);
641
642 extern uint dma_ring_indices;
643 module_param(dma_ring_indices, uint, 0644);
644
645 extern bool h2d_phase;
646 module_param(h2d_phase, bool, 0644);
647 extern bool force_trap_bad_h2d_phase;
648 module_param(force_trap_bad_h2d_phase, bool, 0644);
649 #endif /* PCIE_FULL_DONGLE */
650
651 #ifdef FORCE_TPOWERON
652 /*
653 * On Fire's reference platform, coming out of L1.2,
654 * there is a constant delay of 45us between CLKREQ# and stable REFCLK
655 * Due to this delay, with tPowerOn < 50
656 * there is a chance of the refclk sense to trigger on noise.
657 *
658 * 0x29 when written to L1SSControl2 translates to 50us.
659 */
660 #define FORCE_TPOWERON_50US 0x29
661 uint32 tpoweron_scale = FORCE_TPOWERON_50US; /* default 50us */
662 module_param(tpoweron_scale, uint, 0644);
663 #endif /* FORCE_TPOWERON */
664
665 #ifdef SHOW_LOGTRACE
666 static char *logstrs_path = "/data/misc/wifi/logstrs.bin";
667 char *st_str_file_path = "/data/misc/wifi/rtecdc.bin";
668 static char *map_file_path = "/data/misc/wifi/rtecdc.map";
669 static char *rom_st_str_file_path = "/data/misc/wifi/roml.bin";
670 static char *rom_map_file_path = "/data/misc/wifi/roml.map";
671 static char *ram_file_str = "rtecdc";
672 static char *rom_file_str = "roml";
673
674 module_param(logstrs_path, charp, S_IRUGO);
675 module_param(st_str_file_path, charp, S_IRUGO);
676 module_param(map_file_path, charp, S_IRUGO);
677 module_param(rom_st_str_file_path, charp, S_IRUGO);
678 module_param(rom_map_file_path, charp, S_IRUGO);
679
680 static int dhd_init_logstrs_array(osl_t *osh, dhd_event_log_t *temp);
681 static int dhd_read_map(osl_t *osh, char *fname, uint32 *ramstart, uint32 *rodata_start,
682 uint32 *rodata_end);
683 static int dhd_init_static_strs_array(osl_t *osh, dhd_event_log_t *temp, char *str_file,
684 char *map_file);
685 #endif /* SHOW_LOGTRACE */
686
687 #ifdef USE_WFA_CERT_CONF
688 int g_frameburst = 1;
689 #endif /* USE_WFA_CERT_CONF */
690
691 static int dhd_get_pend_8021x_cnt(dhd_info_t *dhd);
692
693 /* DHD Perimiter lock only used in router with bypass forwarding. */
694 #define DHD_PERIM_RADIO_INIT() do { /* noop */ } while (0)
695 #define DHD_PERIM_LOCK_TRY(unit, flag) do { /* noop */ } while (0)
696 #define DHD_PERIM_UNLOCK_TRY(unit, flag) do { /* noop */ } while (0)
697
698 #ifdef PCIE_FULL_DONGLE
699 #define DHD_IF_STA_LIST_LOCK_INIT(ifp) spin_lock_init(&(ifp)->sta_list_lock)
700 #define DHD_IF_STA_LIST_LOCK(ifp, flags) \
701 spin_lock_irqsave(&(ifp)->sta_list_lock, (flags))
702 #define DHD_IF_STA_LIST_UNLOCK(ifp, flags) \
703 spin_unlock_irqrestore(&(ifp)->sta_list_lock, (flags))
704
705 #if defined(DHD_IGMP_UCQUERY) || defined(DHD_UCAST_UPNP)
706 static struct list_head * dhd_sta_list_snapshot(dhd_info_t *dhd, dhd_if_t *ifp,
707 struct list_head *snapshot_list);
708 static void dhd_sta_list_snapshot_free(dhd_info_t *dhd, struct list_head *snapshot_list);
709 #define DHD_IF_WMF_UCFORWARD_LOCK(dhd, ifp, slist) ({ dhd_sta_list_snapshot(dhd, ifp, slist); })
710 #define DHD_IF_WMF_UCFORWARD_UNLOCK(dhd, slist) ({ dhd_sta_list_snapshot_free(dhd, slist); })
711 #endif /* DHD_IGMP_UCQUERY || DHD_UCAST_UPNP */
712 #endif /* PCIE_FULL_DONGLE */
713
714 /* Control fw roaming */
715 #ifdef BCMCCX
716 uint dhd_roam_disable = 0;
717 #else
718 uint dhd_roam_disable = 0;
719 #endif /* BCMCCX */
720
721 #ifdef BCMDBGFS
722 extern void dhd_dbgfs_init(dhd_pub_t *dhdp);
723 extern void dhd_dbgfs_remove(void);
724 #endif // endif
725
726 static uint pcie_txs_metadata_enable = 0; /* Enable TX status metadta report */
727 module_param(pcie_txs_metadata_enable, int, 0);
728
729 /* Control radio state */
730 uint dhd_radio_up = 1;
731
732 /* Network inteface name */
733 char iface_name[IFNAMSIZ] = {'\0'};
734 module_param_string(iface_name, iface_name, IFNAMSIZ, 0);
735
736 /* The following are specific to the SDIO dongle */
737
738 /* IOCTL response timeout */
739 int dhd_ioctl_timeout_msec = IOCTL_RESP_TIMEOUT;
740
741 /* DS Exit response timeout */
742 int ds_exit_timeout_msec = DS_EXIT_TIMEOUT;
743
744 /* Idle timeout for backplane clock */
745 int dhd_idletime = DHD_IDLETIME_TICKS;
746 module_param(dhd_idletime, int, 0);
747
748 /* Use polling */
749 uint dhd_poll = FALSE;
750 module_param(dhd_poll, uint, 0);
751
752 /* Use interrupts */
753 uint dhd_intr = TRUE;
754 module_param(dhd_intr, uint, 0);
755
756 /* SDIO Drive Strength (in milliamps) */
757 uint dhd_sdiod_drive_strength = 6;
758 module_param(dhd_sdiod_drive_strength, uint, 0);
759
760 #ifdef BCMSDIO
761 /* Tx/Rx bounds */
762 extern uint dhd_txbound;
763 extern uint dhd_rxbound;
764 module_param(dhd_txbound, uint, 0);
765 module_param(dhd_rxbound, uint, 0);
766
767 /* Deferred transmits */
768 extern uint dhd_deferred_tx;
769 module_param(dhd_deferred_tx, uint, 0);
770
771 #endif /* BCMSDIO */
772
773 #ifdef SDTEST
774 /* Echo packet generator (pkts/s) */
775 uint dhd_pktgen = 0;
776 module_param(dhd_pktgen, uint, 0);
777
778 /* Echo packet len (0 => sawtooth, max 2040) */
779 uint dhd_pktgen_len = 0;
780 module_param(dhd_pktgen_len, uint, 0);
781 #endif /* SDTEST */
782
783 #if defined(BCMSUP_4WAY_HANDSHAKE)
784 /* Use in dongle supplicant for 4-way handshake */
785 #if defined(WLFBT) || defined(WL_ENABLE_IDSUP)
786 /* Enable idsup by default (if supported in fw) */
787 uint dhd_use_idsup = 1;
788 #else
789 uint dhd_use_idsup = 0;
790 #endif /* WLFBT || WL_ENABLE_IDSUP */
791 module_param(dhd_use_idsup, uint, 0);
792 #endif /* BCMSUP_4WAY_HANDSHAKE */
793
794 #ifndef BCMDBUS
795 /* Allow delayed firmware download for debug purpose */
796 int allow_delay_fwdl = FALSE;
797 module_param(allow_delay_fwdl, int, 0);
798 #endif /* !BCMDBUS */
799
800 #ifdef ECOUNTER_PERIODIC_DISABLE
801 uint enable_ecounter = FALSE;
802 #else
803 uint enable_ecounter = TRUE;
804 #endif // endif
805 module_param(enable_ecounter, uint, 0);
806
807 /* TCM verification flag */
808 uint dhd_tcm_test_enable = FALSE;
809 module_param(dhd_tcm_test_enable, uint, 0644);
810
811 extern char dhd_version[];
812 extern char fw_version[];
813 extern char clm_version[];
814
815 int dhd_net_bus_devreset(struct net_device *dev, uint8 flag);
816 static void dhd_net_if_lock_local(dhd_info_t *dhd);
817 static void dhd_net_if_unlock_local(dhd_info_t *dhd);
818 static void dhd_suspend_lock(dhd_pub_t *dhdp);
819 static void dhd_suspend_unlock(dhd_pub_t *dhdp);
820
821 /* Monitor interface */
822 int dhd_monitor_init(void *dhd_pub);
823 int dhd_monitor_uninit(void);
824
825 #ifdef DHD_PM_CONTROL_FROM_FILE
826 bool g_pm_control;
827 #ifdef DHD_EXPORT_CNTL_FILE
828 int pmmode_val;
829 #endif /* DHD_EXPORT_CNTL_FILE */
830 void sec_control_pm(dhd_pub_t *dhd, uint *);
831 #endif /* DHD_PM_CONTROL_FROM_FILE */
832
833 #if defined(WL_WIRELESS_EXT)
834 struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev);
835 #endif /* defined(WL_WIRELESS_EXT) */
836
837 #ifndef BCMDBUS
838 static void dhd_dpc(ulong data);
839 #endif /* !BCMDBUS */
840 /* forward decl */
841 extern int dhd_wait_pend8021x(struct net_device *dev);
842 void dhd_os_wd_timer_extend(void *bus, bool extend);
843
844 #ifdef TOE
845 #ifndef BDC
846 #error TOE requires BDC
847 #endif /* !BDC */
848 static int dhd_toe_get(dhd_info_t *dhd, int idx, uint32 *toe_ol);
849 static int dhd_toe_set(dhd_info_t *dhd, int idx, uint32 toe_ol);
850 #endif /* TOE */
851
852 static int dhd_wl_host_event(dhd_info_t *dhd, int ifidx, void *pktdata, uint16 pktlen,
853 wl_event_msg_t *event_ptr, void **data_ptr);
854
855 #if defined(CONFIG_PM_SLEEP)
dhd_pm_callback(struct notifier_block * nfb,unsigned long action,void * ignored)856 static int dhd_pm_callback(struct notifier_block *nfb, unsigned long action, void *ignored)
857 {
858 int ret = NOTIFY_DONE;
859 bool suspend = FALSE;
860
861 #if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
862 #pragma GCC diagnostic push
863 #pragma GCC diagnostic ignored "-Wcast-qual"
864 #endif // endif
865 dhd_info_t *dhdinfo = (dhd_info_t*)container_of(nfb, struct dhd_info, pm_notifier);
866 #if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
867 #pragma GCC diagnostic pop
868 #endif // endif
869
870 BCM_REFERENCE(dhdinfo);
871 BCM_REFERENCE(suspend);
872
873 switch (action) {
874 case PM_HIBERNATION_PREPARE:
875 case PM_SUSPEND_PREPARE:
876 suspend = TRUE;
877 break;
878
879 case PM_POST_HIBERNATION:
880 case PM_POST_SUSPEND:
881 suspend = FALSE;
882 break;
883 }
884
885 printf("%s: action=%ld, suspend=%d, suspend_mode=%d\n",
886 __FUNCTION__, action, suspend, dhdinfo->pub.conf->suspend_mode);
887 if (suspend) {
888 DHD_OS_WAKE_LOCK_WAIVE(&dhdinfo->pub);
889 if (dhdinfo->pub.conf->suspend_mode == PM_NOTIFIER)
890 dhd_suspend_resume_helper(dhdinfo, suspend, 0);
891 #if defined(SUPPORT_P2P_GO_PS) && defined(PROP_TXSTATUS)
892 dhd_wlfc_suspend(&dhdinfo->pub);
893 #endif /* defined(SUPPORT_P2P_GO_PS) && defined(PROP_TXSTATUS) */
894 if (dhdinfo->pub.conf->suspend_mode == PM_NOTIFIER)
895 dhd_conf_set_suspend_resume(&dhdinfo->pub, suspend);
896 DHD_OS_WAKE_LOCK_RESTORE(&dhdinfo->pub);
897 } else {
898 if (dhdinfo->pub.conf->suspend_mode == PM_NOTIFIER)
899 dhd_conf_set_suspend_resume(&dhdinfo->pub, suspend);
900 #if defined(SUPPORT_P2P_GO_PS) && defined(PROP_TXSTATUS)
901 dhd_wlfc_resume(&dhdinfo->pub);
902 #endif /* defined(SUPPORT_P2P_GO_PS) && defined(PROP_TXSTATUS) */
903 if (dhdinfo->pub.conf->suspend_mode == PM_NOTIFIER)
904 dhd_suspend_resume_helper(dhdinfo, suspend, 0);
905 }
906
907 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && (LINUX_VERSION_CODE <= \
908 KERNEL_VERSION(2, 6, 39))
909 dhd_mmc_suspend = suspend;
910 smp_mb();
911 #endif
912
913 return ret;
914 }
915
916 /* to make sure we won't register the same notifier twice, otherwise a loop is likely to be
917 * created in kernel notifier link list (with 'next' pointing to itself)
918 */
919 static bool dhd_pm_notifier_registered = FALSE;
920
921 extern int register_pm_notifier(struct notifier_block *nb);
922 extern int unregister_pm_notifier(struct notifier_block *nb);
923 #endif /* CONFIG_PM_SLEEP */
924
925 /* Request scheduling of the bus rx frame */
926 static void dhd_sched_rxf(dhd_pub_t *dhdp, void *skb);
927 static void dhd_os_rxflock(dhd_pub_t *pub);
928 static void dhd_os_rxfunlock(dhd_pub_t *pub);
929
930 #if defined(DHD_H2D_LOG_TIME_SYNC)
931 static void
932 dhd_deferred_work_rte_log_time_sync(void *handle, void *event_info, u8 event);
933 #endif /* DHD_H2D_LOG_TIME_SYNC */
934
935 /** priv_link is the link between netdev and the dhdif and dhd_info structs. */
936 typedef struct dhd_dev_priv {
937 dhd_info_t * dhd; /* cached pointer to dhd_info in netdevice priv */
938 dhd_if_t * ifp; /* cached pointer to dhd_if in netdevice priv */
939 int ifidx; /* interface index */
940 void * lkup;
941 } dhd_dev_priv_t;
942
943 #define DHD_DEV_PRIV_SIZE (sizeof(dhd_dev_priv_t))
944
945 #ifdef CONFIG_AP6XXX_WIFI6_HDF
946 #include "net_device.h"
947
948 extern int g_hdf_ifidx;
949 //struct NetDevice * get_hdf_netdev(int ifidx);
950 struct NetDevice * GetHdfNetDeviceByLinuxInf(struct net_device *dev);
951 void BDH6_ResetDriver(void);
952
DHD_DEV_PRIV(struct net_device * dev)953 static inline dhd_dev_priv_t * DHD_DEV_PRIV(struct net_device *dev)
954 {
955 dhd_dev_priv_t *__tmp_dhd_netpriv = NULL;
956 struct NetDevice * hnetdev = GetHdfNetDeviceByLinuxInf(dev);
957 if ( hnetdev != NULL) {
958 __tmp_dhd_netpriv = ((dhd_dev_priv_t *)hnetdev->mlPriv);
959 } else {
960 __tmp_dhd_netpriv = NULL;
961 DHD_ERROR(("HDF net_device %s is invalid\n", dev->name));
962 }
963
964 return (__tmp_dhd_netpriv);
965 }
966
VOID_DEV_PRIV(struct net_device * dev)967 void * VOID_DEV_PRIV(struct net_device *dev)
968 {
969 return (void *)DHD_DEV_PRIV(dev);
970 }
971
972 #define DHD_DEV_INFO(dev) (DHD_DEV_PRIV(dev)->dhd)
973 #define DHD_DEV_IFP(dev) (DHD_DEV_PRIV(dev)->ifp)
974 #define DHD_DEV_IFIDX(dev) (DHD_DEV_PRIV(dev)->ifidx)
975 #define DHD_DEV_LKUP(dev) (DHD_DEV_PRIV(dev)->lkup)
976
977
978 #else
979 #define DHD_DEV_PRIV(dev) ((dhd_dev_priv_t *)DEV_PRIV(dev))
980 #define DHD_DEV_INFO(dev) (((dhd_dev_priv_t *)DEV_PRIV(dev))->dhd)
981 #define DHD_DEV_IFP(dev) (((dhd_dev_priv_t *)DEV_PRIV(dev))->ifp)
982 #define DHD_DEV_IFIDX(dev) (((dhd_dev_priv_t *)DEV_PRIV(dev))->ifidx)
983 #define DHD_DEV_LKUP(dev) (((dhd_dev_priv_t *)DEV_PRIV(dev))->lkup)
984 #endif
985
986 /** Clear the dhd net_device's private structure. */
987 static inline void
dhd_dev_priv_clear(struct net_device * dev)988 dhd_dev_priv_clear(struct net_device * dev)
989 {
990 dhd_dev_priv_t * dev_priv;
991 ASSERT(dev != (struct net_device *)NULL);
992 dev_priv = DHD_DEV_PRIV(dev);
993 dev_priv->dhd = (dhd_info_t *)NULL;
994 dev_priv->ifp = (dhd_if_t *)NULL;
995 dev_priv->ifidx = DHD_BAD_IF;
996 dev_priv->lkup = (void *)NULL;
997 }
998
999 /** Setup the dhd net_device's private structure. */
1000 static inline void
dhd_dev_priv_save(struct net_device * dev,dhd_info_t * dhd,dhd_if_t * ifp,int ifidx)1001 dhd_dev_priv_save(struct net_device * dev, dhd_info_t * dhd, dhd_if_t * ifp,
1002 int ifidx)
1003 {
1004 dhd_dev_priv_t * dev_priv;
1005 ASSERT(dev != (struct net_device *)NULL);
1006 dev_priv = DHD_DEV_PRIV(dev);
1007 dev_priv->dhd = dhd;
1008 dev_priv->ifp = ifp;
1009 dev_priv->ifidx = ifidx;
1010 }
1011
1012 /* Return interface pointer */
dhd_get_ifp(dhd_pub_t * dhdp,uint32 ifidx)1013 struct dhd_if * dhd_get_ifp(dhd_pub_t *dhdp, uint32 ifidx)
1014 {
1015 ASSERT(ifidx < DHD_MAX_IFS);
1016
1017 if (!dhdp || !dhdp->info || ifidx >= DHD_MAX_IFS)
1018 return NULL;
1019
1020 return dhdp->info->iflist[ifidx];
1021 }
1022
1023 #ifdef PCIE_FULL_DONGLE
1024
1025 /** Dummy objects are defined with state representing bad|down.
1026 * Performance gains from reducing branch conditionals, instruction parallelism,
1027 * dual issue, reducing load shadows, avail of larger pipelines.
1028 * Use DHD_XXX_NULL instead of (dhd_xxx_t *)NULL, whenever an object pointer
1029 * is accessed via the dhd_sta_t.
1030 */
1031
1032 /* Dummy dhd_info object */
1033 dhd_info_t dhd_info_null = {
1034 .pub = {
1035 .info = &dhd_info_null,
1036 #ifdef DHDTCPACK_SUPPRESS
1037 .tcpack_sup_mode = TCPACK_SUP_REPLACE,
1038 #endif /* DHDTCPACK_SUPPRESS */
1039 .up = FALSE,
1040 .busstate = DHD_BUS_DOWN
1041 }
1042 };
1043 #define DHD_INFO_NULL (&dhd_info_null)
1044 #define DHD_PUB_NULL (&dhd_info_null.pub)
1045
1046 /* Dummy netdevice object */
1047 struct net_device dhd_net_dev_null = {
1048 .reg_state = NETREG_UNREGISTERED
1049 };
1050 #define DHD_NET_DEV_NULL (&dhd_net_dev_null)
1051
1052 /* Dummy dhd_if object */
1053 dhd_if_t dhd_if_null = {
1054 #ifdef WMF
1055 .wmf = { .wmf_enable = TRUE },
1056 #endif // endif
1057 .info = DHD_INFO_NULL,
1058 .net = DHD_NET_DEV_NULL,
1059 .idx = DHD_BAD_IF
1060 };
1061 #define DHD_IF_NULL (&dhd_if_null)
1062
1063 #define DHD_STA_NULL ((dhd_sta_t *)NULL)
1064
1065 /** Interface STA list management. */
1066
1067 /** Alloc/Free a dhd_sta object from the dhd instances' sta_pool. */
1068 static void dhd_sta_free(dhd_pub_t *pub, dhd_sta_t *sta);
1069 static dhd_sta_t * dhd_sta_alloc(dhd_pub_t * dhdp);
1070
1071 /* Delete a dhd_sta or flush all dhd_sta in an interface's sta_list. */
1072 static void dhd_if_del_sta_list(dhd_if_t * ifp);
1073 static void dhd_if_flush_sta(dhd_if_t * ifp);
1074
1075 /* Construct/Destruct a sta pool. */
1076 static int dhd_sta_pool_init(dhd_pub_t *dhdp, int max_sta);
1077 static void dhd_sta_pool_fini(dhd_pub_t *dhdp, int max_sta);
1078 /* Clear the pool of dhd_sta_t objects for built-in type driver */
1079 static void dhd_sta_pool_clear(dhd_pub_t *dhdp, int max_sta);
1080
1081 /** Reset a dhd_sta object and free into the dhd pool. */
1082 static void
dhd_sta_free(dhd_pub_t * dhdp,dhd_sta_t * sta)1083 dhd_sta_free(dhd_pub_t * dhdp, dhd_sta_t * sta)
1084 {
1085 int prio;
1086
1087 ASSERT((sta != DHD_STA_NULL) && (sta->idx != ID16_INVALID));
1088
1089 ASSERT((dhdp->staid_allocator != NULL) && (dhdp->sta_pool != NULL));
1090
1091 /*
1092 * Flush and free all packets in all flowring's queues belonging to sta.
1093 * Packets in flow ring will be flushed later.
1094 */
1095 for (prio = 0; prio < (int)NUMPRIO; prio++) {
1096 uint16 flowid = sta->flowid[prio];
1097
1098 if (flowid != FLOWID_INVALID) {
1099 unsigned long flags;
1100 flow_ring_node_t * flow_ring_node;
1101
1102 #ifdef DHDTCPACK_SUPPRESS
1103 /* Clean tcp_ack_info_tbl in order to prevent access to flushed pkt,
1104 * when there is a newly coming packet from network stack.
1105 */
1106 dhd_tcpack_info_tbl_clean(dhdp);
1107 #endif /* DHDTCPACK_SUPPRESS */
1108
1109 flow_ring_node = dhd_flow_ring_node(dhdp, flowid);
1110 if (flow_ring_node) {
1111 flow_queue_t *queue = &flow_ring_node->queue;
1112
1113 DHD_FLOWRING_LOCK(flow_ring_node->lock, flags);
1114 flow_ring_node->status = FLOW_RING_STATUS_STA_FREEING;
1115
1116 if (!DHD_FLOW_QUEUE_EMPTY(queue)) {
1117 void * pkt;
1118 while ((pkt = dhd_flow_queue_dequeue(dhdp, queue)) !=
1119 NULL) {
1120 PKTFREE(dhdp->osh, pkt, TRUE);
1121 }
1122 }
1123
1124 DHD_FLOWRING_UNLOCK(flow_ring_node->lock, flags);
1125 ASSERT(DHD_FLOW_QUEUE_EMPTY(queue));
1126 }
1127 }
1128
1129 sta->flowid[prio] = FLOWID_INVALID;
1130 }
1131
1132 id16_map_free(dhdp->staid_allocator, sta->idx);
1133 DHD_CUMM_CTR_INIT(&sta->cumm_ctr);
1134 sta->ifp = DHD_IF_NULL; /* dummy dhd_if object */
1135 sta->ifidx = DHD_BAD_IF;
1136 bzero(sta->ea.octet, ETHER_ADDR_LEN);
1137 INIT_LIST_HEAD(&sta->list);
1138 sta->idx = ID16_INVALID; /* implying free */
1139 }
1140
1141 /** Allocate a dhd_sta object from the dhd pool. */
1142 static dhd_sta_t *
dhd_sta_alloc(dhd_pub_t * dhdp)1143 dhd_sta_alloc(dhd_pub_t * dhdp)
1144 {
1145 uint16 idx;
1146 dhd_sta_t * sta;
1147 dhd_sta_pool_t * sta_pool;
1148
1149 ASSERT((dhdp->staid_allocator != NULL) && (dhdp->sta_pool != NULL));
1150
1151 idx = id16_map_alloc(dhdp->staid_allocator);
1152 if (idx == ID16_INVALID) {
1153 DHD_ERROR(("%s: cannot get free staid\n", __FUNCTION__));
1154 return DHD_STA_NULL;
1155 }
1156
1157 sta_pool = (dhd_sta_pool_t *)(dhdp->sta_pool);
1158 sta = &sta_pool[idx];
1159
1160 ASSERT((sta->idx == ID16_INVALID) &&
1161 (sta->ifp == DHD_IF_NULL) && (sta->ifidx == DHD_BAD_IF));
1162
1163 DHD_CUMM_CTR_INIT(&sta->cumm_ctr);
1164
1165 sta->idx = idx; /* implying allocated */
1166
1167 return sta;
1168 }
1169
1170 /** Delete all STAs in an interface's STA list. */
1171 static void
dhd_if_del_sta_list(dhd_if_t * ifp)1172 dhd_if_del_sta_list(dhd_if_t *ifp)
1173 {
1174 dhd_sta_t *sta, *next;
1175 unsigned long flags;
1176
1177 DHD_IF_STA_LIST_LOCK(ifp, flags);
1178 #if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
1179 #pragma GCC diagnostic push
1180 #pragma GCC diagnostic ignored "-Wcast-qual"
1181 #endif // endif
1182 list_for_each_entry_safe(sta, next, &ifp->sta_list, list) {
1183 list_del(&sta->list);
1184 dhd_sta_free(&ifp->info->pub, sta);
1185 }
1186 #if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
1187 #pragma GCC diagnostic pop
1188 #endif // endif
1189 DHD_IF_STA_LIST_UNLOCK(ifp, flags);
1190
1191 return;
1192 }
1193
1194 /** Router/GMAC3: Flush all station entries in the forwarder's WOFA database. */
1195 static void
dhd_if_flush_sta(dhd_if_t * ifp)1196 dhd_if_flush_sta(dhd_if_t * ifp)
1197 {
1198 }
1199
1200 /** Construct a pool of dhd_sta_t objects to be used by interfaces. */
1201 static int
dhd_sta_pool_init(dhd_pub_t * dhdp,int max_sta)1202 dhd_sta_pool_init(dhd_pub_t *dhdp, int max_sta)
1203 {
1204 int idx, prio, sta_pool_memsz;
1205 dhd_sta_t * sta;
1206 dhd_sta_pool_t * sta_pool;
1207 void * staid_allocator;
1208
1209 ASSERT(dhdp != (dhd_pub_t *)NULL);
1210 ASSERT((dhdp->staid_allocator == NULL) && (dhdp->sta_pool == NULL));
1211
1212 /* dhd_sta objects per radio are managed in a table. id#0 reserved. */
1213 staid_allocator = id16_map_init(dhdp->osh, max_sta, 1);
1214 if (staid_allocator == NULL) {
1215 DHD_ERROR(("%s: sta id allocator init failure\n", __FUNCTION__));
1216 return BCME_ERROR;
1217 }
1218
1219 /* Pre allocate a pool of dhd_sta objects (one extra). */
1220 sta_pool_memsz = ((max_sta + 1) * sizeof(dhd_sta_t)); /* skip idx 0 */
1221 sta_pool = (dhd_sta_pool_t *)MALLOC(dhdp->osh, sta_pool_memsz);
1222 if (sta_pool == NULL) {
1223 DHD_ERROR(("%s: sta table alloc failure\n", __FUNCTION__));
1224 id16_map_fini(dhdp->osh, staid_allocator);
1225 return BCME_ERROR;
1226 }
1227
1228 dhdp->sta_pool = sta_pool;
1229 dhdp->staid_allocator = staid_allocator;
1230
1231 /* Initialize all sta(s) for the pre-allocated free pool. */
1232 bzero((uchar *)sta_pool, sta_pool_memsz);
1233 for (idx = max_sta; idx >= 1; idx--) { /* skip sta_pool[0] */
1234 sta = &sta_pool[idx];
1235 sta->idx = id16_map_alloc(staid_allocator);
1236 ASSERT(sta->idx <= max_sta);
1237 }
1238
1239 /* Now place them into the pre-allocated free pool. */
1240 for (idx = 1; idx <= max_sta; idx++) {
1241 sta = &sta_pool[idx];
1242 for (prio = 0; prio < (int)NUMPRIO; prio++) {
1243 sta->flowid[prio] = FLOWID_INVALID; /* Flow rings do not exist */
1244 }
1245 dhd_sta_free(dhdp, sta);
1246 }
1247
1248 return BCME_OK;
1249 }
1250
1251 /** Destruct the pool of dhd_sta_t objects.
1252 * Caller must ensure that no STA objects are currently associated with an if.
1253 */
1254 static void
dhd_sta_pool_fini(dhd_pub_t * dhdp,int max_sta)1255 dhd_sta_pool_fini(dhd_pub_t *dhdp, int max_sta)
1256 {
1257 dhd_sta_pool_t * sta_pool = (dhd_sta_pool_t *)dhdp->sta_pool;
1258
1259 if (sta_pool) {
1260 int idx;
1261 int sta_pool_memsz = ((max_sta + 1) * sizeof(dhd_sta_t));
1262 for (idx = 1; idx <= max_sta; idx++) {
1263 ASSERT(sta_pool[idx].ifp == DHD_IF_NULL);
1264 ASSERT(sta_pool[idx].idx == ID16_INVALID);
1265 }
1266 MFREE(dhdp->osh, dhdp->sta_pool, sta_pool_memsz);
1267 dhdp->sta_pool = NULL;
1268 }
1269
1270 id16_map_fini(dhdp->osh, dhdp->staid_allocator);
1271 dhdp->staid_allocator = NULL;
1272 }
1273
1274 /* Clear the pool of dhd_sta_t objects for built-in type driver */
1275 static void
dhd_sta_pool_clear(dhd_pub_t * dhdp,int max_sta)1276 dhd_sta_pool_clear(dhd_pub_t *dhdp, int max_sta)
1277 {
1278 int idx, prio, sta_pool_memsz;
1279 dhd_sta_t * sta;
1280 dhd_sta_pool_t * sta_pool;
1281 void *staid_allocator;
1282
1283 if (!dhdp) {
1284 DHD_ERROR(("%s: dhdp is NULL\n", __FUNCTION__));
1285 return;
1286 }
1287
1288 sta_pool = (dhd_sta_pool_t *)dhdp->sta_pool;
1289 staid_allocator = dhdp->staid_allocator;
1290
1291 if (!sta_pool) {
1292 DHD_ERROR(("%s: sta_pool is NULL\n", __FUNCTION__));
1293 return;
1294 }
1295
1296 if (!staid_allocator) {
1297 DHD_ERROR(("%s: staid_allocator is NULL\n", __FUNCTION__));
1298 return;
1299 }
1300
1301 /* clear free pool */
1302 sta_pool_memsz = ((max_sta + 1) * sizeof(dhd_sta_t));
1303 bzero((uchar *)sta_pool, sta_pool_memsz);
1304
1305 /* dhd_sta objects per radio are managed in a table. id#0 reserved. */
1306 id16_map_clear(staid_allocator, max_sta, 1);
1307
1308 /* Initialize all sta(s) for the pre-allocated free pool. */
1309 for (idx = max_sta; idx >= 1; idx--) { /* skip sta_pool[0] */
1310 sta = &sta_pool[idx];
1311 sta->idx = id16_map_alloc(staid_allocator);
1312 ASSERT(sta->idx <= max_sta);
1313 }
1314 /* Now place them into the pre-allocated free pool. */
1315 for (idx = 1; idx <= max_sta; idx++) {
1316 sta = &sta_pool[idx];
1317 for (prio = 0; prio < (int)NUMPRIO; prio++) {
1318 sta->flowid[prio] = FLOWID_INVALID; /* Flow rings do not exist */
1319 }
1320 dhd_sta_free(dhdp, sta);
1321 }
1322 }
1323
1324 /** Find STA with MAC address ea in an interface's STA list. */
1325 dhd_sta_t *
dhd_find_sta(void * pub,int ifidx,void * ea)1326 dhd_find_sta(void *pub, int ifidx, void *ea)
1327 {
1328 dhd_sta_t *sta;
1329 dhd_if_t *ifp;
1330 unsigned long flags;
1331
1332 ASSERT(ea != NULL);
1333 ifp = dhd_get_ifp((dhd_pub_t *)pub, ifidx);
1334 if (ifp == NULL)
1335 return DHD_STA_NULL;
1336
1337 DHD_IF_STA_LIST_LOCK(ifp, flags);
1338 #if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
1339 #pragma GCC diagnostic push
1340 #pragma GCC diagnostic ignored "-Wcast-qual"
1341 #endif // endif
1342 list_for_each_entry(sta, &ifp->sta_list, list) {
1343 if (!memcmp(sta->ea.octet, ea, ETHER_ADDR_LEN)) {
1344 DHD_INFO(("%s: Found STA " MACDBG "\n",
1345 __FUNCTION__, MAC2STRDBG((char *)ea)));
1346 DHD_IF_STA_LIST_UNLOCK(ifp, flags);
1347 return sta;
1348 }
1349 }
1350 #if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
1351 #pragma GCC diagnostic pop
1352 #endif // endif
1353 DHD_IF_STA_LIST_UNLOCK(ifp, flags);
1354
1355 return DHD_STA_NULL;
1356 }
1357
1358 /** Add STA into the interface's STA list. */
1359 dhd_sta_t *
dhd_add_sta(void * pub,int ifidx,void * ea)1360 dhd_add_sta(void *pub, int ifidx, void *ea)
1361 {
1362 dhd_sta_t *sta;
1363 dhd_if_t *ifp;
1364 unsigned long flags;
1365
1366 ASSERT(ea != NULL);
1367 ifp = dhd_get_ifp((dhd_pub_t *)pub, ifidx);
1368 if (ifp == NULL)
1369 return DHD_STA_NULL;
1370
1371 if (!memcmp(ifp->net->dev_addr, ea, ETHER_ADDR_LEN)) {
1372 DHD_ERROR(("%s: Serious FAILURE, receive own MAC %pM !!\n", __FUNCTION__, ea));
1373 return DHD_STA_NULL;
1374 }
1375
1376 sta = dhd_sta_alloc((dhd_pub_t *)pub);
1377 if (sta == DHD_STA_NULL) {
1378 DHD_ERROR(("%s: Alloc failed\n", __FUNCTION__));
1379 return DHD_STA_NULL;
1380 }
1381
1382 memcpy(sta->ea.octet, ea, ETHER_ADDR_LEN);
1383
1384 /* link the sta and the dhd interface */
1385 sta->ifp = ifp;
1386 sta->ifidx = ifidx;
1387 INIT_LIST_HEAD(&sta->list);
1388
1389 DHD_IF_STA_LIST_LOCK(ifp, flags);
1390
1391 list_add_tail(&sta->list, &ifp->sta_list);
1392
1393 DHD_ERROR(("%s: Adding STA " MACDBG "\n",
1394 __FUNCTION__, MAC2STRDBG((char *)ea)));
1395
1396 DHD_IF_STA_LIST_UNLOCK(ifp, flags);
1397
1398 return sta;
1399 }
1400
1401 /** Delete all STAs from the interface's STA list. */
1402 void
dhd_del_all_sta(void * pub,int ifidx)1403 dhd_del_all_sta(void *pub, int ifidx)
1404 {
1405 dhd_sta_t *sta, *next;
1406 dhd_if_t *ifp;
1407 unsigned long flags;
1408
1409 ifp = dhd_get_ifp((dhd_pub_t *)pub, ifidx);
1410 if (ifp == NULL)
1411 return;
1412
1413 DHD_IF_STA_LIST_LOCK(ifp, flags);
1414 #if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
1415 #pragma GCC diagnostic push
1416 #pragma GCC diagnostic ignored "-Wcast-qual"
1417 #endif // endif
1418 list_for_each_entry_safe(sta, next, &ifp->sta_list, list) {
1419
1420 list_del(&sta->list);
1421 dhd_sta_free(&ifp->info->pub, sta);
1422 #ifdef DHD_L2_FILTER
1423 if (ifp->parp_enable) {
1424 /* clear Proxy ARP cache of specific Ethernet Address */
1425 bcm_l2_filter_arp_table_update(((dhd_pub_t*)pub)->osh,
1426 ifp->phnd_arp_table, FALSE,
1427 sta->ea.octet, FALSE, ((dhd_pub_t*)pub)->tickcnt);
1428 }
1429 #endif /* DHD_L2_FILTER */
1430 }
1431 #if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
1432 #pragma GCC diagnostic pop
1433 #endif // endif
1434 DHD_IF_STA_LIST_UNLOCK(ifp, flags);
1435
1436 return;
1437 }
1438
1439 /** Delete STA from the interface's STA list. */
1440 void
dhd_del_sta(void * pub,int ifidx,void * ea)1441 dhd_del_sta(void *pub, int ifidx, void *ea)
1442 {
1443 dhd_sta_t *sta, *next;
1444 dhd_if_t *ifp;
1445 unsigned long flags;
1446
1447 ASSERT(ea != NULL);
1448 ifp = dhd_get_ifp((dhd_pub_t *)pub, ifidx);
1449 if (ifp == NULL)
1450 return;
1451
1452 DHD_IF_STA_LIST_LOCK(ifp, flags);
1453 #if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
1454 #pragma GCC diagnostic push
1455 #pragma GCC diagnostic ignored "-Wcast-qual"
1456 #endif // endif
1457 list_for_each_entry_safe(sta, next, &ifp->sta_list, list) {
1458 if (!memcmp(sta->ea.octet, ea, ETHER_ADDR_LEN)) {
1459 DHD_ERROR(("%s: Deleting STA " MACDBG "\n",
1460 __FUNCTION__, MAC2STRDBG(sta->ea.octet)));
1461 list_del(&sta->list);
1462 dhd_sta_free(&ifp->info->pub, sta);
1463 }
1464 }
1465 #if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
1466 #pragma GCC diagnostic pop
1467 #endif // endif
1468 DHD_IF_STA_LIST_UNLOCK(ifp, flags);
1469 #ifdef DHD_L2_FILTER
1470 if (ifp->parp_enable) {
1471 /* clear Proxy ARP cache of specific Ethernet Address */
1472 bcm_l2_filter_arp_table_update(((dhd_pub_t*)pub)->osh, ifp->phnd_arp_table, FALSE,
1473 ea, FALSE, ((dhd_pub_t*)pub)->tickcnt);
1474 }
1475 #endif /* DHD_L2_FILTER */
1476 return;
1477 }
1478
1479 /** Add STA if it doesn't exist. Not reentrant. */
1480 dhd_sta_t*
dhd_findadd_sta(void * pub,int ifidx,void * ea)1481 dhd_findadd_sta(void *pub, int ifidx, void *ea)
1482 {
1483 dhd_sta_t *sta;
1484
1485 sta = dhd_find_sta(pub, ifidx, ea);
1486
1487 if (!sta) {
1488 /* Add entry */
1489 sta = dhd_add_sta(pub, ifidx, ea);
1490 }
1491
1492 return sta;
1493 }
1494
1495 #if defined(DHD_IGMP_UCQUERY) || defined(DHD_UCAST_UPNP)
1496 static struct list_head *
dhd_sta_list_snapshot(dhd_info_t * dhd,dhd_if_t * ifp,struct list_head * snapshot_list)1497 dhd_sta_list_snapshot(dhd_info_t *dhd, dhd_if_t *ifp, struct list_head *snapshot_list)
1498 {
1499 unsigned long flags;
1500 dhd_sta_t *sta, *snapshot;
1501
1502 INIT_LIST_HEAD(snapshot_list);
1503
1504 DHD_IF_STA_LIST_LOCK(ifp, flags);
1505
1506 list_for_each_entry(sta, &ifp->sta_list, list) {
1507 /* allocate one and add to snapshot */
1508 snapshot = (dhd_sta_t *)MALLOC(dhd->pub.osh, sizeof(dhd_sta_t));
1509 if (snapshot == NULL) {
1510 DHD_ERROR(("%s: Cannot allocate memory\n", __FUNCTION__));
1511 continue;
1512 }
1513
1514 memcpy(snapshot->ea.octet, sta->ea.octet, ETHER_ADDR_LEN);
1515
1516 INIT_LIST_HEAD(&snapshot->list);
1517 list_add_tail(&snapshot->list, snapshot_list);
1518 }
1519
1520 DHD_IF_STA_LIST_UNLOCK(ifp, flags);
1521
1522 return snapshot_list;
1523 }
1524
1525 static void
dhd_sta_list_snapshot_free(dhd_info_t * dhd,struct list_head * snapshot_list)1526 dhd_sta_list_snapshot_free(dhd_info_t *dhd, struct list_head *snapshot_list)
1527 {
1528 dhd_sta_t *sta, *next;
1529
1530 list_for_each_entry_safe(sta, next, snapshot_list, list) {
1531 list_del(&sta->list);
1532 MFREE(dhd->pub.osh, sta, sizeof(dhd_sta_t));
1533 }
1534 }
1535 #endif /* DHD_IGMP_UCQUERY || DHD_UCAST_UPNP */
1536
1537 #else
dhd_if_flush_sta(dhd_if_t * ifp)1538 static inline void dhd_if_flush_sta(dhd_if_t * ifp) { }
dhd_if_del_sta_list(dhd_if_t * ifp)1539 static inline void dhd_if_del_sta_list(dhd_if_t *ifp) {}
dhd_sta_pool_init(dhd_pub_t * dhdp,int max_sta)1540 static inline int dhd_sta_pool_init(dhd_pub_t *dhdp, int max_sta) { return BCME_OK; }
dhd_sta_pool_fini(dhd_pub_t * dhdp,int max_sta)1541 static inline void dhd_sta_pool_fini(dhd_pub_t *dhdp, int max_sta) {}
dhd_sta_pool_clear(dhd_pub_t * dhdp,int max_sta)1542 static inline void dhd_sta_pool_clear(dhd_pub_t *dhdp, int max_sta) {}
dhd_findadd_sta(void * pub,int ifidx,void * ea)1543 dhd_sta_t *dhd_findadd_sta(void *pub, int ifidx, void *ea) { return NULL; }
dhd_find_sta(void * pub,int ifidx,void * ea)1544 dhd_sta_t *dhd_find_sta(void *pub, int ifidx, void *ea) { return NULL; }
dhd_del_sta(void * pub,int ifidx,void * ea)1545 void dhd_del_sta(void *pub, int ifidx, void *ea) {}
1546 #endif /* PCIE_FULL_DONGLE */
1547
1548 #if defined(DNGL_AXI_ERROR_LOGGING) && defined(DHD_USE_WQ_FOR_DNGL_AXI_ERROR)
1549 void
dhd_axi_error_dispatch(dhd_pub_t * dhdp)1550 dhd_axi_error_dispatch(dhd_pub_t *dhdp)
1551 {
1552 dhd_info_t *dhd = dhdp->info;
1553 schedule_work(&dhd->axi_error_dispatcher_work);
1554 }
1555
dhd_axi_error_dispatcher_fn(struct work_struct * work)1556 static void dhd_axi_error_dispatcher_fn(struct work_struct * work)
1557 {
1558 struct dhd_info *dhd =
1559 container_of(work, struct dhd_info, axi_error_dispatcher_work);
1560 dhd_axi_error(&dhd->pub);
1561 }
1562 #endif /* DNGL_AXI_ERROR_LOGGING && DHD_USE_WQ_FOR_DNGL_AXI_ERROR */
1563
1564 /** Returns dhd iflist index corresponding the the bssidx provided by apps */
dhd_bssidx2idx(dhd_pub_t * dhdp,uint32 bssidx)1565 int dhd_bssidx2idx(dhd_pub_t *dhdp, uint32 bssidx)
1566 {
1567 dhd_if_t *ifp;
1568 dhd_info_t *dhd = dhdp->info;
1569 int i;
1570
1571 ASSERT(bssidx < DHD_MAX_IFS);
1572 ASSERT(dhdp);
1573
1574 for (i = 0; i < DHD_MAX_IFS; i++) {
1575 ifp = dhd->iflist[i];
1576 if (ifp && (ifp->bssidx == bssidx)) {
1577 DHD_TRACE(("Index manipulated for %s from %d to %d\n",
1578 ifp->name, bssidx, i));
1579 break;
1580 }
1581 }
1582 return i;
1583 }
1584
dhd_rxf_enqueue(dhd_pub_t * dhdp,void * skb)1585 static inline int dhd_rxf_enqueue(dhd_pub_t *dhdp, void* skb)
1586 {
1587 uint32 store_idx;
1588 uint32 sent_idx;
1589
1590 if (!skb) {
1591 DHD_ERROR(("dhd_rxf_enqueue: NULL skb!!!\n"));
1592 return BCME_ERROR;
1593 }
1594
1595 dhd_os_rxflock(dhdp);
1596 store_idx = dhdp->store_idx;
1597 sent_idx = dhdp->sent_idx;
1598 if (dhdp->skbbuf[store_idx] != NULL) {
1599 /* Make sure the previous packets are processed */
1600 dhd_os_rxfunlock(dhdp);
1601 DHD_ERROR(("dhd_rxf_enqueue: pktbuf not consumed %p, store idx %d sent idx %d\n",
1602 skb, store_idx, sent_idx));
1603 /* removed msleep here, should use wait_event_timeout if we
1604 * want to give rx frame thread a chance to run
1605 */
1606 #if defined(WAIT_DEQUEUE)
1607 OSL_SLEEP(1);
1608 #endif // endif
1609 return BCME_ERROR;
1610 }
1611 DHD_TRACE(("dhd_rxf_enqueue: Store SKB %p. idx %d -> %d\n",
1612 skb, store_idx, (store_idx + 1) & (MAXSKBPEND - 1)));
1613 dhdp->skbbuf[store_idx] = skb;
1614 dhdp->store_idx = (store_idx + 1) & (MAXSKBPEND - 1);
1615 dhd_os_rxfunlock(dhdp);
1616
1617 return BCME_OK;
1618 }
1619
dhd_rxf_dequeue(dhd_pub_t * dhdp)1620 static inline void* dhd_rxf_dequeue(dhd_pub_t *dhdp)
1621 {
1622 uint32 store_idx;
1623 uint32 sent_idx;
1624 void *skb;
1625
1626 dhd_os_rxflock(dhdp);
1627
1628 store_idx = dhdp->store_idx;
1629 sent_idx = dhdp->sent_idx;
1630 skb = dhdp->skbbuf[sent_idx];
1631
1632 if (skb == NULL) {
1633 dhd_os_rxfunlock(dhdp);
1634 DHD_ERROR(("dhd_rxf_dequeue: Dequeued packet is NULL, store idx %d sent idx %d\n",
1635 store_idx, sent_idx));
1636 return NULL;
1637 }
1638
1639 dhdp->skbbuf[sent_idx] = NULL;
1640 dhdp->sent_idx = (sent_idx + 1) & (MAXSKBPEND - 1);
1641
1642 DHD_TRACE(("dhd_rxf_dequeue: netif_rx_ni(%p), sent idx %d\n",
1643 skb, sent_idx));
1644
1645 dhd_os_rxfunlock(dhdp);
1646
1647 return skb;
1648 }
1649
dhd_process_cid_mac(dhd_pub_t * dhdp,bool prepost)1650 int dhd_process_cid_mac(dhd_pub_t *dhdp, bool prepost)
1651 {
1652 if (prepost) { /* pre process */
1653 dhd_read_cis(dhdp);
1654 dhd_check_module_cid(dhdp);
1655 dhd_check_module_mac(dhdp);
1656 dhd_set_macaddr_from_file(dhdp);
1657 } else { /* post process */
1658 dhd_write_macaddr(&dhdp->mac);
1659 dhd_clear_cis(dhdp);
1660 }
1661
1662 return 0;
1663 }
1664
1665 #if defined(WL_CFG80211) && defined(DHD_FILE_DUMP_EVENT) && defined(DHD_FW_COREDUMP)
dhd_wait_for_file_dump(dhd_pub_t * dhdp)1666 static int dhd_wait_for_file_dump(dhd_pub_t *dhdp)
1667 {
1668 struct net_device *primary_ndev;
1669 struct bcm_cfg80211 *cfg;
1670 unsigned long flags = 0;
1671 primary_ndev = dhd_linux_get_primary_netdev(dhdp);
1672
1673 if (!primary_ndev) {
1674 DHD_ERROR(("%s: Cannot find primary netdev\n", __FUNCTION__));
1675 return BCME_ERROR;
1676 }
1677 cfg = wl_get_cfg(primary_ndev);
1678
1679 if (!cfg) {
1680 DHD_ERROR(("%s: Cannot find cfg\n", __FUNCTION__));
1681 return BCME_ERROR;
1682 }
1683
1684 DHD_GENERAL_LOCK(dhdp, flags);
1685 if (DHD_BUS_CHECK_DOWN_OR_DOWN_IN_PROGRESS(dhdp)) {
1686 DHD_BUS_BUSY_CLEAR_IN_HALDUMP(dhdp);
1687 dhd_os_busbusy_wake(dhdp);
1688 DHD_GENERAL_UNLOCK(dhdp, flags);
1689 DHD_ERROR(("%s: bus is down! can't collect log dump. \n", __FUNCTION__));
1690 return BCME_ERROR;
1691 }
1692 DHD_BUS_BUSY_SET_IN_HALDUMP(dhdp);
1693 DHD_GENERAL_UNLOCK(dhdp, flags);
1694
1695 DHD_OS_WAKE_LOCK(dhdp);
1696 /* check for hal started and only then send event if not clear dump state here */
1697 if (wl_cfg80211_is_hal_started(cfg)) {
1698 int timeleft = 0;
1699
1700 DHD_ERROR(("[DUMP] %s: HAL started. send urgent event\n", __FUNCTION__));
1701 dhd_dbg_send_urgent_evt(dhdp, NULL, 0);
1702
1703 DHD_ERROR(("%s: wait to clear dhd_bus_busy_state: 0x%x\n",
1704 __FUNCTION__, dhdp->dhd_bus_busy_state));
1705 timeleft = dhd_os_busbusy_wait_bitmask(dhdp,
1706 &dhdp->dhd_bus_busy_state, DHD_BUS_BUSY_IN_HALDUMP, 0);
1707 if ((dhdp->dhd_bus_busy_state & DHD_BUS_BUSY_IN_HALDUMP) != 0) {
1708 DHD_ERROR(("%s: Timed out dhd_bus_busy_state=0x%x\n",
1709 __FUNCTION__, dhdp->dhd_bus_busy_state));
1710 }
1711 } else {
1712 DHD_ERROR(("[DUMP] %s: HAL Not started. skip urgent event\n", __FUNCTION__));
1713 }
1714 DHD_OS_WAKE_UNLOCK(dhdp);
1715 /* In case of dhd_os_busbusy_wait_bitmask() timeout,
1716 * hal dump bit will not be cleared. Hence clearing it here.
1717 */
1718 DHD_GENERAL_LOCK(dhdp, flags);
1719 DHD_BUS_BUSY_CLEAR_IN_HALDUMP(dhdp);
1720 dhd_os_busbusy_wake(dhdp);
1721 DHD_GENERAL_UNLOCK(dhdp, flags);
1722
1723 return BCME_OK;
1724 }
1725 #endif /* WL_CFG80211 && DHD_FILE_DUMP_EVENT && DHD_FW_CORE_DUMP */
1726
1727 // terence 20160615: fix building error if ARP_OFFLOAD_SUPPORT removed
1728 #if defined(PKT_FILTER_SUPPORT)
1729 #if defined(ARP_OFFLOAD_SUPPORT) && !defined(GAN_LITE_NAT_KEEPALIVE_FILTER)
1730 static bool
_turn_on_arp_filter(dhd_pub_t * dhd,int op_mode_param)1731 _turn_on_arp_filter(dhd_pub_t *dhd, int op_mode_param)
1732 {
1733 bool _apply = FALSE;
1734 /* In case of IBSS mode, apply arp pkt filter */
1735 if (op_mode_param & DHD_FLAG_IBSS_MODE) {
1736 _apply = TRUE;
1737 goto exit;
1738 }
1739 /* In case of P2P GO or GC, apply pkt filter to pass arp pkt to host */
1740 if (op_mode_param & (DHD_FLAG_P2P_GC_MODE | DHD_FLAG_P2P_GO_MODE)) {
1741 _apply = TRUE;
1742 goto exit;
1743 }
1744
1745 exit:
1746 return _apply;
1747 }
1748 #endif /* !GAN_LITE_NAT_KEEPALIVE_FILTER */
1749
1750 void
dhd_set_packet_filter(dhd_pub_t * dhd)1751 dhd_set_packet_filter(dhd_pub_t *dhd)
1752 {
1753 int i;
1754
1755 DHD_TRACE(("%s: enter\n", __FUNCTION__));
1756 if (dhd_pkt_filter_enable) {
1757 for (i = 0; i < dhd->pktfilter_count; i++) {
1758 dhd_pktfilter_offload_set(dhd, dhd->pktfilter[i]);
1759 }
1760 }
1761 }
1762
1763 void
dhd_enable_packet_filter(int value,dhd_pub_t * dhd)1764 dhd_enable_packet_filter(int value, dhd_pub_t *dhd)
1765 {
1766 int i;
1767
1768 DHD_ERROR(("%s: enter, value = %d\n", __FUNCTION__, value));
1769 if ((dhd->op_mode & DHD_FLAG_HOSTAP_MODE) && value &&
1770 !dhd_conf_get_insuspend(dhd, AP_FILTER_IN_SUSPEND)) {
1771 DHD_ERROR(("%s: DHD_FLAG_HOSTAP_MODE\n", __FUNCTION__));
1772 return;
1773 }
1774 /* 1 - Enable packet filter, only allow unicast packet to send up */
1775 /* 0 - Disable packet filter */
1776 if (dhd_pkt_filter_enable && (!value ||
1777 (dhd_support_sta_mode(dhd) && !dhd->dhcp_in_progress) ||
1778 dhd_conf_get_insuspend(dhd, AP_FILTER_IN_SUSPEND)))
1779 {
1780 for (i = 0; i < dhd->pktfilter_count; i++) {
1781 // terence 20160615: fix building error if ARP_OFFLOAD_SUPPORT removed
1782 #if defined(ARP_OFFLOAD_SUPPORT) && !defined(GAN_LITE_NAT_KEEPALIVE_FILTER)
1783 if (value && (i == DHD_ARP_FILTER_NUM) &&
1784 !_turn_on_arp_filter(dhd, dhd->op_mode)) {
1785 DHD_TRACE(("Do not turn on ARP white list pkt filter:"
1786 "val %d, cnt %d, op_mode 0x%x\n",
1787 value, i, dhd->op_mode));
1788 continue;
1789 }
1790 #endif /* !GAN_LITE_NAT_KEEPALIVE_FILTER */
1791 dhd_pktfilter_offload_enable(dhd, dhd->pktfilter[i],
1792 value, dhd_master_mode);
1793 }
1794 }
1795 }
1796
1797 int
dhd_packet_filter_add_remove(dhd_pub_t * dhdp,int add_remove,int num)1798 dhd_packet_filter_add_remove(dhd_pub_t *dhdp, int add_remove, int num)
1799 {
1800 char *filterp = NULL;
1801 int filter_id = 0;
1802
1803 switch (num) {
1804 case DHD_BROADCAST_FILTER_NUM:
1805 filterp = "101 0 0 0 0xFFFFFFFFFFFF 0xFFFFFFFFFFFF";
1806 filter_id = 101;
1807 break;
1808 case DHD_MULTICAST4_FILTER_NUM:
1809 filter_id = 102;
1810 if (FW_SUPPORTED((dhdp), pf6)) {
1811 if (dhdp->pktfilter[num] != NULL) {
1812 dhd_pktfilter_offload_delete(dhdp, filter_id);
1813 dhdp->pktfilter[num] = NULL;
1814 }
1815 if (!add_remove) {
1816 filterp = DISCARD_IPV4_MCAST;
1817 add_remove = 1;
1818 break;
1819 }
1820 }
1821 filterp = "102 0 0 0 0xFFFFFF 0x01005E";
1822 break;
1823 case DHD_MULTICAST6_FILTER_NUM:
1824 filter_id = 103;
1825 if (FW_SUPPORTED((dhdp), pf6)) {
1826 if (dhdp->pktfilter[num] != NULL) {
1827 dhd_pktfilter_offload_delete(dhdp, filter_id);
1828 dhdp->pktfilter[num] = NULL;
1829 }
1830 if (!add_remove) {
1831 filterp = DISCARD_IPV6_MCAST;
1832 add_remove = 1;
1833 break;
1834 }
1835 }
1836 filterp = "103 0 0 0 0xFFFF 0x3333";
1837 break;
1838 case DHD_MDNS_FILTER_NUM:
1839 filterp = "104 0 0 0 0xFFFFFFFFFFFF 0x01005E0000FB";
1840 filter_id = 104;
1841 break;
1842 case DHD_ARP_FILTER_NUM:
1843 filterp = "105 0 0 12 0xFFFF 0x0806";
1844 filter_id = 105;
1845 break;
1846 case DHD_BROADCAST_ARP_FILTER_NUM:
1847 filterp = "106 0 0 0 0xFFFFFFFFFFFF0000000000000806"
1848 " 0xFFFFFFFFFFFF0000000000000806";
1849 filter_id = 106;
1850 break;
1851 default:
1852 return -EINVAL;
1853 }
1854
1855 /* Add filter */
1856 if (add_remove) {
1857 dhdp->pktfilter[num] = filterp;
1858 dhd_pktfilter_offload_set(dhdp, dhdp->pktfilter[num]);
1859 } else { /* Delete filter */
1860 if (dhdp->pktfilter[num]) {
1861 dhd_pktfilter_offload_delete(dhdp, filter_id);
1862 dhdp->pktfilter[num] = NULL;
1863 }
1864 }
1865
1866 return 0;
1867 }
1868 #endif /* PKT_FILTER_SUPPORT */
1869
dhd_set_suspend(int value,dhd_pub_t * dhd)1870 static int dhd_set_suspend(int value, dhd_pub_t *dhd)
1871 {
1872 #ifndef SUPPORT_PM2_ONLY
1873 int power_mode = PM_MAX;
1874 #endif /* SUPPORT_PM2_ONLY */
1875 /* wl_pkt_filter_enable_t enable_parm; */
1876 int bcn_li_dtim = 0; /* Default bcn_li_dtim in resume mode is 0 */
1877 int ret = 0;
1878 #ifdef DHD_USE_EARLYSUSPEND
1879 #ifdef CUSTOM_BCN_TIMEOUT_IN_SUSPEND
1880 int bcn_timeout = 0;
1881 #endif /* CUSTOM_BCN_TIMEOUT_IN_SUSPEND */
1882 #ifdef CUSTOM_ROAM_TIME_THRESH_IN_SUSPEND
1883 int roam_time_thresh = 0; /* (ms) */
1884 #endif /* CUSTOM_ROAM_TIME_THRESH_IN_SUSPEND */
1885 #ifndef ENABLE_FW_ROAM_SUSPEND
1886 uint roamvar = 1;
1887 #endif /* ENABLE_FW_ROAM_SUSPEND */
1888 #ifdef ENABLE_BCN_LI_BCN_WAKEUP
1889 int bcn_li_bcn = 1;
1890 #endif /* ENABLE_BCN_LI_BCN_WAKEUP */
1891 uint nd_ra_filter = 0;
1892 #ifdef ENABLE_IPMCAST_FILTER
1893 int ipmcast_l2filter;
1894 #endif /* ENABLE_IPMCAST_FILTER */
1895 #ifdef CUSTOM_EVENT_PM_WAKE
1896 uint32 pm_awake_thresh = CUSTOM_EVENT_PM_WAKE;
1897 #endif /* CUSTOM_EVENT_PM_WAKE */
1898 #endif /* DHD_USE_EARLYSUSPEND */
1899 #ifdef PASS_ALL_MCAST_PKTS
1900 struct dhd_info *dhdinfo;
1901 uint32 allmulti;
1902 uint i;
1903 #endif /* PASS_ALL_MCAST_PKTS */
1904 #ifdef DYNAMIC_SWOOB_DURATION
1905 #ifndef CUSTOM_INTR_WIDTH
1906 #define CUSTOM_INTR_WIDTH 100
1907 int intr_width = 0;
1908 #endif /* CUSTOM_INTR_WIDTH */
1909 #endif /* DYNAMIC_SWOOB_DURATION */
1910
1911 #if defined(BCMPCIE)
1912 int lpas = 0;
1913 int dtim_period = 0;
1914 int bcn_interval = 0;
1915 int bcn_to_dly = 0;
1916 #if defined(CUSTOM_BCN_TIMEOUT_IN_SUSPEND) && defined(DHD_USE_EARLYSUSPEND)
1917 bcn_timeout = CUSTOM_BCN_TIMEOUT_SETTING;
1918 #else
1919 int bcn_timeout = CUSTOM_BCN_TIMEOUT_SETTING;
1920 #endif /* CUSTOM_BCN_TIMEOUT_IN_SUSPEND && DHD_USE_EARLYSUSPEND */
1921 #endif /* OEM_ANDROID && BCMPCIE */
1922
1923 if (!dhd)
1924 return -ENODEV;
1925
1926 #ifdef PASS_ALL_MCAST_PKTS
1927 dhdinfo = dhd->info;
1928 #endif /* PASS_ALL_MCAST_PKTS */
1929
1930 DHD_TRACE(("%s: enter, value = %d in_suspend=%d\n",
1931 __FUNCTION__, value, dhd->in_suspend));
1932
1933 dhd_suspend_lock(dhd);
1934
1935 #ifdef CUSTOM_SET_CPUCORE
1936 DHD_TRACE(("%s set cpucore(suspend%d)\n", __FUNCTION__, value));
1937 /* set specific cpucore */
1938 dhd_set_cpucore(dhd, TRUE);
1939 #endif /* CUSTOM_SET_CPUCORE */
1940 if (dhd->up) {
1941 if (value && dhd->in_suspend) {
1942 #ifdef PKT_FILTER_SUPPORT
1943 dhd->early_suspended = 1;
1944 #endif // endif
1945 /* Kernel suspended */
1946 DHD_ERROR(("%s: force extra Suspend setting\n", __FUNCTION__));
1947
1948 #ifndef SUPPORT_PM2_ONLY
1949 dhd_wl_ioctl_cmd(dhd, WLC_SET_PM, (char *)&power_mode,
1950 sizeof(power_mode), TRUE, 0);
1951 #endif /* SUPPORT_PM2_ONLY */
1952
1953 #ifdef PKT_FILTER_SUPPORT
1954 /* Enable packet filter,
1955 * only allow unicast packet to send up
1956 */
1957 dhd_enable_packet_filter(1, dhd);
1958 #ifdef APF
1959 dhd_dev_apf_enable_filter(dhd_linux_get_primary_netdev(dhd));
1960 #endif /* APF */
1961 #endif /* PKT_FILTER_SUPPORT */
1962 #ifdef ARP_OFFLOAD_SUPPORT
1963 dhd_arp_offload_enable(dhd, TRUE);
1964 #endif /* ARP_OFFLOAD_SUPPORT */
1965
1966 #ifdef PASS_ALL_MCAST_PKTS
1967 allmulti = 0;
1968 for (i = 0; i < DHD_MAX_IFS; i++) {
1969 if (dhdinfo->iflist[i] && dhdinfo->iflist[i]->net)
1970 ret = dhd_iovar(dhd, i, "allmulti", (char *)&allmulti,
1971 sizeof(allmulti), NULL, 0, TRUE);
1972 if (ret < 0) {
1973 DHD_ERROR(("%s allmulti failed %d\n", __FUNCTION__, ret));
1974 }
1975 }
1976 #endif /* PASS_ALL_MCAST_PKTS */
1977
1978 /* If DTIM skip is set up as default, force it to wake
1979 * each third DTIM for better power savings. Note that
1980 * one side effect is a chance to miss BC/MC packet.
1981 */
1982 #ifdef WLTDLS
1983 /* Do not set bcn_li_ditm on WFD mode */
1984 if (dhd->tdls_mode) {
1985 bcn_li_dtim = 0;
1986 } else
1987 #endif /* WLTDLS */
1988 #if defined(BCMPCIE)
1989 bcn_li_dtim = dhd_get_suspend_bcn_li_dtim(dhd, &dtim_period,
1990 &bcn_interval);
1991 ret = dhd_iovar(dhd, 0, "bcn_li_dtim", (char *)&bcn_li_dtim,
1992 sizeof(bcn_li_dtim), NULL, 0, TRUE);
1993 if (ret < 0) {
1994 DHD_ERROR(("%s bcn_li_dtim failed %d\n", __FUNCTION__, ret));
1995 }
1996 if ((bcn_li_dtim * dtim_period * bcn_interval) >=
1997 MIN_DTIM_FOR_ROAM_THRES_EXTEND) {
1998 /*
1999 * Increase max roaming threshold from 2 secs to 8 secs
2000 * the real roam threshold is MIN(max_roam_threshold,
2001 * bcn_timeout/2)
2002 */
2003 lpas = 1;
2004 ret = dhd_iovar(dhd, 0, "lpas", (char *)&lpas, sizeof(lpas),
2005 NULL, 0, TRUE);
2006 if (ret < 0) {
2007 DHD_ERROR(("%s lpas failed %d\n", __FUNCTION__, ret));
2008 }
2009 bcn_to_dly = 1;
2010 /*
2011 * if bcn_to_dly is 1, the real roam threshold is
2012 * MIN(max_roam_threshold, bcn_timeout -1);
2013 * notify link down event after roaming procedure complete
2014 * if we hit bcn_timeout while we are in roaming progress.
2015 */
2016 ret = dhd_iovar(dhd, 0, "bcn_to_dly", (char *)&bcn_to_dly,
2017 sizeof(bcn_to_dly), NULL, 0, TRUE);
2018 if (ret < 0) {
2019 DHD_ERROR(("%s bcn_to_dly failed %d\n", __FUNCTION__, ret));
2020 }
2021 /* Increase beacon timeout to 6 secs or use bigger one */
2022 bcn_timeout = max(bcn_timeout, BCN_TIMEOUT_IN_SUSPEND);
2023 ret = dhd_iovar(dhd, 0, "bcn_timeout", (char *)&bcn_timeout,
2024 sizeof(bcn_timeout), NULL, 0, TRUE);
2025 if (ret < 0) {
2026 DHD_ERROR(("%s bcn_timeout failed %d\n", __FUNCTION__, ret));
2027 }
2028 }
2029 #else
2030 bcn_li_dtim = dhd_get_suspend_bcn_li_dtim(dhd);
2031 if (dhd_iovar(dhd, 0, "bcn_li_dtim", (char *)&bcn_li_dtim,
2032 sizeof(bcn_li_dtim), NULL, 0, TRUE) < 0)
2033 DHD_ERROR(("%s: set dtim failed\n", __FUNCTION__));
2034 #endif /* OEM_ANDROID && BCMPCIE */
2035 #ifdef WL_CFG80211
2036 /* Disable cfg80211 feature events during suspend */
2037 ret = wl_cfg80211_config_suspend_events(
2038 dhd_linux_get_primary_netdev(dhd), FALSE);
2039 if (ret < 0) {
2040 DHD_ERROR(("failed to disable events (%d)\n", ret));
2041 }
2042 #endif /* WL_CFG80211 */
2043 #ifdef DHD_USE_EARLYSUSPEND
2044 #ifdef CUSTOM_BCN_TIMEOUT_IN_SUSPEND
2045 bcn_timeout = CUSTOM_BCN_TIMEOUT_IN_SUSPEND;
2046 ret = dhd_iovar(dhd, 0, "bcn_timeout", (char *)&bcn_timeout,
2047 sizeof(bcn_timeout), NULL, 0, TRUE);
2048 if (ret < 0) {
2049 DHD_ERROR(("%s bcn_timeout failed %d\n", __FUNCTION__, ret));
2050 }
2051 #endif /* CUSTOM_BCN_TIMEOUT_IN_SUSPEND */
2052 #ifdef CUSTOM_ROAM_TIME_THRESH_IN_SUSPEND
2053 roam_time_thresh = CUSTOM_ROAM_TIME_THRESH_IN_SUSPEND;
2054 ret = dhd_iovar(dhd, 0, "roam_time_thresh", (char *)&roam_time_thresh,
2055 sizeof(roam_time_thresh), NULL, 0, TRUE);
2056 if (ret < 0) {
2057 DHD_ERROR(("%s roam_time_thresh failed %d\n", __FUNCTION__, ret));
2058 }
2059 #endif /* CUSTOM_ROAM_TIME_THRESH_IN_SUSPEND */
2060 #ifndef ENABLE_FW_ROAM_SUSPEND
2061 /* Disable firmware roaming during suspend */
2062 ret = dhd_iovar(dhd, 0, "roam_off", (char *)&roamvar,
2063 sizeof(roamvar), NULL, 0, TRUE);
2064 if (ret < 0) {
2065 DHD_ERROR(("%s roam_off failed %d\n", __FUNCTION__, ret));
2066 }
2067 #endif /* ENABLE_FW_ROAM_SUSPEND */
2068 #ifdef ENABLE_BCN_LI_BCN_WAKEUP
2069 if (bcn_li_dtim) {
2070 bcn_li_bcn = 0;
2071 }
2072 ret = dhd_iovar(dhd, 0, "bcn_li_bcn", (char *)&bcn_li_bcn,
2073 sizeof(bcn_li_bcn), NULL, 0, TRUE);
2074 if (ret < 0) {
2075 DHD_ERROR(("%s bcn_li_bcn failed %d\n", __FUNCTION__, ret));
2076 }
2077 #endif /* ENABLE_BCN_LI_BCN_WAKEUP */
2078 #if defined(WL_CFG80211) && defined(WL_BCNRECV)
2079 ret = wl_android_bcnrecv_suspend(dhd_linux_get_primary_netdev(dhd));
2080 if (ret != BCME_OK) {
2081 DHD_ERROR(("failed to stop beacon recv event on"
2082 " suspend state (%d)\n", ret));
2083 }
2084 #endif /* WL_CFG80211 && WL_BCNRECV */
2085 #ifdef NDO_CONFIG_SUPPORT
2086 if (dhd->ndo_enable) {
2087 if (!dhd->ndo_host_ip_overflow) {
2088 /* enable ND offload on suspend */
2089 ret = dhd_ndo_enable(dhd, TRUE);
2090 if (ret < 0) {
2091 DHD_ERROR(("%s: failed to enable NDO\n",
2092 __FUNCTION__));
2093 }
2094 } else {
2095 DHD_INFO(("%s: NDO disabled on suspend due to"
2096 "HW capacity\n", __FUNCTION__));
2097 }
2098 }
2099 #endif /* NDO_CONFIG_SUPPORT */
2100 #ifndef APF
2101 if (FW_SUPPORTED(dhd, ndoe))
2102 #else
2103 if (FW_SUPPORTED(dhd, ndoe) && !FW_SUPPORTED(dhd, apf))
2104 #endif /* APF */
2105 {
2106 /* enable IPv6 RA filter in firmware during suspend */
2107 nd_ra_filter = 1;
2108 ret = dhd_iovar(dhd, 0, "nd_ra_filter_enable",
2109 (char *)&nd_ra_filter, sizeof(nd_ra_filter),
2110 NULL, 0, TRUE);
2111 if (ret < 0)
2112 DHD_ERROR(("failed to set nd_ra_filter (%d)\n",
2113 ret));
2114 }
2115 dhd_os_suppress_logging(dhd, TRUE);
2116 #ifdef ENABLE_IPMCAST_FILTER
2117 ipmcast_l2filter = 1;
2118 ret = dhd_iovar(dhd, 0, "ipmcast_l2filter",
2119 (char *)&ipmcast_l2filter, sizeof(ipmcast_l2filter),
2120 NULL, 0, TRUE);
2121 if (ret < 0) {
2122 DHD_ERROR(("failed to set ipmcast_l2filter (%d)\n", ret));
2123 }
2124 #endif /* ENABLE_IPMCAST_FILTER */
2125 #ifdef DYNAMIC_SWOOB_DURATION
2126 intr_width = CUSTOM_INTR_WIDTH;
2127 ret = dhd_iovar(dhd, 0, "bus:intr_width", (char *)&intr_width,
2128 sizeof(intr_width), NULL, 0, TRUE);
2129 if (ret < 0) {
2130 DHD_ERROR(("failed to set intr_width (%d)\n", ret));
2131 }
2132 #endif /* DYNAMIC_SWOOB_DURATION */
2133 #ifdef CUSTOM_EVENT_PM_WAKE
2134 pm_awake_thresh = CUSTOM_EVENT_PM_WAKE * 4;
2135 ret = dhd_iovar(dhd, 0, "const_awake_thresh",
2136 (char *)&pm_awake_thresh,
2137 sizeof(pm_awake_thresh), NULL, 0, TRUE);
2138 if (ret < 0) {
2139 DHD_ERROR(("%s set const_awake_thresh failed %d\n",
2140 __FUNCTION__, ret));
2141 }
2142 #endif /* CUSTOM_EVENT_PM_WAKE */
2143 #ifdef CONFIG_SILENT_ROAM
2144 if (!dhd->sroamed) {
2145 ret = dhd_sroam_set_mon(dhd, TRUE);
2146 if (ret < 0) {
2147 DHD_ERROR(("%s set sroam failed %d\n",
2148 __FUNCTION__, ret));
2149 }
2150 }
2151 dhd->sroamed = FALSE;
2152 #endif /* CONFIG_SILENT_ROAM */
2153 #endif /* DHD_USE_EARLYSUSPEND */
2154 } else {
2155 #ifdef PKT_FILTER_SUPPORT
2156 dhd->early_suspended = 0;
2157 #endif // endif
2158 /* Kernel resumed */
2159 DHD_ERROR(("%s: Remove extra suspend setting \n", __FUNCTION__));
2160 #ifdef DYNAMIC_SWOOB_DURATION
2161 intr_width = 0;
2162 ret = dhd_iovar(dhd, 0, "bus:intr_width", (char *)&intr_width,
2163 sizeof(intr_width), NULL, 0, TRUE);
2164 if (ret < 0) {
2165 DHD_ERROR(("failed to set intr_width (%d)\n", ret));
2166 }
2167 #endif /* DYNAMIC_SWOOB_DURATION */
2168 #ifndef SUPPORT_PM2_ONLY
2169 power_mode = PM_FAST;
2170 dhd_wl_ioctl_cmd(dhd, WLC_SET_PM, (char *)&power_mode,
2171 sizeof(power_mode), TRUE, 0);
2172 #endif /* SUPPORT_PM2_ONLY */
2173 #if defined(WL_CFG80211) && defined(WL_BCNRECV)
2174 ret = wl_android_bcnrecv_resume(dhd_linux_get_primary_netdev(dhd));
2175 if (ret != BCME_OK) {
2176 DHD_ERROR(("failed to resume beacon recv state (%d)\n",
2177 ret));
2178 }
2179 #endif /* WL_CF80211 && WL_BCNRECV */
2180 #ifdef ARP_OFFLOAD_SUPPORT
2181 dhd_arp_offload_enable(dhd, FALSE);
2182 #endif /* ARP_OFFLOAD_SUPPORT */
2183 #ifdef PKT_FILTER_SUPPORT
2184 /* disable pkt filter */
2185 dhd_enable_packet_filter(0, dhd);
2186 #ifdef APF
2187 dhd_dev_apf_disable_filter(dhd_linux_get_primary_netdev(dhd));
2188 #endif /* APF */
2189 #endif /* PKT_FILTER_SUPPORT */
2190 #ifdef PASS_ALL_MCAST_PKTS
2191 allmulti = 1;
2192 for (i = 0; i < DHD_MAX_IFS; i++) {
2193 if (dhdinfo->iflist[i] && dhdinfo->iflist[i]->net)
2194 ret = dhd_iovar(dhd, i, "allmulti", (char *)&allmulti,
2195 sizeof(allmulti), NULL, 0, TRUE);
2196 if (ret < 0) {
2197 DHD_ERROR(("%s: allmulti failed:%d\n", __FUNCTION__, ret));
2198 }
2199 }
2200 #endif /* PASS_ALL_MCAST_PKTS */
2201 #if defined(BCMPCIE)
2202 /* restore pre-suspend setting */
2203 ret = dhd_iovar(dhd, 0, "bcn_li_dtim", (char *)&bcn_li_dtim,
2204 sizeof(bcn_li_dtim), NULL, 0, TRUE);
2205 if (ret < 0) {
2206 DHD_ERROR(("%s:bcn_li_ditm failed:%d\n", __FUNCTION__, ret));
2207 }
2208 ret = dhd_iovar(dhd, 0, "lpas", (char *)&lpas, sizeof(lpas), NULL,
2209 0, TRUE);
2210 if (ret < 0) {
2211 DHD_ERROR(("%s:lpas failed:%d\n", __FUNCTION__, ret));
2212 }
2213 ret = dhd_iovar(dhd, 0, "bcn_to_dly", (char *)&bcn_to_dly,
2214 sizeof(bcn_to_dly), NULL, 0, TRUE);
2215 if (ret < 0) {
2216 DHD_ERROR(("%s:bcn_to_dly failed:%d\n", __FUNCTION__, ret));
2217 }
2218 ret = dhd_iovar(dhd, 0, "bcn_timeout", (char *)&bcn_timeout,
2219 sizeof(bcn_timeout), NULL, 0, TRUE);
2220 if (ret < 0) {
2221 DHD_ERROR(("%s:bcn_timeout failed:%d\n", __FUNCTION__, ret));
2222 }
2223 #else
2224 /* restore pre-suspend setting for dtim_skip */
2225 ret = dhd_iovar(dhd, 0, "bcn_li_dtim", (char *)&bcn_li_dtim,
2226 sizeof(bcn_li_dtim), NULL, 0, TRUE);
2227 if (ret < 0) {
2228 DHD_ERROR(("%s:bcn_li_ditm fail:%d\n", __FUNCTION__, ret));
2229 }
2230 #endif /* OEM_ANDROID && BCMPCIE */
2231 #ifdef DHD_USE_EARLYSUSPEND
2232 #ifdef CUSTOM_BCN_TIMEOUT_IN_SUSPEND
2233 bcn_timeout = CUSTOM_BCN_TIMEOUT;
2234 ret = dhd_iovar(dhd, 0, "bcn_timeout", (char *)&bcn_timeout,
2235 sizeof(bcn_timeout), NULL, 0, TRUE);
2236 if (ret < 0) {
2237 DHD_ERROR(("%s:bcn_timeout failed:%d\n", __FUNCTION__, ret));
2238 }
2239 #endif /* CUSTOM_BCN_TIMEOUT_IN_SUSPEND */
2240 #ifdef CUSTOM_ROAM_TIME_THRESH_IN_SUSPEND
2241 roam_time_thresh = 2000;
2242 ret = dhd_iovar(dhd, 0, "roam_time_thresh", (char *)&roam_time_thresh,
2243 sizeof(roam_time_thresh), NULL, 0, TRUE);
2244 if (ret < 0) {
2245 DHD_ERROR(("%s:roam_time_thresh failed:%d\n", __FUNCTION__, ret));
2246 }
2247
2248 #endif /* CUSTOM_ROAM_TIME_THRESH_IN_SUSPEND */
2249 #ifndef ENABLE_FW_ROAM_SUSPEND
2250 roamvar = dhd_roam_disable;
2251 ret = dhd_iovar(dhd, 0, "roam_off", (char *)&roamvar,
2252 sizeof(roamvar), NULL, 0, TRUE);
2253 if (ret < 0) {
2254 DHD_ERROR(("%s: roam_off fail:%d\n", __FUNCTION__, ret));
2255 }
2256 #endif /* ENABLE_FW_ROAM_SUSPEND */
2257 #ifdef ENABLE_BCN_LI_BCN_WAKEUP
2258 ret = dhd_iovar(dhd, 0, "bcn_li_bcn", (char *)&bcn_li_bcn,
2259 sizeof(bcn_li_bcn), NULL, 0, TRUE);
2260 if (ret < 0) {
2261 DHD_ERROR(("%s: bcn_li_bcn failed:%d\n", __FUNCTION__, ret));
2262 }
2263 #endif /* ENABLE_BCN_LI_BCN_WAKEUP */
2264 #ifdef NDO_CONFIG_SUPPORT
2265 if (dhd->ndo_enable) {
2266 /* Disable ND offload on resume */
2267 ret = dhd_ndo_enable(dhd, FALSE);
2268 if (ret < 0) {
2269 DHD_ERROR(("%s: failed to disable NDO\n",
2270 __FUNCTION__));
2271 }
2272 }
2273 #endif /* NDO_CONFIG_SUPPORT */
2274 #ifndef APF
2275 if (FW_SUPPORTED(dhd, ndoe))
2276 #else
2277 if (FW_SUPPORTED(dhd, ndoe) && !FW_SUPPORTED(dhd, apf))
2278 #endif /* APF */
2279 {
2280 /* disable IPv6 RA filter in firmware during suspend */
2281 nd_ra_filter = 0;
2282 ret = dhd_iovar(dhd, 0, "nd_ra_filter_enable",
2283 (char *)&nd_ra_filter, sizeof(nd_ra_filter),
2284 NULL, 0, TRUE);
2285 if (ret < 0) {
2286 DHD_ERROR(("failed to set nd_ra_filter (%d)\n",
2287 ret));
2288 }
2289 }
2290 dhd_os_suppress_logging(dhd, FALSE);
2291 #ifdef ENABLE_IPMCAST_FILTER
2292 ipmcast_l2filter = 0;
2293 ret = dhd_iovar(dhd, 0, "ipmcast_l2filter",
2294 (char *)&ipmcast_l2filter, sizeof(ipmcast_l2filter),
2295 NULL, 0, TRUE);
2296 if (ret < 0) {
2297 DHD_ERROR(("failed to clear ipmcast_l2filter ret:%d", ret));
2298 }
2299 #endif /* ENABLE_IPMCAST_FILTER */
2300 #ifdef CUSTOM_EVENT_PM_WAKE
2301 ret = dhd_iovar(dhd, 0, "const_awake_thresh",
2302 (char *)&pm_awake_thresh,
2303 sizeof(pm_awake_thresh), NULL, 0, TRUE);
2304 if (ret < 0) {
2305 DHD_ERROR(("%s set const_awake_thresh failed %d\n",
2306 __FUNCTION__, ret));
2307 }
2308 #endif /* CUSTOM_EVENT_PM_WAKE */
2309 #ifdef CONFIG_SILENT_ROAM
2310 ret = dhd_sroam_set_mon(dhd, FALSE);
2311 if (ret < 0) {
2312 DHD_ERROR(("%s set sroam failed %d\n", __FUNCTION__, ret));
2313 }
2314 #endif /* CONFIG_SILENT_ROAM */
2315 #endif /* DHD_USE_EARLYSUSPEND */
2316 #ifdef WL_CFG80211
2317 /* Enable cfg80211 feature events during resume */
2318 ret = wl_cfg80211_config_suspend_events(
2319 dhd_linux_get_primary_netdev(dhd), TRUE);
2320 if (ret < 0) {
2321 DHD_ERROR(("failed to enable events (%d)\n", ret));
2322 }
2323 #endif /* WL_CFG80211 */
2324 #ifdef DHD_LB_IRQSET
2325 dhd_irq_set_affinity(dhd, dhd->info->cpumask_primary);
2326 #endif /* DHD_LB_IRQSET */
2327 }
2328 }
2329 dhd_suspend_unlock(dhd);
2330
2331 return 0;
2332 }
2333
dhd_suspend_resume_helper(struct dhd_info * dhd,int val,int force)2334 static int dhd_suspend_resume_helper(struct dhd_info *dhd, int val, int force)
2335 {
2336 dhd_pub_t *dhdp = &dhd->pub;
2337 int ret = 0;
2338
2339 DHD_OS_WAKE_LOCK(dhdp);
2340 DHD_PERIM_LOCK(dhdp);
2341
2342 /* Set flag when early suspend was called */
2343 dhdp->in_suspend = val;
2344 if ((force || !dhdp->suspend_disable_flag) &&
2345 (dhd_support_sta_mode(dhdp) || dhd_conf_get_insuspend(dhdp, ALL_IN_SUSPEND)))
2346 {
2347 ret = dhd_set_suspend(val, dhdp);
2348 }
2349
2350 DHD_PERIM_UNLOCK(dhdp);
2351 DHD_OS_WAKE_UNLOCK(dhdp);
2352 return ret;
2353 }
2354
2355 #if defined(CONFIG_HAS_EARLYSUSPEND) && defined(DHD_USE_EARLYSUSPEND)
dhd_early_suspend(struct early_suspend * h)2356 static void dhd_early_suspend(struct early_suspend *h)
2357 {
2358 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
2359 DHD_TRACE_HW4(("%s: enter\n", __FUNCTION__));
2360
2361 if (dhd && dhd->pub.conf->suspend_mode == EARLY_SUSPEND) {
2362 dhd_suspend_resume_helper(dhd, 1, 0);
2363 dhd_conf_set_suspend_resume(&dhd->pub, 1);
2364 }
2365 }
2366
dhd_late_resume(struct early_suspend * h)2367 static void dhd_late_resume(struct early_suspend *h)
2368 {
2369 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
2370 DHD_TRACE_HW4(("%s: enter\n", __FUNCTION__));
2371
2372 if (dhd && dhd->pub.conf->suspend_mode == EARLY_SUSPEND) {
2373 dhd_conf_set_suspend_resume(&dhd->pub, 0);
2374 dhd_suspend_resume_helper(dhd, 0, 0);
2375 }
2376 }
2377 #endif /* CONFIG_HAS_EARLYSUSPEND && DHD_USE_EARLYSUSPEND */
2378
2379 /*
2380 * Generalized timeout mechanism. Uses spin sleep with exponential back-off until
2381 * the sleep time reaches one jiffy, then switches over to task delay. Usage:
2382 *
2383 * dhd_timeout_start(&tmo, usec);
2384 * while (!dhd_timeout_expired(&tmo))
2385 * if (poll_something())
2386 * break;
2387 * if (dhd_timeout_expired(&tmo))
2388 * fatal();
2389 */
2390
2391 void
dhd_timeout_start(dhd_timeout_t * tmo,uint usec)2392 dhd_timeout_start(dhd_timeout_t *tmo, uint usec)
2393 {
2394 tmo->limit = usec;
2395 tmo->increment = 0;
2396 tmo->elapsed = 0;
2397 tmo->tick = jiffies_to_usecs(1);
2398 }
2399
2400 int
dhd_timeout_expired(dhd_timeout_t * tmo)2401 dhd_timeout_expired(dhd_timeout_t *tmo)
2402 {
2403 /* Does nothing the first call */
2404 if (tmo->increment == 0) {
2405 tmo->increment = 1;
2406 return 0;
2407 }
2408
2409 if (tmo->elapsed >= tmo->limit)
2410 return 1;
2411
2412 /* Add the delay that's about to take place */
2413 tmo->elapsed += tmo->increment;
2414
2415 if ((!CAN_SLEEP()) || tmo->increment < tmo->tick) {
2416 OSL_DELAY(tmo->increment);
2417 tmo->increment *= 2;
2418 if (tmo->increment > tmo->tick)
2419 tmo->increment = tmo->tick;
2420 } else {
2421 /*
2422 * OSL_SLEEP() is corresponding to usleep_range(). In non-atomic
2423 * context where the exact wakeup time is flexible, it would be good
2424 * to use usleep_range() instead of udelay(). It takes a few advantages
2425 * such as improving responsiveness and reducing power.
2426 */
2427 OSL_SLEEP(jiffies_to_msecs(1));
2428 }
2429
2430 return 0;
2431 }
2432
2433 int
dhd_net2idx(dhd_info_t * dhd,struct net_device * net)2434 dhd_net2idx(dhd_info_t *dhd, struct net_device *net)
2435 {
2436 int i = 0;
2437
2438 if (!dhd) {
2439 DHD_ERROR(("%s : DHD_BAD_IF return\n", __FUNCTION__));
2440 return DHD_BAD_IF;
2441 }
2442
2443 while (i < DHD_MAX_IFS) {
2444 if (dhd->iflist[i] && dhd->iflist[i]->net && (dhd->iflist[i]->net == net))
2445 return i;
2446 i++;
2447 }
2448
2449 return DHD_BAD_IF;
2450 }
2451
dhd_idx2net(void * pub,int ifidx)2452 struct net_device * dhd_idx2net(void *pub, int ifidx)
2453 {
2454 struct dhd_pub *dhd_pub = (struct dhd_pub *)pub;
2455 struct dhd_info *dhd_info;
2456
2457 if (!dhd_pub || ifidx < 0 || ifidx >= DHD_MAX_IFS)
2458 return NULL;
2459 dhd_info = dhd_pub->info;
2460 if (dhd_info && dhd_info->iflist[ifidx])
2461 return dhd_info->iflist[ifidx]->net;
2462 return NULL;
2463 }
2464
2465 int
dhd_ifname2idx(dhd_info_t * dhd,char * name)2466 dhd_ifname2idx(dhd_info_t *dhd, char *name)
2467 {
2468 int i = DHD_MAX_IFS;
2469
2470 ASSERT(dhd);
2471
2472 if (name == NULL || *name == '\0')
2473 return 0;
2474
2475 while (--i > 0)
2476 if (dhd->iflist[i] && !strncmp(dhd->iflist[i]->dngl_name, name, IFNAMSIZ))
2477 break;
2478
2479 DHD_TRACE(("%s: return idx %d for \"%s\"\n", __FUNCTION__, i, name));
2480
2481 return i; /* default - the primary interface */
2482 }
2483
2484 char *
dhd_ifname(dhd_pub_t * dhdp,int ifidx)2485 dhd_ifname(dhd_pub_t *dhdp, int ifidx)
2486 {
2487 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
2488
2489 ASSERT(dhd);
2490
2491 if (ifidx < 0 || ifidx >= DHD_MAX_IFS) {
2492 DHD_ERROR(("%s: ifidx %d out of range\n", __FUNCTION__, ifidx));
2493 return "<if_bad>";
2494 }
2495
2496 if (dhd->iflist[ifidx] == NULL) {
2497 DHD_ERROR(("%s: null i/f %d\n", __FUNCTION__, ifidx));
2498 return "<if_null>";
2499 }
2500
2501 if (dhd->iflist[ifidx]->net)
2502 return dhd->iflist[ifidx]->net->name;
2503
2504 return "<if_none>";
2505 }
2506
2507 uint8 *
dhd_bssidx2bssid(dhd_pub_t * dhdp,int idx)2508 dhd_bssidx2bssid(dhd_pub_t *dhdp, int idx)
2509 {
2510 int i;
2511 dhd_info_t *dhd = (dhd_info_t *)dhdp;
2512
2513 ASSERT(dhd);
2514 for (i = 0; i < DHD_MAX_IFS; i++)
2515 if (dhd->iflist[i] && dhd->iflist[i]->bssidx == idx)
2516 return dhd->iflist[i]->mac_addr;
2517
2518 return NULL;
2519 }
2520
2521 static void
_dhd_set_multicast_list(dhd_info_t * dhd,int ifidx)2522 _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
2523 {
2524 struct net_device *dev;
2525 struct netdev_hw_addr *ha;
2526 uint32 allmulti, cnt;
2527
2528 wl_ioctl_t ioc;
2529 char *buf, *bufp;
2530 uint buflen;
2531 int ret;
2532
2533 #ifdef MCAST_LIST_ACCUMULATION
2534 int i;
2535 uint32 cnt_iface[DHD_MAX_IFS];
2536 cnt = 0;
2537 allmulti = 0;
2538
2539 for (i = 0; i < DHD_MAX_IFS; i++) {
2540 if (dhd->iflist[i]) {
2541 dev = dhd->iflist[i]->net;
2542 if (!dev)
2543 continue;
2544 netif_addr_lock_bh(dev);
2545 cnt_iface[i] = netdev_mc_count(dev);
2546 cnt += cnt_iface[i];
2547 netif_addr_unlock_bh(dev);
2548
2549 /* Determine initial value of allmulti flag */
2550 allmulti |= (dev->flags & IFF_ALLMULTI) ? TRUE : FALSE;
2551 }
2552 }
2553 #else /* !MCAST_LIST_ACCUMULATION */
2554 if (!dhd->iflist[ifidx]) {
2555 DHD_ERROR(("%s : dhd->iflist[%d] was NULL\n", __FUNCTION__, ifidx));
2556 return;
2557 }
2558 dev = dhd->iflist[ifidx]->net;
2559 if (!dev)
2560 return;
2561 netif_addr_lock_bh(dev);
2562 cnt = netdev_mc_count(dev);
2563 netif_addr_unlock_bh(dev);
2564
2565 /* Determine initial value of allmulti flag */
2566 allmulti = (dev->flags & IFF_ALLMULTI) ? TRUE : FALSE;
2567 #endif /* MCAST_LIST_ACCUMULATION */
2568
2569 #ifdef PASS_ALL_MCAST_PKTS
2570 #ifdef PKT_FILTER_SUPPORT
2571 if (!dhd->pub.early_suspended)
2572 #endif /* PKT_FILTER_SUPPORT */
2573 allmulti = TRUE;
2574 #endif /* PASS_ALL_MCAST_PKTS */
2575
2576 /* Send down the multicast list first. */
2577
2578 buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETHER_ADDR_LEN);
2579 if (!(bufp = buf = MALLOC(dhd->pub.osh, buflen))) {
2580 DHD_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
2581 dhd_ifname(&dhd->pub, ifidx), cnt));
2582 return;
2583 }
2584
2585 strncpy(bufp, "mcast_list", buflen - 1);
2586 bufp[buflen - 1] = '\0';
2587 bufp += strlen("mcast_list") + 1;
2588
2589 cnt = htol32(cnt);
2590 memcpy(bufp, &cnt, sizeof(cnt));
2591 bufp += sizeof(cnt);
2592
2593 #ifdef MCAST_LIST_ACCUMULATION
2594 for (i = 0; i < DHD_MAX_IFS; i++) {
2595 if (dhd->iflist[i]) {
2596 DHD_TRACE(("_dhd_set_multicast_list: ifidx %d\n", i));
2597 dev = dhd->iflist[i]->net;
2598
2599 netif_addr_lock_bh(dev);
2600 #if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
2601 #pragma GCC diagnostic push
2602 #pragma GCC diagnostic ignored "-Wcast-qual"
2603 #endif // endif
2604 netdev_for_each_mc_addr(ha, dev) {
2605 #if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
2606 #pragma GCC diagnostic pop
2607 #endif // endif
2608 if (!cnt_iface[i])
2609 break;
2610 memcpy(bufp, ha->addr, ETHER_ADDR_LEN);
2611 bufp += ETHER_ADDR_LEN;
2612 DHD_TRACE(("_dhd_set_multicast_list: cnt "
2613 "%d " MACDBG "\n",
2614 cnt_iface[i], MAC2STRDBG(ha->addr)));
2615 cnt_iface[i]--;
2616 }
2617 netif_addr_unlock_bh(dev);
2618 }
2619 }
2620 #else /* !MCAST_LIST_ACCUMULATION */
2621 netif_addr_lock_bh(dev);
2622 #if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
2623 #pragma GCC diagnostic push
2624 #pragma GCC diagnostic ignored "-Wcast-qual"
2625 #endif // endif
2626 netdev_for_each_mc_addr(ha, dev) {
2627 if (!cnt)
2628 break;
2629 memcpy(bufp, ha->addr, ETHER_ADDR_LEN);
2630 bufp += ETHER_ADDR_LEN;
2631 cnt--;
2632 }
2633 #if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
2634 #pragma GCC diagnostic pop
2635 #endif // endif
2636 netif_addr_unlock_bh(dev);
2637 #endif /* MCAST_LIST_ACCUMULATION */
2638
2639 memset(&ioc, 0, sizeof(ioc));
2640 ioc.cmd = WLC_SET_VAR;
2641 ioc.buf = buf;
2642 ioc.len = buflen;
2643 ioc.set = TRUE;
2644
2645 ret = dhd_wl_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
2646 if (ret < 0) {
2647 DHD_ERROR(("%s: set mcast_list failed, cnt %d\n",
2648 dhd_ifname(&dhd->pub, ifidx), cnt));
2649 allmulti = cnt ? TRUE : allmulti;
2650 }
2651
2652 MFREE(dhd->pub.osh, buf, buflen);
2653
2654 /* Now send the allmulti setting. This is based on the setting in the
2655 * net_device flags, but might be modified above to be turned on if we
2656 * were trying to set some addresses and dongle rejected it...
2657 */
2658
2659 allmulti = htol32(allmulti);
2660 ret = dhd_iovar(&dhd->pub, ifidx, "allmulti", (char *)&allmulti,
2661 sizeof(allmulti), NULL, 0, TRUE);
2662 if (ret < 0) {
2663 DHD_ERROR(("%s: set allmulti %d failed\n",
2664 dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
2665 }
2666
2667 /* Finally, pick up the PROMISC flag as well, like the NIC driver does */
2668
2669 #ifdef MCAST_LIST_ACCUMULATION
2670 allmulti = 0;
2671 for (i = 0; i < DHD_MAX_IFS; i++) {
2672 if (dhd->iflist[i]) {
2673 dev = dhd->iflist[i]->net;
2674 allmulti |= (dev->flags & IFF_PROMISC) ? TRUE : FALSE;
2675 }
2676 }
2677 #else
2678 allmulti = (dev->flags & IFF_PROMISC) ? TRUE : FALSE;
2679 #endif /* MCAST_LIST_ACCUMULATION */
2680
2681 allmulti = htol32(allmulti);
2682
2683 memset(&ioc, 0, sizeof(ioc));
2684 ioc.cmd = WLC_SET_PROMISC;
2685 ioc.buf = &allmulti;
2686 ioc.len = sizeof(allmulti);
2687 ioc.set = TRUE;
2688
2689 ret = dhd_wl_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
2690 if (ret < 0) {
2691 DHD_ERROR(("%s: set promisc %d failed\n",
2692 dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
2693 }
2694 }
2695
2696 int
_dhd_set_mac_address(dhd_info_t * dhd,int ifidx,uint8 * addr,bool skip_stop)2697 _dhd_set_mac_address(dhd_info_t *dhd, int ifidx, uint8 *addr, bool skip_stop)
2698 {
2699 int ret;
2700
2701 #ifdef DHD_NOTIFY_MAC_CHANGED
2702 if (skip_stop) {
2703 WL_MSG(dhd_ifname(&dhd->pub, ifidx), "close dev for mac changing\n");
2704 dhd->pub.skip_dhd_stop = TRUE;
2705 dev_close(dhd->iflist[ifidx]->net);
2706 }
2707 #endif /* DHD_NOTIFY_MAC_CHANGED */
2708
2709 ret = dhd_iovar(&dhd->pub, ifidx, "cur_etheraddr", (char *)addr,
2710 ETHER_ADDR_LEN, NULL, 0, TRUE);
2711 if (ret < 0) {
2712 DHD_ERROR(("%s: set cur_etheraddr %pM failed ret=%d\n",
2713 dhd_ifname(&dhd->pub, ifidx), addr, ret));
2714 goto exit;
2715 } else {
2716 memcpy(dhd->iflist[ifidx]->net->dev_addr, addr, ETHER_ADDR_LEN);
2717 if (ifidx == 0)
2718 memcpy(dhd->pub.mac.octet, addr, ETHER_ADDR_LEN);
2719 WL_MSG(dhd_ifname(&dhd->pub, ifidx), "MACID %pM is overwritten\n", addr);
2720 }
2721
2722 exit:
2723 #ifdef DHD_NOTIFY_MAC_CHANGED
2724 if (skip_stop) {
2725 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0))
2726 dev_open(dhd->iflist[ifidx]->net, NULL);
2727 #else
2728 dev_open(dhd->iflist[ifidx]->net);
2729 #endif
2730 dhd->pub.skip_dhd_stop = FALSE;
2731 WL_MSG(dhd_ifname(&dhd->pub, ifidx), "notify mac changed done\n");
2732 }
2733 #endif /* DHD_NOTIFY_MAC_CHANGED */
2734
2735 return ret;
2736 }
2737
2738 #ifdef DHD_PSTA
2739 /* Get psta/psr configuration configuration */
dhd_get_psta_mode(dhd_pub_t * dhdp)2740 int dhd_get_psta_mode(dhd_pub_t *dhdp)
2741 {
2742 dhd_info_t *dhd = dhdp->info;
2743 return (int)dhd->psta_mode;
2744 }
2745 /* Set psta/psr configuration configuration */
dhd_set_psta_mode(dhd_pub_t * dhdp,uint32 val)2746 int dhd_set_psta_mode(dhd_pub_t *dhdp, uint32 val)
2747 {
2748 dhd_info_t *dhd = dhdp->info;
2749 dhd->psta_mode = val;
2750 return 0;
2751 }
2752 #endif /* DHD_PSTA */
2753
2754 #if (defined(DHD_WET) || defined(DHD_MCAST_REGEN) || defined(DHD_L2_FILTER))
2755 static void
dhd_update_rx_pkt_chainable_state(dhd_pub_t * dhdp,uint32 idx)2756 dhd_update_rx_pkt_chainable_state(dhd_pub_t* dhdp, uint32 idx)
2757 {
2758 dhd_info_t *dhd = dhdp->info;
2759 dhd_if_t *ifp;
2760
2761 ASSERT(idx < DHD_MAX_IFS);
2762
2763 ifp = dhd->iflist[idx];
2764
2765 if (
2766 #ifdef DHD_L2_FILTER
2767 (ifp->block_ping) ||
2768 #endif // endif
2769 #ifdef DHD_WET
2770 (dhd->wet_mode) ||
2771 #endif // endif
2772 #ifdef DHD_MCAST_REGEN
2773 (ifp->mcast_regen_bss_enable) ||
2774 #endif // endif
2775 FALSE) {
2776 ifp->rx_pkt_chainable = FALSE;
2777 }
2778 }
2779 #endif /* DHD_WET || DHD_MCAST_REGEN || DHD_L2_FILTER */
2780
2781 #ifdef DHD_WET
2782 /* Get wet configuration configuration */
dhd_get_wet_mode(dhd_pub_t * dhdp)2783 int dhd_get_wet_mode(dhd_pub_t *dhdp)
2784 {
2785 dhd_info_t *dhd = dhdp->info;
2786 return (int)dhd->wet_mode;
2787 }
2788
2789 /* Set wet configuration configuration */
dhd_set_wet_mode(dhd_pub_t * dhdp,uint32 val)2790 int dhd_set_wet_mode(dhd_pub_t *dhdp, uint32 val)
2791 {
2792 dhd_info_t *dhd = dhdp->info;
2793 dhd->wet_mode = val;
2794 dhd_update_rx_pkt_chainable_state(dhdp, 0);
2795 return 0;
2796 }
2797 #endif /* DHD_WET */
2798
2799 #if defined(WL_CFG80211) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
dhd_role_to_nl80211_iftype(int32 role)2800 int32 dhd_role_to_nl80211_iftype(int32 role)
2801 {
2802 switch (role) {
2803 case WLC_E_IF_ROLE_STA:
2804 return NL80211_IFTYPE_STATION;
2805 case WLC_E_IF_ROLE_AP:
2806 return NL80211_IFTYPE_AP;
2807 case WLC_E_IF_ROLE_WDS:
2808 return NL80211_IFTYPE_WDS;
2809 case WLC_E_IF_ROLE_P2P_GO:
2810 return NL80211_IFTYPE_P2P_GO;
2811 case WLC_E_IF_ROLE_P2P_CLIENT:
2812 return NL80211_IFTYPE_P2P_CLIENT;
2813 case WLC_E_IF_ROLE_IBSS:
2814 case WLC_E_IF_ROLE_NAN:
2815 return NL80211_IFTYPE_ADHOC;
2816 default:
2817 return NL80211_IFTYPE_UNSPECIFIED;
2818 }
2819 }
2820 #endif /* WL_CFG80211 && LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0) */
2821
2822 static void
dhd_ifadd_event_handler(void * handle,void * event_info,u8 event)2823 dhd_ifadd_event_handler(void *handle, void *event_info, u8 event)
2824 {
2825 dhd_info_t *dhd = handle;
2826 dhd_if_event_t *if_event = event_info;
2827 int ifidx, bssidx;
2828 int ret;
2829 #if defined(WL_CFG80211) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
2830 struct wl_if_event_info info;
2831 #if defined(WLDWDS) && defined(FOURADDR_AUTO_BRG)
2832 struct net_device *ndev = NULL;
2833 #endif
2834 #else
2835 struct net_device *ndev;
2836 #endif /* WL_CFG80211 && LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0) */
2837
2838 BCM_REFERENCE(ret);
2839 if (event != DHD_WQ_WORK_IF_ADD) {
2840 DHD_ERROR(("%s: unexpected event \n", __FUNCTION__));
2841 return;
2842 }
2843
2844 if (!dhd) {
2845 DHD_ERROR(("%s: dhd info not available \n", __FUNCTION__));
2846 return;
2847 }
2848
2849 if (!if_event) {
2850 DHD_ERROR(("%s: event data is null \n", __FUNCTION__));
2851 return;
2852 }
2853
2854 dhd_net_if_lock_local(dhd);
2855 DHD_OS_WAKE_LOCK(&dhd->pub);
2856 DHD_PERIM_LOCK(&dhd->pub);
2857
2858 ifidx = if_event->event.ifidx;
2859 bssidx = if_event->event.bssidx;
2860 DHD_TRACE(("%s: registering if with ifidx %d\n", __FUNCTION__, ifidx));
2861
2862 #if defined(WL_CFG80211) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
2863 if (if_event->event.ifidx > 0) {
2864 u8 *mac_addr;
2865 bzero(&info, sizeof(info));
2866 info.ifidx = ifidx;
2867 info.bssidx = bssidx;
2868 info.role = if_event->event.role;
2869 strncpy(info.name, if_event->name, IFNAMSIZ);
2870 if (is_valid_ether_addr(if_event->mac)) {
2871 mac_addr = if_event->mac;
2872 } else {
2873 mac_addr = NULL;
2874 }
2875
2876 #if defined(WLDWDS) && defined(FOURADDR_AUTO_BRG)
2877 if ((ndev = wl_cfg80211_post_ifcreate(dhd->pub.info->iflist[0]->net,
2878 &info, mac_addr, NULL, true)) == NULL)
2879 #else
2880 if (wl_cfg80211_post_ifcreate(dhd->pub.info->iflist[0]->net,
2881 &info, mac_addr, NULL, true) == NULL)
2882 #endif
2883 {
2884 /* Do the post interface create ops */
2885 DHD_ERROR(("Post ifcreate ops failed. Returning \n"));
2886 goto done;
2887 }
2888 }
2889 #else
2890 /* This path is for non-android case */
2891 /* The interface name in host and in event msg are same */
2892 /* if name in event msg is used to create dongle if list on host */
2893 ndev = dhd_allocate_if(&dhd->pub, ifidx, if_event->name,
2894 if_event->mac, bssidx, TRUE, if_event->name);
2895 if (!ndev) {
2896 DHD_ERROR(("%s: net device alloc failed \n", __FUNCTION__));
2897 goto done;
2898 }
2899
2900 DHD_PERIM_UNLOCK(&dhd->pub);
2901 ret = dhd_register_if(&dhd->pub, ifidx, TRUE);
2902 DHD_PERIM_LOCK(&dhd->pub);
2903 if (ret != BCME_OK) {
2904 DHD_ERROR(("%s: dhd_register_if failed\n", __FUNCTION__));
2905 dhd_remove_if(&dhd->pub, ifidx, TRUE);
2906 goto done;
2907 }
2908 #endif /* WL_CFG80211 && LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0) */
2909
2910 #ifndef PCIE_FULL_DONGLE
2911 /* Turn on AP isolation in the firmware for interfaces operating in AP mode */
2912 if (FW_SUPPORTED((&dhd->pub), ap) && (if_event->event.role != WLC_E_IF_ROLE_STA)) {
2913 uint32 var_int = 1;
2914 ret = dhd_iovar(&dhd->pub, ifidx, "ap_isolate", (char *)&var_int, sizeof(var_int),
2915 NULL, 0, TRUE);
2916 if (ret != BCME_OK) {
2917 DHD_ERROR(("%s: Failed to set ap_isolate to dongle\n", __FUNCTION__));
2918 dhd_remove_if(&dhd->pub, ifidx, TRUE);
2919 }
2920 }
2921 #endif /* PCIE_FULL_DONGLE */
2922
2923 done:
2924 MFREE(dhd->pub.osh, if_event, sizeof(dhd_if_event_t));
2925 #if defined(WLDWDS) && defined(FOURADDR_AUTO_BRG)
2926 dhd_bridge_dev_set(dhd, ifidx, ndev);
2927 #endif /* defiend(WLDWDS) && defined(FOURADDR_AUTO_BRG) */
2928
2929 DHD_PERIM_UNLOCK(&dhd->pub);
2930 DHD_OS_WAKE_UNLOCK(&dhd->pub);
2931 dhd_net_if_unlock_local(dhd);
2932 }
2933
2934 static void
dhd_ifdel_event_handler(void * handle,void * event_info,u8 event)2935 dhd_ifdel_event_handler(void *handle, void *event_info, u8 event)
2936 {
2937 dhd_info_t *dhd = handle;
2938 int ifidx;
2939 dhd_if_event_t *if_event = event_info;
2940
2941 if (event != DHD_WQ_WORK_IF_DEL) {
2942 DHD_ERROR(("%s: unexpected event \n", __FUNCTION__));
2943 return;
2944 }
2945
2946 if (!dhd) {
2947 DHD_ERROR(("%s: dhd info not available \n", __FUNCTION__));
2948 return;
2949 }
2950
2951 if (!if_event) {
2952 DHD_ERROR(("%s: event data is null \n", __FUNCTION__));
2953 return;
2954 }
2955
2956 dhd_net_if_lock_local(dhd);
2957 DHD_OS_WAKE_LOCK(&dhd->pub);
2958 DHD_PERIM_LOCK(&dhd->pub);
2959
2960 ifidx = if_event->event.ifidx;
2961 DHD_TRACE(("Removing interface with idx %d\n", ifidx));
2962 #if defined(WLDWDS) && defined(FOURADDR_AUTO_BRG)
2963 dhd_bridge_dev_set(dhd, ifidx, NULL);
2964 #endif /* defiend(WLDWDS) && defined(FOURADDR_AUTO_BRG) */
2965
2966 DHD_PERIM_UNLOCK(&dhd->pub);
2967 if (!dhd->pub.info->iflist[ifidx]) {
2968 /* No matching netdev found */
2969 DHD_ERROR(("Netdev not found! Do nothing.\n"));
2970 goto done;
2971 }
2972 #if defined(WL_CFG80211) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
2973 if (if_event->event.ifidx > 0) {
2974 /* Do the post interface del ops */
2975 if (wl_cfg80211_post_ifdel(dhd->pub.info->iflist[ifidx]->net,
2976 true, if_event->event.ifidx) != 0) {
2977 DHD_TRACE(("Post ifdel ops failed. Returning \n"));
2978 goto done;
2979 }
2980 }
2981 #else
2982 /* For non-cfg80211 drivers */
2983 dhd_remove_if(&dhd->pub, ifidx, TRUE);
2984 #endif /* WL_CFG80211 && LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0) */
2985
2986 done:
2987 DHD_PERIM_LOCK(&dhd->pub);
2988 MFREE(dhd->pub.osh, if_event, sizeof(dhd_if_event_t));
2989 DHD_PERIM_UNLOCK(&dhd->pub);
2990 DHD_OS_WAKE_UNLOCK(&dhd->pub);
2991 dhd_net_if_unlock_local(dhd);
2992 }
2993
2994 #ifdef DHD_UPDATE_INTF_MAC
2995 static void
dhd_ifupdate_event_handler(void * handle,void * event_info,u8 event)2996 dhd_ifupdate_event_handler(void *handle, void *event_info, u8 event)
2997 {
2998 dhd_info_t *dhd = handle;
2999 int ifidx;
3000 dhd_if_event_t *if_event = event_info;
3001
3002 if (event != DHD_WQ_WORK_IF_UPDATE) {
3003 DHD_ERROR(("%s: unexpected event \n", __FUNCTION__));
3004 return;
3005 }
3006
3007 if (!dhd) {
3008 DHD_ERROR(("%s: dhd info not available \n", __FUNCTION__));
3009 return;
3010 }
3011
3012 if (!if_event) {
3013 DHD_ERROR(("%s: event data is null \n", __FUNCTION__));
3014 return;
3015 }
3016
3017 dhd_net_if_lock_local(dhd);
3018 DHD_OS_WAKE_LOCK(&dhd->pub);
3019
3020 ifidx = if_event->event.ifidx;
3021 DHD_TRACE(("%s: Update interface with idx %d\n", __FUNCTION__, ifidx));
3022
3023 dhd_op_if_update(&dhd->pub, ifidx);
3024
3025 MFREE(dhd->pub.osh, if_event, sizeof(dhd_if_event_t));
3026
3027 DHD_OS_WAKE_UNLOCK(&dhd->pub);
3028 dhd_net_if_unlock_local(dhd);
3029 }
3030
dhd_op_if_update(dhd_pub_t * dhdpub,int ifidx)3031 int dhd_op_if_update(dhd_pub_t *dhdpub, int ifidx)
3032 {
3033 dhd_info_t * dhdinfo = NULL;
3034 dhd_if_t * ifp = NULL;
3035 int ret = 0;
3036 char buf[128];
3037
3038 if ((NULL==dhdpub)||(NULL==dhdpub->info)) {
3039 DHD_ERROR(("%s: *** DHD handler is NULL!\n", __FUNCTION__));
3040 return -1;
3041 } else {
3042 dhdinfo = (dhd_info_t *)dhdpub->info;
3043 ifp = dhdinfo->iflist[ifidx];
3044 if (NULL==ifp) {
3045 DHD_ERROR(("%s: *** ifp handler is NULL!\n", __FUNCTION__));
3046 return -2;
3047 }
3048 }
3049
3050 DHD_TRACE(("%s: idx %d\n", __FUNCTION__, ifidx));
3051 // Get MAC address
3052 strcpy(buf, "cur_etheraddr");
3053 ret = dhd_wl_ioctl_cmd(&dhdinfo->pub, WLC_GET_VAR, buf, sizeof(buf), FALSE, ifp->idx);
3054 if (0>ret) {
3055 DHD_ERROR(("Failed to upudate the MAC address for itf=%s, ret=%d\n", ifp->name, ret));
3056 // avoid collision
3057 dhdinfo->iflist[ifp->idx]->mac_addr[5] += 1;
3058 // force locally administrate address
3059 ETHER_SET_LOCALADDR(&dhdinfo->iflist[ifp->idx]->mac_addr);
3060 } else {
3061 DHD_EVENT(("Got mac for itf %s, idx %d, MAC=%02X:%02X:%02X:%02X:%02X:%02X\n",
3062 ifp->name, ifp->idx,
3063 (unsigned char)buf[0], (unsigned char)buf[1], (unsigned char)buf[2],
3064 (unsigned char)buf[3], (unsigned char)buf[4], (unsigned char)buf[5]));
3065 memcpy(dhdinfo->iflist[ifp->idx]->mac_addr, buf, ETHER_ADDR_LEN);
3066 if (dhdinfo->iflist[ifp->idx]->net) {
3067 memcpy(dhdinfo->iflist[ifp->idx]->net->dev_addr, buf, ETHER_ADDR_LEN);
3068 }
3069 }
3070
3071 return ret;
3072 }
3073 #endif /* DHD_UPDATE_INTF_MAC */
3074
3075 static void
dhd_set_mac_addr_handler(void * handle,void * event_info,u8 event)3076 dhd_set_mac_addr_handler(void *handle, void *event_info, u8 event)
3077 {
3078 dhd_info_t *dhd = handle;
3079 dhd_if_t *ifp = event_info;
3080
3081 if (event != DHD_WQ_WORK_SET_MAC) {
3082 DHD_ERROR(("%s: unexpected event \n", __FUNCTION__));
3083 }
3084
3085 if (!dhd) {
3086 DHD_ERROR(("%s: dhd info not available \n", __FUNCTION__));
3087 return;
3088 }
3089
3090 dhd_net_if_lock_local(dhd);
3091 DHD_OS_WAKE_LOCK(&dhd->pub);
3092 DHD_PERIM_LOCK(&dhd->pub);
3093
3094 // terence 20160907: fix for not able to set mac when wlan0 is down
3095 if (ifp == NULL || !ifp->set_macaddress) {
3096 goto done;
3097 }
3098 if (ifp == NULL || !dhd->pub.up) {
3099 DHD_ERROR(("%s: interface info not available/down \n", __FUNCTION__));
3100 goto done;
3101 }
3102
3103 ifp->set_macaddress = FALSE;
3104
3105 #ifdef DHD_NOTIFY_MAC_CHANGED
3106 rtnl_lock();
3107 #endif /* DHD_NOTIFY_MAC_CHANGED */
3108
3109 if (_dhd_set_mac_address(dhd, ifp->idx, ifp->mac_addr, TRUE) == 0)
3110 DHD_INFO(("%s: MACID is overwritten\n", __FUNCTION__));
3111 else
3112 DHD_ERROR(("%s: _dhd_set_mac_address() failed\n", __FUNCTION__));
3113
3114 #ifdef DHD_NOTIFY_MAC_CHANGED
3115 rtnl_unlock();
3116 #endif /* DHD_NOTIFY_MAC_CHANGED */
3117
3118 done:
3119 DHD_PERIM_UNLOCK(&dhd->pub);
3120 DHD_OS_WAKE_UNLOCK(&dhd->pub);
3121 dhd_net_if_unlock_local(dhd);
3122 }
3123
3124 static void
dhd_set_mcast_list_handler(void * handle,void * event_info,u8 event)3125 dhd_set_mcast_list_handler(void *handle, void *event_info, u8 event)
3126 {
3127 dhd_info_t *dhd = handle;
3128 int ifidx = (int)((long int)event_info);
3129 dhd_if_t *ifp = NULL;
3130
3131 if (event != DHD_WQ_WORK_SET_MCAST_LIST) {
3132 DHD_ERROR(("%s: unexpected event \n", __FUNCTION__));
3133 return;
3134 }
3135
3136 if (!dhd) {
3137 DHD_ERROR(("%s: dhd info not available \n", __FUNCTION__));
3138 return;
3139 }
3140
3141 dhd_net_if_lock_local(dhd);
3142 DHD_OS_WAKE_LOCK(&dhd->pub);
3143 DHD_PERIM_LOCK(&dhd->pub);
3144
3145 ifp = dhd->iflist[ifidx];
3146
3147 if (ifp == NULL || !dhd->pub.up) {
3148 DHD_ERROR(("%s: interface info not available/down \n", __FUNCTION__));
3149 goto done;
3150 }
3151
3152 if (ifp == NULL || !dhd->pub.up) {
3153 DHD_ERROR(("%s: interface info not available/down \n", __FUNCTION__));
3154 goto done;
3155 }
3156
3157 ifidx = ifp->idx;
3158
3159 #ifdef MCAST_LIST_ACCUMULATION
3160 ifidx = 0;
3161 #endif /* MCAST_LIST_ACCUMULATION */
3162
3163 _dhd_set_multicast_list(dhd, ifidx);
3164 DHD_INFO(("%s: set multicast list for if %d\n", __FUNCTION__, ifidx));
3165
3166 done:
3167 DHD_PERIM_UNLOCK(&dhd->pub);
3168 DHD_OS_WAKE_UNLOCK(&dhd->pub);
3169 dhd_net_if_unlock_local(dhd);
3170 }
3171
3172 static int
dhd_set_mac_address(struct net_device * dev,void * addr)3173 dhd_set_mac_address(struct net_device *dev, void *addr)
3174 {
3175 int ret = 0;
3176
3177 dhd_info_t *dhd = DHD_DEV_INFO(dev);
3178 struct sockaddr *sa = (struct sockaddr *)addr;
3179 int ifidx;
3180 dhd_if_t *dhdif;
3181
3182 ifidx = dhd_net2idx(dhd, dev);
3183 if (ifidx == DHD_BAD_IF)
3184 return -1;
3185
3186 dhdif = dhd->iflist[ifidx];
3187
3188 dhd_net_if_lock_local(dhd);
3189 memcpy(dhdif->mac_addr, sa->sa_data, ETHER_ADDR_LEN);
3190 dhdif->set_macaddress = TRUE;
3191 dhd_net_if_unlock_local(dhd);
3192 WL_MSG(dev->name, "iftype = %d macaddr = %pM\n",
3193 dev->ieee80211_ptr->iftype, dhdif->mac_addr);
3194 dhd_deferred_schedule_work(dhd->dhd_deferred_wq, (void *)dhdif, DHD_WQ_WORK_SET_MAC,
3195 dhd_set_mac_addr_handler, DHD_WQ_WORK_PRIORITY_LOW);
3196 return ret;
3197 }
3198
3199 static void
dhd_set_multicast_list(struct net_device * dev)3200 dhd_set_multicast_list(struct net_device *dev)
3201 {
3202 dhd_info_t *dhd = DHD_DEV_INFO(dev);
3203 int ifidx;
3204
3205 ifidx = dhd_net2idx(dhd, dev);
3206 if (ifidx == DHD_BAD_IF)
3207 return;
3208
3209 dhd->iflist[ifidx]->set_multicast = TRUE;
3210 dhd_deferred_schedule_work(dhd->dhd_deferred_wq, (void *)((long int)ifidx),
3211 DHD_WQ_WORK_SET_MCAST_LIST, dhd_set_mcast_list_handler, DHD_WQ_WORK_PRIORITY_LOW);
3212
3213 // terence 20160907: fix for not able to set mac when wlan0 is down
3214 dhd_deferred_schedule_work(dhd->dhd_deferred_wq, (void *)dhd->iflist[ifidx],
3215 DHD_WQ_WORK_SET_MAC, dhd_set_mac_addr_handler, DHD_WQ_WORK_PRIORITY_LOW);
3216 }
3217
3218 #ifdef DHD_UCODE_DOWNLOAD
3219 /* Get ucode path */
3220 char *
dhd_get_ucode_path(dhd_pub_t * dhdp)3221 dhd_get_ucode_path(dhd_pub_t *dhdp)
3222 {
3223 dhd_info_t *dhd = dhdp->info;
3224 return dhd->uc_path;
3225 }
3226 #endif /* DHD_UCODE_DOWNLOAD */
3227
3228 #ifdef PROP_TXSTATUS
3229 int
dhd_os_wlfc_block(dhd_pub_t * pub)3230 dhd_os_wlfc_block(dhd_pub_t *pub)
3231 {
3232 dhd_info_t *di = (dhd_info_t *)(pub->info);
3233 ASSERT(di != NULL);
3234 /* terence 20161229: don't do spin lock if proptx not enabled */
3235 if (disable_proptx)
3236 return 1;
3237 #ifdef BCMDBUS
3238 spin_lock_irqsave(&di->wlfc_spinlock, di->wlfc_lock_flags);
3239 #else
3240 spin_lock_bh(&di->wlfc_spinlock);
3241 #endif /* BCMDBUS */
3242 return 1;
3243 }
3244
3245 int
dhd_os_wlfc_unblock(dhd_pub_t * pub)3246 dhd_os_wlfc_unblock(dhd_pub_t *pub)
3247 {
3248 dhd_info_t *di = (dhd_info_t *)(pub->info);
3249
3250 ASSERT(di != NULL);
3251 /* terence 20161229: don't do spin lock if proptx not enabled */
3252 if (disable_proptx)
3253 return 1;
3254 #ifdef BCMDBUS
3255 spin_unlock_irqrestore(&di->wlfc_spinlock, di->wlfc_lock_flags);
3256 #else
3257 spin_unlock_bh(&di->wlfc_spinlock);
3258 #endif /* BCMDBUS */
3259 return 1;
3260 }
3261
3262 #endif /* PROP_TXSTATUS */
3263
3264 #if defined(WL_MONITOR) && defined(BCMSDIO)
3265 static void
3266 dhd_rx_mon_pkt_sdio(dhd_pub_t *dhdp, void *pkt, int ifidx);
3267 bool
3268 dhd_monitor_enabled(dhd_pub_t *dhd, int ifidx);
3269 #endif /* WL_MONITOR && BCMSDIO */
3270
3271 /* This routine do not support Packet chain feature, Currently tested for
3272 * proxy arp feature
3273 */
dhd_sendup(dhd_pub_t * dhdp,int ifidx,void * p)3274 int dhd_sendup(dhd_pub_t *dhdp, int ifidx, void *p)
3275 {
3276 struct sk_buff *skb;
3277 void *skbhead = NULL;
3278 void *skbprev = NULL;
3279 dhd_if_t *ifp;
3280 ASSERT(!PKTISCHAINED(p));
3281 skb = PKTTONATIVE(dhdp->osh, p);
3282
3283 ifp = dhdp->info->iflist[ifidx];
3284 skb->dev = ifp->net;
3285
3286 skb->protocol = eth_type_trans(skb, skb->dev);
3287
3288 if (in_interrupt()) {
3289 bcm_object_trace_opr(skb, BCM_OBJDBG_REMOVE,
3290 __FUNCTION__, __LINE__);
3291 netif_rx(skb);
3292 } else {
3293 if (dhdp->info->rxthread_enabled) {
3294 if (!skbhead) {
3295 skbhead = skb;
3296 } else {
3297 PKTSETNEXT(dhdp->osh, skbprev, skb);
3298 }
3299 skbprev = skb;
3300 } else {
3301 /* If the receive is not processed inside an ISR,
3302 * the softirqd must be woken explicitly to service
3303 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
3304 * by netif_rx_ni(), but in earlier kernels, we need
3305 * to do it manually.
3306 */
3307 bcm_object_trace_opr(skb, BCM_OBJDBG_REMOVE,
3308 __FUNCTION__, __LINE__);
3309 #if defined(WL_MONITOR) && defined(BCMSDIO)
3310 if (dhd_monitor_enabled(dhdp, ifidx))
3311 dhd_rx_mon_pkt_sdio(dhdp, skb, ifidx);
3312 else
3313 #endif /* WL_MONITOR && BCMSDIO */
3314 netif_rx_ni(skb);
3315 }
3316 }
3317
3318 if (dhdp->info->rxthread_enabled && skbhead)
3319 dhd_sched_rxf(dhdp, skbhead);
3320
3321 return BCME_OK;
3322 }
3323
3324 int BCMFASTPATH
__dhd_sendpkt(dhd_pub_t * dhdp,int ifidx,void * pktbuf)3325 __dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pktbuf)
3326 {
3327 int ret = BCME_OK;
3328 dhd_info_t *dhd = (dhd_info_t *)(dhdp->info);
3329 struct ether_header *eh = NULL;
3330 bool pkt_ether_type_802_1x = FALSE;
3331 uint8 pkt_flow_prio;
3332
3333 #if defined(DHD_L2_FILTER)
3334 dhd_if_t *ifp = dhd_get_ifp(dhdp, ifidx);
3335 #endif // endif
3336
3337 /* Reject if down */
3338 if (!dhdp->up || (dhdp->busstate == DHD_BUS_DOWN)) {
3339 /* free the packet here since the caller won't */
3340 PKTCFREE(dhdp->osh, pktbuf, TRUE);
3341 return -ENODEV;
3342 }
3343
3344 #ifdef PCIE_FULL_DONGLE
3345 if (dhdp->busstate == DHD_BUS_SUSPEND) {
3346 DHD_ERROR(("%s : pcie is still in suspend state!!\n", __FUNCTION__));
3347 PKTCFREE(dhdp->osh, pktbuf, TRUE);
3348 return NETDEV_TX_BUSY;
3349 }
3350 #endif /* PCIE_FULL_DONGLE */
3351
3352 /* Reject if pktlen > MAX_MTU_SZ */
3353 if (PKTLEN(dhdp->osh, pktbuf) > MAX_MTU_SZ) {
3354 /* free the packet here since the caller won't */
3355 dhdp->tx_big_packets++;
3356 PKTCFREE(dhdp->osh, pktbuf, TRUE);
3357 return BCME_ERROR;
3358 }
3359
3360 #ifdef DHD_L2_FILTER
3361 /* if dhcp_unicast is enabled, we need to convert the */
3362 /* broadcast DHCP ACK/REPLY packets to Unicast. */
3363 if (ifp->dhcp_unicast) {
3364 uint8* mac_addr;
3365 uint8* ehptr = NULL;
3366 int ret;
3367 ret = bcm_l2_filter_get_mac_addr_dhcp_pkt(dhdp->osh, pktbuf, ifidx, &mac_addr);
3368 if (ret == BCME_OK) {
3369 /* if given mac address having valid entry in sta list
3370 * copy the given mac address, and return with BCME_OK
3371 */
3372 if (dhd_find_sta(dhdp, ifidx, mac_addr)) {
3373 ehptr = PKTDATA(dhdp->osh, pktbuf);
3374 bcopy(mac_addr, ehptr + ETHER_DEST_OFFSET, ETHER_ADDR_LEN);
3375 }
3376 }
3377 }
3378
3379 if (ifp->grat_arp && DHD_IF_ROLE_AP(dhdp, ifidx)) {
3380 if (bcm_l2_filter_gratuitous_arp(dhdp->osh, pktbuf) == BCME_OK) {
3381 PKTCFREE(dhdp->osh, pktbuf, TRUE);
3382 return BCME_ERROR;
3383 }
3384 }
3385
3386 if (ifp->parp_enable && DHD_IF_ROLE_AP(dhdp, ifidx)) {
3387 ret = dhd_l2_filter_pkt_handle(dhdp, ifidx, pktbuf, TRUE);
3388
3389 /* Drop the packets if l2 filter has processed it already
3390 * otherwise continue with the normal path
3391 */
3392 if (ret == BCME_OK) {
3393 PKTCFREE(dhdp->osh, pktbuf, TRUE);
3394 return BCME_ERROR;
3395 }
3396 }
3397 #endif /* DHD_L2_FILTER */
3398 /* Update multicast statistic */
3399 if (PKTLEN(dhdp->osh, pktbuf) >= ETHER_HDR_LEN) {
3400 uint8 *pktdata = (uint8 *)PKTDATA(dhdp->osh, pktbuf);
3401 eh = (struct ether_header *)pktdata;
3402
3403 if (ETHER_ISMULTI(eh->ether_dhost))
3404 dhdp->tx_multicast++;
3405 if (ntoh16(eh->ether_type) == ETHER_TYPE_802_1X) {
3406 #ifdef DHD_LOSSLESS_ROAMING
3407 uint8 prio = (uint8)PKTPRIO(pktbuf);
3408
3409 /* back up 802.1x's priority */
3410 dhdp->prio_8021x = prio;
3411 #endif /* DHD_LOSSLESS_ROAMING */
3412 pkt_ether_type_802_1x = TRUE;
3413 DBG_EVENT_LOG(dhdp, WIFI_EVENT_DRIVER_EAPOL_FRAME_TRANSMIT_REQUESTED);
3414 atomic_inc(&dhd->pend_8021x_cnt);
3415 #if defined(WL_CFG80211) && defined(WL_WPS_SYNC)
3416 wl_handle_wps_states(dhd_idx2net(dhdp, ifidx),
3417 pktdata, PKTLEN(dhdp->osh, pktbuf), TRUE);
3418 #endif /* WL_CFG80211 && WL_WPS_SYNC */
3419 }
3420 dhd_dump_pkt(dhdp, ifidx, pktdata,
3421 (uint32)PKTLEN(dhdp->osh, pktbuf), TRUE, NULL, NULL);
3422 } else {
3423 PKTCFREE(dhdp->osh, pktbuf, TRUE);
3424 return BCME_ERROR;
3425 }
3426
3427 {
3428 /* Look into the packet and update the packet priority */
3429 #ifndef PKTPRIO_OVERRIDE
3430 if (PKTPRIO(pktbuf) == 0)
3431 #endif /* !PKTPRIO_OVERRIDE */
3432 {
3433 #if defined(QOS_MAP_SET)
3434 pktsetprio_qms(pktbuf, wl_get_up_table(dhdp, ifidx), FALSE);
3435 #else
3436 pktsetprio(pktbuf, FALSE);
3437 #endif /* QOS_MAP_SET */
3438 }
3439 #ifndef PKTPRIO_OVERRIDE
3440 else {
3441 /* Some protocols like OZMO use priority values from 256..263.
3442 * these are magic values to indicate a specific 802.1d priority.
3443 * make sure that priority field is in range of 0..7
3444 */
3445 PKTSETPRIO(pktbuf, PKTPRIO(pktbuf) & 0x7);
3446 }
3447 #endif /* !PKTPRIO_OVERRIDE */
3448 }
3449
3450 BCM_REFERENCE(pkt_ether_type_802_1x);
3451 BCM_REFERENCE(pkt_flow_prio);
3452
3453 #ifdef SUPPORT_SET_TID
3454 dhd_set_tid_based_on_uid(dhdp, pktbuf);
3455 #endif /* SUPPORT_SET_TID */
3456
3457 #ifdef PCIE_FULL_DONGLE
3458 /*
3459 * Lkup the per interface hash table, for a matching flowring. If one is not
3460 * available, allocate a unique flowid and add a flowring entry.
3461 * The found or newly created flowid is placed into the pktbuf's tag.
3462 */
3463
3464 #ifdef DHD_LOSSLESS_ROAMING
3465 /* For LLR override and use flowring with prio 7 for 802.1x packets */
3466 if (pkt_ether_type_802_1x) {
3467 pkt_flow_prio = PRIO_8021D_NC;
3468 } else
3469 #endif /* DHD_LOSSLESS_ROAMING */
3470 {
3471 pkt_flow_prio = dhdp->flow_prio_map[(PKTPRIO(pktbuf))];
3472 }
3473
3474 ret = dhd_flowid_update(dhdp, ifidx, pkt_flow_prio, pktbuf);
3475 if (ret != BCME_OK) {
3476 PKTCFREE(dhd->pub.osh, pktbuf, TRUE);
3477 return ret;
3478 }
3479 #endif /* PCIE_FULL_DONGLE */
3480 /* terence 20150901: Micky add to ajust the 802.1X priority */
3481 /* Set the 802.1X packet with the highest priority 7 */
3482 if (dhdp->conf->pktprio8021x >= 0)
3483 pktset8021xprio(pktbuf, dhdp->conf->pktprio8021x);
3484
3485 #ifdef PROP_TXSTATUS
3486 if (dhd_wlfc_is_supported(dhdp)) {
3487 /* store the interface ID */
3488 DHD_PKTTAG_SETIF(PKTTAG(pktbuf), ifidx);
3489
3490 /* store destination MAC in the tag as well */
3491 DHD_PKTTAG_SETDSTN(PKTTAG(pktbuf), eh->ether_dhost);
3492
3493 /* decide which FIFO this packet belongs to */
3494 if (ETHER_ISMULTI(eh->ether_dhost))
3495 /* one additional queue index (highest AC + 1) is used for bc/mc queue */
3496 DHD_PKTTAG_SETFIFO(PKTTAG(pktbuf), AC_COUNT);
3497 else
3498 DHD_PKTTAG_SETFIFO(PKTTAG(pktbuf), WME_PRIO2AC(PKTPRIO(pktbuf)));
3499 } else
3500 #endif /* PROP_TXSTATUS */
3501 {
3502 /* If the protocol uses a data header, apply it */
3503 dhd_prot_hdrpush(dhdp, ifidx, pktbuf);
3504 }
3505
3506 /* Use bus module to send data frame */
3507 #ifdef PROP_TXSTATUS
3508 {
3509 if (dhd_wlfc_commit_packets(dhdp, (f_commitpkt_t)dhd_bus_txdata,
3510 dhdp->bus, pktbuf, TRUE) == WLFC_UNSUPPORTED) {
3511 /* non-proptxstatus way */
3512 #ifdef BCMPCIE
3513 ret = dhd_bus_txdata(dhdp->bus, pktbuf, (uint8)ifidx);
3514 #else
3515 ret = dhd_bus_txdata(dhdp->bus, pktbuf);
3516 #endif /* BCMPCIE */
3517 }
3518 }
3519 #else
3520 #ifdef BCMPCIE
3521 ret = dhd_bus_txdata(dhdp->bus, pktbuf, (uint8)ifidx);
3522 #else
3523 ret = dhd_bus_txdata(dhdp->bus, pktbuf);
3524 #endif /* BCMPCIE */
3525 #endif /* PROP_TXSTATUS */
3526 #ifdef BCMDBUS
3527 if (ret)
3528 PKTCFREE(dhdp->osh, pktbuf, TRUE);
3529 #endif /* BCMDBUS */
3530
3531 return ret;
3532 }
3533
3534 int BCMFASTPATH
dhd_sendpkt(dhd_pub_t * dhdp,int ifidx,void * pktbuf)3535 dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pktbuf)
3536 {
3537 int ret = 0;
3538 unsigned long flags;
3539 dhd_if_t *ifp;
3540
3541 DHD_GENERAL_LOCK(dhdp, flags);
3542 ifp = dhd_get_ifp(dhdp, ifidx);
3543 if (!ifp || ifp->del_in_progress) {
3544 DHD_ERROR(("%s: ifp:%p del_in_progress:%d\n",
3545 __FUNCTION__, ifp, ifp ? ifp->del_in_progress : 0));
3546 DHD_GENERAL_UNLOCK(dhdp, flags);
3547 PKTCFREE(dhdp->osh, pktbuf, TRUE);
3548 return -ENODEV;
3549 }
3550 if (DHD_BUS_CHECK_DOWN_OR_DOWN_IN_PROGRESS(dhdp)) {
3551 DHD_ERROR(("%s: returning as busstate=%d\n",
3552 __FUNCTION__, dhdp->busstate));
3553 DHD_GENERAL_UNLOCK(dhdp, flags);
3554 PKTCFREE(dhdp->osh, pktbuf, TRUE);
3555 return -ENODEV;
3556 }
3557 DHD_IF_SET_TX_ACTIVE(ifp, DHD_TX_SEND_PKT);
3558 DHD_BUS_BUSY_SET_IN_SEND_PKT(dhdp);
3559 DHD_GENERAL_UNLOCK(dhdp, flags);
3560
3561 DHD_GENERAL_LOCK(dhdp, flags);
3562 if (DHD_BUS_CHECK_SUSPEND_OR_SUSPEND_IN_PROGRESS(dhdp)) {
3563 DHD_ERROR(("%s: bus is in suspend(%d) or suspending(0x%x) state!!\n",
3564 __FUNCTION__, dhdp->busstate, dhdp->dhd_bus_busy_state));
3565 DHD_BUS_BUSY_CLEAR_IN_SEND_PKT(dhdp);
3566 DHD_IF_CLR_TX_ACTIVE(ifp, DHD_TX_SEND_PKT);
3567 dhd_os_tx_completion_wake(dhdp);
3568 dhd_os_busbusy_wake(dhdp);
3569 DHD_GENERAL_UNLOCK(dhdp, flags);
3570 PKTCFREE(dhdp->osh, pktbuf, TRUE);
3571 return -ENODEV;
3572 }
3573 DHD_GENERAL_UNLOCK(dhdp, flags);
3574
3575 ret = __dhd_sendpkt(dhdp, ifidx, pktbuf);
3576
3577 DHD_GENERAL_LOCK(dhdp, flags);
3578 DHD_BUS_BUSY_CLEAR_IN_SEND_PKT(dhdp);
3579 DHD_IF_CLR_TX_ACTIVE(ifp, DHD_TX_SEND_PKT);
3580 dhd_os_tx_completion_wake(dhdp);
3581 dhd_os_busbusy_wake(dhdp);
3582 DHD_GENERAL_UNLOCK(dhdp, flags);
3583 return ret;
3584 }
3585
3586 netdev_tx_t BCMFASTPATH
dhd_start_xmit(struct sk_buff * skb,struct net_device * net)3587 dhd_start_xmit(struct sk_buff *skb, struct net_device *net)
3588 {
3589 int ret;
3590 uint datalen;
3591 void *pktbuf;
3592 dhd_info_t *dhd = DHD_DEV_INFO(net);
3593 dhd_if_t *ifp = NULL;
3594 int ifidx;
3595 unsigned long flags;
3596 uint8 htsfdlystat_sz = 0;
3597
3598 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
3599
3600 if (dhd_query_bus_erros(&dhd->pub)) {
3601 return -ENODEV;
3602 }
3603
3604 DHD_GENERAL_LOCK(&dhd->pub, flags);
3605 DHD_BUS_BUSY_SET_IN_TX(&dhd->pub);
3606 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
3607
3608 DHD_GENERAL_LOCK(&dhd->pub, flags);
3609 #ifdef BCMPCIE
3610 if (DHD_BUS_CHECK_SUSPEND_OR_SUSPEND_IN_PROGRESS(&dhd->pub)) {
3611 DHD_ERROR(("%s: bus is in suspend(%d) or suspending(0x%x) state!!\n",
3612 __FUNCTION__, dhd->pub.busstate, dhd->pub.dhd_bus_busy_state));
3613 DHD_BUS_BUSY_CLEAR_IN_TX(&dhd->pub);
3614 #ifdef PCIE_FULL_DONGLE
3615 /* Stop tx queues if suspend is in progress */
3616 if (DHD_BUS_CHECK_ANY_SUSPEND_IN_PROGRESS(&dhd->pub)) {
3617 dhd_bus_stop_queue(dhd->pub.bus);
3618 }
3619 #endif /* PCIE_FULL_DONGLE */
3620 dhd_os_busbusy_wake(&dhd->pub);
3621 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
3622 return NETDEV_TX_BUSY;
3623 }
3624 #else
3625 if (DHD_BUS_CHECK_SUSPEND_OR_SUSPEND_IN_PROGRESS(&dhd->pub)) {
3626 DHD_ERROR(("%s: bus is in suspend(%d) or suspending(0x%x) state!!\n",
3627 __FUNCTION__, dhd->pub.busstate, dhd->pub.dhd_bus_busy_state));
3628 }
3629 #endif
3630
3631 DHD_OS_WAKE_LOCK(&dhd->pub);
3632 DHD_PERIM_LOCK_TRY(DHD_FWDER_UNIT(dhd), lock_taken);
3633
3634 /* Reject if down */
3635 if (dhd->pub.hang_was_sent || DHD_BUS_CHECK_DOWN_OR_DOWN_IN_PROGRESS(&dhd->pub)) {
3636 DHD_ERROR(("%s: xmit rejected pub.up=%d busstate=%d \n",
3637 __FUNCTION__, dhd->pub.up, dhd->pub.busstate));
3638 netif_stop_queue(net);
3639 /* Send Event when bus down detected during data session */
3640 if (dhd->pub.up && !dhd->pub.hang_was_sent && !DHD_BUS_CHECK_REMOVE(&dhd->pub)) {
3641 DHD_ERROR(("%s: Event HANG sent up\n", __FUNCTION__));
3642 dhd->pub.hang_reason = HANG_REASON_BUS_DOWN;
3643 net_os_send_hang_message(net);
3644 }
3645 DHD_BUS_BUSY_CLEAR_IN_TX(&dhd->pub);
3646 dhd_os_busbusy_wake(&dhd->pub);
3647 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
3648 DHD_PERIM_UNLOCK_TRY(DHD_FWDER_UNIT(dhd), lock_taken);
3649 DHD_OS_WAKE_UNLOCK(&dhd->pub);
3650 return NETDEV_TX_BUSY;
3651 }
3652
3653 ifp = DHD_DEV_IFP(net);
3654 ifidx = DHD_DEV_IFIDX(net);
3655 if (!ifp || (ifidx == DHD_BAD_IF) ||
3656 ifp->del_in_progress) {
3657 DHD_ERROR(("%s: ifidx %d ifp:%p del_in_progress:%d\n",
3658 __FUNCTION__, ifidx, ifp, (ifp ? ifp->del_in_progress : 0)));
3659 netif_stop_queue(net);
3660 DHD_BUS_BUSY_CLEAR_IN_TX(&dhd->pub);
3661 dhd_os_busbusy_wake(&dhd->pub);
3662 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
3663 DHD_PERIM_UNLOCK_TRY(DHD_FWDER_UNIT(dhd), lock_taken);
3664 DHD_OS_WAKE_UNLOCK(&dhd->pub);
3665 return NETDEV_TX_BUSY;
3666 }
3667
3668 DHD_IF_SET_TX_ACTIVE(ifp, DHD_TX_START_XMIT);
3669 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
3670
3671 ASSERT(ifidx == dhd_net2idx(dhd, net));
3672 ASSERT((ifp != NULL) && ((ifidx < DHD_MAX_IFS) && (ifp == dhd->iflist[ifidx])));
3673
3674 bcm_object_trace_opr(skb, BCM_OBJDBG_ADD_PKT, __FUNCTION__, __LINE__);
3675
3676 /* re-align socket buffer if "skb->data" is odd address */
3677 if (((unsigned long)(skb->data)) & 0x1) {
3678 unsigned char *data = skb->data;
3679 uint32 length = skb->len;
3680 PKTPUSH(dhd->pub.osh, skb, 1);
3681 memmove(skb->data, data, length);
3682 PKTSETLEN(dhd->pub.osh, skb, length);
3683 }
3684
3685 datalen = PKTLEN(dhd->pub.osh, skb);
3686
3687 #ifdef HOST_TPUT_TEST
3688 dhd_os_sdlock_txq(&dhd->pub);
3689 dhd->pub.conf->net_len += datalen;
3690 dhd_os_sdunlock_txq(&dhd->pub);
3691 if ((dhd->pub.conf->data_drop_mode == XMIT_DROP) &&
3692 (PKTLEN(dhd->pub.osh, skb) > 500)) {
3693 dev_kfree_skb(skb);
3694 return NETDEV_TX_OK;
3695 }
3696 #endif
3697 /* Make sure there's enough room for any header */
3698 if (skb_headroom(skb) < dhd->pub.hdrlen + htsfdlystat_sz) {
3699 struct sk_buff *skb2;
3700
3701 DHD_INFO(("%s: insufficient headroom\n",
3702 dhd_ifname(&dhd->pub, ifidx)));
3703 dhd->pub.tx_realloc++;
3704
3705 bcm_object_trace_opr(skb, BCM_OBJDBG_REMOVE, __FUNCTION__, __LINE__);
3706 skb2 = skb_realloc_headroom(skb, dhd->pub.hdrlen + htsfdlystat_sz);
3707
3708 dev_kfree_skb(skb);
3709 if ((skb = skb2) == NULL) {
3710 DHD_ERROR(("%s: skb_realloc_headroom failed\n",
3711 dhd_ifname(&dhd->pub, ifidx)));
3712 ret = -ENOMEM;
3713 goto done;
3714 }
3715 bcm_object_trace_opr(skb, BCM_OBJDBG_ADD_PKT, __FUNCTION__, __LINE__);
3716 }
3717
3718 /* move from dhdsdio_sendfromq(), try to orphan skb early */
3719 if (dhd->pub.conf->orphan_move == 2)
3720 PKTORPHAN(skb, dhd->pub.conf->tsq);
3721 else if (dhd->pub.conf->orphan_move == 3)
3722 skb_orphan(skb);
3723
3724 /* Convert to packet */
3725 if (!(pktbuf = PKTFRMNATIVE(dhd->pub.osh, skb))) {
3726 DHD_ERROR(("%s: PKTFRMNATIVE failed\n",
3727 dhd_ifname(&dhd->pub, ifidx)));
3728 bcm_object_trace_opr(skb, BCM_OBJDBG_REMOVE, __FUNCTION__, __LINE__);
3729 dev_kfree_skb_any(skb);
3730 ret = -ENOMEM;
3731 goto done;
3732 }
3733
3734 #ifdef DHD_WET
3735 /* wet related packet proto manipulation should be done in DHD
3736 since dongle doesn't have complete payload
3737 */
3738 if (WET_ENABLED(&dhd->pub) &&
3739 (dhd_wet_send_proc(dhd->pub.wet_info, pktbuf, &pktbuf) < 0)) {
3740 DHD_INFO(("%s:%s: wet send proc failed\n",
3741 __FUNCTION__, dhd_ifname(&dhd->pub, ifidx)));
3742 PKTFREE(dhd->pub.osh, pktbuf, FALSE);
3743 ret = -EFAULT;
3744 goto done;
3745 }
3746 #endif /* DHD_WET */
3747
3748 #ifdef DHD_PSTA
3749 /* PSR related packet proto manipulation should be done in DHD
3750 * since dongle doesn't have complete payload
3751 */
3752 if (PSR_ENABLED(&dhd->pub) &&
3753 (dhd_psta_proc(&dhd->pub, ifidx, &pktbuf, TRUE) < 0)) {
3754
3755 DHD_ERROR(("%s:%s: psta send proc failed\n", __FUNCTION__,
3756 dhd_ifname(&dhd->pub, ifidx)));
3757 }
3758 #endif /* DHD_PSTA */
3759
3760 #ifdef DHDTCPSYNC_FLOOD_BLK
3761 if (dhd_tcpdata_get_flag(&dhd->pub, pktbuf) == FLAG_SYNCACK) {
3762 ifp->tsyncack_txed ++;
3763 }
3764 #endif /* DHDTCPSYNC_FLOOD_BLK */
3765
3766 #ifdef DHDTCPACK_SUPPRESS
3767 if (dhd->pub.tcpack_sup_mode == TCPACK_SUP_HOLD) {
3768 /* If this packet has been hold or got freed, just return */
3769 if (dhd_tcpack_hold(&dhd->pub, pktbuf, ifidx)) {
3770 ret = 0;
3771 goto done;
3772 }
3773 } else {
3774 /* If this packet has replaced another packet and got freed, just return */
3775 if (dhd_tcpack_suppress(&dhd->pub, pktbuf)) {
3776 ret = 0;
3777 goto done;
3778 }
3779 }
3780 #endif /* DHDTCPACK_SUPPRESS */
3781
3782 /*
3783 * If Load Balance is enabled queue the packet
3784 * else send directly from here.
3785 */
3786 #if defined(DHD_LB_TXP)
3787 ret = dhd_lb_sendpkt(dhd, net, ifidx, pktbuf);
3788 #else
3789 ret = __dhd_sendpkt(&dhd->pub, ifidx, pktbuf);
3790 #endif // endif
3791
3792 done:
3793 if (ret) {
3794 ifp->stats.tx_dropped++;
3795 dhd->pub.tx_dropped++;
3796 } else {
3797 #ifdef PROP_TXSTATUS
3798 /* tx_packets counter can counted only when wlfc is disabled */
3799 if (!dhd_wlfc_is_supported(&dhd->pub))
3800 #endif // endif
3801 {
3802 dhd->pub.tx_packets++;
3803 ifp->stats.tx_packets++;
3804 ifp->stats.tx_bytes += datalen;
3805 }
3806 }
3807
3808 DHD_GENERAL_LOCK(&dhd->pub, flags);
3809 DHD_BUS_BUSY_CLEAR_IN_TX(&dhd->pub);
3810 DHD_IF_CLR_TX_ACTIVE(ifp, DHD_TX_START_XMIT);
3811 dhd_os_tx_completion_wake(&dhd->pub);
3812 dhd_os_busbusy_wake(&dhd->pub);
3813 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
3814 DHD_PERIM_UNLOCK_TRY(DHD_FWDER_UNIT(dhd), lock_taken);
3815 DHD_OS_WAKE_UNLOCK(&dhd->pub);
3816 /* Return ok: we always eat the packet */
3817 return NETDEV_TX_OK;
3818 }
3819
3820 #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
dhd_rx_wq_wakeup(struct work_struct * ptr)3821 void dhd_rx_wq_wakeup(struct work_struct *ptr)
3822 {
3823 struct dhd_rx_tx_work *work;
3824 struct dhd_pub * pub;
3825
3826 work = container_of(ptr, struct dhd_rx_tx_work, work);
3827
3828 pub = work->pub;
3829
3830 DHD_RPM(("%s: ENTER. \n", __FUNCTION__));
3831
3832 if (atomic_read(&pub->block_bus) || pub->busstate == DHD_BUS_DOWN) {
3833 return;
3834 }
3835
3836 DHD_OS_WAKE_LOCK(pub);
3837 if (pm_runtime_get_sync(dhd_bus_to_dev(pub->bus)) >= 0) {
3838
3839 // do nothing but wakeup the bus.
3840 pm_runtime_mark_last_busy(dhd_bus_to_dev(pub->bus));
3841 pm_runtime_put_autosuspend(dhd_bus_to_dev(pub->bus));
3842 }
3843 DHD_OS_WAKE_UNLOCK(pub);
3844 kfree(work);
3845 }
3846
dhd_start_xmit_wq_adapter(struct work_struct * ptr)3847 void dhd_start_xmit_wq_adapter(struct work_struct *ptr)
3848 {
3849 struct dhd_rx_tx_work *work;
3850 int ret;
3851 dhd_info_t *dhd;
3852 struct dhd_bus * bus;
3853
3854 work = container_of(ptr, struct dhd_rx_tx_work, work);
3855
3856 dhd = DHD_DEV_INFO(work->net);
3857
3858 bus = dhd->pub.bus;
3859
3860 if (atomic_read(&dhd->pub.block_bus)) {
3861 kfree_skb(work->skb);
3862 kfree(work);
3863 dhd_netif_start_queue(bus);
3864 return;
3865 }
3866
3867 if (pm_runtime_get_sync(dhd_bus_to_dev(bus)) >= 0) {
3868 ret = dhd_start_xmit(work->skb, work->net);
3869 pm_runtime_mark_last_busy(dhd_bus_to_dev(bus));
3870 pm_runtime_put_autosuspend(dhd_bus_to_dev(bus));
3871 }
3872 kfree(work);
3873 dhd_netif_start_queue(bus);
3874
3875 if (ret)
3876 netdev_err(work->net,
3877 "error: dhd_start_xmit():%d\n", ret);
3878 }
3879
3880 netdev_tx_t BCMFASTPATH
dhd_start_xmit_wrapper(struct sk_buff * skb,struct net_device * net)3881 dhd_start_xmit_wrapper(struct sk_buff *skb, struct net_device *net)
3882 {
3883 struct dhd_rx_tx_work *start_xmit_work;
3884 int ret;
3885 dhd_info_t *dhd = DHD_DEV_INFO(net);
3886
3887 if (dhd->pub.busstate == DHD_BUS_SUSPEND) {
3888 DHD_RPM(("%s: wakeup the bus using workqueue.\n", __FUNCTION__));
3889
3890 dhd_netif_stop_queue(dhd->pub.bus);
3891
3892 start_xmit_work = (struct dhd_rx_tx_work*)
3893 kmalloc(sizeof(*start_xmit_work), GFP_ATOMIC);
3894
3895 if (!start_xmit_work) {
3896 netdev_err(net,
3897 "error: failed to alloc start_xmit_work\n");
3898 ret = -ENOMEM;
3899 goto exit;
3900 }
3901
3902 INIT_WORK(&start_xmit_work->work, dhd_start_xmit_wq_adapter);
3903 start_xmit_work->skb = skb;
3904 start_xmit_work->net = net;
3905 queue_work(dhd->tx_wq, &start_xmit_work->work);
3906 ret = NET_XMIT_SUCCESS;
3907
3908 } else if (dhd->pub.busstate == DHD_BUS_DATA) {
3909 ret = dhd_start_xmit(skb, net);
3910 } else {
3911 /* when bus is down */
3912 ret = -ENODEV;
3913 }
3914
3915 exit:
3916 return ret;
3917 }
3918 void
dhd_bus_wakeup_work(dhd_pub_t * dhdp)3919 dhd_bus_wakeup_work(dhd_pub_t *dhdp)
3920 {
3921 struct dhd_rx_tx_work *rx_work;
3922 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
3923
3924 rx_work = kmalloc(sizeof(*rx_work), GFP_ATOMIC);
3925 if (!rx_work) {
3926 DHD_ERROR(("%s: start_rx_work alloc error. \n", __FUNCTION__));
3927 return;
3928 }
3929
3930 INIT_WORK(&rx_work->work, dhd_rx_wq_wakeup);
3931 rx_work->pub = dhdp;
3932 queue_work(dhd->rx_wq, &rx_work->work);
3933
3934 }
3935 #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
3936
3937 static void
__dhd_txflowcontrol(dhd_pub_t * dhdp,struct net_device * net,bool state)3938 __dhd_txflowcontrol(dhd_pub_t *dhdp, struct net_device *net, bool state)
3939 {
3940
3941 if ((state == ON) && (dhdp->txoff == FALSE)) {
3942 netif_stop_queue(net);
3943 dhd_prot_update_pktid_txq_stop_cnt(dhdp);
3944 } else if (state == ON) {
3945 DHD_INFO(("%s: Netif Queue has already stopped\n", __FUNCTION__));
3946 }
3947 if ((state == OFF) && (dhdp->txoff == TRUE)) {
3948 netif_wake_queue(net);
3949 dhd_prot_update_pktid_txq_start_cnt(dhdp);
3950 } else if (state == OFF) {
3951 DHD_INFO(("%s: Netif Queue has already started\n", __FUNCTION__));
3952 }
3953 }
3954
3955 void
dhd_txflowcontrol(dhd_pub_t * dhdp,int ifidx,bool state)3956 dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool state)
3957 {
3958 struct net_device *net;
3959 dhd_info_t *dhd = dhdp->info;
3960 int i;
3961
3962 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
3963
3964 ASSERT(dhd);
3965
3966 #ifdef DHD_LOSSLESS_ROAMING
3967 /* block flowcontrol during roaming */
3968 if ((dhdp->dequeue_prec_map == 1 << PRIO_8021D_NC) && state == ON) {
3969 return;
3970 }
3971 #endif // endif
3972
3973 if (ifidx == ALL_INTERFACES) {
3974 for (i = 0; i < DHD_MAX_IFS; i++) {
3975 if (dhd->iflist[i]) {
3976 net = dhd->iflist[i]->net;
3977 __dhd_txflowcontrol(dhdp, net, state);
3978 }
3979 }
3980 } else {
3981 if (dhd->iflist[ifidx]) {
3982 net = dhd->iflist[ifidx]->net;
3983 __dhd_txflowcontrol(dhdp, net, state);
3984 }
3985 }
3986 dhdp->txoff = state;
3987 }
3988
3989 #ifdef DHD_MCAST_REGEN
3990 /*
3991 * Description: This function is called to do the reverse translation
3992 *
3993 * Input eh - pointer to the ethernet header
3994 */
3995 int32
dhd_mcast_reverse_translation(struct ether_header * eh)3996 dhd_mcast_reverse_translation(struct ether_header *eh)
3997 {
3998 uint8 *iph;
3999 uint32 dest_ip;
4000
4001 iph = (uint8 *)eh + ETHER_HDR_LEN;
4002 dest_ip = ntoh32(*((uint32 *)(iph + IPV4_DEST_IP_OFFSET)));
4003
4004 /* Only IP packets are handled */
4005 if (eh->ether_type != hton16(ETHER_TYPE_IP))
4006 return BCME_ERROR;
4007
4008 /* Non-IPv4 multicast packets are not handled */
4009 if (IP_VER(iph) != IP_VER_4)
4010 return BCME_ERROR;
4011
4012 /*
4013 * The packet has a multicast IP and unicast MAC. That means
4014 * we have to do the reverse translation
4015 */
4016 if (IPV4_ISMULTI(dest_ip) && !ETHER_ISMULTI(&eh->ether_dhost)) {
4017 ETHER_FILL_MCAST_ADDR_FROM_IP(eh->ether_dhost, dest_ip);
4018 return BCME_OK;
4019 }
4020
4021 return BCME_ERROR;
4022 }
4023 #endif /* MCAST_REGEN */
4024
4025 #ifdef SHOW_LOGTRACE
4026 static void
dhd_netif_rx_ni(struct sk_buff * skb)4027 dhd_netif_rx_ni(struct sk_buff * skb)
4028 {
4029 /* Do not call netif_recieve_skb as this workqueue scheduler is
4030 * not from NAPI Also as we are not in INTR context, do not call
4031 * netif_rx, instead call netif_rx_ni (for kerenl >= 2.6) which
4032 * does netif_rx, disables irq, raise NET_IF_RX softirq and
4033 * enables interrupts back
4034 */
4035 netif_rx_ni(skb);
4036 }
4037
4038 static int
dhd_event_logtrace_pkt_process(dhd_pub_t * dhdp,struct sk_buff * skb)4039 dhd_event_logtrace_pkt_process(dhd_pub_t *dhdp, struct sk_buff * skb)
4040 {
4041 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
4042 int ret = BCME_OK;
4043 uint datalen;
4044 bcm_event_msg_u_t evu;
4045 void *data = NULL;
4046 void *pktdata = NULL;
4047 bcm_event_t *pvt_data;
4048 uint pktlen;
4049
4050 DHD_TRACE(("%s:Enter\n", __FUNCTION__));
4051
4052 /* In dhd_rx_frame, header is stripped using skb_pull
4053 * of size ETH_HLEN, so adjust pktlen accordingly
4054 */
4055 pktlen = skb->len + ETH_HLEN;
4056
4057 pktdata = (void *)skb_mac_header(skb);
4058 ret = wl_host_event_get_data(pktdata, pktlen, &evu);
4059
4060 if (ret != BCME_OK) {
4061 DHD_ERROR(("%s: wl_host_event_get_data err = %d\n",
4062 __FUNCTION__, ret));
4063 goto exit;
4064 }
4065
4066 datalen = ntoh32(evu.event.datalen);
4067
4068 pvt_data = (bcm_event_t *)pktdata;
4069 data = &pvt_data[1];
4070
4071 dhd_dbg_trace_evnt_handler(dhdp, data, &dhd->event_data, datalen);
4072
4073 exit:
4074 return ret;
4075 }
4076
4077 /*
4078 * dhd_event_logtrace_process_items processes
4079 * each skb from evt_trace_queue.
4080 * Returns TRUE if more packets to be processed
4081 * else returns FALSE
4082 */
4083
4084 static int
dhd_event_logtrace_process_items(dhd_info_t * dhd)4085 dhd_event_logtrace_process_items(dhd_info_t *dhd)
4086 {
4087 dhd_pub_t *dhdp;
4088 struct sk_buff *skb;
4089 uint32 qlen;
4090 uint32 process_len;
4091
4092 if (!dhd) {
4093 DHD_ERROR(("%s: dhd info not available \n", __FUNCTION__));
4094 return 0;
4095 }
4096
4097 dhdp = &dhd->pub;
4098
4099 if (!dhdp) {
4100 DHD_ERROR(("%s: dhd pub is null \n", __FUNCTION__));
4101 return 0;
4102 }
4103
4104 qlen = skb_queue_len(&dhd->evt_trace_queue);
4105 process_len = MIN(qlen, DHD_EVENT_LOGTRACE_BOUND);
4106
4107 /* Run while loop till bound is reached or skb queue is empty */
4108 while (process_len--) {
4109 int ifid = 0;
4110 skb = skb_dequeue(&dhd->evt_trace_queue);
4111 if (skb == NULL) {
4112 DHD_ERROR(("%s: skb is NULL, which is not valid case\n",
4113 __FUNCTION__));
4114 break;
4115 }
4116 BCM_REFERENCE(ifid);
4117 #ifdef PCIE_FULL_DONGLE
4118 /* Check if pkt is from INFO ring or WLC_E_TRACE */
4119 ifid = DHD_PKTTAG_IFID((dhd_pkttag_fr_t *)PKTTAG(skb));
4120 if (ifid == DHD_DUMMY_INFO_IF) {
4121 /* Process logtrace from info rings */
4122 dhd_event_logtrace_infobuf_pkt_process(dhdp, skb, &dhd->event_data);
4123 } else
4124 #endif /* PCIE_FULL_DONGLE */
4125 {
4126 /* Processing WLC_E_TRACE case OR non PCIE PCIE_FULL_DONGLE case */
4127 dhd_event_logtrace_pkt_process(dhdp, skb);
4128 }
4129
4130 /* Dummy sleep so that scheduler kicks in after processing any logprints */
4131 OSL_SLEEP(0);
4132
4133 /* Send packet up if logtrace_pkt_sendup is TRUE */
4134 if (dhdp->logtrace_pkt_sendup) {
4135 #ifdef DHD_USE_STATIC_CTRLBUF
4136 /* If bufs are allocated via static buf pool
4137 * and logtrace_pkt_sendup enabled, make a copy,
4138 * free the local one and send the copy up.
4139 */
4140 void *npkt = PKTDUP(dhdp->osh, skb);
4141 /* Clone event and send it up */
4142 PKTFREE_STATIC(dhdp->osh, skb, FALSE);
4143 if (npkt) {
4144 skb = npkt;
4145 } else {
4146 DHD_ERROR(("skb clone failed. dropping logtrace pkt.\n"));
4147 /* Packet is already freed, go to next packet */
4148 continue;
4149 }
4150 #endif /* DHD_USE_STATIC_CTRLBUF */
4151 #ifdef PCIE_FULL_DONGLE
4152 /* For infobuf packets as if is DHD_DUMMY_INFO_IF,
4153 * to send skb to network layer, assign skb->dev with
4154 * Primary interface n/w device
4155 */
4156 if (ifid == DHD_DUMMY_INFO_IF) {
4157 skb = PKTTONATIVE(dhdp->osh, skb);
4158 skb->dev = dhd->iflist[0]->net;
4159 }
4160 #endif /* PCIE_FULL_DONGLE */
4161 /* Send pkt UP */
4162 dhd_netif_rx_ni(skb);
4163 } else {
4164 /* Don't send up. Free up the packet. */
4165 #ifdef DHD_USE_STATIC_CTRLBUF
4166 PKTFREE_STATIC(dhdp->osh, skb, FALSE);
4167 #else
4168 PKTFREE(dhdp->osh, skb, FALSE);
4169 #endif /* DHD_USE_STATIC_CTRLBUF */
4170 }
4171 }
4172
4173 /* Reschedule if more packets to be processed */
4174 return (qlen >= DHD_EVENT_LOGTRACE_BOUND);
4175 }
4176
4177 #ifdef DHD_USE_KTHREAD_FOR_LOGTRACE
4178 static int
dhd_logtrace_thread(void * data)4179 dhd_logtrace_thread(void *data)
4180 {
4181 tsk_ctl_t *tsk = (tsk_ctl_t *)data;
4182 dhd_info_t *dhd = (dhd_info_t *)tsk->parent;
4183 dhd_pub_t *dhdp = (dhd_pub_t *)&dhd->pub;
4184 int ret;
4185
4186 while (1) {
4187 dhdp->logtrace_thr_ts.entry_time = OSL_LOCALTIME_NS();
4188 if (!binary_sema_down(tsk)) {
4189 dhdp->logtrace_thr_ts.sem_down_time = OSL_LOCALTIME_NS();
4190 SMP_RD_BARRIER_DEPENDS();
4191 if (dhd->pub.dongle_reset == FALSE) {
4192 do {
4193 /* Check terminated before processing the items */
4194 if (tsk->terminated) {
4195 DHD_ERROR(("%s: task terminated\n", __FUNCTION__));
4196 goto exit;
4197 }
4198 #ifdef EWP_EDL
4199 /* check if EDL is being used */
4200 if (dhd->pub.dongle_edl_support) {
4201 ret = dhd_prot_process_edl_complete(&dhd->pub,
4202 &dhd->event_data);
4203 } else {
4204 ret = dhd_event_logtrace_process_items(dhd);
4205 }
4206 #else
4207 ret = dhd_event_logtrace_process_items(dhd);
4208 #endif /* EWP_EDL */
4209 /* if ret > 0, bound has reached so to be fair to other
4210 * processes need to yield the scheduler.
4211 * The comment above yield()'s definition says:
4212 * If you want to use yield() to wait for something,
4213 * use wait_event().
4214 * If you want to use yield() to be 'nice' for others,
4215 * use cond_resched().
4216 * If you still want to use yield(), do not!
4217 */
4218 if (ret > 0) {
4219 cond_resched();
4220 OSL_SLEEP(DHD_EVENT_LOGTRACE_RESCHEDULE_DELAY_MS);
4221 } else if (ret < 0) {
4222 DHD_ERROR(("%s: ERROR should not reach here\n",
4223 __FUNCTION__));
4224 }
4225 } while (ret > 0);
4226 }
4227 if (tsk->flush_ind) {
4228 DHD_ERROR(("%s: flushed\n", __FUNCTION__));
4229 dhdp->logtrace_thr_ts.flush_time = OSL_LOCALTIME_NS();
4230 tsk->flush_ind = 0;
4231 complete(&tsk->flushed);
4232 }
4233 } else {
4234 DHD_ERROR(("%s: unexpted break\n", __FUNCTION__));
4235 dhdp->logtrace_thr_ts.unexpected_break_time = OSL_LOCALTIME_NS();
4236 break;
4237 }
4238 }
4239 exit:
4240 complete_and_exit(&tsk->completed, 0);
4241 dhdp->logtrace_thr_ts.complete_time = OSL_LOCALTIME_NS();
4242 }
4243 #else
4244 static void
dhd_event_logtrace_process(struct work_struct * work)4245 dhd_event_logtrace_process(struct work_struct * work)
4246 {
4247 int ret = 0;
4248 /* Ignore compiler warnings due to -Werror=cast-qual */
4249 #if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
4250 #pragma GCC diagnostic push
4251 #pragma GCC diagnostic ignored "-Wcast-qual"
4252 #endif // endif
4253 struct delayed_work *dw = to_delayed_work(work);
4254 struct dhd_info *dhd =
4255 container_of(dw, struct dhd_info, event_log_dispatcher_work);
4256 #if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
4257 #pragma GCC diagnostic pop
4258 #endif // endif
4259 #ifdef EWP_EDL
4260 if (dhd->pub.dongle_edl_support) {
4261 ret = dhd_prot_process_edl_complete(&dhd->pub, &dhd->event_data);
4262 } else {
4263 ret = dhd_event_logtrace_process_items(dhd);
4264 }
4265 #else
4266 ret = dhd_event_logtrace_process_items(dhd);
4267 #endif /* EWP_EDL */
4268
4269 if (ret > 0) {
4270 schedule_delayed_work(&(dhd)->event_log_dispatcher_work,
4271 msecs_to_jiffies(DHD_EVENT_LOGTRACE_RESCHEDULE_DELAY_MS));
4272 }
4273
4274 return;
4275 }
4276 #endif /* DHD_USE_KTHREAD_FOR_LOGTRACE */
4277
4278 void
dhd_schedule_logtrace(void * dhd_info)4279 dhd_schedule_logtrace(void *dhd_info)
4280 {
4281 dhd_info_t *dhd = (dhd_info_t *)dhd_info;
4282
4283 #ifdef DHD_USE_KTHREAD_FOR_LOGTRACE
4284 if (dhd->thr_logtrace_ctl.thr_pid >= 0) {
4285 binary_sema_up(&dhd->thr_logtrace_ctl);
4286 } else {
4287 DHD_ERROR(("%s: thr_logtrace_ctl(%ld) not inited\n", __FUNCTION__,
4288 dhd->thr_logtrace_ctl.thr_pid));
4289 }
4290 #else
4291 schedule_delayed_work(&dhd->event_log_dispatcher_work, 0);
4292 #endif /* DHD_USE_KTHREAD_FOR_LOGTRACE */
4293 return;
4294 }
4295
4296 void
dhd_cancel_logtrace_process_sync(dhd_info_t * dhd)4297 dhd_cancel_logtrace_process_sync(dhd_info_t *dhd)
4298 {
4299 #ifdef DHD_USE_KTHREAD_FOR_LOGTRACE
4300 if (dhd->thr_logtrace_ctl.thr_pid >= 0) {
4301 PROC_STOP_USING_BINARY_SEMA(&dhd->thr_logtrace_ctl);
4302 } else {
4303 DHD_ERROR(("%s: thr_logtrace_ctl(%ld) not inited\n", __FUNCTION__,
4304 dhd->thr_logtrace_ctl.thr_pid));
4305 }
4306 #else
4307 cancel_delayed_work_sync(&dhd->event_log_dispatcher_work);
4308 #endif /* DHD_USE_KTHREAD_FOR_LOGTRACE */
4309 }
4310
4311 void
dhd_flush_logtrace_process(dhd_info_t * dhd)4312 dhd_flush_logtrace_process(dhd_info_t *dhd)
4313 {
4314 #ifdef DHD_USE_KTHREAD_FOR_LOGTRACE
4315 if (dhd->thr_logtrace_ctl.thr_pid >= 0) {
4316 PROC_FLUSH_USING_BINARY_SEMA(&dhd->thr_logtrace_ctl);
4317 } else {
4318 DHD_ERROR(("%s: thr_logtrace_ctl(%ld) not inited\n", __FUNCTION__,
4319 dhd->thr_logtrace_ctl.thr_pid));
4320 }
4321 #else
4322 flush_delayed_work(&dhd->event_log_dispatcher_work);
4323 #endif /* DHD_USE_KTHREAD_FOR_LOGTRACE */
4324 }
4325
4326 int
dhd_init_logtrace_process(dhd_info_t * dhd)4327 dhd_init_logtrace_process(dhd_info_t *dhd)
4328 {
4329 #ifdef DHD_USE_KTHREAD_FOR_LOGTRACE
4330 dhd->thr_logtrace_ctl.thr_pid = DHD_PID_KT_INVALID;
4331 PROC_START(dhd_logtrace_thread, dhd, &dhd->thr_logtrace_ctl, 0, "dhd_logtrace_thread");
4332 if (dhd->thr_logtrace_ctl.thr_pid < 0) {
4333 DHD_ERROR(("%s: init logtrace process failed\n", __FUNCTION__));
4334 return BCME_ERROR;
4335 } else {
4336 DHD_ERROR(("%s: thr_logtrace_ctl(%ld) succedded\n", __FUNCTION__,
4337 dhd->thr_logtrace_ctl.thr_pid));
4338 }
4339 #else
4340 INIT_DELAYED_WORK(&dhd->event_log_dispatcher_work, dhd_event_logtrace_process);
4341 #endif /* DHD_USE_KTHREAD_FOR_LOGTRACE */
4342 return BCME_OK;
4343 }
4344
4345 int
dhd_reinit_logtrace_process(dhd_info_t * dhd)4346 dhd_reinit_logtrace_process(dhd_info_t *dhd)
4347 {
4348 #ifdef DHD_USE_KTHREAD_FOR_LOGTRACE
4349 /* Re-init only if PROC_STOP from dhd_stop was called
4350 * which can be checked via thr_pid
4351 */
4352 if (dhd->thr_logtrace_ctl.thr_pid < 0) {
4353 PROC_START(dhd_logtrace_thread, dhd, &dhd->thr_logtrace_ctl,
4354 0, "dhd_logtrace_thread");
4355 if (dhd->thr_logtrace_ctl.thr_pid < 0) {
4356 DHD_ERROR(("%s: reinit logtrace process failed\n", __FUNCTION__));
4357 return BCME_ERROR;
4358 } else {
4359 DHD_ERROR(("%s: thr_logtrace_ctl(%ld) succedded\n", __FUNCTION__,
4360 dhd->thr_logtrace_ctl.thr_pid));
4361 }
4362 }
4363 #else
4364 /* No need to re-init for WQ as calcel_delayed_work_sync will
4365 * will not delete the WQ
4366 */
4367 #endif /* DHD_USE_KTHREAD_FOR_LOGTRACE */
4368 return BCME_OK;
4369 }
4370
4371 void
dhd_event_logtrace_enqueue(dhd_pub_t * dhdp,int ifidx,void * pktbuf)4372 dhd_event_logtrace_enqueue(dhd_pub_t *dhdp, int ifidx, void *pktbuf)
4373 {
4374 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
4375
4376 #ifdef PCIE_FULL_DONGLE
4377 /* Add ifidx in the PKTTAG */
4378 DHD_PKTTAG_SET_IFID((dhd_pkttag_fr_t *)PKTTAG(pktbuf), ifidx);
4379 #endif /* PCIE_FULL_DONGLE */
4380 skb_queue_tail(&dhd->evt_trace_queue, pktbuf);
4381
4382 dhd_schedule_logtrace(dhd);
4383 }
4384
4385 void
dhd_event_logtrace_flush_queue(dhd_pub_t * dhdp)4386 dhd_event_logtrace_flush_queue(dhd_pub_t *dhdp)
4387 {
4388 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
4389 struct sk_buff *skb;
4390
4391 while ((skb = skb_dequeue(&dhd->evt_trace_queue)) != NULL) {
4392 #ifdef DHD_USE_STATIC_CTRLBUF
4393 PKTFREE_STATIC(dhdp->osh, skb, FALSE);
4394 #else
4395 PKTFREE(dhdp->osh, skb, FALSE);
4396 #endif /* DHD_USE_STATIC_CTRLBUF */
4397 }
4398 }
4399
4400 void
dhd_sendup_info_buf(dhd_pub_t * dhdp,uint8 * msg)4401 dhd_sendup_info_buf(dhd_pub_t *dhdp, uint8 *msg)
4402 {
4403 struct sk_buff *skb = NULL;
4404 uint32 pktsize = 0;
4405 void *pkt = NULL;
4406 info_buf_payload_hdr_t *infobuf = NULL;
4407 dhd_info_t *dhd = dhdp->info;
4408 uint8 *pktdata = NULL;
4409
4410 if (!msg)
4411 return;
4412
4413 /* msg = |infobuf_ver(u32)|info_buf_payload_hdr_t|msgtrace_hdr_t|<var len data>| */
4414 infobuf = (info_buf_payload_hdr_t *)(msg + sizeof(uint32));
4415 pktsize = (uint32)(ltoh16(infobuf->length) + sizeof(info_buf_payload_hdr_t) +
4416 sizeof(uint32));
4417 pkt = PKTGET(dhdp->osh, pktsize, FALSE);
4418 if (!pkt) {
4419 DHD_ERROR(("%s: skb alloc failed ! not sending event log up.\n", __FUNCTION__));
4420 } else {
4421 PKTSETLEN(dhdp->osh, pkt, pktsize);
4422 pktdata = PKTDATA(dhdp->osh, pkt);
4423 memcpy(pktdata, msg, pktsize);
4424 /* For infobuf packets assign skb->dev with
4425 * Primary interface n/w device
4426 */
4427 skb = PKTTONATIVE(dhdp->osh, pkt);
4428 skb->dev = dhd->iflist[0]->net;
4429 /* Send pkt UP */
4430 dhd_netif_rx_ni(skb);
4431 }
4432 }
4433 #endif /* SHOW_LOGTRACE */
4434
4435 /** Called when a frame is received by the dongle on interface 'ifidx' */
4436 void
dhd_rx_frame(dhd_pub_t * dhdp,int ifidx,void * pktbuf,int numpkt,uint8 chan)4437 dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *pktbuf, int numpkt, uint8 chan)
4438 {
4439 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
4440 struct sk_buff *skb;
4441 uchar *eth;
4442 uint len;
4443 void *data, *pnext = NULL;
4444 int i;
4445 dhd_if_t *ifp;
4446 wl_event_msg_t event;
4447 int tout_rx = 0;
4448 int tout_ctrl = 0;
4449 void *skbhead = NULL;
4450 void *skbprev = NULL;
4451 uint16 protocol;
4452 unsigned char *dump_data;
4453 #ifdef DHD_MCAST_REGEN
4454 uint8 interface_role;
4455 if_flow_lkup_t *if_flow_lkup;
4456 unsigned long flags;
4457 #endif // endif
4458 #ifdef DHD_WAKE_STATUS
4459 int pkt_wake = 0;
4460 wake_counts_t *wcp = NULL;
4461 #endif /* DHD_WAKE_STATUS */
4462
4463 #ifdef CONFIG_AP6XXX_WIFI6_HDF
4464 struct NetDevice *netDevice = NULL;
4465 struct sk_buff *eap_skb = NULL;
4466 int ret = 0;
4467 #endif
4468 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
4469 BCM_REFERENCE(dump_data);
4470
4471 #ifdef DHD_TPUT_PATCH
4472 if (dhdp->conf->pktsetsum)
4473 PKTSETSUMGOOD(pktbuf, TRUE);
4474 #endif
4475
4476 for (i = 0; pktbuf && i < numpkt; i++, pktbuf = pnext) {
4477 struct ether_header *eh;
4478
4479 pnext = PKTNEXT(dhdp->osh, pktbuf);
4480 PKTSETNEXT(dhdp->osh, pktbuf, NULL);
4481
4482 /* info ring "debug" data, which is not a 802.3 frame, is sent/hacked with a
4483 * special ifidx of DHD_DUMMY_INFO_IF. This is just internal to dhd to get the data
4484 * from dhd_msgbuf.c:dhd_prot_infobuf_cmplt_process() to here (dhd_rx_frame).
4485 */
4486 if (ifidx == DHD_DUMMY_INFO_IF) {
4487 /* Event msg printing is called from dhd_rx_frame which is in Tasklet
4488 * context in case of PCIe FD, in case of other bus this will be from
4489 * DPC context. If we get bunch of events from Dongle then printing all
4490 * of them from Tasklet/DPC context that too in data path is costly.
4491 * Also in the new Dongle SW(4359, 4355 onwards) console prints too come as
4492 * events with type WLC_E_TRACE.
4493 * We'll print this console logs from the WorkQueue context by enqueing SKB
4494 * here and Dequeuing will be done in WorkQueue and will be freed only if
4495 * logtrace_pkt_sendup is TRUE
4496 */
4497 #ifdef SHOW_LOGTRACE
4498 dhd_event_logtrace_enqueue(dhdp, ifidx, pktbuf);
4499 #else /* !SHOW_LOGTRACE */
4500 /* If SHOW_LOGTRACE not defined and ifidx is DHD_DUMMY_INFO_IF,
4501 * free the PKT here itself
4502 */
4503 #ifdef DHD_USE_STATIC_CTRLBUF
4504 PKTFREE_STATIC(dhdp->osh, pktbuf, FALSE);
4505 #else
4506 PKTFREE(dhdp->osh, pktbuf, FALSE);
4507 #endif /* DHD_USE_STATIC_CTRLBUF */
4508 #endif /* SHOW_LOGTRACE */
4509 continue;
4510 }
4511 #ifdef DHD_WAKE_STATUS
4512 #ifdef BCMDBUS
4513 wcp = NULL;
4514 #else
4515 pkt_wake = dhd_bus_get_bus_wake(dhdp);
4516 wcp = dhd_bus_get_wakecount(dhdp);
4517 #endif /* BCMDBUS */
4518 if (wcp == NULL) {
4519 /* If wakeinfo count buffer is null do not update wake count values */
4520 pkt_wake = 0;
4521 }
4522 #endif /* DHD_WAKE_STATUS */
4523
4524 eh = (struct ether_header *)PKTDATA(dhdp->osh, pktbuf);
4525
4526 if (ifidx >= DHD_MAX_IFS) {
4527 DHD_ERROR(("%s: ifidx(%d) Out of bound. drop packet\n",
4528 __FUNCTION__, ifidx));
4529 if (ntoh16(eh->ether_type) == ETHER_TYPE_BRCM) {
4530 #ifdef DHD_USE_STATIC_CTRLBUF
4531 PKTFREE_STATIC(dhdp->osh, pktbuf, FALSE);
4532 #else
4533 PKTFREE(dhdp->osh, pktbuf, FALSE);
4534 #endif /* DHD_USE_STATIC_CTRLBUF */
4535 } else {
4536 PKTCFREE(dhdp->osh, pktbuf, FALSE);
4537 }
4538 continue;
4539 }
4540
4541 ifp = dhd->iflist[ifidx];
4542 if (ifp == NULL) {
4543 DHD_ERROR(("%s: ifp is NULL. drop packet\n",
4544 __FUNCTION__));
4545 if (ntoh16(eh->ether_type) == ETHER_TYPE_BRCM) {
4546 #ifdef DHD_USE_STATIC_CTRLBUF
4547 PKTFREE_STATIC(dhdp->osh, pktbuf, FALSE);
4548 #else
4549 PKTFREE(dhdp->osh, pktbuf, FALSE);
4550 #endif /* DHD_USE_STATIC_CTRLBUF */
4551 } else {
4552 PKTCFREE(dhdp->osh, pktbuf, FALSE);
4553 }
4554 continue;
4555 }
4556
4557 /* Dropping only data packets before registering net device to avoid kernel panic */
4558 #ifndef PROP_TXSTATUS_VSDB
4559 if ((!ifp->net || ifp->net->reg_state != NETREG_REGISTERED) &&
4560 (ntoh16(eh->ether_type) != ETHER_TYPE_BRCM))
4561 #else
4562 if ((!ifp->net || ifp->net->reg_state != NETREG_REGISTERED || !dhd->pub.up) &&
4563 (ntoh16(eh->ether_type) != ETHER_TYPE_BRCM))
4564 #endif /* PROP_TXSTATUS_VSDB */
4565 {
4566 DHD_ERROR(("%s: net device is NOT registered yet. drop packet\n",
4567 __FUNCTION__));
4568 PKTCFREE(dhdp->osh, pktbuf, FALSE);
4569 continue;
4570 }
4571
4572 #ifdef PROP_TXSTATUS
4573 if (dhd_wlfc_is_header_only_pkt(dhdp, pktbuf)) {
4574 /* WLFC may send header only packet when
4575 there is an urgent message but no packet to
4576 piggy-back on
4577 */
4578 PKTCFREE(dhdp->osh, pktbuf, FALSE);
4579 continue;
4580 }
4581 #endif // endif
4582 #ifdef DHD_L2_FILTER
4583 /* If block_ping is enabled drop the ping packet */
4584 if (ifp->block_ping) {
4585 if (bcm_l2_filter_block_ping(dhdp->osh, pktbuf) == BCME_OK) {
4586 PKTCFREE(dhdp->osh, pktbuf, FALSE);
4587 continue;
4588 }
4589 }
4590 if (ifp->grat_arp && DHD_IF_ROLE_STA(dhdp, ifidx)) {
4591 if (bcm_l2_filter_gratuitous_arp(dhdp->osh, pktbuf) == BCME_OK) {
4592 PKTCFREE(dhdp->osh, pktbuf, FALSE);
4593 continue;
4594 }
4595 }
4596 if (ifp->parp_enable && DHD_IF_ROLE_AP(dhdp, ifidx)) {
4597 int ret = dhd_l2_filter_pkt_handle(dhdp, ifidx, pktbuf, FALSE);
4598
4599 /* Drop the packets if l2 filter has processed it already
4600 * otherwise continue with the normal path
4601 */
4602 if (ret == BCME_OK) {
4603 PKTCFREE(dhdp->osh, pktbuf, TRUE);
4604 continue;
4605 }
4606 }
4607 if (ifp->block_tdls) {
4608 if (bcm_l2_filter_block_tdls(dhdp->osh, pktbuf) == BCME_OK) {
4609 PKTCFREE(dhdp->osh, pktbuf, FALSE);
4610 continue;
4611 }
4612 }
4613 #endif /* DHD_L2_FILTER */
4614
4615 #ifdef DHD_MCAST_REGEN
4616 DHD_FLOWID_LOCK(dhdp->flowid_lock, flags);
4617 if_flow_lkup = (if_flow_lkup_t *)dhdp->if_flow_lkup;
4618 ASSERT(if_flow_lkup);
4619
4620 interface_role = if_flow_lkup[ifidx].role;
4621 DHD_FLOWID_UNLOCK(dhdp->flowid_lock, flags);
4622
4623 if (ifp->mcast_regen_bss_enable && (interface_role != WLC_E_IF_ROLE_WDS) &&
4624 !DHD_IF_ROLE_AP(dhdp, ifidx) &&
4625 ETHER_ISUCAST(eh->ether_dhost)) {
4626 if (dhd_mcast_reverse_translation(eh) == BCME_OK) {
4627 #ifdef DHD_PSTA
4628 /* Change bsscfg to primary bsscfg for unicast-multicast packets */
4629 if ((dhd_get_psta_mode(dhdp) == DHD_MODE_PSTA) ||
4630 (dhd_get_psta_mode(dhdp) == DHD_MODE_PSR)) {
4631 if (ifidx != 0) {
4632 /* Let the primary in PSTA interface handle this
4633 * frame after unicast to Multicast conversion
4634 */
4635 ifp = dhd_get_ifp(dhdp, 0);
4636 ASSERT(ifp);
4637 }
4638 }
4639 }
4640 #endif /* PSTA */
4641 }
4642 #endif /* MCAST_REGEN */
4643
4644 #ifdef DHDTCPSYNC_FLOOD_BLK
4645 if (dhd_tcpdata_get_flag(dhdp, pktbuf) == FLAG_SYNC) {
4646 int delta_sec;
4647 int delta_sync;
4648 int sync_per_sec;
4649 u64 curr_time = DIV_U64_BY_U32(OSL_LOCALTIME_NS(), NSEC_PER_SEC);
4650 ifp->tsync_rcvd ++;
4651 delta_sync = ifp->tsync_rcvd - ifp->tsyncack_txed;
4652 delta_sec = curr_time - ifp->last_sync;
4653 if (delta_sec > 1) {
4654 sync_per_sec = delta_sync/delta_sec;
4655 if (sync_per_sec > TCP_SYNC_FLOOD_LIMIT) {
4656 schedule_work(&ifp->blk_tsfl_work);
4657 DHD_ERROR(("ifx %d TCP SYNC Flood attack suspected! "
4658 "sync recvied %d pkt/sec \n",
4659 ifidx, sync_per_sec));
4660 }
4661 dhd_reset_tcpsync_info_by_ifp(ifp);
4662 }
4663
4664 }
4665 #endif /* DHDTCPSYNC_FLOOD_BLK */
4666
4667 #ifdef DHDTCPACK_SUPPRESS
4668 dhd_tcpdata_info_get(dhdp, pktbuf);
4669 #endif // endif
4670 skb = PKTTONATIVE(dhdp->osh, pktbuf);
4671
4672 ASSERT(ifp);
4673 skb->dev = ifp->net;
4674 #ifdef DHD_WET
4675 /* wet related packet proto manipulation should be done in DHD
4676 * since dongle doesn't have complete payload
4677 */
4678 if (WET_ENABLED(&dhd->pub) && (dhd_wet_recv_proc(dhd->pub.wet_info,
4679 pktbuf) < 0)) {
4680 DHD_INFO(("%s:%s: wet recv proc failed\n",
4681 __FUNCTION__, dhd_ifname(dhdp, ifidx)));
4682 }
4683 #endif /* DHD_WET */
4684
4685 #ifdef DHD_PSTA
4686 if (PSR_ENABLED(dhdp) &&
4687 (dhd_psta_proc(dhdp, ifidx, &pktbuf, FALSE) < 0)) {
4688 DHD_ERROR(("%s:%s: psta recv proc failed\n", __FUNCTION__,
4689 dhd_ifname(dhdp, ifidx)));
4690 }
4691 #endif /* DHD_PSTA */
4692
4693 #ifdef PCIE_FULL_DONGLE
4694 if ((DHD_IF_ROLE_AP(dhdp, ifidx) || DHD_IF_ROLE_P2PGO(dhdp, ifidx)) &&
4695 (!ifp->ap_isolate)) {
4696 eh = (struct ether_header *)PKTDATA(dhdp->osh, pktbuf);
4697 if (ETHER_ISUCAST(eh->ether_dhost)) {
4698 if (dhd_find_sta(dhdp, ifidx, (void *)eh->ether_dhost)) {
4699 dhd_sendpkt(dhdp, ifidx, pktbuf);
4700 continue;
4701 }
4702 } else {
4703 void *npktbuf = NULL;
4704 if ((ntoh16(eh->ether_type) != ETHER_TYPE_IAPP_L2_UPDATE) &&
4705 (npktbuf = PKTDUP(dhdp->osh, pktbuf)) != NULL) {
4706 dhd_sendpkt(dhdp, ifidx, npktbuf);
4707 }
4708 }
4709 }
4710 #endif /* PCIE_FULL_DONGLE */
4711 #ifdef DHD_POST_EAPOL_M1_AFTER_ROAM_EVT
4712 if (IS_STA_IFACE(ndev_to_wdev(ifp->net)) &&
4713 (ifp->recv_reassoc_evt == TRUE) && (ifp->post_roam_evt == FALSE) &&
4714 (dhd_is_4way_msg((char *)(skb->data)) == EAPOL_4WAY_M1)) {
4715 DHD_ERROR(("%s: Reassoc is in progress. "
4716 "Drop EAPOL M1 frame\n", __FUNCTION__));
4717 PKTFREE(dhdp->osh, pktbuf, FALSE);
4718 continue;
4719 }
4720 #endif /* DHD_POST_EAPOL_M1_AFTER_ROAM_EVT */
4721 /* Get the protocol, maintain skb around eth_type_trans()
4722 * The main reason for this hack is for the limitation of
4723 * Linux 2.4 where 'eth_type_trans' uses the 'net->hard_header_len'
4724 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
4725 * coping of the packet coming from the network stack to add
4726 * BDC, Hardware header etc, during network interface registration
4727 * we set the 'net->hard_header_len' to ETH_HLEN + extra space required
4728 * for BDC, Hardware header etc. and not just the ETH_HLEN
4729 */
4730 eth = skb->data;
4731 len = skb->len;
4732 dump_data = skb->data;
4733 protocol = (skb->data[12] << 8) | skb->data[13];
4734
4735 if (protocol == ETHER_TYPE_802_1X) {
4736 DBG_EVENT_LOG(dhdp, WIFI_EVENT_DRIVER_EAPOL_FRAME_RECEIVED);
4737 #if defined(WL_CFG80211) && defined(WL_WPS_SYNC)
4738 wl_handle_wps_states(ifp->net, dump_data, len, FALSE);
4739 #endif /* WL_CFG80211 && WL_WPS_SYNC */
4740 #ifdef DHD_4WAYM4_FAIL_DISCONNECT
4741 if (dhd_is_4way_msg((uint8 *)(skb->data)) == EAPOL_4WAY_M3) {
4742 OSL_ATOMIC_SET(dhdp->osh, &ifp->m4state, M3_RXED);
4743 }
4744 #endif /* DHD_4WAYM4_FAIL_DISCONNECT */
4745 }
4746 dhd_dump_pkt(dhdp, ifidx, dump_data, len, FALSE, NULL, NULL);
4747
4748 skb->protocol = eth_type_trans(skb, skb->dev);
4749
4750 if (skb->pkt_type == PACKET_MULTICAST) {
4751 dhd->pub.rx_multicast++;
4752 ifp->stats.multicast++;
4753 }
4754
4755 skb->data = eth;
4756 skb->len = len;
4757
4758 #ifdef CONFIG_AP6XXX_WIFI6_HDF
4759 // send EAPOL pkt to HDF WIFI
4760 if (protocol == ETHER_TYPE_802_1X) {
4761 netDevice = GetHdfNetDeviceByLinuxInf(skb->dev);
4762 if (netDevice && netDevice->netDeviceIf != NULL && netDevice->netDeviceIf->specialEtherTypeProcess != NULL) {
4763 eap_skb = skb_copy(skb, GFP_ATOMIC);
4764 skb_linearize(eap_skb);
4765 ret = netDevice->netDeviceIf->specialEtherTypeProcess(netDevice, eap_skb);
4766 DHD_ERROR(("%s: send EAPOL pkt ret=%d, from %s\n", __FUNCTION__, ret, netDevice->name));
4767 print_hex_dump(KERN_INFO, "recv EAPOL: ", DUMP_PREFIX_NONE, 16, 1, skb->data, skb->len, true);
4768 }
4769 }
4770 #endif
4771 DHD_DBG_PKT_MON_RX(dhdp, skb);
4772 /* Strip header, count, deliver upward */
4773 skb_pull(skb, ETH_HLEN);
4774
4775 /* Process special event packets and then discard them */
4776 memset(&event, 0, sizeof(event));
4777
4778 if (ntoh16(skb->protocol) == ETHER_TYPE_BRCM) {
4779 bcm_event_msg_u_t evu;
4780 int ret_event, event_type;
4781 void *pkt_data = skb_mac_header(skb);
4782
4783 ret_event = wl_host_event_get_data(pkt_data, len, &evu);
4784
4785 if (ret_event != BCME_OK) {
4786 DHD_ERROR(("%s: wl_host_event_get_data err = %d\n",
4787 __FUNCTION__, ret_event));
4788 #ifdef DHD_USE_STATIC_CTRLBUF
4789 PKTFREE_STATIC(dhdp->osh, pktbuf, FALSE);
4790 #else
4791 PKTFREE(dhdp->osh, pktbuf, FALSE);
4792 #endif // endif
4793 continue;
4794 }
4795
4796 memcpy(&event, &evu.event, sizeof(wl_event_msg_t));
4797 event_type = ntoh32_ua((void *)&event.event_type);
4798 #ifdef SHOW_LOGTRACE
4799 /* Event msg printing is called from dhd_rx_frame which is in Tasklet
4800 * context in case of PCIe FD, in case of other bus this will be from
4801 * DPC context. If we get bunch of events from Dongle then printing all
4802 * of them from Tasklet/DPC context that too in data path is costly.
4803 * Also in the new Dongle SW(4359, 4355 onwards) console prints too come as
4804 * events with type WLC_E_TRACE.
4805 * We'll print this console logs from the WorkQueue context by enqueing SKB
4806 * here and Dequeuing will be done in WorkQueue and will be freed only if
4807 * logtrace_pkt_sendup is true
4808 */
4809 if (event_type == WLC_E_TRACE) {
4810 DHD_EVENT(("%s: WLC_E_TRACE\n", __FUNCTION__));
4811 dhd_event_logtrace_enqueue(dhdp, ifidx, pktbuf);
4812 continue;
4813 }
4814 #endif /* SHOW_LOGTRACE */
4815
4816 ret_event = dhd_wl_host_event(dhd, ifidx, pkt_data, len, &event, &data);
4817
4818 wl_event_to_host_order(&event);
4819 if (!tout_ctrl)
4820 tout_ctrl = DHD_PACKET_TIMEOUT_MS;
4821
4822 #if defined(PNO_SUPPORT)
4823 if (event_type == WLC_E_PFN_NET_FOUND) {
4824 /* enforce custom wake lock to garantee that Kernel not suspended */
4825 tout_ctrl = CUSTOM_PNO_EVENT_LOCK_xTIME * DHD_PACKET_TIMEOUT_MS;
4826 }
4827 #endif /* PNO_SUPPORT */
4828 if (numpkt != 1) {
4829 DHD_TRACE(("%s: Got BRCM event packet in a chained packet.\n",
4830 __FUNCTION__));
4831 }
4832
4833 #ifdef DHD_WAKE_STATUS
4834 if (unlikely(pkt_wake)) {
4835 #ifdef DHD_WAKE_EVENT_STATUS
4836 if (event.event_type < WLC_E_LAST) {
4837 wcp->rc_event[event.event_type]++;
4838 wcp->rcwake++;
4839 pkt_wake = 0;
4840 }
4841 #endif /* DHD_WAKE_EVENT_STATUS */
4842 }
4843 #endif /* DHD_WAKE_STATUS */
4844
4845 /* For delete virtual interface event, wl_host_event returns positive
4846 * i/f index, do not proceed. just free the pkt.
4847 */
4848 if ((event_type == WLC_E_IF) && (ret_event > 0)) {
4849 DHD_ERROR(("%s: interface is deleted. Free event packet\n",
4850 __FUNCTION__));
4851 #ifdef DHD_USE_STATIC_CTRLBUF
4852 PKTFREE_STATIC(dhdp->osh, pktbuf, FALSE);
4853 #else
4854 PKTFREE(dhdp->osh, pktbuf, FALSE);
4855 #endif // endif
4856 continue;
4857 }
4858
4859 /*
4860 * For the event packets, there is a possibility
4861 * of ifidx getting modifed.Thus update the ifp
4862 * once again.
4863 */
4864 ASSERT(ifidx < DHD_MAX_IFS && dhd->iflist[ifidx]);
4865 ifp = dhd->iflist[ifidx];
4866 #ifndef PROP_TXSTATUS_VSDB
4867 if (!(ifp && ifp->net && (ifp->net->reg_state == NETREG_REGISTERED)))
4868 #else
4869 if (!(ifp && ifp->net && (ifp->net->reg_state == NETREG_REGISTERED) &&
4870 dhd->pub.up))
4871 #endif /* PROP_TXSTATUS_VSDB */
4872 {
4873 DHD_ERROR(("%s: net device is NOT registered. drop event packet\n",
4874 __FUNCTION__));
4875 #ifdef DHD_USE_STATIC_CTRLBUF
4876 PKTFREE_STATIC(dhdp->osh, pktbuf, FALSE);
4877 #else
4878 PKTFREE(dhdp->osh, pktbuf, FALSE);
4879 #endif // endif
4880 continue;
4881 }
4882
4883 #ifdef SENDPROB
4884 if (dhdp->wl_event_enabled ||
4885 (dhdp->recv_probereq && (event.event_type == WLC_E_PROBREQ_MSG)))
4886 #else
4887 if (dhdp->wl_event_enabled)
4888 #endif
4889 {
4890 #ifdef DHD_USE_STATIC_CTRLBUF
4891 /* If event bufs are allocated via static buf pool
4892 * and wl events are enabled, make a copy, free the
4893 * local one and send the copy up.
4894 */
4895 void *npkt = PKTDUP(dhdp->osh, skb);
4896 /* Clone event and send it up */
4897 PKTFREE_STATIC(dhdp->osh, pktbuf, FALSE);
4898 if (npkt) {
4899 skb = npkt;
4900 } else {
4901 DHD_ERROR(("skb clone failed. dropping event.\n"));
4902 continue;
4903 }
4904 #endif /* DHD_USE_STATIC_CTRLBUF */
4905 } else {
4906 /* If event enabled not explictly set, drop events */
4907 #ifdef DHD_USE_STATIC_CTRLBUF
4908 PKTFREE_STATIC(dhdp->osh, pktbuf, FALSE);
4909 #else
4910 PKTFREE(dhdp->osh, pktbuf, FALSE);
4911 #endif /* DHD_USE_STATIC_CTRLBUF */
4912 continue;
4913 }
4914 } else {
4915 tout_rx = DHD_PACKET_TIMEOUT_MS;
4916
4917 #ifdef PROP_TXSTATUS
4918 dhd_wlfc_save_rxpath_ac_time(dhdp, (uint8)PKTPRIO(skb));
4919 #endif /* PROP_TXSTATUS */
4920
4921 #ifdef DHD_WAKE_STATUS
4922 if (unlikely(pkt_wake)) {
4923 wcp->rxwake++;
4924 #ifdef DHD_WAKE_RX_STATUS
4925 #define ETHER_ICMP6_HEADER 20
4926 #define ETHER_IPV6_SADDR (ETHER_ICMP6_HEADER + 2)
4927 #define ETHER_IPV6_DAADR (ETHER_IPV6_SADDR + IPV6_ADDR_LEN)
4928 #define ETHER_ICMPV6_TYPE (ETHER_IPV6_DAADR + IPV6_ADDR_LEN)
4929
4930 if (ntoh16(skb->protocol) == ETHER_TYPE_ARP) /* ARP */
4931 wcp->rx_arp++;
4932 if (dump_data[0] == 0xFF) { /* Broadcast */
4933 wcp->rx_bcast++;
4934 } else if (dump_data[0] & 0x01) { /* Multicast */
4935 wcp->rx_mcast++;
4936 if (ntoh16(skb->protocol) == ETHER_TYPE_IPV6) {
4937 wcp->rx_multi_ipv6++;
4938 if ((skb->len > ETHER_ICMP6_HEADER) &&
4939 (dump_data[ETHER_ICMP6_HEADER] == IPPROTO_ICMPV6)) {
4940 wcp->rx_icmpv6++;
4941 if (skb->len > ETHER_ICMPV6_TYPE) {
4942 switch (dump_data[ETHER_ICMPV6_TYPE]) {
4943 case NDISC_ROUTER_ADVERTISEMENT:
4944 wcp->rx_icmpv6_ra++;
4945 break;
4946 case NDISC_NEIGHBOUR_ADVERTISEMENT:
4947 wcp->rx_icmpv6_na++;
4948 break;
4949 case NDISC_NEIGHBOUR_SOLICITATION:
4950 wcp->rx_icmpv6_ns++;
4951 break;
4952 }
4953 }
4954 }
4955 } else if (dump_data[2] == 0x5E) {
4956 wcp->rx_multi_ipv4++;
4957 } else {
4958 wcp->rx_multi_other++;
4959 }
4960 } else { /* Unicast */
4961 wcp->rx_ucast++;
4962 }
4963 #undef ETHER_ICMP6_HEADER
4964 #undef ETHER_IPV6_SADDR
4965 #undef ETHER_IPV6_DAADR
4966 #undef ETHER_ICMPV6_TYPE
4967 #endif /* DHD_WAKE_RX_STATUS */
4968 pkt_wake = 0;
4969 }
4970 #endif /* DHD_WAKE_STATUS */
4971 }
4972
4973 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0)
4974 ifp->net->last_rx = jiffies;
4975 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0) */
4976
4977 if (ntoh16(skb->protocol) != ETHER_TYPE_BRCM) {
4978 dhdp->dstats.rx_bytes += skb->len;
4979 dhdp->rx_packets++; /* Local count */
4980 ifp->stats.rx_bytes += skb->len;
4981 ifp->stats.rx_packets++;
4982 }
4983
4984 if (in_interrupt()) {
4985 bcm_object_trace_opr(skb, BCM_OBJDBG_REMOVE,
4986 __FUNCTION__, __LINE__);
4987 DHD_PERIM_UNLOCK_ALL((dhd->fwder_unit % FWDER_MAX_UNIT));
4988 #if defined(WL_MONITOR) && defined(BCMSDIO)
4989 if (dhd_monitor_enabled(dhdp, ifidx))
4990 dhd_rx_mon_pkt_sdio(dhdp, skb, ifidx);
4991 else
4992 #endif /* WL_MONITOR && BCMSDIO */
4993 #if defined(DHD_LB_RXP)
4994 netif_receive_skb(skb);
4995 #else /* !defined(DHD_LB_RXP) */
4996 netif_rx(skb);
4997 #endif /* !defined(DHD_LB_RXP) */
4998 DHD_PERIM_LOCK_ALL((dhd->fwder_unit % FWDER_MAX_UNIT));
4999 } else {
5000 if (dhd->rxthread_enabled) {
5001 if (!skbhead)
5002 skbhead = skb;
5003 else
5004 PKTSETNEXT(dhdp->osh, skbprev, skb);
5005 skbprev = skb;
5006 } else {
5007
5008 /* If the receive is not processed inside an ISR,
5009 * the softirqd must be woken explicitly to service
5010 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
5011 * by netif_rx_ni(), but in earlier kernels, we need
5012 * to do it manually.
5013 */
5014 bcm_object_trace_opr(skb, BCM_OBJDBG_REMOVE,
5015 __FUNCTION__, __LINE__);
5016
5017 #if defined(ARGOS_NOTIFY_CB)
5018 argos_register_notifier_deinit();
5019 #endif // endif
5020 #if defined(BCMPCIE) && defined(DHDTCPACK_SUPPRESS)
5021 dhd_tcpack_suppress_set(&dhd->pub, TCPACK_SUP_OFF);
5022 #endif /* BCMPCIE && DHDTCPACK_SUPPRESS */
5023 DHD_PERIM_UNLOCK_ALL((dhd->fwder_unit % FWDER_MAX_UNIT));
5024 #if defined(DHD_LB_RXP)
5025 netif_receive_skb(skb);
5026 #else /* !defined(DHD_LB_RXP) */
5027 netif_rx_ni(skb);
5028 #endif /* defined(DHD_LB_RXP) */
5029 DHD_PERIM_LOCK_ALL((dhd->fwder_unit % FWDER_MAX_UNIT));
5030 }
5031 }
5032 }
5033
5034 if (dhd->rxthread_enabled && skbhead)
5035 dhd_sched_rxf(dhdp, skbhead);
5036
5037 DHD_OS_WAKE_LOCK_RX_TIMEOUT_ENABLE(dhdp, tout_rx);
5038 DHD_OS_WAKE_LOCK_CTRL_TIMEOUT_ENABLE(dhdp, tout_ctrl);
5039 }
5040
5041 void
dhd_event(struct dhd_info * dhd,char * evpkt,int evlen,int ifidx)5042 dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx)
5043 {
5044 /* Linux version has nothing to do */
5045 return;
5046 }
5047
5048 void
dhd_txcomplete(dhd_pub_t * dhdp,void * txp,bool success)5049 dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success)
5050 {
5051 dhd_info_t *dhd = (dhd_info_t *)(dhdp->info);
5052 struct ether_header *eh;
5053 uint16 type;
5054
5055 dhd_prot_hdrpull(dhdp, NULL, txp, NULL, NULL);
5056
5057 eh = (struct ether_header *)PKTDATA(dhdp->osh, txp);
5058 type = ntoh16(eh->ether_type);
5059
5060 if (type == ETHER_TYPE_802_1X) {
5061 atomic_dec(&dhd->pend_8021x_cnt);
5062 }
5063
5064 #ifdef PROP_TXSTATUS
5065 if (dhdp->wlfc_state && (dhdp->proptxstatus_mode != WLFC_FCMODE_NONE)) {
5066 dhd_if_t *ifp = dhd->iflist[DHD_PKTTAG_IF(PKTTAG(txp))];
5067 uint datalen = PKTLEN(dhd->pub.osh, txp);
5068 if (ifp != NULL) {
5069 if (success) {
5070 dhd->pub.tx_packets++;
5071 ifp->stats.tx_packets++;
5072 ifp->stats.tx_bytes += datalen;
5073 } else {
5074 ifp->stats.tx_dropped++;
5075 }
5076 }
5077 }
5078 #endif // endif
5079 }
5080
5081 static struct net_device_stats *
dhd_get_stats(struct net_device * net)5082 dhd_get_stats(struct net_device *net)
5083 {
5084 dhd_info_t *dhd = DHD_DEV_INFO(net);
5085 dhd_if_t *ifp;
5086
5087 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
5088
5089 if (!dhd) {
5090 DHD_ERROR(("%s : dhd is NULL\n", __FUNCTION__));
5091 goto error;
5092 }
5093
5094 ifp = dhd_get_ifp_by_ndev(&dhd->pub, net);
5095 if (!ifp) {
5096 /* return empty stats */
5097 DHD_ERROR(("%s: BAD_IF\n", __FUNCTION__));
5098 goto error;
5099 }
5100
5101 if (dhd->pub.up) {
5102 /* Use the protocol to get dongle stats */
5103 dhd_prot_dstats(&dhd->pub);
5104 }
5105 return &ifp->stats;
5106
5107 error:
5108 memset(&net->stats, 0, sizeof(net->stats));
5109 return &net->stats;
5110 }
5111
5112 #ifndef BCMDBUS
5113 static int
dhd_watchdog_thread(void * data)5114 dhd_watchdog_thread(void *data)
5115 {
5116 tsk_ctl_t *tsk = (tsk_ctl_t *)data;
5117 dhd_info_t *dhd = (dhd_info_t *)tsk->parent;
5118 /* This thread doesn't need any user-level access,
5119 * so get rid of all our resources
5120 */
5121 if (dhd_watchdog_prio > 0) {
5122 struct sched_param param;
5123 param.sched_priority = (dhd_watchdog_prio < MAX_RT_PRIO)?
5124 dhd_watchdog_prio:(MAX_RT_PRIO-1);
5125 setScheduler(current, SCHED_FIFO, ¶m);
5126 }
5127
5128 while (1) {
5129 if (down_interruptible (&tsk->sema) == 0) {
5130 unsigned long flags;
5131 unsigned long jiffies_at_start = jiffies;
5132 unsigned long time_lapse;
5133 #ifdef BCMPCIE
5134 DHD_OS_WD_WAKE_LOCK(&dhd->pub);
5135 #endif /* BCMPCIE */
5136
5137 SMP_RD_BARRIER_DEPENDS();
5138 if (tsk->terminated) {
5139 #ifdef BCMPCIE
5140 DHD_OS_WD_WAKE_UNLOCK(&dhd->pub);
5141 #endif /* BCMPCIE */
5142 break;
5143 }
5144
5145 if (dhd->pub.dongle_reset == FALSE) {
5146 DHD_TIMER(("%s:\n", __FUNCTION__));
5147 dhd_bus_watchdog(&dhd->pub);
5148
5149 DHD_GENERAL_LOCK(&dhd->pub, flags);
5150 /* Count the tick for reference */
5151 dhd->pub.tickcnt++;
5152 #ifdef DHD_L2_FILTER
5153 dhd_l2_filter_watchdog(&dhd->pub);
5154 #endif /* DHD_L2_FILTER */
5155 time_lapse = jiffies - jiffies_at_start;
5156
5157 /* Reschedule the watchdog */
5158 if (dhd->wd_timer_valid) {
5159 mod_timer(&dhd->timer,
5160 jiffies +
5161 msecs_to_jiffies(dhd_watchdog_ms) -
5162 min(msecs_to_jiffies(dhd_watchdog_ms), time_lapse));
5163 }
5164 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
5165 }
5166 #ifdef BCMPCIE
5167 DHD_OS_WD_WAKE_UNLOCK(&dhd->pub);
5168 #endif /* BCMPCIE */
5169 } else {
5170 break;
5171 }
5172 }
5173
5174 complete_and_exit(&tsk->completed, 0);
5175 }
5176
dhd_watchdog(ulong data)5177 static void dhd_watchdog(ulong data)
5178 {
5179 dhd_info_t *dhd = (dhd_info_t *)data;
5180 unsigned long flags;
5181
5182 if (dhd->pub.dongle_reset) {
5183 return;
5184 }
5185
5186 if (dhd->thr_wdt_ctl.thr_pid >= 0) {
5187 up(&dhd->thr_wdt_ctl.sema);
5188 return;
5189 }
5190
5191 #ifdef BCMPCIE
5192 DHD_OS_WD_WAKE_LOCK(&dhd->pub);
5193 #endif /* BCMPCIE */
5194 /* Call the bus module watchdog */
5195 dhd_bus_watchdog(&dhd->pub);
5196
5197 DHD_GENERAL_LOCK(&dhd->pub, flags);
5198 /* Count the tick for reference */
5199 dhd->pub.tickcnt++;
5200
5201 #ifdef DHD_L2_FILTER
5202 dhd_l2_filter_watchdog(&dhd->pub);
5203 #endif /* DHD_L2_FILTER */
5204 /* Reschedule the watchdog */
5205 if (dhd->wd_timer_valid)
5206 mod_timer(&dhd->timer, jiffies + msecs_to_jiffies(dhd_watchdog_ms));
5207 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
5208 #ifdef BCMPCIE
5209 DHD_OS_WD_WAKE_UNLOCK(&dhd->pub);
5210 #endif /* BCMPCIE */
5211 }
5212
5213 #ifdef ENABLE_ADAPTIVE_SCHED
5214 static void
dhd_sched_policy(int prio)5215 dhd_sched_policy(int prio)
5216 {
5217 struct sched_param param;
5218 if (cpufreq_quick_get(0) <= CUSTOM_CPUFREQ_THRESH) {
5219 param.sched_priority = 0;
5220 setScheduler(current, SCHED_NORMAL, ¶m);
5221 } else {
5222 if (get_scheduler_policy(current) != SCHED_FIFO) {
5223 param.sched_priority = (prio < MAX_RT_PRIO)? prio : (MAX_RT_PRIO-1);
5224 setScheduler(current, SCHED_FIFO, ¶m);
5225 }
5226 }
5227 }
5228 #endif /* ENABLE_ADAPTIVE_SCHED */
5229 #ifdef DEBUG_CPU_FREQ
dhd_cpufreq_notifier(struct notifier_block * nb,unsigned long val,void * data)5230 static int dhd_cpufreq_notifier(struct notifier_block *nb, unsigned long val, void *data)
5231 {
5232 dhd_info_t *dhd = container_of(nb, struct dhd_info, freq_trans);
5233 struct cpufreq_freqs *freq = data;
5234 if (dhd) {
5235 if (!dhd->new_freq)
5236 goto exit;
5237 if (val == CPUFREQ_POSTCHANGE) {
5238 DHD_ERROR(("cpu freq is changed to %u kHZ on CPU %d\n",
5239 freq->new, freq->cpu));
5240 *per_cpu_ptr(dhd->new_freq, freq->cpu) = freq->new;
5241 }
5242 }
5243 exit:
5244 return 0;
5245 }
5246 #endif /* DEBUG_CPU_FREQ */
5247
5248 static int
dhd_dpc_thread(void * data)5249 dhd_dpc_thread(void *data)
5250 {
5251 tsk_ctl_t *tsk = (tsk_ctl_t *)data;
5252 dhd_info_t *dhd = (dhd_info_t *)tsk->parent;
5253
5254 /* This thread doesn't need any user-level access,
5255 * so get rid of all our resources
5256 */
5257 if (dhd_dpc_prio > 0)
5258 {
5259 struct sched_param param;
5260 param.sched_priority = (dhd_dpc_prio < MAX_RT_PRIO)?dhd_dpc_prio:(MAX_RT_PRIO-1);
5261 setScheduler(current, SCHED_FIFO, ¶m);
5262 }
5263
5264 #ifdef CUSTOM_DPC_CPUCORE
5265 set_cpus_allowed_ptr(current, cpumask_of(CUSTOM_DPC_CPUCORE));
5266 #endif // endif
5267 #ifdef CUSTOM_SET_CPUCORE
5268 dhd->pub.current_dpc = current;
5269 #endif /* CUSTOM_SET_CPUCORE */
5270 /* Run until signal received */
5271 while (1) {
5272 if (dhd->pub.conf->dpc_cpucore >= 0) {
5273 printf("%s: set dpc_cpucore %d\n", __FUNCTION__, dhd->pub.conf->dpc_cpucore);
5274 set_cpus_allowed_ptr(current, cpumask_of(dhd->pub.conf->dpc_cpucore));
5275 dhd->pub.conf->dpc_cpucore = -1;
5276 }
5277 if (dhd->pub.conf->dhd_dpc_prio >= 0) {
5278 struct sched_param param;
5279 printf("%s: set dhd_dpc_prio %d\n", __FUNCTION__, dhd->pub.conf->dhd_dpc_prio);
5280 param.sched_priority = (dhd->pub.conf->dhd_dpc_prio < MAX_RT_PRIO)?
5281 dhd->pub.conf->dhd_dpc_prio:(MAX_RT_PRIO-1);
5282 setScheduler(current, SCHED_FIFO, ¶m);
5283 dhd->pub.conf->dhd_dpc_prio = -1;
5284 }
5285 if (!binary_sema_down(tsk)) {
5286 #ifdef ENABLE_ADAPTIVE_SCHED
5287 dhd_sched_policy(dhd_dpc_prio);
5288 #endif /* ENABLE_ADAPTIVE_SCHED */
5289 SMP_RD_BARRIER_DEPENDS();
5290 if (tsk->terminated) {
5291 break;
5292 }
5293
5294 /* Call bus dpc unless it indicated down (then clean stop) */
5295 if (dhd->pub.busstate != DHD_BUS_DOWN) {
5296 #ifdef DEBUG_DPC_THREAD_WATCHDOG
5297 int resched_cnt = 0;
5298 #endif /* DEBUG_DPC_THREAD_WATCHDOG */
5299 dhd_os_wd_timer_extend(&dhd->pub, TRUE);
5300 while (dhd_bus_dpc(dhd->pub.bus)) {
5301 /* process all data */
5302 #ifdef DEBUG_DPC_THREAD_WATCHDOG
5303 resched_cnt++;
5304 if (resched_cnt > MAX_RESCHED_CNT) {
5305 DHD_INFO(("%s Calling msleep to"
5306 "let other processes run. \n",
5307 __FUNCTION__));
5308 dhd->pub.dhd_bug_on = true;
5309 resched_cnt = 0;
5310 OSL_SLEEP(1);
5311 }
5312 #endif /* DEBUG_DPC_THREAD_WATCHDOG */
5313 }
5314 dhd_os_wd_timer_extend(&dhd->pub, FALSE);
5315 DHD_OS_WAKE_UNLOCK(&dhd->pub);
5316 } else {
5317 if (dhd->pub.up)
5318 dhd_bus_stop(dhd->pub.bus, TRUE);
5319 DHD_OS_WAKE_UNLOCK(&dhd->pub);
5320 }
5321 } else {
5322 break;
5323 }
5324 }
5325 complete_and_exit(&tsk->completed, 0);
5326 }
5327
5328 static int
dhd_rxf_thread(void * data)5329 dhd_rxf_thread(void *data)
5330 {
5331 tsk_ctl_t *tsk = (tsk_ctl_t *)data;
5332 dhd_info_t *dhd = (dhd_info_t *)tsk->parent;
5333 #if defined(WAIT_DEQUEUE)
5334 #define RXF_WATCHDOG_TIME 250 /* BARK_TIME(1000) / */
5335 ulong watchdogTime = OSL_SYSUPTIME(); /* msec */
5336 #endif // endif
5337 dhd_pub_t *pub = &dhd->pub;
5338
5339 /* This thread doesn't need any user-level access,
5340 * so get rid of all our resources
5341 */
5342 if (dhd_rxf_prio > 0)
5343 {
5344 struct sched_param param;
5345 param.sched_priority = (dhd_rxf_prio < MAX_RT_PRIO)?dhd_rxf_prio:(MAX_RT_PRIO-1);
5346 setScheduler(current, SCHED_FIFO, ¶m);
5347 }
5348
5349 #ifdef CUSTOM_SET_CPUCORE
5350 dhd->pub.current_rxf = current;
5351 #endif /* CUSTOM_SET_CPUCORE */
5352 /* Run until signal received */
5353 while (1) {
5354 if (dhd->pub.conf->rxf_cpucore >= 0) {
5355 printf("%s: set rxf_cpucore %d\n", __FUNCTION__, dhd->pub.conf->rxf_cpucore);
5356 set_cpus_allowed_ptr(current, cpumask_of(dhd->pub.conf->rxf_cpucore));
5357 dhd->pub.conf->rxf_cpucore = -1;
5358 }
5359 if (down_interruptible(&tsk->sema) == 0) {
5360 void *skb;
5361 #ifdef ENABLE_ADAPTIVE_SCHED
5362 dhd_sched_policy(dhd_rxf_prio);
5363 #endif /* ENABLE_ADAPTIVE_SCHED */
5364
5365 SMP_RD_BARRIER_DEPENDS();
5366
5367 if (tsk->terminated) {
5368 break;
5369 }
5370 skb = dhd_rxf_dequeue(pub);
5371
5372 if (skb == NULL) {
5373 continue;
5374 }
5375 while (skb) {
5376 void *skbnext = PKTNEXT(pub->osh, skb);
5377 PKTSETNEXT(pub->osh, skb, NULL);
5378 bcm_object_trace_opr(skb, BCM_OBJDBG_REMOVE,
5379 __FUNCTION__, __LINE__);
5380 #if defined(WL_MONITOR) && defined(BCMSDIO)
5381 if (dhd_monitor_enabled(pub, 0))
5382 dhd_rx_mon_pkt_sdio(pub, skb, 0);
5383 else
5384 #endif /* WL_MONITOR && BCMSDIO */
5385 netif_rx_ni(skb);
5386 skb = skbnext;
5387 }
5388 #if defined(WAIT_DEQUEUE)
5389 if (OSL_SYSUPTIME() - watchdogTime > RXF_WATCHDOG_TIME) {
5390 OSL_SLEEP(1);
5391 watchdogTime = OSL_SYSUPTIME();
5392 }
5393 #endif // endif
5394
5395 DHD_OS_WAKE_UNLOCK(pub);
5396 } else {
5397 break;
5398 }
5399 }
5400 complete_and_exit(&tsk->completed, 0);
5401 }
5402
5403 #ifdef BCMPCIE
dhd_dpc_enable(dhd_pub_t * dhdp)5404 void dhd_dpc_enable(dhd_pub_t *dhdp)
5405 {
5406 #if defined(DHD_LB_RXP) || defined(DHD_LB_TXP)
5407 dhd_info_t *dhd;
5408
5409 if (!dhdp || !dhdp->info)
5410 return;
5411 dhd = dhdp->info;
5412 #endif /* DHD_LB_RXP || DHD_LB_TXP */
5413
5414 #ifdef DHD_LB_RXP
5415 __skb_queue_head_init(&dhd->rx_pend_queue);
5416 #endif /* DHD_LB_RXP */
5417
5418 #ifdef DHD_LB_TXP
5419 skb_queue_head_init(&dhd->tx_pend_queue);
5420 #endif /* DHD_LB_TXP */
5421 }
5422 #endif /* BCMPCIE */
5423
5424 #ifdef BCMPCIE
5425 void
dhd_dpc_kill(dhd_pub_t * dhdp)5426 dhd_dpc_kill(dhd_pub_t *dhdp)
5427 {
5428 dhd_info_t *dhd;
5429
5430 if (!dhdp) {
5431 return;
5432 }
5433
5434 dhd = dhdp->info;
5435
5436 if (!dhd) {
5437 return;
5438 }
5439
5440 if (dhd->thr_dpc_ctl.thr_pid < 0) {
5441 tasklet_kill(&dhd->tasklet);
5442 DHD_ERROR(("%s: tasklet disabled\n", __FUNCTION__));
5443 }
5444
5445 #ifdef DHD_LB
5446 #ifdef DHD_LB_RXP
5447 cancel_work_sync(&dhd->rx_napi_dispatcher_work);
5448 __skb_queue_purge(&dhd->rx_pend_queue);
5449 #endif /* DHD_LB_RXP */
5450 #ifdef DHD_LB_TXP
5451 cancel_work_sync(&dhd->tx_dispatcher_work);
5452 skb_queue_purge(&dhd->tx_pend_queue);
5453 #endif /* DHD_LB_TXP */
5454
5455 /* Kill the Load Balancing Tasklets */
5456 #if defined(DHD_LB_TXC)
5457 tasklet_kill(&dhd->tx_compl_tasklet);
5458 #endif /* DHD_LB_TXC */
5459 #if defined(DHD_LB_RXC)
5460 tasklet_kill(&dhd->rx_compl_tasklet);
5461 #endif /* DHD_LB_RXC */
5462 #if defined(DHD_LB_TXP)
5463 tasklet_kill(&dhd->tx_tasklet);
5464 #endif /* DHD_LB_TXP */
5465 #endif /* DHD_LB */
5466 }
5467
5468 void
dhd_dpc_tasklet_kill(dhd_pub_t * dhdp)5469 dhd_dpc_tasklet_kill(dhd_pub_t *dhdp)
5470 {
5471 dhd_info_t *dhd;
5472
5473 if (!dhdp) {
5474 return;
5475 }
5476
5477 dhd = dhdp->info;
5478
5479 if (!dhd) {
5480 return;
5481 }
5482
5483 if (dhd->thr_dpc_ctl.thr_pid < 0) {
5484 tasklet_kill(&dhd->tasklet);
5485 }
5486 }
5487 #endif /* BCMPCIE */
5488
5489 static void
dhd_dpc(ulong data)5490 dhd_dpc(ulong data)
5491 {
5492 dhd_info_t *dhd;
5493
5494 dhd = (dhd_info_t *)data;
5495
5496 /* this (tasklet) can be scheduled in dhd_sched_dpc[dhd_linux.c]
5497 * down below , wake lock is set,
5498 * the tasklet is initialized in dhd_attach()
5499 */
5500 /* Call bus dpc unless it indicated down (then clean stop) */
5501 if (dhd->pub.busstate != DHD_BUS_DOWN) {
5502 #if defined(DHD_LB_STATS) && defined(PCIE_FULL_DONGLE)
5503 DHD_LB_STATS_INCR(dhd->dhd_dpc_cnt);
5504 #endif /* DHD_LB_STATS && PCIE_FULL_DONGLE */
5505 if (dhd_bus_dpc(dhd->pub.bus)) {
5506 tasklet_schedule(&dhd->tasklet);
5507 }
5508 } else {
5509 dhd_bus_stop(dhd->pub.bus, TRUE);
5510 }
5511 }
5512
5513 void
dhd_sched_dpc(dhd_pub_t * dhdp)5514 dhd_sched_dpc(dhd_pub_t *dhdp)
5515 {
5516 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
5517
5518 if (dhd->thr_dpc_ctl.thr_pid >= 0) {
5519 DHD_OS_WAKE_LOCK(dhdp);
5520 /* If the semaphore does not get up,
5521 * wake unlock should be done here
5522 */
5523 if (!binary_sema_up(&dhd->thr_dpc_ctl)) {
5524 DHD_OS_WAKE_UNLOCK(dhdp);
5525 }
5526 return;
5527 } else {
5528 dhd_bus_set_dpc_sched_time(dhdp);
5529 tasklet_schedule(&dhd->tasklet);
5530 }
5531 }
5532 #endif /* BCMDBUS */
5533
5534 static void
dhd_sched_rxf(dhd_pub_t * dhdp,void * skb)5535 dhd_sched_rxf(dhd_pub_t *dhdp, void *skb)
5536 {
5537 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
5538
5539 DHD_OS_WAKE_LOCK(dhdp);
5540
5541 DHD_TRACE(("dhd_sched_rxf: Enter\n"));
5542 do {
5543 if (dhd_rxf_enqueue(dhdp, skb) == BCME_OK)
5544 break;
5545 } while (1);
5546 if (dhd->thr_rxf_ctl.thr_pid >= 0) {
5547 up(&dhd->thr_rxf_ctl.sema);
5548 }
5549 return;
5550 }
5551
5552 #if defined(BCM_DNGL_EMBEDIMAGE) || defined(BCM_REQUEST_FW)
5553 #endif /* defined(BCM_DNGL_EMBEDIMAGE) || defined(BCM_REQUEST_FW) */
5554
5555 #ifdef TOE
5556 /* Retrieve current toe component enables, which are kept as a bitmap in toe_ol iovar */
5557 static int
dhd_toe_get(dhd_info_t * dhd,int ifidx,uint32 * toe_ol)5558 dhd_toe_get(dhd_info_t *dhd, int ifidx, uint32 *toe_ol)
5559 {
5560 char buf[32];
5561 int ret;
5562
5563 ret = dhd_iovar(&dhd->pub, ifidx, "toe_ol", NULL, 0, (char *)&buf, sizeof(buf), FALSE);
5564
5565 if (ret < 0) {
5566 if (ret == -EIO) {
5567 DHD_ERROR(("%s: toe not supported by device\n", dhd_ifname(&dhd->pub,
5568 ifidx)));
5569 return -EOPNOTSUPP;
5570 }
5571
5572 DHD_INFO(("%s: could not get toe_ol: ret=%d\n", dhd_ifname(&dhd->pub, ifidx), ret));
5573 return ret;
5574 }
5575
5576 memcpy(toe_ol, buf, sizeof(uint32));
5577 return 0;
5578 }
5579
5580 /* Set current toe component enables in toe_ol iovar, and set toe global enable iovar */
5581 static int
dhd_toe_set(dhd_info_t * dhd,int ifidx,uint32 toe_ol)5582 dhd_toe_set(dhd_info_t *dhd, int ifidx, uint32 toe_ol)
5583 {
5584 int toe, ret;
5585
5586 /* Set toe_ol as requested */
5587 ret = dhd_iovar(&dhd->pub, ifidx, "toe_ol", (char *)&toe_ol, sizeof(toe_ol), NULL, 0, TRUE);
5588 if (ret < 0) {
5589 DHD_ERROR(("%s: could not set toe_ol: ret=%d\n",
5590 dhd_ifname(&dhd->pub, ifidx), ret));
5591 return ret;
5592 }
5593
5594 /* Enable toe globally only if any components are enabled. */
5595 toe = (toe_ol != 0);
5596 ret = dhd_iovar(&dhd->pub, ifidx, "toe", (char *)&toe, sizeof(toe), NULL, 0, TRUE);
5597 if (ret < 0) {
5598 DHD_ERROR(("%s: could not set toe: ret=%d\n", dhd_ifname(&dhd->pub, ifidx), ret));
5599 return ret;
5600 }
5601
5602 return 0;
5603 }
5604 #endif /* TOE */
5605
5606 #if defined(WL_CFG80211) && defined(NUM_SCB_MAX_PROBE)
dhd_set_scb_probe(dhd_pub_t * dhd)5607 void dhd_set_scb_probe(dhd_pub_t *dhd)
5608 {
5609 wl_scb_probe_t scb_probe;
5610 char iovbuf[WL_EVENTING_MASK_LEN + sizeof(wl_scb_probe_t)];
5611 int ret;
5612
5613 if (dhd->op_mode & DHD_FLAG_HOSTAP_MODE) {
5614 return;
5615 }
5616
5617 ret = dhd_iovar(dhd, 0, "scb_probe", NULL, 0, iovbuf, sizeof(iovbuf), FALSE);
5618 if (ret < 0) {
5619 DHD_ERROR(("%s: GET max_scb_probe failed\n", __FUNCTION__));
5620 }
5621
5622 memcpy(&scb_probe, iovbuf, sizeof(wl_scb_probe_t));
5623
5624 scb_probe.scb_max_probe = NUM_SCB_MAX_PROBE;
5625
5626 ret = dhd_iovar(dhd, 0, "scb_probe", (char *)&scb_probe, sizeof(wl_scb_probe_t), NULL, 0,
5627 TRUE);
5628 if (ret < 0) {
5629 DHD_ERROR(("%s: max_scb_probe setting failed\n", __FUNCTION__));
5630 return;
5631 }
5632 }
5633 #endif /* WL_CFG80211 && NUM_SCB_MAX_PROBE */
5634
5635 static void
dhd_ethtool_get_drvinfo(struct net_device * net,struct ethtool_drvinfo * info)5636 dhd_ethtool_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *info)
5637 {
5638 dhd_info_t *dhd = DHD_DEV_INFO(net);
5639
5640 snprintf(info->driver, sizeof(info->driver), "wl");
5641 snprintf(info->version, sizeof(info->version), "%lu", dhd->pub.drv_version);
5642 }
5643
5644 struct ethtool_ops dhd_ethtool_ops = {
5645 .get_drvinfo = dhd_ethtool_get_drvinfo
5646 };
5647
5648 static int
dhd_ethtool(dhd_info_t * dhd,void * uaddr)5649 dhd_ethtool(dhd_info_t *dhd, void *uaddr)
5650 {
5651 struct ethtool_drvinfo info;
5652 char drvname[sizeof(info.driver)];
5653 uint32 cmd;
5654 #ifdef TOE
5655 struct ethtool_value edata;
5656 uint32 toe_cmpnt, csum_dir;
5657 int ret;
5658 #endif // endif
5659
5660 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
5661
5662 /* all ethtool calls start with a cmd word */
5663 if (copy_from_user(&cmd, uaddr, sizeof (uint32)))
5664 return -EFAULT;
5665
5666 switch (cmd) {
5667 case ETHTOOL_GDRVINFO:
5668 /* Copy out any request driver name */
5669 if (copy_from_user(&info, uaddr, sizeof(info)))
5670 return -EFAULT;
5671 strncpy(drvname, info.driver, sizeof(drvname) - 1);
5672 drvname[sizeof(drvname) - 1] = '\0';
5673
5674 /* clear struct for return */
5675 memset(&info, 0, sizeof(info));
5676 info.cmd = cmd;
5677
5678 /* if dhd requested, identify ourselves */
5679 if (strcmp(drvname, "?dhd") == 0) {
5680 snprintf(info.driver, sizeof(info.driver), "dhd");
5681 strncpy(info.version, EPI_VERSION_STR, sizeof(info.version) - 1);
5682 info.version[sizeof(info.version) - 1] = '\0';
5683 }
5684
5685 /* otherwise, require dongle to be up */
5686 else if (!dhd->pub.up) {
5687 DHD_ERROR(("%s: dongle is not up\n", __FUNCTION__));
5688 return -ENODEV;
5689 }
5690
5691 /* finally, report dongle driver type */
5692 else if (dhd->pub.iswl)
5693 snprintf(info.driver, sizeof(info.driver), "wl");
5694 else
5695 snprintf(info.driver, sizeof(info.driver), "xx");
5696
5697 snprintf(info.version, sizeof(info.version), "%lu", dhd->pub.drv_version);
5698 if (copy_to_user(uaddr, &info, sizeof(info)))
5699 return -EFAULT;
5700 DHD_CTL(("%s: given %*s, returning %s\n", __FUNCTION__,
5701 (int)sizeof(drvname), drvname, info.driver));
5702 break;
5703
5704 #ifdef TOE
5705 /* Get toe offload components from dongle */
5706 case ETHTOOL_GRXCSUM:
5707 case ETHTOOL_GTXCSUM:
5708 if ((ret = dhd_toe_get(dhd, 0, &toe_cmpnt)) < 0)
5709 return ret;
5710
5711 csum_dir = (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
5712
5713 edata.cmd = cmd;
5714 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
5715
5716 if (copy_to_user(uaddr, &edata, sizeof(edata)))
5717 return -EFAULT;
5718 break;
5719
5720 /* Set toe offload components in dongle */
5721 case ETHTOOL_SRXCSUM:
5722 case ETHTOOL_STXCSUM:
5723 if (copy_from_user(&edata, uaddr, sizeof(edata)))
5724 return -EFAULT;
5725
5726 /* Read the current settings, update and write back */
5727 if ((ret = dhd_toe_get(dhd, 0, &toe_cmpnt)) < 0)
5728 return ret;
5729
5730 csum_dir = (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
5731
5732 if (edata.data != 0)
5733 toe_cmpnt |= csum_dir;
5734 else
5735 toe_cmpnt &= ~csum_dir;
5736
5737 if ((ret = dhd_toe_set(dhd, 0, toe_cmpnt)) < 0)
5738 return ret;
5739
5740 /* If setting TX checksum mode, tell Linux the new mode */
5741 if (cmd == ETHTOOL_STXCSUM) {
5742 if (edata.data)
5743 dhd->iflist[0]->net->features |= NETIF_F_IP_CSUM;
5744 else
5745 dhd->iflist[0]->net->features &= ~NETIF_F_IP_CSUM;
5746 }
5747
5748 break;
5749 #endif /* TOE */
5750
5751 default:
5752 return -EOPNOTSUPP;
5753 }
5754
5755 return 0;
5756 }
5757
dhd_check_hang(struct net_device * net,dhd_pub_t * dhdp,int error)5758 static bool dhd_check_hang(struct net_device *net, dhd_pub_t *dhdp, int error)
5759 {
5760 if (!dhdp) {
5761 DHD_ERROR(("%s: dhdp is NULL\n", __FUNCTION__));
5762 return FALSE;
5763 }
5764
5765 if (!dhdp->up)
5766 return FALSE;
5767
5768 #if !defined(BCMPCIE) && !defined(BCMDBUS)
5769 if (dhdp->info->thr_dpc_ctl.thr_pid < 0) {
5770 DHD_ERROR(("%s : skipped due to negative pid - unloading?\n", __FUNCTION__));
5771 return FALSE;
5772 }
5773 #endif /* !BCMPCIE && !BCMDBUS */
5774
5775 if ((error == -ETIMEDOUT) || (error == -EREMOTEIO) ||
5776 ((dhdp->busstate == DHD_BUS_DOWN) && (!dhdp->dongle_reset))) {
5777 #ifdef BCMPCIE
5778 DHD_ERROR(("%s: Event HANG send up due to re=%d te=%d d3acke=%d e=%d s=%d\n",
5779 __FUNCTION__, dhdp->rxcnt_timeout, dhdp->txcnt_timeout,
5780 dhdp->d3ackcnt_timeout, error, dhdp->busstate));
5781 #else
5782 DHD_ERROR(("%s: Event HANG send up due to re=%d te=%d e=%d s=%d\n", __FUNCTION__,
5783 dhdp->rxcnt_timeout, dhdp->txcnt_timeout, error, dhdp->busstate));
5784 #endif /* BCMPCIE */
5785 if (dhdp->hang_reason == 0) {
5786 if (dhdp->dongle_trap_occured) {
5787 dhdp->hang_reason = HANG_REASON_DONGLE_TRAP;
5788 #ifdef BCMPCIE
5789 } else if (dhdp->d3ackcnt_timeout) {
5790 dhdp->hang_reason = dhdp->is_sched_error ?
5791 HANG_REASON_D3_ACK_TIMEOUT_SCHED_ERROR :
5792 HANG_REASON_D3_ACK_TIMEOUT;
5793 #endif /* BCMPCIE */
5794 } else {
5795 dhdp->hang_reason = dhdp->is_sched_error ?
5796 HANG_REASON_IOCTL_RESP_TIMEOUT_SCHED_ERROR :
5797 HANG_REASON_IOCTL_RESP_TIMEOUT;
5798 }
5799 }
5800 printf("%s\n", info_string);
5801 printf("MAC %pM\n", &dhdp->mac);
5802 net_os_send_hang_message(net);
5803 return TRUE;
5804 }
5805 return FALSE;
5806 }
5807
5808 #ifdef WL_MONITOR
5809 bool
dhd_monitor_enabled(dhd_pub_t * dhd,int ifidx)5810 dhd_monitor_enabled(dhd_pub_t *dhd, int ifidx)
5811 {
5812 return (dhd->info->monitor_type != 0);
5813 }
5814
5815 #ifdef BCMSDIO
5816 static void
dhd_rx_mon_pkt_sdio(dhd_pub_t * dhdp,void * pkt,int ifidx)5817 dhd_rx_mon_pkt_sdio(dhd_pub_t *dhdp, void *pkt, int ifidx)
5818 {
5819 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
5820
5821 if (!dhd->monitor_skb) {
5822 if ((dhd->monitor_skb = PKTTONATIVE(dhdp->osh, pkt)) == NULL)
5823 return;
5824 }
5825
5826 if (dhd->monitor_type && dhd->monitor_dev)
5827 dhd->monitor_skb->dev = dhd->monitor_dev;
5828 else {
5829 PKTFREE(dhdp->osh, pkt, FALSE);
5830 dhd->monitor_skb = NULL;
5831 return;
5832 }
5833
5834 dhd->monitor_skb->protocol =
5835 eth_type_trans(dhd->monitor_skb, dhd->monitor_skb->dev);
5836 dhd->monitor_len = 0;
5837
5838 netif_rx_ni(dhd->monitor_skb);
5839
5840 dhd->monitor_skb = NULL;
5841 }
5842 #elif defined(BCMPCIE)
5843 void
dhd_rx_mon_pkt(dhd_pub_t * dhdp,host_rxbuf_cmpl_t * msg,void * pkt,int ifidx)5844 dhd_rx_mon_pkt(dhd_pub_t *dhdp, host_rxbuf_cmpl_t* msg, void *pkt, int ifidx)
5845 {
5846 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
5847 {
5848 uint8 amsdu_flag = (msg->flags & BCMPCIE_PKT_FLAGS_MONITOR_MASK) >>
5849 BCMPCIE_PKT_FLAGS_MONITOR_SHIFT;
5850 switch (amsdu_flag) {
5851 case BCMPCIE_PKT_FLAGS_MONITOR_NO_AMSDU:
5852 default:
5853 if (!dhd->monitor_skb) {
5854 if ((dhd->monitor_skb = PKTTONATIVE(dhdp->osh, pkt))
5855 == NULL)
5856 return;
5857 }
5858 if (dhd->monitor_type && dhd->monitor_dev)
5859 dhd->monitor_skb->dev = dhd->monitor_dev;
5860 else {
5861 PKTFREE(dhdp->osh, pkt, FALSE);
5862 dhd->monitor_skb = NULL;
5863 return;
5864 }
5865 dhd->monitor_skb->protocol =
5866 eth_type_trans(dhd->monitor_skb, dhd->monitor_skb->dev);
5867 dhd->monitor_len = 0;
5868 break;
5869
5870 case BCMPCIE_PKT_FLAGS_MONITOR_FIRST_PKT:
5871 if (!dhd->monitor_skb) {
5872 if ((dhd->monitor_skb = dev_alloc_skb(MAX_MON_PKT_SIZE))
5873 == NULL)
5874 return;
5875 dhd->monitor_len = 0;
5876 }
5877 if (dhd->monitor_type && dhd->monitor_dev)
5878 dhd->monitor_skb->dev = dhd->monitor_dev;
5879 else {
5880 PKTFREE(dhdp->osh, pkt, FALSE);
5881 dev_kfree_skb(dhd->monitor_skb);
5882 return;
5883 }
5884 memcpy(PKTDATA(dhdp->osh, dhd->monitor_skb),
5885 PKTDATA(dhdp->osh, pkt), PKTLEN(dhdp->osh, pkt));
5886 dhd->monitor_len = PKTLEN(dhdp->osh, pkt);
5887 PKTFREE(dhdp->osh, pkt, FALSE);
5888 return;
5889
5890 case BCMPCIE_PKT_FLAGS_MONITOR_INTER_PKT:
5891 memcpy(PKTDATA(dhdp->osh, dhd->monitor_skb) + dhd->monitor_len,
5892 PKTDATA(dhdp->osh, pkt), PKTLEN(dhdp->osh, pkt));
5893 dhd->monitor_len += PKTLEN(dhdp->osh, pkt);
5894 PKTFREE(dhdp->osh, pkt, FALSE);
5895 return;
5896
5897 case BCMPCIE_PKT_FLAGS_MONITOR_LAST_PKT:
5898 memcpy(PKTDATA(dhdp->osh, dhd->monitor_skb) + dhd->monitor_len,
5899 PKTDATA(dhdp->osh, pkt), PKTLEN(dhdp->osh, pkt));
5900 dhd->monitor_len += PKTLEN(dhdp->osh, pkt);
5901 PKTFREE(dhdp->osh, pkt, FALSE);
5902 skb_put(dhd->monitor_skb, dhd->monitor_len);
5903 dhd->monitor_skb->protocol =
5904 eth_type_trans(dhd->monitor_skb, dhd->monitor_skb->dev);
5905 dhd->monitor_len = 0;
5906 break;
5907 }
5908 }
5909
5910 if (in_interrupt()) {
5911 bcm_object_trace_opr(skb, BCM_OBJDBG_REMOVE,
5912 __FUNCTION__, __LINE__);
5913 DHD_PERIM_UNLOCK_ALL((dhd->fwder_unit % FWDER_MAX_UNIT));
5914 netif_rx(dhd->monitor_skb);
5915 DHD_PERIM_LOCK_ALL((dhd->fwder_unit % FWDER_MAX_UNIT));
5916 } else {
5917 /* If the receive is not processed inside an ISR,
5918 * the softirqd must be woken explicitly to service
5919 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
5920 * by netif_rx_ni(), but in earlier kernels, we need
5921 * to do it manually.
5922 */
5923 bcm_object_trace_opr(dhd->monitor_skb, BCM_OBJDBG_REMOVE,
5924 __FUNCTION__, __LINE__);
5925
5926 DHD_PERIM_UNLOCK_ALL((dhd->fwder_unit % FWDER_MAX_UNIT));
5927 netif_rx_ni(dhd->monitor_skb);
5928 DHD_PERIM_LOCK_ALL((dhd->fwder_unit % FWDER_MAX_UNIT));
5929 }
5930
5931 dhd->monitor_skb = NULL;
5932 }
5933 #endif
5934
5935 typedef struct dhd_mon_dev_priv {
5936 struct net_device_stats stats;
5937 } dhd_mon_dev_priv_t;
5938
5939 #define DHD_MON_DEV_PRIV_SIZE (sizeof(dhd_mon_dev_priv_t))
5940 #define DHD_MON_DEV_PRIV(dev) ((dhd_mon_dev_priv_t *)DEV_PRIV(dev))
5941 #define DHD_MON_DEV_STATS(dev) (((dhd_mon_dev_priv_t *)DEV_PRIV(dev))->stats)
5942
5943 static netdev_tx_t
dhd_monitor_start(struct sk_buff * skb,struct net_device * dev)5944 dhd_monitor_start(struct sk_buff *skb, struct net_device *dev)
5945 {
5946 PKTFREE(NULL, skb, FALSE);
5947 return 0;
5948 }
5949
5950 #if defined(BT_OVER_SDIO)
5951
5952 void
dhdsdio_bus_usr_cnt_inc(dhd_pub_t * dhdp)5953 dhdsdio_bus_usr_cnt_inc(dhd_pub_t *dhdp)
5954 {
5955 dhdp->info->bus_user_count++;
5956 }
5957
5958 void
dhdsdio_bus_usr_cnt_dec(dhd_pub_t * dhdp)5959 dhdsdio_bus_usr_cnt_dec(dhd_pub_t *dhdp)
5960 {
5961 dhdp->info->bus_user_count--;
5962 }
5963
5964 /* Return values:
5965 * Success: Returns 0
5966 * Failure: Returns -1 or errono code
5967 */
5968 int
dhd_bus_get(wlan_bt_handle_t handle,bus_owner_t owner)5969 dhd_bus_get(wlan_bt_handle_t handle, bus_owner_t owner)
5970 {
5971 dhd_pub_t *dhdp = (dhd_pub_t *)handle;
5972 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
5973 int ret = 0;
5974
5975 mutex_lock(&dhd->bus_user_lock);
5976 ++dhd->bus_user_count;
5977 if (dhd->bus_user_count < 0) {
5978 DHD_ERROR(("%s(): bus_user_count is negative, which is invalid\n", __FUNCTION__));
5979 ret = -1;
5980 goto exit;
5981 }
5982
5983 if (dhd->bus_user_count == 1) {
5984
5985 dhd->pub.hang_was_sent = 0;
5986
5987 /* First user, turn on WL_REG, start the bus */
5988 DHD_ERROR(("%s(): First user Turn On WL_REG & start the bus", __FUNCTION__));
5989
5990 if (!wifi_platform_set_power(dhd->adapter, TRUE, WIFI_TURNON_DELAY)) {
5991 /* Enable F1 */
5992 ret = dhd_bus_resume(dhdp, 0);
5993 if (ret) {
5994 DHD_ERROR(("%s(): Failed to enable F1, err=%d\n",
5995 __FUNCTION__, ret));
5996 goto exit;
5997 }
5998 }
5999
6000 dhd_update_fw_nv_path(dhd);
6001 /* update firmware and nvram path to sdio bus */
6002 dhd_bus_update_fw_nv_path(dhd->pub.bus,
6003 dhd->fw_path, dhd->nv_path);
6004 /* download the firmware, Enable F2 */
6005 /* TODO: Should be done only in case of FW switch */
6006 ret = dhd_bus_devreset(dhdp, FALSE);
6007 dhd_bus_resume(dhdp, 1);
6008 if (!ret) {
6009 if (dhd_sync_with_dongle(&dhd->pub) < 0) {
6010 DHD_ERROR(("%s(): Sync with dongle failed!!\n", __FUNCTION__));
6011 ret = -EFAULT;
6012 }
6013 } else {
6014 DHD_ERROR(("%s(): Failed to download, err=%d\n", __FUNCTION__, ret));
6015 }
6016 } else {
6017 DHD_ERROR(("%s(): BUS is already acquired, just increase the count %d \r\n",
6018 __FUNCTION__, dhd->bus_user_count));
6019 }
6020 exit:
6021 mutex_unlock(&dhd->bus_user_lock);
6022 return ret;
6023 }
6024 EXPORT_SYMBOL(dhd_bus_get);
6025
6026 /* Return values:
6027 * Success: Returns 0
6028 * Failure: Returns -1 or errono code
6029 */
6030 int
dhd_bus_put(wlan_bt_handle_t handle,bus_owner_t owner)6031 dhd_bus_put(wlan_bt_handle_t handle, bus_owner_t owner)
6032 {
6033 dhd_pub_t *dhdp = (dhd_pub_t *)handle;
6034 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
6035 int ret = 0;
6036 BCM_REFERENCE(owner);
6037
6038 mutex_lock(&dhd->bus_user_lock);
6039 --dhd->bus_user_count;
6040 if (dhd->bus_user_count < 0) {
6041 DHD_ERROR(("%s(): bus_user_count is negative, which is invalid\n", __FUNCTION__));
6042 dhd->bus_user_count = 0;
6043 ret = -1;
6044 goto exit;
6045 }
6046
6047 if (dhd->bus_user_count == 0) {
6048 /* Last user, stop the bus and turn Off WL_REG */
6049 DHD_ERROR(("%s(): There are no owners left Trunf Off WL_REG & stop the bus \r\n",
6050 __FUNCTION__));
6051 #ifdef PROP_TXSTATUS
6052 if (dhd->pub.wlfc_enabled) {
6053 dhd_wlfc_deinit(&dhd->pub);
6054 }
6055 #endif /* PROP_TXSTATUS */
6056 #ifdef PNO_SUPPORT
6057 if (dhd->pub.pno_state) {
6058 dhd_pno_deinit(&dhd->pub);
6059 }
6060 #endif /* PNO_SUPPORT */
6061 #ifdef RTT_SUPPORT
6062 if (dhd->pub.rtt_state) {
6063 dhd_rtt_deinit(&dhd->pub);
6064 }
6065 #endif /* RTT_SUPPORT */
6066 ret = dhd_bus_devreset(dhdp, TRUE);
6067 if (!ret) {
6068 dhd_bus_suspend(dhdp);
6069 wifi_platform_set_power(dhd->adapter, FALSE, WIFI_TURNOFF_DELAY);
6070 }
6071 } else {
6072 DHD_ERROR(("%s(): Other owners using bus, decrease the count %d \r\n",
6073 __FUNCTION__, dhd->bus_user_count));
6074 }
6075 exit:
6076 mutex_unlock(&dhd->bus_user_lock);
6077 return ret;
6078 }
6079 EXPORT_SYMBOL(dhd_bus_put);
6080
6081 int
dhd_net_bus_get(struct net_device * dev)6082 dhd_net_bus_get(struct net_device *dev)
6083 {
6084 dhd_info_t *dhd = DHD_DEV_INFO(dev);
6085 return dhd_bus_get(&dhd->pub, WLAN_MODULE);
6086 }
6087
6088 int
dhd_net_bus_put(struct net_device * dev)6089 dhd_net_bus_put(struct net_device *dev)
6090 {
6091 dhd_info_t *dhd = DHD_DEV_INFO(dev);
6092 return dhd_bus_put(&dhd->pub, WLAN_MODULE);
6093 }
6094
6095 /*
6096 * Function to enable the Bus Clock
6097 * Returns BCME_OK on success and BCME_xxx on failure
6098 *
6099 * This function is not callable from non-sleepable context
6100 */
dhd_bus_clk_enable(wlan_bt_handle_t handle,bus_owner_t owner)6101 int dhd_bus_clk_enable(wlan_bt_handle_t handle, bus_owner_t owner)
6102 {
6103 dhd_pub_t *dhdp = (dhd_pub_t *)handle;
6104
6105 int ret;
6106
6107 dhd_os_sdlock(dhdp);
6108 /*
6109 * The second argument is TRUE, that means, we expect
6110 * the function to "wait" until the clocks are really
6111 * available
6112 */
6113 ret = __dhdsdio_clk_enable(dhdp->bus, owner, TRUE);
6114 dhd_os_sdunlock(dhdp);
6115
6116 return ret;
6117 }
6118 EXPORT_SYMBOL(dhd_bus_clk_enable);
6119
6120 /*
6121 * Function to disable the Bus Clock
6122 * Returns BCME_OK on success and BCME_xxx on failure
6123 *
6124 * This function is not callable from non-sleepable context
6125 */
dhd_bus_clk_disable(wlan_bt_handle_t handle,bus_owner_t owner)6126 int dhd_bus_clk_disable(wlan_bt_handle_t handle, bus_owner_t owner)
6127 {
6128 dhd_pub_t *dhdp = (dhd_pub_t *)handle;
6129
6130 int ret;
6131
6132 dhd_os_sdlock(dhdp);
6133 /*
6134 * The second argument is TRUE, that means, we expect
6135 * the function to "wait" until the clocks are really
6136 * disabled
6137 */
6138 ret = __dhdsdio_clk_disable(dhdp->bus, owner, TRUE);
6139 dhd_os_sdunlock(dhdp);
6140
6141 return ret;
6142 }
6143 EXPORT_SYMBOL(dhd_bus_clk_disable);
6144
6145 /*
6146 * Function to reset bt_use_count counter to zero.
6147 *
6148 * This function is not callable from non-sleepable context
6149 */
dhd_bus_reset_bt_use_count(wlan_bt_handle_t handle)6150 void dhd_bus_reset_bt_use_count(wlan_bt_handle_t handle)
6151 {
6152 dhd_pub_t *dhdp = (dhd_pub_t *)handle;
6153
6154 /* take the lock and reset bt use count */
6155 dhd_os_sdlock(dhdp);
6156 dhdsdio_reset_bt_use_count(dhdp->bus);
6157 dhd_os_sdunlock(dhdp);
6158 }
6159 EXPORT_SYMBOL(dhd_bus_reset_bt_use_count);
6160
dhd_bus_retry_hang_recovery(wlan_bt_handle_t handle)6161 void dhd_bus_retry_hang_recovery(wlan_bt_handle_t handle)
6162 {
6163 dhd_pub_t *dhdp = (dhd_pub_t *)handle;
6164 dhd_info_t *dhd = (dhd_info_t*)dhdp->info;
6165
6166 dhdp->hang_was_sent = 0;
6167
6168 dhd_os_send_hang_message(&dhd->pub);
6169 }
6170 EXPORT_SYMBOL(dhd_bus_retry_hang_recovery);
6171
6172 #endif /* BT_OVER_SDIO */
6173
6174 static int
dhd_monitor_ioctl(struct net_device * dev,struct ifreq * ifr,int cmd)6175 dhd_monitor_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
6176 {
6177 return 0;
6178 }
6179
6180 static struct net_device_stats*
dhd_monitor_get_stats(struct net_device * dev)6181 dhd_monitor_get_stats(struct net_device *dev)
6182 {
6183 return &DHD_MON_DEV_STATS(dev);
6184 }
6185
6186 static const struct net_device_ops netdev_monitor_ops =
6187 {
6188 .ndo_start_xmit = dhd_monitor_start,
6189 .ndo_get_stats = dhd_monitor_get_stats,
6190 .ndo_do_ioctl = dhd_monitor_ioctl
6191 };
6192
6193 static void
dhd_add_monitor_if(dhd_info_t * dhd)6194 dhd_add_monitor_if(dhd_info_t *dhd)
6195 {
6196 struct net_device *dev;
6197 char *devname;
6198 uint32 scan_suppress = FALSE;
6199 int ret = BCME_OK;
6200
6201 if (!dhd) {
6202 DHD_ERROR(("%s: dhd info not available \n", __FUNCTION__));
6203 return;
6204 }
6205
6206 if (dhd->monitor_dev) {
6207 DHD_ERROR(("%s: monitor i/f already exists", __FUNCTION__));
6208 return;
6209 }
6210
6211 dev = alloc_etherdev(DHD_MON_DEV_PRIV_SIZE);
6212 if (!dev) {
6213 DHD_ERROR(("%s: alloc wlif failed\n", __FUNCTION__));
6214 return;
6215 }
6216
6217 devname = "radiotap";
6218
6219 snprintf(dev->name, sizeof(dev->name), "%s%u", devname, dhd->unit);
6220
6221 #ifndef ARPHRD_IEEE80211_PRISM /* From Linux 2.4.18 */
6222 #define ARPHRD_IEEE80211_PRISM 802
6223 #endif // endif
6224
6225 #ifndef ARPHRD_IEEE80211_RADIOTAP
6226 #define ARPHRD_IEEE80211_RADIOTAP 803 /* IEEE 802.11 + radiotap header */
6227 #endif /* ARPHRD_IEEE80211_RADIOTAP */
6228
6229 dev->type = ARPHRD_IEEE80211_RADIOTAP;
6230
6231 dev->netdev_ops = &netdev_monitor_ops;
6232
6233 if (register_netdevice(dev)) {
6234 DHD_ERROR(("%s, register_netdev failed for %s\n",
6235 __FUNCTION__, dev->name));
6236 free_netdev(dev);
6237 return;
6238 }
6239
6240 if (FW_SUPPORTED((&dhd->pub), monitor)) {
6241 scan_suppress = TRUE;
6242 /* Set the SCAN SUPPRESS Flag in the firmware to disable scan in Monitor mode */
6243 ret = dhd_iovar(&dhd->pub, 0, "scansuppress", (char *)&scan_suppress,
6244 sizeof(scan_suppress), NULL, 0, TRUE);
6245 if (ret < 0) {
6246 DHD_ERROR(("%s: scansuppress set failed, ret=%d\n", __FUNCTION__, ret));
6247 }
6248 }
6249
6250 dhd->monitor_dev = dev;
6251 }
6252
6253 static void
dhd_del_monitor_if(dhd_info_t * dhd)6254 dhd_del_monitor_if(dhd_info_t *dhd)
6255 {
6256 int ret = BCME_OK;
6257 uint32 scan_suppress = FALSE;
6258
6259 if (!dhd) {
6260 DHD_ERROR(("%s: dhd info not available \n", __FUNCTION__));
6261 return;
6262 }
6263
6264 if (!dhd->monitor_dev) {
6265 DHD_ERROR(("%s: monitor i/f doesn't exist", __FUNCTION__));
6266 return;
6267 }
6268
6269 if (FW_SUPPORTED((&dhd->pub), monitor)) {
6270 scan_suppress = FALSE;
6271 /* Unset the SCAN SUPPRESS Flag in the firmware to enable scan */
6272 ret = dhd_iovar(&dhd->pub, 0, "scansuppress", (char *)&scan_suppress,
6273 sizeof(scan_suppress), NULL, 0, TRUE);
6274 if (ret < 0) {
6275 DHD_ERROR(("%s: scansuppress set failed, ret=%d\n", __FUNCTION__, ret));
6276 }
6277 }
6278
6279 if (dhd->monitor_dev) {
6280 if (dhd->monitor_dev->reg_state == NETREG_UNINITIALIZED) {
6281 free_netdev(dhd->monitor_dev);
6282 } else {
6283 unregister_netdevice(dhd->monitor_dev);
6284 }
6285 dhd->monitor_dev = NULL;
6286 }
6287 }
6288
6289 void
dhd_set_monitor(dhd_pub_t * pub,int ifidx,int val)6290 dhd_set_monitor(dhd_pub_t *pub, int ifidx, int val)
6291 {
6292 dhd_info_t *dhd = pub->info;
6293
6294 DHD_TRACE(("%s: val %d\n", __FUNCTION__, val));
6295
6296 dhd_net_if_lock_local(dhd);
6297 if (!val) {
6298 /* Delete monitor */
6299 dhd_del_monitor_if(dhd);
6300 } else {
6301 /* Add monitor */
6302 dhd_add_monitor_if(dhd);
6303 }
6304 dhd->monitor_type = val;
6305 dhd_net_if_unlock_local(dhd);
6306 }
6307 #endif /* WL_MONITOR */
6308
6309 #if defined(DHD_H2D_LOG_TIME_SYNC)
6310 /*
6311 * Helper function:
6312 * Used for RTE console message time syncing with Host printk
6313 */
dhd_h2d_log_time_sync_deferred_wq_schedule(dhd_pub_t * dhdp)6314 void dhd_h2d_log_time_sync_deferred_wq_schedule(dhd_pub_t *dhdp)
6315 {
6316 dhd_info_t *info = dhdp->info;
6317
6318 /* Ideally the "state" should be always TRUE */
6319 dhd_deferred_schedule_work(info->dhd_deferred_wq, NULL,
6320 DHD_WQ_WORK_H2D_CONSOLE_TIME_STAMP_MATCH,
6321 dhd_deferred_work_rte_log_time_sync,
6322 DHD_WQ_WORK_PRIORITY_LOW);
6323 }
6324
6325 void
dhd_deferred_work_rte_log_time_sync(void * handle,void * event_info,u8 event)6326 dhd_deferred_work_rte_log_time_sync(void *handle, void *event_info, u8 event)
6327 {
6328 dhd_info_t *dhd_info = handle;
6329 dhd_pub_t *dhd;
6330
6331 if (event != DHD_WQ_WORK_H2D_CONSOLE_TIME_STAMP_MATCH) {
6332 DHD_ERROR(("%s: unexpected event \n", __FUNCTION__));
6333 return;
6334 }
6335
6336 if (!dhd_info) {
6337 DHD_ERROR(("%s: dhd info not available \n", __FUNCTION__));
6338 return;
6339 }
6340
6341 dhd = &dhd_info->pub;
6342
6343 /*
6344 * Function to send IOVAR for console timesyncing
6345 * between Host and Dongle.
6346 * If the IOVAR fails,
6347 * 1. dhd_rte_time_sync_ms is set to 0 and
6348 * 2. HOST Dongle console time sync will *not* happen.
6349 */
6350 dhd_h2d_log_time_sync(dhd);
6351 }
6352 #endif /* DHD_H2D_LOG_TIME_SYNC */
6353
dhd_ioctl_process(dhd_pub_t * pub,int ifidx,dhd_ioctl_t * ioc,void * data_buf)6354 int dhd_ioctl_process(dhd_pub_t *pub, int ifidx, dhd_ioctl_t *ioc, void *data_buf)
6355 {
6356 int bcmerror = BCME_OK;
6357 int buflen = 0;
6358 struct net_device *net;
6359
6360 net = dhd_idx2net(pub, ifidx);
6361 if (!net) {
6362 bcmerror = BCME_BADARG;
6363 /*
6364 * The netdev pointer is bad means the DHD can't communicate
6365 * to higher layers, so just return from here
6366 */
6367 return bcmerror;
6368 }
6369
6370 /* check for local dhd ioctl and handle it */
6371 if (ioc->driver == DHD_IOCTL_MAGIC) {
6372 /* This is a DHD IOVAR, truncate buflen to DHD_IOCTL_MAXLEN */
6373 if (data_buf)
6374 buflen = MIN(ioc->len, DHD_IOCTL_MAXLEN);
6375 bcmerror = dhd_ioctl((void *)pub, ioc, data_buf, buflen);
6376 if (bcmerror)
6377 pub->bcmerror = bcmerror;
6378 goto done;
6379 }
6380
6381 /* This is a WL IOVAR, truncate buflen to WLC_IOCTL_MAXLEN */
6382 if (data_buf)
6383 buflen = MIN(ioc->len, WLC_IOCTL_MAXLEN);
6384
6385 #ifndef BCMDBUS
6386 /* send to dongle (must be up, and wl). */
6387 if (pub->busstate == DHD_BUS_DOWN || pub->busstate == DHD_BUS_LOAD) {
6388 if ((!pub->dongle_trap_occured) && allow_delay_fwdl) {
6389 int ret;
6390 if (atomic_read(&exit_in_progress)) {
6391 DHD_ERROR(("%s module exit in progress\n", __func__));
6392 bcmerror = BCME_DONGLE_DOWN;
6393 goto done;
6394 }
6395 ret = dhd_bus_start(pub);
6396 if (ret != 0) {
6397 DHD_ERROR(("%s: failed with code %d\n", __FUNCTION__, ret));
6398 bcmerror = BCME_DONGLE_DOWN;
6399 goto done;
6400 }
6401 } else {
6402 bcmerror = BCME_DONGLE_DOWN;
6403 goto done;
6404 }
6405 }
6406
6407 if (!pub->iswl) {
6408 bcmerror = BCME_DONGLE_DOWN;
6409 goto done;
6410 }
6411 #endif /* !BCMDBUS */
6412
6413 /*
6414 * Flush the TX queue if required for proper message serialization:
6415 * Intercept WLC_SET_KEY IOCTL - serialize M4 send and set key IOCTL to
6416 * prevent M4 encryption and
6417 * intercept WLC_DISASSOC IOCTL - serialize WPS-DONE and WLC_DISASSOC IOCTL to
6418 * prevent disassoc frame being sent before WPS-DONE frame.
6419 */
6420 if (ioc->cmd == WLC_SET_KEY ||
6421 (ioc->cmd == WLC_SET_VAR && data_buf != NULL &&
6422 strncmp("wsec_key", data_buf, 9) == 0) ||
6423 (ioc->cmd == WLC_SET_VAR && data_buf != NULL &&
6424 strncmp("bsscfg:wsec_key", data_buf, 15) == 0) ||
6425 ioc->cmd == WLC_DISASSOC)
6426 dhd_wait_pend8021x(net);
6427
6428 if ((ioc->cmd == WLC_SET_VAR || ioc->cmd == WLC_GET_VAR) &&
6429 data_buf != NULL && strncmp("rpc_", data_buf, 4) == 0) {
6430 bcmerror = BCME_UNSUPPORTED;
6431 goto done;
6432 }
6433
6434 bcmerror = dhd_wl_ioctl(pub, ifidx, (wl_ioctl_t *)ioc, data_buf, buflen);
6435
6436 done:
6437 dhd_check_hang(net, pub, bcmerror);
6438
6439 return bcmerror;
6440 }
6441
6442 /**
6443 * Called by the OS (optionally via a wrapper function).
6444 * @param net Linux per dongle instance
6445 * @param ifr Linux request structure
6446 * @param cmd e.g. SIOCETHTOOL
6447 */
6448 static int
dhd_ioctl_entry(struct net_device * net,struct ifreq * ifr,int cmd)6449 dhd_ioctl_entry(struct net_device *net, struct ifreq *ifr, int cmd)
6450 {
6451 dhd_info_t *dhd = DHD_DEV_INFO(net);
6452 dhd_ioctl_t ioc;
6453 int bcmerror = 0;
6454 int ifidx;
6455 int ret;
6456 void *local_buf = NULL; /**< buffer in kernel space */
6457 void __user *ioc_buf_user = NULL; /**< buffer in user space */
6458 u16 buflen = 0;
6459
6460 if (atomic_read(&exit_in_progress)) {
6461 DHD_ERROR(("%s module exit in progress\n", __func__));
6462 bcmerror = BCME_DONGLE_DOWN;
6463 return OSL_ERROR(bcmerror);
6464 }
6465
6466 DHD_OS_WAKE_LOCK(&dhd->pub);
6467 DHD_PERIM_LOCK(&dhd->pub);
6468
6469 /* Interface up check for built-in type */
6470 if (!dhd_download_fw_on_driverload && dhd->pub.up == FALSE) {
6471 DHD_ERROR(("%s: Interface is down \n", __FUNCTION__));
6472 DHD_PERIM_UNLOCK(&dhd->pub);
6473 DHD_OS_WAKE_UNLOCK(&dhd->pub);
6474 return OSL_ERROR(BCME_NOTUP);
6475 }
6476
6477 ifidx = dhd_net2idx(dhd, net);
6478 DHD_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __FUNCTION__, ifidx, cmd));
6479
6480 #if defined(WL_STATIC_IF)
6481 /* skip for static ndev when it is down */
6482 if (dhd_is_static_ndev(&dhd->pub, net) && !(net->flags & IFF_UP)) {
6483 DHD_PERIM_UNLOCK(&dhd->pub);
6484 DHD_OS_WAKE_UNLOCK(&dhd->pub);
6485 return -1;
6486 }
6487 #endif /* WL_STATIC_iF */
6488
6489 if (ifidx == DHD_BAD_IF) {
6490 DHD_ERROR(("%s: BAD IF\n", __FUNCTION__));
6491 DHD_PERIM_UNLOCK(&dhd->pub);
6492 DHD_OS_WAKE_UNLOCK(&dhd->pub);
6493 return -1;
6494 }
6495
6496 #if defined(WL_WIRELESS_EXT)
6497 /* linux wireless extensions */
6498 if ((cmd >= SIOCIWFIRST) && (cmd <= SIOCIWLAST)) {
6499 /* may recurse, do NOT lock */
6500 ret = wl_iw_ioctl(net, ifr, cmd);
6501 DHD_PERIM_UNLOCK(&dhd->pub);
6502 DHD_OS_WAKE_UNLOCK(&dhd->pub);
6503 return ret;
6504 }
6505 #endif /* defined(WL_WIRELESS_EXT) */
6506
6507 if (cmd == SIOCETHTOOL) {
6508 ret = dhd_ethtool(dhd, (void*)ifr->ifr_data);
6509 DHD_PERIM_UNLOCK(&dhd->pub);
6510 DHD_OS_WAKE_UNLOCK(&dhd->pub);
6511 return ret;
6512 }
6513
6514 if (cmd == SIOCDEVPRIVATE+1) {
6515 ret = wl_android_priv_cmd(net, ifr);
6516 dhd_check_hang(net, &dhd->pub, ret);
6517 DHD_PERIM_UNLOCK(&dhd->pub);
6518 DHD_OS_WAKE_UNLOCK(&dhd->pub);
6519 return ret;
6520 }
6521
6522 if (cmd != SIOCDEVPRIVATE) {
6523 DHD_PERIM_UNLOCK(&dhd->pub);
6524 DHD_OS_WAKE_UNLOCK(&dhd->pub);
6525 return -EOPNOTSUPP;
6526 }
6527
6528 memset(&ioc, 0, sizeof(ioc));
6529
6530 #ifdef CONFIG_COMPAT
6531 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0))
6532 if (in_compat_syscall())
6533 #else
6534 if (is_compat_task())
6535 #endif /* LINUX_VER >= 4.6 */
6536 {
6537 compat_wl_ioctl_t compat_ioc;
6538 if (copy_from_user(&compat_ioc, ifr->ifr_data, sizeof(compat_wl_ioctl_t))) {
6539 bcmerror = BCME_BADADDR;
6540 goto done;
6541 }
6542 ioc.cmd = compat_ioc.cmd;
6543 if (ioc.cmd & WLC_SPEC_FLAG) {
6544 memset(&ioc, 0, sizeof(ioc));
6545 /* Copy the ioc control structure part of ioctl request */
6546 if (copy_from_user(&ioc, ifr->ifr_data, sizeof(wl_ioctl_t))) {
6547 bcmerror = BCME_BADADDR;
6548 goto done;
6549 }
6550 ioc.cmd &= ~WLC_SPEC_FLAG; /* Clear the FLAG */
6551
6552 /* To differentiate between wl and dhd read 4 more byes */
6553 if ((copy_from_user(&ioc.driver, (char *)ifr->ifr_data + sizeof(wl_ioctl_t),
6554 sizeof(uint)) != 0)) {
6555 bcmerror = BCME_BADADDR;
6556 goto done;
6557 }
6558
6559 } else { /* ioc.cmd & WLC_SPEC_FLAG */
6560 ioc.buf = compat_ptr(compat_ioc.buf);
6561 ioc.len = compat_ioc.len;
6562 ioc.set = compat_ioc.set;
6563 ioc.used = compat_ioc.used;
6564 ioc.needed = compat_ioc.needed;
6565 /* To differentiate between wl and dhd read 4 more byes */
6566 if ((copy_from_user(&ioc.driver, (char *)ifr->ifr_data + sizeof(compat_wl_ioctl_t),
6567 sizeof(uint)) != 0)) {
6568 bcmerror = BCME_BADADDR;
6569 goto done;
6570 }
6571 } /* ioc.cmd & WLC_SPEC_FLAG */
6572 } else
6573 #endif /* CONFIG_COMPAT */
6574 {
6575 /* Copy the ioc control structure part of ioctl request */
6576 if (copy_from_user(&ioc, ifr->ifr_data, sizeof(wl_ioctl_t))) {
6577 bcmerror = BCME_BADADDR;
6578 goto done;
6579 }
6580 #ifdef CONFIG_COMPAT
6581 ioc.cmd &= ~WLC_SPEC_FLAG; /* make sure it was clear when it isn't a compat task*/
6582 #endif
6583
6584 /* To differentiate between wl and dhd read 4 more byes */
6585 if ((copy_from_user(&ioc.driver, (char *)ifr->ifr_data + sizeof(wl_ioctl_t),
6586 sizeof(uint)) != 0)) {
6587 bcmerror = BCME_BADADDR;
6588 goto done;
6589 }
6590 }
6591
6592 #ifndef CONFIG_VTS_SUPPORT
6593 if (!capable(CAP_NET_ADMIN)) {
6594 bcmerror = BCME_EPERM;
6595 goto done;
6596 }
6597 #endif
6598
6599 /* Take backup of ioc.buf and restore later */
6600 ioc_buf_user = ioc.buf;
6601
6602 if (ioc.len > 0) {
6603 buflen = MIN(ioc.len, DHD_IOCTL_MAXLEN);
6604 if (!(local_buf = MALLOC(dhd->pub.osh, buflen+1))) {
6605 bcmerror = BCME_NOMEM;
6606 goto done;
6607 }
6608
6609 DHD_PERIM_UNLOCK(&dhd->pub);
6610 if (copy_from_user(local_buf, ioc.buf, buflen)) {
6611 DHD_PERIM_LOCK(&dhd->pub);
6612 bcmerror = BCME_BADADDR;
6613 goto done;
6614 }
6615 DHD_PERIM_LOCK(&dhd->pub);
6616
6617 *((char *)local_buf + buflen) = '\0';
6618
6619 /* For some platforms accessing userspace memory
6620 * of ioc.buf is causing kernel panic, so to avoid that
6621 * make ioc.buf pointing to kernel space memory local_buf
6622 */
6623 ioc.buf = local_buf;
6624 }
6625
6626 /* Skip all the non DHD iovars (wl iovars) after f/w hang */
6627 if (ioc.driver != DHD_IOCTL_MAGIC && dhd->pub.hang_was_sent) {
6628 DHD_TRACE(("%s: HANG was sent up earlier\n", __FUNCTION__));
6629 DHD_OS_WAKE_LOCK_CTRL_TIMEOUT_ENABLE(&dhd->pub, DHD_EVENT_TIMEOUT_MS);
6630 bcmerror = BCME_DONGLE_DOWN;
6631 goto done;
6632 }
6633
6634 bcmerror = dhd_ioctl_process(&dhd->pub, ifidx, &ioc, local_buf);
6635
6636 /* Restore back userspace pointer to ioc.buf */
6637 ioc.buf = ioc_buf_user;
6638
6639 if (!bcmerror && buflen && local_buf && ioc.buf) {
6640 DHD_PERIM_UNLOCK(&dhd->pub);
6641 if (copy_to_user(ioc.buf, local_buf, buflen))
6642 bcmerror = -EFAULT;
6643 DHD_PERIM_LOCK(&dhd->pub);
6644 }
6645
6646 done:
6647 if (local_buf)
6648 MFREE(dhd->pub.osh, local_buf, buflen+1);
6649
6650 DHD_PERIM_UNLOCK(&dhd->pub);
6651 DHD_OS_WAKE_UNLOCK(&dhd->pub);
6652
6653 return OSL_ERROR(bcmerror);
6654 }
6655
6656 #if defined(WL_CFG80211) && defined(SUPPORT_DEEP_SLEEP)
6657 /* Flags to indicate if we distingish power off policy when
6658 * user set the memu "Keep Wi-Fi on during sleep" to "Never"
6659 */
6660 int trigger_deep_sleep = 0;
6661 #endif /* WL_CFG80211 && SUPPORT_DEEP_SLEEP */
6662
6663 #ifdef FIX_CPU_MIN_CLOCK
dhd_init_cpufreq_fix(dhd_info_t * dhd)6664 static int dhd_init_cpufreq_fix(dhd_info_t *dhd)
6665 {
6666 if (dhd) {
6667 mutex_init(&dhd->cpufreq_fix);
6668 dhd->cpufreq_fix_status = FALSE;
6669 }
6670 return 0;
6671 }
6672
dhd_fix_cpu_freq(dhd_info_t * dhd)6673 static void dhd_fix_cpu_freq(dhd_info_t *dhd)
6674 {
6675 mutex_lock(&dhd->cpufreq_fix);
6676 if (dhd && !dhd->cpufreq_fix_status) {
6677 pm_qos_add_request(&dhd->dhd_cpu_qos, PM_QOS_CPU_FREQ_MIN, 300000);
6678 #ifdef FIX_BUS_MIN_CLOCK
6679 pm_qos_add_request(&dhd->dhd_bus_qos, PM_QOS_BUS_THROUGHPUT, 400000);
6680 #endif /* FIX_BUS_MIN_CLOCK */
6681 DHD_ERROR(("pm_qos_add_requests called\n"));
6682
6683 dhd->cpufreq_fix_status = TRUE;
6684 }
6685 mutex_unlock(&dhd->cpufreq_fix);
6686 }
6687
dhd_rollback_cpu_freq(dhd_info_t * dhd)6688 static void dhd_rollback_cpu_freq(dhd_info_t *dhd)
6689 {
6690 mutex_lock(&dhd ->cpufreq_fix);
6691 if (dhd && dhd->cpufreq_fix_status != TRUE) {
6692 mutex_unlock(&dhd->cpufreq_fix);
6693 return;
6694 }
6695
6696 pm_qos_remove_request(&dhd->dhd_cpu_qos);
6697 #ifdef FIX_BUS_MIN_CLOCK
6698 pm_qos_remove_request(&dhd->dhd_bus_qos);
6699 #endif /* FIX_BUS_MIN_CLOCK */
6700 DHD_ERROR(("pm_qos_add_requests called\n"));
6701
6702 dhd->cpufreq_fix_status = FALSE;
6703 mutex_unlock(&dhd->cpufreq_fix);
6704 }
6705 #endif /* FIX_CPU_MIN_CLOCK */
6706
6707 #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
6708 static int
dhd_ioctl_entry_wrapper(struct net_device * net,struct ifreq * ifr,int cmd)6709 dhd_ioctl_entry_wrapper(struct net_device *net, struct ifreq *ifr, int cmd)
6710 {
6711 int error;
6712 dhd_info_t *dhd = DHD_DEV_INFO(net);
6713
6714 if (atomic_read(&dhd->pub.block_bus))
6715 return -EHOSTDOWN;
6716
6717 if (pm_runtime_get_sync(dhd_bus_to_dev(dhd->pub.bus)) < 0)
6718 return BCME_ERROR;
6719
6720 error = dhd_ioctl_entry(net, ifr, cmd);
6721
6722 pm_runtime_mark_last_busy(dhd_bus_to_dev(dhd->pub.bus));
6723 pm_runtime_put_autosuspend(dhd_bus_to_dev(dhd->pub.bus));
6724
6725 return error;
6726 }
6727 #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
6728
6729 static int
dhd_stop(struct net_device * net)6730 dhd_stop(struct net_device *net)
6731 {
6732 int ifidx = 0;
6733 bool skip_reset = false;
6734 #if defined(WL_CFG80211)
6735 unsigned long flags = 0;
6736 #ifdef WL_STATIC_IF
6737 struct bcm_cfg80211 *cfg = wl_get_cfg(net);
6738 #endif /* WL_STATIC_IF */
6739 #endif /* WL_CFG80211 */
6740 dhd_info_t *dhd = DHD_DEV_INFO(net);
6741 DHD_OS_WAKE_LOCK(&dhd->pub);
6742 DHD_PERIM_LOCK(&dhd->pub);
6743 printf("%s: Enter %s\n", __FUNCTION__, net->name);
6744 dhd->pub.rxcnt_timeout = 0;
6745 dhd->pub.txcnt_timeout = 0;
6746
6747 #ifdef BCMPCIE
6748 dhd->pub.d3ackcnt_timeout = 0;
6749 #endif /* BCMPCIE */
6750
6751 mutex_lock(&dhd->pub.ndev_op_sync);
6752
6753 if (dhd->pub.up == 0) {
6754 goto exit;
6755 }
6756
6757 dhd_if_flush_sta(DHD_DEV_IFP(net));
6758
6759 #ifdef FIX_CPU_MIN_CLOCK
6760 if (dhd_get_fw_mode(dhd) == DHD_FLAG_HOSTAP_MODE)
6761 dhd_rollback_cpu_freq(dhd);
6762 #endif /* FIX_CPU_MIN_CLOCK */
6763
6764 ifidx = dhd_net2idx(dhd, net);
6765 BCM_REFERENCE(ifidx);
6766
6767 DHD_ERROR(("%s: ######### dhd_stop called for ifidx=%d #########\n", __FUNCTION__, ifidx));
6768
6769 #if defined(WL_STATIC_IF) && defined(WL_CFG80211)
6770 /* If static if is operational, don't reset the chip */
6771 if (IS_CFG80211_STATIC_IF_ACTIVE(cfg)) {
6772 DHD_ERROR(("static if operational. skip chip reset.\n"));
6773 skip_reset = true;
6774 wl_cfg80211_sta_ifdown(net);
6775 goto exit;
6776 }
6777 #endif /* WL_STATIC_IF && WL_CFG80211 */
6778 #ifdef DHD_NOTIFY_MAC_CHANGED
6779 if (dhd->pub.skip_dhd_stop) {
6780 WL_MSG(net->name, "skip chip reset.\n");
6781 skip_reset = true;
6782 #if defined(WL_CFG80211)
6783 wl_cfg80211_sta_ifdown(net);
6784 #endif /* WL_CFG80211 */
6785 goto exit;
6786 }
6787 #endif /* DHD_NOTIFY_MAC_CHANGED */
6788
6789 DHD_ERROR(("%s: making dhdpub up FALSE\n", __FUNCTION__));
6790 #ifdef WL_CFG80211
6791
6792 /* Disable Runtime PM before interface down */
6793 DHD_DISABLE_RUNTIME_PM(&dhd->pub);
6794
6795 spin_lock_irqsave(&dhd->pub.up_lock, flags);
6796 dhd->pub.up = 0;
6797 spin_unlock_irqrestore(&dhd->pub.up_lock, flags);
6798 #else
6799 dhd->pub.up = 0;
6800 #endif /* WL_CFG80211 */
6801
6802 #ifdef WL_CFG80211
6803 if (ifidx == 0) {
6804 dhd_if_t *ifp;
6805 wl_cfg80211_down(net);
6806
6807 ifp = dhd->iflist[0];
6808 /*
6809 * For CFG80211: Clean up all the left over virtual interfaces
6810 * when the primary Interface is brought down. [ifconfig wlan0 down]
6811 */
6812 if (!dhd_download_fw_on_driverload) {
6813 DHD_STATLOG_CTRL(&dhd->pub, ST(WLAN_POWER_OFF), ifidx, 0);
6814 if ((dhd->dhd_state & DHD_ATTACH_STATE_ADD_IF) &&
6815 (dhd->dhd_state & DHD_ATTACH_STATE_CFG80211)) {
6816 int i;
6817 #ifdef WL_CFG80211_P2P_DEV_IF
6818 wl_cfg80211_del_p2p_wdev(net);
6819 #endif /* WL_CFG80211_P2P_DEV_IF */
6820 #ifdef DHD_4WAYM4_FAIL_DISCONNECT
6821 dhd_cleanup_m4_state_work(&dhd->pub, ifidx);
6822 #endif /* DHD_4WAYM4_FAIL_DISCONNECT */
6823 #ifdef DHD_PKTDUMP_ROAM
6824 dhd_dump_pkt_clear(&dhd->pub);
6825 #endif /* DHD_PKTDUMP_ROAM */
6826
6827 dhd_net_if_lock_local(dhd);
6828 for (i = 1; i < DHD_MAX_IFS; i++)
6829 dhd_remove_if(&dhd->pub, i, FALSE);
6830
6831 if (ifp && ifp->net) {
6832 dhd_if_del_sta_list(ifp);
6833 }
6834 #ifdef ARP_OFFLOAD_SUPPORT
6835 if (dhd_inetaddr_notifier_registered) {
6836 dhd_inetaddr_notifier_registered = FALSE;
6837 unregister_inetaddr_notifier(&dhd_inetaddr_notifier);
6838 }
6839 #endif /* ARP_OFFLOAD_SUPPORT */
6840 #if defined(CONFIG_IPV6) && defined(IPV6_NDO_SUPPORT)
6841 if (dhd_inet6addr_notifier_registered) {
6842 dhd_inet6addr_notifier_registered = FALSE;
6843 unregister_inet6addr_notifier(&dhd_inet6addr_notifier);
6844 }
6845 #endif /* CONFIG_IPV6 && IPV6_NDO_SUPPORT */
6846 dhd_net_if_unlock_local(dhd);
6847 }
6848 #if 0
6849 // terence 20161024: remove this to prevent dev_close() get stuck in dhd_hang_process
6850 cancel_work_sync(dhd->dhd_deferred_wq);
6851 #endif
6852
6853 #ifdef SHOW_LOGTRACE
6854 /* Wait till event logs work/kthread finishes */
6855 dhd_cancel_logtrace_process_sync(dhd);
6856 #endif /* SHOW_LOGTRACE */
6857
6858 #if defined(DHD_LB_RXP)
6859 __skb_queue_purge(&dhd->rx_pend_queue);
6860 #endif /* DHD_LB_RXP */
6861
6862 #if defined(DHD_LB_TXP)
6863 skb_queue_purge(&dhd->tx_pend_queue);
6864 #endif /* DHD_LB_TXP */
6865 }
6866
6867 #if defined(ARGOS_NOTIFY_CB)
6868 argos_register_notifier_deinit();
6869 #endif // endif
6870 #ifdef DHDTCPACK_SUPPRESS
6871 dhd_tcpack_suppress_set(&dhd->pub, TCPACK_SUP_OFF);
6872 #endif /* DHDTCPACK_SUPPRESS */
6873 #if defined(DHD_LB_RXP)
6874 if (ifp && ifp->net == dhd->rx_napi_netdev) {
6875 DHD_INFO(("%s napi<%p> disabled ifp->net<%p,%s>\n",
6876 __FUNCTION__, &dhd->rx_napi_struct, net, net->name));
6877 skb_queue_purge(&dhd->rx_napi_queue);
6878 napi_disable(&dhd->rx_napi_struct);
6879 netif_napi_del(&dhd->rx_napi_struct);
6880 dhd->rx_napi_netdev = NULL;
6881 }
6882 #endif /* DHD_LB_RXP */
6883 }
6884 #endif /* WL_CFG80211 */
6885
6886 DHD_SSSR_DUMP_DEINIT(&dhd->pub);
6887
6888 #ifdef PROP_TXSTATUS
6889 dhd_wlfc_cleanup(&dhd->pub, NULL, 0);
6890 #endif // endif
6891 #ifdef SHOW_LOGTRACE
6892 if (!dhd_download_fw_on_driverload) {
6893 /* Release the skbs from queue for WLC_E_TRACE event */
6894 dhd_event_logtrace_flush_queue(&dhd->pub);
6895 if (dhd->dhd_state & DHD_ATTACH_LOGTRACE_INIT) {
6896 if (dhd->event_data.fmts) {
6897 MFREE(dhd->pub.osh, dhd->event_data.fmts,
6898 dhd->event_data.fmts_size);
6899 dhd->event_data.fmts = NULL;
6900 }
6901 if (dhd->event_data.raw_fmts) {
6902 MFREE(dhd->pub.osh, dhd->event_data.raw_fmts,
6903 dhd->event_data.raw_fmts_size);
6904 dhd->event_data.raw_fmts = NULL;
6905 }
6906 if (dhd->event_data.raw_sstr) {
6907 MFREE(dhd->pub.osh, dhd->event_data.raw_sstr,
6908 dhd->event_data.raw_sstr_size);
6909 dhd->event_data.raw_sstr = NULL;
6910 }
6911 if (dhd->event_data.rom_raw_sstr) {
6912 MFREE(dhd->pub.osh, dhd->event_data.rom_raw_sstr,
6913 dhd->event_data.rom_raw_sstr_size);
6914 dhd->event_data.rom_raw_sstr = NULL;
6915 }
6916 dhd->dhd_state &= ~DHD_ATTACH_LOGTRACE_INIT;
6917 }
6918 }
6919 #endif /* SHOW_LOGTRACE */
6920 #ifdef APF
6921 dhd_dev_apf_delete_filter(net);
6922 #endif /* APF */
6923
6924 /* Stop the protocol module */
6925 dhd_prot_stop(&dhd->pub);
6926
6927 OLD_MOD_DEC_USE_COUNT;
6928 exit:
6929 if (skip_reset == false) {
6930 #if defined(WL_WIRELESS_EXT)
6931 if (ifidx == 0) {
6932 wl_iw_down(net, &dhd->pub);
6933 }
6934 #endif /* defined(WL_WIRELESS_EXT) */
6935 #ifdef WL_ESCAN
6936 if (ifidx == 0) {
6937 wl_escan_down(net, &dhd->pub);
6938 }
6939 #endif /* WL_ESCAN */
6940 if (ifidx == 0 && !dhd_download_fw_on_driverload) {
6941 #if defined(BT_OVER_SDIO)
6942 dhd_bus_put(&dhd->pub, WLAN_MODULE);
6943 wl_android_set_wifi_on_flag(FALSE);
6944 #else
6945 wl_android_wifi_off(net, TRUE);
6946 #if defined(WL_EXT_IAPSTA) || defined(USE_IW) || defined(WL_ESCAN)
6947 #ifdef WL_EXT_IAPSTA
6948 wl_ext_iapsta_dettach_netdev(net, ifidx);
6949 #endif /* WL_EXT_IAPSTA */
6950 #ifdef WL_ESCAN
6951 wl_escan_event_dettach(net, &dhd->pub);
6952 #endif /* WL_ESCAN */
6953 wl_ext_event_dettach_netdev(net, ifidx);
6954 #endif /* WL_EXT_IAPSTA || USE_IW || WL_ESCAN */
6955 #endif /* BT_OVER_SDIO */
6956 }
6957 #ifdef SUPPORT_DEEP_SLEEP
6958 else {
6959 /* CSP#505233: Flags to indicate if we distingish
6960 * power off policy when user set the memu
6961 * "Keep Wi-Fi on during sleep" to "Never"
6962 */
6963 if (trigger_deep_sleep) {
6964 dhd_deepsleep(net, 1);
6965 trigger_deep_sleep = 0;
6966 }
6967 }
6968 #endif /* SUPPORT_DEEP_SLEEP */
6969 dhd->pub.hang_was_sent = 0;
6970 dhd->pub.hang_was_pending = 0;
6971
6972 /* Clear country spec for for built-in type driver */
6973 if (!dhd_download_fw_on_driverload) {
6974 dhd->pub.dhd_cspec.country_abbrev[0] = 0x00;
6975 dhd->pub.dhd_cspec.rev = 0;
6976 dhd->pub.dhd_cspec.ccode[0] = 0x00;
6977 }
6978
6979 #ifdef BCMDBGFS
6980 dhd_dbgfs_remove();
6981 #endif // endif
6982 }
6983
6984 DHD_PERIM_UNLOCK(&dhd->pub);
6985 DHD_OS_WAKE_UNLOCK(&dhd->pub);
6986
6987 /* Destroy wakelock */
6988 if (!dhd_download_fw_on_driverload &&
6989 (dhd->dhd_state & DHD_ATTACH_STATE_WAKELOCKS_INIT) &&
6990 (skip_reset == false)) {
6991 DHD_OS_WAKE_LOCK_DESTROY(dhd);
6992 dhd->dhd_state &= ~DHD_ATTACH_STATE_WAKELOCKS_INIT;
6993 }
6994 printf("%s: Exit %s\n", __FUNCTION__, net->name);
6995
6996 mutex_unlock(&dhd->pub.ndev_op_sync);
6997 return 0;
6998 }
6999
7000 #if defined(WL_CFG80211) && (defined(USE_INITIAL_2G_SCAN) || \
7001 defined(USE_INITIAL_SHORT_DWELL_TIME))
7002 extern bool g_first_broadcast_scan;
7003 #endif /* OEM_ANDROID && WL_CFG80211 && (USE_INITIAL_2G_SCAN || USE_INITIAL_SHORT_DWELL_TIME) */
7004
7005 #ifdef WL11U
dhd_interworking_enable(dhd_pub_t * dhd)7006 static int dhd_interworking_enable(dhd_pub_t *dhd)
7007 {
7008 uint32 enable = true;
7009 int ret = BCME_OK;
7010
7011 ret = dhd_iovar(dhd, 0, "interworking", (char *)&enable, sizeof(enable), NULL, 0, TRUE);
7012 if (ret < 0) {
7013 DHD_ERROR(("%s: enableing interworking failed, ret=%d\n", __FUNCTION__, ret));
7014 }
7015
7016 return ret;
7017 }
7018 #endif /* WL11u */
7019
7020 static int
dhd_open(struct net_device * net)7021 dhd_open(struct net_device *net)
7022 {
7023 dhd_info_t *dhd = DHD_DEV_INFO(net);
7024 #ifdef TOE
7025 uint32 toe_ol;
7026 #endif // endif
7027 int ifidx;
7028 int32 ret = 0;
7029 #if defined(OOB_INTR_ONLY)
7030 uint32 bus_type = -1;
7031 uint32 bus_num = -1;
7032 uint32 slot_num = -1;
7033 wifi_adapter_info_t *adapter = NULL;
7034 #endif
7035 #if defined(WL_EXT_IAPSTA) && defined(ISAM_PREINIT)
7036 int bytes_written = 0;
7037 #endif
7038
7039 mutex_lock(&dhd->pub.ndev_op_sync);
7040
7041 if (dhd->pub.up == 1) {
7042 /* already up */
7043 DHD_ERROR(("Primary net_device is already up \n"));
7044 mutex_unlock(&dhd->pub.ndev_op_sync);
7045 return BCME_OK;
7046 }
7047
7048 if (!dhd_download_fw_on_driverload) {
7049 if (!dhd_driver_init_done) {
7050 DHD_ERROR(("%s: WLAN driver is not initialized\n", __FUNCTION__));
7051 mutex_unlock(&dhd->pub.ndev_op_sync);
7052 return -1;
7053 }
7054 }
7055
7056 printf("%s: Enter %s\n", __FUNCTION__, net->name);
7057 DHD_MUTEX_LOCK();
7058 /* Init wakelock */
7059 if (!dhd_download_fw_on_driverload) {
7060 if (!(dhd->dhd_state & DHD_ATTACH_STATE_WAKELOCKS_INIT)) {
7061 DHD_OS_WAKE_LOCK_INIT(dhd);
7062 dhd->dhd_state |= DHD_ATTACH_STATE_WAKELOCKS_INIT;
7063 }
7064
7065 #ifdef SHOW_LOGTRACE
7066 skb_queue_head_init(&dhd->evt_trace_queue);
7067
7068 if (!(dhd->dhd_state & DHD_ATTACH_LOGTRACE_INIT)) {
7069 ret = dhd_init_logstrs_array(dhd->pub.osh, &dhd->event_data);
7070 if (ret == BCME_OK) {
7071 dhd_init_static_strs_array(dhd->pub.osh, &dhd->event_data,
7072 st_str_file_path, map_file_path);
7073 dhd_init_static_strs_array(dhd->pub.osh, &dhd->event_data,
7074 rom_st_str_file_path, rom_map_file_path);
7075 dhd->dhd_state |= DHD_ATTACH_LOGTRACE_INIT;
7076 }
7077 }
7078 #endif /* SHOW_LOGTRACE */
7079 }
7080
7081 DHD_OS_WAKE_LOCK(&dhd->pub);
7082 DHD_PERIM_LOCK(&dhd->pub);
7083 dhd->pub.dongle_trap_occured = 0;
7084 dhd->pub.hang_was_sent = 0;
7085 dhd->pub.hang_was_pending = 0;
7086 dhd->pub.hang_reason = 0;
7087 dhd->pub.iovar_timeout_occured = 0;
7088 #ifdef PCIE_FULL_DONGLE
7089 dhd->pub.d3ack_timeout_occured = 0;
7090 dhd->pub.livelock_occured = 0;
7091 dhd->pub.pktid_audit_failed = 0;
7092 #endif /* PCIE_FULL_DONGLE */
7093 dhd->pub.iface_op_failed = 0;
7094 dhd->pub.scan_timeout_occurred = 0;
7095 dhd->pub.scan_busy_occurred = 0;
7096 dhd->pub.smmu_fault_occurred = 0;
7097
7098 #ifdef DHD_LOSSLESS_ROAMING
7099 dhd->pub.dequeue_prec_map = ALLPRIO;
7100 #endif // endif
7101
7102 #if 0
7103 /*
7104 * Force start if ifconfig_up gets called before START command
7105 * We keep WEXT's wl_control_wl_start to provide backward compatibility
7106 * This should be removed in the future
7107 */
7108 ret = wl_control_wl_start(net);
7109 if (ret != 0) {
7110 DHD_ERROR(("%s: failed with code %d\n", __FUNCTION__, ret));
7111 ret = -1;
7112 goto exit;
7113 }
7114
7115 #endif // endif
7116
7117 ifidx = dhd_net2idx(dhd, net);
7118 DHD_TRACE(("%s: ifidx %d\n", __FUNCTION__, ifidx));
7119
7120 if (ifidx < 0) {
7121 DHD_ERROR(("%s: Error: called with invalid IF\n", __FUNCTION__));
7122 ret = -1;
7123 goto exit;
7124 }
7125
7126 if (!dhd->iflist[ifidx]) {
7127 DHD_ERROR(("%s: Error: called when IF already deleted\n", __FUNCTION__));
7128 ret = -1;
7129 goto exit;
7130 }
7131
7132 if (ifidx == 0) {
7133 atomic_set(&dhd->pend_8021x_cnt, 0);
7134 if (!dhd_download_fw_on_driverload) {
7135 DHD_ERROR(("\n%s\n", dhd_version));
7136 DHD_STATLOG_CTRL(&dhd->pub, ST(WLAN_POWER_ON), ifidx, 0);
7137 #if defined(WL_EXT_IAPSTA) || defined(USE_IW) || defined(WL_ESCAN)
7138 wl_ext_event_attach_netdev(net, ifidx, dhd->iflist[ifidx]->bssidx);
7139 #ifdef WL_ESCAN
7140 wl_escan_event_attach(net, &dhd->pub);
7141 #endif /* WL_ESCAN */
7142 #ifdef WL_EXT_IAPSTA
7143 wl_ext_iapsta_attach_netdev(net, ifidx, dhd->iflist[ifidx]->bssidx);
7144 #endif /* WL_EXT_IAPSTA */
7145 #endif /* WL_EXT_IAPSTA || USE_IW || WL_ESCAN */
7146 #if defined(USE_INITIAL_2G_SCAN) || defined(USE_INITIAL_SHORT_DWELL_TIME)
7147 g_first_broadcast_scan = TRUE;
7148 #endif /* USE_INITIAL_2G_SCAN || USE_INITIAL_SHORT_DWELL_TIME */
7149 #ifdef SHOW_LOGTRACE
7150 /* dhd_cancel_logtrace_process_sync is called in dhd_stop
7151 * for built-in models. Need to start logtrace kthread before
7152 * calling wifi on, because once wifi is on, EDL will be in action
7153 * any moment, and if kthread is not active, FW event logs will
7154 * not be available
7155 */
7156 if (dhd_reinit_logtrace_process(dhd) != BCME_OK) {
7157 goto exit;
7158 }
7159 #endif /* SHOW_LOGTRACE */
7160 #if defined(BT_OVER_SDIO)
7161 ret = dhd_bus_get(&dhd->pub, WLAN_MODULE);
7162 wl_android_set_wifi_on_flag(TRUE);
7163 #else
7164 ret = wl_android_wifi_on(net);
7165 #endif /* BT_OVER_SDIO */
7166 if (ret != 0) {
7167 DHD_ERROR(("%s : wl_android_wifi_on failed (%d)\n",
7168 __FUNCTION__, ret));
7169 ret = -1;
7170 goto exit;
7171 }
7172 }
7173 #ifdef SUPPORT_DEEP_SLEEP
7174 else {
7175 /* Flags to indicate if we distingish
7176 * power off policy when user set the memu
7177 * "Keep Wi-Fi on during sleep" to "Never"
7178 */
7179 if (trigger_deep_sleep) {
7180 #if defined(USE_INITIAL_2G_SCAN) || defined(USE_INITIAL_SHORT_DWELL_TIME)
7181 g_first_broadcast_scan = TRUE;
7182 #endif /* USE_INITIAL_2G_SCAN || USE_INITIAL_SHORT_DWELL_TIME */
7183 dhd_deepsleep(net, 0);
7184 trigger_deep_sleep = 0;
7185 }
7186 }
7187 #endif /* SUPPORT_DEEP_SLEEP */
7188 #ifdef FIX_CPU_MIN_CLOCK
7189 if (dhd_get_fw_mode(dhd) == DHD_FLAG_HOSTAP_MODE) {
7190 dhd_init_cpufreq_fix(dhd);
7191 dhd_fix_cpu_freq(dhd);
7192 }
7193 #endif /* FIX_CPU_MIN_CLOCK */
7194 #if defined(OOB_INTR_ONLY)
7195 if (dhd->pub.conf->dpc_cpucore >= 0) {
7196 dhd_bus_get_ids(dhd->pub.bus, &bus_type, &bus_num, &slot_num);
7197 adapter = dhd_wifi_platform_get_adapter(bus_type, bus_num, slot_num);
7198 if (adapter) {
7199 printf("%s: set irq affinity hit %d\n", __FUNCTION__, dhd->pub.conf->dpc_cpucore);
7200 irq_set_affinity_hint(adapter->irq_num, cpumask_of(dhd->pub.conf->dpc_cpucore));
7201 }
7202 }
7203 #endif
7204
7205 if (dhd->pub.busstate != DHD_BUS_DATA) {
7206 #ifdef BCMDBUS
7207 dhd_set_path(&dhd->pub);
7208 DHD_MUTEX_UNLOCK();
7209 wait_event_interruptible_timeout(dhd->adapter->status_event,
7210 wifi_get_adapter_status(dhd->adapter, WIFI_STATUS_FW_READY),
7211 msecs_to_jiffies(DHD_FW_READY_TIMEOUT));
7212 DHD_MUTEX_LOCK();
7213 if ((ret = dbus_up(dhd->pub.bus)) != 0) {
7214 DHD_ERROR(("%s: failed to dbus_up with code %d\n", __FUNCTION__, ret));
7215 goto exit;
7216 } else {
7217 dhd->pub.busstate = DHD_BUS_DATA;
7218 }
7219 if ((ret = dhd_sync_with_dongle(&dhd->pub)) < 0) {
7220 DHD_ERROR(("%s: failed with code %d\n", __FUNCTION__, ret));
7221 goto exit;
7222 }
7223 #else
7224 /* try to bring up bus */
7225 DHD_PERIM_UNLOCK(&dhd->pub);
7226
7227 #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
7228 if (pm_runtime_get_sync(dhd_bus_to_dev(dhd->pub.bus)) >= 0) {
7229 ret = dhd_bus_start(&dhd->pub);
7230 pm_runtime_mark_last_busy(dhd_bus_to_dev(dhd->pub.bus));
7231 pm_runtime_put_autosuspend(dhd_bus_to_dev(dhd->pub.bus));
7232 }
7233 #else
7234 ret = dhd_bus_start(&dhd->pub);
7235 #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
7236
7237 DHD_PERIM_LOCK(&dhd->pub);
7238 if (ret) {
7239 DHD_ERROR(("%s: failed with code %d\n", __FUNCTION__, ret));
7240 ret = -1;
7241 goto exit;
7242 }
7243 #endif /* !BCMDBUS */
7244
7245 }
7246 #ifdef WL_EXT_IAPSTA
7247 wl_ext_iapsta_attach_name(net, ifidx);
7248 #endif
7249
7250 #ifdef BT_OVER_SDIO
7251 if (dhd->pub.is_bt_recovery_required) {
7252 DHD_ERROR(("%s: Send Hang Notification 2 to BT\n", __FUNCTION__));
7253 bcmsdh_btsdio_process_dhd_hang_notification(TRUE);
7254 }
7255 dhd->pub.is_bt_recovery_required = FALSE;
7256 #endif // endif
7257
7258 /* dhd_sync_with_dongle has been called in dhd_bus_start or wl_android_wifi_on */
7259 memcpy(net->dev_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
7260
7261 #ifdef TOE
7262 /* Get current TOE mode from dongle */
7263 if (dhd_toe_get(dhd, ifidx, &toe_ol) >= 0 && (toe_ol & TOE_TX_CSUM_OL) != 0) {
7264 dhd->iflist[ifidx]->net->features |= NETIF_F_IP_CSUM;
7265 } else {
7266 dhd->iflist[ifidx]->net->features &= ~NETIF_F_IP_CSUM;
7267 }
7268 #endif /* TOE */
7269
7270 #if defined(DHD_LB_RXP)
7271 __skb_queue_head_init(&dhd->rx_pend_queue);
7272 if (dhd->rx_napi_netdev == NULL) {
7273 dhd->rx_napi_netdev = dhd->iflist[ifidx]->net;
7274 memset(&dhd->rx_napi_struct, 0, sizeof(struct napi_struct));
7275 netif_napi_add(dhd->rx_napi_netdev, &dhd->rx_napi_struct,
7276 dhd_napi_poll, dhd_napi_weight);
7277 DHD_INFO(("%s napi<%p> enabled ifp->net<%p,%s>\n",
7278 __FUNCTION__, &dhd->rx_napi_struct, net, net->name));
7279 napi_enable(&dhd->rx_napi_struct);
7280 DHD_INFO(("%s load balance init rx_napi_struct\n", __FUNCTION__));
7281 skb_queue_head_init(&dhd->rx_napi_queue);
7282 } /* rx_napi_netdev == NULL */
7283 #endif /* DHD_LB_RXP */
7284
7285 #if defined(DHD_LB_TXP)
7286 /* Use the variant that uses locks */
7287 skb_queue_head_init(&dhd->tx_pend_queue);
7288 #endif /* DHD_LB_TXP */
7289
7290 #if defined(WL_CFG80211)
7291 if (unlikely(wl_cfg80211_up(net))) {
7292 DHD_ERROR(("%s: failed to bring up cfg80211\n", __FUNCTION__));
7293 ret = -1;
7294 goto exit;
7295 }
7296 if (!dhd_download_fw_on_driverload) {
7297 #ifdef ARP_OFFLOAD_SUPPORT
7298 dhd->pend_ipaddr = 0;
7299 if (!dhd_inetaddr_notifier_registered) {
7300 dhd_inetaddr_notifier_registered = TRUE;
7301 register_inetaddr_notifier(&dhd_inetaddr_notifier);
7302 }
7303 #endif /* ARP_OFFLOAD_SUPPORT */
7304 #if defined(CONFIG_IPV6) && defined(IPV6_NDO_SUPPORT)
7305 if (!dhd_inet6addr_notifier_registered) {
7306 dhd_inet6addr_notifier_registered = TRUE;
7307 register_inet6addr_notifier(&dhd_inet6addr_notifier);
7308 }
7309 #endif /* CONFIG_IPV6 && IPV6_NDO_SUPPORT */
7310 }
7311
7312 #if defined(DHD_CONTROL_PCIE_ASPM_WIFI_TURNON)
7313 dhd_bus_aspm_enable_rc_ep(dhd->pub.bus, TRUE);
7314 #endif /* DHD_CONTROL_PCIE_ASPM_WIFI_TURNON */
7315 #if defined(DHD_CONTROL_PCIE_CPUCORE_WIFI_TURNON)
7316 dhd_irq_set_affinity(&dhd->pub, cpumask_of(0));
7317 #endif /* DHD_CONTROL_PCIE_CPUCORE_WIFI_TURNON */
7318 #ifdef DHD_LB_IRQSET
7319 dhd_irq_set_affinity(&dhd->pub, dhd->cpumask_primary);
7320 #endif /* DHD_LB_IRQSET */
7321 #if defined(ARGOS_NOTIFY_CB)
7322 argos_register_notifier_init(net);
7323 #endif // endif
7324 #if defined(NUM_SCB_MAX_PROBE)
7325 dhd_set_scb_probe(&dhd->pub);
7326 #endif /* NUM_SCB_MAX_PROBE */
7327 #endif /* WL_CFG80211 */
7328 #if defined(WL_WIRELESS_EXT)
7329 if (unlikely(wl_iw_up(net, &dhd->pub))) {
7330 DHD_ERROR(("%s: failed to bring up wext\n", __FUNCTION__));
7331 ret = -1;
7332 goto exit;
7333 }
7334 #endif
7335 #ifdef WL_ESCAN
7336 if (unlikely(wl_escan_up(net, &dhd->pub))) {
7337 DHD_ERROR(("%s: failed to bring up escan\n", __FUNCTION__));
7338 ret = -1;
7339 goto exit;
7340 }
7341 #endif /* WL_ESCAN */
7342 #if defined(ISAM_PREINIT)
7343 if (!dhd_download_fw_on_driverload) {
7344 if (dhd->pub.conf) {
7345 wl_android_ext_priv_cmd(net, dhd->pub.conf->isam_init, 0, &bytes_written);
7346 wl_android_ext_priv_cmd(net, dhd->pub.conf->isam_config, 0, &bytes_written);
7347 wl_android_ext_priv_cmd(net, dhd->pub.conf->isam_enable, 0, &bytes_written);
7348 }
7349 }
7350 #endif
7351 }
7352
7353 dhd->pub.up = 1;
7354
7355 if (wl_event_enable) {
7356 /* For wl utility to receive events */
7357 dhd->pub.wl_event_enabled = true;
7358 } else {
7359 dhd->pub.wl_event_enabled = false;
7360 }
7361
7362 if (logtrace_pkt_sendup) {
7363 /* For any deamon to recieve logtrace */
7364 dhd->pub.logtrace_pkt_sendup = true;
7365 } else {
7366 dhd->pub.logtrace_pkt_sendup = false;
7367 }
7368
7369 OLD_MOD_INC_USE_COUNT;
7370
7371 #ifdef BCMDBGFS
7372 dhd_dbgfs_init(&dhd->pub);
7373 #endif // endif
7374
7375 exit:
7376 mutex_unlock(&dhd->pub.ndev_op_sync);
7377 if (ret) {
7378 dhd_stop(net);
7379 }
7380
7381 DHD_PERIM_UNLOCK(&dhd->pub);
7382 DHD_OS_WAKE_UNLOCK(&dhd->pub);
7383 DHD_MUTEX_UNLOCK();
7384
7385 printf("%s: Exit %s ret=%d\n", __FUNCTION__, net->name, ret);
7386 return ret;
7387 }
7388
7389 /*
7390 * ndo_start handler for primary ndev
7391 */
7392 static int
dhd_pri_open(struct net_device * net)7393 dhd_pri_open(struct net_device *net)
7394 {
7395 s32 ret;
7396
7397 ret = dhd_open(net);
7398 if (unlikely(ret)) {
7399 DHD_ERROR(("Failed to open primary dev ret %d\n", ret));
7400 return ret;
7401 }
7402
7403 /* Allow transmit calls */
7404 netif_start_queue(net);
7405 DHD_ERROR(("[%s] tx queue started\n", net->name));
7406
7407 #if defined(SET_RPS_CPUS)
7408 dhd_rps_cpus_enable(net, TRUE);
7409 #endif
7410
7411 #if defined(SET_XPS_CPUS)
7412 dhd_xps_cpus_enable(net, TRUE);
7413 #endif
7414
7415 return ret;
7416 }
7417
7418 /*
7419 * ndo_stop handler for primary ndev
7420 */
7421 static int
dhd_pri_stop(struct net_device * net)7422 dhd_pri_stop(struct net_device *net)
7423 {
7424 s32 ret;
7425
7426 /* stop tx queue */
7427 netif_stop_queue(net);
7428 DHD_ERROR(("[%s] tx queue stopped\n", net->name));
7429
7430 ret = dhd_stop(net);
7431 if (unlikely(ret)) {
7432 DHD_ERROR(("dhd_stop failed: %d\n", ret));
7433 return ret;
7434 }
7435
7436 return ret;
7437 }
7438
7439 #if defined(WL_STATIC_IF) && defined(WL_CFG80211)
7440 /*
7441 * For static I/Fs, the firmware interface init
7442 * is done from the IFF_UP context.
7443 */
7444 static int
dhd_static_if_open(struct net_device * net)7445 dhd_static_if_open(struct net_device *net)
7446 {
7447 s32 ret = 0;
7448 struct bcm_cfg80211 *cfg;
7449 struct net_device *primary_netdev = NULL;
7450
7451 cfg = wl_get_cfg(net);
7452 primary_netdev = bcmcfg_to_prmry_ndev(cfg);
7453
7454 if (!IS_CFG80211_STATIC_IF(cfg, net)) {
7455 DHD_TRACE(("non-static interface (%s)..do nothing \n", net->name));
7456 ret = BCME_OK;
7457 goto done;
7458 }
7459
7460 printf("%s: Enter %s\n", __FUNCTION__, net->name);
7461 /* Ensure fw is initialized. If it is already initialized,
7462 * dhd_open will return success.
7463 */
7464 ret = dhd_open(primary_netdev);
7465 if (unlikely(ret)) {
7466 DHD_ERROR(("Failed to open primary dev ret %d\n", ret));
7467 goto done;
7468 }
7469
7470 ret = wl_cfg80211_static_if_open(net);
7471 if (!ret) {
7472 /* Allow transmit calls */
7473 netif_start_queue(net);
7474 }
7475 done:
7476 printf("%s: Exit %s ret=%d\n", __FUNCTION__, net->name, ret);
7477 return ret;
7478 }
7479
7480 static int
dhd_static_if_stop(struct net_device * net)7481 dhd_static_if_stop(struct net_device *net)
7482 {
7483 struct bcm_cfg80211 *cfg;
7484 struct net_device *primary_netdev = NULL;
7485 int ret = BCME_OK;
7486 dhd_info_t *dhd = DHD_DEV_INFO(net);
7487
7488 printf("%s: Enter %s\n", __FUNCTION__, net->name);
7489
7490 cfg = wl_get_cfg(net);
7491 if (!IS_CFG80211_STATIC_IF(cfg, net)) {
7492 DHD_TRACE(("non-static interface (%s)..do nothing \n", net->name));
7493 return BCME_OK;
7494 }
7495 #ifdef DHD_NOTIFY_MAC_CHANGED
7496 if (dhd->pub.skip_dhd_stop) {
7497 WL_MSG(net->name, "Exit skip stop\n");
7498 return BCME_OK;
7499 }
7500 #endif /* DHD_NOTIFY_MAC_CHANGED */
7501
7502 /* Ensure queue is disabled */
7503 netif_tx_disable(net);
7504
7505 ret = wl_cfg80211_static_if_close(net);
7506
7507 if (dhd->pub.up == 0) {
7508 /* If fw is down, return */
7509 DHD_ERROR(("fw down\n"));
7510 return BCME_OK;
7511 }
7512 /* If STA iface is not in operational, invoke dhd_close from this
7513 * context.
7514 */
7515 primary_netdev = bcmcfg_to_prmry_ndev(cfg);
7516 if (!(primary_netdev->flags & IFF_UP)) {
7517 ret = dhd_stop(primary_netdev);
7518 } else {
7519 DHD_ERROR(("Skipped dhd_stop, as sta is operational\n"));
7520 }
7521 printf("%s: Exit %s ret=%d\n", __FUNCTION__, net->name, ret);
7522
7523 return ret;
7524 }
7525 #endif /* WL_STATIC_IF && WL_CF80211 */
7526
dhd_do_driver_init(struct net_device * net)7527 int dhd_do_driver_init(struct net_device *net)
7528 {
7529 dhd_info_t *dhd = NULL;
7530
7531 if (!net) {
7532 DHD_ERROR(("Primary Interface not initialized \n"));
7533 return -EINVAL;
7534 }
7535
7536 DHD_MUTEX_IS_LOCK_RETURN();
7537
7538 /* && defined(OEM_ANDROID) && defined(BCMSDIO) */
7539 dhd = DHD_DEV_INFO(net);
7540
7541 /* If driver is already initialized, do nothing
7542 */
7543 if (dhd->pub.busstate == DHD_BUS_DATA) {
7544 DHD_TRACE(("Driver already Inititalized. Nothing to do"));
7545 return 0;
7546 }
7547
7548 if (dhd_open(net) < 0) {
7549 DHD_ERROR(("Driver Init Failed \n"));
7550 return -1;
7551 }
7552
7553 return 0;
7554 }
7555
7556 int
dhd_event_ifadd(dhd_info_t * dhdinfo,wl_event_data_if_t * ifevent,char * name,uint8 * mac)7557 dhd_event_ifadd(dhd_info_t *dhdinfo, wl_event_data_if_t *ifevent, char *name, uint8 *mac)
7558 {
7559
7560 #ifdef WL_CFG80211
7561 if (wl_cfg80211_notify_ifadd(dhd_linux_get_primary_netdev(&dhdinfo->pub),
7562 ifevent->ifidx, name, mac, ifevent->bssidx, ifevent->role) == BCME_OK)
7563 return BCME_OK;
7564 #endif // endif
7565
7566 /* handle IF event caused by wl commands, SoftAP, WEXT and
7567 * anything else. This has to be done asynchronously otherwise
7568 * DPC will be blocked (and iovars will timeout as DPC has no chance
7569 * to read the response back)
7570 */
7571 if (ifevent->ifidx > 0) {
7572 dhd_if_event_t *if_event = MALLOC(dhdinfo->pub.osh, sizeof(dhd_if_event_t));
7573 if (if_event == NULL) {
7574 DHD_ERROR(("dhd_event_ifadd: Failed MALLOC, malloced %d bytes",
7575 MALLOCED(dhdinfo->pub.osh)));
7576 return BCME_NOMEM;
7577 }
7578
7579 memcpy(&if_event->event, ifevent, sizeof(if_event->event));
7580 memcpy(if_event->mac, mac, ETHER_ADDR_LEN);
7581 strncpy(if_event->name, name, IFNAMSIZ);
7582 if_event->name[IFNAMSIZ - 1] = '\0';
7583 dhd_deferred_schedule_work(dhdinfo->dhd_deferred_wq, (void *)if_event,
7584 DHD_WQ_WORK_IF_ADD, dhd_ifadd_event_handler, DHD_WQ_WORK_PRIORITY_LOW);
7585 }
7586
7587 return BCME_OK;
7588 }
7589
7590 int
dhd_event_ifdel(dhd_info_t * dhdinfo,wl_event_data_if_t * ifevent,char * name,uint8 * mac)7591 dhd_event_ifdel(dhd_info_t *dhdinfo, wl_event_data_if_t *ifevent, char *name, uint8 *mac)
7592 {
7593 dhd_if_event_t *if_event;
7594
7595 #ifdef WL_CFG80211
7596 if (wl_cfg80211_notify_ifdel(dhd_linux_get_primary_netdev(&dhdinfo->pub),
7597 ifevent->ifidx, name, mac, ifevent->bssidx) == BCME_OK)
7598 return BCME_OK;
7599 #endif /* WL_CFG80211 */
7600
7601 /* handle IF event caused by wl commands, SoftAP, WEXT and
7602 * anything else
7603 */
7604 if_event = MALLOC(dhdinfo->pub.osh, sizeof(dhd_if_event_t));
7605 if (if_event == NULL) {
7606 DHD_ERROR(("dhd_event_ifdel: malloc failed for if_event, malloced %d bytes",
7607 MALLOCED(dhdinfo->pub.osh)));
7608 return BCME_NOMEM;
7609 }
7610 memcpy(&if_event->event, ifevent, sizeof(if_event->event));
7611 memcpy(if_event->mac, mac, ETHER_ADDR_LEN);
7612 strncpy(if_event->name, name, IFNAMSIZ);
7613 if_event->name[IFNAMSIZ - 1] = '\0';
7614 dhd_deferred_schedule_work(dhdinfo->dhd_deferred_wq, (void *)if_event, DHD_WQ_WORK_IF_DEL,
7615 dhd_ifdel_event_handler, DHD_WQ_WORK_PRIORITY_LOW);
7616
7617 return BCME_OK;
7618 }
7619
7620 int
dhd_event_ifchange(dhd_info_t * dhdinfo,wl_event_data_if_t * ifevent,char * name,uint8 * mac)7621 dhd_event_ifchange(dhd_info_t *dhdinfo, wl_event_data_if_t *ifevent, char *name, uint8 *mac)
7622 {
7623 #ifdef DHD_UPDATE_INTF_MAC
7624 dhd_if_event_t *if_event;
7625 #endif /* DHD_UPDATE_INTF_MAC */
7626
7627 #ifdef WL_CFG80211
7628 wl_cfg80211_notify_ifchange(dhd_linux_get_primary_netdev(&dhdinfo->pub),
7629 ifevent->ifidx, name, mac, ifevent->bssidx);
7630 #endif /* WL_CFG80211 */
7631
7632 #ifdef DHD_UPDATE_INTF_MAC
7633 /* handle IF event caused by wl commands, SoftAP, WEXT, MBSS and
7634 * anything else
7635 */
7636 if_event = MALLOC(dhdinfo->pub.osh, sizeof(dhd_if_event_t));
7637 if (if_event == NULL) {
7638 DHD_ERROR(("dhd_event_ifdel: malloc failed for if_event, malloced %d bytes",
7639 MALLOCED(dhdinfo->pub.osh)));
7640 return BCME_NOMEM;
7641 }
7642 memcpy(&if_event->event, ifevent, sizeof(if_event->event));
7643 // construct a change event
7644 if_event->event.ifidx = dhd_ifname2idx(dhdinfo, name);
7645 if_event->event.opcode = WLC_E_IF_CHANGE;
7646 memcpy(if_event->mac, mac, ETHER_ADDR_LEN);
7647 strncpy(if_event->name, name, IFNAMSIZ);
7648 if_event->name[IFNAMSIZ - 1] = '\0';
7649 dhd_deferred_schedule_work(dhdinfo->dhd_deferred_wq, (void *)if_event, DHD_WQ_WORK_IF_UPDATE,
7650 dhd_ifupdate_event_handler, DHD_WQ_WORK_PRIORITY_LOW);
7651 #endif /* DHD_UPDATE_INTF_MAC */
7652
7653 return BCME_OK;
7654 }
7655
7656 #ifdef WL_NATOE
7657 /* Handler to update natoe info and bind with new subscriptions if there is change in config */
7658 static void
dhd_natoe_ct_event_hanlder(void * handle,void * event_info,u8 event)7659 dhd_natoe_ct_event_hanlder(void *handle, void *event_info, u8 event)
7660 {
7661 dhd_info_t *dhd = handle;
7662 wl_event_data_natoe_t *natoe = event_info;
7663 dhd_nfct_info_t *nfct = dhd->pub.nfct;
7664
7665 if (event != DHD_WQ_WORK_NATOE_EVENT) {
7666 DHD_ERROR(("%s: unexpected event \n", __FUNCTION__));
7667 return;
7668 }
7669
7670 if (!dhd) {
7671 DHD_ERROR(("%s: dhd info not available \n", __FUNCTION__));
7672 return;
7673 }
7674 if (natoe->natoe_active && natoe->sta_ip && natoe->start_port && natoe->end_port &&
7675 (natoe->start_port < natoe->end_port)) {
7676 /* Rebind subscriptions to start receiving notifications from groups */
7677 if (dhd_ct_nl_bind(nfct, nfct->subscriptions) < 0) {
7678 dhd_ct_close(nfct);
7679 }
7680 dhd_ct_send_dump_req(nfct);
7681 } else if (!natoe->natoe_active) {
7682 /* Rebind subscriptions to stop receiving notifications from groups */
7683 if (dhd_ct_nl_bind(nfct, CT_NULL_SUBSCRIPTION) < 0) {
7684 dhd_ct_close(nfct);
7685 }
7686 }
7687 }
7688
7689 /* As NATOE enable/disbale event is received, we have to bind with new NL subscriptions.
7690 * Scheduling workq to switch from tasklet context as bind call may sleep in handler
7691 */
7692 int
dhd_natoe_ct_event(dhd_pub_t * dhd,char * data)7693 dhd_natoe_ct_event(dhd_pub_t *dhd, char *data)
7694 {
7695 wl_event_data_natoe_t *event_data = (wl_event_data_natoe_t *)data;
7696
7697 if (dhd->nfct) {
7698 wl_event_data_natoe_t *natoe = dhd->nfct->natoe_info;
7699 uint8 prev_enable = natoe->natoe_active;
7700
7701 spin_lock_bh(&dhd->nfct_lock);
7702 memcpy(natoe, event_data, sizeof(*event_data));
7703 spin_unlock_bh(&dhd->nfct_lock);
7704
7705 if (prev_enable != event_data->natoe_active) {
7706 dhd_deferred_schedule_work(dhd->info->dhd_deferred_wq,
7707 (void *)natoe, DHD_WQ_WORK_NATOE_EVENT,
7708 dhd_natoe_ct_event_hanlder, DHD_WQ_WORK_PRIORITY_LOW);
7709 }
7710 return BCME_OK;
7711 }
7712 DHD_ERROR(("%s ERROR NFCT is not enabled \n", __FUNCTION__));
7713 return BCME_ERROR;
7714 }
7715
7716 /* Handler to send natoe ioctl to dongle */
7717 static void
dhd_natoe_ct_ioctl_handler(void * handle,void * event_info,uint8 event)7718 dhd_natoe_ct_ioctl_handler(void *handle, void *event_info, uint8 event)
7719 {
7720 dhd_info_t *dhd = handle;
7721 dhd_ct_ioc_t *ct_ioc = event_info;
7722
7723 if (event != DHD_WQ_WORK_NATOE_IOCTL) {
7724 DHD_ERROR(("%s: unexpected event \n", __FUNCTION__));
7725 return;
7726 }
7727
7728 if (!dhd) {
7729 DHD_ERROR(("%s: dhd info not available \n", __FUNCTION__));
7730 return;
7731 }
7732
7733 if (dhd_natoe_prep_send_exception_port_ioctl(&dhd->pub, ct_ioc) < 0) {
7734 DHD_ERROR(("%s: Error in sending NATOE IOCTL \n", __FUNCTION__));
7735 }
7736 }
7737
7738 /* When Netlink message contains port collision info, the info must be sent to dongle FW
7739 * For that we have to switch context from softirq/tasklet by scheduling workq for natoe_ct ioctl
7740 */
7741 void
dhd_natoe_ct_ioctl_schedule_work(dhd_pub_t * dhd,dhd_ct_ioc_t * ioc)7742 dhd_natoe_ct_ioctl_schedule_work(dhd_pub_t *dhd, dhd_ct_ioc_t *ioc)
7743 {
7744
7745 dhd_deferred_schedule_work(dhd->info->dhd_deferred_wq, (void *)ioc,
7746 DHD_WQ_WORK_NATOE_IOCTL, dhd_natoe_ct_ioctl_handler,
7747 DHD_WQ_WORK_PRIORITY_HIGH);
7748 }
7749 #endif /* WL_NATOE */
7750
7751 /* This API maps ndev to ifp inclusive of static IFs */
7752 static dhd_if_t *
dhd_get_ifp_by_ndev(dhd_pub_t * dhdp,struct net_device * ndev)7753 dhd_get_ifp_by_ndev(dhd_pub_t *dhdp, struct net_device *ndev)
7754 {
7755 dhd_if_t *ifp = NULL;
7756 #ifdef WL_STATIC_IF
7757 u32 ifidx = (DHD_MAX_IFS + DHD_MAX_STATIC_IFS - 1);
7758 #else
7759 u32 ifidx = (DHD_MAX_IFS - 1);
7760 #endif /* WL_STATIC_IF */
7761
7762 dhd_info_t *dhdinfo = (dhd_info_t *)dhdp->info;
7763 do {
7764 ifp = dhdinfo->iflist[ifidx];
7765 if (ifp && (ifp->net == ndev)) {
7766 DHD_TRACE(("match found for %s. ifidx:%d\n",
7767 ndev->name, ifidx));
7768 return ifp;
7769 }
7770 } while (ifidx--);
7771
7772 DHD_ERROR(("no entry found for %s\n", ndev->name));
7773 return NULL;
7774 }
7775
7776 bool
dhd_is_static_ndev(dhd_pub_t * dhdp,struct net_device * ndev)7777 dhd_is_static_ndev(dhd_pub_t *dhdp, struct net_device *ndev)
7778 {
7779 dhd_if_t *ifp = NULL;
7780
7781 if (!dhdp || !ndev) {
7782 DHD_ERROR(("wrong input\n"));
7783 ASSERT(0);
7784 return false;
7785 }
7786
7787 ifp = dhd_get_ifp_by_ndev(dhdp, ndev);
7788 return (ifp && (ifp->static_if == true));
7789 }
7790
7791 #ifdef WL_STATIC_IF
7792 /* In some cases, while registering I/F, the actual ifidx, bssidx and dngl_name
7793 * are not known. For e.g: static i/f case. This function lets to update it once
7794 * it is known.
7795 */
7796 s32
dhd_update_iflist_info(dhd_pub_t * dhdp,struct net_device * ndev,int ifidx,uint8 * mac,uint8 bssidx,const char * dngl_name,int if_state)7797 dhd_update_iflist_info(dhd_pub_t *dhdp, struct net_device *ndev, int ifidx,
7798 uint8 *mac, uint8 bssidx, const char *dngl_name, int if_state)
7799 {
7800 dhd_info_t *dhdinfo = (dhd_info_t *)dhdp->info;
7801 dhd_if_t *ifp, *ifp_new;
7802 s32 cur_idx;
7803 dhd_dev_priv_t * dev_priv;
7804
7805 DHD_TRACE(("[STATIC_IF] update ifinfo for state:%d ifidx:%d\n",
7806 if_state, ifidx));
7807
7808 ASSERT(dhdinfo && (ifidx < (DHD_MAX_IFS + DHD_MAX_STATIC_IFS)));
7809
7810 if ((ifp = dhd_get_ifp_by_ndev(dhdp, ndev)) == NULL) {
7811 return -ENODEV;
7812 }
7813 cur_idx = ifp->idx;
7814
7815 if (if_state == NDEV_STATE_OS_IF_CREATED) {
7816 /* mark static if */
7817 ifp->static_if = TRUE;
7818 return BCME_OK;
7819 }
7820
7821 ifp_new = dhdinfo->iflist[ifidx];
7822 if (ifp_new && (ifp_new != ifp)) {
7823 /* There should be only one entry for a given ifidx. */
7824 DHD_ERROR(("ifp ptr already present for ifidx:%d\n", ifidx));
7825 ASSERT(0);
7826 dhdp->hang_reason = HANG_REASON_IFACE_ADD_FAILURE;
7827 net_os_send_hang_message(ifp->net);
7828 return -EINVAL;
7829 }
7830
7831 /* For static if delete case, cleanup the if before ifidx update */
7832 if ((if_state == NDEV_STATE_FW_IF_DELETED) ||
7833 (if_state == NDEV_STATE_FW_IF_FAILED)) {
7834 dhd_cleanup_if(ifp->net);
7835 dev_priv = DHD_DEV_PRIV(ndev);
7836 dev_priv->ifidx = ifidx;
7837 }
7838
7839 /* update the iflist ifidx slot with cached info */
7840 dhdinfo->iflist[ifidx] = ifp;
7841 dhdinfo->iflist[cur_idx] = NULL;
7842
7843 /* update the values */
7844 ifp->idx = ifidx;
7845 ifp->bssidx = bssidx;
7846
7847 if (if_state == NDEV_STATE_FW_IF_CREATED) {
7848 dhd_dev_priv_save(ndev, dhdinfo, ifp, ifidx);
7849 /* initialize the dongle provided if name */
7850 if (dngl_name) {
7851 strlcpy(ifp->dngl_name, dngl_name, IFNAMSIZ);
7852 } else if (ndev->name[0] != '\0') {
7853 strlcpy(ifp->dngl_name, ndev->name, IFNAMSIZ);
7854 }
7855 if (mac != NULL) {
7856 (void)memcpy_s(&ifp->mac_addr, ETHER_ADDR_LEN, mac, ETHER_ADDR_LEN);
7857 }
7858 #if defined(WL_EXT_IAPSTA) || defined(USE_IW) || defined(WL_ESCAN)
7859 wl_ext_event_attach_netdev(ndev, ifidx, bssidx);
7860 #ifdef WL_ESCAN
7861 wl_escan_event_attach(ndev, dhdp);
7862 #endif /* WL_ESCAN */
7863 #ifdef WL_EXT_IAPSTA
7864 wl_ext_iapsta_ifadding(ndev, ifidx);
7865 wl_ext_iapsta_attach_netdev(ndev, ifidx, bssidx);
7866 wl_ext_iapsta_attach_name(ndev, ifidx);
7867 #endif /* WL_EXT_IAPSTA */
7868 } else if (if_state == NDEV_STATE_FW_IF_DELETED) {
7869 #ifdef WL_EXT_IAPSTA
7870 wl_ext_iapsta_dettach_netdev(ndev, cur_idx);
7871 #endif /* WL_EXT_IAPSTA */
7872 #ifdef WL_ESCAN
7873 wl_escan_event_dettach(ndev, dhdp);
7874 #endif /* WL_ESCAN */
7875 wl_ext_event_dettach_netdev(ndev, cur_idx);
7876 #endif /* WL_EXT_IAPSTA || USE_IW || WL_ESCAN */
7877 }
7878 DHD_INFO(("[STATIC_IF] ifp ptr updated for ifidx:%d curidx:%d if_state:%d\n",
7879 ifidx, cur_idx, if_state));
7880 return BCME_OK;
7881 }
7882 #endif /* WL_STATIC_IF */
7883
7884 #ifdef CONFIG_AP6XXX_WIFI6_HDF
7885 struct net_device * get_krn_netdev(int ifidx);
7886
get_dhd_priv_data_size(void)7887 int get_dhd_priv_data_size(void)
7888 {
7889 return DHD_DEV_PRIV_SIZE;
7890 }
7891
7892 const static struct net_device_ops *hdf_netdev_ops = NULL;
7893
7894 #endif
7895
7896 /* unregister and free the existing net_device interface (if any) in iflist and
7897 * allocate a new one. the slot is reused. this function does NOT register the
7898 * new interface to linux kernel. dhd_register_if does the job
7899 */
7900 struct net_device*
dhd_allocate_if(dhd_pub_t * dhdpub,int ifidx,const char * name,uint8 * mac,uint8 bssidx,bool need_rtnl_lock,const char * dngl_name)7901 dhd_allocate_if(dhd_pub_t *dhdpub, int ifidx, const char *name,
7902 uint8 *mac, uint8 bssidx, bool need_rtnl_lock, const char *dngl_name)
7903 {
7904 dhd_info_t *dhdinfo = (dhd_info_t *)dhdpub->info;
7905 dhd_if_t *ifp;
7906
7907 #ifdef CONFIG_AP6XXX_WIFI6_HDF
7908 DHD_ERROR(("%s: bdh6: create netdevice %s hdfidx=%d, ifidx=%d, bssidx=%u\n", __FUNCTION__, name, g_hdf_ifidx, ifidx, bssidx));
7909 #else
7910 DHD_ERROR(("%s: bdh6: create netdevice %s ifidx=%d, bssidx=%u\n", __FUNCTION__, name, ifidx, bssidx));
7911 #endif
7912
7913 ASSERT(dhdinfo && (ifidx < (DHD_MAX_IFS + DHD_MAX_STATIC_IFS)));
7914
7915 ifp = dhdinfo->iflist[ifidx];
7916
7917 if (ifp != NULL) {
7918 if (ifp->net != NULL) {
7919 DHD_ERROR(("%s: bdh6 free existing IF %s ifidx:%d \n",
7920 __FUNCTION__, ifp->net->name, ifidx));
7921
7922 if (ifidx == 0) {
7923 /* For primary ifidx (0), there shouldn't be
7924 * any netdev present already.
7925 */
7926 DHD_ERROR(("Primary ifidx populated already\n"));
7927 ASSERT(0);
7928 return NULL;
7929 }
7930
7931 dhd_dev_priv_clear(ifp->net); /* clear net_device private */
7932
7933 /* in unregister_netdev case, the interface gets freed by net->destructor
7934 * (which is set to free_netdev)
7935 */
7936 if (ifp->net->reg_state == NETREG_UNINITIALIZED) {
7937 free_netdev(ifp->net);
7938 } else {
7939 netif_stop_queue(ifp->net);
7940 if (need_rtnl_lock)
7941 unregister_netdev(ifp->net);
7942 else
7943 unregister_netdevice(ifp->net);
7944 }
7945 ifp->net = NULL;
7946 }
7947 } else {
7948 ifp = MALLOC(dhdinfo->pub.osh, sizeof(dhd_if_t));
7949 if (ifp == NULL) {
7950 DHD_ERROR(("%s: OOM - dhd_if_t(%zu)\n", __FUNCTION__, sizeof(dhd_if_t)));
7951 return NULL;
7952 }
7953 }
7954
7955 memset(ifp, 0, sizeof(dhd_if_t));
7956 ifp->info = dhdinfo;
7957 ifp->idx = ifidx;
7958 ifp->bssidx = bssidx;
7959 #ifdef DHD_MCAST_REGEN
7960 ifp->mcast_regen_bss_enable = FALSE;
7961 #endif // endif
7962 /* set to TRUE rx_pkt_chainable at alloc time */
7963 ifp->rx_pkt_chainable = TRUE;
7964
7965 if (mac != NULL)
7966 memcpy(&ifp->mac_addr, mac, ETHER_ADDR_LEN);
7967
7968 /* Allocate etherdev, including space for private structure */
7969 #ifdef CONFIG_AP6XXX_WIFI6_HDF
7970 ifp->net = get_krn_netdev(g_hdf_ifidx);
7971 if (0 == g_hdf_ifidx) {
7972 hdf_netdev_ops = ifp->net->netdev_ops;
7973 }
7974 #else
7975 ifp->net = alloc_etherdev(DHD_DEV_PRIV_SIZE);
7976 #endif
7977 if (ifp->net == NULL) {
7978 DHD_ERROR(("%s: OOM - alloc_etherdev(%zu)\n", __FUNCTION__, sizeof(dhdinfo)));
7979 goto fail;
7980 }
7981
7982 /* Setup the dhd interface's netdevice private structure. */
7983 dhd_dev_priv_save(ifp->net, dhdinfo, ifp, ifidx);
7984
7985 if (name && name[0]) {
7986 strncpy(ifp->net->name, name, IFNAMSIZ);
7987 ifp->net->name[IFNAMSIZ - 1] = '\0';
7988 }
7989
7990 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 9))
7991 #define IFP_NET_DESTRUCTOR ifp->net->priv_destructor
7992 #else
7993 #define IFP_NET_DESTRUCTOR ifp->net->destructor
7994 #endif // endif
7995
7996 #ifdef WL_CFG80211
7997 if (ifidx == 0) {
7998 IFP_NET_DESTRUCTOR = free_netdev;
7999 } else {
8000 IFP_NET_DESTRUCTOR = dhd_netdev_free;
8001 }
8002 #else
8003 IFP_NET_DESTRUCTOR = free_netdev;
8004 #endif /* WL_CFG80211 */
8005 strncpy(ifp->name, ifp->net->name, IFNAMSIZ);
8006 ifp->name[IFNAMSIZ - 1] = '\0';
8007 dhdinfo->iflist[ifidx] = ifp;
8008
8009 /* initialize the dongle provided if name */
8010 if (dngl_name) {
8011 strncpy(ifp->dngl_name, dngl_name, IFNAMSIZ);
8012 } else if (name) {
8013 strncpy(ifp->dngl_name, name, IFNAMSIZ);
8014 }
8015
8016 #ifdef PCIE_FULL_DONGLE
8017 /* Initialize STA info list */
8018 INIT_LIST_HEAD(&ifp->sta_list);
8019 DHD_IF_STA_LIST_LOCK_INIT(ifp);
8020 #endif /* PCIE_FULL_DONGLE */
8021
8022 #ifdef DHD_L2_FILTER
8023 ifp->phnd_arp_table = init_l2_filter_arp_table(dhdpub->osh);
8024 ifp->parp_allnode = TRUE;
8025 #endif /* DHD_L2_FILTER */
8026
8027 DHD_CUMM_CTR_INIT(&ifp->cumm_ctr);
8028
8029 #ifdef DHD_4WAYM4_FAIL_DISCONNECT
8030 INIT_DELAYED_WORK(&ifp->m4state_work, dhd_m4_state_handler);
8031 #endif /* DHD_4WAYM4_FAIL_DISCONNECT */
8032
8033 #ifdef DHD_POST_EAPOL_M1_AFTER_ROAM_EVT
8034 ifp->recv_reassoc_evt = FALSE;
8035 ifp->post_roam_evt = FALSE;
8036 #endif /* DHD_POST_EAPOL_M1_AFTER_ROAM_EVT */
8037
8038 #ifdef DHDTCPSYNC_FLOOD_BLK
8039 INIT_WORK(&ifp->blk_tsfl_work, dhd_blk_tsfl_handler);
8040 dhd_reset_tcpsync_info_by_ifp(ifp);
8041 #endif /* DHDTCPSYNC_FLOOD_BLK */
8042
8043 return ifp->net;
8044
8045 fail:
8046 if (ifp != NULL) {
8047 if (ifp->net != NULL) {
8048 #if defined(DHD_LB_RXP) && defined(PCIE_FULL_DONGLE)
8049 if (ifp->net == dhdinfo->rx_napi_netdev) {
8050 napi_disable(&dhdinfo->rx_napi_struct);
8051 netif_napi_del(&dhdinfo->rx_napi_struct);
8052 skb_queue_purge(&dhdinfo->rx_napi_queue);
8053 dhdinfo->rx_napi_netdev = NULL;
8054 }
8055 #endif /* DHD_LB_RXP && PCIE_FULL_DONGLE */
8056 dhd_dev_priv_clear(ifp->net);
8057 free_netdev(ifp->net);
8058 ifp->net = NULL;
8059 }
8060 MFREE(dhdinfo->pub.osh, ifp, sizeof(*ifp));
8061 ifp = NULL;
8062 }
8063
8064 dhdinfo->iflist[ifidx] = NULL;
8065 return NULL;
8066 }
8067
8068 static void
dhd_cleanup_ifp(dhd_pub_t * dhdp,dhd_if_t * ifp)8069 dhd_cleanup_ifp(dhd_pub_t *dhdp, dhd_if_t *ifp)
8070 {
8071 #ifdef PCIE_FULL_DONGLE
8072 s32 ifidx = 0;
8073 if_flow_lkup_t *if_flow_lkup = (if_flow_lkup_t *)dhdp->if_flow_lkup;
8074 #endif /* PCIE_FULL_DONGLE */
8075
8076 if (ifp != NULL) {
8077 if ((ifp->idx < 0) || (ifp->idx >= DHD_MAX_IFS)) {
8078 DHD_ERROR(("Wrong idx:%d \n", ifp->idx));
8079 ASSERT(0);
8080 return;
8081 }
8082 #ifdef DHD_L2_FILTER
8083 bcm_l2_filter_arp_table_update(dhdpub->osh, ifp->phnd_arp_table, TRUE,
8084 NULL, FALSE, dhdpub->tickcnt);
8085 deinit_l2_filter_arp_table(dhdpub->osh, ifp->phnd_arp_table);
8086 ifp->phnd_arp_table = NULL;
8087 #endif /* DHD_L2_FILTER */
8088
8089 dhd_if_del_sta_list(ifp);
8090 #ifdef PCIE_FULL_DONGLE
8091 /* Delete flowrings of virtual interface */
8092 ifidx = ifp->idx;
8093 if ((ifidx != 0) && (if_flow_lkup[ifidx].role != WLC_E_IF_ROLE_AP)) {
8094 dhd_flow_rings_delete(dhdp, ifidx);
8095 }
8096 #endif /* PCIE_FULL_DONGLE */
8097 }
8098 }
8099
8100 void
dhd_cleanup_if(struct net_device * net)8101 dhd_cleanup_if(struct net_device *net)
8102 {
8103 dhd_info_t *dhdinfo = DHD_DEV_INFO(net);
8104 dhd_pub_t *dhdp = &dhdinfo->pub;
8105 dhd_if_t *ifp;
8106
8107 if (!(ifp = dhd_get_ifp_by_ndev(dhdp, net)) ||
8108 (ifp->idx >= DHD_MAX_IFS)) {
8109 DHD_ERROR(("Wrong ifidx: %p, %d\n", ifp, ifp ? ifp->idx : -1));
8110 ASSERT(0);
8111 return;
8112 }
8113
8114 dhd_cleanup_ifp(dhdp, ifp);
8115 }
8116
8117 /* unregister and free the the net_device interface associated with the indexed
8118 * slot, also free the slot memory and set the slot pointer to NULL
8119 */
8120 #define DHD_TX_COMPLETION_TIMEOUT 5000
8121 int
dhd_remove_if(dhd_pub_t * dhdpub,int ifidx,bool need_rtnl_lock)8122 dhd_remove_if(dhd_pub_t *dhdpub, int ifidx, bool need_rtnl_lock)
8123 {
8124 dhd_info_t *dhdinfo = (dhd_info_t *)dhdpub->info;
8125 dhd_if_t *ifp;
8126 unsigned long flags;
8127 long timeout;
8128 ifp = dhdinfo->iflist[ifidx];
8129
8130 if (ifp != NULL) {
8131 #ifdef DHD_4WAYM4_FAIL_DISCONNECT
8132 cancel_delayed_work_sync(&ifp->m4state_work);
8133 #endif /* DHD_4WAYM4_FAIL_DISCONNECT */
8134
8135 #ifdef DHDTCPSYNC_FLOOD_BLK
8136 cancel_work_sync(&ifp->blk_tsfl_work);
8137 #endif /* DHDTCPSYNC_FLOOD_BLK */
8138
8139 #ifdef WL_STATIC_IF
8140 /* static IF will be handled in detach */
8141 if (ifp->static_if) {
8142 DHD_TRACE(("Skip del iface for static interface\n"));
8143 return BCME_OK;
8144 }
8145 #endif /* WL_STATIC_IF */
8146 if (ifp->net != NULL) {
8147 DHD_ERROR(("deleting interface '%s' idx %d\n", ifp->net->name, ifp->idx));
8148
8149 DHD_GENERAL_LOCK(dhdpub, flags);
8150 ifp->del_in_progress = true;
8151 DHD_GENERAL_UNLOCK(dhdpub, flags);
8152
8153 /* If TX is in progress, hold the if del */
8154 if (DHD_IF_IS_TX_ACTIVE(ifp)) {
8155 DHD_INFO(("TX in progress. Wait for it to be complete."));
8156 timeout = wait_event_timeout(dhdpub->tx_completion_wait,
8157 ((ifp->tx_paths_active & DHD_TX_CONTEXT_MASK) == 0),
8158 msecs_to_jiffies(DHD_TX_COMPLETION_TIMEOUT));
8159 if (!timeout) {
8160 /* Tx completion timeout. Attempt proceeding ahead */
8161 DHD_ERROR(("Tx completion timed out!\n"));
8162 ASSERT(0);
8163 }
8164 } else {
8165 DHD_TRACE(("No outstanding TX!\n"));
8166 }
8167 dhdinfo->iflist[ifidx] = NULL;
8168 /* in unregister_netdev case, the interface gets freed by net->destructor
8169 * (which is set to free_netdev)
8170 */
8171 if (ifp->net->reg_state == NETREG_UNINITIALIZED) {
8172 free_netdev(ifp->net);
8173 } else {
8174 netif_tx_disable(ifp->net);
8175
8176 #if defined(SET_RPS_CPUS)
8177 custom_rps_map_clear(ifp->net->_rx);
8178 #endif /* SET_RPS_CPUS */
8179 #if defined(SET_RPS_CPUS)
8180 #if (defined(DHDTCPACK_SUPPRESS) && defined(BCMPCIE))
8181 dhd_tcpack_suppress_set(dhdpub, TCPACK_SUP_OFF);
8182 #endif /* DHDTCPACK_SUPPRESS && BCMPCIE */
8183 #endif // endif
8184 if (need_rtnl_lock)
8185 unregister_netdev(ifp->net);
8186 else
8187 unregister_netdevice(ifp->net);
8188 #if defined(WL_EXT_IAPSTA) || defined(USE_IW) || defined(WL_ESCAN)
8189 #ifdef WL_EXT_IAPSTA
8190 wl_ext_iapsta_dettach_netdev(ifp->net, ifidx);
8191 #endif /* WL_EXT_IAPSTA */
8192 #ifdef WL_ESCAN
8193 wl_escan_event_dettach(ifp->net, dhdpub);
8194 #endif /* WL_ESCAN */
8195 wl_ext_event_dettach_netdev(ifp->net, ifidx);
8196 #endif /* WL_EXT_IAPSTA || USE_IW || WL_ESCAN */
8197 }
8198 ifp->net = NULL;
8199 DHD_GENERAL_LOCK(dhdpub, flags);
8200 ifp->del_in_progress = false;
8201 DHD_GENERAL_UNLOCK(dhdpub, flags);
8202 }
8203 dhd_cleanup_ifp(dhdpub, ifp);
8204 DHD_CUMM_CTR_INIT(&ifp->cumm_ctr);
8205
8206 MFREE(dhdinfo->pub.osh, ifp, sizeof(*ifp));
8207 ifp = NULL;
8208 }
8209
8210 return BCME_OK;
8211 }
8212
8213 #ifndef CONFIG_AP6XXX_WIFI6_HDF
8214 static
8215 #endif
8216 struct net_device_ops dhd_ops_pri = {
8217 .ndo_open = dhd_pri_open,
8218 .ndo_stop = dhd_pri_stop,
8219 .ndo_get_stats = dhd_get_stats,
8220 #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
8221 .ndo_do_ioctl = dhd_ioctl_entry_wrapper,
8222 .ndo_start_xmit = dhd_start_xmit_wrapper,
8223 #else
8224 .ndo_do_ioctl = dhd_ioctl_entry,
8225 .ndo_start_xmit = dhd_start_xmit,
8226 #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
8227 .ndo_set_mac_address = dhd_set_mac_address,
8228 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
8229 .ndo_set_rx_mode = dhd_set_multicast_list,
8230 #else
8231 .ndo_set_multicast_list = dhd_set_multicast_list,
8232 #endif // endif
8233 };
8234
8235 static struct net_device_ops dhd_ops_virt = {
8236 #if defined(WL_CFG80211) && defined(WL_STATIC_IF)
8237 .ndo_open = dhd_static_if_open,
8238 .ndo_stop = dhd_static_if_stop,
8239 #endif // endif
8240 .ndo_get_stats = dhd_get_stats,
8241 #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
8242 .ndo_do_ioctl = dhd_ioctl_entry_wrapper,
8243 .ndo_start_xmit = dhd_start_xmit_wrapper,
8244 #else
8245 .ndo_do_ioctl = dhd_ioctl_entry,
8246 .ndo_start_xmit = dhd_start_xmit,
8247 #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
8248 .ndo_set_mac_address = dhd_set_mac_address,
8249 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
8250 .ndo_set_rx_mode = dhd_set_multicast_list,
8251 #else
8252 .ndo_set_multicast_list = dhd_set_multicast_list,
8253 #endif // endif
8254 };
8255
8256 int
dhd_os_write_file_posn(void * fp,unsigned long * posn,void * buf,unsigned long buflen)8257 dhd_os_write_file_posn(void *fp, unsigned long *posn, void *buf,
8258 unsigned long buflen)
8259 {
8260 loff_t wr_posn = *posn;
8261
8262 if (!fp || !buf || buflen == 0)
8263 return -1;
8264
8265 if (compat_vfs_write((struct file *)fp, buf, buflen, &wr_posn) < 0)
8266 return -1;
8267
8268 *posn = wr_posn;
8269 return 0;
8270 }
8271
8272 #ifdef SHOW_LOGTRACE
8273 int
dhd_os_read_file(void * file,char * buf,uint32 size)8274 dhd_os_read_file(void *file, char *buf, uint32 size)
8275 {
8276 struct file *filep = (struct file *)file;
8277
8278 if (!file || !buf)
8279 return -1;
8280
8281 return vfs_read(filep, buf, size, &filep->f_pos);
8282 }
8283
8284 int
dhd_os_seek_file(void * file,int64 offset)8285 dhd_os_seek_file(void *file, int64 offset)
8286 {
8287 struct file *filep = (struct file *)file;
8288 if (!file)
8289 return -1;
8290
8291 /* offset can be -ve */
8292 filep->f_pos = filep->f_pos + offset;
8293
8294 return 0;
8295 }
8296
8297 static int
dhd_init_logstrs_array(osl_t * osh,dhd_event_log_t * temp)8298 dhd_init_logstrs_array(osl_t *osh, dhd_event_log_t *temp)
8299 {
8300 struct file *filep = NULL;
8301 struct kstat stat;
8302 #if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0))
8303 mm_segment_t fs;
8304 #endif
8305 char *raw_fmts = NULL;
8306 int logstrs_size = 0;
8307 int error = 0;
8308
8309 #if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0))
8310 fs = get_fs();
8311 set_fs(KERNEL_DS);
8312 #endif
8313
8314 filep = filp_open(logstrs_path, O_RDONLY, 0);
8315
8316 if (IS_ERR(filep)) {
8317 DHD_ERROR_NO_HW4(("%s: Failed to open the file %s \n", __FUNCTION__, logstrs_path));
8318 goto fail;
8319 }
8320 error = vfs_stat(logstrs_path, &stat);
8321 if (error) {
8322 DHD_ERROR_NO_HW4(("%s: Failed to stat file %s \n", __FUNCTION__, logstrs_path));
8323 goto fail;
8324 }
8325 logstrs_size = (int) stat.size;
8326
8327 if (logstrs_size == 0) {
8328 DHD_ERROR(("%s: return as logstrs_size is 0\n", __FUNCTION__));
8329 goto fail1;
8330 }
8331
8332 raw_fmts = MALLOC(osh, logstrs_size);
8333 if (raw_fmts == NULL) {
8334 DHD_ERROR(("%s: Failed to allocate memory \n", __FUNCTION__));
8335 goto fail;
8336 }
8337
8338 if (vfs_read(filep, raw_fmts, logstrs_size, &filep->f_pos) != logstrs_size) {
8339 DHD_ERROR_NO_HW4(("%s: Failed to read file %s\n", __FUNCTION__, logstrs_path));
8340 goto fail;
8341 }
8342
8343 if (dhd_parse_logstrs_file(osh, raw_fmts, logstrs_size, temp)
8344 == BCME_OK) {
8345 filp_close(filep, NULL);
8346 #if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0))
8347 set_fs(fs);
8348 #endif
8349 return BCME_OK;
8350 }
8351
8352 fail:
8353 if (raw_fmts) {
8354 MFREE(osh, raw_fmts, logstrs_size);
8355 raw_fmts = NULL;
8356 }
8357
8358 fail1:
8359 if (!IS_ERR(filep))
8360 filp_close(filep, NULL);
8361
8362 #if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0))
8363 set_fs(fs);
8364 #endif
8365 temp->fmts = NULL;
8366 return BCME_ERROR;
8367 }
8368
8369 static int
dhd_read_map(osl_t * osh,char * fname,uint32 * ramstart,uint32 * rodata_start,uint32 * rodata_end)8370 dhd_read_map(osl_t *osh, char *fname, uint32 *ramstart, uint32 *rodata_start,
8371 uint32 *rodata_end)
8372 {
8373 struct file *filep = NULL;
8374 #if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0))
8375 mm_segment_t fs;
8376 #endif
8377 int err = BCME_ERROR;
8378
8379 if (fname == NULL) {
8380 DHD_ERROR(("%s: ERROR fname is NULL \n", __FUNCTION__));
8381 return BCME_ERROR;
8382 }
8383
8384 #if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0))
8385 fs = get_fs();
8386 set_fs(KERNEL_DS);
8387 #endif
8388
8389 filep = filp_open(fname, O_RDONLY, 0);
8390 if (IS_ERR(filep)) {
8391 DHD_ERROR_NO_HW4(("%s: Failed to open %s \n", __FUNCTION__, fname));
8392 goto fail;
8393 }
8394
8395 if ((err = dhd_parse_map_file(osh, filep, ramstart,
8396 rodata_start, rodata_end)) < 0)
8397 goto fail;
8398
8399 fail:
8400 if (!IS_ERR(filep))
8401 filp_close(filep, NULL);
8402
8403 #if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0))
8404 set_fs(fs);
8405 #endif
8406
8407 return err;
8408 }
8409
8410 static int
dhd_init_static_strs_array(osl_t * osh,dhd_event_log_t * temp,char * str_file,char * map_file)8411 dhd_init_static_strs_array(osl_t *osh, dhd_event_log_t *temp, char *str_file, char *map_file)
8412 {
8413 struct file *filep = NULL;
8414 #if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0))
8415 mm_segment_t fs;
8416 #endif
8417 char *raw_fmts = NULL;
8418 uint32 logstrs_size = 0;
8419 int error = 0;
8420 uint32 ramstart = 0;
8421 uint32 rodata_start = 0;
8422 uint32 rodata_end = 0;
8423 uint32 logfilebase = 0;
8424
8425 error = dhd_read_map(osh, map_file, &ramstart, &rodata_start, &rodata_end);
8426 if (error != BCME_OK) {
8427 DHD_ERROR(("readmap Error!! \n"));
8428 /* don't do event log parsing in actual case */
8429 if (strstr(str_file, ram_file_str) != NULL) {
8430 temp->raw_sstr = NULL;
8431 } else if (strstr(str_file, rom_file_str) != NULL) {
8432 temp->rom_raw_sstr = NULL;
8433 }
8434 return error;
8435 }
8436 DHD_ERROR(("ramstart: 0x%x, rodata_start: 0x%x, rodata_end:0x%x\n",
8437 ramstart, rodata_start, rodata_end));
8438
8439 #if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0))
8440 fs = get_fs();
8441 set_fs(KERNEL_DS);
8442 #endif
8443
8444 filep = filp_open(str_file, O_RDONLY, 0);
8445 if (IS_ERR(filep)) {
8446 DHD_ERROR(("%s: Failed to open the file %s \n", __FUNCTION__, str_file));
8447 goto fail;
8448 }
8449
8450 if (TRUE) {
8451 /* Full file size is huge. Just read required part */
8452 logstrs_size = rodata_end - rodata_start;
8453 logfilebase = rodata_start - ramstart;
8454 }
8455
8456 if (logstrs_size == 0) {
8457 DHD_ERROR(("%s: return as logstrs_size is 0\n", __FUNCTION__));
8458 goto fail1;
8459 }
8460
8461 raw_fmts = MALLOC(osh, logstrs_size);
8462 if (raw_fmts == NULL) {
8463 DHD_ERROR(("%s: Failed to allocate raw_fmts memory \n", __FUNCTION__));
8464 goto fail;
8465 }
8466
8467 if (TRUE) {
8468 error = generic_file_llseek(filep, logfilebase, SEEK_SET);
8469 if (error < 0) {
8470 DHD_ERROR(("%s: %s llseek failed %d \n", __FUNCTION__, str_file, error));
8471 goto fail;
8472 }
8473 }
8474
8475 error = vfs_read(filep, raw_fmts, logstrs_size, (&filep->f_pos));
8476 if (error != logstrs_size) {
8477 DHD_ERROR(("%s: %s read failed %d \n", __FUNCTION__, str_file, error));
8478 goto fail;
8479 }
8480
8481 if (strstr(str_file, ram_file_str) != NULL) {
8482 temp->raw_sstr = raw_fmts;
8483 temp->raw_sstr_size = logstrs_size;
8484 temp->rodata_start = rodata_start;
8485 temp->rodata_end = rodata_end;
8486 } else if (strstr(str_file, rom_file_str) != NULL) {
8487 temp->rom_raw_sstr = raw_fmts;
8488 temp->rom_raw_sstr_size = logstrs_size;
8489 temp->rom_rodata_start = rodata_start;
8490 temp->rom_rodata_end = rodata_end;
8491 }
8492
8493 filp_close(filep, NULL);
8494 #if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0))
8495 set_fs(fs);
8496 #endif
8497
8498 return BCME_OK;
8499
8500 fail:
8501 if (raw_fmts) {
8502 MFREE(osh, raw_fmts, logstrs_size);
8503 raw_fmts = NULL;
8504 }
8505
8506 fail1:
8507 if (!IS_ERR(filep))
8508 filp_close(filep, NULL);
8509
8510 #if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0))
8511 set_fs(fs);
8512 #endif
8513
8514 if (strstr(str_file, ram_file_str) != NULL) {
8515 temp->raw_sstr = NULL;
8516 } else if (strstr(str_file, rom_file_str) != NULL) {
8517 temp->rom_raw_sstr = NULL;
8518 }
8519
8520 return error;
8521 } /* dhd_init_static_strs_array */
8522
8523 #endif /* SHOW_LOGTRACE */
8524
8525 #ifdef DHD_ERPOM
8526 uint enable_erpom = 0;
8527 module_param(enable_erpom, int, 0);
8528
8529 int
dhd_wlan_power_off_handler(void * handler,unsigned char reason)8530 dhd_wlan_power_off_handler(void *handler, unsigned char reason)
8531 {
8532 dhd_pub_t *dhdp = (dhd_pub_t *)handler;
8533 bool dongle_isolation = dhdp->dongle_isolation;
8534
8535 DHD_ERROR(("%s: WLAN DHD cleanup reason: %d\n", __FUNCTION__, reason));
8536
8537 if ((reason == BY_BT_DUE_TO_BT) || (reason == BY_BT_DUE_TO_WLAN)) {
8538 #if defined(DHD_FW_COREDUMP)
8539 /* save core dump to a file */
8540 if (dhdp->memdump_enabled) {
8541 #ifdef DHD_SSSR_DUMP
8542 dhdp->collect_sssr = TRUE;
8543 #endif /* DHD_SSSR_DUMP */
8544 dhdp->memdump_type = DUMP_TYPE_DUE_TO_BT;
8545 dhd_bus_mem_dump(dhdp);
8546 }
8547 #endif /* DHD_FW_COREDUMP */
8548 }
8549
8550 /* pause data on all the interfaces */
8551 dhd_bus_stop_queue(dhdp->bus);
8552
8553 /* Devreset function will perform FLR again, to avoid it set dongle_isolation */
8554 dhdp->dongle_isolation = TRUE;
8555 dhd_bus_devreset(dhdp, 1); /* DHD structure cleanup */
8556 dhdp->dongle_isolation = dongle_isolation; /* Restore the old value */
8557 return 0;
8558 }
8559
8560 int
dhd_wlan_power_on_handler(void * handler,unsigned char reason)8561 dhd_wlan_power_on_handler(void *handler, unsigned char reason)
8562 {
8563 dhd_pub_t *dhdp = (dhd_pub_t *)handler;
8564 bool dongle_isolation = dhdp->dongle_isolation;
8565
8566 DHD_ERROR(("%s: WLAN DHD re-init reason: %d\n", __FUNCTION__, reason));
8567 /* Devreset function will perform FLR again, to avoid it set dongle_isolation */
8568 dhdp->dongle_isolation = TRUE;
8569 dhd_bus_devreset(dhdp, 0); /* DHD structure re-init */
8570 dhdp->dongle_isolation = dongle_isolation; /* Restore the old value */
8571 /* resume data on all the interfaces */
8572 dhd_bus_start_queue(dhdp->bus);
8573 return 0;
8574
8575 }
8576
8577 #endif /* DHD_ERPOM */
8578
8579 #ifdef BCMDBUS
8580 uint
dhd_get_rxsz(dhd_pub_t * pub)8581 dhd_get_rxsz(dhd_pub_t *pub)
8582 {
8583 struct net_device *net = NULL;
8584 dhd_info_t *dhd = NULL;
8585 uint rxsz;
8586
8587 /* Assign rxsz for dbus_attach */
8588 dhd = pub->info;
8589 net = dhd->iflist[0]->net;
8590 net->hard_header_len = ETH_HLEN + pub->hdrlen;
8591 rxsz = DBUS_RX_BUFFER_SIZE_DHD(net);
8592
8593 return rxsz;
8594 }
8595
8596 void
dhd_set_path(dhd_pub_t * pub)8597 dhd_set_path(dhd_pub_t *pub)
8598 {
8599 dhd_info_t *dhd = NULL;
8600
8601 dhd = pub->info;
8602
8603 /* try to download image and nvram to the dongle */
8604 if (dhd_update_fw_nv_path(dhd) && dhd->pub.bus) {
8605 DHD_INFO(("%s: fw %s, nv %s, conf %s\n",
8606 __FUNCTION__, dhd->fw_path, dhd->nv_path, dhd->conf_path));
8607 dhd_bus_update_fw_nv_path(dhd->pub.bus,
8608 dhd->fw_path, dhd->nv_path, dhd->clm_path, dhd->conf_path);
8609 }
8610 }
8611 #endif
8612
8613 /** Called once for each hardware (dongle) instance that this DHD manages */
8614 dhd_pub_t *
dhd_attach(osl_t * osh,struct dhd_bus * bus,uint bus_hdrlen,void * data)8615 dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen
8616 #ifdef BCMDBUS
8617 , void *data
8618 #endif
8619 )
8620 {
8621 dhd_info_t *dhd = NULL;
8622 struct net_device *net = NULL;
8623 char if_name[IFNAMSIZ] = {'\0'};
8624 #ifdef SHOW_LOGTRACE
8625 int ret;
8626 #endif /* SHOW_LOGTRACE */
8627 #ifdef DHD_ERPOM
8628 pom_func_handler_t *pom_handler;
8629 #endif /* DHD_ERPOM */
8630 #if defined(BCMSDIO) || defined(BCMPCIE)
8631 uint32 bus_type = -1;
8632 uint32 bus_num = -1;
8633 uint32 slot_num = -1;
8634 wifi_adapter_info_t *adapter = NULL;
8635 #elif defined(BCMDBUS)
8636 wifi_adapter_info_t *adapter = data;
8637 #endif
8638
8639 dhd_attach_states_t dhd_state = DHD_ATTACH_STATE_INIT;
8640 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
8641
8642 #ifdef PCIE_FULL_DONGLE
8643 ASSERT(sizeof(dhd_pkttag_fd_t) <= OSL_PKTTAG_SZ);
8644 ASSERT(sizeof(dhd_pkttag_fr_t) <= OSL_PKTTAG_SZ);
8645 #endif /* PCIE_FULL_DONGLE */
8646
8647 /* will implement get_ids for DBUS later */
8648 #if defined(BCMSDIO) || defined(BCMPCIE)
8649 dhd_bus_get_ids(bus, &bus_type, &bus_num, &slot_num);
8650 adapter = dhd_wifi_platform_get_adapter(bus_type, bus_num, slot_num);
8651 #endif
8652
8653 /* Allocate primary dhd_info */
8654 dhd = wifi_platform_prealloc(adapter, DHD_PREALLOC_DHD_INFO, sizeof(dhd_info_t));
8655 if (dhd == NULL) {
8656 dhd = MALLOC(osh, sizeof(dhd_info_t));
8657 if (dhd == NULL) {
8658 DHD_ERROR(("%s: OOM - alloc dhd_info\n", __FUNCTION__));
8659 goto dhd_null_flag;
8660 }
8661 }
8662 memset(dhd, 0, sizeof(dhd_info_t));
8663 dhd_state |= DHD_ATTACH_STATE_DHD_ALLOC;
8664
8665 dhd->unit = dhd_found + instance_base; /* do not increment dhd_found, yet */
8666
8667 dhd->pub.osh = osh;
8668 #ifdef DUMP_IOCTL_IOV_LIST
8669 dll_init(&(dhd->pub.dump_iovlist_head));
8670 #endif /* DUMP_IOCTL_IOV_LIST */
8671 dhd->adapter = adapter;
8672 dhd->pub.adapter = (void *)adapter;
8673 #ifdef BT_OVER_SDIO
8674 dhd->pub.is_bt_recovery_required = FALSE;
8675 mutex_init(&dhd->bus_user_lock);
8676 #endif /* BT_OVER_SDIO */
8677
8678 g_dhd_pub = &dhd->pub;
8679
8680 #ifdef DHD_DEBUG
8681 dll_init(&(dhd->pub.mw_list_head));
8682 #endif /* DHD_DEBUG */
8683
8684 #ifdef CUSTOM_FORCE_NODFS_FLAG
8685 dhd->pub.dhd_cflags |= WLAN_PLAT_NODFS_FLAG;
8686 dhd->pub.force_country_change = TRUE;
8687 #endif /* CUSTOM_FORCE_NODFS_FLAG */
8688 #ifdef CUSTOM_COUNTRY_CODE
8689 get_customized_country_code(dhd->adapter,
8690 dhd->pub.dhd_cspec.country_abbrev, &dhd->pub.dhd_cspec,
8691 dhd->pub.dhd_cflags);
8692 #endif /* CUSTOM_COUNTRY_CODE */
8693 #ifndef BCMDBUS
8694 dhd->thr_dpc_ctl.thr_pid = DHD_PID_KT_TL_INVALID;
8695 dhd->thr_wdt_ctl.thr_pid = DHD_PID_KT_INVALID;
8696 #ifdef DHD_WET
8697 dhd->pub.wet_info = dhd_get_wet_info(&dhd->pub);
8698 #endif /* DHD_WET */
8699 /* Initialize thread based operation and lock */
8700 sema_init(&dhd->sdsem, 1);
8701 #endif /* !BCMDBUS */
8702 dhd->pub.pcie_txs_metadata_enable = pcie_txs_metadata_enable;
8703
8704 /* Link to info module */
8705 dhd->pub.info = dhd;
8706
8707 /* Link to bus module */
8708 dhd->pub.bus = bus;
8709 dhd->pub.hdrlen = bus_hdrlen;
8710 dhd->pub.txoff = FALSE;
8711
8712 /* dhd_conf must be attached after linking dhd to dhd->pub.info,
8713 * because dhd_detech will check .info is NULL or not.
8714 */
8715 if (dhd_conf_attach(&dhd->pub) != 0) {
8716 DHD_ERROR(("dhd_conf_attach failed\n"));
8717 goto fail;
8718 }
8719 #ifndef BCMDBUS
8720 dhd_conf_reset(&dhd->pub);
8721 dhd_conf_set_chiprev(&dhd->pub, dhd_bus_chip(bus), dhd_bus_chiprev(bus));
8722 dhd_conf_preinit(&dhd->pub);
8723 #endif /* !BCMDBUS */
8724
8725 /* Some DHD modules (e.g. cfg80211) configures operation mode based on firmware name.
8726 * This is indeed a hack but we have to make it work properly before we have a better
8727 * solution
8728 */
8729 dhd_update_fw_nv_path(dhd);
8730
8731 /* Set network interface name if it was provided as module parameter */
8732 if (iface_name[0]) {
8733 int len;
8734 char ch;
8735 strncpy(if_name, iface_name, IFNAMSIZ);
8736 if_name[IFNAMSIZ - 1] = 0;
8737 len = strlen(if_name);
8738 ch = if_name[len - 1];
8739 if ((ch > '9' || ch < '0') && (len < IFNAMSIZ - 2))
8740 strncat(if_name, "%d", IFNAMSIZ - len - 1);
8741 }
8742
8743 /* Passing NULL to dngl_name to ensure host gets if_name in dngl_name member */
8744 net = dhd_allocate_if(&dhd->pub, 0, if_name, NULL, 0, TRUE, NULL);
8745 if (net == NULL) {
8746 goto fail;
8747 }
8748 mutex_init(&dhd->pub.ndev_op_sync);
8749
8750 dhd_state |= DHD_ATTACH_STATE_ADD_IF;
8751 #ifdef DHD_L2_FILTER
8752 /* initialize the l2_filter_cnt */
8753 dhd->pub.l2_filter_cnt = 0;
8754 #endif // endif
8755
8756 #ifndef CONFIG_AP6XXX_WIFI6_HDF
8757 net->netdev_ops = NULL;
8758 #endif
8759
8760 mutex_init(&dhd->dhd_iovar_mutex);
8761 sema_init(&dhd->proto_sem, 1);
8762 #ifdef DHD_ULP
8763 if (!(dhd_ulp_init(osh, &dhd->pub)))
8764 goto fail;
8765 #endif /* DHD_ULP */
8766
8767 #ifdef PROP_TXSTATUS
8768 spin_lock_init(&dhd->wlfc_spinlock);
8769
8770 dhd->pub.skip_fc = dhd_wlfc_skip_fc;
8771 dhd->pub.plat_init = dhd_wlfc_plat_init;
8772 dhd->pub.plat_deinit = dhd_wlfc_plat_deinit;
8773
8774 #ifdef DHD_WLFC_THREAD
8775 init_waitqueue_head(&dhd->pub.wlfc_wqhead);
8776 dhd->pub.wlfc_thread = kthread_create(dhd_wlfc_transfer_packets, &dhd->pub, "wlfc-thread");
8777 if (IS_ERR(dhd->pub.wlfc_thread)) {
8778 DHD_ERROR(("create wlfc thread failed\n"));
8779 goto fail;
8780 } else {
8781 wake_up_process(dhd->pub.wlfc_thread);
8782 }
8783 #endif /* DHD_WLFC_THREAD */
8784 #endif /* PROP_TXSTATUS */
8785
8786 /* Initialize other structure content */
8787 init_waitqueue_head(&dhd->ioctl_resp_wait);
8788 init_waitqueue_head(&dhd->d3ack_wait);
8789 init_waitqueue_head(&dhd->ctrl_wait);
8790 init_waitqueue_head(&dhd->dhd_bus_busy_state_wait);
8791 init_waitqueue_head(&dhd->dmaxfer_wait);
8792 init_waitqueue_head(&dhd->pub.tx_completion_wait);
8793 dhd->pub.dhd_bus_busy_state = 0;
8794 /* Initialize the spinlocks */
8795 spin_lock_init(&dhd->sdlock);
8796 spin_lock_init(&dhd->txqlock);
8797 spin_lock_init(&dhd->dhd_lock);
8798 spin_lock_init(&dhd->rxf_lock);
8799 #ifdef WLTDLS
8800 spin_lock_init(&dhd->pub.tdls_lock);
8801 #endif /* WLTDLS */
8802 #if defined(RXFRAME_THREAD)
8803 dhd->rxthread_enabled = TRUE;
8804 #endif /* defined(RXFRAME_THREAD) */
8805
8806 #ifdef DHDTCPACK_SUPPRESS
8807 spin_lock_init(&dhd->tcpack_lock);
8808 #endif /* DHDTCPACK_SUPPRESS */
8809
8810 /* Initialize Wakelock stuff */
8811 spin_lock_init(&dhd->wakelock_spinlock);
8812 spin_lock_init(&dhd->wakelock_evt_spinlock);
8813 DHD_OS_WAKE_LOCK_INIT(dhd);
8814 dhd->wakelock_counter = 0;
8815 /* wakelocks prevent a system from going into a low power state */
8816 #ifdef CONFIG_HAS_WAKELOCK
8817 // terence 20161023: can not destroy wl_wifi when wlan down, it will happen null pointer in dhd_ioctl_entry
8818 wake_lock_init(&dhd->wl_wifi, WAKE_LOCK_SUSPEND, "wlan_wake");
8819 wake_lock_init(&dhd->wl_wdwake, WAKE_LOCK_SUSPEND, "wlan_wd_wake");
8820 #endif /* CONFIG_HAS_WAKELOCK */
8821
8822 mutex_init(&dhd->dhd_net_if_mutex);
8823 mutex_init(&dhd->dhd_suspend_mutex);
8824 #if defined(PKT_FILTER_SUPPORT) && defined(APF)
8825 mutex_init(&dhd->dhd_apf_mutex);
8826 #endif /* PKT_FILTER_SUPPORT && APF */
8827 dhd_state |= DHD_ATTACH_STATE_WAKELOCKS_INIT;
8828
8829 /* Attach and link in the protocol */
8830 if (dhd_prot_attach(&dhd->pub) != 0) {
8831 DHD_ERROR(("dhd_prot_attach failed\n"));
8832 goto fail;
8833 }
8834 dhd_state |= DHD_ATTACH_STATE_PROT_ATTACH;
8835
8836 #ifdef WL_CFG80211
8837 spin_lock_init(&dhd->pub.up_lock);
8838 /* Attach and link in the cfg80211 */
8839 if (unlikely(wl_cfg80211_attach(net, &dhd->pub))) {
8840 DHD_ERROR(("wl_cfg80211_attach failed\n"));
8841 goto fail;
8842 }
8843
8844 dhd_monitor_init(&dhd->pub);
8845 dhd_state |= DHD_ATTACH_STATE_CFG80211;
8846 #endif // endif
8847
8848 #if defined(WL_EXT_IAPSTA) || defined(USE_IW) || defined(WL_ESCAN)
8849 if (wl_ext_event_attach(net, &dhd->pub) != 0) {
8850 DHD_ERROR(("wl_ext_event_attach failed\n"));
8851 goto fail;
8852 }
8853 #ifdef WL_ESCAN
8854 /* Attach and link in the escan */
8855 if (wl_escan_attach(net, &dhd->pub) != 0) {
8856 DHD_ERROR(("wl_escan_attach failed\n"));
8857 goto fail;
8858 }
8859 #endif /* WL_ESCAN */
8860 #ifdef WL_EXT_IAPSTA
8861 if (wl_ext_iapsta_attach(&dhd->pub) != 0) {
8862 DHD_ERROR(("wl_ext_iapsta_attach failed\n"));
8863 goto fail;
8864 }
8865 #endif /* WL_EXT_IAPSTA */
8866 #endif /* WL_EXT_IAPSTA || USE_IW || WL_ESCAN */
8867 #ifdef WL_EXT_GENL
8868 if (wl_ext_genl_init(net)) {
8869 DHD_ERROR(("wl_ext_genl_init failed\n"));
8870 goto fail;
8871 }
8872 #endif
8873 #if defined(WL_WIRELESS_EXT)
8874 /* Attach and link in the iw */
8875 if (wl_iw_attach(net, &dhd->pub) != 0) {
8876 DHD_ERROR(("wl_iw_attach failed\n"));
8877 goto fail;
8878 }
8879 dhd_state |= DHD_ATTACH_STATE_WL_ATTACH;
8880 #endif /* defined(WL_WIRELESS_EXT) */
8881
8882 #ifdef SHOW_LOGTRACE
8883 ret = dhd_init_logstrs_array(osh, &dhd->event_data);
8884 if (ret == BCME_OK) {
8885 dhd_init_static_strs_array(osh, &dhd->event_data, st_str_file_path, map_file_path);
8886 dhd_init_static_strs_array(osh, &dhd->event_data, rom_st_str_file_path,
8887 rom_map_file_path);
8888 dhd_state |= DHD_ATTACH_LOGTRACE_INIT;
8889 }
8890 #endif /* SHOW_LOGTRACE */
8891
8892 /* attach debug if support */
8893 if (dhd_os_dbg_attach(&dhd->pub)) {
8894 DHD_ERROR(("%s debug module attach failed\n", __FUNCTION__));
8895 goto fail;
8896 }
8897 #ifdef DEBUGABILITY
8898 #if defined(SHOW_LOGTRACE) && defined(DBG_RING_LOG_INIT_DEFAULT)
8899 /* enable verbose ring to support dump_trace_buf */
8900 dhd_os_start_logging(&dhd->pub, FW_VERBOSE_RING_NAME, 3, 0, 0, 0);
8901 #endif /* SHOW_LOGTRACE */
8902
8903 #ifdef DBG_PKT_MON
8904 dhd->pub.dbg->pkt_mon_lock = dhd_os_spin_lock_init(dhd->pub.osh);
8905 #ifdef DBG_PKT_MON_INIT_DEFAULT
8906 dhd_os_dbg_attach_pkt_monitor(&dhd->pub);
8907 #endif /* DBG_PKT_MON_INIT_DEFAULT */
8908 #endif /* DBG_PKT_MON */
8909 #endif /* DEBUGABILITY */
8910
8911 #ifdef DHD_STATUS_LOGGING
8912 dhd->pub.statlog = dhd_attach_statlog(&dhd->pub, MAX_STATLOG_ITEM,
8913 MAX_STATLOG_REQ_ITEM, STATLOG_LOGBUF_LEN);
8914 if (dhd->pub.statlog == NULL) {
8915 DHD_ERROR(("%s: alloc statlog failed\n", __FUNCTION__));
8916 }
8917 #endif /* DHD_STATUS_LOGGING */
8918
8919 #ifdef DHD_LOG_DUMP
8920 dhd_log_dump_init(&dhd->pub);
8921 #endif /* DHD_LOG_DUMP */
8922 #ifdef DHD_PKTDUMP_ROAM
8923 dhd_dump_pkt_init(&dhd->pub);
8924 #endif /* DHD_PKTDUMP_ROAM */
8925
8926 if (dhd_sta_pool_init(&dhd->pub, DHD_MAX_STA) != BCME_OK) {
8927 DHD_ERROR(("%s: Initializing %u sta\n", __FUNCTION__, DHD_MAX_STA));
8928 goto fail;
8929 }
8930
8931 #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
8932 dhd->tx_wq = alloc_workqueue("bcmdhd-tx-wq", WQ_HIGHPRI | WQ_UNBOUND | WQ_MEM_RECLAIM, 1);
8933 if (!dhd->tx_wq) {
8934 DHD_ERROR(("%s: alloc_workqueue(bcmdhd-tx-wq) failed\n", __FUNCTION__));
8935 goto fail;
8936 }
8937 dhd->rx_wq = alloc_workqueue("bcmdhd-rx-wq", WQ_HIGHPRI | WQ_UNBOUND | WQ_MEM_RECLAIM, 1);
8938 if (!dhd->rx_wq) {
8939 DHD_ERROR(("%s: alloc_workqueue(bcmdhd-rx-wq) failed\n", __FUNCTION__));
8940 destroy_workqueue(dhd->tx_wq);
8941 dhd->tx_wq = NULL;
8942 goto fail;
8943 }
8944 #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
8945
8946 #ifndef BCMDBUS
8947 /* Set up the watchdog timer */
8948 init_timer_compat(&dhd->timer, dhd_watchdog, dhd);
8949 dhd->default_wd_interval = dhd_watchdog_ms;
8950
8951 if (dhd_watchdog_prio >= 0) {
8952 /* Initialize watchdog thread */
8953 PROC_START(dhd_watchdog_thread, dhd, &dhd->thr_wdt_ctl, 0, "dhd_watchdog_thread");
8954 if (dhd->thr_wdt_ctl.thr_pid < 0) {
8955 goto fail;
8956 }
8957
8958 } else {
8959 dhd->thr_wdt_ctl.thr_pid = -1;
8960 }
8961
8962 #ifdef SHOW_LOGTRACE
8963 skb_queue_head_init(&dhd->evt_trace_queue);
8964
8965 /* Create ring proc entries */
8966 dhd_dbg_ring_proc_create(&dhd->pub);
8967 #endif /* SHOW_LOGTRACE */
8968
8969 /* Set up the bottom half handler */
8970 if (dhd_dpc_prio >= 0) {
8971 /* Initialize DPC thread */
8972 PROC_START(dhd_dpc_thread, dhd, &dhd->thr_dpc_ctl, 0, "dhd_dpc");
8973 if (dhd->thr_dpc_ctl.thr_pid < 0) {
8974 goto fail;
8975 }
8976 } else {
8977 /* use tasklet for dpc */
8978 tasklet_init(&dhd->tasklet, dhd_dpc, (ulong)dhd);
8979 dhd->thr_dpc_ctl.thr_pid = -1;
8980 }
8981
8982 if (dhd->rxthread_enabled) {
8983 bzero(&dhd->pub.skbbuf[0], sizeof(void *) * MAXSKBPEND);
8984 /* Initialize RXF thread */
8985 PROC_START(dhd_rxf_thread, dhd, &dhd->thr_rxf_ctl, 0, "dhd_rxf");
8986 if (dhd->thr_rxf_ctl.thr_pid < 0) {
8987 goto fail;
8988 }
8989 }
8990 #endif /* !BCMDBUS */
8991
8992 dhd_state |= DHD_ATTACH_STATE_THREADS_CREATED;
8993
8994 #if defined(CONFIG_PM_SLEEP)
8995 if (!dhd_pm_notifier_registered) {
8996 dhd_pm_notifier_registered = TRUE;
8997 dhd->pm_notifier.notifier_call = dhd_pm_callback;
8998 dhd->pm_notifier.priority = 10;
8999 register_pm_notifier(&dhd->pm_notifier);
9000 }
9001
9002 #endif /* CONFIG_PM_SLEEP */
9003
9004 #if defined(CONFIG_HAS_EARLYSUSPEND) && defined(DHD_USE_EARLYSUSPEND)
9005 dhd->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 20;
9006 dhd->early_suspend.suspend = dhd_early_suspend;
9007 dhd->early_suspend.resume = dhd_late_resume;
9008 register_early_suspend(&dhd->early_suspend);
9009 dhd_state |= DHD_ATTACH_STATE_EARLYSUSPEND_DONE;
9010 #endif /* CONFIG_HAS_EARLYSUSPEND && DHD_USE_EARLYSUSPEND */
9011
9012 #ifdef ARP_OFFLOAD_SUPPORT
9013 dhd->pend_ipaddr = 0;
9014 if (!dhd_inetaddr_notifier_registered) {
9015 dhd_inetaddr_notifier_registered = TRUE;
9016 register_inetaddr_notifier(&dhd_inetaddr_notifier);
9017 }
9018 #endif /* ARP_OFFLOAD_SUPPORT */
9019
9020 #if defined(CONFIG_IPV6) && defined(IPV6_NDO_SUPPORT)
9021 if (!dhd_inet6addr_notifier_registered) {
9022 dhd_inet6addr_notifier_registered = TRUE;
9023 register_inet6addr_notifier(&dhd_inet6addr_notifier);
9024 }
9025 #endif /* CONFIG_IPV6 && IPV6_NDO_SUPPORT */
9026 dhd->dhd_deferred_wq = dhd_deferred_work_init((void *)dhd);
9027 INIT_WORK(&dhd->dhd_hang_process_work, dhd_hang_process);
9028 #ifdef DEBUG_CPU_FREQ
9029 dhd->new_freq = alloc_percpu(int);
9030 dhd->freq_trans.notifier_call = dhd_cpufreq_notifier;
9031 cpufreq_register_notifier(&dhd->freq_trans, CPUFREQ_TRANSITION_NOTIFIER);
9032 #endif // endif
9033 #ifdef DHDTCPACK_SUPPRESS
9034 #ifdef BCMSDIO
9035 dhd_tcpack_suppress_set(&dhd->pub, TCPACK_SUP_DELAYTX);
9036 #elif defined(BCMPCIE)
9037 dhd_tcpack_suppress_set(&dhd->pub, TCPACK_SUP_HOLD);
9038 #else
9039 dhd_tcpack_suppress_set(&dhd->pub, TCPACK_SUP_OFF);
9040 #endif /* BCMSDIO */
9041 #endif /* DHDTCPACK_SUPPRESS */
9042
9043 #if defined(BCM_DNGL_EMBEDIMAGE) || defined(BCM_REQUEST_FW)
9044 #endif /* defined(BCM_DNGL_EMBEDIMAGE) || defined(BCM_REQUEST_FW) */
9045
9046 #ifdef DHD_DEBUG_PAGEALLOC
9047 register_page_corrupt_cb(dhd_page_corrupt_cb, &dhd->pub);
9048 #endif /* DHD_DEBUG_PAGEALLOC */
9049
9050 #if defined(DHD_LB)
9051
9052 dhd_lb_set_default_cpus(dhd);
9053 DHD_LB_STATS_INIT(&dhd->pub);
9054
9055 /* Initialize the CPU Masks */
9056 if (dhd_cpumasks_init(dhd) == 0) {
9057 /* Now we have the current CPU maps, run through candidacy */
9058 dhd_select_cpu_candidacy(dhd);
9059
9060 /* Register the call backs to CPU Hotplug sub-system */
9061 dhd_register_cpuhp_callback(dhd);
9062
9063 } else {
9064 /*
9065 * We are unable to initialize CPU masks, so candidacy algorithm
9066 * won't run, but still Load Balancing will be honoured based
9067 * on the CPUs allocated for a given job statically during init
9068 */
9069 dhd->cpu_notifier.notifier_call = NULL;
9070 DHD_ERROR(("%s():dhd_cpumasks_init failed CPUs for JOB would be static\n",
9071 __FUNCTION__));
9072 }
9073
9074 #ifdef DHD_LB_TXP
9075 #ifdef DHD_LB_TXP_DEFAULT_ENAB
9076 /* Trun ON the feature by default */
9077 atomic_set(&dhd->lb_txp_active, 1);
9078 #else
9079 /* Trun OFF the feature by default */
9080 atomic_set(&dhd->lb_txp_active, 0);
9081 #endif /* DHD_LB_TXP_DEFAULT_ENAB */
9082 #endif /* DHD_LB_TXP */
9083
9084 #ifdef DHD_LB_RXP
9085 /* Trun ON the feature by default */
9086 atomic_set(&dhd->lb_rxp_active, 1);
9087 #endif /* DHD_LB_RXP */
9088
9089 /* Initialize the Load Balancing Tasklets and Napi object */
9090 #if defined(DHD_LB_TXC)
9091 tasklet_init(&dhd->tx_compl_tasklet,
9092 dhd_lb_tx_compl_handler, (ulong)(&dhd->pub));
9093 INIT_WORK(&dhd->tx_compl_dispatcher_work, dhd_tx_compl_dispatcher_fn);
9094 DHD_INFO(("%s load balance init tx_compl_tasklet\n", __FUNCTION__));
9095 #endif /* DHD_LB_TXC */
9096 #if defined(DHD_LB_RXC)
9097 tasklet_init(&dhd->rx_compl_tasklet,
9098 dhd_lb_rx_compl_handler, (ulong)(&dhd->pub));
9099 INIT_WORK(&dhd->rx_compl_dispatcher_work, dhd_rx_compl_dispatcher_fn);
9100 DHD_INFO(("%s load balance init rx_compl_tasklet\n", __FUNCTION__));
9101 #endif /* DHD_LB_RXC */
9102
9103 #if defined(DHD_LB_RXP)
9104 __skb_queue_head_init(&dhd->rx_pend_queue);
9105 skb_queue_head_init(&dhd->rx_napi_queue);
9106 /* Initialize the work that dispatches NAPI job to a given core */
9107 INIT_WORK(&dhd->rx_napi_dispatcher_work, dhd_rx_napi_dispatcher_fn);
9108 DHD_INFO(("%s load balance init rx_napi_queue\n", __FUNCTION__));
9109 #endif /* DHD_LB_RXP */
9110
9111 #if defined(DHD_LB_TXP)
9112 INIT_WORK(&dhd->tx_dispatcher_work, dhd_tx_dispatcher_work);
9113 skb_queue_head_init(&dhd->tx_pend_queue);
9114 /* Initialize the work that dispatches TX job to a given core */
9115 tasklet_init(&dhd->tx_tasklet,
9116 dhd_lb_tx_handler, (ulong)(dhd));
9117 DHD_INFO(("%s load balance init tx_pend_queue\n", __FUNCTION__));
9118 #endif /* DHD_LB_TXP */
9119
9120 dhd_state |= DHD_ATTACH_STATE_LB_ATTACH_DONE;
9121 #endif /* DHD_LB */
9122
9123 #if defined(DNGL_AXI_ERROR_LOGGING) && defined(DHD_USE_WQ_FOR_DNGL_AXI_ERROR)
9124 INIT_WORK(&dhd->axi_error_dispatcher_work, dhd_axi_error_dispatcher_fn);
9125 #endif /* DNGL_AXI_ERROR_LOGGING && DHD_USE_WQ_FOR_DNGL_AXI_ERROR */
9126
9127 #if defined(BCMPCIE)
9128 dhd->pub.extended_trap_data = MALLOCZ(osh, BCMPCIE_EXT_TRAP_DATA_MAXLEN);
9129 if (dhd->pub.extended_trap_data == NULL) {
9130 DHD_ERROR(("%s: Failed to alloc extended_trap_data\n", __FUNCTION__));
9131 }
9132 #ifdef DNGL_AXI_ERROR_LOGGING
9133 dhd->pub.axi_err_dump = MALLOCZ(osh, sizeof(dhd_axi_error_dump_t));
9134 if (dhd->pub.axi_err_dump == NULL) {
9135 DHD_ERROR(("%s: Failed to alloc axi_err_dump\n", __FUNCTION__));
9136 }
9137 #endif /* DNGL_AXI_ERROR_LOGGING */
9138 #endif /* BCMPCIE && ETD */
9139
9140 #ifdef SHOW_LOGTRACE
9141 if (dhd_init_logtrace_process(dhd) != BCME_OK) {
9142 goto fail;
9143 }
9144 #endif /* SHOW_LOGTRACE */
9145
9146 DHD_SSSR_MEMPOOL_INIT(&dhd->pub);
9147
9148 #ifdef EWP_EDL
9149 if (host_edl_support) {
9150 if (DHD_EDL_MEM_INIT(&dhd->pub) != BCME_OK) {
9151 host_edl_support = FALSE;
9152 }
9153 }
9154 #endif /* EWP_EDL */
9155
9156 (void)dhd_sysfs_init(dhd);
9157
9158 #ifdef WL_NATOE
9159 /* Open Netlink socket for NF_CONNTRACK notifications */
9160 dhd->pub.nfct = dhd_ct_open(&dhd->pub, NFNL_SUBSYS_CTNETLINK | NFNL_SUBSYS_CTNETLINK_EXP,
9161 CT_ALL);
9162 #endif /* WL_NATOE */
9163
9164 dhd_state |= DHD_ATTACH_STATE_DONE;
9165 dhd->dhd_state = dhd_state;
9166
9167 dhd_found++;
9168
9169 #ifdef CSI_SUPPORT
9170 dhd_csi_init(&dhd->pub);
9171 #endif /* CSI_SUPPORT */
9172
9173 #ifdef DHD_DUMP_MNGR
9174 dhd->pub.dump_file_manage =
9175 (dhd_dump_file_manage_t *)MALLOCZ(dhd->pub.osh, sizeof(dhd_dump_file_manage_t));
9176 if (unlikely(!dhd->pub.dump_file_manage)) {
9177 DHD_ERROR(("%s(): could not allocate memory for - "
9178 "dhd_dump_file_manage_t\n", __FUNCTION__));
9179 }
9180 #endif /* DHD_DUMP_MNGR */
9181 #ifdef DHD_FW_COREDUMP
9182 /* Set memdump default values */
9183 dhd->pub.memdump_enabled = DUMP_MEMFILE_BUGON;
9184 /* Check the memdump capability */
9185 dhd_get_memdump_info(&dhd->pub);
9186 #endif /* DHD_FW_COREDUMP */
9187
9188 #ifdef DHD_ERPOM
9189 if (enable_erpom) {
9190 pom_handler = &dhd->pub.pom_wlan_handler;
9191 pom_handler->func_id = WLAN_FUNC_ID;
9192 pom_handler->handler = (void *)g_dhd_pub;
9193 pom_handler->power_off = dhd_wlan_power_off_handler;
9194 pom_handler->power_on = dhd_wlan_power_on_handler;
9195
9196 dhd->pub.pom_func_register = NULL;
9197 dhd->pub.pom_func_deregister = NULL;
9198 dhd->pub.pom_toggle_reg_on = NULL;
9199
9200 dhd->pub.pom_func_register = symbol_get(pom_func_register);
9201 dhd->pub.pom_func_deregister = symbol_get(pom_func_deregister);
9202 dhd->pub.pom_toggle_reg_on = symbol_get(pom_toggle_reg_on);
9203
9204 symbol_put(pom_func_register);
9205 symbol_put(pom_func_deregister);
9206 symbol_put(pom_toggle_reg_on);
9207
9208 if (!dhd->pub.pom_func_register ||
9209 !dhd->pub.pom_func_deregister ||
9210 !dhd->pub.pom_toggle_reg_on) {
9211 DHD_ERROR(("%s, enable_erpom enabled through module parameter but "
9212 "POM is not loaded\n", __FUNCTION__));
9213 ASSERT(0);
9214 goto fail;
9215 }
9216 dhd->pub.pom_func_register(pom_handler);
9217 dhd->pub.enable_erpom = TRUE;
9218
9219 }
9220 #endif /* DHD_ERPOM */
9221 return &dhd->pub;
9222
9223 fail:
9224 if (dhd_state >= DHD_ATTACH_STATE_DHD_ALLOC) {
9225 DHD_TRACE(("%s: Calling dhd_detach dhd_state 0x%x &dhd->pub %p\n",
9226 __FUNCTION__, dhd_state, &dhd->pub));
9227 dhd->dhd_state = dhd_state;
9228 dhd_detach(&dhd->pub);
9229 dhd_free(&dhd->pub);
9230 }
9231
9232 dhd_null_flag:
9233 return NULL;
9234 }
9235
dhd_get_fw_mode(dhd_info_t * dhdinfo)9236 int dhd_get_fw_mode(dhd_info_t *dhdinfo)
9237 {
9238 if (strstr(dhdinfo->fw_path, "_apsta") != NULL)
9239 return DHD_FLAG_HOSTAP_MODE;
9240 if (strstr(dhdinfo->fw_path, "_p2p") != NULL)
9241 return DHD_FLAG_P2P_MODE;
9242 if (strstr(dhdinfo->fw_path, "_ibss") != NULL)
9243 return DHD_FLAG_IBSS_MODE;
9244 if (strstr(dhdinfo->fw_path, "_mfg") != NULL)
9245 return DHD_FLAG_MFG_MODE;
9246
9247 return DHD_FLAG_STA_MODE;
9248 }
9249
dhd_bus_get_fw_mode(dhd_pub_t * dhdp)9250 int dhd_bus_get_fw_mode(dhd_pub_t *dhdp)
9251 {
9252 return dhd_get_fw_mode(dhdp->info);
9253 }
9254
9255 extern char * nvram_get(const char *name);
9256 extern int rkwifi_set_firmware(char *fw, char *nvram);
dhd_update_fw_nv_path(dhd_info_t * dhdinfo)9257 bool dhd_update_fw_nv_path(dhd_info_t *dhdinfo)
9258 {
9259 int fw_len;
9260 int nv_len;
9261 int clm_len;
9262 int conf_len;
9263 const char *fw = NULL;
9264 const char *nv = NULL;
9265 const char *clm = NULL;
9266 const char *conf = NULL;
9267 char firmware[100] = {0};
9268 char nvram[100] = {0};
9269 #ifdef DHD_UCODE_DOWNLOAD
9270 int uc_len;
9271 const char *uc = NULL;
9272 #endif /* DHD_UCODE_DOWNLOAD */
9273 wifi_adapter_info_t *adapter = dhdinfo->adapter;
9274 int fw_path_len = sizeof(dhdinfo->fw_path);
9275 int nv_path_len = sizeof(dhdinfo->nv_path);
9276
9277 /* Update firmware and nvram path. The path may be from adapter info or module parameter
9278 * The path from adapter info is used for initialization only (as it won't change).
9279 *
9280 * The firmware_path/nvram_path module parameter may be changed by the system at run
9281 * time. When it changes we need to copy it to dhdinfo->fw_path. Also Android private
9282 * command may change dhdinfo->fw_path. As such we need to clear the path info in
9283 * module parameter after it is copied. We won't update the path until the module parameter
9284 * is changed again (first character is not '\0')
9285 */
9286
9287 /* set default firmware and nvram path for built-in type driver */
9288 // if (!dhd_download_fw_on_driverload) {
9289 rkwifi_set_firmware(firmware, nvram);
9290 #ifdef CONFIG_BCMDHD_FW_PATH
9291 fw = VENDOR_PATH CONFIG_BCMDHD_FW_PATH;
9292 #else
9293 fw = firmware;
9294 #endif /* CONFIG_BCMDHD_FW_PATH */
9295 #ifdef CONFIG_BCMDHD_NVRAM_PATH
9296 nv = VENDOR_PATH CONFIG_BCMDHD_NVRAM_PATH;
9297 #else
9298 nv = nvram;
9299 #endif /* CONFIG_BCMDHD_NVRAM_PATH */
9300 // }
9301
9302 /* check if we need to initialize the path */
9303 if (dhdinfo->fw_path[0] == '\0') {
9304 if (adapter && adapter->fw_path && adapter->fw_path[0] != '\0')
9305 fw = adapter->fw_path;
9306 }
9307 if (dhdinfo->nv_path[0] == '\0') {
9308 if (adapter && adapter->nv_path && adapter->nv_path[0] != '\0')
9309 nv = adapter->nv_path;
9310 }
9311 if (dhdinfo->clm_path[0] == '\0') {
9312 if (adapter && adapter->clm_path && adapter->clm_path[0] != '\0')
9313 clm = adapter->clm_path;
9314 }
9315 if (dhdinfo->conf_path[0] == '\0') {
9316 if (adapter && adapter->conf_path && adapter->conf_path[0] != '\0')
9317 conf = adapter->conf_path;
9318 }
9319
9320 /* Use module parameter if it is valid, EVEN IF the path has not been initialized
9321 *
9322 * TODO: need a solution for multi-chip, can't use the same firmware for all chips
9323 */
9324 if (firmware_path[0] != '\0')
9325 fw = firmware_path;
9326
9327 if (nvram_path[0] != '\0')
9328 nv = nvram_path;
9329 if (clm_path[0] != '\0')
9330 clm = clm_path;
9331 if (config_path[0] != '\0')
9332 conf = config_path;
9333
9334 #ifdef DHD_UCODE_DOWNLOAD
9335 if (ucode_path[0] != '\0')
9336 uc = ucode_path;
9337 #endif /* DHD_UCODE_DOWNLOAD */
9338
9339 if (fw && fw[0] != '\0') {
9340 fw_len = strlen(fw);
9341 if (fw_len >= fw_path_len) {
9342 DHD_ERROR(("fw path len exceeds max len of dhdinfo->fw_path\n"));
9343 return FALSE;
9344 }
9345 strncpy(dhdinfo->fw_path, fw, fw_path_len);
9346 if (dhdinfo->fw_path[fw_len-1] == '\n')
9347 dhdinfo->fw_path[fw_len-1] = '\0';
9348 }
9349 if (nv && nv[0] != '\0') {
9350 nv_len = strlen(nv);
9351 if (nv_len >= nv_path_len) {
9352 DHD_ERROR(("nvram path len exceeds max len of dhdinfo->nv_path\n"));
9353 return FALSE;
9354 }
9355 memset(dhdinfo->nv_path, 0, nv_path_len);
9356 strncpy(dhdinfo->nv_path, nv, nv_path_len);
9357 dhdinfo->nv_path[nv_len] = '\0';
9358 #ifdef DHD_USE_SINGLE_NVRAM_FILE
9359 /* Remove "_net" or "_mfg" tag from current nvram path */
9360 {
9361 char *nvram_tag = "nvram_";
9362 char *ext_tag = ".txt";
9363 char *sp_nvram = strnstr(dhdinfo->nv_path, nvram_tag, nv_path_len);
9364 bool valid_buf = sp_nvram && ((uint32)(sp_nvram + strlen(nvram_tag) +
9365 strlen(ext_tag) - dhdinfo->nv_path) <= nv_path_len);
9366 if (valid_buf) {
9367 char *sp = sp_nvram + strlen(nvram_tag) - 1;
9368 uint32 padding_size = (uint32)(dhdinfo->nv_path +
9369 nv_path_len - sp);
9370 memset(sp, 0, padding_size);
9371 strncat(dhdinfo->nv_path, ext_tag, strlen(ext_tag));
9372 nv_len = strlen(dhdinfo->nv_path);
9373 DHD_INFO(("%s: new nvram path = %s\n",
9374 __FUNCTION__, dhdinfo->nv_path));
9375 } else if (sp_nvram) {
9376 DHD_ERROR(("%s: buffer space for nvram path is not enough\n",
9377 __FUNCTION__));
9378 return FALSE;
9379 } else {
9380 DHD_ERROR(("%s: Couldn't find the nvram tag. current"
9381 " nvram path = %s\n", __FUNCTION__, dhdinfo->nv_path));
9382 }
9383 }
9384 #endif /* DHD_USE_SINGLE_NVRAM_FILE */
9385 if (dhdinfo->nv_path[nv_len-1] == '\n')
9386 dhdinfo->nv_path[nv_len-1] = '\0';
9387 }
9388 if (clm && clm[0] != '\0') {
9389 clm_len = strlen(clm);
9390 if (clm_len >= sizeof(dhdinfo->clm_path)) {
9391 DHD_ERROR(("clm path len exceeds max len of dhdinfo->clm_path\n"));
9392 return FALSE;
9393 }
9394 strncpy(dhdinfo->clm_path, clm, sizeof(dhdinfo->clm_path));
9395 if (dhdinfo->clm_path[clm_len-1] == '\n')
9396 dhdinfo->clm_path[clm_len-1] = '\0';
9397 }
9398 if (conf && conf[0] != '\0') {
9399 conf_len = strlen(conf);
9400 if (conf_len >= sizeof(dhdinfo->conf_path)) {
9401 DHD_ERROR(("config path len exceeds max len of dhdinfo->conf_path\n"));
9402 return FALSE;
9403 }
9404 strncpy(dhdinfo->conf_path, conf, sizeof(dhdinfo->conf_path));
9405 if (dhdinfo->conf_path[conf_len-1] == '\n')
9406 dhdinfo->conf_path[conf_len-1] = '\0';
9407 }
9408 #ifdef DHD_UCODE_DOWNLOAD
9409 if (uc && uc[0] != '\0') {
9410 uc_len = strlen(uc);
9411 if (uc_len >= sizeof(dhdinfo->uc_path)) {
9412 DHD_ERROR(("uc path len exceeds max len of dhdinfo->uc_path\n"));
9413 return FALSE;
9414 }
9415 strncpy(dhdinfo->uc_path, uc, sizeof(dhdinfo->uc_path));
9416 if (dhdinfo->uc_path[uc_len-1] == '\n')
9417 dhdinfo->uc_path[uc_len-1] = '\0';
9418 }
9419 #endif /* DHD_UCODE_DOWNLOAD */
9420
9421 #if 0
9422 /* clear the path in module parameter */
9423 if (dhd_download_fw_on_driverload) {
9424 firmware_path[0] = '\0';
9425 nvram_path[0] = '\0';
9426 clm_path[0] = '\0';
9427 config_path[0] = '\0';
9428 }
9429 #endif
9430 #ifdef DHD_UCODE_DOWNLOAD
9431 ucode_path[0] = '\0';
9432 DHD_ERROR(("ucode path: %s\n", dhdinfo->uc_path));
9433 #endif /* DHD_UCODE_DOWNLOAD */
9434
9435 /* fw_path and nv_path are not mandatory for BCMEMBEDIMAGE */
9436 if (dhdinfo->fw_path[0] == '\0') {
9437 DHD_ERROR(("firmware path not found\n"));
9438 return FALSE;
9439 }
9440 if (dhdinfo->nv_path[0] == '\0') {
9441 DHD_ERROR(("nvram path not found\n"));
9442 return FALSE;
9443 }
9444
9445 return TRUE;
9446 }
9447
9448 #if defined(BT_OVER_SDIO)
dhd_update_btfw_path(dhd_info_t * dhdinfo,char * btfw_path)9449 extern bool dhd_update_btfw_path(dhd_info_t *dhdinfo, char* btfw_path)
9450 {
9451 int fw_len;
9452 const char *fw = NULL;
9453 wifi_adapter_info_t *adapter = dhdinfo->adapter;
9454
9455 /* Update bt firmware path. The path may be from adapter info or module parameter
9456 * The path from adapter info is used for initialization only (as it won't change).
9457 *
9458 * The btfw_path module parameter may be changed by the system at run
9459 * time. When it changes we need to copy it to dhdinfo->btfw_path. Also Android private
9460 * command may change dhdinfo->btfw_path. As such we need to clear the path info in
9461 * module parameter after it is copied. We won't update the path until the module parameter
9462 * is changed again (first character is not '\0')
9463 */
9464
9465 /* set default firmware and nvram path for built-in type driver */
9466 if (!dhd_download_fw_on_driverload) {
9467 #ifdef CONFIG_BCMDHD_BTFW_PATH
9468 fw = CONFIG_BCMDHD_BTFW_PATH;
9469 #endif /* CONFIG_BCMDHD_FW_PATH */
9470 }
9471
9472 /* check if we need to initialize the path */
9473 if (dhdinfo->btfw_path[0] == '\0') {
9474 if (adapter && adapter->btfw_path && adapter->btfw_path[0] != '\0')
9475 fw = adapter->btfw_path;
9476 }
9477
9478 /* Use module parameter if it is valid, EVEN IF the path has not been initialized
9479 */
9480 if (btfw_path[0] != '\0')
9481 fw = btfw_path;
9482
9483 if (fw && fw[0] != '\0') {
9484 fw_len = strlen(fw);
9485 if (fw_len >= sizeof(dhdinfo->btfw_path)) {
9486 DHD_ERROR(("fw path len exceeds max len of dhdinfo->btfw_path\n"));
9487 return FALSE;
9488 }
9489 strncpy(dhdinfo->btfw_path, fw, sizeof(dhdinfo->btfw_path));
9490 if (dhdinfo->btfw_path[fw_len-1] == '\n')
9491 dhdinfo->btfw_path[fw_len-1] = '\0';
9492 }
9493
9494 /* clear the path in module parameter */
9495 btfw_path[0] = '\0';
9496
9497 if (dhdinfo->btfw_path[0] == '\0') {
9498 DHD_ERROR(("bt firmware path not found\n"));
9499 return FALSE;
9500 }
9501
9502 return TRUE;
9503 }
9504 #endif /* defined (BT_OVER_SDIO) */
9505
9506 #if defined(BT_OVER_SDIO)
dhd_bt_get_pub_hndl(void)9507 wlan_bt_handle_t dhd_bt_get_pub_hndl(void)
9508 {
9509 DHD_ERROR(("%s: g_dhd_pub %p\n", __FUNCTION__, g_dhd_pub));
9510 /* assuming that dhd_pub_t type pointer is available from a global variable */
9511 return (wlan_bt_handle_t) g_dhd_pub;
9512 } EXPORT_SYMBOL(dhd_bt_get_pub_hndl);
9513
dhd_download_btfw(wlan_bt_handle_t handle,char * btfw_path)9514 int dhd_download_btfw(wlan_bt_handle_t handle, char* btfw_path)
9515 {
9516 int ret = -1;
9517 dhd_pub_t *dhdp = (dhd_pub_t *)handle;
9518 dhd_info_t *dhd = (dhd_info_t*)dhdp->info;
9519
9520 /* Download BT firmware image to the dongle */
9521 if (dhd->pub.busstate == DHD_BUS_DATA && dhd_update_btfw_path(dhd, btfw_path)) {
9522 DHD_INFO(("%s: download btfw from: %s\n", __FUNCTION__, dhd->btfw_path));
9523 ret = dhd_bus_download_btfw(dhd->pub.bus, dhd->pub.osh, dhd->btfw_path);
9524 if (ret < 0) {
9525 DHD_ERROR(("%s: failed to download btfw from: %s\n",
9526 __FUNCTION__, dhd->btfw_path));
9527 return ret;
9528 }
9529 }
9530 return ret;
9531 } EXPORT_SYMBOL(dhd_download_btfw);
9532 #endif /* defined (BT_OVER_SDIO) */
9533
9534 #ifndef BCMDBUS
9535 int
dhd_bus_start(dhd_pub_t * dhdp)9536 dhd_bus_start(dhd_pub_t *dhdp)
9537 {
9538 int ret = -1;
9539 dhd_info_t *dhd = (dhd_info_t*)dhdp->info;
9540 unsigned long flags;
9541
9542 #if defined(DHD_DEBUG) && defined(BCMSDIO)
9543 int fw_download_start = 0, fw_download_end = 0, f2_sync_start = 0, f2_sync_end = 0;
9544 #endif /* DHD_DEBUG && BCMSDIO */
9545 ASSERT(dhd);
9546
9547 DHD_TRACE(("Enter %s:\n", __FUNCTION__));
9548 dhdp->dongle_trap_occured = 0;
9549 #ifdef DHD_SSSR_DUMP
9550 /* Flag to indicate sssr dump is collected */
9551 dhdp->sssr_dump_collected = 0;
9552 #endif /* DHD_SSSR_DUMP */
9553 dhdp->iovar_timeout_occured = 0;
9554 #ifdef PCIE_FULL_DONGLE
9555 dhdp->d3ack_timeout_occured = 0;
9556 dhdp->livelock_occured = 0;
9557 dhdp->pktid_audit_failed = 0;
9558 #endif /* PCIE_FULL_DONGLE */
9559 dhd->pub.iface_op_failed = 0;
9560 dhd->pub.scan_timeout_occurred = 0;
9561 dhd->pub.scan_busy_occurred = 0;
9562 /* Clear induced error during initialize */
9563 dhd->pub.dhd_induce_error = DHD_INDUCE_ERROR_CLEAR;
9564
9565 /* set default value for now. Will be updated again in dhd_preinit_ioctls()
9566 * after querying FW
9567 */
9568 dhdp->event_log_max_sets = NUM_EVENT_LOG_SETS;
9569 dhdp->event_log_max_sets_queried = FALSE;
9570 dhdp->smmu_fault_occurred = 0;
9571 #ifdef DNGL_AXI_ERROR_LOGGING
9572 dhdp->axi_error = FALSE;
9573 #endif /* DNGL_AXI_ERROR_LOGGING */
9574
9575 DHD_PERIM_LOCK(dhdp);
9576 /* try to download image and nvram to the dongle */
9577 if (dhd->pub.busstate == DHD_BUS_DOWN && dhd_update_fw_nv_path(dhd)) {
9578 /* Indicate FW Download has not yet done */
9579 dhd->pub.fw_download_status = FW_DOWNLOAD_IN_PROGRESS;
9580 DHD_INFO(("%s download fw %s, nv %s, conf %s\n",
9581 __FUNCTION__, dhd->fw_path, dhd->nv_path, dhd->conf_path));
9582 #if defined(DHD_DEBUG) && defined(BCMSDIO)
9583 fw_download_start = OSL_SYSUPTIME();
9584 #endif /* DHD_DEBUG && BCMSDIO */
9585 ret = dhd_bus_download_firmware(dhd->pub.bus, dhd->pub.osh,
9586 dhd->fw_path, dhd->nv_path, dhd->clm_path, dhd->conf_path);
9587 #if defined(DHD_DEBUG) && defined(BCMSDIO)
9588 fw_download_end = OSL_SYSUPTIME();
9589 #endif /* DHD_DEBUG && BCMSDIO */
9590 if (ret < 0) {
9591 DHD_ERROR(("%s: failed to download firmware %s\n",
9592 __FUNCTION__, dhd->fw_path));
9593 DHD_PERIM_UNLOCK(dhdp);
9594 return ret;
9595 }
9596 /* Indicate FW Download has succeeded */
9597 dhd->pub.fw_download_status = FW_DOWNLOAD_DONE;
9598 }
9599 if (dhd->pub.busstate != DHD_BUS_LOAD) {
9600 DHD_PERIM_UNLOCK(dhdp);
9601 return -ENETDOWN;
9602 }
9603
9604 #ifdef BCMSDIO
9605 dhd_os_sdlock(dhdp);
9606 #endif /* BCMSDIO */
9607
9608 /* Start the watchdog timer */
9609 dhd->pub.tickcnt = 0;
9610 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
9611
9612 /* Bring up the bus */
9613 if ((ret = dhd_bus_init(&dhd->pub, FALSE)) != 0) {
9614
9615 DHD_ERROR(("%s, dhd_bus_init failed %d\n", __FUNCTION__, ret));
9616 #ifdef BCMSDIO
9617 dhd_os_sdunlock(dhdp);
9618 #endif /* BCMSDIO */
9619 DHD_PERIM_UNLOCK(dhdp);
9620 return ret;
9621 }
9622
9623 DHD_ENABLE_RUNTIME_PM(&dhd->pub);
9624
9625 #ifdef DHD_ULP
9626 dhd_ulp_set_ulp_state(dhdp, DHD_ULP_DISABLED);
9627 #endif /* DHD_ULP */
9628 #if defined(OOB_INTR_ONLY) || defined(BCMSPI_ANDROID) || defined(BCMPCIE_OOB_HOST_WAKE)
9629 /* Host registration for OOB interrupt */
9630 if (dhd_bus_oob_intr_register(dhdp)) {
9631 /* deactivate timer and wait for the handler to finish */
9632 #if !defined(BCMPCIE_OOB_HOST_WAKE)
9633 DHD_GENERAL_LOCK(&dhd->pub, flags);
9634 dhd->wd_timer_valid = FALSE;
9635 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
9636 del_timer_sync(&dhd->timer);
9637
9638 #endif /* !BCMPCIE_OOB_HOST_WAKE */
9639 DHD_DISABLE_RUNTIME_PM(&dhd->pub);
9640 DHD_PERIM_UNLOCK(dhdp);
9641 DHD_ERROR(("%s Host failed to register for OOB\n", __FUNCTION__));
9642 DHD_OS_WD_WAKE_UNLOCK(&dhd->pub);
9643 return -ENODEV;
9644 }
9645
9646 #if defined(BCMPCIE_OOB_HOST_WAKE)
9647 dhd_bus_oob_intr_set(dhdp, TRUE);
9648 #else
9649 /* Enable oob at firmware */
9650 dhd_enable_oob_intr(dhd->pub.bus, TRUE);
9651 #endif /* BCMPCIE_OOB_HOST_WAKE */
9652 #elif defined(FORCE_WOWLAN)
9653 /* Enable oob at firmware */
9654 dhd_enable_oob_intr(dhd->pub.bus, TRUE);
9655 #endif /* OOB_INTR_ONLY || BCMSPI_ANDROID || BCMPCIE_OOB_HOST_WAKE */
9656 #ifdef PCIE_FULL_DONGLE
9657 {
9658 /* max_h2d_rings includes H2D common rings */
9659 uint32 max_h2d_rings = dhd_bus_max_h2d_queues(dhd->pub.bus);
9660
9661 DHD_ERROR(("%s: Initializing %u h2drings\n", __FUNCTION__,
9662 max_h2d_rings));
9663 if ((ret = dhd_flow_rings_init(&dhd->pub, max_h2d_rings)) != BCME_OK) {
9664 #ifdef BCMSDIO
9665 dhd_os_sdunlock(dhdp);
9666 #endif /* BCMSDIO */
9667 DHD_PERIM_UNLOCK(dhdp);
9668 return ret;
9669 }
9670 }
9671 #endif /* PCIE_FULL_DONGLE */
9672
9673 /* Do protocol initialization necessary for IOCTL/IOVAR */
9674 ret = dhd_prot_init(&dhd->pub);
9675 if (unlikely(ret) != BCME_OK) {
9676 DHD_PERIM_UNLOCK(dhdp);
9677 DHD_OS_WD_WAKE_UNLOCK(&dhd->pub);
9678 return ret;
9679 }
9680
9681 /* If bus is not ready, can't come up */
9682 if (dhd->pub.busstate != DHD_BUS_DATA) {
9683 DHD_GENERAL_LOCK(&dhd->pub, flags);
9684 dhd->wd_timer_valid = FALSE;
9685 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
9686 del_timer_sync(&dhd->timer);
9687 DHD_ERROR(("%s failed bus is not ready\n", __FUNCTION__));
9688 DHD_DISABLE_RUNTIME_PM(&dhd->pub);
9689 #ifdef BCMSDIO
9690 dhd_os_sdunlock(dhdp);
9691 #endif /* BCMSDIO */
9692 DHD_PERIM_UNLOCK(dhdp);
9693 DHD_OS_WD_WAKE_UNLOCK(&dhd->pub);
9694 return -ENODEV;
9695 }
9696
9697 #ifdef BCMSDIO
9698 dhd_os_sdunlock(dhdp);
9699 #endif /* BCMSDIO */
9700
9701 /* Bus is ready, query any dongle information */
9702 #if defined(DHD_DEBUG) && defined(BCMSDIO)
9703 f2_sync_start = OSL_SYSUPTIME();
9704 #endif /* DHD_DEBUG && BCMSDIO */
9705 if ((ret = dhd_sync_with_dongle(&dhd->pub)) < 0) {
9706 DHD_GENERAL_LOCK(&dhd->pub, flags);
9707 dhd->wd_timer_valid = FALSE;
9708 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
9709 del_timer_sync(&dhd->timer);
9710 DHD_ERROR(("%s failed to sync with dongle\n", __FUNCTION__));
9711 DHD_OS_WD_WAKE_UNLOCK(&dhd->pub);
9712 DHD_PERIM_UNLOCK(dhdp);
9713 return ret;
9714 }
9715
9716 #if defined(CONFIG_SOC_EXYNOS8895) || defined(CONFIG_SOC_EXYNOS9810) || \
9717 defined(CONFIG_SOC_EXYNOS9820)
9718 DHD_ERROR(("%s: Enable L1ss EP side\n", __FUNCTION__));
9719 exynos_pcie_l1ss_ctrl(1, PCIE_L1SS_CTRL_WIFI);
9720 #endif /* CONFIG_SOC_EXYNOS8895 || CONFIG_SOC_EXYNOS9810 || CONFIG_SOC_EXYNOS9820 */
9721
9722 #if defined(DHD_DEBUG) && defined(BCMSDIO)
9723 f2_sync_end = OSL_SYSUPTIME();
9724 DHD_ERROR(("Time taken for FW download and F2 ready is: %d msec\n",
9725 (fw_download_end - fw_download_start) + (f2_sync_end - f2_sync_start)));
9726 #endif /* DHD_DEBUG && BCMSDIO */
9727
9728 #ifdef ARP_OFFLOAD_SUPPORT
9729 if (dhd->pend_ipaddr) {
9730 #ifdef AOE_IP_ALIAS_SUPPORT
9731 aoe_update_host_ipv4_table(&dhd->pub, dhd->pend_ipaddr, TRUE, 0);
9732 #endif /* AOE_IP_ALIAS_SUPPORT */
9733 dhd->pend_ipaddr = 0;
9734 }
9735 #endif /* ARP_OFFLOAD_SUPPORT */
9736
9737 DHD_PERIM_UNLOCK(dhdp);
9738
9739 return 0;
9740 }
9741 #endif /* !BCMDBUS */
9742
9743 #ifdef WLTDLS
_dhd_tdls_enable(dhd_pub_t * dhd,bool tdls_on,bool auto_on,struct ether_addr * mac)9744 int _dhd_tdls_enable(dhd_pub_t *dhd, bool tdls_on, bool auto_on, struct ether_addr *mac)
9745 {
9746 uint32 tdls = tdls_on;
9747 int ret = 0;
9748 uint32 tdls_auto_op = 0;
9749 uint32 tdls_idle_time = CUSTOM_TDLS_IDLE_MODE_SETTING;
9750 int32 tdls_rssi_high = CUSTOM_TDLS_RSSI_THRESHOLD_HIGH;
9751 int32 tdls_rssi_low = CUSTOM_TDLS_RSSI_THRESHOLD_LOW;
9752 uint32 tdls_pktcnt_high = CUSTOM_TDLS_PCKTCNT_THRESHOLD_HIGH;
9753 uint32 tdls_pktcnt_low = CUSTOM_TDLS_PCKTCNT_THRESHOLD_LOW;
9754
9755 BCM_REFERENCE(mac);
9756 if (!FW_SUPPORTED(dhd, tdls))
9757 return BCME_ERROR;
9758
9759 if (dhd->tdls_enable == tdls_on)
9760 goto auto_mode;
9761 ret = dhd_iovar(dhd, 0, "tdls_enable", (char *)&tdls, sizeof(tdls), NULL, 0, TRUE);
9762 if (ret < 0) {
9763 DHD_ERROR(("%s: tdls %d failed %d\n", __FUNCTION__, tdls, ret));
9764 goto exit;
9765 }
9766 dhd->tdls_enable = tdls_on;
9767 auto_mode:
9768
9769 tdls_auto_op = auto_on;
9770 ret = dhd_iovar(dhd, 0, "tdls_auto_op", (char *)&tdls_auto_op, sizeof(tdls_auto_op), NULL,
9771 0, TRUE);
9772 if (ret < 0) {
9773 DHD_ERROR(("%s: tdls_auto_op failed %d\n", __FUNCTION__, ret));
9774 goto exit;
9775 }
9776
9777 if (tdls_auto_op) {
9778 ret = dhd_iovar(dhd, 0, "tdls_idle_time", (char *)&tdls_idle_time,
9779 sizeof(tdls_idle_time), NULL, 0, TRUE);
9780 if (ret < 0) {
9781 DHD_ERROR(("%s: tdls_idle_time failed %d\n", __FUNCTION__, ret));
9782 goto exit;
9783 }
9784 ret = dhd_iovar(dhd, 0, "tdls_rssi_high", (char *)&tdls_rssi_high,
9785 sizeof(tdls_rssi_high), NULL, 0, TRUE);
9786 if (ret < 0) {
9787 DHD_ERROR(("%s: tdls_rssi_high failed %d\n", __FUNCTION__, ret));
9788 goto exit;
9789 }
9790 ret = dhd_iovar(dhd, 0, "tdls_rssi_low", (char *)&tdls_rssi_low,
9791 sizeof(tdls_rssi_low), NULL, 0, TRUE);
9792 if (ret < 0) {
9793 DHD_ERROR(("%s: tdls_rssi_low failed %d\n", __FUNCTION__, ret));
9794 goto exit;
9795 }
9796 ret = dhd_iovar(dhd, 0, "tdls_trigger_pktcnt_high", (char *)&tdls_pktcnt_high,
9797 sizeof(tdls_pktcnt_high), NULL, 0, TRUE);
9798 if (ret < 0) {
9799 DHD_ERROR(("%s: tdls_trigger_pktcnt_high failed %d\n", __FUNCTION__, ret));
9800 goto exit;
9801 }
9802 ret = dhd_iovar(dhd, 0, "tdls_trigger_pktcnt_low", (char *)&tdls_pktcnt_low,
9803 sizeof(tdls_pktcnt_low), NULL, 0, TRUE);
9804 if (ret < 0) {
9805 DHD_ERROR(("%s: tdls_trigger_pktcnt_low failed %d\n", __FUNCTION__, ret));
9806 goto exit;
9807 }
9808 }
9809
9810 exit:
9811 return ret;
9812 }
9813
dhd_tdls_enable(struct net_device * dev,bool tdls_on,bool auto_on,struct ether_addr * mac)9814 int dhd_tdls_enable(struct net_device *dev, bool tdls_on, bool auto_on, struct ether_addr *mac)
9815 {
9816 dhd_info_t *dhd = DHD_DEV_INFO(dev);
9817 int ret = 0;
9818 if (dhd)
9819 ret = _dhd_tdls_enable(&dhd->pub, tdls_on, auto_on, mac);
9820 else
9821 ret = BCME_ERROR;
9822 return ret;
9823 }
9824
9825 int
dhd_tdls_set_mode(dhd_pub_t * dhd,bool wfd_mode)9826 dhd_tdls_set_mode(dhd_pub_t *dhd, bool wfd_mode)
9827 {
9828 int ret = 0;
9829 bool auto_on = false;
9830 uint32 mode = wfd_mode;
9831
9832 #ifdef ENABLE_TDLS_AUTO_MODE
9833 if (wfd_mode) {
9834 auto_on = false;
9835 } else {
9836 auto_on = true;
9837 }
9838 #else
9839 auto_on = false;
9840 #endif /* ENABLE_TDLS_AUTO_MODE */
9841 ret = _dhd_tdls_enable(dhd, false, auto_on, NULL);
9842 if (ret < 0) {
9843 DHD_ERROR(("Disable tdls_auto_op failed. %d\n", ret));
9844 return ret;
9845 }
9846
9847 ret = dhd_iovar(dhd, 0, "tdls_wfd_mode", (char *)&mode, sizeof(mode), NULL, 0, TRUE);
9848 if ((ret < 0) && (ret != BCME_UNSUPPORTED)) {
9849 DHD_ERROR(("%s: tdls_wfd_mode faile_wfd_mode %d\n", __FUNCTION__, ret));
9850 return ret;
9851 }
9852
9853 ret = _dhd_tdls_enable(dhd, true, auto_on, NULL);
9854 if (ret < 0) {
9855 DHD_ERROR(("enable tdls_auto_op failed. %d\n", ret));
9856 return ret;
9857 }
9858
9859 dhd->tdls_mode = mode;
9860 return ret;
9861 }
9862 #ifdef PCIE_FULL_DONGLE
dhd_tdls_update_peer_info(dhd_pub_t * dhdp,wl_event_msg_t * event)9863 int dhd_tdls_update_peer_info(dhd_pub_t *dhdp, wl_event_msg_t *event)
9864 {
9865 dhd_pub_t *dhd_pub = dhdp;
9866 tdls_peer_node_t *cur = dhd_pub->peer_tbl.node;
9867 tdls_peer_node_t *new = NULL, *prev = NULL;
9868 int ifindex = dhd_ifname2idx(dhd_pub->info, event->ifname);
9869 uint8 *da = (uint8 *)&event->addr.octet[0];
9870 bool connect = FALSE;
9871 uint32 reason = ntoh32(event->reason);
9872 unsigned long flags;
9873
9874 /* No handling needed for peer discovered reason */
9875 if (reason == WLC_E_TDLS_PEER_DISCOVERED) {
9876 return BCME_ERROR;
9877 }
9878 if (reason == WLC_E_TDLS_PEER_CONNECTED)
9879 connect = TRUE;
9880 else if (reason == WLC_E_TDLS_PEER_DISCONNECTED)
9881 connect = FALSE;
9882 else
9883 {
9884 DHD_ERROR(("%s: TDLS Event reason is unknown\n", __FUNCTION__));
9885 return BCME_ERROR;
9886 }
9887 if (ifindex == DHD_BAD_IF)
9888 return BCME_ERROR;
9889
9890 if (connect) {
9891 while (cur != NULL) {
9892 if (!memcmp(da, cur->addr, ETHER_ADDR_LEN)) {
9893 DHD_ERROR(("%s: TDLS Peer exist already %d\n",
9894 __FUNCTION__, __LINE__));
9895 return BCME_ERROR;
9896 }
9897 cur = cur->next;
9898 }
9899
9900 new = MALLOC(dhd_pub->osh, sizeof(tdls_peer_node_t));
9901 if (new == NULL) {
9902 DHD_ERROR(("%s: Failed to allocate memory\n", __FUNCTION__));
9903 return BCME_ERROR;
9904 }
9905 memcpy(new->addr, da, ETHER_ADDR_LEN);
9906 DHD_TDLS_LOCK(&dhdp->tdls_lock, flags);
9907 new->next = dhd_pub->peer_tbl.node;
9908 dhd_pub->peer_tbl.node = new;
9909 dhd_pub->peer_tbl.tdls_peer_count++;
9910 DHD_TDLS_UNLOCK(&dhdp->tdls_lock, flags);
9911
9912 } else {
9913 while (cur != NULL) {
9914 if (!memcmp(da, cur->addr, ETHER_ADDR_LEN)) {
9915 dhd_flow_rings_delete_for_peer(dhd_pub, (uint8)ifindex, da);
9916 DHD_TDLS_LOCK(&dhdp->tdls_lock, flags);
9917 if (prev)
9918 prev->next = cur->next;
9919 else
9920 dhd_pub->peer_tbl.node = cur->next;
9921 MFREE(dhd_pub->osh, cur, sizeof(tdls_peer_node_t));
9922 dhd_pub->peer_tbl.tdls_peer_count--;
9923 DHD_TDLS_UNLOCK(&dhdp->tdls_lock, flags);
9924 return BCME_OK;
9925 }
9926 prev = cur;
9927 cur = cur->next;
9928 }
9929 DHD_ERROR(("%s: TDLS Peer Entry Not found\n", __FUNCTION__));
9930 }
9931 return BCME_OK;
9932 }
9933 #endif /* PCIE_FULL_DONGLE */
9934 #endif // endif
9935
dhd_is_concurrent_mode(dhd_pub_t * dhd)9936 bool dhd_is_concurrent_mode(dhd_pub_t *dhd)
9937 {
9938 if (!dhd)
9939 return FALSE;
9940
9941 if (dhd->op_mode & DHD_FLAG_CONCURR_MULTI_CHAN_MODE)
9942 return TRUE;
9943 else if ((dhd->op_mode & DHD_FLAG_CONCURR_SINGLE_CHAN_MODE) ==
9944 DHD_FLAG_CONCURR_SINGLE_CHAN_MODE)
9945 return TRUE;
9946 else
9947 return FALSE;
9948 }
9949 #if !defined(AP) && defined(WLP2P)
9950 /* From Android JerryBean release, the concurrent mode is enabled by default and the firmware
9951 * name would be fw_bcmdhd.bin. So we need to determine whether P2P is enabled in the STA
9952 * firmware and accordingly enable concurrent mode (Apply P2P settings). SoftAP firmware
9953 * would still be named as fw_bcmdhd_apsta.
9954 */
9955 uint32
dhd_get_concurrent_capabilites(dhd_pub_t * dhd)9956 dhd_get_concurrent_capabilites(dhd_pub_t *dhd)
9957 {
9958 int32 ret = 0;
9959 char buf[WLC_IOCTL_SMLEN];
9960 bool mchan_supported = FALSE;
9961 /* if dhd->op_mode is already set for HOSTAP and Manufacturing
9962 * test mode, that means we only will use the mode as it is
9963 */
9964 if (dhd->op_mode & (DHD_FLAG_HOSTAP_MODE | DHD_FLAG_MFG_MODE))
9965 return 0;
9966 if (FW_SUPPORTED(dhd, vsdb)) {
9967 mchan_supported = TRUE;
9968 }
9969 if (!FW_SUPPORTED(dhd, p2p)) {
9970 DHD_TRACE(("Chip does not support p2p\n"));
9971 return 0;
9972 } else {
9973 /* Chip supports p2p but ensure that p2p is really implemented in firmware or not */
9974 memset(buf, 0, sizeof(buf));
9975 ret = dhd_iovar(dhd, 0, "p2p", NULL, 0, (char *)&buf,
9976 sizeof(buf), FALSE);
9977 if (ret < 0) {
9978 DHD_ERROR(("%s: Get P2P failed (error=%d)\n", __FUNCTION__, ret));
9979 return 0;
9980 } else {
9981 if (buf[0] == 1) {
9982 /* By default, chip supports single chan concurrency,
9983 * now lets check for mchan
9984 */
9985 ret = DHD_FLAG_CONCURR_SINGLE_CHAN_MODE;
9986 if (mchan_supported)
9987 ret |= DHD_FLAG_CONCURR_MULTI_CHAN_MODE;
9988 if (FW_SUPPORTED(dhd, rsdb)) {
9989 ret |= DHD_FLAG_RSDB_MODE;
9990 }
9991 #ifdef WL_SUPPORT_MULTIP2P
9992 if (FW_SUPPORTED(dhd, mp2p)) {
9993 ret |= DHD_FLAG_MP2P_MODE;
9994 }
9995 #endif /* WL_SUPPORT_MULTIP2P */
9996 #if defined(WL_ENABLE_P2P_IF) || defined(WL_CFG80211_P2P_DEV_IF)
9997 return ret;
9998 #else
9999 return 0;
10000 #endif /* WL_ENABLE_P2P_IF || WL_CFG80211_P2P_DEV_IF */
10001 }
10002 }
10003 }
10004 return 0;
10005 }
10006 #endif // endif
10007
10008 #if defined(WLADPS)
10009
10010 int
dhd_enable_adps(dhd_pub_t * dhd,uint8 on)10011 dhd_enable_adps(dhd_pub_t *dhd, uint8 on)
10012 {
10013 int i;
10014 int len;
10015 int ret = BCME_OK;
10016
10017 bcm_iov_buf_t *iov_buf = NULL;
10018 wl_adps_params_v1_t *data = NULL;
10019
10020 len = OFFSETOF(bcm_iov_buf_t, data) + sizeof(*data);
10021 iov_buf = MALLOC(dhd->osh, len);
10022 if (iov_buf == NULL) {
10023 DHD_ERROR(("%s - failed to allocate %d bytes for iov_buf\n", __FUNCTION__, len));
10024 ret = BCME_NOMEM;
10025 goto exit;
10026 }
10027
10028 iov_buf->version = WL_ADPS_IOV_VER;
10029 iov_buf->len = sizeof(*data);
10030 iov_buf->id = WL_ADPS_IOV_MODE;
10031
10032 data = (wl_adps_params_v1_t *)iov_buf->data;
10033 data->version = ADPS_SUB_IOV_VERSION_1;
10034 data->length = sizeof(*data);
10035 data->mode = on;
10036
10037 for (i = 1; i <= MAX_BANDS; i++) {
10038 data->band = i;
10039 ret = dhd_iovar(dhd, 0, "adps", (char *)iov_buf, len, NULL, 0, TRUE);
10040 if (ret < 0) {
10041 if (ret == BCME_UNSUPPORTED) {
10042 DHD_ERROR(("%s adps is not supported\n", __FUNCTION__));
10043 ret = BCME_OK;
10044 goto exit;
10045 }
10046 else {
10047 DHD_ERROR(("%s fail to set adps %s for band %d (%d)\n",
10048 __FUNCTION__, on ? "On" : "Off", i, ret));
10049 goto exit;
10050 }
10051 }
10052 }
10053
10054 exit:
10055 if (iov_buf) {
10056 MFREE(dhd->osh, iov_buf, len);
10057 iov_buf = NULL;
10058 }
10059 return ret;
10060 }
10061 #endif // endif
10062
10063 int
dhd_preinit_ioctls(dhd_pub_t * dhd)10064 dhd_preinit_ioctls(dhd_pub_t *dhd)
10065 {
10066 int ret = 0;
10067 char eventmask[WL_EVENTING_MASK_LEN];
10068 char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" + '\0' + bitvec */
10069 uint32 buf_key_b4_m4 = 1;
10070 uint8 msglen;
10071 eventmsgs_ext_t *eventmask_msg = NULL;
10072 uint32 event_log_max_sets = 0;
10073 char* iov_buf = NULL;
10074 int ret2 = 0;
10075 uint32 wnm_cap = 0;
10076 #if defined(BCMSUP_4WAY_HANDSHAKE)
10077 uint32 sup_wpa = 1;
10078 #endif /* BCMSUP_4WAY_HANDSHAKE */
10079 #if defined(CUSTOM_AMPDU_BA_WSIZE)
10080 uint32 ampdu_ba_wsize = 0;
10081 #endif // endif
10082 #if defined(CUSTOM_AMPDU_MPDU)
10083 int32 ampdu_mpdu = 0;
10084 #endif // endif
10085 #if defined(CUSTOM_AMPDU_RELEASE)
10086 int32 ampdu_release = 0;
10087 #endif // endif
10088 #if defined(CUSTOM_AMSDU_AGGSF)
10089 int32 amsdu_aggsf = 0;
10090 #endif // endif
10091
10092 #if defined(BCMSDIO) || defined(BCMDBUS)
10093 #ifdef PROP_TXSTATUS
10094 int wlfc_enable = TRUE;
10095 #ifndef DISABLE_11N
10096 uint32 hostreorder = 1;
10097 uint wl_down = 1;
10098 #endif /* DISABLE_11N */
10099 #endif /* PROP_TXSTATUS */
10100 #endif /* BCMSDIO || BCMDBUS */
10101 #ifndef PCIE_FULL_DONGLE
10102 uint32 wl_ap_isolate;
10103 #endif /* PCIE_FULL_DONGLE */
10104 uint32 frameburst = CUSTOM_FRAMEBURST_SET;
10105 uint wnm_bsstrans_resp = 0;
10106 #ifdef SUPPORT_SET_CAC
10107 uint32 cac = 1;
10108 #endif /* SUPPORT_SET_CAC */
10109
10110 #ifdef DHD_ENABLE_LPC
10111 uint32 lpc = 1;
10112 #endif /* DHD_ENABLE_LPC */
10113 uint power_mode = PM_FAST;
10114 #if defined(BCMSDIO)
10115 uint32 dongle_align = DHD_SDALIGN;
10116 uint32 glom = CUSTOM_GLOM_SETTING;
10117 #endif /* defined(BCMSDIO) */
10118 #if defined(USE_WL_CREDALL)
10119 uint32 credall = 1;
10120 #endif // endif
10121 uint bcn_timeout = CUSTOM_BCN_TIMEOUT;
10122 uint scancache_enab = TRUE;
10123 #ifdef ENABLE_BCN_LI_BCN_WAKEUP
10124 uint32 bcn_li_bcn = 1;
10125 #endif /* ENABLE_BCN_LI_BCN_WAKEUP */
10126 uint retry_max = CUSTOM_ASSOC_RETRY_MAX;
10127 #if defined(ARP_OFFLOAD_SUPPORT)
10128 int arpoe = 0;
10129 #endif // endif
10130 int scan_assoc_time = DHD_SCAN_ASSOC_ACTIVE_TIME;
10131 int scan_unassoc_time = DHD_SCAN_UNASSOC_ACTIVE_TIME;
10132 int scan_passive_time = DHD_SCAN_PASSIVE_TIME;
10133 char buf[WLC_IOCTL_SMLEN];
10134 char *ptr;
10135 uint32 listen_interval = CUSTOM_LISTEN_INTERVAL; /* Default Listen Interval in Beacons */
10136 #if defined(DHD_8021X_DUMP) && defined(SHOW_LOGTRACE)
10137 wl_el_tag_params_t *el_tag = NULL;
10138 #endif /* DHD_8021X_DUMP */
10139 #ifdef ROAM_ENABLE
10140 uint roamvar = 0;
10141 int roam_trigger[2] = {CUSTOM_ROAM_TRIGGER_SETTING, WLC_BAND_ALL};
10142 int roam_scan_period[2] = {10, WLC_BAND_ALL};
10143 int roam_delta[2] = {CUSTOM_ROAM_DELTA_SETTING, WLC_BAND_ALL};
10144 #ifdef ROAM_AP_ENV_DETECTION
10145 int roam_env_mode = AP_ENV_INDETERMINATE;
10146 #endif /* ROAM_AP_ENV_DETECTION */
10147 #ifdef FULL_ROAMING_SCAN_PERIOD_60_SEC
10148 int roam_fullscan_period = 60;
10149 #else /* FULL_ROAMING_SCAN_PERIOD_60_SEC */
10150 int roam_fullscan_period = 120;
10151 #endif /* FULL_ROAMING_SCAN_PERIOD_60_SEC */
10152 #ifdef DISABLE_BCNLOSS_ROAM
10153 uint roam_bcnloss_off = 1;
10154 #endif /* DISABLE_BCNLOSS_ROAM */
10155 #else
10156 #ifdef DISABLE_BUILTIN_ROAM
10157 uint roamvar = 1;
10158 #endif /* DISABLE_BUILTIN_ROAM */
10159 #endif /* ROAM_ENABLE */
10160
10161 #if defined(SOFTAP)
10162 uint dtim = 1;
10163 #endif // endif
10164 #if (defined(AP) && !defined(WLP2P)) || (!defined(AP) && defined(WL_CFG80211))
10165 struct ether_addr p2p_ea;
10166 #endif // endif
10167 #ifdef BCMCCX
10168 uint32 ccx = 1;
10169 #endif // endif
10170 #ifdef SOFTAP_UAPSD_OFF
10171 uint32 wme_apsd = 0;
10172 #endif /* SOFTAP_UAPSD_OFF */
10173 #if (defined(AP) || defined(WLP2P)) && !defined(SOFTAP_AND_GC)
10174 uint32 apsta = 1; /* Enable APSTA mode */
10175 #elif defined(SOFTAP_AND_GC)
10176 uint32 apsta = 0;
10177 int ap_mode = 1;
10178 #endif /* (defined(AP) || defined(WLP2P)) && !defined(SOFTAP_AND_GC) */
10179 #ifdef GET_CUSTOM_MAC_ENABLE
10180 struct ether_addr ea_addr;
10181 char hw_ether[62];
10182 #endif /* GET_CUSTOM_MAC_ENABLE */
10183 #ifdef OKC_SUPPORT
10184 uint32 okc = 1;
10185 #endif // endif
10186
10187 #ifdef DISABLE_11N
10188 uint32 nmode = 0;
10189 #endif /* DISABLE_11N */
10190
10191 #ifdef USE_WL_TXBF
10192 uint32 txbf = 1;
10193 #endif /* USE_WL_TXBF */
10194 #ifdef DISABLE_TXBFR
10195 uint32 txbf_bfr_cap = 0;
10196 #endif /* DISABLE_TXBFR */
10197 #ifdef AMPDU_VO_ENABLE
10198 struct ampdu_tid_control tid;
10199 #endif // endif
10200 #if defined(PROP_TXSTATUS)
10201 #ifdef USE_WFA_CERT_CONF
10202 uint32 proptx = 0;
10203 #endif /* USE_WFA_CERT_CONF */
10204 #endif /* PROP_TXSTATUS */
10205 #ifdef DHD_SET_FW_HIGHSPEED
10206 uint32 ack_ratio = 250;
10207 uint32 ack_ratio_depth = 64;
10208 #endif /* DHD_SET_FW_HIGHSPEED */
10209 #if defined(SUPPORT_2G_VHT) || defined(SUPPORT_5G_1024QAM_VHT)
10210 uint32 vht_features = 0; /* init to 0, will be set based on each support */
10211 #endif /* SUPPORT_2G_VHT || SUPPORT_5G_1024QAM_VHT */
10212 #ifdef DISABLE_11N_PROPRIETARY_RATES
10213 uint32 ht_features = 0;
10214 #endif /* DISABLE_11N_PROPRIETARY_RATES */
10215 #ifdef CUSTOM_PSPRETEND_THR
10216 uint32 pspretend_thr = CUSTOM_PSPRETEND_THR;
10217 #endif // endif
10218 #ifdef CUSTOM_EVENT_PM_WAKE
10219 uint32 pm_awake_thresh = CUSTOM_EVENT_PM_WAKE;
10220 #endif /* CUSTOM_EVENT_PM_WAKE */
10221 #ifdef DISABLE_PRUNED_SCAN
10222 uint32 scan_features = 0;
10223 #endif /* DISABLE_PRUNED_SCAN */
10224 #ifdef BCMPCIE_OOB_HOST_WAKE
10225 uint32 hostwake_oob = 0;
10226 #endif /* BCMPCIE_OOB_HOST_WAKE */
10227 #ifdef EVENT_LOG_RATE_HC
10228 /* threshold number of lines per second */
10229 #define EVENT_LOG_RATE_HC_THRESHOLD 1000
10230 uint32 event_log_rate_hc = EVENT_LOG_RATE_HC_THRESHOLD;
10231 #endif /* EVENT_LOG_RATE_HC */
10232 wl_wlc_version_t wlc_ver;
10233
10234 #ifdef PKT_FILTER_SUPPORT
10235 dhd_pkt_filter_enable = TRUE;
10236 #ifdef APF
10237 dhd->apf_set = FALSE;
10238 #endif /* APF */
10239 #endif /* PKT_FILTER_SUPPORT */
10240 dhd->suspend_bcn_li_dtim = CUSTOM_SUSPEND_BCN_LI_DTIM;
10241 #ifdef ENABLE_MAX_DTIM_IN_SUSPEND
10242 dhd->max_dtim_enable = TRUE;
10243 #else
10244 dhd->max_dtim_enable = FALSE;
10245 #endif /* ENABLE_MAX_DTIM_IN_SUSPEND */
10246 dhd->disable_dtim_in_suspend = FALSE;
10247 #ifdef SUPPORT_SET_TID
10248 dhd->tid_mode = SET_TID_OFF;
10249 dhd->target_uid = 0;
10250 dhd->target_tid = 0;
10251 #endif /* SUPPORT_SET_TID */
10252 DHD_TRACE(("Enter %s\n", __FUNCTION__));
10253
10254 #ifdef DHDTCPACK_SUPPRESS
10255 dhd_tcpack_suppress_set(dhd, dhd->conf->tcpack_sup_mode);
10256 #endif
10257 dhd->op_mode = 0;
10258
10259 #if defined(CUSTOM_COUNTRY_CODE)
10260 /* clear AP flags */
10261 dhd->dhd_cflags &= ~WLAN_PLAT_AP_FLAG;
10262 #endif /* CUSTOM_COUNTRY_CODE && (CUSTOMER_HW2 || BOARD_HIKEY) */
10263
10264 /* query for 'ver' to get version info from firmware */
10265 memset(buf, 0, sizeof(buf));
10266 ptr = buf;
10267 ret = dhd_iovar(dhd, 0, "ver", NULL, 0, (char *)&buf, sizeof(buf), FALSE);
10268 if (ret < 0)
10269 DHD_ERROR(("%s failed %d\n", __FUNCTION__, ret));
10270 else {
10271 bcmstrtok(&ptr, "\n", 0);
10272 /* Print fw version info */
10273 strncpy(fw_version, buf, FW_VER_STR_LEN);
10274 fw_version[FW_VER_STR_LEN-1] = '\0';
10275 }
10276
10277 /* Set op_mode as MFG_MODE if WLTEST is present in "wl ver" */
10278 if (strstr(fw_version, "WLTEST") != NULL) {
10279 DHD_ERROR(("%s: wl ver has WLTEST, setting op_mode as DHD_FLAG_MFG_MODE\n",
10280 __FUNCTION__));
10281 op_mode = DHD_FLAG_MFG_MODE;
10282 }
10283
10284 if ((!op_mode && dhd_get_fw_mode(dhd->info) == DHD_FLAG_MFG_MODE) ||
10285 (op_mode == DHD_FLAG_MFG_MODE)) {
10286 dhd->op_mode = DHD_FLAG_MFG_MODE;
10287 #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
10288 /* disable runtimePM by default in MFG mode. */
10289 pm_runtime_disable(dhd_bus_to_dev(dhd->bus));
10290 #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
10291 /* Check and adjust IOCTL response timeout for Manufactring firmware */
10292 dhd_os_set_ioctl_resp_timeout(MFG_IOCTL_RESP_TIMEOUT);
10293 DHD_ERROR(("%s : Set IOCTL response time for Manufactring Firmware\n",
10294 __FUNCTION__));
10295 } else {
10296 dhd_os_set_ioctl_resp_timeout(IOCTL_RESP_TIMEOUT);
10297 DHD_INFO(("%s : Set IOCTL response time.\n", __FUNCTION__));
10298 }
10299 #ifdef BCMPCIE_OOB_HOST_WAKE
10300 ret = dhd_iovar(dhd, 0, "bus:hostwake_oob", NULL, 0, (char *)&hostwake_oob,
10301 sizeof(hostwake_oob), FALSE);
10302 if (ret < 0) {
10303 DHD_ERROR(("%s: hostwake_oob IOVAR not present, proceed\n", __FUNCTION__));
10304 } else {
10305 if (hostwake_oob == 0) {
10306 DHD_ERROR(("%s: hostwake_oob is not enabled in the NVRAM, STOP\n",
10307 __FUNCTION__));
10308 ret = BCME_UNSUPPORTED;
10309 goto done;
10310 } else {
10311 DHD_ERROR(("%s: hostwake_oob enabled\n", __FUNCTION__));
10312 }
10313 }
10314 #endif /* BCMPCIE_OOB_HOST_WAKE */
10315
10316 #ifdef DNGL_AXI_ERROR_LOGGING
10317 ret = dhd_iovar(dhd, 0, "axierror_logbuf_addr", NULL, 0, (char *)&dhd->axierror_logbuf_addr,
10318 sizeof(dhd->axierror_logbuf_addr), FALSE);
10319 if (ret < 0) {
10320 DHD_ERROR(("%s: axierror_logbuf_addr IOVAR not present, proceed\n", __FUNCTION__));
10321 dhd->axierror_logbuf_addr = 0;
10322 } else {
10323 DHD_ERROR(("%s: axierror_logbuf_addr : 0x%x\n", __FUNCTION__,
10324 dhd->axierror_logbuf_addr));
10325 }
10326 #endif /* DNGL_AXI_ERROR_LOGGING */
10327
10328 #ifdef EVENT_LOG_RATE_HC
10329 ret = dhd_iovar(dhd, 0, "event_log_rate_hc", (char *)&event_log_rate_hc,
10330 sizeof(event_log_rate_hc), NULL, 0, TRUE);
10331 if (ret < 0) {
10332 DHD_ERROR(("%s event_log_rate_hc set failed %d\n", __FUNCTION__, ret));
10333 } else {
10334 DHD_ERROR(("%s event_log_rate_hc set with threshold:%d\n", __FUNCTION__,
10335 event_log_rate_hc));
10336 }
10337 #endif /* EVENT_LOG_RATE_HC */
10338
10339 #ifdef GET_CUSTOM_MAC_ENABLE
10340 memset(hw_ether, 0, sizeof(hw_ether));
10341 ret = wifi_platform_get_mac_addr(dhd->info->adapter, hw_ether, iface_name);
10342 #ifdef GET_CUSTOM_MAC_FROM_CONFIG
10343 if (!memcmp(ðer_null, &dhd->conf->hw_ether, ETHER_ADDR_LEN)) {
10344 ret = 0;
10345 } else
10346 #endif
10347 if (!ret) {
10348 memset(buf, 0, sizeof(buf));
10349 #ifdef GET_CUSTOM_MAC_FROM_CONFIG
10350 memcpy(hw_ether, &dhd->conf->hw_ether, sizeof(dhd->conf->hw_ether));
10351 #endif
10352 bcopy(hw_ether, ea_addr.octet, sizeof(struct ether_addr));
10353 bcm_mkiovar("cur_etheraddr", (void *)&ea_addr, ETHER_ADDR_LEN, buf, sizeof(buf));
10354 ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, buf, sizeof(buf), TRUE, 0);
10355 if (ret < 0) {
10356 memset(buf, 0, sizeof(buf));
10357 bcm_mkiovar("hw_ether", hw_ether, sizeof(hw_ether), buf, sizeof(buf));
10358 ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, buf, sizeof(buf), TRUE, 0);
10359 if (ret) {
10360 DHD_ERROR(("%s: can't set MAC address MAC="MACDBG", error=%d\n",
10361 __FUNCTION__, MAC2STRDBG(hw_ether), ret));
10362 prhex("MACPAD", &hw_ether[ETHER_ADDR_LEN], sizeof(hw_ether)-ETHER_ADDR_LEN);
10363 ret = BCME_NOTUP;
10364 goto done;
10365 }
10366 }
10367 } else {
10368 DHD_ERROR(("%s: can't get custom MAC address, ret=%d\n", __FUNCTION__, ret));
10369 ret = BCME_NOTUP;
10370 goto done;
10371 }
10372 #endif /* GET_CUSTOM_MAC_ENABLE */
10373 /* Get the default device MAC address directly from firmware */
10374 memset(buf, 0, sizeof(buf));
10375 bcm_mkiovar("cur_etheraddr", 0, 0, buf, sizeof(buf));
10376 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_GET_VAR, buf, sizeof(buf),
10377 FALSE, 0)) < 0) {
10378 DHD_ERROR(("%s: can't get MAC address , error=%d\n", __FUNCTION__, ret));
10379 ret = BCME_NOTUP;
10380 goto done;
10381 }
10382 /* Update public MAC address after reading from Firmware */
10383 memcpy(dhd->mac.octet, buf, ETHER_ADDR_LEN);
10384
10385 if ((ret = dhd_apply_default_clm(dhd, dhd->clm_path)) < 0) {
10386 DHD_ERROR(("%s: CLM set failed. Abort initialization.\n", __FUNCTION__));
10387 goto done;
10388 }
10389
10390 /* get a capabilities from firmware */
10391 {
10392 uint32 cap_buf_size = sizeof(dhd->fw_capabilities);
10393 memset(dhd->fw_capabilities, 0, cap_buf_size);
10394 ret = dhd_iovar(dhd, 0, "cap", NULL, 0, dhd->fw_capabilities, (cap_buf_size - 1),
10395 FALSE);
10396 if (ret < 0) {
10397 DHD_ERROR(("%s: Get Capability failed (error=%d)\n",
10398 __FUNCTION__, ret));
10399 return 0;
10400 }
10401
10402 memmove(&dhd->fw_capabilities[1], dhd->fw_capabilities, (cap_buf_size - 1));
10403 dhd->fw_capabilities[0] = ' ';
10404 dhd->fw_capabilities[cap_buf_size - 2] = ' ';
10405 dhd->fw_capabilities[cap_buf_size - 1] = '\0';
10406 }
10407
10408 if ((!op_mode && dhd_get_fw_mode(dhd->info) == DHD_FLAG_HOSTAP_MODE) ||
10409 (op_mode == DHD_FLAG_HOSTAP_MODE)) {
10410 #ifdef SET_RANDOM_MAC_SOFTAP
10411 uint rand_mac;
10412 #endif /* SET_RANDOM_MAC_SOFTAP */
10413 dhd->op_mode = DHD_FLAG_HOSTAP_MODE;
10414 #if defined(ARP_OFFLOAD_SUPPORT)
10415 arpoe = 0;
10416 #endif // endif
10417 #ifdef PKT_FILTER_SUPPORT
10418 if (dhd_conf_get_insuspend(dhd, AP_FILTER_IN_SUSPEND))
10419 dhd_pkt_filter_enable = TRUE;
10420 else
10421 dhd_pkt_filter_enable = FALSE;
10422 #endif // endif
10423 #ifdef SET_RANDOM_MAC_SOFTAP
10424 SRANDOM32((uint)jiffies);
10425 rand_mac = RANDOM32();
10426 iovbuf[0] = (unsigned char)(vendor_oui >> 16) | 0x02; /* local admin bit */
10427 iovbuf[1] = (unsigned char)(vendor_oui >> 8);
10428 iovbuf[2] = (unsigned char)vendor_oui;
10429 iovbuf[3] = (unsigned char)(rand_mac & 0x0F) | 0xF0;
10430 iovbuf[4] = (unsigned char)(rand_mac >> 8);
10431 iovbuf[5] = (unsigned char)(rand_mac >> 16);
10432
10433 ret = dhd_iovar(dhd, 0, "cur_etheraddr", (char *)&iovbuf, ETHER_ADDR_LEN, NULL, 0,
10434 TRUE);
10435 if (ret < 0) {
10436 DHD_ERROR(("%s: can't set MAC address , error=%d\n", __FUNCTION__, ret));
10437 } else
10438 memcpy(dhd->mac.octet, iovbuf, ETHER_ADDR_LEN);
10439 #endif /* SET_RANDOM_MAC_SOFTAP */
10440 #ifdef USE_DYNAMIC_F2_BLKSIZE
10441 dhdsdio_func_blocksize(dhd, 2, DYNAMIC_F2_BLKSIZE_FOR_NONLEGACY);
10442 #endif /* USE_DYNAMIC_F2_BLKSIZE */
10443 #ifdef SOFTAP_UAPSD_OFF
10444 ret = dhd_iovar(dhd, 0, "wme_apsd", (char *)&wme_apsd, sizeof(wme_apsd), NULL, 0,
10445 TRUE);
10446 if (ret < 0) {
10447 DHD_ERROR(("%s: set wme_apsd 0 fail (error=%d)\n",
10448 __FUNCTION__, ret));
10449 }
10450 #endif /* SOFTAP_UAPSD_OFF */
10451 #if defined(CUSTOM_COUNTRY_CODE)
10452 /* set AP flag for specific country code of SOFTAP */
10453 dhd->dhd_cflags |= WLAN_PLAT_AP_FLAG | WLAN_PLAT_NODFS_FLAG;
10454 #endif /* CUSTOM_COUNTRY_CODE && (CUSTOMER_HW2 || BOARD_HIKEY) */
10455 } else if ((!op_mode && dhd_get_fw_mode(dhd->info) == DHD_FLAG_MFG_MODE) ||
10456 (op_mode == DHD_FLAG_MFG_MODE)) {
10457 #if defined(ARP_OFFLOAD_SUPPORT)
10458 arpoe = 0;
10459 #endif /* ARP_OFFLOAD_SUPPORT */
10460 #ifdef PKT_FILTER_SUPPORT
10461 dhd_pkt_filter_enable = FALSE;
10462 #endif /* PKT_FILTER_SUPPORT */
10463 dhd->op_mode = DHD_FLAG_MFG_MODE;
10464 #ifdef USE_DYNAMIC_F2_BLKSIZE
10465 dhdsdio_func_blocksize(dhd, 2, DYNAMIC_F2_BLKSIZE_FOR_NONLEGACY);
10466 #endif /* USE_DYNAMIC_F2_BLKSIZE */
10467 #ifndef CUSTOM_SET_ANTNPM
10468 if (FW_SUPPORTED(dhd, rsdb)) {
10469 wl_config_t rsdb_mode;
10470 memset(&rsdb_mode, 0, sizeof(rsdb_mode));
10471 ret = dhd_iovar(dhd, 0, "rsdb_mode", (char *)&rsdb_mode, sizeof(rsdb_mode),
10472 NULL, 0, TRUE);
10473 if (ret < 0) {
10474 DHD_ERROR(("%s Disable rsdb_mode is failed ret= %d\n",
10475 __FUNCTION__, ret));
10476 }
10477 }
10478 #endif /* !CUSTOM_SET_ANTNPM */
10479 } else {
10480 uint32 concurrent_mode = 0;
10481 if ((!op_mode && dhd_get_fw_mode(dhd->info) == DHD_FLAG_P2P_MODE) ||
10482 (op_mode == DHD_FLAG_P2P_MODE)) {
10483 #if defined(ARP_OFFLOAD_SUPPORT)
10484 arpoe = 0;
10485 #endif // endif
10486 #ifdef PKT_FILTER_SUPPORT
10487 dhd_pkt_filter_enable = FALSE;
10488 #endif // endif
10489 dhd->op_mode = DHD_FLAG_P2P_MODE;
10490 } else if ((!op_mode && dhd_get_fw_mode(dhd->info) == DHD_FLAG_IBSS_MODE) ||
10491 (op_mode == DHD_FLAG_IBSS_MODE)) {
10492 dhd->op_mode = DHD_FLAG_IBSS_MODE;
10493 } else
10494 dhd->op_mode = DHD_FLAG_STA_MODE;
10495 #if !defined(AP) && defined(WLP2P)
10496 if (dhd->op_mode != DHD_FLAG_IBSS_MODE &&
10497 (concurrent_mode = dhd_get_concurrent_capabilites(dhd))) {
10498 #if defined(ARP_OFFLOAD_SUPPORT)
10499 arpoe = 1;
10500 #endif // endif
10501 dhd->op_mode |= concurrent_mode;
10502 }
10503
10504 /* Check if we are enabling p2p */
10505 if (dhd->op_mode & DHD_FLAG_P2P_MODE) {
10506 ret = dhd_iovar(dhd, 0, "apsta", (char *)&apsta, sizeof(apsta), NULL, 0,
10507 TRUE);
10508 if (ret < 0)
10509 DHD_ERROR(("%s APSTA for P2P failed ret= %d\n", __FUNCTION__, ret));
10510
10511 #if defined(SOFTAP_AND_GC)
10512 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_AP,
10513 (char *)&ap_mode, sizeof(ap_mode), TRUE, 0)) < 0) {
10514 DHD_ERROR(("%s WLC_SET_AP failed %d\n", __FUNCTION__, ret));
10515 }
10516 #endif // endif
10517 memcpy(&p2p_ea, &dhd->mac, ETHER_ADDR_LEN);
10518 ETHER_SET_LOCALADDR(&p2p_ea);
10519 ret = dhd_iovar(dhd, 0, "p2p_da_override", (char *)&p2p_ea, sizeof(p2p_ea),
10520 NULL, 0, TRUE);
10521 if (ret < 0)
10522 DHD_ERROR(("%s p2p_da_override ret= %d\n", __FUNCTION__, ret));
10523 else
10524 DHD_INFO(("dhd_preinit_ioctls: p2p_da_override succeeded\n"));
10525 }
10526 #else
10527 (void)concurrent_mode;
10528 #endif // endif
10529 }
10530
10531 #ifdef DISABLE_PRUNED_SCAN
10532 if (FW_SUPPORTED(dhd, rsdb)) {
10533 ret = dhd_iovar(dhd, 0, "scan_features", (char *)&scan_features,
10534 sizeof(scan_features), iovbuf, sizeof(iovbuf), FALSE);
10535 if (ret < 0) {
10536 DHD_ERROR(("%s get scan_features is failed ret=%d\n",
10537 __FUNCTION__, ret));
10538 } else {
10539 memcpy(&scan_features, iovbuf, 4);
10540 scan_features &= ~RSDB_SCAN_DOWNGRADED_CH_PRUNE_ROAM;
10541 ret = dhd_iovar(dhd, 0, "scan_features", (char *)&scan_features,
10542 sizeof(scan_features), NULL, 0, TRUE);
10543 if (ret < 0) {
10544 DHD_ERROR(("%s set scan_features is failed ret=%d\n",
10545 __FUNCTION__, ret));
10546 }
10547 }
10548 }
10549 #endif /* DISABLE_PRUNED_SCAN */
10550
10551 #if defined(DHD_BLOB_EXISTENCE_CHECK)
10552 if (!dhd->is_blob)
10553 #endif /* DHD_BLOB_EXISTENCE_CHECK */
10554 {
10555 /* get a ccode and revision for the country code */
10556 #if defined(CUSTOM_COUNTRY_CODE)
10557 get_customized_country_code(dhd->info->adapter, dhd->dhd_cspec.country_abbrev,
10558 &dhd->dhd_cspec, dhd->dhd_cflags);
10559 #else
10560 get_customized_country_code(dhd->info->adapter, dhd->dhd_cspec.country_abbrev,
10561 &dhd->dhd_cspec);
10562 #endif /* CUSTOM_COUNTRY_CODE */
10563 }
10564
10565 #if defined(RXFRAME_THREAD) && defined(RXTHREAD_ONLYSTA)
10566 if (dhd->op_mode == DHD_FLAG_HOSTAP_MODE)
10567 dhd->info->rxthread_enabled = FALSE;
10568 else
10569 dhd->info->rxthread_enabled = TRUE;
10570 #endif // endif
10571 /* Set Country code */
10572 if (dhd->dhd_cspec.ccode[0] != 0) {
10573 ret = dhd_iovar(dhd, 0, "country", (char *)&dhd->dhd_cspec, sizeof(wl_country_t),
10574 NULL, 0, TRUE);
10575 if (ret < 0)
10576 DHD_ERROR(("%s: country code setting failed\n", __FUNCTION__));
10577 }
10578
10579 /* Set Listen Interval */
10580 ret = dhd_iovar(dhd, 0, "assoc_listen", (char *)&listen_interval, sizeof(listen_interval),
10581 NULL, 0, TRUE);
10582 if (ret < 0)
10583 DHD_ERROR(("%s assoc_listen failed %d\n", __FUNCTION__, ret));
10584
10585 #if defined(ROAM_ENABLE) || defined(DISABLE_BUILTIN_ROAM)
10586 #ifdef USE_WFA_CERT_CONF
10587 if (sec_get_param_wfa_cert(dhd, SET_PARAM_ROAMOFF, &roamvar) == BCME_OK) {
10588 DHD_ERROR(("%s: read roam_off param =%d\n", __FUNCTION__, roamvar));
10589 }
10590 #endif /* USE_WFA_CERT_CONF */
10591 /* Disable built-in roaming to allowed ext supplicant to take care of roaming */
10592 ret = dhd_iovar(dhd, 0, "roam_off", (char *)&roamvar, sizeof(roamvar), NULL, 0, TRUE);
10593 #endif /* ROAM_ENABLE || DISABLE_BUILTIN_ROAM */
10594 #if defined(ROAM_ENABLE)
10595 #ifdef DISABLE_BCNLOSS_ROAM
10596 ret = dhd_iovar(dhd, 0, "roam_bcnloss_off", (char *)&roam_bcnloss_off,
10597 sizeof(roam_bcnloss_off), NULL, 0, TRUE);
10598 #endif /* DISABLE_BCNLOSS_ROAM */
10599 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_ROAM_TRIGGER, roam_trigger,
10600 sizeof(roam_trigger), TRUE, 0)) < 0)
10601 DHD_ERROR(("%s: roam trigger set failed %d\n", __FUNCTION__, ret));
10602 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_ROAM_SCAN_PERIOD, roam_scan_period,
10603 sizeof(roam_scan_period), TRUE, 0)) < 0)
10604 DHD_ERROR(("%s: roam scan period set failed %d\n", __FUNCTION__, ret));
10605 if ((dhd_wl_ioctl_cmd(dhd, WLC_SET_ROAM_DELTA, roam_delta,
10606 sizeof(roam_delta), TRUE, 0)) < 0)
10607 DHD_ERROR(("%s: roam delta set failed %d\n", __FUNCTION__, ret));
10608 ret = dhd_iovar(dhd, 0, "fullroamperiod", (char *)&roam_fullscan_period,
10609 sizeof(roam_fullscan_period), NULL, 0, TRUE);
10610 if (ret < 0)
10611 DHD_ERROR(("%s: roam fullscan period set failed %d\n", __FUNCTION__, ret));
10612 #ifdef ROAM_AP_ENV_DETECTION
10613 if (roam_trigger[0] == WL_AUTO_ROAM_TRIGGER) {
10614 if (dhd_iovar(dhd, 0, "roam_env_detection", (char *)&roam_env_mode,
10615 sizeof(roam_env_mode), NULL, 0, TRUE) == BCME_OK)
10616 dhd->roam_env_detection = TRUE;
10617 else
10618 dhd->roam_env_detection = FALSE;
10619 }
10620 #endif /* ROAM_AP_ENV_DETECTION */
10621 #endif /* ROAM_ENABLE */
10622
10623 #ifdef CUSTOM_EVENT_PM_WAKE
10624 ret = dhd_iovar(dhd, 0, "const_awake_thresh", (char *)&pm_awake_thresh,
10625 sizeof(pm_awake_thresh), NULL, 0, TRUE);
10626 if (ret < 0) {
10627 DHD_ERROR(("%s set const_awake_thresh failed %d\n", __FUNCTION__, ret));
10628 }
10629 #endif /* CUSTOM_EVENT_PM_WAKE */
10630 #ifdef OKC_SUPPORT
10631 ret = dhd_iovar(dhd, 0, "okc_enable", (char *)&okc, sizeof(okc), NULL, 0, TRUE);
10632 #endif // endif
10633 #ifdef BCMCCX
10634 ret = dhd_iovar(dhd, 0, "ccx_enable", (char *)&ccx, sizeof(ccx), NULL, 0, TRUE);
10635 #endif /* BCMCCX */
10636
10637 #ifdef WLTDLS
10638 dhd->tdls_enable = FALSE;
10639 dhd_tdls_set_mode(dhd, false);
10640 #endif /* WLTDLS */
10641
10642 #ifdef DHD_ENABLE_LPC
10643 /* Set lpc 1 */
10644 ret = dhd_iovar(dhd, 0, "lpc", (char *)&lpc, sizeof(lpc), NULL, 0, TRUE);
10645 if (ret < 0) {
10646 DHD_ERROR(("%s Set lpc failed %d\n", __FUNCTION__, ret));
10647
10648 if (ret == BCME_NOTDOWN) {
10649 uint wl_down = 1;
10650 ret = dhd_wl_ioctl_cmd(dhd, WLC_DOWN,
10651 (char *)&wl_down, sizeof(wl_down), TRUE, 0);
10652 DHD_ERROR(("%s lpc fail WL_DOWN : %d, lpc = %d\n", __FUNCTION__, ret, lpc));
10653
10654 ret = dhd_iovar(dhd, 0, "lpc", (char *)&lpc, sizeof(lpc), NULL, 0, TRUE);
10655 DHD_ERROR(("%s Set lpc ret --> %d\n", __FUNCTION__, ret));
10656 }
10657 }
10658 #endif /* DHD_ENABLE_LPC */
10659
10660 #ifdef WLADPS
10661 if (dhd->op_mode & DHD_FLAG_STA_MODE) {
10662 if ((ret = dhd_enable_adps(dhd, ADPS_ENABLE)) != BCME_OK) {
10663 DHD_ERROR(("%s dhd_enable_adps failed %d\n",
10664 __FUNCTION__, ret));
10665 }
10666 }
10667 #endif /* WLADPS */
10668
10669 #ifdef DHD_PM_CONTROL_FROM_FILE
10670 sec_control_pm(dhd, &power_mode);
10671 #else
10672 /* Set PowerSave mode */
10673 (void) dhd_wl_ioctl_cmd(dhd, WLC_SET_PM, (char *)&power_mode, sizeof(power_mode), TRUE, 0);
10674 #endif /* DHD_PM_CONTROL_FROM_FILE */
10675
10676 #if defined(BCMSDIO)
10677 /* Match Host and Dongle rx alignment */
10678 ret = dhd_iovar(dhd, 0, "bus:txglomalign", (char *)&dongle_align, sizeof(dongle_align),
10679 NULL, 0, TRUE);
10680
10681 #if defined(USE_WL_CREDALL)
10682 /* enable credall to reduce the chance of no bus credit happened. */
10683 ret = dhd_iovar(dhd, 0, "bus:credall", (char *)&credall, sizeof(credall), NULL, 0, TRUE);
10684 #endif // endif
10685
10686 #ifdef USE_WFA_CERT_CONF
10687 if (sec_get_param_wfa_cert(dhd, SET_PARAM_BUS_TXGLOM_MODE, &glom) == BCME_OK) {
10688 DHD_ERROR(("%s, read txglom param =%d\n", __FUNCTION__, glom));
10689 }
10690 #endif /* USE_WFA_CERT_CONF */
10691 if (glom != DEFAULT_GLOM_VALUE) {
10692 DHD_INFO(("%s set glom=0x%X\n", __FUNCTION__, glom));
10693 ret = dhd_iovar(dhd, 0, "bus:txglom", (char *)&glom, sizeof(glom), NULL, 0, TRUE);
10694 }
10695 #endif /* defined(BCMSDIO) */
10696
10697 /* Setup timeout if Beacons are lost and roam is off to report link down */
10698 ret = dhd_iovar(dhd, 0, "bcn_timeout", (char *)&bcn_timeout, sizeof(bcn_timeout), NULL, 0,
10699 TRUE);
10700
10701 /* Setup assoc_retry_max count to reconnect target AP in dongle */
10702 ret = dhd_iovar(dhd, 0, "assoc_retry_max", (char *)&retry_max, sizeof(retry_max), NULL, 0,
10703 TRUE);
10704
10705 #if defined(AP) && !defined(WLP2P)
10706 ret = dhd_iovar(dhd, 0, "apsta", (char *)&apsta, sizeof(apsta), NULL, 0, TRUE);
10707
10708 #endif /* defined(AP) && !defined(WLP2P) */
10709
10710 #ifdef MIMO_ANT_SETTING
10711 dhd_sel_ant_from_file(dhd);
10712 #endif /* MIMO_ANT_SETTING */
10713
10714 #if defined(SOFTAP)
10715 if (ap_fw_loaded == TRUE) {
10716 dhd_wl_ioctl_cmd(dhd, WLC_SET_DTIMPRD, (char *)&dtim, sizeof(dtim), TRUE, 0);
10717 }
10718 #endif // endif
10719
10720 #if defined(KEEP_ALIVE)
10721 {
10722 /* Set Keep Alive : be sure to use FW with -keepalive */
10723 int res;
10724
10725 #if defined(SOFTAP)
10726 if (ap_fw_loaded == FALSE)
10727 #endif // endif
10728 if (!(dhd->op_mode &
10729 (DHD_FLAG_HOSTAP_MODE | DHD_FLAG_MFG_MODE))) {
10730 if ((res = dhd_keep_alive_onoff(dhd)) < 0)
10731 DHD_ERROR(("%s set keeplive failed %d\n",
10732 __FUNCTION__, res));
10733 }
10734 }
10735 #endif /* defined(KEEP_ALIVE) */
10736
10737 #ifdef USE_WL_TXBF
10738 ret = dhd_iovar(dhd, 0, "txbf", (char *)&txbf, sizeof(txbf), NULL, 0, TRUE);
10739 if (ret < 0)
10740 DHD_ERROR(("%s Set txbf failed %d\n", __FUNCTION__, ret));
10741
10742 #endif /* USE_WL_TXBF */
10743
10744 ret = dhd_iovar(dhd, 0, "scancache", (char *)&scancache_enab, sizeof(scancache_enab), NULL,
10745 0, TRUE);
10746 if (ret < 0) {
10747 DHD_ERROR(("%s Set scancache failed %d\n", __FUNCTION__, ret));
10748 }
10749
10750 ret = dhd_iovar(dhd, 0, "event_log_max_sets", NULL, 0, (char *)&event_log_max_sets,
10751 sizeof(event_log_max_sets), FALSE);
10752 if (ret == BCME_OK) {
10753 dhd->event_log_max_sets = event_log_max_sets;
10754 } else {
10755 dhd->event_log_max_sets = NUM_EVENT_LOG_SETS;
10756 }
10757 /* Make sure max_sets is set first with wmb and then sets_queried,
10758 * this will be used during parsing the logsets in the reverse order.
10759 */
10760 OSL_SMP_WMB();
10761 dhd->event_log_max_sets_queried = TRUE;
10762 DHD_ERROR(("%s: event_log_max_sets: %d ret: %d\n",
10763 __FUNCTION__, dhd->event_log_max_sets, ret));
10764
10765 #ifdef DISABLE_TXBFR
10766 ret = dhd_iovar(dhd, 0, "txbf_bfr_cap", (char *)&txbf_bfr_cap, sizeof(txbf_bfr_cap), NULL,
10767 0, TRUE);
10768 if (ret < 0) {
10769 DHD_ERROR(("%s Clear txbf_bfr_cap failed %d\n", __FUNCTION__, ret));
10770 }
10771 #endif /* DISABLE_TXBFR */
10772
10773 #ifdef USE_WFA_CERT_CONF
10774 #ifdef USE_WL_FRAMEBURST
10775 if (sec_get_param_wfa_cert(dhd, SET_PARAM_FRAMEBURST, &frameburst) == BCME_OK) {
10776 DHD_ERROR(("%s, read frameburst param=%d\n", __FUNCTION__, frameburst));
10777 }
10778 #endif /* USE_WL_FRAMEBURST */
10779 g_frameburst = frameburst;
10780 #endif /* USE_WFA_CERT_CONF */
10781 #ifdef DISABLE_WL_FRAMEBURST_SOFTAP
10782 /* Disable Framebursting for SofAP */
10783 if (dhd->op_mode & DHD_FLAG_HOSTAP_MODE) {
10784 frameburst = 0;
10785 }
10786 #endif /* DISABLE_WL_FRAMEBURST_SOFTAP */
10787 /* Set frameburst to value */
10788 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_FAKEFRAG, (char *)&frameburst,
10789 sizeof(frameburst), TRUE, 0)) < 0) {
10790 DHD_INFO(("%s frameburst not supported %d\n", __FUNCTION__, ret));
10791 }
10792 #ifdef DHD_SET_FW_HIGHSPEED
10793 /* Set ack_ratio */
10794 ret = dhd_iovar(dhd, 0, "ack_ratio", (char *)&ack_ratio, sizeof(ack_ratio), NULL, 0, TRUE);
10795 if (ret < 0) {
10796 DHD_ERROR(("%s Set ack_ratio failed %d\n", __FUNCTION__, ret));
10797 }
10798
10799 /* Set ack_ratio_depth */
10800 ret = dhd_iovar(dhd, 0, "ack_ratio_depth", (char *)&ack_ratio_depth,
10801 sizeof(ack_ratio_depth), NULL, 0, TRUE);
10802 if (ret < 0) {
10803 DHD_ERROR(("%s Set ack_ratio_depth failed %d\n", __FUNCTION__, ret));
10804 }
10805 #endif /* DHD_SET_FW_HIGHSPEED */
10806
10807 iov_buf = (char*)MALLOC(dhd->osh, WLC_IOCTL_SMLEN);
10808 if (iov_buf == NULL) {
10809 DHD_ERROR(("failed to allocate %d bytes for iov_buf\n", WLC_IOCTL_SMLEN));
10810 ret = BCME_NOMEM;
10811 goto done;
10812 }
10813
10814 #if defined(CUSTOM_AMPDU_BA_WSIZE)
10815 /* Set ampdu ba wsize to 64 or 16 */
10816 #ifdef CUSTOM_AMPDU_BA_WSIZE
10817 ampdu_ba_wsize = CUSTOM_AMPDU_BA_WSIZE;
10818 #endif // endif
10819 if (ampdu_ba_wsize != 0) {
10820 ret = dhd_iovar(dhd, 0, "ampdu_ba_wsize", (char *)&du_ba_wsize,
10821 sizeof(ampdu_ba_wsize), NULL, 0, TRUE);
10822 if (ret < 0) {
10823 DHD_ERROR(("%s Set ampdu_ba_wsize to %d failed %d\n",
10824 __FUNCTION__, ampdu_ba_wsize, ret));
10825 }
10826 }
10827 #endif // endif
10828
10829 #if defined(CUSTOM_AMPDU_MPDU)
10830 ampdu_mpdu = CUSTOM_AMPDU_MPDU;
10831 if (ampdu_mpdu != 0 && (ampdu_mpdu <= ampdu_ba_wsize)) {
10832 ret = dhd_iovar(dhd, 0, "ampdu_mpdu", (char *)&du_mpdu, sizeof(ampdu_mpdu),
10833 NULL, 0, TRUE);
10834 if (ret < 0) {
10835 DHD_ERROR(("%s Set ampdu_mpdu to %d failed %d\n",
10836 __FUNCTION__, CUSTOM_AMPDU_MPDU, ret));
10837 }
10838 }
10839 #endif /* CUSTOM_AMPDU_MPDU */
10840
10841 #if defined(CUSTOM_AMPDU_RELEASE)
10842 ampdu_release = CUSTOM_AMPDU_RELEASE;
10843 if (ampdu_release != 0 && (ampdu_release <= ampdu_ba_wsize)) {
10844 ret = dhd_iovar(dhd, 0, "ampdu_release", (char *)&du_release,
10845 sizeof(ampdu_release), NULL, 0, TRUE);
10846 if (ret < 0) {
10847 DHD_ERROR(("%s Set ampdu_release to %d failed %d\n",
10848 __FUNCTION__, CUSTOM_AMPDU_RELEASE, ret));
10849 }
10850 }
10851 #endif /* CUSTOM_AMPDU_RELEASE */
10852
10853 #if defined(CUSTOM_AMSDU_AGGSF)
10854 amsdu_aggsf = CUSTOM_AMSDU_AGGSF;
10855 if (amsdu_aggsf != 0) {
10856 ret = dhd_iovar(dhd, 0, "amsdu_aggsf", (char *)&amsdu_aggsf, sizeof(amsdu_aggsf),
10857 NULL, 0, TRUE);
10858 if (ret < 0) {
10859 DHD_ERROR(("%s Set amsdu_aggsf to %d failed %d\n",
10860 __FUNCTION__, CUSTOM_AMSDU_AGGSF, ret));
10861 }
10862 }
10863 #endif /* CUSTOM_AMSDU_AGGSF */
10864
10865 #if defined(BCMSUP_4WAY_HANDSHAKE)
10866 /* Read 4-way handshake requirements */
10867 if (dhd_use_idsup == 1) {
10868 ret = dhd_iovar(dhd, 0, "sup_wpa", (char *)&sup_wpa, sizeof(sup_wpa),
10869 (char *)&iovbuf, sizeof(iovbuf), FALSE);
10870 /* sup_wpa iovar returns NOTREADY status on some platforms using modularized
10871 * in-dongle supplicant.
10872 */
10873 if (ret >= 0 || ret == BCME_NOTREADY)
10874 dhd->fw_4way_handshake = TRUE;
10875 DHD_TRACE(("4-way handshake mode is: %d\n", dhd->fw_4way_handshake));
10876 }
10877 #endif /* BCMSUP_4WAY_HANDSHAKE */
10878 #if defined(SUPPORT_2G_VHT) || defined(SUPPORT_5G_1024QAM_VHT)
10879 ret = dhd_iovar(dhd, 0, "vht_features", (char *)&vht_features, sizeof(vht_features),
10880 NULL, 0, FALSE);
10881 if (ret < 0) {
10882 DHD_ERROR(("%s vht_features get failed %d\n", __FUNCTION__, ret));
10883 vht_features = 0;
10884 } else {
10885 #ifdef SUPPORT_2G_VHT
10886 vht_features |= 0x3; /* 2G support */
10887 #endif /* SUPPORT_2G_VHT */
10888 #ifdef SUPPORT_5G_1024QAM_VHT
10889 vht_features |= 0x6; /* 5G 1024 QAM support */
10890 #endif /* SUPPORT_5G_1024QAM_VHT */
10891 }
10892 if (vht_features) {
10893 ret = dhd_iovar(dhd, 0, "vht_features", (char *)&vht_features, sizeof(vht_features),
10894 NULL, 0, TRUE);
10895 if (ret < 0) {
10896 DHD_ERROR(("%s vht_features set failed %d\n", __FUNCTION__, ret));
10897
10898 if (ret == BCME_NOTDOWN) {
10899 uint wl_down = 1;
10900 ret = dhd_wl_ioctl_cmd(dhd, WLC_DOWN,
10901 (char *)&wl_down, sizeof(wl_down), TRUE, 0);
10902 DHD_ERROR(("%s vht_features fail WL_DOWN : %d,"
10903 " vht_features = 0x%x\n",
10904 __FUNCTION__, ret, vht_features));
10905
10906 ret = dhd_iovar(dhd, 0, "vht_features", (char *)&vht_features,
10907 sizeof(vht_features), NULL, 0, TRUE);
10908
10909 DHD_ERROR(("%s vht_features set. ret --> %d\n", __FUNCTION__, ret));
10910 }
10911 }
10912 }
10913 #endif /* SUPPORT_2G_VHT || SUPPORT_5G_1024QAM_VHT */
10914 #ifdef DISABLE_11N_PROPRIETARY_RATES
10915 ret = dhd_iovar(dhd, 0, "ht_features", (char *)&ht_features, sizeof(ht_features), NULL, 0,
10916 TRUE);
10917 if (ret < 0) {
10918 DHD_ERROR(("%s ht_features set failed %d\n", __FUNCTION__, ret));
10919 }
10920 #endif /* DISABLE_11N_PROPRIETARY_RATES */
10921 #if defined(DISABLE_HE_ENAB) || defined(CUSTOM_CONTROL_HE_ENAB)
10922 #if defined(DISABLE_HE_ENAB)
10923 control_he_enab = 0;
10924 #endif /* DISABLE_HE_ENAB */
10925 dhd_control_he_enab(dhd, control_he_enab);
10926 #endif /* DISABLE_HE_ENAB || CUSTOM_CONTROL_HE_ENAB */
10927
10928 #ifdef CUSTOM_PSPRETEND_THR
10929 /* Turn off MPC in AP mode */
10930 ret = dhd_iovar(dhd, 0, "pspretend_threshold", (char *)&pspretend_thr,
10931 sizeof(pspretend_thr), NULL, 0, TRUE);
10932 if (ret < 0) {
10933 DHD_ERROR(("%s pspretend_threshold for HostAPD failed %d\n",
10934 __FUNCTION__, ret));
10935 }
10936 #endif // endif
10937
10938 ret = dhd_iovar(dhd, 0, "buf_key_b4_m4", (char *)&buf_key_b4_m4, sizeof(buf_key_b4_m4),
10939 NULL, 0, TRUE);
10940 if (ret < 0) {
10941 DHD_ERROR(("%s buf_key_b4_m4 set failed %d\n", __FUNCTION__, ret));
10942 }
10943 #ifdef SUPPORT_SET_CAC
10944 ret = dhd_iovar(dhd, 0, "cac", (char *)&cac, sizeof(cac), NULL, 0, TRUE);
10945 if (ret < 0) {
10946 DHD_ERROR(("%s Failed to set cac to %d, %d\n", __FUNCTION__, cac, ret));
10947 }
10948 #endif /* SUPPORT_SET_CAC */
10949 #ifdef DHD_ULP
10950 /* Get the required details from dongle during preinit ioctl */
10951 dhd_ulp_preinit(dhd);
10952 #endif /* DHD_ULP */
10953
10954 /* Read event_msgs mask */
10955 ret = dhd_iovar(dhd, 0, "event_msgs", eventmask, WL_EVENTING_MASK_LEN, iovbuf,
10956 sizeof(iovbuf), FALSE);
10957 if (ret < 0) {
10958 DHD_ERROR(("%s read Event mask failed %d\n", __FUNCTION__, ret));
10959 goto done;
10960 }
10961 bcopy(iovbuf, eventmask, WL_EVENTING_MASK_LEN);
10962
10963 /* Setup event_msgs */
10964 setbit(eventmask, WLC_E_SET_SSID);
10965 setbit(eventmask, WLC_E_PRUNE);
10966 setbit(eventmask, WLC_E_AUTH);
10967 setbit(eventmask, WLC_E_AUTH_IND);
10968 setbit(eventmask, WLC_E_ASSOC);
10969 setbit(eventmask, WLC_E_REASSOC);
10970 setbit(eventmask, WLC_E_REASSOC_IND);
10971 if (!(dhd->op_mode & DHD_FLAG_IBSS_MODE))
10972 setbit(eventmask, WLC_E_DEAUTH);
10973 setbit(eventmask, WLC_E_DEAUTH_IND);
10974 setbit(eventmask, WLC_E_DISASSOC_IND);
10975 setbit(eventmask, WLC_E_DISASSOC);
10976 setbit(eventmask, WLC_E_JOIN);
10977 setbit(eventmask, WLC_E_START);
10978 setbit(eventmask, WLC_E_ASSOC_IND);
10979 setbit(eventmask, WLC_E_PSK_SUP);
10980 setbit(eventmask, WLC_E_LINK);
10981 setbit(eventmask, WLC_E_MIC_ERROR);
10982 setbit(eventmask, WLC_E_ASSOC_REQ_IE);
10983 setbit(eventmask, WLC_E_ASSOC_RESP_IE);
10984 #ifdef LIMIT_BORROW
10985 setbit(eventmask, WLC_E_ALLOW_CREDIT_BORROW);
10986 #endif // endif
10987 #ifndef WL_CFG80211
10988 setbit(eventmask, WLC_E_PMKID_CACHE);
10989 // setbit(eventmask, WLC_E_TXFAIL); // terence 20181106: remove unnecessary event
10990 #endif // endif
10991 setbit(eventmask, WLC_E_JOIN_START);
10992 // setbit(eventmask, WLC_E_SCAN_COMPLETE); // terence 20150628: remove redundant event
10993 #ifdef DHD_DEBUG
10994 setbit(eventmask, WLC_E_SCAN_CONFIRM_IND);
10995 #endif // endif
10996 #ifdef PNO_SUPPORT
10997 setbit(eventmask, WLC_E_PFN_NET_FOUND);
10998 setbit(eventmask, WLC_E_PFN_BEST_BATCHING);
10999 setbit(eventmask, WLC_E_PFN_BSSID_NET_FOUND);
11000 setbit(eventmask, WLC_E_PFN_BSSID_NET_LOST);
11001 #endif /* PNO_SUPPORT */
11002 /* enable dongle roaming event */
11003 #ifdef WL_CFG80211
11004 #if !defined(ROAM_EVT_DISABLE)
11005 setbit(eventmask, WLC_E_ROAM);
11006 #endif /* !ROAM_EVT_DISABLE */
11007 setbit(eventmask, WLC_E_BSSID);
11008 #endif /* WL_CFG80211 */
11009 #ifdef BCMCCX
11010 setbit(eventmask, WLC_E_ADDTS_IND);
11011 setbit(eventmask, WLC_E_DELTS_IND);
11012 #endif /* BCMCCX */
11013 #ifdef WLTDLS
11014 setbit(eventmask, WLC_E_TDLS_PEER_EVENT);
11015 #endif /* WLTDLS */
11016 #ifdef WL_ESCAN
11017 setbit(eventmask, WLC_E_ESCAN_RESULT);
11018 #endif /* WL_ESCAN */
11019 #ifdef CSI_SUPPORT
11020 setbit(eventmask, WLC_E_CSI);
11021 #endif /* CSI_SUPPORT */
11022 #ifdef RTT_SUPPORT
11023 setbit(eventmask, WLC_E_PROXD);
11024 #endif /* RTT_SUPPORT */
11025 #ifdef WL_CFG80211
11026 setbit(eventmask, WLC_E_ESCAN_RESULT);
11027 setbit(eventmask, WLC_E_AP_STARTED);
11028 setbit(eventmask, WLC_E_ACTION_FRAME_RX);
11029 if (dhd->op_mode & DHD_FLAG_P2P_MODE) {
11030 setbit(eventmask, WLC_E_P2P_DISC_LISTEN_COMPLETE);
11031 }
11032 #endif /* WL_CFG80211 */
11033
11034 #if defined(SHOW_LOGTRACE) && defined(LOGTRACE_FROM_FILE)
11035 if (dhd_logtrace_from_file(dhd)) {
11036 setbit(eventmask, WLC_E_TRACE);
11037 } else {
11038 clrbit(eventmask, WLC_E_TRACE);
11039 }
11040 #elif defined(SHOW_LOGTRACE)
11041 setbit(eventmask, WLC_E_TRACE);
11042 #else
11043 clrbit(eventmask, WLC_E_TRACE);
11044 #endif /* defined(SHOW_LOGTRACE) && defined(LOGTRACE_FROM_FILE) */
11045
11046 setbit(eventmask, WLC_E_CSA_COMPLETE_IND);
11047 #ifdef CUSTOM_EVENT_PM_WAKE
11048 setbit(eventmask, WLC_E_EXCESS_PM_WAKE_EVENT);
11049 #endif /* CUSTOM_EVENT_PM_WAKE */
11050 #ifdef DHD_LOSSLESS_ROAMING
11051 setbit(eventmask, WLC_E_ROAM_PREP);
11052 #endif // endif
11053 /* nan events */
11054 setbit(eventmask, WLC_E_NAN);
11055 #if defined(PCIE_FULL_DONGLE) && defined(DHD_LOSSLESS_ROAMING)
11056 dhd_update_flow_prio_map(dhd, DHD_FLOW_PRIO_LLR_MAP);
11057 #endif /* defined(PCIE_FULL_DONGLE) && defined(DHD_LOSSLESS_ROAMING) */
11058
11059 #if defined(BCMPCIE) && defined(EAPOL_PKT_PRIO)
11060 dhd_update_flow_prio_map(dhd, DHD_FLOW_PRIO_LLR_MAP);
11061 #endif /* defined(BCMPCIE) && defined(EAPOL_PKT_PRIO) */
11062
11063 /* Write updated Event mask */
11064 ret = dhd_iovar(dhd, 0, "event_msgs", eventmask, WL_EVENTING_MASK_LEN, NULL, 0, TRUE);
11065 if (ret < 0) {
11066 DHD_ERROR(("%s Set Event mask failed %d\n", __FUNCTION__, ret));
11067 goto done;
11068 }
11069
11070 /* make up event mask ext message iovar for event larger than 128 */
11071 msglen = ROUNDUP(WLC_E_LAST, NBBY)/NBBY + EVENTMSGS_EXT_STRUCT_SIZE;
11072 eventmask_msg = (eventmsgs_ext_t*)MALLOC(dhd->osh, msglen);
11073 if (eventmask_msg == NULL) {
11074 DHD_ERROR(("failed to allocate %d bytes for event_msg_ext\n", msglen));
11075 ret = BCME_NOMEM;
11076 goto done;
11077 }
11078 bzero(eventmask_msg, msglen);
11079 eventmask_msg->ver = EVENTMSGS_VER;
11080 eventmask_msg->len = ROUNDUP(WLC_E_LAST, NBBY)/NBBY;
11081
11082 /* Read event_msgs_ext mask */
11083 ret2 = dhd_iovar(dhd, 0, "event_msgs_ext", (char *)eventmask_msg, msglen, iov_buf,
11084 WLC_IOCTL_SMLEN, FALSE);
11085
11086 if (ret2 == 0) { /* event_msgs_ext must be supported */
11087 bcopy(iov_buf, eventmask_msg, msglen);
11088 #ifdef RSSI_MONITOR_SUPPORT
11089 setbit(eventmask_msg->mask, WLC_E_RSSI_LQM);
11090 #endif /* RSSI_MONITOR_SUPPORT */
11091 #ifdef GSCAN_SUPPORT
11092 setbit(eventmask_msg->mask, WLC_E_PFN_GSCAN_FULL_RESULT);
11093 setbit(eventmask_msg->mask, WLC_E_PFN_SCAN_COMPLETE);
11094 setbit(eventmask_msg->mask, WLC_E_PFN_SSID_EXT);
11095 setbit(eventmask_msg->mask, WLC_E_ROAM_EXP_EVENT);
11096 #endif /* GSCAN_SUPPORT */
11097 setbit(eventmask_msg->mask, WLC_E_RSSI_LQM);
11098 #ifdef BT_WIFI_HANDOVER
11099 setbit(eventmask_msg->mask, WLC_E_BT_WIFI_HANDOVER_REQ);
11100 #endif /* BT_WIFI_HANDOVER */
11101 #ifdef DBG_PKT_MON
11102 setbit(eventmask_msg->mask, WLC_E_ROAM_PREP);
11103 #endif /* DBG_PKT_MON */
11104 #ifdef DHD_ULP
11105 setbit(eventmask_msg->mask, WLC_E_ULP);
11106 #endif // endif
11107 #ifdef WL_NATOE
11108 setbit(eventmask_msg->mask, WLC_E_NATOE_NFCT);
11109 #endif /* WL_NATOE */
11110 #ifdef WL_NAN
11111 setbit(eventmask_msg->mask, WLC_E_SLOTTED_BSS_PEER_OP);
11112 #endif /* WL_NAN */
11113 #ifdef WL_MBO
11114 setbit(eventmask_msg->mask, WLC_E_MBO);
11115 #endif /* WL_MBO */
11116 #ifdef WL_CLIENT_SAE
11117 setbit(eventmask_msg->mask, WLC_E_JOIN_START);
11118 #endif /* WL_CLIENT_SAE */
11119 #ifdef WL_BCNRECV
11120 setbit(eventmask_msg->mask, WLC_E_BCNRECV_ABORTED);
11121 #endif /* WL_BCNRECV */
11122 #ifdef WL_CAC_TS
11123 setbit(eventmask_msg->mask, WLC_E_ADDTS_IND);
11124 setbit(eventmask_msg->mask, WLC_E_DELTS_IND);
11125 #endif /* WL_CAC_TS */
11126 #ifdef WL_CHAN_UTIL
11127 setbit(eventmask_msg->mask, WLC_E_BSS_LOAD);
11128 #endif /* WL_CHAN_UTIL */
11129
11130 /* Write updated Event mask */
11131 eventmask_msg->ver = EVENTMSGS_VER;
11132 eventmask_msg->command = EVENTMSGS_SET_MASK;
11133 eventmask_msg->len = ROUNDUP(WLC_E_LAST, NBBY)/NBBY;
11134 ret = dhd_iovar(dhd, 0, "event_msgs_ext", (char *)eventmask_msg, msglen, NULL, 0,
11135 TRUE);
11136 if (ret < 0) {
11137 DHD_ERROR(("%s write event mask ext failed %d\n", __FUNCTION__, ret));
11138 goto done;
11139 }
11140 } else if (ret2 == BCME_UNSUPPORTED || ret2 == BCME_VERSION) {
11141 /* Skip for BCME_UNSUPPORTED or BCME_VERSION */
11142 DHD_ERROR(("%s event_msgs_ext not support or version mismatch %d\n",
11143 __FUNCTION__, ret2));
11144 } else {
11145 DHD_ERROR(("%s read event mask ext failed %d\n", __FUNCTION__, ret2));
11146 ret = ret2;
11147 goto done;
11148 }
11149
11150 #if defined(DHD_8021X_DUMP) && defined(SHOW_LOGTRACE)
11151 /* Enabling event log trace for EAP events */
11152 el_tag = (wl_el_tag_params_t *)MALLOC(dhd->osh, sizeof(wl_el_tag_params_t));
11153 if (el_tag == NULL) {
11154 DHD_ERROR(("failed to allocate %d bytes for event_msg_ext\n",
11155 (int)sizeof(wl_el_tag_params_t)));
11156 ret = BCME_NOMEM;
11157 goto done;
11158 }
11159 el_tag->tag = EVENT_LOG_TAG_4WAYHANDSHAKE;
11160 el_tag->set = 1;
11161 el_tag->flags = EVENT_LOG_TAG_FLAG_LOG;
11162 ret = dhd_iovar(dhd, 0, "event_log_tag_control", (char *)el_tag, sizeof(*el_tag), NULL, 0,
11163 TRUE);
11164 #endif /* DHD_8021X_DUMP */
11165
11166 dhd_wl_ioctl_cmd(dhd, WLC_SET_SCAN_CHANNEL_TIME, (char *)&scan_assoc_time,
11167 sizeof(scan_assoc_time), TRUE, 0);
11168 dhd_wl_ioctl_cmd(dhd, WLC_SET_SCAN_UNASSOC_TIME, (char *)&scan_unassoc_time,
11169 sizeof(scan_unassoc_time), TRUE, 0);
11170 dhd_wl_ioctl_cmd(dhd, WLC_SET_SCAN_PASSIVE_TIME, (char *)&scan_passive_time,
11171 sizeof(scan_passive_time), TRUE, 0);
11172
11173 #ifdef ARP_OFFLOAD_SUPPORT
11174 /* Set and enable ARP offload feature for STA only */
11175 #if defined(SOFTAP)
11176 if (arpoe && !ap_fw_loaded)
11177 #else
11178 if (arpoe)
11179 #endif // endif
11180 {
11181 dhd_arp_offload_enable(dhd, TRUE);
11182 dhd_arp_offload_set(dhd, dhd_arp_mode);
11183 } else {
11184 dhd_arp_offload_enable(dhd, FALSE);
11185 dhd_arp_offload_set(dhd, 0);
11186 }
11187 dhd_arp_enable = arpoe;
11188 #endif /* ARP_OFFLOAD_SUPPORT */
11189
11190 #ifdef PKT_FILTER_SUPPORT
11191 /* Setup default defintions for pktfilter , enable in suspend */
11192 if (dhd_master_mode) {
11193 dhd->pktfilter_count = 6;
11194 dhd->pktfilter[DHD_BROADCAST_FILTER_NUM] = NULL;
11195 if (!FW_SUPPORTED(dhd, pf6)) {
11196 dhd->pktfilter[DHD_MULTICAST4_FILTER_NUM] = NULL;
11197 dhd->pktfilter[DHD_MULTICAST6_FILTER_NUM] = NULL;
11198 } else {
11199 /* Immediately pkt filter TYPE 6 Discard IPv4/IPv6 Multicast Packet */
11200 dhd->pktfilter[DHD_MULTICAST4_FILTER_NUM] = DISCARD_IPV4_MCAST;
11201 dhd->pktfilter[DHD_MULTICAST6_FILTER_NUM] = DISCARD_IPV6_MCAST;
11202 }
11203 /* apply APP pktfilter */
11204 dhd->pktfilter[DHD_ARP_FILTER_NUM] = "105 0 0 12 0xFFFF 0x0806";
11205
11206 #ifdef BLOCK_IPV6_PACKET
11207 /* Setup filter to allow only IPv4 unicast frames */
11208 dhd->pktfilter[DHD_UNICAST_FILTER_NUM] = "100 0 0 0 "
11209 HEX_PREF_STR UNI_FILTER_STR ZERO_ADDR_STR ETHER_TYPE_STR IPV6_FILTER_STR
11210 " "
11211 HEX_PREF_STR ZERO_ADDR_STR ZERO_ADDR_STR ETHER_TYPE_STR ZERO_TYPE_STR;
11212 #else
11213 /* Setup filter to allow only unicast */
11214 dhd->pktfilter[DHD_UNICAST_FILTER_NUM] = "100 0 0 0 0x01 0x00";
11215 #endif /* BLOCK_IPV6_PACKET */
11216
11217 #ifdef PASS_IPV4_SUSPEND
11218 dhd->pktfilter[DHD_MDNS_FILTER_NUM] = "104 0 0 0 0xFFFFFF 0x01005E";
11219 #else
11220 /* Add filter to pass multicastDNS packet and NOT filter out as Broadcast */
11221 dhd->pktfilter[DHD_MDNS_FILTER_NUM] = NULL;
11222 #endif /* PASS_IPV4_SUSPEND */
11223 if (FW_SUPPORTED(dhd, pf6)) {
11224 /* Immediately pkt filter TYPE 6 Dicard Broadcast IP packet */
11225 dhd->pktfilter[DHD_IP4BCAST_DROP_FILTER_NUM] = DISCARD_IPV4_BCAST;
11226 /* Immediately pkt filter TYPE 6 Dicard Cisco STP packet */
11227 dhd->pktfilter[DHD_LLC_STP_DROP_FILTER_NUM] = DISCARD_LLC_STP;
11228 /* Immediately pkt filter TYPE 6 Dicard Cisco XID protocol */
11229 dhd->pktfilter[DHD_LLC_XID_DROP_FILTER_NUM] = DISCARD_LLC_XID;
11230 dhd->pktfilter_count = 10;
11231 }
11232
11233 #ifdef GAN_LITE_NAT_KEEPALIVE_FILTER
11234 dhd->pktfilter_count = 4;
11235 /* Setup filter to block broadcast and NAT Keepalive packets */
11236 /* discard all broadcast packets */
11237 dhd->pktfilter[DHD_UNICAST_FILTER_NUM] = "100 0 0 0 0xffffff 0xffffff";
11238 /* discard NAT Keepalive packets */
11239 dhd->pktfilter[DHD_BROADCAST_FILTER_NUM] = "102 0 0 36 0xffffffff 0x11940009";
11240 /* discard NAT Keepalive packets */
11241 dhd->pktfilter[DHD_MULTICAST4_FILTER_NUM] = "104 0 0 38 0xffffffff 0x11940009";
11242 dhd->pktfilter[DHD_MULTICAST6_FILTER_NUM] = NULL;
11243 #endif /* GAN_LITE_NAT_KEEPALIVE_FILTER */
11244 } else
11245 dhd_conf_discard_pkt_filter(dhd);
11246 dhd_conf_add_pkt_filter(dhd);
11247
11248 #if defined(SOFTAP)
11249 if (ap_fw_loaded) {
11250 dhd_enable_packet_filter(0, dhd);
11251 }
11252 #endif /* defined(SOFTAP) */
11253 dhd_set_packet_filter(dhd);
11254 #endif /* PKT_FILTER_SUPPORT */
11255 #ifdef DISABLE_11N
11256 ret = dhd_iovar(dhd, 0, "nmode", (char *)&nmode, sizeof(nmode), NULL, 0, TRUE);
11257 if (ret < 0)
11258 DHD_ERROR(("%s wl nmode 0 failed %d\n", __FUNCTION__, ret));
11259 #endif /* DISABLE_11N */
11260
11261 #ifdef ENABLE_BCN_LI_BCN_WAKEUP
11262 ret = dhd_iovar(dhd, 0, "bcn_li_bcn", (char *)&bcn_li_bcn, sizeof(bcn_li_bcn), NULL, 0,
11263 TRUE);
11264 #endif /* ENABLE_BCN_LI_BCN_WAKEUP */
11265 #ifdef AMPDU_VO_ENABLE
11266 tid.tid = PRIO_8021D_VO; /* Enable TID(6) for voice */
11267 tid.enable = TRUE;
11268 ret = dhd_iovar(dhd, 0, "ampdu_tid", (char *)&tid, sizeof(tid), NULL, 0, TRUE);
11269
11270 tid.tid = PRIO_8021D_NC; /* Enable TID(7) for voice */
11271 tid.enable = TRUE;
11272 ret = dhd_iovar(dhd, 0, "ampdu_tid", (char *)&tid, sizeof(tid), NULL, 0, TRUE);
11273 #endif // endif
11274 /* query for 'clmver' to get clm version info from firmware */
11275 memset(buf, 0, sizeof(buf));
11276 ret = dhd_iovar(dhd, 0, "clmver", NULL, 0, buf, sizeof(buf), FALSE);
11277 if (ret < 0)
11278 DHD_ERROR(("%s clmver failed %d\n", __FUNCTION__, ret));
11279 else {
11280 char *ver_temp_buf = NULL, *ver_date_buf = NULL;
11281 int len;
11282
11283 if ((ver_temp_buf = bcmstrstr(buf, "Data:")) == NULL) {
11284 DHD_ERROR(("Couldn't find \"Data:\"\n"));
11285 } else {
11286 ver_date_buf = bcmstrstr(buf, "Creation:");
11287 ptr = (ver_temp_buf + strlen("Data:"));
11288 if ((ver_temp_buf = bcmstrtok(&ptr, "\n", 0)) == NULL) {
11289 DHD_ERROR(("Couldn't find New line character\n"));
11290 } else {
11291 memset(clm_version, 0, CLM_VER_STR_LEN);
11292 len = snprintf(clm_version, CLM_VER_STR_LEN - 1, "%s", ver_temp_buf);
11293 if (ver_date_buf) {
11294 ptr = (ver_date_buf + strlen("Creation:"));
11295 ver_date_buf = bcmstrtok(&ptr, "\n", 0);
11296 if (ver_date_buf)
11297 snprintf(clm_version+len, CLM_VER_STR_LEN-1-len,
11298 " (%s)", ver_date_buf);
11299 }
11300 DHD_INFO(("CLM version = %s\n", clm_version));
11301 }
11302 }
11303
11304 if (strlen(clm_version)) {
11305 DHD_INFO(("CLM version = %s\n", clm_version));
11306 } else {
11307 DHD_ERROR(("Couldn't find CLM version!\n"));
11308 }
11309 }
11310 dhd_set_version_info(dhd, fw_version);
11311
11312 #ifdef WRITE_WLANINFO
11313 sec_save_wlinfo(fw_version, EPI_VERSION_STR, dhd->info->nv_path, clm_version);
11314 #endif /* WRITE_WLANINFO */
11315
11316 /* query for 'wlc_ver' to get version info from firmware */
11317 memset(&wlc_ver, 0, sizeof(wl_wlc_version_t));
11318 ret2 = dhd_iovar(dhd, 0, "wlc_ver", NULL, 0, (char *)&wlc_ver,
11319 sizeof(wl_wlc_version_t), FALSE);
11320 if (ret2 < 0) {
11321 DHD_ERROR(("%s wlc_ver failed %d\n", __FUNCTION__, ret2));
11322 if (ret2 != BCME_UNSUPPORTED)
11323 ret = ret2;
11324 } else {
11325 dhd->wlc_ver_major = wlc_ver.wlc_ver_major;
11326 dhd->wlc_ver_minor = wlc_ver.wlc_ver_minor;
11327 }
11328 #ifdef GEN_SOFTAP_INFO_FILE
11329 sec_save_softap_info();
11330 #endif /* GEN_SOFTAP_INFO_FILE */
11331
11332 #if defined(BCMSDIO)
11333 dhd_txglom_enable(dhd, dhd->conf->bus_rxglom);
11334 #endif /* defined(BCMSDIO) */
11335
11336 #if defined(BCMSDIO) || defined(BCMDBUS)
11337 #ifdef PROP_TXSTATUS
11338 if (disable_proptx ||
11339 #ifdef PROP_TXSTATUS_VSDB
11340 /* enable WLFC only if the firmware is VSDB when it is in STA mode */
11341 (dhd->op_mode != DHD_FLAG_HOSTAP_MODE &&
11342 dhd->op_mode != DHD_FLAG_IBSS_MODE) ||
11343 #endif /* PROP_TXSTATUS_VSDB */
11344 FALSE) {
11345 wlfc_enable = FALSE;
11346 }
11347 ret = dhd_conf_get_disable_proptx(dhd);
11348 if (ret == 0){
11349 disable_proptx = 0;
11350 wlfc_enable = TRUE;
11351 } else if (ret >= 1) {
11352 disable_proptx = 1;
11353 wlfc_enable = FALSE;
11354 /* terence 20161229: we should set ampdu_hostreorder=0 when disable_proptx=1 */
11355 hostreorder = 0;
11356 }
11357
11358 #if defined(PROP_TXSTATUS)
11359 #ifdef USE_WFA_CERT_CONF
11360 if (sec_get_param_wfa_cert(dhd, SET_PARAM_PROPTX, &proptx) == BCME_OK) {
11361 DHD_ERROR(("%s , read proptx param=%d\n", __FUNCTION__, proptx));
11362 wlfc_enable = proptx;
11363 }
11364 #endif /* USE_WFA_CERT_CONF */
11365 #endif /* PROP_TXSTATUS */
11366
11367 #ifndef DISABLE_11N
11368 ret = dhd_wl_ioctl_cmd(dhd, WLC_DOWN, (char *)&wl_down, sizeof(wl_down), TRUE, 0);
11369 ret2 = dhd_iovar(dhd, 0, "ampdu_hostreorder", (char *)&hostreorder, sizeof(hostreorder),
11370 NULL, 0, TRUE);
11371 if (ret2 < 0) {
11372 DHD_ERROR(("%s wl ampdu_hostreorder failed %d\n", __FUNCTION__, ret2));
11373 if (ret2 != BCME_UNSUPPORTED)
11374 ret = ret2;
11375
11376 if (ret == BCME_NOTDOWN) {
11377 uint wl_down = 1;
11378 ret2 = dhd_wl_ioctl_cmd(dhd, WLC_DOWN, (char *)&wl_down,
11379 sizeof(wl_down), TRUE, 0);
11380 DHD_ERROR(("%s ampdu_hostreorder fail WL_DOWN : %d, hostreorder :%d\n",
11381 __FUNCTION__, ret2, hostreorder));
11382
11383 ret2 = dhd_iovar(dhd, 0, "ampdu_hostreorder", (char *)&hostreorder,
11384 sizeof(hostreorder), NULL, 0, TRUE);
11385 DHD_ERROR(("%s wl ampdu_hostreorder. ret --> %d\n", __FUNCTION__, ret2));
11386 if (ret2 != BCME_UNSUPPORTED)
11387 ret = ret2;
11388 }
11389 if (ret2 != BCME_OK)
11390 hostreorder = 0;
11391 }
11392 #endif /* DISABLE_11N */
11393
11394 if (wlfc_enable) {
11395 dhd_wlfc_init(dhd);
11396 /* terence 20161229: enable ampdu_hostreorder if tlv enabled */
11397 dhd_conf_set_intiovar(dhd, WLC_SET_VAR, "ampdu_hostreorder", 1, 0, TRUE);
11398 }
11399 #ifndef DISABLE_11N
11400 else if (hostreorder)
11401 dhd_wlfc_hostreorder_init(dhd);
11402 #endif /* DISABLE_11N */
11403 #else
11404 /* terence 20161229: disable ampdu_hostreorder if PROP_TXSTATUS not defined */
11405 printf("%s: not define PROP_TXSTATUS\n", __FUNCTION__);
11406 dhd_conf_set_intiovar(dhd, WLC_SET_VAR, "ampdu_hostreorder", 0, 0, TRUE);
11407 #endif /* PROP_TXSTATUS */
11408 #endif /* BCMSDIO || BCMDBUS */
11409 #ifndef PCIE_FULL_DONGLE
11410 /* For FD we need all the packets at DHD to handle intra-BSS forwarding */
11411 if (FW_SUPPORTED(dhd, ap)) {
11412 wl_ap_isolate = AP_ISOLATE_SENDUP_ALL;
11413 ret = dhd_iovar(dhd, 0, "ap_isolate", (char *)&wl_ap_isolate, sizeof(wl_ap_isolate),
11414 NULL, 0, TRUE);
11415 if (ret < 0)
11416 DHD_ERROR(("%s failed %d\n", __FUNCTION__, ret));
11417 }
11418 #endif /* PCIE_FULL_DONGLE */
11419 #ifdef PNO_SUPPORT
11420 if (!dhd->pno_state) {
11421 dhd_pno_init(dhd);
11422 }
11423 #endif // endif
11424 #ifdef RTT_SUPPORT
11425 if (!dhd->rtt_state) {
11426 ret = dhd_rtt_init(dhd);
11427 if (ret < 0) {
11428 DHD_ERROR(("%s failed to initialize RTT\n", __FUNCTION__));
11429 }
11430 }
11431 #endif // endif
11432 #ifdef FILTER_IE
11433 /* Failure to configure filter IE is not a fatal error, ignore it. */
11434 if (!(dhd->op_mode & (DHD_FLAG_HOSTAP_MODE | DHD_FLAG_MFG_MODE)))
11435 dhd_read_from_file(dhd);
11436 #endif /* FILTER_IE */
11437 #ifdef WL11U
11438 dhd_interworking_enable(dhd);
11439 #endif /* WL11U */
11440
11441 #ifdef NDO_CONFIG_SUPPORT
11442 dhd->ndo_enable = FALSE;
11443 dhd->ndo_host_ip_overflow = FALSE;
11444 dhd->ndo_max_host_ip = NDO_MAX_HOST_IP_ENTRIES;
11445 #endif /* NDO_CONFIG_SUPPORT */
11446
11447 /* ND offload version supported */
11448 dhd->ndo_version = dhd_ndo_get_version(dhd);
11449 if (dhd->ndo_version > 0) {
11450 DHD_INFO(("%s: ndo version %d\n", __FUNCTION__, dhd->ndo_version));
11451
11452 #ifdef NDO_CONFIG_SUPPORT
11453 /* enable Unsolicited NA filter */
11454 ret = dhd_ndo_unsolicited_na_filter_enable(dhd, 1);
11455 if (ret < 0) {
11456 DHD_ERROR(("%s failed to enable Unsolicited NA filter\n", __FUNCTION__));
11457 }
11458 #endif /* NDO_CONFIG_SUPPORT */
11459 }
11460
11461 /* check dongle supports wbtext (product policy) or not */
11462 dhd->wbtext_support = FALSE;
11463 if (dhd_wl_ioctl_get_intiovar(dhd, "wnm_bsstrans_resp", &wnm_bsstrans_resp,
11464 WLC_GET_VAR, FALSE, 0) != BCME_OK) {
11465 DHD_ERROR(("failed to get wnm_bsstrans_resp\n"));
11466 }
11467 dhd->wbtext_policy = wnm_bsstrans_resp;
11468 if (dhd->wbtext_policy == WL_BSSTRANS_POLICY_PRODUCT_WBTEXT) {
11469 dhd->wbtext_support = TRUE;
11470 }
11471 /* driver can turn off wbtext feature through makefile */
11472 if (dhd->wbtext_support) {
11473 if (dhd_wl_ioctl_set_intiovar(dhd, "wnm_bsstrans_resp",
11474 WL_BSSTRANS_POLICY_ROAM_ALWAYS,
11475 WLC_SET_VAR, FALSE, 0) != BCME_OK) {
11476 DHD_ERROR(("failed to disable WBTEXT\n"));
11477 }
11478 }
11479
11480 #ifdef DHD_NON_DMA_M2M_CORRUPTION
11481 /* check pcie non dma loopback */
11482 if (dhd->op_mode == DHD_FLAG_MFG_MODE &&
11483 (dhd_bus_dmaxfer_lpbk(dhd, M2M_NON_DMA_LPBK) < 0)) {
11484 goto done;
11485 }
11486 #endif /* DHD_NON_DMA_M2M_CORRUPTION */
11487
11488 /* WNM capabilities */
11489 wnm_cap = 0
11490 #ifdef WL11U
11491 | WL_WNM_BSSTRANS | WL_WNM_NOTIF
11492 #endif // endif
11493 ;
11494 #if defined(WL_MBO) && defined(WL_OCE)
11495 if (FW_SUPPORTED(dhd, estm)) {
11496 wnm_cap |= WL_WNM_ESTM;
11497 }
11498 #endif /* WL_MBO && WL_OCE */
11499 if (dhd_iovar(dhd, 0, "wnm", (char *)&wnm_cap, sizeof(wnm_cap), NULL, 0, TRUE) < 0) {
11500 DHD_ERROR(("failed to set WNM capabilities\n"));
11501 }
11502
11503 if (FW_SUPPORTED(dhd, ecounters) && enable_ecounter) {
11504 dhd_ecounter_configure(dhd, TRUE);
11505 }
11506
11507 /* store the preserve log set numbers */
11508 if (dhd_get_preserve_log_numbers(dhd, &dhd->logset_prsrv_mask)
11509 != BCME_OK) {
11510 DHD_ERROR(("%s: Failed to get preserve log # !\n", __FUNCTION__));
11511 }
11512
11513 #ifdef WL_MONITOR
11514 if (FW_SUPPORTED(dhd, monitor)) {
11515 dhd->monitor_enable = TRUE;
11516 DHD_ERROR(("%s: Monitor mode is enabled in FW cap\n", __FUNCTION__));
11517 } else {
11518 dhd->monitor_enable = FALSE;
11519 DHD_ERROR(("%s: Monitor mode is not enabled in FW cap\n", __FUNCTION__));
11520 }
11521 #endif /* WL_MONITOR */
11522
11523 #ifdef CONFIG_SILENT_ROAM
11524 dhd->sroam_turn_on = TRUE;
11525 dhd->sroamed = FALSE;
11526 #endif /* CONFIG_SILENT_ROAM */
11527
11528 dhd_conf_postinit_ioctls(dhd);
11529 done:
11530
11531 if (eventmask_msg) {
11532 MFREE(dhd->osh, eventmask_msg, msglen);
11533 eventmask_msg = NULL;
11534 }
11535 if (iov_buf) {
11536 MFREE(dhd->osh, iov_buf, WLC_IOCTL_SMLEN);
11537 iov_buf = NULL;
11538 }
11539 #if defined(DHD_8021X_DUMP) && defined(SHOW_LOGTRACE)
11540 if (el_tag) {
11541 MFREE(dhd->osh, el_tag, sizeof(wl_el_tag_params_t));
11542 el_tag = NULL;
11543 }
11544 #endif /* DHD_8021X_DUMP */
11545 return ret;
11546 }
11547
11548 int
dhd_iovar(dhd_pub_t * pub,int ifidx,char * name,char * param_buf,uint param_len,char * res_buf,uint res_len,int set)11549 dhd_iovar(dhd_pub_t *pub, int ifidx, char *name, char *param_buf, uint param_len, char *res_buf,
11550 uint res_len, int set)
11551 {
11552 char *buf = NULL;
11553 int input_len;
11554 wl_ioctl_t ioc;
11555 int ret;
11556
11557 if (res_len > WLC_IOCTL_MAXLEN || param_len > WLC_IOCTL_MAXLEN)
11558 return BCME_BADARG;
11559
11560 input_len = strlen(name) + 1 + param_len;
11561 if (input_len > WLC_IOCTL_MAXLEN)
11562 return BCME_BADARG;
11563
11564 buf = NULL;
11565 if (set) {
11566 if (res_buf || res_len != 0) {
11567 DHD_ERROR(("%s: SET wrong arguemnet\n", __FUNCTION__));
11568 ret = BCME_BADARG;
11569 goto exit;
11570 }
11571 buf = MALLOCZ(pub->osh, input_len);
11572 if (!buf) {
11573 DHD_ERROR(("%s: mem alloc failed\n", __FUNCTION__));
11574 ret = BCME_NOMEM;
11575 goto exit;
11576 }
11577 ret = bcm_mkiovar(name, param_buf, param_len, buf, input_len);
11578 if (!ret) {
11579 ret = BCME_NOMEM;
11580 goto exit;
11581 }
11582
11583 ioc.cmd = WLC_SET_VAR;
11584 ioc.buf = buf;
11585 ioc.len = input_len;
11586 ioc.set = set;
11587
11588 ret = dhd_wl_ioctl(pub, ifidx, &ioc, ioc.buf, ioc.len);
11589 } else {
11590 if (!res_buf || !res_len) {
11591 DHD_ERROR(("%s: GET failed. resp_buf NULL or length 0.\n", __FUNCTION__));
11592 ret = BCME_BADARG;
11593 goto exit;
11594 }
11595
11596 if (res_len < input_len) {
11597 DHD_INFO(("%s: res_len(%d) < input_len(%d)\n", __FUNCTION__,
11598 res_len, input_len));
11599 buf = MALLOCZ(pub->osh, input_len);
11600 if (!buf) {
11601 DHD_ERROR(("%s: mem alloc failed\n", __FUNCTION__));
11602 ret = BCME_NOMEM;
11603 goto exit;
11604 }
11605 ret = bcm_mkiovar(name, param_buf, param_len, buf, input_len);
11606 if (!ret) {
11607 ret = BCME_NOMEM;
11608 goto exit;
11609 }
11610
11611 ioc.cmd = WLC_GET_VAR;
11612 ioc.buf = buf;
11613 ioc.len = input_len;
11614 ioc.set = set;
11615
11616 ret = dhd_wl_ioctl(pub, ifidx, &ioc, ioc.buf, ioc.len);
11617
11618 if (ret == BCME_OK) {
11619 memcpy(res_buf, buf, res_len);
11620 }
11621 } else {
11622 memset(res_buf, 0, res_len);
11623 ret = bcm_mkiovar(name, param_buf, param_len, res_buf, res_len);
11624 if (!ret) {
11625 ret = BCME_NOMEM;
11626 goto exit;
11627 }
11628
11629 ioc.cmd = WLC_GET_VAR;
11630 ioc.buf = res_buf;
11631 ioc.len = res_len;
11632 ioc.set = set;
11633
11634 ret = dhd_wl_ioctl(pub, ifidx, &ioc, ioc.buf, ioc.len);
11635 }
11636 }
11637 exit:
11638 if (buf) {
11639 MFREE(pub->osh, buf, input_len);
11640 buf = NULL;
11641 }
11642 return ret;
11643 }
11644
11645 int
dhd_getiovar(dhd_pub_t * pub,int ifidx,char * name,char * cmd_buf,uint cmd_len,char ** resptr,uint resp_len)11646 dhd_getiovar(dhd_pub_t *pub, int ifidx, char *name, char *cmd_buf,
11647 uint cmd_len, char **resptr, uint resp_len)
11648 {
11649 int len = resp_len;
11650 int ret;
11651 char *buf = *resptr;
11652 wl_ioctl_t ioc;
11653 if (resp_len > WLC_IOCTL_MAXLEN)
11654 return BCME_BADARG;
11655
11656 memset(buf, 0, resp_len);
11657
11658 ret = bcm_mkiovar(name, cmd_buf, cmd_len, buf, len);
11659 if (ret == 0) {
11660 return BCME_BUFTOOSHORT;
11661 }
11662
11663 memset(&ioc, 0, sizeof(ioc));
11664
11665 ioc.cmd = WLC_GET_VAR;
11666 ioc.buf = buf;
11667 ioc.len = len;
11668 ioc.set = 0;
11669
11670 ret = dhd_wl_ioctl(pub, ifidx, &ioc, ioc.buf, ioc.len);
11671
11672 return ret;
11673 }
11674
dhd_change_mtu(dhd_pub_t * dhdp,int new_mtu,int ifidx)11675 int dhd_change_mtu(dhd_pub_t *dhdp, int new_mtu, int ifidx)
11676 {
11677 struct dhd_info *dhd = dhdp->info;
11678 struct net_device *dev = NULL;
11679
11680 ASSERT(dhd && dhd->iflist[ifidx]);
11681 dev = dhd->iflist[ifidx]->net;
11682 ASSERT(dev);
11683
11684 #ifndef DHD_TPUT_PATCH
11685 if (netif_running(dev)) {
11686 DHD_ERROR(("%s: Must be down to change its MTU\n", dev->name));
11687 return BCME_NOTDOWN;
11688 }
11689 #endif
11690
11691 #define DHD_MIN_MTU 1500
11692 #define DHD_MAX_MTU 1752
11693
11694 if ((new_mtu < DHD_MIN_MTU) || (new_mtu > DHD_MAX_MTU)) {
11695 DHD_ERROR(("%s: MTU size %d is invalid.\n", __FUNCTION__, new_mtu));
11696 return BCME_BADARG;
11697 }
11698
11699 dev->mtu = new_mtu;
11700 return 0;
11701 }
11702
11703 #ifdef CONFIG_AP6XXX_WIFI6_HDF
dhd_netdev_changemtu_wrapper(struct net_device * netdev,int mtu)11704 int dhd_netdev_changemtu_wrapper(struct net_device *netdev, int mtu)
11705 {
11706 int bcmerror = BCME_OK;
11707 dhd_info_t *dhd = DHD_DEV_INFO(netdev);
11708 mtu &= 0xffff;
11709 bcmerror = dhd_change_mtu(&dhd->pub, mtu, 0);
11710 return bcmerror;
11711 }
11712 #endif
11713
11714
11715 #ifdef ARP_OFFLOAD_SUPPORT
11716 /* add or remove AOE host ip(s) (up to 8 IPs on the interface) */
11717 void
aoe_update_host_ipv4_table(dhd_pub_t * dhd_pub,u32 ipa,bool add,int idx)11718 aoe_update_host_ipv4_table(dhd_pub_t *dhd_pub, u32 ipa, bool add, int idx)
11719 {
11720 u32 ipv4_buf[MAX_IPV4_ENTRIES]; /* temp save for AOE host_ip table */
11721 int i;
11722 int ret;
11723
11724 bzero(ipv4_buf, sizeof(ipv4_buf));
11725
11726 /* display what we've got */
11727 ret = dhd_arp_get_arp_hostip_table(dhd_pub, ipv4_buf, sizeof(ipv4_buf), idx);
11728 DHD_ARPOE(("%s: hostip table read from Dongle:\n", __FUNCTION__));
11729 #ifdef AOE_DBG
11730 dhd_print_buf(ipv4_buf, 32, 4); /* max 8 IPs 4b each */
11731 #endif // endif
11732 /* now we saved hoste_ip table, clr it in the dongle AOE */
11733 dhd_aoe_hostip_clr(dhd_pub, idx);
11734
11735 if (ret) {
11736 DHD_ERROR(("%s failed\n", __FUNCTION__));
11737 return;
11738 }
11739
11740 for (i = 0; i < MAX_IPV4_ENTRIES; i++) {
11741 if (add && (ipv4_buf[i] == 0)) {
11742 ipv4_buf[i] = ipa;
11743 add = FALSE; /* added ipa to local table */
11744 DHD_ARPOE(("%s: Saved new IP in temp arp_hostip[%d]\n",
11745 __FUNCTION__, i));
11746 } else if (ipv4_buf[i] == ipa) {
11747 ipv4_buf[i] = 0;
11748 DHD_ARPOE(("%s: removed IP:%x from temp table %d\n",
11749 __FUNCTION__, ipa, i));
11750 }
11751
11752 if (ipv4_buf[i] != 0) {
11753 /* add back host_ip entries from our local cache */
11754 dhd_arp_offload_add_ip(dhd_pub, ipv4_buf[i], idx);
11755 DHD_ARPOE(("%s: added IP:%x to dongle arp_hostip[%d]\n\n",
11756 __FUNCTION__, ipv4_buf[i], i));
11757 }
11758 }
11759 #ifdef AOE_DBG
11760 /* see the resulting hostip table */
11761 dhd_arp_get_arp_hostip_table(dhd_pub, ipv4_buf, sizeof(ipv4_buf), idx);
11762 DHD_ARPOE(("%s: read back arp_hostip table:\n", __FUNCTION__));
11763 dhd_print_buf(ipv4_buf, 32, 4); /* max 8 IPs 4b each */
11764 #endif // endif
11765 }
11766
11767 /*
11768 * Notification mechanism from kernel to our driver. This function is called by the Linux kernel
11769 * whenever there is an event related to an IP address.
11770 * ptr : kernel provided pointer to IP address that has changed
11771 */
dhd_inetaddr_notifier_call(struct notifier_block * this,unsigned long event,void * ptr)11772 static int dhd_inetaddr_notifier_call(struct notifier_block *this,
11773 unsigned long event,
11774 void *ptr)
11775 {
11776 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
11777
11778 dhd_info_t *dhd;
11779 dhd_pub_t *dhd_pub;
11780 int idx;
11781
11782 if (!dhd_arp_enable)
11783 return NOTIFY_DONE;
11784 if (!ifa || !(ifa->ifa_dev->dev))
11785 return NOTIFY_DONE;
11786
11787 /* Filter notifications meant for non Broadcom devices */
11788 if ((ifa->ifa_dev->dev->netdev_ops != &dhd_ops_pri) &&
11789 (ifa->ifa_dev->dev->netdev_ops != &dhd_ops_virt)
11790 #ifdef CONFIG_AP6XXX_WIFI6_HDF
11791 && (ifa->ifa_dev->dev->netdev_ops != hdf_netdev_ops)
11792 #endif
11793 ) {
11794 #if defined(WL_ENABLE_P2P_IF)
11795 if (!wl_cfgp2p_is_ifops(ifa->ifa_dev->dev->netdev_ops))
11796 #endif /* WL_ENABLE_P2P_IF */
11797 return NOTIFY_DONE;
11798 }
11799
11800 dhd = DHD_DEV_INFO(ifa->ifa_dev->dev);
11801 if (!dhd)
11802 return NOTIFY_DONE;
11803
11804 dhd_pub = &dhd->pub;
11805
11806 if (dhd_pub->arp_version == 1) {
11807 idx = 0;
11808 } else {
11809 for (idx = 0; idx < DHD_MAX_IFS; idx++) {
11810 if (dhd->iflist[idx] && dhd->iflist[idx]->net == ifa->ifa_dev->dev)
11811 break;
11812 }
11813 if (idx < DHD_MAX_IFS)
11814 DHD_TRACE(("ifidx : %p %s %d\n", dhd->iflist[idx]->net,
11815 dhd->iflist[idx]->name, dhd->iflist[idx]->idx));
11816 else {
11817 DHD_ERROR(("Cannot find ifidx for(%s) set to 0\n", ifa->ifa_label));
11818 idx = 0;
11819 }
11820 }
11821
11822 switch (event) {
11823 case NETDEV_UP:
11824 DHD_ARPOE(("%s: [%s] Up IP: 0x%x\n",
11825 __FUNCTION__, ifa->ifa_label, ifa->ifa_address));
11826
11827 /*
11828 * Skip if Bus is not in a state to transport the IOVAR
11829 * (or) the Dongle is not ready.
11830 */
11831 if (DHD_BUS_CHECK_DOWN_OR_DOWN_IN_PROGRESS(&dhd->pub) ||
11832 dhd->pub.busstate == DHD_BUS_LOAD) {
11833 DHD_ERROR(("%s: bus not ready, exit NETDEV_UP : %d\n",
11834 __FUNCTION__, dhd->pub.busstate));
11835 if (dhd->pend_ipaddr) {
11836 DHD_ERROR(("%s: overwrite pending ipaddr: 0x%x\n",
11837 __FUNCTION__, dhd->pend_ipaddr));
11838 }
11839 dhd->pend_ipaddr = ifa->ifa_address;
11840 break;
11841 }
11842
11843 #ifdef AOE_IP_ALIAS_SUPPORT
11844 DHD_ARPOE(("%s:add aliased IP to AOE hostip cache\n",
11845 __FUNCTION__));
11846 aoe_update_host_ipv4_table(dhd_pub, ifa->ifa_address, TRUE, idx);
11847 #endif /* AOE_IP_ALIAS_SUPPORT */
11848 dhd_conf_set_garp(dhd_pub, idx, ifa->ifa_address, TRUE);
11849 break;
11850
11851 case NETDEV_DOWN:
11852 DHD_ARPOE(("%s: [%s] Down IP: 0x%x\n",
11853 __FUNCTION__, ifa->ifa_label, ifa->ifa_address));
11854 dhd->pend_ipaddr = 0;
11855 #ifdef AOE_IP_ALIAS_SUPPORT
11856 DHD_ARPOE(("%s:interface is down, AOE clr all for this if\n",
11857 __FUNCTION__));
11858 if ((dhd_pub->op_mode & DHD_FLAG_HOSTAP_MODE) ||
11859 (ifa->ifa_dev->dev != dhd_linux_get_primary_netdev(dhd_pub))) {
11860 aoe_update_host_ipv4_table(dhd_pub, ifa->ifa_address, FALSE, idx);
11861 } else
11862 #endif /* AOE_IP_ALIAS_SUPPORT */
11863 {
11864 dhd_aoe_hostip_clr(&dhd->pub, idx);
11865 dhd_aoe_arp_clr(&dhd->pub, idx);
11866 }
11867 dhd_conf_set_garp(dhd_pub, idx, ifa->ifa_address, FALSE);
11868 break;
11869
11870 default:
11871 DHD_ARPOE(("%s: do noting for [%s] Event: %lu\n",
11872 __func__, ifa->ifa_label, event));
11873 break;
11874 }
11875 return NOTIFY_DONE;
11876 }
11877 #endif /* ARP_OFFLOAD_SUPPORT */
11878
11879 #if defined(CONFIG_IPV6) && defined(IPV6_NDO_SUPPORT)
11880 /* Neighbor Discovery Offload: defered handler */
11881 static void
dhd_inet6_work_handler(void * dhd_info,void * event_data,u8 event)11882 dhd_inet6_work_handler(void *dhd_info, void *event_data, u8 event)
11883 {
11884 struct ipv6_work_info_t *ndo_work = (struct ipv6_work_info_t *)event_data;
11885 dhd_info_t *dhd = (dhd_info_t *)dhd_info;
11886 dhd_pub_t *dhdp;
11887 int ret;
11888
11889 if (!dhd) {
11890 DHD_ERROR(("%s: invalid dhd_info\n", __FUNCTION__));
11891 goto done;
11892 }
11893 dhdp = &dhd->pub;
11894
11895 if (event != DHD_WQ_WORK_IPV6_NDO) {
11896 DHD_ERROR(("%s: unexpected event\n", __FUNCTION__));
11897 goto done;
11898 }
11899
11900 if (!ndo_work) {
11901 DHD_ERROR(("%s: ipv6 work info is not initialized\n", __FUNCTION__));
11902 return;
11903 }
11904
11905 switch (ndo_work->event) {
11906 case NETDEV_UP:
11907 #ifndef NDO_CONFIG_SUPPORT
11908 DHD_TRACE(("%s: Enable NDO \n ", __FUNCTION__));
11909 ret = dhd_ndo_enable(dhdp, TRUE);
11910 if (ret < 0) {
11911 DHD_ERROR(("%s: Enabling NDO Failed %d\n", __FUNCTION__, ret));
11912 }
11913 #endif /* !NDO_CONFIG_SUPPORT */
11914 DHD_TRACE(("%s: Add a host ip for NDO\n", __FUNCTION__));
11915 if (dhdp->ndo_version > 0) {
11916 /* inet6 addr notifier called only for unicast address */
11917 ret = dhd_ndo_add_ip_with_type(dhdp, &ndo_work->ipv6_addr[0],
11918 WL_ND_IPV6_ADDR_TYPE_UNICAST, ndo_work->if_idx);
11919 } else {
11920 ret = dhd_ndo_add_ip(dhdp, &ndo_work->ipv6_addr[0],
11921 ndo_work->if_idx);
11922 }
11923 if (ret < 0) {
11924 DHD_ERROR(("%s: Adding a host ip for NDO failed %d\n",
11925 __FUNCTION__, ret));
11926 }
11927 break;
11928 case NETDEV_DOWN:
11929 if (dhdp->ndo_version > 0) {
11930 DHD_TRACE(("%s: Remove a host ip for NDO\n", __FUNCTION__));
11931 ret = dhd_ndo_remove_ip_by_addr(dhdp,
11932 &ndo_work->ipv6_addr[0], ndo_work->if_idx);
11933 } else {
11934 DHD_TRACE(("%s: Clear host ip table for NDO \n", __FUNCTION__));
11935 ret = dhd_ndo_remove_ip(dhdp, ndo_work->if_idx);
11936 }
11937 if (ret < 0) {
11938 DHD_ERROR(("%s: Removing host ip for NDO failed %d\n",
11939 __FUNCTION__, ret));
11940 goto done;
11941 }
11942 #ifdef NDO_CONFIG_SUPPORT
11943 if (dhdp->ndo_host_ip_overflow) {
11944 ret = dhd_dev_ndo_update_inet6addr(
11945 dhd_idx2net(dhdp, ndo_work->if_idx));
11946 if ((ret < 0) && (ret != BCME_NORESOURCE)) {
11947 DHD_ERROR(("%s: Updating host ip for NDO failed %d\n",
11948 __FUNCTION__, ret));
11949 goto done;
11950 }
11951 }
11952 #else /* !NDO_CONFIG_SUPPORT */
11953 DHD_TRACE(("%s: Disable NDO\n ", __FUNCTION__));
11954 ret = dhd_ndo_enable(dhdp, FALSE);
11955 if (ret < 0) {
11956 DHD_ERROR(("%s: disabling NDO Failed %d\n", __FUNCTION__, ret));
11957 goto done;
11958 }
11959 #endif /* NDO_CONFIG_SUPPORT */
11960 break;
11961
11962 default:
11963 DHD_ERROR(("%s: unknown notifier event \n", __FUNCTION__));
11964 break;
11965 }
11966 done:
11967
11968 /* free ndo_work. alloced while scheduling the work */
11969 if (ndo_work) {
11970 kfree(ndo_work);
11971 }
11972
11973 return;
11974 } /* dhd_init_logstrs_array */
11975
11976 /*
11977 * Neighbor Discovery Offload: Called when an interface
11978 * is assigned with ipv6 address.
11979 * Handles only primary interface
11980 */
dhd_inet6addr_notifier_call(struct notifier_block * this,unsigned long event,void * ptr)11981 int dhd_inet6addr_notifier_call(struct notifier_block *this, unsigned long event, void *ptr)
11982 {
11983 dhd_info_t *dhd;
11984 dhd_pub_t *dhdp;
11985 struct inet6_ifaddr *inet6_ifa = ptr;
11986 struct ipv6_work_info_t *ndo_info;
11987 int idx;
11988
11989 /* Filter notifications meant for non Broadcom devices */
11990 if (inet6_ifa->idev->dev->netdev_ops != &dhd_ops_pri
11991 #ifdef CONFIG_AP6XXX_WIFI6_HDF
11992 && inet6_ifa->idev->dev->netdev_ops != hdf_netdev_ops
11993 #endif
11994 ) {
11995 return NOTIFY_DONE;
11996 }
11997
11998 dhd = DHD_DEV_INFO(inet6_ifa->idev->dev);
11999 if (!dhd) {
12000 return NOTIFY_DONE;
12001 }
12002 dhdp = &dhd->pub;
12003
12004 /* Supports only primary interface */
12005 idx = dhd_net2idx(dhd, inet6_ifa->idev->dev);
12006 if (idx != 0) {
12007 return NOTIFY_DONE;
12008 }
12009
12010 /* FW capability */
12011 if (!FW_SUPPORTED(dhdp, ndoe)) {
12012 return NOTIFY_DONE;
12013 }
12014
12015 ndo_info = (struct ipv6_work_info_t *)kzalloc(sizeof(struct ipv6_work_info_t), GFP_ATOMIC);
12016 if (!ndo_info) {
12017 DHD_ERROR(("%s: ipv6 work alloc failed\n", __FUNCTION__));
12018 return NOTIFY_DONE;
12019 }
12020
12021 /* fill up ndo_info */
12022 ndo_info->event = event;
12023 ndo_info->if_idx = idx;
12024 memcpy(ndo_info->ipv6_addr, &inet6_ifa->addr, IPV6_ADDR_LEN);
12025
12026 /* defer the work to thread as it may block kernel */
12027 dhd_deferred_schedule_work(dhd->dhd_deferred_wq, (void *)ndo_info, DHD_WQ_WORK_IPV6_NDO,
12028 dhd_inet6_work_handler, DHD_WQ_WORK_PRIORITY_LOW);
12029 return NOTIFY_DONE;
12030 }
12031 #endif /* CONFIG_IPV6 && IPV6_NDO_SUPPORT */
12032
12033 /* Network attach to be invoked from the bus probe handlers */
12034 int
dhd_attach_net(dhd_pub_t * dhdp,bool need_rtnl_lock)12035 dhd_attach_net(dhd_pub_t *dhdp, bool need_rtnl_lock)
12036 {
12037 struct net_device *primary_ndev;
12038 #ifdef GET_CUSTOM_MAC_ENABLE
12039 char hw_ether[62];
12040 #endif /* GET_CUSTOM_MAC_ENABLE */
12041 #if defined(GET_CUSTOM_MAC_ENABLE) || defined(GET_OTP_MAC_ENABLE)
12042 int ret = BCME_ERROR;
12043 #endif /* GET_CUSTOM_MAC_ENABLE || GET_OTP_MAC_ENABLE */
12044
12045 BCM_REFERENCE(primary_ndev);
12046
12047 #ifdef GET_CUSTOM_MAC_ENABLE
12048 ret = wifi_platform_get_mac_addr(dhdp->adapter, hw_ether, iface_name);
12049 if (!ret)
12050 bcopy(hw_ether, dhdp->mac.octet, ETHER_ADDR_LEN);
12051 #endif /* GET_CUSTOM_MAC_ENABLE */
12052
12053 #ifdef GET_OTP_MAC_ENABLE
12054 if (ret && memcmp(ðer_null, &dhdp->conf->otp_mac, ETHER_ADDR_LEN))
12055 bcopy(&dhdp->conf->otp_mac, &dhdp->mac, ETHER_ADDR_LEN);
12056 #endif /* GET_OTP_MAC_ENABLE */
12057
12058 /* Register primary net device */
12059 if (dhd_register_if(dhdp, 0, need_rtnl_lock) != 0) {
12060 return BCME_ERROR;
12061 }
12062
12063 #if defined(WL_CFG80211)
12064 primary_ndev = dhd_linux_get_primary_netdev(dhdp);
12065 if (wl_cfg80211_net_attach(primary_ndev) < 0) {
12066 /* fail the init */
12067 dhd_remove_if(dhdp, 0, TRUE);
12068 return BCME_ERROR;
12069 }
12070 #endif /* WL_CFG80211 */
12071 return BCME_OK;
12072 }
12073
12074 int
dhd_register_if(dhd_pub_t * dhdp,int ifidx,bool need_rtnl_lock)12075 dhd_register_if(dhd_pub_t *dhdp, int ifidx, bool need_rtnl_lock)
12076 {
12077 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
12078 dhd_if_t *ifp;
12079 struct net_device *net = NULL;
12080 int err = 0;
12081 uint8 temp_addr[ETHER_ADDR_LEN] = { 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33 };
12082 #ifdef CONFIG_AP6XXX_WIFI6_HDF
12083 struct NetDevice *hnetdev = NULL;
12084 #endif
12085
12086 DHD_TRACE(("%s: ifidx %d\n", __FUNCTION__, ifidx));
12087
12088 if (dhd == NULL || dhd->iflist[ifidx] == NULL) {
12089 DHD_ERROR(("%s: Invalid Interface\n", __FUNCTION__));
12090 return BCME_ERROR;
12091 }
12092
12093 ASSERT(dhd && dhd->iflist[ifidx]);
12094 ifp = dhd->iflist[ifidx];
12095 net = ifp->net;
12096 ASSERT(net && (ifp->idx == ifidx));
12097
12098 ASSERT(!net->netdev_ops);
12099
12100 #ifdef CONFIG_AP6XXX_WIFI6_HDF
12101 DHD_ERROR(("%s: bdh6 register netdev=%s hdfidx=%d, ifidx=%d, %p, %p\n", __FUNCTION__, net->name, g_hdf_ifidx,
12102 ifidx, net->netdev_ops, &dhd_ops_virt));
12103 #else
12104 net->netdev_ops = &dhd_ops_virt;
12105 DHD_ERROR(("%s: bdh6 register netdev=%s ifidx=%d\n", __FUNCTION__, net->name, ifidx));
12106 #endif
12107
12108 /* Ok, link into the network layer... */
12109 if (ifidx == 0) {
12110 /*
12111 * device functions for the primary interface only
12112 */
12113 #ifdef CONFIG_AP6XXX_WIFI6_HDF
12114 DHD_ERROR(("%s: for primary inf don't set ops %d\n", __FUNCTION__, g_hdf_ifidx));
12115 #else
12116 net->netdev_ops = &dhd_ops_pri;
12117 #endif
12118 if (!ETHER_ISNULLADDR(dhd->pub.mac.octet))
12119 memcpy(temp_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
12120 } else {
12121 /*
12122 * We have to use the primary MAC for virtual interfaces
12123 */
12124 memcpy(temp_addr, ifp->mac_addr, ETHER_ADDR_LEN);
12125 /*
12126 * Android sets the locally administered bit to indicate that this is a
12127 * portable hotspot. This will not work in simultaneous AP/STA mode,
12128 * nor with P2P. Need to set the Donlge's MAC address, and then use that.
12129 */
12130 if (!memcmp(temp_addr, dhd->iflist[0]->mac_addr,
12131 ETHER_ADDR_LEN)) {
12132 DHD_ERROR(("%s interface [%s]: set locally administered bit in MAC\n",
12133 __func__, net->name));
12134 temp_addr[0] |= 0x02;
12135 }
12136 }
12137
12138 net->hard_header_len = ETH_HLEN + dhd->pub.hdrlen;
12139 net->ethtool_ops = &dhd_ethtool_ops;
12140
12141 #if defined(WL_WIRELESS_EXT)
12142 #if WIRELESS_EXT < 19
12143 net->get_wireless_stats = dhd_get_wireless_stats;
12144 #endif /* WIRELESS_EXT < 19 */
12145 #if WIRELESS_EXT > 12
12146 net->wireless_handlers = &wl_iw_handler_def;
12147 #endif /* WIRELESS_EXT > 12 */
12148 #endif /* defined(WL_WIRELESS_EXT) */
12149
12150 dhd->pub.rxsz = DBUS_RX_BUFFER_SIZE_DHD(net);
12151
12152 #ifdef WLMESH
12153 if (ifidx >= 2 && dhdp->conf->fw_type == FW_TYPE_MESH) {
12154 temp_addr[4] ^= 0x80;
12155 temp_addr[4] += ifidx;
12156 temp_addr[5] += ifidx;
12157 }
12158 #endif
12159 memcpy(net->dev_addr, temp_addr, ETHER_ADDR_LEN);
12160
12161 if (ifidx == 0)
12162 printf("%s\n", dhd_version);
12163 else {
12164 #ifdef WL_EXT_IAPSTA
12165 wl_ext_iapsta_update_net_device(net, ifidx);
12166 #endif /* WL_EXT_IAPSTA */
12167 if (dhd->pub.up == 1) {
12168 if (_dhd_set_mac_address(dhd, ifidx, net->dev_addr, FALSE) == 0)
12169 DHD_INFO(("%s: MACID is overwritten\n", __FUNCTION__));
12170 else
12171 DHD_ERROR(("%s: _dhd_set_mac_address() failed\n", __FUNCTION__));
12172 }
12173 }
12174
12175 #ifdef CONFIG_AP6XXX_WIFI6_HDF
12176 DHD_ERROR(("%s: for hdf inf %d don't register netdev\n", __FUNCTION__, g_hdf_ifidx));
12177
12178 // update mac address
12179 hnetdev = GetHdfNetDeviceByLinuxInf(net);
12180 memcpy(hnetdev->macAddr, net->dev_addr, ETHER_ADDR_LEN);
12181 // Call linux register_netdev()
12182 err = NetDeviceAdd(hnetdev);
12183 DHD_ERROR(("%s:NetDeviceAdd %s ret=%d\n", __FUNCTION__, net->name, err));
12184 #else
12185 if (need_rtnl_lock)
12186 err = register_netdev(net);
12187 else
12188 err = register_netdevice(net);
12189 #endif
12190
12191 if (err != 0) {
12192 DHD_ERROR(("couldn't register the net device [%s], err %d\n", net->name, err));
12193 goto fail;
12194 }
12195 #if defined(WL_EXT_IAPSTA) || defined(USE_IW) || defined(WL_ESCAN)
12196 wl_ext_event_attach_netdev(net, ifidx, ifp->bssidx);
12197 #ifdef WL_ESCAN
12198 wl_escan_event_attach(net, dhdp);
12199 #endif /* WL_ESCAN */
12200 #ifdef WL_EXT_IAPSTA
12201 wl_ext_iapsta_attach_netdev(net, ifidx, ifp->bssidx);
12202 wl_ext_iapsta_attach_name(net, ifidx);
12203 #endif /* WL_EXT_IAPSTA */
12204 #endif /* WL_EXT_IAPSTA || USE_IW || WL_ESCAN */
12205
12206 #if defined(SOFTAP) && defined(WL_WIRELESS_EXT) && !defined(WL_CFG80211)
12207 // wl_iw_iscan_set_scan_broadcast_prep(net, 1);
12208 #endif // endif
12209
12210 #if (defined(BCMPCIE) || defined(BCMLXSDMMC) || defined(BCMDBUS))
12211 if (ifidx == 0) {
12212 #if defined(BCMLXSDMMC) && !defined(DHD_PRELOAD)
12213 up(&dhd_registration_sem);
12214 #endif /* BCMLXSDMMC */
12215 if (!dhd_download_fw_on_driverload) {
12216 #ifdef WL_CFG80211
12217 wl_terminate_event_handler(net);
12218 #endif /* WL_CFG80211 */
12219 #if defined(DHD_LB_RXP)
12220 __skb_queue_purge(&dhd->rx_pend_queue);
12221 #endif /* DHD_LB_RXP */
12222
12223 #if defined(DHD_LB_TXP)
12224 skb_queue_purge(&dhd->tx_pend_queue);
12225 #endif /* DHD_LB_TXP */
12226
12227 #ifdef SHOW_LOGTRACE
12228 /* Release the skbs from queue for WLC_E_TRACE event */
12229 dhd_event_logtrace_flush_queue(dhdp);
12230 #endif /* SHOW_LOGTRACE */
12231
12232 #if defined(BCMPCIE) && defined(DHDTCPACK_SUPPRESS)
12233 dhd_tcpack_suppress_set(dhdp, TCPACK_SUP_OFF);
12234 #endif /* BCMPCIE && DHDTCPACK_SUPPRESS */
12235 dhd_net_bus_devreset(net, TRUE);
12236 #ifdef BCMLXSDMMC
12237 dhd_net_bus_suspend(net);
12238 #endif /* BCMLXSDMMC */
12239 wifi_platform_set_power(dhdp->info->adapter, FALSE, WIFI_TURNOFF_DELAY);
12240 #if defined(BT_OVER_SDIO)
12241 dhd->bus_user_count--;
12242 #endif /* BT_OVER_SDIO */
12243 }
12244 #if defined(WL_WIRELESS_EXT)
12245 wl_iw_down(net, &dhd->pub);
12246 #endif /* defined(WL_WIRELESS_EXT) */
12247 }
12248 #endif /* OEM_ANDROID && (BCMPCIE || BCMLXSDMMC) */
12249 return 0;
12250
12251 fail:
12252 #ifndef CONFIG_AP6XXX_WIFI6_HDF
12253 net->netdev_ops = NULL;
12254 #endif
12255 return err;
12256 }
12257
12258 void
dhd_bus_detach(dhd_pub_t * dhdp)12259 dhd_bus_detach(dhd_pub_t *dhdp)
12260 {
12261 dhd_info_t *dhd;
12262
12263 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
12264
12265 if (dhdp) {
12266 dhd = (dhd_info_t *)dhdp->info;
12267 if (dhd) {
12268
12269 /*
12270 * In case of Android cfg80211 driver, the bus is down in dhd_stop,
12271 * calling stop again will cuase SD read/write errors.
12272 */
12273 if (dhd->pub.busstate != DHD_BUS_DOWN && dhd_download_fw_on_driverload) {
12274 /* Stop the protocol module */
12275 dhd_prot_stop(&dhd->pub);
12276
12277 /* Stop the bus module */
12278 #ifdef BCMDBUS
12279 /* Force Dongle terminated */
12280 if (dhd_wl_ioctl_cmd(dhdp, WLC_TERMINATED, NULL, 0, TRUE, 0) < 0)
12281 DHD_ERROR(("%s Setting WLC_TERMINATED failed\n",
12282 __FUNCTION__));
12283 dbus_stop(dhd->pub.bus);
12284 dhd->pub.busstate = DHD_BUS_DOWN;
12285 #else
12286 dhd_bus_stop(dhd->pub.bus, TRUE);
12287 #endif /* BCMDBUS */
12288 }
12289
12290 #if defined(OOB_INTR_ONLY) || defined(BCMSPI_ANDROID) || defined(BCMPCIE_OOB_HOST_WAKE)
12291 dhd_bus_oob_intr_unregister(dhdp);
12292 #endif /* OOB_INTR_ONLY || BCMSPI_ANDROID || BCMPCIE_OOB_HOST_WAKE */
12293 }
12294 }
12295 }
12296
dhd_detach(dhd_pub_t * dhdp)12297 void dhd_detach(dhd_pub_t *dhdp)
12298 {
12299 dhd_info_t *dhd;
12300 unsigned long flags;
12301 int timer_valid = FALSE;
12302 struct net_device *dev;
12303 #ifdef WL_CFG80211
12304 struct bcm_cfg80211 *cfg = NULL;
12305 #endif // endif
12306 if (!dhdp)
12307 return;
12308
12309 dhd = (dhd_info_t *)dhdp->info;
12310 if (!dhd)
12311 return;
12312
12313 dev = dhd->iflist[0]->net;
12314
12315 if (dev) {
12316 rtnl_lock();
12317 #if defined(WL_CFG80211) && defined(WL_STATIC_IF)
12318 if (dhd->dhd_state & DHD_ATTACH_STATE_CFG80211) {
12319 cfg = wl_get_cfg(dev);
12320 if (cfg && cfg->static_ndev && (cfg->static_ndev->flags & IFF_UP)) {
12321 dev_close(cfg->static_ndev);
12322 }
12323 }
12324 #endif /* WL_CFG80211 && WL_STATIC_IF */
12325 if (dev->flags & IFF_UP) {
12326 /* If IFF_UP is still up, it indicates that
12327 * "ifconfig wlan0 down" hasn't been called.
12328 * So invoke dev_close explicitly here to
12329 * bring down the interface.
12330 */
12331 DHD_TRACE(("IFF_UP flag is up. Enforcing dev_close from detach \n"));
12332 dev_close(dev);
12333 }
12334 rtnl_unlock();
12335 }
12336
12337 DHD_TRACE(("%s: Enter state 0x%x\n", __FUNCTION__, dhd->dhd_state));
12338
12339 DHD_ERROR(("%s: making dhdpub up FALSE\n", __FUNCTION__));
12340 dhd->pub.up = 0;
12341 if (!(dhd->dhd_state & DHD_ATTACH_STATE_DONE)) {
12342 /* Give sufficient time for threads to start running in case
12343 * dhd_attach() has failed
12344 */
12345 OSL_SLEEP(100);
12346 }
12347 #ifdef DHD_WET
12348 dhd_free_wet_info(&dhd->pub, dhd->pub.wet_info);
12349 #endif /* DHD_WET */
12350 #if defined(BCM_DNGL_EMBEDIMAGE) || defined(BCM_REQUEST_FW)
12351 #endif /* defined(BCM_DNGL_EMBEDIMAGE) || defined(BCM_REQUEST_FW) */
12352
12353 #ifdef PROP_TXSTATUS
12354 #ifdef DHD_WLFC_THREAD
12355 if (dhd->pub.wlfc_thread) {
12356 kthread_stop(dhd->pub.wlfc_thread);
12357 dhdp->wlfc_thread_go = TRUE;
12358 wake_up_interruptible(&dhdp->wlfc_wqhead);
12359 }
12360 dhd->pub.wlfc_thread = NULL;
12361 #endif /* DHD_WLFC_THREAD */
12362 #endif /* PROP_TXSTATUS */
12363
12364 #ifdef WL_CFG80211
12365 if (dev)
12366 wl_cfg80211_down(dev);
12367 #endif /* WL_CFG80211 */
12368
12369 if (dhd->dhd_state & DHD_ATTACH_STATE_PROT_ATTACH) {
12370
12371 dhd_bus_detach(dhdp);
12372 #ifdef BCMPCIE
12373 if (is_reboot == SYS_RESTART) {
12374 extern bcmdhd_wifi_platdata_t *dhd_wifi_platdata;
12375 if (dhd_wifi_platdata && !dhdp->dongle_reset) {
12376 dhdpcie_bus_clock_stop(dhdp->bus);
12377 wifi_platform_set_power(dhd_wifi_platdata->adapters,
12378 FALSE, WIFI_TURNOFF_DELAY);
12379 }
12380 }
12381 #endif /* BCMPCIE */
12382 #ifndef PCIE_FULL_DONGLE
12383 if (dhdp->prot)
12384 dhd_prot_detach(dhdp);
12385 #endif /* !PCIE_FULL_DONGLE */
12386 }
12387
12388 #ifdef ARP_OFFLOAD_SUPPORT
12389 if (dhd_inetaddr_notifier_registered) {
12390 dhd_inetaddr_notifier_registered = FALSE;
12391 unregister_inetaddr_notifier(&dhd_inetaddr_notifier);
12392 }
12393 #endif /* ARP_OFFLOAD_SUPPORT */
12394 #if defined(CONFIG_IPV6) && defined(IPV6_NDO_SUPPORT)
12395 if (dhd_inet6addr_notifier_registered) {
12396 dhd_inet6addr_notifier_registered = FALSE;
12397 unregister_inet6addr_notifier(&dhd_inet6addr_notifier);
12398 }
12399 #endif /* CONFIG_IPV6 && IPV6_NDO_SUPPORT */
12400 #if defined(CONFIG_HAS_EARLYSUSPEND) && defined(DHD_USE_EARLYSUSPEND)
12401 if (dhd->dhd_state & DHD_ATTACH_STATE_EARLYSUSPEND_DONE) {
12402 if (dhd->early_suspend.suspend)
12403 unregister_early_suspend(&dhd->early_suspend);
12404 }
12405 #endif /* CONFIG_HAS_EARLYSUSPEND && DHD_USE_EARLYSUSPEND */
12406
12407 #if defined(WL_WIRELESS_EXT)
12408 if (dhd->dhd_state & DHD_ATTACH_STATE_WL_ATTACH) {
12409 /* Detatch and unlink in the iw */
12410 wl_iw_detach(dev, dhdp);
12411 }
12412 #endif /* defined(WL_WIRELESS_EXT) */
12413 #ifdef WL_EXT_GENL
12414 wl_ext_genl_deinit(dev);
12415 #endif
12416 #if defined(WL_EXT_IAPSTA) || defined(USE_IW) || defined(WL_ESCAN)
12417 #ifdef WL_EXT_IAPSTA
12418 wl_ext_iapsta_dettach(dhdp);
12419 #endif /* WL_EXT_IAPSTA */
12420 #ifdef WL_ESCAN
12421 wl_escan_detach(dev, dhdp);
12422 #endif /* WL_ESCAN */
12423 wl_ext_event_dettach(dhdp);
12424 #endif /* WL_EXT_IAPSTA || USE_IW || WL_ESCAN */
12425
12426 #ifdef DHD_ULP
12427 dhd_ulp_deinit(dhd->pub.osh, dhdp);
12428 #endif /* DHD_ULP */
12429
12430 /* delete all interfaces, start with virtual */
12431 if (dhd->dhd_state & DHD_ATTACH_STATE_ADD_IF) {
12432 int i = 1;
12433 dhd_if_t *ifp;
12434
12435 /* Cleanup virtual interfaces */
12436 dhd_net_if_lock_local(dhd);
12437 for (i = 1; i < DHD_MAX_IFS; i++) {
12438 if (dhd->iflist[i]) {
12439 dhd_remove_if(&dhd->pub, i, TRUE);
12440 }
12441 }
12442 dhd_net_if_unlock_local(dhd);
12443
12444 /* delete primary interface 0 */
12445 ifp = dhd->iflist[0];
12446 if (ifp && ifp->net) {
12447
12448 #ifdef WL_CFG80211
12449 cfg = wl_get_cfg(ifp->net);
12450 #endif // endif
12451 /* in unregister_netdev case, the interface gets freed by net->destructor
12452 * (which is set to free_netdev)
12453 */
12454 if (ifp->net->reg_state == NETREG_UNINITIALIZED) {
12455 free_netdev(ifp->net);
12456 } else {
12457 #if defined(ARGOS_NOTIFY_CB)
12458 argos_register_notifier_deinit();
12459 #endif // endif
12460 #ifdef SET_RPS_CPUS
12461 custom_rps_map_clear(ifp->net->_rx);
12462 #endif /* SET_RPS_CPUS */
12463 netif_tx_disable(ifp->net);
12464 #ifdef CONFIG_AP6XXX_WIFI6_HDF
12465 IFP_NET_DESTRUCTOR = NULL;
12466 #endif
12467 unregister_netdev(ifp->net);
12468 }
12469 #ifdef PCIE_FULL_DONGLE
12470 ifp->net = DHD_NET_DEV_NULL;
12471 #else
12472 ifp->net = NULL;
12473 #endif /* PCIE_FULL_DONGLE */
12474
12475 #ifdef DHD_L2_FILTER
12476 bcm_l2_filter_arp_table_update(dhdp->osh, ifp->phnd_arp_table, TRUE,
12477 NULL, FALSE, dhdp->tickcnt);
12478 deinit_l2_filter_arp_table(dhdp->osh, ifp->phnd_arp_table);
12479 ifp->phnd_arp_table = NULL;
12480 #endif /* DHD_L2_FILTER */
12481
12482 dhd_if_del_sta_list(ifp);
12483
12484 MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
12485 dhd->iflist[0] = NULL;
12486 #ifdef WL_CFG80211
12487 if (cfg && cfg->wdev)
12488 cfg->wdev->netdev = NULL;
12489 #endif
12490 }
12491 }
12492
12493 /* Clear the watchdog timer */
12494 DHD_GENERAL_LOCK(&dhd->pub, flags);
12495 timer_valid = dhd->wd_timer_valid;
12496 dhd->wd_timer_valid = FALSE;
12497 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
12498 if (timer_valid)
12499 del_timer_sync(&dhd->timer);
12500 DHD_DISABLE_RUNTIME_PM(&dhd->pub);
12501
12502 #ifdef BCMDBUS
12503 tasklet_kill(&dhd->tasklet);
12504 #else
12505 if (dhd->dhd_state & DHD_ATTACH_STATE_THREADS_CREATED) {
12506 if (dhd->thr_wdt_ctl.thr_pid >= 0) {
12507 PROC_STOP(&dhd->thr_wdt_ctl);
12508 }
12509
12510 if (dhd->rxthread_enabled && dhd->thr_rxf_ctl.thr_pid >= 0) {
12511 PROC_STOP(&dhd->thr_rxf_ctl);
12512 }
12513
12514 if (dhd->thr_dpc_ctl.thr_pid >= 0) {
12515 PROC_STOP(&dhd->thr_dpc_ctl);
12516 } else
12517 {
12518 tasklet_kill(&dhd->tasklet);
12519 }
12520 }
12521 #endif /* BCMDBUS */
12522
12523 #ifdef WL_NATOE
12524 if (dhd->pub.nfct) {
12525 dhd_ct_close(dhd->pub.nfct);
12526 }
12527 #endif /* WL_NATOE */
12528
12529 #ifdef DHD_LB
12530 if (dhd->dhd_state & DHD_ATTACH_STATE_LB_ATTACH_DONE) {
12531 /* Clear the flag first to avoid calling the cpu notifier */
12532 dhd->dhd_state &= ~DHD_ATTACH_STATE_LB_ATTACH_DONE;
12533
12534 /* Kill the Load Balancing Tasklets */
12535 #ifdef DHD_LB_RXP
12536 cancel_work_sync(&dhd->rx_napi_dispatcher_work);
12537 __skb_queue_purge(&dhd->rx_pend_queue);
12538 #endif /* DHD_LB_RXP */
12539 #ifdef DHD_LB_TXP
12540 cancel_work_sync(&dhd->tx_dispatcher_work);
12541 tasklet_kill(&dhd->tx_tasklet);
12542 __skb_queue_purge(&dhd->tx_pend_queue);
12543 #endif /* DHD_LB_TXP */
12544 #ifdef DHD_LB_TXC
12545 cancel_work_sync(&dhd->tx_compl_dispatcher_work);
12546 tasklet_kill(&dhd->tx_compl_tasklet);
12547 #endif /* DHD_LB_TXC */
12548 #ifdef DHD_LB_RXC
12549 tasklet_kill(&dhd->rx_compl_tasklet);
12550 #endif /* DHD_LB_RXC */
12551
12552 /* Unregister from CPU Hotplug framework */
12553 dhd_unregister_cpuhp_callback(dhd);
12554
12555 dhd_cpumasks_deinit(dhd);
12556 DHD_LB_STATS_DEINIT(&dhd->pub);
12557 }
12558 #endif /* DHD_LB */
12559
12560 #ifdef CSI_SUPPORT
12561 dhd_csi_deinit(dhdp);
12562 #endif /* CSI_SUPPORT */
12563
12564 #if defined(DNGL_AXI_ERROR_LOGGING) && defined(DHD_USE_WQ_FOR_DNGL_AXI_ERROR)
12565 cancel_work_sync(&dhd->axi_error_dispatcher_work);
12566 #endif /* DNGL_AXI_ERROR_LOGGING && DHD_USE_WQ_FOR_DNGL_AXI_ERROR */
12567
12568 DHD_SSSR_MEMPOOL_DEINIT(&dhd->pub);
12569
12570 #ifdef WL_CFG80211
12571 if (dhd->dhd_state & DHD_ATTACH_STATE_CFG80211) {
12572 if (!cfg) {
12573 DHD_ERROR(("cfg NULL!\n"));
12574 ASSERT(0);
12575 } else {
12576 wl_cfg80211_detach(cfg);
12577 dhd_monitor_uninit();
12578 }
12579 }
12580 #endif // endif
12581
12582 #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
12583 destroy_workqueue(dhd->tx_wq);
12584 dhd->tx_wq = NULL;
12585 destroy_workqueue(dhd->rx_wq);
12586 dhd->rx_wq = NULL;
12587 #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
12588 #ifdef DEBUGABILITY
12589 if (dhdp->dbg) {
12590 #ifdef DBG_PKT_MON
12591 dhd_os_dbg_detach_pkt_monitor(dhdp);
12592 dhd_os_spin_lock_deinit(dhd->pub.osh, dhd->pub.dbg->pkt_mon_lock);
12593 #endif /* DBG_PKT_MON */
12594 }
12595 #endif /* DEBUGABILITY */
12596 if (dhdp->dbg) {
12597 dhd_os_dbg_detach(dhdp);
12598 }
12599 #ifdef DHD_STATUS_LOGGING
12600 dhd_detach_statlog(dhdp);
12601 #endif /* DHD_STATUS_LOGGING */
12602 #ifdef DHD_PKTDUMP_ROAM
12603 dhd_dump_pkt_deinit(dhdp);
12604 #endif /* DHD_PKTDUMP_ROAM */
12605 #ifdef SHOW_LOGTRACE
12606 /* Release the skbs from queue for WLC_E_TRACE event */
12607 dhd_event_logtrace_flush_queue(dhdp);
12608
12609 /* Wait till event logtrace context finishes */
12610 dhd_cancel_logtrace_process_sync(dhd);
12611
12612 /* Remove ring proc entries */
12613 dhd_dbg_ring_proc_destroy(&dhd->pub);
12614
12615 if (dhd->dhd_state & DHD_ATTACH_LOGTRACE_INIT) {
12616 if (dhd->event_data.fmts) {
12617 MFREE(dhd->pub.osh, dhd->event_data.fmts,
12618 dhd->event_data.fmts_size);
12619 dhd->event_data.fmts = NULL;
12620 }
12621 if (dhd->event_data.raw_fmts) {
12622 MFREE(dhd->pub.osh, dhd->event_data.raw_fmts,
12623 dhd->event_data.raw_fmts_size);
12624 dhd->event_data.raw_fmts = NULL;
12625 }
12626 if (dhd->event_data.raw_sstr) {
12627 MFREE(dhd->pub.osh, dhd->event_data.raw_sstr,
12628 dhd->event_data.raw_sstr_size);
12629 dhd->event_data.raw_sstr = NULL;
12630 }
12631 if (dhd->event_data.rom_raw_sstr) {
12632 MFREE(dhd->pub.osh, dhd->event_data.rom_raw_sstr,
12633 dhd->event_data.rom_raw_sstr_size);
12634 dhd->event_data.rom_raw_sstr = NULL;
12635 }
12636 dhd->dhd_state &= ~DHD_ATTACH_LOGTRACE_INIT;
12637 }
12638 #endif /* SHOW_LOGTRACE */
12639 #ifdef PNO_SUPPORT
12640 if (dhdp->pno_state)
12641 dhd_pno_deinit(dhdp);
12642 #endif // endif
12643 #ifdef RTT_SUPPORT
12644 if (dhdp->rtt_state) {
12645 dhd_rtt_deinit(dhdp);
12646 }
12647 #endif // endif
12648 #if defined(CONFIG_PM_SLEEP)
12649 if (dhd_pm_notifier_registered) {
12650 unregister_pm_notifier(&dhd->pm_notifier);
12651 dhd_pm_notifier_registered = FALSE;
12652 }
12653 #endif /* CONFIG_PM_SLEEP */
12654
12655 #ifdef DEBUG_CPU_FREQ
12656 if (dhd->new_freq)
12657 free_percpu(dhd->new_freq);
12658 dhd->new_freq = NULL;
12659 cpufreq_unregister_notifier(&dhd->freq_trans, CPUFREQ_TRANSITION_NOTIFIER);
12660 #endif // endif
12661 DHD_TRACE(("wd wakelock count:%d\n", dhd->wakelock_wd_counter));
12662 #ifdef CONFIG_HAS_WAKELOCK
12663 dhd->wakelock_wd_counter = 0;
12664 wake_lock_destroy(&dhd->wl_wdwake);
12665 // terence 20161023: can not destroy wl_wifi when wlan down, it will happen null pointer in dhd_ioctl_entry
12666 wake_lock_destroy(&dhd->wl_wifi);
12667 #endif /* CONFIG_HAS_WAKELOCK */
12668 if (dhd->dhd_state & DHD_ATTACH_STATE_WAKELOCKS_INIT) {
12669 DHD_OS_WAKE_LOCK_DESTROY(dhd);
12670 }
12671
12672 #ifdef DHDTCPACK_SUPPRESS
12673 /* This will free all MEM allocated for TCPACK SUPPRESS */
12674 dhd_tcpack_suppress_set(&dhd->pub, TCPACK_SUP_OFF);
12675 #endif /* DHDTCPACK_SUPPRESS */
12676
12677 #ifdef PCIE_FULL_DONGLE
12678 dhd_flow_rings_deinit(dhdp);
12679 if (dhdp->prot)
12680 dhd_prot_detach(dhdp);
12681 #endif // endif
12682
12683 #if defined(WLTDLS) && defined(PCIE_FULL_DONGLE)
12684 dhd_free_tdls_peer_list(dhdp);
12685 #endif // endif
12686
12687 #ifdef DUMP_IOCTL_IOV_LIST
12688 dhd_iov_li_delete(dhdp, &(dhdp->dump_iovlist_head));
12689 #endif /* DUMP_IOCTL_IOV_LIST */
12690 #ifdef DHD_DEBUG
12691 /* memory waste feature list initilization */
12692 dhd_mw_list_delete(dhdp, &(dhdp->mw_list_head));
12693 #endif /* DHD_DEBUG */
12694 #ifdef WL_MONITOR
12695 dhd_del_monitor_if(dhd);
12696 #endif /* WL_MONITOR */
12697
12698 #ifdef DHD_ERPOM
12699 if (dhdp->enable_erpom) {
12700 dhdp->pom_func_deregister(&dhdp->pom_wlan_handler);
12701 }
12702 #endif /* DHD_ERPOM */
12703
12704 cancel_work_sync(&dhd->dhd_hang_process_work);
12705
12706 /* Prefer adding de-init code above this comment unless necessary.
12707 * The idea is to cancel work queue, sysfs and flags at the end.
12708 */
12709 dhd_deferred_work_deinit(dhd->dhd_deferred_wq);
12710 dhd->dhd_deferred_wq = NULL;
12711
12712 /* log dump related buffers should be freed after wq is purged */
12713 #ifdef DHD_LOG_DUMP
12714 dhd_log_dump_deinit(&dhd->pub);
12715 #endif /* DHD_LOG_DUMP */
12716 #if defined(BCMPCIE)
12717 if (dhdp->extended_trap_data)
12718 {
12719 MFREE(dhdp->osh, dhdp->extended_trap_data, BCMPCIE_EXT_TRAP_DATA_MAXLEN);
12720 dhdp->extended_trap_data = NULL;
12721 }
12722 #ifdef DNGL_AXI_ERROR_LOGGING
12723 if (dhdp->axi_err_dump)
12724 {
12725 MFREE(dhdp->osh, dhdp->axi_err_dump, sizeof(dhd_axi_error_dump_t));
12726 dhdp->axi_err_dump = NULL;
12727 }
12728 #endif /* DNGL_AXI_ERROR_LOGGING */
12729 #endif /* BCMPCIE */
12730
12731 #ifdef DHD_DUMP_MNGR
12732 if (dhd->pub.dump_file_manage) {
12733 MFREE(dhd->pub.osh, dhd->pub.dump_file_manage,
12734 sizeof(dhd_dump_file_manage_t));
12735 }
12736 #endif /* DHD_DUMP_MNGR */
12737 dhd_sysfs_exit(dhd);
12738 dhd->pub.fw_download_status = FW_UNLOADED;
12739
12740 #if defined(BT_OVER_SDIO)
12741 mutex_destroy(&dhd->bus_user_lock);
12742 #endif /* BT_OVER_SDIO */
12743 dhd_conf_detach(dhdp);
12744
12745 } /* dhd_detach */
12746
12747 void
dhd_free(dhd_pub_t * dhdp)12748 dhd_free(dhd_pub_t *dhdp)
12749 {
12750 dhd_info_t *dhd;
12751 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
12752
12753 if (dhdp) {
12754 int i;
12755 for (i = 0; i < ARRAYSIZE(dhdp->reorder_bufs); i++) {
12756 if (dhdp->reorder_bufs[i]) {
12757 reorder_info_t *ptr;
12758 uint32 buf_size = sizeof(struct reorder_info);
12759
12760 ptr = dhdp->reorder_bufs[i];
12761
12762 buf_size += ((ptr->max_idx + 1) * sizeof(void*));
12763 DHD_REORDER(("free flow id buf %d, maxidx is %d, buf_size %d\n",
12764 i, ptr->max_idx, buf_size));
12765
12766 MFREE(dhdp->osh, dhdp->reorder_bufs[i], buf_size);
12767 dhdp->reorder_bufs[i] = NULL;
12768 }
12769 }
12770
12771 dhd_sta_pool_fini(dhdp, DHD_MAX_STA);
12772
12773 dhd = (dhd_info_t *)dhdp->info;
12774 if (dhdp->soc_ram) {
12775 #if defined(CONFIG_DHD_USE_STATIC_BUF) && defined(DHD_USE_STATIC_MEMDUMP)
12776 DHD_OS_PREFREE(dhdp, dhdp->soc_ram, dhdp->soc_ram_length);
12777 #else
12778 MFREE(dhdp->osh, dhdp->soc_ram, dhdp->soc_ram_length);
12779 #endif /* CONFIG_DHD_USE_STATIC_BUF && DHD_USE_STATIC_MEMDUMP */
12780 dhdp->soc_ram = NULL;
12781 }
12782 if (dhd != NULL) {
12783
12784 /* If pointer is allocated by dhd_os_prealloc then avoid MFREE */
12785 if (dhd != (dhd_info_t *)dhd_os_prealloc(dhdp,
12786 DHD_PREALLOC_DHD_INFO, 0, FALSE))
12787 MFREE(dhd->pub.osh, dhd, sizeof(*dhd));
12788 dhd = NULL;
12789 }
12790 }
12791 }
12792
12793 void
dhd_clear(dhd_pub_t * dhdp)12794 dhd_clear(dhd_pub_t *dhdp)
12795 {
12796 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
12797
12798 if (dhdp) {
12799 int i;
12800 #ifdef DHDTCPACK_SUPPRESS
12801 /* Clean up timer/data structure for any remaining/pending packet or timer. */
12802 dhd_tcpack_info_tbl_clean(dhdp);
12803 #endif /* DHDTCPACK_SUPPRESS */
12804 for (i = 0; i < ARRAYSIZE(dhdp->reorder_bufs); i++) {
12805 if (dhdp->reorder_bufs[i]) {
12806 reorder_info_t *ptr;
12807 uint32 buf_size = sizeof(struct reorder_info);
12808
12809 ptr = dhdp->reorder_bufs[i];
12810
12811 buf_size += ((ptr->max_idx + 1) * sizeof(void*));
12812 DHD_REORDER(("free flow id buf %d, maxidx is %d, buf_size %d\n",
12813 i, ptr->max_idx, buf_size));
12814
12815 MFREE(dhdp->osh, dhdp->reorder_bufs[i], buf_size);
12816 dhdp->reorder_bufs[i] = NULL;
12817 }
12818 }
12819
12820 dhd_sta_pool_clear(dhdp, DHD_MAX_STA);
12821
12822 if (dhdp->soc_ram) {
12823 #if defined(CONFIG_DHD_USE_STATIC_BUF) && defined(DHD_USE_STATIC_MEMDUMP)
12824 DHD_OS_PREFREE(dhdp, dhdp->soc_ram, dhdp->soc_ram_length);
12825 #else
12826 MFREE(dhdp->osh, dhdp->soc_ram, dhdp->soc_ram_length);
12827 #endif /* CONFIG_DHD_USE_STATIC_BUF && DHD_USE_STATIC_MEMDUMP */
12828 dhdp->soc_ram = NULL;
12829 }
12830 }
12831 }
12832
12833 static void
dhd_module_cleanup(void)12834 dhd_module_cleanup(void)
12835 {
12836 printf("%s: Enter\n", __FUNCTION__);
12837
12838 dhd_bus_unregister();
12839
12840 wl_android_exit();
12841
12842 dhd_wifi_platform_unregister_drv();
12843 printf("%s: Exit\n", __FUNCTION__);
12844 }
12845
12846 #ifdef CONFIG_AP6XXX_WIFI6_HDF
12847 void
12848 #else
12849 static void __exit
12850 #endif
dhd_module_exit(void)12851 dhd_module_exit(void)
12852 {
12853 atomic_set(&exit_in_progress, 1);
12854 dhd_module_cleanup();
12855 unregister_reboot_notifier(&dhd_reboot_notifier);
12856 dhd_destroy_to_notifier_skt();
12857 }
12858
12859 #ifdef CONFIG_AP6XXX_WIFI6_HDF
12860 int
12861 #else
12862 static int __init
12863 #endif
dhd_module_init(void)12864 dhd_module_init(void)
12865 {
12866 int err;
12867 int retry = POWERUP_MAX_RETRY;
12868
12869 printf("%s: in %s\n", __FUNCTION__, dhd_version);
12870
12871 DHD_PERIM_RADIO_INIT();
12872
12873 if (firmware_path[0] != '\0') {
12874 strncpy(fw_bak_path, firmware_path, MOD_PARAM_PATHLEN);
12875 fw_bak_path[MOD_PARAM_PATHLEN-1] = '\0';
12876 }
12877
12878 if (nvram_path[0] != '\0') {
12879 strncpy(nv_bak_path, nvram_path, MOD_PARAM_PATHLEN);
12880 nv_bak_path[MOD_PARAM_PATHLEN-1] = '\0';
12881 }
12882
12883 do {
12884 err = dhd_wifi_platform_register_drv();
12885 if (!err) {
12886 register_reboot_notifier(&dhd_reboot_notifier);
12887 break;
12888 } else {
12889 DHD_ERROR(("%s: Failed to load the driver, try cnt %d\n",
12890 __FUNCTION__, retry));
12891 strncpy(firmware_path, fw_bak_path, MOD_PARAM_PATHLEN);
12892 firmware_path[MOD_PARAM_PATHLEN-1] = '\0';
12893 strncpy(nvram_path, nv_bak_path, MOD_PARAM_PATHLEN);
12894 nvram_path[MOD_PARAM_PATHLEN-1] = '\0';
12895 }
12896 } while (retry--);
12897
12898 dhd_create_to_notifier_skt();
12899
12900 if (err) {
12901 DHD_ERROR(("%s: Failed to load driver max retry reached**\n", __FUNCTION__));
12902 } else {
12903 if (!dhd_download_fw_on_driverload) {
12904 dhd_driver_init_done = TRUE;
12905 }
12906 }
12907
12908 printf("%s: Exit err=%d\n", __FUNCTION__, err);
12909 return err;
12910 }
12911
12912 static int
dhd_reboot_callback(struct notifier_block * this,unsigned long code,void * unused)12913 dhd_reboot_callback(struct notifier_block *this, unsigned long code, void *unused)
12914 {
12915 DHD_TRACE(("%s: code = %ld\n", __FUNCTION__, code));
12916 if (code == SYS_RESTART) {
12917 #ifdef BCMPCIE
12918 is_reboot = code;
12919 #endif /* BCMPCIE */
12920 }
12921 return NOTIFY_DONE;
12922 }
12923
12924 #ifndef CONFIG_AP6XXX_WIFI6_HDF
12925 #if defined(CONFIG_DEFERRED_INITCALLS) && !defined(EXYNOS_PCIE_MODULE_PATCH)
12926 #if defined(CONFIG_MACH_UNIVERSAL7420) || defined(CONFIG_SOC_EXYNOS8890) || \
12927 defined(CONFIG_ARCH_MSM8996) || defined(CONFIG_ARCH_MSM8998) || \
12928 defined(CONFIG_SOC_EXYNOS8895) || defined(CONFIG_SOC_EXYNOS9810) || \
12929 defined(CONFIG_ARCH_SDM845) || defined(CONFIG_SOC_EXYNOS9820) || \
12930 defined(CONFIG_ARCH_SM8150)
12931 deferred_module_init_sync(dhd_module_init);
12932 #else
12933 deferred_module_init(dhd_module_init);
12934 #endif /* CONFIG_MACH_UNIVERSAL7420 || CONFIG_SOC_EXYNOS8890 ||
12935 * CONFIG_ARCH_MSM8996 || CONFIG_ARCH_MSM8998 || CONFIG_SOC_EXYNOS8895
12936 * CONFIG_SOC_EXYNOS9810 || CONFIG_ARCH_SDM845 || CONFIG_SOC_EXYNOS9820
12937 * CONFIG_ARCH_SM8150
12938 */
12939 #elif defined(USE_LATE_INITCALL_SYNC)
12940 late_initcall_sync(dhd_module_init);
12941 #else
12942 late_initcall(dhd_module_init);
12943 #endif /* USE_LATE_INITCALL_SYNC */
12944
12945 module_exit(dhd_module_exit);
12946 #endif
12947
12948 /*
12949 * OS specific functions required to implement DHD driver in OS independent way
12950 */
12951 int
dhd_os_proto_block(dhd_pub_t * pub)12952 dhd_os_proto_block(dhd_pub_t *pub)
12953 {
12954 dhd_info_t * dhd = (dhd_info_t *)(pub->info);
12955
12956 if (dhd) {
12957 DHD_PERIM_UNLOCK(pub);
12958
12959 down(&dhd->proto_sem);
12960
12961 DHD_PERIM_LOCK(pub);
12962 return 1;
12963 }
12964
12965 return 0;
12966 }
12967
12968 int
dhd_os_proto_unblock(dhd_pub_t * pub)12969 dhd_os_proto_unblock(dhd_pub_t *pub)
12970 {
12971 dhd_info_t * dhd = (dhd_info_t *)(pub->info);
12972
12973 if (dhd) {
12974 up(&dhd->proto_sem);
12975 return 1;
12976 }
12977
12978 return 0;
12979 }
12980
12981 void
dhd_os_dhdiovar_lock(dhd_pub_t * pub)12982 dhd_os_dhdiovar_lock(dhd_pub_t *pub)
12983 {
12984 dhd_info_t * dhd = (dhd_info_t *)(pub->info);
12985
12986 if (dhd) {
12987 mutex_lock(&dhd->dhd_iovar_mutex);
12988 }
12989 }
12990
12991 void
dhd_os_dhdiovar_unlock(dhd_pub_t * pub)12992 dhd_os_dhdiovar_unlock(dhd_pub_t *pub)
12993 {
12994 dhd_info_t * dhd = (dhd_info_t *)(pub->info);
12995
12996 if (dhd) {
12997 mutex_unlock(&dhd->dhd_iovar_mutex);
12998 }
12999 }
13000
13001 void
dhd_os_logdump_lock(dhd_pub_t * pub)13002 dhd_os_logdump_lock(dhd_pub_t *pub)
13003 {
13004 dhd_info_t *dhd = NULL;
13005
13006 if (!pub)
13007 return;
13008
13009 dhd = (dhd_info_t *)(pub->info);
13010
13011 if (dhd) {
13012 mutex_lock(&dhd->logdump_lock);
13013 }
13014 }
13015
13016 void
dhd_os_logdump_unlock(dhd_pub_t * pub)13017 dhd_os_logdump_unlock(dhd_pub_t *pub)
13018 {
13019 dhd_info_t *dhd = NULL;
13020
13021 if (!pub)
13022 return;
13023
13024 dhd = (dhd_info_t *)(pub->info);
13025
13026 if (dhd) {
13027 mutex_unlock(&dhd->logdump_lock);
13028 }
13029 }
13030
13031 unsigned long
dhd_os_dbgring_lock(void * lock)13032 dhd_os_dbgring_lock(void *lock)
13033 {
13034 if (!lock)
13035 return 0;
13036
13037 mutex_lock((struct mutex *)lock);
13038
13039 return 0;
13040 }
13041
13042 void
dhd_os_dbgring_unlock(void * lock,unsigned long flags)13043 dhd_os_dbgring_unlock(void *lock, unsigned long flags)
13044 {
13045 BCM_REFERENCE(flags);
13046
13047 if (!lock)
13048 return;
13049
13050 mutex_unlock((struct mutex *)lock);
13051 }
13052
13053 unsigned int
dhd_os_get_ioctl_resp_timeout(void)13054 dhd_os_get_ioctl_resp_timeout(void)
13055 {
13056 return ((unsigned int)dhd_ioctl_timeout_msec);
13057 }
13058
13059 void
dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec)13060 dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec)
13061 {
13062 dhd_ioctl_timeout_msec = (int)timeout_msec;
13063 }
13064
13065 int
dhd_os_ioctl_resp_wait(dhd_pub_t * pub,uint * condition)13066 dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition)
13067 {
13068 dhd_info_t * dhd = (dhd_info_t *)(pub->info);
13069 int timeout;
13070
13071 /* Convert timeout in millsecond to jiffies */
13072 timeout = msecs_to_jiffies(dhd_ioctl_timeout_msec);
13073
13074 DHD_PERIM_UNLOCK(pub);
13075
13076 timeout = wait_event_timeout(dhd->ioctl_resp_wait, (*condition), timeout);
13077
13078 DHD_PERIM_LOCK(pub);
13079
13080 return timeout;
13081 }
13082
13083 int
dhd_os_ioctl_resp_wake(dhd_pub_t * pub)13084 dhd_os_ioctl_resp_wake(dhd_pub_t *pub)
13085 {
13086 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
13087
13088 wake_up(&dhd->ioctl_resp_wait);
13089 return 0;
13090 }
13091
13092 int
dhd_os_d3ack_wait(dhd_pub_t * pub,uint * condition)13093 dhd_os_d3ack_wait(dhd_pub_t *pub, uint *condition)
13094 {
13095 dhd_info_t * dhd = (dhd_info_t *)(pub->info);
13096 int timeout;
13097
13098 /* Convert timeout in millsecond to jiffies */
13099 timeout = msecs_to_jiffies(D3_ACK_RESP_TIMEOUT);
13100
13101 DHD_PERIM_UNLOCK(pub);
13102
13103 timeout = wait_event_timeout(dhd->d3ack_wait, (*condition), timeout);
13104
13105 DHD_PERIM_LOCK(pub);
13106
13107 return timeout;
13108 }
13109
13110 int
dhd_os_d3ack_wake(dhd_pub_t * pub)13111 dhd_os_d3ack_wake(dhd_pub_t *pub)
13112 {
13113 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
13114
13115 wake_up(&dhd->d3ack_wait);
13116 return 0;
13117 }
13118
13119 int
dhd_os_busbusy_wait_negation(dhd_pub_t * pub,uint * condition)13120 dhd_os_busbusy_wait_negation(dhd_pub_t *pub, uint *condition)
13121 {
13122 dhd_info_t * dhd = (dhd_info_t *)(pub->info);
13123 int timeout;
13124
13125 /* Wait for bus usage contexts to gracefully exit within some timeout value
13126 * Set time out to little higher than dhd_ioctl_timeout_msec,
13127 * so that IOCTL timeout should not get affected.
13128 */
13129 /* Convert timeout in millsecond to jiffies */
13130 timeout = msecs_to_jiffies(DHD_BUS_BUSY_TIMEOUT);
13131
13132 timeout = wait_event_timeout(dhd->dhd_bus_busy_state_wait, !(*condition), timeout);
13133
13134 return timeout;
13135 }
13136
13137 /*
13138 * Wait until the condition *var == condition is met.
13139 * Returns 0 if the @condition evaluated to false after the timeout elapsed
13140 * Returns 1 if the @condition evaluated to true
13141 */
13142 int
dhd_os_busbusy_wait_condition(dhd_pub_t * pub,uint * var,uint condition)13143 dhd_os_busbusy_wait_condition(dhd_pub_t *pub, uint *var, uint condition)
13144 {
13145 dhd_info_t * dhd = (dhd_info_t *)(pub->info);
13146 int timeout;
13147
13148 /* Convert timeout in millsecond to jiffies */
13149 timeout = msecs_to_jiffies(DHD_BUS_BUSY_TIMEOUT);
13150
13151 timeout = wait_event_timeout(dhd->dhd_bus_busy_state_wait, (*var == condition), timeout);
13152
13153 return timeout;
13154 }
13155
13156 /*
13157 * Wait until the '(*var & bitmask) == condition' is met.
13158 * Returns 0 if the @condition evaluated to false after the timeout elapsed
13159 * Returns 1 if the @condition evaluated to true
13160 */
13161 int
dhd_os_busbusy_wait_bitmask(dhd_pub_t * pub,uint * var,uint bitmask,uint condition)13162 dhd_os_busbusy_wait_bitmask(dhd_pub_t *pub, uint *var,
13163 uint bitmask, uint condition)
13164 {
13165 dhd_info_t * dhd = (dhd_info_t *)(pub->info);
13166 int timeout;
13167
13168 /* Convert timeout in millsecond to jiffies */
13169 timeout = msecs_to_jiffies(DHD_BUS_BUSY_TIMEOUT);
13170
13171 timeout = wait_event_timeout(dhd->dhd_bus_busy_state_wait,
13172 ((*var & bitmask) == condition), timeout);
13173
13174 return timeout;
13175 }
13176
13177 int
dhd_os_dmaxfer_wait(dhd_pub_t * pub,uint * condition)13178 dhd_os_dmaxfer_wait(dhd_pub_t *pub, uint *condition)
13179 {
13180 int ret = 0;
13181 dhd_info_t * dhd = (dhd_info_t *)(pub->info);
13182 int timeout;
13183
13184 timeout = msecs_to_jiffies(IOCTL_DMAXFER_TIMEOUT);
13185
13186 DHD_PERIM_UNLOCK(pub);
13187 ret = wait_event_timeout(dhd->dmaxfer_wait, (*condition), timeout);
13188 DHD_PERIM_LOCK(pub);
13189
13190 return ret;
13191
13192 }
13193
13194 int
dhd_os_dmaxfer_wake(dhd_pub_t * pub)13195 dhd_os_dmaxfer_wake(dhd_pub_t *pub)
13196 {
13197 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
13198
13199 wake_up(&dhd->dmaxfer_wait);
13200 return 0;
13201 }
13202
13203 void
dhd_os_tx_completion_wake(dhd_pub_t * dhd)13204 dhd_os_tx_completion_wake(dhd_pub_t *dhd)
13205 {
13206 /* Call wmb() to make sure before waking up the other event value gets updated */
13207 OSL_SMP_WMB();
13208 wake_up(&dhd->tx_completion_wait);
13209 }
13210
13211 /* Fix compilation error for FC11 */
13212 INLINE int
dhd_os_busbusy_wake(dhd_pub_t * pub)13213 dhd_os_busbusy_wake(dhd_pub_t *pub)
13214 {
13215 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
13216 /* Call wmb() to make sure before waking up the other event value gets updated */
13217 OSL_SMP_WMB();
13218 wake_up(&dhd->dhd_bus_busy_state_wait);
13219 return 0;
13220 }
13221
13222 void
dhd_os_wd_timer_extend(void * bus,bool extend)13223 dhd_os_wd_timer_extend(void *bus, bool extend)
13224 {
13225 #ifndef BCMDBUS
13226 dhd_pub_t *pub = bus;
13227 dhd_info_t *dhd = (dhd_info_t *)pub->info;
13228
13229 if (extend)
13230 dhd_os_wd_timer(bus, WATCHDOG_EXTEND_INTERVAL);
13231 else
13232 dhd_os_wd_timer(bus, dhd->default_wd_interval);
13233 #endif /* !BCMDBUS */
13234 }
13235
13236 void
dhd_os_wd_timer(void * bus,uint wdtick)13237 dhd_os_wd_timer(void *bus, uint wdtick)
13238 {
13239 #ifndef BCMDBUS
13240 dhd_pub_t *pub = bus;
13241 dhd_info_t *dhd = (dhd_info_t *)pub->info;
13242 unsigned long flags;
13243
13244 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
13245
13246 if (!dhd) {
13247 DHD_ERROR(("%s: dhd NULL\n", __FUNCTION__));
13248 return;
13249 }
13250
13251 DHD_GENERAL_LOCK(pub, flags);
13252
13253 /* don't start the wd until fw is loaded */
13254 if (pub->busstate == DHD_BUS_DOWN) {
13255 DHD_GENERAL_UNLOCK(pub, flags);
13256 #ifdef BCMSDIO
13257 if (!wdtick) {
13258 DHD_OS_WD_WAKE_UNLOCK(pub);
13259 }
13260 #endif /* BCMSDIO */
13261 return;
13262 }
13263
13264 /* Totally stop the timer */
13265 if (!wdtick && dhd->wd_timer_valid == TRUE) {
13266 dhd->wd_timer_valid = FALSE;
13267 DHD_GENERAL_UNLOCK(pub, flags);
13268 del_timer_sync(&dhd->timer);
13269 #ifdef BCMSDIO
13270 DHD_OS_WD_WAKE_UNLOCK(pub);
13271 #endif /* BCMSDIO */
13272 return;
13273 }
13274
13275 if (wdtick) {
13276 #ifdef BCMSDIO
13277 DHD_OS_WD_WAKE_LOCK(pub);
13278 dhd_watchdog_ms = (uint)wdtick;
13279 #endif /* BCMSDIO */
13280 /* Re arm the timer, at last watchdog period */
13281 mod_timer(&dhd->timer, jiffies + msecs_to_jiffies(dhd_watchdog_ms));
13282 dhd->wd_timer_valid = TRUE;
13283 }
13284 DHD_GENERAL_UNLOCK(pub, flags);
13285 #endif /* !BCMDBUS */
13286 }
13287
13288 void *
dhd_os_open_image1(dhd_pub_t * pub,char * filename)13289 dhd_os_open_image1(dhd_pub_t *pub, char *filename)
13290 {
13291 struct file *fp;
13292 int size;
13293
13294 fp = filp_open(filename, O_RDONLY, 0);
13295 /*
13296 * 2.6.11 (FC4) supports filp_open() but later revs don't?
13297 * Alternative:
13298 * fp = open_namei(AT_FDCWD, filename, O_RD, 0);
13299 * ???
13300 */
13301 if (IS_ERR(fp)) {
13302 fp = NULL;
13303 goto err;
13304 }
13305
13306 if (!S_ISREG(file_inode(fp)->i_mode)) {
13307 DHD_ERROR(("%s: %s is not regular file\n", __FUNCTION__, filename));
13308 fp = NULL;
13309 goto err;
13310 }
13311
13312 size = i_size_read(file_inode(fp));
13313 if (size <= 0) {
13314 DHD_ERROR(("%s: %s file size invalid %d\n", __FUNCTION__, filename, size));
13315 fp = NULL;
13316 goto err;
13317 }
13318
13319 DHD_ERROR(("%s: %s (%d bytes) open success\n", __FUNCTION__, filename, size));
13320
13321 err:
13322 return fp;
13323 }
13324
13325 int
dhd_os_get_image_block(char * buf,int len,void * image)13326 dhd_os_get_image_block(char *buf, int len, void *image)
13327 {
13328 struct file *fp = (struct file *)image;
13329 int rdlen;
13330 int size;
13331
13332 if (!image) {
13333 return 0;
13334 }
13335
13336 size = i_size_read(file_inode(fp));
13337 rdlen = compat_kernel_read(fp, fp->f_pos, buf, MIN(len, size));
13338
13339 if (len >= size && size != rdlen) {
13340 return -EIO;
13341 }
13342
13343 if (rdlen > 0) {
13344 fp->f_pos += rdlen;
13345 }
13346
13347 return rdlen;
13348 }
13349
13350 #if defined(BT_OVER_SDIO)
13351 int
dhd_os_gets_image(dhd_pub_t * pub,char * str,int len,void * image)13352 dhd_os_gets_image(dhd_pub_t *pub, char *str, int len, void *image)
13353 {
13354 struct file *fp = (struct file *)image;
13355 int rd_len;
13356 uint str_len = 0;
13357 char *str_end = NULL;
13358
13359 if (!image)
13360 return 0;
13361
13362 rd_len = compat_kernel_read(fp, fp->f_pos, str, len);
13363 str_end = strnchr(str, len, '\n');
13364 if (str_end == NULL) {
13365 goto err;
13366 }
13367 str_len = (uint)(str_end - str);
13368
13369 /* Advance file pointer past the string length */
13370 fp->f_pos += str_len + 1;
13371 bzero(str_end, rd_len - str_len);
13372
13373 err:
13374 return str_len;
13375 }
13376 #endif /* defined (BT_OVER_SDIO) */
13377
13378 int
dhd_os_get_image_size(void * image)13379 dhd_os_get_image_size(void *image)
13380 {
13381 struct file *fp = (struct file *)image;
13382 int size;
13383 if (!image) {
13384 return 0;
13385 }
13386
13387 size = i_size_read(file_inode(fp));
13388
13389 return size;
13390 }
13391
13392 void
dhd_os_close_image1(dhd_pub_t * pub,void * image)13393 dhd_os_close_image1(dhd_pub_t *pub, void *image)
13394 {
13395 if (image) {
13396 filp_close((struct file *)image, NULL);
13397 }
13398 }
13399
13400 void
dhd_os_sdlock(dhd_pub_t * pub)13401 dhd_os_sdlock(dhd_pub_t *pub)
13402 {
13403 dhd_info_t *dhd;
13404
13405 dhd = (dhd_info_t *)(pub->info);
13406
13407 #ifdef BCMDBUS
13408 spin_lock_bh(&dhd->sdlock);
13409 #else
13410 if (dhd_dpc_prio >= 0)
13411 down(&dhd->sdsem);
13412 else
13413 spin_lock_bh(&dhd->sdlock);
13414 #endif /* !BCMDBUS */
13415 }
13416
13417 void
dhd_os_sdunlock(dhd_pub_t * pub)13418 dhd_os_sdunlock(dhd_pub_t *pub)
13419 {
13420 dhd_info_t *dhd;
13421
13422 dhd = (dhd_info_t *)(pub->info);
13423
13424 #ifdef BCMDBUS
13425 spin_unlock_bh(&dhd->sdlock);
13426 #else
13427 if (dhd_dpc_prio >= 0)
13428 up(&dhd->sdsem);
13429 else
13430 spin_unlock_bh(&dhd->sdlock);
13431 #endif /* !BCMDBUS */
13432 }
13433
13434 void
dhd_os_sdlock_txq(dhd_pub_t * pub)13435 dhd_os_sdlock_txq(dhd_pub_t *pub)
13436 {
13437 dhd_info_t *dhd;
13438
13439 dhd = (dhd_info_t *)(pub->info);
13440 #ifdef BCMDBUS
13441 spin_lock_irqsave(&dhd->txqlock, dhd->txqlock_flags);
13442 #else
13443 spin_lock_bh(&dhd->txqlock);
13444 #endif /* BCMDBUS */
13445 }
13446
13447 void
dhd_os_sdunlock_txq(dhd_pub_t * pub)13448 dhd_os_sdunlock_txq(dhd_pub_t *pub)
13449 {
13450 dhd_info_t *dhd;
13451
13452 dhd = (dhd_info_t *)(pub->info);
13453 #ifdef BCMDBUS
13454 spin_unlock_irqrestore(&dhd->txqlock, dhd->txqlock_flags);
13455 #else
13456 spin_unlock_bh(&dhd->txqlock);
13457 #endif /* BCMDBUS */
13458 }
13459
13460 void
dhd_os_sdlock_rxq(dhd_pub_t * pub)13461 dhd_os_sdlock_rxq(dhd_pub_t *pub)
13462 {
13463 }
13464
13465 void
dhd_os_sdunlock_rxq(dhd_pub_t * pub)13466 dhd_os_sdunlock_rxq(dhd_pub_t *pub)
13467 {
13468 }
13469
13470 static void
dhd_os_rxflock(dhd_pub_t * pub)13471 dhd_os_rxflock(dhd_pub_t *pub)
13472 {
13473 dhd_info_t *dhd;
13474
13475 dhd = (dhd_info_t *)(pub->info);
13476 spin_lock_bh(&dhd->rxf_lock);
13477
13478 }
13479
13480 static void
dhd_os_rxfunlock(dhd_pub_t * pub)13481 dhd_os_rxfunlock(dhd_pub_t *pub)
13482 {
13483 dhd_info_t *dhd;
13484
13485 dhd = (dhd_info_t *)(pub->info);
13486 spin_unlock_bh(&dhd->rxf_lock);
13487 }
13488
13489 #ifdef DHDTCPACK_SUPPRESS
13490 unsigned long
dhd_os_tcpacklock(dhd_pub_t * pub)13491 dhd_os_tcpacklock(dhd_pub_t *pub)
13492 {
13493 dhd_info_t *dhd;
13494 unsigned long flags = 0;
13495
13496 dhd = (dhd_info_t *)(pub->info);
13497
13498 if (dhd) {
13499 #ifdef BCMSDIO
13500 spin_lock_bh(&dhd->tcpack_lock);
13501 #else
13502 spin_lock_irqsave(&dhd->tcpack_lock, flags);
13503 #endif /* BCMSDIO */
13504 }
13505
13506 return flags;
13507 }
13508
13509 void
dhd_os_tcpackunlock(dhd_pub_t * pub,unsigned long flags)13510 dhd_os_tcpackunlock(dhd_pub_t *pub, unsigned long flags)
13511 {
13512 dhd_info_t *dhd;
13513
13514 #ifdef BCMSDIO
13515 BCM_REFERENCE(flags);
13516 #endif /* BCMSDIO */
13517
13518 dhd = (dhd_info_t *)(pub->info);
13519
13520 if (dhd) {
13521 #ifdef BCMSDIO
13522 spin_unlock_bh(&dhd->tcpack_lock);
13523 #else
13524 spin_unlock_irqrestore(&dhd->tcpack_lock, flags);
13525 #endif /* BCMSDIO */
13526 }
13527 }
13528 #endif /* DHDTCPACK_SUPPRESS */
13529
dhd_os_prealloc(dhd_pub_t * dhdpub,int section,uint size,bool kmalloc_if_fail)13530 uint8* dhd_os_prealloc(dhd_pub_t *dhdpub, int section, uint size, bool kmalloc_if_fail)
13531 {
13532 uint8* buf;
13533 gfp_t flags = CAN_SLEEP() ? GFP_KERNEL: GFP_ATOMIC;
13534
13535 buf = (uint8*)wifi_platform_prealloc(dhdpub->info->adapter, section, size);
13536 if (buf == NULL && kmalloc_if_fail)
13537 buf = kmalloc(size, flags);
13538
13539 return buf;
13540 }
13541
dhd_os_prefree(dhd_pub_t * dhdpub,void * addr,uint size)13542 void dhd_os_prefree(dhd_pub_t *dhdpub, void *addr, uint size)
13543 {
13544 }
13545
13546 #if defined(WL_WIRELESS_EXT)
13547 struct iw_statistics *
dhd_get_wireless_stats(struct net_device * dev)13548 dhd_get_wireless_stats(struct net_device *dev)
13549 {
13550 int res = 0;
13551 dhd_info_t *dhd = DHD_DEV_INFO(dev);
13552
13553 if (!dhd->pub.up) {
13554 return NULL;
13555 }
13556
13557 if (!(dev->flags & IFF_UP)) {
13558 return NULL;
13559 }
13560
13561 res = wl_iw_get_wireless_stats(dev, &dhd->iw.wstats);
13562
13563 if (res == 0)
13564 return &dhd->iw.wstats;
13565 else
13566 return NULL;
13567 }
13568 #endif /* defined(WL_WIRELESS_EXT) */
13569
13570 static int
dhd_wl_host_event(dhd_info_t * dhd,int ifidx,void * pktdata,uint16 pktlen,wl_event_msg_t * event,void ** data)13571 dhd_wl_host_event(dhd_info_t *dhd, int ifidx, void *pktdata, uint16 pktlen,
13572 wl_event_msg_t *event, void **data)
13573 {
13574 int bcmerror = 0;
13575 #ifdef WL_CFG80211
13576 unsigned long flags = 0;
13577 #endif /* WL_CFG80211 */
13578 ASSERT(dhd != NULL);
13579
13580 #ifdef SHOW_LOGTRACE
13581 bcmerror = wl_process_host_event(&dhd->pub, &ifidx, pktdata, pktlen, event, data,
13582 &dhd->event_data);
13583 #else
13584 bcmerror = wl_process_host_event(&dhd->pub, &ifidx, pktdata, pktlen, event, data,
13585 NULL);
13586 #endif /* SHOW_LOGTRACE */
13587 if (unlikely(bcmerror != BCME_OK)) {
13588 return bcmerror;
13589 }
13590
13591 if (ntoh32(event->event_type) == WLC_E_IF) {
13592 /* WLC_E_IF event types are consumed by wl_process_host_event.
13593 * For ifadd/del ops, the netdev ptr may not be valid at this
13594 * point. so return before invoking cfg80211/wext handlers.
13595 */
13596 return BCME_OK;
13597 }
13598
13599 #if defined(WL_EXT_IAPSTA) || defined(USE_IW)
13600 wl_ext_event_send(dhd->pub.event_params, event, *data);
13601 #endif
13602
13603 #ifdef WL_CFG80211
13604 if (dhd->iflist[ifidx]->net) {
13605 spin_lock_irqsave(&dhd->pub.up_lock, flags);
13606 if (dhd->pub.up) {
13607 wl_cfg80211_event(dhd->iflist[ifidx]->net, event, *data);
13608 }
13609 spin_unlock_irqrestore(&dhd->pub.up_lock, flags);
13610 }
13611 #endif /* defined(WL_CFG80211) */
13612
13613 return (bcmerror);
13614 }
13615
13616 /* send up locally generated event */
13617 void
dhd_sendup_event(dhd_pub_t * dhdp,wl_event_msg_t * event,void * data)13618 dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data)
13619 {
13620 switch (ntoh32(event->event_type)) {
13621 /* Handle error case or further events here */
13622 default:
13623 break;
13624 }
13625 }
13626
13627 #ifdef LOG_INTO_TCPDUMP
13628 void
dhd_sendup_log(dhd_pub_t * dhdp,void * data,int data_len)13629 dhd_sendup_log(dhd_pub_t *dhdp, void *data, int data_len)
13630 {
13631 struct sk_buff *p, *skb;
13632 uint32 pktlen;
13633 int len;
13634 dhd_if_t *ifp;
13635 dhd_info_t *dhd;
13636 uchar *skb_data;
13637 int ifidx = 0;
13638 struct ether_header eth;
13639
13640 pktlen = sizeof(eth) + data_len;
13641 dhd = dhdp->info;
13642
13643 if ((p = PKTGET(dhdp->osh, pktlen, FALSE))) {
13644 ASSERT(ISALIGNED((uintptr)PKTDATA(dhdp->osh, p), sizeof(uint32)));
13645
13646 bcopy(&dhdp->mac, ð.ether_dhost, ETHER_ADDR_LEN);
13647 bcopy(&dhdp->mac, ð.ether_shost, ETHER_ADDR_LEN);
13648 ETHER_TOGGLE_LOCALADDR(ð.ether_shost);
13649 eth.ether_type = hton16(ETHER_TYPE_BRCM);
13650
13651 bcopy((void *)ð, PKTDATA(dhdp->osh, p), sizeof(eth));
13652 bcopy(data, PKTDATA(dhdp->osh, p) + sizeof(eth), data_len);
13653 skb = PKTTONATIVE(dhdp->osh, p);
13654 skb_data = skb->data;
13655 len = skb->len;
13656
13657 ifidx = dhd_ifname2idx(dhd, "wlan0");
13658 ifp = dhd->iflist[ifidx];
13659 if (ifp == NULL)
13660 ifp = dhd->iflist[0];
13661
13662 ASSERT(ifp);
13663 skb->dev = ifp->net;
13664 skb->protocol = eth_type_trans(skb, skb->dev);
13665 skb->data = skb_data;
13666 skb->len = len;
13667
13668 /* Strip header, count, deliver upward */
13669 skb_pull(skb, ETH_HLEN);
13670
13671 bcm_object_trace_opr(skb, BCM_OBJDBG_REMOVE,
13672 __FUNCTION__, __LINE__);
13673 /* Send the packet */
13674 if (in_interrupt()) {
13675 netif_rx(skb);
13676 } else {
13677 netif_rx_ni(skb);
13678 }
13679 } else {
13680 /* Could not allocate a sk_buf */
13681 DHD_ERROR(("%s: unable to alloc sk_buf\n", __FUNCTION__));
13682 }
13683 }
13684 #endif /* LOG_INTO_TCPDUMP */
13685
dhd_wait_for_event(dhd_pub_t * dhd,bool * lockvar)13686 void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar)
13687 {
13688 #if defined(BCMSDIO)
13689 struct dhd_info *dhdinfo = dhd->info;
13690
13691 int timeout = msecs_to_jiffies(IOCTL_RESP_TIMEOUT);
13692
13693 dhd_os_sdunlock(dhd);
13694 wait_event_timeout(dhdinfo->ctrl_wait, (*lockvar == FALSE), timeout);
13695 dhd_os_sdlock(dhd);
13696 #endif /* defined(BCMSDIO) */
13697 return;
13698 } /* dhd_init_static_strs_array */
13699
dhd_wait_event_wakeup(dhd_pub_t * dhd)13700 void dhd_wait_event_wakeup(dhd_pub_t *dhd)
13701 {
13702 #if defined(BCMSDIO)
13703 struct dhd_info *dhdinfo = dhd->info;
13704 if (waitqueue_active(&dhdinfo->ctrl_wait))
13705 wake_up(&dhdinfo->ctrl_wait);
13706 #endif // endif
13707 return;
13708 }
13709
13710 #if defined(BCMSDIO) || defined(BCMPCIE) || defined(BCMDBUS)
13711 int
dhd_net_bus_devreset(struct net_device * dev,uint8 flag)13712 dhd_net_bus_devreset(struct net_device *dev, uint8 flag)
13713 {
13714 int ret;
13715
13716 dhd_info_t *dhd = DHD_DEV_INFO(dev);
13717
13718 #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
13719 if (pm_runtime_get_sync(dhd_bus_to_dev(dhd->pub.bus)) < 0)
13720 return BCME_ERROR;
13721 #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
13722
13723 if (flag == TRUE) {
13724 /* Issue wl down command before resetting the chip */
13725 if (dhd_wl_ioctl_cmd(&dhd->pub, WLC_DOWN, NULL, 0, TRUE, 0) < 0) {
13726 DHD_TRACE(("%s: wl down failed\n", __FUNCTION__));
13727 }
13728 #ifdef PROP_TXSTATUS
13729 if (dhd->pub.wlfc_enabled) {
13730 dhd_wlfc_deinit(&dhd->pub);
13731 }
13732 #endif /* PROP_TXSTATUS */
13733 #ifdef PNO_SUPPORT
13734 if (dhd->pub.pno_state) {
13735 dhd_pno_deinit(&dhd->pub);
13736 }
13737 #endif // endif
13738 #ifdef RTT_SUPPORT
13739 if (dhd->pub.rtt_state) {
13740 dhd_rtt_deinit(&dhd->pub);
13741 }
13742 #endif /* RTT_SUPPORT */
13743
13744 #if defined(DBG_PKT_MON) && !defined(DBG_PKT_MON_INIT_DEFAULT)
13745 dhd_os_dbg_detach_pkt_monitor(&dhd->pub);
13746 #endif /* DBG_PKT_MON */
13747 }
13748
13749 #ifdef BCMSDIO
13750 if (!flag) {
13751 dhd_update_fw_nv_path(dhd);
13752 /* update firmware and nvram path to sdio bus */
13753 dhd_bus_update_fw_nv_path(dhd->pub.bus,
13754 dhd->fw_path, dhd->nv_path, dhd->clm_path, dhd->conf_path);
13755 }
13756 #endif /* BCMSDIO */
13757
13758 ret = dhd_bus_devreset(&dhd->pub, flag);
13759
13760 #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
13761 pm_runtime_mark_last_busy(dhd_bus_to_dev(dhd->pub.bus));
13762 pm_runtime_put_autosuspend(dhd_bus_to_dev(dhd->pub.bus));
13763 #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
13764
13765 if (flag) {
13766 /* Clear some flags for recovery logic */
13767 dhd->pub.dongle_trap_occured = 0;
13768 dhd->pub.iovar_timeout_occured = 0;
13769 #ifdef PCIE_FULL_DONGLE
13770 dhd->pub.d3ack_timeout_occured = 0;
13771 dhd->pub.livelock_occured = 0;
13772 dhd->pub.pktid_audit_failed = 0;
13773 #endif /* PCIE_FULL_DONGLE */
13774 dhd->pub.iface_op_failed = 0;
13775 dhd->pub.scan_timeout_occurred = 0;
13776 dhd->pub.scan_busy_occurred = 0;
13777 dhd->pub.smmu_fault_occurred = 0;
13778 }
13779
13780 if (ret) {
13781 DHD_ERROR(("%s: dhd_bus_devreset: %d\n", __FUNCTION__, ret));
13782 }
13783
13784 return ret;
13785 }
13786
13787 #ifdef BCMSDIO
13788 int
dhd_net_bus_suspend(struct net_device * dev)13789 dhd_net_bus_suspend(struct net_device *dev)
13790 {
13791 dhd_info_t *dhd = DHD_DEV_INFO(dev);
13792 return dhd_bus_suspend(&dhd->pub);
13793 }
13794
13795 int
dhd_net_bus_resume(struct net_device * dev,uint8 stage)13796 dhd_net_bus_resume(struct net_device *dev, uint8 stage)
13797 {
13798 dhd_info_t *dhd = DHD_DEV_INFO(dev);
13799 return dhd_bus_resume(&dhd->pub, stage);
13800 }
13801
13802 #endif /* BCMSDIO */
13803 #endif /* BCMSDIO || BCMPCIE || BCMDBUS */
13804
net_os_set_suspend_disable(struct net_device * dev,int val)13805 int net_os_set_suspend_disable(struct net_device *dev, int val)
13806 {
13807 dhd_info_t *dhd = DHD_DEV_INFO(dev);
13808 int ret = 0;
13809
13810 if (dhd) {
13811 ret = dhd->pub.suspend_disable_flag;
13812 dhd->pub.suspend_disable_flag = val;
13813 }
13814 return ret;
13815 }
13816
net_os_set_suspend(struct net_device * dev,int val,int force)13817 int net_os_set_suspend(struct net_device *dev, int val, int force)
13818 {
13819 int ret = 0;
13820 dhd_info_t *dhd = DHD_DEV_INFO(dev);
13821
13822 if (dhd && dhd->pub.conf->suspend_mode == EARLY_SUSPEND) {
13823 if (!val)
13824 dhd_conf_set_suspend_resume(&dhd->pub, val);
13825 #ifdef CONFIG_MACH_UNIVERSAL7420
13826 #endif /* CONFIG_MACH_UNIVERSAL7420 */
13827 #if defined(CONFIG_HAS_EARLYSUSPEND) && defined(DHD_USE_EARLYSUSPEND)
13828 ret = dhd_set_suspend(val, &dhd->pub);
13829 #else
13830 ret = dhd_suspend_resume_helper(dhd, val, force);
13831 #endif // endif
13832 #ifdef WL_CFG80211
13833 wl_cfg80211_update_power_mode(dev);
13834 #endif // endif
13835 if (val)
13836 dhd_conf_set_suspend_resume(&dhd->pub, val);
13837 }
13838 return ret;
13839 }
13840
net_os_set_suspend_bcn_li_dtim(struct net_device * dev,int val)13841 int net_os_set_suspend_bcn_li_dtim(struct net_device *dev, int val)
13842 {
13843 dhd_info_t *dhd = DHD_DEV_INFO(dev);
13844
13845 if (dhd) {
13846 DHD_ERROR(("%s: Set bcn_li_dtim in suspend %d\n",
13847 __FUNCTION__, val));
13848 dhd->pub.suspend_bcn_li_dtim = val;
13849 }
13850
13851 return 0;
13852 }
13853
net_os_set_max_dtim_enable(struct net_device * dev,int val)13854 int net_os_set_max_dtim_enable(struct net_device *dev, int val)
13855 {
13856 dhd_info_t *dhd = DHD_DEV_INFO(dev);
13857
13858 if (dhd) {
13859 DHD_ERROR(("%s: use MAX bcn_li_dtim in suspend %s\n",
13860 __FUNCTION__, (val ? "Enable" : "Disable")));
13861 if (val) {
13862 dhd->pub.max_dtim_enable = TRUE;
13863 } else {
13864 dhd->pub.max_dtim_enable = FALSE;
13865 }
13866 } else {
13867 return -1;
13868 }
13869
13870 return 0;
13871 }
13872
13873 #ifdef DISABLE_DTIM_IN_SUSPEND
net_os_set_disable_dtim_in_suspend(struct net_device * dev,int val)13874 int net_os_set_disable_dtim_in_suspend(struct net_device *dev, int val)
13875 {
13876 dhd_info_t *dhd = DHD_DEV_INFO(dev);
13877
13878 if (dhd) {
13879 DHD_ERROR(("%s: Disable bcn_li_dtim in suspend %s\n",
13880 __FUNCTION__, (val ? "Enable" : "Disable")));
13881 if (val) {
13882 dhd->pub.disable_dtim_in_suspend = TRUE;
13883 } else {
13884 dhd->pub.disable_dtim_in_suspend = FALSE;
13885 }
13886 } else {
13887 return -1;
13888 }
13889
13890 return 0;
13891 }
13892 #endif /* DISABLE_DTIM_IN_SUSPEND */
13893
13894 #ifdef PKT_FILTER_SUPPORT
net_os_rxfilter_add_remove(struct net_device * dev,int add_remove,int num)13895 int net_os_rxfilter_add_remove(struct net_device *dev, int add_remove, int num)
13896 {
13897 int ret = 0;
13898
13899 #ifndef GAN_LITE_NAT_KEEPALIVE_FILTER
13900 dhd_info_t *dhd = DHD_DEV_INFO(dev);
13901
13902 if (!dhd_master_mode)
13903 add_remove = !add_remove;
13904 DHD_ERROR(("%s: add_remove = %d, num = %d\n", __FUNCTION__, add_remove, num));
13905 if (!dhd || (num == DHD_UNICAST_FILTER_NUM)) {
13906 return 0;
13907 }
13908
13909 #ifdef BLOCK_IPV6_PACKET
13910 /* customer want to use NO IPV6 packets only */
13911 if (num == DHD_MULTICAST6_FILTER_NUM) {
13912 return 0;
13913 }
13914 #endif /* BLOCK_IPV6_PACKET */
13915
13916 if (num >= dhd->pub.pktfilter_count) {
13917 return -EINVAL;
13918 }
13919
13920 ret = dhd_packet_filter_add_remove(&dhd->pub, add_remove, num);
13921 #endif /* !GAN_LITE_NAT_KEEPALIVE_FILTER */
13922
13923 return ret;
13924 }
13925
dhd_os_enable_packet_filter(dhd_pub_t * dhdp,int val)13926 int dhd_os_enable_packet_filter(dhd_pub_t *dhdp, int val)
13927
13928 {
13929 int ret = 0;
13930
13931 /* Packet filtering is set only if we still in early-suspend and
13932 * we need either to turn it ON or turn it OFF
13933 * We can always turn it OFF in case of early-suspend, but we turn it
13934 * back ON only if suspend_disable_flag was not set
13935 */
13936 if (dhdp && dhdp->up) {
13937 if (dhdp->in_suspend) {
13938 if (!val || (val && !dhdp->suspend_disable_flag))
13939 dhd_enable_packet_filter(val, dhdp);
13940 }
13941 }
13942 return ret;
13943 }
13944
13945 /* function to enable/disable packet for Network device */
net_os_enable_packet_filter(struct net_device * dev,int val)13946 int net_os_enable_packet_filter(struct net_device *dev, int val)
13947 {
13948 dhd_info_t *dhd = DHD_DEV_INFO(dev);
13949
13950 DHD_ERROR(("%s: val = %d\n", __FUNCTION__, val));
13951 return dhd_os_enable_packet_filter(&dhd->pub, val);
13952 }
13953 #endif /* PKT_FILTER_SUPPORT */
13954
13955 int
dhd_dev_init_ioctl(struct net_device * dev)13956 dhd_dev_init_ioctl(struct net_device *dev)
13957 {
13958 dhd_info_t *dhd = DHD_DEV_INFO(dev);
13959 int ret;
13960
13961 if ((ret = dhd_sync_with_dongle(&dhd->pub)) < 0)
13962 goto done;
13963
13964 done:
13965 return ret;
13966 }
13967
13968 int
dhd_dev_get_feature_set(struct net_device * dev)13969 dhd_dev_get_feature_set(struct net_device *dev)
13970 {
13971 dhd_info_t *ptr = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
13972 dhd_pub_t *dhd = (&ptr->pub);
13973 int feature_set = 0;
13974
13975 if (FW_SUPPORTED(dhd, sta))
13976 feature_set |= WIFI_FEATURE_INFRA;
13977 if (FW_SUPPORTED(dhd, dualband))
13978 feature_set |= WIFI_FEATURE_INFRA_5G;
13979 if (FW_SUPPORTED(dhd, p2p))
13980 feature_set |= WIFI_FEATURE_P2P;
13981 if (dhd->op_mode & DHD_FLAG_HOSTAP_MODE)
13982 feature_set |= WIFI_FEATURE_SOFT_AP;
13983 if (FW_SUPPORTED(dhd, tdls))
13984 feature_set |= WIFI_FEATURE_TDLS;
13985 if (FW_SUPPORTED(dhd, vsdb))
13986 feature_set |= WIFI_FEATURE_TDLS_OFFCHANNEL;
13987 if (FW_SUPPORTED(dhd, nan)) {
13988 feature_set |= WIFI_FEATURE_NAN;
13989 /* NAN is essentail for d2d rtt */
13990 if (FW_SUPPORTED(dhd, rttd2d))
13991 feature_set |= WIFI_FEATURE_D2D_RTT;
13992 }
13993 #ifdef RTT_SUPPORT
13994 if (dhd->rtt_supported) {
13995 feature_set |= WIFI_FEATURE_D2D_RTT;
13996 feature_set |= WIFI_FEATURE_D2AP_RTT;
13997 }
13998 #endif /* RTT_SUPPORT */
13999 #ifdef LINKSTAT_SUPPORT
14000 feature_set |= WIFI_FEATURE_LINKSTAT;
14001 #endif /* LINKSTAT_SUPPORT */
14002
14003 #if defined(PNO_SUPPORT) && !defined(DISABLE_ANDROID_PNO)
14004 if (dhd_is_pno_supported(dhd)) {
14005 feature_set |= WIFI_FEATURE_PNO;
14006 #ifdef GSCAN_SUPPORT
14007 /* terence 20171115: remove to get GTS PASS
14008 * com.google.android.gts.wifi.WifiHostTest#testWifiScannerBatchTimestamp
14009 */
14010 // feature_set |= WIFI_FEATURE_GSCAN;
14011 // feature_set |= WIFI_FEATURE_HAL_EPNO;
14012 #endif /* GSCAN_SUPPORT */
14013 }
14014 #endif /* PNO_SUPPORT && !DISABLE_ANDROID_PNO */
14015 #ifdef RSSI_MONITOR_SUPPORT
14016 if (FW_SUPPORTED(dhd, rssi_mon)) {
14017 feature_set |= WIFI_FEATURE_RSSI_MONITOR;
14018 }
14019 #endif /* RSSI_MONITOR_SUPPORT */
14020 #ifdef WL11U
14021 feature_set |= WIFI_FEATURE_HOTSPOT;
14022 #endif /* WL11U */
14023 #ifdef NDO_CONFIG_SUPPORT
14024 feature_set |= WIFI_FEATURE_CONFIG_NDO;
14025 #endif /* NDO_CONFIG_SUPPORT */
14026 #ifdef KEEP_ALIVE
14027 feature_set |= WIFI_FEATURE_MKEEP_ALIVE;
14028 #endif /* KEEP_ALIVE */
14029 #ifdef FILTER_IE
14030 if (FW_SUPPORTED(dhd, fie)) {
14031 feature_set |= WIFI_FEATURE_FILTER_IE;
14032 }
14033 #endif /* FILTER_IE */
14034 #ifdef ROAMEXP_SUPPORT
14035 /* Check if the Android O roam feature is supported by FW */
14036 if (!(BCME_UNSUPPORTED == dhd_dev_set_whitelist_ssid(dev, NULL, 0, true))) {
14037 feature_set |= WIFI_FEATURE_CONTROL_ROAMING;
14038 }
14039 #endif /* ROAMEXP_SUPPORT */
14040 return feature_set;
14041 }
14042
14043 int
dhd_dev_get_feature_set_matrix(struct net_device * dev,int num)14044 dhd_dev_get_feature_set_matrix(struct net_device *dev, int num)
14045 {
14046 int feature_set_full;
14047 int ret = 0;
14048
14049 feature_set_full = dhd_dev_get_feature_set(dev);
14050
14051 /* Common feature set for all interface */
14052 ret = (feature_set_full & WIFI_FEATURE_INFRA) |
14053 (feature_set_full & WIFI_FEATURE_INFRA_5G) |
14054 (feature_set_full & WIFI_FEATURE_D2D_RTT) |
14055 (feature_set_full & WIFI_FEATURE_D2AP_RTT) |
14056 (feature_set_full & WIFI_FEATURE_RSSI_MONITOR) |
14057 (feature_set_full & WIFI_FEATURE_EPR);
14058
14059 /* Specific feature group for each interface */
14060 switch (num) {
14061 case 0:
14062 ret |= (feature_set_full & WIFI_FEATURE_P2P) |
14063 /* Not supported yet */
14064 /* (feature_set_full & WIFI_FEATURE_NAN) | */
14065 (feature_set_full & WIFI_FEATURE_TDLS) |
14066 (feature_set_full & WIFI_FEATURE_PNO) |
14067 (feature_set_full & WIFI_FEATURE_HAL_EPNO) |
14068 (feature_set_full & WIFI_FEATURE_BATCH_SCAN) |
14069 (feature_set_full & WIFI_FEATURE_GSCAN) |
14070 (feature_set_full & WIFI_FEATURE_HOTSPOT) |
14071 (feature_set_full & WIFI_FEATURE_ADDITIONAL_STA);
14072 break;
14073
14074 case 1:
14075 ret |= (feature_set_full & WIFI_FEATURE_P2P);
14076 /* Not yet verified NAN with P2P */
14077 /* (feature_set_full & WIFI_FEATURE_NAN) | */
14078 break;
14079
14080 case 2:
14081 ret |= (feature_set_full & WIFI_FEATURE_NAN) |
14082 (feature_set_full & WIFI_FEATURE_TDLS) |
14083 (feature_set_full & WIFI_FEATURE_TDLS_OFFCHANNEL);
14084 break;
14085
14086 default:
14087 ret = WIFI_FEATURE_INVALID;
14088 DHD_ERROR(("%s: Out of index(%d) for get feature set\n", __FUNCTION__, num));
14089 break;
14090 }
14091
14092 return ret;
14093 }
14094
14095 #ifdef CUSTOM_FORCE_NODFS_FLAG
14096 int
dhd_dev_set_nodfs(struct net_device * dev,u32 nodfs)14097 dhd_dev_set_nodfs(struct net_device *dev, u32 nodfs)
14098 {
14099 dhd_info_t *dhd = DHD_DEV_INFO(dev);
14100
14101 if (nodfs)
14102 dhd->pub.dhd_cflags |= WLAN_PLAT_NODFS_FLAG;
14103 else
14104 dhd->pub.dhd_cflags &= ~WLAN_PLAT_NODFS_FLAG;
14105 dhd->pub.force_country_change = TRUE;
14106 return 0;
14107 }
14108 #endif /* CUSTOM_FORCE_NODFS_FLAG */
14109
14110 #ifdef NDO_CONFIG_SUPPORT
14111 int
dhd_dev_ndo_cfg(struct net_device * dev,u8 enable)14112 dhd_dev_ndo_cfg(struct net_device *dev, u8 enable)
14113 {
14114 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14115 dhd_pub_t *dhdp = &dhd->pub;
14116 int ret = 0;
14117
14118 if (enable) {
14119 /* enable ND offload feature (will be enabled in FW on suspend) */
14120 dhdp->ndo_enable = TRUE;
14121
14122 /* Update changes of anycast address & DAD failed address */
14123 ret = dhd_dev_ndo_update_inet6addr(dev);
14124 if ((ret < 0) && (ret != BCME_NORESOURCE)) {
14125 DHD_ERROR(("%s: failed to update host ip addr: %d\n", __FUNCTION__, ret));
14126 return ret;
14127 }
14128 } else {
14129 /* disable ND offload feature */
14130 dhdp->ndo_enable = FALSE;
14131
14132 /* disable ND offload in FW */
14133 ret = dhd_ndo_enable(dhdp, FALSE);
14134 if (ret < 0) {
14135 DHD_ERROR(("%s: failed to disable NDO: %d\n", __FUNCTION__, ret));
14136 }
14137 }
14138 return ret;
14139 }
14140
14141 /* #pragma used as a WAR to fix build failure,
14142 * ignore dropping of 'const' qualifier in 'list_entry' macro
14143 * this pragma disables the warning only for the following function
14144 */
14145 #pragma GCC diagnostic push
14146 #pragma GCC diagnostic ignored "-Wcast-qual"
14147
14148 static int
dhd_dev_ndo_get_valid_inet6addr_count(struct inet6_dev * inet6)14149 dhd_dev_ndo_get_valid_inet6addr_count(struct inet6_dev *inet6)
14150 {
14151 struct inet6_ifaddr *ifa;
14152 struct ifacaddr6 *acaddr = NULL;
14153 int addr_count = 0;
14154
14155 /* lock */
14156 read_lock_bh(&inet6->lock);
14157
14158 /* Count valid unicast address */
14159 list_for_each_entry(ifa, &inet6->addr_list, if_list) {
14160 if ((ifa->flags & IFA_F_DADFAILED) == 0) {
14161 addr_count++;
14162 }
14163 }
14164
14165 /* Count anycast address */
14166 acaddr = inet6->ac_list;
14167 while (acaddr) {
14168 addr_count++;
14169 acaddr = acaddr->aca_next;
14170 }
14171
14172 /* unlock */
14173 read_unlock_bh(&inet6->lock);
14174
14175 return addr_count;
14176 }
14177
14178 int
dhd_dev_ndo_update_inet6addr(struct net_device * dev)14179 dhd_dev_ndo_update_inet6addr(struct net_device *dev)
14180 {
14181 dhd_info_t *dhd;
14182 dhd_pub_t *dhdp;
14183 struct inet6_dev *inet6;
14184 struct inet6_ifaddr *ifa;
14185 struct ifacaddr6 *acaddr = NULL;
14186 struct in6_addr *ipv6_addr = NULL;
14187 int cnt, i;
14188 int ret = BCME_OK;
14189
14190 /*
14191 * this function evaulates host ip address in struct inet6_dev
14192 * unicast addr in inet6_dev->addr_list
14193 * anycast addr in inet6_dev->ac_list
14194 * while evaluating inet6_dev, read_lock_bh() is required to prevent
14195 * access on null(freed) pointer.
14196 */
14197
14198 if (dev) {
14199 inet6 = dev->ip6_ptr;
14200 if (!inet6) {
14201 DHD_ERROR(("%s: Invalid inet6_dev\n", __FUNCTION__));
14202 return BCME_ERROR;
14203 }
14204
14205 dhd = DHD_DEV_INFO(dev);
14206 if (!dhd) {
14207 DHD_ERROR(("%s: Invalid dhd_info\n", __FUNCTION__));
14208 return BCME_ERROR;
14209 }
14210 dhdp = &dhd->pub;
14211
14212 if (dhd_net2idx(dhd, dev) != 0) {
14213 DHD_ERROR(("%s: Not primary interface\n", __FUNCTION__));
14214 return BCME_ERROR;
14215 }
14216 } else {
14217 DHD_ERROR(("%s: Invalid net_device\n", __FUNCTION__));
14218 return BCME_ERROR;
14219 }
14220
14221 /* Check host IP overflow */
14222 cnt = dhd_dev_ndo_get_valid_inet6addr_count(inet6);
14223 if (cnt > dhdp->ndo_max_host_ip) {
14224 if (!dhdp->ndo_host_ip_overflow) {
14225 dhdp->ndo_host_ip_overflow = TRUE;
14226 /* Disable ND offload in FW */
14227 DHD_INFO(("%s: Host IP overflow, disable NDO\n", __FUNCTION__));
14228 ret = dhd_ndo_enable(dhdp, FALSE);
14229 }
14230
14231 return ret;
14232 }
14233
14234 /*
14235 * Allocate ipv6 addr buffer to store addresses to be added/removed.
14236 * driver need to lock inet6_dev while accessing structure. but, driver
14237 * cannot use ioctl while inet6_dev locked since it requires scheduling
14238 * hence, copy addresses to the buffer and do ioctl after unlock.
14239 */
14240 ipv6_addr = (struct in6_addr *)MALLOC(dhdp->osh,
14241 sizeof(struct in6_addr) * dhdp->ndo_max_host_ip);
14242 if (!ipv6_addr) {
14243 DHD_ERROR(("%s: failed to alloc ipv6 addr buffer\n", __FUNCTION__));
14244 return BCME_NOMEM;
14245 }
14246
14247 /* Find DAD failed unicast address to be removed */
14248 cnt = 0;
14249 read_lock_bh(&inet6->lock);
14250 list_for_each_entry(ifa, &inet6->addr_list, if_list) {
14251 /* DAD failed unicast address */
14252 if ((ifa->flags & IFA_F_DADFAILED) &&
14253 (cnt < dhdp->ndo_max_host_ip)) {
14254 memcpy(&ipv6_addr[cnt], &ifa->addr, sizeof(struct in6_addr));
14255 cnt++;
14256 }
14257 }
14258 read_unlock_bh(&inet6->lock);
14259
14260 /* Remove DAD failed unicast address */
14261 for (i = 0; i < cnt; i++) {
14262 DHD_INFO(("%s: Remove DAD failed addr\n", __FUNCTION__));
14263 ret = dhd_ndo_remove_ip_by_addr(dhdp, (char *)&ipv6_addr[i], 0);
14264 if (ret < 0) {
14265 goto done;
14266 }
14267 }
14268
14269 /* Remove all anycast address */
14270 ret = dhd_ndo_remove_ip_by_type(dhdp, WL_ND_IPV6_ADDR_TYPE_ANYCAST, 0);
14271 if (ret < 0) {
14272 goto done;
14273 }
14274
14275 /*
14276 * if ND offload was disabled due to host ip overflow,
14277 * attempt to add valid unicast address.
14278 */
14279 if (dhdp->ndo_host_ip_overflow) {
14280 /* Find valid unicast address */
14281 cnt = 0;
14282 read_lock_bh(&inet6->lock);
14283 list_for_each_entry(ifa, &inet6->addr_list, if_list) {
14284 /* valid unicast address */
14285 if (!(ifa->flags & IFA_F_DADFAILED) &&
14286 (cnt < dhdp->ndo_max_host_ip)) {
14287 memcpy(&ipv6_addr[cnt], &ifa->addr,
14288 sizeof(struct in6_addr));
14289 cnt++;
14290 }
14291 }
14292 read_unlock_bh(&inet6->lock);
14293
14294 /* Add valid unicast address */
14295 for (i = 0; i < cnt; i++) {
14296 ret = dhd_ndo_add_ip_with_type(dhdp,
14297 (char *)&ipv6_addr[i], WL_ND_IPV6_ADDR_TYPE_UNICAST, 0);
14298 if (ret < 0) {
14299 goto done;
14300 }
14301 }
14302 }
14303
14304 /* Find anycast address */
14305 cnt = 0;
14306 read_lock_bh(&inet6->lock);
14307 acaddr = inet6->ac_list;
14308 while (acaddr) {
14309 if (cnt < dhdp->ndo_max_host_ip) {
14310 memcpy(&ipv6_addr[cnt], &acaddr->aca_addr, sizeof(struct in6_addr));
14311 cnt++;
14312 }
14313 acaddr = acaddr->aca_next;
14314 }
14315 read_unlock_bh(&inet6->lock);
14316
14317 /* Add anycast address */
14318 for (i = 0; i < cnt; i++) {
14319 ret = dhd_ndo_add_ip_with_type(dhdp,
14320 (char *)&ipv6_addr[i], WL_ND_IPV6_ADDR_TYPE_ANYCAST, 0);
14321 if (ret < 0) {
14322 goto done;
14323 }
14324 }
14325
14326 /* Now All host IP addr were added successfully */
14327 if (dhdp->ndo_host_ip_overflow) {
14328 dhdp->ndo_host_ip_overflow = FALSE;
14329 if (dhdp->in_suspend) {
14330 /* drvier is in (early) suspend state, need to enable ND offload in FW */
14331 DHD_INFO(("%s: enable NDO\n", __FUNCTION__));
14332 ret = dhd_ndo_enable(dhdp, TRUE);
14333 }
14334 }
14335
14336 done:
14337 if (ipv6_addr) {
14338 MFREE(dhdp->osh, ipv6_addr, sizeof(struct in6_addr) * dhdp->ndo_max_host_ip);
14339 }
14340
14341 return ret;
14342 }
14343 #pragma GCC diagnostic pop
14344
14345 #endif /* NDO_CONFIG_SUPPORT */
14346
14347 #ifdef PNO_SUPPORT
14348 /* Linux wrapper to call common dhd_pno_stop_for_ssid */
14349 int
dhd_dev_pno_stop_for_ssid(struct net_device * dev)14350 dhd_dev_pno_stop_for_ssid(struct net_device *dev)
14351 {
14352 dhd_info_t *dhd = DHD_DEV_INFO(dev);
14353
14354 return (dhd_pno_stop_for_ssid(&dhd->pub));
14355 }
14356
14357 /* Linux wrapper to call common dhd_pno_set_for_ssid */
14358 int
dhd_dev_pno_set_for_ssid(struct net_device * dev,wlc_ssid_ext_t * ssids_local,int nssid,uint16 scan_fr,int pno_repeat,int pno_freq_expo_max,uint16 * channel_list,int nchan)14359 dhd_dev_pno_set_for_ssid(struct net_device *dev, wlc_ssid_ext_t* ssids_local, int nssid,
14360 uint16 scan_fr, int pno_repeat, int pno_freq_expo_max, uint16 *channel_list, int nchan)
14361 {
14362 dhd_info_t *dhd = DHD_DEV_INFO(dev);
14363
14364 return (dhd_pno_set_for_ssid(&dhd->pub, ssids_local, nssid, scan_fr,
14365 pno_repeat, pno_freq_expo_max, channel_list, nchan));
14366 }
14367
14368 /* Linux wrapper to call common dhd_pno_enable */
14369 int
dhd_dev_pno_enable(struct net_device * dev,int enable)14370 dhd_dev_pno_enable(struct net_device *dev, int enable)
14371 {
14372 dhd_info_t *dhd = DHD_DEV_INFO(dev);
14373
14374 return (dhd_pno_enable(&dhd->pub, enable));
14375 }
14376
14377 /* Linux wrapper to call common dhd_pno_set_for_hotlist */
14378 int
dhd_dev_pno_set_for_hotlist(struct net_device * dev,wl_pfn_bssid_t * p_pfn_bssid,struct dhd_pno_hotlist_params * hotlist_params)14379 dhd_dev_pno_set_for_hotlist(struct net_device *dev, wl_pfn_bssid_t *p_pfn_bssid,
14380 struct dhd_pno_hotlist_params *hotlist_params)
14381 {
14382 dhd_info_t *dhd = DHD_DEV_INFO(dev);
14383 return (dhd_pno_set_for_hotlist(&dhd->pub, p_pfn_bssid, hotlist_params));
14384 }
14385 /* Linux wrapper to call common dhd_dev_pno_stop_for_batch */
14386 int
dhd_dev_pno_stop_for_batch(struct net_device * dev)14387 dhd_dev_pno_stop_for_batch(struct net_device *dev)
14388 {
14389 dhd_info_t *dhd = DHD_DEV_INFO(dev);
14390 return (dhd_pno_stop_for_batch(&dhd->pub));
14391 }
14392
14393 /* Linux wrapper to call common dhd_dev_pno_set_for_batch */
14394 int
dhd_dev_pno_set_for_batch(struct net_device * dev,struct dhd_pno_batch_params * batch_params)14395 dhd_dev_pno_set_for_batch(struct net_device *dev, struct dhd_pno_batch_params *batch_params)
14396 {
14397 dhd_info_t *dhd = DHD_DEV_INFO(dev);
14398 return (dhd_pno_set_for_batch(&dhd->pub, batch_params));
14399 }
14400
14401 /* Linux wrapper to call common dhd_dev_pno_get_for_batch */
14402 int
dhd_dev_pno_get_for_batch(struct net_device * dev,char * buf,int bufsize)14403 dhd_dev_pno_get_for_batch(struct net_device *dev, char *buf, int bufsize)
14404 {
14405 dhd_info_t *dhd = DHD_DEV_INFO(dev);
14406 return (dhd_pno_get_for_batch(&dhd->pub, buf, bufsize, PNO_STATUS_NORMAL));
14407 }
14408 #endif /* PNO_SUPPORT */
14409
14410 #if defined(PNO_SUPPORT)
14411 #ifdef GSCAN_SUPPORT
14412 bool
dhd_dev_is_legacy_pno_enabled(struct net_device * dev)14413 dhd_dev_is_legacy_pno_enabled(struct net_device *dev)
14414 {
14415 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14416 return (dhd_is_legacy_pno_enabled(&dhd->pub));
14417 }
14418
14419 int
dhd_dev_set_epno(struct net_device * dev)14420 dhd_dev_set_epno(struct net_device *dev)
14421 {
14422 dhd_info_t *dhd = DHD_DEV_INFO(dev);
14423 if (!dhd) {
14424 return BCME_ERROR;
14425 }
14426 return dhd_pno_set_epno(&dhd->pub);
14427 }
14428 int
dhd_dev_flush_fw_epno(struct net_device * dev)14429 dhd_dev_flush_fw_epno(struct net_device *dev)
14430 {
14431 dhd_info_t *dhd = DHD_DEV_INFO(dev);
14432 if (!dhd) {
14433 return BCME_ERROR;
14434 }
14435 return dhd_pno_flush_fw_epno(&dhd->pub);
14436 }
14437
14438 /* Linux wrapper to call common dhd_pno_set_cfg_gscan */
14439 int
dhd_dev_pno_set_cfg_gscan(struct net_device * dev,dhd_pno_gscan_cmd_cfg_t type,void * buf,bool flush)14440 dhd_dev_pno_set_cfg_gscan(struct net_device *dev, dhd_pno_gscan_cmd_cfg_t type,
14441 void *buf, bool flush)
14442 {
14443 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14444 return (dhd_pno_set_cfg_gscan(&dhd->pub, type, buf, flush));
14445 }
14446
14447 /* Linux wrapper to call common dhd_wait_batch_results_complete */
14448 int
dhd_dev_wait_batch_results_complete(struct net_device * dev)14449 dhd_dev_wait_batch_results_complete(struct net_device *dev)
14450 {
14451 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14452 return (dhd_wait_batch_results_complete(&dhd->pub));
14453 }
14454
14455 /* Linux wrapper to call common dhd_pno_lock_batch_results */
14456 int
dhd_dev_pno_lock_access_batch_results(struct net_device * dev)14457 dhd_dev_pno_lock_access_batch_results(struct net_device *dev)
14458 {
14459 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14460 return (dhd_pno_lock_batch_results(&dhd->pub));
14461 }
14462 /* Linux wrapper to call common dhd_pno_unlock_batch_results */
14463 void
dhd_dev_pno_unlock_access_batch_results(struct net_device * dev)14464 dhd_dev_pno_unlock_access_batch_results(struct net_device *dev)
14465 {
14466 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14467 return (dhd_pno_unlock_batch_results(&dhd->pub));
14468 }
14469
14470 /* Linux wrapper to call common dhd_pno_initiate_gscan_request */
14471 int
dhd_dev_pno_run_gscan(struct net_device * dev,bool run,bool flush)14472 dhd_dev_pno_run_gscan(struct net_device *dev, bool run, bool flush)
14473 {
14474 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14475 return (dhd_pno_initiate_gscan_request(&dhd->pub, run, flush));
14476 }
14477
14478 /* Linux wrapper to call common dhd_pno_enable_full_scan_result */
14479 int
dhd_dev_pno_enable_full_scan_result(struct net_device * dev,bool real_time_flag)14480 dhd_dev_pno_enable_full_scan_result(struct net_device *dev, bool real_time_flag)
14481 {
14482 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14483 return (dhd_pno_enable_full_scan_result(&dhd->pub, real_time_flag));
14484 }
14485
14486 /* Linux wrapper to call common dhd_handle_hotlist_scan_evt */
14487 void *
dhd_dev_hotlist_scan_event(struct net_device * dev,const void * data,int * send_evt_bytes,hotlist_type_t type,u32 * buf_len)14488 dhd_dev_hotlist_scan_event(struct net_device *dev,
14489 const void *data, int *send_evt_bytes, hotlist_type_t type, u32 *buf_len)
14490 {
14491 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14492 return (dhd_handle_hotlist_scan_evt(&dhd->pub, data, send_evt_bytes, type, buf_len));
14493 }
14494
14495 /* Linux wrapper to call common dhd_process_full_gscan_result */
14496 void *
dhd_dev_process_full_gscan_result(struct net_device * dev,const void * data,uint32 len,int * send_evt_bytes)14497 dhd_dev_process_full_gscan_result(struct net_device *dev,
14498 const void *data, uint32 len, int *send_evt_bytes)
14499 {
14500 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14501 return (dhd_process_full_gscan_result(&dhd->pub, data, len, send_evt_bytes));
14502 }
14503
14504 void
dhd_dev_gscan_hotlist_cache_cleanup(struct net_device * dev,hotlist_type_t type)14505 dhd_dev_gscan_hotlist_cache_cleanup(struct net_device *dev, hotlist_type_t type)
14506 {
14507 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14508 dhd_gscan_hotlist_cache_cleanup(&dhd->pub, type);
14509
14510 return;
14511 }
14512
14513 int
dhd_dev_gscan_batch_cache_cleanup(struct net_device * dev)14514 dhd_dev_gscan_batch_cache_cleanup(struct net_device *dev)
14515 {
14516 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14517 return (dhd_gscan_batch_cache_cleanup(&dhd->pub));
14518 }
14519
14520 /* Linux wrapper to call common dhd_retreive_batch_scan_results */
14521 int
dhd_dev_retrieve_batch_scan(struct net_device * dev)14522 dhd_dev_retrieve_batch_scan(struct net_device *dev)
14523 {
14524 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14525 return (dhd_retreive_batch_scan_results(&dhd->pub));
14526 }
14527
14528 /* Linux wrapper to call common dhd_pno_process_epno_result */
dhd_dev_process_epno_result(struct net_device * dev,const void * data,uint32 event,int * send_evt_bytes)14529 void * dhd_dev_process_epno_result(struct net_device *dev,
14530 const void *data, uint32 event, int *send_evt_bytes)
14531 {
14532 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14533 return (dhd_pno_process_epno_result(&dhd->pub, data, event, send_evt_bytes));
14534 }
14535
14536 int
dhd_dev_set_lazy_roam_cfg(struct net_device * dev,wlc_roam_exp_params_t * roam_param)14537 dhd_dev_set_lazy_roam_cfg(struct net_device *dev,
14538 wlc_roam_exp_params_t *roam_param)
14539 {
14540 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14541 wl_roam_exp_cfg_t roam_exp_cfg;
14542 int err;
14543
14544 if (!roam_param) {
14545 return BCME_BADARG;
14546 }
14547
14548 DHD_INFO(("a_band_boost_thr %d a_band_penalty_thr %d\n",
14549 roam_param->a_band_boost_threshold, roam_param->a_band_penalty_threshold));
14550 DHD_INFO(("a_band_boost_factor %d a_band_penalty_factor %d cur_bssid_boost %d\n",
14551 roam_param->a_band_boost_factor, roam_param->a_band_penalty_factor,
14552 roam_param->cur_bssid_boost));
14553 DHD_INFO(("alert_roam_trigger_thr %d a_band_max_boost %d\n",
14554 roam_param->alert_roam_trigger_threshold, roam_param->a_band_max_boost));
14555
14556 memcpy(&roam_exp_cfg.params, roam_param, sizeof(*roam_param));
14557 roam_exp_cfg.version = ROAM_EXP_CFG_VERSION;
14558 roam_exp_cfg.flags = ROAM_EXP_CFG_PRESENT;
14559 if (dhd->pub.lazy_roam_enable) {
14560 roam_exp_cfg.flags |= ROAM_EXP_ENABLE_FLAG;
14561 }
14562 err = dhd_iovar(&dhd->pub, 0, "roam_exp_params",
14563 (char *)&roam_exp_cfg, sizeof(roam_exp_cfg), NULL, 0,
14564 TRUE);
14565 if (err < 0) {
14566 DHD_ERROR(("%s : Failed to execute roam_exp_params %d\n", __FUNCTION__, err));
14567 }
14568 return err;
14569 }
14570
14571 int
dhd_dev_lazy_roam_enable(struct net_device * dev,uint32 enable)14572 dhd_dev_lazy_roam_enable(struct net_device *dev, uint32 enable)
14573 {
14574 int err;
14575 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14576 wl_roam_exp_cfg_t roam_exp_cfg;
14577
14578 memset(&roam_exp_cfg, 0, sizeof(roam_exp_cfg));
14579 roam_exp_cfg.version = ROAM_EXP_CFG_VERSION;
14580 if (enable) {
14581 roam_exp_cfg.flags = ROAM_EXP_ENABLE_FLAG;
14582 }
14583
14584 err = dhd_iovar(&dhd->pub, 0, "roam_exp_params",
14585 (char *)&roam_exp_cfg, sizeof(roam_exp_cfg), NULL, 0,
14586 TRUE);
14587 if (err < 0) {
14588 DHD_ERROR(("%s : Failed to execute roam_exp_params %d\n", __FUNCTION__, err));
14589 } else {
14590 dhd->pub.lazy_roam_enable = (enable != 0);
14591 }
14592 return err;
14593 }
14594
14595 int
dhd_dev_set_lazy_roam_bssid_pref(struct net_device * dev,wl_bssid_pref_cfg_t * bssid_pref,uint32 flush)14596 dhd_dev_set_lazy_roam_bssid_pref(struct net_device *dev,
14597 wl_bssid_pref_cfg_t *bssid_pref, uint32 flush)
14598 {
14599 int err;
14600 uint len;
14601 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14602
14603 bssid_pref->version = BSSID_PREF_LIST_VERSION;
14604 /* By default programming bssid pref flushes out old values */
14605 bssid_pref->flags = (flush && !bssid_pref->count) ? ROAM_EXP_CLEAR_BSSID_PREF: 0;
14606 len = sizeof(wl_bssid_pref_cfg_t);
14607 if (bssid_pref->count) {
14608 len += (bssid_pref->count - 1) * sizeof(wl_bssid_pref_list_t);
14609 }
14610 err = dhd_iovar(&dhd->pub, 0, "roam_exp_bssid_pref",
14611 (char *)bssid_pref, len, NULL, 0, TRUE);
14612 if (err != BCME_OK) {
14613 DHD_ERROR(("%s : Failed to execute roam_exp_bssid_pref %d\n", __FUNCTION__, err));
14614 }
14615 return err;
14616 }
14617 #endif /* GSCAN_SUPPORT */
14618
14619 #if defined(GSCAN_SUPPORT) || defined(ROAMEXP_SUPPORT)
14620 int
dhd_dev_set_blacklist_bssid(struct net_device * dev,maclist_t * blacklist,uint32 len,uint32 flush)14621 dhd_dev_set_blacklist_bssid(struct net_device *dev, maclist_t *blacklist,
14622 uint32 len, uint32 flush)
14623 {
14624 int err;
14625 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14626 int macmode;
14627
14628 if (blacklist) {
14629 err = dhd_wl_ioctl_cmd(&(dhd->pub), WLC_SET_MACLIST, (char *)blacklist,
14630 len, TRUE, 0);
14631 if (err != BCME_OK) {
14632 DHD_ERROR(("%s : WLC_SET_MACLIST failed %d\n", __FUNCTION__, err));
14633 return err;
14634 }
14635 }
14636 /* By default programming blacklist flushes out old values */
14637 macmode = (flush && !blacklist) ? WLC_MACMODE_DISABLED : WLC_MACMODE_DENY;
14638 err = dhd_wl_ioctl_cmd(&(dhd->pub), WLC_SET_MACMODE, (char *)&macmode,
14639 sizeof(macmode), TRUE, 0);
14640 if (err != BCME_OK) {
14641 DHD_ERROR(("%s : WLC_SET_MACMODE failed %d\n", __FUNCTION__, err));
14642 }
14643 return err;
14644 }
14645
14646 int
dhd_dev_set_whitelist_ssid(struct net_device * dev,wl_ssid_whitelist_t * ssid_whitelist,uint32 len,uint32 flush)14647 dhd_dev_set_whitelist_ssid(struct net_device *dev, wl_ssid_whitelist_t *ssid_whitelist,
14648 uint32 len, uint32 flush)
14649 {
14650 int err;
14651 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14652 wl_ssid_whitelist_t whitelist_ssid_flush;
14653
14654 if (!ssid_whitelist) {
14655 if (flush) {
14656 ssid_whitelist = &whitelist_ssid_flush;
14657 ssid_whitelist->ssid_count = 0;
14658 } else {
14659 DHD_ERROR(("%s : Nothing to do here\n", __FUNCTION__));
14660 return BCME_BADARG;
14661 }
14662 }
14663 ssid_whitelist->version = SSID_WHITELIST_VERSION;
14664 ssid_whitelist->flags = flush ? ROAM_EXP_CLEAR_SSID_WHITELIST : 0;
14665 err = dhd_iovar(&dhd->pub, 0, "roam_exp_ssid_whitelist", (char *)ssid_whitelist, len, NULL,
14666 0, TRUE);
14667 if (err != BCME_OK) {
14668 DHD_ERROR(("%s : Failed to execute roam_exp_bssid_pref %d\n", __FUNCTION__, err));
14669 }
14670 return err;
14671 }
14672 #endif /* GSCAN_SUPPORT || ROAMEXP_SUPPORT */
14673
14674 #if defined(GSCAN_SUPPORT) || defined(DHD_GET_VALID_CHANNELS)
14675 /* Linux wrapper to call common dhd_pno_get_gscan */
14676 void *
dhd_dev_pno_get_gscan(struct net_device * dev,dhd_pno_gscan_cmd_cfg_t type,void * info,uint32 * len)14677 dhd_dev_pno_get_gscan(struct net_device *dev, dhd_pno_gscan_cmd_cfg_t type,
14678 void *info, uint32 *len)
14679 {
14680 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14681 return (dhd_pno_get_gscan(&dhd->pub, type, info, len));
14682 }
14683 #endif /* GSCAN_SUPPORT || DHD_GET_VALID_CHANNELS */
14684 #endif // endif
14685
14686 #ifdef RSSI_MONITOR_SUPPORT
14687 int
dhd_dev_set_rssi_monitor_cfg(struct net_device * dev,int start,int8 max_rssi,int8 min_rssi)14688 dhd_dev_set_rssi_monitor_cfg(struct net_device *dev, int start,
14689 int8 max_rssi, int8 min_rssi)
14690 {
14691 int err;
14692 wl_rssi_monitor_cfg_t rssi_monitor;
14693 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14694 rssi_monitor.version = RSSI_MONITOR_VERSION;
14695 rssi_monitor.max_rssi = max_rssi;
14696 rssi_monitor.min_rssi = min_rssi;
14697 rssi_monitor.flags = start ? 0: RSSI_MONITOR_STOP;
14698 err = dhd_iovar(&dhd->pub, 0, "rssi_monitor", (char *)&rssi_monitor, sizeof(rssi_monitor),
14699 NULL, 0, TRUE);
14700 if (err < 0 && err != BCME_UNSUPPORTED) {
14701 DHD_ERROR(("%s : Failed to execute rssi_monitor %d\n", __FUNCTION__, err));
14702 }
14703 return err;
14704 }
14705 #endif /* RSSI_MONITOR_SUPPORT */
14706
14707 #ifdef DHDTCPACK_SUPPRESS
14708 int
dhd_dev_set_tcpack_sup_mode_cfg(struct net_device * dev,uint8 enable)14709 dhd_dev_set_tcpack_sup_mode_cfg(struct net_device *dev, uint8 enable)
14710 {
14711 int err;
14712 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14713 err = dhd_tcpack_suppress_set(&dhd->pub, enable);
14714 if (err != BCME_OK) {
14715 DHD_ERROR(("%s : Failed to set tcpack_suppress mode: %d\n", __FUNCTION__, err));
14716 }
14717 return err;
14718 }
14719 #endif /* DHDTCPACK_SUPPRESS */
14720
14721 int
dhd_dev_cfg_rand_mac_oui(struct net_device * dev,uint8 * oui)14722 dhd_dev_cfg_rand_mac_oui(struct net_device *dev, uint8 *oui)
14723 {
14724 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14725 dhd_pub_t *dhdp = &dhd->pub;
14726
14727 if (!dhdp || !oui) {
14728 DHD_ERROR(("NULL POINTER : %s\n",
14729 __FUNCTION__));
14730 return BCME_ERROR;
14731 }
14732 if (ETHER_ISMULTI(oui)) {
14733 DHD_ERROR(("Expected unicast OUI\n"));
14734 return BCME_ERROR;
14735 } else {
14736 uint8 *rand_mac_oui = dhdp->rand_mac_oui;
14737 memcpy(rand_mac_oui, oui, DOT11_OUI_LEN);
14738 DHD_ERROR(("Random MAC OUI to be used - "MACOUIDBG"\n",
14739 MACOUI2STRDBG(rand_mac_oui)));
14740 }
14741 return BCME_OK;
14742 }
14743
14744 int
dhd_set_rand_mac_oui(dhd_pub_t * dhd)14745 dhd_set_rand_mac_oui(dhd_pub_t *dhd)
14746 {
14747 int err;
14748 wl_pfn_macaddr_cfg_t wl_cfg;
14749 uint8 *rand_mac_oui = dhd->rand_mac_oui;
14750
14751 memset(&wl_cfg.macaddr, 0, ETHER_ADDR_LEN);
14752 memcpy(&wl_cfg.macaddr, rand_mac_oui, DOT11_OUI_LEN);
14753 wl_cfg.version = WL_PFN_MACADDR_CFG_VER;
14754 if (ETHER_ISNULLADDR(&wl_cfg.macaddr)) {
14755 wl_cfg.flags = 0;
14756 } else {
14757 wl_cfg.flags = (WL_PFN_MAC_OUI_ONLY_MASK | WL_PFN_SET_MAC_UNASSOC_MASK);
14758 }
14759
14760 DHD_ERROR(("Setting rand mac oui to FW - "MACOUIDBG"\n",
14761 MACOUI2STRDBG(rand_mac_oui)));
14762
14763 err = dhd_iovar(dhd, 0, "pfn_macaddr", (char *)&wl_cfg, sizeof(wl_cfg), NULL, 0, TRUE);
14764 if (err < 0) {
14765 DHD_ERROR(("%s : failed to execute pfn_macaddr %d\n", __FUNCTION__, err));
14766 }
14767 return err;
14768 }
14769
14770 #if defined(RTT_SUPPORT) && defined(WL_CFG80211)
14771 /* Linux wrapper to call common dhd_pno_set_cfg_gscan */
14772 int
dhd_dev_rtt_set_cfg(struct net_device * dev,void * buf)14773 dhd_dev_rtt_set_cfg(struct net_device *dev, void *buf)
14774 {
14775 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14776 return (dhd_rtt_set_cfg(&dhd->pub, buf));
14777 }
14778
14779 int
dhd_dev_rtt_cancel_cfg(struct net_device * dev,struct ether_addr * mac_list,int mac_cnt)14780 dhd_dev_rtt_cancel_cfg(struct net_device *dev, struct ether_addr *mac_list, int mac_cnt)
14781 {
14782 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14783 return (dhd_rtt_stop(&dhd->pub, mac_list, mac_cnt));
14784 }
14785
14786 int
dhd_dev_rtt_register_noti_callback(struct net_device * dev,void * ctx,dhd_rtt_compl_noti_fn noti_fn)14787 dhd_dev_rtt_register_noti_callback(struct net_device *dev, void *ctx, dhd_rtt_compl_noti_fn noti_fn)
14788 {
14789 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14790 return (dhd_rtt_register_noti_callback(&dhd->pub, ctx, noti_fn));
14791 }
14792
14793 int
dhd_dev_rtt_unregister_noti_callback(struct net_device * dev,dhd_rtt_compl_noti_fn noti_fn)14794 dhd_dev_rtt_unregister_noti_callback(struct net_device *dev, dhd_rtt_compl_noti_fn noti_fn)
14795 {
14796 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14797 return (dhd_rtt_unregister_noti_callback(&dhd->pub, noti_fn));
14798 }
14799
14800 int
dhd_dev_rtt_capability(struct net_device * dev,rtt_capabilities_t * capa)14801 dhd_dev_rtt_capability(struct net_device *dev, rtt_capabilities_t *capa)
14802 {
14803 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14804 return (dhd_rtt_capability(&dhd->pub, capa));
14805 }
14806
14807 int
dhd_dev_rtt_avail_channel(struct net_device * dev,wifi_channel_info * channel_info)14808 dhd_dev_rtt_avail_channel(struct net_device *dev, wifi_channel_info *channel_info)
14809 {
14810 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14811 return (dhd_rtt_avail_channel(&dhd->pub, channel_info));
14812 }
14813
14814 int
dhd_dev_rtt_enable_responder(struct net_device * dev,wifi_channel_info * channel_info)14815 dhd_dev_rtt_enable_responder(struct net_device *dev, wifi_channel_info *channel_info)
14816 {
14817 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14818 return (dhd_rtt_enable_responder(&dhd->pub, channel_info));
14819 }
14820
dhd_dev_rtt_cancel_responder(struct net_device * dev)14821 int dhd_dev_rtt_cancel_responder(struct net_device *dev)
14822 {
14823 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
14824 return (dhd_rtt_cancel_responder(&dhd->pub));
14825 }
14826
14827 #endif /* RTT_SUPPORT */
14828
14829 #ifdef KEEP_ALIVE
14830 #define KA_TEMP_BUF_SIZE 512
14831 #define KA_FRAME_SIZE 300
14832
14833 int
dhd_dev_start_mkeep_alive(dhd_pub_t * dhd_pub,uint8 mkeep_alive_id,uint8 * ip_pkt,uint16 ip_pkt_len,uint8 * src_mac,uint8 * dst_mac,uint32 period_msec)14834 dhd_dev_start_mkeep_alive(dhd_pub_t *dhd_pub, uint8 mkeep_alive_id, uint8 *ip_pkt,
14835 uint16 ip_pkt_len, uint8* src_mac, uint8* dst_mac, uint32 period_msec)
14836 {
14837 const int ETHERTYPE_LEN = 2;
14838 char *pbuf = NULL;
14839 const char *str;
14840 wl_mkeep_alive_pkt_t mkeep_alive_pkt;
14841 wl_mkeep_alive_pkt_t *mkeep_alive_pktp = NULL;
14842 int buf_len = 0;
14843 int str_len = 0;
14844 int res = BCME_ERROR;
14845 int len_bytes = 0;
14846 int i = 0;
14847
14848 /* ether frame to have both max IP pkt (256 bytes) and ether header */
14849 char *pmac_frame = NULL;
14850 char *pmac_frame_begin = NULL;
14851
14852 /*
14853 * The mkeep_alive packet is for STA interface only; if the bss is configured as AP,
14854 * dongle shall reject a mkeep_alive request.
14855 */
14856 if (!dhd_support_sta_mode(dhd_pub))
14857 return res;
14858
14859 DHD_TRACE(("%s execution\n", __FUNCTION__));
14860
14861 if ((pbuf = MALLOCZ(dhd_pub->osh, KA_TEMP_BUF_SIZE)) == NULL) {
14862 DHD_ERROR(("failed to allocate buf with size %d\n", KA_TEMP_BUF_SIZE));
14863 res = BCME_NOMEM;
14864 return res;
14865 }
14866
14867 if ((pmac_frame = MALLOCZ(dhd_pub->osh, KA_FRAME_SIZE)) == NULL) {
14868 DHD_ERROR(("failed to allocate mac_frame with size %d\n", KA_FRAME_SIZE));
14869 res = BCME_NOMEM;
14870 goto exit;
14871 }
14872 pmac_frame_begin = pmac_frame;
14873
14874 /*
14875 * Get current mkeep-alive status.
14876 */
14877 res = dhd_iovar(dhd_pub, 0, "mkeep_alive", &mkeep_alive_id, sizeof(mkeep_alive_id), pbuf,
14878 KA_TEMP_BUF_SIZE, FALSE);
14879 if (res < 0) {
14880 DHD_ERROR(("%s: Get mkeep_alive failed (error=%d)\n", __FUNCTION__, res));
14881 goto exit;
14882 } else {
14883 /* Check available ID whether it is occupied */
14884 mkeep_alive_pktp = (wl_mkeep_alive_pkt_t *) pbuf;
14885 if (dtoh32(mkeep_alive_pktp->period_msec != 0)) {
14886 DHD_ERROR(("%s: Get mkeep_alive failed, ID %u is in use.\n",
14887 __FUNCTION__, mkeep_alive_id));
14888
14889 /* Current occupied ID info */
14890 DHD_ERROR(("%s: mkeep_alive\n", __FUNCTION__));
14891 DHD_ERROR((" Id : %d\n"
14892 " Period: %d msec\n"
14893 " Length: %d\n"
14894 " Packet: 0x",
14895 mkeep_alive_pktp->keep_alive_id,
14896 dtoh32(mkeep_alive_pktp->period_msec),
14897 dtoh16(mkeep_alive_pktp->len_bytes)));
14898
14899 for (i = 0; i < mkeep_alive_pktp->len_bytes; i++) {
14900 DHD_ERROR(("%02x", mkeep_alive_pktp->data[i]));
14901 }
14902 DHD_ERROR(("\n"));
14903
14904 res = BCME_NOTFOUND;
14905 goto exit;
14906 }
14907 }
14908
14909 /* Request the specified ID */
14910 memset(&mkeep_alive_pkt, 0, sizeof(wl_mkeep_alive_pkt_t));
14911 memset(pbuf, 0, KA_TEMP_BUF_SIZE);
14912 str = "mkeep_alive";
14913 str_len = strlen(str);
14914 strncpy(pbuf, str, str_len);
14915 pbuf[str_len] = '\0';
14916
14917 mkeep_alive_pktp = (wl_mkeep_alive_pkt_t *) (pbuf + str_len + 1);
14918 mkeep_alive_pkt.period_msec = htod32(period_msec);
14919 buf_len = str_len + 1;
14920 mkeep_alive_pkt.version = htod16(WL_MKEEP_ALIVE_VERSION);
14921 mkeep_alive_pkt.length = htod16(WL_MKEEP_ALIVE_FIXED_LEN);
14922
14923 /* ID assigned */
14924 mkeep_alive_pkt.keep_alive_id = mkeep_alive_id;
14925
14926 buf_len += WL_MKEEP_ALIVE_FIXED_LEN;
14927
14928 /*
14929 * Build up Ethernet Frame
14930 */
14931
14932 /* Mapping dest mac addr */
14933 memcpy(pmac_frame, dst_mac, ETHER_ADDR_LEN);
14934 pmac_frame += ETHER_ADDR_LEN;
14935
14936 /* Mapping src mac addr */
14937 memcpy(pmac_frame, src_mac, ETHER_ADDR_LEN);
14938 pmac_frame += ETHER_ADDR_LEN;
14939
14940 /* Mapping Ethernet type (ETHERTYPE_IP: 0x0800) */
14941 *(pmac_frame++) = 0x08;
14942 *(pmac_frame++) = 0x00;
14943
14944 /* Mapping IP pkt */
14945 memcpy(pmac_frame, ip_pkt, ip_pkt_len);
14946 pmac_frame += ip_pkt_len;
14947
14948 /*
14949 * Length of ether frame (assume to be all hexa bytes)
14950 * = src mac + dst mac + ether type + ip pkt len
14951 */
14952 len_bytes = ETHER_ADDR_LEN*2 + ETHERTYPE_LEN + ip_pkt_len;
14953 memcpy(mkeep_alive_pktp->data, pmac_frame_begin, len_bytes);
14954 buf_len += len_bytes;
14955 mkeep_alive_pkt.len_bytes = htod16(len_bytes);
14956
14957 /*
14958 * Keep-alive attributes are set in local variable (mkeep_alive_pkt), and
14959 * then memcpy'ed into buffer (mkeep_alive_pktp) since there is no
14960 * guarantee that the buffer is properly aligned.
14961 */
14962 memcpy((char *)mkeep_alive_pktp, &mkeep_alive_pkt, WL_MKEEP_ALIVE_FIXED_LEN);
14963
14964 res = dhd_wl_ioctl_cmd(dhd_pub, WLC_SET_VAR, pbuf, buf_len, TRUE, 0);
14965 exit:
14966 if (pmac_frame_begin) {
14967 MFREE(dhd_pub->osh, pmac_frame_begin, KA_FRAME_SIZE);
14968 pmac_frame_begin = NULL;
14969 }
14970 if (pbuf) {
14971 MFREE(dhd_pub->osh, pbuf, KA_TEMP_BUF_SIZE);
14972 pbuf = NULL;
14973 }
14974 return res;
14975 }
14976
14977 int
dhd_dev_stop_mkeep_alive(dhd_pub_t * dhd_pub,uint8 mkeep_alive_id)14978 dhd_dev_stop_mkeep_alive(dhd_pub_t *dhd_pub, uint8 mkeep_alive_id)
14979 {
14980 char *pbuf = NULL;
14981 wl_mkeep_alive_pkt_t mkeep_alive_pkt;
14982 wl_mkeep_alive_pkt_t *mkeep_alive_pktp = NULL;
14983 int res = BCME_ERROR;
14984 int i = 0;
14985
14986 /*
14987 * The mkeep_alive packet is for STA interface only; if the bss is configured as AP,
14988 * dongle shall reject a mkeep_alive request.
14989 */
14990 if (!dhd_support_sta_mode(dhd_pub))
14991 return res;
14992
14993 DHD_TRACE(("%s execution\n", __FUNCTION__));
14994
14995 /*
14996 * Get current mkeep-alive status. Skip ID 0 which is being used for NULL pkt.
14997 */
14998 if ((pbuf = MALLOC(dhd_pub->osh, KA_TEMP_BUF_SIZE)) == NULL) {
14999 DHD_ERROR(("failed to allocate buf with size %d\n", KA_TEMP_BUF_SIZE));
15000 return res;
15001 }
15002
15003 res = dhd_iovar(dhd_pub, 0, "mkeep_alive", &mkeep_alive_id,
15004 sizeof(mkeep_alive_id), pbuf, KA_TEMP_BUF_SIZE, FALSE);
15005 if (res < 0) {
15006 DHD_ERROR(("%s: Get mkeep_alive failed (error=%d)\n", __FUNCTION__, res));
15007 goto exit;
15008 } else {
15009 /* Check occupied ID */
15010 mkeep_alive_pktp = (wl_mkeep_alive_pkt_t *) pbuf;
15011 DHD_INFO(("%s: mkeep_alive\n", __FUNCTION__));
15012 DHD_INFO((" Id : %d\n"
15013 " Period: %d msec\n"
15014 " Length: %d\n"
15015 " Packet: 0x",
15016 mkeep_alive_pktp->keep_alive_id,
15017 dtoh32(mkeep_alive_pktp->period_msec),
15018 dtoh16(mkeep_alive_pktp->len_bytes)));
15019
15020 for (i = 0; i < mkeep_alive_pktp->len_bytes; i++) {
15021 DHD_INFO(("%02x", mkeep_alive_pktp->data[i]));
15022 }
15023 DHD_INFO(("\n"));
15024 }
15025
15026 /* Make it stop if available */
15027 if (dtoh32(mkeep_alive_pktp->period_msec != 0)) {
15028 DHD_INFO(("stop mkeep_alive on ID %d\n", mkeep_alive_id));
15029 memset(&mkeep_alive_pkt, 0, sizeof(wl_mkeep_alive_pkt_t));
15030
15031 mkeep_alive_pkt.period_msec = 0;
15032 mkeep_alive_pkt.version = htod16(WL_MKEEP_ALIVE_VERSION);
15033 mkeep_alive_pkt.length = htod16(WL_MKEEP_ALIVE_FIXED_LEN);
15034 mkeep_alive_pkt.keep_alive_id = mkeep_alive_id;
15035
15036 res = dhd_iovar(dhd_pub, 0, "mkeep_alive",
15037 (char *)&mkeep_alive_pkt,
15038 WL_MKEEP_ALIVE_FIXED_LEN, NULL, 0, TRUE);
15039 } else {
15040 DHD_ERROR(("%s: ID %u does not exist.\n", __FUNCTION__, mkeep_alive_id));
15041 res = BCME_NOTFOUND;
15042 }
15043 exit:
15044 if (pbuf) {
15045 MFREE(dhd_pub->osh, pbuf, KA_TEMP_BUF_SIZE);
15046 pbuf = NULL;
15047 }
15048 return res;
15049 }
15050 #endif /* KEEP_ALIVE */
15051
15052 #if defined(PKT_FILTER_SUPPORT) && defined(APF)
_dhd_apf_lock_local(dhd_info_t * dhd)15053 static void _dhd_apf_lock_local(dhd_info_t *dhd)
15054 {
15055 if (dhd) {
15056 mutex_lock(&dhd->dhd_apf_mutex);
15057 }
15058 }
15059
_dhd_apf_unlock_local(dhd_info_t * dhd)15060 static void _dhd_apf_unlock_local(dhd_info_t *dhd)
15061 {
15062 if (dhd) {
15063 mutex_unlock(&dhd->dhd_apf_mutex);
15064 }
15065 }
15066
15067 static int
__dhd_apf_add_filter(struct net_device * ndev,uint32 filter_id,u8 * program,uint32 program_len)15068 __dhd_apf_add_filter(struct net_device *ndev, uint32 filter_id,
15069 u8* program, uint32 program_len)
15070 {
15071 dhd_info_t *dhd = DHD_DEV_INFO(ndev);
15072 dhd_pub_t *dhdp = &dhd->pub;
15073 wl_pkt_filter_t * pkt_filterp;
15074 wl_apf_program_t *apf_program;
15075 char *buf;
15076 u32 cmd_len, buf_len;
15077 int ifidx, ret;
15078 char cmd[] = "pkt_filter_add";
15079
15080 ifidx = dhd_net2idx(dhd, ndev);
15081 if (ifidx == DHD_BAD_IF) {
15082 DHD_ERROR(("%s: bad ifidx\n", __FUNCTION__));
15083 return -ENODEV;
15084 }
15085
15086 cmd_len = sizeof(cmd);
15087
15088 /* Check if the program_len is more than the expected len
15089 * and if the program is NULL return from here.
15090 */
15091 if ((program_len > WL_APF_PROGRAM_MAX_SIZE) || (program == NULL)) {
15092 DHD_ERROR(("%s Invalid program_len: %d, program: %pK\n",
15093 __FUNCTION__, program_len, program));
15094 return -EINVAL;
15095 }
15096 buf_len = cmd_len + WL_PKT_FILTER_FIXED_LEN +
15097 WL_APF_PROGRAM_FIXED_LEN + program_len;
15098
15099 buf = MALLOCZ(dhdp->osh, buf_len);
15100 if (unlikely(!buf)) {
15101 DHD_ERROR(("%s: MALLOC failure, %d bytes\n", __FUNCTION__, buf_len));
15102 return -ENOMEM;
15103 }
15104
15105 memcpy(buf, cmd, cmd_len);
15106
15107 pkt_filterp = (wl_pkt_filter_t *) (buf + cmd_len);
15108 pkt_filterp->id = htod32(filter_id);
15109 pkt_filterp->negate_match = htod32(FALSE);
15110 pkt_filterp->type = htod32(WL_PKT_FILTER_TYPE_APF_MATCH);
15111
15112 apf_program = &pkt_filterp->u.apf_program;
15113 apf_program->version = htod16(WL_APF_INTERNAL_VERSION);
15114 apf_program->instr_len = htod16(program_len);
15115 memcpy(apf_program->instrs, program, program_len);
15116
15117 ret = dhd_wl_ioctl_cmd(dhdp, WLC_SET_VAR, buf, buf_len, TRUE, ifidx);
15118 if (unlikely(ret)) {
15119 DHD_ERROR(("%s: failed to add APF filter, id=%d, ret=%d\n",
15120 __FUNCTION__, filter_id, ret));
15121 }
15122
15123 if (buf) {
15124 MFREE(dhdp->osh, buf, buf_len);
15125 }
15126 return ret;
15127 }
15128
15129 static int
__dhd_apf_config_filter(struct net_device * ndev,uint32 filter_id,uint32 mode,uint32 enable)15130 __dhd_apf_config_filter(struct net_device *ndev, uint32 filter_id,
15131 uint32 mode, uint32 enable)
15132 {
15133 dhd_info_t *dhd = DHD_DEV_INFO(ndev);
15134 dhd_pub_t *dhdp = &dhd->pub;
15135 wl_pkt_filter_enable_t * pkt_filterp;
15136 char *buf;
15137 u32 cmd_len, buf_len;
15138 int ifidx, ret;
15139 char cmd[] = "pkt_filter_enable";
15140
15141 ifidx = dhd_net2idx(dhd, ndev);
15142 if (ifidx == DHD_BAD_IF) {
15143 DHD_ERROR(("%s: bad ifidx\n", __FUNCTION__));
15144 return -ENODEV;
15145 }
15146
15147 cmd_len = sizeof(cmd);
15148 buf_len = cmd_len + sizeof(*pkt_filterp);
15149
15150 buf = MALLOCZ(dhdp->osh, buf_len);
15151 if (unlikely(!buf)) {
15152 DHD_ERROR(("%s: MALLOC failure, %d bytes\n", __FUNCTION__, buf_len));
15153 return -ENOMEM;
15154 }
15155
15156 memcpy(buf, cmd, cmd_len);
15157
15158 pkt_filterp = (wl_pkt_filter_enable_t *) (buf + cmd_len);
15159 pkt_filterp->id = htod32(filter_id);
15160 pkt_filterp->enable = htod32(enable);
15161
15162 ret = dhd_wl_ioctl_cmd(dhdp, WLC_SET_VAR, buf, buf_len, TRUE, ifidx);
15163 if (unlikely(ret)) {
15164 DHD_ERROR(("%s: failed to enable APF filter, id=%d, ret=%d\n",
15165 __FUNCTION__, filter_id, ret));
15166 goto exit;
15167 }
15168
15169 ret = dhd_wl_ioctl_set_intiovar(dhdp, "pkt_filter_mode", dhd_master_mode,
15170 WLC_SET_VAR, TRUE, ifidx);
15171 if (unlikely(ret)) {
15172 DHD_ERROR(("%s: failed to set APF filter mode, id=%d, ret=%d\n",
15173 __FUNCTION__, filter_id, ret));
15174 }
15175
15176 exit:
15177 if (buf) {
15178 MFREE(dhdp->osh, buf, buf_len);
15179 }
15180 return ret;
15181 }
15182
15183 static int
__dhd_apf_delete_filter(struct net_device * ndev,uint32 filter_id)15184 __dhd_apf_delete_filter(struct net_device *ndev, uint32 filter_id)
15185 {
15186 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(ndev);
15187 dhd_pub_t *dhdp = &dhd->pub;
15188 int ifidx, ret;
15189
15190 ifidx = dhd_net2idx(dhd, ndev);
15191 if (ifidx == DHD_BAD_IF) {
15192 DHD_ERROR(("%s: bad ifidx\n", __FUNCTION__));
15193 return -ENODEV;
15194 }
15195
15196 ret = dhd_wl_ioctl_set_intiovar(dhdp, "pkt_filter_delete",
15197 htod32(filter_id), WLC_SET_VAR, TRUE, ifidx);
15198 if (unlikely(ret)) {
15199 DHD_ERROR(("%s: failed to delete APF filter, id=%d, ret=%d\n",
15200 __FUNCTION__, filter_id, ret));
15201 }
15202
15203 return ret;
15204 }
15205
dhd_apf_lock(struct net_device * dev)15206 void dhd_apf_lock(struct net_device *dev)
15207 {
15208 dhd_info_t *dhd = DHD_DEV_INFO(dev);
15209 _dhd_apf_lock_local(dhd);
15210 }
15211
dhd_apf_unlock(struct net_device * dev)15212 void dhd_apf_unlock(struct net_device *dev)
15213 {
15214 dhd_info_t *dhd = DHD_DEV_INFO(dev);
15215 _dhd_apf_unlock_local(dhd);
15216 }
15217
15218 int
dhd_dev_apf_get_version(struct net_device * ndev,uint32 * version)15219 dhd_dev_apf_get_version(struct net_device *ndev, uint32 *version)
15220 {
15221 dhd_info_t *dhd = DHD_DEV_INFO(ndev);
15222 dhd_pub_t *dhdp = &dhd->pub;
15223 int ifidx, ret;
15224
15225 if (!FW_SUPPORTED(dhdp, apf)) {
15226 DHD_ERROR(("%s: firmware doesn't support APF\n", __FUNCTION__));
15227
15228 /*
15229 * Notify Android framework that APF is not supported by setting
15230 * version as zero.
15231 */
15232 *version = 0;
15233 return BCME_OK;
15234 }
15235
15236 ifidx = dhd_net2idx(dhd, ndev);
15237 if (ifidx == DHD_BAD_IF) {
15238 DHD_ERROR(("%s: bad ifidx\n", __FUNCTION__));
15239 return -ENODEV;
15240 }
15241
15242 ret = dhd_wl_ioctl_get_intiovar(dhdp, "apf_ver", version,
15243 WLC_GET_VAR, FALSE, ifidx);
15244 if (unlikely(ret)) {
15245 DHD_ERROR(("%s: failed to get APF version, ret=%d\n",
15246 __FUNCTION__, ret));
15247 }
15248
15249 return ret;
15250 }
15251
15252 int
dhd_dev_apf_get_max_len(struct net_device * ndev,uint32 * max_len)15253 dhd_dev_apf_get_max_len(struct net_device *ndev, uint32 *max_len)
15254 {
15255 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(ndev);
15256 dhd_pub_t *dhdp = &dhd->pub;
15257 int ifidx, ret;
15258
15259 if (!FW_SUPPORTED(dhdp, apf)) {
15260 DHD_ERROR(("%s: firmware doesn't support APF\n", __FUNCTION__));
15261 *max_len = 0;
15262 return BCME_OK;
15263 }
15264
15265 ifidx = dhd_net2idx(dhd, ndev);
15266 if (ifidx == DHD_BAD_IF) {
15267 DHD_ERROR(("%s bad ifidx\n", __FUNCTION__));
15268 return -ENODEV;
15269 }
15270
15271 ret = dhd_wl_ioctl_get_intiovar(dhdp, "apf_size_limit", max_len,
15272 WLC_GET_VAR, FALSE, ifidx);
15273 if (unlikely(ret)) {
15274 DHD_ERROR(("%s: failed to get APF size limit, ret=%d\n",
15275 __FUNCTION__, ret));
15276 }
15277
15278 return ret;
15279 }
15280
15281 int
dhd_dev_apf_add_filter(struct net_device * ndev,u8 * program,uint32 program_len)15282 dhd_dev_apf_add_filter(struct net_device *ndev, u8* program,
15283 uint32 program_len)
15284 {
15285 dhd_info_t *dhd = DHD_DEV_INFO(ndev);
15286 dhd_pub_t *dhdp = &dhd->pub;
15287 int ret;
15288
15289 DHD_APF_LOCK(ndev);
15290
15291 /* delete, if filter already exists */
15292 if (dhdp->apf_set) {
15293 ret = __dhd_apf_delete_filter(ndev, PKT_FILTER_APF_ID);
15294 if (unlikely(ret)) {
15295 goto exit;
15296 }
15297 dhdp->apf_set = FALSE;
15298 }
15299
15300 ret = __dhd_apf_add_filter(ndev, PKT_FILTER_APF_ID, program, program_len);
15301 if (ret) {
15302 goto exit;
15303 }
15304 dhdp->apf_set = TRUE;
15305
15306 if (dhdp->in_suspend && dhdp->apf_set && !(dhdp->op_mode & DHD_FLAG_HOSTAP_MODE)) {
15307 /* Driver is still in (early) suspend state, enable APF filter back */
15308 ret = __dhd_apf_config_filter(ndev, PKT_FILTER_APF_ID,
15309 PKT_FILTER_MODE_FORWARD_ON_MATCH, TRUE);
15310 }
15311 exit:
15312 DHD_APF_UNLOCK(ndev);
15313
15314 return ret;
15315 }
15316
15317 int
dhd_dev_apf_enable_filter(struct net_device * ndev)15318 dhd_dev_apf_enable_filter(struct net_device *ndev)
15319 {
15320 dhd_info_t *dhd = DHD_DEV_INFO(ndev);
15321 dhd_pub_t *dhdp = &dhd->pub;
15322 int ret = 0;
15323 bool nan_dp_active = false;
15324
15325 DHD_APF_LOCK(ndev);
15326 #ifdef WL_NAN
15327 nan_dp_active = wl_cfgnan_is_dp_active(ndev);
15328 #endif /* WL_NAN */
15329 if (dhdp->apf_set && (!(dhdp->op_mode & DHD_FLAG_HOSTAP_MODE) &&
15330 !nan_dp_active)) {
15331 ret = __dhd_apf_config_filter(ndev, PKT_FILTER_APF_ID,
15332 PKT_FILTER_MODE_FORWARD_ON_MATCH, TRUE);
15333 }
15334
15335 DHD_APF_UNLOCK(ndev);
15336
15337 return ret;
15338 }
15339
15340 int
dhd_dev_apf_disable_filter(struct net_device * ndev)15341 dhd_dev_apf_disable_filter(struct net_device *ndev)
15342 {
15343 dhd_info_t *dhd = DHD_DEV_INFO(ndev);
15344 dhd_pub_t *dhdp = &dhd->pub;
15345 int ret = 0;
15346
15347 DHD_APF_LOCK(ndev);
15348
15349 if (dhdp->apf_set) {
15350 ret = __dhd_apf_config_filter(ndev, PKT_FILTER_APF_ID,
15351 PKT_FILTER_MODE_FORWARD_ON_MATCH, FALSE);
15352 }
15353
15354 DHD_APF_UNLOCK(ndev);
15355
15356 return ret;
15357 }
15358
15359 int
dhd_dev_apf_delete_filter(struct net_device * ndev)15360 dhd_dev_apf_delete_filter(struct net_device *ndev)
15361 {
15362 dhd_info_t *dhd = DHD_DEV_INFO(ndev);
15363 dhd_pub_t *dhdp = &dhd->pub;
15364 int ret = 0;
15365
15366 DHD_APF_LOCK(ndev);
15367
15368 if (dhdp->apf_set) {
15369 ret = __dhd_apf_delete_filter(ndev, PKT_FILTER_APF_ID);
15370 if (!ret) {
15371 dhdp->apf_set = FALSE;
15372 }
15373 }
15374
15375 DHD_APF_UNLOCK(ndev);
15376
15377 return ret;
15378 }
15379 #endif /* PKT_FILTER_SUPPORT && APF */
15380
dhd_hang_process(struct work_struct * work_data)15381 static void dhd_hang_process(struct work_struct *work_data)
15382 {
15383 struct net_device *dev;
15384 #ifdef IFACE_HANG_FORCE_DEV_CLOSE
15385 struct net_device *ndev;
15386 uint8 i = 0;
15387 #endif /* IFACE_HANG_FORCE_DEV_CLOSE */
15388 /* Ignore compiler warnings due to -Werror=cast-qual */
15389 #if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
15390 #pragma GCC diagnostic push
15391 #pragma GCC diagnostic ignored "-Wcast-qual"
15392 #endif // endif
15393 struct dhd_info *dhd =
15394 container_of(work_data, dhd_info_t, dhd_hang_process_work);
15395 #if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
15396 #pragma GCC diagnostic pop
15397 #endif // endif
15398
15399 if (!dhd || !dhd->iflist[0])
15400 return;
15401 dev = dhd->iflist[0]->net;
15402
15403 if (dev) {
15404 #if defined(WL_WIRELESS_EXT)
15405 wl_iw_send_priv_event(dev, "HANG");
15406 #endif // endif
15407 #if defined(WL_CFG80211)
15408 wl_cfg80211_hang(dev, WLAN_REASON_UNSPECIFIED);
15409 #endif // endif
15410 }
15411 #ifdef IFACE_HANG_FORCE_DEV_CLOSE
15412 /*
15413 * For HW2, dev_close need to be done to recover
15414 * from upper layer after hang. For Interposer skip
15415 * dev_close so that dhd iovars can be used to take
15416 * socramdump after crash, also skip for HW4 as
15417 * handling of hang event is different
15418 */
15419
15420 rtnl_lock();
15421 for (i = 0; i < DHD_MAX_IFS; i++) {
15422 ndev = dhd->iflist[i] ? dhd->iflist[i]->net : NULL;
15423 if (ndev && (ndev->flags & IFF_UP)) {
15424 DHD_ERROR(("ndev->name : %s dev close\n",
15425 ndev->name));
15426 dev_close(ndev);
15427 }
15428 }
15429 rtnl_unlock();
15430
15431 #ifdef CONFIG_AP6XXX_WIFI6_HDF
15432 OSL_SLEEP(500);
15433 BDH6_ResetDriver();
15434 #endif
15435 #endif /* IFACE_HANG_FORCE_DEV_CLOSE */
15436 }
15437
15438 #ifdef EXYNOS_PCIE_LINKDOWN_RECOVERY
15439 extern dhd_pub_t *link_recovery;
dhd_host_recover_link(void)15440 void dhd_host_recover_link(void)
15441 {
15442 DHD_ERROR(("****** %s ******\n", __FUNCTION__));
15443 link_recovery->hang_reason = HANG_REASON_PCIE_LINK_DOWN_RC_DETECT;
15444 dhd_bus_set_linkdown(link_recovery, TRUE);
15445 dhd_os_send_hang_message(link_recovery);
15446 }
15447 EXPORT_SYMBOL(dhd_host_recover_link);
15448 #endif /* EXYNOS_PCIE_LINKDOWN_RECOVERY */
15449
dhd_os_send_hang_message(dhd_pub_t * dhdp)15450 int dhd_os_send_hang_message(dhd_pub_t *dhdp)
15451 {
15452 int ret = 0;
15453 #ifdef WL_CFG80211
15454 struct net_device *primary_ndev;
15455 struct bcm_cfg80211 *cfg;
15456 #ifdef DHD_FILE_DUMP_EVENT
15457 dhd_info_t *dhd_info = NULL;
15458 #endif /* DHD_FILE_DUMP_EVENT */
15459 #endif /* WL_CFG80211 */
15460
15461 if (!dhdp) {
15462 DHD_ERROR(("%s: dhdp is null\n", __FUNCTION__));
15463 return -EINVAL;
15464 }
15465
15466 #if defined(WL_CFG80211) && defined(DHD_FILE_DUMP_EVENT)
15467 dhd_info = (dhd_info_t *)dhdp->info;
15468
15469 if (dhd_info->scheduled_memdump) {
15470 DHD_ERROR_RLMT(("[DUMP]:%s, memdump in progress. return\n", __FUNCTION__));
15471 dhdp->hang_was_pending = 1;
15472 return BCME_OK;
15473 }
15474 #endif /* WL_CFG80211 && DHD_FILE_DUMP_EVENT */
15475
15476 #ifdef WL_CFG80211
15477 primary_ndev = dhd_linux_get_primary_netdev(dhdp);
15478 if (!primary_ndev) {
15479 DHD_ERROR(("%s: Cannot find primary netdev\n", __FUNCTION__));
15480 return -ENODEV;
15481 }
15482 cfg = wl_get_cfg(primary_ndev);
15483 if (!cfg) {
15484 DHD_ERROR(("%s: Cannot find cfg\n", __FUNCTION__));
15485 return -EINVAL;
15486 }
15487
15488 /* Skip sending HANG event to framework if driver is not ready */
15489 if (!wl_get_drv_status(cfg, READY, primary_ndev)) {
15490 DHD_ERROR(("%s: device is not ready\n", __FUNCTION__));
15491 return -ENODEV;
15492 }
15493 #endif /* WL_CFG80211 */
15494
15495 if (!dhdp->hang_was_sent) {
15496 #if defined(CONFIG_BCM_DETECT_CONSECUTIVE_HANG)
15497 dhdp->hang_counts++;
15498 if (dhdp->hang_counts >= MAX_CONSECUTIVE_HANG_COUNTS) {
15499 DHD_ERROR(("%s, Consecutive hang from Dongle :%u\n",
15500 __func__, dhdp->hang_counts));
15501 BUG_ON(1);
15502 }
15503 #endif /* CONFIG_BCM_DETECT_CONSECUTIVE_HANG */
15504 #ifdef DHD_DEBUG_UART
15505 /* If PCIe lane has broken, execute the debug uart application
15506 * to gether a ramdump data from dongle via uart
15507 */
15508 if (!dhdp->info->duart_execute) {
15509 dhd_deferred_schedule_work(dhdp->info->dhd_deferred_wq,
15510 (void *)dhdp, DHD_WQ_WORK_DEBUG_UART_DUMP,
15511 dhd_debug_uart_exec_rd, DHD_WQ_WORK_PRIORITY_HIGH);
15512 }
15513 #endif /* DHD_DEBUG_UART */
15514 dhdp->hang_was_sent = 1;
15515 #ifdef BT_OVER_SDIO
15516 dhdp->is_bt_recovery_required = TRUE;
15517 #endif // endif
15518 schedule_work(&dhdp->info->dhd_hang_process_work);
15519 DHD_ERROR(("%s: Event HANG send up due to re=%d te=%d s=%d\n", __FUNCTION__,
15520 dhdp->rxcnt_timeout, dhdp->txcnt_timeout, dhdp->busstate));
15521 printf("%s\n", info_string);
15522 printf("MAC %pM\n", &dhdp->mac);
15523 }
15524 return ret;
15525 }
15526
net_os_send_hang_message(struct net_device * dev)15527 int net_os_send_hang_message(struct net_device *dev)
15528 {
15529 dhd_info_t *dhd = DHD_DEV_INFO(dev);
15530 int ret = 0;
15531
15532 if (dhd) {
15533 /* Report FW problem when enabled */
15534 if (dhd->pub.hang_report) {
15535 #ifdef BT_OVER_SDIO
15536 if (netif_running(dev)) {
15537 #endif /* BT_OVER_SDIO */
15538 ret = dhd_os_send_hang_message(&dhd->pub);
15539 #ifdef BT_OVER_SDIO
15540 }
15541 DHD_ERROR(("%s: HANG -> Reset BT\n", __FUNCTION__));
15542 bcmsdh_btsdio_process_dhd_hang_notification(!netif_running(dev));
15543 #endif /* BT_OVER_SDIO */
15544 } else {
15545 DHD_ERROR(("%s: FW HANG ignored (for testing purpose) and not sent up\n",
15546 __FUNCTION__));
15547 }
15548 }
15549 return ret;
15550 }
15551
net_os_send_hang_message_reason(struct net_device * dev,const char * string_num)15552 int net_os_send_hang_message_reason(struct net_device *dev, const char *string_num)
15553 {
15554 dhd_info_t *dhd = NULL;
15555 dhd_pub_t *dhdp = NULL;
15556 int reason;
15557
15558 dhd = DHD_DEV_INFO(dev);
15559 if (dhd) {
15560 dhdp = &dhd->pub;
15561 }
15562
15563 if (!dhd || !dhdp) {
15564 return 0;
15565 }
15566
15567 reason = bcm_strtoul(string_num, NULL, 0);
15568 DHD_INFO(("%s: Enter, reason=0x%x\n", __FUNCTION__, reason));
15569
15570 if ((reason <= HANG_REASON_MASK) || (reason >= HANG_REASON_MAX)) {
15571 reason = 0;
15572 }
15573
15574 dhdp->hang_reason = reason;
15575
15576 return net_os_send_hang_message(dev);
15577 }
15578
dhd_net_wifi_platform_set_power(struct net_device * dev,bool on,unsigned long delay_msec)15579 int dhd_net_wifi_platform_set_power(struct net_device *dev, bool on, unsigned long delay_msec)
15580 {
15581 dhd_info_t *dhd = DHD_DEV_INFO(dev);
15582 return wifi_platform_set_power(dhd->adapter, on, delay_msec);
15583 }
15584
dhd_force_country_change(struct net_device * dev)15585 bool dhd_force_country_change(struct net_device *dev)
15586 {
15587 dhd_info_t *dhd = DHD_DEV_INFO(dev);
15588
15589 if (dhd && dhd->pub.up)
15590 return dhd->pub.force_country_change;
15591 return FALSE;
15592 }
15593
dhd_get_customized_country_code(struct net_device * dev,char * country_iso_code,wl_country_t * cspec)15594 void dhd_get_customized_country_code(struct net_device *dev, char *country_iso_code,
15595 wl_country_t *cspec)
15596 {
15597 dhd_info_t *dhd = DHD_DEV_INFO(dev);
15598 #if defined(DHD_BLOB_EXISTENCE_CHECK)
15599 if (!dhd->pub.is_blob)
15600 #endif /* DHD_BLOB_EXISTENCE_CHECK */
15601 {
15602 #if defined(CUSTOM_COUNTRY_CODE)
15603 get_customized_country_code(dhd->adapter, country_iso_code, cspec,
15604 dhd->pub.dhd_cflags);
15605 #else
15606 get_customized_country_code(dhd->adapter, country_iso_code, cspec);
15607 #endif /* CUSTOM_COUNTRY_CODE */
15608 }
15609 #if defined(DHD_BLOB_EXISTENCE_CHECK) && !defined(CUSTOM_COUNTRY_CODE)
15610 else {
15611 /* Replace the ccode to XZ if ccode is undefined country */
15612 if (strncmp(country_iso_code, "", WLC_CNTRY_BUF_SZ) == 0) {
15613 strlcpy(country_iso_code, "XZ", WLC_CNTRY_BUF_SZ);
15614 strlcpy(cspec->country_abbrev, country_iso_code, WLC_CNTRY_BUF_SZ);
15615 strlcpy(cspec->ccode, country_iso_code, WLC_CNTRY_BUF_SZ);
15616 DHD_ERROR(("%s: ccode change to %s\n", __FUNCTION__, country_iso_code));
15617 }
15618 }
15619 #endif /* DHD_BLOB_EXISTENCE_CHECK && !CUSTOM_COUNTRY_CODE */
15620
15621 BCM_REFERENCE(dhd);
15622 }
15623
dhd_bus_country_set(struct net_device * dev,wl_country_t * cspec,bool notify)15624 void dhd_bus_country_set(struct net_device *dev, wl_country_t *cspec, bool notify)
15625 {
15626 dhd_info_t *dhd = DHD_DEV_INFO(dev);
15627 #ifdef WL_CFG80211
15628 struct bcm_cfg80211 *cfg = wl_get_cfg(dev);
15629 #endif // endif
15630
15631 if (dhd && dhd->pub.up) {
15632 memcpy(&dhd->pub.dhd_cspec, cspec, sizeof(wl_country_t));
15633 #ifdef WL_CFG80211
15634 wl_update_wiphybands(cfg, notify);
15635 #endif // endif
15636 }
15637 }
15638
dhd_bus_band_set(struct net_device * dev,uint band)15639 void dhd_bus_band_set(struct net_device *dev, uint band)
15640 {
15641 dhd_info_t *dhd = DHD_DEV_INFO(dev);
15642 #ifdef WL_CFG80211
15643 struct bcm_cfg80211 *cfg = wl_get_cfg(dev);
15644 #endif // endif
15645 if (dhd && dhd->pub.up) {
15646 #ifdef WL_CFG80211
15647 wl_update_wiphybands(cfg, true);
15648 #endif // endif
15649 }
15650 }
15651
dhd_net_set_fw_path(struct net_device * dev,char * fw)15652 int dhd_net_set_fw_path(struct net_device *dev, char *fw)
15653 {
15654 dhd_info_t *dhd = DHD_DEV_INFO(dev);
15655
15656 if (!fw || fw[0] == '\0')
15657 return -EINVAL;
15658
15659 strncpy(dhd->fw_path, fw, sizeof(dhd->fw_path) - 1);
15660 dhd->fw_path[sizeof(dhd->fw_path)-1] = '\0';
15661
15662 #if defined(SOFTAP)
15663 if (strstr(fw, "apsta") != NULL) {
15664 DHD_INFO(("GOT APSTA FIRMWARE\n"));
15665 ap_fw_loaded = TRUE;
15666 } else {
15667 DHD_INFO(("GOT STA FIRMWARE\n"));
15668 ap_fw_loaded = FALSE;
15669 }
15670 #endif // endif
15671 return 0;
15672 }
15673
dhd_net_if_lock(struct net_device * dev)15674 void dhd_net_if_lock(struct net_device *dev)
15675 {
15676 dhd_info_t *dhd = DHD_DEV_INFO(dev);
15677 dhd_net_if_lock_local(dhd);
15678 }
15679
dhd_net_if_unlock(struct net_device * dev)15680 void dhd_net_if_unlock(struct net_device *dev)
15681 {
15682 dhd_info_t *dhd = DHD_DEV_INFO(dev);
15683 dhd_net_if_unlock_local(dhd);
15684 }
15685
dhd_net_if_lock_local(dhd_info_t * dhd)15686 static void dhd_net_if_lock_local(dhd_info_t *dhd)
15687 {
15688 if (dhd)
15689 mutex_lock(&dhd->dhd_net_if_mutex);
15690 }
15691
dhd_net_if_unlock_local(dhd_info_t * dhd)15692 static void dhd_net_if_unlock_local(dhd_info_t *dhd)
15693 {
15694 if (dhd)
15695 mutex_unlock(&dhd->dhd_net_if_mutex);
15696 }
15697
dhd_suspend_lock(dhd_pub_t * pub)15698 static void dhd_suspend_lock(dhd_pub_t *pub)
15699 {
15700 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
15701 if (dhd)
15702 mutex_lock(&dhd->dhd_suspend_mutex);
15703 }
15704
dhd_suspend_unlock(dhd_pub_t * pub)15705 static void dhd_suspend_unlock(dhd_pub_t *pub)
15706 {
15707 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
15708 if (dhd)
15709 mutex_unlock(&dhd->dhd_suspend_mutex);
15710 }
15711
dhd_os_general_spin_lock(dhd_pub_t * pub)15712 unsigned long dhd_os_general_spin_lock(dhd_pub_t *pub)
15713 {
15714 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
15715 unsigned long flags = 0;
15716
15717 if (dhd)
15718 spin_lock_irqsave(&dhd->dhd_lock, flags);
15719
15720 return flags;
15721 }
15722
dhd_os_general_spin_unlock(dhd_pub_t * pub,unsigned long flags)15723 void dhd_os_general_spin_unlock(dhd_pub_t *pub, unsigned long flags)
15724 {
15725 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
15726
15727 if (dhd)
15728 spin_unlock_irqrestore(&dhd->dhd_lock, flags);
15729 }
15730
15731 /* Linux specific multipurpose spinlock API */
15732 void *
dhd_os_spin_lock_init(osl_t * osh)15733 dhd_os_spin_lock_init(osl_t *osh)
15734 {
15735 /* Adding 4 bytes since the sizeof(spinlock_t) could be 0 */
15736 /* if CONFIG_SMP and CONFIG_DEBUG_SPINLOCK are not defined */
15737 /* and this results in kernel asserts in internal builds */
15738 spinlock_t * lock = MALLOC(osh, sizeof(spinlock_t) + 4);
15739 if (lock)
15740 spin_lock_init(lock);
15741 return ((void *)lock);
15742 }
15743 void
dhd_os_spin_lock_deinit(osl_t * osh,void * lock)15744 dhd_os_spin_lock_deinit(osl_t *osh, void *lock)
15745 {
15746 if (lock)
15747 MFREE(osh, lock, sizeof(spinlock_t) + 4);
15748 }
15749 unsigned long
dhd_os_spin_lock(void * lock)15750 dhd_os_spin_lock(void *lock)
15751 {
15752 unsigned long flags = 0;
15753
15754 if (lock)
15755 spin_lock_irqsave((spinlock_t *)lock, flags);
15756
15757 return flags;
15758 }
15759 void
dhd_os_spin_unlock(void * lock,unsigned long flags)15760 dhd_os_spin_unlock(void *lock, unsigned long flags)
15761 {
15762 if (lock)
15763 spin_unlock_irqrestore((spinlock_t *)lock, flags);
15764 }
15765
15766 void *
dhd_os_dbgring_lock_init(osl_t * osh)15767 dhd_os_dbgring_lock_init(osl_t *osh)
15768 {
15769 struct mutex *mtx = NULL;
15770
15771 mtx = MALLOCZ(osh, sizeof(*mtx));
15772 if (mtx)
15773 mutex_init(mtx);
15774
15775 return mtx;
15776 }
15777
15778 void
dhd_os_dbgring_lock_deinit(osl_t * osh,void * mtx)15779 dhd_os_dbgring_lock_deinit(osl_t *osh, void *mtx)
15780 {
15781 if (mtx) {
15782 mutex_destroy(mtx);
15783 MFREE(osh, mtx, sizeof(struct mutex));
15784 }
15785 }
15786
15787 static int
dhd_get_pend_8021x_cnt(dhd_info_t * dhd)15788 dhd_get_pend_8021x_cnt(dhd_info_t *dhd)
15789 {
15790 return (atomic_read(&dhd->pend_8021x_cnt));
15791 }
15792
15793 #define MAX_WAIT_FOR_8021X_TX 100
15794
15795 int
dhd_wait_pend8021x(struct net_device * dev)15796 dhd_wait_pend8021x(struct net_device *dev)
15797 {
15798 dhd_info_t *dhd = DHD_DEV_INFO(dev);
15799 int timeout = msecs_to_jiffies(10);
15800 int ntimes = MAX_WAIT_FOR_8021X_TX;
15801 int pend = dhd_get_pend_8021x_cnt(dhd);
15802
15803 while (ntimes && pend) {
15804 if (pend) {
15805 set_current_state(TASK_INTERRUPTIBLE);
15806 DHD_PERIM_UNLOCK(&dhd->pub);
15807 schedule_timeout(timeout);
15808 DHD_PERIM_LOCK(&dhd->pub);
15809 set_current_state(TASK_RUNNING);
15810 ntimes--;
15811 }
15812 pend = dhd_get_pend_8021x_cnt(dhd);
15813 }
15814 if (ntimes == 0)
15815 {
15816 atomic_set(&dhd->pend_8021x_cnt, 0);
15817 WL_MSG(dev->name, "TIMEOUT\n");
15818 }
15819 return pend;
15820 }
15821
15822 #if defined(DHD_DEBUG)
write_file(const char * file_name,uint32 flags,uint8 * buf,int size)15823 int write_file(const char * file_name, uint32 flags, uint8 *buf, int size)
15824 {
15825 int ret = 0;
15826 struct file *fp = NULL;
15827 #if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0))
15828 mm_segment_t old_fs;
15829 #endif
15830 loff_t pos = 0;
15831 /* change to KERNEL_DS address limit */
15832 #if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0))
15833 old_fs = get_fs();
15834 set_fs(KERNEL_DS);
15835 #endif
15836
15837 /* open file to write */
15838 fp = filp_open(file_name, flags, 0664);
15839 if (IS_ERR(fp)) {
15840 DHD_ERROR(("open file error, err = %ld\n", PTR_ERR(fp)));
15841 goto exit;
15842 }
15843
15844 /* Write buf to file */
15845 ret = compat_vfs_write(fp, buf, size, &pos);
15846 if (ret < 0) {
15847 DHD_ERROR(("write file error, err = %d\n", ret));
15848 goto exit;
15849 }
15850
15851 /* Sync file from filesystem to physical media */
15852 ret = vfs_fsync(fp, 0);
15853 if (ret < 0) {
15854 DHD_ERROR(("sync file error, error = %d\n", ret));
15855 goto exit;
15856 }
15857 ret = BCME_OK;
15858
15859 exit:
15860 /* close file before return */
15861 if (!IS_ERR(fp))
15862 filp_close(fp, current->files);
15863
15864 /* restore previous address limit */
15865 #if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0))
15866 set_fs(old_fs);
15867 #endif
15868
15869 return ret;
15870 }
15871 #endif // endif
15872
15873 #ifdef DHD_DEBUG
15874 static void
dhd_convert_memdump_type_to_str(uint32 type,char * buf,int substr_type)15875 dhd_convert_memdump_type_to_str(uint32 type, char *buf, int substr_type)
15876 {
15877 char *type_str = NULL;
15878
15879 switch (type) {
15880 case DUMP_TYPE_RESUMED_ON_TIMEOUT:
15881 type_str = "resumed_on_timeout";
15882 break;
15883 case DUMP_TYPE_D3_ACK_TIMEOUT:
15884 type_str = "D3_ACK_timeout";
15885 break;
15886 case DUMP_TYPE_DONGLE_TRAP:
15887 type_str = "Dongle_Trap";
15888 break;
15889 case DUMP_TYPE_MEMORY_CORRUPTION:
15890 type_str = "Memory_Corruption";
15891 break;
15892 case DUMP_TYPE_PKTID_AUDIT_FAILURE:
15893 type_str = "PKTID_AUDIT_Fail";
15894 break;
15895 case DUMP_TYPE_PKTID_INVALID:
15896 type_str = "PKTID_INVALID";
15897 break;
15898 case DUMP_TYPE_SCAN_TIMEOUT:
15899 type_str = "SCAN_timeout";
15900 break;
15901 case DUMP_TYPE_SCAN_BUSY:
15902 type_str = "SCAN_Busy";
15903 break;
15904 case DUMP_TYPE_BY_SYSDUMP:
15905 if (substr_type == CMD_UNWANTED) {
15906 type_str = "BY_SYSDUMP_FORUSER_unwanted";
15907 } else if (substr_type == CMD_DISCONNECTED) {
15908 type_str = "BY_SYSDUMP_FORUSER_disconnected";
15909 } else {
15910 type_str = "BY_SYSDUMP_FORUSER";
15911 }
15912 break;
15913 case DUMP_TYPE_BY_LIVELOCK:
15914 type_str = "BY_LIVELOCK";
15915 break;
15916 case DUMP_TYPE_AP_LINKUP_FAILURE:
15917 type_str = "BY_AP_LINK_FAILURE";
15918 break;
15919 case DUMP_TYPE_AP_ABNORMAL_ACCESS:
15920 type_str = "INVALID_ACCESS";
15921 break;
15922 case DUMP_TYPE_RESUMED_ON_TIMEOUT_RX:
15923 type_str = "ERROR_RX_TIMED_OUT";
15924 break;
15925 case DUMP_TYPE_RESUMED_ON_TIMEOUT_TX:
15926 type_str = "ERROR_TX_TIMED_OUT";
15927 break;
15928 case DUMP_TYPE_CFG_VENDOR_TRIGGERED:
15929 type_str = "CFG_VENDOR_TRIGGERED";
15930 break;
15931 case DUMP_TYPE_RESUMED_ON_INVALID_RING_RDWR:
15932 type_str = "BY_INVALID_RING_RDWR";
15933 break;
15934 case DUMP_TYPE_IFACE_OP_FAILURE:
15935 type_str = "BY_IFACE_OP_FAILURE";
15936 break;
15937 case DUMP_TYPE_TRANS_ID_MISMATCH:
15938 type_str = "BY_TRANS_ID_MISMATCH";
15939 break;
15940 #ifdef DEBUG_DNGL_INIT_FAIL
15941 case DUMP_TYPE_DONGLE_INIT_FAILURE:
15942 type_str = "DONGLE_INIT_FAIL";
15943 break;
15944 #endif /* DEBUG_DNGL_INIT_FAIL */
15945 case DUMP_TYPE_DONGLE_HOST_EVENT:
15946 type_str = "BY_DONGLE_HOST_EVENT";
15947 break;
15948 case DUMP_TYPE_SMMU_FAULT:
15949 type_str = "SMMU_FAULT";
15950 break;
15951 case DUMP_TYPE_BY_USER:
15952 type_str = "BY_USER";
15953 break;
15954 #ifdef DHD_ERPOM
15955 case DUMP_TYPE_DUE_TO_BT:
15956 type_str = "DUE_TO_BT";
15957 break;
15958 #endif /* DHD_ERPOM */
15959 case DUMP_TYPE_LOGSET_BEYOND_RANGE:
15960 type_str = "LOGSET_BEYOND_RANGE";
15961 break;
15962 case DUMP_TYPE_CTO_RECOVERY:
15963 type_str = "CTO_RECOVERY";
15964 break;
15965 case DUMP_TYPE_SEQUENTIAL_PRIVCMD_ERROR:
15966 type_str = "SEQUENTIAL_PRIVCMD_ERROR";
15967 break;
15968 case DUMP_TYPE_PROXD_TIMEOUT:
15969 type_str = "PROXD_TIMEOUT";
15970 break;
15971 case DUMP_TYPE_PKTID_POOL_DEPLETED:
15972 type_str = "PKTID_POOL_DEPLETED";
15973 break;
15974 default:
15975 type_str = "Unknown_type";
15976 break;
15977 }
15978
15979 strncpy(buf, type_str, strlen(type_str));
15980 buf[strlen(type_str)] = 0;
15981 }
15982
15983 void
dhd_get_memdump_filename(struct net_device * ndev,char * memdump_path,int len,char * fname)15984 dhd_get_memdump_filename(struct net_device *ndev, char *memdump_path, int len, char *fname)
15985 {
15986 char memdump_type[32];
15987 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(ndev);
15988 dhd_pub_t *dhdp = &dhd->pub;
15989
15990 /* Init file name */
15991 memset(memdump_path, 0, len);
15992 memset(memdump_type, 0, sizeof(memdump_type));
15993 dhd_convert_memdump_type_to_str(dhdp->memdump_type, memdump_type, dhdp->debug_dump_subcmd);
15994 clear_debug_dump_time(dhdp->debug_dump_time_str);
15995 get_debug_dump_time(dhdp->debug_dump_time_str);
15996 snprintf(memdump_path, len, "%s%s_%s_" "%s",
15997 DHD_COMMON_DUMP_PATH, fname, memdump_type, dhdp->debug_dump_time_str);
15998 if (strstr(fname, "sssr_dump")) {
15999 DHD_SSSR_PRINT_FILEPATH(dhdp, memdump_path);
16000 } else {
16001 DHD_ERROR(("%s: file_path = %s%s\n", __FUNCTION__,
16002 memdump_path, FILE_NAME_HAL_TAG));
16003 }
16004 }
16005
16006 int
write_dump_to_file(dhd_pub_t * dhd,uint8 * buf,int size,char * fname)16007 write_dump_to_file(dhd_pub_t *dhd, uint8 *buf, int size, char *fname)
16008 {
16009 int ret = 0;
16010 char memdump_path[128];
16011 char memdump_type[32];
16012 uint32 file_mode;
16013
16014 /* Init file name */
16015 memset(memdump_path, 0, sizeof(memdump_path));
16016 memset(memdump_type, 0, sizeof(memdump_type));
16017 dhd_convert_memdump_type_to_str(dhd->memdump_type, memdump_type, dhd->debug_dump_subcmd);
16018 clear_debug_dump_time(dhd->debug_dump_time_str);
16019 get_debug_dump_time(dhd->debug_dump_time_str);
16020 snprintf(memdump_path, sizeof(memdump_path), "%s%s_%s_" "%s",
16021 DHD_COMMON_DUMP_PATH, fname, memdump_type, dhd->debug_dump_time_str);
16022 file_mode = O_CREAT | O_WRONLY | O_SYNC;
16023
16024 /* print SOCRAM dump file path */
16025 DHD_ERROR(("%s: file_path = %s\n", __FUNCTION__, memdump_path));
16026
16027 #ifdef DHD_LOG_DUMP
16028 dhd_print_buf_addr(dhd, "write_dump_to_file", buf, size);
16029 #endif /* DHD_LOG_DUMP */
16030
16031 /* Write file */
16032 ret = write_file(memdump_path, file_mode, buf, size);
16033
16034 #ifdef DHD_DUMP_MNGR
16035 if (ret == BCME_OK) {
16036 dhd_dump_file_manage_enqueue(dhd, memdump_path, fname);
16037 }
16038 #endif /* DHD_DUMP_MNGR */
16039
16040 return ret;
16041 }
16042 #endif /* DHD_DEBUG */
16043
dhd_os_wake_lock_timeout(dhd_pub_t * pub)16044 int dhd_os_wake_lock_timeout(dhd_pub_t *pub)
16045 {
16046 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
16047 unsigned long flags;
16048 int ret = 0;
16049
16050 if (dhd && (dhd->dhd_state & DHD_ATTACH_STATE_WAKELOCKS_INIT)) {
16051 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
16052 ret = dhd->wakelock_rx_timeout_enable > dhd->wakelock_ctrl_timeout_enable ?
16053 dhd->wakelock_rx_timeout_enable : dhd->wakelock_ctrl_timeout_enable;
16054 #ifdef CONFIG_HAS_WAKELOCK
16055 if (dhd->wakelock_rx_timeout_enable)
16056 wake_lock_timeout(&dhd->wl_rxwake,
16057 msecs_to_jiffies(dhd->wakelock_rx_timeout_enable));
16058 if (dhd->wakelock_ctrl_timeout_enable)
16059 wake_lock_timeout(&dhd->wl_ctrlwake,
16060 msecs_to_jiffies(dhd->wakelock_ctrl_timeout_enable));
16061 #endif // endif
16062 dhd->wakelock_rx_timeout_enable = 0;
16063 dhd->wakelock_ctrl_timeout_enable = 0;
16064 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
16065 }
16066 return ret;
16067 }
16068
net_os_wake_lock_timeout(struct net_device * dev)16069 int net_os_wake_lock_timeout(struct net_device *dev)
16070 {
16071 dhd_info_t *dhd = DHD_DEV_INFO(dev);
16072 int ret = 0;
16073
16074 if (dhd)
16075 ret = dhd_os_wake_lock_timeout(&dhd->pub);
16076 return ret;
16077 }
16078
dhd_os_wake_lock_rx_timeout_enable(dhd_pub_t * pub,int val)16079 int dhd_os_wake_lock_rx_timeout_enable(dhd_pub_t *pub, int val)
16080 {
16081 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
16082 unsigned long flags;
16083
16084 if (dhd && (dhd->dhd_state & DHD_ATTACH_STATE_WAKELOCKS_INIT)) {
16085 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
16086 if (val > dhd->wakelock_rx_timeout_enable)
16087 dhd->wakelock_rx_timeout_enable = val;
16088 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
16089 }
16090 return 0;
16091 }
16092
dhd_os_wake_lock_ctrl_timeout_enable(dhd_pub_t * pub,int val)16093 int dhd_os_wake_lock_ctrl_timeout_enable(dhd_pub_t *pub, int val)
16094 {
16095 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
16096 unsigned long flags;
16097
16098 if (dhd && (dhd->dhd_state & DHD_ATTACH_STATE_WAKELOCKS_INIT)) {
16099 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
16100 if (val > dhd->wakelock_ctrl_timeout_enable)
16101 dhd->wakelock_ctrl_timeout_enable = val;
16102 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
16103 }
16104 return 0;
16105 }
16106
dhd_os_wake_lock_ctrl_timeout_cancel(dhd_pub_t * pub)16107 int dhd_os_wake_lock_ctrl_timeout_cancel(dhd_pub_t *pub)
16108 {
16109 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
16110 unsigned long flags;
16111
16112 if (dhd && (dhd->dhd_state & DHD_ATTACH_STATE_WAKELOCKS_INIT)) {
16113 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
16114 dhd->wakelock_ctrl_timeout_enable = 0;
16115 #ifdef CONFIG_HAS_WAKELOCK
16116 if (wake_lock_active(&dhd->wl_ctrlwake))
16117 wake_unlock(&dhd->wl_ctrlwake);
16118 #endif // endif
16119 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
16120 }
16121 return 0;
16122 }
16123
net_os_wake_lock_rx_timeout_enable(struct net_device * dev,int val)16124 int net_os_wake_lock_rx_timeout_enable(struct net_device *dev, int val)
16125 {
16126 dhd_info_t *dhd = DHD_DEV_INFO(dev);
16127 int ret = 0;
16128
16129 if (dhd)
16130 ret = dhd_os_wake_lock_rx_timeout_enable(&dhd->pub, val);
16131 return ret;
16132 }
16133
net_os_wake_lock_ctrl_timeout_enable(struct net_device * dev,int val)16134 int net_os_wake_lock_ctrl_timeout_enable(struct net_device *dev, int val)
16135 {
16136 dhd_info_t *dhd = DHD_DEV_INFO(dev);
16137 int ret = 0;
16138
16139 if (dhd)
16140 ret = dhd_os_wake_lock_ctrl_timeout_enable(&dhd->pub, val);
16141 return ret;
16142 }
16143
16144 #if defined(DHD_TRACE_WAKE_LOCK)
16145 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
16146 #include <linux/hashtable.h>
16147 #else
16148 #include <linux/hash.h>
16149 #endif /* KERNEL_VER >= KERNEL_VERSION(3, 7, 0) */
16150
16151 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
16152 /* Define 2^5 = 32 bucket size hash table */
16153 DEFINE_HASHTABLE(wklock_history, 5);
16154 #else
16155 /* Define 2^5 = 32 bucket size hash table */
16156 struct hlist_head wklock_history[32] = { [0 ... 31] = HLIST_HEAD_INIT };
16157 #endif /* KERNEL_VER >= KERNEL_VERSION(3, 7, 0) */
16158
16159 atomic_t trace_wklock_onoff;
16160 typedef enum dhd_wklock_type {
16161 DHD_WAKE_LOCK,
16162 DHD_WAKE_UNLOCK,
16163 DHD_WAIVE_LOCK,
16164 DHD_RESTORE_LOCK
16165 } dhd_wklock_t;
16166
16167 struct wk_trace_record {
16168 unsigned long addr; /* Address of the instruction */
16169 dhd_wklock_t lock_type; /* lock_type */
16170 unsigned long long counter; /* counter information */
16171 struct hlist_node wklock_node; /* hash node */
16172 };
16173
find_wklock_entry(unsigned long addr)16174 static struct wk_trace_record *find_wklock_entry(unsigned long addr)
16175 {
16176 struct wk_trace_record *wklock_info;
16177 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
16178 hash_for_each_possible(wklock_history, wklock_info, wklock_node, addr)
16179 #else
16180 struct hlist_node *entry;
16181 int index = hash_long(addr, ilog2(ARRAY_SIZE(wklock_history)));
16182 hlist_for_each_entry(wklock_info, entry, &wklock_history[index], wklock_node)
16183 #endif /* KERNEL_VER >= KERNEL_VERSION(3, 7, 0) */
16184 {
16185 if (wklock_info->addr == addr) {
16186 return wklock_info;
16187 }
16188 }
16189 return NULL;
16190 }
16191
16192 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
16193 #define HASH_ADD(hashtable, node, key) \
16194 do { \
16195 hash_add(hashtable, node, key); \
16196 } while (0);
16197 #else
16198 #define HASH_ADD(hashtable, node, key) \
16199 do { \
16200 int index = hash_long(key, ilog2(ARRAY_SIZE(hashtable))); \
16201 hlist_add_head(node, &hashtable[index]); \
16202 } while (0);
16203 #endif /* KERNEL_VER < KERNEL_VERSION(3, 7, 0) */
16204
16205 #define STORE_WKLOCK_RECORD(wklock_type) \
16206 do { \
16207 struct wk_trace_record *wklock_info = NULL; \
16208 unsigned long func_addr = (unsigned long)__builtin_return_address(0); \
16209 wklock_info = find_wklock_entry(func_addr); \
16210 if (wklock_info) { \
16211 if (wklock_type == DHD_WAIVE_LOCK || wklock_type == DHD_RESTORE_LOCK) { \
16212 wklock_info->counter = dhd->wakelock_counter; \
16213 } else { \
16214 wklock_info->counter++; \
16215 } \
16216 } else { \
16217 wklock_info = kzalloc(sizeof(*wklock_info), GFP_ATOMIC); \
16218 if (!wklock_info) {\
16219 printk("Can't allocate wk_trace_record \n"); \
16220 } else { \
16221 wklock_info->addr = func_addr; \
16222 wklock_info->lock_type = wklock_type; \
16223 if (wklock_type == DHD_WAIVE_LOCK || \
16224 wklock_type == DHD_RESTORE_LOCK) { \
16225 wklock_info->counter = dhd->wakelock_counter; \
16226 } else { \
16227 wklock_info->counter++; \
16228 } \
16229 HASH_ADD(wklock_history, &wklock_info->wklock_node, func_addr); \
16230 } \
16231 } \
16232 } while (0);
16233
dhd_wk_lock_rec_dump(void)16234 static inline void dhd_wk_lock_rec_dump(void)
16235 {
16236 int bkt;
16237 struct wk_trace_record *wklock_info;
16238
16239 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
16240 hash_for_each(wklock_history, bkt, wklock_info, wklock_node)
16241 #else
16242 struct hlist_node *entry = NULL;
16243 int max_index = ARRAY_SIZE(wklock_history);
16244 for (bkt = 0; bkt < max_index; bkt++)
16245 hlist_for_each_entry(wklock_info, entry, &wklock_history[bkt], wklock_node)
16246 #endif /* KERNEL_VER >= KERNEL_VERSION(3, 7, 0) */
16247 {
16248 switch (wklock_info->lock_type) {
16249 case DHD_WAKE_LOCK:
16250 printk("wakelock lock : %pS lock_counter : %llu \n",
16251 (void *)wklock_info->addr, wklock_info->counter);
16252 break;
16253 case DHD_WAKE_UNLOCK:
16254 printk("wakelock unlock : %pS, unlock_counter : %llu \n",
16255 (void *)wklock_info->addr, wklock_info->counter);
16256 break;
16257 case DHD_WAIVE_LOCK:
16258 printk("wakelock waive : %pS before_waive : %llu \n",
16259 (void *)wklock_info->addr, wklock_info->counter);
16260 break;
16261 case DHD_RESTORE_LOCK:
16262 printk("wakelock restore : %pS, after_waive : %llu \n",
16263 (void *)wklock_info->addr, wklock_info->counter);
16264 break;
16265 }
16266 }
16267 }
16268
dhd_wk_lock_trace_init(struct dhd_info * dhd)16269 static void dhd_wk_lock_trace_init(struct dhd_info *dhd)
16270 {
16271 unsigned long flags;
16272 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
16273 int i;
16274 #endif /* KERNEL_VER >= KERNEL_VERSION(3, 7, 0) */
16275
16276 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
16277 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
16278 hash_init(wklock_history);
16279 #else
16280 for (i = 0; i < ARRAY_SIZE(wklock_history); i++)
16281 INIT_HLIST_HEAD(&wklock_history[i]);
16282 #endif /* KERNEL_VER >= KERNEL_VERSION(3, 7, 0) */
16283 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
16284 atomic_set(&trace_wklock_onoff, 1);
16285 }
16286
dhd_wk_lock_trace_deinit(struct dhd_info * dhd)16287 static void dhd_wk_lock_trace_deinit(struct dhd_info *dhd)
16288 {
16289 int bkt;
16290 struct wk_trace_record *wklock_info;
16291 struct hlist_node *tmp;
16292 unsigned long flags;
16293 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
16294 struct hlist_node *entry = NULL;
16295 int max_index = ARRAY_SIZE(wklock_history);
16296 #endif /* KERNEL_VER >= KERNEL_VERSION(3, 7, 0) */
16297
16298 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
16299 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
16300 hash_for_each_safe(wklock_history, bkt, tmp, wklock_info, wklock_node)
16301 #else
16302 for (bkt = 0; bkt < max_index; bkt++)
16303 hlist_for_each_entry_safe(wklock_info, entry, tmp,
16304 &wklock_history[bkt], wklock_node)
16305 #endif /* KERNEL_VER >= KERNEL_VERSION(3, 7, 0)) */
16306 {
16307 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
16308 hash_del(&wklock_info->wklock_node);
16309 #else
16310 hlist_del_init(&wklock_info->wklock_node);
16311 #endif /* KERNEL_VER >= KERNEL_VERSION(3, 7, 0)) */
16312 kfree(wklock_info);
16313 }
16314 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
16315 }
16316
dhd_wk_lock_stats_dump(dhd_pub_t * dhdp)16317 void dhd_wk_lock_stats_dump(dhd_pub_t *dhdp)
16318 {
16319 dhd_info_t *dhd = (dhd_info_t *)(dhdp->info);
16320 unsigned long flags;
16321
16322 printk(KERN_ERR"DHD Printing wl_wake Lock/Unlock Record \r\n");
16323 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
16324 dhd_wk_lock_rec_dump();
16325 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
16326
16327 }
16328 #else
16329 #define STORE_WKLOCK_RECORD(wklock_type)
16330 #endif /* ! DHD_TRACE_WAKE_LOCK */
16331
dhd_os_wake_lock(dhd_pub_t * pub)16332 int dhd_os_wake_lock(dhd_pub_t *pub)
16333 {
16334 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
16335 unsigned long flags;
16336 int ret = 0;
16337
16338 if (dhd && (dhd->dhd_state & DHD_ATTACH_STATE_WAKELOCKS_INIT)) {
16339 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
16340 if (dhd->wakelock_counter == 0 && !dhd->waive_wakelock) {
16341 #ifdef CONFIG_HAS_WAKELOCK
16342 wake_lock(&dhd->wl_wifi);
16343 #elif defined(BCMSDIO)
16344 dhd_bus_dev_pm_stay_awake(pub);
16345 #endif // endif
16346 }
16347 #ifdef DHD_TRACE_WAKE_LOCK
16348 if (atomic_read(&trace_wklock_onoff)) {
16349 STORE_WKLOCK_RECORD(DHD_WAKE_LOCK);
16350 }
16351 #endif /* DHD_TRACE_WAKE_LOCK */
16352 dhd->wakelock_counter++;
16353 ret = dhd->wakelock_counter;
16354 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
16355 }
16356
16357 return ret;
16358 }
16359
dhd_event_wake_lock(dhd_pub_t * pub)16360 void dhd_event_wake_lock(dhd_pub_t *pub)
16361 {
16362 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
16363
16364 if (dhd) {
16365 #ifdef CONFIG_HAS_WAKELOCK
16366 wake_lock(&dhd->wl_evtwake);
16367 #elif defined(BCMSDIO)
16368 dhd_bus_dev_pm_stay_awake(pub);
16369 #endif // endif
16370 }
16371 }
16372
16373 void
dhd_pm_wake_lock_timeout(dhd_pub_t * pub,int val)16374 dhd_pm_wake_lock_timeout(dhd_pub_t *pub, int val)
16375 {
16376 #ifdef CONFIG_HAS_WAKELOCK
16377 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
16378
16379 if (dhd) {
16380 wake_lock_timeout(&dhd->wl_pmwake, msecs_to_jiffies(val));
16381 }
16382 #endif /* CONFIG_HAS_WAKE_LOCK */
16383 }
16384
16385 void
dhd_txfl_wake_lock_timeout(dhd_pub_t * pub,int val)16386 dhd_txfl_wake_lock_timeout(dhd_pub_t *pub, int val)
16387 {
16388 #ifdef CONFIG_HAS_WAKELOCK
16389 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
16390
16391 if (dhd) {
16392 wake_lock_timeout(&dhd->wl_txflwake, msecs_to_jiffies(val));
16393 }
16394 #endif /* CONFIG_HAS_WAKE_LOCK */
16395 }
16396
net_os_wake_lock(struct net_device * dev)16397 int net_os_wake_lock(struct net_device *dev)
16398 {
16399 dhd_info_t *dhd = DHD_DEV_INFO(dev);
16400 int ret = 0;
16401
16402 if (dhd)
16403 ret = dhd_os_wake_lock(&dhd->pub);
16404 return ret;
16405 }
16406
dhd_os_wake_unlock(dhd_pub_t * pub)16407 int dhd_os_wake_unlock(dhd_pub_t *pub)
16408 {
16409 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
16410 unsigned long flags;
16411 int ret = 0;
16412
16413 dhd_os_wake_lock_timeout(pub);
16414 if (dhd && (dhd->dhd_state & DHD_ATTACH_STATE_WAKELOCKS_INIT)) {
16415 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
16416
16417 if (dhd->wakelock_counter > 0) {
16418 dhd->wakelock_counter--;
16419 #ifdef DHD_TRACE_WAKE_LOCK
16420 if (atomic_read(&trace_wklock_onoff)) {
16421 STORE_WKLOCK_RECORD(DHD_WAKE_UNLOCK);
16422 }
16423 #endif /* DHD_TRACE_WAKE_LOCK */
16424 if (dhd->wakelock_counter == 0 && !dhd->waive_wakelock) {
16425 #ifdef CONFIG_HAS_WAKELOCK
16426 wake_unlock(&dhd->wl_wifi);
16427 #elif defined(BCMSDIO)
16428 dhd_bus_dev_pm_relax(pub);
16429 #endif // endif
16430 }
16431 ret = dhd->wakelock_counter;
16432 }
16433 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
16434 }
16435 return ret;
16436 }
16437
dhd_event_wake_unlock(dhd_pub_t * pub)16438 void dhd_event_wake_unlock(dhd_pub_t *pub)
16439 {
16440 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
16441
16442 if (dhd) {
16443 #ifdef CONFIG_HAS_WAKELOCK
16444 wake_unlock(&dhd->wl_evtwake);
16445 #elif defined(BCMSDIO)
16446 dhd_bus_dev_pm_relax(pub);
16447 #endif // endif
16448 }
16449 }
16450
dhd_pm_wake_unlock(dhd_pub_t * pub)16451 void dhd_pm_wake_unlock(dhd_pub_t *pub)
16452 {
16453 #ifdef CONFIG_HAS_WAKELOCK
16454 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
16455
16456 if (dhd) {
16457 /* if wl_pmwake is active, unlock it */
16458 if (wake_lock_active(&dhd->wl_pmwake)) {
16459 wake_unlock(&dhd->wl_pmwake);
16460 }
16461 }
16462 #endif /* CONFIG_HAS_WAKELOCK */
16463 }
16464
dhd_txfl_wake_unlock(dhd_pub_t * pub)16465 void dhd_txfl_wake_unlock(dhd_pub_t *pub)
16466 {
16467 #ifdef CONFIG_HAS_WAKELOCK
16468 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
16469
16470 if (dhd) {
16471 /* if wl_txflwake is active, unlock it */
16472 if (wake_lock_active(&dhd->wl_txflwake)) {
16473 wake_unlock(&dhd->wl_txflwake);
16474 }
16475 }
16476 #endif /* CONFIG_HAS_WAKELOCK */
16477 }
16478
dhd_os_check_wakelock(dhd_pub_t * pub)16479 int dhd_os_check_wakelock(dhd_pub_t *pub)
16480 {
16481 #if defined(CONFIG_HAS_WAKELOCK) || defined(BCMSDIO)
16482 dhd_info_t *dhd;
16483
16484 if (!pub)
16485 return 0;
16486 dhd = (dhd_info_t *)(pub->info);
16487 #endif /* CONFIG_HAS_WAKELOCK || BCMSDIO */
16488
16489 #ifdef CONFIG_HAS_WAKELOCK
16490 /* Indicate to the SD Host to avoid going to suspend if internal locks are up */
16491 if (dhd && (wake_lock_active(&dhd->wl_wifi) ||
16492 (wake_lock_active(&dhd->wl_wdwake))))
16493 return 1;
16494 #elif defined(BCMSDIO)
16495 if (dhd && (dhd->wakelock_counter > 0) && dhd_bus_dev_pm_enabled(pub))
16496 return 1;
16497 #endif // endif
16498 return 0;
16499 }
16500
16501 int
dhd_os_check_wakelock_all(dhd_pub_t * pub)16502 dhd_os_check_wakelock_all(dhd_pub_t *pub)
16503 {
16504 #if defined(CONFIG_HAS_WAKELOCK) || defined(BCMSDIO)
16505 #if defined(CONFIG_HAS_WAKELOCK)
16506 int l1, l2, l3, l4, l7, l8, l9;
16507 int l5 = 0, l6 = 0;
16508 int c, lock_active;
16509 #endif /* CONFIG_HAS_WAKELOCK */
16510 dhd_info_t *dhd;
16511
16512 if (!pub) {
16513 return 0;
16514 }
16515 dhd = (dhd_info_t *)(pub->info);
16516 if (!dhd) {
16517 return 0;
16518 }
16519 #endif /* CONFIG_HAS_WAKELOCK || BCMSDIO */
16520
16521 #ifdef CONFIG_HAS_WAKELOCK
16522 c = dhd->wakelock_counter;
16523 l1 = wake_lock_active(&dhd->wl_wifi);
16524 l2 = wake_lock_active(&dhd->wl_wdwake);
16525 l3 = wake_lock_active(&dhd->wl_rxwake);
16526 l4 = wake_lock_active(&dhd->wl_ctrlwake);
16527 l7 = wake_lock_active(&dhd->wl_evtwake);
16528 #ifdef BCMPCIE_OOB_HOST_WAKE
16529 l5 = wake_lock_active(&dhd->wl_intrwake);
16530 #endif /* BCMPCIE_OOB_HOST_WAKE */
16531 #ifdef DHD_USE_SCAN_WAKELOCK
16532 l6 = wake_lock_active(&dhd->wl_scanwake);
16533 #endif /* DHD_USE_SCAN_WAKELOCK */
16534 l8 = wake_lock_active(&dhd->wl_pmwake);
16535 l9 = wake_lock_active(&dhd->wl_txflwake);
16536 lock_active = (l1 || l2 || l3 || l4 || l5 || l6 || l7 || l8 || l9);
16537
16538 /* Indicate to the Host to avoid going to suspend if internal locks are up */
16539 if (lock_active) {
16540 DHD_ERROR(("%s wakelock c-%d wl-%d wd-%d rx-%d "
16541 "ctl-%d intr-%d scan-%d evt-%d, pm-%d, txfl-%d\n",
16542 __FUNCTION__, c, l1, l2, l3, l4, l5, l6, l7, l8, l9));
16543 return 1;
16544 }
16545 #elif defined(BCMSDIO)
16546 if (dhd && (dhd->wakelock_counter > 0) && dhd_bus_dev_pm_enabled(pub)) {
16547 return 1;
16548 }
16549 #endif /* defined(BCMSDIO) */
16550 return 0;
16551 }
16552
net_os_wake_unlock(struct net_device * dev)16553 int net_os_wake_unlock(struct net_device *dev)
16554 {
16555 dhd_info_t *dhd = DHD_DEV_INFO(dev);
16556 int ret = 0;
16557
16558 if (dhd)
16559 ret = dhd_os_wake_unlock(&dhd->pub);
16560 return ret;
16561 }
16562
dhd_os_wd_wake_lock(dhd_pub_t * pub)16563 int dhd_os_wd_wake_lock(dhd_pub_t *pub)
16564 {
16565 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
16566 unsigned long flags;
16567 int ret = 0;
16568
16569 if (dhd) {
16570 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
16571 if (dhd->wakelock_wd_counter == 0 && !dhd->waive_wakelock) {
16572 #ifdef CONFIG_HAS_WAKELOCK
16573 /* if wakelock_wd_counter was never used : lock it at once */
16574 wake_lock(&dhd->wl_wdwake);
16575 #endif // endif
16576 }
16577 dhd->wakelock_wd_counter++;
16578 ret = dhd->wakelock_wd_counter;
16579 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
16580 }
16581 return ret;
16582 }
16583
dhd_os_wd_wake_unlock(dhd_pub_t * pub)16584 int dhd_os_wd_wake_unlock(dhd_pub_t *pub)
16585 {
16586 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
16587 unsigned long flags;
16588 int ret = 0;
16589
16590 if (dhd) {
16591 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
16592 if (dhd->wakelock_wd_counter > 0) {
16593 dhd->wakelock_wd_counter = 0;
16594 if (!dhd->waive_wakelock) {
16595 #ifdef CONFIG_HAS_WAKELOCK
16596 wake_unlock(&dhd->wl_wdwake);
16597 #endif // endif
16598 }
16599 }
16600 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
16601 }
16602 return ret;
16603 }
16604
16605 #ifdef BCMPCIE_OOB_HOST_WAKE
16606 void
dhd_os_oob_irq_wake_lock_timeout(dhd_pub_t * pub,int val)16607 dhd_os_oob_irq_wake_lock_timeout(dhd_pub_t *pub, int val)
16608 {
16609 #ifdef CONFIG_HAS_WAKELOCK
16610 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
16611
16612 if (dhd) {
16613 wake_lock_timeout(&dhd->wl_intrwake, msecs_to_jiffies(val));
16614 }
16615 #endif /* CONFIG_HAS_WAKELOCK */
16616 }
16617
16618 void
dhd_os_oob_irq_wake_unlock(dhd_pub_t * pub)16619 dhd_os_oob_irq_wake_unlock(dhd_pub_t *pub)
16620 {
16621 #ifdef CONFIG_HAS_WAKELOCK
16622 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
16623
16624 if (dhd) {
16625 /* if wl_intrwake is active, unlock it */
16626 if (wake_lock_active(&dhd->wl_intrwake)) {
16627 wake_unlock(&dhd->wl_intrwake);
16628 }
16629 }
16630 #endif /* CONFIG_HAS_WAKELOCK */
16631 }
16632 #endif /* BCMPCIE_OOB_HOST_WAKE */
16633
16634 #ifdef DHD_USE_SCAN_WAKELOCK
16635 void
dhd_os_scan_wake_lock_timeout(dhd_pub_t * pub,int val)16636 dhd_os_scan_wake_lock_timeout(dhd_pub_t *pub, int val)
16637 {
16638 #ifdef CONFIG_HAS_WAKELOCK
16639 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
16640
16641 if (dhd) {
16642 wake_lock_timeout(&dhd->wl_scanwake, msecs_to_jiffies(val));
16643 }
16644 #endif /* CONFIG_HAS_WAKELOCK */
16645 }
16646
16647 void
dhd_os_scan_wake_unlock(dhd_pub_t * pub)16648 dhd_os_scan_wake_unlock(dhd_pub_t *pub)
16649 {
16650 #ifdef CONFIG_HAS_WAKELOCK
16651 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
16652
16653 if (dhd) {
16654 /* if wl_scanwake is active, unlock it */
16655 if (wake_lock_active(&dhd->wl_scanwake)) {
16656 wake_unlock(&dhd->wl_scanwake);
16657 }
16658 }
16659 #endif /* CONFIG_HAS_WAKELOCK */
16660 }
16661 #endif /* DHD_USE_SCAN_WAKELOCK */
16662
16663 /* waive wakelocks for operations such as IOVARs in suspend function, must be closed
16664 * by a paired function call to dhd_wakelock_restore. returns current wakelock counter
16665 */
dhd_os_wake_lock_waive(dhd_pub_t * pub)16666 int dhd_os_wake_lock_waive(dhd_pub_t *pub)
16667 {
16668 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
16669 unsigned long flags;
16670 int ret = 0;
16671
16672 if (dhd && (dhd->dhd_state & DHD_ATTACH_STATE_WAKELOCKS_INIT)) {
16673 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
16674
16675 /* dhd_wakelock_waive/dhd_wakelock_restore must be paired */
16676 if (dhd->waive_wakelock == FALSE) {
16677 #ifdef DHD_TRACE_WAKE_LOCK
16678 if (atomic_read(&trace_wklock_onoff)) {
16679 STORE_WKLOCK_RECORD(DHD_WAIVE_LOCK);
16680 }
16681 #endif /* DHD_TRACE_WAKE_LOCK */
16682 /* record current lock status */
16683 dhd->wakelock_before_waive = dhd->wakelock_counter;
16684 dhd->waive_wakelock = TRUE;
16685 }
16686 ret = dhd->wakelock_wd_counter;
16687 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
16688 }
16689 return ret;
16690 }
16691
dhd_os_wake_lock_restore(dhd_pub_t * pub)16692 int dhd_os_wake_lock_restore(dhd_pub_t *pub)
16693 {
16694 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
16695 unsigned long flags;
16696 int ret = 0;
16697
16698 if (!dhd)
16699 return 0;
16700 if ((dhd->dhd_state & DHD_ATTACH_STATE_WAKELOCKS_INIT) == 0)
16701 return 0;
16702
16703 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
16704
16705 /* dhd_wakelock_waive/dhd_wakelock_restore must be paired */
16706 if (!dhd->waive_wakelock)
16707 goto exit;
16708
16709 dhd->waive_wakelock = FALSE;
16710 /* if somebody else acquires wakelock between dhd_wakelock_waive/dhd_wakelock_restore,
16711 * we need to make it up by calling wake_lock or pm_stay_awake. or if somebody releases
16712 * the lock in between, do the same by calling wake_unlock or pm_relax
16713 */
16714 #ifdef DHD_TRACE_WAKE_LOCK
16715 if (atomic_read(&trace_wklock_onoff)) {
16716 STORE_WKLOCK_RECORD(DHD_RESTORE_LOCK);
16717 }
16718 #endif /* DHD_TRACE_WAKE_LOCK */
16719
16720 if (dhd->wakelock_before_waive == 0 && dhd->wakelock_counter > 0) {
16721 #ifdef CONFIG_HAS_WAKELOCK
16722 wake_lock(&dhd->wl_wifi);
16723 #elif defined(BCMSDIO)
16724 dhd_bus_dev_pm_stay_awake(&dhd->pub);
16725 #endif // endif
16726 } else if (dhd->wakelock_before_waive > 0 && dhd->wakelock_counter == 0) {
16727 #ifdef CONFIG_HAS_WAKELOCK
16728 wake_unlock(&dhd->wl_wifi);
16729 #elif defined(BCMSDIO)
16730 dhd_bus_dev_pm_relax(&dhd->pub);
16731 #endif // endif
16732 }
16733 dhd->wakelock_before_waive = 0;
16734 exit:
16735 ret = dhd->wakelock_wd_counter;
16736 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
16737 return ret;
16738 }
16739
dhd_os_wake_lock_init(struct dhd_info * dhd)16740 void dhd_os_wake_lock_init(struct dhd_info *dhd)
16741 {
16742 DHD_TRACE(("%s: initialize wake_lock_counters\n", __FUNCTION__));
16743 dhd->wakelock_counter = 0;
16744 dhd->wakelock_rx_timeout_enable = 0;
16745 dhd->wakelock_ctrl_timeout_enable = 0;
16746 /* wakelocks prevent a system from going into a low power state */
16747 #ifdef CONFIG_HAS_WAKELOCK
16748 // terence 20161023: can not destroy wl_wifi when wlan down, it will happen null pointer in dhd_ioctl_entry
16749 wake_lock_init(&dhd->wl_rxwake, WAKE_LOCK_SUSPEND, "wlan_rx_wake");
16750 wake_lock_init(&dhd->wl_ctrlwake, WAKE_LOCK_SUSPEND, "wlan_ctrl_wake");
16751 wake_lock_init(&dhd->wl_evtwake, WAKE_LOCK_SUSPEND, "wlan_evt_wake");
16752 wake_lock_init(&dhd->wl_pmwake, WAKE_LOCK_SUSPEND, "wlan_pm_wake");
16753 wake_lock_init(&dhd->wl_txflwake, WAKE_LOCK_SUSPEND, "wlan_txfl_wake");
16754 #ifdef BCMPCIE_OOB_HOST_WAKE
16755 wake_lock_init(&dhd->wl_intrwake, WAKE_LOCK_SUSPEND, "wlan_oob_irq_wake");
16756 #endif /* BCMPCIE_OOB_HOST_WAKE */
16757 #ifdef DHD_USE_SCAN_WAKELOCK
16758 wake_lock_init(&dhd->wl_scanwake, WAKE_LOCK_SUSPEND, "wlan_scan_wake");
16759 #endif /* DHD_USE_SCAN_WAKELOCK */
16760 #endif /* CONFIG_HAS_WAKELOCK */
16761 #ifdef DHD_TRACE_WAKE_LOCK
16762 dhd_wk_lock_trace_init(dhd);
16763 #endif /* DHD_TRACE_WAKE_LOCK */
16764 }
16765
dhd_os_wake_lock_destroy(struct dhd_info * dhd)16766 void dhd_os_wake_lock_destroy(struct dhd_info *dhd)
16767 {
16768 DHD_TRACE(("%s: deinit wake_lock_counters\n", __FUNCTION__));
16769 #ifdef CONFIG_HAS_WAKELOCK
16770 dhd->wakelock_counter = 0;
16771 dhd->wakelock_rx_timeout_enable = 0;
16772 dhd->wakelock_ctrl_timeout_enable = 0;
16773 // terence 20161023: can not destroy wl_wifi when wlan down, it will happen null pointer in dhd_ioctl_entry
16774 wake_lock_destroy(&dhd->wl_rxwake);
16775 wake_lock_destroy(&dhd->wl_ctrlwake);
16776 wake_lock_destroy(&dhd->wl_evtwake);
16777 wake_lock_destroy(&dhd->wl_pmwake);
16778 wake_lock_destroy(&dhd->wl_txflwake);
16779 #ifdef BCMPCIE_OOB_HOST_WAKE
16780 wake_lock_destroy(&dhd->wl_intrwake);
16781 #endif /* BCMPCIE_OOB_HOST_WAKE */
16782 #ifdef DHD_USE_SCAN_WAKELOCK
16783 wake_lock_destroy(&dhd->wl_scanwake);
16784 #endif /* DHD_USE_SCAN_WAKELOCK */
16785 #ifdef DHD_TRACE_WAKE_LOCK
16786 dhd_wk_lock_trace_deinit(dhd);
16787 #endif /* DHD_TRACE_WAKE_LOCK */
16788 #endif /* CONFIG_HAS_WAKELOCK */
16789 }
16790
dhd_os_check_if_up(dhd_pub_t * pub)16791 bool dhd_os_check_if_up(dhd_pub_t *pub)
16792 {
16793 if (!pub)
16794 return FALSE;
16795 return pub->up;
16796 }
16797
16798 /* function to collect firmware, chip id and chip version info */
dhd_set_version_info(dhd_pub_t * dhdp,char * fw)16799 void dhd_set_version_info(dhd_pub_t *dhdp, char *fw)
16800 {
16801 int i;
16802
16803 i = snprintf(info_string, sizeof(info_string),
16804 " Driver: %s\n Firmware: %s\n CLM: %s ", EPI_VERSION_STR, fw, clm_version);
16805 printf("%s\n", info_string);
16806
16807 if (!dhdp)
16808 return;
16809
16810 i = snprintf(&info_string[i], sizeof(info_string) - i,
16811 "\n Chip: %x Rev %x", dhd_conf_get_chip(dhdp),
16812 dhd_conf_get_chiprev(dhdp));
16813 }
16814
dhd_ioctl_entry_local(struct net_device * net,wl_ioctl_t * ioc,int cmd)16815 int dhd_ioctl_entry_local(struct net_device *net, wl_ioctl_t *ioc, int cmd)
16816 {
16817 int ifidx;
16818 int ret = 0;
16819 dhd_info_t *dhd = NULL;
16820
16821 if (!net || !DEV_PRIV(net)) {
16822 DHD_ERROR(("%s invalid parameter net %p dev_priv %p\n",
16823 __FUNCTION__, net, DEV_PRIV(net)));
16824 return -EINVAL;
16825 }
16826
16827 dhd = DHD_DEV_INFO(net);
16828 if (!dhd)
16829 return -EINVAL;
16830
16831 ifidx = dhd_net2idx(dhd, net);
16832 if (ifidx == DHD_BAD_IF) {
16833 DHD_ERROR(("%s bad ifidx\n", __FUNCTION__));
16834 return -ENODEV;
16835 }
16836
16837 DHD_OS_WAKE_LOCK(&dhd->pub);
16838 DHD_PERIM_LOCK(&dhd->pub);
16839
16840 ret = dhd_wl_ioctl(&dhd->pub, ifidx, ioc, ioc->buf, ioc->len);
16841 dhd_check_hang(net, &dhd->pub, ret);
16842
16843 DHD_PERIM_UNLOCK(&dhd->pub);
16844 DHD_OS_WAKE_UNLOCK(&dhd->pub);
16845
16846 return ret;
16847 }
16848
dhd_os_check_hang(dhd_pub_t * dhdp,int ifidx,int ret)16849 bool dhd_os_check_hang(dhd_pub_t *dhdp, int ifidx, int ret)
16850 {
16851 struct net_device *net;
16852
16853 net = dhd_idx2net(dhdp, ifidx);
16854 if (!net) {
16855 DHD_ERROR(("%s : Invalid index : %d\n", __FUNCTION__, ifidx));
16856 return -EINVAL;
16857 }
16858
16859 return dhd_check_hang(net, dhdp, ret);
16860 }
16861
16862 /* Return instance */
dhd_get_instance(dhd_pub_t * dhdp)16863 int dhd_get_instance(dhd_pub_t *dhdp)
16864 {
16865 return dhdp->info->unit;
16866 }
16867
16868 #if defined(WL_CFG80211) && defined(SUPPORT_DEEP_SLEEP)
16869 #define MAX_TRY_CNT 5 /* Number of tries to disable deepsleep */
dhd_deepsleep(struct net_device * dev,int flag)16870 int dhd_deepsleep(struct net_device *dev, int flag)
16871 {
16872 char iovbuf[20];
16873 uint powervar = 0;
16874 dhd_info_t *dhd;
16875 dhd_pub_t *dhdp;
16876 int cnt = 0;
16877 int ret = 0;
16878
16879 dhd = DHD_DEV_INFO(dev);
16880 dhdp = &dhd->pub;
16881
16882 switch (flag) {
16883 case 1 : /* Deepsleep on */
16884 DHD_ERROR(("[WiFi] Deepsleep On\n"));
16885 /* give some time to sysioc_work before deepsleep */
16886 OSL_SLEEP(200);
16887 #ifdef PKT_FILTER_SUPPORT
16888 /* disable pkt filter */
16889 dhd_enable_packet_filter(0, dhdp);
16890 #endif /* PKT_FILTER_SUPPORT */
16891 /* Disable MPC */
16892 powervar = 0;
16893 ret = dhd_iovar(dhdp, 0, "mpc", (char *)&powervar, sizeof(powervar), NULL,
16894 0, TRUE);
16895
16896 /* Enable Deepsleep */
16897 powervar = 1;
16898 ret = dhd_iovar(dhdp, 0, "deepsleep", (char *)&powervar, sizeof(powervar),
16899 NULL, 0, TRUE);
16900 break;
16901
16902 case 0: /* Deepsleep Off */
16903 DHD_ERROR(("[WiFi] Deepsleep Off\n"));
16904
16905 /* Disable Deepsleep */
16906 for (cnt = 0; cnt < MAX_TRY_CNT; cnt++) {
16907 powervar = 0;
16908 ret = dhd_iovar(dhdp, 0, "deepsleep", (char *)&powervar,
16909 sizeof(powervar), NULL, 0, TRUE);
16910
16911 ret = dhd_iovar(dhdp, 0, "deepsleep", (char *)&powervar,
16912 sizeof(powervar), iovbuf, sizeof(iovbuf), FALSE);
16913 if (ret < 0) {
16914 DHD_ERROR(("the error of dhd deepsleep status"
16915 " ret value :%d\n", ret));
16916 } else {
16917 if (!(*(int *)iovbuf)) {
16918 DHD_ERROR(("deepsleep mode is 0,"
16919 " count: %d\n", cnt));
16920 break;
16921 }
16922 }
16923 }
16924
16925 /* Enable MPC */
16926 powervar = 1;
16927 ret = dhd_iovar(dhdp, 0, "mpc", (char *)&powervar, sizeof(powervar), NULL,
16928 0, TRUE);
16929 break;
16930 }
16931
16932 return 0;
16933 }
16934 #endif /* WL_CFG80211 && SUPPORT_DEEP_SLEEP */
16935
16936 #ifdef PROP_TXSTATUS
16937
dhd_wlfc_plat_init(void * dhd)16938 void dhd_wlfc_plat_init(void *dhd)
16939 {
16940 #ifdef USE_DYNAMIC_F2_BLKSIZE
16941 dhdsdio_func_blocksize((dhd_pub_t *)dhd, 2, DYNAMIC_F2_BLKSIZE_FOR_NONLEGACY);
16942 #endif /* USE_DYNAMIC_F2_BLKSIZE */
16943 return;
16944 }
16945
dhd_wlfc_plat_deinit(void * dhd)16946 void dhd_wlfc_plat_deinit(void *dhd)
16947 {
16948 #ifdef USE_DYNAMIC_F2_BLKSIZE
16949 dhdsdio_func_blocksize((dhd_pub_t *)dhd, 2, sd_f2_blocksize);
16950 #endif /* USE_DYNAMIC_F2_BLKSIZE */
16951 return;
16952 }
16953
dhd_wlfc_skip_fc(void * dhdp,uint8 idx)16954 bool dhd_wlfc_skip_fc(void * dhdp, uint8 idx)
16955 {
16956 #ifdef SKIP_WLFC_ON_CONCURRENT
16957
16958 #ifdef WL_CFG80211
16959 struct net_device * net = dhd_idx2net((dhd_pub_t *)dhdp, idx);
16960 if (net)
16961 /* enable flow control in vsdb mode */
16962 return !(wl_cfg80211_is_concurrent_mode(net));
16963 #else
16964 return TRUE; /* skip flow control */
16965 #endif /* WL_CFG80211 */
16966
16967 #else
16968 return FALSE;
16969 #endif /* SKIP_WLFC_ON_CONCURRENT */
16970 return FALSE;
16971 }
16972 #endif /* PROP_TXSTATUS */
16973
16974 #ifdef BCMDBGFS
16975 #include <linux/debugfs.h>
16976
16977 typedef struct dhd_dbgfs {
16978 struct dentry *debugfs_dir;
16979 struct dentry *debugfs_mem;
16980 dhd_pub_t *dhdp;
16981 uint32 size;
16982 } dhd_dbgfs_t;
16983
16984 dhd_dbgfs_t g_dbgfs;
16985
16986 extern uint32 dhd_readregl(void *bp, uint32 addr);
16987 extern uint32 dhd_writeregl(void *bp, uint32 addr, uint32 data);
16988
16989 static int
dhd_dbg_state_open(struct inode * inode,struct file * file)16990 dhd_dbg_state_open(struct inode *inode, struct file *file)
16991 {
16992 file->private_data = inode->i_private;
16993 return 0;
16994 }
16995
16996 static ssize_t
dhd_dbg_state_read(struct file * file,char __user * ubuf,size_t count,loff_t * ppos)16997 dhd_dbg_state_read(struct file *file, char __user *ubuf,
16998 size_t count, loff_t *ppos)
16999 {
17000 ssize_t rval;
17001 uint32 tmp;
17002 loff_t pos = *ppos;
17003 size_t ret;
17004
17005 if (pos < 0)
17006 return -EINVAL;
17007 if (pos >= g_dbgfs.size || !count)
17008 return 0;
17009 if (count > g_dbgfs.size - pos)
17010 count = g_dbgfs.size - pos;
17011
17012 /* Basically enforce aligned 4 byte reads. It's up to the user to work out the details */
17013 tmp = dhd_readregl(g_dbgfs.dhdp->bus, file->f_pos & (~3));
17014
17015 ret = copy_to_user(ubuf, &tmp, 4);
17016 if (ret == count)
17017 return -EFAULT;
17018
17019 count -= ret;
17020 *ppos = pos + count;
17021 rval = count;
17022
17023 return rval;
17024 }
17025
17026 static ssize_t
dhd_debugfs_write(struct file * file,const char __user * ubuf,size_t count,loff_t * ppos)17027 dhd_debugfs_write(struct file *file, const char __user *ubuf, size_t count, loff_t *ppos)
17028 {
17029 loff_t pos = *ppos;
17030 size_t ret;
17031 uint32 buf;
17032
17033 if (pos < 0)
17034 return -EINVAL;
17035 if (pos >= g_dbgfs.size || !count)
17036 return 0;
17037 if (count > g_dbgfs.size - pos)
17038 count = g_dbgfs.size - pos;
17039
17040 ret = copy_from_user(&buf, ubuf, sizeof(uint32));
17041 if (ret == count)
17042 return -EFAULT;
17043
17044 /* Basically enforce aligned 4 byte writes. It's up to the user to work out the details */
17045 dhd_writeregl(g_dbgfs.dhdp->bus, file->f_pos & (~3), buf);
17046
17047 return count;
17048 }
17049
17050 loff_t
dhd_debugfs_lseek(struct file * file,loff_t off,int whence)17051 dhd_debugfs_lseek(struct file *file, loff_t off, int whence)
17052 {
17053 loff_t pos = -1;
17054
17055 switch (whence) {
17056 case 0:
17057 pos = off;
17058 break;
17059 case 1:
17060 pos = file->f_pos + off;
17061 break;
17062 case 2:
17063 pos = g_dbgfs.size - off;
17064 }
17065 return (pos < 0 || pos > g_dbgfs.size) ? -EINVAL : (file->f_pos = pos);
17066 }
17067
17068 static const struct file_operations dhd_dbg_state_ops = {
17069 .read = dhd_dbg_state_read,
17070 .write = dhd_debugfs_write,
17071 .open = dhd_dbg_state_open,
17072 .llseek = dhd_debugfs_lseek
17073 };
17074
dhd_dbgfs_create(void)17075 static void dhd_dbgfs_create(void)
17076 {
17077 if (g_dbgfs.debugfs_dir) {
17078 g_dbgfs.debugfs_mem = debugfs_create_file("mem", 0644, g_dbgfs.debugfs_dir,
17079 NULL, &dhd_dbg_state_ops);
17080 }
17081 }
17082
dhd_dbgfs_init(dhd_pub_t * dhdp)17083 void dhd_dbgfs_init(dhd_pub_t *dhdp)
17084 {
17085 g_dbgfs.dhdp = dhdp;
17086 g_dbgfs.size = 0x20000000; /* Allow access to various cores regs */
17087
17088 g_dbgfs.debugfs_dir = debugfs_create_dir("dhd", 0);
17089 if (IS_ERR(g_dbgfs.debugfs_dir)) {
17090 g_dbgfs.debugfs_dir = NULL;
17091 return;
17092 }
17093
17094 dhd_dbgfs_create();
17095
17096 return;
17097 }
17098
dhd_dbgfs_remove(void)17099 void dhd_dbgfs_remove(void)
17100 {
17101 debugfs_remove(g_dbgfs.debugfs_mem);
17102 debugfs_remove(g_dbgfs.debugfs_dir);
17103
17104 bzero((unsigned char *) &g_dbgfs, sizeof(g_dbgfs));
17105 }
17106 #endif /* BCMDBGFS */
17107
17108 #ifdef CUSTOM_SET_CPUCORE
dhd_set_cpucore(dhd_pub_t * dhd,int set)17109 void dhd_set_cpucore(dhd_pub_t *dhd, int set)
17110 {
17111 int e_dpc = 0, e_rxf = 0, retry_set = 0;
17112
17113 if (!(dhd->chan_isvht80)) {
17114 DHD_ERROR(("%s: chan_status(%d) cpucore!!!\n", __FUNCTION__, dhd->chan_isvht80));
17115 return;
17116 }
17117
17118 if (DPC_CPUCORE) {
17119 do {
17120 if (set == TRUE) {
17121 e_dpc = set_cpus_allowed_ptr(dhd->current_dpc,
17122 cpumask_of(DPC_CPUCORE));
17123 } else {
17124 e_dpc = set_cpus_allowed_ptr(dhd->current_dpc,
17125 cpumask_of(PRIMARY_CPUCORE));
17126 }
17127 if (retry_set++ > MAX_RETRY_SET_CPUCORE) {
17128 DHD_ERROR(("%s: dpc(%d) invalid cpu!\n", __FUNCTION__, e_dpc));
17129 return;
17130 }
17131 if (e_dpc < 0)
17132 OSL_SLEEP(1);
17133 } while (e_dpc < 0);
17134 }
17135 if (RXF_CPUCORE) {
17136 do {
17137 if (set == TRUE) {
17138 e_rxf = set_cpus_allowed_ptr(dhd->current_rxf,
17139 cpumask_of(RXF_CPUCORE));
17140 } else {
17141 e_rxf = set_cpus_allowed_ptr(dhd->current_rxf,
17142 cpumask_of(PRIMARY_CPUCORE));
17143 }
17144 if (retry_set++ > MAX_RETRY_SET_CPUCORE) {
17145 DHD_ERROR(("%s: rxf(%d) invalid cpu!\n", __FUNCTION__, e_rxf));
17146 return;
17147 }
17148 if (e_rxf < 0)
17149 OSL_SLEEP(1);
17150 } while (e_rxf < 0);
17151 }
17152 DHD_TRACE(("%s: set(%d) cpucore success!\n", __FUNCTION__, set));
17153
17154 return;
17155 }
17156 #endif /* CUSTOM_SET_CPUCORE */
17157
17158 #ifdef DHD_MCAST_REGEN
17159 /* Get interface specific ap_isolate configuration */
dhd_get_mcast_regen_bss_enable(dhd_pub_t * dhdp,uint32 idx)17160 int dhd_get_mcast_regen_bss_enable(dhd_pub_t *dhdp, uint32 idx)
17161 {
17162 dhd_info_t *dhd = dhdp->info;
17163 dhd_if_t *ifp;
17164
17165 ASSERT(idx < DHD_MAX_IFS);
17166
17167 ifp = dhd->iflist[idx];
17168
17169 return ifp->mcast_regen_bss_enable;
17170 }
17171
17172 /* Set interface specific mcast_regen configuration */
dhd_set_mcast_regen_bss_enable(dhd_pub_t * dhdp,uint32 idx,int val)17173 int dhd_set_mcast_regen_bss_enable(dhd_pub_t *dhdp, uint32 idx, int val)
17174 {
17175 dhd_info_t *dhd = dhdp->info;
17176 dhd_if_t *ifp;
17177
17178 ASSERT(idx < DHD_MAX_IFS);
17179
17180 ifp = dhd->iflist[idx];
17181
17182 ifp->mcast_regen_bss_enable = val;
17183
17184 /* Disable rx_pkt_chain feature for interface, if mcast_regen feature
17185 * is enabled
17186 */
17187 dhd_update_rx_pkt_chainable_state(dhdp, idx);
17188 return BCME_OK;
17189 }
17190 #endif /* DHD_MCAST_REGEN */
17191
17192 /* Get interface specific ap_isolate configuration */
dhd_get_ap_isolate(dhd_pub_t * dhdp,uint32 idx)17193 int dhd_get_ap_isolate(dhd_pub_t *dhdp, uint32 idx)
17194 {
17195 dhd_info_t *dhd = dhdp->info;
17196 dhd_if_t *ifp;
17197
17198 ASSERT(idx < DHD_MAX_IFS);
17199
17200 ifp = dhd->iflist[idx];
17201
17202 return ifp->ap_isolate;
17203 }
17204
17205 /* Set interface specific ap_isolate configuration */
dhd_set_ap_isolate(dhd_pub_t * dhdp,uint32 idx,int val)17206 int dhd_set_ap_isolate(dhd_pub_t *dhdp, uint32 idx, int val)
17207 {
17208 dhd_info_t *dhd = dhdp->info;
17209 dhd_if_t *ifp;
17210
17211 ASSERT(idx < DHD_MAX_IFS);
17212
17213 ifp = dhd->iflist[idx];
17214
17215 if (ifp)
17216 ifp->ap_isolate = val;
17217
17218 return 0;
17219 }
17220
17221 #ifdef DHD_FW_COREDUMP
dhd_schedule_memdump(dhd_pub_t * dhdp,uint8 * buf,uint32 size)17222 void dhd_schedule_memdump(dhd_pub_t *dhdp, uint8 *buf, uint32 size)
17223 {
17224 unsigned long flags = 0;
17225 dhd_dump_t *dump = NULL;
17226 dhd_info_t *dhd_info = NULL;
17227 #if !defined(DHD_DUMP_FILE_WRITE_FROM_KERNEL)
17228 log_dump_type_t type = DLD_BUF_TYPE_ALL;
17229 #endif /* !DHD_DUMP_FILE_WRITE_FROM_KERNEL */
17230
17231 dhd_info = (dhd_info_t *)dhdp->info;
17232 dump = (dhd_dump_t *)MALLOC(dhdp->osh, sizeof(dhd_dump_t));
17233 if (dump == NULL) {
17234 DHD_ERROR(("%s: dhd dump memory allocation failed\n", __FUNCTION__));
17235 return;
17236 }
17237 dump->buf = buf;
17238 dump->bufsize = size;
17239 #ifdef BCMPCIE
17240 dhd_get_hscb_info(dhdp, (void*)(&dump->hscb_buf),
17241 (uint32 *)(&dump->hscb_bufsize));
17242 #else /* BCMPCIE */
17243 dump->hscb_bufsize = 0;
17244 #endif /* BCMPCIE */
17245
17246 #ifdef DHD_LOG_DUMP
17247 dhd_print_buf_addr(dhdp, "memdump", buf, size);
17248 #if !defined(DHD_DUMP_FILE_WRITE_FROM_KERNEL)
17249 /* Print out buffer infomation */
17250 dhd_log_dump_buf_addr(dhdp, &type);
17251 #endif /* !DHD_DUMP_FILE_WRITE_FROM_KERNEL */
17252 #endif /* DHD_LOG_DUMP */
17253
17254 if (dhdp->memdump_enabled == DUMP_MEMONLY) {
17255 BUG_ON(1);
17256 }
17257
17258 #if defined(DEBUG_DNGL_INIT_FAIL) || defined(DHD_ERPOM) || \
17259 defined(DNGL_AXI_ERROR_LOGGING)
17260 if (
17261 #if defined(DEBUG_DNGL_INIT_FAIL)
17262 (dhdp->memdump_type == DUMP_TYPE_DONGLE_INIT_FAILURE) ||
17263 #endif /* DEBUG_DNGL_INIT_FAIL */
17264 #ifdef DHD_ERPOM
17265 (dhdp->memdump_type == DUMP_TYPE_DUE_TO_BT) ||
17266 #endif /* DHD_ERPOM */
17267 #ifdef DNGL_AXI_ERROR_LOGGING
17268 (dhdp->memdump_type == DUMP_TYPE_SMMU_FAULT) ||
17269 #endif /* DNGL_AXI_ERROR_LOGGING */
17270 FALSE)
17271 {
17272 #if defined(DHD_DUMP_FILE_WRITE_FROM_KERNEL) && defined(DHD_LOG_DUMP)
17273 log_dump_type_t *flush_type = NULL;
17274 #endif /* DHD_DUMP_FILE_WRITE_FROM_KERNEL && DHD_LOG_DUMP */
17275 dhd_info->scheduled_memdump = FALSE;
17276 (void)dhd_mem_dump((void *)dhdp->info, (void *)dump, 0);
17277 #if defined(DHD_DUMP_FILE_WRITE_FROM_KERNEL) && defined(DHD_LOG_DUMP)
17278 /* for dongle init fail cases, 'dhd_mem_dump' does
17279 * not call 'dhd_log_dump', so call it here.
17280 */
17281 flush_type = MALLOCZ(dhdp->osh,
17282 sizeof(log_dump_type_t));
17283 if (flush_type) {
17284 *flush_type = DLD_BUF_TYPE_ALL;
17285 DHD_ERROR(("%s: calling log dump.. \n", __FUNCTION__));
17286 dhd_log_dump(dhdp->info, flush_type, 0);
17287 }
17288 #endif /* DHD_DUMP_FILE_WRITE_FROM_KERNEL && DHD_LOG_DUMP */
17289 return;
17290 }
17291 #endif /* DEBUG_DNGL_INIT_FAIL || DHD_ERPOM || DNGL_AXI_ERROR_LOGGING */
17292
17293 dhd_info->scheduled_memdump = TRUE;
17294 /* bus busy bit for mem dump will be cleared in mem dump
17295 * work item context, after mem dump file is written
17296 */
17297 DHD_GENERAL_LOCK(dhdp, flags);
17298 DHD_BUS_BUSY_SET_IN_MEMDUMP(dhdp);
17299 DHD_GENERAL_UNLOCK(dhdp, flags);
17300 DHD_ERROR(("%s: scheduling mem dump.. \n", __FUNCTION__));
17301 dhd_deferred_schedule_work(dhdp->info->dhd_deferred_wq, (void *)dump,
17302 DHD_WQ_WORK_SOC_RAM_DUMP, (void *)dhd_mem_dump, DHD_WQ_WORK_PRIORITY_HIGH);
17303 }
17304
17305 static int
dhd_mem_dump(void * handle,void * event_info,u8 event)17306 dhd_mem_dump(void *handle, void *event_info, u8 event)
17307 {
17308 dhd_info_t *dhd = handle;
17309 dhd_pub_t *dhdp = NULL;
17310 unsigned long flags = 0;
17311 int ret = 0;
17312 dhd_dump_t *dump = NULL;
17313
17314 DHD_ERROR(("%s: ENTER, memdump type %u\n", __FUNCTION__, dhd->pub.memdump_type));
17315
17316 if (!dhd) {
17317 DHD_ERROR(("%s: dhd is NULL\n", __FUNCTION__));
17318 return -ENODEV;
17319 }
17320
17321 dhdp = &dhd->pub;
17322 if (!dhdp) {
17323 DHD_ERROR(("%s: dhdp is NULL\n", __FUNCTION__));
17324 return -ENODEV;
17325 }
17326
17327 DHD_GENERAL_LOCK(dhdp, flags);
17328 if (DHD_BUS_CHECK_DOWN_OR_DOWN_IN_PROGRESS(dhdp)) {
17329 DHD_GENERAL_UNLOCK(dhdp, flags);
17330 DHD_ERROR(("%s: bus is down! can't collect mem dump. \n", __FUNCTION__));
17331 ret = -ENODEV;
17332 goto exit;
17333 }
17334 DHD_GENERAL_UNLOCK(dhdp, flags);
17335
17336 #ifdef DHD_SSSR_DUMP
17337 if (dhdp->sssr_inited && dhdp->collect_sssr) {
17338 dhdpcie_sssr_dump(dhdp);
17339 }
17340 dhdp->collect_sssr = FALSE;
17341 #endif /* DHD_SSSR_DUMP */
17342 #if defined(WL_CFG80211) && defined(DHD_FILE_DUMP_EVENT)
17343 dhd_wait_for_file_dump(dhdp);
17344 #endif /* WL_CFG80211 && DHD_FILE_DUMP_EVENT */
17345
17346 dump = (dhd_dump_t *)event_info;
17347 if (!dump) {
17348 DHD_ERROR(("%s: dump is NULL\n", __FUNCTION__));
17349 ret = -EINVAL;
17350 goto exit;
17351 }
17352
17353 /*
17354 * If kernel does not have file write access enabled
17355 * then skip writing dumps to files.
17356 * The dumps will be pushed to HAL layer which will
17357 * write into files
17358 */
17359 #ifdef DHD_DUMP_FILE_WRITE_FROM_KERNEL
17360
17361 if (write_dump_to_file(&dhd->pub, dump->buf, dump->bufsize, "mem_dump")) {
17362 DHD_ERROR(("%s: writing SoC_RAM dump to the file failed\n", __FUNCTION__));
17363 #ifdef DHD_DEBUG_UART
17364 dhd->pub.memdump_success = FALSE;
17365 #endif /* DHD_DEBUG_UART */
17366 }
17367
17368 /* directly call dhd_log_dump for debug_dump collection from the mem_dump work queue
17369 * context, no need to schedule another work queue for log dump. In case of
17370 * user initiated DEBUG_DUMP wpa_cli command (DUMP_TYPE_BY_SYSDUMP),
17371 * cfg layer is itself scheduling the log_dump work queue.
17372 * that path is not disturbed. If 'dhd_mem_dump' is called directly then we will not
17373 * collect debug_dump as it may be called from non-sleepable context.
17374 */
17375 #ifdef DHD_LOG_DUMP
17376 if (dhd->scheduled_memdump &&
17377 dhdp->memdump_type != DUMP_TYPE_BY_SYSDUMP) {
17378 log_dump_type_t *flush_type = MALLOCZ(dhdp->osh,
17379 sizeof(log_dump_type_t));
17380 if (flush_type) {
17381 *flush_type = DLD_BUF_TYPE_ALL;
17382 DHD_ERROR(("%s: calling log dump.. \n", __FUNCTION__));
17383 dhd_log_dump(dhd, flush_type, 0);
17384 }
17385 }
17386 #endif /* DHD_LOG_DUMP */
17387
17388 clear_debug_dump_time(dhdp->debug_dump_time_str);
17389
17390 /* before calling bug on, wait for other logs to be dumped.
17391 * we cannot wait in case dhd_mem_dump is called directly
17392 * as it may not be in a sleepable context
17393 */
17394 if (dhd->scheduled_memdump) {
17395 uint bitmask = 0;
17396 int timeleft = 0;
17397 #ifdef DHD_SSSR_DUMP
17398 bitmask |= DHD_BUS_BUSY_IN_SSSRDUMP;
17399 #endif // endif
17400 if (bitmask != 0) {
17401 DHD_ERROR(("%s: wait to clear dhd_bus_busy_state: 0x%x\n",
17402 __FUNCTION__, dhdp->dhd_bus_busy_state));
17403 timeleft = dhd_os_busbusy_wait_bitmask(dhdp,
17404 &dhdp->dhd_bus_busy_state, bitmask, 0);
17405 if ((timeleft == 0) || (timeleft == 1)) {
17406 DHD_ERROR(("%s: Timed out dhd_bus_busy_state=0x%x\n",
17407 __FUNCTION__, dhdp->dhd_bus_busy_state));
17408 }
17409 }
17410 }
17411
17412 if (dump->hscb_buf && dump->hscb_bufsize) {
17413 DHD_ERROR(("%s: write HSCB dump... \n", __FUNCTION__));
17414 if (write_dump_to_file(&dhd->pub, dump->hscb_buf,
17415 dump->hscb_bufsize, "mem_dump_hscb")) {
17416 DHD_ERROR(("%s: writing HSCB dump to the file failed\n", __FUNCTION__));
17417 #ifdef DHD_DEBUG_UART
17418 dhd->pub.memdump_success = FALSE;
17419 #endif /* DHD_DEBUG_UART */
17420 }
17421 }
17422 #endif /* DHD_DUMP_FILE_WRITE_FROM_KERNEL */
17423
17424 DHD_ERROR(("%s: memdump type %u\n", __FUNCTION__, dhd->pub.memdump_type));
17425 if (dhd->pub.memdump_enabled == DUMP_MEMFILE_BUGON &&
17426 #ifdef DHD_LOG_DUMP
17427 dhd->pub.memdump_type != DUMP_TYPE_BY_SYSDUMP &&
17428 #endif /* DHD_LOG_DUMP */
17429 dhd->pub.memdump_type != DUMP_TYPE_BY_USER &&
17430 #ifdef DHD_DEBUG_UART
17431 dhd->pub.memdump_success == TRUE &&
17432 #endif /* DHD_DEBUG_UART */
17433 #ifdef DNGL_EVENT_SUPPORT
17434 dhd->pub.memdump_type != DUMP_TYPE_DONGLE_HOST_EVENT &&
17435 #endif /* DNGL_EVENT_SUPPORT */
17436 dhd->pub.memdump_type != DUMP_TYPE_CFG_VENDOR_TRIGGERED) {
17437
17438 #ifdef SHOW_LOGTRACE
17439 /* Wait till logtrace context is flushed */
17440 dhd_flush_logtrace_process(dhd);
17441 #endif /* SHOW_LOGTRACE */
17442
17443 printf("%s\n", info_string);
17444 printf("MAC %pM\n", &dhdp->mac);
17445 DHD_ERROR(("%s: call BUG_ON \n", __FUNCTION__));
17446 // BUG_ON(1);
17447 }
17448 DHD_ERROR(("%s: No BUG ON, memdump type %u \n", __FUNCTION__, dhd->pub.memdump_type));
17449
17450 exit:
17451 if (dump) {
17452 MFREE(dhd->pub.osh, dump, sizeof(dhd_dump_t));
17453 }
17454 DHD_GENERAL_LOCK(dhdp, flags);
17455 DHD_BUS_BUSY_CLEAR_IN_MEMDUMP(&dhd->pub);
17456 dhd_os_busbusy_wake(dhdp);
17457 DHD_GENERAL_UNLOCK(dhdp, flags);
17458 dhd->scheduled_memdump = FALSE;
17459 if (dhdp->hang_was_pending) {
17460 DHD_ERROR(("%s: Send pending HANG event...\n", __FUNCTION__));
17461 dhd_os_send_hang_message(dhdp);
17462 dhdp->hang_was_pending = 0;
17463 }
17464 DHD_ERROR(("%s: EXIT \n", __FUNCTION__));
17465 return ret;
17466 }
17467 #endif /* DHD_FW_COREDUMP */
17468
17469 #ifdef DHD_SSSR_DUMP
17470 int
dhd_sssr_dump_dig_buf_before(void * dev,const void * user_buf,uint32 len)17471 dhd_sssr_dump_dig_buf_before(void *dev, const void *user_buf, uint32 len)
17472 {
17473 dhd_info_t *dhd_info = *(dhd_info_t **)DHD_DEV_PRIV_CFG((struct net_device *)dev);
17474 dhd_pub_t *dhdp = &dhd_info->pub;
17475 int pos = 0, ret = BCME_ERROR;
17476 uint dig_buf_size = 0;
17477
17478 if (dhdp->sssr_reg_info.vasip_regs.vasip_sr_size) {
17479 dig_buf_size = dhdp->sssr_reg_info.vasip_regs.vasip_sr_size;
17480 } else if ((dhdp->sssr_reg_info.length > OFFSETOF(sssr_reg_info_v1_t, dig_mem_info)) &&
17481 dhdp->sssr_reg_info.dig_mem_info.dig_sr_size) {
17482 dig_buf_size = dhdp->sssr_reg_info.dig_mem_info.dig_sr_size;
17483 }
17484
17485 if (dhdp->sssr_dig_buf_before && (dhdp->sssr_dump_mode == SSSR_DUMP_MODE_SSSR)) {
17486 ret = dhd_export_debug_data((char *)dhdp->sssr_dig_buf_before,
17487 NULL, user_buf, dig_buf_size, &pos);
17488 }
17489 return ret;
17490 }
17491
17492 int
dhd_sssr_dump_dig_buf_after(void * dev,const void * user_buf,uint32 len)17493 dhd_sssr_dump_dig_buf_after(void *dev, const void *user_buf, uint32 len)
17494 {
17495 dhd_info_t *dhd_info = *(dhd_info_t **)DHD_DEV_PRIV_CFG((struct net_device *)dev);
17496 dhd_pub_t *dhdp = &dhd_info->pub;
17497 int pos = 0, ret = BCME_ERROR;
17498 uint dig_buf_size = 0;
17499
17500 if (dhdp->sssr_reg_info.vasip_regs.vasip_sr_size) {
17501 dig_buf_size = dhdp->sssr_reg_info.vasip_regs.vasip_sr_size;
17502 } else if ((dhdp->sssr_reg_info.length > OFFSETOF(sssr_reg_info_v1_t, dig_mem_info)) &&
17503 dhdp->sssr_reg_info.dig_mem_info.dig_sr_size) {
17504 dig_buf_size = dhdp->sssr_reg_info.dig_mem_info.dig_sr_size;
17505 }
17506
17507 if (dhdp->sssr_dig_buf_after) {
17508 ret = dhd_export_debug_data((char *)dhdp->sssr_dig_buf_after,
17509 NULL, user_buf, dig_buf_size, &pos);
17510 }
17511 return ret;
17512 }
17513
17514 int
dhd_sssr_dump_d11_buf_before(void * dev,const void * user_buf,uint32 len,int core)17515 dhd_sssr_dump_d11_buf_before(void *dev, const void *user_buf, uint32 len, int core)
17516 {
17517 dhd_info_t *dhd_info = *(dhd_info_t **)DHD_DEV_PRIV_CFG((struct net_device *)dev);
17518 dhd_pub_t *dhdp = &dhd_info->pub;
17519 int pos = 0, ret = BCME_ERROR;
17520
17521 if (dhdp->sssr_d11_before[core] &&
17522 dhdp->sssr_d11_outofreset[core] &&
17523 (dhdp->sssr_dump_mode == SSSR_DUMP_MODE_SSSR)) {
17524 ret = dhd_export_debug_data((char *)dhdp->sssr_d11_before[core],
17525 NULL, user_buf, len, &pos);
17526 }
17527 return ret;
17528 }
17529
17530 int
dhd_sssr_dump_d11_buf_after(void * dev,const void * user_buf,uint32 len,int core)17531 dhd_sssr_dump_d11_buf_after(void *dev, const void *user_buf, uint32 len, int core)
17532 {
17533 dhd_info_t *dhd_info = *(dhd_info_t **)DHD_DEV_PRIV_CFG((struct net_device *)dev);
17534 dhd_pub_t *dhdp = &dhd_info->pub;
17535 int pos = 0, ret = BCME_ERROR;
17536
17537 if (dhdp->sssr_d11_after[core] &&
17538 dhdp->sssr_d11_outofreset[core]) {
17539 ret = dhd_export_debug_data((char *)dhdp->sssr_d11_after[core],
17540 NULL, user_buf, len, &pos);
17541 }
17542 return ret;
17543 }
17544
17545 static void
dhd_sssr_dump_to_file(dhd_info_t * dhdinfo)17546 dhd_sssr_dump_to_file(dhd_info_t* dhdinfo)
17547 {
17548 dhd_info_t *dhd = dhdinfo;
17549 dhd_pub_t *dhdp;
17550 int i;
17551 char before_sr_dump[128];
17552 char after_sr_dump[128];
17553 unsigned long flags = 0;
17554 uint dig_buf_size = 0;
17555
17556 DHD_ERROR(("%s: ENTER \n", __FUNCTION__));
17557
17558 if (!dhd) {
17559 DHD_ERROR(("%s: dhd is NULL\n", __FUNCTION__));
17560 return;
17561 }
17562
17563 dhdp = &dhd->pub;
17564
17565 DHD_GENERAL_LOCK(dhdp, flags);
17566 DHD_BUS_BUSY_SET_IN_SSSRDUMP(dhdp);
17567 if (DHD_BUS_CHECK_DOWN_OR_DOWN_IN_PROGRESS(dhdp)) {
17568 DHD_GENERAL_UNLOCK(dhdp, flags);
17569 DHD_ERROR(("%s: bus is down! can't collect sssr dump. \n", __FUNCTION__));
17570 goto exit;
17571 }
17572 DHD_GENERAL_UNLOCK(dhdp, flags);
17573
17574 for (i = 0; i < MAX_NUM_D11CORES; i++) {
17575 /* Init file name */
17576 memset(before_sr_dump, 0, sizeof(before_sr_dump));
17577 memset(after_sr_dump, 0, sizeof(after_sr_dump));
17578
17579 snprintf(before_sr_dump, sizeof(before_sr_dump), "%s_%d_%s",
17580 "sssr_dump_core", i, "before_SR");
17581 snprintf(after_sr_dump, sizeof(after_sr_dump), "%s_%d_%s",
17582 "sssr_dump_core", i, "after_SR");
17583
17584 if (dhdp->sssr_d11_before[i] && dhdp->sssr_d11_outofreset[i] &&
17585 (dhdp->sssr_dump_mode == SSSR_DUMP_MODE_SSSR)) {
17586 if (write_dump_to_file(dhdp, (uint8 *)dhdp->sssr_d11_before[i],
17587 dhdp->sssr_reg_info.mac_regs[i].sr_size, before_sr_dump)) {
17588 DHD_ERROR(("%s: writing SSSR MAIN dump before to the file failed\n",
17589 __FUNCTION__));
17590 }
17591 }
17592 if (dhdp->sssr_d11_after[i] && dhdp->sssr_d11_outofreset[i]) {
17593 if (write_dump_to_file(dhdp, (uint8 *)dhdp->sssr_d11_after[i],
17594 dhdp->sssr_reg_info.mac_regs[i].sr_size, after_sr_dump)) {
17595 DHD_ERROR(("%s: writing SSSR AUX dump after to the file failed\n",
17596 __FUNCTION__));
17597 }
17598 }
17599 }
17600
17601 if (dhdp->sssr_reg_info.vasip_regs.vasip_sr_size) {
17602 dig_buf_size = dhdp->sssr_reg_info.vasip_regs.vasip_sr_size;
17603 } else if ((dhdp->sssr_reg_info.length > OFFSETOF(sssr_reg_info_v1_t, dig_mem_info)) &&
17604 dhdp->sssr_reg_info.dig_mem_info.dig_sr_size) {
17605 dig_buf_size = dhdp->sssr_reg_info.dig_mem_info.dig_sr_size;
17606 }
17607
17608 if (dhdp->sssr_dig_buf_before && (dhdp->sssr_dump_mode == SSSR_DUMP_MODE_SSSR)) {
17609 if (write_dump_to_file(dhdp, (uint8 *)dhdp->sssr_dig_buf_before,
17610 dig_buf_size, "sssr_dump_dig_before_SR")) {
17611 DHD_ERROR(("%s: writing SSSR Dig dump before to the file failed\n",
17612 __FUNCTION__));
17613 }
17614 }
17615
17616 if (dhdp->sssr_dig_buf_after) {
17617 if (write_dump_to_file(dhdp, (uint8 *)dhdp->sssr_dig_buf_after,
17618 dig_buf_size, "sssr_dump_dig_after_SR")) {
17619 DHD_ERROR(("%s: writing SSSR Dig VASIP dump after to the file failed\n",
17620 __FUNCTION__));
17621 }
17622 }
17623
17624 exit:
17625 DHD_GENERAL_LOCK(dhdp, flags);
17626 DHD_BUS_BUSY_CLEAR_IN_SSSRDUMP(dhdp);
17627 dhd_os_busbusy_wake(dhdp);
17628 DHD_GENERAL_UNLOCK(dhdp, flags);
17629 }
17630
17631 void
dhd_write_sssr_dump(dhd_pub_t * dhdp,uint32 dump_mode)17632 dhd_write_sssr_dump(dhd_pub_t *dhdp, uint32 dump_mode)
17633 {
17634 dhdp->sssr_dump_mode = dump_mode;
17635
17636 /*
17637 * If kernel does not have file write access enabled
17638 * then skip writing dumps to files.
17639 * The dumps will be pushed to HAL layer which will
17640 * write into files
17641 */
17642 #if !defined(DHD_DUMP_FILE_WRITE_FROM_KERNEL)
17643 return;
17644 #endif /* !DHD_DUMP_FILE_WRITE_FROM_KERNEL */
17645
17646 /*
17647 * dhd_mem_dump -> dhd_sssr_dump -> dhd_write_sssr_dump
17648 * Without workqueue -
17649 * DUMP_TYPE_DONGLE_INIT_FAILURE/DUMP_TYPE_DUE_TO_BT/DUMP_TYPE_SMMU_FAULT
17650 * : These are called in own handler, not in the interrupt context
17651 * With workqueue - all other DUMP_TYPEs : dhd_mem_dump is called in workqueue
17652 * Thus, it doesn't neeed to dump SSSR in workqueue
17653 */
17654 DHD_ERROR(("%s: writing sssr dump to file... \n", __FUNCTION__));
17655 dhd_sssr_dump_to_file(dhdp->info);
17656
17657 }
17658 #endif /* DHD_SSSR_DUMP */
17659
17660 #ifdef DHD_LOG_DUMP
17661 static void
dhd_log_dump(void * handle,void * event_info,u8 event)17662 dhd_log_dump(void *handle, void *event_info, u8 event)
17663 {
17664 dhd_info_t *dhd = handle;
17665 log_dump_type_t *type = (log_dump_type_t *)event_info;
17666
17667 if (!dhd || !type) {
17668 DHD_ERROR(("%s: dhd is NULL\n", __FUNCTION__));
17669 return;
17670 }
17671
17672 #ifdef WL_CFG80211
17673 /* flush the fw side logs */
17674 wl_flush_fw_log_buffer(dhd_linux_get_primary_netdev(&dhd->pub),
17675 FW_LOGSET_MASK_ALL);
17676 #endif // endif
17677 /* there are currently 3 possible contexts from which
17678 * log dump can be scheduled -
17679 * 1.TRAP 2.supplicant DEBUG_DUMP pvt driver command
17680 * 3.HEALTH CHECK event
17681 * The concise debug info buffer is a shared resource
17682 * and in case a trap is one of the contexts then both the
17683 * scheduled work queues need to run because trap data is
17684 * essential for debugging. Hence a mutex lock is acquired
17685 * before calling do_dhd_log_dump().
17686 */
17687 DHD_ERROR(("%s: calling log dump.. \n", __FUNCTION__));
17688 dhd_os_logdump_lock(&dhd->pub);
17689 DHD_OS_WAKE_LOCK(&dhd->pub);
17690 if (do_dhd_log_dump(&dhd->pub, type) != BCME_OK) {
17691 DHD_ERROR(("%s: writing debug dump to the file failed\n", __FUNCTION__));
17692 }
17693 DHD_OS_WAKE_UNLOCK(&dhd->pub);
17694 dhd_os_logdump_unlock(&dhd->pub);
17695 }
17696
dhd_schedule_log_dump(dhd_pub_t * dhdp,void * type)17697 void dhd_schedule_log_dump(dhd_pub_t *dhdp, void *type)
17698 {
17699 DHD_ERROR(("%s: scheduling log dump.. \n", __FUNCTION__));
17700 dhd_deferred_schedule_work(dhdp->info->dhd_deferred_wq,
17701 type, DHD_WQ_WORK_DHD_LOG_DUMP,
17702 dhd_log_dump, DHD_WQ_WORK_PRIORITY_HIGH);
17703 }
17704
17705 static void
dhd_print_buf_addr(dhd_pub_t * dhdp,char * name,void * buf,unsigned int size)17706 dhd_print_buf_addr(dhd_pub_t *dhdp, char *name, void *buf, unsigned int size)
17707 {
17708 #ifdef DHD_FW_COREDUMP
17709 if ((dhdp->memdump_enabled == DUMP_MEMONLY) ||
17710 (dhdp->memdump_enabled == DUMP_MEMFILE_BUGON) ||
17711 (dhdp->memdump_type == DUMP_TYPE_SMMU_FAULT))
17712 #else
17713 if (dhdp->memdump_type == DUMP_TYPE_SMMU_FAULT)
17714 #endif
17715 {
17716 #if defined(CONFIG_ARM64)
17717 DHD_ERROR(("-------- %s: buf(va)=%llx, buf(pa)=%llx, bufsize=%d\n",
17718 name, (uint64)buf, (uint64)__virt_to_phys((ulong)buf), size));
17719 #elif defined(__ARM_ARCH_7A__)
17720 DHD_ERROR(("-------- %s: buf(va)=%x, buf(pa)=%x, bufsize=%d\n",
17721 name, (uint32)buf, (uint32)__virt_to_phys((ulong)buf), size));
17722 #endif /* __ARM_ARCH_7A__ */
17723 }
17724 }
17725
17726 static void
dhd_log_dump_buf_addr(dhd_pub_t * dhdp,log_dump_type_t * type)17727 dhd_log_dump_buf_addr(dhd_pub_t *dhdp, log_dump_type_t *type)
17728 {
17729 int i;
17730 unsigned long wr_size = 0;
17731 struct dhd_log_dump_buf *dld_buf = &g_dld_buf[0];
17732 size_t log_size = 0;
17733 char buf_name[DHD_PRINT_BUF_NAME_LEN];
17734 dhd_dbg_ring_t *ring = NULL;
17735
17736 BCM_REFERENCE(ring);
17737
17738 for (i = 0; i < DLD_BUFFER_NUM; i++) {
17739 dld_buf = &g_dld_buf[i];
17740 log_size = (unsigned long)dld_buf->max -
17741 (unsigned long)dld_buf->buffer;
17742 if (dld_buf->wraparound) {
17743 wr_size = log_size;
17744 } else {
17745 wr_size = (unsigned long)dld_buf->present -
17746 (unsigned long)dld_buf->front;
17747 }
17748 scnprintf(buf_name, sizeof(buf_name), "dlb_buf[%d]", i);
17749 dhd_print_buf_addr(dhdp, buf_name, dld_buf, dld_buf_size[i]);
17750 scnprintf(buf_name, sizeof(buf_name), "dlb_buf[%d] buffer", i);
17751 dhd_print_buf_addr(dhdp, buf_name, dld_buf->buffer, wr_size);
17752 scnprintf(buf_name, sizeof(buf_name), "dlb_buf[%d] present", i);
17753 dhd_print_buf_addr(dhdp, buf_name, dld_buf->present, wr_size);
17754 scnprintf(buf_name, sizeof(buf_name), "dlb_buf[%d] front", i);
17755 dhd_print_buf_addr(dhdp, buf_name, dld_buf->front, wr_size);
17756 }
17757
17758 #ifdef EWP_ECNTRS_LOGGING
17759 /* periodic flushing of ecounters is NOT supported */
17760 if (*type == DLD_BUF_TYPE_ALL &&
17761 logdump_ecntr_enable &&
17762 dhdp->ecntr_dbg_ring) {
17763
17764 ring = (dhd_dbg_ring_t *)dhdp->ecntr_dbg_ring;
17765 dhd_print_buf_addr(dhdp, "ecntr_dbg_ring", ring, LOG_DUMP_ECNTRS_MAX_BUFSIZE);
17766 dhd_print_buf_addr(dhdp, "ecntr_dbg_ring ring_buf", ring->ring_buf,
17767 LOG_DUMP_ECNTRS_MAX_BUFSIZE);
17768 }
17769 #endif /* EWP_ECNTRS_LOGGING */
17770
17771 #ifdef DHD_STATUS_LOGGING
17772 if (dhdp->statlog) {
17773 dhd_print_buf_addr(dhdp, "statlog_logbuf", dhd_statlog_get_logbuf(dhdp),
17774 dhd_statlog_get_logbuf_len(dhdp));
17775 }
17776 #endif /* DHD_STATUS_LOGGING */
17777
17778 #ifdef EWP_RTT_LOGGING
17779 /* periodic flushing of ecounters is NOT supported */
17780 if (*type == DLD_BUF_TYPE_ALL &&
17781 logdump_rtt_enable &&
17782 dhdp->rtt_dbg_ring) {
17783
17784 ring = (dhd_dbg_ring_t *)dhdp->rtt_dbg_ring;
17785 dhd_print_buf_addr(dhdp, "rtt_dbg_ring", ring, LOG_DUMP_RTT_MAX_BUFSIZE);
17786 dhd_print_buf_addr(dhdp, "rtt_dbg_ring ring_buf", ring->ring_buf,
17787 LOG_DUMP_RTT_MAX_BUFSIZE);
17788 }
17789 #endif /* EWP_RTT_LOGGING */
17790
17791 #ifdef BCMPCIE
17792 if (dhdp->dongle_trap_occured && dhdp->extended_trap_data) {
17793 dhd_print_buf_addr(dhdp, "extended_trap_data", dhdp->extended_trap_data,
17794 BCMPCIE_EXT_TRAP_DATA_MAXLEN);
17795 }
17796 #endif /* BCMPCIE */
17797
17798 #if defined(DHD_FW_COREDUMP) && defined(DNGL_EVENT_SUPPORT)
17799 /* if health check event was received */
17800 if (dhdp->memdump_type == DUMP_TYPE_DONGLE_HOST_EVENT) {
17801 dhd_print_buf_addr(dhdp, "health_chk_event_data", dhdp->health_chk_event_data,
17802 HEALTH_CHK_BUF_SIZE);
17803 }
17804 #endif /* DHD_FW_COREDUMP && DNGL_EVENT_SUPPORT */
17805
17806 /* append the concise debug information */
17807 if (dhdp->concise_dbg_buf) {
17808 dhd_print_buf_addr(dhdp, "concise_dbg_buf", dhdp->concise_dbg_buf,
17809 CONCISE_DUMP_BUFLEN);
17810 }
17811 }
17812
17813 #ifdef DHD_SSSR_DUMP
17814 int
dhdpcie_sssr_dump_get_before_after_len(dhd_pub_t * dhd,uint32 * arr_len)17815 dhdpcie_sssr_dump_get_before_after_len(dhd_pub_t *dhd, uint32 *arr_len)
17816 {
17817 int i = 0;
17818
17819 DHD_ERROR(("%s\n", __FUNCTION__));
17820
17821 /* core 0 */
17822 i = 0;
17823 if (dhd->sssr_d11_before[i] && dhd->sssr_d11_outofreset[i] &&
17824 (dhd->sssr_dump_mode == SSSR_DUMP_MODE_SSSR)) {
17825 arr_len[SSSR_C0_D11_BEFORE] = (dhd->sssr_reg_info.mac_regs[i].sr_size);
17826 DHD_ERROR(("%s: arr_len[SSSR_C0_D11_BEFORE] : %d\n", __FUNCTION__,
17827 arr_len[SSSR_C0_D11_BEFORE]));
17828 #ifdef DHD_LOG_DUMP
17829 dhd_print_buf_addr(dhd, "SSSR_C0_D11_BEFORE",
17830 dhd->sssr_d11_before[i], arr_len[SSSR_C0_D11_BEFORE]);
17831 #endif /* DHD_LOG_DUMP */
17832 }
17833 if (dhd->sssr_d11_after[i] && dhd->sssr_d11_outofreset[i]) {
17834 arr_len[SSSR_C0_D11_AFTER] = (dhd->sssr_reg_info.mac_regs[i].sr_size);
17835 DHD_ERROR(("%s: arr_len[SSSR_C0_D11_AFTER] : %d\n", __FUNCTION__,
17836 arr_len[SSSR_C0_D11_AFTER]));
17837 #ifdef DHD_LOG_DUMP
17838 dhd_print_buf_addr(dhd, "SSSR_C0_D11_AFTER",
17839 dhd->sssr_d11_after[i], arr_len[SSSR_C0_D11_AFTER]);
17840 #endif /* DHD_LOG_DUMP */
17841 }
17842
17843 /* core 1 */
17844 i = 1;
17845 if (dhd->sssr_d11_before[i] && dhd->sssr_d11_outofreset[i] &&
17846 (dhd->sssr_dump_mode == SSSR_DUMP_MODE_SSSR)) {
17847 arr_len[SSSR_C1_D11_BEFORE] = (dhd->sssr_reg_info.mac_regs[i].sr_size);
17848 DHD_ERROR(("%s: arr_len[SSSR_C1_D11_BEFORE] : %d\n", __FUNCTION__,
17849 arr_len[SSSR_C1_D11_BEFORE]));
17850 #ifdef DHD_LOG_DUMP
17851 dhd_print_buf_addr(dhd, "SSSR_C1_D11_BEFORE",
17852 dhd->sssr_d11_before[i], arr_len[SSSR_C1_D11_BEFORE]);
17853 #endif /* DHD_LOG_DUMP */
17854 }
17855 if (dhd->sssr_d11_after[i] && dhd->sssr_d11_outofreset[i]) {
17856 arr_len[SSSR_C1_D11_AFTER] = (dhd->sssr_reg_info.mac_regs[i].sr_size);
17857 DHD_ERROR(("%s: arr_len[SSSR_C1_D11_AFTER] : %d\n", __FUNCTION__,
17858 arr_len[SSSR_C1_D11_AFTER]));
17859 #ifdef DHD_LOG_DUMP
17860 dhd_print_buf_addr(dhd, "SSSR_C1_D11_AFTER",
17861 dhd->sssr_d11_after[i], arr_len[SSSR_C1_D11_AFTER]);
17862 #endif /* DHD_LOG_DUMP */
17863 }
17864
17865 if (dhd->sssr_reg_info.vasip_regs.vasip_sr_size) {
17866 arr_len[SSSR_DIG_BEFORE] = (dhd->sssr_reg_info.vasip_regs.vasip_sr_size);
17867 arr_len[SSSR_DIG_AFTER] = (dhd->sssr_reg_info.vasip_regs.vasip_sr_size);
17868 DHD_ERROR(("%s: arr_len[SSSR_DIG_BEFORE] : %d\n", __FUNCTION__,
17869 arr_len[SSSR_DIG_BEFORE]));
17870 DHD_ERROR(("%s: arr_len[SSSR_DIG_AFTER] : %d\n", __FUNCTION__,
17871 arr_len[SSSR_DIG_AFTER]));
17872 #ifdef DHD_LOG_DUMP
17873 if (dhd->sssr_dig_buf_before) {
17874 dhd_print_buf_addr(dhd, "SSSR_DIG_BEFORE",
17875 dhd->sssr_dig_buf_before, arr_len[SSSR_DIG_BEFORE]);
17876 }
17877 if (dhd->sssr_dig_buf_after) {
17878 dhd_print_buf_addr(dhd, "SSSR_DIG_AFTER",
17879 dhd->sssr_dig_buf_after, arr_len[SSSR_DIG_AFTER]);
17880 }
17881 #endif /* DHD_LOG_DUMP */
17882 } else if ((dhd->sssr_reg_info.length > OFFSETOF(sssr_reg_info_v1_t, dig_mem_info)) &&
17883 dhd->sssr_reg_info.dig_mem_info.dig_sr_addr) {
17884 arr_len[SSSR_DIG_BEFORE] = (dhd->sssr_reg_info.dig_mem_info.dig_sr_size);
17885 arr_len[SSSR_DIG_AFTER] = (dhd->sssr_reg_info.dig_mem_info.dig_sr_size);
17886 DHD_ERROR(("%s: arr_len[SSSR_DIG_BEFORE] : %d\n", __FUNCTION__,
17887 arr_len[SSSR_DIG_BEFORE]));
17888 DHD_ERROR(("%s: arr_len[SSSR_DIG_AFTER] : %d\n", __FUNCTION__,
17889 arr_len[SSSR_DIG_AFTER]));
17890 #ifdef DHD_LOG_DUMP
17891 if (dhd->sssr_dig_buf_before) {
17892 dhd_print_buf_addr(dhd, "SSSR_DIG_BEFORE",
17893 dhd->sssr_dig_buf_before, arr_len[SSSR_DIG_BEFORE]);
17894 }
17895 if (dhd->sssr_dig_buf_after) {
17896 dhd_print_buf_addr(dhd, "SSSR_DIG_AFTER",
17897 dhd->sssr_dig_buf_after, arr_len[SSSR_DIG_AFTER]);
17898 }
17899 #endif /* DHD_LOG_DUMP */
17900 }
17901 return BCME_OK;
17902 }
17903
17904 void
dhd_nla_put_sssr_dump_len(void * ndev,uint32 * arr_len)17905 dhd_nla_put_sssr_dump_len(void *ndev, uint32 *arr_len)
17906 {
17907 dhd_info_t *dhd_info = *(dhd_info_t **)DHD_DEV_PRIV_CFG((struct net_device *)ndev);
17908 dhd_pub_t *dhdp = &dhd_info->pub;
17909
17910 if (dhdp->sssr_dump_collected) {
17911 dhdpcie_sssr_dump_get_before_after_len(dhdp, arr_len);
17912 }
17913 }
17914 #endif /* DHD_SSSR_DUMP */
17915
17916 uint32
dhd_get_time_str_len()17917 dhd_get_time_str_len()
17918 {
17919 char *ts = NULL, time_str[128];
17920
17921 ts = dhd_log_dump_get_timestamp();
17922 snprintf(time_str, sizeof(time_str),
17923 "\n\n ========== LOG DUMP TAKEN AT : %s =========\n", ts);
17924 return strlen(time_str);
17925 }
17926
17927 #if defined(BCMPCIE)
17928 uint32
dhd_get_ext_trap_len(void * ndev,dhd_pub_t * dhdp)17929 dhd_get_ext_trap_len(void *ndev, dhd_pub_t *dhdp)
17930 {
17931 int length = 0;
17932 log_dump_section_hdr_t sec_hdr;
17933 dhd_info_t *dhd_info;
17934
17935 if (ndev) {
17936 dhd_info = *(dhd_info_t **)DHD_DEV_PRIV_CFG((struct net_device *)ndev);
17937 dhdp = &dhd_info->pub;
17938 }
17939
17940 if (!dhdp)
17941 return length;
17942
17943 if (dhdp->extended_trap_data) {
17944 length = (strlen(EXT_TRAP_LOG_HDR)
17945 + sizeof(sec_hdr) + BCMPCIE_EXT_TRAP_DATA_MAXLEN);
17946 }
17947 return length;
17948 }
17949 #endif
17950
17951 #if defined(DHD_FW_COREDUMP) && defined(DNGL_EVENT_SUPPORT)
17952 uint32
dhd_get_health_chk_len(void * ndev,dhd_pub_t * dhdp)17953 dhd_get_health_chk_len(void *ndev, dhd_pub_t *dhdp)
17954 {
17955 int length = 0;
17956 log_dump_section_hdr_t sec_hdr;
17957 dhd_info_t *dhd_info;
17958
17959 if (ndev) {
17960 dhd_info = *(dhd_info_t **)DHD_DEV_PRIV_CFG((struct net_device *)ndev);
17961 dhdp = &dhd_info->pub;
17962 }
17963
17964 if (!dhdp)
17965 return length;
17966
17967 if (dhdp->memdump_type == DUMP_TYPE_DONGLE_HOST_EVENT) {
17968 length = (strlen(HEALTH_CHK_LOG_HDR)
17969 + sizeof(sec_hdr) + HEALTH_CHK_BUF_SIZE);
17970 }
17971 return length;
17972 }
17973 #endif /* DHD_FW_COREDUMP && DNGL_EVENT_SUPPORT */
17974
17975 uint32
dhd_get_dhd_dump_len(void * ndev,dhd_pub_t * dhdp)17976 dhd_get_dhd_dump_len(void *ndev, dhd_pub_t *dhdp)
17977 {
17978 int length = 0;
17979 log_dump_section_hdr_t sec_hdr;
17980 dhd_info_t *dhd_info;
17981 uint32 remain_len = 0;
17982
17983 if (ndev) {
17984 dhd_info = *(dhd_info_t **)DHD_DEV_PRIV_CFG((struct net_device *)ndev);
17985 dhdp = &dhd_info->pub;
17986 }
17987
17988 if (!dhdp)
17989 return length;
17990
17991 if (dhdp->concise_dbg_buf) {
17992 remain_len = dhd_dump(dhdp, (char *)dhdp->concise_dbg_buf, CONCISE_DUMP_BUFLEN);
17993 if (remain_len <= 0) {
17994 DHD_ERROR(("%s: error getting concise debug info !\n",
17995 __FUNCTION__));
17996 return length;
17997 }
17998 length = (strlen(DHD_DUMP_LOG_HDR) + sizeof(sec_hdr) +
17999 (CONCISE_DUMP_BUFLEN - remain_len));
18000 }
18001 return length;
18002 }
18003
18004 uint32
dhd_get_cookie_log_len(void * ndev,dhd_pub_t * dhdp)18005 dhd_get_cookie_log_len(void *ndev, dhd_pub_t *dhdp)
18006 {
18007 int length = 0;
18008 dhd_info_t *dhd_info;
18009
18010 if (ndev) {
18011 dhd_info = *(dhd_info_t **)DHD_DEV_PRIV_CFG((struct net_device *)ndev);
18012 dhdp = &dhd_info->pub;
18013 }
18014
18015 if (!dhdp)
18016 return length;
18017
18018 if (dhdp->logdump_cookie && dhd_logdump_cookie_count(dhdp) > 0) {
18019 length = dhd_log_dump_cookie_len(dhdp);
18020 }
18021 return length;
18022
18023 }
18024
18025 #ifdef DHD_DUMP_PCIE_RINGS
18026 uint32
dhd_get_flowring_len(void * ndev,dhd_pub_t * dhdp)18027 dhd_get_flowring_len(void *ndev, dhd_pub_t *dhdp)
18028 {
18029 int length = 0;
18030 log_dump_section_hdr_t sec_hdr;
18031 dhd_info_t *dhd_info;
18032 uint16 h2d_flowrings_total;
18033 uint32 remain_len = 0;
18034
18035 if (ndev) {
18036 dhd_info = *(dhd_info_t **)DHD_DEV_PRIV_CFG((struct net_device *)ndev);
18037 dhdp = &dhd_info->pub;
18038 }
18039
18040 if (!dhdp)
18041 return length;
18042
18043 if (dhdp->concise_dbg_buf) {
18044 remain_len = dhd_dump(dhdp, (char *)dhdp->concise_dbg_buf, CONCISE_DUMP_BUFLEN);
18045 if (remain_len <= 0) {
18046 DHD_ERROR(("%s: error getting concise debug info !\n",
18047 __FUNCTION__));
18048 return length;
18049 }
18050 }
18051
18052 length += strlen(FLOWRING_DUMP_HDR);
18053 length += CONCISE_DUMP_BUFLEN - remain_len;
18054 length += sizeof(sec_hdr);
18055 h2d_flowrings_total = dhd_get_max_flow_rings(dhdp);
18056 length += ((H2DRING_TXPOST_ITEMSIZE
18057 * H2DRING_TXPOST_MAX_ITEM * h2d_flowrings_total)
18058 + (D2HRING_TXCMPLT_ITEMSIZE * D2HRING_TXCMPLT_MAX_ITEM)
18059 + (H2DRING_RXPOST_ITEMSIZE * H2DRING_RXPOST_MAX_ITEM)
18060 + (D2HRING_RXCMPLT_ITEMSIZE * D2HRING_RXCMPLT_MAX_ITEM)
18061 + (H2DRING_CTRL_SUB_ITEMSIZE * H2DRING_CTRL_SUB_MAX_ITEM)
18062 + (D2HRING_CTRL_CMPLT_ITEMSIZE * D2HRING_CTRL_CMPLT_MAX_ITEM)
18063 #ifdef EWP_EDL
18064 + (D2HRING_EDL_HDR_SIZE * D2HRING_EDL_MAX_ITEM));
18065 #else
18066 + (H2DRING_INFO_BUFPOST_ITEMSIZE * H2DRING_DYNAMIC_INFO_MAX_ITEM)
18067 + (D2HRING_INFO_BUFCMPLT_ITEMSIZE * D2HRING_DYNAMIC_INFO_MAX_ITEM));
18068 #endif /* EWP_EDL */
18069 return length;
18070 }
18071 #endif /* DHD_DUMP_PCIE_RINGS */
18072
18073 #ifdef EWP_ECNTRS_LOGGING
18074 uint32
dhd_get_ecntrs_len(void * ndev,dhd_pub_t * dhdp)18075 dhd_get_ecntrs_len(void *ndev, dhd_pub_t *dhdp)
18076 {
18077 dhd_info_t *dhd_info;
18078 log_dump_section_hdr_t sec_hdr;
18079 int length = 0;
18080 dhd_dbg_ring_t *ring;
18081
18082 if (ndev) {
18083 dhd_info = *(dhd_info_t **)DHD_DEV_PRIV_CFG((struct net_device *)ndev);
18084 dhdp = &dhd_info->pub;
18085 }
18086
18087 if (!dhdp)
18088 return length;
18089
18090 if (logdump_ecntr_enable && dhdp->ecntr_dbg_ring) {
18091 ring = (dhd_dbg_ring_t *)dhdp->ecntr_dbg_ring;
18092 length = ring->ring_size + strlen(ECNTRS_LOG_HDR) + sizeof(sec_hdr);
18093 }
18094 return length;
18095 }
18096 #endif /* EWP_ECNTRS_LOGGING */
18097
18098 #ifdef EWP_RTT_LOGGING
18099 uint32
dhd_get_rtt_len(void * ndev,dhd_pub_t * dhdp)18100 dhd_get_rtt_len(void *ndev, dhd_pub_t *dhdp)
18101 {
18102 dhd_info_t *dhd_info;
18103 log_dump_section_hdr_t sec_hdr;
18104 int length = 0;
18105 dhd_dbg_ring_t *ring;
18106
18107 if (ndev) {
18108 dhd_info = *(dhd_info_t **)DHD_DEV_PRIV_CFG((struct net_device *)ndev);
18109 dhdp = &dhd_info->pub;
18110 }
18111
18112 if (!dhdp)
18113 return length;
18114
18115 if (logdump_rtt_enable && dhdp->rtt_dbg_ring) {
18116 ring = (dhd_dbg_ring_t *)dhdp->rtt_dbg_ring;
18117 length = ring->ring_size + strlen(RTT_LOG_HDR) + sizeof(sec_hdr);
18118 }
18119 return length;
18120 }
18121 #endif /* EWP_RTT_LOGGING */
18122
18123 int
dhd_get_dld_log_dump(void * dev,dhd_pub_t * dhdp,const void * user_buf,void * fp,uint32 len,int type,void * pos)18124 dhd_get_dld_log_dump(void *dev, dhd_pub_t *dhdp, const void *user_buf,
18125 void *fp, uint32 len, int type, void *pos)
18126 {
18127 int ret = BCME_OK;
18128 struct dhd_log_dump_buf *dld_buf;
18129 log_dump_section_hdr_t sec_hdr;
18130 dhd_info_t *dhd_info;
18131
18132 dld_buf = &g_dld_buf[type];
18133
18134 if (dev) {
18135 dhd_info = *(dhd_info_t **)DHD_DEV_PRIV_CFG((struct net_device *)dev);
18136 dhdp = &dhd_info->pub;
18137 } else if (!dhdp) {
18138 return BCME_ERROR;
18139 }
18140
18141 DHD_ERROR(("%s: ENTER \n", __FUNCTION__));
18142
18143 dhd_init_sec_hdr(&sec_hdr);
18144
18145 /* write the section header first */
18146 ret = dhd_export_debug_data(dld_hdrs[type].hdr_str, fp, user_buf,
18147 strlen(dld_hdrs[type].hdr_str), pos);
18148 if (ret < 0)
18149 goto exit;
18150 len -= (uint32)strlen(dld_hdrs[type].hdr_str);
18151 len -= (uint32)sizeof(sec_hdr);
18152 sec_hdr.type = dld_hdrs[type].sec_type;
18153 sec_hdr.length = len;
18154 ret = dhd_export_debug_data((char *)&sec_hdr, fp, user_buf, sizeof(sec_hdr), pos);
18155 if (ret < 0)
18156 goto exit;
18157 ret = dhd_export_debug_data(dld_buf->buffer, fp, user_buf, len, pos);
18158 if (ret < 0)
18159 goto exit;
18160
18161 exit:
18162 return ret;
18163 }
18164
18165 static int
dhd_log_flush(dhd_pub_t * dhdp,log_dump_type_t * type)18166 dhd_log_flush(dhd_pub_t *dhdp, log_dump_type_t *type)
18167 {
18168 unsigned long flags = 0;
18169 #ifdef EWP_EDL
18170 int i = 0;
18171 #endif /* EWP_EDL */
18172 dhd_info_t *dhd_info = NULL;
18173
18174 /* if dhdp is null, its extremely unlikely that log dump will be scheduled
18175 * so not freeing 'type' here is ok, even if we want to free 'type'
18176 * we cannot do so, since 'dhdp->osh' is unavailable
18177 * as dhdp is null
18178 */
18179 if (!dhdp || !type) {
18180 if (dhdp) {
18181 DHD_GENERAL_LOCK(dhdp, flags);
18182 DHD_BUS_BUSY_CLEAR_IN_LOGDUMP(dhdp);
18183 dhd_os_busbusy_wake(dhdp);
18184 DHD_GENERAL_UNLOCK(dhdp, flags);
18185 }
18186 return BCME_ERROR;
18187 }
18188
18189 dhd_info = (dhd_info_t *)dhdp->info;
18190 /* in case of trap get preserve logs from ETD */
18191 #if defined(BCMPCIE) && defined(EWP_ETD_PRSRV_LOGS)
18192 if (dhdp->dongle_trap_occured &&
18193 dhdp->extended_trap_data) {
18194 dhdpcie_get_etd_preserve_logs(dhdp, (uint8 *)dhdp->extended_trap_data,
18195 &dhd_info->event_data);
18196 }
18197 #endif /* BCMPCIE */
18198
18199 /* flush the event work items to get any fw events/logs
18200 * flush_work is a blocking call
18201 */
18202 #ifdef SHOW_LOGTRACE
18203 #ifdef EWP_EDL
18204 if (dhd_info->pub.dongle_edl_support) {
18205 /* wait till existing edl items are processed */
18206 dhd_flush_logtrace_process(dhd_info);
18207 /* dhd_flush_logtrace_process will ensure the work items in the ring
18208 * (EDL ring) from rd to wr are processed. But if wr had
18209 * wrapped around, only the work items from rd to ring-end are processed.
18210 * So to ensure that the work items at the
18211 * beginning of ring are also processed in the wrap around case, call
18212 * it twice
18213 */
18214 for (i = 0; i < 2; i++) {
18215 /* blocks till the edl items are processed */
18216 dhd_flush_logtrace_process(dhd_info);
18217 }
18218 } else {
18219 dhd_flush_logtrace_process(dhd_info);
18220 }
18221 #else
18222 dhd_flush_logtrace_process(dhd_info);
18223 #endif /* EWP_EDL */
18224 #endif /* SHOW_LOGTRACE */
18225
18226 return BCME_OK;
18227 }
18228
18229 int
dhd_get_debug_dump_file_name(void * dev,dhd_pub_t * dhdp,char * dump_path,int size)18230 dhd_get_debug_dump_file_name(void *dev, dhd_pub_t *dhdp, char *dump_path, int size)
18231 {
18232 dhd_info_t *dhd_info;
18233
18234 if (dev) {
18235 dhd_info = *(dhd_info_t **)DHD_DEV_PRIV_CFG((struct net_device *)dev);
18236 dhdp = &dhd_info->pub;
18237 }
18238
18239 if (!dhdp)
18240 return BCME_ERROR;
18241
18242 memset(dump_path, 0, size);
18243
18244 switch (dhdp->debug_dump_subcmd) {
18245 case CMD_UNWANTED:
18246 snprintf(dump_path, size, "%s",
18247 DHD_COMMON_DUMP_PATH DHD_DEBUG_DUMP_TYPE
18248 DHD_DUMP_SUBSTR_UNWANTED);
18249 break;
18250 case CMD_DISCONNECTED:
18251 snprintf(dump_path, size, "%s",
18252 DHD_COMMON_DUMP_PATH DHD_DEBUG_DUMP_TYPE
18253 DHD_DUMP_SUBSTR_DISCONNECTED);
18254 break;
18255 default:
18256 snprintf(dump_path, size, "%s",
18257 DHD_COMMON_DUMP_PATH DHD_DEBUG_DUMP_TYPE);
18258 }
18259
18260 if (!dhdp->logdump_periodic_flush) {
18261 get_debug_dump_time(dhdp->debug_dump_time_str);
18262 snprintf(dump_path + strlen(dump_path),
18263 size - strlen(dump_path),
18264 "_%s", dhdp->debug_dump_time_str);
18265 }
18266 return BCME_OK;
18267 }
18268
18269 uint32
dhd_get_dld_len(int log_type)18270 dhd_get_dld_len(int log_type)
18271 {
18272 unsigned long wr_size = 0;
18273 unsigned long buf_size = 0;
18274 unsigned long flags = 0;
18275 struct dhd_log_dump_buf *dld_buf;
18276 log_dump_section_hdr_t sec_hdr;
18277
18278 /* calculate the length of the log */
18279 dld_buf = &g_dld_buf[log_type];
18280 buf_size = (unsigned long)dld_buf->max -
18281 (unsigned long)dld_buf->buffer;
18282
18283 if (dld_buf->wraparound) {
18284 wr_size = buf_size;
18285 } else {
18286 /* need to hold the lock before accessing 'present' and 'remain' ptrs */
18287 spin_lock_irqsave(&dld_buf->lock, flags);
18288 wr_size = (unsigned long)dld_buf->present -
18289 (unsigned long)dld_buf->front;
18290 spin_unlock_irqrestore(&dld_buf->lock, flags);
18291 }
18292 return (wr_size + sizeof(sec_hdr) + strlen(dld_hdrs[log_type].hdr_str));
18293 }
18294
18295 static void
dhd_get_time_str(dhd_pub_t * dhdp,char * time_str,int size)18296 dhd_get_time_str(dhd_pub_t *dhdp, char *time_str, int size)
18297 {
18298 char *ts = NULL;
18299 memset(time_str, 0, size);
18300 ts = dhd_log_dump_get_timestamp();
18301 snprintf(time_str, size,
18302 "\n\n ========== LOG DUMP TAKEN AT : %s =========\n", ts);
18303 }
18304
18305 int
dhd_print_time_str(const void * user_buf,void * fp,uint32 len,void * pos)18306 dhd_print_time_str(const void *user_buf, void *fp, uint32 len, void *pos)
18307 {
18308 char *ts = NULL;
18309 int ret = 0;
18310 char time_str[128];
18311
18312 memset_s(time_str, sizeof(time_str), 0, sizeof(time_str));
18313 ts = dhd_log_dump_get_timestamp();
18314 snprintf(time_str, sizeof(time_str),
18315 "\n\n ========== LOG DUMP TAKEN AT : %s =========\n", ts);
18316
18317 /* write the timestamp hdr to the file first */
18318 ret = dhd_export_debug_data(time_str, fp, user_buf, strlen(time_str), pos);
18319 if (ret < 0) {
18320 DHD_ERROR(("write file error, err = %d\n", ret));
18321 }
18322 return ret;
18323 }
18324
18325 #if defined(DHD_FW_COREDUMP) && defined(DNGL_EVENT_SUPPORT)
18326 int
dhd_print_health_chk_data(void * dev,dhd_pub_t * dhdp,const void * user_buf,void * fp,uint32 len,void * pos)18327 dhd_print_health_chk_data(void *dev, dhd_pub_t *dhdp, const void *user_buf,
18328 void *fp, uint32 len, void *pos)
18329 {
18330 int ret = BCME_OK;
18331 log_dump_section_hdr_t sec_hdr;
18332 dhd_info_t *dhd_info;
18333
18334 if (dev) {
18335 dhd_info = *(dhd_info_t **)DHD_DEV_PRIV_CFG((struct net_device *)dev);
18336 dhdp = &dhd_info->pub;
18337 }
18338
18339 if (!dhdp)
18340 return BCME_ERROR;
18341
18342 dhd_init_sec_hdr(&sec_hdr);
18343
18344 if (dhdp->memdump_type == DUMP_TYPE_DONGLE_HOST_EVENT) {
18345 /* write the section header first */
18346 ret = dhd_export_debug_data(HEALTH_CHK_LOG_HDR, fp, user_buf,
18347 strlen(HEALTH_CHK_LOG_HDR), pos);
18348 if (ret < 0)
18349 goto exit;
18350
18351 len -= (uint32)strlen(HEALTH_CHK_LOG_HDR);
18352 sec_hdr.type = LOG_DUMP_SECTION_HEALTH_CHK;
18353 sec_hdr.length = HEALTH_CHK_BUF_SIZE;
18354 ret = dhd_export_debug_data((char *)&sec_hdr, fp, user_buf, sizeof(sec_hdr), pos);
18355 if (ret < 0)
18356 goto exit;
18357
18358 len -= (uint32)sizeof(sec_hdr);
18359 /* write the log */
18360 ret = dhd_export_debug_data((char *)dhdp->health_chk_event_data, fp,
18361 user_buf, len, pos);
18362 if (ret < 0)
18363 goto exit;
18364 }
18365 exit:
18366 return ret;
18367 }
18368 #endif /* DHD_FW_COREDUMP && DNGL_EVENT_SUPPORT */
18369
18370 #ifdef BCMPCIE
18371 int
dhd_print_ext_trap_data(void * dev,dhd_pub_t * dhdp,const void * user_buf,void * fp,uint32 len,void * pos)18372 dhd_print_ext_trap_data(void *dev, dhd_pub_t *dhdp, const void *user_buf,
18373 void *fp, uint32 len, void *pos)
18374 {
18375 int ret = BCME_OK;
18376 log_dump_section_hdr_t sec_hdr;
18377 dhd_info_t *dhd_info;
18378
18379 if (dev) {
18380 dhd_info = *(dhd_info_t **)DHD_DEV_PRIV_CFG((struct net_device *)dev);
18381 dhdp = &dhd_info->pub;
18382 }
18383
18384 if (!dhdp)
18385 return BCME_ERROR;
18386
18387 dhd_init_sec_hdr(&sec_hdr);
18388
18389 /* append extended trap data to the file in case of traps */
18390 if (dhdp->dongle_trap_occured &&
18391 dhdp->extended_trap_data) {
18392 /* write the section header first */
18393 ret = dhd_export_debug_data(EXT_TRAP_LOG_HDR, fp, user_buf,
18394 strlen(EXT_TRAP_LOG_HDR), pos);
18395 if (ret < 0)
18396 goto exit;
18397
18398 len -= (uint32)strlen(EXT_TRAP_LOG_HDR);
18399 sec_hdr.type = LOG_DUMP_SECTION_EXT_TRAP;
18400 sec_hdr.length = BCMPCIE_EXT_TRAP_DATA_MAXLEN;
18401 ret = dhd_export_debug_data((uint8 *)&sec_hdr, fp, user_buf, sizeof(sec_hdr), pos);
18402 if (ret < 0)
18403 goto exit;
18404
18405 len -= (uint32)sizeof(sec_hdr);
18406 /* write the log */
18407 ret = dhd_export_debug_data((uint8 *)dhdp->extended_trap_data, fp,
18408 user_buf, len, pos);
18409 if (ret < 0)
18410 goto exit;
18411 }
18412 exit:
18413 return ret;
18414 }
18415 #endif /* BCMPCIE */
18416
18417 int
dhd_print_dump_data(void * dev,dhd_pub_t * dhdp,const void * user_buf,void * fp,uint32 len,void * pos)18418 dhd_print_dump_data(void *dev, dhd_pub_t *dhdp, const void *user_buf,
18419 void *fp, uint32 len, void *pos)
18420 {
18421 int ret = BCME_OK;
18422 log_dump_section_hdr_t sec_hdr;
18423 dhd_info_t *dhd_info;
18424
18425 if (dev) {
18426 dhd_info = *(dhd_info_t **)DHD_DEV_PRIV_CFG((struct net_device *)dev);
18427 dhdp = &dhd_info->pub;
18428 }
18429
18430 if (!dhdp)
18431 return BCME_ERROR;
18432
18433 dhd_init_sec_hdr(&sec_hdr);
18434
18435 ret = dhd_export_debug_data(DHD_DUMP_LOG_HDR, fp, user_buf, strlen(DHD_DUMP_LOG_HDR), pos);
18436 if (ret < 0)
18437 goto exit;
18438
18439 len -= (uint32)strlen(DHD_DUMP_LOG_HDR);
18440 sec_hdr.type = LOG_DUMP_SECTION_DHD_DUMP;
18441 sec_hdr.length = len;
18442 ret = dhd_export_debug_data((char *)&sec_hdr, fp, user_buf, sizeof(sec_hdr), pos);
18443 if (ret < 0)
18444 goto exit;
18445
18446 len -= (uint32)sizeof(sec_hdr);
18447
18448 if (dhdp->concise_dbg_buf) {
18449 dhd_dump(dhdp, (char *)dhdp->concise_dbg_buf, CONCISE_DUMP_BUFLEN);
18450 ret = dhd_export_debug_data(dhdp->concise_dbg_buf, fp, user_buf, len, pos);
18451 if (ret < 0)
18452 goto exit;
18453 }
18454
18455 exit:
18456 return ret;
18457 }
18458
18459 int
dhd_print_cookie_data(void * dev,dhd_pub_t * dhdp,const void * user_buf,void * fp,uint32 len,void * pos)18460 dhd_print_cookie_data(void *dev, dhd_pub_t *dhdp, const void *user_buf,
18461 void *fp, uint32 len, void *pos)
18462 {
18463 int ret = BCME_OK;
18464 dhd_info_t *dhd_info;
18465
18466 if (dev) {
18467 dhd_info = *(dhd_info_t **)DHD_DEV_PRIV_CFG((struct net_device *)dev);
18468 dhdp = &dhd_info->pub;
18469 }
18470
18471 if (!dhdp)
18472 return BCME_ERROR;
18473
18474 if (dhdp->logdump_cookie && dhd_logdump_cookie_count(dhdp) > 0) {
18475 ret = dhd_log_dump_cookie_to_file(dhdp, fp, user_buf, (unsigned long *)pos);
18476 }
18477 return ret;
18478 }
18479
18480 #ifdef DHD_DUMP_PCIE_RINGS
18481 int
dhd_print_flowring_data(void * dev,dhd_pub_t * dhdp,const void * user_buf,void * fp,uint32 len,void * pos)18482 dhd_print_flowring_data(void *dev, dhd_pub_t *dhdp, const void *user_buf,
18483 void *fp, uint32 len, void *pos)
18484 {
18485 log_dump_section_hdr_t sec_hdr;
18486 int ret = BCME_OK;
18487 uint32 remain_len = 0;
18488 dhd_info_t *dhd_info;
18489
18490 if (dev) {
18491 dhd_info = *(dhd_info_t **)DHD_DEV_PRIV_CFG((struct net_device *)dev);
18492 dhdp = &dhd_info->pub;
18493 }
18494
18495 if (!dhdp)
18496 return BCME_ERROR;
18497
18498 dhd_init_sec_hdr(&sec_hdr);
18499
18500 remain_len = dhd_dump(dhdp, (char *)dhdp->concise_dbg_buf, CONCISE_DUMP_BUFLEN);
18501 memset(dhdp->concise_dbg_buf, 0, CONCISE_DUMP_BUFLEN);
18502
18503 /* write the section header first */
18504 ret = dhd_export_debug_data(FLOWRING_DUMP_HDR, fp, user_buf,
18505 strlen(FLOWRING_DUMP_HDR), pos);
18506 if (ret < 0)
18507 goto exit;
18508
18509 /* Write the ring summary */
18510 ret = dhd_export_debug_data(dhdp->concise_dbg_buf, fp, user_buf,
18511 (CONCISE_DUMP_BUFLEN - remain_len), pos);
18512 if (ret < 0)
18513 goto exit;
18514
18515 sec_hdr.type = LOG_DUMP_SECTION_FLOWRING;
18516 sec_hdr.length = len;
18517 ret = dhd_export_debug_data((char *)&sec_hdr, fp, user_buf, sizeof(sec_hdr), pos);
18518 if (ret < 0)
18519 goto exit;
18520
18521 /* write the log */
18522 ret = dhd_d2h_h2d_ring_dump(dhdp, fp, user_buf, (unsigned long *)pos, TRUE);
18523 if (ret < 0)
18524 goto exit;
18525
18526 exit:
18527 return ret;
18528 }
18529 #endif /* DHD_DUMP_PCIE_RINGS */
18530
18531 #ifdef EWP_ECNTRS_LOGGING
18532 int
dhd_print_ecntrs_data(void * dev,dhd_pub_t * dhdp,const void * user_buf,void * fp,uint32 len,void * pos)18533 dhd_print_ecntrs_data(void *dev, dhd_pub_t *dhdp, const void *user_buf,
18534 void *fp, uint32 len, void *pos)
18535 {
18536 log_dump_section_hdr_t sec_hdr;
18537 int ret = BCME_OK;
18538 dhd_info_t *dhd_info;
18539
18540 if (dev) {
18541 dhd_info = *(dhd_info_t **)DHD_DEV_PRIV_CFG((struct net_device *)dev);
18542 dhdp = &dhd_info->pub;
18543 }
18544
18545 if (!dhdp)
18546 return BCME_ERROR;
18547
18548 dhd_init_sec_hdr(&sec_hdr);
18549
18550 if (logdump_ecntr_enable &&
18551 dhdp->ecntr_dbg_ring) {
18552 sec_hdr.type = LOG_DUMP_SECTION_ECNTRS;
18553 ret = dhd_dump_debug_ring(dhdp, dhdp->ecntr_dbg_ring,
18554 user_buf, &sec_hdr, ECNTRS_LOG_HDR, len, LOG_DUMP_SECTION_ECNTRS);
18555 }
18556 return ret;
18557
18558 }
18559 #endif /* EWP_ECNTRS_LOGGING */
18560
18561 #ifdef EWP_RTT_LOGGING
18562 int
dhd_print_rtt_data(void * dev,dhd_pub_t * dhdp,const void * user_buf,void * fp,uint32 len,void * pos)18563 dhd_print_rtt_data(void *dev, dhd_pub_t *dhdp, const void *user_buf,
18564 void *fp, uint32 len, void *pos)
18565 {
18566 log_dump_section_hdr_t sec_hdr;
18567 int ret = BCME_OK;
18568 dhd_info_t *dhd_info;
18569
18570 if (dev) {
18571 dhd_info = *(dhd_info_t **)DHD_DEV_PRIV_CFG((struct net_device *)dev);
18572 dhdp = &dhd_info->pub;
18573 }
18574
18575 if (!dhdp)
18576 return BCME_ERROR;
18577
18578 dhd_init_sec_hdr(&sec_hdr);
18579
18580 if (logdump_rtt_enable && dhdp->rtt_dbg_ring) {
18581 ret = dhd_dump_debug_ring(dhdp, dhdp->rtt_dbg_ring,
18582 user_buf, &sec_hdr, RTT_LOG_HDR, len, LOG_DUMP_SECTION_RTT);
18583 }
18584 return ret;
18585
18586 }
18587 #endif /* EWP_RTT_LOGGING */
18588
18589 #ifdef DHD_STATUS_LOGGING
18590 int
dhd_print_status_log_data(void * dev,dhd_pub_t * dhdp,const void * user_buf,void * fp,uint32 len,void * pos)18591 dhd_print_status_log_data(void *dev, dhd_pub_t *dhdp, const void *user_buf,
18592 void *fp, uint32 len, void *pos)
18593 {
18594 dhd_info_t *dhd_info;
18595
18596 if (dev) {
18597 dhd_info = *(dhd_info_t **)DHD_DEV_PRIV_CFG((struct net_device *)dev);
18598 dhdp = &dhd_info->pub;
18599 }
18600
18601 if (!dhdp) {
18602 return BCME_ERROR;
18603 }
18604
18605 return dhd_statlog_write_logdump(dhdp, user_buf, fp, len, pos);
18606 }
18607
18608 uint32
dhd_get_status_log_len(void * ndev,dhd_pub_t * dhdp)18609 dhd_get_status_log_len(void *ndev, dhd_pub_t *dhdp)
18610 {
18611 dhd_info_t *dhd_info;
18612 uint32 length = 0;
18613
18614 if (ndev) {
18615 dhd_info = *(dhd_info_t **)DHD_DEV_PRIV_CFG((struct net_device *)ndev);
18616 dhdp = &dhd_info->pub;
18617 }
18618
18619 if (dhdp) {
18620 length = dhd_statlog_get_logbuf_len(dhdp);
18621 }
18622
18623 return length;
18624 }
18625 #endif /* DHD_STATUS_LOGGING */
18626
18627 void
dhd_init_sec_hdr(log_dump_section_hdr_t * sec_hdr)18628 dhd_init_sec_hdr(log_dump_section_hdr_t *sec_hdr)
18629 {
18630 /* prep the section header */
18631 memset(sec_hdr, 0, sizeof(*sec_hdr));
18632 sec_hdr->magic = LOG_DUMP_MAGIC;
18633 sec_hdr->timestamp = local_clock();
18634 }
18635
18636 /* Must hold 'dhd_os_logdump_lock' before calling this function ! */
18637 static int
do_dhd_log_dump(dhd_pub_t * dhdp,log_dump_type_t * type)18638 do_dhd_log_dump(dhd_pub_t *dhdp, log_dump_type_t *type)
18639 {
18640 int ret = 0, i = 0;
18641 struct file *fp = NULL;
18642 #if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0))
18643 mm_segment_t old_fs;
18644 #endif
18645 loff_t pos = 0;
18646 char dump_path[128];
18647 uint32 file_mode;
18648 unsigned long flags = 0;
18649 size_t log_size = 0;
18650 size_t fspace_remain = 0;
18651 struct kstat stat;
18652 char time_str[128];
18653 unsigned int len = 0;
18654 log_dump_section_hdr_t sec_hdr;
18655
18656 DHD_ERROR(("%s: ENTER \n", __FUNCTION__));
18657
18658 DHD_GENERAL_LOCK(dhdp, flags);
18659 if (DHD_BUS_CHECK_DOWN_OR_DOWN_IN_PROGRESS(dhdp)) {
18660 DHD_GENERAL_UNLOCK(dhdp, flags);
18661 DHD_ERROR(("%s: bus is down! can't collect log dump. \n", __FUNCTION__));
18662 goto exit1;
18663 }
18664 DHD_BUS_BUSY_SET_IN_LOGDUMP(dhdp);
18665 DHD_GENERAL_UNLOCK(dhdp, flags);
18666
18667 if ((ret = dhd_log_flush(dhdp, type)) < 0) {
18668 goto exit1;
18669 }
18670 /* change to KERNEL_DS address limit */
18671 #if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0))
18672 old_fs = get_fs();
18673 set_fs(KERNEL_DS);
18674 #endif
18675
18676 dhd_get_debug_dump_file_name(NULL, dhdp, dump_path, sizeof(dump_path));
18677
18678 DHD_ERROR(("debug_dump_path = %s\n", dump_path));
18679 DHD_ERROR(("DHD version: %s\n", dhd_version));
18680 DHD_ERROR(("F/W version: %s\n", fw_version));
18681
18682 dhd_log_dump_buf_addr(dhdp, type);
18683
18684 dhd_get_time_str(dhdp, time_str, 128);
18685
18686 /* if this is the first time after dhd is loaded,
18687 * or, if periodic flush is disabled, clear the log file
18688 */
18689 if (!dhdp->logdump_periodic_flush || dhdp->last_file_posn == 0)
18690 file_mode = O_CREAT | O_WRONLY | O_SYNC | O_TRUNC;
18691 else
18692 file_mode = O_CREAT | O_RDWR | O_SYNC;
18693
18694 fp = filp_open(dump_path, file_mode, 0664);
18695 if (IS_ERR(fp)) {
18696 /* If android installed image, try '/data' directory */
18697 #if defined(CONFIG_X86)
18698 DHD_ERROR(("%s: File open error on Installed android image, trying /data...\n",
18699 __FUNCTION__));
18700 snprintf(dump_path, sizeof(dump_path), "/data/" DHD_DEBUG_DUMP_TYPE);
18701 if (!dhdp->logdump_periodic_flush) {
18702 snprintf(dump_path + strlen(dump_path),
18703 sizeof(dump_path) - strlen(dump_path),
18704 "_%s", dhdp->debug_dump_time_str);
18705 }
18706 fp = filp_open(dump_path, file_mode, 0664);
18707 if (IS_ERR(fp)) {
18708 ret = PTR_ERR(fp);
18709 DHD_ERROR(("open file error, err = %d\n", ret));
18710 goto exit2;
18711 }
18712 DHD_ERROR(("debug_dump_path = %s\n", dump_path));
18713 #else
18714 ret = PTR_ERR(fp);
18715 DHD_ERROR(("open file error, err = %d\n", ret));
18716 goto exit2;
18717 #endif /* CONFIG_X86 && OEM_ANDROID */
18718 }
18719
18720 ret = vfs_stat(dump_path, &stat);
18721 if (ret < 0) {
18722 DHD_ERROR(("file stat error, err = %d\n", ret));
18723 goto exit2;
18724 }
18725
18726 /* if some one else has changed the file */
18727 if (dhdp->last_file_posn != 0 &&
18728 stat.size < dhdp->last_file_posn) {
18729 dhdp->last_file_posn = 0;
18730 }
18731
18732 if (dhdp->logdump_periodic_flush) {
18733 log_size = strlen(time_str) + strlen(DHD_DUMP_LOG_HDR) + sizeof(sec_hdr);
18734 /* calculate the amount of space required to dump all logs */
18735 for (i = 0; i < DLD_BUFFER_NUM; ++i) {
18736 if (*type != DLD_BUF_TYPE_ALL && i != *type)
18737 continue;
18738
18739 if (g_dld_buf[i].wraparound) {
18740 log_size += (unsigned long)g_dld_buf[i].max
18741 - (unsigned long)g_dld_buf[i].buffer;
18742 } else {
18743 spin_lock_irqsave(&g_dld_buf[i].lock, flags);
18744 log_size += (unsigned long)g_dld_buf[i].present -
18745 (unsigned long)g_dld_buf[i].front;
18746 spin_unlock_irqrestore(&g_dld_buf[i].lock, flags);
18747 }
18748 log_size += strlen(dld_hdrs[i].hdr_str) + sizeof(sec_hdr);
18749
18750 if (*type != DLD_BUF_TYPE_ALL && i == *type)
18751 break;
18752 }
18753
18754 ret = generic_file_llseek(fp, dhdp->last_file_posn, SEEK_CUR);
18755 if (ret < 0) {
18756 DHD_ERROR(("file seek last posn error ! err = %d \n", ret));
18757 goto exit2;
18758 }
18759 pos = fp->f_pos;
18760
18761 /* if the max file size is reached, wrap around to beginning of the file
18762 * we're treating the file as a large ring buffer
18763 */
18764 fspace_remain = logdump_max_filesize - pos;
18765 if (log_size > fspace_remain) {
18766 fp->f_pos -= pos;
18767 pos = fp->f_pos;
18768 }
18769 }
18770
18771 dhd_print_time_str(0, fp, len, &pos);
18772
18773 for (i = 0; i < DLD_BUFFER_NUM; ++i) {
18774
18775 if (*type != DLD_BUF_TYPE_ALL && i != *type)
18776 continue;
18777
18778 len = dhd_get_dld_len(i);
18779 dhd_get_dld_log_dump(NULL, dhdp, 0, fp, len, i, &pos);
18780 if (*type != DLD_BUF_TYPE_ALL)
18781 break;
18782 }
18783
18784 #ifdef EWP_ECNTRS_LOGGING
18785 /* periodic flushing of ecounters is NOT supported */
18786 if (*type == DLD_BUF_TYPE_ALL &&
18787 logdump_ecntr_enable &&
18788 dhdp->ecntr_dbg_ring) {
18789 dhd_log_dump_ring_to_file(dhdp, dhdp->ecntr_dbg_ring,
18790 fp, (unsigned long *)&pos,
18791 &sec_hdr, ECNTRS_LOG_HDR, LOG_DUMP_SECTION_ECNTRS);
18792 }
18793 #endif /* EWP_ECNTRS_LOGGING */
18794
18795 #ifdef DHD_STATUS_LOGGING
18796 if (dhdp->statlog) {
18797 /* write the statlog */
18798 len = dhd_get_status_log_len(NULL, dhdp);
18799 if (len) {
18800 if (dhd_print_status_log_data(NULL, dhdp, 0, fp,
18801 len, &pos) < 0) {
18802 goto exit2;
18803 }
18804 }
18805 }
18806 #endif /* DHD_STATUS_LOGGING */
18807
18808 #ifdef EWP_RTT_LOGGING
18809 /* periodic flushing of ecounters is NOT supported */
18810 if (*type == DLD_BUF_TYPE_ALL &&
18811 logdump_rtt_enable &&
18812 dhdp->rtt_dbg_ring) {
18813 dhd_log_dump_ring_to_file(dhdp, dhdp->rtt_dbg_ring,
18814 fp, (unsigned long *)&pos,
18815 &sec_hdr, RTT_LOG_HDR, LOG_DUMP_SECTION_RTT);
18816 }
18817 #endif /* EWP_RTT_LOGGING */
18818
18819 #ifdef BCMPCIE
18820 len = dhd_get_ext_trap_len(NULL, dhdp);
18821 if (len) {
18822 if (dhd_print_ext_trap_data(NULL, dhdp, 0, fp, len, &pos) < 0)
18823 goto exit2;
18824 }
18825 #endif /* BCMPCIE */
18826
18827 #if defined(DHD_FW_COREDUMP) && defined(DNGL_EVENT_SUPPORT)
18828 len = dhd_get_health_chk_len(NULL, dhdp);
18829 if (len) {
18830 if (dhd_print_ext_trap_data(NULL, dhdp, 0, fp, len, &pos) < 0)
18831 goto exit2;
18832 }
18833 #endif /* DHD_FW_COREDUMP && DNGL_EVENT_SUPPORT */
18834
18835 len = dhd_get_dhd_dump_len(NULL, dhdp);
18836 if (len) {
18837 if (dhd_print_dump_data(NULL, dhdp, 0, fp, len, &pos) < 0)
18838 goto exit2;
18839 }
18840
18841 len = dhd_get_cookie_log_len(NULL, dhdp);
18842 if (len) {
18843 if (dhd_print_cookie_data(NULL, dhdp, 0, fp, len, &pos) < 0)
18844 goto exit2;
18845 }
18846
18847 #ifdef DHD_DUMP_PCIE_RINGS
18848 len = dhd_get_flowring_len(NULL, dhdp);
18849 if (len) {
18850 if (dhd_print_flowring_data(NULL, dhdp, 0, fp, len, &pos) < 0)
18851 goto exit2;
18852 }
18853 #endif // endif
18854
18855 if (dhdp->logdump_periodic_flush) {
18856 /* store the last position written to in the file for future use */
18857 dhdp->last_file_posn = pos;
18858 }
18859
18860 exit2:
18861 if (!IS_ERR(fp) && fp != NULL) {
18862 filp_close(fp, NULL);
18863 DHD_ERROR(("%s: Finished writing log dump to file - '%s' \n",
18864 __FUNCTION__, dump_path));
18865 }
18866 #if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0))
18867 set_fs(old_fs);
18868 #endif
18869 exit1:
18870 if (type) {
18871 MFREE(dhdp->osh, type, sizeof(*type));
18872 }
18873 DHD_GENERAL_LOCK(dhdp, flags);
18874 DHD_BUS_BUSY_CLEAR_IN_LOGDUMP(dhdp);
18875 dhd_os_busbusy_wake(dhdp);
18876 DHD_GENERAL_UNLOCK(dhdp, flags);
18877
18878 #ifdef DHD_DUMP_MNGR
18879 if (ret >= 0) {
18880 dhd_dump_file_manage_enqueue(dhdp, dump_path, DHD_DEBUG_DUMP_TYPE);
18881 }
18882 #endif /* DHD_DUMP_MNGR */
18883
18884 return (ret < 0) ? BCME_ERROR : BCME_OK;
18885 }
18886 #endif /* DHD_LOG_DUMP */
18887
18888 /* This function writes data to the file pointed by fp, OR
18889 * copies data to the user buffer sent by upper layer(HAL).
18890 */
18891 int
dhd_export_debug_data(void * mem_buf,void * fp,const void * user_buf,int buf_len,void * pos)18892 dhd_export_debug_data(void *mem_buf, void *fp, const void *user_buf, int buf_len, void *pos)
18893 {
18894 int ret = BCME_OK;
18895
18896 if (fp) {
18897 ret = compat_vfs_write(fp, mem_buf, buf_len, (loff_t *)pos);
18898 if (ret < 0) {
18899 DHD_ERROR(("write file error, err = %d\n", ret));
18900 goto exit;
18901 }
18902 } else {
18903 #ifdef CONFIG_COMPAT
18904 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0))
18905 if (in_compat_syscall())
18906 #else
18907 if (is_compat_task())
18908 #endif /* LINUX_VER >= 4.6 */
18909 {
18910 void * usr_ptr = compat_ptr((uintptr_t) user_buf);
18911 ret = copy_to_user((void *)((uintptr_t)usr_ptr + (*(int *)pos)),
18912 mem_buf, buf_len);
18913 if (ret) {
18914 DHD_ERROR(("failed to copy into user buffer : %d\n", ret));
18915 goto exit;
18916 }
18917 }
18918 else
18919 #endif /* CONFIG_COMPAT */
18920 {
18921 ret = copy_to_user((void *)((uintptr_t)user_buf + (*(int *)pos)),
18922 mem_buf, buf_len);
18923 if (ret) {
18924 DHD_ERROR(("failed to copy into user buffer : %d\n", ret));
18925 goto exit;
18926 }
18927 }
18928 (*(int *)pos) += buf_len;
18929 }
18930 exit:
18931 return ret;
18932 }
18933
18934 /*
18935 * This call is to get the memdump size so that,
18936 * halutil can alloc that much buffer in user space.
18937 */
18938 int
dhd_os_socram_dump(struct net_device * dev,uint32 * dump_size)18939 dhd_os_socram_dump(struct net_device *dev, uint32 *dump_size)
18940 {
18941 int ret = BCME_OK;
18942 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
18943 dhd_pub_t *dhdp = &dhd->pub;
18944
18945 if (dhdp->busstate == DHD_BUS_DOWN) {
18946 DHD_ERROR(("%s: bus is down\n", __FUNCTION__));
18947 return BCME_ERROR;
18948 }
18949
18950 if (DHD_BUS_CHECK_SUSPEND_OR_SUSPEND_IN_PROGRESS(dhdp)) {
18951 DHD_ERROR(("%s: bus is in suspend(%d) or suspending(0x%x) state, so skip\n",
18952 __FUNCTION__, dhdp->busstate, dhdp->dhd_bus_busy_state));
18953 return BCME_ERROR;
18954 }
18955 ret = dhd_common_socram_dump(dhdp);
18956 if (ret == BCME_OK) {
18957 *dump_size = dhdp->soc_ram_length;
18958 }
18959 return ret;
18960 }
18961
18962 /*
18963 * This is to get the actual memdup after getting the memdump size
18964 */
18965 int
dhd_os_get_socram_dump(struct net_device * dev,char ** buf,uint32 * size)18966 dhd_os_get_socram_dump(struct net_device *dev, char **buf, uint32 *size)
18967 {
18968 int ret = BCME_OK;
18969 int orig_len = 0;
18970 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
18971 dhd_pub_t *dhdp = &dhd->pub;
18972 if (buf == NULL)
18973 return BCME_ERROR;
18974 orig_len = *size;
18975 if (dhdp->soc_ram) {
18976 if (orig_len >= dhdp->soc_ram_length) {
18977 *buf = dhdp->soc_ram;
18978 *size = dhdp->soc_ram_length;
18979 } else {
18980 ret = BCME_BUFTOOSHORT;
18981 DHD_ERROR(("The length of the buffer is too short"
18982 " to save the memory dump with %d\n", dhdp->soc_ram_length));
18983 }
18984 } else {
18985 DHD_ERROR(("socram_dump is not ready to get\n"));
18986 ret = BCME_NOTREADY;
18987 }
18988 return ret;
18989 }
18990
18991 int
dhd_os_get_version(struct net_device * dev,bool dhd_ver,char ** buf,uint32 size)18992 dhd_os_get_version(struct net_device *dev, bool dhd_ver, char **buf, uint32 size)
18993 {
18994 char *fw_str;
18995
18996 if (size == 0)
18997 return BCME_BADARG;
18998
18999 fw_str = strstr(info_string, "Firmware: ");
19000 if (fw_str == NULL) {
19001 return BCME_ERROR;
19002 }
19003
19004 memset(*buf, 0, size);
19005 if (dhd_ver) {
19006 strncpy(*buf, dhd_version, size - 1);
19007 } else {
19008 strncpy(*buf, fw_str, size - 1);
19009 }
19010 return BCME_OK;
19011 }
19012
19013 #ifdef DNGL_AXI_ERROR_LOGGING
19014 int
dhd_os_get_axi_error_dump(void * dev,const void * user_buf,uint32 len)19015 dhd_os_get_axi_error_dump(void *dev, const void *user_buf, uint32 len)
19016 {
19017 int ret = BCME_OK;
19018 dhd_info_t *dhd = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
19019 dhd_pub_t *dhdp = &dhd->pub;
19020 loff_t pos = 0;
19021 if (user_buf == NULL) {
19022 DHD_ERROR(("%s(): user buffer is NULL\n", __FUNCTION__));
19023 return BCME_ERROR;
19024 }
19025
19026 ret = dhd_export_debug_data((char *)dhdp->axi_err_dump,
19027 NULL, user_buf, sizeof(dhd_axi_error_dump_t), &pos);
19028
19029 if (ret < 0) {
19030 DHD_ERROR(("%s(): fail to dump pktlog, err = %d\n", __FUNCTION__, ret));
19031 return ret;
19032 }
19033 return ret;
19034 }
19035
19036 int
dhd_os_get_axi_error_dump_size(struct net_device * dev)19037 dhd_os_get_axi_error_dump_size(struct net_device *dev)
19038 {
19039 int size = -1;
19040
19041 size = sizeof(dhd_axi_error_dump_t);
19042 if (size < 0) {
19043 DHD_ERROR(("%s(): fail to get axi error size, err = %d\n", __FUNCTION__, size));
19044 }
19045 return size;
19046 }
19047
19048 void
dhd_os_get_axi_error_filename(struct net_device * dev,char * dump_path,int len)19049 dhd_os_get_axi_error_filename(struct net_device *dev, char *dump_path, int len)
19050 {
19051 snprintf(dump_path, len, "%s",
19052 DHD_COMMON_DUMP_PATH DHD_DUMP_AXI_ERROR_FILENAME);
19053 }
19054 #endif /* DNGL_AXI_ERROR_LOGGING */
19055
dhd_sta_associated(dhd_pub_t * dhdp,uint32 bssidx,uint8 * mac)19056 bool dhd_sta_associated(dhd_pub_t *dhdp, uint32 bssidx, uint8 *mac)
19057 {
19058 return dhd_find_sta(dhdp, bssidx, mac) ? TRUE : FALSE;
19059 }
19060
19061 #ifdef DHD_L2_FILTER
19062 arp_table_t*
dhd_get_ifp_arp_table_handle(dhd_pub_t * dhdp,uint32 bssidx)19063 dhd_get_ifp_arp_table_handle(dhd_pub_t *dhdp, uint32 bssidx)
19064 {
19065 dhd_info_t *dhd = dhdp->info;
19066 dhd_if_t *ifp;
19067
19068 ASSERT(bssidx < DHD_MAX_IFS);
19069
19070 ifp = dhd->iflist[bssidx];
19071 return ifp->phnd_arp_table;
19072 }
19073
dhd_get_parp_status(dhd_pub_t * dhdp,uint32 idx)19074 int dhd_get_parp_status(dhd_pub_t *dhdp, uint32 idx)
19075 {
19076 dhd_info_t *dhd = dhdp->info;
19077 dhd_if_t *ifp;
19078
19079 ASSERT(idx < DHD_MAX_IFS);
19080
19081 ifp = dhd->iflist[idx];
19082
19083 if (ifp)
19084 return ifp->parp_enable;
19085 else
19086 return FALSE;
19087 }
19088
19089 /* Set interface specific proxy arp configuration */
dhd_set_parp_status(dhd_pub_t * dhdp,uint32 idx,int val)19090 int dhd_set_parp_status(dhd_pub_t *dhdp, uint32 idx, int val)
19091 {
19092 dhd_info_t *dhd = dhdp->info;
19093 dhd_if_t *ifp;
19094 ASSERT(idx < DHD_MAX_IFS);
19095 ifp = dhd->iflist[idx];
19096
19097 if (!ifp)
19098 return BCME_ERROR;
19099
19100 /* At present all 3 variables are being
19101 * handled at once
19102 */
19103 ifp->parp_enable = val;
19104 ifp->parp_discard = val;
19105 ifp->parp_allnode = val;
19106
19107 /* Flush ARP entries when disabled */
19108 if (val == FALSE) {
19109 bcm_l2_filter_arp_table_update(dhdp->osh, ifp->phnd_arp_table, TRUE, NULL,
19110 FALSE, dhdp->tickcnt);
19111 }
19112 return BCME_OK;
19113 }
19114
dhd_parp_discard_is_enabled(dhd_pub_t * dhdp,uint32 idx)19115 bool dhd_parp_discard_is_enabled(dhd_pub_t *dhdp, uint32 idx)
19116 {
19117 dhd_info_t *dhd = dhdp->info;
19118 dhd_if_t *ifp;
19119
19120 ASSERT(idx < DHD_MAX_IFS);
19121
19122 ifp = dhd->iflist[idx];
19123
19124 ASSERT(ifp);
19125 return ifp->parp_discard;
19126 }
19127
19128 bool
dhd_parp_allnode_is_enabled(dhd_pub_t * dhdp,uint32 idx)19129 dhd_parp_allnode_is_enabled(dhd_pub_t *dhdp, uint32 idx)
19130 {
19131 dhd_info_t *dhd = dhdp->info;
19132 dhd_if_t *ifp;
19133
19134 ASSERT(idx < DHD_MAX_IFS);
19135
19136 ifp = dhd->iflist[idx];
19137
19138 ASSERT(ifp);
19139
19140 return ifp->parp_allnode;
19141 }
19142
dhd_get_dhcp_unicast_status(dhd_pub_t * dhdp,uint32 idx)19143 int dhd_get_dhcp_unicast_status(dhd_pub_t *dhdp, uint32 idx)
19144 {
19145 dhd_info_t *dhd = dhdp->info;
19146 dhd_if_t *ifp;
19147
19148 ASSERT(idx < DHD_MAX_IFS);
19149
19150 ifp = dhd->iflist[idx];
19151
19152 ASSERT(ifp);
19153
19154 return ifp->dhcp_unicast;
19155 }
19156
dhd_set_dhcp_unicast_status(dhd_pub_t * dhdp,uint32 idx,int val)19157 int dhd_set_dhcp_unicast_status(dhd_pub_t *dhdp, uint32 idx, int val)
19158 {
19159 dhd_info_t *dhd = dhdp->info;
19160 dhd_if_t *ifp;
19161 ASSERT(idx < DHD_MAX_IFS);
19162 ifp = dhd->iflist[idx];
19163
19164 ASSERT(ifp);
19165
19166 ifp->dhcp_unicast = val;
19167 return BCME_OK;
19168 }
19169
dhd_get_block_ping_status(dhd_pub_t * dhdp,uint32 idx)19170 int dhd_get_block_ping_status(dhd_pub_t *dhdp, uint32 idx)
19171 {
19172 dhd_info_t *dhd = dhdp->info;
19173 dhd_if_t *ifp;
19174
19175 ASSERT(idx < DHD_MAX_IFS);
19176
19177 ifp = dhd->iflist[idx];
19178
19179 ASSERT(ifp);
19180
19181 return ifp->block_ping;
19182 }
19183
dhd_set_block_ping_status(dhd_pub_t * dhdp,uint32 idx,int val)19184 int dhd_set_block_ping_status(dhd_pub_t *dhdp, uint32 idx, int val)
19185 {
19186 dhd_info_t *dhd = dhdp->info;
19187 dhd_if_t *ifp;
19188 ASSERT(idx < DHD_MAX_IFS);
19189 ifp = dhd->iflist[idx];
19190
19191 ASSERT(ifp);
19192
19193 ifp->block_ping = val;
19194 /* Disable rx_pkt_chain feature for interface if block_ping option is
19195 * enabled
19196 */
19197 dhd_update_rx_pkt_chainable_state(dhdp, idx);
19198 return BCME_OK;
19199 }
19200
dhd_get_grat_arp_status(dhd_pub_t * dhdp,uint32 idx)19201 int dhd_get_grat_arp_status(dhd_pub_t *dhdp, uint32 idx)
19202 {
19203 dhd_info_t *dhd = dhdp->info;
19204 dhd_if_t *ifp;
19205
19206 ASSERT(idx < DHD_MAX_IFS);
19207
19208 ifp = dhd->iflist[idx];
19209
19210 ASSERT(ifp);
19211
19212 return ifp->grat_arp;
19213 }
19214
dhd_set_grat_arp_status(dhd_pub_t * dhdp,uint32 idx,int val)19215 int dhd_set_grat_arp_status(dhd_pub_t *dhdp, uint32 idx, int val)
19216 {
19217 dhd_info_t *dhd = dhdp->info;
19218 dhd_if_t *ifp;
19219 ASSERT(idx < DHD_MAX_IFS);
19220 ifp = dhd->iflist[idx];
19221
19222 ASSERT(ifp);
19223
19224 ifp->grat_arp = val;
19225
19226 return BCME_OK;
19227 }
19228
dhd_get_block_tdls_status(dhd_pub_t * dhdp,uint32 idx)19229 int dhd_get_block_tdls_status(dhd_pub_t *dhdp, uint32 idx)
19230 {
19231 dhd_info_t *dhd = dhdp->info;
19232 dhd_if_t *ifp;
19233
19234 ASSERT(idx < DHD_MAX_IFS);
19235
19236 ifp = dhd->iflist[idx];
19237
19238 ASSERT(ifp);
19239
19240 return ifp->block_tdls;
19241 }
19242
dhd_set_block_tdls_status(dhd_pub_t * dhdp,uint32 idx,int val)19243 int dhd_set_block_tdls_status(dhd_pub_t *dhdp, uint32 idx, int val)
19244 {
19245 dhd_info_t *dhd = dhdp->info;
19246 dhd_if_t *ifp;
19247 ASSERT(idx < DHD_MAX_IFS);
19248 ifp = dhd->iflist[idx];
19249
19250 ASSERT(ifp);
19251
19252 ifp->block_tdls = val;
19253
19254 return BCME_OK;
19255 }
19256 #endif /* DHD_L2_FILTER */
19257
19258 #if defined(SET_XPS_CPUS)
dhd_xps_cpus_enable(struct net_device * net,int enable)19259 int dhd_xps_cpus_enable(struct net_device *net, int enable)
19260 {
19261 dhd_info_t *dhd = DHD_DEV_INFO(net);
19262 dhd_if_t *ifp;
19263 int ifidx;
19264 char * XPS_CPU_SETBUF;
19265
19266 ifidx = dhd_net2idx(dhd, net);
19267 if (ifidx == DHD_BAD_IF) {
19268 DHD_ERROR(("%s bad ifidx\n", __FUNCTION__));
19269 return -ENODEV;
19270 }
19271
19272 if (!dhd->pub.conf->xps_cpus)
19273 return -ENODEV;
19274
19275 if (ifidx == PRIMARY_INF) {
19276 if (dhd->pub.op_mode == DHD_FLAG_IBSS_MODE) {
19277 DHD_INFO(("%s : set for IBSS.\n", __FUNCTION__));
19278 XPS_CPU_SETBUF = RPS_CPUS_MASK_IBSS;
19279 } else {
19280 DHD_INFO(("%s : set for BSS.\n", __FUNCTION__));
19281 XPS_CPU_SETBUF = RPS_CPUS_MASK;
19282 }
19283 } else if (ifidx == VIRTUAL_INF) {
19284 DHD_INFO(("%s : set for P2P.\n", __FUNCTION__));
19285 XPS_CPU_SETBUF = RPS_CPUS_MASK_P2P;
19286 } else {
19287 DHD_ERROR(("%s : Invalid index : %d.\n", __FUNCTION__, ifidx));
19288 return -EINVAL;
19289 }
19290
19291 ifp = dhd->iflist[ifidx];
19292 if (ifp) {
19293 if (enable) {
19294 DHD_INFO(("%s : set xps_cpus as [%s]\n", __FUNCTION__, XPS_CPU_SETBUF));
19295 custom_xps_map_set(ifp->net, XPS_CPU_SETBUF, strlen(XPS_CPU_SETBUF));
19296 } else {
19297 custom_xps_map_clear(ifp->net);
19298 }
19299 } else {
19300 DHD_ERROR(("%s : ifp is NULL!!\n", __FUNCTION__));
19301 return -ENODEV;
19302 }
19303 return BCME_OK;
19304 }
19305
custom_xps_map_set(struct net_device * net,char * buf,size_t len)19306 int custom_xps_map_set(struct net_device *net, char *buf, size_t len)
19307 {
19308 cpumask_var_t mask;
19309 int err;
19310
19311 DHD_INFO(("%s : Entered.\n", __FUNCTION__));
19312
19313 if (!alloc_cpumask_var(&mask, GFP_KERNEL)) {
19314 DHD_ERROR(("%s : alloc_cpumask_var fail.\n", __FUNCTION__));
19315 return -ENOMEM;
19316 }
19317
19318 err = bitmap_parse(buf, len, cpumask_bits(mask), nr_cpumask_bits);
19319 if (err) {
19320 free_cpumask_var(mask);
19321 DHD_ERROR(("%s : bitmap_parse fail.\n", __FUNCTION__));
19322 return err;
19323 }
19324
19325 err = netif_set_xps_queue(net, mask, 0);
19326
19327 free_cpumask_var(mask);
19328
19329 if (0 == err)
19330 WL_MSG(net->name, "Done. mapping cpu\n");
19331
19332 return err;
19333 }
19334
custom_xps_map_clear(struct net_device * net)19335 void custom_xps_map_clear(struct net_device *net)
19336 {
19337 struct xps_dev_maps *dev_maps;
19338
19339 DHD_INFO(("%s : Entered.\n", __FUNCTION__));
19340
19341 rcu_read_lock();
19342 dev_maps = rcu_dereference(net->xps_maps);
19343 rcu_read_unlock();
19344
19345 if (dev_maps) {
19346 RCU_INIT_POINTER(net->xps_maps, NULL);
19347 kfree_rcu(dev_maps, rcu);
19348 DHD_INFO(("%s : xps_cpus map clear.\n", __FUNCTION__));
19349 }
19350 }
19351 #endif // endif
19352
19353 #if defined(SET_RPS_CPUS)
dhd_rps_cpus_enable(struct net_device * net,int enable)19354 int dhd_rps_cpus_enable(struct net_device *net, int enable)
19355 {
19356 dhd_info_t *dhd = DHD_DEV_INFO(net);
19357 dhd_if_t *ifp;
19358 int ifidx;
19359 char * RPS_CPU_SETBUF;
19360
19361 ifidx = dhd_net2idx(dhd, net);
19362 if (ifidx == DHD_BAD_IF) {
19363 DHD_ERROR(("%s bad ifidx\n", __FUNCTION__));
19364 return -ENODEV;
19365 }
19366
19367 if (!dhd->pub.conf->rps_cpus)
19368 return -ENODEV;
19369
19370 if (ifidx == PRIMARY_INF) {
19371 if (dhd->pub.op_mode == DHD_FLAG_IBSS_MODE) {
19372 DHD_INFO(("%s : set for IBSS.\n", __FUNCTION__));
19373 RPS_CPU_SETBUF = RPS_CPUS_MASK_IBSS;
19374 } else {
19375 DHD_INFO(("%s : set for BSS.\n", __FUNCTION__));
19376 RPS_CPU_SETBUF = RPS_CPUS_MASK;
19377 }
19378 } else if (ifidx == VIRTUAL_INF) {
19379 DHD_INFO(("%s : set for P2P.\n", __FUNCTION__));
19380 RPS_CPU_SETBUF = RPS_CPUS_MASK_P2P;
19381 } else {
19382 DHD_ERROR(("%s : Invalid index : %d.\n", __FUNCTION__, ifidx));
19383 return -EINVAL;
19384 }
19385
19386 ifp = dhd->iflist[ifidx];
19387 if (ifp) {
19388 if (enable) {
19389 DHD_INFO(("%s : set rps_cpus as [%s]\n", __FUNCTION__, RPS_CPU_SETBUF));
19390 custom_rps_map_set(ifp->net->_rx, RPS_CPU_SETBUF, strlen(RPS_CPU_SETBUF));
19391 } else {
19392 custom_rps_map_clear(ifp->net->_rx);
19393 }
19394 } else {
19395 DHD_ERROR(("%s : ifp is NULL!!\n", __FUNCTION__));
19396 return -ENODEV;
19397 }
19398 return BCME_OK;
19399 }
19400
custom_rps_map_set(struct netdev_rx_queue * queue,char * buf,size_t len)19401 int custom_rps_map_set(struct netdev_rx_queue *queue, char *buf, size_t len)
19402 {
19403 struct rps_map *old_map, *map;
19404 cpumask_var_t mask;
19405 int err, cpu, i;
19406 static DEFINE_SPINLOCK(rps_map_lock);
19407
19408 DHD_INFO(("%s : Entered.\n", __FUNCTION__));
19409
19410 if (!alloc_cpumask_var(&mask, GFP_KERNEL)) {
19411 DHD_ERROR(("%s : alloc_cpumask_var fail.\n", __FUNCTION__));
19412 return -ENOMEM;
19413 }
19414
19415 err = bitmap_parse(buf, len, cpumask_bits(mask), nr_cpumask_bits);
19416 if (err) {
19417 free_cpumask_var(mask);
19418 DHD_ERROR(("%s : bitmap_parse fail.\n", __FUNCTION__));
19419 return err;
19420 }
19421
19422 map = kzalloc(max_t(unsigned int,
19423 RPS_MAP_SIZE(cpumask_weight(mask)), L1_CACHE_BYTES),
19424 GFP_KERNEL);
19425 if (!map) {
19426 free_cpumask_var(mask);
19427 DHD_ERROR(("%s : map malloc fail.\n", __FUNCTION__));
19428 return -ENOMEM;
19429 }
19430
19431 i = 0;
19432 for_each_cpu(cpu, mask) {
19433 map->cpus[i++] = cpu;
19434 }
19435
19436 if (i) {
19437 map->len = i;
19438 } else {
19439 kfree(map);
19440 map = NULL;
19441 free_cpumask_var(mask);
19442 DHD_ERROR(("%s : mapping cpu fail.\n", __FUNCTION__));
19443 return -1;
19444 }
19445
19446 spin_lock(&rps_map_lock);
19447 old_map = rcu_dereference_protected(queue->rps_map,
19448 lockdep_is_held(&rps_map_lock));
19449 rcu_assign_pointer(queue->rps_map, map);
19450 spin_unlock(&rps_map_lock);
19451
19452 if (map) {
19453 static_key_slow_inc(&rps_needed);
19454 }
19455 if (old_map) {
19456 kfree_rcu(old_map, rcu);
19457 static_key_slow_dec(&rps_needed);
19458 }
19459 free_cpumask_var(mask);
19460
19461 DHD_INFO(("%s : Done. mapping cpu nummber : %d\n", __FUNCTION__, map->len));
19462 return map->len;
19463 }
19464
custom_rps_map_clear(struct netdev_rx_queue * queue)19465 void custom_rps_map_clear(struct netdev_rx_queue *queue)
19466 {
19467 struct rps_map *map;
19468
19469 DHD_INFO(("%s : Entered.\n", __FUNCTION__));
19470
19471 map = rcu_dereference_protected(queue->rps_map, 1);
19472 if (map) {
19473 RCU_INIT_POINTER(queue->rps_map, NULL);
19474 kfree_rcu(map, rcu);
19475 DHD_INFO(("%s : rps_cpus map clear.\n", __FUNCTION__));
19476 }
19477 }
19478 #endif // endif
19479
19480 #if defined(ARGOS_NOTIFY_CB)
19481
19482 static int argos_status_notifier_wifi_cb(struct notifier_block *notifier,
19483 unsigned long speed, void *v);
19484 static int argos_status_notifier_p2p_cb(struct notifier_block *notifier,
19485 unsigned long speed, void *v);
19486
19487 int
argos_register_notifier_init(struct net_device * net)19488 argos_register_notifier_init(struct net_device *net)
19489 {
19490 int ret = 0;
19491
19492 DHD_INFO(("DHD: %s: \n", __FUNCTION__));
19493 argos_rps_ctrl_data.wlan_primary_netdev = net;
19494 argos_rps_ctrl_data.argos_rps_cpus_enabled = 0;
19495
19496 if (argos_wifi.notifier_call == NULL) {
19497 argos_wifi.notifier_call = argos_status_notifier_wifi_cb;
19498 ret = sec_argos_register_notifier(&argos_wifi, ARGOS_WIFI_TABLE_LABEL);
19499 if (ret < 0) {
19500 DHD_ERROR(("DHD:Failed to register WIFI notifier, ret=%d\n", ret));
19501 goto exit;
19502 }
19503 }
19504
19505 if (argos_p2p.notifier_call == NULL) {
19506 argos_p2p.notifier_call = argos_status_notifier_p2p_cb;
19507 ret = sec_argos_register_notifier(&argos_p2p, ARGOS_P2P_TABLE_LABEL);
19508 if (ret < 0) {
19509 DHD_ERROR(("DHD:Failed to register P2P notifier, ret=%d\n", ret));
19510 sec_argos_unregister_notifier(&argos_wifi, ARGOS_WIFI_TABLE_LABEL);
19511 goto exit;
19512 }
19513 }
19514
19515 return 0;
19516
19517 exit:
19518 if (argos_wifi.notifier_call) {
19519 argos_wifi.notifier_call = NULL;
19520 }
19521
19522 if (argos_p2p.notifier_call) {
19523 argos_p2p.notifier_call = NULL;
19524 }
19525
19526 return ret;
19527 }
19528
19529 int
argos_register_notifier_deinit(void)19530 argos_register_notifier_deinit(void)
19531 {
19532 DHD_INFO(("DHD: %s: \n", __FUNCTION__));
19533
19534 if (argos_rps_ctrl_data.wlan_primary_netdev == NULL) {
19535 DHD_ERROR(("DHD: primary_net_dev is null %s: \n", __FUNCTION__));
19536 return -1;
19537 }
19538 #ifndef DHD_LB
19539 custom_rps_map_clear(argos_rps_ctrl_data.wlan_primary_netdev->_rx);
19540 #endif /* !DHD_LB */
19541
19542 if (argos_p2p.notifier_call) {
19543 sec_argos_unregister_notifier(&argos_p2p, ARGOS_P2P_TABLE_LABEL);
19544 argos_p2p.notifier_call = NULL;
19545 }
19546
19547 if (argos_wifi.notifier_call) {
19548 sec_argos_unregister_notifier(&argos_wifi, ARGOS_WIFI_TABLE_LABEL);
19549 argos_wifi.notifier_call = NULL;
19550 }
19551
19552 argos_rps_ctrl_data.wlan_primary_netdev = NULL;
19553 argos_rps_ctrl_data.argos_rps_cpus_enabled = 0;
19554
19555 return 0;
19556 }
19557
19558 int
argos_status_notifier_wifi_cb(struct notifier_block * notifier,unsigned long speed,void * v)19559 argos_status_notifier_wifi_cb(struct notifier_block *notifier,
19560 unsigned long speed, void *v)
19561 {
19562 dhd_info_t *dhd;
19563 dhd_pub_t *dhdp;
19564 #if defined(ARGOS_NOTIFY_CB)
19565 unsigned int pcie_irq = 0;
19566 #endif /* ARGOS_NOTIFY_CB */
19567 DHD_INFO(("DHD: %s: speed=%ld\n", __FUNCTION__, speed));
19568
19569 if (argos_rps_ctrl_data.wlan_primary_netdev == NULL) {
19570 goto exit;
19571 }
19572
19573 dhd = DHD_DEV_INFO(argos_rps_ctrl_data.wlan_primary_netdev);
19574 if (dhd == NULL) {
19575 goto exit;
19576 }
19577
19578 dhdp = &dhd->pub;
19579 if (dhdp == NULL || !dhdp->up) {
19580 goto exit;
19581 }
19582 /* Check if reported TPut value is more than threshold value */
19583 if (speed > RPS_TPUT_THRESHOLD) {
19584 if (argos_rps_ctrl_data.argos_rps_cpus_enabled == 0) {
19585 /* It does not need to configre rps_cpus
19586 * if Load Balance is enabled
19587 */
19588 #ifndef DHD_LB
19589 int err = 0;
19590
19591 if (cpu_online(RPS_CPUS_WLAN_CORE_ID)) {
19592 err = custom_rps_map_set(
19593 argos_rps_ctrl_data.wlan_primary_netdev->_rx,
19594 RPS_CPUS_MASK, strlen(RPS_CPUS_MASK));
19595 } else {
19596 DHD_ERROR(("DHD: %s: RPS_Set fail,"
19597 " Core=%d Offline\n", __FUNCTION__,
19598 RPS_CPUS_WLAN_CORE_ID));
19599 err = -1;
19600 }
19601
19602 if (err < 0) {
19603 DHD_ERROR(("DHD: %s: Failed to RPS_CPUs. "
19604 "speed=%ld, error=%d\n",
19605 __FUNCTION__, speed, err));
19606 } else {
19607 #endif /* !DHD_LB */
19608 #if (defined(DHDTCPACK_SUPPRESS) && defined(BCMPCIE))
19609 if (dhdp->tcpack_sup_mode != TCPACK_SUP_HOLD) {
19610 DHD_ERROR(("%s : set ack suppress. TCPACK_SUP_ON(%d)\n",
19611 __FUNCTION__, TCPACK_SUP_HOLD));
19612 dhd_tcpack_suppress_set(dhdp, TCPACK_SUP_HOLD);
19613 }
19614 #endif /* DHDTCPACK_SUPPRESS && BCMPCIE */
19615 argos_rps_ctrl_data.argos_rps_cpus_enabled = 1;
19616 #ifndef DHD_LB
19617 DHD_ERROR(("DHD: %s: Set RPS_CPUs, speed=%ld\n",
19618 __FUNCTION__, speed));
19619 }
19620 #endif /* !DHD_LB */
19621 }
19622 } else {
19623 if (argos_rps_ctrl_data.argos_rps_cpus_enabled == 1) {
19624 #if (defined(DHDTCPACK_SUPPRESS) && defined(BCMPCIE))
19625 if (dhdp->tcpack_sup_mode != TCPACK_SUP_OFF) {
19626 DHD_ERROR(("%s : set ack suppress. TCPACK_SUP_OFF\n",
19627 __FUNCTION__));
19628 dhd_tcpack_suppress_set(dhdp, TCPACK_SUP_OFF);
19629 }
19630 #endif /* DHDTCPACK_SUPPRESS && BCMPCIE */
19631 #ifndef DHD_LB
19632 /* It does not need to configre rps_cpus
19633 * if Load Balance is enabled
19634 */
19635 custom_rps_map_clear(argos_rps_ctrl_data.wlan_primary_netdev->_rx);
19636 DHD_ERROR(("DHD: %s: Clear RPS_CPUs, speed=%ld\n", __FUNCTION__, speed));
19637 OSL_SLEEP(DELAY_TO_CLEAR_RPS_CPUS);
19638 #endif /* !DHD_LB */
19639 argos_rps_ctrl_data.argos_rps_cpus_enabled = 0;
19640 }
19641 }
19642
19643 exit:
19644 return NOTIFY_OK;
19645 }
19646
19647 int
argos_status_notifier_p2p_cb(struct notifier_block * notifier,unsigned long speed,void * v)19648 argos_status_notifier_p2p_cb(struct notifier_block *notifier,
19649 unsigned long speed, void *v)
19650 {
19651 DHD_INFO(("DHD: %s: speed=%ld\n", __FUNCTION__, speed));
19652 return argos_status_notifier_wifi_cb(notifier, speed, v);
19653 }
19654 #endif // endif
19655
19656 #ifdef DHD_DEBUG_PAGEALLOC
19657
19658 void
dhd_page_corrupt_cb(void * handle,void * addr_corrupt,size_t len)19659 dhd_page_corrupt_cb(void *handle, void *addr_corrupt, size_t len)
19660 {
19661 dhd_pub_t *dhdp = (dhd_pub_t *)handle;
19662
19663 DHD_ERROR(("%s: Got dhd_page_corrupt_cb 0x%p %d\n",
19664 __FUNCTION__, addr_corrupt, (uint32)len));
19665
19666 DHD_OS_WAKE_LOCK(dhdp);
19667 prhex("Page Corruption:", addr_corrupt, len);
19668 dhd_dump_to_kernelog(dhdp);
19669 #if defined(BCMPCIE) && defined(DHD_FW_COREDUMP)
19670 /* Load the dongle side dump to host memory and then BUG_ON() */
19671 dhdp->memdump_enabled = DUMP_MEMONLY;
19672 dhdp->memdump_type = DUMP_TYPE_MEMORY_CORRUPTION;
19673 dhd_bus_mem_dump(dhdp);
19674 #endif /* BCMPCIE && DHD_FW_COREDUMP */
19675 DHD_OS_WAKE_UNLOCK(dhdp);
19676 }
19677 EXPORT_SYMBOL(dhd_page_corrupt_cb);
19678 #endif /* DHD_DEBUG_PAGEALLOC */
19679
19680 #if defined(BCMPCIE) && defined(DHD_PKTID_AUDIT_ENABLED)
19681 void
dhd_pktid_error_handler(dhd_pub_t * dhdp)19682 dhd_pktid_error_handler(dhd_pub_t *dhdp)
19683 {
19684 DHD_ERROR(("%s: Got Pkt Id Audit failure \n", __FUNCTION__));
19685 DHD_OS_WAKE_LOCK(dhdp);
19686 dhd_dump_to_kernelog(dhdp);
19687 #ifdef DHD_FW_COREDUMP
19688 /* Load the dongle side dump to host memory */
19689 if (dhdp->memdump_enabled == DUMP_DISABLED) {
19690 dhdp->memdump_enabled = DUMP_MEMFILE;
19691 }
19692 dhdp->memdump_type = DUMP_TYPE_PKTID_AUDIT_FAILURE;
19693 dhd_bus_mem_dump(dhdp);
19694 #endif /* DHD_FW_COREDUMP */
19695 dhdp->hang_reason = HANG_REASON_PCIE_PKTID_ERROR;
19696 dhd_os_check_hang(dhdp, 0, -EREMOTEIO);
19697 DHD_OS_WAKE_UNLOCK(dhdp);
19698 }
19699 #endif /* BCMPCIE && DHD_PKTID_AUDIT_ENABLED */
19700
19701 struct net_device *
dhd_linux_get_primary_netdev(dhd_pub_t * dhdp)19702 dhd_linux_get_primary_netdev(dhd_pub_t *dhdp)
19703 {
19704 dhd_info_t *dhd = dhdp->info;
19705
19706 if (dhd->iflist[0] && dhd->iflist[0]->net)
19707 return dhd->iflist[0]->net;
19708 else
19709 return NULL;
19710 }
19711
19712 fw_download_status_t
dhd_fw_download_status(dhd_pub_t * dhd_pub)19713 dhd_fw_download_status(dhd_pub_t * dhd_pub)
19714 {
19715 return dhd_pub->fw_download_status;
19716 }
19717
19718 static int
dhd_create_to_notifier_skt(void)19719 dhd_create_to_notifier_skt(void)
19720 {
19721 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
19722 /* Kernel 3.7 onwards this API accepts only 3 arguments. */
19723 /* Kernel version 3.6 is a special case which accepts 4 arguments */
19724 nl_to_event_sk = netlink_kernel_create(&init_net, BCM_NL_USER, &dhd_netlink_cfg);
19725 #elif (LINUX_VERSION_CODE < KERNEL_VERSION(3, 6, 0))
19726 /* Kernel version 3.5 and below use this old API format */
19727 nl_to_event_sk = netlink_kernel_create(&init_net, BCM_NL_USER, 0,
19728 dhd_process_daemon_msg, NULL, THIS_MODULE);
19729 #else
19730 nl_to_event_sk = netlink_kernel_create(&init_net, BCM_NL_USER, THIS_MODULE,
19731 &dhd_netlink_cfg);
19732 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0)) */
19733 if (!nl_to_event_sk)
19734 {
19735 printf("Error creating socket.\n");
19736 return -1;
19737 }
19738 DHD_INFO(("nl_to socket created successfully...\n"));
19739 return 0;
19740 }
19741
19742 void
dhd_destroy_to_notifier_skt(void)19743 dhd_destroy_to_notifier_skt(void)
19744 {
19745 DHD_INFO(("Destroying nl_to socket\n"));
19746 netlink_kernel_release(nl_to_event_sk);
19747 }
19748
19749 static void
dhd_recv_msg_from_daemon(struct sk_buff * skb)19750 dhd_recv_msg_from_daemon(struct sk_buff *skb)
19751 {
19752 struct nlmsghdr *nlh;
19753 bcm_to_info_t *cmd;
19754
19755 nlh = (struct nlmsghdr *)skb->data;
19756 cmd = (bcm_to_info_t *)nlmsg_data(nlh);
19757 if ((cmd->magic == BCM_TO_MAGIC) && (cmd->reason == REASON_DAEMON_STARTED)) {
19758 sender_pid = ((struct nlmsghdr *)(skb->data))->nlmsg_pid;
19759 DHD_INFO(("DHD Daemon Started\n"));
19760 }
19761 }
19762
19763 int
dhd_send_msg_to_daemon(struct sk_buff * skb,void * data,int size)19764 dhd_send_msg_to_daemon(struct sk_buff *skb, void *data, int size)
19765 {
19766 struct nlmsghdr *nlh;
19767 struct sk_buff *skb_out;
19768 int ret = BCME_ERROR;
19769
19770 BCM_REFERENCE(skb);
19771 if (sender_pid == 0) {
19772 DHD_INFO(("Invalid PID 0\n"));
19773 skb_out = NULL;
19774 goto err;
19775 }
19776
19777 if ((skb_out = nlmsg_new(size, 0)) == NULL) {
19778 DHD_ERROR(("%s: skb alloc failed\n", __FUNCTION__));
19779 ret = BCME_NOMEM;
19780 goto err;
19781 }
19782 nlh = nlmsg_put(skb_out, 0, 0, NLMSG_DONE, size, 0);
19783 if (nlh == NULL) {
19784 DHD_ERROR(("%s: nlmsg_put failed\n", __FUNCTION__));
19785 goto err;
19786 }
19787 NETLINK_CB(skb_out).dst_group = 0; /* Unicast */
19788 (void)memcpy_s(nlmsg_data(nlh), size, (char *)data, size);
19789
19790 if ((ret = nlmsg_unicast(nl_to_event_sk, skb_out, sender_pid)) < 0) {
19791 DHD_ERROR(("Error sending message, ret:%d\n", ret));
19792 /* skb is already freed inside nlmsg_unicast() on error case */
19793 /* explicitly making skb_out to NULL to avoid double free */
19794 skb_out = NULL;
19795 goto err;
19796 }
19797 return BCME_OK;
19798 err:
19799 if (skb_out) {
19800 nlmsg_free(skb_out);
19801 }
19802 return ret;
19803 }
19804
19805 static void
dhd_process_daemon_msg(struct sk_buff * skb)19806 dhd_process_daemon_msg(struct sk_buff *skb)
19807 {
19808 bcm_to_info_t to_info;
19809
19810 to_info.magic = BCM_TO_MAGIC;
19811 to_info.reason = REASON_DAEMON_STARTED;
19812 to_info.trap = NO_TRAP;
19813
19814 dhd_recv_msg_from_daemon(skb);
19815 dhd_send_msg_to_daemon(skb, &to_info, sizeof(to_info));
19816 }
19817
19818 #ifdef DHD_LOG_DUMP
19819 bool
dhd_log_dump_ecntr_enabled(void)19820 dhd_log_dump_ecntr_enabled(void)
19821 {
19822 return (bool)logdump_ecntr_enable;
19823 }
19824
19825 bool
dhd_log_dump_rtt_enabled(void)19826 dhd_log_dump_rtt_enabled(void)
19827 {
19828 return (bool)logdump_rtt_enable;
19829 }
19830
19831 void
dhd_log_dump_init(dhd_pub_t * dhd)19832 dhd_log_dump_init(dhd_pub_t *dhd)
19833 {
19834 struct dhd_log_dump_buf *dld_buf, *dld_buf_special;
19835 int i = 0;
19836 uint8 *prealloc_buf = NULL, *bufptr = NULL;
19837 #if defined(CONFIG_DHD_USE_STATIC_BUF) && defined(DHD_USE_STATIC_MEMDUMP)
19838 int prealloc_idx = DHD_PREALLOC_DHD_LOG_DUMP_BUF;
19839 #endif /* CONFIG_DHD_USE_STATIC_BUF && DHD_USE_STATIC_MEMDUMP */
19840 int ret;
19841 dhd_dbg_ring_t *ring = NULL;
19842 unsigned long flags = 0;
19843 dhd_info_t *dhd_info = dhd->info;
19844 void *cookie_buf = NULL;
19845
19846 BCM_REFERENCE(ret);
19847 BCM_REFERENCE(ring);
19848 BCM_REFERENCE(flags);
19849
19850 /* sanity check */
19851 if (logdump_prsrv_tailsize <= 0 ||
19852 logdump_prsrv_tailsize > DHD_LOG_DUMP_MAX_TAIL_FLUSH_SIZE) {
19853 logdump_prsrv_tailsize = DHD_LOG_DUMP_MAX_TAIL_FLUSH_SIZE;
19854 }
19855 /* now adjust the preserve log flush size based on the
19856 * kernel printk log buffer size
19857 */
19858 #ifdef CONFIG_LOG_BUF_SHIFT
19859 DHD_ERROR(("%s: kernel log buf size = %uKB; logdump_prsrv_tailsize = %uKB;"
19860 " limit prsrv tail size to = %uKB\n",
19861 __FUNCTION__, (1 << CONFIG_LOG_BUF_SHIFT)/1024,
19862 logdump_prsrv_tailsize/1024, LOG_DUMP_KERNEL_TAIL_FLUSH_SIZE/1024));
19863
19864 if (logdump_prsrv_tailsize > LOG_DUMP_KERNEL_TAIL_FLUSH_SIZE) {
19865 logdump_prsrv_tailsize = LOG_DUMP_KERNEL_TAIL_FLUSH_SIZE;
19866 }
19867 #else
19868 DHD_ERROR(("%s: logdump_prsrv_tailsize = %uKB \n",
19869 __FUNCTION__, logdump_prsrv_tailsize/1024);
19870 #endif /* CONFIG_LOG_BUF_SHIFT */
19871
19872 mutex_init(&dhd_info->logdump_lock);
19873
19874 /* initialize log dump buf structures */
19875 memset(g_dld_buf, 0, sizeof(struct dhd_log_dump_buf) * DLD_BUFFER_NUM);
19876
19877 /* set the log dump buffer size based on the module_param */
19878 if (logdump_max_bufsize > LOG_DUMP_GENERAL_MAX_BUFSIZE ||
19879 logdump_max_bufsize <= 0)
19880 dld_buf_size[DLD_BUF_TYPE_GENERAL] = LOG_DUMP_GENERAL_MAX_BUFSIZE;
19881 else
19882 dld_buf_size[DLD_BUF_TYPE_GENERAL] = logdump_max_bufsize;
19883
19884 /* pre-alloc the memory for the log buffers & 'special' buffer */
19885 dld_buf_special = &g_dld_buf[DLD_BUF_TYPE_SPECIAL];
19886 #if defined(CONFIG_DHD_USE_STATIC_BUF) && defined(DHD_USE_STATIC_MEMDUMP)
19887 DHD_ERROR(("%s : Try to allocate memory total(%d) special(%d)\n",
19888 __FUNCTION__, LOG_DUMP_TOTAL_BUFSIZE, LOG_DUMP_SPECIAL_MAX_BUFSIZE));
19889 prealloc_buf = DHD_OS_PREALLOC(dhd, prealloc_idx++, LOG_DUMP_TOTAL_BUFSIZE);
19890 dld_buf_special->buffer = DHD_OS_PREALLOC(dhd, prealloc_idx++,
19891 dld_buf_size[DLD_BUF_TYPE_SPECIAL]);
19892 #else
19893 prealloc_buf = MALLOCZ(dhd->osh, LOG_DUMP_TOTAL_BUFSIZE);
19894 dld_buf_special->buffer = MALLOCZ(dhd->osh, dld_buf_size[DLD_BUF_TYPE_SPECIAL]);
19895 #endif /* CONFIG_DHD_USE_STATIC_BUF && DHD_USE_STATIC_MEMDUMP */
19896 if (!prealloc_buf) {
19897 DHD_ERROR(("Failed to pre-allocate memory for log buffers !\n"));
19898 goto fail;
19899 }
19900 if (!dld_buf_special->buffer) {
19901 DHD_ERROR(("Failed to pre-allocate memory for special buffer !\n"));
19902 goto fail;
19903 }
19904
19905 bufptr = prealloc_buf;
19906 for (i = 0; i < DLD_BUFFER_NUM; i++) {
19907 dld_buf = &g_dld_buf[i];
19908 dld_buf->dhd_pub = dhd;
19909 spin_lock_init(&dld_buf->lock);
19910 dld_buf->wraparound = 0;
19911 if (i != DLD_BUF_TYPE_SPECIAL) {
19912 dld_buf->buffer = bufptr;
19913 dld_buf->max = (unsigned long)dld_buf->buffer + dld_buf_size[i];
19914 bufptr = (uint8 *)dld_buf->max;
19915 } else {
19916 dld_buf->max = (unsigned long)dld_buf->buffer + dld_buf_size[i];
19917 }
19918 dld_buf->present = dld_buf->front = dld_buf->buffer;
19919 dld_buf->remain = dld_buf_size[i];
19920 dld_buf->enable = 1;
19921 }
19922
19923 #ifdef EWP_ECNTRS_LOGGING
19924 /* now use the rest of the pre-alloc'd memory for filter and ecounter log */
19925 dhd->ecntr_dbg_ring = MALLOCZ(dhd->osh, sizeof(dhd_dbg_ring_t));
19926 if (!dhd->ecntr_dbg_ring)
19927 goto fail;
19928
19929 ring = (dhd_dbg_ring_t *)dhd->ecntr_dbg_ring;
19930 ret = dhd_dbg_ring_init(dhd, ring, ECNTR_RING_ID,
19931 ECNTR_RING_NAME, LOG_DUMP_ECNTRS_MAX_BUFSIZE,
19932 bufptr, TRUE);
19933 if (ret != BCME_OK) {
19934 DHD_ERROR(("%s: unable to init ecntr ring !\n",
19935 __FUNCTION__));
19936 goto fail;
19937 }
19938 DHD_DBG_RING_LOCK(ring->lock, flags);
19939 ring->state = RING_ACTIVE;
19940 ring->threshold = 0;
19941 DHD_DBG_RING_UNLOCK(ring->lock, flags);
19942
19943 bufptr += LOG_DUMP_ECNTRS_MAX_BUFSIZE;
19944 #endif /* EWP_ECNTRS_LOGGING */
19945
19946 #ifdef EWP_RTT_LOGGING
19947 /* now use the rest of the pre-alloc'd memory for filter and ecounter log */
19948 dhd->rtt_dbg_ring = MALLOCZ(dhd->osh, sizeof(dhd_dbg_ring_t));
19949 if (!dhd->rtt_dbg_ring)
19950 goto fail;
19951
19952 ring = (dhd_dbg_ring_t *)dhd->rtt_dbg_ring;
19953 ret = dhd_dbg_ring_init(dhd, ring, RTT_RING_ID,
19954 RTT_RING_NAME, LOG_DUMP_RTT_MAX_BUFSIZE,
19955 bufptr, TRUE);
19956 if (ret != BCME_OK) {
19957 DHD_ERROR(("%s: unable to init ecntr ring !\n",
19958 __FUNCTION__));
19959 goto fail;
19960 }
19961 DHD_DBG_RING_LOCK(ring->lock, flags);
19962 ring->state = RING_ACTIVE;
19963 ring->threshold = 0;
19964 DHD_DBG_RING_UNLOCK(ring->lock, flags);
19965
19966 bufptr += LOG_DUMP_RTT_MAX_BUFSIZE;
19967 #endif /* EWP_RTT_LOGGING */
19968
19969 /* Concise buffer is used as intermediate buffer for following purposes
19970 * a) pull ecounters records temporarily before
19971 * writing it to file
19972 * b) to store dhd dump data before putting it to file
19973 * It should have a size equal to
19974 * MAX(largest possible ecntr record, 'dhd dump' data size)
19975 */
19976 dhd->concise_dbg_buf = MALLOC(dhd->osh, CONCISE_DUMP_BUFLEN);
19977 if (!dhd->concise_dbg_buf) {
19978 DHD_ERROR(("%s: unable to alloc mem for concise debug info !\n",
19979 __FUNCTION__));
19980 goto fail;
19981 }
19982
19983 cookie_buf = MALLOC(dhd->osh, LOG_DUMP_COOKIE_BUFSIZE);
19984 if (!cookie_buf) {
19985 DHD_ERROR(("%s: unable to alloc mem for logdump cookie buffer\n",
19986 __FUNCTION__));
19987 goto fail;
19988 }
19989 ret = dhd_logdump_cookie_init(dhd, cookie_buf, LOG_DUMP_COOKIE_BUFSIZE);
19990 if (ret != BCME_OK) {
19991 MFREE(dhd->osh, cookie_buf, LOG_DUMP_COOKIE_BUFSIZE);
19992 goto fail;
19993 }
19994 return;
19995
19996 fail:
19997
19998 if (dhd->logdump_cookie) {
19999 dhd_logdump_cookie_deinit(dhd);
20000 MFREE(dhd->osh, dhd->logdump_cookie, LOG_DUMP_COOKIE_BUFSIZE);
20001 dhd->logdump_cookie = NULL;
20002 }
20003
20004 if (dhd->concise_dbg_buf) {
20005 MFREE(dhd->osh, dhd->concise_dbg_buf, CONCISE_DUMP_BUFLEN);
20006 }
20007
20008 #ifdef EWP_ECNTRS_LOGGING
20009 if (dhd->ecntr_dbg_ring) {
20010 ring = (dhd_dbg_ring_t *)dhd->ecntr_dbg_ring;
20011 dhd_dbg_ring_deinit(dhd, ring);
20012 ring->ring_buf = NULL;
20013 ring->ring_size = 0;
20014 MFREE(dhd->osh, ring, sizeof(dhd_dbg_ring_t));
20015 dhd->ecntr_dbg_ring = NULL;
20016 }
20017 #endif /* EWP_ECNTRS_LOGGING */
20018
20019 #ifdef EWP_RTT_LOGGING
20020 if (dhd->rtt_dbg_ring) {
20021 ring = (dhd_dbg_ring_t *)dhd->rtt_dbg_ring;
20022 dhd_dbg_ring_deinit(dhd, ring);
20023 ring->ring_buf = NULL;
20024 ring->ring_size = 0;
20025 MFREE(dhd->osh, ring, sizeof(dhd_dbg_ring_t));
20026 dhd->rtt_dbg_ring = NULL;
20027 }
20028 #endif /* EWP_RTT_LOGGING */
20029
20030 #if defined(CONFIG_DHD_USE_STATIC_BUF) && defined(DHD_USE_STATIC_MEMDUMP)
20031 if (prealloc_buf) {
20032 DHD_OS_PREFREE(dhd, prealloc_buf, LOG_DUMP_TOTAL_BUFSIZE);
20033 }
20034 if (dld_buf_special->buffer) {
20035 DHD_OS_PREFREE(dhd, dld_buf_special->buffer,
20036 dld_buf_size[DLD_BUF_TYPE_SPECIAL]);
20037 }
20038 #else
20039 if (prealloc_buf) {
20040 MFREE(dhd->osh, prealloc_buf, LOG_DUMP_TOTAL_BUFSIZE);
20041 }
20042 if (dld_buf_special->buffer) {
20043 MFREE(dhd->osh, dld_buf_special->buffer,
20044 dld_buf_size[DLD_BUF_TYPE_SPECIAL]);
20045 }
20046 #endif /* CONFIG_DHD_USE_STATIC_BUF */
20047 for (i = 0; i < DLD_BUFFER_NUM; i++) {
20048 dld_buf = &g_dld_buf[i];
20049 dld_buf->enable = 0;
20050 dld_buf->buffer = NULL;
20051 }
20052
20053 mutex_destroy(&dhd_info->logdump_lock);
20054 }
20055
20056 void
20057 dhd_log_dump_deinit(dhd_pub_t *dhd)
20058 {
20059 struct dhd_log_dump_buf *dld_buf = NULL, *dld_buf_special = NULL;
20060 int i = 0;
20061 dhd_info_t *dhd_info = dhd->info;
20062 dhd_dbg_ring_t *ring = NULL;
20063
20064 BCM_REFERENCE(ring);
20065
20066 if (dhd->concise_dbg_buf) {
20067 MFREE(dhd->osh, dhd->concise_dbg_buf, CONCISE_DUMP_BUFLEN);
20068 dhd->concise_dbg_buf = NULL;
20069 }
20070
20071 if (dhd->logdump_cookie) {
20072 dhd_logdump_cookie_deinit(dhd);
20073 MFREE(dhd->osh, dhd->logdump_cookie, LOG_DUMP_COOKIE_BUFSIZE);
20074 dhd->logdump_cookie = NULL;
20075 }
20076
20077 #ifdef EWP_ECNTRS_LOGGING
20078 if (dhd->ecntr_dbg_ring) {
20079 ring = (dhd_dbg_ring_t *)dhd->ecntr_dbg_ring;
20080 dhd_dbg_ring_deinit(dhd, ring);
20081 ring->ring_buf = NULL;
20082 ring->ring_size = 0;
20083 MFREE(dhd->osh, ring, sizeof(dhd_dbg_ring_t));
20084 dhd->ecntr_dbg_ring = NULL;
20085 }
20086 #endif /* EWP_ECNTRS_LOGGING */
20087
20088 #ifdef EWP_RTT_LOGGING
20089 if (dhd->rtt_dbg_ring) {
20090 ring = (dhd_dbg_ring_t *)dhd->rtt_dbg_ring;
20091 dhd_dbg_ring_deinit(dhd, ring);
20092 ring->ring_buf = NULL;
20093 ring->ring_size = 0;
20094 MFREE(dhd->osh, ring, sizeof(dhd_dbg_ring_t));
20095 dhd->rtt_dbg_ring = NULL;
20096 }
20097 #endif /* EWP_RTT_LOGGING */
20098
20099 /* 'general' buffer points to start of the pre-alloc'd memory */
20100 dld_buf = &g_dld_buf[DLD_BUF_TYPE_GENERAL];
20101 dld_buf_special = &g_dld_buf[DLD_BUF_TYPE_SPECIAL];
20102 #if defined(CONFIG_DHD_USE_STATIC_BUF) && defined(DHD_USE_STATIC_MEMDUMP)
20103 if (dld_buf->buffer) {
20104 DHD_OS_PREFREE(dhd, dld_buf->buffer, LOG_DUMP_TOTAL_BUFSIZE);
20105 }
20106 if (dld_buf_special->buffer) {
20107 DHD_OS_PREFREE(dhd, dld_buf_special->buffer,
20108 dld_buf_size[DLD_BUF_TYPE_SPECIAL]);
20109 }
20110 #else
20111 if (dld_buf->buffer) {
20112 MFREE(dhd->osh, dld_buf->buffer, LOG_DUMP_TOTAL_BUFSIZE);
20113 }
20114 if (dld_buf_special->buffer) {
20115 MFREE(dhd->osh, dld_buf_special->buffer,
20116 dld_buf_size[DLD_BUF_TYPE_SPECIAL]);
20117 }
20118 #endif /* CONFIG_DHD_USE_STATIC_BUF */
20119 for (i = 0; i < DLD_BUFFER_NUM; i++) {
20120 dld_buf = &g_dld_buf[i];
20121 dld_buf->enable = 0;
20122 dld_buf->buffer = NULL;
20123 }
20124
20125 mutex_destroy(&dhd_info->logdump_lock);
20126 }
20127
20128 void
20129 dhd_log_dump_write(int type, char *binary_data,
20130 int binary_len, const char *fmt, ...)
20131 {
20132 int len = 0;
20133 char tmp_buf[DHD_LOG_DUMP_MAX_TEMP_BUFFER_SIZE] = {0, };
20134 va_list args;
20135 unsigned long flags = 0;
20136 struct dhd_log_dump_buf *dld_buf = NULL;
20137 bool flush_log = FALSE;
20138
20139 if (type < 0 || type >= DLD_BUFFER_NUM) {
20140 DHD_INFO(("%s: Unknown DHD_LOG_DUMP_BUF_TYPE(%d).\n",
20141 __FUNCTION__, type));
20142 return;
20143 }
20144
20145 dld_buf = &g_dld_buf[type];
20146
20147 if (dld_buf->enable != 1) {
20148 return;
20149 }
20150
20151 va_start(args, fmt);
20152 len = vsnprintf(tmp_buf, DHD_LOG_DUMP_MAX_TEMP_BUFFER_SIZE, fmt, args);
20153 /* Non ANSI C99 compliant returns -1,
20154 * ANSI compliant return len >= DHD_LOG_DUMP_MAX_TEMP_BUFFER_SIZE
20155 */
20156 va_end(args);
20157 if (len < 0) {
20158 return;
20159 }
20160
20161 if (len >= DHD_LOG_DUMP_MAX_TEMP_BUFFER_SIZE) {
20162 len = DHD_LOG_DUMP_MAX_TEMP_BUFFER_SIZE - 1;
20163 tmp_buf[len] = '\0';
20164 }
20165
20166 /* make a critical section to eliminate race conditions */
20167 spin_lock_irqsave(&dld_buf->lock, flags);
20168 if (dld_buf->remain < len) {
20169 dld_buf->wraparound = 1;
20170 dld_buf->present = dld_buf->front;
20171 dld_buf->remain = dld_buf_size[type];
20172 /* if wrap around happens, flush the ring buffer to the file */
20173 flush_log = TRUE;
20174 }
20175
20176 memcpy(dld_buf->present, tmp_buf, len);
20177 dld_buf->remain -= len;
20178 dld_buf->present += len;
20179 spin_unlock_irqrestore(&dld_buf->lock, flags);
20180
20181 /* double check invalid memory operation */
20182 ASSERT((unsigned long)dld_buf->present <= dld_buf->max);
20183
20184 if (dld_buf->dhd_pub) {
20185 dhd_pub_t *dhdp = (dhd_pub_t *)dld_buf->dhd_pub;
20186 dhdp->logdump_periodic_flush =
20187 logdump_periodic_flush;
20188 if (logdump_periodic_flush && flush_log) {
20189 log_dump_type_t *flush_type = MALLOCZ(dhdp->osh,
20190 sizeof(log_dump_type_t));
20191 if (flush_type) {
20192 *flush_type = type;
20193 dhd_schedule_log_dump(dld_buf->dhd_pub, flush_type);
20194 }
20195 }
20196 }
20197 }
20198
20199 char*
20200 dhd_log_dump_get_timestamp(void)
20201 {
20202 static char buf[16];
20203 u64 ts_nsec;
20204 unsigned long rem_nsec;
20205
20206 ts_nsec = local_clock();
20207 rem_nsec = DIV_AND_MOD_U64_BY_U32(ts_nsec, NSEC_PER_SEC);
20208 snprintf(buf, sizeof(buf), "%5lu.%06lu",
20209 (unsigned long)ts_nsec, rem_nsec / NSEC_PER_USEC);
20210
20211 return buf;
20212 }
20213 #endif /* DHD_LOG_DUMP */
20214
20215 #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
20216 void
20217 dhd_flush_rx_tx_wq(dhd_pub_t *dhdp)
20218 {
20219 dhd_info_t * dhd;
20220
20221 if (dhdp) {
20222 dhd = dhdp->info;
20223 if (dhd) {
20224 flush_workqueue(dhd->tx_wq);
20225 flush_workqueue(dhd->rx_wq);
20226 }
20227 }
20228
20229 return;
20230 }
20231 #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
20232
20233 #ifdef DHD_DEBUG_UART
20234 bool
20235 dhd_debug_uart_is_running(struct net_device *dev)
20236 {
20237 dhd_info_t *dhd = DHD_DEV_INFO(dev);
20238
20239 if (dhd->duart_execute) {
20240 return TRUE;
20241 }
20242
20243 return FALSE;
20244 }
20245
20246 static void
20247 dhd_debug_uart_exec_rd(void *handle, void *event_info, u8 event)
20248 {
20249 dhd_pub_t *dhdp = handle;
20250 dhd_debug_uart_exec(dhdp, "rd");
20251 }
20252
20253 static void
20254 dhd_debug_uart_exec(dhd_pub_t *dhdp, char *cmd)
20255 {
20256 int ret;
20257
20258 char *argv[] = {DHD_DEBUG_UART_EXEC_PATH, cmd, NULL};
20259 char *envp[] = {"HOME=/", "TERM=linux", "PATH=/sbin:/system/bin", NULL};
20260
20261 #ifdef DHD_FW_COREDUMP
20262 if (dhdp->memdump_enabled == DUMP_MEMFILE_BUGON)
20263 #endif // endif
20264 {
20265 if (dhdp->hang_reason == HANG_REASON_PCIE_LINK_DOWN_RC_DETECT ||
20266 dhdp->hang_reason == HANG_REASON_PCIE_LINK_DOWN_EP_DETECT ||
20267 #ifdef DHD_FW_COREDUMP
20268 dhdp->memdump_success == FALSE ||
20269 #endif // endif
20270 FALSE) {
20271 dhdp->info->duart_execute = TRUE;
20272 DHD_ERROR(("DHD: %s - execute %s %s\n",
20273 __FUNCTION__, DHD_DEBUG_UART_EXEC_PATH, cmd));
20274 ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
20275 DHD_ERROR(("DHD: %s - %s %s ret = %d\n",
20276 __FUNCTION__, DHD_DEBUG_UART_EXEC_PATH, cmd, ret));
20277 dhdp->info->duart_execute = FALSE;
20278
20279 #ifdef DHD_LOG_DUMP
20280 if (dhdp->memdump_type != DUMP_TYPE_BY_SYSDUMP)
20281 #endif // endif
20282 {
20283 BUG_ON(1);
20284 }
20285 }
20286 }
20287 }
20288 #endif /* DHD_DEBUG_UART */
20289
20290 #if defined(DHD_BLOB_EXISTENCE_CHECK)
20291 void
20292 dhd_set_blob_support(dhd_pub_t *dhdp, char *fw_path)
20293 {
20294 struct file *fp;
20295 char *filepath = VENDOR_PATH CONFIG_BCMDHD_CLM_PATH;
20296 fp = filp_open(filepath, O_RDONLY, 0);
20297 if (IS_ERR(fp)) {
20298 DHD_ERROR(("%s: ----- blob file doesn't exist (%s) -----\n", __FUNCTION__,
20299 filepath));
20300 dhdp->is_blob = FALSE;
20301 } else {
20302 DHD_ERROR(("%s: ----- blob file exists (%s)-----\n", __FUNCTION__, filepath));
20303 dhdp->is_blob = TRUE;
20304 #if defined(CONCATE_BLOB)
20305 strncat(fw_path, "_blob", strlen("_blob"));
20306 #else
20307 BCM_REFERENCE(fw_path);
20308 #endif /* SKIP_CONCATE_BLOB */
20309 filp_close(fp, NULL);
20310 }
20311 }
20312 #endif /* DHD_BLOB_EXISTENCE_CHECK */
20313
20314 #if defined(PCIE_FULL_DONGLE)
20315 /** test / loopback */
20316 void
20317 dmaxfer_free_dmaaddr_handler(void *handle, void *event_info, u8 event)
20318 {
20319 dmaxref_mem_map_t *dmmap = (dmaxref_mem_map_t *)event_info;
20320 dhd_info_t *dhd_info = (dhd_info_t *)handle;
20321
20322 if (event != DHD_WQ_WORK_DMA_LB_MEM_REL) {
20323 DHD_ERROR(("%s: Unexpected event \n", __FUNCTION__));
20324 return;
20325 }
20326 if (dhd_info == NULL) {
20327 DHD_ERROR(("%s: Invalid dhd_info\n", __FUNCTION__));
20328 return;
20329 }
20330 if (dmmap == NULL) {
20331 DHD_ERROR(("%s: dmmap is null\n", __FUNCTION__));
20332 return;
20333 }
20334 dmaxfer_free_prev_dmaaddr(&dhd_info->pub, dmmap);
20335 }
20336
20337 void
20338 dhd_schedule_dmaxfer_free(dhd_pub_t *dhdp, dmaxref_mem_map_t *dmmap)
20339 {
20340 dhd_info_t *dhd_info = dhdp->info;
20341
20342 dhd_deferred_schedule_work(dhd_info->dhd_deferred_wq, (void *)dmmap,
20343 DHD_WQ_WORK_DMA_LB_MEM_REL, dmaxfer_free_dmaaddr_handler, DHD_WQ_WORK_PRIORITY_LOW);
20344 }
20345 #endif /* PCIE_FULL_DONGLE */
20346 /* ---------------------------- End of sysfs implementation ------------------------------------- */
20347
20348 #ifdef SET_PCIE_IRQ_CPU_CORE
20349 void
20350 dhd_set_irq_cpucore(dhd_pub_t *dhdp, int affinity_cmd)
20351 {
20352 unsigned int pcie_irq = 0;
20353
20354 if (!dhdp) {
20355 DHD_ERROR(("%s : dhd is NULL\n", __FUNCTION__));
20356 return;
20357 }
20358
20359 if (!dhdp->bus) {
20360 DHD_ERROR(("%s : dhd->bus is NULL\n", __FUNCTION__));
20361 return;
20362 }
20363
20364 DHD_ERROR(("Enter %s, PCIe affinity cmd=0x%x\n", __FUNCTION__, affinity_cmd));
20365
20366 if (dhdpcie_get_pcieirq(dhdp->bus, &pcie_irq)) {
20367 DHD_ERROR(("%s : Can't get interrupt number\n", __FUNCTION__));
20368 return;
20369 }
20370
20371 /*
20372 irq_set_affinity() assign dedicated CPU core PCIe interrupt
20373 If dedicated CPU core is not on-line,
20374 PCIe interrupt scheduled on CPU core 0
20375 */
20376 switch (affinity_cmd) {
20377 case PCIE_IRQ_AFFINITY_OFF:
20378 break;
20379 case PCIE_IRQ_AFFINITY_BIG_CORE_ANY:
20380 #if defined(CONFIG_ARCH_SM8150)
20381 irq_set_affinity_hint(pcie_irq, dhdp->info->cpumask_primary);
20382 irq_set_affinity(pcie_irq, dhdp->info->cpumask_primary);
20383 #else /* Exynos and Others */
20384 irq_set_affinity(pcie_irq, dhdp->info->cpumask_primary);
20385 #endif /* CONFIG_ARCH_SM8150 */
20386 break;
20387 #if defined(CONFIG_SOC_EXYNOS9810) || defined(CONFIG_SOC_EXYNOS9820)
20388 case PCIE_IRQ_AFFINITY_BIG_CORE_EXYNOS:
20389 DHD_ERROR(("%s, PCIe IRQ:%u set Core %d\n",
20390 __FUNCTION__, pcie_irq, PCIE_IRQ_CPU_CORE));
20391 irq_set_affinity(pcie_irq, cpumask_of(PCIE_IRQ_CPU_CORE));
20392 break;
20393 #endif /* CONFIG_SOC_EXYNOS9810 || CONFIG_SOC_EXYNOS9820 */
20394 default:
20395 DHD_ERROR(("%s, Unknown PCIe affinity cmd=0x%x\n",
20396 __FUNCTION__, affinity_cmd));
20397 }
20398 }
20399 #endif /* SET_PCIE_IRQ_CPU_CORE */
20400
20401 int
20402 dhd_write_file(const char *filepath, char *buf, int buf_len)
20403 {
20404 struct file *fp = NULL;
20405 #if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0))
20406 mm_segment_t old_fs;
20407 #endif
20408 int ret = 0;
20409
20410 /* change to KERNEL_DS address limit */
20411 #if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0))
20412 old_fs = get_fs();
20413 set_fs(KERNEL_DS);
20414 #endif
20415
20416 /* File is always created. */
20417 fp = filp_open(filepath, O_RDWR | O_CREAT, 0664);
20418 if (IS_ERR(fp)) {
20419 DHD_ERROR(("%s: Couldn't open file '%s' err %ld\n",
20420 __FUNCTION__, filepath, PTR_ERR(fp)));
20421 ret = BCME_ERROR;
20422 } else {
20423 if (fp->f_mode & FMODE_WRITE) {
20424 ret = compat_vfs_write(fp, buf, buf_len, &fp->f_pos);
20425 if (ret < 0) {
20426 DHD_ERROR(("%s: Couldn't write file '%s'\n",
20427 __FUNCTION__, filepath));
20428 ret = BCME_ERROR;
20429 } else {
20430 ret = BCME_OK;
20431 }
20432 }
20433 filp_close(fp, NULL);
20434 }
20435
20436 /* restore previous address limit */
20437 #if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0))
20438 set_fs(old_fs);
20439 #endif
20440
20441 return ret;
20442 }
20443
20444 int
20445 dhd_read_file(const char *filepath, char *buf, int buf_len)
20446 {
20447 struct file *fp = NULL;
20448 #if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0))
20449 mm_segment_t old_fs;
20450 #endif
20451 int ret;
20452
20453 /* change to KERNEL_DS address limit */
20454 #if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0))
20455 old_fs = get_fs();
20456 set_fs(KERNEL_DS);
20457 #endif
20458
20459 fp = filp_open(filepath, O_RDONLY, 0);
20460 if (IS_ERR(fp)) {
20461 #if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0))
20462 set_fs(old_fs);
20463 #endif
20464 DHD_ERROR(("%s: File %s doesn't exist\n", __FUNCTION__, filepath));
20465 return BCME_ERROR;
20466 }
20467
20468 ret = compat_kernel_read(fp, 0, buf, buf_len);
20469 filp_close(fp, NULL);
20470
20471 /* restore previous address limit */
20472 #if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0))
20473 set_fs(old_fs);
20474 #endif
20475
20476 /* Return the number of bytes read */
20477 if (ret > 0) {
20478 /* Success to read */
20479 ret = 0;
20480 } else {
20481 DHD_ERROR(("%s: Couldn't read the file %s, ret=%d\n",
20482 __FUNCTION__, filepath, ret));
20483 ret = BCME_ERROR;
20484 }
20485
20486 return ret;
20487 }
20488
20489 int
20490 dhd_write_file_and_check(const char *filepath, char *buf, int buf_len)
20491 {
20492 int ret;
20493
20494 ret = dhd_write_file(filepath, buf, buf_len);
20495 if (ret < 0) {
20496 return ret;
20497 }
20498
20499 /* Read the file again and check if the file size is not zero */
20500 memset(buf, 0, buf_len);
20501 ret = dhd_read_file(filepath, buf, buf_len);
20502
20503 return ret;
20504 }
20505
20506 #ifdef FILTER_IE
20507 int dhd_read_from_file(dhd_pub_t *dhd)
20508 {
20509 int ret = 0, nread = 0;
20510 void *fd;
20511 uint8 *buf;
20512 NULL_CHECK(dhd, "dhd is NULL", ret);
20513
20514 buf = MALLOCZ(dhd->osh, FILE_BLOCK_READ_SIZE);
20515 if (!buf) {
20516 DHD_ERROR(("error: failed to alllocate buf.\n"));
20517 return BCME_NOMEM;
20518 }
20519
20520 /* open file to read */
20521 fd = dhd_os_open_image1(dhd, FILTER_IE_PATH);
20522 if (!fd) {
20523 DHD_ERROR(("error: failed to open %s\n", FILTER_IE_PATH));
20524 ret = BCME_EPERM;
20525 goto exit;
20526 }
20527 nread = dhd_os_get_image_block(buf, (FILE_BLOCK_READ_SIZE - 1), fd);
20528 if (nread > 0) {
20529 buf[nread] = '\0';
20530 if ((ret = dhd_parse_filter_ie(dhd, buf)) < 0) {
20531 DHD_ERROR(("error: failed to parse filter ie\n"));
20532 }
20533 } else {
20534 DHD_ERROR(("error: zero length file.failed to read\n"));
20535 ret = BCME_ERROR;
20536 }
20537 dhd_os_close_image1(dhd, fd);
20538 exit:
20539 if (buf) {
20540 MFREE(dhd->osh, buf, FILE_BLOCK_READ_SIZE);
20541 buf = NULL;
20542 }
20543 return ret;
20544 }
20545
20546 int dhd_get_filter_ie_count(dhd_pub_t *dhdp, uint8* buf)
20547 {
20548 uint8* pstr = buf;
20549 int element_count = 0;
20550
20551 if (buf == NULL) {
20552 return BCME_ERROR;
20553 }
20554
20555 while (*pstr != '\0') {
20556 if (*pstr == '\n') {
20557 element_count++;
20558 }
20559 pstr++;
20560 }
20561 /*
20562 * New line character must not be present after last line.
20563 * To count last line
20564 */
20565 element_count++;
20566
20567 return element_count;
20568 }
20569
20570 int dhd_parse_oui(dhd_pub_t *dhd, uint8 *inbuf, uint8 *oui, int len)
20571 {
20572 uint8 i, j, msb, lsb, oui_len = 0;
20573 /*
20574 * OUI can vary from 3 bytes to 5 bytes.
20575 * While reading from file as ascii input it can
20576 * take maximum size of 14 bytes and minumum size of
20577 * 8 bytes including ":"
20578 * Example 5byte OUI <AB:DE:BE:CD:FA>
20579 * Example 3byte OUI <AB:DC:EF>
20580 */
20581
20582 if ((inbuf == NULL) || (len < 8) || (len > 14)) {
20583 DHD_ERROR(("error: failed to parse OUI \n"));
20584 return BCME_ERROR;
20585 }
20586
20587 for (j = 0, i = 0; i < len; i += 3, ++j) {
20588 if (!bcm_isxdigit(inbuf[i]) || !bcm_isxdigit(inbuf[i + 1])) {
20589 DHD_ERROR(("error: invalid OUI format \n"));
20590 return BCME_ERROR;
20591 }
20592 msb = inbuf[i] > '9' ? bcm_toupper(inbuf[i]) - 'A' + 10 : inbuf[i] - '0';
20593 lsb = inbuf[i + 1] > '9' ? bcm_toupper(inbuf[i + 1]) -
20594 'A' + 10 : inbuf[i + 1] - '0';
20595 oui[j] = (msb << 4) | lsb;
20596 }
20597 /* Size of oui.It can vary from 3/4/5 */
20598 oui_len = j;
20599
20600 return oui_len;
20601 }
20602
20603 int dhd_check_valid_ie(dhd_pub_t *dhdp, uint8* buf, int len)
20604 {
20605 int i = 0;
20606
20607 while (i < len) {
20608 if (!bcm_isdigit(buf[i])) {
20609 DHD_ERROR(("error: non digit value found in filter_ie \n"));
20610 return BCME_ERROR;
20611 }
20612 i++;
20613 }
20614 if (bcm_atoi((char*)buf) > 255) {
20615 DHD_ERROR(("error: element id cannot be greater than 255 \n"));
20616 return BCME_ERROR;
20617 }
20618
20619 return BCME_OK;
20620 }
20621
20622 int dhd_parse_filter_ie(dhd_pub_t *dhd, uint8 *buf)
20623 {
20624 int element_count = 0, i = 0, oui_size = 0, ret = 0;
20625 uint16 bufsize, buf_space_left, id = 0, len = 0;
20626 uint16 filter_iovsize, all_tlvsize;
20627 wl_filter_ie_tlv_t *p_ie_tlv = NULL;
20628 wl_filter_ie_iov_v1_t *p_filter_iov = (wl_filter_ie_iov_v1_t *) NULL;
20629 char *token = NULL, *ele_token = NULL, *oui_token = NULL, *type = NULL;
20630 uint8 data[20];
20631
20632 element_count = dhd_get_filter_ie_count(dhd, buf);
20633 DHD_INFO(("total element count %d \n", element_count));
20634 /* Calculate the whole buffer size */
20635 filter_iovsize = sizeof(wl_filter_ie_iov_v1_t) + FILTER_IE_BUFSZ;
20636 p_filter_iov = MALLOCZ(dhd->osh, filter_iovsize);
20637
20638 if (p_filter_iov == NULL) {
20639 DHD_ERROR(("error: failed to allocate %d bytes of memory\n", filter_iovsize));
20640 return BCME_ERROR;
20641 }
20642
20643 /* setup filter iovar header */
20644 p_filter_iov->version = WL_FILTER_IE_VERSION;
20645 p_filter_iov->len = filter_iovsize;
20646 p_filter_iov->fixed_length = p_filter_iov->len - FILTER_IE_BUFSZ;
20647 p_filter_iov->pktflag = FC_PROBE_REQ;
20648 p_filter_iov->option = WL_FILTER_IE_CHECK_SUB_OPTION;
20649 /* setup TLVs */
20650 bufsize = filter_iovsize - WL_FILTER_IE_IOV_HDR_SIZE; /* adjust available size for TLVs */
20651 p_ie_tlv = (wl_filter_ie_tlv_t *)&p_filter_iov->tlvs[0];
20652 buf_space_left = bufsize;
20653
20654 while ((i < element_count) && (buf != NULL)) {
20655 len = 0;
20656 /* token contains one line of input data */
20657 token = bcmstrtok((char**)&buf, "\n", NULL);
20658 if (token == NULL) {
20659 break;
20660 }
20661 if ((ele_token = bcmstrstr(token, ",")) == NULL) {
20662 /* only element id is present */
20663 if (dhd_check_valid_ie(dhd, token, strlen(token)) == BCME_ERROR) {
20664 DHD_ERROR(("error: Invalid element id \n"));
20665 ret = BCME_ERROR;
20666 goto exit;
20667 }
20668 id = bcm_atoi((char*)token);
20669 data[len++] = WL_FILTER_IE_SET;
20670 } else {
20671 /* oui is present */
20672 ele_token = bcmstrtok(&token, ",", NULL);
20673 if ((ele_token == NULL) || (dhd_check_valid_ie(dhd, ele_token,
20674 strlen(ele_token)) == BCME_ERROR)) {
20675 DHD_ERROR(("error: Invalid element id \n"));
20676 ret = BCME_ERROR;
20677 goto exit;
20678 }
20679 id = bcm_atoi((char*)ele_token);
20680 data[len++] = WL_FILTER_IE_SET;
20681 if ((oui_token = bcmstrstr(token, ",")) == NULL) {
20682 oui_size = dhd_parse_oui(dhd, token, &(data[len]), strlen(token));
20683 if (oui_size == BCME_ERROR) {
20684 DHD_ERROR(("error: Invalid OUI \n"));
20685 ret = BCME_ERROR;
20686 goto exit;
20687 }
20688 len += oui_size;
20689 } else {
20690 /* type is present */
20691 oui_token = bcmstrtok(&token, ",", NULL);
20692 if ((oui_token == NULL) || ((oui_size =
20693 dhd_parse_oui(dhd, oui_token,
20694 &(data[len]), strlen(oui_token))) == BCME_ERROR)) {
20695 DHD_ERROR(("error: Invalid OUI \n"));
20696 ret = BCME_ERROR;
20697 goto exit;
20698 }
20699 len += oui_size;
20700 if ((type = bcmstrstr(token, ",")) == NULL) {
20701 if (dhd_check_valid_ie(dhd, token,
20702 strlen(token)) == BCME_ERROR) {
20703 DHD_ERROR(("error: Invalid type \n"));
20704 ret = BCME_ERROR;
20705 goto exit;
20706 }
20707 data[len++] = bcm_atoi((char*)token);
20708 } else {
20709 /* subtype is present */
20710 type = bcmstrtok(&token, ",", NULL);
20711 if ((type == NULL) || (dhd_check_valid_ie(dhd, type,
20712 strlen(type)) == BCME_ERROR)) {
20713 DHD_ERROR(("error: Invalid type \n"));
20714 ret = BCME_ERROR;
20715 goto exit;
20716 }
20717 data[len++] = bcm_atoi((char*)type);
20718 /* subtype is last element */
20719 if ((token == NULL) || (*token == '\0') ||
20720 (dhd_check_valid_ie(dhd, token,
20721 strlen(token)) == BCME_ERROR)) {
20722 DHD_ERROR(("error: Invalid subtype \n"));
20723 ret = BCME_ERROR;
20724 goto exit;
20725 }
20726 data[len++] = bcm_atoi((char*)token);
20727 }
20728 }
20729 }
20730 ret = bcm_pack_xtlv_entry((uint8 **)&p_ie_tlv,
20731 &buf_space_left, id, len, data, BCM_XTLV_OPTION_ALIGN32);
20732 if (ret != BCME_OK) {
20733 DHD_ERROR(("%s : bcm_pack_xtlv_entry() failed ,"
20734 "status=%d\n", __FUNCTION__, ret));
20735 goto exit;
20736 }
20737 i++;
20738 }
20739 if (i == 0) {
20740 /* file is empty or first line is blank */
20741 DHD_ERROR(("error: filter_ie file is empty or first line is blank \n"));
20742 ret = BCME_ERROR;
20743 goto exit;
20744 }
20745 /* update the iov header, set len to include all TLVs + header */
20746 all_tlvsize = (bufsize - buf_space_left);
20747 p_filter_iov->len = htol16(all_tlvsize + WL_FILTER_IE_IOV_HDR_SIZE);
20748 ret = dhd_iovar(dhd, 0, "filter_ie", (void *)p_filter_iov,
20749 p_filter_iov->len, NULL, 0, TRUE);
20750 if (ret != BCME_OK) {
20751 DHD_ERROR(("error: IOVAR failed, status=%d\n", ret));
20752 }
20753 exit:
20754 /* clean up */
20755 if (p_filter_iov) {
20756 MFREE(dhd->osh, p_filter_iov, filter_iovsize);
20757 p_filter_iov = NULL;
20758 }
20759 return ret;
20760 }
20761 #endif /* FILTER_IE */
20762 #ifdef DHD_WAKE_STATUS
20763 wake_counts_t*
20764 dhd_get_wakecount(dhd_pub_t *dhdp)
20765 {
20766 #ifdef BCMDBUS
20767 return NULL;
20768 #else
20769 return dhd_bus_get_wakecount(dhdp);
20770 #endif /* BCMDBUS */
20771 }
20772 #endif /* DHD_WAKE_STATUS */
20773
20774 int
20775 dhd_get_random_bytes(uint8 *buf, uint len)
20776 {
20777 #ifdef BCMPCIE
20778 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0))
20779 int rndlen = get_random_bytes_arch(buf, len);
20780 if (rndlen != len) {
20781 bzero(buf, len);
20782 get_random_bytes(buf, len);
20783 }
20784 #else
20785 get_random_bytes_arch(buf, len);
20786 #endif // endif
20787 #endif /* BCMPCIE */
20788 return BCME_OK;
20789 }
20790
20791 #ifdef DHD_ERPOM
20792 static void
20793 dhd_error_recovery(void *handle, void *event_info, u8 event)
20794 {
20795 dhd_info_t *dhd = handle;
20796 dhd_pub_t *dhdp;
20797 int ret = 0;
20798
20799 if (!dhd) {
20800 DHD_ERROR(("%s: dhd is NULL\n", __FUNCTION__));
20801 return;
20802 }
20803
20804 dhdp = &dhd->pub;
20805
20806 if (!(dhd->dhd_state & DHD_ATTACH_STATE_DONE)) {
20807 DHD_ERROR(("%s: init not completed, cannot initiate recovery\n",
20808 __FUNCTION__));
20809 return;
20810 }
20811
20812 ret = dhd_bus_perform_flr_with_quiesce(dhdp, dhdp->bus, FALSE);
20813 if (ret != BCME_DNGL_DEVRESET) {
20814 DHD_ERROR(("%s: dhd_bus_perform_flr_with_quiesce failed with ret: %d,"
20815 "toggle REG_ON\n", __FUNCTION__, ret));
20816 /* toggle REG_ON */
20817 dhdp->pom_toggle_reg_on(WLAN_FUNC_ID, BY_WLAN_DUE_TO_WLAN);
20818 return;
20819 }
20820 }
20821
20822 void
20823 dhd_schedule_reset(dhd_pub_t *dhdp)
20824 {
20825 if (dhdp->enable_erpom) {
20826 dhd_deferred_schedule_work(dhdp->info->dhd_deferred_wq, NULL,
20827 DHD_WQ_WORK_ERROR_RECOVERY, dhd_error_recovery, DHD_WQ_WORK_PRIORITY_HIGH);
20828 }
20829 }
20830 #endif /* DHD_ERPOM */
20831
20832 void
20833 get_debug_dump_time(char *str)
20834 {
20835 struct osl_timespec curtime;
20836 unsigned long local_time;
20837 struct rtc_time tm;
20838
20839 if (!strlen(str)) {
20840 osl_do_gettimeofday(&curtime);
20841 local_time = (u32)(curtime.tv_sec -
20842 (sys_tz.tz_minuteswest * DHD_LOG_DUMP_TS_MULTIPLIER_VALUE));
20843 rtc_time_to_tm(local_time, &tm);
20844
20845 snprintf(str, DEBUG_DUMP_TIME_BUF_LEN, DHD_LOG_DUMP_TS_FMT_YYMMDDHHMMSSMSMS,
20846 tm.tm_year - 100, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min,
20847 tm.tm_sec, (int)(curtime.tv_usec/NSEC_PER_USEC));
20848 }
20849 }
20850
20851 void
20852 clear_debug_dump_time(char *str)
20853 {
20854 memset(str, 0, DEBUG_DUMP_TIME_BUF_LEN);
20855 }
20856
20857 void
20858 dhd_print_tasklet_status(dhd_pub_t *dhd)
20859 {
20860 dhd_info_t *dhdinfo;
20861
20862 if (!dhd) {
20863 DHD_ERROR(("%s : DHD is null\n", __FUNCTION__));
20864 return;
20865 }
20866
20867 dhdinfo = dhd->info;
20868
20869 if (!dhdinfo) {
20870 DHD_ERROR(("%s : DHD INFO is null \n", __FUNCTION__));
20871 return;
20872 }
20873
20874 DHD_ERROR(("DHD Tasklet status : 0x%lx\n", dhdinfo->tasklet.state));
20875 }
20876
20877 /*
20878 * DHD RING
20879 */
20880 #define DHD_RING_ERR_INTERNAL(fmt, ...) DHD_ERROR(("EWPF-" fmt, ##__VA_ARGS__))
20881 #define DHD_RING_TRACE_INTERNAL(fmt, ...) DHD_INFO(("EWPF-" fmt, ##__VA_ARGS__))
20882
20883 #define DHD_RING_ERR(x) DHD_RING_ERR_INTERNAL x
20884 #define DHD_RING_TRACE(x) DHD_RING_TRACE_INTERNAL x
20885
20886 #define DHD_RING_MAGIC 0x20170910
20887 #define DHD_RING_IDX_INVALID 0xffffffff
20888
20889 #define DHD_RING_SYNC_LOCK_INIT(osh) dhd_os_spin_lock_init(osh)
20890 #define DHD_RING_SYNC_LOCK_DEINIT(osh, lock) dhd_os_spin_lock_deinit(osh, lock)
20891 #define DHD_RING_SYNC_LOCK(lock, flags) (flags) = dhd_os_spin_lock(lock)
20892 #define DHD_RING_SYNC_UNLOCK(lock, flags) dhd_os_spin_unlock(lock, flags)
20893
20894 typedef struct {
20895 uint32 elem_size;
20896 uint32 elem_cnt;
20897 uint32 write_idx; /* next write index, -1 : not started */
20898 uint32 read_idx; /* next read index, -1 : not start */
20899
20900 /* protected elements during serialization */
20901 int lock_idx; /* start index of locked, element will not be overried */
20902 int lock_count; /* number of locked, from lock idx */
20903
20904 /* saved data elements */
20905 void *elem;
20906 } dhd_fixed_ring_info_t;
20907
20908 typedef struct {
20909 uint32 elem_size;
20910 uint32 elem_cnt;
20911 uint32 idx; /* -1 : not started */
20912 uint32 rsvd; /* reserved for future use */
20913
20914 /* protected elements during serialization */
20915 atomic_t ring_locked;
20916 /* check the overwriting */
20917 uint32 ring_overwrited;
20918
20919 /* saved data elements */
20920 void *elem;
20921 } dhd_singleidx_ring_info_t;
20922
20923 typedef struct {
20924 uint32 magic;
20925 uint32 type;
20926 void *ring_sync; /* spinlock for sync */
20927 union {
20928 dhd_fixed_ring_info_t fixed;
20929 dhd_singleidx_ring_info_t single;
20930 };
20931 } dhd_ring_info_t;
20932
20933 uint32
20934 dhd_ring_get_hdr_size(void)
20935 {
20936 return sizeof(dhd_ring_info_t);
20937 }
20938
20939 void *
20940 dhd_ring_init(dhd_pub_t *dhdp, uint8 *buf, uint32 buf_size, uint32 elem_size,
20941 uint32 elem_cnt, uint32 type)
20942 {
20943 dhd_ring_info_t *ret_ring;
20944
20945 if (!buf) {
20946 DHD_RING_ERR(("NO RING BUFFER\n"));
20947 return NULL;
20948 }
20949
20950 if (buf_size < dhd_ring_get_hdr_size() + elem_size * elem_cnt) {
20951 DHD_RING_ERR(("RING SIZE IS TOO SMALL\n"));
20952 return NULL;
20953 }
20954
20955 if (type != DHD_RING_TYPE_FIXED && type != DHD_RING_TYPE_SINGLE_IDX) {
20956 DHD_RING_ERR(("UNSUPPORTED RING TYPE\n"));
20957 return NULL;
20958 }
20959
20960 ret_ring = (dhd_ring_info_t *)buf;
20961 ret_ring->type = type;
20962 ret_ring->ring_sync = DHD_RING_SYNC_LOCK_INIT(dhdp->osh);
20963 ret_ring->magic = DHD_RING_MAGIC;
20964
20965 if (type == DHD_RING_TYPE_FIXED) {
20966 ret_ring->fixed.read_idx = DHD_RING_IDX_INVALID;
20967 ret_ring->fixed.write_idx = DHD_RING_IDX_INVALID;
20968 ret_ring->fixed.lock_idx = DHD_RING_IDX_INVALID;
20969 ret_ring->fixed.elem = buf + sizeof(dhd_ring_info_t);
20970 ret_ring->fixed.elem_size = elem_size;
20971 ret_ring->fixed.elem_cnt = elem_cnt;
20972 } else {
20973 ret_ring->single.idx = DHD_RING_IDX_INVALID;
20974 atomic_set(&ret_ring->single.ring_locked, 0);
20975 ret_ring->single.ring_overwrited = 0;
20976 ret_ring->single.rsvd = 0;
20977 ret_ring->single.elem = buf + sizeof(dhd_ring_info_t);
20978 ret_ring->single.elem_size = elem_size;
20979 ret_ring->single.elem_cnt = elem_cnt;
20980 }
20981
20982 return ret_ring;
20983 }
20984
20985 void
20986 dhd_ring_deinit(dhd_pub_t *dhdp, void *_ring)
20987 {
20988 dhd_ring_info_t *ring = (dhd_ring_info_t *)_ring;
20989 if (!ring) {
20990 return;
20991 }
20992
20993 if (ring->magic != DHD_RING_MAGIC) {
20994 return;
20995 }
20996
20997 if (ring->type != DHD_RING_TYPE_FIXED &&
20998 ring->type != DHD_RING_TYPE_SINGLE_IDX) {
20999 return;
21000 }
21001
21002 DHD_RING_SYNC_LOCK_DEINIT(dhdp->osh, ring->ring_sync);
21003 ring->ring_sync = NULL;
21004 if (ring->type == DHD_RING_TYPE_FIXED) {
21005 dhd_fixed_ring_info_t *fixed = &ring->fixed;
21006 memset(fixed->elem, 0, fixed->elem_size * fixed->elem_cnt);
21007 fixed->elem_size = fixed->elem_cnt = 0;
21008 } else {
21009 dhd_singleidx_ring_info_t *single = &ring->single;
21010 memset(single->elem, 0, single->elem_size * single->elem_cnt);
21011 single->elem_size = single->elem_cnt = 0;
21012 }
21013 ring->type = 0;
21014 ring->magic = 0;
21015 }
21016
21017 static inline uint32
21018 __dhd_ring_ptr2idx(void *ring, void *ptr, char *sig, uint32 type)
21019 {
21020 uint32 diff;
21021 uint32 ret_idx = (uint32)DHD_RING_IDX_INVALID;
21022 uint32 elem_size, elem_cnt;
21023 void *elem;
21024
21025 if (type == DHD_RING_TYPE_FIXED) {
21026 dhd_fixed_ring_info_t *fixed = (dhd_fixed_ring_info_t *)ring;
21027 elem_size = fixed->elem_size;
21028 elem_cnt = fixed->elem_cnt;
21029 elem = fixed->elem;
21030 } else if (type == DHD_RING_TYPE_SINGLE_IDX) {
21031 dhd_singleidx_ring_info_t *single = (dhd_singleidx_ring_info_t *)ring;
21032 elem_size = single->elem_size;
21033 elem_cnt = single->elem_cnt;
21034 elem = single->elem;
21035 } else {
21036 DHD_RING_ERR(("UNSUPPORTED RING TYPE %d\n", type));
21037 return ret_idx;
21038 }
21039
21040 if (ptr < elem) {
21041 DHD_RING_ERR(("INVALID POINTER %s:%p, ring->elem:%p\n", sig, ptr, elem));
21042 return ret_idx;
21043 }
21044 diff = (uint32)((uint8 *)ptr - (uint8 *)elem);
21045 if (diff % elem_size != 0) {
21046 DHD_RING_ERR(("INVALID POINTER %s:%p, ring->elem:%p\n", sig, ptr, elem));
21047 return ret_idx;
21048 }
21049 ret_idx = diff / elem_size;
21050 if (ret_idx >= elem_cnt) {
21051 DHD_RING_ERR(("INVALID POINTER max:%d cur:%d\n", elem_cnt, ret_idx));
21052 }
21053 return ret_idx;
21054 }
21055
21056 /* Sub functions for fixed ring */
21057 /* get counts between two indexes of ring buffer (internal only) */
21058 static inline int
21059 __dhd_fixed_ring_get_count(dhd_fixed_ring_info_t *ring, int start, int end)
21060 {
21061 if (start == DHD_RING_IDX_INVALID || end == DHD_RING_IDX_INVALID) {
21062 return 0;
21063 }
21064
21065 return (ring->elem_cnt + end - start) % ring->elem_cnt + 1;
21066 }
21067
21068 static inline int
21069 __dhd_fixed_ring_get_cur_size(dhd_fixed_ring_info_t *ring)
21070 {
21071 return __dhd_fixed_ring_get_count(ring, ring->read_idx, ring->write_idx);
21072 }
21073
21074 static inline void *
21075 __dhd_fixed_ring_get_first(dhd_fixed_ring_info_t *ring)
21076 {
21077 if (ring->read_idx == DHD_RING_IDX_INVALID) {
21078 return NULL;
21079 }
21080 return (uint8 *)ring->elem + (ring->elem_size * ring->read_idx);
21081 }
21082
21083 static inline void
21084 __dhd_fixed_ring_free_first(dhd_fixed_ring_info_t *ring)
21085 {
21086 uint32 next_idx;
21087
21088 if (ring->read_idx == DHD_RING_IDX_INVALID) {
21089 DHD_RING_ERR(("EMPTY RING\n"));
21090 return;
21091 }
21092
21093 next_idx = (ring->read_idx + 1) % ring->elem_cnt;
21094 if (ring->read_idx == ring->write_idx) {
21095 /* Become empty */
21096 ring->read_idx = ring->write_idx = DHD_RING_IDX_INVALID;
21097 return;
21098 }
21099
21100 ring->read_idx = next_idx;
21101 return;
21102 }
21103
21104 static inline void *
21105 __dhd_fixed_ring_get_last(dhd_fixed_ring_info_t *ring)
21106 {
21107 if (ring->read_idx == DHD_RING_IDX_INVALID) {
21108 return NULL;
21109 }
21110 return (uint8 *)ring->elem + (ring->elem_size * ring->write_idx);
21111 }
21112
21113 static inline void *
21114 __dhd_fixed_ring_get_empty(dhd_fixed_ring_info_t *ring)
21115 {
21116 uint32 tmp_idx;
21117
21118 if (ring->read_idx == DHD_RING_IDX_INVALID) {
21119 ring->read_idx = ring->write_idx = 0;
21120 return (uint8 *)ring->elem;
21121 }
21122
21123 /* check next index is not locked */
21124 tmp_idx = (ring->write_idx + 1) % ring->elem_cnt;
21125 if (ring->lock_idx == tmp_idx) {
21126 return NULL;
21127 }
21128
21129 ring->write_idx = tmp_idx;
21130 if (ring->write_idx == ring->read_idx) {
21131 /* record is full, drop oldest one */
21132 ring->read_idx = (ring->read_idx + 1) % ring->elem_cnt;
21133
21134 }
21135 return (uint8 *)ring->elem + (ring->elem_size * ring->write_idx);
21136 }
21137
21138 static inline void *
21139 __dhd_fixed_ring_get_next(dhd_fixed_ring_info_t *ring, void *prev, uint32 type)
21140 {
21141 uint32 cur_idx;
21142
21143 if (ring->read_idx == DHD_RING_IDX_INVALID) {
21144 DHD_RING_ERR(("EMPTY RING\n"));
21145 return NULL;
21146 }
21147
21148 cur_idx = __dhd_ring_ptr2idx(ring, prev, "NEXT", type);
21149 if (cur_idx >= ring->elem_cnt) {
21150 return NULL;
21151 }
21152
21153 if (cur_idx == ring->write_idx) {
21154 /* no more new record */
21155 return NULL;
21156 }
21157
21158 cur_idx = (cur_idx + 1) % ring->elem_cnt;
21159 return (uint8 *)ring->elem + ring->elem_size * cur_idx;
21160 }
21161
21162 static inline void *
21163 __dhd_fixed_ring_get_prev(dhd_fixed_ring_info_t *ring, void *prev, uint32 type)
21164 {
21165 uint32 cur_idx;
21166
21167 if (ring->read_idx == DHD_RING_IDX_INVALID) {
21168 DHD_RING_ERR(("EMPTY RING\n"));
21169 return NULL;
21170 }
21171 cur_idx = __dhd_ring_ptr2idx(ring, prev, "PREV", type);
21172 if (cur_idx >= ring->elem_cnt) {
21173 return NULL;
21174 }
21175 if (cur_idx == ring->read_idx) {
21176 /* no more new record */
21177 return NULL;
21178 }
21179
21180 cur_idx = (cur_idx + ring->elem_cnt - 1) % ring->elem_cnt;
21181 return (uint8 *)ring->elem + ring->elem_size * cur_idx;
21182 }
21183
21184 static inline void
21185 __dhd_fixed_ring_lock(dhd_fixed_ring_info_t *ring, void *first_ptr, void *last_ptr, uint32 type)
21186 {
21187 uint32 first_idx;
21188 uint32 last_idx;
21189 uint32 ring_filled_cnt;
21190 uint32 tmp_cnt;
21191
21192 if (ring->read_idx == DHD_RING_IDX_INVALID) {
21193 DHD_RING_ERR(("EMPTY RING\n"));
21194 return;
21195 }
21196
21197 if (first_ptr) {
21198 first_idx = __dhd_ring_ptr2idx(ring, first_ptr, "LCK FIRST", type);
21199 if (first_idx >= ring->elem_cnt) {
21200 return;
21201 }
21202 } else {
21203 first_idx = ring->read_idx;
21204 }
21205
21206 if (last_ptr) {
21207 last_idx = __dhd_ring_ptr2idx(ring, last_ptr, "LCK LAST", type);
21208 if (last_idx >= ring->elem_cnt) {
21209 return;
21210 }
21211 } else {
21212 last_idx = ring->write_idx;
21213 }
21214
21215 ring_filled_cnt = __dhd_fixed_ring_get_count(ring, ring->read_idx, ring->write_idx);
21216 tmp_cnt = __dhd_fixed_ring_get_count(ring, ring->read_idx, first_idx);
21217 if (tmp_cnt > ring_filled_cnt) {
21218 DHD_RING_ERR(("LOCK FIRST IS TO EMPTY ELEM: write: %d read: %d cur:%d\n",
21219 ring->write_idx, ring->read_idx, first_idx));
21220 return;
21221 }
21222
21223 tmp_cnt = __dhd_fixed_ring_get_count(ring, ring->read_idx, last_idx);
21224 if (tmp_cnt > ring_filled_cnt) {
21225 DHD_RING_ERR(("LOCK LAST IS TO EMPTY ELEM: write: %d read: %d cur:%d\n",
21226 ring->write_idx, ring->read_idx, last_idx));
21227 return;
21228 }
21229
21230 ring->lock_idx = first_idx;
21231 ring->lock_count = __dhd_fixed_ring_get_count(ring, first_idx, last_idx);
21232 return;
21233 }
21234
21235 static inline void
21236 __dhd_fixed_ring_lock_free(dhd_fixed_ring_info_t *ring)
21237 {
21238 if (ring->read_idx == DHD_RING_IDX_INVALID) {
21239 DHD_RING_ERR(("EMPTY RING\n"));
21240 return;
21241 }
21242
21243 ring->lock_idx = DHD_RING_IDX_INVALID;
21244 ring->lock_count = 0;
21245 return;
21246 }
21247 static inline void *
21248 __dhd_fixed_ring_lock_get_first(dhd_fixed_ring_info_t *ring)
21249 {
21250 if (ring->read_idx == DHD_RING_IDX_INVALID) {
21251 DHD_RING_ERR(("EMPTY RING\n"));
21252 return NULL;
21253 }
21254 if (ring->lock_idx == DHD_RING_IDX_INVALID) {
21255 DHD_RING_ERR(("NO LOCK POINT\n"));
21256 return NULL;
21257 }
21258 return (uint8 *)ring->elem + ring->elem_size * ring->lock_idx;
21259 }
21260
21261 static inline void *
21262 __dhd_fixed_ring_lock_get_last(dhd_fixed_ring_info_t *ring)
21263 {
21264 int lock_last_idx;
21265 if (ring->read_idx == DHD_RING_IDX_INVALID) {
21266 DHD_RING_ERR(("EMPTY RING\n"));
21267 return NULL;
21268 }
21269 if (ring->lock_idx == DHD_RING_IDX_INVALID) {
21270 DHD_RING_ERR(("NO LOCK POINT\n"));
21271 return NULL;
21272 }
21273
21274 lock_last_idx = (ring->lock_idx + ring->lock_count - 1) % ring->elem_cnt;
21275 return (uint8 *)ring->elem + ring->elem_size * lock_last_idx;
21276 }
21277
21278 static inline int
21279 __dhd_fixed_ring_lock_get_count(dhd_fixed_ring_info_t *ring)
21280 {
21281 if (ring->read_idx == DHD_RING_IDX_INVALID) {
21282 DHD_RING_ERR(("EMPTY RING\n"));
21283 return BCME_ERROR;
21284 }
21285 if (ring->lock_idx == DHD_RING_IDX_INVALID) {
21286 DHD_RING_ERR(("NO LOCK POINT\n"));
21287 return BCME_ERROR;
21288 }
21289 return ring->lock_count;
21290 }
21291
21292 static inline void
21293 __dhd_fixed_ring_lock_free_first(dhd_fixed_ring_info_t *ring)
21294 {
21295 if (ring->read_idx == DHD_RING_IDX_INVALID) {
21296 DHD_RING_ERR(("EMPTY RING\n"));
21297 return;
21298 }
21299 if (ring->lock_idx == DHD_RING_IDX_INVALID) {
21300 DHD_RING_ERR(("NO LOCK POINT\n"));
21301 return;
21302 }
21303
21304 ring->lock_count--;
21305 if (ring->lock_count <= 0) {
21306 ring->lock_idx = DHD_RING_IDX_INVALID;
21307 } else {
21308 ring->lock_idx = (ring->lock_idx + 1) % ring->elem_cnt;
21309 }
21310 return;
21311 }
21312
21313 static inline void
21314 __dhd_fixed_ring_set_read_idx(dhd_fixed_ring_info_t *ring, uint32 idx)
21315 {
21316 ring->read_idx = idx;
21317 }
21318
21319 static inline void
21320 __dhd_fixed_ring_set_write_idx(dhd_fixed_ring_info_t *ring, uint32 idx)
21321 {
21322 ring->write_idx = idx;
21323 }
21324
21325 static inline uint32
21326 __dhd_fixed_ring_get_read_idx(dhd_fixed_ring_info_t *ring)
21327 {
21328 return ring->read_idx;
21329 }
21330
21331 static inline uint32
21332 __dhd_fixed_ring_get_write_idx(dhd_fixed_ring_info_t *ring)
21333 {
21334 return ring->write_idx;
21335 }
21336
21337 /* Sub functions for single index ring */
21338 static inline void *
21339 __dhd_singleidx_ring_get_first(dhd_singleidx_ring_info_t *ring)
21340 {
21341 uint32 tmp_idx = 0;
21342
21343 if (ring->idx == DHD_RING_IDX_INVALID) {
21344 return NULL;
21345 }
21346
21347 if (ring->ring_overwrited) {
21348 tmp_idx = (ring->idx + 1) % ring->elem_cnt;
21349 }
21350
21351 return (uint8 *)ring->elem + (ring->elem_size * tmp_idx);
21352 }
21353
21354 static inline void *
21355 __dhd_singleidx_ring_get_last(dhd_singleidx_ring_info_t *ring)
21356 {
21357 if (ring->idx == DHD_RING_IDX_INVALID) {
21358 return NULL;
21359 }
21360
21361 return (uint8 *)ring->elem + (ring->elem_size * ring->idx);
21362 }
21363
21364 static inline void *
21365 __dhd_singleidx_ring_get_empty(dhd_singleidx_ring_info_t *ring)
21366 {
21367 if (ring->idx == DHD_RING_IDX_INVALID) {
21368 ring->idx = 0;
21369 return (uint8 *)ring->elem;
21370 }
21371
21372 /* check the lock is held */
21373 if (atomic_read(&ring->ring_locked)) {
21374 return NULL;
21375 }
21376
21377 /* check the index rollover */
21378 if (!ring->ring_overwrited && ring->idx == (ring->elem_cnt - 1)) {
21379 ring->ring_overwrited = 1;
21380 }
21381
21382 ring->idx = (ring->idx + 1) % ring->elem_cnt;
21383
21384 return (uint8 *)ring->elem + (ring->elem_size * ring->idx);
21385 }
21386
21387 static inline void *
21388 __dhd_singleidx_ring_get_next(dhd_singleidx_ring_info_t *ring, void *prev, uint32 type)
21389 {
21390 uint32 cur_idx;
21391
21392 if (ring->idx == DHD_RING_IDX_INVALID) {
21393 DHD_RING_ERR(("EMPTY RING\n"));
21394 return NULL;
21395 }
21396
21397 cur_idx = __dhd_ring_ptr2idx(ring, prev, "NEXT", type);
21398 if (cur_idx >= ring->elem_cnt) {
21399 return NULL;
21400 }
21401
21402 if (cur_idx == ring->idx) {
21403 /* no more new record */
21404 return NULL;
21405 }
21406
21407 cur_idx = (cur_idx + 1) % ring->elem_cnt;
21408
21409 return (uint8 *)ring->elem + ring->elem_size * cur_idx;
21410 }
21411
21412 static inline void *
21413 __dhd_singleidx_ring_get_prev(dhd_singleidx_ring_info_t *ring, void *prev, uint32 type)
21414 {
21415 uint32 cur_idx;
21416
21417 if (ring->idx == DHD_RING_IDX_INVALID) {
21418 DHD_RING_ERR(("EMPTY RING\n"));
21419 return NULL;
21420 }
21421 cur_idx = __dhd_ring_ptr2idx(ring, prev, "PREV", type);
21422 if (cur_idx >= ring->elem_cnt) {
21423 return NULL;
21424 }
21425
21426 if (!ring->ring_overwrited && cur_idx == 0) {
21427 /* no more new record */
21428 return NULL;
21429 }
21430
21431 cur_idx = (cur_idx + ring->elem_cnt - 1) % ring->elem_cnt;
21432 if (ring->ring_overwrited && cur_idx == ring->idx) {
21433 /* no more new record */
21434 return NULL;
21435 }
21436
21437 return (uint8 *)ring->elem + ring->elem_size * cur_idx;
21438 }
21439
21440 static inline void
21441 __dhd_singleidx_ring_whole_lock(dhd_singleidx_ring_info_t *ring)
21442 {
21443 if (!atomic_read(&ring->ring_locked)) {
21444 atomic_set(&ring->ring_locked, 1);
21445 }
21446 }
21447
21448 static inline void
21449 __dhd_singleidx_ring_whole_unlock(dhd_singleidx_ring_info_t *ring)
21450 {
21451 if (atomic_read(&ring->ring_locked)) {
21452 atomic_set(&ring->ring_locked, 0);
21453 }
21454 }
21455
21456 /* Get first element : oldest element */
21457 void *
21458 dhd_ring_get_first(void *_ring)
21459 {
21460 dhd_ring_info_t *ring = (dhd_ring_info_t *)_ring;
21461 void *ret = NULL;
21462 unsigned long flags;
21463
21464 if (!ring || ring->magic != DHD_RING_MAGIC) {
21465 DHD_RING_ERR(("%s :INVALID RING INFO\n", __FUNCTION__));
21466 return NULL;
21467 }
21468
21469 DHD_RING_SYNC_LOCK(ring->ring_sync, flags);
21470 if (ring->type == DHD_RING_TYPE_FIXED) {
21471 ret = __dhd_fixed_ring_get_first(&ring->fixed);
21472 }
21473 if (ring->type == DHD_RING_TYPE_SINGLE_IDX) {
21474 ret = __dhd_singleidx_ring_get_first(&ring->single);
21475 }
21476 DHD_RING_SYNC_UNLOCK(ring->ring_sync, flags);
21477 return ret;
21478 }
21479
21480 /* Free first element : oldest element */
21481 void
21482 dhd_ring_free_first(void *_ring)
21483 {
21484 dhd_ring_info_t *ring = (dhd_ring_info_t *)_ring;
21485 unsigned long flags;
21486
21487 if (!ring || ring->magic != DHD_RING_MAGIC) {
21488 DHD_RING_ERR(("%s :INVALID RING INFO\n", __FUNCTION__));
21489 return;
21490 }
21491
21492 DHD_RING_SYNC_LOCK(ring->ring_sync, flags);
21493 if (ring->type == DHD_RING_TYPE_FIXED) {
21494 __dhd_fixed_ring_free_first(&ring->fixed);
21495 }
21496 DHD_RING_SYNC_UNLOCK(ring->ring_sync, flags);
21497 }
21498
21499 void
21500 dhd_ring_set_read_idx(void *_ring, uint32 read_idx)
21501 {
21502 dhd_ring_info_t *ring = (dhd_ring_info_t *)_ring;
21503 unsigned long flags;
21504
21505 if (!ring || ring->magic != DHD_RING_MAGIC) {
21506 DHD_RING_ERR(("%s :INVALID RING INFO\n", __FUNCTION__));
21507 return;
21508 }
21509
21510 DHD_RING_SYNC_LOCK(ring->ring_sync, flags);
21511 if (ring->type == DHD_RING_TYPE_FIXED) {
21512 __dhd_fixed_ring_set_read_idx(&ring->fixed, read_idx);
21513 }
21514 DHD_RING_SYNC_UNLOCK(ring->ring_sync, flags);
21515 }
21516
21517 void
21518 dhd_ring_set_write_idx(void *_ring, uint32 write_idx)
21519 {
21520 dhd_ring_info_t *ring = (dhd_ring_info_t *)_ring;
21521 unsigned long flags;
21522
21523 if (!ring || ring->magic != DHD_RING_MAGIC) {
21524 DHD_RING_ERR(("%s :INVALID RING INFO\n", __FUNCTION__));
21525 return;
21526 }
21527
21528 DHD_RING_SYNC_LOCK(ring->ring_sync, flags);
21529 if (ring->type == DHD_RING_TYPE_FIXED) {
21530 __dhd_fixed_ring_set_write_idx(&ring->fixed, write_idx);
21531 }
21532 DHD_RING_SYNC_UNLOCK(ring->ring_sync, flags);
21533 }
21534
21535 uint32
21536 dhd_ring_get_read_idx(void *_ring)
21537 {
21538 dhd_ring_info_t *ring = (dhd_ring_info_t *)_ring;
21539 uint32 read_idx = DHD_RING_IDX_INVALID;
21540 unsigned long flags;
21541
21542 if (!ring || ring->magic != DHD_RING_MAGIC) {
21543 DHD_RING_ERR(("%s :INVALID RING INFO\n", __FUNCTION__));
21544 return read_idx;
21545 }
21546
21547 DHD_RING_SYNC_LOCK(ring->ring_sync, flags);
21548 if (ring->type == DHD_RING_TYPE_FIXED) {
21549 read_idx = __dhd_fixed_ring_get_read_idx(&ring->fixed);
21550 }
21551 DHD_RING_SYNC_UNLOCK(ring->ring_sync, flags);
21552
21553 return read_idx;
21554 }
21555
21556 uint32
21557 dhd_ring_get_write_idx(void *_ring)
21558 {
21559 dhd_ring_info_t *ring = (dhd_ring_info_t *)_ring;
21560 uint32 write_idx = DHD_RING_IDX_INVALID;
21561 unsigned long flags;
21562
21563 if (!ring || ring->magic != DHD_RING_MAGIC) {
21564 DHD_RING_ERR(("%s :INVALID RING INFO\n", __FUNCTION__));
21565 return write_idx;
21566 }
21567
21568 DHD_RING_SYNC_LOCK(ring->ring_sync, flags);
21569 if (ring->type == DHD_RING_TYPE_FIXED) {
21570 write_idx = __dhd_fixed_ring_get_write_idx(&ring->fixed);
21571 }
21572 DHD_RING_SYNC_UNLOCK(ring->ring_sync, flags);
21573
21574 return write_idx;
21575 }
21576
21577 /* Get latest element */
21578 void *
21579 dhd_ring_get_last(void *_ring)
21580 {
21581 dhd_ring_info_t *ring = (dhd_ring_info_t *)_ring;
21582 void *ret = NULL;
21583 unsigned long flags;
21584
21585 if (!ring || ring->magic != DHD_RING_MAGIC) {
21586 DHD_RING_ERR(("%s :INVALID RING INFO\n", __FUNCTION__));
21587 return NULL;
21588 }
21589
21590 DHD_RING_SYNC_LOCK(ring->ring_sync, flags);
21591 if (ring->type == DHD_RING_TYPE_FIXED) {
21592 ret = __dhd_fixed_ring_get_last(&ring->fixed);
21593 }
21594 if (ring->type == DHD_RING_TYPE_SINGLE_IDX) {
21595 ret = __dhd_singleidx_ring_get_last(&ring->single);
21596 }
21597 DHD_RING_SYNC_UNLOCK(ring->ring_sync, flags);
21598 return ret;
21599 }
21600
21601 /* Get next point can be written
21602 * will overwrite which doesn't read
21603 * will return NULL if next pointer is locked
21604 */
21605 void *
21606 dhd_ring_get_empty(void *_ring)
21607 {
21608 dhd_ring_info_t *ring = (dhd_ring_info_t *)_ring;
21609 void *ret = NULL;
21610 unsigned long flags;
21611
21612 if (!ring || ring->magic != DHD_RING_MAGIC) {
21613 DHD_RING_ERR(("%s :INVALID RING INFO\n", __FUNCTION__));
21614 return NULL;
21615 }
21616
21617 DHD_RING_SYNC_LOCK(ring->ring_sync, flags);
21618 if (ring->type == DHD_RING_TYPE_FIXED) {
21619 ret = __dhd_fixed_ring_get_empty(&ring->fixed);
21620 }
21621 if (ring->type == DHD_RING_TYPE_SINGLE_IDX) {
21622 ret = __dhd_singleidx_ring_get_empty(&ring->single);
21623 }
21624 DHD_RING_SYNC_UNLOCK(ring->ring_sync, flags);
21625 return ret;
21626 }
21627
21628 void *
21629 dhd_ring_get_next(void *_ring, void *cur)
21630 {
21631 dhd_ring_info_t *ring = (dhd_ring_info_t *)_ring;
21632 void *ret = NULL;
21633 unsigned long flags;
21634
21635 if (!ring || ring->magic != DHD_RING_MAGIC) {
21636 DHD_RING_ERR(("%s :INVALID RING INFO\n", __FUNCTION__));
21637 return NULL;
21638 }
21639
21640 DHD_RING_SYNC_LOCK(ring->ring_sync, flags);
21641 if (ring->type == DHD_RING_TYPE_FIXED) {
21642 ret = __dhd_fixed_ring_get_next(&ring->fixed, cur, ring->type);
21643 }
21644 if (ring->type == DHD_RING_TYPE_SINGLE_IDX) {
21645 ret = __dhd_singleidx_ring_get_next(&ring->single, cur, ring->type);
21646 }
21647 DHD_RING_SYNC_UNLOCK(ring->ring_sync, flags);
21648 return ret;
21649 }
21650
21651 void *
21652 dhd_ring_get_prev(void *_ring, void *cur)
21653 {
21654 dhd_ring_info_t *ring = (dhd_ring_info_t *)_ring;
21655 void *ret = NULL;
21656 unsigned long flags;
21657
21658 if (!ring || ring->magic != DHD_RING_MAGIC) {
21659 DHD_RING_ERR(("%s :INVALID RING INFO\n", __FUNCTION__));
21660 return NULL;
21661 }
21662
21663 DHD_RING_SYNC_LOCK(ring->ring_sync, flags);
21664 if (ring->type == DHD_RING_TYPE_FIXED) {
21665 ret = __dhd_fixed_ring_get_prev(&ring->fixed, cur, ring->type);
21666 }
21667 if (ring->type == DHD_RING_TYPE_SINGLE_IDX) {
21668 ret = __dhd_singleidx_ring_get_prev(&ring->single, cur, ring->type);
21669 }
21670 DHD_RING_SYNC_UNLOCK(ring->ring_sync, flags);
21671 return ret;
21672 }
21673
21674 int
21675 dhd_ring_get_cur_size(void *_ring)
21676 {
21677 dhd_ring_info_t *ring = (dhd_ring_info_t *)_ring;
21678 int cnt = 0;
21679 unsigned long flags;
21680
21681 if (!ring || ring->magic != DHD_RING_MAGIC) {
21682 DHD_RING_ERR(("%s :INVALID RING INFO\n", __FUNCTION__));
21683 return cnt;
21684 }
21685
21686 DHD_RING_SYNC_LOCK(ring->ring_sync, flags);
21687 if (ring->type == DHD_RING_TYPE_FIXED) {
21688 cnt = __dhd_fixed_ring_get_cur_size(&ring->fixed);
21689 }
21690 DHD_RING_SYNC_UNLOCK(ring->ring_sync, flags);
21691 return cnt;
21692 }
21693
21694 /* protect element between lock_ptr and write_idx */
21695 void
21696 dhd_ring_lock(void *_ring, void *first_ptr, void *last_ptr)
21697 {
21698 dhd_ring_info_t *ring = (dhd_ring_info_t *)_ring;
21699 unsigned long flags;
21700
21701 if (!ring || ring->magic != DHD_RING_MAGIC) {
21702 DHD_RING_ERR(("%s :INVALID RING INFO\n", __FUNCTION__));
21703 return;
21704 }
21705
21706 DHD_RING_SYNC_LOCK(ring->ring_sync, flags);
21707 if (ring->type == DHD_RING_TYPE_FIXED) {
21708 __dhd_fixed_ring_lock(&ring->fixed, first_ptr, last_ptr, ring->type);
21709 }
21710 DHD_RING_SYNC_UNLOCK(ring->ring_sync, flags);
21711 }
21712
21713 /* free all lock */
21714 void
21715 dhd_ring_lock_free(void *_ring)
21716 {
21717 dhd_ring_info_t *ring = (dhd_ring_info_t *)_ring;
21718 unsigned long flags;
21719
21720 if (!ring || ring->magic != DHD_RING_MAGIC) {
21721 DHD_RING_ERR(("%s :INVALID RING INFO\n", __FUNCTION__));
21722 return;
21723 }
21724
21725 DHD_RING_SYNC_LOCK(ring->ring_sync, flags);
21726 if (ring->type == DHD_RING_TYPE_FIXED) {
21727 __dhd_fixed_ring_lock_free(&ring->fixed);
21728 }
21729 DHD_RING_SYNC_UNLOCK(ring->ring_sync, flags);
21730 }
21731
21732 void *
21733 dhd_ring_lock_get_first(void *_ring)
21734 {
21735 dhd_ring_info_t *ring = (dhd_ring_info_t *)_ring;
21736 void *ret = NULL;
21737 unsigned long flags;
21738
21739 if (!ring || ring->magic != DHD_RING_MAGIC) {
21740 DHD_RING_ERR(("%s :INVALID RING INFO\n", __FUNCTION__));
21741 return NULL;
21742 }
21743
21744 DHD_RING_SYNC_LOCK(ring->ring_sync, flags);
21745 if (ring->type == DHD_RING_TYPE_FIXED) {
21746 ret = __dhd_fixed_ring_lock_get_first(&ring->fixed);
21747 }
21748 DHD_RING_SYNC_UNLOCK(ring->ring_sync, flags);
21749 return ret;
21750 }
21751
21752 void *
21753 dhd_ring_lock_get_last(void *_ring)
21754 {
21755 dhd_ring_info_t *ring = (dhd_ring_info_t *)_ring;
21756 void *ret = NULL;
21757 unsigned long flags;
21758
21759 if (!ring || ring->magic != DHD_RING_MAGIC) {
21760 DHD_RING_ERR(("%s :INVALID RING INFO\n", __FUNCTION__));
21761 return NULL;
21762 }
21763
21764 DHD_RING_SYNC_LOCK(ring->ring_sync, flags);
21765 if (ring->type == DHD_RING_TYPE_FIXED) {
21766 ret = __dhd_fixed_ring_lock_get_last(&ring->fixed);
21767 }
21768 DHD_RING_SYNC_UNLOCK(ring->ring_sync, flags);
21769 return ret;
21770 }
21771
21772 int
21773 dhd_ring_lock_get_count(void *_ring)
21774 {
21775 dhd_ring_info_t *ring = (dhd_ring_info_t *)_ring;
21776 int ret = BCME_ERROR;
21777 unsigned long flags;
21778
21779 if (!ring || ring->magic != DHD_RING_MAGIC) {
21780 DHD_RING_ERR(("%s :INVALID RING INFO\n", __FUNCTION__));
21781 return ret;
21782 }
21783
21784 DHD_RING_SYNC_LOCK(ring->ring_sync, flags);
21785 if (ring->type == DHD_RING_TYPE_FIXED) {
21786 ret = __dhd_fixed_ring_lock_get_count(&ring->fixed);
21787 }
21788 DHD_RING_SYNC_UNLOCK(ring->ring_sync, flags);
21789 return ret;
21790 }
21791
21792 /* free first locked element */
21793 void
21794 dhd_ring_lock_free_first(void *_ring)
21795 {
21796 dhd_ring_info_t *ring = (dhd_ring_info_t *)_ring;
21797 unsigned long flags;
21798
21799 if (!ring || ring->magic != DHD_RING_MAGIC) {
21800 DHD_RING_ERR(("%s :INVALID RING INFO\n", __FUNCTION__));
21801 return;
21802 }
21803
21804 DHD_RING_SYNC_LOCK(ring->ring_sync, flags);
21805 if (ring->type == DHD_RING_TYPE_FIXED) {
21806 __dhd_fixed_ring_lock_free_first(&ring->fixed);
21807 }
21808 DHD_RING_SYNC_UNLOCK(ring->ring_sync, flags);
21809 }
21810
21811 void
21812 dhd_ring_whole_lock(void *_ring)
21813 {
21814 dhd_ring_info_t *ring = (dhd_ring_info_t *)_ring;
21815 unsigned long flags;
21816
21817 if (!ring || ring->magic != DHD_RING_MAGIC) {
21818 DHD_RING_ERR(("%s :INVALID RING INFO\n", __FUNCTION__));
21819 return;
21820 }
21821
21822 DHD_RING_SYNC_LOCK(ring->ring_sync, flags);
21823 if (ring->type == DHD_RING_TYPE_SINGLE_IDX) {
21824 __dhd_singleidx_ring_whole_lock(&ring->single);
21825 }
21826 DHD_RING_SYNC_UNLOCK(ring->ring_sync, flags);
21827 }
21828
21829 void
21830 dhd_ring_whole_unlock(void *_ring)
21831 {
21832 dhd_ring_info_t *ring = (dhd_ring_info_t *)_ring;
21833 unsigned long flags;
21834
21835 if (!ring || ring->magic != DHD_RING_MAGIC) {
21836 DHD_RING_ERR(("%s :INVALID RING INFO\n", __FUNCTION__));
21837 return;
21838 }
21839
21840 DHD_RING_SYNC_LOCK(ring->ring_sync, flags);
21841 if (ring->type == DHD_RING_TYPE_SINGLE_IDX) {
21842 __dhd_singleidx_ring_whole_unlock(&ring->single);
21843 }
21844 DHD_RING_SYNC_UNLOCK(ring->ring_sync, flags);
21845 }
21846
21847 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0))
21848 #define DHD_VFS_INODE(dir) (dir->d_inode)
21849 #else
21850 #define DHD_VFS_INODE(dir) d_inode(dir)
21851 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0) */
21852
21853 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 13, 0))
21854 #define DHD_VFS_UNLINK(dir, b, c) vfs_unlink(DHD_VFS_INODE(dir), b)
21855 #else
21856 #define DHD_VFS_UNLINK(dir, b, c) vfs_unlink(DHD_VFS_INODE(dir), b, c)
21857 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3, 13, 0) */
21858 int
21859 dhd_file_delete(char *path)
21860 {
21861 struct path file_path;
21862 int err;
21863 struct dentry *dir;
21864
21865 err = kern_path(path, 0, &file_path);
21866
21867 if (err < 0) {
21868 DHD_ERROR(("Failed to get kern-path delete file: %s error: %d\n", path, err));
21869 return err;
21870 }
21871 if (
21872 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
21873 !d_is_file(file_path.dentry) ||
21874 #if (LINUX_VERSION_CODE > KERNEL_VERSION(4, 1, 0))
21875 d_really_is_negative(file_path.dentry) ||
21876 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(4, 1, 0) */
21877 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0) */
21878 FALSE)
21879 {
21880 err = -EINVAL;
21881 } else {
21882 dir = dget_parent(file_path.dentry);
21883
21884 if (!IS_ERR(dir)) {
21885 err = DHD_VFS_UNLINK(dir, file_path.dentry, NULL);
21886 dput(dir);
21887 } else {
21888 err = PTR_ERR(dir);
21889 }
21890 }
21891
21892 path_put(&file_path);
21893
21894 if (err < 0) {
21895 DHD_ERROR(("Failed to delete file: %s error: %d\n", path, err));
21896 }
21897
21898 return err;
21899 }
21900 #ifdef DHD_DUMP_MNGR
21901 static int
21902 dhd_dump_file_manage_idx(dhd_dump_file_manage_t *fm_ptr, char *fname)
21903 {
21904 int i;
21905 int fm_idx = -1;
21906
21907 for (i = 0; i < DHD_DUMP_TYPE_COUNT_MAX; i++) {
21908 if (strlen(fm_ptr->elems[i].type_name) == 0) {
21909 fm_idx = i;
21910 break;
21911 }
21912 if (!(strncmp(fname, fm_ptr->elems[i].type_name, strlen(fname)))) {
21913 fm_idx = i;
21914 break;
21915 }
21916 }
21917
21918 if (fm_idx == -1) {
21919 return fm_idx;
21920 }
21921
21922 if (strlen(fm_ptr->elems[fm_idx].type_name) == 0) {
21923 strncpy(fm_ptr->elems[fm_idx].type_name, fname, DHD_DUMP_TYPE_NAME_SIZE);
21924 fm_ptr->elems[fm_idx].type_name[DHD_DUMP_TYPE_NAME_SIZE - 1] = '\0';
21925 fm_ptr->elems[fm_idx].file_idx = 0;
21926 }
21927
21928 return fm_idx;
21929 }
21930
21931 /*
21932 * dhd_dump_file_manage_enqueue - enqueue dump file path
21933 * and delete odest file if file count is max.
21934 */
21935 void
21936 dhd_dump_file_manage_enqueue(dhd_pub_t *dhd, char *dump_path, char *fname)
21937 {
21938 int fm_idx;
21939 int fp_idx;
21940 dhd_dump_file_manage_t *fm_ptr;
21941 DFM_elem_t *elem;
21942
21943 if (!dhd || !dhd->dump_file_manage) {
21944 DHD_ERROR(("%s(): dhdp=%p dump_file_manage=%p\n",
21945 __FUNCTION__, dhd, (dhd ? dhd->dump_file_manage : NULL)));
21946 return;
21947 }
21948
21949 fm_ptr = dhd->dump_file_manage;
21950
21951 /* find file_manage idx */
21952 DHD_INFO(("%s(): fname: %s dump_path: %s\n", __FUNCTION__, fname, dump_path));
21953 if ((fm_idx = dhd_dump_file_manage_idx(fm_ptr, fname)) < 0) {
21954 DHD_ERROR(("%s(): Out of file manager entries, fname: %s\n",
21955 __FUNCTION__, fname));
21956 return;
21957 }
21958
21959 elem = &fm_ptr->elems[fm_idx];
21960 fp_idx = elem->file_idx;
21961 DHD_INFO(("%s(): fm_idx: %d fp_idx: %d path: %s\n",
21962 __FUNCTION__, fm_idx, fp_idx, elem->file_path[fp_idx]));
21963
21964 /* delete oldest file */
21965 if (strlen(elem->file_path[fp_idx]) != 0) {
21966 if (dhd_file_delete(elem->file_path[fp_idx]) < 0) {
21967 DHD_ERROR(("%s(): Failed to delete file: %s\n",
21968 __FUNCTION__, elem->file_path[fp_idx]));
21969 } else {
21970 DHD_ERROR(("%s(): Successed to delete file: %s\n",
21971 __FUNCTION__, elem->file_path[fp_idx]));
21972 }
21973 }
21974
21975 /* save dump file path */
21976 strncpy(elem->file_path[fp_idx], dump_path, DHD_DUMP_FILE_PATH_SIZE);
21977 elem->file_path[fp_idx][DHD_DUMP_FILE_PATH_SIZE - 1] = '\0';
21978
21979 /* change file index to next file index */
21980 elem->file_idx = (elem->file_idx + 1) % DHD_DUMP_FILE_COUNT_MAX;
21981 }
21982 #endif /* DHD_DUMP_MNGR */
21983
21984 #ifdef DHD_MAP_LOGGING
21985 /* Will be called from SMMU fault handler */
21986 void
21987 dhd_smmu_fault_handler(uint32 axid, ulong fault_addr)
21988 {
21989 dhd_pub_t *dhdp = (dhd_pub_t *)g_dhd_pub;
21990 uint32 irq = (uint32)-1;
21991
21992 DHD_ERROR(("%s: Trigger SMMU Fault\n", __FUNCTION__));
21993 DHD_ERROR(("%s: axid:0x%x, fault_addr:0x%lx", __FUNCTION__, axid, fault_addr));
21994 dhdp->smmu_fault_occurred = TRUE;
21995 #ifdef DNGL_AXI_ERROR_LOGGING
21996 dhdp->axi_error = TRUE;
21997 dhdp->axi_err_dump->axid = axid;
21998 dhdp->axi_err_dump->fault_address = fault_addr;
21999 #endif /* DNGL_AXI_ERROR_LOGGING */
22000
22001 /* Disable PCIe IRQ */
22002 dhdpcie_get_pcieirq(dhdp->bus, &irq);
22003 if (irq != (uint32)-1) {
22004 disable_irq_nosync(irq);
22005 }
22006
22007 /* Take debug information first */
22008 DHD_OS_WAKE_LOCK(dhdp);
22009 dhd_prot_smmu_fault_dump(dhdp);
22010 DHD_OS_WAKE_UNLOCK(dhdp);
22011
22012 /* Take AXI information if possible */
22013 #ifdef DNGL_AXI_ERROR_LOGGING
22014 #ifdef DHD_USE_WQ_FOR_DNGL_AXI_ERROR
22015 dhd_axi_error_dispatch(dhdp);
22016 #else
22017 dhd_axi_error(dhdp);
22018 #endif /* DHD_USE_WQ_FOR_DNGL_AXI_ERROR */
22019 #endif /* DNGL_AXI_ERROR_LOGGING */
22020 }
22021 EXPORT_SYMBOL(dhd_smmu_fault_handler);
22022 #endif /* DHD_MAP_LOGGING */
22023
22024 #ifdef DHD_WIFI_SHUTDOWN
22025 void wifi_plat_dev_drv_shutdown(struct platform_device *pdev)
22026 {
22027 dhd_pub_t *dhd_pub = NULL;
22028 dhd_info_t *dhd_info = NULL;
22029 dhd_if_t *dhd_if = NULL;
22030
22031 DHD_ERROR(("%s enter\n", __FUNCTION__));
22032 dhd_pub = g_dhd_pub;
22033
22034 if (dhd_os_check_if_up(dhd_pub)) {
22035 dhd_info = (dhd_info_t *)dhd_pub->info;
22036 dhd_if = dhd_info->iflist[0];
22037 ASSERT(dhd_if);
22038 ASSERT(dhd_if->net);
22039 if (dhd_if && dhd_if->net) {
22040 dhd_stop(dhd_if->net);
22041 }
22042 }
22043 }
22044 #endif /* DHD_WIFI_SHUTDOWN */
22045
22046 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0))
22047 int
22048 compat_kernel_read(struct file *file, loff_t offset, char *addr, unsigned long count)
22049 {
22050 return (int)kernel_read(file, addr, (size_t)count, &offset);
22051 }
22052 int
22053 compat_vfs_write(struct file *file, char *addr, int count, loff_t *offset)
22054 {
22055 return (int)kernel_write(file, addr, count, offset);
22056 }
22057 #else
22058 int
22059 compat_kernel_read(struct file *file, loff_t offset, char *addr, unsigned long count)
22060 {
22061 return kernel_read(file, offset, addr, count);
22062 }
22063 int
22064 compat_vfs_write(struct file *file, char *addr, int count, loff_t *offset)
22065 {
22066 return (int)vfs_write(file, addr, count, offset);
22067 }
22068 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)) */
22069
22070 #ifdef DHDTCPSYNC_FLOOD_BLK
22071 static void dhd_blk_tsfl_handler(struct work_struct * work)
22072 {
22073 dhd_if_t *ifp = NULL;
22074 dhd_pub_t *dhdp = NULL;
22075 /* Ignore compiler warnings due to -Werror=cast-qual */
22076 #if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
22077 #pragma GCC diagnostic push
22078 #pragma GCC diagnostic ignored "-Wcast-qual"
22079 #endif /* STRICT_GCC_WARNINGS && __GNUC__ */
22080 ifp = container_of(work, dhd_if_t, blk_tsfl_work);
22081 #if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
22082 #pragma GCC diagnostic pop
22083 #endif /* STRICT_GCC_WARNINGS && __GNUC__ */
22084 if (ifp) {
22085 dhdp = &ifp->info->pub;
22086 if (dhdp) {
22087 if ((dhdp->op_mode & DHD_FLAG_P2P_GO_MODE)||
22088 (dhdp->op_mode & DHD_FLAG_HOSTAP_MODE)) {
22089 DHD_ERROR(("Disassoc due to TCP SYNC FLOOD ATTACK\n"));
22090 wl_cfg80211_del_all_sta(ifp->net, WLAN_REASON_UNSPECIFIED);
22091 } else if ((dhdp->op_mode & DHD_FLAG_P2P_GC_MODE)||
22092 (dhdp->op_mode & DHD_FLAG_STA_MODE)) {
22093 DHD_ERROR(("Diconnect due to TCP SYNC FLOOD ATTACK\n"));
22094 wl_cfg80211_disassoc(ifp->net, WLAN_REASON_UNSPECIFIED);
22095 }
22096 }
22097 }
22098 }
22099 void dhd_reset_tcpsync_info_by_ifp(dhd_if_t *ifp)
22100 {
22101 ifp->tsync_rcvd = 0;
22102 ifp->tsyncack_txed = 0;
22103 ifp->last_sync = DIV_U64_BY_U32(OSL_LOCALTIME_NS(), NSEC_PER_SEC);
22104 }
22105 void dhd_reset_tcpsync_info_by_dev(struct net_device *dev)
22106 {
22107 dhd_if_t *ifp = NULL;
22108 if (dev) {
22109 ifp = DHD_DEV_IFP(dev);
22110 }
22111 if (ifp) {
22112 ifp->tsync_rcvd = 0;
22113 ifp->tsyncack_txed = 0;
22114 ifp->last_sync = DIV_U64_BY_U32(OSL_LOCALTIME_NS(), NSEC_PER_SEC);
22115 }
22116 }
22117 #endif /* DHDTCPSYNC_FLOOD_BLK */
22118
22119 #ifdef DHD_4WAYM4_FAIL_DISCONNECT
22120 static void dhd_m4_state_handler(struct work_struct *work)
22121 {
22122 dhd_if_t *ifp = NULL;
22123 /* Ignore compiler warnings due to -Werror=cast-qual */
22124 #if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
22125 #pragma GCC diagnostic push
22126 #pragma GCC diagnostic ignored "-Wcast-qual"
22127 #endif // endif
22128 struct delayed_work *dw = to_delayed_work(work);
22129 ifp = container_of(dw, dhd_if_t, m4state_work);
22130 #if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
22131 #pragma GCC diagnostic pop
22132 #endif // endif
22133
22134 if (ifp && ifp->net &&
22135 (OSL_ATOMIC_READ(ifp->info->pub->osh, &ifp->m4state) == M4_TXFAILED)) {
22136 DHD_ERROR(("Disassoc for 4WAY_HANDSHAKE_TIMEOUT at %s\n",
22137 ifp->net->name));
22138 wl_cfg80211_disassoc(ifp->net, WLAN_REASON_4WAY_HANDSHAKE_TIMEOUT);
22139 }
22140 }
22141
22142 void
22143 dhd_eap_txcomplete(dhd_pub_t *dhdp, void *txp, bool success, int ifidx)
22144 {
22145 dhd_info_t *dhd = (dhd_info_t *)(dhdp->info);
22146 struct ether_header *eh;
22147 uint16 type;
22148
22149 if (!success) {
22150 dhd_prot_hdrpull(dhdp, NULL, txp, NULL, NULL);
22151
22152 eh = (struct ether_header *)PKTDATA(dhdp->osh, txp);
22153 type = ntoh16(eh->ether_type);
22154 if (type == ETHER_TYPE_802_1X) {
22155 if (dhd_is_4way_msg((uint8 *)eh) == EAPOL_4WAY_M4) {
22156 dhd_if_t *ifp = NULL;
22157 ifp = dhd->iflist[ifidx];
22158 if (!ifp || !ifp->net) {
22159 return;
22160 }
22161
22162 DHD_INFO(("%s: M4 TX failed on %d.\n",
22163 __FUNCTION__, ifidx));
22164
22165 OSL_ATOMIC_SET(dhdp->osh, &ifp->m4state, M4_TXFAILED);
22166 schedule_delayed_work(&ifp->m4state_work,
22167 msecs_to_jiffies(MAX_4WAY_TIMEOUT_MS));
22168 }
22169 }
22170 }
22171 }
22172
22173 void
22174 dhd_cleanup_m4_state_work(dhd_pub_t *dhdp, int ifidx)
22175 {
22176 dhd_info_t *dhdinfo;
22177 dhd_if_t *ifp;
22178
22179 if ((ifidx < 0) || (ifidx >= DHD_MAX_IFS)) {
22180 DHD_ERROR(("%s: invalid ifidx %d\n", __FUNCTION__, ifidx));
22181 return;
22182 }
22183
22184 dhdinfo = (dhd_info_t *)(dhdp->info);
22185 if (!dhdinfo) {
22186 DHD_ERROR(("%s: dhdinfo is NULL\n", __FUNCTION__));
22187 return;
22188 }
22189
22190 ifp = dhdinfo->iflist[ifidx];
22191 if (ifp) {
22192 cancel_delayed_work_sync(&ifp->m4state_work);
22193 }
22194 }
22195 #endif /* DHD_4WAYM4_FAIL_DISCONNECT */
22196
22197 #ifdef DHD_HP2P
22198 unsigned long
22199 dhd_os_hp2plock(dhd_pub_t *pub)
22200 {
22201 dhd_info_t *dhd;
22202 unsigned long flags = 0;
22203
22204 dhd = (dhd_info_t *)(pub->info);
22205
22206 if (dhd) {
22207 spin_lock_irqsave(&dhd->hp2p_lock, flags);
22208 }
22209
22210 return flags;
22211 }
22212
22213 void
22214 dhd_os_hp2punlock(dhd_pub_t *pub, unsigned long flags)
22215 {
22216 dhd_info_t *dhd;
22217
22218 dhd = (dhd_info_t *)(pub->info);
22219
22220 if (dhd) {
22221 spin_unlock_irqrestore(&dhd->hp2p_lock, flags);
22222 }
22223 }
22224 #endif /* DHD_HP2P */
22225 #ifdef DNGL_AXI_ERROR_LOGGING
22226 static void
22227 dhd_axi_error_dump(void *handle, void *event_info, u8 event)
22228 {
22229 dhd_info_t *dhd = (dhd_info_t *)handle;
22230 dhd_pub_t *dhdp = NULL;
22231
22232 if (!dhd) {
22233 DHD_ERROR(("%s: dhd is NULL\n", __FUNCTION__));
22234 goto exit;
22235 }
22236
22237 dhdp = &dhd->pub;
22238 if (!dhdp) {
22239 DHD_ERROR(("%s: dhdp is NULL\n", __FUNCTION__));
22240 goto exit;
22241 }
22242
22243 /**
22244 * First save axi error information to a file
22245 * because panic should happen right after this.
22246 * After dhd reset, dhd reads the file, and do hang event process
22247 * to send axi error stored on the file to Bigdata server
22248 */
22249 if (dhdp->axi_err_dump->etd_axi_error_v1.version != HND_EXT_TRAP_AXIERROR_VERSION_1) {
22250 DHD_ERROR(("%s: Invalid AXI version: 0x%x\n",
22251 __FUNCTION__, dhdp->axi_err_dump->etd_axi_error_v1.version));
22252 }
22253
22254 DHD_OS_WAKE_LOCK(dhdp);
22255 #ifdef DHD_FW_COREDUMP
22256 #ifdef DHD_SSSR_DUMP
22257 dhdp->collect_sssr = TRUE;
22258 #endif /* DHD_SSSR_DUMP */
22259 DHD_ERROR(("%s: scheduling mem dump.. \n", __FUNCTION__));
22260 dhd_schedule_memdump(dhdp, dhdp->soc_ram, dhdp->soc_ram_length);
22261 #endif /* DHD_FW_COREDUMP */
22262 DHD_OS_WAKE_UNLOCK(dhdp);
22263
22264 exit:
22265 /* Trigger kernel panic after taking necessary dumps */
22266 BUG_ON(1);
22267 }
22268
22269 void dhd_schedule_axi_error_dump(dhd_pub_t *dhdp, void *type)
22270 {
22271 DHD_ERROR(("%s: scheduling axi_error_dump.. \n", __FUNCTION__));
22272 dhd_deferred_schedule_work(dhdp->info->dhd_deferred_wq,
22273 type, DHD_WQ_WORK_AXI_ERROR_DUMP,
22274 dhd_axi_error_dump, DHD_WQ_WORK_PRIORITY_HIGH);
22275 }
22276 #endif /* DNGL_AXI_ERROR_LOGGING */
22277
22278 #ifdef BCMPCIE
22279 static void
22280 dhd_cto_recovery_handler(void *handle, void *event_info, u8 event)
22281 {
22282 dhd_info_t *dhd = handle;
22283 dhd_pub_t *dhdp = NULL;
22284
22285 if (!dhd) {
22286 DHD_ERROR(("%s: dhd is NULL\n", __FUNCTION__));
22287 BUG_ON(1);
22288 return;
22289 }
22290
22291 dhdp = &dhd->pub;
22292 dhdpcie_cto_recovery_handler(dhdp);
22293 }
22294
22295 void
22296 dhd_schedule_cto_recovery(dhd_pub_t *dhdp)
22297 {
22298 DHD_ERROR(("%s: scheduling cto recovery.. \n", __FUNCTION__));
22299 dhd_deferred_schedule_work(dhdp->info->dhd_deferred_wq,
22300 NULL, DHD_WQ_WORK_CTO_RECOVERY,
22301 dhd_cto_recovery_handler, DHD_WQ_WORK_PRIORITY_HIGH);
22302 }
22303 #endif /* BCMPCIE */
22304
22305 #ifdef SUPPORT_SET_TID
22306 /*
22307 * Set custom TID value for UDP frame based on UID value.
22308 * This will be triggered by android private command below.
22309 * DRIVER SET_TID <Mode:uint8> <Target UID:uint32> <Custom TID:uint8>
22310 * Mode 0(SET_TID_OFF) : Disable changing TID
22311 * Mode 1(SET_TID_ALL_UDP) : Change TID for all UDP frames
22312 * Mode 2(SET_TID_BASED_ON_UID) : Change TID for UDP frames based on target UID
22313 */
22314 void
22315 dhd_set_tid_based_on_uid(dhd_pub_t *dhdp, void *pkt)
22316 {
22317 struct ether_header *eh = NULL;
22318 struct sock *sk = NULL;
22319 uint8 *pktdata = NULL;
22320 uint8 *ip_hdr = NULL;
22321 uint8 cur_prio;
22322 uint8 prio;
22323 uint32 uid;
22324
22325 if (dhdp->tid_mode == SET_TID_OFF) {
22326 return;
22327 }
22328
22329 pktdata = (uint8 *)PKTDATA(dhdp->osh, pkt);
22330 eh = (struct ether_header *) pktdata;
22331 ip_hdr = (uint8 *)eh + ETHER_HDR_LEN;
22332
22333 if (IPV4_PROT(ip_hdr) != IP_PROT_UDP) {
22334 return;
22335 }
22336
22337 cur_prio = PKTPRIO(pkt);
22338 prio = dhdp->target_tid;
22339 uid = dhdp->target_uid;
22340
22341 if ((cur_prio == prio) ||
22342 (cur_prio != PRIO_8021D_BE)) {
22343 return;
22344 }
22345
22346 sk = ((struct sk_buff*)(pkt))->sk;
22347
22348 if ((dhdp->tid_mode == SET_TID_ALL_UDP) ||
22349 (sk && (uid == __kuid_val(sock_i_uid(sk))))) {
22350 PKTSETPRIO(pkt, prio);
22351 }
22352 }
22353 #endif /* SUPPORT_SET_TID */
22354
22355 void *dhd_get_pub(struct net_device *dev)
22356 {
22357 dhd_info_t *dhdinfo = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
22358 if (dhdinfo)
22359 return (void *)&dhdinfo->pub;
22360 else {
22361 printf("%s: null dhdinfo\n", __FUNCTION__);
22362 return NULL;
22363 }
22364 }
22365
22366 void *dhd_get_conf(struct net_device *dev)
22367 {
22368 dhd_info_t *dhdinfo = *(dhd_info_t **)DHD_DEV_PRIV_CFG(dev);
22369 if (dhdinfo)
22370 return (void *)dhdinfo->pub.conf;
22371 else {
22372 printf("%s: null dhdinfo\n", __FUNCTION__);
22373 return NULL;
22374 }
22375 }
22376
22377 bool dhd_os_wd_timer_enabled(void *bus)
22378 {
22379 dhd_pub_t *pub = bus;
22380 dhd_info_t *dhd = (dhd_info_t *)pub->info;
22381
22382 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
22383 if (!dhd) {
22384 DHD_ERROR(("%s: dhd NULL\n", __FUNCTION__));
22385 return FALSE;
22386 }
22387 return dhd->wd_timer_valid;
22388 }
22389
22390 #if defined(WLDWDS) && defined(FOURADDR_AUTO_BRG)
22391 /* This function is to automatically add/del interface to the bridged dev that priamy dev is in */
22392 static void dhd_bridge_dev_set(dhd_info_t *dhd, int ifidx, struct net_device *dev)
22393 {
22394 struct net_device *primary_ndev = NULL, *br_dev = NULL;
22395 int cmd;
22396 struct ifreq ifr;
22397
22398 /* add new interface to bridge dev */
22399 if (dev) {
22400 int found = 0, i;
22401 DHD_ERROR(("bssidx %d\n", dhd->pub.info->iflist[ifidx]->bssidx));
22402 for (i = 0 ; i < ifidx; i++) {
22403 DHD_ERROR(("bssidx %d %d\n", i, dhd->pub.info->iflist[i]->bssidx));
22404 /* search the primary interface */
22405 if (dhd->pub.info->iflist[i]->bssidx == dhd->pub.info->iflist[ifidx]->bssidx) {
22406 primary_ndev = dhd->pub.info->iflist[i]->net;
22407 DHD_ERROR(("%dst is primary dev %s\n", i, primary_ndev->name));
22408 found = 1;
22409 break;
22410 }
22411 }
22412 if (found == 0) {
22413 DHD_ERROR(("Can not find primary dev %s\n", dev->name));
22414 return;
22415 }
22416 cmd = SIOCBRADDIF;
22417 ifr.ifr_ifindex = dev->ifindex;
22418 } else { /* del interface from bridge dev */
22419 primary_ndev = dhd->pub.info->iflist[ifidx]->net;
22420 cmd = SIOCBRDELIF;
22421 ifr.ifr_ifindex = primary_ndev->ifindex;
22422 }
22423 /* if primary net device is bridged */
22424 if (primary_ndev->priv_flags & IFF_BRIDGE_PORT) {
22425 rtnl_lock();
22426 /* get bridge device */
22427 br_dev = netdev_master_upper_dev_get(primary_ndev);
22428 if (br_dev) {
22429 const struct net_device_ops *ops = br_dev->netdev_ops;
22430 DHD_ERROR(("br %s pri %s\n", br_dev->name, primary_ndev->name));
22431 if (ops) {
22432 if (cmd == SIOCBRADDIF) {
22433 DHD_ERROR(("br call ndo_add_slave\n"));
22434 ops->ndo_add_slave(br_dev, dev);
22435 /* Also bring wds0.x interface up automatically */
22436 dev_change_flags(dev, dev->flags | IFF_UP);
22437 }
22438 else {
22439 DHD_ERROR(("br call ndo_del_slave\n"));
22440 ops->ndo_del_slave(br_dev, primary_ndev);
22441 }
22442 }
22443 }
22444 else {
22445 DHD_ERROR(("no br dev\n"));
22446 }
22447 rtnl_unlock();
22448 }
22449 else {
22450 DHD_ERROR(("device %s is not bridged\n", primary_ndev->name));
22451 }
22452 }
22453 #endif /* defiend(WLDWDS) && defined(FOURADDR_AUTO_BRG) */
22454