4cd8de76548a634013a6fd4f6ff3fb7553c3bbb6
[dpdk.git] / lib / librte_reorder / rte_reorder.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef _RTE_REORDER_H_
35 #define _RTE_REORDER_H_
36
37 /**
38  * @file
39  * RTE reorder
40  *
41  * Reorder library is a component which is designed to
42  * provide ordering of out of ordered packets based on
43  * sequence number present in mbuf.
44  *
45  */
46
47 #include <rte_mbuf.h>
48
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52
53 struct rte_reorder_buffer;
54
55 /**
56  * Create a new reorder buffer instance
57  *
58  * Allocate memory and initialize a new reorder buffer in that
59  * memory, returning the reorder buffer pointer to the user
60  *
61  * @param name
62  *   The name to be given to the reorder buffer instance.
63  * @param socket_id
64  *   The NUMA node on which the memory for the reorder buffer
65  *   instance is to be reserved.
66  * @param size
67  *   Max number of elements that can be stored in the reorder buffer
68  * @return
69  *   The initialized reorder buffer instance, or NULL on error
70  *   On error case, rte_errno will be set appropriately:
71  *    - ENOMEM - no appropriate memory area found in which to create memzone
72  *    - EINVAL - invalid parameters
73  */
74 struct rte_reorder_buffer *
75 rte_reorder_create(const char *name, unsigned socket_id, unsigned int size);
76
77 /**
78  * Initializes given reorder buffer instance
79  *
80  * @param b
81  *   Reorder buffer instance to initialize
82  * @param bufsize
83  *   Size of the reorder buffer
84  * @param name
85  *   The name to be given to the reorder buffer
86  * @param size
87  *   Number of elements that can be stored in reorder buffer
88  * @return
89  *   The initialized reorder buffer instance, or NULL on error
90  *   On error case, rte_errno will be set appropriately:
91  *    - EINVAL - invalid parameters
92  */
93 struct rte_reorder_buffer *
94 rte_reorder_init(struct rte_reorder_buffer *b, unsigned int bufsize,
95                 const char *name, unsigned int size);
96
97 /**
98  * Find an existing reorder buffer instance
99  * and return a pointer to it.
100  *
101  * @param name
102  *   Name of the reorder buffer instacne as passed to rte_reorder_create()
103  * @return
104  *   Pointer to reorder buffer instance or NULL if object not found with rte_errno
105  *   set appropriately. Possible rte_errno values include:
106  *    - ENOENT - required entry not available to return.
107  *    reorder instance list
108  */
109 struct rte_reorder_buffer *
110 rte_reorder_find_existing(const char *name);
111
112 /**
113  * Reset the given reorder buffer instance with initial values.
114  *
115  * @param b
116  *   Reorder buffer instance which has to be reset
117  */
118 void
119 rte_reorder_reset(struct rte_reorder_buffer *b);
120
121 /**
122  * Free reorder buffer instance.
123  *
124  * @param b
125  *   reorder buffer instance
126  * @return
127  *   None
128  */
129 void
130 rte_reorder_free(struct rte_reorder_buffer *b);
131
132 /**
133  * Insert given mbuf in reorder buffer in its correct position
134  *
135  * The given mbuf is to be reordered relative to other mbufs in the system.
136  * The mbuf must contain a sequence number which is then used to place
137  * the buffer in the correct position in the reorder buffer. Reordered
138  * packets can later be taken from the buffer using the rte_reorder_drain()
139  * API.
140  *
141  * @param b
142  *   Reorder buffer where the mbuf has to be inserted.
143  * @param mbuf
144  *   mbuf of packet that needs to be inserted in reorder buffer.
145  * @return
146  *   0 on success
147  *   -1 on error
148  *   On error case, rte_errno will be set appropriately:
149  *    - ENOSPC - Cannot move existing mbufs from reorder buffer to accommodate
150  *      ealry mbuf, but it can be accommodated by performing drain and then insert.
151  *    - ERANGE - Too early or late mbuf which is vastly out of range of expected
152  *      window should be ingnored without any handling.
153  */
154 int
155 rte_reorder_insert(struct rte_reorder_buffer *b, struct rte_mbuf *mbuf);
156
157 /**
158  * Fetch reordered buffers
159  *
160  * Returns a set of in-order buffers from the reorder buffer structure. Gaps
161  * may be present in the sequence numbers of the mbuf if packets have been
162  * delayed too long before reaching the reorder window, or have been previously
163  * dropped by the system.
164  *
165  * @param b
166  *   Reorder buffer instance from which packets are to be drained
167  * @param mbufs
168  *   array of mbufs where reordered packets will be inserted from reorder buffer
169  * @param max_mbufs
170  *   the number of elements in the mbufs array.
171  * @return
172  *   number of mbuf pointers written to mbufs. 0 <= N < max_mbufs.
173  */
174 unsigned int
175 rte_reorder_drain(struct rte_reorder_buffer *b, struct rte_mbuf **mbufs,
176                 unsigned max_mbufs);
177
178 #ifdef __cplusplus
179 }
180 #endif
181
182 #endif /* _RTE_REORDER_H_ */