1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
5 #ifndef _RTE_REORDER_H_
6 #define _RTE_REORDER_H_
12 * Reorder library is a component which is designed to
13 * provide ordering of out of ordered packets based on
14 * sequence number present in mbuf.
19 #include <rte_mbuf_dyn.h>
25 struct rte_reorder_buffer;
27 typedef uint32_t rte_reorder_seqn_t;
28 extern int rte_reorder_seqn_dynfield_offset;
32 * @b EXPERIMENTAL: this API may change without prior notice
34 * Read reorder sequence number from mbuf.
36 * @param mbuf Structure to read from.
37 * @return pointer to reorder sequence number.
40 static inline rte_reorder_seqn_t *
41 rte_reorder_seqn(struct rte_mbuf *mbuf)
43 return RTE_MBUF_DYNFIELD(mbuf, rte_reorder_seqn_dynfield_offset,
44 rte_reorder_seqn_t *);
48 * Create a new reorder buffer instance
50 * Allocate memory and initialize a new reorder buffer in that
51 * memory, returning the reorder buffer pointer to the user
54 * The name to be given to the reorder buffer instance.
56 * The NUMA node on which the memory for the reorder buffer
57 * instance is to be reserved.
59 * Max number of elements that can be stored in the reorder buffer
61 * The initialized reorder buffer instance, or NULL on error
62 * On error case, rte_errno will be set appropriately:
63 * - ENOMEM - no appropriate memory area found in which to create memzone
64 * - EINVAL - invalid parameters
66 struct rte_reorder_buffer *
67 rte_reorder_create(const char *name, unsigned socket_id, unsigned int size);
70 * Initializes given reorder buffer instance
73 * Reorder buffer instance to initialize
75 * Size of the reorder buffer
77 * The name to be given to the reorder buffer
79 * Number of elements that can be stored in reorder buffer
81 * The initialized reorder buffer instance, or NULL on error
82 * On error case, rte_errno will be set appropriately:
83 * - EINVAL - invalid parameters
85 struct rte_reorder_buffer *
86 rte_reorder_init(struct rte_reorder_buffer *b, unsigned int bufsize,
87 const char *name, unsigned int size);
90 * Find an existing reorder buffer instance
91 * and return a pointer to it.
94 * Name of the reorder buffer instance as passed to rte_reorder_create()
96 * Pointer to reorder buffer instance or NULL if object not found with rte_errno
97 * set appropriately. Possible rte_errno values include:
98 * - ENOENT - required entry not available to return.
99 * reorder instance list
101 struct rte_reorder_buffer *
102 rte_reorder_find_existing(const char *name);
105 * Reset the given reorder buffer instance with initial values.
108 * Reorder buffer instance which has to be reset
111 rte_reorder_reset(struct rte_reorder_buffer *b);
114 * Free reorder buffer instance.
117 * reorder buffer instance
122 rte_reorder_free(struct rte_reorder_buffer *b);
125 * Insert given mbuf in reorder buffer in its correct position
127 * The given mbuf is to be reordered relative to other mbufs in the system.
128 * The mbuf must contain a sequence number which is then used to place
129 * the buffer in the correct position in the reorder buffer. Reordered
130 * packets can later be taken from the buffer using the rte_reorder_drain()
134 * Reorder buffer where the mbuf has to be inserted.
136 * mbuf of packet that needs to be inserted in reorder buffer.
140 * On error case, rte_errno will be set appropriately:
141 * - ENOSPC - Cannot move existing mbufs from reorder buffer to accommodate
142 * early mbuf, but it can be accommodated by performing drain and then insert.
143 * - ERANGE - Too early or late mbuf which is vastly out of range of expected
144 * window should be ignored without any handling.
147 rte_reorder_insert(struct rte_reorder_buffer *b, struct rte_mbuf *mbuf);
150 * Fetch reordered buffers
152 * Returns a set of in-order buffers from the reorder buffer structure. Gaps
153 * may be present in the sequence numbers of the mbuf if packets have been
154 * delayed too long before reaching the reorder window, or have been previously
155 * dropped by the system.
158 * Reorder buffer instance from which packets are to be drained
160 * array of mbufs where reordered packets will be inserted from reorder buffer
162 * the number of elements in the mbufs array.
164 * number of mbuf pointers written to mbufs. 0 <= N < max_mbufs.
167 rte_reorder_drain(struct rte_reorder_buffer *b, struct rte_mbuf **mbufs,
174 #endif /* _RTE_REORDER_H_ */