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>
34 #include <net/cfg80211.h>
36 #include <brcmu_utils.h>
37 #include <brcmu_wifi.h>
39 #include "dngl_stats.h"
42 #include "dhd_proto.h"
44 #include "wl_cfg80211.h"
46 #define EPI_VERSION_STR "4.218.248.5"
47 #define ETH_P_BRCM 0x886c
49 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
50 #include <linux/wifi_tiwlan.h>
52 struct semaphore wifi_control_sem
;
54 struct dhd_bus
*g_bus
;
56 static struct wifi_platform_data
*wifi_control_data
;
57 static struct resource
*wifi_irqres
;
59 int wifi_get_irq_number(unsigned long *irq_flags_ptr
)
62 *irq_flags_ptr
= wifi_irqres
->flags
& IRQF_TRIGGER_MASK
;
63 return (int)wifi_irqres
->start
;
65 #ifdef CUSTOM_OOB_GPIO_NUM
66 return CUSTOM_OOB_GPIO_NUM
;
72 int wifi_set_carddetect(int on
)
74 printk(KERN_ERR
"%s = %d\n", __func__
, on
);
75 if (wifi_control_data
&& wifi_control_data
->set_carddetect
)
76 wifi_control_data
->set_carddetect(on
);
80 int wifi_set_power(int on
, unsigned long msec
)
82 printk(KERN_ERR
"%s = %d\n", __func__
, on
);
83 if (wifi_control_data
&& wifi_control_data
->set_power
)
84 wifi_control_data
->set_power(on
);
90 int wifi_set_reset(int on
, unsigned long msec
)
92 printk(KERN_ERR
"%s = %d\n", __func__
, on
);
93 if (wifi_control_data
&& wifi_control_data
->set_reset
)
94 wifi_control_data
->set_reset(on
);
100 static int wifi_probe(struct platform_device
*pdev
)
102 struct wifi_platform_data
*wifi_ctrl
=
103 (struct wifi_platform_data
*)(pdev
->dev
.platform_data
);
105 printk(KERN_ERR
"## %s\n", __func__
);
107 platform_get_resource_byname(pdev
, IORESOURCE_IRQ
,
109 wifi_control_data
= wifi_ctrl
;
111 wifi_set_power(1, 0); /* Power On */
112 wifi_set_carddetect(1); /* CardDetect (0->1) */
114 up(&wifi_control_sem
);
118 static int wifi_remove(struct platform_device
*pdev
)
120 struct wifi_platform_data
*wifi_ctrl
=
121 (struct wifi_platform_data
*)(pdev
->dev
.platform_data
);
123 printk(KERN_ERR
"## %s\n", __func__
);
124 wifi_control_data
= wifi_ctrl
;
126 wifi_set_carddetect(0); /* CardDetect (1->0) */
127 wifi_set_power(0, 0); /* Power Off */
129 up(&wifi_control_sem
);
133 static int wifi_suspend(struct platform_device
*pdev
, pm_message_t state
)
135 DHD_TRACE(("##> %s\n", __func__
));
139 static int wifi_resume(struct platform_device
*pdev
)
141 DHD_TRACE(("##> %s\n", __func__
));
145 static struct platform_driver wifi_device
= {
147 .remove
= wifi_remove
,
148 .suspend
= wifi_suspend
,
149 .resume
= wifi_resume
,
151 .name
= KBUILD_MODNAME
,
155 int wifi_add_dev(void)
157 DHD_TRACE(("## Calling platform_driver_register\n"));
158 return platform_driver_register(&wifi_device
);
161 void wifi_del_dev(void)
163 DHD_TRACE(("## Unregister platform_driver_register\n"));
164 platform_driver_unregister(&wifi_device
);
166 #endif /* defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
168 #if defined(CONFIG_PM_SLEEP)
169 #include <linux/suspend.h>
170 atomic_t dhd_mmc_suspend
;
171 DECLARE_WAIT_QUEUE_HEAD(dhd_dpc_wait
);
172 #endif /* defined(CONFIG_PM_SLEEP) */
174 #if defined(OOB_INTR_ONLY)
175 extern void dhd_enable_oob_intr(struct dhd_bus
*bus
, bool enable
);
176 #endif /* defined(OOB_INTR_ONLY) */
178 MODULE_AUTHOR("Broadcom Corporation");
179 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN fullmac driver.");
180 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN fullmac cards");
181 MODULE_LICENSE("Dual BSD/GPL");
183 #define DRV_MODULE_NAME "brcmfmac"
185 /* Linux wireless extension support */
186 #if defined(CONFIG_WIRELESS_EXT)
188 extern wl_iw_extra_params_t g_wl_iw_params
;
189 #endif /* defined(CONFIG_WIRELESS_EXT) */
191 #if defined(CONFIG_HAS_EARLYSUSPEND)
192 #include <linux/earlysuspend.h>
193 extern int dhdcdc_set_ioctl(dhd_pub_t
*dhd
, int ifidx
, uint cmd
, void *buf
,
195 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
197 #ifdef PKT_FILTER_SUPPORT
198 extern void dhd_pktfilter_offload_set(dhd_pub_t
*dhd
, char *arg
);
199 extern void dhd_pktfilter_offload_enable(dhd_pub_t
*dhd
, char *arg
, int enable
,
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 int state
; /* interface state */
211 uint subunit
; /* subunit */
212 u8 mac_addr
[ETH_ALEN
]; /* assigned MAC address */
213 bool attached
; /* Delayed attachment when unset */
214 bool txflowcontrol
; /* Per interface flow control indicator */
215 char name
[IFNAMSIZ
]; /* linux interface name */
218 /* Local private structure (extension of pub) */
219 typedef struct dhd_info
{
220 #if defined(CONFIG_WIRELESS_EXT)
221 wl_iw_t iw
; /* wireless extensions state (must be first) */
222 #endif /* defined(CONFIG_WIRELESS_EXT) */
226 /* OS/stack specifics */
227 dhd_if_t
*iflist
[DHD_MAX_IFS
];
229 struct semaphore proto_sem
;
230 wait_queue_head_t ioctl_resp_wait
;
231 struct timer_list timer
;
233 struct tasklet_struct tasklet
;
236 /* Thread based operation */
238 struct semaphore sdsem
;
239 struct task_struct
*watchdog_tsk
;
240 struct semaphore watchdog_sem
;
241 struct task_struct
*dpc_tsk
;
242 struct semaphore dpc_sem
;
244 /* Thread to issue ioctl for multicast */
245 struct task_struct
*sysioc_tsk
;
246 struct semaphore sysioc_sem
;
249 u8 macvalue
[ETH_ALEN
];
250 wait_queue_head_t ctrl_wait
;
251 atomic_t pend_8021x_cnt
;
253 #ifdef CONFIG_HAS_EARLYSUSPEND
254 struct early_suspend early_suspend
;
255 #endif /* CONFIG_HAS_EARLYSUSPEND */
258 /* Definitions to provide path to the firmware and nvram
259 * example nvram_path[MOD_PARAM_PATHLEN]="/projects/wlan/nvram.txt"
261 char firmware_path
[MOD_PARAM_PATHLEN
];
262 char nvram_path
[MOD_PARAM_PATHLEN
];
264 /* load firmware and/or nvram values from the filesystem */
265 module_param_string(firmware_path
, firmware_path
, MOD_PARAM_PATHLEN
, 0);
266 module_param_string(nvram_path
, nvram_path
, MOD_PARAM_PATHLEN
, 0);
269 module_param(dhd_msg_level
, int, 0);
271 /* Spawn a thread for system ioctls (set mac, set mcast) */
272 uint dhd_sysioc
= true;
273 module_param(dhd_sysioc
, uint
, 0);
275 /* Watchdog interval */
276 uint dhd_watchdog_ms
= 10;
277 module_param(dhd_watchdog_ms
, uint
, 0);
280 /* Console poll interval */
282 module_param(dhd_console_ms
, uint
, 0);
283 #endif /* DHD_DEBUG */
285 /* ARP offload agent mode : Enable ARP Host Auto-Reply
286 and ARP Peer Auto-Reply */
287 uint dhd_arp_mode
= 0xb;
288 module_param(dhd_arp_mode
, uint
, 0);
290 /* ARP offload enable */
291 uint dhd_arp_enable
= true;
292 module_param(dhd_arp_enable
, uint
, 0);
294 /* Global Pkt filter enable control */
295 uint dhd_pkt_filter_enable
= true;
296 module_param(dhd_pkt_filter_enable
, uint
, 0);
298 /* Pkt filter init setup */
299 uint dhd_pkt_filter_init
;
300 module_param(dhd_pkt_filter_init
, uint
, 0);
302 /* Pkt filter mode control */
303 uint dhd_master_mode
= true;
304 module_param(dhd_master_mode
, uint
, 1);
306 /* Watchdog thread priority, -1 to use kernel timer */
307 int dhd_watchdog_prio
= 97;
308 module_param(dhd_watchdog_prio
, int, 0);
310 /* DPC thread priority, -1 to use tasklet */
311 int dhd_dpc_prio
= 98;
312 module_param(dhd_dpc_prio
, int, 0);
314 /* DPC thread priority, -1 to use tasklet */
315 extern int dhd_dongle_memsize
;
316 module_param(dhd_dongle_memsize
, int, 0);
318 /* Contorl fw roaming */
325 /* Control radio state */
326 uint dhd_radio_up
= 1;
328 /* Network inteface name */
329 char iface_name
[IFNAMSIZ
] = "wlan";
330 module_param_string(iface_name
, iface_name
, IFNAMSIZ
, 0);
332 /* The following are specific to the SDIO dongle */
334 /* IOCTL response timeout */
335 int dhd_ioctl_timeout_msec
= IOCTL_RESP_TIMEOUT
;
337 /* Idle timeout for backplane clock */
338 int dhd_idletime
= DHD_IDLETIME_TICKS
;
339 module_param(dhd_idletime
, int, 0);
343 module_param(dhd_poll
, uint
, 0);
346 uint dhd_cfg80211
= true;
347 module_param(dhd_cfg80211
, uint
, 0);
350 uint dhd_intr
= true;
351 module_param(dhd_intr
, uint
, 0);
353 /* SDIO Drive Strength (in milliamps) */
354 uint dhd_sdiod_drive_strength
= 6;
355 module_param(dhd_sdiod_drive_strength
, uint
, 0);
358 extern uint dhd_txbound
;
359 extern uint dhd_rxbound
;
360 module_param(dhd_txbound
, uint
, 0);
361 module_param(dhd_rxbound
, uint
, 0);
363 /* Deferred transmits */
364 extern uint dhd_deferred_tx
;
365 module_param(dhd_deferred_tx
, uint
, 0);
368 /* Echo packet generator (pkts/s) */
370 module_param(dhd_pktgen
, uint
, 0);
372 /* Echo packet len (0 => sawtooth, max 2040) */
374 module_param(dhd_pktgen_len
, uint
, 0);
377 #define FAVORITE_WIFI_CP (!!dhd_cfg80211)
378 #define IS_CFG80211_FAVORITE() FAVORITE_WIFI_CP
379 #define DBG_CFG80211_GET() ((dhd_cfg80211 & WL_DBG_MASK) >> 1)
380 #define NO_FW_REQ() (dhd_cfg80211 & 0x80)
382 /* Version string to report */
384 #define DHD_COMPILED "\nCompiled in " SRCBASE
389 static void dhd_dpc(unsigned long data
);
391 extern int dhd_wait_pend8021x(struct net_device
*dev
);
395 #error TOE requires BDC
397 static int dhd_toe_get(dhd_info_t
*dhd
, int idx
, u32
*toe_ol
);
398 static int dhd_toe_set(dhd_info_t
*dhd
, int idx
, u32 toe_ol
);
401 static int dhd_wl_host_event(dhd_info_t
*dhd
, int *ifidx
, void *pktdata
,
402 wl_event_msg_t
*event_ptr
, void **data_ptr
);
404 #if defined(CONFIG_PM_SLEEP)
405 static int dhd_sleep_pm_callback(struct notifier_block
*nfb
,
406 unsigned long action
, void *ignored
)
409 case PM_HIBERNATION_PREPARE
:
410 case PM_SUSPEND_PREPARE
:
411 atomic_set(&dhd_mmc_suspend
, true);
413 case PM_POST_HIBERNATION
:
414 case PM_POST_SUSPEND
:
415 atomic_set(&dhd_mmc_suspend
, false);
421 static struct notifier_block dhd_sleep_pm_notifier
= {
422 .notifier_call
= dhd_sleep_pm_callback
,
426 extern int register_pm_notifier(struct notifier_block
*nb
);
427 extern int unregister_pm_notifier(struct notifier_block
*nb
);
428 #endif /* defined(CONFIG_PM_SLEEP) */
429 /* && defined(DHD_GPL) */
430 static void dhd_set_packet_filter(int value
, dhd_pub_t
*dhd
)
432 #ifdef PKT_FILTER_SUPPORT
433 DHD_TRACE(("%s: %d\n", __func__
, value
));
434 /* 1 - Enable packet filter, only allow unicast packet to send up */
435 /* 0 - Disable packet filter */
436 if (dhd_pkt_filter_enable
) {
439 for (i
= 0; i
< dhd
->pktfilter_count
; i
++) {
440 dhd_pktfilter_offload_set(dhd
, dhd
->pktfilter
[i
]);
441 dhd_pktfilter_offload_enable(dhd
, dhd
->pktfilter
[i
],
442 value
, dhd_master_mode
);
448 #if defined(CONFIG_HAS_EARLYSUSPEND)
449 static int dhd_set_suspend(int value
, dhd_pub_t
*dhd
)
451 int power_mode
= PM_MAX
;
452 /* wl_pkt_filter_enable_t enable_parm; */
457 #endif /* CUSTOMER_HW2 */
459 DHD_TRACE(("%s: enter, value = %d in_suspend=%d\n",
460 __func__
, value
, dhd
->in_suspend
));
462 if (dhd
&& dhd
->up
) {
463 if (value
&& dhd
->in_suspend
) {
465 /* Kernel suspended */
466 DHD_TRACE(("%s: force extra Suspend setting\n",
469 dhdcdc_set_ioctl(dhd
, 0, WLC_SET_PM
,
473 /* Enable packet filter, only allow unicast
475 dhd_set_packet_filter(1, dhd
);
477 /* if dtim skip setup as default force it
478 * to wake each third dtim
479 * for better power saving.
480 * Note that side effect is chance to miss BC/MC
483 if ((dhd
->dtim_skip
== 0) || (dhd
->dtim_skip
== 1))
486 bcn_li_dtim
= dhd
->dtim_skip
;
487 brcmu_mkiovar("bcn_li_dtim", (char *)&bcn_li_dtim
,
488 4, iovbuf
, sizeof(iovbuf
));
489 dhdcdc_set_ioctl(dhd
, 0, WLC_SET_VAR
, iovbuf
,
492 /* Disable build-in roaming to allowed \
493 * supplicant to take of romaing
495 brcmu_mkiovar("roam_off", (char *)&roamvar
, 4,
496 iovbuf
, sizeof(iovbuf
));
497 dhdcdc_set_ioctl(dhd
, 0, WLC_SET_VAR
, iovbuf
,
499 #endif /* CUSTOMER_HW2 */
503 DHD_TRACE(("%s: Remove extra suspend setting\n",
506 power_mode
= PM_FAST
;
507 dhdcdc_set_ioctl(dhd
, 0, WLC_SET_PM
,
511 /* disable pkt filter */
512 dhd_set_packet_filter(0, dhd
);
514 /* restore pre-suspend setting for dtim_skip */
515 brcmu_mkiovar("bcn_li_dtim", (char *)&dhd
->dtim_skip
,
516 4, iovbuf
, sizeof(iovbuf
));
518 dhdcdc_set_ioctl(dhd
, 0, WLC_SET_VAR
, iovbuf
,
522 brcmu_mkiovar("roam_off", (char *)&roamvar
, 4, iovbuf
,
524 dhdcdc_set_ioctl(dhd
, 0, WLC_SET_VAR
, iovbuf
,
526 #endif /* CUSTOMER_HW2 */
533 static void dhd_suspend_resume_helper(struct dhd_info
*dhd
, int val
)
535 dhd_pub_t
*dhdp
= &dhd
->pub
;
537 dhd_os_proto_block(dhdp
);
538 /* Set flag when early suspend was called */
539 dhdp
->in_suspend
= val
;
540 if (!dhdp
->suspend_disable_flag
)
541 dhd_set_suspend(val
, dhdp
);
542 dhd_os_proto_unblock(dhdp
);
545 static void dhd_early_suspend(struct early_suspend
*h
)
547 struct dhd_info
*dhd
= container_of(h
, struct dhd_info
, early_suspend
);
549 DHD_TRACE(("%s: enter\n", __func__
));
552 dhd_suspend_resume_helper(dhd
, 1);
556 static void dhd_late_resume(struct early_suspend
*h
)
558 struct dhd_info
*dhd
= container_of(h
, struct dhd_info
, early_suspend
);
560 DHD_TRACE(("%s: enter\n", __func__
));
563 dhd_suspend_resume_helper(dhd
, 0);
565 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
568 * Generalized timeout mechanism. Uses spin sleep with exponential
570 * the sleep time reaches one jiffy, then switches over to task delay. Usage:
572 * dhd_timeout_start(&tmo, usec);
573 * while (!dhd_timeout_expired(&tmo))
574 * if (poll_something())
576 * if (dhd_timeout_expired(&tmo))
580 void dhd_timeout_start(dhd_timeout_t
*tmo
, uint usec
)
585 tmo
->tick
= 1000000 / HZ
;
588 int dhd_timeout_expired(dhd_timeout_t
*tmo
)
590 /* Does nothing the first call */
591 if (tmo
->increment
== 0) {
596 if (tmo
->elapsed
>= tmo
->limit
)
599 /* Add the delay that's about to take place */
600 tmo
->elapsed
+= tmo
->increment
;
602 if (tmo
->increment
< tmo
->tick
) {
603 udelay(tmo
->increment
);
605 if (tmo
->increment
> tmo
->tick
)
606 tmo
->increment
= tmo
->tick
;
608 wait_queue_head_t delay_wait
;
609 DECLARE_WAITQUEUE(wait
, current
);
611 init_waitqueue_head(&delay_wait
);
612 add_wait_queue(&delay_wait
, &wait
);
613 set_current_state(TASK_INTERRUPTIBLE
);
615 pending
= signal_pending(current
);
616 remove_wait_queue(&delay_wait
, &wait
);
617 set_current_state(TASK_RUNNING
);
619 return 1; /* Interrupted */
625 static int dhd_net2idx(dhd_info_t
*dhd
, struct net_device
*net
)
630 while (i
< DHD_MAX_IFS
) {
631 if (dhd
->iflist
[i
] && (dhd
->iflist
[i
]->net
== net
))
639 int dhd_ifname2idx(dhd_info_t
*dhd
, char *name
)
645 if (name
== NULL
|| *name
== '\0')
650 && !strncmp(dhd
->iflist
[i
]->name
, name
, IFNAMSIZ
))
653 DHD_TRACE(("%s: return idx %d for \"%s\"\n", __func__
, i
, name
));
655 return i
; /* default - the primary interface */
658 char *dhd_ifname(dhd_pub_t
*dhdp
, int ifidx
)
660 dhd_info_t
*dhd
= (dhd_info_t
*) dhdp
->info
;
664 if (ifidx
< 0 || ifidx
>= DHD_MAX_IFS
) {
665 DHD_ERROR(("%s: ifidx %d out of range\n", __func__
, ifidx
));
669 if (dhd
->iflist
[ifidx
] == NULL
) {
670 DHD_ERROR(("%s: null i/f %d\n", __func__
, ifidx
));
674 if (dhd
->iflist
[ifidx
]->net
)
675 return dhd
->iflist
[ifidx
]->net
->name
;
680 static void _dhd_set_multicast_list(dhd_info_t
*dhd
, int ifidx
)
682 struct net_device
*dev
;
683 struct netdev_hw_addr
*ha
;
691 ASSERT(dhd
&& dhd
->iflist
[ifidx
]);
692 dev
= dhd
->iflist
[ifidx
]->net
;
693 cnt
= netdev_mc_count(dev
);
695 /* Determine initial value of allmulti flag */
696 allmulti
= (dev
->flags
& IFF_ALLMULTI
) ? true : false;
698 /* Send down the multicast list first. */
700 buflen
= sizeof("mcast_list") + sizeof(cnt
) + (cnt
* ETH_ALEN
);
701 bufp
= buf
= kmalloc(buflen
, GFP_ATOMIC
);
703 DHD_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
704 dhd_ifname(&dhd
->pub
, ifidx
), cnt
));
708 strcpy(bufp
, "mcast_list");
709 bufp
+= strlen("mcast_list") + 1;
711 cnt
= cpu_to_le32(cnt
);
712 memcpy(bufp
, &cnt
, sizeof(cnt
));
715 netdev_for_each_mc_addr(ha
, dev
) {
718 memcpy(bufp
, ha
->addr
, ETH_ALEN
);
723 memset(&ioc
, 0, sizeof(ioc
));
724 ioc
.cmd
= WLC_SET_VAR
;
729 ret
= dhd_prot_ioctl(&dhd
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
731 DHD_ERROR(("%s: set mcast_list failed, cnt %d\n",
732 dhd_ifname(&dhd
->pub
, ifidx
), cnt
));
733 allmulti
= cnt
? true : allmulti
;
738 /* Now send the allmulti setting. This is based on the setting in the
739 * net_device flags, but might be modified above to be turned on if we
740 * were trying to set some addresses and dongle rejected it...
743 buflen
= sizeof("allmulti") + sizeof(allmulti
);
744 buf
= kmalloc(buflen
, GFP_ATOMIC
);
746 DHD_ERROR(("%s: out of memory for allmulti\n",
747 dhd_ifname(&dhd
->pub
, ifidx
)));
750 allmulti
= cpu_to_le32(allmulti
);
753 ("allmulti", (void *)&allmulti
, sizeof(allmulti
), buf
, buflen
)) {
754 DHD_ERROR(("%s: mkiovar failed for allmulti, datalen %d "
755 "buflen %u\n", dhd_ifname(&dhd
->pub
, ifidx
),
756 (int)sizeof(allmulti
), buflen
));
761 memset(&ioc
, 0, sizeof(ioc
));
762 ioc
.cmd
= WLC_SET_VAR
;
767 ret
= dhd_prot_ioctl(&dhd
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
769 DHD_ERROR(("%s: set allmulti %d failed\n",
770 dhd_ifname(&dhd
->pub
, ifidx
),
771 le32_to_cpu(allmulti
)));
776 /* Finally, pick up the PROMISC flag as well, like the NIC
779 allmulti
= (dev
->flags
& IFF_PROMISC
) ? true : false;
780 allmulti
= cpu_to_le32(allmulti
);
782 memset(&ioc
, 0, sizeof(ioc
));
783 ioc
.cmd
= WLC_SET_PROMISC
;
785 ioc
.len
= sizeof(allmulti
);
788 ret
= dhd_prot_ioctl(&dhd
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
790 DHD_ERROR(("%s: set promisc %d failed\n",
791 dhd_ifname(&dhd
->pub
, ifidx
),
792 le32_to_cpu(allmulti
)));
797 _dhd_set_mac_address(dhd_info_t
*dhd
, int ifidx
, u8
*addr
)
803 DHD_TRACE(("%s enter\n", __func__
));
805 ("cur_etheraddr", (char *)addr
, ETH_ALEN
, buf
, 32)) {
806 DHD_ERROR(("%s: mkiovar failed for cur_etheraddr\n",
807 dhd_ifname(&dhd
->pub
, ifidx
)));
810 memset(&ioc
, 0, sizeof(ioc
));
811 ioc
.cmd
= WLC_SET_VAR
;
816 ret
= dhd_prot_ioctl(&dhd
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
818 DHD_ERROR(("%s: set cur_etheraddr failed\n",
819 dhd_ifname(&dhd
->pub
, ifidx
)));
821 memcpy(dhd
->iflist
[ifidx
]->net
->dev_addr
, addr
, ETH_ALEN
);
828 extern struct net_device
*ap_net_dev
;
831 static void dhd_op_if(dhd_if_t
*ifp
)
834 int ret
= 0, err
= 0;
836 ASSERT(ifp
&& ifp
->info
&& ifp
->idx
); /* Virtual interfaces only */
840 DHD_TRACE(("%s: idx %d, state %d\n", __func__
, ifp
->idx
, ifp
->state
));
842 switch (ifp
->state
) {
845 * Delete the existing interface before overwriting it
846 * in case we missed the WLC_E_IF_DEL event.
848 if (ifp
->net
!= NULL
) {
849 DHD_ERROR(("%s: ERROR: netdev:%s already exists, "
850 "try free & unregister\n",
851 __func__
, ifp
->net
->name
));
852 netif_stop_queue(ifp
->net
);
853 unregister_netdev(ifp
->net
);
854 free_netdev(ifp
->net
);
856 /* Allocate etherdev, including space for private structure */
857 ifp
->net
= alloc_etherdev(sizeof(dhd
));
859 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__
));
863 strcpy(ifp
->net
->name
, ifp
->name
);
864 memcpy(netdev_priv(ifp
->net
), &dhd
, sizeof(dhd
));
865 err
= dhd_net_attach(&dhd
->pub
, ifp
->idx
);
867 DHD_ERROR(("%s: dhd_net_attach failed, "
873 /* semaphore that the soft AP CODE
875 extern struct semaphore ap_eth_sema
;
877 /* save ptr to wl0.1 netdev for use
879 ap_net_dev
= ifp
->net
;
880 /* signal to the SOFTAP 'sleeper' thread,
884 DHD_TRACE(("\n ==== pid:%x, net_device for "
885 "if:%s created ===\n\n",
886 current
->pid
, ifp
->net
->name
));
892 if (ifp
->net
!= NULL
) {
893 DHD_TRACE(("\n%s: got 'WLC_E_IF_DEL' state\n",
895 netif_stop_queue(ifp
->net
);
896 unregister_netdev(ifp
->net
);
897 ret
= DHD_DEL_IF
; /* Make sure the free_netdev()
902 DHD_ERROR(("%s: bad op %d\n", __func__
, ifp
->state
));
909 free_netdev(ifp
->net
);
911 dhd
->iflist
[ifp
->idx
] = NULL
;
914 if (ifp
->net
== ap_net_dev
)
915 ap_net_dev
= NULL
; /* NULL SOFTAP global
921 static int _dhd_sysioc_thread(void *data
)
923 dhd_info_t
*dhd
= (dhd_info_t
*) data
;
929 allow_signal(SIGTERM
);
931 while (down_interruptible(&dhd
->sysioc_sem
) == 0) {
932 if (kthread_should_stop())
934 for (i
= 0; i
< DHD_MAX_IFS
; i
++) {
935 if (dhd
->iflist
[i
]) {
937 in_ap
= (ap_net_dev
!= NULL
);
939 if (dhd
->iflist
[i
]->state
)
940 dhd_op_if(dhd
->iflist
[i
]);
942 if (dhd
->iflist
[i
] == NULL
) {
943 DHD_TRACE(("\n\n %s: interface %d "
944 "removed!\n", __func__
, i
));
948 if (in_ap
&& dhd
->set_macaddress
) {
949 DHD_TRACE(("attempt to set MAC for %s "
950 "in AP Mode," "blocked. \n",
951 dhd
->iflist
[i
]->net
->name
));
952 dhd
->set_macaddress
= false;
956 if (in_ap
&& dhd
->set_multicast
) {
957 DHD_TRACE(("attempt to set MULTICAST list for %s" "in AP Mode, blocked. \n",
958 dhd
->iflist
[i
]->net
->name
));
959 dhd
->set_multicast
= false;
963 if (dhd
->set_multicast
) {
964 dhd
->set_multicast
= false;
965 _dhd_set_multicast_list(dhd
, i
);
967 if (dhd
->set_macaddress
) {
968 dhd
->set_macaddress
= false;
969 _dhd_set_mac_address(dhd
, i
,
978 static int dhd_set_mac_address(struct net_device
*dev
, void *addr
)
982 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(dev
);
983 struct sockaddr
*sa
= (struct sockaddr
*)addr
;
986 ifidx
= dhd_net2idx(dhd
, dev
);
987 if (ifidx
== DHD_BAD_IF
)
990 ASSERT(dhd
->sysioc_tsk
);
991 memcpy(&dhd
->macvalue
, sa
->sa_data
, ETH_ALEN
);
992 dhd
->set_macaddress
= true;
993 up(&dhd
->sysioc_sem
);
998 static void dhd_set_multicast_list(struct net_device
*dev
)
1000 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(dev
);
1003 ifidx
= dhd_net2idx(dhd
, dev
);
1004 if (ifidx
== DHD_BAD_IF
)
1007 ASSERT(dhd
->sysioc_tsk
);
1008 dhd
->set_multicast
= true;
1009 up(&dhd
->sysioc_sem
);
1012 int dhd_sendpkt(dhd_pub_t
*dhdp
, int ifidx
, struct sk_buff
*pktbuf
)
1015 dhd_info_t
*dhd
= (dhd_info_t
*) (dhdp
->info
);
1017 /* Reject if down */
1018 if (!dhdp
->up
|| (dhdp
->busstate
== DHD_BUS_DOWN
))
1021 /* Update multicast statistic */
1022 if (pktbuf
->len
>= ETH_ALEN
) {
1023 u8
*pktdata
= (u8
*) (pktbuf
->data
);
1024 struct ethhdr
*eh
= (struct ethhdr
*)pktdata
;
1026 if (is_multicast_ether_addr(eh
->h_dest
))
1027 dhdp
->tx_multicast
++;
1028 if (ntohs(eh
->h_proto
) == ETH_P_PAE
)
1029 atomic_inc(&dhd
->pend_8021x_cnt
);
1032 /* If the protocol uses a data header, apply it */
1033 dhd_prot_hdrpush(dhdp
, ifidx
, pktbuf
);
1035 /* Use bus module to send data frame */
1037 ret
= dbus_send_pkt(dhdp
->dbus
, pktbuf
, NULL
/* pktinfo */);
1039 ret
= dhd_bus_txdata(dhdp
->bus
, pktbuf
);
1040 #endif /* BCMDBUS */
1045 static inline void *
1046 osl_pkt_frmnative(struct sk_buff
*skb
)
1050 #define PKTFRMNATIVE(osh, skb) \
1051 osl_pkt_frmnative((struct sk_buff *)(skb))
1053 static inline struct sk_buff
*
1054 osl_pkt_tonative(void *pkt
)
1056 return (struct sk_buff
*)pkt
;
1058 #define PKTTONATIVE(osh, pkt) \
1059 osl_pkt_tonative((pkt))
1061 static int dhd_start_xmit(struct sk_buff
*skb
, struct net_device
*net
)
1065 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(net
);
1068 DHD_TRACE(("%s: Enter\n", __func__
));
1070 /* Reject if down */
1071 if (!dhd
->pub
.up
|| (dhd
->pub
.busstate
== DHD_BUS_DOWN
)) {
1072 DHD_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n",
1073 __func__
, dhd
->pub
.up
, dhd
->pub
.busstate
));
1074 netif_stop_queue(net
);
1078 ifidx
= dhd_net2idx(dhd
, net
);
1079 if (ifidx
== DHD_BAD_IF
) {
1080 DHD_ERROR(("%s: bad ifidx %d\n", __func__
, ifidx
));
1081 netif_stop_queue(net
);
1085 /* Make sure there's enough room for any header */
1086 if (skb_headroom(skb
) < dhd
->pub
.hdrlen
) {
1087 struct sk_buff
*skb2
;
1089 DHD_INFO(("%s: insufficient headroom\n",
1090 dhd_ifname(&dhd
->pub
, ifidx
)));
1091 dhd
->pub
.tx_realloc
++;
1092 skb2
= skb_realloc_headroom(skb
, dhd
->pub
.hdrlen
);
1096 DHD_ERROR(("%s: skb_realloc_headroom failed\n",
1097 dhd_ifname(&dhd
->pub
, ifidx
)));
1103 /* Convert to packet */
1104 pktbuf
= PKTFRMNATIVE(dhd
->pub
.osh
, skb
);
1106 DHD_ERROR(("%s: PKTFRMNATIVE failed\n",
1107 dhd_ifname(&dhd
->pub
, ifidx
)));
1108 dev_kfree_skb_any(skb
);
1113 ret
= dhd_sendpkt(&dhd
->pub
, ifidx
, pktbuf
);
1117 dhd
->pub
.dstats
.tx_dropped
++;
1119 dhd
->pub
.tx_packets
++;
1121 /* Return ok: we always eat the packet */
1125 void dhd_txflowcontrol(dhd_pub_t
*dhdp
, int ifidx
, bool state
)
1127 struct net_device
*net
;
1128 dhd_info_t
*dhd
= dhdp
->info
;
1130 DHD_TRACE(("%s: Enter\n", __func__
));
1132 dhdp
->txoff
= state
;
1133 ASSERT(dhd
&& dhd
->iflist
[ifidx
]);
1134 net
= dhd
->iflist
[ifidx
]->net
;
1136 netif_stop_queue(net
);
1138 netif_wake_queue(net
);
1141 void dhd_rx_frame(dhd_pub_t
*dhdp
, int ifidx
, struct sk_buff
*pktbuf
,
1144 dhd_info_t
*dhd
= (dhd_info_t
*) dhdp
->info
;
1145 struct sk_buff
*skb
;
1149 struct sk_buff
*pnext
, *save_pktbuf
;
1152 wl_event_msg_t event
;
1154 DHD_TRACE(("%s: Enter\n", __func__
));
1156 save_pktbuf
= pktbuf
;
1158 for (i
= 0; pktbuf
&& i
< numpkt
; i
++, pktbuf
= pnext
) {
1160 pnext
= pktbuf
->next
;
1161 pktbuf
->next
= NULL
;
1163 skb
= PKTTONATIVE(dhdp
->osh
, pktbuf
);
1165 /* Get the protocol, maintain skb around eth_type_trans()
1166 * The main reason for this hack is for the limitation of
1167 * Linux 2.4 where 'eth_type_trans' uses the
1168 * 'net->hard_header_len'
1169 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
1170 * coping of the packet coming from the network stack to add
1171 * BDC, Hardware header etc, during network interface
1173 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
1175 * for BDC, Hardware header etc. and not just the ETH_HLEN
1180 ifp
= dhd
->iflist
[ifidx
];
1182 ifp
= dhd
->iflist
[0];
1185 skb
->dev
= ifp
->net
;
1186 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
1188 if (skb
->pkt_type
== PACKET_MULTICAST
)
1189 dhd
->pub
.rx_multicast
++;
1194 /* Strip header, count, deliver upward */
1195 skb_pull(skb
, ETH_HLEN
);
1197 /* Process special event packets and then discard them */
1198 if (ntohs(skb
->protocol
) == ETH_P_BRCM
)
1199 dhd_wl_host_event(dhd
, &ifidx
,
1200 skb_mac_header(skb
),
1203 ASSERT(ifidx
< DHD_MAX_IFS
&& dhd
->iflist
[ifidx
]);
1204 if (dhd
->iflist
[ifidx
] && !dhd
->iflist
[ifidx
]->state
)
1205 ifp
= dhd
->iflist
[ifidx
];
1208 ifp
->net
->last_rx
= jiffies
;
1210 dhdp
->dstats
.rx_bytes
+= skb
->len
;
1211 dhdp
->rx_packets
++; /* Local count */
1213 if (in_interrupt()) {
1216 /* If the receive is not processed inside an ISR,
1217 * the softirqd must be woken explicitly to service
1218 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
1219 * by netif_rx_ni(), but in earlier kernels, we need
1220 * to do it manually.
1227 void dhd_event(struct dhd_info
*dhd
, char *evpkt
, int evlen
, int ifidx
)
1229 /* Linux version has nothing to do */
1233 void dhd_txcomplete(dhd_pub_t
*dhdp
, struct sk_buff
*txp
, bool success
)
1236 dhd_info_t
*dhd
= (dhd_info_t
*) (dhdp
->info
);
1240 dhd_prot_hdrpull(dhdp
, &ifidx
, txp
);
1242 eh
= (struct ethhdr
*)(txp
->data
);
1243 type
= ntohs(eh
->h_proto
);
1245 if (type
== ETH_P_PAE
)
1246 atomic_dec(&dhd
->pend_8021x_cnt
);
1250 static struct net_device_stats
*dhd_get_stats(struct net_device
*net
)
1252 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(net
);
1256 DHD_TRACE(("%s: Enter\n", __func__
));
1258 ifidx
= dhd_net2idx(dhd
, net
);
1259 if (ifidx
== DHD_BAD_IF
)
1262 ifp
= dhd
->iflist
[ifidx
];
1266 /* Use the protocol to get dongle stats */
1267 dhd_prot_dstats(&dhd
->pub
);
1270 /* Copy dongle stats to net device stats */
1271 ifp
->stats
.rx_packets
= dhd
->pub
.dstats
.rx_packets
;
1272 ifp
->stats
.tx_packets
= dhd
->pub
.dstats
.tx_packets
;
1273 ifp
->stats
.rx_bytes
= dhd
->pub
.dstats
.rx_bytes
;
1274 ifp
->stats
.tx_bytes
= dhd
->pub
.dstats
.tx_bytes
;
1275 ifp
->stats
.rx_errors
= dhd
->pub
.dstats
.rx_errors
;
1276 ifp
->stats
.tx_errors
= dhd
->pub
.dstats
.tx_errors
;
1277 ifp
->stats
.rx_dropped
= dhd
->pub
.dstats
.rx_dropped
;
1278 ifp
->stats
.tx_dropped
= dhd
->pub
.dstats
.tx_dropped
;
1279 ifp
->stats
.multicast
= dhd
->pub
.dstats
.multicast
;
1284 static int dhd_watchdog_thread(void *data
)
1286 dhd_info_t
*dhd
= (dhd_info_t
*) data
;
1288 /* This thread doesn't need any user-level access,
1289 * so get rid of all our resources
1292 if (dhd_watchdog_prio
> 0) {
1293 struct sched_param param
;
1294 param
.sched_priority
= (dhd_watchdog_prio
< MAX_RT_PRIO
) ?
1295 dhd_watchdog_prio
: (MAX_RT_PRIO
- 1);
1296 setScheduler(current
, SCHED_FIFO
, ¶m
);
1298 #endif /* DHD_SCHED */
1300 allow_signal(SIGTERM
);
1301 /* Run until signal received */
1303 if (kthread_should_stop())
1305 if (down_interruptible(&dhd
->watchdog_sem
) == 0) {
1306 if (dhd
->pub
.dongle_reset
== false) {
1307 /* Call the bus module watchdog */
1308 dhd_bus_watchdog(&dhd
->pub
);
1310 /* Count the tick for reference */
1318 static void dhd_watchdog(unsigned long data
)
1320 dhd_info_t
*dhd
= (dhd_info_t
*) data
;
1322 if (dhd
->watchdog_tsk
) {
1323 up(&dhd
->watchdog_sem
);
1325 /* Reschedule the watchdog */
1326 if (dhd
->wd_timer_valid
) {
1327 mod_timer(&dhd
->timer
,
1328 jiffies
+ dhd_watchdog_ms
* HZ
/ 1000);
1333 /* Call the bus module watchdog */
1334 dhd_bus_watchdog(&dhd
->pub
);
1336 /* Count the tick for reference */
1339 /* Reschedule the watchdog */
1340 if (dhd
->wd_timer_valid
)
1341 mod_timer(&dhd
->timer
, jiffies
+ dhd_watchdog_ms
* HZ
/ 1000);
1344 static int dhd_dpc_thread(void *data
)
1346 dhd_info_t
*dhd
= (dhd_info_t
*) data
;
1348 /* This thread doesn't need any user-level access,
1349 * so get rid of all our resources
1352 if (dhd_dpc_prio
> 0) {
1353 struct sched_param param
;
1354 param
.sched_priority
=
1356 MAX_RT_PRIO
) ? dhd_dpc_prio
: (MAX_RT_PRIO
- 1);
1357 setScheduler(current
, SCHED_FIFO
, ¶m
);
1359 #endif /* DHD_SCHED */
1361 allow_signal(SIGTERM
);
1362 /* Run until signal received */
1364 if (kthread_should_stop())
1366 if (down_interruptible(&dhd
->dpc_sem
) == 0) {
1367 /* Call bus dpc unless it indicated down
1368 (then clean stop) */
1369 if (dhd
->pub
.busstate
!= DHD_BUS_DOWN
) {
1370 if (dhd_bus_dpc(dhd
->pub
.bus
)) {
1374 dhd_bus_stop(dhd
->pub
.bus
, true);
1382 static void dhd_dpc(unsigned long data
)
1386 dhd
= (dhd_info_t
*) data
;
1388 /* Call bus dpc unless it indicated down (then clean stop) */
1389 if (dhd
->pub
.busstate
!= DHD_BUS_DOWN
) {
1390 if (dhd_bus_dpc(dhd
->pub
.bus
))
1391 tasklet_schedule(&dhd
->tasklet
);
1393 dhd_bus_stop(dhd
->pub
.bus
, true);
1397 void dhd_sched_dpc(dhd_pub_t
*dhdp
)
1399 dhd_info_t
*dhd
= (dhd_info_t
*) dhdp
->info
;
1406 tasklet_schedule(&dhd
->tasklet
);
1410 /* Retrieve current toe component enables, which are kept
1411 as a bitmap in toe_ol iovar */
1412 static int dhd_toe_get(dhd_info_t
*dhd
, int ifidx
, u32
*toe_ol
)
1418 memset(&ioc
, 0, sizeof(ioc
));
1420 ioc
.cmd
= WLC_GET_VAR
;
1422 ioc
.len
= (uint
) sizeof(buf
);
1425 strcpy(buf
, "toe_ol");
1426 ret
= dhd_prot_ioctl(&dhd
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
1428 /* Check for older dongle image that doesn't support toe_ol */
1430 DHD_ERROR(("%s: toe not supported by device\n",
1431 dhd_ifname(&dhd
->pub
, ifidx
)));
1435 DHD_INFO(("%s: could not get toe_ol: ret=%d\n",
1436 dhd_ifname(&dhd
->pub
, ifidx
), ret
));
1440 memcpy(toe_ol
, buf
, sizeof(u32
));
1444 /* Set current toe component enables in toe_ol iovar,
1445 and set toe global enable iovar */
1446 static int dhd_toe_set(dhd_info_t
*dhd
, int ifidx
, u32 toe_ol
)
1452 memset(&ioc
, 0, sizeof(ioc
));
1454 ioc
.cmd
= WLC_SET_VAR
;
1456 ioc
.len
= (uint
) sizeof(buf
);
1459 /* Set toe_ol as requested */
1461 strcpy(buf
, "toe_ol");
1462 memcpy(&buf
[sizeof("toe_ol")], &toe_ol
, sizeof(u32
));
1464 ret
= dhd_prot_ioctl(&dhd
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
1466 DHD_ERROR(("%s: could not set toe_ol: ret=%d\n",
1467 dhd_ifname(&dhd
->pub
, ifidx
), ret
));
1471 /* Enable toe globally only if any components are enabled. */
1473 toe
= (toe_ol
!= 0);
1476 memcpy(&buf
[sizeof("toe")], &toe
, sizeof(u32
));
1478 ret
= dhd_prot_ioctl(&dhd
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
1480 DHD_ERROR(("%s: could not set toe: ret=%d\n",
1481 dhd_ifname(&dhd
->pub
, ifidx
), ret
));
1489 static void dhd_ethtool_get_drvinfo(struct net_device
*net
,
1490 struct ethtool_drvinfo
*info
)
1492 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(net
);
1494 sprintf(info
->driver
, DRV_MODULE_NAME
);
1495 sprintf(info
->version
, "%lu", dhd
->pub
.drv_version
);
1496 sprintf(info
->fw_version
, "%s", wl_cfg80211_get_fwname());
1497 sprintf(info
->bus_info
, "%s", dev_name(&wl_cfg80211_get_sdio_func()->dev
));
1500 struct ethtool_ops dhd_ethtool_ops
= {
1501 .get_drvinfo
= dhd_ethtool_get_drvinfo
1504 static int dhd_ethtool(dhd_info_t
*dhd
, void *uaddr
)
1506 struct ethtool_drvinfo info
;
1507 char drvname
[sizeof(info
.driver
)];
1510 struct ethtool_value edata
;
1511 u32 toe_cmpnt
, csum_dir
;
1515 DHD_TRACE(("%s: Enter\n", __func__
));
1517 /* all ethtool calls start with a cmd word */
1518 if (copy_from_user(&cmd
, uaddr
, sizeof(u32
)))
1522 case ETHTOOL_GDRVINFO
:
1523 /* Copy out any request driver name */
1524 if (copy_from_user(&info
, uaddr
, sizeof(info
)))
1526 strncpy(drvname
, info
.driver
, sizeof(info
.driver
));
1527 drvname
[sizeof(info
.driver
) - 1] = '\0';
1529 /* clear struct for return */
1530 memset(&info
, 0, sizeof(info
));
1533 /* if dhd requested, identify ourselves */
1534 if (strcmp(drvname
, "?dhd") == 0) {
1535 sprintf(info
.driver
, "dhd");
1536 strcpy(info
.version
, EPI_VERSION_STR
);
1539 /* otherwise, require dongle to be up */
1540 else if (!dhd
->pub
.up
) {
1541 DHD_ERROR(("%s: dongle is not up\n", __func__
));
1545 /* finally, report dongle driver type */
1546 else if (dhd
->pub
.iswl
)
1547 sprintf(info
.driver
, "wl");
1549 sprintf(info
.driver
, "xx");
1551 sprintf(info
.version
, "%lu", dhd
->pub
.drv_version
);
1552 if (copy_to_user(uaddr
, &info
, sizeof(info
)))
1554 DHD_CTL(("%s: given %*s, returning %s\n", __func__
,
1555 (int)sizeof(drvname
), drvname
, info
.driver
));
1559 /* Get toe offload components from dongle */
1560 case ETHTOOL_GRXCSUM
:
1561 case ETHTOOL_GTXCSUM
:
1562 ret
= dhd_toe_get(dhd
, 0, &toe_cmpnt
);
1567 (cmd
== ETHTOOL_GTXCSUM
) ? TOE_TX_CSUM_OL
: TOE_RX_CSUM_OL
;
1570 edata
.data
= (toe_cmpnt
& csum_dir
) ? 1 : 0;
1572 if (copy_to_user(uaddr
, &edata
, sizeof(edata
)))
1576 /* Set toe offload components in dongle */
1577 case ETHTOOL_SRXCSUM
:
1578 case ETHTOOL_STXCSUM
:
1579 if (copy_from_user(&edata
, uaddr
, sizeof(edata
)))
1582 /* Read the current settings, update and write back */
1583 ret
= dhd_toe_get(dhd
, 0, &toe_cmpnt
);
1588 (cmd
== ETHTOOL_STXCSUM
) ? TOE_TX_CSUM_OL
: TOE_RX_CSUM_OL
;
1590 if (edata
.data
!= 0)
1591 toe_cmpnt
|= csum_dir
;
1593 toe_cmpnt
&= ~csum_dir
;
1595 ret
= dhd_toe_set(dhd
, 0, toe_cmpnt
);
1599 /* If setting TX checksum mode, tell Linux the new mode */
1600 if (cmd
== ETHTOOL_STXCSUM
) {
1602 dhd
->iflist
[0]->net
->features
|=
1605 dhd
->iflist
[0]->net
->features
&=
1619 static int dhd_ioctl_entry(struct net_device
*net
, struct ifreq
*ifr
, int cmd
)
1621 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(net
);
1628 bool is_set_key_cmd
;
1630 ifidx
= dhd_net2idx(dhd
, net
);
1631 DHD_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __func__
, ifidx
, cmd
));
1633 if (ifidx
== DHD_BAD_IF
)
1636 #if defined(CONFIG_WIRELESS_EXT)
1637 /* linux wireless extensions */
1638 if ((cmd
>= SIOCIWFIRST
) && (cmd
<= SIOCIWLAST
)) {
1639 /* may recurse, do NOT lock */
1640 return wl_iw_ioctl(net
, ifr
, cmd
);
1642 #endif /* defined(CONFIG_WIRELESS_EXT) */
1644 if (cmd
== SIOCETHTOOL
)
1645 return dhd_ethtool(dhd
, (void *)ifr
->ifr_data
);
1647 if (cmd
!= SIOCDEVPRIVATE
)
1650 memset(&ioc
, 0, sizeof(ioc
));
1652 /* Copy the ioc control structure part of ioctl request */
1653 if (copy_from_user(&ioc
, ifr
->ifr_data
, sizeof(wl_ioctl_t
))) {
1658 /* Copy out any buffer passed */
1660 buflen
= min_t(int, ioc
.len
, DHD_IOCTL_MAXLEN
);
1661 /* optimization for direct ioctl calls from kernel */
1663 if (segment_eq(get_fs(), KERNEL_DS)) {
1668 buf
= kmalloc(buflen
, GFP_ATOMIC
);
1673 if (copy_from_user(buf
, ioc
.buf
, buflen
)) {
1680 /* To differentiate between wl and dhd read 4 more byes */
1681 if ((copy_from_user(&driver
, (char *)ifr
->ifr_data
+ sizeof(wl_ioctl_t
),
1682 sizeof(uint
)) != 0)) {
1687 if (!capable(CAP_NET_ADMIN
)) {
1692 /* check for local dhd ioctl and handle it */
1693 if (driver
== DHD_IOCTL_MAGIC
) {
1694 bcmerror
= dhd_ioctl((void *)&dhd
->pub
, &ioc
, buf
, buflen
);
1696 dhd
->pub
.bcmerror
= bcmerror
;
1700 /* send to dongle (must be up, and wl) */
1701 if ((dhd
->pub
.busstate
!= DHD_BUS_DATA
)) {
1702 DHD_ERROR(("%s DONGLE_DOWN,__func__\n", __func__
));
1707 if (!dhd
->pub
.iswl
) {
1712 /* Intercept WLC_SET_KEY IOCTL - serialize M4 send and set key IOCTL to
1713 * prevent M4 encryption.
1715 is_set_key_cmd
= ((ioc
.cmd
== WLC_SET_KEY
) ||
1716 ((ioc
.cmd
== WLC_SET_VAR
) &&
1717 !(strncmp("wsec_key", ioc
.buf
, 9))) ||
1718 ((ioc
.cmd
== WLC_SET_VAR
) &&
1719 !(strncmp("bsscfg:wsec_key", ioc
.buf
, 15))));
1721 dhd_wait_pend8021x(net
);
1724 dhd_prot_ioctl(&dhd
->pub
, ifidx
, (wl_ioctl_t
*)&ioc
, buf
, buflen
);
1727 if (!bcmerror
&& buf
&& ioc
.buf
) {
1728 if (copy_to_user(ioc
.buf
, buf
, buflen
))
1740 static int dhd_stop(struct net_device
*net
)
1742 #if !defined(IGNORE_ETH0_DOWN)
1743 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(net
);
1745 DHD_TRACE(("%s: Enter\n", __func__
));
1746 if (IS_CFG80211_FAVORITE()) {
1749 if (dhd
->pub
.up
== 0)
1752 /* Set state and stop OS transmissions */
1754 netif_stop_queue(net
);
1756 DHD_ERROR(("BYPASS %s:due to BRCM compilation : under investigation\n",
1758 #endif /* !defined(IGNORE_ETH0_DOWN) */
1763 static int dhd_open(struct net_device
*net
)
1765 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(net
);
1769 int ifidx
= dhd_net2idx(dhd
, net
);
1772 DHD_TRACE(("%s: ifidx %d\n", __func__
, ifidx
));
1774 if (ifidx
== 0) { /* do it only for primary eth0 */
1776 /* try to bring up bus */
1777 ret
= dhd_bus_start(&dhd
->pub
);
1779 DHD_ERROR(("%s: failed with code %d\n", __func__
, ret
));
1782 atomic_set(&dhd
->pend_8021x_cnt
, 0);
1784 memcpy(net
->dev_addr
, dhd
->pub
.mac
, ETH_ALEN
);
1787 /* Get current TOE mode from dongle */
1788 if (dhd_toe_get(dhd
, ifidx
, &toe_ol
) >= 0
1789 && (toe_ol
& TOE_TX_CSUM_OL
) != 0)
1790 dhd
->iflist
[ifidx
]->net
->features
|= NETIF_F_IP_CSUM
;
1792 dhd
->iflist
[ifidx
]->net
->features
&= ~NETIF_F_IP_CSUM
;
1795 /* Allow transmit calls */
1796 netif_start_queue(net
);
1798 if (IS_CFG80211_FAVORITE()) {
1799 if (unlikely(wl_cfg80211_up())) {
1800 DHD_ERROR(("%s: failed to bring up cfg80211\n",
1810 dhd_add_if(dhd_info_t
*dhd
, int ifidx
, void *handle
, char *name
,
1811 u8
*mac_addr
, u32 flags
, u8 bssidx
)
1815 DHD_TRACE(("%s: idx %d, handle->%p\n", __func__
, ifidx
, handle
));
1817 ASSERT(dhd
&& (ifidx
< DHD_MAX_IFS
));
1819 ifp
= dhd
->iflist
[ifidx
];
1821 ifp
= kmalloc(sizeof(dhd_if_t
), GFP_ATOMIC
);
1823 DHD_ERROR(("%s: OOM - dhd_if_t\n", __func__
));
1828 memset(ifp
, 0, sizeof(dhd_if_t
));
1830 dhd
->iflist
[ifidx
] = ifp
;
1831 strlcpy(ifp
->name
, name
, IFNAMSIZ
);
1832 if (mac_addr
!= NULL
)
1833 memcpy(&ifp
->mac_addr
, mac_addr
, ETH_ALEN
);
1835 if (handle
== NULL
) {
1836 ifp
->state
= WLC_E_IF_ADD
;
1838 ASSERT(dhd
->sysioc_tsk
);
1839 up(&dhd
->sysioc_sem
);
1841 ifp
->net
= (struct net_device
*)handle
;
1846 void dhd_del_if(dhd_info_t
*dhd
, int ifidx
)
1850 DHD_TRACE(("%s: idx %d\n", __func__
, ifidx
));
1852 ASSERT(dhd
&& ifidx
&& (ifidx
< DHD_MAX_IFS
));
1853 ifp
= dhd
->iflist
[ifidx
];
1855 DHD_ERROR(("%s: Null interface\n", __func__
));
1859 ifp
->state
= WLC_E_IF_DEL
;
1861 ASSERT(dhd
->sysioc_tsk
);
1862 up(&dhd
->sysioc_sem
);
1865 dhd_pub_t
*dhd_attach(struct dhd_bus
*bus
, uint bus_hdrlen
)
1867 dhd_info_t
*dhd
= NULL
;
1868 struct net_device
*net
;
1870 DHD_TRACE(("%s: Enter\n", __func__
));
1871 /* updates firmware nvram path if it was provided as module
1873 if ((firmware_path
!= NULL
) && (firmware_path
[0] != '\0'))
1874 strcpy(fw_path
, firmware_path
);
1875 if ((nvram_path
!= NULL
) && (nvram_path
[0] != '\0'))
1876 strcpy(nv_path
, nvram_path
);
1878 /* Allocate etherdev, including space for private structure */
1879 net
= alloc_etherdev(sizeof(dhd
));
1881 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__
));
1885 /* Allocate primary dhd_info */
1886 dhd
= kzalloc(sizeof(dhd_info_t
), GFP_ATOMIC
);
1888 DHD_ERROR(("%s: OOM - alloc dhd_info\n", __func__
));
1893 * Save the dhd_info into the priv
1895 memcpy(netdev_priv(net
), &dhd
, sizeof(dhd
));
1897 /* Set network interface name if it was provided as module parameter */
1898 if (iface_name
[0]) {
1901 strncpy(net
->name
, iface_name
, IFNAMSIZ
);
1902 net
->name
[IFNAMSIZ
- 1] = 0;
1903 len
= strlen(net
->name
);
1904 ch
= net
->name
[len
- 1];
1905 if ((ch
> '9' || ch
< '0') && (len
< IFNAMSIZ
- 2))
1906 strcat(net
->name
, "%d");
1909 if (dhd_add_if(dhd
, 0, (void *)net
, net
->name
, NULL
, 0, 0) ==
1913 net
->netdev_ops
= NULL
;
1914 sema_init(&dhd
->proto_sem
, 1);
1915 /* Initialize other structure content */
1916 init_waitqueue_head(&dhd
->ioctl_resp_wait
);
1917 init_waitqueue_head(&dhd
->ctrl_wait
);
1919 /* Initialize the spinlocks */
1920 spin_lock_init(&dhd
->sdlock
);
1921 spin_lock_init(&dhd
->txqlock
);
1923 /* Link to info module */
1924 dhd
->pub
.info
= dhd
;
1926 /* Link to bus module */
1928 dhd
->pub
.hdrlen
= bus_hdrlen
;
1930 /* Attach and link in the protocol */
1931 if (dhd_prot_attach(&dhd
->pub
) != 0) {
1932 DHD_ERROR(("dhd_prot_attach failed\n"));
1935 #if defined(CONFIG_WIRELESS_EXT)
1936 /* Attach and link in the iw */
1937 if (wl_iw_attach(net
, (void *)&dhd
->pub
) != 0) {
1938 DHD_ERROR(("wl_iw_attach failed\n"));
1941 #endif /* defined(CONFIG_WIRELESS_EXT) */
1943 /* Attach and link in the cfg80211 */
1944 if (IS_CFG80211_FAVORITE()) {
1945 if (unlikely(wl_cfg80211_attach(net
, &dhd
->pub
))) {
1946 DHD_ERROR(("wl_cfg80211_attach failed\n"));
1950 strcpy(fw_path
, wl_cfg80211_get_fwname());
1951 strcpy(nv_path
, wl_cfg80211_get_nvramname());
1955 /* Set up the watchdog timer */
1956 init_timer(&dhd
->timer
);
1957 dhd
->timer
.data
= (unsigned long) dhd
;
1958 dhd
->timer
.function
= dhd_watchdog
;
1960 /* Initialize thread based operation and lock */
1961 sema_init(&dhd
->sdsem
, 1);
1962 if ((dhd_watchdog_prio
>= 0) && (dhd_dpc_prio
>= 0))
1963 dhd
->threads_only
= true;
1965 dhd
->threads_only
= false;
1967 if (dhd_dpc_prio
>= 0) {
1968 /* Initialize watchdog thread */
1969 sema_init(&dhd
->watchdog_sem
, 0);
1970 dhd
->watchdog_tsk
= kthread_run(dhd_watchdog_thread
, dhd
,
1972 if (IS_ERR(dhd
->watchdog_tsk
)) {
1974 "dhd_watchdog thread failed to start\n");
1975 dhd
->watchdog_tsk
= NULL
;
1978 dhd
->watchdog_tsk
= NULL
;
1981 /* Set up the bottom half handler */
1982 if (dhd_dpc_prio
>= 0) {
1983 /* Initialize DPC thread */
1984 sema_init(&dhd
->dpc_sem
, 0);
1985 dhd
->dpc_tsk
= kthread_run(dhd_dpc_thread
, dhd
, "dhd_dpc");
1986 if (IS_ERR(dhd
->dpc_tsk
)) {
1988 "dhd_dpc thread failed to start\n");
1989 dhd
->dpc_tsk
= NULL
;
1992 tasklet_init(&dhd
->tasklet
, dhd_dpc
, (unsigned long) dhd
);
1993 dhd
->dpc_tsk
= NULL
;
1997 sema_init(&dhd
->sysioc_sem
, 0);
1998 dhd
->sysioc_tsk
= kthread_run(_dhd_sysioc_thread
, dhd
,
2000 if (IS_ERR(dhd
->sysioc_tsk
)) {
2002 "_dhd_sysioc thread failed to start\n");
2003 dhd
->sysioc_tsk
= NULL
;
2006 dhd
->sysioc_tsk
= NULL
;
2009 * Save the dhd_info into the priv
2011 memcpy(netdev_priv(net
), &dhd
, sizeof(dhd
));
2013 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2016 #if defined(CONFIG_PM_SLEEP)
2017 atomic_set(&dhd_mmc_suspend
, false);
2018 if (!IS_CFG80211_FAVORITE())
2019 register_pm_notifier(&dhd_sleep_pm_notifier
);
2020 #endif /* defined(CONFIG_PM_SLEEP) */
2021 /* && defined(DHD_GPL) */
2022 /* Init lock suspend to prevent kernel going to suspend */
2023 #ifdef CONFIG_HAS_EARLYSUSPEND
2024 dhd
->early_suspend
.level
= EARLY_SUSPEND_LEVEL_BLANK_SCREEN
+ 20;
2025 dhd
->early_suspend
.suspend
= dhd_early_suspend
;
2026 dhd
->early_suspend
.resume
= dhd_late_resume
;
2027 register_early_suspend(&dhd
->early_suspend
);
2036 dhd_detach(&dhd
->pub
);
2041 int dhd_bus_start(dhd_pub_t
*dhdp
)
2044 dhd_info_t
*dhd
= (dhd_info_t
*) dhdp
->info
;
2045 #ifdef EMBEDDED_PLATFORM
2046 char iovbuf
[WL_EVENTING_MASK_LEN
+ 12]; /* Room for "event_msgs" +
2048 #endif /* EMBEDDED_PLATFORM */
2052 DHD_TRACE(("%s:\n", __func__
));
2054 /* try to download image and nvram to the dongle */
2055 if (dhd
->pub
.busstate
== DHD_BUS_DOWN
) {
2056 if (!(dhd_bus_download_firmware(dhd
->pub
.bus
,
2057 fw_path
, nv_path
))) {
2058 DHD_ERROR(("%s: dhdsdio_probe_download failed. "
2059 "firmware = %s nvram = %s\n",
2060 __func__
, fw_path
, nv_path
));
2065 /* Start the watchdog timer */
2066 dhd
->pub
.tickcnt
= 0;
2067 dhd_os_wd_timer(&dhd
->pub
, dhd_watchdog_ms
);
2069 /* Bring up the bus */
2070 ret
= dhd_bus_init(&dhd
->pub
, true);
2072 DHD_ERROR(("%s, dhd_bus_init failed %d\n", __func__
, ret
));
2075 #if defined(OOB_INTR_ONLY)
2076 /* Host registration for OOB interrupt */
2077 if (bcmsdh_register_oob_intr(dhdp
)) {
2078 del_timer_sync(&dhd
->timer
);
2079 dhd
->wd_timer_valid
= false;
2080 DHD_ERROR(("%s Host failed to resgister for OOB\n", __func__
));
2084 /* Enable oob at firmware */
2085 dhd_enable_oob_intr(dhd
->pub
.bus
, true);
2086 #endif /* defined(OOB_INTR_ONLY) */
2088 /* If bus is not ready, can't come up */
2089 if (dhd
->pub
.busstate
!= DHD_BUS_DATA
) {
2090 del_timer_sync(&dhd
->timer
);
2091 dhd
->wd_timer_valid
= false;
2092 DHD_ERROR(("%s failed bus is not ready\n", __func__
));
2095 #ifdef EMBEDDED_PLATFORM
2096 brcmu_mkiovar("event_msgs", dhdp
->eventmask
, WL_EVENTING_MASK_LEN
,
2097 iovbuf
, sizeof(iovbuf
));
2098 dhdcdc_query_ioctl(dhdp
, 0, WLC_GET_VAR
, iovbuf
, sizeof(iovbuf
));
2099 memcpy(dhdp
->eventmask
, iovbuf
, WL_EVENTING_MASK_LEN
);
2101 setbit(dhdp
->eventmask
, WLC_E_SET_SSID
);
2102 setbit(dhdp
->eventmask
, WLC_E_PRUNE
);
2103 setbit(dhdp
->eventmask
, WLC_E_AUTH
);
2104 setbit(dhdp
->eventmask
, WLC_E_REASSOC
);
2105 setbit(dhdp
->eventmask
, WLC_E_REASSOC_IND
);
2106 setbit(dhdp
->eventmask
, WLC_E_DEAUTH_IND
);
2107 setbit(dhdp
->eventmask
, WLC_E_DISASSOC_IND
);
2108 setbit(dhdp
->eventmask
, WLC_E_DISASSOC
);
2109 setbit(dhdp
->eventmask
, WLC_E_JOIN
);
2110 setbit(dhdp
->eventmask
, WLC_E_ASSOC_IND
);
2111 setbit(dhdp
->eventmask
, WLC_E_PSK_SUP
);
2112 setbit(dhdp
->eventmask
, WLC_E_LINK
);
2113 setbit(dhdp
->eventmask
, WLC_E_NDIS_LINK
);
2114 setbit(dhdp
->eventmask
, WLC_E_MIC_ERROR
);
2115 setbit(dhdp
->eventmask
, WLC_E_PMKID_CACHE
);
2116 setbit(dhdp
->eventmask
, WLC_E_TXFAIL
);
2117 setbit(dhdp
->eventmask
, WLC_E_JOIN_START
);
2118 setbit(dhdp
->eventmask
, WLC_E_SCAN_COMPLETE
);
2120 setbit(dhdp
->eventmask
, WLC_E_PFN_NET_FOUND
);
2121 #endif /* PNO_SUPPORT */
2123 /* enable dongle roaming event */
2125 dhdp
->pktfilter_count
= 1;
2126 /* Setup filter to allow only unicast */
2127 dhdp
->pktfilter
[0] = "100 0 0 0 0x01 0x00";
2128 #endif /* EMBEDDED_PLATFORM */
2130 /* Bus is ready, do any protocol initialization */
2131 ret
= dhd_prot_init(&dhd
->pub
);
2139 dhd_iovar(dhd_pub_t
*pub
, int ifidx
, char *name
, char *cmd_buf
, uint cmd_len
,
2142 char buf
[strlen(name
) + 1 + cmd_len
];
2143 int len
= sizeof(buf
);
2147 len
= brcmu_mkiovar(name
, cmd_buf
, cmd_len
, buf
, len
);
2149 memset(&ioc
, 0, sizeof(ioc
));
2151 ioc
.cmd
= set
? WLC_SET_VAR
: WLC_GET_VAR
;
2156 ret
= dhd_prot_ioctl(pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
2157 if (!set
&& ret
>= 0)
2158 memcpy(cmd_buf
, buf
, cmd_len
);
2163 static struct net_device_ops dhd_ops_pri
= {
2164 .ndo_open
= dhd_open
,
2165 .ndo_stop
= dhd_stop
,
2166 .ndo_get_stats
= dhd_get_stats
,
2167 .ndo_do_ioctl
= dhd_ioctl_entry
,
2168 .ndo_start_xmit
= dhd_start_xmit
,
2169 .ndo_set_mac_address
= dhd_set_mac_address
,
2170 .ndo_set_multicast_list
= dhd_set_multicast_list
2173 int dhd_net_attach(dhd_pub_t
*dhdp
, int ifidx
)
2175 dhd_info_t
*dhd
= (dhd_info_t
*) dhdp
->info
;
2176 struct net_device
*net
;
2177 u8 temp_addr
[ETH_ALEN
] = {
2178 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
2180 DHD_TRACE(("%s: ifidx %d\n", __func__
, ifidx
));
2182 ASSERT(dhd
&& dhd
->iflist
[ifidx
]);
2184 net
= dhd
->iflist
[ifidx
]->net
;
2187 ASSERT(!net
->netdev_ops
);
2188 net
->netdev_ops
= &dhd_ops_pri
;
2191 * We have to use the primary MAC for virtual interfaces
2194 /* for virtual interfaces use the primary MAC */
2195 memcpy(temp_addr
, dhd
->pub
.mac
, ETH_ALEN
);
2200 DHD_TRACE(("%s ACCESS POINT MAC: \n", __func__
));
2201 /* ACCESSPOINT INTERFACE CASE */
2202 temp_addr
[0] |= 0X02; /* set bit 2 ,
2203 - Locally Administered address */
2206 net
->hard_header_len
= ETH_HLEN
+ dhd
->pub
.hdrlen
;
2207 net
->ethtool_ops
= &dhd_ethtool_ops
;
2209 dhd
->pub
.rxsz
= net
->mtu
+ net
->hard_header_len
+ dhd
->pub
.hdrlen
;
2211 memcpy(net
->dev_addr
, temp_addr
, ETH_ALEN
);
2213 if (register_netdev(net
) != 0) {
2214 DHD_ERROR(("%s: couldn't register the net device\n",
2219 DHD_INFO(("%s: Broadcom Dongle Host Driver\n", net
->name
));
2224 net
->netdev_ops
= NULL
;
2228 void dhd_bus_detach(dhd_pub_t
*dhdp
)
2232 DHD_TRACE(("%s: Enter\n", __func__
));
2235 dhd
= (dhd_info_t
*) dhdp
->info
;
2237 /* Stop the protocol module */
2238 dhd_prot_stop(&dhd
->pub
);
2240 /* Stop the bus module */
2241 dhd_bus_stop(dhd
->pub
.bus
, true);
2242 #if defined(OOB_INTR_ONLY)
2243 bcmsdh_unregister_oob_intr();
2244 #endif /* defined(OOB_INTR_ONLY) */
2246 /* Clear the watchdog timer */
2247 del_timer_sync(&dhd
->timer
);
2248 dhd
->wd_timer_valid
= false;
2253 void dhd_detach(dhd_pub_t
*dhdp
)
2257 DHD_TRACE(("%s: Enter\n", __func__
));
2260 dhd
= (dhd_info_t
*) dhdp
->info
;
2265 #if defined(CONFIG_HAS_EARLYSUSPEND)
2266 if (dhd
->early_suspend
.suspend
)
2267 unregister_early_suspend(&dhd
->early_suspend
);
2268 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2270 for (i
= 1; i
< DHD_MAX_IFS
; i
++)
2274 ifp
= dhd
->iflist
[0];
2276 if (ifp
->net
->netdev_ops
== &dhd_ops_pri
) {
2278 unregister_netdev(ifp
->net
);
2281 if (dhd
->watchdog_tsk
) {
2282 send_sig(SIGTERM
, dhd
->watchdog_tsk
, 1);
2283 kthread_stop(dhd
->watchdog_tsk
);
2284 dhd
->watchdog_tsk
= NULL
;
2288 send_sig(SIGTERM
, dhd
->dpc_tsk
, 1);
2289 kthread_stop(dhd
->dpc_tsk
);
2290 dhd
->dpc_tsk
= NULL
;
2292 tasklet_kill(&dhd
->tasklet
);
2294 if (dhd
->sysioc_tsk
) {
2295 send_sig(SIGTERM
, dhd
->sysioc_tsk
, 1);
2296 kthread_stop(dhd
->sysioc_tsk
);
2297 dhd
->sysioc_tsk
= NULL
;
2300 dhd_bus_detach(dhdp
);
2303 dhd_prot_detach(dhdp
);
2305 #if defined(CONFIG_WIRELESS_EXT)
2307 #endif /* (CONFIG_WIRELESS_EXT) */
2309 if (IS_CFG80211_FAVORITE())
2310 wl_cfg80211_detach();
2312 #if defined(CONFIG_PM_SLEEP)
2313 if (!IS_CFG80211_FAVORITE())
2314 unregister_pm_notifier(&dhd_sleep_pm_notifier
);
2315 #endif /* defined(CONFIG_PM_SLEEP) */
2316 /* && defined(DHD_GPL) */
2317 free_netdev(ifp
->net
);
2324 static void __exit
dhd_module_cleanup(void)
2326 DHD_TRACE(("%s: Enter\n", __func__
));
2328 dhd_bus_unregister();
2329 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2332 /* Call customer gpio to turn off power with WL_REG_ON signal */
2333 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF
);
2336 static int __init
dhd_module_init(void)
2340 DHD_TRACE(("%s: Enter\n", __func__
));
2342 /* Sanity check on the module parameters */
2344 /* Both watchdog and DPC as tasklets are ok */
2345 if ((dhd_watchdog_prio
< 0) && (dhd_dpc_prio
< 0))
2348 /* If both watchdog and DPC are threads, TX must be deferred */
2349 if ((dhd_watchdog_prio
>= 0) && (dhd_dpc_prio
>= 0)
2353 DHD_ERROR(("Invalid module parameters.\n"));
2356 /* Call customer gpio to turn on power with WL_REG_ON signal */
2357 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_ON
);
2359 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2360 sema_init(&wifi_control_sem
, 0);
2362 error
= wifi_add_dev();
2364 DHD_ERROR(("%s: platform_driver_register failed\n", __func__
));
2368 /* Waiting callback after platform_driver_register is done or
2370 if (down_timeout(&wifi_control_sem
, msecs_to_jiffies(1000)) != 0) {
2371 printk(KERN_ERR
"%s: platform_driver_register timeout\n",
2377 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2379 error
= dhd_bus_register();
2382 DHD_ERROR(("%s: sdio_register_driver failed\n", __func__
));
2388 /* turn off power and exit */
2389 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF
);
2393 module_init(dhd_module_init
);
2394 module_exit(dhd_module_cleanup
);
2397 * OS specific functions required to implement DHD driver in OS independent way
2399 int dhd_os_proto_block(dhd_pub_t
*pub
)
2401 dhd_info_t
*dhd
= (dhd_info_t
*) (pub
->info
);
2404 down(&dhd
->proto_sem
);
2410 int dhd_os_proto_unblock(dhd_pub_t
*pub
)
2412 dhd_info_t
*dhd
= (dhd_info_t
*) (pub
->info
);
2415 up(&dhd
->proto_sem
);
2422 unsigned int dhd_os_get_ioctl_resp_timeout(void)
2424 return (unsigned int)dhd_ioctl_timeout_msec
;
2427 void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec
)
2429 dhd_ioctl_timeout_msec
= (int)timeout_msec
;
2432 int dhd_os_ioctl_resp_wait(dhd_pub_t
*pub
, uint
*condition
, bool *pending
)
2434 dhd_info_t
*dhd
= (dhd_info_t
*) (pub
->info
);
2435 DECLARE_WAITQUEUE(wait
, current
);
2436 int timeout
= dhd_ioctl_timeout_msec
;
2438 /* Convert timeout in millsecond to jiffies */
2439 timeout
= timeout
* HZ
/ 1000;
2441 /* Wait until control frame is available */
2442 add_wait_queue(&dhd
->ioctl_resp_wait
, &wait
);
2443 set_current_state(TASK_INTERRUPTIBLE
);
2445 while (!(*condition
) && (!signal_pending(current
) && timeout
))
2446 timeout
= schedule_timeout(timeout
);
2448 if (signal_pending(current
))
2451 set_current_state(TASK_RUNNING
);
2452 remove_wait_queue(&dhd
->ioctl_resp_wait
, &wait
);
2457 int dhd_os_ioctl_resp_wake(dhd_pub_t
*pub
)
2459 dhd_info_t
*dhd
= (dhd_info_t
*) (pub
->info
);
2461 if (waitqueue_active(&dhd
->ioctl_resp_wait
))
2462 wake_up_interruptible(&dhd
->ioctl_resp_wait
);
2467 void dhd_os_wd_timer(void *bus
, uint wdtick
)
2469 dhd_pub_t
*pub
= bus
;
2470 static uint save_dhd_watchdog_ms
;
2471 dhd_info_t
*dhd
= (dhd_info_t
*) pub
->info
;
2473 /* don't start the wd until fw is loaded */
2474 if (pub
->busstate
== DHD_BUS_DOWN
)
2477 /* Totally stop the timer */
2478 if (!wdtick
&& dhd
->wd_timer_valid
== true) {
2479 del_timer_sync(&dhd
->timer
);
2480 dhd
->wd_timer_valid
= false;
2481 save_dhd_watchdog_ms
= wdtick
;
2486 dhd_watchdog_ms
= (uint
) wdtick
;
2488 if (save_dhd_watchdog_ms
!= dhd_watchdog_ms
) {
2490 if (dhd
->wd_timer_valid
== true)
2491 /* Stop timer and restart at new value */
2492 del_timer_sync(&dhd
->timer
);
2494 /* Create timer again when watchdog period is
2495 dynamically changed or in the first instance
2497 dhd
->timer
.expires
=
2498 jiffies
+ dhd_watchdog_ms
* HZ
/ 1000;
2499 add_timer(&dhd
->timer
);
2502 /* Re arm the timer, at last watchdog period */
2503 mod_timer(&dhd
->timer
,
2504 jiffies
+ dhd_watchdog_ms
* HZ
/ 1000);
2507 dhd
->wd_timer_valid
= true;
2508 save_dhd_watchdog_ms
= wdtick
;
2512 void *dhd_os_open_image(char *filename
)
2516 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2517 return wl_cfg80211_request_fw(filename
);
2519 fp
= filp_open(filename
, O_RDONLY
, 0);
2521 * 2.6.11 (FC4) supports filp_open() but later revs don't?
2523 * fp = open_namei(AT_FDCWD, filename, O_RD, 0);
2532 int dhd_os_get_image_block(char *buf
, int len
, void *image
)
2534 struct file
*fp
= (struct file
*)image
;
2537 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2538 return wl_cfg80211_read_fw(buf
, len
);
2543 rdlen
= kernel_read(fp
, fp
->f_pos
, buf
, len
);
2550 void dhd_os_close_image(void *image
)
2552 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2553 return wl_cfg80211_release_fw();
2555 filp_close((struct file
*)image
, NULL
);
2558 void dhd_os_sdlock(dhd_pub_t
*pub
)
2562 dhd
= (dhd_info_t
*) (pub
->info
);
2564 if (dhd
->threads_only
)
2567 spin_lock_bh(&dhd
->sdlock
);
2570 void dhd_os_sdunlock(dhd_pub_t
*pub
)
2574 dhd
= (dhd_info_t
*) (pub
->info
);
2576 if (dhd
->threads_only
)
2579 spin_unlock_bh(&dhd
->sdlock
);
2582 void dhd_os_sdlock_txq(dhd_pub_t
*pub
)
2586 dhd
= (dhd_info_t
*) (pub
->info
);
2587 spin_lock_bh(&dhd
->txqlock
);
2590 void dhd_os_sdunlock_txq(dhd_pub_t
*pub
)
2594 dhd
= (dhd_info_t
*) (pub
->info
);
2595 spin_unlock_bh(&dhd
->txqlock
);
2599 dhd_wl_host_event(dhd_info_t
*dhd
, int *ifidx
, void *pktdata
,
2600 wl_event_msg_t
*event
, void **data
)
2604 ASSERT(dhd
!= NULL
);
2606 bcmerror
= wl_host_event(dhd
, ifidx
, pktdata
, event
, data
);
2610 #if defined(CONFIG_WIRELESS_EXT)
2611 if (!IS_CFG80211_FAVORITE()) {
2612 if ((dhd
->iflist
[*ifidx
] == NULL
)
2613 || (dhd
->iflist
[*ifidx
]->net
== NULL
)) {
2614 DHD_ERROR(("%s Exit null pointer\n", __func__
));
2618 if (dhd
->iflist
[*ifidx
]->net
)
2619 wl_iw_event(dhd
->iflist
[*ifidx
]->net
, event
, *data
);
2621 #endif /* defined(CONFIG_WIRELESS_EXT) */
2623 if (IS_CFG80211_FAVORITE()) {
2624 ASSERT(dhd
->iflist
[*ifidx
] != NULL
);
2625 ASSERT(dhd
->iflist
[*ifidx
]->net
!= NULL
);
2626 if (dhd
->iflist
[*ifidx
]->net
)
2627 wl_cfg80211_event(dhd
->iflist
[*ifidx
]->net
, event
,
2634 /* send up locally generated event */
2635 void dhd_sendup_event(dhd_pub_t
*dhdp
, wl_event_msg_t
*event
, void *data
)
2637 switch (be32_to_cpu(event
->event_type
)) {
2643 void dhd_wait_for_event(dhd_pub_t
*dhd
, bool *lockvar
)
2645 struct dhd_info
*dhdinfo
= dhd
->info
;
2646 dhd_os_sdunlock(dhd
);
2647 wait_event_interruptible_timeout(dhdinfo
->ctrl_wait
,
2648 (*lockvar
== false), HZ
* 2);
2653 void dhd_wait_event_wakeup(dhd_pub_t
*dhd
)
2655 struct dhd_info
*dhdinfo
= dhd
->info
;
2656 if (waitqueue_active(&dhdinfo
->ctrl_wait
))
2657 wake_up_interruptible(&dhdinfo
->ctrl_wait
);
2661 int dhd_dev_reset(struct net_device
*dev
, u8 flag
)
2663 dhd_info_t
*dhd
= *(dhd_info_t
**)netdev_priv(dev
);
2665 /* Turning off watchdog */
2667 dhd_os_wd_timer(&dhd
->pub
, 0);
2669 dhd_bus_devreset(&dhd
->pub
, flag
);
2671 /* Turning on watchdog back */
2673 dhd_os_wd_timer(&dhd
->pub
, dhd_watchdog_ms
);
2674 DHD_ERROR(("%s: WLAN OFF DONE\n", __func__
));
2679 int net_os_set_suspend_disable(struct net_device
*dev
, int val
)
2681 dhd_info_t
*dhd
= *(dhd_info_t
**)netdev_priv(dev
);
2685 ret
= dhd
->pub
.suspend_disable_flag
;
2686 dhd
->pub
.suspend_disable_flag
= val
;
2691 int net_os_set_suspend(struct net_device
*dev
, int val
)
2694 #if defined(CONFIG_HAS_EARLYSUSPEND)
2695 dhd_info_t
*dhd
= *(dhd_info_t
**)netdev_priv(dev
);
2698 dhd_os_proto_block(&dhd
->pub
);
2699 ret
= dhd_set_suspend(val
, &dhd
->pub
);
2700 dhd_os_proto_unblock(&dhd
->pub
);
2702 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2706 int net_os_set_dtim_skip(struct net_device
*dev
, int val
)
2708 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(dev
);
2711 dhd
->pub
.dtim_skip
= val
;
2716 int net_os_set_packet_filter(struct net_device
*dev
, int val
)
2718 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(dev
);
2721 /* Packet filtering is set only if we still in early-suspend and
2722 * we need either to turn it ON or turn it OFF
2723 * We can always turn it OFF in case of early-suspend, but we turn it
2724 * back ON only if suspend_disable_flag was not set
2726 if (dhd
&& dhd
->pub
.up
) {
2727 dhd_os_proto_block(&dhd
->pub
);
2728 if (dhd
->pub
.in_suspend
) {
2729 if (!val
|| (val
&& !dhd
->pub
.suspend_disable_flag
))
2730 dhd_set_packet_filter(val
, &dhd
->pub
);
2732 dhd_os_proto_unblock(&dhd
->pub
);
2737 void dhd_dev_init_ioctl(struct net_device
*dev
)
2739 dhd_info_t
*dhd
= *(dhd_info_t
**)netdev_priv(dev
);
2741 dhd_preinit_ioctls(&dhd
->pub
);
2745 /* Linux wrapper to call common dhd_pno_clean */
2746 int dhd_dev_pno_reset(struct net_device
*dev
)
2748 dhd_info_t
*dhd
= *(dhd_info_t
**)netdev_priv(dev
);
2750 return dhd_pno_clean(&dhd
->pub
);
2753 /* Linux wrapper to call common dhd_pno_enable */
2754 int dhd_dev_pno_enable(struct net_device
*dev
, int pfn_enabled
)
2756 dhd_info_t
*dhd
= *(dhd_info_t
**)netdev_priv(dev
);
2758 return dhd_pno_enable(&dhd
->pub
, pfn_enabled
);
2761 /* Linux wrapper to call common dhd_pno_set */
2763 dhd_dev_pno_set(struct net_device
*dev
, wlc_ssid_t
*ssids_local
, int nssid
,
2764 unsigned char scan_fr
)
2766 dhd_info_t
*dhd
= *(dhd_info_t
**)netdev_priv(dev
);
2768 return dhd_pno_set(&dhd
->pub
, ssids_local
, nssid
, scan_fr
);
2771 /* Linux wrapper to get pno status */
2772 int dhd_dev_get_pno_status(struct net_device
*dev
)
2774 dhd_info_t
*dhd
= *(dhd_info_t
**)netdev_priv(dev
);
2776 return dhd_pno_get_status(&dhd
->pub
);
2779 #endif /* PNO_SUPPORT */
2781 static int dhd_get_pend_8021x_cnt(dhd_info_t
*dhd
)
2783 return atomic_read(&dhd
->pend_8021x_cnt
);
2786 #define MAX_WAIT_FOR_8021X_TX 10
2788 int dhd_wait_pend8021x(struct net_device
*dev
)
2790 dhd_info_t
*dhd
= *(dhd_info_t
**)netdev_priv(dev
);
2791 int timeout
= 10 * HZ
/ 1000;
2792 int ntimes
= MAX_WAIT_FOR_8021X_TX
;
2793 int pend
= dhd_get_pend_8021x_cnt(dhd
);
2795 while (ntimes
&& pend
) {
2797 set_current_state(TASK_INTERRUPTIBLE
);
2798 schedule_timeout(timeout
);
2799 set_current_state(TASK_RUNNING
);
2802 pend
= dhd_get_pend_8021x_cnt(dhd
);
2807 void wl_os_wd_timer(struct net_device
*ndev
, uint wdtick
)
2809 dhd_info_t
*dhd
= *(dhd_info_t
**)netdev_priv(ndev
);
2811 dhd_os_wd_timer(&dhd
->pub
, wdtick
);
2815 int write_to_file(dhd_pub_t
*dhd
, u8
*buf
, int size
)
2819 mm_segment_t old_fs
;
2822 /* change to KERNEL_DS address limit */
2826 /* open file to write */
2827 fp
= filp_open("/tmp/mem_dump", O_WRONLY
| O_CREAT
, 0640);
2829 DHD_ERROR(("%s: open file error\n", __func__
));
2834 /* Write buf to file */
2835 fp
->f_op
->write(fp
, buf
, size
, &pos
);
2838 /* free buf before return */
2840 /* close file before return */
2842 filp_close(fp
, current
->files
);
2843 /* restore previous address limit */
2848 #endif /* DHD_DEBUG */