DPDK  18.05.1
rte_kni_fifo.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4 
5 
6 
10 static void
11 kni_fifo_init(struct rte_kni_fifo *fifo, unsigned size)
12 {
13  /* Ensure size is power of 2 */
14  if (size & (size - 1))
15  rte_panic("KNI fifo size must be power of 2\n");
16 
17  fifo->write = 0;
18  fifo->read = 0;
19  fifo->len = size;
20  fifo->elem_size = sizeof(void *);
21 }
22 
26 static inline unsigned
27 kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num)
28 {
29  unsigned i = 0;
30  unsigned fifo_write = fifo->write;
31  unsigned fifo_read = fifo->read;
32  unsigned new_write = fifo_write;
33 
34  for (i = 0; i < num; i++) {
35  new_write = (new_write + 1) & (fifo->len - 1);
36 
37  if (new_write == fifo_read)
38  break;
39  fifo->buffer[fifo_write] = data[i];
40  fifo_write = new_write;
41  }
42  fifo->write = fifo_write;
43  return i;
44 }
45 
49 static inline unsigned
50 kni_fifo_get(struct rte_kni_fifo *fifo, void **data, unsigned num)
51 {
52  unsigned i = 0;
53  unsigned new_read = fifo->read;
54  unsigned fifo_write = fifo->write;
55  for (i = 0; i < num; i++) {
56  if (new_read == fifo_write)
57  break;
58 
59  data[i] = fifo->buffer[new_read];
60  new_read = (new_read + 1) & (fifo->len - 1);
61  }
62  fifo->read = new_read;
63  return i;
64 }
65 
69 static inline uint32_t
70 kni_fifo_count(struct rte_kni_fifo *fifo)
71 {
72  return (fifo->len + fifo->write - fifo->read) & (fifo->len - 1);
73 }