.. | .. |
---|
| 1 | +// SPDX-License-Identifier: ISC |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (c) 2012 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 | 4 | */ |
---|
16 | 5 | #include <linux/netdevice.h> |
---|
17 | 6 | |
---|
.. | .. |
---|
34 | 23 | * @ifidx: interface index related to this event. |
---|
35 | 24 | * @ifaddr: ethernet address for interface. |
---|
36 | 25 | * @emsg: common parameters of the firmware event message. |
---|
| 26 | + * @datalen: length of the data array |
---|
37 | 27 | * @data: event specific data part of the firmware event. |
---|
38 | 28 | */ |
---|
39 | 29 | struct brcmf_fweh_queue_item { |
---|
.. | .. |
---|
43 | 33 | u8 ifaddr[ETH_ALEN]; |
---|
44 | 34 | struct brcmf_event_msg_be emsg; |
---|
45 | 35 | u32 datalen; |
---|
46 | | - u8 data[0]; |
---|
| 36 | + u8 data[]; |
---|
47 | 37 | }; |
---|
48 | 38 | |
---|
49 | | -/** |
---|
| 39 | +/* |
---|
50 | 40 | * struct brcmf_fweh_event_name - code, name mapping entry. |
---|
51 | 41 | */ |
---|
52 | 42 | struct brcmf_fweh_event_name { |
---|
.. | .. |
---|
102 | 92 | schedule_work(&fweh->event_work); |
---|
103 | 93 | } |
---|
104 | 94 | |
---|
105 | | -static int brcmf_fweh_call_event_handler(struct brcmf_if *ifp, |
---|
| 95 | +static int brcmf_fweh_call_event_handler(struct brcmf_pub *drvr, |
---|
| 96 | + struct brcmf_if *ifp, |
---|
106 | 97 | enum brcmf_fweh_event_code code, |
---|
107 | 98 | struct brcmf_event_msg *emsg, |
---|
108 | 99 | void *data) |
---|
.. | .. |
---|
117 | 108 | if (fweh->evt_handler[code]) |
---|
118 | 109 | err = fweh->evt_handler[code](ifp, emsg, data); |
---|
119 | 110 | else |
---|
120 | | - brcmf_err("unhandled event %d ignored\n", code); |
---|
| 111 | + bphy_err(drvr, "unhandled event %d ignored\n", code); |
---|
121 | 112 | } else { |
---|
122 | | - brcmf_err("no interface object\n"); |
---|
| 113 | + bphy_err(drvr, "no interface object\n"); |
---|
123 | 114 | } |
---|
124 | 115 | return err; |
---|
125 | 116 | } |
---|
.. | .. |
---|
128 | 119 | * brcmf_fweh_handle_if_event() - handle IF event. |
---|
129 | 120 | * |
---|
130 | 121 | * @drvr: driver information object. |
---|
131 | | - * @item: queue entry. |
---|
132 | | - * @ifpp: interface object (may change upon ADD action). |
---|
| 122 | + * @emsg: event message object. |
---|
| 123 | + * @data: event object. |
---|
133 | 124 | */ |
---|
134 | 125 | static void brcmf_fweh_handle_if_event(struct brcmf_pub *drvr, |
---|
135 | 126 | struct brcmf_event_msg *emsg, |
---|
.. | .. |
---|
138 | 129 | struct brcmf_if_event *ifevent = data; |
---|
139 | 130 | struct brcmf_if *ifp; |
---|
140 | 131 | bool is_p2pdev; |
---|
141 | | - int err = 0; |
---|
142 | 132 | |
---|
143 | 133 | brcmf_dbg(EVENT, "action: %u ifidx: %u bsscfgidx: %u flags: %u role: %u\n", |
---|
144 | 134 | ifevent->action, ifevent->ifidx, ifevent->bsscfgidx, |
---|
.. | .. |
---|
158 | 148 | return; |
---|
159 | 149 | } |
---|
160 | 150 | if (ifevent->ifidx >= BRCMF_MAX_IFS) { |
---|
161 | | - brcmf_err("invalid interface index: %u\n", ifevent->ifidx); |
---|
| 151 | + bphy_err(drvr, "invalid interface index: %u\n", ifevent->ifidx); |
---|
162 | 152 | return; |
---|
163 | 153 | } |
---|
164 | 154 | |
---|
.. | .. |
---|
181 | 171 | if (ifp && ifevent->action == BRCMF_E_IF_CHANGE) |
---|
182 | 172 | brcmf_proto_reset_if(drvr, ifp); |
---|
183 | 173 | |
---|
184 | | - err = brcmf_fweh_call_event_handler(ifp, emsg->event_code, emsg, data); |
---|
| 174 | + brcmf_fweh_call_event_handler(drvr, ifp, emsg->event_code, emsg, |
---|
| 175 | + data); |
---|
185 | 176 | |
---|
186 | 177 | if (ifp && ifevent->action == BRCMF_E_IF_DEL) { |
---|
187 | 178 | bool armed = brcmf_cfg80211_vif_event_armed(drvr->config); |
---|
.. | .. |
---|
237 | 228 | brcmf_fweh_event_name(event->code), event->code, |
---|
238 | 229 | event->emsg.ifidx, event->emsg.bsscfgidx, |
---|
239 | 230 | event->emsg.addr); |
---|
| 231 | + if (event->emsg.bsscfgidx >= BRCMF_MAX_IFS) { |
---|
| 232 | + bphy_err(drvr, "invalid bsscfg index: %u\n", event->emsg.bsscfgidx); |
---|
| 233 | + goto event_free; |
---|
| 234 | + } |
---|
240 | 235 | |
---|
241 | 236 | /* convert event message */ |
---|
242 | 237 | emsg_be = &event->emsg; |
---|
.. | .. |
---|
268 | 263 | ifp = drvr->iflist[0]; |
---|
269 | 264 | else |
---|
270 | 265 | ifp = drvr->iflist[emsg.bsscfgidx]; |
---|
271 | | - err = brcmf_fweh_call_event_handler(ifp, event->code, &emsg, |
---|
272 | | - event->data); |
---|
| 266 | + err = brcmf_fweh_call_event_handler(drvr, ifp, event->code, |
---|
| 267 | + &emsg, event->data); |
---|
273 | 268 | if (err) { |
---|
274 | | - brcmf_err("event handler failed (%d)\n", |
---|
275 | | - event->code); |
---|
| 269 | + bphy_err(drvr, "event handler failed (%d)\n", |
---|
| 270 | + event->code); |
---|
276 | 271 | err = 0; |
---|
277 | 272 | } |
---|
278 | 273 | event_free: |
---|
.. | .. |
---|
312 | 307 | void brcmf_fweh_detach(struct brcmf_pub *drvr) |
---|
313 | 308 | { |
---|
314 | 309 | struct brcmf_fweh_info *fweh = &drvr->fweh; |
---|
315 | | - struct brcmf_if *ifp = brcmf_get_ifp(drvr, 0); |
---|
316 | | - s8 eventmask[BRCMF_EVENTING_MASK_LEN]; |
---|
317 | 310 | |
---|
318 | | - if (ifp) { |
---|
319 | | - /* clear all events */ |
---|
320 | | - memset(eventmask, 0, BRCMF_EVENTING_MASK_LEN); |
---|
321 | | - (void)brcmf_fil_iovar_data_set(ifp, "event_msgs", |
---|
322 | | - eventmask, |
---|
323 | | - BRCMF_EVENTING_MASK_LEN); |
---|
| 311 | + /* cancel the worker if initialized */ |
---|
| 312 | + if (fweh->event_work.func) { |
---|
| 313 | + cancel_work_sync(&fweh->event_work); |
---|
| 314 | + WARN_ON(!list_empty(&fweh->event_q)); |
---|
| 315 | + memset(fweh->evt_handler, 0, sizeof(fweh->evt_handler)); |
---|
324 | 316 | } |
---|
325 | | - /* cancel the worker */ |
---|
326 | | - cancel_work_sync(&fweh->event_work); |
---|
327 | | - WARN_ON(!list_empty(&fweh->event_q)); |
---|
328 | | - memset(fweh->evt_handler, 0, sizeof(fweh->evt_handler)); |
---|
329 | 317 | } |
---|
330 | 318 | |
---|
331 | 319 | /** |
---|
.. | .. |
---|
339 | 327 | brcmf_fweh_handler_t handler) |
---|
340 | 328 | { |
---|
341 | 329 | if (drvr->fweh.evt_handler[code]) { |
---|
342 | | - brcmf_err("event code %d already registered\n", code); |
---|
| 330 | + bphy_err(drvr, "event code %d already registered\n", code); |
---|
343 | 331 | return -ENOSPC; |
---|
344 | 332 | } |
---|
345 | 333 | drvr->fweh.evt_handler[code] = handler; |
---|
.. | .. |
---|
369 | 357 | */ |
---|
370 | 358 | int brcmf_fweh_activate_events(struct brcmf_if *ifp) |
---|
371 | 359 | { |
---|
| 360 | + struct brcmf_pub *drvr = ifp->drvr; |
---|
372 | 361 | int i, err; |
---|
373 | 362 | s8 eventmask[BRCMF_EVENTING_MASK_LEN]; |
---|
374 | 363 | |
---|
.. | .. |
---|
388 | 377 | err = brcmf_fil_iovar_data_set(ifp, "event_msgs", |
---|
389 | 378 | eventmask, BRCMF_EVENTING_MASK_LEN); |
---|
390 | 379 | if (err) |
---|
391 | | - brcmf_err("Set event_msgs error (%d)\n", err); |
---|
| 380 | + bphy_err(drvr, "Set event_msgs error (%d)\n", err); |
---|
392 | 381 | |
---|
393 | 382 | return err; |
---|
394 | 383 | } |
---|
.. | .. |
---|
398 | 387 | * |
---|
399 | 388 | * @drvr: driver information object. |
---|
400 | 389 | * @event_packet: event packet to process. |
---|
| 390 | + * @packet_len: length of the packet |
---|
401 | 391 | * |
---|
402 | 392 | * If the packet buffer contains a firmware event message it will |
---|
403 | 393 | * dispatch the event to a registered handler (using worker). |
---|
404 | 394 | */ |
---|
405 | 395 | void brcmf_fweh_process_event(struct brcmf_pub *drvr, |
---|
406 | 396 | struct brcmf_event *event_packet, |
---|
407 | | - u32 packet_len) |
---|
| 397 | + u32 packet_len, gfp_t gfp) |
---|
408 | 398 | { |
---|
409 | 399 | enum brcmf_fweh_event_code code; |
---|
410 | 400 | struct brcmf_fweh_info *fweh = &drvr->fweh; |
---|
411 | 401 | struct brcmf_fweh_queue_item *event; |
---|
412 | | - gfp_t alloc_flag = GFP_KERNEL; |
---|
413 | 402 | void *data; |
---|
414 | 403 | u32 datalen; |
---|
415 | 404 | |
---|
.. | .. |
---|
428 | 417 | datalen + sizeof(*event_packet) > packet_len) |
---|
429 | 418 | return; |
---|
430 | 419 | |
---|
431 | | - if (in_interrupt()) |
---|
432 | | - alloc_flag = GFP_ATOMIC; |
---|
433 | | - |
---|
434 | | - event = kzalloc(sizeof(*event) + datalen, alloc_flag); |
---|
| 420 | + event = kzalloc(sizeof(*event) + datalen, gfp); |
---|
435 | 421 | if (!event) |
---|
436 | 422 | return; |
---|
437 | 423 | |
---|