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