876bcfb3b5462a7911032847b9256333db6bb7f0
[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 #include <linux/inetdevice.h>
21 #include <linux/etherdevice.h>
22 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/skbuff.h>
25
26 #include <linux/semaphore.h>
27
28 #ifdef WILC_SDIO
29 #include "linux_wlan_sdio.h"
30 #else
31 #include "linux_wlan_spi.h"
32 #endif
33
34 static int dev_state_ev_handler(struct notifier_block *this, unsigned long event, void *ptr);
35
36 static struct notifier_block g_dev_notifier = {
37 .notifier_call = dev_state_ev_handler
38 };
39
40 #define IRQ_WAIT 1
41 #define IRQ_NO_WAIT 0
42 static struct semaphore close_exit_sync;
43
44 static int wlan_deinit_locks(struct net_device *dev);
45 static void wlan_deinitialize_threads(struct net_device *dev);
46
47 static void linux_wlan_tx_complete(void *priv, int status);
48 static int mac_init_fn(struct net_device *ndev);
49 static struct net_device_stats *mac_stats(struct net_device *dev);
50 static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd);
51 static void wilc_set_multicast_list(struct net_device *dev);
52 struct wilc *wilc_dev;
53 bool wilc_enable_ps = true;
54
55 static const struct net_device_ops wilc_netdev_ops = {
56 .ndo_init = mac_init_fn,
57 .ndo_open = wilc_mac_open,
58 .ndo_stop = wilc_mac_close,
59 .ndo_start_xmit = wilc_mac_xmit,
60 .ndo_do_ioctl = mac_ioctl,
61 .ndo_get_stats = mac_stats,
62 .ndo_set_rx_mode = wilc_set_multicast_list,
63
64 };
65
66 static int dev_state_ev_handler(struct notifier_block *this, unsigned long event, void *ptr)
67 {
68 struct in_ifaddr *dev_iface = (struct in_ifaddr *)ptr;
69 struct wilc_priv *priv;
70 struct host_if_drv *hif_drv;
71 struct net_device *dev;
72 u8 *ip_addr_buf;
73 perInterface_wlan_t *nic;
74 u8 null_ip[4] = {0};
75 char wlan_dev_name[5] = "wlan0";
76
77 if (!dev_iface || !dev_iface->ifa_dev || !dev_iface->ifa_dev->dev) {
78 PRINT_D(GENERIC_DBG, "dev_iface = NULL\n");
79 return NOTIFY_DONE;
80 }
81
82 if (memcmp(dev_iface->ifa_label, "wlan0", 5) &&
83 memcmp(dev_iface->ifa_label, "p2p0", 4)) {
84 PRINT_D(GENERIC_DBG, "Interface is neither WLAN0 nor P2P0\n");
85 return NOTIFY_DONE;
86 }
87
88 dev = (struct net_device *)dev_iface->ifa_dev->dev;
89 if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy) {
90 PRINT_D(GENERIC_DBG, "No Wireless registerd\n");
91 return NOTIFY_DONE;
92 }
93 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
94 if (!priv) {
95 PRINT_D(GENERIC_DBG, "No Wireless Priv\n");
96 return NOTIFY_DONE;
97 }
98 hif_drv = (struct host_if_drv *)priv->hWILCWFIDrv;
99 nic = netdev_priv(dev);
100 if (!nic || !hif_drv) {
101 PRINT_D(GENERIC_DBG, "No Wireless Priv\n");
102 return NOTIFY_DONE;
103 }
104
105 PRINT_INFO(GENERIC_DBG, "dev_state_ev_handler +++\n");
106
107 switch (event) {
108 case NETDEV_UP:
109 PRINT_D(GENERIC_DBG, "dev_state_ev_handler event=NETDEV_UP %p\n", dev);
110
111 PRINT_INFO(GENERIC_DBG, "\n ============== IP Address Obtained ===============\n\n");
112
113 if (nic->iftype == STATION_MODE || nic->iftype == CLIENT_MODE) {
114 hif_drv->IFC_UP = 1;
115 wilc_optaining_ip = false;
116 del_timer(&wilc_during_ip_timer);
117 PRINT_D(GENERIC_DBG, "IP obtained , enable scan\n");
118 }
119
120 if (wilc_enable_ps)
121 wilc_set_power_mgmt(hif_drv, 1, 0);
122
123 PRINT_D(GENERIC_DBG, "[%s] Up IP\n", dev_iface->ifa_label);
124
125 ip_addr_buf = (char *)&dev_iface->ifa_address;
126 PRINT_D(GENERIC_DBG, "IP add=%d:%d:%d:%d\n",
127 ip_addr_buf[0], ip_addr_buf[1],
128 ip_addr_buf[2], ip_addr_buf[3]);
129 wilc_setup_ipaddress(hif_drv, ip_addr_buf, nic->u8IfIdx);
130
131 break;
132
133 case NETDEV_DOWN:
134 PRINT_D(GENERIC_DBG, "dev_state_ev_handler event=NETDEV_DOWN %p\n", dev);
135
136 PRINT_INFO(GENERIC_DBG, "\n ============== IP Address Released ===============\n\n");
137 if (nic->iftype == STATION_MODE || nic->iftype == CLIENT_MODE) {
138 hif_drv->IFC_UP = 0;
139 wilc_optaining_ip = false;
140 }
141
142 if (memcmp(dev_iface->ifa_label, wlan_dev_name, 5) == 0)
143 wilc_set_power_mgmt(hif_drv, 0, 0);
144
145 wilc_resolve_disconnect_aberration(hif_drv);
146
147 PRINT_D(GENERIC_DBG, "[%s] Down IP\n", dev_iface->ifa_label);
148
149 ip_addr_buf = null_ip;
150 PRINT_D(GENERIC_DBG, "IP add=%d:%d:%d:%d\n",
151 ip_addr_buf[0], ip_addr_buf[1],
152 ip_addr_buf[2], ip_addr_buf[3]);
153
154 wilc_setup_ipaddress(hif_drv, ip_addr_buf, nic->u8IfIdx);
155
156 break;
157
158 default:
159 PRINT_INFO(GENERIC_DBG, "dev_state_ev_handler event=default\n");
160 PRINT_INFO(GENERIC_DBG, "[%s] unknown dev event: %lu\n", dev_iface->ifa_label, event);
161
162 break;
163 }
164
165 return NOTIFY_DONE;
166 }
167
168 #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
169 static irqreturn_t isr_uh_routine(int irq, void *user_data)
170 {
171 perInterface_wlan_t *nic;
172 struct wilc *wilc;
173 struct net_device *dev = (struct net_device *)user_data;
174
175 nic = netdev_priv(dev);
176 wilc = nic->wilc;
177 PRINT_D(INT_DBG, "Interrupt received UH\n");
178
179 if (wilc->close) {
180 PRINT_ER("Driver is CLOSING: Can't handle UH interrupt\n");
181 return IRQ_HANDLED;
182 }
183 return IRQ_WAKE_THREAD;
184 }
185
186 static irqreturn_t isr_bh_routine(int irq, void *userdata)
187 {
188 perInterface_wlan_t *nic;
189 struct wilc *wilc;
190
191 nic = netdev_priv(userdata);
192 wilc = nic->wilc;
193
194 if (wilc->close) {
195 PRINT_ER("Driver is CLOSING: Can't handle BH interrupt\n");
196 return IRQ_HANDLED;
197 }
198
199 PRINT_D(INT_DBG, "Interrupt received BH\n");
200 wilc_handle_isr(wilc);
201
202 return IRQ_HANDLED;
203 }
204
205 static int init_irq(struct net_device *dev)
206 {
207 int ret = 0;
208 perInterface_wlan_t *nic;
209 struct wilc *wl;
210
211 nic = netdev_priv(dev);
212 wl = nic->wilc;
213
214 if ((gpio_request(GPIO_NUM, "WILC_INTR") == 0) &&
215 (gpio_direction_input(GPIO_NUM) == 0)) {
216 wl->dev_irq_num = gpio_to_irq(GPIO_NUM);
217 } else {
218 ret = -1;
219 PRINT_ER("could not obtain gpio for WILC_INTR\n");
220 }
221
222 if (ret != -1 && request_threaded_irq(wl->dev_irq_num,
223 isr_uh_routine,
224 isr_bh_routine,
225 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
226 "WILC_IRQ", dev) < 0) {
227 PRINT_ER("Failed to request IRQ for GPIO: %d\n", GPIO_NUM);
228 ret = -1;
229 } else {
230 PRINT_D(INIT_DBG, "IRQ request succeeded IRQ-NUM= %d on GPIO: %d\n",
231 wl->dev_irq_num, GPIO_NUM);
232 }
233
234 return ret;
235 }
236 #endif
237
238 static void deinit_irq(struct net_device *dev)
239 {
240 perInterface_wlan_t *nic;
241 struct wilc *wilc;
242
243 nic = netdev_priv(dev);
244 wilc = nic->wilc;
245
246 #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
247 if (&wilc->dev_irq_num != 0) {
248 free_irq(wilc->dev_irq_num, wilc);
249
250 gpio_free(GPIO_NUM);
251 }
252 #endif
253 }
254
255 void linux_wlan_dbg(u8 *buff)
256 {
257 PRINT_D(INIT_DBG, "%d\n", *buff);
258 }
259
260 int linux_wlan_lock_timeout(void *vp, u32 timeout)
261 {
262 int error = -1;
263
264 PRINT_D(LOCK_DBG, "Locking %p\n", vp);
265 if (vp)
266 error = down_timeout((struct semaphore *)vp,
267 msecs_to_jiffies(timeout));
268 else
269 PRINT_ER("Failed, mutex is NULL\n");
270 return error;
271 }
272
273 void linux_wlan_mac_indicate(struct wilc *wilc, int flag)
274 {
275 int status;
276
277 if (flag == WILC_MAC_INDICATE_STATUS) {
278 wilc_wlan_cfg_get_val(WID_STATUS,
279 (unsigned char *)&status, 4);
280 if (wilc->mac_status == WILC_MAC_STATUS_INIT) {
281 wilc->mac_status = status;
282 up(&wilc->sync_event);
283 } else {
284 wilc->mac_status = status;
285 }
286 } else if (flag == WILC_MAC_INDICATE_SCAN) {
287 PRINT_D(GENERIC_DBG, "Scanning ...\n");
288 }
289 }
290
291 static struct net_device *get_if_handler(struct wilc *wilc, u8 *mac_header)
292 {
293 u8 *bssid, *bssid1;
294 int i = 0;
295
296 bssid = mac_header + 10;
297 bssid1 = mac_header + 4;
298
299 for (i = 0; i < wilc->vif_num; i++)
300 if (!memcmp(bssid1, wilc->vif[i].bssid, ETH_ALEN) ||
301 !memcmp(bssid, wilc->vif[i].bssid, ETH_ALEN))
302 return wilc->vif[i].ndev;
303
304 PRINT_INFO(INIT_DBG, "Invalide handle\n");
305 for (i = 0; i < 25; i++)
306 PRINT_D(INIT_DBG, "%02x ", mac_header[i]);
307 bssid = mac_header + 18;
308 bssid1 = mac_header + 12;
309 for (i = 0; i < wilc->vif_num; i++)
310 if (!memcmp(bssid1, wilc->vif[i].bssid, ETH_ALEN) ||
311 !memcmp(bssid, wilc->vif[i].bssid, ETH_ALEN))
312 return wilc->vif[i].ndev;
313
314 PRINT_INFO(INIT_DBG, "\n");
315 return NULL;
316 }
317
318 int wilc_wlan_set_bssid(struct net_device *wilc_netdev, u8 *bssid)
319 {
320 int i = 0;
321 int ret = -1;
322 perInterface_wlan_t *nic;
323 struct wilc *wilc;
324
325 nic = netdev_priv(wilc_netdev);
326 wilc = nic->wilc;
327
328 for (i = 0; i < wilc->vif_num; i++)
329 if (wilc->vif[i].ndev == wilc_netdev) {
330 memcpy(wilc->vif[i].bssid, bssid, 6);
331 ret = 0;
332 break;
333 }
334
335 return ret;
336 }
337
338 int wilc_wlan_get_num_conn_ifcs(void)
339 {
340 u8 i = 0;
341 u8 null_bssid[6] = {0};
342 u8 ret_val = 0;
343
344 for (i = 0; i < wilc_dev->vif_num; i++)
345 if (memcmp(wilc_dev->vif[i].bssid, null_bssid, 6))
346 ret_val++;
347
348 return ret_val;
349 }
350
351 #define USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
352
353 static int linux_wlan_txq_task(void *vp)
354 {
355 int ret, txq_count;
356 perInterface_wlan_t *nic;
357 struct wilc *wl;
358 struct net_device *dev = vp;
359 #if defined USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
360 #define TX_BACKOFF_WEIGHT_INCR_STEP (1)
361 #define TX_BACKOFF_WEIGHT_DECR_STEP (1)
362 #define TX_BACKOFF_WEIGHT_MAX (7)
363 #define TX_BACKOFF_WEIGHT_MIN (0)
364 #define TX_BACKOFF_WEIGHT_UNIT_MS (10)
365 int backoff_weight = TX_BACKOFF_WEIGHT_MIN;
366 #endif
367
368 nic = netdev_priv(dev);
369 wl = nic->wilc;
370
371 up(&wl->txq_thread_started);
372 while (1) {
373 PRINT_D(TX_DBG, "txq_task Taking a nap :)\n");
374 down(&wl->txq_event);
375 PRINT_D(TX_DBG, "txq_task Who waked me up :$\n");
376
377 if (wl->close) {
378 up(&wl->txq_thread_started);
379
380 while (!kthread_should_stop())
381 schedule();
382
383 PRINT_D(TX_DBG, "TX thread stopped\n");
384 break;
385 }
386 PRINT_D(TX_DBG, "txq_task handle the sending packet and let me go to sleep.\n");
387 #if !defined USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
388 ret = wilc_wlan_handle_txq(dev, &txq_count);
389 #else
390 do {
391 ret = wilc_wlan_handle_txq(dev, &txq_count);
392 if (txq_count < FLOW_CONTROL_LOWER_THRESHOLD) {
393 PRINT_D(TX_DBG, "Waking up queue\n");
394
395 if (netif_queue_stopped(wl->vif[0].ndev))
396 netif_wake_queue(wl->vif[0].ndev);
397 if (netif_queue_stopped(wl->vif[1].ndev))
398 netif_wake_queue(wl->vif[1].ndev);
399 }
400
401 if (ret == WILC_TX_ERR_NO_BUF) {
402 do {
403 msleep(TX_BACKOFF_WEIGHT_UNIT_MS << backoff_weight);
404 } while (0);
405 backoff_weight += TX_BACKOFF_WEIGHT_INCR_STEP;
406 if (backoff_weight > TX_BACKOFF_WEIGHT_MAX)
407 backoff_weight = TX_BACKOFF_WEIGHT_MAX;
408 } else {
409 if (backoff_weight > TX_BACKOFF_WEIGHT_MIN) {
410 backoff_weight -= TX_BACKOFF_WEIGHT_DECR_STEP;
411 if (backoff_weight < TX_BACKOFF_WEIGHT_MIN)
412 backoff_weight = TX_BACKOFF_WEIGHT_MIN;
413 }
414 }
415 } while (ret == WILC_TX_ERR_NO_BUF && !wl->close);
416 #endif
417 }
418 return 0;
419 }
420
421 void linux_wlan_rx_complete(void)
422 {
423 PRINT_D(RX_DBG, "RX completed\n");
424 }
425
426 int wilc_wlan_get_firmware(struct net_device *dev)
427 {
428 perInterface_wlan_t *nic;
429 struct wilc *wilc;
430 int ret = 0;
431 const struct firmware *wilc_firmware;
432 char *firmware;
433
434 nic = netdev_priv(dev);
435 wilc = nic->wilc;
436
437 if (nic->iftype == AP_MODE) {
438 firmware = AP_FIRMWARE;
439 } else if (nic->iftype == STATION_MODE) {
440 firmware = STA_FIRMWARE;
441 } else {
442 PRINT_D(INIT_DBG, "Get P2P_CONCURRENCY_FIRMWARE\n");
443 firmware = P2P_CONCURRENCY_FIRMWARE;
444 }
445
446 if (!nic) {
447 PRINT_ER("NIC is NULL\n");
448 goto _fail_;
449 }
450
451 if (!(&nic->wilc_netdev->dev)) {
452 PRINT_ER("&nic->wilc_netdev->dev is NULL\n");
453 goto _fail_;
454 }
455
456 #ifdef WILC_SDIO
457 if (request_firmware(&wilc_firmware, firmware, &wilc->wilc_sdio_func->dev) != 0) {
458 PRINT_ER("%s - firmare not available\n", firmware);
459 ret = -1;
460 goto _fail_;
461 }
462 #else
463 if (request_firmware(&wilc_firmware, firmware, &wilc->wilc_spidev->dev) != 0) {
464 PRINT_ER("%s - firmare not available\n", firmware);
465 ret = -1;
466 goto _fail_;
467 }
468 #endif
469 wilc->firmware = wilc_firmware;
470
471 _fail_:
472
473 return ret;
474 }
475
476 static int linux_wlan_start_firmware(struct net_device *dev)
477 {
478 perInterface_wlan_t *nic;
479 struct wilc *wilc;
480 int ret = 0;
481
482 nic = netdev_priv(dev);
483 wilc = nic->wilc;
484
485 PRINT_D(INIT_DBG, "Starting Firmware ...\n");
486 ret = wilc_wlan_start();
487 if (ret < 0) {
488 PRINT_ER("Failed to start Firmware\n");
489 return ret;
490 }
491
492 PRINT_D(INIT_DBG, "Waiting for Firmware to get ready ...\n");
493 ret = linux_wlan_lock_timeout(&wilc->sync_event, 5000);
494 if (ret) {
495 PRINT_D(INIT_DBG, "Firmware start timed out");
496 return ret;
497 }
498 PRINT_D(INIT_DBG, "Firmware successfully started\n");
499
500 return 0;
501 }
502
503 static int linux_wlan_firmware_download(struct net_device *dev)
504 {
505 perInterface_wlan_t *nic;
506 struct wilc *wilc;
507 int ret = 0;
508
509 nic = netdev_priv(dev);
510 wilc = nic->wilc;
511
512 if (!wilc->firmware) {
513 PRINT_ER("Firmware buffer is NULL\n");
514 return -ENOBUFS;
515 }
516 PRINT_D(INIT_DBG, "Downloading Firmware ...\n");
517 ret = wilc_wlan_firmware_download(wilc->firmware->data,
518 wilc->firmware->size);
519 if (ret < 0)
520 return ret;
521
522 PRINT_D(INIT_DBG, "Freeing FW buffer ...\n");
523 PRINT_D(INIT_DBG, "Releasing firmware\n");
524 release_firmware(wilc->firmware);
525
526 PRINT_D(INIT_DBG, "Download Succeeded\n");
527
528 return 0;
529 }
530
531 static int linux_wlan_init_test_config(struct net_device *dev, struct wilc *p_nic)
532 {
533 unsigned char c_val[64];
534 unsigned char mac_add[] = {0x00, 0x80, 0xC2, 0x5E, 0xa2, 0xff};
535
536 struct wilc_priv *priv;
537 struct host_if_drv *hif_drv;
538
539 PRINT_D(TX_DBG, "Start configuring Firmware\n");
540 get_random_bytes(&mac_add[5], 1);
541 get_random_bytes(&mac_add[4], 1);
542 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
543 hif_drv = (struct host_if_drv *)priv->hWILCWFIDrv;
544 PRINT_D(INIT_DBG, "Host = %p\n", hif_drv);
545
546 PRINT_D(INIT_DBG, "MAC address is : %02x-%02x-%02x-%02x-%02x-%02x\n",
547 mac_add[0], mac_add[1], mac_add[2],
548 mac_add[3], mac_add[4], mac_add[5]);
549 wilc_get_chipid(0);
550
551 *(int *)c_val = 1;
552
553 if (!wilc_wlan_cfg_set(1, WID_SET_DRV_HANDLER, c_val, 4, 0, 0))
554 goto _fail_;
555
556 c_val[0] = 0;
557 if (!wilc_wlan_cfg_set(0, WID_PC_TEST_MODE, c_val, 1, 0, 0))
558 goto _fail_;
559
560 c_val[0] = INFRASTRUCTURE;
561 if (!wilc_wlan_cfg_set(0, WID_BSS_TYPE, c_val, 1, 0, 0))
562 goto _fail_;
563
564 c_val[0] = RATE_AUTO;
565 if (!wilc_wlan_cfg_set(0, WID_CURRENT_TX_RATE, c_val, 1, 0, 0))
566 goto _fail_;
567
568 c_val[0] = G_MIXED_11B_2_MODE;
569 if (!wilc_wlan_cfg_set(0, WID_11G_OPERATING_MODE, c_val, 1, 0, 0))
570 goto _fail_;
571
572 c_val[0] = 1;
573 if (!wilc_wlan_cfg_set(0, WID_CURRENT_CHANNEL, c_val, 1, 0, 0))
574 goto _fail_;
575
576 c_val[0] = G_SHORT_PREAMBLE;
577 if (!wilc_wlan_cfg_set(0, WID_PREAMBLE, c_val, 1, 0, 0))
578 goto _fail_;
579
580 c_val[0] = AUTO_PROT;
581 if (!wilc_wlan_cfg_set(0, WID_11N_PROT_MECH, c_val, 1, 0, 0))
582 goto _fail_;
583
584 c_val[0] = ACTIVE_SCAN;
585 if (!wilc_wlan_cfg_set(0, WID_SCAN_TYPE, c_val, 1, 0, 0))
586 goto _fail_;
587
588 c_val[0] = SITE_SURVEY_OFF;
589 if (!wilc_wlan_cfg_set(0, WID_SITE_SURVEY, c_val, 1, 0, 0))
590 goto _fail_;
591
592 *((int *)c_val) = 0xffff;
593 if (!wilc_wlan_cfg_set(0, WID_RTS_THRESHOLD, c_val, 2, 0, 0))
594 goto _fail_;
595
596 *((int *)c_val) = 2346;
597 if (!wilc_wlan_cfg_set(0, WID_FRAG_THRESHOLD, c_val, 2, 0, 0))
598 goto _fail_;
599
600 c_val[0] = 0;
601 if (!wilc_wlan_cfg_set(0, WID_BCAST_SSID, c_val, 1, 0, 0))
602 goto _fail_;
603
604 c_val[0] = 1;
605 if (!wilc_wlan_cfg_set(0, WID_QOS_ENABLE, c_val, 1, 0, 0))
606 goto _fail_;
607
608 c_val[0] = NO_POWERSAVE;
609 if (!wilc_wlan_cfg_set(0, WID_POWER_MANAGEMENT, c_val, 1, 0, 0))
610 goto _fail_;
611
612 c_val[0] = NO_SECURITY; /* NO_ENCRYPT, 0x79 */
613 if (!wilc_wlan_cfg_set(0, WID_11I_MODE, c_val, 1, 0, 0))
614 goto _fail_;
615
616 c_val[0] = OPEN_SYSTEM;
617 if (!wilc_wlan_cfg_set(0, WID_AUTH_TYPE, c_val, 1, 0, 0))
618 goto _fail_;
619
620 strcpy(c_val, "123456790abcdef1234567890");
621 if (!wilc_wlan_cfg_set(0, WID_WEP_KEY_VALUE, c_val, (strlen(c_val) + 1), 0, 0))
622 goto _fail_;
623
624 strcpy(c_val, "12345678");
625 if (!wilc_wlan_cfg_set(0, WID_11I_PSK, c_val, (strlen(c_val)), 0, 0))
626 goto _fail_;
627
628 strcpy(c_val, "password");
629 if (!wilc_wlan_cfg_set(0, WID_1X_KEY, c_val, (strlen(c_val) + 1), 0, 0))
630 goto _fail_;
631
632 c_val[0] = 192;
633 c_val[1] = 168;
634 c_val[2] = 1;
635 c_val[3] = 112;
636 if (!wilc_wlan_cfg_set(0, WID_1X_SERV_ADDR, c_val, 4, 0, 0))
637 goto _fail_;
638
639 c_val[0] = 3;
640 if (!wilc_wlan_cfg_set(0, WID_LISTEN_INTERVAL, c_val, 1, 0, 0))
641 goto _fail_;
642
643 c_val[0] = 3;
644 if (!wilc_wlan_cfg_set(0, WID_DTIM_PERIOD, c_val, 1, 0, 0))
645 goto _fail_;
646
647 c_val[0] = NORMAL_ACK;
648 if (!wilc_wlan_cfg_set(0, WID_ACK_POLICY, c_val, 1, 0, 0))
649 goto _fail_;
650
651 c_val[0] = 0;
652 if (!wilc_wlan_cfg_set(0, WID_USER_CONTROL_ON_TX_POWER, c_val, 1, 0, 0))
653 goto _fail_;
654
655 c_val[0] = 48;
656 if (!wilc_wlan_cfg_set(0, WID_TX_POWER_LEVEL_11A, c_val, 1, 0, 0))
657 goto _fail_;
658
659 c_val[0] = 28;
660 if (!wilc_wlan_cfg_set(0, WID_TX_POWER_LEVEL_11B, c_val, 1, 0, 0))
661 goto _fail_;
662
663 *((int *)c_val) = 100;
664 if (!wilc_wlan_cfg_set(0, WID_BEACON_INTERVAL, c_val, 2, 0, 0))
665 goto _fail_;
666
667 c_val[0] = REKEY_DISABLE;
668 if (!wilc_wlan_cfg_set(0, WID_REKEY_POLICY, c_val, 1, 0, 0))
669 goto _fail_;
670
671 *((int *)c_val) = 84600;
672 if (!wilc_wlan_cfg_set(0, WID_REKEY_PERIOD, c_val, 4, 0, 0))
673 goto _fail_;
674
675 *((int *)c_val) = 500;
676 if (!wilc_wlan_cfg_set(0, WID_REKEY_PACKET_COUNT, c_val, 4, 0, 0))
677 goto _fail_;
678
679 c_val[0] = 1;
680 if (!wilc_wlan_cfg_set(0, WID_SHORT_SLOT_ALLOWED, c_val, 1, 0, 0))
681 goto _fail_;
682
683 c_val[0] = G_SELF_CTS_PROT;
684 if (!wilc_wlan_cfg_set(0, WID_11N_ERP_PROT_TYPE, c_val, 1, 0, 0))
685 goto _fail_;
686
687 c_val[0] = 1;
688 if (!wilc_wlan_cfg_set(0, WID_11N_ENABLE, c_val, 1, 0, 0))
689 goto _fail_;
690
691 c_val[0] = HT_MIXED_MODE;
692 if (!wilc_wlan_cfg_set(0, WID_11N_OPERATING_MODE, c_val, 1, 0, 0))
693 goto _fail_;
694
695 c_val[0] = 1;
696 if (!wilc_wlan_cfg_set(0, WID_11N_TXOP_PROT_DISABLE, c_val, 1, 0, 0))
697 goto _fail_;
698
699 memcpy(c_val, mac_add, 6);
700
701 if (!wilc_wlan_cfg_set(0, WID_MAC_ADDR, c_val, 6, 0, 0))
702 goto _fail_;
703
704 c_val[0] = DETECT_PROTECT_REPORT;
705 if (!wilc_wlan_cfg_set(0, WID_11N_OBSS_NONHT_DETECTION, c_val, 1, 0, 0))
706 goto _fail_;
707
708 c_val[0] = RTS_CTS_NONHT_PROT;
709 if (!wilc_wlan_cfg_set(0, WID_11N_HT_PROT_TYPE, c_val, 1, 0, 0))
710 goto _fail_;
711
712 c_val[0] = 0;
713 if (!wilc_wlan_cfg_set(0, WID_11N_RIFS_PROT_ENABLE, c_val, 1, 0, 0))
714 goto _fail_;
715
716 c_val[0] = MIMO_MODE;
717 if (!wilc_wlan_cfg_set(0, WID_11N_SMPS_MODE, c_val, 1, 0, 0))
718 goto _fail_;
719
720 c_val[0] = 7;
721 if (!wilc_wlan_cfg_set(0, WID_11N_CURRENT_TX_MCS, c_val, 1, 0, 0))
722 goto _fail_;
723
724 c_val[0] = 1;
725 if (!wilc_wlan_cfg_set(0, WID_11N_IMMEDIATE_BA_ENABLED, c_val, 1, 1, 1))
726 goto _fail_;
727
728 return 0;
729
730 _fail_:
731 return -1;
732 }
733
734 void wilc1000_wlan_deinit(struct net_device *dev)
735 {
736 perInterface_wlan_t *nic;
737 struct wilc *wl;
738
739 nic = netdev_priv(dev);
740 wl = nic->wilc;
741
742 if (!wl) {
743 netdev_err(dev, "wl is NULL\n");
744 return;
745 }
746
747 if (wl->initialized) {
748 netdev_info(dev, "Deinitializing wilc1000...\n");
749
750 #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
751 PRINT_D(INIT_DBG, "skip wilc_bus_set_default_speed\n");
752 #else
753 wilc_bus_set_default_speed();
754 #endif
755
756 PRINT_D(INIT_DBG, "Disabling IRQ\n");
757 #ifdef WILC_SDIO
758 mutex_lock(&wl->hif_cs);
759 wilc_sdio_disable_interrupt();
760 mutex_unlock(&wl->hif_cs);
761 #endif
762 if (&wl->txq_event)
763 up(&wl->txq_event);
764
765 PRINT_D(INIT_DBG, "Deinitializing Threads\n");
766 wlan_deinitialize_threads(dev);
767
768 PRINT_D(INIT_DBG, "Deinitializing IRQ\n");
769 deinit_irq(dev);
770
771 wilc_wlan_stop();
772
773 PRINT_D(INIT_DBG, "Deinitializing WILC Wlan\n");
774 wilc_wlan_cleanup(dev);
775 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
776 #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
777 PRINT_D(INIT_DBG, "Disabling IRQ 2\n");
778
779 mutex_lock(&wl->hif_cs);
780 wilc_sdio_disable_interrupt();
781 mutex_unlock(&wl->hif_cs);
782 #endif
783 #endif
784
785 PRINT_D(INIT_DBG, "Deinitializing Locks\n");
786 wlan_deinit_locks(dev);
787
788 wl->initialized = false;
789
790 PRINT_D(INIT_DBG, "wilc1000 deinitialization Done\n");
791
792 } else {
793 PRINT_D(INIT_DBG, "wilc1000 is not initialized\n");
794 }
795 }
796
797 static int wlan_init_locks(struct net_device *dev)
798 {
799 perInterface_wlan_t *nic;
800 struct wilc *wl;
801
802 nic = netdev_priv(dev);
803 wl = nic->wilc;
804
805 PRINT_D(INIT_DBG, "Initializing Locks ...\n");
806
807 mutex_init(&wl->hif_cs);
808 mutex_init(&wl->rxq_cs);
809
810 spin_lock_init(&wl->txq_spinlock);
811 sema_init(&wl->txq_add_to_head_cs, 1);
812
813 sema_init(&wl->txq_event, 0);
814
815 sema_init(&wl->cfg_event, 0);
816 sema_init(&wl->sync_event, 0);
817
818 sema_init(&wl->txq_thread_started, 0);
819
820 return 0;
821 }
822
823 static int wlan_deinit_locks(struct net_device *dev)
824 {
825 perInterface_wlan_t *nic;
826 struct wilc *wilc;
827
828 nic = netdev_priv(dev);
829 wilc = nic->wilc;
830
831 PRINT_D(INIT_DBG, "De-Initializing Locks\n");
832
833 if (&wilc->hif_cs)
834 mutex_destroy(&wilc->hif_cs);
835
836 if (&wilc->rxq_cs)
837 mutex_destroy(&wilc->rxq_cs);
838
839 return 0;
840 }
841
842 static int wlan_initialize_threads(struct net_device *dev)
843 {
844 perInterface_wlan_t *nic;
845 struct wilc *wilc;
846
847 nic = netdev_priv(dev);
848 wilc = nic->wilc;
849
850 PRINT_D(INIT_DBG, "Initializing Threads ...\n");
851 PRINT_D(INIT_DBG, "Creating kthread for transmission\n");
852 wilc->txq_thread = kthread_run(linux_wlan_txq_task, (void *)dev,
853 "K_TXQ_TASK");
854 if (!wilc->txq_thread) {
855 PRINT_ER("couldn't create TXQ thread\n");
856 wilc->close = 0;
857 return -ENOBUFS;
858 }
859 down(&wilc->txq_thread_started);
860
861 return 0;
862 }
863
864 static void wlan_deinitialize_threads(struct net_device *dev)
865 {
866 perInterface_wlan_t *nic;
867 struct wilc *wl;
868 nic = netdev_priv(dev);
869 wl = nic->wilc;
870
871 wl->close = 1;
872 PRINT_D(INIT_DBG, "Deinitializing Threads\n");
873
874 if (&wl->txq_event)
875 up(&wl->txq_event);
876
877 if (wl->txq_thread) {
878 kthread_stop(wl->txq_thread);
879 wl->txq_thread = NULL;
880 }
881 }
882
883 int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic)
884 {
885 perInterface_wlan_t *nic = p_nic;
886 int ret = 0;
887 struct wilc *wl = nic->wilc;
888
889 if (!wl->initialized) {
890 wl->mac_status = WILC_MAC_STATUS_INIT;
891 wl->close = 0;
892
893 wlan_init_locks(dev);
894
895 #ifdef WILC_SDIO
896 wl->io_type = HIF_SDIO;
897 #else
898 wl->io_type = HIF_SPI;
899 #endif
900 ret = wilc_wlan_init(dev);
901 if (ret < 0) {
902 PRINT_ER("Initializing WILC_Wlan FAILED\n");
903 ret = -EIO;
904 goto _fail_locks_;
905 }
906
907 #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
908 if (init_irq(dev)) {
909 PRINT_ER("couldn't initialize IRQ\n");
910 ret = -EIO;
911 goto _fail_locks_;
912 }
913 #endif
914
915 ret = wlan_initialize_threads(dev);
916 if (ret < 0) {
917 PRINT_ER("Initializing Threads FAILED\n");
918 ret = -EIO;
919 goto _fail_wilc_wlan_;
920 }
921
922 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
923 if (wilc_sdio_enable_interrupt()) {
924 PRINT_ER("couldn't initialize IRQ\n");
925 ret = -EIO;
926 goto _fail_irq_init_;
927 }
928 #endif
929
930 if (wilc_wlan_get_firmware(dev)) {
931 PRINT_ER("Can't get firmware\n");
932 ret = -EIO;
933 goto _fail_irq_enable_;
934 }
935
936 ret = linux_wlan_firmware_download(dev);
937 if (ret < 0) {
938 PRINT_ER("Failed to download firmware\n");
939 ret = -EIO;
940 goto _fail_irq_enable_;
941 }
942
943 ret = linux_wlan_start_firmware(dev);
944 if (ret < 0) {
945 PRINT_ER("Failed to start firmware\n");
946 ret = -EIO;
947 goto _fail_irq_enable_;
948 }
949
950 wilc_bus_set_max_speed();
951
952 if (wilc_wlan_cfg_get(1, WID_FIRMWARE_VERSION, 1, 0)) {
953 int size;
954 char Firmware_ver[20];
955
956 size = wilc_wlan_cfg_get_val(
957 WID_FIRMWARE_VERSION,
958 Firmware_ver, sizeof(Firmware_ver));
959 Firmware_ver[size] = '\0';
960 PRINT_D(INIT_DBG, "***** Firmware Ver = %s *******\n", Firmware_ver);
961 }
962 ret = linux_wlan_init_test_config(dev, wl);
963
964 if (ret < 0) {
965 PRINT_ER("Failed to configure firmware\n");
966 ret = -EIO;
967 goto _fail_fw_start_;
968 }
969
970 wl->initialized = true;
971 return 0;
972
973 _fail_fw_start_:
974 wilc_wlan_stop();
975
976 _fail_irq_enable_:
977 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
978 wilc_sdio_disable_interrupt();
979 _fail_irq_init_:
980 #endif
981 #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
982 deinit_irq(dev);
983
984 #endif
985 wlan_deinitialize_threads(dev);
986 _fail_wilc_wlan_:
987 wilc_wlan_cleanup(dev);
988 _fail_locks_:
989 wlan_deinit_locks(dev);
990 PRINT_ER("WLAN Iinitialization FAILED\n");
991 } else {
992 PRINT_D(INIT_DBG, "wilc1000 already initialized\n");
993 }
994 return ret;
995 }
996
997 static int mac_init_fn(struct net_device *ndev)
998 {
999 netif_start_queue(ndev);
1000 netif_stop_queue(ndev);
1001
1002 return 0;
1003 }
1004
1005 int wilc_mac_open(struct net_device *ndev)
1006 {
1007 perInterface_wlan_t *nic;
1008
1009 unsigned char mac_add[ETH_ALEN] = {0};
1010 int ret = 0;
1011 int i = 0;
1012 struct wilc_priv *priv;
1013 struct wilc *wl;
1014
1015 nic = netdev_priv(ndev);
1016 wl = nic->wilc;
1017
1018 #ifdef WILC_SPI
1019 if (!wl || !wl->wilc_spidev) {
1020 netdev_err(ndev, "wilc1000: SPI device not ready\n");
1021 return -ENODEV;
1022 }
1023 #endif
1024 nic = netdev_priv(ndev);
1025 priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy);
1026 PRINT_D(INIT_DBG, "MAC OPEN[%p]\n", ndev);
1027
1028 ret = wilc_init_host_int(ndev);
1029 if (ret < 0) {
1030 PRINT_ER("Failed to initialize host interface\n");
1031
1032 return ret;
1033 }
1034
1035 PRINT_D(INIT_DBG, "*** re-init ***\n");
1036 ret = wilc1000_wlan_init(ndev, nic);
1037 if (ret < 0) {
1038 PRINT_ER("Failed to initialize wilc1000\n");
1039 wilc_deinit_host_int(ndev);
1040 return ret;
1041 }
1042
1043 wilc_set_machw_change_vir_if(ndev, false);
1044
1045 wilc_get_mac_address(priv->hWILCWFIDrv, mac_add);
1046 PRINT_D(INIT_DBG, "Mac address: %pM\n", mac_add);
1047
1048 for (i = 0; i < wl->vif_num; i++) {
1049 if (ndev == wl->vif[i].ndev) {
1050 memcpy(wl->vif[i].src_addr, mac_add, ETH_ALEN);
1051 wl->vif[i].hif_drv = priv->hWILCWFIDrv;
1052 break;
1053 }
1054 }
1055
1056 memcpy(ndev->dev_addr, wl->vif[i].src_addr, ETH_ALEN);
1057
1058 if (!is_valid_ether_addr(ndev->dev_addr)) {
1059 PRINT_ER("Error: Wrong MAC address\n");
1060 wilc_deinit_host_int(ndev);
1061 wilc1000_wlan_deinit(ndev);
1062 return -EINVAL;
1063 }
1064
1065 wilc_mgmt_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy,
1066 nic->wilc_netdev->ieee80211_ptr,
1067 nic->g_struct_frame_reg[0].frame_type,
1068 nic->g_struct_frame_reg[0].reg);
1069 wilc_mgmt_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy,
1070 nic->wilc_netdev->ieee80211_ptr,
1071 nic->g_struct_frame_reg[1].frame_type,
1072 nic->g_struct_frame_reg[1].reg);
1073 netif_wake_queue(ndev);
1074 wl->open_ifcs++;
1075 nic->mac_opened = 1;
1076 return 0;
1077 }
1078
1079 static struct net_device_stats *mac_stats(struct net_device *dev)
1080 {
1081 perInterface_wlan_t *nic = netdev_priv(dev);
1082
1083 return &nic->netstats;
1084 }
1085
1086 static void wilc_set_multicast_list(struct net_device *dev)
1087 {
1088 struct netdev_hw_addr *ha;
1089 struct wilc_priv *priv;
1090 struct host_if_drv *hif_drv;
1091 int i = 0;
1092
1093 priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
1094 hif_drv = (struct host_if_drv *)priv->hWILCWFIDrv;
1095
1096 if (!dev)
1097 return;
1098
1099 PRINT_D(INIT_DBG, "Setting Multicast List with count = %d.\n",
1100 dev->mc.count);
1101
1102 if (dev->flags & IFF_PROMISC) {
1103 PRINT_D(INIT_DBG, "Set promiscuous mode ON, retrive all packets\n");
1104 return;
1105 }
1106
1107 if ((dev->flags & IFF_ALLMULTI) ||
1108 (dev->mc.count) > WILC_MULTICAST_TABLE_SIZE) {
1109 PRINT_D(INIT_DBG, "Disable multicast filter, retrive all multicast packets\n");
1110 wilc_setup_multicast_filter(hif_drv, false, 0);
1111 return;
1112 }
1113
1114 if ((dev->mc.count) == 0) {
1115 PRINT_D(INIT_DBG, "Enable multicast filter, retrive directed packets only.\n");
1116 wilc_setup_multicast_filter(hif_drv, true, 0);
1117 return;
1118 }
1119
1120 netdev_for_each_mc_addr(ha, dev) {
1121 memcpy(wilc_multicast_mac_addr_list[i], ha->addr, ETH_ALEN);
1122 PRINT_D(INIT_DBG, "Entry[%d]: %x:%x:%x:%x:%x:%x\n", i,
1123 wilc_multicast_mac_addr_list[i][0],
1124 wilc_multicast_mac_addr_list[i][1],
1125 wilc_multicast_mac_addr_list[i][2],
1126 wilc_multicast_mac_addr_list[i][3],
1127 wilc_multicast_mac_addr_list[i][4],
1128 wilc_multicast_mac_addr_list[i][5]);
1129 i++;
1130 }
1131
1132 wilc_setup_multicast_filter(hif_drv, true, (dev->mc.count));
1133
1134 return;
1135 }
1136
1137 static void linux_wlan_tx_complete(void *priv, int status)
1138 {
1139 struct tx_complete_data *pv_data = (struct tx_complete_data *)priv;
1140
1141 if (status == 1)
1142 PRINT_D(TX_DBG, "Packet sent successfully - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb);
1143 else
1144 PRINT_D(TX_DBG, "Couldn't send packet - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb);
1145 dev_kfree_skb(pv_data->skb);
1146 kfree(pv_data);
1147 }
1148
1149 int wilc_mac_xmit(struct sk_buff *skb, struct net_device *ndev)
1150 {
1151 perInterface_wlan_t *nic;
1152 struct tx_complete_data *tx_data = NULL;
1153 int queue_count;
1154 char *udp_buf;
1155 struct iphdr *ih;
1156 struct ethhdr *eth_h;
1157 struct wilc *wilc;
1158
1159 nic = netdev_priv(ndev);
1160 wilc = nic->wilc;
1161
1162 PRINT_D(TX_DBG, "Sending packet just received from TCP/IP\n");
1163
1164 if (skb->dev != ndev) {
1165 PRINT_ER("Packet not destined to this device\n");
1166 return 0;
1167 }
1168
1169 tx_data = kmalloc(sizeof(*tx_data), GFP_ATOMIC);
1170 if (!tx_data) {
1171 PRINT_ER("Failed to allocate memory for tx_data structure\n");
1172 dev_kfree_skb(skb);
1173 netif_wake_queue(ndev);
1174 return 0;
1175 }
1176
1177 tx_data->buff = skb->data;
1178 tx_data->size = skb->len;
1179 tx_data->skb = skb;
1180
1181 eth_h = (struct ethhdr *)(skb->data);
1182 if (eth_h->h_proto == 0x8e88)
1183 PRINT_D(INIT_DBG, "EAPOL transmitted\n");
1184
1185 ih = (struct iphdr *)(skb->data + sizeof(struct ethhdr));
1186
1187 udp_buf = (char *)ih + sizeof(struct iphdr);
1188 if ((udp_buf[1] == 68 && udp_buf[3] == 67) ||
1189 (udp_buf[1] == 67 && udp_buf[3] == 68))
1190 PRINT_D(GENERIC_DBG, "DHCP Message transmitted, type:%x %x %x\n",
1191 udp_buf[248], udp_buf[249], udp_buf[250]);
1192
1193 PRINT_D(TX_DBG, "Sending packet - Size = %d - Address = %p - SKB = %p\n", tx_data->size, tx_data->buff, tx_data->skb);
1194 PRINT_D(TX_DBG, "Adding tx packet to TX Queue\n");
1195 nic->netstats.tx_packets++;
1196 nic->netstats.tx_bytes += tx_data->size;
1197 tx_data->pBssid = wilc->vif[nic->u8IfIdx].bssid;
1198 queue_count = wilc_wlan_txq_add_net_pkt(ndev, (void *)tx_data,
1199 tx_data->buff, tx_data->size,
1200 linux_wlan_tx_complete);
1201
1202 if (queue_count > FLOW_CONTROL_UPPER_THRESHOLD) {
1203 netif_stop_queue(wilc->vif[0].ndev);
1204 netif_stop_queue(wilc->vif[1].ndev);
1205 }
1206
1207 return 0;
1208 }
1209
1210 int wilc_mac_close(struct net_device *ndev)
1211 {
1212 struct wilc_priv *priv;
1213 perInterface_wlan_t *nic;
1214 struct host_if_drv *hif_drv;
1215 struct wilc *wl;
1216
1217 nic = netdev_priv(ndev);
1218
1219 if (!nic || !nic->wilc_netdev || !nic->wilc_netdev->ieee80211_ptr ||
1220 !nic->wilc_netdev->ieee80211_ptr->wiphy) {
1221 PRINT_ER("nic = NULL\n");
1222 return 0;
1223 }
1224
1225 priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy);
1226 wl = nic->wilc;
1227
1228 if (!priv) {
1229 PRINT_ER("priv = NULL\n");
1230 return 0;
1231 }
1232
1233 hif_drv = (struct host_if_drv *)priv->hWILCWFIDrv;
1234
1235 PRINT_D(GENERIC_DBG, "Mac close\n");
1236
1237 if (!wl) {
1238 PRINT_ER("wl = NULL\n");
1239 return 0;
1240 }
1241
1242 if (!hif_drv) {
1243 PRINT_ER("hif_drv = NULL\n");
1244 return 0;
1245 }
1246
1247 if ((wl->open_ifcs) > 0) {
1248 wl->open_ifcs--;
1249 } else {
1250 PRINT_ER("ERROR: MAC close called while number of opened interfaces is zero\n");
1251 return 0;
1252 }
1253
1254 if (nic->wilc_netdev) {
1255 netif_stop_queue(nic->wilc_netdev);
1256
1257 wilc_deinit_host_int(nic->wilc_netdev);
1258 }
1259
1260 if (wl->open_ifcs == 0) {
1261 PRINT_D(GENERIC_DBG, "Deinitializing wilc1000\n");
1262 wl->close = 1;
1263 wilc1000_wlan_deinit(ndev);
1264 WILC_WFI_deinit_mon_interface();
1265 }
1266
1267 up(&close_exit_sync);
1268 nic->mac_opened = 0;
1269
1270 return 0;
1271 }
1272
1273 static int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
1274 {
1275 u8 *buff = NULL;
1276 s8 rssi;
1277 u32 size = 0, length = 0;
1278 perInterface_wlan_t *nic;
1279 struct wilc_priv *priv;
1280 s32 ret = 0;
1281 struct wilc *wilc;
1282
1283 nic = netdev_priv(ndev);
1284 wilc = nic->wilc;
1285
1286 if (!wilc->initialized)
1287 return 0;
1288
1289 switch (cmd) {
1290 case SIOCSIWPRIV:
1291 {
1292 struct iwreq *wrq = (struct iwreq *) req;
1293
1294 size = wrq->u.data.length;
1295
1296 if (size && wrq->u.data.pointer) {
1297 buff = memdup_user(wrq->u.data.pointer,
1298 wrq->u.data.length);
1299 if (IS_ERR(buff))
1300 return PTR_ERR(buff);
1301
1302 if (strncasecmp(buff, "RSSI", length) == 0) {
1303 priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy);
1304 ret = wilc_get_rssi(priv->hWILCWFIDrv, &rssi);
1305 if (ret)
1306 PRINT_ER("Failed to send get rssi param's message queue ");
1307 PRINT_INFO(GENERIC_DBG, "RSSI :%d\n", rssi);
1308
1309 rssi += 5;
1310
1311 snprintf(buff, size, "rssi %d", rssi);
1312
1313 if (copy_to_user(wrq->u.data.pointer, buff, size)) {
1314 PRINT_ER("%s: failed to copy data to user buffer\n", __func__);
1315 ret = -EFAULT;
1316 goto done;
1317 }
1318 }
1319 }
1320 }
1321 break;
1322
1323 default:
1324 {
1325 PRINT_INFO(GENERIC_DBG, "Command - %d - has been received\n", cmd);
1326 ret = -EOPNOTSUPP;
1327 goto done;
1328 }
1329 }
1330
1331 done:
1332
1333 kfree(buff);
1334
1335 return ret;
1336 }
1337
1338 void frmw_to_linux(struct wilc *wilc, u8 *buff, u32 size, u32 pkt_offset)
1339 {
1340 unsigned int frame_len = 0;
1341 int stats;
1342 unsigned char *buff_to_send = NULL;
1343 struct sk_buff *skb;
1344 struct net_device *wilc_netdev;
1345 perInterface_wlan_t *nic;
1346
1347 wilc_netdev = get_if_handler(wilc, buff);
1348 if (!wilc_netdev)
1349 return;
1350
1351 buff += pkt_offset;
1352 nic = netdev_priv(wilc_netdev);
1353
1354 if (size > 0) {
1355 frame_len = size;
1356 buff_to_send = buff;
1357
1358 skb = dev_alloc_skb(frame_len);
1359 if (!skb) {
1360 PRINT_ER("Low memory - packet droped\n");
1361 return;
1362 }
1363
1364 if (!wilc || !wilc_netdev)
1365 PRINT_ER("wilc_netdev in wilc is NULL");
1366 skb->dev = wilc_netdev;
1367
1368 if (!skb->dev)
1369 PRINT_ER("skb->dev is NULL\n");
1370
1371 memcpy(skb_put(skb, frame_len), buff_to_send, frame_len);
1372
1373 skb->protocol = eth_type_trans(skb, wilc_netdev);
1374 nic->netstats.rx_packets++;
1375 nic->netstats.rx_bytes += frame_len;
1376 skb->ip_summed = CHECKSUM_UNNECESSARY;
1377 stats = netif_rx(skb);
1378 PRINT_D(RX_DBG, "netif_rx ret value is: %d\n", stats);
1379 }
1380 }
1381
1382 void WILC_WFI_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size)
1383 {
1384 int i = 0;
1385 perInterface_wlan_t *nic;
1386
1387 for (i = 0; i < wilc->vif_num; i++) {
1388 nic = netdev_priv(wilc->vif[i].ndev);
1389 if (nic->monitor_flag) {
1390 WILC_WFI_monitor_rx(buff, size);
1391 return;
1392 }
1393 }
1394
1395 nic = netdev_priv(wilc->vif[1].ndev);
1396 if ((buff[0] == nic->g_struct_frame_reg[0].frame_type && nic->g_struct_frame_reg[0].reg) ||
1397 (buff[0] == nic->g_struct_frame_reg[1].frame_type && nic->g_struct_frame_reg[1].reg))
1398 WILC_WFI_p2p_rx(wilc->vif[1].ndev, buff, size);
1399 }
1400
1401 void wilc_netdev_cleanup(struct wilc *wilc)
1402 {
1403 int i = 0;
1404 perInterface_wlan_t *nic[NUM_CONCURRENT_IFC];
1405
1406 if (wilc && (wilc->vif[0].ndev || wilc->vif[1].ndev)) {
1407 unregister_inetaddr_notifier(&g_dev_notifier);
1408
1409 for (i = 0; i < NUM_CONCURRENT_IFC; i++)
1410 nic[i] = netdev_priv(wilc->vif[i].ndev);
1411 }
1412
1413 if (wilc && wilc->firmware)
1414 release_firmware(wilc->firmware);
1415
1416 if (wilc && (wilc->vif[0].ndev || wilc->vif[1].ndev)) {
1417 linux_wlan_lock_timeout(&close_exit_sync, 12 * 1000);
1418
1419 for (i = 0; i < NUM_CONCURRENT_IFC; i++)
1420 if (wilc->vif[i].ndev)
1421 if (nic[i]->mac_opened)
1422 wilc_mac_close(wilc->vif[i].ndev);
1423
1424 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
1425 unregister_netdev(wilc->vif[i].ndev);
1426 wilc_free_wiphy(wilc->vif[i].ndev);
1427 free_netdev(wilc->vif[i].ndev);
1428 }
1429 }
1430
1431 kfree(wilc);
1432
1433 #if defined(WILC_DEBUGFS)
1434 wilc_debugfs_remove();
1435 #endif
1436 }
1437
1438 int wilc_netdev_init(struct wilc **wilc)
1439 {
1440 int i;
1441 perInterface_wlan_t *nic;
1442 struct net_device *ndev;
1443
1444 sema_init(&close_exit_sync, 0);
1445
1446 wilc_dev = kzalloc(sizeof(*wilc_dev), GFP_KERNEL);
1447 if (!wilc_dev)
1448 return -ENOMEM;
1449
1450 *wilc = wilc_dev;
1451
1452 register_inetaddr_notifier(&g_dev_notifier);
1453
1454 for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
1455 ndev = alloc_etherdev(sizeof(perInterface_wlan_t));
1456 if (!ndev) {
1457 PRINT_ER("Failed to allocate ethernet dev\n");
1458 return -1;
1459 }
1460
1461 nic = netdev_priv(ndev);
1462 memset(nic, 0, sizeof(perInterface_wlan_t));
1463
1464 if (i == 0)
1465 strcpy(ndev->name, "wlan%d");
1466 else
1467 strcpy(ndev->name, "p2p%d");
1468
1469 nic->u8IfIdx = wilc_dev->vif_num;
1470 nic->wilc_netdev = ndev;
1471 nic->wilc = *wilc;
1472 wilc_dev->vif[wilc_dev->vif_num].ndev = ndev;
1473 wilc_dev->vif_num++;
1474 ndev->netdev_ops = &wilc_netdev_ops;
1475
1476 {
1477 struct wireless_dev *wdev;
1478 wdev = wilc_create_wiphy(ndev);
1479
1480 #ifdef WILC_SDIO
1481 SET_NETDEV_DEV(ndev, &wilc_sdio_func->dev);
1482 #endif
1483
1484 if (!wdev) {
1485 PRINT_ER("Can't register WILC Wiphy\n");
1486 return -1;
1487 }
1488
1489 nic->wilc_netdev->ieee80211_ptr = wdev;
1490 nic->wilc_netdev->ml_priv = nic;
1491 wdev->netdev = nic->wilc_netdev;
1492 nic->netstats.rx_packets = 0;
1493 nic->netstats.tx_packets = 0;
1494 nic->netstats.rx_bytes = 0;
1495 nic->netstats.tx_bytes = 0;
1496 }
1497
1498 if (register_netdev(ndev)) {
1499 PRINT_ER("Device couldn't be registered - %s\n",
1500 ndev->name);
1501 return -1;
1502 }
1503
1504 nic->iftype = STATION_MODE;
1505 nic->mac_opened = 0;
1506 }
1507
1508 #ifndef WILC_SDIO
1509 if (!wilc_spi_init()) {
1510 PRINT_ER("Can't initialize SPI\n");
1511 return -1;
1512 }
1513 wilc_dev->wilc_spidev = wilc_spi_dev;
1514 #else
1515 wilc_dev->wilc_sdio_func = wilc_sdio_func;
1516 #endif
1517
1518 return 0;
1519 }
This page took 0.085975 seconds and 4 git commands to generate.