1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright(c) 2010-2014 Intel Corporation.
9 #include <exec-env/rte_kni_common.h>
12 * Adds num elements into the fifo. Return the number actually written
14 static inline uint32_t
15 kni_fifo_put(struct rte_kni_fifo *fifo, void **data, uint32_t num)
18 uint32_t fifo_write = fifo->write;
19 uint32_t fifo_read = fifo->read;
20 uint32_t new_write = fifo_write;
22 for (i = 0; i < num; i++) {
23 new_write = (new_write + 1) & (fifo->len - 1);
25 if (new_write == fifo_read)
27 fifo->buffer[fifo_write] = data[i];
28 fifo_write = new_write;
30 fifo->write = fifo_write;
36 * Get up to num elements from the fifo. Return the number actully read
38 static inline uint32_t
39 kni_fifo_get(struct rte_kni_fifo *fifo, void **data, uint32_t num)
42 uint32_t new_read = fifo->read;
43 uint32_t fifo_write = fifo->write;
45 for (i = 0; i < num; i++) {
46 if (new_read == fifo_write)
49 data[i] = fifo->buffer[new_read];
50 new_read = (new_read + 1) & (fifo->len - 1);
52 fifo->read = new_read;
58 * Get the num of elements in the fifo
60 static inline uint32_t
61 kni_fifo_count(struct rte_kni_fifo *fifo)
63 return (fifo->len + fifo->write - fifo->read) & (fifo->len - 1);
67 * Get the num of available elements in the fifo
69 static inline uint32_t
70 kni_fifo_free_count(struct rte_kni_fifo *fifo)
72 return (fifo->read - fifo->write - 1) & (fifo->len - 1);
75 #endif /* _KNI_FIFO_H_ */