Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
cqe.h
Go to the documentation of this file.
1/*
2 * SPDX-Copyright: Copyright (c) 2022 Intel Corporation
3 * SPDX-FileCopyrightText: <text>Copyright (c) 2026 Infineon Technologies AG,
4 * or an affiliate of Infineon Technologies AG. All rights reserved.</text>
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 */
8
14
15
16#ifndef ZEPHYR_INCLUDE_RTIO_CQE_H_
17#define ZEPHYR_INCLUDE_RTIO_CQE_H_
18
19#include <stdint.h>
20#include <string.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
32
39
46#define RTIO_CQE_FLAG_MEMPOOL_BUFFER BIT(0)
47
54#define RTIO_CQE_FLAG_GET(flags) FIELD_GET(GENMASK(7, 0), (flags))
55
62#define RTIO_CQE_FLAG_MEMPOOL_GET_BLK_IDX(flags) FIELD_GET(GENMASK(19, 8), (flags))
63
70#define RTIO_CQE_FLAG_MEMPOOL_GET_BLK_CNT(flags) FIELD_GET(GENMASK(31, 20), (flags))
71
79#define RTIO_CQE_FLAG_PREP_MEMPOOL(blk_idx, blk_cnt) \
80 (FIELD_PREP(GENMASK(7, 0), RTIO_CQE_FLAG_MEMPOOL_BUFFER) | \
81 FIELD_PREP(GENMASK(19, 8), blk_idx) | FIELD_PREP(GENMASK(31, 20), blk_cnt))
82
86
90struct rtio_cqe {
92 struct mpsc_node q;
94
96 void *userdata;
98};
99
100/* Private structures and functions used for the pool of cqe structures */
102
103struct rtio_cqe_pool {
104 struct mpsc free_q;
105 const uint16_t pool_size;
106 uint16_t pool_free;
107 struct rtio_cqe *pool;
108};
109
110
111static inline struct rtio_cqe *rtio_cqe_pool_alloc(struct rtio_cqe_pool *pool)
112{
113 struct mpsc_node *node = mpsc_pop(&pool->free_q);
114
115 if (node == NULL) {
116 return NULL;
117 }
118
119 struct rtio_cqe *cqe = CONTAINER_OF(node, struct rtio_cqe, q);
120
121 memset(cqe, 0, sizeof(struct rtio_cqe));
122
123 pool->pool_free--;
124
125 return cqe;
126}
127
128static inline void rtio_cqe_pool_free(struct rtio_cqe_pool *pool, struct rtio_cqe *cqe)
129{
130 mpsc_push(&pool->free_q, &cqe->q);
131
132 pool->pool_free++;
133}
134
135/* Do not try and reformat the macros */
136/* clang-format off */
137
138#define Z_RTIO_CQE_POOL_DEFINE(name, sz) \
139 static struct rtio_cqe CONCAT(_cqe_pool_, name)[sz]; \
140 STRUCT_SECTION_ITERABLE(rtio_cqe_pool, name) = { \
141 .free_q = MPSC_INIT((name.free_q)), \
142 .pool_size = sz, \
143 .pool_free = sz, \
144 .pool = CONCAT(_cqe_pool_, name), \
145 }
146
147/* clang-format on */
149
150
154
155#ifdef __cplusplus
156}
157#endif
158
159#endif /* ZEPHYR_INCLUDE_RTIO_CQE_H_ */
static ALWAYS_INLINE void mpsc_push(struct mpsc *q, struct mpsc_node *n)
Push a node.
Definition mpsc_lockfree.h:126
static struct mpsc_node * mpsc_pop(struct mpsc *q)
Pop a node off of the list.
Definition mpsc_lockfree.h:145
#define CONTAINER_OF(ptr, type, field)
Get a pointer to a structure containing the element.
Definition util.h:281
A wait-free intrusive multi producer single consumer (MPSC) queue using a singly linked list.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__INT32_TYPE__ int32_t
Definition stdint.h:74
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
void * memset(void *buf, int c, size_t n)
Queue member.
Definition mpsc_lockfree.h:79
MPSC Queue.
Definition mpsc_lockfree.h:86
A completion queue event.
Definition cqe.h:90
void * userdata
Associated userdata with operation.
Definition cqe.h:96
uint32_t flags
Flags associated with the operation.
Definition cqe.h:97
int32_t result
Result from operation.
Definition cqe.h:95
Iterable sections helpers.