staging: brcm80211: remove empty sdrxqlock from fullmac
[deliverable/linux.git] / drivers / staging / brcm80211 / brcmfmac / dhd_linux.c
1 /*
2 * Copyright (c) 2010 Broadcom Corporation
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #ifdef CONFIG_WIFI_CONTROL_FUNC
18 #include <linux/platform_device.h>
19 #endif
20 #include <linux/init.h>
21 #include <linux/kernel.h>
22 #include <linux/kthread.h>
23 #include <linux/slab.h>
24 #include <linux/skbuff.h>
25 #include <linux/netdevice.h>
26 #include <linux/etherdevice.h>
27 #include <linux/mmc/sdio_func.h>
28 #include <linux/random.h>
29 #include <linux/spinlock.h>
30 #include <linux/ethtool.h>
31 #include <linux/fcntl.h>
32 #include <linux/fs.h>
33 #include <linux/uaccess.h>
34 #include <net/cfg80211.h>
35 #include <defs.h>
36 #include <brcmu_utils.h>
37 #include <brcmu_wifi.h>
38
39 #include "dngl_stats.h"
40 #include "dhd.h"
41 #include "dhd_bus.h"
42 #include "dhd_proto.h"
43 #include "dhd_dbg.h"
44 #include "wl_cfg80211.h"
45
46 #define EPI_VERSION_STR "4.218.248.5"
47 #define ETH_P_BRCM 0x886c
48
49 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
50 #include <linux/wifi_tiwlan.h>
51
52 struct semaphore wifi_control_sem;
53
54 struct dhd_bus *g_bus;
55
56 static struct wifi_platform_data *wifi_control_data;
57 static struct resource *wifi_irqres;
58
59 int wifi_get_irq_number(unsigned long *irq_flags_ptr)
60 {
61 if (wifi_irqres) {
62 *irq_flags_ptr = wifi_irqres->flags & IRQF_TRIGGER_MASK;
63 return (int)wifi_irqres->start;
64 }
65 #ifdef CUSTOM_OOB_GPIO_NUM
66 return CUSTOM_OOB_GPIO_NUM;
67 #else
68 return -1;
69 #endif
70 }
71
72 int wifi_set_carddetect(int on)
73 {
74 printk(KERN_ERR "%s = %d\n", __func__, on);
75 if (wifi_control_data && wifi_control_data->set_carddetect)
76 wifi_control_data->set_carddetect(on);
77 return 0;
78 }
79
80 int wifi_set_power(int on, unsigned long msec)
81 {
82 printk(KERN_ERR "%s = %d\n", __func__, on);
83 if (wifi_control_data && wifi_control_data->set_power)
84 wifi_control_data->set_power(on);
85 if (msec)
86 mdelay(msec);
87 return 0;
88 }
89
90 int wifi_set_reset(int on, unsigned long msec)
91 {
92 printk(KERN_ERR "%s = %d\n", __func__, on);
93 if (wifi_control_data && wifi_control_data->set_reset)
94 wifi_control_data->set_reset(on);
95 if (msec)
96 mdelay(msec);
97 return 0;
98 }
99
100 static int wifi_probe(struct platform_device *pdev)
101 {
102 struct wifi_platform_data *wifi_ctrl =
103 (struct wifi_platform_data *)(pdev->dev.platform_data);
104
105 printk(KERN_ERR "## %s\n", __func__);
106 wifi_irqres =
107 platform_get_resource_byname(pdev, IORESOURCE_IRQ,
108 "bcm4329_wlan_irq");
109 wifi_control_data = wifi_ctrl;
110
111 wifi_set_power(1, 0); /* Power On */
112 wifi_set_carddetect(1); /* CardDetect (0->1) */
113
114 up(&wifi_control_sem);
115 return 0;
116 }
117
118 static int wifi_remove(struct platform_device *pdev)
119 {
120 struct wifi_platform_data *wifi_ctrl =
121 (struct wifi_platform_data *)(pdev->dev.platform_data);
122
123 printk(KERN_ERR "## %s\n", __func__);
124 wifi_control_data = wifi_ctrl;
125
126 wifi_set_carddetect(0); /* CardDetect (1->0) */
127 wifi_set_power(0, 0); /* Power Off */
128
129 up(&wifi_control_sem);
130 return 0;
131 }
132
133 static int wifi_suspend(struct platform_device *pdev, pm_message_t state)
134 {
135 DHD_TRACE(("##> %s\n", __func__));
136 return 0;
137 }
138
139 static int wifi_resume(struct platform_device *pdev)
140 {
141 DHD_TRACE(("##> %s\n", __func__));
142 return 0;
143 }
144
145 static struct platform_driver wifi_device = {
146 .probe = wifi_probe,
147 .remove = wifi_remove,
148 .suspend = wifi_suspend,
149 .resume = wifi_resume,
150 .driver = {
151 .name = KBUILD_MODNAME,
152 }
153 };
154
155 int wifi_add_dev(void)
156 {
157 DHD_TRACE(("## Calling platform_driver_register\n"));
158 return platform_driver_register(&wifi_device);
159 }
160
161 void wifi_del_dev(void)
162 {
163 DHD_TRACE(("## Unregister platform_driver_register\n"));
164 platform_driver_unregister(&wifi_device);
165 }
166 #endif /* defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
167
168 #if defined(CONFIG_PM_SLEEP)
169 #include <linux/suspend.h>
170 atomic_t dhd_mmc_suspend;
171 DECLARE_WAIT_QUEUE_HEAD(dhd_dpc_wait);
172 #endif /* defined(CONFIG_PM_SLEEP) */
173
174 #if defined(OOB_INTR_ONLY)
175 extern void dhd_enable_oob_intr(struct dhd_bus *bus, bool enable);
176 #endif /* defined(OOB_INTR_ONLY) */
177
178 MODULE_AUTHOR("Broadcom Corporation");
179 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN fullmac driver.");
180 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN fullmac cards");
181 MODULE_LICENSE("Dual BSD/GPL");
182
183 #define DRV_MODULE_NAME "brcmfmac"
184
185 /* Linux wireless extension support */
186 #if defined(CONFIG_WIRELESS_EXT)
187 #include <wl_iw.h>
188 extern wl_iw_extra_params_t g_wl_iw_params;
189 #endif /* defined(CONFIG_WIRELESS_EXT) */
190
191 #if defined(CONFIG_HAS_EARLYSUSPEND)
192 #include <linux/earlysuspend.h>
193 extern int dhdcdc_set_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf,
194 uint len);
195 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
196
197 #ifdef PKT_FILTER_SUPPORT
198 extern void dhd_pktfilter_offload_set(dhd_pub_t *dhd, char *arg);
199 extern void dhd_pktfilter_offload_enable(dhd_pub_t *dhd, char *arg, int enable,
200 int master_mode);
201 #endif
202
203 /* Interface control information */
204 typedef struct dhd_if {
205 struct dhd_info *info; /* back pointer to dhd_info */
206 /* OS/stack specifics */
207 struct net_device *net;
208 struct net_device_stats stats;
209 int idx; /* iface idx in dongle */
210 int state; /* interface state */
211 uint subunit; /* subunit */
212 u8 mac_addr[ETH_ALEN]; /* assigned MAC address */
213 bool attached; /* Delayed attachment when unset */
214 bool txflowcontrol; /* Per interface flow control indicator */
215 char name[IFNAMSIZ]; /* linux interface name */
216 } dhd_if_t;
217
218 /* Local private structure (extension of pub) */
219 typedef struct dhd_info {
220 #if defined(CONFIG_WIRELESS_EXT)
221 wl_iw_t iw; /* wireless extensions state (must be first) */
222 #endif /* defined(CONFIG_WIRELESS_EXT) */
223
224 dhd_pub_t pub;
225
226 /* OS/stack specifics */
227 dhd_if_t *iflist[DHD_MAX_IFS];
228
229 struct semaphore proto_sem;
230 wait_queue_head_t ioctl_resp_wait;
231 struct timer_list timer;
232 bool wd_timer_valid;
233 struct tasklet_struct tasklet;
234 spinlock_t sdlock;
235 spinlock_t txqlock;
236 /* Thread based operation */
237 bool threads_only;
238 struct semaphore sdsem;
239 struct task_struct *watchdog_tsk;
240 struct semaphore watchdog_sem;
241 struct task_struct *dpc_tsk;
242 struct semaphore dpc_sem;
243
244 /* Thread to issue ioctl for multicast */
245 struct task_struct *sysioc_tsk;
246 struct semaphore sysioc_sem;
247 bool set_multicast;
248 bool set_macaddress;
249 u8 macvalue[ETH_ALEN];
250 wait_queue_head_t ctrl_wait;
251 atomic_t pend_8021x_cnt;
252
253 #ifdef CONFIG_HAS_EARLYSUSPEND
254 struct early_suspend early_suspend;
255 #endif /* CONFIG_HAS_EARLYSUSPEND */
256 } dhd_info_t;
257
258 /* Definitions to provide path to the firmware and nvram
259 * example nvram_path[MOD_PARAM_PATHLEN]="/projects/wlan/nvram.txt"
260 */
261 char firmware_path[MOD_PARAM_PATHLEN];
262 char nvram_path[MOD_PARAM_PATHLEN];
263
264 /* load firmware and/or nvram values from the filesystem */
265 module_param_string(firmware_path, firmware_path, MOD_PARAM_PATHLEN, 0);
266 module_param_string(nvram_path, nvram_path, MOD_PARAM_PATHLEN, 0);
267
268 /* Error bits */
269 module_param(dhd_msg_level, int, 0);
270
271 /* Spawn a thread for system ioctls (set mac, set mcast) */
272 uint dhd_sysioc = true;
273 module_param(dhd_sysioc, uint, 0);
274
275 /* Watchdog interval */
276 uint dhd_watchdog_ms = 10;
277 module_param(dhd_watchdog_ms, uint, 0);
278
279 #ifdef DHD_DEBUG
280 /* Console poll interval */
281 uint dhd_console_ms;
282 module_param(dhd_console_ms, uint, 0);
283 #endif /* DHD_DEBUG */
284
285 /* ARP offload agent mode : Enable ARP Host Auto-Reply
286 and ARP Peer Auto-Reply */
287 uint dhd_arp_mode = 0xb;
288 module_param(dhd_arp_mode, uint, 0);
289
290 /* ARP offload enable */
291 uint dhd_arp_enable = true;
292 module_param(dhd_arp_enable, uint, 0);
293
294 /* Global Pkt filter enable control */
295 uint dhd_pkt_filter_enable = true;
296 module_param(dhd_pkt_filter_enable, uint, 0);
297
298 /* Pkt filter init setup */
299 uint dhd_pkt_filter_init;
300 module_param(dhd_pkt_filter_init, uint, 0);
301
302 /* Pkt filter mode control */
303 uint dhd_master_mode = true;
304 module_param(dhd_master_mode, uint, 1);
305
306 /* Watchdog thread priority, -1 to use kernel timer */
307 int dhd_watchdog_prio = 97;
308 module_param(dhd_watchdog_prio, int, 0);
309
310 /* DPC thread priority, -1 to use tasklet */
311 int dhd_dpc_prio = 98;
312 module_param(dhd_dpc_prio, int, 0);
313
314 /* DPC thread priority, -1 to use tasklet */
315 extern int dhd_dongle_memsize;
316 module_param(dhd_dongle_memsize, int, 0);
317
318 /* Contorl fw roaming */
319 #ifdef CUSTOMER_HW2
320 uint dhd_roam;
321 #else
322 uint dhd_roam = 1;
323 #endif
324
325 /* Control radio state */
326 uint dhd_radio_up = 1;
327
328 /* Network inteface name */
329 char iface_name[IFNAMSIZ] = "wlan";
330 module_param_string(iface_name, iface_name, IFNAMSIZ, 0);
331
332 /* The following are specific to the SDIO dongle */
333
334 /* IOCTL response timeout */
335 int dhd_ioctl_timeout_msec = IOCTL_RESP_TIMEOUT;
336
337 /* Idle timeout for backplane clock */
338 int dhd_idletime = DHD_IDLETIME_TICKS;
339 module_param(dhd_idletime, int, 0);
340
341 /* Use polling */
342 uint dhd_poll;
343 module_param(dhd_poll, uint, 0);
344
345 /* Use cfg80211 */
346 uint dhd_cfg80211 = true;
347 module_param(dhd_cfg80211, uint, 0);
348
349 /* Use interrupts */
350 uint dhd_intr = true;
351 module_param(dhd_intr, uint, 0);
352
353 /* SDIO Drive Strength (in milliamps) */
354 uint dhd_sdiod_drive_strength = 6;
355 module_param(dhd_sdiod_drive_strength, uint, 0);
356
357 /* Tx/Rx bounds */
358 extern uint dhd_txbound;
359 extern uint dhd_rxbound;
360 module_param(dhd_txbound, uint, 0);
361 module_param(dhd_rxbound, uint, 0);
362
363 /* Deferred transmits */
364 extern uint dhd_deferred_tx;
365 module_param(dhd_deferred_tx, uint, 0);
366
367 #ifdef SDTEST
368 /* Echo packet generator (pkts/s) */
369 uint dhd_pktgen;
370 module_param(dhd_pktgen, uint, 0);
371
372 /* Echo packet len (0 => sawtooth, max 2040) */
373 uint dhd_pktgen_len;
374 module_param(dhd_pktgen_len, uint, 0);
375 #endif
376
377 #define FAVORITE_WIFI_CP (!!dhd_cfg80211)
378 #define IS_CFG80211_FAVORITE() FAVORITE_WIFI_CP
379 #define DBG_CFG80211_GET() ((dhd_cfg80211 & WL_DBG_MASK) >> 1)
380 #define NO_FW_REQ() (dhd_cfg80211 & 0x80)
381
382 /* Version string to report */
383 #ifdef DHD_DEBUG
384 #define DHD_COMPILED "\nCompiled in " SRCBASE
385 #else
386 #define DHD_COMPILED
387 #endif
388
389 static void dhd_dpc(unsigned long data);
390 /* forward decl */
391 extern int dhd_wait_pend8021x(struct net_device *dev);
392
393 #ifdef TOE
394 #ifndef BDC
395 #error TOE requires BDC
396 #endif /* !BDC */
397 static int dhd_toe_get(dhd_info_t *dhd, int idx, u32 *toe_ol);
398 static int dhd_toe_set(dhd_info_t *dhd, int idx, u32 toe_ol);
399 #endif /* TOE */
400
401 static int dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
402 wl_event_msg_t *event_ptr, void **data_ptr);
403
404 #if defined(CONFIG_PM_SLEEP)
405 static int dhd_sleep_pm_callback(struct notifier_block *nfb,
406 unsigned long action, void *ignored)
407 {
408 switch (action) {
409 case PM_HIBERNATION_PREPARE:
410 case PM_SUSPEND_PREPARE:
411 atomic_set(&dhd_mmc_suspend, true);
412 return NOTIFY_OK;
413 case PM_POST_HIBERNATION:
414 case PM_POST_SUSPEND:
415 atomic_set(&dhd_mmc_suspend, false);
416 return NOTIFY_OK;
417 }
418 return 0;
419 }
420
421 static struct notifier_block dhd_sleep_pm_notifier = {
422 .notifier_call = dhd_sleep_pm_callback,
423 .priority = 0
424 };
425
426 extern int register_pm_notifier(struct notifier_block *nb);
427 extern int unregister_pm_notifier(struct notifier_block *nb);
428 #endif /* defined(CONFIG_PM_SLEEP) */
429 /* && defined(DHD_GPL) */
430 static void dhd_set_packet_filter(int value, dhd_pub_t *dhd)
431 {
432 #ifdef PKT_FILTER_SUPPORT
433 DHD_TRACE(("%s: %d\n", __func__, value));
434 /* 1 - Enable packet filter, only allow unicast packet to send up */
435 /* 0 - Disable packet filter */
436 if (dhd_pkt_filter_enable) {
437 int i;
438
439 for (i = 0; i < dhd->pktfilter_count; i++) {
440 dhd_pktfilter_offload_set(dhd, dhd->pktfilter[i]);
441 dhd_pktfilter_offload_enable(dhd, dhd->pktfilter[i],
442 value, dhd_master_mode);
443 }
444 }
445 #endif
446 }
447
448 #if defined(CONFIG_HAS_EARLYSUSPEND)
449 static int dhd_set_suspend(int value, dhd_pub_t *dhd)
450 {
451 int power_mode = PM_MAX;
452 /* wl_pkt_filter_enable_t enable_parm; */
453 char iovbuf[32];
454 int bcn_li_dtim = 3;
455 #ifdef CUSTOMER_HW2
456 uint roamvar = 1;
457 #endif /* CUSTOMER_HW2 */
458
459 DHD_TRACE(("%s: enter, value = %d in_suspend=%d\n",
460 __func__, value, dhd->in_suspend));
461
462 if (dhd && dhd->up) {
463 if (value && dhd->in_suspend) {
464
465 /* Kernel suspended */
466 DHD_TRACE(("%s: force extra Suspend setting\n",
467 __func__));
468
469 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM,
470 (char *)&power_mode,
471 sizeof(power_mode));
472
473 /* Enable packet filter, only allow unicast
474 packet to send up */
475 dhd_set_packet_filter(1, dhd);
476
477 /* if dtim skip setup as default force it
478 * to wake each third dtim
479 * for better power saving.
480 * Note that side effect is chance to miss BC/MC
481 * packet
482 */
483 if ((dhd->dtim_skip == 0) || (dhd->dtim_skip == 1))
484 bcn_li_dtim = 3;
485 else
486 bcn_li_dtim = dhd->dtim_skip;
487 brcmu_mkiovar("bcn_li_dtim", (char *)&bcn_li_dtim,
488 4, iovbuf, sizeof(iovbuf));
489 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
490 sizeof(iovbuf));
491 #ifdef CUSTOMER_HW2
492 /* Disable build-in roaming to allowed \
493 * supplicant to take of romaing
494 */
495 brcmu_mkiovar("roam_off", (char *)&roamvar, 4,
496 iovbuf, sizeof(iovbuf));
497 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
498 sizeof(iovbuf));
499 #endif /* CUSTOMER_HW2 */
500 } else {
501
502 /* Kernel resumed */
503 DHD_TRACE(("%s: Remove extra suspend setting\n",
504 __func__));
505
506 power_mode = PM_FAST;
507 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM,
508 (char *)&power_mode,
509 sizeof(power_mode));
510
511 /* disable pkt filter */
512 dhd_set_packet_filter(0, dhd);
513
514 /* restore pre-suspend setting for dtim_skip */
515 brcmu_mkiovar("bcn_li_dtim", (char *)&dhd->dtim_skip,
516 4, iovbuf, sizeof(iovbuf));
517
518 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
519 sizeof(iovbuf));
520 #ifdef CUSTOMER_HW2
521 roamvar = 0;
522 brcmu_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf,
523 sizeof(iovbuf));
524 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
525 sizeof(iovbuf));
526 #endif /* CUSTOMER_HW2 */
527 }
528 }
529
530 return 0;
531 }
532
533 static void dhd_suspend_resume_helper(struct dhd_info *dhd, int val)
534 {
535 dhd_pub_t *dhdp = &dhd->pub;
536
537 dhd_os_proto_block(dhdp);
538 /* Set flag when early suspend was called */
539 dhdp->in_suspend = val;
540 if (!dhdp->suspend_disable_flag)
541 dhd_set_suspend(val, dhdp);
542 dhd_os_proto_unblock(dhdp);
543 }
544
545 static void dhd_early_suspend(struct early_suspend *h)
546 {
547 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
548
549 DHD_TRACE(("%s: enter\n", __func__));
550
551 if (dhd)
552 dhd_suspend_resume_helper(dhd, 1);
553
554 }
555
556 static void dhd_late_resume(struct early_suspend *h)
557 {
558 struct dhd_info *dhd = container_of(h, struct dhd_info, early_suspend);
559
560 DHD_TRACE(("%s: enter\n", __func__));
561
562 if (dhd)
563 dhd_suspend_resume_helper(dhd, 0);
564 }
565 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
566
567 /*
568 * Generalized timeout mechanism. Uses spin sleep with exponential
569 * back-off until
570 * the sleep time reaches one jiffy, then switches over to task delay. Usage:
571 *
572 * dhd_timeout_start(&tmo, usec);
573 * while (!dhd_timeout_expired(&tmo))
574 * if (poll_something())
575 * break;
576 * if (dhd_timeout_expired(&tmo))
577 * fatal();
578 */
579
580 void dhd_timeout_start(dhd_timeout_t *tmo, uint usec)
581 {
582 tmo->limit = usec;
583 tmo->increment = 0;
584 tmo->elapsed = 0;
585 tmo->tick = 1000000 / HZ;
586 }
587
588 int dhd_timeout_expired(dhd_timeout_t *tmo)
589 {
590 /* Does nothing the first call */
591 if (tmo->increment == 0) {
592 tmo->increment = 1;
593 return 0;
594 }
595
596 if (tmo->elapsed >= tmo->limit)
597 return 1;
598
599 /* Add the delay that's about to take place */
600 tmo->elapsed += tmo->increment;
601
602 if (tmo->increment < tmo->tick) {
603 udelay(tmo->increment);
604 tmo->increment *= 2;
605 if (tmo->increment > tmo->tick)
606 tmo->increment = tmo->tick;
607 } else {
608 wait_queue_head_t delay_wait;
609 DECLARE_WAITQUEUE(wait, current);
610 int pending;
611 init_waitqueue_head(&delay_wait);
612 add_wait_queue(&delay_wait, &wait);
613 set_current_state(TASK_INTERRUPTIBLE);
614 schedule_timeout(1);
615 pending = signal_pending(current);
616 remove_wait_queue(&delay_wait, &wait);
617 set_current_state(TASK_RUNNING);
618 if (pending)
619 return 1; /* Interrupted */
620 }
621
622 return 0;
623 }
624
625 static int dhd_net2idx(dhd_info_t *dhd, struct net_device *net)
626 {
627 int i = 0;
628
629 ASSERT(dhd);
630 while (i < DHD_MAX_IFS) {
631 if (dhd->iflist[i] && (dhd->iflist[i]->net == net))
632 return i;
633 i++;
634 }
635
636 return DHD_BAD_IF;
637 }
638
639 int dhd_ifname2idx(dhd_info_t *dhd, char *name)
640 {
641 int i = DHD_MAX_IFS;
642
643 ASSERT(dhd);
644
645 if (name == NULL || *name == '\0')
646 return 0;
647
648 while (--i > 0)
649 if (dhd->iflist[i]
650 && !strncmp(dhd->iflist[i]->name, name, IFNAMSIZ))
651 break;
652
653 DHD_TRACE(("%s: return idx %d for \"%s\"\n", __func__, i, name));
654
655 return i; /* default - the primary interface */
656 }
657
658 char *dhd_ifname(dhd_pub_t *dhdp, int ifidx)
659 {
660 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
661
662 ASSERT(dhd);
663
664 if (ifidx < 0 || ifidx >= DHD_MAX_IFS) {
665 DHD_ERROR(("%s: ifidx %d out of range\n", __func__, ifidx));
666 return "<if_bad>";
667 }
668
669 if (dhd->iflist[ifidx] == NULL) {
670 DHD_ERROR(("%s: null i/f %d\n", __func__, ifidx));
671 return "<if_null>";
672 }
673
674 if (dhd->iflist[ifidx]->net)
675 return dhd->iflist[ifidx]->net->name;
676
677 return "<if_none>";
678 }
679
680 static void _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
681 {
682 struct net_device *dev;
683 struct netdev_hw_addr *ha;
684 u32 allmulti, cnt;
685
686 wl_ioctl_t ioc;
687 char *buf, *bufp;
688 uint buflen;
689 int ret;
690
691 ASSERT(dhd && dhd->iflist[ifidx]);
692 dev = dhd->iflist[ifidx]->net;
693 cnt = netdev_mc_count(dev);
694
695 /* Determine initial value of allmulti flag */
696 allmulti = (dev->flags & IFF_ALLMULTI) ? true : false;
697
698 /* Send down the multicast list first. */
699
700 buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETH_ALEN);
701 bufp = buf = kmalloc(buflen, GFP_ATOMIC);
702 if (!bufp) {
703 DHD_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
704 dhd_ifname(&dhd->pub, ifidx), cnt));
705 return;
706 }
707
708 strcpy(bufp, "mcast_list");
709 bufp += strlen("mcast_list") + 1;
710
711 cnt = cpu_to_le32(cnt);
712 memcpy(bufp, &cnt, sizeof(cnt));
713 bufp += sizeof(cnt);
714
715 netdev_for_each_mc_addr(ha, dev) {
716 if (!cnt)
717 break;
718 memcpy(bufp, ha->addr, ETH_ALEN);
719 bufp += ETH_ALEN;
720 cnt--;
721 }
722
723 memset(&ioc, 0, sizeof(ioc));
724 ioc.cmd = WLC_SET_VAR;
725 ioc.buf = buf;
726 ioc.len = buflen;
727 ioc.set = true;
728
729 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
730 if (ret < 0) {
731 DHD_ERROR(("%s: set mcast_list failed, cnt %d\n",
732 dhd_ifname(&dhd->pub, ifidx), cnt));
733 allmulti = cnt ? true : allmulti;
734 }
735
736 kfree(buf);
737
738 /* Now send the allmulti setting. This is based on the setting in the
739 * net_device flags, but might be modified above to be turned on if we
740 * were trying to set some addresses and dongle rejected it...
741 */
742
743 buflen = sizeof("allmulti") + sizeof(allmulti);
744 buf = kmalloc(buflen, GFP_ATOMIC);
745 if (!buf) {
746 DHD_ERROR(("%s: out of memory for allmulti\n",
747 dhd_ifname(&dhd->pub, ifidx)));
748 return;
749 }
750 allmulti = cpu_to_le32(allmulti);
751
752 if (!brcmu_mkiovar
753 ("allmulti", (void *)&allmulti, sizeof(allmulti), buf, buflen)) {
754 DHD_ERROR(("%s: mkiovar failed for allmulti, datalen %d "
755 "buflen %u\n", dhd_ifname(&dhd->pub, ifidx),
756 (int)sizeof(allmulti), buflen));
757 kfree(buf);
758 return;
759 }
760
761 memset(&ioc, 0, sizeof(ioc));
762 ioc.cmd = WLC_SET_VAR;
763 ioc.buf = buf;
764 ioc.len = buflen;
765 ioc.set = true;
766
767 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
768 if (ret < 0) {
769 DHD_ERROR(("%s: set allmulti %d failed\n",
770 dhd_ifname(&dhd->pub, ifidx),
771 le32_to_cpu(allmulti)));
772 }
773
774 kfree(buf);
775
776 /* Finally, pick up the PROMISC flag as well, like the NIC
777 driver does */
778
779 allmulti = (dev->flags & IFF_PROMISC) ? true : false;
780 allmulti = cpu_to_le32(allmulti);
781
782 memset(&ioc, 0, sizeof(ioc));
783 ioc.cmd = WLC_SET_PROMISC;
784 ioc.buf = &allmulti;
785 ioc.len = sizeof(allmulti);
786 ioc.set = true;
787
788 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
789 if (ret < 0) {
790 DHD_ERROR(("%s: set promisc %d failed\n",
791 dhd_ifname(&dhd->pub, ifidx),
792 le32_to_cpu(allmulti)));
793 }
794 }
795
796 static int
797 _dhd_set_mac_address(dhd_info_t *dhd, int ifidx, u8 *addr)
798 {
799 char buf[32];
800 wl_ioctl_t ioc;
801 int ret;
802
803 DHD_TRACE(("%s enter\n", __func__));
804 if (!brcmu_mkiovar
805 ("cur_etheraddr", (char *)addr, ETH_ALEN, buf, 32)) {
806 DHD_ERROR(("%s: mkiovar failed for cur_etheraddr\n",
807 dhd_ifname(&dhd->pub, ifidx)));
808 return -1;
809 }
810 memset(&ioc, 0, sizeof(ioc));
811 ioc.cmd = WLC_SET_VAR;
812 ioc.buf = buf;
813 ioc.len = 32;
814 ioc.set = true;
815
816 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
817 if (ret < 0) {
818 DHD_ERROR(("%s: set cur_etheraddr failed\n",
819 dhd_ifname(&dhd->pub, ifidx)));
820 } else {
821 memcpy(dhd->iflist[ifidx]->net->dev_addr, addr, ETH_ALEN);
822 }
823
824 return ret;
825 }
826
827 #ifdef SOFTAP
828 extern struct net_device *ap_net_dev;
829 #endif
830
831 static void dhd_op_if(dhd_if_t *ifp)
832 {
833 dhd_info_t *dhd;
834 int ret = 0, err = 0;
835
836 ASSERT(ifp && ifp->info && ifp->idx); /* Virtual interfaces only */
837
838 dhd = ifp->info;
839
840 DHD_TRACE(("%s: idx %d, state %d\n", __func__, ifp->idx, ifp->state));
841
842 switch (ifp->state) {
843 case WLC_E_IF_ADD:
844 /*
845 * Delete the existing interface before overwriting it
846 * in case we missed the WLC_E_IF_DEL event.
847 */
848 if (ifp->net != NULL) {
849 DHD_ERROR(("%s: ERROR: netdev:%s already exists, "
850 "try free & unregister\n",
851 __func__, ifp->net->name));
852 netif_stop_queue(ifp->net);
853 unregister_netdev(ifp->net);
854 free_netdev(ifp->net);
855 }
856 /* Allocate etherdev, including space for private structure */
857 ifp->net = alloc_etherdev(sizeof(dhd));
858 if (!ifp->net) {
859 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
860 ret = -ENOMEM;
861 }
862 if (ret == 0) {
863 strcpy(ifp->net->name, ifp->name);
864 memcpy(netdev_priv(ifp->net), &dhd, sizeof(dhd));
865 err = dhd_net_attach(&dhd->pub, ifp->idx);
866 if (err != 0) {
867 DHD_ERROR(("%s: dhd_net_attach failed, "
868 "err %d\n",
869 __func__, err));
870 ret = -EOPNOTSUPP;
871 } else {
872 #ifdef SOFTAP
873 /* semaphore that the soft AP CODE
874 waits on */
875 extern struct semaphore ap_eth_sema;
876
877 /* save ptr to wl0.1 netdev for use
878 in wl_iw.c */
879 ap_net_dev = ifp->net;
880 /* signal to the SOFTAP 'sleeper' thread,
881 wl0.1 is ready */
882 up(&ap_eth_sema);
883 #endif
884 DHD_TRACE(("\n ==== pid:%x, net_device for "
885 "if:%s created ===\n\n",
886 current->pid, ifp->net->name));
887 ifp->state = 0;
888 }
889 }
890 break;
891 case WLC_E_IF_DEL:
892 if (ifp->net != NULL) {
893 DHD_TRACE(("\n%s: got 'WLC_E_IF_DEL' state\n",
894 __func__));
895 netif_stop_queue(ifp->net);
896 unregister_netdev(ifp->net);
897 ret = DHD_DEL_IF; /* Make sure the free_netdev()
898 is called */
899 }
900 break;
901 default:
902 DHD_ERROR(("%s: bad op %d\n", __func__, ifp->state));
903 ASSERT(!ifp->state);
904 break;
905 }
906
907 if (ret < 0) {
908 if (ifp->net)
909 free_netdev(ifp->net);
910
911 dhd->iflist[ifp->idx] = NULL;
912 kfree(ifp);
913 #ifdef SOFTAP
914 if (ifp->net == ap_net_dev)
915 ap_net_dev = NULL; /* NULL SOFTAP global
916 wl0.1 as well */
917 #endif /* SOFTAP */
918 }
919 }
920
921 static int _dhd_sysioc_thread(void *data)
922 {
923 dhd_info_t *dhd = (dhd_info_t *) data;
924 int i;
925 #ifdef SOFTAP
926 bool in_ap = false;
927 #endif
928
929 allow_signal(SIGTERM);
930
931 while (down_interruptible(&dhd->sysioc_sem) == 0) {
932 if (kthread_should_stop())
933 break;
934 for (i = 0; i < DHD_MAX_IFS; i++) {
935 if (dhd->iflist[i]) {
936 #ifdef SOFTAP
937 in_ap = (ap_net_dev != NULL);
938 #endif /* SOFTAP */
939 if (dhd->iflist[i]->state)
940 dhd_op_if(dhd->iflist[i]);
941 #ifdef SOFTAP
942 if (dhd->iflist[i] == NULL) {
943 DHD_TRACE(("\n\n %s: interface %d "
944 "removed!\n", __func__, i));
945 continue;
946 }
947
948 if (in_ap && dhd->set_macaddress) {
949 DHD_TRACE(("attempt to set MAC for %s "
950 "in AP Mode," "blocked. \n",
951 dhd->iflist[i]->net->name));
952 dhd->set_macaddress = false;
953 continue;
954 }
955
956 if (in_ap && dhd->set_multicast) {
957 DHD_TRACE(("attempt to set MULTICAST list for %s" "in AP Mode, blocked. \n",
958 dhd->iflist[i]->net->name));
959 dhd->set_multicast = false;
960 continue;
961 }
962 #endif /* SOFTAP */
963 if (dhd->set_multicast) {
964 dhd->set_multicast = false;
965 _dhd_set_multicast_list(dhd, i);
966 }
967 if (dhd->set_macaddress) {
968 dhd->set_macaddress = false;
969 _dhd_set_mac_address(dhd, i,
970 dhd->macvalue);
971 }
972 }
973 }
974 }
975 return 0;
976 }
977
978 static int dhd_set_mac_address(struct net_device *dev, void *addr)
979 {
980 int ret = 0;
981
982 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
983 struct sockaddr *sa = (struct sockaddr *)addr;
984 int ifidx;
985
986 ifidx = dhd_net2idx(dhd, dev);
987 if (ifidx == DHD_BAD_IF)
988 return -1;
989
990 ASSERT(dhd->sysioc_tsk);
991 memcpy(&dhd->macvalue, sa->sa_data, ETH_ALEN);
992 dhd->set_macaddress = true;
993 up(&dhd->sysioc_sem);
994
995 return ret;
996 }
997
998 static void dhd_set_multicast_list(struct net_device *dev)
999 {
1000 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
1001 int ifidx;
1002
1003 ifidx = dhd_net2idx(dhd, dev);
1004 if (ifidx == DHD_BAD_IF)
1005 return;
1006
1007 ASSERT(dhd->sysioc_tsk);
1008 dhd->set_multicast = true;
1009 up(&dhd->sysioc_sem);
1010 }
1011
1012 int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, struct sk_buff *pktbuf)
1013 {
1014 int ret;
1015 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
1016
1017 /* Reject if down */
1018 if (!dhdp->up || (dhdp->busstate == DHD_BUS_DOWN))
1019 return -ENODEV;
1020
1021 /* Update multicast statistic */
1022 if (pktbuf->len >= ETH_ALEN) {
1023 u8 *pktdata = (u8 *) (pktbuf->data);
1024 struct ethhdr *eh = (struct ethhdr *)pktdata;
1025
1026 if (is_multicast_ether_addr(eh->h_dest))
1027 dhdp->tx_multicast++;
1028 if (ntohs(eh->h_proto) == ETH_P_PAE)
1029 atomic_inc(&dhd->pend_8021x_cnt);
1030 }
1031
1032 /* If the protocol uses a data header, apply it */
1033 dhd_prot_hdrpush(dhdp, ifidx, pktbuf);
1034
1035 /* Use bus module to send data frame */
1036 #ifdef BCMDBUS
1037 ret = dbus_send_pkt(dhdp->dbus, pktbuf, NULL /* pktinfo */);
1038 #else
1039 ret = dhd_bus_txdata(dhdp->bus, pktbuf);
1040 #endif /* BCMDBUS */
1041
1042 return ret;
1043 }
1044
1045 static inline void *
1046 osl_pkt_frmnative(struct sk_buff *skb)
1047 {
1048 return (void *)skb;
1049 }
1050 #define PKTFRMNATIVE(osh, skb) \
1051 osl_pkt_frmnative((struct sk_buff *)(skb))
1052
1053 static inline struct sk_buff *
1054 osl_pkt_tonative(void *pkt)
1055 {
1056 return (struct sk_buff *)pkt;
1057 }
1058 #define PKTTONATIVE(osh, pkt) \
1059 osl_pkt_tonative((pkt))
1060
1061 static int dhd_start_xmit(struct sk_buff *skb, struct net_device *net)
1062 {
1063 int ret;
1064 void *pktbuf;
1065 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1066 int ifidx;
1067
1068 DHD_TRACE(("%s: Enter\n", __func__));
1069
1070 /* Reject if down */
1071 if (!dhd->pub.up || (dhd->pub.busstate == DHD_BUS_DOWN)) {
1072 DHD_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n",
1073 __func__, dhd->pub.up, dhd->pub.busstate));
1074 netif_stop_queue(net);
1075 return -ENODEV;
1076 }
1077
1078 ifidx = dhd_net2idx(dhd, net);
1079 if (ifidx == DHD_BAD_IF) {
1080 DHD_ERROR(("%s: bad ifidx %d\n", __func__, ifidx));
1081 netif_stop_queue(net);
1082 return -ENODEV;
1083 }
1084
1085 /* Make sure there's enough room for any header */
1086 if (skb_headroom(skb) < dhd->pub.hdrlen) {
1087 struct sk_buff *skb2;
1088
1089 DHD_INFO(("%s: insufficient headroom\n",
1090 dhd_ifname(&dhd->pub, ifidx)));
1091 dhd->pub.tx_realloc++;
1092 skb2 = skb_realloc_headroom(skb, dhd->pub.hdrlen);
1093 dev_kfree_skb(skb);
1094 skb = skb2;
1095 if (skb == NULL) {
1096 DHD_ERROR(("%s: skb_realloc_headroom failed\n",
1097 dhd_ifname(&dhd->pub, ifidx)));
1098 ret = -ENOMEM;
1099 goto done;
1100 }
1101 }
1102
1103 /* Convert to packet */
1104 pktbuf = PKTFRMNATIVE(dhd->pub.osh, skb);
1105 if (!pktbuf) {
1106 DHD_ERROR(("%s: PKTFRMNATIVE failed\n",
1107 dhd_ifname(&dhd->pub, ifidx)));
1108 dev_kfree_skb_any(skb);
1109 ret = -ENOMEM;
1110 goto done;
1111 }
1112
1113 ret = dhd_sendpkt(&dhd->pub, ifidx, pktbuf);
1114
1115 done:
1116 if (ret)
1117 dhd->pub.dstats.tx_dropped++;
1118 else
1119 dhd->pub.tx_packets++;
1120
1121 /* Return ok: we always eat the packet */
1122 return 0;
1123 }
1124
1125 void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool state)
1126 {
1127 struct net_device *net;
1128 dhd_info_t *dhd = dhdp->info;
1129
1130 DHD_TRACE(("%s: Enter\n", __func__));
1131
1132 dhdp->txoff = state;
1133 ASSERT(dhd && dhd->iflist[ifidx]);
1134 net = dhd->iflist[ifidx]->net;
1135 if (state == ON)
1136 netif_stop_queue(net);
1137 else
1138 netif_wake_queue(net);
1139 }
1140
1141 void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, struct sk_buff *pktbuf,
1142 int numpkt)
1143 {
1144 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1145 struct sk_buff *skb;
1146 unsigned char *eth;
1147 uint len;
1148 void *data;
1149 struct sk_buff *pnext, *save_pktbuf;
1150 int i;
1151 dhd_if_t *ifp;
1152 wl_event_msg_t event;
1153
1154 DHD_TRACE(("%s: Enter\n", __func__));
1155
1156 save_pktbuf = pktbuf;
1157
1158 for (i = 0; pktbuf && i < numpkt; i++, pktbuf = pnext) {
1159
1160 pnext = pktbuf->next;
1161 pktbuf->next = NULL;
1162
1163 skb = PKTTONATIVE(dhdp->osh, pktbuf);
1164
1165 /* Get the protocol, maintain skb around eth_type_trans()
1166 * The main reason for this hack is for the limitation of
1167 * Linux 2.4 where 'eth_type_trans' uses the
1168 * 'net->hard_header_len'
1169 * to perform skb_pull inside vs ETH_HLEN. Since to avoid
1170 * coping of the packet coming from the network stack to add
1171 * BDC, Hardware header etc, during network interface
1172 * registration
1173 * we set the 'net->hard_header_len' to ETH_HLEN + extra space
1174 * required
1175 * for BDC, Hardware header etc. and not just the ETH_HLEN
1176 */
1177 eth = skb->data;
1178 len = skb->len;
1179
1180 ifp = dhd->iflist[ifidx];
1181 if (ifp == NULL)
1182 ifp = dhd->iflist[0];
1183
1184 ASSERT(ifp);
1185 skb->dev = ifp->net;
1186 skb->protocol = eth_type_trans(skb, skb->dev);
1187
1188 if (skb->pkt_type == PACKET_MULTICAST)
1189 dhd->pub.rx_multicast++;
1190
1191 skb->data = eth;
1192 skb->len = len;
1193
1194 /* Strip header, count, deliver upward */
1195 skb_pull(skb, ETH_HLEN);
1196
1197 /* Process special event packets and then discard them */
1198 if (ntohs(skb->protocol) == ETH_P_BRCM)
1199 dhd_wl_host_event(dhd, &ifidx,
1200 skb_mac_header(skb),
1201 &event, &data);
1202
1203 ASSERT(ifidx < DHD_MAX_IFS && dhd->iflist[ifidx]);
1204 if (dhd->iflist[ifidx] && !dhd->iflist[ifidx]->state)
1205 ifp = dhd->iflist[ifidx];
1206
1207 if (ifp->net)
1208 ifp->net->last_rx = jiffies;
1209
1210 dhdp->dstats.rx_bytes += skb->len;
1211 dhdp->rx_packets++; /* Local count */
1212
1213 if (in_interrupt()) {
1214 netif_rx(skb);
1215 } else {
1216 /* If the receive is not processed inside an ISR,
1217 * the softirqd must be woken explicitly to service
1218 * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled
1219 * by netif_rx_ni(), but in earlier kernels, we need
1220 * to do it manually.
1221 */
1222 netif_rx_ni(skb);
1223 }
1224 }
1225 }
1226
1227 void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx)
1228 {
1229 /* Linux version has nothing to do */
1230 return;
1231 }
1232
1233 void dhd_txcomplete(dhd_pub_t *dhdp, struct sk_buff *txp, bool success)
1234 {
1235 uint ifidx;
1236 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
1237 struct ethhdr *eh;
1238 u16 type;
1239
1240 dhd_prot_hdrpull(dhdp, &ifidx, txp);
1241
1242 eh = (struct ethhdr *)(txp->data);
1243 type = ntohs(eh->h_proto);
1244
1245 if (type == ETH_P_PAE)
1246 atomic_dec(&dhd->pend_8021x_cnt);
1247
1248 }
1249
1250 static struct net_device_stats *dhd_get_stats(struct net_device *net)
1251 {
1252 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1253 dhd_if_t *ifp;
1254 int ifidx;
1255
1256 DHD_TRACE(("%s: Enter\n", __func__));
1257
1258 ifidx = dhd_net2idx(dhd, net);
1259 if (ifidx == DHD_BAD_IF)
1260 return NULL;
1261
1262 ifp = dhd->iflist[ifidx];
1263 ASSERT(dhd && ifp);
1264
1265 if (dhd->pub.up) {
1266 /* Use the protocol to get dongle stats */
1267 dhd_prot_dstats(&dhd->pub);
1268 }
1269
1270 /* Copy dongle stats to net device stats */
1271 ifp->stats.rx_packets = dhd->pub.dstats.rx_packets;
1272 ifp->stats.tx_packets = dhd->pub.dstats.tx_packets;
1273 ifp->stats.rx_bytes = dhd->pub.dstats.rx_bytes;
1274 ifp->stats.tx_bytes = dhd->pub.dstats.tx_bytes;
1275 ifp->stats.rx_errors = dhd->pub.dstats.rx_errors;
1276 ifp->stats.tx_errors = dhd->pub.dstats.tx_errors;
1277 ifp->stats.rx_dropped = dhd->pub.dstats.rx_dropped;
1278 ifp->stats.tx_dropped = dhd->pub.dstats.tx_dropped;
1279 ifp->stats.multicast = dhd->pub.dstats.multicast;
1280
1281 return &ifp->stats;
1282 }
1283
1284 static int dhd_watchdog_thread(void *data)
1285 {
1286 dhd_info_t *dhd = (dhd_info_t *) data;
1287
1288 /* This thread doesn't need any user-level access,
1289 * so get rid of all our resources
1290 */
1291 #ifdef DHD_SCHED
1292 if (dhd_watchdog_prio > 0) {
1293 struct sched_param param;
1294 param.sched_priority = (dhd_watchdog_prio < MAX_RT_PRIO) ?
1295 dhd_watchdog_prio : (MAX_RT_PRIO - 1);
1296 setScheduler(current, SCHED_FIFO, &param);
1297 }
1298 #endif /* DHD_SCHED */
1299
1300 allow_signal(SIGTERM);
1301 /* Run until signal received */
1302 while (1) {
1303 if (kthread_should_stop())
1304 break;
1305 if (down_interruptible(&dhd->watchdog_sem) == 0) {
1306 if (dhd->pub.dongle_reset == false) {
1307 /* Call the bus module watchdog */
1308 dhd_bus_watchdog(&dhd->pub);
1309 }
1310 /* Count the tick for reference */
1311 dhd->pub.tickcnt++;
1312 } else
1313 break;
1314 }
1315 return 0;
1316 }
1317
1318 static void dhd_watchdog(unsigned long data)
1319 {
1320 dhd_info_t *dhd = (dhd_info_t *) data;
1321
1322 if (dhd->watchdog_tsk) {
1323 up(&dhd->watchdog_sem);
1324
1325 /* Reschedule the watchdog */
1326 if (dhd->wd_timer_valid) {
1327 mod_timer(&dhd->timer,
1328 jiffies + dhd_watchdog_ms * HZ / 1000);
1329 }
1330 return;
1331 }
1332
1333 /* Call the bus module watchdog */
1334 dhd_bus_watchdog(&dhd->pub);
1335
1336 /* Count the tick for reference */
1337 dhd->pub.tickcnt++;
1338
1339 /* Reschedule the watchdog */
1340 if (dhd->wd_timer_valid)
1341 mod_timer(&dhd->timer, jiffies + dhd_watchdog_ms * HZ / 1000);
1342 }
1343
1344 static int dhd_dpc_thread(void *data)
1345 {
1346 dhd_info_t *dhd = (dhd_info_t *) data;
1347
1348 /* This thread doesn't need any user-level access,
1349 * so get rid of all our resources
1350 */
1351 #ifdef DHD_SCHED
1352 if (dhd_dpc_prio > 0) {
1353 struct sched_param param;
1354 param.sched_priority =
1355 (dhd_dpc_prio <
1356 MAX_RT_PRIO) ? dhd_dpc_prio : (MAX_RT_PRIO - 1);
1357 setScheduler(current, SCHED_FIFO, &param);
1358 }
1359 #endif /* DHD_SCHED */
1360
1361 allow_signal(SIGTERM);
1362 /* Run until signal received */
1363 while (1) {
1364 if (kthread_should_stop())
1365 break;
1366 if (down_interruptible(&dhd->dpc_sem) == 0) {
1367 /* Call bus dpc unless it indicated down
1368 (then clean stop) */
1369 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1370 if (dhd_bus_dpc(dhd->pub.bus)) {
1371 up(&dhd->dpc_sem);
1372 }
1373 } else {
1374 dhd_bus_stop(dhd->pub.bus, true);
1375 }
1376 } else
1377 break;
1378 }
1379 return 0;
1380 }
1381
1382 static void dhd_dpc(unsigned long data)
1383 {
1384 dhd_info_t *dhd;
1385
1386 dhd = (dhd_info_t *) data;
1387
1388 /* Call bus dpc unless it indicated down (then clean stop) */
1389 if (dhd->pub.busstate != DHD_BUS_DOWN) {
1390 if (dhd_bus_dpc(dhd->pub.bus))
1391 tasklet_schedule(&dhd->tasklet);
1392 } else {
1393 dhd_bus_stop(dhd->pub.bus, true);
1394 }
1395 }
1396
1397 void dhd_sched_dpc(dhd_pub_t *dhdp)
1398 {
1399 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1400
1401 if (dhd->dpc_tsk) {
1402 up(&dhd->dpc_sem);
1403 return;
1404 }
1405
1406 tasklet_schedule(&dhd->tasklet);
1407 }
1408
1409 #ifdef TOE
1410 /* Retrieve current toe component enables, which are kept
1411 as a bitmap in toe_ol iovar */
1412 static int dhd_toe_get(dhd_info_t *dhd, int ifidx, u32 *toe_ol)
1413 {
1414 wl_ioctl_t ioc;
1415 char buf[32];
1416 int ret;
1417
1418 memset(&ioc, 0, sizeof(ioc));
1419
1420 ioc.cmd = WLC_GET_VAR;
1421 ioc.buf = buf;
1422 ioc.len = (uint) sizeof(buf);
1423 ioc.set = false;
1424
1425 strcpy(buf, "toe_ol");
1426 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1427 if (ret < 0) {
1428 /* Check for older dongle image that doesn't support toe_ol */
1429 if (ret == -EIO) {
1430 DHD_ERROR(("%s: toe not supported by device\n",
1431 dhd_ifname(&dhd->pub, ifidx)));
1432 return -EOPNOTSUPP;
1433 }
1434
1435 DHD_INFO(("%s: could not get toe_ol: ret=%d\n",
1436 dhd_ifname(&dhd->pub, ifidx), ret));
1437 return ret;
1438 }
1439
1440 memcpy(toe_ol, buf, sizeof(u32));
1441 return 0;
1442 }
1443
1444 /* Set current toe component enables in toe_ol iovar,
1445 and set toe global enable iovar */
1446 static int dhd_toe_set(dhd_info_t *dhd, int ifidx, u32 toe_ol)
1447 {
1448 wl_ioctl_t ioc;
1449 char buf[32];
1450 int toe, ret;
1451
1452 memset(&ioc, 0, sizeof(ioc));
1453
1454 ioc.cmd = WLC_SET_VAR;
1455 ioc.buf = buf;
1456 ioc.len = (uint) sizeof(buf);
1457 ioc.set = true;
1458
1459 /* Set toe_ol as requested */
1460
1461 strcpy(buf, "toe_ol");
1462 memcpy(&buf[sizeof("toe_ol")], &toe_ol, sizeof(u32));
1463
1464 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1465 if (ret < 0) {
1466 DHD_ERROR(("%s: could not set toe_ol: ret=%d\n",
1467 dhd_ifname(&dhd->pub, ifidx), ret));
1468 return ret;
1469 }
1470
1471 /* Enable toe globally only if any components are enabled. */
1472
1473 toe = (toe_ol != 0);
1474
1475 strcpy(buf, "toe");
1476 memcpy(&buf[sizeof("toe")], &toe, sizeof(u32));
1477
1478 ret = dhd_prot_ioctl(&dhd->pub, ifidx, &ioc, ioc.buf, ioc.len);
1479 if (ret < 0) {
1480 DHD_ERROR(("%s: could not set toe: ret=%d\n",
1481 dhd_ifname(&dhd->pub, ifidx), ret));
1482 return ret;
1483 }
1484
1485 return 0;
1486 }
1487 #endif /* TOE */
1488
1489 static void dhd_ethtool_get_drvinfo(struct net_device *net,
1490 struct ethtool_drvinfo *info)
1491 {
1492 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1493
1494 sprintf(info->driver, DRV_MODULE_NAME);
1495 sprintf(info->version, "%lu", dhd->pub.drv_version);
1496 sprintf(info->fw_version, "%s", wl_cfg80211_get_fwname());
1497 sprintf(info->bus_info, "%s", dev_name(&wl_cfg80211_get_sdio_func()->dev));
1498 }
1499
1500 struct ethtool_ops dhd_ethtool_ops = {
1501 .get_drvinfo = dhd_ethtool_get_drvinfo
1502 };
1503
1504 static int dhd_ethtool(dhd_info_t *dhd, void *uaddr)
1505 {
1506 struct ethtool_drvinfo info;
1507 char drvname[sizeof(info.driver)];
1508 u32 cmd;
1509 #ifdef TOE
1510 struct ethtool_value edata;
1511 u32 toe_cmpnt, csum_dir;
1512 int ret;
1513 #endif
1514
1515 DHD_TRACE(("%s: Enter\n", __func__));
1516
1517 /* all ethtool calls start with a cmd word */
1518 if (copy_from_user(&cmd, uaddr, sizeof(u32)))
1519 return -EFAULT;
1520
1521 switch (cmd) {
1522 case ETHTOOL_GDRVINFO:
1523 /* Copy out any request driver name */
1524 if (copy_from_user(&info, uaddr, sizeof(info)))
1525 return -EFAULT;
1526 strncpy(drvname, info.driver, sizeof(info.driver));
1527 drvname[sizeof(info.driver) - 1] = '\0';
1528
1529 /* clear struct for return */
1530 memset(&info, 0, sizeof(info));
1531 info.cmd = cmd;
1532
1533 /* if dhd requested, identify ourselves */
1534 if (strcmp(drvname, "?dhd") == 0) {
1535 sprintf(info.driver, "dhd");
1536 strcpy(info.version, EPI_VERSION_STR);
1537 }
1538
1539 /* otherwise, require dongle to be up */
1540 else if (!dhd->pub.up) {
1541 DHD_ERROR(("%s: dongle is not up\n", __func__));
1542 return -ENODEV;
1543 }
1544
1545 /* finally, report dongle driver type */
1546 else if (dhd->pub.iswl)
1547 sprintf(info.driver, "wl");
1548 else
1549 sprintf(info.driver, "xx");
1550
1551 sprintf(info.version, "%lu", dhd->pub.drv_version);
1552 if (copy_to_user(uaddr, &info, sizeof(info)))
1553 return -EFAULT;
1554 DHD_CTL(("%s: given %*s, returning %s\n", __func__,
1555 (int)sizeof(drvname), drvname, info.driver));
1556 break;
1557
1558 #ifdef TOE
1559 /* Get toe offload components from dongle */
1560 case ETHTOOL_GRXCSUM:
1561 case ETHTOOL_GTXCSUM:
1562 ret = dhd_toe_get(dhd, 0, &toe_cmpnt);
1563 if (ret < 0)
1564 return ret;
1565
1566 csum_dir =
1567 (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1568
1569 edata.cmd = cmd;
1570 edata.data = (toe_cmpnt & csum_dir) ? 1 : 0;
1571
1572 if (copy_to_user(uaddr, &edata, sizeof(edata)))
1573 return -EFAULT;
1574 break;
1575
1576 /* Set toe offload components in dongle */
1577 case ETHTOOL_SRXCSUM:
1578 case ETHTOOL_STXCSUM:
1579 if (copy_from_user(&edata, uaddr, sizeof(edata)))
1580 return -EFAULT;
1581
1582 /* Read the current settings, update and write back */
1583 ret = dhd_toe_get(dhd, 0, &toe_cmpnt);
1584 if (ret < 0)
1585 return ret;
1586
1587 csum_dir =
1588 (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL;
1589
1590 if (edata.data != 0)
1591 toe_cmpnt |= csum_dir;
1592 else
1593 toe_cmpnt &= ~csum_dir;
1594
1595 ret = dhd_toe_set(dhd, 0, toe_cmpnt);
1596 if (ret < 0)
1597 return ret;
1598
1599 /* If setting TX checksum mode, tell Linux the new mode */
1600 if (cmd == ETHTOOL_STXCSUM) {
1601 if (edata.data)
1602 dhd->iflist[0]->net->features |=
1603 NETIF_F_IP_CSUM;
1604 else
1605 dhd->iflist[0]->net->features &=
1606 ~NETIF_F_IP_CSUM;
1607 }
1608
1609 break;
1610 #endif /* TOE */
1611
1612 default:
1613 return -EOPNOTSUPP;
1614 }
1615
1616 return 0;
1617 }
1618
1619 static int dhd_ioctl_entry(struct net_device *net, struct ifreq *ifr, int cmd)
1620 {
1621 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1622 dhd_ioctl_t ioc;
1623 int bcmerror = 0;
1624 int buflen = 0;
1625 void *buf = NULL;
1626 uint driver = 0;
1627 int ifidx;
1628 bool is_set_key_cmd;
1629
1630 ifidx = dhd_net2idx(dhd, net);
1631 DHD_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __func__, ifidx, cmd));
1632
1633 if (ifidx == DHD_BAD_IF)
1634 return -1;
1635
1636 #if defined(CONFIG_WIRELESS_EXT)
1637 /* linux wireless extensions */
1638 if ((cmd >= SIOCIWFIRST) && (cmd <= SIOCIWLAST)) {
1639 /* may recurse, do NOT lock */
1640 return wl_iw_ioctl(net, ifr, cmd);
1641 }
1642 #endif /* defined(CONFIG_WIRELESS_EXT) */
1643
1644 if (cmd == SIOCETHTOOL)
1645 return dhd_ethtool(dhd, (void *)ifr->ifr_data);
1646
1647 if (cmd != SIOCDEVPRIVATE)
1648 return -EOPNOTSUPP;
1649
1650 memset(&ioc, 0, sizeof(ioc));
1651
1652 /* Copy the ioc control structure part of ioctl request */
1653 if (copy_from_user(&ioc, ifr->ifr_data, sizeof(wl_ioctl_t))) {
1654 bcmerror = -EINVAL;
1655 goto done;
1656 }
1657
1658 /* Copy out any buffer passed */
1659 if (ioc.buf) {
1660 buflen = min_t(int, ioc.len, DHD_IOCTL_MAXLEN);
1661 /* optimization for direct ioctl calls from kernel */
1662 /*
1663 if (segment_eq(get_fs(), KERNEL_DS)) {
1664 buf = ioc.buf;
1665 } else {
1666 */
1667 {
1668 buf = kmalloc(buflen, GFP_ATOMIC);
1669 if (!buf) {
1670 bcmerror = -ENOMEM;
1671 goto done;
1672 }
1673 if (copy_from_user(buf, ioc.buf, buflen)) {
1674 bcmerror = -EINVAL;
1675 goto done;
1676 }
1677 }
1678 }
1679
1680 /* To differentiate between wl and dhd read 4 more byes */
1681 if ((copy_from_user(&driver, (char *)ifr->ifr_data + sizeof(wl_ioctl_t),
1682 sizeof(uint)) != 0)) {
1683 bcmerror = -EINVAL;
1684 goto done;
1685 }
1686
1687 if (!capable(CAP_NET_ADMIN)) {
1688 bcmerror = -EPERM;
1689 goto done;
1690 }
1691
1692 /* check for local dhd ioctl and handle it */
1693 if (driver == DHD_IOCTL_MAGIC) {
1694 bcmerror = dhd_ioctl((void *)&dhd->pub, &ioc, buf, buflen);
1695 if (bcmerror)
1696 dhd->pub.bcmerror = bcmerror;
1697 goto done;
1698 }
1699
1700 /* send to dongle (must be up, and wl) */
1701 if ((dhd->pub.busstate != DHD_BUS_DATA)) {
1702 DHD_ERROR(("%s DONGLE_DOWN,__func__\n", __func__));
1703 bcmerror = -EIO;
1704 goto done;
1705 }
1706
1707 if (!dhd->pub.iswl) {
1708 bcmerror = -EIO;
1709 goto done;
1710 }
1711
1712 /* Intercept WLC_SET_KEY IOCTL - serialize M4 send and set key IOCTL to
1713 * prevent M4 encryption.
1714 */
1715 is_set_key_cmd = ((ioc.cmd == WLC_SET_KEY) ||
1716 ((ioc.cmd == WLC_SET_VAR) &&
1717 !(strncmp("wsec_key", ioc.buf, 9))) ||
1718 ((ioc.cmd == WLC_SET_VAR) &&
1719 !(strncmp("bsscfg:wsec_key", ioc.buf, 15))));
1720 if (is_set_key_cmd)
1721 dhd_wait_pend8021x(net);
1722
1723 bcmerror =
1724 dhd_prot_ioctl(&dhd->pub, ifidx, (wl_ioctl_t *)&ioc, buf, buflen);
1725
1726 done:
1727 if (!bcmerror && buf && ioc.buf) {
1728 if (copy_to_user(ioc.buf, buf, buflen))
1729 bcmerror = -EFAULT;
1730 }
1731
1732 kfree(buf);
1733
1734 if (bcmerror > 0)
1735 bcmerror = 0;
1736
1737 return bcmerror;
1738 }
1739
1740 static int dhd_stop(struct net_device *net)
1741 {
1742 #if !defined(IGNORE_ETH0_DOWN)
1743 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1744
1745 DHD_TRACE(("%s: Enter\n", __func__));
1746 if (IS_CFG80211_FAVORITE()) {
1747 wl_cfg80211_down();
1748 }
1749 if (dhd->pub.up == 0)
1750 return 0;
1751
1752 /* Set state and stop OS transmissions */
1753 dhd->pub.up = 0;
1754 netif_stop_queue(net);
1755 #else
1756 DHD_ERROR(("BYPASS %s:due to BRCM compilation : under investigation\n",
1757 __func__));
1758 #endif /* !defined(IGNORE_ETH0_DOWN) */
1759
1760 return 0;
1761 }
1762
1763 static int dhd_open(struct net_device *net)
1764 {
1765 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
1766 #ifdef TOE
1767 u32 toe_ol;
1768 #endif
1769 int ifidx = dhd_net2idx(dhd, net);
1770 s32 ret = 0;
1771
1772 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
1773
1774 if (ifidx == 0) { /* do it only for primary eth0 */
1775
1776 /* try to bring up bus */
1777 ret = dhd_bus_start(&dhd->pub);
1778 if (ret != 0) {
1779 DHD_ERROR(("%s: failed with code %d\n", __func__, ret));
1780 return -1;
1781 }
1782 atomic_set(&dhd->pend_8021x_cnt, 0);
1783
1784 memcpy(net->dev_addr, dhd->pub.mac, ETH_ALEN);
1785
1786 #ifdef TOE
1787 /* Get current TOE mode from dongle */
1788 if (dhd_toe_get(dhd, ifidx, &toe_ol) >= 0
1789 && (toe_ol & TOE_TX_CSUM_OL) != 0)
1790 dhd->iflist[ifidx]->net->features |= NETIF_F_IP_CSUM;
1791 else
1792 dhd->iflist[ifidx]->net->features &= ~NETIF_F_IP_CSUM;
1793 #endif
1794 }
1795 /* Allow transmit calls */
1796 netif_start_queue(net);
1797 dhd->pub.up = 1;
1798 if (IS_CFG80211_FAVORITE()) {
1799 if (unlikely(wl_cfg80211_up())) {
1800 DHD_ERROR(("%s: failed to bring up cfg80211\n",
1801 __func__));
1802 return -1;
1803 }
1804 }
1805
1806 return ret;
1807 }
1808
1809 int
1810 dhd_add_if(dhd_info_t *dhd, int ifidx, void *handle, char *name,
1811 u8 *mac_addr, u32 flags, u8 bssidx)
1812 {
1813 dhd_if_t *ifp;
1814
1815 DHD_TRACE(("%s: idx %d, handle->%p\n", __func__, ifidx, handle));
1816
1817 ASSERT(dhd && (ifidx < DHD_MAX_IFS));
1818
1819 ifp = dhd->iflist[ifidx];
1820 if (!ifp) {
1821 ifp = kmalloc(sizeof(dhd_if_t), GFP_ATOMIC);
1822 if (!ifp) {
1823 DHD_ERROR(("%s: OOM - dhd_if_t\n", __func__));
1824 return -ENOMEM;
1825 }
1826 }
1827
1828 memset(ifp, 0, sizeof(dhd_if_t));
1829 ifp->info = dhd;
1830 dhd->iflist[ifidx] = ifp;
1831 strlcpy(ifp->name, name, IFNAMSIZ);
1832 if (mac_addr != NULL)
1833 memcpy(&ifp->mac_addr, mac_addr, ETH_ALEN);
1834
1835 if (handle == NULL) {
1836 ifp->state = WLC_E_IF_ADD;
1837 ifp->idx = ifidx;
1838 ASSERT(dhd->sysioc_tsk);
1839 up(&dhd->sysioc_sem);
1840 } else
1841 ifp->net = (struct net_device *)handle;
1842
1843 return 0;
1844 }
1845
1846 void dhd_del_if(dhd_info_t *dhd, int ifidx)
1847 {
1848 dhd_if_t *ifp;
1849
1850 DHD_TRACE(("%s: idx %d\n", __func__, ifidx));
1851
1852 ASSERT(dhd && ifidx && (ifidx < DHD_MAX_IFS));
1853 ifp = dhd->iflist[ifidx];
1854 if (!ifp) {
1855 DHD_ERROR(("%s: Null interface\n", __func__));
1856 return;
1857 }
1858
1859 ifp->state = WLC_E_IF_DEL;
1860 ifp->idx = ifidx;
1861 ASSERT(dhd->sysioc_tsk);
1862 up(&dhd->sysioc_sem);
1863 }
1864
1865 dhd_pub_t *dhd_attach(struct dhd_bus *bus, uint bus_hdrlen)
1866 {
1867 dhd_info_t *dhd = NULL;
1868 struct net_device *net;
1869
1870 DHD_TRACE(("%s: Enter\n", __func__));
1871 /* updates firmware nvram path if it was provided as module
1872 paramters */
1873 if ((firmware_path != NULL) && (firmware_path[0] != '\0'))
1874 strcpy(fw_path, firmware_path);
1875 if ((nvram_path != NULL) && (nvram_path[0] != '\0'))
1876 strcpy(nv_path, nvram_path);
1877
1878 /* Allocate etherdev, including space for private structure */
1879 net = alloc_etherdev(sizeof(dhd));
1880 if (!net) {
1881 DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__));
1882 goto fail;
1883 }
1884
1885 /* Allocate primary dhd_info */
1886 dhd = kzalloc(sizeof(dhd_info_t), GFP_ATOMIC);
1887 if (!dhd) {
1888 DHD_ERROR(("%s: OOM - alloc dhd_info\n", __func__));
1889 goto fail;
1890 }
1891
1892 /*
1893 * Save the dhd_info into the priv
1894 */
1895 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
1896
1897 /* Set network interface name if it was provided as module parameter */
1898 if (iface_name[0]) {
1899 int len;
1900 char ch;
1901 strncpy(net->name, iface_name, IFNAMSIZ);
1902 net->name[IFNAMSIZ - 1] = 0;
1903 len = strlen(net->name);
1904 ch = net->name[len - 1];
1905 if ((ch > '9' || ch < '0') && (len < IFNAMSIZ - 2))
1906 strcat(net->name, "%d");
1907 }
1908
1909 if (dhd_add_if(dhd, 0, (void *)net, net->name, NULL, 0, 0) ==
1910 DHD_BAD_IF)
1911 goto fail;
1912
1913 net->netdev_ops = NULL;
1914 sema_init(&dhd->proto_sem, 1);
1915 /* Initialize other structure content */
1916 init_waitqueue_head(&dhd->ioctl_resp_wait);
1917 init_waitqueue_head(&dhd->ctrl_wait);
1918
1919 /* Initialize the spinlocks */
1920 spin_lock_init(&dhd->sdlock);
1921 spin_lock_init(&dhd->txqlock);
1922
1923 /* Link to info module */
1924 dhd->pub.info = dhd;
1925
1926 /* Link to bus module */
1927 dhd->pub.bus = bus;
1928 dhd->pub.hdrlen = bus_hdrlen;
1929
1930 /* Attach and link in the protocol */
1931 if (dhd_prot_attach(&dhd->pub) != 0) {
1932 DHD_ERROR(("dhd_prot_attach failed\n"));
1933 goto fail;
1934 }
1935 #if defined(CONFIG_WIRELESS_EXT)
1936 /* Attach and link in the iw */
1937 if (wl_iw_attach(net, (void *)&dhd->pub) != 0) {
1938 DHD_ERROR(("wl_iw_attach failed\n"));
1939 goto fail;
1940 }
1941 #endif /* defined(CONFIG_WIRELESS_EXT) */
1942
1943 /* Attach and link in the cfg80211 */
1944 if (IS_CFG80211_FAVORITE()) {
1945 if (unlikely(wl_cfg80211_attach(net, &dhd->pub))) {
1946 DHD_ERROR(("wl_cfg80211_attach failed\n"));
1947 goto fail;
1948 }
1949 if (!NO_FW_REQ()) {
1950 strcpy(fw_path, wl_cfg80211_get_fwname());
1951 strcpy(nv_path, wl_cfg80211_get_nvramname());
1952 }
1953 }
1954
1955 /* Set up the watchdog timer */
1956 init_timer(&dhd->timer);
1957 dhd->timer.data = (unsigned long) dhd;
1958 dhd->timer.function = dhd_watchdog;
1959
1960 /* Initialize thread based operation and lock */
1961 sema_init(&dhd->sdsem, 1);
1962 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0))
1963 dhd->threads_only = true;
1964 else
1965 dhd->threads_only = false;
1966
1967 if (dhd_dpc_prio >= 0) {
1968 /* Initialize watchdog thread */
1969 sema_init(&dhd->watchdog_sem, 0);
1970 dhd->watchdog_tsk = kthread_run(dhd_watchdog_thread, dhd,
1971 "dhd_watchdog");
1972 if (IS_ERR(dhd->watchdog_tsk)) {
1973 printk(KERN_WARNING
1974 "dhd_watchdog thread failed to start\n");
1975 dhd->watchdog_tsk = NULL;
1976 }
1977 } else {
1978 dhd->watchdog_tsk = NULL;
1979 }
1980
1981 /* Set up the bottom half handler */
1982 if (dhd_dpc_prio >= 0) {
1983 /* Initialize DPC thread */
1984 sema_init(&dhd->dpc_sem, 0);
1985 dhd->dpc_tsk = kthread_run(dhd_dpc_thread, dhd, "dhd_dpc");
1986 if (IS_ERR(dhd->dpc_tsk)) {
1987 printk(KERN_WARNING
1988 "dhd_dpc thread failed to start\n");
1989 dhd->dpc_tsk = NULL;
1990 }
1991 } else {
1992 tasklet_init(&dhd->tasklet, dhd_dpc, (unsigned long) dhd);
1993 dhd->dpc_tsk = NULL;
1994 }
1995
1996 if (dhd_sysioc) {
1997 sema_init(&dhd->sysioc_sem, 0);
1998 dhd->sysioc_tsk = kthread_run(_dhd_sysioc_thread, dhd,
1999 "_dhd_sysioc");
2000 if (IS_ERR(dhd->sysioc_tsk)) {
2001 printk(KERN_WARNING
2002 "_dhd_sysioc thread failed to start\n");
2003 dhd->sysioc_tsk = NULL;
2004 }
2005 } else
2006 dhd->sysioc_tsk = NULL;
2007
2008 /*
2009 * Save the dhd_info into the priv
2010 */
2011 memcpy(netdev_priv(net), &dhd, sizeof(dhd));
2012
2013 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2014 g_bus = bus;
2015 #endif
2016 #if defined(CONFIG_PM_SLEEP)
2017 atomic_set(&dhd_mmc_suspend, false);
2018 if (!IS_CFG80211_FAVORITE())
2019 register_pm_notifier(&dhd_sleep_pm_notifier);
2020 #endif /* defined(CONFIG_PM_SLEEP) */
2021 /* && defined(DHD_GPL) */
2022 /* Init lock suspend to prevent kernel going to suspend */
2023 #ifdef CONFIG_HAS_EARLYSUSPEND
2024 dhd->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 20;
2025 dhd->early_suspend.suspend = dhd_early_suspend;
2026 dhd->early_suspend.resume = dhd_late_resume;
2027 register_early_suspend(&dhd->early_suspend);
2028 #endif
2029
2030 return &dhd->pub;
2031
2032 fail:
2033 if (net)
2034 free_netdev(net);
2035 if (dhd)
2036 dhd_detach(&dhd->pub);
2037
2038 return NULL;
2039 }
2040
2041 int dhd_bus_start(dhd_pub_t *dhdp)
2042 {
2043 int ret = -1;
2044 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
2045 #ifdef EMBEDDED_PLATFORM
2046 char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" +
2047 '\0' + bitvec */
2048 #endif /* EMBEDDED_PLATFORM */
2049
2050 ASSERT(dhd);
2051
2052 DHD_TRACE(("%s:\n", __func__));
2053
2054 /* try to download image and nvram to the dongle */
2055 if (dhd->pub.busstate == DHD_BUS_DOWN) {
2056 if (!(dhd_bus_download_firmware(dhd->pub.bus,
2057 fw_path, nv_path))) {
2058 DHD_ERROR(("%s: dhdsdio_probe_download failed. "
2059 "firmware = %s nvram = %s\n",
2060 __func__, fw_path, nv_path));
2061 return -1;
2062 }
2063 }
2064
2065 /* Start the watchdog timer */
2066 dhd->pub.tickcnt = 0;
2067 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2068
2069 /* Bring up the bus */
2070 ret = dhd_bus_init(&dhd->pub, true);
2071 if (ret != 0) {
2072 DHD_ERROR(("%s, dhd_bus_init failed %d\n", __func__, ret));
2073 return ret;
2074 }
2075 #if defined(OOB_INTR_ONLY)
2076 /* Host registration for OOB interrupt */
2077 if (bcmsdh_register_oob_intr(dhdp)) {
2078 del_timer_sync(&dhd->timer);
2079 dhd->wd_timer_valid = false;
2080 DHD_ERROR(("%s Host failed to resgister for OOB\n", __func__));
2081 return -ENODEV;
2082 }
2083
2084 /* Enable oob at firmware */
2085 dhd_enable_oob_intr(dhd->pub.bus, true);
2086 #endif /* defined(OOB_INTR_ONLY) */
2087
2088 /* If bus is not ready, can't come up */
2089 if (dhd->pub.busstate != DHD_BUS_DATA) {
2090 del_timer_sync(&dhd->timer);
2091 dhd->wd_timer_valid = false;
2092 DHD_ERROR(("%s failed bus is not ready\n", __func__));
2093 return -ENODEV;
2094 }
2095 #ifdef EMBEDDED_PLATFORM
2096 brcmu_mkiovar("event_msgs", dhdp->eventmask, WL_EVENTING_MASK_LEN,
2097 iovbuf, sizeof(iovbuf));
2098 dhdcdc_query_ioctl(dhdp, 0, WLC_GET_VAR, iovbuf, sizeof(iovbuf));
2099 memcpy(dhdp->eventmask, iovbuf, WL_EVENTING_MASK_LEN);
2100
2101 setbit(dhdp->eventmask, WLC_E_SET_SSID);
2102 setbit(dhdp->eventmask, WLC_E_PRUNE);
2103 setbit(dhdp->eventmask, WLC_E_AUTH);
2104 setbit(dhdp->eventmask, WLC_E_REASSOC);
2105 setbit(dhdp->eventmask, WLC_E_REASSOC_IND);
2106 setbit(dhdp->eventmask, WLC_E_DEAUTH_IND);
2107 setbit(dhdp->eventmask, WLC_E_DISASSOC_IND);
2108 setbit(dhdp->eventmask, WLC_E_DISASSOC);
2109 setbit(dhdp->eventmask, WLC_E_JOIN);
2110 setbit(dhdp->eventmask, WLC_E_ASSOC_IND);
2111 setbit(dhdp->eventmask, WLC_E_PSK_SUP);
2112 setbit(dhdp->eventmask, WLC_E_LINK);
2113 setbit(dhdp->eventmask, WLC_E_NDIS_LINK);
2114 setbit(dhdp->eventmask, WLC_E_MIC_ERROR);
2115 setbit(dhdp->eventmask, WLC_E_PMKID_CACHE);
2116 setbit(dhdp->eventmask, WLC_E_TXFAIL);
2117 setbit(dhdp->eventmask, WLC_E_JOIN_START);
2118 setbit(dhdp->eventmask, WLC_E_SCAN_COMPLETE);
2119 #ifdef PNO_SUPPORT
2120 setbit(dhdp->eventmask, WLC_E_PFN_NET_FOUND);
2121 #endif /* PNO_SUPPORT */
2122
2123 /* enable dongle roaming event */
2124
2125 dhdp->pktfilter_count = 1;
2126 /* Setup filter to allow only unicast */
2127 dhdp->pktfilter[0] = "100 0 0 0 0x01 0x00";
2128 #endif /* EMBEDDED_PLATFORM */
2129
2130 /* Bus is ready, do any protocol initialization */
2131 ret = dhd_prot_init(&dhd->pub);
2132 if (ret < 0)
2133 return ret;
2134
2135 return 0;
2136 }
2137
2138 int
2139 dhd_iovar(dhd_pub_t *pub, int ifidx, char *name, char *cmd_buf, uint cmd_len,
2140 int set)
2141 {
2142 char buf[strlen(name) + 1 + cmd_len];
2143 int len = sizeof(buf);
2144 wl_ioctl_t ioc;
2145 int ret;
2146
2147 len = brcmu_mkiovar(name, cmd_buf, cmd_len, buf, len);
2148
2149 memset(&ioc, 0, sizeof(ioc));
2150
2151 ioc.cmd = set ? WLC_SET_VAR : WLC_GET_VAR;
2152 ioc.buf = buf;
2153 ioc.len = len;
2154 ioc.set = set;
2155
2156 ret = dhd_prot_ioctl(pub, ifidx, &ioc, ioc.buf, ioc.len);
2157 if (!set && ret >= 0)
2158 memcpy(cmd_buf, buf, cmd_len);
2159
2160 return ret;
2161 }
2162
2163 static struct net_device_ops dhd_ops_pri = {
2164 .ndo_open = dhd_open,
2165 .ndo_stop = dhd_stop,
2166 .ndo_get_stats = dhd_get_stats,
2167 .ndo_do_ioctl = dhd_ioctl_entry,
2168 .ndo_start_xmit = dhd_start_xmit,
2169 .ndo_set_mac_address = dhd_set_mac_address,
2170 .ndo_set_multicast_list = dhd_set_multicast_list
2171 };
2172
2173 int dhd_net_attach(dhd_pub_t *dhdp, int ifidx)
2174 {
2175 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
2176 struct net_device *net;
2177 u8 temp_addr[ETH_ALEN] = {
2178 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
2179
2180 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
2181
2182 ASSERT(dhd && dhd->iflist[ifidx]);
2183
2184 net = dhd->iflist[ifidx]->net;
2185 ASSERT(net);
2186
2187 ASSERT(!net->netdev_ops);
2188 net->netdev_ops = &dhd_ops_pri;
2189
2190 /*
2191 * We have to use the primary MAC for virtual interfaces
2192 */
2193 if (ifidx != 0) {
2194 /* for virtual interfaces use the primary MAC */
2195 memcpy(temp_addr, dhd->pub.mac, ETH_ALEN);
2196
2197 }
2198
2199 if (ifidx == 1) {
2200 DHD_TRACE(("%s ACCESS POINT MAC: \n", __func__));
2201 /* ACCESSPOINT INTERFACE CASE */
2202 temp_addr[0] |= 0X02; /* set bit 2 ,
2203 - Locally Administered address */
2204
2205 }
2206 net->hard_header_len = ETH_HLEN + dhd->pub.hdrlen;
2207 net->ethtool_ops = &dhd_ethtool_ops;
2208
2209 dhd->pub.rxsz = net->mtu + net->hard_header_len + dhd->pub.hdrlen;
2210
2211 memcpy(net->dev_addr, temp_addr, ETH_ALEN);
2212
2213 if (register_netdev(net) != 0) {
2214 DHD_ERROR(("%s: couldn't register the net device\n",
2215 __func__));
2216 goto fail;
2217 }
2218
2219 DHD_INFO(("%s: Broadcom Dongle Host Driver\n", net->name));
2220
2221 return 0;
2222
2223 fail:
2224 net->netdev_ops = NULL;
2225 return -EBADE;
2226 }
2227
2228 void dhd_bus_detach(dhd_pub_t *dhdp)
2229 {
2230 dhd_info_t *dhd;
2231
2232 DHD_TRACE(("%s: Enter\n", __func__));
2233
2234 if (dhdp) {
2235 dhd = (dhd_info_t *) dhdp->info;
2236 if (dhd) {
2237 /* Stop the protocol module */
2238 dhd_prot_stop(&dhd->pub);
2239
2240 /* Stop the bus module */
2241 dhd_bus_stop(dhd->pub.bus, true);
2242 #if defined(OOB_INTR_ONLY)
2243 bcmsdh_unregister_oob_intr();
2244 #endif /* defined(OOB_INTR_ONLY) */
2245
2246 /* Clear the watchdog timer */
2247 del_timer_sync(&dhd->timer);
2248 dhd->wd_timer_valid = false;
2249 }
2250 }
2251 }
2252
2253 void dhd_detach(dhd_pub_t *dhdp)
2254 {
2255 dhd_info_t *dhd;
2256
2257 DHD_TRACE(("%s: Enter\n", __func__));
2258
2259 if (dhdp) {
2260 dhd = (dhd_info_t *) dhdp->info;
2261 if (dhd) {
2262 dhd_if_t *ifp;
2263 int i;
2264
2265 #if defined(CONFIG_HAS_EARLYSUSPEND)
2266 if (dhd->early_suspend.suspend)
2267 unregister_early_suspend(&dhd->early_suspend);
2268 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2269
2270 for (i = 1; i < DHD_MAX_IFS; i++)
2271 if (dhd->iflist[i])
2272 dhd_del_if(dhd, i);
2273
2274 ifp = dhd->iflist[0];
2275 ASSERT(ifp);
2276 if (ifp->net->netdev_ops == &dhd_ops_pri) {
2277 dhd_stop(ifp->net);
2278 unregister_netdev(ifp->net);
2279 }
2280
2281 if (dhd->watchdog_tsk) {
2282 send_sig(SIGTERM, dhd->watchdog_tsk, 1);
2283 kthread_stop(dhd->watchdog_tsk);
2284 dhd->watchdog_tsk = NULL;
2285 }
2286
2287 if (dhd->dpc_tsk) {
2288 send_sig(SIGTERM, dhd->dpc_tsk, 1);
2289 kthread_stop(dhd->dpc_tsk);
2290 dhd->dpc_tsk = NULL;
2291 } else
2292 tasklet_kill(&dhd->tasklet);
2293
2294 if (dhd->sysioc_tsk) {
2295 send_sig(SIGTERM, dhd->sysioc_tsk, 1);
2296 kthread_stop(dhd->sysioc_tsk);
2297 dhd->sysioc_tsk = NULL;
2298 }
2299
2300 dhd_bus_detach(dhdp);
2301
2302 if (dhdp->prot)
2303 dhd_prot_detach(dhdp);
2304
2305 #if defined(CONFIG_WIRELESS_EXT)
2306 wl_iw_detach();
2307 #endif /* (CONFIG_WIRELESS_EXT) */
2308
2309 if (IS_CFG80211_FAVORITE())
2310 wl_cfg80211_detach();
2311
2312 #if defined(CONFIG_PM_SLEEP)
2313 if (!IS_CFG80211_FAVORITE())
2314 unregister_pm_notifier(&dhd_sleep_pm_notifier);
2315 #endif /* defined(CONFIG_PM_SLEEP) */
2316 /* && defined(DHD_GPL) */
2317 free_netdev(ifp->net);
2318 kfree(ifp);
2319 kfree(dhd);
2320 }
2321 }
2322 }
2323
2324 static void __exit dhd_module_cleanup(void)
2325 {
2326 DHD_TRACE(("%s: Enter\n", __func__));
2327
2328 dhd_bus_unregister();
2329 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2330 wifi_del_dev();
2331 #endif
2332 /* Call customer gpio to turn off power with WL_REG_ON signal */
2333 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2334 }
2335
2336 static int __init dhd_module_init(void)
2337 {
2338 int error;
2339
2340 DHD_TRACE(("%s: Enter\n", __func__));
2341
2342 /* Sanity check on the module parameters */
2343 do {
2344 /* Both watchdog and DPC as tasklets are ok */
2345 if ((dhd_watchdog_prio < 0) && (dhd_dpc_prio < 0))
2346 break;
2347
2348 /* If both watchdog and DPC are threads, TX must be deferred */
2349 if ((dhd_watchdog_prio >= 0) && (dhd_dpc_prio >= 0)
2350 && dhd_deferred_tx)
2351 break;
2352
2353 DHD_ERROR(("Invalid module parameters.\n"));
2354 return -EINVAL;
2355 } while (0);
2356 /* Call customer gpio to turn on power with WL_REG_ON signal */
2357 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_ON);
2358
2359 #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC)
2360 sema_init(&wifi_control_sem, 0);
2361
2362 error = wifi_add_dev();
2363 if (error) {
2364 DHD_ERROR(("%s: platform_driver_register failed\n", __func__));
2365 goto failed;
2366 }
2367
2368 /* Waiting callback after platform_driver_register is done or
2369 exit with error */
2370 if (down_timeout(&wifi_control_sem, msecs_to_jiffies(1000)) != 0) {
2371 printk(KERN_ERR "%s: platform_driver_register timeout\n",
2372 __func__);
2373 /* remove device */
2374 wifi_del_dev();
2375 goto failed;
2376 }
2377 #endif /* #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) */
2378
2379 error = dhd_bus_register();
2380
2381 if (error) {
2382 DHD_ERROR(("%s: sdio_register_driver failed\n", __func__));
2383 goto failed;
2384 }
2385 return error;
2386
2387 failed:
2388 /* turn off power and exit */
2389 dhd_customer_gpio_wlan_ctrl(WLAN_POWER_OFF);
2390 return -EINVAL;
2391 }
2392
2393 module_init(dhd_module_init);
2394 module_exit(dhd_module_cleanup);
2395
2396 /*
2397 * OS specific functions required to implement DHD driver in OS independent way
2398 */
2399 int dhd_os_proto_block(dhd_pub_t *pub)
2400 {
2401 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2402
2403 if (dhd) {
2404 down(&dhd->proto_sem);
2405 return 1;
2406 }
2407 return 0;
2408 }
2409
2410 int dhd_os_proto_unblock(dhd_pub_t *pub)
2411 {
2412 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2413
2414 if (dhd) {
2415 up(&dhd->proto_sem);
2416 return 1;
2417 }
2418
2419 return 0;
2420 }
2421
2422 unsigned int dhd_os_get_ioctl_resp_timeout(void)
2423 {
2424 return (unsigned int)dhd_ioctl_timeout_msec;
2425 }
2426
2427 void dhd_os_set_ioctl_resp_timeout(unsigned int timeout_msec)
2428 {
2429 dhd_ioctl_timeout_msec = (int)timeout_msec;
2430 }
2431
2432 int dhd_os_ioctl_resp_wait(dhd_pub_t *pub, uint *condition, bool *pending)
2433 {
2434 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2435 DECLARE_WAITQUEUE(wait, current);
2436 int timeout = dhd_ioctl_timeout_msec;
2437
2438 /* Convert timeout in millsecond to jiffies */
2439 timeout = timeout * HZ / 1000;
2440
2441 /* Wait until control frame is available */
2442 add_wait_queue(&dhd->ioctl_resp_wait, &wait);
2443 set_current_state(TASK_INTERRUPTIBLE);
2444
2445 while (!(*condition) && (!signal_pending(current) && timeout))
2446 timeout = schedule_timeout(timeout);
2447
2448 if (signal_pending(current))
2449 *pending = true;
2450
2451 set_current_state(TASK_RUNNING);
2452 remove_wait_queue(&dhd->ioctl_resp_wait, &wait);
2453
2454 return timeout;
2455 }
2456
2457 int dhd_os_ioctl_resp_wake(dhd_pub_t *pub)
2458 {
2459 dhd_info_t *dhd = (dhd_info_t *) (pub->info);
2460
2461 if (waitqueue_active(&dhd->ioctl_resp_wait))
2462 wake_up_interruptible(&dhd->ioctl_resp_wait);
2463
2464 return 0;
2465 }
2466
2467 void dhd_os_wd_timer(void *bus, uint wdtick)
2468 {
2469 dhd_pub_t *pub = bus;
2470 static uint save_dhd_watchdog_ms;
2471 dhd_info_t *dhd = (dhd_info_t *) pub->info;
2472
2473 /* don't start the wd until fw is loaded */
2474 if (pub->busstate == DHD_BUS_DOWN)
2475 return;
2476
2477 /* Totally stop the timer */
2478 if (!wdtick && dhd->wd_timer_valid == true) {
2479 del_timer_sync(&dhd->timer);
2480 dhd->wd_timer_valid = false;
2481 save_dhd_watchdog_ms = wdtick;
2482 return;
2483 }
2484
2485 if (wdtick) {
2486 dhd_watchdog_ms = (uint) wdtick;
2487
2488 if (save_dhd_watchdog_ms != dhd_watchdog_ms) {
2489
2490 if (dhd->wd_timer_valid == true)
2491 /* Stop timer and restart at new value */
2492 del_timer_sync(&dhd->timer);
2493
2494 /* Create timer again when watchdog period is
2495 dynamically changed or in the first instance
2496 */
2497 dhd->timer.expires =
2498 jiffies + dhd_watchdog_ms * HZ / 1000;
2499 add_timer(&dhd->timer);
2500
2501 } else {
2502 /* Re arm the timer, at last watchdog period */
2503 mod_timer(&dhd->timer,
2504 jiffies + dhd_watchdog_ms * HZ / 1000);
2505 }
2506
2507 dhd->wd_timer_valid = true;
2508 save_dhd_watchdog_ms = wdtick;
2509 }
2510 }
2511
2512 void *dhd_os_open_image(char *filename)
2513 {
2514 struct file *fp;
2515
2516 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2517 return wl_cfg80211_request_fw(filename);
2518
2519 fp = filp_open(filename, O_RDONLY, 0);
2520 /*
2521 * 2.6.11 (FC4) supports filp_open() but later revs don't?
2522 * Alternative:
2523 * fp = open_namei(AT_FDCWD, filename, O_RD, 0);
2524 * ???
2525 */
2526 if (IS_ERR(fp))
2527 fp = NULL;
2528
2529 return fp;
2530 }
2531
2532 int dhd_os_get_image_block(char *buf, int len, void *image)
2533 {
2534 struct file *fp = (struct file *)image;
2535 int rdlen;
2536
2537 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2538 return wl_cfg80211_read_fw(buf, len);
2539
2540 if (!image)
2541 return 0;
2542
2543 rdlen = kernel_read(fp, fp->f_pos, buf, len);
2544 if (rdlen > 0)
2545 fp->f_pos += rdlen;
2546
2547 return rdlen;
2548 }
2549
2550 void dhd_os_close_image(void *image)
2551 {
2552 if (IS_CFG80211_FAVORITE() && !NO_FW_REQ())
2553 return wl_cfg80211_release_fw();
2554 if (image)
2555 filp_close((struct file *)image, NULL);
2556 }
2557
2558 void dhd_os_sdlock(dhd_pub_t *pub)
2559 {
2560 dhd_info_t *dhd;
2561
2562 dhd = (dhd_info_t *) (pub->info);
2563
2564 if (dhd->threads_only)
2565 down(&dhd->sdsem);
2566 else
2567 spin_lock_bh(&dhd->sdlock);
2568 }
2569
2570 void dhd_os_sdunlock(dhd_pub_t *pub)
2571 {
2572 dhd_info_t *dhd;
2573
2574 dhd = (dhd_info_t *) (pub->info);
2575
2576 if (dhd->threads_only)
2577 up(&dhd->sdsem);
2578 else
2579 spin_unlock_bh(&dhd->sdlock);
2580 }
2581
2582 void dhd_os_sdlock_txq(dhd_pub_t *pub)
2583 {
2584 dhd_info_t *dhd;
2585
2586 dhd = (dhd_info_t *) (pub->info);
2587 spin_lock_bh(&dhd->txqlock);
2588 }
2589
2590 void dhd_os_sdunlock_txq(dhd_pub_t *pub)
2591 {
2592 dhd_info_t *dhd;
2593
2594 dhd = (dhd_info_t *) (pub->info);
2595 spin_unlock_bh(&dhd->txqlock);
2596 }
2597
2598 static int
2599 dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata,
2600 wl_event_msg_t *event, void **data)
2601 {
2602 int bcmerror = 0;
2603
2604 ASSERT(dhd != NULL);
2605
2606 bcmerror = wl_host_event(dhd, ifidx, pktdata, event, data);
2607 if (bcmerror != 0)
2608 return bcmerror;
2609
2610 #if defined(CONFIG_WIRELESS_EXT)
2611 if (!IS_CFG80211_FAVORITE()) {
2612 if ((dhd->iflist[*ifidx] == NULL)
2613 || (dhd->iflist[*ifidx]->net == NULL)) {
2614 DHD_ERROR(("%s Exit null pointer\n", __func__));
2615 return bcmerror;
2616 }
2617
2618 if (dhd->iflist[*ifidx]->net)
2619 wl_iw_event(dhd->iflist[*ifidx]->net, event, *data);
2620 }
2621 #endif /* defined(CONFIG_WIRELESS_EXT) */
2622
2623 if (IS_CFG80211_FAVORITE()) {
2624 ASSERT(dhd->iflist[*ifidx] != NULL);
2625 ASSERT(dhd->iflist[*ifidx]->net != NULL);
2626 if (dhd->iflist[*ifidx]->net)
2627 wl_cfg80211_event(dhd->iflist[*ifidx]->net, event,
2628 *data);
2629 }
2630
2631 return bcmerror;
2632 }
2633
2634 /* send up locally generated event */
2635 void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, void *data)
2636 {
2637 switch (be32_to_cpu(event->event_type)) {
2638 default:
2639 break;
2640 }
2641 }
2642
2643 void dhd_wait_for_event(dhd_pub_t *dhd, bool *lockvar)
2644 {
2645 struct dhd_info *dhdinfo = dhd->info;
2646 dhd_os_sdunlock(dhd);
2647 wait_event_interruptible_timeout(dhdinfo->ctrl_wait,
2648 (*lockvar == false), HZ * 2);
2649 dhd_os_sdlock(dhd);
2650 return;
2651 }
2652
2653 void dhd_wait_event_wakeup(dhd_pub_t *dhd)
2654 {
2655 struct dhd_info *dhdinfo = dhd->info;
2656 if (waitqueue_active(&dhdinfo->ctrl_wait))
2657 wake_up_interruptible(&dhdinfo->ctrl_wait);
2658 return;
2659 }
2660
2661 int dhd_dev_reset(struct net_device *dev, u8 flag)
2662 {
2663 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2664
2665 /* Turning off watchdog */
2666 if (flag)
2667 dhd_os_wd_timer(&dhd->pub, 0);
2668
2669 dhd_bus_devreset(&dhd->pub, flag);
2670
2671 /* Turning on watchdog back */
2672 if (!flag)
2673 dhd_os_wd_timer(&dhd->pub, dhd_watchdog_ms);
2674 DHD_ERROR(("%s: WLAN OFF DONE\n", __func__));
2675
2676 return 1;
2677 }
2678
2679 int net_os_set_suspend_disable(struct net_device *dev, int val)
2680 {
2681 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2682 int ret = 0;
2683
2684 if (dhd) {
2685 ret = dhd->pub.suspend_disable_flag;
2686 dhd->pub.suspend_disable_flag = val;
2687 }
2688 return ret;
2689 }
2690
2691 int net_os_set_suspend(struct net_device *dev, int val)
2692 {
2693 int ret = 0;
2694 #if defined(CONFIG_HAS_EARLYSUSPEND)
2695 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2696
2697 if (dhd) {
2698 dhd_os_proto_block(&dhd->pub);
2699 ret = dhd_set_suspend(val, &dhd->pub);
2700 dhd_os_proto_unblock(&dhd->pub);
2701 }
2702 #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */
2703 return ret;
2704 }
2705
2706 int net_os_set_dtim_skip(struct net_device *dev, int val)
2707 {
2708 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2709
2710 if (dhd)
2711 dhd->pub.dtim_skip = val;
2712
2713 return 0;
2714 }
2715
2716 int net_os_set_packet_filter(struct net_device *dev, int val)
2717 {
2718 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(dev);
2719 int ret = 0;
2720
2721 /* Packet filtering is set only if we still in early-suspend and
2722 * we need either to turn it ON or turn it OFF
2723 * We can always turn it OFF in case of early-suspend, but we turn it
2724 * back ON only if suspend_disable_flag was not set
2725 */
2726 if (dhd && dhd->pub.up) {
2727 dhd_os_proto_block(&dhd->pub);
2728 if (dhd->pub.in_suspend) {
2729 if (!val || (val && !dhd->pub.suspend_disable_flag))
2730 dhd_set_packet_filter(val, &dhd->pub);
2731 }
2732 dhd_os_proto_unblock(&dhd->pub);
2733 }
2734 return ret;
2735 }
2736
2737 void dhd_dev_init_ioctl(struct net_device *dev)
2738 {
2739 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2740
2741 dhd_preinit_ioctls(&dhd->pub);
2742 }
2743
2744 #ifdef PNO_SUPPORT
2745 /* Linux wrapper to call common dhd_pno_clean */
2746 int dhd_dev_pno_reset(struct net_device *dev)
2747 {
2748 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2749
2750 return dhd_pno_clean(&dhd->pub);
2751 }
2752
2753 /* Linux wrapper to call common dhd_pno_enable */
2754 int dhd_dev_pno_enable(struct net_device *dev, int pfn_enabled)
2755 {
2756 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2757
2758 return dhd_pno_enable(&dhd->pub, pfn_enabled);
2759 }
2760
2761 /* Linux wrapper to call common dhd_pno_set */
2762 int
2763 dhd_dev_pno_set(struct net_device *dev, wlc_ssid_t *ssids_local, int nssid,
2764 unsigned char scan_fr)
2765 {
2766 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2767
2768 return dhd_pno_set(&dhd->pub, ssids_local, nssid, scan_fr);
2769 }
2770
2771 /* Linux wrapper to get pno status */
2772 int dhd_dev_get_pno_status(struct net_device *dev)
2773 {
2774 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2775
2776 return dhd_pno_get_status(&dhd->pub);
2777 }
2778
2779 #endif /* PNO_SUPPORT */
2780
2781 static int dhd_get_pend_8021x_cnt(dhd_info_t *dhd)
2782 {
2783 return atomic_read(&dhd->pend_8021x_cnt);
2784 }
2785
2786 #define MAX_WAIT_FOR_8021X_TX 10
2787
2788 int dhd_wait_pend8021x(struct net_device *dev)
2789 {
2790 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(dev);
2791 int timeout = 10 * HZ / 1000;
2792 int ntimes = MAX_WAIT_FOR_8021X_TX;
2793 int pend = dhd_get_pend_8021x_cnt(dhd);
2794
2795 while (ntimes && pend) {
2796 if (pend) {
2797 set_current_state(TASK_INTERRUPTIBLE);
2798 schedule_timeout(timeout);
2799 set_current_state(TASK_RUNNING);
2800 ntimes--;
2801 }
2802 pend = dhd_get_pend_8021x_cnt(dhd);
2803 }
2804 return pend;
2805 }
2806
2807 void wl_os_wd_timer(struct net_device *ndev, uint wdtick)
2808 {
2809 dhd_info_t *dhd = *(dhd_info_t **)netdev_priv(ndev);
2810
2811 dhd_os_wd_timer(&dhd->pub, wdtick);
2812 }
2813
2814 #ifdef DHD_DEBUG
2815 int write_to_file(dhd_pub_t *dhd, u8 *buf, int size)
2816 {
2817 int ret = 0;
2818 struct file *fp;
2819 mm_segment_t old_fs;
2820 loff_t pos = 0;
2821
2822 /* change to KERNEL_DS address limit */
2823 old_fs = get_fs();
2824 set_fs(KERNEL_DS);
2825
2826 /* open file to write */
2827 fp = filp_open("/tmp/mem_dump", O_WRONLY | O_CREAT, 0640);
2828 if (!fp) {
2829 DHD_ERROR(("%s: open file error\n", __func__));
2830 ret = -1;
2831 goto exit;
2832 }
2833
2834 /* Write buf to file */
2835 fp->f_op->write(fp, buf, size, &pos);
2836
2837 exit:
2838 /* free buf before return */
2839 kfree(buf);
2840 /* close file before return */
2841 if (fp)
2842 filp_close(fp, current->files);
2843 /* restore previous address limit */
2844 set_fs(old_fs);
2845
2846 return ret;
2847 }
2848 #endif /* DHD_DEBUG */
This page took 0.090406 seconds and 6 git commands to generate.