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