2 * Copyright (c) 2010 Broadcom Corporation
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #ifdef CONFIG_WIFI_CONTROL_FUNC
18 #include <linux/platform_device.h>
20 #include <linux/init.h>
21 #include <linux/kernel.h>
22 #include <linux/kthread.h>
23 #include <linux/slab.h>
24 #include <linux/skbuff.h>
25 #include <linux/netdevice.h>
26 #include <linux/etherdevice.h>
27 #include <linux/mmc/sdio_func.h>
28 #include <linux/random.h>
29 #include <linux/spinlock.h>
30 #include <linux/ethtool.h>
31 #include <linux/fcntl.h>
33 #include <linux/uaccess.h>
37 #include <dngl_stats.h>
40 #include <dhd_proto.h>
43 #include <wl_cfg80211.h>
45 #define EPI_VERSION_STR "4.218.248.5"
46 #define ETH_P_BRCM 0x886c
48 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
49 #include <linux/wifi_tiwlan.h>
51 struct semaphore wifi_control_sem
;
53 struct dhd_bus
*g_bus
;
55 static struct wifi_platform_data
*wifi_control_data
;
56 static struct resource
*wifi_irqres
;
58 int wifi_get_irq_number(unsigned long *irq_flags_ptr
)
61 *irq_flags_ptr
= wifi_irqres
->flags
& IRQF_TRIGGER_MASK
;
62 return (int)wifi_irqres
->start
;
64 #ifdef CUSTOM_OOB_GPIO_NUM
65 return CUSTOM_OOB_GPIO_NUM
;
71 int wifi_set_carddetect(int on
)
73 printk(KERN_ERR
"%s = %d\n", __func__
, on
);
74 if (wifi_control_data
&& wifi_control_data
->set_carddetect
)
75 wifi_control_data
->set_carddetect(on
);
79 int wifi_set_power(int on
, unsigned long msec
)
81 printk(KERN_ERR
"%s = %d\n", __func__
, on
);
82 if (wifi_control_data
&& wifi_control_data
->set_power
)
83 wifi_control_data
->set_power(on
);
89 int wifi_set_reset(int on
, unsigned long msec
)
91 printk(KERN_ERR
"%s = %d\n", __func__
, on
);
92 if (wifi_control_data
&& wifi_control_data
->set_reset
)
93 wifi_control_data
->set_reset(on
);
99 static int wifi_probe(struct platform_device
*pdev
)
101 struct wifi_platform_data
*wifi_ctrl
=
102 (struct wifi_platform_data
*)(pdev
->dev
.platform_data
);
104 printk(KERN_ERR
"## %s\n", __func__
);
106 platform_get_resource_byname(pdev
, IORESOURCE_IRQ
,
108 wifi_control_data
= wifi_ctrl
;
110 wifi_set_power(1, 0); /* Power On */
111 wifi_set_carddetect(1); /* CardDetect (0->1) */
113 up(&wifi_control_sem
);
117 static int wifi_remove(struct platform_device
*pdev
)
119 struct wifi_platform_data
*wifi_ctrl
=
120 (struct wifi_platform_data
*)(pdev
->dev
.platform_data
);
122 printk(KERN_ERR
"## %s\n", __func__
);
123 wifi_control_data
= wifi_ctrl
;
125 wifi_set_carddetect(0); /* CardDetect (1->0) */
126 wifi_set_power(0, 0); /* Power Off */
128 up(&wifi_control_sem
);
132 static int wifi_suspend(struct platform_device
*pdev
, pm_message_t state
)
134 DHD_TRACE(("##> %s\n", __func__
));
138 static int wifi_resume(struct platform_device
*pdev
)
140 DHD_TRACE(("##> %s\n", __func__
));
144 static struct platform_driver wifi_device
= {
146 .remove
= wifi_remove
,
147 .suspend
= wifi_suspend
,
148 .resume
= wifi_resume
,
150 .name
= KBUILD_MODNAME
,
154 int wifi_add_dev(void)
156 DHD_TRACE(("## Calling platform_driver_register\n"));
157 return platform_driver_register(&wifi_device
);
160 void wifi_del_dev(void)
162 DHD_TRACE(("## Unregister platform_driver_register\n"));
163 platform_driver_unregister(&wifi_device
);
165 #endif /* defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
167 #if defined(CONFIG_PM_SLEEP)
168 #include <linux/suspend.h>
169 atomic_t dhd_mmc_suspend
;
170 DECLARE_WAIT_QUEUE_HEAD(dhd_dpc_wait
);
171 #endif /* defined(CONFIG_PM_SLEEP) */
173 #if defined(OOB_INTR_ONLY)
174 extern void dhd_enable_oob_intr(struct dhd_bus
*bus
, bool enable
);
175 #endif /* defined(OOB_INTR_ONLY) */
177 MODULE_AUTHOR("Broadcom Corporation");
178 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN fullmac driver.");
179 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN fullmac cards");
180 MODULE_LICENSE("Dual BSD/GPL");
182 #define DRV_MODULE_NAME "brcmfmac"
184 /* Linux wireless extension support */
185 #if defined(CONFIG_WIRELESS_EXT)
187 extern wl_iw_extra_params_t g_wl_iw_params
;
188 #endif /* defined(CONFIG_WIRELESS_EXT) */
190 #if defined(CONFIG_HAS_EARLYSUSPEND)
191 #include <linux/earlysuspend.h>
192 extern int dhdcdc_set_ioctl(dhd_pub_t
*dhd
, int ifidx
, uint cmd
, void *buf
,
194 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
196 #ifdef PKT_FILTER_SUPPORT
197 extern void dhd_pktfilter_offload_set(dhd_pub_t
*dhd
, char *arg
);
198 extern void dhd_pktfilter_offload_enable(dhd_pub_t
*dhd
, char *arg
, int enable
,
202 /* Interface control information */
203 typedef struct dhd_if
{
204 struct dhd_info
*info
; /* back pointer to dhd_info */
205 /* OS/stack specifics */
206 struct net_device
*net
;
207 struct net_device_stats stats
;
208 int idx
; /* iface idx in dongle */
209 int state
; /* interface state */
210 uint subunit
; /* subunit */
211 u8 mac_addr
[ETH_ALEN
]; /* assigned MAC address */
212 bool attached
; /* Delayed attachment when unset */
213 bool txflowcontrol
; /* Per interface flow control indicator */
214 char name
[IFNAMSIZ
]; /* linux interface name */
217 /* Local private structure (extension of pub) */
218 typedef struct dhd_info
{
219 #if defined(CONFIG_WIRELESS_EXT)
220 wl_iw_t iw
; /* wireless extensions state (must be first) */
221 #endif /* defined(CONFIG_WIRELESS_EXT) */
225 /* OS/stack specifics */
226 dhd_if_t
*iflist
[DHD_MAX_IFS
];
228 struct semaphore proto_sem
;
229 wait_queue_head_t ioctl_resp_wait
;
230 struct timer_list timer
;
232 struct tasklet_struct tasklet
;
235 /* Thread based operation */
237 struct semaphore sdsem
;
238 struct task_struct
*watchdog_tsk
;
239 struct semaphore watchdog_sem
;
240 struct task_struct
*dpc_tsk
;
241 struct semaphore dpc_sem
;
243 /* Thread to issue ioctl for multicast */
244 struct task_struct
*sysioc_tsk
;
245 struct semaphore sysioc_sem
;
248 u8 macvalue
[ETH_ALEN
];
249 wait_queue_head_t ctrl_wait
;
250 atomic_t pend_8021x_cnt
;
252 #ifdef CONFIG_HAS_EARLYSUSPEND
253 struct early_suspend early_suspend
;
254 #endif /* CONFIG_HAS_EARLYSUSPEND */
257 /* Definitions to provide path to the firmware and nvram
258 * example nvram_path[MOD_PARAM_PATHLEN]="/projects/wlan/nvram.txt"
260 char firmware_path
[MOD_PARAM_PATHLEN
];
261 char nvram_path
[MOD_PARAM_PATHLEN
];
263 /* load firmware and/or nvram values from the filesystem */
264 module_param_string(firmware_path
, firmware_path
, MOD_PARAM_PATHLEN
, 0);
265 module_param_string(nvram_path
, nvram_path
, MOD_PARAM_PATHLEN
, 0);
268 module_param(dhd_msg_level
, int, 0);
270 /* Spawn a thread for system ioctls (set mac, set mcast) */
271 uint dhd_sysioc
= true;
272 module_param(dhd_sysioc
, uint
, 0);
274 /* Watchdog interval */
275 uint dhd_watchdog_ms
= 10;
276 module_param(dhd_watchdog_ms
, uint
, 0);
279 /* Console poll interval */
281 module_param(dhd_console_ms
, uint
, 0);
282 #endif /* DHD_DEBUG */
284 /* ARP offload agent mode : Enable ARP Host Auto-Reply
285 and ARP Peer Auto-Reply */
286 uint dhd_arp_mode
= 0xb;
287 module_param(dhd_arp_mode
, uint
, 0);
289 /* ARP offload enable */
290 uint dhd_arp_enable
= true;
291 module_param(dhd_arp_enable
, uint
, 0);
293 /* Global Pkt filter enable control */
294 uint dhd_pkt_filter_enable
= true;
295 module_param(dhd_pkt_filter_enable
, uint
, 0);
297 /* Pkt filter init setup */
298 uint dhd_pkt_filter_init
;
299 module_param(dhd_pkt_filter_init
, uint
, 0);
301 /* Pkt filter mode control */
302 uint dhd_master_mode
= true;
303 module_param(dhd_master_mode
, uint
, 1);
305 /* Watchdog thread priority, -1 to use kernel timer */
306 int dhd_watchdog_prio
= 97;
307 module_param(dhd_watchdog_prio
, int, 0);
309 /* DPC thread priority, -1 to use tasklet */
310 int dhd_dpc_prio
= 98;
311 module_param(dhd_dpc_prio
, int, 0);
313 /* DPC thread priority, -1 to use tasklet */
314 extern int dhd_dongle_memsize
;
315 module_param(dhd_dongle_memsize
, int, 0);
317 /* Contorl fw roaming */
324 /* Control radio state */
325 uint dhd_radio_up
= 1;
327 /* Network inteface name */
328 char iface_name
[IFNAMSIZ
] = "wlan";
329 module_param_string(iface_name
, iface_name
, IFNAMSIZ
, 0);
331 /* The following are specific to the SDIO dongle */
333 /* IOCTL response timeout */
334 int dhd_ioctl_timeout_msec
= IOCTL_RESP_TIMEOUT
;
336 /* Idle timeout for backplane clock */
337 int dhd_idletime
= DHD_IDLETIME_TICKS
;
338 module_param(dhd_idletime
, int, 0);
341 uint dhd_poll
= false;
342 module_param(dhd_poll
, uint
, 0);
345 uint dhd_cfg80211
= true;
346 module_param(dhd_cfg80211
, uint
, 0);
349 uint dhd_intr
= true;
350 module_param(dhd_intr
, uint
, 0);
352 /* SDIO Drive Strength (in milliamps) */
353 uint dhd_sdiod_drive_strength
= 6;
354 module_param(dhd_sdiod_drive_strength
, uint
, 0);
357 extern uint dhd_txbound
;
358 extern uint dhd_rxbound
;
359 module_param(dhd_txbound
, uint
, 0);
360 module_param(dhd_rxbound
, uint
, 0);
362 /* Deferred transmits */
363 extern uint dhd_deferred_tx
;
364 module_param(dhd_deferred_tx
, uint
, 0);
367 /* Echo packet generator (pkts/s) */
369 module_param(dhd_pktgen
, uint
, 0);
371 /* Echo packet len (0 => sawtooth, max 2040) */
373 module_param(dhd_pktgen_len
, uint
, 0);
376 #define FAVORITE_WIFI_CP (!!dhd_cfg80211)
377 #define IS_CFG80211_FAVORITE() FAVORITE_WIFI_CP
378 #define DBG_CFG80211_GET() ((dhd_cfg80211 & WL_DBG_MASK) >> 1)
379 #define NO_FW_REQ() (dhd_cfg80211 & 0x80)
381 /* Version string to report */
383 #define DHD_COMPILED "\nCompiled in " SRCBASE
388 static void dhd_dpc(unsigned long data
);
390 extern int dhd_wait_pend8021x(struct net_device
*dev
);
394 #error TOE requires BDC
396 static int dhd_toe_get(dhd_info_t
*dhd
, int idx
, u32
*toe_ol
);
397 static int dhd_toe_set(dhd_info_t
*dhd
, int idx
, u32 toe_ol
);
400 static int dhd_wl_host_event(dhd_info_t
*dhd
, int *ifidx
, void *pktdata
,
401 wl_event_msg_t
*event_ptr
, void **data_ptr
);
403 #if defined(CONFIG_PM_SLEEP)
404 static int dhd_sleep_pm_callback(struct notifier_block
*nfb
,
405 unsigned long action
, void *ignored
)
408 case PM_HIBERNATION_PREPARE
:
409 case PM_SUSPEND_PREPARE
:
410 atomic_set(&dhd_mmc_suspend
, true);
412 case PM_POST_HIBERNATION
:
413 case PM_POST_SUSPEND
:
414 atomic_set(&dhd_mmc_suspend
, false);
420 static struct notifier_block dhd_sleep_pm_notifier
= {
421 .notifier_call
= dhd_sleep_pm_callback
,
425 extern int register_pm_notifier(struct notifier_block
*nb
);
426 extern int unregister_pm_notifier(struct notifier_block
*nb
);
427 #endif /* defined(CONFIG_PM_SLEEP) */
428 /* && defined(DHD_GPL) */
429 static void dhd_set_packet_filter(int value
, dhd_pub_t
*dhd
)
431 #ifdef PKT_FILTER_SUPPORT
432 DHD_TRACE(("%s: %d\n", __func__
, value
));
433 /* 1 - Enable packet filter, only allow unicast packet to send up */
434 /* 0 - Disable packet filter */
435 if (dhd_pkt_filter_enable
) {
438 for (i
= 0; i
< dhd
->pktfilter_count
; i
++) {
439 dhd_pktfilter_offload_set(dhd
, dhd
->pktfilter
[i
]);
440 dhd_pktfilter_offload_enable(dhd
, dhd
->pktfilter
[i
],
441 value
, dhd_master_mode
);
447 #if defined(CONFIG_HAS_EARLYSUSPEND)
448 static int dhd_set_suspend(int value
, dhd_pub_t
*dhd
)
450 int power_mode
= PM_MAX
;
451 /* wl_pkt_filter_enable_t enable_parm; */
456 #endif /* CUSTOMER_HW2 */
458 DHD_TRACE(("%s: enter, value = %d in_suspend=%d\n",
459 __func__
, value
, dhd
->in_suspend
));
461 if (dhd
&& dhd
->up
) {
462 if (value
&& dhd
->in_suspend
) {
464 /* Kernel suspended */
465 DHD_TRACE(("%s: force extra Suspend setting\n",
468 dhdcdc_set_ioctl(dhd
, 0, WLC_SET_PM
,
472 /* Enable packet filter, only allow unicast
474 dhd_set_packet_filter(1, dhd
);
476 /* if dtim skip setup as default force it
477 * to wake each third dtim
478 * for better power saving.
479 * Note that side effect is chance to miss BC/MC
482 if ((dhd
->dtim_skip
== 0) || (dhd
->dtim_skip
== 1))
485 bcn_li_dtim
= dhd
->dtim_skip
;
486 bcm_mkiovar("bcn_li_dtim", (char *)&bcn_li_dtim
,
487 4, iovbuf
, sizeof(iovbuf
));
488 dhdcdc_set_ioctl(dhd
, 0, WLC_SET_VAR
, iovbuf
,
491 /* Disable build-in roaming to allowed \
492 * supplicant to take of romaing
494 bcm_mkiovar("roam_off", (char *)&roamvar
, 4,
495 iovbuf
, sizeof(iovbuf
));
496 dhdcdc_set_ioctl(dhd
, 0, WLC_SET_VAR
, iovbuf
,
498 #endif /* CUSTOMER_HW2 */
502 DHD_TRACE(("%s: Remove extra suspend setting\n",
505 power_mode
= PM_FAST
;
506 dhdcdc_set_ioctl(dhd
, 0, WLC_SET_PM
,
510 /* disable pkt filter */
511 dhd_set_packet_filter(0, dhd
);
513 /* restore pre-suspend setting for dtim_skip */
514 bcm_mkiovar("bcn_li_dtim", (char *)&dhd
->dtim_skip
,
515 4, iovbuf
, sizeof(iovbuf
));
517 dhdcdc_set_ioctl(dhd
, 0, WLC_SET_VAR
, iovbuf
,
521 bcm_mkiovar("roam_off", (char *)&roamvar
, 4, iovbuf
,
523 dhdcdc_set_ioctl(dhd
, 0, WLC_SET_VAR
, iovbuf
,
525 #endif /* CUSTOMER_HW2 */
532 static void dhd_suspend_resume_helper(struct dhd_info
*dhd
, int val
)
534 dhd_pub_t
*dhdp
= &dhd
->pub
;
536 dhd_os_proto_block(dhdp
);
537 /* Set flag when early suspend was called */
538 dhdp
->in_suspend
= val
;
539 if (!dhdp
->suspend_disable_flag
)
540 dhd_set_suspend(val
, dhdp
);
541 dhd_os_proto_unblock(dhdp
);
544 static void dhd_early_suspend(struct early_suspend
*h
)
546 struct dhd_info
*dhd
= container_of(h
, struct dhd_info
, early_suspend
);
548 DHD_TRACE(("%s: enter\n", __func__
));
551 dhd_suspend_resume_helper(dhd
, 1);
555 static void dhd_late_resume(struct early_suspend
*h
)
557 struct dhd_info
*dhd
= container_of(h
, struct dhd_info
, early_suspend
);
559 DHD_TRACE(("%s: enter\n", __func__
));
562 dhd_suspend_resume_helper(dhd
, 0);
564 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
567 * Generalized timeout mechanism. Uses spin sleep with exponential
569 * the sleep time reaches one jiffy, then switches over to task delay. Usage:
571 * dhd_timeout_start(&tmo, usec);
572 * while (!dhd_timeout_expired(&tmo))
573 * if (poll_something())
575 * if (dhd_timeout_expired(&tmo))
579 void dhd_timeout_start(dhd_timeout_t
*tmo
, uint usec
)
584 tmo
->tick
= 1000000 / HZ
;
587 int dhd_timeout_expired(dhd_timeout_t
*tmo
)
589 /* Does nothing the first call */
590 if (tmo
->increment
== 0) {
595 if (tmo
->elapsed
>= tmo
->limit
)
598 /* Add the delay that's about to take place */
599 tmo
->elapsed
+= tmo
->increment
;
601 if (tmo
->increment
< tmo
->tick
) {
602 udelay(tmo
->increment
);
604 if (tmo
->increment
> tmo
->tick
)
605 tmo
->increment
= tmo
->tick
;
607 wait_queue_head_t delay_wait
;
608 DECLARE_WAITQUEUE(wait
, current
);
610 init_waitqueue_head(&delay_wait
);
611 add_wait_queue(&delay_wait
, &wait
);
612 set_current_state(TASK_INTERRUPTIBLE
);
614 pending
= signal_pending(current
);
615 remove_wait_queue(&delay_wait
, &wait
);
616 set_current_state(TASK_RUNNING
);
618 return 1; /* Interrupted */
624 static int dhd_net2idx(dhd_info_t
*dhd
, struct net_device
*net
)
629 while (i
< DHD_MAX_IFS
) {
630 if (dhd
->iflist
[i
] && (dhd
->iflist
[i
]->net
== net
))
638 int dhd_ifname2idx(dhd_info_t
*dhd
, char *name
)
644 if (name
== NULL
|| *name
== '\0')
649 && !strncmp(dhd
->iflist
[i
]->name
, name
, IFNAMSIZ
))
652 DHD_TRACE(("%s: return idx %d for \"%s\"\n", __func__
, i
, name
));
654 return i
; /* default - the primary interface */
657 char *dhd_ifname(dhd_pub_t
*dhdp
, int ifidx
)
659 dhd_info_t
*dhd
= (dhd_info_t
*) dhdp
->info
;
663 if (ifidx
< 0 || ifidx
>= DHD_MAX_IFS
) {
664 DHD_ERROR(("%s: ifidx %d out of range\n", __func__
, ifidx
));
668 if (dhd
->iflist
[ifidx
] == NULL
) {
669 DHD_ERROR(("%s: null i/f %d\n", __func__
, ifidx
));
673 if (dhd
->iflist
[ifidx
]->net
)
674 return dhd
->iflist
[ifidx
]->net
->name
;
679 static void _dhd_set_multicast_list(dhd_info_t
*dhd
, int ifidx
)
681 struct net_device
*dev
;
682 struct netdev_hw_addr
*ha
;
690 ASSERT(dhd
&& dhd
->iflist
[ifidx
]);
691 dev
= dhd
->iflist
[ifidx
]->net
;
692 cnt
= netdev_mc_count(dev
);
694 /* Determine initial value of allmulti flag */
695 allmulti
= (dev
->flags
& IFF_ALLMULTI
) ? true : false;
697 /* Send down the multicast list first. */
699 buflen
= sizeof("mcast_list") + sizeof(cnt
) + (cnt
* ETH_ALEN
);
700 bufp
= buf
= kmalloc(buflen
, GFP_ATOMIC
);
702 DHD_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
703 dhd_ifname(&dhd
->pub
, ifidx
), cnt
));
707 strcpy(bufp
, "mcast_list");
708 bufp
+= strlen("mcast_list") + 1;
710 cnt
= cpu_to_le32(cnt
);
711 memcpy(bufp
, &cnt
, sizeof(cnt
));
714 netdev_for_each_mc_addr(ha
, dev
) {
717 memcpy(bufp
, ha
->addr
, ETH_ALEN
);
722 memset(&ioc
, 0, sizeof(ioc
));
723 ioc
.cmd
= WLC_SET_VAR
;
728 ret
= dhd_prot_ioctl(&dhd
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
730 DHD_ERROR(("%s: set mcast_list failed, cnt %d\n",
731 dhd_ifname(&dhd
->pub
, ifidx
), cnt
));
732 allmulti
= cnt
? true : allmulti
;
737 /* Now send the allmulti setting. This is based on the setting in the
738 * net_device flags, but might be modified above to be turned on if we
739 * were trying to set some addresses and dongle rejected it...
742 buflen
= sizeof("allmulti") + sizeof(allmulti
);
743 buf
= kmalloc(buflen
, GFP_ATOMIC
);
745 DHD_ERROR(("%s: out of memory for allmulti\n",
746 dhd_ifname(&dhd
->pub
, ifidx
)));
749 allmulti
= cpu_to_le32(allmulti
);
752 ("allmulti", (void *)&allmulti
, sizeof(allmulti
), buf
, buflen
)) {
753 DHD_ERROR(("%s: mkiovar failed for allmulti, datalen %d "
754 "buflen %u\n", dhd_ifname(&dhd
->pub
, ifidx
),
755 (int)sizeof(allmulti
), buflen
));
760 memset(&ioc
, 0, sizeof(ioc
));
761 ioc
.cmd
= WLC_SET_VAR
;
766 ret
= dhd_prot_ioctl(&dhd
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
768 DHD_ERROR(("%s: set allmulti %d failed\n",
769 dhd_ifname(&dhd
->pub
, ifidx
),
770 le32_to_cpu(allmulti
)));
775 /* Finally, pick up the PROMISC flag as well, like the NIC
778 allmulti
= (dev
->flags
& IFF_PROMISC
) ? true : false;
779 allmulti
= cpu_to_le32(allmulti
);
781 memset(&ioc
, 0, sizeof(ioc
));
782 ioc
.cmd
= WLC_SET_PROMISC
;
784 ioc
.len
= sizeof(allmulti
);
787 ret
= dhd_prot_ioctl(&dhd
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
789 DHD_ERROR(("%s: set promisc %d failed\n",
790 dhd_ifname(&dhd
->pub
, ifidx
),
791 le32_to_cpu(allmulti
)));
796 _dhd_set_mac_address(dhd_info_t
*dhd
, int ifidx
, u8
*addr
)
802 DHD_TRACE(("%s enter\n", __func__
));
804 ("cur_etheraddr", (char *)addr
, ETH_ALEN
, buf
, 32)) {
805 DHD_ERROR(("%s: mkiovar failed for cur_etheraddr\n",
806 dhd_ifname(&dhd
->pub
, ifidx
)));
809 memset(&ioc
, 0, sizeof(ioc
));
810 ioc
.cmd
= WLC_SET_VAR
;
815 ret
= dhd_prot_ioctl(&dhd
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
817 DHD_ERROR(("%s: set cur_etheraddr failed\n",
818 dhd_ifname(&dhd
->pub
, ifidx
)));
820 memcpy(dhd
->iflist
[ifidx
]->net
->dev_addr
, addr
, ETH_ALEN
);
827 extern struct net_device
*ap_net_dev
;
830 static void dhd_op_if(dhd_if_t
*ifp
)
833 int ret
= 0, err
= 0;
835 ASSERT(ifp
&& ifp
->info
&& ifp
->idx
); /* Virtual interfaces only */
839 DHD_TRACE(("%s: idx %d, state %d\n", __func__
, ifp
->idx
, ifp
->state
));
841 switch (ifp
->state
) {
844 * Delete the existing interface before overwriting it
845 * in case we missed the WLC_E_IF_DEL event.
847 if (ifp
->net
!= NULL
) {
848 DHD_ERROR(("%s: ERROR: netdev:%s already exists, "
849 "try free & unregister\n",
850 __func__
, ifp
->net
->name
));
851 netif_stop_queue(ifp
->net
);
852 unregister_netdev(ifp
->net
);
853 free_netdev(ifp
->net
);
855 /* Allocate etherdev, including space for private structure */
856 ifp
->net
= alloc_etherdev(sizeof(dhd
));
858 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__
));
862 strcpy(ifp
->net
->name
, ifp
->name
);
863 memcpy(netdev_priv(ifp
->net
), &dhd
, sizeof(dhd
));
864 err
= dhd_net_attach(&dhd
->pub
, ifp
->idx
);
866 DHD_ERROR(("%s: dhd_net_attach failed, "
872 /* semaphore that the soft AP CODE
874 extern struct semaphore ap_eth_sema
;
876 /* save ptr to wl0.1 netdev for use
878 ap_net_dev
= ifp
->net
;
879 /* signal to the SOFTAP 'sleeper' thread,
883 DHD_TRACE(("\n ==== pid:%x, net_device for "
884 "if:%s created ===\n\n",
885 current
->pid
, ifp
->net
->name
));
891 if (ifp
->net
!= NULL
) {
892 DHD_TRACE(("\n%s: got 'WLC_E_IF_DEL' state\n",
894 netif_stop_queue(ifp
->net
);
895 unregister_netdev(ifp
->net
);
896 ret
= DHD_DEL_IF
; /* Make sure the free_netdev()
901 DHD_ERROR(("%s: bad op %d\n", __func__
, ifp
->state
));
908 free_netdev(ifp
->net
);
910 dhd
->iflist
[ifp
->idx
] = NULL
;
913 if (ifp
->net
== ap_net_dev
)
914 ap_net_dev
= NULL
; /* NULL SOFTAP global
920 static int _dhd_sysioc_thread(void *data
)
922 dhd_info_t
*dhd
= (dhd_info_t
*) data
;
928 allow_signal(SIGTERM
);
930 while (down_interruptible(&dhd
->sysioc_sem
) == 0) {
931 if (kthread_should_stop())
933 for (i
= 0; i
< DHD_MAX_IFS
; i
++) {
934 if (dhd
->iflist
[i
]) {
936 in_ap
= (ap_net_dev
!= NULL
);
938 if (dhd
->iflist
[i
]->state
)
939 dhd_op_if(dhd
->iflist
[i
]);
941 if (dhd
->iflist
[i
] == NULL
) {
942 DHD_TRACE(("\n\n %s: interface %d "
943 "removed!\n", __func__
, i
));
947 if (in_ap
&& dhd
->set_macaddress
) {
948 DHD_TRACE(("attempt to set MAC for %s "
949 "in AP Mode," "blocked. \n",
950 dhd
->iflist
[i
]->net
->name
));
951 dhd
->set_macaddress
= false;
955 if (in_ap
&& dhd
->set_multicast
) {
956 DHD_TRACE(("attempt to set MULTICAST list for %s" "in AP Mode, blocked. \n",
957 dhd
->iflist
[i
]->net
->name
));
958 dhd
->set_multicast
= false;
962 if (dhd
->set_multicast
) {
963 dhd
->set_multicast
= false;
964 _dhd_set_multicast_list(dhd
, i
);
966 if (dhd
->set_macaddress
) {
967 dhd
->set_macaddress
= false;
968 _dhd_set_mac_address(dhd
, i
,
977 static int dhd_set_mac_address(struct net_device
*dev
, void *addr
)
981 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(dev
);
982 struct sockaddr
*sa
= (struct sockaddr
*)addr
;
985 ifidx
= dhd_net2idx(dhd
, dev
);
986 if (ifidx
== DHD_BAD_IF
)
989 ASSERT(dhd
->sysioc_tsk
);
990 memcpy(&dhd
->macvalue
, sa
->sa_data
, ETH_ALEN
);
991 dhd
->set_macaddress
= true;
992 up(&dhd
->sysioc_sem
);
997 static void dhd_set_multicast_list(struct net_device
*dev
)
999 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(dev
);
1002 ifidx
= dhd_net2idx(dhd
, dev
);
1003 if (ifidx
== DHD_BAD_IF
)
1006 ASSERT(dhd
->sysioc_tsk
);
1007 dhd
->set_multicast
= true;
1008 up(&dhd
->sysioc_sem
);
1011 int dhd_sendpkt(dhd_pub_t
*dhdp
, int ifidx
, struct sk_buff
*pktbuf
)
1014 dhd_info_t
*dhd
= (dhd_info_t
*) (dhdp
->info
);
1016 /* Reject if down */
1017 if (!dhdp
->up
|| (dhdp
->busstate
== DHD_BUS_DOWN
))
1020 /* Update multicast statistic */
1021 if (pktbuf
->len
>= ETH_ALEN
) {
1022 u8
*pktdata
= (u8
*) (pktbuf
->data
);
1023 struct ethhdr
*eh
= (struct ethhdr
*)pktdata
;
1025 if (is_multicast_ether_addr(eh
->h_dest
))
1026 dhdp
->tx_multicast
++;
1027 if (ntohs(eh
->h_proto
) == ETH_P_PAE
)
1028 atomic_inc(&dhd
->pend_8021x_cnt
);
1031 /* If the protocol uses a data header, apply it */
1032 dhd_prot_hdrpush(dhdp
, ifidx
, pktbuf
);
1034 /* Use bus module to send data frame */
1036 ret
= dbus_send_pkt(dhdp
->dbus
, pktbuf
, NULL
/* pktinfo */);
1038 ret
= dhd_bus_txdata(dhdp
->bus
, pktbuf
);
1039 #endif /* BCMDBUS */
1044 static inline void *
1045 osl_pkt_frmnative(struct sk_buff
*skb
)
1049 #define PKTFRMNATIVE(osh, skb) \
1050 osl_pkt_frmnative((struct sk_buff *)(skb))
1052 static inline struct sk_buff
*
1053 osl_pkt_tonative(void *pkt
)
1055 return (struct sk_buff
*)pkt
;
1057 #define PKTTONATIVE(osh, pkt) \
1058 osl_pkt_tonative((pkt))
1060 static int dhd_start_xmit(struct sk_buff
*skb
, struct net_device
*net
)
1064 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(net
);
1067 DHD_TRACE(("%s: Enter\n", __func__
));
1069 /* Reject if down */
1070 if (!dhd
->pub
.up
|| (dhd
->pub
.busstate
== DHD_BUS_DOWN
)) {
1071 DHD_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n",
1072 __func__
, dhd
->pub
.up
, dhd
->pub
.busstate
));
1073 netif_stop_queue(net
);
1077 ifidx
= dhd_net2idx(dhd
, net
);
1078 if (ifidx
== DHD_BAD_IF
) {
1079 DHD_ERROR(("%s: bad ifidx %d\n", __func__
, ifidx
));
1080 netif_stop_queue(net
);
1084 /* Make sure there's enough room for any header */
1085 if (skb_headroom(skb
) < dhd
->pub
.hdrlen
) {
1086 struct sk_buff
*skb2
;
1088 DHD_INFO(("%s: insufficient headroom\n",
1089 dhd_ifname(&dhd
->pub
, ifidx
)));
1090 dhd
->pub
.tx_realloc
++;
1091 skb2
= skb_realloc_headroom(skb
, dhd
->pub
.hdrlen
);
1095 DHD_ERROR(("%s: skb_realloc_headroom failed\n",
1096 dhd_ifname(&dhd
->pub
, ifidx
)));
1102 /* Convert to packet */
1103 pktbuf
= PKTFRMNATIVE(dhd
->pub
.osh
, skb
);
1105 DHD_ERROR(("%s: PKTFRMNATIVE failed\n",
1106 dhd_ifname(&dhd
->pub
, ifidx
)));
1107 dev_kfree_skb_any(skb
);
1112 ret
= dhd_sendpkt(&dhd
->pub
, ifidx
, pktbuf
);
1116 dhd
->pub
.dstats
.tx_dropped
++;
1118 dhd
->pub
.tx_packets
++;
1120 /* Return ok: we always eat the packet */
1124 void dhd_txflowcontrol(dhd_pub_t
*dhdp
, int ifidx
, bool state
)
1126 struct net_device
*net
;
1127 dhd_info_t
*dhd
= dhdp
->info
;
1129 DHD_TRACE(("%s: Enter\n", __func__
));
1131 dhdp
->txoff
= state
;
1132 ASSERT(dhd
&& dhd
->iflist
[ifidx
]);
1133 net
= dhd
->iflist
[ifidx
]->net
;
1135 netif_stop_queue(net
);
1137 netif_wake_queue(net
);
1140 void dhd_rx_frame(dhd_pub_t
*dhdp
, int ifidx
, struct sk_buff
*pktbuf
,
1143 dhd_info_t
*dhd
= (dhd_info_t
*) dhdp
->info
;
1144 struct sk_buff
*skb
;
1148 struct sk_buff
*pnext
, *save_pktbuf
;
1151 wl_event_msg_t event
;
1153 DHD_TRACE(("%s: Enter\n", __func__
));
1155 save_pktbuf
= pktbuf
;
1157 for (i
= 0; pktbuf
&& i
< numpkt
; i
++, pktbuf
= pnext
) {
1159 pnext
= pktbuf
->next
;
1160 pktbuf
->next
= NULL
;
1162 skb
= PKTTONATIVE(dhdp
->osh
, pktbuf
);
1164 /* Get the protocol, maintain skb around eth_type_trans()
1165 * The main reason for this hack is for the limitation of
1166 * Linux 2.4 where 'eth_type_trans' uses the
1167 * 'net->hard_header_len'
1168 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
1169 * coping of the packet coming from the network stack to add
1170 * BDC, Hardware header etc, during network interface
1172 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
1174 * for BDC, Hardware header etc. and not just the ETH_HLEN
1179 ifp
= dhd
->iflist
[ifidx
];
1181 ifp
= dhd
->iflist
[0];
1184 skb
->dev
= ifp
->net
;
1185 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
1187 if (skb
->pkt_type
== PACKET_MULTICAST
)
1188 dhd
->pub
.rx_multicast
++;
1193 /* Strip header, count, deliver upward */
1194 skb_pull(skb
, ETH_HLEN
);
1196 /* Process special event packets and then discard them */
1197 if (ntohs(skb
->protocol
) == ETH_P_BRCM
)
1198 dhd_wl_host_event(dhd
, &ifidx
,
1199 skb_mac_header(skb
),
1202 ASSERT(ifidx
< DHD_MAX_IFS
&& dhd
->iflist
[ifidx
]);
1203 if (dhd
->iflist
[ifidx
] && !dhd
->iflist
[ifidx
]->state
)
1204 ifp
= dhd
->iflist
[ifidx
];
1207 ifp
->net
->last_rx
= jiffies
;
1209 dhdp
->dstats
.rx_bytes
+= skb
->len
;
1210 dhdp
->rx_packets
++; /* Local count */
1212 if (in_interrupt()) {
1215 /* If the receive is not processed inside an ISR,
1216 * the softirqd must be woken explicitly to service
1217 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
1218 * by netif_rx_ni(), but in earlier kernels, we need
1219 * to do it manually.
1226 void dhd_event(struct dhd_info
*dhd
, char *evpkt
, int evlen
, int ifidx
)
1228 /* Linux version has nothing to do */
1232 void dhd_txcomplete(dhd_pub_t
*dhdp
, struct sk_buff
*txp
, bool success
)
1235 dhd_info_t
*dhd
= (dhd_info_t
*) (dhdp
->info
);
1239 dhd_prot_hdrpull(dhdp
, &ifidx
, txp
);
1241 eh
= (struct ethhdr
*)(txp
->data
);
1242 type
= ntohs(eh
->h_proto
);
1244 if (type
== ETH_P_PAE
)
1245 atomic_dec(&dhd
->pend_8021x_cnt
);
1249 static struct net_device_stats
*dhd_get_stats(struct net_device
*net
)
1251 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(net
);
1255 DHD_TRACE(("%s: Enter\n", __func__
));
1257 ifidx
= dhd_net2idx(dhd
, net
);
1258 if (ifidx
== DHD_BAD_IF
)
1261 ifp
= dhd
->iflist
[ifidx
];
1265 /* Use the protocol to get dongle stats */
1266 dhd_prot_dstats(&dhd
->pub
);
1269 /* Copy dongle stats to net device stats */
1270 ifp
->stats
.rx_packets
= dhd
->pub
.dstats
.rx_packets
;
1271 ifp
->stats
.tx_packets
= dhd
->pub
.dstats
.tx_packets
;
1272 ifp
->stats
.rx_bytes
= dhd
->pub
.dstats
.rx_bytes
;
1273 ifp
->stats
.tx_bytes
= dhd
->pub
.dstats
.tx_bytes
;
1274 ifp
->stats
.rx_errors
= dhd
->pub
.dstats
.rx_errors
;
1275 ifp
->stats
.tx_errors
= dhd
->pub
.dstats
.tx_errors
;
1276 ifp
->stats
.rx_dropped
= dhd
->pub
.dstats
.rx_dropped
;
1277 ifp
->stats
.tx_dropped
= dhd
->pub
.dstats
.tx_dropped
;
1278 ifp
->stats
.multicast
= dhd
->pub
.dstats
.multicast
;
1283 static int dhd_watchdog_thread(void *data
)
1285 dhd_info_t
*dhd
= (dhd_info_t
*) data
;
1287 /* This thread doesn't need any user-level access,
1288 * so get rid of all our resources
1291 if (dhd_watchdog_prio
> 0) {
1292 struct sched_param param
;
1293 param
.sched_priority
= (dhd_watchdog_prio
< MAX_RT_PRIO
) ?
1294 dhd_watchdog_prio
: (MAX_RT_PRIO
- 1);
1295 setScheduler(current
, SCHED_FIFO
, ¶m
);
1297 #endif /* DHD_SCHED */
1299 allow_signal(SIGTERM
);
1300 /* Run until signal received */
1302 if (kthread_should_stop())
1304 if (down_interruptible(&dhd
->watchdog_sem
) == 0) {
1305 if (dhd
->pub
.dongle_reset
== false) {
1306 /* Call the bus module watchdog */
1307 dhd_bus_watchdog(&dhd
->pub
);
1309 /* Count the tick for reference */
1317 static void dhd_watchdog(unsigned long data
)
1319 dhd_info_t
*dhd
= (dhd_info_t
*) data
;
1321 if (dhd
->watchdog_tsk
) {
1322 up(&dhd
->watchdog_sem
);
1324 /* Reschedule the watchdog */
1325 if (dhd
->wd_timer_valid
) {
1326 mod_timer(&dhd
->timer
,
1327 jiffies
+ dhd_watchdog_ms
* HZ
/ 1000);
1332 /* Call the bus module watchdog */
1333 dhd_bus_watchdog(&dhd
->pub
);
1335 /* Count the tick for reference */
1338 /* Reschedule the watchdog */
1339 if (dhd
->wd_timer_valid
)
1340 mod_timer(&dhd
->timer
, jiffies
+ dhd_watchdog_ms
* HZ
/ 1000);
1343 static int dhd_dpc_thread(void *data
)
1345 dhd_info_t
*dhd
= (dhd_info_t
*) data
;
1347 /* This thread doesn't need any user-level access,
1348 * so get rid of all our resources
1351 if (dhd_dpc_prio
> 0) {
1352 struct sched_param param
;
1353 param
.sched_priority
=
1355 MAX_RT_PRIO
) ? dhd_dpc_prio
: (MAX_RT_PRIO
- 1);
1356 setScheduler(current
, SCHED_FIFO
, ¶m
);
1358 #endif /* DHD_SCHED */
1360 allow_signal(SIGTERM
);
1361 /* Run until signal received */
1363 if (kthread_should_stop())
1365 if (down_interruptible(&dhd
->dpc_sem
) == 0) {
1366 /* Call bus dpc unless it indicated down
1367 (then clean stop) */
1368 if (dhd
->pub
.busstate
!= DHD_BUS_DOWN
) {
1369 if (dhd_bus_dpc(dhd
->pub
.bus
)) {
1373 dhd_bus_stop(dhd
->pub
.bus
, true);
1381 static void dhd_dpc(unsigned long data
)
1385 dhd
= (dhd_info_t
*) data
;
1387 /* Call bus dpc unless it indicated down (then clean stop) */
1388 if (dhd
->pub
.busstate
!= DHD_BUS_DOWN
) {
1389 if (dhd_bus_dpc(dhd
->pub
.bus
))
1390 tasklet_schedule(&dhd
->tasklet
);
1392 dhd_bus_stop(dhd
->pub
.bus
, true);
1396 void dhd_sched_dpc(dhd_pub_t
*dhdp
)
1398 dhd_info_t
*dhd
= (dhd_info_t
*) dhdp
->info
;
1405 tasklet_schedule(&dhd
->tasklet
);
1409 /* Retrieve current toe component enables, which are kept
1410 as a bitmap in toe_ol iovar */
1411 static int dhd_toe_get(dhd_info_t
*dhd
, int ifidx
, u32
*toe_ol
)
1417 memset(&ioc
, 0, sizeof(ioc
));
1419 ioc
.cmd
= WLC_GET_VAR
;
1421 ioc
.len
= (uint
) sizeof(buf
);
1424 strcpy(buf
, "toe_ol");
1425 ret
= dhd_prot_ioctl(&dhd
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
1427 /* Check for older dongle image that doesn't support toe_ol */
1429 DHD_ERROR(("%s: toe not supported by device\n",
1430 dhd_ifname(&dhd
->pub
, ifidx
)));
1434 DHD_INFO(("%s: could not get toe_ol: ret=%d\n",
1435 dhd_ifname(&dhd
->pub
, ifidx
), ret
));
1439 memcpy(toe_ol
, buf
, sizeof(u32
));
1443 /* Set current toe component enables in toe_ol iovar,
1444 and set toe global enable iovar */
1445 static int dhd_toe_set(dhd_info_t
*dhd
, int ifidx
, u32 toe_ol
)
1451 memset(&ioc
, 0, sizeof(ioc
));
1453 ioc
.cmd
= WLC_SET_VAR
;
1455 ioc
.len
= (uint
) sizeof(buf
);
1458 /* Set toe_ol as requested */
1460 strcpy(buf
, "toe_ol");
1461 memcpy(&buf
[sizeof("toe_ol")], &toe_ol
, sizeof(u32
));
1463 ret
= dhd_prot_ioctl(&dhd
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
1465 DHD_ERROR(("%s: could not set toe_ol: ret=%d\n",
1466 dhd_ifname(&dhd
->pub
, ifidx
), ret
));
1470 /* Enable toe globally only if any components are enabled. */
1472 toe
= (toe_ol
!= 0);
1475 memcpy(&buf
[sizeof("toe")], &toe
, sizeof(u32
));
1477 ret
= dhd_prot_ioctl(&dhd
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
1479 DHD_ERROR(("%s: could not set toe: ret=%d\n",
1480 dhd_ifname(&dhd
->pub
, ifidx
), ret
));
1488 static void dhd_ethtool_get_drvinfo(struct net_device
*net
,
1489 struct ethtool_drvinfo
*info
)
1491 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(net
);
1493 sprintf(info
->driver
, DRV_MODULE_NAME
);
1494 sprintf(info
->version
, "%lu", dhd
->pub
.drv_version
);
1495 sprintf(info
->fw_version
, "%s", wl_cfg80211_get_fwname());
1496 sprintf(info
->bus_info
, "%s", dev_name(&wl_cfg80211_get_sdio_func()->dev
));
1499 struct ethtool_ops dhd_ethtool_ops
= {
1500 .get_drvinfo
= dhd_ethtool_get_drvinfo
1503 static int dhd_ethtool(dhd_info_t
*dhd
, void *uaddr
)
1505 struct ethtool_drvinfo info
;
1506 char drvname
[sizeof(info
.driver
)];
1509 struct ethtool_value edata
;
1510 u32 toe_cmpnt
, csum_dir
;
1514 DHD_TRACE(("%s: Enter\n", __func__
));
1516 /* all ethtool calls start with a cmd word */
1517 if (copy_from_user(&cmd
, uaddr
, sizeof(u32
)))
1521 case ETHTOOL_GDRVINFO
:
1522 /* Copy out any request driver name */
1523 if (copy_from_user(&info
, uaddr
, sizeof(info
)))
1525 strncpy(drvname
, info
.driver
, sizeof(info
.driver
));
1526 drvname
[sizeof(info
.driver
) - 1] = '\0';
1528 /* clear struct for return */
1529 memset(&info
, 0, sizeof(info
));
1532 /* if dhd requested, identify ourselves */
1533 if (strcmp(drvname
, "?dhd") == 0) {
1534 sprintf(info
.driver
, "dhd");
1535 strcpy(info
.version
, EPI_VERSION_STR
);
1538 /* otherwise, require dongle to be up */
1539 else if (!dhd
->pub
.up
) {
1540 DHD_ERROR(("%s: dongle is not up\n", __func__
));
1544 /* finally, report dongle driver type */
1545 else if (dhd
->pub
.iswl
)
1546 sprintf(info
.driver
, "wl");
1548 sprintf(info
.driver
, "xx");
1550 sprintf(info
.version
, "%lu", dhd
->pub
.drv_version
);
1551 if (copy_to_user(uaddr
, &info
, sizeof(info
)))
1553 DHD_CTL(("%s: given %*s, returning %s\n", __func__
,
1554 (int)sizeof(drvname
), drvname
, info
.driver
));
1558 /* Get toe offload components from dongle */
1559 case ETHTOOL_GRXCSUM
:
1560 case ETHTOOL_GTXCSUM
:
1561 ret
= dhd_toe_get(dhd
, 0, &toe_cmpnt
);
1566 (cmd
== ETHTOOL_GTXCSUM
) ? TOE_TX_CSUM_OL
: TOE_RX_CSUM_OL
;
1569 edata
.data
= (toe_cmpnt
& csum_dir
) ? 1 : 0;
1571 if (copy_to_user(uaddr
, &edata
, sizeof(edata
)))
1575 /* Set toe offload components in dongle */
1576 case ETHTOOL_SRXCSUM
:
1577 case ETHTOOL_STXCSUM
:
1578 if (copy_from_user(&edata
, uaddr
, sizeof(edata
)))
1581 /* Read the current settings, update and write back */
1582 ret
= dhd_toe_get(dhd
, 0, &toe_cmpnt
);
1587 (cmd
== ETHTOOL_STXCSUM
) ? TOE_TX_CSUM_OL
: TOE_RX_CSUM_OL
;
1589 if (edata
.data
!= 0)
1590 toe_cmpnt
|= csum_dir
;
1592 toe_cmpnt
&= ~csum_dir
;
1594 ret
= dhd_toe_set(dhd
, 0, toe_cmpnt
);
1598 /* If setting TX checksum mode, tell Linux the new mode */
1599 if (cmd
== ETHTOOL_STXCSUM
) {
1601 dhd
->iflist
[0]->net
->features
|=
1604 dhd
->iflist
[0]->net
->features
&=
1618 static int dhd_ioctl_entry(struct net_device
*net
, struct ifreq
*ifr
, int cmd
)
1620 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(net
);
1627 bool is_set_key_cmd
;
1629 ifidx
= dhd_net2idx(dhd
, net
);
1630 DHD_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __func__
, ifidx
, cmd
));
1632 if (ifidx
== DHD_BAD_IF
)
1635 #if defined(CONFIG_WIRELESS_EXT)
1636 /* linux wireless extensions */
1637 if ((cmd
>= SIOCIWFIRST
) && (cmd
<= SIOCIWLAST
)) {
1638 /* may recurse, do NOT lock */
1639 return wl_iw_ioctl(net
, ifr
, cmd
);
1641 #endif /* defined(CONFIG_WIRELESS_EXT) */
1643 if (cmd
== SIOCETHTOOL
)
1644 return dhd_ethtool(dhd
, (void *)ifr
->ifr_data
);
1646 if (cmd
!= SIOCDEVPRIVATE
)
1649 memset(&ioc
, 0, sizeof(ioc
));
1651 /* Copy the ioc control structure part of ioctl request */
1652 if (copy_from_user(&ioc
, ifr
->ifr_data
, sizeof(wl_ioctl_t
))) {
1657 /* Copy out any buffer passed */
1659 buflen
= min_t(int, ioc
.len
, DHD_IOCTL_MAXLEN
);
1660 /* optimization for direct ioctl calls from kernel */
1662 if (segment_eq(get_fs(), KERNEL_DS)) {
1667 buf
= kmalloc(buflen
, GFP_ATOMIC
);
1672 if (copy_from_user(buf
, ioc
.buf
, buflen
)) {
1679 /* To differentiate between wl and dhd read 4 more byes */
1680 if ((copy_from_user(&driver
, (char *)ifr
->ifr_data
+ sizeof(wl_ioctl_t
),
1681 sizeof(uint
)) != 0)) {
1686 if (!capable(CAP_NET_ADMIN
)) {
1691 /* check for local dhd ioctl and handle it */
1692 if (driver
== DHD_IOCTL_MAGIC
) {
1693 bcmerror
= dhd_ioctl((void *)&dhd
->pub
, &ioc
, buf
, buflen
);
1695 dhd
->pub
.bcmerror
= bcmerror
;
1699 /* send to dongle (must be up, and wl) */
1700 if ((dhd
->pub
.busstate
!= DHD_BUS_DATA
)) {
1701 DHD_ERROR(("%s DONGLE_DOWN,__func__\n", __func__
));
1706 if (!dhd
->pub
.iswl
) {
1711 /* Intercept WLC_SET_KEY IOCTL - serialize M4 send and set key IOCTL to
1712 * prevent M4 encryption.
1714 is_set_key_cmd
= ((ioc
.cmd
== WLC_SET_KEY
) ||
1715 ((ioc
.cmd
== WLC_SET_VAR
) &&
1716 !(strncmp("wsec_key", ioc
.buf
, 9))) ||
1717 ((ioc
.cmd
== WLC_SET_VAR
) &&
1718 !(strncmp("bsscfg:wsec_key", ioc
.buf
, 15))));
1720 dhd_wait_pend8021x(net
);
1723 dhd_prot_ioctl(&dhd
->pub
, ifidx
, (wl_ioctl_t
*)&ioc
, buf
, buflen
);
1726 if (!bcmerror
&& buf
&& ioc
.buf
) {
1727 if (copy_to_user(ioc
.buf
, buf
, buflen
))
1739 static int dhd_stop(struct net_device
*net
)
1741 #if !defined(IGNORE_ETH0_DOWN)
1742 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(net
);
1744 DHD_TRACE(("%s: Enter\n", __func__
));
1745 if (IS_CFG80211_FAVORITE()) {
1748 if (dhd
->pub
.up
== 0)
1751 /* Set state and stop OS transmissions */
1753 netif_stop_queue(net
);
1755 DHD_ERROR(("BYPASS %s:due to BRCM compilation : under investigation\n",
1757 #endif /* !defined(IGNORE_ETH0_DOWN) */
1762 static int dhd_open(struct net_device
*net
)
1764 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(net
);
1768 int ifidx
= dhd_net2idx(dhd
, net
);
1771 DHD_TRACE(("%s: ifidx %d\n", __func__
, ifidx
));
1773 if (ifidx
== 0) { /* do it only for primary eth0 */
1775 /* try to bring up bus */
1776 ret
= dhd_bus_start(&dhd
->pub
);
1778 DHD_ERROR(("%s: failed with code %d\n", __func__
, ret
));
1781 atomic_set(&dhd
->pend_8021x_cnt
, 0);
1783 memcpy(net
->dev_addr
, dhd
->pub
.mac
, ETH_ALEN
);
1786 /* Get current TOE mode from dongle */
1787 if (dhd_toe_get(dhd
, ifidx
, &toe_ol
) >= 0
1788 && (toe_ol
& TOE_TX_CSUM_OL
) != 0)
1789 dhd
->iflist
[ifidx
]->net
->features
|= NETIF_F_IP_CSUM
;
1791 dhd
->iflist
[ifidx
]->net
->features
&= ~NETIF_F_IP_CSUM
;
1794 /* Allow transmit calls */
1795 netif_start_queue(net
);
1797 if (IS_CFG80211_FAVORITE()) {
1798 if (unlikely(wl_cfg80211_up())) {
1799 DHD_ERROR(("%s: failed to bring up cfg80211\n",
1809 dhd_add_if(dhd_info_t
*dhd
, int ifidx
, void *handle
, char *name
,
1810 u8
*mac_addr
, u32 flags
, u8 bssidx
)
1814 DHD_TRACE(("%s: idx %d, handle->%p\n", __func__
, ifidx
, handle
));
1816 ASSERT(dhd
&& (ifidx
< DHD_MAX_IFS
));
1818 ifp
= dhd
->iflist
[ifidx
];
1819 if (!ifp
&& !(ifp
= kmalloc(sizeof(dhd_if_t
), GFP_ATOMIC
))) {
1820 DHD_ERROR(("%s: OOM - dhd_if_t\n", __func__
));
1824 memset(ifp
, 0, sizeof(dhd_if_t
));
1826 dhd
->iflist
[ifidx
] = ifp
;
1827 strlcpy(ifp
->name
, name
, IFNAMSIZ
);
1828 if (mac_addr
!= NULL
)
1829 memcpy(&ifp
->mac_addr
, mac_addr
, ETH_ALEN
);
1831 if (handle
== NULL
) {
1832 ifp
->state
= WLC_E_IF_ADD
;
1834 ASSERT(dhd
->sysioc_tsk
);
1835 up(&dhd
->sysioc_sem
);
1837 ifp
->net
= (struct net_device
*)handle
;
1842 void dhd_del_if(dhd_info_t
*dhd
, int ifidx
)
1846 DHD_TRACE(("%s: idx %d\n", __func__
, ifidx
));
1848 ASSERT(dhd
&& ifidx
&& (ifidx
< DHD_MAX_IFS
));
1849 ifp
= dhd
->iflist
[ifidx
];
1851 DHD_ERROR(("%s: Null interface\n", __func__
));
1855 ifp
->state
= WLC_E_IF_DEL
;
1857 ASSERT(dhd
->sysioc_tsk
);
1858 up(&dhd
->sysioc_sem
);
1861 dhd_pub_t
*dhd_attach(struct dhd_bus
*bus
, uint bus_hdrlen
)
1863 dhd_info_t
*dhd
= NULL
;
1864 struct net_device
*net
;
1866 DHD_TRACE(("%s: Enter\n", __func__
));
1867 /* updates firmware nvram path if it was provided as module
1869 if ((firmware_path
!= NULL
) && (firmware_path
[0] != '\0'))
1870 strcpy(fw_path
, firmware_path
);
1871 if ((nvram_path
!= NULL
) && (nvram_path
[0] != '\0'))
1872 strcpy(nv_path
, nvram_path
);
1874 /* Allocate etherdev, including space for private structure */
1875 net
= alloc_etherdev(sizeof(dhd
));
1877 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__
));
1881 /* Allocate primary dhd_info */
1882 dhd
= kzalloc(sizeof(dhd_info_t
), GFP_ATOMIC
);
1884 DHD_ERROR(("%s: OOM - alloc dhd_info\n", __func__
));
1889 * Save the dhd_info into the priv
1891 memcpy(netdev_priv(net
), &dhd
, sizeof(dhd
));
1893 /* Set network interface name if it was provided as module parameter */
1894 if (iface_name
[0]) {
1897 strncpy(net
->name
, iface_name
, IFNAMSIZ
);
1898 net
->name
[IFNAMSIZ
- 1] = 0;
1899 len
= strlen(net
->name
);
1900 ch
= net
->name
[len
- 1];
1901 if ((ch
> '9' || ch
< '0') && (len
< IFNAMSIZ
- 2))
1902 strcat(net
->name
, "%d");
1905 if (dhd_add_if(dhd
, 0, (void *)net
, net
->name
, NULL
, 0, 0) ==
1909 net
->netdev_ops
= NULL
;
1910 sema_init(&dhd
->proto_sem
, 1);
1911 /* Initialize other structure content */
1912 init_waitqueue_head(&dhd
->ioctl_resp_wait
);
1913 init_waitqueue_head(&dhd
->ctrl_wait
);
1915 /* Initialize the spinlocks */
1916 spin_lock_init(&dhd
->sdlock
);
1917 spin_lock_init(&dhd
->txqlock
);
1919 /* Link to info module */
1920 dhd
->pub
.info
= dhd
;
1922 /* Link to bus module */
1924 dhd
->pub
.hdrlen
= bus_hdrlen
;
1926 /* Attach and link in the protocol */
1927 if (dhd_prot_attach(&dhd
->pub
) != 0) {
1928 DHD_ERROR(("dhd_prot_attach failed\n"));
1931 #if defined(CONFIG_WIRELESS_EXT)
1932 /* Attach and link in the iw */
1933 if (wl_iw_attach(net
, (void *)&dhd
->pub
) != 0) {
1934 DHD_ERROR(("wl_iw_attach failed\n"));
1937 #endif /* defined(CONFIG_WIRELESS_EXT) */
1939 /* Attach and link in the cfg80211 */
1940 if (IS_CFG80211_FAVORITE()) {
1941 if (unlikely(wl_cfg80211_attach(net
, &dhd
->pub
))) {
1942 DHD_ERROR(("wl_cfg80211_attach failed\n"));
1946 strcpy(fw_path
, wl_cfg80211_get_fwname());
1947 strcpy(nv_path
, wl_cfg80211_get_nvramname());
1951 /* Set up the watchdog timer */
1952 init_timer(&dhd
->timer
);
1953 dhd
->timer
.data
= (unsigned long) dhd
;
1954 dhd
->timer
.function
= dhd_watchdog
;
1956 /* Initialize thread based operation and lock */
1957 sema_init(&dhd
->sdsem
, 1);
1958 if ((dhd_watchdog_prio
>= 0) && (dhd_dpc_prio
>= 0))
1959 dhd
->threads_only
= true;
1961 dhd
->threads_only
= false;
1963 if (dhd_dpc_prio
>= 0) {
1964 /* Initialize watchdog thread */
1965 sema_init(&dhd
->watchdog_sem
, 0);
1966 dhd
->watchdog_tsk
= kthread_run(dhd_watchdog_thread
, dhd
,
1968 if (IS_ERR(dhd
->watchdog_tsk
)) {
1970 "dhd_watchdog thread failed to start\n");
1971 dhd
->watchdog_tsk
= NULL
;
1974 dhd
->watchdog_tsk
= NULL
;
1977 /* Set up the bottom half handler */
1978 if (dhd_dpc_prio
>= 0) {
1979 /* Initialize DPC thread */
1980 sema_init(&dhd
->dpc_sem
, 0);
1981 dhd
->dpc_tsk
= kthread_run(dhd_dpc_thread
, dhd
, "dhd_dpc");
1982 if (IS_ERR(dhd
->dpc_tsk
)) {
1984 "dhd_dpc thread failed to start\n");
1985 dhd
->dpc_tsk
= NULL
;
1988 tasklet_init(&dhd
->tasklet
, dhd_dpc
, (unsigned long) dhd
);
1989 dhd
->dpc_tsk
= NULL
;
1993 sema_init(&dhd
->sysioc_sem
, 0);
1994 dhd
->sysioc_tsk
= kthread_run(_dhd_sysioc_thread
, dhd
,
1996 if (IS_ERR(dhd
->sysioc_tsk
)) {
1998 "_dhd_sysioc thread failed to start\n");
1999 dhd
->sysioc_tsk
= NULL
;
2002 dhd
->sysioc_tsk
= NULL
;
2005 * Save the dhd_info into the priv
2007 memcpy(netdev_priv(net
), &dhd
, sizeof(dhd
));
2009 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2012 #if defined(CONFIG_PM_SLEEP)
2013 atomic_set(&dhd_mmc_suspend
, false);
2014 if (!IS_CFG80211_FAVORITE())
2015 register_pm_notifier(&dhd_sleep_pm_notifier
);
2016 #endif /* defined(CONFIG_PM_SLEEP) */
2017 /* && defined(DHD_GPL) */
2018 /* Init lock suspend to prevent kernel going to suspend */
2019 #ifdef CONFIG_HAS_EARLYSUSPEND
2020 dhd
->early_suspend
.level
= EARLY_SUSPEND_LEVEL_BLANK_SCREEN
+ 20;
2021 dhd
->early_suspend
.suspend
= dhd_early_suspend
;
2022 dhd
->early_suspend
.resume
= dhd_late_resume
;
2023 register_early_suspend(&dhd
->early_suspend
);
2032 dhd_detach(&dhd
->pub
);
2037 int dhd_bus_start(dhd_pub_t
*dhdp
)
2040 dhd_info_t
*dhd
= (dhd_info_t
*) dhdp
->info
;
2041 #ifdef EMBEDDED_PLATFORM
2042 char iovbuf
[WL_EVENTING_MASK_LEN
+ 12]; /* Room for "event_msgs" +
2044 #endif /* EMBEDDED_PLATFORM */
2048 DHD_TRACE(("%s:\n", __func__
));
2050 /* try to download image and nvram to the dongle */
2051 if (dhd
->pub
.busstate
== DHD_BUS_DOWN
) {
2052 if (!(dhd_bus_download_firmware(dhd
->pub
.bus
,
2053 fw_path
, nv_path
))) {
2054 DHD_ERROR(("%s: dhdsdio_probe_download failed. "
2055 "firmware = %s nvram = %s\n",
2056 __func__
, fw_path
, nv_path
));
2061 /* Start the watchdog timer */
2062 dhd
->pub
.tickcnt
= 0;
2063 dhd_os_wd_timer(&dhd
->pub
, dhd_watchdog_ms
);
2065 /* Bring up the bus */
2066 ret
= dhd_bus_init(&dhd
->pub
, true);
2068 DHD_ERROR(("%s, dhd_bus_init failed %d\n", __func__
, ret
));
2071 #if defined(OOB_INTR_ONLY)
2072 /* Host registration for OOB interrupt */
2073 if (bcmsdh_register_oob_intr(dhdp
)) {
2074 del_timer_sync(&dhd
->timer
);
2075 dhd
->wd_timer_valid
= false;
2076 DHD_ERROR(("%s Host failed to resgister for OOB\n", __func__
));
2080 /* Enable oob at firmware */
2081 dhd_enable_oob_intr(dhd
->pub
.bus
, true);
2082 #endif /* defined(OOB_INTR_ONLY) */
2084 /* If bus is not ready, can't come up */
2085 if (dhd
->pub
.busstate
!= DHD_BUS_DATA
) {
2086 del_timer_sync(&dhd
->timer
);
2087 dhd
->wd_timer_valid
= false;
2088 DHD_ERROR(("%s failed bus is not ready\n", __func__
));
2091 #ifdef EMBEDDED_PLATFORM
2092 bcm_mkiovar("event_msgs", dhdp
->eventmask
, WL_EVENTING_MASK_LEN
, iovbuf
,
2094 dhdcdc_query_ioctl(dhdp
, 0, WLC_GET_VAR
, iovbuf
, sizeof(iovbuf
));
2095 memcpy(dhdp
->eventmask
, iovbuf
, WL_EVENTING_MASK_LEN
);
2097 setbit(dhdp
->eventmask
, WLC_E_SET_SSID
);
2098 setbit(dhdp
->eventmask
, WLC_E_PRUNE
);
2099 setbit(dhdp
->eventmask
, WLC_E_AUTH
);
2100 setbit(dhdp
->eventmask
, WLC_E_REASSOC
);
2101 setbit(dhdp
->eventmask
, WLC_E_REASSOC_IND
);
2102 setbit(dhdp
->eventmask
, WLC_E_DEAUTH_IND
);
2103 setbit(dhdp
->eventmask
, WLC_E_DISASSOC_IND
);
2104 setbit(dhdp
->eventmask
, WLC_E_DISASSOC
);
2105 setbit(dhdp
->eventmask
, WLC_E_JOIN
);
2106 setbit(dhdp
->eventmask
, WLC_E_ASSOC_IND
);
2107 setbit(dhdp
->eventmask
, WLC_E_PSK_SUP
);
2108 setbit(dhdp
->eventmask
, WLC_E_LINK
);
2109 setbit(dhdp
->eventmask
, WLC_E_NDIS_LINK
);
2110 setbit(dhdp
->eventmask
, WLC_E_MIC_ERROR
);
2111 setbit(dhdp
->eventmask
, WLC_E_PMKID_CACHE
);
2112 setbit(dhdp
->eventmask
, WLC_E_TXFAIL
);
2113 setbit(dhdp
->eventmask
, WLC_E_JOIN_START
);
2114 setbit(dhdp
->eventmask
, WLC_E_SCAN_COMPLETE
);
2116 setbit(dhdp
->eventmask
, WLC_E_PFN_NET_FOUND
);
2117 #endif /* PNO_SUPPORT */
2119 /* enable dongle roaming event */
2121 dhdp
->pktfilter_count
= 1;
2122 /* Setup filter to allow only unicast */
2123 dhdp
->pktfilter
[0] = "100 0 0 0 0x01 0x00";
2124 #endif /* EMBEDDED_PLATFORM */
2126 /* Bus is ready, do any protocol initialization */
2127 ret
= dhd_prot_init(&dhd
->pub
);
2135 dhd_iovar(dhd_pub_t
*pub
, int ifidx
, char *name
, char *cmd_buf
, uint cmd_len
,
2138 char buf
[strlen(name
) + 1 + cmd_len
];
2139 int len
= sizeof(buf
);
2143 len
= bcm_mkiovar(name
, cmd_buf
, cmd_len
, buf
, len
);
2145 memset(&ioc
, 0, sizeof(ioc
));
2147 ioc
.cmd
= set
? WLC_SET_VAR
: WLC_GET_VAR
;
2152 ret
= dhd_prot_ioctl(pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
2153 if (!set
&& ret
>= 0)
2154 memcpy(cmd_buf
, buf
, cmd_len
);
2159 static struct net_device_ops dhd_ops_pri
= {
2160 .ndo_open
= dhd_open
,
2161 .ndo_stop
= dhd_stop
,
2162 .ndo_get_stats
= dhd_get_stats
,
2163 .ndo_do_ioctl
= dhd_ioctl_entry
,
2164 .ndo_start_xmit
= dhd_start_xmit
,
2165 .ndo_set_mac_address
= dhd_set_mac_address
,
2166 .ndo_set_multicast_list
= dhd_set_multicast_list
2169 int dhd_net_attach(dhd_pub_t
*dhdp
, int ifidx
)
2171 dhd_info_t
*dhd
= (dhd_info_t
*) dhdp
->info
;
2172 struct net_device
*net
;
2173 u8 temp_addr
[ETH_ALEN
] = {
2174 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
2176 DHD_TRACE(("%s: ifidx %d\n", __func__
, ifidx
));
2178 ASSERT(dhd
&& dhd
->iflist
[ifidx
]);
2180 net
= dhd
->iflist
[ifidx
]->net
;
2183 ASSERT(!net
->netdev_ops
);
2184 net
->netdev_ops
= &dhd_ops_pri
;
2187 * We have to use the primary MAC for virtual interfaces
2190 /* for virtual interfaces use the primary MAC */
2191 memcpy(temp_addr
, dhd
->pub
.mac
, ETH_ALEN
);
2196 DHD_TRACE(("%s ACCESS POINT MAC: \n", __func__
));
2197 /* ACCESSPOINT INTERFACE CASE */
2198 temp_addr
[0] |= 0X02; /* set bit 2 ,
2199 - Locally Administered address */
2202 net
->hard_header_len
= ETH_HLEN
+ dhd
->pub
.hdrlen
;
2203 net
->ethtool_ops
= &dhd_ethtool_ops
;
2205 dhd
->pub
.rxsz
= net
->mtu
+ net
->hard_header_len
+ dhd
->pub
.hdrlen
;
2207 memcpy(net
->dev_addr
, temp_addr
, ETH_ALEN
);
2209 if (register_netdev(net
) != 0) {
2210 DHD_ERROR(("%s: couldn't register the net device\n",
2215 DHD_INFO(("%s: Broadcom Dongle Host Driver\n", net
->name
));
2220 net
->netdev_ops
= NULL
;
2224 void dhd_bus_detach(dhd_pub_t
*dhdp
)
2228 DHD_TRACE(("%s: Enter\n", __func__
));
2231 dhd
= (dhd_info_t
*) dhdp
->info
;
2233 /* Stop the protocol module */
2234 dhd_prot_stop(&dhd
->pub
);
2236 /* Stop the bus module */
2237 dhd_bus_stop(dhd
->pub
.bus
, true);
2238 #if defined(OOB_INTR_ONLY)
2239 bcmsdh_unregister_oob_intr();
2240 #endif /* defined(OOB_INTR_ONLY) */
2242 /* Clear the watchdog timer */
2243 del_timer_sync(&dhd
->timer
);
2244 dhd
->wd_timer_valid
= false;
2249 void dhd_detach(dhd_pub_t
*dhdp
)
2253 DHD_TRACE(("%s: Enter\n", __func__
));
2256 dhd
= (dhd_info_t
*) dhdp
->info
;
2261 #if defined(CONFIG_HAS_EARLYSUSPEND)
2262 if (dhd
->early_suspend
.suspend
)
2263 unregister_early_suspend(&dhd
->early_suspend
);
2264 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2266 for (i
= 1; i
< DHD_MAX_IFS
; i
++)
2270 ifp
= dhd
->iflist
[0];
2272 if (ifp
->net
->netdev_ops
== &dhd_ops_pri
) {
2274 unregister_netdev(ifp
->net
);
2277 if (dhd
->watchdog_tsk
) {
2278 send_sig(SIGTERM
, dhd
->watchdog_tsk
, 1);
2279 kthread_stop(dhd
->watchdog_tsk
);
2280 dhd
->watchdog_tsk
= NULL
;
2284 send_sig(SIGTERM
, dhd
->dpc_tsk
, 1);
2285 kthread_stop(dhd
->dpc_tsk
);
2286 dhd
->dpc_tsk
= NULL
;
2288 tasklet_kill(&dhd
->tasklet
);
2290 if (dhd
->sysioc_tsk
) {
2291 send_sig(SIGTERM
, dhd
->sysioc_tsk
, 1);
2292 kthread_stop(dhd
->sysioc_tsk
);
2293 dhd
->sysioc_tsk
= NULL
;
2296 dhd_bus_detach(dhdp
);
2299 dhd_prot_detach(dhdp
);
2301 #if defined(CONFIG_WIRELESS_EXT)
2303 #endif /* (CONFIG_WIRELESS_EXT) */
2305 if (IS_CFG80211_FAVORITE())
2306 wl_cfg80211_detach();
2308 #if defined(CONFIG_PM_SLEEP)
2309 if (!IS_CFG80211_FAVORITE())
2310 unregister_pm_notifier(&dhd_sleep_pm_notifier
);
2311 #endif /* defined(CONFIG_PM_SLEEP) */
2312 /* && defined(DHD_GPL) */
2313 free_netdev(ifp
->net
);
2320 static void __exit
dhd_module_cleanup(void)
2322 DHD_TRACE(("%s: Enter\n", __func__
));
2324 dhd_bus_unregister();
2325 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2328 /* Call customer gpio to turn off power with WL_REG_ON signal */
2329 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF
);
2332 static int __init
dhd_module_init(void)
2336 DHD_TRACE(("%s: Enter\n", __func__
));
2338 /* Sanity check on the module parameters */
2340 /* Both watchdog and DPC as tasklets are ok */
2341 if ((dhd_watchdog_prio
< 0) && (dhd_dpc_prio
< 0))
2344 /* If both watchdog and DPC are threads, TX must be deferred */
2345 if ((dhd_watchdog_prio
>= 0) && (dhd_dpc_prio
>= 0)
2349 DHD_ERROR(("Invalid module parameters.\n"));
2352 /* Call customer gpio to turn on power with WL_REG_ON signal */
2353 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_ON
);
2355 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2356 sema_init(&wifi_control_sem
, 0);
2358 error
= wifi_add_dev();
2360 DHD_ERROR(("%s: platform_driver_register failed\n", __func__
));
2364 /* Waiting callback after platform_driver_register is done or
2366 if (down_timeout(&wifi_control_sem
, msecs_to_jiffies(1000)) != 0) {
2367 printk(KERN_ERR
"%s: platform_driver_register timeout\n",
2373 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2375 error
= dhd_bus_register();
2378 DHD_ERROR(("%s: sdio_register_driver failed\n", __func__
));
2384 /* turn off power and exit */
2385 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF
);
2389 module_init(dhd_module_init
);
2390 module_exit(dhd_module_cleanup
);
2393 * OS specific functions required to implement DHD driver in OS independent way
2395 int dhd_os_proto_block(dhd_pub_t
*pub
)
2397 dhd_info_t
*dhd
= (dhd_info_t
*) (pub
->info
);
2400 down(&dhd
->proto_sem
);
2406 int dhd_os_proto_unblock(dhd_pub_t
*pub
)
2408 dhd_info_t
*dhd
= (dhd_info_t
*) (pub
->info
);
2411 up(&dhd
->proto_sem
);
2418 unsigned int dhd_os_get_ioctl_resp_timeout(void)
2420 return (unsigned int)dhd_ioctl_timeout_msec
;
2423 void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec
)
2425 dhd_ioctl_timeout_msec
= (int)timeout_msec
;
2428 int dhd_os_ioctl_resp_wait(dhd_pub_t
*pub
, uint
*condition
, bool *pending
)
2430 dhd_info_t
*dhd
= (dhd_info_t
*) (pub
->info
);
2431 DECLARE_WAITQUEUE(wait
, current
);
2432 int timeout
= dhd_ioctl_timeout_msec
;
2434 /* Convert timeout in millsecond to jiffies */
2435 timeout
= timeout
* HZ
/ 1000;
2437 /* Wait until control frame is available */
2438 add_wait_queue(&dhd
->ioctl_resp_wait
, &wait
);
2439 set_current_state(TASK_INTERRUPTIBLE
);
2441 while (!(*condition
) && (!signal_pending(current
) && timeout
))
2442 timeout
= schedule_timeout(timeout
);
2444 if (signal_pending(current
))
2447 set_current_state(TASK_RUNNING
);
2448 remove_wait_queue(&dhd
->ioctl_resp_wait
, &wait
);
2453 int dhd_os_ioctl_resp_wake(dhd_pub_t
*pub
)
2455 dhd_info_t
*dhd
= (dhd_info_t
*) (pub
->info
);
2457 if (waitqueue_active(&dhd
->ioctl_resp_wait
))
2458 wake_up_interruptible(&dhd
->ioctl_resp_wait
);
2463 void dhd_os_wd_timer(void *bus
, uint wdtick
)
2465 dhd_pub_t
*pub
= bus
;
2466 static uint save_dhd_watchdog_ms
;
2467 dhd_info_t
*dhd
= (dhd_info_t
*) pub
->info
;
2469 /* don't start the wd until fw is loaded */
2470 if (pub
->busstate
== DHD_BUS_DOWN
)
2473 /* Totally stop the timer */
2474 if (!wdtick
&& dhd
->wd_timer_valid
== true) {
2475 del_timer_sync(&dhd
->timer
);
2476 dhd
->wd_timer_valid
= false;
2477 save_dhd_watchdog_ms
= wdtick
;
2482 dhd_watchdog_ms
= (uint
) wdtick
;
2484 if (save_dhd_watchdog_ms
!= dhd_watchdog_ms
) {
2486 if (dhd
->wd_timer_valid
== true)
2487 /* Stop timer and restart at new value */
2488 del_timer_sync(&dhd
->timer
);
2490 /* Create timer again when watchdog period is
2491 dynamically changed or in the first instance
2493 dhd
->timer
.expires
=
2494 jiffies
+ dhd_watchdog_ms
* HZ
/ 1000;
2495 add_timer(&dhd
->timer
);
2498 /* Re arm the timer, at last watchdog period */
2499 mod_timer(&dhd
->timer
,
2500 jiffies
+ dhd_watchdog_ms
* HZ
/ 1000);
2503 dhd
->wd_timer_valid
= true;
2504 save_dhd_watchdog_ms
= wdtick
;
2508 void *dhd_os_open_image(char *filename
)
2512 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2513 return wl_cfg80211_request_fw(filename
);
2515 fp
= filp_open(filename
, O_RDONLY
, 0);
2517 * 2.6.11 (FC4) supports filp_open() but later revs don't?
2519 * fp = open_namei(AT_FDCWD, filename, O_RD, 0);
2528 int dhd_os_get_image_block(char *buf
, int len
, void *image
)
2530 struct file
*fp
= (struct file
*)image
;
2533 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2534 return wl_cfg80211_read_fw(buf
, len
);
2539 rdlen
= kernel_read(fp
, fp
->f_pos
, buf
, len
);
2546 void dhd_os_close_image(void *image
)
2548 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2549 return wl_cfg80211_release_fw();
2551 filp_close((struct file
*)image
, NULL
);
2554 void dhd_os_sdlock(dhd_pub_t
*pub
)
2558 dhd
= (dhd_info_t
*) (pub
->info
);
2560 if (dhd
->threads_only
)
2563 spin_lock_bh(&dhd
->sdlock
);
2566 void dhd_os_sdunlock(dhd_pub_t
*pub
)
2570 dhd
= (dhd_info_t
*) (pub
->info
);
2572 if (dhd
->threads_only
)
2575 spin_unlock_bh(&dhd
->sdlock
);
2578 void dhd_os_sdlock_txq(dhd_pub_t
*pub
)
2582 dhd
= (dhd_info_t
*) (pub
->info
);
2583 spin_lock_bh(&dhd
->txqlock
);
2586 void dhd_os_sdunlock_txq(dhd_pub_t
*pub
)
2590 dhd
= (dhd_info_t
*) (pub
->info
);
2591 spin_unlock_bh(&dhd
->txqlock
);
2594 void dhd_os_sdlock_rxq(dhd_pub_t
*pub
)
2598 void dhd_os_sdunlock_rxq(dhd_pub_t
*pub
)
2602 void dhd_os_sdtxlock(dhd_pub_t
*pub
)
2607 void dhd_os_sdtxunlock(dhd_pub_t
*pub
)
2609 dhd_os_sdunlock(pub
);
2613 dhd_wl_host_event(dhd_info_t
*dhd
, int *ifidx
, void *pktdata
,
2614 wl_event_msg_t
*event
, void **data
)
2618 ASSERT(dhd
!= NULL
);
2620 bcmerror
= wl_host_event(dhd
, ifidx
, pktdata
, event
, data
);
2624 #if defined(CONFIG_WIRELESS_EXT)
2625 if (!IS_CFG80211_FAVORITE()) {
2626 if ((dhd
->iflist
[*ifidx
] == NULL
)
2627 || (dhd
->iflist
[*ifidx
]->net
== NULL
)) {
2628 DHD_ERROR(("%s Exit null pointer\n", __func__
));
2632 if (dhd
->iflist
[*ifidx
]->net
)
2633 wl_iw_event(dhd
->iflist
[*ifidx
]->net
, event
, *data
);
2635 #endif /* defined(CONFIG_WIRELESS_EXT) */
2637 if (IS_CFG80211_FAVORITE()) {
2638 ASSERT(dhd
->iflist
[*ifidx
] != NULL
);
2639 ASSERT(dhd
->iflist
[*ifidx
]->net
!= NULL
);
2640 if (dhd
->iflist
[*ifidx
]->net
)
2641 wl_cfg80211_event(dhd
->iflist
[*ifidx
]->net
, event
,
2648 /* send up locally generated event */
2649 void dhd_sendup_event(dhd_pub_t
*dhdp
, wl_event_msg_t
*event
, void *data
)
2651 switch (be32_to_cpu(event
->event_type
)) {
2657 void dhd_wait_for_event(dhd_pub_t
*dhd
, bool *lockvar
)
2659 struct dhd_info
*dhdinfo
= dhd
->info
;
2660 dhd_os_sdunlock(dhd
);
2661 wait_event_interruptible_timeout(dhdinfo
->ctrl_wait
,
2662 (*lockvar
== false), HZ
* 2);
2667 void dhd_wait_event_wakeup(dhd_pub_t
*dhd
)
2669 struct dhd_info
*dhdinfo
= dhd
->info
;
2670 if (waitqueue_active(&dhdinfo
->ctrl_wait
))
2671 wake_up_interruptible(&dhdinfo
->ctrl_wait
);
2675 int dhd_dev_reset(struct net_device
*dev
, u8 flag
)
2677 dhd_info_t
*dhd
= *(dhd_info_t
**)netdev_priv(dev
);
2679 /* Turning off watchdog */
2681 dhd_os_wd_timer(&dhd
->pub
, 0);
2683 dhd_bus_devreset(&dhd
->pub
, flag
);
2685 /* Turning on watchdog back */
2687 dhd_os_wd_timer(&dhd
->pub
, dhd_watchdog_ms
);
2688 DHD_ERROR(("%s: WLAN OFF DONE\n", __func__
));
2693 int net_os_set_suspend_disable(struct net_device
*dev
, int val
)
2695 dhd_info_t
*dhd
= *(dhd_info_t
**)netdev_priv(dev
);
2699 ret
= dhd
->pub
.suspend_disable_flag
;
2700 dhd
->pub
.suspend_disable_flag
= val
;
2705 int net_os_set_suspend(struct net_device
*dev
, int val
)
2708 #if defined(CONFIG_HAS_EARLYSUSPEND)
2709 dhd_info_t
*dhd
= *(dhd_info_t
**)netdev_priv(dev
);
2712 dhd_os_proto_block(&dhd
->pub
);
2713 ret
= dhd_set_suspend(val
, &dhd
->pub
);
2714 dhd_os_proto_unblock(&dhd
->pub
);
2716 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2720 int net_os_set_dtim_skip(struct net_device
*dev
, int val
)
2722 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(dev
);
2725 dhd
->pub
.dtim_skip
= val
;
2730 int net_os_set_packet_filter(struct net_device
*dev
, int val
)
2732 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(dev
);
2735 /* Packet filtering is set only if we still in early-suspend and
2736 * we need either to turn it ON or turn it OFF
2737 * We can always turn it OFF in case of early-suspend, but we turn it
2738 * back ON only if suspend_disable_flag was not set
2740 if (dhd
&& dhd
->pub
.up
) {
2741 dhd_os_proto_block(&dhd
->pub
);
2742 if (dhd
->pub
.in_suspend
) {
2743 if (!val
|| (val
&& !dhd
->pub
.suspend_disable_flag
))
2744 dhd_set_packet_filter(val
, &dhd
->pub
);
2746 dhd_os_proto_unblock(&dhd
->pub
);
2751 void dhd_dev_init_ioctl(struct net_device
*dev
)
2753 dhd_info_t
*dhd
= *(dhd_info_t
**)netdev_priv(dev
);
2755 dhd_preinit_ioctls(&dhd
->pub
);
2759 /* Linux wrapper to call common dhd_pno_clean */
2760 int dhd_dev_pno_reset(struct net_device
*dev
)
2762 dhd_info_t
*dhd
= *(dhd_info_t
**)netdev_priv(dev
);
2764 return dhd_pno_clean(&dhd
->pub
);
2767 /* Linux wrapper to call common dhd_pno_enable */
2768 int dhd_dev_pno_enable(struct net_device
*dev
, int pfn_enabled
)
2770 dhd_info_t
*dhd
= *(dhd_info_t
**)netdev_priv(dev
);
2772 return dhd_pno_enable(&dhd
->pub
, pfn_enabled
);
2775 /* Linux wrapper to call common dhd_pno_set */
2777 dhd_dev_pno_set(struct net_device
*dev
, wlc_ssid_t
*ssids_local
, int nssid
,
2778 unsigned char scan_fr
)
2780 dhd_info_t
*dhd
= *(dhd_info_t
**)netdev_priv(dev
);
2782 return dhd_pno_set(&dhd
->pub
, ssids_local
, nssid
, scan_fr
);
2785 /* Linux wrapper to get pno status */
2786 int dhd_dev_get_pno_status(struct net_device
*dev
)
2788 dhd_info_t
*dhd
= *(dhd_info_t
**)netdev_priv(dev
);
2790 return dhd_pno_get_status(&dhd
->pub
);
2793 #endif /* PNO_SUPPORT */
2795 static int dhd_get_pend_8021x_cnt(dhd_info_t
*dhd
)
2797 return atomic_read(&dhd
->pend_8021x_cnt
);
2800 #define MAX_WAIT_FOR_8021X_TX 10
2802 int dhd_wait_pend8021x(struct net_device
*dev
)
2804 dhd_info_t
*dhd
= *(dhd_info_t
**)netdev_priv(dev
);
2805 int timeout
= 10 * HZ
/ 1000;
2806 int ntimes
= MAX_WAIT_FOR_8021X_TX
;
2807 int pend
= dhd_get_pend_8021x_cnt(dhd
);
2809 while (ntimes
&& pend
) {
2811 set_current_state(TASK_INTERRUPTIBLE
);
2812 schedule_timeout(timeout
);
2813 set_current_state(TASK_RUNNING
);
2816 pend
= dhd_get_pend_8021x_cnt(dhd
);
2821 void wl_os_wd_timer(struct net_device
*ndev
, uint wdtick
)
2823 dhd_info_t
*dhd
= *(dhd_info_t
**)netdev_priv(ndev
);
2825 dhd_os_wd_timer(&dhd
->pub
, wdtick
);
2829 int write_to_file(dhd_pub_t
*dhd
, u8
*buf
, int size
)
2833 mm_segment_t old_fs
;
2836 /* change to KERNEL_DS address limit */
2840 /* open file to write */
2841 fp
= filp_open("/tmp/mem_dump", O_WRONLY
| O_CREAT
, 0640);
2843 DHD_ERROR(("%s: open file error\n", __func__
));
2848 /* Write buf to file */
2849 fp
->f_op
->write(fp
, buf
, size
, &pos
);
2852 /* free buf before return */
2854 /* close file before return */
2856 filp_close(fp
, current
->files
);
2857 /* restore previous address limit */
2862 #endif /* DHD_DEBUG */