Zephyr API Documentation 4.3.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: Copyright (c) 2026 Infineon Technologies AG,
4 * or an affiliate of Infineon Technologies AG.
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 */
8
13
14
15#ifndef ZEPHYR_INCLUDE_RTIO_CQE_H_
16#define ZEPHYR_INCLUDE_RTIO_CQE_H_
17
18#include <stdint.h>
19#include <string.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
31
38
45#define RTIO_CQE_FLAG_MEMPOOL_BUFFER BIT(0)
46
47#define RTIO_CQE_FLAG_GET(flags) FIELD_GET(GENMASK(7, 0), (flags))
48
55#define RTIO_CQE_FLAG_MEMPOOL_GET_BLK_IDX(flags) FIELD_GET(GENMASK(19, 8), (flags))
56
63#define RTIO_CQE_FLAG_MEMPOOL_GET_BLK_CNT(flags) FIELD_GET(GENMASK(31, 20), (flags))
64
72#define RTIO_CQE_FLAG_PREP_MEMPOOL(blk_idx, blk_cnt) \
73 (FIELD_PREP(GENMASK(7, 0), RTIO_CQE_FLAG_MEMPOOL_BUFFER) | \
74 FIELD_PREP(GENMASK(19, 8), blk_idx) | FIELD_PREP(GENMASK(31, 20), blk_cnt))
75
79
90
91/* Private structures and functions used for the pool of cqe structures */
93
94struct rtio_cqe_pool {
95 struct mpsc free_q;
96 const uint16_t pool_size;
97 uint16_t pool_free;
98 struct rtio_cqe *pool;
99};
100
101
102static inline struct rtio_cqe *rtio_cqe_pool_alloc(struct rtio_cqe_pool *pool)
103{
104 struct mpsc_node *node = mpsc_pop(&pool->free_q);
105
106 if (node == NULL) {
107 return NULL;
108 }
109
110 struct rtio_cqe *cqe = CONTAINER_OF(node, struct rtio_cqe, q);
111
112 memset(cqe, 0, sizeof(struct rtio_cqe));
113
114 pool->pool_free--;
115
116 return cqe;
117}
118
119static inline void rtio_cqe_pool_free(struct rtio_cqe_pool *pool, struct rtio_cqe *cqe)
120{
121 mpsc_push(&pool->free_q, &cqe->q);
122
123 pool->pool_free++;
124}
125
126/* Do not try and reformat the macros */
127/* clang-format off */
128
129#define Z_RTIO_CQE_POOL_DEFINE(name, sz) \
130 static struct rtio_cqe CONCAT(_cqe_pool_, name)[sz]; \
131 STRUCT_SECTION_ITERABLE(rtio_cqe_pool, name) = { \
132 .free_q = MPSC_INIT((name.free_q)), \
133 .pool_size = sz, \
134 .pool_free = sz, \
135 .pool = CONCAT(_cqe_pool_, name), \
136 }
137
138/* clang-format on */
140
141
145
146#ifdef __cplusplus
147}
148#endif
149
150#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
#define NULL
Definition iar_missing_defs.h:20
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:83
void * userdata
Associated userdata with operation.
Definition cqe.h:87
struct mpsc_node q
Definition cqe.h:84
uint32_t flags
Flags associated with the operation.
Definition cqe.h:88
int32_t result
Result from operation.
Definition cqe.h:86