2 * This file is provided under a dual BSD/LGPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
5 * GNU LESSER GENERAL PUBLIC LICENSE
7 * Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
8 * Copyright(c) 2014 Wind River Systems, Inc. All rights reserved.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2.1 of the GNU Lesser General Public License
12 * as published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * Contact Information:
20 * Wind River Systems, Inc.
25 * Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
26 * Copyright(c) 2013-2017 Wind River Systems, Inc. All rights reserved.
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
33 * * Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * * Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in
37 * the documentation and/or other materials provided with the
39 * * Neither the name of Intel Corporation nor the names of its
40 * contributors may be used to endorse or promote products derived
41 * from this software without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
44 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
45 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
46 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
47 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 #ifndef _RTE_AVP_FIFO_H_
58 #define _RTE_AVP_FIFO_H_
61 /* Write memory barrier for kernel compiles */
62 #define AVP_WMB() smp_wmb()
63 /* Read memory barrier for kernel compiles */
64 #define AVP_RMB() smp_rmb()
66 /* Write memory barrier for userspace compiles */
67 #define AVP_WMB() rte_wmb()
68 /* Read memory barrier for userspace compiles */
69 #define AVP_RMB() rte_rmb()
74 * Initializes the avp fifo structure
77 avp_fifo_init(struct rte_avp_fifo *fifo, unsigned int size)
79 /* Ensure size is power of 2 */
80 if (size & (size - 1))
81 rte_panic("AVP fifo size must be power of 2\n");
86 fifo->elem_size = sizeof(void *);
91 * Adds num elements into the fifo. Return the number actually written
93 static inline unsigned
94 avp_fifo_put(struct rte_avp_fifo *fifo, void **data, unsigned int num)
97 unsigned int fifo_write = fifo->write;
98 unsigned int fifo_read = fifo->read;
99 unsigned int new_write = fifo_write;
101 for (i = 0; i < num; i++) {
102 new_write = (new_write + 1) & (fifo->len - 1);
104 if (new_write == fifo_read)
106 fifo->buffer[fifo_write] = data[i];
107 fifo_write = new_write;
110 fifo->write = fifo_write;
115 * Get up to num elements from the fifo. Return the number actually read
117 static inline unsigned int
118 avp_fifo_get(struct rte_avp_fifo *fifo, void **data, unsigned int num)
121 unsigned int new_read = fifo->read;
122 unsigned int fifo_write = fifo->write;
124 if (new_read == fifo_write)
125 return 0; /* empty */
127 for (i = 0; i < num; i++) {
128 if (new_read == fifo_write)
131 data[i] = fifo->buffer[new_read];
132 new_read = (new_read + 1) & (fifo->len - 1);
135 fifo->read = new_read;
140 * Get the num of elements in the fifo
142 static inline unsigned int
143 avp_fifo_count(struct rte_avp_fifo *fifo)
145 return (fifo->len + fifo->write - fifo->read) & (fifo->len - 1);
149 * Get the num of available elements in the fifo
151 static inline unsigned int
152 avp_fifo_free_count(struct rte_avp_fifo *fifo)
154 return (fifo->read - fifo->write - 1) & (fifo->len - 1);
157 #endif /* _RTE_AVP_FIFO_H_ */