1 #include "wilc_wfi_cfgoperations.h"
2 #include "linux_wlan_common.h"
3 #include "wilc_wlan_if.h"
6 #include <linux/slab.h>
7 #include <linux/sched.h>
8 #include <linux/delay.h>
9 #include <linux/workqueue.h>
10 #include <linux/interrupt.h>
11 #include <linux/irq.h>
12 #include <linux/gpio.h>
14 #include <linux/kthread.h>
15 #include <linux/firmware.h>
16 #include <linux/delay.h>
18 #include <linux/init.h>
19 #include <linux/netdevice.h>
20 #include <linux/inetdevice.h>
21 #include <linux/etherdevice.h>
22 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/skbuff.h>
26 #include <linux/version.h>
27 #include <linux/semaphore.h>
30 #include "linux_wlan_sdio.h"
32 #include "linux_wlan_spi.h"
35 #if defined(CUSTOMER_PLATFORM)
37 TODO : Write power control functions as customer platform.
41 #define _linux_wlan_device_power_on() {}
42 #define _linux_wlan_device_power_off() {}
44 #define _linux_wlan_device_detection() {}
45 #define _linux_wlan_device_removal() {}
48 extern bool g_obtainingIP;
49 extern u16 Set_machw_change_vir_if(bool bValue);
50 extern void resolve_disconnect_aberration(void *drvHandler);
51 extern u8 gau8MulticastMacAddrList[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN];
52 void wilc1000_wlan_deinit(struct wilc *nic);
53 extern struct timer_list hDuringIpTimer;
55 static int linux_wlan_device_power(int on_off)
57 PRINT_D(INIT_DBG, "linux_wlan_device_power.. (%d)\n", on_off);
60 _linux_wlan_device_power_on();
62 _linux_wlan_device_power_off();
68 static int linux_wlan_device_detection(int on_off)
70 PRINT_D(INIT_DBG, "linux_wlan_device_detection.. (%d)\n", on_off);
74 _linux_wlan_device_detection();
76 _linux_wlan_device_removal();
83 static int dev_state_ev_handler(struct notifier_block *this, unsigned long event, void *ptr);
85 static struct notifier_block g_dev_notifier = {
86 .notifier_call = dev_state_ev_handler
92 * to sync between mac_close and module exit.
93 * don't initialize or de-initialize from init/deinitlocks
94 * to be initialized from module wilc_netdev_init and
95 * deinitialized from mdoule_exit
97 static struct semaphore close_exit_sync;
99 static int wlan_deinit_locks(struct wilc *nic);
100 static void wlan_deinitialize_threads(struct wilc *nic);
101 extern void WILC_WFI_monitor_rx(u8 *buff, u32 size);
102 extern void WILC_WFI_p2p_rx(struct net_device *dev, u8 *buff, u32 size);
104 static void linux_wlan_tx_complete(void *priv, int status);
105 static int mac_init_fn(struct net_device *ndev);
106 int mac_xmit(struct sk_buff *skb, struct net_device *dev);
107 int mac_open(struct net_device *ndev);
108 int mac_close(struct net_device *ndev);
109 static struct net_device_stats *mac_stats(struct net_device *dev);
110 static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd);
111 static void wilc_set_multicast_list(struct net_device *dev);
114 * for now - in frmw_to_linux there should be private data to be passed to it
115 * and this data should be pointer to net device
117 struct wilc *g_linux_wlan;
118 bool bEnablePS = true;
120 static const struct net_device_ops wilc_netdev_ops = {
121 .ndo_init = mac_init_fn,
122 .ndo_open = mac_open,
123 .ndo_stop = mac_close,
124 .ndo_start_xmit = mac_xmit,
125 .ndo_do_ioctl = mac_ioctl,
126 .ndo_get_stats = mac_stats,
127 .ndo_set_rx_mode = wilc_set_multicast_list,
131 static int dev_state_ev_handler(struct notifier_block *this, unsigned long event, void *ptr)
133 struct in_ifaddr *dev_iface = (struct in_ifaddr *)ptr;
134 struct wilc_priv *priv;
135 struct host_if_drv *pstrWFIDrv;
136 struct net_device *dev;
138 perInterface_wlan_t *nic;
140 char wlan_dev_name[5] = "wlan0";
142 if (dev_iface == NULL || dev_iface->ifa_dev == NULL || dev_iface->ifa_dev->dev == NULL) {
143 PRINT_D(GENERIC_DBG, "dev_iface = NULL\n");
147 if ((memcmp(dev_iface->ifa_label, "wlan0", 5)) && (memcmp(dev_iface->ifa_label, "p2p0", 4))) {
148 PRINT_D(GENERIC_DBG, "Interface is neither WLAN0 nor P2P0\n");
152 dev = (struct net_device *)dev_iface->ifa_dev->dev;
153 if (dev->ieee80211_ptr == NULL || dev->ieee80211_ptr->wiphy == NULL) {
154 PRINT_D(GENERIC_DBG, "No Wireless registerd\n");
157 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
159 PRINT_D(GENERIC_DBG, "No Wireless Priv\n");
162 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
163 nic = netdev_priv(dev);
164 if (nic == NULL || pstrWFIDrv == NULL) {
165 PRINT_D(GENERIC_DBG, "No Wireless Priv\n");
169 PRINT_INFO(GENERIC_DBG, "dev_state_ev_handler +++\n"); /* tony */
173 PRINT_D(GENERIC_DBG, "dev_state_ev_handler event=NETDEV_UP %p\n", dev); /* tony */
175 PRINT_INFO(GENERIC_DBG, "\n ============== IP Address Obtained ===============\n\n");
177 /*If we are in station mode or client mode*/
178 if (nic->iftype == STATION_MODE || nic->iftype == CLIENT_MODE) {
179 pstrWFIDrv->IFC_UP = 1;
180 g_obtainingIP = false;
181 del_timer(&hDuringIpTimer);
182 PRINT_D(GENERIC_DBG, "IP obtained , enable scan\n");
186 host_int_set_power_mgmt(pstrWFIDrv, 1, 0);
188 PRINT_D(GENERIC_DBG, "[%s] Up IP\n", dev_iface->ifa_label);
190 pIP_Add_buff = (char *) (&(dev_iface->ifa_address));
191 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]);
192 host_int_setup_ipaddress(pstrWFIDrv, pIP_Add_buff, nic->u8IfIdx);
197 PRINT_D(GENERIC_DBG, "dev_state_ev_handler event=NETDEV_DOWN %p\n", dev); /* tony */
199 PRINT_INFO(GENERIC_DBG, "\n ============== IP Address Released ===============\n\n");
200 if (nic->iftype == STATION_MODE || nic->iftype == CLIENT_MODE) {
201 pstrWFIDrv->IFC_UP = 0;
202 g_obtainingIP = false;
205 if (memcmp(dev_iface->ifa_label, wlan_dev_name, 5) == 0)
206 host_int_set_power_mgmt(pstrWFIDrv, 0, 0);
208 resolve_disconnect_aberration(pstrWFIDrv);
210 PRINT_D(GENERIC_DBG, "[%s] Down IP\n", dev_iface->ifa_label);
212 pIP_Add_buff = null_ip;
213 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]);
215 host_int_setup_ipaddress(pstrWFIDrv, pIP_Add_buff, nic->u8IfIdx);
220 PRINT_INFO(GENERIC_DBG, "dev_state_ev_handler event=default\n"); /* tony */
221 PRINT_INFO(GENERIC_DBG, "[%s] unknown dev event: %lu\n", dev_iface->ifa_label, event);
230 #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
231 static irqreturn_t isr_uh_routine(int irq, void *user_data)
233 PRINT_D(INT_DBG, "Interrupt received UH\n");
235 /*While mac is closing cacncel the handling of any interrupts received*/
236 if (g_linux_wlan->close) {
237 PRINT_ER("Driver is CLOSING: Can't handle UH interrupt\n");
240 return IRQ_WAKE_THREAD;
244 irqreturn_t isr_bh_routine(int irq, void *userdata)
248 nic = (struct wilc *)userdata;
250 /*While mac is closing cacncel the handling of any interrupts received*/
251 if (g_linux_wlan->close) {
252 PRINT_ER("Driver is CLOSING: Can't handle BH interrupt\n");
256 PRINT_D(INT_DBG, "Interrupt received BH\n");
262 #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
263 static int init_irq(struct wilc *p_nic)
266 struct wilc *nic = p_nic;
268 /*initialize GPIO and register IRQ num*/
270 if ((gpio_request(GPIO_NUM, "WILC_INTR") == 0) &&
271 (gpio_direction_input(GPIO_NUM) == 0)) {
272 #if defined(CUSTOMER_PLATFORM)
274 TODO : save the registerd irq number to the private wilc context in kernel.
276 * ex) nic->dev_irq_num = gpio_to_irq(GPIO_NUM);
279 nic->dev_irq_num = gpio_to_irq(GPIO_NUM);
283 PRINT_ER("could not obtain gpio for WILC_INTR\n");
286 if ((ret != -1) && (request_threaded_irq(nic->dev_irq_num, isr_uh_routine, isr_bh_routine,
287 IRQF_TRIGGER_LOW | IRQF_ONESHOT, /*Without IRQF_ONESHOT the uh will remain kicked in and dont gave a chance to bh*/
288 "WILC_IRQ", nic)) < 0) {
290 PRINT_ER("Failed to request IRQ for GPIO: %d\n", GPIO_NUM);
294 PRINT_D(INIT_DBG, "IRQ request succeeded IRQ-NUM= %d on GPIO: %d\n",
295 nic->dev_irq_num, GPIO_NUM);
302 static void deinit_irq(struct wilc *nic)
304 #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
305 /* Deintialize IRQ */
306 if (&nic->dev_irq_num != 0) {
307 free_irq(nic->dev_irq_num, g_linux_wlan);
317 void linux_wlan_dbg(u8 *buff)
319 PRINT_D(INIT_DBG, "%d\n", *buff);
322 int linux_wlan_lock_timeout(void *vp, u32 timeout)
326 PRINT_D(LOCK_DBG, "Locking %p\n", vp);
328 error = down_timeout((struct semaphore *)vp, msecs_to_jiffies(timeout));
330 PRINT_ER("Failed, mutex is NULL\n");
334 void linux_wlan_mac_indicate(int flag)
336 /*I have to do it that way becuase there is no mean to encapsulate device pointer
339 struct wilc *pd = g_linux_wlan;
342 if (flag == WILC_MAC_INDICATE_STATUS) {
343 wilc_wlan_cfg_get_val(WID_STATUS, (unsigned char *)&status, 4);
344 if (pd->mac_status == WILC_MAC_STATUS_INIT) {
345 pd->mac_status = status;
348 pd->mac_status = status;
351 if (pd->mac_status == WILC_MAC_STATUS_CONNECT) { /* Connect */
354 } else if (flag == WILC_MAC_INDICATE_SCAN) {
355 PRINT_D(GENERIC_DBG, "Scanning ...\n");
361 struct net_device *GetIfHandler(u8 *pMacHeader)
366 Bssid = pMacHeader + 10;
367 Bssid1 = pMacHeader + 4;
369 for (i = 0; i < g_linux_wlan->vif_num; i++)
370 if (!memcmp(Bssid1, g_linux_wlan->vif[i].bssid, ETH_ALEN) ||
371 !memcmp(Bssid, g_linux_wlan->vif[i].bssid, ETH_ALEN))
372 return g_linux_wlan->vif[i].wilc_netdev;
374 PRINT_INFO(INIT_DBG, "Invalide handle\n");
375 for (i = 0; i < 25; i++)
376 PRINT_D(INIT_DBG, "%02x ", pMacHeader[i]);
377 Bssid = pMacHeader + 18;
378 Bssid1 = pMacHeader + 12;
379 for (i = 0; i < g_linux_wlan->vif_num; i++)
380 if (!memcmp(Bssid1, g_linux_wlan->vif[i].bssid, ETH_ALEN) ||
381 !memcmp(Bssid, g_linux_wlan->vif[i].bssid, ETH_ALEN))
382 return g_linux_wlan->vif[i].wilc_netdev;
384 PRINT_INFO(INIT_DBG, "\n");
388 int linux_wlan_set_bssid(struct net_device *wilc_netdev, u8 *pBSSID)
393 for (i = 0; i < g_linux_wlan->vif_num; i++)
394 if (g_linux_wlan->vif[i].wilc_netdev == wilc_netdev) {
395 memcpy(g_linux_wlan->vif[i].bssid, pBSSID, 6);
403 /*Function to get number of connected interfaces*/
404 int linux_wlan_get_num_conn_ifcs(void)
407 u8 null_bssid[6] = {0};
410 for (i = 0; i < g_linux_wlan->vif_num; i++)
411 if (memcmp(g_linux_wlan->vif[i].bssid, null_bssid, 6))
417 #define USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
419 static int linux_wlan_txq_task(void *vp)
423 #if defined USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
424 #define TX_BACKOFF_WEIGHT_INCR_STEP (1)
425 #define TX_BACKOFF_WEIGHT_DECR_STEP (1)
426 #define TX_BACKOFF_WEIGHT_MAX (7)
427 #define TX_BACKOFF_WEIGHT_MIN (0)
428 #define TX_BACKOFF_WEIGHT_UNIT_MS (10)
429 int backoff_weight = TX_BACKOFF_WEIGHT_MIN;
432 /* inform wilc1000_wlan_init that TXQ task is started. */
433 up(&g_linux_wlan->txq_thread_started);
436 PRINT_D(TX_DBG, "txq_task Taking a nap :)\n");
437 down(&g_linux_wlan->txq_event);
438 /* wait_for_completion(&pd->txq_event); */
439 PRINT_D(TX_DBG, "txq_task Who waked me up :$\n");
441 if (g_linux_wlan->close) {
442 /*Unlock the mutex in the mac_close function to indicate the exiting of the TX thread */
443 up(&g_linux_wlan->txq_thread_started);
445 while (!kthread_should_stop())
448 PRINT_D(TX_DBG, "TX thread stopped\n");
451 PRINT_D(TX_DBG, "txq_task handle the sending packet and let me go to sleep.\n");
452 #if !defined USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
453 ret = wilc_wlan_handle_txq(&txq_count);
456 ret = wilc_wlan_handle_txq(&txq_count);
457 if (txq_count < FLOW_CONTROL_LOWER_THRESHOLD /* && netif_queue_stopped(pd->wilc_netdev)*/) {
458 PRINT_D(TX_DBG, "Waking up queue\n");
459 /* netif_wake_queue(pd->wilc_netdev); */
460 if (netif_queue_stopped(g_linux_wlan->vif[0].wilc_netdev))
461 netif_wake_queue(g_linux_wlan->vif[0].wilc_netdev);
462 if (netif_queue_stopped(g_linux_wlan->vif[1].wilc_netdev))
463 netif_wake_queue(g_linux_wlan->vif[1].wilc_netdev);
466 if (ret == WILC_TX_ERR_NO_BUF) { /* failed to allocate buffers in chip. */
468 /* Back off from sending packets for some time. */
469 /* schedule_timeout will allow RX task to run and free buffers.*/
470 /* set_current_state(TASK_UNINTERRUPTIBLE); */
471 /* timeout = schedule_timeout(timeout); */
472 msleep(TX_BACKOFF_WEIGHT_UNIT_MS << backoff_weight);
473 } while (/*timeout*/ 0);
474 backoff_weight += TX_BACKOFF_WEIGHT_INCR_STEP;
475 if (backoff_weight > TX_BACKOFF_WEIGHT_MAX)
476 backoff_weight = TX_BACKOFF_WEIGHT_MAX;
478 if (backoff_weight > TX_BACKOFF_WEIGHT_MIN) {
479 backoff_weight -= TX_BACKOFF_WEIGHT_DECR_STEP;
480 if (backoff_weight < TX_BACKOFF_WEIGHT_MIN)
481 backoff_weight = TX_BACKOFF_WEIGHT_MIN;
484 /*TODO: drop packets after a certain time/number of retry count. */
485 } while (ret == WILC_TX_ERR_NO_BUF && !g_linux_wlan->close); /* retry sending packets if no more buffers in chip. */
491 void linux_wlan_rx_complete(void)
493 PRINT_D(RX_DBG, "RX completed\n");
496 int linux_wlan_get_firmware(perInterface_wlan_t *p_nic)
499 perInterface_wlan_t *nic = p_nic;
501 const struct firmware *wilc_firmware;
504 if (nic->iftype == AP_MODE)
505 firmware = AP_FIRMWARE;
506 else if (nic->iftype == STATION_MODE)
507 firmware = STA_FIRMWARE;
510 PRINT_D(INIT_DBG, "Get P2P_CONCURRENCY_FIRMWARE\n");
511 firmware = P2P_CONCURRENCY_FIRMWARE;
515 PRINT_ER("NIC is NULL\n");
519 if (&nic->wilc_netdev->dev == NULL) {
520 PRINT_ER("&nic->wilc_netdev->dev is NULL\n");
524 /* the firmare should be located in /lib/firmware in
525 * root file system with the name specified above */
528 if (request_firmware(&wilc_firmware, firmware, &g_linux_wlan->wilc_sdio_func->dev) != 0) {
529 PRINT_ER("%s - firmare not available\n", firmware);
534 if (request_firmware(&wilc_firmware, firmware, &g_linux_wlan->wilc_spidev->dev) != 0) {
535 PRINT_ER("%s - firmare not available\n", firmware);
540 g_linux_wlan->wilc_firmware = wilc_firmware;
548 #ifdef COMPLEMENT_BOOT
549 int repeat_power_cycle(perInterface_wlan_t *nic);
552 static int linux_wlan_start_firmware(perInterface_wlan_t *nic)
557 PRINT_D(INIT_DBG, "Starting Firmware ...\n");
558 ret = wilc_wlan_start();
560 PRINT_ER("Failed to start Firmware\n");
564 /* wait for mac ready */
565 PRINT_D(INIT_DBG, "Waiting for Firmware to get ready ...\n");
566 ret = linux_wlan_lock_timeout(&g_linux_wlan->sync_event, 5000);
568 #ifdef COMPLEMENT_BOOT
569 static int timeout = 5;
572 PRINT_D(INIT_DBG, "repeat power cycle[%d]", timeout);
573 ret = repeat_power_cycle(nic);
580 PRINT_D(INIT_DBG, "Firmware start timed out");
584 * TODO: Driver shouoldn't wait forever for firmware to get started -
585 * in case of timeout this should be handled properly
587 PRINT_D(INIT_DBG, "Firmware successfully started\n");
592 static int linux_wlan_firmware_download(struct wilc *p_nic)
597 if (g_linux_wlan->wilc_firmware == NULL) {
598 PRINT_ER("Firmware buffer is NULL\n");
603 * do the firmware download
605 PRINT_D(INIT_DBG, "Downloading Firmware ...\n");
606 ret = wilc_wlan_firmware_download(g_linux_wlan->wilc_firmware->data,
607 g_linux_wlan->wilc_firmware->size);
611 /* Freeing FW buffer */
612 PRINT_D(INIT_DBG, "Freeing FW buffer ...\n");
613 PRINT_D(INIT_DBG, "Releasing firmware\n");
614 release_firmware(g_linux_wlan->wilc_firmware);
615 g_linux_wlan->wilc_firmware = NULL;
617 PRINT_D(INIT_DBG, "Download Succeeded\n");
623 /* startup configuration - could be changed later using iconfig*/
624 static int linux_wlan_init_test_config(struct net_device *dev, struct wilc *p_nic)
627 unsigned char c_val[64];
628 unsigned char mac_add[] = {0x00, 0x80, 0xC2, 0x5E, 0xa2, 0xff};
630 struct wilc_priv *priv;
631 struct host_if_drv *pstrWFIDrv;
633 PRINT_D(TX_DBG, "Start configuring Firmware\n");
634 get_random_bytes(&mac_add[5], 1);
635 get_random_bytes(&mac_add[4], 1);
636 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
637 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
638 PRINT_D(INIT_DBG, "Host = %p\n", pstrWFIDrv);
640 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]);
645 if (!wilc_wlan_cfg_set(1, WID_SET_DRV_HANDLER, c_val, 4, 0, 0))
648 /*to tell fw that we are going to use PC test - WILC specific*/
650 if (!wilc_wlan_cfg_set(0, WID_PC_TEST_MODE, c_val, 1, 0, 0))
653 c_val[0] = INFRASTRUCTURE;
654 if (!wilc_wlan_cfg_set(0, WID_BSS_TYPE, c_val, 1, 0, 0))
657 /* c_val[0] = RATE_AUTO; */
658 c_val[0] = RATE_AUTO;
659 if (!wilc_wlan_cfg_set(0, WID_CURRENT_TX_RATE, c_val, 1, 0, 0))
662 c_val[0] = G_MIXED_11B_2_MODE;
663 if (!wilc_wlan_cfg_set(0, WID_11G_OPERATING_MODE, c_val, 1, 0, 0))
667 if (!wilc_wlan_cfg_set(0, WID_CURRENT_CHANNEL, c_val, 1, 0, 0))
670 c_val[0] = G_SHORT_PREAMBLE;
671 if (!wilc_wlan_cfg_set(0, WID_PREAMBLE, c_val, 1, 0, 0))
674 c_val[0] = AUTO_PROT;
675 if (!wilc_wlan_cfg_set(0, WID_11N_PROT_MECH, c_val, 1, 0, 0))
678 c_val[0] = ACTIVE_SCAN;
679 if (!wilc_wlan_cfg_set(0, WID_SCAN_TYPE, c_val, 1, 0, 0))
682 c_val[0] = SITE_SURVEY_OFF;
683 if (!wilc_wlan_cfg_set(0, WID_SITE_SURVEY, c_val, 1, 0, 0))
686 *((int *)c_val) = 0xffff; /* Never use RTS-CTS */
687 if (!wilc_wlan_cfg_set(0, WID_RTS_THRESHOLD, c_val, 2, 0, 0))
690 *((int *)c_val) = 2346;
691 if (!wilc_wlan_cfg_set(0, WID_FRAG_THRESHOLD, c_val, 2, 0, 0))
695 /* -------------------------------------------------------------- */
696 /* Configuration : String with length less than 32 bytes */
697 /* Values to set : Any string with length less than 32 bytes */
698 /* ( In BSS Station Set SSID to "" (null string) */
699 /* to enable Broadcast SSID suppport ) */
700 /* -------------------------------------------------------------- */
702 if (!wilc_wlan_cfg_set(0, WID_BCAST_SSID, c_val, 1, 0, 0))
706 if (!wilc_wlan_cfg_set(0, WID_QOS_ENABLE, c_val, 1, 0, 0))
709 c_val[0] = NO_POWERSAVE;
710 if (!wilc_wlan_cfg_set(0, WID_POWER_MANAGEMENT, c_val, 1, 0, 0))
713 c_val[0] = NO_ENCRYPT; /* NO_ENCRYPT, 0x79 */
714 if (!wilc_wlan_cfg_set(0, WID_11I_MODE, c_val, 1, 0, 0))
717 c_val[0] = OPEN_SYSTEM;
718 if (!wilc_wlan_cfg_set(0, WID_AUTH_TYPE, c_val, 1, 0, 0))
721 /* WEP/802 11I Configuration */
722 /* ------------------------------------------------------------------ */
723 /* Configuration : WEP Key */
724 /* Values (0x) : 5 byte for WEP40 and 13 bytes for WEP104 */
725 /* In case more than 5 bytes are passed on for WEP 40 */
726 /* only first 5 bytes will be used as the key */
727 /* ------------------------------------------------------------------ */
729 strcpy(c_val, "123456790abcdef1234567890");
730 if (!wilc_wlan_cfg_set(0, WID_WEP_KEY_VALUE, c_val, (strlen(c_val) + 1), 0, 0))
733 /* WEP/802 11I Configuration */
734 /* ------------------------------------------------------------------ */
735 /* Configuration : AES/TKIP WPA/RSNA Pre-Shared Key */
736 /* Values to set : Any string with length greater than equal to 8 bytes */
737 /* and less than 64 bytes */
738 /* ------------------------------------------------------------------ */
739 strcpy(c_val, "12345678");
740 if (!wilc_wlan_cfg_set(0, WID_11I_PSK, c_val, (strlen(c_val)), 0, 0))
743 /* IEEE802.1X Key Configuration */
744 /* ------------------------------------------------------------------ */
745 /* Configuration : Radius Server Access Secret Key */
746 /* Values to set : Any string with length greater than equal to 8 bytes */
747 /* and less than 65 bytes */
748 /* ------------------------------------------------------------------ */
749 strcpy(c_val, "password");
750 if (!wilc_wlan_cfg_set(0, WID_1X_KEY, c_val, (strlen(c_val) + 1), 0, 0))
753 /* IEEE802.1X Server Address Configuration */
754 /* ------------------------------------------------------------------ */
755 /* Configuration : Radius Server IP Address */
756 /* Values to set : Any valid IP Address */
757 /* ------------------------------------------------------------------ */
762 if (!wilc_wlan_cfg_set(0, WID_1X_SERV_ADDR, c_val, 4, 0, 0))
766 if (!wilc_wlan_cfg_set(0, WID_LISTEN_INTERVAL, c_val, 1, 0, 0))
770 if (!wilc_wlan_cfg_set(0, WID_DTIM_PERIOD, c_val, 1, 0, 0))
773 c_val[0] = NORMAL_ACK;
774 if (!wilc_wlan_cfg_set(0, WID_ACK_POLICY, c_val, 1, 0, 0))
778 if (!wilc_wlan_cfg_set(0, WID_USER_CONTROL_ON_TX_POWER, c_val, 1, 0, 0))
782 if (!wilc_wlan_cfg_set(0, WID_TX_POWER_LEVEL_11A, c_val, 1, 0, 0))
786 if (!wilc_wlan_cfg_set(0, WID_TX_POWER_LEVEL_11B, c_val, 1, 0, 0))
789 /* Beacon Interval */
790 /* -------------------------------------------------------------------- */
791 /* Configuration : Sets the beacon interval value */
792 /* Values to set : Any 16-bit value */
793 /* -------------------------------------------------------------------- */
795 *((int *)c_val) = 100;
796 if (!wilc_wlan_cfg_set(0, WID_BEACON_INTERVAL, c_val, 2, 0, 0))
799 c_val[0] = REKEY_DISABLE;
800 if (!wilc_wlan_cfg_set(0, WID_REKEY_POLICY, c_val, 1, 0, 0))
803 /* Rekey Time (s) (Used only when the Rekey policy is 2 or 4) */
804 /* -------------------------------------------------------------------- */
805 /* Configuration : Sets the Rekey Time (s) */
806 /* Values to set : 32-bit value */
807 /* -------------------------------------------------------------------- */
808 *((int *)c_val) = 84600;
809 if (!wilc_wlan_cfg_set(0, WID_REKEY_PERIOD, c_val, 4, 0, 0))
812 /* Rekey Packet Count (in 1000s; used when Rekey Policy is 3) */
813 /* -------------------------------------------------------------------- */
814 /* Configuration : Sets Rekey Group Packet count */
815 /* Values to set : 32-bit Value */
816 /* -------------------------------------------------------------------- */
817 *((int *)c_val) = 500;
818 if (!wilc_wlan_cfg_set(0, WID_REKEY_PACKET_COUNT, c_val, 4, 0, 0))
822 if (!wilc_wlan_cfg_set(0, WID_SHORT_SLOT_ALLOWED, c_val, 1, 0, 0))
825 c_val[0] = G_SELF_CTS_PROT;
826 if (!wilc_wlan_cfg_set(0, WID_11N_ERP_PROT_TYPE, c_val, 1, 0, 0))
829 c_val[0] = 1; /* Enable N */
830 if (!wilc_wlan_cfg_set(0, WID_11N_ENABLE, c_val, 1, 0, 0))
833 c_val[0] = HT_MIXED_MODE;
834 if (!wilc_wlan_cfg_set(0, WID_11N_OPERATING_MODE, c_val, 1, 0, 0))
837 c_val[0] = 1; /* TXOP Prot disable in N mode: No RTS-CTS on TX A-MPDUs to save air-time. */
838 if (!wilc_wlan_cfg_set(0, WID_11N_TXOP_PROT_DISABLE, c_val, 1, 0, 0))
841 memcpy(c_val, mac_add, 6);
843 if (!wilc_wlan_cfg_set(0, WID_MAC_ADDR, c_val, 6, 0, 0))
849 c_val[0] = DETECT_PROTECT_REPORT;
850 if (!wilc_wlan_cfg_set(0, WID_11N_OBSS_NONHT_DETECTION, c_val, 1, 0, 0))
853 c_val[0] = RTS_CTS_NONHT_PROT;
854 if (!wilc_wlan_cfg_set(0, WID_11N_HT_PROT_TYPE, c_val, 1, 0, 0))
858 if (!wilc_wlan_cfg_set(0, WID_11N_RIFS_PROT_ENABLE, c_val, 1, 0, 0))
861 c_val[0] = MIMO_MODE;
862 if (!wilc_wlan_cfg_set(0, WID_11N_SMPS_MODE, c_val, 1, 0, 0))
866 if (!wilc_wlan_cfg_set(0, WID_11N_CURRENT_TX_MCS, c_val, 1, 0, 0))
869 c_val[0] = 1; /* Enable N with immediate block ack. */
870 if (!wilc_wlan_cfg_set(0, WID_11N_IMMEDIATE_BA_ENABLED, c_val, 1, 1, 1))
879 /**************************/
880 void wilc1000_wlan_deinit(struct wilc *nic)
882 if (g_linux_wlan->initialized) {
883 printk("Deinitializing wilc1000 ...\n");
886 PRINT_ER("nic is NULL\n");
890 #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
891 /* johnny : remove */
892 PRINT_D(INIT_DBG, "skip wilc_bus_set_default_speed\n");
894 wilc_bus_set_default_speed();
897 PRINT_D(INIT_DBG, "Disabling IRQ\n");
899 mutex_lock(&g_linux_wlan->hif_cs);
900 disable_sdio_interrupt();
901 mutex_unlock(&g_linux_wlan->hif_cs);
903 if (&g_linux_wlan->txq_event != NULL)
904 up(&g_linux_wlan->txq_event);
906 PRINT_D(INIT_DBG, "Deinitializing Threads\n");
907 wlan_deinitialize_threads(nic);
909 PRINT_D(INIT_DBG, "Deinitializing IRQ\n");
910 deinit_irq(g_linux_wlan);
914 PRINT_D(INIT_DBG, "Deinitializing WILC Wlan\n");
916 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
917 #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
918 PRINT_D(INIT_DBG, "Disabling IRQ 2\n");
920 mutex_lock(&g_linux_wlan->hif_cs);
921 disable_sdio_interrupt();
922 mutex_unlock(&g_linux_wlan->hif_cs);
926 /*De-Initialize locks*/
927 PRINT_D(INIT_DBG, "Deinitializing Locks\n");
928 wlan_deinit_locks(g_linux_wlan);
930 /* announce that wilc1000 is not initialized */
931 g_linux_wlan->initialized = false;
933 PRINT_D(INIT_DBG, "wilc1000 deinitialization Done\n");
936 PRINT_D(INIT_DBG, "wilc1000 is not initialized\n");
940 int wlan_init_locks(struct wilc *p_nic)
943 PRINT_D(INIT_DBG, "Initializing Locks ...\n");
945 mutex_init(&g_linux_wlan->hif_cs);
946 mutex_init(&g_linux_wlan->rxq_cs);
948 spin_lock_init(&g_linux_wlan->txq_spinlock);
949 sema_init(&g_linux_wlan->txq_add_to_head_cs, 1);
951 sema_init(&g_linux_wlan->txq_event, 0);
953 sema_init(&g_linux_wlan->cfg_event, 0);
954 sema_init(&g_linux_wlan->sync_event, 0);
956 sema_init(&g_linux_wlan->txq_thread_started, 0);
961 static int wlan_deinit_locks(struct wilc *nic)
963 PRINT_D(INIT_DBG, "De-Initializing Locks\n");
965 if (&g_linux_wlan->hif_cs != NULL)
966 mutex_destroy(&g_linux_wlan->hif_cs);
968 if (&g_linux_wlan->rxq_cs != NULL)
969 mutex_destroy(&g_linux_wlan->rxq_cs);
973 void linux_to_wlan(wilc_wlan_inp_t *nwi, struct wilc *nic)
976 PRINT_D(INIT_DBG, "Linux to Wlan services ...\n");
978 nwi->os_context.os_private = (void *)nic;
981 nwi->io_func.io_type = HIF_SDIO;
982 nwi->io_func.io_init = linux_sdio_init;
983 nwi->io_func.io_deinit = linux_sdio_deinit;
984 nwi->io_func.u.sdio.sdio_cmd52 = linux_sdio_cmd52;
985 nwi->io_func.u.sdio.sdio_cmd53 = linux_sdio_cmd53;
986 nwi->io_func.u.sdio.sdio_set_max_speed = linux_sdio_set_max_speed;
987 nwi->io_func.u.sdio.sdio_set_default_speed = linux_sdio_set_default_speed;
989 nwi->io_func.io_type = HIF_SPI;
990 nwi->io_func.io_init = linux_spi_init;
991 nwi->io_func.io_deinit = linux_spi_deinit;
992 nwi->io_func.u.spi.spi_tx = linux_spi_write;
993 nwi->io_func.u.spi.spi_rx = linux_spi_read;
994 nwi->io_func.u.spi.spi_trx = linux_spi_write_read;
995 nwi->io_func.u.spi.spi_max_speed = linux_spi_set_max_speed;
999 int wlan_initialize_threads(perInterface_wlan_t *nic)
1004 PRINT_D(INIT_DBG, "Initializing Threads ...\n");
1006 /* create tx task */
1007 PRINT_D(INIT_DBG, "Creating kthread for transmission\n");
1008 g_linux_wlan->txq_thread = kthread_run(linux_wlan_txq_task, (void *)g_linux_wlan, "K_TXQ_TASK");
1009 if (g_linux_wlan->txq_thread == NULL) {
1010 PRINT_ER("couldn't create TXQ thread\n");
1014 /* wait for TXQ task to start. */
1015 down(&g_linux_wlan->txq_thread_started);
1020 /*De-Initialize 2nd thread*/
1021 g_linux_wlan->close = 1;
1023 g_linux_wlan->close = 0;
1027 static void wlan_deinitialize_threads(struct wilc *nic)
1030 g_linux_wlan->close = 1;
1031 PRINT_D(INIT_DBG, "Deinitializing Threads\n");
1033 if (&g_linux_wlan->txq_event != NULL)
1034 up(&g_linux_wlan->txq_event);
1036 if (g_linux_wlan->txq_thread != NULL) {
1037 kthread_stop(g_linux_wlan->txq_thread);
1038 g_linux_wlan->txq_thread = NULL;
1042 #ifdef COMPLEMENT_BOOT
1044 extern volatile int probe;
1045 extern u8 core_11b_ready(void);
1047 #define READY_CHECK_THRESHOLD 30
1048 extern void wilc_wlan_global_reset(void);
1049 u8 wilc1000_prepare_11b_core(wilc_wlan_inp_t *nwi, struct wilc *nic)
1053 while ((core_11b_ready() && (READY_CHECK_THRESHOLD > (trials++)))) {
1054 PRINT_D(INIT_DBG, "11b core not ready yet: %u\n", trials);
1055 wilc_wlan_cleanup();
1056 wilc_wlan_global_reset();
1057 sdio_unregister_driver(&wilc_bus);
1059 linux_wlan_device_detection(0);
1063 linux_wlan_device_detection(1);
1065 sdio_register_driver(&wilc_bus);
1070 g_linux_wlan->wilc_sdio_func = local_sdio_func;
1071 linux_to_wlan(nwi, nic);
1072 wilc_wlan_init(nwi);
1075 if (READY_CHECK_THRESHOLD <= trials)
1082 int repeat_power_cycle(perInterface_wlan_t *nic)
1085 wilc_wlan_inp_t nwi;
1087 sdio_unregister_driver(&wilc_bus);
1089 linux_wlan_device_detection(0);
1090 linux_wlan_device_power(0);
1092 linux_wlan_device_power(1);
1094 linux_wlan_device_detection(1);
1097 sdio_register_driver(&wilc_bus);
1103 g_linux_wlan->wilc_sdio_func = local_sdio_func;
1104 linux_to_wlan(&nwi, g_linux_wlan);
1105 ret = wilc_wlan_init(&nwi);
1107 g_linux_wlan->mac_status = WILC_MAC_STATUS_INIT;
1108 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
1109 enable_sdio_interrupt();
1112 if (linux_wlan_get_firmware(nic)) {
1113 PRINT_ER("Can't get firmware\n");
1118 /*Download firmware*/
1119 ret = linux_wlan_firmware_download(g_linux_wlan);
1121 PRINT_ER("Failed to download firmware\n");
1125 ret = linux_wlan_start_firmware(nic);
1127 PRINT_ER("Failed to start firmware\n");
1133 int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic)
1135 wilc_wlan_inp_t nwi;
1136 perInterface_wlan_t *nic = p_nic;
1139 if (!g_linux_wlan->initialized) {
1140 g_linux_wlan->mac_status = WILC_MAC_STATUS_INIT;
1141 g_linux_wlan->close = 0;
1143 wlan_init_locks(g_linux_wlan);
1145 linux_to_wlan(&nwi, g_linux_wlan);
1147 ret = wilc_wlan_init(&nwi);
1149 PRINT_ER("Initializing WILC_Wlan FAILED\n");
1154 ret = wlan_initialize_threads(nic);
1156 PRINT_ER("Initializing Threads FAILED\n");
1158 goto _fail_wilc_wlan_;
1161 #if (defined WILC_SDIO) && (defined COMPLEMENT_BOOT)
1162 if (wilc1000_prepare_11b_core(&nwi, g_linux_wlan)) {
1163 PRINT_ER("11b Core is not ready\n");
1165 goto _fail_threads_;
1169 #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
1170 if (init_irq(g_linux_wlan)) {
1171 PRINT_ER("couldn't initialize IRQ\n");
1173 goto _fail_threads_;
1177 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
1178 if (enable_sdio_interrupt()) {
1179 PRINT_ER("couldn't initialize IRQ\n");
1181 goto _fail_irq_init_;
1185 if (linux_wlan_get_firmware(nic)) {
1186 PRINT_ER("Can't get firmware\n");
1188 goto _fail_irq_enable_;
1191 /*Download firmware*/
1192 ret = linux_wlan_firmware_download(g_linux_wlan);
1194 PRINT_ER("Failed to download firmware\n");
1196 goto _fail_irq_enable_;
1200 ret = linux_wlan_start_firmware(nic);
1202 PRINT_ER("Failed to start firmware\n");
1204 goto _fail_irq_enable_;
1207 wilc_bus_set_max_speed();
1209 if (wilc_wlan_cfg_get(1, WID_FIRMWARE_VERSION, 1, 0)) {
1211 char Firmware_ver[20];
1213 size = wilc_wlan_cfg_get_val(
1214 WID_FIRMWARE_VERSION,
1215 Firmware_ver, sizeof(Firmware_ver));
1216 Firmware_ver[size] = '\0';
1217 PRINT_D(INIT_DBG, "***** Firmware Ver = %s *******\n", Firmware_ver);
1219 /* Initialize firmware with default configuration */
1220 ret = linux_wlan_init_test_config(dev, g_linux_wlan);
1223 PRINT_ER("Failed to configure firmware\n");
1225 goto _fail_fw_start_;
1228 g_linux_wlan->initialized = true;
1229 return 0; /*success*/
1235 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
1236 disable_sdio_interrupt();
1239 #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
1240 deinit_irq(g_linux_wlan);
1244 wlan_deinitialize_threads(g_linux_wlan);
1246 wilc_wlan_cleanup();
1248 wlan_deinit_locks(g_linux_wlan);
1249 PRINT_ER("WLAN Iinitialization FAILED\n");
1251 PRINT_D(INIT_DBG, "wilc1000 already initialized\n");
1257 * - this function will be called automatically by OS when module inserted.
1260 int mac_init_fn(struct net_device *ndev)
1263 /*Why we do this !!!*/
1264 netif_start_queue(ndev); /* ma */
1265 netif_stop_queue(ndev); /* ma */
1270 /* This fn is called, when this device is setup using ifconfig */
1271 int mac_open(struct net_device *ndev)
1273 perInterface_wlan_t *nic;
1275 /*No need for setting mac address here anymore,*/
1276 /*Just set it in init_test_config()*/
1277 unsigned char mac_add[ETH_ALEN] = {0};
1280 struct wilc_priv *priv;
1283 if (!g_linux_wlan || !g_linux_wlan->wilc_spidev) {
1284 netdev_err(ndev, "wilc1000: SPI device not ready\n");
1288 nic = netdev_priv(ndev);
1289 priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy);
1290 PRINT_D(INIT_DBG, "MAC OPEN[%p]\n", ndev);
1292 ret = wilc_init_host_int(ndev);
1294 PRINT_ER("Failed to initialize host interface\n");
1299 /*initialize platform*/
1300 PRINT_D(INIT_DBG, "*** re-init ***\n");
1301 ret = wilc1000_wlan_init(ndev, nic);
1303 PRINT_ER("Failed to initialize wilc1000\n");
1304 wilc_deinit_host_int(ndev);
1308 Set_machw_change_vir_if(false);
1310 host_int_get_MacAddress(priv->hWILCWFIDrv, mac_add);
1311 PRINT_D(INIT_DBG, "Mac address: %pM\n", mac_add);
1313 /* loop through the NUM of supported devices and set the MAC address */
1314 for (i = 0; i < g_linux_wlan->vif_num; i++) {
1315 if (ndev == g_linux_wlan->vif[i].wilc_netdev) {
1316 memcpy(g_linux_wlan->vif[i].src_addr, mac_add, ETH_ALEN);
1317 g_linux_wlan->vif[i].hif_drv = priv->hWILCWFIDrv;
1322 /* TODO: get MAC address whenever the source is EPROM - hardcoded and copy it to ndev*/
1323 memcpy(ndev->dev_addr, g_linux_wlan->vif[i].src_addr, ETH_ALEN);
1325 if (!is_valid_ether_addr(ndev->dev_addr)) {
1326 PRINT_ER("Error: Wrong MAC address\n");
1331 wilc_mgmt_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy, nic->wilc_netdev->ieee80211_ptr,
1332 nic->g_struct_frame_reg[0].frame_type, nic->g_struct_frame_reg[0].reg);
1333 wilc_mgmt_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy, nic->wilc_netdev->ieee80211_ptr,
1334 nic->g_struct_frame_reg[1].frame_type, nic->g_struct_frame_reg[1].reg);
1335 netif_wake_queue(ndev);
1336 g_linux_wlan->open_ifcs++;
1337 nic->mac_opened = 1;
1341 wilc_deinit_host_int(ndev);
1342 wilc1000_wlan_deinit(g_linux_wlan);
1346 struct net_device_stats *mac_stats(struct net_device *dev)
1348 perInterface_wlan_t *nic = netdev_priv(dev);
1350 return &nic->netstats;
1353 /* Setup the multicast filter */
1354 static void wilc_set_multicast_list(struct net_device *dev)
1357 struct netdev_hw_addr *ha;
1358 struct wilc_priv *priv;
1359 struct host_if_drv *pstrWFIDrv;
1362 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
1363 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
1368 PRINT_D(INIT_DBG, "Setting Multicast List with count = %d.\n", dev->mc.count);
1370 if (dev->flags & IFF_PROMISC) {
1371 /* Normally, we should configure the chip to retrive all packets
1372 * but we don't wanna support this right now */
1373 /* TODO: add promiscuous mode support */
1374 PRINT_D(INIT_DBG, "Set promiscuous mode ON, retrive all packets\n");
1378 /* If there's more addresses than we handle, get all multicast
1379 * packets and sort them out in software. */
1380 if ((dev->flags & IFF_ALLMULTI) || (dev->mc.count) > WILC_MULTICAST_TABLE_SIZE) {
1381 PRINT_D(INIT_DBG, "Disable multicast filter, retrive all multicast packets\n");
1382 /* get all multicast packets */
1383 host_int_setup_multicast_filter(pstrWFIDrv, false, 0);
1387 /* No multicast? Just get our own stuff */
1388 if ((dev->mc.count) == 0) {
1389 PRINT_D(INIT_DBG, "Enable multicast filter, retrive directed packets only.\n");
1390 host_int_setup_multicast_filter(pstrWFIDrv, true, 0);
1394 /* Store all of the multicast addresses in the hardware filter */
1395 netdev_for_each_mc_addr(ha, dev)
1397 memcpy(gau8MulticastMacAddrList[i], ha->addr, ETH_ALEN);
1398 PRINT_D(INIT_DBG, "Entry[%d]: %x:%x:%x:%x:%x:%x\n", i,
1399 gau8MulticastMacAddrList[i][0], gau8MulticastMacAddrList[i][1], gau8MulticastMacAddrList[i][2], gau8MulticastMacAddrList[i][3], gau8MulticastMacAddrList[i][4], gau8MulticastMacAddrList[i][5]);
1403 host_int_setup_multicast_filter(pstrWFIDrv, true, (dev->mc.count));
1409 static void linux_wlan_tx_complete(void *priv, int status)
1412 struct tx_complete_data *pv_data = (struct tx_complete_data *)priv;
1415 PRINT_D(TX_DBG, "Packet sent successfully - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb);
1417 PRINT_D(TX_DBG, "Couldn't send packet - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb);
1418 /* Free the SK Buffer, its work is done */
1419 dev_kfree_skb(pv_data->skb);
1423 int mac_xmit(struct sk_buff *skb, struct net_device *ndev)
1425 perInterface_wlan_t *nic;
1426 struct tx_complete_data *tx_data = NULL;
1430 struct ethhdr *eth_h;
1432 nic = netdev_priv(ndev);
1434 PRINT_D(TX_DBG, "Sending packet just received from TCP/IP\n");
1436 /* Stop the network interface queue */
1437 if (skb->dev != ndev) {
1438 PRINT_ER("Packet not destined to this device\n");
1442 tx_data = kmalloc(sizeof(struct tx_complete_data), GFP_ATOMIC);
1443 if (tx_data == NULL) {
1444 PRINT_ER("Failed to allocate memory for tx_data structure\n");
1446 netif_wake_queue(ndev);
1450 tx_data->buff = skb->data;
1451 tx_data->size = skb->len;
1454 eth_h = (struct ethhdr *)(skb->data);
1455 if (eth_h->h_proto == 0x8e88)
1456 PRINT_D(INIT_DBG, "EAPOL transmitted\n");
1458 /*get source and dest ip addresses*/
1459 ih = (struct iphdr *)(skb->data + sizeof(struct ethhdr));
1461 pu8UdpBuffer = (char *)ih + sizeof(struct iphdr);
1462 if ((pu8UdpBuffer[1] == 68 && pu8UdpBuffer[3] == 67) || (pu8UdpBuffer[1] == 67 && pu8UdpBuffer[3] == 68))
1463 PRINT_D(GENERIC_DBG, "DHCP Message transmitted, type:%x %x %x\n", pu8UdpBuffer[248], pu8UdpBuffer[249], pu8UdpBuffer[250]);
1465 PRINT_D(TX_DBG, "Sending packet - Size = %d - Address = %p - SKB = %p\n", tx_data->size, tx_data->buff, tx_data->skb);
1467 /* Send packet to MAC HW - for now the tx_complete function will be just status
1468 * indicator. still not sure if I need to suspend host transmission till the tx_complete
1469 * function called or not?
1470 * allocated buffer will be freed in tx_complete function.
1472 PRINT_D(TX_DBG, "Adding tx packet to TX Queue\n");
1473 nic->netstats.tx_packets++;
1474 nic->netstats.tx_bytes += tx_data->size;
1475 tx_data->pBssid = g_linux_wlan->vif[nic->u8IfIdx].bssid;
1476 QueueCount = wilc_wlan_txq_add_net_pkt((void *)tx_data, tx_data->buff,
1478 linux_wlan_tx_complete);
1480 if (QueueCount > FLOW_CONTROL_UPPER_THRESHOLD) {
1481 netif_stop_queue(g_linux_wlan->vif[0].wilc_netdev);
1482 netif_stop_queue(g_linux_wlan->vif[1].wilc_netdev);
1488 int mac_close(struct net_device *ndev)
1490 struct wilc_priv *priv;
1491 perInterface_wlan_t *nic;
1492 struct host_if_drv *pstrWFIDrv;
1494 nic = netdev_priv(ndev);
1496 if ((nic == NULL) || (nic->wilc_netdev == NULL) || (nic->wilc_netdev->ieee80211_ptr == NULL) || (nic->wilc_netdev->ieee80211_ptr->wiphy == NULL)) {
1497 PRINT_ER("nic = NULL\n");
1501 priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy);
1504 PRINT_ER("priv = NULL\n");
1508 pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
1510 PRINT_D(GENERIC_DBG, "Mac close\n");
1512 if (g_linux_wlan == NULL) {
1513 PRINT_ER("g_linux_wlan = NULL\n");
1517 if (pstrWFIDrv == NULL) {
1518 PRINT_ER("pstrWFIDrv = NULL\n");
1522 if ((g_linux_wlan->open_ifcs) > 0) {
1523 g_linux_wlan->open_ifcs--;
1525 PRINT_ER("ERROR: MAC close called while number of opened interfaces is zero\n");
1529 if (nic->wilc_netdev != NULL) {
1530 /* Stop the network interface queue */
1531 netif_stop_queue(nic->wilc_netdev);
1533 wilc_deinit_host_int(nic->wilc_netdev);
1536 if (g_linux_wlan->open_ifcs == 0) {
1537 PRINT_D(GENERIC_DBG, "Deinitializing wilc1000\n");
1538 g_linux_wlan->close = 1;
1539 wilc1000_wlan_deinit(g_linux_wlan);
1540 WILC_WFI_deinit_mon_interface();
1543 up(&close_exit_sync);
1544 nic->mac_opened = 0;
1549 int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
1554 u32 size = 0, length = 0;
1555 perInterface_wlan_t *nic;
1556 struct wilc_priv *priv;
1559 /* struct iwreq *wrq = (struct iwreq *) req; // tony moved to case SIOCSIWPRIV */
1560 nic = netdev_priv(ndev);
1562 if (!g_linux_wlan->initialized)
1570 struct iwreq *wrq = (struct iwreq *) req; /* added by tony */
1572 size = wrq->u.data.length;
1574 if (size && wrq->u.data.pointer) {
1576 buff = memdup_user(wrq->u.data.pointer, wrq->u.data.length);
1578 return PTR_ERR(buff);
1580 if (strncasecmp(buff, "RSSI", length) == 0) {
1581 priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy);
1582 s32Error = host_int_get_rssi(priv->hWILCWFIDrv, &(rssi));
1584 PRINT_ER("Failed to send get rssi param's message queue ");
1585 PRINT_INFO(GENERIC_DBG, "RSSI :%d\n", rssi);
1587 /*Rounding up the rssi negative value*/
1590 snprintf(buff, size, "rssi %d", rssi);
1592 if (copy_to_user(wrq->u.data.pointer, buff, size)) {
1593 PRINT_ER("%s: failed to copy data to user buffer\n", __func__);
1604 PRINT_INFO(GENERIC_DBG, "Command - %d - has been received\n", cmd);
1605 s32Error = -EOPNOTSUPP;
1617 void frmw_to_linux(u8 *buff, u32 size, u32 pkt_offset)
1620 unsigned int frame_len = 0;
1622 unsigned char *buff_to_send = NULL;
1623 struct sk_buff *skb;
1624 struct net_device *wilc_netdev;
1625 perInterface_wlan_t *nic;
1627 wilc_netdev = GetIfHandler(buff);
1628 if (wilc_netdev == NULL)
1632 nic = netdev_priv(wilc_netdev);
1637 buff_to_send = buff;
1639 /* Need to send the packet up to the host, allocate a skb buffer */
1640 skb = dev_alloc_skb(frame_len);
1642 PRINT_ER("Low memory - packet droped\n");
1646 if (g_linux_wlan == NULL || wilc_netdev == NULL)
1647 PRINT_ER("wilc_netdev in g_linux_wlan is NULL");
1648 skb->dev = wilc_netdev;
1650 if (skb->dev == NULL)
1651 PRINT_ER("skb->dev is NULL\n");
1657 * WILC_PRINTF("buff_to_send[%d]=%2x\n",i,buff_to_send[i]);
1661 /* skb_put(skb, frame_len); */
1662 memcpy(skb_put(skb, frame_len), buff_to_send, frame_len);
1664 /* WILC_PRINTF("After MEM_CPY\n"); */
1666 /* nic = netdev_priv(wilc_netdev); */
1668 skb->protocol = eth_type_trans(skb, wilc_netdev);
1669 /* Send the packet to the stack by giving it to the bridge */
1670 nic->netstats.rx_packets++;
1671 nic->netstats.rx_bytes += frame_len;
1672 skb->ip_summed = CHECKSUM_UNNECESSARY;
1673 stats = netif_rx(skb);
1674 PRINT_D(RX_DBG, "netif_rx ret value is: %d\n", stats);
1678 void WILC_WFI_mgmt_rx(u8 *buff, u32 size)
1681 perInterface_wlan_t *nic;
1683 /*Pass the frame on the monitor interface, if any.*/
1684 /*Otherwise, pass it on p2p0 netdev, if registered on it*/
1685 for (i = 0; i < g_linux_wlan->vif_num; i++) {
1686 nic = netdev_priv(g_linux_wlan->vif[i].wilc_netdev);
1687 if (nic->monitor_flag) {
1688 WILC_WFI_monitor_rx(buff, size);
1693 nic = netdev_priv(g_linux_wlan->vif[1].wilc_netdev); /* p2p0 */
1694 if ((buff[0] == nic->g_struct_frame_reg[0].frame_type && nic->g_struct_frame_reg[0].reg) ||
1695 (buff[0] == nic->g_struct_frame_reg[1].frame_type && nic->g_struct_frame_reg[1].reg))
1696 WILC_WFI_p2p_rx(g_linux_wlan->vif[1].wilc_netdev, buff, size);
1699 int wilc_netdev_init(void)
1703 perInterface_wlan_t *nic;
1704 struct net_device *ndev;
1706 sema_init(&close_exit_sync, 0);
1708 /*create the common structure*/
1709 g_linux_wlan = kzalloc(sizeof(*g_linux_wlan), GFP_KERNEL);
1713 register_inetaddr_notifier(&g_dev_notifier);
1715 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
1716 /*allocate first ethernet device with perinterface_wlan_t as its private data*/
1717 ndev = alloc_etherdev(sizeof(perInterface_wlan_t));
1719 PRINT_ER("Failed to allocate ethernet dev\n");
1723 nic = netdev_priv(ndev);
1724 memset(nic, 0, sizeof(perInterface_wlan_t));
1726 /*Name the Devices*/
1728 #if defined(NM73131) /* tony, 2012-09-20 */
1729 strcpy(ndev->name, "wilc_eth%d");
1730 #elif defined(PLAT_CLM9722) /* rachel */
1731 strcpy(ndev->name, "eth%d");
1732 #else /* PANDA_BOARD, PLAT_ALLWINNER_A10, PLAT_ALLWINNER_A20, PLAT_ALLWINNER_A31, PLAT_AML8726_M3 or PLAT_WMS8304 */
1733 strcpy(ndev->name, "wlan%d");
1736 strcpy(ndev->name, "p2p%d");
1738 nic->u8IfIdx = g_linux_wlan->vif_num;
1739 nic->wilc_netdev = ndev;
1740 g_linux_wlan->vif[g_linux_wlan->vif_num].wilc_netdev = ndev;
1741 g_linux_wlan->vif_num++;
1742 ndev->netdev_ops = &wilc_netdev_ops;
1745 struct wireless_dev *wdev;
1747 wdev = wilc_create_wiphy(ndev);
1750 /* set netdev, tony */
1751 SET_NETDEV_DEV(ndev, &local_sdio_func->dev);
1755 PRINT_ER("Can't register WILC Wiphy\n");
1759 /*linking the wireless_dev structure with the netdevice*/
1760 nic->wilc_netdev->ieee80211_ptr = wdev;
1761 nic->wilc_netdev->ml_priv = nic;
1762 wdev->netdev = nic->wilc_netdev;
1763 nic->netstats.rx_packets = 0;
1764 nic->netstats.tx_packets = 0;
1765 nic->netstats.rx_bytes = 0;
1766 nic->netstats.tx_bytes = 0;
1770 if (register_netdev(ndev)) {
1771 PRINT_ER("Device couldn't be registered - %s\n", ndev->name);
1772 return -1; /* ERROR */
1775 nic->iftype = STATION_MODE;
1776 nic->mac_opened = 0;
1781 if (!linux_spi_init(&g_linux_wlan->wilc_spidev)) {
1782 PRINT_ER("Can't initialize SPI\n");
1783 return -1; /* ERROR */
1785 g_linux_wlan->wilc_spidev = wilc_spi_dev;
1787 g_linux_wlan->wilc_sdio_func = local_sdio_func;
1793 /*The 1st function called after module inserted*/
1794 static int __init init_wilc_driver(void)
1796 #if defined(WILC_DEBUGFS)
1797 if (wilc_debugfs_init() < 0) {
1798 PRINT_D(GENERIC_DBG, "fail to create debugfs for wilc driver\n");
1803 printk("IN INIT FUNCTION\n");
1804 printk("*** WILC1000 driver VERSION=[10.2] FW_VER=[10.2] ***\n");
1806 linux_wlan_device_power(1);
1808 linux_wlan_device_detection(1);
1814 ret = sdio_register_driver(&wilc_bus);
1816 PRINT_D(INIT_DBG, "init_wilc_driver: Failed register sdio driver\n");
1821 PRINT_D(INIT_DBG, "Initializing netdev\n");
1822 if (wilc_netdev_init())
1823 PRINT_ER("Couldn't initialize netdev\n");
1827 late_initcall(init_wilc_driver);
1829 static void __exit exit_wilc_driver(void)
1832 perInterface_wlan_t *nic[NUM_CONCURRENT_IFC] = {NULL,};
1833 #define CLOSE_TIMEOUT (12 * 1000)
1835 if ((g_linux_wlan != NULL) && (((g_linux_wlan->vif[0].wilc_netdev) != NULL)
1836 || ((g_linux_wlan->vif[1].wilc_netdev) != NULL))) {
1837 unregister_inetaddr_notifier(&g_dev_notifier);
1839 for (i = 0; i < NUM_CONCURRENT_IFC; i++)
1840 nic[i] = netdev_priv(g_linux_wlan->vif[i].wilc_netdev);
1843 if ((g_linux_wlan != NULL) && g_linux_wlan->wilc_firmware != NULL) {
1844 release_firmware(g_linux_wlan->wilc_firmware);
1845 g_linux_wlan->wilc_firmware = NULL;
1848 if ((g_linux_wlan != NULL) && (((g_linux_wlan->vif[0].wilc_netdev) != NULL)
1849 || ((g_linux_wlan->vif[1].wilc_netdev) != NULL))) {
1850 PRINT_D(INIT_DBG, "Waiting for mac_close ....\n");
1852 if (linux_wlan_lock_timeout(&close_exit_sync, CLOSE_TIMEOUT) < 0)
1853 PRINT_D(INIT_DBG, "Closed TimedOUT\n");
1855 PRINT_D(INIT_DBG, "mac_closed\n");
1857 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
1858 /* close all opened interfaces */
1859 if (g_linux_wlan->vif[i].wilc_netdev != NULL) {
1860 if (nic[i]->mac_opened)
1861 mac_close(g_linux_wlan->vif[i].wilc_netdev);
1864 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
1865 PRINT_D(INIT_DBG, "Unregistering netdev %p\n", g_linux_wlan->vif[i].wilc_netdev);
1866 unregister_netdev(g_linux_wlan->vif[i].wilc_netdev);
1867 PRINT_D(INIT_DBG, "Freeing Wiphy...\n");
1868 wilc_free_wiphy(g_linux_wlan->vif[i].wilc_netdev);
1869 PRINT_D(INIT_DBG, "Freeing netdev...\n");
1870 free_netdev(g_linux_wlan->vif[i].wilc_netdev);
1875 PRINT_D(INIT_DBG, "SPI unregsiter...\n");
1876 spi_unregister_driver(&wilc_bus);
1878 PRINT_D(INIT_DBG, "SDIO unregsiter...\n");
1879 sdio_unregister_driver(&wilc_bus);
1882 kfree(g_linux_wlan);
1883 g_linux_wlan = NULL;
1884 printk("Module_exit Done.\n");
1886 #if defined(WILC_DEBUGFS)
1887 wilc_debugfs_remove();
1890 linux_wlan_device_detection(0);
1891 linux_wlan_device_power(0);
1893 module_exit(exit_wilc_driver);
1895 MODULE_LICENSE("GPL");