Lines Matching +full:async +full:- +full:enum

1 /* SPDX-License-Identifier: GPL-2.0-only
9 #error "HID_BPF_ASYNC_MAX_CTX should be set to the maximum number of concurrent async functions"
16 enum hid_bpf_async_state {
26 enum hid_bpf_async_state state;
40 * HID_BPF_ASYNC_CB: macro to define an async callback used in a bpf_wq
42 * The caller is responsible for allocating a key in the async map
55 ctx = hid_bpf_allocate_context(e->hid); \
59 e->state = HID_BPF_ASYNC_STATE_RUNNING; \
63 e->state = HID_BPF_ASYNC_STATE_INITIALIZED; \
71 * ASYNC: macro to automatically handle async callbacks contexts
102 bpf_wq_start(&e->wq, 0); in __start_wq_timer_cb()
117 return -ENOMEM; /* should never happen */ in hid_bpf_async_find_empty_key()
119 bpf_spin_lock(&elem->lock); in hid_bpf_async_find_empty_key()
121 if (elem->state == HID_BPF_ASYNC_STATE_UNSET) { in hid_bpf_async_find_empty_key()
122 elem->state = HID_BPF_ASYNC_STATE_INITIALIZING; in hid_bpf_async_find_empty_key()
123 bpf_spin_unlock(&elem->lock); in hid_bpf_async_find_empty_key()
127 bpf_spin_unlock(&elem->lock); in hid_bpf_async_find_empty_key()
130 return -EINVAL; in hid_bpf_async_find_empty_key()
144 return -EINVAL; in hid_bpf_async_get_ctx()
146 err = bpf_timer_init(&elem->t, &hid_bpf_async_ctx_map, CLOCK_MONOTONIC); in hid_bpf_async_get_ctx()
150 err = bpf_timer_set_callback(&elem->t, __start_wq_timer_cb); in hid_bpf_async_get_ctx()
154 err = bpf_wq_init(&elem->wq, &hid_bpf_async_ctx_map, 0); in hid_bpf_async_get_ctx()
158 elem->state = HID_BPF_ASYNC_STATE_INITIALIZED; in hid_bpf_async_get_ctx()
176 return -EINVAL; in hid_bpf_async_delayed_call()
178 bpf_spin_lock(&elem->lock); in hid_bpf_async_delayed_call()
180 * - HID_BPF_ASYNC_STATE_INITIALIZED -> it's been initialized and ready to be called in hid_bpf_async_delayed_call()
181 * - HID_BPF_ASYNC_STATE_RUNNING -> possible re-entry from the wq itself in hid_bpf_async_delayed_call()
183 if (elem->state != HID_BPF_ASYNC_STATE_INITIALIZED && in hid_bpf_async_delayed_call()
184 elem->state != HID_BPF_ASYNC_STATE_RUNNING) { in hid_bpf_async_delayed_call()
185 bpf_spin_unlock(&elem->lock); in hid_bpf_async_delayed_call()
186 return -EINVAL; in hid_bpf_async_delayed_call()
188 elem->state = HID_BPF_ASYNC_STATE_STARTING; in hid_bpf_async_delayed_call()
189 bpf_spin_unlock(&elem->lock); in hid_bpf_async_delayed_call()
191 elem->hid = hctx->hid->id; in hid_bpf_async_delayed_call()
193 err = bpf_wq_set_callback(&elem->wq, wq_cb, 0); in hid_bpf_async_delayed_call()
199 err = bpf_timer_set_callback(&elem->t, __start_wq_timer_cb); in hid_bpf_async_delayed_call()
203 err = bpf_timer_start(&elem->t, ms_to_ns(milliseconds), 0); in hid_bpf_async_delayed_call()
210 return bpf_wq_start(&elem->wq, 0); in hid_bpf_async_delayed_call()