84 #include <linux/kernel.h>
86 #include <linux/slab.h>
88 #include <linux/export.h>
118 static void uwb_rc_neh_timer(
unsigned long arg);
120 static void uwb_rc_neh_release(
struct kref *
kref)
127 static void uwb_rc_neh_get(
struct uwb_rc_neh *neh)
129 kref_get(&neh->
kref);
138 kref_put(&neh->
kref, uwb_rc_neh_release);
189 dev_err(dev,
"context %u not set in bitmap\n",
210 u8 expected_type,
u16 expected_event,
224 kref_init(&neh->
kref);
227 neh->
timer.function = uwb_rc_neh_timer;
237 result = __uwb_rc_ctx_get(rc, neh);
243 spin_unlock_irqrestore(&rc->
neh_lock, flags);
252 dev_err(dev,
"cannot open handle to radio controller: %d\n", result);
253 return ERR_PTR(result);
258 __uwb_rc_ctx_put(rc, neh);
275 __uwb_rc_neh_rm(rc, neh);
276 spin_unlock_irqrestore(&rc->
neh_lock, flags);
298 spin_unlock_irqrestore(&rc->
neh_lock, flags);
303 (*neh->
cb)(neh->
rc, neh->
arg, rceb, size);
338 if (uwb_rc_neh_match(h, rceb)) {
345 __uwb_rc_neh_rm(rc, neh);
347 spin_unlock_irqrestore(&rc->
neh_lock, flags);
387 dev_err(dev,
"ignoring event with error code %zu\n",
392 uwb_evt = kzalloc(
sizeof(*uwb_evt),
GFP_ATOMIC);
394 dev_err(dev,
"no memory to queue event 0x%02x/%04x/%02x\n",
399 uwb_evt->
rc = __uwb_rc_get(rc);
408 static void uwb_rc_neh_grok_event(
struct uwb_rc *rc,
struct uwb_rceb *rceb,
size_t size)
418 memcpy(notif, rceb, size);
419 uwb_rc_notif(rc, notif, size);
421 dev_err(dev,
"event 0x%02x/%04x/%02x (%zu bytes): no memory\n",
425 neh = uwb_rc_neh_lookup(rc, rceb);
431 spin_unlock_irqrestore(&rc->
neh_lock, flags);
432 uwb_rc_neh_cb(neh, rceb, size);
434 dev_warn(dev,
"event 0x%02x/%04x/%02x (%zu bytes): nobody cared\n",
485 size_t size, real_size, event_size;
491 if (size <
sizeof(*rceb)) {
492 dev_err(dev,
"not enough data in event buffer to "
493 "process incoming events (%zu left, minimum is "
494 "%zu)\n", size,
sizeof(*rceb));
501 &real_size, &event_size);
502 if (needtofree < 0 && needtofree != -
ENOANO) {
503 dev_err(dev,
"BUG: Unable to filter event "
504 "(0x%02x/%04x/%02x) from "
514 if (needtofree == -
ENOANO) {
519 dev_err(dev,
"BUG: hw sent incomplete event "
520 "0x%02x/%04x/%02x (%zd bytes), only got "
521 "%zu bytes. We don't handle that.\n",
526 real_size = event_size =
ret;
528 uwb_rc_neh_grok_event(rc, rceb, event_size);
556 spin_unlock_irqrestore(&rc->
neh_lock, flags);
560 __uwb_rc_neh_rm(rc, neh);
561 spin_unlock_irqrestore(&rc->
neh_lock, flags);
564 uwb_rc_neh_cb(neh,
NULL, error);
570 static void uwb_rc_neh_timer(
unsigned long arg)
578 spin_unlock_irqrestore(&rc->
neh_lock, flags);
582 __uwb_rc_neh_rm(rc, neh);
585 spin_unlock_irqrestore(&rc->
neh_lock, flags);
612 spin_unlock_irqrestore(&rc->
neh_lock, flags);
616 __uwb_rc_neh_rm(rc, neh);
617 spin_unlock_irqrestore(&rc->
neh_lock, flags);