CNDP  22.08.0
cne_ring_api.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright (c) 2019-2022 Intel Corporation
4  * Copyright (c) 2007-2009 Kip Macy kmacy@freebsd.org
5  * All rights reserved.
6  * Derived from FreeBSD's bufring.h
7  * Used as BSD-3 Licensed with permission from Kip Macy.
8  */
9 
10 #ifndef _CNE_RING_API_H_
11 #define _CNE_RING_API_H_
12 
39 #include <errno.h>
40 #include <stdio.h>
41 #include <cne_common.h>
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 typedef void cne_ring_t;
48 
49 #define RING_F_SP_ENQ 0x0001
50 #define RING_F_SC_DEQ 0x0002
51 #define RING_F_ALLOCATED 0x8000
61 #define RING_F_EXACT_SZ 0x0004
62 #define CNE_RING_SZ_MASK (0x7fffffffU)
82 CNDP_API ssize_t cne_ring_get_memsize_elem(unsigned int esize, unsigned int count);
83 
98 CNDP_API ssize_t cne_ring_get_memsize(unsigned count);
99 
130 CNDP_API cne_ring_t *cne_ring_create(const char *name, unsigned int esize, unsigned count,
131  unsigned flags);
132 
169 CNDP_API cne_ring_t *cne_ring_init(void *addr, ssize_t size, const char *name, unsigned int esize,
170  unsigned int count, unsigned int flags);
171 
178 CNDP_API void cne_ring_free(cne_ring_t *r);
179 
188 CNDP_API void cne_ring_dump(FILE *f, cne_ring_t *r);
189 
198 CNDP_API void cne_ring_reset(cne_ring_t *r);
199 
208 CNDP_API unsigned cne_ring_count(const cne_ring_t *r);
209 
218 CNDP_API unsigned cne_ring_free_count(const cne_ring_t *r);
219 
229 CNDP_API int cne_ring_full(const cne_ring_t *r);
230 
240 CNDP_API int cne_ring_empty(const cne_ring_t *r);
241 
252 CNDP_API unsigned cne_ring_get_size(const cne_ring_t *r);
253 
262 CNDP_API unsigned cne_ring_get_capacity(const cne_ring_t *r);
263 
271 CNDP_API const char *cne_ring_get_name(const cne_ring_t *r);
272 
280 CNDP_API int cne_ring_get_flags(const cne_ring_t *r);
281 
289 CNDP_API uint32_t cne_ring_get_mask(const cne_ring_t *r);
290 
298 CNDP_API uint32_t cne_ring_get_prod_head(const cne_ring_t *r);
299 
307 CNDP_API uint32_t cne_ring_get_prod_tail(const cne_ring_t *r);
308 
316 CNDP_API uint32_t cne_ring_get_cons_head(const cne_ring_t *r);
317 
325 CNDP_API uint32_t cne_ring_get_cons_tail(const cne_ring_t *r);
326 
327 /****************************************************************************
328  * Ring Generic Functions *
329  ****************************************************************************/
349 CNDP_API unsigned int cne_ring_enqueue_bulk(cne_ring_t *r, void *const *obj_table, unsigned int n,
350  unsigned int *free_space);
351 
368 cne_ring_enqueue(cne_ring_t *r, void *obj)
369 {
370  return cne_ring_enqueue_bulk(r, &obj, 1, NULL) ? 0 : -ENOBUFS;
371 }
372 
392 CNDP_API unsigned int cne_ring_dequeue_bulk(cne_ring_t *r, void **obj_table, unsigned int n,
393  unsigned int *available);
394 
411 CNDP_API __cne_always_inline int
412 cne_ring_dequeue(cne_ring_t *r, void **obj_p)
413 {
414  return cne_ring_dequeue_bulk(r, obj_p, 1, NULL) ? 0 : -ENOENT;
415 }
416 
436 CNDP_API unsigned cne_ring_enqueue_burst(cne_ring_t *r, void *const *obj_table, unsigned int n,
437  unsigned int *free_space);
438 
458 CNDP_API unsigned cne_ring_dequeue_burst(cne_ring_t *r, void **obj_table, unsigned int n,
459  unsigned int *available);
460 
461 /****************************************************************************
462  * Ring Elem Functions *
463  ****************************************************************************/
464 
488 CNDP_API unsigned int cne_ring_enqueue_bulk_elem(cne_ring_t *r, const void *obj_table,
489  unsigned int esize, unsigned int n,
490  unsigned int *free_space);
491 
511 CNDP_API __cne_always_inline int
512 cne_ring_enqueue_elem(cne_ring_t *r, void *obj, unsigned int esize)
513 {
514  return cne_ring_enqueue_bulk_elem(r, obj, esize, 1, NULL) ? 0 : -ENOBUFS;
515 }
516 
540 CNDP_API unsigned int cne_ring_dequeue_bulk_elem(cne_ring_t *r, void *obj_table, unsigned int esize,
541  unsigned int n, unsigned int *available);
542 
563 CNDP_API __cne_always_inline int
564 cne_ring_dequeue_elem(cne_ring_t *r, void *obj_p, unsigned int esize)
565 {
566  return cne_ring_dequeue_bulk_elem(r, obj_p, esize, 1, NULL) ? 0 : -ENOENT;
567 }
568 
592 CNDP_API unsigned cne_ring_enqueue_burst_elem(cne_ring_t *r, const void *obj_table,
593  unsigned int esize, unsigned int n,
594  unsigned int *free_space);
595 
619 CNDP_API unsigned int cne_ring_dequeue_burst_elem(cne_ring_t *r, void *obj_table,
620  unsigned int esize, unsigned int n,
621  unsigned int *available);
622 
623 #ifdef __cplusplus
624 }
625 #endif
626 
627 #endif /* _CNE_RING__API_H_ */
#define __cne_always_inline
Definition: cne_common.h:218
CNDP_API uint32_t cne_ring_get_prod_head(const cne_ring_t *r)
CNDP_API unsigned int cne_ring_dequeue_bulk(cne_ring_t *r, void **obj_table, unsigned int n, unsigned int *available)
CNDP_API int cne_ring_full(const cne_ring_t *r)
CNDP_API unsigned cne_ring_enqueue_burst_elem(cne_ring_t *r, const void *obj_table, unsigned int esize, unsigned int n, unsigned int *free_space)
CNDP_API const char * cne_ring_get_name(const cne_ring_t *r)
CNDP_API cne_ring_t * cne_ring_create(const char *name, unsigned int esize, unsigned count, unsigned flags)
__cne_always_inline int cne_ring_enqueue(cne_ring_t *r, void *obj)
Definition: cne_ring_api.h:368
CNDP_API unsigned cne_ring_count(const cne_ring_t *r)
CNDP_API void cne_ring_dump(FILE *f, cne_ring_t *r)
CNDP_API uint32_t cne_ring_get_prod_tail(const cne_ring_t *r)
CNDP_API unsigned cne_ring_enqueue_burst(cne_ring_t *r, void *const *obj_table, unsigned int n, unsigned int *free_space)
CNDP_API ssize_t cne_ring_get_memsize_elem(unsigned int esize, unsigned int count)
CNDP_API uint32_t cne_ring_get_cons_head(const cne_ring_t *r)
CNDP_API unsigned cne_ring_get_capacity(const cne_ring_t *r)
CNDP_API void cne_ring_reset(cne_ring_t *r)
CNDP_API int cne_ring_get_flags(const cne_ring_t *r)
CNDP_API unsigned cne_ring_get_size(const cne_ring_t *r)
CNDP_API __cne_always_inline int cne_ring_dequeue(cne_ring_t *r, void **obj_p)
Definition: cne_ring_api.h:412
CNDP_API uint32_t cne_ring_get_cons_tail(const cne_ring_t *r)
CNDP_API unsigned cne_ring_dequeue_burst(cne_ring_t *r, void **obj_table, unsigned int n, unsigned int *available)
CNDP_API unsigned int cne_ring_dequeue_burst_elem(cne_ring_t *r, void *obj_table, unsigned int esize, unsigned int n, unsigned int *available)
CNDP_API unsigned int cne_ring_enqueue_bulk(cne_ring_t *r, void *const *obj_table, unsigned int n, unsigned int *free_space)
CNDP_API uint32_t cne_ring_get_mask(const cne_ring_t *r)
CNDP_API ssize_t cne_ring_get_memsize(unsigned count)
CNDP_API unsigned int cne_ring_enqueue_bulk_elem(cne_ring_t *r, const void *obj_table, unsigned int esize, unsigned int n, unsigned int *free_space)
CNDP_API __cne_always_inline int cne_ring_dequeue_elem(cne_ring_t *r, void *obj_p, unsigned int esize)
Definition: cne_ring_api.h:564
CNDP_API __cne_always_inline int cne_ring_enqueue_elem(cne_ring_t *r, void *obj, unsigned int esize)
Definition: cne_ring_api.h:512
CNDP_API cne_ring_t * cne_ring_init(void *addr, ssize_t size, const char *name, unsigned int esize, unsigned int count, unsigned int flags)
CNDP_API void cne_ring_free(cne_ring_t *r)
CNDP_API unsigned cne_ring_free_count(const cne_ring_t *r)
CNDP_API unsigned int cne_ring_dequeue_bulk_elem(cne_ring_t *r, void *obj_table, unsigned int esize, unsigned int n, unsigned int *available)
CNDP_API int cne_ring_empty(const cne_ring_t *r)