1 #include "wilc_wfi_cfgoperations.h"
2 #include "linux_wlan_common.h"
3 #include "wilc_wlan_if.h"
6 #include "wilc_wfi_cfgoperations.h"
9 #include "linux_wlan_common.h"
11 #include <linux/slab.h>
12 #include <linux/sched.h>
13 #include <linux/delay.h>
14 #include <linux/workqueue.h>
15 #include <linux/interrupt.h>
16 #include <linux/irq.h>
17 #include <linux/gpio.h>
19 #include <linux/kthread.h>
20 #include <linux/firmware.h>
21 #include <linux/delay.h>
23 #include <linux/init.h>
24 #include <linux/netdevice.h>
25 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
26 #include <linux/inetdevice.h>
28 #include <linux/etherdevice.h>
29 #include <linux/module.h>
30 #include <linux/kernel.h>
31 #include <linux/skbuff.h>
33 #include <linux/version.h>
34 #include <linux/semaphore.h>
37 #include "linux_wlan_sdio.h"
39 #include "linux_wlan_spi.h"
42 #ifdef WILC_FULLY_HOSTING_AP
43 #include "wilc_host_ap.h"
46 #ifdef STATIC_MACADDRESS /* brandy_0724 [[ */
47 #include <linux/vmalloc.h>
49 struct task_struct *wilc_mac_thread;
50 unsigned char mac_add[] = {0x00, 0x80, 0xC2, 0x5E, 0xa2, 0xb2};
51 #endif /* brandy_0724 ]] */
53 #if defined(CUSTOMER_PLATFORM)
55 TODO : Write power control functions as customer platform.
59 #define _linux_wlan_device_power_on() {}
60 #define _linux_wlan_device_power_off() {}
62 #define _linux_wlan_device_detection() {}
63 #define _linux_wlan_device_removal() {}
66 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
67 extern bool g_obtainingIP;
69 extern u16 Set_machw_change_vir_if(bool bValue);
70 extern void resolve_disconnect_aberration(void *drvHandler);
71 extern u8 gau8MulticastMacAddrList[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN];
72 void wilc1000_wlan_deinit(linux_wlan_t *nic);
73 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
74 extern struct timer_list hDuringIpTimer;
77 static int linux_wlan_device_power(int on_off)
79 PRINT_D(INIT_DBG, "linux_wlan_device_power.. (%d)\n", on_off);
82 _linux_wlan_device_power_on();
84 _linux_wlan_device_power_off();
90 static int linux_wlan_device_detection(int on_off)
92 PRINT_D(INIT_DBG, "linux_wlan_device_detection.. (%d)\n", on_off);
96 _linux_wlan_device_detection();
98 _linux_wlan_device_removal();
105 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
106 static int dev_state_ev_handler(struct notifier_block *this, unsigned long event, void *ptr);
108 static struct notifier_block g_dev_notifier = {
109 .notifier_call = dev_state_ev_handler
113 #define wilc_wlan_deinit(nic) { if (&g_linux_wlan->oup != NULL) \
114 if (g_linux_wlan->oup.wlan_cleanup != NULL) \
115 g_linux_wlan->oup.wlan_cleanup(); }
118 #define STA_FIRMWARE "wifi_firmware.bin"
122 #define AP_FIRMWARE "wifi_firmware_ap.bin"
125 #ifndef P2P_CONCURRENCY_FIRMWARE
126 #define P2P_CONCURRENCY_FIRMWARE "wifi_firmware_p2p_concurrency.bin"
129 typedef struct android_wifi_priv_cmd {
133 } android_wifi_priv_cmd;
136 #define IRQ_NO_WAIT 0
138 * to sync between mac_close and module exit.
139 * don't initialize or de-initialize from init/deinitlocks
140 * to be initialized from module wilc_netdev_init and
141 * deinitialized from mdoule_exit
143 static struct semaphore close_exit_sync;
144 unsigned int int_rcvdU;
145 unsigned int int_rcvdB;
146 unsigned int int_clrd;
148 static int wlan_deinit_locks(linux_wlan_t *nic);
149 static void wlan_deinitialize_threads(linux_wlan_t *nic);
150 extern void WILC_WFI_monitor_rx(uint8_t *buff, uint32_t size);
151 extern void WILC_WFI_p2p_rx(struct net_device *dev, uint8_t *buff, uint32_t size);
153 static void linux_wlan_tx_complete(void *priv, int status);
154 void frmw_to_linux(uint8_t *buff, uint32_t size, uint32_t pkt_offset);
155 static int mac_init_fn(struct net_device *ndev);
156 int mac_xmit(struct sk_buff *skb, struct net_device *dev);
157 int mac_open(struct net_device *ndev);
158 int mac_close(struct net_device *ndev);
159 static struct net_device_stats *mac_stats(struct net_device *dev);
160 static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd);
161 static void wilc_set_multicast_list(struct net_device *dev);
164 * for now - in frmw_to_linux there should be private data to be passed to it
165 * and this data should be pointer to net device
167 linux_wlan_t *g_linux_wlan;
168 wilc_wlan_oup_t *gpstrWlanOps;
169 bool bEnablePS = true;
171 static const struct net_device_ops wilc_netdev_ops = {
172 .ndo_init = mac_init_fn,
173 .ndo_open = mac_open,
174 .ndo_stop = mac_close,
175 .ndo_start_xmit = mac_xmit,
176 .ndo_do_ioctl = mac_ioctl,
177 .ndo_get_stats = mac_stats,
178 .ndo_set_rx_mode = wilc_set_multicast_list,
184 extern volatile int timeNo;
186 #define DEGUG_BUFFER_LENGTH 1000
187 volatile int WatchDogdebuggerCounter;
188 char DebugBuffer[DEGUG_BUFFER_LENGTH + 20] = {0};
189 static char *ps8current = DebugBuffer;
191 void printk_later(const char *format, ...)
195 va_start(args, format);
196 ps8current += vsprintf(ps8current, format, args);
198 if ((ps8current - DebugBuffer) > DEGUG_BUFFER_LENGTH)
199 ps8current = DebugBuffer;
205 if (DebugBuffer[0]) {
206 DebugBuffer[DEGUG_BUFFER_LENGTH] = 0;
207 PRINT_INFO(GENERIC_DBG, "early printed\n");
208 PRINT_D(GENERIC_DBG, ps8current + 1);
210 PRINT_INFO(GENERIC_DBG, "latest printed\n");
211 PRINT_D(GENERIC_DBG, DebugBuffer);
213 ps8current = DebugBuffer;
217 void Reset_WatchDogdebugger(void)
219 WatchDogdebuggerCounter = 0;
222 static int DebuggingThreadTask(void *vp)
225 while (!WatchDogdebuggerCounter) {
226 PRINT_D(GENERIC_DBG, "Debug Thread Running %d\n", timeNo);
227 WatchDogdebuggerCounter = 1;
231 WatchDogdebuggerCounter = 0;
236 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
237 static int dev_state_ev_handler(struct notifier_block *this, unsigned long event, void *ptr)
239 struct in_ifaddr *dev_iface = (struct in_ifaddr *)ptr;
240 struct WILC_WFI_priv *priv;
241 tstrWILC_WFIDrv *pstrWFIDrv;
242 struct net_device *dev;
244 perInterface_wlan_t *nic;
246 char wlan_dev_name[5] = "wlan0";
248 if (dev_iface == NULL || dev_iface->ifa_dev == NULL || dev_iface->ifa_dev->dev == NULL) {
249 PRINT_D(GENERIC_DBG, "dev_iface = NULL\n");
253 if ((memcmp(dev_iface->ifa_label, "wlan0", 5)) && (memcmp(dev_iface->ifa_label, "p2p0", 4))) {
254 PRINT_D(GENERIC_DBG, "Interface is neither WLAN0 nor P2P0\n");
258 dev = (struct net_device *)dev_iface->ifa_dev->dev;
259 if (dev->ieee80211_ptr == NULL || dev->ieee80211_ptr->wiphy == NULL) {
260 PRINT_D(GENERIC_DBG, "No Wireless registerd\n");
263 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
265 PRINT_D(GENERIC_DBG, "No Wireless Priv\n");
268 pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
269 nic = netdev_priv(dev);
270 if (nic == NULL || pstrWFIDrv == NULL) {
271 PRINT_D(GENERIC_DBG, "No Wireless Priv\n");
275 PRINT_INFO(GENERIC_DBG, "dev_state_ev_handler +++\n"); /* tony */
279 PRINT_D(GENERIC_DBG, "dev_state_ev_handler event=NETDEV_UP %p\n", dev); /* tony */
281 PRINT_INFO(GENERIC_DBG, "\n ============== IP Address Obtained ===============\n\n");
283 /*If we are in station mode or client mode*/
284 if (nic->iftype == STATION_MODE || nic->iftype == CLIENT_MODE) {
285 pstrWFIDrv->IFC_UP = 1;
286 g_obtainingIP = false;
287 del_timer(&hDuringIpTimer);
288 PRINT_D(GENERIC_DBG, "IP obtained , enable scan\n");
292 host_int_set_power_mgmt(pstrWFIDrv, 1, 0);
294 PRINT_D(GENERIC_DBG, "[%s] Up IP\n", dev_iface->ifa_label);
296 pIP_Add_buff = (char *) (&(dev_iface->ifa_address));
297 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]);
298 host_int_setup_ipaddress(pstrWFIDrv, pIP_Add_buff, nic->u8IfIdx);
303 PRINT_D(GENERIC_DBG, "dev_state_ev_handler event=NETDEV_DOWN %p\n", dev); /* tony */
305 PRINT_INFO(GENERIC_DBG, "\n ============== IP Address Released ===============\n\n");
306 if (nic->iftype == STATION_MODE || nic->iftype == CLIENT_MODE) {
307 pstrWFIDrv->IFC_UP = 0;
308 g_obtainingIP = false;
311 if (memcmp(dev_iface->ifa_label, wlan_dev_name, 5) == 0)
312 host_int_set_power_mgmt(pstrWFIDrv, 0, 0);
314 resolve_disconnect_aberration(pstrWFIDrv);
316 PRINT_D(GENERIC_DBG, "[%s] Down IP\n", dev_iface->ifa_label);
318 pIP_Add_buff = null_ip;
319 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]);
321 host_int_setup_ipaddress(pstrWFIDrv, pIP_Add_buff, nic->u8IfIdx);
326 PRINT_INFO(GENERIC_DBG, "dev_state_ev_handler event=default\n"); /* tony */
327 PRINT_INFO(GENERIC_DBG, "[%s] unknown dev event: %lu\n", dev_iface->ifa_label, event);
338 * Interrupt initialization and handling functions
341 void linux_wlan_enable_irq(void)
344 #if (RX_BH_TYPE != RX_BH_THREADED_IRQ)
345 #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
346 PRINT_D(INT_DBG, "Enabling IRQ ...\n");
347 enable_irq(g_linux_wlan->dev_irq_num);
352 void linux_wlan_disable_irq(int wait)
354 #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
356 PRINT_D(INT_DBG, "Disabling IRQ ...\n");
357 disable_irq(g_linux_wlan->dev_irq_num);
359 PRINT_D(INT_DBG, "Disabling IRQ ...\n");
360 disable_irq_nosync(g_linux_wlan->dev_irq_num);
365 #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
366 static irqreturn_t isr_uh_routine(int irq, void *user_data)
369 #if (RX_BH_TYPE != RX_BH_THREADED_IRQ)
370 linux_wlan_disable_irq(IRQ_NO_WAIT);
372 PRINT_D(INT_DBG, "Interrupt received UH\n");
374 /*While mac is closing cacncel the handling of any interrupts received*/
375 if (g_linux_wlan->close) {
376 PRINT_ER("Driver is CLOSING: Can't handle UH interrupt\n");
377 #if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
384 #if (RX_BH_TYPE == RX_BH_WORK_QUEUE)
385 schedule_work(&g_linux_wlan->rx_work_queue);
387 #elif (RX_BH_TYPE == RX_BH_KTHREAD)
388 up(&g_linux_wlan->rx_sem);
390 #elif (RX_BH_TYPE == RX_BH_THREADED_IRQ)
391 return IRQ_WAKE_THREAD;
397 #if (RX_BH_TYPE == RX_BH_WORK_QUEUE || RX_BH_TYPE == RX_BH_THREADED_IRQ)
399 #if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
400 irqreturn_t isr_bh_routine(int irq, void *userdata)
404 nic = (linux_wlan_t *)userdata;
406 static void isr_bh_routine(struct work_struct *work)
408 perInterface_wlan_t *nic;
410 nic = (perInterface_wlan_t *)container_of(work, linux_wlan_t, rx_work_queue);
413 /*While mac is closing cacncel the handling of any interrupts received*/
414 if (g_linux_wlan->close) {
415 PRINT_ER("Driver is CLOSING: Can't handle BH interrupt\n");
416 #if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
424 PRINT_D(INT_DBG, "Interrupt received BH\n");
425 if (g_linux_wlan->oup.wlan_handle_rx_isr != 0)
426 g_linux_wlan->oup.wlan_handle_rx_isr();
428 PRINT_ER("wlan_handle_rx_isr() hasn't been initialized\n");
430 #if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
434 #elif (RX_BH_TYPE == RX_BH_KTHREAD)
435 static int isr_bh_routine(void *vp)
439 nic = (linux_wlan_t *)vp;
443 if (g_linux_wlan->close) {
445 while (!kthread_should_stop())
451 PRINT_D(INT_DBG, "Interrupt received BH\n");
452 if (g_linux_wlan->oup.wlan_handle_rx_isr != 0)
453 g_linux_wlan->oup.wlan_handle_rx_isr();
455 PRINT_ER("wlan_handle_rx_isr() hasn't been initialized\n");
462 #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
463 static int init_irq(linux_wlan_t *p_nic)
466 linux_wlan_t *nic = p_nic;
468 /*initialize GPIO and register IRQ num*/
470 if ((gpio_request(GPIO_NUM, "WILC_INTR") == 0) &&
471 (gpio_direction_input(GPIO_NUM) == 0)) {
472 #if defined(CUSTOMER_PLATFORM)
474 TODO : save the registerd irq number to the private wilc context in kernel.
476 * ex) nic->dev_irq_num = gpio_to_irq(GPIO_NUM);
478 #elif defined(NM73131_0_BOARD)
479 nic->dev_irq_num = IRQ_WILC1000;
480 #elif defined(PANDA_BOARD)
481 gpio_export(GPIO_NUM, 1);
482 nic->dev_irq_num = OMAP_GPIO_IRQ(GPIO_NUM);
483 irq_set_irq_type(nic->dev_irq_num, IRQ_TYPE_LEVEL_LOW);
485 nic->dev_irq_num = gpio_to_irq(GPIO_NUM);
489 PRINT_ER("could not obtain gpio for WILC_INTR\n");
492 #if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
493 if ((ret != -1) && (request_threaded_irq(nic->dev_irq_num, isr_uh_routine, isr_bh_routine,
494 IRQF_TRIGGER_LOW | IRQF_ONESHOT, /*Without IRQF_ONESHOT the uh will remain kicked in and dont gave a chance to bh*/
495 "WILC_IRQ", nic)) < 0) {
499 if ((ret != -1) && (request_irq(nic->dev_irq_num, isr_uh_routine,
500 IRQF_TRIGGER_LOW, "WILC_IRQ", nic) < 0)) {
503 PRINT_ER("Failed to request IRQ for GPIO: %d\n", GPIO_NUM);
507 PRINT_D(INIT_DBG, "IRQ request succeeded IRQ-NUM= %d on GPIO: %d\n",
508 nic->dev_irq_num, GPIO_NUM);
515 static void deinit_irq(linux_wlan_t *nic)
517 #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
518 /* Deintialize IRQ */
519 if (&nic->dev_irq_num != 0) {
520 free_irq(nic->dev_irq_num, g_linux_wlan);
530 static void linux_wlan_msleep(uint32_t msc)
532 if (msc <= 4000000) {
533 u32 u32Temp = msc * 1000;
535 usleep_range(u32Temp, u32Temp);
541 static void linux_wlan_dbg(uint8_t *buff)
543 PRINT_D(INIT_DBG, "%d\n", *buff);
546 static int linux_wlan_lock_timeout(void *vp, u32 timeout)
550 PRINT_D(LOCK_DBG, "Locking %p\n", vp);
552 error = down_timeout((struct semaphore *)vp, msecs_to_jiffies(timeout));
554 PRINT_ER("Failed, mutex is NULL\n");
558 static void linux_wlan_mac_indicate(int flag)
560 /*I have to do it that way becuase there is no mean to encapsulate device pointer
563 linux_wlan_t *pd = g_linux_wlan;
566 if (flag == WILC_MAC_INDICATE_STATUS) {
567 pd->oup.wlan_cfg_get_value(WID_STATUS, (unsigned char *)&status, 4);
568 if (pd->mac_status == WILC_MAC_STATUS_INIT) {
569 pd->mac_status = status;
572 pd->mac_status = status;
575 if (pd->mac_status == WILC_MAC_STATUS_CONNECT) { /* Connect */
578 } else if (flag == WILC_MAC_INDICATE_SCAN) {
579 PRINT_D(GENERIC_DBG, "Scanning ...\n");
585 struct net_device *GetIfHandler(uint8_t *pMacHeader)
587 uint8_t *Bssid, *Bssid1;
590 Bssid = pMacHeader + 10;
591 Bssid1 = pMacHeader + 4;
593 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
594 if (!memcmp(Bssid1, g_linux_wlan->strInterfaceInfo[i].aBSSID, ETH_ALEN) ||
595 !memcmp(Bssid, g_linux_wlan->strInterfaceInfo[i].aBSSID, ETH_ALEN)) {
596 return g_linux_wlan->strInterfaceInfo[i].wilc_netdev;
599 PRINT_INFO(INIT_DBG, "Invalide handle\n");
600 for (i = 0; i < 25; i++)
601 PRINT_D(INIT_DBG, "%02x ", pMacHeader[i]);
602 Bssid = pMacHeader + 18;
603 Bssid1 = pMacHeader + 12;
604 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
605 if (!memcmp(Bssid1, g_linux_wlan->strInterfaceInfo[i].aBSSID, ETH_ALEN) ||
606 !memcmp(Bssid, g_linux_wlan->strInterfaceInfo[i].aBSSID, ETH_ALEN)) {
607 PRINT_D(INIT_DBG, "Ctx [%p]\n", g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
608 return g_linux_wlan->strInterfaceInfo[i].wilc_netdev;
611 PRINT_INFO(INIT_DBG, "\n");
615 int linux_wlan_set_bssid(struct net_device *wilc_netdev, uint8_t *pBSSID)
620 PRINT_D(INIT_DBG, "set bssid on[%p]\n", wilc_netdev);
621 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
622 if (g_linux_wlan->strInterfaceInfo[i].wilc_netdev == wilc_netdev) {
623 PRINT_D(INIT_DBG, "set bssid [%x][%x][%x]\n", pBSSID[0], pBSSID[1], pBSSID[2]);
624 memcpy(g_linux_wlan->strInterfaceInfo[i].aBSSID, pBSSID, 6);
633 /*Function to get number of connected interfaces*/
634 int linux_wlan_get_num_conn_ifcs(void)
637 uint8_t null_bssid[6] = {0};
640 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
641 if (memcmp(g_linux_wlan->strInterfaceInfo[i].aBSSID, null_bssid, 6))
647 static int linux_wlan_rxq_task(void *vp)
650 /* inform wilc1000_wlan_init that RXQ task is started. */
651 up(&g_linux_wlan->rxq_thread_started);
653 down(&g_linux_wlan->rxq_event);
654 /* wait_for_completion(&g_linux_wlan->rxq_event); */
656 if (g_linux_wlan->close) {
657 /*Unlock the mutex in the mac_close function to indicate the exiting of the RX thread */
658 up(&g_linux_wlan->rxq_thread_started);
660 while (!kthread_should_stop())
663 PRINT_D(RX_DBG, " RX thread stopped\n");
666 PRINT_D(RX_DBG, "Calling wlan_handle_rx_que()\n");
668 g_linux_wlan->oup.wlan_handle_rx_que();
673 #define USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
675 static int linux_wlan_txq_task(void *vp)
679 #if defined USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
680 #define TX_BACKOFF_WEIGHT_INCR_STEP (1)
681 #define TX_BACKOFF_WEIGHT_DECR_STEP (1)
682 #define TX_BACKOFF_WEIGHT_MAX (7)
683 #define TX_BACKOFF_WEIGHT_MIN (0)
684 #define TX_BACKOFF_WEIGHT_UNIT_MS (10)
685 int backoff_weight = TX_BACKOFF_WEIGHT_MIN;
688 /* inform wilc1000_wlan_init that TXQ task is started. */
689 up(&g_linux_wlan->txq_thread_started);
692 PRINT_D(TX_DBG, "txq_task Taking a nap :)\n");
693 down(&g_linux_wlan->txq_event);
694 /* wait_for_completion(&pd->txq_event); */
695 PRINT_D(TX_DBG, "txq_task Who waked me up :$\n");
697 if (g_linux_wlan->close) {
698 /*Unlock the mutex in the mac_close function to indicate the exiting of the TX thread */
699 up(&g_linux_wlan->txq_thread_started);
701 while (!kthread_should_stop())
704 PRINT_D(TX_DBG, "TX thread stopped\n");
707 PRINT_D(TX_DBG, "txq_task handle the sending packet and let me go to sleep.\n");
708 #if !defined USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
709 g_linux_wlan->oup.wlan_handle_tx_que();
712 ret = g_linux_wlan->oup.wlan_handle_tx_que(&txq_count);
713 if (txq_count < FLOW_CONTROL_LOWER_THRESHOLD /* && netif_queue_stopped(pd->wilc_netdev)*/) {
714 PRINT_D(TX_DBG, "Waking up queue\n");
715 /* netif_wake_queue(pd->wilc_netdev); */
716 if (netif_queue_stopped(g_linux_wlan->strInterfaceInfo[0].wilc_netdev))
717 netif_wake_queue(g_linux_wlan->strInterfaceInfo[0].wilc_netdev);
718 if (netif_queue_stopped(g_linux_wlan->strInterfaceInfo[1].wilc_netdev))
719 netif_wake_queue(g_linux_wlan->strInterfaceInfo[1].wilc_netdev);
722 if (ret == WILC_TX_ERR_NO_BUF) { /* failed to allocate buffers in chip. */
724 /* Back off from sending packets for some time. */
725 /* schedule_timeout will allow RX task to run and free buffers.*/
726 /* set_current_state(TASK_UNINTERRUPTIBLE); */
727 /* timeout = schedule_timeout(timeout); */
728 msleep(TX_BACKOFF_WEIGHT_UNIT_MS << backoff_weight);
729 } while (/*timeout*/ 0);
730 backoff_weight += TX_BACKOFF_WEIGHT_INCR_STEP;
731 if (backoff_weight > TX_BACKOFF_WEIGHT_MAX)
732 backoff_weight = TX_BACKOFF_WEIGHT_MAX;
734 if (backoff_weight > TX_BACKOFF_WEIGHT_MIN) {
735 backoff_weight -= TX_BACKOFF_WEIGHT_DECR_STEP;
736 if (backoff_weight < TX_BACKOFF_WEIGHT_MIN)
737 backoff_weight = TX_BACKOFF_WEIGHT_MIN;
740 /*TODO: drop packets after a certain time/number of retry count. */
741 } while (ret == WILC_TX_ERR_NO_BUF && !g_linux_wlan->close); /* retry sending packets if no more buffers in chip. */
747 static void linux_wlan_rx_complete(void)
749 PRINT_D(RX_DBG, "RX completed\n");
752 int linux_wlan_get_firmware(perInterface_wlan_t *p_nic)
755 perInterface_wlan_t *nic = p_nic;
757 const struct firmware *wilc_firmware;
760 if (nic->iftype == AP_MODE)
761 firmware = AP_FIRMWARE;
762 else if (nic->iftype == STATION_MODE)
763 firmware = STA_FIRMWARE;
767 PRINT_D(INIT_DBG, "Get P2P_CONCURRENCY_FIRMWARE\n");
768 firmware = P2P_CONCURRENCY_FIRMWARE;
772 PRINT_ER("NIC is NULL\n");
776 if (&nic->wilc_netdev->dev == NULL) {
777 PRINT_ER("&nic->wilc_netdev->dev is NULL\n");
781 /* the firmare should be located in /lib/firmware in
782 * root file system with the name specified above */
785 if (request_firmware(&wilc_firmware, firmware, &g_linux_wlan->wilc_sdio_func->dev) != 0) {
786 PRINT_ER("%s - firmare not available\n", firmware);
791 if (request_firmware(&wilc_firmware, firmware, &g_linux_wlan->wilc_spidev->dev) != 0) {
792 PRINT_ER("%s - firmare not available\n", firmware);
797 g_linux_wlan->wilc_firmware = wilc_firmware; /* Bug 4703 */
805 #ifdef COMPLEMENT_BOOT
806 int repeat_power_cycle(perInterface_wlan_t *nic);
809 static int linux_wlan_start_firmware(perInterface_wlan_t *nic)
814 PRINT_D(INIT_DBG, "Starting Firmware ...\n");
815 ret = g_linux_wlan->oup.wlan_start();
817 PRINT_ER("Failed to start Firmware\n");
821 /* wait for mac ready */
822 PRINT_D(INIT_DBG, "Waiting for Firmware to get ready ...\n");
823 ret = linux_wlan_lock_timeout(&g_linux_wlan->sync_event, 5000);
825 #ifdef COMPLEMENT_BOOT
826 static int timeout = 5;
829 PRINT_D(INIT_DBG, "repeat power cycle[%d]", timeout);
830 ret = repeat_power_cycle(nic);
837 PRINT_D(INIT_DBG, "Firmware start timed out");
841 * TODO: Driver shouoldn't wait forever for firmware to get started -
842 * in case of timeout this should be handled properly
844 PRINT_D(INIT_DBG, "Firmware successfully started\n");
849 static int linux_wlan_firmware_download(linux_wlan_t *p_nic)
854 if (g_linux_wlan->wilc_firmware == NULL) {
855 PRINT_ER("Firmware buffer is NULL\n");
860 * do the firmware download
862 PRINT_D(INIT_DBG, "Downloading Firmware ...\n");
863 ret = g_linux_wlan->oup.wlan_firmware_download(g_linux_wlan->wilc_firmware->data, g_linux_wlan->wilc_firmware->size);
867 /* Freeing FW buffer */
868 PRINT_D(INIT_DBG, "Freeing FW buffer ...\n");
869 PRINT_D(INIT_DBG, "Releasing firmware\n");
870 release_firmware(g_linux_wlan->wilc_firmware);
871 g_linux_wlan->wilc_firmware = NULL;
873 PRINT_D(INIT_DBG, "Download Succeeded\n");
879 /* startup configuration - could be changed later using iconfig*/
880 static int linux_wlan_init_test_config(struct net_device *dev, linux_wlan_t *p_nic)
883 unsigned char c_val[64];
884 #ifndef STATIC_MACADDRESS
885 unsigned char mac_add[] = {0x00, 0x80, 0xC2, 0x5E, 0xa2, 0xff};
889 struct WILC_WFI_priv *priv;
890 tstrWILC_WFIDrv *pstrWFIDrv;
892 PRINT_D(TX_DBG, "Start configuring Firmware\n");
893 #ifndef STATIC_MACADDRESS
894 get_random_bytes(&mac_add[5], 1);
895 get_random_bytes(&mac_add[4], 1);
897 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
898 pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
899 PRINT_D(INIT_DBG, "Host = %p\n", pstrWFIDrv);
901 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]);
904 if (g_linux_wlan->oup.wlan_cfg_set == NULL) {
905 PRINT_D(INIT_DBG, "Null p[ointer\n");
911 if (!g_linux_wlan->oup.wlan_cfg_set(1, WID_SET_DRV_HANDLER, c_val, 4, 0, 0))
914 /*to tell fw that we are going to use PC test - WILC specific*/
916 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_PC_TEST_MODE, c_val, 1, 0, 0))
919 c_val[0] = INFRASTRUCTURE;
920 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_BSS_TYPE, c_val, 1, 0, 0))
923 /* c_val[0] = RATE_AUTO; / * bug 4275: Enable autorate and limit it to 24Mbps * / */
924 c_val[0] = RATE_AUTO;
925 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_CURRENT_TX_RATE, c_val, 1, 0, 0))
928 c_val[0] = G_MIXED_11B_2_MODE;
929 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11G_OPERATING_MODE, c_val, 1, 0, 0))
933 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_CURRENT_CHANNEL, c_val, 1, 0, 0))
936 c_val[0] = G_SHORT_PREAMBLE;
937 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_PREAMBLE, c_val, 1, 0, 0))
940 c_val[0] = AUTO_PROT;
941 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_PROT_MECH, c_val, 1, 0, 0))
944 #ifdef SWITCH_LOG_TERMINAL
945 c_val[0] = AUTO_PROT;
946 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_LOGTerminal_Switch, c_val, 1, 0, 0))
950 c_val[0] = ACTIVE_SCAN;
951 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_SCAN_TYPE, c_val, 1, 0, 0))
954 c_val[0] = SITE_SURVEY_OFF;
955 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_SITE_SURVEY, c_val, 1, 0, 0))
958 *((int *)c_val) = 0xffff; /* Never use RTS-CTS */
959 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_RTS_THRESHOLD, c_val, 2, 0, 0))
962 *((int *)c_val) = 2346;
963 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_FRAG_THRESHOLD, c_val, 2, 0, 0))
967 /* -------------------------------------------------------------- */
968 /* Configuration : String with length less than 32 bytes */
969 /* Values to set : Any string with length less than 32 bytes */
970 /* ( In BSS Station Set SSID to "" (null string) */
971 /* to enable Broadcast SSID suppport ) */
972 /* -------------------------------------------------------------- */
974 strcpy(c_val, "nwifi");
975 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_SSID, c_val, (strlen(c_val) + 1), 0, 0))
980 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_BCAST_SSID, c_val, 1, 0, 0))
984 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_QOS_ENABLE, c_val, 1, 0, 0))
987 c_val[0] = NO_POWERSAVE;
988 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_POWER_MANAGEMENT, c_val, 1, 0, 0))
991 c_val[0] = NO_ENCRYPT; /* NO_ENCRYPT, 0x79 */
992 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11I_MODE, c_val, 1, 0, 0))
995 c_val[0] = OPEN_SYSTEM;
996 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_AUTH_TYPE, c_val, 1, 0, 0))
999 /* WEP/802 11I Configuration */
1000 /* ------------------------------------------------------------------ */
1001 /* Configuration : WEP Key */
1002 /* Values (0x) : 5 byte for WEP40 and 13 bytes for WEP104 */
1003 /* In case more than 5 bytes are passed on for WEP 40 */
1004 /* only first 5 bytes will be used as the key */
1005 /* ------------------------------------------------------------------ */
1007 strcpy(c_val, "123456790abcdef1234567890");
1008 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_WEP_KEY_VALUE, c_val, (strlen(c_val) + 1), 0, 0))
1011 /* WEP/802 11I Configuration */
1012 /* ------------------------------------------------------------------ */
1013 /* Configuration : AES/TKIP WPA/RSNA Pre-Shared Key */
1014 /* Values to set : Any string with length greater than equal to 8 bytes */
1015 /* and less than 64 bytes */
1016 /* ------------------------------------------------------------------ */
1017 strcpy(c_val, "12345678");
1018 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11I_PSK, c_val, (strlen(c_val)), 0, 0))
1021 /* IEEE802.1X Key Configuration */
1022 /* ------------------------------------------------------------------ */
1023 /* Configuration : Radius Server Access Secret Key */
1024 /* Values to set : Any string with length greater than equal to 8 bytes */
1025 /* and less than 65 bytes */
1026 /* ------------------------------------------------------------------ */
1027 strcpy(c_val, "password");
1028 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_1X_KEY, c_val, (strlen(c_val) + 1), 0, 0))
1031 /* IEEE802.1X Server Address Configuration */
1032 /* ------------------------------------------------------------------ */
1033 /* Configuration : Radius Server IP Address */
1034 /* Values to set : Any valid IP Address */
1035 /* ------------------------------------------------------------------ */
1040 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_1X_SERV_ADDR, c_val, 4, 0, 0))
1044 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_LISTEN_INTERVAL, c_val, 1, 0, 0))
1048 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_DTIM_PERIOD, c_val, 1, 0, 0))
1051 c_val[0] = NORMAL_ACK;
1052 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_ACK_POLICY, c_val, 1, 0, 0))
1056 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_USER_CONTROL_ON_TX_POWER, c_val, 1, 0, 0))
1060 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_TX_POWER_LEVEL_11A, c_val, 1, 0, 0))
1064 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_TX_POWER_LEVEL_11B, c_val, 1, 0, 0))
1067 /* Beacon Interval */
1068 /* -------------------------------------------------------------------- */
1069 /* Configuration : Sets the beacon interval value */
1070 /* Values to set : Any 16-bit value */
1071 /* -------------------------------------------------------------------- */
1073 *((int *)c_val) = 100;
1074 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_BEACON_INTERVAL, c_val, 2, 0, 0))
1077 c_val[0] = REKEY_DISABLE;
1078 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_REKEY_POLICY, c_val, 1, 0, 0))
1081 /* Rekey Time (s) (Used only when the Rekey policy is 2 or 4) */
1082 /* -------------------------------------------------------------------- */
1083 /* Configuration : Sets the Rekey Time (s) */
1084 /* Values to set : 32-bit value */
1085 /* -------------------------------------------------------------------- */
1086 *((int *)c_val) = 84600;
1087 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_REKEY_PERIOD, c_val, 4, 0, 0))
1090 /* Rekey Packet Count (in 1000s; used when Rekey Policy is 3) */
1091 /* -------------------------------------------------------------------- */
1092 /* Configuration : Sets Rekey Group Packet count */
1093 /* Values to set : 32-bit Value */
1094 /* -------------------------------------------------------------------- */
1095 *((int *)c_val) = 500;
1096 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_REKEY_PACKET_COUNT, c_val, 4, 0, 0))
1100 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_SHORT_SLOT_ALLOWED, c_val, 1, 0, 0))
1103 c_val[0] = G_SELF_CTS_PROT;
1104 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_ERP_PROT_TYPE, c_val, 1, 0, 0))
1107 c_val[0] = 1; /* Enable N */
1108 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_ENABLE, c_val, 1, 0, 0))
1111 c_val[0] = HT_MIXED_MODE;
1112 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_OPERATING_MODE, c_val, 1, 0, 0))
1115 c_val[0] = 1; /* TXOP Prot disable in N mode: No RTS-CTS on TX A-MPDUs to save air-time. */
1116 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_TXOP_PROT_DISABLE, c_val, 1, 0, 0))
1119 memcpy(c_val, mac_add, 6);
1121 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_MAC_ADDR, c_val, 6, 0, 0))
1127 c_val[0] = DETECT_PROTECT_REPORT;
1128 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_OBSS_NONHT_DETECTION, c_val, 1, 0, 0))
1131 c_val[0] = RTS_CTS_NONHT_PROT;
1132 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_HT_PROT_TYPE, c_val, 1, 0, 0))
1136 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_RIFS_PROT_ENABLE, c_val, 1, 0, 0))
1139 c_val[0] = MIMO_MODE;
1140 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_SMPS_MODE, c_val, 1, 0, 0))
1144 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_CURRENT_TX_MCS, c_val, 1, 0, 0))
1147 c_val[0] = 1; /* Enable N with immediate block ack. */
1148 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_IMMEDIATE_BA_ENABLED, c_val, 1, 1, 1))
1157 /**************************/
1158 void wilc1000_wlan_deinit(linux_wlan_t *nic)
1161 if (g_linux_wlan->wilc1000_initialized) {
1163 printk("Deinitializing wilc1000 ...\n");
1166 PRINT_ER("nic is NULL\n");
1170 #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
1171 /* johnny : remove */
1172 PRINT_D(INIT_DBG, "skip wilc_bus_set_default_speed\n");
1174 wilc_bus_set_default_speed();
1177 PRINT_D(INIT_DBG, "Disabling IRQ\n");
1178 #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
1179 linux_wlan_disable_irq(IRQ_WAIT);
1181 #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
1184 mutex_lock(&g_linux_wlan->hif_cs);
1185 disable_sdio_interrupt();
1186 mutex_unlock(&g_linux_wlan->hif_cs);
1190 /* not sure if the following unlocks are needed or not*/
1191 if (&g_linux_wlan->rxq_event != NULL)
1192 up(&g_linux_wlan->rxq_event);
1194 if (&g_linux_wlan->txq_event != NULL)
1195 up(&g_linux_wlan->txq_event);
1197 #if (RX_BH_TYPE == RX_BH_WORK_QUEUE)
1198 /*Removing the work struct from the linux kernel workqueue*/
1199 if (&g_linux_wlan->rx_work_queue != NULL)
1200 flush_work(&g_linux_wlan->rx_work_queue);
1202 #elif (RX_BH_TYPE == RX_BH_KTHREAD)
1203 /* if(&nic->rx_sem != NULL) */
1204 /* up(&nic->rx_sem); */
1207 PRINT_D(INIT_DBG, "Deinitializing Threads\n");
1208 wlan_deinitialize_threads(nic);
1210 PRINT_D(INIT_DBG, "Deinitializing IRQ\n");
1211 deinit_irq(g_linux_wlan);
1213 if (&g_linux_wlan->oup != NULL) {
1214 if (g_linux_wlan->oup.wlan_stop != NULL)
1215 g_linux_wlan->oup.wlan_stop();
1218 PRINT_D(INIT_DBG, "Deinitializing WILC Wlan\n");
1219 wilc_wlan_deinit(nic);
1220 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
1221 #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
1222 PRINT_D(INIT_DBG, "Disabling IRQ 2\n");
1224 mutex_lock(&g_linux_wlan->hif_cs);
1225 disable_sdio_interrupt();
1226 mutex_unlock(&g_linux_wlan->hif_cs);
1230 /*De-Initialize locks*/
1231 PRINT_D(INIT_DBG, "Deinitializing Locks\n");
1232 wlan_deinit_locks(g_linux_wlan);
1234 /* announce that wilc1000 is not initialized */
1235 g_linux_wlan->wilc1000_initialized = 0;
1237 PRINT_D(INIT_DBG, "wilc1000 deinitialization Done\n");
1240 PRINT_D(INIT_DBG, "wilc1000 is not initialized\n");
1244 int wlan_init_locks(linux_wlan_t *p_nic)
1247 PRINT_D(INIT_DBG, "Initializing Locks ...\n");
1249 mutex_init(&g_linux_wlan->hif_cs);
1250 mutex_init(&g_linux_wlan->rxq_cs);
1251 mutex_init(&g_linux_wlan->txq_cs);
1253 /*Added by Amr - BugID_4720*/
1254 spin_lock_init(&g_linux_wlan->txq_spinlock);
1255 sema_init(&g_linux_wlan->txq_add_to_head_cs, 1);
1257 sema_init(&g_linux_wlan->txq_event, 0);
1258 sema_init(&g_linux_wlan->rxq_event, 0);
1260 sema_init(&g_linux_wlan->cfg_event, 0);
1261 sema_init(&g_linux_wlan->sync_event, 0);
1263 sema_init(&g_linux_wlan->rxq_thread_started, 0);
1264 sema_init(&g_linux_wlan->txq_thread_started, 0);
1266 #if (RX_BH_TYPE == RX_BH_KTHREAD)
1267 sema_init(&g_linux_wlan->rx_sem, 0);
1273 static int wlan_deinit_locks(linux_wlan_t *nic)
1275 PRINT_D(INIT_DBG, "De-Initializing Locks\n");
1277 if (&g_linux_wlan->hif_cs != NULL)
1278 mutex_destroy(&g_linux_wlan->hif_cs);
1280 if (&g_linux_wlan->rxq_cs != NULL)
1281 mutex_destroy(&g_linux_wlan->rxq_cs);
1283 if (&g_linux_wlan->txq_cs != NULL)
1284 mutex_destroy(&g_linux_wlan->txq_cs);
1288 void linux_to_wlan(wilc_wlan_inp_t *nwi, linux_wlan_t *nic)
1291 PRINT_D(INIT_DBG, "Linux to Wlan services ...\n");
1293 nwi->os_context.hif_critical_section = (void *)&g_linux_wlan->hif_cs;
1294 nwi->os_context.os_private = (void *)nic;
1295 nwi->os_context.tx_buffer_size = LINUX_TX_SIZE;
1296 nwi->os_context.txq_critical_section = (void *)&g_linux_wlan->txq_cs;
1298 /*Added by Amr - BugID_4720*/
1299 nwi->os_context.txq_add_to_head_critical_section = (void *)&g_linux_wlan->txq_add_to_head_cs;
1301 /*Added by Amr - BugID_4720*/
1302 nwi->os_context.txq_spin_lock = (void *)&g_linux_wlan->txq_spinlock;
1304 nwi->os_context.txq_wait_event = (void *)&g_linux_wlan->txq_event;
1306 #if defined(MEMORY_STATIC)
1307 nwi->os_context.rx_buffer_size = LINUX_RX_SIZE;
1309 nwi->os_context.rxq_critical_section = (void *)&g_linux_wlan->rxq_cs;
1310 nwi->os_context.rxq_wait_event = (void *)&g_linux_wlan->rxq_event;
1311 nwi->os_context.cfg_wait_event = (void *)&g_linux_wlan->cfg_event;
1313 nwi->os_func.os_sleep = linux_wlan_msleep;
1314 nwi->os_func.os_debug = linux_wlan_dbg;
1315 nwi->os_func.os_wait = linux_wlan_lock_timeout;
1318 nwi->io_func.io_type = HIF_SDIO;
1319 nwi->io_func.io_init = linux_sdio_init;
1320 nwi->io_func.io_deinit = linux_sdio_deinit;
1321 nwi->io_func.u.sdio.sdio_cmd52 = linux_sdio_cmd52;
1322 nwi->io_func.u.sdio.sdio_cmd53 = linux_sdio_cmd53;
1323 nwi->io_func.u.sdio.sdio_set_max_speed = linux_sdio_set_max_speed;
1324 nwi->io_func.u.sdio.sdio_set_default_speed = linux_sdio_set_default_speed;
1326 nwi->io_func.io_type = HIF_SPI;
1327 nwi->io_func.io_init = linux_spi_init;
1328 nwi->io_func.io_deinit = linux_spi_deinit;
1329 nwi->io_func.u.spi.spi_tx = linux_spi_write;
1330 nwi->io_func.u.spi.spi_rx = linux_spi_read;
1331 nwi->io_func.u.spi.spi_trx = linux_spi_write_read;
1332 nwi->io_func.u.spi.spi_max_speed = linux_spi_set_max_speed;
1335 /*for now - to be revised*/
1336 #ifdef WILC_FULLY_HOSTING_AP
1337 /* incase of Fully hosted AP, all non cfg pkts are processed here*/
1338 nwi->net_func.rx_indicate = WILC_Process_rx_frame;
1340 nwi->net_func.rx_indicate = frmw_to_linux;
1342 nwi->net_func.rx_complete = linux_wlan_rx_complete;
1343 nwi->indicate_func.mac_indicate = linux_wlan_mac_indicate;
1346 int wlan_initialize_threads(perInterface_wlan_t *nic)
1351 PRINT_D(INIT_DBG, "Initializing Threads ...\n");
1353 #if (RX_BH_TYPE == RX_BH_WORK_QUEUE)
1354 /*Initialize rx work queue task*/
1355 INIT_WORK(&g_linux_wlan->rx_work_queue, isr_bh_routine);
1356 #elif (RX_BH_TYPE == RX_BH_KTHREAD)
1357 PRINT_D(INIT_DBG, "Creating kthread for Rxq BH\n");
1358 g_linux_wlan->rx_bh_thread = kthread_run(isr_bh_routine, (void *)g_linux_wlan, "K_RXQ_BH");
1359 if (g_linux_wlan->rx_bh_thread == 0) {
1360 PRINT_ER("couldn't create RX BH thread\n");
1366 #ifndef TCP_ENHANCEMENTS
1367 /* create rx task */
1368 PRINT_D(INIT_DBG, "Creating kthread for reception\n");
1369 g_linux_wlan->rxq_thread = kthread_run(linux_wlan_rxq_task, (void *)g_linux_wlan, "K_RXQ_TASK");
1370 if (g_linux_wlan->rxq_thread == 0) {
1371 PRINT_ER("couldn't create RXQ thread\n");
1376 /* wait for RXQ task to start. */
1377 down(&g_linux_wlan->rxq_thread_started);
1381 /* create tx task */
1382 PRINT_D(INIT_DBG, "Creating kthread for transmission\n");
1383 g_linux_wlan->txq_thread = kthread_run(linux_wlan_txq_task, (void *)g_linux_wlan, "K_TXQ_TASK");
1384 if (g_linux_wlan->txq_thread == 0) {
1385 PRINT_ER("couldn't create TXQ thread\n");
1390 PRINT_D(INIT_DBG, "Creating kthread for Debugging\n");
1391 g_linux_wlan->txq_thread = kthread_run(DebuggingThreadTask, (void *)g_linux_wlan, "DebugThread");
1392 if (g_linux_wlan->txq_thread == 0) {
1393 PRINT_ER("couldn't create TXQ thread\n");
1398 /* wait for TXQ task to start. */
1399 down(&g_linux_wlan->txq_thread_started);
1404 /*De-Initialize 2nd thread*/
1405 g_linux_wlan->close = 1;
1406 up(&g_linux_wlan->rxq_event);
1407 kthread_stop(g_linux_wlan->rxq_thread);
1409 #ifndef TCP_ENHANCEMENTS
1412 #if (RX_BH_TYPE == RX_BH_KTHREAD)
1413 /*De-Initialize 1st thread*/
1414 g_linux_wlan->close = 1;
1415 up(&g_linux_wlan->rx_sem);
1416 kthread_stop(g_linux_wlan->rx_bh_thread);
1419 g_linux_wlan->close = 0;
1423 static void wlan_deinitialize_threads(linux_wlan_t *nic)
1426 g_linux_wlan->close = 1;
1427 PRINT_D(INIT_DBG, "Deinitializing Threads\n");
1428 if (&g_linux_wlan->rxq_event != NULL)
1429 up(&g_linux_wlan->rxq_event);
1431 if (g_linux_wlan->rxq_thread != NULL) {
1432 kthread_stop(g_linux_wlan->rxq_thread);
1433 g_linux_wlan->rxq_thread = NULL;
1436 if (&g_linux_wlan->txq_event != NULL)
1437 up(&g_linux_wlan->txq_event);
1439 if (g_linux_wlan->txq_thread != NULL) {
1440 kthread_stop(g_linux_wlan->txq_thread);
1441 g_linux_wlan->txq_thread = NULL;
1444 #if (RX_BH_TYPE == RX_BH_KTHREAD)
1445 if (&g_linux_wlan->rx_sem != NULL)
1446 up(&g_linux_wlan->rx_sem);
1448 if (g_linux_wlan->rx_bh_thread != NULL) {
1449 kthread_stop(g_linux_wlan->rx_bh_thread);
1450 g_linux_wlan->rx_bh_thread = NULL;
1455 #ifdef STATIC_MACADDRESS
1456 const char *path_string[] = {
1461 static int linux_wlan_read_mac_addr(void *vp)
1464 struct file *fp = (struct file *)-ENOENT;
1465 mm_segment_t old_fs;
1468 int array_size = ARRAY_SIZE(path_string);
1470 /* change to KERNEL_DS address limit */
1474 for (index = 0; index < array_size; index++) {
1475 fp = filp_open(path_string[index], O_WRONLY, 0640);
1481 /*No such file or directory */
1482 if (IS_ERR(fp) || !fp->f_op) {
1483 get_random_bytes(&mac_add[3], 3);
1484 /* open file to write */
1485 fp = filp_open(path_string[index], O_WRONLY | O_CREAT, 0640);
1487 if (!fp || IS_ERR(fp)) {
1491 /* write buf to file */
1492 fp->f_op->write(fp, mac_add, 6, &pos);
1496 /* read file to buf */
1497 fp->f_op->read(fp, mac_add, 6, &pos);
1502 if (index == array_size)
1503 PRINT_ER("random MAC\n");
1506 if (fp && !IS_ERR(fp))
1507 filp_close(fp, NULL);
1515 #ifdef COMPLEMENT_BOOT
1517 extern volatile int probe;
1518 extern uint8_t core_11b_ready(void);
1520 #define READY_CHECK_THRESHOLD 30
1521 extern void wilc_wlan_global_reset(void);
1522 uint8_t wilc1000_prepare_11b_core(wilc_wlan_inp_t *nwi, wilc_wlan_oup_t *nwo, linux_wlan_t *nic)
1526 while ((core_11b_ready() && (READY_CHECK_THRESHOLD > (trials++)))) {
1527 PRINT_D(INIT_DBG, "11b core not ready yet: %u\n", trials);
1528 wilc_wlan_deinit(nic);
1529 wilc_wlan_global_reset();
1530 sdio_unregister_driver(&wilc_bus);
1532 linux_wlan_device_detection(0);
1536 linux_wlan_device_detection(1);
1538 sdio_register_driver(&wilc_bus);
1543 g_linux_wlan->wilc_sdio_func = local_sdio_func;
1544 linux_to_wlan(nwi, nic);
1545 wilc_wlan_init(nwi, nwo);
1548 if (READY_CHECK_THRESHOLD <= trials)
1555 int repeat_power_cycle(perInterface_wlan_t *nic)
1558 wilc_wlan_inp_t nwi;
1559 wilc_wlan_oup_t nwo;
1561 sdio_unregister_driver(&wilc_bus);
1563 linux_wlan_device_detection(0);
1564 linux_wlan_device_power(0);
1566 linux_wlan_device_power(1);
1568 linux_wlan_device_detection(1);
1571 sdio_register_driver(&wilc_bus);
1577 g_linux_wlan->wilc_sdio_func = local_sdio_func;
1578 linux_to_wlan(&nwi, g_linux_wlan);
1579 ret = wilc_wlan_init(&nwi, &nwo);
1581 g_linux_wlan->mac_status = WILC_MAC_STATUS_INIT;
1582 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
1583 enable_sdio_interrupt();
1586 if (linux_wlan_get_firmware(nic)) {
1587 PRINT_ER("Can't get firmware\n");
1592 /*Download firmware*/
1593 ret = linux_wlan_firmware_download(g_linux_wlan);
1595 PRINT_ER("Failed to download firmware\n");
1599 ret = linux_wlan_start_firmware(nic);
1601 PRINT_ER("Failed to start firmware\n");
1607 int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic)
1609 wilc_wlan_inp_t nwi;
1610 wilc_wlan_oup_t nwo;
1611 perInterface_wlan_t *nic = p_nic;
1614 if (!g_linux_wlan->wilc1000_initialized) {
1615 g_linux_wlan->mac_status = WILC_MAC_STATUS_INIT;
1616 g_linux_wlan->close = 0;
1617 g_linux_wlan->wilc1000_initialized = 0;
1619 wlan_init_locks(g_linux_wlan);
1621 #ifdef STATIC_MACADDRESS
1622 wilc_mac_thread = kthread_run(linux_wlan_read_mac_addr, NULL, "wilc_mac_thread");
1623 if (wilc_mac_thread < 0)
1624 PRINT_ER("couldn't create Mac addr thread\n");
1627 linux_to_wlan(&nwi, g_linux_wlan);
1629 ret = wilc_wlan_init(&nwi, &nwo);
1631 PRINT_ER("Initializing WILC_Wlan FAILED\n");
1635 memcpy(&g_linux_wlan->oup, &nwo, sizeof(wilc_wlan_oup_t));
1637 /*Save the oup structre into global pointer*/
1638 gpstrWlanOps = &g_linux_wlan->oup;
1640 ret = wlan_initialize_threads(nic);
1642 PRINT_ER("Initializing Threads FAILED\n");
1644 goto _fail_wilc_wlan_;
1647 #if (defined WILC_SDIO) && (defined COMPLEMENT_BOOT)
1648 if (wilc1000_prepare_11b_core(&nwi, &nwo, g_linux_wlan)) {
1649 PRINT_ER("11b Core is not ready\n");
1651 goto _fail_threads_;
1655 #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
1656 if (init_irq(g_linux_wlan)) {
1657 PRINT_ER("couldn't initialize IRQ\n");
1659 goto _fail_threads_;
1663 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
1664 if (enable_sdio_interrupt()) {
1665 PRINT_ER("couldn't initialize IRQ\n");
1667 goto _fail_irq_init_;
1671 if (linux_wlan_get_firmware(nic)) {
1672 PRINT_ER("Can't get firmware\n");
1674 goto _fail_irq_enable_;
1677 /*Download firmware*/
1678 ret = linux_wlan_firmware_download(g_linux_wlan);
1680 PRINT_ER("Failed to download firmware\n");
1682 goto _fail_irq_enable_;
1686 ret = linux_wlan_start_firmware(nic);
1688 PRINT_ER("Failed to start firmware\n");
1690 goto _fail_irq_enable_;
1693 wilc_bus_set_max_speed();
1695 if (g_linux_wlan->oup.wlan_cfg_get(1, WID_FIRMWARE_VERSION, 1, 0)) {
1697 char Firmware_ver[20];
1699 size = g_linux_wlan->oup.wlan_cfg_get_value(
1700 WID_FIRMWARE_VERSION,
1701 Firmware_ver, sizeof(Firmware_ver));
1702 Firmware_ver[size] = '\0';
1703 PRINT_D(INIT_DBG, "***** Firmware Ver = %s *******\n", Firmware_ver);
1705 /* Initialize firmware with default configuration */
1706 ret = linux_wlan_init_test_config(dev, g_linux_wlan);
1709 PRINT_ER("Failed to configure firmware\n");
1711 goto _fail_fw_start_;
1714 g_linux_wlan->wilc1000_initialized = 1;
1715 return 0; /*success*/
1718 if (&g_linux_wlan->oup != NULL) {
1719 if (g_linux_wlan->oup.wlan_stop != NULL)
1720 g_linux_wlan->oup.wlan_stop();
1724 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
1725 disable_sdio_interrupt();
1728 #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
1729 deinit_irq(g_linux_wlan);
1733 wlan_deinitialize_threads(g_linux_wlan);
1735 wilc_wlan_deinit(g_linux_wlan);
1737 wlan_deinit_locks(g_linux_wlan);
1738 PRINT_ER("WLAN Iinitialization FAILED\n");
1740 PRINT_D(INIT_DBG, "wilc1000 already initialized\n");
1746 * - this function will be called automatically by OS when module inserted.
1749 #if !defined(NM73131_0_BOARD)
1750 int mac_init_fn(struct net_device *ndev)
1753 /*Why we do this !!!*/
1754 netif_start_queue(ndev); /* ma */
1755 netif_stop_queue(ndev); /* ma */
1760 int mac_init_fn(struct net_device *ndev)
1763 unsigned char mac_add[] = {0x00, 0x50, 0xc2, 0x5e, 0x10, 0x00};
1764 /* TODO: get MAC address whenever the source is EPROM - hardcoded and copy it to ndev*/
1765 memcpy(ndev->dev_addr, mac_add, 6);
1767 if (!is_valid_ether_addr(ndev->dev_addr)) {
1768 PRINT_ER("Error: Wrong MAC address\n");
1776 void WILC_WFI_frame_register(struct wiphy *wiphy, struct net_device *dev,
1777 u16 frame_type, bool reg);
1779 /* This fn is called, when this device is setup using ifconfig */
1780 #if !defined(NM73131_0_BOARD)
1781 int mac_open(struct net_device *ndev)
1783 perInterface_wlan_t *nic;
1786 /*No need for setting mac address here anymore,*/
1787 /*Just set it in init_test_config()*/
1788 unsigned char mac_add[ETH_ALEN] = {0};
1791 struct WILC_WFI_priv *priv;
1793 nic = netdev_priv(ndev);
1794 priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy);
1795 PRINT_D(INIT_DBG, "MAC OPEN[%p]\n", ndev);
1798 ret = WILC_WFI_InitHostInt(ndev);
1800 PRINT_ER("Failed to initialize host interface\n");
1806 /*initialize platform*/
1807 PRINT_D(INIT_DBG, "*** re-init ***\n");
1808 ret = wilc1000_wlan_init(ndev, nic);
1810 PRINT_ER("Failed to initialize wilc1000\n");
1811 WILC_WFI_DeInitHostInt(ndev);
1815 Set_machw_change_vir_if(false);
1817 host_int_get_MacAddress(priv->hWILCWFIDrv, mac_add);
1818 PRINT_D(INIT_DBG, "Mac address: %pM\n", mac_add);
1820 /* loop through the NUM of supported devices and set the MAC address */
1821 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
1822 if (ndev == g_linux_wlan->strInterfaceInfo[i].wilc_netdev) {
1823 memcpy(g_linux_wlan->strInterfaceInfo[i].aSrcAddress, mac_add, ETH_ALEN);
1824 g_linux_wlan->strInterfaceInfo[i].drvHandler = priv->hWILCWFIDrv;
1829 /* TODO: get MAC address whenever the source is EPROM - hardcoded and copy it to ndev*/
1830 memcpy(ndev->dev_addr, g_linux_wlan->strInterfaceInfo[i].aSrcAddress, ETH_ALEN);
1832 if (!is_valid_ether_addr(ndev->dev_addr)) {
1833 PRINT_ER("Error: Wrong MAC address\n");
1838 WILC_WFI_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy, nic->wilc_netdev,
1839 nic->g_struct_frame_reg[0].frame_type, nic->g_struct_frame_reg[0].reg);
1840 WILC_WFI_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy, nic->wilc_netdev,
1841 nic->g_struct_frame_reg[1].frame_type, nic->g_struct_frame_reg[1].reg);
1842 netif_wake_queue(ndev);
1843 g_linux_wlan->open_ifcs++;
1844 nic->mac_opened = 1;
1848 WILC_WFI_DeInitHostInt(ndev);
1849 wilc1000_wlan_deinit(g_linux_wlan);
1853 int mac_open(struct net_device *ndev)
1858 nic = netdev_priv(ndev);
1860 /*initialize platform*/
1861 if (wilc1000_wlan_init(nic)) {
1862 PRINT_ER("Failed to initialize platform\n");
1865 /* Start the network interface queue for this device */
1866 PRINT_D(INIT_DBG, "Starting netifQ\n");
1867 netif_start_queue(ndev);
1868 /* down(&close_exit_sync); */
1873 struct net_device_stats *mac_stats(struct net_device *dev)
1875 perInterface_wlan_t *nic = netdev_priv(dev);
1877 return &nic->netstats;
1880 /* Setup the multicast filter */
1881 static void wilc_set_multicast_list(struct net_device *dev)
1884 struct netdev_hw_addr *ha;
1885 struct WILC_WFI_priv *priv;
1886 tstrWILC_WFIDrv *pstrWFIDrv;
1889 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
1890 pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
1895 PRINT_D(INIT_DBG, "Setting Multicast List with count = %d.\n", dev->mc.count);
1897 if (dev->flags & IFF_PROMISC) {
1898 /* Normally, we should configure the chip to retrive all packets
1899 * but we don't wanna support this right now */
1900 /* TODO: add promiscuous mode support */
1901 PRINT_D(INIT_DBG, "Set promiscuous mode ON, retrive all packets\n");
1905 /* If there's more addresses than we handle, get all multicast
1906 * packets and sort them out in software. */
1907 if ((dev->flags & IFF_ALLMULTI) || (dev->mc.count) > WILC_MULTICAST_TABLE_SIZE) {
1908 PRINT_D(INIT_DBG, "Disable multicast filter, retrive all multicast packets\n");
1909 /* get all multicast packets */
1910 host_int_setup_multicast_filter(pstrWFIDrv, false, 0);
1914 /* No multicast? Just get our own stuff */
1915 if ((dev->mc.count) == 0) {
1916 PRINT_D(INIT_DBG, "Enable multicast filter, retrive directed packets only.\n");
1917 host_int_setup_multicast_filter(pstrWFIDrv, true, 0);
1921 /* Store all of the multicast addresses in the hardware filter */
1922 netdev_for_each_mc_addr(ha, dev)
1924 memcpy(gau8MulticastMacAddrList[i], ha->addr, ETH_ALEN);
1925 PRINT_D(INIT_DBG, "Entry[%d]: %x:%x:%x:%x:%x:%x\n", i,
1926 gau8MulticastMacAddrList[i][0], gau8MulticastMacAddrList[i][1], gau8MulticastMacAddrList[i][2], gau8MulticastMacAddrList[i][3], gau8MulticastMacAddrList[i][4], gau8MulticastMacAddrList[i][5]);
1930 host_int_setup_multicast_filter(pstrWFIDrv, true, (dev->mc.count));
1936 static void linux_wlan_tx_complete(void *priv, int status)
1939 struct tx_complete_data *pv_data = (struct tx_complete_data *)priv;
1942 PRINT_D(TX_DBG, "Packet sent successfully - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb);
1944 PRINT_D(TX_DBG, "Couldn't send packet - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb);
1945 /* Free the SK Buffer, its work is done */
1946 dev_kfree_skb(pv_data->skb);
1950 int mac_xmit(struct sk_buff *skb, struct net_device *ndev)
1952 perInterface_wlan_t *nic;
1953 struct tx_complete_data *tx_data = NULL;
1957 struct ethhdr *eth_h;
1959 nic = netdev_priv(ndev);
1961 PRINT_D(INT_DBG, "\n========\n IntUH: %d - IntBH: %d - IntCld: %d\n========\n", int_rcvdU, int_rcvdB, int_clrd);
1962 PRINT_D(TX_DBG, "Sending packet just received from TCP/IP\n");
1964 /* Stop the network interface queue */
1965 if (skb->dev != ndev) {
1966 PRINT_ER("Packet not destined to this device\n");
1970 tx_data = kmalloc(sizeof(struct tx_complete_data), GFP_ATOMIC);
1971 if (tx_data == NULL) {
1972 PRINT_ER("Failed to allocate memory for tx_data structure\n");
1974 netif_wake_queue(ndev);
1978 tx_data->buff = skb->data;
1979 tx_data->size = skb->len;
1982 eth_h = (struct ethhdr *)(skb->data);
1983 if (eth_h->h_proto == 0x8e88)
1984 PRINT_D(INIT_DBG, "EAPOL transmitted\n");
1986 /*get source and dest ip addresses*/
1987 ih = (struct iphdr *)(skb->data + sizeof(struct ethhdr));
1989 pu8UdpBuffer = (char *)ih + sizeof(struct iphdr);
1990 if ((pu8UdpBuffer[1] == 68 && pu8UdpBuffer[3] == 67) || (pu8UdpBuffer[1] == 67 && pu8UdpBuffer[3] == 68))
1991 PRINT_D(GENERIC_DBG, "DHCP Message transmitted, type:%x %x %x\n", pu8UdpBuffer[248], pu8UdpBuffer[249], pu8UdpBuffer[250]);
1993 PRINT_D(TX_DBG, "Sending packet - Size = %d - Address = %p - SKB = %p\n", tx_data->size, tx_data->buff, tx_data->skb);
1995 /* Send packet to MAC HW - for now the tx_complete function will be just status
1996 * indicator. still not sure if I need to suspend host transmission till the tx_complete
1997 * function called or not?
1998 * allocated buffer will be freed in tx_complete function.
2000 PRINT_D(TX_DBG, "Adding tx packet to TX Queue\n");
2001 nic->netstats.tx_packets++;
2002 nic->netstats.tx_bytes += tx_data->size;
2003 tx_data->pBssid = g_linux_wlan->strInterfaceInfo[nic->u8IfIdx].aBSSID;
2004 #ifndef WILC_FULLY_HOSTING_AP
2005 QueueCount = g_linux_wlan->oup.wlan_add_to_tx_que((void *)tx_data,
2008 linux_wlan_tx_complete);
2010 QueueCount = WILC_Xmit_data((void *)tx_data, HOST_TO_WLAN);
2011 #endif /* WILC_FULLY_HOSTING_AP */
2013 if (QueueCount > FLOW_CONTROL_UPPER_THRESHOLD) {
2014 netif_stop_queue(g_linux_wlan->strInterfaceInfo[0].wilc_netdev);
2015 netif_stop_queue(g_linux_wlan->strInterfaceInfo[1].wilc_netdev);
2021 int mac_close(struct net_device *ndev)
2023 struct WILC_WFI_priv *priv;
2024 perInterface_wlan_t *nic;
2025 tstrWILC_WFIDrv *pstrWFIDrv;
2027 nic = netdev_priv(ndev);
2029 if ((nic == NULL) || (nic->wilc_netdev == NULL) || (nic->wilc_netdev->ieee80211_ptr == NULL) || (nic->wilc_netdev->ieee80211_ptr->wiphy == NULL)) {
2030 PRINT_ER("nic = NULL\n");
2034 priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy);
2037 PRINT_ER("priv = NULL\n");
2041 pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
2043 PRINT_D(GENERIC_DBG, "Mac close\n");
2045 if (g_linux_wlan == NULL) {
2046 PRINT_ER("g_linux_wlan = NULL\n");
2050 if (pstrWFIDrv == NULL) {
2051 PRINT_ER("pstrWFIDrv = NULL\n");
2055 if ((g_linux_wlan->open_ifcs) > 0) {
2056 g_linux_wlan->open_ifcs--;
2058 PRINT_ER("ERROR: MAC close called while number of opened interfaces is zero\n");
2062 if (nic->wilc_netdev != NULL) {
2063 /* Stop the network interface queue */
2064 netif_stop_queue(nic->wilc_netdev);
2067 WILC_WFI_DeInitHostInt(nic->wilc_netdev);
2071 if (g_linux_wlan->open_ifcs == 0) {
2072 PRINT_D(GENERIC_DBG, "Deinitializing wilc1000\n");
2073 g_linux_wlan->close = 1;
2074 wilc1000_wlan_deinit(g_linux_wlan);
2076 #ifdef WILC_AP_EXTERNAL_MLME
2077 WILC_WFI_deinit_mon_interface();
2082 up(&close_exit_sync);
2083 nic->mac_opened = 0;
2088 int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
2093 u32 size = 0, length = 0;
2094 perInterface_wlan_t *nic;
2095 struct WILC_WFI_priv *priv;
2096 s32 s32Error = WILC_SUCCESS;
2098 /* struct iwreq *wrq = (struct iwreq *) req; // tony moved to case SIOCSIWPRIV */
2100 nic = netdev_priv(ndev);
2102 if (!g_linux_wlan->wilc1000_initialized)
2112 struct iwreq *wrq = (struct iwreq *) req; /* added by tony */
2114 size = wrq->u.data.length;
2116 if (size && wrq->u.data.pointer) {
2118 buff = memdup_user(wrq->u.data.pointer, wrq->u.data.length);
2120 s32Error = PTR_ERR(buff);
2124 if (strncasecmp(buff, "RSSI", length) == 0) {
2127 priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy);
2128 s32Error = host_int_get_rssi(priv->hWILCWFIDrv, &(rssi));
2130 PRINT_ER("Failed to send get rssi param's message queue ");
2132 PRINT_INFO(GENERIC_DBG, "RSSI :%d\n", rssi);
2134 /*Rounding up the rssi negative value*/
2137 snprintf(buff, size, "rssi %d", rssi);
2139 if (copy_to_user(wrq->u.data.pointer, buff, size)) {
2140 PRINT_ER("%s: failed to copy data to user buffer\n", __func__);
2151 PRINT_INFO(GENERIC_DBG, "Command - %d - has been received\n", cmd);
2152 s32Error = -EOPNOTSUPP;
2164 void frmw_to_linux(uint8_t *buff, uint32_t size, uint32_t pkt_offset)
2167 unsigned int frame_len = 0;
2169 unsigned char *buff_to_send = NULL;
2170 struct sk_buff *skb;
2171 #ifndef TCP_ENHANCEMENTS
2175 struct net_device *wilc_netdev;
2176 perInterface_wlan_t *nic;
2178 wilc_netdev = GetIfHandler(buff);
2179 if (wilc_netdev == NULL)
2183 nic = netdev_priv(wilc_netdev);
2188 buff_to_send = buff;
2190 /* Need to send the packet up to the host, allocate a skb buffer */
2191 skb = dev_alloc_skb(frame_len);
2193 PRINT_ER("Low memory - packet droped\n");
2197 skb_reserve(skb, (unsigned int)skb->data & 0x3);
2199 if (g_linux_wlan == NULL || wilc_netdev == NULL)
2200 PRINT_ER("wilc_netdev in g_linux_wlan is NULL");
2201 skb->dev = wilc_netdev;
2203 if (skb->dev == NULL)
2204 PRINT_ER("skb->dev is NULL\n");
2210 * WILC_PRINTF("buff_to_send[%d]=%2x\n",i,buff_to_send[i]);
2214 /* skb_put(skb, frame_len); */
2215 memcpy(skb_put(skb, frame_len), buff_to_send, frame_len);
2217 /* WILC_PRINTF("After MEM_CPY\n"); */
2219 /* nic = netdev_priv(wilc_netdev); */
2222 /* if(nic->monitor_flag)
2224 * WILC_WFI_monitor_rx(nic->wilc_netdev,skb);
2228 skb->protocol = eth_type_trans(skb, wilc_netdev);
2229 #ifndef TCP_ENHANCEMENTS
2230 /*get source and dest ip addresses*/
2231 ih = (struct iphdr *)(skb->data + sizeof(struct ethhdr));
2233 pu8UdpBuffer = (char *)ih + sizeof(struct iphdr);
2234 if (buff_to_send[35] == 67 && buff_to_send[37] == 68)
2235 PRINT_D(RX_DBG, "DHCP Message received\n");
2236 if (buff_to_send[12] == 0x88 && buff_to_send[13] == 0x8e)
2237 PRINT_D(GENERIC_DBG, "eapol received\n");
2239 /* Send the packet to the stack by giving it to the bridge */
2240 nic->netstats.rx_packets++;
2241 nic->netstats.rx_bytes += frame_len;
2242 skb->ip_summed = CHECKSUM_UNNECESSARY;
2243 stats = netif_rx(skb);
2244 PRINT_D(RX_DBG, "netif_rx ret value is: %d\n", stats);
2246 #ifndef TCP_ENHANCEMENTS
2248 PRINT_ER("Discard sending packet with len = %d\n", size);
2252 void WILC_WFI_mgmt_rx(uint8_t *buff, uint32_t size)
2255 perInterface_wlan_t *nic;
2258 /*Pass the frame on the monitor interface, if any.*/
2259 /*Otherwise, pass it on p2p0 netdev, if registered on it*/
2260 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
2261 nic = netdev_priv(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2262 if (nic->monitor_flag) {
2263 WILC_WFI_monitor_rx(buff, size);
2269 nic = netdev_priv(g_linux_wlan->strInterfaceInfo[1].wilc_netdev); /* p2p0 */
2270 if ((buff[0] == nic->g_struct_frame_reg[0].frame_type && nic->g_struct_frame_reg[0].reg) ||
2271 (buff[0] == nic->g_struct_frame_reg[1].frame_type && nic->g_struct_frame_reg[1].reg))
2272 WILC_WFI_p2p_rx(g_linux_wlan->strInterfaceInfo[1].wilc_netdev, buff, size);
2276 int wilc_netdev_init(void)
2280 perInterface_wlan_t *nic;
2281 struct net_device *ndev;
2283 sema_init(&close_exit_sync, 0);
2285 /*create the common structure*/
2286 g_linux_wlan = WILC_MALLOC(sizeof(linux_wlan_t));
2287 memset(g_linux_wlan, 0, sizeof(linux_wlan_t));
2289 /*Reset interrupt count debug*/
2293 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
2294 register_inetaddr_notifier(&g_dev_notifier);
2297 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
2298 /*allocate first ethernet device with perinterface_wlan_t as its private data*/
2299 ndev = alloc_etherdev(sizeof(perInterface_wlan_t));
2301 PRINT_ER("Failed to allocate ethernet dev\n");
2305 nic = netdev_priv(ndev);
2306 memset(nic, 0, sizeof(perInterface_wlan_t));
2308 /*Name the Devices*/
2310 #if defined(NM73131) /* tony, 2012-09-20 */
2311 strcpy(ndev->name, "wilc_eth%d");
2312 #elif defined(PLAT_CLM9722) /* rachel */
2313 strcpy(ndev->name, "eth%d");
2314 #else /* PANDA_BOARD, PLAT_ALLWINNER_A10, PLAT_ALLWINNER_A20, PLAT_ALLWINNER_A31, PLAT_AML8726_M3 or PLAT_WMS8304 */
2315 strcpy(ndev->name, "wlan%d");
2318 strcpy(ndev->name, "p2p%d");
2320 nic->u8IfIdx = g_linux_wlan->u8NoIfcs;
2321 nic->wilc_netdev = ndev;
2322 g_linux_wlan->strInterfaceInfo[g_linux_wlan->u8NoIfcs].wilc_netdev = ndev;
2323 g_linux_wlan->u8NoIfcs++;
2324 ndev->netdev_ops = &wilc_netdev_ops;
2328 struct wireless_dev *wdev;
2330 wdev = WILC_WFI_WiphyRegister(ndev);
2333 /* set netdev, tony */
2334 SET_NETDEV_DEV(ndev, &local_sdio_func->dev);
2338 PRINT_ER("Can't register WILC Wiphy\n");
2342 /*linking the wireless_dev structure with the netdevice*/
2343 nic->wilc_netdev->ieee80211_ptr = wdev;
2344 nic->wilc_netdev->ml_priv = nic;
2345 wdev->netdev = nic->wilc_netdev;
2346 nic->netstats.rx_packets = 0;
2347 nic->netstats.tx_packets = 0;
2348 nic->netstats.rx_bytes = 0;
2349 nic->netstats.tx_bytes = 0;
2354 if (register_netdev(ndev)) {
2355 PRINT_ER("Device couldn't be registered - %s\n", ndev->name);
2356 return -1; /* ERROR */
2359 nic->iftype = STATION_MODE;
2360 nic->mac_opened = 0;
2365 if (!linux_spi_init(&g_linux_wlan->wilc_spidev)) {
2366 PRINT_ER("Can't initialize SPI\n");
2367 return -1; /* ERROR */
2369 g_linux_wlan->wilc_spidev = wilc_spi_dev;
2371 g_linux_wlan->wilc_sdio_func = local_sdio_func;
2377 /*The 1st function called after module inserted*/
2378 static int __init init_wilc_driver(void)
2380 #if defined(WILC_DEBUGFS)
2381 if (wilc_debugfs_init() < 0) {
2382 PRINT_D(GENERIC_DBG, "fail to create debugfs for wilc driver\n");
2387 printk("IN INIT FUNCTION\n");
2388 printk("*** WILC1000 driver VERSION=[10.2] FW_VER=[10.2] ***\n");
2390 linux_wlan_device_power(1);
2392 linux_wlan_device_detection(1);
2398 ret = sdio_register_driver(&wilc_bus);
2400 PRINT_D(INIT_DBG, "init_wilc_driver: Failed register sdio driver\n");
2405 PRINT_D(INIT_DBG, "Initializing netdev\n");
2406 if (wilc_netdev_init())
2407 PRINT_ER("Couldn't initialize netdev\n");
2411 late_initcall(init_wilc_driver);
2413 static void __exit exit_wilc_driver(void)
2416 perInterface_wlan_t *nic[NUM_CONCURRENT_IFC] = {NULL,};
2417 #define CLOSE_TIMEOUT (12 * 1000)
2419 if ((g_linux_wlan != NULL) && (((g_linux_wlan->strInterfaceInfo[0].wilc_netdev) != NULL)
2420 || ((g_linux_wlan->strInterfaceInfo[1].wilc_netdev) != NULL))) {
2421 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
2422 unregister_inetaddr_notifier(&g_dev_notifier);
2425 for (i = 0; i < NUM_CONCURRENT_IFC; i++)
2426 nic[i] = netdev_priv(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2429 if ((g_linux_wlan != NULL) && g_linux_wlan->wilc_firmware != NULL) {
2430 release_firmware(g_linux_wlan->wilc_firmware);
2431 g_linux_wlan->wilc_firmware = NULL;
2434 if ((g_linux_wlan != NULL) && (((g_linux_wlan->strInterfaceInfo[0].wilc_netdev) != NULL)
2435 || ((g_linux_wlan->strInterfaceInfo[1].wilc_netdev) != NULL))) {
2436 PRINT_D(INIT_DBG, "Waiting for mac_close ....\n");
2438 if (linux_wlan_lock_timeout(&close_exit_sync, CLOSE_TIMEOUT) < 0)
2439 PRINT_D(INIT_DBG, "Closed TimedOUT\n");
2441 PRINT_D(INIT_DBG, "mac_closed\n");
2443 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
2444 /* close all opened interfaces */
2445 if (g_linux_wlan->strInterfaceInfo[i].wilc_netdev != NULL) {
2446 if (nic[i]->mac_opened)
2447 mac_close(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2450 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
2451 PRINT_D(INIT_DBG, "Unregistering netdev %p\n", g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2452 unregister_netdev(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2454 PRINT_D(INIT_DBG, "Freeing Wiphy...\n");
2455 WILC_WFI_WiphyFree(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2457 PRINT_D(INIT_DBG, "Freeing netdev...\n");
2458 free_netdev(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2463 #ifdef WILC_AP_EXTERNAL_MLME
2464 /* Bug 4600 : WILC_WFI_deinit_mon_interface was already called at mac_close */
2465 /* WILC_WFI_deinit_mon_interface(); */
2469 /* if(g_linux_wlan->open_ifcs==0) */
2472 PRINT_D(INIT_DBG, "SPI unregsiter...\n");
2473 spi_unregister_driver(&wilc_bus);
2475 PRINT_D(INIT_DBG, "SDIO unregsiter...\n");
2476 sdio_unregister_driver(&wilc_bus);
2479 if (g_linux_wlan != NULL) {
2480 kfree(g_linux_wlan);
2481 g_linux_wlan = NULL;
2483 printk("Module_exit Done.\n");
2485 #if defined(WILC_DEBUGFS)
2486 wilc_debugfs_remove();
2489 linux_wlan_device_detection(0);
2490 linux_wlan_device_power(0);
2493 module_exit(exit_wilc_driver);
2495 MODULE_LICENSE("GPL");