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 | ||
cf2b4488 HP |
17 | #include <linux/init.h> |
18 | #include <linux/kernel.h> | |
860708d9 | 19 | #include <linux/kthread.h> |
cf2b4488 HP |
20 | #include <linux/slab.h> |
21 | #include <linux/skbuff.h> | |
22 | #include <linux/netdevice.h> | |
23 | #include <linux/etherdevice.h> | |
93ad12cf | 24 | #include <linux/mmc/sdio_func.h> |
cf2b4488 HP |
25 | #include <linux/random.h> |
26 | #include <linux/spinlock.h> | |
27 | #include <linux/ethtool.h> | |
28 | #include <linux/fcntl.h> | |
29 | #include <linux/fs.h> | |
93ad12cf | 30 | #include <linux/uaccess.h> |
583c3827 | 31 | #include <net/cfg80211.h> |
e51b3e52 AS |
32 | #if defined(CONFIG_HAS_EARLYSUSPEND) |
33 | #include <linux/earlysuspend.h> | |
34 | #endif | |
cc3cea5a | 35 | #include <defs.h> |
f97e956a RV |
36 | #include <brcmu_utils.h> |
37 | #include <brcmu_wifi.h> | |
cf2b4488 | 38 | |
c4daa849 RV |
39 | #include "dngl_stats.h" |
40 | #include "dhd.h" | |
41 | #include "dhd_bus.h" | |
42 | #include "dhd_proto.h" | |
43 | #include "dhd_dbg.h" | |
44 | #include "wl_cfg80211.h" | |
b7859cd9 | 45 | #include "bcmchip.h" |
cf2b4488 | 46 | |
47a6d2cd AS |
47 | /* Global ASSERT type flag */ |
48 | u32 g_assert_type; | |
49 | ||
cf2b4488 HP |
50 | #if defined(CONFIG_PM_SLEEP) |
51 | #include <linux/suspend.h> | |
8d825a8e | 52 | atomic_t brcmf_mmc_suspend; |
cf2b4488 HP |
53 | DECLARE_WAIT_QUEUE_HEAD(dhd_dpc_wait); |
54 | #endif /* defined(CONFIG_PM_SLEEP) */ | |
55 | ||
cf2b4488 HP |
56 | MODULE_AUTHOR("Broadcom Corporation"); |
57 | MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN fullmac driver."); | |
58 | MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN fullmac cards"); | |
59 | MODULE_LICENSE("Dual BSD/GPL"); | |
60 | ||
cf2b4488 HP |
61 | |
62 | /* Interface control information */ | |
abfe1804 AS |
63 | struct brcmf_if { |
64 | struct brcmf_info *info; /* back pointer to brcmf_info */ | |
cf2b4488 HP |
65 | /* OS/stack specifics */ |
66 | struct net_device *net; | |
67 | struct net_device_stats stats; | |
68 | int idx; /* iface idx in dongle */ | |
69 | int state; /* interface state */ | |
70 | uint subunit; /* subunit */ | |
b8d63078 | 71 | u8 mac_addr[ETH_ALEN]; /* assigned MAC address */ |
cf2b4488 HP |
72 | bool attached; /* Delayed attachment when unset */ |
73 | bool txflowcontrol; /* Per interface flow control indicator */ | |
cbf6baac | 74 | char name[IFNAMSIZ]; /* linux interface name */ |
abfe1804 | 75 | }; |
cf2b4488 HP |
76 | |
77 | /* Local private structure (extension of pub) */ | |
abfe1804 | 78 | struct brcmf_info { |
fb1d0aa2 | 79 | struct brcmf_pub pub; |
cf2b4488 HP |
80 | |
81 | /* OS/stack specifics */ | |
abfe1804 | 82 | struct brcmf_if *iflist[BRCMF_MAX_IFS]; |
cf2b4488 HP |
83 | |
84 | struct semaphore proto_sem; | |
85 | wait_queue_head_t ioctl_resp_wait; | |
cf2b4488 HP |
86 | |
87 | /* Thread to issue ioctl for multicast */ | |
d809dcb9 | 88 | struct task_struct *sysioc_tsk; |
cf2b4488 | 89 | struct semaphore sysioc_sem; |
cf2b4488 HP |
90 | bool set_multicast; |
91 | bool set_macaddress; | |
a44d4236 | 92 | u8 macvalue[ETH_ALEN]; |
cf2b4488 HP |
93 | atomic_t pend_8021x_cnt; |
94 | ||
95 | #ifdef CONFIG_HAS_EARLYSUSPEND | |
96 | struct early_suspend early_suspend; | |
97 | #endif /* CONFIG_HAS_EARLYSUSPEND */ | |
abfe1804 | 98 | }; |
cf2b4488 | 99 | |
cf2b4488 | 100 | /* Error bits */ |
aba5e0ad | 101 | module_param(brcmf_msg_level, int, 0); |
cf2b4488 HP |
102 | |
103 | /* Spawn a thread for system ioctls (set mac, set mcast) */ | |
7af9d0ca AS |
104 | uint brcmf_sysioc = true; |
105 | module_param(brcmf_sysioc, uint, 0); | |
cf2b4488 | 106 | |
cf2b4488 HP |
107 | /* ARP offload agent mode : Enable ARP Host Auto-Reply |
108 | and ARP Peer Auto-Reply */ | |
5e92aa8c AS |
109 | uint brcmf_arp_mode = 0xb; |
110 | module_param(brcmf_arp_mode, uint, 0); | |
cf2b4488 HP |
111 | |
112 | /* ARP offload enable */ | |
5e92aa8c AS |
113 | uint brcmf_arp_enable = true; |
114 | module_param(brcmf_arp_enable, uint, 0); | |
cf2b4488 HP |
115 | |
116 | /* Global Pkt filter enable control */ | |
5e92aa8c AS |
117 | uint brcmf_pkt_filter_enable = true; |
118 | module_param(brcmf_pkt_filter_enable, uint, 0); | |
cf2b4488 HP |
119 | |
120 | /* Pkt filter init setup */ | |
5e92aa8c AS |
121 | uint brcmf_pkt_filter_init; |
122 | module_param(brcmf_pkt_filter_init, uint, 0); | |
cf2b4488 HP |
123 | |
124 | /* Pkt filter mode control */ | |
5e92aa8c AS |
125 | uint brcmf_master_mode = true; |
126 | module_param(brcmf_master_mode, uint, 1); | |
cf2b4488 | 127 | |
7af9d0ca AS |
128 | extern int brcmf_dongle_memsize; |
129 | module_param(brcmf_dongle_memsize, int, 0); | |
cf2b4488 HP |
130 | |
131 | /* Contorl fw roaming */ | |
5e92aa8c | 132 | uint brcmf_roam = 1; |
cf2b4488 HP |
133 | |
134 | /* Control radio state */ | |
5e92aa8c | 135 | uint brcmf_radio_up = 1; |
cf2b4488 HP |
136 | |
137 | /* Network inteface name */ | |
8343f180 | 138 | char iface_name[IFNAMSIZ] = "wlan"; |
cf2b4488 HP |
139 | module_param_string(iface_name, iface_name, IFNAMSIZ, 0); |
140 | ||
cf2b4488 HP |
141 | /* The following are specific to the SDIO dongle */ |
142 | ||
143 | /* IOCTL response timeout */ | |
7af9d0ca | 144 | int brcmf_ioctl_timeout_msec = IOCTL_RESP_TIMEOUT; |
cf2b4488 HP |
145 | |
146 | /* Idle timeout for backplane clock */ | |
5e92aa8c AS |
147 | int brcmf_idletime = BRCMF_IDLETIME_TICKS; |
148 | module_param(brcmf_idletime, int, 0); | |
cf2b4488 HP |
149 | |
150 | /* Use polling */ | |
5e92aa8c AS |
151 | uint brcmf_poll; |
152 | module_param(brcmf_poll, uint, 0); | |
cf2b4488 | 153 | |
cf2b4488 | 154 | /* Use interrupts */ |
5e92aa8c AS |
155 | uint brcmf_intr = true; |
156 | module_param(brcmf_intr, uint, 0); | |
cf2b4488 HP |
157 | |
158 | /* SDIO Drive Strength (in milliamps) */ | |
5e92aa8c AS |
159 | uint brcmf_sdiod_drive_strength = 6; |
160 | module_param(brcmf_sdiod_drive_strength, uint, 0); | |
cf2b4488 HP |
161 | |
162 | /* Tx/Rx bounds */ | |
7af9d0ca AS |
163 | extern uint brcmf_txbound; |
164 | extern uint brcmf_rxbound; | |
165 | module_param(brcmf_txbound, uint, 0); | |
166 | module_param(brcmf_rxbound, uint, 0); | |
cf2b4488 | 167 | |
cf2b4488 HP |
168 | #ifdef SDTEST |
169 | /* Echo packet generator (pkts/s) */ | |
5e92aa8c AS |
170 | uint brcmf_pktgen; |
171 | module_param(brcmf_pktgen, uint, 0); | |
cf2b4488 HP |
172 | |
173 | /* Echo packet len (0 => sawtooth, max 2040) */ | |
5e92aa8c AS |
174 | uint brcmf_pktgen_len; |
175 | module_param(brcmf_pktgen_len, uint, 0); | |
cf2b4488 HP |
176 | #endif |
177 | ||
cf2b4488 | 178 | /* Version string to report */ |
762c2a36 | 179 | #ifdef BCMDBG |
cf2b4488 HP |
180 | #define DHD_COMPILED "\nCompiled in " SRCBASE |
181 | #else | |
182 | #define DHD_COMPILED | |
183 | #endif | |
184 | ||
abfe1804 AS |
185 | static int brcmf_toe_get(struct brcmf_info *drvr_priv, int idx, u32 *toe_ol); |
186 | static int brcmf_toe_set(struct brcmf_info *drvr_priv, int idx, u32 toe_ol); | |
187 | static int brcmf_host_event(struct brcmf_info *drvr_priv, int *ifidx, void *pktdata, | |
63bec49e RV |
188 | struct brcmf_event_msg *event_ptr, |
189 | void **data_ptr); | |
cf2b4488 | 190 | |
cf2b4488 | 191 | #if defined(CONFIG_HAS_EARLYSUSPEND) |
fb1d0aa2 | 192 | static int brcmf_set_suspend(int value, struct brcmf_pub *drvr) |
cf2b4488 HP |
193 | { |
194 | int power_mode = PM_MAX; | |
ec66c6fa | 195 | /* struct wl_pkt_filter_enable enable_parm; */ |
cf2b4488 HP |
196 | char iovbuf[32]; |
197 | int bcn_li_dtim = 3; | |
cf2b4488 HP |
198 | |
199 | DHD_TRACE(("%s: enter, value = %d in_suspend=%d\n", | |
56d52fcc | 200 | __func__, value, drvr->in_suspend)); |
cf2b4488 | 201 | |
56d52fcc AS |
202 | if (drvr && drvr->up) { |
203 | if (value && drvr->in_suspend) { | |
cf2b4488 HP |
204 | |
205 | /* Kernel suspended */ | |
206 | DHD_TRACE(("%s: force extra Suspend setting\n", | |
207 | __func__)); | |
208 | ||
56d52fcc | 209 | brcmf_proto_cdc_set_ioctl(drvr, 0, BRCMF_C_SET_PM, |
cf2b4488 HP |
210 | (char *)&power_mode, |
211 | sizeof(power_mode)); | |
212 | ||
213 | /* Enable packet filter, only allow unicast | |
214 | packet to send up */ | |
56d52fcc | 215 | brcmf_set_packet_filter(1, drvr); |
cf2b4488 HP |
216 | |
217 | /* if dtim skip setup as default force it | |
25985edc | 218 | * to wake each third dtim |
cf2b4488 HP |
219 | * for better power saving. |
220 | * Note that side effect is chance to miss BC/MC | |
221 | * packet | |
222 | */ | |
56d52fcc | 223 | if ((drvr->dtim_skip == 0) || (drvr->dtim_skip == 1)) |
cf2b4488 HP |
224 | bcn_li_dtim = 3; |
225 | else | |
56d52fcc | 226 | bcn_li_dtim = drvr->dtim_skip; |
67ad48bc | 227 | brcmu_mkiovar("bcn_li_dtim", (char *)&bcn_li_dtim, |
cf2b4488 | 228 | 4, iovbuf, sizeof(iovbuf)); |
56d52fcc | 229 | brcmf_proto_cdc_set_ioctl(drvr, 0, BRCMF_C_SET_VAR, |
0aa94b84 | 230 | iovbuf, sizeof(iovbuf)); |
cf2b4488 HP |
231 | } else { |
232 | ||
233 | /* Kernel resumed */ | |
234 | DHD_TRACE(("%s: Remove extra suspend setting\n", | |
235 | __func__)); | |
236 | ||
237 | power_mode = PM_FAST; | |
56d52fcc AS |
238 | brcmf_proto_cdc_set_ioctl(drvr, 0, BRCMF_C_SET_PM, |
239 | (char *)&power_mode, | |
240 | sizeof(power_mode)); | |
cf2b4488 HP |
241 | |
242 | /* disable pkt filter */ | |
56d52fcc | 243 | brcmf_set_packet_filter(0, drvr); |
cf2b4488 HP |
244 | |
245 | /* restore pre-suspend setting for dtim_skip */ | |
56d52fcc | 246 | brcmu_mkiovar("bcn_li_dtim", (char *)&drvr->dtim_skip, |
cf2b4488 HP |
247 | 4, iovbuf, sizeof(iovbuf)); |
248 | ||
56d52fcc | 249 | brcmf_proto_cdc_set_ioctl(drvr, 0, BRCMF_C_SET_VAR, |
0aa94b84 | 250 | iovbuf, sizeof(iovbuf)); |
cf2b4488 HP |
251 | } |
252 | } | |
253 | ||
254 | return 0; | |
255 | } | |
256 | ||
abfe1804 | 257 | static void brcmf_suspend_resume_helper(struct brcmf_info *drvr_priv, int val) |
cf2b4488 | 258 | { |
fb1d0aa2 | 259 | struct brcmf_pub *drvr = &drvr_priv->pub; |
cf2b4488 | 260 | |
56d52fcc | 261 | brcmf_os_proto_block(drvr); |
cf2b4488 | 262 | /* Set flag when early suspend was called */ |
56d52fcc AS |
263 | drvr->in_suspend = val; |
264 | if (!drvr->suspend_disable_flag) | |
265 | brcmf_set_suspend(val, drvr); | |
266 | brcmf_os_proto_unblock(drvr); | |
cf2b4488 HP |
267 | } |
268 | ||
db62efcc | 269 | static void brcmf_early_suspend(struct early_suspend *h) |
cf2b4488 | 270 | { |
abfe1804 AS |
271 | struct brcmf_info *drvr_priv = |
272 | container_of(h, struct brcmf_info, early_suspend); | |
cf2b4488 HP |
273 | |
274 | DHD_TRACE(("%s: enter\n", __func__)); | |
275 | ||
56d52fcc AS |
276 | if (drvr_priv) |
277 | dhd_suspend_resume_helper(drvr_priv, 1); | |
cf2b4488 HP |
278 | |
279 | } | |
280 | ||
db62efcc | 281 | static void brcmf_late_resume(struct early_suspend *h) |
cf2b4488 | 282 | { |
abfe1804 AS |
283 | struct brcmf_info *drvr_priv = |
284 | container_of(h, struct brcmf_info, early_suspend); | |
cf2b4488 HP |
285 | |
286 | DHD_TRACE(("%s: enter\n", __func__)); | |
287 | ||
56d52fcc AS |
288 | if (drvr_priv) |
289 | dhd_suspend_resume_helper(drvr_priv, 0); | |
cf2b4488 HP |
290 | } |
291 | #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */ | |
292 | ||
293 | /* | |
294 | * Generalized timeout mechanism. Uses spin sleep with exponential | |
295 | * back-off until | |
296 | * the sleep time reaches one jiffy, then switches over to task delay. Usage: | |
297 | * | |
a84bac46 AS |
298 | * brcmf_timeout_start(&tmo, usec); |
299 | * while (!brcmf_timeout_expired(&tmo)) | |
cf2b4488 HP |
300 | * if (poll_something()) |
301 | * break; | |
a84bac46 | 302 | * if (brcmf_timeout_expired(&tmo)) |
cf2b4488 HP |
303 | * fatal(); |
304 | */ | |
305 | ||
bb26354a | 306 | void brcmf_timeout_start(struct brcmf_timeout *tmo, uint usec) |
cf2b4488 HP |
307 | { |
308 | tmo->limit = usec; | |
309 | tmo->increment = 0; | |
310 | tmo->elapsed = 0; | |
311 | tmo->tick = 1000000 / HZ; | |
312 | } | |
313 | ||
bb26354a | 314 | int brcmf_timeout_expired(struct brcmf_timeout *tmo) |
cf2b4488 HP |
315 | { |
316 | /* Does nothing the first call */ | |
317 | if (tmo->increment == 0) { | |
318 | tmo->increment = 1; | |
319 | return 0; | |
320 | } | |
321 | ||
322 | if (tmo->elapsed >= tmo->limit) | |
323 | return 1; | |
324 | ||
325 | /* Add the delay that's about to take place */ | |
326 | tmo->elapsed += tmo->increment; | |
327 | ||
328 | if (tmo->increment < tmo->tick) { | |
7383141b | 329 | udelay(tmo->increment); |
cf2b4488 HP |
330 | tmo->increment *= 2; |
331 | if (tmo->increment > tmo->tick) | |
332 | tmo->increment = tmo->tick; | |
333 | } else { | |
334 | wait_queue_head_t delay_wait; | |
335 | DECLARE_WAITQUEUE(wait, current); | |
336 | int pending; | |
337 | init_waitqueue_head(&delay_wait); | |
338 | add_wait_queue(&delay_wait, &wait); | |
339 | set_current_state(TASK_INTERRUPTIBLE); | |
340 | schedule_timeout(1); | |
341 | pending = signal_pending(current); | |
342 | remove_wait_queue(&delay_wait, &wait); | |
343 | set_current_state(TASK_RUNNING); | |
344 | if (pending) | |
345 | return 1; /* Interrupted */ | |
346 | } | |
347 | ||
348 | return 0; | |
349 | } | |
350 | ||
abfe1804 | 351 | static int brcmf_net2idx(struct brcmf_info *drvr_priv, struct net_device *net) |
cf2b4488 HP |
352 | { |
353 | int i = 0; | |
354 | ||
56d52fcc | 355 | ASSERT(drvr_priv); |
40695d1a | 356 | while (i < BRCMF_MAX_IFS) { |
56d52fcc | 357 | if (drvr_priv->iflist[i] && (drvr_priv->iflist[i]->net == net)) |
cf2b4488 HP |
358 | return i; |
359 | i++; | |
360 | } | |
361 | ||
40695d1a | 362 | return BRCMF_BAD_IF; |
cf2b4488 HP |
363 | } |
364 | ||
abfe1804 | 365 | int brcmf_ifname2idx(struct brcmf_info *drvr_priv, char *name) |
cf2b4488 | 366 | { |
40695d1a | 367 | int i = BRCMF_MAX_IFS; |
cf2b4488 | 368 | |
56d52fcc | 369 | ASSERT(drvr_priv); |
cf2b4488 HP |
370 | |
371 | if (name == NULL || *name == '\0') | |
372 | return 0; | |
373 | ||
374 | while (--i > 0) | |
56d52fcc AS |
375 | if (drvr_priv->iflist[i] |
376 | && !strncmp(drvr_priv->iflist[i]->name, name, IFNAMSIZ)) | |
cf2b4488 HP |
377 | break; |
378 | ||
379 | DHD_TRACE(("%s: return idx %d for \"%s\"\n", __func__, i, name)); | |
380 | ||
381 | return i; /* default - the primary interface */ | |
382 | } | |
383 | ||
fb1d0aa2 | 384 | char *brcmf_ifname(struct brcmf_pub *drvr, int ifidx) |
cf2b4488 | 385 | { |
abfe1804 | 386 | struct brcmf_info *drvr_priv = drvr->info; |
cf2b4488 | 387 | |
56d52fcc | 388 | ASSERT(drvr_priv); |
cf2b4488 | 389 | |
40695d1a | 390 | if (ifidx < 0 || ifidx >= BRCMF_MAX_IFS) { |
cf2b4488 HP |
391 | DHD_ERROR(("%s: ifidx %d out of range\n", __func__, ifidx)); |
392 | return "<if_bad>"; | |
393 | } | |
394 | ||
56d52fcc | 395 | if (drvr_priv->iflist[ifidx] == NULL) { |
cf2b4488 HP |
396 | DHD_ERROR(("%s: null i/f %d\n", __func__, ifidx)); |
397 | return "<if_null>"; | |
398 | } | |
399 | ||
56d52fcc AS |
400 | if (drvr_priv->iflist[ifidx]->net) |
401 | return drvr_priv->iflist[ifidx]->net->name; | |
cf2b4488 HP |
402 | |
403 | return "<if_none>"; | |
404 | } | |
405 | ||
abfe1804 | 406 | static void _brcmf_set_multicast_list(struct brcmf_info *drvr_priv, int ifidx) |
cf2b4488 HP |
407 | { |
408 | struct net_device *dev; | |
409 | struct netdev_hw_addr *ha; | |
66cbd3ab | 410 | u32 allmulti, cnt; |
cf2b4488 | 411 | |
ec66c6fa | 412 | struct brcmf_ioctl ioc; |
cf2b4488 HP |
413 | char *buf, *bufp; |
414 | uint buflen; | |
415 | int ret; | |
416 | ||
56d52fcc AS |
417 | ASSERT(drvr_priv && drvr_priv->iflist[ifidx]); |
418 | dev = drvr_priv->iflist[ifidx]->net; | |
cf2b4488 HP |
419 | cnt = netdev_mc_count(dev); |
420 | ||
421 | /* Determine initial value of allmulti flag */ | |
0965ae88 | 422 | allmulti = (dev->flags & IFF_ALLMULTI) ? true : false; |
cf2b4488 HP |
423 | |
424 | /* Send down the multicast list first. */ | |
425 | ||
b8d63078 | 426 | buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETH_ALEN); |
5fcc1fcb | 427 | bufp = buf = kmalloc(buflen, GFP_ATOMIC); |
a618cc28 | 428 | if (!bufp) { |
cf2b4488 | 429 | DHD_ERROR(("%s: out of memory for mcast_list, cnt %d\n", |
56d52fcc | 430 | brcmf_ifname(&drvr_priv->pub, ifidx), cnt)); |
cf2b4488 HP |
431 | return; |
432 | } | |
433 | ||
434 | strcpy(bufp, "mcast_list"); | |
435 | bufp += strlen("mcast_list") + 1; | |
436 | ||
628f10ba | 437 | cnt = cpu_to_le32(cnt); |
cf2b4488 HP |
438 | memcpy(bufp, &cnt, sizeof(cnt)); |
439 | bufp += sizeof(cnt); | |
440 | ||
441 | netdev_for_each_mc_addr(ha, dev) { | |
442 | if (!cnt) | |
443 | break; | |
b8d63078 JP |
444 | memcpy(bufp, ha->addr, ETH_ALEN); |
445 | bufp += ETH_ALEN; | |
cf2b4488 HP |
446 | cnt--; |
447 | } | |
448 | ||
449 | memset(&ioc, 0, sizeof(ioc)); | |
366bbb3f | 450 | ioc.cmd = BRCMF_C_SET_VAR; |
cf2b4488 HP |
451 | ioc.buf = buf; |
452 | ioc.len = buflen; | |
0f0881b0 | 453 | ioc.set = true; |
cf2b4488 | 454 | |
56d52fcc | 455 | ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len); |
cf2b4488 HP |
456 | if (ret < 0) { |
457 | DHD_ERROR(("%s: set mcast_list failed, cnt %d\n", | |
56d52fcc | 458 | brcmf_ifname(&drvr_priv->pub, ifidx), cnt)); |
0f0881b0 | 459 | allmulti = cnt ? true : allmulti; |
cf2b4488 HP |
460 | } |
461 | ||
182acb3c | 462 | kfree(buf); |
cf2b4488 HP |
463 | |
464 | /* Now send the allmulti setting. This is based on the setting in the | |
465 | * net_device flags, but might be modified above to be turned on if we | |
466 | * were trying to set some addresses and dongle rejected it... | |
467 | */ | |
468 | ||
469 | buflen = sizeof("allmulti") + sizeof(allmulti); | |
5fcc1fcb | 470 | buf = kmalloc(buflen, GFP_ATOMIC); |
a618cc28 | 471 | if (!buf) { |
cf2b4488 | 472 | DHD_ERROR(("%s: out of memory for allmulti\n", |
56d52fcc | 473 | brcmf_ifname(&drvr_priv->pub, ifidx))); |
cf2b4488 HP |
474 | return; |
475 | } | |
628f10ba | 476 | allmulti = cpu_to_le32(allmulti); |
cf2b4488 | 477 | |
67ad48bc | 478 | if (!brcmu_mkiovar |
cf2b4488 HP |
479 | ("allmulti", (void *)&allmulti, sizeof(allmulti), buf, buflen)) { |
480 | DHD_ERROR(("%s: mkiovar failed for allmulti, datalen %d " | |
56d52fcc | 481 | "buflen %u\n", brcmf_ifname(&drvr_priv->pub, ifidx), |
cf2b4488 | 482 | (int)sizeof(allmulti), buflen)); |
182acb3c | 483 | kfree(buf); |
cf2b4488 HP |
484 | return; |
485 | } | |
486 | ||
487 | memset(&ioc, 0, sizeof(ioc)); | |
366bbb3f | 488 | ioc.cmd = BRCMF_C_SET_VAR; |
cf2b4488 HP |
489 | ioc.buf = buf; |
490 | ioc.len = buflen; | |
0f0881b0 | 491 | ioc.set = true; |
cf2b4488 | 492 | |
56d52fcc | 493 | ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len); |
cf2b4488 HP |
494 | if (ret < 0) { |
495 | DHD_ERROR(("%s: set allmulti %d failed\n", | |
56d52fcc | 496 | brcmf_ifname(&drvr_priv->pub, ifidx), |
628f10ba | 497 | le32_to_cpu(allmulti))); |
cf2b4488 HP |
498 | } |
499 | ||
182acb3c | 500 | kfree(buf); |
cf2b4488 HP |
501 | |
502 | /* Finally, pick up the PROMISC flag as well, like the NIC | |
503 | driver does */ | |
504 | ||
0965ae88 | 505 | allmulti = (dev->flags & IFF_PROMISC) ? true : false; |
628f10ba | 506 | allmulti = cpu_to_le32(allmulti); |
cf2b4488 HP |
507 | |
508 | memset(&ioc, 0, sizeof(ioc)); | |
366bbb3f | 509 | ioc.cmd = BRCMF_C_SET_PROMISC; |
cf2b4488 HP |
510 | ioc.buf = &allmulti; |
511 | ioc.len = sizeof(allmulti); | |
0f0881b0 | 512 | ioc.set = true; |
cf2b4488 | 513 | |
56d52fcc | 514 | ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len); |
cf2b4488 HP |
515 | if (ret < 0) { |
516 | DHD_ERROR(("%s: set promisc %d failed\n", | |
56d52fcc | 517 | brcmf_ifname(&drvr_priv->pub, ifidx), |
628f10ba | 518 | le32_to_cpu(allmulti))); |
cf2b4488 HP |
519 | } |
520 | } | |
521 | ||
abfe1804 | 522 | static int _brcmf_set_mac_address(struct brcmf_info *drvr_priv, int ifidx, u8 *addr) |
cf2b4488 HP |
523 | { |
524 | char buf[32]; | |
ec66c6fa | 525 | struct brcmf_ioctl ioc; |
cf2b4488 HP |
526 | int ret; |
527 | ||
528 | DHD_TRACE(("%s enter\n", __func__)); | |
67ad48bc | 529 | if (!brcmu_mkiovar |
b8d63078 | 530 | ("cur_etheraddr", (char *)addr, ETH_ALEN, buf, 32)) { |
cf2b4488 | 531 | DHD_ERROR(("%s: mkiovar failed for cur_etheraddr\n", |
56d52fcc | 532 | brcmf_ifname(&drvr_priv->pub, ifidx))); |
cf2b4488 HP |
533 | return -1; |
534 | } | |
535 | memset(&ioc, 0, sizeof(ioc)); | |
366bbb3f | 536 | ioc.cmd = BRCMF_C_SET_VAR; |
cf2b4488 HP |
537 | ioc.buf = buf; |
538 | ioc.len = 32; | |
0f0881b0 | 539 | ioc.set = true; |
cf2b4488 | 540 | |
56d52fcc | 541 | ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len); |
cf2b4488 HP |
542 | if (ret < 0) { |
543 | DHD_ERROR(("%s: set cur_etheraddr failed\n", | |
56d52fcc | 544 | brcmf_ifname(&drvr_priv->pub, ifidx))); |
cf2b4488 | 545 | } else { |
56d52fcc | 546 | memcpy(drvr_priv->iflist[ifidx]->net->dev_addr, addr, ETH_ALEN); |
cf2b4488 HP |
547 | } |
548 | ||
549 | return ret; | |
550 | } | |
551 | ||
552 | #ifdef SOFTAP | |
553 | extern struct net_device *ap_net_dev; | |
554 | #endif | |
555 | ||
abfe1804 | 556 | static void brcmf_op_if(struct brcmf_if *ifp) |
cf2b4488 | 557 | { |
abfe1804 | 558 | struct brcmf_info *drvr_priv; |
cf2b4488 HP |
559 | int ret = 0, err = 0; |
560 | ||
561 | ASSERT(ifp && ifp->info && ifp->idx); /* Virtual interfaces only */ | |
562 | ||
56d52fcc | 563 | drvr_priv = ifp->info; |
cf2b4488 HP |
564 | |
565 | DHD_TRACE(("%s: idx %d, state %d\n", __func__, ifp->idx, ifp->state)); | |
566 | ||
567 | switch (ifp->state) { | |
05dc0f43 | 568 | case BRCMF_E_IF_ADD: |
cf2b4488 HP |
569 | /* |
570 | * Delete the existing interface before overwriting it | |
05dc0f43 | 571 | * in case we missed the BRCMF_E_IF_DEL event. |
cf2b4488 HP |
572 | */ |
573 | if (ifp->net != NULL) { | |
574 | DHD_ERROR(("%s: ERROR: netdev:%s already exists, " | |
575 | "try free & unregister\n", | |
576 | __func__, ifp->net->name)); | |
577 | netif_stop_queue(ifp->net); | |
578 | unregister_netdev(ifp->net); | |
579 | free_netdev(ifp->net); | |
580 | } | |
581 | /* Allocate etherdev, including space for private structure */ | |
56d52fcc | 582 | ifp->net = alloc_etherdev(sizeof(drvr_priv)); |
a618cc28 | 583 | if (!ifp->net) { |
cf2b4488 HP |
584 | DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__)); |
585 | ret = -ENOMEM; | |
586 | } | |
587 | if (ret == 0) { | |
588 | strcpy(ifp->net->name, ifp->name); | |
56d52fcc AS |
589 | memcpy(netdev_priv(ifp->net), &drvr_priv, sizeof(drvr_priv)); |
590 | err = brcmf_net_attach(&drvr_priv->pub, ifp->idx); | |
a618cc28 | 591 | if (err != 0) { |
cf2b4488 HP |
592 | DHD_ERROR(("%s: dhd_net_attach failed, " |
593 | "err %d\n", | |
594 | __func__, err)); | |
595 | ret = -EOPNOTSUPP; | |
596 | } else { | |
597 | #ifdef SOFTAP | |
598 | /* semaphore that the soft AP CODE | |
599 | waits on */ | |
600 | extern struct semaphore ap_eth_sema; | |
601 | ||
602 | /* save ptr to wl0.1 netdev for use | |
603 | in wl_iw.c */ | |
604 | ap_net_dev = ifp->net; | |
605 | /* signal to the SOFTAP 'sleeper' thread, | |
606 | wl0.1 is ready */ | |
607 | up(&ap_eth_sema); | |
608 | #endif | |
609 | DHD_TRACE(("\n ==== pid:%x, net_device for " | |
610 | "if:%s created ===\n\n", | |
611 | current->pid, ifp->net->name)); | |
612 | ifp->state = 0; | |
613 | } | |
614 | } | |
615 | break; | |
05dc0f43 | 616 | case BRCMF_E_IF_DEL: |
cf2b4488 HP |
617 | if (ifp->net != NULL) { |
618 | DHD_TRACE(("\n%s: got 'WLC_E_IF_DEL' state\n", | |
619 | __func__)); | |
620 | netif_stop_queue(ifp->net); | |
621 | unregister_netdev(ifp->net); | |
40695d1a | 622 | ret = BRCMF_DEL_IF; /* Make sure the free_netdev() |
cf2b4488 HP |
623 | is called */ |
624 | } | |
625 | break; | |
626 | default: | |
627 | DHD_ERROR(("%s: bad op %d\n", __func__, ifp->state)); | |
628 | ASSERT(!ifp->state); | |
629 | break; | |
630 | } | |
631 | ||
632 | if (ret < 0) { | |
633 | if (ifp->net) | |
634 | free_netdev(ifp->net); | |
635 | ||
56d52fcc | 636 | drvr_priv->iflist[ifp->idx] = NULL; |
182acb3c | 637 | kfree(ifp); |
cf2b4488 HP |
638 | #ifdef SOFTAP |
639 | if (ifp->net == ap_net_dev) | |
640 | ap_net_dev = NULL; /* NULL SOFTAP global | |
641 | wl0.1 as well */ | |
642 | #endif /* SOFTAP */ | |
643 | } | |
644 | } | |
645 | ||
db62efcc | 646 | static int _brcmf_sysioc_thread(void *data) |
cf2b4488 | 647 | { |
abfe1804 | 648 | struct brcmf_info *drvr_priv = (struct brcmf_info *) data; |
cf2b4488 HP |
649 | int i; |
650 | #ifdef SOFTAP | |
0965ae88 | 651 | bool in_ap = false; |
cf2b4488 HP |
652 | #endif |
653 | ||
af737136 | 654 | allow_signal(SIGTERM); |
655 | ||
56d52fcc | 656 | while (down_interruptible(&drvr_priv->sysioc_sem) == 0) { |
eeb8e46b | 657 | if (kthread_should_stop()) |
d809dcb9 | 658 | break; |
40695d1a | 659 | for (i = 0; i < BRCMF_MAX_IFS; i++) { |
56d52fcc | 660 | if (drvr_priv->iflist[i]) { |
cf2b4488 HP |
661 | #ifdef SOFTAP |
662 | in_ap = (ap_net_dev != NULL); | |
663 | #endif /* SOFTAP */ | |
56d52fcc AS |
664 | if (drvr_priv->iflist[i]->state) |
665 | brcmf_op_if(drvr_priv->iflist[i]); | |
cf2b4488 | 666 | #ifdef SOFTAP |
56d52fcc | 667 | if (drvr_priv->iflist[i] == NULL) { |
cf2b4488 HP |
668 | DHD_TRACE(("\n\n %s: interface %d " |
669 | "removed!\n", __func__, i)); | |
670 | continue; | |
671 | } | |
672 | ||
56d52fcc | 673 | if (in_ap && drvr_priv->set_macaddress) { |
cf2b4488 | 674 | DHD_TRACE(("attempt to set MAC for %s " |
e131d3ce | 675 | "in AP Mode," "blocked.\n", |
56d52fcc AS |
676 | drvr_priv->iflist[i]->net->name)); |
677 | drvr_priv->set_macaddress = false; | |
cf2b4488 HP |
678 | continue; |
679 | } | |
680 | ||
56d52fcc AS |
681 | if (in_ap && drvr_priv->set_multicast) { |
682 | DHD_TRACE(("attempt to set MULTICAST " | |
683 | "list for %s in AP Mode, " | |
684 | "blocked.\n", | |
685 | drvr_priv->iflist[i]->net->name)); | |
686 | drvr_priv->set_multicast = false; | |
cf2b4488 HP |
687 | continue; |
688 | } | |
689 | #endif /* SOFTAP */ | |
56d52fcc AS |
690 | if (drvr_priv->set_multicast) { |
691 | drvr_priv->set_multicast = false; | |
692 | _brcmf_set_multicast_list(drvr_priv, i); | |
cf2b4488 | 693 | } |
56d52fcc AS |
694 | if (drvr_priv->set_macaddress) { |
695 | drvr_priv->set_macaddress = false; | |
696 | _brcmf_set_mac_address(drvr_priv, i, | |
697 | drvr_priv->macvalue); | |
cf2b4488 HP |
698 | } |
699 | } | |
700 | } | |
701 | } | |
d809dcb9 | 702 | return 0; |
cf2b4488 HP |
703 | } |
704 | ||
fc2860a9 | 705 | static int brcmf_netdev_set_mac_address(struct net_device *dev, void *addr) |
cf2b4488 HP |
706 | { |
707 | int ret = 0; | |
708 | ||
abfe1804 | 709 | struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(dev); |
cf2b4488 HP |
710 | struct sockaddr *sa = (struct sockaddr *)addr; |
711 | int ifidx; | |
712 | ||
56d52fcc | 713 | ifidx = brcmf_net2idx(drvr_priv, dev); |
40695d1a | 714 | if (ifidx == BRCMF_BAD_IF) |
cf2b4488 HP |
715 | return -1; |
716 | ||
56d52fcc AS |
717 | ASSERT(drvr_priv->sysioc_tsk); |
718 | memcpy(&drvr_priv->macvalue, sa->sa_data, ETH_ALEN); | |
719 | drvr_priv->set_macaddress = true; | |
720 | up(&drvr_priv->sysioc_sem); | |
cf2b4488 HP |
721 | |
722 | return ret; | |
723 | } | |
724 | ||
fc2860a9 | 725 | static void brcmf_netdev_set_multicast_list(struct net_device *dev) |
cf2b4488 | 726 | { |
abfe1804 | 727 | struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(dev); |
cf2b4488 HP |
728 | int ifidx; |
729 | ||
56d52fcc | 730 | ifidx = brcmf_net2idx(drvr_priv, dev); |
40695d1a | 731 | if (ifidx == BRCMF_BAD_IF) |
cf2b4488 HP |
732 | return; |
733 | ||
56d52fcc AS |
734 | ASSERT(drvr_priv->sysioc_tsk); |
735 | drvr_priv->set_multicast = true; | |
736 | up(&drvr_priv->sysioc_sem); | |
cf2b4488 HP |
737 | } |
738 | ||
fb1d0aa2 | 739 | int brcmf_sendpkt(struct brcmf_pub *drvr, int ifidx, struct sk_buff *pktbuf) |
cf2b4488 | 740 | { |
abfe1804 | 741 | struct brcmf_info *drvr_priv = drvr->info; |
cf2b4488 HP |
742 | |
743 | /* Reject if down */ | |
56d52fcc | 744 | if (!drvr->up || (drvr->busstate == DHD_BUS_DOWN)) |
cf2b4488 HP |
745 | return -ENODEV; |
746 | ||
747 | /* Update multicast statistic */ | |
b8d63078 | 748 | if (pktbuf->len >= ETH_ALEN) { |
54991ad6 | 749 | u8 *pktdata = (u8 *) (pktbuf->data); |
e2582ad8 | 750 | struct ethhdr *eh = (struct ethhdr *)pktdata; |
cf2b4488 | 751 | |
e2582ad8 | 752 | if (is_multicast_ether_addr(eh->h_dest)) |
56d52fcc | 753 | drvr->tx_multicast++; |
628f10ba | 754 | if (ntohs(eh->h_proto) == ETH_P_PAE) |
56d52fcc | 755 | atomic_inc(&drvr_priv->pend_8021x_cnt); |
cf2b4488 HP |
756 | } |
757 | ||
cf2b4488 | 758 | /* If the protocol uses a data header, apply it */ |
56d52fcc | 759 | brcmf_proto_hdrpush(drvr, ifidx, pktbuf); |
cf2b4488 HP |
760 | |
761 | /* Use bus module to send data frame */ | |
56d52fcc | 762 | return brcmf_sdbrcm_bus_txdata(drvr->bus, pktbuf); |
cf2b4488 HP |
763 | } |
764 | ||
fc2860a9 | 765 | static int brcmf_netdev_start_xmit(struct sk_buff *skb, struct net_device *net) |
cf2b4488 HP |
766 | { |
767 | int ret; | |
abfe1804 | 768 | struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net); |
cf2b4488 HP |
769 | int ifidx; |
770 | ||
771 | DHD_TRACE(("%s: Enter\n", __func__)); | |
772 | ||
773 | /* Reject if down */ | |
56d52fcc | 774 | if (!drvr_priv->pub.up || (drvr_priv->pub.busstate == DHD_BUS_DOWN)) { |
cf2b4488 | 775 | DHD_ERROR(("%s: xmit rejected pub.up=%d busstate=%d\n", |
56d52fcc | 776 | __func__, drvr_priv->pub.up, drvr_priv->pub.busstate)); |
cf2b4488 HP |
777 | netif_stop_queue(net); |
778 | return -ENODEV; | |
779 | } | |
780 | ||
56d52fcc | 781 | ifidx = brcmf_net2idx(drvr_priv, net); |
40695d1a | 782 | if (ifidx == BRCMF_BAD_IF) { |
cf2b4488 HP |
783 | DHD_ERROR(("%s: bad ifidx %d\n", __func__, ifidx)); |
784 | netif_stop_queue(net); | |
785 | return -ENODEV; | |
786 | } | |
787 | ||
788 | /* Make sure there's enough room for any header */ | |
56d52fcc | 789 | if (skb_headroom(skb) < drvr_priv->pub.hdrlen) { |
cf2b4488 HP |
790 | struct sk_buff *skb2; |
791 | ||
792 | DHD_INFO(("%s: insufficient headroom\n", | |
56d52fcc AS |
793 | brcmf_ifname(&drvr_priv->pub, ifidx))); |
794 | drvr_priv->pub.tx_realloc++; | |
795 | skb2 = skb_realloc_headroom(skb, drvr_priv->pub.hdrlen); | |
cf2b4488 | 796 | dev_kfree_skb(skb); |
a618cc28 JC |
797 | skb = skb2; |
798 | if (skb == NULL) { | |
cf2b4488 | 799 | DHD_ERROR(("%s: skb_realloc_headroom failed\n", |
56d52fcc | 800 | brcmf_ifname(&drvr_priv->pub, ifidx))); |
cf2b4488 HP |
801 | ret = -ENOMEM; |
802 | goto done; | |
803 | } | |
804 | } | |
805 | ||
56d52fcc | 806 | ret = brcmf_sendpkt(&drvr_priv->pub, ifidx, skb); |
cf2b4488 HP |
807 | |
808 | done: | |
809 | if (ret) | |
56d52fcc | 810 | drvr_priv->pub.dstats.tx_dropped++; |
cf2b4488 | 811 | else |
56d52fcc | 812 | drvr_priv->pub.tx_packets++; |
cf2b4488 HP |
813 | |
814 | /* Return ok: we always eat the packet */ | |
815 | return 0; | |
816 | } | |
817 | ||
fb1d0aa2 | 818 | void brcmf_txflowcontrol(struct brcmf_pub *drvr, int ifidx, bool state) |
cf2b4488 HP |
819 | { |
820 | struct net_device *net; | |
abfe1804 | 821 | struct brcmf_info *drvr_priv = drvr->info; |
cf2b4488 HP |
822 | |
823 | DHD_TRACE(("%s: Enter\n", __func__)); | |
824 | ||
56d52fcc AS |
825 | drvr->txoff = state; |
826 | ASSERT(drvr_priv && drvr_priv->iflist[ifidx]); | |
827 | net = drvr_priv->iflist[ifidx]->net; | |
cf2b4488 HP |
828 | if (state == ON) |
829 | netif_stop_queue(net); | |
830 | else | |
831 | netif_wake_queue(net); | |
832 | } | |
833 | ||
fb1d0aa2 | 834 | void brcmf_rx_frame(struct brcmf_pub *drvr, int ifidx, struct sk_buff *skb, |
c26b1378 | 835 | int numpkt) |
cf2b4488 | 836 | { |
abfe1804 | 837 | struct brcmf_info *drvr_priv = drvr->info; |
580a0bd9 | 838 | unsigned char *eth; |
cf2b4488 | 839 | uint len; |
c26b1378 AS |
840 | void *data; |
841 | struct sk_buff *pnext, *save_pktbuf; | |
cf2b4488 | 842 | int i; |
abfe1804 | 843 | struct brcmf_if *ifp; |
63bec49e | 844 | struct brcmf_event_msg event; |
cf2b4488 HP |
845 | |
846 | DHD_TRACE(("%s: Enter\n", __func__)); | |
847 | ||
b8b5418b | 848 | save_pktbuf = skb; |
cf2b4488 | 849 | |
b8b5418b | 850 | for (i = 0; skb && i < numpkt; i++, skb = pnext) { |
cf2b4488 | 851 | |
b8b5418b AS |
852 | pnext = skb->next; |
853 | skb->next = NULL; | |
cf2b4488 HP |
854 | |
855 | /* Get the protocol, maintain skb around eth_type_trans() | |
856 | * The main reason for this hack is for the limitation of | |
857 | * Linux 2.4 where 'eth_type_trans' uses the | |
858 | * 'net->hard_header_len' | |
859 | * to perform skb_pull inside vs ETH_HLEN. Since to avoid | |
860 | * coping of the packet coming from the network stack to add | |
861 | * BDC, Hardware header etc, during network interface | |
862 | * registration | |
863 | * we set the 'net->hard_header_len' to ETH_HLEN + extra space | |
864 | * required | |
865 | * for BDC, Hardware header etc. and not just the ETH_HLEN | |
866 | */ | |
867 | eth = skb->data; | |
868 | len = skb->len; | |
869 | ||
56d52fcc | 870 | ifp = drvr_priv->iflist[ifidx]; |
cf2b4488 | 871 | if (ifp == NULL) |
56d52fcc | 872 | ifp = drvr_priv->iflist[0]; |
cf2b4488 HP |
873 | |
874 | ASSERT(ifp); | |
875 | skb->dev = ifp->net; | |
876 | skb->protocol = eth_type_trans(skb, skb->dev); | |
877 | ||
878 | if (skb->pkt_type == PACKET_MULTICAST) | |
56d52fcc | 879 | drvr_priv->pub.rx_multicast++; |
cf2b4488 HP |
880 | |
881 | skb->data = eth; | |
882 | skb->len = len; | |
883 | ||
884 | /* Strip header, count, deliver upward */ | |
885 | skb_pull(skb, ETH_HLEN); | |
886 | ||
887 | /* Process special event packets and then discard them */ | |
cb645abd | 888 | if (ntohs(skb->protocol) == ETH_P_LINK_CTL) |
56d52fcc | 889 | brcmf_host_event(drvr_priv, &ifidx, |
d4fcdc68 | 890 | skb_mac_header(skb), |
cf2b4488 HP |
891 | &event, &data); |
892 | ||
40695d1a | 893 | ASSERT(ifidx < BRCMF_MAX_IFS && drvr_priv->iflist[ifidx]); |
56d52fcc AS |
894 | if (drvr_priv->iflist[ifidx] && |
895 | !drvr_priv->iflist[ifidx]->state) | |
896 | ifp = drvr_priv->iflist[ifidx]; | |
cf2b4488 HP |
897 | |
898 | if (ifp->net) | |
899 | ifp->net->last_rx = jiffies; | |
900 | ||
56d52fcc AS |
901 | drvr->dstats.rx_bytes += skb->len; |
902 | drvr->rx_packets++; /* Local count */ | |
cf2b4488 HP |
903 | |
904 | if (in_interrupt()) { | |
905 | netif_rx(skb); | |
906 | } else { | |
907 | /* If the receive is not processed inside an ISR, | |
908 | * the softirqd must be woken explicitly to service | |
909 | * the NET_RX_SOFTIRQ. In 2.6 kernels, this is handled | |
910 | * by netif_rx_ni(), but in earlier kernels, we need | |
911 | * to do it manually. | |
912 | */ | |
913 | netif_rx_ni(skb); | |
914 | } | |
915 | } | |
916 | } | |
917 | ||
fb1d0aa2 | 918 | void brcmf_txcomplete(struct brcmf_pub *drvr, struct sk_buff *txp, bool success) |
cf2b4488 HP |
919 | { |
920 | uint ifidx; | |
abfe1804 | 921 | struct brcmf_info *drvr_priv = drvr->info; |
e2582ad8 | 922 | struct ethhdr *eh; |
7d4df48e | 923 | u16 type; |
cf2b4488 | 924 | |
56d52fcc | 925 | brcmf_proto_hdrpull(drvr, &ifidx, txp); |
cf2b4488 | 926 | |
e2582ad8 | 927 | eh = (struct ethhdr *)(txp->data); |
628f10ba | 928 | type = ntohs(eh->h_proto); |
cf2b4488 | 929 | |
fcbdbed0 | 930 | if (type == ETH_P_PAE) |
56d52fcc | 931 | atomic_dec(&drvr_priv->pend_8021x_cnt); |
cf2b4488 HP |
932 | |
933 | } | |
934 | ||
fc2860a9 | 935 | static struct net_device_stats *brcmf_netdev_get_stats(struct net_device *net) |
cf2b4488 | 936 | { |
abfe1804 AS |
937 | struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net); |
938 | struct brcmf_if *ifp; | |
cf2b4488 HP |
939 | int ifidx; |
940 | ||
941 | DHD_TRACE(("%s: Enter\n", __func__)); | |
942 | ||
56d52fcc | 943 | ifidx = brcmf_net2idx(drvr_priv, net); |
40695d1a | 944 | if (ifidx == BRCMF_BAD_IF) |
cf2b4488 HP |
945 | return NULL; |
946 | ||
56d52fcc AS |
947 | ifp = drvr_priv->iflist[ifidx]; |
948 | ASSERT(drvr_priv && ifp); | |
cf2b4488 | 949 | |
56d52fcc | 950 | if (drvr_priv->pub.up) { |
cf2b4488 | 951 | /* Use the protocol to get dongle stats */ |
56d52fcc | 952 | brcmf_proto_dstats(&drvr_priv->pub); |
cf2b4488 HP |
953 | } |
954 | ||
955 | /* Copy dongle stats to net device stats */ | |
56d52fcc AS |
956 | ifp->stats.rx_packets = drvr_priv->pub.dstats.rx_packets; |
957 | ifp->stats.tx_packets = drvr_priv->pub.dstats.tx_packets; | |
958 | ifp->stats.rx_bytes = drvr_priv->pub.dstats.rx_bytes; | |
959 | ifp->stats.tx_bytes = drvr_priv->pub.dstats.tx_bytes; | |
960 | ifp->stats.rx_errors = drvr_priv->pub.dstats.rx_errors; | |
961 | ifp->stats.tx_errors = drvr_priv->pub.dstats.tx_errors; | |
962 | ifp->stats.rx_dropped = drvr_priv->pub.dstats.rx_dropped; | |
963 | ifp->stats.tx_dropped = drvr_priv->pub.dstats.tx_dropped; | |
964 | ifp->stats.multicast = drvr_priv->pub.dstats.multicast; | |
cf2b4488 HP |
965 | |
966 | return &ifp->stats; | |
967 | } | |
968 | ||
cf2b4488 HP |
969 | /* Retrieve current toe component enables, which are kept |
970 | as a bitmap in toe_ol iovar */ | |
abfe1804 | 971 | static int brcmf_toe_get(struct brcmf_info *drvr_priv, int ifidx, u32 *toe_ol) |
cf2b4488 | 972 | { |
ec66c6fa | 973 | struct brcmf_ioctl ioc; |
cf2b4488 HP |
974 | char buf[32]; |
975 | int ret; | |
976 | ||
977 | memset(&ioc, 0, sizeof(ioc)); | |
978 | ||
366bbb3f | 979 | ioc.cmd = BRCMF_C_GET_VAR; |
cf2b4488 HP |
980 | ioc.buf = buf; |
981 | ioc.len = (uint) sizeof(buf); | |
0965ae88 | 982 | ioc.set = false; |
cf2b4488 HP |
983 | |
984 | strcpy(buf, "toe_ol"); | |
56d52fcc | 985 | ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len); |
a618cc28 | 986 | if (ret < 0) { |
cf2b4488 HP |
987 | /* Check for older dongle image that doesn't support toe_ol */ |
988 | if (ret == -EIO) { | |
989 | DHD_ERROR(("%s: toe not supported by device\n", | |
56d52fcc | 990 | brcmf_ifname(&drvr_priv->pub, ifidx))); |
cf2b4488 HP |
991 | return -EOPNOTSUPP; |
992 | } | |
993 | ||
994 | DHD_INFO(("%s: could not get toe_ol: ret=%d\n", | |
56d52fcc | 995 | brcmf_ifname(&drvr_priv->pub, ifidx), ret)); |
cf2b4488 HP |
996 | return ret; |
997 | } | |
998 | ||
66cbd3ab | 999 | memcpy(toe_ol, buf, sizeof(u32)); |
cf2b4488 HP |
1000 | return 0; |
1001 | } | |
1002 | ||
1003 | /* Set current toe component enables in toe_ol iovar, | |
1004 | and set toe global enable iovar */ | |
abfe1804 | 1005 | static int brcmf_toe_set(struct brcmf_info *drvr_priv, int ifidx, u32 toe_ol) |
cf2b4488 | 1006 | { |
ec66c6fa | 1007 | struct brcmf_ioctl ioc; |
cf2b4488 HP |
1008 | char buf[32]; |
1009 | int toe, ret; | |
1010 | ||
1011 | memset(&ioc, 0, sizeof(ioc)); | |
1012 | ||
366bbb3f | 1013 | ioc.cmd = BRCMF_C_SET_VAR; |
cf2b4488 HP |
1014 | ioc.buf = buf; |
1015 | ioc.len = (uint) sizeof(buf); | |
0f0881b0 | 1016 | ioc.set = true; |
cf2b4488 HP |
1017 | |
1018 | /* Set toe_ol as requested */ | |
1019 | ||
1020 | strcpy(buf, "toe_ol"); | |
66cbd3ab | 1021 | memcpy(&buf[sizeof("toe_ol")], &toe_ol, sizeof(u32)); |
cf2b4488 | 1022 | |
56d52fcc | 1023 | ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len); |
a618cc28 | 1024 | if (ret < 0) { |
cf2b4488 | 1025 | DHD_ERROR(("%s: could not set toe_ol: ret=%d\n", |
56d52fcc | 1026 | brcmf_ifname(&drvr_priv->pub, ifidx), ret)); |
cf2b4488 HP |
1027 | return ret; |
1028 | } | |
1029 | ||
1030 | /* Enable toe globally only if any components are enabled. */ | |
1031 | ||
1032 | toe = (toe_ol != 0); | |
1033 | ||
1034 | strcpy(buf, "toe"); | |
66cbd3ab | 1035 | memcpy(&buf[sizeof("toe")], &toe, sizeof(u32)); |
cf2b4488 | 1036 | |
56d52fcc | 1037 | ret = brcmf_proto_ioctl(&drvr_priv->pub, ifidx, &ioc, ioc.buf, ioc.len); |
a618cc28 | 1038 | if (ret < 0) { |
cf2b4488 | 1039 | DHD_ERROR(("%s: could not set toe: ret=%d\n", |
56d52fcc | 1040 | brcmf_ifname(&drvr_priv->pub, ifidx), ret)); |
cf2b4488 HP |
1041 | return ret; |
1042 | } | |
1043 | ||
1044 | return 0; | |
1045 | } | |
cf2b4488 | 1046 | |
fc2860a9 | 1047 | static void brcmf_ethtool_get_drvinfo(struct net_device *net, |
cf2b4488 HP |
1048 | struct ethtool_drvinfo *info) |
1049 | { | |
abfe1804 | 1050 | struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net); |
cf2b4488 | 1051 | |
f70a456a | 1052 | sprintf(info->driver, KBUILD_MODNAME); |
56d52fcc | 1053 | sprintf(info->version, "%lu", drvr_priv->pub.drv_version); |
b7859cd9 | 1054 | sprintf(info->fw_version, "%s", BCM4329_FW_NAME); |
93ad12cf | 1055 | sprintf(info->bus_info, "%s", dev_name(&wl_cfg80211_get_sdio_func()->dev)); |
cf2b4488 HP |
1056 | } |
1057 | ||
fc2860a9 AS |
1058 | struct ethtool_ops brcmf_ethtool_ops = { |
1059 | .get_drvinfo = brcmf_ethtool_get_drvinfo | |
cf2b4488 HP |
1060 | }; |
1061 | ||
abfe1804 | 1062 | static int brcmf_ethtool(struct brcmf_info *drvr_priv, void *uaddr) |
cf2b4488 HP |
1063 | { |
1064 | struct ethtool_drvinfo info; | |
1065 | char drvname[sizeof(info.driver)]; | |
66cbd3ab | 1066 | u32 cmd; |
cf2b4488 | 1067 | struct ethtool_value edata; |
66cbd3ab | 1068 | u32 toe_cmpnt, csum_dir; |
cf2b4488 | 1069 | int ret; |
cf2b4488 HP |
1070 | |
1071 | DHD_TRACE(("%s: Enter\n", __func__)); | |
1072 | ||
1073 | /* all ethtool calls start with a cmd word */ | |
66cbd3ab | 1074 | if (copy_from_user(&cmd, uaddr, sizeof(u32))) |
cf2b4488 HP |
1075 | return -EFAULT; |
1076 | ||
1077 | switch (cmd) { | |
1078 | case ETHTOOL_GDRVINFO: | |
1079 | /* Copy out any request driver name */ | |
1080 | if (copy_from_user(&info, uaddr, sizeof(info))) | |
1081 | return -EFAULT; | |
1082 | strncpy(drvname, info.driver, sizeof(info.driver)); | |
1083 | drvname[sizeof(info.driver) - 1] = '\0'; | |
1084 | ||
1085 | /* clear struct for return */ | |
1086 | memset(&info, 0, sizeof(info)); | |
1087 | info.cmd = cmd; | |
1088 | ||
1089 | /* if dhd requested, identify ourselves */ | |
1090 | if (strcmp(drvname, "?dhd") == 0) { | |
1091 | sprintf(info.driver, "dhd"); | |
c8796cbe | 1092 | strcpy(info.version, BRCMF_VERSION_STR); |
cf2b4488 HP |
1093 | } |
1094 | ||
1095 | /* otherwise, require dongle to be up */ | |
56d52fcc | 1096 | else if (!drvr_priv->pub.up) { |
cf2b4488 HP |
1097 | DHD_ERROR(("%s: dongle is not up\n", __func__)); |
1098 | return -ENODEV; | |
1099 | } | |
1100 | ||
1101 | /* finally, report dongle driver type */ | |
56d52fcc | 1102 | else if (drvr_priv->pub.iswl) |
cf2b4488 HP |
1103 | sprintf(info.driver, "wl"); |
1104 | else | |
1105 | sprintf(info.driver, "xx"); | |
1106 | ||
56d52fcc | 1107 | sprintf(info.version, "%lu", drvr_priv->pub.drv_version); |
cf2b4488 HP |
1108 | if (copy_to_user(uaddr, &info, sizeof(info))) |
1109 | return -EFAULT; | |
1110 | DHD_CTL(("%s: given %*s, returning %s\n", __func__, | |
1111 | (int)sizeof(drvname), drvname, info.driver)); | |
1112 | break; | |
1113 | ||
cf2b4488 HP |
1114 | /* Get toe offload components from dongle */ |
1115 | case ETHTOOL_GRXCSUM: | |
1116 | case ETHTOOL_GTXCSUM: | |
56d52fcc | 1117 | ret = brcmf_toe_get(drvr_priv, 0, &toe_cmpnt); |
a618cc28 | 1118 | if (ret < 0) |
cf2b4488 HP |
1119 | return ret; |
1120 | ||
1121 | csum_dir = | |
1122 | (cmd == ETHTOOL_GTXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL; | |
1123 | ||
1124 | edata.cmd = cmd; | |
1125 | edata.data = (toe_cmpnt & csum_dir) ? 1 : 0; | |
1126 | ||
1127 | if (copy_to_user(uaddr, &edata, sizeof(edata))) | |
1128 | return -EFAULT; | |
1129 | break; | |
1130 | ||
1131 | /* Set toe offload components in dongle */ | |
1132 | case ETHTOOL_SRXCSUM: | |
1133 | case ETHTOOL_STXCSUM: | |
1134 | if (copy_from_user(&edata, uaddr, sizeof(edata))) | |
1135 | return -EFAULT; | |
1136 | ||
1137 | /* Read the current settings, update and write back */ | |
56d52fcc | 1138 | ret = brcmf_toe_get(drvr_priv, 0, &toe_cmpnt); |
a618cc28 | 1139 | if (ret < 0) |
cf2b4488 HP |
1140 | return ret; |
1141 | ||
1142 | csum_dir = | |
1143 | (cmd == ETHTOOL_STXCSUM) ? TOE_TX_CSUM_OL : TOE_RX_CSUM_OL; | |
1144 | ||
1145 | if (edata.data != 0) | |
1146 | toe_cmpnt |= csum_dir; | |
1147 | else | |
1148 | toe_cmpnt &= ~csum_dir; | |
1149 | ||
56d52fcc | 1150 | ret = brcmf_toe_set(drvr_priv, 0, toe_cmpnt); |
a618cc28 | 1151 | if (ret < 0) |
cf2b4488 HP |
1152 | return ret; |
1153 | ||
1154 | /* If setting TX checksum mode, tell Linux the new mode */ | |
1155 | if (cmd == ETHTOOL_STXCSUM) { | |
1156 | if (edata.data) | |
56d52fcc | 1157 | drvr_priv->iflist[0]->net->features |= |
cf2b4488 HP |
1158 | NETIF_F_IP_CSUM; |
1159 | else | |
56d52fcc | 1160 | drvr_priv->iflist[0]->net->features &= |
cf2b4488 HP |
1161 | ~NETIF_F_IP_CSUM; |
1162 | } | |
1163 | ||
1164 | break; | |
cf2b4488 HP |
1165 | |
1166 | default: | |
1167 | return -EOPNOTSUPP; | |
1168 | } | |
1169 | ||
1170 | return 0; | |
1171 | } | |
1172 | ||
fc2860a9 AS |
1173 | static int brcmf_netdev_ioctl_entry(struct net_device *net, struct ifreq *ifr, |
1174 | int cmd) | |
cf2b4488 | 1175 | { |
abfe1804 | 1176 | struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net); |
bb26354a | 1177 | struct brcmf_c_ioctl ioc; |
cf2b4488 HP |
1178 | int bcmerror = 0; |
1179 | int buflen = 0; | |
1180 | void *buf = NULL; | |
1181 | uint driver = 0; | |
1182 | int ifidx; | |
1183 | bool is_set_key_cmd; | |
1184 | ||
56d52fcc | 1185 | ifidx = brcmf_net2idx(drvr_priv, net); |
cf2b4488 HP |
1186 | DHD_TRACE(("%s: ifidx %d, cmd 0x%04x\n", __func__, ifidx, cmd)); |
1187 | ||
40695d1a | 1188 | if (ifidx == BRCMF_BAD_IF) |
cf2b4488 HP |
1189 | return -1; |
1190 | ||
cf2b4488 | 1191 | if (cmd == SIOCETHTOOL) |
56d52fcc | 1192 | return brcmf_ethtool(drvr_priv, (void *)ifr->ifr_data); |
cf2b4488 HP |
1193 | |
1194 | if (cmd != SIOCDEVPRIVATE) | |
1195 | return -EOPNOTSUPP; | |
1196 | ||
1197 | memset(&ioc, 0, sizeof(ioc)); | |
1198 | ||
1199 | /* Copy the ioc control structure part of ioctl request */ | |
ec66c6fa | 1200 | if (copy_from_user(&ioc, ifr->ifr_data, sizeof(struct brcmf_ioctl))) { |
e10d82d4 | 1201 | bcmerror = -EINVAL; |
cf2b4488 HP |
1202 | goto done; |
1203 | } | |
1204 | ||
1205 | /* Copy out any buffer passed */ | |
1206 | if (ioc.buf) { | |
40695d1a | 1207 | buflen = min_t(int, ioc.len, BRCMF_IOCTL_MAXLEN); |
cf2b4488 HP |
1208 | /* optimization for direct ioctl calls from kernel */ |
1209 | /* | |
1210 | if (segment_eq(get_fs(), KERNEL_DS)) { | |
1211 | buf = ioc.buf; | |
1212 | } else { | |
1213 | */ | |
1214 | { | |
5fcc1fcb | 1215 | buf = kmalloc(buflen, GFP_ATOMIC); |
a618cc28 | 1216 | if (!buf) { |
e10d82d4 | 1217 | bcmerror = -ENOMEM; |
cf2b4488 HP |
1218 | goto done; |
1219 | } | |
1220 | if (copy_from_user(buf, ioc.buf, buflen)) { | |
e10d82d4 | 1221 | bcmerror = -EINVAL; |
cf2b4488 HP |
1222 | goto done; |
1223 | } | |
1224 | } | |
1225 | } | |
1226 | ||
1227 | /* To differentiate between wl and dhd read 4 more byes */ | |
ec66c6fa AS |
1228 | if ((copy_from_user(&driver, (char *)ifr->ifr_data + |
1229 | sizeof(struct brcmf_ioctl), sizeof(uint)) != 0)) { | |
e10d82d4 | 1230 | bcmerror = -EINVAL; |
cf2b4488 HP |
1231 | goto done; |
1232 | } | |
1233 | ||
1234 | if (!capable(CAP_NET_ADMIN)) { | |
e10d82d4 | 1235 | bcmerror = -EPERM; |
cf2b4488 HP |
1236 | goto done; |
1237 | } | |
1238 | ||
1239 | /* check for local dhd ioctl and handle it */ | |
40695d1a | 1240 | if (driver == BRCMF_IOCTL_MAGIC) { |
56d52fcc | 1241 | bcmerror = brcmf_c_ioctl((void *)&drvr_priv->pub, &ioc, buf, buflen); |
cf2b4488 | 1242 | if (bcmerror) |
56d52fcc | 1243 | drvr_priv->pub.bcmerror = bcmerror; |
cf2b4488 HP |
1244 | goto done; |
1245 | } | |
1246 | ||
1247 | /* send to dongle (must be up, and wl) */ | |
56d52fcc | 1248 | if ((drvr_priv->pub.busstate != DHD_BUS_DATA)) { |
cf2b4488 | 1249 | DHD_ERROR(("%s DONGLE_DOWN,__func__\n", __func__)); |
b74ac12e | 1250 | bcmerror = -EIO; |
cf2b4488 HP |
1251 | goto done; |
1252 | } | |
1253 | ||
56d52fcc | 1254 | if (!drvr_priv->pub.iswl) { |
b74ac12e | 1255 | bcmerror = -EIO; |
cf2b4488 HP |
1256 | goto done; |
1257 | } | |
1258 | ||
366bbb3f AS |
1259 | /* |
1260 | * Intercept BRCMF_C_SET_KEY IOCTL - serialize M4 send and | |
1261 | * set key IOCTL to prevent M4 encryption. | |
cf2b4488 | 1262 | */ |
366bbb3f AS |
1263 | is_set_key_cmd = ((ioc.cmd == BRCMF_C_SET_KEY) || |
1264 | ((ioc.cmd == BRCMF_C_SET_VAR) && | |
cf2b4488 | 1265 | !(strncmp("wsec_key", ioc.buf, 9))) || |
366bbb3f | 1266 | ((ioc.cmd == BRCMF_C_SET_VAR) && |
cf2b4488 HP |
1267 | !(strncmp("bsscfg:wsec_key", ioc.buf, 15)))); |
1268 | if (is_set_key_cmd) | |
fc2860a9 | 1269 | brcmf_netdev_wait_pend8021x(net); |
cf2b4488 | 1270 | |
cf2b4488 | 1271 | bcmerror = |
ec66c6fa AS |
1272 | brcmf_proto_ioctl(&drvr_priv->pub, ifidx, (struct brcmf_ioctl *)&ioc, |
1273 | buf, buflen); | |
cf2b4488 | 1274 | |
cf2b4488 HP |
1275 | done: |
1276 | if (!bcmerror && buf && ioc.buf) { | |
1277 | if (copy_to_user(ioc.buf, buf, buflen)) | |
1278 | bcmerror = -EFAULT; | |
1279 | } | |
1280 | ||
46d994b1 | 1281 | kfree(buf); |
cf2b4488 | 1282 | |
9014378b BR |
1283 | if (bcmerror > 0) |
1284 | bcmerror = 0; | |
9014378b | 1285 | |
b74ac12e | 1286 | return bcmerror; |
cf2b4488 HP |
1287 | } |
1288 | ||
fc2860a9 | 1289 | static int brcmf_netdev_stop(struct net_device *net) |
cf2b4488 HP |
1290 | { |
1291 | #if !defined(IGNORE_ETH0_DOWN) | |
abfe1804 | 1292 | struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net); |
cf2b4488 HP |
1293 | |
1294 | DHD_TRACE(("%s: Enter\n", __func__)); | |
f10c5b0b | 1295 | wl_cfg80211_down(); |
56d52fcc | 1296 | if (drvr_priv->pub.up == 0) |
cf2b4488 HP |
1297 | return 0; |
1298 | ||
1299 | /* Set state and stop OS transmissions */ | |
56d52fcc | 1300 | drvr_priv->pub.up = 0; |
cf2b4488 HP |
1301 | netif_stop_queue(net); |
1302 | #else | |
1303 | DHD_ERROR(("BYPASS %s:due to BRCM compilation : under investigation\n", | |
1304 | __func__)); | |
1305 | #endif /* !defined(IGNORE_ETH0_DOWN) */ | |
1306 | ||
cf2b4488 HP |
1307 | return 0; |
1308 | } | |
1309 | ||
fc2860a9 | 1310 | static int brcmf_netdev_open(struct net_device *net) |
cf2b4488 | 1311 | { |
abfe1804 | 1312 | struct brcmf_info *drvr_priv = *(struct brcmf_info **) netdev_priv(net); |
66cbd3ab | 1313 | u32 toe_ol; |
56d52fcc | 1314 | int ifidx = brcmf_net2idx(drvr_priv, net); |
3e26416e | 1315 | s32 ret = 0; |
cf2b4488 HP |
1316 | |
1317 | DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx)); | |
1318 | ||
1319 | if (ifidx == 0) { /* do it only for primary eth0 */ | |
1320 | ||
1321 | /* try to bring up bus */ | |
56d52fcc | 1322 | ret = brcmf_bus_start(&drvr_priv->pub); |
a618cc28 | 1323 | if (ret != 0) { |
cf2b4488 HP |
1324 | DHD_ERROR(("%s: failed with code %d\n", __func__, ret)); |
1325 | return -1; | |
1326 | } | |
56d52fcc | 1327 | atomic_set(&drvr_priv->pend_8021x_cnt, 0); |
cf2b4488 | 1328 | |
56d52fcc | 1329 | memcpy(net->dev_addr, drvr_priv->pub.mac, ETH_ALEN); |
cf2b4488 | 1330 | |
cf2b4488 | 1331 | /* Get current TOE mode from dongle */ |
56d52fcc | 1332 | if (brcmf_toe_get(drvr_priv, ifidx, &toe_ol) >= 0 |
cf2b4488 | 1333 | && (toe_ol & TOE_TX_CSUM_OL) != 0) |
56d52fcc | 1334 | drvr_priv->iflist[ifidx]->net->features |= NETIF_F_IP_CSUM; |
cf2b4488 | 1335 | else |
56d52fcc | 1336 | drvr_priv->iflist[ifidx]->net->features &= ~NETIF_F_IP_CSUM; |
cf2b4488 HP |
1337 | } |
1338 | /* Allow transmit calls */ | |
1339 | netif_start_queue(net); | |
56d52fcc | 1340 | drvr_priv->pub.up = 1; |
f10c5b0b AS |
1341 | if (unlikely(wl_cfg80211_up())) { |
1342 | DHD_ERROR(("%s: failed to bring up cfg80211\n", | |
1343 | __func__)); | |
1344 | return -1; | |
cf2b4488 | 1345 | } |
cf2b4488 | 1346 | |
cf2b4488 HP |
1347 | return ret; |
1348 | } | |
1349 | ||
cf2b4488 | 1350 | int |
abfe1804 | 1351 | brcmf_add_if(struct brcmf_info *drvr_priv, int ifidx, void *handle, char *name, |
66cbd3ab | 1352 | u8 *mac_addr, u32 flags, u8 bssidx) |
cf2b4488 | 1353 | { |
abfe1804 | 1354 | struct brcmf_if *ifp; |
cf2b4488 HP |
1355 | |
1356 | DHD_TRACE(("%s: idx %d, handle->%p\n", __func__, ifidx, handle)); | |
1357 | ||
40695d1a | 1358 | ASSERT(drvr_priv && (ifidx < BRCMF_MAX_IFS)); |
cf2b4488 | 1359 | |
56d52fcc | 1360 | ifp = drvr_priv->iflist[ifidx]; |
a7c551bc | 1361 | if (!ifp) { |
abfe1804 | 1362 | ifp = kmalloc(sizeof(struct brcmf_if), GFP_ATOMIC); |
a7c551bc | 1363 | if (!ifp) { |
abfe1804 | 1364 | DHD_ERROR(("%s: OOM - struct dhd_if\n", __func__)); |
a7c551bc AS |
1365 | return -ENOMEM; |
1366 | } | |
cf2b4488 HP |
1367 | } |
1368 | ||
abfe1804 | 1369 | memset(ifp, 0, sizeof(struct brcmf_if)); |
56d52fcc AS |
1370 | ifp->info = drvr_priv; |
1371 | drvr_priv->iflist[ifidx] = ifp; | |
cbf6baac | 1372 | strlcpy(ifp->name, name, IFNAMSIZ); |
cf2b4488 | 1373 | if (mac_addr != NULL) |
b8d63078 | 1374 | memcpy(&ifp->mac_addr, mac_addr, ETH_ALEN); |
cf2b4488 HP |
1375 | |
1376 | if (handle == NULL) { | |
05dc0f43 | 1377 | ifp->state = BRCMF_E_IF_ADD; |
cf2b4488 | 1378 | ifp->idx = ifidx; |
56d52fcc AS |
1379 | ASSERT(drvr_priv->sysioc_tsk); |
1380 | up(&drvr_priv->sysioc_sem); | |
cf2b4488 HP |
1381 | } else |
1382 | ifp->net = (struct net_device *)handle; | |
1383 | ||
1384 | return 0; | |
1385 | } | |
1386 | ||
abfe1804 | 1387 | void brcmf_del_if(struct brcmf_info *drvr_priv, int ifidx) |
cf2b4488 | 1388 | { |
abfe1804 | 1389 | struct brcmf_if *ifp; |
cf2b4488 HP |
1390 | |
1391 | DHD_TRACE(("%s: idx %d\n", __func__, ifidx)); | |
1392 | ||
40695d1a | 1393 | ASSERT(drvr_priv && ifidx && (ifidx < BRCMF_MAX_IFS)); |
56d52fcc | 1394 | ifp = drvr_priv->iflist[ifidx]; |
cf2b4488 HP |
1395 | if (!ifp) { |
1396 | DHD_ERROR(("%s: Null interface\n", __func__)); | |
1397 | return; | |
1398 | } | |
1399 | ||
05dc0f43 | 1400 | ifp->state = BRCMF_E_IF_DEL; |
cf2b4488 | 1401 | ifp->idx = ifidx; |
56d52fcc AS |
1402 | ASSERT(drvr_priv->sysioc_tsk); |
1403 | up(&drvr_priv->sysioc_sem); | |
cf2b4488 HP |
1404 | } |
1405 | ||
46c3db78 | 1406 | struct brcmf_pub *brcmf_attach(struct brcmf_bus *bus, uint bus_hdrlen) |
cf2b4488 | 1407 | { |
abfe1804 | 1408 | struct brcmf_info *drvr_priv = NULL; |
cf2b4488 HP |
1409 | struct net_device *net; |
1410 | ||
1411 | DHD_TRACE(("%s: Enter\n", __func__)); | |
cf2b4488 HP |
1412 | |
1413 | /* Allocate etherdev, including space for private structure */ | |
56d52fcc | 1414 | net = alloc_etherdev(sizeof(drvr_priv)); |
a618cc28 | 1415 | if (!net) { |
cf2b4488 HP |
1416 | DHD_ERROR(("%s: OOM - alloc_etherdev\n", __func__)); |
1417 | goto fail; | |
1418 | } | |
1419 | ||
abfe1804 AS |
1420 | /* Allocate primary brcmf_info */ |
1421 | drvr_priv = kzalloc(sizeof(struct brcmf_info), GFP_ATOMIC); | |
56d52fcc | 1422 | if (!drvr_priv) { |
cf2b4488 HP |
1423 | DHD_ERROR(("%s: OOM - alloc dhd_info\n", __func__)); |
1424 | goto fail; | |
1425 | } | |
1426 | ||
cf2b4488 | 1427 | /* |
abfe1804 | 1428 | * Save the brcmf_info into the priv |
cf2b4488 | 1429 | */ |
56d52fcc | 1430 | memcpy(netdev_priv(net), &drvr_priv, sizeof(drvr_priv)); |
cf2b4488 HP |
1431 | |
1432 | /* Set network interface name if it was provided as module parameter */ | |
1433 | if (iface_name[0]) { | |
1434 | int len; | |
1435 | char ch; | |
1436 | strncpy(net->name, iface_name, IFNAMSIZ); | |
1437 | net->name[IFNAMSIZ - 1] = 0; | |
1438 | len = strlen(net->name); | |
1439 | ch = net->name[len - 1]; | |
1440 | if ((ch > '9' || ch < '0') && (len < IFNAMSIZ - 2)) | |
1441 | strcat(net->name, "%d"); | |
1442 | } | |
1443 | ||
56d52fcc | 1444 | if (brcmf_add_if(drvr_priv, 0, (void *)net, net->name, NULL, 0, 0) == |
40695d1a | 1445 | BRCMF_BAD_IF) |
cf2b4488 HP |
1446 | goto fail; |
1447 | ||
1448 | net->netdev_ops = NULL; | |
56d52fcc | 1449 | sema_init(&drvr_priv->proto_sem, 1); |
cf2b4488 | 1450 | /* Initialize other structure content */ |
56d52fcc | 1451 | init_waitqueue_head(&drvr_priv->ioctl_resp_wait); |
cf2b4488 | 1452 | |
cf2b4488 | 1453 | /* Link to info module */ |
56d52fcc | 1454 | drvr_priv->pub.info = drvr_priv; |
cf2b4488 HP |
1455 | |
1456 | /* Link to bus module */ | |
56d52fcc AS |
1457 | drvr_priv->pub.bus = bus; |
1458 | drvr_priv->pub.hdrlen = bus_hdrlen; | |
cf2b4488 HP |
1459 | |
1460 | /* Attach and link in the protocol */ | |
56d52fcc | 1461 | if (brcmf_proto_attach(&drvr_priv->pub) != 0) { |
cf2b4488 HP |
1462 | DHD_ERROR(("dhd_prot_attach failed\n")); |
1463 | goto fail; | |
1464 | } | |
cf2b4488 | 1465 | |
cf2b4488 | 1466 | /* Attach and link in the cfg80211 */ |
56d52fcc | 1467 | if (unlikely(wl_cfg80211_attach(net, &drvr_priv->pub))) { |
f10c5b0b AS |
1468 | DHD_ERROR(("wl_cfg80211_attach failed\n")); |
1469 | goto fail; | |
1470 | } | |
cf2b4488 | 1471 | |
7af9d0ca | 1472 | if (brcmf_sysioc) { |
56d52fcc AS |
1473 | sema_init(&drvr_priv->sysioc_sem, 0); |
1474 | drvr_priv->sysioc_tsk = kthread_run(_brcmf_sysioc_thread, drvr_priv, | |
d809dcb9 | 1475 | "_dhd_sysioc"); |
56d52fcc | 1476 | if (IS_ERR(drvr_priv->sysioc_tsk)) { |
d809dcb9 JC |
1477 | printk(KERN_WARNING |
1478 | "_dhd_sysioc thread failed to start\n"); | |
56d52fcc | 1479 | drvr_priv->sysioc_tsk = NULL; |
d809dcb9 JC |
1480 | } |
1481 | } else | |
56d52fcc | 1482 | drvr_priv->sysioc_tsk = NULL; |
cf2b4488 HP |
1483 | |
1484 | /* | |
abfe1804 | 1485 | * Save the brcmf_info into the priv |
cf2b4488 | 1486 | */ |
56d52fcc | 1487 | memcpy(netdev_priv(net), &drvr_priv, sizeof(drvr_priv)); |
cf2b4488 HP |
1488 | |
1489 | #if defined(CUSTOMER_HW2) && defined(CONFIG_WIFI_CONTROL_FUNC) | |
1490 | g_bus = bus; | |
1491 | #endif | |
1492 | #if defined(CONFIG_PM_SLEEP) | |
8d825a8e | 1493 | atomic_set(&brcmf_mmc_suspend, false); |
cf2b4488 HP |
1494 | #endif /* defined(CONFIG_PM_SLEEP) */ |
1495 | /* && defined(DHD_GPL) */ | |
1496 | /* Init lock suspend to prevent kernel going to suspend */ | |
cf2b4488 | 1497 | #ifdef CONFIG_HAS_EARLYSUSPEND |
56d52fcc AS |
1498 | drvr_priv->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 20; |
1499 | drvr_priv->early_suspend.suspend = brcmf_early_suspend; | |
1500 | drvr_priv->early_suspend.resume = brcmf_late_resume; | |
1501 | register_early_suspend(&drvr_priv->early_suspend); | |
cf2b4488 HP |
1502 | #endif |
1503 | ||
56d52fcc | 1504 | return &drvr_priv->pub; |
cf2b4488 HP |
1505 | |
1506 | fail: | |
1507 | if (net) | |
1508 | free_netdev(net); | |
56d52fcc AS |
1509 | if (drvr_priv) |
1510 | brcmf_detach(&drvr_priv->pub); | |
cf2b4488 HP |
1511 | |
1512 | return NULL; | |
1513 | } | |
1514 | ||
fb1d0aa2 | 1515 | int brcmf_bus_start(struct brcmf_pub *drvr) |
cf2b4488 HP |
1516 | { |
1517 | int ret = -1; | |
abfe1804 | 1518 | struct brcmf_info *drvr_priv = drvr->info; |
40695d1a AS |
1519 | /* Room for "event_msgs" + '\0' + bitvec */ |
1520 | char iovbuf[BRCMF_EVENTING_MASK_LEN + 12]; | |
cf2b4488 | 1521 | |
56d52fcc | 1522 | ASSERT(drvr_priv); |
cf2b4488 HP |
1523 | |
1524 | DHD_TRACE(("%s:\n", __func__)); | |
1525 | ||
cf2b4488 | 1526 | /* Bring up the bus */ |
56d52fcc | 1527 | ret = brcmf_sdbrcm_bus_init(&drvr_priv->pub, true); |
a618cc28 | 1528 | if (ret != 0) { |
54ca2969 RV |
1529 | DHD_ERROR(("%s, brcmf_sdbrcm_bus_init failed %d\n", __func__, |
1530 | ret)); | |
cf2b4488 HP |
1531 | return ret; |
1532 | } | |
cf2b4488 HP |
1533 | |
1534 | /* If bus is not ready, can't come up */ | |
56d52fcc | 1535 | if (drvr_priv->pub.busstate != DHD_BUS_DATA) { |
cf2b4488 HP |
1536 | DHD_ERROR(("%s failed bus is not ready\n", __func__)); |
1537 | return -ENODEV; | |
1538 | } | |
248dcbb0 | 1539 | |
40695d1a | 1540 | brcmu_mkiovar("event_msgs", drvr->eventmask, BRCMF_EVENTING_MASK_LEN, |
67ad48bc | 1541 | iovbuf, sizeof(iovbuf)); |
56d52fcc | 1542 | brcmf_proto_cdc_query_ioctl(drvr, 0, BRCMF_C_GET_VAR, iovbuf, |
0aa94b84 | 1543 | sizeof(iovbuf)); |
40695d1a | 1544 | memcpy(drvr->eventmask, iovbuf, BRCMF_EVENTING_MASK_LEN); |
56d52fcc AS |
1545 | |
1546 | setbit(drvr->eventmask, BRCMF_E_SET_SSID); | |
1547 | setbit(drvr->eventmask, BRCMF_E_PRUNE); | |
1548 | setbit(drvr->eventmask, BRCMF_E_AUTH); | |
1549 | setbit(drvr->eventmask, BRCMF_E_REASSOC); | |
1550 | setbit(drvr->eventmask, BRCMF_E_REASSOC_IND); | |
1551 | setbit(drvr->eventmask, BRCMF_E_DEAUTH_IND); | |
1552 | setbit(drvr->eventmask, BRCMF_E_DISASSOC_IND); | |
1553 | setbit(drvr->eventmask, BRCMF_E_DISASSOC); | |
1554 | setbit(drvr->eventmask, BRCMF_E_JOIN); | |
1555 | setbit(drvr->eventmask, BRCMF_E_ASSOC_IND); | |
1556 | setbit(drvr->eventmask, BRCMF_E_PSK_SUP); | |
1557 | setbit(drvr->eventmask, BRCMF_E_LINK); | |
1558 | setbit(drvr->eventmask, BRCMF_E_NDIS_LINK); | |
1559 | setbit(drvr->eventmask, BRCMF_E_MIC_ERROR); | |
1560 | setbit(drvr->eventmask, BRCMF_E_PMKID_CACHE); | |
1561 | setbit(drvr->eventmask, BRCMF_E_TXFAIL); | |
1562 | setbit(drvr->eventmask, BRCMF_E_JOIN_START); | |
1563 | setbit(drvr->eventmask, BRCMF_E_SCAN_COMPLETE); | |
cf2b4488 HP |
1564 | |
1565 | /* enable dongle roaming event */ | |
1566 | ||
56d52fcc | 1567 | drvr->pktfilter_count = 1; |
cf2b4488 | 1568 | /* Setup filter to allow only unicast */ |
56d52fcc | 1569 | drvr->pktfilter[0] = "100 0 0 0 0x01 0x00"; |
cf2b4488 HP |
1570 | |
1571 | /* Bus is ready, do any protocol initialization */ | |
56d52fcc | 1572 | ret = brcmf_proto_init(&drvr_priv->pub); |
a618cc28 | 1573 | if (ret < 0) |
cf2b4488 HP |
1574 | return ret; |
1575 | ||
1576 | return 0; | |
1577 | } | |
1578 | ||
8d825a8e | 1579 | static struct net_device_ops brcmf_netdev_ops_pri = { |
fc2860a9 AS |
1580 | .ndo_open = brcmf_netdev_open, |
1581 | .ndo_stop = brcmf_netdev_stop, | |
1582 | .ndo_get_stats = brcmf_netdev_get_stats, | |
1583 | .ndo_do_ioctl = brcmf_netdev_ioctl_entry, | |
1584 | .ndo_start_xmit = brcmf_netdev_start_xmit, | |
1585 | .ndo_set_mac_address = brcmf_netdev_set_mac_address, | |
1586 | .ndo_set_multicast_list = brcmf_netdev_set_multicast_list | |
cf2b4488 HP |
1587 | }; |
1588 | ||
fb1d0aa2 | 1589 | int brcmf_net_attach(struct brcmf_pub *drvr, int ifidx) |
cf2b4488 | 1590 | { |
abfe1804 | 1591 | struct brcmf_info *drvr_priv = drvr->info; |
cf2b4488 | 1592 | struct net_device *net; |
b8d63078 | 1593 | u8 temp_addr[ETH_ALEN] = { |
cf2b4488 HP |
1594 | 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33}; |
1595 | ||
1596 | DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx)); | |
1597 | ||
56d52fcc | 1598 | ASSERT(drvr_priv && drvr_priv->iflist[ifidx]); |
cf2b4488 | 1599 | |
56d52fcc | 1600 | net = drvr_priv->iflist[ifidx]->net; |
cf2b4488 HP |
1601 | ASSERT(net); |
1602 | ||
1603 | ASSERT(!net->netdev_ops); | |
8d825a8e | 1604 | net->netdev_ops = &brcmf_netdev_ops_pri; |
cf2b4488 HP |
1605 | |
1606 | /* | |
1607 | * We have to use the primary MAC for virtual interfaces | |
1608 | */ | |
1609 | if (ifidx != 0) { | |
1610 | /* for virtual interfaces use the primary MAC */ | |
56d52fcc | 1611 | memcpy(temp_addr, drvr_priv->pub.mac, ETH_ALEN); |
cf2b4488 HP |
1612 | |
1613 | } | |
1614 | ||
1615 | if (ifidx == 1) { | |
e131d3ce | 1616 | DHD_TRACE(("%s ACCESS POINT MAC:\n", __func__)); |
cf2b4488 HP |
1617 | /* ACCESSPOINT INTERFACE CASE */ |
1618 | temp_addr[0] |= 0X02; /* set bit 2 , | |
1619 | - Locally Administered address */ | |
1620 | ||
1621 | } | |
56d52fcc | 1622 | net->hard_header_len = ETH_HLEN + drvr_priv->pub.hdrlen; |
fc2860a9 | 1623 | net->ethtool_ops = &brcmf_ethtool_ops; |
cf2b4488 | 1624 | |
56d52fcc AS |
1625 | drvr_priv->pub.rxsz = net->mtu + net->hard_header_len + |
1626 | drvr_priv->pub.hdrlen; | |
cf2b4488 | 1627 | |
b8d63078 | 1628 | memcpy(net->dev_addr, temp_addr, ETH_ALEN); |
cf2b4488 HP |
1629 | |
1630 | if (register_netdev(net) != 0) { | |
1631 | DHD_ERROR(("%s: couldn't register the net device\n", | |
1632 | __func__)); | |
1633 | goto fail; | |
1634 | } | |
1635 | ||
0bef7748 | 1636 | DHD_INFO(("%s: Broadcom Dongle Host Driver\n", net->name)); |
cf2b4488 HP |
1637 | |
1638 | return 0; | |
1639 | ||
1640 | fail: | |
1641 | net->netdev_ops = NULL; | |
b74ac12e | 1642 | return -EBADE; |
cf2b4488 HP |
1643 | } |
1644 | ||
fb1d0aa2 | 1645 | static void brcmf_bus_detach(struct brcmf_pub *drvr) |
cf2b4488 | 1646 | { |
abfe1804 | 1647 | struct brcmf_info *drvr_priv; |
cf2b4488 HP |
1648 | |
1649 | DHD_TRACE(("%s: Enter\n", __func__)); | |
1650 | ||
56d52fcc AS |
1651 | if (drvr) { |
1652 | drvr_priv = drvr->info; | |
1653 | if (drvr_priv) { | |
cf2b4488 | 1654 | /* Stop the protocol module */ |
56d52fcc | 1655 | brcmf_proto_stop(&drvr_priv->pub); |
cf2b4488 HP |
1656 | |
1657 | /* Stop the bus module */ | |
56d52fcc | 1658 | brcmf_sdbrcm_bus_stop(drvr_priv->pub.bus, true); |
cf2b4488 HP |
1659 | } |
1660 | } | |
1661 | } | |
1662 | ||
fb1d0aa2 | 1663 | void brcmf_detach(struct brcmf_pub *drvr) |
cf2b4488 | 1664 | { |
abfe1804 | 1665 | struct brcmf_info *drvr_priv; |
cf2b4488 HP |
1666 | |
1667 | DHD_TRACE(("%s: Enter\n", __func__)); | |
1668 | ||
56d52fcc AS |
1669 | if (drvr) { |
1670 | drvr_priv = drvr->info; | |
1671 | if (drvr_priv) { | |
abfe1804 | 1672 | struct brcmf_if *ifp; |
cf2b4488 HP |
1673 | int i; |
1674 | ||
1675 | #if defined(CONFIG_HAS_EARLYSUSPEND) | |
56d52fcc AS |
1676 | if (drvr_priv->early_suspend.suspend) |
1677 | unregister_early_suspend( | |
1678 | &drvr_priv->early_suspend); | |
cf2b4488 HP |
1679 | #endif /* defined(CONFIG_HAS_EARLYSUSPEND) */ |
1680 | ||
40695d1a | 1681 | for (i = 1; i < BRCMF_MAX_IFS; i++) |
56d52fcc AS |
1682 | if (drvr_priv->iflist[i]) |
1683 | brcmf_del_if(drvr_priv, i); | |
cf2b4488 | 1684 | |
56d52fcc | 1685 | ifp = drvr_priv->iflist[0]; |
cf2b4488 | 1686 | ASSERT(ifp); |
8d825a8e | 1687 | if (ifp->net->netdev_ops == &brcmf_netdev_ops_pri) { |
fc2860a9 | 1688 | brcmf_netdev_stop(ifp->net); |
cf2b4488 HP |
1689 | unregister_netdev(ifp->net); |
1690 | } | |
1691 | ||
56d52fcc AS |
1692 | if (drvr_priv->sysioc_tsk) { |
1693 | send_sig(SIGTERM, drvr_priv->sysioc_tsk, 1); | |
1694 | kthread_stop(drvr_priv->sysioc_tsk); | |
1695 | drvr_priv->sysioc_tsk = NULL; | |
cf2b4488 HP |
1696 | } |
1697 | ||
56d52fcc | 1698 | brcmf_bus_detach(drvr); |
cf2b4488 | 1699 | |
56d52fcc AS |
1700 | if (drvr->prot) |
1701 | brcmf_proto_detach(drvr); | |
cf2b4488 | 1702 | |
f10c5b0b | 1703 | wl_cfg80211_detach(); |
cf2b4488 | 1704 | |
cf2b4488 | 1705 | /* && defined(DHD_GPL) */ |
cf2b4488 | 1706 | free_netdev(ifp->net); |
182acb3c | 1707 | kfree(ifp); |
56d52fcc | 1708 | kfree(drvr_priv); |
cf2b4488 HP |
1709 | } |
1710 | } | |
1711 | } | |
1712 | ||
db62efcc | 1713 | static void __exit brcmf_module_cleanup(void) |
cf2b4488 HP |
1714 | { |
1715 | DHD_TRACE(("%s: Enter\n", __func__)); | |
1716 | ||
46c3db78 | 1717 | brcmf_bus_unregister(); |
cf2b4488 HP |
1718 | } |
1719 | ||
db62efcc | 1720 | static int __init brcmf_module_init(void) |
cf2b4488 HP |
1721 | { |
1722 | int error; | |
1723 | ||
1724 | DHD_TRACE(("%s: Enter\n", __func__)); | |
1725 | ||
46c3db78 | 1726 | error = brcmf_bus_register(); |
cf2b4488 | 1727 | |
49ba9d2d | 1728 | if (error) { |
54ca2969 | 1729 | DHD_ERROR(("%s: dhd_bus_register failed\n", __func__)); |
f0c0dda0 | 1730 | goto failed; |
cf2b4488 | 1731 | } |
e327ec23 | 1732 | return 0; |
cf2b4488 | 1733 | |
f0c0dda0 | 1734 | failed: |
cf2b4488 HP |
1735 | return -EINVAL; |
1736 | } | |
1737 | ||
db62efcc AS |
1738 | module_init(brcmf_module_init); |
1739 | module_exit(brcmf_module_cleanup); | |
cf2b4488 HP |
1740 | |
1741 | /* | |
1742 | * OS specific functions required to implement DHD driver in OS independent way | |
1743 | */ | |
fb1d0aa2 | 1744 | int brcmf_os_proto_block(struct brcmf_pub *drvr) |
cf2b4488 | 1745 | { |
abfe1804 | 1746 | struct brcmf_info *drvr_priv = drvr->info; |
cf2b4488 | 1747 | |
56d52fcc AS |
1748 | if (drvr_priv) { |
1749 | down(&drvr_priv->proto_sem); | |
cf2b4488 HP |
1750 | return 1; |
1751 | } | |
1752 | return 0; | |
1753 | } | |
1754 | ||
fb1d0aa2 | 1755 | int brcmf_os_proto_unblock(struct brcmf_pub *drvr) |
cf2b4488 | 1756 | { |
abfe1804 | 1757 | struct brcmf_info *drvr_priv = drvr->info; |
cf2b4488 | 1758 | |
56d52fcc AS |
1759 | if (drvr_priv) { |
1760 | up(&drvr_priv->proto_sem); | |
cf2b4488 HP |
1761 | return 1; |
1762 | } | |
1763 | ||
1764 | return 0; | |
1765 | } | |
1766 | ||
a84bac46 | 1767 | unsigned int brcmf_os_get_ioctl_resp_timeout(void) |
cf2b4488 | 1768 | { |
7af9d0ca | 1769 | return (unsigned int)brcmf_ioctl_timeout_msec; |
cf2b4488 HP |
1770 | } |
1771 | ||
a84bac46 | 1772 | void brcmf_os_set_ioctl_resp_timeout(unsigned int timeout_msec) |
cf2b4488 | 1773 | { |
7af9d0ca | 1774 | brcmf_ioctl_timeout_msec = (int)timeout_msec; |
cf2b4488 HP |
1775 | } |
1776 | ||
fb1d0aa2 AS |
1777 | int brcmf_os_ioctl_resp_wait(struct brcmf_pub *drvr, uint *condition, |
1778 | bool *pending) | |
cf2b4488 | 1779 | { |
abfe1804 | 1780 | struct brcmf_info *drvr_priv = drvr->info; |
cf2b4488 | 1781 | DECLARE_WAITQUEUE(wait, current); |
7af9d0ca | 1782 | int timeout = brcmf_ioctl_timeout_msec; |
cf2b4488 HP |
1783 | |
1784 | /* Convert timeout in millsecond to jiffies */ | |
1785 | timeout = timeout * HZ / 1000; | |
1786 | ||
1787 | /* Wait until control frame is available */ | |
56d52fcc | 1788 | add_wait_queue(&drvr_priv->ioctl_resp_wait, &wait); |
cf2b4488 HP |
1789 | set_current_state(TASK_INTERRUPTIBLE); |
1790 | ||
1791 | while (!(*condition) && (!signal_pending(current) && timeout)) | |
1792 | timeout = schedule_timeout(timeout); | |
1793 | ||
1794 | if (signal_pending(current)) | |
0f0881b0 | 1795 | *pending = true; |
cf2b4488 HP |
1796 | |
1797 | set_current_state(TASK_RUNNING); | |
56d52fcc | 1798 | remove_wait_queue(&drvr_priv->ioctl_resp_wait, &wait); |
cf2b4488 HP |
1799 | |
1800 | return timeout; | |
1801 | } | |
1802 | ||
fb1d0aa2 | 1803 | int brcmf_os_ioctl_resp_wake(struct brcmf_pub *drvr) |
cf2b4488 | 1804 | { |
abfe1804 | 1805 | struct brcmf_info *drvr_priv = drvr->info; |
cf2b4488 | 1806 | |
56d52fcc AS |
1807 | if (waitqueue_active(&drvr_priv->ioctl_resp_wait)) |
1808 | wake_up_interruptible(&drvr_priv->ioctl_resp_wait); | |
cf2b4488 HP |
1809 | |
1810 | return 0; | |
1811 | } | |
1812 | ||
abfe1804 | 1813 | static int brcmf_host_event(struct brcmf_info *drvr_priv, int *ifidx, void *pktdata, |
63bec49e | 1814 | struct brcmf_event_msg *event, void **data) |
cf2b4488 HP |
1815 | { |
1816 | int bcmerror = 0; | |
1817 | ||
56d52fcc | 1818 | ASSERT(drvr_priv != NULL); |
cf2b4488 | 1819 | |
56d52fcc | 1820 | bcmerror = brcmf_c_host_event(drvr_priv, ifidx, pktdata, event, data); |
a1c5ad81 | 1821 | if (bcmerror != 0) |
cf2b4488 HP |
1822 | return bcmerror; |
1823 | ||
56d52fcc AS |
1824 | ASSERT(drvr_priv->iflist[*ifidx] != NULL); |
1825 | ASSERT(drvr_priv->iflist[*ifidx]->net != NULL); | |
1826 | if (drvr_priv->iflist[*ifidx]->net) | |
1827 | wl_cfg80211_event(drvr_priv->iflist[*ifidx]->net, event, *data); | |
cf2b4488 HP |
1828 | |
1829 | return bcmerror; | |
1830 | } | |
1831 | ||
fc2860a9 | 1832 | int brcmf_netdev_reset(struct net_device *dev, u8 flag) |
cf2b4488 | 1833 | { |
abfe1804 | 1834 | struct brcmf_info *drvr_priv = *(struct brcmf_info **)netdev_priv(dev); |
cf2b4488 | 1835 | |
56d52fcc | 1836 | brcmf_bus_devreset(&drvr_priv->pub, flag); |
cf2b4488 | 1837 | |
cf2b4488 HP |
1838 | return 1; |
1839 | } | |
1840 | ||
abfe1804 | 1841 | static int brcmf_get_pend_8021x_cnt(struct brcmf_info *drvr_priv) |
cf2b4488 | 1842 | { |
56d52fcc | 1843 | return atomic_read(&drvr_priv->pend_8021x_cnt); |
cf2b4488 HP |
1844 | } |
1845 | ||
1846 | #define MAX_WAIT_FOR_8021X_TX 10 | |
1847 | ||
fc2860a9 | 1848 | int brcmf_netdev_wait_pend8021x(struct net_device *dev) |
cf2b4488 | 1849 | { |
abfe1804 | 1850 | struct brcmf_info *drvr_priv = *(struct brcmf_info **)netdev_priv(dev); |
cf2b4488 HP |
1851 | int timeout = 10 * HZ / 1000; |
1852 | int ntimes = MAX_WAIT_FOR_8021X_TX; | |
56d52fcc | 1853 | int pend = brcmf_get_pend_8021x_cnt(drvr_priv); |
cf2b4488 HP |
1854 | |
1855 | while (ntimes && pend) { | |
1856 | if (pend) { | |
1857 | set_current_state(TASK_INTERRUPTIBLE); | |
1858 | schedule_timeout(timeout); | |
1859 | set_current_state(TASK_RUNNING); | |
1860 | ntimes--; | |
1861 | } | |
56d52fcc | 1862 | pend = brcmf_get_pend_8021x_cnt(drvr_priv); |
cf2b4488 HP |
1863 | } |
1864 | return pend; | |
1865 | } | |
1866 | ||
762c2a36 | 1867 | #ifdef BCMDBG |
fb1d0aa2 | 1868 | int brcmf_write_to_file(struct brcmf_pub *drvr, u8 *buf, int size) |
cf2b4488 HP |
1869 | { |
1870 | int ret = 0; | |
1871 | struct file *fp; | |
1872 | mm_segment_t old_fs; | |
1873 | loff_t pos = 0; | |
1874 | ||
1875 | /* change to KERNEL_DS address limit */ | |
1876 | old_fs = get_fs(); | |
1877 | set_fs(KERNEL_DS); | |
1878 | ||
1879 | /* open file to write */ | |
1880 | fp = filp_open("/tmp/mem_dump", O_WRONLY | O_CREAT, 0640); | |
1881 | if (!fp) { | |
0bef7748 | 1882 | DHD_ERROR(("%s: open file error\n", __func__)); |
cf2b4488 HP |
1883 | ret = -1; |
1884 | goto exit; | |
1885 | } | |
1886 | ||
1887 | /* Write buf to file */ | |
1888 | fp->f_op->write(fp, buf, size, &pos); | |
1889 | ||
1890 | exit: | |
1891 | /* free buf before return */ | |
182acb3c | 1892 | kfree(buf); |
cf2b4488 HP |
1893 | /* close file before return */ |
1894 | if (fp) | |
1895 | filp_close(fp, current->files); | |
1896 | /* restore previous address limit */ | |
1897 | set_fs(old_fs); | |
1898 | ||
1899 | return ret; | |
1900 | } | |
762c2a36 | 1901 | #endif /* BCMDBG */ |
47a6d2cd AS |
1902 | |
1903 | #if defined(BCMDBG) | |
1904 | void osl_assert(char *exp, char *file, int line) | |
1905 | { | |
1906 | char tempbuf[256]; | |
1907 | char *basename; | |
1908 | ||
1909 | basename = strrchr(file, '/'); | |
1910 | /* skip the '/' */ | |
1911 | if (basename) | |
1912 | basename++; | |
1913 | ||
1914 | if (!basename) | |
1915 | basename = file; | |
1916 | ||
1917 | snprintf(tempbuf, 256, | |
1918 | "assertion \"%s\" failed: file \"%s\", line %d\n", exp, | |
1919 | basename, line); | |
1920 | ||
1921 | /* | |
1922 | * Print assert message and give it time to | |
1923 | * be written to /var/log/messages | |
1924 | */ | |
1925 | if (!in_interrupt()) { | |
1926 | const int delay = 3; | |
1927 | printk(KERN_ERR "%s", tempbuf); | |
1928 | printk(KERN_ERR "panic in %d seconds\n", delay); | |
1929 | set_current_state(TASK_INTERRUPTIBLE); | |
1930 | schedule_timeout(delay * HZ); | |
1931 | } | |
1932 | ||
1933 | switch (g_assert_type) { | |
1934 | case 0: | |
1935 | panic(KERN_ERR "%s", tempbuf); | |
1936 | break; | |
1937 | case 1: | |
1938 | printk(KERN_ERR "%s", tempbuf); | |
1939 | BUG(); | |
1940 | break; | |
1941 | case 2: | |
1942 | printk(KERN_ERR "%s", tempbuf); | |
1943 | break; | |
1944 | default: | |
1945 | break; | |
1946 | } | |
1947 | } | |
1948 | #endif /* defined(BCMDBG) */ |