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