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>
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 WILC_Bool g_obtainingIP;
70 extern WILC_Uint16 Set_machw_change_vir_if(WILC_Bool bValue);
71 extern void resolve_disconnect_aberration(void *drvHandler);
72 extern WILC_Uint8 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 WILC_Bool bEnablePS = WILC_TRUE;
183 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0)
184 static const struct net_device_ops wilc_netdev_ops = {
185 .ndo_init = mac_init_fn,
186 .ndo_open = mac_open,
187 .ndo_stop = mac_close,
188 .ndo_start_xmit = mac_xmit,
189 .ndo_do_ioctl = mac_ioctl,
190 .ndo_get_stats = mac_stats,
191 .ndo_set_rx_mode = wilc_set_multicast_list,
194 #define wilc_set_netdev_ops(ndev) do { (ndev)->netdev_ops = &wilc_netdev_ops; } while (0)
195 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)
197 static const struct net_device_ops wilc_netdev_ops = {
198 .ndo_init = mac_init_fn,
199 .ndo_open = mac_open,
200 .ndo_stop = mac_close,
201 .ndo_start_xmit = mac_xmit,
202 .ndo_do_ioctl = mac_ioctl,
203 .ndo_get_stats = mac_stats,
204 .ndo_set_multicast_list = wilc_set_multicast_list,
208 #define wilc_set_netdev_ops(ndev) do { (ndev)->netdev_ops = &wilc_netdev_ops; } while (0)
212 static void wilc_set_netdev_ops(struct net_device *ndev)
215 ndev->init = mac_init_fn;
216 ndev->open = mac_open;
217 ndev->stop = mac_close;
218 ndev->hard_start_xmit = mac_xmit;
219 ndev->do_ioctl = mac_ioctl;
220 ndev->get_stats = mac_stats;
221 ndev->set_multicast_list = wilc_set_multicast_list,
227 extern volatile int timeNo;
229 #define DEGUG_BUFFER_LENGTH 1000
230 volatile int WatchDogdebuggerCounter;
231 char DebugBuffer[DEGUG_BUFFER_LENGTH + 20] = {0};
232 static char *ps8current = DebugBuffer;
236 void printk_later(const char *format, ...)
239 va_start (args, format);
240 ps8current += vsprintf (ps8current, format, args);
242 if ((ps8current - DebugBuffer) > DEGUG_BUFFER_LENGTH) {
243 ps8current = DebugBuffer;
251 if (DebugBuffer[0]) {
252 DebugBuffer[DEGUG_BUFFER_LENGTH] = 0;
253 PRINT_INFO(GENERIC_DBG, "early printed\n");
254 PRINT_D(GENERIC_DBG, ps8current + 1);
256 PRINT_INFO(GENERIC_DBG, "latest printed\n");
257 PRINT_D(GENERIC_DBG, DebugBuffer);
259 ps8current = DebugBuffer;
263 void Reset_WatchDogdebugger()
265 WatchDogdebuggerCounter = 0;
268 static int DebuggingThreadTask(void *vp)
271 while (!WatchDogdebuggerCounter) {
272 PRINT_D(GENERIC_DBG, "Debug Thread Running %d\n", timeNo);
273 WatchDogdebuggerCounter = 1;
277 WatchDogdebuggerCounter = 0;
285 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
286 static int dev_state_ev_handler(struct notifier_block *this, unsigned long event, void *ptr)
288 struct in_ifaddr *dev_iface = (struct in_ifaddr *)ptr;
289 struct WILC_WFI_priv *priv;
290 tstrWILC_WFIDrv *pstrWFIDrv;
291 struct net_device *dev;
292 WILC_Uint8 *pIP_Add_buff;
293 WILC_Sint32 s32status = WILC_FAIL;
294 perInterface_wlan_t *nic;
295 WILC_Uint8 null_ip[4] = {0};
296 char wlan_dev_name[5] = "wlan0";
298 if (dev_iface == NULL || dev_iface->ifa_dev == NULL || dev_iface->ifa_dev->dev == NULL) {
299 PRINT_D(GENERIC_DBG, "dev_iface = NULL\n");
303 if ((memcmp(dev_iface->ifa_label, "wlan0", 5)) && (memcmp(dev_iface->ifa_label, "p2p0", 4))) {
304 PRINT_D(GENERIC_DBG, "Interface is neither WLAN0 nor P2P0\n");
308 dev = (struct net_device *)dev_iface->ifa_dev->dev;
309 if (dev->ieee80211_ptr == NULL || dev->ieee80211_ptr->wiphy == NULL) {
310 PRINT_D(GENERIC_DBG, "No Wireless registerd\n");
313 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
315 PRINT_D(GENERIC_DBG, "No Wireless Priv\n");
318 pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
319 nic = netdev_priv(dev);
320 if (nic == NULL || pstrWFIDrv == NULL) {
321 PRINT_D(GENERIC_DBG, "No Wireless Priv\n");
325 PRINT_INFO(GENERIC_DBG, "dev_state_ev_handler +++\n"); /* tony */
329 PRINT_D(GENERIC_DBG, "dev_state_ev_handler event=NETDEV_UP %p\n", dev); /* tony */
331 PRINT_INFO(GENERIC_DBG, "\n ============== IP Address Obtained ===============\n\n");
334 /*If we are in station mode or client mode*/
335 if (nic->iftype == STATION_MODE || nic->iftype == CLIENT_MODE) {
336 pstrWFIDrv->IFC_UP = 1;
337 g_obtainingIP = WILC_FALSE;
338 WILC_TimerStop(&hDuringIpTimer, WILC_NULL);
339 PRINT_D(GENERIC_DBG, "IP obtained , enable scan\n");
344 if (bEnablePS == WILC_TRUE)
345 host_int_set_power_mgmt((WILC_WFIDrvHandle)pstrWFIDrv, 1, 0);
347 PRINT_D(GENERIC_DBG, "[%s] Up IP\n", dev_iface->ifa_label);
349 pIP_Add_buff = (char *) (&(dev_iface->ifa_address));
350 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]);
351 s32status = host_int_setup_ipaddress((WILC_WFIDrvHandle)pstrWFIDrv, pIP_Add_buff, nic->u8IfIdx);
356 PRINT_D(GENERIC_DBG, "dev_state_ev_handler event=NETDEV_DOWN %p\n", dev); /* tony */
358 PRINT_INFO(GENERIC_DBG, "\n ============== IP Address Released ===============\n\n");
359 if (nic->iftype == STATION_MODE || nic->iftype == CLIENT_MODE) {
360 pstrWFIDrv->IFC_UP = 0;
361 g_obtainingIP = WILC_FALSE;
364 if (memcmp(dev_iface->ifa_label, wlan_dev_name, 5) == 0)
365 host_int_set_power_mgmt((WILC_WFIDrvHandle)pstrWFIDrv, 0, 0);
367 resolve_disconnect_aberration(pstrWFIDrv);
370 PRINT_D(GENERIC_DBG, "[%s] Down IP\n", dev_iface->ifa_label);
372 pIP_Add_buff = null_ip;
373 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]);
375 s32status = host_int_setup_ipaddress((WILC_WFIDrvHandle)pstrWFIDrv, pIP_Add_buff, nic->u8IfIdx);
380 PRINT_INFO(GENERIC_DBG, "dev_state_ev_handler event=default\n"); /* tony */
381 PRINT_INFO(GENERIC_DBG, "[%s] unknown dev event: %lu\n", dev_iface->ifa_label, event);
392 * Interrupt initialization and handling functions
395 void linux_wlan_enable_irq(void)
398 #if (RX_BH_TYPE != RX_BH_THREADED_IRQ)
399 #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
400 PRINT_D(INT_DBG, "Enabling IRQ ...\n");
401 enable_irq(g_linux_wlan->dev_irq_num);
406 void linux_wlan_disable_irq(int wait)
408 #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
410 PRINT_D(INT_DBG, "Disabling IRQ ...\n");
411 disable_irq(g_linux_wlan->dev_irq_num);
413 PRINT_D(INT_DBG, "Disabling IRQ ...\n");
414 disable_irq_nosync(g_linux_wlan->dev_irq_num);
419 #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
420 static irqreturn_t isr_uh_routine(int irq, void *user_data)
425 #if (RX_BH_TYPE != RX_BH_THREADED_IRQ)
426 linux_wlan_disable_irq(IRQ_NO_WAIT);
428 PRINT_D(INT_DBG, "Interrupt received UH\n");
430 /*While mac is closing cacncel the handling of any interrupts received*/
431 if (g_linux_wlan->close) {
432 PRINT_ER("Driver is CLOSING: Can't handle UH interrupt\n");
433 #if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
440 #if (RX_BH_TYPE == RX_BH_WORK_QUEUE)
441 schedule_work(&g_linux_wlan->rx_work_queue);
443 #elif (RX_BH_TYPE == RX_BH_KTHREAD)
444 linux_wlan_unlock(&g_linux_wlan->rx_sem);
446 #elif (RX_BH_TYPE == RX_BH_THREADED_IRQ)
447 return IRQ_WAKE_THREAD;
453 #if (RX_BH_TYPE == RX_BH_WORK_QUEUE || RX_BH_TYPE == RX_BH_THREADED_IRQ)
455 #if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
456 irqreturn_t isr_bh_routine(int irq, void *userdata)
459 nic = (linux_wlan_t *)userdata;
461 static void isr_bh_routine(struct work_struct *work)
463 perInterface_wlan_t *nic;
464 nic = (perInterface_wlan_t *)container_of(work, linux_wlan_t, rx_work_queue);
467 /*While mac is closing cacncel the handling of any interrupts received*/
468 if (g_linux_wlan->close) {
469 PRINT_ER("Driver is CLOSING: Can't handle BH interrupt\n");
470 #if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
481 PRINT_D(INT_DBG, "Interrupt received BH\n");
482 if (g_linux_wlan->oup.wlan_handle_rx_isr != 0) {
483 g_linux_wlan->oup.wlan_handle_rx_isr();
485 PRINT_ER("wlan_handle_rx_isr() hasn't been initialized\n");
489 #if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
493 #elif (RX_BH_TYPE == RX_BH_KTHREAD)
494 static int isr_bh_routine(void *vp)
498 nic = (linux_wlan_t *)vp;
501 linux_wlan_lock(&nic->rx_sem);
502 if (g_linux_wlan->close) {
504 while (!kthread_should_stop())
510 PRINT_D(INT_DBG, "Interrupt received BH\n");
511 if (g_linux_wlan->oup.wlan_handle_rx_isr != 0) {
512 g_linux_wlan->oup.wlan_handle_rx_isr();
514 PRINT_ER("wlan_handle_rx_isr() hasn't been initialized\n");
523 #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
524 static int init_irq(linux_wlan_t *p_nic)
527 linux_wlan_t *nic = p_nic;
529 /*initialize GPIO and register IRQ num*/
531 if ((gpio_request(GPIO_NUM, "WILC_INTR") == 0) &&
532 (gpio_direction_input(GPIO_NUM) == 0)) {
533 #if defined(CUSTOMER_PLATFORM)
535 TODO : save the registerd irq number to the private wilc context in kernel.
537 * ex) nic->dev_irq_num = gpio_to_irq(GPIO_NUM);
539 #elif defined (NM73131_0_BOARD)
540 nic->dev_irq_num = IRQ_WILC1000;
541 #elif defined (PANDA_BOARD)
542 gpio_export(GPIO_NUM, 1);
543 nic->dev_irq_num = OMAP_GPIO_IRQ(GPIO_NUM);
544 irq_set_irq_type(nic->dev_irq_num, IRQ_TYPE_LEVEL_LOW);
546 nic->dev_irq_num = gpio_to_irq(GPIO_NUM);
550 PRINT_ER("could not obtain gpio for WILC_INTR\n");
554 #if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
555 if ((ret != -1) && (request_threaded_irq(nic->dev_irq_num, isr_uh_routine, isr_bh_routine,
556 IRQF_TRIGGER_LOW | IRQF_ONESHOT, /*Without IRQF_ONESHOT the uh will remain kicked in and dont gave a chance to bh*/
557 "WILC_IRQ", nic)) < 0) {
561 if ((ret != -1) && (request_irq(nic->dev_irq_num, isr_uh_routine,
562 IRQF_TRIGGER_LOW, "WILC_IRQ", nic) < 0)) {
565 PRINT_ER("Failed to request IRQ for GPIO: %d\n", GPIO_NUM);
569 PRINT_D(INIT_DBG, "IRQ request succeeded IRQ-NUM= %d on GPIO: %d\n",
570 nic->dev_irq_num, GPIO_NUM);
577 static void deinit_irq(linux_wlan_t *nic)
579 #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
580 /* Deintialize IRQ */
581 if (&nic->dev_irq_num != 0) {
582 free_irq(nic->dev_irq_num, g_linux_wlan);
593 static void linux_wlan_msleep(uint32_t msc)
595 if (msc <= 4000000) {
596 WILC_Uint32 u32Temp = msc * 1000;
597 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 35)
598 usleep_range(u32Temp, u32Temp);
600 /* This is delay not sleep !!!, has to be changed*/
608 static void linux_wlan_atomic_msleep(uint32_t msc)
612 static void linux_wlan_dbg(uint8_t *buff)
614 PRINT_D(INIT_DBG, "%d\n", *buff);
617 static void *linux_wlan_malloc_atomic(uint32_t sz)
620 pntr = (char *)kmalloc(sz, GFP_ATOMIC);
621 PRINT_D(MEM_DBG, "Allocating %d bytes at address %p\n", sz, pntr);
625 static void *linux_wlan_malloc(uint32_t sz)
628 pntr = (char *)kmalloc(sz, GFP_KERNEL);
629 PRINT_D(MEM_DBG, "Allocating %d bytes at address %p\n", sz, pntr);
633 void linux_wlan_free(void *vp)
636 PRINT_D(MEM_DBG, "Freeing %p\n", vp);
642 static void *internal_alloc(uint32_t size, uint32_t flag)
645 pntr = (char *)kmalloc(size, flag);
646 PRINT_D(MEM_DBG, "Allocating %d bytes at address %p\n", size, pntr);
651 static void linux_wlan_init_lock(char *lockName, void *plock, int count)
653 sema_init((struct semaphore *)plock, count);
654 PRINT_D(LOCK_DBG, "Initializing [%s][%p]\n", lockName, plock);
658 static void linux_wlan_deinit_lock(void *plock)
660 /* mutex_destroy((struct mutex*)plock); */
663 static void linux_wlan_lock(void *vp)
665 PRINT_D(LOCK_DBG, "Locking %p\n", vp);
667 while (down_interruptible((struct semaphore *) vp))
670 PRINT_ER("Failed, mutex is NULL\n");
674 static int linux_wlan_lock_timeout(void *vp, WILC_Uint32 timeout)
677 PRINT_D(LOCK_DBG, "Locking %p\n", vp);
679 error = down_timeout((struct semaphore *)vp, msecs_to_jiffies(timeout));
681 PRINT_ER("Failed, mutex is NULL\n");
686 void linux_wlan_unlock(void *vp)
688 PRINT_D(LOCK_DBG, "Unlocking %p\n", vp);
690 up((struct semaphore *)vp);
692 PRINT_ER("Failed, mutex is NULL\n");
697 static void linux_wlan_init_mutex(char *lockName, void *plock, int count)
699 mutex_init((struct mutex *)plock);
700 PRINT_D(LOCK_DBG, "Initializing mutex [%s][%p]\n", lockName, plock);
704 static void linux_wlan_deinit_mutex(void *plock)
706 mutex_destroy((struct mutex *)plock);
709 static void linux_wlan_lock_mutex(void *vp)
711 PRINT_D(LOCK_DBG, "Locking mutex %p\n", vp);
714 * if(mutex_is_locked((struct mutex*)vp))
716 * //PRINT_ER("Mutex already locked - %p \n",vp);
719 mutex_lock((struct mutex *)vp);
722 PRINT_ER("Failed, mutex is NULL\n");
726 static void linux_wlan_unlock_mutex(void *vp)
728 PRINT_D(LOCK_DBG, "Unlocking mutex %p\n", vp);
731 if (mutex_is_locked((struct mutex *)vp)) {
732 mutex_unlock((struct mutex *)vp);
734 /* PRINT_ER("Mutex already unlocked - %p\n",vp); */
738 PRINT_ER("Failed, mutex is NULL\n");
743 /*Added by Amr - BugID_4720*/
744 static void linux_wlan_init_spin_lock(char *lockName, void *plock, int count)
746 spin_lock_init((spinlock_t *)plock);
747 PRINT_D(SPIN_DEBUG, "Initializing mutex [%s][%p]\n", lockName, plock);
751 static void linux_wlan_deinit_spin_lock(void *plock)
755 static void linux_wlan_spin_lock(void *vp, unsigned long *flags)
757 unsigned long lflags;
758 PRINT_D(SPIN_DEBUG, "Lock spin %p\n", vp);
760 spin_lock_irqsave((spinlock_t *)vp, lflags);
763 PRINT_ER("Failed, spin lock is NULL\n");
766 static void linux_wlan_spin_unlock(void *vp, unsigned long *flags)
768 unsigned long lflags = *flags;
769 PRINT_D(SPIN_DEBUG, "Unlock spin %p\n", vp);
771 spin_unlock_irqrestore((spinlock_t *)vp, lflags);
774 PRINT_ER("Failed, spin lock is NULL\n");
778 static void linux_wlan_mac_indicate(int flag)
780 /*I have to do it that way becuase there is no mean to encapsulate device pointer
783 linux_wlan_t *pd = g_linux_wlan;
786 if (flag == WILC_MAC_INDICATE_STATUS) {
787 pd->oup.wlan_cfg_get_value(WID_STATUS, (unsigned char *)&status, 4);
788 if (pd->mac_status == WILC_MAC_STATUS_INIT) {
789 pd->mac_status = status;
790 linux_wlan_unlock(&pd->sync_event);
792 pd->mac_status = status;
795 if (pd->mac_status == WILC_MAC_STATUS_CONNECT) { /* Connect */
798 * get the mac and bssid address
800 PRINT_D(RX_DBG, "Calling cfg_get to get MAC_ADDR\n");
801 pd->oup.wlan_cfg_get(1, WID_MAC_ADDR, 0);
802 PRINT_D(RX_DBG, "Calling cfg_get to get BSSID\n");
803 pd->oup.wlan_cfg_get(0, WID_BSSID, 1);
808 pd->oup.wlan_cfg_get_value(WID_MAC_ADDR, pd->eth_src_address, 6);
809 pd->oup.wlan_cfg_get_value(WID_BSSID, pd->eth_dst_address, 6);
811 PRINT_D(GENERIC_DBG, "Source Address = %s", pd->eth_src_address);
812 PRINT_D(GENERIC_DBG, "Destiation Address = %s", pd->eth_dst_address);
820 } else if (flag == WILC_MAC_INDICATE_SCAN) {
821 PRINT_D(GENERIC_DBG, "Scanning ...\n");
827 struct net_device *GetIfHandler(uint8_t *pMacHeader)
829 uint8_t *Bssid, *Bssid1;
832 Bssid = pMacHeader + 10;
833 Bssid1 = pMacHeader + 4;
835 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
836 if (!memcmp(Bssid1, g_linux_wlan->strInterfaceInfo[i].aBSSID, ETH_ALEN) ||
837 !memcmp(Bssid, g_linux_wlan->strInterfaceInfo[i].aBSSID, ETH_ALEN)) {
838 return g_linux_wlan->strInterfaceInfo[i].wilc_netdev;
841 PRINT_INFO(INIT_DBG, "Invalide handle\n");
842 for (i = 0; i < 25; i++) {
843 PRINT_D(INIT_DBG, "%02x ", pMacHeader[i]);
845 Bssid = pMacHeader + 18;
846 Bssid1 = pMacHeader + 12;
847 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
848 if (!memcmp(Bssid1, g_linux_wlan->strInterfaceInfo[i].aBSSID, ETH_ALEN) ||
849 !memcmp(Bssid, g_linux_wlan->strInterfaceInfo[i].aBSSID, ETH_ALEN)) {
850 PRINT_D(INIT_DBG, "Ctx [%p]\n", g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
851 return g_linux_wlan->strInterfaceInfo[i].wilc_netdev;
854 PRINT_INFO(INIT_DBG, "\n");
858 int linux_wlan_set_bssid(struct net_device *wilc_netdev, uint8_t *pBSSID)
863 PRINT_D(INIT_DBG, "set bssid on[%p]\n", wilc_netdev);
864 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
865 if (g_linux_wlan->strInterfaceInfo[i].wilc_netdev == wilc_netdev) {
866 PRINT_D(INIT_DBG, "set bssid [%x][%x][%x]\n", pBSSID[0], pBSSID[1], pBSSID[2]);
867 memcpy(g_linux_wlan->strInterfaceInfo[i].aBSSID, pBSSID, 6);
876 /*Function to get number of connected interfaces*/
877 int linux_wlan_get_num_conn_ifcs(void)
880 uint8_t null_bssid[6] = {0};
883 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
884 if (memcmp(g_linux_wlan->strInterfaceInfo[i].aBSSID, null_bssid, 6)) {
891 static int linux_wlan_rxq_task(void *vp)
894 /* inform wilc1000_wlan_init that RXQ task is started. */
895 linux_wlan_unlock(&g_linux_wlan->rxq_thread_started);
897 linux_wlan_lock(&g_linux_wlan->rxq_event);
898 /* wait_for_completion(&g_linux_wlan->rxq_event); */
900 if (g_linux_wlan->close) {
901 /*Unlock the mutex in the mac_close function to indicate the exiting of the RX thread */
902 linux_wlan_unlock(&g_linux_wlan->rxq_thread_started);
904 while (!kthread_should_stop())
907 PRINT_D(RX_DBG, " RX thread stopped\n");
910 PRINT_D(RX_DBG, "Calling wlan_handle_rx_que()\n");
912 g_linux_wlan->oup.wlan_handle_rx_que();
917 #define USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
919 static int linux_wlan_txq_task(void *vp)
923 #if defined USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
924 #define TX_BACKOFF_WEIGHT_INCR_STEP (1)
925 #define TX_BACKOFF_WEIGHT_DECR_STEP (1)
926 #define TX_BACKOFF_WEIGHT_MAX (7)
927 #define TX_BACKOFF_WEIGHT_MIN (0)
928 #define TX_BACKOFF_WEIGHT_UNIT_MS (10)
929 int backoff_weight = TX_BACKOFF_WEIGHT_MIN;
933 /* inform wilc1000_wlan_init that TXQ task is started. */
934 linux_wlan_unlock(&g_linux_wlan->txq_thread_started);
937 PRINT_D(TX_DBG, "txq_task Taking a nap :)\n");
938 linux_wlan_lock(&g_linux_wlan->txq_event);
939 /* wait_for_completion(&pd->txq_event); */
940 PRINT_D(TX_DBG, "txq_task Who waked me up :$\n");
942 if (g_linux_wlan->close) {
943 /*Unlock the mutex in the mac_close function to indicate the exiting of the TX thread */
944 linux_wlan_unlock(&g_linux_wlan->txq_thread_started);
946 while (!kthread_should_stop())
949 PRINT_D(TX_DBG, "TX thread stopped\n");
952 PRINT_D(TX_DBG, "txq_task handle the sending packet and let me go to sleep.\n");
953 #if !defined USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
954 g_linux_wlan->oup.wlan_handle_tx_que();
957 ret = g_linux_wlan->oup.wlan_handle_tx_que(&txq_count);
958 if (txq_count < FLOW_CONTROL_LOWER_THRESHOLD /* && netif_queue_stopped(pd->wilc_netdev)*/) {
959 PRINT_D(TX_DBG, "Waking up queue\n");
960 /* netif_wake_queue(pd->wilc_netdev); */
961 if (netif_queue_stopped(g_linux_wlan->strInterfaceInfo[0].wilc_netdev))
962 netif_wake_queue(g_linux_wlan->strInterfaceInfo[0].wilc_netdev);
963 if (netif_queue_stopped(g_linux_wlan->strInterfaceInfo[1].wilc_netdev))
964 netif_wake_queue(g_linux_wlan->strInterfaceInfo[1].wilc_netdev);
967 if (ret == WILC_TX_ERR_NO_BUF) { /* failed to allocate buffers in chip. */
968 timeout = msecs_to_jiffies(TX_BACKOFF_WEIGHT_UNIT_MS << backoff_weight);
970 /* Back off from sending packets for some time. */
971 /* schedule_timeout will allow RX task to run and free buffers.*/
972 /* set_current_state(TASK_UNINTERRUPTIBLE); */
973 /* timeout = schedule_timeout(timeout); */
974 msleep(TX_BACKOFF_WEIGHT_UNIT_MS << backoff_weight);
975 } while (/*timeout*/ 0);
976 backoff_weight += TX_BACKOFF_WEIGHT_INCR_STEP;
977 if (backoff_weight > TX_BACKOFF_WEIGHT_MAX) {
978 backoff_weight = TX_BACKOFF_WEIGHT_MAX;
981 if (backoff_weight > TX_BACKOFF_WEIGHT_MIN) {
982 backoff_weight -= TX_BACKOFF_WEIGHT_DECR_STEP;
983 if (backoff_weight < TX_BACKOFF_WEIGHT_MIN) {
984 backoff_weight = TX_BACKOFF_WEIGHT_MIN;
988 /*TODO: drop packets after a certain time/number of retry count. */
989 } while (ret == WILC_TX_ERR_NO_BUF && !g_linux_wlan->close); /* retry sending packets if no more buffers in chip. */
995 static void linux_wlan_rx_complete(void)
997 PRINT_D(RX_DBG, "RX completed\n");
1000 int linux_wlan_get_firmware(perInterface_wlan_t *p_nic)
1003 perInterface_wlan_t *nic = p_nic;
1005 const struct firmware *wilc_firmware;
1009 if (nic->iftype == AP_MODE)
1010 firmware = AP_FIRMWARE;
1011 else if (nic->iftype == STATION_MODE)
1012 firmware = STA_FIRMWARE;
1016 PRINT_D(INIT_DBG, "Get P2P_CONCURRENCY_FIRMWARE\n");
1017 firmware = P2P_CONCURRENCY_FIRMWARE;
1023 PRINT_ER("NIC is NULL\n");
1027 if (&nic->wilc_netdev->dev == NULL) {
1028 PRINT_ER("&nic->wilc_netdev->dev is NULL\n");
1033 /* the firmare should be located in /lib/firmware in
1034 * root file system with the name specified above */
1037 if (request_firmware(&wilc_firmware, firmware, &g_linux_wlan->wilc_sdio_func->dev) != 0) {
1038 PRINT_ER("%s - firmare not available\n", firmware);
1043 if (request_firmware(&wilc_firmware, firmware, &g_linux_wlan->wilc_spidev->dev) != 0) {
1044 PRINT_ER("%s - firmare not available\n", firmware);
1049 g_linux_wlan->wilc_firmware = wilc_firmware; /* Bug 4703 */
1057 #ifdef COMPLEMENT_BOOT
1058 int repeat_power_cycle(perInterface_wlan_t *nic);
1061 static int linux_wlan_start_firmware(perInterface_wlan_t *nic)
1064 static int timeout = 5;
1066 /* start firmware */
1067 PRINT_D(INIT_DBG, "Starting Firmware ...\n");
1068 ret = g_linux_wlan->oup.wlan_start();
1070 PRINT_ER("Failed to start Firmware\n");
1074 /* wait for mac ready */
1075 PRINT_D(INIT_DBG, "Waiting for Firmware to get ready ...\n");
1076 ret = linux_wlan_lock_timeout(&g_linux_wlan->sync_event, 5000);
1078 #ifdef COMPLEMENT_BOOT
1081 PRINT_D(INIT_DBG, "repeat power cycle[%d]", timeout);
1082 ret = repeat_power_cycle(nic);
1089 PRINT_D(INIT_DBG, "Firmware start timed out");
1093 * TODO: Driver shouoldn't wait forever for firmware to get started -
1094 * in case of timeout this should be handled properly
1096 PRINT_D(INIT_DBG, "Firmware successfully started\n");
1101 static int linux_wlan_firmware_download(linux_wlan_t *p_nic)
1106 if (g_linux_wlan->wilc_firmware == NULL) {
1107 PRINT_ER("Firmware buffer is NULL\n");
1112 * do the firmware download
1114 PRINT_D(INIT_DBG, "Downloading Firmware ...\n");
1115 ret = g_linux_wlan->oup.wlan_firmware_download(g_linux_wlan->wilc_firmware->data, g_linux_wlan->wilc_firmware->size);
1120 /* Freeing FW buffer */
1121 PRINT_D(INIT_DBG, "Freeing FW buffer ...\n");
1122 PRINT_D(INIT_DBG, "Releasing firmware\n");
1123 release_firmware(g_linux_wlan->wilc_firmware);
1124 g_linux_wlan->wilc_firmware = NULL;
1126 PRINT_D(INIT_DBG, "Download Succeeded \n");
1133 /* startup configuration - could be changed later using iconfig*/
1134 static int linux_wlan_init_test_config(struct net_device *dev, linux_wlan_t *p_nic)
1137 unsigned char c_val[64];
1138 #ifndef STATIC_MACADDRESS
1139 unsigned char mac_add[] = {0x00, 0x80, 0xC2, 0x5E, 0xa2, 0xff};
1141 unsigned int chipid = 0;
1144 struct WILC_WFI_priv *priv;
1145 tstrWILC_WFIDrv *pstrWFIDrv;
1147 PRINT_D(TX_DBG, "Start configuring Firmware\n");
1148 #ifndef STATIC_MACADDRESS
1149 get_random_bytes(&mac_add[5], 1);
1150 get_random_bytes(&mac_add[4], 1);
1152 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
1153 pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
1154 PRINT_D(INIT_DBG, "Host = %x\n", (WILC_Uint32)pstrWFIDrv);
1156 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]);
1157 chipid = wilc_get_chipid(0);
1160 if (g_linux_wlan->oup.wlan_cfg_set == NULL) {
1161 PRINT_D(INIT_DBG, "Null p[ointer\n");
1165 *(int *)c_val = (WILC_Uint32)pstrWFIDrv;
1167 if (!g_linux_wlan->oup.wlan_cfg_set(1, WID_SET_DRV_HANDLER, c_val, 4, 0, 0))
1170 /*to tell fw that we are going to use PC test - WILC specific*/
1172 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_PC_TEST_MODE, c_val, 1, 0, 0))
1175 c_val[0] = INFRASTRUCTURE;
1176 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_BSS_TYPE, c_val, 1, 0, 0))
1180 /* c_val[0] = RATE_AUTO; / * bug 4275: Enable autorate and limit it to 24Mbps * / */
1181 c_val[0] = RATE_AUTO;
1182 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_CURRENT_TX_RATE, c_val, 1, 0, 0))
1185 c_val[0] = G_MIXED_11B_2_MODE;
1186 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11G_OPERATING_MODE, c_val, 1, 0, 0))
1190 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_CURRENT_CHANNEL, c_val, 1, 0, 0))
1193 c_val[0] = G_SHORT_PREAMBLE;
1194 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_PREAMBLE, c_val, 1, 0, 0))
1197 c_val[0] = AUTO_PROT;
1198 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_PROT_MECH, c_val, 1, 0, 0))
1201 #ifdef SWITCH_LOG_TERMINAL
1202 c_val[0] = AUTO_PROT;
1203 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_LOGTerminal_Switch, c_val, 1, 0, 0))
1207 c_val[0] = ACTIVE_SCAN;
1208 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_SCAN_TYPE, c_val, 1, 0, 0))
1211 c_val[0] = SITE_SURVEY_OFF;
1212 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_SITE_SURVEY, c_val, 1, 0, 0))
1215 *((int *)c_val) = 0xffff; /* Never use RTS-CTS */
1216 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_RTS_THRESHOLD, c_val, 2, 0, 0))
1219 *((int *)c_val) = 2346;
1220 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_FRAG_THRESHOLD, c_val, 2, 0, 0))
1224 /* -------------------------------------------------------------- */
1225 /* Configuration : String with length less than 32 bytes */
1226 /* Values to set : Any string with length less than 32 bytes */
1227 /* ( In BSS Station Set SSID to "" (null string) */
1228 /* to enable Broadcast SSID suppport ) */
1229 /* -------------------------------------------------------------- */
1230 #ifndef USE_WIRELESS
1231 strcpy(c_val, "nwifi");
1232 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_SSID, c_val, (strlen(c_val) + 1), 0, 0))
1237 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_BCAST_SSID, c_val, 1, 0, 0))
1241 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_QOS_ENABLE, c_val, 1, 0, 0))
1244 c_val[0] = NO_POWERSAVE;
1245 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_POWER_MANAGEMENT, c_val, 1, 0, 0))
1248 c_val[0] = NO_ENCRYPT; /* NO_ENCRYPT, 0x79 */
1249 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11I_MODE, c_val, 1, 0, 0))
1252 c_val[0] = OPEN_SYSTEM;
1253 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_AUTH_TYPE, c_val, 1, 0, 0))
1256 /* WEP/802 11I Configuration */
1257 /* ------------------------------------------------------------------ */
1258 /* Configuration : WEP Key */
1259 /* Values (0x) : 5 byte for WEP40 and 13 bytes for WEP104 */
1260 /* In case more than 5 bytes are passed on for WEP 40 */
1261 /* only first 5 bytes will be used as the key */
1262 /* ------------------------------------------------------------------ */
1264 strcpy(c_val, "123456790abcdef1234567890");
1265 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_WEP_KEY_VALUE, c_val, (strlen(c_val) + 1), 0, 0))
1268 /* WEP/802 11I Configuration */
1269 /* ------------------------------------------------------------------ */
1270 /* Configuration : AES/TKIP WPA/RSNA Pre-Shared Key */
1271 /* Values to set : Any string with length greater than equal to 8 bytes */
1272 /* and less than 64 bytes */
1273 /* ------------------------------------------------------------------ */
1274 strcpy(c_val, "12345678");
1275 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11I_PSK, c_val, (strlen(c_val)), 0, 0))
1278 /* IEEE802.1X Key Configuration */
1279 /* ------------------------------------------------------------------ */
1280 /* Configuration : Radius Server Access Secret Key */
1281 /* Values to set : Any string with length greater than equal to 8 bytes */
1282 /* and less than 65 bytes */
1283 /* ------------------------------------------------------------------ */
1284 strcpy(c_val, "password");
1285 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_1X_KEY, c_val, (strlen(c_val) + 1), 0, 0))
1288 /* IEEE802.1X Server Address Configuration */
1289 /* ------------------------------------------------------------------ */
1290 /* Configuration : Radius Server IP Address */
1291 /* Values to set : Any valid IP Address */
1292 /* ------------------------------------------------------------------ */
1297 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_1X_SERV_ADDR, c_val, 4, 0, 0))
1301 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_LISTEN_INTERVAL, c_val, 1, 0, 0))
1305 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_DTIM_PERIOD, c_val, 1, 0, 0))
1308 c_val[0] = NORMAL_ACK;
1309 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_ACK_POLICY, c_val, 1, 0, 0))
1313 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_USER_CONTROL_ON_TX_POWER, c_val, 1, 0, 0))
1317 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_TX_POWER_LEVEL_11A, c_val, 1, 0, 0))
1321 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_TX_POWER_LEVEL_11B, c_val, 1, 0, 0))
1324 /* Beacon Interval */
1325 /* -------------------------------------------------------------------- */
1326 /* Configuration : Sets the beacon interval value */
1327 /* Values to set : Any 16-bit value */
1328 /* -------------------------------------------------------------------- */
1330 *((int *)c_val) = 100;
1331 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_BEACON_INTERVAL, c_val, 2, 0, 0))
1334 c_val[0] = REKEY_DISABLE;
1335 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_REKEY_POLICY, c_val, 1, 0, 0))
1338 /* Rekey Time (s) (Used only when the Rekey policy is 2 or 4) */
1339 /* -------------------------------------------------------------------- */
1340 /* Configuration : Sets the Rekey Time (s) */
1341 /* Values to set : 32-bit value */
1342 /* -------------------------------------------------------------------- */
1343 *((int *)c_val) = 84600;
1344 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_REKEY_PERIOD, c_val, 4, 0, 0))
1347 /* Rekey Packet Count (in 1000s; used when Rekey Policy is 3) */
1348 /* -------------------------------------------------------------------- */
1349 /* Configuration : Sets Rekey Group Packet count */
1350 /* Values to set : 32-bit Value */
1351 /* -------------------------------------------------------------------- */
1352 *((int *)c_val) = 500;
1353 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_REKEY_PACKET_COUNT, c_val, 4, 0, 0))
1357 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_SHORT_SLOT_ALLOWED, c_val, 1, 0, 0))
1360 c_val[0] = G_SELF_CTS_PROT;
1361 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_ERP_PROT_TYPE, c_val, 1, 0, 0))
1364 c_val[0] = 1; /* Enable N */
1365 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_ENABLE, c_val, 1, 0, 0))
1368 c_val[0] = HT_MIXED_MODE;
1369 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_OPERATING_MODE, c_val, 1, 0, 0))
1372 c_val[0] = 1; /* TXOP Prot disable in N mode: No RTS-CTS on TX A-MPDUs to save air-time. */
1373 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_TXOP_PROT_DISABLE, c_val, 1, 0, 0))
1376 memcpy(c_val, mac_add, 6);
1378 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_MAC_ADDR, c_val, 6, 0, 0))
1384 c_val[0] = DETECT_PROTECT_REPORT;
1385 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_OBSS_NONHT_DETECTION, c_val, 1, 0, 0))
1388 c_val[0] = RTS_CTS_NONHT_PROT;
1389 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_HT_PROT_TYPE, c_val, 1, 0, 0))
1393 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_RIFS_PROT_ENABLE, c_val, 1, 0, 0))
1396 c_val[0] = MIMO_MODE;
1397 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_SMPS_MODE, c_val, 1, 0, 0))
1401 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_CURRENT_TX_MCS, c_val, 1, 0, 0))
1404 c_val[0] = 1; /* Enable N with immediate block ack. */
1405 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_IMMEDIATE_BA_ENABLED, c_val, 1, 1, (WILC_Uint32)pstrWFIDrv))
1415 /**************************/
1416 void wilc1000_wlan_deinit(linux_wlan_t *nic)
1419 if (g_linux_wlan->wilc1000_initialized) {
1421 printk("Deinitializing wilc1000 ...\n");
1424 PRINT_ER("nic is NULL\n");
1428 #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
1429 /* johnny : remove */
1430 PRINT_D(INIT_DBG, "skip wilc_bus_set_default_speed\n");
1432 wilc_bus_set_default_speed();
1435 PRINT_D(INIT_DBG, "Disabling IRQ\n");
1436 #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
1437 linux_wlan_disable_irq(IRQ_WAIT);
1439 #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
1442 linux_wlan_lock_mutex((void *)&g_linux_wlan->hif_cs);
1443 disable_sdio_interrupt();
1444 linux_wlan_unlock_mutex((void *)&g_linux_wlan->hif_cs);
1449 /* not sure if the following unlocks are needed or not*/
1450 if (&g_linux_wlan->rxq_event != NULL) {
1451 linux_wlan_unlock(&g_linux_wlan->rxq_event);
1454 if (&g_linux_wlan->txq_event != NULL) {
1455 linux_wlan_unlock(&g_linux_wlan->txq_event);
1459 #if (RX_BH_TYPE == RX_BH_WORK_QUEUE)
1460 /*Removing the work struct from the linux kernel workqueue*/
1461 if (&g_linux_wlan->rx_work_queue != NULL)
1462 flush_work(&g_linux_wlan->rx_work_queue);
1464 #elif (RX_BH_TYPE == RX_BH_KTHREAD)
1465 /* if(&nic->rx_sem != NULL) */
1466 /* linux_wlan_unlock(&nic->rx_sem); */
1469 PRINT_D(INIT_DBG, "Deinitializing Threads\n");
1470 wlan_deinitialize_threads(nic);
1472 PRINT_D(INIT_DBG, "Deinitializing IRQ\n");
1473 deinit_irq(g_linux_wlan);
1476 if (&g_linux_wlan->oup != NULL) {
1477 if (g_linux_wlan->oup.wlan_stop != NULL)
1478 g_linux_wlan->oup.wlan_stop();
1481 PRINT_D(INIT_DBG, "Deinitializing WILC Wlan\n");
1482 wilc_wlan_deinit(nic);
1483 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
1484 #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
1485 PRINT_D(INIT_DBG, "Disabling IRQ 2\n");
1487 linux_wlan_lock_mutex((void *)&g_linux_wlan->hif_cs);
1488 disable_sdio_interrupt();
1489 linux_wlan_unlock_mutex((void *)&g_linux_wlan->hif_cs);
1493 /*De-Initialize locks*/
1494 PRINT_D(INIT_DBG, "Deinitializing Locks\n");
1495 wlan_deinit_locks(g_linux_wlan);
1497 /* announce that wilc1000 is not initialized */
1498 g_linux_wlan->wilc1000_initialized = 0;
1500 PRINT_D(INIT_DBG, "wilc1000 deinitialization Done\n");
1503 PRINT_D(INIT_DBG, "wilc1000 is not initialized\n");
1508 int wlan_init_locks(linux_wlan_t *p_nic)
1511 PRINT_D(INIT_DBG, "Initializing Locks ...\n");
1513 /*initialize mutexes*/
1514 linux_wlan_init_mutex("hif_lock/hif_cs", &g_linux_wlan->hif_cs, 1);
1515 linux_wlan_init_mutex("rxq_lock/rxq_cs", &g_linux_wlan->rxq_cs, 1);
1516 linux_wlan_init_mutex("txq_lock/txq_cs", &g_linux_wlan->txq_cs, 1);
1518 /*Added by Amr - BugID_4720*/
1519 linux_wlan_init_spin_lock("txq_spin_lock/txq_cs", &g_linux_wlan->txq_spinlock, 1);
1521 /*Added by Amr - BugID_4720*/
1522 linux_wlan_init_lock("txq_add_to_head_lock/txq_cs", &g_linux_wlan->txq_add_to_head_cs, 1);
1524 linux_wlan_init_lock("txq_wait/txq_event", &g_linux_wlan->txq_event, 0);
1525 linux_wlan_init_lock("rxq_wait/rxq_event", &g_linux_wlan->rxq_event, 0);
1527 linux_wlan_init_lock("cfg_wait/cfg_event", &g_linux_wlan->cfg_event, 0);
1528 linux_wlan_init_lock("sync_event", &g_linux_wlan->sync_event, 0);
1530 linux_wlan_init_lock("rxq_lock/rxq_started", &g_linux_wlan->rxq_thread_started, 0);
1531 linux_wlan_init_lock("rxq_lock/txq_started", &g_linux_wlan->txq_thread_started, 0);
1533 #if (RX_BH_TYPE == RX_BH_KTHREAD)
1534 linux_wlan_init_lock("BH_SEM", &g_linux_wlan->rx_sem, 0);
1540 static int wlan_deinit_locks(linux_wlan_t *nic)
1542 PRINT_D(INIT_DBG, "De-Initializing Locks\n");
1544 if (&g_linux_wlan->hif_cs != NULL)
1545 linux_wlan_deinit_mutex(&g_linux_wlan->hif_cs);
1547 if (&g_linux_wlan->rxq_cs != NULL)
1548 linux_wlan_deinit_mutex(&g_linux_wlan->rxq_cs);
1550 if (&g_linux_wlan->txq_cs != NULL)
1551 linux_wlan_deinit_mutex(&g_linux_wlan->txq_cs);
1553 /*Added by Amr - BugID_4720*/
1554 if (&g_linux_wlan->txq_spinlock != NULL)
1555 linux_wlan_deinit_spin_lock(&g_linux_wlan->txq_spinlock);
1557 if (&g_linux_wlan->rxq_event != NULL)
1558 linux_wlan_deinit_lock(&g_linux_wlan->rxq_event);
1560 if (&g_linux_wlan->txq_event != NULL)
1561 linux_wlan_deinit_lock(&g_linux_wlan->txq_event);
1563 /*Added by Amr - BugID_4720*/
1564 if (&g_linux_wlan->txq_add_to_head_cs != NULL)
1565 linux_wlan_deinit_lock(&g_linux_wlan->txq_add_to_head_cs);
1567 if (&g_linux_wlan->rxq_thread_started != NULL)
1568 linux_wlan_deinit_lock(&g_linux_wlan->rxq_thread_started);
1570 if (&g_linux_wlan->txq_thread_started != NULL)
1571 linux_wlan_deinit_lock(&g_linux_wlan->txq_thread_started);
1573 if (&g_linux_wlan->cfg_event != NULL)
1574 linux_wlan_deinit_lock(&g_linux_wlan->cfg_event);
1576 if (&g_linux_wlan->sync_event != NULL)
1577 linux_wlan_deinit_lock(&g_linux_wlan->sync_event);
1581 void linux_to_wlan(wilc_wlan_inp_t *nwi, linux_wlan_t *nic)
1584 PRINT_D(INIT_DBG, "Linux to Wlan services ...\n");
1586 nwi->os_context.hif_critical_section = (void *)&g_linux_wlan->hif_cs;
1587 nwi->os_context.os_private = (void *)nic;
1588 nwi->os_context.tx_buffer_size = LINUX_TX_SIZE;
1589 nwi->os_context.txq_critical_section = (void *)&g_linux_wlan->txq_cs;
1591 /*Added by Amr - BugID_4720*/
1592 nwi->os_context.txq_add_to_head_critical_section = (void *)&g_linux_wlan->txq_add_to_head_cs;
1594 /*Added by Amr - BugID_4720*/
1595 nwi->os_context.txq_spin_lock = (void *)&g_linux_wlan->txq_spinlock;
1597 nwi->os_context.txq_wait_event = (void *)&g_linux_wlan->txq_event;
1599 #if defined (MEMORY_STATIC)
1600 nwi->os_context.rx_buffer_size = LINUX_RX_SIZE;
1602 nwi->os_context.rxq_critical_section = (void *)&g_linux_wlan->rxq_cs;
1603 nwi->os_context.rxq_wait_event = (void *)&g_linux_wlan->rxq_event;
1604 nwi->os_context.cfg_wait_event = (void *)&g_linux_wlan->cfg_event;
1606 nwi->os_func.os_sleep = linux_wlan_msleep;
1607 nwi->os_func.os_atomic_sleep = linux_wlan_atomic_msleep;
1608 nwi->os_func.os_debug = linux_wlan_dbg;
1609 nwi->os_func.os_malloc = linux_wlan_malloc;
1610 nwi->os_func.os_malloc_atomic = linux_wlan_malloc_atomic;
1611 nwi->os_func.os_free = linux_wlan_free;
1612 nwi->os_func.os_lock = linux_wlan_lock;
1613 nwi->os_func.os_unlock = linux_wlan_unlock;
1614 nwi->os_func.os_wait = linux_wlan_lock_timeout;
1615 nwi->os_func.os_signal = linux_wlan_unlock;
1616 nwi->os_func.os_enter_cs = linux_wlan_lock_mutex;
1617 nwi->os_func.os_leave_cs = linux_wlan_unlock_mutex;
1619 /*Added by Amr - BugID_4720*/
1620 nwi->os_func.os_spin_lock = linux_wlan_spin_lock;
1621 nwi->os_func.os_spin_unlock = linux_wlan_spin_unlock;
1624 nwi->io_func.io_type = HIF_SDIO;
1625 nwi->io_func.io_init = linux_sdio_init;
1626 nwi->io_func.io_deinit = linux_sdio_deinit;
1627 nwi->io_func.u.sdio.sdio_cmd52 = linux_sdio_cmd52;
1628 nwi->io_func.u.sdio.sdio_cmd53 = linux_sdio_cmd53;
1629 nwi->io_func.u.sdio.sdio_set_max_speed = linux_sdio_set_max_speed;
1630 nwi->io_func.u.sdio.sdio_set_default_speed = linux_sdio_set_default_speed;
1632 nwi->io_func.io_type = HIF_SPI;
1633 nwi->io_func.io_init = linux_spi_init;
1634 nwi->io_func.io_deinit = linux_spi_deinit;
1635 nwi->io_func.u.spi.spi_tx = linux_spi_write;
1636 nwi->io_func.u.spi.spi_rx = linux_spi_read;
1637 nwi->io_func.u.spi.spi_trx = linux_spi_write_read;
1638 nwi->io_func.u.spi.spi_max_speed = linux_spi_set_max_speed;
1641 /*for now - to be revised*/
1642 #ifdef WILC_FULLY_HOSTING_AP
1643 /* incase of Fully hosted AP, all non cfg pkts are processed here*/
1644 nwi->net_func.rx_indicate = WILC_Process_rx_frame;
1646 nwi->net_func.rx_indicate = frmw_to_linux;
1648 nwi->net_func.rx_complete = linux_wlan_rx_complete;
1649 nwi->indicate_func.mac_indicate = linux_wlan_mac_indicate;
1652 int wlan_initialize_threads(perInterface_wlan_t *nic)
1656 PRINT_D(INIT_DBG, "Initializing Threads ...\n");
1658 #if (RX_BH_TYPE == RX_BH_WORK_QUEUE)
1659 /*Initialize rx work queue task*/
1660 INIT_WORK(&g_linux_wlan->rx_work_queue, isr_bh_routine);
1661 #elif (RX_BH_TYPE == RX_BH_KTHREAD)
1662 PRINT_D(INIT_DBG, "Creating kthread for Rxq BH\n");
1663 g_linux_wlan->rx_bh_thread = kthread_run(isr_bh_routine, (void *)g_linux_wlan, "K_RXQ_BH");
1664 if (g_linux_wlan->rx_bh_thread == 0) {
1665 PRINT_ER("couldn't create RX BH thread\n");
1671 #ifndef TCP_ENHANCEMENTS
1672 /* create rx task */
1673 PRINT_D(INIT_DBG, "Creating kthread for reception\n");
1674 g_linux_wlan->rxq_thread = kthread_run(linux_wlan_rxq_task, (void *)g_linux_wlan, "K_RXQ_TASK");
1675 if (g_linux_wlan->rxq_thread == 0) {
1676 PRINT_ER("couldn't create RXQ thread\n");
1681 /* wait for RXQ task to start. */
1682 linux_wlan_lock(&g_linux_wlan->rxq_thread_started);
1686 /* create tx task */
1687 PRINT_D(INIT_DBG, "Creating kthread for transmission\n");
1688 g_linux_wlan->txq_thread = kthread_run(linux_wlan_txq_task, (void *)g_linux_wlan, "K_TXQ_TASK");
1689 if (g_linux_wlan->txq_thread == 0) {
1690 PRINT_ER("couldn't create TXQ thread\n");
1695 PRINT_D(INIT_DBG, "Creating kthread for Debugging\n");
1696 g_linux_wlan->txq_thread = kthread_run(DebuggingThreadTask, (void *)g_linux_wlan, "DebugThread");
1697 if (g_linux_wlan->txq_thread == 0) {
1698 PRINT_ER("couldn't create TXQ thread\n");
1703 /* wait for TXQ task to start. */
1704 linux_wlan_lock(&g_linux_wlan->txq_thread_started);
1709 /*De-Initialize 2nd thread*/
1710 g_linux_wlan->close = 1;
1711 linux_wlan_unlock(&g_linux_wlan->rxq_event);
1712 kthread_stop(g_linux_wlan->rxq_thread);
1715 #if (RX_BH_TYPE == RX_BH_KTHREAD)
1716 /*De-Initialize 1st thread*/
1717 g_linux_wlan->close = 1;
1718 linux_wlan_unlock(&g_linux_wlan->rx_sem);
1719 kthread_stop(g_linux_wlan->rx_bh_thread);
1722 g_linux_wlan->close = 0;
1726 static void wlan_deinitialize_threads(linux_wlan_t *nic)
1729 g_linux_wlan->close = 1;
1730 PRINT_D(INIT_DBG, "Deinitializing Threads\n");
1731 if (&g_linux_wlan->rxq_event != NULL)
1732 linux_wlan_unlock(&g_linux_wlan->rxq_event);
1735 if (g_linux_wlan->rxq_thread != NULL) {
1736 kthread_stop(g_linux_wlan->rxq_thread);
1737 g_linux_wlan->rxq_thread = NULL;
1741 if (&g_linux_wlan->txq_event != NULL)
1742 linux_wlan_unlock(&g_linux_wlan->txq_event);
1745 if (g_linux_wlan->txq_thread != NULL) {
1746 kthread_stop(g_linux_wlan->txq_thread);
1747 g_linux_wlan->txq_thread = NULL;
1750 #if (RX_BH_TYPE == RX_BH_KTHREAD)
1751 if (&g_linux_wlan->rx_sem != NULL)
1752 linux_wlan_unlock(&g_linux_wlan->rx_sem);
1754 if (g_linux_wlan->rx_bh_thread != NULL) {
1755 kthread_stop(g_linux_wlan->rx_bh_thread);
1756 g_linux_wlan->rx_bh_thread = NULL;
1761 #ifdef STATIC_MACADDRESS
1762 const char *path_string[] = {
1767 static int linux_wlan_read_mac_addr(void *vp)
1770 struct file *fp = (struct file *)-ENOENT;
1771 mm_segment_t old_fs;
1774 int array_size = sizeof(path_string) / sizeof(path_string[0]);
1776 /* change to KERNEL_DS address limit */
1780 for (index = 0; index < array_size; index++) {
1781 fp = filp_open(path_string[index], O_WRONLY, 0640);
1787 /*No such file or directory */
1788 if (IS_ERR(fp) || !fp->f_op) {
1789 get_random_bytes(&mac_add[3], 3);
1790 /* open file to write */
1791 fp = filp_open(path_string[index], O_WRONLY | O_CREAT, 0640);
1793 if (!fp || IS_ERR(fp)) {
1797 /* write buf to file */
1798 fp->f_op->write(fp, mac_add, 6, &pos);
1802 /* read file to buf */
1803 fp->f_op->read(fp, mac_add, 6, &pos);
1808 if (index == array_size) {
1809 PRINT_ER("random MAC\n");
1813 if (fp && !IS_ERR(fp)) {
1814 filp_close(fp, NULL);
1823 #ifdef COMPLEMENT_BOOT
1825 extern volatile int probe;
1826 extern uint8_t core_11b_ready(void);
1828 #define READY_CHECK_THRESHOLD 30
1829 extern void wilc_wlan_global_reset(void);
1830 uint8_t wilc1000_prepare_11b_core(wilc_wlan_inp_t *nwi, wilc_wlan_oup_t *nwo, linux_wlan_t *nic)
1833 while ((core_11b_ready() && (READY_CHECK_THRESHOLD > (trials++)))) {
1834 PRINT_D(INIT_DBG, "11b core not ready yet: %u\n", trials);
1835 wilc_wlan_deinit(nic);
1836 wilc_wlan_global_reset();
1837 sdio_unregister_driver(&wilc_bus);
1839 linux_wlan_device_detection(0);
1843 linux_wlan_device_detection(1);
1845 sdio_register_driver(&wilc_bus);
1851 g_linux_wlan->wilc_sdio_func = local_sdio_func;
1852 linux_to_wlan(nwi, nic);
1853 wilc_wlan_init(nwi, nwo);
1856 if (READY_CHECK_THRESHOLD <= trials)
1863 int repeat_power_cycle(perInterface_wlan_t *nic)
1866 wilc_wlan_inp_t nwi;
1867 wilc_wlan_oup_t nwo;
1868 sdio_unregister_driver(&wilc_bus);
1870 linux_wlan_device_detection(0);
1871 linux_wlan_device_power(0);
1873 linux_wlan_device_power(1);
1875 linux_wlan_device_detection(1);
1878 sdio_register_driver(&wilc_bus);
1885 g_linux_wlan->wilc_sdio_func = local_sdio_func;
1886 linux_to_wlan(&nwi, g_linux_wlan);
1887 ret = wilc_wlan_init(&nwi, &nwo);
1889 g_linux_wlan->mac_status = WILC_MAC_STATUS_INIT;
1890 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
1891 enable_sdio_interrupt();
1894 if (linux_wlan_get_firmware(nic)) {
1895 PRINT_ER("Can't get firmware \n");
1900 /*Download firmware*/
1901 ret = linux_wlan_firmware_download(g_linux_wlan);
1903 PRINT_ER("Failed to download firmware\n");
1907 ret = linux_wlan_start_firmware(nic);
1909 PRINT_ER("Failed to start firmware\n");
1916 int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic)
1918 wilc_wlan_inp_t nwi;
1919 wilc_wlan_oup_t nwo;
1920 perInterface_wlan_t *nic = p_nic;
1923 if (!g_linux_wlan->wilc1000_initialized) {
1924 g_linux_wlan->mac_status = WILC_MAC_STATUS_INIT;
1925 g_linux_wlan->close = 0;
1926 g_linux_wlan->wilc1000_initialized = 0;
1928 wlan_init_locks(g_linux_wlan);
1930 #ifdef STATIC_MACADDRESS
1931 wilc_mac_thread = kthread_run(linux_wlan_read_mac_addr, NULL, "wilc_mac_thread");
1932 if (wilc_mac_thread < 0) {
1933 PRINT_ER("couldn't create Mac addr thread\n");
1937 linux_to_wlan(&nwi, g_linux_wlan);
1939 ret = wilc_wlan_init(&nwi, &nwo);
1941 PRINT_ER("Initializing WILC_Wlan FAILED\n");
1945 memcpy(&g_linux_wlan->oup, &nwo, sizeof(wilc_wlan_oup_t));
1947 /*Save the oup structre into global pointer*/
1948 gpstrWlanOps = &g_linux_wlan->oup;
1951 ret = wlan_initialize_threads(nic);
1953 PRINT_ER("Initializing Threads FAILED\n");
1955 goto _fail_wilc_wlan_;
1958 #if (defined WILC_SDIO) && (defined COMPLEMENT_BOOT)
1959 if (wilc1000_prepare_11b_core(&nwi, &nwo, g_linux_wlan)) {
1960 PRINT_ER("11b Core is not ready\n");
1962 goto _fail_threads_;
1966 #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
1967 if (init_irq(g_linux_wlan)) {
1968 PRINT_ER("couldn't initialize IRQ\n");
1970 goto _fail_threads_;
1974 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
1975 if (enable_sdio_interrupt()) {
1976 PRINT_ER("couldn't initialize IRQ\n");
1978 goto _fail_irq_init_;
1982 if (linux_wlan_get_firmware(nic)) {
1983 PRINT_ER("Can't get firmware \n");
1985 goto _fail_irq_enable_;
1989 /*Download firmware*/
1990 ret = linux_wlan_firmware_download(g_linux_wlan);
1992 PRINT_ER("Failed to download firmware\n");
1994 goto _fail_irq_enable_;
1998 ret = linux_wlan_start_firmware(nic);
2000 PRINT_ER("Failed to start firmware\n");
2002 goto _fail_irq_enable_;
2005 wilc_bus_set_max_speed();
2007 if (g_linux_wlan->oup.wlan_cfg_get(1, WID_FIRMWARE_VERSION, 1, 0)) {
2009 char Firmware_ver[20];
2010 size = g_linux_wlan->oup.wlan_cfg_get_value(
2011 WID_FIRMWARE_VERSION,
2012 Firmware_ver, sizeof(Firmware_ver));
2013 Firmware_ver[size] = '\0';
2014 PRINT_D(INIT_DBG, "***** Firmware Ver = %s *******\n", Firmware_ver);
2016 /* Initialize firmware with default configuration */
2017 ret = linux_wlan_init_test_config(dev, g_linux_wlan);
2020 PRINT_ER("Failed to configure firmware\n");
2022 goto _fail_fw_start_;
2025 g_linux_wlan->wilc1000_initialized = 1;
2026 return 0; /*success*/
2030 if (&g_linux_wlan->oup != NULL) {
2031 if (g_linux_wlan->oup.wlan_stop != NULL)
2032 g_linux_wlan->oup.wlan_stop();
2036 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
2037 disable_sdio_interrupt();
2040 #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
2041 deinit_irq(g_linux_wlan);
2045 wlan_deinitialize_threads(g_linux_wlan);
2047 wilc_wlan_deinit(g_linux_wlan);
2049 wlan_deinit_locks(g_linux_wlan);
2050 PRINT_ER("WLAN Iinitialization FAILED\n");
2052 PRINT_D(INIT_DBG, "wilc1000 already initialized\n");
2059 * - this function will be called automatically by OS when module inserted.
2062 #if !defined (NM73131_0_BOARD)
2063 int mac_init_fn(struct net_device *ndev)
2066 /*Why we do this !!!*/
2067 netif_start_queue(ndev); /* ma */
2068 netif_stop_queue(ndev); /* ma */
2073 int mac_init_fn(struct net_device *ndev)
2076 unsigned char mac_add[] = {0x00, 0x50, 0xc2, 0x5e, 0x10, 0x00};
2077 /* TODO: get MAC address whenever the source is EPROM - hardcoded and copy it to ndev*/
2078 memcpy(ndev->dev_addr, mac_add, 6);
2080 if (!is_valid_ether_addr(ndev->dev_addr)) {
2081 PRINT_ER("Error: Wrong MAC address\n");
2090 void WILC_WFI_frame_register(struct wiphy *wiphy, struct net_device *dev,
2091 u16 frame_type, bool reg);
2093 /* This fn is called, when this device is setup using ifconfig */
2094 #if !defined (NM73131_0_BOARD)
2095 int mac_open(struct net_device *ndev)
2097 perInterface_wlan_t *nic;
2100 /*No need for setting mac address here anymore,*/
2101 /*Just set it in init_test_config()*/
2102 unsigned char mac_add[ETH_ALEN] = {0};
2106 struct WILC_WFI_priv *priv;
2108 nic = netdev_priv(ndev);
2109 priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy);
2110 PRINT_D(INIT_DBG, "MAC OPEN[%p]\n", ndev);
2113 ret = WILC_WFI_InitHostInt(ndev);
2115 PRINT_ER("Failed to initialize host interface\n");
2121 /*initialize platform*/
2122 PRINT_D(INIT_DBG, "*** re-init ***\n");
2123 ret = wilc1000_wlan_init(ndev, nic);
2125 PRINT_ER("Failed to initialize wilc1000\n");
2126 WILC_WFI_DeInitHostInt(ndev);
2130 Set_machw_change_vir_if(WILC_FALSE);
2132 status = host_int_get_MacAddress(priv->hWILCWFIDrv, mac_add);
2133 PRINT_D(INIT_DBG, "Mac address: %x:%x:%x:%x:%x:%x\n", mac_add[0], mac_add[1], mac_add[2],
2134 mac_add[3], mac_add[4], mac_add[5]);
2136 /* loop through the NUM of supported devices and set the MAC address */
2137 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
2138 if (ndev == g_linux_wlan->strInterfaceInfo[i].wilc_netdev) {
2139 memcpy(g_linux_wlan->strInterfaceInfo[i].aSrcAddress, mac_add, ETH_ALEN);
2140 g_linux_wlan->strInterfaceInfo[i].drvHandler = (WILC_Uint32)priv->hWILCWFIDrv;
2145 /* TODO: get MAC address whenever the source is EPROM - hardcoded and copy it to ndev*/
2146 memcpy(ndev->dev_addr, g_linux_wlan->strInterfaceInfo[i].aSrcAddress, ETH_ALEN);
2148 if (!is_valid_ether_addr(ndev->dev_addr)) {
2149 PRINT_ER("Error: Wrong MAC address\n");
2155 WILC_WFI_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy, nic->wilc_netdev,
2156 nic->g_struct_frame_reg[0].frame_type, nic->g_struct_frame_reg[0].reg);
2157 WILC_WFI_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy, nic->wilc_netdev,
2158 nic->g_struct_frame_reg[1].frame_type, nic->g_struct_frame_reg[1].reg);
2159 netif_wake_queue(ndev);
2160 g_linux_wlan->open_ifcs++;
2161 nic->mac_opened = 1;
2165 WILC_WFI_DeInitHostInt(ndev);
2166 wilc1000_wlan_deinit(g_linux_wlan);
2170 int mac_open(struct net_device *ndev)
2174 nic = netdev_priv(ndev);
2176 /*initialize platform*/
2177 if (wilc1000_wlan_init(nic)) {
2178 PRINT_ER("Failed to initialize platform\n");
2181 /* Start the network interface queue for this device */
2182 PRINT_D(INIT_DBG, "Starting netifQ\n");
2183 netif_start_queue(ndev);
2184 /* linux_wlan_lock(&close_exit_sync); */
2189 struct net_device_stats *mac_stats(struct net_device *dev)
2191 perInterface_wlan_t *nic = netdev_priv(dev);
2194 return &nic->netstats;
2197 /* Setup the multicast filter */
2198 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 34)
2199 static void wilc_set_multicast_list(struct net_device *dev)
2202 struct netdev_hw_addr *ha;
2203 struct WILC_WFI_priv *priv;
2204 tstrWILC_WFIDrv *pstrWFIDrv;
2206 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
2207 pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
2213 PRINT_D(INIT_DBG, "Setting Multicast List with count = %d. \n", dev->mc.count);
2215 if (dev->flags & IFF_PROMISC) {
2216 /* Normally, we should configure the chip to retrive all packets
2217 * but we don't wanna support this right now */
2218 /* TODO: add promiscuous mode support */
2219 PRINT_D(INIT_DBG, "Set promiscuous mode ON, retrive all packets \n");
2223 /* If there's more addresses than we handle, get all multicast
2224 * packets and sort them out in software. */
2225 if ((dev->flags & IFF_ALLMULTI) || (dev->mc.count) > WILC_MULTICAST_TABLE_SIZE) {
2226 PRINT_D(INIT_DBG, "Disable multicast filter, retrive all multicast packets\n");
2227 /* get all multicast packets */
2228 host_int_setup_multicast_filter((WILC_WFIDrvHandle)pstrWFIDrv, WILC_FALSE, 0);
2232 /* No multicast? Just get our own stuff */
2233 if ((dev->mc.count) == 0) {
2234 PRINT_D(INIT_DBG, "Enable multicast filter, retrive directed packets only.\n");
2235 host_int_setup_multicast_filter((WILC_WFIDrvHandle)pstrWFIDrv, WILC_TRUE, 0);
2239 /* Store all of the multicast addresses in the hardware filter */
2240 netdev_for_each_mc_addr(ha, dev)
2242 WILC_memcpy(gau8MulticastMacAddrList[i], ha->addr, ETH_ALEN);
2243 PRINT_D(INIT_DBG, "Entry[%d]: %x:%x:%x:%x:%x:%x\n", i,
2244 gau8MulticastMacAddrList[i][0], gau8MulticastMacAddrList[i][1], gau8MulticastMacAddrList[i][2], gau8MulticastMacAddrList[i][3], gau8MulticastMacAddrList[i][4], gau8MulticastMacAddrList[i][5]);
2248 host_int_setup_multicast_filter((WILC_WFIDrvHandle)pstrWFIDrv, WILC_TRUE, (dev->mc.count));
2256 static void wilc_set_multicast_list(struct net_device *dev)
2258 /* BIG Warning, Beware : Uncompiled, untested... */
2259 struct dev_mc_list *mc_ptr;
2265 PRINT_D(INIT_DBG, "Setting Multicast List. \n");
2266 PRINT_D(INIT_DBG, "dev->mc_count = %d\n", dev->mc_count);
2268 if (dev->flags & IFF_PROMISC) {
2269 /* Normally, we should configure the chip to retrive all packets
2270 * but we don't wanna support this right now */
2271 /* TODO: add promiscuous mode support */
2272 PRINT_D(INIT_DBG, "Set promiscuous mode ON, retrive all packets \n");
2276 /* If there's more addresses than we handle, get all multicast
2277 * packets and sort them out in software. */
2278 if ((dev->flags & IFF_ALLMULTI) || (dev->mc_count > WILC_MULTICAST_TABLE_SIZE)) {
2279 PRINT_D(INIT_DBG, "Disable multicast filter, retrive all multicast packets\n");
2280 host_int_setup_multicast_filter((WILC_WFIDrvHandle)gWFiDrvHandle, WILC_FALSE, 0);
2284 /* No multicast? Just get our own stuff */
2285 if (dev->mc_count == 0) {
2286 PRINT_D(INIT_DBG, "Enable multicast filter, retrive directed packets only.\n");
2287 host_int_setup_multicast_filter((WILC_WFIDrvHandle)gWFiDrvHandle, WILC_TRUE, 0);
2291 /* Store all of the multicast addresses in the hardware filter */
2293 for (mc_ptr = dev->mc_list; mc_ptr; mc_ptr = mc_ptr->next, i++) {
2294 WILC_memcpy(gau8MulticastMacAddrList[i], mc_ptr->dmi_addr, ETH_ALEN)
2298 host_int_setup_multicast_filter((WILC_WFIDrvHandle)gWFiDrvHandle, WILC_TRUE, (dev->mc_count));
2303 static void linux_wlan_tx_complete(void *priv, int status)
2306 struct tx_complete_data *pv_data = (struct tx_complete_data *)priv;
2308 PRINT_D(TX_DBG, "Packet sent successfully - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb);
2310 PRINT_D(TX_DBG, "Couldn't send packet - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb);
2312 /* Free the SK Buffer, its work is done */
2313 dev_kfree_skb(pv_data->skb);
2314 linux_wlan_free(pv_data);
2317 int mac_xmit(struct sk_buff *skb, struct net_device *ndev)
2319 perInterface_wlan_t *nic;
2320 struct tx_complete_data *tx_data = NULL;
2324 struct ethhdr *eth_h;
2325 nic = netdev_priv(ndev);
2327 PRINT_D(INT_DBG, "\n========\n IntUH: %d - IntBH: %d - IntCld: %d \n========\n", int_rcvdU, int_rcvdB, int_clrd);
2328 PRINT_D(TX_DBG, "Sending packet just received from TCP/IP\n");
2330 /* Stop the network interface queue */
2331 if (skb->dev != ndev) {
2332 PRINT_ER("Packet not destined to this device\n");
2336 tx_data = (struct tx_complete_data *)internal_alloc(sizeof(struct tx_complete_data), GFP_ATOMIC);
2337 if (tx_data == NULL) {
2338 PRINT_ER("Failed to allocate memory for tx_data structure\n");
2340 netif_wake_queue(ndev);
2344 tx_data->buff = skb->data;
2345 tx_data->size = skb->len;
2348 eth_h = (struct ethhdr *)(skb->data);
2349 if (eth_h->h_proto == 0x8e88) {
2350 PRINT_D(INIT_DBG, "EAPOL transmitted\n");
2353 /*get source and dest ip addresses*/
2354 ih = (struct iphdr *)(skb->data + sizeof(struct ethhdr));
2356 pu8UdpBuffer = (char *)ih + sizeof(struct iphdr);
2357 if ((pu8UdpBuffer[1] == 68 && pu8UdpBuffer[3] == 67) || (pu8UdpBuffer[1] == 67 && pu8UdpBuffer[3] == 68)) {
2358 PRINT_D(GENERIC_DBG, "DHCP Message transmitted, type:%x %x %x\n", pu8UdpBuffer[248], pu8UdpBuffer[249], pu8UdpBuffer[250]);
2361 PRINT_D(TX_DBG, "Sending packet - Size = %d - Address = %p - SKB = %p\n", tx_data->size, tx_data->buff, tx_data->skb);
2363 /* Send packet to MAC HW - for now the tx_complete function will be just status
2364 * indicator. still not sure if I need to suspend host transmission till the tx_complete
2365 * function called or not?
2366 * allocated buffer will be freed in tx_complete function.
2368 PRINT_D(TX_DBG, "Adding tx packet to TX Queue\n");
2369 nic->netstats.tx_packets++;
2370 nic->netstats.tx_bytes += tx_data->size;
2371 tx_data->pBssid = g_linux_wlan->strInterfaceInfo[nic->u8IfIdx].aBSSID;
2372 #ifndef WILC_FULLY_HOSTING_AP
2373 QueueCount = g_linux_wlan->oup.wlan_add_to_tx_que((void *)tx_data,
2376 linux_wlan_tx_complete);
2378 QueueCount = WILC_Xmit_data((void *)tx_data, HOST_TO_WLAN);
2379 #endif /* WILC_FULLY_HOSTING_AP */
2382 if (QueueCount > FLOW_CONTROL_UPPER_THRESHOLD) {
2383 netif_stop_queue(g_linux_wlan->strInterfaceInfo[0].wilc_netdev);
2384 netif_stop_queue(g_linux_wlan->strInterfaceInfo[1].wilc_netdev);
2391 int mac_close(struct net_device *ndev)
2393 struct WILC_WFI_priv *priv;
2394 perInterface_wlan_t *nic;
2395 tstrWILC_WFIDrv *pstrWFIDrv;
2397 nic = netdev_priv(ndev);
2399 if ((nic == NULL) || (nic->wilc_netdev == NULL) || (nic->wilc_netdev->ieee80211_ptr == NULL) || (nic->wilc_netdev->ieee80211_ptr->wiphy == NULL)) {
2400 PRINT_ER("nic = NULL\n");
2404 priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy);
2407 PRINT_ER("priv = NULL\n");
2411 pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
2415 PRINT_D(GENERIC_DBG, "Mac close\n");
2417 if (g_linux_wlan == NULL) {
2418 PRINT_ER("g_linux_wlan = NULL\n");
2422 if (pstrWFIDrv == NULL) {
2423 PRINT_ER("pstrWFIDrv = NULL\n");
2427 if ((g_linux_wlan->open_ifcs) > 0) {
2428 g_linux_wlan->open_ifcs--;
2430 PRINT_ER("ERROR: MAC close called while number of opened interfaces is zero\n");
2434 if (nic->wilc_netdev != NULL) {
2435 /* Stop the network interface queue */
2436 netif_stop_queue(nic->wilc_netdev);
2439 WILC_WFI_DeInitHostInt(nic->wilc_netdev);
2443 if (g_linux_wlan->open_ifcs == 0) {
2444 PRINT_D(GENERIC_DBG, "Deinitializing wilc1000\n");
2445 g_linux_wlan->close = 1;
2446 wilc1000_wlan_deinit(g_linux_wlan);
2448 #ifdef WILC_AP_EXTERNAL_MLME
2449 WILC_WFI_deinit_mon_interface();
2454 linux_wlan_unlock(&close_exit_sync);
2455 nic->mac_opened = 0;
2461 int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
2464 WILC_Uint8 *buff = NULL;
2466 WILC_Uint32 size = 0, length = 0;
2467 perInterface_wlan_t *nic;
2468 struct WILC_WFI_priv *priv;
2469 WILC_Sint32 s32Error = WILC_SUCCESS;
2473 /* struct iwreq *wrq = (struct iwreq *) req; // tony moved to case SIOCSIWPRIV */
2475 nic = netdev_priv(ndev);
2477 if (!g_linux_wlan->wilc1000_initialized)
2483 /* [[ added by tony for SIOCDEVPRIVATE */
2484 case SIOCDEVPRIVATE + 1:
2486 android_wifi_priv_cmd priv_cmd;
2488 PRINT_INFO(GENERIC_DBG, "in SIOCDEVPRIVATE+1\n");
2490 if (copy_from_user(&priv_cmd, req->ifr_data, sizeof(android_wifi_priv_cmd))) {
2495 buff = kmalloc(priv_cmd.total_len, GFP_KERNEL);
2501 if (copy_from_user(buff, priv_cmd.buf, priv_cmd.total_len)) {
2506 PRINT_INFO(GENERIC_DBG, "%s: Android private cmd \"%s\" on %s\n", __FUNCTION__, buff, req->ifr_name);
2508 if (strncasecmp(buff, "SCAN-ACTIVE", strlen("SCAN-ACTIVE")) == 0) {
2509 PRINT_INFO(GENERIC_DBG, "%s, SCAN-ACTIVE command\n", __FUNCTION__);
2510 } else if (strncasecmp(buff, "SCAN-PASSIVE", strlen("SCAN-PASSIVE")) == 0) {
2511 PRINT_INFO(GENERIC_DBG, "%s, SCAN-PASSIVE command\n", __FUNCTION__);
2512 } else if (strncasecmp(buff, "RXFILTER-START", strlen("RXFILTER-START")) == 0) {
2513 PRINT_INFO(GENERIC_DBG, "%s, RXFILTER-START command\n", __FUNCTION__);
2514 } else if (strncasecmp(buff, "RXFILTER-STOP", strlen("RXFILTER-STOP")) == 0) {
2515 PRINT_INFO(GENERIC_DBG, "%s, RXFILTER-STOP command\n", __FUNCTION__);
2516 } else if (strncasecmp(buff, "RXFILTER-ADD", strlen("RXFILTER-ADD")) == 0) {
2517 int filter_num = *(buff + strlen("RXFILTER-ADD") + 1) - '0';
2518 PRINT_INFO(GENERIC_DBG, "%s, RXFILTER-ADD command, filter_num=%d\n", __FUNCTION__, filter_num);
2519 } else if (strncasecmp(buff, "RXFILTER-REMOVE", strlen("RXFILTER-REMOVE")) == 0) {
2520 int filter_num = *(buff + strlen("RXFILTER-REMOVE") + 1) - '0';
2521 PRINT_INFO(GENERIC_DBG, "%s, RXFILTER-REMOVE command, filter_num=%d\n", __FUNCTION__, filter_num);
2522 } else if (strncasecmp(buff, "BTCOEXSCAN-START", strlen("BTCOEXSCAN-START")) == 0) {
2523 PRINT_INFO(GENERIC_DBG, "%s, BTCOEXSCAN-START command\n", __FUNCTION__);
2524 } else if (strncasecmp(buff, "BTCOEXSCAN-STOP", strlen("BTCOEXSCAN-STOP")) == 0) {
2525 PRINT_INFO(GENERIC_DBG, "%s, BTCOEXSCAN-STOP command\n", __FUNCTION__);
2526 } else if (strncasecmp(buff, "BTCOEXMODE", strlen("BTCOEXMODE")) == 0) {
2527 PRINT_INFO(GENERIC_DBG, "%s, BTCOEXMODE command\n", __FUNCTION__);
2528 } else if (strncasecmp(buff, "SETBAND", strlen("SETBAND")) == 0) {
2529 uint band = *(buff + strlen("SETBAND") + 1) - '0';
2530 PRINT_INFO(GENERIC_DBG, "%s, SETBAND command, band=%d\n", __FUNCTION__, band);
2531 } else if (strncasecmp(buff, "GETBAND", strlen("GETBAND")) == 0) {
2532 PRINT_INFO(GENERIC_DBG, "%s, GETBAND command\n", __FUNCTION__);
2533 } else if (strncasecmp(buff, "COUNTRY", strlen("COUNTRY")) == 0) {
2534 char *country_code = buff + strlen("COUNTRY") + 1;
2535 PRINT_INFO(GENERIC_DBG, "%s, COUNTRY command, country_code=%s\n", __FUNCTION__, country_code);
2537 PRINT_INFO(GENERIC_DBG, "%s, Unknown command\n", __FUNCTION__);
2544 struct iwreq *wrq = (struct iwreq *) req; /* added by tony */
2546 size = wrq->u.data.length;
2548 if (size && wrq->u.data.pointer) {
2549 buff = kmalloc(size, GFP_KERNEL);
2556 (buff, wrq->u.data.pointer,
2557 wrq->u.data.length)) {
2562 if (strncasecmp(buff, "RSSI", length) == 0) {
2565 priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy);
2566 s32Error = host_int_get_rssi(priv->hWILCWFIDrv, &(rssi));
2568 PRINT_ER("Failed to send get rssi param's message queue ");
2570 PRINT_INFO(GENERIC_DBG, "RSSI :%d\n", rssi);
2572 /*Rounding up the rssi negative value*/
2575 snprintf(buff, size, "rssi %d", rssi);
2577 if (copy_to_user(wrq->u.data.pointer, buff, size)) {
2578 PRINT_ER("%s: failed to copy data to user buffer\n", __FUNCTION__);
2589 PRINT_INFO(GENERIC_DBG, "Command - %d - has been received\n", cmd);
2590 s32Error = -EOPNOTSUPP;
2604 void frmw_to_linux(uint8_t *buff, uint32_t size, uint32_t pkt_offset)
2607 unsigned int frame_len = 0;
2609 unsigned char *buff_to_send = NULL;
2610 struct sk_buff *skb;
2613 struct net_device *wilc_netdev;
2614 perInterface_wlan_t *nic;
2616 wilc_netdev = GetIfHandler(buff);
2617 if (wilc_netdev == NULL)
2621 nic = netdev_priv(wilc_netdev);
2626 buff_to_send = buff;
2629 /* Need to send the packet up to the host, allocate a skb buffer */
2630 skb = dev_alloc_skb(frame_len);
2632 PRINT_ER("Low memory - packet droped\n");
2636 skb_reserve(skb, (unsigned int)skb->data & 0x3);
2638 if (g_linux_wlan == NULL || wilc_netdev == NULL) {
2639 PRINT_ER("wilc_netdev in g_linux_wlan is NULL");
2641 skb->dev = wilc_netdev;
2643 if (skb->dev == NULL) {
2644 PRINT_ER("skb->dev is NULL\n");
2651 * WILC_PRINTF("buff_to_send[%d]=%2x\n",i,buff_to_send[i]);
2655 /* skb_put(skb, frame_len); */
2656 memcpy(skb_put(skb, frame_len), buff_to_send, frame_len);
2658 /* WILC_PRINTF("After MEM_CPY\n"); */
2660 /* nic = netdev_priv(wilc_netdev); */
2663 /* if(nic->monitor_flag)
2665 * WILC_WFI_monitor_rx(nic->wilc_netdev,skb);
2669 skb->protocol = eth_type_trans(skb, wilc_netdev);
2670 #ifndef TCP_ENHANCEMENTS
2671 /*get source and dest ip addresses*/
2672 ih = (struct iphdr *)(skb->data + sizeof(struct ethhdr));
2674 pu8UdpBuffer = (char *)ih + sizeof(struct iphdr);
2675 if (buff_to_send[35] == 67 && buff_to_send[37] == 68) {
2676 PRINT_D(RX_DBG, "DHCP Message received\n");
2678 if (buff_to_send[12] == 0x88 && buff_to_send[13] == 0x8e)
2679 PRINT_D(GENERIC_DBG, "eapol received\n");
2681 /* Send the packet to the stack by giving it to the bridge */
2682 nic->netstats.rx_packets++;
2683 nic->netstats.rx_bytes += frame_len;
2684 skb->ip_summed = CHECKSUM_UNNECESSARY;
2685 stats = netif_rx(skb);
2686 PRINT_D(RX_DBG, "netif_rx ret value is: %d\n", stats);
2688 #ifndef TCP_ENHANCEMENTS
2690 PRINT_ER("Discard sending packet with len = %d\n", size);
2695 void WILC_WFI_mgmt_rx(uint8_t *buff, uint32_t size)
2698 perInterface_wlan_t *nic;
2701 /*Pass the frame on the monitor interface, if any.*/
2702 /*Otherwise, pass it on p2p0 netdev, if registered on it*/
2703 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
2704 nic = netdev_priv(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2705 if (nic->monitor_flag) {
2706 WILC_WFI_monitor_rx(buff, size);
2712 nic = netdev_priv(g_linux_wlan->strInterfaceInfo[1].wilc_netdev); /* p2p0 */
2713 if ((buff[0] == nic->g_struct_frame_reg[0].frame_type && nic->g_struct_frame_reg[0].reg) ||
2714 (buff[0] == nic->g_struct_frame_reg[1].frame_type && nic->g_struct_frame_reg[1].reg)) {
2715 WILC_WFI_p2p_rx(g_linux_wlan->strInterfaceInfo[1].wilc_netdev, buff, size);
2720 int wilc_netdev_init(void)
2724 perInterface_wlan_t *nic;
2725 struct net_device *ndev;
2727 linux_wlan_init_lock("close_exit_sync", &close_exit_sync, 0);
2729 /*create the common structure*/
2730 g_linux_wlan = (linux_wlan_t *)WILC_MALLOC(sizeof(linux_wlan_t));
2731 memset(g_linux_wlan, 0, sizeof(linux_wlan_t));
2733 /*Reset interrupt count debug*/
2737 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
2738 register_inetaddr_notifier(&g_dev_notifier);
2741 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
2742 /*allocate first ethernet device with perinterface_wlan_t as its private data*/
2743 ndev = alloc_etherdev(sizeof(perInterface_wlan_t));
2745 PRINT_ER("Failed to allocate ethernet dev\n");
2749 nic = netdev_priv(ndev);
2750 memset(nic, 0, sizeof(perInterface_wlan_t));
2752 /*Name the Devices*/
2754 #if defined(NM73131) /* tony, 2012-09-20 */
2755 strcpy(ndev->name, "wilc_eth%d");
2756 #elif defined(PLAT_CLM9722) /* rachel */
2757 strcpy(ndev->name, "eth%d");
2758 #else /* PANDA_BOARD, PLAT_ALLWINNER_A10, PLAT_ALLWINNER_A20, PLAT_ALLWINNER_A31, PLAT_AML8726_M3 or PLAT_WMS8304 */
2759 strcpy(ndev->name, "wlan%d");
2762 strcpy(ndev->name, "p2p%d");
2764 nic->u8IfIdx = g_linux_wlan->u8NoIfcs;
2765 nic->wilc_netdev = ndev;
2766 g_linux_wlan->strInterfaceInfo[g_linux_wlan->u8NoIfcs].wilc_netdev = ndev;
2767 g_linux_wlan->u8NoIfcs++;
2768 wilc_set_netdev_ops(ndev);
2772 struct wireless_dev *wdev;
2774 wdev = WILC_WFI_WiphyRegister(ndev);
2777 /* set netdev, tony */
2778 SET_NETDEV_DEV(ndev, &local_sdio_func->dev);
2782 PRINT_ER("Can't register WILC Wiphy\n");
2786 /*linking the wireless_dev structure with the netdevice*/
2787 nic->wilc_netdev->ieee80211_ptr = wdev;
2788 nic->wilc_netdev->ml_priv = nic;
2789 wdev->netdev = nic->wilc_netdev;
2790 nic->netstats.rx_packets = 0;
2791 nic->netstats.tx_packets = 0;
2792 nic->netstats.rx_bytes = 0;
2793 nic->netstats.tx_bytes = 0;
2799 if (register_netdev(ndev)) {
2800 PRINT_ER("Device couldn't be registered - %s\n", ndev->name);
2801 return -1; /* ERROR */
2804 nic->iftype = STATION_MODE;
2805 nic->mac_opened = 0;
2810 if (!linux_spi_init(&g_linux_wlan->wilc_spidev)) {
2811 PRINT_ER("Can't initialize SPI \n");
2812 return -1; /* ERROR */
2814 g_linux_wlan->wilc_spidev = wilc_spi_dev;
2816 g_linux_wlan->wilc_sdio_func = local_sdio_func;
2823 /*The 1st function called after module inserted*/
2824 static int __init init_wilc_driver(void)
2828 #if defined (WILC_DEBUGFS)
2829 if (wilc_debugfs_init() < 0) {
2830 PRINT_D(GENERIC_DBG, "fail to create debugfs for wilc driver\n");
2835 printk("IN INIT FUNCTION\n");
2836 printk("*** WILC1000 driver VERSION=[%s] FW_VER=[%s] ***\n", __DRIVER_VERSION__, __DRIVER_VERSION__);
2838 linux_wlan_device_power(1);
2840 linux_wlan_device_detection(1);
2846 ret = sdio_register_driver(&wilc_bus);
2848 PRINT_D(INIT_DBG, "init_wilc_driver: Failed register sdio driver\n");
2854 PRINT_D(INIT_DBG, "Initializing netdev\n");
2855 if (wilc_netdev_init()) {
2856 PRINT_ER("Couldn't initialize netdev\n");
2861 late_initcall(init_wilc_driver);
2863 static void __exit exit_wilc_driver(void)
2866 perInterface_wlan_t *nic[NUM_CONCURRENT_IFC];
2867 #define CLOSE_TIMEOUT (12 * 1000)
2869 if ((g_linux_wlan != NULL) && (((g_linux_wlan->strInterfaceInfo[0].wilc_netdev) != NULL)
2870 || ((g_linux_wlan->strInterfaceInfo[1].wilc_netdev) != NULL))) {
2871 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
2872 unregister_inetaddr_notifier(&g_dev_notifier);
2875 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
2876 nic[i] = netdev_priv(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2881 if ((g_linux_wlan != NULL) && g_linux_wlan->wilc_firmware != NULL) {
2882 release_firmware(g_linux_wlan->wilc_firmware);
2883 g_linux_wlan->wilc_firmware = NULL;
2887 if ((g_linux_wlan != NULL) && (((g_linux_wlan->strInterfaceInfo[0].wilc_netdev) != NULL)
2888 || ((g_linux_wlan->strInterfaceInfo[1].wilc_netdev) != NULL))) {
2889 PRINT_D(INIT_DBG, "Waiting for mac_close ....\n");
2891 if (linux_wlan_lock_timeout(&close_exit_sync, CLOSE_TIMEOUT) < 0)
2892 PRINT_D(INIT_DBG, "Closed TimedOUT\n");
2894 PRINT_D(INIT_DBG, "mac_closed\n");
2897 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
2898 /* close all opened interfaces */
2899 if (g_linux_wlan->strInterfaceInfo[i].wilc_netdev != NULL) {
2900 if (nic[i]->mac_opened) {
2901 mac_close(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2905 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
2906 PRINT_D(INIT_DBG, "Unregistering netdev %p \n", g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2907 unregister_netdev(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2909 PRINT_D(INIT_DBG, "Freeing Wiphy...\n");
2910 WILC_WFI_WiphyFree(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2912 PRINT_D(INIT_DBG, "Freeing netdev...\n");
2913 free_netdev(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2919 #ifdef WILC_AP_EXTERNAL_MLME
2920 /* Bug 4600 : WILC_WFI_deinit_mon_interface was already called at mac_close */
2921 /* WILC_WFI_deinit_mon_interface(); */
2925 /* if(g_linux_wlan->open_ifcs==0) */
2928 PRINT_D(INIT_DBG, "SPI unregsiter...\n");
2929 spi_unregister_driver(&wilc_bus);
2931 PRINT_D(INIT_DBG, "SDIO unregsiter...\n");
2932 sdio_unregister_driver(&wilc_bus);
2935 linux_wlan_deinit_lock(&close_exit_sync);
2936 if (g_linux_wlan != NULL) {
2937 WILC_FREE(g_linux_wlan);
2938 g_linux_wlan = NULL;
2940 printk("Module_exit Done.\n");
2942 #if defined (WILC_DEBUGFS)
2943 wilc_debugfs_remove();
2946 linux_wlan_device_detection(0);
2947 linux_wlan_device_power(0);
2950 module_exit(exit_wilc_driver);
2952 MODULE_LICENSE("GPL");