]>
git.proxmox.com Git - ceph.git/blob - ceph/src/dpdk/lib/librte_eal/linuxapp/kni/kni_fifo.h
4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
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.
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.
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.
21 * Contact Information:
28 #include <exec-env/rte_kni_common.h>
31 * Adds num elements into the fifo. Return the number actually written
33 static inline uint32_t
34 kni_fifo_put(struct rte_kni_fifo
*fifo
, void **data
, uint32_t num
)
37 uint32_t fifo_write
= fifo
->write
;
38 uint32_t fifo_read
= fifo
->read
;
39 uint32_t new_write
= fifo_write
;
41 for (i
= 0; i
< num
; i
++) {
42 new_write
= (new_write
+ 1) & (fifo
->len
- 1);
44 if (new_write
== fifo_read
)
46 fifo
->buffer
[fifo_write
] = data
[i
];
47 fifo_write
= new_write
;
49 fifo
->write
= fifo_write
;
55 * Get up to num elements from the fifo. Return the number actully read
57 static inline uint32_t
58 kni_fifo_get(struct rte_kni_fifo
*fifo
, void **data
, uint32_t num
)
61 uint32_t new_read
= fifo
->read
;
62 uint32_t fifo_write
= fifo
->write
;
64 for (i
= 0; i
< num
; i
++) {
65 if (new_read
== fifo_write
)
68 data
[i
] = fifo
->buffer
[new_read
];
69 new_read
= (new_read
+ 1) & (fifo
->len
- 1);
71 fifo
->read
= new_read
;
77 * Get the num of elements in the fifo
79 static inline uint32_t
80 kni_fifo_count(struct rte_kni_fifo
*fifo
)
82 return (fifo
->len
+ fifo
->write
- fifo
->read
) & (fifo
->len
- 1);
86 * Get the num of available elements in the fifo
88 static inline uint32_t
89 kni_fifo_free_count(struct rte_kni_fifo
*fifo
)
91 return (fifo
->read
- fifo
->write
- 1) & (fifo
->len
- 1);
96 * Initializes the kni fifo structure
99 kni_fifo_init(struct rte_kni_fifo
*fifo
, uint32_t size
)
104 fifo
->elem_size
= sizeof(void *);
108 #endif /* _KNI_FIFO_H_ */