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