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