2 #include "wilc_wfi_cfgoperations.h"
3 #include "linux_wlan_common.h"
4 #include "wilc_wlan_if.h"
7 #include "wilc_wfi_cfgoperations.h"
10 #include "linux_wlan_common.h"
12 #include <linux/slab.h>
13 #include <linux/sched.h>
14 #include <linux/delay.h>
15 #include <linux/workqueue.h>
16 #include <linux/interrupt.h>
17 #include <linux/irq.h>
18 #include <linux/gpio.h>
20 #include <linux/kthread.h>
21 #include <linux/firmware.h>
22 #include <linux/delay.h>
24 #include <linux/init.h>
25 #include <linux/netdevice.h>
26 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
27 #include <linux/inetdevice.h>
29 #include <linux/etherdevice.h>
30 #include <linux/module.h>
31 #include <linux/kernel.h>
32 #include <linux/skbuff.h>
34 #include <linux/version.h>
35 #include <linux/semaphore.h>
38 #include "linux_wlan_sdio.h"
40 #include "linux_wlan_spi.h"
43 #ifdef WILC_FULLY_HOSTING_AP
44 #include "wilc_host_ap.h"
47 #ifdef STATIC_MACADDRESS /* brandy_0724 [[ */
48 #include <linux/vmalloc.h>
50 struct task_struct *wilc_mac_thread;
51 unsigned char mac_add[] = {0x00, 0x80, 0xC2, 0x5E, 0xa2, 0xb2};
52 #endif /* brandy_0724 ]] */
54 #if defined(CUSTOMER_PLATFORM)
56 TODO : Write power control functions as customer platform.
60 #define _linux_wlan_device_power_on() {}
61 #define _linux_wlan_device_power_off() {}
63 #define _linux_wlan_device_detection() {}
64 #define _linux_wlan_device_removal() {}
67 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
68 extern bool g_obtainingIP;
70 extern u16 Set_machw_change_vir_if(bool bValue);
71 extern void resolve_disconnect_aberration(void *drvHandler);
72 extern u8 gau8MulticastMacAddrList[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN];
73 void wilc1000_wlan_deinit(linux_wlan_t *nic);
74 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
75 extern WILC_TimerHandle hDuringIpTimer;
78 static int linux_wlan_device_power(int on_off)
80 PRINT_D(INIT_DBG, "linux_wlan_device_power.. (%d)\n", on_off);
83 _linux_wlan_device_power_on();
85 _linux_wlan_device_power_off();
91 static int linux_wlan_device_detection(int on_off)
93 PRINT_D(INIT_DBG, "linux_wlan_device_detection.. (%d)\n", on_off);
97 _linux_wlan_device_detection();
99 _linux_wlan_device_removal();
107 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
108 static int dev_state_ev_handler(struct notifier_block *this, unsigned long event, void *ptr);
110 static struct notifier_block g_dev_notifier = {
111 .notifier_call = dev_state_ev_handler
115 #define wilc_wlan_deinit(nic) { if (&g_linux_wlan->oup != NULL) \
116 if (g_linux_wlan->oup.wlan_cleanup != NULL) \
117 g_linux_wlan->oup.wlan_cleanup(); }
121 #define STA_FIRMWARE "wifi_firmware.bin"
125 #define AP_FIRMWARE "wifi_firmware_ap.bin"
128 #ifndef P2P_CONCURRENCY_FIRMWARE
129 #define P2P_CONCURRENCY_FIRMWARE "wifi_firmware_p2p_concurrency.bin"
134 typedef struct android_wifi_priv_cmd {
138 } android_wifi_priv_cmd;
142 #define IRQ_NO_WAIT 0
144 * to sync between mac_close and module exit.
145 * don't initialize or de-initialize from init/deinitlocks
146 * to be initialized from module wilc_netdev_init and
147 * deinitialized from mdoule_exit
149 static struct semaphore close_exit_sync;
150 unsigned int int_rcvdU;
151 unsigned int int_rcvdB;
152 unsigned int int_clrd;
154 static int wlan_deinit_locks(linux_wlan_t *nic);
155 static void wlan_deinitialize_threads(linux_wlan_t *nic);
156 static void linux_wlan_lock(void *vp);
157 void linux_wlan_unlock(void *vp);
158 extern void WILC_WFI_monitor_rx(uint8_t *buff, uint32_t size);
159 extern void WILC_WFI_p2p_rx(struct net_device *dev, uint8_t *buff, uint32_t size);
162 static void *internal_alloc(uint32_t size, uint32_t flag);
163 static void linux_wlan_tx_complete(void *priv, int status);
164 void frmw_to_linux(uint8_t *buff, uint32_t size, uint32_t pkt_offset);
165 static int mac_init_fn(struct net_device *ndev);
166 int mac_xmit(struct sk_buff *skb, struct net_device *dev);
167 int mac_open(struct net_device *ndev);
168 int mac_close(struct net_device *ndev);
169 static struct net_device_stats *mac_stats(struct net_device *dev);
170 static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd);
171 static void wilc_set_multicast_list(struct net_device *dev);
176 * for now - in frmw_to_linux there should be private data to be passed to it
177 * and this data should be pointer to net device
179 linux_wlan_t *g_linux_wlan;
180 wilc_wlan_oup_t *gpstrWlanOps;
181 bool bEnablePS = true;
183 static const struct net_device_ops wilc_netdev_ops = {
184 .ndo_init = mac_init_fn,
185 .ndo_open = mac_open,
186 .ndo_stop = mac_close,
187 .ndo_start_xmit = mac_xmit,
188 .ndo_do_ioctl = mac_ioctl,
189 .ndo_get_stats = mac_stats,
190 .ndo_set_rx_mode = wilc_set_multicast_list,
196 extern volatile int timeNo;
198 #define DEGUG_BUFFER_LENGTH 1000
199 volatile int WatchDogdebuggerCounter;
200 char DebugBuffer[DEGUG_BUFFER_LENGTH + 20] = {0};
201 static char *ps8current = DebugBuffer;
205 void printk_later(const char *format, ...)
208 va_start (args, format);
209 ps8current += vsprintf (ps8current, format, args);
211 if ((ps8current - DebugBuffer) > DEGUG_BUFFER_LENGTH) {
212 ps8current = DebugBuffer;
220 if (DebugBuffer[0]) {
221 DebugBuffer[DEGUG_BUFFER_LENGTH] = 0;
222 PRINT_INFO(GENERIC_DBG, "early printed\n");
223 PRINT_D(GENERIC_DBG, ps8current + 1);
225 PRINT_INFO(GENERIC_DBG, "latest printed\n");
226 PRINT_D(GENERIC_DBG, DebugBuffer);
228 ps8current = DebugBuffer;
232 void Reset_WatchDogdebugger()
234 WatchDogdebuggerCounter = 0;
237 static int DebuggingThreadTask(void *vp)
240 while (!WatchDogdebuggerCounter) {
241 PRINT_D(GENERIC_DBG, "Debug Thread Running %d\n", timeNo);
242 WatchDogdebuggerCounter = 1;
246 WatchDogdebuggerCounter = 0;
254 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
255 static int dev_state_ev_handler(struct notifier_block *this, unsigned long event, void *ptr)
257 struct in_ifaddr *dev_iface = (struct in_ifaddr *)ptr;
258 struct WILC_WFI_priv *priv;
259 tstrWILC_WFIDrv *pstrWFIDrv;
260 struct net_device *dev;
262 perInterface_wlan_t *nic;
264 char wlan_dev_name[5] = "wlan0";
266 if (dev_iface == NULL || dev_iface->ifa_dev == NULL || dev_iface->ifa_dev->dev == NULL) {
267 PRINT_D(GENERIC_DBG, "dev_iface = NULL\n");
271 if ((memcmp(dev_iface->ifa_label, "wlan0", 5)) && (memcmp(dev_iface->ifa_label, "p2p0", 4))) {
272 PRINT_D(GENERIC_DBG, "Interface is neither WLAN0 nor P2P0\n");
276 dev = (struct net_device *)dev_iface->ifa_dev->dev;
277 if (dev->ieee80211_ptr == NULL || dev->ieee80211_ptr->wiphy == NULL) {
278 PRINT_D(GENERIC_DBG, "No Wireless registerd\n");
281 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
283 PRINT_D(GENERIC_DBG, "No Wireless Priv\n");
286 pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
287 nic = netdev_priv(dev);
288 if (nic == NULL || pstrWFIDrv == NULL) {
289 PRINT_D(GENERIC_DBG, "No Wireless Priv\n");
293 PRINT_INFO(GENERIC_DBG, "dev_state_ev_handler +++\n"); /* tony */
297 PRINT_D(GENERIC_DBG, "dev_state_ev_handler event=NETDEV_UP %p\n", dev); /* tony */
299 PRINT_INFO(GENERIC_DBG, "\n ============== IP Address Obtained ===============\n\n");
302 /*If we are in station mode or client mode*/
303 if (nic->iftype == STATION_MODE || nic->iftype == CLIENT_MODE) {
304 pstrWFIDrv->IFC_UP = 1;
305 g_obtainingIP = false;
306 WILC_TimerStop(&hDuringIpTimer, NULL);
307 PRINT_D(GENERIC_DBG, "IP obtained , enable scan\n");
312 if (bEnablePS == true)
313 host_int_set_power_mgmt((WILC_WFIDrvHandle)pstrWFIDrv, 1, 0);
315 PRINT_D(GENERIC_DBG, "[%s] Up IP\n", dev_iface->ifa_label);
317 pIP_Add_buff = (char *) (&(dev_iface->ifa_address));
318 PRINT_D(GENERIC_DBG, "IP add=%d:%d:%d:%d \n", pIP_Add_buff[0], pIP_Add_buff[1], pIP_Add_buff[2], pIP_Add_buff[3]);
319 host_int_setup_ipaddress((WILC_WFIDrvHandle)pstrWFIDrv, pIP_Add_buff, nic->u8IfIdx);
324 PRINT_D(GENERIC_DBG, "dev_state_ev_handler event=NETDEV_DOWN %p\n", dev); /* tony */
326 PRINT_INFO(GENERIC_DBG, "\n ============== IP Address Released ===============\n\n");
327 if (nic->iftype == STATION_MODE || nic->iftype == CLIENT_MODE) {
328 pstrWFIDrv->IFC_UP = 0;
329 g_obtainingIP = false;
332 if (memcmp(dev_iface->ifa_label, wlan_dev_name, 5) == 0)
333 host_int_set_power_mgmt((WILC_WFIDrvHandle)pstrWFIDrv, 0, 0);
335 resolve_disconnect_aberration(pstrWFIDrv);
338 PRINT_D(GENERIC_DBG, "[%s] Down IP\n", dev_iface->ifa_label);
340 pIP_Add_buff = null_ip;
341 PRINT_D(GENERIC_DBG, "IP add=%d:%d:%d:%d \n", pIP_Add_buff[0], pIP_Add_buff[1], pIP_Add_buff[2], pIP_Add_buff[3]);
343 host_int_setup_ipaddress((WILC_WFIDrvHandle)pstrWFIDrv, pIP_Add_buff, nic->u8IfIdx);
348 PRINT_INFO(GENERIC_DBG, "dev_state_ev_handler event=default\n"); /* tony */
349 PRINT_INFO(GENERIC_DBG, "[%s] unknown dev event: %lu\n", dev_iface->ifa_label, event);
360 * Interrupt initialization and handling functions
363 void linux_wlan_enable_irq(void)
366 #if (RX_BH_TYPE != RX_BH_THREADED_IRQ)
367 #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
368 PRINT_D(INT_DBG, "Enabling IRQ ...\n");
369 enable_irq(g_linux_wlan->dev_irq_num);
374 void linux_wlan_disable_irq(int wait)
376 #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
378 PRINT_D(INT_DBG, "Disabling IRQ ...\n");
379 disable_irq(g_linux_wlan->dev_irq_num);
381 PRINT_D(INT_DBG, "Disabling IRQ ...\n");
382 disable_irq_nosync(g_linux_wlan->dev_irq_num);
387 #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
388 static irqreturn_t isr_uh_routine(int irq, void *user_data)
393 #if (RX_BH_TYPE != RX_BH_THREADED_IRQ)
394 linux_wlan_disable_irq(IRQ_NO_WAIT);
396 PRINT_D(INT_DBG, "Interrupt received UH\n");
398 /*While mac is closing cacncel the handling of any interrupts received*/
399 if (g_linux_wlan->close) {
400 PRINT_ER("Driver is CLOSING: Can't handle UH interrupt\n");
401 #if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
408 #if (RX_BH_TYPE == RX_BH_WORK_QUEUE)
409 schedule_work(&g_linux_wlan->rx_work_queue);
411 #elif (RX_BH_TYPE == RX_BH_KTHREAD)
412 linux_wlan_unlock(&g_linux_wlan->rx_sem);
414 #elif (RX_BH_TYPE == RX_BH_THREADED_IRQ)
415 return IRQ_WAKE_THREAD;
421 #if (RX_BH_TYPE == RX_BH_WORK_QUEUE || RX_BH_TYPE == RX_BH_THREADED_IRQ)
423 #if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
424 irqreturn_t isr_bh_routine(int irq, void *userdata)
427 nic = (linux_wlan_t *)userdata;
429 static void isr_bh_routine(struct work_struct *work)
431 perInterface_wlan_t *nic;
432 nic = (perInterface_wlan_t *)container_of(work, linux_wlan_t, rx_work_queue);
435 /*While mac is closing cacncel the handling of any interrupts received*/
436 if (g_linux_wlan->close) {
437 PRINT_ER("Driver is CLOSING: Can't handle BH interrupt\n");
438 #if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
449 PRINT_D(INT_DBG, "Interrupt received BH\n");
450 if (g_linux_wlan->oup.wlan_handle_rx_isr != 0) {
451 g_linux_wlan->oup.wlan_handle_rx_isr();
453 PRINT_ER("wlan_handle_rx_isr() hasn't been initialized\n");
457 #if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
461 #elif (RX_BH_TYPE == RX_BH_KTHREAD)
462 static int isr_bh_routine(void *vp)
466 nic = (linux_wlan_t *)vp;
469 linux_wlan_lock(&nic->rx_sem);
470 if (g_linux_wlan->close) {
472 while (!kthread_should_stop())
478 PRINT_D(INT_DBG, "Interrupt received BH\n");
479 if (g_linux_wlan->oup.wlan_handle_rx_isr != 0) {
480 g_linux_wlan->oup.wlan_handle_rx_isr();
482 PRINT_ER("wlan_handle_rx_isr() hasn't been initialized\n");
491 #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
492 static int init_irq(linux_wlan_t *p_nic)
495 linux_wlan_t *nic = p_nic;
497 /*initialize GPIO and register IRQ num*/
499 if ((gpio_request(GPIO_NUM, "WILC_INTR") == 0) &&
500 (gpio_direction_input(GPIO_NUM) == 0)) {
501 #if defined(CUSTOMER_PLATFORM)
503 TODO : save the registerd irq number to the private wilc context in kernel.
505 * ex) nic->dev_irq_num = gpio_to_irq(GPIO_NUM);
507 #elif defined (NM73131_0_BOARD)
508 nic->dev_irq_num = IRQ_WILC1000;
509 #elif defined (PANDA_BOARD)
510 gpio_export(GPIO_NUM, 1);
511 nic->dev_irq_num = OMAP_GPIO_IRQ(GPIO_NUM);
512 irq_set_irq_type(nic->dev_irq_num, IRQ_TYPE_LEVEL_LOW);
514 nic->dev_irq_num = gpio_to_irq(GPIO_NUM);
518 PRINT_ER("could not obtain gpio for WILC_INTR\n");
522 #if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
523 if ((ret != -1) && (request_threaded_irq(nic->dev_irq_num, isr_uh_routine, isr_bh_routine,
524 IRQF_TRIGGER_LOW | IRQF_ONESHOT, /*Without IRQF_ONESHOT the uh will remain kicked in and dont gave a chance to bh*/
525 "WILC_IRQ", nic)) < 0) {
529 if ((ret != -1) && (request_irq(nic->dev_irq_num, isr_uh_routine,
530 IRQF_TRIGGER_LOW, "WILC_IRQ", nic) < 0)) {
533 PRINT_ER("Failed to request IRQ for GPIO: %d\n", GPIO_NUM);
537 PRINT_D(INIT_DBG, "IRQ request succeeded IRQ-NUM= %d on GPIO: %d\n",
538 nic->dev_irq_num, GPIO_NUM);
545 static void deinit_irq(linux_wlan_t *nic)
547 #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
548 /* Deintialize IRQ */
549 if (&nic->dev_irq_num != 0) {
550 free_irq(nic->dev_irq_num, g_linux_wlan);
561 static void linux_wlan_msleep(uint32_t msc)
563 if (msc <= 4000000) {
564 u32 u32Temp = msc * 1000;
565 usleep_range(u32Temp, u32Temp);
571 static void linux_wlan_atomic_msleep(uint32_t msc)
575 static void linux_wlan_dbg(uint8_t *buff)
577 PRINT_D(INIT_DBG, "%d\n", *buff);
580 static void *linux_wlan_malloc_atomic(uint32_t sz)
583 pntr = (char *)kmalloc(sz, GFP_ATOMIC);
584 PRINT_D(MEM_DBG, "Allocating %d bytes at address %p\n", sz, pntr);
588 static void *linux_wlan_malloc(uint32_t sz)
591 pntr = (char *)kmalloc(sz, GFP_KERNEL);
592 PRINT_D(MEM_DBG, "Allocating %d bytes at address %p\n", sz, pntr);
596 void linux_wlan_free(void *vp)
599 PRINT_D(MEM_DBG, "Freeing %p\n", vp);
605 static void *internal_alloc(uint32_t size, uint32_t flag)
608 pntr = (char *)kmalloc(size, flag);
609 PRINT_D(MEM_DBG, "Allocating %d bytes at address %p\n", size, pntr);
614 static void linux_wlan_init_lock(char *lockName, void *plock, int count)
616 sema_init((struct semaphore *)plock, count);
617 PRINT_D(LOCK_DBG, "Initializing [%s][%p]\n", lockName, plock);
621 static void linux_wlan_deinit_lock(void *plock)
623 /* mutex_destroy((struct mutex*)plock); */
626 static void linux_wlan_lock(void *vp)
628 PRINT_D(LOCK_DBG, "Locking %p\n", vp);
630 while (down_interruptible((struct semaphore *) vp))
633 PRINT_ER("Failed, mutex is NULL\n");
637 static int linux_wlan_lock_timeout(void *vp, u32 timeout)
640 PRINT_D(LOCK_DBG, "Locking %p\n", vp);
642 error = down_timeout((struct semaphore *)vp, msecs_to_jiffies(timeout));
644 PRINT_ER("Failed, mutex is NULL\n");
649 void linux_wlan_unlock(void *vp)
651 PRINT_D(LOCK_DBG, "Unlocking %p\n", vp);
653 up((struct semaphore *)vp);
655 PRINT_ER("Failed, mutex is NULL\n");
660 static void linux_wlan_init_mutex(char *lockName, void *plock, int count)
662 mutex_init((struct mutex *)plock);
663 PRINT_D(LOCK_DBG, "Initializing mutex [%s][%p]\n", lockName, plock);
667 static void linux_wlan_deinit_mutex(void *plock)
669 mutex_destroy((struct mutex *)plock);
672 static void linux_wlan_lock_mutex(void *vp)
674 PRINT_D(LOCK_DBG, "Locking mutex %p\n", vp);
677 * if(mutex_is_locked((struct mutex*)vp))
679 * //PRINT_ER("Mutex already locked - %p \n",vp);
682 mutex_lock((struct mutex *)vp);
685 PRINT_ER("Failed, mutex is NULL\n");
689 static void linux_wlan_unlock_mutex(void *vp)
691 PRINT_D(LOCK_DBG, "Unlocking mutex %p\n", vp);
694 if (mutex_is_locked((struct mutex *)vp)) {
695 mutex_unlock((struct mutex *)vp);
697 /* PRINT_ER("Mutex already unlocked - %p\n",vp); */
701 PRINT_ER("Failed, mutex is NULL\n");
706 /*Added by Amr - BugID_4720*/
707 static void linux_wlan_init_spin_lock(char *lockName, void *plock, int count)
709 spin_lock_init((spinlock_t *)plock);
710 PRINT_D(SPIN_DEBUG, "Initializing mutex [%s][%p]\n", lockName, plock);
714 static void linux_wlan_deinit_spin_lock(void *plock)
718 static void linux_wlan_spin_lock(void *vp, unsigned long *flags)
720 unsigned long lflags;
721 PRINT_D(SPIN_DEBUG, "Lock spin %p\n", vp);
723 spin_lock_irqsave((spinlock_t *)vp, lflags);
726 PRINT_ER("Failed, spin lock is NULL\n");
729 static void linux_wlan_spin_unlock(void *vp, unsigned long *flags)
731 unsigned long lflags = *flags;
732 PRINT_D(SPIN_DEBUG, "Unlock spin %p\n", vp);
734 spin_unlock_irqrestore((spinlock_t *)vp, lflags);
737 PRINT_ER("Failed, spin lock is NULL\n");
741 static void linux_wlan_mac_indicate(int flag)
743 /*I have to do it that way becuase there is no mean to encapsulate device pointer
746 linux_wlan_t *pd = g_linux_wlan;
749 if (flag == WILC_MAC_INDICATE_STATUS) {
750 pd->oup.wlan_cfg_get_value(WID_STATUS, (unsigned char *)&status, 4);
751 if (pd->mac_status == WILC_MAC_STATUS_INIT) {
752 pd->mac_status = status;
753 linux_wlan_unlock(&pd->sync_event);
755 pd->mac_status = status;
758 if (pd->mac_status == WILC_MAC_STATUS_CONNECT) { /* Connect */
761 * get the mac and bssid address
763 PRINT_D(RX_DBG, "Calling cfg_get to get MAC_ADDR\n");
764 pd->oup.wlan_cfg_get(1, WID_MAC_ADDR, 0);
765 PRINT_D(RX_DBG, "Calling cfg_get to get BSSID\n");
766 pd->oup.wlan_cfg_get(0, WID_BSSID, 1);
771 pd->oup.wlan_cfg_get_value(WID_MAC_ADDR, pd->eth_src_address, 6);
772 pd->oup.wlan_cfg_get_value(WID_BSSID, pd->eth_dst_address, 6);
774 PRINT_D(GENERIC_DBG, "Source Address = %s", pd->eth_src_address);
775 PRINT_D(GENERIC_DBG, "Destiation Address = %s", pd->eth_dst_address);
783 } else if (flag == WILC_MAC_INDICATE_SCAN) {
784 PRINT_D(GENERIC_DBG, "Scanning ...\n");
790 struct net_device *GetIfHandler(uint8_t *pMacHeader)
792 uint8_t *Bssid, *Bssid1;
795 Bssid = pMacHeader + 10;
796 Bssid1 = pMacHeader + 4;
798 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
799 if (!memcmp(Bssid1, g_linux_wlan->strInterfaceInfo[i].aBSSID, ETH_ALEN) ||
800 !memcmp(Bssid, g_linux_wlan->strInterfaceInfo[i].aBSSID, ETH_ALEN)) {
801 return g_linux_wlan->strInterfaceInfo[i].wilc_netdev;
804 PRINT_INFO(INIT_DBG, "Invalide handle\n");
805 for (i = 0; i < 25; i++) {
806 PRINT_D(INIT_DBG, "%02x ", pMacHeader[i]);
808 Bssid = pMacHeader + 18;
809 Bssid1 = pMacHeader + 12;
810 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
811 if (!memcmp(Bssid1, g_linux_wlan->strInterfaceInfo[i].aBSSID, ETH_ALEN) ||
812 !memcmp(Bssid, g_linux_wlan->strInterfaceInfo[i].aBSSID, ETH_ALEN)) {
813 PRINT_D(INIT_DBG, "Ctx [%p]\n", g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
814 return g_linux_wlan->strInterfaceInfo[i].wilc_netdev;
817 PRINT_INFO(INIT_DBG, "\n");
821 int linux_wlan_set_bssid(struct net_device *wilc_netdev, uint8_t *pBSSID)
826 PRINT_D(INIT_DBG, "set bssid on[%p]\n", wilc_netdev);
827 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
828 if (g_linux_wlan->strInterfaceInfo[i].wilc_netdev == wilc_netdev) {
829 PRINT_D(INIT_DBG, "set bssid [%x][%x][%x]\n", pBSSID[0], pBSSID[1], pBSSID[2]);
830 memcpy(g_linux_wlan->strInterfaceInfo[i].aBSSID, pBSSID, 6);
839 /*Function to get number of connected interfaces*/
840 int linux_wlan_get_num_conn_ifcs(void)
843 uint8_t null_bssid[6] = {0};
846 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
847 if (memcmp(g_linux_wlan->strInterfaceInfo[i].aBSSID, null_bssid, 6)) {
854 static int linux_wlan_rxq_task(void *vp)
857 /* inform wilc1000_wlan_init that RXQ task is started. */
858 linux_wlan_unlock(&g_linux_wlan->rxq_thread_started);
860 linux_wlan_lock(&g_linux_wlan->rxq_event);
861 /* wait_for_completion(&g_linux_wlan->rxq_event); */
863 if (g_linux_wlan->close) {
864 /*Unlock the mutex in the mac_close function to indicate the exiting of the RX thread */
865 linux_wlan_unlock(&g_linux_wlan->rxq_thread_started);
867 while (!kthread_should_stop())
870 PRINT_D(RX_DBG, " RX thread stopped\n");
873 PRINT_D(RX_DBG, "Calling wlan_handle_rx_que()\n");
875 g_linux_wlan->oup.wlan_handle_rx_que();
880 #define USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
882 static int linux_wlan_txq_task(void *vp)
886 #if defined USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
887 #define TX_BACKOFF_WEIGHT_INCR_STEP (1)
888 #define TX_BACKOFF_WEIGHT_DECR_STEP (1)
889 #define TX_BACKOFF_WEIGHT_MAX (7)
890 #define TX_BACKOFF_WEIGHT_MIN (0)
891 #define TX_BACKOFF_WEIGHT_UNIT_MS (10)
892 int backoff_weight = TX_BACKOFF_WEIGHT_MIN;
896 /* inform wilc1000_wlan_init that TXQ task is started. */
897 linux_wlan_unlock(&g_linux_wlan->txq_thread_started);
900 PRINT_D(TX_DBG, "txq_task Taking a nap :)\n");
901 linux_wlan_lock(&g_linux_wlan->txq_event);
902 /* wait_for_completion(&pd->txq_event); */
903 PRINT_D(TX_DBG, "txq_task Who waked me up :$\n");
905 if (g_linux_wlan->close) {
906 /*Unlock the mutex in the mac_close function to indicate the exiting of the TX thread */
907 linux_wlan_unlock(&g_linux_wlan->txq_thread_started);
909 while (!kthread_should_stop())
912 PRINT_D(TX_DBG, "TX thread stopped\n");
915 PRINT_D(TX_DBG, "txq_task handle the sending packet and let me go to sleep.\n");
916 #if !defined USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
917 g_linux_wlan->oup.wlan_handle_tx_que();
920 ret = g_linux_wlan->oup.wlan_handle_tx_que(&txq_count);
921 if (txq_count < FLOW_CONTROL_LOWER_THRESHOLD /* && netif_queue_stopped(pd->wilc_netdev)*/) {
922 PRINT_D(TX_DBG, "Waking up queue\n");
923 /* netif_wake_queue(pd->wilc_netdev); */
924 if (netif_queue_stopped(g_linux_wlan->strInterfaceInfo[0].wilc_netdev))
925 netif_wake_queue(g_linux_wlan->strInterfaceInfo[0].wilc_netdev);
926 if (netif_queue_stopped(g_linux_wlan->strInterfaceInfo[1].wilc_netdev))
927 netif_wake_queue(g_linux_wlan->strInterfaceInfo[1].wilc_netdev);
930 if (ret == WILC_TX_ERR_NO_BUF) { /* failed to allocate buffers in chip. */
931 timeout = msecs_to_jiffies(TX_BACKOFF_WEIGHT_UNIT_MS << backoff_weight);
933 /* Back off from sending packets for some time. */
934 /* schedule_timeout will allow RX task to run and free buffers.*/
935 /* set_current_state(TASK_UNINTERRUPTIBLE); */
936 /* timeout = schedule_timeout(timeout); */
937 msleep(TX_BACKOFF_WEIGHT_UNIT_MS << backoff_weight);
938 } while (/*timeout*/ 0);
939 backoff_weight += TX_BACKOFF_WEIGHT_INCR_STEP;
940 if (backoff_weight > TX_BACKOFF_WEIGHT_MAX) {
941 backoff_weight = TX_BACKOFF_WEIGHT_MAX;
944 if (backoff_weight > TX_BACKOFF_WEIGHT_MIN) {
945 backoff_weight -= TX_BACKOFF_WEIGHT_DECR_STEP;
946 if (backoff_weight < TX_BACKOFF_WEIGHT_MIN) {
947 backoff_weight = TX_BACKOFF_WEIGHT_MIN;
951 /*TODO: drop packets after a certain time/number of retry count. */
952 } while (ret == WILC_TX_ERR_NO_BUF && !g_linux_wlan->close); /* retry sending packets if no more buffers in chip. */
958 static void linux_wlan_rx_complete(void)
960 PRINT_D(RX_DBG, "RX completed\n");
963 int linux_wlan_get_firmware(perInterface_wlan_t *p_nic)
966 perInterface_wlan_t *nic = p_nic;
968 const struct firmware *wilc_firmware;
972 if (nic->iftype == AP_MODE)
973 firmware = AP_FIRMWARE;
974 else if (nic->iftype == STATION_MODE)
975 firmware = STA_FIRMWARE;
979 PRINT_D(INIT_DBG, "Get P2P_CONCURRENCY_FIRMWARE\n");
980 firmware = P2P_CONCURRENCY_FIRMWARE;
986 PRINT_ER("NIC is NULL\n");
990 if (&nic->wilc_netdev->dev == NULL) {
991 PRINT_ER("&nic->wilc_netdev->dev is NULL\n");
996 /* the firmare should be located in /lib/firmware in
997 * root file system with the name specified above */
1000 if (request_firmware(&wilc_firmware, firmware, &g_linux_wlan->wilc_sdio_func->dev) != 0) {
1001 PRINT_ER("%s - firmare not available\n", firmware);
1006 if (request_firmware(&wilc_firmware, firmware, &g_linux_wlan->wilc_spidev->dev) != 0) {
1007 PRINT_ER("%s - firmare not available\n", firmware);
1012 g_linux_wlan->wilc_firmware = wilc_firmware; /* Bug 4703 */
1020 #ifdef COMPLEMENT_BOOT
1021 int repeat_power_cycle(perInterface_wlan_t *nic);
1024 static int linux_wlan_start_firmware(perInterface_wlan_t *nic)
1028 /* start firmware */
1029 PRINT_D(INIT_DBG, "Starting Firmware ...\n");
1030 ret = g_linux_wlan->oup.wlan_start();
1032 PRINT_ER("Failed to start Firmware\n");
1036 /* wait for mac ready */
1037 PRINT_D(INIT_DBG, "Waiting for Firmware to get ready ...\n");
1038 ret = linux_wlan_lock_timeout(&g_linux_wlan->sync_event, 5000);
1040 #ifdef COMPLEMENT_BOOT
1041 static int timeout = 5;
1044 PRINT_D(INIT_DBG, "repeat power cycle[%d]", timeout);
1045 ret = repeat_power_cycle(nic);
1052 PRINT_D(INIT_DBG, "Firmware start timed out");
1056 * TODO: Driver shouoldn't wait forever for firmware to get started -
1057 * in case of timeout this should be handled properly
1059 PRINT_D(INIT_DBG, "Firmware successfully started\n");
1064 static int linux_wlan_firmware_download(linux_wlan_t *p_nic)
1069 if (g_linux_wlan->wilc_firmware == NULL) {
1070 PRINT_ER("Firmware buffer is NULL\n");
1075 * do the firmware download
1077 PRINT_D(INIT_DBG, "Downloading Firmware ...\n");
1078 ret = g_linux_wlan->oup.wlan_firmware_download(g_linux_wlan->wilc_firmware->data, g_linux_wlan->wilc_firmware->size);
1083 /* Freeing FW buffer */
1084 PRINT_D(INIT_DBG, "Freeing FW buffer ...\n");
1085 PRINT_D(INIT_DBG, "Releasing firmware\n");
1086 release_firmware(g_linux_wlan->wilc_firmware);
1087 g_linux_wlan->wilc_firmware = NULL;
1089 PRINT_D(INIT_DBG, "Download Succeeded \n");
1096 /* startup configuration - could be changed later using iconfig*/
1097 static int linux_wlan_init_test_config(struct net_device *dev, linux_wlan_t *p_nic)
1100 unsigned char c_val[64];
1101 #ifndef STATIC_MACADDRESS
1102 unsigned char mac_add[] = {0x00, 0x80, 0xC2, 0x5E, 0xa2, 0xff};
1106 struct WILC_WFI_priv *priv;
1107 tstrWILC_WFIDrv *pstrWFIDrv;
1109 PRINT_D(TX_DBG, "Start configuring Firmware\n");
1110 #ifndef STATIC_MACADDRESS
1111 get_random_bytes(&mac_add[5], 1);
1112 get_random_bytes(&mac_add[4], 1);
1114 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
1115 pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
1116 PRINT_D(INIT_DBG, "Host = %p\n", pstrWFIDrv);
1118 PRINT_D(INIT_DBG, "MAC address is : %02x-%02x-%02x-%02x-%02x-%02x\n", mac_add[0], mac_add[1], mac_add[2], mac_add[3], mac_add[4], mac_add[5]);
1122 if (g_linux_wlan->oup.wlan_cfg_set == NULL) {
1123 PRINT_D(INIT_DBG, "Null p[ointer\n");
1127 *(int *)c_val = (u32)pstrWFIDrv;
1129 if (!g_linux_wlan->oup.wlan_cfg_set(1, WID_SET_DRV_HANDLER, c_val, 4, 0, 0))
1132 /*to tell fw that we are going to use PC test - WILC specific*/
1134 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_PC_TEST_MODE, c_val, 1, 0, 0))
1137 c_val[0] = INFRASTRUCTURE;
1138 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_BSS_TYPE, c_val, 1, 0, 0))
1142 /* c_val[0] = RATE_AUTO; / * bug 4275: Enable autorate and limit it to 24Mbps * / */
1143 c_val[0] = RATE_AUTO;
1144 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_CURRENT_TX_RATE, c_val, 1, 0, 0))
1147 c_val[0] = G_MIXED_11B_2_MODE;
1148 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11G_OPERATING_MODE, c_val, 1, 0, 0))
1152 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_CURRENT_CHANNEL, c_val, 1, 0, 0))
1155 c_val[0] = G_SHORT_PREAMBLE;
1156 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_PREAMBLE, c_val, 1, 0, 0))
1159 c_val[0] = AUTO_PROT;
1160 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_PROT_MECH, c_val, 1, 0, 0))
1163 #ifdef SWITCH_LOG_TERMINAL
1164 c_val[0] = AUTO_PROT;
1165 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_LOGTerminal_Switch, c_val, 1, 0, 0))
1169 c_val[0] = ACTIVE_SCAN;
1170 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_SCAN_TYPE, c_val, 1, 0, 0))
1173 c_val[0] = SITE_SURVEY_OFF;
1174 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_SITE_SURVEY, c_val, 1, 0, 0))
1177 *((int *)c_val) = 0xffff; /* Never use RTS-CTS */
1178 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_RTS_THRESHOLD, c_val, 2, 0, 0))
1181 *((int *)c_val) = 2346;
1182 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_FRAG_THRESHOLD, c_val, 2, 0, 0))
1186 /* -------------------------------------------------------------- */
1187 /* Configuration : String with length less than 32 bytes */
1188 /* Values to set : Any string with length less than 32 bytes */
1189 /* ( In BSS Station Set SSID to "" (null string) */
1190 /* to enable Broadcast SSID suppport ) */
1191 /* -------------------------------------------------------------- */
1192 #ifndef USE_WIRELESS
1193 strcpy(c_val, "nwifi");
1194 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_SSID, c_val, (strlen(c_val) + 1), 0, 0))
1199 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_BCAST_SSID, c_val, 1, 0, 0))
1203 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_QOS_ENABLE, c_val, 1, 0, 0))
1206 c_val[0] = NO_POWERSAVE;
1207 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_POWER_MANAGEMENT, c_val, 1, 0, 0))
1210 c_val[0] = NO_ENCRYPT; /* NO_ENCRYPT, 0x79 */
1211 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11I_MODE, c_val, 1, 0, 0))
1214 c_val[0] = OPEN_SYSTEM;
1215 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_AUTH_TYPE, c_val, 1, 0, 0))
1218 /* WEP/802 11I Configuration */
1219 /* ------------------------------------------------------------------ */
1220 /* Configuration : WEP Key */
1221 /* Values (0x) : 5 byte for WEP40 and 13 bytes for WEP104 */
1222 /* In case more than 5 bytes are passed on for WEP 40 */
1223 /* only first 5 bytes will be used as the key */
1224 /* ------------------------------------------------------------------ */
1226 strcpy(c_val, "123456790abcdef1234567890");
1227 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_WEP_KEY_VALUE, c_val, (strlen(c_val) + 1), 0, 0))
1230 /* WEP/802 11I Configuration */
1231 /* ------------------------------------------------------------------ */
1232 /* Configuration : AES/TKIP WPA/RSNA Pre-Shared Key */
1233 /* Values to set : Any string with length greater than equal to 8 bytes */
1234 /* and less than 64 bytes */
1235 /* ------------------------------------------------------------------ */
1236 strcpy(c_val, "12345678");
1237 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11I_PSK, c_val, (strlen(c_val)), 0, 0))
1240 /* IEEE802.1X Key Configuration */
1241 /* ------------------------------------------------------------------ */
1242 /* Configuration : Radius Server Access Secret Key */
1243 /* Values to set : Any string with length greater than equal to 8 bytes */
1244 /* and less than 65 bytes */
1245 /* ------------------------------------------------------------------ */
1246 strcpy(c_val, "password");
1247 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_1X_KEY, c_val, (strlen(c_val) + 1), 0, 0))
1250 /* IEEE802.1X Server Address Configuration */
1251 /* ------------------------------------------------------------------ */
1252 /* Configuration : Radius Server IP Address */
1253 /* Values to set : Any valid IP Address */
1254 /* ------------------------------------------------------------------ */
1259 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_1X_SERV_ADDR, c_val, 4, 0, 0))
1263 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_LISTEN_INTERVAL, c_val, 1, 0, 0))
1267 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_DTIM_PERIOD, c_val, 1, 0, 0))
1270 c_val[0] = NORMAL_ACK;
1271 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_ACK_POLICY, c_val, 1, 0, 0))
1275 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_USER_CONTROL_ON_TX_POWER, c_val, 1, 0, 0))
1279 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_TX_POWER_LEVEL_11A, c_val, 1, 0, 0))
1283 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_TX_POWER_LEVEL_11B, c_val, 1, 0, 0))
1286 /* Beacon Interval */
1287 /* -------------------------------------------------------------------- */
1288 /* Configuration : Sets the beacon interval value */
1289 /* Values to set : Any 16-bit value */
1290 /* -------------------------------------------------------------------- */
1292 *((int *)c_val) = 100;
1293 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_BEACON_INTERVAL, c_val, 2, 0, 0))
1296 c_val[0] = REKEY_DISABLE;
1297 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_REKEY_POLICY, c_val, 1, 0, 0))
1300 /* Rekey Time (s) (Used only when the Rekey policy is 2 or 4) */
1301 /* -------------------------------------------------------------------- */
1302 /* Configuration : Sets the Rekey Time (s) */
1303 /* Values to set : 32-bit value */
1304 /* -------------------------------------------------------------------- */
1305 *((int *)c_val) = 84600;
1306 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_REKEY_PERIOD, c_val, 4, 0, 0))
1309 /* Rekey Packet Count (in 1000s; used when Rekey Policy is 3) */
1310 /* -------------------------------------------------------------------- */
1311 /* Configuration : Sets Rekey Group Packet count */
1312 /* Values to set : 32-bit Value */
1313 /* -------------------------------------------------------------------- */
1314 *((int *)c_val) = 500;
1315 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_REKEY_PACKET_COUNT, c_val, 4, 0, 0))
1319 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_SHORT_SLOT_ALLOWED, c_val, 1, 0, 0))
1322 c_val[0] = G_SELF_CTS_PROT;
1323 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_ERP_PROT_TYPE, c_val, 1, 0, 0))
1326 c_val[0] = 1; /* Enable N */
1327 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_ENABLE, c_val, 1, 0, 0))
1330 c_val[0] = HT_MIXED_MODE;
1331 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_OPERATING_MODE, c_val, 1, 0, 0))
1334 c_val[0] = 1; /* TXOP Prot disable in N mode: No RTS-CTS on TX A-MPDUs to save air-time. */
1335 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_TXOP_PROT_DISABLE, c_val, 1, 0, 0))
1338 memcpy(c_val, mac_add, 6);
1340 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_MAC_ADDR, c_val, 6, 0, 0))
1346 c_val[0] = DETECT_PROTECT_REPORT;
1347 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_OBSS_NONHT_DETECTION, c_val, 1, 0, 0))
1350 c_val[0] = RTS_CTS_NONHT_PROT;
1351 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_HT_PROT_TYPE, c_val, 1, 0, 0))
1355 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_RIFS_PROT_ENABLE, c_val, 1, 0, 0))
1358 c_val[0] = MIMO_MODE;
1359 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_SMPS_MODE, c_val, 1, 0, 0))
1363 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_CURRENT_TX_MCS, c_val, 1, 0, 0))
1366 c_val[0] = 1; /* Enable N with immediate block ack. */
1367 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_IMMEDIATE_BA_ENABLED, c_val, 1, 1, (u32)pstrWFIDrv))
1377 /**************************/
1378 void wilc1000_wlan_deinit(linux_wlan_t *nic)
1381 if (g_linux_wlan->wilc1000_initialized) {
1383 printk("Deinitializing wilc1000 ...\n");
1386 PRINT_ER("nic is NULL\n");
1390 #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
1391 /* johnny : remove */
1392 PRINT_D(INIT_DBG, "skip wilc_bus_set_default_speed\n");
1394 wilc_bus_set_default_speed();
1397 PRINT_D(INIT_DBG, "Disabling IRQ\n");
1398 #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
1399 linux_wlan_disable_irq(IRQ_WAIT);
1401 #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
1404 linux_wlan_lock_mutex((void *)&g_linux_wlan->hif_cs);
1405 disable_sdio_interrupt();
1406 linux_wlan_unlock_mutex((void *)&g_linux_wlan->hif_cs);
1411 /* not sure if the following unlocks are needed or not*/
1412 if (&g_linux_wlan->rxq_event != NULL) {
1413 linux_wlan_unlock(&g_linux_wlan->rxq_event);
1416 if (&g_linux_wlan->txq_event != NULL) {
1417 linux_wlan_unlock(&g_linux_wlan->txq_event);
1421 #if (RX_BH_TYPE == RX_BH_WORK_QUEUE)
1422 /*Removing the work struct from the linux kernel workqueue*/
1423 if (&g_linux_wlan->rx_work_queue != NULL)
1424 flush_work(&g_linux_wlan->rx_work_queue);
1426 #elif (RX_BH_TYPE == RX_BH_KTHREAD)
1427 /* if(&nic->rx_sem != NULL) */
1428 /* linux_wlan_unlock(&nic->rx_sem); */
1431 PRINT_D(INIT_DBG, "Deinitializing Threads\n");
1432 wlan_deinitialize_threads(nic);
1434 PRINT_D(INIT_DBG, "Deinitializing IRQ\n");
1435 deinit_irq(g_linux_wlan);
1438 if (&g_linux_wlan->oup != NULL) {
1439 if (g_linux_wlan->oup.wlan_stop != NULL)
1440 g_linux_wlan->oup.wlan_stop();
1443 PRINT_D(INIT_DBG, "Deinitializing WILC Wlan\n");
1444 wilc_wlan_deinit(nic);
1445 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
1446 #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
1447 PRINT_D(INIT_DBG, "Disabling IRQ 2\n");
1449 linux_wlan_lock_mutex((void *)&g_linux_wlan->hif_cs);
1450 disable_sdio_interrupt();
1451 linux_wlan_unlock_mutex((void *)&g_linux_wlan->hif_cs);
1455 /*De-Initialize locks*/
1456 PRINT_D(INIT_DBG, "Deinitializing Locks\n");
1457 wlan_deinit_locks(g_linux_wlan);
1459 /* announce that wilc1000 is not initialized */
1460 g_linux_wlan->wilc1000_initialized = 0;
1462 PRINT_D(INIT_DBG, "wilc1000 deinitialization Done\n");
1465 PRINT_D(INIT_DBG, "wilc1000 is not initialized\n");
1470 int wlan_init_locks(linux_wlan_t *p_nic)
1473 PRINT_D(INIT_DBG, "Initializing Locks ...\n");
1475 /*initialize mutexes*/
1476 linux_wlan_init_mutex("hif_lock/hif_cs", &g_linux_wlan->hif_cs, 1);
1477 linux_wlan_init_mutex("rxq_lock/rxq_cs", &g_linux_wlan->rxq_cs, 1);
1478 linux_wlan_init_mutex("txq_lock/txq_cs", &g_linux_wlan->txq_cs, 1);
1480 /*Added by Amr - BugID_4720*/
1481 linux_wlan_init_spin_lock("txq_spin_lock/txq_cs", &g_linux_wlan->txq_spinlock, 1);
1483 /*Added by Amr - BugID_4720*/
1484 linux_wlan_init_lock("txq_add_to_head_lock/txq_cs", &g_linux_wlan->txq_add_to_head_cs, 1);
1486 linux_wlan_init_lock("txq_wait/txq_event", &g_linux_wlan->txq_event, 0);
1487 linux_wlan_init_lock("rxq_wait/rxq_event", &g_linux_wlan->rxq_event, 0);
1489 linux_wlan_init_lock("cfg_wait/cfg_event", &g_linux_wlan->cfg_event, 0);
1490 linux_wlan_init_lock("sync_event", &g_linux_wlan->sync_event, 0);
1492 linux_wlan_init_lock("rxq_lock/rxq_started", &g_linux_wlan->rxq_thread_started, 0);
1493 linux_wlan_init_lock("rxq_lock/txq_started", &g_linux_wlan->txq_thread_started, 0);
1495 #if (RX_BH_TYPE == RX_BH_KTHREAD)
1496 linux_wlan_init_lock("BH_SEM", &g_linux_wlan->rx_sem, 0);
1502 static int wlan_deinit_locks(linux_wlan_t *nic)
1504 PRINT_D(INIT_DBG, "De-Initializing Locks\n");
1506 if (&g_linux_wlan->hif_cs != NULL)
1507 linux_wlan_deinit_mutex(&g_linux_wlan->hif_cs);
1509 if (&g_linux_wlan->rxq_cs != NULL)
1510 linux_wlan_deinit_mutex(&g_linux_wlan->rxq_cs);
1512 if (&g_linux_wlan->txq_cs != NULL)
1513 linux_wlan_deinit_mutex(&g_linux_wlan->txq_cs);
1515 /*Added by Amr - BugID_4720*/
1516 if (&g_linux_wlan->txq_spinlock != NULL)
1517 linux_wlan_deinit_spin_lock(&g_linux_wlan->txq_spinlock);
1519 if (&g_linux_wlan->rxq_event != NULL)
1520 linux_wlan_deinit_lock(&g_linux_wlan->rxq_event);
1522 if (&g_linux_wlan->txq_event != NULL)
1523 linux_wlan_deinit_lock(&g_linux_wlan->txq_event);
1525 /*Added by Amr - BugID_4720*/
1526 if (&g_linux_wlan->txq_add_to_head_cs != NULL)
1527 linux_wlan_deinit_lock(&g_linux_wlan->txq_add_to_head_cs);
1529 if (&g_linux_wlan->rxq_thread_started != NULL)
1530 linux_wlan_deinit_lock(&g_linux_wlan->rxq_thread_started);
1532 if (&g_linux_wlan->txq_thread_started != NULL)
1533 linux_wlan_deinit_lock(&g_linux_wlan->txq_thread_started);
1535 if (&g_linux_wlan->cfg_event != NULL)
1536 linux_wlan_deinit_lock(&g_linux_wlan->cfg_event);
1538 if (&g_linux_wlan->sync_event != NULL)
1539 linux_wlan_deinit_lock(&g_linux_wlan->sync_event);
1543 void linux_to_wlan(wilc_wlan_inp_t *nwi, linux_wlan_t *nic)
1546 PRINT_D(INIT_DBG, "Linux to Wlan services ...\n");
1548 nwi->os_context.hif_critical_section = (void *)&g_linux_wlan->hif_cs;
1549 nwi->os_context.os_private = (void *)nic;
1550 nwi->os_context.tx_buffer_size = LINUX_TX_SIZE;
1551 nwi->os_context.txq_critical_section = (void *)&g_linux_wlan->txq_cs;
1553 /*Added by Amr - BugID_4720*/
1554 nwi->os_context.txq_add_to_head_critical_section = (void *)&g_linux_wlan->txq_add_to_head_cs;
1556 /*Added by Amr - BugID_4720*/
1557 nwi->os_context.txq_spin_lock = (void *)&g_linux_wlan->txq_spinlock;
1559 nwi->os_context.txq_wait_event = (void *)&g_linux_wlan->txq_event;
1561 #if defined (MEMORY_STATIC)
1562 nwi->os_context.rx_buffer_size = LINUX_RX_SIZE;
1564 nwi->os_context.rxq_critical_section = (void *)&g_linux_wlan->rxq_cs;
1565 nwi->os_context.rxq_wait_event = (void *)&g_linux_wlan->rxq_event;
1566 nwi->os_context.cfg_wait_event = (void *)&g_linux_wlan->cfg_event;
1568 nwi->os_func.os_sleep = linux_wlan_msleep;
1569 nwi->os_func.os_atomic_sleep = linux_wlan_atomic_msleep;
1570 nwi->os_func.os_debug = linux_wlan_dbg;
1571 nwi->os_func.os_malloc = linux_wlan_malloc;
1572 nwi->os_func.os_malloc_atomic = linux_wlan_malloc_atomic;
1573 nwi->os_func.os_free = linux_wlan_free;
1574 nwi->os_func.os_lock = linux_wlan_lock;
1575 nwi->os_func.os_unlock = linux_wlan_unlock;
1576 nwi->os_func.os_wait = linux_wlan_lock_timeout;
1577 nwi->os_func.os_signal = linux_wlan_unlock;
1578 nwi->os_func.os_enter_cs = linux_wlan_lock_mutex;
1579 nwi->os_func.os_leave_cs = linux_wlan_unlock_mutex;
1581 /*Added by Amr - BugID_4720*/
1582 nwi->os_func.os_spin_lock = linux_wlan_spin_lock;
1583 nwi->os_func.os_spin_unlock = linux_wlan_spin_unlock;
1586 nwi->io_func.io_type = HIF_SDIO;
1587 nwi->io_func.io_init = linux_sdio_init;
1588 nwi->io_func.io_deinit = linux_sdio_deinit;
1589 nwi->io_func.u.sdio.sdio_cmd52 = linux_sdio_cmd52;
1590 nwi->io_func.u.sdio.sdio_cmd53 = linux_sdio_cmd53;
1591 nwi->io_func.u.sdio.sdio_set_max_speed = linux_sdio_set_max_speed;
1592 nwi->io_func.u.sdio.sdio_set_default_speed = linux_sdio_set_default_speed;
1594 nwi->io_func.io_type = HIF_SPI;
1595 nwi->io_func.io_init = linux_spi_init;
1596 nwi->io_func.io_deinit = linux_spi_deinit;
1597 nwi->io_func.u.spi.spi_tx = linux_spi_write;
1598 nwi->io_func.u.spi.spi_rx = linux_spi_read;
1599 nwi->io_func.u.spi.spi_trx = linux_spi_write_read;
1600 nwi->io_func.u.spi.spi_max_speed = linux_spi_set_max_speed;
1603 /*for now - to be revised*/
1604 #ifdef WILC_FULLY_HOSTING_AP
1605 /* incase of Fully hosted AP, all non cfg pkts are processed here*/
1606 nwi->net_func.rx_indicate = WILC_Process_rx_frame;
1608 nwi->net_func.rx_indicate = frmw_to_linux;
1610 nwi->net_func.rx_complete = linux_wlan_rx_complete;
1611 nwi->indicate_func.mac_indicate = linux_wlan_mac_indicate;
1614 int wlan_initialize_threads(perInterface_wlan_t *nic)
1618 PRINT_D(INIT_DBG, "Initializing Threads ...\n");
1620 #if (RX_BH_TYPE == RX_BH_WORK_QUEUE)
1621 /*Initialize rx work queue task*/
1622 INIT_WORK(&g_linux_wlan->rx_work_queue, isr_bh_routine);
1623 #elif (RX_BH_TYPE == RX_BH_KTHREAD)
1624 PRINT_D(INIT_DBG, "Creating kthread for Rxq BH\n");
1625 g_linux_wlan->rx_bh_thread = kthread_run(isr_bh_routine, (void *)g_linux_wlan, "K_RXQ_BH");
1626 if (g_linux_wlan->rx_bh_thread == 0) {
1627 PRINT_ER("couldn't create RX BH thread\n");
1633 #ifndef TCP_ENHANCEMENTS
1634 /* create rx task */
1635 PRINT_D(INIT_DBG, "Creating kthread for reception\n");
1636 g_linux_wlan->rxq_thread = kthread_run(linux_wlan_rxq_task, (void *)g_linux_wlan, "K_RXQ_TASK");
1637 if (g_linux_wlan->rxq_thread == 0) {
1638 PRINT_ER("couldn't create RXQ thread\n");
1643 /* wait for RXQ task to start. */
1644 linux_wlan_lock(&g_linux_wlan->rxq_thread_started);
1648 /* create tx task */
1649 PRINT_D(INIT_DBG, "Creating kthread for transmission\n");
1650 g_linux_wlan->txq_thread = kthread_run(linux_wlan_txq_task, (void *)g_linux_wlan, "K_TXQ_TASK");
1651 if (g_linux_wlan->txq_thread == 0) {
1652 PRINT_ER("couldn't create TXQ thread\n");
1657 PRINT_D(INIT_DBG, "Creating kthread for Debugging\n");
1658 g_linux_wlan->txq_thread = kthread_run(DebuggingThreadTask, (void *)g_linux_wlan, "DebugThread");
1659 if (g_linux_wlan->txq_thread == 0) {
1660 PRINT_ER("couldn't create TXQ thread\n");
1665 /* wait for TXQ task to start. */
1666 linux_wlan_lock(&g_linux_wlan->txq_thread_started);
1671 /*De-Initialize 2nd thread*/
1672 g_linux_wlan->close = 1;
1673 linux_wlan_unlock(&g_linux_wlan->rxq_event);
1674 kthread_stop(g_linux_wlan->rxq_thread);
1676 #ifndef TCP_ENHANCEMENTS
1679 #if (RX_BH_TYPE == RX_BH_KTHREAD)
1680 /*De-Initialize 1st thread*/
1681 g_linux_wlan->close = 1;
1682 linux_wlan_unlock(&g_linux_wlan->rx_sem);
1683 kthread_stop(g_linux_wlan->rx_bh_thread);
1686 g_linux_wlan->close = 0;
1690 static void wlan_deinitialize_threads(linux_wlan_t *nic)
1693 g_linux_wlan->close = 1;
1694 PRINT_D(INIT_DBG, "Deinitializing Threads\n");
1695 if (&g_linux_wlan->rxq_event != NULL)
1696 linux_wlan_unlock(&g_linux_wlan->rxq_event);
1699 if (g_linux_wlan->rxq_thread != NULL) {
1700 kthread_stop(g_linux_wlan->rxq_thread);
1701 g_linux_wlan->rxq_thread = NULL;
1705 if (&g_linux_wlan->txq_event != NULL)
1706 linux_wlan_unlock(&g_linux_wlan->txq_event);
1709 if (g_linux_wlan->txq_thread != NULL) {
1710 kthread_stop(g_linux_wlan->txq_thread);
1711 g_linux_wlan->txq_thread = NULL;
1714 #if (RX_BH_TYPE == RX_BH_KTHREAD)
1715 if (&g_linux_wlan->rx_sem != NULL)
1716 linux_wlan_unlock(&g_linux_wlan->rx_sem);
1718 if (g_linux_wlan->rx_bh_thread != NULL) {
1719 kthread_stop(g_linux_wlan->rx_bh_thread);
1720 g_linux_wlan->rx_bh_thread = NULL;
1725 #ifdef STATIC_MACADDRESS
1726 const char *path_string[] = {
1731 static int linux_wlan_read_mac_addr(void *vp)
1734 struct file *fp = (struct file *)-ENOENT;
1735 mm_segment_t old_fs;
1738 int array_size = ARRAY_SIZE(path_string);
1740 /* change to KERNEL_DS address limit */
1744 for (index = 0; index < array_size; index++) {
1745 fp = filp_open(path_string[index], O_WRONLY, 0640);
1751 /*No such file or directory */
1752 if (IS_ERR(fp) || !fp->f_op) {
1753 get_random_bytes(&mac_add[3], 3);
1754 /* open file to write */
1755 fp = filp_open(path_string[index], O_WRONLY | O_CREAT, 0640);
1757 if (!fp || IS_ERR(fp)) {
1761 /* write buf to file */
1762 fp->f_op->write(fp, mac_add, 6, &pos);
1766 /* read file to buf */
1767 fp->f_op->read(fp, mac_add, 6, &pos);
1772 if (index == array_size) {
1773 PRINT_ER("random MAC\n");
1777 if (fp && !IS_ERR(fp)) {
1778 filp_close(fp, NULL);
1787 #ifdef COMPLEMENT_BOOT
1789 extern volatile int probe;
1790 extern uint8_t core_11b_ready(void);
1792 #define READY_CHECK_THRESHOLD 30
1793 extern void wilc_wlan_global_reset(void);
1794 uint8_t wilc1000_prepare_11b_core(wilc_wlan_inp_t *nwi, wilc_wlan_oup_t *nwo, linux_wlan_t *nic)
1797 while ((core_11b_ready() && (READY_CHECK_THRESHOLD > (trials++)))) {
1798 PRINT_D(INIT_DBG, "11b core not ready yet: %u\n", trials);
1799 wilc_wlan_deinit(nic);
1800 wilc_wlan_global_reset();
1801 sdio_unregister_driver(&wilc_bus);
1803 linux_wlan_device_detection(0);
1807 linux_wlan_device_detection(1);
1809 sdio_register_driver(&wilc_bus);
1815 g_linux_wlan->wilc_sdio_func = local_sdio_func;
1816 linux_to_wlan(nwi, nic);
1817 wilc_wlan_init(nwi, nwo);
1820 if (READY_CHECK_THRESHOLD <= trials)
1827 int repeat_power_cycle(perInterface_wlan_t *nic)
1830 wilc_wlan_inp_t nwi;
1831 wilc_wlan_oup_t nwo;
1832 sdio_unregister_driver(&wilc_bus);
1834 linux_wlan_device_detection(0);
1835 linux_wlan_device_power(0);
1837 linux_wlan_device_power(1);
1839 linux_wlan_device_detection(1);
1842 sdio_register_driver(&wilc_bus);
1849 g_linux_wlan->wilc_sdio_func = local_sdio_func;
1850 linux_to_wlan(&nwi, g_linux_wlan);
1851 ret = wilc_wlan_init(&nwi, &nwo);
1853 g_linux_wlan->mac_status = WILC_MAC_STATUS_INIT;
1854 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
1855 enable_sdio_interrupt();
1858 if (linux_wlan_get_firmware(nic)) {
1859 PRINT_ER("Can't get firmware \n");
1864 /*Download firmware*/
1865 ret = linux_wlan_firmware_download(g_linux_wlan);
1867 PRINT_ER("Failed to download firmware\n");
1871 ret = linux_wlan_start_firmware(nic);
1873 PRINT_ER("Failed to start firmware\n");
1880 int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic)
1882 wilc_wlan_inp_t nwi;
1883 wilc_wlan_oup_t nwo;
1884 perInterface_wlan_t *nic = p_nic;
1887 if (!g_linux_wlan->wilc1000_initialized) {
1888 g_linux_wlan->mac_status = WILC_MAC_STATUS_INIT;
1889 g_linux_wlan->close = 0;
1890 g_linux_wlan->wilc1000_initialized = 0;
1892 wlan_init_locks(g_linux_wlan);
1894 #ifdef STATIC_MACADDRESS
1895 wilc_mac_thread = kthread_run(linux_wlan_read_mac_addr, NULL, "wilc_mac_thread");
1896 if (wilc_mac_thread < 0) {
1897 PRINT_ER("couldn't create Mac addr thread\n");
1901 linux_to_wlan(&nwi, g_linux_wlan);
1903 ret = wilc_wlan_init(&nwi, &nwo);
1905 PRINT_ER("Initializing WILC_Wlan FAILED\n");
1909 memcpy(&g_linux_wlan->oup, &nwo, sizeof(wilc_wlan_oup_t));
1911 /*Save the oup structre into global pointer*/
1912 gpstrWlanOps = &g_linux_wlan->oup;
1915 ret = wlan_initialize_threads(nic);
1917 PRINT_ER("Initializing Threads FAILED\n");
1919 goto _fail_wilc_wlan_;
1922 #if (defined WILC_SDIO) && (defined COMPLEMENT_BOOT)
1923 if (wilc1000_prepare_11b_core(&nwi, &nwo, g_linux_wlan)) {
1924 PRINT_ER("11b Core is not ready\n");
1926 goto _fail_threads_;
1930 #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
1931 if (init_irq(g_linux_wlan)) {
1932 PRINT_ER("couldn't initialize IRQ\n");
1934 goto _fail_threads_;
1938 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
1939 if (enable_sdio_interrupt()) {
1940 PRINT_ER("couldn't initialize IRQ\n");
1942 goto _fail_irq_init_;
1946 if (linux_wlan_get_firmware(nic)) {
1947 PRINT_ER("Can't get firmware \n");
1949 goto _fail_irq_enable_;
1953 /*Download firmware*/
1954 ret = linux_wlan_firmware_download(g_linux_wlan);
1956 PRINT_ER("Failed to download firmware\n");
1958 goto _fail_irq_enable_;
1962 ret = linux_wlan_start_firmware(nic);
1964 PRINT_ER("Failed to start firmware\n");
1966 goto _fail_irq_enable_;
1969 wilc_bus_set_max_speed();
1971 if (g_linux_wlan->oup.wlan_cfg_get(1, WID_FIRMWARE_VERSION, 1, 0)) {
1973 char Firmware_ver[20];
1974 size = g_linux_wlan->oup.wlan_cfg_get_value(
1975 WID_FIRMWARE_VERSION,
1976 Firmware_ver, sizeof(Firmware_ver));
1977 Firmware_ver[size] = '\0';
1978 PRINT_D(INIT_DBG, "***** Firmware Ver = %s *******\n", Firmware_ver);
1980 /* Initialize firmware with default configuration */
1981 ret = linux_wlan_init_test_config(dev, g_linux_wlan);
1984 PRINT_ER("Failed to configure firmware\n");
1986 goto _fail_fw_start_;
1989 g_linux_wlan->wilc1000_initialized = 1;
1990 return 0; /*success*/
1994 if (&g_linux_wlan->oup != NULL) {
1995 if (g_linux_wlan->oup.wlan_stop != NULL)
1996 g_linux_wlan->oup.wlan_stop();
2000 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
2001 disable_sdio_interrupt();
2004 #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
2005 deinit_irq(g_linux_wlan);
2009 wlan_deinitialize_threads(g_linux_wlan);
2011 wilc_wlan_deinit(g_linux_wlan);
2013 wlan_deinit_locks(g_linux_wlan);
2014 PRINT_ER("WLAN Iinitialization FAILED\n");
2016 PRINT_D(INIT_DBG, "wilc1000 already initialized\n");
2023 * - this function will be called automatically by OS when module inserted.
2026 #if !defined (NM73131_0_BOARD)
2027 int mac_init_fn(struct net_device *ndev)
2030 /*Why we do this !!!*/
2031 netif_start_queue(ndev); /* ma */
2032 netif_stop_queue(ndev); /* ma */
2037 int mac_init_fn(struct net_device *ndev)
2040 unsigned char mac_add[] = {0x00, 0x50, 0xc2, 0x5e, 0x10, 0x00};
2041 /* TODO: get MAC address whenever the source is EPROM - hardcoded and copy it to ndev*/
2042 memcpy(ndev->dev_addr, mac_add, 6);
2044 if (!is_valid_ether_addr(ndev->dev_addr)) {
2045 PRINT_ER("Error: Wrong MAC address\n");
2054 void WILC_WFI_frame_register(struct wiphy *wiphy, struct net_device *dev,
2055 u16 frame_type, bool reg);
2057 /* This fn is called, when this device is setup using ifconfig */
2058 #if !defined (NM73131_0_BOARD)
2059 int mac_open(struct net_device *ndev)
2061 perInterface_wlan_t *nic;
2064 /*No need for setting mac address here anymore,*/
2065 /*Just set it in init_test_config()*/
2066 unsigned char mac_add[ETH_ALEN] = {0};
2069 struct WILC_WFI_priv *priv;
2071 nic = netdev_priv(ndev);
2072 priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy);
2073 PRINT_D(INIT_DBG, "MAC OPEN[%p]\n", ndev);
2076 ret = WILC_WFI_InitHostInt(ndev);
2078 PRINT_ER("Failed to initialize host interface\n");
2084 /*initialize platform*/
2085 PRINT_D(INIT_DBG, "*** re-init ***\n");
2086 ret = wilc1000_wlan_init(ndev, nic);
2088 PRINT_ER("Failed to initialize wilc1000\n");
2089 WILC_WFI_DeInitHostInt(ndev);
2093 Set_machw_change_vir_if(false);
2095 host_int_get_MacAddress(priv->hWILCWFIDrv, mac_add);
2096 PRINT_D(INIT_DBG, "Mac address: %x:%x:%x:%x:%x:%x\n", mac_add[0], mac_add[1], mac_add[2],
2097 mac_add[3], mac_add[4], mac_add[5]);
2099 /* loop through the NUM of supported devices and set the MAC address */
2100 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
2101 if (ndev == g_linux_wlan->strInterfaceInfo[i].wilc_netdev) {
2102 memcpy(g_linux_wlan->strInterfaceInfo[i].aSrcAddress, mac_add, ETH_ALEN);
2103 g_linux_wlan->strInterfaceInfo[i].drvHandler = (u32)priv->hWILCWFIDrv;
2108 /* TODO: get MAC address whenever the source is EPROM - hardcoded and copy it to ndev*/
2109 memcpy(ndev->dev_addr, g_linux_wlan->strInterfaceInfo[i].aSrcAddress, ETH_ALEN);
2111 if (!is_valid_ether_addr(ndev->dev_addr)) {
2112 PRINT_ER("Error: Wrong MAC address\n");
2118 WILC_WFI_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy, nic->wilc_netdev,
2119 nic->g_struct_frame_reg[0].frame_type, nic->g_struct_frame_reg[0].reg);
2120 WILC_WFI_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy, nic->wilc_netdev,
2121 nic->g_struct_frame_reg[1].frame_type, nic->g_struct_frame_reg[1].reg);
2122 netif_wake_queue(ndev);
2123 g_linux_wlan->open_ifcs++;
2124 nic->mac_opened = 1;
2128 WILC_WFI_DeInitHostInt(ndev);
2129 wilc1000_wlan_deinit(g_linux_wlan);
2133 int mac_open(struct net_device *ndev)
2137 nic = netdev_priv(ndev);
2139 /*initialize platform*/
2140 if (wilc1000_wlan_init(nic)) {
2141 PRINT_ER("Failed to initialize platform\n");
2144 /* Start the network interface queue for this device */
2145 PRINT_D(INIT_DBG, "Starting netifQ\n");
2146 netif_start_queue(ndev);
2147 /* linux_wlan_lock(&close_exit_sync); */
2152 struct net_device_stats *mac_stats(struct net_device *dev)
2154 perInterface_wlan_t *nic = netdev_priv(dev);
2157 return &nic->netstats;
2160 /* Setup the multicast filter */
2161 static void wilc_set_multicast_list(struct net_device *dev)
2164 struct netdev_hw_addr *ha;
2165 struct WILC_WFI_priv *priv;
2166 tstrWILC_WFIDrv *pstrWFIDrv;
2168 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
2169 pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
2175 PRINT_D(INIT_DBG, "Setting Multicast List with count = %d. \n", dev->mc.count);
2177 if (dev->flags & IFF_PROMISC) {
2178 /* Normally, we should configure the chip to retrive all packets
2179 * but we don't wanna support this right now */
2180 /* TODO: add promiscuous mode support */
2181 PRINT_D(INIT_DBG, "Set promiscuous mode ON, retrive all packets \n");
2185 /* If there's more addresses than we handle, get all multicast
2186 * packets and sort them out in software. */
2187 if ((dev->flags & IFF_ALLMULTI) || (dev->mc.count) > WILC_MULTICAST_TABLE_SIZE) {
2188 PRINT_D(INIT_DBG, "Disable multicast filter, retrive all multicast packets\n");
2189 /* get all multicast packets */
2190 host_int_setup_multicast_filter((WILC_WFIDrvHandle)pstrWFIDrv, false, 0);
2194 /* No multicast? Just get our own stuff */
2195 if ((dev->mc.count) == 0) {
2196 PRINT_D(INIT_DBG, "Enable multicast filter, retrive directed packets only.\n");
2197 host_int_setup_multicast_filter((WILC_WFIDrvHandle)pstrWFIDrv, true, 0);
2201 /* Store all of the multicast addresses in the hardware filter */
2202 netdev_for_each_mc_addr(ha, dev)
2204 WILC_memcpy(gau8MulticastMacAddrList[i], ha->addr, ETH_ALEN);
2205 PRINT_D(INIT_DBG, "Entry[%d]: %x:%x:%x:%x:%x:%x\n", i,
2206 gau8MulticastMacAddrList[i][0], gau8MulticastMacAddrList[i][1], gau8MulticastMacAddrList[i][2], gau8MulticastMacAddrList[i][3], gau8MulticastMacAddrList[i][4], gau8MulticastMacAddrList[i][5]);
2210 host_int_setup_multicast_filter((WILC_WFIDrvHandle)pstrWFIDrv, true, (dev->mc.count));
2216 static void linux_wlan_tx_complete(void *priv, int status)
2219 struct tx_complete_data *pv_data = (struct tx_complete_data *)priv;
2221 PRINT_D(TX_DBG, "Packet sent successfully - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb);
2223 PRINT_D(TX_DBG, "Couldn't send packet - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb);
2225 /* Free the SK Buffer, its work is done */
2226 dev_kfree_skb(pv_data->skb);
2227 linux_wlan_free(pv_data);
2230 int mac_xmit(struct sk_buff *skb, struct net_device *ndev)
2232 perInterface_wlan_t *nic;
2233 struct tx_complete_data *tx_data = NULL;
2237 struct ethhdr *eth_h;
2238 nic = netdev_priv(ndev);
2240 PRINT_D(INT_DBG, "\n========\n IntUH: %d - IntBH: %d - IntCld: %d \n========\n", int_rcvdU, int_rcvdB, int_clrd);
2241 PRINT_D(TX_DBG, "Sending packet just received from TCP/IP\n");
2243 /* Stop the network interface queue */
2244 if (skb->dev != ndev) {
2245 PRINT_ER("Packet not destined to this device\n");
2249 tx_data = (struct tx_complete_data *)internal_alloc(sizeof(struct tx_complete_data), GFP_ATOMIC);
2250 if (tx_data == NULL) {
2251 PRINT_ER("Failed to allocate memory for tx_data structure\n");
2253 netif_wake_queue(ndev);
2257 tx_data->buff = skb->data;
2258 tx_data->size = skb->len;
2261 eth_h = (struct ethhdr *)(skb->data);
2262 if (eth_h->h_proto == 0x8e88) {
2263 PRINT_D(INIT_DBG, "EAPOL transmitted\n");
2266 /*get source and dest ip addresses*/
2267 ih = (struct iphdr *)(skb->data + sizeof(struct ethhdr));
2269 pu8UdpBuffer = (char *)ih + sizeof(struct iphdr);
2270 if ((pu8UdpBuffer[1] == 68 && pu8UdpBuffer[3] == 67) || (pu8UdpBuffer[1] == 67 && pu8UdpBuffer[3] == 68)) {
2271 PRINT_D(GENERIC_DBG, "DHCP Message transmitted, type:%x %x %x\n", pu8UdpBuffer[248], pu8UdpBuffer[249], pu8UdpBuffer[250]);
2274 PRINT_D(TX_DBG, "Sending packet - Size = %d - Address = %p - SKB = %p\n", tx_data->size, tx_data->buff, tx_data->skb);
2276 /* Send packet to MAC HW - for now the tx_complete function will be just status
2277 * indicator. still not sure if I need to suspend host transmission till the tx_complete
2278 * function called or not?
2279 * allocated buffer will be freed in tx_complete function.
2281 PRINT_D(TX_DBG, "Adding tx packet to TX Queue\n");
2282 nic->netstats.tx_packets++;
2283 nic->netstats.tx_bytes += tx_data->size;
2284 tx_data->pBssid = g_linux_wlan->strInterfaceInfo[nic->u8IfIdx].aBSSID;
2285 #ifndef WILC_FULLY_HOSTING_AP
2286 QueueCount = g_linux_wlan->oup.wlan_add_to_tx_que((void *)tx_data,
2289 linux_wlan_tx_complete);
2291 QueueCount = WILC_Xmit_data((void *)tx_data, HOST_TO_WLAN);
2292 #endif /* WILC_FULLY_HOSTING_AP */
2295 if (QueueCount > FLOW_CONTROL_UPPER_THRESHOLD) {
2296 netif_stop_queue(g_linux_wlan->strInterfaceInfo[0].wilc_netdev);
2297 netif_stop_queue(g_linux_wlan->strInterfaceInfo[1].wilc_netdev);
2304 int mac_close(struct net_device *ndev)
2306 struct WILC_WFI_priv *priv;
2307 perInterface_wlan_t *nic;
2308 tstrWILC_WFIDrv *pstrWFIDrv;
2310 nic = netdev_priv(ndev);
2312 if ((nic == NULL) || (nic->wilc_netdev == NULL) || (nic->wilc_netdev->ieee80211_ptr == NULL) || (nic->wilc_netdev->ieee80211_ptr->wiphy == NULL)) {
2313 PRINT_ER("nic = NULL\n");
2317 priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy);
2320 PRINT_ER("priv = NULL\n");
2324 pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
2328 PRINT_D(GENERIC_DBG, "Mac close\n");
2330 if (g_linux_wlan == NULL) {
2331 PRINT_ER("g_linux_wlan = NULL\n");
2335 if (pstrWFIDrv == NULL) {
2336 PRINT_ER("pstrWFIDrv = NULL\n");
2340 if ((g_linux_wlan->open_ifcs) > 0) {
2341 g_linux_wlan->open_ifcs--;
2343 PRINT_ER("ERROR: MAC close called while number of opened interfaces is zero\n");
2347 if (nic->wilc_netdev != NULL) {
2348 /* Stop the network interface queue */
2349 netif_stop_queue(nic->wilc_netdev);
2352 WILC_WFI_DeInitHostInt(nic->wilc_netdev);
2356 if (g_linux_wlan->open_ifcs == 0) {
2357 PRINT_D(GENERIC_DBG, "Deinitializing wilc1000\n");
2358 g_linux_wlan->close = 1;
2359 wilc1000_wlan_deinit(g_linux_wlan);
2361 #ifdef WILC_AP_EXTERNAL_MLME
2362 WILC_WFI_deinit_mon_interface();
2367 linux_wlan_unlock(&close_exit_sync);
2368 nic->mac_opened = 0;
2374 int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
2379 u32 size = 0, length = 0;
2380 perInterface_wlan_t *nic;
2381 struct WILC_WFI_priv *priv;
2382 s32 s32Error = WILC_SUCCESS;
2386 /* struct iwreq *wrq = (struct iwreq *) req; // tony moved to case SIOCSIWPRIV */
2388 nic = netdev_priv(ndev);
2390 if (!g_linux_wlan->wilc1000_initialized)
2396 /* [[ added by tony for SIOCDEVPRIVATE */
2397 case SIOCDEVPRIVATE + 1:
2399 android_wifi_priv_cmd priv_cmd;
2401 PRINT_INFO(GENERIC_DBG, "in SIOCDEVPRIVATE+1\n");
2403 if (copy_from_user(&priv_cmd, req->ifr_data, sizeof(android_wifi_priv_cmd))) {
2408 buff = kmalloc(priv_cmd.total_len, GFP_KERNEL);
2414 if (copy_from_user(buff, priv_cmd.buf, priv_cmd.total_len)) {
2419 PRINT_INFO(GENERIC_DBG, "%s: Android private cmd \"%s\" on %s\n", __FUNCTION__, buff, req->ifr_name);
2421 if (strncasecmp(buff, "SCAN-ACTIVE", strlen("SCAN-ACTIVE")) == 0) {
2422 PRINT_INFO(GENERIC_DBG, "%s, SCAN-ACTIVE command\n", __FUNCTION__);
2423 } else if (strncasecmp(buff, "SCAN-PASSIVE", strlen("SCAN-PASSIVE")) == 0) {
2424 PRINT_INFO(GENERIC_DBG, "%s, SCAN-PASSIVE command\n", __FUNCTION__);
2425 } else if (strncasecmp(buff, "RXFILTER-START", strlen("RXFILTER-START")) == 0) {
2426 PRINT_INFO(GENERIC_DBG, "%s, RXFILTER-START command\n", __FUNCTION__);
2427 } else if (strncasecmp(buff, "RXFILTER-STOP", strlen("RXFILTER-STOP")) == 0) {
2428 PRINT_INFO(GENERIC_DBG, "%s, RXFILTER-STOP command\n", __FUNCTION__);
2429 } else if (strncasecmp(buff, "RXFILTER-ADD", strlen("RXFILTER-ADD")) == 0) {
2430 int filter_num = *(buff + strlen("RXFILTER-ADD") + 1) - '0';
2431 PRINT_INFO(GENERIC_DBG, "%s, RXFILTER-ADD command, filter_num=%d\n", __FUNCTION__, filter_num);
2432 } else if (strncasecmp(buff, "RXFILTER-REMOVE", strlen("RXFILTER-REMOVE")) == 0) {
2433 int filter_num = *(buff + strlen("RXFILTER-REMOVE") + 1) - '0';
2434 PRINT_INFO(GENERIC_DBG, "%s, RXFILTER-REMOVE command, filter_num=%d\n", __FUNCTION__, filter_num);
2435 } else if (strncasecmp(buff, "BTCOEXSCAN-START", strlen("BTCOEXSCAN-START")) == 0) {
2436 PRINT_INFO(GENERIC_DBG, "%s, BTCOEXSCAN-START command\n", __FUNCTION__);
2437 } else if (strncasecmp(buff, "BTCOEXSCAN-STOP", strlen("BTCOEXSCAN-STOP")) == 0) {
2438 PRINT_INFO(GENERIC_DBG, "%s, BTCOEXSCAN-STOP command\n", __FUNCTION__);
2439 } else if (strncasecmp(buff, "BTCOEXMODE", strlen("BTCOEXMODE")) == 0) {
2440 PRINT_INFO(GENERIC_DBG, "%s, BTCOEXMODE command\n", __FUNCTION__);
2441 } else if (strncasecmp(buff, "SETBAND", strlen("SETBAND")) == 0) {
2442 uint band = *(buff + strlen("SETBAND") + 1) - '0';
2443 PRINT_INFO(GENERIC_DBG, "%s, SETBAND command, band=%d\n", __FUNCTION__, band);
2444 } else if (strncasecmp(buff, "GETBAND", strlen("GETBAND")) == 0) {
2445 PRINT_INFO(GENERIC_DBG, "%s, GETBAND command\n", __FUNCTION__);
2446 } else if (strncasecmp(buff, "COUNTRY", strlen("COUNTRY")) == 0) {
2447 char *country_code = buff + strlen("COUNTRY") + 1;
2448 PRINT_INFO(GENERIC_DBG, "%s, COUNTRY command, country_code=%s\n", __FUNCTION__, country_code);
2450 PRINT_INFO(GENERIC_DBG, "%s, Unknown command\n", __FUNCTION__);
2457 struct iwreq *wrq = (struct iwreq *) req; /* added by tony */
2459 size = wrq->u.data.length;
2461 if (size && wrq->u.data.pointer) {
2463 buff = memdup_user(wrq->u.data.pointer, wrq->u.data.length);
2465 s32Error = PTR_ERR(buff);
2469 if (strncasecmp(buff, "RSSI", length) == 0) {
2472 priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy);
2473 s32Error = host_int_get_rssi(priv->hWILCWFIDrv, &(rssi));
2475 PRINT_ER("Failed to send get rssi param's message queue ");
2477 PRINT_INFO(GENERIC_DBG, "RSSI :%d\n", rssi);
2479 /*Rounding up the rssi negative value*/
2482 snprintf(buff, size, "rssi %d", rssi);
2484 if (copy_to_user(wrq->u.data.pointer, buff, size)) {
2485 PRINT_ER("%s: failed to copy data to user buffer\n", __FUNCTION__);
2496 PRINT_INFO(GENERIC_DBG, "Command - %d - has been received\n", cmd);
2497 s32Error = -EOPNOTSUPP;
2511 void frmw_to_linux(uint8_t *buff, uint32_t size, uint32_t pkt_offset)
2514 unsigned int frame_len = 0;
2516 unsigned char *buff_to_send = NULL;
2517 struct sk_buff *skb;
2518 #ifndef TCP_ENHANCEMENTS
2522 struct net_device *wilc_netdev;
2523 perInterface_wlan_t *nic;
2525 wilc_netdev = GetIfHandler(buff);
2526 if (wilc_netdev == NULL)
2530 nic = netdev_priv(wilc_netdev);
2535 buff_to_send = buff;
2538 /* Need to send the packet up to the host, allocate a skb buffer */
2539 skb = dev_alloc_skb(frame_len);
2541 PRINT_ER("Low memory - packet droped\n");
2545 skb_reserve(skb, (unsigned int)skb->data & 0x3);
2547 if (g_linux_wlan == NULL || wilc_netdev == NULL) {
2548 PRINT_ER("wilc_netdev in g_linux_wlan is NULL");
2550 skb->dev = wilc_netdev;
2552 if (skb->dev == NULL) {
2553 PRINT_ER("skb->dev is NULL\n");
2560 * WILC_PRINTF("buff_to_send[%d]=%2x\n",i,buff_to_send[i]);
2564 /* skb_put(skb, frame_len); */
2565 memcpy(skb_put(skb, frame_len), buff_to_send, frame_len);
2567 /* WILC_PRINTF("After MEM_CPY\n"); */
2569 /* nic = netdev_priv(wilc_netdev); */
2572 /* if(nic->monitor_flag)
2574 * WILC_WFI_monitor_rx(nic->wilc_netdev,skb);
2578 skb->protocol = eth_type_trans(skb, wilc_netdev);
2579 #ifndef TCP_ENHANCEMENTS
2580 /*get source and dest ip addresses*/
2581 ih = (struct iphdr *)(skb->data + sizeof(struct ethhdr));
2583 pu8UdpBuffer = (char *)ih + sizeof(struct iphdr);
2584 if (buff_to_send[35] == 67 && buff_to_send[37] == 68) {
2585 PRINT_D(RX_DBG, "DHCP Message received\n");
2587 if (buff_to_send[12] == 0x88 && buff_to_send[13] == 0x8e)
2588 PRINT_D(GENERIC_DBG, "eapol received\n");
2590 /* Send the packet to the stack by giving it to the bridge */
2591 nic->netstats.rx_packets++;
2592 nic->netstats.rx_bytes += frame_len;
2593 skb->ip_summed = CHECKSUM_UNNECESSARY;
2594 stats = netif_rx(skb);
2595 PRINT_D(RX_DBG, "netif_rx ret value is: %d\n", stats);
2597 #ifndef TCP_ENHANCEMENTS
2599 PRINT_ER("Discard sending packet with len = %d\n", size);
2604 void WILC_WFI_mgmt_rx(uint8_t *buff, uint32_t size)
2607 perInterface_wlan_t *nic;
2610 /*Pass the frame on the monitor interface, if any.*/
2611 /*Otherwise, pass it on p2p0 netdev, if registered on it*/
2612 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
2613 nic = netdev_priv(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2614 if (nic->monitor_flag) {
2615 WILC_WFI_monitor_rx(buff, size);
2621 nic = netdev_priv(g_linux_wlan->strInterfaceInfo[1].wilc_netdev); /* p2p0 */
2622 if ((buff[0] == nic->g_struct_frame_reg[0].frame_type && nic->g_struct_frame_reg[0].reg) ||
2623 (buff[0] == nic->g_struct_frame_reg[1].frame_type && nic->g_struct_frame_reg[1].reg)) {
2624 WILC_WFI_p2p_rx(g_linux_wlan->strInterfaceInfo[1].wilc_netdev, buff, size);
2629 int wilc_netdev_init(void)
2633 perInterface_wlan_t *nic;
2634 struct net_device *ndev;
2636 linux_wlan_init_lock("close_exit_sync", &close_exit_sync, 0);
2638 /*create the common structure*/
2639 g_linux_wlan = (linux_wlan_t *)WILC_MALLOC(sizeof(linux_wlan_t));
2640 memset(g_linux_wlan, 0, sizeof(linux_wlan_t));
2642 /*Reset interrupt count debug*/
2646 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
2647 register_inetaddr_notifier(&g_dev_notifier);
2650 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
2651 /*allocate first ethernet device with perinterface_wlan_t as its private data*/
2652 ndev = alloc_etherdev(sizeof(perInterface_wlan_t));
2654 PRINT_ER("Failed to allocate ethernet dev\n");
2658 nic = netdev_priv(ndev);
2659 memset(nic, 0, sizeof(perInterface_wlan_t));
2661 /*Name the Devices*/
2663 #if defined(NM73131) /* tony, 2012-09-20 */
2664 strcpy(ndev->name, "wilc_eth%d");
2665 #elif defined(PLAT_CLM9722) /* rachel */
2666 strcpy(ndev->name, "eth%d");
2667 #else /* PANDA_BOARD, PLAT_ALLWINNER_A10, PLAT_ALLWINNER_A20, PLAT_ALLWINNER_A31, PLAT_AML8726_M3 or PLAT_WMS8304 */
2668 strcpy(ndev->name, "wlan%d");
2671 strcpy(ndev->name, "p2p%d");
2673 nic->u8IfIdx = g_linux_wlan->u8NoIfcs;
2674 nic->wilc_netdev = ndev;
2675 g_linux_wlan->strInterfaceInfo[g_linux_wlan->u8NoIfcs].wilc_netdev = ndev;
2676 g_linux_wlan->u8NoIfcs++;
2677 ndev->netdev_ops = &wilc_netdev_ops;
2681 struct wireless_dev *wdev;
2683 wdev = WILC_WFI_WiphyRegister(ndev);
2686 /* set netdev, tony */
2687 SET_NETDEV_DEV(ndev, &local_sdio_func->dev);
2691 PRINT_ER("Can't register WILC Wiphy\n");
2695 /*linking the wireless_dev structure with the netdevice*/
2696 nic->wilc_netdev->ieee80211_ptr = wdev;
2697 nic->wilc_netdev->ml_priv = nic;
2698 wdev->netdev = nic->wilc_netdev;
2699 nic->netstats.rx_packets = 0;
2700 nic->netstats.tx_packets = 0;
2701 nic->netstats.rx_bytes = 0;
2702 nic->netstats.tx_bytes = 0;
2708 if (register_netdev(ndev)) {
2709 PRINT_ER("Device couldn't be registered - %s\n", ndev->name);
2710 return -1; /* ERROR */
2713 nic->iftype = STATION_MODE;
2714 nic->mac_opened = 0;
2719 if (!linux_spi_init(&g_linux_wlan->wilc_spidev)) {
2720 PRINT_ER("Can't initialize SPI \n");
2721 return -1; /* ERROR */
2723 g_linux_wlan->wilc_spidev = wilc_spi_dev;
2725 g_linux_wlan->wilc_sdio_func = local_sdio_func;
2732 /*The 1st function called after module inserted*/
2733 static int __init init_wilc_driver(void)
2737 #if defined (WILC_DEBUGFS)
2738 if (wilc_debugfs_init() < 0) {
2739 PRINT_D(GENERIC_DBG, "fail to create debugfs for wilc driver\n");
2744 printk("IN INIT FUNCTION\n");
2745 printk("*** WILC1000 driver VERSION=[10.2] FW_VER=[10.2] ***\n");
2747 linux_wlan_device_power(1);
2749 linux_wlan_device_detection(1);
2755 ret = sdio_register_driver(&wilc_bus);
2757 PRINT_D(INIT_DBG, "init_wilc_driver: Failed register sdio driver\n");
2763 PRINT_D(INIT_DBG, "Initializing netdev\n");
2764 if (wilc_netdev_init()) {
2765 PRINT_ER("Couldn't initialize netdev\n");
2770 late_initcall(init_wilc_driver);
2772 static void __exit exit_wilc_driver(void)
2775 perInterface_wlan_t *nic[NUM_CONCURRENT_IFC] = {NULL,};
2776 #define CLOSE_TIMEOUT (12 * 1000)
2778 if ((g_linux_wlan != NULL) && (((g_linux_wlan->strInterfaceInfo[0].wilc_netdev) != NULL)
2779 || ((g_linux_wlan->strInterfaceInfo[1].wilc_netdev) != NULL))) {
2780 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
2781 unregister_inetaddr_notifier(&g_dev_notifier);
2784 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
2785 nic[i] = netdev_priv(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2790 if ((g_linux_wlan != NULL) && g_linux_wlan->wilc_firmware != NULL) {
2791 release_firmware(g_linux_wlan->wilc_firmware);
2792 g_linux_wlan->wilc_firmware = NULL;
2796 if ((g_linux_wlan != NULL) && (((g_linux_wlan->strInterfaceInfo[0].wilc_netdev) != NULL)
2797 || ((g_linux_wlan->strInterfaceInfo[1].wilc_netdev) != NULL))) {
2798 PRINT_D(INIT_DBG, "Waiting for mac_close ....\n");
2800 if (linux_wlan_lock_timeout(&close_exit_sync, CLOSE_TIMEOUT) < 0)
2801 PRINT_D(INIT_DBG, "Closed TimedOUT\n");
2803 PRINT_D(INIT_DBG, "mac_closed\n");
2806 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
2807 /* close all opened interfaces */
2808 if (g_linux_wlan->strInterfaceInfo[i].wilc_netdev != NULL) {
2809 if (nic[i]->mac_opened) {
2810 mac_close(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2814 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
2815 PRINT_D(INIT_DBG, "Unregistering netdev %p \n", g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2816 unregister_netdev(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2818 PRINT_D(INIT_DBG, "Freeing Wiphy...\n");
2819 WILC_WFI_WiphyFree(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2821 PRINT_D(INIT_DBG, "Freeing netdev...\n");
2822 free_netdev(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2828 #ifdef WILC_AP_EXTERNAL_MLME
2829 /* Bug 4600 : WILC_WFI_deinit_mon_interface was already called at mac_close */
2830 /* WILC_WFI_deinit_mon_interface(); */
2834 /* if(g_linux_wlan->open_ifcs==0) */
2837 PRINT_D(INIT_DBG, "SPI unregsiter...\n");
2838 spi_unregister_driver(&wilc_bus);
2840 PRINT_D(INIT_DBG, "SDIO unregsiter...\n");
2841 sdio_unregister_driver(&wilc_bus);
2844 linux_wlan_deinit_lock(&close_exit_sync);
2845 if (g_linux_wlan != NULL) {
2846 WILC_FREE(g_linux_wlan);
2847 g_linux_wlan = NULL;
2849 printk("Module_exit Done.\n");
2851 #if defined (WILC_DEBUGFS)
2852 wilc_debugfs_remove();
2855 linux_wlan_device_detection(0);
2856 linux_wlan_device_power(0);
2859 module_exit(exit_wilc_driver);
2861 MODULE_LICENSE("GPL");