]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/staging/wilc1000/linux_wlan.c
staging: fbtft: fix build error
[mirror_ubuntu-artful-kernel.git] / drivers / staging / wilc1000 / linux_wlan.c
CommitLineData
c5c77ba1
JK
1#ifndef SIMULATION
2#include "wilc_wfi_cfgoperations.h"
3#include "linux_wlan_common.h"
4#include "wilc_wlan_if.h"
5#include "wilc_wlan.h"
6#ifdef USE_WIRELESS
7#include "wilc_wfi_cfgoperations.h"
8#endif
9
10#include "linux_wlan_common.h"
11
12#include <linux/slab.h>
13#include <linux/sched.h>
14#include <linux/delay.h>
15#include <linux/workqueue.h>
16#include <linux/interrupt.h>
17#include <linux/irq.h>
f1a99830 18#include <linux/gpio.h>
c5c77ba1
JK
19
20#include <linux/kthread.h>
21#include <linux/firmware.h>
22#include <linux/delay.h>
23
24#include <linux/init.h>
25#include <linux/netdevice.h>
26#ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
27#include <linux/inetdevice.h>
28#endif
29#include <linux/etherdevice.h>
30#include <linux/module.h>
31#include <linux/kernel.h>
32#include <linux/skbuff.h>
33
34#include <linux/version.h>
35#include <linux/semaphore.h>
36
37#ifdef WILC_SDIO
38#include "linux_wlan_sdio.h"
39#else
40#include "linux_wlan_spi.h"
41#endif
42
43#ifdef WILC_FULLY_HOSTING_AP
44#include "wilc_host_ap.h"
45#endif
46
47#ifdef STATIC_MACADDRESS /* brandy_0724 [[ */
48#include <linux/vmalloc.h>
49#include <linux/fs.h>
50struct task_struct *wilc_mac_thread;
51unsigned char mac_add[] = {0x00, 0x80, 0xC2, 0x5E, 0xa2, 0xb2};
52#endif /* brandy_0724 ]] */
53
54#if defined(CUSTOMER_PLATFORM)
55/*
56 TODO : Write power control functions as customer platform.
57 */
58#else
59
60 #define _linux_wlan_device_power_on() {}
61 #define _linux_wlan_device_power_off() {}
62
63 #define _linux_wlan_device_detection() {}
64 #define _linux_wlan_device_removal() {}
65#endif
66
67#ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
68extern WILC_Bool g_obtainingIP;
69#endif
70extern WILC_Uint16 Set_machw_change_vir_if(WILC_Bool bValue);
71extern void resolve_disconnect_aberration(void *drvHandler);
63d03e47 72extern u8 gau8MulticastMacAddrList[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN];
c5c77ba1
JK
73void wilc1000_wlan_deinit(linux_wlan_t *nic);
74#ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
75extern WILC_TimerHandle hDuringIpTimer;
76#endif
77
78static int linux_wlan_device_power(int on_off)
79{
80 PRINT_D(INIT_DBG, "linux_wlan_device_power.. (%d)\n", on_off);
81
82 if (on_off) {
83 _linux_wlan_device_power_on();
84 } else {
85 _linux_wlan_device_power_off();
86 }
87
88 return 0;
89}
90
91static int linux_wlan_device_detection(int on_off)
92{
93 PRINT_D(INIT_DBG, "linux_wlan_device_detection.. (%d)\n", on_off);
94
95#ifdef WILC_SDIO
96 if (on_off) {
97 _linux_wlan_device_detection();
98 } else {
99 _linux_wlan_device_removal();
100 }
101#endif
102
103 return 0;
104}
105
106
107#ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
108static int dev_state_ev_handler(struct notifier_block *this, unsigned long event, void *ptr);
109
110static struct notifier_block g_dev_notifier = {
111 .notifier_call = dev_state_ev_handler
112};
113#endif
114
115#define wilc_wlan_deinit(nic) { if (&g_linux_wlan->oup != NULL) \
116 if (g_linux_wlan->oup.wlan_cleanup != NULL) \
117 g_linux_wlan->oup.wlan_cleanup(); }
118
119
120#ifndef STA_FIRMWARE
121#define STA_FIRMWARE "wifi_firmware.bin"
122#endif
123
124#ifndef AP_FIRMWARE
125#define AP_FIRMWARE "wifi_firmware_ap.bin"
126#endif
127
128#ifndef P2P_CONCURRENCY_FIRMWARE
129#define P2P_CONCURRENCY_FIRMWARE "wifi_firmware_p2p_concurrency.bin"
130#endif
131
132
133
134typedef struct android_wifi_priv_cmd {
135 char *buf;
136 int used_len;
137 int total_len;
138} android_wifi_priv_cmd;
139
140
141#define IRQ_WAIT 1
142#define IRQ_NO_WAIT 0
143/*
144 * to sync between mac_close and module exit.
145 * don't initialize or de-initialize from init/deinitlocks
146 * to be initialized from module wilc_netdev_init and
147 * deinitialized from mdoule_exit
148 */
149static struct semaphore close_exit_sync;
150unsigned int int_rcvdU;
151unsigned int int_rcvdB;
152unsigned int int_clrd;
153
154static int wlan_deinit_locks(linux_wlan_t *nic);
155static void wlan_deinitialize_threads(linux_wlan_t *nic);
156static void linux_wlan_lock(void *vp);
157void linux_wlan_unlock(void *vp);
158extern void WILC_WFI_monitor_rx(uint8_t *buff, uint32_t size);
159extern void WILC_WFI_p2p_rx(struct net_device *dev, uint8_t *buff, uint32_t size);
160
161
162static void *internal_alloc(uint32_t size, uint32_t flag);
163static void linux_wlan_tx_complete(void *priv, int status);
164void frmw_to_linux(uint8_t *buff, uint32_t size, uint32_t pkt_offset);
165static int mac_init_fn(struct net_device *ndev);
166int mac_xmit(struct sk_buff *skb, struct net_device *dev);
167int mac_open(struct net_device *ndev);
168int mac_close(struct net_device *ndev);
169static struct net_device_stats *mac_stats(struct net_device *dev);
170static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd);
171static void wilc_set_multicast_list(struct net_device *dev);
172
173
174
175/*
176 * for now - in frmw_to_linux there should be private data to be passed to it
177 * and this data should be pointer to net device
178 */
179linux_wlan_t *g_linux_wlan;
180wilc_wlan_oup_t *gpstrWlanOps;
181WILC_Bool bEnablePS = WILC_TRUE;
182
c5c77ba1
JK
183static const struct net_device_ops wilc_netdev_ops = {
184 .ndo_init = mac_init_fn,
185 .ndo_open = mac_open,
186 .ndo_stop = mac_close,
187 .ndo_start_xmit = mac_xmit,
188 .ndo_do_ioctl = mac_ioctl,
189 .ndo_get_stats = mac_stats,
190 .ndo_set_rx_mode = wilc_set_multicast_list,
191
192};
c5c77ba1 193
c5c77ba1
JK
194#ifdef DEBUG_MODE
195
196extern volatile int timeNo;
197
198#define DEGUG_BUFFER_LENGTH 1000
199volatile int WatchDogdebuggerCounter;
200char DebugBuffer[DEGUG_BUFFER_LENGTH + 20] = {0};
201static char *ps8current = DebugBuffer;
202
203
204
205void printk_later(const char *format, ...)
206{
207 va_list args;
208 va_start (args, format);
209 ps8current += vsprintf (ps8current, format, args);
210 va_end (args);
211 if ((ps8current - DebugBuffer) > DEGUG_BUFFER_LENGTH) {
212 ps8current = DebugBuffer;
213 }
214
215}
216
217
218void dump_logs()
219{
220 if (DebugBuffer[0]) {
221 DebugBuffer[DEGUG_BUFFER_LENGTH] = 0;
222 PRINT_INFO(GENERIC_DBG, "early printed\n");
223 PRINT_D(GENERIC_DBG, ps8current + 1);
224 ps8current[1] = 0;
225 PRINT_INFO(GENERIC_DBG, "latest printed\n");
226 PRINT_D(GENERIC_DBG, DebugBuffer);
227 DebugBuffer[0] = 0;
228 ps8current = DebugBuffer;
229 }
230}
231
232void Reset_WatchDogdebugger()
233{
234 WatchDogdebuggerCounter = 0;
235}
236
237static int DebuggingThreadTask(void *vp)
238{
239 while (1) {
240 while (!WatchDogdebuggerCounter) {
241 PRINT_D(GENERIC_DBG, "Debug Thread Running %d\n", timeNo);
242 WatchDogdebuggerCounter = 1;
243 msleep(10000);
244 }
245 dump_logs();
246 WatchDogdebuggerCounter = 0;
247 }
248}
249
250
251#endif
252
253
254#ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
255static int dev_state_ev_handler(struct notifier_block *this, unsigned long event, void *ptr)
256{
257 struct in_ifaddr *dev_iface = (struct in_ifaddr *)ptr;
258 struct WILC_WFI_priv *priv;
259 tstrWILC_WFIDrv *pstrWFIDrv;
260 struct net_device *dev;
63d03e47 261 u8 *pIP_Add_buff;
c5c77ba1
JK
262 WILC_Sint32 s32status = WILC_FAIL;
263 perInterface_wlan_t *nic;
63d03e47 264 u8 null_ip[4] = {0};
c5c77ba1
JK
265 char wlan_dev_name[5] = "wlan0";
266
267 if (dev_iface == NULL || dev_iface->ifa_dev == NULL || dev_iface->ifa_dev->dev == NULL) {
268 PRINT_D(GENERIC_DBG, "dev_iface = NULL\n");
269 return NOTIFY_DONE;
270 }
271
272 if ((memcmp(dev_iface->ifa_label, "wlan0", 5)) && (memcmp(dev_iface->ifa_label, "p2p0", 4))) {
273 PRINT_D(GENERIC_DBG, "Interface is neither WLAN0 nor P2P0\n");
274 return NOTIFY_DONE;
275 }
276
277 dev = (struct net_device *)dev_iface->ifa_dev->dev;
278 if (dev->ieee80211_ptr == NULL || dev->ieee80211_ptr->wiphy == NULL) {
279 PRINT_D(GENERIC_DBG, "No Wireless registerd\n");
280 return NOTIFY_DONE;
281 }
282 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
283 if (priv == NULL) {
284 PRINT_D(GENERIC_DBG, "No Wireless Priv\n");
285 return NOTIFY_DONE;
286 }
287 pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
288 nic = netdev_priv(dev);
289 if (nic == NULL || pstrWFIDrv == NULL) {
290 PRINT_D(GENERIC_DBG, "No Wireless Priv\n");
291 return NOTIFY_DONE;
292 }
293
294 PRINT_INFO(GENERIC_DBG, "dev_state_ev_handler +++\n"); /* tony */
295
296 switch (event) {
297 case NETDEV_UP:
298 PRINT_D(GENERIC_DBG, "dev_state_ev_handler event=NETDEV_UP %p\n", dev); /* tony */
299
300 PRINT_INFO(GENERIC_DBG, "\n ============== IP Address Obtained ===============\n\n");
301
302
303 /*If we are in station mode or client mode*/
304 if (nic->iftype == STATION_MODE || nic->iftype == CLIENT_MODE) {
305 pstrWFIDrv->IFC_UP = 1;
306 g_obtainingIP = WILC_FALSE;
b1413b60 307 WILC_TimerStop(&hDuringIpTimer, NULL);
c5c77ba1
JK
308 PRINT_D(GENERIC_DBG, "IP obtained , enable scan\n");
309 }
310
311
312
313 if (bEnablePS == WILC_TRUE)
314 host_int_set_power_mgmt((WILC_WFIDrvHandle)pstrWFIDrv, 1, 0);
315
316 PRINT_D(GENERIC_DBG, "[%s] Up IP\n", dev_iface->ifa_label);
317
318 pIP_Add_buff = (char *) (&(dev_iface->ifa_address));
319 PRINT_D(GENERIC_DBG, "IP add=%d:%d:%d:%d \n", pIP_Add_buff[0], pIP_Add_buff[1], pIP_Add_buff[2], pIP_Add_buff[3]);
320 s32status = host_int_setup_ipaddress((WILC_WFIDrvHandle)pstrWFIDrv, pIP_Add_buff, nic->u8IfIdx);
321
322 break;
323
324 case NETDEV_DOWN:
325 PRINT_D(GENERIC_DBG, "dev_state_ev_handler event=NETDEV_DOWN %p\n", dev); /* tony */
326
327 PRINT_INFO(GENERIC_DBG, "\n ============== IP Address Released ===============\n\n");
328 if (nic->iftype == STATION_MODE || nic->iftype == CLIENT_MODE) {
329 pstrWFIDrv->IFC_UP = 0;
330 g_obtainingIP = WILC_FALSE;
331 }
332
333 if (memcmp(dev_iface->ifa_label, wlan_dev_name, 5) == 0)
334 host_int_set_power_mgmt((WILC_WFIDrvHandle)pstrWFIDrv, 0, 0);
335
336 resolve_disconnect_aberration(pstrWFIDrv);
337
338
339 PRINT_D(GENERIC_DBG, "[%s] Down IP\n", dev_iface->ifa_label);
340
341 pIP_Add_buff = null_ip;
342 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]);
343
344 s32status = host_int_setup_ipaddress((WILC_WFIDrvHandle)pstrWFIDrv, pIP_Add_buff, nic->u8IfIdx);
345
346 break;
347
348 default:
349 PRINT_INFO(GENERIC_DBG, "dev_state_ev_handler event=default\n"); /* tony */
350 PRINT_INFO(GENERIC_DBG, "[%s] unknown dev event: %lu\n", dev_iface->ifa_label, event);
351
352 break;
353 }
354
355 return NOTIFY_DONE;
356
357}
358#endif
359
360/*
361 * Interrupt initialization and handling functions
362 */
363
364void linux_wlan_enable_irq(void)
365{
366
367#if (RX_BH_TYPE != RX_BH_THREADED_IRQ)
368#if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
369 PRINT_D(INT_DBG, "Enabling IRQ ...\n");
370 enable_irq(g_linux_wlan->dev_irq_num);
371#endif
372#endif
373}
374
375void linux_wlan_disable_irq(int wait)
376{
377#if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
378 if (wait) {
379 PRINT_D(INT_DBG, "Disabling IRQ ...\n");
380 disable_irq(g_linux_wlan->dev_irq_num);
381 } else {
382 PRINT_D(INT_DBG, "Disabling IRQ ...\n");
383 disable_irq_nosync(g_linux_wlan->dev_irq_num);
384 }
385#endif
386}
387
388#if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
389static irqreturn_t isr_uh_routine(int irq, void *user_data)
390{
391
392
393 int_rcvdU++;
394#if (RX_BH_TYPE != RX_BH_THREADED_IRQ)
395 linux_wlan_disable_irq(IRQ_NO_WAIT);
396#endif
397 PRINT_D(INT_DBG, "Interrupt received UH\n");
398
399 /*While mac is closing cacncel the handling of any interrupts received*/
400 if (g_linux_wlan->close) {
401 PRINT_ER("Driver is CLOSING: Can't handle UH interrupt\n");
402 #if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
403 return IRQ_HANDLED;
404 #else
405 return IRQ_NONE;
406 #endif
407
408 }
409#if (RX_BH_TYPE == RX_BH_WORK_QUEUE)
410 schedule_work(&g_linux_wlan->rx_work_queue);
411 return IRQ_HANDLED;
412#elif (RX_BH_TYPE == RX_BH_KTHREAD)
413 linux_wlan_unlock(&g_linux_wlan->rx_sem);
414 return IRQ_HANDLED;
415#elif (RX_BH_TYPE == RX_BH_THREADED_IRQ)
416 return IRQ_WAKE_THREAD;
417#endif
418
419}
420#endif
421
422#if (RX_BH_TYPE == RX_BH_WORK_QUEUE || RX_BH_TYPE == RX_BH_THREADED_IRQ)
423
424#if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
425irqreturn_t isr_bh_routine(int irq, void *userdata)
426{
427 linux_wlan_t *nic;
428 nic = (linux_wlan_t *)userdata;
429#else
430static void isr_bh_routine(struct work_struct *work)
431{
432 perInterface_wlan_t *nic;
433 nic = (perInterface_wlan_t *)container_of(work, linux_wlan_t, rx_work_queue);
434#endif
435
436 /*While mac is closing cacncel the handling of any interrupts received*/
437 if (g_linux_wlan->close) {
438 PRINT_ER("Driver is CLOSING: Can't handle BH interrupt\n");
439 #if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
440 return IRQ_HANDLED;
441 #else
442 return;
443 #endif
444
445
446
447 }
448
449 int_rcvdB++;
450 PRINT_D(INT_DBG, "Interrupt received BH\n");
451 if (g_linux_wlan->oup.wlan_handle_rx_isr != 0) {
452 g_linux_wlan->oup.wlan_handle_rx_isr();
453 } else {
454 PRINT_ER("wlan_handle_rx_isr() hasn't been initialized\n");
455 }
456
457
458#if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
459 return IRQ_HANDLED;
460#endif
461}
462#elif (RX_BH_TYPE == RX_BH_KTHREAD)
463static int isr_bh_routine(void *vp)
464{
465 linux_wlan_t *nic;
466
467 nic = (linux_wlan_t *)vp;
468
469 while (1) {
470 linux_wlan_lock(&nic->rx_sem);
471 if (g_linux_wlan->close) {
472
473 while (!kthread_should_stop())
474 schedule();
475
476 break;
477 }
478 int_rcvdB++;
479 PRINT_D(INT_DBG, "Interrupt received BH\n");
480 if (g_linux_wlan->oup.wlan_handle_rx_isr != 0) {
481 g_linux_wlan->oup.wlan_handle_rx_isr();
482 } else {
483 PRINT_ER("wlan_handle_rx_isr() hasn't been initialized\n");
484 }
485 }
486
487 return 0;
488}
489#endif
490
491
492#if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
493static int init_irq(linux_wlan_t *p_nic)
494{
495 int ret = 0;
496 linux_wlan_t *nic = p_nic;
497
498 /*initialize GPIO and register IRQ num*/
499 /*GPIO request*/
500 if ((gpio_request(GPIO_NUM, "WILC_INTR") == 0) &&
501 (gpio_direction_input(GPIO_NUM) == 0)) {
502#if defined(CUSTOMER_PLATFORM)
503/*
504 TODO : save the registerd irq number to the private wilc context in kernel.
505 *
506 * ex) nic->dev_irq_num = gpio_to_irq(GPIO_NUM);
507 */
508#elif defined (NM73131_0_BOARD)
509 nic->dev_irq_num = IRQ_WILC1000;
510#elif defined (PANDA_BOARD)
511 gpio_export(GPIO_NUM, 1);
512 nic->dev_irq_num = OMAP_GPIO_IRQ(GPIO_NUM);
513 irq_set_irq_type(nic->dev_irq_num, IRQ_TYPE_LEVEL_LOW);
514#else
515 nic->dev_irq_num = gpio_to_irq(GPIO_NUM);
516#endif
517 } else {
518 ret = -1;
519 PRINT_ER("could not obtain gpio for WILC_INTR\n");
520 }
521
522
523#if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
524 if ((ret != -1) && (request_threaded_irq(nic->dev_irq_num, isr_uh_routine, isr_bh_routine,
525 IRQF_TRIGGER_LOW | IRQF_ONESHOT, /*Without IRQF_ONESHOT the uh will remain kicked in and dont gave a chance to bh*/
526 "WILC_IRQ", nic)) < 0) {
527
528#else
529 /*Request IRQ*/
530 if ((ret != -1) && (request_irq(nic->dev_irq_num, isr_uh_routine,
531 IRQF_TRIGGER_LOW, "WILC_IRQ", nic) < 0)) {
532
533#endif
534 PRINT_ER("Failed to request IRQ for GPIO: %d\n", GPIO_NUM);
535 ret = -1;
536 } else {
537
538 PRINT_D(INIT_DBG, "IRQ request succeeded IRQ-NUM= %d on GPIO: %d\n",
539 nic->dev_irq_num, GPIO_NUM);
540 }
541
542 return ret;
543}
544#endif
545
546static void deinit_irq(linux_wlan_t *nic)
547{
548#if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
549 /* Deintialize IRQ */
550 if (&nic->dev_irq_num != 0) {
551 free_irq(nic->dev_irq_num, g_linux_wlan);
552
553 gpio_free(GPIO_NUM);
554 }
555#endif
556}
557
558
559/*
560 * OS functions
561 */
562static void linux_wlan_msleep(uint32_t msc)
563{
564 if (msc <= 4000000) {
565 WILC_Uint32 u32Temp = msc * 1000;
c5c77ba1 566 usleep_range(u32Temp, u32Temp);
c5c77ba1
JK
567 } else {
568 msleep(msc);
569 }
570}
571
572static void linux_wlan_atomic_msleep(uint32_t msc)
573{
574 mdelay(msc);
575}
576static void linux_wlan_dbg(uint8_t *buff)
577{
578 PRINT_D(INIT_DBG, "%d\n", *buff);
579}
580
581static void *linux_wlan_malloc_atomic(uint32_t sz)
582{
583 char *pntr = NULL;
584 pntr = (char *)kmalloc(sz, GFP_ATOMIC);
585 PRINT_D(MEM_DBG, "Allocating %d bytes at address %p\n", sz, pntr);
586 return (void *)pntr;
587
588}
589static void *linux_wlan_malloc(uint32_t sz)
590{
591 char *pntr = NULL;
592 pntr = (char *)kmalloc(sz, GFP_KERNEL);
593 PRINT_D(MEM_DBG, "Allocating %d bytes at address %p\n", sz, pntr);
594 return (void *)pntr;
595}
596
597void linux_wlan_free(void *vp)
598{
599 if (vp != NULL) {
600 PRINT_D(MEM_DBG, "Freeing %p\n", vp);
601 kfree(vp);
602 }
603}
604
605
606static void *internal_alloc(uint32_t size, uint32_t flag)
607{
608 char *pntr = NULL;
609 pntr = (char *)kmalloc(size, flag);
610 PRINT_D(MEM_DBG, "Allocating %d bytes at address %p\n", size, pntr);
611 return (void *)pntr;
612}
613
614
615static void linux_wlan_init_lock(char *lockName, void *plock, int count)
616{
617 sema_init((struct semaphore *)plock, count);
618 PRINT_D(LOCK_DBG, "Initializing [%s][%p]\n", lockName, plock);
619
620}
621
622static void linux_wlan_deinit_lock(void *plock)
623{
624 /* mutex_destroy((struct mutex*)plock); */
625}
626
627static void linux_wlan_lock(void *vp)
628{
629 PRINT_D(LOCK_DBG, "Locking %p\n", vp);
630 if (vp != NULL) {
631 while (down_interruptible((struct semaphore *) vp))
632 ;
633 } else {
634 PRINT_ER("Failed, mutex is NULL\n");
635 }
636}
637
638static int linux_wlan_lock_timeout(void *vp, WILC_Uint32 timeout)
639{
640 int error = -1;
641 PRINT_D(LOCK_DBG, "Locking %p\n", vp);
642 if (vp != NULL) {
643 error = down_timeout((struct semaphore *)vp, msecs_to_jiffies(timeout));
644 } else {
645 PRINT_ER("Failed, mutex is NULL\n");
646 }
647 return error;
648}
649
650void linux_wlan_unlock(void *vp)
651{
652 PRINT_D(LOCK_DBG, "Unlocking %p\n", vp);
653 if (vp != NULL) {
654 up((struct semaphore *)vp);
655 } else {
656 PRINT_ER("Failed, mutex is NULL\n");
657 }
658}
659
660
661static void linux_wlan_init_mutex(char *lockName, void *plock, int count)
662{
663 mutex_init((struct mutex *)plock);
664 PRINT_D(LOCK_DBG, "Initializing mutex [%s][%p]\n", lockName, plock);
665
666}
667
668static void linux_wlan_deinit_mutex(void *plock)
669{
670 mutex_destroy((struct mutex *)plock);
671}
672
673static void linux_wlan_lock_mutex(void *vp)
674{
675 PRINT_D(LOCK_DBG, "Locking mutex %p\n", vp);
676 if (vp != NULL) {
677 /*
678 * if(mutex_is_locked((struct mutex*)vp))
679 * {
680 * //PRINT_ER("Mutex already locked - %p \n",vp);
681 * }
682 */
683 mutex_lock((struct mutex *)vp);
684
685 } else {
686 PRINT_ER("Failed, mutex is NULL\n");
687 }
688}
689
690static void linux_wlan_unlock_mutex(void *vp)
691{
692 PRINT_D(LOCK_DBG, "Unlocking mutex %p\n", vp);
693 if (vp != NULL) {
694
695 if (mutex_is_locked((struct mutex *)vp)) {
696 mutex_unlock((struct mutex *)vp);
697 } else {
698 /* PRINT_ER("Mutex already unlocked - %p\n",vp); */
699 }
700
701 } else {
702 PRINT_ER("Failed, mutex is NULL\n");
703 }
704}
705
706
707/*Added by Amr - BugID_4720*/
708static void linux_wlan_init_spin_lock(char *lockName, void *plock, int count)
709{
710 spin_lock_init((spinlock_t *)plock);
711 PRINT_D(SPIN_DEBUG, "Initializing mutex [%s][%p]\n", lockName, plock);
712
713}
714
715static void linux_wlan_deinit_spin_lock(void *plock)
716{
717
718}
719static void linux_wlan_spin_lock(void *vp, unsigned long *flags)
720{
721 unsigned long lflags;
722 PRINT_D(SPIN_DEBUG, "Lock spin %p\n", vp);
723 if (vp != NULL) {
724 spin_lock_irqsave((spinlock_t *)vp, lflags);
725 *flags = lflags;
726 } else {
727 PRINT_ER("Failed, spin lock is NULL\n");
728 }
729}
730static void linux_wlan_spin_unlock(void *vp, unsigned long *flags)
731{
732 unsigned long lflags = *flags;
733 PRINT_D(SPIN_DEBUG, "Unlock spin %p\n", vp);
734 if (vp != NULL) {
735 spin_unlock_irqrestore((spinlock_t *)vp, lflags);
736 *flags = lflags;
737 } else {
738 PRINT_ER("Failed, spin lock is NULL\n");
739 }
740}
741
742static void linux_wlan_mac_indicate(int flag)
743{
744 /*I have to do it that way becuase there is no mean to encapsulate device pointer
745 * as a parameter
746 */
747 linux_wlan_t *pd = g_linux_wlan;
748 int status;
749
750 if (flag == WILC_MAC_INDICATE_STATUS) {
751 pd->oup.wlan_cfg_get_value(WID_STATUS, (unsigned char *)&status, 4);
752 if (pd->mac_status == WILC_MAC_STATUS_INIT) {
753 pd->mac_status = status;
754 linux_wlan_unlock(&pd->sync_event);
755 } else {
756 pd->mac_status = status;
757 }
758
759 if (pd->mac_status == WILC_MAC_STATUS_CONNECT) { /* Connect */
760#if 0
761 /**
762 * get the mac and bssid address
763 **/
764 PRINT_D(RX_DBG, "Calling cfg_get to get MAC_ADDR\n");
765 pd->oup.wlan_cfg_get(1, WID_MAC_ADDR, 0);
766 PRINT_D(RX_DBG, "Calling cfg_get to get BSSID\n");
767 pd->oup.wlan_cfg_get(0, WID_BSSID, 1);
768
769 /**
770 * get the value
771 **/
772 pd->oup.wlan_cfg_get_value(WID_MAC_ADDR, pd->eth_src_address, 6);
773 pd->oup.wlan_cfg_get_value(WID_BSSID, pd->eth_dst_address, 6);
774
775 PRINT_D(GENERIC_DBG, "Source Address = %s", pd->eth_src_address);
776 PRINT_D(GENERIC_DBG, "Destiation Address = %s", pd->eth_dst_address);
777
778 /**
779 * launch ndis
780 **/
781#endif
782 }
783
784 } else if (flag == WILC_MAC_INDICATE_SCAN) {
785 PRINT_D(GENERIC_DBG, "Scanning ...\n");
786
787 }
788
789}
790
791struct net_device *GetIfHandler(uint8_t *pMacHeader)
792{
793 uint8_t *Bssid, *Bssid1;
794 int i = 0;
795
796 Bssid = pMacHeader + 10;
797 Bssid1 = pMacHeader + 4;
798
799 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
800 if (!memcmp(Bssid1, g_linux_wlan->strInterfaceInfo[i].aBSSID, ETH_ALEN) ||
801 !memcmp(Bssid, g_linux_wlan->strInterfaceInfo[i].aBSSID, ETH_ALEN)) {
802 return g_linux_wlan->strInterfaceInfo[i].wilc_netdev;
803 }
804 }
805 PRINT_INFO(INIT_DBG, "Invalide handle\n");
806 for (i = 0; i < 25; i++) {
807 PRINT_D(INIT_DBG, "%02x ", pMacHeader[i]);
808 }
809 Bssid = pMacHeader + 18;
810 Bssid1 = pMacHeader + 12;
811 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
812 if (!memcmp(Bssid1, g_linux_wlan->strInterfaceInfo[i].aBSSID, ETH_ALEN) ||
813 !memcmp(Bssid, g_linux_wlan->strInterfaceInfo[i].aBSSID, ETH_ALEN)) {
814 PRINT_D(INIT_DBG, "Ctx [%p]\n", g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
815 return g_linux_wlan->strInterfaceInfo[i].wilc_netdev;
816 }
817 }
818 PRINT_INFO(INIT_DBG, "\n");
819 return NULL;
820}
821
822int linux_wlan_set_bssid(struct net_device *wilc_netdev, uint8_t *pBSSID)
823{
824 int i = 0;
825 int ret = -1;
826
827 PRINT_D(INIT_DBG, "set bssid on[%p]\n", wilc_netdev);
828 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
829 if (g_linux_wlan->strInterfaceInfo[i].wilc_netdev == wilc_netdev) {
830 PRINT_D(INIT_DBG, "set bssid [%x][%x][%x]\n", pBSSID[0], pBSSID[1], pBSSID[2]);
831 memcpy(g_linux_wlan->strInterfaceInfo[i].aBSSID, pBSSID, 6);
832 ret = 0;
833 break;
834 }
835 }
836 return ret;
837}
838
839/*BugID_5213*/
840/*Function to get number of connected interfaces*/
841int linux_wlan_get_num_conn_ifcs(void)
842{
843 uint8_t i = 0;
844 uint8_t null_bssid[6] = {0};
845 uint8_t ret_val = 0;
846
847 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
848 if (memcmp(g_linux_wlan->strInterfaceInfo[i].aBSSID, null_bssid, 6)) {
849 ret_val++;
850 }
851 }
852 return ret_val;
853}
854
855static int linux_wlan_rxq_task(void *vp)
856{
857
858 /* inform wilc1000_wlan_init that RXQ task is started. */
859 linux_wlan_unlock(&g_linux_wlan->rxq_thread_started);
860 while (1) {
861 linux_wlan_lock(&g_linux_wlan->rxq_event);
862 /* wait_for_completion(&g_linux_wlan->rxq_event); */
863
864 if (g_linux_wlan->close) {
865 /*Unlock the mutex in the mac_close function to indicate the exiting of the RX thread */
866 linux_wlan_unlock(&g_linux_wlan->rxq_thread_started);
867
868 while (!kthread_should_stop())
869 schedule();
870
871 PRINT_D(RX_DBG, " RX thread stopped\n");
872 break;
873 }
874 PRINT_D(RX_DBG, "Calling wlan_handle_rx_que()\n");
875
876 g_linux_wlan->oup.wlan_handle_rx_que();
877 }
878 return 0;
879}
880
881#define USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
882
883static int linux_wlan_txq_task(void *vp)
884{
885 int ret, txq_count;
886
887#if defined USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
888#define TX_BACKOFF_WEIGHT_INCR_STEP (1)
889#define TX_BACKOFF_WEIGHT_DECR_STEP (1)
890#define TX_BACKOFF_WEIGHT_MAX (7)
891#define TX_BACKOFF_WEIGHT_MIN (0)
892#define TX_BACKOFF_WEIGHT_UNIT_MS (10)
893 int backoff_weight = TX_BACKOFF_WEIGHT_MIN;
894 signed long timeout;
895#endif
896
897 /* inform wilc1000_wlan_init that TXQ task is started. */
898 linux_wlan_unlock(&g_linux_wlan->txq_thread_started);
899 while (1) {
900
901 PRINT_D(TX_DBG, "txq_task Taking a nap :)\n");
902 linux_wlan_lock(&g_linux_wlan->txq_event);
903 /* wait_for_completion(&pd->txq_event); */
904 PRINT_D(TX_DBG, "txq_task Who waked me up :$\n");
905
906 if (g_linux_wlan->close) {
907 /*Unlock the mutex in the mac_close function to indicate the exiting of the TX thread */
908 linux_wlan_unlock(&g_linux_wlan->txq_thread_started);
909
910 while (!kthread_should_stop())
911 schedule();
912
913 PRINT_D(TX_DBG, "TX thread stopped\n");
914 break;
915 }
916 PRINT_D(TX_DBG, "txq_task handle the sending packet and let me go to sleep.\n");
917#if !defined USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
918 g_linux_wlan->oup.wlan_handle_tx_que();
919#else
920 do {
921 ret = g_linux_wlan->oup.wlan_handle_tx_que(&txq_count);
922 if (txq_count < FLOW_CONTROL_LOWER_THRESHOLD /* && netif_queue_stopped(pd->wilc_netdev)*/) {
923 PRINT_D(TX_DBG, "Waking up queue\n");
924 /* netif_wake_queue(pd->wilc_netdev); */
925 if (netif_queue_stopped(g_linux_wlan->strInterfaceInfo[0].wilc_netdev))
926 netif_wake_queue(g_linux_wlan->strInterfaceInfo[0].wilc_netdev);
927 if (netif_queue_stopped(g_linux_wlan->strInterfaceInfo[1].wilc_netdev))
928 netif_wake_queue(g_linux_wlan->strInterfaceInfo[1].wilc_netdev);
929 }
930
931 if (ret == WILC_TX_ERR_NO_BUF) { /* failed to allocate buffers in chip. */
932 timeout = msecs_to_jiffies(TX_BACKOFF_WEIGHT_UNIT_MS << backoff_weight);
933 do {
934 /* Back off from sending packets for some time. */
935 /* schedule_timeout will allow RX task to run and free buffers.*/
936 /* set_current_state(TASK_UNINTERRUPTIBLE); */
937 /* timeout = schedule_timeout(timeout); */
938 msleep(TX_BACKOFF_WEIGHT_UNIT_MS << backoff_weight);
939 } while (/*timeout*/ 0);
940 backoff_weight += TX_BACKOFF_WEIGHT_INCR_STEP;
941 if (backoff_weight > TX_BACKOFF_WEIGHT_MAX) {
942 backoff_weight = TX_BACKOFF_WEIGHT_MAX;
943 }
944 } else {
945 if (backoff_weight > TX_BACKOFF_WEIGHT_MIN) {
946 backoff_weight -= TX_BACKOFF_WEIGHT_DECR_STEP;
947 if (backoff_weight < TX_BACKOFF_WEIGHT_MIN) {
948 backoff_weight = TX_BACKOFF_WEIGHT_MIN;
949 }
950 }
951 }
952 /*TODO: drop packets after a certain time/number of retry count. */
953 } while (ret == WILC_TX_ERR_NO_BUF && !g_linux_wlan->close); /* retry sending packets if no more buffers in chip. */
954#endif
955 }
956 return 0;
957}
958
959static void linux_wlan_rx_complete(void)
960{
961 PRINT_D(RX_DBG, "RX completed\n");
962}
963
964int linux_wlan_get_firmware(perInterface_wlan_t *p_nic)
965{
966
967 perInterface_wlan_t *nic = p_nic;
968 int ret = 0;
969 const struct firmware *wilc_firmware;
970 char *firmware;
971
972
973 if (nic->iftype == AP_MODE)
974 firmware = AP_FIRMWARE;
975 else if (nic->iftype == STATION_MODE)
976 firmware = STA_FIRMWARE;
977
978 /*BugID_5137*/
979 else {
980 PRINT_D(INIT_DBG, "Get P2P_CONCURRENCY_FIRMWARE\n");
981 firmware = P2P_CONCURRENCY_FIRMWARE;
982 }
983
984
985
986 if (nic == NULL) {
987 PRINT_ER("NIC is NULL\n");
988 goto _fail_;
989 }
990
991 if (&nic->wilc_netdev->dev == NULL) {
992 PRINT_ER("&nic->wilc_netdev->dev is NULL\n");
993 goto _fail_;
994 }
995
996
997 /* the firmare should be located in /lib/firmware in
998 * root file system with the name specified above */
999
1000#ifdef WILC_SDIO
1001 if (request_firmware(&wilc_firmware, firmware, &g_linux_wlan->wilc_sdio_func->dev) != 0) {
1002 PRINT_ER("%s - firmare not available\n", firmware);
1003 ret = -1;
1004 goto _fail_;
1005 }
1006#else
1007 if (request_firmware(&wilc_firmware, firmware, &g_linux_wlan->wilc_spidev->dev) != 0) {
1008 PRINT_ER("%s - firmare not available\n", firmware);
1009 ret = -1;
1010 goto _fail_;
1011 }
1012#endif
1013 g_linux_wlan->wilc_firmware = wilc_firmware; /* Bug 4703 */
1014
1015_fail_:
1016
1017 return ret;
1018
1019}
1020
1021#ifdef COMPLEMENT_BOOT
1022int repeat_power_cycle(perInterface_wlan_t *nic);
1023#endif
1024
1025static int linux_wlan_start_firmware(perInterface_wlan_t *nic)
1026{
1027
c5c77ba1
JK
1028 int ret = 0;
1029 /* start firmware */
1030 PRINT_D(INIT_DBG, "Starting Firmware ...\n");
1031 ret = g_linux_wlan->oup.wlan_start();
1032 if (ret < 0) {
1033 PRINT_ER("Failed to start Firmware\n");
1034 goto _fail_;
1035 }
1036
1037 /* wait for mac ready */
1038 PRINT_D(INIT_DBG, "Waiting for Firmware to get ready ...\n");
1039 ret = linux_wlan_lock_timeout(&g_linux_wlan->sync_event, 5000);
1040 if (ret) {
1041#ifdef COMPLEMENT_BOOT
7a8fd841 1042 static int timeout = 5;
c5c77ba1
JK
1043
1044 if (timeout--) {
1045 PRINT_D(INIT_DBG, "repeat power cycle[%d]", timeout);
1046 ret = repeat_power_cycle(nic);
1047 } else {
1048 timeout = 5;
1049 ret = -1;
1050 goto _fail_;
1051 }
1052#endif
1053 PRINT_D(INIT_DBG, "Firmware start timed out");
1054 goto _fail_;
1055 }
1056 /*
1057 * TODO: Driver shouoldn't wait forever for firmware to get started -
1058 * in case of timeout this should be handled properly
1059 */
1060 PRINT_D(INIT_DBG, "Firmware successfully started\n");
1061
1062_fail_:
1063 return ret;
1064}
1065static int linux_wlan_firmware_download(linux_wlan_t *p_nic)
1066{
1067
1068 int ret = 0;
1069
1070 if (g_linux_wlan->wilc_firmware == NULL) {
1071 PRINT_ER("Firmware buffer is NULL\n");
1072 ret = -ENOBUFS;
1073 goto _FAIL_;
1074 }
1075 /**
1076 * do the firmware download
1077 **/
1078 PRINT_D(INIT_DBG, "Downloading Firmware ...\n");
1079 ret = g_linux_wlan->oup.wlan_firmware_download(g_linux_wlan->wilc_firmware->data, g_linux_wlan->wilc_firmware->size);
1080 if (ret < 0) {
1081 goto _FAIL_;
1082 }
1083
1084 /* Freeing FW buffer */
1085 PRINT_D(INIT_DBG, "Freeing FW buffer ...\n");
1086 PRINT_D(INIT_DBG, "Releasing firmware\n");
1087 release_firmware(g_linux_wlan->wilc_firmware);
1088 g_linux_wlan->wilc_firmware = NULL;
1089
1090 PRINT_D(INIT_DBG, "Download Succeeded \n");
1091
1092_FAIL_:
1093 return ret;
1094}
1095
1096
1097/* startup configuration - could be changed later using iconfig*/
1098static int linux_wlan_init_test_config(struct net_device *dev, linux_wlan_t *p_nic)
1099{
1100
1101 unsigned char c_val[64];
1102 #ifndef STATIC_MACADDRESS
1103 unsigned char mac_add[] = {0x00, 0x80, 0xC2, 0x5E, 0xa2, 0xff};
1104 #endif
1105 unsigned int chipid = 0;
1106
1107 /*BugID_5077*/
1108 struct WILC_WFI_priv *priv;
1109 tstrWILC_WFIDrv *pstrWFIDrv;
1110
1111 PRINT_D(TX_DBG, "Start configuring Firmware\n");
1112 #ifndef STATIC_MACADDRESS
1113 get_random_bytes(&mac_add[5], 1);
1114 get_random_bytes(&mac_add[4], 1);
1115 #endif
1116 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
1117 pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
1118 PRINT_D(INIT_DBG, "Host = %x\n", (WILC_Uint32)pstrWFIDrv);
1119
1120 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]);
1121 chipid = wilc_get_chipid(0);
1122
1123
1124 if (g_linux_wlan->oup.wlan_cfg_set == NULL) {
1125 PRINT_D(INIT_DBG, "Null p[ointer\n");
1126 goto _fail_;
1127 }
1128
1129 *(int *)c_val = (WILC_Uint32)pstrWFIDrv;
1130
1131 if (!g_linux_wlan->oup.wlan_cfg_set(1, WID_SET_DRV_HANDLER, c_val, 4, 0, 0))
1132 goto _fail_;
1133
1134 /*to tell fw that we are going to use PC test - WILC specific*/
1135 c_val[0] = 0;
1136 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_PC_TEST_MODE, c_val, 1, 0, 0))
1137 goto _fail_;
1138
1139 c_val[0] = INFRASTRUCTURE;
1140 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_BSS_TYPE, c_val, 1, 0, 0))
1141 goto _fail_;
1142
1143
1144 /* c_val[0] = RATE_AUTO; / * bug 4275: Enable autorate and limit it to 24Mbps * / */
1145 c_val[0] = RATE_AUTO;
1146 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_CURRENT_TX_RATE, c_val, 1, 0, 0))
1147 goto _fail_;
1148
1149 c_val[0] = G_MIXED_11B_2_MODE;
1150 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11G_OPERATING_MODE, c_val, 1, 0, 0))
1151 goto _fail_;
1152
1153 c_val[0] = 1;
1154 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_CURRENT_CHANNEL, c_val, 1, 0, 0))
1155 goto _fail_;
1156
1157 c_val[0] = G_SHORT_PREAMBLE;
1158 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_PREAMBLE, c_val, 1, 0, 0))
1159 goto _fail_;
1160
1161 c_val[0] = AUTO_PROT;
1162 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_PROT_MECH, c_val, 1, 0, 0))
1163 goto _fail_;
1164
1165#ifdef SWITCH_LOG_TERMINAL
1166 c_val[0] = AUTO_PROT;
1167 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_LOGTerminal_Switch, c_val, 1, 0, 0))
1168 goto _fail_;
1169#endif
1170
1171 c_val[0] = ACTIVE_SCAN;
1172 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_SCAN_TYPE, c_val, 1, 0, 0))
1173 goto _fail_;
1174
1175 c_val[0] = SITE_SURVEY_OFF;
1176 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_SITE_SURVEY, c_val, 1, 0, 0))
1177 goto _fail_;
1178
1179 *((int *)c_val) = 0xffff; /* Never use RTS-CTS */
1180 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_RTS_THRESHOLD, c_val, 2, 0, 0))
1181 goto _fail_;
1182
1183 *((int *)c_val) = 2346;
1184 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_FRAG_THRESHOLD, c_val, 2, 0, 0))
1185 goto _fail_;
1186
1187 /* SSID */
1188 /* -------------------------------------------------------------- */
1189 /* Configuration : String with length less than 32 bytes */
1190 /* Values to set : Any string with length less than 32 bytes */
1191 /* ( In BSS Station Set SSID to "" (null string) */
1192 /* to enable Broadcast SSID suppport ) */
1193 /* -------------------------------------------------------------- */
1194#ifndef USE_WIRELESS
1195 strcpy(c_val, "nwifi");
1196 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_SSID, c_val, (strlen(c_val) + 1), 0, 0))
1197 goto _fail_;
1198#endif
1199
1200 c_val[0] = 0;
1201 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_BCAST_SSID, c_val, 1, 0, 0))
1202 goto _fail_;
1203
1204 c_val[0] = 1;
1205 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_QOS_ENABLE, c_val, 1, 0, 0))
1206 goto _fail_;
1207
1208 c_val[0] = NO_POWERSAVE;
1209 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_POWER_MANAGEMENT, c_val, 1, 0, 0))
1210 goto _fail_;
1211
1212 c_val[0] = NO_ENCRYPT; /* NO_ENCRYPT, 0x79 */
1213 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11I_MODE, c_val, 1, 0, 0))
1214 goto _fail_;
1215
1216 c_val[0] = OPEN_SYSTEM;
1217 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_AUTH_TYPE, c_val, 1, 0, 0))
1218 goto _fail_;
1219
1220 /* WEP/802 11I Configuration */
1221 /* ------------------------------------------------------------------ */
1222 /* Configuration : WEP Key */
1223 /* Values (0x) : 5 byte for WEP40 and 13 bytes for WEP104 */
1224 /* In case more than 5 bytes are passed on for WEP 40 */
1225 /* only first 5 bytes will be used as the key */
1226 /* ------------------------------------------------------------------ */
1227
1228 strcpy(c_val, "123456790abcdef1234567890");
1229 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_WEP_KEY_VALUE, c_val, (strlen(c_val) + 1), 0, 0))
1230 goto _fail_;
1231
1232 /* WEP/802 11I Configuration */
1233 /* ------------------------------------------------------------------ */
1234 /* Configuration : AES/TKIP WPA/RSNA Pre-Shared Key */
1235 /* Values to set : Any string with length greater than equal to 8 bytes */
1236 /* and less than 64 bytes */
1237 /* ------------------------------------------------------------------ */
1238 strcpy(c_val, "12345678");
1239 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11I_PSK, c_val, (strlen(c_val)), 0, 0))
1240 goto _fail_;
1241
1242 /* IEEE802.1X Key Configuration */
1243 /* ------------------------------------------------------------------ */
1244 /* Configuration : Radius Server Access Secret Key */
1245 /* Values to set : Any string with length greater than equal to 8 bytes */
1246 /* and less than 65 bytes */
1247 /* ------------------------------------------------------------------ */
1248 strcpy(c_val, "password");
1249 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_1X_KEY, c_val, (strlen(c_val) + 1), 0, 0))
1250 goto _fail_;
1251
1252 /* IEEE802.1X Server Address Configuration */
1253 /* ------------------------------------------------------------------ */
1254 /* Configuration : Radius Server IP Address */
1255 /* Values to set : Any valid IP Address */
1256 /* ------------------------------------------------------------------ */
1257 c_val[0] = 192;
1258 c_val[1] = 168;
1259 c_val[2] = 1;
1260 c_val[3] = 112;
1261 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_1X_SERV_ADDR, c_val, 4, 0, 0))
1262 goto _fail_;
1263
1264 c_val[0] = 3;
1265 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_LISTEN_INTERVAL, c_val, 1, 0, 0))
1266 goto _fail_;
1267
1268 c_val[0] = 3;
1269 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_DTIM_PERIOD, c_val, 1, 0, 0))
1270 goto _fail_;
1271
1272 c_val[0] = NORMAL_ACK;
1273 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_ACK_POLICY, c_val, 1, 0, 0))
1274 goto _fail_;
1275
1276 c_val[0] = 0;
1277 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_USER_CONTROL_ON_TX_POWER, c_val, 1, 0, 0))
1278 goto _fail_;
1279
1280 c_val[0] = 48;
1281 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_TX_POWER_LEVEL_11A, c_val, 1, 0, 0))
1282 goto _fail_;
1283
1284 c_val[0] = 28;
1285 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_TX_POWER_LEVEL_11B, c_val, 1, 0, 0))
1286 goto _fail_;
1287
1288 /* Beacon Interval */
1289 /* -------------------------------------------------------------------- */
1290 /* Configuration : Sets the beacon interval value */
1291 /* Values to set : Any 16-bit value */
1292 /* -------------------------------------------------------------------- */
1293
1294 *((int *)c_val) = 100;
1295 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_BEACON_INTERVAL, c_val, 2, 0, 0))
1296 goto _fail_;
1297
1298 c_val[0] = REKEY_DISABLE;
1299 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_REKEY_POLICY, c_val, 1, 0, 0))
1300 goto _fail_;
1301
1302 /* Rekey Time (s) (Used only when the Rekey policy is 2 or 4) */
1303 /* -------------------------------------------------------------------- */
1304 /* Configuration : Sets the Rekey Time (s) */
1305 /* Values to set : 32-bit value */
1306 /* -------------------------------------------------------------------- */
1307 *((int *)c_val) = 84600;
1308 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_REKEY_PERIOD, c_val, 4, 0, 0))
1309 goto _fail_;
1310
1311 /* Rekey Packet Count (in 1000s; used when Rekey Policy is 3) */
1312 /* -------------------------------------------------------------------- */
1313 /* Configuration : Sets Rekey Group Packet count */
1314 /* Values to set : 32-bit Value */
1315 /* -------------------------------------------------------------------- */
1316 *((int *)c_val) = 500;
1317 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_REKEY_PACKET_COUNT, c_val, 4, 0, 0))
1318 goto _fail_;
1319
1320 c_val[0] = 1;
1321 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_SHORT_SLOT_ALLOWED, c_val, 1, 0, 0))
1322 goto _fail_;
1323
1324 c_val[0] = G_SELF_CTS_PROT;
1325 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_ERP_PROT_TYPE, c_val, 1, 0, 0))
1326 goto _fail_;
1327
1328 c_val[0] = 1; /* Enable N */
1329 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_ENABLE, c_val, 1, 0, 0))
1330 goto _fail_;
1331
1332 c_val[0] = HT_MIXED_MODE;
1333 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_OPERATING_MODE, c_val, 1, 0, 0))
1334 goto _fail_;
1335
1336 c_val[0] = 1; /* TXOP Prot disable in N mode: No RTS-CTS on TX A-MPDUs to save air-time. */
1337 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_TXOP_PROT_DISABLE, c_val, 1, 0, 0))
1338 goto _fail_;
1339
1340 memcpy(c_val, mac_add, 6);
1341
1342 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_MAC_ADDR, c_val, 6, 0, 0))
1343 goto _fail_;
1344
1345 /**
1346 * AP only
1347 **/
1348 c_val[0] = DETECT_PROTECT_REPORT;
1349 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_OBSS_NONHT_DETECTION, c_val, 1, 0, 0))
1350 goto _fail_;
1351
1352 c_val[0] = RTS_CTS_NONHT_PROT;
1353 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_HT_PROT_TYPE, c_val, 1, 0, 0))
1354 goto _fail_;
1355
1356 c_val[0] = 0;
1357 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_RIFS_PROT_ENABLE, c_val, 1, 0, 0))
1358 goto _fail_;
1359
1360 c_val[0] = MIMO_MODE;
1361 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_SMPS_MODE, c_val, 1, 0, 0))
1362 goto _fail_;
1363
1364 c_val[0] = 7;
1365 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_CURRENT_TX_MCS, c_val, 1, 0, 0))
1366 goto _fail_;
1367
1368 c_val[0] = 1; /* Enable N with immediate block ack. */
1369 if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_IMMEDIATE_BA_ENABLED, c_val, 1, 1, (WILC_Uint32)pstrWFIDrv))
1370 goto _fail_;
1371
1372 return 0;
1373
1374_fail_:
1375 return -1;
1376}
1377
1378
1379/**************************/
1380void wilc1000_wlan_deinit(linux_wlan_t *nic)
1381{
1382
1383 if (g_linux_wlan->wilc1000_initialized) {
1384
1385 printk("Deinitializing wilc1000 ...\n");
1386
1387 if (nic == NULL) {
1388 PRINT_ER("nic is NULL\n");
1389 return;
1390 }
1391
1392#if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
1393 /* johnny : remove */
1394 PRINT_D(INIT_DBG, "skip wilc_bus_set_default_speed\n");
1395#else
1396 wilc_bus_set_default_speed();
1397#endif
1398
1399 PRINT_D(INIT_DBG, "Disabling IRQ\n");
1400 #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
1401 linux_wlan_disable_irq(IRQ_WAIT);
1402 #else
1403 #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
1404
1405 #else
1406 linux_wlan_lock_mutex((void *)&g_linux_wlan->hif_cs);
1407 disable_sdio_interrupt();
1408 linux_wlan_unlock_mutex((void *)&g_linux_wlan->hif_cs);
1409 #endif
1410 #endif
1411
1412
1413 /* not sure if the following unlocks are needed or not*/
1414 if (&g_linux_wlan->rxq_event != NULL) {
1415 linux_wlan_unlock(&g_linux_wlan->rxq_event);
1416 }
1417
1418 if (&g_linux_wlan->txq_event != NULL) {
1419 linux_wlan_unlock(&g_linux_wlan->txq_event);
1420 }
1421
1422
1423 #if (RX_BH_TYPE == RX_BH_WORK_QUEUE)
1424 /*Removing the work struct from the linux kernel workqueue*/
1425 if (&g_linux_wlan->rx_work_queue != NULL)
1426 flush_work(&g_linux_wlan->rx_work_queue);
1427
1428 #elif (RX_BH_TYPE == RX_BH_KTHREAD)
1429 /* if(&nic->rx_sem != NULL) */
1430 /* linux_wlan_unlock(&nic->rx_sem); */
1431 #endif
1432
1433 PRINT_D(INIT_DBG, "Deinitializing Threads\n");
1434 wlan_deinitialize_threads(nic);
1435
1436 PRINT_D(INIT_DBG, "Deinitializing IRQ\n");
1437 deinit_irq(g_linux_wlan);
1438
1439
1440 if (&g_linux_wlan->oup != NULL) {
1441 if (g_linux_wlan->oup.wlan_stop != NULL)
1442 g_linux_wlan->oup.wlan_stop();
1443 }
1444
1445 PRINT_D(INIT_DBG, "Deinitializing WILC Wlan\n");
1446 wilc_wlan_deinit(nic);
1447#if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
1448 #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
1449 PRINT_D(INIT_DBG, "Disabling IRQ 2\n");
1450
1451 linux_wlan_lock_mutex((void *)&g_linux_wlan->hif_cs);
1452 disable_sdio_interrupt();
1453 linux_wlan_unlock_mutex((void *)&g_linux_wlan->hif_cs);
1454 #endif
1455#endif
1456
1457 /*De-Initialize locks*/
1458 PRINT_D(INIT_DBG, "Deinitializing Locks\n");
1459 wlan_deinit_locks(g_linux_wlan);
1460
1461 /* announce that wilc1000 is not initialized */
1462 g_linux_wlan->wilc1000_initialized = 0;
1463
1464 PRINT_D(INIT_DBG, "wilc1000 deinitialization Done\n");
1465
1466 } else {
1467 PRINT_D(INIT_DBG, "wilc1000 is not initialized\n");
1468 }
1469 return;
1470}
1471
1472int wlan_init_locks(linux_wlan_t *p_nic)
1473{
1474
1475 PRINT_D(INIT_DBG, "Initializing Locks ...\n");
1476
1477 /*initialize mutexes*/
1478 linux_wlan_init_mutex("hif_lock/hif_cs", &g_linux_wlan->hif_cs, 1);
1479 linux_wlan_init_mutex("rxq_lock/rxq_cs", &g_linux_wlan->rxq_cs, 1);
1480 linux_wlan_init_mutex("txq_lock/txq_cs", &g_linux_wlan->txq_cs, 1);
1481
1482 /*Added by Amr - BugID_4720*/
1483 linux_wlan_init_spin_lock("txq_spin_lock/txq_cs", &g_linux_wlan->txq_spinlock, 1);
1484
1485 /*Added by Amr - BugID_4720*/
1486 linux_wlan_init_lock("txq_add_to_head_lock/txq_cs", &g_linux_wlan->txq_add_to_head_cs, 1);
1487
1488 linux_wlan_init_lock("txq_wait/txq_event", &g_linux_wlan->txq_event, 0);
1489 linux_wlan_init_lock("rxq_wait/rxq_event", &g_linux_wlan->rxq_event, 0);
1490
1491 linux_wlan_init_lock("cfg_wait/cfg_event", &g_linux_wlan->cfg_event, 0);
1492 linux_wlan_init_lock("sync_event", &g_linux_wlan->sync_event, 0);
1493
1494 linux_wlan_init_lock("rxq_lock/rxq_started", &g_linux_wlan->rxq_thread_started, 0);
1495 linux_wlan_init_lock("rxq_lock/txq_started", &g_linux_wlan->txq_thread_started, 0);
1496
1497 #if (RX_BH_TYPE == RX_BH_KTHREAD)
1498 linux_wlan_init_lock("BH_SEM", &g_linux_wlan->rx_sem, 0);
1499 #endif
1500
1501 return 0;
1502}
1503
1504static int wlan_deinit_locks(linux_wlan_t *nic)
1505{
1506 PRINT_D(INIT_DBG, "De-Initializing Locks\n");
1507
1508 if (&g_linux_wlan->hif_cs != NULL)
1509 linux_wlan_deinit_mutex(&g_linux_wlan->hif_cs);
1510
1511 if (&g_linux_wlan->rxq_cs != NULL)
1512 linux_wlan_deinit_mutex(&g_linux_wlan->rxq_cs);
1513
1514 if (&g_linux_wlan->txq_cs != NULL)
1515 linux_wlan_deinit_mutex(&g_linux_wlan->txq_cs);
1516
1517 /*Added by Amr - BugID_4720*/
1518 if (&g_linux_wlan->txq_spinlock != NULL)
1519 linux_wlan_deinit_spin_lock(&g_linux_wlan->txq_spinlock);
1520
1521 if (&g_linux_wlan->rxq_event != NULL)
1522 linux_wlan_deinit_lock(&g_linux_wlan->rxq_event);
1523
1524 if (&g_linux_wlan->txq_event != NULL)
1525 linux_wlan_deinit_lock(&g_linux_wlan->txq_event);
1526
1527 /*Added by Amr - BugID_4720*/
1528 if (&g_linux_wlan->txq_add_to_head_cs != NULL)
1529 linux_wlan_deinit_lock(&g_linux_wlan->txq_add_to_head_cs);
1530
1531 if (&g_linux_wlan->rxq_thread_started != NULL)
1532 linux_wlan_deinit_lock(&g_linux_wlan->rxq_thread_started);
1533
1534 if (&g_linux_wlan->txq_thread_started != NULL)
1535 linux_wlan_deinit_lock(&g_linux_wlan->txq_thread_started);
1536
1537 if (&g_linux_wlan->cfg_event != NULL)
1538 linux_wlan_deinit_lock(&g_linux_wlan->cfg_event);
1539
1540 if (&g_linux_wlan->sync_event != NULL)
1541 linux_wlan_deinit_lock(&g_linux_wlan->sync_event);
1542
1543 return 0;
1544}
1545void linux_to_wlan(wilc_wlan_inp_t *nwi, linux_wlan_t *nic)
1546{
1547
1548 PRINT_D(INIT_DBG, "Linux to Wlan services ...\n");
1549
1550 nwi->os_context.hif_critical_section = (void *)&g_linux_wlan->hif_cs;
1551 nwi->os_context.os_private = (void *)nic;
1552 nwi->os_context.tx_buffer_size = LINUX_TX_SIZE;
1553 nwi->os_context.txq_critical_section = (void *)&g_linux_wlan->txq_cs;
1554
1555 /*Added by Amr - BugID_4720*/
1556 nwi->os_context.txq_add_to_head_critical_section = (void *)&g_linux_wlan->txq_add_to_head_cs;
1557
1558 /*Added by Amr - BugID_4720*/
1559 nwi->os_context.txq_spin_lock = (void *)&g_linux_wlan->txq_spinlock;
1560
1561 nwi->os_context.txq_wait_event = (void *)&g_linux_wlan->txq_event;
1562
1563#if defined (MEMORY_STATIC)
1564 nwi->os_context.rx_buffer_size = LINUX_RX_SIZE;
1565#endif
1566 nwi->os_context.rxq_critical_section = (void *)&g_linux_wlan->rxq_cs;
1567 nwi->os_context.rxq_wait_event = (void *)&g_linux_wlan->rxq_event;
1568 nwi->os_context.cfg_wait_event = (void *)&g_linux_wlan->cfg_event;
1569
1570 nwi->os_func.os_sleep = linux_wlan_msleep;
1571 nwi->os_func.os_atomic_sleep = linux_wlan_atomic_msleep;
1572 nwi->os_func.os_debug = linux_wlan_dbg;
1573 nwi->os_func.os_malloc = linux_wlan_malloc;
1574 nwi->os_func.os_malloc_atomic = linux_wlan_malloc_atomic;
1575 nwi->os_func.os_free = linux_wlan_free;
1576 nwi->os_func.os_lock = linux_wlan_lock;
1577 nwi->os_func.os_unlock = linux_wlan_unlock;
1578 nwi->os_func.os_wait = linux_wlan_lock_timeout;
1579 nwi->os_func.os_signal = linux_wlan_unlock;
1580 nwi->os_func.os_enter_cs = linux_wlan_lock_mutex;
1581 nwi->os_func.os_leave_cs = linux_wlan_unlock_mutex;
1582
1583 /*Added by Amr - BugID_4720*/
1584 nwi->os_func.os_spin_lock = linux_wlan_spin_lock;
1585 nwi->os_func.os_spin_unlock = linux_wlan_spin_unlock;
1586
1587#ifdef WILC_SDIO
1588 nwi->io_func.io_type = HIF_SDIO;
1589 nwi->io_func.io_init = linux_sdio_init;
1590 nwi->io_func.io_deinit = linux_sdio_deinit;
1591 nwi->io_func.u.sdio.sdio_cmd52 = linux_sdio_cmd52;
1592 nwi->io_func.u.sdio.sdio_cmd53 = linux_sdio_cmd53;
1593 nwi->io_func.u.sdio.sdio_set_max_speed = linux_sdio_set_max_speed;
1594 nwi->io_func.u.sdio.sdio_set_default_speed = linux_sdio_set_default_speed;
1595#else
1596 nwi->io_func.io_type = HIF_SPI;
1597 nwi->io_func.io_init = linux_spi_init;
1598 nwi->io_func.io_deinit = linux_spi_deinit;
1599 nwi->io_func.u.spi.spi_tx = linux_spi_write;
1600 nwi->io_func.u.spi.spi_rx = linux_spi_read;
1601 nwi->io_func.u.spi.spi_trx = linux_spi_write_read;
1602 nwi->io_func.u.spi.spi_max_speed = linux_spi_set_max_speed;
1603#endif
1604
1605 /*for now - to be revised*/
1606 #ifdef WILC_FULLY_HOSTING_AP
1607 /* incase of Fully hosted AP, all non cfg pkts are processed here*/
1608 nwi->net_func.rx_indicate = WILC_Process_rx_frame;
1609 #else
1610 nwi->net_func.rx_indicate = frmw_to_linux;
1611 #endif
1612 nwi->net_func.rx_complete = linux_wlan_rx_complete;
1613 nwi->indicate_func.mac_indicate = linux_wlan_mac_indicate;
1614}
1615
1616int wlan_initialize_threads(perInterface_wlan_t *nic)
1617{
1618
1619 int ret = 0;
1620 PRINT_D(INIT_DBG, "Initializing Threads ...\n");
1621
1622#if (RX_BH_TYPE == RX_BH_WORK_QUEUE)
1623 /*Initialize rx work queue task*/
1624 INIT_WORK(&g_linux_wlan->rx_work_queue, isr_bh_routine);
1625#elif (RX_BH_TYPE == RX_BH_KTHREAD)
1626 PRINT_D(INIT_DBG, "Creating kthread for Rxq BH\n");
1627 g_linux_wlan->rx_bh_thread = kthread_run(isr_bh_routine, (void *)g_linux_wlan, "K_RXQ_BH");
1628 if (g_linux_wlan->rx_bh_thread == 0) {
1629 PRINT_ER("couldn't create RX BH thread\n");
1630 ret = -ENOBUFS;
1631 goto _fail_;
1632 }
1633#endif
1634
1635#ifndef TCP_ENHANCEMENTS
1636 /* create rx task */
1637 PRINT_D(INIT_DBG, "Creating kthread for reception\n");
1638 g_linux_wlan->rxq_thread = kthread_run(linux_wlan_rxq_task, (void *)g_linux_wlan, "K_RXQ_TASK");
1639 if (g_linux_wlan->rxq_thread == 0) {
1640 PRINT_ER("couldn't create RXQ thread\n");
1641 ret = -ENOBUFS;
1642 goto _fail_1;
1643 }
1644
1645 /* wait for RXQ task to start. */
1646 linux_wlan_lock(&g_linux_wlan->rxq_thread_started);
1647
1648#endif
1649
1650 /* create tx task */
1651 PRINT_D(INIT_DBG, "Creating kthread for transmission\n");
1652 g_linux_wlan->txq_thread = kthread_run(linux_wlan_txq_task, (void *)g_linux_wlan, "K_TXQ_TASK");
1653 if (g_linux_wlan->txq_thread == 0) {
1654 PRINT_ER("couldn't create TXQ thread\n");
1655 ret = -ENOBUFS;
1656 goto _fail_2;
1657 }
1658#ifdef DEBUG_MODE
1659 PRINT_D(INIT_DBG, "Creating kthread for Debugging\n");
1660 g_linux_wlan->txq_thread = kthread_run(DebuggingThreadTask, (void *)g_linux_wlan, "DebugThread");
1661 if (g_linux_wlan->txq_thread == 0) {
1662 PRINT_ER("couldn't create TXQ thread\n");
1663 ret = -ENOBUFS;
1664 goto _fail_2;
1665 }
1666#endif
1667 /* wait for TXQ task to start. */
1668 linux_wlan_lock(&g_linux_wlan->txq_thread_started);
1669
1670 return 0;
1671
1672_fail_2:
1673 /*De-Initialize 2nd thread*/
1674 g_linux_wlan->close = 1;
1675 linux_wlan_unlock(&g_linux_wlan->rxq_event);
1676 kthread_stop(g_linux_wlan->rxq_thread);
1677
7a8fd841 1678#ifndef TCP_ENHANCEMENTS
c5c77ba1 1679_fail_1:
7a8fd841 1680#endif
c5c77ba1
JK
1681 #if (RX_BH_TYPE == RX_BH_KTHREAD)
1682 /*De-Initialize 1st thread*/
1683 g_linux_wlan->close = 1;
1684 linux_wlan_unlock(&g_linux_wlan->rx_sem);
1685 kthread_stop(g_linux_wlan->rx_bh_thread);
1686_fail_:
1687 #endif
1688 g_linux_wlan->close = 0;
1689 return ret;
1690}
1691
1692static void wlan_deinitialize_threads(linux_wlan_t *nic)
1693{
1694
1695 g_linux_wlan->close = 1;
1696 PRINT_D(INIT_DBG, "Deinitializing Threads\n");
1697 if (&g_linux_wlan->rxq_event != NULL)
1698 linux_wlan_unlock(&g_linux_wlan->rxq_event);
1699
1700
1701 if (g_linux_wlan->rxq_thread != NULL) {
1702 kthread_stop(g_linux_wlan->rxq_thread);
1703 g_linux_wlan->rxq_thread = NULL;
1704 }
1705
1706
1707 if (&g_linux_wlan->txq_event != NULL)
1708 linux_wlan_unlock(&g_linux_wlan->txq_event);
1709
1710
1711 if (g_linux_wlan->txq_thread != NULL) {
1712 kthread_stop(g_linux_wlan->txq_thread);
1713 g_linux_wlan->txq_thread = NULL;
1714 }
1715
1716 #if (RX_BH_TYPE == RX_BH_KTHREAD)
1717 if (&g_linux_wlan->rx_sem != NULL)
1718 linux_wlan_unlock(&g_linux_wlan->rx_sem);
1719
1720 if (g_linux_wlan->rx_bh_thread != NULL) {
1721 kthread_stop(g_linux_wlan->rx_bh_thread);
1722 g_linux_wlan->rx_bh_thread = NULL;
1723 }
1724 #endif
1725}
1726
1727#ifdef STATIC_MACADDRESS
1728const char *path_string[] = {
1729 "/etc/wlan",
1730 "/data/wlan",
1731};
1732
1733static int linux_wlan_read_mac_addr(void *vp)
1734{
1735 int ret = 0;
1736 struct file *fp = (struct file *)-ENOENT;
1737 mm_segment_t old_fs;
1738 loff_t pos = 0;
1739 int index;
0feae200 1740 int array_size = ARRAY_SIZE(path_string);
c5c77ba1
JK
1741
1742 /* change to KERNEL_DS address limit */
1743 old_fs = get_fs();
1744 set_fs(KERNEL_DS);
1745
1746 for (index = 0; index < array_size; index++) {
1747 fp = filp_open(path_string[index], O_WRONLY, 0640);
1748 if (!fp) {
1749 ret = -1;
1750 goto exit;
1751 }
1752
1753 /*No such file or directory */
1754 if (IS_ERR(fp) || !fp->f_op) {
1755 get_random_bytes(&mac_add[3], 3);
1756 /* open file to write */
1757 fp = filp_open(path_string[index], O_WRONLY | O_CREAT, 0640);
1758
1759 if (!fp || IS_ERR(fp)) {
1760 ret = -1;
1761 continue;
1762 } else {
1763 /* write buf to file */
1764 fp->f_op->write(fp, mac_add, 6, &pos);
1765 break;
1766 }
1767 } else {
1768 /* read file to buf */
1769 fp->f_op->read(fp, mac_add, 6, &pos);
1770 break;
1771 }
1772 }
1773
1774 if (index == array_size) {
1775 PRINT_ER("random MAC\n");
1776 }
1777
1778exit:
1779 if (fp && !IS_ERR(fp)) {
1780 filp_close(fp, NULL);
1781 }
1782
1783 set_fs(old_fs);
1784
1785 return ret;
1786}
1787#endif
1788
1789#ifdef COMPLEMENT_BOOT
1790
1791extern volatile int probe;
1792extern uint8_t core_11b_ready(void);
1793
1794#define READY_CHECK_THRESHOLD 30
1795extern void wilc_wlan_global_reset(void);
1796uint8_t wilc1000_prepare_11b_core(wilc_wlan_inp_t *nwi, wilc_wlan_oup_t *nwo, linux_wlan_t *nic)
1797{
1798 uint8_t trials = 0;
1799 while ((core_11b_ready() && (READY_CHECK_THRESHOLD > (trials++)))) {
1800 PRINT_D(INIT_DBG, "11b core not ready yet: %u\n", trials);
1801 wilc_wlan_deinit(nic);
1802 wilc_wlan_global_reset();
1803 sdio_unregister_driver(&wilc_bus);
1804
1805 linux_wlan_device_detection(0);
1806
1807 mdelay(100);
1808
1809 linux_wlan_device_detection(1);
1810
1811 sdio_register_driver(&wilc_bus);
1812
1813 while (!probe) {
1814 msleep(100);
1815 }
1816 probe = 0;
1817 g_linux_wlan->wilc_sdio_func = local_sdio_func;
1818 linux_to_wlan(nwi, nic);
1819 wilc_wlan_init(nwi, nwo);
1820 }
1821
1822 if (READY_CHECK_THRESHOLD <= trials)
1823 return 1;
1824 else
1825 return 0;
1826
1827}
1828
1829int repeat_power_cycle(perInterface_wlan_t *nic)
1830{
1831 int ret = 0;
1832 wilc_wlan_inp_t nwi;
1833 wilc_wlan_oup_t nwo;
1834 sdio_unregister_driver(&wilc_bus);
1835
1836 linux_wlan_device_detection(0);
1837 linux_wlan_device_power(0);
1838 msleep(100);
1839 linux_wlan_device_power(1);
1840 msleep(80);
1841 linux_wlan_device_detection(1);
1842 msleep(20);
1843
1844 sdio_register_driver(&wilc_bus);
1845
1846 /* msleep(1000); */
1847 while (!probe) {
1848 msleep(100);
1849 }
1850 probe = 0;
1851 g_linux_wlan->wilc_sdio_func = local_sdio_func;
1852 linux_to_wlan(&nwi, g_linux_wlan);
1853 ret = wilc_wlan_init(&nwi, &nwo);
1854
1855 g_linux_wlan->mac_status = WILC_MAC_STATUS_INIT;
1856 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
1857 enable_sdio_interrupt();
1858 #endif
1859
1860 if (linux_wlan_get_firmware(nic)) {
1861 PRINT_ER("Can't get firmware \n");
1862 ret = -1;
1863 goto __fail__;
1864 }
1865
1866 /*Download firmware*/
1867 ret = linux_wlan_firmware_download(g_linux_wlan);
1868 if (ret < 0) {
1869 PRINT_ER("Failed to download firmware\n");
1870 goto __fail__;
1871 }
1872 /* Start firmware*/
1873 ret = linux_wlan_start_firmware(nic);
1874 if (ret < 0) {
1875 PRINT_ER("Failed to start firmware\n");
1876 }
1877__fail__:
1878 return ret;
1879}
1880#endif
1881
1882int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic)
1883{
1884 wilc_wlan_inp_t nwi;
1885 wilc_wlan_oup_t nwo;
1886 perInterface_wlan_t *nic = p_nic;
1887 int ret = 0;
1888
1889 if (!g_linux_wlan->wilc1000_initialized) {
1890 g_linux_wlan->mac_status = WILC_MAC_STATUS_INIT;
1891 g_linux_wlan->close = 0;
1892 g_linux_wlan->wilc1000_initialized = 0;
1893
1894 wlan_init_locks(g_linux_wlan);
1895
1896#ifdef STATIC_MACADDRESS
1897 wilc_mac_thread = kthread_run(linux_wlan_read_mac_addr, NULL, "wilc_mac_thread");
1898 if (wilc_mac_thread < 0) {
1899 PRINT_ER("couldn't create Mac addr thread\n");
1900 }
1901#endif
1902
1903 linux_to_wlan(&nwi, g_linux_wlan);
1904
1905 ret = wilc_wlan_init(&nwi, &nwo);
1906 if (ret < 0) {
1907 PRINT_ER("Initializing WILC_Wlan FAILED\n");
1908 ret = -EIO;
1909 goto _fail_locks_;
1910 }
1911 memcpy(&g_linux_wlan->oup, &nwo, sizeof(wilc_wlan_oup_t));
1912
1913 /*Save the oup structre into global pointer*/
1914 gpstrWlanOps = &g_linux_wlan->oup;
1915
1916
1917 ret = wlan_initialize_threads(nic);
1918 if (ret < 0) {
1919 PRINT_ER("Initializing Threads FAILED\n");
1920 ret = -EIO;
1921 goto _fail_wilc_wlan_;
1922 }
1923
1924#if (defined WILC_SDIO) && (defined COMPLEMENT_BOOT)
1925 if (wilc1000_prepare_11b_core(&nwi, &nwo, g_linux_wlan)) {
1926 PRINT_ER("11b Core is not ready\n");
1927 ret = -EIO;
1928 goto _fail_threads_;
1929 }
1930#endif
1931
1932#if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
1933 if (init_irq(g_linux_wlan)) {
1934 PRINT_ER("couldn't initialize IRQ\n");
1935 ret = -EIO;
1936 goto _fail_threads_;
1937 }
1938#endif
1939
1940#if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
1941 if (enable_sdio_interrupt()) {
1942 PRINT_ER("couldn't initialize IRQ\n");
1943 ret = -EIO;
1944 goto _fail_irq_init_;
1945 }
1946#endif
1947
1948 if (linux_wlan_get_firmware(nic)) {
1949 PRINT_ER("Can't get firmware \n");
1950 ret = -EIO;
1951 goto _fail_irq_enable_;
1952 }
1953
1954
1955 /*Download firmware*/
1956 ret = linux_wlan_firmware_download(g_linux_wlan);
1957 if (ret < 0) {
1958 PRINT_ER("Failed to download firmware\n");
1959 ret = -EIO;
1960 goto _fail_irq_enable_;
1961 }
1962
1963 /* Start firmware*/
1964 ret = linux_wlan_start_firmware(nic);
1965 if (ret < 0) {
1966 PRINT_ER("Failed to start firmware\n");
1967 ret = -EIO;
1968 goto _fail_irq_enable_;
1969 }
1970
1971 wilc_bus_set_max_speed();
1972
1973 if (g_linux_wlan->oup.wlan_cfg_get(1, WID_FIRMWARE_VERSION, 1, 0)) {
1974 int size;
1975 char Firmware_ver[20];
1976 size = g_linux_wlan->oup.wlan_cfg_get_value(
1977 WID_FIRMWARE_VERSION,
1978 Firmware_ver, sizeof(Firmware_ver));
1979 Firmware_ver[size] = '\0';
1980 PRINT_D(INIT_DBG, "***** Firmware Ver = %s *******\n", Firmware_ver);
1981 }
1982 /* Initialize firmware with default configuration */
1983 ret = linux_wlan_init_test_config(dev, g_linux_wlan);
1984
1985 if (ret < 0) {
1986 PRINT_ER("Failed to configure firmware\n");
1987 ret = -EIO;
1988 goto _fail_fw_start_;
1989 }
1990
1991 g_linux_wlan->wilc1000_initialized = 1;
1992 return 0; /*success*/
1993
1994
1995_fail_fw_start_:
1996 if (&g_linux_wlan->oup != NULL) {
1997 if (g_linux_wlan->oup.wlan_stop != NULL)
1998 g_linux_wlan->oup.wlan_stop();
1999 }
2000
2001_fail_irq_enable_:
2002#if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
2003 disable_sdio_interrupt();
c5c77ba1 2004_fail_irq_init_:
7a8fd841 2005#endif
c5c77ba1
JK
2006#if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
2007 deinit_irq(g_linux_wlan);
2008
2009#endif
2010_fail_threads_:
2011 wlan_deinitialize_threads(g_linux_wlan);
2012_fail_wilc_wlan_:
2013 wilc_wlan_deinit(g_linux_wlan);
2014_fail_locks_:
2015 wlan_deinit_locks(g_linux_wlan);
2016 PRINT_ER("WLAN Iinitialization FAILED\n");
2017 } else {
2018 PRINT_D(INIT_DBG, "wilc1000 already initialized\n");
2019 }
2020 return ret;
2021}
2022
2023
2024/*
2025 * - this function will be called automatically by OS when module inserted.
2026 */
2027
2028#if !defined (NM73131_0_BOARD)
2029int mac_init_fn(struct net_device *ndev)
2030{
2031
2032 /*Why we do this !!!*/
2033 netif_start_queue(ndev); /* ma */
2034 netif_stop_queue(ndev); /* ma */
2035
2036 return 0;
2037}
2038#else
2039int mac_init_fn(struct net_device *ndev)
2040{
2041
2042 unsigned char mac_add[] = {0x00, 0x50, 0xc2, 0x5e, 0x10, 0x00};
2043 /* TODO: get MAC address whenever the source is EPROM - hardcoded and copy it to ndev*/
2044 memcpy(ndev->dev_addr, mac_add, 6);
2045
2046 if (!is_valid_ether_addr(ndev->dev_addr)) {
2047 PRINT_ER("Error: Wrong MAC address\n");
2048 return -EINVAL;
2049 }
2050
2051 return 0;
2052}
2053#endif
2054
2055
2056void WILC_WFI_frame_register(struct wiphy *wiphy, struct net_device *dev,
2057 u16 frame_type, bool reg);
2058
2059/* This fn is called, when this device is setup using ifconfig */
2060#if !defined (NM73131_0_BOARD)
2061int mac_open(struct net_device *ndev)
2062{
2063 perInterface_wlan_t *nic;
2064
2065 /*BugID_5213*/
2066 /*No need for setting mac address here anymore,*/
2067 /*Just set it in init_test_config()*/
2068 unsigned char mac_add[ETH_ALEN] = {0};
2069 int status;
2070 int ret = 0;
2071 int i = 0;
2072 struct WILC_WFI_priv *priv;
2073
2074 nic = netdev_priv(ndev);
2075 priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy);
2076 PRINT_D(INIT_DBG, "MAC OPEN[%p]\n", ndev);
2077
2078 #ifdef USE_WIRELESS
2079 ret = WILC_WFI_InitHostInt(ndev);
2080 if (ret < 0) {
2081 PRINT_ER("Failed to initialize host interface\n");
2082
2083 return ret;
2084 }
2085 #endif
2086
2087 /*initialize platform*/
2088 PRINT_D(INIT_DBG, "*** re-init ***\n");
2089 ret = wilc1000_wlan_init(ndev, nic);
2090 if (ret < 0) {
2091 PRINT_ER("Failed to initialize wilc1000\n");
2092 WILC_WFI_DeInitHostInt(ndev);
2093 return ret;
2094 }
2095
2096 Set_machw_change_vir_if(WILC_FALSE);
2097
2098 status = host_int_get_MacAddress(priv->hWILCWFIDrv, mac_add);
2099 PRINT_D(INIT_DBG, "Mac address: %x:%x:%x:%x:%x:%x\n", mac_add[0], mac_add[1], mac_add[2],
2100 mac_add[3], mac_add[4], mac_add[5]);
2101
2102 /* loop through the NUM of supported devices and set the MAC address */
2103 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
2104 if (ndev == g_linux_wlan->strInterfaceInfo[i].wilc_netdev) {
2105 memcpy(g_linux_wlan->strInterfaceInfo[i].aSrcAddress, mac_add, ETH_ALEN);
2106 g_linux_wlan->strInterfaceInfo[i].drvHandler = (WILC_Uint32)priv->hWILCWFIDrv;
2107 break;
2108 }
2109 }
2110
2111 /* TODO: get MAC address whenever the source is EPROM - hardcoded and copy it to ndev*/
2112 memcpy(ndev->dev_addr, g_linux_wlan->strInterfaceInfo[i].aSrcAddress, ETH_ALEN);
2113
2114 if (!is_valid_ether_addr(ndev->dev_addr)) {
2115 PRINT_ER("Error: Wrong MAC address\n");
2116 ret = -EINVAL;
2117 goto _err_;
2118 }
2119
2120
2121 WILC_WFI_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy, nic->wilc_netdev,
2122 nic->g_struct_frame_reg[0].frame_type, nic->g_struct_frame_reg[0].reg);
2123 WILC_WFI_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy, nic->wilc_netdev,
2124 nic->g_struct_frame_reg[1].frame_type, nic->g_struct_frame_reg[1].reg);
2125 netif_wake_queue(ndev);
2126 g_linux_wlan->open_ifcs++;
2127 nic->mac_opened = 1;
2128 return 0;
2129
2130_err_:
2131 WILC_WFI_DeInitHostInt(ndev);
2132 wilc1000_wlan_deinit(g_linux_wlan);
2133 return ret;
2134}
2135#else
2136int mac_open(struct net_device *ndev)
2137{
2138
2139 linux_wlan_t *nic;
2140 nic = netdev_priv(ndev);
2141
2142 /*initialize platform*/
2143 if (wilc1000_wlan_init(nic)) {
2144 PRINT_ER("Failed to initialize platform\n");
2145 return 1;
2146 }
2147 /* Start the network interface queue for this device */
2148 PRINT_D(INIT_DBG, "Starting netifQ\n");
2149 netif_start_queue(ndev);
2150/* linux_wlan_lock(&close_exit_sync); */
2151 return 0;
2152}
2153#endif
2154
2155struct net_device_stats *mac_stats(struct net_device *dev)
2156{
2157 perInterface_wlan_t *nic = netdev_priv(dev);
2158
2159
2160 return &nic->netstats;
2161}
2162
2163/* Setup the multicast filter */
c5c77ba1
JK
2164static void wilc_set_multicast_list(struct net_device *dev)
2165{
2166
2167 struct netdev_hw_addr *ha;
2168 struct WILC_WFI_priv *priv;
2169 tstrWILC_WFIDrv *pstrWFIDrv;
2170 int i = 0;
2171 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
2172 pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
2173
2174
2175 if (!dev)
2176 return;
2177
2178 PRINT_D(INIT_DBG, "Setting Multicast List with count = %d. \n", dev->mc.count);
2179
2180 if (dev->flags & IFF_PROMISC) {
2181 /* Normally, we should configure the chip to retrive all packets
2182 * but we don't wanna support this right now */
2183 /* TODO: add promiscuous mode support */
2184 PRINT_D(INIT_DBG, "Set promiscuous mode ON, retrive all packets \n");
2185 return;
2186 }
2187
2188 /* If there's more addresses than we handle, get all multicast
2189 * packets and sort them out in software. */
2190 if ((dev->flags & IFF_ALLMULTI) || (dev->mc.count) > WILC_MULTICAST_TABLE_SIZE) {
2191 PRINT_D(INIT_DBG, "Disable multicast filter, retrive all multicast packets\n");
2192 /* get all multicast packets */
2193 host_int_setup_multicast_filter((WILC_WFIDrvHandle)pstrWFIDrv, WILC_FALSE, 0);
2194 return;
2195 }
2196
2197 /* No multicast? Just get our own stuff */
2198 if ((dev->mc.count) == 0) {
2199 PRINT_D(INIT_DBG, "Enable multicast filter, retrive directed packets only.\n");
2200 host_int_setup_multicast_filter((WILC_WFIDrvHandle)pstrWFIDrv, WILC_TRUE, 0);
2201 return;
2202 }
2203
2204 /* Store all of the multicast addresses in the hardware filter */
2205 netdev_for_each_mc_addr(ha, dev)
2206 {
2207 WILC_memcpy(gau8MulticastMacAddrList[i], ha->addr, ETH_ALEN);
2208 PRINT_D(INIT_DBG, "Entry[%d]: %x:%x:%x:%x:%x:%x\n", i,
2209 gau8MulticastMacAddrList[i][0], gau8MulticastMacAddrList[i][1], gau8MulticastMacAddrList[i][2], gau8MulticastMacAddrList[i][3], gau8MulticastMacAddrList[i][4], gau8MulticastMacAddrList[i][5]);
2210 i++;
2211 }
2212
2213 host_int_setup_multicast_filter((WILC_WFIDrvHandle)pstrWFIDrv, WILC_TRUE, (dev->mc.count));
2214
2215 return;
2216
2217}
2218
c5c77ba1
JK
2219static void linux_wlan_tx_complete(void *priv, int status)
2220{
2221
2222 struct tx_complete_data *pv_data = (struct tx_complete_data *)priv;
2223 if (status == 1) {
2224 PRINT_D(TX_DBG, "Packet sent successfully - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb);
2225 } else {
2226 PRINT_D(TX_DBG, "Couldn't send packet - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb);
2227 }
2228 /* Free the SK Buffer, its work is done */
2229 dev_kfree_skb(pv_data->skb);
2230 linux_wlan_free(pv_data);
2231}
2232
2233int mac_xmit(struct sk_buff *skb, struct net_device *ndev)
2234{
2235 perInterface_wlan_t *nic;
2236 struct tx_complete_data *tx_data = NULL;
2237 int QueueCount;
2238 char *pu8UdpBuffer;
2239 struct iphdr *ih;
2240 struct ethhdr *eth_h;
2241 nic = netdev_priv(ndev);
2242
2243 PRINT_D(INT_DBG, "\n========\n IntUH: %d - IntBH: %d - IntCld: %d \n========\n", int_rcvdU, int_rcvdB, int_clrd);
2244 PRINT_D(TX_DBG, "Sending packet just received from TCP/IP\n");
2245
2246 /* Stop the network interface queue */
2247 if (skb->dev != ndev) {
2248 PRINT_ER("Packet not destined to this device\n");
2249 return 0;
2250 }
2251
2252 tx_data = (struct tx_complete_data *)internal_alloc(sizeof(struct tx_complete_data), GFP_ATOMIC);
2253 if (tx_data == NULL) {
2254 PRINT_ER("Failed to allocate memory for tx_data structure\n");
2255 dev_kfree_skb(skb);
2256 netif_wake_queue(ndev);
2257 return 0;
2258 }
2259
2260 tx_data->buff = skb->data;
2261 tx_data->size = skb->len;
2262 tx_data->skb = skb;
2263
2264 eth_h = (struct ethhdr *)(skb->data);
2265 if (eth_h->h_proto == 0x8e88) {
2266 PRINT_D(INIT_DBG, "EAPOL transmitted\n");
2267 }
2268
2269 /*get source and dest ip addresses*/
2270 ih = (struct iphdr *)(skb->data + sizeof(struct ethhdr));
2271
2272 pu8UdpBuffer = (char *)ih + sizeof(struct iphdr);
2273 if ((pu8UdpBuffer[1] == 68 && pu8UdpBuffer[3] == 67) || (pu8UdpBuffer[1] == 67 && pu8UdpBuffer[3] == 68)) {
2274 PRINT_D(GENERIC_DBG, "DHCP Message transmitted, type:%x %x %x\n", pu8UdpBuffer[248], pu8UdpBuffer[249], pu8UdpBuffer[250]);
2275
2276 }
2277 PRINT_D(TX_DBG, "Sending packet - Size = %d - Address = %p - SKB = %p\n", tx_data->size, tx_data->buff, tx_data->skb);
2278
2279 /* Send packet to MAC HW - for now the tx_complete function will be just status
2280 * indicator. still not sure if I need to suspend host transmission till the tx_complete
2281 * function called or not?
2282 * allocated buffer will be freed in tx_complete function.
2283 */
2284 PRINT_D(TX_DBG, "Adding tx packet to TX Queue\n");
2285 nic->netstats.tx_packets++;
2286 nic->netstats.tx_bytes += tx_data->size;
2287 tx_data->pBssid = g_linux_wlan->strInterfaceInfo[nic->u8IfIdx].aBSSID;
2288 #ifndef WILC_FULLY_HOSTING_AP
2289 QueueCount = g_linux_wlan->oup.wlan_add_to_tx_que((void *)tx_data,
2290 tx_data->buff,
2291 tx_data->size,
2292 linux_wlan_tx_complete);
2293 #else
2294 QueueCount = WILC_Xmit_data((void *)tx_data, HOST_TO_WLAN);
2295 #endif /* WILC_FULLY_HOSTING_AP */
2296
2297
2298 if (QueueCount > FLOW_CONTROL_UPPER_THRESHOLD) {
2299 netif_stop_queue(g_linux_wlan->strInterfaceInfo[0].wilc_netdev);
2300 netif_stop_queue(g_linux_wlan->strInterfaceInfo[1].wilc_netdev);
2301 }
2302
2303 return 0;
2304}
2305
2306
2307int mac_close(struct net_device *ndev)
2308{
2309 struct WILC_WFI_priv *priv;
2310 perInterface_wlan_t *nic;
2311 tstrWILC_WFIDrv *pstrWFIDrv;
2312
2313 nic = netdev_priv(ndev);
2314
2315 if ((nic == NULL) || (nic->wilc_netdev == NULL) || (nic->wilc_netdev->ieee80211_ptr == NULL) || (nic->wilc_netdev->ieee80211_ptr->wiphy == NULL)) {
2316 PRINT_ER("nic = NULL\n");
2317 return 0;
2318 }
2319
2320 priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy);
2321
2322 if (priv == NULL) {
2323 PRINT_ER("priv = NULL\n");
2324 return 0;
2325 }
2326
2327 pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
2328
2329
2330
2331 PRINT_D(GENERIC_DBG, "Mac close\n");
2332
2333 if (g_linux_wlan == NULL) {
2334 PRINT_ER("g_linux_wlan = NULL\n");
2335 return 0;
2336 }
2337
2338 if (pstrWFIDrv == NULL) {
2339 PRINT_ER("pstrWFIDrv = NULL\n");
2340 return 0;
2341 }
2342
2343 if ((g_linux_wlan->open_ifcs) > 0) {
2344 g_linux_wlan->open_ifcs--;
2345 } else {
2346 PRINT_ER("ERROR: MAC close called while number of opened interfaces is zero\n");
2347 return 0;
2348 }
2349
2350 if (nic->wilc_netdev != NULL) {
2351 /* Stop the network interface queue */
2352 netif_stop_queue(nic->wilc_netdev);
2353
2354 #ifdef USE_WIRELESS
2355 WILC_WFI_DeInitHostInt(nic->wilc_netdev);
2356 #endif
2357 }
2358
2359 if (g_linux_wlan->open_ifcs == 0) {
2360 PRINT_D(GENERIC_DBG, "Deinitializing wilc1000\n");
2361 g_linux_wlan->close = 1;
2362 wilc1000_wlan_deinit(g_linux_wlan);
2363 #ifdef USE_WIRELESS
2364 #ifdef WILC_AP_EXTERNAL_MLME
2365 WILC_WFI_deinit_mon_interface();
2366 #endif
2367 #endif
2368 }
2369
2370 linux_wlan_unlock(&close_exit_sync);
2371 nic->mac_opened = 0;
2372
2373 return 0;
2374}
2375
2376
2377int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
2378{
2379
63d03e47 2380 u8 *buff = NULL;
c5c77ba1
JK
2381 WILC_Sint8 rssi;
2382 WILC_Uint32 size = 0, length = 0;
2383 perInterface_wlan_t *nic;
2384 struct WILC_WFI_priv *priv;
2385 WILC_Sint32 s32Error = WILC_SUCCESS;
2386
2387
2388
2389 /* struct iwreq *wrq = (struct iwreq *) req; // tony moved to case SIOCSIWPRIV */
2390 #ifdef USE_WIRELESS
2391 nic = netdev_priv(ndev);
2392
2393 if (!g_linux_wlan->wilc1000_initialized)
2394 return 0;
2395
2396 #endif
2397
2398 switch (cmd) {
2399 /* [[ added by tony for SIOCDEVPRIVATE */
2400 case SIOCDEVPRIVATE + 1:
2401 {
2402 android_wifi_priv_cmd priv_cmd;
2403
2404 PRINT_INFO(GENERIC_DBG, "in SIOCDEVPRIVATE+1\n");
2405
2406 if (copy_from_user(&priv_cmd, req->ifr_data, sizeof(android_wifi_priv_cmd))) {
2407 s32Error = -EFAULT;
2408 goto done;
2409 }
2410
2411 buff = kmalloc(priv_cmd.total_len, GFP_KERNEL);
2412 if (!buff) {
2413 s32Error = -ENOMEM;
2414 goto done;
2415 }
2416
2417 if (copy_from_user(buff, priv_cmd.buf, priv_cmd.total_len)) {
2418 s32Error = -EFAULT;
2419 goto done;
2420 }
2421
2422 PRINT_INFO(GENERIC_DBG, "%s: Android private cmd \"%s\" on %s\n", __FUNCTION__, buff, req->ifr_name);
2423
2424 if (strncasecmp(buff, "SCAN-ACTIVE", strlen("SCAN-ACTIVE")) == 0) {
2425 PRINT_INFO(GENERIC_DBG, "%s, SCAN-ACTIVE command\n", __FUNCTION__);
2426 } else if (strncasecmp(buff, "SCAN-PASSIVE", strlen("SCAN-PASSIVE")) == 0) {
2427 PRINT_INFO(GENERIC_DBG, "%s, SCAN-PASSIVE command\n", __FUNCTION__);
2428 } else if (strncasecmp(buff, "RXFILTER-START", strlen("RXFILTER-START")) == 0) {
2429 PRINT_INFO(GENERIC_DBG, "%s, RXFILTER-START command\n", __FUNCTION__);
2430 } else if (strncasecmp(buff, "RXFILTER-STOP", strlen("RXFILTER-STOP")) == 0) {
2431 PRINT_INFO(GENERIC_DBG, "%s, RXFILTER-STOP command\n", __FUNCTION__);
2432 } else if (strncasecmp(buff, "RXFILTER-ADD", strlen("RXFILTER-ADD")) == 0) {
2433 int filter_num = *(buff + strlen("RXFILTER-ADD") + 1) - '0';
2434 PRINT_INFO(GENERIC_DBG, "%s, RXFILTER-ADD command, filter_num=%d\n", __FUNCTION__, filter_num);
2435 } else if (strncasecmp(buff, "RXFILTER-REMOVE", strlen("RXFILTER-REMOVE")) == 0) {
2436 int filter_num = *(buff + strlen("RXFILTER-REMOVE") + 1) - '0';
2437 PRINT_INFO(GENERIC_DBG, "%s, RXFILTER-REMOVE command, filter_num=%d\n", __FUNCTION__, filter_num);
2438 } else if (strncasecmp(buff, "BTCOEXSCAN-START", strlen("BTCOEXSCAN-START")) == 0) {
2439 PRINT_INFO(GENERIC_DBG, "%s, BTCOEXSCAN-START command\n", __FUNCTION__);
2440 } else if (strncasecmp(buff, "BTCOEXSCAN-STOP", strlen("BTCOEXSCAN-STOP")) == 0) {
2441 PRINT_INFO(GENERIC_DBG, "%s, BTCOEXSCAN-STOP command\n", __FUNCTION__);
2442 } else if (strncasecmp(buff, "BTCOEXMODE", strlen("BTCOEXMODE")) == 0) {
2443 PRINT_INFO(GENERIC_DBG, "%s, BTCOEXMODE command\n", __FUNCTION__);
2444 } else if (strncasecmp(buff, "SETBAND", strlen("SETBAND")) == 0) {
2445 uint band = *(buff + strlen("SETBAND") + 1) - '0';
2446 PRINT_INFO(GENERIC_DBG, "%s, SETBAND command, band=%d\n", __FUNCTION__, band);
2447 } else if (strncasecmp(buff, "GETBAND", strlen("GETBAND")) == 0) {
2448 PRINT_INFO(GENERIC_DBG, "%s, GETBAND command\n", __FUNCTION__);
2449 } else if (strncasecmp(buff, "COUNTRY", strlen("COUNTRY")) == 0) {
2450 char *country_code = buff + strlen("COUNTRY") + 1;
2451 PRINT_INFO(GENERIC_DBG, "%s, COUNTRY command, country_code=%s\n", __FUNCTION__, country_code);
2452 } else {
2453 PRINT_INFO(GENERIC_DBG, "%s, Unknown command\n", __FUNCTION__);
2454 }
2455 } break;
2456
2457 /* ]] 2013-06-24 */
2458 case SIOCSIWPRIV:
2459 {
2460 struct iwreq *wrq = (struct iwreq *) req; /* added by tony */
2461
2462 size = wrq->u.data.length;
2463
2464 if (size && wrq->u.data.pointer) {
2465 buff = kmalloc(size, GFP_KERNEL);
2466 if (!buff) {
2467 s32Error = -ENOMEM;
2468 goto done;
2469 }
2470
2471 if (copy_from_user
2472 (buff, wrq->u.data.pointer,
2473 wrq->u.data.length)) {
2474 s32Error = -EFAULT;
2475 goto done;
2476 }
2477
2478 if (strncasecmp(buff, "RSSI", length) == 0) {
2479
2480 #ifdef USE_WIRELESS
2481 priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy);
2482 s32Error = host_int_get_rssi(priv->hWILCWFIDrv, &(rssi));
2483 if (s32Error)
2484 PRINT_ER("Failed to send get rssi param's message queue ");
2485 #endif
2486 PRINT_INFO(GENERIC_DBG, "RSSI :%d\n", rssi);
2487
2488 /*Rounding up the rssi negative value*/
2489 rssi += 5;
2490
2491 snprintf(buff, size, "rssi %d", rssi);
2492
2493 if (copy_to_user(wrq->u.data.pointer, buff, size)) {
2494 PRINT_ER("%s: failed to copy data to user buffer\n", __FUNCTION__);
2495 s32Error = -EFAULT;
2496 goto done;
2497 }
2498 }
2499 }
2500 }
2501 break;
2502
2503 default:
2504 {
2505 PRINT_INFO(GENERIC_DBG, "Command - %d - has been received\n", cmd);
2506 s32Error = -EOPNOTSUPP;
2507 goto done;
2508 }
2509 }
2510
2511done:
2512
2513 if (buff != NULL) {
2514 kfree(buff);
2515 }
2516
2517 return s32Error;
2518}
2519
2520void frmw_to_linux(uint8_t *buff, uint32_t size, uint32_t pkt_offset)
2521{
2522
2523 unsigned int frame_len = 0;
2524 int stats;
2525 unsigned char *buff_to_send = NULL;
2526 struct sk_buff *skb;
7a8fd841 2527#ifndef TCP_ENHANCEMENTS
c5c77ba1
JK
2528 char *pu8UdpBuffer;
2529 struct iphdr *ih;
7a8fd841 2530#endif
c5c77ba1
JK
2531 struct net_device *wilc_netdev;
2532 perInterface_wlan_t *nic;
2533
2534 wilc_netdev = GetIfHandler(buff);
2535 if (wilc_netdev == NULL)
2536 return;
2537
2538 buff += pkt_offset;
2539 nic = netdev_priv(wilc_netdev);
2540
2541 if (size > 0) {
2542
2543 frame_len = size;
2544 buff_to_send = buff;
2545
2546
2547 /* Need to send the packet up to the host, allocate a skb buffer */
2548 skb = dev_alloc_skb(frame_len);
2549 if (skb == NULL) {
2550 PRINT_ER("Low memory - packet droped\n");
2551 return;
2552 }
2553
2554 skb_reserve(skb, (unsigned int)skb->data & 0x3);
2555
2556 if (g_linux_wlan == NULL || wilc_netdev == NULL) {
2557 PRINT_ER("wilc_netdev in g_linux_wlan is NULL");
2558 }
2559 skb->dev = wilc_netdev;
2560
2561 if (skb->dev == NULL) {
2562 PRINT_ER("skb->dev is NULL\n");
2563 }
2564
2565 /*
2566 * for(i=0;i<40;i++)
2567 * {
2568 * if(i<frame_len)
2569 * WILC_PRINTF("buff_to_send[%d]=%2x\n",i,buff_to_send[i]);
2570 *
2571 * }*/
2572
2573 /* skb_put(skb, frame_len); */
2574 memcpy(skb_put(skb, frame_len), buff_to_send, frame_len);
2575
2576 /* WILC_PRINTF("After MEM_CPY\n"); */
2577
2578 /* nic = netdev_priv(wilc_netdev); */
2579
2580#ifdef USE_WIRELESS
2581 /* if(nic->monitor_flag)
2582 * {
2583 * WILC_WFI_monitor_rx(nic->wilc_netdev,skb);
2584 * return;
2585 * }*/
2586#endif
2587 skb->protocol = eth_type_trans(skb, wilc_netdev);
2588 #ifndef TCP_ENHANCEMENTS
2589 /*get source and dest ip addresses*/
2590 ih = (struct iphdr *)(skb->data + sizeof(struct ethhdr));
2591
2592 pu8UdpBuffer = (char *)ih + sizeof(struct iphdr);
2593 if (buff_to_send[35] == 67 && buff_to_send[37] == 68) {
2594 PRINT_D(RX_DBG, "DHCP Message received\n");
2595 }
2596 if (buff_to_send[12] == 0x88 && buff_to_send[13] == 0x8e)
2597 PRINT_D(GENERIC_DBG, "eapol received\n");
2598 #endif
2599 /* Send the packet to the stack by giving it to the bridge */
2600 nic->netstats.rx_packets++;
2601 nic->netstats.rx_bytes += frame_len;
2602 skb->ip_summed = CHECKSUM_UNNECESSARY;
2603 stats = netif_rx(skb);
2604 PRINT_D(RX_DBG, "netif_rx ret value is: %d\n", stats);
2605 }
2606 #ifndef TCP_ENHANCEMENTS
2607 else {
2608 PRINT_ER("Discard sending packet with len = %d\n", size);
2609 }
2610 #endif
2611}
2612
2613void WILC_WFI_mgmt_rx(uint8_t *buff, uint32_t size)
2614{
2615 int i = 0;
2616 perInterface_wlan_t *nic;
2617
2618 /*BugID_5450*/
2619 /*Pass the frame on the monitor interface, if any.*/
2620 /*Otherwise, pass it on p2p0 netdev, if registered on it*/
2621 for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
2622 nic = netdev_priv(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2623 if (nic->monitor_flag) {
2624 WILC_WFI_monitor_rx(buff, size);
2625 return;
2626 }
2627 }
2628
2629 #ifdef WILC_P2P
2630 nic = netdev_priv(g_linux_wlan->strInterfaceInfo[1].wilc_netdev); /* p2p0 */
2631 if ((buff[0] == nic->g_struct_frame_reg[0].frame_type && nic->g_struct_frame_reg[0].reg) ||
2632 (buff[0] == nic->g_struct_frame_reg[1].frame_type && nic->g_struct_frame_reg[1].reg)) {
2633 WILC_WFI_p2p_rx(g_linux_wlan->strInterfaceInfo[1].wilc_netdev, buff, size);
2634 }
2635 #endif
2636}
2637
2638int wilc_netdev_init(void)
2639{
2640
2641 int i;
2642 perInterface_wlan_t *nic;
2643 struct net_device *ndev;
2644
2645 linux_wlan_init_lock("close_exit_sync", &close_exit_sync, 0);
2646
2647 /*create the common structure*/
2648 g_linux_wlan = (linux_wlan_t *)WILC_MALLOC(sizeof(linux_wlan_t));
2649 memset(g_linux_wlan, 0, sizeof(linux_wlan_t));
2650
2651 /*Reset interrupt count debug*/
2652 int_rcvdU = 0;
2653 int_rcvdB = 0;
2654 int_clrd = 0;
2655 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
2656 register_inetaddr_notifier(&g_dev_notifier);
2657 #endif
2658
2659 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
2660 /*allocate first ethernet device with perinterface_wlan_t as its private data*/
2661 ndev = alloc_etherdev(sizeof(perInterface_wlan_t));
2662 if (!ndev) {
2663 PRINT_ER("Failed to allocate ethernet dev\n");
2664 return -1;
2665 }
2666
2667 nic = netdev_priv(ndev);
2668 memset(nic, 0, sizeof(perInterface_wlan_t));
2669
2670 /*Name the Devices*/
2671 if (i == 0) {
2672 #if defined(NM73131) /* tony, 2012-09-20 */
2673 strcpy(ndev->name, "wilc_eth%d");
2674 #elif defined(PLAT_CLM9722) /* rachel */
2675 strcpy(ndev->name, "eth%d");
2676 #else /* PANDA_BOARD, PLAT_ALLWINNER_A10, PLAT_ALLWINNER_A20, PLAT_ALLWINNER_A31, PLAT_AML8726_M3 or PLAT_WMS8304 */
2677 strcpy(ndev->name, "wlan%d");
2678 #endif
2679 } else
2680 strcpy(ndev->name, "p2p%d");
2681
2682 nic->u8IfIdx = g_linux_wlan->u8NoIfcs;
2683 nic->wilc_netdev = ndev;
2684 g_linux_wlan->strInterfaceInfo[g_linux_wlan->u8NoIfcs].wilc_netdev = ndev;
2685 g_linux_wlan->u8NoIfcs++;
e5af0561 2686 ndev->netdev_ops = &wilc_netdev_ops;
c5c77ba1
JK
2687
2688 #ifdef USE_WIRELESS
2689 {
2690 struct wireless_dev *wdev;
2691 /*Register WiFi*/
2692 wdev = WILC_WFI_WiphyRegister(ndev);
2693
2694 #ifdef WILC_SDIO
2695 /* set netdev, tony */
2696 SET_NETDEV_DEV(ndev, &local_sdio_func->dev);
2697 #endif
2698
2699 if (wdev == NULL) {
2700 PRINT_ER("Can't register WILC Wiphy\n");
2701 return -1;
2702 }
2703
2704 /*linking the wireless_dev structure with the netdevice*/
2705 nic->wilc_netdev->ieee80211_ptr = wdev;
2706 nic->wilc_netdev->ml_priv = nic;
2707 wdev->netdev = nic->wilc_netdev;
2708 nic->netstats.rx_packets = 0;
2709 nic->netstats.tx_packets = 0;
2710 nic->netstats.rx_bytes = 0;
2711 nic->netstats.tx_bytes = 0;
2712
2713 }
2714 #endif
2715
2716
2717 if (register_netdev(ndev)) {
2718 PRINT_ER("Device couldn't be registered - %s\n", ndev->name);
2719 return -1; /* ERROR */
2720 }
2721
2722 nic->iftype = STATION_MODE;
2723 nic->mac_opened = 0;
2724
2725 }
2726
2727 #ifndef WILC_SDIO
2728 if (!linux_spi_init(&g_linux_wlan->wilc_spidev)) {
2729 PRINT_ER("Can't initialize SPI \n");
2730 return -1; /* ERROR */
2731 }
2732 g_linux_wlan->wilc_spidev = wilc_spi_dev;
2733 #else
2734 g_linux_wlan->wilc_sdio_func = local_sdio_func;
2735 #endif
2736
2737 return 0;
2738}
2739
2740
2741/*The 1st function called after module inserted*/
2742static int __init init_wilc_driver(void)
2743{
2744
2745
2746#if defined (WILC_DEBUGFS)
2747 if (wilc_debugfs_init() < 0) {
2748 PRINT_D(GENERIC_DBG, "fail to create debugfs for wilc driver\n");
2749 return -1;
2750 }
2751#endif
2752
2753 printk("IN INIT FUNCTION\n");
691f1a2f 2754 printk("*** WILC1000 driver VERSION=[10.2] FW_VER=[10.2] ***\n");
c5c77ba1
JK
2755
2756 linux_wlan_device_power(1);
2757 msleep(100);
2758 linux_wlan_device_detection(1);
2759
2760#ifdef WILC_SDIO
2761 {
2762 int ret;
2763
2764 ret = sdio_register_driver(&wilc_bus);
2765 if (ret < 0) {
2766 PRINT_D(INIT_DBG, "init_wilc_driver: Failed register sdio driver\n");
2767 }
2768
2769 return ret;
2770 }
2771#else
2772 PRINT_D(INIT_DBG, "Initializing netdev\n");
2773 if (wilc_netdev_init()) {
2774 PRINT_ER("Couldn't initialize netdev\n");
2775 }
2776 return 0;
2777#endif
2778}
2779late_initcall(init_wilc_driver);
2780
2781static void __exit exit_wilc_driver(void)
2782{
2783 int i = 0;
2784 perInterface_wlan_t *nic[NUM_CONCURRENT_IFC];
2785 #define CLOSE_TIMEOUT (12 * 1000)
2786
2787 if ((g_linux_wlan != NULL) && (((g_linux_wlan->strInterfaceInfo[0].wilc_netdev) != NULL)
2788 || ((g_linux_wlan->strInterfaceInfo[1].wilc_netdev) != NULL))) {
2789 #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
2790 unregister_inetaddr_notifier(&g_dev_notifier);
2791 #endif
2792
2793 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
2794 nic[i] = netdev_priv(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2795 }
2796 }
2797
2798
2799 if ((g_linux_wlan != NULL) && g_linux_wlan->wilc_firmware != NULL) {
2800 release_firmware(g_linux_wlan->wilc_firmware);
2801 g_linux_wlan->wilc_firmware = NULL;
2802 }
2803
2804
2805 if ((g_linux_wlan != NULL) && (((g_linux_wlan->strInterfaceInfo[0].wilc_netdev) != NULL)
2806 || ((g_linux_wlan->strInterfaceInfo[1].wilc_netdev) != NULL))) {
2807 PRINT_D(INIT_DBG, "Waiting for mac_close ....\n");
2808
2809 if (linux_wlan_lock_timeout(&close_exit_sync, CLOSE_TIMEOUT) < 0)
2810 PRINT_D(INIT_DBG, "Closed TimedOUT\n");
2811 else
2812 PRINT_D(INIT_DBG, "mac_closed\n");
2813
2814
2815 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
2816 /* close all opened interfaces */
2817 if (g_linux_wlan->strInterfaceInfo[i].wilc_netdev != NULL) {
2818 if (nic[i]->mac_opened) {
2819 mac_close(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2820 }
2821 }
2822 }
2823 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
2824 PRINT_D(INIT_DBG, "Unregistering netdev %p \n", g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2825 unregister_netdev(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2826 #ifdef USE_WIRELESS
2827 PRINT_D(INIT_DBG, "Freeing Wiphy...\n");
2828 WILC_WFI_WiphyFree(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2829 #endif
2830 PRINT_D(INIT_DBG, "Freeing netdev...\n");
2831 free_netdev(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
2832 }
2833 }
2834
2835
2836#ifdef USE_WIRELESS
2837#ifdef WILC_AP_EXTERNAL_MLME
2838 /* Bug 4600 : WILC_WFI_deinit_mon_interface was already called at mac_close */
2839 /* WILC_WFI_deinit_mon_interface(); */
2840#endif
2841#endif
2842
2843 /* if(g_linux_wlan->open_ifcs==0) */
2844 {
2845 #ifndef WILC_SDIO
2846 PRINT_D(INIT_DBG, "SPI unregsiter...\n");
2847 spi_unregister_driver(&wilc_bus);
2848 #else
2849 PRINT_D(INIT_DBG, "SDIO unregsiter...\n");
2850 sdio_unregister_driver(&wilc_bus);
2851 #endif
2852
2853 linux_wlan_deinit_lock(&close_exit_sync);
2854 if (g_linux_wlan != NULL) {
2855 WILC_FREE(g_linux_wlan);
2856 g_linux_wlan = NULL;
2857 }
2858 printk("Module_exit Done.\n");
2859
2860#if defined (WILC_DEBUGFS)
2861 wilc_debugfs_remove();
2862#endif
2863
2864 linux_wlan_device_detection(0);
2865 linux_wlan_device_power(0);
2866 }
2867}
2868module_exit(exit_wilc_driver);
2869
2870MODULE_LICENSE("GPL");
2871#endif