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 Open Broadcom Corporation$
7 * $Id: dhd_linux.c 419821 2013-08-22 21:43:26Z $
14 #include <linux/init.h>
15 #include <linux/kernel.h>
16 #include <linux/slab.h>
17 #include <linux/skbuff.h>
18 #include <linux/netdevice.h>
19 #include <linux/inetdevice.h>
20 #include <linux/rtnetlink.h>
21 #include <linux/etherdevice.h>
22 #include <linux/random.h>
23 #include <linux/spinlock.h>
24 #include <linux/ethtool.h>
25 #include <linux/fcntl.h>
28 #include <net/addrconf.h>
30 #include <asm/uaccess.h>
31 #include <asm/unaligned.h>
35 #include <bcmendian.h>
38 #include <proto/ethernet.h>
39 #include <proto/bcmip.h>
40 #include <dngl_stats.h>
43 #include <dhd_proto.h>
44 #include <dhd_config.h>
46 #ifdef CONFIG_HAS_WAKELOCK
47 #include <linux/wakelock.h>
50 #include <wl_cfg80211.h>
56 #include <proto/802.11_bta.h>
57 #include <proto/bt_amp_hci.h>
62 #include <linux/time.h>
65 #define HTSF_MINLEN 200 /* min. packet length to timestamp */
66 #define HTSF_BUS_DELAY 150 /* assume a fix propagation in us */
67 #define TSMAX 1000 /* max no. of timing record kept */
70 static uint32 tsidx = 0;
71 static uint32 htsf_seqnum = 0;
74 static uint32 tsport = 5010;
76 typedef struct histo_ {
80 #if !ISPOWEROF2(DHD_SDALIGN)
81 #error DHD_SDALIGN is not a power of 2!
84 static histo_t vi_d1, vi_d2, vi_d3, vi_d4;
85 #endif /* WLMEDIA_HTSF */
89 extern bool ap_cfg_running;
90 extern bool ap_fw_loaded;
94 /* enable HOSTIP cache update from the host side when an eth0:N is up */
95 #define AOE_IP_ALIAS_SUPPORT 1
99 #include <bcm_rpc_tp.h>
102 #include <wlfc_proto.h>
103 #include <dhd_wlfc.h>
106 #include <wl_android.h>
108 #ifdef ARP_OFFLOAD_SUPPORT
109 void aoe_update_host_ipv4_table(dhd_pub_t *dhd_pub, u32 ipa, bool add, int idx);
110 static int dhd_device_event(struct notifier_block *this,
114 static struct notifier_block dhd_notifier = {
115 .notifier_call = dhd_device_event
117 #endif /* ARP_OFFLOAD_SUPPORT */
118 static int dhd_device_ipv6_event(struct notifier_block *this,
122 static struct notifier_block dhd_notifier_ipv6 = {
123 .notifier_call = dhd_device_ipv6_event
126 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP)
127 #include <linux/suspend.h>
128 volatile bool dhd_mmc_suspend = FALSE;
129 DECLARE_WAIT_QUEUE_HEAD(dhd_dpc_wait);
130 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(CONFIG_PM_SLEEP) */
132 #if defined(OOB_INTR_ONLY)
133 extern void dhd_enable_oob_intr(struct dhd_bus *bus, bool enable);
135 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && (1)
136 static void dhd_hang_process(struct work_struct *work);
138 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
139 MODULE_LICENSE("GPL v2");
140 #endif /* LinuxVer */
145 #define DBUS_RX_BUFFER_SIZE_DHD(net) (BCM_RPC_TP_DNGL_AGG_MAX_BYTE)
147 #ifndef PROP_TXSTATUS
148 #define DBUS_RX_BUFFER_SIZE_DHD(net) (net->mtu + net->hard_header_len + dhd->pub.hdrlen)
150 #define DBUS_RX_BUFFER_SIZE_DHD(net) (net->mtu + net->hard_header_len + dhd->pub.hdrlen + 128)
152 #endif /* BCM_FD_AGGR */
155 extern bool dhd_wlfc_skip_fc(void);
156 extern void dhd_wlfc_plat_enable(void *dhd);
157 extern void dhd_wlfc_plat_deinit(void *dhd);
158 #endif /* PROP_TXSTATUS */
160 #if LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 15)
166 #endif /* LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 15) */
168 /* Linux wireless extension support */
169 #if defined(WL_WIRELESS_EXT)
171 extern wl_iw_extra_params_t g_wl_iw_params;
172 #endif /* defined(WL_WIRELESS_EXT) */
174 #if defined(CONFIG_HAS_EARLYSUSPEND) && defined(DHD_USE_EARLYSUSPEND)
175 #include <linux/earlysuspend.h>
176 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) && defined(DHD_USE_EARLYSUSPEND) */
178 extern int dhd_get_suspend_bcn_li_dtim(dhd_pub_t *dhd);
180 #ifdef PKT_FILTER_SUPPORT
181 extern void dhd_pktfilter_offload_set(dhd_pub_t * dhd, char *arg);
182 extern void dhd_pktfilter_offload_enable(dhd_pub_t * dhd, char *arg, int enable, int master_mode);
183 extern void dhd_pktfilter_offload_delete(dhd_pub_t *dhd, int id);
188 extern int dhd_read_macaddr(struct dhd_info *dhd);
190 static inline int dhd_read_macaddr(struct dhd_info *dhd) { return 0; }
193 extern int dhd_write_macaddr(struct ether_addr *mac);
195 static inline int dhd_write_macaddr(struct ether_addr *mac) { return 0; }
198 char ipv6_addr[IPV6_ADDR_LEN];
199 dhd_ipv6_op_t ipv6_oper;
200 struct list_head list;
203 /* Interface control information */
204 typedef struct dhd_if {
205 struct dhd_info *info; /* back pointer to dhd_info */
206 /* OS/stack specifics */
207 struct net_device *net;
208 struct net_device_stats stats;
209 int idx; /* iface idx in dongle */
210 dhd_if_state_t state; /* interface state */
211 uint subunit; /* subunit */
212 uint8 mac_addr[ETHER_ADDR_LEN]; /* assigned MAC address */
213 bool attached; /* Delayed attachment when unset */
214 bool txflowcontrol; /* Per interface flow control indicator */
215 char name[IFNAMSIZ+1]; /* linux interface name */
216 uint8 bssidx; /* bsscfg index for the interface */
218 struct list_head ipv6_list;
219 spinlock_t ipv6_lock;
220 bool event2cfg80211; /* To determine if pass event to cfg80211 */
233 uint32 coef; /* scaling factor */
234 uint32 coefdec1; /* first decimal */
235 uint32 coefdec2; /* second decimal */
245 static tstamp_t ts[TSMAX];
246 static tstamp_t maxdelayts;
247 static uint32 maxdelay = 0, tspktcnt = 0, maxdelaypktno = 0;
249 #endif /* WLMEDIA_HTSF */
251 /* Local private structure (extension of pub) */
252 typedef struct dhd_info {
253 #if defined(WL_WIRELESS_EXT)
254 wl_iw_t iw; /* wireless extensions state (must be first) */
255 #endif /* defined(WL_WIRELESS_EXT) */
259 /* For supporting multiple interfaces */
260 dhd_if_t *iflist[DHD_MAX_IFS];
262 struct semaphore proto_sem;
264 spinlock_t wlfc_spinlock;
265 #endif /* PROP_TXSTATUS */
269 wait_queue_head_t ioctl_resp_wait;
270 uint32 default_wd_interval;
272 struct timer_list timer;
274 struct tasklet_struct tasklet;
279 /* Thread based operation */
281 struct semaphore sdsem;
283 tsk_ctl_t thr_dpc_ctl;
284 tsk_ctl_t thr_wdt_ctl;
285 #ifdef RXFRAME_THREAD
286 tsk_ctl_t thr_rxf_ctl;
288 #endif /* RXFRAME_THREAD */
289 #endif /* DHDTHREAD */
290 bool dhd_tasklet_create;
291 tsk_ctl_t thr_sysioc_ctl;
292 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
293 struct work_struct work_hang;
297 #if defined(CONFIG_HAS_WAKELOCK) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
298 struct wake_lock wl_wifi; /* Wifi wakelock */
299 struct wake_lock wl_rxwake; /* Wifi rx wakelock */
300 struct wake_lock wl_ctrlwake; /* Wifi ctrl wakelock */
301 struct wake_lock wl_wdwake; /* Wifi wd wakelock */
304 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) && 1
305 /* net_device interface lock, prevent race conditions among net_dev interface
306 * calls and wifi_on or wifi_off
308 struct mutex dhd_net_if_mutex;
309 struct mutex dhd_suspend_mutex;
311 spinlock_t wakelock_spinlock;
312 int wakelock_counter;
313 int wakelock_wd_counter;
314 int wakelock_rx_timeout_enable;
315 int wakelock_ctrl_timeout_enable;
317 /* Thread to issue ioctl for multicast */
318 unsigned char set_macaddress;
319 struct ether_addr macvalue;
320 wait_queue_head_t ctrl_wait;
321 atomic_t pend_8021x_cnt;
322 dhd_attach_states_t dhd_state;
324 #if defined(CONFIG_HAS_EARLYSUSPEND) && defined(DHD_USE_EARLYSUSPEND)
325 struct early_suspend early_suspend;
326 #endif /* CONFIG_HAS_EARLYSUSPEND && DHD_USE_EARLYSUSPEND */
328 #ifdef ARP_OFFLOAD_SUPPORT
330 #endif /* ARP_OFFLOAD_SUPPORT */
334 struct timer_list rpcth_timer;
335 bool rpcth_timer_active;
338 #ifdef DHDTCPACK_SUPPRESS
339 spinlock_t tcpack_lock;
340 #endif /* DHDTCPACK_SUPPRESS */
343 /* Flag to indicate if we should download firmware on driver load */
344 uint dhd_download_fw_on_driverload = TRUE;
346 /* Definitions to provide path to the firmware and nvram
347 * example nvram_path[MOD_PARAM_PATHLEN]="/projects/wlan/nvram.txt"
349 char firmware_path[MOD_PARAM_PATHLEN];
350 char nvram_path[MOD_PARAM_PATHLEN];
351 char config_path[MOD_PARAM_PATHLEN];
353 /* information string to keep firmware, chio, cheip version info visiable from log */
354 char info_string[MOD_PARAM_INFOLEN];
355 module_param_string(info_string, info_string, MOD_PARAM_INFOLEN, 0444);
357 int disable_proptx = 0;
358 module_param(op_mode, int, 0644);
359 extern int wl_control_wl_start(struct net_device *dev);
360 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
361 struct semaphore dhd_registration_sem;
362 struct semaphore dhd_chipup_sem;
363 int dhd_registration_check = FALSE;
365 #define DHD_REGISTRATION_TIMEOUT 12000 /* msec : allowed time to finished dhd registration */
366 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
368 /* Spawn a thread for system ioctls (set mac, set mcast) */
369 uint dhd_sysioc = TRUE;
370 module_param(dhd_sysioc, uint, 0);
373 module_param(dhd_msg_level, int, 0);
374 #if defined(WL_WIRELESS_EXT)
375 module_param(iw_msg_level, int, 0);
378 module_param(wl_dbg_level, int, 0);
380 module_param(android_msg_level, int, 0);
381 module_param(config_msg_level, int, 0);
383 #ifdef ARP_OFFLOAD_SUPPORT
384 /* ARP offload enable */
385 uint dhd_arp_enable = TRUE;
386 module_param(dhd_arp_enable, uint, 0);
388 /* ARP offload agent mode : Enable ARP Host Auto-Reply and ARP Peer Auto-Reply */
390 uint dhd_arp_mode = ARP_OL_AGENT | ARP_OL_PEER_AUTO_REPLY;
392 module_param(dhd_arp_mode, uint, 0);
393 #endif /* ARP_OFFLOAD_SUPPORT */
397 /* Disable Prop tx */
398 module_param(disable_proptx, int, 0644);
399 /* load firmware and/or nvram values from the filesystem */
400 module_param_string(firmware_path, firmware_path, MOD_PARAM_PATHLEN, 0660);
401 module_param_string(nvram_path, nvram_path, MOD_PARAM_PATHLEN, 0);
402 module_param_string(config_path, config_path, MOD_PARAM_PATHLEN, 0);
404 /* Watchdog interval */
406 /* extend watchdog expiration to 2 seconds when DPC is running */
407 #define WATCHDOG_EXTEND_INTERVAL (2000)
409 uint dhd_watchdog_ms = 10;
410 module_param(dhd_watchdog_ms, uint, 0);
412 #if defined(DHD_DEBUG)
413 /* Console poll interval */
414 uint dhd_console_ms = 0;
415 module_param(dhd_console_ms, uint, 0644);
416 #endif /* defined(DHD_DEBUG) */
418 uint dhd_slpauto = TRUE;
419 module_param(dhd_slpauto, uint, 0);
421 #ifdef PKT_FILTER_SUPPORT
422 /* Global Pkt filter enable control */
423 uint dhd_pkt_filter_enable = TRUE;
424 module_param(dhd_pkt_filter_enable, uint, 0);
427 /* Pkt filter init setup */
428 uint dhd_pkt_filter_init = 0;
429 module_param(dhd_pkt_filter_init, uint, 0);
431 /* Pkt filter mode control */
432 uint dhd_master_mode = TRUE;
433 module_param(dhd_master_mode, uint, 0);
436 int dhd_watchdog_prio = 0;
437 module_param(dhd_watchdog_prio, int, 0);
439 /* DPC thread priority */
440 int dhd_dpc_prio = CUSTOM_DPC_PRIO_SETTING;
441 module_param(dhd_dpc_prio, int, 0);
443 #ifdef RXFRAME_THREAD
444 /* RX frame thread priority */
445 int dhd_rxf_prio = CUSTOM_RXF_PRIO_SETTING;
446 module_param(dhd_rxf_prio, int, 0);
447 #endif /* RXFRAME_THREAD */
449 /* DPC thread priority, -1 to use tasklet */
450 extern int dhd_dongle_ramsize;
451 module_param(dhd_dongle_ramsize, int, 0);
452 #endif /* DHDTHREAD */
453 /* Control fw roaming */
455 uint dhd_roam_disable = 0;
457 uint dhd_roam_disable = 0;
460 /* Control radio state */
461 uint dhd_radio_up = 1;
463 /* Network inteface name */
464 char iface_name[IFNAMSIZ] = {'\0'};
465 module_param_string(iface_name, iface_name, IFNAMSIZ, 0);
467 /* The following are specific to the SDIO dongle */
469 /* IOCTL response timeout */
470 int dhd_ioctl_timeout_msec = IOCTL_RESP_TIMEOUT;
472 /* Idle timeout for backplane clock */
473 int dhd_idletime = DHD_IDLETIME_TICKS;
474 module_param(dhd_idletime, int, 0);
477 uint dhd_poll = FALSE;
478 module_param(dhd_poll, uint, 0);
481 uint dhd_intr = TRUE;
482 module_param(dhd_intr, uint, 0);
484 /* SDIO Drive Strength (in milliamps) */
485 uint dhd_sdiod_drive_strength = 6;
486 module_param(dhd_sdiod_drive_strength, uint, 0);
489 extern uint dhd_txbound;
490 extern uint dhd_rxbound;
491 module_param(dhd_txbound, uint, 0);
492 module_param(dhd_rxbound, uint, 0);
494 /* Deferred transmits */
495 extern uint dhd_deferred_tx;
496 module_param(dhd_deferred_tx, uint, 0);
499 extern void dhd_dbg_init(dhd_pub_t *dhdp);
500 extern void dhd_dbg_remove(void);
501 #endif /* BCMDBGFS */
506 /* Echo packet generator (pkts/s) */
508 module_param(dhd_pktgen, uint, 0);
510 /* Echo packet len (0 => sawtooth, max 2040) */
511 uint dhd_pktgen_len = 0;
512 module_param(dhd_pktgen_len, uint, 0);
515 /* Version string to report */
518 #define SRCBASE "drivers/net/wireless/bcmdhd"
520 #define DHD_COMPILED "\nCompiled in " SRCBASE
523 #endif /* DHD_DEBUG */
525 static char dhd_version[] = "Dongle Host Driver, version " EPI_VERSION_STR
527 "\nCompiled in " SRCBASE " on " __DATE__ " at " __TIME__
530 static void dhd_net_if_lock_local(dhd_info_t *dhd);
531 static void dhd_net_if_unlock_local(dhd_info_t *dhd);
532 static void dhd_suspend_lock(dhd_pub_t *dhdp);
533 static void dhd_suspend_unlock(dhd_pub_t *dhdp);
536 void htsf_update(dhd_info_t *dhd, void *data);
537 tsf_t prev_tsf, cur_tsf;
539 uint32 dhd_get_htsf(dhd_info_t *dhd, int ifidx);
540 static int dhd_ioctl_htsf_get(dhd_info_t *dhd, int ifidx);
541 static void dhd_dump_latency(void);
542 static void dhd_htsf_addtxts(dhd_pub_t *dhdp, void *pktbuf);
543 static void dhd_htsf_addrxts(dhd_pub_t *dhdp, void *pktbuf);
544 static void dhd_dump_htsfhisto(histo_t *his, char *s);
545 #endif /* WLMEDIA_HTSF */
547 /* Monitor interface */
548 int dhd_monitor_init(void *dhd_pub);
549 int dhd_monitor_uninit(void);
553 #if defined(WL_WIRELESS_EXT)
554 struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev);
555 #endif /* defined(WL_WIRELESS_EXT) */
557 static void dhd_dpc(ulong data);
559 extern int dhd_wait_pend8021x(struct net_device *dev);
560 void dhd_os_wd_timer_extend(void *bus, bool extend);
564 #error TOE requires BDC
566 static int dhd_toe_get(dhd_info_t *dhd, int idx, uint32 *toe_ol);
567 static int dhd_toe_set(dhd_info_t *dhd, int idx, uint32 toe_ol);
570 static int dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
571 wl_event_msg_t *event_ptr, void **data_ptr);
573 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && (LINUX_VERSION_CODE <= \
574 KERNEL_VERSION(2, 6, 39)) && defined(CONFIG_PM_SLEEP)
575 static int dhd_sleep_pm_callback(struct notifier_block *nfb, unsigned long action, void *ignored)
577 int ret = NOTIFY_DONE;
580 case PM_HIBERNATION_PREPARE:
581 case PM_SUSPEND_PREPARE:
582 dhd_mmc_suspend = TRUE;
585 case PM_POST_HIBERNATION:
586 case PM_POST_SUSPEND:
587 dhd_mmc_suspend = FALSE;
595 static struct notifier_block dhd_sleep_pm_notifier = {
596 .notifier_call = dhd_sleep_pm_callback,
599 extern int register_pm_notifier(struct notifier_block *nb);
600 extern int unregister_pm_notifier(struct notifier_block *nb);
601 #endif /* (LINUX_VERSION >= 2.6.27 && LINUX_VERSION <= 2.6.39 && CONFIG_PM_SLEEP */
603 #if defined(DHDTHREAD) && defined(RXFRAME_THREAD)
604 /* Request scheduling of the bus rx frame */
605 static void dhd_sched_rxf(dhd_pub_t *dhdp, void *skb);
606 static void dhd_os_rxflock(dhd_pub_t *pub);
607 static void dhd_os_rxfunlock(dhd_pub_t *pub);
609 static inline int dhd_rxf_enqueue(dhd_pub_t *dhdp, void* skb)
615 DHD_ERROR(("dhd_rxf_enqueue: NULL skb!!!\n"));
619 dhd_os_rxflock(dhdp);
620 store_idx = dhdp->store_idx;
621 sent_idx = dhdp->sent_idx;
622 if (dhdp->skbbuf[store_idx] != NULL) {
623 /* Make sure the previous packets are processed */
624 /* Do I need to make this context sleep here? Definitely in Single processor case */
625 dhd_os_rxfunlock(dhdp);
626 DHD_ERROR(("dhd_rxf_enqueue: pktbuf not consumed %p, store idx %d sent idx %d\n",
627 skb, store_idx, sent_idx));
631 DHD_TRACE(("dhd_rxf_enqueue: Store SKB %p. idx %d -> %d\n",
632 skb, store_idx, (store_idx + 1) & (MAXSKBPEND - 1)));
633 dhdp->skbbuf[store_idx] = skb;
634 dhdp->store_idx = (store_idx + 1) & (MAXSKBPEND - 1);
635 dhd_os_rxfunlock(dhdp);
640 static inline void* dhd_rxf_dequeue(dhd_pub_t *dhdp)
646 dhd_os_rxflock(dhdp);
648 store_idx = dhdp->store_idx;
649 sent_idx = dhdp->sent_idx;
650 skb = dhdp->skbbuf[sent_idx];
653 dhd_os_rxfunlock(dhdp);
654 DHD_ERROR(("dhd_rxf_dequeue: Dequeued packet is NULL, store idx %d sent idx %d\n",
655 store_idx, sent_idx));
659 dhdp->skbbuf[sent_idx] = NULL;
660 dhdp->sent_idx = (sent_idx + 1) & (MAXSKBPEND - 1);
662 DHD_TRACE(("dhd_rxf_dequeue: netif_rx_ni(%p), sent idx %d\n",
665 dhd_os_rxfunlock(dhdp);
669 #endif /* defined(DHDTHREAD) && defined(RXFRAME_THREAD) */
671 static int dhd_process_cid_mac(dhd_pub_t *dhdp, bool prepost)
673 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
675 if (prepost) { /* pre process */
676 dhd_read_macaddr(dhd);
677 } else { /* post process */
678 dhd_write_macaddr(&dhd->pub.mac);
684 #if defined(PKT_FILTER_SUPPORT) && !defined(GAN_LITE_NAT_KEEPALIVE_FILTER)
686 _turn_on_arp_filter(dhd_pub_t *dhd, int op_mode)
689 /* In case of IBSS mode, apply arp pkt filter */
690 if (op_mode & DHD_FLAG_IBSS_MODE) {
694 /* In case of P2P GO or GC, apply pkt filter to pass arp pkt to host */
695 if ((dhd->arp_version == 1) &&
696 (op_mode & (DHD_FLAG_P2P_GC_MODE | DHD_FLAG_P2P_GO_MODE))) {
704 #endif /* PKT_FILTER_SUPPORT && !GAN_LITE_NAT_KEEPALIVE_FILTER */
706 void dhd_set_packet_filter(dhd_pub_t *dhd)
708 #ifdef PKT_FILTER_SUPPORT
711 DHD_TRACE(("%s: enter\n", __FUNCTION__));
712 if (dhd_pkt_filter_enable) {
713 for (i = 0; i < dhd->pktfilter_count; i++) {
714 dhd_pktfilter_offload_set(dhd, dhd->pktfilter[i]);
717 #endif /* PKT_FILTER_SUPPORT */
720 void dhd_enable_packet_filter(int value, dhd_pub_t *dhd)
722 #ifdef PKT_FILTER_SUPPORT
725 DHD_TRACE(("%s: enter, value = %d\n", __FUNCTION__, value));
726 /* 1 - Enable packet filter, only allow unicast packet to send up */
727 /* 0 - Disable packet filter */
728 if (dhd_pkt_filter_enable && (!value ||
729 (dhd_support_sta_mode(dhd) && !dhd->dhcp_in_progress)))
731 for (i = 0; i < dhd->pktfilter_count; i++) {
732 #ifndef GAN_LITE_NAT_KEEPALIVE_FILTER
733 if (!dhd->conf->filter_out_all_packets &&
734 value && (i == DHD_ARP_FILTER_NUM) &&
735 !_turn_on_arp_filter(dhd, dhd->op_mode)) {
736 DHD_TRACE(("Do not turn on ARP white list pkt filter:"
737 "val %d, cnt %d, op_mode 0x%x\n",
738 value, i, dhd->op_mode));
741 #endif /* !GAN_LITE_NAT_KEEPALIVE_FILTER */
742 dhd_pktfilter_offload_enable(dhd, dhd->pktfilter[i],
743 value, dhd_master_mode);
746 #endif /* PKT_FILTER_SUPPORT */
749 static int dhd_set_suspend(int value, dhd_pub_t *dhd)
751 #ifndef SUPPORT_PM2_ONLY
752 int power_mode = PM_MAX;
753 #endif /* SUPPORT_PM2_ONLY */
754 /* wl_pkt_filter_enable_t enable_parm; */
756 int bcn_li_dtim = 0; /* Default bcn_li_dtim in resume mode is 0 */
757 uint roamvar = dhd->conf->roam_off_suspend;
762 DHD_TRACE(("%s: enter, value = %d in_suspend=%d\n",
763 __FUNCTION__, value, dhd->in_suspend));
765 dhd_suspend_lock(dhd);
767 if (value && dhd->in_suspend) {
768 #ifdef PKT_FILTER_SUPPORT
769 dhd->early_suspended = 1;
771 /* Kernel suspended */
772 DHD_ERROR(("%s: force extra Suspend setting\n", __FUNCTION__));
774 #ifndef SUPPORT_PM2_ONLY
775 dhd_wl_ioctl_cmd(dhd, WLC_SET_PM, (char *)&power_mode,
776 sizeof(power_mode), TRUE, 0);
777 #endif /* SUPPORT_PM2_ONLY */
779 /* Enable packet filter, only allow unicast packet to send up */
780 dhd_enable_packet_filter(1, dhd);
782 /* If DTIM skip is set up as default, force it to wake
783 * each third DTIM for better power savings. Note that
784 * one side effect is a chance to miss BC/MC packet.
786 bcn_li_dtim = dhd_get_suspend_bcn_li_dtim(dhd);
787 bcm_mkiovar("bcn_li_dtim", (char *)&bcn_li_dtim,
788 4, iovbuf, sizeof(iovbuf));
789 if (dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf),
791 DHD_ERROR(("%s: set dtim failed\n", __FUNCTION__));
793 /* Disable firmware roaming during suspend */
794 bcm_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf, sizeof(iovbuf));
795 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
797 #ifdef PKT_FILTER_SUPPORT
798 dhd->early_suspended = 0;
801 DHD_ERROR(("%s: Remove extra suspend setting\n", __FUNCTION__));
803 #ifndef SUPPORT_PM2_ONLY
804 power_mode = PM_FAST;
805 dhd_wl_ioctl_cmd(dhd, WLC_SET_PM, (char *)&power_mode,
806 sizeof(power_mode), TRUE, 0);
807 #endif /* SUPPORT_PM2_ONLY */
808 #ifdef PKT_FILTER_SUPPORT
809 /* disable pkt filter */
810 dhd_enable_packet_filter(0, dhd);
811 #endif /* PKT_FILTER_SUPPORT */
813 /* restore pre-suspend setting for dtim_skip */
814 bcm_mkiovar("bcn_li_dtim", (char *)&bcn_li_dtim,
815 4, iovbuf, sizeof(iovbuf));
817 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
818 roamvar = dhd_roam_disable;
819 bcm_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf, sizeof(iovbuf));
820 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
823 dhd_suspend_unlock(dhd);
828 static int dhd_suspend_resume_helper(struct dhd_info *dhd, int val, int force)
830 dhd_pub_t *dhdp = &dhd->pub;
833 DHD_OS_WAKE_LOCK(dhdp);
834 /* Set flag when early suspend was called */
835 dhdp->in_suspend = val;
836 if ((force || !dhdp->suspend_disable_flag) &&
837 dhd_support_sta_mode(dhdp))
839 ret = dhd_set_suspend(val, dhdp);
842 DHD_OS_WAKE_UNLOCK(dhdp);
846 #if defined(CONFIG_HAS_EARLYSUSPEND) && defined(DHD_USE_EARLYSUSPEND)
847 static void dhd_early_suspend(struct early_suspend *h)
849 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
850 DHD_TRACE_HW4(("%s: enter\n", __FUNCTION__));
853 dhd_suspend_resume_helper(dhd, 1, 0);
856 static void dhd_late_resume(struct early_suspend *h)
858 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
859 DHD_TRACE_HW4(("%s: enter\n", __FUNCTION__));
862 dhd_suspend_resume_helper(dhd, 0, 0);
864 #endif /* CONFIG_HAS_EARLYSUSPEND && DHD_USE_EARLYSUSPEND */
867 * Generalized timeout mechanism. Uses spin sleep with exponential back-off until
868 * the sleep time reaches one jiffy, then switches over to task delay. Usage:
870 * dhd_timeout_start(&tmo, usec);
871 * while (!dhd_timeout_expired(&tmo))
872 * if (poll_something())
874 * if (dhd_timeout_expired(&tmo))
879 dhd_timeout_start(dhd_timeout_t *tmo, uint usec)
884 tmo->tick = jiffies_to_usecs(1);
888 dhd_timeout_expired(dhd_timeout_t *tmo)
890 /* Does nothing the first call */
891 if (tmo->increment == 0) {
896 if (tmo->elapsed >= tmo->limit)
899 /* Add the delay that's about to take place */
900 tmo->elapsed += tmo->increment;
902 if (tmo->increment < tmo->tick) {
903 OSL_DELAY(tmo->increment);
905 if (tmo->increment > tmo->tick)
906 tmo->increment = tmo->tick;
908 wait_queue_head_t delay_wait;
909 DECLARE_WAITQUEUE(wait, current);
910 init_waitqueue_head(&delay_wait);
911 add_wait_queue(&delay_wait, &wait);
912 set_current_state(TASK_INTERRUPTIBLE);
914 remove_wait_queue(&delay_wait, &wait);
915 set_current_state(TASK_RUNNING);
922 dhd_net2idx(dhd_info_t *dhd, struct net_device *net)
927 while (i < DHD_MAX_IFS) {
928 if (dhd->iflist[i] && (dhd->iflist[i]->net == net))
936 struct net_device * dhd_idx2net(void *pub, int ifidx)
938 struct dhd_pub *dhd_pub = (struct dhd_pub *)pub;
939 struct dhd_info *dhd_info;
941 if (!dhd_pub || ifidx < 0 || ifidx >= DHD_MAX_IFS)
943 dhd_info = dhd_pub->info;
944 if (dhd_info && dhd_info->iflist[ifidx])
945 return dhd_info->iflist[ifidx]->net;
950 dhd_ifname2idx(dhd_info_t *dhd, char *name)
956 if (name == NULL || *name == '\0')
960 if (dhd->iflist[i] && !strncmp(dhd->iflist[i]->name, name, IFNAMSIZ))
963 DHD_TRACE(("%s: return idx %d for \"%s\"\n", __FUNCTION__, i, name));
965 return i; /* default - the primary interface */
969 dhd_ifname(dhd_pub_t *dhdp, int ifidx)
971 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
975 if (ifidx < 0 || ifidx >= DHD_MAX_IFS) {
976 DHD_ERROR(("%s: ifidx %d out of range\n", __FUNCTION__, ifidx));
980 if (dhd->iflist[ifidx] == NULL) {
981 DHD_ERROR(("%s: null i/f %d\n", __FUNCTION__, ifidx));
985 if (dhd->iflist[ifidx]->net)
986 return dhd->iflist[ifidx]->net->name;
992 dhd_bssidx2bssid(dhd_pub_t *dhdp, int idx)
995 dhd_info_t *dhd = (dhd_info_t *)dhdp;
998 for (i = 0; i < DHD_MAX_IFS; i++)
999 if (dhd->iflist[i] && dhd->iflist[i]->bssidx == idx)
1000 return dhd->iflist[i]->mac_addr;
1007 _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
1009 struct net_device *dev;
1010 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
1011 struct netdev_hw_addr *ha;
1013 struct dev_mc_list *mclist;
1015 uint32 allmulti, cnt;
1022 ASSERT(dhd && dhd->iflist[ifidx]);
1023 dev = dhd->iflist[ifidx]->net;
1026 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
1027 netif_addr_lock_bh(dev);
1029 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
1030 cnt = netdev_mc_count(dev);
1032 cnt = dev->mc_count;
1033 #endif /* LINUX_VERSION_CODE */
1035 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
1036 netif_addr_unlock_bh(dev);
1039 /* Determine initial value of allmulti flag */
1040 allmulti = (dev->flags & IFF_ALLMULTI) ? TRUE : FALSE;
1042 /* Send down the multicast list first. */
1045 buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETHER_ADDR_LEN);
1046 if (!(bufp = buf = MALLOC(dhd->pub.osh, buflen))) {
1047 DHD_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
1048 dhd_ifname(&dhd->pub, ifidx), cnt));
1052 strncpy(bufp, "mcast_list", buflen - 1);
1053 bufp[buflen - 1] = '\0';
1054 bufp += strlen("mcast_list") + 1;
1057 memcpy(bufp, &cnt, sizeof(cnt));
1058 bufp += sizeof(cnt);
1060 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
1061 netif_addr_lock_bh(dev);
1063 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
1064 netdev_for_each_mc_addr(ha, dev) {
1067 memcpy(bufp, ha->addr, ETHER_ADDR_LEN);
1068 bufp += ETHER_ADDR_LEN;
1072 for (mclist = dev->mc_list; (mclist && (cnt > 0));
1073 cnt--, mclist = mclist->next) {
1074 memcpy(bufp, (void *)mclist->dmi_addr, ETHER_ADDR_LEN);
1075 bufp += ETHER_ADDR_LEN;
1077 #endif /* LINUX_VERSION_CODE */
1079 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
1080 netif_addr_unlock_bh(dev);
1083 memset(&ioc, 0, sizeof(ioc));
1084 ioc.cmd = WLC_SET_VAR;
1089 ret = dhd_wl_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1091 DHD_ERROR(("%s: set mcast_list failed, cnt %d\n",
1092 dhd_ifname(&dhd->pub, ifidx), cnt));
1093 allmulti = cnt ? TRUE : allmulti;
1096 MFREE(dhd->pub.osh, buf, buflen);
1098 /* Now send the allmulti setting. This is based on the setting in the
1099 * net_device flags, but might be modified above to be turned on if we
1100 * were trying to set some addresses and dongle rejected it...
1103 buflen = sizeof("allmulti") + sizeof(allmulti);
1104 if (!(buf = MALLOC(dhd->pub.osh, buflen))) {
1105 DHD_ERROR(("%s: out of memory for allmulti\n", dhd_ifname(&dhd->pub, ifidx)));
1108 allmulti = htol32(allmulti);
1110 if (!bcm_mkiovar("allmulti", (void*)&allmulti, sizeof(allmulti), buf, buflen)) {
1111 DHD_ERROR(("%s: mkiovar failed for allmulti, datalen %d buflen %u\n",
1112 dhd_ifname(&dhd->pub, ifidx), (int)sizeof(allmulti), buflen));
1113 MFREE(dhd->pub.osh, buf, buflen);
1118 memset(&ioc, 0, sizeof(ioc));
1119 ioc.cmd = WLC_SET_VAR;
1124 ret = dhd_wl_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1126 DHD_ERROR(("%s: set allmulti %d failed\n",
1127 dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
1130 MFREE(dhd->pub.osh, buf, buflen);
1132 /* Finally, pick up the PROMISC flag as well, like the NIC driver does */
1134 allmulti = (dev->flags & IFF_PROMISC) ? TRUE : FALSE;
1135 allmulti = htol32(allmulti);
1137 memset(&ioc, 0, sizeof(ioc));
1138 ioc.cmd = WLC_SET_PROMISC;
1139 ioc.buf = &allmulti;
1140 ioc.len = sizeof(allmulti);
1143 ret = dhd_wl_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1145 DHD_ERROR(("%s: set promisc %d failed\n",
1146 dhd_ifname(&dhd->pub, ifidx), ltoh32(allmulti)));
1151 _dhd_set_mac_address(dhd_info_t *dhd, int ifidx, struct ether_addr *addr)
1157 if (!bcm_mkiovar("cur_etheraddr", (char*)addr, ETHER_ADDR_LEN, buf, 32)) {
1158 DHD_ERROR(("%s: mkiovar failed for cur_etheraddr\n", dhd_ifname(&dhd->pub, ifidx)));
1161 memset(&ioc, 0, sizeof(ioc));
1162 ioc.cmd = WLC_SET_VAR;
1167 ret = dhd_wl_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1169 DHD_ERROR(("%s: set cur_etheraddr failed\n", dhd_ifname(&dhd->pub, ifidx)));
1171 memcpy(dhd->iflist[ifidx]->net->dev_addr, addr, ETHER_ADDR_LEN);
1172 memcpy(dhd->pub.mac.octet, addr, ETHER_ADDR_LEN);
1179 extern struct net_device *ap_net_dev;
1180 extern tsk_ctl_t ap_eth_ctl; /* ap netdev heper thread ctl */
1184 dhd_op_if(dhd_if_t *ifp)
1187 int ret = 0, err = 0;
1189 unsigned long flags;
1192 if (!ifp || !ifp->info || !ifp->idx)
1194 ASSERT(ifp && ifp->info && ifp->idx); /* Virtual interfaces only */
1197 DHD_TRACE(("%s: idx %d, state %d\n", __FUNCTION__, ifp->idx, ifp->state));
1200 if (wl_cfg80211_is_progress_ifchange())
1204 switch (ifp->state) {
1207 * Delete the existing interface before overwriting it
1208 * in case we missed the WLC_E_IF_DEL event.
1210 if (ifp->net != NULL) {
1211 DHD_ERROR(("%s: ERROR: netdev:%s already exists, try free & unregister \n",
1212 __FUNCTION__, ifp->net->name));
1213 netif_stop_queue(ifp->net);
1214 unregister_netdev(ifp->net);
1215 free_netdev(ifp->net);
1217 /* Allocate etherdev, including space for private structure */
1218 if (!(ifp->net = alloc_etherdev(sizeof(dhd)))) {
1219 DHD_ERROR(("%s: OOM - alloc_etherdev(%d)\n", __FUNCTION__, sizeof(dhd)));
1223 strncpy(ifp->net->name, ifp->name, IFNAMSIZ);
1224 ifp->net->name[IFNAMSIZ - 1] = '\0';
1225 memcpy(netdev_priv(ifp->net), &dhd, sizeof(dhd));
1227 if (dhd->dhd_state & DHD_ATTACH_STATE_CFG80211)
1228 if (!wl_cfg80211_notify_ifadd(ifp->net, ifp->idx, ifp->bssidx,
1229 (void*)dhd_net_attach)) {
1230 ifp->state = DHD_IF_NONE;
1231 ifp->event2cfg80211 = TRUE;
1235 if ((err = dhd_net_attach(&dhd->pub, ifp->idx)) != 0) {
1236 DHD_ERROR(("%s: dhd_net_attach failed, err %d\n",
1237 __FUNCTION__, err));
1241 if (ap_fw_loaded && !(dhd->dhd_state & DHD_ATTACH_STATE_CFG80211)) {
1242 /* semaphore that the soft AP CODE waits on */
1243 flags = dhd_os_spin_lock(&dhd->pub);
1245 /* save ptr to wl0.1 netdev for use in wl_iw.c */
1246 ap_net_dev = ifp->net;
1247 /* signal to the SOFTAP 'sleeper' thread, wl0.1 is ready */
1248 up(&ap_eth_ctl.sema);
1249 dhd_os_spin_unlock(&dhd->pub, flags);
1252 DHD_TRACE(("\n ==== pid:%x, net_device for if:%s created ===\n\n",
1253 current->pid, ifp->net->name));
1254 ifp->state = DHD_IF_NONE;
1259 /* Make sure that we don't enter again here if .. */
1260 /* dhd_op_if is called again from some other context */
1261 ifp->state = DHD_IF_DELETING;
1262 if (ifp->net != NULL) {
1263 DHD_TRACE(("\n%s: got 'DHD_IF_DEL' state\n", __FUNCTION__));
1264 netif_stop_queue(ifp->net);
1266 if (dhd->dhd_state & DHD_ATTACH_STATE_CFG80211) {
1267 wl_cfg80211_ifdel_ops(ifp->net);
1270 unregister_netdev(ifp->net);
1271 ret = DHD_DEL_IF; /* Make sure the free_netdev() is called */
1273 if (dhd->dhd_state & DHD_ATTACH_STATE_CFG80211) {
1274 wl_cfg80211_notify_ifdel();
1279 case DHD_IF_DELETING:
1282 DHD_ERROR(("%s: bad op %d\n", __FUNCTION__, ifp->state));
1283 ASSERT(!ifp->state);
1288 ifp->set_multicast = FALSE;
1290 free_netdev(ifp->net);
1293 dhd->iflist[ifp->idx] = NULL;
1295 flags = dhd_os_spin_lock(&dhd->pub);
1296 if (ifp->net == ap_net_dev)
1297 ap_net_dev = NULL; /* NULL SOFTAP global wl0.1 as well */
1298 dhd_os_spin_unlock(&dhd->pub, flags);
1300 MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
1304 #ifdef DHDTCPACK_SUPPRESS
1305 uint dhd_use_tcpack_suppress = TRUE;
1306 module_param(dhd_use_tcpack_suppress, uint, FALSE);
1307 extern bool dhd_tcpack_suppress(dhd_pub_t *dhdp, void *pkt);
1308 #endif /* DHDTCPACK_SUPPRESS */
1311 _dhd_sysioc_thread(void *data)
1313 tsk_ctl_t *tsk = (tsk_ctl_t *)data;
1314 dhd_info_t *dhd = (dhd_info_t *)tsk->parent;
1315 struct ipv6_addr *iter, *next;
1319 unsigned long flags;
1322 while (down_interruptible(&tsk->sema) == 0) {
1324 SMP_RD_BARRIER_DEPENDS();
1325 if (tsk->terminated) {
1329 dhd_net_if_lock_local(dhd);
1330 DHD_OS_WAKE_LOCK(&dhd->pub);
1332 for (i = 0; i < DHD_MAX_IFS; i++) {
1333 if (dhd->iflist[i]) {
1334 DHD_TRACE(("%s: interface %d\n", __FUNCTION__, i));
1336 flags = dhd_os_spin_lock(&dhd->pub);
1337 in_ap = (ap_net_dev != NULL);
1338 dhd_os_spin_unlock(&dhd->pub, flags);
1340 if (dhd->iflist[i] && dhd->iflist[i]->state)
1341 dhd_op_if(dhd->iflist[i]);
1343 if (dhd->iflist[i] == NULL) {
1344 DHD_TRACE(("\n\n %s: interface %d just been removed,"
1345 "!\n\n", __FUNCTION__, i));
1349 if (in_ap && dhd->set_macaddress == i+1) {
1350 DHD_TRACE(("attempt to set MAC for %s in AP Mode,"
1351 "blocked. \n", dhd->iflist[i]->net->name));
1352 dhd->set_macaddress = 0;
1356 if (in_ap && dhd->iflist[i]->set_multicast) {
1357 DHD_TRACE(("attempt to set MULTICAST list for %s"
1358 "in AP Mode, blocked. \n", dhd->iflist[i]->net->name));
1359 dhd->iflist[i]->set_multicast = FALSE;
1363 if (dhd->pub.up == 0)
1365 if (dhd->iflist[i]->set_multicast) {
1366 dhd->iflist[i]->set_multicast = FALSE;
1367 _dhd_set_multicast_list(dhd, i);
1370 list_for_each_entry_safe(iter, next,
1371 &dhd->iflist[i]->ipv6_list, list) {
1372 spin_lock_bh(&dhd->iflist[i]->ipv6_lock);
1373 list_del(&iter->list);
1374 spin_unlock_bh(&dhd->iflist[i]->ipv6_lock);
1375 if (iter->ipv6_oper == DHD_IPV6_ADDR_ADD) {
1376 ret = dhd_ndo_enable(&dhd->pub, TRUE);
1378 DHD_ERROR(("%s: Enabling NDO Failed %d\n",
1379 __FUNCTION__, ret));
1382 ret = dhd_ndo_add_ip(&dhd->pub,
1383 (char*)&iter->ipv6_addr[0], i);
1385 DHD_ERROR(("%s: Adding host ip fail %d\n",
1386 __FUNCTION__, ret));
1390 ret = dhd_ndo_remove_ip(&dhd->pub, i);
1392 DHD_ERROR(("%s: Removing host ip fail %d\n",
1393 __FUNCTION__, ret));
1397 NATIVE_MFREE(dhd->pub.osh, iter, sizeof(struct ipv6_addr));
1399 if (dhd->set_macaddress == i+1) {
1400 dhd->set_macaddress = 0;
1401 if (_dhd_set_mac_address(dhd, i, &dhd->macvalue) == 0) {
1402 DHD_INFO(("%s: MACID is overwritten\n", __FUNCTION__));
1404 DHD_ERROR(("%s: _dhd_set_mac_address() failed\n",
1411 DHD_OS_WAKE_UNLOCK(&dhd->pub);
1412 dhd_net_if_unlock_local(dhd);
1414 DHD_TRACE(("%s: stopped\n", __FUNCTION__));
1415 complete_and_exit(&tsk->completed, 0);
1419 dhd_set_mac_address(struct net_device *dev, void *addr)
1423 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
1424 struct sockaddr *sa = (struct sockaddr *)addr;
1427 ifidx = dhd_net2idx(dhd, dev);
1428 if (ifidx == DHD_BAD_IF)
1431 ASSERT(dhd->thr_sysioc_ctl.thr_pid >= 0);
1432 memcpy(&dhd->macvalue, sa->sa_data, ETHER_ADDR_LEN);
1433 dhd->set_macaddress = ifidx+1;
1434 up(&dhd->thr_sysioc_ctl.sema);
1440 dhd_set_multicast_list(struct net_device *dev)
1442 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
1445 ifidx = dhd_net2idx(dhd, dev);
1446 if (ifidx == DHD_BAD_IF)
1449 ASSERT(dhd->thr_sysioc_ctl.thr_pid >= 0);
1450 dhd->iflist[ifidx]->set_multicast = TRUE;
1451 up(&dhd->thr_sysioc_ctl.sema);
1454 #ifdef PROP_TXSTATUS
1456 dhd_os_wlfc_block(dhd_pub_t *pub)
1458 dhd_info_t *di = (dhd_info_t *)(pub->info);
1460 spin_lock_bh(&di->wlfc_spinlock);
1465 dhd_os_wlfc_unblock(dhd_pub_t *pub)
1467 dhd_info_t *di = (dhd_info_t *)(pub->info);
1470 spin_unlock_bh(&di->wlfc_spinlock);
1474 const uint8 wme_fifo2ac[] = { 0, 1, 2, 3, 1, 1 };
1475 uint8 prio2fifo[8] = { 1, 0, 0, 1, 2, 2, 3, 3 };
1476 #define WME_PRIO2AC(prio) wme_fifo2ac[prio2fifo[(prio)]]
1478 #endif /* PROP_TXSTATUS */
1480 dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pktbuf)
1483 dhd_info_t *dhd = (dhd_info_t *)(dhdp->info);
1484 struct ether_header *eh = NULL;
1486 /* Reject if down */
1487 if (!dhdp->up || (dhdp->busstate == DHD_BUS_DOWN)) {
1488 /* free the packet here since the caller won't */
1489 PKTFREE(dhdp->osh, pktbuf, TRUE);
1493 /* Update multicast statistic */
1494 if (PKTLEN(dhdp->osh, pktbuf) >= ETHER_HDR_LEN) {
1495 uint8 *pktdata = (uint8 *)PKTDATA(dhdp->osh, pktbuf);
1496 eh = (struct ether_header *)pktdata;
1498 if (ETHER_ISMULTI(eh->ether_dhost))
1499 dhdp->tx_multicast++;
1500 if (ntoh16(eh->ether_type) == ETHER_TYPE_802_1X)
1501 atomic_inc(&dhd->pend_8021x_cnt);
1503 PKTFREE(dhd->pub.osh, pktbuf, TRUE);
1507 /* Look into the packet and update the packet priority */
1508 #ifndef PKTPRIO_OVERRIDE
1509 if (PKTPRIO(pktbuf) == 0)
1511 pktsetprio(pktbuf, FALSE);
1513 #ifdef PROP_TXSTATUS
1514 if (dhdp->wlfc_state) {
1515 /* store the interface ID */
1516 DHD_PKTTAG_SETIF(PKTTAG(pktbuf), ifidx);
1518 /* store destination MAC in the tag as well */
1519 DHD_PKTTAG_SETDSTN(PKTTAG(pktbuf), eh->ether_dhost);
1521 /* decide which FIFO this packet belongs to */
1522 if (ETHER_ISMULTI(eh->ether_dhost))
1523 /* one additional queue index (highest AC + 1) is used for bc/mc queue */
1524 DHD_PKTTAG_SETFIFO(PKTTAG(pktbuf), AC_COUNT);
1526 DHD_PKTTAG_SETFIFO(PKTTAG(pktbuf), WME_PRIO2AC(PKTPRIO(pktbuf)));
1528 #endif /* PROP_TXSTATUS */
1529 /* If the protocol uses a data header, apply it */
1530 dhd_prot_hdrpush(dhdp, ifidx, pktbuf);
1532 /* Use bus module to send data frame */
1534 dhd_htsf_addtxts(dhdp, pktbuf);
1536 #ifdef DHDTCPACK_SUPPRESS
1537 if (dhd_use_tcpack_suppress && dhd_tcpack_suppress(dhdp, pktbuf))
1540 #endif /* DHDTCPACK_SUPPRESS */
1541 #ifdef PROP_TXSTATUS
1543 dhd_os_wlfc_block(dhdp);
1544 if (dhdp->wlfc_state && ((athost_wl_status_info_t*)dhdp->wlfc_state)->proptxstatus_mode
1545 != WLFC_FCMODE_NONE) {
1546 dhd_wlfc_commit_packets(dhdp->wlfc_state, (f_commitpkt_t)dhd_bus_txdata,
1548 if (((athost_wl_status_info_t*)dhdp->wlfc_state)->toggle_host_if) {
1549 ((athost_wl_status_info_t*)dhdp->wlfc_state)->toggle_host_if = 0;
1551 dhd_os_wlfc_unblock(dhdp);
1554 dhd_os_wlfc_unblock(dhdp);
1555 /* non-proptxstatus way */
1556 ret = dhd_bus_txdata(dhdp->bus, pktbuf);
1560 ret = dhd_bus_txdata(dhdp->bus, pktbuf);
1561 #endif /* PROP_TXSTATUS */
1567 dhd_start_xmit(struct sk_buff *skb, struct net_device *net)
1572 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
1573 dhd_if_t *ifp = NULL;
1576 uint8 htsfdlystat_sz = dhd->pub.htsfdlystat_sz;
1578 uint8 htsfdlystat_sz = 0;
1581 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
1583 DHD_OS_WAKE_LOCK(&dhd->pub);
1585 /* Reject if down */
1586 if (dhd->pub.busstate == DHD_BUS_DOWN || dhd->pub.hang_was_sent) {
1587 DHD_ERROR(("%s: xmit rejected pub.up=%d busstate=%d \n",
1588 __FUNCTION__, dhd->pub.up, dhd->pub.busstate));
1589 netif_stop_queue(net);
1590 /* Send Event when bus down detected during data session */
1592 DHD_ERROR(("%s: Event HANG sent up\n", __FUNCTION__));
1593 net_os_send_hang_message(net);
1595 DHD_OS_WAKE_UNLOCK(&dhd->pub);
1596 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20))
1599 return NETDEV_TX_BUSY;
1603 ifidx = dhd_net2idx(dhd, net);
1604 if (ifidx == DHD_BAD_IF) {
1605 DHD_ERROR(("%s: bad ifidx %d\n", __FUNCTION__, ifidx));
1606 netif_stop_queue(net);
1607 DHD_OS_WAKE_UNLOCK(&dhd->pub);
1608 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20))
1611 return NETDEV_TX_BUSY;
1615 ifp = dhd->iflist[ifidx];
1616 datalen = PKTLEN(dhdp->osh, skb);
1618 /* Make sure there's enough room for any header */
1620 if (skb_headroom(skb) < dhd->pub.hdrlen + htsfdlystat_sz) {
1621 struct sk_buff *skb2;
1623 DHD_INFO(("%s: insufficient headroom\n",
1624 dhd_ifname(&dhd->pub, ifidx)));
1625 dhd->pub.tx_realloc++;
1627 skb2 = skb_realloc_headroom(skb, dhd->pub.hdrlen + htsfdlystat_sz);
1630 if ((skb = skb2) == NULL) {
1631 DHD_ERROR(("%s: skb_realloc_headroom failed\n",
1632 dhd_ifname(&dhd->pub, ifidx)));
1638 /* Convert to packet */
1639 if (!(pktbuf = PKTFRMNATIVE(dhd->pub.osh, skb))) {
1640 DHD_ERROR(("%s: PKTFRMNATIVE failed\n",
1641 dhd_ifname(&dhd->pub, ifidx)));
1642 dev_kfree_skb_any(skb);
1647 if (htsfdlystat_sz && PKTLEN(dhd->pub.osh, pktbuf) >= ETHER_ADDR_LEN) {
1648 uint8 *pktdata = (uint8 *)PKTDATA(dhd->pub.osh, pktbuf);
1649 struct ether_header *eh = (struct ether_header *)pktdata;
1651 if (!ETHER_ISMULTI(eh->ether_dhost) &&
1652 (ntoh16(eh->ether_type) == ETHER_TYPE_IP)) {
1653 eh->ether_type = hton16(ETHER_TYPE_BRCM_PKTDLYSTATS);
1658 ret = dhd_sendpkt(&dhd->pub, ifidx, pktbuf);
1662 ifp->stats.tx_dropped++;
1665 dhd->pub.tx_packets++;
1666 ifp->stats.tx_packets++;
1667 ifp->stats.tx_bytes += datalen;
1670 DHD_OS_WAKE_UNLOCK(&dhd->pub);
1672 /* Return ok: we always eat the packet */
1673 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20))
1676 return NETDEV_TX_OK;
1681 dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool state)
1683 struct net_device *net;
1684 dhd_info_t *dhd = dhdp->info;
1687 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
1691 if (ifidx == ALL_INTERFACES) {
1692 /* Flow control on all active interfaces */
1693 dhdp->txoff = state;
1694 for (i = 0; i < DHD_MAX_IFS; i++) {
1695 if (dhd->iflist[i]) {
1696 net = dhd->iflist[i]->net;
1698 netif_stop_queue(net);
1700 netif_wake_queue(net);
1705 if (dhd->iflist[ifidx]) {
1706 net = dhd->iflist[ifidx]->net;
1708 netif_stop_queue(net);
1710 netif_wake_queue(net);
1721 static const PKTTYPE_INFO packet_type_info[] =
1723 { ETHER_TYPE_IP, "IP" },
1724 { ETHER_TYPE_ARP, "ARP" },
1725 { ETHER_TYPE_BRCM, "BRCM" },
1726 { ETHER_TYPE_802_1X, "802.1X" },
1727 { ETHER_TYPE_WAI, "WAPI" },
1731 static const char *_get_packet_type_str(uint16 type)
1734 int n = sizeof(packet_type_info)/sizeof(packet_type_info[1]) - 1;
1736 for (i = 0; i < n; i++) {
1737 if (packet_type_info[i].type == type)
1738 return packet_type_info[i].str;
1741 return packet_type_info[n].str;
1743 #endif /* DHD_RX_DUMP */
1746 dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *pktbuf, int numpkt, uint8 chan)
1748 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
1749 struct sk_buff *skb;
1752 void *data, *pnext = NULL;
1755 wl_event_msg_t event;
1758 #if defined(DHDTHREAD) && defined(RXFRAME_THREAD)
1759 void *skbhead = NULL;
1760 void *skbprev = NULL;
1761 #endif /* defined(DHDTHREAD) && defined(RXFRAME_THREAD) */
1763 #ifdef DHD_RX_FULL_DUMP
1765 #endif /* DHD_RX_FULL_DUMP */
1768 #endif /* DHD_RX_DUMP */
1770 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
1772 for (i = 0; pktbuf && i < numpkt; i++, pktbuf = pnext) {
1774 struct ether_header *eh;
1775 struct dot11_llc_snap_header *lsh;
1778 pnext = PKTNEXT(dhdp->osh, pktbuf);
1779 PKTSETNEXT(wl->sh.osh, pktbuf, NULL);
1781 ifp = dhd->iflist[ifidx];
1783 DHD_ERROR(("%s: ifp is NULL. drop packet\n",
1785 PKTFREE(dhdp->osh, pktbuf, TRUE);
1788 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
1789 /* Dropping packets before registering net device to avoid kernel panic */
1790 #ifndef PROP_TXSTATUS_VSDB
1791 if (!ifp->net || ifp->net->reg_state != NETREG_REGISTERED)
1793 if (!ifp->net || ifp->net->reg_state != NETREG_REGISTERED || !dhd->pub.up)
1794 #endif /* PROP_TXSTATUS_VSDB */
1796 DHD_ERROR(("%s: net device is NOT registered yet. drop packet\n",
1798 PKTFREE(dhdp->osh, pktbuf, TRUE);
1801 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) */
1804 eh = (struct ether_header *)PKTDATA(wl->sh.osh, pktbuf);
1805 lsh = (struct dot11_llc_snap_header *)&eh[1];
1807 if ((ntoh16(eh->ether_type) < ETHER_TYPE_MIN) &&
1808 (PKTLEN(wl->sh.osh, pktbuf) >= RFC1042_HDR_LEN) &&
1809 bcmp(lsh, BT_SIG_SNAP_MPROT, DOT11_LLC_SNAP_HDR_LEN - 2) == 0 &&
1810 lsh->type == HTON16(BTA_PROT_L2CAP)) {
1811 amp_hci_ACL_data_t *ACL_data = (amp_hci_ACL_data_t *)
1812 ((uint8 *)eh + RFC1042_HDR_LEN);
1815 #endif /* WLBTAMP */
1817 #ifdef PROP_TXSTATUS
1818 if (dhdp->wlfc_state && PKTLEN(wl->sh.osh, pktbuf) == 0) {
1819 /* WLFC may send header only packet when
1820 there is an urgent message but no packet to
1823 ((athost_wl_status_info_t*)dhdp->wlfc_state)->stats.wlfc_header_only_pkt++;
1824 PKTFREE(dhdp->osh, pktbuf, TRUE);
1829 skb = PKTTONATIVE(dhdp->osh, pktbuf);
1831 /* Get the protocol, maintain skb around eth_type_trans()
1832 * The main reason for this hack is for the limitation of
1833 * Linux 2.4 where 'eth_type_trans' uses the 'net->hard_header_len'
1834 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
1835 * coping of the packet coming from the network stack to add
1836 * BDC, Hardware header etc, during network interface registration
1837 * we set the 'net->hard_header_len' to ETH_HLEN + extra space required
1838 * for BDC, Hardware header etc. and not just the ETH_HLEN
1844 dump_data = skb->data;
1845 protocol = (dump_data[12] << 8) | dump_data[13];
1846 DHD_ERROR(("RX DUMP - %s\n", _get_packet_type_str(protocol)));
1848 #ifdef DHD_RX_FULL_DUMP
1849 if (protocol != ETHER_TYPE_BRCM) {
1850 for (k = 0; k < skb->len; k++) {
1851 DHD_ERROR(("%02X ", dump_data[k]));
1857 #endif /* DHD_RX_FULL_DUMP */
1859 if (protocol != ETHER_TYPE_BRCM) {
1860 if (dump_data[0] == 0xFF) {
1861 DHD_ERROR(("%s: BROADCAST\n", __FUNCTION__));
1863 if ((dump_data[12] == 8) &&
1864 (dump_data[13] == 6)) {
1865 DHD_ERROR(("%s: ARP %d\n",
1866 __FUNCTION__, dump_data[0x15]));
1868 } else if (dump_data[0] & 1) {
1869 DHD_ERROR(("%s: MULTICAST: " MACDBG "\n",
1870 __FUNCTION__, MAC2STRDBG(dump_data)));
1873 if (protocol == ETHER_TYPE_802_1X) {
1874 DHD_ERROR(("ETHER_TYPE_802_1X: "
1875 "ver %d, type %d, replay %d\n",
1876 dump_data[14], dump_data[15],
1881 #endif /* DHD_RX_DUMP */
1883 ifp = dhd->iflist[ifidx];
1885 ifp = dhd->iflist[0];
1888 skb->dev = ifp->net;
1889 skb->protocol = eth_type_trans(skb, skb->dev);
1891 if (skb->pkt_type == PACKET_MULTICAST) {
1892 dhd->pub.rx_multicast++;
1899 dhd_htsf_addrxts(dhdp, pktbuf);
1901 /* Strip header, count, deliver upward */
1902 skb_pull(skb, ETH_HLEN);
1904 /* Process special event packets and then discard them */
1905 memset(&event, 0, sizeof(event));
1906 if (ntoh16(skb->protocol) == ETHER_TYPE_BRCM) {
1907 dhd_wl_host_event(dhd, &ifidx,
1908 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 22)
1909 skb_mac_header(skb),
1916 wl_event_to_host_order(&event);
1918 tout_ctrl = DHD_PACKET_TIMEOUT_MS;
1920 if (event.event_type == WLC_E_BTA_HCI_EVENT) {
1921 dhd_bta_doevt(dhdp, data, event.datalen);
1923 #endif /* WLBTAMP */
1925 #if defined(PNO_SUPPORT)
1926 if (event.event_type == WLC_E_PFN_NET_FOUND) {
1927 /* enforce custom wake lock to garantee that Kernel not suspended */
1928 tout_ctrl = CUSTOM_PNO_EVENT_LOCK_xTIME * DHD_PACKET_TIMEOUT_MS;
1930 #endif /* PNO_SUPPORT */
1932 #ifdef DHD_DONOT_FORWARD_BCMEVENT_AS_NETWORK_PKT
1933 PKTFREE(dhdp->osh, pktbuf, TRUE);
1937 tout_rx = DHD_PACKET_TIMEOUT_MS;
1940 ASSERT(ifidx < DHD_MAX_IFS && dhd->iflist[ifidx]);
1941 if (dhd->iflist[ifidx] && !dhd->iflist[ifidx]->state)
1942 ifp = dhd->iflist[ifidx];
1945 ifp->net->last_rx = jiffies;
1947 dhdp->dstats.rx_bytes += skb->len;
1948 dhdp->rx_packets++; /* Local count */
1949 ifp->stats.rx_bytes += skb->len;
1950 ifp->stats.rx_packets++;
1952 if (in_interrupt()) {
1955 /* If the receive is not processed inside an ISR,
1956 * the softirqd must be woken explicitly to service
1957 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
1958 * by netif_rx_ni(), but in earlier kernels, we need
1959 * to do it manually.
1961 #if defined(DHDTHREAD) && defined(RXFRAME_THREAD)
1965 PKTSETNEXT(wl->sh.osh, skbprev, skb);
1968 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
1973 local_irq_save(flags);
1975 local_irq_restore(flags);
1976 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) */
1977 #endif /* defined(DHDTHREAD) && defined(RXFRAME_THREAD) */
1980 #if defined(DHDTHREAD) && defined(RXFRAME_THREAD)
1982 dhd_sched_rxf(dhdp, skbhead);
1984 DHD_OS_WAKE_LOCK_RX_TIMEOUT_ENABLE(dhdp, tout_rx);
1985 DHD_OS_WAKE_LOCK_CTRL_TIMEOUT_ENABLE(dhdp, tout_ctrl);
1989 dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx)
1991 /* Linux version has nothing to do */
1996 dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success)
1998 dhd_info_t *dhd = (dhd_info_t *)(dhdp->info);
1999 struct ether_header *eh;
2005 dhd_prot_hdrpull(dhdp, NULL, txp, NULL, NULL);
2007 eh = (struct ether_header *)PKTDATA(dhdp->osh, txp);
2008 type = ntoh16(eh->ether_type);
2010 if (type == ETHER_TYPE_802_1X)
2011 atomic_dec(&dhd->pend_8021x_cnt);
2014 /* Crack open the packet and check to see if it is BT HCI ACL data packet.
2015 * If yes generate packet completion event.
2017 len = PKTLEN(dhdp->osh, txp);
2019 /* Generate ACL data tx completion event locally to avoid SDIO bus transaction */
2020 if ((type < ETHER_TYPE_MIN) && (len >= RFC1042_HDR_LEN)) {
2021 struct dot11_llc_snap_header *lsh = (struct dot11_llc_snap_header *)&eh[1];
2023 if (bcmp(lsh, BT_SIG_SNAP_MPROT, DOT11_LLC_SNAP_HDR_LEN - 2) == 0 &&
2024 ntoh16(lsh->type) == BTA_PROT_L2CAP) {
2026 dhd_bta_tx_hcidata_complete(dhdp, txp, success);
2029 #endif /* WLBTAMP */
2032 static struct net_device_stats *
2033 dhd_get_stats(struct net_device *net)
2035 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
2039 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
2041 ifidx = dhd_net2idx(dhd, net);
2042 if (ifidx == DHD_BAD_IF) {
2043 DHD_ERROR(("%s: BAD_IF\n", __FUNCTION__));
2047 ifp = dhd->iflist[ifidx];
2051 /* Use the protocol to get dongle stats */
2052 dhd_prot_dstats(&dhd->pub);
2055 /* Copy dongle stats to net device stats */
2056 ifp->stats.rx_packets = dhd->pub.dstats.rx_packets;
2057 ifp->stats.tx_packets = dhd->pub.dstats.tx_packets;
2058 ifp->stats.rx_bytes = dhd->pub.dstats.rx_bytes;
2059 ifp->stats.tx_bytes = dhd->pub.dstats.tx_bytes;
2060 ifp->stats.rx_errors = dhd->pub.dstats.rx_errors;
2061 ifp->stats.tx_errors = dhd->pub.dstats.tx_errors;
2062 ifp->stats.rx_dropped = dhd->pub.dstats.rx_dropped;
2063 ifp->stats.tx_dropped = dhd->pub.dstats.tx_dropped;
2064 ifp->stats.multicast = dhd->pub.dstats.multicast;
2071 dhd_watchdog_thread(void *data)
2073 tsk_ctl_t *tsk = (tsk_ctl_t *)data;
2074 dhd_info_t *dhd = (dhd_info_t *)tsk->parent;
2075 /* This thread doesn't need any user-level access,
2076 * so get rid of all our resources
2078 if (dhd_watchdog_prio > 0) {
2079 struct sched_param param;
2080 param.sched_priority = (dhd_watchdog_prio < MAX_RT_PRIO)?
2081 dhd_watchdog_prio:(MAX_RT_PRIO-1);
2082 setScheduler(current, SCHED_FIFO, ¶m);
2086 if (down_interruptible (&tsk->sema) == 0) {
2087 unsigned long flags;
2088 unsigned long jiffies_at_start = jiffies;
2089 unsigned long time_lapse;
2091 SMP_RD_BARRIER_DEPENDS();
2092 if (tsk->terminated) {
2096 dhd_os_sdlock(&dhd->pub);
2097 if (dhd->pub.dongle_reset == FALSE) {
2098 DHD_TIMER(("%s:\n", __FUNCTION__));
2100 /* Call the bus module watchdog */
2101 dhd_bus_watchdog(&dhd->pub);
2103 flags = dhd_os_spin_lock(&dhd->pub);
2104 /* Count the tick for reference */
2106 time_lapse = jiffies - jiffies_at_start;
2108 /* Reschedule the watchdog */
2109 if (dhd->wd_timer_valid)
2110 mod_timer(&dhd->timer,
2112 msecs_to_jiffies(dhd_watchdog_ms) -
2113 min(msecs_to_jiffies(dhd_watchdog_ms), time_lapse));
2114 dhd_os_spin_unlock(&dhd->pub, flags);
2116 dhd_os_sdunlock(&dhd->pub);
2121 complete_and_exit(&tsk->completed, 0);
2123 #endif /* DHDTHREAD */
2125 static void dhd_watchdog(ulong data)
2127 dhd_info_t *dhd = (dhd_info_t *)data;
2128 unsigned long flags;
2130 if (dhd->pub.dongle_reset) {
2135 if (dhd->thr_wdt_ctl.thr_pid >= 0) {
2136 up(&dhd->thr_wdt_ctl.sema);
2139 #endif /* DHDTHREAD */
2141 dhd_os_sdlock(&dhd->pub);
2142 /* Call the bus module watchdog */
2143 dhd_bus_watchdog(&dhd->pub);
2145 flags = dhd_os_spin_lock(&dhd->pub);
2146 /* Count the tick for reference */
2149 /* Reschedule the watchdog */
2150 if (dhd->wd_timer_valid)
2151 mod_timer(&dhd->timer, jiffies + msecs_to_jiffies(dhd_watchdog_ms));
2152 dhd_os_spin_unlock(&dhd->pub, flags);
2153 dhd_os_sdunlock(&dhd->pub);
2158 dhd_dpc_thread(void *data)
2160 tsk_ctl_t *tsk = (tsk_ctl_t *)data;
2161 dhd_info_t *dhd = (dhd_info_t *)tsk->parent;
2163 /* This thread doesn't need any user-level access,
2164 * so get rid of all our resources
2166 if (dhd_dpc_prio > 0)
2168 struct sched_param param;
2169 param.sched_priority = (dhd_dpc_prio < MAX_RT_PRIO)?dhd_dpc_prio:(MAX_RT_PRIO-1);
2170 setScheduler(current, SCHED_FIFO, ¶m);
2173 #ifdef CUSTOM_DPC_CPUCORE
2174 set_cpus_allowed_ptr(current, cpumask_of(CUSTOM_DPC_CPUCORE));
2175 #endif /* CUSTOM_DPC_CPUCORE */
2177 /* Run until signal received */
2179 if (!binary_sema_down(tsk)) {
2181 SMP_RD_BARRIER_DEPENDS();
2182 if (tsk->terminated) {
2186 /* Call bus dpc unless it indicated down (then clean stop) */
2187 if (dhd->pub.busstate != DHD_BUS_DOWN) {
2188 dhd_os_wd_timer_extend(&dhd->pub, TRUE);
2189 while (dhd_bus_dpc(dhd->pub.bus)) {
2190 /* process all data */
2192 dhd_os_wd_timer_extend(&dhd->pub, FALSE);
2193 DHD_OS_WAKE_UNLOCK(&dhd->pub);
2196 dhd_bus_stop(dhd->pub.bus, TRUE);
2197 DHD_OS_WAKE_UNLOCK(&dhd->pub);
2204 complete_and_exit(&tsk->completed, 0);
2207 #ifdef RXFRAME_THREAD
2209 dhd_rxf_thread(void *data)
2211 tsk_ctl_t *tsk = (tsk_ctl_t *)data;
2212 dhd_info_t *dhd = (dhd_info_t *)tsk->parent;
2213 dhd_pub_t *pub = &dhd->pub;
2215 /* This thread doesn't need any user-level access,
2216 * so get rid of all our resources
2218 if (dhd_rxf_prio > 0)
2220 struct sched_param param;
2221 param.sched_priority = (dhd_rxf_prio < MAX_RT_PRIO)?dhd_rxf_prio:(MAX_RT_PRIO-1);
2222 setScheduler(current, SCHED_FIFO, ¶m);
2225 DAEMONIZE("dhd_rxf");
2226 /* DHD_OS_WAKE_LOCK is called in dhd_sched_dpc[dhd_linux.c] down below */
2228 /* signal: thread has started */
2229 complete(&tsk->completed);
2231 /* Run until signal received */
2233 if (down_interruptible(&tsk->sema) == 0) {
2235 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
2239 SMP_RD_BARRIER_DEPENDS();
2241 if (tsk->terminated) {
2244 skb = dhd_rxf_dequeue(pub);
2250 void *skbnext = PKTNEXT(pub->osh, skb);
2251 PKTSETNEXT(pub->osh, skb, NULL);
2253 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
2257 local_irq_save(flags);
2259 local_irq_restore(flags);
2265 DHD_OS_WAKE_UNLOCK(pub);
2271 complete_and_exit(&tsk->completed, 0);
2273 #endif /* RXFRAME_THREAD */
2274 #endif /* DHDTHREAD */
2281 dhd = (dhd_info_t *)data;
2283 /* this (tasklet) can be scheduled in dhd_sched_dpc[dhd_linux.c]
2284 * down below , wake lock is set,
2285 * the tasklet is initialized in dhd_attach()
2287 /* Call bus dpc unless it indicated down (then clean stop) */
2288 if (dhd->pub.busstate != DHD_BUS_DOWN) {
2289 if (dhd_bus_dpc(dhd->pub.bus))
2290 tasklet_schedule(&dhd->tasklet);
2292 DHD_OS_WAKE_UNLOCK(&dhd->pub);
2294 dhd_bus_stop(dhd->pub.bus, TRUE);
2295 DHD_OS_WAKE_UNLOCK(&dhd->pub);
2300 dhd_sched_dpc(dhd_pub_t *dhdp)
2302 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
2304 DHD_OS_WAKE_LOCK(dhdp);
2306 if (dhd->thr_dpc_ctl.thr_pid >= 0) {
2307 /* If the semaphore does not get up,
2308 * wake unlock should be done here
2310 if (!binary_sema_up(&dhd->thr_dpc_ctl))
2311 DHD_OS_WAKE_UNLOCK(dhdp);
2314 #endif /* DHDTHREAD */
2316 if (dhd->dhd_tasklet_create)
2317 tasklet_schedule(&dhd->tasklet);
2320 #if defined(DHDTHREAD) && defined(RXFRAME_THREAD)
2322 dhd_sched_rxf(dhd_pub_t *dhdp, void *skb)
2324 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
2326 DHD_OS_WAKE_LOCK(dhdp);
2328 DHD_TRACE(("dhd_sched_rxf: Enter\n"));
2331 if (dhd_rxf_enqueue(dhdp, skb) == BCME_OK)
2334 if (dhd->thr_rxf_ctl.thr_pid >= 0) {
2335 up(&dhd->thr_rxf_ctl.sema);
2339 #endif /* defined(DHDTHREAD) && defined(RXFRAME_THREAD) */
2342 /* Retrieve current toe component enables, which are kept as a bitmap in toe_ol iovar */
2344 dhd_toe_get(dhd_info_t *dhd, int ifidx, uint32 *toe_ol)
2350 memset(&ioc, 0, sizeof(ioc));
2352 ioc.cmd = WLC_GET_VAR;
2354 ioc.len = (uint)sizeof(buf);
2357 strncpy(buf, "toe_ol", sizeof(buf) - 1);
2358 buf[sizeof(buf) - 1] = '\0';
2359 if ((ret = dhd_wl_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len)) < 0) {
2360 /* Check for older dongle image that doesn't support toe_ol */
2362 DHD_ERROR(("%s: toe not supported by device\n",
2363 dhd_ifname(&dhd->pub, ifidx)));
2367 DHD_INFO(("%s: could not get toe_ol: ret=%d\n", dhd_ifname(&dhd->pub, ifidx), ret));
2371 memcpy(toe_ol, buf, sizeof(uint32));
2375 /* Set current toe component enables in toe_ol iovar, and set toe global enable iovar */
2377 dhd_toe_set(dhd_info_t *dhd, int ifidx, uint32 toe_ol)
2383 memset(&ioc, 0, sizeof(ioc));
2385 ioc.cmd = WLC_SET_VAR;
2387 ioc.len = (uint)sizeof(buf);
2390 /* Set toe_ol as requested */
2392 strncpy(buf, "toe_ol", sizeof(buf) - 1);
2393 buf[sizeof(buf) - 1] = '\0';
2394 memcpy(&buf[sizeof("toe_ol")], &toe_ol, sizeof(uint32));
2396 if ((ret = dhd_wl_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len)) < 0) {
2397 DHD_ERROR(("%s: could not set toe_ol: ret=%d\n",
2398 dhd_ifname(&dhd->pub, ifidx), ret));
2402 /* Enable toe globally only if any components are enabled. */
2404 toe = (toe_ol != 0);
2407 memcpy(&buf[sizeof("toe")], &toe, sizeof(uint32));
2409 if ((ret = dhd_wl_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len)) < 0) {
2410 DHD_ERROR(("%s: could not set toe: ret=%d\n", dhd_ifname(&dhd->pub, ifidx), ret));
2418 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
2420 dhd_ethtool_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *info)
2422 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
2424 snprintf(info->driver, sizeof(info->driver), "wl");
2425 snprintf(info->version, sizeof(info->version), "%lu", dhd->pub.drv_version);
2428 struct ethtool_ops dhd_ethtool_ops = {
2429 .get_drvinfo = dhd_ethtool_get_drvinfo
2431 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) */
2434 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 4, 2)
2436 dhd_ethtool(dhd_info_t *dhd, void *uaddr)
2438 struct ethtool_drvinfo info;
2439 char drvname[sizeof(info.driver)];
2442 struct ethtool_value edata;
2443 uint32 toe_cmpnt, csum_dir;
2447 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
2449 /* all ethtool calls start with a cmd word */
2450 if (copy_from_user(&cmd, uaddr, sizeof (uint32)))
2454 case ETHTOOL_GDRVINFO:
2455 /* Copy out any request driver name */
2456 if (copy_from_user(&info, uaddr, sizeof(info)))
2458 strncpy(drvname, info.driver, sizeof(info.driver));
2459 drvname[sizeof(info.driver)-1] = '\0';
2461 /* clear struct for return */
2462 memset(&info, 0, sizeof(info));
2465 /* if dhd requested, identify ourselves */
2466 if (strcmp(drvname, "?dhd") == 0) {
2467 snprintf(info.driver, sizeof(info.driver), "dhd");
2468 strncpy(info.version, EPI_VERSION_STR, sizeof(info.version) - 1);
2469 info.version[sizeof(info.version) - 1] = '\0';
2472 /* otherwise, require dongle to be up */
2473 else if (!dhd->pub.up) {
2474 DHD_ERROR(("%s: dongle is not up\n", __FUNCTION__));
2478 /* finally, report dongle driver type */
2479 else if (dhd->pub.iswl)
2480 snprintf(info.driver, sizeof(info.driver), "wl");
2482 snprintf(info.driver, sizeof(info.driver), "xx");
2484 snprintf(info.version, sizeof(info.version), "%lu", dhd->pub.drv_version);
2485 if (copy_to_user(uaddr, &info, sizeof(info)))
2487 DHD_CTL(("%s: given %*s, returning %s\n", __FUNCTION__,
2488 (int)sizeof(drvname), drvname, info.driver));
2492 /* Get toe offload components from dongle */
2493 case ETHTOOL_GRXCSUM:
2494 case ETHTOOL_GTXCSUM:
2495 if ((ret = dhd_toe_get(dhd, 0, &toe_cmpnt)) < 0)
2498 csum_dir = (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
2501 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
2503 if (copy_to_user(uaddr, &edata, sizeof(edata)))
2507 /* Set toe offload components in dongle */
2508 case ETHTOOL_SRXCSUM:
2509 case ETHTOOL_STXCSUM:
2510 if (copy_from_user(&edata, uaddr, sizeof(edata)))
2513 /* Read the current settings, update and write back */
2514 if ((ret = dhd_toe_get(dhd, 0, &toe_cmpnt)) < 0)
2517 csum_dir = (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
2519 if (edata.data != 0)
2520 toe_cmpnt |= csum_dir;
2522 toe_cmpnt &= ~csum_dir;
2524 if ((ret = dhd_toe_set(dhd, 0, toe_cmpnt)) < 0)
2527 /* If setting TX checksum mode, tell Linux the new mode */
2528 if (cmd == ETHTOOL_STXCSUM) {
2530 dhd->iflist[0]->net->features |= NETIF_F_IP_CSUM;
2532 dhd->iflist[0]->net->features &= ~NETIF_F_IP_CSUM;
2544 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 4, 2) */
2546 static bool dhd_check_hang(struct net_device *net, dhd_pub_t *dhdp, int error)
2551 DHD_ERROR(("%s: dhdp is NULL\n", __FUNCTION__));
2558 dhd = (dhd_info_t *)dhdp->info;
2559 if (dhd->thr_sysioc_ctl.thr_pid < 0) {
2560 DHD_ERROR(("%s : skipped due to negative pid - unloading?\n", __FUNCTION__));
2564 if ((error == -ETIMEDOUT) || (error == -EREMOTEIO) ||
2565 ((dhdp->busstate == DHD_BUS_DOWN) && (!dhdp->dongle_reset))) {
2566 DHD_ERROR(("%s: Event HANG send up due to re=%d te=%d e=%d s=%d\n", __FUNCTION__,
2567 dhdp->rxcnt_timeout, dhdp->txcnt_timeout, error, dhdp->busstate));
2568 net_os_send_hang_message(net);
2574 int dhd_ioctl_process(dhd_pub_t *pub, int ifidx, dhd_ioctl_t *ioc)
2576 int bcmerror = BCME_OK;
2579 struct net_device *net;
2581 net = dhd_idx2net(pub, ifidx);
2583 bcmerror = BCME_BADARG;
2587 /* Copy out any buffer passed */
2589 if (ioc->len == 0) {
2590 DHD_TRACE(("%s: ioc->len=0, returns BCME_BADARG \n", __FUNCTION__));
2591 bcmerror = BCME_BADARG;
2594 buflen = MIN(ioc->len, DHD_IOCTL_MAXLEN);
2595 /* optimization for direct ioctl calls from kernel */
2597 if (segment_eq(get_fs(), KERNEL_DS)) {
2602 if (!(buf = MALLOC(pub->osh, buflen + 1))) {
2603 bcmerror = BCME_NOMEM;
2606 if (copy_from_user(buf, ioc->buf, buflen)) {
2607 bcmerror = BCME_BADADDR;
2610 *(char *)(buf + buflen) = '\0';
2614 /* check for local dhd ioctl and handle it */
2615 if (ioc->driver == DHD_IOCTL_MAGIC) {
2616 bcmerror = dhd_ioctl((void *)pub, ioc, buf, buflen);
2618 pub->bcmerror = bcmerror;
2622 /* send to dongle (must be up, and wl). */
2623 if (pub->busstate != DHD_BUS_DATA) {
2624 bcmerror = BCME_DONGLE_DOWN;
2629 bcmerror = BCME_DONGLE_DOWN;
2634 * Flush the TX queue if required for proper message serialization:
2635 * Intercept WLC_SET_KEY IOCTL - serialize M4 send and set key IOCTL to
2636 * prevent M4 encryption and
2637 * intercept WLC_DISASSOC IOCTL - serialize WPS-DONE and WLC_DISASSOC IOCTL to
2638 * prevent disassoc frame being sent before WPS-DONE frame.
2640 if (ioc->cmd == WLC_SET_KEY ||
2641 (ioc->cmd == WLC_SET_VAR && ioc->buf != NULL &&
2642 strncmp("wsec_key", ioc->buf, 9) == 0) ||
2643 (ioc->cmd == WLC_SET_VAR && ioc->buf != NULL &&
2644 strncmp("bsscfg:wsec_key", ioc->buf, 15) == 0) ||
2645 ioc->cmd == WLC_DISASSOC)
2646 dhd_wait_pend8021x(net);
2650 /* short cut wl ioctl calls here */
2651 if (strcmp("htsf", ioc->buf) == 0) {
2652 dhd_ioctl_htsf_get(dhd, 0);
2656 if (strcmp("htsflate", ioc->buf) == 0) {
2658 memset(ts, 0, sizeof(tstamp_t)*TSMAX);
2659 memset(&maxdelayts, 0, sizeof(tstamp_t));
2663 memset(&vi_d1.bin, 0, sizeof(uint32)*NUMBIN);
2664 memset(&vi_d2.bin, 0, sizeof(uint32)*NUMBIN);
2665 memset(&vi_d3.bin, 0, sizeof(uint32)*NUMBIN);
2666 memset(&vi_d4.bin, 0, sizeof(uint32)*NUMBIN);
2672 if (strcmp("htsfclear", ioc->buf) == 0) {
2673 memset(&vi_d1.bin, 0, sizeof(uint32)*NUMBIN);
2674 memset(&vi_d2.bin, 0, sizeof(uint32)*NUMBIN);
2675 memset(&vi_d3.bin, 0, sizeof(uint32)*NUMBIN);
2676 memset(&vi_d4.bin, 0, sizeof(uint32)*NUMBIN);
2680 if (strcmp("htsfhis", ioc->buf) == 0) {
2681 dhd_dump_htsfhisto(&vi_d1, "H to D");
2682 dhd_dump_htsfhisto(&vi_d2, "D to D");
2683 dhd_dump_htsfhisto(&vi_d3, "D to H");
2684 dhd_dump_htsfhisto(&vi_d4, "H to H");
2687 if (strcmp("tsport", ioc->buf) == 0) {
2689 memcpy(&tsport, ioc->buf + 7, 4);
2691 DHD_ERROR(("current timestamp port: %d \n", tsport));
2696 #endif /* WLMEDIA_HTSF */
2698 if ((ioc->cmd == WLC_SET_VAR || ioc->cmd == WLC_GET_VAR) &&
2699 ioc->buf != NULL && strncmp("rpc_", ioc->buf, 4) == 0) {
2701 bcmerror = dhd_fdaggr_ioctl(pub, ifidx, (wl_ioctl_t *)ioc, buf, buflen);
2703 bcmerror = BCME_UNSUPPORTED;
2707 bcmerror = dhd_wl_ioctl(pub, ifidx, (wl_ioctl_t *)ioc, buf, buflen);
2710 dhd_check_hang(net, pub, bcmerror);
2712 if (!bcmerror && buf && ioc->buf) {
2713 if (copy_to_user(ioc->buf, buf, buflen))
2718 MFREE(pub->osh, buf, buflen + 1);
2724 dhd_ioctl_entry(struct net_device *net, struct ifreq *ifr, int cmd)
2726 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
2732 DHD_OS_WAKE_LOCK(&dhd->pub);
2734 /* send to dongle only if we are not waiting for reload already */
2735 if (dhd->pub.hang_was_sent) {
2736 DHD_ERROR(("%s: HANG was sent up earlier\n", __FUNCTION__));
2737 DHD_OS_WAKE_LOCK_CTRL_TIMEOUT_ENABLE(&dhd->pub, DHD_EVENT_TIMEOUT_MS);
2738 DHD_OS_WAKE_UNLOCK(&dhd->pub);
2739 return OSL_ERROR(BCME_DONGLE_DOWN);
2742 ifidx = dhd_net2idx(dhd, net);
2743 DHD_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __FUNCTION__, ifidx, cmd));
2745 if (ifidx == DHD_BAD_IF) {
2746 DHD_ERROR(("%s: BAD IF\n", __FUNCTION__));
2747 DHD_OS_WAKE_UNLOCK(&dhd->pub);
2751 #if defined(WL_WIRELESS_EXT)
2752 /* linux wireless extensions */
2753 if ((cmd >= SIOCIWFIRST) && (cmd <= SIOCIWLAST)) {
2754 /* may recurse, do NOT lock */
2755 ret = wl_iw_ioctl(net, ifr, cmd);
2756 DHD_OS_WAKE_UNLOCK(&dhd->pub);
2759 #endif /* defined(WL_WIRELESS_EXT) */
2761 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 4, 2)
2762 if (cmd == SIOCETHTOOL) {
2763 ret = dhd_ethtool(dhd, (void*)ifr->ifr_data);
2764 DHD_OS_WAKE_UNLOCK(&dhd->pub);
2767 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 4, 2) */
2769 if (cmd == SIOCDEVPRIVATE+1) {
2770 ret = wl_android_priv_cmd(net, ifr, cmd);
2771 dhd_check_hang(net, &dhd->pub, ret);
2772 DHD_OS_WAKE_UNLOCK(&dhd->pub);
2776 if (cmd != SIOCDEVPRIVATE) {
2777 DHD_OS_WAKE_UNLOCK(&dhd->pub);
2781 memset(&ioc, 0, sizeof(ioc));
2783 /* Copy the ioc control structure part of ioctl request */
2784 if (copy_from_user(&ioc, ifr->ifr_data, sizeof(wl_ioctl_t))) {
2785 bcmerror = BCME_BADADDR;
2789 /* To differentiate between wl and dhd read 4 more byes */
2790 if ((copy_from_user(&ioc.driver, (char *)ifr->ifr_data + sizeof(wl_ioctl_t),
2791 sizeof(uint)) != 0)) {
2792 bcmerror = BCME_BADADDR;
2796 if (!capable(CAP_NET_ADMIN)) {
2797 bcmerror = BCME_EPERM;
2801 bcmerror = dhd_ioctl_process(&dhd->pub, ifidx, &ioc);
2804 DHD_OS_WAKE_UNLOCK(&dhd->pub);
2806 return OSL_ERROR(bcmerror);
2811 dhd_cleanup_virt_ifaces(dhd_info_t *dhd)
2813 int i = 1; /* Leave ifidx 0 [Primary Interface] */
2814 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
2815 int rollback_lock = FALSE;
2818 DHD_TRACE(("%s: Enter \n", __func__));
2820 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
2821 /* release lock for unregister_netdev */
2822 if (rtnl_is_locked()) {
2824 rollback_lock = TRUE;
2828 for (i = 1; i < DHD_MAX_IFS; i++) {
2829 dhd_net_if_lock_local(dhd);
2830 if (dhd->iflist[i]) {
2831 DHD_TRACE(("Deleting IF: %d \n", i));
2832 if ((dhd->iflist[i]->state != DHD_IF_DEL) &&
2833 (dhd->iflist[i]->state != DHD_IF_DELETING)) {
2834 dhd->iflist[i]->state = DHD_IF_DEL;
2835 dhd->iflist[i]->idx = i;
2836 dhd_op_if(dhd->iflist[i]);
2839 dhd_net_if_unlock_local(dhd);
2842 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
2849 #endif /* WL_CFG80211 */
2853 dhd_stop(struct net_device *net)
2856 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
2857 DHD_OS_WAKE_LOCK(&dhd->pub);
2858 DHD_TRACE(("%s: Enter %p\n", __FUNCTION__, net));
2860 if (dhd->pub.up == 0) {
2863 ifidx = dhd_net2idx(dhd, net);
2864 BCM_REFERENCE(ifidx);
2866 /* Set state and stop OS transmissions */
2867 netif_stop_queue(net);
2872 wl_cfg80211_down(NULL);
2875 * For CFG80211: Clean up all the left over virtual interfaces
2876 * when the primary Interface is brought down. [ifconfig wlan0 down]
2878 if (!dhd_download_fw_on_driverload) {
2879 if ((dhd->dhd_state & DHD_ATTACH_STATE_ADD_IF) &&
2880 (dhd->dhd_state & DHD_ATTACH_STATE_CFG80211)) {
2881 dhd_cleanup_virt_ifaces(dhd);
2887 #ifdef PROP_TXSTATUS
2888 dhd_os_wlfc_block(&dhd->pub);
2889 dhd_wlfc_cleanup(&dhd->pub, NULL, 0);
2890 dhd_os_wlfc_unblock(&dhd->pub);
2892 /* Stop the protocol module */
2893 dhd_prot_stop(&dhd->pub);
2895 OLD_MOD_DEC_USE_COUNT;
2897 #if defined(WL_CFG80211)
2898 if (ifidx == 0 && !dhd_download_fw_on_driverload)
2899 wl_android_wifi_off(net);
2901 dhd->pub.rxcnt_timeout = 0;
2902 dhd->pub.txcnt_timeout = 0;
2903 dhd->pub.hang_was_sent = 0;
2905 DHD_OS_WAKE_UNLOCK(&dhd->pub);
2909 /* (USE_INITIAL_2G_SCAN || USE_INITIAL_SHORT_DWELL_TIME) */
2911 dhd_open(struct net_device *net)
2913 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(net);
2920 #if defined(MULTIPLE_SUPPLICANT)
2921 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) && 1 && 1
2922 if (mutex_is_locked(&_dhd_sdio_mutex_lock_) != 0) {
2923 DHD_ERROR(("%s : dhd_open: call dev open before insmod complete!\n", __FUNCTION__));
2925 mutex_lock(&_dhd_sdio_mutex_lock_);
2927 #endif /* MULTIPLE_SUPPLICANT */
2929 DHD_OS_WAKE_LOCK(&dhd->pub);
2930 /* Update FW path if it was changed */
2931 if (strlen(firmware_path) != 0) {
2932 if (firmware_path[strlen(firmware_path)-1] == '\n')
2933 firmware_path[strlen(firmware_path)-1] = '\0';
2934 dhd_conf_set_fw_name_by_chip(&dhd->pub, fw_path, firmware_path);
2938 dhd->pub.dongle_trap_occured = 0;
2939 dhd->pub.hang_was_sent = 0;
2940 #if !defined(WL_CFG80211)
2942 * Force start if ifconfig_up gets called before START command
2943 * We keep WEXT's wl_control_wl_start to provide backward compatibility
2944 * This should be removed in the future
2946 ret = wl_control_wl_start(net);
2948 DHD_ERROR(("%s: failed with code %d\n", __FUNCTION__, ret));
2954 ifidx = dhd_net2idx(dhd, net);
2955 DHD_TRACE(("%s: ifidx %d\n", __FUNCTION__, ifidx));
2958 DHD_ERROR(("%s: Error: called with invalid IF\n", __FUNCTION__));
2963 if (!dhd->iflist[ifidx] || dhd->iflist[ifidx]->state == DHD_IF_DEL) {
2964 DHD_ERROR(("%s: Error: called when IF already deleted\n", __FUNCTION__));
2970 atomic_set(&dhd->pend_8021x_cnt, 0);
2971 #if defined(WL_CFG80211)
2972 DHD_ERROR(("\n%s\n", dhd_version));
2973 if (!dhd_download_fw_on_driverload) {
2974 ret = wl_android_wifi_on(net);
2976 DHD_ERROR(("%s : wl_android_wifi_on failed (%d)\n",
2977 __FUNCTION__, ret));
2984 if (dhd->pub.busstate != DHD_BUS_DATA) {
2986 /* try to bring up bus */
2987 if ((ret = dhd_bus_start(&dhd->pub)) != 0) {
2988 DHD_ERROR(("%s: failed with code %d\n", __FUNCTION__, ret));
2995 /* dhd_prot_init has been called in dhd_bus_start or wl_android_wifi_on */
2996 memcpy(net->dev_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
2999 /* Get current TOE mode from dongle */
3000 if (dhd_toe_get(dhd, ifidx, &toe_ol) >= 0 && (toe_ol & TOE_TX_CSUM_OL) != 0)
3001 dhd->iflist[ifidx]->net->features |= NETIF_F_IP_CSUM;
3003 dhd->iflist[ifidx]->net->features &= ~NETIF_F_IP_CSUM;
3006 #if defined(WL_CFG80211)
3007 if (unlikely(wl_cfg80211_up(NULL))) {
3008 DHD_ERROR(("%s: failed to bring up cfg80211\n", __FUNCTION__));
3012 #endif /* WL_CFG80211 */
3015 /* Allow transmit calls */
3016 netif_start_queue(net);
3020 dhd_dbg_init(&dhd->pub);
3023 OLD_MOD_INC_USE_COUNT;
3028 DHD_OS_WAKE_UNLOCK(&dhd->pub);
3030 #if defined(MULTIPLE_SUPPLICANT)
3031 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) && 1 && 1
3032 mutex_unlock(&_dhd_sdio_mutex_lock_);
3034 #endif /* MULTIPLE_SUPPLICANT */
3039 int dhd_do_driver_init(struct net_device *net)
3041 dhd_info_t *dhd = NULL;
3044 DHD_ERROR(("Primary Interface not initialized \n"));
3048 #ifdef MULTIPLE_SUPPLICANT
3049 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) && 1 && 1
3050 if (mutex_is_locked(&_dhd_sdio_mutex_lock_) != 0) {
3051 DHD_ERROR(("%s : dhdsdio_probe is already running!\n", __FUNCTION__));
3054 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) */
3055 #endif /* MULTIPLE_SUPPLICANT */
3057 /* && defined(OEM_ANDROID) && defined(BCMSDIO) */
3058 dhd = *(dhd_info_t **)netdev_priv(net);
3060 /* If driver is already initialized, do nothing
3062 if (dhd->pub.busstate == DHD_BUS_DATA) {
3063 DHD_TRACE(("Driver already Inititalized. Nothing to do"));
3067 if (dhd_open(net) < 0) {
3068 DHD_ERROR(("Driver Init Failed \n"));
3076 dhd_osl_attach(void *pdev, uint bustype)
3078 return osl_attach(pdev, bustype, TRUE);
3082 dhd_osl_detach(osl_t *osh)
3084 if (MALLOCED(osh)) {
3085 DHD_ERROR(("%s: MEMORY LEAK %d bytes\n", __FUNCTION__, MALLOCED(osh)));
3088 #if 1 && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
3089 dhd_registration_check = FALSE;
3090 up(&dhd_registration_sem);
3091 #if defined(BCMLXSDMMC)
3092 up(&dhd_chipup_sem);
3098 dhd_add_if(dhd_info_t *dhd, int ifidx, void *handle, char *name,
3099 uint8 *mac_addr, uint32 flags, uint8 bssidx)
3103 DHD_TRACE(("%s: idx %d, handle->%p\n", __FUNCTION__, ifidx, handle));
3105 ASSERT(dhd && (ifidx < DHD_MAX_IFS));
3107 ifp = dhd->iflist[ifidx];
3109 if (ifp->net != NULL) {
3110 netif_stop_queue(ifp->net);
3111 unregister_netdev(ifp->net);
3112 free_netdev(ifp->net);
3115 if ((ifp = MALLOC(dhd->pub.osh, sizeof(dhd_if_t))) == NULL) {
3116 DHD_ERROR(("%s: OOM - dhd_if_t(%d)\n", __FUNCTION__, sizeof(dhd_if_t)));
3120 memset(ifp, 0, sizeof(dhd_if_t));
3121 ifp->event2cfg80211 = FALSE;
3123 dhd->iflist[ifidx] = ifp;
3124 strncpy(ifp->name, name, IFNAMSIZ);
3125 ifp->name[IFNAMSIZ] = '\0';
3126 INIT_LIST_HEAD(&ifp->ipv6_list);
3127 spin_lock_init(&ifp->ipv6_lock);
3128 if (mac_addr != NULL)
3129 memcpy(&ifp->mac_addr, mac_addr, ETHER_ADDR_LEN);
3131 if (handle == NULL) {
3132 ifp->state = DHD_IF_ADD;
3134 ifp->bssidx = bssidx;
3135 ASSERT(dhd->thr_sysioc_ctl.thr_pid >= 0);
3136 up(&dhd->thr_sysioc_ctl.sema);
3138 ifp->net = (struct net_device *)handle;
3141 ifp->event2cfg80211 = TRUE;
3148 dhd_del_if(dhd_info_t *dhd, int ifidx)
3152 DHD_TRACE(("%s: idx %d\n", __FUNCTION__, ifidx));
3154 ASSERT(dhd && ifidx && (ifidx < DHD_MAX_IFS));
3155 ifp = dhd->iflist[ifidx];
3157 DHD_ERROR(("%s: Null interface\n", __FUNCTION__));
3161 ifp->state = DHD_IF_DEL;
3163 ASSERT(dhd->thr_sysioc_ctl.thr_pid >= 0);
3164 up(&dhd->thr_sysioc_ctl.sema);
3167 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
3168 static struct net_device_ops dhd_ops_pri = {
3169 .ndo_open = dhd_open,
3170 .ndo_stop = dhd_stop,
3171 .ndo_get_stats = dhd_get_stats,
3172 .ndo_do_ioctl = dhd_ioctl_entry,
3173 .ndo_start_xmit = dhd_start_xmit,
3174 .ndo_set_mac_address = dhd_set_mac_address,
3175 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
3176 .ndo_set_rx_mode = dhd_set_multicast_list,
3178 .ndo_set_multicast_list = dhd_set_multicast_list,
3182 static struct net_device_ops dhd_ops_virt = {
3183 .ndo_get_stats = dhd_get_stats,
3184 .ndo_do_ioctl = dhd_ioctl_entry,
3185 .ndo_start_xmit = dhd_start_xmit,
3186 .ndo_set_mac_address = dhd_set_mac_address,
3187 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0))
3188 .ndo_set_rx_mode = dhd_set_multicast_list,
3190 .ndo_set_multicast_list = dhd_set_multicast_list,
3193 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31)) */
3196 dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen)
3198 dhd_info_t *dhd = NULL;
3199 struct net_device *net = NULL;
3201 dhd_attach_states_t dhd_state = DHD_ATTACH_STATE_INIT;
3202 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
3204 /* updates firmware nvram path if it was provided as module parameters */
3205 if (strlen(nvram_path) != 0) {
3206 bzero(nv_path, MOD_PARAM_PATHLEN);
3207 strncpy(nv_path, nvram_path, sizeof(nv_path) -1);
3209 if (strlen(config_path) != 0) {
3210 bzero(conf_path, MOD_PARAM_PATHLEN);
3211 strncpy(conf_path, config_path, sizeof(conf_path) -1);
3214 /* Allocate etherdev, including space for private structure */
3215 if (!(net = alloc_etherdev(sizeof(dhd)))) {
3216 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __FUNCTION__));
3219 dhd_state |= DHD_ATTACH_STATE_NET_ALLOC;
3221 /* Allocate primary dhd_info */
3222 #if defined(CONFIG_DHD_USE_STATIC_BUF)
3223 dhd = (void *)dhd_os_prealloc(osh, DHD_PREALLOC_DHD_INFO, sizeof(dhd_info_t));
3225 DHD_INFO(("%s: OOM - Pre-alloc dhd_info\n", __FUNCTION__));
3226 #endif /* CONFIG_DHD_USE_STATIC_BUF */
3227 if (!(dhd = MALLOC(osh, sizeof(dhd_info_t)))) {
3228 DHD_ERROR(("%s: OOM - alloc dhd_info\n", __FUNCTION__));
3231 #if defined(CONFIG_DHD_USE_STATIC_BUF)
3233 #endif /* CONFIG_DHD_USE_STATIC_BUF */
3234 memset(dhd, 0, sizeof(dhd_info_t));
3237 dhd->thr_dpc_ctl.thr_pid = DHD_PID_KT_TL_INVALID;
3238 dhd->thr_wdt_ctl.thr_pid = DHD_PID_KT_INVALID;
3239 #endif /* DHDTHREAD */
3240 dhd->dhd_tasklet_create = FALSE;
3241 dhd->thr_sysioc_ctl.thr_pid = DHD_PID_KT_INVALID;
3242 dhd_state |= DHD_ATTACH_STATE_DHD_ALLOC;
3245 * Save the dhd_info into the priv
3247 memcpy((void *)netdev_priv(net), &dhd, sizeof(dhd));
3250 /* Link to info module */
3251 dhd->pub.info = dhd;
3252 /* Link to bus module */
3254 dhd->pub.hdrlen = bus_hdrlen;
3255 if (strlen(firmware_path) != 0)
3256 dhd_conf_set_fw_name_by_chip(&dhd->pub, fw_path, firmware_path);
3258 /* Set network interface name if it was provided as module parameter */
3259 if (iface_name[0]) {
3262 strncpy(net->name, iface_name, IFNAMSIZ);
3263 net->name[IFNAMSIZ - 1] = 0;
3264 len = strlen(net->name);
3265 ch = net->name[len - 1];
3266 if ((ch > '9' || ch < '0') && (len < IFNAMSIZ - 2))
3267 strcat(net->name, "%d");
3270 if (dhd_add_if(dhd, 0, (void *)net, net->name, NULL, 0, 0) == DHD_BAD_IF)
3272 dhd_state |= DHD_ATTACH_STATE_ADD_IF;
3274 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31))
3277 net->netdev_ops = NULL;
3280 sema_init(&dhd->proto_sem, 1);
3282 #ifdef PROP_TXSTATUS
3283 spin_lock_init(&dhd->wlfc_spinlock);
3284 #ifdef PROP_TXSTATUS_VSDB
3285 dhd->pub.wlfc_enabled = FALSE;
3287 if (!disable_proptx)
3288 dhd->pub.wlfc_enabled = TRUE;
3290 dhd->pub.wlfc_enabled = FALSE;
3291 #endif /* PROP_TXSTATUS_VSDB */
3292 dhd->pub.ptx_opt_enabled = FALSE;
3293 dhd->pub.skip_fc = dhd_wlfc_skip_fc;
3294 dhd->pub.plat_enable = dhd_wlfc_plat_enable;
3295 dhd->pub.plat_deinit = dhd_wlfc_plat_deinit;
3296 #endif /* PROP_TXSTATUS */
3298 /* Initialize other structure content */
3299 init_waitqueue_head(&dhd->ioctl_resp_wait);
3300 init_waitqueue_head(&dhd->ctrl_wait);
3302 /* Initialize the spinlocks */
3303 spin_lock_init(&dhd->sdlock);
3304 spin_lock_init(&dhd->txqlock);
3305 spin_lock_init(&dhd->dhd_lock);
3306 #if defined(DHDTHREAD) && defined(RXFRAME_THREAD)
3307 spin_lock_init(&dhd->rxf_lock);
3308 #endif /* defined(DHDTHREAD) && defined(RXFRAME_THREAD) */
3309 #ifdef DHDTCPACK_SUPPRESS
3310 spin_lock_init(&dhd->tcpack_lock);
3311 #endif /* DHDTCPACK_SUPPRESS */
3313 /* Initialize Wakelock stuff */
3314 spin_lock_init(&dhd->wakelock_spinlock);
3315 dhd->wakelock_counter = 0;
3316 dhd->wakelock_wd_counter = 0;
3317 dhd->wakelock_rx_timeout_enable = 0;
3318 dhd->wakelock_ctrl_timeout_enable = 0;
3319 #ifdef CONFIG_HAS_WAKELOCK
3320 wake_lock_init(&dhd->wl_wifi, WAKE_LOCK_SUSPEND, "wlan_wake");
3321 wake_lock_init(&dhd->wl_rxwake, WAKE_LOCK_SUSPEND, "wlan_rx_wake");
3322 wake_lock_init(&dhd->wl_ctrlwake, WAKE_LOCK_SUSPEND, "wlan_ctrl_wake");
3323 wake_lock_init(&dhd->wl_wdwake, WAKE_LOCK_SUSPEND, "wlan_wd_wake");
3324 #endif /* CONFIG_HAS_WAKELOCK */
3325 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) && 1
3326 mutex_init(&dhd->dhd_net_if_mutex);
3327 mutex_init(&dhd->dhd_suspend_mutex);
3329 dhd_state |= DHD_ATTACH_STATE_WAKELOCKS_INIT;
3331 if (dhd_conf_attach(&dhd->pub) != 0) {
3332 DHD_ERROR(("dhd_conf_attach failed\n"));
3336 /* Attach and link in the protocol */
3337 if (dhd_prot_attach(&dhd->pub) != 0) {
3338 DHD_ERROR(("dhd_prot_attach failed\n"));
3341 dhd_state |= DHD_ATTACH_STATE_PROT_ATTACH;
3344 /* Attach and link in the cfg80211 */
3345 if (unlikely(wl_cfg80211_attach(net, &dhd->pub))) {
3346 DHD_ERROR(("wl_cfg80211_attach failed\n"));
3350 dhd_monitor_init(&dhd->pub);
3351 dhd_state |= DHD_ATTACH_STATE_CFG80211;
3353 #if defined(WL_WIRELESS_EXT)
3354 /* Attach and link in the iw */
3355 if (!(dhd_state & DHD_ATTACH_STATE_CFG80211)) {
3356 if (wl_iw_attach(net, (void *)&dhd->pub) != 0) {
3357 DHD_ERROR(("wl_iw_attach failed\n"));
3360 dhd_state |= DHD_ATTACH_STATE_WL_ATTACH;
3362 #endif /* defined(WL_WIRELESS_EXT) */
3365 /* Set up the watchdog timer */
3366 init_timer(&dhd->timer);
3367 dhd->timer.data = (ulong)dhd;
3368 dhd->timer.function = dhd_watchdog;
3369 dhd->default_wd_interval = dhd_watchdog_ms;
3372 /* Initialize thread based operation and lock */
3373 sema_init(&dhd->sdsem, 1);
3374 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0)) {
3375 dhd->threads_only = TRUE;
3378 dhd->threads_only = FALSE;
3381 if (dhd_watchdog_prio >= 0) {
3382 /* Initialize watchdog thread */
3383 PROC_START(dhd_watchdog_thread, dhd, &dhd->thr_wdt_ctl, 0, "dhd_watchdog_thread");
3386 dhd->thr_wdt_ctl.thr_pid = -1;
3389 /* Set up the bottom half handler */
3390 if (dhd_dpc_prio >= 0) {
3391 /* Initialize DPC thread */
3392 PROC_START(dhd_dpc_thread, dhd, &dhd->thr_dpc_ctl, 0, "dhd_dpc");
3394 /* use tasklet for dpc */
3395 tasklet_init(&dhd->tasklet, dhd_dpc, (ulong)dhd);
3396 dhd->thr_dpc_ctl.thr_pid = -1;
3398 #ifdef RXFRAME_THREAD
3399 bzero(&dhd->pub.skbbuf[0], sizeof(void *) * MAXSKBPEND);
3400 /* Initialize RXF thread */
3401 PROC_START(dhd_rxf_thread, dhd, &dhd->thr_rxf_ctl, 0, "dhd_rxf");
3404 /* Set up the bottom half handler */
3405 tasklet_init(&dhd->tasklet, dhd_dpc, (ulong)dhd);
3406 dhd->dhd_tasklet_create = TRUE;
3407 #endif /* DHDTHREAD */
3410 PROC_START(_dhd_sysioc_thread, dhd, &dhd->thr_sysioc_ctl, 0, "dhd_sysioc");
3412 dhd->thr_sysioc_ctl.thr_pid = -1;
3414 dhd_state |= DHD_ATTACH_STATE_THREADS_CREATED;
3416 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && (1)
3417 INIT_WORK(&dhd->work_hang, dhd_hang_process);
3418 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
3421 * Save the dhd_info into the priv
3423 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
3425 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && (LINUX_VERSION_CODE <= \
3426 KERNEL_VERSION(2, 6, 39)) && defined(CONFIG_PM_SLEEP)
3427 register_pm_notifier(&dhd_sleep_pm_notifier);
3428 #endif /* (LINUX_VERSION >= 2.6.27 && LINUX_VERSION <= 2.6.39 && CONFIG_PM_SLEEP */
3430 #if defined(CONFIG_HAS_EARLYSUSPEND) && defined(DHD_USE_EARLYSUSPEND)
3431 dhd->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 20;
3432 dhd->early_suspend.suspend = dhd_early_suspend;
3433 dhd->early_suspend.resume = dhd_late_resume;
3434 register_early_suspend(&dhd->early_suspend);
3435 dhd_state |= DHD_ATTACH_STATE_EARLYSUSPEND_DONE;
3436 #endif /* CONFIG_HAS_EARLYSUSPEND && DHD_USE_EARLYSUSPEND */
3438 #ifdef ARP_OFFLOAD_SUPPORT
3439 dhd->pend_ipaddr = 0;
3440 register_inetaddr_notifier(&dhd_notifier);
3441 #endif /* ARP_OFFLOAD_SUPPORT */
3442 register_inet6addr_notifier(&dhd_notifier_ipv6);
3444 #ifdef DHDTCPACK_SUPPRESS
3445 dhd->pub.tcp_ack_info_cnt = 0;
3446 bzero(dhd->pub.tcp_ack_info_tbl, sizeof(struct tcp_ack_info)*MAXTCPSTREAMS);
3447 #endif /* DHDTCPACK_SUPPRESS */
3449 dhd_state |= DHD_ATTACH_STATE_DONE;
3450 dhd->dhd_state = dhd_state;
3454 if (dhd_state < DHD_ATTACH_STATE_DHD_ALLOC) {
3455 if (net) free_netdev(net);
3457 DHD_TRACE(("%s: Calling dhd_detach dhd_state 0x%x &dhd->pub %p\n",
3458 __FUNCTION__, dhd_state, &dhd->pub));
3459 dhd->dhd_state = dhd_state;
3460 dhd_detach(&dhd->pub);
3461 dhd_free(&dhd->pub);
3468 dhd_bus_start(dhd_pub_t *dhdp)
3471 dhd_info_t *dhd = (dhd_info_t*)dhdp->info;
3472 unsigned long flags;
3476 DHD_TRACE(("Enter %s:\n", __FUNCTION__));
3479 if (dhd->threads_only)
3480 dhd_os_sdlock(dhdp);
3481 #endif /* DHDTHREAD */
3484 /* try to download image and nvram to the dongle */
3485 if ((dhd->pub.busstate == DHD_BUS_DOWN) &&
3486 (fw_path[0] != '\0') && (nv_path[0] != '\0')) {
3487 #ifdef SHOW_NVRAM_TYPE
3488 { /* Show nvram type in the kernel log */
3490 for (i = 0; nv_path[i] != '\0'; ++i) {
3491 if (nv_path[i] == '.') {
3496 DHD_ERROR(("%s: nvram_type = [%s]\n", __FUNCTION__, &nv_path[i]));
3498 #endif /* SHOW_NVRAM_TYPE */
3499 /* wake lock moved to dhdsdio_download_firmware */
3500 if (!(dhd_bus_download_firmware(dhd->pub.bus, dhd->pub.osh,
3501 fw_path, nv_path, conf_path))) {
3502 DHD_ERROR(("%s: dhdsdio_probe_download failed. firmware = %s nvram = %s config = %s\n",
3503 __FUNCTION__, fw_path, nv_path, conf_path));
3505 if (dhd->threads_only)
3506 dhd_os_sdunlock(dhdp);
3507 #endif /* DHDTHREAD */
3511 if (dhd->pub.busstate != DHD_BUS_LOAD) {
3513 if (dhd->threads_only)
3514 dhd_os_sdunlock(dhdp);
3515 #endif /* DHDTHREAD */
3519 /* Start the watchdog timer */
3520 dhd->pub.tickcnt = 0;
3521 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
3523 /* Bring up the bus */
3524 if ((ret = dhd_bus_init(&dhd->pub, FALSE)) != 0) {
3526 DHD_ERROR(("%s, dhd_bus_init failed %d\n", __FUNCTION__, ret));
3528 if (dhd->threads_only)
3529 dhd_os_sdunlock(dhdp);
3530 #endif /* DHDTHREAD */
3533 bcmsdh_set_drvdata(dhdp); // terence 20130427: fix for null pointer issue
3534 #if defined(OOB_INTR_ONLY)
3535 /* Host registration for OOB interrupt */
3536 if (bcmsdh_register_oob_intr(dhdp)) {
3537 /* deactivate timer and wait for the handler to finish */
3539 flags = dhd_os_spin_lock(&dhd->pub);
3540 dhd->wd_timer_valid = FALSE;
3541 dhd_os_spin_unlock(&dhd->pub, flags);
3542 del_timer_sync(&dhd->timer);
3544 DHD_ERROR(("%s Host failed to register for OOB\n", __FUNCTION__));
3546 if (dhd->threads_only)
3547 dhd_os_sdunlock(dhdp);
3548 #endif /* DHDTHREAD */
3549 DHD_OS_WD_WAKE_UNLOCK(&dhd->pub);
3553 /* Enable oob at firmware */
3554 dhd_enable_oob_intr(dhd->pub.bus, TRUE);
3557 /* If bus is not ready, can't come up */
3558 if (dhd->pub.busstate != DHD_BUS_DATA) {
3559 flags = dhd_os_spin_lock(&dhd->pub);
3560 dhd->wd_timer_valid = FALSE;
3561 dhd_os_spin_unlock(&dhd->pub, flags);
3562 del_timer_sync(&dhd->timer);
3563 DHD_ERROR(("%s failed bus is not ready\n", __FUNCTION__));
3565 if (dhd->threads_only)
3566 dhd_os_sdunlock(dhdp);
3567 #endif /* DHDTHREAD */
3568 DHD_OS_WD_WAKE_UNLOCK(&dhd->pub);
3573 if (dhd->threads_only)
3574 dhd_os_sdunlock(dhdp);
3575 #endif /* DHDTHREAD */
3577 dhd_process_cid_mac(dhdp, TRUE);
3579 /* Bus is ready, do any protocol initialization */
3580 if ((ret = dhd_prot_init(&dhd->pub)) < 0)
3583 dhd_process_cid_mac(dhdp, FALSE);
3585 #ifdef ARP_OFFLOAD_SUPPORT
3586 if (dhd->pend_ipaddr) {
3587 #ifdef AOE_IP_ALIAS_SUPPORT
3588 aoe_update_host_ipv4_table(&dhd->pub, dhd->pend_ipaddr, TRUE, 0);
3589 #endif /* AOE_IP_ALIAS_SUPPORT */
3590 dhd->pend_ipaddr = 0;
3592 #endif /* ARP_OFFLOAD_SUPPORT */
3597 int dhd_tdls_enable_disable(dhd_pub_t *dhd, bool flag)
3599 char iovbuf[WLC_IOCTL_SMLEN];
3602 #ifdef WLTDLS_AUTO_ENABLE
3603 uint32 tdls_auto_op = 1;
3604 uint32 tdls_idle_time = CUSTOM_TDLS_IDLE_MODE_SETTING;
3605 #endif /* WLTDLS_AUTO_ENABLE */
3606 if (!FW_SUPPORTED(dhd, tdls))
3609 bcm_mkiovar("tdls_enable", (char *)&tdls, sizeof(tdls), iovbuf, sizeof(iovbuf));
3610 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0)) < 0) {
3611 DHD_ERROR(("%s: tdls %d failed %d\n", __FUNCTION__, tdls, ret));
3614 dhd->tdls_enable = flag;
3617 #ifdef WLTDLS_AUTO_ENABLE
3618 bcm_mkiovar("tdls_auto_op", (char *)&tdls_auto_op, sizeof(tdls_auto_op),
3619 iovbuf, sizeof(iovbuf));
3620 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0)) < 0) {
3621 DHD_ERROR(("%s: tdls_auto_op failed %d\n", __FUNCTION__, ret));
3624 bcm_mkiovar("tdls_idle_time", (char *)&tdls_idle_time, sizeof(tdls_idle_time),
3625 iovbuf, sizeof(iovbuf));
3626 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0)) < 0) {
3627 DHD_ERROR(("%s: tdls_idle_time failed %d\n", __FUNCTION__, ret));
3630 #endif /* WLTDLS_AUTO_ENABLE */
3636 bool dhd_is_concurrent_mode(dhd_pub_t *dhd)
3641 if (dhd->op_mode & DHD_FLAG_CONCURR_MULTI_CHAN_MODE)
3643 else if ((dhd->op_mode & DHD_FLAG_CONCURR_SINGLE_CHAN_MODE) ==
3644 DHD_FLAG_CONCURR_SINGLE_CHAN_MODE)
3649 #if !defined(AP) && defined(WLP2P)
3650 /* From Android JerryBean release, the concurrent mode is enabled by default and the firmware
3651 * name would be fw_bcmdhd.bin. So we need to determine whether P2P is enabled in the STA
3652 * firmware and accordingly enable concurrent mode (Apply P2P settings). SoftAP firmware
3653 * would still be named as fw_bcmdhd_apsta.
3656 dhd_get_concurrent_capabilites(dhd_pub_t *dhd)
3659 char buf[WLC_IOCTL_SMLEN];
3660 bool mchan_supported = FALSE;
3661 /* if dhd->op_mode is already set for HOSTAP,
3662 * that means we only will use the mode as it is
3664 if (dhd->op_mode & DHD_FLAG_HOSTAP_MODE)
3666 if (FW_SUPPORTED(dhd, vsdb)) {
3667 mchan_supported = TRUE;
3669 if (!FW_SUPPORTED(dhd, p2p)) {
3670 DHD_TRACE(("Chip does not support p2p\n"));
3674 /* Chip supports p2p but ensure that p2p is really implemented in firmware or not */
3675 memset(buf, 0, sizeof(buf));
3676 bcm_mkiovar("p2p", 0, 0, buf, sizeof(buf));
3677 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_GET_VAR, buf, sizeof(buf),
3679 DHD_ERROR(("%s: Get P2P failed (error=%d)\n", __FUNCTION__, ret));
3684 /* By default, chip supports single chan concurrency,
3685 * now lets check for mchan
3687 ret = DHD_FLAG_CONCURR_SINGLE_CHAN_MODE;
3688 if (mchan_supported)
3689 ret |= DHD_FLAG_CONCURR_MULTI_CHAN_MODE;
3690 #if defined(WL_ENABLE_P2P_IF) || defined(WL_CFG80211_P2P_DEV_IF)
3691 /* For customer_hw4, although ICS,
3692 * we still support concurrent mode
3706 dhd_preinit_ioctls(dhd_pub_t *dhd)
3709 char eventmask[WL_EVENTING_MASK_LEN];
3710 char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" + '\0' + bitvec */
3711 uint32 buf_key_b4_m4 = 1;
3712 #if defined(BCMSUP_4WAY_HANDSHAKE) && defined(WLAN_AKM_SUITE_FT_8021X)
3715 #ifdef CUSTOM_AMPDU_BA_WSIZE
3716 uint32 ampdu_ba_wsize = CUSTOM_AMPDU_BA_WSIZE;
3717 #endif /* CUSTOM_AMPDU_BA_WSIZE */
3718 #ifdef DHD_ENABLE_LPC
3720 #endif /* DHD_ENABLE_LPC */
3721 uint power_mode = PM_FAST;
3722 uint32 dongle_align = DHD_SDALIGN;
3723 uint32 glom = CUSTOM_GLOM_SETTING;
3724 uint bcn_timeout = 4;
3726 #if defined(ARP_OFFLOAD_SUPPORT)
3729 int scan_assoc_time = DHD_SCAN_ASSOC_ACTIVE_TIME;
3730 int scan_unassoc_time = DHD_SCAN_UNASSOC_ACTIVE_TIME;
3731 int scan_passive_time = DHD_SCAN_PASSIVE_TIME;
3732 char buf[WLC_IOCTL_SMLEN];
3734 uint32 listen_interval = CUSTOM_LISTEN_INTERVAL; /* Default Listen Interval in Beacons */
3737 int roam_trigger[2] = {CUSTOM_ROAM_TRIGGER_SETTING, WLC_BAND_ALL};
3738 int roam_scan_period[2] = {10, WLC_BAND_ALL};
3739 int roam_delta[2] = {CUSTOM_ROAM_DELTA_SETTING, WLC_BAND_ALL};
3740 #ifdef FULL_ROAMING_SCAN_PERIOD_60_SEC
3741 int roam_fullscan_period = 60;
3742 #else /* FULL_ROAMING_SCAN_PERIOD_60_SEC */
3743 int roam_fullscan_period = 120;
3744 #endif /* FULL_ROAMING_SCAN_PERIOD_60_SEC */
3746 #ifdef DISABLE_BUILTIN_ROAM
3748 #endif /* DISABLE_BUILTIN_ROAM */
3749 #endif /* ROAM_ENABLE */
3754 #if (defined(AP) && !defined(WLP2P)) || (!defined(AP) && defined(WL_CFG80211))
3755 uint32 mpc = 0; /* Turn MPC off for AP/APSTA mode */
3756 struct ether_addr p2p_ea;
3759 #if defined(AP) || defined(WLP2P)
3760 uint32 apsta = 1; /* Enable APSTA mode */
3761 #endif /* defined(AP) || defined(WLP2P) */
3762 #ifdef GET_CUSTOM_MAC_ENABLE
3763 struct ether_addr ea_addr;
3764 #endif /* GET_CUSTOM_MAC_ENABLE */
3771 #endif /* DISABLE_11N */
3774 #endif /* USE_WL_TXBF */
3775 #ifdef USE_WL_FRAMEBURST
3776 uint32 frameburst = 1;
3777 #endif /* USE_WL_FRAMEBURST */
3778 #ifdef DHD_SET_FW_HIGHSPEED
3779 uint32 ack_ratio = 250;
3780 uint32 ack_ratio_depth = 64;
3781 #endif /* DHD_SET_FW_HIGHSPEED */
3782 #ifdef SUPPORT_2G_VHT
3783 uint32 vht_features = 0x3; /* 2G enable | rates all */
3784 #endif /* SUPPORT_2G_VHT */
3785 #ifdef PROP_TXSTATUS
3786 #ifdef PROP_TXSTATUS_VSDB
3787 /* In case the host does not support proptxstatus, hostreorder in dongle should be off */
3788 uint32 hostreorder = 0;
3789 dhd->wlfc_enabled = FALSE;
3790 /* enable WLFC only if the firmware is VSDB */
3792 if (!disable_proptx)
3793 dhd->wlfc_enabled = TRUE;
3795 dhd->wlfc_enabled = FALSE;
3796 #endif /* PROP_TXSTATUS_VSDB */
3797 #endif /* PROP_TXSTATUS */
3799 dhd->suspend_bcn_li_dtim = CUSTOM_SUSPEND_BCN_LI_DTIM;
3800 DHD_TRACE(("Enter %s\n", __FUNCTION__));
3802 dhd_conf_set_band(dhd);
3805 #ifdef GET_CUSTOM_MAC_ENABLE
3806 ret = dhd_custom_get_mac_address(ea_addr.octet);
3808 memset(buf, 0, sizeof(buf));
3809 bcm_mkiovar("cur_etheraddr", (void *)&ea_addr, ETHER_ADDR_LEN, buf, sizeof(buf));
3810 ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, buf, sizeof(buf), TRUE, 0);
3812 DHD_ERROR(("%s: can't set MAC address , error=%d\n", __FUNCTION__, ret));
3815 memcpy(dhd->mac.octet, ea_addr.octet, ETHER_ADDR_LEN);
3817 #endif /* GET_CUSTOM_MAC_ENABLE */
3818 /* Get the default device MAC address directly from firmware */
3819 memset(buf, 0, sizeof(buf));
3820 bcm_mkiovar("cur_etheraddr", 0, 0, buf, sizeof(buf));
3821 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_GET_VAR, buf, sizeof(buf),
3823 DHD_ERROR(("%s: can't get MAC address , error=%d\n", __FUNCTION__, ret));
3826 /* Update public MAC address after reading from Firmware */
3827 memcpy(dhd->mac.octet, buf, ETHER_ADDR_LEN);
3829 #ifdef GET_CUSTOM_MAC_ENABLE
3831 #endif /* GET_CUSTOM_MAC_ENABLE */
3833 DHD_TRACE(("Firmware = %s\n", fw_path));
3834 /* get a capabilities from firmware */
3835 memset(dhd->fw_capabilities, 0, sizeof(dhd->fw_capabilities));
3836 bcm_mkiovar("cap", 0, 0, dhd->fw_capabilities, sizeof(dhd->fw_capabilities));
3837 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_GET_VAR, dhd->fw_capabilities,
3838 sizeof(dhd->fw_capabilities), FALSE, 0)) < 0) {
3839 DHD_ERROR(("%s: Get Capability failed (error=%d)\n",
3840 __FUNCTION__, ret));
3843 if ((!op_mode && strstr(fw_path, "_apsta") != NULL) ||
3844 (op_mode == DHD_FLAG_HOSTAP_MODE)) {
3845 #ifdef SET_RANDOM_MAC_SOFTAP
3848 dhd->op_mode = DHD_FLAG_HOSTAP_MODE;
3849 #if defined(ARP_OFFLOAD_SUPPORT)
3852 #ifdef PKT_FILTER_SUPPORT
3853 dhd_pkt_filter_enable = FALSE;
3855 #ifdef SET_RANDOM_MAC_SOFTAP
3856 SRANDOM32((uint)jiffies);
3857 rand_mac = RANDOM32();
3858 iovbuf[0] = 0x02; /* locally administered bit */
3861 iovbuf[3] = (unsigned char)(rand_mac & 0x0F) | 0xF0;
3862 iovbuf[4] = (unsigned char)(rand_mac >> 8);
3863 iovbuf[5] = (unsigned char)(rand_mac >> 16);
3865 bcm_mkiovar("cur_etheraddr", (void *)iovbuf, ETHER_ADDR_LEN, buf, sizeof(buf));
3866 ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, buf, sizeof(buf), TRUE, 0);
3868 DHD_ERROR(("%s: can't set MAC address , error=%d\n", __FUNCTION__, ret));
3870 memcpy(dhd->mac.octet, iovbuf, ETHER_ADDR_LEN);
3871 #endif /* SET_RANDOM_MAC_SOFTAP */
3872 #if !defined(AP) && defined(WL_CFG80211)
3873 /* Turn off MPC in AP mode */
3874 bcm_mkiovar("mpc", (char *)&mpc, 4, iovbuf, sizeof(iovbuf));
3875 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf,
3876 sizeof(iovbuf), TRUE, 0)) < 0) {
3877 DHD_ERROR(("%s mpc for HostAPD failed %d\n", __FUNCTION__, ret));
3882 uint32 concurrent_mode = 0;
3883 if ((!op_mode && strstr(fw_path, "_p2p") != NULL) ||
3884 (op_mode == DHD_FLAG_P2P_MODE)) {
3885 #if defined(ARP_OFFLOAD_SUPPORT)
3888 #ifdef PKT_FILTER_SUPPORT
3889 dhd_pkt_filter_enable = FALSE;
3891 dhd->op_mode = DHD_FLAG_P2P_MODE;
3892 } else if (op_mode == DHD_FLAG_IBSS_MODE ||
3893 (!op_mode && strstr(fw_path, "_ibss") != NULL)) {
3894 dhd->op_mode = DHD_FLAG_IBSS_MODE;
3896 dhd->op_mode = DHD_FLAG_STA_MODE;
3898 #if !defined(AP) && defined(WLP2P)
3899 if (dhd->op_mode != DHD_FLAG_IBSS_MODE &&
3900 (concurrent_mode = dhd_get_concurrent_capabilites(dhd))) {
3901 #if defined(ARP_OFFLOAD_SUPPORT)
3904 dhd->op_mode |= concurrent_mode;
3907 /* Check if we are enabling p2p */
3908 if (dhd->op_mode & DHD_FLAG_P2P_MODE) {
3909 bcm_mkiovar("apsta", (char *)&apsta, 4, iovbuf, sizeof(iovbuf));
3910 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR,
3911 iovbuf, sizeof(iovbuf), TRUE, 0)) < 0) {
3912 DHD_ERROR(("%s APSTA for P2P failed ret= %d\n", __FUNCTION__, ret));
3915 memcpy(&p2p_ea, &dhd->mac, ETHER_ADDR_LEN);
3916 ETHER_SET_LOCALADDR(&p2p_ea);
3917 bcm_mkiovar("p2p_da_override", (char *)&p2p_ea,
3918 ETHER_ADDR_LEN, iovbuf, sizeof(iovbuf));
3919 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR,
3920 iovbuf, sizeof(iovbuf), TRUE, 0)) < 0) {
3921 DHD_ERROR(("%s p2p_da_override ret= %d\n", __FUNCTION__, ret));
3923 DHD_INFO(("dhd_preinit_ioctls: p2p_da_override succeeded\n"));
3927 (void)concurrent_mode;
3931 DHD_ERROR(("Firmware up: op_mode=0x%04x, "
3932 "Broadcom Dongle Host Driver mac="MACDBG"\n",
3934 MAC2STRDBG(dhd->mac.octet)));
3935 /* Set Country code */
3936 if (dhd->dhd_cspec.ccode[0] != 0) {
3937 printf("Set country %s, revision %d\n", dhd->dhd_cspec.ccode, dhd->dhd_cspec.rev);
3938 bcm_mkiovar("country", (char *)&dhd->dhd_cspec,
3939 sizeof(wl_country_t), iovbuf, sizeof(iovbuf));
3940 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0)) < 0)
3941 printf("%s: country code setting failed %d\n", __FUNCTION__, ret);
3943 dhd_conf_set_country(dhd);
3944 dhd_conf_get_country(dhd);
3946 /* Set Listen Interval */
3947 bcm_mkiovar("assoc_listen", (char *)&listen_interval, 4, iovbuf, sizeof(iovbuf));
3948 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0)) < 0)
3949 DHD_ERROR(("%s assoc_listen failed %d\n", __FUNCTION__, ret));
3951 #if defined(ROAM_ENABLE) || defined(DISABLE_BUILTIN_ROAM)
3952 /* Disable built-in roaming to allowed ext supplicant to take care of roaming */
3953 bcm_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf, sizeof(iovbuf));
3954 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
3955 #endif /* ROAM_ENABLE || DISABLE_BUILTIN_ROAM */
3956 #if defined(ROAM_ENABLE)
3957 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_ROAM_TRIGGER, roam_trigger,
3958 sizeof(roam_trigger), TRUE, 0)) < 0)
3959 DHD_ERROR(("%s: roam trigger set failed %d\n", __FUNCTION__, ret));
3960 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_ROAM_SCAN_PERIOD, roam_scan_period,
3961 sizeof(roam_scan_period), TRUE, 0)) < 0)
3962 DHD_ERROR(("%s: roam scan period set failed %d\n", __FUNCTION__, ret));
3963 if ((dhd_wl_ioctl_cmd(dhd, WLC_SET_ROAM_DELTA, roam_delta,
3964 sizeof(roam_delta), TRUE, 0)) < 0)
3965 DHD_ERROR(("%s: roam delta set failed %d\n", __FUNCTION__, ret));
3966 bcm_mkiovar("fullroamperiod", (char *)&roam_fullscan_period, 4, iovbuf, sizeof(iovbuf));
3967 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0)) < 0)
3968 DHD_ERROR(("%s: roam fullscan period set failed %d\n", __FUNCTION__, ret));
3969 #endif /* ROAM_ENABLE */
3970 dhd_conf_set_roam(dhd);
3973 bcm_mkiovar("ccx_enable", (char *)&ccx, 4, iovbuf, sizeof(iovbuf));
3974 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
3977 dhd_tdls_enable_disable(dhd, 1);
3980 #ifdef DHD_ENABLE_LPC
3982 bcm_mkiovar("lpc", (char *)&lpc, 4, iovbuf, sizeof(iovbuf));
3983 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf,
3984 sizeof(iovbuf), TRUE, 0)) < 0) {
3985 DHD_ERROR(("%s Set lpc failed %d\n", __FUNCTION__, ret));
3987 #endif /* DHD_ENABLE_LPC */
3989 /* Set PowerSave mode */
3990 dhd_wl_ioctl_cmd(dhd, WLC_SET_PM, (char *)&power_mode, sizeof(power_mode), TRUE, 0);
3992 /* Match Host and Dongle rx alignment */
3993 bcm_mkiovar("bus:txglomalign", (char *)&dongle_align, 4, iovbuf, sizeof(iovbuf));
3994 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
3996 if (glom != DEFAULT_GLOM_VALUE) {
3997 DHD_INFO(("%s set glom=0x%X\n", __FUNCTION__, glom));
3998 bcm_mkiovar("bus:txglom", (char *)&glom, 4, iovbuf, sizeof(iovbuf));
3999 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
4002 /* Setup timeout if Beacons are lost and roam is off to report link down */
4003 bcm_mkiovar("bcn_timeout", (char *)&bcn_timeout, 4, iovbuf, sizeof(iovbuf));
4004 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
4005 /* Setup assoc_retry_max count to reconnect target AP in dongle */
4006 bcm_mkiovar("assoc_retry_max", (char *)&retry_max, 4, iovbuf, sizeof(iovbuf));
4007 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
4008 #if defined(AP) && !defined(WLP2P)
4009 /* Turn off MPC in AP mode */
4010 bcm_mkiovar("mpc", (char *)&mpc, 4, iovbuf, sizeof(iovbuf));
4011 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
4012 bcm_mkiovar("apsta", (char *)&apsta, 4, iovbuf, sizeof(iovbuf));
4013 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0);
4014 #endif /* defined(AP) && !defined(WLP2P) */
4015 dhd_conf_set_bw(dhd);
4016 dhd_conf_force_wme(dhd);
4017 dhd_conf_set_stbc(dhd);
4020 if (ap_fw_loaded == TRUE) {
4021 dhd_wl_ioctl_cmd(dhd, WLC_SET_DTIMPRD, (char *)&dtim, sizeof(dtim), TRUE, 0);
4025 #if defined(KEEP_ALIVE)
4027 /* Set Keep Alive : be sure to use FW with -keepalive */
4031 if (ap_fw_loaded == FALSE)
4033 if (!(dhd->op_mode & DHD_FLAG_HOSTAP_MODE)) {
4034 if ((res = dhd_keep_alive_onoff(dhd)) < 0)
4035 DHD_ERROR(("%s set keeplive failed %d\n",
4036 __FUNCTION__, res));
4039 #endif /* defined(KEEP_ALIVE) */
4041 bcm_mkiovar("txbf", (char *)&txbf, 4, iovbuf, sizeof(iovbuf));
4042 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf,
4043 sizeof(iovbuf), TRUE, 0)) < 0) {
4044 DHD_ERROR(("%s Set txbf failed %d\n", __FUNCTION__, ret));
4046 #endif /* USE_WL_TXBF */
4047 #ifdef USE_WL_FRAMEBURST
4048 /* Set frameburst to value */
4049 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_FAKEFRAG, (char *)&frameburst,
4050 sizeof(frameburst), TRUE, 0)) < 0) {
4051 DHD_ERROR(("%s Set frameburst failed %d\n", __FUNCTION__, ret));
4053 #endif /* USE_WL_FRAMEBURST */
4054 #ifdef DHD_SET_FW_HIGHSPEED
4056 bcm_mkiovar("ack_ratio", (char *)&ack_ratio, 4, iovbuf, sizeof(iovbuf));
4057 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf,
4058 sizeof(iovbuf), TRUE, 0)) < 0) {
4059 DHD_ERROR(("%s Set ack_ratio failed %d\n", __FUNCTION__, ret));
4062 /* Set ack_ratio_depth */
4063 bcm_mkiovar("ack_ratio_depth", (char *)&ack_ratio_depth, 4, iovbuf, sizeof(iovbuf));
4064 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf,
4065 sizeof(iovbuf), TRUE, 0)) < 0) {
4066 DHD_ERROR(("%s Set ack_ratio_depth failed %d\n", __FUNCTION__, ret));
4068 #endif /* DHD_SET_FW_HIGHSPEED */
4069 #ifdef CUSTOM_AMPDU_BA_WSIZE
4070 /* Set ampdu ba wsize to 64 */
4071 bcm_mkiovar("ampdu_ba_wsize", (char *)&du_ba_wsize, 4, iovbuf, sizeof(iovbuf));
4072 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf,
4073 sizeof(iovbuf), TRUE, 0)) < 0) {
4074 DHD_ERROR(("%s Set ampdu_ba_wsize to %d failed %d\n",
4075 __FUNCTION__, CUSTOM_AMPDU_BA_WSIZE, ret));
4077 #endif /* CUSTOM_AMPDU_BA_WSIZE */
4078 #if defined(BCMSUP_4WAY_HANDSHAKE) && defined(WLAN_AKM_SUITE_FT_8021X)
4079 /* Read 4-way handshake requirements. */
4080 bcm_mkiovar("sup_wpa", (char *)&sup_wpa, 4,
4081 iovbuf, sizeof(iovbuf));
4082 ret = dhd_wl_ioctl_cmd(dhd, WLC_GET_VAR, iovbuf, sizeof(iovbuf), FALSE, 0);
4084 dhd->fw_4way_handshake = TRUE;
4085 DHD_TRACE(("4-way handshake mode is: %d\n", dhd->fw_4way_handshake));
4086 #endif /* BCMSUP_4WAY_HANDSHAKE && WLAN_AKM_SUITE_FT_8021X */
4087 #ifdef SUPPORT_2G_VHT
4088 bcm_mkiovar("vht_features", (char *)&vht_features, 4, iovbuf, sizeof(iovbuf));
4089 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0)) < 0) {
4090 DHD_ERROR(("%s vht_features set failed %d\n", __FUNCTION__, ret));
4092 #endif /* SUPPORT_2G_VHT */
4094 bcm_mkiovar("buf_key_b4_m4", (char *)&buf_key_b4_m4, 4, iovbuf, sizeof(iovbuf));
4095 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf,
4096 sizeof(iovbuf), TRUE, 0)) < 0) {
4097 DHD_ERROR(("%s buf_key_b4_m4 set failed %d\n", __FUNCTION__, ret));
4100 /* Read event_msgs mask */
4101 bcm_mkiovar("event_msgs", eventmask, WL_EVENTING_MASK_LEN, iovbuf, sizeof(iovbuf));
4102 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_GET_VAR, iovbuf, sizeof(iovbuf), FALSE, 0)) < 0) {
4103 DHD_ERROR(("%s read Event mask failed %d\n", __FUNCTION__, ret));
4106 bcopy(iovbuf, eventmask, WL_EVENTING_MASK_LEN);
4108 /* Setup event_msgs */
4109 setbit(eventmask, WLC_E_SET_SSID);
4110 setbit(eventmask, WLC_E_PRUNE);
4111 setbit(eventmask, WLC_E_AUTH);
4112 setbit(eventmask, WLC_E_ASSOC);
4113 setbit(eventmask, WLC_E_REASSOC);
4114 setbit(eventmask, WLC_E_REASSOC_IND);
4115 setbit(eventmask, WLC_E_DEAUTH);
4116 setbit(eventmask, WLC_E_DEAUTH_IND);
4117 setbit(eventmask, WLC_E_DISASSOC_IND);
4118 setbit(eventmask, WLC_E_DISASSOC);
4119 setbit(eventmask, WLC_E_JOIN);
4120 setbit(eventmask, WLC_E_START);
4121 setbit(eventmask, WLC_E_ASSOC_IND);
4122 setbit(eventmask, WLC_E_PSK_SUP);
4123 setbit(eventmask, WLC_E_LINK);
4124 setbit(eventmask, WLC_E_NDIS_LINK);
4125 setbit(eventmask, WLC_E_MIC_ERROR);
4126 setbit(eventmask, WLC_E_ASSOC_REQ_IE);
4127 setbit(eventmask, WLC_E_ASSOC_RESP_IE);
4129 setbit(eventmask, WLC_E_PMKID_CACHE);
4130 setbit(eventmask, WLC_E_TXFAIL);
4132 setbit(eventmask, WLC_E_JOIN_START);
4133 setbit(eventmask, WLC_E_SCAN_COMPLETE);
4135 setbit(eventmask, WLC_E_HTSFSYNC);
4136 #endif /* WLMEDIA_HTSF */
4138 setbit(eventmask, WLC_E_PFN_NET_FOUND);
4139 setbit(eventmask, WLC_E_PFN_BEST_BATCHING);
4140 setbit(eventmask, WLC_E_PFN_BSSID_NET_FOUND);
4141 setbit(eventmask, WLC_E_PFN_BSSID_NET_LOST);
4142 #endif /* PNO_SUPPORT */
4143 /* enable dongle roaming event */
4144 setbit(eventmask, WLC_E_ROAM);
4146 setbit(eventmask, WLC_E_ADDTS_IND);
4147 setbit(eventmask, WLC_E_DELTS_IND);
4150 setbit(eventmask, WLC_E_TDLS_PEER_EVENT);
4153 setbit(eventmask, WLC_E_ESCAN_RESULT);
4154 if (dhd->op_mode & DHD_FLAG_P2P_MODE) {
4155 setbit(eventmask, WLC_E_ACTION_FRAME_RX);
4156 setbit(eventmask, WLC_E_P2P_DISC_LISTEN_COMPLETE);
4158 #endif /* WL_CFG80211 */
4160 /* Write updated Event mask */
4161 bcm_mkiovar("event_msgs", eventmask, WL_EVENTING_MASK_LEN, iovbuf, sizeof(iovbuf));
4162 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0)) < 0) {
4163 DHD_ERROR(("%s Set Event mask failed %d\n", __FUNCTION__, ret));
4167 dhd_wl_ioctl_cmd(dhd, WLC_SET_SCAN_CHANNEL_TIME, (char *)&scan_assoc_time,
4168 sizeof(scan_assoc_time), TRUE, 0);
4169 dhd_wl_ioctl_cmd(dhd, WLC_SET_SCAN_UNASSOC_TIME, (char *)&scan_unassoc_time,
4170 sizeof(scan_unassoc_time), TRUE, 0);
4171 dhd_wl_ioctl_cmd(dhd, WLC_SET_SCAN_PASSIVE_TIME, (char *)&scan_passive_time,
4172 sizeof(scan_passive_time), TRUE, 0);
4174 #ifdef ARP_OFFLOAD_SUPPORT
4175 /* Set and enable ARP offload feature for STA only */
4177 if (arpoe && !ap_fw_loaded)
4182 dhd_arp_offload_enable(dhd, TRUE);
4183 dhd_arp_offload_set(dhd, dhd_arp_mode);
4185 dhd_arp_offload_enable(dhd, FALSE);
4186 dhd_arp_offload_set(dhd, 0);
4188 dhd_arp_enable = arpoe;
4189 #endif /* ARP_OFFLOAD_SUPPORT */
4191 #ifdef PKT_FILTER_SUPPORT
4192 if (dhd->conf->filter_out_all_packets) {
4193 dhd_master_mode = FALSE;
4194 dhd->pktfilter_count = 1;
4195 dhd->pktfilter[0] = "99 0 0 0 0x000000000000 0xFFFFFFFFFFFF";
4197 /* Setup default defintions for pktfilter , enable in suspend */
4198 dhd->pktfilter_count = 6;
4199 /* Setup filter to allow only unicast */
4200 dhd->pktfilter[DHD_UNICAST_FILTER_NUM] = "100 0 0 0 0x01 0x00";
4201 dhd->pktfilter[DHD_BROADCAST_FILTER_NUM] = NULL;
4202 dhd->pktfilter[DHD_MULTICAST4_FILTER_NUM] = NULL;
4203 dhd->pktfilter[DHD_MULTICAST6_FILTER_NUM] = NULL;
4204 /* Add filter to pass multicastDNS packet and NOT filter out as Broadcast */
4205 dhd->pktfilter[DHD_MDNS_FILTER_NUM] = "104 0 0 0 0xFFFFFFFFFFFF 0x01005E0000FB";
4206 /* apply APP pktfilter */
4207 dhd->pktfilter[DHD_ARP_FILTER_NUM] = "105 0 0 12 0xFFFF 0x0806";
4212 dhd_enable_packet_filter(0, dhd);
4214 #endif /* defined(SOFTAP) */
4215 dhd_set_packet_filter(dhd);
4216 #endif /* PKT_FILTER_SUPPORT */
4218 bcm_mkiovar("nmode", (char *)&nmode, 4, iovbuf, sizeof(iovbuf));
4219 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0)) < 0)
4220 DHD_ERROR(("%s wl nmode 0 failed %d\n", __FUNCTION__, ret));
4222 #if defined(PROP_TXSTATUS) && defined(PROP_TXSTATUS_VSDB)
4223 bcm_mkiovar("ampdu_hostreorder", (char *)&hostreorder, 4, buf, sizeof(buf));
4224 dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, buf, sizeof(buf), TRUE, 0);
4226 #endif /* DISABLE_11N */
4228 /* query for 'ver' to get version info from firmware */
4229 memset(buf, 0, sizeof(buf));
4231 bcm_mkiovar("ver", (char *)&buf, 4, buf, sizeof(buf));
4232 if ((ret = dhd_wl_ioctl_cmd(dhd, WLC_GET_VAR, buf, sizeof(buf), FALSE, 0)) < 0)
4233 DHD_ERROR(("%s failed %d\n", __FUNCTION__, ret));
4235 bcmstrtok(&ptr, "\n", 0);
4236 /* Print fw version info */
4237 DHD_ERROR(("Firmware version = %s\n", buf));
4238 dhd_set_version_info(dhd, buf);
4240 /* Check and adjust IOCTL response timeout for Manufactring firmware */
4241 if (strstr(buf, MANUFACTRING_FW) != NULL) {
4242 dhd_os_set_ioctl_resp_timeout(20000);
4243 DHD_ERROR(("%s : adjust IOCTL response time for Manufactring Firmware\n",
4248 #ifdef BCMSDIOH_TXGLOM
4249 if (bcmsdh_glom_enabled()) {
4250 dhd_txglom_enable(dhd, TRUE);
4252 #endif /* BCMSDIOH_TXGLOM */
4254 #if defined(PROP_TXSTATUS) && !defined(PROP_TXSTATUS_VSDB)
4256 #endif /* PROP_TXSTATUS && !PROP_TXSTATUS_VSDB */
4258 if (!dhd->pno_state) {
4269 dhd_iovar(dhd_pub_t *pub, int ifidx, char *name, char *cmd_buf, uint cmd_len, int set)
4271 char buf[strlen(name) + 1 + cmd_len];
4272 int len = sizeof(buf);
4276 len = bcm_mkiovar(name, cmd_buf, cmd_len, buf, len);
4278 memset(&ioc, 0, sizeof(ioc));
4280 ioc.cmd = set? WLC_SET_VAR : WLC_GET_VAR;
4285 ret = dhd_wl_ioctl(pub, ifidx, &ioc, ioc.buf, ioc.len);
4286 if (!set && ret >= 0)
4287 memcpy(cmd_buf, buf, cmd_len);
4292 int dhd_change_mtu(dhd_pub_t *dhdp, int new_mtu, int ifidx)
4294 struct dhd_info *dhd = dhdp->info;
4295 struct net_device *dev = NULL;
4297 ASSERT(dhd && dhd->iflist[ifidx]);
4298 dev = dhd->iflist[ifidx]->net;
4301 if (netif_running(dev)) {
4302 DHD_ERROR(("%s: Must be down to change its MTU", dev->name));
4303 return BCME_NOTDOWN;
4306 #define DHD_MIN_MTU 1500
4307 #define DHD_MAX_MTU 1752
4309 if ((new_mtu < DHD_MIN_MTU) || (new_mtu > DHD_MAX_MTU)) {
4310 DHD_ERROR(("%s: MTU size %d is invalid.\n", __FUNCTION__, new_mtu));
4318 #ifdef ARP_OFFLOAD_SUPPORT
4319 /* add or remove AOE host ip(s) (up to 8 IPs on the interface) */
4321 aoe_update_host_ipv4_table(dhd_pub_t *dhd_pub, u32 ipa, bool add, int idx)
4323 u32 ipv4_buf[MAX_IPV4_ENTRIES]; /* temp save for AOE host_ip table */
4327 bzero(ipv4_buf, sizeof(ipv4_buf));
4329 /* display what we've got */
4330 ret = dhd_arp_get_arp_hostip_table(dhd_pub, ipv4_buf, sizeof(ipv4_buf), idx);
4331 DHD_ARPOE(("%s: hostip table read from Dongle:\n", __FUNCTION__));
4333 dhd_print_buf(ipv4_buf, 32, 4); /* max 8 IPs 4b each */
4335 /* now we saved hoste_ip table, clr it in the dongle AOE */
4336 dhd_aoe_hostip_clr(dhd_pub, idx);
4339 DHD_ERROR(("%s failed\n", __FUNCTION__));
4343 for (i = 0; i < MAX_IPV4_ENTRIES; i++) {
4344 if (add && (ipv4_buf[i] == 0)) {
4346 add = FALSE; /* added ipa to local table */
4347 DHD_ARPOE(("%s: Saved new IP in temp arp_hostip[%d]\n",
4349 } else if (ipv4_buf[i] == ipa) {
4351 DHD_ARPOE(("%s: removed IP:%x from temp table %d\n",
4352 __FUNCTION__, ipa, i));
4355 if (ipv4_buf[i] != 0) {
4356 /* add back host_ip entries from our local cache */
4357 dhd_arp_offload_add_ip(dhd_pub, ipv4_buf[i], idx);
4358 DHD_ARPOE(("%s: added IP:%x to dongle arp_hostip[%d]\n\n",
4359 __FUNCTION__, ipv4_buf[i], i));
4363 /* see the resulting hostip table */
4364 dhd_arp_get_arp_hostip_table(dhd_pub, ipv4_buf, sizeof(ipv4_buf), idx);
4365 DHD_ARPOE(("%s: read back arp_hostip table:\n", __FUNCTION__));
4366 dhd_print_buf(ipv4_buf, 32, 4); /* max 8 IPs 4b each */
4371 * Notification mechanism from kernel to our driver. This function is called by the Linux kernel
4372 * whenever there is an event related to an IP address.
4373 * ptr : kernel provided pointer to IP address that has changed
4375 static int dhd_device_event(struct notifier_block *this,
4376 unsigned long event,
4379 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
4385 if (!dhd_arp_enable)
4387 if (!ifa || !(ifa->ifa_dev->dev))
4390 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
4391 /* Filter notifications meant for non Broadcom devices */
4392 if ((ifa->ifa_dev->dev->netdev_ops != &dhd_ops_pri) &&
4393 (ifa->ifa_dev->dev->netdev_ops != &dhd_ops_virt)) {
4394 #if defined(WL_ENABLE_P2P_IF)
4395 if (!wl_cfgp2p_is_ifops(ifa->ifa_dev->dev->netdev_ops))
4396 #endif /* WL_ENABLE_P2P_IF */
4399 #endif /* LINUX_VERSION_CODE */
4401 dhd = *(dhd_info_t **)netdev_priv(ifa->ifa_dev->dev);
4405 dhd_pub = &dhd->pub;
4407 if (dhd_pub->arp_version == 1) {
4411 for (idx = 0; idx < DHD_MAX_IFS; idx++) {
4412 if (dhd->iflist[idx] && dhd->iflist[idx]->net == ifa->ifa_dev->dev)
4415 if (idx < DHD_MAX_IFS)
4416 DHD_TRACE(("ifidx : %p %s %d\n", dhd->iflist[idx]->net,
4417 dhd->iflist[idx]->name, dhd->iflist[idx]->idx));
4419 DHD_ERROR(("Cannot find ifidx for(%s) set to 0\n", ifa->ifa_label));
4426 DHD_ARPOE(("%s: [%s] Up IP: 0x%x\n",
4427 __FUNCTION__, ifa->ifa_label, ifa->ifa_address));
4429 if (dhd->pub.busstate != DHD_BUS_DATA) {
4430 DHD_ERROR(("%s: bus not ready, exit\n", __FUNCTION__));
4431 if (dhd->pend_ipaddr) {
4432 DHD_ERROR(("%s: overwrite pending ipaddr: 0x%x\n",
4433 __FUNCTION__, dhd->pend_ipaddr));
4435 dhd->pend_ipaddr = ifa->ifa_address;
4439 #ifdef AOE_IP_ALIAS_SUPPORT
4440 DHD_ARPOE(("%s:add aliased IP to AOE hostip cache\n",
4442 aoe_update_host_ipv4_table(dhd_pub, ifa->ifa_address, TRUE, idx);
4443 #endif /* AOE_IP_ALIAS_SUPPORT */
4447 DHD_ARPOE(("%s: [%s] Down IP: 0x%x\n",
4448 __FUNCTION__, ifa->ifa_label, ifa->ifa_address));
4449 dhd->pend_ipaddr = 0;
4450 #ifdef AOE_IP_ALIAS_SUPPORT
4451 DHD_ARPOE(("%s:interface is down, AOE clr all for this if\n",
4453 aoe_update_host_ipv4_table(dhd_pub, ifa->ifa_address, FALSE, idx);
4455 dhd_aoe_hostip_clr(&dhd->pub, idx);
4456 dhd_aoe_arp_clr(&dhd->pub, idx);
4457 #endif /* AOE_IP_ALIAS_SUPPORT */
4461 DHD_ARPOE(("%s: do noting for [%s] Event: %lu\n",
4462 __func__, ifa->ifa_label, event));
4467 #endif /* ARP_OFFLOAD_SUPPORT */
4470 * Neighbor Discovery Offload: Called when an interface
4471 * is assigned with ipv6 address.
4472 * Handles only primary interface
4474 static int dhd_device_ipv6_event(struct notifier_block *this,
4475 unsigned long event,
4480 struct ipv6_addr *_ipv6_addr = NULL;
4481 struct inet6_ifaddr *inet6_ifa = ptr;
4483 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
4484 /* Filter notifications meant for non Broadcom devices */
4485 if (inet6_ifa->idev->dev->netdev_ops != &dhd_ops_pri) {
4488 #endif /* LINUX_VERSION_CODE */
4490 dhd = *(dhd_info_t **)netdev_priv(inet6_ifa->idev->dev);
4494 idx = dhd_net2idx(dhd, inet6_ifa->idev->dev);
4495 if (idx == DHD_BAD_IF) {
4496 DHD_ERROR(("Cannot find ifidx"));
4499 dhd_pub = &dhd->pub;
4500 if (!FW_SUPPORTED(dhd_pub, ndoe))
4502 if (event == NETDEV_UP || event == NETDEV_DOWN) {
4503 _ipv6_addr = NATIVE_MALLOC(dhd_pub->osh, sizeof(struct ipv6_addr));
4504 if (_ipv6_addr == NULL) {
4505 DHD_ERROR(("Failed to allocate ipv6\n"));
4508 memcpy(&_ipv6_addr->ipv6_addr[0], &inet6_ifa->addr, IPV6_ADDR_LEN);
4509 DHD_TRACE(("IPV6 address : %pI6\n", &inet6_ifa->addr));
4513 DHD_TRACE(("%s: Enable NDO and add ipv6 into table \n ", __FUNCTION__));
4514 _ipv6_addr->ipv6_oper = DHD_IPV6_ADDR_ADD;
4517 DHD_TRACE(("%s: clear ipv6 table \n", __FUNCTION__));
4518 _ipv6_addr->ipv6_oper = DHD_IPV6_ADDR_DELETE;
4521 DHD_ERROR(("%s: unknown notifier event \n", __FUNCTION__));
4524 spin_lock_bh(&dhd->iflist[idx]->ipv6_lock);
4525 list_add_tail(&_ipv6_addr->list, &dhd->iflist[idx]->ipv6_list);
4526 spin_unlock_bh(&dhd->iflist[idx]->ipv6_lock);
4527 up(&dhd->thr_sysioc_ctl.sema);
4533 dhd_net_attach(dhd_pub_t *dhdp, int ifidx)
4535 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
4536 struct net_device *net = NULL;
4538 uint8 temp_addr[ETHER_ADDR_LEN] = { 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33 };
4540 DHD_TRACE(("%s: ifidx %d\n", __FUNCTION__, ifidx));
4542 ASSERT(dhd && dhd->iflist[ifidx]);
4544 net = dhd->iflist[ifidx]->net;
4547 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31))
4549 net->get_stats = dhd_get_stats;
4550 net->do_ioctl = dhd_ioctl_entry;
4551 net->hard_start_xmit = dhd_start_xmit;
4552 net->set_mac_address = dhd_set_mac_address;
4553 net->set_multicast_list = dhd_set_multicast_list;
4554 net->open = net->stop = NULL;
4556 ASSERT(!net->netdev_ops);
4557 net->netdev_ops = &dhd_ops_virt;
4558 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31) */
4560 /* Ok, link into the network layer... */
4563 * device functions for the primary interface only
4565 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31))
4566 net->open = dhd_open;
4567 net->stop = dhd_stop;
4569 net->netdev_ops = &dhd_ops_pri;
4570 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31) */
4571 if (!ETHER_ISNULLADDR(dhd->pub.mac.octet))
4572 memcpy(temp_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN);
4575 * We have to use the primary MAC for virtual interfaces
4577 memcpy(temp_addr, dhd->iflist[ifidx]->mac_addr, ETHER_ADDR_LEN);
4579 * Android sets the locally administered bit to indicate that this is a
4580 * portable hotspot. This will not work in simultaneous AP/STA mode,
4581 * nor with P2P. Need to set the Donlge's MAC address, and then use that.
4583 if (!memcmp(temp_addr, dhd->iflist[0]->mac_addr,
4585 DHD_ERROR(("%s interface [%s]: set locally administered bit in MAC\n",
4586 __func__, net->name));
4587 temp_addr[0] |= 0x02;
4591 net->hard_header_len = ETH_HLEN + dhd->pub.hdrlen;
4592 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
4593 net->ethtool_ops = &dhd_ethtool_ops;
4594 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) */
4596 #if defined(WL_WIRELESS_EXT)
4597 #if WIRELESS_EXT < 19
4598 net->get_wireless_stats = dhd_get_wireless_stats;
4599 #endif /* WIRELESS_EXT < 19 */
4600 #if WIRELESS_EXT > 12
4601 net->wireless_handlers = (struct iw_handler_def *)&wl_iw_handler_def;
4602 #endif /* WIRELESS_EXT > 12 */
4603 #endif /* defined(WL_WIRELESS_EXT) */
4605 dhd->pub.rxsz = DBUS_RX_BUFFER_SIZE_DHD(net);
4607 memcpy(net->dev_addr, temp_addr, ETHER_ADDR_LEN);
4610 if ((err = register_netdev(net)) != 0) {
4611 DHD_ERROR(("couldn't register the net device, err %d\n", err));
4614 printf("Broadcom Dongle Host Driver: register interface [%s]"
4617 MAC2STRDBG(net->dev_addr));
4619 #if defined(SOFTAP) && defined(WL_WIRELESS_EXT) && !defined(WL_CFG80211)
4620 wl_iw_iscan_set_scan_broadcast_prep(net, 1);
4623 #if 1 && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
4625 dhd_registration_check = TRUE;
4626 up(&dhd_registration_sem);
4632 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31)
4635 net->netdev_ops = NULL;
4641 dhd_bus_detach(dhd_pub_t *dhdp)
4645 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
4648 dhd = (dhd_info_t *)dhdp->info;
4652 * In case of Android cfg80211 driver, the bus is down in dhd_stop,
4653 * calling stop again will cuase SD read/write errors.
4655 if (dhd->pub.busstate != DHD_BUS_DOWN) {
4656 /* Stop the protocol module */
4657 dhd_prot_stop(&dhd->pub);
4659 /* Stop the bus module */
4660 dhd_bus_stop(dhd->pub.bus, TRUE);
4663 #if defined(OOB_INTR_ONLY)
4664 bcmsdh_unregister_oob_intr();
4671 void dhd_detach(dhd_pub_t *dhdp)
4674 unsigned long flags;
4675 int timer_valid = FALSE;
4680 dhd = (dhd_info_t *)dhdp->info;
4684 DHD_TRACE(("%s: Enter state 0x%x\n", __FUNCTION__, dhd->dhd_state));
4685 #ifdef ARP_OFFLOAD_SUPPORT
4686 unregister_inetaddr_notifier(&dhd_notifier);
4687 #endif /* ARP_OFFLOAD_SUPPORT */
4688 unregister_inet6addr_notifier(&dhd_notifier_ipv6);
4691 if (!(dhd->dhd_state & DHD_ATTACH_STATE_DONE)) {
4692 /* Give sufficient time for threads to start running in case
4693 * dhd_attach() has failed
4698 if (dhd->dhd_state & DHD_ATTACH_STATE_PROT_ATTACH) {
4699 dhd_bus_detach(dhdp);
4702 dhd_prot_detach(dhdp);
4705 #if defined(CONFIG_HAS_EARLYSUSPEND) && defined(DHD_USE_EARLYSUSPEND)
4706 if (dhd->dhd_state & DHD_ATTACH_STATE_EARLYSUSPEND_DONE) {
4707 if (dhd->early_suspend.suspend)
4708 unregister_early_suspend(&dhd->early_suspend);
4710 #endif /* CONFIG_HAS_EARLYSUSPEND && DHD_USE_EARLYSUSPEND */
4712 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
4713 cancel_work_sync(&dhd->work_hang);
4714 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
4716 #if defined(WL_WIRELESS_EXT)
4717 if (dhd->dhd_state & DHD_ATTACH_STATE_WL_ATTACH) {
4718 /* Detatch and unlink in the iw */
4721 #endif /* defined(WL_WIRELESS_EXT) */
4723 if (dhd->thr_sysioc_ctl.thr_pid >= 0) {
4724 PROC_STOP(&dhd->thr_sysioc_ctl);
4727 /* delete all interfaces, start with virtual */
4728 if (dhd->dhd_state & DHD_ATTACH_STATE_ADD_IF) {
4732 /* Cleanup virtual interfaces */
4733 for (i = 1; i < DHD_MAX_IFS; i++) {
4734 dhd_net_if_lock_local(dhd);
4735 if (dhd->iflist[i]) {
4736 dhd->iflist[i]->state = DHD_IF_DEL;
4737 dhd->iflist[i]->idx = i;
4738 dhd_op_if(dhd->iflist[i]);
4741 dhd_net_if_unlock_local(dhd);
4743 /* delete primary interface 0 */
4744 ifp = dhd->iflist[0];
4747 if (ifp && ifp->net) {
4748 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31))
4751 if (ifp->net->netdev_ops == &dhd_ops_pri)
4754 unregister_netdev(ifp->net);
4755 free_netdev(ifp->net);
4757 MFREE(dhd->pub.osh, ifp, sizeof(*ifp));
4758 dhd->iflist[0] = NULL;
4763 /* Clear the watchdog timer */
4764 flags = dhd_os_spin_lock(&dhd->pub);
4765 timer_valid = dhd->wd_timer_valid;
4766 dhd->wd_timer_valid = FALSE;
4767 dhd_os_spin_unlock(&dhd->pub, flags);
4769 del_timer_sync(&dhd->timer);
4771 if (dhd->dhd_state & DHD_ATTACH_STATE_THREADS_CREATED) {
4773 if (dhd->thr_wdt_ctl.thr_pid >= 0) {
4774 PROC_STOP(&dhd->thr_wdt_ctl);
4777 if (dhd->thr_dpc_ctl.thr_pid >= 0) {
4778 PROC_STOP(&dhd->thr_dpc_ctl);
4780 #ifdef RXFRAME_THREAD
4781 if (dhd->thr_rxf_ctl.thr_pid >= 0) {
4782 PROC_STOP(&dhd->thr_rxf_ctl);
4786 #endif /* DHDTHREAD */
4787 tasklet_kill(&dhd->tasklet);
4790 if (dhd->dhd_state & DHD_ATTACH_STATE_CFG80211) {
4791 wl_cfg80211_detach(NULL);
4792 dhd_monitor_uninit();
4795 dhd_conf_detach(dhdp);
4798 if (dhdp->pno_state)
4799 dhd_pno_deinit(dhdp);
4801 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && (LINUX_VERSION_CODE <= \
4802 KERNEL_VERSION(2, 6, 39)) && defined(CONFIG_PM_SLEEP)
4803 unregister_pm_notifier(&dhd_sleep_pm_notifier);
4804 #endif /* (LINUX_VERSION >= 2.6.27 && LINUX_VERSION <= 2.6.39 && CONFIG_PM_SLEEP */
4806 if (dhd->dhd_state & DHD_ATTACH_STATE_WAKELOCKS_INIT) {
4807 DHD_TRACE(("wd wakelock count:%d\n", dhd->wakelock_wd_counter));
4808 #ifdef CONFIG_HAS_WAKELOCK
4809 dhd->wakelock_counter = 0;
4810 dhd->wakelock_wd_counter = 0;
4811 dhd->wakelock_rx_timeout_enable = 0;
4812 dhd->wakelock_ctrl_timeout_enable = 0;
4813 wake_lock_destroy(&dhd->wl_wifi);
4814 wake_lock_destroy(&dhd->wl_rxwake);
4815 wake_lock_destroy(&dhd->wl_ctrlwake);
4816 wake_lock_destroy(&dhd->wl_wdwake);
4817 #endif /* CONFIG_HAS_WAKELOCK */
4823 dhd_free(dhd_pub_t *dhdp)
4826 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
4830 for (i = 0; i < ARRAYSIZE(dhdp->reorder_bufs); i++) {
4831 if (dhdp->reorder_bufs[i]) {
4832 reorder_info_t *ptr;
4833 uint32 buf_size = sizeof(struct reorder_info);
4835 ptr = dhdp->reorder_bufs[i];
4837 buf_size += ((ptr->max_idx + 1) * sizeof(void*));
4838 DHD_REORDER(("free flow id buf %d, maxidx is %d, buf_size %d\n",
4839 i, ptr->max_idx, buf_size));
4841 MFREE(dhdp->osh, dhdp->reorder_bufs[i], buf_size);
4842 dhdp->reorder_bufs[i] = NULL;
4845 dhd = (dhd_info_t *)dhdp->info;
4846 #if defined(CONFIG_DHD_USE_STATIC_BUF)
4847 /* If pointer is allocated by dhd_os_prealloc then avoid MFREE */
4848 if (dhd != (dhd_info_t *)dhd_os_prealloc(NULL, DHD_PREALLOC_DHD_INFO, 0)) {
4849 #endif /* CONFIG_DHD_USE_STATIC_BUF */
4851 MFREE(dhd->pub.osh, dhd, sizeof(*dhd));
4852 #if defined(CONFIG_DHD_USE_STATIC_BUF)
4858 #endif /* CONFIG_DHD_USE_STATIC_BUF */
4863 dhd_module_cleanup(void)
4865 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
4867 dhd_bus_unregister();
4869 #if defined(CONFIG_WIFI_CONTROL_FUNC)
4870 wl_android_wifictrl_func_del();
4871 #endif /* CONFIG_WIFI_CONTROL_FUNC */
4874 /* Call customer gpio to turn off power with WL_REG_ON signal */
4875 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
4878 #if defined(CONFIG_WIFI_CONTROL_FUNC)
4879 extern bool g_wifi_poweron;
4880 #endif /* CONFIG_WIFI_CONTROL_FUNC */
4884 dhd_module_init(void)
4888 #if 1 && defined(BCMLXSDMMC) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
4889 int retry = POWERUP_MAX_RETRY;
4893 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
4897 #if defined(DHDTHREAD)
4898 /* Sanity check on the module parameters */
4900 /* Both watchdog and DPC as tasklets are ok */
4901 if ((dhd_watchdog_prio < 0) && (dhd_dpc_prio < 0))
4904 /* If both watchdog and DPC are threads, TX must be deferred */
4905 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0) && dhd_deferred_tx)
4908 DHD_ERROR(("Invalid module parameters.\n"));
4915 #if 1 && defined(BCMLXSDMMC) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
4917 sema_init(&dhd_chipup_sem, 0);
4918 dhd_bus_reg_sdio_notify(&dhd_chipup_sem);
4919 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_ON);
4920 #if defined(CONFIG_WIFI_CONTROL_FUNC)
4921 if (wl_android_wifictrl_func_add() < 0) {
4922 dhd_bus_unreg_sdio_notify();
4925 #endif /* defined(CONFIG_WIFI_CONTROL_FUNC) */
4926 if (down_timeout(&dhd_chipup_sem,
4927 msecs_to_jiffies(POWERUP_WAIT_MS)) == 0) {
4928 dhd_bus_unreg_sdio_notify();
4932 DHD_ERROR(("\nfailed to power up wifi chip, retry again (%d left) **\n\n",
4934 dhd_bus_unreg_sdio_notify();
4935 #if defined(CONFIG_WIFI_CONTROL_FUNC)
4936 wl_android_wifictrl_func_del();
4937 #endif /* defined(CONFIG_WIFI_CONTROL_FUNC) */
4938 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
4939 } while (retry-- > 0);
4942 DHD_ERROR(("\nfailed to power up wifi chip, max retry reached, exits **\n\n"));
4947 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_ON);
4948 #if defined(CONFIG_WIFI_CONTROL_FUNC)
4949 if (wl_android_wifictrl_func_add() < 0)
4951 #endif /* defined(CONFIG_WIFI_CONTROL_FUNC) */
4955 #if defined(CONFIG_WIFI_CONTROL_FUNC) && defined(BCMLXSDMMC)
4956 /* If the wifi_set_power() is failed,
4957 * we need to jump error handling routines.
4959 if (!g_wifi_poweron) {
4960 printk("%s: wifi_set_power() failed\n", __FUNCTION__);
4964 #endif /* defined(CONFIG_WIFI_CONTROL_FUNC) */
4966 #if 1 && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
4967 sema_init(&dhd_registration_sem, 0);
4971 error = dhd_bus_register();
4974 printf("\n%s\n", dhd_version);
4976 DHD_ERROR(("%s: sdio_register_driver failed\n", __FUNCTION__));
4980 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(BCMLXSDMMC)
4982 * Wait till MMC sdio_register_driver callback called and made driver attach.
4983 * It's needed to make sync up exit from dhd insmod and
4984 * Kernel MMC sdio device callback registration
4986 if ((down_timeout(&dhd_registration_sem,
4987 msecs_to_jiffies(DHD_REGISTRATION_TIMEOUT)) != 0) ||
4988 (dhd_registration_check != TRUE)) {
4990 DHD_ERROR(("%s: sdio_register_driver timeout or error \n", __FUNCTION__));
4993 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
4994 #if defined(WL_CFG80211)
4995 wl_android_post_init();
4996 #endif /* defined(WL_CFG80211) */
5000 #if 1 && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && defined(BCMLXSDMMC)
5002 dhd_bus_unregister();
5003 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
5007 #if defined(CONFIG_WIFI_CONTROL_FUNC)
5008 wl_android_wifictrl_func_del();
5011 /* Call customer gpio to turn off power with WL_REG_ON signal */
5012 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
5021 extern char WIFI_MODULE_NAME[];
5022 extern char RKWIFI_DRV_VERSION[];
5024 int rockchip_wifi_init_module_rkwifi(void)
5026 printk("=======================================================\n");
5027 printk("==== Launching Wi-Fi driver! (Powered by Rockchip) ====\n");
5028 printk("=======================================================\n");
5029 printk("%s WiFi driver (Powered by Rockchip,Ver %s) init.\n", WIFI_MODULE_NAME, RKWIFI_DRV_VERSION);
5031 return dhd_module_init();
5034 void rockchip_wifi_exit_module_rkwifi(void)
5036 printk("=======================================================\n");
5037 printk("== Dis-launching Wi-Fi driver! (Powered by Rockchip) ==\n");
5038 printk("=======================================================\n");
5039 dhd_module_cleanup();
5042 EXPORT_SYMBOL(rockchip_wifi_init_module_rkwifi);
5043 EXPORT_SYMBOL(rockchip_wifi_exit_module_rkwifi);
5044 //late_initcall(rockchip_wifi_init_module);
5045 //module_exit(rockchip_wifi_exit_module);
5047 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
5048 #ifdef USE_LATE_INITCALL_SYNC
5049 late_initcall_sync(dhd_module_init);
5051 late_initcall(dhd_module_init);
5052 #endif // USE_LATE_INITCALL_SYNC
5054 module_init(dhd_module_init);
5055 #endif // LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
5057 module_exit(dhd_module_cleanup);
5061 * OS specific functions required to implement DHD driver in OS independent way
5064 dhd_os_proto_block(dhd_pub_t *pub)
5066 dhd_info_t * dhd = (dhd_info_t *)(pub->info);
5069 down(&dhd->proto_sem);
5077 dhd_os_proto_unblock(dhd_pub_t *pub)
5079 dhd_info_t * dhd = (dhd_info_t *)(pub->info);
5082 up(&dhd->proto_sem);
5090 dhd_os_get_ioctl_resp_timeout(void)
5092 return ((unsigned int)dhd_ioctl_timeout_msec);
5096 dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec)
5098 dhd_ioctl_timeout_msec = (int)timeout_msec;
5102 dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition, bool *pending)
5104 dhd_info_t * dhd = (dhd_info_t *)(pub->info);
5107 /* Convert timeout in millsecond to jiffies */
5108 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
5109 timeout = msecs_to_jiffies(dhd_ioctl_timeout_msec);
5111 timeout = dhd_ioctl_timeout_msec * HZ / 1000;
5114 timeout = wait_event_timeout(dhd->ioctl_resp_wait, (*condition), timeout);
5119 dhd_os_ioctl_resp_wake(dhd_pub_t *pub)
5121 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
5123 if (waitqueue_active(&dhd->ioctl_resp_wait)) {
5124 wake_up(&dhd->ioctl_resp_wait);
5131 dhd_os_wd_timer_extend(void *bus, bool extend)
5133 dhd_pub_t *pub = bus;
5134 dhd_info_t *dhd = (dhd_info_t *)pub->info;
5137 dhd_os_wd_timer(bus, WATCHDOG_EXTEND_INTERVAL);
5139 dhd_os_wd_timer(bus, dhd->default_wd_interval);
5144 dhd_os_wd_timer(void *bus, uint wdtick)
5146 dhd_pub_t *pub = bus;
5147 dhd_info_t *dhd = (dhd_info_t *)pub->info;
5148 unsigned long flags;
5150 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
5153 DHD_ERROR(("%s: dhd NULL\n", __FUNCTION__));
5157 flags = dhd_os_spin_lock(pub);
5159 /* don't start the wd until fw is loaded */
5160 if (pub->busstate == DHD_BUS_DOWN) {
5161 dhd_os_spin_unlock(pub, flags);
5163 DHD_OS_WD_WAKE_UNLOCK(pub);
5167 /* Totally stop the timer */
5168 if (!wdtick && dhd->wd_timer_valid == TRUE) {
5169 dhd->wd_timer_valid = FALSE;
5170 dhd_os_spin_unlock(pub, flags);
5172 del_timer_sync(&dhd->timer);
5174 del_timer(&dhd->timer);
5175 #endif /* DHDTHREAD */
5176 DHD_OS_WD_WAKE_UNLOCK(pub);
5181 DHD_OS_WD_WAKE_LOCK(pub);
5182 dhd_watchdog_ms = (uint)wdtick;
5183 /* Re arm the timer, at last watchdog period */
5184 mod_timer(&dhd->timer, jiffies + msecs_to_jiffies(dhd_watchdog_ms));
5185 dhd->wd_timer_valid = TRUE;
5187 dhd_os_spin_unlock(pub, flags);
5191 dhd_os_open_image(char *filename)
5195 fp = filp_open(filename, O_RDONLY, 0);
5197 * 2.6.11 (FC4) supports filp_open() but later revs don't?
5199 * fp = open_namei(AT_FDCWD, filename, O_RD, 0);
5209 dhd_os_get_image_block(char *buf, int len, void *image)
5211 struct file *fp = (struct file *)image;
5217 rdlen = kernel_read(fp, fp->f_pos, buf, len);
5225 dhd_os_close_image(void *image)
5228 filp_close((struct file *)image, NULL);
5233 dhd_os_sdlock(dhd_pub_t *pub)
5237 dhd = (dhd_info_t *)(pub->info);
5240 if (dhd->threads_only)
5243 #endif /* DHDTHREAD */
5244 spin_lock_bh(&dhd->sdlock);
5248 dhd_os_sdunlock(dhd_pub_t *pub)
5252 dhd = (dhd_info_t *)(pub->info);
5255 if (dhd->threads_only)
5258 #endif /* DHDTHREAD */
5259 spin_unlock_bh(&dhd->sdlock);
5263 dhd_os_sdlock_txq(dhd_pub_t *pub)
5267 dhd = (dhd_info_t *)(pub->info);
5268 spin_lock_bh(&dhd->txqlock);
5272 dhd_os_sdunlock_txq(dhd_pub_t *pub)
5276 dhd = (dhd_info_t *)(pub->info);
5277 spin_unlock_bh(&dhd->txqlock);
5281 dhd_os_sdlock_rxq(dhd_pub_t *pub)
5286 dhd_os_sdunlock_rxq(dhd_pub_t *pub)
5291 dhd_os_sdtxlock(dhd_pub_t *pub)
5297 dhd_os_sdtxunlock(dhd_pub_t *pub)
5299 dhd_os_sdunlock(pub);
5302 #if defined(DHDTHREAD) && defined(RXFRAME_THREAD)
5304 dhd_os_rxflock(dhd_pub_t *pub)
5308 dhd = (dhd_info_t *)(pub->info);
5309 spin_lock_bh(&dhd->rxf_lock);
5314 dhd_os_rxfunlock(dhd_pub_t *pub)
5318 dhd = (dhd_info_t *)(pub->info);
5319 spin_unlock_bh(&dhd->rxf_lock);
5321 #endif /* defined(DHDTHREAD) && defined(RXFRAME_THREAD) */
5323 #ifdef DHDTCPACK_SUPPRESS
5325 dhd_os_tcpacklock(dhd_pub_t *pub)
5329 dhd = (dhd_info_t *)(pub->info);
5330 spin_lock_bh(&dhd->tcpack_lock);
5335 dhd_os_tcpackunlock(dhd_pub_t *pub)
5339 dhd = (dhd_info_t *)(pub->info);
5340 spin_unlock_bh(&dhd->tcpack_lock);
5342 #endif /* DHDTCPACK_SUPPRESS */
5344 #if defined(CONFIG_DHD_USE_STATIC_BUF)
5345 uint8* dhd_os_prealloc(void *osh, int section, uint size)
5347 return (uint8*)wl_android_prealloc(section, size);
5350 void dhd_os_prefree(void *osh, void *addr, uint size)
5353 #endif /* defined(CONFIG_WIFI_CONTROL_FUNC) */
5355 #if defined(WL_WIRELESS_EXT)
5356 struct iw_statistics *
5357 dhd_get_wireless_stats(struct net_device *dev)
5360 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
5366 res = wl_iw_get_wireless_stats(dev, &dhd->iw.wstats);
5369 return &dhd->iw.wstats;
5373 #endif /* defined(WL_WIRELESS_EXT) */
5376 dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
5377 wl_event_msg_t *event, void **data)
5380 ASSERT(dhd != NULL);
5382 bcmerror = wl_host_event(&dhd->pub, ifidx, pktdata, event, data);
5383 if (bcmerror != BCME_OK)
5386 #if defined(WL_WIRELESS_EXT)
5387 if (event->bsscfgidx == 0) {
5389 * Wireless ext is on primary interface only
5392 ASSERT(dhd->iflist[*ifidx] != NULL);
5393 ASSERT(dhd->iflist[*ifidx]->net != NULL);
5395 if (dhd->iflist[*ifidx]->net) {
5396 wl_iw_event(dhd->iflist[*ifidx]->net, event, *data);
5399 #endif /* defined(WL_WIRELESS_EXT) */
5402 if ((ntoh32(event->event_type) == WLC_E_IF) &&
5403 (((dhd_if_event_t *)*data)->action == WLC_E_IF_ADD))
5404 /* If ADD_IF has been called directly by wl utility then we
5405 * should not report this. In case if ADD_IF was called from
5406 * CFG stack, then too this event need not be reported back
5409 if ((wl_cfg80211_is_progress_ifchange() ||
5410 wl_cfg80211_is_progress_ifadd()) && (*ifidx != 0)) {
5412 * If IF_ADD/CHANGE operation is going on,
5413 * discard any event received on the virtual I/F
5418 ASSERT(dhd->iflist[*ifidx] != NULL);
5419 ASSERT(dhd->iflist[*ifidx]->net != NULL);
5420 if (dhd->iflist[*ifidx]->event2cfg80211 && dhd->iflist[*ifidx]->net) {
5421 wl_cfg80211_event(dhd->iflist[*ifidx]->net, event, *data);
5423 #endif /* defined(WL_CFG80211) */
5428 /* send up locally generated event */
5430 dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data)
5432 switch (ntoh32(event->event_type)) {
5434 /* Send up locally generated AMP HCI Events */
5435 case WLC_E_BTA_HCI_EVENT: {
5436 struct sk_buff *p, *skb;
5438 wl_event_msg_t *p_bcm_event;
5447 len = ntoh32(event->datalen);
5448 pktlen = sizeof(bcm_event_t) + len + 2;
5450 ifidx = dhd_ifname2idx(dhd, event->ifname);
5452 if ((p = PKTGET(dhdp->osh, pktlen, FALSE))) {
5453 ASSERT(ISALIGNED((uintptr)PKTDATA(dhdp->osh, p), sizeof(uint32)));
5455 msg = (bcm_event_t *) PKTDATA(dhdp->osh, p);
5457 bcopy(&dhdp->mac, &msg->eth.ether_dhost, ETHER_ADDR_LEN);
5458 bcopy(&dhdp->mac, &msg->eth.ether_shost, ETHER_ADDR_LEN);
5459 ETHER_TOGGLE_LOCALADDR(&msg->eth.ether_shost);
5461 msg->eth.ether_type = hton16(ETHER_TYPE_BRCM);
5463 /* BCM Vendor specific header... */
5464 msg->bcm_hdr.subtype = hton16(BCMILCP_SUBTYPE_VENDOR_LONG);
5465 msg->bcm_hdr.version = BCMILCP_BCM_SUBTYPEHDR_VERSION;
5466 bcopy(BRCM_OUI, &msg->bcm_hdr.oui[0], DOT11_OUI_LEN);
5468 /* vendor spec header length + pvt data length (private indication
5469 * hdr + actual message itself)
5471 msg->bcm_hdr.length = hton16(BCMILCP_BCM_SUBTYPEHDR_MINLENGTH +
5472 BCM_MSG_LEN + sizeof(wl_event_msg_t) + (uint16)len);
5473 msg->bcm_hdr.usr_subtype = hton16(BCMILCP_BCM_SUBTYPE_EVENT);
5475 PKTSETLEN(dhdp->osh, p, (sizeof(bcm_event_t) + len + 2));
5477 /* copy wl_event_msg_t into sk_buf */
5479 /* pointer to wl_event_msg_t in sk_buf */
5480 p_bcm_event = &msg->event;
5481 bcopy(event, p_bcm_event, sizeof(wl_event_msg_t));
5483 /* copy hci event into sk_buf */
5484 bcopy(data, (p_bcm_event + 1), len);
5486 msg->bcm_hdr.length = hton16(sizeof(wl_event_msg_t) +
5487 ntoh16(msg->bcm_hdr.length));
5488 PKTSETLEN(dhdp->osh, p, (sizeof(bcm_event_t) + len + 2));
5490 ptr = (char *)(msg + 1);
5491 /* Last 2 bytes of the message are 0x00 0x00 to signal that there
5492 * are no ethertypes which are following this
5497 skb = PKTTONATIVE(dhdp->osh, p);
5501 ifp = dhd->iflist[ifidx];
5503 ifp = dhd->iflist[0];
5506 skb->dev = ifp->net;
5507 skb->protocol = eth_type_trans(skb, skb->dev);
5512 /* Strip header, count, deliver upward */
5513 skb_pull(skb, ETH_HLEN);
5515 /* Send the packet */
5516 if (in_interrupt()) {
5523 /* Could not allocate a sk_buf */
5524 DHD_ERROR(("%s: unable to alloc sk_buf", __FUNCTION__));
5527 } /* case WLC_E_BTA_HCI_EVENT */
5528 #endif /* WLBTAMP */
5535 void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar)
5537 #if 1 && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
5538 struct dhd_info *dhdinfo = dhd->info;
5540 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
5541 int timeout = msecs_to_jiffies(IOCTL_RESP_TIMEOUT);
5543 int timeout = (IOCTL_RESP_TIMEOUT / 1000) * HZ;
5544 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) */
5546 dhd_os_sdunlock(dhd);
5547 wait_event_timeout(dhdinfo->ctrl_wait, (*lockvar == FALSE), timeout);
5553 void dhd_wait_event_wakeup(dhd_pub_t *dhd)
5555 #if 1 && (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
5556 struct dhd_info *dhdinfo = dhd->info;
5557 if (waitqueue_active(&dhdinfo->ctrl_wait))
5558 wake_up(&dhdinfo->ctrl_wait);
5564 dhd_dev_reset(struct net_device *dev, uint8 flag)
5568 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
5571 /* Issue wl down command before resetting the chip */
5572 if (dhd_wl_ioctl_cmd(&dhd->pub, WLC_DOWN, NULL, 0, TRUE, 0) < 0) {
5573 DHD_TRACE(("%s: wl down failed\n", __FUNCTION__));
5575 #if defined(PROP_TXSTATUS) && !defined(PROP_TXSTATUS_VSDB)
5576 dhd_wlfc_deinit(&dhd->pub);
5577 if (dhd->pub.plat_deinit)
5578 dhd->pub.plat_deinit((void *)&dhd->pub);
5579 #endif /* PROP_TXSTATUS && !PROP_TXSTATUS_VSDB */
5582 ret = dhd_bus_devreset(&dhd->pub, flag);
5584 DHD_ERROR(("%s: dhd_bus_devreset: %d\n", __FUNCTION__, ret));
5591 int net_os_set_suspend_disable(struct net_device *dev, int val)
5593 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
5597 ret = dhd->pub.suspend_disable_flag;
5598 dhd->pub.suspend_disable_flag = val;
5603 int net_os_set_suspend(struct net_device *dev, int val, int force)
5606 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
5609 #if defined(CONFIG_HAS_EARLYSUSPEND) && defined(DHD_USE_EARLYSUSPEND)
5610 ret = dhd_set_suspend(val, &dhd->pub);
5612 ret = dhd_suspend_resume_helper(dhd, val, force);
5615 wl_cfg80211_update_power_mode(dev);
5621 int net_os_set_suspend_bcn_li_dtim(struct net_device *dev, int val)
5623 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
5626 dhd->pub.suspend_bcn_li_dtim = val;
5631 #ifdef PKT_FILTER_SUPPORT
5632 int net_os_rxfilter_add_remove(struct net_device *dev, int add_remove, int num)
5634 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
5635 char *filterp = NULL;
5639 if (dhd->pub.conf->filter_out_all_packets)
5642 if (!dhd || (num == DHD_UNICAST_FILTER_NUM) ||
5643 (num == DHD_MDNS_FILTER_NUM))
5645 if (num >= dhd->pub.pktfilter_count)
5648 case DHD_BROADCAST_FILTER_NUM:
5649 filterp = "101 0 0 0 0xFFFFFFFFFFFF 0xFFFFFFFFFFFF";
5652 case DHD_MULTICAST4_FILTER_NUM:
5653 filterp = "102 0 0 0 0xFFFFFF 0x01005E";
5656 case DHD_MULTICAST6_FILTER_NUM:
5657 filterp = "103 0 0 0 0xFFFF 0x3333";
5666 dhd->pub.pktfilter[num] = filterp;
5667 dhd_pktfilter_offload_set(&dhd->pub, dhd->pub.pktfilter[num]);
5668 } else { /* Delete filter */
5669 dhd_pktfilter_offload_delete(&dhd->pub, filter_id);
5674 int dhd_os_enable_packet_filter(dhd_pub_t *dhdp, int val)
5678 /* Packet filtering is set only if we still in early-suspend and
5679 * we need either to turn it ON or turn it OFF
5680 * We can always turn it OFF in case of early-suspend, but we turn it
5681 * back ON only if suspend_disable_flag was not set
5683 if (dhdp && dhdp->up) {
5684 if (dhdp->in_suspend) {
5685 if (!val || (val && !dhdp->suspend_disable_flag))
5686 dhd_enable_packet_filter(val, dhdp);
5692 /* function to enable/disable packet for Network device */
5693 int net_os_enable_packet_filter(struct net_device *dev, int val)
5695 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
5697 return dhd_os_enable_packet_filter(&dhd->pub, val);
5699 #endif /* PKT_FILTER_SUPPORT */
5702 dhd_dev_init_ioctl(struct net_device *dev)
5704 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
5707 dhd_process_cid_mac(&dhd->pub, TRUE);
5709 if ((ret = dhd_preinit_ioctls(&dhd->pub)) < 0)
5712 dhd_process_cid_mac(&dhd->pub, FALSE);
5719 /* Linux wrapper to call common dhd_pno_stop_for_ssid */
5721 dhd_dev_pno_stop_for_ssid(struct net_device *dev)
5723 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
5725 return (dhd_pno_stop_for_ssid(&dhd->pub));
5727 /* Linux wrapper to call common dhd_pno_set_for_ssid */
5729 dhd_dev_pno_set_for_ssid(struct net_device *dev, wlc_ssid_t* ssids_local, int nssid,
5730 uint16 scan_fr, int pno_repeat, int pno_freq_expo_max, uint16 *channel_list, int nchan)
5732 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
5734 return (dhd_pno_set_for_ssid(&dhd->pub, ssids_local, nssid, scan_fr,
5735 pno_repeat, pno_freq_expo_max, channel_list, nchan));
5738 /* Linux wrapper to call common dhd_pno_enable */
5740 dhd_dev_pno_enable(struct net_device *dev, int enable)
5742 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
5744 return (dhd_pno_enable(&dhd->pub, enable));
5747 /* Linux wrapper to call common dhd_pno_set_for_hotlist */
5749 dhd_dev_pno_set_for_hotlist(struct net_device *dev, wl_pfn_bssid_t *p_pfn_bssid,
5750 struct dhd_pno_hotlist_params *hotlist_params)
5752 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
5753 return (dhd_pno_set_for_hotlist(&dhd->pub, p_pfn_bssid, hotlist_params));
5755 /* Linux wrapper to call common dhd_dev_pno_stop_for_batch */
5757 dhd_dev_pno_stop_for_batch(struct net_device *dev)
5759 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
5760 return (dhd_pno_stop_for_batch(&dhd->pub));
5762 /* Linux wrapper to call common dhd_dev_pno_set_for_batch */
5764 dhd_dev_pno_set_for_batch(struct net_device *dev, struct dhd_pno_batch_params *batch_params)
5766 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
5767 return (dhd_pno_set_for_batch(&dhd->pub, batch_params));
5769 /* Linux wrapper to call common dhd_dev_pno_get_for_batch */
5771 dhd_dev_pno_get_for_batch(struct net_device *dev, char *buf, int bufsize)
5773 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
5774 return (dhd_pno_get_for_batch(&dhd->pub, buf, bufsize, PNO_STATUS_NORMAL));
5776 #endif /* PNO_SUPPORT */
5778 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)) && (1)
5779 static void dhd_hang_process(struct work_struct *work)
5782 struct net_device *dev;
5784 dhd = (dhd_info_t *)container_of(work, dhd_info_t, work_hang);
5785 dev = dhd->iflist[0]->net;
5791 #if defined(WL_WIRELESS_EXT)
5792 wl_iw_send_priv_event(dev, "HANG");
5794 #if defined(WL_CFG80211)
5795 wl_cfg80211_hang(dev, WLAN_REASON_UNSPECIFIED);
5800 int dhd_os_send_hang_message(dhd_pub_t *dhdp)
5804 if (!dhdp->hang_was_sent) {
5805 dhdp->hang_was_sent = 1;
5806 schedule_work(&dhdp->info->work_hang);
5812 int net_os_send_hang_message(struct net_device *dev)
5814 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
5818 /* Report FW problem when enabled */
5819 if (dhd->pub.hang_report) {
5820 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
5821 ret = dhd_os_send_hang_message(&dhd->pub);
5823 ret = wl_cfg80211_hang(dev, WLAN_REASON_UNSPECIFIED);
5826 DHD_ERROR(("%s: FW HANG ignored (for testing purpose) and not sent up\n",
5828 /* Enforce bus down to stop any future traffic */
5829 dhd->pub.busstate = DHD_BUS_DOWN;
5834 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27) && OEM_ANDROID */
5836 void dhd_bus_country_set(struct net_device *dev, wl_country_t *cspec, bool notify)
5838 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
5839 if (dhd && dhd->pub.up) {
5840 memcpy(&dhd->pub.dhd_cspec, cspec, sizeof(wl_country_t));
5842 wl_update_wiphybands(NULL, notify);
5847 void dhd_bus_band_set(struct net_device *dev, uint band)
5849 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
5850 if (dhd && dhd->pub.up) {
5852 wl_update_wiphybands(NULL, true);
5857 void dhd_net_if_lock(struct net_device *dev)
5859 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
5860 dhd_net_if_lock_local(dhd);
5863 void dhd_net_if_unlock(struct net_device *dev)
5865 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
5866 dhd_net_if_unlock_local(dhd);
5869 static void dhd_net_if_lock_local(dhd_info_t *dhd)
5871 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) && 1
5873 mutex_lock(&dhd->dhd_net_if_mutex);
5877 static void dhd_net_if_unlock_local(dhd_info_t *dhd)
5879 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) && 1
5881 mutex_unlock(&dhd->dhd_net_if_mutex);
5885 static void dhd_suspend_lock(dhd_pub_t *pub)
5887 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) && 1
5888 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
5890 mutex_lock(&dhd->dhd_suspend_mutex);
5894 static void dhd_suspend_unlock(dhd_pub_t *pub)
5896 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)) && 1
5897 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
5899 mutex_unlock(&dhd->dhd_suspend_mutex);
5903 unsigned long dhd_os_spin_lock(dhd_pub_t *pub)
5905 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
5906 unsigned long flags = 0;
5909 spin_lock_irqsave(&dhd->dhd_lock, flags);
5914 void dhd_os_spin_unlock(dhd_pub_t *pub, unsigned long flags)
5916 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
5919 spin_unlock_irqrestore(&dhd->dhd_lock, flags);
5923 dhd_get_pend_8021x_cnt(dhd_info_t *dhd)
5925 return (atomic_read(&dhd->pend_8021x_cnt));
5928 #define MAX_WAIT_FOR_8021X_TX 50
5931 dhd_wait_pend8021x(struct net_device *dev)
5933 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
5934 int timeout = msecs_to_jiffies(10);
5935 int ntimes = MAX_WAIT_FOR_8021X_TX;
5936 int pend = dhd_get_pend_8021x_cnt(dhd);
5938 while (ntimes && pend) {
5940 set_current_state(TASK_INTERRUPTIBLE);
5941 schedule_timeout(timeout);
5942 set_current_state(TASK_RUNNING);
5945 pend = dhd_get_pend_8021x_cnt(dhd);
5949 atomic_set(&dhd->pend_8021x_cnt, 0);
5950 DHD_ERROR(("%s: TIMEOUT\n", __FUNCTION__));
5957 write_to_file(dhd_pub_t *dhd, uint8 *buf, int size)
5961 mm_segment_t old_fs;
5964 /* change to KERNEL_DS address limit */
5968 /* open file to write */
5969 fp = filp_open("/tmp/mem_dump", O_WRONLY|O_CREAT, 0640);
5971 printf("%s: open file error\n", __FUNCTION__);
5976 /* Write buf to file */
5977 fp->f_op->write(fp, buf, size, &pos);
5980 /* free buf before return */
5981 MFREE(dhd->osh, buf, size);
5982 /* close file before return */
5984 filp_close(fp, current->files);
5985 /* restore previous address limit */
5990 #endif /* DHD_DEBUG */
5992 int dhd_os_wake_lock_timeout(dhd_pub_t *pub)
5994 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
5995 unsigned long flags;
5999 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
6000 ret = dhd->wakelock_rx_timeout_enable > dhd->wakelock_ctrl_timeout_enable ?
6001 dhd->wakelock_rx_timeout_enable : dhd->wakelock_ctrl_timeout_enable;
6002 #ifdef CONFIG_HAS_WAKELOCK
6003 if (dhd->wakelock_rx_timeout_enable)
6004 wake_lock_timeout(&dhd->wl_rxwake,
6005 msecs_to_jiffies(dhd->wakelock_rx_timeout_enable));
6006 if (dhd->wakelock_ctrl_timeout_enable)
6007 wake_lock_timeout(&dhd->wl_ctrlwake,
6008 msecs_to_jiffies(dhd->wakelock_ctrl_timeout_enable));
6010 dhd->wakelock_rx_timeout_enable = 0;
6011 dhd->wakelock_ctrl_timeout_enable = 0;
6012 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
6017 int net_os_wake_lock_timeout(struct net_device *dev)
6019 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
6023 ret = dhd_os_wake_lock_timeout(&dhd->pub);
6027 int dhd_os_wake_lock_rx_timeout_enable(dhd_pub_t *pub, int val)
6029 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
6030 unsigned long flags;
6033 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
6034 if (val > dhd->wakelock_rx_timeout_enable)
6035 dhd->wakelock_rx_timeout_enable = val;
6036 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
6041 int dhd_os_wake_lock_ctrl_timeout_enable(dhd_pub_t *pub, int val)
6043 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
6044 unsigned long flags;
6047 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
6048 if (val > dhd->wakelock_ctrl_timeout_enable)
6049 dhd->wakelock_ctrl_timeout_enable = val;
6050 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
6055 int net_os_wake_lock_rx_timeout_enable(struct net_device *dev, int val)
6057 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
6061 ret = dhd_os_wake_lock_rx_timeout_enable(&dhd->pub, val);
6065 int net_os_wake_lock_ctrl_timeout_enable(struct net_device *dev, int val)
6067 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
6071 ret = dhd_os_wake_lock_ctrl_timeout_enable(&dhd->pub, val);
6075 int dhd_os_wake_lock(dhd_pub_t *pub)
6077 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
6078 unsigned long flags;
6082 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
6083 #ifdef CONFIG_HAS_WAKELOCK
6084 if (!dhd->wakelock_counter)
6085 wake_lock(&dhd->wl_wifi);
6087 dhd->wakelock_counter++;
6088 ret = dhd->wakelock_counter;
6089 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
6094 int net_os_wake_lock(struct net_device *dev)
6096 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
6100 ret = dhd_os_wake_lock(&dhd->pub);
6104 int dhd_os_wake_unlock(dhd_pub_t *pub)
6106 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
6107 unsigned long flags;
6110 dhd_os_wake_lock_timeout(pub);
6112 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
6113 if (dhd->wakelock_counter) {
6114 dhd->wakelock_counter--;
6115 #ifdef CONFIG_HAS_WAKELOCK
6116 if (!dhd->wakelock_counter)
6117 wake_unlock(&dhd->wl_wifi);
6119 ret = dhd->wakelock_counter;
6121 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
6126 int dhd_os_check_wakelock(void *dhdp)
6128 #if defined(CONFIG_HAS_WAKELOCK) || (1 && (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, \
6130 dhd_pub_t *pub = (dhd_pub_t *)dhdp;
6135 dhd = (dhd_info_t *)(pub->info);
6136 #endif /* CONFIG_HAS_WAKELOCK || BCMSDIO */
6138 #ifdef CONFIG_HAS_WAKELOCK
6139 /* Indicate to the SD Host to avoid going to suspend if internal locks are up */
6140 if (dhd && (wake_lock_active(&dhd->wl_wifi) ||
6141 (wake_lock_active(&dhd->wl_wdwake))))
6147 int net_os_wake_unlock(struct net_device *dev)
6149 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
6153 ret = dhd_os_wake_unlock(&dhd->pub);
6157 int dhd_os_wd_wake_lock(dhd_pub_t *pub)
6159 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
6160 unsigned long flags;
6164 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
6165 #ifdef CONFIG_HAS_WAKELOCK
6166 /* if wakelock_wd_counter was never used : lock it at once */
6167 if (!dhd->wakelock_wd_counter)
6168 wake_lock(&dhd->wl_wdwake);
6170 dhd->wakelock_wd_counter++;
6171 ret = dhd->wakelock_wd_counter;
6172 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
6177 int dhd_os_wd_wake_unlock(dhd_pub_t *pub)
6179 dhd_info_t *dhd = (dhd_info_t *)(pub->info);
6180 unsigned long flags;
6184 spin_lock_irqsave(&dhd->wakelock_spinlock, flags);
6185 if (dhd->wakelock_wd_counter) {
6186 dhd->wakelock_wd_counter = 0;
6187 #ifdef CONFIG_HAS_WAKELOCK
6188 wake_unlock(&dhd->wl_wdwake);
6191 spin_unlock_irqrestore(&dhd->wakelock_spinlock, flags);
6196 int dhd_os_check_if_up(void *dhdp)
6198 dhd_pub_t *pub = (dhd_pub_t *)dhdp;
6205 /* function to collect firmware, chip id and chip version info */
6206 void dhd_set_version_info(dhd_pub_t *dhdp, char *fw)
6210 i = snprintf(info_string, sizeof(info_string),
6211 " Driver: %s\n Firmware: %s ", EPI_VERSION_STR, fw);
6212 printf("%s\n", info_string);
6217 i = snprintf(&info_string[i], sizeof(info_string) - i,
6218 "\n Chip: %x Rev %x Pkg %x", dhd_bus_chip_id(dhdp),
6219 dhd_bus_chiprev_id(dhdp), dhd_bus_chippkg_id(dhdp));
6222 int dhd_ioctl_entry_local(struct net_device *net, wl_ioctl_t *ioc, int cmd)
6226 dhd_info_t *dhd = NULL;
6228 if (!net || !netdev_priv(net)) {
6229 DHD_ERROR(("%s invalid parameter\n", __FUNCTION__));
6233 dhd = *(dhd_info_t **)netdev_priv(net);
6237 ifidx = dhd_net2idx(dhd, net);
6238 if (ifidx == DHD_BAD_IF) {
6239 DHD_ERROR(("%s bad ifidx\n", __FUNCTION__));
6243 DHD_OS_WAKE_LOCK(&dhd->pub);
6244 ret = dhd_wl_ioctl(&dhd->pub, ifidx, ioc, ioc->buf, ioc->len);
6245 dhd_check_hang(net, &dhd->pub, ret);
6246 DHD_OS_WAKE_UNLOCK(&dhd->pub);
6251 bool dhd_os_check_hang(dhd_pub_t *dhdp, int ifidx, int ret)
6253 struct net_device *net;
6255 net = dhd_idx2net(dhdp, ifidx);
6256 return dhd_check_hang(net, dhdp, ret);
6260 #ifdef PROP_TXSTATUS
6261 extern int dhd_wlfc_interface_entry_update(void* state, ewlfc_mac_entry_action_t action, uint8 ifid,
6262 uint8 iftype, uint8* ea);
6263 extern int dhd_wlfc_FIFOcreditmap_update(void* state, uint8* credits);
6265 int dhd_wlfc_interface_event(struct dhd_info *dhd,
6266 ewlfc_mac_entry_action_t action, uint8 ifid, uint8 iftype, uint8* ea)
6268 if (dhd->pub.wlfc_state == NULL)
6271 return dhd_wlfc_interface_entry_update(dhd->pub.wlfc_state, action, ifid, iftype, ea);
6274 int dhd_wlfc_FIFOcreditmap_event(struct dhd_info *dhd, uint8* event_data)
6276 if (dhd->pub.wlfc_state == NULL)
6279 return dhd_wlfc_FIFOcreditmap_update(dhd->pub.wlfc_state, event_data);
6282 int dhd_wlfc_event(struct dhd_info *dhd)
6284 return dhd_wlfc_enable(&dhd->pub);
6287 void dhd_wlfc_plat_enable(void *dhd)
6292 void dhd_wlfc_plat_deinit(void *dhd)
6297 bool dhd_wlfc_skip_fc(void)
6301 extern struct wl_priv *wlcfg_drv_priv;
6303 /* enable flow control in vsdb mode */
6304 return !(wlcfg_drv_priv && wlcfg_drv_priv->vsdb_mode);
6306 return TRUE; /* skip flow control */
6307 #endif /* WL_CFG80211 */
6309 #endif /* PROP_TXSTATUS */
6313 #include <linux/debugfs.h>
6315 extern uint32 dhd_readregl(void *bp, uint32 addr);
6316 extern uint32 dhd_writeregl(void *bp, uint32 addr, uint32 data);
6318 typedef struct dhd_dbgfs {
6319 struct dentry *debugfs_dir;
6320 struct dentry *debugfs_mem;
6325 dhd_dbgfs_t g_dbgfs;
6328 dhd_dbg_state_open(struct inode *inode, struct file *file)
6330 file->private_data = inode->i_private;
6335 dhd_dbg_state_read(struct file *file, char __user *ubuf,
6336 size_t count, loff_t *ppos)
6345 if (pos >= g_dbgfs.size || !count)
6347 if (count > g_dbgfs.size - pos)
6348 count = g_dbgfs.size - pos;
6350 /* Basically enforce aligned 4 byte reads. It's up to the user to work out the details */
6351 tmp = dhd_readregl(g_dbgfs.dhdp->bus, file->f_pos & (~3));
6353 ret = copy_to_user(ubuf, &tmp, 4);
6358 *ppos = pos + count;
6366 dhd_debugfs_write(struct file *file, const char __user *ubuf, size_t count, loff_t *ppos)
6374 if (pos >= g_dbgfs.size || !count)
6376 if (count > g_dbgfs.size - pos)
6377 count = g_dbgfs.size - pos;
6379 ret = copy_from_user(&buf, ubuf, sizeof(uint32));
6383 /* Basically enforce aligned 4 byte writes. It's up to the user to work out the details */
6384 dhd_writeregl(g_dbgfs.dhdp->bus, file->f_pos & (~3), buf);
6391 dhd_debugfs_lseek(struct file *file, loff_t off, int whence)
6400 pos = file->f_pos + off;
6403 pos = g_dbgfs.size - off;
6405 return (pos < 0 || pos > g_dbgfs.size) ? -EINVAL : (file->f_pos = pos);
6408 static const struct file_operations dhd_dbg_state_ops = {
6409 .read = dhd_dbg_state_read,
6410 .write = dhd_debugfs_write,
6411 .open = dhd_dbg_state_open,
6412 .llseek = dhd_debugfs_lseek
6415 static void dhd_dbg_create(void)
6417 if (g_dbgfs.debugfs_dir) {
6418 g_dbgfs.debugfs_mem = debugfs_create_file("mem", 0644, g_dbgfs.debugfs_dir,
6419 NULL, &dhd_dbg_state_ops);
6423 void dhd_dbg_init(dhd_pub_t *dhdp)
6427 g_dbgfs.dhdp = dhdp;
6428 g_dbgfs.size = 0x20000000; /* Allow access to various cores regs */
6430 g_dbgfs.debugfs_dir = debugfs_create_dir("dhd", 0);
6431 if (IS_ERR(g_dbgfs.debugfs_dir)) {
6432 err = PTR_ERR(g_dbgfs.debugfs_dir);
6433 g_dbgfs.debugfs_dir = NULL;
6442 void dhd_dbg_remove(void)
6444 debugfs_remove(g_dbgfs.debugfs_mem);
6445 debugfs_remove(g_dbgfs.debugfs_dir);
6447 bzero((unsigned char *) &g_dbgfs, sizeof(g_dbgfs));
6450 #endif /* ifdef BCMDBGFS */
6455 void dhd_htsf_addtxts(dhd_pub_t *dhdp, void *pktbuf)
6457 dhd_info_t *dhd = (dhd_info_t *)(dhdp->info);
6458 struct sk_buff *skb;
6460 uint16 dport = 0, oldmagic = 0xACAC;
6464 /* timestamp packet */
6466 p1 = (char*) PKTDATA(dhdp->osh, pktbuf);
6468 if (PKTLEN(dhdp->osh, pktbuf) > HTSF_MINLEN) {
6469 /* memcpy(&proto, p1+26, 4); */
6470 memcpy(&dport, p1+40, 2);
6471 /* proto = ((ntoh32(proto))>> 16) & 0xFF; */
6472 dport = ntoh16(dport);
6475 /* timestamp only if icmp or udb iperf with port 5555 */
6476 /* if (proto == 17 && dport == tsport) { */
6477 if (dport >= tsport && dport <= tsport + 20) {
6479 skb = (struct sk_buff *) pktbuf;
6481 htsf = dhd_get_htsf(dhd, 0);
6482 memset(skb->data + 44, 0, 2); /* clear checksum */
6483 memcpy(skb->data+82, &oldmagic, 2);
6484 memcpy(skb->data+84, &htsf, 4);
6486 memset(&ts, 0, sizeof(htsfts_t));
6487 ts.magic = HTSFMAGIC;
6488 ts.prio = PKTPRIO(pktbuf);
6489 ts.seqnum = htsf_seqnum++;
6490 ts.c10 = get_cycles();
6492 ts.endmagic = HTSFENDMAGIC;
6494 memcpy(skb->data + HTSF_HOSTOFFSET, &ts, sizeof(ts));
6498 static void dhd_dump_htsfhisto(histo_t *his, char *s)
6500 int pktcnt = 0, curval = 0, i;
6501 for (i = 0; i < (NUMBIN-2); i++) {
6503 printf("%d ", his->bin[i]);
6504 pktcnt += his->bin[i];
6506 printf(" max: %d TotPkt: %d neg: %d [%s]\n", his->bin[NUMBIN-2], pktcnt,
6507 his->bin[NUMBIN-1], s);
6511 void sorttobin(int value, histo_t *histo)
6516 histo->bin[NUMBIN-1]++;
6519 if (value > histo->bin[NUMBIN-2]) /* store the max value */
6520 histo->bin[NUMBIN-2] = value;
6522 for (i = 0; i < (NUMBIN-2); i++) {
6523 binval += 500; /* 500m s bins */
6524 if (value <= binval) {
6529 histo->bin[NUMBIN-3]++;
6533 void dhd_htsf_addrxts(dhd_pub_t *dhdp, void *pktbuf)
6535 dhd_info_t *dhd = (dhd_info_t *)dhdp->info;
6536 struct sk_buff *skb;
6539 int d1, d2, d3, end2end;
6543 skb = PKTTONATIVE(dhdp->osh, pktbuf);
6544 p1 = (char*)PKTDATA(dhdp->osh, pktbuf);
6546 if (PKTLEN(osh, pktbuf) > HTSF_MINLEN) {
6547 memcpy(&old_magic, p1+78, 2);
6548 htsf_ts = (htsfts_t*) (p1 + HTSF_HOSTOFFSET - 4);
6553 if (htsf_ts->magic == HTSFMAGIC) {
6554 htsf_ts->tE0 = dhd_get_htsf(dhd, 0);
6555 htsf_ts->cE0 = get_cycles();
6558 if (old_magic == 0xACAC) {
6561 htsf = dhd_get_htsf(dhd, 0);
6562 memcpy(skb->data+92, &htsf, sizeof(uint32));
6564 memcpy(&ts[tsidx].t1, skb->data+80, 16);
6566 d1 = ts[tsidx].t2 - ts[tsidx].t1;
6567 d2 = ts[tsidx].t3 - ts[tsidx].t2;
6568 d3 = ts[tsidx].t4 - ts[tsidx].t3;
6569 end2end = ts[tsidx].t4 - ts[tsidx].t1;
6571 sorttobin(d1, &vi_d1);
6572 sorttobin(d2, &vi_d2);
6573 sorttobin(d3, &vi_d3);
6574 sorttobin(end2end, &vi_d4);
6576 if (end2end > 0 && end2end > maxdelay) {
6578 maxdelaypktno = tspktcnt;
6579 memcpy(&maxdelayts, &ts[tsidx], 16);
6581 if (++tsidx >= TSMAX)
6586 uint32 dhd_get_htsf(dhd_info_t *dhd, int ifidx)
6588 uint32 htsf = 0, cur_cycle, delta, delta_us;
6589 uint32 factor, baseval, baseval2;
6595 if (cur_cycle > dhd->htsf.last_cycle)
6596 delta = cur_cycle - dhd->htsf.last_cycle;
6598 delta = cur_cycle + (0xFFFFFFFF - dhd->htsf.last_cycle);
6603 if (dhd->htsf.coef) {
6604 /* times ten to get the first digit */
6605 factor = (dhd->htsf.coef*10 + dhd->htsf.coefdec1);
6606 baseval = (delta*10)/factor;
6607 baseval2 = (delta*10)/(factor+1);
6608 delta_us = (baseval - (((baseval - baseval2) * dhd->htsf.coefdec2)) / 10);
6609 htsf = (delta_us << 4) + dhd->htsf.last_tsf + HTSF_BUS_DELAY;
6612 DHD_ERROR(("-------dhd->htsf.coef = 0 -------\n"));
6618 static void dhd_dump_latency(void)
6621 int d1, d2, d3, d4, d5;
6623 printf("T1 T2 T3 T4 d1 d2 t4-t1 i \n");
6624 for (i = 0; i < TSMAX; i++) {
6625 d1 = ts[i].t2 - ts[i].t1;
6626 d2 = ts[i].t3 - ts[i].t2;
6627 d3 = ts[i].t4 - ts[i].t3;
6628 d4 = ts[i].t4 - ts[i].t1;
6629 d5 = ts[max].t4-ts[max].t1;
6630 if (d4 > d5 && d4 > 0) {
6633 printf("%08X %08X %08X %08X \t%d %d %d %d i=%d\n",
6634 ts[i].t1, ts[i].t2, ts[i].t3, ts[i].t4,
6638 printf("current idx = %d \n", tsidx);
6640 printf("Highest latency %d pkt no.%d total=%d\n", maxdelay, maxdelaypktno, tspktcnt);
6641 printf("%08X %08X %08X %08X \t%d %d %d %d\n",
6642 maxdelayts.t1, maxdelayts.t2, maxdelayts.t3, maxdelayts.t4,
6643 maxdelayts.t2 - maxdelayts.t1,
6644 maxdelayts.t3 - maxdelayts.t2,
6645 maxdelayts.t4 - maxdelayts.t3,
6646 maxdelayts.t4 - maxdelayts.t1);
6651 dhd_ioctl_htsf_get(dhd_info_t *dhd, int ifidx)
6663 memset(&ioc, 0, sizeof(ioc));
6664 memset(&tsf_buf, 0, sizeof(tsf_buf));
6666 ioc.cmd = WLC_GET_VAR;
6668 ioc.len = (uint)sizeof(buf);
6671 strncpy(buf, "tsf", sizeof(buf) - 1);
6672 buf[sizeof(buf) - 1] = '\0';
6673 s1 = dhd_get_htsf(dhd, 0);
6674 if ((ret = dhd_wl_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len)) < 0) {
6676 DHD_ERROR(("%s: tsf is not supported by device\n",
6677 dhd_ifname(&dhd->pub, ifidx)));
6682 s2 = dhd_get_htsf(dhd, 0);
6684 memcpy(&tsf_buf, buf, sizeof(tsf_buf));
6685 printf(" TSF_h=%04X lo=%08X Calc:htsf=%08X, coef=%d.%d%d delta=%d ",
6686 tsf_buf.high, tsf_buf.low, s2, dhd->htsf.coef, dhd->htsf.coefdec1,
6687 dhd->htsf.coefdec2, s2-tsf_buf.low);
6688 printf("lasttsf=%08X lastcycle=%08X\n", dhd->htsf.last_tsf, dhd->htsf.last_cycle);
6692 void htsf_update(dhd_info_t *dhd, void *data)
6694 static ulong cur_cycle = 0, prev_cycle = 0;
6695 uint32 htsf, tsf_delta = 0;
6696 uint32 hfactor = 0, cyc_delta, dec1 = 0, dec2, dec3, tmp;
6700 /* cycles_t in inlcude/mips/timex.h */
6704 prev_cycle = cur_cycle;
6707 if (cur_cycle > prev_cycle)
6708 cyc_delta = cur_cycle - prev_cycle;
6712 cyc_delta = cur_cycle + (0xFFFFFFFF - prev_cycle);
6716 printf(" tsf update ata point er is null \n");
6718 memcpy(&prev_tsf, &cur_tsf, sizeof(tsf_t));
6719 memcpy(&cur_tsf, data, sizeof(tsf_t));
6721 if (cur_tsf.low == 0) {
6722 DHD_INFO((" ---- 0 TSF, do not update, return\n"));
6726 if (cur_tsf.low > prev_tsf.low)
6727 tsf_delta = (cur_tsf.low - prev_tsf.low);
6729 DHD_INFO((" ---- tsf low is smaller cur_tsf= %08X, prev_tsf=%08X, \n",
6730 cur_tsf.low, prev_tsf.low));
6731 if (cur_tsf.high > prev_tsf.high) {
6732 tsf_delta = cur_tsf.low + (0xFFFFFFFF - prev_tsf.low);
6733 DHD_INFO((" ---- Wrap around tsf coutner adjusted TSF=%08X\n", tsf_delta));
6736 return; /* do not update */
6740 hfactor = cyc_delta / tsf_delta;
6741 tmp = (cyc_delta - (hfactor * tsf_delta))*10;
6742 dec1 = tmp/tsf_delta;
6743 dec2 = ((tmp - dec1*tsf_delta)*10) / tsf_delta;
6744 tmp = (tmp - (dec1*tsf_delta))*10;
6745 dec3 = ((tmp - dec2*tsf_delta)*10) / tsf_delta;
6764 htsf = ((cyc_delta * 10) / (hfactor*10+dec1)) + prev_tsf.low;
6765 dhd->htsf.coef = hfactor;
6766 dhd->htsf.last_cycle = cur_cycle;
6767 dhd->htsf.last_tsf = cur_tsf.low;
6768 dhd->htsf.coefdec1 = dec1;
6769 dhd->htsf.coefdec2 = dec2;
6772 htsf = prev_tsf.low;
6776 #endif /* WLMEDIA_HTSF */