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_
60 #include "rte_avp_common.h"
67 /* Write memory barrier for kernel compiles */
68 #define AVP_WMB() smp_wmb()
69 /* Read memory barrier for kernel compiles */
70 #define AVP_RMB() smp_rmb()
72 /* Write memory barrier for userspace compiles */
73 #define AVP_WMB() rte_wmb()
74 /* Read memory barrier for userspace compiles */
75 #define AVP_RMB() rte_rmb()
79 #include <rte_debug.h>
82 * Initializes the avp fifo structure
85 avp_fifo_init(struct rte_avp_fifo *fifo, unsigned int size)
87 /* Ensure size is power of 2 */
88 if (size & (size - 1))
89 rte_panic("AVP fifo size must be power of 2\n");
94 fifo->elem_size = sizeof(void *);
99 * Adds num elements into the fifo. Return the number actually written
101 static inline unsigned
102 avp_fifo_put(struct rte_avp_fifo *fifo, void **data, unsigned int num)
105 unsigned int fifo_write = fifo->write;
106 unsigned int fifo_read = fifo->read;
107 unsigned int new_write = fifo_write;
109 for (i = 0; i < num; i++) {
110 new_write = (new_write + 1) & (fifo->len - 1);
112 if (new_write == fifo_read)
114 fifo->buffer[fifo_write] = data[i];
115 fifo_write = new_write;
118 fifo->write = fifo_write;
123 * Get up to num elements from the fifo. Return the number actually read
125 static inline unsigned int
126 avp_fifo_get(struct rte_avp_fifo *fifo, void **data, unsigned int num)
129 unsigned int new_read = fifo->read;
130 unsigned int fifo_write = fifo->write;
132 if (new_read == fifo_write)
133 return 0; /* empty */
135 for (i = 0; i < num; i++) {
136 if (new_read == fifo_write)
139 data[i] = fifo->buffer[new_read];
140 new_read = (new_read + 1) & (fifo->len - 1);
143 fifo->read = new_read;
148 * Get the num of elements in the fifo
150 static inline unsigned int
151 avp_fifo_count(struct rte_avp_fifo *fifo)
153 return (fifo->len + fifo->write - fifo->read) & (fifo->len - 1);
157 * Get the num of available elements in the fifo
159 static inline unsigned int
160 avp_fifo_free_count(struct rte_avp_fifo *fifo)
162 return (fifo->read - fifo->write - 1) & (fifo->len - 1);
169 #endif /* _RTE_AVP_FIFO_H_ */