2 * Broadcom Dongle Host Driver (DHD), Linux-specific network interface
3 * Basically selected code segments from usb-cdc.c and usb-rndis.c
5 * Copyright (C) 1999-2016, Broadcom Corporation
7 * Unless you and Broadcom execute a separate written software license
8 * agreement governing use of this software, this software is licensed to you
9 * under the terms of the GNU General Public License version 2 (the "GPL"),
10 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
11 * following added to such license:
13 * As a special exception, the copyright holders of this software give you
14 * permission to link this software with independent modules, and to copy and
15 * distribute the resulting executable under terms of your choice, provided that
16 * you also meet, for each linked independent module, the terms and conditions of
17 * the license of that module. An independent module is a module which is not
18 * derived from this software. The special exception does not apply to any
19 * modifications of the software.
21 * Notwithstanding the above, under no circumstances may you combine this
22 * software in any way with any other Broadcom software provided under a license
23 * other than the GPL, without Broadcom's express prior written consent.
26 * <<Broadcom-WL-IPTag/Open:>>
28 * $Id: dhd_linux.c 609723 2016-01-05 08:40:45Z $
35 #include <linux/syscalls.h>
36 #include <event_log.h>
37 #endif /* SHOW_LOGTRACE */
40 #include <linux/init.h>
41 #include <linux/kernel.h>
42 #include <linux/slab.h>
43 #include <linux/skbuff.h>
44 #include <linux/netdevice.h>
45 #include <linux/inetdevice.h>
46 #include <linux/rtnetlink.h>
47 #include <linux/etherdevice.h>
48 #include <linux/random.h>
49 #include <linux/spinlock.h>
50 #include <linux/ethtool.h>
51 #include <linux/fcntl.h>
54 #include <linux/reboot.h>
55 #include <linux/notifier.h>
56 #include <net/addrconf.h>
57 #ifdef ENABLE_ADAPTIVE_SCHED
58 #include <linux/cpufreq.h>
59 #endif /* ENABLE_ADAPTIVE_SCHED */
61 #include <asm/uaccess.h>
62 #include <asm/unaligned.h>
66 #include <bcmendian.h>
69 #include <proto/ethernet.h>
70 #include <proto/bcmevent.h>
71 #include <proto/vlan.h>
72 #include <proto/802.3.h>
74 #include <dngl_stats.h>
75 #include <dhd_linux_wq.h>
77 #include <dhd_linux.h>
78 #ifdef PCIE_FULL_DONGLE
79 #include <dhd_flowring.h>
82 #include <dhd_proto.h>
83 #include <dhd_config.h>
88 #ifdef CONFIG_HAS_WAKELOCK
89 #include <linux/wakelock.h>
92 #include <wl_cfg80211.h>
102 #include <linux/compat.h>
106 #include <dhd_wmf_linux.h>
110 #include <proto/bcmicmp.h>
111 #include <bcm_l2_filter.h>
112 #include <dhd_l2_filter.h>
113 #endif /* DHD_L2_FILTER */
116 #include <dhd_psta.h>
117 #endif /* DHD_PSTA */
120 #ifdef DHDTCPACK_SUPPRESS
122 #endif /* DHDTCPACK_SUPPRESS */
124 #ifdef DHD_DEBUG_PAGEALLOC
125 typedef void (*page_corrupt_cb_t)(void *handle, void *addr_corrupt, size_t len);
126 void dhd_page_corrupt_cb(void *handle, void *addr_corrupt, size_t len);
127 extern void register_page_corrupt_cb(page_corrupt_cb_t cb, void* handle);
128 #endif /* DHD_DEBUG_PAGEALLOC */
132 /* Dynamic CPU selection for load balancing */
133 #include <linux/cpu.h>
134 #include <linux/cpumask.h>
135 #include <linux/notifier.h>
136 #include <linux/workqueue.h>
137 #include <asm/atomic.h>
139 #if !defined(DHD_LB_PRIMARY_CPUS)
140 #define DHD_LB_PRIMARY_CPUS 0x0 /* Big CPU coreids mask */
143 #if !defined(DHD_LB_SECONDARY_CPUS)
144 #define DHD_LB_SECONDARY_CPUS 0xFE /* Little CPU coreids mask */
147 #define HIST_BIN_SIZE 8
149 #if defined(DHD_LB_RXP)
150 static void dhd_rx_napi_dispatcher_fn(struct work_struct * work);
151 #endif /* DHD_LB_RXP */
156 #include <linux/time.h>
159 #define HTSF_MINLEN 200 /* min. packet length to timestamp */
160 #define HTSF_BUS_DELAY 150 /* assume a fix propagation in us */
161 #define TSMAX 1000 /* max no. of timing record kept */
164 static uint32 tsidx = 0;
165 static uint32 htsf_seqnum = 0;
167 struct timeval tsync;
168 static uint32 tsport = 5010;
170 typedef struct histo_ {
174 #if !ISPOWEROF2(DHD_SDALIGN)
175 #error DHD_SDALIGN is not a power of 2!
178 static histo_t vi_d1, vi_d2, vi_d3, vi_d4;
179 #endif /* WLMEDIA_HTSF */
184 #endif /* quote_str */
187 #endif /* quote_str */
189 #define quote_str(s) to_str(s)
191 static char *driver_target = "driver_target: "quote_str(BRCM_DRIVER_TARGET);
192 #endif /* STBLINUX */
196 extern bool ap_cfg_running;
197 extern bool ap_fw_loaded;
199 extern void dhd_dump_eapol_4way_message(char *ifname, char *dump_data, bool direction);
201 #ifdef FIX_CPU_MIN_CLOCK
202 #include <linux/pm_qos.h>
203 #endif /* FIX_CPU_MIN_CLOCK */
204 #ifdef SET_RANDOM_MAC_SOFTAP
205 #ifndef CONFIG_DHD_SET_RANDOM_MAC_VAL
206 #define CONFIG_DHD_SET_RANDOM_MAC_VAL 0x001A11
208 static u32 vendor_oui = CONFIG_DHD_SET_RANDOM_MAC_VAL;
209 #endif /* SET_RANDOM_MAC_SOFTAP */
210 #ifdef ENABLE_ADAPTIVE_SCHED
211 #define DEFAULT_CPUFREQ_THRESH 1000000 /* threshold frequency : 1000000 = 1GHz */
212 #ifndef CUSTOM_CPUFREQ_THRESH
213 #define CUSTOM_CPUFREQ_THRESH DEFAULT_CPUFREQ_THRESH
214 #endif /* CUSTOM_CPUFREQ_THRESH */
215 #endif /* ENABLE_ADAPTIVE_SCHED */
217 /* enable HOSTIP cache update from the host side when an eth0:N is up */
218 #define AOE_IP_ALIAS_SUPPORT 1
222 #include <bcm_rpc_tp.h>
225 #include <wlfc_proto.h>
226 #include <dhd_wlfc.h>
229 #include <wl_android.h>
231 /* Maximum STA per radio */
232 #define DHD_MAX_STA 32
236 const uint8 wme_fifo2ac[] = { 0, 1, 2, 3, 1, 1 };
237 const uint8 prio2fifo[8] = { 1, 0, 0, 1, 2, 2, 3, 3 };
238 #define WME_PRIO2AC(prio) wme_fifo2ac[prio2fifo[(prio)]]
240 #ifdef ARP_OFFLOAD_SUPPORT
241 void aoe_update_host_ipv4_table(dhd_pub_t *dhd_pub, u32 ipa, bool add, int idx);
242 static int dhd_inetaddr_notifier_call(struct notifier_block *this,
243 unsigned long event, void *ptr);
244 static struct notifier_block dhd_inetaddr_notifier = {
245 .notifier_call = dhd_inetaddr_notifier_call
247 /* to make sure we won't register the same notifier twice, otherwise a loop is likely to be
248 * created in kernel notifier link list (with 'next' pointing to itself)
250 static bool dhd_inetaddr_notifier_registered = FALSE;
251 #endif /* ARP_OFFLOAD_SUPPORT */
253 #if defined(CONFIG_IPV6) && defined(IPV6_NDO_SUPPORT)
254 static int dhd_inet6addr_notifier_call(struct notifier_block *this,
255 unsigned long event, void *ptr);
256 static struct notifier_block dhd_inet6addr_notifier = {
257 .notifier_call = dhd_inet6addr_notifier_call
259 /* to make sure we won't register the same notifier twice, otherwise a loop is likely to be
260 * created in kernel notifier link list (with 'next' pointing to itself)
262 static bool dhd_inet6addr_notifier_registered = FALSE;
263 #endif /* CONFIG_IPV6 && IPV6_NDO_SUPPORT */
265 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP)
266 #include <linux/suspend.h>
267 volatile bool dhd_mmc_suspend = FALSE;
268 DECLARE_WAIT_QUEUE_HEAD(dhd_dpc_wait);
269 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP) */
271 #if defined(OOB_INTR_ONLY) || defined(FORCE_WOWLAN)
272 extern void dhd_enable_oob_intr(struct dhd_bus *bus, bool enable);
274 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
275 static void dhd_hang_process(void *dhd_info, void *event_data, u8 event);
277 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
278 MODULE_LICENSE("GPL and additional rights");
279 #endif /* LinuxVer */
284 #define DBUS_RX_BUFFER_SIZE_DHD(net) (BCM_RPC_TP_DNGL_AGG_MAX_BYTE)
286 #ifndef PROP_TXSTATUS
287 #define DBUS_RX_BUFFER_SIZE_DHD(net) (net->mtu + net->hard_header_len + dhd->pub.hdrlen)
289 #define DBUS_RX_BUFFER_SIZE_DHD(net) (net->mtu + net->hard_header_len + dhd->pub.hdrlen + 128)
291 #endif /* BCM_FD_AGGR */
294 extern bool dhd_wlfc_skip_fc(void);
295 extern void dhd_wlfc_plat_init(void *dhd);
296 extern void dhd_wlfc_plat_deinit(void *dhd);
297 #endif /* PROP_TXSTATUS */
298 #ifdef USE_DYNAMIC_F2_BLKSIZE
299 extern uint sd_f2_blocksize;
300 extern int dhdsdio_func_blocksize(dhd_pub_t *dhd, int function_num, int block_size);
301 #endif /* USE_DYNAMIC_F2_BLKSIZE */
303 #if LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 15)
309 #endif /* LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 15) */
311 /* Linux wireless extension support */
312 #if defined(WL_WIRELESS_EXT)
314 extern wl_iw_extra_params_t g_wl_iw_params;
315 #endif /* defined(WL_WIRELESS_EXT) */
317 #ifdef CONFIG_PARTIALSUSPEND_SLP
318 #include <linux/partialsuspend_slp.h>
319 #define CONFIG_HAS_EARLYSUSPEND
320 #define DHD_USE_EARLYSUSPEND
321 #define register_early_suspend register_pre_suspend
322 #define unregister_early_suspend unregister_pre_suspend
323 #define early_suspend pre_suspend
324 #define EARLY_SUSPEND_LEVEL_BLANK_SCREEN 50
326 #if defined(CONFIG_HAS_EARLYSUSPEND) && defined(DHD_USE_EARLYSUSPEND)
327 #include <linux/earlysuspend.h>
328 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) && defined(DHD_USE_EARLYSUSPEND) */
329 #endif /* CONFIG_PARTIALSUSPEND_SLP */
331 extern int dhd_get_suspend_bcn_li_dtim(dhd_pub_t *dhd);
333 #ifdef PKT_FILTER_SUPPORT
334 extern void dhd_pktfilter_offload_set(dhd_pub_t * dhd, char *arg);
335 extern void dhd_pktfilter_offload_enable(dhd_pub_t * dhd, char *arg, int enable, int master_mode);
336 extern void dhd_pktfilter_offload_delete(dhd_pub_t *dhd, int id);
341 extern int dhd_read_macaddr(struct dhd_info *dhd);
343 static inline int dhd_read_macaddr(struct dhd_info *dhd) { return 0; }
346 extern int dhd_write_macaddr(struct ether_addr *mac);
348 static inline int dhd_write_macaddr(struct ether_addr *mac) { return 0; }
355 #ifdef DHD_FW_COREDUMP
356 static void dhd_mem_dump(void *dhd_info, void *event_info, u8 event);
357 #endif /* DHD_FW_COREDUMP */
359 static void dhd_log_dump_init(dhd_pub_t *dhd);
360 static void dhd_log_dump_deinit(dhd_pub_t *dhd);
361 static void dhd_log_dump(void *handle, void *event_info, u8 event);
362 void dhd_schedule_log_dump(dhd_pub_t *dhdp);
363 static int do_dhd_log_dump(dhd_pub_t *dhdp);
364 #endif /* DHD_LOG_DUMP */
366 static int dhd_reboot_callback(struct notifier_block *this, unsigned long code, void *unused);
367 static struct notifier_block dhd_reboot_notifier = {
368 .notifier_call = dhd_reboot_callback,
373 static int is_reboot = 0;
376 typedef struct dhd_if_event {
377 struct list_head list;
378 wl_event_data_if_t event;
379 char name[IFNAMSIZ+1];
380 uint8 mac[ETHER_ADDR_LEN];
383 /* Interface control information */
384 typedef struct dhd_if {
385 struct dhd_info *info; /* back pointer to dhd_info */
386 /* OS/stack specifics */
387 struct net_device *net;
388 int idx; /* iface idx in dongle */
389 uint subunit; /* subunit */
390 uint8 mac_addr[ETHER_ADDR_LEN]; /* assigned MAC address */
393 uint8 bssidx; /* bsscfg index for the interface */
394 bool attached; /* Delayed attachment when unset */
395 bool txflowcontrol; /* Per interface flow control indicator */
396 char name[IFNAMSIZ+1]; /* linux interface name */
397 char dngl_name[IFNAMSIZ+1]; /* corresponding dongle interface name */
398 struct net_device_stats stats;
400 dhd_wmf_t wmf; /* per bsscfg wmf setting */
402 #ifdef PCIE_FULL_DONGLE
403 struct list_head sta_list; /* sll of associated stations */
404 #if !defined(BCM_GMAC3)
405 spinlock_t sta_list_lock; /* lock for manipulating sll */
406 #endif /* ! BCM_GMAC3 */
407 #endif /* PCIE_FULL_DONGLE */
408 uint32 ap_isolate; /* ap-isolation settings */
413 arp_table_t *phnd_arp_table;
414 /* for Per BSS modification */
418 #endif /* DHD_L2_FILTER */
431 uint32 coef; /* scaling factor */
432 uint32 coefdec1; /* first decimal */
433 uint32 coefdec2; /* second decimal */
443 static tstamp_t ts[TSMAX];
444 static tstamp_t maxdelayts;
445 static uint32 maxdelay = 0, tspktcnt = 0, maxdelaypktno = 0;
447 #endif /* WLMEDIA_HTSF */
449 struct ipv6_work_info_t {
456 typedef struct dhd_dump {
460 #endif /* DHD_DEBUG */
462 /* When Perimeter locks are deployed, any blocking calls must be preceeded
463 * with a PERIM UNLOCK and followed by a PERIM LOCK.
464 * Examples of blocking calls are: schedule_timeout(), down_interruptible(),
465 * wait_event_timeout().
468 /* Local private structure (extension of pub) */
469 typedef struct dhd_info {
470 #if defined(WL_WIRELESS_EXT)
471 wl_iw_t iw; /* wireless extensions state (must be first) */
472 #endif /* defined(WL_WIRELESS_EXT) */
474 dhd_if_t *iflist[DHD_MAX_IFS]; /* for supporting multiple interfaces */
476 void *adapter; /* adapter information, interrupt, fw path etc. */
477 char fw_path[PATH_MAX]; /* path to firmware image */
478 char nv_path[PATH_MAX]; /* path to nvram vars file */
479 char conf_path[PATH_MAX]; /* path to config vars file */
481 /* serialize dhd iovars */
482 struct mutex dhd_iovar_mutex;
484 struct semaphore proto_sem;
486 spinlock_t wlfc_spinlock;
488 #endif /* PROP_TXSTATUS */
492 wait_queue_head_t ioctl_resp_wait;
493 wait_queue_head_t d3ack_wait;
494 wait_queue_head_t dhd_bus_busy_state_wait;
495 uint32 default_wd_interval;
497 struct timer_list timer;
499 #ifdef DHD_PCIE_RUNTIMEPM
500 struct timer_list rpm_timer;
501 bool rpm_timer_valid;
502 tsk_ctl_t thr_rpm_ctl;
503 #endif /* DHD_PCIE_RUNTIMEPM */
504 struct tasklet_struct tasklet;
509 struct semaphore sdsem;
510 tsk_ctl_t thr_dpc_ctl;
511 tsk_ctl_t thr_wdt_ctl;
513 tsk_ctl_t thr_rxf_ctl;
515 bool rxthread_enabled;
518 #if defined(CONFIG_HAS_WAKELOCK) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
519 struct wake_lock wl_wifi; /* Wifi wakelock */
520 struct wake_lock wl_rxwake; /* Wifi rx wakelock */
521 struct wake_lock wl_ctrlwake; /* Wifi ctrl wakelock */
522 struct wake_lock wl_wdwake; /* Wifi wd wakelock */
523 struct wake_lock wl_evtwake; /* Wifi event wakelock */
524 #ifdef BCMPCIE_OOB_HOST_WAKE
525 struct wake_lock wl_intrwake; /* Host wakeup wakelock */
526 #endif /* BCMPCIE_OOB_HOST_WAKE */
527 #ifdef DHD_USE_SCAN_WAKELOCK
528 struct wake_lock wl_scanwake; /* Wifi scan wakelock */
529 #endif /* DHD_USE_SCAN_WAKELOCK */
530 #endif /* CONFIG_HAS_WAKELOCK && LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27) */
532 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
533 /* net_device interface lock, prevent race conditions among net_dev interface
534 * calls and wifi_on or wifi_off
536 struct mutex dhd_net_if_mutex;
537 struct mutex dhd_suspend_mutex;
539 spinlock_t wakelock_spinlock;
540 spinlock_t wakelock_evt_spinlock;
541 uint32 wakelock_event_counter;
542 uint32 wakelock_counter;
543 int wakelock_wd_counter;
544 int wakelock_rx_timeout_enable;
545 int wakelock_ctrl_timeout_enable;
547 uint32 wakelock_before_waive;
549 /* Thread to issue ioctl for multicast */
550 wait_queue_head_t ctrl_wait;
551 atomic_t pend_8021x_cnt;
552 dhd_attach_states_t dhd_state;
554 dhd_event_log_t event_data;
555 #endif /* SHOW_LOGTRACE */
557 #if defined(CONFIG_HAS_EARLYSUSPEND) && defined(DHD_USE_EARLYSUSPEND)
558 struct early_suspend early_suspend;
559 #endif /* CONFIG_HAS_EARLYSUSPEND && DHD_USE_EARLYSUSPEND */
561 #ifdef ARP_OFFLOAD_SUPPORT
563 #endif /* ARP_OFFLOAD_SUPPORT */
567 struct timer_list rpcth_timer;
568 bool rpcth_timer_active;
571 #ifdef DHDTCPACK_SUPPRESS
572 spinlock_t tcpack_lock;
573 #endif /* DHDTCPACK_SUPPRESS */
574 #ifdef FIX_CPU_MIN_CLOCK
575 bool cpufreq_fix_status;
576 struct mutex cpufreq_fix;
577 struct pm_qos_request dhd_cpu_qos;
578 #ifdef FIX_BUS_MIN_CLOCK
579 struct pm_qos_request dhd_bus_qos;
580 #endif /* FIX_BUS_MIN_CLOCK */
581 #endif /* FIX_CPU_MIN_CLOCK */
582 void *dhd_deferred_wq;
583 #ifdef DEBUG_CPU_FREQ
584 struct notifier_block freq_trans;
585 int __percpu *new_freq;
588 struct notifier_block pm_notifier;
590 uint32 psta_mode; /* PSTA or PSR */
591 #endif /* DHD_PSTA */
594 struct timer_list join_timer;
595 u32 join_timeout_val;
596 bool join_timer_active;
597 uint scan_time_count;
598 struct timer_list scan_timer;
599 bool scan_timer_active;
602 /* CPU Load Balance dynamic CPU selection */
604 /* Variable that tracks the currect CPUs available for candidacy */
605 cpumask_var_t cpumask_curr_avail;
607 /* Primary and secondary CPU mask */
608 cpumask_var_t cpumask_primary, cpumask_secondary; /* configuration */
609 cpumask_var_t cpumask_primary_new, cpumask_secondary_new; /* temp */
611 struct notifier_block cpu_notifier;
613 /* Tasklet to handle Tx Completion packet freeing */
614 struct tasklet_struct tx_compl_tasklet;
615 atomic_t tx_compl_cpu;
618 /* Tasklet to handle RxBuf Post during Rx completion */
619 struct tasklet_struct rx_compl_tasklet;
620 atomic_t rx_compl_cpu;
622 /* Napi struct for handling rx packet sendup. Packets are removed from
623 * H2D RxCompl ring and placed into rx_pend_queue. rx_pend_queue is then
624 * appended to rx_napi_queue (w/ lock) and the rx_napi_struct is scheduled
625 * to run to rx_napi_cpu.
627 struct sk_buff_head rx_pend_queue ____cacheline_aligned;
628 struct sk_buff_head rx_napi_queue ____cacheline_aligned;
629 struct napi_struct rx_napi_struct ____cacheline_aligned;
630 atomic_t rx_napi_cpu; /* cpu on which the napi is dispatched */
631 struct net_device *rx_napi_netdev; /* netdev of primary interface */
633 struct work_struct rx_napi_dispatcher_work;
634 struct work_struct tx_compl_dispatcher_work;
635 struct work_struct rx_compl_dispatcher_work;
636 /* Number of times DPC Tasklet ran */
639 /* Number of times NAPI processing got scheduled */
640 uint32 napi_sched_cnt;
642 /* Number of times NAPI processing ran on each available core */
643 uint32 napi_percpu_run_cnt[NR_CPUS];
645 /* Number of times RX Completions got scheduled */
646 uint32 rxc_sched_cnt;
647 /* Number of times RX Completion ran on each available core */
648 uint32 rxc_percpu_run_cnt[NR_CPUS];
650 /* Number of times TX Completions got scheduled */
651 uint32 txc_sched_cnt;
652 /* Number of times TX Completions ran on each available core */
653 uint32 txc_percpu_run_cnt[NR_CPUS];
656 /* Number of times each CPU came online */
657 uint32 cpu_online_cnt[NR_CPUS];
659 /* Number of times each CPU went offline */
660 uint32 cpu_offline_cnt[NR_CPUS];
663 * Consumer Histogram - NAPI RX Packet processing
664 * -----------------------------------------------
665 * On Each CPU, when the NAPI RX Packet processing call back was invoked
666 * how many packets were processed is captured in this data structure.
667 * Now its difficult to capture the "exact" number of packets processed.
668 * So considering the packet counter to be a 32 bit one, we have a
669 * bucket with 8 bins (2^1, 2^2 ... 2^8). The "number" of packets
670 * processed is rounded off to the next power of 2 and put in the
671 * approriate "bin" the value in the bin gets incremented.
672 * For example, assume that in CPU 1 if NAPI Rx runs 3 times
673 * and the packet count processed is as follows (assume the bin counters are 0)
674 * iteration 1 - 10 (the bin counter 2^4 increments to 1)
675 * iteration 2 - 30 (the bin counter 2^5 increments to 1)
676 * iteration 3 - 15 (the bin counter 2^4 increments by 1 to become 2)
678 uint32 napi_rx_hist[NR_CPUS][HIST_BIN_SIZE];
679 uint32 txc_hist[NR_CPUS][HIST_BIN_SIZE];
680 uint32 rxc_hist[NR_CPUS][HIST_BIN_SIZE];
683 #if defined(BCM_DNGL_EMBEDIMAGE) || defined(BCM_REQUEST_FW)
684 #endif /* defined(BCM_DNGL_EMBEDIMAGE) || defined(BCM_REQUEST_FW) */
686 struct kobject dhd_kobj;
687 #ifdef SUPPORT_SENSORHUB
689 #endif /* SUPPORT_SENSORHUB */
691 struct delayed_work dhd_memdump_work;
694 #define DHDIF_FWDER(dhdif) FALSE
696 /* Flag to indicate if we should download firmware on driver load */
697 uint dhd_download_fw_on_driverload = TRUE;
699 /* Flag to indicate if driver is initialized */
700 uint dhd_driver_init_done = FALSE;
702 /* Definitions to provide path to the firmware and nvram
703 * example nvram_path[MOD_PARAM_PATHLEN]="/projects/wlan/nvram.txt"
705 char firmware_path[MOD_PARAM_PATHLEN];
706 char nvram_path[MOD_PARAM_PATHLEN];
707 char config_path[MOD_PARAM_PATHLEN];
709 /* backup buffer for firmware and nvram path */
710 char fw_bak_path[MOD_PARAM_PATHLEN];
711 char nv_bak_path[MOD_PARAM_PATHLEN];
713 /* information string to keep firmware, chio, cheip version info visiable from log */
714 char info_string[MOD_PARAM_INFOLEN];
715 module_param_string(info_string, info_string, MOD_PARAM_INFOLEN, 0444);
717 int disable_proptx = 0;
718 module_param(op_mode, int, 0644);
720 #if defined(DHD_LB_RXP)
721 static int dhd_napi_weight = 32;
722 module_param(dhd_napi_weight, int, 0644);
723 #endif /* DHD_LB_RXP */
725 extern int wl_control_wl_start(struct net_device *dev);
726 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(BCMLXSDMMC)
727 struct semaphore dhd_registration_sem;
728 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
730 /* deferred handlers */
731 static void dhd_ifadd_event_handler(void *handle, void *event_info, u8 event);
732 static void dhd_ifdel_event_handler(void *handle, void *event_info, u8 event);
733 static void dhd_set_mac_addr_handler(void *handle, void *event_info, u8 event);
734 static void dhd_set_mcast_list_handler(void *handle, void *event_info, u8 event);
735 #if defined(CONFIG_IPV6) && defined(IPV6_NDO_SUPPORT)
736 static void dhd_inet6_work_handler(void *dhd_info, void *event_data, u8 event);
737 #endif /* CONFIG_IPV6 && IPV6_NDO_SUPPORT */
739 extern void dhd_netdev_free(struct net_device *ndev);
740 #endif /* WL_CFG80211 */
743 module_param(dhd_msg_level, int, 0);
744 #if defined(WL_WIRELESS_EXT)
745 module_param(iw_msg_level, int, 0);
748 module_param(wl_dbg_level, int, 0);
750 module_param(android_msg_level, int, 0);
751 module_param(config_msg_level, int, 0);
753 #ifdef ARP_OFFLOAD_SUPPORT
754 /* ARP offload enable */
755 uint dhd_arp_enable = TRUE;
756 module_param(dhd_arp_enable, uint, 0);
758 /* ARP offload agent mode : Enable ARP Host Auto-Reply and ARP Peer Auto-Reply */
760 #ifdef ENABLE_ARP_SNOOP_MODE
761 uint dhd_arp_mode = ARP_OL_AGENT | ARP_OL_PEER_AUTO_REPLY | ARP_OL_SNOOP;
763 uint dhd_arp_mode = ARP_OL_AGENT | ARP_OL_PEER_AUTO_REPLY;
764 #endif /* ENABLE_ARP_SNOOP_MODE */
766 module_param(dhd_arp_mode, uint, 0);
767 #endif /* ARP_OFFLOAD_SUPPORT */
769 /* Disable Prop tx */
770 module_param(disable_proptx, int, 0644);
771 /* load firmware and/or nvram values from the filesystem */
772 module_param_string(firmware_path, firmware_path, MOD_PARAM_PATHLEN, 0660);
773 module_param_string(nvram_path, nvram_path, MOD_PARAM_PATHLEN, 0660);
774 module_param_string(config_path, config_path, MOD_PARAM_PATHLEN, 0);
776 /* Watchdog interval */
778 /* extend watchdog expiration to 2 seconds when DPC is running */
779 #define WATCHDOG_EXTEND_INTERVAL (2000)
781 uint dhd_watchdog_ms = CUSTOM_DHD_WATCHDOG_MS;
782 module_param(dhd_watchdog_ms, uint, 0);
784 #ifdef DHD_PCIE_RUNTIMEPM
785 uint dhd_runtimepm_ms = CUSTOM_DHD_RUNTIME_MS;
786 #endif /* DHD_PCIE_RUNTIMEPMT */
787 #if defined(DHD_DEBUG)
788 /* Console poll interval */
789 uint dhd_console_ms = 0;
790 module_param(dhd_console_ms, uint, 0644);
791 #endif /* defined(DHD_DEBUG) */
794 uint dhd_slpauto = TRUE;
795 module_param(dhd_slpauto, uint, 0);
797 #ifdef PKT_FILTER_SUPPORT
798 /* Global Pkt filter enable control */
799 uint dhd_pkt_filter_enable = TRUE;
800 module_param(dhd_pkt_filter_enable, uint, 0);
803 /* Pkt filter init setup */
804 uint dhd_pkt_filter_init = 0;
805 module_param(dhd_pkt_filter_init, uint, 0);
807 /* Pkt filter mode control */
808 #ifdef GAN_LITE_NAT_KEEPALIVE_FILTER
809 uint dhd_master_mode = FALSE;
811 uint dhd_master_mode = FALSE;
812 #endif /* GAN_LITE_NAT_KEEPALIVE_FILTER */
813 module_param(dhd_master_mode, uint, 0);
815 int dhd_watchdog_prio = 0;
816 module_param(dhd_watchdog_prio, int, 0);
818 /* DPC thread priority */
819 int dhd_dpc_prio = CUSTOM_DPC_PRIO_SETTING;
820 module_param(dhd_dpc_prio, int, 0);
822 /* RX frame thread priority */
823 int dhd_rxf_prio = CUSTOM_RXF_PRIO_SETTING;
824 module_param(dhd_rxf_prio, int, 0);
826 int passive_channel_skip = 0;
827 module_param(passive_channel_skip, int, (S_IRUSR|S_IWUSR));
829 #if !defined(BCMDHDUSB)
830 extern int dhd_dongle_ramsize;
831 module_param(dhd_dongle_ramsize, int, 0);
832 #endif /* BCMDHDUSB */
834 /* Keep track of number of instances */
835 static int dhd_found = 0;
836 static int instance_base = 0; /* Starting instance number */
837 module_param(instance_base, int, 0644);
839 /* Functions to manage sysfs interface for dhd */
840 static int dhd_sysfs_init(dhd_info_t *dhd);
841 static void dhd_sysfs_exit(dhd_info_t *dhd);
846 dhd_lb_set_default_cpus(dhd_info_t *dhd)
848 /* Default CPU allocation for the jobs */
849 atomic_set(&dhd->rx_napi_cpu, 1);
850 atomic_set(&dhd->rx_compl_cpu, 2);
851 atomic_set(&dhd->tx_compl_cpu, 2);
855 dhd_cpumasks_deinit(dhd_info_t *dhd)
857 free_cpumask_var(dhd->cpumask_curr_avail);
858 free_cpumask_var(dhd->cpumask_primary);
859 free_cpumask_var(dhd->cpumask_primary_new);
860 free_cpumask_var(dhd->cpumask_secondary);
861 free_cpumask_var(dhd->cpumask_secondary_new);
865 dhd_cpumasks_init(dhd_info_t *dhd)
871 if (!alloc_cpumask_var(&dhd->cpumask_curr_avail, GFP_KERNEL) ||
872 !alloc_cpumask_var(&dhd->cpumask_primary, GFP_KERNEL) ||
873 !alloc_cpumask_var(&dhd->cpumask_primary_new, GFP_KERNEL) ||
874 !alloc_cpumask_var(&dhd->cpumask_secondary, GFP_KERNEL) ||
875 !alloc_cpumask_var(&dhd->cpumask_secondary_new, GFP_KERNEL)) {
876 DHD_ERROR(("%s Failed to init cpumasks\n", __FUNCTION__));
881 cpumask_copy(dhd->cpumask_curr_avail, cpu_online_mask);
882 cpumask_clear(dhd->cpumask_primary);
883 cpumask_clear(dhd->cpumask_secondary);
885 cpus = DHD_LB_PRIMARY_CPUS;
886 for (id = 0; id < NR_CPUS; id++) {
887 if (isset(&cpus, id))
888 cpumask_set_cpu(id, dhd->cpumask_primary);
891 cpus = DHD_LB_SECONDARY_CPUS;
892 for (id = 0; id < NR_CPUS; id++) {
893 if (isset(&cpus, id))
894 cpumask_set_cpu(id, dhd->cpumask_secondary);
899 dhd_cpumasks_deinit(dhd);
904 * The CPU Candidacy Algorithm
905 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
906 * The available CPUs for selection are divided into two groups
907 * Primary Set - A CPU mask that carries the First Choice CPUs
908 * Secondary Set - A CPU mask that carries the Second Choice CPUs.
910 * There are two types of Job, that needs to be assigned to
911 * the CPUs, from one of the above mentioned CPU group. The Jobs are
912 * 1) Rx Packet Processing - napi_cpu
913 * 2) Completion Processiong (Tx, RX) - compl_cpu
915 * To begin with both napi_cpu and compl_cpu are on CPU0. Whenever a CPU goes
916 * on-line/off-line the CPU candidacy algorithm is triggerd. The candidacy
917 * algo tries to pickup the first available non boot CPU (CPU0) for napi_cpu.
918 * If there are more processors free, it assigns one to compl_cpu.
919 * It also tries to ensure that both napi_cpu and compl_cpu are not on the same
920 * CPU, as much as possible.
922 * By design, both Tx and Rx completion jobs are run on the same CPU core, as it
923 * would allow Tx completion skb's to be released into a local free pool from
924 * which the rx buffer posts could have been serviced. it is important to note
925 * that a Tx packet may not have a large enough buffer for rx posting.
927 void dhd_select_cpu_candidacy(dhd_info_t *dhd)
929 uint32 primary_available_cpus; /* count of primary available cpus */
930 uint32 secondary_available_cpus; /* count of secondary available cpus */
931 uint32 napi_cpu = 0; /* cpu selected for napi rx processing */
932 uint32 compl_cpu = 0; /* cpu selected for completion jobs */
934 cpumask_clear(dhd->cpumask_primary_new);
935 cpumask_clear(dhd->cpumask_secondary_new);
938 * Now select from the primary mask. Even if a Job is
939 * already running on a CPU in secondary group, we still move
940 * to primary CPU. So no conditional checks.
942 cpumask_and(dhd->cpumask_primary_new, dhd->cpumask_primary,
943 dhd->cpumask_curr_avail);
945 cpumask_and(dhd->cpumask_secondary_new, dhd->cpumask_secondary,
946 dhd->cpumask_curr_avail);
948 primary_available_cpus = cpumask_weight(dhd->cpumask_primary_new);
950 if (primary_available_cpus > 0) {
951 napi_cpu = cpumask_first(dhd->cpumask_primary_new);
953 /* If no further CPU is available,
954 * cpumask_next returns >= nr_cpu_ids
956 compl_cpu = cpumask_next(napi_cpu, dhd->cpumask_primary_new);
957 if (compl_cpu >= nr_cpu_ids)
961 DHD_INFO(("%s After primary CPU check napi_cpu %d compl_cpu %d\n",
962 __FUNCTION__, napi_cpu, compl_cpu));
964 /* -- Now check for the CPUs from the secondary mask -- */
965 secondary_available_cpus = cpumask_weight(dhd->cpumask_secondary_new);
967 DHD_INFO(("%s Available secondary cpus %d nr_cpu_ids %d\n",
968 __FUNCTION__, secondary_available_cpus, nr_cpu_ids));
970 if (secondary_available_cpus > 0) {
971 /* At this point if napi_cpu is unassigned it means no CPU
972 * is online from Primary Group
975 napi_cpu = cpumask_first(dhd->cpumask_secondary_new);
976 compl_cpu = cpumask_next(napi_cpu, dhd->cpumask_secondary_new);
977 } else if (compl_cpu == 0) {
978 compl_cpu = cpumask_first(dhd->cpumask_secondary_new);
981 /* If no CPU was available for completion, choose CPU 0 */
982 if (compl_cpu >= nr_cpu_ids)
985 if ((primary_available_cpus == 0) &&
986 (secondary_available_cpus == 0)) {
987 /* No CPUs available from primary or secondary mask */
992 DHD_INFO(("%s After secondary CPU check napi_cpu %d compl_cpu %d\n",
993 __FUNCTION__, napi_cpu, compl_cpu));
994 ASSERT(napi_cpu < nr_cpu_ids);
995 ASSERT(compl_cpu < nr_cpu_ids);
997 atomic_set(&dhd->rx_napi_cpu, napi_cpu);
998 atomic_set(&dhd->tx_compl_cpu, compl_cpu);
999 atomic_set(&dhd->rx_compl_cpu, compl_cpu);
1004 * Function to handle CPU Hotplug notifications.
1005 * One of the task it does is to trigger the CPU Candidacy algorithm
1006 * for load balancing.
1009 dhd_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
1011 unsigned int cpu = (unsigned int)(long)hcpu;
1013 dhd_info_t *dhd = container_of(nfb, dhd_info_t, cpu_notifier);
1018 DHD_LB_STATS_INCR(dhd->cpu_online_cnt[cpu]);
1019 cpumask_set_cpu(cpu, dhd->cpumask_curr_avail);
1020 dhd_select_cpu_candidacy(dhd);
1023 case CPU_DOWN_PREPARE:
1024 case CPU_DOWN_PREPARE_FROZEN:
1025 DHD_LB_STATS_INCR(dhd->cpu_offline_cnt[cpu]);
1026 cpumask_clear_cpu(cpu, dhd->cpumask_curr_avail);
1027 dhd_select_cpu_candidacy(dhd);
1036 #if defined(DHD_LB_STATS)
1037 void dhd_lb_stats_init(dhd_pub_t *dhdp)
1043 DHD_ERROR(("%s(): Invalid argument dhdp is NULL \n",
1050 DHD_ERROR(("%s(): DHD pointer is NULL \n", __FUNCTION__));
1054 DHD_LB_STATS_CLR(dhd->dhd_dpc_cnt);
1055 DHD_LB_STATS_CLR(dhd->napi_sched_cnt);
1056 DHD_LB_STATS_CLR(dhd->rxc_sched_cnt);
1057 DHD_LB_STATS_CLR(dhd->txc_sched_cnt);
1059 for (i = 0; i < NR_CPUS; i++) {
1060 DHD_LB_STATS_CLR(dhd->napi_percpu_run_cnt[i]);
1061 DHD_LB_STATS_CLR(dhd->rxc_percpu_run_cnt[i]);
1062 DHD_LB_STATS_CLR(dhd->txc_percpu_run_cnt[i]);
1064 DHD_LB_STATS_CLR(dhd->cpu_online_cnt[i]);
1065 DHD_LB_STATS_CLR(dhd->cpu_offline_cnt[i]);
1068 for (i = 0; i < NR_CPUS; i++) {
1069 for (j = 0; j < HIST_BIN_SIZE; j++) {
1070 DHD_LB_STATS_CLR(dhd->napi_rx_hist[i][j]);
1071 DHD_LB_STATS_CLR(dhd->txc_hist[i][j]);
1072 DHD_LB_STATS_CLR(dhd->rxc_hist[i][j]);
1079 static void dhd_lb_stats_dump_histo(
1080 struct bcmstrbuf *strbuf, uint32 (*hist)[HIST_BIN_SIZE])
1083 uint32 per_cpu_total[NR_CPUS] = {0};
1086 bcm_bprintf(strbuf, "CPU: \t\t");
1087 for (i = 0; i < num_possible_cpus(); i++)
1088 bcm_bprintf(strbuf, "%d\t", i);
1089 bcm_bprintf(strbuf, "\nBin\n");
1091 for (i = 0; i < HIST_BIN_SIZE; i++) {
1092 bcm_bprintf(strbuf, "%d:\t\t", 1<<(i+1));
1093 for (j = 0; j < num_possible_cpus(); j++) {
1094 bcm_bprintf(strbuf, "%d\t", hist[j][i]);
1096 bcm_bprintf(strbuf, "\n");
1098 bcm_bprintf(strbuf, "Per CPU Total \t");
1100 for (i = 0; i < num_possible_cpus(); i++) {
1101 for (j = 0; j < HIST_BIN_SIZE; j++) {
1102 per_cpu_total[i] += (hist[i][j] * (1<<(j+1)));
1104 bcm_bprintf(strbuf, "%d\t", per_cpu_total[i]);
1105 total += per_cpu_total[i];
1107 bcm_bprintf(strbuf, "\nTotal\t\t%d \n", total);
1112 static inline void dhd_lb_stats_dump_cpu_array(struct bcmstrbuf *strbuf, uint32 *p)
1116 bcm_bprintf(strbuf, "CPU: \t");
1117 for (i = 0; i < num_possible_cpus(); i++)
1118 bcm_bprintf(strbuf, "%d\t", i);
1119 bcm_bprintf(strbuf, "\n");
1121 bcm_bprintf(strbuf, "Val: \t");
1122 for (i = 0; i < num_possible_cpus(); i++)
1123 bcm_bprintf(strbuf, "%u\t", *(p+i));
1124 bcm_bprintf(strbuf, "\n");
1128 void dhd_lb_stats_dump(dhd_pub_t *dhdp, struct bcmstrbuf *strbuf)
1132 if (dhdp == NULL || strbuf == NULL) {
1133 DHD_ERROR(("%s(): Invalid argument dhdp %p strbuf %p \n",
1134 __FUNCTION__, dhdp, strbuf));
1140 DHD_ERROR(("%s(): DHD pointer is NULL \n", __FUNCTION__));
1144 bcm_bprintf(strbuf, "\ncpu_online_cnt:\n");
1145 dhd_lb_stats_dump_cpu_array(strbuf, dhd->cpu_online_cnt);
1147 bcm_bprintf(strbuf, "cpu_offline_cnt:\n");
1148 dhd_lb_stats_dump_cpu_array(strbuf, dhd->cpu_offline_cnt);
1150 bcm_bprintf(strbuf, "\nsched_cnt: dhd_dpc %u napi %u rxc %u txc %u\n",
1151 dhd->dhd_dpc_cnt, dhd->napi_sched_cnt, dhd->rxc_sched_cnt,
1152 dhd->txc_sched_cnt);
1154 bcm_bprintf(strbuf, "napi_percpu_run_cnt:\n");
1155 dhd_lb_stats_dump_cpu_array(strbuf, dhd->napi_percpu_run_cnt);
1156 bcm_bprintf(strbuf, "\nNAPI Packets Received Histogram:\n");
1157 dhd_lb_stats_dump_histo(strbuf, dhd->napi_rx_hist);
1158 #endif /* DHD_LB_RXP */
1161 bcm_bprintf(strbuf, "rxc_percpu_run_cnt:\n");
1162 dhd_lb_stats_dump_cpu_array(strbuf, dhd->rxc_percpu_run_cnt);
1163 bcm_bprintf(strbuf, "\nRX Completions (Buffer Post) Histogram:\n");
1164 dhd_lb_stats_dump_histo(strbuf, dhd->rxc_hist);
1165 #endif /* DHD_LB_RXC */
1169 bcm_bprintf(strbuf, "txc_percpu_run_cnt:\n");
1170 dhd_lb_stats_dump_cpu_array(strbuf, dhd->txc_percpu_run_cnt);
1171 bcm_bprintf(strbuf, "\nTX Completions (Buffer Free) Histogram:\n");
1172 dhd_lb_stats_dump_histo(strbuf, dhd->txc_hist);
1173 #endif /* DHD_LB_TXC */
1176 static void dhd_lb_stats_update_histo(uint32 *bin, uint32 count)
1181 bin_power = next_larger_power2(count);
1183 switch (bin_power) {
1185 case 1: /* Fall through intentionally */
1186 case 2: p = bin + 0; break;
1187 case 4: p = bin + 1; break;
1188 case 8: p = bin + 2; break;
1189 case 16: p = bin + 3; break;
1190 case 32: p = bin + 4; break;
1191 case 64: p = bin + 5; break;
1192 case 128: p = bin + 6; break;
1193 default : p = bin + 7; break;
1200 extern void dhd_lb_stats_update_napi_histo(dhd_pub_t *dhdp, uint32 count)
1203 dhd_info_t *dhd = dhdp->info;
1207 dhd_lb_stats_update_histo(&dhd->napi_rx_hist[cpu][0], count);
1212 extern void dhd_lb_stats_update_txc_histo(dhd_pub_t *dhdp, uint32 count)
1215 dhd_info_t *dhd = dhdp->info;
1219 dhd_lb_stats_update_histo(&dhd->txc_hist[cpu][0], count);
1224 extern void dhd_lb_stats_update_rxc_histo(dhd_pub_t *dhdp, uint32 count)
1227 dhd_info_t *dhd = dhdp->info;
1231 dhd_lb_stats_update_histo(&dhd->rxc_hist[cpu][0], count);
1236 extern void dhd_lb_stats_txc_percpu_cnt_incr(dhd_pub_t *dhdp)
1238 dhd_info_t *dhd = dhdp->info;
1239 DHD_LB_STATS_PERCPU_ARR_INCR(dhd->txc_percpu_run_cnt);
1242 extern void dhd_lb_stats_rxc_percpu_cnt_incr(dhd_pub_t *dhdp)
1244 dhd_info_t *dhd = dhdp->info;
1245 DHD_LB_STATS_PERCPU_ARR_INCR(dhd->rxc_percpu_run_cnt);
1248 #endif /* DHD_LB_STATS */
1252 #if defined(DISABLE_FRAMEBURST_VSDB) && defined(USE_WFA_CERT_CONF)
1253 int g_frameburst = 1;
1254 #endif /* DISABLE_FRAMEBURST_VSDB && USE_WFA_CERT_CONF */
1256 static int dhd_get_pend_8021x_cnt(dhd_info_t *dhd);
1258 /* DHD Perimiter lock only used in router with bypass forwarding. */
1259 #define DHD_PERIM_RADIO_INIT() do { /* noop */ } while (0)
1260 #define DHD_PERIM_LOCK_TRY(unit, flag) do { /* noop */ } while (0)
1261 #define DHD_PERIM_UNLOCK_TRY(unit, flag) do { /* noop */ } while (0)
1263 #ifdef PCIE_FULL_DONGLE
1264 #if defined(BCM_GMAC3)
1265 #define DHD_IF_STA_LIST_LOCK_INIT(ifp) do { /* noop */ } while (0)
1266 #define DHD_IF_STA_LIST_LOCK(ifp, flags) ({ BCM_REFERENCE(flags); })
1267 #define DHD_IF_STA_LIST_UNLOCK(ifp, flags) ({ BCM_REFERENCE(flags); })
1269 #if defined(DHD_IGMP_UCQUERY) || defined(DHD_UCAST_UPNP)
1270 #define DHD_IF_WMF_UCFORWARD_LOCK(dhd, ifp, slist) ({ BCM_REFERENCE(slist); &(ifp)->sta_list; })
1271 #define DHD_IF_WMF_UCFORWARD_UNLOCK(dhd, slist) ({ BCM_REFERENCE(slist); })
1272 #endif /* DHD_IGMP_UCQUERY || DHD_UCAST_UPNP */
1274 #else /* ! BCM_GMAC3 */
1275 #define DHD_IF_STA_LIST_LOCK_INIT(ifp) spin_lock_init(&(ifp)->sta_list_lock)
1276 #define DHD_IF_STA_LIST_LOCK(ifp, flags) \
1277 spin_lock_irqsave(&(ifp)->sta_list_lock, (flags))
1278 #define DHD_IF_STA_LIST_UNLOCK(ifp, flags) \
1279 spin_unlock_irqrestore(&(ifp)->sta_list_lock, (flags))
1281 #if defined(DHD_IGMP_UCQUERY) || defined(DHD_UCAST_UPNP)
1282 static struct list_head * dhd_sta_list_snapshot(dhd_info_t *dhd, dhd_if_t *ifp,
1283 struct list_head *snapshot_list);
1284 static void dhd_sta_list_snapshot_free(dhd_info_t *dhd, struct list_head *snapshot_list);
1285 #define DHD_IF_WMF_UCFORWARD_LOCK(dhd, ifp, slist) ({ dhd_sta_list_snapshot(dhd, ifp, slist); })
1286 #define DHD_IF_WMF_UCFORWARD_UNLOCK(dhd, slist) ({ dhd_sta_list_snapshot_free(dhd, slist); })
1287 #endif /* DHD_IGMP_UCQUERY || DHD_UCAST_UPNP */
1289 #endif /* ! BCM_GMAC3 */
1290 #endif /* PCIE_FULL_DONGLE */
1292 /* Control fw roaming */
1293 uint dhd_roam_disable = 0;
1296 extern int dhd_dbg_init(dhd_pub_t *dhdp);
1297 extern void dhd_dbg_remove(void);
1300 /* Control radio state */
1301 uint dhd_radio_up = 1;
1303 /* Network inteface name */
1304 char iface_name[IFNAMSIZ] = {'\0'};
1305 module_param_string(iface_name, iface_name, IFNAMSIZ, 0);
1307 /* The following are specific to the SDIO dongle */
1309 /* IOCTL response timeout */
1310 int dhd_ioctl_timeout_msec = IOCTL_RESP_TIMEOUT;
1312 /* Idle timeout for backplane clock */
1313 int dhd_idletime = DHD_IDLETIME_TICKS;
1314 module_param(dhd_idletime, int, 0);
1317 uint dhd_poll = FALSE;
1318 module_param(dhd_poll, uint, 0);
1320 /* Use interrupts */
1321 uint dhd_intr = TRUE;
1322 module_param(dhd_intr, uint, 0);
1324 /* SDIO Drive Strength (in milliamps) */
1325 uint dhd_sdiod_drive_strength = 6;
1326 module_param(dhd_sdiod_drive_strength, uint, 0);
1330 extern uint dhd_txbound;
1331 extern uint dhd_rxbound;
1332 module_param(dhd_txbound, uint, 0);
1333 module_param(dhd_rxbound, uint, 0);
1335 /* Deferred transmits */
1336 extern uint dhd_deferred_tx;
1337 module_param(dhd_deferred_tx, uint, 0);
1339 #endif /* BCMSDIO */
1343 /* Echo packet generator (pkts/s) */
1344 uint dhd_pktgen = 0;
1345 module_param(dhd_pktgen, uint, 0);
1347 /* Echo packet len (0 => sawtooth, max 2040) */
1348 uint dhd_pktgen_len = 0;
1349 module_param(dhd_pktgen_len, uint, 0);
1354 /* Allow delayed firmware download for debug purpose */
1355 int allow_delay_fwdl = FALSE;
1356 module_param(allow_delay_fwdl, int, 0);
1358 extern char dhd_version[];
1359 extern char fw_version[];
1361 int dhd_net_bus_devreset(struct net_device *dev, uint8 flag);
1362 static void dhd_net_if_lock_local(dhd_info_t *dhd);
1363 static void dhd_net_if_unlock_local(dhd_info_t *dhd);
1364 static void dhd_suspend_lock(dhd_pub_t *dhdp);
1365 static void dhd_suspend_unlock(dhd_pub_t *dhdp);
1368 void htsf_update(dhd_info_t *dhd, void *data);
1369 tsf_t prev_tsf, cur_tsf;
1371 uint32 dhd_get_htsf(dhd_info_t *dhd, int ifidx);
1372 static int dhd_ioctl_htsf_get(dhd_info_t *dhd, int ifidx);
1373 static void dhd_dump_latency(void);
1374 static void dhd_htsf_addtxts(dhd_pub_t *dhdp, void *pktbuf);
1375 static void dhd_htsf_addrxts(dhd_pub_t *dhdp, void *pktbuf);
1376 static void dhd_dump_htsfhisto(histo_t *his, char *s);
1377 #endif /* WLMEDIA_HTSF */
1379 /* Monitor interface */
1380 int dhd_monitor_init(void *dhd_pub);
1381 int dhd_monitor_uninit(void);
1384 #if defined(WL_WIRELESS_EXT)
1385 struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev);
1386 #endif /* defined(WL_WIRELESS_EXT) */
1388 static void dhd_dpc(ulong data);
1390 extern int dhd_wait_pend8021x(struct net_device *dev);
1391 void dhd_os_wd_timer_extend(void *bus, bool extend);
1395 #error TOE requires BDC
1397 static int dhd_toe_get(dhd_info_t *dhd, int idx, uint32 *toe_ol);
1398 static int dhd_toe_set(dhd_info_t *dhd, int idx, uint32 toe_ol);
1401 static int dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
1402 wl_event_msg_t *event_ptr, void **data_ptr);
1404 #if defined(CONFIG_PM_SLEEP)
1405 static int dhd_pm_callback(struct notifier_block *nfb, unsigned long action, void *ignored)
1407 int ret = NOTIFY_DONE;
1408 bool suspend = FALSE;
1409 dhd_info_t *dhdinfo = (dhd_info_t*)container_of(nfb, struct dhd_info, pm_notifier);
1411 BCM_REFERENCE(dhdinfo);
1414 case PM_HIBERNATION_PREPARE:
1415 case PM_SUSPEND_PREPARE:
1419 case PM_POST_HIBERNATION:
1420 case PM_POST_SUSPEND:
1425 #if defined(SUPPORT_P2P_GO_PS)
1426 #ifdef PROP_TXSTATUS
1428 DHD_OS_WAKE_LOCK_WAIVE(&dhdinfo->pub);
1429 dhd_wlfc_suspend(&dhdinfo->pub);
1430 DHD_OS_WAKE_LOCK_RESTORE(&dhdinfo->pub);
1432 dhd_wlfc_resume(&dhdinfo->pub);
1433 #endif /* PROP_TXSTATUS */
1434 #endif /* defined(SUPPORT_P2P_GO_PS) */
1436 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && (LINUX_VERSION_CODE <= \
1437 KERNEL_VERSION(2, 6, 39))
1438 dhd_mmc_suspend = suspend;
1445 /* to make sure we won't register the same notifier twice, otherwise a loop is likely to be
1446 * created in kernel notifier link list (with 'next' pointing to itself)
1448 static bool dhd_pm_notifier_registered = FALSE;
1450 extern int register_pm_notifier(struct notifier_block *nb);
1451 extern int unregister_pm_notifier(struct notifier_block *nb);
1452 #endif /* CONFIG_PM_SLEEP */
1454 /* Request scheduling of the bus rx frame */
1455 static void dhd_sched_rxf(dhd_pub_t *dhdp, void *skb);
1456 static void dhd_os_rxflock(dhd_pub_t *pub);
1457 static void dhd_os_rxfunlock(dhd_pub_t *pub);
1459 /** priv_link is the link between netdev and the dhdif and dhd_info structs. */
1460 typedef struct dhd_dev_priv {
1461 dhd_info_t * dhd; /* cached pointer to dhd_info in netdevice priv */
1462 dhd_if_t * ifp; /* cached pointer to dhd_if in netdevice priv */
1463 int ifidx; /* interface index */
1466 #define DHD_DEV_PRIV_SIZE (sizeof(dhd_dev_priv_t))
1467 #define DHD_DEV_PRIV(dev) ((dhd_dev_priv_t *)DEV_PRIV(dev))
1468 #define DHD_DEV_INFO(dev) (((dhd_dev_priv_t *)DEV_PRIV(dev))->dhd)
1469 #define DHD_DEV_IFP(dev) (((dhd_dev_priv_t *)DEV_PRIV(dev))->ifp)
1470 #define DHD_DEV_IFIDX(dev) (((dhd_dev_priv_t *)DEV_PRIV(dev))->ifidx)
1472 /** Clear the dhd net_device's private structure. */
1474 dhd_dev_priv_clear(struct net_device * dev)
1476 dhd_dev_priv_t * dev_priv;
1477 ASSERT(dev != (struct net_device *)NULL);
1478 dev_priv = DHD_DEV_PRIV(dev);
1479 dev_priv->dhd = (dhd_info_t *)NULL;
1480 dev_priv->ifp = (dhd_if_t *)NULL;
1481 dev_priv->ifidx = DHD_BAD_IF;
1484 /** Setup the dhd net_device's private structure. */
1486 dhd_dev_priv_save(struct net_device * dev, dhd_info_t * dhd, dhd_if_t * ifp,
1489 dhd_dev_priv_t * dev_priv;
1490 ASSERT(dev != (struct net_device *)NULL);
1491 dev_priv = DHD_DEV_PRIV(dev);
1492 dev_priv->dhd = dhd;
1493 dev_priv->ifp = ifp;
1494 dev_priv->ifidx = ifidx;
1497 #ifdef PCIE_FULL_DONGLE
1499 /** Dummy objects are defined with state representing bad|down.
1500 * Performance gains from reducing branch conditionals, instruction parallelism,
1501 * dual issue, reducing load shadows, avail of larger pipelines.
1502 * Use DHD_XXX_NULL instead of (dhd_xxx_t *)NULL, whenever an object pointer
1503 * is accessed via the dhd_sta_t.
1506 /* Dummy dhd_info object */
1507 dhd_info_t dhd_info_null = {
1508 #if defined(BCM_GMAC3)
1512 .info = &dhd_info_null,
1513 #ifdef DHDTCPACK_SUPPRESS
1514 .tcpack_sup_mode = TCPACK_SUP_REPLACE,
1515 #endif /* DHDTCPACK_SUPPRESS */
1517 .busstate = DHD_BUS_DOWN
1520 #define DHD_INFO_NULL (&dhd_info_null)
1521 #define DHD_PUB_NULL (&dhd_info_null.pub)
1523 /* Dummy netdevice object */
1524 struct net_device dhd_net_dev_null = {
1525 .reg_state = NETREG_UNREGISTERED
1527 #define DHD_NET_DEV_NULL (&dhd_net_dev_null)
1529 /* Dummy dhd_if object */
1530 dhd_if_t dhd_if_null = {
1531 #if defined(BCM_GMAC3)
1535 .wmf = { .wmf_enable = TRUE },
1537 .info = DHD_INFO_NULL,
1538 .net = DHD_NET_DEV_NULL,
1541 #define DHD_IF_NULL (&dhd_if_null)
1543 #define DHD_STA_NULL ((dhd_sta_t *)NULL)
1545 /** Interface STA list management. */
1547 /** Fetch the dhd_if object, given the interface index in the dhd. */
1548 static inline dhd_if_t *dhd_get_ifp(dhd_pub_t *dhdp, uint32 ifidx);
1550 /** Alloc/Free a dhd_sta object from the dhd instances' sta_pool. */
1551 static void dhd_sta_free(dhd_pub_t *pub, dhd_sta_t *sta);
1552 static dhd_sta_t * dhd_sta_alloc(dhd_pub_t * dhdp);
1554 /* Delete a dhd_sta or flush all dhd_sta in an interface's sta_list. */
1555 static void dhd_if_del_sta_list(dhd_if_t * ifp);
1556 static void dhd_if_flush_sta(dhd_if_t * ifp);
1558 /* Construct/Destruct a sta pool. */
1559 static int dhd_sta_pool_init(dhd_pub_t *dhdp, int max_sta);
1560 static void dhd_sta_pool_fini(dhd_pub_t *dhdp, int max_sta);
1561 /* Clear the pool of dhd_sta_t objects for built-in type driver */
1562 static void dhd_sta_pool_clear(dhd_pub_t *dhdp, int max_sta);
1565 /* Return interface pointer */
1566 static inline dhd_if_t *dhd_get_ifp(dhd_pub_t *dhdp, uint32 ifidx)
1568 ASSERT(ifidx < DHD_MAX_IFS);
1570 if (ifidx >= DHD_MAX_IFS)
1573 return dhdp->info->iflist[ifidx];
1576 /** Reset a dhd_sta object and free into the dhd pool. */
1578 dhd_sta_free(dhd_pub_t * dhdp, dhd_sta_t * sta)
1582 ASSERT((sta != DHD_STA_NULL) && (sta->idx != ID16_INVALID));
1584 ASSERT((dhdp->staid_allocator != NULL) && (dhdp->sta_pool != NULL));
1587 * Flush and free all packets in all flowring's queues belonging to sta.
1588 * Packets in flow ring will be flushed later.
1590 for (prio = 0; prio < (int)NUMPRIO; prio++) {
1591 uint16 flowid = sta->flowid[prio];
1593 if (flowid != FLOWID_INVALID) {
1594 unsigned long flags;
1595 flow_queue_t * queue = dhd_flow_queue(dhdp, flowid);
1596 flow_ring_node_t * flow_ring_node;
1598 #ifdef DHDTCPACK_SUPPRESS
1599 /* Clean tcp_ack_info_tbl in order to prevent access to flushed pkt,
1600 * when there is a newly coming packet from network stack.
1602 dhd_tcpack_info_tbl_clean(dhdp);
1603 #endif /* DHDTCPACK_SUPPRESS */
1605 flow_ring_node = dhd_flow_ring_node(dhdp, flowid);
1606 DHD_FLOWRING_LOCK(flow_ring_node->lock, flags);
1607 flow_ring_node->status = FLOW_RING_STATUS_STA_FREEING;
1609 if (!DHD_FLOW_QUEUE_EMPTY(queue)) {
1611 while ((pkt = dhd_flow_queue_dequeue(dhdp, queue)) != NULL) {
1612 PKTFREE(dhdp->osh, pkt, TRUE);
1616 DHD_FLOWRING_UNLOCK(flow_ring_node->lock, flags);
1617 ASSERT(DHD_FLOW_QUEUE_EMPTY(queue));
1620 sta->flowid[prio] = FLOWID_INVALID;
1623 id16_map_free(dhdp->staid_allocator, sta->idx);
1624 DHD_CUMM_CTR_INIT(&sta->cumm_ctr);
1625 sta->ifp = DHD_IF_NULL; /* dummy dhd_if object */
1626 sta->ifidx = DHD_BAD_IF;
1627 bzero(sta->ea.octet, ETHER_ADDR_LEN);
1628 INIT_LIST_HEAD(&sta->list);
1629 sta->idx = ID16_INVALID; /* implying free */
1632 /** Allocate a dhd_sta object from the dhd pool. */
1634 dhd_sta_alloc(dhd_pub_t * dhdp)
1638 dhd_sta_pool_t * sta_pool;
1640 ASSERT((dhdp->staid_allocator != NULL) && (dhdp->sta_pool != NULL));
1642 idx = id16_map_alloc(dhdp->staid_allocator);
1643 if (idx == ID16_INVALID) {
1644 DHD_ERROR(("%s: cannot get free staid\n", __FUNCTION__));
1645 return DHD_STA_NULL;
1648 sta_pool = (dhd_sta_pool_t *)(dhdp->sta_pool);
1649 sta = &sta_pool[idx];
1651 ASSERT((sta->idx == ID16_INVALID) &&
1652 (sta->ifp == DHD_IF_NULL) && (sta->ifidx == DHD_BAD_IF));
1654 DHD_CUMM_CTR_INIT(&sta->cumm_ctr);
1656 sta->idx = idx; /* implying allocated */
1661 /** Delete all STAs in an interface's STA list. */
1663 dhd_if_del_sta_list(dhd_if_t *ifp)
1665 dhd_sta_t *sta, *next;
1666 unsigned long flags;
1668 DHD_IF_STA_LIST_LOCK(ifp, flags);
1670 list_for_each_entry_safe(sta, next, &ifp->sta_list, list) {
1671 #if defined(BCM_GMAC3)
1673 /* Remove sta from WOFA forwarder. */
1674 fwder_deassoc(ifp->fwdh, (uint16 *)(sta->ea.octet), (wofa_t)sta);
1676 #endif /* BCM_GMAC3 */
1677 list_del(&sta->list);
1678 dhd_sta_free(&ifp->info->pub, sta);
1681 DHD_IF_STA_LIST_UNLOCK(ifp, flags);
1686 /** Router/GMAC3: Flush all station entries in the forwarder's WOFA database. */
1688 dhd_if_flush_sta(dhd_if_t * ifp)
1690 #if defined(BCM_GMAC3)
1692 if (ifp && (ifp->fwdh != FWDER_NULL)) {
1693 dhd_sta_t *sta, *next;
1694 unsigned long flags;
1696 DHD_IF_STA_LIST_LOCK(ifp, flags);
1698 list_for_each_entry_safe(sta, next, &ifp->sta_list, list) {
1699 /* Remove any sta entry from WOFA forwarder. */
1700 fwder_flush(ifp->fwdh, (wofa_t)sta);
1703 DHD_IF_STA_LIST_UNLOCK(ifp, flags);
1705 #endif /* BCM_GMAC3 */
1708 /** Construct a pool of dhd_sta_t objects to be used by interfaces. */
1710 dhd_sta_pool_init(dhd_pub_t *dhdp, int max_sta)
1712 int idx, prio, sta_pool_memsz;
1714 dhd_sta_pool_t * sta_pool;
1715 void * staid_allocator;
1717 ASSERT(dhdp != (dhd_pub_t *)NULL);
1718 ASSERT((dhdp->staid_allocator == NULL) && (dhdp->sta_pool == NULL));
1720 /* dhd_sta objects per radio are managed in a table. id#0 reserved. */
1721 staid_allocator = id16_map_init(dhdp->osh, max_sta, 1);
1722 if (staid_allocator == NULL) {
1723 DHD_ERROR(("%s: sta id allocator init failure\n", __FUNCTION__));
1727 /* Pre allocate a pool of dhd_sta objects (one extra). */
1728 sta_pool_memsz = ((max_sta + 1) * sizeof(dhd_sta_t)); /* skip idx 0 */
1729 sta_pool = (dhd_sta_pool_t *)MALLOC(dhdp->osh, sta_pool_memsz);
1730 if (sta_pool == NULL) {
1731 DHD_ERROR(("%s: sta table alloc failure\n", __FUNCTION__));
1732 id16_map_fini(dhdp->osh, staid_allocator);
1736 dhdp->sta_pool = sta_pool;
1737 dhdp->staid_allocator = staid_allocator;
1739 /* Initialize all sta(s) for the pre-allocated free pool. */
1740 bzero((uchar *)sta_pool, sta_pool_memsz);
1741 for (idx = max_sta; idx >= 1; idx--) { /* skip sta_pool[0] */
1742 sta = &sta_pool[idx];
1743 sta->idx = id16_map_alloc(staid_allocator);
1744 ASSERT(sta->idx <= max_sta);
1746 /* Now place them into the pre-allocated free pool. */
1747 for (idx = 1; idx <= max_sta; idx++) {
1748 sta = &sta_pool[idx];
1749 for (prio = 0; prio < (int)NUMPRIO; prio++) {
1750 sta->flowid[prio] = FLOWID_INVALID; /* Flow rings do not exist */
1752 dhd_sta_free(dhdp, sta);
1758 /** Destruct the pool of dhd_sta_t objects.
1759 * Caller must ensure that no STA objects are currently associated with an if.
1762 dhd_sta_pool_fini(dhd_pub_t *dhdp, int max_sta)
1764 dhd_sta_pool_t * sta_pool = (dhd_sta_pool_t *)dhdp->sta_pool;
1768 int sta_pool_memsz = ((max_sta + 1) * sizeof(dhd_sta_t));
1769 for (idx = 1; idx <= max_sta; idx++) {
1770 ASSERT(sta_pool[idx].ifp == DHD_IF_NULL);
1771 ASSERT(sta_pool[idx].idx == ID16_INVALID);
1773 MFREE(dhdp->osh, dhdp->sta_pool, sta_pool_memsz);
1774 dhdp->sta_pool = NULL;
1777 id16_map_fini(dhdp->osh, dhdp->staid_allocator);
1778 dhdp->staid_allocator = NULL;
1781 /* Clear the pool of dhd_sta_t objects for built-in type driver */
1783 dhd_sta_pool_clear(dhd_pub_t *dhdp, int max_sta)
1785 int idx, prio, sta_pool_memsz;
1787 dhd_sta_pool_t * sta_pool;
1788 void *staid_allocator;
1791 DHD_ERROR(("%s: dhdp is NULL\n", __FUNCTION__));
1795 sta_pool = (dhd_sta_pool_t *)dhdp->sta_pool;
1796 staid_allocator = dhdp->staid_allocator;
1799 DHD_ERROR(("%s: sta_pool is NULL\n", __FUNCTION__));
1803 if (!staid_allocator) {
1804 DHD_ERROR(("%s: staid_allocator is NULL\n", __FUNCTION__));
1808 /* clear free pool */
1809 sta_pool_memsz = ((max_sta + 1) * sizeof(dhd_sta_t));
1810 bzero((uchar *)sta_pool, sta_pool_memsz);
1812 /* dhd_sta objects per radio are managed in a table. id#0 reserved. */
1813 id16_map_clear(staid_allocator, max_sta, 1);
1815 /* Initialize all sta(s) for the pre-allocated free pool. */
1816 for (idx = max_sta; idx >= 1; idx--) { /* skip sta_pool[0] */
1817 sta = &sta_pool[idx];
1818 sta->idx = id16_map_alloc(staid_allocator);
1819 ASSERT(sta->idx <= max_sta);
1821 /* Now place them into the pre-allocated free pool. */
1822 for (idx = 1; idx <= max_sta; idx++) {
1823 sta = &sta_pool[idx];
1824 for (prio = 0; prio < (int)NUMPRIO; prio++) {
1825 sta->flowid[prio] = FLOWID_INVALID; /* Flow rings do not exist */
1827 dhd_sta_free(dhdp, sta);
1831 /** Find STA with MAC address ea in an interface's STA list. */
1833 dhd_find_sta(void *pub, int ifidx, void *ea)
1837 unsigned long flags;
1840 ifp = dhd_get_ifp((dhd_pub_t *)pub, ifidx);
1842 return DHD_STA_NULL;
1844 DHD_IF_STA_LIST_LOCK(ifp, flags);
1846 list_for_each_entry(sta, &ifp->sta_list, list) {
1847 if (!memcmp(sta->ea.octet, ea, ETHER_ADDR_LEN)) {
1848 DHD_IF_STA_LIST_UNLOCK(ifp, flags);
1853 DHD_IF_STA_LIST_UNLOCK(ifp, flags);
1855 return DHD_STA_NULL;
1858 /** Add STA into the interface's STA list. */
1860 dhd_add_sta(void *pub, int ifidx, void *ea)
1864 unsigned long flags;
1867 ifp = dhd_get_ifp((dhd_pub_t *)pub, ifidx);
1869 return DHD_STA_NULL;
1871 sta = dhd_sta_alloc((dhd_pub_t *)pub);
1872 if (sta == DHD_STA_NULL) {
1873 DHD_ERROR(("%s: Alloc failed\n", __FUNCTION__));
1874 return DHD_STA_NULL;
1877 memcpy(sta->ea.octet, ea, ETHER_ADDR_LEN);
1879 /* link the sta and the dhd interface */
1882 INIT_LIST_HEAD(&sta->list);
1884 DHD_IF_STA_LIST_LOCK(ifp, flags);
1886 list_add_tail(&sta->list, &ifp->sta_list);
1888 #if defined(BCM_GMAC3)
1890 ASSERT(ISALIGNED(ea, 2));
1891 /* Add sta to WOFA forwarder. */
1892 fwder_reassoc(ifp->fwdh, (uint16 *)ea, (wofa_t)sta);
1894 #endif /* BCM_GMAC3 */
1896 DHD_IF_STA_LIST_UNLOCK(ifp, flags);
1901 /** Delete STA from the interface's STA list. */
1903 dhd_del_sta(void *pub, int ifidx, void *ea)
1905 dhd_sta_t *sta, *next;
1907 unsigned long flags;
1910 ifp = dhd_get_ifp((dhd_pub_t *)pub, ifidx);
1914 DHD_IF_STA_LIST_LOCK(ifp, flags);
1916 list_for_each_entry_safe(sta, next, &ifp->sta_list, list) {
1917 if (!memcmp(sta->ea.octet, ea, ETHER_ADDR_LEN)) {
1918 #if defined(BCM_GMAC3)
1919 if (ifp->fwdh) { /* Found a sta, remove from WOFA forwarder. */
1920 ASSERT(ISALIGNED(ea, 2));
1921 fwder_deassoc(ifp->fwdh, (uint16 *)ea, (wofa_t)sta);
1923 #endif /* BCM_GMAC3 */
1924 list_del(&sta->list);
1925 dhd_sta_free(&ifp->info->pub, sta);
1929 DHD_IF_STA_LIST_UNLOCK(ifp, flags);
1930 #ifdef DHD_L2_FILTER
1931 if (ifp->parp_enable) {
1932 /* clear Proxy ARP cache of specific Ethernet Address */
1933 bcm_l2_filter_arp_table_update(((dhd_pub_t*)pub)->osh, ifp->phnd_arp_table, FALSE,
1934 ea, FALSE, ((dhd_pub_t*)pub)->tickcnt);
1936 #endif /* DHD_L2_FILTER */
1940 /** Add STA if it doesn't exist. Not reentrant. */
1942 dhd_findadd_sta(void *pub, int ifidx, void *ea)
1946 sta = dhd_find_sta(pub, ifidx, ea);
1950 sta = dhd_add_sta(pub, ifidx, ea);
1956 #if defined(DHD_IGMP_UCQUERY) || defined(DHD_UCAST_UPNP)
1957 #if !defined(BCM_GMAC3)
1958 static struct list_head *
1959 dhd_sta_list_snapshot(dhd_info_t *dhd, dhd_if_t *ifp, struct list_head *snapshot_list)
1961 unsigned long flags;
1962 dhd_sta_t *sta, *snapshot;
1964 INIT_LIST_HEAD(snapshot_list);
1966 DHD_IF_STA_LIST_LOCK(ifp, flags);
1968 list_for_each_entry(sta, &ifp->sta_list, list) {
1969 /* allocate one and add to snapshot */
1970 snapshot = (dhd_sta_t *)MALLOC(dhd->pub.osh, sizeof(dhd_sta_t));
1971 if (snapshot == NULL) {
1972 DHD_ERROR(("%s: Cannot allocate memory\n", __FUNCTION__));
1976 memcpy(snapshot->ea.octet, sta->ea.octet, ETHER_ADDR_LEN);
1978 INIT_LIST_HEAD(&snapshot->list);
1979 list_add_tail(&snapshot->list, snapshot_list);
1982 DHD_IF_STA_LIST_UNLOCK(ifp, flags);
1984 return snapshot_list;
1988 dhd_sta_list_snapshot_free(dhd_info_t *dhd, struct list_head *snapshot_list)
1990 dhd_sta_t *sta, *next;
1992 list_for_each_entry_safe(sta, next, snapshot_list, list) {
1993 list_del(&sta->list);
1994 MFREE(dhd->pub.osh, sta, sizeof(dhd_sta_t));
1997 #endif /* !BCM_GMAC3 */
1998 #endif /* DHD_IGMP_UCQUERY || DHD_UCAST_UPNP */
2001 static inline void dhd_if_flush_sta(dhd_if_t * ifp) { }
2002 static inline void dhd_if_del_sta_list(dhd_if_t *ifp) {}
2003 static inline int dhd_sta_pool_init(dhd_pub_t *dhdp, int max_sta) { return BCME_OK; }
2004 static inline void dhd_sta_pool_fini(dhd_pub_t *dhdp, int max_sta) {}
2005 static inline void dhd_sta_pool_clear(dhd_pub_t *dhdp, int max_sta) {}
2006 dhd_sta_t *dhd_findadd_sta(void *pub, int ifidx, void *ea) { return NULL; }
2007 void dhd_del_sta(void *pub, int ifidx, void *ea) {}
2008 #endif /* PCIE_FULL_DONGLE */
2013 #if defined(DHD_LB_TXC) || defined(DHD_LB_RXC)
2015 * dhd_tasklet_schedule - Function that runs in IPI context of the destination
2016 * CPU and schedules a tasklet.
2017 * @tasklet: opaque pointer to the tasklet
2020 dhd_tasklet_schedule(void *tasklet)
2022 tasklet_schedule((struct tasklet_struct *)tasklet);
2026 * dhd_tasklet_schedule_on - Executes the passed takslet in a given CPU
2027 * @tasklet: tasklet to be scheduled
2028 * @on_cpu: cpu core id
2030 * If the requested cpu is online, then an IPI is sent to this cpu via the
2031 * smp_call_function_single with no wait and the tasklet_schedule function
2032 * will be invoked to schedule the specified tasklet on the requested CPU.
2035 dhd_tasklet_schedule_on(struct tasklet_struct *tasklet, int on_cpu)
2038 smp_call_function_single(on_cpu,
2039 dhd_tasklet_schedule, (void *)tasklet, wait);
2041 #endif /* DHD_LB_TXC || DHD_LB_RXC */
2044 #if defined(DHD_LB_TXC)
2046 * dhd_lb_tx_compl_dispatch - load balance by dispatching the tx_compl_tasklet
2047 * on another cpu. The tx_compl_tasklet will take care of DMA unmapping and
2048 * freeing the packets placed in the tx_compl workq
2051 dhd_lb_tx_compl_dispatch(dhd_pub_t *dhdp)
2053 dhd_info_t *dhd = dhdp->info;
2054 int curr_cpu, on_cpu;
2056 if (dhd->rx_napi_netdev == NULL) {
2057 DHD_ERROR(("%s: dhd->rx_napi_netdev is NULL\n", __FUNCTION__));
2061 DHD_LB_STATS_INCR(dhd->txc_sched_cnt);
2063 * If the destination CPU is NOT online or is same as current CPU
2064 * no need to schedule the work
2066 curr_cpu = get_cpu();
2069 on_cpu = atomic_read(&dhd->tx_compl_cpu);
2071 if ((on_cpu == curr_cpu) || (!cpu_online(on_cpu))) {
2072 dhd_tasklet_schedule(&dhd->tx_compl_tasklet);
2074 schedule_work(&dhd->tx_compl_dispatcher_work);
2078 static void dhd_tx_compl_dispatcher_fn(struct work_struct * work)
2080 struct dhd_info *dhd =
2081 container_of(work, struct dhd_info, tx_compl_dispatcher_work);
2085 cpu = atomic_read(&dhd->tx_compl_cpu);
2086 if (!cpu_online(cpu))
2087 dhd_tasklet_schedule(&dhd->tx_compl_tasklet);
2089 dhd_tasklet_schedule_on(&dhd->tx_compl_tasklet, cpu);
2093 #endif /* DHD_LB_TXC */
2096 #if defined(DHD_LB_RXC)
2098 * dhd_lb_rx_compl_dispatch - load balance by dispatching the rx_compl_tasklet
2099 * on another cpu. The rx_compl_tasklet will take care of reposting rx buffers
2100 * in the H2D RxBuffer Post common ring, by using the recycled pktids that were
2101 * placed in the rx_compl workq.
2103 * @dhdp: pointer to dhd_pub object
2106 dhd_lb_rx_compl_dispatch(dhd_pub_t *dhdp)
2108 dhd_info_t *dhd = dhdp->info;
2109 int curr_cpu, on_cpu;
2111 if (dhd->rx_napi_netdev == NULL) {
2112 DHD_ERROR(("%s: dhd->rx_napi_netdev is NULL\n", __FUNCTION__));
2116 DHD_LB_STATS_INCR(dhd->rxc_sched_cnt);
2118 * If the destination CPU is NOT online or is same as current CPU
2119 * no need to schedule the work
2121 curr_cpu = get_cpu();
2124 on_cpu = atomic_read(&dhd->rx_compl_cpu);
2126 if ((on_cpu == curr_cpu) || (!cpu_online(on_cpu))) {
2127 dhd_tasklet_schedule(&dhd->rx_compl_tasklet);
2129 schedule_work(&dhd->rx_compl_dispatcher_work);
2133 static void dhd_rx_compl_dispatcher_fn(struct work_struct * work)
2135 struct dhd_info *dhd =
2136 container_of(work, struct dhd_info, rx_compl_dispatcher_work);
2140 cpu = atomic_read(&dhd->tx_compl_cpu);
2141 if (!cpu_online(cpu))
2142 dhd_tasklet_schedule(&dhd->rx_compl_tasklet);
2144 dhd_tasklet_schedule_on(&dhd->rx_compl_tasklet, cpu);
2148 #endif /* DHD_LB_RXC */
2151 #if defined(DHD_LB_RXP)
2153 * dhd_napi_poll - Load balance napi poll function to process received
2154 * packets and send up the network stack using netif_receive_skb()
2156 * @napi: napi object in which context this poll function is invoked
2157 * @budget: number of packets to be processed.
2159 * Fetch the dhd_info given the rx_napi_struct. Move all packets from the
2160 * rx_napi_queue into a local rx_process_queue (lock and queue move and unlock).
2161 * Dequeue each packet from head of rx_process_queue, fetch the ifid from the
2162 * packet tag and sendup.
2165 dhd_napi_poll(struct napi_struct *napi, int budget)
2168 const int pkt_count = 1;
2170 struct sk_buff * skb;
2171 unsigned long flags;
2172 struct dhd_info *dhd;
2174 struct sk_buff_head rx_process_queue;
2176 dhd = container_of(napi, struct dhd_info, rx_napi_struct);
2177 DHD_INFO(("%s napi_queue<%d> budget<%d>\n",
2178 __FUNCTION__, skb_queue_len(&dhd->rx_napi_queue), budget));
2180 __skb_queue_head_init(&rx_process_queue);
2182 /* extract the entire rx_napi_queue into local rx_process_queue */
2183 spin_lock_irqsave(&dhd->rx_napi_queue.lock, flags);
2184 skb_queue_splice_tail_init(&dhd->rx_napi_queue, &rx_process_queue);
2185 spin_unlock_irqrestore(&dhd->rx_napi_queue.lock, flags);
2187 while ((skb = __skb_dequeue(&rx_process_queue)) != NULL) {
2188 OSL_PREFETCH(skb->data);
2190 ifid = DHD_PKTTAG_IFID((dhd_pkttag_fr_t *)PKTTAG(skb));
2192 DHD_INFO(("%s dhd_rx_frame pkt<%p> ifid<%d>\n",
2193 __FUNCTION__, skb, ifid));
2195 dhd_rx_frame(&dhd->pub, ifid, skb, pkt_count, chan);
2199 DHD_LB_STATS_UPDATE_NAPI_HISTO(&dhd->pub, processed);
2201 DHD_INFO(("%s processed %d\n", __FUNCTION__, processed));
2202 napi_complete(napi);
2208 * dhd_napi_schedule - Place the napi struct into the current cpus softnet napi
2209 * poll list. This function may be invoked via the smp_call_function_single
2210 * from a remote CPU.
2212 * This function will essentially invoke __raise_softirq_irqoff(NET_RX_SOFTIRQ)
2213 * after the napi_struct is added to the softnet data's poll_list
2215 * @info: pointer to a dhd_info struct
2218 dhd_napi_schedule(void *info)
2220 dhd_info_t *dhd = (dhd_info_t *)info;
2222 DHD_INFO(("%s rx_napi_struct<%p> on cpu<%d>\n",
2223 __FUNCTION__, &dhd->rx_napi_struct, atomic_read(&dhd->rx_napi_cpu)));
2225 /* add napi_struct to softnet data poll list and raise NET_RX_SOFTIRQ */
2226 if (napi_schedule_prep(&dhd->rx_napi_struct)) {
2227 __napi_schedule(&dhd->rx_napi_struct);
2228 DHD_LB_STATS_PERCPU_ARR_INCR(dhd->napi_percpu_run_cnt);
2232 * If the rx_napi_struct was already running, then we let it complete
2233 * processing all its packets. The rx_napi_struct may only run on one
2234 * core at a time, to avoid out-of-order handling.
2239 * dhd_napi_schedule_on - API to schedule on a desired CPU core a NET_RX_SOFTIRQ
2240 * action after placing the dhd's rx_process napi object in the the remote CPU's
2241 * softnet data's poll_list.
2243 * @dhd: dhd_info which has the rx_process napi object
2244 * @on_cpu: desired remote CPU id
2247 dhd_napi_schedule_on(dhd_info_t *dhd, int on_cpu)
2249 int wait = 0; /* asynchronous IPI */
2251 DHD_INFO(("%s dhd<%p> napi<%p> on_cpu<%d>\n",
2252 __FUNCTION__, dhd, &dhd->rx_napi_struct, on_cpu));
2254 if (smp_call_function_single(on_cpu, dhd_napi_schedule, dhd, wait)) {
2255 DHD_ERROR(("%s smp_call_function_single on_cpu<%d> failed\n",
2256 __FUNCTION__, on_cpu));
2259 DHD_LB_STATS_INCR(dhd->napi_sched_cnt);
2265 * Call get_online_cpus/put_online_cpus around dhd_napi_schedule_on
2266 * Why should we do this?
2267 * The candidacy algorithm is run from the call back function
2268 * registered to CPU hotplug notifier. This call back happens from Worker
2269 * context. The dhd_napi_schedule_on is also from worker context.
2270 * Note that both of this can run on two different CPUs at the same time.
2271 * So we can possibly have a window where a given CPUn is being brought
2272 * down from CPUm while we try to run a function on CPUn.
2273 * To prevent this its better have the whole code to execute an SMP
2274 * function under get_online_cpus.
2275 * This function call ensures that hotplug mechanism does not kick-in
2276 * until we are done dealing with online CPUs
2277 * If the hotplug worker is already running, no worries because the
2278 * candidacy algo would then reflect the same in dhd->rx_napi_cpu.
2280 * The below mentioned code structure is proposed in
2281 * https://www.kernel.org/doc/Documentation/cpu-hotplug.txt
2283 * Q: I need to ensure that a particular cpu is not removed when there is some
2284 * work specific to this cpu is in progress
2286 * According to the documentation calling get_online_cpus is NOT required, if
2287 * we are running from tasklet context. Since dhd_rx_napi_dispatcher_fn can
2288 * run from Work Queue context we have to call these functions
2290 static void dhd_rx_napi_dispatcher_fn(struct work_struct * work)
2292 struct dhd_info *dhd =
2293 container_of(work, struct dhd_info, rx_napi_dispatcher_work);
2297 cpu = atomic_read(&dhd->rx_napi_cpu);
2298 if (!cpu_online(cpu))
2299 dhd_napi_schedule(dhd);
2301 dhd_napi_schedule_on(dhd, cpu);
2306 * dhd_lb_rx_napi_dispatch - load balance by dispatching the rx_napi_struct
2307 * to run on another CPU. The rx_napi_struct's poll function will retrieve all
2308 * the packets enqueued into the rx_napi_queue and sendup.
2309 * The producer's rx packet queue is appended to the rx_napi_queue before
2310 * dispatching the rx_napi_struct.
2313 dhd_lb_rx_napi_dispatch(dhd_pub_t *dhdp)
2315 unsigned long flags;
2316 dhd_info_t *dhd = dhdp->info;
2320 if (dhd->rx_napi_netdev == NULL) {
2321 DHD_ERROR(("%s: dhd->rx_napi_netdev is NULL\n", __FUNCTION__));
2325 DHD_INFO(("%s append napi_queue<%d> pend_queue<%d>\n", __FUNCTION__,
2326 skb_queue_len(&dhd->rx_napi_queue), skb_queue_len(&dhd->rx_pend_queue)));
2328 /* append the producer's queue of packets to the napi's rx process queue */
2329 spin_lock_irqsave(&dhd->rx_napi_queue.lock, flags);
2330 skb_queue_splice_tail_init(&dhd->rx_pend_queue, &dhd->rx_napi_queue);
2331 spin_unlock_irqrestore(&dhd->rx_napi_queue.lock, flags);
2334 * If the destination CPU is NOT online or is same as current CPU
2335 * no need to schedule the work
2337 curr_cpu = get_cpu();
2340 on_cpu = atomic_read(&dhd->rx_napi_cpu);
2342 if ((on_cpu == curr_cpu) || (!cpu_online(on_cpu))) {
2343 dhd_napi_schedule(dhd);
2345 schedule_work(&dhd->rx_napi_dispatcher_work);
2350 * dhd_lb_rx_pkt_enqueue - Enqueue the packet into the producer's queue
2353 dhd_lb_rx_pkt_enqueue(dhd_pub_t *dhdp, void *pkt, int ifidx)
2355 dhd_info_t *dhd = dhdp->info;
2357 DHD_INFO(("%s enqueue pkt<%p> ifidx<%d> pend_queue<%d>\n", __FUNCTION__,
2358 pkt, ifidx, skb_queue_len(&dhd->rx_pend_queue)));
2359 DHD_PKTTAG_SET_IFID((dhd_pkttag_fr_t *)PKTTAG(pkt), ifidx);
2360 __skb_queue_tail(&dhd->rx_pend_queue, pkt);
2362 #endif /* DHD_LB_RXP */
2366 static void dhd_memdump_work_handler(struct work_struct * work)
2368 struct dhd_info *dhd =
2369 container_of(work, struct dhd_info, dhd_memdump_work.work);
2373 dhd_prot_collect_memdump(&dhd->pub);
2378 /** Returns dhd iflist index corresponding the the bssidx provided by apps */
2379 int dhd_bssidx2idx(dhd_pub_t *dhdp, uint32 bssidx)
2382 dhd_info_t *dhd = dhdp->info;
2385 ASSERT(bssidx < DHD_MAX_IFS);
2388 for (i = 0; i < DHD_MAX_IFS; i++) {
2389 ifp = dhd->iflist[i];
2390 if (ifp && (ifp->bssidx == bssidx)) {
2391 DHD_TRACE(("Index manipulated for %s from %d to %d\n",
2392 ifp->name, bssidx, i));
2399 static inline int dhd_rxf_enqueue(dhd_pub_t *dhdp, void* skb)
2405 DHD_ERROR(("dhd_rxf_enqueue: NULL skb!!!\n"));
2409 dhd_os_rxflock(dhdp);
2410 store_idx = dhdp->store_idx;
2411 sent_idx = dhdp->sent_idx;
2412 if (dhdp->skbbuf[store_idx] != NULL) {
2413 /* Make sure the previous packets are processed */
2414 dhd_os_rxfunlock(dhdp);
2415 #ifdef RXF_DEQUEUE_ON_BUSY
2416 DHD_TRACE(("dhd_rxf_enqueue: pktbuf not consumed %p, store idx %d sent idx %d\n",
2417 skb, store_idx, sent_idx));
2419 #else /* RXF_DEQUEUE_ON_BUSY */
2420 DHD_ERROR(("dhd_rxf_enqueue: pktbuf not consumed %p, store idx %d sent idx %d\n",
2421 skb, store_idx, sent_idx));
2422 /* removed msleep here, should use wait_event_timeout if we
2423 * want to give rx frame thread a chance to run
2425 #if defined(WAIT_DEQUEUE)
2429 #endif /* RXF_DEQUEUE_ON_BUSY */
2431 DHD_TRACE(("dhd_rxf_enqueue: Store SKB %p. idx %d -> %d\n",
2432 skb, store_idx, (store_idx + 1) & (MAXSKBPEND - 1)));
2433 dhdp->skbbuf[store_idx] = skb;
2434 dhdp->store_idx = (store_idx + 1) & (MAXSKBPEND - 1);
2435 dhd_os_rxfunlock(dhdp);
2440 static inline void* dhd_rxf_dequeue(dhd_pub_t *dhdp)
2446 dhd_os_rxflock(dhdp);
2448 store_idx = dhdp->store_idx;
2449 sent_idx = dhdp->sent_idx;
2450 skb = dhdp->skbbuf[sent_idx];
2453 dhd_os_rxfunlock(dhdp);
2454 DHD_ERROR(("dhd_rxf_dequeue: Dequeued packet is NULL, store idx %d sent idx %d\n",
2455 store_idx, sent_idx));
2459 dhdp->skbbuf[sent_idx] = NULL;
2460 dhdp->sent_idx = (sent_idx + 1) & (MAXSKBPEND - 1);
2462 DHD_TRACE(("dhd_rxf_dequeue: netif_rx_ni(%p), sent idx %d\n",
2465 dhd_os_rxfunlock(dhdp);
2470 int dhd_process_cid_mac(dhd_pub_t *dhdp, bool prepost)
2472 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
2474 if (prepost) { /* pre process */
2475 dhd_read_macaddr(dhd);
2476 } else { /* post process */
2477 dhd_write_macaddr(&dhd->pub.mac);
2483 #if defined(PKT_FILTER_SUPPORT) && !defined(GAN_LITE_NAT_KEEPALIVE_FILTER)
2485 _turn_on_arp_filter(dhd_pub_t *dhd, int op_mode)
2487 bool _apply = FALSE;
2488 /* In case of IBSS mode, apply arp pkt filter */
2489 if (op_mode & DHD_FLAG_IBSS_MODE) {
2493 /* In case of P2P GO or GC, apply pkt filter to pass arp pkt to host */
2494 if ((dhd->arp_version == 1) &&
2495 (op_mode & (DHD_FLAG_P2P_GC_MODE | DHD_FLAG_P2P_GO_MODE))) {
2503 #endif /* PKT_FILTER_SUPPORT && !GAN_LITE_NAT_KEEPALIVE_FILTER */
2505 void dhd_set_packet_filter(dhd_pub_t *dhd)
2507 #ifdef PKT_FILTER_SUPPORT
2510 DHD_TRACE(("%s: enter\n", __FUNCTION__));
2511 if (dhd_pkt_filter_enable) {
2512 for (i = 0; i < dhd->pktfilter_count; i++) {
2513 dhd_pktfilter_offload_set(dhd, dhd->pktfilter[i]);
2516 #endif /* PKT_FILTER_SUPPORT */
2519 void dhd_enable_packet_filter(int value, dhd_pub_t *dhd)
2521 #ifdef PKT_FILTER_SUPPORT
2524 DHD_ERROR(("%s: enter, value = %d\n", __FUNCTION__, value));
2526 if ((dhd->op_mode & DHD_FLAG_HOSTAP_MODE) && value) {
2527 DHD_ERROR(("%s: DHD_FLAG_HOSTAP_MODE\n", __FUNCTION__));
2530 /* 1 - Enable packet filter, only allow unicast packet to send up */
2531 /* 0 - Disable packet filter */
2532 if (dhd_pkt_filter_enable && (!value ||
2533 (dhd_support_sta_mode(dhd) && !dhd->dhcp_in_progress)))
2535 for (i = 0; i < dhd->pktfilter_count; i++) {
2536 #ifndef GAN_LITE_NAT_KEEPALIVE_FILTER
2537 if (value && (i == DHD_ARP_FILTER_NUM) &&
2538 !_turn_on_arp_filter(dhd, dhd->op_mode)) {
2539 DHD_TRACE(("Do not turn on ARP white list pkt filter:"
2540 "val %d, cnt %d, op_mode 0x%x\n",
2541 value, i, dhd->op_mode));
2544 #endif /* !GAN_LITE_NAT_KEEPALIVE_FILTER */
2545 dhd_pktfilter_offload_enable(dhd, dhd->pktfilter[i],
2546 value, dhd_master_mode);
2549 #endif /* PKT_FILTER_SUPPORT */
2552 static int dhd_set_suspend(int value, dhd_pub_t *dhd)
2554 #ifndef SUPPORT_PM2_ONLY
2555 int power_mode = PM_MAX;
2556 #endif /* SUPPORT_PM2_ONLY */
2557 #ifdef SUPPORT_SENSORHUB
2559 #endif /* SUPPORT_SENSORHUB */
2560 /* wl_pkt_filter_enable_t enable_parm; */
2562 int bcn_li_dtim = 0; /* Default bcn_li_dtim in resume mode is 0 */
2563 #ifdef DHD_USE_EARLYSUSPEND
2564 #ifdef CUSTOM_BCN_TIMEOUT_IN_SUSPEND
2565 int bcn_timeout = 0;
2566 #endif /* CUSTOM_BCN_TIMEOUT_IN_SUSPEND */
2567 #ifdef CUSTOM_ROAM_TIME_THRESH_IN_SUSPEND
2568 int roam_time_thresh = 0; /* (ms) */
2569 #endif /* CUSTOM_ROAM_TIME_THRESH_IN_SUSPEND */
2570 #ifndef ENABLE_FW_ROAM_SUSPEND
2571 uint roamvar = dhd->conf->roam_off_suspend;
2572 #endif /* ENABLE_FW_ROAM_SUSPEND */
2573 #ifdef ENABLE_BCN_LI_BCN_WAKEUP
2575 #endif /* ENABLE_BCN_LI_BCN_WAKEUP */
2576 uint nd_ra_filter = 0;
2578 #endif /* DHD_USE_EARLYSUSPEND */
2579 #ifdef PASS_ALL_MCAST_PKTS
2580 struct dhd_info *dhdinfo;
2583 #endif /* PASS_ALL_MCAST_PKTS */
2584 #ifdef DYNAMIC_SWOOB_DURATION
2585 #ifndef CUSTOM_INTR_WIDTH
2586 #define CUSTOM_INTR_WIDTH 100
2588 #endif /* CUSTOM_INTR_WIDTH */
2589 #endif /* DYNAMIC_SWOOB_DURATION */
2594 #ifdef PASS_ALL_MCAST_PKTS
2595 dhdinfo = dhd->info;
2596 #endif /* PASS_ALL_MCAST_PKTS */
2598 DHD_TRACE(("%s: enter, value = %d in_suspend=%d\n",
2599 __FUNCTION__, value, dhd->in_suspend));
2601 dhd_suspend_lock(dhd);
2603 #ifdef CUSTOM_SET_CPUCORE
2604 DHD_TRACE(("%s set cpucore(suspend%d)\n", __FUNCTION__, value));
2605 /* set specific cpucore */
2606 dhd_set_cpucore(dhd, TRUE);
2607 #endif /* CUSTOM_SET_CPUCORE */
2608 #ifndef SUPPORT_PM2_ONLY
2609 if (dhd->conf->pm >= 0)
2610 power_mode = dhd->conf->pm;
2611 #endif /* SUPPORT_PM2_ONLY */
2613 if (value && dhd->in_suspend) {
2614 #ifdef PKT_FILTER_SUPPORT
2615 dhd->early_suspended = 1;
2617 /* Kernel suspended */
2618 DHD_ERROR(("%s: force extra Suspend setting\n", __FUNCTION__));
2620 #ifdef SUPPORT_SENSORHUB
2622 if (dhd->info->shub_enable == 1) {
2623 bcm_mkiovar("shub_msreq", (char *)&shub_msreq, 4,
2624 iovbuf, sizeof(iovbuf));
2625 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR,
2626 iovbuf, sizeof(iovbuf), TRUE, 0)) < 0) {
2627 DHD_ERROR(("%s Sensor Hub move/stop start: failed %d\n",
2628 __FUNCTION__, ret));
2631 #endif /* SUPPORT_SENSORHUB */
2633 #ifndef SUPPORT_PM2_ONLY
2634 dhd_wl_ioctl_cmd(dhd, WLC_SET_PM, (char *)&power_mode,
2635 sizeof(power_mode), TRUE, 0);
2636 #endif /* SUPPORT_PM2_ONLY */
2638 #ifdef PKT_FILTER_SUPPORT
2639 /* Enable packet filter,
2640 * only allow unicast packet to send up
2642 dhd_enable_packet_filter(1, dhd);
2643 #endif /* PKT_FILTER_SUPPORT */
2645 #ifdef PASS_ALL_MCAST_PKTS
2647 bcm_mkiovar("allmulti", (char *)&allmulti, 4,
2648 iovbuf, sizeof(iovbuf));
2649 for (i = 0; i < DHD_MAX_IFS; i++) {
2650 if (dhdinfo->iflist[i] && dhdinfo->iflist[i]->net)
2651 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf,
2652 sizeof(iovbuf), TRUE, i);
2654 #endif /* PASS_ALL_MCAST_PKTS */
2656 /* If DTIM skip is set up as default, force it to wake
2657 * each third DTIM for better power savings. Note that
2658 * one side effect is a chance to miss BC/MC packet.
2661 /* Do not set bcn_li_ditm on WFD mode */
2662 if (dhd->tdls_mode) {
2666 bcn_li_dtim = dhd_get_suspend_bcn_li_dtim(dhd);
2667 bcm_mkiovar("bcn_li_dtim", (char *)&bcn_li_dtim,
2668 4, iovbuf, sizeof(iovbuf));
2669 if (dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf),
2671 DHD_ERROR(("%s: set dtim failed\n", __FUNCTION__));
2673 #ifdef DHD_USE_EARLYSUSPEND
2674 #ifdef CUSTOM_BCN_TIMEOUT_IN_SUSPEND
2675 bcn_timeout = CUSTOM_BCN_TIMEOUT_IN_SUSPEND;
2676 bcm_mkiovar("bcn_timeout", (char *)&bcn_timeout,
2677 4, iovbuf, sizeof(iovbuf));
2678 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
2679 #endif /* CUSTOM_BCN_TIMEOUT_IN_SUSPEND */
2680 #ifdef CUSTOM_ROAM_TIME_THRESH_IN_SUSPEND
2681 roam_time_thresh = CUSTOM_ROAM_TIME_THRESH_IN_SUSPEND;
2682 bcm_mkiovar("roam_time_thresh", (char *)&roam_time_thresh,
2683 4, iovbuf, sizeof(iovbuf));
2684 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
2685 #endif /* CUSTOM_ROAM_TIME_THRESH_IN_SUSPEND */
2686 #ifndef ENABLE_FW_ROAM_SUSPEND
2687 /* Disable firmware roaming during suspend */
2688 bcm_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf, sizeof(iovbuf));
2689 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
2690 #endif /* ENABLE_FW_ROAM_SUSPEND */
2691 #ifdef ENABLE_BCN_LI_BCN_WAKEUP
2693 bcm_mkiovar("bcn_li_bcn", (char *)&bcn_li_bcn,
2694 4, iovbuf, sizeof(iovbuf));
2695 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
2696 #endif /* ENABLE_BCN_LI_BCN_WAKEUP */
2697 if (FW_SUPPORTED(dhd, ndoe)) {
2698 /* enable IPv6 RA filter in firmware during suspend */
2700 bcm_mkiovar("nd_ra_filter_enable", (char *)&nd_ra_filter, 4,
2701 iovbuf, sizeof(iovbuf));
2702 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf,
2703 sizeof(iovbuf), TRUE, 0)) < 0)
2704 DHD_ERROR(("failed to set nd_ra_filter (%d)\n",
2707 #ifdef DYNAMIC_SWOOB_DURATION
2708 intr_width = CUSTOM_INTR_WIDTH;
2709 bcm_mkiovar("bus:intr_width", (char *)&intr_width, 4,
2710 iovbuf, sizeof(iovbuf));
2711 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf,
2712 sizeof(iovbuf), TRUE, 0)) < 0) {
2713 DHD_ERROR(("failed to set intr_width (%d)\n", ret));
2715 #endif /* DYNAMIC_SWOOB_DURATION */
2716 #endif /* DHD_USE_EARLYSUSPEND */
2718 #ifdef PKT_FILTER_SUPPORT
2719 dhd->early_suspended = 0;
2721 /* Kernel resumed */
2722 DHD_ERROR(("%s: Remove extra suspend setting\n", __FUNCTION__));
2724 #ifdef SUPPORT_SENSORHUB
2726 if (dhd->info->shub_enable == 1) {
2727 bcm_mkiovar("shub_msreq", (char *)&shub_msreq,
2728 4, iovbuf, sizeof(iovbuf));
2729 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR,
2730 iovbuf, sizeof(iovbuf), TRUE, 0)) < 0) {
2731 DHD_ERROR(("%s Sensor Hub move/stop stop:"
2732 "failed %d\n", __FUNCTION__, ret));
2735 #endif /* SUPPORT_SENSORHUB */
2738 #ifdef DYNAMIC_SWOOB_DURATION
2740 bcm_mkiovar("bus:intr_width", (char *)&intr_width, 4,
2741 iovbuf, sizeof(iovbuf));
2742 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf,
2743 sizeof(iovbuf), TRUE, 0)) < 0) {
2744 DHD_ERROR(("failed to set intr_width (%d)\n", ret));
2746 #endif /* DYNAMIC_SWOOB_DURATION */
2747 #ifndef SUPPORT_PM2_ONLY
2748 power_mode = PM_FAST;
2749 dhd_wl_ioctl_cmd(dhd, WLC_SET_PM, (char *)&power_mode,
2750 sizeof(power_mode), TRUE, 0);
2751 #endif /* SUPPORT_PM2_ONLY */
2752 #ifdef PKT_FILTER_SUPPORT
2753 /* disable pkt filter */
2754 dhd_enable_packet_filter(0, dhd);
2755 #endif /* PKT_FILTER_SUPPORT */
2756 #ifdef PASS_ALL_MCAST_PKTS
2758 bcm_mkiovar("allmulti", (char *)&allmulti, 4,
2759 iovbuf, sizeof(iovbuf));
2760 for (i = 0; i < DHD_MAX_IFS; i++) {
2761 if (dhdinfo->iflist[i] && dhdinfo->iflist[i]->net)
2762 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf,
2763 sizeof(iovbuf), TRUE, i);
2765 #endif /* PASS_ALL_MCAST_PKTS */
2767 /* restore pre-suspend setting for dtim_skip */
2768 bcm_mkiovar("bcn_li_dtim", (char *)&bcn_li_dtim,
2769 4, iovbuf, sizeof(iovbuf));
2771 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
2772 #ifdef DHD_USE_EARLYSUSPEND
2773 #ifdef CUSTOM_BCN_TIMEOUT_IN_SUSPEND
2774 bcn_timeout = CUSTOM_BCN_TIMEOUT;
2775 bcm_mkiovar("bcn_timeout", (char *)&bcn_timeout,
2776 4, iovbuf, sizeof(iovbuf));
2777 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
2778 #endif /* CUSTOM_BCN_TIMEOUT_IN_SUSPEND */
2779 #ifdef CUSTOM_ROAM_TIME_THRESH_IN_SUSPEND
2780 roam_time_thresh = 2000;
2781 bcm_mkiovar("roam_time_thresh", (char *)&roam_time_thresh,
2782 4, iovbuf, sizeof(iovbuf));
2783 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
2784 #endif /* CUSTOM_ROAM_TIME_THRESH_IN_SUSPEND */
2785 #ifndef ENABLE_FW_ROAM_SUSPEND
2786 roamvar = dhd_roam_disable;
2787 bcm_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf, sizeof(iovbuf));
2788 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
2789 #endif /* ENABLE_FW_ROAM_SUSPEND */
2790 #ifdef ENABLE_BCN_LI_BCN_WAKEUP
2792 bcm_mkiovar("bcn_li_bcn", (char *)&bcn_li_bcn,
2793 4, iovbuf, sizeof(iovbuf));
2794 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
2795 #endif /* ENABLE_BCN_LI_BCN_WAKEUP */
2796 if (FW_SUPPORTED(dhd, ndoe)) {
2797 /* disable IPv6 RA filter in firmware during suspend */
2799 bcm_mkiovar("nd_ra_filter_enable", (char *)&nd_ra_filter, 4,
2800 iovbuf, sizeof(iovbuf));
2801 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf,
2802 sizeof(iovbuf), TRUE, 0)) < 0)
2803 DHD_ERROR(("failed to set nd_ra_filter (%d)\n",
2806 #endif /* DHD_USE_EARLYSUSPEND */
2809 dhd_suspend_unlock(dhd);
2814 static int dhd_suspend_resume_helper(struct dhd_info *dhd, int val, int force)
2816 dhd_pub_t *dhdp = &dhd->pub;
2819 DHD_OS_WAKE_LOCK(dhdp);
2820 DHD_PERIM_LOCK(dhdp);
2822 /* Set flag when early suspend was called */
2823 dhdp->in_suspend = val;
2824 if ((force || !dhdp->suspend_disable_flag) &&
2825 dhd_support_sta_mode(dhdp))
2827 ret = dhd_set_suspend(val, dhdp);
2830 DHD_PERIM_UNLOCK(dhdp);
2831 DHD_OS_WAKE_UNLOCK(dhdp);
2835 #if defined(CONFIG_HAS_EARLYSUSPEND) && defined(DHD_USE_EARLYSUSPEND)
2836 static void dhd_early_suspend(struct early_suspend *h)
2838 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
2839 DHD_TRACE_HW4(("%s: enter\n", __FUNCTION__));
2842 dhd_suspend_resume_helper(dhd, 1, 0);
2845 static void dhd_late_resume(struct early_suspend *h)
2847 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
2848 DHD_TRACE_HW4(("%s: enter\n", __FUNCTION__));
2851 dhd_suspend_resume_helper(dhd, 0, 0);
2853 #endif /* CONFIG_HAS_EARLYSUSPEND && DHD_USE_EARLYSUSPEND */
2856 * Generalized timeout mechanism. Uses spin sleep with exponential back-off until
2857 * the sleep time reaches one jiffy, then switches over to task delay. Usage:
2859 * dhd_timeout_start(&tmo, usec);
2860 * while (!dhd_timeout_expired(&tmo))
2861 * if (poll_something())
2863 * if (dhd_timeout_expired(&tmo))
2868 dhd_timeout_start(dhd_timeout_t *tmo, uint usec)
2873 tmo->tick = jiffies_to_usecs(1);
2877 dhd_timeout_expired(dhd_timeout_t *tmo)
2879 /* Does nothing the first call */
2880 if (tmo->increment == 0) {
2885 if (tmo->elapsed >= tmo->limit)
2888 /* Add the delay that's about to take place */
2889 tmo->elapsed += tmo->increment;
2891 if ((!CAN_SLEEP()) || tmo->increment < tmo->tick) {
2892 OSL_DELAY(tmo->increment);
2893 tmo->increment *= 2;
2894 if (tmo->increment > tmo->tick)
2895 tmo->increment = tmo->tick;
2897 wait_queue_head_t delay_wait;
2898 DECLARE_WAITQUEUE(wait, current);
2899 init_waitqueue_head(&delay_wait);
2900 add_wait_queue(&delay_wait, &wait);
2901 set_current_state(TASK_INTERRUPTIBLE);
2902 (void)schedule_timeout(1);
2903 remove_wait_queue(&delay_wait, &wait);
2904 set_current_state(TASK_RUNNING);
2911 dhd_net2idx(dhd_info_t *dhd, struct net_device *net)
2916 DHD_ERROR(("%s : DHD_BAD_IF return\n", __FUNCTION__));
2920 while (i < DHD_MAX_IFS) {
2921 if (dhd->iflist[i] && dhd->iflist[i]->net && (dhd->iflist[i]->net == net))
2929 struct net_device * dhd_idx2net(void *pub, int ifidx)
2931 struct dhd_pub *dhd_pub = (struct dhd_pub *)pub;
2932 struct dhd_info *dhd_info;
2934 if (!dhd_pub || ifidx < 0 || ifidx >= DHD_MAX_IFS)
2936 dhd_info = dhd_pub->info;
2937 if (dhd_info && dhd_info->iflist[ifidx])
2938 return dhd_info->iflist[ifidx]->net;
2943 dhd_ifname2idx(dhd_info_t *dhd, char *name)
2945 int i = DHD_MAX_IFS;
2949 if (name == NULL || *name == '\0')
2953 if (dhd->iflist[i] && !strncmp(dhd->iflist[i]->dngl_name, name, IFNAMSIZ))
2956 DHD_TRACE(("%s: return idx %d for \"%s\"\n", __FUNCTION__, i, name));
2958 return i; /* default - the primary interface */
2962 dhd_ifname(dhd_pub_t *dhdp, int ifidx)
2964 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
2968 if (ifidx < 0 || ifidx >= DHD_MAX_IFS) {
2969 DHD_ERROR(("%s: ifidx %d out of range\n", __FUNCTION__, ifidx));
2973 if (dhd->iflist[ifidx] == NULL) {
2974 DHD_ERROR(("%s: null i/f %d\n", __FUNCTION__, ifidx));
2978 if (dhd->iflist[ifidx]->net)
2979 return dhd->iflist[ifidx]->net->name;
2985 dhd_bssidx2bssid(dhd_pub_t *dhdp, int idx)
2988 dhd_info_t *dhd = (dhd_info_t *)dhdp;
2991 for (i = 0; i < DHD_MAX_IFS; i++)
2992 if (dhd->iflist[i] && dhd->iflist[i]->bssidx == idx)
2993 return dhd->iflist[i]->mac_addr;
3000 _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
3002 struct net_device *dev;
3003 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
3004 struct netdev_hw_addr *ha;
3006 struct dev_mc_list *mclist;
3008 uint32 allmulti, cnt;
3015 if (!dhd->iflist[ifidx]) {
3016 DHD_ERROR(("%s : dhd->iflist[%d] was NULL\n", __FUNCTION__, ifidx));
3019 dev = dhd->iflist[ifidx]->net;
3022 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
3023 netif_addr_lock_bh(dev);
3024 #endif /* LINUX >= 2.6.27 */
3025 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
3026 cnt = netdev_mc_count(dev);
3028 cnt = dev->mc_count;
3029 #endif /* LINUX >= 2.6.35 */
3030 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
3031 netif_addr_unlock_bh(dev);
3032 #endif /* LINUX >= 2.6.27 */
3034 /* Determine initial value of allmulti flag */
3035 allmulti = (dev->flags & IFF_ALLMULTI) ? TRUE : FALSE;
3037 #ifdef PASS_ALL_MCAST_PKTS
3038 #ifdef PKT_FILTER_SUPPORT
3039 if (!dhd->pub.early_suspended)
3040 #endif /* PKT_FILTER_SUPPORT */
3042 #endif /* PASS_ALL_MCAST_PKTS */
3044 /* Send down the multicast list first. */
3047 buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETHER_ADDR_LEN);
3048 if (!(bufp = buf = MALLOC(dhd->pub.osh, buflen))) {
3049 DHD_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
3050 dhd_ifname(&dhd->pub, ifidx), cnt));
3054 strncpy(bufp, "mcast_list", buflen - 1);
3055 bufp[buflen - 1] = '\0';
3056 bufp += strlen("mcast_list") + 1;
3059 memcpy(bufp, &cnt, sizeof(cnt));
3060 bufp += sizeof(cnt);
3062 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
3063 netif_addr_lock_bh(dev);
3064 #endif /* LINUX >= 2.6.27 */
3065 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
3066 netdev_for_each_mc_addr(ha, dev) {
3069 memcpy(bufp, ha->addr, ETHER_ADDR_LEN);
3070 bufp += ETHER_ADDR_LEN;
3073 #else /* LINUX < 2.6.35 */
3074 for (mclist = dev->mc_list; (mclist && (cnt > 0));
3075 cnt--, mclist = mclist->next) {
3076 memcpy(bufp, (void *)mclist->dmi_addr, ETHER_ADDR_LEN);
3077 bufp += ETHER_ADDR_LEN;
3079 #endif /* LINUX >= 2.6.35 */
3080 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
3081 netif_addr_unlock_bh(dev);
3082 #endif /* LINUX >= 2.6.27 */
3084 memset(&ioc, 0, sizeof(ioc));
3085 ioc.cmd = WLC_SET_VAR;
3090 ret = dhd_wl_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
3092 DHD_ERROR(("%s: set mcast_list failed, cnt %d\n",
3093 dhd_ifname(&dhd->pub, ifidx), cnt));
3094 allmulti = cnt ? TRUE : allmulti;
3097 MFREE(dhd->pub.osh, buf, buflen);
3099 /* Now send the allmulti setting. This is based on the setting in the
3100 * net_device flags, but might be modified above to be turned on if we
3101 * were trying to set some addresses and dongle rejected it...
3104 buflen = sizeof("allmulti") + sizeof(allmulti);
3105 if (!(buf = MALLOC(dhd->pub.osh, buflen))) {
3106 DHD_ERROR(("%s: out of memory for allmulti\n", dhd_ifname(&dhd->pub, ifidx)));
3109 allmulti = htol32(allmulti);
3111 if (!bcm_mkiovar("allmulti", (void*)&allmulti, sizeof(allmulti), buf, buflen)) {
3112 DHD_ERROR(("%s: mkiovar failed for allmulti, datalen %d buflen %u\n",
3113 dhd_ifname(&dhd->pub, ifidx), (int)sizeof(allmulti), buflen));
3114 MFREE(dhd->pub.osh, buf, buflen);
3119 memset(&ioc, 0, sizeof(ioc));
3120 ioc.cmd = WLC_SET_VAR;
3125 ret = dhd_wl_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
3127 DHD_ERROR(("%s: set allmulti %d failed\n",
3128 dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
3131 MFREE(dhd->pub.osh, buf, buflen);
3133 /* Finally, pick up the PROMISC flag as well, like the NIC driver does */
3135 allmulti = (dev->flags & IFF_PROMISC) ? TRUE : FALSE;
3137 allmulti = htol32(allmulti);
3139 memset(&ioc, 0, sizeof(ioc));
3140 ioc.cmd = WLC_SET_PROMISC;
3141 ioc.buf = &allmulti;
3142 ioc.len = sizeof(allmulti);
3145 ret = dhd_wl_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
3147 DHD_ERROR(("%s: set promisc %d failed\n",
3148 dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
3153 _dhd_set_mac_address(dhd_info_t *dhd, int ifidx, uint8 *addr)
3159 if (!bcm_mkiovar("cur_etheraddr", (char*)addr, ETHER_ADDR_LEN, buf, 32)) {
3160 DHD_ERROR(("%s: mkiovar failed for cur_etheraddr\n", dhd_ifname(&dhd->pub, ifidx)));
3163 memset(&ioc, 0, sizeof(ioc));
3164 ioc.cmd = WLC_SET_VAR;
3169 ret = dhd_wl_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
3171 DHD_ERROR(("%s: set cur_etheraddr failed\n", dhd_ifname(&dhd->pub, ifidx)));
3173 memcpy(dhd->iflist[ifidx]->net->dev_addr, addr, ETHER_ADDR_LEN);
3175 memcpy(dhd->pub.mac.octet, addr, ETHER_ADDR_LEN);
3182 extern struct net_device *ap_net_dev;
3183 extern tsk_ctl_t ap_eth_ctl; /* ap netdev heper thread ctl */
3187 /* Get psta/psr configuration configuration */
3188 int dhd_get_psta_mode(dhd_pub_t *dhdp)
3190 dhd_info_t *dhd = dhdp->info;
3191 return (int)dhd->psta_mode;
3193 /* Set psta/psr configuration configuration */
3194 int dhd_set_psta_mode(dhd_pub_t *dhdp, uint32 val)
3196 dhd_info_t *dhd = dhdp->info;
3197 dhd->psta_mode = val;
3200 #endif /* DHD_PSTA */
3203 dhd_ifadd_event_handler(void *handle, void *event_info, u8 event)
3205 dhd_info_t *dhd = handle;
3206 dhd_if_event_t *if_event = event_info;
3207 struct net_device *ndev;
3210 #if defined(WL_CFG80211) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
3211 struct wireless_dev *vwdev, *primary_wdev;
3212 struct net_device *primary_ndev;
3213 #endif /* OEM_ANDROID && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0)) */
3215 if (event != DHD_WQ_WORK_IF_ADD) {
3216 DHD_ERROR(("%s: unexpected event \n", __FUNCTION__));
3221 DHD_ERROR(("%s: dhd info not available \n", __FUNCTION__));
3226 DHD_ERROR(("%s: event data is null \n", __FUNCTION__));
3230 dhd_net_if_lock_local(dhd);
3231 DHD_OS_WAKE_LOCK(&dhd->pub);
3232 DHD_PERIM_LOCK(&dhd->pub);
3234 ifidx = if_event->event.ifidx;
3235 bssidx = if_event->event.bssidx;
3236 DHD_TRACE(("%s: registering if with ifidx %d\n", __FUNCTION__, ifidx));
3238 /* This path is for non-android case */
3239 /* The interface name in host and in event msg are same */
3240 /* if name in event msg is used to create dongle if list on host */
3241 ndev = dhd_allocate_if(&dhd->pub, ifidx, if_event->name,
3242 if_event->mac, bssidx, TRUE, if_event->name);
3244 DHD_ERROR(("%s: net device alloc failed \n", __FUNCTION__));
3248 #if defined(WL_CFG80211) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0))
3249 vwdev = kzalloc(sizeof(*vwdev), GFP_KERNEL);
3250 if (unlikely(!vwdev)) {
3251 DHD_ERROR(("Could not allocate wireless device\n"));
3254 primary_ndev = dhd->pub.info->iflist[0]->net;
3255 primary_wdev = ndev_to_wdev(primary_ndev);
3256 vwdev->wiphy = primary_wdev->wiphy;
3257 vwdev->iftype = if_event->event.role;
3258 vwdev->netdev = ndev;
3259 ndev->ieee80211_ptr = vwdev;
3260 SET_NETDEV_DEV(ndev, wiphy_dev(vwdev->wiphy));
3261 DHD_ERROR(("virtual interface(%s) is created\n", if_event->name));
3262 #endif /* OEM_ANDROID && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0)) */
3264 DHD_PERIM_UNLOCK(&dhd->pub);
3265 ret = dhd_register_if(&dhd->pub, ifidx, TRUE);
3266 DHD_PERIM_LOCK(&dhd->pub);
3267 if (ret != BCME_OK) {
3268 DHD_ERROR(("%s: dhd_register_if failed\n", __FUNCTION__));
3269 dhd_remove_if(&dhd->pub, ifidx, TRUE);
3272 #ifdef PCIE_FULL_DONGLE
3273 /* Turn on AP isolation in the firmware for interfaces operating in AP mode */
3274 if (FW_SUPPORTED((&dhd->pub), ap) && (if_event->event.role != WLC_E_IF_ROLE_STA)) {
3275 char iovbuf[WLC_IOCTL_SMLEN];
3278 memset(iovbuf, 0, sizeof(iovbuf));
3279 bcm_mkiovar("ap_isolate", (char *)&var_int, 4, iovbuf, sizeof(iovbuf));
3280 ret = dhd_wl_ioctl_cmd(&dhd->pub, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, ifidx);
3282 if (ret != BCME_OK) {
3283 DHD_ERROR(("%s: Failed to set ap_isolate to dongle\n", __FUNCTION__));
3284 dhd_remove_if(&dhd->pub, ifidx, TRUE);
3287 #endif /* PCIE_FULL_DONGLE */
3290 MFREE(dhd->pub.osh, if_event, sizeof(dhd_if_event_t));
3292 DHD_PERIM_UNLOCK(&dhd->pub);
3293 DHD_OS_WAKE_UNLOCK(&dhd->pub);
3294 dhd_net_if_unlock_local(dhd);
3298 dhd_ifdel_event_handler(void *handle, void *event_info, u8 event)
3300 dhd_info_t *dhd = handle;
3302 dhd_if_event_t *if_event = event_info;
3305 if (event != DHD_WQ_WORK_IF_DEL) {
3306 DHD_ERROR(("%s: unexpected event \n", __FUNCTION__));
3311 DHD_ERROR(("%s: dhd info not available \n", __FUNCTION__));
3316 DHD_ERROR(("%s: event data is null \n", __FUNCTION__));
3320 dhd_net_if_lock_local(dhd);
3321 DHD_OS_WAKE_LOCK(&dhd->pub);
3322 DHD_PERIM_LOCK(&dhd->pub);
3324 ifidx = if_event->event.ifidx;
3325 DHD_TRACE(("Removing interface with idx %d\n", ifidx));
3327 DHD_PERIM_UNLOCK(&dhd->pub);
3328 dhd_remove_if(&dhd->pub, ifidx, TRUE);
3329 DHD_PERIM_LOCK(&dhd->pub);
3331 MFREE(dhd->pub.osh, if_event, sizeof(dhd_if_event_t));
3333 DHD_PERIM_UNLOCK(&dhd->pub);
3334 DHD_OS_WAKE_UNLOCK(&dhd->pub);
3335 dhd_net_if_unlock_local(dhd);
3339 dhd_set_mac_addr_handler(void *handle, void *event_info, u8 event)
3341 dhd_info_t *dhd = handle;
3342 dhd_if_t *ifp = event_info;
3344 if (event != DHD_WQ_WORK_SET_MAC) {
3345 DHD_ERROR(("%s: unexpected event \n", __FUNCTION__));
3349 DHD_ERROR(("%s: dhd info not available \n", __FUNCTION__));
3353 dhd_net_if_lock_local(dhd);
3354 DHD_OS_WAKE_LOCK(&dhd->pub);
3355 DHD_PERIM_LOCK(&dhd->pub);
3359 unsigned long flags;
3361 DHD_GENERAL_LOCK(&dhd->pub, flags);
3362 in_ap = (ap_net_dev != NULL);
3363 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
3366 DHD_ERROR(("attempt to set MAC for %s in AP Mode, blocked. \n",
3373 if (ifp == NULL || !dhd->pub.up) {
3374 DHD_ERROR(("%s: interface info not available/down \n", __FUNCTION__));
3378 DHD_ERROR(("%s: MACID is overwritten\n", __FUNCTION__));
3379 ifp->set_macaddress = FALSE;
3380 if (_dhd_set_mac_address(dhd, ifp->idx, ifp->mac_addr) == 0)
3381 DHD_INFO(("%s: MACID is overwritten\n", __FUNCTION__));
3383 DHD_ERROR(("%s: _dhd_set_mac_address() failed\n", __FUNCTION__));
3386 DHD_PERIM_UNLOCK(&dhd->pub);
3387 DHD_OS_WAKE_UNLOCK(&dhd->pub);
3388 dhd_net_if_unlock_local(dhd);
3392 dhd_set_mcast_list_handler(void *handle, void *event_info, u8 event)
3394 dhd_info_t *dhd = handle;
3395 dhd_if_t *ifp = event_info;
3398 if (event != DHD_WQ_WORK_SET_MCAST_LIST) {
3399 DHD_ERROR(("%s: unexpected event \n", __FUNCTION__));
3404 DHD_ERROR(("%s: dhd info not available \n", __FUNCTION__));
3408 dhd_net_if_lock_local(dhd);
3409 DHD_OS_WAKE_LOCK(&dhd->pub);
3410 DHD_PERIM_LOCK(&dhd->pub);
3415 unsigned long flags;
3416 DHD_GENERAL_LOCK(&dhd->pub, flags);
3417 in_ap = (ap_net_dev != NULL);
3418 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
3421 DHD_ERROR(("set MULTICAST list for %s in AP Mode, blocked. \n",
3423 ifp->set_multicast = FALSE;
3429 if (ifp == NULL || !dhd->pub.up) {
3430 DHD_ERROR(("%s: interface info not available/down \n", __FUNCTION__));
3437 _dhd_set_multicast_list(dhd, ifidx);
3438 DHD_INFO(("%s: set multicast list for if %d\n", __FUNCTION__, ifidx));
3441 DHD_PERIM_UNLOCK(&dhd->pub);
3442 DHD_OS_WAKE_UNLOCK(&dhd->pub);
3443 dhd_net_if_unlock_local(dhd);
3447 dhd_set_mac_address(struct net_device *dev, void *addr)
3451 dhd_info_t *dhd = DHD_DEV_INFO(dev);
3452 struct sockaddr *sa = (struct sockaddr *)addr;
3456 ifidx = dhd_net2idx(dhd, dev);
3457 if (ifidx == DHD_BAD_IF)
3460 dhdif = dhd->iflist[ifidx];
3462 dhd_net_if_lock_local(dhd);
3463 memcpy(dhdif->mac_addr, sa->sa_data, ETHER_ADDR_LEN);
3464 dhdif->set_macaddress = TRUE;
3465 dhd_net_if_unlock_local(dhd);
3466 dhd_deferred_schedule_work(dhd->dhd_deferred_wq, (void *)dhdif, DHD_WQ_WORK_SET_MAC,
3467 dhd_set_mac_addr_handler, DHD_WORK_PRIORITY_LOW);
3472 dhd_set_multicast_list(struct net_device *dev)
3474 dhd_info_t *dhd = DHD_DEV_INFO(dev);
3477 ifidx = dhd_net2idx(dhd, dev);
3478 if (ifidx == DHD_BAD_IF)
3481 dhd->iflist[ifidx]->set_multicast = TRUE;
3482 dhd_deferred_schedule_work(dhd->dhd_deferred_wq, (void *)dhd->iflist[ifidx],
3483 DHD_WQ_WORK_SET_MCAST_LIST, dhd_set_mcast_list_handler, DHD_WORK_PRIORITY_LOW);
3486 #ifdef PROP_TXSTATUS
3488 dhd_os_wlfc_block(dhd_pub_t *pub)
3490 dhd_info_t *di = (dhd_info_t *)(pub->info);
3492 spin_lock_bh(&di->wlfc_spinlock);
3497 dhd_os_wlfc_unblock(dhd_pub_t *pub)
3499 dhd_info_t *di = (dhd_info_t *)(pub->info);
3502 spin_unlock_bh(&di->wlfc_spinlock);
3506 #endif /* PROP_TXSTATUS */
3508 #if defined(DHD_RX_DUMP) || defined(DHD_TX_DUMP)
3514 static const PKTTYPE_INFO packet_type_info[] =
3516 { ETHER_TYPE_IP, "IP" },
3517 { ETHER_TYPE_ARP, "ARP" },
3518 { ETHER_TYPE_BRCM, "BRCM" },
3519 { ETHER_TYPE_802_1X, "802.1X" },
3520 { ETHER_TYPE_WAI, "WAPI" },
3524 static const char *_get_packet_type_str(uint16 type)
3527 int n = sizeof(packet_type_info)/sizeof(packet_type_info[1]) - 1;
3529 for (i = 0; i < n; i++) {
3530 if (packet_type_info[i].type == type)
3531 return packet_type_info[i].str;
3534 return packet_type_info[n].str;
3536 #endif /* DHD_RX_DUMP || DHD_TX_DUMP */
3538 #if defined(DHD_TX_DUMP)
3540 dhd_tx_dump(struct net_device *ndev, osl_t *osh, void *pkt)
3546 dump_data = PKTDATA(osh, pkt);
3547 protocol = (dump_data[12] << 8) | dump_data[13];
3548 ifname = ndev ? ndev->name : "N/A";
3550 DHD_ERROR(("TX DUMP[%s] - %s\n", ifname, _get_packet_type_str(protocol)));
3552 if (protocol == ETHER_TYPE_802_1X) {
3553 dhd_dump_eapol_4way_message(ifname, dump_data, TRUE);
3556 #if defined(DHD_TX_FULL_DUMP)
3560 datalen = PKTLEN(osh, pkt);
3562 for (i = 0; i < datalen; i++) {
3563 printk("%02X ", dump_data[i]);
3569 #endif /* DHD_TX_FULL_DUMP */
3571 #endif /* DHD_TX_DUMP */
3573 /* This routine do not support Packet chain feature, Currently tested for
3576 int dhd_sendup(dhd_pub_t *dhdp, int ifidx, void *p)
3578 struct sk_buff *skb;
3579 void *skbhead = NULL;
3580 void *skbprev = NULL;
3582 ASSERT(!PKTISCHAINED(p));
3583 skb = PKTTONATIVE(dhdp->osh, p);
3585 ifp = dhdp->info->iflist[ifidx];
3586 skb->dev = ifp->net;
3587 #if defined(BCM_GMAC3)
3588 /* Forwarder capable interfaces use WOFA based forwarding */
3590 struct ether_header *eh = (struct ether_header *)PKTDATA(dhdp->osh, p);
3591 uint16 * da = (uint16 *)(eh->ether_dhost);
3593 ASSERT(ISALIGNED(da, 2));
3595 wofa = fwder_lookup(ifp->fwdh->mate, da, ifp->idx);
3596 if (wofa == FWDER_WOFA_INVALID) { /* Unknown MAC address */
3597 if (fwder_transmit(ifp->fwdh, skb, 1, skb->dev) == FWDER_SUCCESS) {
3601 PKTFRMNATIVE(dhdp->osh, p);
3602 PKTFREE(dhdp->osh, p, FALSE);
3605 #endif /* BCM_GMAC3 */
3607 skb->protocol = eth_type_trans(skb, skb->dev);
3609 if (in_interrupt()) {
3610 bcm_object_trace_opr(skb, BCM_OBJDBG_REMOVE,
3611 __FUNCTION__, __LINE__);
3614 if (dhdp->info->rxthread_enabled) {
3618 PKTSETNEXT(dhdp->osh, skbprev, skb);
3622 /* If the receive is not processed inside an ISR,
3623 * the softirqd must be woken explicitly to service
3624 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
3625 * by netif_rx_ni(), but in earlier kernels, we need
3626 * to do it manually.
3628 bcm_object_trace_opr(skb, BCM_OBJDBG_REMOVE,
3629 __FUNCTION__, __LINE__);
3630 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
3635 local_irq_save(flags);
3637 local_irq_restore(flags);
3638 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) */
3642 if (dhdp->info->rxthread_enabled && skbhead)
3643 dhd_sched_rxf(dhdp, skbhead);
3649 __dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pktbuf)
3652 dhd_info_t *dhd = (dhd_info_t *)(dhdp->info);
3653 struct ether_header *eh = NULL;
3654 #ifdef DHD_L2_FILTER
3655 dhd_if_t *ifp = dhd_get_ifp(dhdp, ifidx);
3657 #ifdef DHD_8021X_DUMP
3658 struct net_device *ndev;
3659 #endif /* DHD_8021X_DUMP */
3661 /* Reject if down */
3662 if (!dhdp->up || (dhdp->busstate == DHD_BUS_DOWN)) {
3663 /* free the packet here since the caller won't */
3664 PKTCFREE(dhdp->osh, pktbuf, TRUE);
3668 #ifdef PCIE_FULL_DONGLE
3669 if (dhdp->busstate == DHD_BUS_SUSPEND) {
3670 DHD_ERROR(("%s : pcie is still in suspend state!!\n", __FUNCTION__));
3671 PKTFREE(dhdp->osh, pktbuf, TRUE);
3674 #endif /* PCIE_FULL_DONGLE */
3676 #ifdef DHD_L2_FILTER
3677 /* if dhcp_unicast is enabled, we need to convert the */
3678 /* broadcast DHCP ACK/REPLY packets to Unicast. */
3679 if (ifp->dhcp_unicast) {
3681 uint8* ehptr = NULL;
3683 ret = bcm_l2_filter_get_mac_addr_dhcp_pkt(dhdp->osh, pktbuf, ifidx, &mac_addr);
3684 if (ret == BCME_OK) {
3685 /* if given mac address having valid entry in sta list
3686 * copy the given mac address, and return with BCME_OK
3688 if (dhd_find_sta(dhdp, ifidx, mac_addr)) {
3689 ehptr = PKTDATA(dhdp->osh, pktbuf);
3690 bcopy(mac_addr, ehptr + ETHER_DEST_OFFSET, ETHER_ADDR_LEN);
3695 if (ifp->grat_arp && DHD_IF_ROLE_AP(dhdp, ifidx)) {
3696 if (bcm_l2_filter_gratuitous_arp(dhdp->osh, pktbuf) == BCME_OK) {
3697 PKTCFREE(dhdp->osh, pktbuf, TRUE);
3702 if (ifp->parp_enable && DHD_IF_ROLE_AP(dhdp, ifidx)) {
3703 ret = dhd_l2_filter_pkt_handle(dhdp, ifidx, pktbuf, TRUE);
3705 /* Drop the packets if l2 filter has processed it already
3706 * otherwise continue with the normal path
3708 if (ret == BCME_OK) {
3709 PKTCFREE(dhdp->osh, pktbuf, TRUE);
3713 #endif /* DHD_L2_FILTER */
3714 /* Update multicast statistic */
3715 if (PKTLEN(dhdp->osh, pktbuf) >= ETHER_HDR_LEN) {
3716 uint8 *pktdata = (uint8 *)PKTDATA(dhdp->osh, pktbuf);
3717 eh = (struct ether_header *)pktdata;
3719 if (ETHER_ISMULTI(eh->ether_dhost))
3720 dhdp->tx_multicast++;
3721 if (ntoh16(eh->ether_type) == ETHER_TYPE_802_1X)
3722 atomic_inc(&dhd->pend_8021x_cnt);
3723 #ifdef DHD_DHCP_DUMP
3724 if (ntoh16(eh->ether_type) == ETHER_TYPE_IP) {
3728 uint16 udp_port_pos;
3729 uint8 *ptr8 = (uint8 *)&pktdata[ETHER_HDR_LEN];
3730 uint8 ip_header_len = (*ptr8 & 0x0f)<<2;
3731 struct net_device *net;
3734 net = dhd_idx2net(dhdp, ifidx);
3735 ifname = net ? net->name : "N/A";
3736 udp_port_pos = ETHER_HDR_LEN + ip_header_len;
3737 source_port = (pktdata[udp_port_pos] << 8) | pktdata[udp_port_pos+1];
3738 dest_port = (pktdata[udp_port_pos+2] << 8) | pktdata[udp_port_pos+3];
3739 if (source_port == 0x0044 || dest_port == 0x0044) {
3740 dump_hex = (pktdata[udp_port_pos+249] << 8) |
3741 pktdata[udp_port_pos+250];
3742 if (dump_hex == 0x0101) {
3743 DHD_ERROR(("DHCP[%s] - DISCOVER [TX]", ifname));
3744 } else if (dump_hex == 0x0102) {
3745 DHD_ERROR(("DHCP[%s] - OFFER [TX]", ifname));
3746 } else if (dump_hex == 0x0103) {
3747 DHD_ERROR(("DHCP[%s] - REQUEST [TX]", ifname));
3748 } else if (dump_hex == 0x0105) {
3749 DHD_ERROR(("DHCP[%s] - ACK [TX]", ifname));
3751 DHD_ERROR(("DHCP[%s] - 0x%X [TX]", ifname, dump_hex));
3753 #ifdef DHD_LOSSLESS_ROAMING
3754 if (dhdp->dequeue_prec_map != (uint8)ALLPRIO) {
3755 DHD_ERROR(("/%d", dhdp->dequeue_prec_map));
3757 #endif /* DHD_LOSSLESS_ROAMING */
3759 } else if (source_port == 0x0043 || dest_port == 0x0043) {
3760 DHD_ERROR(("DHCP[%s] - BOOTP [RX]\n", ifname));
3763 #endif /* DHD_DHCP_DUMP */
3765 PKTCFREE(dhdp->osh, pktbuf, TRUE);
3769 /* Look into the packet and update the packet priority */
3770 #ifndef PKTPRIO_OVERRIDE
3771 if (PKTPRIO(pktbuf) == 0)
3772 #endif /* !PKTPRIO_OVERRIDE */
3775 pktsetprio_qms(pktbuf, wl_get_up_table(), FALSE);
3777 pktsetprio(pktbuf, FALSE);
3778 #endif /* QOS_MAP_SET */
3782 #ifdef PCIE_FULL_DONGLE
3784 * Lkup the per interface hash table, for a matching flowring. If one is not
3785 * available, allocate a unique flowid and add a flowring entry.
3786 * The found or newly created flowid is placed into the pktbuf's tag.
3788 ret = dhd_flowid_update(dhdp, ifidx, dhdp->flow_prio_map[(PKTPRIO(pktbuf))], pktbuf);
3789 if (ret != BCME_OK) {
3790 PKTCFREE(dhd->pub.osh, pktbuf, TRUE);
3795 #if defined(DHD_TX_DUMP)
3796 ndev = dhd_idx2net(dhdp, ifidx);
3797 dhd_tx_dump(ndev, dhdp->osh, pktbuf);
3799 /* terence 20150901: Micky add to ajust the 802.1X priority */
3800 /* Set the 802.1X packet with the highest priority 7 */
3801 if (dhdp->conf->pktprio8021x >= 0)
3802 pktset8021xprio(pktbuf, dhdp->conf->pktprio8021x);
3804 #ifdef PROP_TXSTATUS
3805 if (dhd_wlfc_is_supported(dhdp)) {
3806 /* store the interface ID */
3807 DHD_PKTTAG_SETIF(PKTTAG(pktbuf), ifidx);
3809 /* store destination MAC in the tag as well */
3810 DHD_PKTTAG_SETDSTN(PKTTAG(pktbuf), eh->ether_dhost);
3812 /* decide which FIFO this packet belongs to */
3813 if (ETHER_ISMULTI(eh->ether_dhost))
3814 /* one additional queue index (highest AC + 1) is used for bc/mc queue */
3815 DHD_PKTTAG_SETFIFO(PKTTAG(pktbuf), AC_COUNT);
3817 DHD_PKTTAG_SETFIFO(PKTTAG(pktbuf), WME_PRIO2AC(PKTPRIO(pktbuf)));
3819 #endif /* PROP_TXSTATUS */
3821 /* If the protocol uses a data header, apply it */
3822 dhd_prot_hdrpush(dhdp, ifidx, pktbuf);
3825 /* Use bus module to send data frame */
3827 dhd_htsf_addtxts(dhdp, pktbuf);
3829 #ifdef PROP_TXSTATUS
3831 if (dhd_wlfc_commit_packets(dhdp, (f_commitpkt_t)dhd_bus_txdata,
3832 dhdp->bus, pktbuf, TRUE) == WLFC_UNSUPPORTED) {
3833 /* non-proptxstatus way */
3835 ret = dhd_bus_txdata(dhdp->bus, pktbuf, (uint8)ifidx);
3837 ret = dhd_bus_txdata(dhdp->bus, pktbuf);
3838 #endif /* BCMPCIE */
3843 ret = dhd_bus_txdata(dhdp->bus, pktbuf, (uint8)ifidx);
3845 ret = dhd_bus_txdata(dhdp->bus, pktbuf);
3846 #endif /* BCMPCIE */
3847 #endif /* PROP_TXSTATUS */
3853 dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pktbuf)
3856 unsigned long flags;
3858 DHD_GENERAL_LOCK(dhdp, flags);
3859 if (dhdp->busstate == DHD_BUS_DOWN ||
3860 dhdp->busstate == DHD_BUS_DOWN_IN_PROGRESS) {
3861 DHD_ERROR(("%s: returning as busstate=%d\n",
3862 __FUNCTION__, dhdp->busstate));
3863 DHD_GENERAL_UNLOCK(dhdp, flags);
3864 PKTCFREE(dhdp->osh, pktbuf, TRUE);
3867 dhdp->dhd_bus_busy_state |= DHD_BUS_BUSY_IN_SEND_PKT;
3868 DHD_GENERAL_UNLOCK(dhdp, flags);
3870 #ifdef DHD_PCIE_RUNTIMEPM
3871 if (dhdpcie_runtime_bus_wake(dhdp, FALSE, __builtin_return_address(0))) {
3872 DHD_ERROR(("%s : pcie is still in suspend state!!\n", __FUNCTION__));
3873 PKTCFREE(dhdp->osh, pktbuf, TRUE);
3877 #endif /* DHD_PCIE_RUNTIMEPM */
3879 ret = __dhd_sendpkt(dhdp, ifidx, pktbuf);
3881 #ifdef DHD_PCIE_RUNTIMEPM
3884 DHD_GENERAL_LOCK(dhdp, flags);
3885 dhdp->dhd_bus_busy_state &= ~DHD_BUS_BUSY_IN_SEND_PKT;
3886 DHD_GENERAL_UNLOCK(dhdp, flags);
3891 dhd_start_xmit(struct sk_buff *skb, struct net_device *net)
3896 dhd_info_t *dhd = DHD_DEV_INFO(net);
3897 dhd_if_t *ifp = NULL;
3899 unsigned long flags;
3901 uint8 htsfdlystat_sz = dhd->pub.htsfdlystat_sz;
3903 uint8 htsfdlystat_sz = 0;
3906 struct ether_header *eh;
3908 #endif /* DHD_WMF */
3910 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
3913 #ifdef PCIE_FULL_DONGLE
3914 DHD_GENERAL_LOCK(&dhd->pub, flags);
3915 dhd->pub.dhd_bus_busy_state |= DHD_BUS_BUSY_IN_TX;
3916 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
3917 #endif /* PCIE_FULL_DONGLE */
3919 #ifdef DHD_PCIE_RUNTIMEPM
3920 if (dhdpcie_runtime_bus_wake(&dhd->pub, FALSE, dhd_start_xmit)) {
3921 /* In order to avoid pkt loss. Return NETDEV_TX_BUSY until run-time resumed. */
3922 /* stop the network queue temporarily until resume done */
3923 DHD_GENERAL_LOCK(&dhd->pub, flags);
3924 if (!dhdpcie_is_resume_done(&dhd->pub)) {
3925 dhd_bus_stop_queue(dhd->pub.bus);
3927 dhd->pub.dhd_bus_busy_state &= ~DHD_BUS_BUSY_IN_TX;
3928 dhd_os_busbusy_wake(&dhd->pub);
3929 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
3930 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20))
3933 return NETDEV_TX_BUSY;
3936 #endif /* DHD_PCIE_RUNTIMEPM */
3938 DHD_GENERAL_LOCK(&dhd->pub, flags);
3939 #ifdef PCIE_FULL_DONGLE
3940 if (dhd->pub.busstate == DHD_BUS_SUSPEND) {
3941 dhd->pub.dhd_bus_busy_state &= ~DHD_BUS_BUSY_IN_TX;
3942 dhd_os_busbusy_wake(&dhd->pub);
3943 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
3944 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20))
3947 return NETDEV_TX_BUSY;
3950 #endif /* PCIE_FULL_DONGLE */
3952 DHD_OS_WAKE_LOCK(&dhd->pub);
3953 DHD_PERIM_LOCK_TRY(DHD_FWDER_UNIT(dhd), lock_taken);
3955 /* Reject if down */
3956 if (dhd->pub.hang_was_sent || dhd->pub.busstate == DHD_BUS_DOWN ||
3957 dhd->pub.busstate == DHD_BUS_DOWN_IN_PROGRESS) {
3958 DHD_ERROR(("%s: xmit rejected pub.up=%d busstate=%d \n",
3959 __FUNCTION__, dhd->pub.up, dhd->pub.busstate));
3960 netif_stop_queue(net);
3961 /* Send Event when bus down detected during data session */
3962 if (dhd->pub.up && !dhd->pub.hang_was_sent) {
3963 DHD_ERROR(("%s: Event HANG sent up\n", __FUNCTION__));
3964 dhd->pub.hang_reason = HANG_REASON_BUS_DOWN;
3965 net_os_send_hang_message(net);
3967 #ifdef PCIE_FULL_DONGLE
3968 dhd->pub.dhd_bus_busy_state &= ~DHD_BUS_BUSY_IN_TX;
3969 dhd_os_busbusy_wake(&dhd->pub);
3970 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
3971 #endif /* PCIE_FULL_DONGLE */
3972 DHD_PERIM_UNLOCK_TRY(DHD_FWDER_UNIT(dhd), lock_taken);
3973 DHD_OS_WAKE_UNLOCK(&dhd->pub);
3974 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20))
3977 return NETDEV_TX_BUSY;
3981 ifp = DHD_DEV_IFP(net);
3982 ifidx = DHD_DEV_IFIDX(net);
3983 BUZZZ_LOG(START_XMIT_BGN, 2, (uint32)ifidx, (uintptr)skb);
3985 if (ifidx == DHD_BAD_IF) {
3986 DHD_ERROR(("%s: bad ifidx %d\n", __FUNCTION__, ifidx));
3987 netif_stop_queue(net);
3988 #ifdef PCIE_FULL_DONGLE
3989 dhd->pub.dhd_bus_busy_state &= ~DHD_BUS_BUSY_IN_TX;
3990 dhd_os_busbusy_wake(&dhd->pub);
3991 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
3992 #endif /* PCIE_FULL_DONGLE */
3993 DHD_PERIM_UNLOCK_TRY(DHD_FWDER_UNIT(dhd), lock_taken);
3994 DHD_OS_WAKE_UNLOCK(&dhd->pub);
3995 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20))
3998 return NETDEV_TX_BUSY;
4001 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
4003 ASSERT(ifidx == dhd_net2idx(dhd, net));
4004 ASSERT((ifp != NULL) && ((ifidx < DHD_MAX_IFS) && (ifp == dhd->iflist[ifidx])));
4006 bcm_object_trace_opr(skb, BCM_OBJDBG_ADD_PKT, __FUNCTION__, __LINE__);
4008 /* re-align socket buffer if "skb->data" is odd address */
4009 if (((unsigned long)(skb->data)) & 0x1) {
4010 unsigned char *data = skb->data;
4011 uint32 length = skb->len;
4012 PKTPUSH(dhd->pub.osh, skb, 1);
4013 memmove(skb->data, data, length);
4014 PKTSETLEN(dhd->pub.osh, skb, length);
4017 datalen = PKTLEN(dhd->pub.osh, skb);
4019 /* Make sure there's enough room for any header */
4020 if (skb_headroom(skb) < dhd->pub.hdrlen + htsfdlystat_sz) {
4021 struct sk_buff *skb2;
4023 DHD_INFO(("%s: insufficient headroom\n",
4024 dhd_ifname(&dhd->pub, ifidx)));
4025 dhd->pub.tx_realloc++;
4027 bcm_object_trace_opr(skb, BCM_OBJDBG_REMOVE, __FUNCTION__, __LINE__);
4028 skb2 = skb_realloc_headroom(skb, dhd->pub.hdrlen + htsfdlystat_sz);
4031 if ((skb = skb2) == NULL) {
4032 DHD_ERROR(("%s: skb_realloc_headroom failed\n",
4033 dhd_ifname(&dhd->pub, ifidx)));
4037 bcm_object_trace_opr(skb, BCM_OBJDBG_ADD_PKT, __FUNCTION__, __LINE__);
4040 /* Convert to packet */
4041 if (!(pktbuf = PKTFRMNATIVE(dhd->pub.osh, skb))) {
4042 DHD_ERROR(("%s: PKTFRMNATIVE failed\n",
4043 dhd_ifname(&dhd->pub, ifidx)));
4044 bcm_object_trace_opr(skb, BCM_OBJDBG_REMOVE, __FUNCTION__, __LINE__);
4045 dev_kfree_skb_any(skb);
4050 #if defined(WLMEDIA_HTSF)
4051 if (htsfdlystat_sz && PKTLEN(dhd->pub.osh, pktbuf) >= ETHER_ADDR_LEN) {
4052 uint8 *pktdata = (uint8 *)PKTDATA(dhd->pub.osh, pktbuf);
4053 struct ether_header *eh = (struct ether_header *)pktdata;
4055 if (!ETHER_ISMULTI(eh->ether_dhost) &&
4056 (ntoh16(eh->ether_type) == ETHER_TYPE_IP)) {
4057 eh->ether_type = hton16(ETHER_TYPE_BRCM_PKTDLYSTATS);
4063 eh = (struct ether_header *)PKTDATA(dhd->pub.osh, pktbuf);
4064 iph = (uint8 *)eh + ETHER_HDR_LEN;
4066 /* WMF processing for multicast packets
4067 * Only IPv4 packets are handled
4069 if (ifp->wmf.wmf_enable && (ntoh16(eh->ether_type) == ETHER_TYPE_IP) &&
4070 (IP_VER(iph) == IP_VER_4) && (ETHER_ISMULTI(eh->ether_dhost) ||
4071 ((IPV4_PROT(iph) == IP_PROT_IGMP) && dhd->pub.wmf_ucast_igmp))) {
4072 #if defined(DHD_IGMP_UCQUERY) || defined(DHD_UCAST_UPNP)
4074 bool ucast_convert = FALSE;
4075 #ifdef DHD_UCAST_UPNP
4078 dest_ip = ntoh32(*((uint32 *)(iph + IPV4_DEST_IP_OFFSET)));
4079 ucast_convert = dhd->pub.wmf_ucast_upnp && MCAST_ADDR_UPNP_SSDP(dest_ip);
4080 #endif /* DHD_UCAST_UPNP */
4081 #ifdef DHD_IGMP_UCQUERY
4082 ucast_convert |= dhd->pub.wmf_ucast_igmp_query &&
4083 (IPV4_PROT(iph) == IP_PROT_IGMP) &&
4084 (*(iph + IPV4_HLEN(iph)) == IGMPV2_HOST_MEMBERSHIP_QUERY);
4085 #endif /* DHD_IGMP_UCQUERY */
4086 if (ucast_convert) {
4088 #ifdef PCIE_FULL_DONGLE
4089 unsigned long flags;
4091 struct list_head snapshot_list;
4092 struct list_head *wmf_ucforward_list;
4096 /* For non BCM_GMAC3 platform we need a snapshot sta_list to
4097 * resolve double DHD_IF_STA_LIST_LOCK call deadlock issue.
4099 wmf_ucforward_list = DHD_IF_WMF_UCFORWARD_LOCK(dhd, ifp, &snapshot_list);
4101 /* Convert upnp/igmp query to unicast for each assoc STA */
4102 list_for_each_entry(sta, wmf_ucforward_list, list) {
4103 if ((sdu_clone = PKTDUP(dhd->pub.osh, pktbuf)) == NULL) {
4107 dhd_wmf_forward(ifp->wmf.wmfh, sdu_clone, 0, sta, 1);
4109 DHD_IF_WMF_UCFORWARD_UNLOCK(dhd, wmf_ucforward_list);
4111 #ifdef PCIE_FULL_DONGLE
4112 DHD_GENERAL_LOCK(&dhd->pub, flags);
4113 dhd->pub.dhd_bus_busy_state &= ~DHD_BUS_BUSY_IN_TX;
4114 dhd_os_busbusy_wake(&dhd->pub);
4115 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
4116 #endif /* PCIE_FULL_DONGLE */
4117 DHD_PERIM_UNLOCK_TRY(DHD_FWDER_UNIT(dhd), lock_taken);
4118 DHD_OS_WAKE_UNLOCK(&dhd->pub);
4120 if (ret == NETDEV_TX_OK)
4121 PKTFREE(dhd->pub.osh, pktbuf, TRUE);
4125 #endif /* defined(DHD_IGMP_UCQUERY) || defined(DHD_UCAST_UPNP) */
4127 /* There will be no STA info if the packet is coming from LAN host
4130 ret = dhd_wmf_packets_handle(&dhd->pub, pktbuf, NULL, ifidx, 0);
4134 /* Either taken by WMF or we should drop it.
4137 #ifdef PCIE_FULL_DONGLE
4138 DHD_GENERAL_LOCK(&dhd->pub, flags);
4139 dhd->pub.dhd_bus_busy_state &= ~DHD_BUS_BUSY_IN_TX;
4140 dhd_os_busbusy_wake(&dhd->pub);
4141 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
4142 #endif /* PCIE_FULL_DONGLE */
4143 DHD_PERIM_UNLOCK_TRY(DHD_FWDER_UNIT(dhd), lock_taken);
4144 DHD_OS_WAKE_UNLOCK(&dhd->pub);
4145 return NETDEV_TX_OK;
4147 /* Continue the transmit path */
4152 #endif /* DHD_WMF */
4154 /* PSR related packet proto manipulation should be done in DHD
4155 * since dongle doesn't have complete payload
4157 if (PSR_ENABLED(&dhd->pub) && (dhd_psta_proc(&dhd->pub,
4158 ifidx, &pktbuf, TRUE) < 0)) {
4159 DHD_ERROR(("%s:%s: psta send proc failed\n", __FUNCTION__,
4160 dhd_ifname(&dhd->pub, ifidx)));
4162 #endif /* DHD_PSTA */
4164 #ifdef DHDTCPACK_SUPPRESS
4165 if (dhd->pub.tcpack_sup_mode == TCPACK_SUP_HOLD) {
4166 /* If this packet has been hold or got freed, just return */
4167 if (dhd_tcpack_hold(&dhd->pub, pktbuf, ifidx)) {
4172 /* If this packet has replaced another packet and got freed, just return */
4173 if (dhd_tcpack_suppress(&dhd->pub, pktbuf)) {
4178 #endif /* DHDTCPACK_SUPPRESS */
4180 /* no segmented SKB support (Kernel-3.18.y) */
4181 if ((PKTLINK(skb) != NULL) && (PKTLINK(skb) == skb)) {
4182 PKTSETLINK(skb, NULL);
4185 ret = __dhd_sendpkt(&dhd->pub, ifidx, pktbuf);
4189 ifp->stats.tx_dropped++;
4190 dhd->pub.tx_dropped++;
4193 #ifdef PROP_TXSTATUS
4194 /* tx_packets counter can counted only when wlfc is disabled */
4195 if (!dhd_wlfc_is_supported(&dhd->pub))
4198 dhd->pub.tx_packets++;
4199 ifp->stats.tx_packets++;
4200 ifp->stats.tx_bytes += datalen;
4204 #ifdef PCIE_FULL_DONGLE
4205 DHD_GENERAL_LOCK(&dhd->pub, flags);
4206 dhd->pub.dhd_bus_busy_state &= ~DHD_BUS_BUSY_IN_TX;
4207 dhd_os_busbusy_wake(&dhd->pub);
4208 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
4209 #endif /* PCIE_FULL_DONGLE */
4211 DHD_PERIM_UNLOCK_TRY(DHD_FWDER_UNIT(dhd), lock_taken);
4212 DHD_OS_WAKE_UNLOCK(&dhd->pub);
4213 BUZZZ_LOG(START_XMIT_END, 0);
4215 /* Return ok: we always eat the packet */
4216 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20))
4219 return NETDEV_TX_OK;
4225 dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool state)
4227 struct net_device *net;
4228 dhd_info_t *dhd = dhdp->info;
4231 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
4235 #ifdef DHD_LOSSLESS_ROAMING
4236 /* block flowcontrol during roaming */
4237 if ((dhdp->dequeue_prec_map == 1 << PRIO_8021D_NC) && state == ON) {
4242 if (ifidx == ALL_INTERFACES) {
4243 /* Flow control on all active interfaces */
4244 dhdp->txoff = state;
4245 for (i = 0; i < DHD_MAX_IFS; i++) {
4246 if (dhd->iflist[i]) {
4247 net = dhd->iflist[i]->net;
4249 netif_stop_queue(net);
4251 netif_wake_queue(net);
4255 if (dhd->iflist[ifidx]) {
4256 net = dhd->iflist[ifidx]->net;
4258 netif_stop_queue(net);
4260 netif_wake_queue(net);
4268 dhd_is_rxthread_enabled(dhd_pub_t *dhdp)
4270 dhd_info_t *dhd = dhdp->info;
4272 return dhd->rxthread_enabled;
4274 #endif /* DHD_WMF */
4276 /** Called when a frame is received by the dongle on interface 'ifidx' */
4278 dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *pktbuf, int numpkt, uint8 chan)
4280 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
4281 struct sk_buff *skb;
4284 void *data, *pnext = NULL;
4287 wl_event_msg_t event;
4290 void *skbhead = NULL;
4291 void *skbprev = NULL;
4292 #if defined(DHD_RX_DUMP) || defined(DHD_8021X_DUMP) || defined(DHD_DHCP_DUMP)
4296 #endif /* DHD_RX_DUMP || DHD_8021X_DUMP || DHD_DHCP_DUMP */
4298 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
4300 for (i = 0; pktbuf && i < numpkt; i++, pktbuf = pnext) {
4301 struct ether_header *eh;
4303 pnext = PKTNEXT(dhdp->osh, pktbuf);
4304 PKTSETNEXT(dhdp->osh, pktbuf, NULL);
4306 ifp = dhd->iflist[ifidx];
4308 DHD_ERROR(("%s: ifp is NULL. drop packet\n",
4310 PKTCFREE(dhdp->osh, pktbuf, FALSE);
4314 eh = (struct ether_header *)PKTDATA(dhdp->osh, pktbuf);
4316 /* Dropping only data packets before registering net device to avoid kernel panic */
4317 #ifndef PROP_TXSTATUS_VSDB
4318 if ((!ifp->net || ifp->net->reg_state != NETREG_REGISTERED) &&
4319 (ntoh16(eh->ether_type) != ETHER_TYPE_BRCM))
4321 if ((!ifp->net || ifp->net->reg_state != NETREG_REGISTERED || !dhd->pub.up) &&
4322 (ntoh16(eh->ether_type) != ETHER_TYPE_BRCM))
4323 #endif /* PROP_TXSTATUS_VSDB */
4325 DHD_ERROR(("%s: net device is NOT registered yet. drop packet\n",
4327 PKTCFREE(dhdp->osh, pktbuf, FALSE);
4332 #ifdef PROP_TXSTATUS
4333 if (dhd_wlfc_is_header_only_pkt(dhdp, pktbuf)) {
4334 /* WLFC may send header only packet when
4335 there is an urgent message but no packet to
4338 PKTCFREE(dhdp->osh, pktbuf, FALSE);
4342 #ifdef DHD_L2_FILTER
4343 /* If block_ping is enabled drop the ping packet */
4344 if (ifp->block_ping) {
4345 if (bcm_l2_filter_block_ping(dhdp->osh, pktbuf) == BCME_OK) {
4346 PKTCFREE(dhdp->osh, pktbuf, FALSE);
4350 if (ifp->grat_arp && DHD_IF_ROLE_STA(dhdp, ifidx)) {
4351 if (bcm_l2_filter_gratuitous_arp(dhdp->osh, pktbuf) == BCME_OK) {
4352 PKTCFREE(dhdp->osh, pktbuf, FALSE);
4356 if (ifp->parp_enable && DHD_IF_ROLE_AP(dhdp, ifidx)) {
4357 int ret = dhd_l2_filter_pkt_handle(dhdp, ifidx, pktbuf, FALSE);
4359 /* Drop the packets if l2 filter has processed it already
4360 * otherwise continue with the normal path
4362 if (ret == BCME_OK) {
4363 PKTCFREE(dhdp->osh, pktbuf, TRUE);
4367 #endif /* DHD_L2_FILTER */
4369 /* WMF processing for multicast packets */
4370 if (ifp->wmf.wmf_enable && (ETHER_ISMULTI(eh->ether_dhost))) {
4374 sta = dhd_find_sta(dhdp, ifidx, (void *)eh->ether_shost);
4375 ret = dhd_wmf_packets_handle(dhdp, pktbuf, sta, ifidx, 1);
4378 /* The packet is taken by WMF. Continue to next iteration */
4381 /* Packet DROP decision by WMF. Toss it */
4382 DHD_ERROR(("%s: WMF decides to drop packet\n",
4384 PKTCFREE(dhdp->osh, pktbuf, FALSE);
4387 /* Continue the transmit path */
4391 #endif /* DHD_WMF */
4393 #ifdef DHDTCPACK_SUPPRESS
4394 dhd_tcpdata_info_get(dhdp, pktbuf);
4396 skb = PKTTONATIVE(dhdp->osh, pktbuf);
4399 skb->dev = ifp->net;
4402 if (PSR_ENABLED(dhdp) && (dhd_psta_proc(dhdp, ifidx, &pktbuf, FALSE) < 0)) {
4403 DHD_ERROR(("%s:%s: psta recv proc failed\n", __FUNCTION__,
4404 dhd_ifname(dhdp, ifidx)));
4406 #endif /* DHD_PSTA */
4408 #ifdef PCIE_FULL_DONGLE
4409 if ((DHD_IF_ROLE_AP(dhdp, ifidx) || DHD_IF_ROLE_P2PGO(dhdp, ifidx)) &&
4410 (!ifp->ap_isolate)) {
4411 eh = (struct ether_header *)PKTDATA(dhdp->osh, pktbuf);
4412 if (ETHER_ISUCAST(eh->ether_dhost)) {
4413 if (dhd_find_sta(dhdp, ifidx, (void *)eh->ether_dhost)) {
4414 dhd_sendpkt(dhdp, ifidx, pktbuf);
4418 void *npktbuf = PKTDUP(dhdp->osh, pktbuf);
4420 dhd_sendpkt(dhdp, ifidx, npktbuf);
4423 #endif /* PCIE_FULL_DONGLE */
4425 /* Get the protocol, maintain skb around eth_type_trans()
4426 * The main reason for this hack is for the limitation of
4427 * Linux 2.4 where 'eth_type_trans' uses the 'net->hard_header_len'
4428 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
4429 * coping of the packet coming from the network stack to add
4430 * BDC, Hardware header etc, during network interface registration
4431 * we set the 'net->hard_header_len' to ETH_HLEN + extra space required
4432 * for BDC, Hardware header etc. and not just the ETH_HLEN
4437 #if defined(DHD_RX_DUMP) || defined(DHD_8021X_DUMP) || defined(DHD_DHCP_DUMP)
4438 dump_data = skb->data;
4439 protocol = (dump_data[12] << 8) | dump_data[13];
4440 ifname = skb->dev ? skb->dev->name : "N/A";
4441 #endif /* DHD_RX_DUMP || DHD_8021X_DUMP || DHD_DHCP_DUMP */
4442 #ifdef DHD_8021X_DUMP
4443 if (protocol == ETHER_TYPE_802_1X) {
4444 dhd_dump_eapol_4way_message(ifname, dump_data, FALSE);
4446 #endif /* DHD_8021X_DUMP */
4447 #ifdef DHD_DHCP_DUMP
4448 if (protocol != ETHER_TYPE_BRCM && protocol == ETHER_TYPE_IP) {
4452 uint16 udp_port_pos;
4453 uint8 *ptr8 = (uint8 *)&dump_data[ETHER_HDR_LEN];
4454 uint8 ip_header_len = (*ptr8 & 0x0f)<<2;
4456 udp_port_pos = ETHER_HDR_LEN + ip_header_len;
4457 source_port = (dump_data[udp_port_pos] << 8) | dump_data[udp_port_pos+1];
4458 dest_port = (dump_data[udp_port_pos+2] << 8) | dump_data[udp_port_pos+3];
4459 if (source_port == 0x0044 || dest_port == 0x0044) {
4460 dump_hex = (dump_data[udp_port_pos+249] << 8) |
4461 dump_data[udp_port_pos+250];
4462 if (dump_hex == 0x0101) {
4463 DHD_ERROR(("DHCP[%s] - DISCOVER [RX]\n", ifname));
4464 } else if (dump_hex == 0x0102) {
4465 DHD_ERROR(("DHCP[%s] - OFFER [RX]\n", ifname));
4466 } else if (dump_hex == 0x0103) {
4467 DHD_ERROR(("DHCP[%s] - REQUEST [RX]\n", ifname));
4468 } else if (dump_hex == 0x0105) {
4469 DHD_ERROR(("DHCP[%s] - ACK [RX]\n", ifname));
4471 DHD_ERROR(("DHCP[%s] - 0x%X [RX]\n", ifname, dump_hex));
4473 } else if (source_port == 0x0043 || dest_port == 0x0043) {
4474 DHD_ERROR(("DHCP[%s] - BOOTP [RX]\n", ifname));
4477 #endif /* DHD_DHCP_DUMP */
4478 #if defined(DHD_RX_DUMP)
4479 DHD_ERROR(("RX DUMP[%s] - %s\n", ifname, _get_packet_type_str(protocol)));
4480 if (protocol != ETHER_TYPE_BRCM) {
4481 if (dump_data[0] == 0xFF) {
4482 DHD_ERROR(("%s: BROADCAST\n", __FUNCTION__));
4484 if ((dump_data[12] == 8) &&
4485 (dump_data[13] == 6)) {
4486 DHD_ERROR(("%s: ARP %d\n",
4487 __FUNCTION__, dump_data[0x15]));
4489 } else if (dump_data[0] & 1) {
4490 DHD_ERROR(("%s: MULTICAST: " MACDBG "\n",
4491 __FUNCTION__, MAC2STRDBG(dump_data)));
4493 #ifdef DHD_RX_FULL_DUMP
4496 for (k = 0; k < skb->len; k++) {
4497 printk("%02X ", dump_data[k]);
4503 #endif /* DHD_RX_FULL_DUMP */
4505 #endif /* DHD_RX_DUMP */
4507 skb->protocol = eth_type_trans(skb, skb->dev);
4509 if (skb->pkt_type == PACKET_MULTICAST) {
4510 dhd->pub.rx_multicast++;
4511 ifp->stats.multicast++;
4518 dhd_htsf_addrxts(dhdp, pktbuf);
4520 /* Strip header, count, deliver upward */
4521 skb_pull(skb, ETH_HLEN);
4523 /* Process special event packets and then discard them */
4524 memset(&event, 0, sizeof(event));
4525 if (ntoh16(skb->protocol) == ETHER_TYPE_BRCM) {
4526 dhd_wl_host_event(dhd, &ifidx,
4527 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 22)
4528 skb_mac_header(skb),
4531 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 22) */
4535 wl_event_to_host_order(&event);
4537 tout_ctrl = DHD_PACKET_TIMEOUT_MS;
4539 #if defined(PNO_SUPPORT)
4540 if (event.event_type == WLC_E_PFN_NET_FOUND) {
4541 /* enforce custom wake lock to garantee that Kernel not suspended */
4542 tout_ctrl = CUSTOM_PNO_EVENT_LOCK_xTIME * DHD_PACKET_TIMEOUT_MS;
4544 #endif /* PNO_SUPPORT */
4546 #ifdef DHD_DONOT_FORWARD_BCMEVENT_AS_NETWORK_PKT
4547 #ifdef DHD_USE_STATIC_CTRLBUF
4548 PKTFREE_STATIC(dhdp->osh, pktbuf, FALSE);
4550 PKTFREE(dhdp->osh, pktbuf, FALSE);
4551 #endif /* DHD_USE_STATIC_CTRLBUF */
4553 #endif /* DHD_DONOT_FORWARD_BCMEVENT_AS_NETWORK_PKT */
4555 tout_rx = DHD_PACKET_TIMEOUT_MS;
4557 #ifdef PROP_TXSTATUS
4558 dhd_wlfc_save_rxpath_ac_time(dhdp, (uint8)PKTPRIO(skb));
4559 #endif /* PROP_TXSTATUS */
4562 ASSERT(ifidx < DHD_MAX_IFS && dhd->iflist[ifidx]);
4563 ifp = dhd->iflist[ifidx];
4566 ifp->net->last_rx = jiffies;
4568 if (ntoh16(skb->protocol) != ETHER_TYPE_BRCM) {
4569 dhdp->dstats.rx_bytes += skb->len;
4570 dhdp->rx_packets++; /* Local count */
4571 ifp->stats.rx_bytes += skb->len;
4572 ifp->stats.rx_packets++;
4575 if (in_interrupt()) {
4576 bcm_object_trace_opr(skb, BCM_OBJDBG_REMOVE,
4577 __FUNCTION__, __LINE__);
4578 DHD_PERIM_UNLOCK_ALL((dhd->fwder_unit % FWDER_MAX_UNIT));
4579 #if defined(DHD_LB) && defined(DHD_LB_RXP)
4580 netif_receive_skb(skb);
4583 #endif /* !defined(DHD_LB) && !defined(DHD_LB_RXP) */
4584 DHD_PERIM_LOCK_ALL((dhd->fwder_unit % FWDER_MAX_UNIT));
4586 if (dhd->rxthread_enabled) {
4590 PKTSETNEXT(dhdp->osh, skbprev, skb);
4594 /* If the receive is not processed inside an ISR,
4595 * the softirqd must be woken explicitly to service
4596 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
4597 * by netif_rx_ni(), but in earlier kernels, we need
4598 * to do it manually.
4600 bcm_object_trace_opr(skb, BCM_OBJDBG_REMOVE,
4601 __FUNCTION__, __LINE__);
4603 #if defined(DHD_LB) && defined(DHD_LB_RXP)
4604 DHD_PERIM_UNLOCK_ALL((dhd->fwder_unit % FWDER_MAX_UNIT));
4605 netif_receive_skb(skb);
4606 DHD_PERIM_LOCK_ALL((dhd->fwder_unit % FWDER_MAX_UNIT));
4608 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
4609 DHD_PERIM_UNLOCK_ALL((dhd->fwder_unit % FWDER_MAX_UNIT));
4611 DHD_PERIM_LOCK_ALL((dhd->fwder_unit % FWDER_MAX_UNIT));
4614 DHD_PERIM_UNLOCK_ALL((dhd->fwder_unit % FWDER_MAX_UNIT));
4616 DHD_PERIM_LOCK_ALL((dhd->fwder_unit % FWDER_MAX_UNIT));
4617 local_irq_save(flags);
4619 local_irq_restore(flags);
4620 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) */
4621 #endif /* !defined(DHD_LB) && !defined(DHD_LB_RXP) */
4626 if (dhd->rxthread_enabled && skbhead)
4627 dhd_sched_rxf(dhdp, skbhead);
4629 DHD_OS_WAKE_LOCK_RX_TIMEOUT_ENABLE(dhdp, tout_rx);
4630 DHD_OS_WAKE_LOCK_CTRL_TIMEOUT_ENABLE(dhdp, tout_ctrl);
4631 DHD_OS_WAKE_LOCK_TIMEOUT(dhdp);
4635 dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx)
4637 /* Linux version has nothing to do */
4642 dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success)
4644 dhd_info_t *dhd = (dhd_info_t *)(dhdp->info);
4645 struct ether_header *eh;
4648 dhd_prot_hdrpull(dhdp, NULL, txp, NULL, NULL);
4650 eh = (struct ether_header *)PKTDATA(dhdp->osh, txp);
4651 type = ntoh16(eh->ether_type);
4653 if ((type == ETHER_TYPE_802_1X) && (dhd_get_pend_8021x_cnt(dhd) > 0))
4654 atomic_dec(&dhd->pend_8021x_cnt);
4656 #ifdef PROP_TXSTATUS
4657 if (dhdp->wlfc_state && (dhdp->proptxstatus_mode != WLFC_FCMODE_NONE)) {
4658 dhd_if_t *ifp = dhd->iflist[DHD_PKTTAG_IF(PKTTAG(txp))];
4659 uint datalen = PKTLEN(dhd->pub.osh, txp);
4662 dhd->pub.tx_packets++;
4663 ifp->stats.tx_packets++;
4664 ifp->stats.tx_bytes += datalen;
4666 ifp->stats.tx_dropped++;
4673 static struct net_device_stats *
4674 dhd_get_stats(struct net_device *net)
4676 dhd_info_t *dhd = DHD_DEV_INFO(net);
4680 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
4682 ifidx = dhd_net2idx(dhd, net);
4683 if (ifidx == DHD_BAD_IF) {
4684 DHD_ERROR(("%s: BAD_IF\n", __FUNCTION__));
4686 memset(&net->stats, 0, sizeof(net->stats));
4690 ifp = dhd->iflist[ifidx];
4694 /* Use the protocol to get dongle stats */
4695 dhd_prot_dstats(&dhd->pub);
4701 dhd_watchdog_thread(void *data)
4703 tsk_ctl_t *tsk = (tsk_ctl_t *)data;
4704 dhd_info_t *dhd = (dhd_info_t *)tsk->parent;
4705 /* This thread doesn't need any user-level access,
4706 * so get rid of all our resources
4708 if (dhd_watchdog_prio > 0) {
4709 struct sched_param param;
4710 param.sched_priority = (dhd_watchdog_prio < MAX_RT_PRIO)?
4711 dhd_watchdog_prio:(MAX_RT_PRIO-1);
4712 setScheduler(current, SCHED_FIFO, ¶m);
4716 if (down_interruptible (&tsk->sema) == 0) {
4717 unsigned long flags;
4718 unsigned long jiffies_at_start = jiffies;
4719 unsigned long time_lapse;
4721 DHD_OS_WD_WAKE_LOCK(&dhd->pub);
4722 SMP_RD_BARRIER_DEPENDS();
4723 if (tsk->terminated) {
4727 if (dhd->pub.dongle_reset == FALSE) {
4728 DHD_TIMER(("%s:\n", __FUNCTION__));
4729 dhd_bus_watchdog(&dhd->pub);
4731 DHD_GENERAL_LOCK(&dhd->pub, flags);
4732 /* Count the tick for reference */
4734 #ifdef DHD_L2_FILTER
4735 dhd_l2_filter_watchdog(&dhd->pub);
4736 #endif /* DHD_L2_FILTER */
4737 time_lapse = jiffies - jiffies_at_start;
4739 /* Reschedule the watchdog */
4740 if (dhd->wd_timer_valid) {
4741 mod_timer(&dhd->timer,
4743 msecs_to_jiffies(dhd_watchdog_ms) -
4744 min(msecs_to_jiffies(dhd_watchdog_ms), time_lapse));
4746 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
4748 DHD_OS_WD_WAKE_UNLOCK(&dhd->pub);
4754 complete_and_exit(&tsk->completed, 0);
4757 static void dhd_watchdog(ulong data)
4759 dhd_info_t *dhd = (dhd_info_t *)data;
4760 unsigned long flags;
4762 if (dhd->pub.dongle_reset) {
4766 if (dhd->pub.busstate == DHD_BUS_SUSPEND) {
4767 DHD_ERROR(("%s wd while suspend in progress \n", __FUNCTION__));
4771 if (dhd->thr_wdt_ctl.thr_pid >= 0) {
4772 up(&dhd->thr_wdt_ctl.sema);
4776 DHD_OS_WD_WAKE_LOCK(&dhd->pub);
4777 /* Call the bus module watchdog */
4778 dhd_bus_watchdog(&dhd->pub);
4779 DHD_GENERAL_LOCK(&dhd->pub, flags);
4780 /* Count the tick for reference */
4783 #ifdef DHD_L2_FILTER
4784 dhd_l2_filter_watchdog(&dhd->pub);
4785 #endif /* DHD_L2_FILTER */
4786 /* Reschedule the watchdog */
4787 if (dhd->wd_timer_valid)
4788 mod_timer(&dhd->timer, jiffies + msecs_to_jiffies(dhd_watchdog_ms));
4789 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
4790 DHD_OS_WD_WAKE_UNLOCK(&dhd->pub);
4793 #ifdef DHD_PCIE_RUNTIMEPM
4795 dhd_rpm_state_thread(void *data)
4797 tsk_ctl_t *tsk = (tsk_ctl_t *)data;
4798 dhd_info_t *dhd = (dhd_info_t *)tsk->parent;
4801 if (down_interruptible (&tsk->sema) == 0) {
4802 unsigned long flags;
4803 unsigned long jiffies_at_start = jiffies;
4804 unsigned long time_lapse;
4806 SMP_RD_BARRIER_DEPENDS();
4807 if (tsk->terminated) {
4811 if (dhd->pub.dongle_reset == FALSE) {
4812 DHD_TIMER(("%s:\n", __FUNCTION__));
4814 dhd_runtimepm_state(&dhd->pub);
4817 DHD_GENERAL_LOCK(&dhd->pub, flags);
4818 time_lapse = jiffies - jiffies_at_start;
4820 /* Reschedule the watchdog */
4821 if (dhd->rpm_timer_valid) {
4822 mod_timer(&dhd->rpm_timer,
4824 msecs_to_jiffies(dhd_runtimepm_ms) -
4825 min(msecs_to_jiffies(dhd_runtimepm_ms),
4828 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
4835 complete_and_exit(&tsk->completed, 0);
4838 static void dhd_runtimepm(ulong data)
4840 dhd_info_t *dhd = (dhd_info_t *)data;
4842 if (dhd->pub.dongle_reset) {
4846 if (dhd->thr_rpm_ctl.thr_pid >= 0) {
4847 up(&dhd->thr_rpm_ctl.sema);
4852 void dhd_runtime_pm_disable(dhd_pub_t *dhdp)
4854 dhd_os_runtimepm_timer(dhdp, 0);
4855 dhdpcie_runtime_bus_wake(dhdp, TRUE, __builtin_return_address(0));
4856 DHD_ERROR(("DHD Runtime PM Disabled \n"));
4859 void dhd_runtime_pm_enable(dhd_pub_t *dhdp)
4861 dhd_os_runtimepm_timer(dhdp, dhd_runtimepm_ms);
4862 DHD_ERROR(("DHD Runtime PM Enabled \n"));
4865 #endif /* DHD_PCIE_RUNTIMEPM */
4868 #ifdef ENABLE_ADAPTIVE_SCHED
4870 dhd_sched_policy(int prio)
4872 struct sched_param param;
4873 if (cpufreq_quick_get(0) <= CUSTOM_CPUFREQ_THRESH) {
4874 param.sched_priority = 0;
4875 setScheduler(current, SCHED_NORMAL, ¶m);
4877 if (get_scheduler_policy(current) != SCHED_FIFO) {
4878 param.sched_priority = (prio < MAX_RT_PRIO)? prio : (MAX_RT_PRIO-1);
4879 setScheduler(current, SCHED_FIFO, ¶m);
4883 #endif /* ENABLE_ADAPTIVE_SCHED */
4884 #ifdef DEBUG_CPU_FREQ
4885 static int dhd_cpufreq_notifier(struct notifier_block *nb, unsigned long val, void *data)
4887 dhd_info_t *dhd = container_of(nb, struct dhd_info, freq_trans);
4888 struct cpufreq_freqs *freq = data;
4892 if (val == CPUFREQ_POSTCHANGE) {
4893 DHD_ERROR(("cpu freq is changed to %u kHZ on CPU %d\n",
4894 freq->new, freq->cpu));
4895 *per_cpu_ptr(dhd->new_freq, freq->cpu) = freq->new;
4901 #endif /* DEBUG_CPU_FREQ */
4903 dhd_dpc_thread(void *data)
4905 tsk_ctl_t *tsk = (tsk_ctl_t *)data;
4906 dhd_info_t *dhd = (dhd_info_t *)tsk->parent;
4908 /* This thread doesn't need any user-level access,
4909 * so get rid of all our resources
4911 if (dhd_dpc_prio > 0)
4913 struct sched_param param;
4914 param.sched_priority = (dhd_dpc_prio < MAX_RT_PRIO)?dhd_dpc_prio:(MAX_RT_PRIO-1);
4915 setScheduler(current, SCHED_FIFO, ¶m);
4918 #ifdef CUSTOM_DPC_CPUCORE
4919 set_cpus_allowed_ptr(current, cpumask_of(CUSTOM_DPC_CPUCORE));
4921 if (dhd->pub.conf->dpc_cpucore >= 0) {
4922 printf("%s: set dpc_cpucore %d from config.txt\n", __FUNCTION__, dhd->pub.conf->dpc_cpucore);
4923 set_cpus_allowed_ptr(current, cpumask_of(dhd->pub.conf->dpc_cpucore));
4926 #ifdef CUSTOM_SET_CPUCORE
4927 dhd->pub.current_dpc = current;
4928 #endif /* CUSTOM_SET_CPUCORE */
4929 /* Run until signal received */
4931 if (!binary_sema_down(tsk)) {
4932 #ifdef ENABLE_ADAPTIVE_SCHED
4933 dhd_sched_policy(dhd_dpc_prio);
4934 #endif /* ENABLE_ADAPTIVE_SCHED */
4935 SMP_RD_BARRIER_DEPENDS();
4936 if (tsk->terminated) {
4940 /* Call bus dpc unless it indicated down (then clean stop) */
4941 if (dhd->pub.busstate != DHD_BUS_DOWN) {
4942 #ifdef DEBUG_DPC_THREAD_WATCHDOG
4943 int resched_cnt = 0;
4944 #endif /* DEBUG_DPC_THREAD_WATCHDOG */
4945 dhd_os_wd_timer_extend(&dhd->pub, TRUE);
4946 while (dhd_bus_dpc(dhd->pub.bus)) {
4947 /* process all data */
4948 #ifdef DEBUG_DPC_THREAD_WATCHDOG
4950 if (resched_cnt > MAX_RESCHED_CNT) {
4951 DHD_INFO(("%s Calling msleep to"
4952 "let other processes run. \n",
4954 dhd->pub.dhd_bug_on = true;
4958 #endif /* DEBUG_DPC_THREAD_WATCHDOG */
4960 dhd_os_wd_timer_extend(&dhd->pub, FALSE);
4961 DHD_OS_WAKE_UNLOCK(&dhd->pub);
4964 dhd_bus_stop(dhd->pub.bus, TRUE);
4965 DHD_OS_WAKE_UNLOCK(&dhd->pub);
4971 complete_and_exit(&tsk->completed, 0);
4975 dhd_rxf_thread(void *data)
4977 tsk_ctl_t *tsk = (tsk_ctl_t *)data;
4978 dhd_info_t *dhd = (dhd_info_t *)tsk->parent;
4979 #if defined(WAIT_DEQUEUE)
4980 #define RXF_WATCHDOG_TIME 250 /* BARK_TIME(1000) / */
4981 ulong watchdogTime = OSL_SYSUPTIME(); /* msec */
4983 dhd_pub_t *pub = &dhd->pub;
4985 /* This thread doesn't need any user-level access,
4986 * so get rid of all our resources
4988 if (dhd_rxf_prio > 0)
4990 struct sched_param param;
4991 param.sched_priority = (dhd_rxf_prio < MAX_RT_PRIO)?dhd_rxf_prio:(MAX_RT_PRIO-1);
4992 setScheduler(current, SCHED_FIFO, ¶m);
4995 DAEMONIZE("dhd_rxf");
4996 /* DHD_OS_WAKE_LOCK is called in dhd_sched_dpc[dhd_linux.c] down below */
4998 /* signal: thread has started */
4999 complete(&tsk->completed);
5000 #ifdef CUSTOM_SET_CPUCORE
5001 dhd->pub.current_rxf = current;
5002 #endif /* CUSTOM_SET_CPUCORE */
5003 /* Run until signal received */
5005 if (down_interruptible(&tsk->sema) == 0) {
5007 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
5010 #ifdef ENABLE_ADAPTIVE_SCHED
5011 dhd_sched_policy(dhd_rxf_prio);
5012 #endif /* ENABLE_ADAPTIVE_SCHED */
5014 SMP_RD_BARRIER_DEPENDS();
5016 if (tsk->terminated) {
5019 skb = dhd_rxf_dequeue(pub);
5025 void *skbnext = PKTNEXT(pub->osh, skb);
5026 PKTSETNEXT(pub->osh, skb, NULL);
5027 bcm_object_trace_opr(skb, BCM_OBJDBG_REMOVE,
5028 __FUNCTION__, __LINE__);
5029 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
5033 local_irq_save(flags);
5035 local_irq_restore(flags);
5040 #if defined(WAIT_DEQUEUE)
5041 if (OSL_SYSUPTIME() - watchdogTime > RXF_WATCHDOG_TIME) {
5043 watchdogTime = OSL_SYSUPTIME();
5047 DHD_OS_WAKE_UNLOCK(pub);
5052 complete_and_exit(&tsk->completed, 0);
5056 void dhd_dpc_enable(dhd_pub_t *dhdp)
5060 if (!dhdp || !dhdp->info)
5066 __skb_queue_head_init(&dhd->rx_pend_queue);
5067 #endif /* DHD_LB_RXP */
5069 if (atomic_read(&dhd->tx_compl_tasklet.count) == 1)
5070 tasklet_enable(&dhd->tx_compl_tasklet);
5071 #endif /* DHD_LB_TXC */
5073 if (atomic_read(&dhd->rx_compl_tasklet.count) == 1)
5074 tasklet_enable(&dhd->rx_compl_tasklet);
5075 #endif /* DHD_LB_RXC */
5077 if (atomic_read(&dhd->tasklet.count) == 1)
5078 tasklet_enable(&dhd->tasklet);
5080 #endif /* BCMPCIE */
5085 dhd_dpc_kill(dhd_pub_t *dhdp)
5099 if (dhd->thr_dpc_ctl.thr_pid < 0) {
5100 tasklet_disable(&dhd->tasklet);
5101 tasklet_kill(&dhd->tasklet);
5102 DHD_ERROR(("%s: tasklet disabled\n", __FUNCTION__));
5106 __skb_queue_purge(&dhd->rx_pend_queue);
5107 #endif /* DHD_LB_RXP */
5108 /* Kill the Load Balancing Tasklets */
5109 #if defined(DHD_LB_TXC)
5110 tasklet_disable(&dhd->tx_compl_tasklet);
5111 tasklet_kill(&dhd->tx_compl_tasklet);
5112 #endif /* DHD_LB_TXC */
5113 #if defined(DHD_LB_RXC)
5114 tasklet_disable(&dhd->rx_compl_tasklet);
5115 tasklet_kill(&dhd->rx_compl_tasklet);
5116 #endif /* DHD_LB_RXC */
5119 #endif /* BCMPCIE */
5126 dhd = (dhd_info_t *)data;
5128 /* this (tasklet) can be scheduled in dhd_sched_dpc[dhd_linux.c]
5129 * down below , wake lock is set,
5130 * the tasklet is initialized in dhd_attach()
5132 /* Call bus dpc unless it indicated down (then clean stop) */
5133 if (dhd->pub.busstate != DHD_BUS_DOWN) {
5134 if (dhd_bus_dpc(dhd->pub.bus)) {
5135 DHD_LB_STATS_INCR(dhd->dhd_dpc_cnt);
5136 tasklet_schedule(&dhd->tasklet);
5139 dhd_bus_stop(dhd->pub.bus, TRUE);
5144 dhd_sched_dpc(dhd_pub_t *dhdp)
5146 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
5148 if (dhd->thr_dpc_ctl.thr_pid >= 0) {
5149 DHD_OS_WAKE_LOCK(dhdp);
5150 /* If the semaphore does not get up,
5151 * wake unlock should be done here
5153 if (!binary_sema_up(&dhd->thr_dpc_ctl)) {
5154 DHD_OS_WAKE_UNLOCK(dhdp);
5158 tasklet_schedule(&dhd->tasklet);
5163 dhd_sched_rxf(dhd_pub_t *dhdp, void *skb)
5165 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
5166 #ifdef RXF_DEQUEUE_ON_BUSY
5169 #endif /* RXF_DEQUEUE_ON_BUSY */
5171 DHD_OS_WAKE_LOCK(dhdp);
5173 DHD_TRACE(("dhd_sched_rxf: Enter\n"));
5174 #ifdef RXF_DEQUEUE_ON_BUSY
5176 ret = dhd_rxf_enqueue(dhdp, skb);
5177 if (ret == BCME_OK || ret == BCME_ERROR)
5180 OSL_SLEEP(50); /* waiting for dequeueing */
5181 } while (retry-- > 0);
5183 if (retry <= 0 && ret == BCME_BUSY) {
5187 void *skbnext = PKTNEXT(dhdp->osh, skbp);
5188 PKTSETNEXT(dhdp->osh, skbp, NULL);
5189 bcm_object_trace_opr(skb, BCM_OBJDBG_REMOVE,
5190 __FUNCTION__, __LINE__);
5194 DHD_ERROR(("send skb to kernel backlog without rxf_thread\n"));
5196 if (dhd->thr_rxf_ctl.thr_pid >= 0) {
5197 up(&dhd->thr_rxf_ctl.sema);
5200 #else /* RXF_DEQUEUE_ON_BUSY */
5202 if (dhd_rxf_enqueue(dhdp, skb) == BCME_OK)
5205 if (dhd->thr_rxf_ctl.thr_pid >= 0) {
5206 up(&dhd->thr_rxf_ctl.sema);
5209 #endif /* RXF_DEQUEUE_ON_BUSY */
5212 #if defined(BCM_DNGL_EMBEDIMAGE) || defined(BCM_REQUEST_FW)
5213 #endif /* defined(BCM_DNGL_EMBEDIMAGE) || defined(BCM_REQUEST_FW) */
5216 /* Retrieve current toe component enables, which are kept as a bitmap in toe_ol iovar */
5218 dhd_toe_get(dhd_info_t *dhd, int ifidx, uint32 *toe_ol)
5224 memset(&ioc, 0, sizeof(ioc));
5226 ioc.cmd = WLC_GET_VAR;
5228 ioc.len = (uint)sizeof(buf);
5231 strncpy(buf, "toe_ol", sizeof(buf) - 1);
5232 buf[sizeof(buf) - 1] = '\0';
5233 if ((ret = dhd_wl_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len)) < 0) {
5234 /* Check for older dongle image that doesn't support toe_ol */
5236 DHD_ERROR(("%s: toe not supported by device\n",
5237 dhd_ifname(&dhd->pub, ifidx)));
5241 DHD_INFO(("%s: could not get toe_ol: ret=%d\n", dhd_ifname(&dhd->pub, ifidx), ret));
5245 memcpy(toe_ol, buf, sizeof(uint32));
5249 /* Set current toe component enables in toe_ol iovar, and set toe global enable iovar */
5251 dhd_toe_set(dhd_info_t *dhd, int ifidx, uint32 toe_ol)
5257 memset(&ioc, 0, sizeof(ioc));
5259 ioc.cmd = WLC_SET_VAR;
5261 ioc.len = (uint)sizeof(buf);
5264 /* Set toe_ol as requested */
5266 strncpy(buf, "toe_ol", sizeof(buf) - 1);
5267 buf[sizeof(buf) - 1] = '\0';
5268 memcpy(&buf[sizeof("toe_ol")], &toe_ol, sizeof(uint32));
5270 if ((ret = dhd_wl_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len)) < 0) {
5271 DHD_ERROR(("%s: could not set toe_ol: ret=%d\n",
5272 dhd_ifname(&dhd->pub, ifidx), ret));
5276 /* Enable toe globally only if any components are enabled. */
5278 toe = (toe_ol != 0);
5281 memcpy(&buf[sizeof("toe")], &toe, sizeof(uint32));
5283 if ((ret = dhd_wl_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len)) < 0) {
5284 DHD_ERROR(("%s: could not set toe: ret=%d\n", dhd_ifname(&dhd->pub, ifidx), ret));
5292 #if defined(WL_CFG80211) && defined(NUM_SCB_MAX_PROBE)
5293 void dhd_set_scb_probe(dhd_pub_t *dhd)
5296 wl_scb_probe_t scb_probe;
5297 char iovbuf[WL_EVENTING_MASK_LEN + sizeof(wl_scb_probe_t)];
5299 memset(&scb_probe, 0, sizeof(wl_scb_probe_t));
5301 if (dhd->op_mode & DHD_FLAG_HOSTAP_MODE) {
5305 bcm_mkiovar("scb_probe", NULL, 0, iovbuf, sizeof(iovbuf));
5307 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_GET_VAR, iovbuf, sizeof(iovbuf), FALSE, 0)) < 0) {
5308 DHD_ERROR(("%s: GET max_scb_probe failed\n", __FUNCTION__));
5311 memcpy(&scb_probe, iovbuf, sizeof(wl_scb_probe_t));
5313 scb_probe.scb_max_probe = NUM_SCB_MAX_PROBE;
5315 bcm_mkiovar("scb_probe", (char *)&scb_probe,
5316 sizeof(wl_scb_probe_t), iovbuf, sizeof(iovbuf));
5317 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0)) < 0) {
5318 DHD_ERROR(("%s: max_scb_probe setting failed\n", __FUNCTION__));
5322 #endif /* WL_CFG80211 && NUM_SCB_MAX_PROBE */
5324 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
5326 dhd_ethtool_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *info)
5328 dhd_info_t *dhd = DHD_DEV_INFO(net);
5330 snprintf(info->driver, sizeof(info->driver), "wl");
5331 snprintf(info->version, sizeof(info->version), "%lu", dhd->pub.drv_version);
5334 struct ethtool_ops dhd_ethtool_ops = {
5335 .get_drvinfo = dhd_ethtool_get_drvinfo
5337 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) */
5340 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 4, 2)
5342 dhd_ethtool(dhd_info_t *dhd, void *uaddr)
5344 struct ethtool_drvinfo info;
5345 char drvname[sizeof(info.driver)];
5348 struct ethtool_value edata;
5349 uint32 toe_cmpnt, csum_dir;
5353 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
5355 /* all ethtool calls start with a cmd word */
5356 if (copy_from_user(&cmd, uaddr, sizeof (uint32)))
5360 case ETHTOOL_GDRVINFO:
5361 /* Copy out any request driver name */
5362 if (copy_from_user(&info, uaddr, sizeof(info)))
5364 strncpy(drvname, info.driver, sizeof(info.driver));
5365 drvname[sizeof(info.driver)-1] = '\0';
5367 /* clear struct for return */
5368 memset(&info, 0, sizeof(info));
5371 /* if dhd requested, identify ourselves */
5372 if (strcmp(drvname, "?dhd") == 0) {
5373 snprintf(info.driver, sizeof(info.driver), "dhd");
5374 strncpy(info.version, EPI_VERSION_STR, sizeof(info.version) - 1);
5375 info.version[sizeof(info.version) - 1] = '\0';
5378 /* otherwise, require dongle to be up */
5379 else if (!dhd->pub.up) {
5380 DHD_ERROR(("%s: dongle is not up\n", __FUNCTION__));
5384 /* finally, report dongle driver type */
5385 else if (dhd->pub.iswl)
5386 snprintf(info.driver, sizeof(info.driver), "wl");
5388 snprintf(info.driver, sizeof(info.driver), "xx");
5390 snprintf(info.version, sizeof(info.version), "%lu", dhd->pub.drv_version);
5391 if (copy_to_user(uaddr, &info, sizeof(info)))
5393 DHD_CTL(("%s: given %*s, returning %s\n", __FUNCTION__,
5394 (int)sizeof(drvname), drvname, info.driver));
5398 /* Get toe offload components from dongle */
5399 case ETHTOOL_GRXCSUM:
5400 case ETHTOOL_GTXCSUM:
5401 if ((ret = dhd_toe_get(dhd, 0, &toe_cmpnt)) < 0)
5404 csum_dir = (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
5407 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
5409 if (copy_to_user(uaddr, &edata, sizeof(edata)))
5413 /* Set toe offload components in dongle */
5414 case ETHTOOL_SRXCSUM:
5415 case ETHTOOL_STXCSUM:
5416 if (copy_from_user(&edata, uaddr, sizeof(edata)))
5419 /* Read the current settings, update and write back */
5420 if ((ret = dhd_toe_get(dhd, 0, &toe_cmpnt)) < 0)
5423 csum_dir = (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
5425 if (edata.data != 0)
5426 toe_cmpnt |= csum_dir;
5428 toe_cmpnt &= ~csum_dir;
5430 if ((ret = dhd_toe_set(dhd, 0, toe_cmpnt)) < 0)
5433 /* If setting TX checksum mode, tell Linux the new mode */
5434 if (cmd == ETHTOOL_STXCSUM) {
5436 dhd->iflist[0]->net->features |= NETIF_F_IP_CSUM;
5438 dhd->iflist[0]->net->features &= ~NETIF_F_IP_CSUM;
5450 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 4, 2) */
5452 static bool dhd_check_hang(struct net_device *net, dhd_pub_t *dhdp, int error)
5457 DHD_ERROR(("%s: dhdp is NULL\n", __FUNCTION__));
5464 dhd = (dhd_info_t *)dhdp->info;
5465 #if !defined(BCMPCIE)
5466 if (dhd->thr_dpc_ctl.thr_pid < 0) {
5467 DHD_ERROR(("%s : skipped due to negative pid - unloading?\n", __FUNCTION__));
5472 if ((error == -ETIMEDOUT) || (error == -EREMOTEIO) ||
5473 ((dhdp->busstate == DHD_BUS_DOWN) && (!dhdp->dongle_reset))) {
5475 DHD_ERROR(("%s: Event HANG send up due to re=%d te=%d d3acke=%d e=%d s=%d\n",
5476 __FUNCTION__, dhdp->rxcnt_timeout, dhdp->txcnt_timeout,
5477 dhdp->d3ackcnt_timeout, error, dhdp->busstate));
5479 DHD_ERROR(("%s: Event HANG send up due to re=%d te=%d e=%d s=%d\n", __FUNCTION__,
5480 dhdp->rxcnt_timeout, dhdp->txcnt_timeout, error, dhdp->busstate));
5481 #endif /* BCMPCIE */
5482 if (dhdp->hang_reason == 0) {
5483 if (dhdp->dongle_trap_occured) {
5484 dhdp->hang_reason = HANG_REASON_DONGLE_TRAP;
5486 } else if (dhdp->d3ackcnt_timeout) {
5487 dhdp->hang_reason = HANG_REASON_D3_ACK_TIMEOUT;
5488 #endif /* BCMPCIE */
5490 dhdp->hang_reason = HANG_REASON_IOCTL_RESP_TIMEOUT;
5493 net_os_send_hang_message(net);
5499 int dhd_ioctl_process(dhd_pub_t *pub, int ifidx, dhd_ioctl_t *ioc, void *data_buf)
5501 int bcmerror = BCME_OK;
5503 struct net_device *net;
5505 net = dhd_idx2net(pub, ifidx);
5507 bcmerror = BCME_BADARG;
5512 buflen = MIN(ioc->len, DHD_IOCTL_MAXLEN);
5514 /* check for local dhd ioctl and handle it */
5515 if (ioc->driver == DHD_IOCTL_MAGIC) {
5516 bcmerror = dhd_ioctl((void *)pub, ioc, data_buf, buflen);
5518 pub->bcmerror = bcmerror;
5522 /* send to dongle (must be up, and wl). */
5523 if (pub->busstate == DHD_BUS_DOWN || pub->busstate == DHD_BUS_LOAD) {
5524 if (allow_delay_fwdl) {
5525 int ret = dhd_bus_start(pub);
5527 DHD_ERROR(("%s: failed with code %d\n", __FUNCTION__, ret));
5528 bcmerror = BCME_DONGLE_DOWN;
5532 bcmerror = BCME_DONGLE_DOWN;
5538 bcmerror = BCME_DONGLE_DOWN;
5543 * Flush the TX queue if required for proper message serialization:
5544 * Intercept WLC_SET_KEY IOCTL - serialize M4 send and set key IOCTL to
5545 * prevent M4 encryption and
5546 * intercept WLC_DISASSOC IOCTL - serialize WPS-DONE and WLC_DISASSOC IOCTL to
5547 * prevent disassoc frame being sent before WPS-DONE frame.
5549 if (ioc->cmd == WLC_SET_KEY ||
5550 (ioc->cmd == WLC_SET_VAR && data_buf != NULL &&
5551 strncmp("wsec_key", data_buf, 9) == 0) ||
5552 (ioc->cmd == WLC_SET_VAR && data_buf != NULL &&
5553 strncmp("bsscfg:wsec_key", data_buf, 15) == 0) ||
5554 ioc->cmd == WLC_DISASSOC)
5555 dhd_wait_pend8021x(net);
5559 /* short cut wl ioctl calls here */
5560 if (strcmp("htsf", data_buf) == 0) {
5561 dhd_ioctl_htsf_get(dhd, 0);
5565 if (strcmp("htsflate", data_buf) == 0) {
5567 memset(ts, 0, sizeof(tstamp_t)*TSMAX);
5568 memset(&maxdelayts, 0, sizeof(tstamp_t));
5572 memset(&vi_d1.bin, 0, sizeof(uint32)*NUMBIN);
5573 memset(&vi_d2.bin, 0, sizeof(uint32)*NUMBIN);
5574 memset(&vi_d3.bin, 0, sizeof(uint32)*NUMBIN);
5575 memset(&vi_d4.bin, 0, sizeof(uint32)*NUMBIN);
5581 if (strcmp("htsfclear", data_buf) == 0) {
5582 memset(&vi_d1.bin, 0, sizeof(uint32)*NUMBIN);
5583 memset(&vi_d2.bin, 0, sizeof(uint32)*NUMBIN);
5584 memset(&vi_d3.bin, 0, sizeof(uint32)*NUMBIN);
5585 memset(&vi_d4.bin, 0, sizeof(uint32)*NUMBIN);
5589 if (strcmp("htsfhis", data_buf) == 0) {
5590 dhd_dump_htsfhisto(&vi_d1, "H to D");
5591 dhd_dump_htsfhisto(&vi_d2, "D to D");
5592 dhd_dump_htsfhisto(&vi_d3, "D to H");
5593 dhd_dump_htsfhisto(&vi_d4, "H to H");
5596 if (strcmp("tsport", data_buf) == 0) {
5598 memcpy(&tsport, data_buf + 7, 4);
5600 DHD_ERROR(("current timestamp port: %d \n", tsport));
5605 #endif /* WLMEDIA_HTSF */
5607 if ((ioc->cmd == WLC_SET_VAR || ioc->cmd == WLC_GET_VAR) &&
5608 data_buf != NULL && strncmp("rpc_", data_buf, 4) == 0) {
5610 bcmerror = dhd_fdaggr_ioctl(pub, ifidx, (wl_ioctl_t *)ioc, data_buf, buflen);
5612 bcmerror = BCME_UNSUPPORTED;
5618 if (ioc->cmd != WLC_GET_MAGIC && ioc->cmd != WLC_GET_VERSION) {
5619 if (ioc->cmd == WLC_SET_VAR || ioc->cmd == WLC_GET_VAR) {
5620 /* Print IOVAR Information */
5621 DHD_IOV_INFO(("%s: IOVAR_INFO name = %s set = %d\n",
5622 __FUNCTION__, (char *)data_buf, ioc->set));
5623 if ((dhd_msg_level & DHD_IOV_INFO_VAL) && ioc->set && data_buf) {
5624 prhex(NULL, data_buf + strlen(data_buf) + 1,
5625 buflen - strlen(data_buf) - 1);
5628 /* Print IOCTL Information */
5629 DHD_IOV_INFO(("%s: IOCTL_INFO cmd = %d set = %d\n",
5630 __FUNCTION__, ioc->cmd, ioc->set));
5631 if ((dhd_msg_level & DHD_IOV_INFO_VAL) && ioc->set && data_buf) {
5632 prhex(NULL, data_buf, buflen);
5636 #endif /* DHD_DEBUG */
5638 bcmerror = dhd_wl_ioctl(pub, ifidx, (wl_ioctl_t *)ioc, data_buf, buflen);
5641 dhd_check_hang(net, pub, bcmerror);
5647 dhd_ioctl_entry(struct net_device *net, struct ifreq *ifr, int cmd)
5649 dhd_info_t *dhd = DHD_DEV_INFO(net);
5653 void *local_buf = NULL;
5656 DHD_OS_WAKE_LOCK(&dhd->pub);
5657 DHD_PERIM_LOCK(&dhd->pub);
5659 /* Interface up check for built-in type */
5660 if (!dhd_download_fw_on_driverload && dhd->pub.up == FALSE) {
5661 DHD_ERROR(("%s: Interface is down \n", __FUNCTION__));
5666 /* send to dongle only if we are not waiting for reload already */
5667 if (dhd->pub.hang_was_sent) {
5668 DHD_ERROR(("%s: HANG was sent up earlier\n", __FUNCTION__));
5669 DHD_OS_WAKE_LOCK_CTRL_TIMEOUT_ENABLE(&dhd->pub, DHD_EVENT_TIMEOUT_MS);
5670 ret = BCME_DONGLE_DOWN;
5674 ifidx = dhd_net2idx(dhd, net);
5675 DHD_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __FUNCTION__, ifidx, cmd));
5677 if (ifidx == DHD_BAD_IF) {
5678 DHD_ERROR(("%s: BAD IF\n", __FUNCTION__));
5683 #if defined(WL_WIRELESS_EXT)
5684 /* linux wireless extensions */
5685 if ((cmd >= SIOCIWFIRST) && (cmd <= SIOCIWLAST)) {
5686 /* may recurse, do NOT lock */
5687 ret = wl_iw_ioctl(net, ifr, cmd);
5690 #endif /* defined(WL_WIRELESS_EXT) */
5692 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 4, 2)
5693 if (cmd == SIOCETHTOOL) {
5694 ret = dhd_ethtool(dhd, (void*)ifr->ifr_data);
5697 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 4, 2) */
5699 if (cmd == SIOCDEVPRIVATE+1) {
5700 ret = wl_android_priv_cmd(net, ifr, cmd);
5701 dhd_check_hang(net, &dhd->pub, ret);
5705 if (cmd != SIOCDEVPRIVATE) {
5710 memset(&ioc, 0, sizeof(ioc));
5712 #ifdef CONFIG_COMPAT
5713 if (is_compat_task()) {
5714 compat_wl_ioctl_t compat_ioc;
5715 if (copy_from_user(&compat_ioc, ifr->ifr_data, sizeof(compat_wl_ioctl_t))) {
5719 ioc.cmd = compat_ioc.cmd;
5720 if (ioc.cmd & WLC_SPEC_FLAG) {
5721 memset(&ioc, 0, sizeof(ioc));
5722 /* Copy the ioc control structure part of ioctl request */
5723 if (copy_from_user(&ioc, ifr->ifr_data, sizeof(wl_ioctl_t))) {
5727 ioc.cmd &= ~WLC_SPEC_FLAG; /* Clear the FLAG */
5729 /* To differentiate between wl and dhd read 4 more byes */
5730 if ((copy_from_user(&ioc.driver, (char *)ifr->ifr_data + sizeof(wl_ioctl_t),
5731 sizeof(uint)) != 0)) {
5736 } else { /* ioc.cmd & WLC_SPEC_FLAG */
5737 ioc.buf = compat_ptr(compat_ioc.buf);
5738 ioc.len = compat_ioc.len;
5739 ioc.set = compat_ioc.set;
5740 ioc.used = compat_ioc.used;
5741 ioc.needed = compat_ioc.needed;
5742 /* To differentiate between wl and dhd read 4 more byes */
5743 if ((copy_from_user(&ioc.driver, (char *)ifr->ifr_data + sizeof(compat_wl_ioctl_t),
5744 sizeof(uint)) != 0)) {
5748 } /* ioc.cmd & WLC_SPEC_FLAG */
5750 #endif /* CONFIG_COMPAT */
5752 /* Copy the ioc control structure part of ioctl request */
5753 if (copy_from_user(&ioc, ifr->ifr_data, sizeof(wl_ioctl_t))) {
5757 #ifdef CONFIG_COMPAT
5758 ioc.cmd &= ~WLC_SPEC_FLAG; /* make sure it was clear when it isn't a compat task*/
5760 /* To differentiate between wl and dhd read 4 more byes */
5761 if ((copy_from_user(&ioc.driver, (char *)ifr->ifr_data + sizeof(wl_ioctl_t),
5762 sizeof(uint)) != 0)) {
5768 if (!capable(CAP_NET_ADMIN)) {
5774 buflen = MIN(ioc.len, DHD_IOCTL_MAXLEN);
5775 if (!(local_buf = MALLOC(dhd->pub.osh, buflen+1))) {
5780 DHD_PERIM_UNLOCK(&dhd->pub);
5781 if (copy_from_user(local_buf, ioc.buf, buflen)) {
5782 DHD_PERIM_LOCK(&dhd->pub);
5786 DHD_PERIM_LOCK(&dhd->pub);
5788 *(char *)(local_buf + buflen) = '\0';
5791 ret = dhd_ioctl_process(&dhd->pub, ifidx, &ioc, local_buf);
5793 if (!ret && buflen && local_buf && ioc.buf) {
5794 DHD_PERIM_UNLOCK(&dhd->pub);
5795 if (copy_to_user(ioc.buf, local_buf, buflen))
5797 DHD_PERIM_LOCK(&dhd->pub);
5802 MFREE(dhd->pub.osh, local_buf, buflen+1);
5805 DHD_PERIM_UNLOCK(&dhd->pub);
5806 DHD_OS_WAKE_UNLOCK(&dhd->pub);
5808 return OSL_ERROR(ret);
5812 #ifdef FIX_CPU_MIN_CLOCK
5813 static int dhd_init_cpufreq_fix(dhd_info_t *dhd)
5816 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
5817 mutex_init(&dhd->cpufreq_fix);
5819 dhd->cpufreq_fix_status = FALSE;
5824 static void dhd_fix_cpu_freq(dhd_info_t *dhd)
5826 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
5827 mutex_lock(&dhd->cpufreq_fix);
5829 if (dhd && !dhd->cpufreq_fix_status) {
5830 pm_qos_add_request(&dhd->dhd_cpu_qos, PM_QOS_CPU_FREQ_MIN, 300000);
5831 #ifdef FIX_BUS_MIN_CLOCK
5832 pm_qos_add_request(&dhd->dhd_bus_qos, PM_QOS_BUS_THROUGHPUT, 400000);
5833 #endif /* FIX_BUS_MIN_CLOCK */
5834 DHD_ERROR(("pm_qos_add_requests called\n"));
5836 dhd->cpufreq_fix_status = TRUE;
5838 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
5839 mutex_unlock(&dhd->cpufreq_fix);
5843 static void dhd_rollback_cpu_freq(dhd_info_t *dhd)
5845 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
5846 mutex_lock(&dhd ->cpufreq_fix);
5848 if (dhd && dhd->cpufreq_fix_status != TRUE) {
5849 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
5850 mutex_unlock(&dhd->cpufreq_fix);
5855 pm_qos_remove_request(&dhd->dhd_cpu_qos);
5856 #ifdef FIX_BUS_MIN_CLOCK
5857 pm_qos_remove_request(&dhd->dhd_bus_qos);
5858 #endif /* FIX_BUS_MIN_CLOCK */
5859 DHD_ERROR(("pm_qos_add_requests called\n"));
5861 dhd->cpufreq_fix_status = FALSE;
5862 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
5863 mutex_unlock(&dhd->cpufreq_fix);
5866 #endif /* FIX_CPU_MIN_CLOCK */
5868 #define MAX_TRY_CNT 5 /* Number of tries to disable deepsleep */
5869 int dhd_deepsleep(dhd_info_t *dhd, int flag)
5880 case 1 : /* Deepsleep on */
5881 DHD_ERROR(("dhd_deepsleep: ON\n"));
5882 /* give some time to sysioc_work before deepsleep */
5884 #ifdef PKT_FILTER_SUPPORT
5885 /* disable pkt filter */
5886 dhd_enable_packet_filter(0, dhdp);
5887 #endif /* PKT_FILTER_SUPPORT */
5890 memset(iovbuf, 0, sizeof(iovbuf));
5891 bcm_mkiovar("mpc", (char *)&powervar, 4, iovbuf, sizeof(iovbuf));
5892 dhd_wl_ioctl_cmd(dhdp, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
5894 /* Enable Deepsleep */
5896 memset(iovbuf, 0, sizeof(iovbuf));
5897 bcm_mkiovar("deepsleep", (char *)&powervar, 4, iovbuf, sizeof(iovbuf));
5898 dhd_wl_ioctl_cmd(dhdp, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
5901 case 0: /* Deepsleep Off */
5902 DHD_ERROR(("dhd_deepsleep: OFF\n"));
5904 /* Disable Deepsleep */
5905 for (cnt = 0; cnt < MAX_TRY_CNT; cnt++) {
5907 memset(iovbuf, 0, sizeof(iovbuf));
5908 bcm_mkiovar("deepsleep", (char *)&powervar, 4,
5909 iovbuf, sizeof(iovbuf));
5910 dhd_wl_ioctl_cmd(dhdp, WLC_SET_VAR, iovbuf,
5911 sizeof(iovbuf), TRUE, 0);
5913 memset(iovbuf, 0, sizeof(iovbuf));
5914 bcm_mkiovar("deepsleep", (char *)&powervar, 4,
5915 iovbuf, sizeof(iovbuf));
5916 if ((ret = dhd_wl_ioctl_cmd(dhdp, WLC_GET_VAR, iovbuf,
5917 sizeof(iovbuf), FALSE, 0)) < 0) {
5918 DHD_ERROR(("the error of dhd deepsleep status"
5919 " ret value :%d\n", ret));
5921 if (!(*(int *)iovbuf)) {
5922 DHD_ERROR(("deepsleep mode is 0,"
5923 " count: %d\n", cnt));
5931 memset(iovbuf, 0, sizeof(iovbuf));
5932 bcm_mkiovar("mpc", (char *)&powervar, 4, iovbuf, sizeof(iovbuf));
5933 dhd_wl_ioctl_cmd(dhdp, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
5941 dhd_stop(struct net_device *net)
5944 dhd_info_t *dhd = DHD_DEV_INFO(net);
5945 DHD_OS_WAKE_LOCK(&dhd->pub);
5946 DHD_PERIM_LOCK(&dhd->pub);
5947 printf("%s: Enter %p\n", __FUNCTION__, net);
5948 dhd->pub.rxcnt_timeout = 0;
5949 dhd->pub.txcnt_timeout = 0;
5952 dhd->pub.d3ackcnt_timeout = 0;
5953 #endif /* BCMPCIE */
5955 if (dhd->pub.up == 0) {
5959 dhd_if_flush_sta(DHD_DEV_IFP(net));
5961 /* Disable Runtime PM before interface down */
5962 DHD_DISABLE_RUNTIME_PM(&dhd->pub);
5964 #ifdef FIX_CPU_MIN_CLOCK
5965 if (dhd_get_fw_mode(dhd) == DHD_FLAG_HOSTAP_MODE)
5966 dhd_rollback_cpu_freq(dhd);
5967 #endif /* FIX_CPU_MIN_CLOCK */
5969 ifidx = dhd_net2idx(dhd, net);
5970 BCM_REFERENCE(ifidx);
5972 /* Set state and stop OS transmissions */
5973 netif_stop_queue(net);
5979 wl_cfg80211_down(NULL);
5981 ifp = dhd->iflist[0];
5982 ASSERT(ifp && ifp->net);
5984 * For CFG80211: Clean up all the left over virtual interfaces
5985 * when the primary Interface is brought down. [ifconfig wlan0 down]
5987 if (!dhd_download_fw_on_driverload) {
5988 if ((dhd->dhd_state & DHD_ATTACH_STATE_ADD_IF) &&
5989 (dhd->dhd_state & DHD_ATTACH_STATE_CFG80211)) {
5992 #ifdef WL_CFG80211_P2P_DEV_IF
5993 wl_cfg80211_del_p2p_wdev();
5994 #endif /* WL_CFG80211_P2P_DEV_IF */
5996 dhd_net_if_lock_local(dhd);
5997 for (i = 1; i < DHD_MAX_IFS; i++)
5998 dhd_remove_if(&dhd->pub, i, FALSE);
6000 if (ifp && ifp->net) {
6001 dhd_if_del_sta_list(ifp);
6004 #ifdef ARP_OFFLOAD_SUPPORT
6005 if (dhd_inetaddr_notifier_registered) {
6006 dhd_inetaddr_notifier_registered = FALSE;
6007 unregister_inetaddr_notifier(&dhd_inetaddr_notifier);
6009 #endif /* ARP_OFFLOAD_SUPPORT */
6010 #if defined(CONFIG_IPV6) && defined(IPV6_NDO_SUPPORT)
6011 if (dhd_inet6addr_notifier_registered) {
6012 dhd_inet6addr_notifier_registered = FALSE;
6013 unregister_inet6addr_notifier(&dhd_inet6addr_notifier);
6015 #endif /* CONFIG_IPV6 && IPV6_NDO_SUPPORT */
6016 dhd_net_if_unlock_local(dhd);
6018 cancel_work_sync(dhd->dhd_deferred_wq);
6019 #if defined(DHD_LB) && defined(DHD_LB_RXP)
6020 __skb_queue_purge(&dhd->rx_pend_queue);
6021 #endif /* DHD_LB && DHD_LB_RXP */
6024 #if defined(BCMPCIE) && defined(DHDTCPACK_SUPPRESS)
6025 dhd_tcpack_suppress_set(&dhd->pub, TCPACK_SUP_OFF);
6026 #endif /* BCMPCIE && DHDTCPACK_SUPPRESS */
6027 #if defined(DHD_LB) && defined(DHD_LB_RXP)
6028 if (ifp->net == dhd->rx_napi_netdev) {
6029 DHD_INFO(("%s napi<%p> disabled ifp->net<%p,%s>\n",
6030 __FUNCTION__, &dhd->rx_napi_struct, net, net->name));
6031 skb_queue_purge(&dhd->rx_napi_queue);
6032 napi_disable(&dhd->rx_napi_struct);
6033 netif_napi_del(&dhd->rx_napi_struct);
6034 dhd->rx_napi_netdev = NULL;
6036 #endif /* DHD_LB && DHD_LB_RXP */
6039 #endif /* WL_CFG80211 */
6041 #ifdef PROP_TXSTATUS
6042 dhd_wlfc_cleanup(&dhd->pub, NULL, 0);
6044 /* Stop the protocol module */
6045 dhd_prot_stop(&dhd->pub);
6047 OLD_MOD_DEC_USE_COUNT;
6049 if (ifidx == 0 && !dhd_download_fw_on_driverload)
6050 wl_android_wifi_off(net, TRUE);
6052 if (dhd->pub.conf->deepsleep)
6053 dhd_deepsleep(dhd, 1);
6055 dhd->pub.hang_was_sent = 0;
6057 /* Clear country spec for for built-in type driver */
6058 if (!dhd_download_fw_on_driverload) {
6059 dhd->pub.dhd_cspec.country_abbrev[0] = 0x00;
6060 dhd->pub.dhd_cspec.rev = 0;
6061 dhd->pub.dhd_cspec.ccode[0] = 0x00;
6068 DHD_PERIM_UNLOCK(&dhd->pub);
6069 DHD_OS_WAKE_UNLOCK(&dhd->pub);
6071 /* Destroy wakelock */
6072 if (!dhd_download_fw_on_driverload &&
6073 (dhd->dhd_state & DHD_ATTACH_STATE_WAKELOCKS_INIT)) {
6074 DHD_OS_WAKE_LOCK_DESTROY(dhd);
6075 dhd->dhd_state &= ~DHD_ATTACH_STATE_WAKELOCKS_INIT;
6077 printf("%s: Exit\n", __FUNCTION__);
6082 #if defined(WL_CFG80211) && defined(USE_INITIAL_SHORT_DWELL_TIME)
6083 extern bool g_first_broadcast_scan;
6087 static int dhd_interworking_enable(dhd_pub_t *dhd)
6089 char iovbuf[WLC_IOCTL_SMLEN];
6090 uint32 enable = true;
6093 bcm_mkiovar("interworking", (char *)&enable, sizeof(enable), iovbuf, sizeof(iovbuf));
6094 ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
6096 DHD_ERROR(("%s: enableing interworking failed, ret=%d\n", __FUNCTION__, ret));
6099 if (ret == BCME_OK) {
6100 /* basic capabilities for HS20 REL2 */
6101 uint32 cap = WL_WNM_BSSTRANS | WL_WNM_NOTIF;
6102 bcm_mkiovar("wnm", (char *)&cap, sizeof(cap), iovbuf, sizeof(iovbuf));
6103 ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
6105 DHD_ERROR(("%s: set wnm returned (%d)\n", __FUNCTION__, ret));
6114 dhd_open(struct net_device *net)
6116 dhd_info_t *dhd = DHD_DEV_INFO(net);
6121 char iovbuf[WLC_IOCTL_SMLEN];
6122 dbus_config_t config;
6123 uint32 agglimit = 0;
6124 uint32 rpc_agg = BCM_RPC_TP_DNGL_AGG_DPC; /* host aggr not enabled yet */
6125 #endif /* BCM_FD_AGGR */
6129 if (!dhd_download_fw_on_driverload && !dhd_driver_init_done) {
6130 DHD_ERROR(("%s: WLAN driver is not initialized\n", __FUNCTION__));
6134 printf("%s: Enter %p\n", __FUNCTION__, net);
6135 #if defined(MULTIPLE_SUPPLICANT)
6136 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) && 1
6137 if (mutex_is_locked(&_dhd_sdio_mutex_lock_) != 0) {
6138 DHD_ERROR(("%s : dhd_open: call dev open before insmod complete!\n", __FUNCTION__));
6140 mutex_lock(&_dhd_sdio_mutex_lock_);
6142 #endif /* MULTIPLE_SUPPLICANT */
6144 if (!dhd_download_fw_on_driverload &&
6145 !(dhd->dhd_state & DHD_ATTACH_STATE_WAKELOCKS_INIT)) {
6146 DHD_OS_WAKE_LOCK_INIT(dhd);
6147 dhd->dhd_state |= DHD_ATTACH_STATE_WAKELOCKS_INIT;
6150 #ifdef PREVENT_REOPEN_DURING_HANG
6151 /* WAR : to prevent calling dhd_open abnormally in quick succession after hang event */
6152 if (dhd->pub.hang_was_sent == 1) {
6153 DHD_ERROR(("%s: HANG was sent up earlier\n", __FUNCTION__));
6154 /* Force to bring down WLAN interface in case dhd_stop() is not called
6155 * from the upper layer when HANG event is triggered.
6157 if (!dhd_download_fw_on_driverload && dhd->pub.up == 1) {
6158 DHD_ERROR(("%s: WLAN interface is not brought down\n", __FUNCTION__));
6164 #endif /* PREVENT_REOPEN_DURING_HANG */
6167 DHD_OS_WAKE_LOCK(&dhd->pub);
6168 DHD_PERIM_LOCK(&dhd->pub);
6169 dhd->pub.dongle_trap_occured = 0;
6170 dhd->pub.hang_was_sent = 0;
6171 dhd->pub.hang_reason = 0;
6172 #ifdef DHD_LOSSLESS_ROAMING
6173 dhd->pub.dequeue_prec_map = ALLPRIO;
6177 * Force start if ifconfig_up gets called before START command
6178 * We keep WEXT's wl_control_wl_start to provide backward compatibility
6179 * This should be removed in the future
6181 ret = wl_control_wl_start(net);
6183 DHD_ERROR(("%s: failed with code %d\n", __FUNCTION__, ret));
6189 ifidx = dhd_net2idx(dhd, net);
6190 DHD_TRACE(("%s: ifidx %d\n", __FUNCTION__, ifidx));
6193 DHD_ERROR(("%s: Error: called with invalid IF\n", __FUNCTION__));
6198 if (!dhd->iflist[ifidx]) {
6199 DHD_ERROR(("%s: Error: called when IF already deleted\n", __FUNCTION__));
6205 atomic_set(&dhd->pend_8021x_cnt, 0);
6206 if (!dhd_download_fw_on_driverload) {
6207 DHD_ERROR(("\n%s\n", dhd_version));
6208 #if defined(USE_INITIAL_SHORT_DWELL_TIME)
6209 g_first_broadcast_scan = TRUE;
6211 ret = wl_android_wifi_on(net);
6213 DHD_ERROR(("%s : wl_android_wifi_on failed (%d)\n",
6214 __FUNCTION__, ret));
6219 #ifdef FIX_CPU_MIN_CLOCK
6220 if (dhd_get_fw_mode(dhd) == DHD_FLAG_HOSTAP_MODE) {
6221 dhd_init_cpufreq_fix(dhd);
6222 dhd_fix_cpu_freq(dhd);
6224 #endif /* FIX_CPU_MIN_CLOCK */
6226 if (dhd->pub.busstate != DHD_BUS_DATA) {
6228 /* try to bring up bus */
6229 DHD_PERIM_UNLOCK(&dhd->pub);
6230 ret = dhd_bus_start(&dhd->pub);
6231 DHD_PERIM_LOCK(&dhd->pub);
6233 DHD_ERROR(("%s: failed with code %d\n", __FUNCTION__, ret));
6239 if (dhd_download_fw_on_driverload) {
6240 if (dhd->pub.conf->deepsleep)
6241 dhd_deepsleep(dhd, 0);
6245 config.config_id = DBUS_CONFIG_ID_AGGR_LIMIT;
6248 memset(iovbuf, 0, sizeof(iovbuf));
6249 bcm_mkiovar("rpc_dngl_agglimit", (char *)&agglimit, 4,
6250 iovbuf, sizeof(iovbuf));
6252 if (!dhd_wl_ioctl_cmd(&dhd->pub, WLC_GET_VAR, iovbuf, sizeof(iovbuf), FALSE, 0)) {
6253 agglimit = *(uint32 *)iovbuf;
6254 config.aggr_param.maxrxsf = agglimit >> BCM_RPC_TP_AGG_SF_SHIFT;
6255 config.aggr_param.maxrxsize = agglimit & BCM_RPC_TP_AGG_BYTES_MASK;
6256 DHD_ERROR(("rpc_dngl_agglimit %x : sf_limit %d bytes_limit %d\n",
6257 agglimit, config.aggr_param.maxrxsf, config.aggr_param.maxrxsize));
6258 if (bcm_rpc_tp_set_config(dhd->pub.info->rpc_th, &config)) {
6259 DHD_ERROR(("set tx/rx queue size and buffersize failed\n"));
6262 DHD_ERROR(("get rpc_dngl_agglimit failed\n"));
6263 rpc_agg &= ~BCM_RPC_TP_DNGL_AGG_DPC;
6266 /* Set aggregation for TX */
6267 bcm_rpc_tp_agg_set(dhd->pub.info->rpc_th, BCM_RPC_TP_HOST_AGG_MASK,
6268 rpc_agg & BCM_RPC_TP_HOST_AGG_MASK);
6270 /* Set aggregation for RX */
6271 memset(iovbuf, 0, sizeof(iovbuf));
6272 bcm_mkiovar("rpc_agg", (char *)&rpc_agg, sizeof(rpc_agg), iovbuf, sizeof(iovbuf));
6273 if (!dhd_wl_ioctl_cmd(&dhd->pub, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0)) {
6274 dhd->pub.info->fdaggr = 0;
6275 if (rpc_agg & BCM_RPC_TP_HOST_AGG_MASK)
6276 dhd->pub.info->fdaggr |= BCM_FDAGGR_H2D_ENABLED;
6277 if (rpc_agg & BCM_RPC_TP_DNGL_AGG_MASK)
6278 dhd->pub.info->fdaggr |= BCM_FDAGGR_D2H_ENABLED;
6280 DHD_ERROR(("%s(): Setting RX aggregation failed %d\n", __FUNCTION__, ret));
6282 #endif /* BCM_FD_AGGR */
6284 /* dhd_sync_with_dongle has been called in dhd_bus_start or wl_android_wifi_on */
6285 memcpy(net->dev_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
6288 /* Get current TOE mode from dongle */
6289 if (dhd_toe_get(dhd, ifidx, &toe_ol) >= 0 && (toe_ol & TOE_TX_CSUM_OL) != 0) {
6290 dhd->iflist[ifidx]->net->features |= NETIF_F_IP_CSUM;
6292 dhd->iflist[ifidx]->net->features &= ~NETIF_F_IP_CSUM;
6296 #if defined(WL_CFG80211)
6297 if (unlikely(wl_cfg80211_up(NULL))) {
6298 DHD_ERROR(("%s: failed to bring up cfg80211\n", __FUNCTION__));
6302 if (!dhd_download_fw_on_driverload) {
6303 #ifdef ARP_OFFLOAD_SUPPORT
6304 dhd->pend_ipaddr = 0;
6305 if (!dhd_inetaddr_notifier_registered) {
6306 dhd_inetaddr_notifier_registered = TRUE;
6307 register_inetaddr_notifier(&dhd_inetaddr_notifier);
6309 #endif /* ARP_OFFLOAD_SUPPORT */
6310 #if defined(CONFIG_IPV6) && defined(IPV6_NDO_SUPPORT)
6311 if (!dhd_inet6addr_notifier_registered) {
6312 dhd_inet6addr_notifier_registered = TRUE;
6313 register_inet6addr_notifier(&dhd_inet6addr_notifier);
6315 #endif /* CONFIG_IPV6 && IPV6_NDO_SUPPORT */
6317 DHD_LB_STATS_INIT(&dhd->pub);
6319 __skb_queue_head_init(&dhd->rx_pend_queue);
6320 #endif /* DHD_LB_RXP */
6324 #if defined(BCMPCIE) && defined(DHDTCPACK_SUPPRESS)
6325 #if defined(SET_RPS_CPUS)
6326 dhd_tcpack_suppress_set(&dhd->pub, TCPACK_SUP_OFF);
6328 dhd_tcpack_suppress_set(&dhd->pub, TCPACK_SUP_HOLD);
6330 #endif /* BCMPCIE && DHDTCPACK_SUPPRESS */
6331 #if defined(DHD_LB) && defined(DHD_LB_RXP)
6332 if (dhd->rx_napi_netdev == NULL) {
6333 dhd->rx_napi_netdev = dhd->iflist[ifidx]->net;
6334 memset(&dhd->rx_napi_struct, 0, sizeof(struct napi_struct));
6335 netif_napi_add(dhd->rx_napi_netdev, &dhd->rx_napi_struct,
6336 dhd_napi_poll, dhd_napi_weight);
6337 DHD_INFO(("%s napi<%p> enabled ifp->net<%p,%s>\n",
6338 __FUNCTION__, &dhd->rx_napi_struct, net, net->name));
6339 napi_enable(&dhd->rx_napi_struct);
6340 DHD_INFO(("%s load balance init rx_napi_struct\n", __FUNCTION__));
6341 skb_queue_head_init(&dhd->rx_napi_queue);
6343 #endif /* DHD_LB && DHD_LB_RXP */
6344 #if defined(NUM_SCB_MAX_PROBE)
6345 dhd_set_scb_probe(&dhd->pub);
6346 #endif /* NUM_SCB_MAX_PROBE */
6347 #endif /* WL_CFG80211 */
6350 /* Allow transmit calls */
6351 netif_start_queue(net);
6354 OLD_MOD_INC_USE_COUNT;
6357 dhd_dbg_init(&dhd->pub);
6365 DHD_PERIM_UNLOCK(&dhd->pub);
6366 DHD_OS_WAKE_UNLOCK(&dhd->pub);
6368 #if defined(MULTIPLE_SUPPLICANT)
6369 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) && 1
6370 mutex_unlock(&_dhd_sdio_mutex_lock_);
6372 #endif /* MULTIPLE_SUPPLICANT */
6374 printf("%s: Exit ret=%d\n", __FUNCTION__, ret);
6378 int dhd_do_driver_init(struct net_device *net)
6380 dhd_info_t *dhd = NULL;
6383 DHD_ERROR(("Primary Interface not initialized \n"));
6387 #ifdef MULTIPLE_SUPPLICANT
6388 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) && 1 && defined(BCMSDIO)
6389 if (mutex_is_locked(&_dhd_sdio_mutex_lock_) != 0) {
6390 DHD_ERROR(("%s : dhdsdio_probe is already running!\n", __FUNCTION__));
6393 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) */
6394 #endif /* MULTIPLE_SUPPLICANT */
6396 /* && defined(OEM_ANDROID) && defined(BCMSDIO) */
6397 dhd = DHD_DEV_INFO(net);
6399 /* If driver is already initialized, do nothing
6401 if (dhd->pub.busstate == DHD_BUS_DATA) {
6402 DHD_TRACE(("Driver already Inititalized. Nothing to do"));
6406 if (dhd_open(net) < 0) {
6407 DHD_ERROR(("Driver Init Failed \n"));
6415 dhd_event_ifadd(dhd_info_t *dhdinfo, wl_event_data_if_t *ifevent, char *name, uint8 *mac)
6419 if (wl_cfg80211_notify_ifadd(ifevent->ifidx, name, mac, ifevent->bssidx) == BCME_OK)
6423 /* handle IF event caused by wl commands, SoftAP, WEXT and
6424 * anything else. This has to be done asynchronously otherwise
6425 * DPC will be blocked (and iovars will timeout as DPC has no chance
6426 * to read the response back)
6428 if (ifevent->ifidx > 0) {
6429 dhd_if_event_t *if_event = MALLOC(dhdinfo->pub.osh, sizeof(dhd_if_event_t));
6430 if (if_event == NULL) {
6431 DHD_ERROR(("dhd_event_ifadd: Failed MALLOC, malloced %d bytes",
6432 MALLOCED(dhdinfo->pub.osh)));
6436 memcpy(&if_event->event, ifevent, sizeof(if_event->event));
6437 memcpy(if_event->mac, mac, ETHER_ADDR_LEN);
6438 strncpy(if_event->name, name, IFNAMSIZ);
6439 if_event->name[IFNAMSIZ - 1] = '\0';
6440 dhd_deferred_schedule_work(dhdinfo->dhd_deferred_wq, (void *)if_event,
6441 DHD_WQ_WORK_IF_ADD, dhd_ifadd_event_handler, DHD_WORK_PRIORITY_LOW);
6448 dhd_event_ifdel(dhd_info_t *dhdinfo, wl_event_data_if_t *ifevent, char *name, uint8 *mac)
6450 dhd_if_event_t *if_event;
6453 if (wl_cfg80211_notify_ifdel(ifevent->ifidx, name, mac, ifevent->bssidx) == BCME_OK)
6455 #endif /* WL_CFG80211 */
6457 /* handle IF event caused by wl commands, SoftAP, WEXT and
6460 if_event = MALLOC(dhdinfo->pub.osh, sizeof(dhd_if_event_t));
6461 if (if_event == NULL) {
6462 DHD_ERROR(("dhd_event_ifdel: malloc failed for if_event, malloced %d bytes",
6463 MALLOCED(dhdinfo->pub.osh)));
6466 memcpy(&if_event->event, ifevent, sizeof(if_event->event));
6467 memcpy(if_event->mac, mac, ETHER_ADDR_LEN);
6468 strncpy(if_event->name, name, IFNAMSIZ);
6469 if_event->name[IFNAMSIZ - 1] = '\0';
6470 dhd_deferred_schedule_work(dhdinfo->dhd_deferred_wq, (void *)if_event, DHD_WQ_WORK_IF_DEL,
6471 dhd_ifdel_event_handler, DHD_WORK_PRIORITY_LOW);
6476 /* unregister and free the existing net_device interface (if any) in iflist and
6477 * allocate a new one. the slot is reused. this function does NOT register the
6478 * new interface to linux kernel. dhd_register_if does the job
6481 dhd_allocate_if(dhd_pub_t *dhdpub, int ifidx, char *name,
6482 uint8 *mac, uint8 bssidx, bool need_rtnl_lock, char *dngl_name)
6484 dhd_info_t *dhdinfo = (dhd_info_t *)dhdpub->info;
6487 ASSERT(dhdinfo && (ifidx < DHD_MAX_IFS));
6488 ifp = dhdinfo->iflist[ifidx];
6491 if (ifp->net != NULL) {
6492 DHD_ERROR(("%s: free existing IF %s\n", __FUNCTION__, ifp->net->name));
6494 dhd_dev_priv_clear(ifp->net); /* clear net_device private */
6496 /* in unregister_netdev case, the interface gets freed by net->destructor
6497 * (which is set to free_netdev)
6499 if (ifp->net->reg_state == NETREG_UNINITIALIZED) {
6500 free_netdev(ifp->net);
6502 netif_stop_queue(ifp->net);
6504 unregister_netdev(ifp->net);
6506 unregister_netdevice(ifp->net);
6511 ifp = MALLOC(dhdinfo->pub.osh, sizeof(dhd_if_t));
6513 DHD_ERROR(("%s: OOM - dhd_if_t(%zu)\n", __FUNCTION__, sizeof(dhd_if_t)));
6518 memset(ifp, 0, sizeof(dhd_if_t));
6519 ifp->info = dhdinfo;
6521 ifp->bssidx = bssidx;
6523 memcpy(&ifp->mac_addr, mac, ETHER_ADDR_LEN);
6525 /* Allocate etherdev, including space for private structure */
6526 ifp->net = alloc_etherdev(DHD_DEV_PRIV_SIZE);
6527 if (ifp->net == NULL) {
6528 DHD_ERROR(("%s: OOM - alloc_etherdev(%zu)\n", __FUNCTION__, sizeof(dhdinfo)));
6532 /* Setup the dhd interface's netdevice private structure. */
6533 dhd_dev_priv_save(ifp->net, dhdinfo, ifp, ifidx);
6535 if (name && name[0]) {
6536 strncpy(ifp->net->name, name, IFNAMSIZ);
6537 ifp->net->name[IFNAMSIZ - 1] = '\0';
6542 ifp->net->destructor = free_netdev;
6544 ifp->net->destructor = dhd_netdev_free;
6546 ifp->net->destructor = free_netdev;
6547 #endif /* WL_CFG80211 */
6548 strncpy(ifp->name, ifp->net->name, IFNAMSIZ);
6549 ifp->name[IFNAMSIZ - 1] = '\0';
6550 dhdinfo->iflist[ifidx] = ifp;
6552 /* initialize the dongle provided if name */
6554 strncpy(ifp->dngl_name, dngl_name, IFNAMSIZ);
6556 strncpy(ifp->dngl_name, name, IFNAMSIZ);
6558 #ifdef PCIE_FULL_DONGLE
6559 /* Initialize STA info list */
6560 INIT_LIST_HEAD(&ifp->sta_list);
6561 DHD_IF_STA_LIST_LOCK_INIT(ifp);
6562 #endif /* PCIE_FULL_DONGLE */
6564 #ifdef DHD_L2_FILTER
6565 ifp->phnd_arp_table = init_l2_filter_arp_table(dhdpub->osh);
6566 ifp->parp_allnode = TRUE;
6573 if (ifp->net != NULL) {
6574 dhd_dev_priv_clear(ifp->net);
6575 free_netdev(ifp->net);
6578 MFREE(dhdinfo->pub.osh, ifp, sizeof(*ifp));
6582 dhdinfo->iflist[ifidx] = NULL;
6586 /* unregister and free the the net_device interface associated with the indexed
6587 * slot, also free the slot memory and set the slot pointer to NULL
6590 dhd_remove_if(dhd_pub_t *dhdpub, int ifidx, bool need_rtnl_lock)
6592 dhd_info_t *dhdinfo = (dhd_info_t *)dhdpub->info;
6595 ifp = dhdinfo->iflist[ifidx];
6598 if (ifp->net != NULL) {
6599 DHD_ERROR(("deleting interface '%s' idx %d\n", ifp->net->name, ifp->idx));
6601 /* in unregister_netdev case, the interface gets freed by net->destructor
6602 * (which is set to free_netdev)
6604 if (ifp->net->reg_state == NETREG_UNINITIALIZED) {
6605 free_netdev(ifp->net);
6607 netif_tx_disable(ifp->net);
6611 #if defined(SET_RPS_CPUS)
6612 custom_rps_map_clear(ifp->net->_rx);
6613 #endif /* SET_RPS_CPUS */
6614 #if defined(SET_RPS_CPUS)
6615 #if (defined(DHDTCPACK_SUPPRESS) && defined(BCMPCIE))
6616 dhd_tcpack_suppress_set(dhdpub, TCPACK_SUP_OFF);
6617 #endif /* DHDTCPACK_SUPPRESS && BCMPCIE */
6620 unregister_netdev(ifp->net);
6622 unregister_netdevice(ifp->net);
6625 dhdinfo->iflist[ifidx] = NULL;
6628 dhd_wmf_cleanup(dhdpub, ifidx);
6629 #endif /* DHD_WMF */
6630 #ifdef DHD_L2_FILTER
6631 bcm_l2_filter_arp_table_update(dhdpub->osh, ifp->phnd_arp_table, TRUE,
6632 NULL, FALSE, dhdpub->tickcnt);
6633 deinit_l2_filter_arp_table(dhdpub->osh, ifp->phnd_arp_table);
6634 ifp->phnd_arp_table = NULL;
6635 #endif /* DHD_L2_FILTER */
6637 dhd_if_del_sta_list(ifp);
6639 MFREE(dhdinfo->pub.osh, ifp, sizeof(*ifp));
6646 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
6647 static struct net_device_ops dhd_ops_pri = {
6648 .ndo_open = dhd_open,
6649 .ndo_stop = dhd_stop,
6650 .ndo_get_stats = dhd_get_stats,
6651 .ndo_do_ioctl = dhd_ioctl_entry,
6652 .ndo_start_xmit = dhd_start_xmit,
6653 .ndo_set_mac_address = dhd_set_mac_address,
6654 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
6655 .ndo_set_rx_mode = dhd_set_multicast_list,
6657 .ndo_set_multicast_list = dhd_set_multicast_list,
6661 static struct net_device_ops dhd_ops_virt = {
6662 .ndo_get_stats = dhd_get_stats,
6663 .ndo_do_ioctl = dhd_ioctl_entry,
6664 .ndo_start_xmit = dhd_start_xmit,
6665 .ndo_set_mac_address = dhd_set_mac_address,
6666 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
6667 .ndo_set_rx_mode = dhd_set_multicast_list,
6669 .ndo_set_multicast_list = dhd_set_multicast_list,
6672 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)) */
6675 extern void debugger_init(void *bus_handle);
6679 #ifdef SHOW_LOGTRACE
6680 static char *logstrs_path = "/root/logstrs.bin";
6681 static char *st_str_file_path = "/root/rtecdc.bin";
6682 static char *map_file_path = "/root/rtecdc.map";
6683 static char *rom_st_str_file_path = "/root/roml.bin";
6684 static char *rom_map_file_path = "/root/roml.map";
6686 #define BYTES_AHEAD_NUM 11 /* address in map file is before these many bytes */
6687 #define READ_NUM_BYTES 1000 /* read map file each time this No. of bytes */
6688 #define GO_BACK_FILE_POS_NUM_BYTES 100 /* set file pos back to cur pos */
6689 static char *ramstart_str = "text_start"; /* string in mapfile has addr ramstart */
6690 static char *rodata_start_str = "rodata_start"; /* string in mapfile has addr rodata start */
6691 static char *rodata_end_str = "rodata_end"; /* string in mapfile has addr rodata end */
6692 static char *ram_file_str = "rtecdc";
6693 static char *rom_file_str = "roml";
6694 #define RAMSTART_BIT 0x01
6695 #define RDSTART_BIT 0x02
6696 #define RDEND_BIT 0x04
6697 #define ALL_MAP_VAL (RAMSTART_BIT | RDSTART_BIT | RDEND_BIT)
6699 module_param(logstrs_path, charp, S_IRUGO);
6700 module_param(st_str_file_path, charp, S_IRUGO);
6701 module_param(map_file_path, charp, S_IRUGO);
6702 module_param(rom_st_str_file_path, charp, S_IRUGO);
6703 module_param(rom_map_file_path, charp, S_IRUGO);
6706 dhd_init_logstrs_array(dhd_event_log_t *temp)
6708 struct file *filep = NULL;
6711 char *raw_fmts = NULL;
6712 int logstrs_size = 0;
6714 logstr_header_t *hdr = NULL;
6715 uint32 *lognums = NULL;
6716 char *logstrs = NULL;
6726 filep = filp_open(logstrs_path, O_RDONLY, 0);
6728 if (IS_ERR(filep)) {
6729 DHD_ERROR(("%s: Failed to open the file %s \n", __FUNCTION__, logstrs_path));
6732 error = vfs_stat(logstrs_path, &stat);
6734 DHD_ERROR(("%s: Failed to stat file %s \n", __FUNCTION__, logstrs_path));
6737 logstrs_size = (int) stat.size;
6739 raw_fmts = kmalloc(logstrs_size, GFP_KERNEL);
6740 if (raw_fmts == NULL) {
6741 DHD_ERROR(("%s: Failed to allocate memory \n", __FUNCTION__));
6744 if (vfs_read(filep, raw_fmts, logstrs_size, &filep->f_pos) != logstrs_size) {
6745 DHD_ERROR(("%s: Failed to read file %s", __FUNCTION__, logstrs_path));
6749 /* Remember header from the logstrs.bin file */
6750 hdr = (logstr_header_t *) (raw_fmts + logstrs_size -
6751 sizeof(logstr_header_t));
6753 if (hdr->log_magic == LOGSTRS_MAGIC) {
6755 * logstrs.bin start with header.
6757 num_fmts = hdr->rom_logstrs_offset / sizeof(uint32);
6758 ram_index = (hdr->ram_lognums_offset -
6759 hdr->rom_lognums_offset) / sizeof(uint32);
6760 lognums = (uint32 *) &raw_fmts[hdr->rom_lognums_offset];
6761 logstrs = (char *) &raw_fmts[hdr->rom_logstrs_offset];
6764 * Legacy logstrs.bin format without header.
6766 num_fmts = *((uint32 *) (raw_fmts)) / sizeof(uint32);
6767 if (num_fmts == 0) {
6768 /* Legacy ROM/RAM logstrs.bin format:
6769 * - ROM 'lognums' section
6770 * - RAM 'lognums' section
6771 * - ROM 'logstrs' section.
6772 * - RAM 'logstrs' section.
6774 * 'lognums' is an array of indexes for the strings in the
6775 * 'logstrs' section. The first uint32 is 0 (index of first
6776 * string in ROM 'logstrs' section).
6778 * The 4324b5 is the only ROM that uses this legacy format. Use the
6779 * fixed number of ROM fmtnums to find the start of the RAM
6780 * 'lognums' section. Use the fixed first ROM string ("Con\n") to
6781 * find the ROM 'logstrs' section.
6783 #define NUM_4324B5_ROM_FMTS 186
6784 #define FIRST_4324B5_ROM_LOGSTR "Con\n"
6785 ram_index = NUM_4324B5_ROM_FMTS;
6786 lognums = (uint32 *) raw_fmts;
6787 num_fmts = ram_index;
6788 logstrs = (char *) &raw_fmts[num_fmts << 2];
6789 while (strncmp(FIRST_4324B5_ROM_LOGSTR, logstrs, 4)) {
6791 logstrs = (char *) &raw_fmts[num_fmts << 2];
6794 /* Legacy RAM-only logstrs.bin format:
6795 * - RAM 'lognums' section
6796 * - RAM 'logstrs' section.
6798 * 'lognums' is an array of indexes for the strings in the
6799 * 'logstrs' section. The first uint32 is an index to the
6800 * start of 'logstrs'. Therefore, if this index is divided
6801 * by 'sizeof(uint32)' it provides the number of logstr
6805 lognums = (uint32 *) raw_fmts;
6806 logstrs = (char *) &raw_fmts[num_fmts << 2];
6809 fmts = kmalloc(num_fmts * sizeof(char *), GFP_KERNEL);
6811 DHD_ERROR(("Failed to allocate fmts memory\n"));
6815 for (i = 0; i < num_fmts; i++) {
6816 /* ROM lognums index into logstrs using 'rom_logstrs_offset' as a base
6817 * (they are 0-indexed relative to 'rom_logstrs_offset').
6819 * RAM lognums are already indexed to point to the correct RAM logstrs (they
6820 * are 0-indexed relative to the start of the logstrs.bin file).
6822 if (i == ram_index) {
6825 fmts[i] = &logstrs[lognums[i]];
6828 temp->raw_fmts = raw_fmts;
6829 temp->num_fmts = num_fmts;
6830 filp_close(filep, NULL);
6839 filp_close(filep, NULL);
6846 dhd_read_map(char *fname, uint32 *ramstart, uint32 *rodata_start,
6849 struct file *filep = NULL;
6851 char *raw_fmts = NULL;
6852 uint32 read_size = READ_NUM_BYTES;
6862 if (fname == NULL) {
6863 DHD_ERROR(("%s: ERROR fname is NULL \n", __FUNCTION__));
6870 filep = filp_open(fname, O_RDONLY, 0);
6871 if (IS_ERR(filep)) {
6872 DHD_ERROR(("%s: Failed to open %s \n", __FUNCTION__, fname));
6876 /* Allocate 1 byte more than read_size to terminate it with NULL */
6877 raw_fmts = kmalloc(read_size + 1, GFP_KERNEL);
6878 if (raw_fmts == NULL) {
6879 DHD_ERROR(("%s: Failed to allocate raw_fmts memory \n", __FUNCTION__));
6883 /* read ram start, rodata_start and rodata_end values from map file */
6885 while (count != ALL_MAP_VAL)
6887 error = vfs_read(filep, raw_fmts, read_size, (&filep->f_pos));
6889 DHD_ERROR(("%s: read failed %s err:%d \n", __FUNCTION__,
6890 map_file_path, error));
6894 if (error < read_size) {
6896 * since we reset file pos back to earlier pos by
6897 * GO_BACK_FILE_POS_NUM_BYTES bytes we won't reach EOF.
6898 * So if ret value is less than read_size, reached EOF don't read further
6902 /* End raw_fmts with NULL as strstr expects NULL terminated strings */
6903 raw_fmts[read_size] = '\0';
6905 /* Get ramstart address */
6906 if ((cptr = strstr(raw_fmts, ramstart_str))) {
6907 cptr = cptr - BYTES_AHEAD_NUM;
6908 sscanf(cptr, "%x %c text_start", ramstart, &c);
6909 count |= RAMSTART_BIT;
6912 /* Get ram rodata start address */
6913 if ((cptr = strstr(raw_fmts, rodata_start_str))) {
6914 cptr = cptr - BYTES_AHEAD_NUM;
6915 sscanf(cptr, "%x %c rodata_start", rodata_start, &c);
6916 count |= RDSTART_BIT;
6919 /* Get ram rodata end address */
6920 if ((cptr = strstr(raw_fmts, rodata_end_str))) {
6921 cptr = cptr - BYTES_AHEAD_NUM;
6922 sscanf(cptr, "%x %c rodata_end", rodata_end, &c);
6925 memset(raw_fmts, 0, read_size);
6927 * go back to predefined NUM of bytes so that we won't miss
6928 * the string and addr even if it comes as splited in next read.
6930 filep->f_pos = filep->f_pos - GO_BACK_FILE_POS_NUM_BYTES;
6933 DHD_ERROR(("---ramstart: 0x%x, rodata_start: 0x%x, rodata_end:0x%x\n",
6934 *ramstart, *rodata_start, *rodata_end));
6936 DHD_ERROR(("readmap over \n"));
6944 filp_close(filep, NULL);
6947 if (count == ALL_MAP_VAL) {
6950 DHD_ERROR(("readmap error 0X%x \n", count));
6955 dhd_init_static_strs_array(dhd_event_log_t *temp, char *str_file, char *map_file)
6957 struct file *filep = NULL;
6959 char *raw_fmts = NULL;
6960 uint32 logstrs_size = 0;
6963 uint32 ramstart = 0;
6964 uint32 rodata_start = 0;
6965 uint32 rodata_end = 0;
6966 uint32 logfilebase = 0;
6968 error = dhd_read_map(map_file, &ramstart, &rodata_start, &rodata_end);
6969 if (error == BCME_ERROR) {
6970 DHD_ERROR(("readmap Error!! \n"));
6971 /* don't do event log parsing in actual case */
6972 temp->raw_sstr = NULL;
6975 DHD_ERROR(("ramstart: 0x%x, rodata_start: 0x%x, rodata_end:0x%x\n",
6976 ramstart, rodata_start, rodata_end));
6981 filep = filp_open(str_file, O_RDONLY, 0);
6982 if (IS_ERR(filep)) {
6983 DHD_ERROR(("%s: Failed to open the file %s \n", __FUNCTION__, str_file));
6987 /* Full file size is huge. Just read required part */
6988 logstrs_size = rodata_end - rodata_start;
6990 raw_fmts = kmalloc(logstrs_size, GFP_KERNEL);
6991 if (raw_fmts == NULL) {
6992 DHD_ERROR(("%s: Failed to allocate raw_fmts memory \n", __FUNCTION__));
6996 logfilebase = rodata_start - ramstart;
6998 error = generic_file_llseek(filep, logfilebase, SEEK_SET);
7000 DHD_ERROR(("%s: %s llseek failed %d \n", __FUNCTION__, str_file, error));
7004 error = vfs_read(filep, raw_fmts, logstrs_size, (&filep->f_pos));
7005 if (error != logstrs_size) {
7006 DHD_ERROR(("%s: %s read failed %d \n", __FUNCTION__, str_file, error));
7010 if (strstr(str_file, ram_file_str) != NULL) {
7011 temp->raw_sstr = raw_fmts;
7012 temp->ramstart = ramstart;
7013 temp->rodata_start = rodata_start;
7014 temp->rodata_end = rodata_end;
7015 } else if (strstr(str_file, rom_file_str) != NULL) {
7016 temp->rom_raw_sstr = raw_fmts;
7017 temp->rom_ramstart = ramstart;
7018 temp->rom_rodata_start = rodata_start;
7019 temp->rom_rodata_end = rodata_end;
7022 filp_close(filep, NULL);
7032 filp_close(filep, NULL);
7034 if (strstr(str_file, ram_file_str) != NULL) {
7035 temp->raw_sstr = NULL;
7036 } else if (strstr(str_file, rom_file_str) != NULL) {
7037 temp->rom_raw_sstr = NULL;
7042 #endif /* SHOW_LOGTRACE */
7046 dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen)
7048 dhd_info_t *dhd = NULL;
7049 struct net_device *net = NULL;
7050 char if_name[IFNAMSIZ] = {'\0'};
7051 uint32 bus_type = -1;
7052 uint32 bus_num = -1;
7053 uint32 slot_num = -1;
7054 wifi_adapter_info_t *adapter = NULL;
7056 dhd_attach_states_t dhd_state = DHD_ATTACH_STATE_INIT;
7057 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
7060 DHD_ERROR(("%s\n", driver_target));
7061 #endif /* STBLINUX */
7062 /* will implement get_ids for DBUS later */
7063 #if defined(BCMSDIO)
7064 dhd_bus_get_ids(bus, &bus_type, &bus_num, &slot_num);
7066 adapter = dhd_wifi_platform_get_adapter(bus_type, bus_num, slot_num);
7068 /* Allocate primary dhd_info */
7069 dhd = wifi_platform_prealloc(adapter, DHD_PREALLOC_DHD_INFO, sizeof(dhd_info_t));
7071 dhd = MALLOC(osh, sizeof(dhd_info_t));
7073 DHD_ERROR(("%s: OOM - alloc dhd_info\n", __FUNCTION__));
7077 memset(dhd, 0, sizeof(dhd_info_t));
7078 dhd_state |= DHD_ATTACH_STATE_DHD_ALLOC;
7080 dhd->unit = dhd_found + instance_base; /* do not increment dhd_found, yet */
7083 dhd->adapter = adapter;
7085 #ifdef GET_CUSTOM_MAC_ENABLE
7086 wifi_platform_get_mac_addr(dhd->adapter, dhd->pub.mac.octet);
7087 #endif /* GET_CUSTOM_MAC_ENABLE */
7088 #ifdef CUSTOM_FORCE_NODFS_FLAG
7089 dhd->pub.dhd_cflags |= WLAN_PLAT_NODFS_FLAG;
7090 dhd->pub.force_country_change = TRUE;
7091 #endif /* CUSTOM_FORCE_NODFS_FLAG */
7092 #ifdef CUSTOM_COUNTRY_CODE
7093 get_customized_country_code(dhd->adapter,
7094 dhd->pub.dhd_cspec.country_abbrev, &dhd->pub.dhd_cspec,
7095 dhd->pub.dhd_cflags);
7096 #endif /* CUSTOM_COUNTRY_CODE */
7097 dhd->thr_dpc_ctl.thr_pid = DHD_PID_KT_TL_INVALID;
7098 dhd->thr_wdt_ctl.thr_pid = DHD_PID_KT_INVALID;
7100 /* Initialize thread based operation and lock */
7101 sema_init(&dhd->sdsem, 1);
7103 /* Link to info module */
7104 dhd->pub.info = dhd;
7107 /* Link to bus module */
7109 dhd->pub.hdrlen = bus_hdrlen;
7111 /* dhd_conf must be attached after linking dhd to dhd->pub.info,
7112 * because dhd_detech will check .info is NULL or not.
7114 if (dhd_conf_attach(&dhd->pub) != 0) {
7115 DHD_ERROR(("dhd_conf_attach failed\n"));
7118 dhd_conf_reset(&dhd->pub);
7119 dhd_conf_set_chiprev(&dhd->pub, dhd_bus_chip(bus), dhd_bus_chiprev(bus));
7120 dhd_conf_preinit(&dhd->pub);
7122 /* Some DHD modules (e.g. cfg80211) configures operation mode based on firmware name.
7123 * This is indeed a hack but we have to make it work properly before we have a better
7126 dhd_update_fw_nv_path(dhd);
7127 #ifndef BUILD_IN_KERNEL
7128 dhd_conf_read_config(&dhd->pub, dhd->conf_path);
7131 /* Set network interface name if it was provided as module parameter */
7132 if (iface_name[0]) {
7135 strncpy(if_name, iface_name, IFNAMSIZ);
7136 if_name[IFNAMSIZ - 1] = 0;
7137 len = strlen(if_name);
7138 ch = if_name[len - 1];
7139 if ((ch > '9' || ch < '0') && (len < IFNAMSIZ - 2))
7140 strcat(if_name, "%d");
7143 /* Passing NULL to dngl_name to ensure host gets if_name in dngl_name member */
7144 net = dhd_allocate_if(&dhd->pub, 0, if_name, NULL, 0, TRUE, NULL);
7150 dhd_state |= DHD_ATTACH_STATE_ADD_IF;
7151 #ifdef DHD_L2_FILTER
7152 /* initialize the l2_filter_cnt */
7153 dhd->pub.l2_filter_cnt = 0;
7155 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31))
7158 net->netdev_ops = NULL;
7161 mutex_init(&dhd->dhd_iovar_mutex);
7162 sema_init(&dhd->proto_sem, 1);
7164 #ifdef PROP_TXSTATUS
7165 spin_lock_init(&dhd->wlfc_spinlock);
7167 dhd->pub.skip_fc = dhd_wlfc_skip_fc;
7168 dhd->pub.plat_init = dhd_wlfc_plat_init;
7169 dhd->pub.plat_deinit = dhd_wlfc_plat_deinit;
7171 #ifdef DHD_WLFC_THREAD
7172 init_waitqueue_head(&dhd->pub.wlfc_wqhead);
7173 dhd->pub.wlfc_thread = kthread_create(dhd_wlfc_transfer_packets, &dhd->pub, "wlfc-thread");
7174 if (IS_ERR(dhd->pub.wlfc_thread)) {
7175 DHD_ERROR(("create wlfc thread failed\n"));
7178 wake_up_process(dhd->pub.wlfc_thread);
7180 #endif /* DHD_WLFC_THREAD */
7181 #endif /* PROP_TXSTATUS */
7183 /* Initialize other structure content */
7184 init_waitqueue_head(&dhd->ioctl_resp_wait);
7185 init_waitqueue_head(&dhd->d3ack_wait);
7186 init_waitqueue_head(&dhd->ctrl_wait);
7187 init_waitqueue_head(&dhd->dhd_bus_busy_state_wait);
7188 dhd->pub.dhd_bus_busy_state = 0;
7190 /* Initialize the spinlocks */
7191 spin_lock_init(&dhd->sdlock);
7192 spin_lock_init(&dhd->txqlock);
7193 spin_lock_init(&dhd->dhd_lock);
7194 spin_lock_init(&dhd->rxf_lock);
7195 #if defined(RXFRAME_THREAD)
7196 dhd->rxthread_enabled = TRUE;
7197 #endif /* defined(RXFRAME_THREAD) */
7199 #ifdef DHDTCPACK_SUPPRESS
7200 spin_lock_init(&dhd->tcpack_lock);
7201 #endif /* DHDTCPACK_SUPPRESS */
7203 /* Initialize Wakelock stuff */
7204 spin_lock_init(&dhd->wakelock_spinlock);
7205 spin_lock_init(&dhd->wakelock_evt_spinlock);
7206 DHD_OS_WAKE_LOCK_INIT(dhd);
7207 dhd->wakelock_wd_counter = 0;
7208 #ifdef CONFIG_HAS_WAKELOCK
7209 wake_lock_init(&dhd->wl_wdwake, WAKE_LOCK_SUSPEND, "wlan_wd_wake");
7210 #endif /* CONFIG_HAS_WAKELOCK */
7212 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
7213 mutex_init(&dhd->dhd_net_if_mutex);
7214 mutex_init(&dhd->dhd_suspend_mutex);
7216 dhd_state |= DHD_ATTACH_STATE_WAKELOCKS_INIT;
7218 /* Attach and link in the protocol */
7219 if (dhd_prot_attach(&dhd->pub) != 0) {
7220 DHD_ERROR(("dhd_prot_attach failed\n"));
7223 dhd_state |= DHD_ATTACH_STATE_PROT_ATTACH;
7226 /* Attach and link in the cfg80211 */
7227 if (unlikely(wl_cfg80211_attach(net, &dhd->pub))) {
7228 DHD_ERROR(("wl_cfg80211_attach failed\n"));
7232 dhd_monitor_init(&dhd->pub);
7233 dhd_state |= DHD_ATTACH_STATE_CFG80211;
7236 dhd_log_dump_init(&dhd->pub);
7237 #endif /* DHD_LOG_DUMP */
7238 #if defined(WL_WIRELESS_EXT)
7239 /* Attach and link in the iw */
7240 if (!(dhd_state & DHD_ATTACH_STATE_CFG80211)) {
7241 if (wl_iw_attach(net, (void *)&dhd->pub) != 0) {
7242 DHD_ERROR(("wl_iw_attach failed\n"));
7245 dhd_state |= DHD_ATTACH_STATE_WL_ATTACH;
7248 wl_escan_attach(net, (void *)&dhd->pub);
7250 #endif /* defined(WL_WIRELESS_EXT) */
7252 #ifdef SHOW_LOGTRACE
7253 dhd_init_logstrs_array(&dhd->event_data);
7254 dhd_init_static_strs_array(&dhd->event_data, st_str_file_path, map_file_path);
7255 dhd_init_static_strs_array(&dhd->event_data, rom_st_str_file_path, rom_map_file_path);
7256 #endif /* SHOW_LOGTRACE */
7258 if (dhd_sta_pool_init(&dhd->pub, DHD_MAX_STA) != BCME_OK) {
7259 DHD_ERROR(("%s: Initializing %u sta\n", __FUNCTION__, DHD_MAX_STA));
7265 /* Set up the watchdog timer */
7266 init_timer(&dhd->timer);
7267 dhd->timer.data = (ulong)dhd;
7268 dhd->timer.function = dhd_watchdog;
7269 dhd->default_wd_interval = dhd_watchdog_ms;
7271 if (dhd_watchdog_prio >= 0) {
7272 /* Initialize watchdog thread */
7273 PROC_START(dhd_watchdog_thread, dhd, &dhd->thr_wdt_ctl, 0, "dhd_watchdog_thread");
7274 if (dhd->thr_wdt_ctl.thr_pid < 0) {
7279 dhd->thr_wdt_ctl.thr_pid = -1;
7282 #ifdef DHD_PCIE_RUNTIMEPM
7283 /* Setup up the runtime PM Idlecount timer */
7284 init_timer(&dhd->rpm_timer);
7285 dhd->rpm_timer.data = (ulong)dhd;
7286 dhd->rpm_timer.function = dhd_runtimepm;
7287 dhd->rpm_timer_valid = FALSE;
7289 dhd->thr_rpm_ctl.thr_pid = DHD_PID_KT_INVALID;
7290 PROC_START(dhd_rpm_state_thread, dhd, &dhd->thr_rpm_ctl, 0, "dhd_rpm_state_thread");
7291 if (dhd->thr_rpm_ctl.thr_pid < 0) {
7294 #endif /* DHD_PCIE_RUNTIMEPM */
7297 debugger_init((void *) bus);
7300 /* Set up the bottom half handler */
7301 if (dhd_dpc_prio >= 0) {
7302 /* Initialize DPC thread */
7303 PROC_START(dhd_dpc_thread, dhd, &dhd->thr_dpc_ctl, 0, "dhd_dpc");
7304 if (dhd->thr_dpc_ctl.thr_pid < 0) {
7308 /* use tasklet for dpc */
7309 tasklet_init(&dhd->tasklet, dhd_dpc, (ulong)dhd);
7310 dhd->thr_dpc_ctl.thr_pid = -1;
7313 if (dhd->rxthread_enabled) {
7314 bzero(&dhd->pub.skbbuf[0], sizeof(void *) * MAXSKBPEND);
7315 /* Initialize RXF thread */
7316 PROC_START(dhd_rxf_thread, dhd, &dhd->thr_rxf_ctl, 0, "dhd_rxf");
7317 if (dhd->thr_rxf_ctl.thr_pid < 0) {
7322 dhd_state |= DHD_ATTACH_STATE_THREADS_CREATED;
7324 #if defined(CONFIG_PM_SLEEP)
7325 if (!dhd_pm_notifier_registered) {
7326 dhd_pm_notifier_registered = TRUE;
7327 dhd->pm_notifier.notifier_call = dhd_pm_callback;
7328 dhd->pm_notifier.priority = 10;
7329 register_pm_notifier(&dhd->pm_notifier);
7332 #endif /* CONFIG_PM_SLEEP */
7334 #if defined(CONFIG_HAS_EARLYSUSPEND) && defined(DHD_USE_EARLYSUSPEND)
7335 dhd->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 20;
7336 dhd->early_suspend.suspend = dhd_early_suspend;
7337 dhd->early_suspend.resume = dhd_late_resume;
7338 register_early_suspend(&dhd->early_suspend);
7339 dhd_state |= DHD_ATTACH_STATE_EARLYSUSPEND_DONE;
7340 #endif /* CONFIG_HAS_EARLYSUSPEND && DHD_USE_EARLYSUSPEND */
7342 #ifdef ARP_OFFLOAD_SUPPORT
7343 dhd->pend_ipaddr = 0;
7344 if (!dhd_inetaddr_notifier_registered) {
7345 dhd_inetaddr_notifier_registered = TRUE;
7346 register_inetaddr_notifier(&dhd_inetaddr_notifier);
7348 #endif /* ARP_OFFLOAD_SUPPORT */
7350 #if defined(CONFIG_IPV6) && defined(IPV6_NDO_SUPPORT)
7351 if (!dhd_inet6addr_notifier_registered) {
7352 dhd_inet6addr_notifier_registered = TRUE;
7353 register_inet6addr_notifier(&dhd_inet6addr_notifier);
7355 #endif /* CONFIG_IPV6 && IPV6_NDO_SUPPORT */
7356 dhd->dhd_deferred_wq = dhd_deferred_work_init((void *)dhd);
7357 #ifdef DEBUG_CPU_FREQ
7358 dhd->new_freq = alloc_percpu(int);
7359 dhd->freq_trans.notifier_call = dhd_cpufreq_notifier;
7360 cpufreq_register_notifier(&dhd->freq_trans, CPUFREQ_TRANSITION_NOTIFIER);
7362 #ifdef DHDTCPACK_SUPPRESS
7364 dhd_tcpack_suppress_set(&dhd->pub, TCPACK_SUP_DELAYTX);
7365 #elif defined(BCMPCIE)
7366 dhd_tcpack_suppress_set(&dhd->pub, TCPACK_SUP_HOLD);
7368 dhd_tcpack_suppress_set(&dhd->pub, TCPACK_SUP_OFF);
7369 #endif /* BCMSDIO */
7370 #endif /* DHDTCPACK_SUPPRESS */
7372 #if defined(BCM_DNGL_EMBEDIMAGE) || defined(BCM_REQUEST_FW)
7373 #endif /* defined(BCM_DNGL_EMBEDIMAGE) || defined(BCM_REQUEST_FW) */
7375 dhd_state |= DHD_ATTACH_STATE_DONE;
7376 dhd->dhd_state = dhd_state;
7379 #ifdef DHD_DEBUG_PAGEALLOC
7380 register_page_corrupt_cb(dhd_page_corrupt_cb, &dhd->pub);
7381 #endif /* DHD_DEBUG_PAGEALLOC */
7384 DHD_ERROR(("DHD LOAD BALANCING Enabled\n"));
7386 dhd_lb_set_default_cpus(dhd);
7388 /* Initialize the CPU Masks */
7389 if (dhd_cpumasks_init(dhd) == 0) {
7391 /* Now we have the current CPU maps, run through candidacy */
7392 dhd_select_cpu_candidacy(dhd);
7395 * If we are able to initialize CPU masks, lets register to the
7396 * CPU Hotplug framework to change the CPU for each job dynamically
7397 * using candidacy algorithm.
7399 dhd->cpu_notifier.notifier_call = dhd_cpu_callback;
7400 register_cpu_notifier(&dhd->cpu_notifier); /* Register a callback */
7403 * We are unable to initialize CPU masks, so candidacy algorithm
7404 * won't run, but still Load Balancing will be honoured based
7405 * on the CPUs allocated for a given job statically during init
7407 dhd->cpu_notifier.notifier_call = NULL;
7408 DHD_ERROR(("%s(): dhd_cpumasks_init failed CPUs for JOB would be static\n",
7413 DHD_LB_STATS_INIT(&dhd->pub);
7415 /* Initialize the Load Balancing Tasklets and Napi object */
7416 #if defined(DHD_LB_TXC)
7417 tasklet_init(&dhd->tx_compl_tasklet,
7418 dhd_lb_tx_compl_handler, (ulong)(&dhd->pub));
7419 INIT_WORK(&dhd->tx_compl_dispatcher_work, dhd_tx_compl_dispatcher_fn);
7420 DHD_INFO(("%s load balance init tx_compl_tasklet\n", __FUNCTION__));
7421 #endif /* DHD_LB_TXC */
7423 #if defined(DHD_LB_RXC)
7424 tasklet_init(&dhd->rx_compl_tasklet,
7425 dhd_lb_rx_compl_handler, (ulong)(&dhd->pub));
7426 INIT_WORK(&dhd->rx_compl_dispatcher_work, dhd_rx_compl_dispatcher_fn);
7427 DHD_INFO(("%s load balance init rx_compl_tasklet\n", __FUNCTION__));
7428 #endif /* DHD_LB_RXC */
7430 #if defined(DHD_LB_RXP)
7431 __skb_queue_head_init(&dhd->rx_pend_queue);
7432 skb_queue_head_init(&dhd->rx_napi_queue);
7434 /* Initialize the work that dispatches NAPI job to a given core */
7435 INIT_WORK(&dhd->rx_napi_dispatcher_work, dhd_rx_napi_dispatcher_fn);
7436 DHD_INFO(("%s load balance init rx_napi_queue\n", __FUNCTION__));
7437 #endif /* DHD_LB_RXP */
7441 INIT_DELAYED_WORK(&dhd->dhd_memdump_work, dhd_memdump_work_handler);
7443 (void)dhd_sysfs_init(dhd);
7448 if (dhd_state >= DHD_ATTACH_STATE_DHD_ALLOC) {
7449 DHD_TRACE(("%s: Calling dhd_detach dhd_state 0x%x &dhd->pub %p\n",
7450 __FUNCTION__, dhd_state, &dhd->pub));
7451 dhd->dhd_state = dhd_state;
7452 dhd_detach(&dhd->pub);
7453 dhd_free(&dhd->pub);
7459 #include <linux/delay.h>
7461 void dhd_memdump_work_schedule(dhd_pub_t *dhdp, unsigned long msecs)
7463 dhd_info_t *dhd = (dhd_info_t*)dhdp->info;
7465 schedule_delayed_work(&dhd->dhd_memdump_work, msecs_to_jiffies(msecs));
7468 int dhd_get_fw_mode(dhd_info_t *dhdinfo)
7470 if (strstr(dhdinfo->fw_path, "_apsta") != NULL)
7471 return DHD_FLAG_HOSTAP_MODE;
7472 if (strstr(dhdinfo->fw_path, "_p2p") != NULL)
7473 return DHD_FLAG_P2P_MODE;
7474 if (strstr(dhdinfo->fw_path, "_ibss") != NULL)
7475 return DHD_FLAG_IBSS_MODE;
7476 if (strstr(dhdinfo->fw_path, "_mfg") != NULL)
7477 return DHD_FLAG_MFG_MODE;
7479 return DHD_FLAG_STA_MODE;
7482 extern int rkwifi_set_firmware(char *fw, char *nvram);
7483 bool dhd_update_fw_nv_path(dhd_info_t *dhdinfo)
7488 const char *fw = NULL;
7489 const char *nv = NULL;
7490 const char *conf = NULL;
7491 char firmware[100] = {0};
7492 char nvram[100] = {0};
7493 wifi_adapter_info_t *adapter = dhdinfo->adapter;
7496 /* Update firmware and nvram path. The path may be from adapter info or module parameter
7497 * The path from adapter info is used for initialization only (as it won't change).
7499 * The firmware_path/nvram_path module parameter may be changed by the system at run
7500 * time. When it changes we need to copy it to dhdinfo->fw_path. Also Android private
7501 * command may change dhdinfo->fw_path. As such we need to clear the path info in
7502 * module parameter after it is copied. We won't update the path until the module parameter
7503 * is changed again (first character is not '\0')
7506 /* set default firmware and nvram path for built-in type driver */
7507 // if (!dhd_download_fw_on_driverload) {
7508 rkwifi_set_firmware(firmware, nvram);
7509 #ifdef CONFIG_BCMDHD_FW_PATH
7510 fw = CONFIG_BCMDHD_FW_PATH;
7513 #endif /* CONFIG_BCMDHD_FW_PATH */
7514 #ifdef CONFIG_BCMDHD_NVRAM_PATH
7515 nv = CONFIG_BCMDHD_NVRAM_PATH;
7518 #endif /* CONFIG_BCMDHD_NVRAM_PATH */
7521 /* check if we need to initialize the path */
7522 if (dhdinfo->fw_path[0] == '\0') {
7523 if (adapter && adapter->fw_path && adapter->fw_path[0] != '\0')
7524 fw = adapter->fw_path;
7527 if (dhdinfo->nv_path[0] == '\0') {
7528 if (adapter && adapter->nv_path && adapter->nv_path[0] != '\0')
7529 nv = adapter->nv_path;
7531 if (dhdinfo->conf_path[0] == '\0') {
7532 if (adapter && adapter->conf_path && adapter->conf_path[0] != '\0')
7533 conf = adapter->conf_path;
7536 /* Use module parameter if it is valid, EVEN IF the path has not been initialized
7538 * TODO: need a solution for multi-chip, can't use the same firmware for all chips
7540 if (firmware_path[0] != '\0')
7542 if (nvram_path[0] != '\0')
7544 if (config_path[0] != '\0')
7547 if (fw && fw[0] != '\0') {
7548 fw_len = strlen(fw);
7549 if (fw_len >= sizeof(dhdinfo->fw_path)) {
7550 DHD_ERROR(("fw path len exceeds max len of dhdinfo->fw_path\n"));
7553 strncpy(dhdinfo->fw_path, fw, sizeof(dhdinfo->fw_path));
7554 if (dhdinfo->fw_path[fw_len-1] == '\n')
7555 dhdinfo->fw_path[fw_len-1] = '\0';
7557 if (nv && nv[0] != '\0') {
7558 nv_len = strlen(nv);
7559 if (nv_len >= sizeof(dhdinfo->nv_path)) {
7560 DHD_ERROR(("nvram path len exceeds max len of dhdinfo->nv_path\n"));
7563 strncpy(dhdinfo->nv_path, nv, sizeof(dhdinfo->nv_path));
7564 if (dhdinfo->nv_path[nv_len-1] == '\n')
7565 dhdinfo->nv_path[nv_len-1] = '\0';
7567 if (conf && conf[0] != '\0') {
7568 conf_len = strlen(conf);
7569 if (conf_len >= sizeof(dhdinfo->conf_path)) {
7570 DHD_ERROR(("config path len exceeds max len of dhdinfo->conf_path\n"));
7573 strncpy(dhdinfo->conf_path, conf, sizeof(dhdinfo->conf_path));
7574 if (dhdinfo->conf_path[conf_len-1] == '\n')
7575 dhdinfo->conf_path[conf_len-1] = '\0';
7579 /* clear the path in module parameter */
7580 if (dhd_download_fw_on_driverload) {
7581 firmware_path[0] = '\0';
7582 nvram_path[0] = '\0';
7583 config_path[0] = '\0';
7587 #ifndef BCMEMBEDIMAGE
7588 /* fw_path and nv_path are not mandatory for BCMEMBEDIMAGE */
7589 if (dhdinfo->fw_path[0] == '\0') {
7590 DHD_ERROR(("firmware path not found\n"));
7593 if (dhdinfo->nv_path[0] == '\0') {
7594 DHD_ERROR(("nvram path not found\n"));
7597 if (dhdinfo->conf_path[0] == '\0') {
7598 dhd_conf_set_conf_path_by_nv_path(&dhdinfo->pub, dhdinfo->conf_path, dhdinfo->nv_path);
7600 #ifdef CONFIG_PATH_AUTO_SELECT
7601 dhd_conf_set_conf_name_by_chip(&dhdinfo->pub, dhdinfo->conf_path);
7603 #endif /* BCMEMBEDIMAGE */
7608 #ifdef CUSTOMER_HW4_DEBUG
7609 bool dhd_validate_chipid(dhd_pub_t *dhdp)
7611 uint chipid = dhd_bus_chip_id(dhdp);
7615 config_chipid = BCM4359_CHIP_ID;
7616 #elif defined(BCM4358_CHIP)
7617 config_chipid = BCM4358_CHIP_ID;
7618 #elif defined(BCM4354_CHIP)
7619 config_chipid = BCM4354_CHIP_ID;
7620 #elif defined(BCM4356_CHIP)
7621 config_chipid = BCM4356_CHIP_ID;
7622 #elif defined(BCM4339_CHIP)
7623 config_chipid = BCM4339_CHIP_ID;
7624 #elif defined(BCM43349_CHIP)
7625 config_chipid = BCM43349_CHIP_ID;
7626 #elif defined(BCM4335_CHIP)
7627 config_chipid = BCM4335_CHIP_ID;
7628 #elif defined(BCM43241_CHIP)
7629 config_chipid = BCM4324_CHIP_ID;
7630 #elif defined(BCM4330_CHIP)
7631 config_chipid = BCM4330_CHIP_ID;
7632 #elif defined(BCM43430_CHIP)
7633 config_chipid = BCM43430_CHIP_ID;
7634 #elif defined(BCM4334W_CHIP)
7635 config_chipid = BCM43342_CHIP_ID;
7636 #elif defined(BCM43455_CHIP)
7637 config_chipid = BCM4345_CHIP_ID;
7639 DHD_ERROR(("%s: Unknown chip id, if you use new chipset,"
7640 " please add CONFIG_BCMXXXX into the Kernel and"
7641 " BCMXXXX_CHIP definition into the DHD driver\n",
7646 #endif /* BCM4354_CHIP */
7648 #if defined(BCM4359_CHIP)
7649 if (chipid == BCM4355_CHIP_ID && config_chipid == BCM4359_CHIP_ID) {
7652 #endif /* BCM4359_CHIP */
7654 return config_chipid == chipid;
7656 #endif /* CUSTOMER_HW4_DEBUG */
7659 dhd_bus_start(dhd_pub_t *dhdp)
7662 dhd_info_t *dhd = (dhd_info_t*)dhdp->info;
7663 unsigned long flags;
7667 DHD_TRACE(("Enter %s:\n", __FUNCTION__));
7669 DHD_PERIM_LOCK(dhdp);
7671 /* try to download image and nvram to the dongle */
7672 if (dhd->pub.busstate == DHD_BUS_DOWN && dhd_update_fw_nv_path(dhd)) {
7673 /* Indicate FW Download has not yet done */
7674 dhd->pub.is_fw_download_done = FALSE;
7675 DHD_INFO(("%s download fw %s, nv %s, conf %s\n",
7676 __FUNCTION__, dhd->fw_path, dhd->nv_path, dhd->conf_path));
7677 ret = dhd_bus_download_firmware(dhd->pub.bus, dhd->pub.osh,
7678 dhd->fw_path, dhd->nv_path, dhd->conf_path);
7680 DHD_ERROR(("%s: failed to download firmware %s\n",
7681 __FUNCTION__, dhd->fw_path));
7682 DHD_PERIM_UNLOCK(dhdp);
7685 /* Indicate FW Download has succeeded */
7686 dhd->pub.is_fw_download_done = TRUE;
7688 if (dhd->pub.busstate != DHD_BUS_LOAD) {
7689 DHD_PERIM_UNLOCK(dhdp);
7693 dhd_os_sdlock(dhdp);
7695 /* Start the watchdog timer */
7696 dhd->pub.tickcnt = 0;
7697 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
7698 DHD_ENABLE_RUNTIME_PM(&dhd->pub);
7700 /* Bring up the bus */
7701 if ((ret = dhd_bus_init(&dhd->pub, FALSE)) != 0) {
7703 DHD_ERROR(("%s, dhd_bus_init failed %d\n", __FUNCTION__, ret));
7704 dhd_os_sdunlock(dhdp);
7705 DHD_PERIM_UNLOCK(dhdp);
7708 #if defined(OOB_INTR_ONLY) || defined(BCMPCIE_OOB_HOST_WAKE)
7709 #if defined(BCMPCIE_OOB_HOST_WAKE)
7710 dhd_os_sdunlock(dhdp);
7711 #endif /* BCMPCIE_OOB_HOST_WAKE */
7712 /* Host registration for OOB interrupt */
7713 if (dhd_bus_oob_intr_register(dhdp)) {
7714 /* deactivate timer and wait for the handler to finish */
7715 #if !defined(BCMPCIE_OOB_HOST_WAKE)
7716 DHD_GENERAL_LOCK(&dhd->pub, flags);
7717 dhd->wd_timer_valid = FALSE;
7718 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
7719 del_timer_sync(&dhd->timer);
7721 dhd_os_sdunlock(dhdp);
7722 #endif /* !BCMPCIE_OOB_HOST_WAKE */
7723 DHD_DISABLE_RUNTIME_PM(&dhd->pub);
7724 DHD_PERIM_UNLOCK(dhdp);
7725 DHD_OS_WD_WAKE_UNLOCK(&dhd->pub);
7726 DHD_ERROR(("%s Host failed to register for OOB\n", __FUNCTION__));
7730 #if defined(BCMPCIE_OOB_HOST_WAKE)
7731 dhd_os_sdlock(dhdp);
7732 dhd_bus_oob_intr_set(dhdp, TRUE);
7734 /* Enable oob at firmware */
7735 dhd_enable_oob_intr(dhd->pub.bus, TRUE);
7736 #endif /* BCMPCIE_OOB_HOST_WAKE */
7737 #elif defined(FORCE_WOWLAN)
7738 /* Enable oob at firmware */
7739 dhd_enable_oob_intr(dhd->pub.bus, TRUE);
7741 #ifdef PCIE_FULL_DONGLE
7743 /* max_h2d_rings includes H2D common rings */
7744 uint32 max_h2d_rings = dhd_bus_max_h2d_queues(dhd->pub.bus);
7746 DHD_ERROR(("%s: Initializing %u h2drings\n", __FUNCTION__,
7748 if ((ret = dhd_flow_rings_init(&dhd->pub, max_h2d_rings)) != BCME_OK) {
7749 dhd_os_sdunlock(dhdp);
7750 DHD_PERIM_UNLOCK(dhdp);
7754 #endif /* PCIE_FULL_DONGLE */
7756 /* Do protocol initialization necessary for IOCTL/IOVAR */
7757 #ifdef PCIE_FULL_DONGLE
7758 dhd_os_sdunlock(dhdp);
7759 #endif /* PCIE_FULL_DONGLE */
7760 ret = dhd_prot_init(&dhd->pub);
7761 if (unlikely(ret) != BCME_OK) {
7762 DHD_PERIM_UNLOCK(dhdp);
7763 DHD_OS_WD_WAKE_UNLOCK(&dhd->pub);
7766 #ifdef PCIE_FULL_DONGLE
7767 dhd_os_sdlock(dhdp);
7768 #endif /* PCIE_FULL_DONGLE */
7770 /* If bus is not ready, can't come up */
7771 if (dhd->pub.busstate != DHD_BUS_DATA) {
7772 DHD_GENERAL_LOCK(&dhd->pub, flags);
7773 dhd->wd_timer_valid = FALSE;
7774 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
7775 del_timer_sync(&dhd->timer);
7776 DHD_ERROR(("%s failed bus is not ready\n", __FUNCTION__));
7777 DHD_DISABLE_RUNTIME_PM(&dhd->pub);
7778 dhd_os_sdunlock(dhdp);
7779 DHD_PERIM_UNLOCK(dhdp);
7780 DHD_OS_WD_WAKE_UNLOCK(&dhd->pub);
7784 dhd_os_sdunlock(dhdp);
7786 /* Bus is ready, query any dongle information */
7787 if ((ret = dhd_sync_with_dongle(&dhd->pub)) < 0) {
7788 DHD_GENERAL_LOCK(&dhd->pub, flags);
7789 dhd->wd_timer_valid = FALSE;
7790 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
7791 del_timer_sync(&dhd->timer);
7792 DHD_ERROR(("%s failed to sync with dongle\n", __FUNCTION__));
7793 DHD_DISABLE_RUNTIME_PM(&dhd->pub);
7794 DHD_OS_WD_WAKE_UNLOCK(&dhd->pub);
7795 DHD_PERIM_UNLOCK(dhdp);
7799 #ifdef ARP_OFFLOAD_SUPPORT
7800 if (dhd->pend_ipaddr) {
7801 #ifdef AOE_IP_ALIAS_SUPPORT
7802 aoe_update_host_ipv4_table(&dhd->pub, dhd->pend_ipaddr, TRUE, 0);
7803 #endif /* AOE_IP_ALIAS_SUPPORT */
7804 dhd->pend_ipaddr = 0;
7806 #endif /* ARP_OFFLOAD_SUPPORT */
7808 DHD_PERIM_UNLOCK(dhdp);
7813 int _dhd_tdls_enable(dhd_pub_t *dhd, bool tdls_on, bool auto_on, struct ether_addr *mac)
7815 char iovbuf[WLC_IOCTL_SMLEN];
7816 uint32 tdls = tdls_on;
7818 uint32 tdls_auto_op = 0;
7819 uint32 tdls_idle_time = CUSTOM_TDLS_IDLE_MODE_SETTING;
7820 int32 tdls_rssi_high = CUSTOM_TDLS_RSSI_THRESHOLD_HIGH;
7821 int32 tdls_rssi_low = CUSTOM_TDLS_RSSI_THRESHOLD_LOW;
7823 if (!FW_SUPPORTED(dhd, tdls))
7826 if (dhd->tdls_enable == tdls_on)
7828 bcm_mkiovar("tdls_enable", (char *)&tdls, sizeof(tdls), iovbuf, sizeof(iovbuf));
7829 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0)) < 0) {
7830 DHD_ERROR(("%s: tdls %d failed %d\n", __FUNCTION__, tdls, ret));
7833 dhd->tdls_enable = tdls_on;
7836 tdls_auto_op = auto_on;
7837 bcm_mkiovar("tdls_auto_op", (char *)&tdls_auto_op, sizeof(tdls_auto_op),
7838 iovbuf, sizeof(iovbuf));
7839 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf,
7840 sizeof(iovbuf), TRUE, 0)) < 0) {
7841 DHD_ERROR(("%s: tdls_auto_op failed %d\n", __FUNCTION__, ret));
7846 bcm_mkiovar("tdls_idle_time", (char *)&tdls_idle_time,
7847 sizeof(tdls_idle_time), iovbuf, sizeof(iovbuf));
7848 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf,
7849 sizeof(iovbuf), TRUE, 0)) < 0) {
7850 DHD_ERROR(("%s: tdls_idle_time failed %d\n", __FUNCTION__, ret));
7853 bcm_mkiovar("tdls_rssi_high", (char *)&tdls_rssi_high, 4, iovbuf, sizeof(iovbuf));
7854 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf,
7855 sizeof(iovbuf), TRUE, 0)) < 0) {
7856 DHD_ERROR(("%s: tdls_rssi_high failed %d\n", __FUNCTION__, ret));
7859 bcm_mkiovar("tdls_rssi_low", (char *)&tdls_rssi_low, 4, iovbuf, sizeof(iovbuf));
7860 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf,
7861 sizeof(iovbuf), TRUE, 0)) < 0) {
7862 DHD_ERROR(("%s: tdls_rssi_low failed %d\n", __FUNCTION__, ret));
7871 int dhd_tdls_enable(struct net_device *dev, bool tdls_on, bool auto_on, struct ether_addr *mac)
7873 dhd_info_t *dhd = DHD_DEV_INFO(dev);
7876 ret = _dhd_tdls_enable(&dhd->pub, tdls_on, auto_on, mac);
7882 dhd_tdls_set_mode(dhd_pub_t *dhd, bool wfd_mode)
7884 char iovbuf[WLC_IOCTL_SMLEN];
7886 bool auto_on = false;
7887 uint32 mode = wfd_mode;
7889 #ifdef ENABLE_TDLS_AUTO_MODE
7897 #endif /* ENABLE_TDLS_AUTO_MODE */
7898 ret = _dhd_tdls_enable(dhd, false, auto_on, NULL);
7900 DHD_ERROR(("Disable tdls_auto_op failed. %d\n", ret));
7905 bcm_mkiovar("tdls_wfd_mode", (char *)&mode, sizeof(mode),
7906 iovbuf, sizeof(iovbuf));
7907 if (((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf,
7908 sizeof(iovbuf), TRUE, 0)) < 0) &&
7909 (ret != BCME_UNSUPPORTED)) {
7910 DHD_ERROR(("%s: tdls_wfd_mode faile_wfd_mode %d\n", __FUNCTION__, ret));
7914 ret = _dhd_tdls_enable(dhd, true, auto_on, NULL);
7916 DHD_ERROR(("enable tdls_auto_op failed. %d\n", ret));
7920 dhd->tdls_mode = mode;
7923 #ifdef PCIE_FULL_DONGLE
7924 void dhd_tdls_update_peer_info(struct net_device *dev, bool connect, uint8 *da)
7926 dhd_info_t *dhd = DHD_DEV_INFO(dev);
7927 dhd_pub_t *dhdp = (dhd_pub_t *)&dhd->pub;
7928 tdls_peer_node_t *cur = dhdp->peer_tbl.node;
7929 tdls_peer_node_t *new = NULL, *prev = NULL;
7931 uint8 sa[ETHER_ADDR_LEN];
7932 int ifidx = dhd_net2idx(dhd, dev);
7934 if (ifidx == DHD_BAD_IF)
7937 dhdif = dhd->iflist[ifidx];
7938 memcpy(sa, dhdif->mac_addr, ETHER_ADDR_LEN);
7941 while (cur != NULL) {
7942 if (!memcmp(da, cur->addr, ETHER_ADDR_LEN)) {
7943 DHD_ERROR(("%s: TDLS Peer exist already %d\n",
7944 __FUNCTION__, __LINE__));
7950 new = MALLOC(dhdp->osh, sizeof(tdls_peer_node_t));
7952 DHD_ERROR(("%s: Failed to allocate memory\n", __FUNCTION__));
7955 memcpy(new->addr, da, ETHER_ADDR_LEN);
7956 new->next = dhdp->peer_tbl.node;
7957 dhdp->peer_tbl.node = new;
7958 dhdp->peer_tbl.tdls_peer_count++;
7961 while (cur != NULL) {
7962 if (!memcmp(da, cur->addr, ETHER_ADDR_LEN)) {
7963 dhd_flow_rings_delete_for_peer(dhdp, ifidx, da);
7965 prev->next = cur->next;
7967 dhdp->peer_tbl.node = cur->next;
7968 MFREE(dhdp->osh, cur, sizeof(tdls_peer_node_t));
7969 dhdp->peer_tbl.tdls_peer_count--;
7975 DHD_ERROR(("%s: TDLS Peer Entry Not found\n", __FUNCTION__));
7978 #endif /* PCIE_FULL_DONGLE */
7981 bool dhd_is_concurrent_mode(dhd_pub_t *dhd)
7986 if (dhd->op_mode & DHD_FLAG_CONCURR_MULTI_CHAN_MODE)
7988 else if ((dhd->op_mode & DHD_FLAG_CONCURR_SINGLE_CHAN_MODE) ==
7989 DHD_FLAG_CONCURR_SINGLE_CHAN_MODE)
7994 #if !defined(AP) && defined(WLP2P)
7995 /* From Android JerryBean release, the concurrent mode is enabled by default and the firmware
7996 * name would be fw_bcmdhd.bin. So we need to determine whether P2P is enabled in the STA
7997 * firmware and accordingly enable concurrent mode (Apply P2P settings). SoftAP firmware
7998 * would still be named as fw_bcmdhd_apsta.
8001 dhd_get_concurrent_capabilites(dhd_pub_t *dhd)
8004 char buf[WLC_IOCTL_SMLEN];
8005 bool mchan_supported = FALSE;
8006 /* if dhd->op_mode is already set for HOSTAP and Manufacturing
8007 * test mode, that means we only will use the mode as it is
8009 if (dhd->op_mode & (DHD_FLAG_HOSTAP_MODE | DHD_FLAG_MFG_MODE))
8011 if (FW_SUPPORTED(dhd, vsdb)) {
8012 mchan_supported = TRUE;
8014 if (!FW_SUPPORTED(dhd, p2p)) {
8015 DHD_TRACE(("Chip does not support p2p\n"));
8018 /* Chip supports p2p but ensure that p2p is really implemented in firmware or not */
8019 memset(buf, 0, sizeof(buf));
8020 bcm_mkiovar("p2p", 0, 0, buf, sizeof(buf));
8021 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_GET_VAR, buf, sizeof(buf),
8023 DHD_ERROR(("%s: Get P2P failed (error=%d)\n", __FUNCTION__, ret));
8027 /* By default, chip supports single chan concurrency,
8028 * now lets check for mchan
8030 ret = DHD_FLAG_CONCURR_SINGLE_CHAN_MODE;
8031 if (mchan_supported)
8032 ret |= DHD_FLAG_CONCURR_MULTI_CHAN_MODE;
8033 if (FW_SUPPORTED(dhd, rsdb)) {
8034 ret |= DHD_FLAG_RSDB_MODE;
8036 if (FW_SUPPORTED(dhd, mp2p)) {
8037 ret |= DHD_FLAG_MP2P_MODE;
8039 #if defined(WL_ENABLE_P2P_IF) || defined(WL_CFG80211_P2P_DEV_IF)
8043 #endif /* WL_ENABLE_P2P_IF || WL_CFG80211_P2P_DEV_IF */
8051 #ifdef SUPPORT_AP_POWERSAVE
8052 #define RXCHAIN_PWRSAVE_PPS 10
8053 #define RXCHAIN_PWRSAVE_QUIET_TIME 10
8054 #define RXCHAIN_PWRSAVE_STAS_ASSOC_CHECK 0
8055 int dhd_set_ap_powersave(dhd_pub_t *dhdp, int ifidx, int enable)
8058 int32 pps = RXCHAIN_PWRSAVE_PPS;
8059 int32 quiet_time = RXCHAIN_PWRSAVE_QUIET_TIME;
8060 int32 stas_assoc_check = RXCHAIN_PWRSAVE_STAS_ASSOC_CHECK;
8063 bcm_mkiovar("rxchain_pwrsave_enable", (char *)&enable, 4, iovbuf, sizeof(iovbuf));
8064 if (dhd_wl_ioctl_cmd(dhdp, WLC_SET_VAR,
8065 iovbuf, sizeof(iovbuf), TRUE, 0) != BCME_OK) {
8066 DHD_ERROR(("Failed to enable AP power save\n"));
8068 bcm_mkiovar("rxchain_pwrsave_pps", (char *)&pps, 4, iovbuf, sizeof(iovbuf));
8069 if (dhd_wl_ioctl_cmd(dhdp, WLC_SET_VAR,
8070 iovbuf, sizeof(iovbuf), TRUE, 0) != BCME_OK) {
8071 DHD_ERROR(("Failed to set pps\n"));
8073 bcm_mkiovar("rxchain_pwrsave_quiet_time", (char *)&quiet_time,
8074 4, iovbuf, sizeof(iovbuf));
8075 if (dhd_wl_ioctl_cmd(dhdp, WLC_SET_VAR,
8076 iovbuf, sizeof(iovbuf), TRUE, 0) != BCME_OK) {
8077 DHD_ERROR(("Failed to set quiet time\n"));
8079 bcm_mkiovar("rxchain_pwrsave_stas_assoc_check", (char *)&stas_assoc_check,
8080 4, iovbuf, sizeof(iovbuf));
8081 if (dhd_wl_ioctl_cmd(dhdp, WLC_SET_VAR,
8082 iovbuf, sizeof(iovbuf), TRUE, 0) != BCME_OK) {
8083 DHD_ERROR(("Failed to set stas assoc check\n"));
8086 bcm_mkiovar("rxchain_pwrsave_enable", (char *)&enable, 4, iovbuf, sizeof(iovbuf));
8087 if (dhd_wl_ioctl_cmd(dhdp, WLC_SET_VAR,
8088 iovbuf, sizeof(iovbuf), TRUE, 0) != BCME_OK) {
8089 DHD_ERROR(("Failed to disable AP power save\n"));
8095 #endif /* SUPPORT_AP_POWERSAVE */
8099 dhd_preinit_ioctls(dhd_pub_t *dhd)
8102 char eventmask[WL_EVENTING_MASK_LEN];
8103 char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" + '\0' + bitvec */
8104 uint32 buf_key_b4_m4 = 1;
8109 eventmsgs_ext_t *eventmask_msg = NULL;
8110 char* iov_buf = NULL;
8112 #if defined(CUSTOM_AMPDU_BA_WSIZE)
8113 uint32 ampdu_ba_wsize = 0;
8115 #if defined(CUSTOM_AMPDU_MPDU)
8116 int32 ampdu_mpdu = 0;
8118 #if defined(CUSTOM_AMPDU_RELEASE)
8119 int32 ampdu_release = 0;
8121 #if defined(CUSTOM_AMSDU_AGGSF)
8122 int32 amsdu_aggsf = 0;
8124 #ifdef SUPPORT_SENSORHUB
8125 int32 shub_enable = 0;
8126 #endif /* SUPPORT_SENSORHUB */
8127 #if defined(BCMSDIO)
8128 #ifdef PROP_TXSTATUS
8129 int wlfc_enable = TRUE;
8131 uint32 hostreorder = 1;
8133 #endif /* DISABLE_11N */
8134 #endif /* PROP_TXSTATUS */
8136 #ifdef PCIE_FULL_DONGLE
8137 uint32 wl_ap_isolate;
8138 #endif /* PCIE_FULL_DONGLE */
8140 #if defined(BCMSDIO)
8141 /* by default frame burst is enabled for PCIe and disabled for SDIO dongles */
8142 uint32 frameburst = 0;
8144 uint32 frameburst = 1;
8145 #endif /* BCMSDIO */
8147 #ifdef DHD_ENABLE_LPC
8149 #endif /* DHD_ENABLE_LPC */
8150 uint power_mode = PM_FAST;
8151 #if defined(BCMSDIO)
8152 uint32 dongle_align = DHD_SDALIGN;
8153 uint32 glom = CUSTOM_GLOM_SETTING;
8154 #endif /* defined(BCMSDIO) */
8155 #if defined(CUSTOMER_HW2) && defined(USE_WL_CREDALL)
8158 uint bcn_timeout = dhd->conf->bcn_timeout;
8159 #ifdef ENABLE_BCN_LI_BCN_WAKEUP
8160 uint32 bcn_li_bcn = 1;
8161 #endif /* ENABLE_BCN_LI_BCN_WAKEUP */
8162 uint retry_max = CUSTOM_ASSOC_RETRY_MAX;
8163 #if defined(ARP_OFFLOAD_SUPPORT)
8166 int scan_assoc_time = DHD_SCAN_ASSOC_ACTIVE_TIME;
8167 int scan_unassoc_time = DHD_SCAN_UNASSOC_ACTIVE_TIME;
8168 int scan_passive_time = DHD_SCAN_PASSIVE_TIME;
8169 char buf[WLC_IOCTL_SMLEN];
8171 uint32 listen_interval = CUSTOM_LISTEN_INTERVAL; /* Default Listen Interval in Beacons */
8174 int roam_trigger[2] = {CUSTOM_ROAM_TRIGGER_SETTING, WLC_BAND_ALL};
8175 int roam_scan_period[2] = {10, WLC_BAND_ALL};
8176 int roam_delta[2] = {CUSTOM_ROAM_DELTA_SETTING, WLC_BAND_ALL};
8177 #ifdef FULL_ROAMING_SCAN_PERIOD_60_SEC
8178 int roam_fullscan_period = 60;
8179 #else /* FULL_ROAMING_SCAN_PERIOD_60_SEC */
8180 int roam_fullscan_period = 120;
8181 #endif /* FULL_ROAMING_SCAN_PERIOD_60_SEC */
8183 #ifdef DISABLE_BUILTIN_ROAM
8185 #endif /* DISABLE_BUILTIN_ROAM */
8186 #endif /* ROAM_ENABLE */
8191 #if (defined(AP) && !defined(WLP2P)) || (!defined(AP) && defined(WL_CFG80211))
8192 uint32 mpc = 0; /* Turn MPC off for AP/APSTA mode */
8193 struct ether_addr p2p_ea;
8195 #ifdef SOFTAP_UAPSD_OFF
8196 uint32 wme_apsd = 0;
8197 #endif /* SOFTAP_UAPSD_OFF */
8198 #if (defined(AP) || defined(WLP2P)) && !defined(SOFTAP_AND_GC)
8199 uint32 apsta = 1; /* Enable APSTA mode */
8200 #elif defined(SOFTAP_AND_GC)
8203 #endif /* (defined(AP) || defined(WLP2P)) && !defined(SOFTAP_AND_GC) */
8204 #ifdef GET_CUSTOM_MAC_ENABLE
8205 struct ether_addr ea_addr;
8206 #endif /* GET_CUSTOM_MAC_ENABLE */
8210 #endif /* DISABLE_11N */
8214 #endif /* USE_WL_TXBF */
8215 #if defined(PROP_TXSTATUS)
8216 #ifdef USE_WFA_CERT_CONF
8218 #endif /* USE_WFA_CERT_CONF */
8219 #endif /* PROP_TXSTATUS */
8220 #ifdef CUSTOM_PSPRETEND_THR
8221 uint32 pspretend_thr = CUSTOM_PSPRETEND_THR;
8223 uint32 rsdb_mode = 0;
8224 #ifdef ENABLE_TEMP_THROTTLING
8225 wl_temp_control_t temp_control;
8226 #endif /* ENABLE_TEMP_THROTTLING */
8227 #ifdef DISABLE_PRUNED_SCAN
8228 uint32 scan_features = 0;
8229 #endif /* DISABLE_PRUNED_SCAN */
8230 #ifdef CUSTOM_EVENT_PM_WAKE
8231 uint32 pm_awake_thresh = CUSTOM_EVENT_PM_WAKE;
8232 #endif /* CUSTOM_EVENT_PM_WAKE */
8233 #ifdef PKT_FILTER_SUPPORT
8234 dhd_pkt_filter_enable = TRUE;
8235 #endif /* PKT_FILTER_SUPPORT */
8237 dhd->tdls_enable = FALSE;
8238 dhd_tdls_set_mode(dhd, false);
8240 dhd->suspend_bcn_li_dtim = CUSTOM_SUSPEND_BCN_LI_DTIM;
8241 DHD_TRACE(("Enter %s\n", __FUNCTION__));
8243 dhd_conf_set_fw_int_cmd(dhd, "WLC_SET_BAND", WLC_SET_BAND, dhd->conf->band, 0, FALSE);
8244 #ifdef DHDTCPACK_SUPPRESS
8245 printf("%s: Set tcpack_sup_mode %d\n", __FUNCTION__, dhd->conf->tcpack_sup_mode);
8246 dhd_tcpack_suppress_set(dhd, dhd->conf->tcpack_sup_mode);
8250 #ifdef CUSTOMER_HW4_DEBUG
8251 if (!dhd_validate_chipid(dhd)) {
8252 DHD_ERROR(("%s: CONFIG_BCMXXX and CHIP ID(%x) is mismatched\n",
8253 __FUNCTION__, dhd_bus_chip_id(dhd)));
8254 #ifndef SUPPORT_MULTIPLE_CHIPS
8257 #endif /* !SUPPORT_MULTIPLE_CHIPS */
8259 #endif /* CUSTOMER_HW4_DEBUG */
8260 if ((!op_mode && dhd_get_fw_mode(dhd->info) == DHD_FLAG_MFG_MODE) ||
8261 (op_mode == DHD_FLAG_MFG_MODE)) {
8262 #ifdef DHD_PCIE_RUNTIMEPM
8263 /* Disable RuntimePM in mfg mode */
8264 DHD_DISABLE_RUNTIME_PM(dhd);
8265 DHD_ERROR(("%s : Disable RuntimePM in Manufactring Firmware\n", __FUNCTION__));
8266 #endif /* DHD_PCIE_RUNTIME_PM */
8267 /* Check and adjust IOCTL response timeout for Manufactring firmware */
8268 dhd_os_set_ioctl_resp_timeout(MFG_IOCTL_RESP_TIMEOUT);
8269 DHD_ERROR(("%s : Set IOCTL response time for Manufactring Firmware\n",
8272 dhd_os_set_ioctl_resp_timeout(IOCTL_RESP_TIMEOUT);
8273 DHD_INFO(("%s : Set IOCTL response time.\n", __FUNCTION__));
8275 #ifdef GET_CUSTOM_MAC_ENABLE
8276 ret = wifi_platform_get_mac_addr(dhd->info->adapter, ea_addr.octet);
8278 memset(buf, 0, sizeof(buf));
8279 bcm_mkiovar("cur_etheraddr", (void *)&ea_addr, ETHER_ADDR_LEN, buf, sizeof(buf));
8280 ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, buf, sizeof(buf), TRUE, 0);
8282 DHD_ERROR(("%s: can't set MAC address MAC="MACDBG", error=%d\n",
8283 __FUNCTION__, MAC2STRDBG(ea_addr.octet), ret));
8287 memcpy(dhd->mac.octet, ea_addr.octet, ETHER_ADDR_LEN);
8289 #endif /* GET_CUSTOM_MAC_ENABLE */
8290 /* Get the default device MAC address directly from firmware */
8291 memset(buf, 0, sizeof(buf));
8292 bcm_mkiovar("cur_etheraddr", 0, 0, buf, sizeof(buf));
8293 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_GET_VAR, buf, sizeof(buf),
8295 DHD_ERROR(("%s: can't get MAC address , error=%d\n", __FUNCTION__, ret));
8299 /* Update public MAC address after reading from Firmware */
8300 memcpy(dhd->mac.octet, buf, ETHER_ADDR_LEN);
8302 #ifdef GET_CUSTOM_MAC_ENABLE
8304 #endif /* GET_CUSTOM_MAC_ENABLE */
8306 /* get a capabilities from firmware */
8308 uint32 cap_buf_size = sizeof(dhd->fw_capabilities);
8309 memset(dhd->fw_capabilities, 0, cap_buf_size);
8310 bcm_mkiovar("cap", 0, 0, dhd->fw_capabilities, cap_buf_size - 1);
8311 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_GET_VAR, dhd->fw_capabilities,
8312 (cap_buf_size - 1), FALSE, 0)) < 0)
8314 DHD_ERROR(("%s: Get Capability failed (error=%d)\n",
8315 __FUNCTION__, ret));
8319 memmove(&dhd->fw_capabilities[1], dhd->fw_capabilities, (cap_buf_size - 1));
8320 dhd->fw_capabilities[0] = ' ';
8321 dhd->fw_capabilities[cap_buf_size - 2] = ' ';
8322 dhd->fw_capabilities[cap_buf_size - 1] = '\0';
8325 if ((!op_mode && dhd_get_fw_mode(dhd->info) == DHD_FLAG_HOSTAP_MODE) ||
8326 (op_mode == DHD_FLAG_HOSTAP_MODE)) {
8327 #ifdef SET_RANDOM_MAC_SOFTAP
8329 #endif /* SET_RANDOM_MAC_SOFTAP */
8330 dhd->op_mode = DHD_FLAG_HOSTAP_MODE;
8331 #if defined(ARP_OFFLOAD_SUPPORT)
8334 #ifdef PKT_FILTER_SUPPORT
8335 dhd_pkt_filter_enable = FALSE;
8337 #ifdef SET_RANDOM_MAC_SOFTAP
8338 SRANDOM32((uint)jiffies);
8339 rand_mac = RANDOM32();
8340 iovbuf[0] = (unsigned char)(vendor_oui >> 16) | 0x02; /* local admin bit */
8341 iovbuf[1] = (unsigned char)(vendor_oui >> 8);
8342 iovbuf[2] = (unsigned char)vendor_oui;
8343 iovbuf[3] = (unsigned char)(rand_mac & 0x0F) | 0xF0;
8344 iovbuf[4] = (unsigned char)(rand_mac >> 8);
8345 iovbuf[5] = (unsigned char)(rand_mac >> 16);
8347 bcm_mkiovar("cur_etheraddr", (void *)iovbuf, ETHER_ADDR_LEN, buf, sizeof(buf));
8348 ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, buf, sizeof(buf), TRUE, 0);
8350 DHD_ERROR(("%s: can't set MAC address , error=%d\n", __FUNCTION__, ret));
8352 memcpy(dhd->mac.octet, iovbuf, ETHER_ADDR_LEN);
8353 #endif /* SET_RANDOM_MAC_SOFTAP */
8354 #if !defined(AP) && defined(WL_CFG80211)
8355 /* Turn off MPC in AP mode */
8356 bcm_mkiovar("mpc", (char *)&mpc, 4, iovbuf, sizeof(iovbuf));
8357 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf,
8358 sizeof(iovbuf), TRUE, 0)) < 0) {
8359 DHD_ERROR(("%s mpc for HostAPD failed %d\n", __FUNCTION__, ret));
8362 #ifdef USE_DYNAMIC_F2_BLKSIZE
8363 dhdsdio_func_blocksize(dhd, 2, DYNAMIC_F2_BLKSIZE_FOR_NONLEGACY);
8364 #endif /* USE_DYNAMIC_F2_BLKSIZE */
8365 #ifdef SUPPORT_AP_POWERSAVE
8366 dhd_set_ap_powersave(dhd, 0, TRUE);
8367 #endif /* SUPPORT_AP_POWERSAVE */
8368 #ifdef SOFTAP_UAPSD_OFF
8369 bcm_mkiovar("wme_apsd", (char *)&wme_apsd, 4, iovbuf, sizeof(iovbuf));
8370 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf,
8371 sizeof(iovbuf), TRUE, 0)) < 0) {
8372 DHD_ERROR(("%s: set wme_apsd 0 fail (error=%d)\n",
8373 __FUNCTION__, ret));
8375 #endif /* SOFTAP_UAPSD_OFF */
8376 } else if ((!op_mode && dhd_get_fw_mode(dhd->info) == DHD_FLAG_MFG_MODE) ||
8377 (op_mode == DHD_FLAG_MFG_MODE)) {
8378 #if defined(ARP_OFFLOAD_SUPPORT)
8380 #endif /* ARP_OFFLOAD_SUPPORT */
8381 #ifdef PKT_FILTER_SUPPORT
8382 dhd_pkt_filter_enable = FALSE;
8383 #endif /* PKT_FILTER_SUPPORT */
8384 dhd->op_mode = DHD_FLAG_MFG_MODE;
8385 #ifdef USE_DYNAMIC_F2_BLKSIZE
8386 dhdsdio_func_blocksize(dhd, 2, DYNAMIC_F2_BLKSIZE_FOR_NONLEGACY);
8387 #endif /* USE_DYNAMIC_F2_BLKSIZE */
8388 if (FW_SUPPORTED(dhd, rsdb)) {
8390 bcm_mkiovar("rsdb_mode", (char *)&rsdb_mode, 4, iovbuf, sizeof(iovbuf));
8391 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR,
8392 iovbuf, sizeof(iovbuf), TRUE, 0)) < 0) {
8393 DHD_ERROR(("%s Disable rsdb_mode is failed ret= %d\n",
8394 __FUNCTION__, ret));
8398 uint32 concurrent_mode = 0;
8399 if ((!op_mode && dhd_get_fw_mode(dhd->info) == DHD_FLAG_P2P_MODE) ||
8400 (op_mode == DHD_FLAG_P2P_MODE)) {
8401 #if defined(ARP_OFFLOAD_SUPPORT)
8404 #ifdef PKT_FILTER_SUPPORT
8405 dhd_pkt_filter_enable = FALSE;
8407 dhd->op_mode = DHD_FLAG_P2P_MODE;
8408 } else if ((!op_mode && dhd_get_fw_mode(dhd->info) == DHD_FLAG_IBSS_MODE) ||
8409 (op_mode == DHD_FLAG_IBSS_MODE)) {
8410 dhd->op_mode = DHD_FLAG_IBSS_MODE;
8412 dhd->op_mode = DHD_FLAG_STA_MODE;
8413 #if !defined(AP) && defined(WLP2P)
8414 if (dhd->op_mode != DHD_FLAG_IBSS_MODE &&
8415 (concurrent_mode = dhd_get_concurrent_capabilites(dhd))) {
8416 #if defined(ARP_OFFLOAD_SUPPORT)
8419 dhd->op_mode |= concurrent_mode;
8422 /* Check if we are enabling p2p */
8423 if (dhd->op_mode & DHD_FLAG_P2P_MODE) {
8424 bcm_mkiovar("apsta", (char *)&apsta, 4, iovbuf, sizeof(iovbuf));
8425 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR,
8426 iovbuf, sizeof(iovbuf), TRUE, 0)) < 0) {
8427 DHD_ERROR(("%s APSTA for P2P failed ret= %d\n", __FUNCTION__, ret));
8430 #if defined(SOFTAP_AND_GC)
8431 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_AP,
8432 (char *)&ap_mode, sizeof(ap_mode), TRUE, 0)) < 0) {
8433 DHD_ERROR(("%s WLC_SET_AP failed %d\n", __FUNCTION__, ret));
8436 memcpy(&p2p_ea, &dhd->mac, ETHER_ADDR_LEN);
8437 ETHER_SET_LOCALADDR(&p2p_ea);
8438 bcm_mkiovar("p2p_da_override", (char *)&p2p_ea,
8439 ETHER_ADDR_LEN, iovbuf, sizeof(iovbuf));
8440 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR,
8441 iovbuf, sizeof(iovbuf), TRUE, 0)) < 0) {
8442 DHD_ERROR(("%s p2p_da_override ret= %d\n", __FUNCTION__, ret));
8444 DHD_INFO(("dhd_preinit_ioctls: p2p_da_override succeeded\n"));
8448 (void)concurrent_mode;
8452 #ifdef RSDB_MODE_FROM_FILE
8453 (void)dhd_rsdb_mode_from_file(dhd);
8454 #endif /* RSDB_MODE_FROM_FILE */
8456 #ifdef DISABLE_PRUNED_SCAN
8457 if (FW_SUPPORTED(dhd, rsdb)) {
8458 memset(iovbuf, 0, sizeof(iovbuf));
8459 bcm_mkiovar("scan_features", (char *)&scan_features,
8460 4, iovbuf, sizeof(iovbuf));
8461 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_GET_VAR,
8462 iovbuf, sizeof(iovbuf), FALSE, 0)) < 0) {
8463 DHD_ERROR(("%s get scan_features is failed ret=%d\n",
8464 __FUNCTION__, ret));
8466 memcpy(&scan_features, iovbuf, 4);
8467 scan_features &= ~RSDB_SCAN_DOWNGRADED_CH_PRUNE_ROAM;
8468 memset(iovbuf, 0, sizeof(iovbuf));
8469 bcm_mkiovar("scan_features", (char *)&scan_features,
8470 4, iovbuf, sizeof(iovbuf));
8471 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR,
8472 iovbuf, sizeof(iovbuf), TRUE, 0)) < 0) {
8473 DHD_ERROR(("%s set scan_features is failed ret=%d\n",
8474 __FUNCTION__, ret));
8478 #endif /* DISABLE_PRUNED_SCAN */
8480 DHD_ERROR(("Firmware up: op_mode=0x%04x, MAC="MACDBG"\n",
8481 dhd->op_mode, MAC2STRDBG(dhd->mac.octet)));
8482 #if defined(RXFRAME_THREAD) && defined(RXTHREAD_ONLYSTA)
8483 if (dhd->op_mode == DHD_FLAG_HOSTAP_MODE)
8484 dhd->info->rxthread_enabled = FALSE;
8486 dhd->info->rxthread_enabled = TRUE;
8488 /* Set Country code */
8489 if (dhd->dhd_cspec.ccode[0] != 0) {
8490 printf("Set country %s, revision %d\n", dhd->dhd_cspec.ccode, dhd->dhd_cspec.rev);
8491 bcm_mkiovar("country", (char *)&dhd->dhd_cspec,
8492 sizeof(wl_country_t), iovbuf, sizeof(iovbuf));
8493 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0)) < 0)
8494 printf("%s: country code setting failed %d\n", __FUNCTION__, ret);
8496 dhd_conf_set_country(dhd);
8497 dhd_conf_fix_country(dhd);
8499 dhd_conf_get_country(dhd, &dhd->dhd_cspec);
8502 /* Set Listen Interval */
8503 bcm_mkiovar("assoc_listen", (char *)&listen_interval, 4, iovbuf, sizeof(iovbuf));
8504 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0)) < 0)
8505 DHD_ERROR(("%s assoc_listen failed %d\n", __FUNCTION__, ret));
8507 #if defined(ROAM_ENABLE) || defined(DISABLE_BUILTIN_ROAM)
8508 #ifdef USE_WFA_CERT_CONF
8509 if (sec_get_param_wfa_cert(dhd, SET_PARAM_ROAMOFF, &roamvar) == BCME_OK) {
8510 DHD_ERROR(("%s: read roam_off param =%d\n", __FUNCTION__, roamvar));
8512 #endif /* USE_WFA_CERT_CONF */
8513 /* Disable built-in roaming to allowed ext supplicant to take care of roaming */
8514 bcm_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf, sizeof(iovbuf));
8515 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
8516 #endif /* ROAM_ENABLE || DISABLE_BUILTIN_ROAM */
8517 #if defined(ROAM_ENABLE)
8518 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_ROAM_TRIGGER, roam_trigger,
8519 sizeof(roam_trigger), TRUE, 0)) < 0)
8520 DHD_ERROR(("%s: roam trigger set failed %d\n", __FUNCTION__, ret));
8521 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_ROAM_SCAN_PERIOD, roam_scan_period,
8522 sizeof(roam_scan_period), TRUE, 0)) < 0)
8523 DHD_ERROR(("%s: roam scan period set failed %d\n", __FUNCTION__, ret));
8524 if ((dhd_wl_ioctl_cmd(dhd, WLC_SET_ROAM_DELTA, roam_delta,
8525 sizeof(roam_delta), TRUE, 0)) < 0)
8526 DHD_ERROR(("%s: roam delta set failed %d\n", __FUNCTION__, ret));
8527 bcm_mkiovar("fullroamperiod", (char *)&roam_fullscan_period, 4, iovbuf, sizeof(iovbuf));
8528 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0)) < 0)
8529 DHD_ERROR(("%s: roam fullscan period set failed %d\n", __FUNCTION__, ret));
8530 #endif /* ROAM_ENABLE */
8531 dhd_conf_set_roam(dhd);
8533 #ifdef CUSTOM_EVENT_PM_WAKE
8534 bcm_mkiovar("const_awake_thresh", (char *)&pm_awake_thresh, 4, iovbuf, sizeof(iovbuf));
8535 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0)) < 0) {
8536 DHD_ERROR(("%s set const_awake_thresh failed %d\n", __FUNCTION__, ret));
8538 #endif /* CUSTOM_EVENT_PM_WAKE */
8540 #ifdef ENABLE_TDLS_AUTO_MODE
8541 /* by default TDLS on and auto mode on */
8542 _dhd_tdls_enable(dhd, true, true, NULL);
8544 /* by default TDLS on and auto mode off */
8545 _dhd_tdls_enable(dhd, true, false, NULL);
8546 #endif /* ENABLE_TDLS_AUTO_MODE */
8549 #ifdef DHD_ENABLE_LPC
8551 bcm_mkiovar("lpc", (char *)&lpc, 4, iovbuf, sizeof(iovbuf));
8552 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf,
8553 sizeof(iovbuf), TRUE, 0)) < 0) {
8554 DHD_ERROR(("%s Set lpc failed %d\n", __FUNCTION__, ret));
8556 if (ret == BCME_NOTDOWN) {
8558 ret = dhd_wl_ioctl_cmd(dhd, WLC_DOWN,
8559 (char *)&wl_down, sizeof(wl_down), TRUE, 0);
8560 DHD_ERROR(("%s lpc fail WL_DOWN : %d, lpc = %d\n", __FUNCTION__, ret, lpc));
8562 bcm_mkiovar("lpc", (char *)&lpc, 4, iovbuf, sizeof(iovbuf));
8563 ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
8564 DHD_ERROR(("%s Set lpc ret --> %d\n", __FUNCTION__, ret));
8567 #endif /* DHD_ENABLE_LPC */
8568 dhd_conf_set_fw_string_cmd(dhd, "lpc", dhd->conf->lpc, 0, FALSE);
8570 /* Set PowerSave mode */
8571 if (dhd->conf->pm >= 0)
8572 power_mode = dhd->conf->pm;
8573 dhd_wl_ioctl_cmd(dhd, WLC_SET_PM, (char *)&power_mode, sizeof(power_mode), TRUE, 0);
8575 #if defined(BCMSDIO)
8576 /* Match Host and Dongle rx alignment */
8577 bcm_mkiovar("bus:txglomalign", (char *)&dongle_align, 4, iovbuf, sizeof(iovbuf));
8578 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
8580 #if defined(CUSTOMER_HW2) && defined(USE_WL_CREDALL)
8581 /* enable credall to reduce the chance of no bus credit happened. */
8582 bcm_mkiovar("bus:credall", (char *)&credall, 4, iovbuf, sizeof(iovbuf));
8583 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
8586 #ifdef USE_WFA_CERT_CONF
8587 if (sec_get_param_wfa_cert(dhd, SET_PARAM_BUS_TXGLOM_MODE, &glom) == BCME_OK) {
8588 DHD_ERROR(("%s, read txglom param =%d\n", __FUNCTION__, glom));
8590 #endif /* USE_WFA_CERT_CONF */
8591 if (glom != DEFAULT_GLOM_VALUE) {
8592 DHD_INFO(("%s set glom=0x%X\n", __FUNCTION__, glom));
8593 bcm_mkiovar("bus:txglom", (char *)&glom, 4, iovbuf, sizeof(iovbuf));
8594 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
8596 #endif /* defined(BCMSDIO) */
8598 /* Setup timeout if Beacons are lost and roam is off to report link down */
8599 bcm_mkiovar("bcn_timeout", (char *)&bcn_timeout, 4, iovbuf, sizeof(iovbuf));
8600 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
8601 /* Setup assoc_retry_max count to reconnect target AP in dongle */
8602 bcm_mkiovar("assoc_retry_max", (char *)&retry_max, 4, iovbuf, sizeof(iovbuf));
8603 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
8604 #if defined(AP) && !defined(WLP2P)
8605 /* Turn off MPC in AP mode */
8606 bcm_mkiovar("mpc", (char *)&mpc, 4, iovbuf, sizeof(iovbuf));
8607 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
8608 bcm_mkiovar("apsta", (char *)&apsta, 4, iovbuf, sizeof(iovbuf));
8609 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
8610 #endif /* defined(AP) && !defined(WLP2P) */
8611 /* 0:HT20 in ALL, 1:HT40 in ALL, 2: HT20 in 2G HT40 in 5G */
8612 dhd_conf_set_fw_string_cmd(dhd, "mimo_bw_cap", dhd->conf->mimo_bw_cap, 1, TRUE);
8613 dhd_conf_set_fw_string_cmd(dhd, "force_wme_ac", dhd->conf->force_wme_ac, 1, FALSE);
8614 dhd_conf_set_fw_string_cmd(dhd, "stbc_tx", dhd->conf->stbc, 0, FALSE);
8615 dhd_conf_set_fw_string_cmd(dhd, "stbc_rx", dhd->conf->stbc, 0, FALSE);
8616 dhd_conf_set_fw_int_cmd(dhd, "WLC_SET_SRL", WLC_SET_SRL, dhd->conf->srl, 0, TRUE);
8617 dhd_conf_set_fw_int_cmd(dhd, "WLC_SET_LRL", WLC_SET_LRL, dhd->conf->lrl, 0, FALSE);
8618 dhd_conf_set_fw_int_cmd(dhd, "WLC_SET_SPECT_MANAGMENT", WLC_SET_SPECT_MANAGMENT, dhd->conf->spect, 0, FALSE);
8619 dhd_conf_set_fw_string_cmd(dhd, "rsdb_mode", dhd->conf->rsdb_mode, -1, TRUE);
8621 #ifdef MIMO_ANT_SETTING
8622 dhd_sel_ant_from_file(dhd);
8623 #endif /* MIMO_ANT_SETTING */
8626 if (ap_fw_loaded == TRUE) {
8627 dhd_wl_ioctl_cmd(dhd, WLC_SET_DTIMPRD, (char *)&dtim, sizeof(dtim), TRUE, 0);
8631 #if defined(KEEP_ALIVE)
8633 /* Set Keep Alive : be sure to use FW with -keepalive */
8637 if (ap_fw_loaded == FALSE)
8639 if (!(dhd->op_mode &
8640 (DHD_FLAG_HOSTAP_MODE | DHD_FLAG_MFG_MODE))) {
8641 if ((res = dhd_keep_alive_onoff(dhd)) < 0)
8642 DHD_ERROR(("%s set keeplive failed %d\n",
8643 __FUNCTION__, res));
8646 #endif /* defined(KEEP_ALIVE) */
8649 bcm_mkiovar("txbf", (char *)&txbf, 4, iovbuf, sizeof(iovbuf));
8650 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf,
8651 sizeof(iovbuf), TRUE, 0)) < 0) {
8652 DHD_ERROR(("%s Set txbf returned (%d)\n", __FUNCTION__, ret));
8654 #endif /* USE_WL_TXBF */
8655 dhd_conf_set_fw_string_cmd(dhd, "txbf", dhd->conf->txbf, 0, FALSE);
8657 #ifdef USE_WFA_CERT_CONF
8658 #ifdef USE_WL_FRAMEBURST
8659 if (sec_get_param_wfa_cert(dhd, SET_PARAM_FRAMEBURST, &frameburst) == BCME_OK) {
8660 DHD_ERROR(("%s, read frameburst param=%d\n", __FUNCTION__, frameburst));
8662 #endif /* USE_WL_FRAMEBURST */
8663 #ifdef DISABLE_FRAMEBURST_VSDB
8664 g_frameburst = frameburst;
8665 #endif /* DISABLE_FRAMEBURST_VSDB */
8666 #endif /* USE_WFA_CERT_CONF */
8667 #ifdef DISABLE_WL_FRAMEBURST_SOFTAP
8668 /* Disable Framebursting for SofAP */
8669 if (dhd->op_mode & DHD_FLAG_HOSTAP_MODE) {
8672 #endif /* DISABLE_WL_FRAMEBURST_SOFTAP */
8673 /* Set frameburst to value */
8674 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_FAKEFRAG, (char *)&frameburst,
8675 sizeof(frameburst), TRUE, 0)) < 0) {
8676 DHD_INFO(("%s frameburst not supported %d\n", __FUNCTION__, ret));
8678 dhd_conf_set_fw_string_cmd(dhd, "frameburst", dhd->conf->frameburst, 0, FALSE);
8679 #if defined(CUSTOM_AMPDU_BA_WSIZE)
8680 /* Set ampdu ba wsize to 64 or 16 */
8681 #ifdef CUSTOM_AMPDU_BA_WSIZE
8682 ampdu_ba_wsize = CUSTOM_AMPDU_BA_WSIZE;
8684 if (ampdu_ba_wsize != 0) {
8685 bcm_mkiovar("ampdu_ba_wsize", (char *)&du_ba_wsize, 4, iovbuf, sizeof(iovbuf));
8686 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf,
8687 sizeof(iovbuf), TRUE, 0)) < 0) {
8688 DHD_ERROR(("%s Set ampdu_ba_wsize to %d failed %d\n",
8689 __FUNCTION__, ampdu_ba_wsize, ret));
8693 dhd_conf_set_fw_string_cmd(dhd, "ampdu_ba_wsize", dhd->conf->ampdu_ba_wsize, 1, FALSE);
8695 iov_buf = (char*)kmalloc(WLC_IOCTL_SMLEN, GFP_KERNEL);
8696 if (iov_buf == NULL) {
8697 DHD_ERROR(("failed to allocate %d bytes for iov_buf\n", WLC_IOCTL_SMLEN));
8701 #ifdef ENABLE_TEMP_THROTTLING
8702 if (dhd->op_mode & DHD_FLAG_STA_MODE) {
8703 memset(&temp_control, 0, sizeof(temp_control));
8704 temp_control.enable = 1;
8705 temp_control.control_bit = TEMP_THROTTLE_CONTROL_BIT;
8706 bcm_mkiovar("temp_throttle_control", (char *)&temp_control,
8707 sizeof(wl_temp_control_t), iov_buf, WLC_IOCTL_SMLEN);
8708 ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iov_buf, WLC_IOCTL_SMLEN, TRUE, 0);
8710 DHD_ERROR(("%s Set temp_throttle_control to %d failed \n",
8711 __FUNCTION__, ret));
8714 #endif /* ENABLE_TEMP_THROTTLING */
8715 #if defined(CUSTOM_AMPDU_MPDU)
8716 ampdu_mpdu = CUSTOM_AMPDU_MPDU;
8717 if (ampdu_mpdu != 0 && (ampdu_mpdu <= ampdu_ba_wsize)) {
8718 bcm_mkiovar("ampdu_mpdu", (char *)&du_mpdu, 4, iovbuf, sizeof(iovbuf));
8719 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf,
8720 sizeof(iovbuf), TRUE, 0)) < 0) {
8721 DHD_ERROR(("%s Set ampdu_mpdu to %d failed %d\n",
8722 __FUNCTION__, CUSTOM_AMPDU_MPDU, ret));
8725 #endif /* CUSTOM_AMPDU_MPDU */
8727 #if defined(CUSTOM_AMPDU_RELEASE)
8728 ampdu_release = CUSTOM_AMPDU_RELEASE;
8729 if (ampdu_release != 0 && (ampdu_release <= ampdu_ba_wsize)) {
8730 bcm_mkiovar("ampdu_release", (char *)&du_release, 4, iovbuf, sizeof(iovbuf));
8731 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf,
8732 sizeof(iovbuf), TRUE, 0)) < 0) {
8733 DHD_ERROR(("%s Set ampdu_release to %d failed %d\n",
8734 __FUNCTION__, CUSTOM_AMPDU_RELEASE, ret));
8737 #endif /* CUSTOM_AMPDU_RELEASE */
8739 #if defined(CUSTOM_AMSDU_AGGSF)
8740 amsdu_aggsf = CUSTOM_AMSDU_AGGSF;
8741 if (amsdu_aggsf != 0) {
8742 bcm_mkiovar("amsdu_aggsf", (char *)&amsdu_aggsf, 4, iovbuf, sizeof(iovbuf));
8743 ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
8745 DHD_ERROR(("%s Set amsdu_aggsf to %d failed %d\n",
8746 __FUNCTION__, CUSTOM_AMSDU_AGGSF, ret));
8749 #endif /* CUSTOM_AMSDU_AGGSF */
8751 #ifdef CUSTOM_PSPRETEND_THR
8752 /* Turn off MPC in AP mode */
8753 bcm_mkiovar("pspretend_threshold", (char *)&pspretend_thr, 4,
8754 iovbuf, sizeof(iovbuf));
8755 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf,
8756 sizeof(iovbuf), TRUE, 0)) < 0) {
8757 DHD_ERROR(("%s pspretend_threshold for HostAPD failed %d\n",
8758 __FUNCTION__, ret));
8762 bcm_mkiovar("buf_key_b4_m4", (char *)&buf_key_b4_m4, 4, iovbuf, sizeof(iovbuf));
8763 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf,
8764 sizeof(iovbuf), TRUE, 0)) < 0) {
8765 DHD_ERROR(("%s buf_key_b4_m4 set failed %d\n", __FUNCTION__, ret));
8768 /* Read event_msgs mask */
8769 bcm_mkiovar("event_msgs", eventmask, WL_EVENTING_MASK_LEN, iovbuf, sizeof(iovbuf));
8770 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_GET_VAR, iovbuf, sizeof(iovbuf), FALSE, 0)) < 0) {
8771 DHD_ERROR(("%s read Event mask failed %d\n", __FUNCTION__, ret));
8774 bcopy(iovbuf, eventmask, WL_EVENTING_MASK_LEN);
8776 /* Setup event_msgs */
8777 setbit(eventmask, WLC_E_SET_SSID);
8778 setbit(eventmask, WLC_E_PRUNE);
8779 setbit(eventmask, WLC_E_AUTH);
8780 setbit(eventmask, WLC_E_AUTH_IND);
8781 setbit(eventmask, WLC_E_ASSOC);
8782 setbit(eventmask, WLC_E_REASSOC);
8783 setbit(eventmask, WLC_E_REASSOC_IND);
8784 if (!(dhd->op_mode & DHD_FLAG_IBSS_MODE))
8785 setbit(eventmask, WLC_E_DEAUTH);
8786 setbit(eventmask, WLC_E_DEAUTH_IND);
8787 setbit(eventmask, WLC_E_DISASSOC_IND);
8788 setbit(eventmask, WLC_E_DISASSOC);
8789 setbit(eventmask, WLC_E_JOIN);
8790 setbit(eventmask, WLC_E_START);
8791 setbit(eventmask, WLC_E_ASSOC_IND);
8792 setbit(eventmask, WLC_E_PSK_SUP);
8793 setbit(eventmask, WLC_E_LINK);
8794 setbit(eventmask, WLC_E_MIC_ERROR);
8795 setbit(eventmask, WLC_E_ASSOC_REQ_IE);
8796 setbit(eventmask, WLC_E_ASSOC_RESP_IE);
8798 setbit(eventmask, WLC_E_PMKID_CACHE);
8799 setbit(eventmask, WLC_E_TXFAIL);
8801 setbit(eventmask, WLC_E_JOIN_START);
8802 // setbit(eventmask, WLC_E_SCAN_COMPLETE); // terence 20150628: remove redundant event
8804 setbit(eventmask, WLC_E_SCAN_CONFIRM_IND);
8807 setbit(eventmask, WLC_E_HTSFSYNC);
8808 #endif /* WLMEDIA_HTSF */
8810 setbit(eventmask, WLC_E_PFN_NET_FOUND);
8811 setbit(eventmask, WLC_E_PFN_BEST_BATCHING);
8812 setbit(eventmask, WLC_E_PFN_BSSID_NET_FOUND);
8813 setbit(eventmask, WLC_E_PFN_BSSID_NET_LOST);
8814 #endif /* PNO_SUPPORT */
8815 /* enable dongle roaming event */
8816 setbit(eventmask, WLC_E_ROAM);
8817 setbit(eventmask, WLC_E_BSSID);
8819 setbit(eventmask, WLC_E_TDLS_PEER_EVENT);
8822 setbit(eventmask, WLC_E_ESCAN_RESULT);
8825 setbit(eventmask, WLC_E_ESCAN_RESULT);
8826 setbit(eventmask, WLC_E_AP_STARTED);
8827 if (dhd->op_mode & DHD_FLAG_P2P_MODE) {
8828 setbit(eventmask, WLC_E_ACTION_FRAME_RX);
8829 setbit(eventmask, WLC_E_P2P_DISC_LISTEN_COMPLETE);
8831 #endif /* WL_CFG80211 */
8833 #if defined(SHOW_LOGTRACE) && defined(LOGTRACE_FROM_FILE)
8834 if (dhd_logtrace_from_file(dhd)) {
8835 setbit(eventmask, WLC_E_TRACE);
8837 clrbit(eventmask, WLC_E_TRACE);
8839 #elif defined(SHOW_LOGTRACE)
8840 setbit(eventmask, WLC_E_TRACE);
8842 clrbit(eventmask, WLC_E_TRACE);
8843 #endif /* defined(SHOW_LOGTRACE) && defined(LOGTRACE_FROM_FILE) */
8845 setbit(eventmask, WLC_E_CSA_COMPLETE_IND);
8846 #ifdef DHD_LOSSLESS_ROAMING
8847 setbit(eventmask, WLC_E_ROAM_PREP);
8849 #ifdef CUSTOM_EVENT_PM_WAKE
8850 setbit(eventmask, WLC_E_EXCESS_PM_WAKE_EVENT);
8851 #endif /* CUSTOM_EVENT_PM_WAKE */
8852 #if defined(PCIE_FULL_DONGLE) && defined(DHD_LOSSLESS_ROAMING)
8853 dhd_update_flow_prio_map(dhd, DHD_FLOW_PRIO_LLR_MAP);
8854 #endif /* defined(PCIE_FULL_DONGLE) && defined(DHD_LOSSLESS_ROAMING) */
8856 /* Write updated Event mask */
8857 bcm_mkiovar("event_msgs", eventmask, WL_EVENTING_MASK_LEN, iovbuf, sizeof(iovbuf));
8858 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0)) < 0) {
8859 DHD_ERROR(("%s Set Event mask failed %d\n", __FUNCTION__, ret));
8863 /* make up event mask ext message iovar for event larger than 128 */
8864 msglen = ROUNDUP(WLC_E_LAST, NBBY)/NBBY + EVENTMSGS_EXT_STRUCT_SIZE;
8865 eventmask_msg = (eventmsgs_ext_t*)kmalloc(msglen, GFP_KERNEL);
8866 if (eventmask_msg == NULL) {
8867 DHD_ERROR(("failed to allocate %d bytes for event_msg_ext\n", msglen));
8871 bzero(eventmask_msg, msglen);
8872 eventmask_msg->ver = EVENTMSGS_VER;
8873 eventmask_msg->len = ROUNDUP(WLC_E_LAST, NBBY)/NBBY;
8875 /* Read event_msgs_ext mask */
8876 bcm_mkiovar("event_msgs_ext", (char *)eventmask_msg, msglen, iov_buf, WLC_IOCTL_SMLEN);
8877 ret2 = dhd_wl_ioctl_cmd(dhd, WLC_GET_VAR, iov_buf, WLC_IOCTL_SMLEN, FALSE, 0);
8878 if (ret2 == 0) { /* event_msgs_ext must be supported */
8879 bcopy(iov_buf, eventmask_msg, msglen);
8880 #ifdef GSCAN_SUPPORT
8881 setbit(eventmask_msg->mask, WLC_E_PFN_GSCAN_FULL_RESULT);
8882 setbit(eventmask_msg->mask, WLC_E_PFN_SCAN_COMPLETE);
8883 setbit(eventmask_msg->mask, WLC_E_PFN_SWC);
8884 #endif /* GSCAN_SUPPORT */
8885 #ifdef BT_WIFI_HANDOVER
8886 setbit(eventmask_msg->mask, WLC_E_BT_WIFI_HANDOVER_REQ);
8887 #endif /* BT_WIFI_HANDOVER */
8889 /* Write updated Event mask */
8890 eventmask_msg->ver = EVENTMSGS_VER;
8891 eventmask_msg->command = EVENTMSGS_SET_MASK;
8892 eventmask_msg->len = ROUNDUP(WLC_E_LAST, NBBY)/NBBY;
8893 bcm_mkiovar("event_msgs_ext", (char *)eventmask_msg,
8894 msglen, iov_buf, WLC_IOCTL_SMLEN);
8895 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR,
8896 iov_buf, WLC_IOCTL_SMLEN, TRUE, 0)) < 0) {
8897 DHD_ERROR(("%s write event mask ext failed %d\n", __FUNCTION__, ret));
8900 } else if (ret2 == BCME_UNSUPPORTED || ret2 == BCME_VERSION) {
8901 /* Skip for BCME_UNSUPPORTED or BCME_VERSION */
8902 DHD_ERROR(("%s event_msgs_ext not support or version mismatch %d\n",
8903 __FUNCTION__, ret2));
8905 DHD_ERROR(("%s read event mask ext failed %d\n", __FUNCTION__, ret2));
8910 dhd_wl_ioctl_cmd(dhd, WLC_SET_SCAN_CHANNEL_TIME, (char *)&scan_assoc_time,
8911 sizeof(scan_assoc_time), TRUE, 0);
8912 dhd_wl_ioctl_cmd(dhd, WLC_SET_SCAN_UNASSOC_TIME, (char *)&scan_unassoc_time,
8913 sizeof(scan_unassoc_time), TRUE, 0);
8914 dhd_wl_ioctl_cmd(dhd, WLC_SET_SCAN_PASSIVE_TIME, (char *)&scan_passive_time,
8915 sizeof(scan_passive_time), TRUE, 0);
8917 #ifdef ARP_OFFLOAD_SUPPORT
8918 /* Set and enable ARP offload feature for STA only */
8920 if (arpoe && !ap_fw_loaded)
8925 dhd_arp_offload_enable(dhd, TRUE);
8926 dhd_arp_offload_set(dhd, dhd_arp_mode);
8928 dhd_arp_offload_enable(dhd, FALSE);
8929 dhd_arp_offload_set(dhd, 0);
8931 dhd_arp_enable = arpoe;
8932 #endif /* ARP_OFFLOAD_SUPPORT */
8934 #ifdef PKT_FILTER_SUPPORT
8935 /* Setup default defintions for pktfilter , enable in suspend */
8936 if (dhd_master_mode) {
8937 dhd->pktfilter_count = 6;
8938 dhd->pktfilter[DHD_BROADCAST_FILTER_NUM] = NULL;
8939 dhd->pktfilter[DHD_MULTICAST4_FILTER_NUM] = NULL;
8940 dhd->pktfilter[DHD_MULTICAST6_FILTER_NUM] = NULL;
8941 /* apply APP pktfilter */
8942 dhd->pktfilter[DHD_ARP_FILTER_NUM] = "105 0 0 12 0xFFFF 0x0806";
8944 /* Setup filter to allow only unicast */
8945 dhd->pktfilter[DHD_UNICAST_FILTER_NUM] = "100 0 0 0 0x01 0x00";
8947 /* Add filter to pass multicastDNS packet and NOT filter out as Broadcast */
8948 dhd->pktfilter[DHD_MDNS_FILTER_NUM] = NULL;
8950 #ifdef GAN_LITE_NAT_KEEPALIVE_FILTER
8951 dhd->pktfilter_count = 4;
8952 /* Setup filter to block broadcast and NAT Keepalive packets */
8953 /* discard all broadcast packets */
8954 dhd->pktfilter[DHD_UNICAST_FILTER_NUM] = "100 0 0 0 0xffffff 0xffffff";
8955 /* discard NAT Keepalive packets */
8956 dhd->pktfilter[DHD_BROADCAST_FILTER_NUM] = "102 0 0 36 0xffffffff 0x11940009";
8957 /* discard NAT Keepalive packets */
8958 dhd->pktfilter[DHD_MULTICAST4_FILTER_NUM] = "104 0 0 38 0xffffffff 0x11940009";
8959 dhd->pktfilter[DHD_MULTICAST6_FILTER_NUM] = NULL;
8960 #endif /* GAN_LITE_NAT_KEEPALIVE_FILTER */
8962 dhd_conf_discard_pkt_filter(dhd);
8963 dhd_conf_add_pkt_filter(dhd);
8967 dhd_enable_packet_filter(0, dhd);
8969 #endif /* defined(SOFTAP) */
8970 dhd_set_packet_filter(dhd);
8971 #endif /* PKT_FILTER_SUPPORT */
8973 bcm_mkiovar("nmode", (char *)&nmode, 4, iovbuf, sizeof(iovbuf));
8974 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0)) < 0)
8975 DHD_ERROR(("%s wl nmode 0 failed %d\n", __FUNCTION__, ret));
8976 #endif /* DISABLE_11N */
8978 #ifdef ENABLE_BCN_LI_BCN_WAKEUP
8979 bcm_mkiovar("bcn_li_bcn", (char *)&bcn_li_bcn, 4, iovbuf, sizeof(iovbuf));
8980 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
8981 #endif /* ENABLE_BCN_LI_BCN_WAKEUP */
8982 /* query for 'ver' to get version info from firmware */
8983 memset(buf, 0, sizeof(buf));
8985 bcm_mkiovar("ver", (char *)&buf, 4, buf, sizeof(buf));
8986 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_GET_VAR, buf, sizeof(buf), FALSE, 0)) < 0)
8987 DHD_ERROR(("%s failed %d\n", __FUNCTION__, ret));
8989 bcmstrtok(&ptr, "\n", 0);
8990 /* Print fw version info */
8991 DHD_ERROR(("Firmware version = %s\n", buf));
8992 strncpy(fw_version, buf, FW_VER_STR_LEN);
8993 dhd_set_version_info(dhd, buf);
8994 #ifdef WRITE_WLANINFO
8995 sec_save_wlinfo(buf, EPI_VERSION_STR, dhd->info->nv_path);
8996 #endif /* WRITE_WLANINFO */
8999 #if defined(BCMSDIO)
9000 dhd_txglom_enable(dhd, dhd->conf->bus_rxglom);
9001 // terence 20151210: set bus:txglom after dhd_txglom_enable since it's possible changed in dhd_conf_set_txglom_params
9002 dhd_conf_set_fw_string_cmd(dhd, "bus:txglom", dhd->conf->bus_txglom, 1, FALSE);
9003 #endif /* defined(BCMSDIO) */
9005 dhd_conf_set_disable_proptx(dhd);
9006 #if defined(BCMSDIO)
9007 #ifdef PROP_TXSTATUS
9008 if (disable_proptx ||
9009 #ifdef PROP_TXSTATUS_VSDB
9010 /* enable WLFC only if the firmware is VSDB when it is in STA mode */
9011 (dhd->op_mode != DHD_FLAG_HOSTAP_MODE &&
9012 dhd->op_mode != DHD_FLAG_IBSS_MODE) ||
9013 #endif /* PROP_TXSTATUS_VSDB */
9015 wlfc_enable = FALSE;
9018 #ifdef USE_WFA_CERT_CONF
9019 if (sec_get_param_wfa_cert(dhd, SET_PARAM_PROPTX, &proptx) == BCME_OK) {
9020 DHD_ERROR(("%s , read proptx param=%d\n", __FUNCTION__, proptx));
9021 wlfc_enable = proptx;
9023 #endif /* USE_WFA_CERT_CONF */
9026 ret = dhd_wl_ioctl_cmd(dhd, WLC_DOWN, (char *)&wl_down, sizeof(wl_down), TRUE, 0);
9027 bcm_mkiovar("ampdu_hostreorder", (char *)&hostreorder, 4, iovbuf, sizeof(iovbuf));
9028 if ((ret2 = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0)) < 0) {
9029 DHD_ERROR(("%s wl ampdu_hostreorder failed %d\n", __FUNCTION__, ret2));
9030 if (ret2 != BCME_UNSUPPORTED)
9033 if (ret == BCME_NOTDOWN) {
9035 ret2 = dhd_wl_ioctl_cmd(dhd, WLC_DOWN, (char *)&wl_down,
9036 sizeof(wl_down), TRUE, 0);
9037 DHD_ERROR(("%s ampdu_hostreorder fail WL_DOWN : %d, hostreorder :%d\n",
9038 __FUNCTION__, ret2, hostreorder));
9040 bcm_mkiovar("ampdu_hostreorder", (char *)&hostreorder, 4,
9041 iovbuf, sizeof(iovbuf));
9042 ret2 = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
9043 DHD_ERROR(("%s wl ampdu_hostreorder. ret --> %d\n", __FUNCTION__, ret2));
9044 if (ret2 != BCME_UNSUPPORTED)
9047 if (ret2 != BCME_OK)
9050 #endif /* DISABLE_11N */
9056 else if (hostreorder)
9057 dhd_wlfc_hostreorder_init(dhd);
9058 #endif /* DISABLE_11N */
9060 #endif /* PROP_TXSTATUS */
9061 #endif /* BCMSDIO || BCMBUS */
9062 #ifdef PCIE_FULL_DONGLE
9063 /* For FD we need all the packets at DHD to handle intra-BSS forwarding */
9064 if (FW_SUPPORTED(dhd, ap)) {
9065 wl_ap_isolate = AP_ISOLATE_SENDUP_ALL;
9066 bcm_mkiovar("ap_isolate", (char *)&wl_ap_isolate, 4, iovbuf, sizeof(iovbuf));
9067 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0)) < 0)
9068 DHD_ERROR(("%s failed %d\n", __FUNCTION__, ret));
9070 #endif /* PCIE_FULL_DONGLE */
9072 if (!dhd->pno_state) {
9077 dhd_interworking_enable(dhd);
9080 dhd_wl_ioctl_cmd(dhd, WLC_UP, (char *)&up, sizeof(up), TRUE, 0);
9083 #ifdef SUPPORT_SENSORHUB
9084 bcm_mkiovar("shub", (char *)&shub_enable, 4, iovbuf, sizeof(iovbuf));
9085 if ((dhd_wl_ioctl_cmd(dhd, WLC_GET_VAR, iovbuf, sizeof(iovbuf),
9087 DHD_ERROR(("%s failed to get shub hub enable information %d\n",
9088 __FUNCTION__, ret));
9089 dhd->info->shub_enable = 0;
9091 memcpy(&shub_enable, iovbuf, sizeof(uint32));
9092 dhd->info->shub_enable = shub_enable;
9093 DHD_ERROR(("%s: checking sensorhub enable %d\n",
9094 __FUNCTION__, dhd->info->shub_enable));
9096 #endif /* SUPPORT_SENSORHUB */
9100 kfree(eventmask_msg);
9109 dhd_iovar(dhd_pub_t *pub, int ifidx, char *name, char *cmd_buf, uint cmd_len, int set)
9111 char buf[strlen(name) + 1 + cmd_len];
9112 int len = sizeof(buf);
9116 len = bcm_mkiovar(name, cmd_buf, cmd_len, buf, len);
9118 memset(&ioc, 0, sizeof(ioc));
9120 ioc.cmd = set? WLC_SET_VAR : WLC_GET_VAR;
9125 ret = dhd_wl_ioctl(pub, ifidx, &ioc, ioc.buf, ioc.len);
9126 if (!set && ret >= 0)
9127 memcpy(cmd_buf, buf, cmd_len);
9132 int dhd_change_mtu(dhd_pub_t *dhdp, int new_mtu, int ifidx)
9134 struct dhd_info *dhd = dhdp->info;
9135 struct net_device *dev = NULL;
9137 ASSERT(dhd && dhd->iflist[ifidx]);
9138 dev = dhd->iflist[ifidx]->net;
9141 if (netif_running(dev)) {
9142 DHD_ERROR(("%s: Must be down to change its MTU\n", dev->name));
9143 return BCME_NOTDOWN;
9146 #define DHD_MIN_MTU 1500
9147 #define DHD_MAX_MTU 1752
9149 if ((new_mtu < DHD_MIN_MTU) || (new_mtu > DHD_MAX_MTU)) {
9150 DHD_ERROR(("%s: MTU size %d is invalid.\n", __FUNCTION__, new_mtu));
9158 #ifdef ARP_OFFLOAD_SUPPORT
9159 /* add or remove AOE host ip(s) (up to 8 IPs on the interface) */
9161 aoe_update_host_ipv4_table(dhd_pub_t *dhd_pub, u32 ipa, bool add, int idx)
9163 u32 ipv4_buf[MAX_IPV4_ENTRIES]; /* temp save for AOE host_ip table */
9167 bzero(ipv4_buf, sizeof(ipv4_buf));
9169 /* display what we've got */
9170 ret = dhd_arp_get_arp_hostip_table(dhd_pub, ipv4_buf, sizeof(ipv4_buf), idx);
9171 DHD_ARPOE(("%s: hostip table read from Dongle:\n", __FUNCTION__));
9173 dhd_print_buf(ipv4_buf, 32, 4); /* max 8 IPs 4b each */
9175 /* now we saved hoste_ip table, clr it in the dongle AOE */
9176 dhd_aoe_hostip_clr(dhd_pub, idx);
9179 DHD_ERROR(("%s failed\n", __FUNCTION__));
9183 for (i = 0; i < MAX_IPV4_ENTRIES; i++) {
9184 if (add && (ipv4_buf[i] == 0)) {
9186 add = FALSE; /* added ipa to local table */
9187 DHD_ARPOE(("%s: Saved new IP in temp arp_hostip[%d]\n",
9189 } else if (ipv4_buf[i] == ipa) {
9191 DHD_ARPOE(("%s: removed IP:%x from temp table %d\n",
9192 __FUNCTION__, ipa, i));
9195 if (ipv4_buf[i] != 0) {
9196 /* add back host_ip entries from our local cache */
9197 dhd_arp_offload_add_ip(dhd_pub, ipv4_buf[i], idx);
9198 DHD_ARPOE(("%s: added IP:%x to dongle arp_hostip[%d]\n\n",
9199 __FUNCTION__, ipv4_buf[i], i));
9203 /* see the resulting hostip table */
9204 dhd_arp_get_arp_hostip_table(dhd_pub, ipv4_buf, sizeof(ipv4_buf), idx);
9205 DHD_ARPOE(("%s: read back arp_hostip table:\n", __FUNCTION__));
9206 dhd_print_buf(ipv4_buf, 32, 4); /* max 8 IPs 4b each */
9211 * Notification mechanism from kernel to our driver. This function is called by the Linux kernel
9212 * whenever there is an event related to an IP address.
9213 * ptr : kernel provided pointer to IP address that has changed
9215 static int dhd_inetaddr_notifier_call(struct notifier_block *this,
9216 unsigned long event,
9219 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
9225 if (!dhd_arp_enable)
9227 if (!ifa || !(ifa->ifa_dev->dev))
9230 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
9231 /* Filter notifications meant for non Broadcom devices */
9232 if ((ifa->ifa_dev->dev->netdev_ops != &dhd_ops_pri) &&
9233 (ifa->ifa_dev->dev->netdev_ops != &dhd_ops_virt)) {
9234 #if defined(WL_ENABLE_P2P_IF)
9235 if (!wl_cfgp2p_is_ifops(ifa->ifa_dev->dev->netdev_ops))
9236 #endif /* WL_ENABLE_P2P_IF */
9239 #endif /* LINUX_VERSION_CODE */
9241 dhd = DHD_DEV_INFO(ifa->ifa_dev->dev);
9245 dhd_pub = &dhd->pub;
9247 if (dhd_pub->arp_version == 1) {
9250 for (idx = 0; idx < DHD_MAX_IFS; idx++) {
9251 if (dhd->iflist[idx] && dhd->iflist[idx]->net == ifa->ifa_dev->dev)
9254 if (idx < DHD_MAX_IFS) {
9255 DHD_TRACE(("ifidx : %p %s %d\n", dhd->iflist[idx]->net,
9256 dhd->iflist[idx]->name, dhd->iflist[idx]->idx));
9258 DHD_ERROR(("Cannot find ifidx for(%s) set to 0\n", ifa->ifa_label));
9265 DHD_ARPOE(("%s: [%s] Up IP: 0x%x\n",
9266 __FUNCTION__, ifa->ifa_label, ifa->ifa_address));
9268 if (dhd->pub.busstate != DHD_BUS_DATA) {
9269 DHD_ERROR(("%s: bus not ready, exit\n", __FUNCTION__));
9270 if (dhd->pend_ipaddr) {
9271 DHD_ERROR(("%s: overwrite pending ipaddr: 0x%x\n",
9272 __FUNCTION__, dhd->pend_ipaddr));
9274 dhd->pend_ipaddr = ifa->ifa_address;
9278 #ifdef AOE_IP_ALIAS_SUPPORT
9279 DHD_ARPOE(("%s:add aliased IP to AOE hostip cache\n",
9281 aoe_update_host_ipv4_table(dhd_pub, ifa->ifa_address, TRUE, idx);
9282 #endif /* AOE_IP_ALIAS_SUPPORT */
9286 DHD_ARPOE(("%s: [%s] Down IP: 0x%x\n",
9287 __FUNCTION__, ifa->ifa_label, ifa->ifa_address));
9288 dhd->pend_ipaddr = 0;
9289 #ifdef AOE_IP_ALIAS_SUPPORT
9290 DHD_ARPOE(("%s:interface is down, AOE clr all for this if\n",
9292 aoe_update_host_ipv4_table(dhd_pub, ifa->ifa_address, FALSE, idx);
9294 dhd_aoe_hostip_clr(&dhd->pub, idx);
9295 dhd_aoe_arp_clr(&dhd->pub, idx);
9296 #endif /* AOE_IP_ALIAS_SUPPORT */
9300 DHD_ARPOE(("%s: do noting for [%s] Event: %lu\n",
9301 __func__, ifa->ifa_label, event));
9306 #endif /* ARP_OFFLOAD_SUPPORT */
9308 #if defined(CONFIG_IPV6) && defined(IPV6_NDO_SUPPORT)
9309 /* Neighbor Discovery Offload: defered handler */
9311 dhd_inet6_work_handler(void *dhd_info, void *event_data, u8 event)
9313 struct ipv6_work_info_t *ndo_work = (struct ipv6_work_info_t *)event_data;
9314 dhd_pub_t *pub = &((dhd_info_t *)dhd_info)->pub;
9317 if (event != DHD_WQ_WORK_IPV6_NDO) {
9318 DHD_ERROR(("%s: unexpected event \n", __FUNCTION__));
9323 DHD_ERROR(("%s: ipv6 work info is not initialized \n", __FUNCTION__));
9328 DHD_ERROR(("%s: dhd pub is not initialized \n", __FUNCTION__));
9332 if (ndo_work->if_idx) {
9333 DHD_ERROR(("%s: idx %d \n", __FUNCTION__, ndo_work->if_idx));
9337 switch (ndo_work->event) {
9339 DHD_TRACE(("%s: Enable NDO and add ipv6 into table \n ", __FUNCTION__));
9340 ret = dhd_ndo_enable(pub, TRUE);
9342 DHD_ERROR(("%s: Enabling NDO Failed %d\n", __FUNCTION__, ret));
9345 ret = dhd_ndo_add_ip(pub, &ndo_work->ipv6_addr[0], ndo_work->if_idx);
9347 DHD_ERROR(("%s: Adding host ip for NDO failed %d\n",
9348 __FUNCTION__, ret));
9352 DHD_TRACE(("%s: clear ipv6 table \n", __FUNCTION__));
9353 ret = dhd_ndo_remove_ip(pub, ndo_work->if_idx);
9355 DHD_ERROR(("%s: Removing host ip for NDO failed %d\n",
9356 __FUNCTION__, ret));
9360 ret = dhd_ndo_enable(pub, FALSE);
9362 DHD_ERROR(("%s: disabling NDO Failed %d\n", __FUNCTION__, ret));
9367 DHD_ERROR(("%s: unknown notifier event \n", __FUNCTION__));
9371 /* free ndo_work. alloced while scheduling the work */
9378 * Neighbor Discovery Offload: Called when an interface
9379 * is assigned with ipv6 address.
9380 * Handles only primary interface
9382 static int dhd_inet6addr_notifier_call(struct notifier_block *this,
9383 unsigned long event,
9388 struct inet6_ifaddr *inet6_ifa = ptr;
9389 struct in6_addr *ipv6_addr = &inet6_ifa->addr;
9390 struct ipv6_work_info_t *ndo_info;
9391 int idx = 0; /* REVISIT */
9393 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
9394 /* Filter notifications meant for non Broadcom devices */
9395 if (inet6_ifa->idev->dev->netdev_ops != &dhd_ops_pri) {
9398 #endif /* LINUX_VERSION_CODE */
9400 dhd = DHD_DEV_INFO(inet6_ifa->idev->dev);
9404 if (dhd->iflist[idx] && dhd->iflist[idx]->net != inet6_ifa->idev->dev)
9406 dhd_pub = &dhd->pub;
9408 if (!FW_SUPPORTED(dhd_pub, ndoe))
9411 ndo_info = (struct ipv6_work_info_t *)kzalloc(sizeof(struct ipv6_work_info_t), GFP_ATOMIC);
9413 DHD_ERROR(("%s: ipv6 work alloc failed\n", __FUNCTION__));
9417 ndo_info->event = event;
9418 ndo_info->if_idx = idx;
9419 memcpy(&ndo_info->ipv6_addr[0], ipv6_addr, IPV6_ADDR_LEN);
9421 /* defer the work to thread as it may block kernel */
9422 dhd_deferred_schedule_work(dhd->dhd_deferred_wq, (void *)ndo_info, DHD_WQ_WORK_IPV6_NDO,
9423 dhd_inet6_work_handler, DHD_WORK_PRIORITY_LOW);
9426 #endif /* CONFIG_IPV6 && IPV6_NDO_SUPPORT */
9429 dhd_register_if(dhd_pub_t *dhdp, int ifidx, bool need_rtnl_lock)
9431 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
9433 struct net_device *net = NULL;
9435 uint8 temp_addr[ETHER_ADDR_LEN] = { 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33 };
9437 DHD_TRACE(("%s: ifidx %d\n", __FUNCTION__, ifidx));
9439 ASSERT(dhd && dhd->iflist[ifidx]);
9440 ifp = dhd->iflist[ifidx];
9442 ASSERT(net && (ifp->idx == ifidx));
9444 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31))
9446 net->get_stats = dhd_get_stats;
9447 net->do_ioctl = dhd_ioctl_entry;
9448 net->hard_start_xmit = dhd_start_xmit;
9449 net->set_mac_address = dhd_set_mac_address;
9450 net->set_multicast_list = dhd_set_multicast_list;
9451 net->open = net->stop = NULL;
9453 ASSERT(!net->netdev_ops);
9454 net->netdev_ops = &dhd_ops_virt;
9455 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31) */
9457 /* Ok, link into the network layer... */
9460 * device functions for the primary interface only
9462 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31))
9463 net->open = dhd_open;
9464 net->stop = dhd_stop;
9466 net->netdev_ops = &dhd_ops_pri;
9467 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31) */
9468 if (!ETHER_ISNULLADDR(dhd->pub.mac.octet))
9469 memcpy(temp_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
9472 * We have to use the primary MAC for virtual interfaces
9474 memcpy(temp_addr, ifp->mac_addr, ETHER_ADDR_LEN);
9476 * Android sets the locally administered bit to indicate that this is a
9477 * portable hotspot. This will not work in simultaneous AP/STA mode,
9478 * nor with P2P. Need to set the Donlge's MAC address, and then use that.
9480 if (!memcmp(temp_addr, dhd->iflist[0]->mac_addr,
9482 DHD_ERROR(("%s interface [%s]: set locally administered bit in MAC\n",
9483 __func__, net->name));
9484 temp_addr[0] |= 0x02;
9488 net->hard_header_len = ETH_HLEN + dhd->pub.hdrlen;
9489 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
9490 net->ethtool_ops = &dhd_ethtool_ops;
9491 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) */
9493 #if defined(WL_WIRELESS_EXT)
9494 #if WIRELESS_EXT < 19
9495 net->get_wireless_stats = dhd_get_wireless_stats;
9496 #endif /* WIRELESS_EXT < 19 */
9497 #if WIRELESS_EXT > 12
9498 net->wireless_handlers = (struct iw_handler_def *)&wl_iw_handler_def;
9499 #endif /* WIRELESS_EXT > 12 */
9500 #endif /* defined(WL_WIRELESS_EXT) */
9502 dhd->pub.rxsz = DBUS_RX_BUFFER_SIZE_DHD(net);
9504 memcpy(net->dev_addr, temp_addr, ETHER_ADDR_LEN);
9507 printf("%s\n", dhd_version);
9510 err = register_netdev(net);
9512 err = register_netdevice(net);
9515 DHD_ERROR(("couldn't register the net device [%s], err %d\n", net->name, err));
9521 printf("Register interface [%s] MAC: "MACDBG"\n\n", net->name,
9522 #if defined(CUSTOMER_HW4_DEBUG)
9523 MAC2STRDBG(dhd->pub.mac.octet));
9525 MAC2STRDBG(net->dev_addr));
9526 #endif /* CUSTOMER_HW4_DEBUG */
9528 #if defined(SOFTAP) && defined(WL_WIRELESS_EXT) && !defined(WL_CFG80211)
9529 // wl_iw_iscan_set_scan_broadcast_prep(net, 1);
9532 #if (defined(BCMPCIE) || (defined(BCMLXSDMMC) && (LINUX_VERSION_CODE >= \
9533 KERNEL_VERSION(2, 6, 27))))
9536 up(&dhd_registration_sem);
9537 #endif /* BCMLXSDMMC */
9538 if (!dhd_download_fw_on_driverload) {
9540 wl_terminate_event_handler();
9541 #endif /* WL_CFG80211 */
9542 #if defined(DHD_LB) && defined(DHD_LB_RXP)
9543 __skb_queue_purge(&dhd->rx_pend_queue);
9544 #endif /* DHD_LB && DHD_LB_RXP */
9545 #if defined(BCMPCIE) && defined(DHDTCPACK_SUPPRESS)
9546 dhd_tcpack_suppress_set(dhdp, TCPACK_SUP_OFF);
9547 #endif /* BCMPCIE && DHDTCPACK_SUPPRESS */
9548 dhd_net_bus_devreset(net, TRUE);
9550 dhd_net_bus_suspend(net);
9551 #endif /* BCMLXSDMMC */
9552 wifi_platform_set_power(dhdp->info->adapter, FALSE, WIFI_TURNOFF_DELAY);
9555 #endif /* OEM_ANDROID && (BCMPCIE || (BCMLXSDMMC && KERNEL_VERSION >= 2.6.27)) */
9559 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31)
9562 net->netdev_ops = NULL;
9568 dhd_bus_detach(dhd_pub_t *dhdp)
9572 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
9575 dhd = (dhd_info_t *)dhdp->info;
9579 * In case of Android cfg80211 driver, the bus is down in dhd_stop,
9580 * calling stop again will cuase SD read/write errors.
9582 if (dhd->pub.busstate != DHD_BUS_DOWN) {
9583 /* Stop the protocol module */
9584 dhd_prot_stop(&dhd->pub);
9586 /* Stop the bus module */
9587 dhd_bus_stop(dhd->pub.bus, TRUE);
9590 #if defined(OOB_INTR_ONLY) || defined(BCMPCIE_OOB_HOST_WAKE)
9591 dhd_bus_oob_intr_unregister(dhdp);
9598 void dhd_detach(dhd_pub_t *dhdp)
9601 unsigned long flags;
9602 int timer_valid = FALSE;
9603 struct net_device *dev;
9608 dhd = (dhd_info_t *)dhdp->info;
9612 dev = dhd->iflist[0]->net;
9616 if (dev->flags & IFF_UP) {
9617 /* If IFF_UP is still up, it indicates that
9618 * "ifconfig wlan0 down" hasn't been called.
9619 * So invoke dev_close explicitly here to
9620 * bring down the interface.
9622 DHD_TRACE(("IFF_UP flag is up. Enforcing dev_close from detach \n"));
9628 DHD_TRACE(("%s: Enter state 0x%x\n", __FUNCTION__, dhd->dhd_state));
9631 if (!(dhd->dhd_state & DHD_ATTACH_STATE_DONE)) {
9632 /* Give sufficient time for threads to start running in case
9633 * dhd_attach() has failed
9638 #if defined(BCM_DNGL_EMBEDIMAGE) || defined(BCM_REQUEST_FW)
9639 #endif /* defined(BCM_DNGL_EMBEDIMAGE) || defined(BCM_REQUEST_FW) */
9641 #ifdef PROP_TXSTATUS
9642 #ifdef DHD_WLFC_THREAD
9643 if (dhd->pub.wlfc_thread) {
9644 kthread_stop(dhd->pub.wlfc_thread);
9645 dhdp->wlfc_thread_go = TRUE;
9646 wake_up_interruptible(&dhdp->wlfc_wqhead);
9648 dhd->pub.wlfc_thread = NULL;
9649 #endif /* DHD_WLFC_THREAD */
9650 #endif /* PROP_TXSTATUS */
9652 if (dhd->dhd_state & DHD_ATTACH_STATE_PROT_ATTACH) {
9654 dhd_bus_detach(dhdp);
9656 if (is_reboot == SYS_RESTART) {
9657 extern bcmdhd_wifi_platdata_t *dhd_wifi_platdata;
9658 if (dhd_wifi_platdata && !dhdp->dongle_reset) {
9659 dhdpcie_bus_clock_stop(dhdp->bus);
9660 wifi_platform_set_power(dhd_wifi_platdata->adapters,
9661 FALSE, WIFI_TURNOFF_DELAY);
9664 #endif /* BCMPCIE */
9665 #ifndef PCIE_FULL_DONGLE
9667 dhd_prot_detach(dhdp);
9671 #ifdef ARP_OFFLOAD_SUPPORT
9672 if (dhd_inetaddr_notifier_registered) {
9673 dhd_inetaddr_notifier_registered = FALSE;
9674 unregister_inetaddr_notifier(&dhd_inetaddr_notifier);
9676 #endif /* ARP_OFFLOAD_SUPPORT */
9677 #if defined(CONFIG_IPV6) && defined(IPV6_NDO_SUPPORT)
9678 if (dhd_inet6addr_notifier_registered) {
9679 dhd_inet6addr_notifier_registered = FALSE;
9680 unregister_inet6addr_notifier(&dhd_inet6addr_notifier);
9682 #endif /* CONFIG_IPV6 && IPV6_NDO_SUPPORT */
9683 #if defined(CONFIG_HAS_EARLYSUSPEND) && defined(DHD_USE_EARLYSUSPEND)
9684 if (dhd->dhd_state & DHD_ATTACH_STATE_EARLYSUSPEND_DONE) {
9685 if (dhd->early_suspend.suspend)
9686 unregister_early_suspend(&dhd->early_suspend);
9688 #endif /* CONFIG_HAS_EARLYSUSPEND && DHD_USE_EARLYSUSPEND */
9690 #if defined(WL_WIRELESS_EXT)
9691 if (dhd->dhd_state & DHD_ATTACH_STATE_WL_ATTACH) {
9692 /* Detatch and unlink in the iw */
9698 #endif /* defined(WL_WIRELESS_EXT) */
9700 /* delete all interfaces, start with virtual */
9701 if (dhd->dhd_state & DHD_ATTACH_STATE_ADD_IF) {
9705 /* Cleanup virtual interfaces */
9706 dhd_net_if_lock_local(dhd);
9707 for (i = 1; i < DHD_MAX_IFS; i++) {
9709 dhd_remove_if(&dhd->pub, i, TRUE);
9711 dhd_net_if_unlock_local(dhd);
9713 /* delete primary interface 0 */
9714 ifp = dhd->iflist[0];
9717 if (ifp && ifp->net) {
9721 /* in unregister_netdev case, the interface gets freed by net->destructor
9722 * (which is set to free_netdev)
9724 if (ifp->net->reg_state == NETREG_UNINITIALIZED) {
9725 free_netdev(ifp->net);
9728 custom_rps_map_clear(ifp->net->_rx);
9729 #endif /* SET_RPS_CPUS */
9730 netif_tx_disable(ifp->net);
9731 unregister_netdev(ifp->net);
9735 dhd_wmf_cleanup(dhdp, 0);
9736 #endif /* DHD_WMF */
9737 #ifdef DHD_L2_FILTER
9738 bcm_l2_filter_arp_table_update(dhdp->osh, ifp->phnd_arp_table, TRUE,
9739 NULL, FALSE, dhdp->tickcnt);
9740 deinit_l2_filter_arp_table(dhdp->osh, ifp->phnd_arp_table);
9741 ifp->phnd_arp_table = NULL;
9742 #endif /* DHD_L2_FILTER */
9744 dhd_if_del_sta_list(ifp);
9746 MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
9747 dhd->iflist[0] = NULL;
9751 /* Clear the watchdog timer */
9752 DHD_GENERAL_LOCK(&dhd->pub, flags);
9753 timer_valid = dhd->wd_timer_valid;
9754 dhd->wd_timer_valid = FALSE;
9755 DHD_GENERAL_UNLOCK(&dhd->pub, flags);
9757 del_timer_sync(&dhd->timer);
9758 DHD_DISABLE_RUNTIME_PM(&dhd->pub);
9760 if (dhd->dhd_state & DHD_ATTACH_STATE_THREADS_CREATED) {
9761 #ifdef DHD_PCIE_RUNTIMEPM
9762 if (dhd->thr_rpm_ctl.thr_pid >= 0) {
9763 PROC_STOP(&dhd->thr_rpm_ctl);
9765 #endif /* DHD_PCIE_RUNTIMEPM */
9766 if (dhd->thr_wdt_ctl.thr_pid >= 0) {
9767 PROC_STOP(&dhd->thr_wdt_ctl);
9770 if (dhd->rxthread_enabled && dhd->thr_rxf_ctl.thr_pid >= 0) {
9771 PROC_STOP(&dhd->thr_rxf_ctl);
9774 if (dhd->thr_dpc_ctl.thr_pid >= 0) {
9775 PROC_STOP(&dhd->thr_dpc_ctl);
9777 tasklet_kill(&dhd->tasklet);
9779 __skb_queue_purge(&dhd->rx_pend_queue);
9780 #endif /* DHD_LB_RXP */
9785 /* Kill the Load Balancing Tasklets */
9786 #if defined(DHD_LB_TXC)
9787 tasklet_disable(&dhd->tx_compl_tasklet);
9788 tasklet_kill(&dhd->tx_compl_tasklet);
9789 #endif /* DHD_LB_TXC */
9790 #if defined(DHD_LB_RXC)
9791 tasklet_disable(&dhd->rx_compl_tasklet);
9792 tasklet_kill(&dhd->rx_compl_tasklet);
9793 #endif /* DHD_LB_RXC */
9794 if (dhd->cpu_notifier.notifier_call != NULL)
9795 unregister_cpu_notifier(&dhd->cpu_notifier);
9796 dhd_cpumasks_deinit(dhd);
9800 dhd_log_dump_deinit(&dhd->pub);
9801 #endif /* DHD_LOG_DUMP */
9803 if (dhd->dhd_state & DHD_ATTACH_STATE_CFG80211) {
9804 wl_cfg80211_detach(NULL);
9805 dhd_monitor_uninit();
9808 /* free deferred work queue */
9809 dhd_deferred_work_deinit(dhd->dhd_deferred_wq);
9810 dhd->dhd_deferred_wq = NULL;
9812 #ifdef SHOW_LOGTRACE
9813 if (dhd->event_data.fmts)
9814 kfree(dhd->event_data.fmts);
9815 if (dhd->event_data.raw_fmts)
9816 kfree(dhd->event_data.raw_fmts);
9817 if (dhd->event_data.raw_sstr)
9818 kfree(dhd->event_data.raw_sstr);
9819 #endif /* SHOW_LOGTRACE */
9822 if (dhdp->pno_state)
9823 dhd_pno_deinit(dhdp);
9825 #if defined(CONFIG_PM_SLEEP)
9826 if (dhd_pm_notifier_registered) {
9827 unregister_pm_notifier(&dhd->pm_notifier);
9828 dhd_pm_notifier_registered = FALSE;
9830 #endif /* CONFIG_PM_SLEEP */
9832 #ifdef DEBUG_CPU_FREQ
9834 free_percpu(dhd->new_freq);
9835 dhd->new_freq = NULL;
9836 cpufreq_unregister_notifier(&dhd->freq_trans, CPUFREQ_TRANSITION_NOTIFIER);
9838 if (dhd->dhd_state & DHD_ATTACH_STATE_WAKELOCKS_INIT) {
9839 DHD_TRACE(("wd wakelock count:%d\n", dhd->wakelock_wd_counter));
9840 #ifdef CONFIG_HAS_WAKELOCK
9841 dhd->wakelock_wd_counter = 0;
9842 wake_lock_destroy(&dhd->wl_wdwake);
9843 #endif /* CONFIG_HAS_WAKELOCK */
9844 DHD_OS_WAKE_LOCK_DESTROY(dhd);
9849 #ifdef DHDTCPACK_SUPPRESS
9850 /* This will free all MEM allocated for TCPACK SUPPRESS */
9851 dhd_tcpack_suppress_set(&dhd->pub, TCPACK_SUP_OFF);
9852 #endif /* DHDTCPACK_SUPPRESS */
9854 #ifdef PCIE_FULL_DONGLE
9855 dhd_flow_rings_deinit(dhdp);
9857 dhd_prot_detach(dhdp);
9861 dhd_sysfs_exit(dhd);
9862 dhd->pub.is_fw_download_done = FALSE;
9863 dhd_conf_detach(dhdp);
9868 dhd_free(dhd_pub_t *dhdp)
9871 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
9875 for (i = 0; i < ARRAYSIZE(dhdp->reorder_bufs); i++) {
9876 if (dhdp->reorder_bufs[i]) {
9877 reorder_info_t *ptr;
9878 uint32 buf_size = sizeof(struct reorder_info);
9880 ptr = dhdp->reorder_bufs[i];
9882 buf_size += ((ptr->max_idx + 1) * sizeof(void*));
9883 DHD_REORDER(("free flow id buf %d, maxidx is %d, buf_size %d\n",
9884 i, ptr->max_idx, buf_size));
9886 MFREE(dhdp->osh, dhdp->reorder_bufs[i], buf_size);
9887 dhdp->reorder_bufs[i] = NULL;
9891 dhd_sta_pool_fini(dhdp, DHD_MAX_STA);
9893 dhd = (dhd_info_t *)dhdp->info;
9894 if (dhdp->soc_ram) {
9895 #if defined(CONFIG_DHD_USE_STATIC_BUF) && defined(DHD_USE_STATIC_MEMDUMP)
9896 DHD_OS_PREFREE(dhdp, dhdp->soc_ram, dhdp->soc_ram_length);
9898 MFREE(dhdp->osh, dhdp->soc_ram, dhdp->soc_ram_length);
9899 #endif /* CONFIG_DHD_USE_STATIC_BUF && DHD_USE_STATIC_MEMDUMP */
9900 dhdp->soc_ram = NULL;
9902 #ifdef CACHE_FW_IMAGES
9903 if (dhdp->cached_fw) {
9904 MFREE(dhdp->osh, dhdp->cached_fw, dhdp->bus->ramsize);
9905 dhdp->cached_fw = NULL;
9908 if (dhdp->cached_nvram) {
9909 MFREE(dhdp->osh, dhdp->cached_nvram, MAX_NVRAMBUF_SIZE);
9910 dhdp->cached_nvram = NULL;
9913 /* If pointer is allocated by dhd_os_prealloc then avoid MFREE */
9915 dhd != (dhd_info_t *)dhd_os_prealloc(dhdp, DHD_PREALLOC_DHD_INFO, 0, FALSE))
9916 MFREE(dhd->pub.osh, dhd, sizeof(*dhd));
9922 dhd_clear(dhd_pub_t *dhdp)
9924 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
9928 #ifdef DHDTCPACK_SUPPRESS
9929 /* Clean up timer/data structure for any remaining/pending packet or timer. */
9930 dhd_tcpack_info_tbl_clean(dhdp);
9931 #endif /* DHDTCPACK_SUPPRESS */
9932 for (i = 0; i < ARRAYSIZE(dhdp->reorder_bufs); i++) {
9933 if (dhdp->reorder_bufs[i]) {
9934 reorder_info_t *ptr;
9935 uint32 buf_size = sizeof(struct reorder_info);
9937 ptr = dhdp->reorder_bufs[i];
9939 buf_size += ((ptr->max_idx + 1) * sizeof(void*));
9940 DHD_REORDER(("free flow id buf %d, maxidx is %d, buf_size %d\n",
9941 i, ptr->max_idx, buf_size));
9943 MFREE(dhdp->osh, dhdp->reorder_bufs[i], buf_size);
9944 dhdp->reorder_bufs[i] = NULL;
9948 dhd_sta_pool_clear(dhdp, DHD_MAX_STA);
9950 if (dhdp->soc_ram) {
9951 #if defined(CONFIG_DHD_USE_STATIC_BUF) && defined(DHD_USE_STATIC_MEMDUMP)
9952 DHD_OS_PREFREE(dhdp, dhdp->soc_ram, dhdp->soc_ram_length);
9954 MFREE(dhdp->osh, dhdp->soc_ram, dhdp->soc_ram_length);
9955 #endif /* CONFIG_DHD_USE_STATIC_BUF && DHD_USE_STATIC_MEMDUMP */
9956 dhdp->soc_ram = NULL;
9962 dhd_module_cleanup(void)
9964 printf("%s: Enter\n", __FUNCTION__);
9966 dhd_bus_unregister();
9970 dhd_wifi_platform_unregister_drv();
9971 printf("%s: Exit\n", __FUNCTION__);
9975 dhd_module_exit(void)
9978 dhd_module_cleanup();
9979 unregister_reboot_notifier(&dhd_reboot_notifier);
9983 dhd_module_init(void)
9988 printf("%s: in\n", __FUNCTION__);
9992 DHD_PERIM_RADIO_INIT();
9995 if (firmware_path[0] != '\0') {
9996 strncpy(fw_bak_path, firmware_path, MOD_PARAM_PATHLEN);
9997 fw_bak_path[MOD_PARAM_PATHLEN-1] = '\0';
10000 if (nvram_path[0] != '\0') {
10001 strncpy(nv_bak_path, nvram_path, MOD_PARAM_PATHLEN);
10002 nv_bak_path[MOD_PARAM_PATHLEN-1] = '\0';
10006 err = dhd_wifi_platform_register_drv();
10008 register_reboot_notifier(&dhd_reboot_notifier);
10012 DHD_ERROR(("%s: Failed to load the driver, try cnt %d\n",
10013 __FUNCTION__, retry));
10014 strncpy(firmware_path, fw_bak_path, MOD_PARAM_PATHLEN);
10015 firmware_path[MOD_PARAM_PATHLEN-1] = '\0';
10016 strncpy(nvram_path, nv_bak_path, MOD_PARAM_PATHLEN);
10017 nvram_path[MOD_PARAM_PATHLEN-1] = '\0';
10022 DHD_ERROR(("%s: Failed to load driver max retry reached**\n", __FUNCTION__));
10024 if (!dhd_download_fw_on_driverload) {
10025 dhd_driver_init_done = TRUE;
10029 printf("%s: Exit err=%d\n", __FUNCTION__, err);
10034 dhd_reboot_callback(struct notifier_block *this, unsigned long code, void *unused)
10036 DHD_TRACE(("%s: code = %ld\n", __FUNCTION__, code));
10037 if (code == SYS_RESTART) {
10040 #endif /* BCMPCIE */
10042 return NOTIFY_DONE;
10045 static int wifi_init_thread(void *data)
10052 int rockchip_wifi_init_module_rkwifi(void)
10054 struct task_struct *kthread = NULL;
10056 kthread = kthread_run(wifi_init_thread, NULL, "wifi_init_thread");
10057 if (IS_ERR(kthread))
10058 pr_err("create wifi_init_thread failed.\n");
10063 void rockchip_wifi_exit_module_rkwifi(void)
10068 #ifdef CONFIG_WIFI_LOAD_DRIVER_WHEN_KERNEL_BOOTUP
10069 late_initcall(rockchip_wifi_init_module_rkwifi);
10070 module_exit(rockchip_wifi_exit_module_rkwifi);
10072 module_init(rockchip_wifi_init_module_rkwifi);
10073 module_exit(rockchip_wifi_exit_module_rkwifi);
10076 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
10077 #if defined(CONFIG_DEFERRED_INITCALLS)
10078 #if defined(CONFIG_MACH_UNIVERSAL7420) || defined(CONFIG_SOC_EXYNOS8890) || \
10079 defined(CONFIG_ARCH_MSM8996)
10080 deferred_module_init_sync(dhd_module_init);
10082 deferred_module_init(dhd_module_init);
10083 #endif /* CONFIG_MACH_UNIVERSAL7420 || CONFIG_SOC_EXYNOS8890 ||
10084 * CONFIG_ARCH_MSM8996
10086 #elif defined(USE_LATE_INITCALL_SYNC)
10087 late_initcall_sync(dhd_module_init);
10089 late_initcall(dhd_module_init);
10090 #endif /* USE_LATE_INITCALL_SYNC */
10092 module_init(dhd_module_init);
10093 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) */
10095 module_exit(dhd_module_exit);
10099 * OS specific functions required to implement DHD driver in OS independent way
10102 dhd_os_proto_block(dhd_pub_t *pub)
10104 dhd_info_t * dhd = (dhd_info_t *)(pub->info);
10107 DHD_PERIM_UNLOCK(pub);
10109 down(&dhd->proto_sem);
10111 DHD_PERIM_LOCK(pub);
10119 dhd_os_proto_unblock(dhd_pub_t *pub)
10121 dhd_info_t * dhd = (dhd_info_t *)(pub->info);
10124 up(&dhd->proto_sem);
10132 dhd_os_dhdiovar_lock(dhd_pub_t *pub)
10134 dhd_info_t * dhd = (dhd_info_t *)(pub->info);
10137 mutex_lock(&dhd->dhd_iovar_mutex);
10142 dhd_os_dhdiovar_unlock(dhd_pub_t *pub)
10144 dhd_info_t * dhd = (dhd_info_t *)(pub->info);
10147 mutex_unlock(&dhd->dhd_iovar_mutex);
10152 dhd_os_get_ioctl_resp_timeout(void)
10154 return ((unsigned int)dhd_ioctl_timeout_msec);
10158 dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec)
10160 dhd_ioctl_timeout_msec = (int)timeout_msec;
10164 dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition)
10166 dhd_info_t * dhd = (dhd_info_t *)(pub->info);
10169 /* Convert timeout in millsecond to jiffies */
10170 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
10171 timeout = msecs_to_jiffies(dhd_ioctl_timeout_msec);
10173 timeout = dhd_ioctl_timeout_msec * HZ / 1000;
10176 DHD_PERIM_UNLOCK(pub);
10178 timeout = wait_event_timeout(dhd->ioctl_resp_wait, (*condition), timeout);
10180 DHD_PERIM_LOCK(pub);
10186 dhd_os_ioctl_resp_wake(dhd_pub_t *pub)
10188 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
10190 wake_up(&dhd->ioctl_resp_wait);
10195 dhd_os_d3ack_wait(dhd_pub_t *pub, uint *condition)
10197 dhd_info_t * dhd = (dhd_info_t *)(pub->info);
10200 /* Convert timeout in millsecond to jiffies */
10201 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
10202 timeout = msecs_to_jiffies(dhd_ioctl_timeout_msec);
10204 timeout = dhd_ioctl_timeout_msec * HZ / 1000;
10207 DHD_PERIM_UNLOCK(pub);
10209 timeout = wait_event_timeout(dhd->d3ack_wait, (*condition), timeout);
10211 DHD_PERIM_LOCK(pub);
10217 dhd_os_d3ack_wake(dhd_pub_t *pub)
10219 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
10221 wake_up(&dhd->d3ack_wait);
10226 dhd_os_busbusy_wait_negation(dhd_pub_t *pub, uint *condition)
10228 dhd_info_t * dhd = (dhd_info_t *)(pub->info);
10231 /* Wait for bus usage contexts to gracefully exit within some timeout value
10232 * Set time out to little higher than dhd_ioctl_timeout_msec,
10233 * so that IOCTL timeout should not get affected.
10235 /* Convert timeout in millsecond to jiffies */
10236 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
10237 timeout = msecs_to_jiffies(DHD_BUS_BUSY_TIMEOUT);
10239 timeout = DHD_BUS_BUSY_TIMEOUT * HZ / 1000;
10242 timeout = wait_event_timeout(dhd->dhd_bus_busy_state_wait, !(*condition), timeout);
10248 dhd_os_busbusy_wake(dhd_pub_t *pub)
10250 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
10251 /* Call wmb() to make sure before waking up the other event value gets updated */
10253 wake_up(&dhd->dhd_bus_busy_state_wait);
10258 dhd_os_wd_timer_extend(void *bus, bool extend)
10260 dhd_pub_t *pub = bus;
10261 dhd_info_t *dhd = (dhd_info_t *)pub->info;
10264 dhd_os_wd_timer(bus, WATCHDOG_EXTEND_INTERVAL);
10266 dhd_os_wd_timer(bus, dhd->default_wd_interval);
10271 dhd_os_wd_timer(void *bus, uint wdtick)
10273 dhd_pub_t *pub = bus;
10274 dhd_info_t *dhd = (dhd_info_t *)pub->info;
10275 unsigned long flags;
10277 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
10280 DHD_ERROR(("%s: dhd NULL\n", __FUNCTION__));
10284 DHD_OS_WD_WAKE_LOCK(pub);
10285 DHD_GENERAL_LOCK(pub, flags);
10287 /* don't start the wd until fw is loaded */
10288 if (pub->busstate == DHD_BUS_DOWN) {
10289 DHD_GENERAL_UNLOCK(pub, flags);
10291 DHD_OS_WD_WAKE_UNLOCK(pub);
10295 /* Totally stop the timer */
10296 if (!wdtick && dhd->wd_timer_valid == TRUE) {
10297 dhd->wd_timer_valid = FALSE;
10298 DHD_GENERAL_UNLOCK(pub, flags);
10299 del_timer_sync(&dhd->timer);
10300 DHD_OS_WD_WAKE_UNLOCK(pub);
10305 DHD_OS_WD_WAKE_LOCK(pub);
10306 dhd_watchdog_ms = (uint)wdtick;
10307 /* Re arm the timer, at last watchdog period */
10308 mod_timer(&dhd->timer, jiffies + msecs_to_jiffies(dhd_watchdog_ms));
10309 dhd->wd_timer_valid = TRUE;
10311 DHD_GENERAL_UNLOCK(pub, flags);
10312 DHD_OS_WD_WAKE_UNLOCK(pub);
10315 #ifdef DHD_PCIE_RUNTIMEPM
10317 dhd_os_runtimepm_timer(void *bus, uint tick)
10319 dhd_pub_t *pub = bus;
10320 dhd_info_t *dhd = (dhd_info_t *)pub->info;
10321 unsigned long flags;
10323 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
10326 DHD_ERROR(("%s: dhd is NULL\n", __FUNCTION__));
10330 DHD_GENERAL_LOCK(pub, flags);
10332 /* don't start the RPM until fw is loaded */
10333 if (pub->busstate == DHD_BUS_DOWN ||
10334 pub->busstate == DHD_BUS_DOWN_IN_PROGRESS) {
10335 DHD_GENERAL_UNLOCK(pub, flags);
10339 /* If tick is non-zero, the request is to start the timer */
10341 /* Start the timer only if its not already running */
10342 if (dhd->rpm_timer_valid == FALSE) {
10343 mod_timer(&dhd->rpm_timer, jiffies + msecs_to_jiffies(dhd_runtimepm_ms));
10344 dhd->rpm_timer_valid = TRUE;
10347 /* tick is zero, we have to stop the timer */
10348 /* Stop the timer only if its running, otherwise we don't have to do anything */
10349 if (dhd->rpm_timer_valid == TRUE) {
10350 dhd->rpm_timer_valid = FALSE;
10351 DHD_GENERAL_UNLOCK(pub, flags);
10352 del_timer_sync(&dhd->rpm_timer);
10353 /* we have already released the lock, so just go to exit */
10358 DHD_GENERAL_UNLOCK(pub, flags);
10364 #endif /* DHD_PCIE_RUNTIMEPM */
10367 dhd_os_open_image(char *filename)
10372 fp = filp_open(filename, O_RDONLY, 0);
10374 * 2.6.11 (FC4) supports filp_open() but later revs don't?
10376 * fp = open_namei(AT_FDCWD, filename, O_RD, 0);
10384 if (!S_ISREG(file_inode(fp)->i_mode)) {
10385 DHD_ERROR(("%s: %s is not regular file\n", __FUNCTION__, filename));
10390 size = i_size_read(file_inode(fp));
10392 DHD_ERROR(("%s: %s file size invalid %d\n", __FUNCTION__, filename, size));
10397 DHD_ERROR(("%s: %s (%d bytes) open success\n", __FUNCTION__, filename, size));
10404 dhd_os_get_image_block(char *buf, int len, void *image)
10406 struct file *fp = (struct file *)image;
10413 size = i_size_read(file_inode(fp));
10414 rdlen = kernel_read(fp, fp->f_pos, buf, MIN(len, size));
10416 if (len >= size && size != rdlen) {
10421 fp->f_pos += rdlen;
10427 dhd_os_close_image(void *image)
10430 filp_close((struct file *)image, NULL);
10434 dhd_os_sdlock(dhd_pub_t *pub)
10438 dhd = (dhd_info_t *)(pub->info);
10440 if (dhd_dpc_prio >= 0)
10443 spin_lock_bh(&dhd->sdlock);
10447 dhd_os_sdunlock(dhd_pub_t *pub)
10451 dhd = (dhd_info_t *)(pub->info);
10453 if (dhd_dpc_prio >= 0)
10456 spin_unlock_bh(&dhd->sdlock);
10460 dhd_os_sdlock_txq(dhd_pub_t *pub)
10464 dhd = (dhd_info_t *)(pub->info);
10465 spin_lock_bh(&dhd->txqlock);
10469 dhd_os_sdunlock_txq(dhd_pub_t *pub)
10473 dhd = (dhd_info_t *)(pub->info);
10474 spin_unlock_bh(&dhd->txqlock);
10478 dhd_os_sdlock_rxq(dhd_pub_t *pub)
10483 dhd_os_sdunlock_rxq(dhd_pub_t *pub)
10488 dhd_os_rxflock(dhd_pub_t *pub)
10492 dhd = (dhd_info_t *)(pub->info);
10493 spin_lock_bh(&dhd->rxf_lock);
10498 dhd_os_rxfunlock(dhd_pub_t *pub)
10502 dhd = (dhd_info_t *)(pub->info);
10503 spin_unlock_bh(&dhd->rxf_lock);
10506 #ifdef DHDTCPACK_SUPPRESS
10508 dhd_os_tcpacklock(dhd_pub_t *pub)
10511 unsigned long flags = 0;
10513 dhd = (dhd_info_t *)(pub->info);
10517 spin_lock_bh(&dhd->tcpack_lock);
10519 spin_lock_irqsave(&dhd->tcpack_lock, flags);
10520 #endif /* BCMSDIO */
10527 dhd_os_tcpackunlock(dhd_pub_t *pub, unsigned long flags)
10532 BCM_REFERENCE(flags);
10533 #endif /* BCMSDIO */
10535 dhd = (dhd_info_t *)(pub->info);
10539 spin_lock_bh(&dhd->tcpack_lock);
10541 spin_unlock_irqrestore(&dhd->tcpack_lock, flags);
10542 #endif /* BCMSDIO */
10545 #endif /* DHDTCPACK_SUPPRESS */
10547 uint8* dhd_os_prealloc(dhd_pub_t *dhdpub, int section, uint size, bool kmalloc_if_fail)
10550 gfp_t flags = CAN_SLEEP() ? GFP_KERNEL: GFP_ATOMIC;
10552 buf = (uint8*)wifi_platform_prealloc(dhdpub->info->adapter, section, size);
10553 if (buf == NULL && kmalloc_if_fail)
10554 buf = kmalloc(size, flags);
10559 void dhd_os_prefree(dhd_pub_t *dhdpub, void *addr, uint size)
10563 #if defined(WL_WIRELESS_EXT)
10564 struct iw_statistics *
10565 dhd_get_wireless_stats(struct net_device *dev)
10568 dhd_info_t *dhd = DHD_DEV_INFO(dev);
10570 if (!dhd->pub.up) {
10574 res = wl_iw_get_wireless_stats(dev, &dhd->iw.wstats);
10577 return &dhd->iw.wstats;
10581 #endif /* defined(WL_WIRELESS_EXT) */
10584 dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
10585 wl_event_msg_t *event, void **data)
10588 ASSERT(dhd != NULL);
10590 #ifdef SHOW_LOGTRACE
10591 bcmerror = wl_host_event(&dhd->pub, ifidx, pktdata, event, data, &dhd->event_data);
10593 bcmerror = wl_host_event(&dhd->pub, ifidx, pktdata, event, data, NULL);
10594 #endif /* SHOW_LOGTRACE */
10596 if (bcmerror != BCME_OK)
10599 #if defined(WL_WIRELESS_EXT)
10600 if (event->bsscfgidx == 0) {
10602 * Wireless ext is on primary interface only
10605 ASSERT(dhd->iflist[*ifidx] != NULL);
10606 ASSERT(dhd->iflist[*ifidx]->net != NULL);
10608 if (dhd->iflist[*ifidx]->net) {
10609 wl_iw_event(dhd->iflist[*ifidx]->net, event, *data);
10612 #endif /* defined(WL_WIRELESS_EXT) */
10615 ASSERT(dhd->iflist[*ifidx] != NULL);
10616 ASSERT(dhd->iflist[*ifidx]->net != NULL);
10617 if (dhd->iflist[*ifidx]->net)
10618 wl_cfg80211_event(dhd->iflist[*ifidx]->net, event, *data);
10619 #endif /* defined(WL_CFG80211) */
10624 /* send up locally generated event */
10626 dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data)
10628 switch (ntoh32(event->event_type)) {
10635 #ifdef LOG_INTO_TCPDUMP
10637 dhd_sendup_log(dhd_pub_t *dhdp, void *data, int data_len)
10639 struct sk_buff *p, *skb;
10646 struct ether_header eth;
10648 pktlen = sizeof(eth) + data_len;
10651 if ((p = PKTGET(dhdp->osh, pktlen, FALSE))) {
10652 ASSERT(ISALIGNED((uintptr)PKTDATA(dhdp->osh, p), sizeof(uint32)));
10654 bcopy(&dhdp->mac, ð.ether_dhost, ETHER_ADDR_LEN);
10655 bcopy(&dhdp->mac, ð.ether_shost, ETHER_ADDR_LEN);
10656 ETHER_TOGGLE_LOCALADDR(ð.ether_shost);
10657 eth.ether_type = hton16(ETHER_TYPE_BRCM);
10659 bcopy((void *)ð, PKTDATA(dhdp->osh, p), sizeof(eth));
10660 bcopy(data, PKTDATA(dhdp->osh, p) + sizeof(eth), data_len);
10661 skb = PKTTONATIVE(dhdp->osh, p);
10662 skb_data = skb->data;
10665 ifidx = dhd_ifname2idx(dhd, "wlan0");
10666 ifp = dhd->iflist[ifidx];
10668 ifp = dhd->iflist[0];
10671 skb->dev = ifp->net;
10672 skb->protocol = eth_type_trans(skb, skb->dev);
10673 skb->data = skb_data;
10676 /* Strip header, count, deliver upward */
10677 skb_pull(skb, ETH_HLEN);
10679 bcm_object_trace_opr(skb, BCM_OBJDBG_REMOVE,
10680 __FUNCTION__, __LINE__);
10681 /* Send the packet */
10682 if (in_interrupt()) {
10689 /* Could not allocate a sk_buf */
10690 DHD_ERROR(("%s: unable to alloc sk_buf\n", __FUNCTION__));
10693 #endif /* LOG_INTO_TCPDUMP */
10695 void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar)
10697 #if defined(BCMSDIO) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
10698 struct dhd_info *dhdinfo = dhd->info;
10700 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
10701 int timeout = msecs_to_jiffies(IOCTL_RESP_TIMEOUT);
10703 int timeout = (IOCTL_RESP_TIMEOUT / 1000) * HZ;
10704 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
10706 dhd_os_sdunlock(dhd);
10707 wait_event_timeout(dhdinfo->ctrl_wait, (*lockvar == FALSE), timeout);
10708 dhd_os_sdlock(dhd);
10709 #endif /* defined(BCMSDIO) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)) */
10713 void dhd_wait_event_wakeup(dhd_pub_t *dhd)
10715 #if defined(BCMSDIO) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
10716 struct dhd_info *dhdinfo = dhd->info;
10717 if (waitqueue_active(&dhdinfo->ctrl_wait))
10718 wake_up(&dhdinfo->ctrl_wait);
10723 #if defined(BCMSDIO) || defined(BCMPCIE)
10725 dhd_net_bus_devreset(struct net_device *dev, uint8 flag)
10729 dhd_info_t *dhd = DHD_DEV_INFO(dev);
10731 if (flag == TRUE) {
10732 /* Issue wl down command before resetting the chip */
10733 if (dhd_wl_ioctl_cmd(&dhd->pub, WLC_DOWN, NULL, 0, TRUE, 0) < 0) {
10734 DHD_TRACE(("%s: wl down failed\n", __FUNCTION__));
10736 #ifdef PROP_TXSTATUS
10737 if (dhd->pub.wlfc_enabled)
10738 dhd_wlfc_deinit(&dhd->pub);
10739 #endif /* PROP_TXSTATUS */
10741 if (dhd->pub.pno_state)
10742 dhd_pno_deinit(&dhd->pub);
10748 dhd_update_fw_nv_path(dhd);
10749 /* update firmware and nvram path to sdio bus */
10750 dhd_bus_update_fw_nv_path(dhd->pub.bus,
10751 dhd->fw_path, dhd->nv_path, dhd->conf_path);
10753 #endif /* BCMSDIO */
10755 ret = dhd_bus_devreset(&dhd->pub, flag);
10757 DHD_ERROR(("%s: dhd_bus_devreset: %d\n", __FUNCTION__, ret));
10766 dhd_net_bus_suspend(struct net_device *dev)
10768 dhd_info_t *dhd = DHD_DEV_INFO(dev);
10769 return dhd_bus_suspend(&dhd->pub);
10773 dhd_net_bus_resume(struct net_device *dev, uint8 stage)
10775 dhd_info_t *dhd = DHD_DEV_INFO(dev);
10776 return dhd_bus_resume(&dhd->pub, stage);
10779 #endif /* BCMSDIO */
10780 #endif /* BCMSDIO || BCMPCIE */
10782 int net_os_set_suspend_disable(struct net_device *dev, int val)
10784 dhd_info_t *dhd = DHD_DEV_INFO(dev);
10788 ret = dhd->pub.suspend_disable_flag;
10789 dhd->pub.suspend_disable_flag = val;
10794 int net_os_set_suspend(struct net_device *dev, int val, int force)
10797 dhd_info_t *dhd = DHD_DEV_INFO(dev);
10800 #ifdef CONFIG_MACH_UNIVERSAL7420
10801 #endif /* CONFIG_MACH_UNIVERSAL7420 */
10802 #if defined(CONFIG_HAS_EARLYSUSPEND) && defined(DHD_USE_EARLYSUSPEND)
10803 ret = dhd_set_suspend(val, &dhd->pub);
10805 ret = dhd_suspend_resume_helper(dhd, val, force);
10808 wl_cfg80211_update_power_mode(dev);
10814 int net_os_set_suspend_bcn_li_dtim(struct net_device *dev, int val)
10816 dhd_info_t *dhd = DHD_DEV_INFO(dev);
10819 dhd->pub.suspend_bcn_li_dtim = val;
10824 #ifdef PKT_FILTER_SUPPORT
10825 int net_os_rxfilter_add_remove(struct net_device *dev, int add_remove, int num)
10827 #ifdef GAN_LITE_NAT_KEEPALIVE_FILTER
10830 dhd_info_t *dhd = DHD_DEV_INFO(dev);
10831 char *filterp = NULL;
10835 if (!dhd_master_mode)
10836 add_remove = !add_remove;
10837 DHD_ERROR(("%s: add_remove = %d, num = %d\n", __FUNCTION__, add_remove, num));
10838 if (!dhd || (num == DHD_UNICAST_FILTER_NUM))
10840 if (num >= dhd->pub.pktfilter_count)
10843 case DHD_BROADCAST_FILTER_NUM:
10844 filterp = "101 0 0 0 0xFFFFFFFFFFFF 0xFFFFFFFFFFFF";
10847 case DHD_MULTICAST4_FILTER_NUM:
10848 filterp = "102 0 0 0 0xFFFFFF 0x01005E";
10851 case DHD_MULTICAST6_FILTER_NUM:
10852 filterp = "103 0 0 0 0xFFFF 0x3333";
10855 case DHD_MDNS_FILTER_NUM:
10856 filterp = "104 0 0 0 0xFFFFFFFFFFFF 0x01005E0000FB";
10865 dhd->pub.pktfilter[num] = filterp;
10866 dhd_pktfilter_offload_set(&dhd->pub, dhd->pub.pktfilter[num]);
10867 } else { /* Delete filter */
10868 if (dhd->pub.pktfilter[num] != NULL) {
10869 dhd_pktfilter_offload_delete(&dhd->pub, filter_id);
10870 dhd->pub.pktfilter[num] = NULL;
10874 #endif /* GAN_LITE_NAT_KEEPALIVE_FILTER */
10877 int dhd_os_enable_packet_filter(dhd_pub_t *dhdp, int val)
10882 /* Packet filtering is set only if we still in early-suspend and
10883 * we need either to turn it ON or turn it OFF
10884 * We can always turn it OFF in case of early-suspend, but we turn it
10885 * back ON only if suspend_disable_flag was not set
10887 if (dhdp && dhdp->up) {
10888 if (dhdp->in_suspend) {
10889 if (!val || (val && !dhdp->suspend_disable_flag))
10890 dhd_enable_packet_filter(val, dhdp);
10896 /* function to enable/disable packet for Network device */
10897 int net_os_enable_packet_filter(struct net_device *dev, int val)
10899 dhd_info_t *dhd = DHD_DEV_INFO(dev);
10901 DHD_ERROR(("%s: val = %d\n", __FUNCTION__, val));
10902 return dhd_os_enable_packet_filter(&dhd->pub, val);
10904 #endif /* PKT_FILTER_SUPPORT */
10907 dhd_dev_init_ioctl(struct net_device *dev)
10909 dhd_info_t *dhd = DHD_DEV_INFO(dev);
10912 if ((ret = dhd_sync_with_dongle(&dhd->pub)) < 0)
10920 dhd_dev_get_feature_set(struct net_device *dev)
10922 dhd_info_t *ptr = *(dhd_info_t **)netdev_priv(dev);
10923 dhd_pub_t *dhd = (&ptr->pub);
10924 int feature_set = 0;
10926 #ifdef DYNAMIC_SWOOB_DURATION
10927 #ifndef CUSTOM_INTR_WIDTH
10928 #define CUSTOM_INTR_WIDTH 100
10929 int intr_width = 0;
10930 #endif /* CUSTOM_INTR_WIDTH */
10931 #endif /* DYNAMIC_SWOOB_DURATION */
10933 return feature_set;
10935 if (FW_SUPPORTED(dhd, sta))
10936 feature_set |= WIFI_FEATURE_INFRA;
10937 if (FW_SUPPORTED(dhd, dualband))
10938 feature_set |= WIFI_FEATURE_INFRA_5G;
10939 if (FW_SUPPORTED(dhd, p2p))
10940 feature_set |= WIFI_FEATURE_P2P;
10941 if (dhd->op_mode & DHD_FLAG_HOSTAP_MODE)
10942 feature_set |= WIFI_FEATURE_SOFT_AP;
10943 if (FW_SUPPORTED(dhd, tdls))
10944 feature_set |= WIFI_FEATURE_TDLS;
10945 if (FW_SUPPORTED(dhd, vsdb))
10946 feature_set |= WIFI_FEATURE_TDLS_OFFCHANNEL;
10947 if (FW_SUPPORTED(dhd, nan)) {
10948 feature_set |= WIFI_FEATURE_NAN;
10949 /* NAN is essentail for d2d rtt */
10950 if (FW_SUPPORTED(dhd, rttd2d))
10951 feature_set |= WIFI_FEATURE_D2D_RTT;
10954 feature_set |= WIFI_FEATURE_D2AP_RTT;
10955 #endif /* RTT_SUPPORT */
10956 #ifdef LINKSTAT_SUPPORT
10957 feature_set |= WIFI_FEATURE_LINKSTAT;
10958 #endif /* LINKSTAT_SUPPORT */
10959 /* Supports STA + STA always */
10960 feature_set |= WIFI_FEATURE_ADDITIONAL_STA;
10962 if (dhd_is_pno_supported(dhd)) {
10963 feature_set |= WIFI_FEATURE_PNO;
10964 feature_set |= WIFI_FEATURE_BATCH_SCAN;
10965 #ifdef GSCAN_SUPPORT
10966 feature_set |= WIFI_FEATURE_GSCAN;
10967 #endif /* GSCAN_SUPPORT */
10969 #endif /* PNO_SUPPORT */
10971 feature_set |= WIFI_FEATURE_HOTSPOT;
10973 return feature_set;
10977 int *dhd_dev_get_feature_set_matrix(struct net_device *dev, int *num)
10979 int feature_set_full, mem_needed;
10983 mem_needed = sizeof(int) * MAX_FEATURE_SET_CONCURRRENT_GROUPS;
10984 ret = (int *) kmalloc(mem_needed, GFP_KERNEL);
10986 DHD_ERROR(("%s: failed to allocate %d bytes\n", __FUNCTION__,
10991 feature_set_full = dhd_dev_get_feature_set(dev);
10993 ret[0] = (feature_set_full & WIFI_FEATURE_INFRA) |
10994 (feature_set_full & WIFI_FEATURE_INFRA_5G) |
10995 (feature_set_full & WIFI_FEATURE_NAN) |
10996 (feature_set_full & WIFI_FEATURE_D2D_RTT) |
10997 (feature_set_full & WIFI_FEATURE_D2AP_RTT) |
10998 (feature_set_full & WIFI_FEATURE_PNO) |
10999 (feature_set_full & WIFI_FEATURE_BATCH_SCAN) |
11000 (feature_set_full & WIFI_FEATURE_GSCAN) |
11001 (feature_set_full & WIFI_FEATURE_HOTSPOT) |
11002 (feature_set_full & WIFI_FEATURE_ADDITIONAL_STA) |
11003 (feature_set_full & WIFI_FEATURE_EPR);
11005 ret[1] = (feature_set_full & WIFI_FEATURE_INFRA) |
11006 (feature_set_full & WIFI_FEATURE_INFRA_5G) |
11007 /* Not yet verified NAN with P2P */
11008 /* (feature_set_full & WIFI_FEATURE_NAN) | */
11009 (feature_set_full & WIFI_FEATURE_P2P) |
11010 (feature_set_full & WIFI_FEATURE_D2AP_RTT) |
11011 (feature_set_full & WIFI_FEATURE_D2D_RTT) |
11012 (feature_set_full & WIFI_FEATURE_EPR);
11014 ret[2] = (feature_set_full & WIFI_FEATURE_INFRA) |
11015 (feature_set_full & WIFI_FEATURE_INFRA_5G) |
11016 (feature_set_full & WIFI_FEATURE_NAN) |
11017 (feature_set_full & WIFI_FEATURE_D2D_RTT) |
11018 (feature_set_full & WIFI_FEATURE_D2AP_RTT) |
11019 (feature_set_full & WIFI_FEATURE_TDLS) |
11020 (feature_set_full & WIFI_FEATURE_TDLS_OFFCHANNEL) |
11021 (feature_set_full & WIFI_FEATURE_EPR);
11022 *num = MAX_FEATURE_SET_CONCURRRENT_GROUPS;
11026 #ifdef CUSTOM_FORCE_NODFS_FLAG
11028 dhd_dev_set_nodfs(struct net_device *dev, u32 nodfs)
11030 dhd_info_t *dhd = DHD_DEV_INFO(dev);
11033 dhd->pub.dhd_cflags |= WLAN_PLAT_NODFS_FLAG;
11035 dhd->pub.dhd_cflags &= ~WLAN_PLAT_NODFS_FLAG;
11036 dhd->pub.force_country_change = TRUE;
11039 #endif /* CUSTOM_FORCE_NODFS_FLAG */
11041 /* Linux wrapper to call common dhd_pno_stop_for_ssid */
11043 dhd_dev_pno_stop_for_ssid(struct net_device *dev)
11045 dhd_info_t *dhd = DHD_DEV_INFO(dev);
11047 return (dhd_pno_stop_for_ssid(&dhd->pub));
11049 /* Linux wrapper to call common dhd_pno_set_for_ssid */
11051 dhd_dev_pno_set_for_ssid(struct net_device *dev, wlc_ssid_ext_t* ssids_local, int nssid,
11052 uint16 scan_fr, int pno_repeat, int pno_freq_expo_max, uint16 *channel_list, int nchan)
11054 dhd_info_t *dhd = DHD_DEV_INFO(dev);
11056 return (dhd_pno_set_for_ssid(&dhd->pub, ssids_local, nssid, scan_fr,
11057 pno_repeat, pno_freq_expo_max, channel_list, nchan));
11060 /* Linux wrapper to call common dhd_pno_enable */
11062 dhd_dev_pno_enable(struct net_device *dev, int enable)
11064 dhd_info_t *dhd = DHD_DEV_INFO(dev);
11066 return (dhd_pno_enable(&dhd->pub, enable));
11069 /* Linux wrapper to call common dhd_pno_set_for_hotlist */
11071 dhd_dev_pno_set_for_hotlist(struct net_device *dev, wl_pfn_bssid_t *p_pfn_bssid,
11072 struct dhd_pno_hotlist_params *hotlist_params)
11074 dhd_info_t *dhd = DHD_DEV_INFO(dev);
11075 return (dhd_pno_set_for_hotlist(&dhd->pub, p_pfn_bssid, hotlist_params));
11077 /* Linux wrapper to call common dhd_dev_pno_stop_for_batch */
11079 dhd_dev_pno_stop_for_batch(struct net_device *dev)
11081 dhd_info_t *dhd = DHD_DEV_INFO(dev);
11082 return (dhd_pno_stop_for_batch(&dhd->pub));
11084 /* Linux wrapper to call common dhd_dev_pno_set_for_batch */
11086 dhd_dev_pno_set_for_batch(struct net_device *dev, struct dhd_pno_batch_params *batch_params)
11088 dhd_info_t *dhd = DHD_DEV_INFO(dev);
11089 return (dhd_pno_set_for_batch(&dhd->pub, batch_params));
11091 /* Linux wrapper to call common dhd_dev_pno_get_for_batch */
11093 dhd_dev_pno_get_for_batch(struct net_device *dev, char *buf, int bufsize)
11095 dhd_info_t *dhd = DHD_DEV_INFO(dev);
11096 return (dhd_pno_get_for_batch(&dhd->pub, buf, bufsize, PNO_STATUS_NORMAL));
11098 /* Linux wrapper to call common dhd_pno_set_mac_oui */
11100 dhd_dev_pno_set_mac_oui(struct net_device *dev, uint8 *oui)
11102 dhd_info_t *dhd = DHD_DEV_INFO(dev);
11103 return (dhd_pno_set_mac_oui(&dhd->pub, oui));
11105 #endif /* PNO_SUPPORT */
11107 #if defined(PNO_SUPPORT)
11108 #ifdef GSCAN_SUPPORT
11109 /* Linux wrapper to call common dhd_pno_set_cfg_gscan */
11111 dhd_dev_pno_set_cfg_gscan(struct net_device *dev, dhd_pno_gscan_cmd_cfg_t type,
11112 void *buf, uint8 flush)
11114 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
11116 return (dhd_pno_set_cfg_gscan(&dhd->pub, type, buf, flush));
11119 /* Linux wrapper to call common dhd_pno_get_gscan */
11121 dhd_dev_pno_get_gscan(struct net_device *dev, dhd_pno_gscan_cmd_cfg_t type,
11122 void *info, uint32 *len)
11124 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
11126 return (dhd_pno_get_gscan(&dhd->pub, type, info, len));
11129 /* Linux wrapper to call common dhd_wait_batch_results_complete */
11131 dhd_dev_wait_batch_results_complete(struct net_device *dev)
11133 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
11135 return (dhd_wait_batch_results_complete(&dhd->pub));
11138 /* Linux wrapper to call common dhd_pno_lock_batch_results */
11140 dhd_dev_pno_lock_access_batch_results(struct net_device *dev)
11142 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
11144 return (dhd_pno_lock_batch_results(&dhd->pub));
11146 /* Linux wrapper to call common dhd_pno_unlock_batch_results */
11148 dhd_dev_pno_unlock_access_batch_results(struct net_device *dev)
11150 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
11152 return (dhd_pno_unlock_batch_results(&dhd->pub));
11155 /* Linux wrapper to call common dhd_pno_initiate_gscan_request */
11157 dhd_dev_pno_run_gscan(struct net_device *dev, bool run, bool flush)
11159 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
11161 return (dhd_pno_initiate_gscan_request(&dhd->pub, run, flush));
11164 /* Linux wrapper to call common dhd_pno_enable_full_scan_result */
11166 dhd_dev_pno_enable_full_scan_result(struct net_device *dev, bool real_time_flag)
11168 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
11170 return (dhd_pno_enable_full_scan_result(&dhd->pub, real_time_flag));
11173 /* Linux wrapper to call common dhd_handle_swc_evt */
11175 dhd_dev_swc_scan_event(struct net_device *dev, const void *data, int *send_evt_bytes)
11177 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
11179 return (dhd_handle_swc_evt(&dhd->pub, data, send_evt_bytes));
11182 /* Linux wrapper to call common dhd_handle_hotlist_scan_evt */
11184 dhd_dev_hotlist_scan_event(struct net_device *dev,
11185 const void *data, int *send_evt_bytes, hotlist_type_t type)
11187 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
11189 return (dhd_handle_hotlist_scan_evt(&dhd->pub, data, send_evt_bytes, type));
11192 /* Linux wrapper to call common dhd_process_full_gscan_result */
11194 dhd_dev_process_full_gscan_result(struct net_device *dev,
11195 const void *data, int *send_evt_bytes)
11197 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
11199 return (dhd_process_full_gscan_result(&dhd->pub, data, send_evt_bytes));
11203 dhd_dev_gscan_hotlist_cache_cleanup(struct net_device *dev, hotlist_type_t type)
11205 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
11207 dhd_gscan_hotlist_cache_cleanup(&dhd->pub, type);
11213 dhd_dev_gscan_batch_cache_cleanup(struct net_device *dev)
11215 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
11217 return (dhd_gscan_batch_cache_cleanup(&dhd->pub));
11220 /* Linux wrapper to call common dhd_retreive_batch_scan_results */
11222 dhd_dev_retrieve_batch_scan(struct net_device *dev)
11224 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
11226 return (dhd_retreive_batch_scan_results(&dhd->pub));
11228 #endif /* GSCAN_SUPPORT */
11231 /* Linux wrapper to call common dhd_pno_set_cfg_gscan */
11233 dhd_dev_rtt_set_cfg(struct net_device *dev, void *buf)
11235 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
11237 return (dhd_rtt_set_cfg(&dhd->pub, buf));
11240 dhd_dev_rtt_cancel_cfg(struct net_device *dev, struct ether_addr *mac_list, int mac_cnt)
11242 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
11244 return (dhd_rtt_stop(&dhd->pub, mac_list, mac_cnt));
11247 dhd_dev_rtt_register_noti_callback(struct net_device *dev, void *ctx, dhd_rtt_compl_noti_fn noti_fn)
11249 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
11251 return (dhd_rtt_register_noti_callback(&dhd->pub, ctx, noti_fn));
11254 dhd_dev_rtt_unregister_noti_callback(struct net_device *dev, dhd_rtt_compl_noti_fn noti_fn)
11256 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
11258 return (dhd_rtt_unregister_noti_callback(&dhd->pub, noti_fn));
11262 dhd_dev_rtt_capability(struct net_device *dev, rtt_capabilities_t *capa)
11264 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
11266 return (dhd_rtt_capability(&dhd->pub, capa));
11269 #endif /* RTT_SUPPORT */
11271 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
11272 static void dhd_hang_process(void *dhd_info, void *event_info, u8 event)
11275 struct net_device *dev;
11277 dhd = (dhd_info_t *)dhd_info;
11278 dev = dhd->iflist[0]->net;
11281 #if defined(WL_WIRELESS_EXT)
11282 wl_iw_send_priv_event(dev, "HANG");
11284 #if defined(WL_CFG80211)
11285 wl_cfg80211_hang(dev, WLAN_REASON_UNSPECIFIED);
11290 #ifdef EXYNOS_PCIE_LINKDOWN_RECOVERY
11291 extern dhd_pub_t *link_recovery;
11292 void dhd_host_recover_link(void)
11294 DHD_ERROR(("****** %s ******\n", __FUNCTION__));
11295 link_recovery->hang_reason = HANG_REASON_PCIE_LINK_DOWN;
11296 dhd_bus_set_linkdown(link_recovery, TRUE);
11297 dhd_os_send_hang_message(link_recovery);
11299 EXPORT_SYMBOL(dhd_host_recover_link);
11300 #endif /* EXYNOS_PCIE_LINKDOWN_RECOVERY */
11302 int dhd_os_send_hang_message(dhd_pub_t *dhdp)
11306 if (!dhdp->hang_was_sent) {
11307 dhdp->hang_was_sent = 1;
11308 dhd_deferred_schedule_work(dhdp->info->dhd_deferred_wq, (void *)dhdp,
11309 DHD_WQ_WORK_HANG_MSG, dhd_hang_process, DHD_WORK_PRIORITY_HIGH);
11310 DHD_ERROR(("%s: Event HANG send up due to re=%d te=%d s=%d\n", __FUNCTION__,
11311 dhdp->rxcnt_timeout, dhdp->txcnt_timeout, dhdp->busstate));
11317 int net_os_send_hang_message(struct net_device *dev)
11319 dhd_info_t *dhd = DHD_DEV_INFO(dev);
11323 /* Report FW problem when enabled */
11324 if (dhd->pub.hang_report) {
11325 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
11326 ret = dhd_os_send_hang_message(&dhd->pub);
11328 ret = wl_cfg80211_hang(dev, WLAN_REASON_UNSPECIFIED);
11331 DHD_ERROR(("%s: FW HANG ignored (for testing purpose) and not sent up\n",
11333 /* Enforce bus down to stop any future traffic */
11334 dhd->pub.busstate = DHD_BUS_DOWN;
11340 int net_os_send_hang_message_reason(struct net_device *dev, const char *string_num)
11342 dhd_info_t *dhd = NULL;
11343 dhd_pub_t *dhdp = NULL;
11346 dhd = DHD_DEV_INFO(dev);
11351 if (!dhd || !dhdp) {
11355 reason = bcm_strtoul(string_num, NULL, 0);
11356 DHD_INFO(("%s: Enter, reason=0x%x\n", __FUNCTION__, reason));
11358 if ((reason <= HANG_REASON_MASK) || (reason >= HANG_REASON_MAX)) {
11362 dhdp->hang_reason = reason;
11364 return net_os_send_hang_message(dev);
11366 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27) && OEM_ANDROID */
11369 int dhd_net_wifi_platform_set_power(struct net_device *dev, bool on, unsigned long delay_msec)
11371 dhd_info_t *dhd = DHD_DEV_INFO(dev);
11372 return wifi_platform_set_power(dhd->adapter, on, delay_msec);
11375 bool dhd_force_country_change(struct net_device *dev)
11377 dhd_info_t *dhd = DHD_DEV_INFO(dev);
11379 if (dhd && dhd->pub.up)
11380 return dhd->pub.force_country_change;
11383 void dhd_get_customized_country_code(struct net_device *dev, char *country_iso_code,
11384 wl_country_t *cspec)
11386 dhd_info_t *dhd = DHD_DEV_INFO(dev);
11387 #ifdef CUSTOM_COUNTRY_CODE
11388 get_customized_country_code(dhd->adapter, country_iso_code, cspec,
11389 dhd->pub.dhd_cflags);
11391 get_customized_country_code(dhd->adapter, country_iso_code, cspec);
11392 #endif /* CUSTOM_COUNTRY_CODE */
11394 void dhd_bus_country_set(struct net_device *dev, wl_country_t *cspec, bool notify)
11396 dhd_info_t *dhd = DHD_DEV_INFO(dev);
11397 if (dhd && dhd->pub.up) {
11398 memcpy(&dhd->pub.dhd_cspec, cspec, sizeof(wl_country_t));
11400 wl_update_wiphybands(NULL, notify);
11405 void dhd_bus_band_set(struct net_device *dev, uint band)
11407 dhd_info_t *dhd = DHD_DEV_INFO(dev);
11408 if (dhd && dhd->pub.up) {
11410 wl_update_wiphybands(NULL, true);
11415 int dhd_net_set_fw_path(struct net_device *dev, char *fw)
11417 dhd_info_t *dhd = DHD_DEV_INFO(dev);
11419 if (!fw || fw[0] == '\0')
11422 strncpy(dhd->fw_path, fw, sizeof(dhd->fw_path) - 1);
11423 dhd->fw_path[sizeof(dhd->fw_path)-1] = '\0';
11425 #if defined(SOFTAP)
11426 if (strstr(fw, "apsta") != NULL) {
11427 DHD_INFO(("GOT APSTA FIRMWARE\n"));
11428 ap_fw_loaded = TRUE;
11430 DHD_INFO(("GOT STA FIRMWARE\n"));
11431 ap_fw_loaded = FALSE;
11437 void dhd_net_if_lock(struct net_device *dev)
11439 dhd_info_t *dhd = DHD_DEV_INFO(dev);
11440 dhd_net_if_lock_local(dhd);
11443 void dhd_net_if_unlock(struct net_device *dev)
11445 dhd_info_t *dhd = DHD_DEV_INFO(dev);
11446 dhd_net_if_unlock_local(dhd);
11449 static void dhd_net_if_lock_local(dhd_info_t *dhd)
11451 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
11453 mutex_lock(&dhd->dhd_net_if_mutex);
11457 static void dhd_net_if_unlock_local(dhd_info_t *dhd)
11459 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
11461 mutex_unlock(&dhd->dhd_net_if_mutex);
11465 static void dhd_suspend_lock(dhd_pub_t *pub)
11467 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
11468 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
11470 mutex_lock(&dhd->dhd_suspend_mutex);
11474 static void dhd_suspend_unlock(dhd_pub_t *pub)
11476 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25))
11477 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
11479 mutex_unlock(&dhd->dhd_suspend_mutex);
11483 unsigned long dhd_os_general_spin_lock(dhd_pub_t *pub)
11485 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
11486 unsigned long flags = 0;
11489 spin_lock_irqsave(&dhd->dhd_lock, flags);
11494 void dhd_os_general_spin_unlock(dhd_pub_t *pub, unsigned long flags)
11496 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
11499 spin_unlock_irqrestore(&dhd->dhd_lock, flags);
11502 /* Linux specific multipurpose spinlock API */
11504 dhd_os_spin_lock_init(osl_t *osh)
11506 /* Adding 4 bytes since the sizeof(spinlock_t) could be 0 */
11507 /* if CONFIG_SMP and CONFIG_DEBUG_SPINLOCK are not defined */
11508 /* and this results in kernel asserts in internal builds */
11509 spinlock_t * lock = MALLOC(osh, sizeof(spinlock_t) + 4);
11511 spin_lock_init(lock);
11512 return ((void *)lock);
11515 dhd_os_spin_lock_deinit(osl_t *osh, void *lock)
11518 MFREE(osh, lock, sizeof(spinlock_t) + 4);
11521 dhd_os_spin_lock(void *lock)
11523 unsigned long flags = 0;
11526 spin_lock_irqsave((spinlock_t *)lock, flags);
11531 dhd_os_spin_unlock(void *lock, unsigned long flags)
11534 spin_unlock_irqrestore((spinlock_t *)lock, flags);
11538 dhd_get_pend_8021x_cnt(dhd_info_t *dhd)
11540 return (atomic_read(&dhd->pend_8021x_cnt));
11543 #define MAX_WAIT_FOR_8021X_TX 100
11546 dhd_wait_pend8021x(struct net_device *dev)
11548 dhd_info_t *dhd = DHD_DEV_INFO(dev);
11549 int timeout = msecs_to_jiffies(10);
11550 int ntimes = MAX_WAIT_FOR_8021X_TX;
11551 int pend = dhd_get_pend_8021x_cnt(dhd);
11553 while (ntimes && pend) {
11555 set_current_state(TASK_INTERRUPTIBLE);
11556 DHD_PERIM_UNLOCK(&dhd->pub);
11557 schedule_timeout(timeout);
11558 DHD_PERIM_LOCK(&dhd->pub);
11559 set_current_state(TASK_RUNNING);
11562 pend = dhd_get_pend_8021x_cnt(dhd);
11566 atomic_set(&dhd->pend_8021x_cnt, 0);
11567 DHD_ERROR(("%s: TIMEOUT\n", __FUNCTION__));
11574 dhd_convert_memdump_type_to_str(uint32 type, char *buf)
11576 char *type_str = NULL;
11579 case DUMP_TYPE_RESUMED_ON_TIMEOUT:
11580 type_str = "resumed_on_timeout";
11582 case DUMP_TYPE_D3_ACK_TIMEOUT:
11583 type_str = "D3_ACK_timeout";
11585 case DUMP_TYPE_DONGLE_TRAP:
11586 type_str = "Dongle_Trap";
11588 case DUMP_TYPE_MEMORY_CORRUPTION:
11589 type_str = "Memory_Corruption";
11591 case DUMP_TYPE_PKTID_AUDIT_FAILURE:
11592 type_str = "PKTID_AUDIT_Fail";
11594 case DUMP_TYPE_SCAN_TIMEOUT:
11595 type_str = "SCAN_timeout";
11597 case DUMP_TYPE_SCAN_BUSY:
11598 type_str = "SCAN_Busy";
11600 case DUMP_TYPE_BY_SYSDUMP:
11601 type_str = "BY_SYSDUMP";
11603 case DUMP_TYPE_BY_LIVELOCK:
11604 type_str = "BY_LIVELOCK";
11606 case DUMP_TYPE_AP_LINKUP_FAILURE:
11607 type_str = "BY_AP_LINK_FAILURE";
11610 type_str = "Unknown_type";
11614 strncpy(buf, type_str, strlen(type_str));
11615 buf[strlen(type_str)] = 0;
11619 write_to_file(dhd_pub_t *dhd, uint8 *buf, int size)
11622 struct file *fp = NULL;
11623 mm_segment_t old_fs;
11625 char memdump_path[128];
11626 char memdump_type[32];
11627 struct timeval curtime;
11630 /* change to KERNEL_DS address limit */
11634 /* Init file name */
11635 memset(memdump_path, 0, sizeof(memdump_path));
11636 memset(memdump_type, 0, sizeof(memdump_type));
11637 do_gettimeofday(&curtime);
11638 dhd_convert_memdump_type_to_str(dhd->memdump_type, memdump_type);
11639 #ifdef CUSTOMER_HW4_DEBUG
11640 snprintf(memdump_path, sizeof(memdump_path), "%s_%s_%ld.%ld",
11641 DHD_COMMON_DUMP_PATH "mem_dump", memdump_type,
11642 (unsigned long)curtime.tv_sec, (unsigned long)curtime.tv_usec);
11643 file_mode = O_CREAT | O_WRONLY | O_SYNC;
11644 #elif defined(CUSTOMER_HW2)
11645 snprintf(memdump_path, sizeof(memdump_path), "%s_%s_%ld.%ld",
11646 "/data/misc/wifi/mem_dump", memdump_type,
11647 (unsigned long)curtime.tv_sec, (unsigned long)curtime.tv_usec);
11648 file_mode = O_CREAT | O_WRONLY | O_SYNC;
11650 snprintf(memdump_path, sizeof(memdump_path), "%s_%s_%ld.%ld",
11651 "/installmedia/mem_dump", memdump_type,
11652 (unsigned long)curtime.tv_sec, (unsigned long)curtime.tv_usec);
11653 /* Extra flags O_DIRECT and O_SYNC are required for Brix Android, as we are
11654 * calling BUG_ON immediately after collecting the socram dump.
11655 * So the file write operation should directly write the contents into the
11656 * file instead of caching it. O_TRUNC flag ensures that file will be re-written
11657 * instead of appending.
11659 file_mode = O_CREAT | O_WRONLY | O_DIRECT | O_SYNC | O_TRUNC;
11660 #endif /* CUSTOMER_HW4_DEBUG */
11662 /* print SOCRAM dump file path */
11663 DHD_ERROR(("%s: memdump_path = %s\n", __FUNCTION__, memdump_path));
11665 /* open file to write */
11666 fp = filp_open(memdump_path, file_mode, 0644);
11669 printf("%s: open file error, err = %d\n", __FUNCTION__, ret);
11673 /* Write buf to file */
11674 fp->f_op->write(fp, buf, size, &pos);
11677 /* close file before return */
11679 filp_close(fp, current->files);
11681 /* restore previous address limit */
11684 /* free buf before return */
11685 #if defined(CONFIG_DHD_USE_STATIC_BUF) && defined(DHD_USE_STATIC_MEMDUMP)
11686 DHD_OS_PREFREE(dhd, buf, size);
11688 MFREE(dhd->osh, buf, size);
11689 #endif /* CONFIG_DHD_USE_STATIC_BUF && DHD_USE_STATIC_MEMDUMP */
11693 #endif /* DHD_DEBUG */
11695 int dhd_os_wake_lock_timeout(dhd_pub_t *pub)
11697 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
11698 unsigned long flags;
11702 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
11703 ret = dhd->wakelock_rx_timeout_enable > dhd->wakelock_ctrl_timeout_enable ?
11704 dhd->wakelock_rx_timeout_enable : dhd->wakelock_ctrl_timeout_enable;
11705 #ifdef CONFIG_HAS_WAKELOCK
11706 if (dhd->wakelock_rx_timeout_enable)
11707 wake_lock_timeout(&dhd->wl_rxwake,
11708 msecs_to_jiffies(dhd->wakelock_rx_timeout_enable));
11709 if (dhd->wakelock_ctrl_timeout_enable)
11710 wake_lock_timeout(&dhd->wl_ctrlwake,
11711 msecs_to_jiffies(dhd->wakelock_ctrl_timeout_enable));
11713 dhd->wakelock_rx_timeout_enable = 0;
11714 dhd->wakelock_ctrl_timeout_enable = 0;
11715 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
11720 int net_os_wake_lock_timeout(struct net_device *dev)
11722 dhd_info_t *dhd = DHD_DEV_INFO(dev);
11726 ret = dhd_os_wake_lock_timeout(&dhd->pub);
11730 int dhd_os_wake_lock_rx_timeout_enable(dhd_pub_t *pub, int val)
11732 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
11733 unsigned long flags;
11736 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
11737 if (val > dhd->wakelock_rx_timeout_enable)
11738 dhd->wakelock_rx_timeout_enable = val;
11739 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
11744 int dhd_os_wake_lock_ctrl_timeout_enable(dhd_pub_t *pub, int val)
11746 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
11747 unsigned long flags;
11750 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
11751 if (val > dhd->wakelock_ctrl_timeout_enable)
11752 dhd->wakelock_ctrl_timeout_enable = val;
11753 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
11758 int dhd_os_wake_lock_ctrl_timeout_cancel(dhd_pub_t *pub)
11760 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
11761 unsigned long flags;
11764 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
11765 dhd->wakelock_ctrl_timeout_enable = 0;
11766 #ifdef CONFIG_HAS_WAKELOCK
11767 if (wake_lock_active(&dhd->wl_ctrlwake))
11768 wake_unlock(&dhd->wl_ctrlwake);
11770 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
11775 int net_os_wake_lock_rx_timeout_enable(struct net_device *dev, int val)
11777 dhd_info_t *dhd = DHD_DEV_INFO(dev);
11781 ret = dhd_os_wake_lock_rx_timeout_enable(&dhd->pub, val);
11785 int net_os_wake_lock_ctrl_timeout_enable(struct net_device *dev, int val)
11787 dhd_info_t *dhd = DHD_DEV_INFO(dev);
11791 ret = dhd_os_wake_lock_ctrl_timeout_enable(&dhd->pub, val);
11796 #if defined(DHD_TRACE_WAKE_LOCK)
11797 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
11798 #include <linux/hashtable.h>
11800 #include <linux/hash.h>
11801 #endif /* KERNEL_VER >= KERNEL_VERSION(3, 7, 0) */
11804 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
11805 /* Define 2^5 = 32 bucket size hash table */
11806 DEFINE_HASHTABLE(wklock_history, 5);
11808 /* Define 2^5 = 32 bucket size hash table */
11809 struct hlist_head wklock_history[32] = { [0 ... 31] = HLIST_HEAD_INIT };
11810 #endif /* KERNEL_VER >= KERNEL_VERSION(3, 7, 0) */
11812 int trace_wklock_onoff = 1;
11814 typedef enum dhd_wklock_type {
11821 struct wk_trace_record {
11822 unsigned long addr; /* Address of the instruction */
11823 dhd_wklock_t lock_type; /* lock_type */
11824 unsigned long long counter; /* counter information */
11825 struct hlist_node wklock_node; /* hash node */
11829 static struct wk_trace_record *find_wklock_entry(unsigned long addr)
11831 struct wk_trace_record *wklock_info;
11832 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
11833 hash_for_each_possible(wklock_history, wklock_info, wklock_node, addr)
11835 struct hlist_node *entry;
11836 int index = hash_long(addr, ilog2(ARRAY_SIZE(wklock_history)));
11837 hlist_for_each_entry(wklock_info, entry, &wklock_history[index], wklock_node)
11838 #endif /* KERNEL_VER >= KERNEL_VERSION(3, 7, 0) */
11840 if (wklock_info->addr == addr) {
11841 return wklock_info;
11847 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
11848 #define HASH_ADD(hashtable, node, key) \
11850 hash_add(hashtable, node, key); \
11853 #define HASH_ADD(hashtable, node, key) \
11855 int index = hash_long(key, ilog2(ARRAY_SIZE(hashtable))); \
11856 hlist_add_head(node, &hashtable[index]); \
11858 #endif /* KERNEL_VER < KERNEL_VERSION(3, 7, 0) */
11860 #define STORE_WKLOCK_RECORD(wklock_type) \
11862 struct wk_trace_record *wklock_info = NULL; \
11863 unsigned long func_addr = (unsigned long)__builtin_return_address(0); \
11864 wklock_info = find_wklock_entry(func_addr); \
11865 if (wklock_info) { \
11866 if (wklock_type == DHD_WAIVE_LOCK || wklock_type == DHD_RESTORE_LOCK) { \
11867 wklock_info->counter = dhd->wakelock_counter; \
11869 wklock_info->counter++; \
11872 wklock_info = kzalloc(sizeof(*wklock_info), GFP_ATOMIC); \
11873 if (!wklock_info) {\
11874 printk("Can't allocate wk_trace_record \n"); \
11876 wklock_info->addr = func_addr; \
11877 wklock_info->lock_type = wklock_type; \
11878 if (wklock_type == DHD_WAIVE_LOCK || \
11879 wklock_type == DHD_RESTORE_LOCK) { \
11880 wklock_info->counter = dhd->wakelock_counter; \
11882 wklock_info->counter++; \
11884 HASH_ADD(wklock_history, &wklock_info->wklock_node, func_addr); \
11889 static inline void dhd_wk_lock_rec_dump(void)
11892 struct wk_trace_record *wklock_info;
11894 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
11895 hash_for_each(wklock_history, bkt, wklock_info, wklock_node)
11897 struct hlist_node *entry = NULL;
11898 int max_index = ARRAY_SIZE(wklock_history);
11899 for (bkt = 0; bkt < max_index; bkt++)
11900 hlist_for_each_entry(wklock_info, entry, &wklock_history[bkt], wklock_node)
11901 #endif /* KERNEL_VER >= KERNEL_VERSION(3, 7, 0) */
11903 switch (wklock_info->lock_type) {
11904 case DHD_WAKE_LOCK:
11905 DHD_ERROR(("wakelock lock : %pS lock_counter : %llu\n",
11906 (void *)wklock_info->addr, wklock_info->counter));
11908 case DHD_WAKE_UNLOCK:
11909 DHD_ERROR(("wakelock unlock : %pS, unlock_counter : %llu\n",
11910 (void *)wklock_info->addr, wklock_info->counter));
11912 case DHD_WAIVE_LOCK:
11913 DHD_ERROR(("wakelock waive : %pS before_waive : %llu\n",
11914 (void *)wklock_info->addr, wklock_info->counter));
11916 case DHD_RESTORE_LOCK:
11917 DHD_ERROR(("wakelock restore : %pS, after_waive : %llu\n",
11918 (void *)wklock_info->addr, wklock_info->counter));
11924 static void dhd_wk_lock_trace_init(struct dhd_info *dhd)
11926 unsigned long flags;
11927 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
11929 #endif /* KERNEL_VER >= KERNEL_VERSION(3, 7, 0) */
11931 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
11932 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
11933 hash_init(wklock_history);
11935 for (i = 0; i < ARRAY_SIZE(wklock_history); i++)
11936 INIT_HLIST_HEAD(&wklock_history[i]);
11937 #endif /* KERNEL_VER >= KERNEL_VERSION(3, 7, 0) */
11938 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
11941 static void dhd_wk_lock_trace_deinit(struct dhd_info *dhd)
11944 struct wk_trace_record *wklock_info;
11945 struct hlist_node *tmp;
11946 unsigned long flags;
11947 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0))
11948 struct hlist_node *entry = NULL;
11949 int max_index = ARRAY_SIZE(wklock_history);
11950 #endif /* KERNEL_VER >= KERNEL_VERSION(3, 7, 0) */
11952 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
11953 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
11954 hash_for_each_safe(wklock_history, bkt, tmp, wklock_info, wklock_node)
11956 for (bkt = 0; bkt < max_index; bkt++)
11957 hlist_for_each_entry_safe(wklock_info, entry, tmp,
11958 &wklock_history[bkt], wklock_node)
11959 #endif /* KERNEL_VER >= KERNEL_VERSION(3, 7, 0)) */
11961 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
11962 hash_del(&wklock_info->wklock_node);
11964 hlist_del_init(&wklock_info->wklock_node);
11965 #endif /* KERNEL_VER >= KERNEL_VERSION(3, 7, 0)) */
11966 kfree(wklock_info);
11968 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
11971 void dhd_wk_lock_stats_dump(dhd_pub_t *dhdp)
11973 dhd_info_t *dhd = (dhd_info_t *)(dhdp->info);
11974 unsigned long flags;
11976 DHD_ERROR((KERN_ERR"DHD Printing wl_wake Lock/Unlock Record \r\n"));
11977 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
11978 dhd_wk_lock_rec_dump();
11979 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
11980 DHD_ERROR((KERN_ERR"Event wakelock counter %u\n", dhd->wakelock_event_counter));
11983 #define STORE_WKLOCK_RECORD(wklock_type)
11984 #endif /* ! DHD_TRACE_WAKE_LOCK */
11986 int dhd_os_wake_lock(dhd_pub_t *pub)
11988 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
11989 unsigned long flags;
11993 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
11994 if (dhd->wakelock_counter == 0 && !dhd->waive_wakelock) {
11995 #ifdef CONFIG_HAS_WAKELOCK
11996 wake_lock(&dhd->wl_wifi);
11997 #elif defined(BCMSDIO) && (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36))
11998 dhd_bus_dev_pm_stay_awake(pub);
12001 #ifdef DHD_TRACE_WAKE_LOCK
12002 if (trace_wklock_onoff) {
12003 STORE_WKLOCK_RECORD(DHD_WAKE_LOCK);
12005 #endif /* DHD_TRACE_WAKE_LOCK */
12006 dhd->wakelock_counter++;
12007 ret = dhd->wakelock_counter;
12008 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
12014 int dhd_event_wake_lock(dhd_pub_t *pub)
12016 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
12017 unsigned long flags;
12021 spin_lock_irqsave(&dhd->wakelock_evt_spinlock, flags);
12022 if (dhd->wakelock_event_counter == 0) {
12023 #ifdef CONFIG_HAS_WAKELOCK
12024 wake_lock(&dhd->wl_evtwake);
12025 #elif defined(BCMSDIO) && (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36))
12026 dhd_bus_dev_pm_stay_awake(pub);
12029 dhd->wakelock_event_counter++;
12030 ret = dhd->wakelock_event_counter;
12031 spin_unlock_irqrestore(&dhd->wakelock_evt_spinlock, flags);
12037 int net_os_wake_lock(struct net_device *dev)
12039 dhd_info_t *dhd = DHD_DEV_INFO(dev);
12043 ret = dhd_os_wake_lock(&dhd->pub);
12047 int dhd_os_wake_unlock(dhd_pub_t *pub)
12049 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
12050 unsigned long flags;
12053 dhd_os_wake_lock_timeout(pub);
12055 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
12057 if (dhd->wakelock_counter > 0) {
12058 dhd->wakelock_counter--;
12059 #ifdef DHD_TRACE_WAKE_LOCK
12060 if (trace_wklock_onoff) {
12061 STORE_WKLOCK_RECORD(DHD_WAKE_UNLOCK);
12063 #endif /* DHD_TRACE_WAKE_LOCK */
12064 if (dhd->wakelock_counter == 0 && !dhd->waive_wakelock) {
12065 #ifdef CONFIG_HAS_WAKELOCK
12066 wake_unlock(&dhd->wl_wifi);
12067 #elif defined(BCMSDIO) && (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36))
12068 dhd_bus_dev_pm_relax(pub);
12071 ret = dhd->wakelock_counter;
12073 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
12078 int dhd_event_wake_unlock(dhd_pub_t *pub)
12080 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
12081 unsigned long flags;
12085 spin_lock_irqsave(&dhd->wakelock_evt_spinlock, flags);
12087 if (dhd->wakelock_event_counter > 0) {
12088 dhd->wakelock_event_counter--;
12089 if (dhd->wakelock_event_counter == 0) {
12090 #ifdef CONFIG_HAS_WAKELOCK
12091 wake_unlock(&dhd->wl_evtwake);
12092 #elif defined(BCMSDIO) && (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36))
12093 dhd_bus_dev_pm_relax(pub);
12096 ret = dhd->wakelock_event_counter;
12098 spin_unlock_irqrestore(&dhd->wakelock_evt_spinlock, flags);
12103 int dhd_os_check_wakelock(dhd_pub_t *pub)
12105 #if defined(CONFIG_HAS_WAKELOCK) || (defined(BCMSDIO) && (LINUX_VERSION_CODE > \
12106 KERNEL_VERSION(2, 6, 36)))
12111 dhd = (dhd_info_t *)(pub->info);
12112 #endif /* CONFIG_HAS_WAKELOCK || BCMSDIO */
12114 #ifdef CONFIG_HAS_WAKELOCK
12115 /* Indicate to the SD Host to avoid going to suspend if internal locks are up */
12116 if (dhd && (wake_lock_active(&dhd->wl_wifi) ||
12117 (wake_lock_active(&dhd->wl_wdwake))))
12119 #elif defined(BCMSDIO) && (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36))
12120 if (dhd && (dhd->wakelock_counter > 0) && dhd_bus_dev_pm_enabled(pub))
12127 dhd_os_check_wakelock_all(dhd_pub_t *pub)
12129 #ifdef CONFIG_HAS_WAKELOCK
12130 int l1, l2, l3, l4, l7;
12131 int l5 = 0, l6 = 0;
12132 int c, lock_active;
12133 #endif /* CONFIG_HAS_WAKELOCK */
12134 #if defined(CONFIG_HAS_WAKELOCK) || (defined(BCMSDIO) && (LINUX_VERSION_CODE > \
12135 KERNEL_VERSION(2, 6, 36)))
12141 dhd = (dhd_info_t *)(pub->info);
12145 #endif /* CONFIG_HAS_WAKELOCK || BCMSDIO */
12147 #ifdef CONFIG_HAS_WAKELOCK
12148 c = dhd->wakelock_counter;
12149 l1 = wake_lock_active(&dhd->wl_wifi);
12150 l2 = wake_lock_active(&dhd->wl_wdwake);
12151 l3 = wake_lock_active(&dhd->wl_rxwake);
12152 l4 = wake_lock_active(&dhd->wl_ctrlwake);
12153 #ifdef BCMPCIE_OOB_HOST_WAKE
12154 l5 = wake_lock_active(&dhd->wl_intrwake);
12155 #endif /* BCMPCIE_OOB_HOST_WAKE */
12156 #ifdef DHD_USE_SCAN_WAKELOCK
12157 l6 = wake_lock_active(&dhd->wl_scanwake);
12158 #endif /* DHD_USE_SCAN_WAKELOCK */
12159 l7 = wake_lock_active(&dhd->wl_evtwake);
12160 lock_active = (l1 || l2 || l3 || l4 || l5 || l6 || l7);
12162 /* Indicate to the Host to avoid going to suspend if internal locks are up */
12163 if (dhd && lock_active) {
12164 DHD_ERROR(("%s wakelock c-%d wl-%d wd-%d rx-%d "
12165 "ctl-%d intr-%d scan-%d evt-%d\n",
12166 __FUNCTION__, c, l1, l2, l3, l4, l5, l6, l7));
12169 #elif defined(BCMSDIO) && (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36))
12170 if (dhd && (dhd->wakelock_counter > 0) && dhd_bus_dev_pm_enabled(pub)) {
12173 #endif /* CONFIG_HAS_WAKELOCK */
12177 int net_os_wake_unlock(struct net_device *dev)
12179 dhd_info_t *dhd = DHD_DEV_INFO(dev);
12183 ret = dhd_os_wake_unlock(&dhd->pub);
12187 int dhd_os_wd_wake_lock(dhd_pub_t *pub)
12189 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
12190 unsigned long flags;
12194 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
12195 #ifdef CONFIG_HAS_WAKELOCK
12196 /* if wakelock_wd_counter was never used : lock it at once */
12197 if (!dhd->wakelock_wd_counter)
12198 wake_lock(&dhd->wl_wdwake);
12200 dhd->wakelock_wd_counter++;
12201 ret = dhd->wakelock_wd_counter;
12202 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
12207 int dhd_os_wd_wake_unlock(dhd_pub_t *pub)
12209 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
12210 unsigned long flags;
12214 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
12215 if (dhd->wakelock_wd_counter) {
12216 dhd->wakelock_wd_counter = 0;
12217 #ifdef CONFIG_HAS_WAKELOCK
12218 wake_unlock(&dhd->wl_wdwake);
12221 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
12226 #ifdef BCMPCIE_OOB_HOST_WAKE
12228 dhd_os_oob_irq_wake_lock_timeout(dhd_pub_t *pub, int val)
12230 #ifdef CONFIG_HAS_WAKELOCK
12231 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
12234 wake_lock_timeout(&dhd->wl_intrwake, msecs_to_jiffies(val));
12236 #endif /* CONFIG_HAS_WAKELOCK */
12240 dhd_os_oob_irq_wake_unlock(dhd_pub_t *pub)
12242 #ifdef CONFIG_HAS_WAKELOCK
12243 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
12246 /* if wl_intrwake is active, unlock it */
12247 if (wake_lock_active(&dhd->wl_intrwake)) {
12248 wake_unlock(&dhd->wl_intrwake);
12251 #endif /* CONFIG_HAS_WAKELOCK */
12253 #endif /* BCMPCIE_OOB_HOST_WAKE */
12255 #ifdef DHD_USE_SCAN_WAKELOCK
12257 dhd_os_scan_wake_lock_timeout(dhd_pub_t *pub, int val)
12259 #ifdef CONFIG_HAS_WAKELOCK
12260 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
12263 wake_lock_timeout(&dhd->wl_scanwake, msecs_to_jiffies(val));
12265 #endif /* CONFIG_HAS_WAKELOCK */
12269 dhd_os_scan_wake_unlock(dhd_pub_t *pub)
12271 #ifdef CONFIG_HAS_WAKELOCK
12272 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
12275 /* if wl_scanwake is active, unlock it */
12276 if (wake_lock_active(&dhd->wl_scanwake)) {
12277 wake_unlock(&dhd->wl_scanwake);
12280 #endif /* CONFIG_HAS_WAKELOCK */
12282 #endif /* DHD_USE_SCAN_WAKELOCK */
12284 /* waive wakelocks for operations such as IOVARs in suspend function, must be closed
12285 * by a paired function call to dhd_wakelock_restore. returns current wakelock counter
12287 int dhd_os_wake_lock_waive(dhd_pub_t *pub)
12289 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
12290 unsigned long flags;
12294 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
12296 /* dhd_wakelock_waive/dhd_wakelock_restore must be paired */
12297 if (dhd->waive_wakelock == FALSE) {
12298 #ifdef DHD_TRACE_WAKE_LOCK
12299 if (trace_wklock_onoff) {
12300 STORE_WKLOCK_RECORD(DHD_WAIVE_LOCK);
12302 #endif /* DHD_TRACE_WAKE_LOCK */
12303 /* record current lock status */
12304 dhd->wakelock_before_waive = dhd->wakelock_counter;
12305 dhd->waive_wakelock = TRUE;
12307 ret = dhd->wakelock_wd_counter;
12308 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
12313 int dhd_os_wake_lock_restore(dhd_pub_t *pub)
12315 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
12316 unsigned long flags;
12322 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
12324 /* dhd_wakelock_waive/dhd_wakelock_restore must be paired */
12325 if (!dhd->waive_wakelock)
12328 dhd->waive_wakelock = FALSE;
12329 /* if somebody else acquires wakelock between dhd_wakelock_waive/dhd_wakelock_restore,
12330 * we need to make it up by calling wake_lock or pm_stay_awake. or if somebody releases
12331 * the lock in between, do the same by calling wake_unlock or pm_relax
12333 #ifdef DHD_TRACE_WAKE_LOCK
12334 if (trace_wklock_onoff) {
12335 STORE_WKLOCK_RECORD(DHD_RESTORE_LOCK);
12337 #endif /* DHD_TRACE_WAKE_LOCK */
12339 if (dhd->wakelock_before_waive == 0 && dhd->wakelock_counter > 0) {
12340 #ifdef CONFIG_HAS_WAKELOCK
12341 wake_lock(&dhd->wl_wifi);
12342 #elif defined(BCMSDIO) && (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36))
12343 dhd_bus_dev_pm_stay_awake(&dhd->pub);
12345 } else if (dhd->wakelock_before_waive > 0 && dhd->wakelock_counter == 0) {
12346 #ifdef CONFIG_HAS_WAKELOCK
12347 wake_unlock(&dhd->wl_wifi);
12348 #elif defined(BCMSDIO) && (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36))
12349 dhd_bus_dev_pm_relax(&dhd->pub);
12352 dhd->wakelock_before_waive = 0;
12354 ret = dhd->wakelock_wd_counter;
12355 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
12359 void dhd_os_wake_lock_init(struct dhd_info *dhd)
12361 DHD_TRACE(("%s: initialize wake_lock_counters\n", __FUNCTION__));
12362 dhd->wakelock_event_counter = 0;
12363 dhd->wakelock_counter = 0;
12364 dhd->wakelock_rx_timeout_enable = 0;
12365 dhd->wakelock_ctrl_timeout_enable = 0;
12366 #ifdef CONFIG_HAS_WAKELOCK
12367 wake_lock_init(&dhd->wl_wifi, WAKE_LOCK_SUSPEND, "wlan_wake");
12368 wake_lock_init(&dhd->wl_rxwake, WAKE_LOCK_SUSPEND, "wlan_rx_wake");
12369 wake_lock_init(&dhd->wl_ctrlwake, WAKE_LOCK_SUSPEND, "wlan_ctrl_wake");
12370 wake_lock_init(&dhd->wl_evtwake, WAKE_LOCK_SUSPEND, "wlan_evt_wake");
12371 #ifdef BCMPCIE_OOB_HOST_WAKE
12372 wake_lock_init(&dhd->wl_intrwake, WAKE_LOCK_SUSPEND, "wlan_oob_irq_wake");
12373 #endif /* BCMPCIE_OOB_HOST_WAKE */
12374 #ifdef DHD_USE_SCAN_WAKELOCK
12375 wake_lock_init(&dhd->wl_scanwake, WAKE_LOCK_SUSPEND, "wlan_scan_wake");
12376 #endif /* DHD_USE_SCAN_WAKELOCK */
12377 #endif /* CONFIG_HAS_WAKELOCK */
12378 #ifdef DHD_TRACE_WAKE_LOCK
12379 dhd_wk_lock_trace_init(dhd);
12380 #endif /* DHD_TRACE_WAKE_LOCK */
12383 void dhd_os_wake_lock_destroy(struct dhd_info *dhd)
12385 DHD_TRACE(("%s: deinit wake_lock_counters\n", __FUNCTION__));
12386 #ifdef CONFIG_HAS_WAKELOCK
12387 dhd->wakelock_event_counter = 0;
12388 dhd->wakelock_counter = 0;
12389 dhd->wakelock_rx_timeout_enable = 0;
12390 dhd->wakelock_ctrl_timeout_enable = 0;
12391 wake_lock_destroy(&dhd->wl_wifi);
12392 wake_lock_destroy(&dhd->wl_rxwake);
12393 wake_lock_destroy(&dhd->wl_ctrlwake);
12394 wake_lock_destroy(&dhd->wl_evtwake);
12395 #ifdef BCMPCIE_OOB_HOST_WAKE
12396 wake_lock_destroy(&dhd->wl_intrwake);
12397 #endif /* BCMPCIE_OOB_HOST_WAKE */
12398 #ifdef DHD_USE_SCAN_WAKELOCK
12399 wake_lock_destroy(&dhd->wl_scanwake);
12400 #endif /* DHD_USE_SCAN_WAKELOCK */
12401 #ifdef DHD_TRACE_WAKE_LOCK
12402 dhd_wk_lock_trace_deinit(dhd);
12403 #endif /* DHD_TRACE_WAKE_LOCK */
12404 #endif /* CONFIG_HAS_WAKELOCK */
12407 bool dhd_os_check_if_up(dhd_pub_t *pub)
12414 /* function to collect firmware, chip id and chip version info */
12415 void dhd_set_version_info(dhd_pub_t *dhdp, char *fw)
12419 i = snprintf(info_string, sizeof(info_string),
12420 " Driver: %s\n Firmware: %s ", EPI_VERSION_STR, fw);
12421 printf("%s\n", info_string);
12426 i = snprintf(&info_string[i], sizeof(info_string) - i,
12427 "\n Chip: %x Rev %x Pkg %x", dhd_bus_chip_id(dhdp),
12428 dhd_bus_chiprev_id(dhdp), dhd_bus_chippkg_id(dhdp));
12431 int dhd_ioctl_entry_local(struct net_device *net, wl_ioctl_t *ioc, int cmd)
12435 dhd_info_t *dhd = NULL;
12437 if (!net || !DEV_PRIV(net)) {
12438 DHD_ERROR(("%s invalid parameter\n", __FUNCTION__));
12442 dhd = DHD_DEV_INFO(net);
12446 ifidx = dhd_net2idx(dhd, net);
12447 if (ifidx == DHD_BAD_IF) {
12448 DHD_ERROR(("%s bad ifidx\n", __FUNCTION__));
12452 DHD_OS_WAKE_LOCK(&dhd->pub);
12453 DHD_PERIM_LOCK(&dhd->pub);
12455 ret = dhd_wl_ioctl(&dhd->pub, ifidx, ioc, ioc->buf, ioc->len);
12456 dhd_check_hang(net, &dhd->pub, ret);
12458 DHD_PERIM_UNLOCK(&dhd->pub);
12459 DHD_OS_WAKE_UNLOCK(&dhd->pub);
12464 bool dhd_os_check_hang(dhd_pub_t *dhdp, int ifidx, int ret)
12466 struct net_device *net;
12468 net = dhd_idx2net(dhdp, ifidx);
12470 DHD_ERROR(("%s : Invalid index : %d\n", __FUNCTION__, ifidx));
12474 return dhd_check_hang(net, dhdp, ret);
12477 /* Return instance */
12478 int dhd_get_instance(dhd_pub_t *dhdp)
12480 return dhdp->info->unit;
12484 #ifdef PROP_TXSTATUS
12486 void dhd_wlfc_plat_init(void *dhd)
12488 #ifdef USE_DYNAMIC_F2_BLKSIZE
12489 dhdsdio_func_blocksize((dhd_pub_t *)dhd, 2, DYNAMIC_F2_BLKSIZE_FOR_NONLEGACY);
12490 #endif /* USE_DYNAMIC_F2_BLKSIZE */
12494 void dhd_wlfc_plat_deinit(void *dhd)
12496 #ifdef USE_DYNAMIC_F2_BLKSIZE
12497 dhdsdio_func_blocksize((dhd_pub_t *)dhd, 2, sd_f2_blocksize);
12498 #endif /* USE_DYNAMIC_F2_BLKSIZE */
12502 bool dhd_wlfc_skip_fc(void)
12504 #ifdef SKIP_WLFC_ON_CONCURRENT
12507 /* enable flow control in vsdb mode */
12508 return !(wl_cfg80211_is_concurrent_mode());
12510 return TRUE; /* skip flow control */
12511 #endif /* WL_CFG80211 */
12515 #endif /* SKIP_WLFC_ON_CONCURRENT */
12517 #endif /* PROP_TXSTATUS */
12520 #include <linux/debugfs.h>
12522 typedef struct dhd_dbgfs {
12523 struct dentry *debugfs_dir;
12524 struct dentry *debugfs_mem;
12529 dhd_dbgfs_t g_dbgfs;
12531 extern uint32 dhd_readregl(void *bp, uint32 addr);
12532 extern uint32 dhd_writeregl(void *bp, uint32 addr, uint32 data);
12535 dhd_dbg_state_open(struct inode *inode, struct file *file)
12537 file->private_data = inode->i_private;
12542 dhd_dbg_state_read(struct file *file, char __user *ubuf,
12543 size_t count, loff_t *ppos)
12547 loff_t pos = *ppos;
12552 if (pos >= g_dbgfs.size || !count)
12554 if (count > g_dbgfs.size - pos)
12555 count = g_dbgfs.size - pos;
12557 /* Basically enforce aligned 4 byte reads. It's up to the user to work out the details */
12558 tmp = dhd_readregl(g_dbgfs.dhdp->bus, file->f_pos & (~3));
12560 ret = copy_to_user(ubuf, &tmp, 4);
12565 *ppos = pos + count;
12573 dhd_debugfs_write(struct file *file, const char __user *ubuf, size_t count, loff_t *ppos)
12575 loff_t pos = *ppos;
12581 if (pos >= g_dbgfs.size || !count)
12583 if (count > g_dbgfs.size - pos)
12584 count = g_dbgfs.size - pos;
12586 ret = copy_from_user(&buf, ubuf, sizeof(uint32));
12590 /* Basically enforce aligned 4 byte writes. It's up to the user to work out the details */
12591 dhd_writeregl(g_dbgfs.dhdp->bus, file->f_pos & (~3), buf);
12598 dhd_debugfs_lseek(struct file *file, loff_t off, int whence)
12607 pos = file->f_pos + off;
12610 pos = g_dbgfs.size - off;
12612 return (pos < 0 || pos > g_dbgfs.size) ? -EINVAL : (file->f_pos = pos);
12615 static const struct file_operations dhd_dbg_state_ops = {
12616 .read = dhd_dbg_state_read,
12617 .write = dhd_debugfs_write,
12618 .open = dhd_dbg_state_open,
12619 .llseek = dhd_debugfs_lseek
12622 static void dhd_dbg_create(void)
12624 if (g_dbgfs.debugfs_dir) {
12625 g_dbgfs.debugfs_mem = debugfs_create_file("mem", 0644, g_dbgfs.debugfs_dir,
12626 NULL, &dhd_dbg_state_ops);
12630 void dhd_dbg_init(dhd_pub_t *dhdp)
12632 g_dbgfs.dhdp = dhdp;
12633 g_dbgfs.size = 0x20000000; /* Allow access to various cores regs */
12635 g_dbgfs.debugfs_dir = debugfs_create_dir("dhd", 0);
12636 if (IS_ERR(g_dbgfs.debugfs_dir)) {
12637 g_dbgfs.debugfs_dir = NULL;
12646 void dhd_dbg_remove(void)
12648 debugfs_remove(g_dbgfs.debugfs_mem);
12649 debugfs_remove(g_dbgfs.debugfs_dir);
12651 bzero((unsigned char *) &g_dbgfs, sizeof(g_dbgfs));
12653 #endif /* BCMDBGFS */
12655 #ifdef WLMEDIA_HTSF
12658 void dhd_htsf_addtxts(dhd_pub_t *dhdp, void *pktbuf)
12660 dhd_info_t *dhd = (dhd_info_t *)(dhdp->info);
12661 struct sk_buff *skb;
12663 uint16 dport = 0, oldmagic = 0xACAC;
12667 /* timestamp packet */
12669 p1 = (char*) PKTDATA(dhdp->osh, pktbuf);
12671 if (PKTLEN(dhdp->osh, pktbuf) > HTSF_MINLEN) {
12672 /* memcpy(&proto, p1+26, 4); */
12673 memcpy(&dport, p1+40, 2);
12674 /* proto = ((ntoh32(proto))>> 16) & 0xFF; */
12675 dport = ntoh16(dport);
12678 /* timestamp only if icmp or udb iperf with port 5555 */
12679 /* if (proto == 17 && dport == tsport) { */
12680 if (dport >= tsport && dport <= tsport + 20) {
12682 skb = (struct sk_buff *) pktbuf;
12684 htsf = dhd_get_htsf(dhd, 0);
12685 memset(skb->data + 44, 0, 2); /* clear checksum */
12686 memcpy(skb->data+82, &oldmagic, 2);
12687 memcpy(skb->data+84, &htsf, 4);
12689 memset(&ts, 0, sizeof(htsfts_t));
12690 ts.magic = HTSFMAGIC;
12691 ts.prio = PKTPRIO(pktbuf);
12692 ts.seqnum = htsf_seqnum++;
12693 ts.c10 = get_cycles();
12695 ts.endmagic = HTSFENDMAGIC;
12697 memcpy(skb->data + HTSF_HOSTOFFSET, &ts, sizeof(ts));
12701 static void dhd_dump_htsfhisto(histo_t *his, char *s)
12703 int pktcnt = 0, curval = 0, i;
12704 for (i = 0; i < (NUMBIN-2); i++) {
12706 printf("%d ", his->bin[i]);
12707 pktcnt += his->bin[i];
12709 printf(" max: %d TotPkt: %d neg: %d [%s]\n", his->bin[NUMBIN-2], pktcnt,
12710 his->bin[NUMBIN-1], s);
12714 void sorttobin(int value, histo_t *histo)
12719 histo->bin[NUMBIN-1]++;
12722 if (value > histo->bin[NUMBIN-2]) /* store the max value */
12723 histo->bin[NUMBIN-2] = value;
12725 for (i = 0; i < (NUMBIN-2); i++) {
12726 binval += 500; /* 500m s bins */
12727 if (value <= binval) {
12732 histo->bin[NUMBIN-3]++;
12736 void dhd_htsf_addrxts(dhd_pub_t *dhdp, void *pktbuf)
12738 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
12739 struct sk_buff *skb;
12742 int d1, d2, d3, end2end;
12746 skb = PKTTONATIVE(dhdp->osh, pktbuf);
12747 p1 = (char*)PKTDATA(dhdp->osh, pktbuf);
12749 if (PKTLEN(osh, pktbuf) > HTSF_MINLEN) {
12750 memcpy(&old_magic, p1+78, 2);
12751 htsf_ts = (htsfts_t*) (p1 + HTSF_HOSTOFFSET - 4);
12755 if (htsf_ts->magic == HTSFMAGIC) {
12756 htsf_ts->tE0 = dhd_get_htsf(dhd, 0);
12757 htsf_ts->cE0 = get_cycles();
12760 if (old_magic == 0xACAC) {
12763 htsf = dhd_get_htsf(dhd, 0);
12764 memcpy(skb->data+92, &htsf, sizeof(uint32));
12766 memcpy(&ts[tsidx].t1, skb->data+80, 16);
12768 d1 = ts[tsidx].t2 - ts[tsidx].t1;
12769 d2 = ts[tsidx].t3 - ts[tsidx].t2;
12770 d3 = ts[tsidx].t4 - ts[tsidx].t3;
12771 end2end = ts[tsidx].t4 - ts[tsidx].t1;
12773 sorttobin(d1, &vi_d1);
12774 sorttobin(d2, &vi_d2);
12775 sorttobin(d3, &vi_d3);
12776 sorttobin(end2end, &vi_d4);
12778 if (end2end > 0 && end2end > maxdelay) {
12779 maxdelay = end2end;
12780 maxdelaypktno = tspktcnt;
12781 memcpy(&maxdelayts, &ts[tsidx], 16);
12783 if (++tsidx >= TSMAX)
12788 uint32 dhd_get_htsf(dhd_info_t *dhd, int ifidx)
12790 uint32 htsf = 0, cur_cycle, delta, delta_us;
12791 uint32 factor, baseval, baseval2;
12797 if (cur_cycle > dhd->htsf.last_cycle) {
12798 delta = cur_cycle - dhd->htsf.last_cycle;
12800 delta = cur_cycle + (0xFFFFFFFF - dhd->htsf.last_cycle);
12803 delta = delta >> 4;
12805 if (dhd->htsf.coef) {
12806 /* times ten to get the first digit */
12807 factor = (dhd->htsf.coef*10 + dhd->htsf.coefdec1);
12808 baseval = (delta*10)/factor;
12809 baseval2 = (delta*10)/(factor+1);
12810 delta_us = (baseval - (((baseval - baseval2) * dhd->htsf.coefdec2)) / 10);
12811 htsf = (delta_us << 4) + dhd->htsf.last_tsf + HTSF_BUS_DELAY;
12813 DHD_ERROR(("-------dhd->htsf.coef = 0 -------\n"));
12819 static void dhd_dump_latency(void)
12822 int d1, d2, d3, d4, d5;
12824 printf("T1 T2 T3 T4 d1 d2 t4-t1 i \n");
12825 for (i = 0; i < TSMAX; i++) {
12826 d1 = ts[i].t2 - ts[i].t1;
12827 d2 = ts[i].t3 - ts[i].t2;
12828 d3 = ts[i].t4 - ts[i].t3;
12829 d4 = ts[i].t4 - ts[i].t1;
12830 d5 = ts[max].t4-ts[max].t1;
12831 if (d4 > d5 && d4 > 0) {
12834 printf("%08X %08X %08X %08X \t%d %d %d %d i=%d\n",
12835 ts[i].t1, ts[i].t2, ts[i].t3, ts[i].t4,
12836 d1, d2, d3, d4, i);
12839 printf("current idx = %d \n", tsidx);
12841 printf("Highest latency %d pkt no.%d total=%d\n", maxdelay, maxdelaypktno, tspktcnt);
12842 printf("%08X %08X %08X %08X \t%d %d %d %d\n",
12843 maxdelayts.t1, maxdelayts.t2, maxdelayts.t3, maxdelayts.t4,
12844 maxdelayts.t2 - maxdelayts.t1,
12845 maxdelayts.t3 - maxdelayts.t2,
12846 maxdelayts.t4 - maxdelayts.t3,
12847 maxdelayts.t4 - maxdelayts.t1);
12852 dhd_ioctl_htsf_get(dhd_info_t *dhd, int ifidx)
12864 memset(&ioc, 0, sizeof(ioc));
12865 memset(&tsf_buf, 0, sizeof(tsf_buf));
12867 ioc.cmd = WLC_GET_VAR;
12869 ioc.len = (uint)sizeof(buf);
12872 strncpy(buf, "tsf", sizeof(buf) - 1);
12873 buf[sizeof(buf) - 1] = '\0';
12874 s1 = dhd_get_htsf(dhd, 0);
12875 if ((ret = dhd_wl_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len)) < 0) {
12877 DHD_ERROR(("%s: tsf is not supported by device\n",
12878 dhd_ifname(&dhd->pub, ifidx)));
12879 return -EOPNOTSUPP;
12883 s2 = dhd_get_htsf(dhd, 0);
12885 memcpy(&tsf_buf, buf, sizeof(tsf_buf));
12886 printf(" TSF_h=%04X lo=%08X Calc:htsf=%08X, coef=%d.%d%d delta=%d ",
12887 tsf_buf.high, tsf_buf.low, s2, dhd->htsf.coef, dhd->htsf.coefdec1,
12888 dhd->htsf.coefdec2, s2-tsf_buf.low);
12889 printf("lasttsf=%08X lastcycle=%08X\n", dhd->htsf.last_tsf, dhd->htsf.last_cycle);
12893 void htsf_update(dhd_info_t *dhd, void *data)
12895 static ulong cur_cycle = 0, prev_cycle = 0;
12896 uint32 htsf, tsf_delta = 0;
12897 uint32 hfactor = 0, cyc_delta, dec1 = 0, dec2, dec3, tmp;
12901 /* cycles_t in inlcude/mips/timex.h */
12905 prev_cycle = cur_cycle;
12908 if (cur_cycle > prev_cycle)
12909 cyc_delta = cur_cycle - prev_cycle;
12913 cyc_delta = cur_cycle + (0xFFFFFFFF - prev_cycle);
12917 printf(" tsf update ata point er is null \n");
12919 memcpy(&prev_tsf, &cur_tsf, sizeof(tsf_t));
12920 memcpy(&cur_tsf, data, sizeof(tsf_t));
12922 if (cur_tsf.low == 0) {
12923 DHD_INFO((" ---- 0 TSF, do not update, return\n"));
12927 if (cur_tsf.low > prev_tsf.low)
12928 tsf_delta = (cur_tsf.low - prev_tsf.low);
12930 DHD_INFO((" ---- tsf low is smaller cur_tsf= %08X, prev_tsf=%08X, \n",
12931 cur_tsf.low, prev_tsf.low));
12932 if (cur_tsf.high > prev_tsf.high) {
12933 tsf_delta = cur_tsf.low + (0xFFFFFFFF - prev_tsf.low);
12934 DHD_INFO((" ---- Wrap around tsf coutner adjusted TSF=%08X\n", tsf_delta));
12936 return; /* do not update */
12941 hfactor = cyc_delta / tsf_delta;
12942 tmp = (cyc_delta - (hfactor * tsf_delta))*10;
12943 dec1 = tmp/tsf_delta;
12944 dec2 = ((tmp - dec1*tsf_delta)*10) / tsf_delta;
12945 tmp = (tmp - (dec1*tsf_delta))*10;
12946 dec3 = ((tmp - dec2*tsf_delta)*10) / tsf_delta;
12964 htsf = ((cyc_delta * 10) / (hfactor*10+dec1)) + prev_tsf.low;
12965 dhd->htsf.coef = hfactor;
12966 dhd->htsf.last_cycle = cur_cycle;
12967 dhd->htsf.last_tsf = cur_tsf.low;
12968 dhd->htsf.coefdec1 = dec1;
12969 dhd->htsf.coefdec2 = dec2;
12971 htsf = prev_tsf.low;
12975 #endif /* WLMEDIA_HTSF */
12977 #ifdef CUSTOM_SET_CPUCORE
12978 void dhd_set_cpucore(dhd_pub_t *dhd, int set)
12980 int e_dpc = 0, e_rxf = 0, retry_set = 0;
12982 if (!(dhd->chan_isvht80)) {
12983 DHD_ERROR(("%s: chan_status(%d) cpucore!!!\n", __FUNCTION__, dhd->chan_isvht80));
12990 e_dpc = set_cpus_allowed_ptr(dhd->current_dpc,
12991 cpumask_of(DPC_CPUCORE));
12993 e_dpc = set_cpus_allowed_ptr(dhd->current_dpc,
12994 cpumask_of(PRIMARY_CPUCORE));
12996 if (retry_set++ > MAX_RETRY_SET_CPUCORE) {
12997 DHD_ERROR(("%s: dpc(%d) invalid cpu!\n", __FUNCTION__, e_dpc));
13002 } while (e_dpc < 0);
13007 e_rxf = set_cpus_allowed_ptr(dhd->current_rxf,
13008 cpumask_of(RXF_CPUCORE));
13010 e_rxf = set_cpus_allowed_ptr(dhd->current_rxf,
13011 cpumask_of(PRIMARY_CPUCORE));
13013 if (retry_set++ > MAX_RETRY_SET_CPUCORE) {
13014 DHD_ERROR(("%s: rxf(%d) invalid cpu!\n", __FUNCTION__, e_rxf));
13019 } while (e_rxf < 0);
13021 #ifdef DHD_OF_SUPPORT
13022 interrupt_set_cpucore(set);
13023 #endif /* DHD_OF_SUPPORT */
13024 DHD_TRACE(("%s: set(%d) cpucore success!\n", __FUNCTION__, set));
13028 #endif /* CUSTOM_SET_CPUCORE */
13030 /* Get interface specific ap_isolate configuration */
13031 int dhd_get_ap_isolate(dhd_pub_t *dhdp, uint32 idx)
13033 dhd_info_t *dhd = dhdp->info;
13036 ASSERT(idx < DHD_MAX_IFS);
13038 ifp = dhd->iflist[idx];
13040 return ifp->ap_isolate;
13043 /* Set interface specific ap_isolate configuration */
13044 int dhd_set_ap_isolate(dhd_pub_t *dhdp, uint32 idx, int val)
13046 dhd_info_t *dhd = dhdp->info;
13049 ASSERT(idx < DHD_MAX_IFS);
13051 ifp = dhd->iflist[idx];
13053 ifp->ap_isolate = val;
13058 #ifdef DHD_FW_COREDUMP
13061 #ifdef CUSTOMER_HW4_DEBUG
13062 #ifdef PLATFORM_SLP
13063 #define MEMDUMPINFO "/opt/etc/.memdump.info"
13065 #define MEMDUMPINFO "/data/.memdump.info"
13066 #endif /* PLATFORM_SLP */
13067 #elif defined(CUSTOMER_HW2)
13068 #define MEMDUMPINFO "/data/misc/wifi/.memdump.info"
13070 #define MEMDUMPINFO "/installmedia/.memdump.info"
13071 #endif /* CUSTOMER_HW4_DEBUG */
13073 void dhd_get_memdump_info(dhd_pub_t *dhd)
13075 struct file *fp = NULL;
13076 uint32 mem_val = DUMP_MEMFILE_MAX;
13078 char *filepath = MEMDUMPINFO;
13080 /* Read memdump info from the file */
13081 fp = filp_open(filepath, O_RDONLY, 0);
13083 DHD_ERROR(("%s: File [%s] doesn't exist\n", __FUNCTION__, filepath));
13086 ret = kernel_read(fp, 0, (char *)&mem_val, 4);
13088 DHD_ERROR(("%s: File read error, ret=%d\n", __FUNCTION__, ret));
13089 filp_close(fp, NULL);
13093 mem_val = bcm_atoi((char *)&mem_val);
13095 DHD_ERROR(("%s: MEMDUMP ENABLED = %d\n", __FUNCTION__, mem_val));
13096 filp_close(fp, NULL);
13100 #ifdef CUSTOMER_HW4_DEBUG
13101 dhd->memdump_enabled = (mem_val < DUMP_MEMFILE_MAX) ? mem_val : DUMP_DISABLED;
13103 dhd->memdump_enabled = (mem_val < DUMP_MEMFILE_MAX) ? mem_val : DUMP_MEMFILE_BUGON;
13104 #endif /* CUSTOMER_HW4_DEBUG */
13108 void dhd_schedule_memdump(dhd_pub_t *dhdp, uint8 *buf, uint32 size)
13110 dhd_dump_t *dump = NULL;
13111 dump = (dhd_dump_t *)MALLOC(dhdp->osh, sizeof(dhd_dump_t));
13112 if (dump == NULL) {
13113 DHD_ERROR(("%s: dhd dump memory allocation failed\n", __FUNCTION__));
13117 dump->bufsize = size;
13119 #if defined(CONFIG_ARM64)
13120 DHD_ERROR(("%s: buf(va)=%llx, buf(pa)=%llx, bufsize=%d\n", __FUNCTION__,
13121 (uint64)buf, (uint64)__virt_to_phys((ulong)buf), size));
13122 #elif defined(__ARM_ARCH_7A__)
13123 DHD_ERROR(("%s: buf(va)=%x, buf(pa)=%x, bufsize=%d\n", __FUNCTION__,
13124 (uint32)buf, (uint32)__virt_to_phys((ulong)buf), size));
13125 #endif /* __ARM_ARCH_7A__ */
13126 if (dhdp->memdump_enabled == DUMP_MEMONLY) {
13130 #ifdef DHD_LOG_DUMP
13131 if (dhdp->memdump_type != DUMP_TYPE_BY_SYSDUMP) {
13132 dhd_schedule_log_dump(dhdp);
13134 #endif /* DHD_LOG_DUMP */
13135 dhd_deferred_schedule_work(dhdp->info->dhd_deferred_wq, (void *)dump,
13136 DHD_WQ_WORK_SOC_RAM_DUMP, dhd_mem_dump, DHD_WORK_PRIORITY_HIGH);
13139 dhd_mem_dump(void *handle, void *event_info, u8 event)
13141 dhd_info_t *dhd = handle;
13142 dhd_dump_t *dump = event_info;
13145 DHD_ERROR(("%s: dhd is NULL\n", __FUNCTION__));
13150 DHD_ERROR(("%s: dump is NULL\n", __FUNCTION__));
13154 if (write_to_file(&dhd->pub, dump->buf, dump->bufsize)) {
13155 DHD_ERROR(("%s: writing SoC_RAM dump to the file failed\n", __FUNCTION__));
13158 if (dhd->pub.memdump_enabled == DUMP_MEMFILE_BUGON &&
13159 #ifdef DHD_LOG_DUMP
13160 dhd->pub.memdump_type != DUMP_TYPE_BY_SYSDUMP &&
13165 MFREE(dhd->pub.osh, dump, sizeof(dhd_dump_t));
13167 #endif /* DHD_FW_COREDUMP */
13169 #ifdef DHD_LOG_DUMP
13171 dhd_log_dump(void *handle, void *event_info, u8 event)
13173 dhd_info_t *dhd = handle;
13176 DHD_ERROR(("%s: dhd is NULL\n", __FUNCTION__));
13180 if (do_dhd_log_dump(&dhd->pub)) {
13181 DHD_ERROR(("%s: writing debug dump to the file failed\n", __FUNCTION__));
13186 void dhd_schedule_log_dump(dhd_pub_t *dhdp)
13188 dhd_deferred_schedule_work(dhdp->info->dhd_deferred_wq,
13189 (void*)NULL, DHD_WQ_WORK_DHD_LOG_DUMP,
13190 dhd_log_dump, DHD_WORK_PRIORITY_HIGH);
13194 do_dhd_log_dump(dhd_pub_t *dhdp)
13197 struct file *fp = NULL;
13198 mm_segment_t old_fs;
13200 char dump_path[128];
13201 char common_info[1024];
13202 struct timeval curtime;
13204 unsigned long flags = 0;
13210 /* Building the additional information like DHD, F/W version */
13211 memset(common_info, 0, sizeof(common_info));
13212 snprintf(common_info, sizeof(common_info),
13213 "---------- Common information ----------\n"
13214 "DHD version: %s\n"
13215 "F/W version: %s\n"
13216 "----------------------------------------\n",
13217 dhd_version, fw_version);
13219 /* change to KERNEL_DS address limit */
13223 /* Init file name */
13224 memset(dump_path, 0, sizeof(dump_path));
13225 do_gettimeofday(&curtime);
13226 snprintf(dump_path, sizeof(dump_path), "%s_%ld.%ld",
13227 DHD_COMMON_DUMP_PATH "debug_dump",
13228 (unsigned long)curtime.tv_sec, (unsigned long)curtime.tv_usec);
13229 file_mode = O_CREAT | O_WRONLY | O_SYNC;
13231 DHD_ERROR(("debug_dump_path = %s\n", dump_path));
13232 fp = filp_open(dump_path, file_mode, 0644);
13235 DHD_ERROR(("open file error, err = %d\n", ret));
13240 fp->f_op->write(fp, common_info, strlen(common_info), &pos);
13241 if (dhdp->dld_buf.wraparound) {
13242 fp->f_op->write(fp, dhdp->dld_buf.buffer, DHD_LOG_DUMP_BUFFER_SIZE, &pos);
13244 fp->f_op->write(fp, dhdp->dld_buf.buffer,
13245 (int)(dhdp->dld_buf.present - dhdp->dld_buf.front), &pos);
13248 /* re-init dhd_log_dump_buf structure */
13249 spin_lock_irqsave(&dhdp->dld_buf.lock, flags);
13250 dhdp->dld_buf.wraparound = 0;
13251 dhdp->dld_buf.present = dhdp->dld_buf.front;
13252 dhdp->dld_buf.remain = DHD_LOG_DUMP_BUFFER_SIZE;
13253 bzero(dhdp->dld_buf.buffer, DHD_LOG_DUMP_BUFFER_SIZE);
13254 spin_unlock_irqrestore(&dhdp->dld_buf.lock, flags);
13257 filp_close(fp, NULL);
13263 #endif /* DHD_LOG_DUMP */
13265 #ifdef BCMASSERT_LOG
13266 #ifdef CUSTOMER_HW4_DEBUG
13267 #ifdef PLATFORM_SLP
13268 #define ASSERTINFO "/opt/etc/.assert.info"
13270 #define ASSERTINFO "/data/.assert.info"
13271 #endif /* PLATFORM_SLP */
13272 #elif defined(CUSTOMER_HW2)
13273 #define ASSERTINFO "/data/misc/wifi/.assert.info"
13275 #define ASSERTINFO "/installmedia/.assert.info"
13276 #endif /* CUSTOMER_HW4_DEBUG */
13277 void dhd_get_assert_info(dhd_pub_t *dhd)
13279 struct file *fp = NULL;
13280 char *filepath = ASSERTINFO;
13283 * Read assert info from the file
13284 * 0: Trigger Kernel crash by panic()
13285 * 1: Print out the logs and don't trigger Kernel panic. (default)
13286 * 2: Trigger Kernel crash by BUG()
13287 * File doesn't exist: Keep default value (1).
13289 fp = filp_open(filepath, O_RDONLY, 0);
13291 DHD_ERROR(("%s: File [%s] doesn't exist\n", __FUNCTION__, filepath));
13294 int ret = kernel_read(fp, 0, (char *)&mem_val, 4);
13296 DHD_ERROR(("%s: File read error, ret=%d\n", __FUNCTION__, ret));
13298 mem_val = bcm_atoi((char *)&mem_val);
13299 DHD_ERROR(("%s: ASSERT ENABLED = %d\n", __FUNCTION__, mem_val));
13300 g_assert_type = mem_val;
13302 filp_close(fp, NULL);
13305 #endif /* BCMASSERT_LOG */
13309 /* Returns interface specific WMF configuration */
13310 dhd_wmf_t* dhd_wmf_conf(dhd_pub_t *dhdp, uint32 idx)
13312 dhd_info_t *dhd = dhdp->info;
13315 ASSERT(idx < DHD_MAX_IFS);
13317 ifp = dhd->iflist[idx];
13320 #endif /* DHD_WMF */
13323 #if defined(DHD_L2_FILTER)
13324 bool dhd_sta_associated(dhd_pub_t *dhdp, uint32 bssidx, uint8 *mac)
13326 return dhd_find_sta(dhdp, bssidx, mac) ? TRUE : FALSE;
13330 #ifdef DHD_L2_FILTER
13332 dhd_get_ifp_arp_table_handle(dhd_pub_t *dhdp, uint32 bssidx)
13334 dhd_info_t *dhd = dhdp->info;
13337 ASSERT(bssidx < DHD_MAX_IFS);
13339 ifp = dhd->iflist[bssidx];
13340 return ifp->phnd_arp_table;
13343 int dhd_get_parp_status(dhd_pub_t *dhdp, uint32 idx)
13345 dhd_info_t *dhd = dhdp->info;
13348 ASSERT(idx < DHD_MAX_IFS);
13350 ifp = dhd->iflist[idx];
13353 return ifp->parp_enable;
13358 /* Set interface specific proxy arp configuration */
13359 int dhd_set_parp_status(dhd_pub_t *dhdp, uint32 idx, int val)
13361 dhd_info_t *dhd = dhdp->info;
13363 ASSERT(idx < DHD_MAX_IFS);
13364 ifp = dhd->iflist[idx];
13369 /* At present all 3 variables are being
13372 ifp->parp_enable = val;
13373 ifp->parp_discard = val;
13374 ifp->parp_allnode = !val;
13376 /* Flush ARP entries when disabled */
13377 if (val == FALSE) {
13378 bcm_l2_filter_arp_table_update(dhdp->osh, ifp->phnd_arp_table, TRUE, NULL,
13379 FALSE, dhdp->tickcnt);
13384 bool dhd_parp_discard_is_enabled(dhd_pub_t *dhdp, uint32 idx)
13386 dhd_info_t *dhd = dhdp->info;
13389 ASSERT(idx < DHD_MAX_IFS);
13391 ifp = dhd->iflist[idx];
13394 return ifp->parp_discard;
13398 dhd_parp_allnode_is_enabled(dhd_pub_t *dhdp, uint32 idx)
13400 dhd_info_t *dhd = dhdp->info;
13403 ASSERT(idx < DHD_MAX_IFS);
13405 ifp = dhd->iflist[idx];
13409 return ifp->parp_allnode;
13412 int dhd_get_dhcp_unicast_status(dhd_pub_t *dhdp, uint32 idx)
13414 dhd_info_t *dhd = dhdp->info;
13417 ASSERT(idx < DHD_MAX_IFS);
13419 ifp = dhd->iflist[idx];
13423 return ifp->dhcp_unicast;
13426 int dhd_set_dhcp_unicast_status(dhd_pub_t *dhdp, uint32 idx, int val)
13428 dhd_info_t *dhd = dhdp->info;
13430 ASSERT(idx < DHD_MAX_IFS);
13431 ifp = dhd->iflist[idx];
13435 ifp->dhcp_unicast = val;
13439 int dhd_get_block_ping_status(dhd_pub_t *dhdp, uint32 idx)
13441 dhd_info_t *dhd = dhdp->info;
13444 ASSERT(idx < DHD_MAX_IFS);
13446 ifp = dhd->iflist[idx];
13450 return ifp->block_ping;
13453 int dhd_set_block_ping_status(dhd_pub_t *dhdp, uint32 idx, int val)
13455 dhd_info_t *dhd = dhdp->info;
13457 ASSERT(idx < DHD_MAX_IFS);
13458 ifp = dhd->iflist[idx];
13462 ifp->block_ping = val;
13467 int dhd_get_grat_arp_status(dhd_pub_t *dhdp, uint32 idx)
13469 dhd_info_t *dhd = dhdp->info;
13472 ASSERT(idx < DHD_MAX_IFS);
13474 ifp = dhd->iflist[idx];
13478 return ifp->grat_arp;
13481 int dhd_set_grat_arp_status(dhd_pub_t *dhdp, uint32 idx, int val)
13483 dhd_info_t *dhd = dhdp->info;
13485 ASSERT(idx < DHD_MAX_IFS);
13486 ifp = dhd->iflist[idx];
13490 ifp->grat_arp = val;
13494 #endif /* DHD_L2_FILTER */
13497 #if defined(SET_RPS_CPUS)
13498 int dhd_rps_cpus_enable(struct net_device *net, int enable)
13500 dhd_info_t *dhd = DHD_DEV_INFO(net);
13503 char * RPS_CPU_SETBUF;
13505 ifidx = dhd_net2idx(dhd, net);
13506 if (ifidx == DHD_BAD_IF) {
13507 DHD_ERROR(("%s bad ifidx\n", __FUNCTION__));
13511 if (ifidx == PRIMARY_INF) {
13512 if (dhd->pub.op_mode == DHD_FLAG_IBSS_MODE) {
13513 DHD_INFO(("%s : set for IBSS.\n", __FUNCTION__));
13514 RPS_CPU_SETBUF = RPS_CPUS_MASK_IBSS;
13516 DHD_INFO(("%s : set for BSS.\n", __FUNCTION__));
13517 RPS_CPU_SETBUF = RPS_CPUS_MASK;
13519 } else if (ifidx == VIRTUAL_INF) {
13520 DHD_INFO(("%s : set for P2P.\n", __FUNCTION__));
13521 RPS_CPU_SETBUF = RPS_CPUS_MASK_P2P;
13523 DHD_ERROR(("%s : Invalid index : %d.\n", __FUNCTION__, ifidx));
13527 ifp = dhd->iflist[ifidx];
13530 DHD_INFO(("%s : set rps_cpus as [%s]\n", __FUNCTION__, RPS_CPU_SETBUF));
13531 custom_rps_map_set(ifp->net->_rx, RPS_CPU_SETBUF, strlen(RPS_CPU_SETBUF));
13533 custom_rps_map_clear(ifp->net->_rx);
13536 DHD_ERROR(("%s : ifp is NULL!!\n", __FUNCTION__));
13542 int custom_rps_map_set(struct netdev_rx_queue *queue, char *buf, size_t len)
13544 struct rps_map *old_map, *map;
13545 cpumask_var_t mask;
13547 static DEFINE_SPINLOCK(rps_map_lock);
13549 DHD_INFO(("%s : Entered.\n", __FUNCTION__));
13551 if (!alloc_cpumask_var(&mask, GFP_KERNEL)) {
13552 DHD_ERROR(("%s : alloc_cpumask_var fail.\n", __FUNCTION__));
13556 err = bitmap_parse(buf, len, cpumask_bits(mask), nr_cpumask_bits);
13558 free_cpumask_var(mask);
13559 DHD_ERROR(("%s : bitmap_parse fail.\n", __FUNCTION__));
13563 map = kzalloc(max_t(unsigned int,
13564 RPS_MAP_SIZE(cpumask_weight(mask)), L1_CACHE_BYTES),
13567 free_cpumask_var(mask);
13568 DHD_ERROR(("%s : map malloc fail.\n", __FUNCTION__));
13573 for_each_cpu(cpu, mask) {
13574 map->cpus[i++] = cpu;
13582 free_cpumask_var(mask);
13583 DHD_ERROR(("%s : mapping cpu fail.\n", __FUNCTION__));
13587 spin_lock(&rps_map_lock);
13588 old_map = rcu_dereference_protected(queue->rps_map,
13589 lockdep_is_held(&rps_map_lock));
13590 rcu_assign_pointer(queue->rps_map, map);
13591 spin_unlock(&rps_map_lock);
13594 static_key_slow_inc(&rps_needed);
13597 kfree_rcu(old_map, rcu);
13598 static_key_slow_dec(&rps_needed);
13600 free_cpumask_var(mask);
13602 DHD_INFO(("%s : Done. mapping cpu nummber : %d\n", __FUNCTION__, map->len));
13606 void custom_rps_map_clear(struct netdev_rx_queue *queue)
13608 struct rps_map *map;
13610 DHD_INFO(("%s : Entered.\n", __FUNCTION__));
13612 map = rcu_dereference_protected(queue->rps_map, 1);
13614 RCU_INIT_POINTER(queue->rps_map, NULL);
13615 kfree_rcu(map, rcu);
13616 DHD_INFO(("%s : rps_cpus map clear.\n", __FUNCTION__));
13623 #ifdef DHD_DEBUG_PAGEALLOC
13626 dhd_page_corrupt_cb(void *handle, void *addr_corrupt, size_t len)
13628 dhd_pub_t *dhdp = (dhd_pub_t *)handle;
13630 DHD_ERROR(("%s: Got dhd_page_corrupt_cb 0x%p %d\n",
13631 __FUNCTION__, addr_corrupt, (uint32)len));
13633 DHD_OS_WAKE_LOCK(dhdp);
13634 prhex("Page Corruption:", addr_corrupt, len);
13635 dhd_dump_to_kernelog(dhdp);
13636 #if defined(BCMPCIE) && defined(DHD_FW_COREDUMP)
13637 /* Load the dongle side dump to host memory and then BUG_ON() */
13638 dhdp->memdump_enabled = DUMP_MEMONLY;
13639 dhdp->memdump_type = DUMP_TYPE_MEMORY_CORRUPTION;
13640 dhd_bus_mem_dump(dhdp);
13641 #endif /* BCMPCIE && DHD_FW_COREDUMP */
13642 DHD_OS_WAKE_UNLOCK(dhdp);
13644 EXPORT_SYMBOL(dhd_page_corrupt_cb);
13645 #endif /* DHD_DEBUG_PAGEALLOC */
13647 #ifdef DHD_PKTID_AUDIT_ENABLED
13649 dhd_pktid_audit_fail_cb(dhd_pub_t *dhdp)
13651 DHD_ERROR(("%s: Got Pkt Id Audit failure \n", __FUNCTION__));
13652 DHD_OS_WAKE_LOCK(dhdp);
13653 dhd_dump_to_kernelog(dhdp);
13654 #if defined(BCMPCIE) && defined(DHD_FW_COREDUMP)
13655 /* Load the dongle side dump to host memory and then BUG_ON() */
13656 dhdp->memdump_enabled = DUMP_MEMFILE_BUGON;
13657 dhdp->memdump_type = DUMP_TYPE_PKTID_AUDIT_FAILURE;
13658 dhd_bus_mem_dump(dhdp);
13659 #endif /* BCMPCIE && DHD_FW_COREDUMP */
13660 DHD_OS_WAKE_UNLOCK(dhdp);
13662 #endif /* DHD_PKTID_AUDIT_ENABLED */
13664 /* ----------------------------------------------------------------------------
13665 * Infrastructure code for sysfs interface support for DHD
13667 * What is sysfs interface?
13668 * https://www.kernel.org/doc/Documentation/filesystems/sysfs.txt
13670 * Why sysfs interface?
13671 * This is the Linux standard way of changing/configuring Run Time parameters
13672 * for a driver. We can use this interface to control "linux" specific driver
13675 * -----------------------------------------------------------------------------
13678 #include <linux/sysfs.h>
13679 #include <linux/kobject.h>
13681 #if defined(DHD_TRACE_WAKE_LOCK)
13683 /* Function to show the history buffer */
13685 show_wklock_trace(struct dhd_info *dev, char *buf)
13688 dhd_info_t *dhd = (dhd_info_t *)dev;
13693 dhd_wk_lock_stats_dump(&dhd->pub);
13697 /* Function to enable/disable wakelock trace */
13699 wklock_trace_onoff(struct dhd_info *dev, const char *buf, size_t count)
13701 unsigned long onoff;
13702 unsigned long flags;
13703 dhd_info_t *dhd = (dhd_info_t *)dev;
13705 onoff = bcm_strtoul(buf, NULL, 10);
13706 if (onoff != 0 && onoff != 1) {
13710 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
13711 trace_wklock_onoff = onoff;
13712 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
13713 if (trace_wklock_onoff) {
13714 printk("ENABLE WAKLOCK TRACE\n");
13716 printk("DISABLE WAKELOCK TRACE\n");
13719 return (ssize_t)(onoff+1);
13721 #endif /* DHD_TRACE_WAKE_LOCK */
13724 * Generic Attribute Structure for DHD.
13725 * If we have to add a new sysfs entry under /sys/bcm-dhd/, we have
13726 * to instantiate an object of type dhd_attr, populate it with
13727 * the required show/store functions (ex:- dhd_attr_cpumask_primary)
13728 * and add the object to default_attrs[] array, that gets registered
13729 * to the kobject of dhd (named bcm-dhd).
13733 struct attribute attr;
13734 ssize_t(*show)(struct dhd_info *, char *);
13735 ssize_t(*store)(struct dhd_info *, const char *, size_t count);
13738 #if defined(DHD_TRACE_WAKE_LOCK)
13739 static struct dhd_attr dhd_attr_wklock =
13740 __ATTR(wklock_trace, 0660, show_wklock_trace, wklock_trace_onoff);
13741 #endif /* defined(DHD_TRACE_WAKE_LOCK */
13743 /* Attribute object that gets registered with "bcm-dhd" kobject tree */
13744 static struct attribute *default_attrs[] = {
13745 #if defined(DHD_TRACE_WAKE_LOCK)
13746 &dhd_attr_wklock.attr,
13751 #define to_dhd(k) container_of(k, struct dhd_info, dhd_kobj)
13752 #define to_attr(a) container_of(a, struct dhd_attr, attr)
13755 * bcm-dhd kobject show function, the "attr" attribute specifices to which
13756 * node under "bcm-dhd" the show function is called.
13758 static ssize_t dhd_show(struct kobject *kobj, struct attribute *attr, char *buf)
13760 dhd_info_t *dhd = to_dhd(kobj);
13761 struct dhd_attr *d_attr = to_attr(attr);
13765 ret = d_attr->show(dhd, buf);
13774 * bcm-dhd kobject show function, the "attr" attribute specifices to which
13775 * node under "bcm-dhd" the store function is called.
13777 static ssize_t dhd_store(struct kobject *kobj, struct attribute *attr,
13778 const char *buf, size_t count)
13780 dhd_info_t *dhd = to_dhd(kobj);
13781 struct dhd_attr *d_attr = to_attr(attr);
13785 ret = d_attr->store(dhd, buf, count);
13793 static struct sysfs_ops dhd_sysfs_ops = {
13795 .store = dhd_store,
13798 static struct kobj_type dhd_ktype = {
13799 .sysfs_ops = &dhd_sysfs_ops,
13800 .default_attrs = default_attrs,
13803 /* Create a kobject and attach to sysfs interface */
13804 static int dhd_sysfs_init(dhd_info_t *dhd)
13809 DHD_ERROR(("%s(): dhd is NULL \r\n", __FUNCTION__));
13813 /* Initialize the kobject */
13814 ret = kobject_init_and_add(&dhd->dhd_kobj, &dhd_ktype, NULL, "bcm-dhd");
13816 kobject_put(&dhd->dhd_kobj);
13817 DHD_ERROR(("%s(): Unable to allocate kobject \r\n", __FUNCTION__));
13822 * We are always responsible for sending the uevent that the kobject
13823 * was added to the system.
13825 kobject_uevent(&dhd->dhd_kobj, KOBJ_ADD);
13830 /* Done with the kobject and detach the sysfs interface */
13831 static void dhd_sysfs_exit(dhd_info_t *dhd)
13834 DHD_ERROR(("%s(): dhd is NULL \r\n", __FUNCTION__));
13838 /* Releae the kobject */
13839 kobject_put(&dhd->dhd_kobj);
13842 #ifdef DHD_LOG_DUMP
13844 dhd_log_dump_init(dhd_pub_t *dhd)
13846 spin_lock_init(&dhd->dld_buf.lock);
13847 #if defined(CONFIG_DHD_USE_STATIC_BUF) && defined(DHD_USE_STATIC_MEMDUMP)
13848 dhd->dld_buf.buffer = DHD_OS_PREALLOC(dhd,
13849 DHD_PREALLOC_DHD_LOG_DUMP_BUF, DHD_LOG_DUMP_BUFFER_SIZE);
13851 dhd->dld_buf.buffer = kmalloc(DHD_LOG_DUMP_BUFFER_SIZE, GFP_KERNEL);
13852 #endif /* CONFIG_DHD_USE_STATIC_BUF && DHD_USE_STATIC_MEMDUMP */
13854 if (!dhd->dld_buf.buffer) {
13855 dhd->dld_buf.buffer = kmalloc(DHD_LOG_DUMP_BUFFER_SIZE, GFP_KERNEL);
13856 DHD_ERROR(("Try to allocate memory using kmalloc().\n"));
13858 if (!dhd->dld_buf.buffer) {
13859 DHD_ERROR(("Failed to allocate memory for dld_buf.\n"));
13864 dhd->dld_buf.wraparound = 0;
13865 dhd->dld_buf.max = (unsigned long)dhd->dld_buf.buffer + DHD_LOG_DUMP_BUFFER_SIZE;
13866 dhd->dld_buf.present = dhd->dld_buf.buffer;
13867 dhd->dld_buf.front = dhd->dld_buf.buffer;
13868 dhd->dld_buf.remain = DHD_LOG_DUMP_BUFFER_SIZE;
13869 dhd->dld_enable = 1;
13873 dhd_log_dump_deinit(dhd_pub_t *dhd)
13875 dhd->dld_enable = 0;
13876 #if defined(CONFIG_DHD_USE_STATIC_BUF) && defined(DHD_USE_STATIC_MEMDUMP)
13877 DHD_OS_PREFREE(dhd,
13878 dhd->dld_buf.buffer, DHD_LOG_DUMP_BUFFER_SIZE);
13880 kfree(dhd->dld_buf.buffer);
13881 #endif /* CONFIG_DHD_USE_STATIC_BUF && DHD_USE_STATIC_MEMDUMP */
13885 dhd_log_dump_print(const char *fmt, ...)
13888 char tmp_buf[DHD_LOG_DUMP_MAX_TEMP_BUFFER_SIZE] = {0, };
13890 dhd_pub_t *dhd = NULL;
13891 unsigned long flags = 0;
13893 if (wl_get_bcm_cfg80211_ptr()) {
13894 dhd = (dhd_pub_t*)(wl_get_bcm_cfg80211_ptr()->pub);
13897 if (!dhd || dhd->dld_enable != 1) {
13901 va_start(args, fmt);
13903 len = vsnprintf(tmp_buf, DHD_LOG_DUMP_MAX_TEMP_BUFFER_SIZE, fmt, args);
13908 /* make a critical section to eliminate race conditions */
13909 spin_lock_irqsave(&dhd->dld_buf.lock, flags);
13910 if (dhd->dld_buf.remain < len) {
13911 dhd->dld_buf.wraparound = 1;
13912 dhd->dld_buf.present = dhd->dld_buf.front;
13913 dhd->dld_buf.remain = DHD_LOG_DUMP_BUFFER_SIZE;
13916 strncpy(dhd->dld_buf.present, tmp_buf, len);
13917 dhd->dld_buf.remain -= len;
13918 dhd->dld_buf.present += len;
13919 spin_unlock_irqrestore(&dhd->dld_buf.lock, flags);
13921 /* double check invalid memory operation */
13922 ASSERT((unsigned long)dhd->dld_buf.present <= dhd->dld_buf.max);
13927 dhd_log_dump_get_timestamp(void)
13929 static char buf[16];
13931 unsigned long rem_nsec;
13933 ts_nsec = local_clock();
13934 rem_nsec = do_div(ts_nsec, 1000000000);
13935 snprintf(buf, sizeof(buf), "%5lu.%06lu",
13936 (unsigned long)ts_nsec, rem_nsec / 1000);
13941 #endif /* DHD_LOG_DUMP */
13943 /* ---------------------------- End of sysfs implementation ------------------------------------- */
13945 void *dhd_get_pub(struct net_device *dev)
13947 dhd_info_t *dhdinfo = *(dhd_info_t **)netdev_priv(dev);
13949 return (void *)&dhdinfo->pub;
13954 bool dhd_os_wd_timer_enabled(void *bus)
13956 dhd_pub_t *pub = bus;
13957 dhd_info_t *dhd = (dhd_info_t *)pub->info;
13959 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
13961 DHD_ERROR(("%s: dhd NULL\n", __FUNCTION__));
13964 return dhd->wd_timer_valid;