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