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);
439 nic
->dev_irq_num
= gpio_to_irq(GPIO_NUM
);
443 PRINT_ER("could not obtain gpio for WILC_INTR\n");
446 #if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
447 if ((ret
!= -1) && (request_threaded_irq(nic
->dev_irq_num
, isr_uh_routine
, isr_bh_routine
,
448 IRQF_TRIGGER_LOW
| IRQF_ONESHOT
, /*Without IRQF_ONESHOT the uh will remain kicked in and dont gave a chance to bh*/
449 "WILC_IRQ", nic
)) < 0) {
453 if ((ret
!= -1) && (request_irq(nic
->dev_irq_num
, isr_uh_routine
,
454 IRQF_TRIGGER_LOW
, "WILC_IRQ", nic
) < 0)) {
457 PRINT_ER("Failed to request IRQ for GPIO: %d\n", GPIO_NUM
);
461 PRINT_D(INIT_DBG
, "IRQ request succeeded IRQ-NUM= %d on GPIO: %d\n",
462 nic
->dev_irq_num
, GPIO_NUM
);
469 static void deinit_irq(linux_wlan_t
*nic
)
471 #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
472 /* Deintialize IRQ */
473 if (&nic
->dev_irq_num
!= 0) {
474 free_irq(nic
->dev_irq_num
, g_linux_wlan
);
484 static void linux_wlan_dbg(u8
*buff
)
486 PRINT_D(INIT_DBG
, "%d\n", *buff
);
489 static int linux_wlan_lock_timeout(void *vp
, u32 timeout
)
493 PRINT_D(LOCK_DBG
, "Locking %p\n", vp
);
495 error
= down_timeout((struct semaphore
*)vp
, msecs_to_jiffies(timeout
));
497 PRINT_ER("Failed, mutex is NULL\n");
501 static void linux_wlan_mac_indicate(int flag
)
503 /*I have to do it that way becuase there is no mean to encapsulate device pointer
506 linux_wlan_t
*pd
= g_linux_wlan
;
509 if (flag
== WILC_MAC_INDICATE_STATUS
) {
510 pd
->oup
.wlan_cfg_get_value(WID_STATUS
, (unsigned char *)&status
, 4);
511 if (pd
->mac_status
== WILC_MAC_STATUS_INIT
) {
512 pd
->mac_status
= status
;
515 pd
->mac_status
= status
;
518 if (pd
->mac_status
== WILC_MAC_STATUS_CONNECT
) { /* Connect */
521 } else if (flag
== WILC_MAC_INDICATE_SCAN
) {
522 PRINT_D(GENERIC_DBG
, "Scanning ...\n");
528 struct net_device
*GetIfHandler(u8
*pMacHeader
)
533 Bssid
= pMacHeader
+ 10;
534 Bssid1
= pMacHeader
+ 4;
536 for (i
= 0; i
< g_linux_wlan
->u8NoIfcs
; i
++) {
537 if (!memcmp(Bssid1
, g_linux_wlan
->strInterfaceInfo
[i
].aBSSID
, ETH_ALEN
) ||
538 !memcmp(Bssid
, g_linux_wlan
->strInterfaceInfo
[i
].aBSSID
, ETH_ALEN
)) {
539 return g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
;
542 PRINT_INFO(INIT_DBG
, "Invalide handle\n");
543 for (i
= 0; i
< 25; i
++)
544 PRINT_D(INIT_DBG
, "%02x ", pMacHeader
[i
]);
545 Bssid
= pMacHeader
+ 18;
546 Bssid1
= pMacHeader
+ 12;
547 for (i
= 0; i
< g_linux_wlan
->u8NoIfcs
; i
++) {
548 if (!memcmp(Bssid1
, g_linux_wlan
->strInterfaceInfo
[i
].aBSSID
, ETH_ALEN
) ||
549 !memcmp(Bssid
, g_linux_wlan
->strInterfaceInfo
[i
].aBSSID
, ETH_ALEN
)) {
550 PRINT_D(INIT_DBG
, "Ctx [%p]\n", g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
);
551 return g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
;
554 PRINT_INFO(INIT_DBG
, "\n");
558 int linux_wlan_set_bssid(struct net_device
*wilc_netdev
, u8
*pBSSID
)
563 PRINT_D(INIT_DBG
, "set bssid on[%p]\n", wilc_netdev
);
564 for (i
= 0; i
< g_linux_wlan
->u8NoIfcs
; i
++) {
565 if (g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
== wilc_netdev
) {
566 PRINT_D(INIT_DBG
, "set bssid [%x][%x][%x]\n", pBSSID
[0], pBSSID
[1], pBSSID
[2]);
567 memcpy(g_linux_wlan
->strInterfaceInfo
[i
].aBSSID
, pBSSID
, 6);
576 /*Function to get number of connected interfaces*/
577 int linux_wlan_get_num_conn_ifcs(void)
580 u8 null_bssid
[6] = {0};
583 for (i
= 0; i
< g_linux_wlan
->u8NoIfcs
; i
++) {
584 if (memcmp(g_linux_wlan
->strInterfaceInfo
[i
].aBSSID
, null_bssid
, 6))
590 static int linux_wlan_rxq_task(void *vp
)
593 /* inform wilc1000_wlan_init that RXQ task is started. */
594 up(&g_linux_wlan
->rxq_thread_started
);
596 down(&g_linux_wlan
->rxq_event
);
597 /* wait_for_completion(&g_linux_wlan->rxq_event); */
599 if (g_linux_wlan
->close
) {
600 /*Unlock the mutex in the mac_close function to indicate the exiting of the RX thread */
601 up(&g_linux_wlan
->rxq_thread_started
);
603 while (!kthread_should_stop())
606 PRINT_D(RX_DBG
, " RX thread stopped\n");
609 PRINT_D(RX_DBG
, "Calling wlan_handle_rx_que()\n");
611 g_linux_wlan
->oup
.wlan_handle_rx_que();
616 #define USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
618 static int linux_wlan_txq_task(void *vp
)
622 #if defined USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
623 #define TX_BACKOFF_WEIGHT_INCR_STEP (1)
624 #define TX_BACKOFF_WEIGHT_DECR_STEP (1)
625 #define TX_BACKOFF_WEIGHT_MAX (7)
626 #define TX_BACKOFF_WEIGHT_MIN (0)
627 #define TX_BACKOFF_WEIGHT_UNIT_MS (10)
628 int backoff_weight
= TX_BACKOFF_WEIGHT_MIN
;
631 /* inform wilc1000_wlan_init that TXQ task is started. */
632 up(&g_linux_wlan
->txq_thread_started
);
635 PRINT_D(TX_DBG
, "txq_task Taking a nap :)\n");
636 down(&g_linux_wlan
->txq_event
);
637 /* wait_for_completion(&pd->txq_event); */
638 PRINT_D(TX_DBG
, "txq_task Who waked me up :$\n");
640 if (g_linux_wlan
->close
) {
641 /*Unlock the mutex in the mac_close function to indicate the exiting of the TX thread */
642 up(&g_linux_wlan
->txq_thread_started
);
644 while (!kthread_should_stop())
647 PRINT_D(TX_DBG
, "TX thread stopped\n");
650 PRINT_D(TX_DBG
, "txq_task handle the sending packet and let me go to sleep.\n");
651 #if !defined USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
652 g_linux_wlan
->oup
.wlan_handle_tx_que();
655 ret
= g_linux_wlan
->oup
.wlan_handle_tx_que(&txq_count
);
656 if (txq_count
< FLOW_CONTROL_LOWER_THRESHOLD
/* && netif_queue_stopped(pd->wilc_netdev)*/) {
657 PRINT_D(TX_DBG
, "Waking up queue\n");
658 /* netif_wake_queue(pd->wilc_netdev); */
659 if (netif_queue_stopped(g_linux_wlan
->strInterfaceInfo
[0].wilc_netdev
))
660 netif_wake_queue(g_linux_wlan
->strInterfaceInfo
[0].wilc_netdev
);
661 if (netif_queue_stopped(g_linux_wlan
->strInterfaceInfo
[1].wilc_netdev
))
662 netif_wake_queue(g_linux_wlan
->strInterfaceInfo
[1].wilc_netdev
);
665 if (ret
== WILC_TX_ERR_NO_BUF
) { /* failed to allocate buffers in chip. */
667 /* Back off from sending packets for some time. */
668 /* schedule_timeout will allow RX task to run and free buffers.*/
669 /* set_current_state(TASK_UNINTERRUPTIBLE); */
670 /* timeout = schedule_timeout(timeout); */
671 msleep(TX_BACKOFF_WEIGHT_UNIT_MS
<< backoff_weight
);
672 } while (/*timeout*/ 0);
673 backoff_weight
+= TX_BACKOFF_WEIGHT_INCR_STEP
;
674 if (backoff_weight
> TX_BACKOFF_WEIGHT_MAX
)
675 backoff_weight
= TX_BACKOFF_WEIGHT_MAX
;
677 if (backoff_weight
> TX_BACKOFF_WEIGHT_MIN
) {
678 backoff_weight
-= TX_BACKOFF_WEIGHT_DECR_STEP
;
679 if (backoff_weight
< TX_BACKOFF_WEIGHT_MIN
)
680 backoff_weight
= TX_BACKOFF_WEIGHT_MIN
;
683 /*TODO: drop packets after a certain time/number of retry count. */
684 } while (ret
== WILC_TX_ERR_NO_BUF
&& !g_linux_wlan
->close
); /* retry sending packets if no more buffers in chip. */
690 static void linux_wlan_rx_complete(void)
692 PRINT_D(RX_DBG
, "RX completed\n");
695 int linux_wlan_get_firmware(perInterface_wlan_t
*p_nic
)
698 perInterface_wlan_t
*nic
= p_nic
;
700 const struct firmware
*wilc_firmware
;
703 if (nic
->iftype
== AP_MODE
)
704 firmware
= AP_FIRMWARE
;
705 else if (nic
->iftype
== STATION_MODE
)
706 firmware
= STA_FIRMWARE
;
710 PRINT_D(INIT_DBG
, "Get P2P_CONCURRENCY_FIRMWARE\n");
711 firmware
= P2P_CONCURRENCY_FIRMWARE
;
715 PRINT_ER("NIC is NULL\n");
719 if (&nic
->wilc_netdev
->dev
== NULL
) {
720 PRINT_ER("&nic->wilc_netdev->dev is NULL\n");
724 /* the firmare should be located in /lib/firmware in
725 * root file system with the name specified above */
728 if (request_firmware(&wilc_firmware
, firmware
, &g_linux_wlan
->wilc_sdio_func
->dev
) != 0) {
729 PRINT_ER("%s - firmare not available\n", firmware
);
734 if (request_firmware(&wilc_firmware
, firmware
, &g_linux_wlan
->wilc_spidev
->dev
) != 0) {
735 PRINT_ER("%s - firmare not available\n", firmware
);
740 g_linux_wlan
->wilc_firmware
= wilc_firmware
; /* Bug 4703 */
748 #ifdef COMPLEMENT_BOOT
749 int repeat_power_cycle(perInterface_wlan_t
*nic
);
752 static int linux_wlan_start_firmware(perInterface_wlan_t
*nic
)
757 PRINT_D(INIT_DBG
, "Starting Firmware ...\n");
758 ret
= g_linux_wlan
->oup
.wlan_start();
760 PRINT_ER("Failed to start Firmware\n");
764 /* wait for mac ready */
765 PRINT_D(INIT_DBG
, "Waiting for Firmware to get ready ...\n");
766 ret
= linux_wlan_lock_timeout(&g_linux_wlan
->sync_event
, 5000);
768 #ifdef COMPLEMENT_BOOT
769 static int timeout
= 5;
772 PRINT_D(INIT_DBG
, "repeat power cycle[%d]", timeout
);
773 ret
= repeat_power_cycle(nic
);
780 PRINT_D(INIT_DBG
, "Firmware start timed out");
784 * TODO: Driver shouoldn't wait forever for firmware to get started -
785 * in case of timeout this should be handled properly
787 PRINT_D(INIT_DBG
, "Firmware successfully started\n");
792 static int linux_wlan_firmware_download(linux_wlan_t
*p_nic
)
797 if (g_linux_wlan
->wilc_firmware
== NULL
) {
798 PRINT_ER("Firmware buffer is NULL\n");
803 * do the firmware download
805 PRINT_D(INIT_DBG
, "Downloading Firmware ...\n");
806 ret
= g_linux_wlan
->oup
.wlan_firmware_download(g_linux_wlan
->wilc_firmware
->data
, g_linux_wlan
->wilc_firmware
->size
);
810 /* Freeing FW buffer */
811 PRINT_D(INIT_DBG
, "Freeing FW buffer ...\n");
812 PRINT_D(INIT_DBG
, "Releasing firmware\n");
813 release_firmware(g_linux_wlan
->wilc_firmware
);
814 g_linux_wlan
->wilc_firmware
= NULL
;
816 PRINT_D(INIT_DBG
, "Download Succeeded\n");
822 /* startup configuration - could be changed later using iconfig*/
823 static int linux_wlan_init_test_config(struct net_device
*dev
, linux_wlan_t
*p_nic
)
826 unsigned char c_val
[64];
827 unsigned char mac_add
[] = {0x00, 0x80, 0xC2, 0x5E, 0xa2, 0xff};
830 struct wilc_priv
*priv
;
831 tstrWILC_WFIDrv
*pstrWFIDrv
;
833 PRINT_D(TX_DBG
, "Start configuring Firmware\n");
834 get_random_bytes(&mac_add
[5], 1);
835 get_random_bytes(&mac_add
[4], 1);
836 priv
= wiphy_priv(dev
->ieee80211_ptr
->wiphy
);
837 pstrWFIDrv
= (tstrWILC_WFIDrv
*)priv
->hWILCWFIDrv
;
838 PRINT_D(INIT_DBG
, "Host = %p\n", pstrWFIDrv
);
840 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]);
843 if (g_linux_wlan
->oup
.wlan_cfg_set
== NULL
) {
844 PRINT_D(INIT_DBG
, "Null p[ointer\n");
850 if (!g_linux_wlan
->oup
.wlan_cfg_set(1, WID_SET_DRV_HANDLER
, c_val
, 4, 0, 0))
853 /*to tell fw that we are going to use PC test - WILC specific*/
855 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_PC_TEST_MODE
, c_val
, 1, 0, 0))
858 c_val
[0] = INFRASTRUCTURE
;
859 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_BSS_TYPE
, c_val
, 1, 0, 0))
862 /* c_val[0] = RATE_AUTO; / * bug 4275: Enable autorate and limit it to 24Mbps * / */
863 c_val
[0] = RATE_AUTO
;
864 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_CURRENT_TX_RATE
, c_val
, 1, 0, 0))
867 c_val
[0] = G_MIXED_11B_2_MODE
;
868 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11G_OPERATING_MODE
, c_val
, 1, 0, 0))
872 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_CURRENT_CHANNEL
, c_val
, 1, 0, 0))
875 c_val
[0] = G_SHORT_PREAMBLE
;
876 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_PREAMBLE
, c_val
, 1, 0, 0))
879 c_val
[0] = AUTO_PROT
;
880 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_PROT_MECH
, c_val
, 1, 0, 0))
883 c_val
[0] = ACTIVE_SCAN
;
884 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_SCAN_TYPE
, c_val
, 1, 0, 0))
887 c_val
[0] = SITE_SURVEY_OFF
;
888 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_SITE_SURVEY
, c_val
, 1, 0, 0))
891 *((int *)c_val
) = 0xffff; /* Never use RTS-CTS */
892 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_RTS_THRESHOLD
, c_val
, 2, 0, 0))
895 *((int *)c_val
) = 2346;
896 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_FRAG_THRESHOLD
, c_val
, 2, 0, 0))
900 /* -------------------------------------------------------------- */
901 /* Configuration : String with length less than 32 bytes */
902 /* Values to set : Any string with length less than 32 bytes */
903 /* ( In BSS Station Set SSID to "" (null string) */
904 /* to enable Broadcast SSID suppport ) */
905 /* -------------------------------------------------------------- */
907 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_BCAST_SSID
, c_val
, 1, 0, 0))
911 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_QOS_ENABLE
, c_val
, 1, 0, 0))
914 c_val
[0] = NO_POWERSAVE
;
915 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_POWER_MANAGEMENT
, c_val
, 1, 0, 0))
918 c_val
[0] = NO_ENCRYPT
; /* NO_ENCRYPT, 0x79 */
919 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11I_MODE
, c_val
, 1, 0, 0))
922 c_val
[0] = OPEN_SYSTEM
;
923 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_AUTH_TYPE
, c_val
, 1, 0, 0))
926 /* WEP/802 11I Configuration */
927 /* ------------------------------------------------------------------ */
928 /* Configuration : WEP Key */
929 /* Values (0x) : 5 byte for WEP40 and 13 bytes for WEP104 */
930 /* In case more than 5 bytes are passed on for WEP 40 */
931 /* only first 5 bytes will be used as the key */
932 /* ------------------------------------------------------------------ */
934 strcpy(c_val
, "123456790abcdef1234567890");
935 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_WEP_KEY_VALUE
, c_val
, (strlen(c_val
) + 1), 0, 0))
938 /* WEP/802 11I Configuration */
939 /* ------------------------------------------------------------------ */
940 /* Configuration : AES/TKIP WPA/RSNA Pre-Shared Key */
941 /* Values to set : Any string with length greater than equal to 8 bytes */
942 /* and less than 64 bytes */
943 /* ------------------------------------------------------------------ */
944 strcpy(c_val
, "12345678");
945 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11I_PSK
, c_val
, (strlen(c_val
)), 0, 0))
948 /* IEEE802.1X Key Configuration */
949 /* ------------------------------------------------------------------ */
950 /* Configuration : Radius Server Access Secret Key */
951 /* Values to set : Any string with length greater than equal to 8 bytes */
952 /* and less than 65 bytes */
953 /* ------------------------------------------------------------------ */
954 strcpy(c_val
, "password");
955 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_1X_KEY
, c_val
, (strlen(c_val
) + 1), 0, 0))
958 /* IEEE802.1X Server Address Configuration */
959 /* ------------------------------------------------------------------ */
960 /* Configuration : Radius Server IP Address */
961 /* Values to set : Any valid IP Address */
962 /* ------------------------------------------------------------------ */
967 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_1X_SERV_ADDR
, c_val
, 4, 0, 0))
971 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_LISTEN_INTERVAL
, c_val
, 1, 0, 0))
975 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_DTIM_PERIOD
, c_val
, 1, 0, 0))
978 c_val
[0] = NORMAL_ACK
;
979 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_ACK_POLICY
, c_val
, 1, 0, 0))
983 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_USER_CONTROL_ON_TX_POWER
, c_val
, 1, 0, 0))
987 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_TX_POWER_LEVEL_11A
, c_val
, 1, 0, 0))
991 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_TX_POWER_LEVEL_11B
, c_val
, 1, 0, 0))
994 /* Beacon Interval */
995 /* -------------------------------------------------------------------- */
996 /* Configuration : Sets the beacon interval value */
997 /* Values to set : Any 16-bit value */
998 /* -------------------------------------------------------------------- */
1000 *((int *)c_val
) = 100;
1001 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_BEACON_INTERVAL
, c_val
, 2, 0, 0))
1004 c_val
[0] = REKEY_DISABLE
;
1005 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_REKEY_POLICY
, c_val
, 1, 0, 0))
1008 /* Rekey Time (s) (Used only when the Rekey policy is 2 or 4) */
1009 /* -------------------------------------------------------------------- */
1010 /* Configuration : Sets the Rekey Time (s) */
1011 /* Values to set : 32-bit value */
1012 /* -------------------------------------------------------------------- */
1013 *((int *)c_val
) = 84600;
1014 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_REKEY_PERIOD
, c_val
, 4, 0, 0))
1017 /* Rekey Packet Count (in 1000s; used when Rekey Policy is 3) */
1018 /* -------------------------------------------------------------------- */
1019 /* Configuration : Sets Rekey Group Packet count */
1020 /* Values to set : 32-bit Value */
1021 /* -------------------------------------------------------------------- */
1022 *((int *)c_val
) = 500;
1023 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_REKEY_PACKET_COUNT
, c_val
, 4, 0, 0))
1027 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_SHORT_SLOT_ALLOWED
, c_val
, 1, 0, 0))
1030 c_val
[0] = G_SELF_CTS_PROT
;
1031 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_ERP_PROT_TYPE
, c_val
, 1, 0, 0))
1034 c_val
[0] = 1; /* Enable N */
1035 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_ENABLE
, c_val
, 1, 0, 0))
1038 c_val
[0] = HT_MIXED_MODE
;
1039 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_OPERATING_MODE
, c_val
, 1, 0, 0))
1042 c_val
[0] = 1; /* TXOP Prot disable in N mode: No RTS-CTS on TX A-MPDUs to save air-time. */
1043 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_TXOP_PROT_DISABLE
, c_val
, 1, 0, 0))
1046 memcpy(c_val
, mac_add
, 6);
1048 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_MAC_ADDR
, c_val
, 6, 0, 0))
1054 c_val
[0] = DETECT_PROTECT_REPORT
;
1055 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_OBSS_NONHT_DETECTION
, c_val
, 1, 0, 0))
1058 c_val
[0] = RTS_CTS_NONHT_PROT
;
1059 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_HT_PROT_TYPE
, c_val
, 1, 0, 0))
1063 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_RIFS_PROT_ENABLE
, c_val
, 1, 0, 0))
1066 c_val
[0] = MIMO_MODE
;
1067 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_SMPS_MODE
, c_val
, 1, 0, 0))
1071 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_CURRENT_TX_MCS
, c_val
, 1, 0, 0))
1074 c_val
[0] = 1; /* Enable N with immediate block ack. */
1075 if (!g_linux_wlan
->oup
.wlan_cfg_set(0, WID_11N_IMMEDIATE_BA_ENABLED
, c_val
, 1, 1, 1))
1084 /**************************/
1085 void wilc1000_wlan_deinit(linux_wlan_t
*nic
)
1088 if (g_linux_wlan
->wilc1000_initialized
) {
1090 printk("Deinitializing wilc1000 ...\n");
1093 PRINT_ER("nic is NULL\n");
1097 #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
1098 /* johnny : remove */
1099 PRINT_D(INIT_DBG
, "skip wilc_bus_set_default_speed\n");
1101 wilc_bus_set_default_speed();
1104 PRINT_D(INIT_DBG
, "Disabling IRQ\n");
1105 #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
1106 linux_wlan_disable_irq(IRQ_WAIT
);
1108 #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
1111 mutex_lock(&g_linux_wlan
->hif_cs
);
1112 disable_sdio_interrupt();
1113 mutex_unlock(&g_linux_wlan
->hif_cs
);
1117 /* not sure if the following unlocks are needed or not*/
1118 if (&g_linux_wlan
->rxq_event
!= NULL
)
1119 up(&g_linux_wlan
->rxq_event
);
1121 if (&g_linux_wlan
->txq_event
!= NULL
)
1122 up(&g_linux_wlan
->txq_event
);
1124 #if (RX_BH_TYPE == RX_BH_WORK_QUEUE)
1125 /*Removing the work struct from the linux kernel workqueue*/
1126 if (&g_linux_wlan
->rx_work_queue
!= NULL
)
1127 flush_work(&g_linux_wlan
->rx_work_queue
);
1129 #elif (RX_BH_TYPE == RX_BH_KTHREAD)
1130 /* if(&nic->rx_sem != NULL) */
1131 /* up(&nic->rx_sem); */
1134 PRINT_D(INIT_DBG
, "Deinitializing Threads\n");
1135 wlan_deinitialize_threads(nic
);
1137 PRINT_D(INIT_DBG
, "Deinitializing IRQ\n");
1138 deinit_irq(g_linux_wlan
);
1140 if (&g_linux_wlan
->oup
!= NULL
) {
1141 if (g_linux_wlan
->oup
.wlan_stop
!= NULL
)
1142 g_linux_wlan
->oup
.wlan_stop();
1145 PRINT_D(INIT_DBG
, "Deinitializing WILC Wlan\n");
1146 wilc_wlan_deinit(nic
);
1147 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
1148 #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
1149 PRINT_D(INIT_DBG
, "Disabling IRQ 2\n");
1151 mutex_lock(&g_linux_wlan
->hif_cs
);
1152 disable_sdio_interrupt();
1153 mutex_unlock(&g_linux_wlan
->hif_cs
);
1157 /*De-Initialize locks*/
1158 PRINT_D(INIT_DBG
, "Deinitializing Locks\n");
1159 wlan_deinit_locks(g_linux_wlan
);
1161 /* announce that wilc1000 is not initialized */
1162 g_linux_wlan
->wilc1000_initialized
= 0;
1164 PRINT_D(INIT_DBG
, "wilc1000 deinitialization Done\n");
1167 PRINT_D(INIT_DBG
, "wilc1000 is not initialized\n");
1171 int wlan_init_locks(linux_wlan_t
*p_nic
)
1174 PRINT_D(INIT_DBG
, "Initializing Locks ...\n");
1176 mutex_init(&g_linux_wlan
->hif_cs
);
1177 mutex_init(&g_linux_wlan
->rxq_cs
);
1178 mutex_init(&g_linux_wlan
->txq_cs
);
1180 /*Added by Amr - BugID_4720*/
1181 spin_lock_init(&g_linux_wlan
->txq_spinlock
);
1182 sema_init(&g_linux_wlan
->txq_add_to_head_cs
, 1);
1184 sema_init(&g_linux_wlan
->txq_event
, 0);
1185 sema_init(&g_linux_wlan
->rxq_event
, 0);
1187 sema_init(&g_linux_wlan
->cfg_event
, 0);
1188 sema_init(&g_linux_wlan
->sync_event
, 0);
1190 sema_init(&g_linux_wlan
->rxq_thread_started
, 0);
1191 sema_init(&g_linux_wlan
->txq_thread_started
, 0);
1193 #if (RX_BH_TYPE == RX_BH_KTHREAD)
1194 sema_init(&g_linux_wlan
->rx_sem
, 0);
1200 static int wlan_deinit_locks(linux_wlan_t
*nic
)
1202 PRINT_D(INIT_DBG
, "De-Initializing Locks\n");
1204 if (&g_linux_wlan
->hif_cs
!= NULL
)
1205 mutex_destroy(&g_linux_wlan
->hif_cs
);
1207 if (&g_linux_wlan
->rxq_cs
!= NULL
)
1208 mutex_destroy(&g_linux_wlan
->rxq_cs
);
1210 if (&g_linux_wlan
->txq_cs
!= NULL
)
1211 mutex_destroy(&g_linux_wlan
->txq_cs
);
1215 void linux_to_wlan(wilc_wlan_inp_t
*nwi
, linux_wlan_t
*nic
)
1218 PRINT_D(INIT_DBG
, "Linux to Wlan services ...\n");
1220 nwi
->os_context
.hif_critical_section
= (void *)&g_linux_wlan
->hif_cs
;
1221 nwi
->os_context
.os_private
= (void *)nic
;
1222 nwi
->os_context
.tx_buffer_size
= LINUX_TX_SIZE
;
1223 nwi
->os_context
.txq_critical_section
= (void *)&g_linux_wlan
->txq_cs
;
1225 /*Added by Amr - BugID_4720*/
1226 nwi
->os_context
.txq_add_to_head_critical_section
= (void *)&g_linux_wlan
->txq_add_to_head_cs
;
1228 /*Added by Amr - BugID_4720*/
1229 nwi
->os_context
.txq_spin_lock
= (void *)&g_linux_wlan
->txq_spinlock
;
1231 nwi
->os_context
.txq_wait_event
= (void *)&g_linux_wlan
->txq_event
;
1233 #if defined(MEMORY_STATIC)
1234 nwi
->os_context
.rx_buffer_size
= LINUX_RX_SIZE
;
1236 nwi
->os_context
.rxq_critical_section
= (void *)&g_linux_wlan
->rxq_cs
;
1237 nwi
->os_context
.rxq_wait_event
= (void *)&g_linux_wlan
->rxq_event
;
1238 nwi
->os_context
.cfg_wait_event
= (void *)&g_linux_wlan
->cfg_event
;
1240 nwi
->os_func
.os_debug
= linux_wlan_dbg
;
1241 nwi
->os_func
.os_wait
= linux_wlan_lock_timeout
;
1244 nwi
->io_func
.io_type
= HIF_SDIO
;
1245 nwi
->io_func
.io_init
= linux_sdio_init
;
1246 nwi
->io_func
.io_deinit
= linux_sdio_deinit
;
1247 nwi
->io_func
.u
.sdio
.sdio_cmd52
= linux_sdio_cmd52
;
1248 nwi
->io_func
.u
.sdio
.sdio_cmd53
= linux_sdio_cmd53
;
1249 nwi
->io_func
.u
.sdio
.sdio_set_max_speed
= linux_sdio_set_max_speed
;
1250 nwi
->io_func
.u
.sdio
.sdio_set_default_speed
= linux_sdio_set_default_speed
;
1252 nwi
->io_func
.io_type
= HIF_SPI
;
1253 nwi
->io_func
.io_init
= linux_spi_init
;
1254 nwi
->io_func
.io_deinit
= linux_spi_deinit
;
1255 nwi
->io_func
.u
.spi
.spi_tx
= linux_spi_write
;
1256 nwi
->io_func
.u
.spi
.spi_rx
= linux_spi_read
;
1257 nwi
->io_func
.u
.spi
.spi_trx
= linux_spi_write_read
;
1258 nwi
->io_func
.u
.spi
.spi_max_speed
= linux_spi_set_max_speed
;
1261 /*for now - to be revised*/
1262 nwi
->net_func
.rx_indicate
= frmw_to_linux
;
1263 nwi
->net_func
.rx_complete
= linux_wlan_rx_complete
;
1264 nwi
->indicate_func
.mac_indicate
= linux_wlan_mac_indicate
;
1267 int wlan_initialize_threads(perInterface_wlan_t
*nic
)
1272 PRINT_D(INIT_DBG
, "Initializing Threads ...\n");
1274 #if (RX_BH_TYPE == RX_BH_WORK_QUEUE)
1275 /*Initialize rx work queue task*/
1276 INIT_WORK(&g_linux_wlan
->rx_work_queue
, isr_bh_routine
);
1277 #elif (RX_BH_TYPE == RX_BH_KTHREAD)
1278 PRINT_D(INIT_DBG
, "Creating kthread for Rxq BH\n");
1279 g_linux_wlan
->rx_bh_thread
= kthread_run(isr_bh_routine
, (void *)g_linux_wlan
, "K_RXQ_BH");
1280 if (g_linux_wlan
->rx_bh_thread
== NULL
) {
1281 PRINT_ER("couldn't create RX BH thread\n");
1287 #ifndef TCP_ENHANCEMENTS
1288 /* create rx task */
1289 PRINT_D(INIT_DBG
, "Creating kthread for reception\n");
1290 g_linux_wlan
->rxq_thread
= kthread_run(linux_wlan_rxq_task
, (void *)g_linux_wlan
, "K_RXQ_TASK");
1291 if (g_linux_wlan
->rxq_thread
== 0) {
1292 PRINT_ER("couldn't create RXQ thread\n");
1297 /* wait for RXQ task to start. */
1298 down(&g_linux_wlan
->rxq_thread_started
);
1302 /* create tx task */
1303 PRINT_D(INIT_DBG
, "Creating kthread for transmission\n");
1304 g_linux_wlan
->txq_thread
= kthread_run(linux_wlan_txq_task
, (void *)g_linux_wlan
, "K_TXQ_TASK");
1305 if (g_linux_wlan
->txq_thread
== NULL
) {
1306 PRINT_ER("couldn't create TXQ thread\n");
1311 PRINT_D(INIT_DBG
, "Creating kthread for Debugging\n");
1312 g_linux_wlan
->txq_thread
= kthread_run(DebuggingThreadTask
, (void *)g_linux_wlan
, "DebugThread");
1313 if (g_linux_wlan
->txq_thread
== 0) {
1314 PRINT_ER("couldn't create TXQ thread\n");
1319 /* wait for TXQ task to start. */
1320 down(&g_linux_wlan
->txq_thread_started
);
1325 /*De-Initialize 2nd thread*/
1326 g_linux_wlan
->close
= 1;
1327 up(&g_linux_wlan
->rxq_event
);
1328 kthread_stop(g_linux_wlan
->rxq_thread
);
1330 #ifndef TCP_ENHANCEMENTS
1333 #if (RX_BH_TYPE == RX_BH_KTHREAD)
1334 /*De-Initialize 1st thread*/
1335 g_linux_wlan
->close
= 1;
1336 up(&g_linux_wlan
->rx_sem
);
1337 kthread_stop(g_linux_wlan
->rx_bh_thread
);
1340 g_linux_wlan
->close
= 0;
1344 static void wlan_deinitialize_threads(linux_wlan_t
*nic
)
1347 g_linux_wlan
->close
= 1;
1348 PRINT_D(INIT_DBG
, "Deinitializing Threads\n");
1349 if (&g_linux_wlan
->rxq_event
!= NULL
)
1350 up(&g_linux_wlan
->rxq_event
);
1352 if (g_linux_wlan
->rxq_thread
!= NULL
) {
1353 kthread_stop(g_linux_wlan
->rxq_thread
);
1354 g_linux_wlan
->rxq_thread
= NULL
;
1357 if (&g_linux_wlan
->txq_event
!= NULL
)
1358 up(&g_linux_wlan
->txq_event
);
1360 if (g_linux_wlan
->txq_thread
!= NULL
) {
1361 kthread_stop(g_linux_wlan
->txq_thread
);
1362 g_linux_wlan
->txq_thread
= NULL
;
1365 #if (RX_BH_TYPE == RX_BH_KTHREAD)
1366 if (&g_linux_wlan
->rx_sem
!= NULL
)
1367 up(&g_linux_wlan
->rx_sem
);
1369 if (g_linux_wlan
->rx_bh_thread
!= NULL
) {
1370 kthread_stop(g_linux_wlan
->rx_bh_thread
);
1371 g_linux_wlan
->rx_bh_thread
= NULL
;
1376 #ifdef COMPLEMENT_BOOT
1378 extern volatile int probe
;
1379 extern u8
core_11b_ready(void);
1381 #define READY_CHECK_THRESHOLD 30
1382 extern void wilc_wlan_global_reset(void);
1383 u8
wilc1000_prepare_11b_core(wilc_wlan_inp_t
*nwi
, wilc_wlan_oup_t
*nwo
, linux_wlan_t
*nic
)
1387 while ((core_11b_ready() && (READY_CHECK_THRESHOLD
> (trials
++)))) {
1388 PRINT_D(INIT_DBG
, "11b core not ready yet: %u\n", trials
);
1389 wilc_wlan_deinit(nic
);
1390 wilc_wlan_global_reset();
1391 sdio_unregister_driver(&wilc_bus
);
1393 linux_wlan_device_detection(0);
1397 linux_wlan_device_detection(1);
1399 sdio_register_driver(&wilc_bus
);
1404 g_linux_wlan
->wilc_sdio_func
= local_sdio_func
;
1405 linux_to_wlan(nwi
, nic
);
1406 wilc_wlan_init(nwi
, nwo
);
1409 if (READY_CHECK_THRESHOLD
<= trials
)
1416 int repeat_power_cycle(perInterface_wlan_t
*nic
)
1419 wilc_wlan_inp_t nwi
;
1420 wilc_wlan_oup_t nwo
;
1422 sdio_unregister_driver(&wilc_bus
);
1424 linux_wlan_device_detection(0);
1425 linux_wlan_device_power(0);
1427 linux_wlan_device_power(1);
1429 linux_wlan_device_detection(1);
1432 sdio_register_driver(&wilc_bus
);
1438 g_linux_wlan
->wilc_sdio_func
= local_sdio_func
;
1439 linux_to_wlan(&nwi
, g_linux_wlan
);
1440 ret
= wilc_wlan_init(&nwi
, &nwo
);
1442 g_linux_wlan
->mac_status
= WILC_MAC_STATUS_INIT
;
1443 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
1444 enable_sdio_interrupt();
1447 if (linux_wlan_get_firmware(nic
)) {
1448 PRINT_ER("Can't get firmware\n");
1453 /*Download firmware*/
1454 ret
= linux_wlan_firmware_download(g_linux_wlan
);
1456 PRINT_ER("Failed to download firmware\n");
1460 ret
= linux_wlan_start_firmware(nic
);
1462 PRINT_ER("Failed to start firmware\n");
1468 int wilc1000_wlan_init(struct net_device
*dev
, perInterface_wlan_t
*p_nic
)
1470 wilc_wlan_inp_t nwi
;
1471 wilc_wlan_oup_t nwo
;
1472 perInterface_wlan_t
*nic
= p_nic
;
1475 if (!g_linux_wlan
->wilc1000_initialized
) {
1476 g_linux_wlan
->mac_status
= WILC_MAC_STATUS_INIT
;
1477 g_linux_wlan
->close
= 0;
1478 g_linux_wlan
->wilc1000_initialized
= 0;
1480 wlan_init_locks(g_linux_wlan
);
1482 linux_to_wlan(&nwi
, g_linux_wlan
);
1484 ret
= wilc_wlan_init(&nwi
, &nwo
);
1486 PRINT_ER("Initializing WILC_Wlan FAILED\n");
1490 memcpy(&g_linux_wlan
->oup
, &nwo
, sizeof(wilc_wlan_oup_t
));
1492 /*Save the oup structre into global pointer*/
1493 gpstrWlanOps
= &g_linux_wlan
->oup
;
1495 ret
= wlan_initialize_threads(nic
);
1497 PRINT_ER("Initializing Threads FAILED\n");
1499 goto _fail_wilc_wlan_
;
1502 #if (defined WILC_SDIO) && (defined COMPLEMENT_BOOT)
1503 if (wilc1000_prepare_11b_core(&nwi
, &nwo
, g_linux_wlan
)) {
1504 PRINT_ER("11b Core is not ready\n");
1506 goto _fail_threads_
;
1510 #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
1511 if (init_irq(g_linux_wlan
)) {
1512 PRINT_ER("couldn't initialize IRQ\n");
1514 goto _fail_threads_
;
1518 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
1519 if (enable_sdio_interrupt()) {
1520 PRINT_ER("couldn't initialize IRQ\n");
1522 goto _fail_irq_init_
;
1526 if (linux_wlan_get_firmware(nic
)) {
1527 PRINT_ER("Can't get firmware\n");
1529 goto _fail_irq_enable_
;
1532 /*Download firmware*/
1533 ret
= linux_wlan_firmware_download(g_linux_wlan
);
1535 PRINT_ER("Failed to download firmware\n");
1537 goto _fail_irq_enable_
;
1541 ret
= linux_wlan_start_firmware(nic
);
1543 PRINT_ER("Failed to start firmware\n");
1545 goto _fail_irq_enable_
;
1548 wilc_bus_set_max_speed();
1550 if (g_linux_wlan
->oup
.wlan_cfg_get(1, WID_FIRMWARE_VERSION
, 1, 0)) {
1552 char Firmware_ver
[20];
1554 size
= g_linux_wlan
->oup
.wlan_cfg_get_value(
1555 WID_FIRMWARE_VERSION
,
1556 Firmware_ver
, sizeof(Firmware_ver
));
1557 Firmware_ver
[size
] = '\0';
1558 PRINT_D(INIT_DBG
, "***** Firmware Ver = %s *******\n", Firmware_ver
);
1560 /* Initialize firmware with default configuration */
1561 ret
= linux_wlan_init_test_config(dev
, g_linux_wlan
);
1564 PRINT_ER("Failed to configure firmware\n");
1566 goto _fail_fw_start_
;
1569 g_linux_wlan
->wilc1000_initialized
= 1;
1570 return 0; /*success*/
1573 if (&g_linux_wlan
->oup
!= NULL
) {
1574 if (g_linux_wlan
->oup
.wlan_stop
!= NULL
)
1575 g_linux_wlan
->oup
.wlan_stop();
1579 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
1580 disable_sdio_interrupt();
1583 #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
1584 deinit_irq(g_linux_wlan
);
1588 wlan_deinitialize_threads(g_linux_wlan
);
1590 wilc_wlan_deinit(g_linux_wlan
);
1592 wlan_deinit_locks(g_linux_wlan
);
1593 PRINT_ER("WLAN Iinitialization FAILED\n");
1595 PRINT_D(INIT_DBG
, "wilc1000 already initialized\n");
1601 * - this function will be called automatically by OS when module inserted.
1604 int mac_init_fn(struct net_device
*ndev
)
1607 /*Why we do this !!!*/
1608 netif_start_queue(ndev
); /* ma */
1609 netif_stop_queue(ndev
); /* ma */
1614 void WILC_WFI_frame_register(struct wiphy
*wiphy
, struct net_device
*dev
,
1615 u16 frame_type
, bool reg
);
1617 /* This fn is called, when this device is setup using ifconfig */
1618 int mac_open(struct net_device
*ndev
)
1620 perInterface_wlan_t
*nic
;
1623 /*No need for setting mac address here anymore,*/
1624 /*Just set it in init_test_config()*/
1625 unsigned char mac_add
[ETH_ALEN
] = {0};
1628 struct wilc_priv
*priv
;
1631 if (!g_linux_wlan
|| !g_linux_wlan
->wilc_spidev
) {
1632 netdev_err(ndev
, "wilc1000: SPI device not ready\n");
1636 nic
= netdev_priv(ndev
);
1637 priv
= wiphy_priv(nic
->wilc_netdev
->ieee80211_ptr
->wiphy
);
1638 PRINT_D(INIT_DBG
, "MAC OPEN[%p]\n", ndev
);
1640 ret
= WILC_WFI_InitHostInt(ndev
);
1642 PRINT_ER("Failed to initialize host interface\n");
1647 /*initialize platform*/
1648 PRINT_D(INIT_DBG
, "*** re-init ***\n");
1649 ret
= wilc1000_wlan_init(ndev
, nic
);
1651 PRINT_ER("Failed to initialize wilc1000\n");
1652 WILC_WFI_DeInitHostInt(ndev
);
1656 Set_machw_change_vir_if(false);
1658 host_int_get_MacAddress(priv
->hWILCWFIDrv
, mac_add
);
1659 PRINT_D(INIT_DBG
, "Mac address: %pM\n", mac_add
);
1661 /* loop through the NUM of supported devices and set the MAC address */
1662 for (i
= 0; i
< g_linux_wlan
->u8NoIfcs
; i
++) {
1663 if (ndev
== g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
) {
1664 memcpy(g_linux_wlan
->strInterfaceInfo
[i
].aSrcAddress
, mac_add
, ETH_ALEN
);
1665 g_linux_wlan
->strInterfaceInfo
[i
].drvHandler
= priv
->hWILCWFIDrv
;
1670 /* TODO: get MAC address whenever the source is EPROM - hardcoded and copy it to ndev*/
1671 memcpy(ndev
->dev_addr
, g_linux_wlan
->strInterfaceInfo
[i
].aSrcAddress
, ETH_ALEN
);
1673 if (!is_valid_ether_addr(ndev
->dev_addr
)) {
1674 PRINT_ER("Error: Wrong MAC address\n");
1679 WILC_WFI_frame_register(nic
->wilc_netdev
->ieee80211_ptr
->wiphy
, nic
->wilc_netdev
,
1680 nic
->g_struct_frame_reg
[0].frame_type
, nic
->g_struct_frame_reg
[0].reg
);
1681 WILC_WFI_frame_register(nic
->wilc_netdev
->ieee80211_ptr
->wiphy
, nic
->wilc_netdev
,
1682 nic
->g_struct_frame_reg
[1].frame_type
, nic
->g_struct_frame_reg
[1].reg
);
1683 netif_wake_queue(ndev
);
1684 g_linux_wlan
->open_ifcs
++;
1685 nic
->mac_opened
= 1;
1689 WILC_WFI_DeInitHostInt(ndev
);
1690 wilc1000_wlan_deinit(g_linux_wlan
);
1694 struct net_device_stats
*mac_stats(struct net_device
*dev
)
1696 perInterface_wlan_t
*nic
= netdev_priv(dev
);
1698 return &nic
->netstats
;
1701 /* Setup the multicast filter */
1702 static void wilc_set_multicast_list(struct net_device
*dev
)
1705 struct netdev_hw_addr
*ha
;
1706 struct wilc_priv
*priv
;
1707 tstrWILC_WFIDrv
*pstrWFIDrv
;
1710 priv
= wiphy_priv(dev
->ieee80211_ptr
->wiphy
);
1711 pstrWFIDrv
= (tstrWILC_WFIDrv
*)priv
->hWILCWFIDrv
;
1716 PRINT_D(INIT_DBG
, "Setting Multicast List with count = %d.\n", dev
->mc
.count
);
1718 if (dev
->flags
& IFF_PROMISC
) {
1719 /* Normally, we should configure the chip to retrive all packets
1720 * but we don't wanna support this right now */
1721 /* TODO: add promiscuous mode support */
1722 PRINT_D(INIT_DBG
, "Set promiscuous mode ON, retrive all packets\n");
1726 /* If there's more addresses than we handle, get all multicast
1727 * packets and sort them out in software. */
1728 if ((dev
->flags
& IFF_ALLMULTI
) || (dev
->mc
.count
) > WILC_MULTICAST_TABLE_SIZE
) {
1729 PRINT_D(INIT_DBG
, "Disable multicast filter, retrive all multicast packets\n");
1730 /* get all multicast packets */
1731 host_int_setup_multicast_filter(pstrWFIDrv
, false, 0);
1735 /* No multicast? Just get our own stuff */
1736 if ((dev
->mc
.count
) == 0) {
1737 PRINT_D(INIT_DBG
, "Enable multicast filter, retrive directed packets only.\n");
1738 host_int_setup_multicast_filter(pstrWFIDrv
, true, 0);
1742 /* Store all of the multicast addresses in the hardware filter */
1743 netdev_for_each_mc_addr(ha
, dev
)
1745 memcpy(gau8MulticastMacAddrList
[i
], ha
->addr
, ETH_ALEN
);
1746 PRINT_D(INIT_DBG
, "Entry[%d]: %x:%x:%x:%x:%x:%x\n", i
,
1747 gau8MulticastMacAddrList
[i
][0], gau8MulticastMacAddrList
[i
][1], gau8MulticastMacAddrList
[i
][2], gau8MulticastMacAddrList
[i
][3], gau8MulticastMacAddrList
[i
][4], gau8MulticastMacAddrList
[i
][5]);
1751 host_int_setup_multicast_filter(pstrWFIDrv
, true, (dev
->mc
.count
));
1757 static void linux_wlan_tx_complete(void *priv
, int status
)
1760 struct tx_complete_data
*pv_data
= (struct tx_complete_data
*)priv
;
1763 PRINT_D(TX_DBG
, "Packet sent successfully - Size = %d - Address = %p - SKB = %p\n", pv_data
->size
, pv_data
->buff
, pv_data
->skb
);
1765 PRINT_D(TX_DBG
, "Couldn't send packet - Size = %d - Address = %p - SKB = %p\n", pv_data
->size
, pv_data
->buff
, pv_data
->skb
);
1766 /* Free the SK Buffer, its work is done */
1767 dev_kfree_skb(pv_data
->skb
);
1771 int mac_xmit(struct sk_buff
*skb
, struct net_device
*ndev
)
1773 perInterface_wlan_t
*nic
;
1774 struct tx_complete_data
*tx_data
= NULL
;
1778 struct ethhdr
*eth_h
;
1780 nic
= netdev_priv(ndev
);
1782 PRINT_D(TX_DBG
, "Sending packet just received from TCP/IP\n");
1784 /* Stop the network interface queue */
1785 if (skb
->dev
!= ndev
) {
1786 PRINT_ER("Packet not destined to this device\n");
1790 tx_data
= kmalloc(sizeof(struct tx_complete_data
), GFP_ATOMIC
);
1791 if (tx_data
== NULL
) {
1792 PRINT_ER("Failed to allocate memory for tx_data structure\n");
1794 netif_wake_queue(ndev
);
1798 tx_data
->buff
= skb
->data
;
1799 tx_data
->size
= skb
->len
;
1802 eth_h
= (struct ethhdr
*)(skb
->data
);
1803 if (eth_h
->h_proto
== 0x8e88)
1804 PRINT_D(INIT_DBG
, "EAPOL transmitted\n");
1806 /*get source and dest ip addresses*/
1807 ih
= (struct iphdr
*)(skb
->data
+ sizeof(struct ethhdr
));
1809 pu8UdpBuffer
= (char *)ih
+ sizeof(struct iphdr
);
1810 if ((pu8UdpBuffer
[1] == 68 && pu8UdpBuffer
[3] == 67) || (pu8UdpBuffer
[1] == 67 && pu8UdpBuffer
[3] == 68))
1811 PRINT_D(GENERIC_DBG
, "DHCP Message transmitted, type:%x %x %x\n", pu8UdpBuffer
[248], pu8UdpBuffer
[249], pu8UdpBuffer
[250]);
1813 PRINT_D(TX_DBG
, "Sending packet - Size = %d - Address = %p - SKB = %p\n", tx_data
->size
, tx_data
->buff
, tx_data
->skb
);
1815 /* Send packet to MAC HW - for now the tx_complete function will be just status
1816 * indicator. still not sure if I need to suspend host transmission till the tx_complete
1817 * function called or not?
1818 * allocated buffer will be freed in tx_complete function.
1820 PRINT_D(TX_DBG
, "Adding tx packet to TX Queue\n");
1821 nic
->netstats
.tx_packets
++;
1822 nic
->netstats
.tx_bytes
+= tx_data
->size
;
1823 tx_data
->pBssid
= g_linux_wlan
->strInterfaceInfo
[nic
->u8IfIdx
].aBSSID
;
1824 QueueCount
= g_linux_wlan
->oup
.wlan_add_to_tx_que((void *)tx_data
,
1827 linux_wlan_tx_complete
);
1829 if (QueueCount
> FLOW_CONTROL_UPPER_THRESHOLD
) {
1830 netif_stop_queue(g_linux_wlan
->strInterfaceInfo
[0].wilc_netdev
);
1831 netif_stop_queue(g_linux_wlan
->strInterfaceInfo
[1].wilc_netdev
);
1837 int mac_close(struct net_device
*ndev
)
1839 struct wilc_priv
*priv
;
1840 perInterface_wlan_t
*nic
;
1841 tstrWILC_WFIDrv
*pstrWFIDrv
;
1843 nic
= netdev_priv(ndev
);
1845 if ((nic
== NULL
) || (nic
->wilc_netdev
== NULL
) || (nic
->wilc_netdev
->ieee80211_ptr
== NULL
) || (nic
->wilc_netdev
->ieee80211_ptr
->wiphy
== NULL
)) {
1846 PRINT_ER("nic = NULL\n");
1850 priv
= wiphy_priv(nic
->wilc_netdev
->ieee80211_ptr
->wiphy
);
1853 PRINT_ER("priv = NULL\n");
1857 pstrWFIDrv
= (tstrWILC_WFIDrv
*)priv
->hWILCWFIDrv
;
1859 PRINT_D(GENERIC_DBG
, "Mac close\n");
1861 if (g_linux_wlan
== NULL
) {
1862 PRINT_ER("g_linux_wlan = NULL\n");
1866 if (pstrWFIDrv
== NULL
) {
1867 PRINT_ER("pstrWFIDrv = NULL\n");
1871 if ((g_linux_wlan
->open_ifcs
) > 0) {
1872 g_linux_wlan
->open_ifcs
--;
1874 PRINT_ER("ERROR: MAC close called while number of opened interfaces is zero\n");
1878 if (nic
->wilc_netdev
!= NULL
) {
1879 /* Stop the network interface queue */
1880 netif_stop_queue(nic
->wilc_netdev
);
1882 WILC_WFI_DeInitHostInt(nic
->wilc_netdev
);
1885 if (g_linux_wlan
->open_ifcs
== 0) {
1886 PRINT_D(GENERIC_DBG
, "Deinitializing wilc1000\n");
1887 g_linux_wlan
->close
= 1;
1888 wilc1000_wlan_deinit(g_linux_wlan
);
1889 #ifdef WILC_AP_EXTERNAL_MLME
1890 WILC_WFI_deinit_mon_interface();
1894 up(&close_exit_sync
);
1895 nic
->mac_opened
= 0;
1900 int mac_ioctl(struct net_device
*ndev
, struct ifreq
*req
, int cmd
)
1905 u32 size
= 0, length
= 0;
1906 perInterface_wlan_t
*nic
;
1907 struct wilc_priv
*priv
;
1910 /* struct iwreq *wrq = (struct iwreq *) req; // tony moved to case SIOCSIWPRIV */
1911 nic
= netdev_priv(ndev
);
1913 if (!g_linux_wlan
->wilc1000_initialized
)
1921 struct iwreq
*wrq
= (struct iwreq
*) req
; /* added by tony */
1923 size
= wrq
->u
.data
.length
;
1925 if (size
&& wrq
->u
.data
.pointer
) {
1927 buff
= memdup_user(wrq
->u
.data
.pointer
, wrq
->u
.data
.length
);
1929 return PTR_ERR(buff
);
1931 if (strncasecmp(buff
, "RSSI", length
) == 0) {
1932 priv
= wiphy_priv(nic
->wilc_netdev
->ieee80211_ptr
->wiphy
);
1933 s32Error
= host_int_get_rssi(priv
->hWILCWFIDrv
, &(rssi
));
1935 PRINT_ER("Failed to send get rssi param's message queue ");
1936 PRINT_INFO(GENERIC_DBG
, "RSSI :%d\n", rssi
);
1938 /*Rounding up the rssi negative value*/
1941 snprintf(buff
, size
, "rssi %d", rssi
);
1943 if (copy_to_user(wrq
->u
.data
.pointer
, buff
, size
)) {
1944 PRINT_ER("%s: failed to copy data to user buffer\n", __func__
);
1955 PRINT_INFO(GENERIC_DBG
, "Command - %d - has been received\n", cmd
);
1956 s32Error
= -EOPNOTSUPP
;
1968 void frmw_to_linux(u8
*buff
, u32 size
, u32 pkt_offset
)
1971 unsigned int frame_len
= 0;
1973 unsigned char *buff_to_send
= NULL
;
1974 struct sk_buff
*skb
;
1975 #ifndef TCP_ENHANCEMENTS
1979 struct net_device
*wilc_netdev
;
1980 perInterface_wlan_t
*nic
;
1982 wilc_netdev
= GetIfHandler(buff
);
1983 if (wilc_netdev
== NULL
)
1987 nic
= netdev_priv(wilc_netdev
);
1992 buff_to_send
= buff
;
1994 /* Need to send the packet up to the host, allocate a skb buffer */
1995 skb
= dev_alloc_skb(frame_len
);
1997 PRINT_ER("Low memory - packet droped\n");
2001 if (g_linux_wlan
== NULL
|| wilc_netdev
== NULL
)
2002 PRINT_ER("wilc_netdev in g_linux_wlan is NULL");
2003 skb
->dev
= wilc_netdev
;
2005 if (skb
->dev
== NULL
)
2006 PRINT_ER("skb->dev is NULL\n");
2012 * WILC_PRINTF("buff_to_send[%d]=%2x\n",i,buff_to_send[i]);
2016 /* skb_put(skb, frame_len); */
2017 memcpy(skb_put(skb
, frame_len
), buff_to_send
, frame_len
);
2019 /* WILC_PRINTF("After MEM_CPY\n"); */
2021 /* nic = netdev_priv(wilc_netdev); */
2023 skb
->protocol
= eth_type_trans(skb
, wilc_netdev
);
2024 #ifndef TCP_ENHANCEMENTS
2025 /*get source and dest ip addresses*/
2026 ih
= (struct iphdr
*)(skb
->data
+ sizeof(struct ethhdr
));
2028 pu8UdpBuffer
= (char *)ih
+ sizeof(struct iphdr
);
2029 if (buff_to_send
[35] == 67 && buff_to_send
[37] == 68)
2030 PRINT_D(RX_DBG
, "DHCP Message received\n");
2031 if (buff_to_send
[12] == 0x88 && buff_to_send
[13] == 0x8e)
2032 PRINT_D(GENERIC_DBG
, "eapol received\n");
2034 /* Send the packet to the stack by giving it to the bridge */
2035 nic
->netstats
.rx_packets
++;
2036 nic
->netstats
.rx_bytes
+= frame_len
;
2037 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
2038 stats
= netif_rx(skb
);
2039 PRINT_D(RX_DBG
, "netif_rx ret value is: %d\n", stats
);
2041 #ifndef TCP_ENHANCEMENTS
2043 PRINT_ER("Discard sending packet with len = %d\n", size
);
2047 void WILC_WFI_mgmt_rx(u8
*buff
, u32 size
)
2050 perInterface_wlan_t
*nic
;
2053 /*Pass the frame on the monitor interface, if any.*/
2054 /*Otherwise, pass it on p2p0 netdev, if registered on it*/
2055 for (i
= 0; i
< g_linux_wlan
->u8NoIfcs
; i
++) {
2056 nic
= netdev_priv(g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
);
2057 if (nic
->monitor_flag
) {
2058 WILC_WFI_monitor_rx(buff
, size
);
2064 nic
= netdev_priv(g_linux_wlan
->strInterfaceInfo
[1].wilc_netdev
); /* p2p0 */
2065 if ((buff
[0] == nic
->g_struct_frame_reg
[0].frame_type
&& nic
->g_struct_frame_reg
[0].reg
) ||
2066 (buff
[0] == nic
->g_struct_frame_reg
[1].frame_type
&& nic
->g_struct_frame_reg
[1].reg
))
2067 WILC_WFI_p2p_rx(g_linux_wlan
->strInterfaceInfo
[1].wilc_netdev
, buff
, size
);
2071 int wilc_netdev_init(void)
2075 perInterface_wlan_t
*nic
;
2076 struct net_device
*ndev
;
2078 sema_init(&close_exit_sync
, 0);
2080 /*create the common structure*/
2081 g_linux_wlan
= kzalloc(sizeof(linux_wlan_t
), GFP_KERNEL
);
2085 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
2086 register_inetaddr_notifier(&g_dev_notifier
);
2089 for (i
= 0; i
< NUM_CONCURRENT_IFC
; i
++) {
2090 /*allocate first ethernet device with perinterface_wlan_t as its private data*/
2091 ndev
= alloc_etherdev(sizeof(perInterface_wlan_t
));
2093 PRINT_ER("Failed to allocate ethernet dev\n");
2097 nic
= netdev_priv(ndev
);
2098 memset(nic
, 0, sizeof(perInterface_wlan_t
));
2100 /*Name the Devices*/
2102 #if defined(NM73131) /* tony, 2012-09-20 */
2103 strcpy(ndev
->name
, "wilc_eth%d");
2104 #elif defined(PLAT_CLM9722) /* rachel */
2105 strcpy(ndev
->name
, "eth%d");
2106 #else /* PANDA_BOARD, PLAT_ALLWINNER_A10, PLAT_ALLWINNER_A20, PLAT_ALLWINNER_A31, PLAT_AML8726_M3 or PLAT_WMS8304 */
2107 strcpy(ndev
->name
, "wlan%d");
2110 strcpy(ndev
->name
, "p2p%d");
2112 nic
->u8IfIdx
= g_linux_wlan
->u8NoIfcs
;
2113 nic
->wilc_netdev
= ndev
;
2114 g_linux_wlan
->strInterfaceInfo
[g_linux_wlan
->u8NoIfcs
].wilc_netdev
= ndev
;
2115 g_linux_wlan
->u8NoIfcs
++;
2116 ndev
->netdev_ops
= &wilc_netdev_ops
;
2119 struct wireless_dev
*wdev
;
2121 wdev
= WILC_WFI_WiphyRegister(ndev
);
2124 /* set netdev, tony */
2125 SET_NETDEV_DEV(ndev
, &local_sdio_func
->dev
);
2129 PRINT_ER("Can't register WILC Wiphy\n");
2133 /*linking the wireless_dev structure with the netdevice*/
2134 nic
->wilc_netdev
->ieee80211_ptr
= wdev
;
2135 nic
->wilc_netdev
->ml_priv
= nic
;
2136 wdev
->netdev
= nic
->wilc_netdev
;
2137 nic
->netstats
.rx_packets
= 0;
2138 nic
->netstats
.tx_packets
= 0;
2139 nic
->netstats
.rx_bytes
= 0;
2140 nic
->netstats
.tx_bytes
= 0;
2144 if (register_netdev(ndev
)) {
2145 PRINT_ER("Device couldn't be registered - %s\n", ndev
->name
);
2146 return -1; /* ERROR */
2149 nic
->iftype
= STATION_MODE
;
2150 nic
->mac_opened
= 0;
2155 if (!linux_spi_init(&g_linux_wlan
->wilc_spidev
)) {
2156 PRINT_ER("Can't initialize SPI\n");
2157 return -1; /* ERROR */
2159 g_linux_wlan
->wilc_spidev
= wilc_spi_dev
;
2161 g_linux_wlan
->wilc_sdio_func
= local_sdio_func
;
2167 /*The 1st function called after module inserted*/
2168 static int __init
init_wilc_driver(void)
2170 #if defined(WILC_DEBUGFS)
2171 if (wilc_debugfs_init() < 0) {
2172 PRINT_D(GENERIC_DBG
, "fail to create debugfs for wilc driver\n");
2177 printk("IN INIT FUNCTION\n");
2178 printk("*** WILC1000 driver VERSION=[10.2] FW_VER=[10.2] ***\n");
2180 linux_wlan_device_power(1);
2182 linux_wlan_device_detection(1);
2188 ret
= sdio_register_driver(&wilc_bus
);
2190 PRINT_D(INIT_DBG
, "init_wilc_driver: Failed register sdio driver\n");
2195 PRINT_D(INIT_DBG
, "Initializing netdev\n");
2196 if (wilc_netdev_init())
2197 PRINT_ER("Couldn't initialize netdev\n");
2201 late_initcall(init_wilc_driver
);
2203 static void __exit
exit_wilc_driver(void)
2206 perInterface_wlan_t
*nic
[NUM_CONCURRENT_IFC
] = {NULL
,};
2207 #define CLOSE_TIMEOUT (12 * 1000)
2209 if ((g_linux_wlan
!= NULL
) && (((g_linux_wlan
->strInterfaceInfo
[0].wilc_netdev
) != NULL
)
2210 || ((g_linux_wlan
->strInterfaceInfo
[1].wilc_netdev
) != NULL
))) {
2211 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
2212 unregister_inetaddr_notifier(&g_dev_notifier
);
2215 for (i
= 0; i
< NUM_CONCURRENT_IFC
; i
++)
2216 nic
[i
] = netdev_priv(g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
);
2219 if ((g_linux_wlan
!= NULL
) && g_linux_wlan
->wilc_firmware
!= NULL
) {
2220 release_firmware(g_linux_wlan
->wilc_firmware
);
2221 g_linux_wlan
->wilc_firmware
= NULL
;
2224 if ((g_linux_wlan
!= NULL
) && (((g_linux_wlan
->strInterfaceInfo
[0].wilc_netdev
) != NULL
)
2225 || ((g_linux_wlan
->strInterfaceInfo
[1].wilc_netdev
) != NULL
))) {
2226 PRINT_D(INIT_DBG
, "Waiting for mac_close ....\n");
2228 if (linux_wlan_lock_timeout(&close_exit_sync
, CLOSE_TIMEOUT
) < 0)
2229 PRINT_D(INIT_DBG
, "Closed TimedOUT\n");
2231 PRINT_D(INIT_DBG
, "mac_closed\n");
2233 for (i
= 0; i
< NUM_CONCURRENT_IFC
; i
++) {
2234 /* close all opened interfaces */
2235 if (g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
!= NULL
) {
2236 if (nic
[i
]->mac_opened
)
2237 mac_close(g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
);
2240 for (i
= 0; i
< NUM_CONCURRENT_IFC
; i
++) {
2241 PRINT_D(INIT_DBG
, "Unregistering netdev %p\n", g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
);
2242 unregister_netdev(g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
);
2243 PRINT_D(INIT_DBG
, "Freeing Wiphy...\n");
2244 WILC_WFI_WiphyFree(g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
);
2245 PRINT_D(INIT_DBG
, "Freeing netdev...\n");
2246 free_netdev(g_linux_wlan
->strInterfaceInfo
[i
].wilc_netdev
);
2250 #ifdef WILC_AP_EXTERNAL_MLME
2251 /* Bug 4600 : WILC_WFI_deinit_mon_interface was already called at mac_close */
2252 /* WILC_WFI_deinit_mon_interface(); */
2255 /* if(g_linux_wlan->open_ifcs==0) */
2258 PRINT_D(INIT_DBG
, "SPI unregsiter...\n");
2259 spi_unregister_driver(&wilc_bus
);
2261 PRINT_D(INIT_DBG
, "SDIO unregsiter...\n");
2262 sdio_unregister_driver(&wilc_bus
);
2265 if (g_linux_wlan
!= NULL
) {
2266 kfree(g_linux_wlan
);
2267 g_linux_wlan
= NULL
;
2269 printk("Module_exit Done.\n");
2271 #if defined(WILC_DEBUGFS)
2272 wilc_debugfs_remove();
2275 linux_wlan_device_detection(0);
2276 linux_wlan_device_power(0);
2279 module_exit(exit_wilc_driver
);
2281 MODULE_LICENSE("GPL");