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