Imported Upstream version 16.04
[deb_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 #ifdef __cplusplus
48 extern "C" {
49 #endif
50
51 struct rte_reorder_buffer;
52
53 /**
54  * Create a new reorder buffer instance
55  *
56  * Allocate memory and initialize a new reorder buffer in that
57  * memory, returning the reorder buffer pointer to the user
58  *
59  * @param name
60  *   The name to be given to the reorder buffer instance.
61  * @param socket_id
62  *   The NUMA node on which the memory for the reorder buffer
63  *   instance is to be reserved.
64  * @param size
65  *   Max number of elements that can be stored in the reorder buffer
66  * @return
67  *   The initialized reorder buffer instance, or NULL on error
68  *   On error case, rte_errno will be set appropriately:
69  *    - ENOMEM - no appropriate memory area found in which to create memzone
70  *    - EINVAL - invalid parameters
71  */
72 struct rte_reorder_buffer *
73 rte_reorder_create(const char *name, unsigned socket_id, unsigned int size);
74
75 /**
76  * Initializes given reorder buffer instance
77  *
78  * @param b
79  *   Reorder buffer instance to initialize
80  * @param bufsize
81  *   Size of the reorder buffer
82  * @param name
83  *   The name to be given to the reorder buffer
84  * @param size
85  *   Number of elements that can be stored in reorder buffer
86  * @return
87  *   The initialized reorder buffer instance, or NULL on error
88  *   On error case, rte_errno will be set appropriately:
89  *    - EINVAL - invalid parameters
90  */
91 struct rte_reorder_buffer *
92 rte_reorder_init(struct rte_reorder_buffer *b, unsigned int bufsize,
93                 const char *name, unsigned int size);
94
95 /**
96  * Find an existing reorder buffer instance
97  * and return a pointer to it.
98  *
99  * @param name
100  *   Name of the reorder buffer instacne as passed to rte_reorder_create()
101  * @return
102  *   Pointer to reorder buffer instance or NULL if object not found with rte_errno
103  *   set appropriately. Possible rte_errno values include:
104  *    - ENOENT - required entry not available to return.
105  *    reorder instance list
106  */
107 struct rte_reorder_buffer *
108 rte_reorder_find_existing(const char *name);
109
110 /**
111  * Reset the given reorder buffer instance with initial values.
112  *
113  * @param b
114  *   Reorder buffer instance which has to be reset
115  */
116 void
117 rte_reorder_reset(struct rte_reorder_buffer *b);
118
119 /**
120  * Free reorder buffer instance.
121  *
122  * @param b
123  *   reorder buffer instance
124  * @return
125  *   None
126  */
127 void
128 rte_reorder_free(struct rte_reorder_buffer *b);
129
130 /**
131  * Insert given mbuf in reorder buffer in its correct position
132  *
133  * The given mbuf is to be reordered relative to other mbufs in the system.
134  * The mbuf must contain a sequence number which is then used to place
135  * the buffer in the correct position in the reorder buffer. Reordered
136  * packets can later be taken from the buffer using the rte_reorder_drain()
137  * API.
138  *
139  * @param b
140  *   Reorder buffer where the mbuf has to be inserted.
141  * @param mbuf
142  *   mbuf of packet that needs to be inserted in reorder buffer.
143  * @return
144  *   0 on success
145  *   -1 on error
146  *   On error case, rte_errno will be set appropriately:
147  *    - ENOSPC - Cannot move existing mbufs from reorder buffer to accommodate
148  *      ealry mbuf, but it can be accomodated by performing drain and then insert.
149  *    - ERANGE - Too early or late mbuf which is vastly out of range of expected
150  *      window should be ingnored without any handling.
151  */
152 int
153 rte_reorder_insert(struct rte_reorder_buffer *b, struct rte_mbuf *mbuf);
154
155 /**
156  * Fetch reordered buffers
157  *
158  * Returns a set of in-order buffers from the reorder buffer structure. Gaps
159  * may be present in the sequence numbers of the mbuf if packets have been
160  * delayed too long before reaching the reorder window, or have been previously
161  * dropped by the system.
162  *
163  * @param b
164  *   Reorder buffer instance from which packets are to be drained
165  * @param mbufs
166  *   array of mbufs where reordered packets will be inserted from reorder buffer
167  * @param max_mbufs
168  *   the number of elements in the mbufs array.
169  * @return
170  *   number of mbuf pointers written to mbufs. 0 <= N < max_mbufs.
171  */
172 unsigned int
173 rte_reorder_drain(struct rte_reorder_buffer *b, struct rte_mbuf **mbufs,
174                 unsigned max_mbufs);
175
176 #ifdef __cplusplus
177 }
178 #endif
179
180 #endif /* _RTE_REORDER_H_ */