]> git.proxmox.com Git - ceph.git/blob - ceph/src/dpdk/lib/librte_eal/linuxapp/kni/kni_fifo.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / dpdk / lib / librte_eal / linuxapp / kni / kni_fifo.h
1 /*-
2 * GPL LICENSE SUMMARY
3 *
4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of version 2 of the GNU General Public License as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18 * The full GNU General Public License is included in this distribution
19 * in the file called LICENSE.GPL.
20 *
21 * Contact Information:
22 * Intel Corporation
23 */
24
25 #ifndef _KNI_FIFO_H_
26 #define _KNI_FIFO_H_
27
28 #include <exec-env/rte_kni_common.h>
29
30 /**
31 * Adds num elements into the fifo. Return the number actually written
32 */
33 static inline uint32_t
34 kni_fifo_put(struct rte_kni_fifo *fifo, void **data, uint32_t num)
35 {
36 uint32_t i = 0;
37 uint32_t fifo_write = fifo->write;
38 uint32_t fifo_read = fifo->read;
39 uint32_t new_write = fifo_write;
40
41 for (i = 0; i < num; i++) {
42 new_write = (new_write + 1) & (fifo->len - 1);
43
44 if (new_write == fifo_read)
45 break;
46 fifo->buffer[fifo_write] = data[i];
47 fifo_write = new_write;
48 }
49 fifo->write = fifo_write;
50
51 return i;
52 }
53
54 /**
55 * Get up to num elements from the fifo. Return the number actully read
56 */
57 static inline uint32_t
58 kni_fifo_get(struct rte_kni_fifo *fifo, void **data, uint32_t num)
59 {
60 uint32_t i = 0;
61 uint32_t new_read = fifo->read;
62 uint32_t fifo_write = fifo->write;
63
64 for (i = 0; i < num; i++) {
65 if (new_read == fifo_write)
66 break;
67
68 data[i] = fifo->buffer[new_read];
69 new_read = (new_read + 1) & (fifo->len - 1);
70 }
71 fifo->read = new_read;
72
73 return i;
74 }
75
76 /**
77 * Get the num of elements in the fifo
78 */
79 static inline uint32_t
80 kni_fifo_count(struct rte_kni_fifo *fifo)
81 {
82 return (fifo->len + fifo->write - fifo->read) & (fifo->len - 1);
83 }
84
85 /**
86 * Get the num of available elements in the fifo
87 */
88 static inline uint32_t
89 kni_fifo_free_count(struct rte_kni_fifo *fifo)
90 {
91 return (fifo->read - fifo->write - 1) & (fifo->len - 1);
92 }
93
94 #ifdef RTE_KNI_VHOST
95 /**
96 * Initializes the kni fifo structure
97 */
98 static inline void
99 kni_fifo_init(struct rte_kni_fifo *fifo, uint32_t size)
100 {
101 fifo->write = 0;
102 fifo->read = 0;
103 fifo->len = size;
104 fifo->elem_size = sizeof(void *);
105 }
106 #endif
107
108 #endif /* _KNI_FIFO_H_ */