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 volatile bool dhd_mmc_suspend
= false;
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
];
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 #if defined(CONFIG_WIRELESS_EXT)
389 struct iw_statistics
*dhd_get_wireless_stats(struct net_device
*dev
);
390 #endif /* defined(CONFIG_WIRELESS_EXT) */
392 static void dhd_dpc(unsigned long data
);
394 extern int dhd_wait_pend8021x(struct net_device
*dev
);
398 #error TOE requires BDC
400 static int dhd_toe_get(dhd_info_t
*dhd
, int idx
, u32
*toe_ol
);
401 static int dhd_toe_set(dhd_info_t
*dhd
, int idx
, u32 toe_ol
);
404 static int dhd_wl_host_event(dhd_info_t
*dhd
, int *ifidx
, void *pktdata
,
405 wl_event_msg_t
*event_ptr
, void **data_ptr
);
407 #if defined(CONFIG_PM_SLEEP)
408 static int dhd_sleep_pm_callback(struct notifier_block
*nfb
,
409 unsigned long action
, void *ignored
)
412 case PM_HIBERNATION_PREPARE
:
413 case PM_SUSPEND_PREPARE
:
414 dhd_mmc_suspend
= true;
416 case PM_POST_HIBERNATION
:
417 case PM_POST_SUSPEND
:
418 dhd_mmc_suspend
= false;
424 static struct notifier_block dhd_sleep_pm_notifier
= {
425 .notifier_call
= dhd_sleep_pm_callback
,
429 extern int register_pm_notifier(struct notifier_block
*nb
);
430 extern int unregister_pm_notifier(struct notifier_block
*nb
);
431 #endif /* defined(CONFIG_PM_SLEEP) */
432 /* && defined(DHD_GPL) */
433 static void dhd_set_packet_filter(int value
, dhd_pub_t
*dhd
)
435 #ifdef PKT_FILTER_SUPPORT
436 DHD_TRACE(("%s: %d\n", __func__
, value
));
437 /* 1 - Enable packet filter, only allow unicast packet to send up */
438 /* 0 - Disable packet filter */
439 if (dhd_pkt_filter_enable
) {
442 for (i
= 0; i
< dhd
->pktfilter_count
; i
++) {
443 dhd_pktfilter_offload_set(dhd
, dhd
->pktfilter
[i
]);
444 dhd_pktfilter_offload_enable(dhd
, dhd
->pktfilter
[i
],
445 value
, dhd_master_mode
);
451 #if defined(CONFIG_HAS_EARLYSUSPEND)
452 static int dhd_set_suspend(int value
, dhd_pub_t
*dhd
)
454 int power_mode
= PM_MAX
;
455 /* wl_pkt_filter_enable_t enable_parm; */
460 #endif /* CUSTOMER_HW2 */
462 DHD_TRACE(("%s: enter, value = %d in_suspend=%d\n",
463 __func__
, value
, dhd
->in_suspend
));
465 if (dhd
&& dhd
->up
) {
466 if (value
&& dhd
->in_suspend
) {
468 /* Kernel suspended */
469 DHD_TRACE(("%s: force extra Suspend setting\n",
472 dhdcdc_set_ioctl(dhd
, 0, WLC_SET_PM
,
476 /* Enable packet filter, only allow unicast
478 dhd_set_packet_filter(1, dhd
);
480 /* if dtim skip setup as default force it
481 * to wake each third dtim
482 * for better power saving.
483 * Note that side effect is chance to miss BC/MC
486 if ((dhd
->dtim_skip
== 0) || (dhd
->dtim_skip
== 1))
489 bcn_li_dtim
= dhd
->dtim_skip
;
490 bcm_mkiovar("bcn_li_dtim", (char *)&bcn_li_dtim
,
491 4, iovbuf
, sizeof(iovbuf
));
492 dhdcdc_set_ioctl(dhd
, 0, WLC_SET_VAR
, iovbuf
,
495 /* Disable build-in roaming to allowed \
496 * supplicant to take of romaing
498 bcm_mkiovar("roam_off", (char *)&roamvar
, 4,
499 iovbuf
, sizeof(iovbuf
));
500 dhdcdc_set_ioctl(dhd
, 0, WLC_SET_VAR
, iovbuf
,
502 #endif /* CUSTOMER_HW2 */
506 DHD_TRACE(("%s: Remove extra suspend setting\n",
509 power_mode
= PM_FAST
;
510 dhdcdc_set_ioctl(dhd
, 0, WLC_SET_PM
,
514 /* disable pkt filter */
515 dhd_set_packet_filter(0, dhd
);
517 /* restore pre-suspend setting for dtim_skip */
518 bcm_mkiovar("bcn_li_dtim", (char *)&dhd
->dtim_skip
,
519 4, iovbuf
, sizeof(iovbuf
));
521 dhdcdc_set_ioctl(dhd
, 0, WLC_SET_VAR
, iovbuf
,
525 bcm_mkiovar("roam_off", (char *)&roamvar
, 4, iovbuf
,
527 dhdcdc_set_ioctl(dhd
, 0, WLC_SET_VAR
, iovbuf
,
529 #endif /* CUSTOMER_HW2 */
536 static void dhd_suspend_resume_helper(struct dhd_info
*dhd
, int val
)
538 dhd_pub_t
*dhdp
= &dhd
->pub
;
540 dhd_os_proto_block(dhdp
);
541 /* Set flag when early suspend was called */
542 dhdp
->in_suspend
= val
;
543 if (!dhdp
->suspend_disable_flag
)
544 dhd_set_suspend(val
, dhdp
);
545 dhd_os_proto_unblock(dhdp
);
548 static void dhd_early_suspend(struct early_suspend
*h
)
550 struct dhd_info
*dhd
= container_of(h
, struct dhd_info
, early_suspend
);
552 DHD_TRACE(("%s: enter\n", __func__
));
555 dhd_suspend_resume_helper(dhd
, 1);
559 static void dhd_late_resume(struct early_suspend
*h
)
561 struct dhd_info
*dhd
= container_of(h
, struct dhd_info
, early_suspend
);
563 DHD_TRACE(("%s: enter\n", __func__
));
566 dhd_suspend_resume_helper(dhd
, 0);
568 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
571 * Generalized timeout mechanism. Uses spin sleep with exponential
573 * the sleep time reaches one jiffy, then switches over to task delay. Usage:
575 * dhd_timeout_start(&tmo, usec);
576 * while (!dhd_timeout_expired(&tmo))
577 * if (poll_something())
579 * if (dhd_timeout_expired(&tmo))
583 void dhd_timeout_start(dhd_timeout_t
*tmo
, uint usec
)
588 tmo
->tick
= 1000000 / HZ
;
591 int dhd_timeout_expired(dhd_timeout_t
*tmo
)
593 /* Does nothing the first call */
594 if (tmo
->increment
== 0) {
599 if (tmo
->elapsed
>= tmo
->limit
)
602 /* Add the delay that's about to take place */
603 tmo
->elapsed
+= tmo
->increment
;
605 if (tmo
->increment
< tmo
->tick
) {
606 udelay(tmo
->increment
);
608 if (tmo
->increment
> tmo
->tick
)
609 tmo
->increment
= tmo
->tick
;
611 wait_queue_head_t delay_wait
;
612 DECLARE_WAITQUEUE(wait
, current
);
614 init_waitqueue_head(&delay_wait
);
615 add_wait_queue(&delay_wait
, &wait
);
616 set_current_state(TASK_INTERRUPTIBLE
);
618 pending
= signal_pending(current
);
619 remove_wait_queue(&delay_wait
, &wait
);
620 set_current_state(TASK_RUNNING
);
622 return 1; /* Interrupted */
628 static int dhd_net2idx(dhd_info_t
*dhd
, struct net_device
*net
)
633 while (i
< DHD_MAX_IFS
) {
634 if (dhd
->iflist
[i
] && (dhd
->iflist
[i
]->net
== net
))
642 int dhd_ifname2idx(dhd_info_t
*dhd
, char *name
)
648 if (name
== NULL
|| *name
== '\0')
653 && !strncmp(dhd
->iflist
[i
]->name
, name
, IFNAMSIZ
))
656 DHD_TRACE(("%s: return idx %d for \"%s\"\n", __func__
, i
, name
));
658 return i
; /* default - the primary interface */
661 char *dhd_ifname(dhd_pub_t
*dhdp
, int ifidx
)
663 dhd_info_t
*dhd
= (dhd_info_t
*) dhdp
->info
;
667 if (ifidx
< 0 || ifidx
>= DHD_MAX_IFS
) {
668 DHD_ERROR(("%s: ifidx %d out of range\n", __func__
, ifidx
));
672 if (dhd
->iflist
[ifidx
] == NULL
) {
673 DHD_ERROR(("%s: null i/f %d\n", __func__
, ifidx
));
677 if (dhd
->iflist
[ifidx
]->net
)
678 return dhd
->iflist
[ifidx
]->net
->name
;
683 static void _dhd_set_multicast_list(dhd_info_t
*dhd
, int ifidx
)
685 struct net_device
*dev
;
686 struct netdev_hw_addr
*ha
;
694 ASSERT(dhd
&& dhd
->iflist
[ifidx
]);
695 dev
= dhd
->iflist
[ifidx
]->net
;
696 cnt
= netdev_mc_count(dev
);
698 /* Determine initial value of allmulti flag */
699 allmulti
= (dev
->flags
& IFF_ALLMULTI
) ? true : false;
701 /* Send down the multicast list first. */
703 buflen
= sizeof("mcast_list") + sizeof(cnt
) + (cnt
* ETH_ALEN
);
704 bufp
= buf
= kmalloc(buflen
, GFP_ATOMIC
);
706 DHD_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
707 dhd_ifname(&dhd
->pub
, ifidx
), cnt
));
711 strcpy(bufp
, "mcast_list");
712 bufp
+= strlen("mcast_list") + 1;
714 cnt
= cpu_to_le32(cnt
);
715 memcpy(bufp
, &cnt
, sizeof(cnt
));
718 netdev_for_each_mc_addr(ha
, dev
) {
721 memcpy(bufp
, ha
->addr
, ETH_ALEN
);
726 memset(&ioc
, 0, sizeof(ioc
));
727 ioc
.cmd
= WLC_SET_VAR
;
732 ret
= dhd_prot_ioctl(&dhd
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
734 DHD_ERROR(("%s: set mcast_list failed, cnt %d\n",
735 dhd_ifname(&dhd
->pub
, ifidx
), cnt
));
736 allmulti
= cnt
? true : allmulti
;
741 /* Now send the allmulti setting. This is based on the setting in the
742 * net_device flags, but might be modified above to be turned on if we
743 * were trying to set some addresses and dongle rejected it...
746 buflen
= sizeof("allmulti") + sizeof(allmulti
);
747 buf
= kmalloc(buflen
, GFP_ATOMIC
);
749 DHD_ERROR(("%s: out of memory for allmulti\n",
750 dhd_ifname(&dhd
->pub
, ifidx
)));
753 allmulti
= cpu_to_le32(allmulti
);
756 ("allmulti", (void *)&allmulti
, sizeof(allmulti
), buf
, buflen
)) {
757 DHD_ERROR(("%s: mkiovar failed for allmulti, datalen %d "
758 "buflen %u\n", dhd_ifname(&dhd
->pub
, ifidx
),
759 (int)sizeof(allmulti
), buflen
));
764 memset(&ioc
, 0, sizeof(ioc
));
765 ioc
.cmd
= WLC_SET_VAR
;
770 ret
= dhd_prot_ioctl(&dhd
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
772 DHD_ERROR(("%s: set allmulti %d failed\n",
773 dhd_ifname(&dhd
->pub
, ifidx
),
774 le32_to_cpu(allmulti
)));
779 /* Finally, pick up the PROMISC flag as well, like the NIC
782 allmulti
= (dev
->flags
& IFF_PROMISC
) ? true : false;
783 allmulti
= cpu_to_le32(allmulti
);
785 memset(&ioc
, 0, sizeof(ioc
));
786 ioc
.cmd
= WLC_SET_PROMISC
;
788 ioc
.len
= sizeof(allmulti
);
791 ret
= dhd_prot_ioctl(&dhd
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
793 DHD_ERROR(("%s: set promisc %d failed\n",
794 dhd_ifname(&dhd
->pub
, ifidx
),
795 le32_to_cpu(allmulti
)));
800 _dhd_set_mac_address(dhd_info_t
*dhd
, int ifidx
, u8
*addr
)
806 DHD_TRACE(("%s enter\n", __func__
));
808 ("cur_etheraddr", (char *)addr
, ETH_ALEN
, buf
, 32)) {
809 DHD_ERROR(("%s: mkiovar failed for cur_etheraddr\n",
810 dhd_ifname(&dhd
->pub
, ifidx
)));
813 memset(&ioc
, 0, sizeof(ioc
));
814 ioc
.cmd
= WLC_SET_VAR
;
819 ret
= dhd_prot_ioctl(&dhd
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
821 DHD_ERROR(("%s: set cur_etheraddr failed\n",
822 dhd_ifname(&dhd
->pub
, ifidx
)));
824 memcpy(dhd
->iflist
[ifidx
]->net
->dev_addr
, addr
, ETH_ALEN
);
831 extern struct net_device
*ap_net_dev
;
834 static void dhd_op_if(dhd_if_t
*ifp
)
837 int ret
= 0, err
= 0;
839 ASSERT(ifp
&& ifp
->info
&& ifp
->idx
); /* Virtual interfaces only */
843 DHD_TRACE(("%s: idx %d, state %d\n", __func__
, ifp
->idx
, ifp
->state
));
845 switch (ifp
->state
) {
848 * Delete the existing interface before overwriting it
849 * in case we missed the WLC_E_IF_DEL event.
851 if (ifp
->net
!= NULL
) {
852 DHD_ERROR(("%s: ERROR: netdev:%s already exists, "
853 "try free & unregister\n",
854 __func__
, ifp
->net
->name
));
855 netif_stop_queue(ifp
->net
);
856 unregister_netdev(ifp
->net
);
857 free_netdev(ifp
->net
);
859 /* Allocate etherdev, including space for private structure */
860 ifp
->net
= alloc_etherdev(sizeof(dhd
));
862 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__
));
866 strcpy(ifp
->net
->name
, ifp
->name
);
867 memcpy(netdev_priv(ifp
->net
), &dhd
, sizeof(dhd
));
868 err
= dhd_net_attach(&dhd
->pub
, ifp
->idx
);
870 DHD_ERROR(("%s: dhd_net_attach failed, "
876 /* semaphore that the soft AP CODE
878 extern struct semaphore ap_eth_sema
;
880 /* save ptr to wl0.1 netdev for use
882 ap_net_dev
= ifp
->net
;
883 /* signal to the SOFTAP 'sleeper' thread,
887 DHD_TRACE(("\n ==== pid:%x, net_device for "
888 "if:%s created ===\n\n",
889 current
->pid
, ifp
->net
->name
));
895 if (ifp
->net
!= NULL
) {
896 DHD_TRACE(("\n%s: got 'WLC_E_IF_DEL' state\n",
898 netif_stop_queue(ifp
->net
);
899 unregister_netdev(ifp
->net
);
900 ret
= DHD_DEL_IF
; /* Make sure the free_netdev()
905 DHD_ERROR(("%s: bad op %d\n", __func__
, ifp
->state
));
912 free_netdev(ifp
->net
);
914 dhd
->iflist
[ifp
->idx
] = NULL
;
917 if (ifp
->net
== ap_net_dev
)
918 ap_net_dev
= NULL
; /* NULL SOFTAP global
924 static int _dhd_sysioc_thread(void *data
)
926 dhd_info_t
*dhd
= (dhd_info_t
*) data
;
932 allow_signal(SIGTERM
);
934 while (down_interruptible(&dhd
->sysioc_sem
) == 0) {
935 if (kthread_should_stop())
937 for (i
= 0; i
< DHD_MAX_IFS
; i
++) {
938 if (dhd
->iflist
[i
]) {
940 in_ap
= (ap_net_dev
!= NULL
);
942 if (dhd
->iflist
[i
]->state
)
943 dhd_op_if(dhd
->iflist
[i
]);
945 if (dhd
->iflist
[i
] == NULL
) {
946 DHD_TRACE(("\n\n %s: interface %d "
947 "removed!\n", __func__
, i
));
951 if (in_ap
&& dhd
->set_macaddress
) {
952 DHD_TRACE(("attempt to set MAC for %s "
953 "in AP Mode," "blocked. \n",
954 dhd
->iflist
[i
]->net
->name
));
955 dhd
->set_macaddress
= false;
959 if (in_ap
&& dhd
->set_multicast
) {
960 DHD_TRACE(("attempt to set MULTICAST list for %s" "in AP Mode, blocked. \n",
961 dhd
->iflist
[i
]->net
->name
));
962 dhd
->set_multicast
= false;
966 if (dhd
->set_multicast
) {
967 dhd
->set_multicast
= false;
968 _dhd_set_multicast_list(dhd
, i
);
970 if (dhd
->set_macaddress
) {
971 dhd
->set_macaddress
= false;
972 _dhd_set_mac_address(dhd
, i
,
981 static int dhd_set_mac_address(struct net_device
*dev
, void *addr
)
985 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(dev
);
986 struct sockaddr
*sa
= (struct sockaddr
*)addr
;
989 ifidx
= dhd_net2idx(dhd
, dev
);
990 if (ifidx
== DHD_BAD_IF
)
993 ASSERT(dhd
->sysioc_tsk
);
994 memcpy(&dhd
->macvalue
, sa
->sa_data
, ETH_ALEN
);
995 dhd
->set_macaddress
= true;
996 up(&dhd
->sysioc_sem
);
1001 static void dhd_set_multicast_list(struct net_device
*dev
)
1003 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(dev
);
1006 ifidx
= dhd_net2idx(dhd
, dev
);
1007 if (ifidx
== DHD_BAD_IF
)
1010 ASSERT(dhd
->sysioc_tsk
);
1011 dhd
->set_multicast
= true;
1012 up(&dhd
->sysioc_sem
);
1015 int dhd_sendpkt(dhd_pub_t
*dhdp
, int ifidx
, struct sk_buff
*pktbuf
)
1018 dhd_info_t
*dhd
= (dhd_info_t
*) (dhdp
->info
);
1020 /* Reject if down */
1021 if (!dhdp
->up
|| (dhdp
->busstate
== DHD_BUS_DOWN
))
1024 /* Update multicast statistic */
1025 if (pktbuf
->len
>= ETH_ALEN
) {
1026 u8
*pktdata
= (u8
*) (pktbuf
->data
);
1027 struct ethhdr
*eh
= (struct ethhdr
*)pktdata
;
1029 if (is_multicast_ether_addr(eh
->h_dest
))
1030 dhdp
->tx_multicast
++;
1031 if (ntohs(eh
->h_proto
) == ETH_P_PAE
)
1032 atomic_inc(&dhd
->pend_8021x_cnt
);
1035 /* If the protocol uses a data header, apply it */
1036 dhd_prot_hdrpush(dhdp
, ifidx
, pktbuf
);
1038 /* Use bus module to send data frame */
1040 ret
= dbus_send_pkt(dhdp
->dbus
, pktbuf
, NULL
/* pktinfo */);
1042 ret
= dhd_bus_txdata(dhdp
->bus
, pktbuf
);
1043 #endif /* BCMDBUS */
1048 static inline void *
1049 osl_pkt_frmnative(struct sk_buff
*skb
)
1053 #define PKTFRMNATIVE(osh, skb) \
1054 osl_pkt_frmnative((struct sk_buff *)(skb))
1056 static inline struct sk_buff
*
1057 osl_pkt_tonative(void *pkt
)
1059 return (struct sk_buff
*)pkt
;
1061 #define PKTTONATIVE(osh, pkt) \
1062 osl_pkt_tonative((pkt))
1064 static int dhd_start_xmit(struct sk_buff
*skb
, struct net_device
*net
)
1068 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(net
);
1071 DHD_TRACE(("%s: Enter\n", __func__
));
1073 /* Reject if down */
1074 if (!dhd
->pub
.up
|| (dhd
->pub
.busstate
== DHD_BUS_DOWN
)) {
1075 DHD_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n",
1076 __func__
, dhd
->pub
.up
, dhd
->pub
.busstate
));
1077 netif_stop_queue(net
);
1081 ifidx
= dhd_net2idx(dhd
, net
);
1082 if (ifidx
== DHD_BAD_IF
) {
1083 DHD_ERROR(("%s: bad ifidx %d\n", __func__
, ifidx
));
1084 netif_stop_queue(net
);
1088 /* Make sure there's enough room for any header */
1089 if (skb_headroom(skb
) < dhd
->pub
.hdrlen
) {
1090 struct sk_buff
*skb2
;
1092 DHD_INFO(("%s: insufficient headroom\n",
1093 dhd_ifname(&dhd
->pub
, ifidx
)));
1094 dhd
->pub
.tx_realloc
++;
1095 skb2
= skb_realloc_headroom(skb
, dhd
->pub
.hdrlen
);
1099 DHD_ERROR(("%s: skb_realloc_headroom failed\n",
1100 dhd_ifname(&dhd
->pub
, ifidx
)));
1106 /* Convert to packet */
1107 pktbuf
= PKTFRMNATIVE(dhd
->pub
.osh
, skb
);
1109 DHD_ERROR(("%s: PKTFRMNATIVE failed\n",
1110 dhd_ifname(&dhd
->pub
, ifidx
)));
1111 dev_kfree_skb_any(skb
);
1116 ret
= dhd_sendpkt(&dhd
->pub
, ifidx
, pktbuf
);
1120 dhd
->pub
.dstats
.tx_dropped
++;
1122 dhd
->pub
.tx_packets
++;
1124 /* Return ok: we always eat the packet */
1128 void dhd_txflowcontrol(dhd_pub_t
*dhdp
, int ifidx
, bool state
)
1130 struct net_device
*net
;
1131 dhd_info_t
*dhd
= dhdp
->info
;
1133 DHD_TRACE(("%s: Enter\n", __func__
));
1135 dhdp
->txoff
= state
;
1136 ASSERT(dhd
&& dhd
->iflist
[ifidx
]);
1137 net
= dhd
->iflist
[ifidx
]->net
;
1139 netif_stop_queue(net
);
1141 netif_wake_queue(net
);
1144 void dhd_rx_frame(dhd_pub_t
*dhdp
, int ifidx
, struct sk_buff
*pktbuf
,
1147 dhd_info_t
*dhd
= (dhd_info_t
*) dhdp
->info
;
1148 struct sk_buff
*skb
;
1152 struct sk_buff
*pnext
, *save_pktbuf
;
1155 wl_event_msg_t event
;
1157 DHD_TRACE(("%s: Enter\n", __func__
));
1159 save_pktbuf
= pktbuf
;
1161 for (i
= 0; pktbuf
&& i
< numpkt
; i
++, pktbuf
= pnext
) {
1163 pnext
= pktbuf
->next
;
1164 pktbuf
->next
= NULL
;
1166 skb
= PKTTONATIVE(dhdp
->osh
, pktbuf
);
1168 /* Get the protocol, maintain skb around eth_type_trans()
1169 * The main reason for this hack is for the limitation of
1170 * Linux 2.4 where 'eth_type_trans' uses the
1171 * 'net->hard_header_len'
1172 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
1173 * coping of the packet coming from the network stack to add
1174 * BDC, Hardware header etc, during network interface
1176 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
1178 * for BDC, Hardware header etc. and not just the ETH_HLEN
1183 ifp
= dhd
->iflist
[ifidx
];
1185 ifp
= dhd
->iflist
[0];
1188 skb
->dev
= ifp
->net
;
1189 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
1191 if (skb
->pkt_type
== PACKET_MULTICAST
)
1192 dhd
->pub
.rx_multicast
++;
1197 /* Strip header, count, deliver upward */
1198 skb_pull(skb
, ETH_HLEN
);
1200 /* Process special event packets and then discard them */
1201 if (ntohs(skb
->protocol
) == ETH_P_BRCM
)
1202 dhd_wl_host_event(dhd
, &ifidx
,
1203 skb_mac_header(skb
),
1206 ASSERT(ifidx
< DHD_MAX_IFS
&& dhd
->iflist
[ifidx
]);
1207 if (dhd
->iflist
[ifidx
] && !dhd
->iflist
[ifidx
]->state
)
1208 ifp
= dhd
->iflist
[ifidx
];
1211 ifp
->net
->last_rx
= jiffies
;
1213 dhdp
->dstats
.rx_bytes
+= skb
->len
;
1214 dhdp
->rx_packets
++; /* Local count */
1216 if (in_interrupt()) {
1219 /* If the receive is not processed inside an ISR,
1220 * the softirqd must be woken explicitly to service
1221 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
1222 * by netif_rx_ni(), but in earlier kernels, we need
1223 * to do it manually.
1230 void dhd_event(struct dhd_info
*dhd
, char *evpkt
, int evlen
, int ifidx
)
1232 /* Linux version has nothing to do */
1236 void dhd_txcomplete(dhd_pub_t
*dhdp
, struct sk_buff
*txp
, bool success
)
1239 dhd_info_t
*dhd
= (dhd_info_t
*) (dhdp
->info
);
1243 dhd_prot_hdrpull(dhdp
, &ifidx
, txp
);
1245 eh
= (struct ethhdr
*)(txp
->data
);
1246 type
= ntohs(eh
->h_proto
);
1248 if (type
== ETH_P_PAE
)
1249 atomic_dec(&dhd
->pend_8021x_cnt
);
1253 static struct net_device_stats
*dhd_get_stats(struct net_device
*net
)
1255 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(net
);
1259 DHD_TRACE(("%s: Enter\n", __func__
));
1261 ifidx
= dhd_net2idx(dhd
, net
);
1262 if (ifidx
== DHD_BAD_IF
)
1265 ifp
= dhd
->iflist
[ifidx
];
1269 /* Use the protocol to get dongle stats */
1270 dhd_prot_dstats(&dhd
->pub
);
1273 /* Copy dongle stats to net device stats */
1274 ifp
->stats
.rx_packets
= dhd
->pub
.dstats
.rx_packets
;
1275 ifp
->stats
.tx_packets
= dhd
->pub
.dstats
.tx_packets
;
1276 ifp
->stats
.rx_bytes
= dhd
->pub
.dstats
.rx_bytes
;
1277 ifp
->stats
.tx_bytes
= dhd
->pub
.dstats
.tx_bytes
;
1278 ifp
->stats
.rx_errors
= dhd
->pub
.dstats
.rx_errors
;
1279 ifp
->stats
.tx_errors
= dhd
->pub
.dstats
.tx_errors
;
1280 ifp
->stats
.rx_dropped
= dhd
->pub
.dstats
.rx_dropped
;
1281 ifp
->stats
.tx_dropped
= dhd
->pub
.dstats
.tx_dropped
;
1282 ifp
->stats
.multicast
= dhd
->pub
.dstats
.multicast
;
1287 static int dhd_watchdog_thread(void *data
)
1289 dhd_info_t
*dhd
= (dhd_info_t
*) data
;
1291 /* This thread doesn't need any user-level access,
1292 * so get rid of all our resources
1295 if (dhd_watchdog_prio
> 0) {
1296 struct sched_param param
;
1297 param
.sched_priority
= (dhd_watchdog_prio
< MAX_RT_PRIO
) ?
1298 dhd_watchdog_prio
: (MAX_RT_PRIO
- 1);
1299 setScheduler(current
, SCHED_FIFO
, ¶m
);
1301 #endif /* DHD_SCHED */
1303 allow_signal(SIGTERM
);
1304 /* Run until signal received */
1306 if (kthread_should_stop())
1308 if (down_interruptible(&dhd
->watchdog_sem
) == 0) {
1309 if (dhd
->pub
.dongle_reset
== false) {
1310 /* Call the bus module watchdog */
1311 dhd_bus_watchdog(&dhd
->pub
);
1313 /* Count the tick for reference */
1321 static void dhd_watchdog(unsigned long data
)
1323 dhd_info_t
*dhd
= (dhd_info_t
*) data
;
1325 if (dhd
->watchdog_tsk
) {
1326 up(&dhd
->watchdog_sem
);
1328 /* Reschedule the watchdog */
1329 if (dhd
->wd_timer_valid
) {
1330 mod_timer(&dhd
->timer
,
1331 jiffies
+ dhd_watchdog_ms
* HZ
/ 1000);
1336 /* Call the bus module watchdog */
1337 dhd_bus_watchdog(&dhd
->pub
);
1339 /* Count the tick for reference */
1342 /* Reschedule the watchdog */
1343 if (dhd
->wd_timer_valid
)
1344 mod_timer(&dhd
->timer
, jiffies
+ dhd_watchdog_ms
* HZ
/ 1000);
1347 static int dhd_dpc_thread(void *data
)
1349 dhd_info_t
*dhd
= (dhd_info_t
*) data
;
1351 /* This thread doesn't need any user-level access,
1352 * so get rid of all our resources
1355 if (dhd_dpc_prio
> 0) {
1356 struct sched_param param
;
1357 param
.sched_priority
=
1359 MAX_RT_PRIO
) ? dhd_dpc_prio
: (MAX_RT_PRIO
- 1);
1360 setScheduler(current
, SCHED_FIFO
, ¶m
);
1362 #endif /* DHD_SCHED */
1364 allow_signal(SIGTERM
);
1365 /* Run until signal received */
1367 if (kthread_should_stop())
1369 if (down_interruptible(&dhd
->dpc_sem
) == 0) {
1370 /* Call bus dpc unless it indicated down
1371 (then clean stop) */
1372 if (dhd
->pub
.busstate
!= DHD_BUS_DOWN
) {
1373 if (dhd_bus_dpc(dhd
->pub
.bus
)) {
1377 dhd_bus_stop(dhd
->pub
.bus
, true);
1385 static void dhd_dpc(unsigned long data
)
1389 dhd
= (dhd_info_t
*) data
;
1391 /* Call bus dpc unless it indicated down (then clean stop) */
1392 if (dhd
->pub
.busstate
!= DHD_BUS_DOWN
) {
1393 if (dhd_bus_dpc(dhd
->pub
.bus
))
1394 tasklet_schedule(&dhd
->tasklet
);
1396 dhd_bus_stop(dhd
->pub
.bus
, true);
1400 void dhd_sched_dpc(dhd_pub_t
*dhdp
)
1402 dhd_info_t
*dhd
= (dhd_info_t
*) dhdp
->info
;
1409 tasklet_schedule(&dhd
->tasklet
);
1413 /* Retrieve current toe component enables, which are kept
1414 as a bitmap in toe_ol iovar */
1415 static int dhd_toe_get(dhd_info_t
*dhd
, int ifidx
, u32
*toe_ol
)
1421 memset(&ioc
, 0, sizeof(ioc
));
1423 ioc
.cmd
= WLC_GET_VAR
;
1425 ioc
.len
= (uint
) sizeof(buf
);
1428 strcpy(buf
, "toe_ol");
1429 ret
= dhd_prot_ioctl(&dhd
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
1431 /* Check for older dongle image that doesn't support toe_ol */
1433 DHD_ERROR(("%s: toe not supported by device\n",
1434 dhd_ifname(&dhd
->pub
, ifidx
)));
1438 DHD_INFO(("%s: could not get toe_ol: ret=%d\n",
1439 dhd_ifname(&dhd
->pub
, ifidx
), ret
));
1443 memcpy(toe_ol
, buf
, sizeof(u32
));
1447 /* Set current toe component enables in toe_ol iovar,
1448 and set toe global enable iovar */
1449 static int dhd_toe_set(dhd_info_t
*dhd
, int ifidx
, u32 toe_ol
)
1455 memset(&ioc
, 0, sizeof(ioc
));
1457 ioc
.cmd
= WLC_SET_VAR
;
1459 ioc
.len
= (uint
) sizeof(buf
);
1462 /* Set toe_ol as requested */
1464 strcpy(buf
, "toe_ol");
1465 memcpy(&buf
[sizeof("toe_ol")], &toe_ol
, sizeof(u32
));
1467 ret
= dhd_prot_ioctl(&dhd
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
1469 DHD_ERROR(("%s: could not set toe_ol: ret=%d\n",
1470 dhd_ifname(&dhd
->pub
, ifidx
), ret
));
1474 /* Enable toe globally only if any components are enabled. */
1476 toe
= (toe_ol
!= 0);
1479 memcpy(&buf
[sizeof("toe")], &toe
, sizeof(u32
));
1481 ret
= dhd_prot_ioctl(&dhd
->pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
1483 DHD_ERROR(("%s: could not set toe: ret=%d\n",
1484 dhd_ifname(&dhd
->pub
, ifidx
), ret
));
1492 static void dhd_ethtool_get_drvinfo(struct net_device
*net
,
1493 struct ethtool_drvinfo
*info
)
1495 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(net
);
1497 sprintf(info
->driver
, DRV_MODULE_NAME
);
1498 sprintf(info
->version
, "%lu", dhd
->pub
.drv_version
);
1499 sprintf(info
->fw_version
, "%s", wl_cfg80211_get_fwname());
1500 sprintf(info
->bus_info
, "%s", dev_name(&wl_cfg80211_get_sdio_func()->dev
));
1503 struct ethtool_ops dhd_ethtool_ops
= {
1504 .get_drvinfo
= dhd_ethtool_get_drvinfo
1507 static int dhd_ethtool(dhd_info_t
*dhd
, void *uaddr
)
1509 struct ethtool_drvinfo info
;
1510 char drvname
[sizeof(info
.driver
)];
1513 struct ethtool_value edata
;
1514 u32 toe_cmpnt
, csum_dir
;
1518 DHD_TRACE(("%s: Enter\n", __func__
));
1520 /* all ethtool calls start with a cmd word */
1521 if (copy_from_user(&cmd
, uaddr
, sizeof(u32
)))
1525 case ETHTOOL_GDRVINFO
:
1526 /* Copy out any request driver name */
1527 if (copy_from_user(&info
, uaddr
, sizeof(info
)))
1529 strncpy(drvname
, info
.driver
, sizeof(info
.driver
));
1530 drvname
[sizeof(info
.driver
) - 1] = '\0';
1532 /* clear struct for return */
1533 memset(&info
, 0, sizeof(info
));
1536 /* if dhd requested, identify ourselves */
1537 if (strcmp(drvname
, "?dhd") == 0) {
1538 sprintf(info
.driver
, "dhd");
1539 strcpy(info
.version
, EPI_VERSION_STR
);
1542 /* otherwise, require dongle to be up */
1543 else if (!dhd
->pub
.up
) {
1544 DHD_ERROR(("%s: dongle is not up\n", __func__
));
1548 /* finally, report dongle driver type */
1549 else if (dhd
->pub
.iswl
)
1550 sprintf(info
.driver
, "wl");
1552 sprintf(info
.driver
, "xx");
1554 sprintf(info
.version
, "%lu", dhd
->pub
.drv_version
);
1555 if (copy_to_user(uaddr
, &info
, sizeof(info
)))
1557 DHD_CTL(("%s: given %*s, returning %s\n", __func__
,
1558 (int)sizeof(drvname
), drvname
, info
.driver
));
1562 /* Get toe offload components from dongle */
1563 case ETHTOOL_GRXCSUM
:
1564 case ETHTOOL_GTXCSUM
:
1565 ret
= dhd_toe_get(dhd
, 0, &toe_cmpnt
);
1570 (cmd
== ETHTOOL_GTXCSUM
) ? TOE_TX_CSUM_OL
: TOE_RX_CSUM_OL
;
1573 edata
.data
= (toe_cmpnt
& csum_dir
) ? 1 : 0;
1575 if (copy_to_user(uaddr
, &edata
, sizeof(edata
)))
1579 /* Set toe offload components in dongle */
1580 case ETHTOOL_SRXCSUM
:
1581 case ETHTOOL_STXCSUM
:
1582 if (copy_from_user(&edata
, uaddr
, sizeof(edata
)))
1585 /* Read the current settings, update and write back */
1586 ret
= dhd_toe_get(dhd
, 0, &toe_cmpnt
);
1591 (cmd
== ETHTOOL_STXCSUM
) ? TOE_TX_CSUM_OL
: TOE_RX_CSUM_OL
;
1593 if (edata
.data
!= 0)
1594 toe_cmpnt
|= csum_dir
;
1596 toe_cmpnt
&= ~csum_dir
;
1598 ret
= dhd_toe_set(dhd
, 0, toe_cmpnt
);
1602 /* If setting TX checksum mode, tell Linux the new mode */
1603 if (cmd
== ETHTOOL_STXCSUM
) {
1605 dhd
->iflist
[0]->net
->features
|=
1608 dhd
->iflist
[0]->net
->features
&=
1622 static s16 linuxbcmerrormap
[] = { 0, /* 0 */
1623 -EINVAL
, /* BCME_ERROR */
1624 -EINVAL
, /* BCME_BADARG */
1625 -EINVAL
, /* BCME_BADOPTION */
1626 -EINVAL
, /* BCME_NOTUP */
1627 -EINVAL
, /* BCME_NOTDOWN */
1628 -EINVAL
, /* BCME_NOTAP */
1629 -EINVAL
, /* BCME_NOTSTA */
1630 -EINVAL
, /* BCME_BADKEYIDX */
1631 -EINVAL
, /* BCME_RADIOOFF */
1632 -EINVAL
, /* BCME_NOTBANDLOCKED */
1633 -EINVAL
, /* BCME_NOCLK */
1634 -EINVAL
, /* BCME_BADRATESET */
1635 -EINVAL
, /* BCME_BADBAND */
1636 -E2BIG
, /* BCME_BUFTOOSHORT */
1637 -E2BIG
, /* BCME_BUFTOOLONG */
1638 -EBUSY
, /* BCME_BUSY */
1639 -EINVAL
, /* BCME_NOTASSOCIATED */
1640 -EINVAL
, /* BCME_BADSSIDLEN */
1641 -EINVAL
, /* BCME_OUTOFRANGECHAN */
1642 -EINVAL
, /* BCME_BADCHAN */
1643 -EFAULT
, /* BCME_BADADDR */
1644 -ENOMEM
, /* BCME_NORESOURCE */
1645 -EOPNOTSUPP
, /* BCME_UNSUPPORTED */
1646 -EMSGSIZE
, /* BCME_BADLENGTH */
1647 -EINVAL
, /* BCME_NOTREADY */
1648 -EPERM
, /* BCME_NOTPERMITTED */
1649 -ENOMEM
, /* BCME_NOMEM */
1650 -EINVAL
, /* BCME_ASSOCIATED */
1651 -ERANGE
, /* BCME_RANGE */
1652 -EINVAL
, /* BCME_NOTFOUND */
1653 -EINVAL
, /* BCME_WME_NOT_ENABLED */
1654 -EINVAL
, /* BCME_TSPEC_NOTFOUND */
1655 -EINVAL
, /* BCME_ACM_NOTSUPPORTED */
1656 -EINVAL
, /* BCME_NOT_WME_ASSOCIATION */
1657 -EIO
, /* BCME_SDIO_ERROR */
1658 -ENODEV
, /* BCME_DONGLE_DOWN */
1659 -EINVAL
, /* BCME_VERSION */
1660 -EIO
, /* BCME_TXFAIL */
1661 -EIO
, /* BCME_RXFAIL */
1662 -EINVAL
, /* BCME_NODEVICE */
1663 -EINVAL
, /* BCME_NMODE_DISABLED */
1664 -ENODATA
, /* BCME_NONRESIDENT */
1667 static int dhd_ioctl_entry(struct net_device
*net
, struct ifreq
*ifr
, int cmd
)
1669 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(net
);
1676 bool is_set_key_cmd
;
1678 ifidx
= dhd_net2idx(dhd
, net
);
1679 DHD_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __func__
, ifidx
, cmd
));
1681 if (ifidx
== DHD_BAD_IF
)
1684 #if defined(CONFIG_WIRELESS_EXT)
1685 /* linux wireless extensions */
1686 if ((cmd
>= SIOCIWFIRST
) && (cmd
<= SIOCIWLAST
)) {
1687 /* may recurse, do NOT lock */
1688 return wl_iw_ioctl(net
, ifr
, cmd
);
1690 #endif /* defined(CONFIG_WIRELESS_EXT) */
1692 if (cmd
== SIOCETHTOOL
)
1693 return dhd_ethtool(dhd
, (void *)ifr
->ifr_data
);
1695 if (cmd
!= SIOCDEVPRIVATE
)
1698 memset(&ioc
, 0, sizeof(ioc
));
1700 /* Copy the ioc control structure part of ioctl request */
1701 if (copy_from_user(&ioc
, ifr
->ifr_data
, sizeof(wl_ioctl_t
))) {
1702 bcmerror
= -BCME_BADADDR
;
1706 /* Copy out any buffer passed */
1708 buflen
= min_t(int, ioc
.len
, DHD_IOCTL_MAXLEN
);
1709 /* optimization for direct ioctl calls from kernel */
1711 if (segment_eq(get_fs(), KERNEL_DS)) {
1716 buf
= kmalloc(buflen
, GFP_ATOMIC
);
1718 bcmerror
= -BCME_NOMEM
;
1721 if (copy_from_user(buf
, ioc
.buf
, buflen
)) {
1722 bcmerror
= -BCME_BADADDR
;
1728 /* To differentiate between wl and dhd read 4 more byes */
1729 if ((copy_from_user(&driver
, (char *)ifr
->ifr_data
+ sizeof(wl_ioctl_t
),
1730 sizeof(uint
)) != 0)) {
1731 bcmerror
= -BCME_BADADDR
;
1735 if (!capable(CAP_NET_ADMIN
)) {
1736 bcmerror
= -BCME_EPERM
;
1740 /* check for local dhd ioctl and handle it */
1741 if (driver
== DHD_IOCTL_MAGIC
) {
1742 bcmerror
= dhd_ioctl((void *)&dhd
->pub
, &ioc
, buf
, buflen
);
1744 dhd
->pub
.bcmerror
= bcmerror
;
1748 /* send to dongle (must be up, and wl) */
1749 if ((dhd
->pub
.busstate
!= DHD_BUS_DATA
)) {
1750 DHD_ERROR(("%s DONGLE_DOWN,__func__\n", __func__
));
1751 bcmerror
= BCME_DONGLE_DOWN
;
1755 if (!dhd
->pub
.iswl
) {
1756 bcmerror
= BCME_DONGLE_DOWN
;
1760 /* Intercept WLC_SET_KEY IOCTL - serialize M4 send and set key IOCTL to
1761 * prevent M4 encryption.
1763 is_set_key_cmd
= ((ioc
.cmd
== WLC_SET_KEY
) ||
1764 ((ioc
.cmd
== WLC_SET_VAR
) &&
1765 !(strncmp("wsec_key", ioc
.buf
, 9))) ||
1766 ((ioc
.cmd
== WLC_SET_VAR
) &&
1767 !(strncmp("bsscfg:wsec_key", ioc
.buf
, 15))));
1769 dhd_wait_pend8021x(net
);
1772 dhd_prot_ioctl(&dhd
->pub
, ifidx
, (wl_ioctl_t
*)&ioc
, buf
, buflen
);
1775 if (!bcmerror
&& buf
&& ioc
.buf
) {
1776 if (copy_to_user(ioc
.buf
, buf
, buflen
))
1784 else if (bcmerror
< BCME_LAST
)
1785 bcmerror
= BCME_ERROR
;
1787 return linuxbcmerrormap
[-bcmerror
];
1790 static int dhd_stop(struct net_device
*net
)
1792 #if !defined(IGNORE_ETH0_DOWN)
1793 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(net
);
1795 DHD_TRACE(("%s: Enter\n", __func__
));
1796 if (IS_CFG80211_FAVORITE()) {
1799 if (dhd
->pub
.up
== 0)
1802 /* Set state and stop OS transmissions */
1804 netif_stop_queue(net
);
1806 DHD_ERROR(("BYPASS %s:due to BRCM compilation : under investigation\n",
1808 #endif /* !defined(IGNORE_ETH0_DOWN) */
1813 static int dhd_open(struct net_device
*net
)
1815 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(net
);
1819 int ifidx
= dhd_net2idx(dhd
, net
);
1822 DHD_TRACE(("%s: ifidx %d\n", __func__
, ifidx
));
1824 if (ifidx
== 0) { /* do it only for primary eth0 */
1826 /* try to bring up bus */
1827 ret
= dhd_bus_start(&dhd
->pub
);
1829 DHD_ERROR(("%s: failed with code %d\n", __func__
, ret
));
1832 atomic_set(&dhd
->pend_8021x_cnt
, 0);
1834 memcpy(net
->dev_addr
, dhd
->pub
.mac
, ETH_ALEN
);
1837 /* Get current TOE mode from dongle */
1838 if (dhd_toe_get(dhd
, ifidx
, &toe_ol
) >= 0
1839 && (toe_ol
& TOE_TX_CSUM_OL
) != 0)
1840 dhd
->iflist
[ifidx
]->net
->features
|= NETIF_F_IP_CSUM
;
1842 dhd
->iflist
[ifidx
]->net
->features
&= ~NETIF_F_IP_CSUM
;
1845 /* Allow transmit calls */
1846 netif_start_queue(net
);
1848 if (IS_CFG80211_FAVORITE()) {
1849 if (unlikely(wl_cfg80211_up())) {
1850 DHD_ERROR(("%s: failed to bring up cfg80211\n",
1860 dhd_add_if(dhd_info_t
*dhd
, int ifidx
, void *handle
, char *name
,
1861 u8
*mac_addr
, u32 flags
, u8 bssidx
)
1865 DHD_TRACE(("%s: idx %d, handle->%p\n", __func__
, ifidx
, handle
));
1867 ASSERT(dhd
&& (ifidx
< DHD_MAX_IFS
));
1869 ifp
= dhd
->iflist
[ifidx
];
1870 if (!ifp
&& !(ifp
= kmalloc(sizeof(dhd_if_t
), GFP_ATOMIC
))) {
1871 DHD_ERROR(("%s: OOM - dhd_if_t\n", __func__
));
1875 memset(ifp
, 0, sizeof(dhd_if_t
));
1877 dhd
->iflist
[ifidx
] = ifp
;
1878 strlcpy(ifp
->name
, name
, IFNAMSIZ
);
1879 if (mac_addr
!= NULL
)
1880 memcpy(&ifp
->mac_addr
, mac_addr
, ETH_ALEN
);
1882 if (handle
== NULL
) {
1883 ifp
->state
= WLC_E_IF_ADD
;
1885 ASSERT(dhd
->sysioc_tsk
);
1886 up(&dhd
->sysioc_sem
);
1888 ifp
->net
= (struct net_device
*)handle
;
1893 void dhd_del_if(dhd_info_t
*dhd
, int ifidx
)
1897 DHD_TRACE(("%s: idx %d\n", __func__
, ifidx
));
1899 ASSERT(dhd
&& ifidx
&& (ifidx
< DHD_MAX_IFS
));
1900 ifp
= dhd
->iflist
[ifidx
];
1902 DHD_ERROR(("%s: Null interface\n", __func__
));
1906 ifp
->state
= WLC_E_IF_DEL
;
1908 ASSERT(dhd
->sysioc_tsk
);
1909 up(&dhd
->sysioc_sem
);
1912 dhd_pub_t
*dhd_attach(struct dhd_bus
*bus
, uint bus_hdrlen
)
1914 dhd_info_t
*dhd
= NULL
;
1915 struct net_device
*net
;
1917 DHD_TRACE(("%s: Enter\n", __func__
));
1918 /* updates firmware nvram path if it was provided as module
1920 if ((firmware_path
!= NULL
) && (firmware_path
[0] != '\0'))
1921 strcpy(fw_path
, firmware_path
);
1922 if ((nvram_path
!= NULL
) && (nvram_path
[0] != '\0'))
1923 strcpy(nv_path
, nvram_path
);
1925 /* Allocate etherdev, including space for private structure */
1926 net
= alloc_etherdev(sizeof(dhd
));
1928 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__
));
1932 /* Allocate primary dhd_info */
1933 dhd
= kzalloc(sizeof(dhd_info_t
), GFP_ATOMIC
);
1935 DHD_ERROR(("%s: OOM - alloc dhd_info\n", __func__
));
1940 * Save the dhd_info into the priv
1942 memcpy(netdev_priv(net
), &dhd
, sizeof(dhd
));
1944 /* Set network interface name if it was provided as module parameter */
1945 if (iface_name
[0]) {
1948 strncpy(net
->name
, iface_name
, IFNAMSIZ
);
1949 net
->name
[IFNAMSIZ
- 1] = 0;
1950 len
= strlen(net
->name
);
1951 ch
= net
->name
[len
- 1];
1952 if ((ch
> '9' || ch
< '0') && (len
< IFNAMSIZ
- 2))
1953 strcat(net
->name
, "%d");
1956 if (dhd_add_if(dhd
, 0, (void *)net
, net
->name
, NULL
, 0, 0) ==
1960 net
->netdev_ops
= NULL
;
1961 sema_init(&dhd
->proto_sem
, 1);
1962 /* Initialize other structure content */
1963 init_waitqueue_head(&dhd
->ioctl_resp_wait
);
1964 init_waitqueue_head(&dhd
->ctrl_wait
);
1966 /* Initialize the spinlocks */
1967 spin_lock_init(&dhd
->sdlock
);
1968 spin_lock_init(&dhd
->txqlock
);
1970 /* Link to info module */
1971 dhd
->pub
.info
= dhd
;
1973 /* Link to bus module */
1975 dhd
->pub
.hdrlen
= bus_hdrlen
;
1977 /* Attach and link in the protocol */
1978 if (dhd_prot_attach(&dhd
->pub
) != 0) {
1979 DHD_ERROR(("dhd_prot_attach failed\n"));
1982 #if defined(CONFIG_WIRELESS_EXT)
1983 /* Attach and link in the iw */
1984 if (wl_iw_attach(net
, (void *)&dhd
->pub
) != 0) {
1985 DHD_ERROR(("wl_iw_attach failed\n"));
1988 #endif /* defined(CONFIG_WIRELESS_EXT) */
1990 /* Attach and link in the cfg80211 */
1991 if (IS_CFG80211_FAVORITE()) {
1992 if (unlikely(wl_cfg80211_attach(net
, &dhd
->pub
))) {
1993 DHD_ERROR(("wl_cfg80211_attach failed\n"));
1997 strcpy(fw_path
, wl_cfg80211_get_fwname());
1998 strcpy(nv_path
, wl_cfg80211_get_nvramname());
2000 wl_cfg80211_dbg_level(DBG_CFG80211_GET());
2003 /* Set up the watchdog timer */
2004 init_timer(&dhd
->timer
);
2005 dhd
->timer
.data
= (unsigned long) dhd
;
2006 dhd
->timer
.function
= dhd_watchdog
;
2008 /* Initialize thread based operation and lock */
2009 sema_init(&dhd
->sdsem
, 1);
2010 if ((dhd_watchdog_prio
>= 0) && (dhd_dpc_prio
>= 0))
2011 dhd
->threads_only
= true;
2013 dhd
->threads_only
= false;
2015 if (dhd_dpc_prio
>= 0) {
2016 /* Initialize watchdog thread */
2017 sema_init(&dhd
->watchdog_sem
, 0);
2018 dhd
->watchdog_tsk
= kthread_run(dhd_watchdog_thread
, dhd
,
2020 if (IS_ERR(dhd
->watchdog_tsk
)) {
2022 "dhd_watchdog thread failed to start\n");
2023 dhd
->watchdog_tsk
= NULL
;
2026 dhd
->watchdog_tsk
= NULL
;
2029 /* Set up the bottom half handler */
2030 if (dhd_dpc_prio
>= 0) {
2031 /* Initialize DPC thread */
2032 sema_init(&dhd
->dpc_sem
, 0);
2033 dhd
->dpc_tsk
= kthread_run(dhd_dpc_thread
, dhd
, "dhd_dpc");
2034 if (IS_ERR(dhd
->dpc_tsk
)) {
2036 "dhd_dpc thread failed to start\n");
2037 dhd
->dpc_tsk
= NULL
;
2040 tasklet_init(&dhd
->tasklet
, dhd_dpc
, (unsigned long) dhd
);
2041 dhd
->dpc_tsk
= NULL
;
2045 sema_init(&dhd
->sysioc_sem
, 0);
2046 dhd
->sysioc_tsk
= kthread_run(_dhd_sysioc_thread
, dhd
,
2048 if (IS_ERR(dhd
->sysioc_tsk
)) {
2050 "_dhd_sysioc thread failed to start\n");
2051 dhd
->sysioc_tsk
= NULL
;
2054 dhd
->sysioc_tsk
= NULL
;
2057 * Save the dhd_info into the priv
2059 memcpy(netdev_priv(net
), &dhd
, sizeof(dhd
));
2061 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2064 #if defined(CONFIG_PM_SLEEP)
2065 register_pm_notifier(&dhd_sleep_pm_notifier
);
2066 #endif /* defined(CONFIG_PM_SLEEP) */
2067 /* && defined(DHD_GPL) */
2068 /* Init lock suspend to prevent kernel going to suspend */
2069 #ifdef CONFIG_HAS_EARLYSUSPEND
2070 dhd
->early_suspend
.level
= EARLY_SUSPEND_LEVEL_BLANK_SCREEN
+ 20;
2071 dhd
->early_suspend
.suspend
= dhd_early_suspend
;
2072 dhd
->early_suspend
.resume
= dhd_late_resume
;
2073 register_early_suspend(&dhd
->early_suspend
);
2082 dhd_detach(&dhd
->pub
);
2087 int dhd_bus_start(dhd_pub_t
*dhdp
)
2090 dhd_info_t
*dhd
= (dhd_info_t
*) dhdp
->info
;
2091 #ifdef EMBEDDED_PLATFORM
2092 char iovbuf
[WL_EVENTING_MASK_LEN
+ 12]; /* Room for "event_msgs" +
2094 #endif /* EMBEDDED_PLATFORM */
2098 DHD_TRACE(("%s:\n", __func__
));
2100 /* try to download image and nvram to the dongle */
2101 if (dhd
->pub
.busstate
== DHD_BUS_DOWN
) {
2102 if (!(dhd_bus_download_firmware(dhd
->pub
.bus
,
2103 fw_path
, nv_path
))) {
2104 DHD_ERROR(("%s: dhdsdio_probe_download failed. "
2105 "firmware = %s nvram = %s\n",
2106 __func__
, fw_path
, nv_path
));
2111 /* Start the watchdog timer */
2112 dhd
->pub
.tickcnt
= 0;
2113 dhd_os_wd_timer(&dhd
->pub
, dhd_watchdog_ms
);
2115 /* Bring up the bus */
2116 ret
= dhd_bus_init(&dhd
->pub
, true);
2118 DHD_ERROR(("%s, dhd_bus_init failed %d\n", __func__
, ret
));
2121 #if defined(OOB_INTR_ONLY)
2122 /* Host registration for OOB interrupt */
2123 if (bcmsdh_register_oob_intr(dhdp
)) {
2124 del_timer_sync(&dhd
->timer
);
2125 dhd
->wd_timer_valid
= false;
2126 DHD_ERROR(("%s Host failed to resgister for OOB\n", __func__
));
2130 /* Enable oob at firmware */
2131 dhd_enable_oob_intr(dhd
->pub
.bus
, true);
2132 #endif /* defined(OOB_INTR_ONLY) */
2134 /* If bus is not ready, can't come up */
2135 if (dhd
->pub
.busstate
!= DHD_BUS_DATA
) {
2136 del_timer_sync(&dhd
->timer
);
2137 dhd
->wd_timer_valid
= false;
2138 DHD_ERROR(("%s failed bus is not ready\n", __func__
));
2141 #ifdef EMBEDDED_PLATFORM
2142 bcm_mkiovar("event_msgs", dhdp
->eventmask
, WL_EVENTING_MASK_LEN
, iovbuf
,
2144 dhdcdc_query_ioctl(dhdp
, 0, WLC_GET_VAR
, iovbuf
, sizeof(iovbuf
));
2145 memcpy(dhdp
->eventmask
, iovbuf
, WL_EVENTING_MASK_LEN
);
2147 setbit(dhdp
->eventmask
, WLC_E_SET_SSID
);
2148 setbit(dhdp
->eventmask
, WLC_E_PRUNE
);
2149 setbit(dhdp
->eventmask
, WLC_E_AUTH
);
2150 setbit(dhdp
->eventmask
, WLC_E_REASSOC
);
2151 setbit(dhdp
->eventmask
, WLC_E_REASSOC_IND
);
2152 setbit(dhdp
->eventmask
, WLC_E_DEAUTH_IND
);
2153 setbit(dhdp
->eventmask
, WLC_E_DISASSOC_IND
);
2154 setbit(dhdp
->eventmask
, WLC_E_DISASSOC
);
2155 setbit(dhdp
->eventmask
, WLC_E_JOIN
);
2156 setbit(dhdp
->eventmask
, WLC_E_ASSOC_IND
);
2157 setbit(dhdp
->eventmask
, WLC_E_PSK_SUP
);
2158 setbit(dhdp
->eventmask
, WLC_E_LINK
);
2159 setbit(dhdp
->eventmask
, WLC_E_NDIS_LINK
);
2160 setbit(dhdp
->eventmask
, WLC_E_MIC_ERROR
);
2161 setbit(dhdp
->eventmask
, WLC_E_PMKID_CACHE
);
2162 setbit(dhdp
->eventmask
, WLC_E_TXFAIL
);
2163 setbit(dhdp
->eventmask
, WLC_E_JOIN_START
);
2164 setbit(dhdp
->eventmask
, WLC_E_SCAN_COMPLETE
);
2166 setbit(dhdp
->eventmask
, WLC_E_PFN_NET_FOUND
);
2167 #endif /* PNO_SUPPORT */
2169 /* enable dongle roaming event */
2171 dhdp
->pktfilter_count
= 1;
2172 /* Setup filter to allow only unicast */
2173 dhdp
->pktfilter
[0] = "100 0 0 0 0x01 0x00";
2174 #endif /* EMBEDDED_PLATFORM */
2176 /* Bus is ready, do any protocol initialization */
2177 ret
= dhd_prot_init(&dhd
->pub
);
2185 dhd_iovar(dhd_pub_t
*pub
, int ifidx
, char *name
, char *cmd_buf
, uint cmd_len
,
2188 char buf
[strlen(name
) + 1 + cmd_len
];
2189 int len
= sizeof(buf
);
2193 len
= bcm_mkiovar(name
, cmd_buf
, cmd_len
, buf
, len
);
2195 memset(&ioc
, 0, sizeof(ioc
));
2197 ioc
.cmd
= set
? WLC_SET_VAR
: WLC_GET_VAR
;
2202 ret
= dhd_prot_ioctl(pub
, ifidx
, &ioc
, ioc
.buf
, ioc
.len
);
2203 if (!set
&& ret
>= 0)
2204 memcpy(cmd_buf
, buf
, cmd_len
);
2209 static struct net_device_ops dhd_ops_pri
= {
2210 .ndo_open
= dhd_open
,
2211 .ndo_stop
= dhd_stop
,
2212 .ndo_get_stats
= dhd_get_stats
,
2213 .ndo_do_ioctl
= dhd_ioctl_entry
,
2214 .ndo_start_xmit
= dhd_start_xmit
,
2215 .ndo_set_mac_address
= dhd_set_mac_address
,
2216 .ndo_set_multicast_list
= dhd_set_multicast_list
2219 int dhd_net_attach(dhd_pub_t
*dhdp
, int ifidx
)
2221 dhd_info_t
*dhd
= (dhd_info_t
*) dhdp
->info
;
2222 struct net_device
*net
;
2223 u8 temp_addr
[ETH_ALEN
] = {
2224 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
2226 DHD_TRACE(("%s: ifidx %d\n", __func__
, ifidx
));
2228 ASSERT(dhd
&& dhd
->iflist
[ifidx
]);
2230 net
= dhd
->iflist
[ifidx
]->net
;
2233 ASSERT(!net
->netdev_ops
);
2234 net
->netdev_ops
= &dhd_ops_pri
;
2237 * We have to use the primary MAC for virtual interfaces
2240 /* for virtual interfaces use the primary MAC */
2241 memcpy(temp_addr
, dhd
->pub
.mac
, ETH_ALEN
);
2246 DHD_TRACE(("%s ACCESS POINT MAC: \n", __func__
));
2247 /* ACCESSPOINT INTERFACE CASE */
2248 temp_addr
[0] |= 0X02; /* set bit 2 ,
2249 - Locally Administered address */
2252 net
->hard_header_len
= ETH_HLEN
+ dhd
->pub
.hdrlen
;
2253 net
->ethtool_ops
= &dhd_ethtool_ops
;
2255 #if defined(CONFIG_WIRELESS_EXT)
2256 if (!IS_CFG80211_FAVORITE()) {
2257 #if WIRELESS_EXT < 19
2258 net
->get_wireless_stats
= dhd_get_wireless_stats
;
2259 #endif /* WIRELESS_EXT < 19 */
2260 #if WIRELESS_EXT > 12
2261 net
->wireless_handlers
=
2262 (struct iw_handler_def
*)&wl_iw_handler_def
;
2263 #endif /* WIRELESS_EXT > 12 */
2265 #endif /* defined(CONFIG_WIRELESS_EXT) */
2267 dhd
->pub
.rxsz
= net
->mtu
+ net
->hard_header_len
+ dhd
->pub
.hdrlen
;
2269 memcpy(net
->dev_addr
, temp_addr
, ETH_ALEN
);
2271 if (register_netdev(net
) != 0) {
2272 DHD_ERROR(("%s: couldn't register the net device\n",
2277 DHD_INFO(("%s: Broadcom Dongle Host Driver\n", net
->name
));
2282 net
->netdev_ops
= NULL
;
2286 void dhd_bus_detach(dhd_pub_t
*dhdp
)
2290 DHD_TRACE(("%s: Enter\n", __func__
));
2293 dhd
= (dhd_info_t
*) dhdp
->info
;
2295 /* Stop the protocol module */
2296 dhd_prot_stop(&dhd
->pub
);
2298 /* Stop the bus module */
2299 dhd_bus_stop(dhd
->pub
.bus
, true);
2300 #if defined(OOB_INTR_ONLY)
2301 bcmsdh_unregister_oob_intr();
2302 #endif /* defined(OOB_INTR_ONLY) */
2304 /* Clear the watchdog timer */
2305 del_timer_sync(&dhd
->timer
);
2306 dhd
->wd_timer_valid
= false;
2311 void dhd_detach(dhd_pub_t
*dhdp
)
2315 DHD_TRACE(("%s: Enter\n", __func__
));
2318 dhd
= (dhd_info_t
*) dhdp
->info
;
2323 #if defined(CONFIG_HAS_EARLYSUSPEND)
2324 if (dhd
->early_suspend
.suspend
)
2325 unregister_early_suspend(&dhd
->early_suspend
);
2326 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2328 for (i
= 1; i
< DHD_MAX_IFS
; i
++)
2332 ifp
= dhd
->iflist
[0];
2334 if (ifp
->net
->netdev_ops
== &dhd_ops_pri
) {
2336 unregister_netdev(ifp
->net
);
2339 if (dhd
->watchdog_tsk
) {
2340 send_sig(SIGTERM
, dhd
->watchdog_tsk
, 1);
2341 kthread_stop(dhd
->watchdog_tsk
);
2342 dhd
->watchdog_tsk
= NULL
;
2346 send_sig(SIGTERM
, dhd
->dpc_tsk
, 1);
2347 kthread_stop(dhd
->dpc_tsk
);
2348 dhd
->dpc_tsk
= NULL
;
2350 tasklet_kill(&dhd
->tasklet
);
2352 if (dhd
->sysioc_tsk
) {
2353 send_sig(SIGTERM
, dhd
->sysioc_tsk
, 1);
2354 kthread_stop(dhd
->sysioc_tsk
);
2355 dhd
->sysioc_tsk
= NULL
;
2358 dhd_bus_detach(dhdp
);
2361 dhd_prot_detach(dhdp
);
2363 #if defined(CONFIG_WIRELESS_EXT)
2365 #endif /* (CONFIG_WIRELESS_EXT) */
2367 if (IS_CFG80211_FAVORITE())
2368 wl_cfg80211_detach();
2370 #if defined(CONFIG_PM_SLEEP)
2371 unregister_pm_notifier(&dhd_sleep_pm_notifier
);
2372 #endif /* defined(CONFIG_PM_SLEEP) */
2373 /* && defined(DHD_GPL) */
2374 free_netdev(ifp
->net
);
2381 static void __exit
dhd_module_cleanup(void)
2383 DHD_TRACE(("%s: Enter\n", __func__
));
2385 dhd_bus_unregister();
2386 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2389 /* Call customer gpio to turn off power with WL_REG_ON signal */
2390 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF
);
2393 static int __init
dhd_module_init(void)
2397 DHD_TRACE(("%s: Enter\n", __func__
));
2399 /* Sanity check on the module parameters */
2401 /* Both watchdog and DPC as tasklets are ok */
2402 if ((dhd_watchdog_prio
< 0) && (dhd_dpc_prio
< 0))
2405 /* If both watchdog and DPC are threads, TX must be deferred */
2406 if ((dhd_watchdog_prio
>= 0) && (dhd_dpc_prio
>= 0)
2410 DHD_ERROR(("Invalid module parameters.\n"));
2413 /* Call customer gpio to turn on power with WL_REG_ON signal */
2414 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_ON
);
2416 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2417 sema_init(&wifi_control_sem
, 0);
2419 error
= wifi_add_dev();
2421 DHD_ERROR(("%s: platform_driver_register failed\n", __func__
));
2425 /* Waiting callback after platform_driver_register is done or
2427 if (down_timeout(&wifi_control_sem
, msecs_to_jiffies(1000)) != 0) {
2428 printk(KERN_ERR
"%s: platform_driver_register timeout\n",
2434 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2436 error
= dhd_bus_register();
2439 DHD_ERROR(("%s: sdio_register_driver failed\n", __func__
));
2445 /* turn off power and exit */
2446 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF
);
2450 module_init(dhd_module_init
);
2451 module_exit(dhd_module_cleanup
);
2454 * OS specific functions required to implement DHD driver in OS independent way
2456 int dhd_os_proto_block(dhd_pub_t
*pub
)
2458 dhd_info_t
*dhd
= (dhd_info_t
*) (pub
->info
);
2461 down(&dhd
->proto_sem
);
2467 int dhd_os_proto_unblock(dhd_pub_t
*pub
)
2469 dhd_info_t
*dhd
= (dhd_info_t
*) (pub
->info
);
2472 up(&dhd
->proto_sem
);
2479 unsigned int dhd_os_get_ioctl_resp_timeout(void)
2481 return (unsigned int)dhd_ioctl_timeout_msec
;
2484 void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec
)
2486 dhd_ioctl_timeout_msec
= (int)timeout_msec
;
2489 int dhd_os_ioctl_resp_wait(dhd_pub_t
*pub
, uint
*condition
, bool *pending
)
2491 dhd_info_t
*dhd
= (dhd_info_t
*) (pub
->info
);
2492 DECLARE_WAITQUEUE(wait
, current
);
2493 int timeout
= dhd_ioctl_timeout_msec
;
2495 /* Convert timeout in millsecond to jiffies */
2496 timeout
= timeout
* HZ
/ 1000;
2498 /* Wait until control frame is available */
2499 add_wait_queue(&dhd
->ioctl_resp_wait
, &wait
);
2500 set_current_state(TASK_INTERRUPTIBLE
);
2502 while (!(*condition
) && (!signal_pending(current
) && timeout
))
2503 timeout
= schedule_timeout(timeout
);
2505 if (signal_pending(current
))
2508 set_current_state(TASK_RUNNING
);
2509 remove_wait_queue(&dhd
->ioctl_resp_wait
, &wait
);
2514 int dhd_os_ioctl_resp_wake(dhd_pub_t
*pub
)
2516 dhd_info_t
*dhd
= (dhd_info_t
*) (pub
->info
);
2518 if (waitqueue_active(&dhd
->ioctl_resp_wait
))
2519 wake_up_interruptible(&dhd
->ioctl_resp_wait
);
2524 void dhd_os_wd_timer(void *bus
, uint wdtick
)
2526 dhd_pub_t
*pub
= bus
;
2527 static uint save_dhd_watchdog_ms
;
2528 dhd_info_t
*dhd
= (dhd_info_t
*) pub
->info
;
2530 /* don't start the wd until fw is loaded */
2531 if (pub
->busstate
== DHD_BUS_DOWN
)
2534 /* Totally stop the timer */
2535 if (!wdtick
&& dhd
->wd_timer_valid
== true) {
2536 del_timer_sync(&dhd
->timer
);
2537 dhd
->wd_timer_valid
= false;
2538 save_dhd_watchdog_ms
= wdtick
;
2543 dhd_watchdog_ms
= (uint
) wdtick
;
2545 if (save_dhd_watchdog_ms
!= dhd_watchdog_ms
) {
2547 if (dhd
->wd_timer_valid
== true)
2548 /* Stop timer and restart at new value */
2549 del_timer_sync(&dhd
->timer
);
2551 /* Create timer again when watchdog period is
2552 dynamically changed or in the first instance
2554 dhd
->timer
.expires
=
2555 jiffies
+ dhd_watchdog_ms
* HZ
/ 1000;
2556 add_timer(&dhd
->timer
);
2559 /* Re arm the timer, at last watchdog period */
2560 mod_timer(&dhd
->timer
,
2561 jiffies
+ dhd_watchdog_ms
* HZ
/ 1000);
2564 dhd
->wd_timer_valid
= true;
2565 save_dhd_watchdog_ms
= wdtick
;
2569 void *dhd_os_open_image(char *filename
)
2573 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2574 return wl_cfg80211_request_fw(filename
);
2576 fp
= filp_open(filename
, O_RDONLY
, 0);
2578 * 2.6.11 (FC4) supports filp_open() but later revs don't?
2580 * fp = open_namei(AT_FDCWD, filename, O_RD, 0);
2589 int dhd_os_get_image_block(char *buf
, int len
, void *image
)
2591 struct file
*fp
= (struct file
*)image
;
2594 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2595 return wl_cfg80211_read_fw(buf
, len
);
2600 rdlen
= kernel_read(fp
, fp
->f_pos
, buf
, len
);
2607 void dhd_os_close_image(void *image
)
2609 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2610 return wl_cfg80211_release_fw();
2612 filp_close((struct file
*)image
, NULL
);
2615 void dhd_os_sdlock(dhd_pub_t
*pub
)
2619 dhd
= (dhd_info_t
*) (pub
->info
);
2621 if (dhd
->threads_only
)
2624 spin_lock_bh(&dhd
->sdlock
);
2627 void dhd_os_sdunlock(dhd_pub_t
*pub
)
2631 dhd
= (dhd_info_t
*) (pub
->info
);
2633 if (dhd
->threads_only
)
2636 spin_unlock_bh(&dhd
->sdlock
);
2639 void dhd_os_sdlock_txq(dhd_pub_t
*pub
)
2643 dhd
= (dhd_info_t
*) (pub
->info
);
2644 spin_lock_bh(&dhd
->txqlock
);
2647 void dhd_os_sdunlock_txq(dhd_pub_t
*pub
)
2651 dhd
= (dhd_info_t
*) (pub
->info
);
2652 spin_unlock_bh(&dhd
->txqlock
);
2655 void dhd_os_sdlock_rxq(dhd_pub_t
*pub
)
2659 void dhd_os_sdunlock_rxq(dhd_pub_t
*pub
)
2663 void dhd_os_sdtxlock(dhd_pub_t
*pub
)
2668 void dhd_os_sdtxunlock(dhd_pub_t
*pub
)
2670 dhd_os_sdunlock(pub
);
2673 #if defined(CONFIG_WIRELESS_EXT)
2674 struct iw_statistics
*dhd_get_wireless_stats(struct net_device
*dev
)
2677 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(dev
);
2679 res
= wl_iw_get_wireless_stats(dev
, &dhd
->iw
.wstats
);
2682 return &dhd
->iw
.wstats
;
2686 #endif /* defined(CONFIG_WIRELESS_EXT) */
2689 dhd_wl_host_event(dhd_info_t
*dhd
, int *ifidx
, void *pktdata
,
2690 wl_event_msg_t
*event
, void **data
)
2694 ASSERT(dhd
!= NULL
);
2696 bcmerror
= wl_host_event(dhd
, ifidx
, pktdata
, event
, data
);
2697 if (bcmerror
!= BCME_OK
)
2700 #if defined(CONFIG_WIRELESS_EXT)
2701 if (!IS_CFG80211_FAVORITE()) {
2702 if ((dhd
->iflist
[*ifidx
] == NULL
)
2703 || (dhd
->iflist
[*ifidx
]->net
== NULL
)) {
2704 DHD_ERROR(("%s Exit null pointer\n", __func__
));
2708 if (dhd
->iflist
[*ifidx
]->net
)
2709 wl_iw_event(dhd
->iflist
[*ifidx
]->net
, event
, *data
);
2711 #endif /* defined(CONFIG_WIRELESS_EXT) */
2713 if (IS_CFG80211_FAVORITE()) {
2714 ASSERT(dhd
->iflist
[*ifidx
] != NULL
);
2715 ASSERT(dhd
->iflist
[*ifidx
]->net
!= NULL
);
2716 if (dhd
->iflist
[*ifidx
]->net
)
2717 wl_cfg80211_event(dhd
->iflist
[*ifidx
]->net
, event
,
2724 /* send up locally generated event */
2725 void dhd_sendup_event(dhd_pub_t
*dhdp
, wl_event_msg_t
*event
, void *data
)
2727 switch (be32_to_cpu(event
->event_type
)) {
2733 void dhd_wait_for_event(dhd_pub_t
*dhd
, bool *lockvar
)
2735 struct dhd_info
*dhdinfo
= dhd
->info
;
2736 dhd_os_sdunlock(dhd
);
2737 wait_event_interruptible_timeout(dhdinfo
->ctrl_wait
,
2738 (*lockvar
== false), HZ
* 2);
2743 void dhd_wait_event_wakeup(dhd_pub_t
*dhd
)
2745 struct dhd_info
*dhdinfo
= dhd
->info
;
2746 if (waitqueue_active(&dhdinfo
->ctrl_wait
))
2747 wake_up_interruptible(&dhdinfo
->ctrl_wait
);
2751 int dhd_dev_reset(struct net_device
*dev
, u8 flag
)
2753 dhd_info_t
*dhd
= *(dhd_info_t
**)netdev_priv(dev
);
2755 /* Turning off watchdog */
2757 dhd_os_wd_timer(&dhd
->pub
, 0);
2759 dhd_bus_devreset(&dhd
->pub
, flag
);
2761 /* Turning on watchdog back */
2763 dhd_os_wd_timer(&dhd
->pub
, dhd_watchdog_ms
);
2764 DHD_ERROR(("%s: WLAN OFF DONE\n", __func__
));
2769 int net_os_set_suspend_disable(struct net_device
*dev
, int val
)
2771 dhd_info_t
*dhd
= *(dhd_info_t
**)netdev_priv(dev
);
2775 ret
= dhd
->pub
.suspend_disable_flag
;
2776 dhd
->pub
.suspend_disable_flag
= val
;
2781 int net_os_set_suspend(struct net_device
*dev
, int val
)
2784 #if defined(CONFIG_HAS_EARLYSUSPEND)
2785 dhd_info_t
*dhd
= *(dhd_info_t
**)netdev_priv(dev
);
2788 dhd_os_proto_block(&dhd
->pub
);
2789 ret
= dhd_set_suspend(val
, &dhd
->pub
);
2790 dhd_os_proto_unblock(&dhd
->pub
);
2792 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2796 int net_os_set_dtim_skip(struct net_device
*dev
, int val
)
2798 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(dev
);
2801 dhd
->pub
.dtim_skip
= val
;
2806 int net_os_set_packet_filter(struct net_device
*dev
, int val
)
2808 dhd_info_t
*dhd
= *(dhd_info_t
**) netdev_priv(dev
);
2811 /* Packet filtering is set only if we still in early-suspend and
2812 * we need either to turn it ON or turn it OFF
2813 * We can always turn it OFF in case of early-suspend, but we turn it
2814 * back ON only if suspend_disable_flag was not set
2816 if (dhd
&& dhd
->pub
.up
) {
2817 dhd_os_proto_block(&dhd
->pub
);
2818 if (dhd
->pub
.in_suspend
) {
2819 if (!val
|| (val
&& !dhd
->pub
.suspend_disable_flag
))
2820 dhd_set_packet_filter(val
, &dhd
->pub
);
2822 dhd_os_proto_unblock(&dhd
->pub
);
2827 void dhd_dev_init_ioctl(struct net_device
*dev
)
2829 dhd_info_t
*dhd
= *(dhd_info_t
**)netdev_priv(dev
);
2831 dhd_preinit_ioctls(&dhd
->pub
);
2835 /* Linux wrapper to call common dhd_pno_clean */
2836 int dhd_dev_pno_reset(struct net_device
*dev
)
2838 dhd_info_t
*dhd
= *(dhd_info_t
**)netdev_priv(dev
);
2840 return dhd_pno_clean(&dhd
->pub
);
2843 /* Linux wrapper to call common dhd_pno_enable */
2844 int dhd_dev_pno_enable(struct net_device
*dev
, int pfn_enabled
)
2846 dhd_info_t
*dhd
= *(dhd_info_t
**)netdev_priv(dev
);
2848 return dhd_pno_enable(&dhd
->pub
, pfn_enabled
);
2851 /* Linux wrapper to call common dhd_pno_set */
2853 dhd_dev_pno_set(struct net_device
*dev
, wlc_ssid_t
*ssids_local
, int nssid
,
2854 unsigned char scan_fr
)
2856 dhd_info_t
*dhd
= *(dhd_info_t
**)netdev_priv(dev
);
2858 return dhd_pno_set(&dhd
->pub
, ssids_local
, nssid
, scan_fr
);
2861 /* Linux wrapper to get pno status */
2862 int dhd_dev_get_pno_status(struct net_device
*dev
)
2864 dhd_info_t
*dhd
= *(dhd_info_t
**)netdev_priv(dev
);
2866 return dhd_pno_get_status(&dhd
->pub
);
2869 #endif /* PNO_SUPPORT */
2871 static int dhd_get_pend_8021x_cnt(dhd_info_t
*dhd
)
2873 return atomic_read(&dhd
->pend_8021x_cnt
);
2876 #define MAX_WAIT_FOR_8021X_TX 10
2878 int dhd_wait_pend8021x(struct net_device
*dev
)
2880 dhd_info_t
*dhd
= *(dhd_info_t
**)netdev_priv(dev
);
2881 int timeout
= 10 * HZ
/ 1000;
2882 int ntimes
= MAX_WAIT_FOR_8021X_TX
;
2883 int pend
= dhd_get_pend_8021x_cnt(dhd
);
2885 while (ntimes
&& pend
) {
2887 set_current_state(TASK_INTERRUPTIBLE
);
2888 schedule_timeout(timeout
);
2889 set_current_state(TASK_RUNNING
);
2892 pend
= dhd_get_pend_8021x_cnt(dhd
);
2898 int write_to_file(dhd_pub_t
*dhd
, u8
*buf
, int size
)
2902 mm_segment_t old_fs
;
2905 /* change to KERNEL_DS address limit */
2909 /* open file to write */
2910 fp
= filp_open("/tmp/mem_dump", O_WRONLY
| O_CREAT
, 0640);
2912 DHD_ERROR(("%s: open file error\n", __func__
));
2917 /* Write buf to file */
2918 fp
->f_op
->write(fp
, buf
, size
, &pos
);
2921 /* free buf before return */
2923 /* close file before return */
2925 filp_close(fp
, current
->files
);
2926 /* restore previous address limit */
2931 #endif /* DHD_DEBUG */