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