1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2015 6WIND S.A.
3 * Copyright 2015 Mellanox Technologies, Ltd
6 #ifndef RTE_PMD_MLX5_UTILS_H_
7 #define RTE_PMD_MLX5_UTILS_H_
15 #include <rte_spinlock.h>
16 #include <rte_rwlock.h>
17 #include <rte_memory.h>
18 #include <rte_bitmap.h>
20 #include <mlx5_common.h>
22 #include "mlx5_defs.h"
24 #define mlx5_hlist_remove(h, e) \
25 mlx5_hlist_unregister(h, e)
27 #define mlx5_hlist_insert(h, e) \
28 mlx5_hlist_register(h, 0, e)
30 /* Convert a bit number to the corresponding 64-bit mask */
31 #define MLX5_BITSHIFT(v) (UINT64_C(1) << (v))
33 /* Save and restore errno around argument evaluation. */
34 #define ERRNO_SAFE(x) ((errno = (int []){ errno, ((x), 0) }[0]))
36 extern int mlx5_logtype;
38 /* Generic printf()-like logging macro with automatic line feed. */
39 #define DRV_LOG(level, ...) \
40 PMD_DRV_LOG_(level, mlx5_logtype, MLX5_DRIVER_NAME, \
41 __VA_ARGS__ PMD_DRV_LOG_STRIP PMD_DRV_LOG_OPAREN, \
44 /* Convenience macros for accessing mbuf fields. */
45 #define NEXT(m) ((m)->next)
46 #define DATA_LEN(m) ((m)->data_len)
47 #define PKT_LEN(m) ((m)->pkt_len)
48 #define DATA_OFF(m) ((m)->data_off)
49 #define SET_DATA_OFF(m, o) ((m)->data_off = (o))
50 #define NB_SEGS(m) ((m)->nb_segs)
51 #define PORT(m) ((m)->port)
53 /* Transpose flags. Useful to convert IBV to DPDK flags. */
54 #define TRANSPOSE(val, from, to) \
56 (((val) & (from)) / ((from) / (to))) : \
57 (((val) & (from)) * ((to) / (from))))
60 * For the case which data is linked with sequence increased index, the
61 * array table will be more efficiect than hash table once need to serarch
62 * one data entry in large numbers of entries. Since the traditional hash
63 * tables has fixed table size, when huge numbers of data saved to the hash
64 * table, it also comes lots of hash conflict.
66 * But simple array table also has fixed size, allocates all the needed
67 * memory at once will waste lots of memory. For the case don't know the
68 * exactly number of entries will be impossible to allocate the array.
70 * Then the multiple level table helps to balance the two disadvantages.
71 * Allocate a global high level table with sub table entries at first,
72 * the global table contains the sub table entries, and the sub table will
73 * be allocated only once the corresponding index entry need to be saved.
74 * e.g. for up to 32-bits index, three level table with 10-10-12 splitting,
75 * with sequence increased index, the memory grows with every 4K entries.
77 * The currently implementation introduces 10-10-12 32-bits splitting
78 * Three-Level table to help the cases which have millions of enties to
79 * save. The index entries can be addressed directly by the index, no
80 * search will be needed.q
83 /* L3 table global table define. */
84 #define MLX5_L3T_GT_OFFSET 22
85 #define MLX5_L3T_GT_SIZE (1 << 10)
86 #define MLX5_L3T_GT_MASK (MLX5_L3T_GT_SIZE - 1)
88 /* L3 table middle table define. */
89 #define MLX5_L3T_MT_OFFSET 12
90 #define MLX5_L3T_MT_SIZE (1 << 10)
91 #define MLX5_L3T_MT_MASK (MLX5_L3T_MT_SIZE - 1)
93 /* L3 table entry table define. */
94 #define MLX5_L3T_ET_OFFSET 0
95 #define MLX5_L3T_ET_SIZE (1 << 12)
96 #define MLX5_L3T_ET_MASK (MLX5_L3T_ET_SIZE - 1)
100 MLX5_L3T_TYPE_WORD = 0,
107 struct mlx5_indexed_pool;
109 /* Generic data struct. */
110 union mlx5_l3t_data {
117 /* L3 level table data structure. */
118 struct mlx5_l3t_level_tbl {
119 uint64_t ref_cnt; /* Table ref_cnt. */
120 void *tbl[]; /* Table array. */
123 /* L3 word entry table data structure. */
124 struct mlx5_l3t_entry_word {
125 uint32_t idx; /* Table index. */
126 uint64_t ref_cnt; /* Table ref_cnt. */
130 } entry[MLX5_L3T_ET_SIZE]; /* Entry array */
133 /* L3 double word entry table data structure. */
134 struct mlx5_l3t_entry_dword {
135 uint32_t idx; /* Table index. */
136 uint64_t ref_cnt; /* Table ref_cnt. */
140 } entry[MLX5_L3T_ET_SIZE]; /* Entry array */
143 /* L3 quad word entry table data structure. */
144 struct mlx5_l3t_entry_qword {
145 uint32_t idx; /* Table index. */
146 uint64_t ref_cnt; /* Table ref_cnt. */
150 } entry[MLX5_L3T_ET_SIZE]; /* Entry array */
153 /* L3 pointer entry table data structure. */
154 struct mlx5_l3t_entry_ptr {
155 uint32_t idx; /* Table index. */
156 uint64_t ref_cnt; /* Table ref_cnt. */
160 } entry[MLX5_L3T_ET_SIZE]; /* Entry array */
163 /* L3 table data structure. */
164 struct mlx5_l3t_tbl {
165 enum mlx5_l3t_type type; /* Table type. */
166 struct mlx5_indexed_pool *eip;
167 /* Table index pool handles. */
168 struct mlx5_l3t_level_tbl *tbl; /* Global table index. */
169 rte_spinlock_t sl; /* The table lock. */
172 /** Type of function that is used to handle the data before freeing. */
173 typedef int32_t (*mlx5_l3t_alloc_callback_fn)(void *ctx,
174 union mlx5_l3t_data *data);
177 * The indexed memory entry index is made up of trunk index and offset of
178 * the entry in the trunk. Since the entry index is 32 bits, in case user
179 * prefers to have small trunks, user can change the macro below to a big
180 * number which helps the pool contains more trunks with lots of entries
183 #define TRUNK_IDX_BITS 16
184 #define TRUNK_MAX_IDX ((1 << TRUNK_IDX_BITS) - 1)
185 #define TRUNK_INVALID TRUNK_MAX_IDX
186 #define MLX5_IPOOL_DEFAULT_TRUNK_SIZE (1 << (28 - TRUNK_IDX_BITS))
187 #ifdef RTE_LIBRTE_MLX5_DEBUG
191 struct mlx5_indexed_pool_config {
192 uint32_t size; /* Pool entry size. */
193 uint32_t trunk_size:22;
195 * Trunk entry number. Must be power of 2. It can be increased
196 * if trunk_grow enable. The trunk entry number increases with
197 * left shift grow_shift. Trunks with index are after grow_trunk
198 * will keep the entry number same with the last grow trunk.
200 uint32_t grow_trunk:4;
202 * Trunks with entry number increase in the pool. Set it to 0
203 * to make the pool works as trunk entry fixed pool. It works
204 * only if grow_shift is not 0.
206 uint32_t grow_shift:4;
208 * Trunk entry number increase shift value, stop after grow_trunk.
209 * It works only if grow_trunk is not 0.
211 uint32_t need_lock:1;
212 /* Lock is needed for multiple thread usage. */
213 uint32_t release_mem_en:1; /* Rlease trunk when it is free. */
214 const char *type; /* Memory allocate type name. */
215 void *(*malloc)(uint32_t flags, size_t size, unsigned int align,
217 /* User defined memory allocator. */
218 void (*free)(void *addr); /* User defined memory release. */
221 struct mlx5_indexed_trunk {
222 uint32_t idx; /* Trunk id. */
223 uint32_t prev; /* Previous free trunk in free list. */
224 uint32_t next; /* Next free trunk in free list. */
225 uint32_t free; /* Free entries available */
226 struct rte_bitmap *bmp;
227 uint8_t data[] __rte_cache_aligned; /* Entry data start. */
230 struct mlx5_indexed_pool {
231 struct mlx5_indexed_pool_config cfg; /* Indexed pool configuration. */
232 rte_spinlock_t lock; /* Pool lock for multiple thread usage. */
233 uint32_t n_trunk_valid; /* Trunks allocated. */
234 uint32_t n_trunk; /* Trunk pointer array size. */
235 /* Dim of trunk pointer array. */
236 struct mlx5_indexed_trunk **trunks;
237 uint32_t free_list; /* Index to first free trunk. */
241 uint32_t trunk_avail;
242 uint32_t trunk_empty;
245 uint32_t grow_tbl[]; /* Save the index offset for the grow trunks. */
249 * Return logarithm of the nearest power of two above input value.
255 * Logarithm of the nearest power of two above input value.
257 static inline unsigned int
258 log2above(unsigned int v)
263 for (l = 0, r = 0; (v >> 1); ++l, v >>= 1)
268 #define MLX5_HLIST_DIRECT_KEY 0x0001 /* Use the key directly as hash index. */
269 #define MLX5_HLIST_WRITE_MOST 0x0002 /* List mostly used for append new. */
271 /** Maximum size of string for naming the hlist table. */
272 #define MLX5_HLIST_NAMESIZE 32
277 * Structure of the entry in the hash list, user should define its own struct
278 * that contains this in order to store the data. The 'key' is 64-bits right
279 * now and its user's responsibility to guarantee there is no collision.
281 struct mlx5_hlist_entry {
282 LIST_ENTRY(mlx5_hlist_entry) next; /* entry pointers in the list. */
283 uint64_t key; /* user defined 'key', could be the hash signature. */
284 uint32_t ref_cnt; /* Reference count. */
287 /** Structure for hash head. */
288 LIST_HEAD(mlx5_hlist_head, mlx5_hlist_entry);
290 /** Type of function that is used to handle the data before freeing. */
291 typedef void (*mlx5_hlist_destroy_callback_fn)(void *p, void *ctx);
294 * Type of function for user defined matching.
297 * The entry in the list.
299 * The pointer to new entry context.
302 * 0 if matching, -1 otherwise.
304 typedef int (*mlx5_hlist_match_callback_fn)(struct mlx5_hlist_entry *entry,
308 * Type of callback function for entry removal.
313 * The entry in the list.
315 typedef void (*mlx5_hlist_remove_cb)(struct mlx5_hlist *list,
316 struct mlx5_hlist_entry *entry);
319 * Type of function for user defined matching.
324 * The entry in the list.
328 * The pointer to new entry context.
331 * 0 if matching, non-zero number otherwise.
333 typedef int (*mlx5_hlist_match_cb)(struct mlx5_hlist *list,
334 struct mlx5_hlist_entry *entry,
335 uint64_t key, void *ctx);
338 * Type of function for user defined hash list entry creation.
343 * The key of the new entry.
345 * The pointer to new entry context.
348 * Pointer to allocated entry on success, NULL otherwise.
350 typedef struct mlx5_hlist_entry *(*mlx5_hlist_create_cb)
351 (struct mlx5_hlist *list,
352 uint64_t key, void *ctx);
355 * Hash list table structure
357 * Entry in hash list could be reused if entry already exists, reference
358 * count will increase and the existing entry returns.
360 * When destroy an entry from list, decrease reference count and only
361 * destroy when no further reference.
364 char name[MLX5_HLIST_NAMESIZE]; /**< Name of the hash list. */
365 /**< number of heads, need to be power of 2. */
367 uint32_t entry_sz; /**< Size of entry, used to allocate entry. */
368 /**< mask to get the index of the list heads. */
371 uint32_t gen_cnt; /* List modification will update generation count. */
372 bool direct_key; /* Use the new entry key directly as hash index. */
373 bool write_most; /* List mostly used for append new or destroy. */
375 mlx5_hlist_create_cb cb_create; /**< entry create callback. */
376 mlx5_hlist_match_cb cb_match; /**< entry match callback. */
377 mlx5_hlist_remove_cb cb_remove; /**< entry remove callback. */
378 struct mlx5_hlist_head heads[]; /**< list head arrays. */
382 * Create a hash list table, the user can specify the list heads array size
383 * of the table, now the size should be a power of 2 in order to get better
384 * distribution for the entries. Each entry is a part of the whole data element
385 * and the caller should be responsible for the data element's allocation and
386 * cleanup / free. Key of each entry will be calculated with CRC in order to
387 * generate a little fairer distribution.
390 * Name of the hash list(optional).
392 * Heads array size of the hash list.
394 * Entry size to allocate if cb_create not specified.
396 * The hash list attribute flags.
398 * Callback function for entry create.
400 * Callback function for entry match.
402 * Callback function for entry destroy.
404 * Pointer of the hash list table created, NULL on failure.
406 struct mlx5_hlist *mlx5_hlist_create(const char *name, uint32_t size,
407 uint32_t entry_size, uint32_t flags,
408 mlx5_hlist_create_cb cb_create,
409 mlx5_hlist_match_cb cb_match,
410 mlx5_hlist_remove_cb cb_destroy);
413 * Search an entry matching the key.
415 * Result returned might be destroyed by other thread, must use
416 * this function only in main thread.
419 * Pointer to the hast list table.
421 * Key for the searching entry.
423 * Common context parameter used by entry callback function.
426 * Pointer of the hlist entry if found, NULL otherwise.
428 struct mlx5_hlist_entry *mlx5_hlist_lookup(struct mlx5_hlist *h, uint64_t key,
432 * Extended routine to search an entry matching the context with
433 * user defined match function.
436 * Pointer to the hast list table.
438 * Key for the searching entry.
440 * Callback function to match the node with context.
442 * Common context parameter used by callback function.
445 * Pointer of the hlist entry if found, NULL otherwise.
447 struct mlx5_hlist_entry *mlx5_hlist_lookup_ex(struct mlx5_hlist *h,
449 mlx5_hlist_match_callback_fn cb,
453 * Extended routine to insert an entry to the list with key collisions.
455 * For the list have key collision, the extra user defined match function
456 * allows node with same key will be inserted.
459 * Pointer to the hast list table.
461 * Entry to be inserted into the hash list table.
463 * Callback function to match the node with context.
465 * Common context parameter used by callback function.
468 * - zero for success.
469 * - -EEXIST if the entry is already inserted.
471 int mlx5_hlist_insert_ex(struct mlx5_hlist *h, struct mlx5_hlist_entry *entry,
472 mlx5_hlist_match_callback_fn cb, void *ctx);
475 * Insert an entry to the hash list table, the entry is only part of whole data
476 * element and a 64B key is used for matching. User should construct the key or
477 * give a calculated hash signature and guarantee there is no collision.
480 * Pointer to the hast list table.
482 * Entry to be inserted into the hash list table.
484 * Common context parameter used by callback function.
487 * registered entry on success, NULL otherwise
489 struct mlx5_hlist_entry *mlx5_hlist_register(struct mlx5_hlist *h, uint64_t key,
493 * Remove an entry from the hash list table. User should guarantee the validity
497 * Pointer to the hast list table. (not used)
499 * Entry to be removed from the hash list table.
501 * 0 on entry removed, 1 on entry still referenced.
503 int mlx5_hlist_unregister(struct mlx5_hlist *h, struct mlx5_hlist_entry *entry);
506 * Destroy the hash list table, all the entries already inserted into the lists
507 * will be handled by the callback function provided by the user (including
508 * free if needed) before the table is freed.
511 * Pointer to the hast list table.
513 void mlx5_hlist_destroy(struct mlx5_hlist *h);
515 /************************ cache list *****************************/
517 /** Maximum size of string for naming. */
518 #define MLX5_NAME_SIZE 32
520 struct mlx5_cache_list;
523 * Structure of the entry in the cache list, user should define its own struct
524 * that contains this in order to store the data.
526 struct mlx5_cache_entry {
527 LIST_ENTRY(mlx5_cache_entry) next; /* Entry pointers in the list. */
528 uint32_t ref_cnt; /* Reference count. */
532 * Type of callback function for entry removal.
537 * The entry in the list.
539 typedef void (*mlx5_cache_remove_cb)(struct mlx5_cache_list *list,
540 struct mlx5_cache_entry *entry);
543 * Type of function for user defined matching.
548 * The entry in the list.
550 * The pointer to new entry context.
553 * 0 if matching, non-zero number otherwise.
555 typedef int (*mlx5_cache_match_cb)(struct mlx5_cache_list *list,
556 struct mlx5_cache_entry *entry, void *ctx);
559 * Type of function for user defined cache list entry creation.
564 * The new allocated entry, NULL if list entry size unspecified,
565 * New entry has to be allocated in callback and return.
567 * The pointer to new entry context.
570 * Pointer of entry on success, NULL otherwise.
572 typedef struct mlx5_cache_entry *(*mlx5_cache_create_cb)
573 (struct mlx5_cache_list *list,
574 struct mlx5_cache_entry *entry,
578 * Linked cache list structure.
580 * Entry in cache list could be reused if entry already exists,
581 * reference count will increase and the existing entry returns.
583 * When destroy an entry from list, decrease reference count and only
584 * destroy when no further reference.
586 * Linked list cache is designed for limited number of entries cache,
587 * read mostly, less modification.
589 * For huge amount of entries cache, please consider hash list cache.
592 struct mlx5_cache_list {
593 char name[MLX5_NAME_SIZE]; /**< Name of the cache list. */
594 uint32_t entry_sz; /**< Entry size, 0: use create callback. */
595 rte_rwlock_t lock; /* read/write lock. */
596 uint32_t gen_cnt; /* List modification will update generation count. */
597 uint32_t count; /* number of entries in list. */
598 void *ctx; /* user objects target to callback. */
599 mlx5_cache_create_cb cb_create; /**< entry create callback. */
600 mlx5_cache_match_cb cb_match; /**< entry match callback. */
601 mlx5_cache_remove_cb cb_remove; /**< entry remove callback. */
602 LIST_HEAD(mlx5_cache_head, mlx5_cache_entry) head;
606 * Initialize a cache list.
609 * Pointer to the hast list table.
611 * Name of the cache list.
613 * Entry size to allocate, 0 to allocate by creation callback.
615 * Pointer to the list context data.
617 * Callback function for entry create.
619 * Callback function for entry match.
621 * Callback function for entry remove.
623 * 0 on success, otherwise failure.
625 int mlx5_cache_list_init(struct mlx5_cache_list *list,
626 const char *name, uint32_t entry_size, void *ctx,
627 mlx5_cache_create_cb cb_create,
628 mlx5_cache_match_cb cb_match,
629 mlx5_cache_remove_cb cb_remove);
632 * Search an entry matching the key.
634 * Result returned might be destroyed by other thread, must use
635 * this function only in main thread.
638 * Pointer to the cache list.
640 * Common context parameter used by entry callback function.
643 * Pointer of the cache entry if found, NULL otherwise.
645 struct mlx5_cache_entry *mlx5_cache_lookup(struct mlx5_cache_list *list,
649 * Reuse or create an entry to the cache list.
652 * Pointer to the hast list table.
654 * Common context parameter used by callback function.
657 * registered entry on success, NULL otherwise
659 struct mlx5_cache_entry *mlx5_cache_register(struct mlx5_cache_list *list,
663 * Remove an entry from the cache list.
665 * User should guarantee the validity of the entry.
668 * Pointer to the hast list.
670 * Entry to be removed from the cache list table.
672 * 0 on entry removed, 1 on entry still referenced.
674 int mlx5_cache_unregister(struct mlx5_cache_list *list,
675 struct mlx5_cache_entry *entry);
678 * Destroy the cache list.
681 * Pointer to the cache list.
683 void mlx5_cache_list_destroy(struct mlx5_cache_list *list);
686 * Get entry number from the cache list.
689 * Pointer to the hast list.
691 * Cache list entry number.
694 mlx5_cache_list_get_entry_num(struct mlx5_cache_list *list);
696 /********************************* indexed pool *************************/
699 * This function allocates non-initialized memory entry from pool.
700 * In NUMA systems, the memory entry allocated resides on the same
701 * NUMA socket as the core that calls this function.
703 * Memory entry is allocated from memory trunk, no alignment.
706 * Pointer to indexed memory entry pool.
707 * No initialization required.
709 * Pointer to memory to save allocated index.
710 * Memory index always positive value.
712 * - Pointer to the allocated memory entry.
713 * - NULL on error. Not enough memory, or invalid arguments.
715 void *mlx5_ipool_malloc(struct mlx5_indexed_pool *pool, uint32_t *idx);
718 * This function allocates zero initialized memory entry from pool.
719 * In NUMA systems, the memory entry allocated resides on the same
720 * NUMA socket as the core that calls this function.
722 * Memory entry is allocated from memory trunk, no alignment.
725 * Pointer to indexed memory pool.
726 * No initialization required.
728 * Pointer to memory to save allocated index.
729 * Memory index always positive value.
731 * - Pointer to the allocated memory entry .
732 * - NULL on error. Not enough memory, or invalid arguments.
734 void *mlx5_ipool_zmalloc(struct mlx5_indexed_pool *pool, uint32_t *idx);
737 * This function frees indexed memory entry to pool.
738 * Caller has to make sure that the index is allocated from same pool.
741 * Pointer to indexed memory pool.
743 * Allocated memory entry index.
745 void mlx5_ipool_free(struct mlx5_indexed_pool *pool, uint32_t idx);
748 * This function returns pointer of indexed memory entry from index.
749 * Caller has to make sure that the index is valid, and allocated
753 * Pointer to indexed memory pool.
755 * Allocated memory index.
757 * - Pointer to indexed memory entry.
759 void *mlx5_ipool_get(struct mlx5_indexed_pool *pool, uint32_t idx);
762 * This function creates indexed memory pool.
763 * Caller has to configure the configuration accordingly.
766 * Pointer to indexed memory pool.
768 * Allocated memory index.
770 struct mlx5_indexed_pool *
771 mlx5_ipool_create(struct mlx5_indexed_pool_config *cfg);
774 * This function releases all resources of pool.
775 * Caller has to make sure that all indexes and memories allocated
776 * from this pool not referenced anymore.
779 * Pointer to indexed memory pool.
781 * - non-zero value on error.
784 int mlx5_ipool_destroy(struct mlx5_indexed_pool *pool);
787 * This function dumps debug info of pool.
790 * Pointer to indexed memory pool.
792 void mlx5_ipool_dump(struct mlx5_indexed_pool *pool);
795 * This function allocates new empty Three-level table.
798 * The l3t can set as word, double word, quad word or pointer with index.
801 * - Pointer to the allocated l3t.
802 * - NULL on error. Not enough memory, or invalid arguments.
804 struct mlx5_l3t_tbl *mlx5_l3t_create(enum mlx5_l3t_type type);
807 * This function destroys Three-level table.
810 * Pointer to the l3t.
812 void mlx5_l3t_destroy(struct mlx5_l3t_tbl *tbl);
815 * This function gets the index entry from Three-level table.
818 * Pointer to the l3t.
820 * Index to the entry.
822 * Pointer to the memory which saves the entry data.
823 * When function call returns 0, data contains the entry data get from
825 * When function call returns -1, data is not modified.
828 * 0 if success, -1 on error.
831 int32_t mlx5_l3t_get_entry(struct mlx5_l3t_tbl *tbl, uint32_t idx,
832 union mlx5_l3t_data *data);
835 * This function gets the index entry from Three-level table.
837 * If the index entry is not available, allocate new one by callback
838 * function and fill in the entry.
841 * Pointer to the l3t.
843 * Index to the entry.
845 * Pointer to the memory which saves the entry data.
846 * When function call returns 0, data contains the entry data get from
848 * When function call returns -1, data is not modified.
850 * Callback function to allocate new data.
852 * Context for callback function.
855 * 0 if success, -1 on error.
858 int32_t mlx5_l3t_prepare_entry(struct mlx5_l3t_tbl *tbl, uint32_t idx,
859 union mlx5_l3t_data *data,
860 mlx5_l3t_alloc_callback_fn cb, void *ctx);
863 * This function decreases and clear index entry if reference
864 * counter is 0 from Three-level table.
867 * Pointer to the l3t.
869 * Index to the entry.
872 * The remaining reference count, 0 means entry be cleared, -1 on error.
874 int32_t mlx5_l3t_clear_entry(struct mlx5_l3t_tbl *tbl, uint32_t idx);
877 * This function sets the index entry to Three-level table.
878 * If the entry is already set, the EEXIST errno will be given, and
879 * the set data will be filled to the data.
882 * Pointer to the l3t.
884 * Index to the entry.
885 * @param data[in/out]
886 * Pointer to the memory which contains the entry data save to l3t.
887 * If the entry is already set, the set data will be filled.
890 * 0 if success, -1 on error.
892 int32_t mlx5_l3t_set_entry(struct mlx5_l3t_tbl *tbl, uint32_t idx,
893 union mlx5_l3t_data *data);
896 * Macros for linked list based on indexed memory.
897 * Example data structure:
899 * ILIST_ENTRY(uint16_t) next;
904 #define ILIST_ENTRY(type) \
906 type prev; /* Index of previous element. */ \
907 type next; /* Index of next element. */ \
910 #define ILIST_INSERT(pool, head, idx, elem, field) \
913 MLX5_ASSERT((elem) && (idx)); \
914 (elem)->field.next = *(head); \
915 (elem)->field.prev = 0; \
917 (peer) = mlx5_ipool_get(pool, *(head)); \
919 (peer)->field.prev = (idx); \
924 #define ILIST_REMOVE(pool, head, idx, elem, field) \
929 if ((elem)->field.prev) { \
930 (peer) = mlx5_ipool_get \
931 (pool, (elem)->field.prev); \
933 (peer)->field.next = (elem)->field.next;\
935 if ((elem)->field.next) { \
936 (peer) = mlx5_ipool_get \
937 (pool, (elem)->field.next); \
939 (peer)->field.prev = (elem)->field.prev;\
941 if (*(head) == (idx)) \
942 *(head) = (elem)->field.next; \
945 #define ILIST_FOREACH(pool, head, idx, elem, field) \
946 for ((idx) = (head), (elem) = \
947 (idx) ? mlx5_ipool_get(pool, (idx)) : NULL; (elem); \
948 idx = (elem)->field.next, (elem) = \
949 (idx) ? mlx5_ipool_get(pool, idx) : NULL)
951 /* Single index list. */
952 #define SILIST_ENTRY(type) \
954 type next; /* Index of next element. */ \
957 #define SILIST_INSERT(head, idx, elem, field) \
959 MLX5_ASSERT((elem) && (idx)); \
960 (elem)->field.next = *(head); \
964 #define SILIST_FOREACH(pool, head, idx, elem, field) \
965 for ((idx) = (head), (elem) = \
966 (idx) ? mlx5_ipool_get(pool, (idx)) : NULL; (elem); \
967 idx = (elem)->field.next, (elem) = \
968 (idx) ? mlx5_ipool_get(pool, idx) : NULL)
970 #endif /* RTE_PMD_MLX5_UTILS_H_ */