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");
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
= 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
= 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
= 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 } else if (flag
== WILC_MAC_INDICATE_SCAN
) {
762 PRINT_D(GENERIC_DBG
, "Scanning ...\n");
768 struct net_device
*GetIfHandler(uint8_t *pMacHeader
)
770 uint8_t *Bssid
, *Bssid1
;
773 Bssid
= pMacHeader
+ 10;
774 Bssid1
= pMacHeader
+ 4;
776 for (i
= 0; i
< g_linux_wlan
->u8NoIfcs
; i
++) {
777 if (!memcmp(Bssid1
, g_linux_wlan
->strInterfaceInfo
[i
].aBSSID
, ETH_ALEN
) ||
778 !memcmp(Bssid
, g_linux_wlan
->strInterfaceInfo
[i
].aBSSID
, ETH_ALEN
)) {
779 return g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
;
782 PRINT_INFO(INIT_DBG
, "Invalide handle\n");
783 for (i
= 0; i
< 25; i
++) {
784 PRINT_D(INIT_DBG
, "%02x ", pMacHeader
[i
]);
786 Bssid
= pMacHeader
+ 18;
787 Bssid1
= pMacHeader
+ 12;
788 for (i
= 0; i
< g_linux_wlan
->u8NoIfcs
; i
++) {
789 if (!memcmp(Bssid1
, g_linux_wlan
->strInterfaceInfo
[i
].aBSSID
, ETH_ALEN
) ||
790 !memcmp(Bssid
, g_linux_wlan
->strInterfaceInfo
[i
].aBSSID
, ETH_ALEN
)) {
791 PRINT_D(INIT_DBG
, "Ctx [%p]\n", g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
);
792 return g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
;
795 PRINT_INFO(INIT_DBG
, "\n");
799 int linux_wlan_set_bssid(struct net_device
*wilc_netdev
, uint8_t *pBSSID
)
804 PRINT_D(INIT_DBG
, "set bssid on[%p]\n", wilc_netdev
);
805 for (i
= 0; i
< g_linux_wlan
->u8NoIfcs
; i
++) {
806 if (g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
== wilc_netdev
) {
807 PRINT_D(INIT_DBG
, "set bssid [%x][%x][%x]\n", pBSSID
[0], pBSSID
[1], pBSSID
[2]);
808 memcpy(g_linux_wlan
->strInterfaceInfo
[i
].aBSSID
, pBSSID
, 6);
817 /*Function to get number of connected interfaces*/
818 int linux_wlan_get_num_conn_ifcs(void)
821 uint8_t null_bssid
[6] = {0};
824 for (i
= 0; i
< g_linux_wlan
->u8NoIfcs
; i
++) {
825 if (memcmp(g_linux_wlan
->strInterfaceInfo
[i
].aBSSID
, null_bssid
, 6)) {
832 static int linux_wlan_rxq_task(void *vp
)
835 /* inform wilc1000_wlan_init that RXQ task is started. */
836 linux_wlan_unlock(&g_linux_wlan
->rxq_thread_started
);
838 linux_wlan_lock(&g_linux_wlan
->rxq_event
);
839 /* wait_for_completion(&g_linux_wlan->rxq_event); */
841 if (g_linux_wlan
->close
) {
842 /*Unlock the mutex in the mac_close function to indicate the exiting of the RX thread */
843 linux_wlan_unlock(&g_linux_wlan
->rxq_thread_started
);
845 while (!kthread_should_stop())
848 PRINT_D(RX_DBG
, " RX thread stopped\n");
851 PRINT_D(RX_DBG
, "Calling wlan_handle_rx_que()\n");
853 g_linux_wlan
->oup
.wlan_handle_rx_que();
858 #define USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
860 static int linux_wlan_txq_task(void *vp
)
864 #if defined USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
865 #define TX_BACKOFF_WEIGHT_INCR_STEP (1)
866 #define TX_BACKOFF_WEIGHT_DECR_STEP (1)
867 #define TX_BACKOFF_WEIGHT_MAX (7)
868 #define TX_BACKOFF_WEIGHT_MIN (0)
869 #define TX_BACKOFF_WEIGHT_UNIT_MS (10)
870 int backoff_weight
= TX_BACKOFF_WEIGHT_MIN
;
873 /* inform wilc1000_wlan_init that TXQ task is started. */
874 linux_wlan_unlock(&g_linux_wlan
->txq_thread_started
);
877 PRINT_D(TX_DBG
, "txq_task Taking a nap :)\n");
878 linux_wlan_lock(&g_linux_wlan
->txq_event
);
879 /* wait_for_completion(&pd->txq_event); */
880 PRINT_D(TX_DBG
, "txq_task Who waked me up :$\n");
882 if (g_linux_wlan
->close
) {
883 /*Unlock the mutex in the mac_close function to indicate the exiting of the TX thread */
884 linux_wlan_unlock(&g_linux_wlan
->txq_thread_started
);
886 while (!kthread_should_stop())
889 PRINT_D(TX_DBG
, "TX thread stopped\n");
892 PRINT_D(TX_DBG
, "txq_task handle the sending packet and let me go to sleep.\n");
893 #if !defined USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
894 g_linux_wlan
->oup
.wlan_handle_tx_que();
897 ret
= g_linux_wlan
->oup
.wlan_handle_tx_que(&txq_count
);
898 if (txq_count
< FLOW_CONTROL_LOWER_THRESHOLD
/* && netif_queue_stopped(pd->wilc_netdev)*/) {
899 PRINT_D(TX_DBG
, "Waking up queue\n");
900 /* netif_wake_queue(pd->wilc_netdev); */
901 if (netif_queue_stopped(g_linux_wlan
->strInterfaceInfo
[0].wilc_netdev
))
902 netif_wake_queue(g_linux_wlan
->strInterfaceInfo
[0].wilc_netdev
);
903 if (netif_queue_stopped(g_linux_wlan
->strInterfaceInfo
[1].wilc_netdev
))
904 netif_wake_queue(g_linux_wlan
->strInterfaceInfo
[1].wilc_netdev
);
907 if (ret
== WILC_TX_ERR_NO_BUF
) { /* failed to allocate buffers in chip. */
909 /* Back off from sending packets for some time. */
910 /* schedule_timeout will allow RX task to run and free buffers.*/
911 /* set_current_state(TASK_UNINTERRUPTIBLE); */
912 /* timeout = schedule_timeout(timeout); */
913 msleep(TX_BACKOFF_WEIGHT_UNIT_MS
<< backoff_weight
);
914 } while (/*timeout*/ 0);
915 backoff_weight
+= TX_BACKOFF_WEIGHT_INCR_STEP
;
916 if (backoff_weight
> TX_BACKOFF_WEIGHT_MAX
) {
917 backoff_weight
= TX_BACKOFF_WEIGHT_MAX
;
920 if (backoff_weight
> TX_BACKOFF_WEIGHT_MIN
) {
921 backoff_weight
-= TX_BACKOFF_WEIGHT_DECR_STEP
;
922 if (backoff_weight
< TX_BACKOFF_WEIGHT_MIN
) {
923 backoff_weight
= TX_BACKOFF_WEIGHT_MIN
;
927 /*TODO: drop packets after a certain time/number of retry count. */
928 } while (ret
== WILC_TX_ERR_NO_BUF
&& !g_linux_wlan
->close
); /* retry sending packets if no more buffers in chip. */
934 static void linux_wlan_rx_complete(void)
936 PRINT_D(RX_DBG
, "RX completed\n");
939 int linux_wlan_get_firmware(perInterface_wlan_t
*p_nic
)
942 perInterface_wlan_t
*nic
= p_nic
;
944 const struct firmware
*wilc_firmware
;
948 if (nic
->iftype
== AP_MODE
)
949 firmware
= AP_FIRMWARE
;
950 else if (nic
->iftype
== STATION_MODE
)
951 firmware
= STA_FIRMWARE
;
955 PRINT_D(INIT_DBG
, "Get P2P_CONCURRENCY_FIRMWARE\n");
956 firmware
= P2P_CONCURRENCY_FIRMWARE
;
962 PRINT_ER("NIC is NULL\n");
966 if (&nic
->wilc_netdev
->dev
== NULL
) {
967 PRINT_ER("&nic->wilc_netdev->dev is NULL\n");
972 /* the firmare should be located in /lib/firmware in
973 * root file system with the name specified above */
976 if (request_firmware(&wilc_firmware
, firmware
, &g_linux_wlan
->wilc_sdio_func
->dev
) != 0) {
977 PRINT_ER("%s - firmare not available\n", firmware
);
982 if (request_firmware(&wilc_firmware
, firmware
, &g_linux_wlan
->wilc_spidev
->dev
) != 0) {
983 PRINT_ER("%s - firmare not available\n", firmware
);
988 g_linux_wlan
->wilc_firmware
= wilc_firmware
; /* Bug 4703 */
996 #ifdef COMPLEMENT_BOOT
997 int repeat_power_cycle(perInterface_wlan_t
*nic
);
1000 static int linux_wlan_start_firmware(perInterface_wlan_t
*nic
)
1004 /* start firmware */
1005 PRINT_D(INIT_DBG
, "Starting Firmware ...\n");
1006 ret
= g_linux_wlan
->oup
.wlan_start();
1008 PRINT_ER("Failed to start Firmware\n");
1012 /* wait for mac ready */
1013 PRINT_D(INIT_DBG
, "Waiting for Firmware to get ready ...\n");
1014 ret
= linux_wlan_lock_timeout(&g_linux_wlan
->sync_event
, 5000);
1016 #ifdef COMPLEMENT_BOOT
1017 static int timeout
= 5;
1020 PRINT_D(INIT_DBG
, "repeat power cycle[%d]", timeout
);
1021 ret
= repeat_power_cycle(nic
);
1028 PRINT_D(INIT_DBG
, "Firmware start timed out");
1032 * TODO: Driver shouoldn't wait forever for firmware to get started -
1033 * in case of timeout this should be handled properly
1035 PRINT_D(INIT_DBG
, "Firmware successfully started\n");
1040 static int linux_wlan_firmware_download(linux_wlan_t
*p_nic
)
1045 if (g_linux_wlan
->wilc_firmware
== NULL
) {
1046 PRINT_ER("Firmware buffer is NULL\n");
1051 * do the firmware download
1053 PRINT_D(INIT_DBG
, "Downloading Firmware ...\n");
1054 ret
= g_linux_wlan
->oup
.wlan_firmware_download(g_linux_wlan
->wilc_firmware
->data
, g_linux_wlan
->wilc_firmware
->size
);
1059 /* Freeing FW buffer */
1060 PRINT_D(INIT_DBG
, "Freeing FW buffer ...\n");
1061 PRINT_D(INIT_DBG
, "Releasing firmware\n");
1062 release_firmware(g_linux_wlan
->wilc_firmware
);
1063 g_linux_wlan
->wilc_firmware
= NULL
;
1065 PRINT_D(INIT_DBG
, "Download Succeeded \n");
1072 /* startup configuration - could be changed later using iconfig*/
1073 static int linux_wlan_init_test_config(struct net_device
*dev
, linux_wlan_t
*p_nic
)
1076 unsigned char c_val
[64];
1077 #ifndef STATIC_MACADDRESS
1078 unsigned char mac_add
[] = {0x00, 0x80, 0xC2, 0x5E, 0xa2, 0xff};
1082 struct WILC_WFI_priv
*priv
;
1083 tstrWILC_WFIDrv
*pstrWFIDrv
;
1085 PRINT_D(TX_DBG
, "Start configuring Firmware\n");
1086 #ifndef STATIC_MACADDRESS
1087 get_random_bytes(&mac_add
[5], 1);
1088 get_random_bytes(&mac_add
[4], 1);
1090 priv
= wiphy_priv(dev
->ieee80211_ptr
->wiphy
);
1091 pstrWFIDrv
= (tstrWILC_WFIDrv
*)priv
->hWILCWFIDrv
;
1092 PRINT_D(INIT_DBG
, "Host = %p\n", pstrWFIDrv
);
1094 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]);
1098 if (g_linux_wlan
->oup
.wlan_cfg_set
== NULL
) {
1099 PRINT_D(INIT_DBG
, "Null p[ointer\n");
1103 *(int *)c_val
= (u32
)pstrWFIDrv
;
1105 if (!g_linux_wlan
->oup
.wlan_cfg_set(1, WID_SET_DRV_HANDLER
, c_val
, 4, 0, 0))
1108 /*to tell fw that we are going to use PC test - WILC specific*/
1110 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_PC_TEST_MODE
, c_val
, 1, 0, 0))
1113 c_val
[0] = INFRASTRUCTURE
;
1114 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_BSS_TYPE
, c_val
, 1, 0, 0))
1118 /* c_val[0] = RATE_AUTO; / * bug 4275: Enable autorate and limit it to 24Mbps * / */
1119 c_val
[0] = RATE_AUTO
;
1120 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_CURRENT_TX_RATE
, c_val
, 1, 0, 0))
1123 c_val
[0] = G_MIXED_11B_2_MODE
;
1124 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11G_OPERATING_MODE
, c_val
, 1, 0, 0))
1128 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_CURRENT_CHANNEL
, c_val
, 1, 0, 0))
1131 c_val
[0] = G_SHORT_PREAMBLE
;
1132 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_PREAMBLE
, c_val
, 1, 0, 0))
1135 c_val
[0] = AUTO_PROT
;
1136 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_PROT_MECH
, c_val
, 1, 0, 0))
1139 #ifdef SWITCH_LOG_TERMINAL
1140 c_val
[0] = AUTO_PROT
;
1141 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_LOGTerminal_Switch
, c_val
, 1, 0, 0))
1145 c_val
[0] = ACTIVE_SCAN
;
1146 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_SCAN_TYPE
, c_val
, 1, 0, 0))
1149 c_val
[0] = SITE_SURVEY_OFF
;
1150 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_SITE_SURVEY
, c_val
, 1, 0, 0))
1153 *((int *)c_val
) = 0xffff; /* Never use RTS-CTS */
1154 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_RTS_THRESHOLD
, c_val
, 2, 0, 0))
1157 *((int *)c_val
) = 2346;
1158 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_FRAG_THRESHOLD
, c_val
, 2, 0, 0))
1162 /* -------------------------------------------------------------- */
1163 /* Configuration : String with length less than 32 bytes */
1164 /* Values to set : Any string with length less than 32 bytes */
1165 /* ( In BSS Station Set SSID to "" (null string) */
1166 /* to enable Broadcast SSID suppport ) */
1167 /* -------------------------------------------------------------- */
1168 #ifndef USE_WIRELESS
1169 strcpy(c_val
, "nwifi");
1170 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_SSID
, c_val
, (strlen(c_val
) + 1), 0, 0))
1175 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_BCAST_SSID
, c_val
, 1, 0, 0))
1179 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_QOS_ENABLE
, c_val
, 1, 0, 0))
1182 c_val
[0] = NO_POWERSAVE
;
1183 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_POWER_MANAGEMENT
, c_val
, 1, 0, 0))
1186 c_val
[0] = NO_ENCRYPT
; /* NO_ENCRYPT, 0x79 */
1187 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11I_MODE
, c_val
, 1, 0, 0))
1190 c_val
[0] = OPEN_SYSTEM
;
1191 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_AUTH_TYPE
, c_val
, 1, 0, 0))
1194 /* WEP/802 11I Configuration */
1195 /* ------------------------------------------------------------------ */
1196 /* Configuration : WEP Key */
1197 /* Values (0x) : 5 byte for WEP40 and 13 bytes for WEP104 */
1198 /* In case more than 5 bytes are passed on for WEP 40 */
1199 /* only first 5 bytes will be used as the key */
1200 /* ------------------------------------------------------------------ */
1202 strcpy(c_val
, "123456790abcdef1234567890");
1203 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_WEP_KEY_VALUE
, c_val
, (strlen(c_val
) + 1), 0, 0))
1206 /* WEP/802 11I Configuration */
1207 /* ------------------------------------------------------------------ */
1208 /* Configuration : AES/TKIP WPA/RSNA Pre-Shared Key */
1209 /* Values to set : Any string with length greater than equal to 8 bytes */
1210 /* and less than 64 bytes */
1211 /* ------------------------------------------------------------------ */
1212 strcpy(c_val
, "12345678");
1213 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11I_PSK
, c_val
, (strlen(c_val
)), 0, 0))
1216 /* IEEE802.1X Key Configuration */
1217 /* ------------------------------------------------------------------ */
1218 /* Configuration : Radius Server Access Secret Key */
1219 /* Values to set : Any string with length greater than equal to 8 bytes */
1220 /* and less than 65 bytes */
1221 /* ------------------------------------------------------------------ */
1222 strcpy(c_val
, "password");
1223 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_1X_KEY
, c_val
, (strlen(c_val
) + 1), 0, 0))
1226 /* IEEE802.1X Server Address Configuration */
1227 /* ------------------------------------------------------------------ */
1228 /* Configuration : Radius Server IP Address */
1229 /* Values to set : Any valid IP Address */
1230 /* ------------------------------------------------------------------ */
1235 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_1X_SERV_ADDR
, c_val
, 4, 0, 0))
1239 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_LISTEN_INTERVAL
, c_val
, 1, 0, 0))
1243 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_DTIM_PERIOD
, c_val
, 1, 0, 0))
1246 c_val
[0] = NORMAL_ACK
;
1247 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_ACK_POLICY
, c_val
, 1, 0, 0))
1251 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_USER_CONTROL_ON_TX_POWER
, c_val
, 1, 0, 0))
1255 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_TX_POWER_LEVEL_11A
, c_val
, 1, 0, 0))
1259 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_TX_POWER_LEVEL_11B
, c_val
, 1, 0, 0))
1262 /* Beacon Interval */
1263 /* -------------------------------------------------------------------- */
1264 /* Configuration : Sets the beacon interval value */
1265 /* Values to set : Any 16-bit value */
1266 /* -------------------------------------------------------------------- */
1268 *((int *)c_val
) = 100;
1269 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_BEACON_INTERVAL
, c_val
, 2, 0, 0))
1272 c_val
[0] = REKEY_DISABLE
;
1273 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_REKEY_POLICY
, c_val
, 1, 0, 0))
1276 /* Rekey Time (s) (Used only when the Rekey policy is 2 or 4) */
1277 /* -------------------------------------------------------------------- */
1278 /* Configuration : Sets the Rekey Time (s) */
1279 /* Values to set : 32-bit value */
1280 /* -------------------------------------------------------------------- */
1281 *((int *)c_val
) = 84600;
1282 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_REKEY_PERIOD
, c_val
, 4, 0, 0))
1285 /* Rekey Packet Count (in 1000s; used when Rekey Policy is 3) */
1286 /* -------------------------------------------------------------------- */
1287 /* Configuration : Sets Rekey Group Packet count */
1288 /* Values to set : 32-bit Value */
1289 /* -------------------------------------------------------------------- */
1290 *((int *)c_val
) = 500;
1291 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_REKEY_PACKET_COUNT
, c_val
, 4, 0, 0))
1295 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_SHORT_SLOT_ALLOWED
, c_val
, 1, 0, 0))
1298 c_val
[0] = G_SELF_CTS_PROT
;
1299 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_ERP_PROT_TYPE
, c_val
, 1, 0, 0))
1302 c_val
[0] = 1; /* Enable N */
1303 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_ENABLE
, c_val
, 1, 0, 0))
1306 c_val
[0] = HT_MIXED_MODE
;
1307 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_OPERATING_MODE
, c_val
, 1, 0, 0))
1310 c_val
[0] = 1; /* TXOP Prot disable in N mode: No RTS-CTS on TX A-MPDUs to save air-time. */
1311 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_TXOP_PROT_DISABLE
, c_val
, 1, 0, 0))
1314 memcpy(c_val
, mac_add
, 6);
1316 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_MAC_ADDR
, c_val
, 6, 0, 0))
1322 c_val
[0] = DETECT_PROTECT_REPORT
;
1323 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_OBSS_NONHT_DETECTION
, c_val
, 1, 0, 0))
1326 c_val
[0] = RTS_CTS_NONHT_PROT
;
1327 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_HT_PROT_TYPE
, c_val
, 1, 0, 0))
1331 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_RIFS_PROT_ENABLE
, c_val
, 1, 0, 0))
1334 c_val
[0] = MIMO_MODE
;
1335 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_SMPS_MODE
, c_val
, 1, 0, 0))
1339 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_CURRENT_TX_MCS
, c_val
, 1, 0, 0))
1342 c_val
[0] = 1; /* Enable N with immediate block ack. */
1343 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_IMMEDIATE_BA_ENABLED
, c_val
, 1, 1, (u32
)pstrWFIDrv
))
1353 /**************************/
1354 void wilc1000_wlan_deinit(linux_wlan_t
*nic
)
1357 if (g_linux_wlan
->wilc1000_initialized
) {
1359 printk("Deinitializing wilc1000 ...\n");
1362 PRINT_ER("nic is NULL\n");
1366 #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
1367 /* johnny : remove */
1368 PRINT_D(INIT_DBG
, "skip wilc_bus_set_default_speed\n");
1370 wilc_bus_set_default_speed();
1373 PRINT_D(INIT_DBG
, "Disabling IRQ\n");
1374 #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
1375 linux_wlan_disable_irq(IRQ_WAIT
);
1377 #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
1380 linux_wlan_lock_mutex((void *)&g_linux_wlan
->hif_cs
);
1381 disable_sdio_interrupt();
1382 linux_wlan_unlock_mutex((void *)&g_linux_wlan
->hif_cs
);
1387 /* not sure if the following unlocks are needed or not*/
1388 if (&g_linux_wlan
->rxq_event
!= NULL
) {
1389 linux_wlan_unlock(&g_linux_wlan
->rxq_event
);
1392 if (&g_linux_wlan
->txq_event
!= NULL
) {
1393 linux_wlan_unlock(&g_linux_wlan
->txq_event
);
1397 #if (RX_BH_TYPE == RX_BH_WORK_QUEUE)
1398 /*Removing the work struct from the linux kernel workqueue*/
1399 if (&g_linux_wlan
->rx_work_queue
!= NULL
)
1400 flush_work(&g_linux_wlan
->rx_work_queue
);
1402 #elif (RX_BH_TYPE == RX_BH_KTHREAD)
1403 /* if(&nic->rx_sem != NULL) */
1404 /* linux_wlan_unlock(&nic->rx_sem); */
1407 PRINT_D(INIT_DBG
, "Deinitializing Threads\n");
1408 wlan_deinitialize_threads(nic
);
1410 PRINT_D(INIT_DBG
, "Deinitializing IRQ\n");
1411 deinit_irq(g_linux_wlan
);
1414 if (&g_linux_wlan
->oup
!= NULL
) {
1415 if (g_linux_wlan
->oup
.wlan_stop
!= NULL
)
1416 g_linux_wlan
->oup
.wlan_stop();
1419 PRINT_D(INIT_DBG
, "Deinitializing WILC Wlan\n");
1420 wilc_wlan_deinit(nic
);
1421 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
1422 #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
1423 PRINT_D(INIT_DBG
, "Disabling IRQ 2\n");
1425 linux_wlan_lock_mutex((void *)&g_linux_wlan
->hif_cs
);
1426 disable_sdio_interrupt();
1427 linux_wlan_unlock_mutex((void *)&g_linux_wlan
->hif_cs
);
1431 /*De-Initialize locks*/
1432 PRINT_D(INIT_DBG
, "Deinitializing Locks\n");
1433 wlan_deinit_locks(g_linux_wlan
);
1435 /* announce that wilc1000 is not initialized */
1436 g_linux_wlan
->wilc1000_initialized
= 0;
1438 PRINT_D(INIT_DBG
, "wilc1000 deinitialization Done\n");
1441 PRINT_D(INIT_DBG
, "wilc1000 is not initialized\n");
1446 int wlan_init_locks(linux_wlan_t
*p_nic
)
1449 PRINT_D(INIT_DBG
, "Initializing Locks ...\n");
1451 /*initialize mutexes*/
1452 linux_wlan_init_mutex("hif_lock/hif_cs", &g_linux_wlan
->hif_cs
, 1);
1453 linux_wlan_init_mutex("rxq_lock/rxq_cs", &g_linux_wlan
->rxq_cs
, 1);
1454 linux_wlan_init_mutex("txq_lock/txq_cs", &g_linux_wlan
->txq_cs
, 1);
1456 /*Added by Amr - BugID_4720*/
1457 linux_wlan_init_spin_lock("txq_spin_lock/txq_cs", &g_linux_wlan
->txq_spinlock
, 1);
1459 /*Added by Amr - BugID_4720*/
1460 linux_wlan_init_lock("txq_add_to_head_lock/txq_cs", &g_linux_wlan
->txq_add_to_head_cs
, 1);
1462 linux_wlan_init_lock("txq_wait/txq_event", &g_linux_wlan
->txq_event
, 0);
1463 linux_wlan_init_lock("rxq_wait/rxq_event", &g_linux_wlan
->rxq_event
, 0);
1465 linux_wlan_init_lock("cfg_wait/cfg_event", &g_linux_wlan
->cfg_event
, 0);
1466 linux_wlan_init_lock("sync_event", &g_linux_wlan
->sync_event
, 0);
1468 linux_wlan_init_lock("rxq_lock/rxq_started", &g_linux_wlan
->rxq_thread_started
, 0);
1469 linux_wlan_init_lock("rxq_lock/txq_started", &g_linux_wlan
->txq_thread_started
, 0);
1471 #if (RX_BH_TYPE == RX_BH_KTHREAD)
1472 linux_wlan_init_lock("BH_SEM", &g_linux_wlan
->rx_sem
, 0);
1478 static int wlan_deinit_locks(linux_wlan_t
*nic
)
1480 PRINT_D(INIT_DBG
, "De-Initializing Locks\n");
1482 if (&g_linux_wlan
->hif_cs
!= NULL
)
1483 linux_wlan_deinit_mutex(&g_linux_wlan
->hif_cs
);
1485 if (&g_linux_wlan
->rxq_cs
!= NULL
)
1486 linux_wlan_deinit_mutex(&g_linux_wlan
->rxq_cs
);
1488 if (&g_linux_wlan
->txq_cs
!= NULL
)
1489 linux_wlan_deinit_mutex(&g_linux_wlan
->txq_cs
);
1491 /*Added by Amr - BugID_4720*/
1492 if (&g_linux_wlan
->txq_spinlock
!= NULL
)
1493 linux_wlan_deinit_spin_lock(&g_linux_wlan
->txq_spinlock
);
1495 if (&g_linux_wlan
->rxq_event
!= NULL
)
1496 linux_wlan_deinit_lock(&g_linux_wlan
->rxq_event
);
1498 if (&g_linux_wlan
->txq_event
!= NULL
)
1499 linux_wlan_deinit_lock(&g_linux_wlan
->txq_event
);
1501 /*Added by Amr - BugID_4720*/
1502 if (&g_linux_wlan
->txq_add_to_head_cs
!= NULL
)
1503 linux_wlan_deinit_lock(&g_linux_wlan
->txq_add_to_head_cs
);
1505 if (&g_linux_wlan
->rxq_thread_started
!= NULL
)
1506 linux_wlan_deinit_lock(&g_linux_wlan
->rxq_thread_started
);
1508 if (&g_linux_wlan
->txq_thread_started
!= NULL
)
1509 linux_wlan_deinit_lock(&g_linux_wlan
->txq_thread_started
);
1511 if (&g_linux_wlan
->cfg_event
!= NULL
)
1512 linux_wlan_deinit_lock(&g_linux_wlan
->cfg_event
);
1514 if (&g_linux_wlan
->sync_event
!= NULL
)
1515 linux_wlan_deinit_lock(&g_linux_wlan
->sync_event
);
1519 void linux_to_wlan(wilc_wlan_inp_t
*nwi
, linux_wlan_t
*nic
)
1522 PRINT_D(INIT_DBG
, "Linux to Wlan services ...\n");
1524 nwi
->os_context
.hif_critical_section
= (void *)&g_linux_wlan
->hif_cs
;
1525 nwi
->os_context
.os_private
= (void *)nic
;
1526 nwi
->os_context
.tx_buffer_size
= LINUX_TX_SIZE
;
1527 nwi
->os_context
.txq_critical_section
= (void *)&g_linux_wlan
->txq_cs
;
1529 /*Added by Amr - BugID_4720*/
1530 nwi
->os_context
.txq_add_to_head_critical_section
= (void *)&g_linux_wlan
->txq_add_to_head_cs
;
1532 /*Added by Amr - BugID_4720*/
1533 nwi
->os_context
.txq_spin_lock
= (void *)&g_linux_wlan
->txq_spinlock
;
1535 nwi
->os_context
.txq_wait_event
= (void *)&g_linux_wlan
->txq_event
;
1537 #if defined (MEMORY_STATIC)
1538 nwi
->os_context
.rx_buffer_size
= LINUX_RX_SIZE
;
1540 nwi
->os_context
.rxq_critical_section
= (void *)&g_linux_wlan
->rxq_cs
;
1541 nwi
->os_context
.rxq_wait_event
= (void *)&g_linux_wlan
->rxq_event
;
1542 nwi
->os_context
.cfg_wait_event
= (void *)&g_linux_wlan
->cfg_event
;
1544 nwi
->os_func
.os_sleep
= linux_wlan_msleep
;
1545 nwi
->os_func
.os_atomic_sleep
= linux_wlan_atomic_msleep
;
1546 nwi
->os_func
.os_debug
= linux_wlan_dbg
;
1547 nwi
->os_func
.os_malloc
= linux_wlan_malloc
;
1548 nwi
->os_func
.os_malloc_atomic
= linux_wlan_malloc_atomic
;
1549 nwi
->os_func
.os_free
= linux_wlan_free
;
1550 nwi
->os_func
.os_lock
= linux_wlan_lock
;
1551 nwi
->os_func
.os_unlock
= linux_wlan_unlock
;
1552 nwi
->os_func
.os_wait
= linux_wlan_lock_timeout
;
1553 nwi
->os_func
.os_signal
= linux_wlan_unlock
;
1554 nwi
->os_func
.os_enter_cs
= linux_wlan_lock_mutex
;
1555 nwi
->os_func
.os_leave_cs
= linux_wlan_unlock_mutex
;
1557 /*Added by Amr - BugID_4720*/
1558 nwi
->os_func
.os_spin_lock
= linux_wlan_spin_lock
;
1559 nwi
->os_func
.os_spin_unlock
= linux_wlan_spin_unlock
;
1562 nwi
->io_func
.io_type
= HIF_SDIO
;
1563 nwi
->io_func
.io_init
= linux_sdio_init
;
1564 nwi
->io_func
.io_deinit
= linux_sdio_deinit
;
1565 nwi
->io_func
.u
.sdio
.sdio_cmd52
= linux_sdio_cmd52
;
1566 nwi
->io_func
.u
.sdio
.sdio_cmd53
= linux_sdio_cmd53
;
1567 nwi
->io_func
.u
.sdio
.sdio_set_max_speed
= linux_sdio_set_max_speed
;
1568 nwi
->io_func
.u
.sdio
.sdio_set_default_speed
= linux_sdio_set_default_speed
;
1570 nwi
->io_func
.io_type
= HIF_SPI
;
1571 nwi
->io_func
.io_init
= linux_spi_init
;
1572 nwi
->io_func
.io_deinit
= linux_spi_deinit
;
1573 nwi
->io_func
.u
.spi
.spi_tx
= linux_spi_write
;
1574 nwi
->io_func
.u
.spi
.spi_rx
= linux_spi_read
;
1575 nwi
->io_func
.u
.spi
.spi_trx
= linux_spi_write_read
;
1576 nwi
->io_func
.u
.spi
.spi_max_speed
= linux_spi_set_max_speed
;
1579 /*for now - to be revised*/
1580 #ifdef WILC_FULLY_HOSTING_AP
1581 /* incase of Fully hosted AP, all non cfg pkts are processed here*/
1582 nwi
->net_func
.rx_indicate
= WILC_Process_rx_frame
;
1584 nwi
->net_func
.rx_indicate
= frmw_to_linux
;
1586 nwi
->net_func
.rx_complete
= linux_wlan_rx_complete
;
1587 nwi
->indicate_func
.mac_indicate
= linux_wlan_mac_indicate
;
1590 int wlan_initialize_threads(perInterface_wlan_t
*nic
)
1594 PRINT_D(INIT_DBG
, "Initializing Threads ...\n");
1596 #if (RX_BH_TYPE == RX_BH_WORK_QUEUE)
1597 /*Initialize rx work queue task*/
1598 INIT_WORK(&g_linux_wlan
->rx_work_queue
, isr_bh_routine
);
1599 #elif (RX_BH_TYPE == RX_BH_KTHREAD)
1600 PRINT_D(INIT_DBG
, "Creating kthread for Rxq BH\n");
1601 g_linux_wlan
->rx_bh_thread
= kthread_run(isr_bh_routine
, (void *)g_linux_wlan
, "K_RXQ_BH");
1602 if (g_linux_wlan
->rx_bh_thread
== 0) {
1603 PRINT_ER("couldn't create RX BH thread\n");
1609 #ifndef TCP_ENHANCEMENTS
1610 /* create rx task */
1611 PRINT_D(INIT_DBG
, "Creating kthread for reception\n");
1612 g_linux_wlan
->rxq_thread
= kthread_run(linux_wlan_rxq_task
, (void *)g_linux_wlan
, "K_RXQ_TASK");
1613 if (g_linux_wlan
->rxq_thread
== 0) {
1614 PRINT_ER("couldn't create RXQ thread\n");
1619 /* wait for RXQ task to start. */
1620 linux_wlan_lock(&g_linux_wlan
->rxq_thread_started
);
1624 /* create tx task */
1625 PRINT_D(INIT_DBG
, "Creating kthread for transmission\n");
1626 g_linux_wlan
->txq_thread
= kthread_run(linux_wlan_txq_task
, (void *)g_linux_wlan
, "K_TXQ_TASK");
1627 if (g_linux_wlan
->txq_thread
== 0) {
1628 PRINT_ER("couldn't create TXQ thread\n");
1633 PRINT_D(INIT_DBG
, "Creating kthread for Debugging\n");
1634 g_linux_wlan
->txq_thread
= kthread_run(DebuggingThreadTask
, (void *)g_linux_wlan
, "DebugThread");
1635 if (g_linux_wlan
->txq_thread
== 0) {
1636 PRINT_ER("couldn't create TXQ thread\n");
1641 /* wait for TXQ task to start. */
1642 linux_wlan_lock(&g_linux_wlan
->txq_thread_started
);
1647 /*De-Initialize 2nd thread*/
1648 g_linux_wlan
->close
= 1;
1649 linux_wlan_unlock(&g_linux_wlan
->rxq_event
);
1650 kthread_stop(g_linux_wlan
->rxq_thread
);
1652 #ifndef TCP_ENHANCEMENTS
1655 #if (RX_BH_TYPE == RX_BH_KTHREAD)
1656 /*De-Initialize 1st thread*/
1657 g_linux_wlan
->close
= 1;
1658 linux_wlan_unlock(&g_linux_wlan
->rx_sem
);
1659 kthread_stop(g_linux_wlan
->rx_bh_thread
);
1662 g_linux_wlan
->close
= 0;
1666 static void wlan_deinitialize_threads(linux_wlan_t
*nic
)
1669 g_linux_wlan
->close
= 1;
1670 PRINT_D(INIT_DBG
, "Deinitializing Threads\n");
1671 if (&g_linux_wlan
->rxq_event
!= NULL
)
1672 linux_wlan_unlock(&g_linux_wlan
->rxq_event
);
1675 if (g_linux_wlan
->rxq_thread
!= NULL
) {
1676 kthread_stop(g_linux_wlan
->rxq_thread
);
1677 g_linux_wlan
->rxq_thread
= NULL
;
1681 if (&g_linux_wlan
->txq_event
!= NULL
)
1682 linux_wlan_unlock(&g_linux_wlan
->txq_event
);
1685 if (g_linux_wlan
->txq_thread
!= NULL
) {
1686 kthread_stop(g_linux_wlan
->txq_thread
);
1687 g_linux_wlan
->txq_thread
= NULL
;
1690 #if (RX_BH_TYPE == RX_BH_KTHREAD)
1691 if (&g_linux_wlan
->rx_sem
!= NULL
)
1692 linux_wlan_unlock(&g_linux_wlan
->rx_sem
);
1694 if (g_linux_wlan
->rx_bh_thread
!= NULL
) {
1695 kthread_stop(g_linux_wlan
->rx_bh_thread
);
1696 g_linux_wlan
->rx_bh_thread
= NULL
;
1701 #ifdef STATIC_MACADDRESS
1702 const char *path_string
[] = {
1707 static int linux_wlan_read_mac_addr(void *vp
)
1710 struct file
*fp
= (struct file
*)-ENOENT
;
1711 mm_segment_t old_fs
;
1714 int array_size
= ARRAY_SIZE(path_string
);
1716 /* change to KERNEL_DS address limit */
1720 for (index
= 0; index
< array_size
; index
++) {
1721 fp
= filp_open(path_string
[index
], O_WRONLY
, 0640);
1727 /*No such file or directory */
1728 if (IS_ERR(fp
) || !fp
->f_op
) {
1729 get_random_bytes(&mac_add
[3], 3);
1730 /* open file to write */
1731 fp
= filp_open(path_string
[index
], O_WRONLY
| O_CREAT
, 0640);
1733 if (!fp
|| IS_ERR(fp
)) {
1737 /* write buf to file */
1738 fp
->f_op
->write(fp
, mac_add
, 6, &pos
);
1742 /* read file to buf */
1743 fp
->f_op
->read(fp
, mac_add
, 6, &pos
);
1748 if (index
== array_size
) {
1749 PRINT_ER("random MAC\n");
1753 if (fp
&& !IS_ERR(fp
)) {
1754 filp_close(fp
, NULL
);
1763 #ifdef COMPLEMENT_BOOT
1765 extern volatile int probe
;
1766 extern uint8_t core_11b_ready(void);
1768 #define READY_CHECK_THRESHOLD 30
1769 extern void wilc_wlan_global_reset(void);
1770 uint8_t wilc1000_prepare_11b_core(wilc_wlan_inp_t
*nwi
, wilc_wlan_oup_t
*nwo
, linux_wlan_t
*nic
)
1773 while ((core_11b_ready() && (READY_CHECK_THRESHOLD
> (trials
++)))) {
1774 PRINT_D(INIT_DBG
, "11b core not ready yet: %u\n", trials
);
1775 wilc_wlan_deinit(nic
);
1776 wilc_wlan_global_reset();
1777 sdio_unregister_driver(&wilc_bus
);
1779 linux_wlan_device_detection(0);
1783 linux_wlan_device_detection(1);
1785 sdio_register_driver(&wilc_bus
);
1791 g_linux_wlan
->wilc_sdio_func
= local_sdio_func
;
1792 linux_to_wlan(nwi
, nic
);
1793 wilc_wlan_init(nwi
, nwo
);
1796 if (READY_CHECK_THRESHOLD
<= trials
)
1803 int repeat_power_cycle(perInterface_wlan_t
*nic
)
1806 wilc_wlan_inp_t nwi
;
1807 wilc_wlan_oup_t nwo
;
1808 sdio_unregister_driver(&wilc_bus
);
1810 linux_wlan_device_detection(0);
1811 linux_wlan_device_power(0);
1813 linux_wlan_device_power(1);
1815 linux_wlan_device_detection(1);
1818 sdio_register_driver(&wilc_bus
);
1825 g_linux_wlan
->wilc_sdio_func
= local_sdio_func
;
1826 linux_to_wlan(&nwi
, g_linux_wlan
);
1827 ret
= wilc_wlan_init(&nwi
, &nwo
);
1829 g_linux_wlan
->mac_status
= WILC_MAC_STATUS_INIT
;
1830 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
1831 enable_sdio_interrupt();
1834 if (linux_wlan_get_firmware(nic
)) {
1835 PRINT_ER("Can't get firmware \n");
1840 /*Download firmware*/
1841 ret
= linux_wlan_firmware_download(g_linux_wlan
);
1843 PRINT_ER("Failed to download firmware\n");
1847 ret
= linux_wlan_start_firmware(nic
);
1849 PRINT_ER("Failed to start firmware\n");
1856 int wilc1000_wlan_init(struct net_device
*dev
, perInterface_wlan_t
*p_nic
)
1858 wilc_wlan_inp_t nwi
;
1859 wilc_wlan_oup_t nwo
;
1860 perInterface_wlan_t
*nic
= p_nic
;
1863 if (!g_linux_wlan
->wilc1000_initialized
) {
1864 g_linux_wlan
->mac_status
= WILC_MAC_STATUS_INIT
;
1865 g_linux_wlan
->close
= 0;
1866 g_linux_wlan
->wilc1000_initialized
= 0;
1868 wlan_init_locks(g_linux_wlan
);
1870 #ifdef STATIC_MACADDRESS
1871 wilc_mac_thread
= kthread_run(linux_wlan_read_mac_addr
, NULL
, "wilc_mac_thread");
1872 if (wilc_mac_thread
< 0) {
1873 PRINT_ER("couldn't create Mac addr thread\n");
1877 linux_to_wlan(&nwi
, g_linux_wlan
);
1879 ret
= wilc_wlan_init(&nwi
, &nwo
);
1881 PRINT_ER("Initializing WILC_Wlan FAILED\n");
1885 memcpy(&g_linux_wlan
->oup
, &nwo
, sizeof(wilc_wlan_oup_t
));
1887 /*Save the oup structre into global pointer*/
1888 gpstrWlanOps
= &g_linux_wlan
->oup
;
1891 ret
= wlan_initialize_threads(nic
);
1893 PRINT_ER("Initializing Threads FAILED\n");
1895 goto _fail_wilc_wlan_
;
1898 #if (defined WILC_SDIO) && (defined COMPLEMENT_BOOT)
1899 if (wilc1000_prepare_11b_core(&nwi
, &nwo
, g_linux_wlan
)) {
1900 PRINT_ER("11b Core is not ready\n");
1902 goto _fail_threads_
;
1906 #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
1907 if (init_irq(g_linux_wlan
)) {
1908 PRINT_ER("couldn't initialize IRQ\n");
1910 goto _fail_threads_
;
1914 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
1915 if (enable_sdio_interrupt()) {
1916 PRINT_ER("couldn't initialize IRQ\n");
1918 goto _fail_irq_init_
;
1922 if (linux_wlan_get_firmware(nic
)) {
1923 PRINT_ER("Can't get firmware \n");
1925 goto _fail_irq_enable_
;
1929 /*Download firmware*/
1930 ret
= linux_wlan_firmware_download(g_linux_wlan
);
1932 PRINT_ER("Failed to download firmware\n");
1934 goto _fail_irq_enable_
;
1938 ret
= linux_wlan_start_firmware(nic
);
1940 PRINT_ER("Failed to start firmware\n");
1942 goto _fail_irq_enable_
;
1945 wilc_bus_set_max_speed();
1947 if (g_linux_wlan
->oup
.wlan_cfg_get(1, WID_FIRMWARE_VERSION
, 1, 0)) {
1949 char Firmware_ver
[20];
1950 size
= g_linux_wlan
->oup
.wlan_cfg_get_value(
1951 WID_FIRMWARE_VERSION
,
1952 Firmware_ver
, sizeof(Firmware_ver
));
1953 Firmware_ver
[size
] = '\0';
1954 PRINT_D(INIT_DBG
, "***** Firmware Ver = %s *******\n", Firmware_ver
);
1956 /* Initialize firmware with default configuration */
1957 ret
= linux_wlan_init_test_config(dev
, g_linux_wlan
);
1960 PRINT_ER("Failed to configure firmware\n");
1962 goto _fail_fw_start_
;
1965 g_linux_wlan
->wilc1000_initialized
= 1;
1966 return 0; /*success*/
1970 if (&g_linux_wlan
->oup
!= NULL
) {
1971 if (g_linux_wlan
->oup
.wlan_stop
!= NULL
)
1972 g_linux_wlan
->oup
.wlan_stop();
1976 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
1977 disable_sdio_interrupt();
1980 #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
1981 deinit_irq(g_linux_wlan
);
1985 wlan_deinitialize_threads(g_linux_wlan
);
1987 wilc_wlan_deinit(g_linux_wlan
);
1989 wlan_deinit_locks(g_linux_wlan
);
1990 PRINT_ER("WLAN Iinitialization FAILED\n");
1992 PRINT_D(INIT_DBG
, "wilc1000 already initialized\n");
1999 * - this function will be called automatically by OS when module inserted.
2002 #if !defined (NM73131_0_BOARD)
2003 int mac_init_fn(struct net_device
*ndev
)
2006 /*Why we do this !!!*/
2007 netif_start_queue(ndev
); /* ma */
2008 netif_stop_queue(ndev
); /* ma */
2013 int mac_init_fn(struct net_device
*ndev
)
2016 unsigned char mac_add
[] = {0x00, 0x50, 0xc2, 0x5e, 0x10, 0x00};
2017 /* TODO: get MAC address whenever the source is EPROM - hardcoded and copy it to ndev*/
2018 memcpy(ndev
->dev_addr
, mac_add
, 6);
2020 if (!is_valid_ether_addr(ndev
->dev_addr
)) {
2021 PRINT_ER("Error: Wrong MAC address\n");
2030 void WILC_WFI_frame_register(struct wiphy
*wiphy
, struct net_device
*dev
,
2031 u16 frame_type
, bool reg
);
2033 /* This fn is called, when this device is setup using ifconfig */
2034 #if !defined (NM73131_0_BOARD)
2035 int mac_open(struct net_device
*ndev
)
2037 perInterface_wlan_t
*nic
;
2040 /*No need for setting mac address here anymore,*/
2041 /*Just set it in init_test_config()*/
2042 unsigned char mac_add
[ETH_ALEN
] = {0};
2045 struct WILC_WFI_priv
*priv
;
2047 nic
= netdev_priv(ndev
);
2048 priv
= wiphy_priv(nic
->wilc_netdev
->ieee80211_ptr
->wiphy
);
2049 PRINT_D(INIT_DBG
, "MAC OPEN[%p]\n", ndev
);
2052 ret
= WILC_WFI_InitHostInt(ndev
);
2054 PRINT_ER("Failed to initialize host interface\n");
2060 /*initialize platform*/
2061 PRINT_D(INIT_DBG
, "*** re-init ***\n");
2062 ret
= wilc1000_wlan_init(ndev
, nic
);
2064 PRINT_ER("Failed to initialize wilc1000\n");
2065 WILC_WFI_DeInitHostInt(ndev
);
2069 Set_machw_change_vir_if(false);
2071 host_int_get_MacAddress(priv
->hWILCWFIDrv
, mac_add
);
2072 PRINT_D(INIT_DBG
, "Mac address: %x:%x:%x:%x:%x:%x\n", mac_add
[0], mac_add
[1], mac_add
[2],
2073 mac_add
[3], mac_add
[4], mac_add
[5]);
2075 /* loop through the NUM of supported devices and set the MAC address */
2076 for (i
= 0; i
< g_linux_wlan
->u8NoIfcs
; i
++) {
2077 if (ndev
== g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
) {
2078 memcpy(g_linux_wlan
->strInterfaceInfo
[i
].aSrcAddress
, mac_add
, ETH_ALEN
);
2079 g_linux_wlan
->strInterfaceInfo
[i
].drvHandler
= (u32
)priv
->hWILCWFIDrv
;
2084 /* TODO: get MAC address whenever the source is EPROM - hardcoded and copy it to ndev*/
2085 memcpy(ndev
->dev_addr
, g_linux_wlan
->strInterfaceInfo
[i
].aSrcAddress
, ETH_ALEN
);
2087 if (!is_valid_ether_addr(ndev
->dev_addr
)) {
2088 PRINT_ER("Error: Wrong MAC address\n");
2094 WILC_WFI_frame_register(nic
->wilc_netdev
->ieee80211_ptr
->wiphy
, nic
->wilc_netdev
,
2095 nic
->g_struct_frame_reg
[0].frame_type
, nic
->g_struct_frame_reg
[0].reg
);
2096 WILC_WFI_frame_register(nic
->wilc_netdev
->ieee80211_ptr
->wiphy
, nic
->wilc_netdev
,
2097 nic
->g_struct_frame_reg
[1].frame_type
, nic
->g_struct_frame_reg
[1].reg
);
2098 netif_wake_queue(ndev
);
2099 g_linux_wlan
->open_ifcs
++;
2100 nic
->mac_opened
= 1;
2104 WILC_WFI_DeInitHostInt(ndev
);
2105 wilc1000_wlan_deinit(g_linux_wlan
);
2109 int mac_open(struct net_device
*ndev
)
2113 nic
= netdev_priv(ndev
);
2115 /*initialize platform*/
2116 if (wilc1000_wlan_init(nic
)) {
2117 PRINT_ER("Failed to initialize platform\n");
2120 /* Start the network interface queue for this device */
2121 PRINT_D(INIT_DBG
, "Starting netifQ\n");
2122 netif_start_queue(ndev
);
2123 /* linux_wlan_lock(&close_exit_sync); */
2128 struct net_device_stats
*mac_stats(struct net_device
*dev
)
2130 perInterface_wlan_t
*nic
= netdev_priv(dev
);
2133 return &nic
->netstats
;
2136 /* Setup the multicast filter */
2137 static void wilc_set_multicast_list(struct net_device
*dev
)
2140 struct netdev_hw_addr
*ha
;
2141 struct WILC_WFI_priv
*priv
;
2142 tstrWILC_WFIDrv
*pstrWFIDrv
;
2144 priv
= wiphy_priv(dev
->ieee80211_ptr
->wiphy
);
2145 pstrWFIDrv
= (tstrWILC_WFIDrv
*)priv
->hWILCWFIDrv
;
2151 PRINT_D(INIT_DBG
, "Setting Multicast List with count = %d. \n", dev
->mc
.count
);
2153 if (dev
->flags
& IFF_PROMISC
) {
2154 /* Normally, we should configure the chip to retrive all packets
2155 * but we don't wanna support this right now */
2156 /* TODO: add promiscuous mode support */
2157 PRINT_D(INIT_DBG
, "Set promiscuous mode ON, retrive all packets \n");
2161 /* If there's more addresses than we handle, get all multicast
2162 * packets and sort them out in software. */
2163 if ((dev
->flags
& IFF_ALLMULTI
) || (dev
->mc
.count
) > WILC_MULTICAST_TABLE_SIZE
) {
2164 PRINT_D(INIT_DBG
, "Disable multicast filter, retrive all multicast packets\n");
2165 /* get all multicast packets */
2166 host_int_setup_multicast_filter((WILC_WFIDrvHandle
)pstrWFIDrv
, false, 0);
2170 /* No multicast? Just get our own stuff */
2171 if ((dev
->mc
.count
) == 0) {
2172 PRINT_D(INIT_DBG
, "Enable multicast filter, retrive directed packets only.\n");
2173 host_int_setup_multicast_filter((WILC_WFIDrvHandle
)pstrWFIDrv
, true, 0);
2177 /* Store all of the multicast addresses in the hardware filter */
2178 netdev_for_each_mc_addr(ha
, dev
)
2180 WILC_memcpy(gau8MulticastMacAddrList
[i
], ha
->addr
, ETH_ALEN
);
2181 PRINT_D(INIT_DBG
, "Entry[%d]: %x:%x:%x:%x:%x:%x\n", i
,
2182 gau8MulticastMacAddrList
[i
][0], gau8MulticastMacAddrList
[i
][1], gau8MulticastMacAddrList
[i
][2], gau8MulticastMacAddrList
[i
][3], gau8MulticastMacAddrList
[i
][4], gau8MulticastMacAddrList
[i
][5]);
2186 host_int_setup_multicast_filter((WILC_WFIDrvHandle
)pstrWFIDrv
, true, (dev
->mc
.count
));
2192 static void linux_wlan_tx_complete(void *priv
, int status
)
2195 struct tx_complete_data
*pv_data
= (struct tx_complete_data
*)priv
;
2197 PRINT_D(TX_DBG
, "Packet sent successfully - Size = %d - Address = %p - SKB = %p\n", pv_data
->size
, pv_data
->buff
, pv_data
->skb
);
2199 PRINT_D(TX_DBG
, "Couldn't send packet - Size = %d - Address = %p - SKB = %p\n", pv_data
->size
, pv_data
->buff
, pv_data
->skb
);
2201 /* Free the SK Buffer, its work is done */
2202 dev_kfree_skb(pv_data
->skb
);
2203 linux_wlan_free(pv_data
);
2206 int mac_xmit(struct sk_buff
*skb
, struct net_device
*ndev
)
2208 perInterface_wlan_t
*nic
;
2209 struct tx_complete_data
*tx_data
= NULL
;
2213 struct ethhdr
*eth_h
;
2214 nic
= netdev_priv(ndev
);
2216 PRINT_D(INT_DBG
, "\n========\n IntUH: %d - IntBH: %d - IntCld: %d \n========\n", int_rcvdU
, int_rcvdB
, int_clrd
);
2217 PRINT_D(TX_DBG
, "Sending packet just received from TCP/IP\n");
2219 /* Stop the network interface queue */
2220 if (skb
->dev
!= ndev
) {
2221 PRINT_ER("Packet not destined to this device\n");
2225 tx_data
= (struct tx_complete_data
*)internal_alloc(sizeof(struct tx_complete_data
), GFP_ATOMIC
);
2226 if (tx_data
== NULL
) {
2227 PRINT_ER("Failed to allocate memory for tx_data structure\n");
2229 netif_wake_queue(ndev
);
2233 tx_data
->buff
= skb
->data
;
2234 tx_data
->size
= skb
->len
;
2237 eth_h
= (struct ethhdr
*)(skb
->data
);
2238 if (eth_h
->h_proto
== 0x8e88) {
2239 PRINT_D(INIT_DBG
, "EAPOL transmitted\n");
2242 /*get source and dest ip addresses*/
2243 ih
= (struct iphdr
*)(skb
->data
+ sizeof(struct ethhdr
));
2245 pu8UdpBuffer
= (char *)ih
+ sizeof(struct iphdr
);
2246 if ((pu8UdpBuffer
[1] == 68 && pu8UdpBuffer
[3] == 67) || (pu8UdpBuffer
[1] == 67 && pu8UdpBuffer
[3] == 68)) {
2247 PRINT_D(GENERIC_DBG
, "DHCP Message transmitted, type:%x %x %x\n", pu8UdpBuffer
[248], pu8UdpBuffer
[249], pu8UdpBuffer
[250]);
2250 PRINT_D(TX_DBG
, "Sending packet - Size = %d - Address = %p - SKB = %p\n", tx_data
->size
, tx_data
->buff
, tx_data
->skb
);
2252 /* Send packet to MAC HW - for now the tx_complete function will be just status
2253 * indicator. still not sure if I need to suspend host transmission till the tx_complete
2254 * function called or not?
2255 * allocated buffer will be freed in tx_complete function.
2257 PRINT_D(TX_DBG
, "Adding tx packet to TX Queue\n");
2258 nic
->netstats
.tx_packets
++;
2259 nic
->netstats
.tx_bytes
+= tx_data
->size
;
2260 tx_data
->pBssid
= g_linux_wlan
->strInterfaceInfo
[nic
->u8IfIdx
].aBSSID
;
2261 #ifndef WILC_FULLY_HOSTING_AP
2262 QueueCount
= g_linux_wlan
->oup
.wlan_add_to_tx_que((void *)tx_data
,
2265 linux_wlan_tx_complete
);
2267 QueueCount
= WILC_Xmit_data((void *)tx_data
, HOST_TO_WLAN
);
2268 #endif /* WILC_FULLY_HOSTING_AP */
2271 if (QueueCount
> FLOW_CONTROL_UPPER_THRESHOLD
) {
2272 netif_stop_queue(g_linux_wlan
->strInterfaceInfo
[0].wilc_netdev
);
2273 netif_stop_queue(g_linux_wlan
->strInterfaceInfo
[1].wilc_netdev
);
2280 int mac_close(struct net_device
*ndev
)
2282 struct WILC_WFI_priv
*priv
;
2283 perInterface_wlan_t
*nic
;
2284 tstrWILC_WFIDrv
*pstrWFIDrv
;
2286 nic
= netdev_priv(ndev
);
2288 if ((nic
== NULL
) || (nic
->wilc_netdev
== NULL
) || (nic
->wilc_netdev
->ieee80211_ptr
== NULL
) || (nic
->wilc_netdev
->ieee80211_ptr
->wiphy
== NULL
)) {
2289 PRINT_ER("nic = NULL\n");
2293 priv
= wiphy_priv(nic
->wilc_netdev
->ieee80211_ptr
->wiphy
);
2296 PRINT_ER("priv = NULL\n");
2300 pstrWFIDrv
= (tstrWILC_WFIDrv
*)priv
->hWILCWFIDrv
;
2304 PRINT_D(GENERIC_DBG
, "Mac close\n");
2306 if (g_linux_wlan
== NULL
) {
2307 PRINT_ER("g_linux_wlan = NULL\n");
2311 if (pstrWFIDrv
== NULL
) {
2312 PRINT_ER("pstrWFIDrv = NULL\n");
2316 if ((g_linux_wlan
->open_ifcs
) > 0) {
2317 g_linux_wlan
->open_ifcs
--;
2319 PRINT_ER("ERROR: MAC close called while number of opened interfaces is zero\n");
2323 if (nic
->wilc_netdev
!= NULL
) {
2324 /* Stop the network interface queue */
2325 netif_stop_queue(nic
->wilc_netdev
);
2328 WILC_WFI_DeInitHostInt(nic
->wilc_netdev
);
2332 if (g_linux_wlan
->open_ifcs
== 0) {
2333 PRINT_D(GENERIC_DBG
, "Deinitializing wilc1000\n");
2334 g_linux_wlan
->close
= 1;
2335 wilc1000_wlan_deinit(g_linux_wlan
);
2337 #ifdef WILC_AP_EXTERNAL_MLME
2338 WILC_WFI_deinit_mon_interface();
2343 linux_wlan_unlock(&close_exit_sync
);
2344 nic
->mac_opened
= 0;
2350 int mac_ioctl(struct net_device
*ndev
, struct ifreq
*req
, int cmd
)
2355 u32 size
= 0, length
= 0;
2356 perInterface_wlan_t
*nic
;
2357 struct WILC_WFI_priv
*priv
;
2358 s32 s32Error
= WILC_SUCCESS
;
2362 /* struct iwreq *wrq = (struct iwreq *) req; // tony moved to case SIOCSIWPRIV */
2364 nic
= netdev_priv(ndev
);
2366 if (!g_linux_wlan
->wilc1000_initialized
)
2376 struct iwreq
*wrq
= (struct iwreq
*) req
; /* added by tony */
2378 size
= wrq
->u
.data
.length
;
2380 if (size
&& wrq
->u
.data
.pointer
) {
2382 buff
= memdup_user(wrq
->u
.data
.pointer
, wrq
->u
.data
.length
);
2384 s32Error
= PTR_ERR(buff
);
2388 if (strncasecmp(buff
, "RSSI", length
) == 0) {
2391 priv
= wiphy_priv(nic
->wilc_netdev
->ieee80211_ptr
->wiphy
);
2392 s32Error
= host_int_get_rssi(priv
->hWILCWFIDrv
, &(rssi
));
2394 PRINT_ER("Failed to send get rssi param's message queue ");
2396 PRINT_INFO(GENERIC_DBG
, "RSSI :%d\n", rssi
);
2398 /*Rounding up the rssi negative value*/
2401 snprintf(buff
, size
, "rssi %d", rssi
);
2403 if (copy_to_user(wrq
->u
.data
.pointer
, buff
, size
)) {
2404 PRINT_ER("%s: failed to copy data to user buffer\n", __func__
);
2415 PRINT_INFO(GENERIC_DBG
, "Command - %d - has been received\n", cmd
);
2416 s32Error
= -EOPNOTSUPP
;
2430 void frmw_to_linux(uint8_t *buff
, uint32_t size
, uint32_t pkt_offset
)
2433 unsigned int frame_len
= 0;
2435 unsigned char *buff_to_send
= NULL
;
2436 struct sk_buff
*skb
;
2437 #ifndef TCP_ENHANCEMENTS
2441 struct net_device
*wilc_netdev
;
2442 perInterface_wlan_t
*nic
;
2444 wilc_netdev
= GetIfHandler(buff
);
2445 if (wilc_netdev
== NULL
)
2449 nic
= netdev_priv(wilc_netdev
);
2454 buff_to_send
= buff
;
2457 /* Need to send the packet up to the host, allocate a skb buffer */
2458 skb
= dev_alloc_skb(frame_len
);
2460 PRINT_ER("Low memory - packet droped\n");
2464 skb_reserve(skb
, (unsigned int)skb
->data
& 0x3);
2466 if (g_linux_wlan
== NULL
|| wilc_netdev
== NULL
) {
2467 PRINT_ER("wilc_netdev in g_linux_wlan is NULL");
2469 skb
->dev
= wilc_netdev
;
2471 if (skb
->dev
== NULL
) {
2472 PRINT_ER("skb->dev is NULL\n");
2479 * WILC_PRINTF("buff_to_send[%d]=%2x\n",i,buff_to_send[i]);
2483 /* skb_put(skb, frame_len); */
2484 memcpy(skb_put(skb
, frame_len
), buff_to_send
, frame_len
);
2486 /* WILC_PRINTF("After MEM_CPY\n"); */
2488 /* nic = netdev_priv(wilc_netdev); */
2491 /* if(nic->monitor_flag)
2493 * WILC_WFI_monitor_rx(nic->wilc_netdev,skb);
2497 skb
->protocol
= eth_type_trans(skb
, wilc_netdev
);
2498 #ifndef TCP_ENHANCEMENTS
2499 /*get source and dest ip addresses*/
2500 ih
= (struct iphdr
*)(skb
->data
+ sizeof(struct ethhdr
));
2502 pu8UdpBuffer
= (char *)ih
+ sizeof(struct iphdr
);
2503 if (buff_to_send
[35] == 67 && buff_to_send
[37] == 68) {
2504 PRINT_D(RX_DBG
, "DHCP Message received\n");
2506 if (buff_to_send
[12] == 0x88 && buff_to_send
[13] == 0x8e)
2507 PRINT_D(GENERIC_DBG
, "eapol received\n");
2509 /* Send the packet to the stack by giving it to the bridge */
2510 nic
->netstats
.rx_packets
++;
2511 nic
->netstats
.rx_bytes
+= frame_len
;
2512 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
2513 stats
= netif_rx(skb
);
2514 PRINT_D(RX_DBG
, "netif_rx ret value is: %d\n", stats
);
2516 #ifndef TCP_ENHANCEMENTS
2518 PRINT_ER("Discard sending packet with len = %d\n", size
);
2523 void WILC_WFI_mgmt_rx(uint8_t *buff
, uint32_t size
)
2526 perInterface_wlan_t
*nic
;
2529 /*Pass the frame on the monitor interface, if any.*/
2530 /*Otherwise, pass it on p2p0 netdev, if registered on it*/
2531 for (i
= 0; i
< g_linux_wlan
->u8NoIfcs
; i
++) {
2532 nic
= netdev_priv(g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
);
2533 if (nic
->monitor_flag
) {
2534 WILC_WFI_monitor_rx(buff
, size
);
2540 nic
= netdev_priv(g_linux_wlan
->strInterfaceInfo
[1].wilc_netdev
); /* p2p0 */
2541 if ((buff
[0] == nic
->g_struct_frame_reg
[0].frame_type
&& nic
->g_struct_frame_reg
[0].reg
) ||
2542 (buff
[0] == nic
->g_struct_frame_reg
[1].frame_type
&& nic
->g_struct_frame_reg
[1].reg
)) {
2543 WILC_WFI_p2p_rx(g_linux_wlan
->strInterfaceInfo
[1].wilc_netdev
, buff
, size
);
2548 int wilc_netdev_init(void)
2552 perInterface_wlan_t
*nic
;
2553 struct net_device
*ndev
;
2555 linux_wlan_init_lock("close_exit_sync", &close_exit_sync
, 0);
2557 /*create the common structure*/
2558 g_linux_wlan
= (linux_wlan_t
*)WILC_MALLOC(sizeof(linux_wlan_t
));
2559 memset(g_linux_wlan
, 0, sizeof(linux_wlan_t
));
2561 /*Reset interrupt count debug*/
2565 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
2566 register_inetaddr_notifier(&g_dev_notifier
);
2569 for (i
= 0; i
< NUM_CONCURRENT_IFC
; i
++) {
2570 /*allocate first ethernet device with perinterface_wlan_t as its private data*/
2571 ndev
= alloc_etherdev(sizeof(perInterface_wlan_t
));
2573 PRINT_ER("Failed to allocate ethernet dev\n");
2577 nic
= netdev_priv(ndev
);
2578 memset(nic
, 0, sizeof(perInterface_wlan_t
));
2580 /*Name the Devices*/
2582 #if defined(NM73131) /* tony, 2012-09-20 */
2583 strcpy(ndev
->name
, "wilc_eth%d");
2584 #elif defined(PLAT_CLM9722) /* rachel */
2585 strcpy(ndev
->name
, "eth%d");
2586 #else /* PANDA_BOARD, PLAT_ALLWINNER_A10, PLAT_ALLWINNER_A20, PLAT_ALLWINNER_A31, PLAT_AML8726_M3 or PLAT_WMS8304 */
2587 strcpy(ndev
->name
, "wlan%d");
2590 strcpy(ndev
->name
, "p2p%d");
2592 nic
->u8IfIdx
= g_linux_wlan
->u8NoIfcs
;
2593 nic
->wilc_netdev
= ndev
;
2594 g_linux_wlan
->strInterfaceInfo
[g_linux_wlan
->u8NoIfcs
].wilc_netdev
= ndev
;
2595 g_linux_wlan
->u8NoIfcs
++;
2596 ndev
->netdev_ops
= &wilc_netdev_ops
;
2600 struct wireless_dev
*wdev
;
2602 wdev
= WILC_WFI_WiphyRegister(ndev
);
2605 /* set netdev, tony */
2606 SET_NETDEV_DEV(ndev
, &local_sdio_func
->dev
);
2610 PRINT_ER("Can't register WILC Wiphy\n");
2614 /*linking the wireless_dev structure with the netdevice*/
2615 nic
->wilc_netdev
->ieee80211_ptr
= wdev
;
2616 nic
->wilc_netdev
->ml_priv
= nic
;
2617 wdev
->netdev
= nic
->wilc_netdev
;
2618 nic
->netstats
.rx_packets
= 0;
2619 nic
->netstats
.tx_packets
= 0;
2620 nic
->netstats
.rx_bytes
= 0;
2621 nic
->netstats
.tx_bytes
= 0;
2627 if (register_netdev(ndev
)) {
2628 PRINT_ER("Device couldn't be registered - %s\n", ndev
->name
);
2629 return -1; /* ERROR */
2632 nic
->iftype
= STATION_MODE
;
2633 nic
->mac_opened
= 0;
2638 if (!linux_spi_init(&g_linux_wlan
->wilc_spidev
)) {
2639 PRINT_ER("Can't initialize SPI \n");
2640 return -1; /* ERROR */
2642 g_linux_wlan
->wilc_spidev
= wilc_spi_dev
;
2644 g_linux_wlan
->wilc_sdio_func
= local_sdio_func
;
2651 /*The 1st function called after module inserted*/
2652 static int __init
init_wilc_driver(void)
2656 #if defined (WILC_DEBUGFS)
2657 if (wilc_debugfs_init() < 0) {
2658 PRINT_D(GENERIC_DBG
, "fail to create debugfs for wilc driver\n");
2663 printk("IN INIT FUNCTION\n");
2664 printk("*** WILC1000 driver VERSION=[10.2] FW_VER=[10.2] ***\n");
2666 linux_wlan_device_power(1);
2668 linux_wlan_device_detection(1);
2674 ret
= sdio_register_driver(&wilc_bus
);
2676 PRINT_D(INIT_DBG
, "init_wilc_driver: Failed register sdio driver\n");
2682 PRINT_D(INIT_DBG
, "Initializing netdev\n");
2683 if (wilc_netdev_init()) {
2684 PRINT_ER("Couldn't initialize netdev\n");
2689 late_initcall(init_wilc_driver
);
2691 static void __exit
exit_wilc_driver(void)
2694 perInterface_wlan_t
*nic
[NUM_CONCURRENT_IFC
] = {NULL
,};
2695 #define CLOSE_TIMEOUT (12 * 1000)
2697 if ((g_linux_wlan
!= NULL
) && (((g_linux_wlan
->strInterfaceInfo
[0].wilc_netdev
) != NULL
)
2698 || ((g_linux_wlan
->strInterfaceInfo
[1].wilc_netdev
) != NULL
))) {
2699 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
2700 unregister_inetaddr_notifier(&g_dev_notifier
);
2703 for (i
= 0; i
< NUM_CONCURRENT_IFC
; i
++) {
2704 nic
[i
] = netdev_priv(g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
);
2709 if ((g_linux_wlan
!= NULL
) && g_linux_wlan
->wilc_firmware
!= NULL
) {
2710 release_firmware(g_linux_wlan
->wilc_firmware
);
2711 g_linux_wlan
->wilc_firmware
= NULL
;
2715 if ((g_linux_wlan
!= NULL
) && (((g_linux_wlan
->strInterfaceInfo
[0].wilc_netdev
) != NULL
)
2716 || ((g_linux_wlan
->strInterfaceInfo
[1].wilc_netdev
) != NULL
))) {
2717 PRINT_D(INIT_DBG
, "Waiting for mac_close ....\n");
2719 if (linux_wlan_lock_timeout(&close_exit_sync
, CLOSE_TIMEOUT
) < 0)
2720 PRINT_D(INIT_DBG
, "Closed TimedOUT\n");
2722 PRINT_D(INIT_DBG
, "mac_closed\n");
2725 for (i
= 0; i
< NUM_CONCURRENT_IFC
; i
++) {
2726 /* close all opened interfaces */
2727 if (g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
!= NULL
) {
2728 if (nic
[i
]->mac_opened
) {
2729 mac_close(g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
);
2733 for (i
= 0; i
< NUM_CONCURRENT_IFC
; i
++) {
2734 PRINT_D(INIT_DBG
, "Unregistering netdev %p \n", g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
);
2735 unregister_netdev(g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
);
2737 PRINT_D(INIT_DBG
, "Freeing Wiphy...\n");
2738 WILC_WFI_WiphyFree(g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
);
2740 PRINT_D(INIT_DBG
, "Freeing netdev...\n");
2741 free_netdev(g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
);
2747 #ifdef WILC_AP_EXTERNAL_MLME
2748 /* Bug 4600 : WILC_WFI_deinit_mon_interface was already called at mac_close */
2749 /* WILC_WFI_deinit_mon_interface(); */
2753 /* if(g_linux_wlan->open_ifcs==0) */
2756 PRINT_D(INIT_DBG
, "SPI unregsiter...\n");
2757 spi_unregister_driver(&wilc_bus
);
2759 PRINT_D(INIT_DBG
, "SDIO unregsiter...\n");
2760 sdio_unregister_driver(&wilc_bus
);
2763 linux_wlan_deinit_lock(&close_exit_sync
);
2764 if (g_linux_wlan
!= NULL
) {
2765 WILC_FREE(g_linux_wlan
);
2766 g_linux_wlan
= NULL
;
2768 printk("Module_exit Done.\n");
2770 #if defined (WILC_DEBUGFS)
2771 wilc_debugfs_remove();
2774 linux_wlan_device_detection(0);
2775 linux_wlan_device_power(0);
2778 module_exit(exit_wilc_driver
);
2780 MODULE_LICENSE("GPL");