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