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 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
21 #include <linux/inetdevice.h>
23 #include <linux/etherdevice.h>
24 #include <linux/module.h>
25 #include <linux/kernel.h>
26 #include <linux/skbuff.h>
28 #include <linux/version.h>
29 #include <linux/semaphore.h>
32 #include "linux_wlan_sdio.h"
34 #include "linux_wlan_spi.h"
37 #if defined(CUSTOMER_PLATFORM)
39 TODO : Write power control functions as customer platform.
43 #define _linux_wlan_device_power_on() {}
44 #define _linux_wlan_device_power_off() {}
46 #define _linux_wlan_device_detection() {}
47 #define _linux_wlan_device_removal() {}
50 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
51 extern bool g_obtainingIP
;
53 extern u16
Set_machw_change_vir_if(bool bValue
);
54 extern void resolve_disconnect_aberration(void *drvHandler
);
55 extern u8 gau8MulticastMacAddrList
[WILC_MULTICAST_TABLE_SIZE
][ETH_ALEN
];
56 void wilc1000_wlan_deinit(linux_wlan_t
*nic
);
57 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
58 extern struct timer_list hDuringIpTimer
;
61 static int linux_wlan_device_power(int on_off
)
63 PRINT_D(INIT_DBG
, "linux_wlan_device_power.. (%d)\n", on_off
);
66 _linux_wlan_device_power_on();
68 _linux_wlan_device_power_off();
74 static int linux_wlan_device_detection(int on_off
)
76 PRINT_D(INIT_DBG
, "linux_wlan_device_detection.. (%d)\n", on_off
);
80 _linux_wlan_device_detection();
82 _linux_wlan_device_removal();
89 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
90 static int dev_state_ev_handler(struct notifier_block
*this, unsigned long event
, void *ptr
);
92 static struct notifier_block g_dev_notifier
= {
93 .notifier_call
= dev_state_ev_handler
97 #define wilc_wlan_deinit(nic) { if (&g_linux_wlan->oup != NULL) \
98 if (g_linux_wlan->oup.wlan_cleanup != NULL) \
99 g_linux_wlan->oup.wlan_cleanup(); }
102 #define IRQ_NO_WAIT 0
104 * to sync between mac_close and module exit.
105 * don't initialize or de-initialize from init/deinitlocks
106 * to be initialized from module wilc_netdev_init and
107 * deinitialized from mdoule_exit
109 static struct semaphore close_exit_sync
;
111 static int wlan_deinit_locks(linux_wlan_t
*nic
);
112 static void wlan_deinitialize_threads(linux_wlan_t
*nic
);
113 extern void WILC_WFI_monitor_rx(u8
*buff
, u32 size
);
114 extern void WILC_WFI_p2p_rx(struct net_device
*dev
, u8
*buff
, u32 size
);
116 static void linux_wlan_tx_complete(void *priv
, int status
);
117 void frmw_to_linux(u8
*buff
, u32 size
, u32 pkt_offset
);
118 static int mac_init_fn(struct net_device
*ndev
);
119 int mac_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
120 int mac_open(struct net_device
*ndev
);
121 int mac_close(struct net_device
*ndev
);
122 static struct net_device_stats
*mac_stats(struct net_device
*dev
);
123 static int mac_ioctl(struct net_device
*ndev
, struct ifreq
*req
, int cmd
);
124 static void wilc_set_multicast_list(struct net_device
*dev
);
127 * for now - in frmw_to_linux there should be private data to be passed to it
128 * and this data should be pointer to net device
130 linux_wlan_t
*g_linux_wlan
;
131 wilc_wlan_oup_t
*gpstrWlanOps
;
132 bool bEnablePS
= true;
134 static const struct net_device_ops wilc_netdev_ops
= {
135 .ndo_init
= mac_init_fn
,
136 .ndo_open
= mac_open
,
137 .ndo_stop
= mac_close
,
138 .ndo_start_xmit
= mac_xmit
,
139 .ndo_do_ioctl
= mac_ioctl
,
140 .ndo_get_stats
= mac_stats
,
141 .ndo_set_rx_mode
= wilc_set_multicast_list
,
147 extern volatile int timeNo
;
149 #define DEGUG_BUFFER_LENGTH 1000
150 volatile int WatchDogdebuggerCounter
;
151 char DebugBuffer
[DEGUG_BUFFER_LENGTH
+ 20] = {0};
152 static char *ps8current
= DebugBuffer
;
154 void printk_later(const char *format
, ...)
158 va_start(args
, format
);
159 ps8current
+= vsprintf(ps8current
, format
, args
);
161 if ((ps8current
- DebugBuffer
) > DEGUG_BUFFER_LENGTH
)
162 ps8current
= DebugBuffer
;
168 if (DebugBuffer
[0]) {
169 DebugBuffer
[DEGUG_BUFFER_LENGTH
] = 0;
170 PRINT_INFO(GENERIC_DBG
, "early printed\n");
171 PRINT_D(GENERIC_DBG
, ps8current
+ 1);
173 PRINT_INFO(GENERIC_DBG
, "latest printed\n");
174 PRINT_D(GENERIC_DBG
, DebugBuffer
);
176 ps8current
= DebugBuffer
;
180 void Reset_WatchDogdebugger(void)
182 WatchDogdebuggerCounter
= 0;
185 static int DebuggingThreadTask(void *vp
)
188 while (!WatchDogdebuggerCounter
) {
189 PRINT_D(GENERIC_DBG
, "Debug Thread Running %d\n", timeNo
);
190 WatchDogdebuggerCounter
= 1;
194 WatchDogdebuggerCounter
= 0;
199 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
200 static int dev_state_ev_handler(struct notifier_block
*this, unsigned long event
, void *ptr
)
202 struct in_ifaddr
*dev_iface
= (struct in_ifaddr
*)ptr
;
203 struct wilc_priv
*priv
;
204 tstrWILC_WFIDrv
*pstrWFIDrv
;
205 struct net_device
*dev
;
207 perInterface_wlan_t
*nic
;
209 char wlan_dev_name
[5] = "wlan0";
211 if (dev_iface
== NULL
|| dev_iface
->ifa_dev
== NULL
|| dev_iface
->ifa_dev
->dev
== NULL
) {
212 PRINT_D(GENERIC_DBG
, "dev_iface = NULL\n");
216 if ((memcmp(dev_iface
->ifa_label
, "wlan0", 5)) && (memcmp(dev_iface
->ifa_label
, "p2p0", 4))) {
217 PRINT_D(GENERIC_DBG
, "Interface is neither WLAN0 nor P2P0\n");
221 dev
= (struct net_device
*)dev_iface
->ifa_dev
->dev
;
222 if (dev
->ieee80211_ptr
== NULL
|| dev
->ieee80211_ptr
->wiphy
== NULL
) {
223 PRINT_D(GENERIC_DBG
, "No Wireless registerd\n");
226 priv
= wiphy_priv(dev
->ieee80211_ptr
->wiphy
);
228 PRINT_D(GENERIC_DBG
, "No Wireless Priv\n");
231 pstrWFIDrv
= (tstrWILC_WFIDrv
*)priv
->hWILCWFIDrv
;
232 nic
= netdev_priv(dev
);
233 if (nic
== NULL
|| pstrWFIDrv
== NULL
) {
234 PRINT_D(GENERIC_DBG
, "No Wireless Priv\n");
238 PRINT_INFO(GENERIC_DBG
, "dev_state_ev_handler +++\n"); /* tony */
242 PRINT_D(GENERIC_DBG
, "dev_state_ev_handler event=NETDEV_UP %p\n", dev
); /* tony */
244 PRINT_INFO(GENERIC_DBG
, "\n ============== IP Address Obtained ===============\n\n");
246 /*If we are in station mode or client mode*/
247 if (nic
->iftype
== STATION_MODE
|| nic
->iftype
== CLIENT_MODE
) {
248 pstrWFIDrv
->IFC_UP
= 1;
249 g_obtainingIP
= false;
250 del_timer(&hDuringIpTimer
);
251 PRINT_D(GENERIC_DBG
, "IP obtained , enable scan\n");
255 host_int_set_power_mgmt(pstrWFIDrv
, 1, 0);
257 PRINT_D(GENERIC_DBG
, "[%s] Up IP\n", dev_iface
->ifa_label
);
259 pIP_Add_buff
= (char *) (&(dev_iface
->ifa_address
));
260 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]);
261 host_int_setup_ipaddress(pstrWFIDrv
, pIP_Add_buff
, nic
->u8IfIdx
);
266 PRINT_D(GENERIC_DBG
, "dev_state_ev_handler event=NETDEV_DOWN %p\n", dev
); /* tony */
268 PRINT_INFO(GENERIC_DBG
, "\n ============== IP Address Released ===============\n\n");
269 if (nic
->iftype
== STATION_MODE
|| nic
->iftype
== CLIENT_MODE
) {
270 pstrWFIDrv
->IFC_UP
= 0;
271 g_obtainingIP
= false;
274 if (memcmp(dev_iface
->ifa_label
, wlan_dev_name
, 5) == 0)
275 host_int_set_power_mgmt(pstrWFIDrv
, 0, 0);
277 resolve_disconnect_aberration(pstrWFIDrv
);
279 PRINT_D(GENERIC_DBG
, "[%s] Down IP\n", dev_iface
->ifa_label
);
281 pIP_Add_buff
= null_ip
;
282 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]);
284 host_int_setup_ipaddress(pstrWFIDrv
, pIP_Add_buff
, nic
->u8IfIdx
);
289 PRINT_INFO(GENERIC_DBG
, "dev_state_ev_handler event=default\n"); /* tony */
290 PRINT_INFO(GENERIC_DBG
, "[%s] unknown dev event: %lu\n", dev_iface
->ifa_label
, event
);
301 * Interrupt initialization and handling functions
304 void linux_wlan_enable_irq(void)
307 #if (RX_BH_TYPE != RX_BH_THREADED_IRQ)
308 #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
309 PRINT_D(INT_DBG
, "Enabling IRQ ...\n");
310 enable_irq(g_linux_wlan
->dev_irq_num
);
315 void linux_wlan_disable_irq(int wait
)
317 #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
319 PRINT_D(INT_DBG
, "Disabling IRQ ...\n");
320 disable_irq(g_linux_wlan
->dev_irq_num
);
322 PRINT_D(INT_DBG
, "Disabling IRQ ...\n");
323 disable_irq_nosync(g_linux_wlan
->dev_irq_num
);
328 #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
329 static irqreturn_t
isr_uh_routine(int irq
, void *user_data
)
331 #if (RX_BH_TYPE != RX_BH_THREADED_IRQ)
332 linux_wlan_disable_irq(IRQ_NO_WAIT
);
334 PRINT_D(INT_DBG
, "Interrupt received UH\n");
336 /*While mac is closing cacncel the handling of any interrupts received*/
337 if (g_linux_wlan
->close
) {
338 PRINT_ER("Driver is CLOSING: Can't handle UH interrupt\n");
339 #if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
346 #if (RX_BH_TYPE == RX_BH_WORK_QUEUE)
347 schedule_work(&g_linux_wlan
->rx_work_queue
);
349 #elif (RX_BH_TYPE == RX_BH_KTHREAD)
350 up(&g_linux_wlan
->rx_sem
);
352 #elif (RX_BH_TYPE == RX_BH_THREADED_IRQ)
353 return IRQ_WAKE_THREAD
;
359 #if (RX_BH_TYPE == RX_BH_WORK_QUEUE || RX_BH_TYPE == RX_BH_THREADED_IRQ)
361 #if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
362 irqreturn_t
isr_bh_routine(int irq
, void *userdata
)
366 nic
= (linux_wlan_t
*)userdata
;
368 static void isr_bh_routine(struct work_struct
*work
)
370 perInterface_wlan_t
*nic
;
372 nic
= (perInterface_wlan_t
*)container_of(work
, linux_wlan_t
, rx_work_queue
);
375 /*While mac is closing cacncel the handling of any interrupts received*/
376 if (g_linux_wlan
->close
) {
377 PRINT_ER("Driver is CLOSING: Can't handle BH interrupt\n");
378 #if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
385 PRINT_D(INT_DBG
, "Interrupt received BH\n");
386 if (g_linux_wlan
->oup
.wlan_handle_rx_isr
!= 0)
387 g_linux_wlan
->oup
.wlan_handle_rx_isr();
389 PRINT_ER("wlan_handle_rx_isr() hasn't been initialized\n");
391 #if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
395 #elif (RX_BH_TYPE == RX_BH_KTHREAD)
396 static int isr_bh_routine(void *vp
)
400 nic
= (linux_wlan_t
*)vp
;
404 if (g_linux_wlan
->close
) {
406 while (!kthread_should_stop())
411 PRINT_D(INT_DBG
, "Interrupt received BH\n");
412 if (g_linux_wlan
->oup
.wlan_handle_rx_isr
!= NULL
)
413 g_linux_wlan
->oup
.wlan_handle_rx_isr();
415 PRINT_ER("wlan_handle_rx_isr() hasn't been initialized\n");
422 #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
423 static int init_irq(linux_wlan_t
*p_nic
)
426 linux_wlan_t
*nic
= p_nic
;
428 /*initialize GPIO and register IRQ num*/
430 if ((gpio_request(GPIO_NUM
, "WILC_INTR") == 0) &&
431 (gpio_direction_input(GPIO_NUM
) == 0)) {
432 #if defined(CUSTOMER_PLATFORM)
434 TODO : save the registerd irq number to the private wilc context in kernel.
436 * ex) nic->dev_irq_num = gpio_to_irq(GPIO_NUM);
438 #elif defined(PANDA_BOARD)
439 gpio_export(GPIO_NUM
, 1);
440 nic
->dev_irq_num
= OMAP_GPIO_IRQ(GPIO_NUM
);
441 irq_set_irq_type(nic
->dev_irq_num
, IRQ_TYPE_LEVEL_LOW
);
443 nic
->dev_irq_num
= gpio_to_irq(GPIO_NUM
);
447 PRINT_ER("could not obtain gpio for WILC_INTR\n");
450 #if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
451 if ((ret
!= -1) && (request_threaded_irq(nic
->dev_irq_num
, isr_uh_routine
, isr_bh_routine
,
452 IRQF_TRIGGER_LOW
| IRQF_ONESHOT
, /*Without IRQF_ONESHOT the uh will remain kicked in and dont gave a chance to bh*/
453 "WILC_IRQ", nic
)) < 0) {
457 if ((ret
!= -1) && (request_irq(nic
->dev_irq_num
, isr_uh_routine
,
458 IRQF_TRIGGER_LOW
, "WILC_IRQ", nic
) < 0)) {
461 PRINT_ER("Failed to request IRQ for GPIO: %d\n", GPIO_NUM
);
465 PRINT_D(INIT_DBG
, "IRQ request succeeded IRQ-NUM= %d on GPIO: %d\n",
466 nic
->dev_irq_num
, GPIO_NUM
);
473 static void deinit_irq(linux_wlan_t
*nic
)
475 #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
476 /* Deintialize IRQ */
477 if (&nic
->dev_irq_num
!= 0) {
478 free_irq(nic
->dev_irq_num
, g_linux_wlan
);
488 static void linux_wlan_dbg(u8
*buff
)
490 PRINT_D(INIT_DBG
, "%d\n", *buff
);
493 static int linux_wlan_lock_timeout(void *vp
, u32 timeout
)
497 PRINT_D(LOCK_DBG
, "Locking %p\n", vp
);
499 error
= down_timeout((struct semaphore
*)vp
, msecs_to_jiffies(timeout
));
501 PRINT_ER("Failed, mutex is NULL\n");
505 static void linux_wlan_mac_indicate(int flag
)
507 /*I have to do it that way becuase there is no mean to encapsulate device pointer
510 linux_wlan_t
*pd
= g_linux_wlan
;
513 if (flag
== WILC_MAC_INDICATE_STATUS
) {
514 pd
->oup
.wlan_cfg_get_value(WID_STATUS
, (unsigned char *)&status
, 4);
515 if (pd
->mac_status
== WILC_MAC_STATUS_INIT
) {
516 pd
->mac_status
= status
;
519 pd
->mac_status
= status
;
522 if (pd
->mac_status
== WILC_MAC_STATUS_CONNECT
) { /* Connect */
525 } else if (flag
== WILC_MAC_INDICATE_SCAN
) {
526 PRINT_D(GENERIC_DBG
, "Scanning ...\n");
532 struct net_device
*GetIfHandler(u8
*pMacHeader
)
537 Bssid
= pMacHeader
+ 10;
538 Bssid1
= pMacHeader
+ 4;
540 for (i
= 0; i
< g_linux_wlan
->u8NoIfcs
; i
++) {
541 if (!memcmp(Bssid1
, g_linux_wlan
->strInterfaceInfo
[i
].aBSSID
, ETH_ALEN
) ||
542 !memcmp(Bssid
, g_linux_wlan
->strInterfaceInfo
[i
].aBSSID
, ETH_ALEN
)) {
543 return g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
;
546 PRINT_INFO(INIT_DBG
, "Invalide handle\n");
547 for (i
= 0; i
< 25; i
++)
548 PRINT_D(INIT_DBG
, "%02x ", pMacHeader
[i
]);
549 Bssid
= pMacHeader
+ 18;
550 Bssid1
= pMacHeader
+ 12;
551 for (i
= 0; i
< g_linux_wlan
->u8NoIfcs
; i
++) {
552 if (!memcmp(Bssid1
, g_linux_wlan
->strInterfaceInfo
[i
].aBSSID
, ETH_ALEN
) ||
553 !memcmp(Bssid
, g_linux_wlan
->strInterfaceInfo
[i
].aBSSID
, ETH_ALEN
)) {
554 PRINT_D(INIT_DBG
, "Ctx [%p]\n", g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
);
555 return g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
;
558 PRINT_INFO(INIT_DBG
, "\n");
562 int linux_wlan_set_bssid(struct net_device
*wilc_netdev
, u8
*pBSSID
)
567 PRINT_D(INIT_DBG
, "set bssid on[%p]\n", wilc_netdev
);
568 for (i
= 0; i
< g_linux_wlan
->u8NoIfcs
; i
++) {
569 if (g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
== wilc_netdev
) {
570 PRINT_D(INIT_DBG
, "set bssid [%x][%x][%x]\n", pBSSID
[0], pBSSID
[1], pBSSID
[2]);
571 memcpy(g_linux_wlan
->strInterfaceInfo
[i
].aBSSID
, pBSSID
, 6);
580 /*Function to get number of connected interfaces*/
581 int linux_wlan_get_num_conn_ifcs(void)
584 u8 null_bssid
[6] = {0};
587 for (i
= 0; i
< g_linux_wlan
->u8NoIfcs
; i
++) {
588 if (memcmp(g_linux_wlan
->strInterfaceInfo
[i
].aBSSID
, null_bssid
, 6))
594 static int linux_wlan_rxq_task(void *vp
)
597 /* inform wilc1000_wlan_init that RXQ task is started. */
598 up(&g_linux_wlan
->rxq_thread_started
);
600 down(&g_linux_wlan
->rxq_event
);
601 /* wait_for_completion(&g_linux_wlan->rxq_event); */
603 if (g_linux_wlan
->close
) {
604 /*Unlock the mutex in the mac_close function to indicate the exiting of the RX thread */
605 up(&g_linux_wlan
->rxq_thread_started
);
607 while (!kthread_should_stop())
610 PRINT_D(RX_DBG
, " RX thread stopped\n");
613 PRINT_D(RX_DBG
, "Calling wlan_handle_rx_que()\n");
615 g_linux_wlan
->oup
.wlan_handle_rx_que();
620 #define USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
622 static int linux_wlan_txq_task(void *vp
)
626 #if defined USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
627 #define TX_BACKOFF_WEIGHT_INCR_STEP (1)
628 #define TX_BACKOFF_WEIGHT_DECR_STEP (1)
629 #define TX_BACKOFF_WEIGHT_MAX (7)
630 #define TX_BACKOFF_WEIGHT_MIN (0)
631 #define TX_BACKOFF_WEIGHT_UNIT_MS (10)
632 int backoff_weight
= TX_BACKOFF_WEIGHT_MIN
;
635 /* inform wilc1000_wlan_init that TXQ task is started. */
636 up(&g_linux_wlan
->txq_thread_started
);
639 PRINT_D(TX_DBG
, "txq_task Taking a nap :)\n");
640 down(&g_linux_wlan
->txq_event
);
641 /* wait_for_completion(&pd->txq_event); */
642 PRINT_D(TX_DBG
, "txq_task Who waked me up :$\n");
644 if (g_linux_wlan
->close
) {
645 /*Unlock the mutex in the mac_close function to indicate the exiting of the TX thread */
646 up(&g_linux_wlan
->txq_thread_started
);
648 while (!kthread_should_stop())
651 PRINT_D(TX_DBG
, "TX thread stopped\n");
654 PRINT_D(TX_DBG
, "txq_task handle the sending packet and let me go to sleep.\n");
655 #if !defined USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
656 g_linux_wlan
->oup
.wlan_handle_tx_que();
659 ret
= g_linux_wlan
->oup
.wlan_handle_tx_que(&txq_count
);
660 if (txq_count
< FLOW_CONTROL_LOWER_THRESHOLD
/* && netif_queue_stopped(pd->wilc_netdev)*/) {
661 PRINT_D(TX_DBG
, "Waking up queue\n");
662 /* netif_wake_queue(pd->wilc_netdev); */
663 if (netif_queue_stopped(g_linux_wlan
->strInterfaceInfo
[0].wilc_netdev
))
664 netif_wake_queue(g_linux_wlan
->strInterfaceInfo
[0].wilc_netdev
);
665 if (netif_queue_stopped(g_linux_wlan
->strInterfaceInfo
[1].wilc_netdev
))
666 netif_wake_queue(g_linux_wlan
->strInterfaceInfo
[1].wilc_netdev
);
669 if (ret
== WILC_TX_ERR_NO_BUF
) { /* failed to allocate buffers in chip. */
671 /* Back off from sending packets for some time. */
672 /* schedule_timeout will allow RX task to run and free buffers.*/
673 /* set_current_state(TASK_UNINTERRUPTIBLE); */
674 /* timeout = schedule_timeout(timeout); */
675 msleep(TX_BACKOFF_WEIGHT_UNIT_MS
<< backoff_weight
);
676 } while (/*timeout*/ 0);
677 backoff_weight
+= TX_BACKOFF_WEIGHT_INCR_STEP
;
678 if (backoff_weight
> TX_BACKOFF_WEIGHT_MAX
)
679 backoff_weight
= TX_BACKOFF_WEIGHT_MAX
;
681 if (backoff_weight
> TX_BACKOFF_WEIGHT_MIN
) {
682 backoff_weight
-= TX_BACKOFF_WEIGHT_DECR_STEP
;
683 if (backoff_weight
< TX_BACKOFF_WEIGHT_MIN
)
684 backoff_weight
= TX_BACKOFF_WEIGHT_MIN
;
687 /*TODO: drop packets after a certain time/number of retry count. */
688 } while (ret
== WILC_TX_ERR_NO_BUF
&& !g_linux_wlan
->close
); /* retry sending packets if no more buffers in chip. */
694 static void linux_wlan_rx_complete(void)
696 PRINT_D(RX_DBG
, "RX completed\n");
699 int linux_wlan_get_firmware(perInterface_wlan_t
*p_nic
)
702 perInterface_wlan_t
*nic
= p_nic
;
704 const struct firmware
*wilc_firmware
;
707 if (nic
->iftype
== AP_MODE
)
708 firmware
= AP_FIRMWARE
;
709 else if (nic
->iftype
== STATION_MODE
)
710 firmware
= STA_FIRMWARE
;
714 PRINT_D(INIT_DBG
, "Get P2P_CONCURRENCY_FIRMWARE\n");
715 firmware
= P2P_CONCURRENCY_FIRMWARE
;
719 PRINT_ER("NIC is NULL\n");
723 if (&nic
->wilc_netdev
->dev
== NULL
) {
724 PRINT_ER("&nic->wilc_netdev->dev is NULL\n");
728 /* the firmare should be located in /lib/firmware in
729 * root file system with the name specified above */
732 if (request_firmware(&wilc_firmware
, firmware
, &g_linux_wlan
->wilc_sdio_func
->dev
) != 0) {
733 PRINT_ER("%s - firmare not available\n", firmware
);
738 if (request_firmware(&wilc_firmware
, firmware
, &g_linux_wlan
->wilc_spidev
->dev
) != 0) {
739 PRINT_ER("%s - firmare not available\n", firmware
);
744 g_linux_wlan
->wilc_firmware
= wilc_firmware
; /* Bug 4703 */
752 #ifdef COMPLEMENT_BOOT
753 int repeat_power_cycle(perInterface_wlan_t
*nic
);
756 static int linux_wlan_start_firmware(perInterface_wlan_t
*nic
)
761 PRINT_D(INIT_DBG
, "Starting Firmware ...\n");
762 ret
= g_linux_wlan
->oup
.wlan_start();
764 PRINT_ER("Failed to start Firmware\n");
768 /* wait for mac ready */
769 PRINT_D(INIT_DBG
, "Waiting for Firmware to get ready ...\n");
770 ret
= linux_wlan_lock_timeout(&g_linux_wlan
->sync_event
, 5000);
772 #ifdef COMPLEMENT_BOOT
773 static int timeout
= 5;
776 PRINT_D(INIT_DBG
, "repeat power cycle[%d]", timeout
);
777 ret
= repeat_power_cycle(nic
);
784 PRINT_D(INIT_DBG
, "Firmware start timed out");
788 * TODO: Driver shouoldn't wait forever for firmware to get started -
789 * in case of timeout this should be handled properly
791 PRINT_D(INIT_DBG
, "Firmware successfully started\n");
796 static int linux_wlan_firmware_download(linux_wlan_t
*p_nic
)
801 if (g_linux_wlan
->wilc_firmware
== NULL
) {
802 PRINT_ER("Firmware buffer is NULL\n");
807 * do the firmware download
809 PRINT_D(INIT_DBG
, "Downloading Firmware ...\n");
810 ret
= g_linux_wlan
->oup
.wlan_firmware_download(g_linux_wlan
->wilc_firmware
->data
, g_linux_wlan
->wilc_firmware
->size
);
814 /* Freeing FW buffer */
815 PRINT_D(INIT_DBG
, "Freeing FW buffer ...\n");
816 PRINT_D(INIT_DBG
, "Releasing firmware\n");
817 release_firmware(g_linux_wlan
->wilc_firmware
);
818 g_linux_wlan
->wilc_firmware
= NULL
;
820 PRINT_D(INIT_DBG
, "Download Succeeded\n");
826 /* startup configuration - could be changed later using iconfig*/
827 static int linux_wlan_init_test_config(struct net_device
*dev
, linux_wlan_t
*p_nic
)
830 unsigned char c_val
[64];
831 unsigned char mac_add
[] = {0x00, 0x80, 0xC2, 0x5E, 0xa2, 0xff};
834 struct wilc_priv
*priv
;
835 tstrWILC_WFIDrv
*pstrWFIDrv
;
837 PRINT_D(TX_DBG
, "Start configuring Firmware\n");
838 get_random_bytes(&mac_add
[5], 1);
839 get_random_bytes(&mac_add
[4], 1);
840 priv
= wiphy_priv(dev
->ieee80211_ptr
->wiphy
);
841 pstrWFIDrv
= (tstrWILC_WFIDrv
*)priv
->hWILCWFIDrv
;
842 PRINT_D(INIT_DBG
, "Host = %p\n", pstrWFIDrv
);
844 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]);
847 if (g_linux_wlan
->oup
.wlan_cfg_set
== NULL
) {
848 PRINT_D(INIT_DBG
, "Null p[ointer\n");
854 if (!g_linux_wlan
->oup
.wlan_cfg_set(1, WID_SET_DRV_HANDLER
, c_val
, 4, 0, 0))
857 /*to tell fw that we are going to use PC test - WILC specific*/
859 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_PC_TEST_MODE
, c_val
, 1, 0, 0))
862 c_val
[0] = INFRASTRUCTURE
;
863 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_BSS_TYPE
, c_val
, 1, 0, 0))
866 /* c_val[0] = RATE_AUTO; / * bug 4275: Enable autorate and limit it to 24Mbps * / */
867 c_val
[0] = RATE_AUTO
;
868 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_CURRENT_TX_RATE
, c_val
, 1, 0, 0))
871 c_val
[0] = G_MIXED_11B_2_MODE
;
872 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11G_OPERATING_MODE
, c_val
, 1, 0, 0))
876 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_CURRENT_CHANNEL
, c_val
, 1, 0, 0))
879 c_val
[0] = G_SHORT_PREAMBLE
;
880 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_PREAMBLE
, c_val
, 1, 0, 0))
883 c_val
[0] = AUTO_PROT
;
884 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_PROT_MECH
, c_val
, 1, 0, 0))
887 c_val
[0] = ACTIVE_SCAN
;
888 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_SCAN_TYPE
, c_val
, 1, 0, 0))
891 c_val
[0] = SITE_SURVEY_OFF
;
892 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_SITE_SURVEY
, c_val
, 1, 0, 0))
895 *((int *)c_val
) = 0xffff; /* Never use RTS-CTS */
896 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_RTS_THRESHOLD
, c_val
, 2, 0, 0))
899 *((int *)c_val
) = 2346;
900 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_FRAG_THRESHOLD
, c_val
, 2, 0, 0))
904 /* -------------------------------------------------------------- */
905 /* Configuration : String with length less than 32 bytes */
906 /* Values to set : Any string with length less than 32 bytes */
907 /* ( In BSS Station Set SSID to "" (null string) */
908 /* to enable Broadcast SSID suppport ) */
909 /* -------------------------------------------------------------- */
911 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_BCAST_SSID
, c_val
, 1, 0, 0))
915 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_QOS_ENABLE
, c_val
, 1, 0, 0))
918 c_val
[0] = NO_POWERSAVE
;
919 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_POWER_MANAGEMENT
, c_val
, 1, 0, 0))
922 c_val
[0] = NO_ENCRYPT
; /* NO_ENCRYPT, 0x79 */
923 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11I_MODE
, c_val
, 1, 0, 0))
926 c_val
[0] = OPEN_SYSTEM
;
927 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_AUTH_TYPE
, c_val
, 1, 0, 0))
930 /* WEP/802 11I Configuration */
931 /* ------------------------------------------------------------------ */
932 /* Configuration : WEP Key */
933 /* Values (0x) : 5 byte for WEP40 and 13 bytes for WEP104 */
934 /* In case more than 5 bytes are passed on for WEP 40 */
935 /* only first 5 bytes will be used as the key */
936 /* ------------------------------------------------------------------ */
938 strcpy(c_val
, "123456790abcdef1234567890");
939 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_WEP_KEY_VALUE
, c_val
, (strlen(c_val
) + 1), 0, 0))
942 /* WEP/802 11I Configuration */
943 /* ------------------------------------------------------------------ */
944 /* Configuration : AES/TKIP WPA/RSNA Pre-Shared Key */
945 /* Values to set : Any string with length greater than equal to 8 bytes */
946 /* and less than 64 bytes */
947 /* ------------------------------------------------------------------ */
948 strcpy(c_val
, "12345678");
949 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11I_PSK
, c_val
, (strlen(c_val
)), 0, 0))
952 /* IEEE802.1X Key Configuration */
953 /* ------------------------------------------------------------------ */
954 /* Configuration : Radius Server Access Secret Key */
955 /* Values to set : Any string with length greater than equal to 8 bytes */
956 /* and less than 65 bytes */
957 /* ------------------------------------------------------------------ */
958 strcpy(c_val
, "password");
959 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_1X_KEY
, c_val
, (strlen(c_val
) + 1), 0, 0))
962 /* IEEE802.1X Server Address Configuration */
963 /* ------------------------------------------------------------------ */
964 /* Configuration : Radius Server IP Address */
965 /* Values to set : Any valid IP Address */
966 /* ------------------------------------------------------------------ */
971 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_1X_SERV_ADDR
, c_val
, 4, 0, 0))
975 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_LISTEN_INTERVAL
, c_val
, 1, 0, 0))
979 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_DTIM_PERIOD
, c_val
, 1, 0, 0))
982 c_val
[0] = NORMAL_ACK
;
983 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_ACK_POLICY
, c_val
, 1, 0, 0))
987 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_USER_CONTROL_ON_TX_POWER
, c_val
, 1, 0, 0))
991 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_TX_POWER_LEVEL_11A
, c_val
, 1, 0, 0))
995 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_TX_POWER_LEVEL_11B
, c_val
, 1, 0, 0))
998 /* Beacon Interval */
999 /* -------------------------------------------------------------------- */
1000 /* Configuration : Sets the beacon interval value */
1001 /* Values to set : Any 16-bit value */
1002 /* -------------------------------------------------------------------- */
1004 *((int *)c_val
) = 100;
1005 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_BEACON_INTERVAL
, c_val
, 2, 0, 0))
1008 c_val
[0] = REKEY_DISABLE
;
1009 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_REKEY_POLICY
, c_val
, 1, 0, 0))
1012 /* Rekey Time (s) (Used only when the Rekey policy is 2 or 4) */
1013 /* -------------------------------------------------------------------- */
1014 /* Configuration : Sets the Rekey Time (s) */
1015 /* Values to set : 32-bit value */
1016 /* -------------------------------------------------------------------- */
1017 *((int *)c_val
) = 84600;
1018 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_REKEY_PERIOD
, c_val
, 4, 0, 0))
1021 /* Rekey Packet Count (in 1000s; used when Rekey Policy is 3) */
1022 /* -------------------------------------------------------------------- */
1023 /* Configuration : Sets Rekey Group Packet count */
1024 /* Values to set : 32-bit Value */
1025 /* -------------------------------------------------------------------- */
1026 *((int *)c_val
) = 500;
1027 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_REKEY_PACKET_COUNT
, c_val
, 4, 0, 0))
1031 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_SHORT_SLOT_ALLOWED
, c_val
, 1, 0, 0))
1034 c_val
[0] = G_SELF_CTS_PROT
;
1035 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_ERP_PROT_TYPE
, c_val
, 1, 0, 0))
1038 c_val
[0] = 1; /* Enable N */
1039 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_ENABLE
, c_val
, 1, 0, 0))
1042 c_val
[0] = HT_MIXED_MODE
;
1043 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_OPERATING_MODE
, c_val
, 1, 0, 0))
1046 c_val
[0] = 1; /* TXOP Prot disable in N mode: No RTS-CTS on TX A-MPDUs to save air-time. */
1047 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_TXOP_PROT_DISABLE
, c_val
, 1, 0, 0))
1050 memcpy(c_val
, mac_add
, 6);
1052 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_MAC_ADDR
, c_val
, 6, 0, 0))
1058 c_val
[0] = DETECT_PROTECT_REPORT
;
1059 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_OBSS_NONHT_DETECTION
, c_val
, 1, 0, 0))
1062 c_val
[0] = RTS_CTS_NONHT_PROT
;
1063 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_HT_PROT_TYPE
, c_val
, 1, 0, 0))
1067 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_RIFS_PROT_ENABLE
, c_val
, 1, 0, 0))
1070 c_val
[0] = MIMO_MODE
;
1071 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_SMPS_MODE
, c_val
, 1, 0, 0))
1075 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_CURRENT_TX_MCS
, c_val
, 1, 0, 0))
1078 c_val
[0] = 1; /* Enable N with immediate block ack. */
1079 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_IMMEDIATE_BA_ENABLED
, c_val
, 1, 1, 1))
1088 /**************************/
1089 void wilc1000_wlan_deinit(linux_wlan_t
*nic
)
1092 if (g_linux_wlan
->wilc1000_initialized
) {
1094 printk("Deinitializing wilc1000 ...\n");
1097 PRINT_ER("nic is NULL\n");
1101 #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
1102 /* johnny : remove */
1103 PRINT_D(INIT_DBG
, "skip wilc_bus_set_default_speed\n");
1105 wilc_bus_set_default_speed();
1108 PRINT_D(INIT_DBG
, "Disabling IRQ\n");
1109 #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
1110 linux_wlan_disable_irq(IRQ_WAIT
);
1112 #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
1115 mutex_lock(&g_linux_wlan
->hif_cs
);
1116 disable_sdio_interrupt();
1117 mutex_unlock(&g_linux_wlan
->hif_cs
);
1121 /* not sure if the following unlocks are needed or not*/
1122 if (&g_linux_wlan
->rxq_event
!= NULL
)
1123 up(&g_linux_wlan
->rxq_event
);
1125 if (&g_linux_wlan
->txq_event
!= NULL
)
1126 up(&g_linux_wlan
->txq_event
);
1128 #if (RX_BH_TYPE == RX_BH_WORK_QUEUE)
1129 /*Removing the work struct from the linux kernel workqueue*/
1130 if (&g_linux_wlan
->rx_work_queue
!= NULL
)
1131 flush_work(&g_linux_wlan
->rx_work_queue
);
1133 #elif (RX_BH_TYPE == RX_BH_KTHREAD)
1134 /* if(&nic->rx_sem != NULL) */
1135 /* up(&nic->rx_sem); */
1138 PRINT_D(INIT_DBG
, "Deinitializing Threads\n");
1139 wlan_deinitialize_threads(nic
);
1141 PRINT_D(INIT_DBG
, "Deinitializing IRQ\n");
1142 deinit_irq(g_linux_wlan
);
1144 if (&g_linux_wlan
->oup
!= NULL
) {
1145 if (g_linux_wlan
->oup
.wlan_stop
!= NULL
)
1146 g_linux_wlan
->oup
.wlan_stop();
1149 PRINT_D(INIT_DBG
, "Deinitializing WILC Wlan\n");
1150 wilc_wlan_deinit(nic
);
1151 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
1152 #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
1153 PRINT_D(INIT_DBG
, "Disabling IRQ 2\n");
1155 mutex_lock(&g_linux_wlan
->hif_cs
);
1156 disable_sdio_interrupt();
1157 mutex_unlock(&g_linux_wlan
->hif_cs
);
1161 /*De-Initialize locks*/
1162 PRINT_D(INIT_DBG
, "Deinitializing Locks\n");
1163 wlan_deinit_locks(g_linux_wlan
);
1165 /* announce that wilc1000 is not initialized */
1166 g_linux_wlan
->wilc1000_initialized
= 0;
1168 PRINT_D(INIT_DBG
, "wilc1000 deinitialization Done\n");
1171 PRINT_D(INIT_DBG
, "wilc1000 is not initialized\n");
1175 int wlan_init_locks(linux_wlan_t
*p_nic
)
1178 PRINT_D(INIT_DBG
, "Initializing Locks ...\n");
1180 mutex_init(&g_linux_wlan
->hif_cs
);
1181 mutex_init(&g_linux_wlan
->rxq_cs
);
1182 mutex_init(&g_linux_wlan
->txq_cs
);
1184 /*Added by Amr - BugID_4720*/
1185 spin_lock_init(&g_linux_wlan
->txq_spinlock
);
1186 sema_init(&g_linux_wlan
->txq_add_to_head_cs
, 1);
1188 sema_init(&g_linux_wlan
->txq_event
, 0);
1189 sema_init(&g_linux_wlan
->rxq_event
, 0);
1191 sema_init(&g_linux_wlan
->cfg_event
, 0);
1192 sema_init(&g_linux_wlan
->sync_event
, 0);
1194 sema_init(&g_linux_wlan
->rxq_thread_started
, 0);
1195 sema_init(&g_linux_wlan
->txq_thread_started
, 0);
1197 #if (RX_BH_TYPE == RX_BH_KTHREAD)
1198 sema_init(&g_linux_wlan
->rx_sem
, 0);
1204 static int wlan_deinit_locks(linux_wlan_t
*nic
)
1206 PRINT_D(INIT_DBG
, "De-Initializing Locks\n");
1208 if (&g_linux_wlan
->hif_cs
!= NULL
)
1209 mutex_destroy(&g_linux_wlan
->hif_cs
);
1211 if (&g_linux_wlan
->rxq_cs
!= NULL
)
1212 mutex_destroy(&g_linux_wlan
->rxq_cs
);
1214 if (&g_linux_wlan
->txq_cs
!= NULL
)
1215 mutex_destroy(&g_linux_wlan
->txq_cs
);
1219 void linux_to_wlan(wilc_wlan_inp_t
*nwi
, linux_wlan_t
*nic
)
1222 PRINT_D(INIT_DBG
, "Linux to Wlan services ...\n");
1224 nwi
->os_context
.hif_critical_section
= (void *)&g_linux_wlan
->hif_cs
;
1225 nwi
->os_context
.os_private
= (void *)nic
;
1226 nwi
->os_context
.tx_buffer_size
= LINUX_TX_SIZE
;
1227 nwi
->os_context
.txq_critical_section
= (void *)&g_linux_wlan
->txq_cs
;
1229 /*Added by Amr - BugID_4720*/
1230 nwi
->os_context
.txq_add_to_head_critical_section
= (void *)&g_linux_wlan
->txq_add_to_head_cs
;
1232 /*Added by Amr - BugID_4720*/
1233 nwi
->os_context
.txq_spin_lock
= (void *)&g_linux_wlan
->txq_spinlock
;
1235 nwi
->os_context
.txq_wait_event
= (void *)&g_linux_wlan
->txq_event
;
1237 #if defined(MEMORY_STATIC)
1238 nwi
->os_context
.rx_buffer_size
= LINUX_RX_SIZE
;
1240 nwi
->os_context
.rxq_critical_section
= (void *)&g_linux_wlan
->rxq_cs
;
1241 nwi
->os_context
.rxq_wait_event
= (void *)&g_linux_wlan
->rxq_event
;
1242 nwi
->os_context
.cfg_wait_event
= (void *)&g_linux_wlan
->cfg_event
;
1244 nwi
->os_func
.os_debug
= linux_wlan_dbg
;
1245 nwi
->os_func
.os_wait
= linux_wlan_lock_timeout
;
1248 nwi
->io_func
.io_type
= HIF_SDIO
;
1249 nwi
->io_func
.io_init
= linux_sdio_init
;
1250 nwi
->io_func
.io_deinit
= linux_sdio_deinit
;
1251 nwi
->io_func
.u
.sdio
.sdio_cmd52
= linux_sdio_cmd52
;
1252 nwi
->io_func
.u
.sdio
.sdio_cmd53
= linux_sdio_cmd53
;
1253 nwi
->io_func
.u
.sdio
.sdio_set_max_speed
= linux_sdio_set_max_speed
;
1254 nwi
->io_func
.u
.sdio
.sdio_set_default_speed
= linux_sdio_set_default_speed
;
1256 nwi
->io_func
.io_type
= HIF_SPI
;
1257 nwi
->io_func
.io_init
= linux_spi_init
;
1258 nwi
->io_func
.io_deinit
= linux_spi_deinit
;
1259 nwi
->io_func
.u
.spi
.spi_tx
= linux_spi_write
;
1260 nwi
->io_func
.u
.spi
.spi_rx
= linux_spi_read
;
1261 nwi
->io_func
.u
.spi
.spi_trx
= linux_spi_write_read
;
1262 nwi
->io_func
.u
.spi
.spi_max_speed
= linux_spi_set_max_speed
;
1265 /*for now - to be revised*/
1266 nwi
->net_func
.rx_indicate
= frmw_to_linux
;
1267 nwi
->net_func
.rx_complete
= linux_wlan_rx_complete
;
1268 nwi
->indicate_func
.mac_indicate
= linux_wlan_mac_indicate
;
1271 int wlan_initialize_threads(perInterface_wlan_t
*nic
)
1276 PRINT_D(INIT_DBG
, "Initializing Threads ...\n");
1278 #if (RX_BH_TYPE == RX_BH_WORK_QUEUE)
1279 /*Initialize rx work queue task*/
1280 INIT_WORK(&g_linux_wlan
->rx_work_queue
, isr_bh_routine
);
1281 #elif (RX_BH_TYPE == RX_BH_KTHREAD)
1282 PRINT_D(INIT_DBG
, "Creating kthread for Rxq BH\n");
1283 g_linux_wlan
->rx_bh_thread
= kthread_run(isr_bh_routine
, (void *)g_linux_wlan
, "K_RXQ_BH");
1284 if (g_linux_wlan
->rx_bh_thread
== NULL
) {
1285 PRINT_ER("couldn't create RX BH thread\n");
1291 #ifndef TCP_ENHANCEMENTS
1292 /* create rx task */
1293 PRINT_D(INIT_DBG
, "Creating kthread for reception\n");
1294 g_linux_wlan
->rxq_thread
= kthread_run(linux_wlan_rxq_task
, (void *)g_linux_wlan
, "K_RXQ_TASK");
1295 if (g_linux_wlan
->rxq_thread
== 0) {
1296 PRINT_ER("couldn't create RXQ thread\n");
1301 /* wait for RXQ task to start. */
1302 down(&g_linux_wlan
->rxq_thread_started
);
1306 /* create tx task */
1307 PRINT_D(INIT_DBG
, "Creating kthread for transmission\n");
1308 g_linux_wlan
->txq_thread
= kthread_run(linux_wlan_txq_task
, (void *)g_linux_wlan
, "K_TXQ_TASK");
1309 if (g_linux_wlan
->txq_thread
== NULL
) {
1310 PRINT_ER("couldn't create TXQ thread\n");
1315 PRINT_D(INIT_DBG
, "Creating kthread for Debugging\n");
1316 g_linux_wlan
->txq_thread
= kthread_run(DebuggingThreadTask
, (void *)g_linux_wlan
, "DebugThread");
1317 if (g_linux_wlan
->txq_thread
== 0) {
1318 PRINT_ER("couldn't create TXQ thread\n");
1323 /* wait for TXQ task to start. */
1324 down(&g_linux_wlan
->txq_thread_started
);
1329 /*De-Initialize 2nd thread*/
1330 g_linux_wlan
->close
= 1;
1331 up(&g_linux_wlan
->rxq_event
);
1332 kthread_stop(g_linux_wlan
->rxq_thread
);
1334 #ifndef TCP_ENHANCEMENTS
1337 #if (RX_BH_TYPE == RX_BH_KTHREAD)
1338 /*De-Initialize 1st thread*/
1339 g_linux_wlan
->close
= 1;
1340 up(&g_linux_wlan
->rx_sem
);
1341 kthread_stop(g_linux_wlan
->rx_bh_thread
);
1344 g_linux_wlan
->close
= 0;
1348 static void wlan_deinitialize_threads(linux_wlan_t
*nic
)
1351 g_linux_wlan
->close
= 1;
1352 PRINT_D(INIT_DBG
, "Deinitializing Threads\n");
1353 if (&g_linux_wlan
->rxq_event
!= NULL
)
1354 up(&g_linux_wlan
->rxq_event
);
1356 if (g_linux_wlan
->rxq_thread
!= NULL
) {
1357 kthread_stop(g_linux_wlan
->rxq_thread
);
1358 g_linux_wlan
->rxq_thread
= NULL
;
1361 if (&g_linux_wlan
->txq_event
!= NULL
)
1362 up(&g_linux_wlan
->txq_event
);
1364 if (g_linux_wlan
->txq_thread
!= NULL
) {
1365 kthread_stop(g_linux_wlan
->txq_thread
);
1366 g_linux_wlan
->txq_thread
= NULL
;
1369 #if (RX_BH_TYPE == RX_BH_KTHREAD)
1370 if (&g_linux_wlan
->rx_sem
!= NULL
)
1371 up(&g_linux_wlan
->rx_sem
);
1373 if (g_linux_wlan
->rx_bh_thread
!= NULL
) {
1374 kthread_stop(g_linux_wlan
->rx_bh_thread
);
1375 g_linux_wlan
->rx_bh_thread
= NULL
;
1380 #ifdef COMPLEMENT_BOOT
1382 extern volatile int probe
;
1383 extern u8
core_11b_ready(void);
1385 #define READY_CHECK_THRESHOLD 30
1386 extern void wilc_wlan_global_reset(void);
1387 u8
wilc1000_prepare_11b_core(wilc_wlan_inp_t
*nwi
, wilc_wlan_oup_t
*nwo
, linux_wlan_t
*nic
)
1391 while ((core_11b_ready() && (READY_CHECK_THRESHOLD
> (trials
++)))) {
1392 PRINT_D(INIT_DBG
, "11b core not ready yet: %u\n", trials
);
1393 wilc_wlan_deinit(nic
);
1394 wilc_wlan_global_reset();
1395 sdio_unregister_driver(&wilc_bus
);
1397 linux_wlan_device_detection(0);
1401 linux_wlan_device_detection(1);
1403 sdio_register_driver(&wilc_bus
);
1408 g_linux_wlan
->wilc_sdio_func
= local_sdio_func
;
1409 linux_to_wlan(nwi
, nic
);
1410 wilc_wlan_init(nwi
, nwo
);
1413 if (READY_CHECK_THRESHOLD
<= trials
)
1420 int repeat_power_cycle(perInterface_wlan_t
*nic
)
1423 wilc_wlan_inp_t nwi
;
1424 wilc_wlan_oup_t nwo
;
1426 sdio_unregister_driver(&wilc_bus
);
1428 linux_wlan_device_detection(0);
1429 linux_wlan_device_power(0);
1431 linux_wlan_device_power(1);
1433 linux_wlan_device_detection(1);
1436 sdio_register_driver(&wilc_bus
);
1442 g_linux_wlan
->wilc_sdio_func
= local_sdio_func
;
1443 linux_to_wlan(&nwi
, g_linux_wlan
);
1444 ret
= wilc_wlan_init(&nwi
, &nwo
);
1446 g_linux_wlan
->mac_status
= WILC_MAC_STATUS_INIT
;
1447 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
1448 enable_sdio_interrupt();
1451 if (linux_wlan_get_firmware(nic
)) {
1452 PRINT_ER("Can't get firmware\n");
1457 /*Download firmware*/
1458 ret
= linux_wlan_firmware_download(g_linux_wlan
);
1460 PRINT_ER("Failed to download firmware\n");
1464 ret
= linux_wlan_start_firmware(nic
);
1466 PRINT_ER("Failed to start firmware\n");
1472 int wilc1000_wlan_init(struct net_device
*dev
, perInterface_wlan_t
*p_nic
)
1474 wilc_wlan_inp_t nwi
;
1475 wilc_wlan_oup_t nwo
;
1476 perInterface_wlan_t
*nic
= p_nic
;
1479 if (!g_linux_wlan
->wilc1000_initialized
) {
1480 g_linux_wlan
->mac_status
= WILC_MAC_STATUS_INIT
;
1481 g_linux_wlan
->close
= 0;
1482 g_linux_wlan
->wilc1000_initialized
= 0;
1484 wlan_init_locks(g_linux_wlan
);
1486 linux_to_wlan(&nwi
, g_linux_wlan
);
1488 ret
= wilc_wlan_init(&nwi
, &nwo
);
1490 PRINT_ER("Initializing WILC_Wlan FAILED\n");
1494 memcpy(&g_linux_wlan
->oup
, &nwo
, sizeof(wilc_wlan_oup_t
));
1496 /*Save the oup structre into global pointer*/
1497 gpstrWlanOps
= &g_linux_wlan
->oup
;
1499 ret
= wlan_initialize_threads(nic
);
1501 PRINT_ER("Initializing Threads FAILED\n");
1503 goto _fail_wilc_wlan_
;
1506 #if (defined WILC_SDIO) && (defined COMPLEMENT_BOOT)
1507 if (wilc1000_prepare_11b_core(&nwi
, &nwo
, g_linux_wlan
)) {
1508 PRINT_ER("11b Core is not ready\n");
1510 goto _fail_threads_
;
1514 #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
1515 if (init_irq(g_linux_wlan
)) {
1516 PRINT_ER("couldn't initialize IRQ\n");
1518 goto _fail_threads_
;
1522 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
1523 if (enable_sdio_interrupt()) {
1524 PRINT_ER("couldn't initialize IRQ\n");
1526 goto _fail_irq_init_
;
1530 if (linux_wlan_get_firmware(nic
)) {
1531 PRINT_ER("Can't get firmware\n");
1533 goto _fail_irq_enable_
;
1536 /*Download firmware*/
1537 ret
= linux_wlan_firmware_download(g_linux_wlan
);
1539 PRINT_ER("Failed to download firmware\n");
1541 goto _fail_irq_enable_
;
1545 ret
= linux_wlan_start_firmware(nic
);
1547 PRINT_ER("Failed to start firmware\n");
1549 goto _fail_irq_enable_
;
1552 wilc_bus_set_max_speed();
1554 if (g_linux_wlan
->oup
.wlan_cfg_get(1, WID_FIRMWARE_VERSION
, 1, 0)) {
1556 char Firmware_ver
[20];
1558 size
= g_linux_wlan
->oup
.wlan_cfg_get_value(
1559 WID_FIRMWARE_VERSION
,
1560 Firmware_ver
, sizeof(Firmware_ver
));
1561 Firmware_ver
[size
] = '\0';
1562 PRINT_D(INIT_DBG
, "***** Firmware Ver = %s *******\n", Firmware_ver
);
1564 /* Initialize firmware with default configuration */
1565 ret
= linux_wlan_init_test_config(dev
, g_linux_wlan
);
1568 PRINT_ER("Failed to configure firmware\n");
1570 goto _fail_fw_start_
;
1573 g_linux_wlan
->wilc1000_initialized
= 1;
1574 return 0; /*success*/
1577 if (&g_linux_wlan
->oup
!= NULL
) {
1578 if (g_linux_wlan
->oup
.wlan_stop
!= NULL
)
1579 g_linux_wlan
->oup
.wlan_stop();
1583 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
1584 disable_sdio_interrupt();
1587 #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
1588 deinit_irq(g_linux_wlan
);
1592 wlan_deinitialize_threads(g_linux_wlan
);
1594 wilc_wlan_deinit(g_linux_wlan
);
1596 wlan_deinit_locks(g_linux_wlan
);
1597 PRINT_ER("WLAN Iinitialization FAILED\n");
1599 PRINT_D(INIT_DBG
, "wilc1000 already initialized\n");
1605 * - this function will be called automatically by OS when module inserted.
1608 int mac_init_fn(struct net_device
*ndev
)
1611 /*Why we do this !!!*/
1612 netif_start_queue(ndev
); /* ma */
1613 netif_stop_queue(ndev
); /* ma */
1618 void WILC_WFI_frame_register(struct wiphy
*wiphy
, struct net_device
*dev
,
1619 u16 frame_type
, bool reg
);
1621 /* This fn is called, when this device is setup using ifconfig */
1622 int mac_open(struct net_device
*ndev
)
1624 perInterface_wlan_t
*nic
;
1627 /*No need for setting mac address here anymore,*/
1628 /*Just set it in init_test_config()*/
1629 unsigned char mac_add
[ETH_ALEN
] = {0};
1632 struct wilc_priv
*priv
;
1635 if (!g_linux_wlan
|| !g_linux_wlan
->wilc_spidev
) {
1636 netdev_err(ndev
, "wilc1000: SPI device not ready\n");
1640 nic
= netdev_priv(ndev
);
1641 priv
= wiphy_priv(nic
->wilc_netdev
->ieee80211_ptr
->wiphy
);
1642 PRINT_D(INIT_DBG
, "MAC OPEN[%p]\n", ndev
);
1644 ret
= WILC_WFI_InitHostInt(ndev
);
1646 PRINT_ER("Failed to initialize host interface\n");
1651 /*initialize platform*/
1652 PRINT_D(INIT_DBG
, "*** re-init ***\n");
1653 ret
= wilc1000_wlan_init(ndev
, nic
);
1655 PRINT_ER("Failed to initialize wilc1000\n");
1656 WILC_WFI_DeInitHostInt(ndev
);
1660 Set_machw_change_vir_if(false);
1662 host_int_get_MacAddress(priv
->hWILCWFIDrv
, mac_add
);
1663 PRINT_D(INIT_DBG
, "Mac address: %pM\n", mac_add
);
1665 /* loop through the NUM of supported devices and set the MAC address */
1666 for (i
= 0; i
< g_linux_wlan
->u8NoIfcs
; i
++) {
1667 if (ndev
== g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
) {
1668 memcpy(g_linux_wlan
->strInterfaceInfo
[i
].aSrcAddress
, mac_add
, ETH_ALEN
);
1669 g_linux_wlan
->strInterfaceInfo
[i
].drvHandler
= priv
->hWILCWFIDrv
;
1674 /* TODO: get MAC address whenever the source is EPROM - hardcoded and copy it to ndev*/
1675 memcpy(ndev
->dev_addr
, g_linux_wlan
->strInterfaceInfo
[i
].aSrcAddress
, ETH_ALEN
);
1677 if (!is_valid_ether_addr(ndev
->dev_addr
)) {
1678 PRINT_ER("Error: Wrong MAC address\n");
1683 WILC_WFI_frame_register(nic
->wilc_netdev
->ieee80211_ptr
->wiphy
, nic
->wilc_netdev
,
1684 nic
->g_struct_frame_reg
[0].frame_type
, nic
->g_struct_frame_reg
[0].reg
);
1685 WILC_WFI_frame_register(nic
->wilc_netdev
->ieee80211_ptr
->wiphy
, nic
->wilc_netdev
,
1686 nic
->g_struct_frame_reg
[1].frame_type
, nic
->g_struct_frame_reg
[1].reg
);
1687 netif_wake_queue(ndev
);
1688 g_linux_wlan
->open_ifcs
++;
1689 nic
->mac_opened
= 1;
1693 WILC_WFI_DeInitHostInt(ndev
);
1694 wilc1000_wlan_deinit(g_linux_wlan
);
1698 struct net_device_stats
*mac_stats(struct net_device
*dev
)
1700 perInterface_wlan_t
*nic
= netdev_priv(dev
);
1702 return &nic
->netstats
;
1705 /* Setup the multicast filter */
1706 static void wilc_set_multicast_list(struct net_device
*dev
)
1709 struct netdev_hw_addr
*ha
;
1710 struct wilc_priv
*priv
;
1711 tstrWILC_WFIDrv
*pstrWFIDrv
;
1714 priv
= wiphy_priv(dev
->ieee80211_ptr
->wiphy
);
1715 pstrWFIDrv
= (tstrWILC_WFIDrv
*)priv
->hWILCWFIDrv
;
1720 PRINT_D(INIT_DBG
, "Setting Multicast List with count = %d.\n", dev
->mc
.count
);
1722 if (dev
->flags
& IFF_PROMISC
) {
1723 /* Normally, we should configure the chip to retrive all packets
1724 * but we don't wanna support this right now */
1725 /* TODO: add promiscuous mode support */
1726 PRINT_D(INIT_DBG
, "Set promiscuous mode ON, retrive all packets\n");
1730 /* If there's more addresses than we handle, get all multicast
1731 * packets and sort them out in software. */
1732 if ((dev
->flags
& IFF_ALLMULTI
) || (dev
->mc
.count
) > WILC_MULTICAST_TABLE_SIZE
) {
1733 PRINT_D(INIT_DBG
, "Disable multicast filter, retrive all multicast packets\n");
1734 /* get all multicast packets */
1735 host_int_setup_multicast_filter(pstrWFIDrv
, false, 0);
1739 /* No multicast? Just get our own stuff */
1740 if ((dev
->mc
.count
) == 0) {
1741 PRINT_D(INIT_DBG
, "Enable multicast filter, retrive directed packets only.\n");
1742 host_int_setup_multicast_filter(pstrWFIDrv
, true, 0);
1746 /* Store all of the multicast addresses in the hardware filter */
1747 netdev_for_each_mc_addr(ha
, dev
)
1749 memcpy(gau8MulticastMacAddrList
[i
], ha
->addr
, ETH_ALEN
);
1750 PRINT_D(INIT_DBG
, "Entry[%d]: %x:%x:%x:%x:%x:%x\n", i
,
1751 gau8MulticastMacAddrList
[i
][0], gau8MulticastMacAddrList
[i
][1], gau8MulticastMacAddrList
[i
][2], gau8MulticastMacAddrList
[i
][3], gau8MulticastMacAddrList
[i
][4], gau8MulticastMacAddrList
[i
][5]);
1755 host_int_setup_multicast_filter(pstrWFIDrv
, true, (dev
->mc
.count
));
1761 static void linux_wlan_tx_complete(void *priv
, int status
)
1764 struct tx_complete_data
*pv_data
= (struct tx_complete_data
*)priv
;
1767 PRINT_D(TX_DBG
, "Packet sent successfully - Size = %d - Address = %p - SKB = %p\n", pv_data
->size
, pv_data
->buff
, pv_data
->skb
);
1769 PRINT_D(TX_DBG
, "Couldn't send packet - Size = %d - Address = %p - SKB = %p\n", pv_data
->size
, pv_data
->buff
, pv_data
->skb
);
1770 /* Free the SK Buffer, its work is done */
1771 dev_kfree_skb(pv_data
->skb
);
1775 int mac_xmit(struct sk_buff
*skb
, struct net_device
*ndev
)
1777 perInterface_wlan_t
*nic
;
1778 struct tx_complete_data
*tx_data
= NULL
;
1782 struct ethhdr
*eth_h
;
1784 nic
= netdev_priv(ndev
);
1786 PRINT_D(TX_DBG
, "Sending packet just received from TCP/IP\n");
1788 /* Stop the network interface queue */
1789 if (skb
->dev
!= ndev
) {
1790 PRINT_ER("Packet not destined to this device\n");
1794 tx_data
= kmalloc(sizeof(struct tx_complete_data
), GFP_ATOMIC
);
1795 if (tx_data
== NULL
) {
1796 PRINT_ER("Failed to allocate memory for tx_data structure\n");
1798 netif_wake_queue(ndev
);
1802 tx_data
->buff
= skb
->data
;
1803 tx_data
->size
= skb
->len
;
1806 eth_h
= (struct ethhdr
*)(skb
->data
);
1807 if (eth_h
->h_proto
== 0x8e88)
1808 PRINT_D(INIT_DBG
, "EAPOL transmitted\n");
1810 /*get source and dest ip addresses*/
1811 ih
= (struct iphdr
*)(skb
->data
+ sizeof(struct ethhdr
));
1813 pu8UdpBuffer
= (char *)ih
+ sizeof(struct iphdr
);
1814 if ((pu8UdpBuffer
[1] == 68 && pu8UdpBuffer
[3] == 67) || (pu8UdpBuffer
[1] == 67 && pu8UdpBuffer
[3] == 68))
1815 PRINT_D(GENERIC_DBG
, "DHCP Message transmitted, type:%x %x %x\n", pu8UdpBuffer
[248], pu8UdpBuffer
[249], pu8UdpBuffer
[250]);
1817 PRINT_D(TX_DBG
, "Sending packet - Size = %d - Address = %p - SKB = %p\n", tx_data
->size
, tx_data
->buff
, tx_data
->skb
);
1819 /* Send packet to MAC HW - for now the tx_complete function will be just status
1820 * indicator. still not sure if I need to suspend host transmission till the tx_complete
1821 * function called or not?
1822 * allocated buffer will be freed in tx_complete function.
1824 PRINT_D(TX_DBG
, "Adding tx packet to TX Queue\n");
1825 nic
->netstats
.tx_packets
++;
1826 nic
->netstats
.tx_bytes
+= tx_data
->size
;
1827 tx_data
->pBssid
= g_linux_wlan
->strInterfaceInfo
[nic
->u8IfIdx
].aBSSID
;
1828 QueueCount
= g_linux_wlan
->oup
.wlan_add_to_tx_que((void *)tx_data
,
1831 linux_wlan_tx_complete
);
1833 if (QueueCount
> FLOW_CONTROL_UPPER_THRESHOLD
) {
1834 netif_stop_queue(g_linux_wlan
->strInterfaceInfo
[0].wilc_netdev
);
1835 netif_stop_queue(g_linux_wlan
->strInterfaceInfo
[1].wilc_netdev
);
1841 int mac_close(struct net_device
*ndev
)
1843 struct wilc_priv
*priv
;
1844 perInterface_wlan_t
*nic
;
1845 tstrWILC_WFIDrv
*pstrWFIDrv
;
1847 nic
= netdev_priv(ndev
);
1849 if ((nic
== NULL
) || (nic
->wilc_netdev
== NULL
) || (nic
->wilc_netdev
->ieee80211_ptr
== NULL
) || (nic
->wilc_netdev
->ieee80211_ptr
->wiphy
== NULL
)) {
1850 PRINT_ER("nic = NULL\n");
1854 priv
= wiphy_priv(nic
->wilc_netdev
->ieee80211_ptr
->wiphy
);
1857 PRINT_ER("priv = NULL\n");
1861 pstrWFIDrv
= (tstrWILC_WFIDrv
*)priv
->hWILCWFIDrv
;
1863 PRINT_D(GENERIC_DBG
, "Mac close\n");
1865 if (g_linux_wlan
== NULL
) {
1866 PRINT_ER("g_linux_wlan = NULL\n");
1870 if (pstrWFIDrv
== NULL
) {
1871 PRINT_ER("pstrWFIDrv = NULL\n");
1875 if ((g_linux_wlan
->open_ifcs
) > 0) {
1876 g_linux_wlan
->open_ifcs
--;
1878 PRINT_ER("ERROR: MAC close called while number of opened interfaces is zero\n");
1882 if (nic
->wilc_netdev
!= NULL
) {
1883 /* Stop the network interface queue */
1884 netif_stop_queue(nic
->wilc_netdev
);
1886 WILC_WFI_DeInitHostInt(nic
->wilc_netdev
);
1889 if (g_linux_wlan
->open_ifcs
== 0) {
1890 PRINT_D(GENERIC_DBG
, "Deinitializing wilc1000\n");
1891 g_linux_wlan
->close
= 1;
1892 wilc1000_wlan_deinit(g_linux_wlan
);
1893 #ifdef WILC_AP_EXTERNAL_MLME
1894 WILC_WFI_deinit_mon_interface();
1898 up(&close_exit_sync
);
1899 nic
->mac_opened
= 0;
1904 int mac_ioctl(struct net_device
*ndev
, struct ifreq
*req
, int cmd
)
1909 u32 size
= 0, length
= 0;
1910 perInterface_wlan_t
*nic
;
1911 struct wilc_priv
*priv
;
1912 s32 s32Error
= WILC_SUCCESS
;
1914 /* struct iwreq *wrq = (struct iwreq *) req; // tony moved to case SIOCSIWPRIV */
1915 nic
= netdev_priv(ndev
);
1917 if (!g_linux_wlan
->wilc1000_initialized
)
1925 struct iwreq
*wrq
= (struct iwreq
*) req
; /* added by tony */
1927 size
= wrq
->u
.data
.length
;
1929 if (size
&& wrq
->u
.data
.pointer
) {
1931 buff
= memdup_user(wrq
->u
.data
.pointer
, wrq
->u
.data
.length
);
1933 return PTR_ERR(buff
);
1935 if (strncasecmp(buff
, "RSSI", length
) == 0) {
1936 priv
= wiphy_priv(nic
->wilc_netdev
->ieee80211_ptr
->wiphy
);
1937 s32Error
= host_int_get_rssi(priv
->hWILCWFIDrv
, &(rssi
));
1939 PRINT_ER("Failed to send get rssi param's message queue ");
1940 PRINT_INFO(GENERIC_DBG
, "RSSI :%d\n", rssi
);
1942 /*Rounding up the rssi negative value*/
1945 snprintf(buff
, size
, "rssi %d", rssi
);
1947 if (copy_to_user(wrq
->u
.data
.pointer
, buff
, size
)) {
1948 PRINT_ER("%s: failed to copy data to user buffer\n", __func__
);
1959 PRINT_INFO(GENERIC_DBG
, "Command - %d - has been received\n", cmd
);
1960 s32Error
= -EOPNOTSUPP
;
1972 void frmw_to_linux(u8
*buff
, u32 size
, u32 pkt_offset
)
1975 unsigned int frame_len
= 0;
1977 unsigned char *buff_to_send
= NULL
;
1978 struct sk_buff
*skb
;
1979 #ifndef TCP_ENHANCEMENTS
1983 struct net_device
*wilc_netdev
;
1984 perInterface_wlan_t
*nic
;
1986 wilc_netdev
= GetIfHandler(buff
);
1987 if (wilc_netdev
== NULL
)
1991 nic
= netdev_priv(wilc_netdev
);
1996 buff_to_send
= buff
;
1998 /* Need to send the packet up to the host, allocate a skb buffer */
1999 skb
= dev_alloc_skb(frame_len
);
2001 PRINT_ER("Low memory - packet droped\n");
2005 if (g_linux_wlan
== NULL
|| wilc_netdev
== NULL
)
2006 PRINT_ER("wilc_netdev in g_linux_wlan is NULL");
2007 skb
->dev
= wilc_netdev
;
2009 if (skb
->dev
== NULL
)
2010 PRINT_ER("skb->dev is NULL\n");
2016 * WILC_PRINTF("buff_to_send[%d]=%2x\n",i,buff_to_send[i]);
2020 /* skb_put(skb, frame_len); */
2021 memcpy(skb_put(skb
, frame_len
), buff_to_send
, frame_len
);
2023 /* WILC_PRINTF("After MEM_CPY\n"); */
2025 /* nic = netdev_priv(wilc_netdev); */
2027 skb
->protocol
= eth_type_trans(skb
, wilc_netdev
);
2028 #ifndef TCP_ENHANCEMENTS
2029 /*get source and dest ip addresses*/
2030 ih
= (struct iphdr
*)(skb
->data
+ sizeof(struct ethhdr
));
2032 pu8UdpBuffer
= (char *)ih
+ sizeof(struct iphdr
);
2033 if (buff_to_send
[35] == 67 && buff_to_send
[37] == 68)
2034 PRINT_D(RX_DBG
, "DHCP Message received\n");
2035 if (buff_to_send
[12] == 0x88 && buff_to_send
[13] == 0x8e)
2036 PRINT_D(GENERIC_DBG
, "eapol received\n");
2038 /* Send the packet to the stack by giving it to the bridge */
2039 nic
->netstats
.rx_packets
++;
2040 nic
->netstats
.rx_bytes
+= frame_len
;
2041 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
2042 stats
= netif_rx(skb
);
2043 PRINT_D(RX_DBG
, "netif_rx ret value is: %d\n", stats
);
2045 #ifndef TCP_ENHANCEMENTS
2047 PRINT_ER("Discard sending packet with len = %d\n", size
);
2051 void WILC_WFI_mgmt_rx(u8
*buff
, u32 size
)
2054 perInterface_wlan_t
*nic
;
2057 /*Pass the frame on the monitor interface, if any.*/
2058 /*Otherwise, pass it on p2p0 netdev, if registered on it*/
2059 for (i
= 0; i
< g_linux_wlan
->u8NoIfcs
; i
++) {
2060 nic
= netdev_priv(g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
);
2061 if (nic
->monitor_flag
) {
2062 WILC_WFI_monitor_rx(buff
, size
);
2068 nic
= netdev_priv(g_linux_wlan
->strInterfaceInfo
[1].wilc_netdev
); /* p2p0 */
2069 if ((buff
[0] == nic
->g_struct_frame_reg
[0].frame_type
&& nic
->g_struct_frame_reg
[0].reg
) ||
2070 (buff
[0] == nic
->g_struct_frame_reg
[1].frame_type
&& nic
->g_struct_frame_reg
[1].reg
))
2071 WILC_WFI_p2p_rx(g_linux_wlan
->strInterfaceInfo
[1].wilc_netdev
, buff
, size
);
2075 int wilc_netdev_init(void)
2079 perInterface_wlan_t
*nic
;
2080 struct net_device
*ndev
;
2082 sema_init(&close_exit_sync
, 0);
2084 /*create the common structure*/
2085 g_linux_wlan
= kzalloc(sizeof(linux_wlan_t
), GFP_KERNEL
);
2089 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
2090 register_inetaddr_notifier(&g_dev_notifier
);
2093 for (i
= 0; i
< NUM_CONCURRENT_IFC
; i
++) {
2094 /*allocate first ethernet device with perinterface_wlan_t as its private data*/
2095 ndev
= alloc_etherdev(sizeof(perInterface_wlan_t
));
2097 PRINT_ER("Failed to allocate ethernet dev\n");
2101 nic
= netdev_priv(ndev
);
2102 memset(nic
, 0, sizeof(perInterface_wlan_t
));
2104 /*Name the Devices*/
2106 #if defined(NM73131) /* tony, 2012-09-20 */
2107 strcpy(ndev
->name
, "wilc_eth%d");
2108 #elif defined(PLAT_CLM9722) /* rachel */
2109 strcpy(ndev
->name
, "eth%d");
2110 #else /* PANDA_BOARD, PLAT_ALLWINNER_A10, PLAT_ALLWINNER_A20, PLAT_ALLWINNER_A31, PLAT_AML8726_M3 or PLAT_WMS8304 */
2111 strcpy(ndev
->name
, "wlan%d");
2114 strcpy(ndev
->name
, "p2p%d");
2116 nic
->u8IfIdx
= g_linux_wlan
->u8NoIfcs
;
2117 nic
->wilc_netdev
= ndev
;
2118 g_linux_wlan
->strInterfaceInfo
[g_linux_wlan
->u8NoIfcs
].wilc_netdev
= ndev
;
2119 g_linux_wlan
->u8NoIfcs
++;
2120 ndev
->netdev_ops
= &wilc_netdev_ops
;
2123 struct wireless_dev
*wdev
;
2125 wdev
= WILC_WFI_WiphyRegister(ndev
);
2128 /* set netdev, tony */
2129 SET_NETDEV_DEV(ndev
, &local_sdio_func
->dev
);
2133 PRINT_ER("Can't register WILC Wiphy\n");
2137 /*linking the wireless_dev structure with the netdevice*/
2138 nic
->wilc_netdev
->ieee80211_ptr
= wdev
;
2139 nic
->wilc_netdev
->ml_priv
= nic
;
2140 wdev
->netdev
= nic
->wilc_netdev
;
2141 nic
->netstats
.rx_packets
= 0;
2142 nic
->netstats
.tx_packets
= 0;
2143 nic
->netstats
.rx_bytes
= 0;
2144 nic
->netstats
.tx_bytes
= 0;
2148 if (register_netdev(ndev
)) {
2149 PRINT_ER("Device couldn't be registered - %s\n", ndev
->name
);
2150 return -1; /* ERROR */
2153 nic
->iftype
= STATION_MODE
;
2154 nic
->mac_opened
= 0;
2159 if (!linux_spi_init(&g_linux_wlan
->wilc_spidev
)) {
2160 PRINT_ER("Can't initialize SPI\n");
2161 return -1; /* ERROR */
2163 g_linux_wlan
->wilc_spidev
= wilc_spi_dev
;
2165 g_linux_wlan
->wilc_sdio_func
= local_sdio_func
;
2171 /*The 1st function called after module inserted*/
2172 static int __init
init_wilc_driver(void)
2174 #if defined(WILC_DEBUGFS)
2175 if (wilc_debugfs_init() < 0) {
2176 PRINT_D(GENERIC_DBG
, "fail to create debugfs for wilc driver\n");
2181 printk("IN INIT FUNCTION\n");
2182 printk("*** WILC1000 driver VERSION=[10.2] FW_VER=[10.2] ***\n");
2184 linux_wlan_device_power(1);
2186 linux_wlan_device_detection(1);
2192 ret
= sdio_register_driver(&wilc_bus
);
2194 PRINT_D(INIT_DBG
, "init_wilc_driver: Failed register sdio driver\n");
2199 PRINT_D(INIT_DBG
, "Initializing netdev\n");
2200 if (wilc_netdev_init())
2201 PRINT_ER("Couldn't initialize netdev\n");
2205 late_initcall(init_wilc_driver
);
2207 static void __exit
exit_wilc_driver(void)
2210 perInterface_wlan_t
*nic
[NUM_CONCURRENT_IFC
] = {NULL
,};
2211 #define CLOSE_TIMEOUT (12 * 1000)
2213 if ((g_linux_wlan
!= NULL
) && (((g_linux_wlan
->strInterfaceInfo
[0].wilc_netdev
) != NULL
)
2214 || ((g_linux_wlan
->strInterfaceInfo
[1].wilc_netdev
) != NULL
))) {
2215 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
2216 unregister_inetaddr_notifier(&g_dev_notifier
);
2219 for (i
= 0; i
< NUM_CONCURRENT_IFC
; i
++)
2220 nic
[i
] = netdev_priv(g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
);
2223 if ((g_linux_wlan
!= NULL
) && g_linux_wlan
->wilc_firmware
!= NULL
) {
2224 release_firmware(g_linux_wlan
->wilc_firmware
);
2225 g_linux_wlan
->wilc_firmware
= NULL
;
2228 if ((g_linux_wlan
!= NULL
) && (((g_linux_wlan
->strInterfaceInfo
[0].wilc_netdev
) != NULL
)
2229 || ((g_linux_wlan
->strInterfaceInfo
[1].wilc_netdev
) != NULL
))) {
2230 PRINT_D(INIT_DBG
, "Waiting for mac_close ....\n");
2232 if (linux_wlan_lock_timeout(&close_exit_sync
, CLOSE_TIMEOUT
) < 0)
2233 PRINT_D(INIT_DBG
, "Closed TimedOUT\n");
2235 PRINT_D(INIT_DBG
, "mac_closed\n");
2237 for (i
= 0; i
< NUM_CONCURRENT_IFC
; i
++) {
2238 /* close all opened interfaces */
2239 if (g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
!= NULL
) {
2240 if (nic
[i
]->mac_opened
)
2241 mac_close(g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
);
2244 for (i
= 0; i
< NUM_CONCURRENT_IFC
; i
++) {
2245 PRINT_D(INIT_DBG
, "Unregistering netdev %p\n", g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
);
2246 unregister_netdev(g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
);
2247 PRINT_D(INIT_DBG
, "Freeing Wiphy...\n");
2248 WILC_WFI_WiphyFree(g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
);
2249 PRINT_D(INIT_DBG
, "Freeing netdev...\n");
2250 free_netdev(g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
);
2254 #ifdef WILC_AP_EXTERNAL_MLME
2255 /* Bug 4600 : WILC_WFI_deinit_mon_interface was already called at mac_close */
2256 /* WILC_WFI_deinit_mon_interface(); */
2259 /* if(g_linux_wlan->open_ifcs==0) */
2262 PRINT_D(INIT_DBG
, "SPI unregsiter...\n");
2263 spi_unregister_driver(&wilc_bus
);
2265 PRINT_D(INIT_DBG
, "SDIO unregsiter...\n");
2266 sdio_unregister_driver(&wilc_bus
);
2269 if (g_linux_wlan
!= NULL
) {
2270 kfree(g_linux_wlan
);
2271 g_linux_wlan
= NULL
;
2273 printk("Module_exit Done.\n");
2275 #if defined(WILC_DEBUGFS)
2276 wilc_debugfs_remove();
2279 linux_wlan_device_detection(0);
2280 linux_wlan_device_power(0);
2283 module_exit(exit_wilc_driver
);
2285 MODULE_LICENSE("GPL");