Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2010-2014 Intel Corporation 3 : : */ 4 : : 5 : : #ifndef _RTE_REORDER_H_ 6 : : #define _RTE_REORDER_H_ 7 : : 8 : : /** 9 : : * @file 10 : : * RTE reorder 11 : : * 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. 15 : : */ 16 : : 17 : : #include <rte_common.h> 18 : : #include <rte_compat.h> 19 : : #include <rte_mbuf.h> 20 : : #include <rte_mbuf_dyn.h> 21 : : 22 : : #ifdef __cplusplus 23 : : extern "C" { 24 : : #endif 25 : : 26 : : struct rte_reorder_buffer; 27 : : 28 : : typedef uint32_t rte_reorder_seqn_t; 29 : : extern int rte_reorder_seqn_dynfield_offset; 30 : : 31 : : /** 32 : : * @warning 33 : : * @b EXPERIMENTAL: this API may change without prior notice 34 : : * 35 : : * Read reorder sequence number from mbuf. 36 : : * 37 : : * @param mbuf Structure to read from. 38 : : * @return pointer to reorder sequence number. 39 : : */ 40 : : __rte_experimental 41 : : static inline rte_reorder_seqn_t * 42 : : rte_reorder_seqn(struct rte_mbuf *mbuf) 43 : : { 44 [ - - + + : 54 : return RTE_MBUF_DYNFIELD(mbuf, rte_reorder_seqn_dynfield_offset, - - ] 45 : : rte_reorder_seqn_t *); 46 : : } 47 : : 48 : : /** 49 : : * Free reorder buffer instance. 50 : : * 51 : : * @param b 52 : : * Pointer to reorder buffer instance. 53 : : * If b is NULL, no operation is performed. 54 : : */ 55 : : void 56 : : rte_reorder_free(struct rte_reorder_buffer *b); 57 : : 58 : : /** 59 : : * Create a new reorder buffer instance 60 : : * 61 : : * Allocate memory and initialize a new reorder buffer in that 62 : : * memory, returning the reorder buffer pointer to the user 63 : : * 64 : : * @param name 65 : : * The name to be given to the reorder buffer instance. 66 : : * @param socket_id 67 : : * The NUMA node on which the memory for the reorder buffer 68 : : * instance is to be reserved. 69 : : * @param size 70 : : * Max number of elements that can be stored in the reorder buffer 71 : : * @return 72 : : * The initialized reorder buffer instance, or NULL on error 73 : : * On error case, rte_errno will be set appropriately: 74 : : * - ENOMEM - no appropriate memory area found in which to create memzone 75 : : * - EINVAL - invalid parameters 76 : : */ 77 : : struct rte_reorder_buffer * 78 : : rte_reorder_create(const char *name, unsigned int socket_id, unsigned int size) 79 : : __rte_malloc __rte_dealloc(rte_reorder_free, 1); 80 : : 81 : : /** 82 : : * Initializes given reorder buffer instance 83 : : * 84 : : * @param b 85 : : * Reorder buffer instance to initialize 86 : : * @param bufsize 87 : : * Size of the reorder buffer 88 : : * @param name 89 : : * The name to be given to the reorder buffer 90 : : * @param size 91 : : * Number of elements that can be stored in reorder buffer 92 : : * @return 93 : : * The initialized reorder buffer instance, or NULL on error 94 : : * On error case, rte_errno will be set appropriately: 95 : : * - EINVAL - invalid parameters 96 : : * - ENOMEM - not enough memory to register dynamic field 97 : : */ 98 : : struct rte_reorder_buffer * 99 : : rte_reorder_init(struct rte_reorder_buffer *b, unsigned int bufsize, 100 : : const char *name, unsigned int size); 101 : : 102 : : /** 103 : : * Find an existing reorder buffer instance 104 : : * and return a pointer to it. 105 : : * 106 : : * @param name 107 : : * Name of the reorder buffer instance as passed to rte_reorder_create() 108 : : * @return 109 : : * Pointer to reorder buffer instance or NULL if object not found with rte_errno 110 : : * set appropriately. Possible rte_errno values include: 111 : : * - ENOENT - required entry not available to return. 112 : : * reorder instance list 113 : : */ 114 : : struct rte_reorder_buffer * 115 : : rte_reorder_find_existing(const char *name); 116 : : 117 : : /** 118 : : * Reset the given reorder buffer instance with initial values. 119 : : * 120 : : * @param b 121 : : * Reorder buffer instance which has to be reset 122 : : */ 123 : : void 124 : : rte_reorder_reset(struct rte_reorder_buffer *b); 125 : : 126 : : /** 127 : : * Insert given mbuf in reorder buffer in its correct position 128 : : * 129 : : * The given mbuf is to be reordered relative to other mbufs in the system. 130 : : * The mbuf must contain a sequence number which is then used to place 131 : : * the buffer in the correct position in the reorder buffer. Reordered 132 : : * packets can later be taken from the buffer using the rte_reorder_drain() 133 : : * API. 134 : : * 135 : : * @param b 136 : : * Reorder buffer where the mbuf has to be inserted. 137 : : * @param mbuf 138 : : * mbuf of packet that needs to be inserted in reorder buffer. 139 : : * @return 140 : : * 0 on success 141 : : * -1 on error 142 : : * On error case, rte_errno will be set appropriately: 143 : : * - ENOSPC - Cannot move existing mbufs from reorder buffer to accommodate 144 : : * early mbuf, but it can be accommodated by performing drain and then insert. 145 : : * - ERANGE - Too early or late mbuf which is vastly out of range of expected 146 : : * window should be ignored without any handling. 147 : : */ 148 : : int 149 : : rte_reorder_insert(struct rte_reorder_buffer *b, struct rte_mbuf *mbuf); 150 : : 151 : : /** 152 : : * Fetch reordered buffers 153 : : * 154 : : * Returns a set of in-order buffers from the reorder buffer structure. Gaps 155 : : * may be present in the sequence numbers of the mbuf if packets have been 156 : : * delayed too long before reaching the reorder window, or have been previously 157 : : * dropped by the system. 158 : : * 159 : : * @param b 160 : : * Reorder buffer instance from which packets are to be drained 161 : : * @param mbufs 162 : : * array of mbufs where reordered packets will be inserted from reorder buffer 163 : : * @param max_mbufs 164 : : * the number of elements in the mbufs array. 165 : : * @return 166 : : * number of mbuf pointers written to mbufs. 0 <= N < max_mbufs. 167 : : */ 168 : : unsigned int 169 : : rte_reorder_drain(struct rte_reorder_buffer *b, struct rte_mbuf **mbufs, 170 : : unsigned max_mbufs); 171 : : 172 : : /** 173 : : * @warning 174 : : * @b EXPERIMENTAL: this API may change without prior notice 175 : : * 176 : : * Fetch set of reordered packets up to specified sequence number (exclusive). 177 : : * 178 : : * Returns a set of in-order packets from the reorder buffer structure. 179 : : * Gaps may be present since reorder buffer will try to fetch 180 : : * all possible packets up to given sequence number. 181 : : * 182 : : * @param b 183 : : * Reorder buffer instance from which packets are to be drained. 184 : : * @param mbufs 185 : : * Array of mbufs where reordered packets will be inserted from reorder buffer. 186 : : * @param max_mbufs 187 : : * The number of elements in the mbuf array. 188 : : * @param seqn 189 : : * Sequence number up to which buffer will be drained. 190 : : * @return 191 : : * Number of mbuf pointers written to mbufs. 0 <= N < max_mbufs. 192 : : */ 193 : : __rte_experimental 194 : : unsigned int 195 : : rte_reorder_drain_up_to_seqn(struct rte_reorder_buffer *b, struct rte_mbuf **mbufs, 196 : : unsigned int max_mbufs, rte_reorder_seqn_t seqn); 197 : : 198 : : /** 199 : : * @warning 200 : : * @b EXPERIMENTAL: this API may change without prior notice 201 : : * 202 : : * Set minimum sequence number of packet allowed to be buffered. 203 : : * To successfully set new value, 204 : : * reorder buffer has to be empty (after create, reset or drain_all). 205 : : * 206 : : * @param b 207 : : * Empty reorder buffer instance to modify. 208 : : * @param min_seqn 209 : : * New sequence number to set. 210 : : * @return 211 : : * 0 on success, a negative value otherwise. 212 : : */ 213 : : __rte_experimental 214 : : unsigned int 215 : : rte_reorder_min_seqn_set(struct rte_reorder_buffer *b, rte_reorder_seqn_t min_seqn); 216 : : 217 : : /** 218 : : * @warning 219 : : * @b EXPERIMENTAL: this API may change without prior notice 220 : : * 221 : : * Determine the amount of memory needed by the reorder buffer 222 : : * to accommodate a given number of elements. 223 : : * @see rte_reorder_init() 224 : : * 225 : : * @param size 226 : : * Number of elements that can be stored in reorder buffer. 227 : : * @return 228 : : * Reorder buffer footprint measured in bytes. 229 : : */ 230 : : __rte_experimental 231 : : unsigned int 232 : : rte_reorder_memory_footprint_get(unsigned int size); 233 : : 234 : : #ifdef __cplusplus 235 : : } 236 : : #endif 237 : : 238 : : #endif /* _RTE_REORDER_H_ */