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>
21 #include <mlx5_common_utils.h>
23 #include "mlx5_defs.h"
25 /* Convert a bit number to the corresponding 64-bit mask */
26 #define MLX5_BITSHIFT(v) (UINT64_C(1) << (v))
28 /* Save and restore errno around argument evaluation. */
29 #define ERRNO_SAFE(x) ((errno = (int []){ errno, ((x), 0) }[0]))
31 extern int mlx5_logtype;
33 #define MLX5_NET_LOG_PREFIX "mlx5_net"
35 /* Generic printf()-like logging macro with automatic line feed. */
36 #define DRV_LOG(level, ...) \
37 PMD_DRV_LOG_(level, mlx5_logtype, MLX5_NET_LOG_PREFIX, \
38 __VA_ARGS__ PMD_DRV_LOG_STRIP PMD_DRV_LOG_OPAREN, \
41 /* Convenience macros for accessing mbuf fields. */
42 #define NEXT(m) ((m)->next)
43 #define DATA_LEN(m) ((m)->data_len)
44 #define PKT_LEN(m) ((m)->pkt_len)
45 #define DATA_OFF(m) ((m)->data_off)
46 #define SET_DATA_OFF(m, o) ((m)->data_off = (o))
47 #define NB_SEGS(m) ((m)->nb_segs)
48 #define PORT(m) ((m)->port)
50 /* Transpose flags. Useful to convert IBV to DPDK flags. */
51 #define TRANSPOSE(val, from, to) \
53 (((val) & (from)) / ((from) / (to))) : \
54 (((val) & (from)) * ((to) / (from))))
57 * For the case which data is linked with sequence increased index, the
58 * array table will be more efficiect than hash table once need to serarch
59 * one data entry in large numbers of entries. Since the traditional hash
60 * tables has fixed table size, when huge numbers of data saved to the hash
61 * table, it also comes lots of hash conflict.
63 * But simple array table also has fixed size, allocates all the needed
64 * memory at once will waste lots of memory. For the case don't know the
65 * exactly number of entries will be impossible to allocate the array.
67 * Then the multiple level table helps to balance the two disadvantages.
68 * Allocate a global high level table with sub table entries at first,
69 * the global table contains the sub table entries, and the sub table will
70 * be allocated only once the corresponding index entry need to be saved.
71 * e.g. for up to 32-bits index, three level table with 10-10-12 splitting,
72 * with sequence increased index, the memory grows with every 4K entries.
74 * The currently implementation introduces 10-10-12 32-bits splitting
75 * Three-Level table to help the cases which have millions of enties to
76 * save. The index entries can be addressed directly by the index, no
77 * search will be needed.q
80 /* L3 table global table define. */
81 #define MLX5_L3T_GT_OFFSET 22
82 #define MLX5_L3T_GT_SIZE (1 << 10)
83 #define MLX5_L3T_GT_MASK (MLX5_L3T_GT_SIZE - 1)
85 /* L3 table middle table define. */
86 #define MLX5_L3T_MT_OFFSET 12
87 #define MLX5_L3T_MT_SIZE (1 << 10)
88 #define MLX5_L3T_MT_MASK (MLX5_L3T_MT_SIZE - 1)
90 /* L3 table entry table define. */
91 #define MLX5_L3T_ET_OFFSET 0
92 #define MLX5_L3T_ET_SIZE (1 << 12)
93 #define MLX5_L3T_ET_MASK (MLX5_L3T_ET_SIZE - 1)
97 MLX5_L3T_TYPE_WORD = 0,
104 struct mlx5_indexed_pool;
106 /* Generic data struct. */
107 union mlx5_l3t_data {
114 /* L3 level table data structure. */
115 struct mlx5_l3t_level_tbl {
116 uint64_t ref_cnt; /* Table ref_cnt. */
117 void *tbl[]; /* Table array. */
120 /* L3 word entry table data structure. */
121 struct mlx5_l3t_entry_word {
122 uint32_t idx; /* Table index. */
123 uint64_t ref_cnt; /* Table ref_cnt. */
127 } entry[MLX5_L3T_ET_SIZE]; /* Entry array */
130 /* L3 double word entry table data structure. */
131 struct mlx5_l3t_entry_dword {
132 uint32_t idx; /* Table index. */
133 uint64_t ref_cnt; /* Table ref_cnt. */
137 } entry[MLX5_L3T_ET_SIZE]; /* Entry array */
140 /* L3 quad word entry table data structure. */
141 struct mlx5_l3t_entry_qword {
142 uint32_t idx; /* Table index. */
143 uint64_t ref_cnt; /* Table ref_cnt. */
147 } entry[MLX5_L3T_ET_SIZE]; /* Entry array */
150 /* L3 pointer entry table data structure. */
151 struct mlx5_l3t_entry_ptr {
152 uint32_t idx; /* Table index. */
153 uint64_t ref_cnt; /* Table ref_cnt. */
157 } entry[MLX5_L3T_ET_SIZE]; /* Entry array */
160 /* L3 table data structure. */
161 struct mlx5_l3t_tbl {
162 enum mlx5_l3t_type type; /* Table type. */
163 struct mlx5_indexed_pool *eip;
164 /* Table index pool handles. */
165 struct mlx5_l3t_level_tbl *tbl; /* Global table index. */
166 rte_spinlock_t sl; /* The table lock. */
169 /** Type of function that is used to handle the data before freeing. */
170 typedef int32_t (*mlx5_l3t_alloc_callback_fn)(void *ctx,
171 union mlx5_l3t_data *data);
174 * The indexed memory entry index is made up of trunk index and offset of
175 * the entry in the trunk. Since the entry index is 32 bits, in case user
176 * prefers to have small trunks, user can change the macro below to a big
177 * number which helps the pool contains more trunks with lots of entries
180 #define TRUNK_IDX_BITS 16
181 #define TRUNK_MAX_IDX ((1 << TRUNK_IDX_BITS) - 1)
182 #define TRUNK_INVALID TRUNK_MAX_IDX
183 #define MLX5_IPOOL_DEFAULT_TRUNK_SIZE (1 << (28 - TRUNK_IDX_BITS))
184 #ifdef RTE_LIBRTE_MLX5_DEBUG
188 struct mlx5_indexed_pool_config {
189 uint32_t size; /* Pool entry size. */
190 uint32_t trunk_size:22;
192 * Trunk entry number. Must be power of 2. It can be increased
193 * if trunk_grow enable. The trunk entry number increases with
194 * left shift grow_shift. Trunks with index are after grow_trunk
195 * will keep the entry number same with the last grow trunk.
197 uint32_t grow_trunk:4;
199 * Trunks with entry number increase in the pool. Set it to 0
200 * to make the pool works as trunk entry fixed pool. It works
201 * only if grow_shift is not 0.
203 uint32_t grow_shift:4;
205 * Trunk entry number increase shift value, stop after grow_trunk.
206 * It works only if grow_trunk is not 0.
208 uint32_t need_lock:1;
209 /* Lock is needed for multiple thread usage. */
210 uint32_t release_mem_en:1; /* Rlease trunk when it is free. */
211 uint32_t max_idx; /* The maximum index can be allocated. */
212 uint32_t per_core_cache;
214 * Cache entry number per core for performance. Should not be
215 * set with release_mem_en.
217 const char *type; /* Memory allocate type name. */
218 void *(*malloc)(uint32_t flags, size_t size, unsigned int align,
220 /* User defined memory allocator. */
221 void (*free)(void *addr); /* User defined memory release. */
224 struct mlx5_indexed_trunk {
225 uint32_t idx; /* Trunk id. */
226 uint32_t prev; /* Previous free trunk in free list. */
227 uint32_t next; /* Next free trunk in free list. */
228 uint32_t free; /* Free entries available */
229 struct rte_bitmap *bmp;
230 uint8_t data[] __rte_cache_aligned; /* Entry data start. */
233 struct mlx5_indexed_cache {
234 struct mlx5_indexed_trunk **trunks;
235 volatile uint32_t n_trunk_valid; /* Trunks allocated. */
236 uint32_t n_trunk; /* Trunk pointer array size. */
242 struct mlx5_ipool_per_lcore {
243 struct mlx5_indexed_cache *lc;
244 uint32_t len; /**< Current cache count. */
245 uint32_t idx[]; /**< Cache objects. */
248 struct mlx5_indexed_pool {
249 struct mlx5_indexed_pool_config cfg; /* Indexed pool configuration. */
250 rte_spinlock_t rsz_lock; /* Pool lock for multiple thread usage. */
251 rte_spinlock_t lcore_lock;
252 /* Dim of trunk pointer array. */
255 uint32_t n_trunk_valid; /* Trunks allocated. */
256 uint32_t n_trunk; /* Trunk pointer array size. */
257 struct mlx5_indexed_trunk **trunks;
258 uint32_t free_list; /* Index to first free trunk. */
261 struct mlx5_indexed_cache *gc;
263 struct mlx5_ipool_per_lcore *cache[RTE_MAX_LCORE + 1];
265 struct rte_bitmap *ibmp;
267 /* Allocate objects bitmap. Use during flush. */
273 uint32_t trunk_avail;
274 uint32_t trunk_empty;
277 uint32_t grow_tbl[]; /* Save the index offset for the grow trunks. */
281 * Return logarithm of the nearest power of two above input value.
287 * Logarithm of the nearest power of two above input value.
289 static inline unsigned int
290 log2above(unsigned int v)
295 for (l = 0, r = 0; (v >> 1); ++l, v >>= 1)
300 /************************ mlx5 list *****************************/
302 /** Maximum size of string for naming. */
303 #define MLX5_NAME_SIZE 32
308 * Structure of the entry in the mlx5 list, user should define its own struct
309 * that contains this in order to store the data.
311 struct mlx5_list_entry {
312 LIST_ENTRY(mlx5_list_entry) next; /* Entry pointers in the list. */
313 uint32_t ref_cnt; /* 0 means, entry is invalid. */
315 struct mlx5_list_entry *gentry;
318 struct mlx5_list_cache {
319 LIST_HEAD(mlx5_list_head, mlx5_list_entry) h;
320 uint32_t inv_cnt; /* Invalid entries counter. */
321 } __rte_cache_aligned;
324 * Type of callback function for entry removal.
329 * The entry in the list.
331 typedef void (*mlx5_list_remove_cb)(struct mlx5_list *list,
332 struct mlx5_list_entry *entry);
335 * Type of function for user defined matching.
340 * The entry in the list.
342 * The pointer to new entry context.
345 * 0 if matching, non-zero number otherwise.
347 typedef int (*mlx5_list_match_cb)(struct mlx5_list *list,
348 struct mlx5_list_entry *entry, void *ctx);
350 typedef struct mlx5_list_entry *(*mlx5_list_clone_cb)
351 (struct mlx5_list *list,
352 struct mlx5_list_entry *entry, void *ctx);
354 typedef void (*mlx5_list_clone_free_cb)(struct mlx5_list *list,
355 struct mlx5_list_entry *entry);
358 * Type of function for user defined mlx5 list entry creation.
363 * The new allocated entry, NULL if list entry size unspecified,
364 * New entry has to be allocated in callback and return.
366 * The pointer to new entry context.
369 * Pointer of entry on success, NULL otherwise.
371 typedef struct mlx5_list_entry *(*mlx5_list_create_cb)
372 (struct mlx5_list *list,
373 struct mlx5_list_entry *entry,
377 * Linked mlx5 list structure.
379 * Entry in mlx5 list could be reused if entry already exists,
380 * reference count will increase and the existing entry returns.
382 * When destroy an entry from list, decrease reference count and only
383 * destroy when no further reference.
385 * Linked list is designed for limited number of entries,
386 * read mostly, less modification.
388 * For huge amount of entries, please consider hash list.
392 char name[MLX5_NAME_SIZE]; /**< Name of the mlx5 list. */
393 volatile uint32_t gen_cnt;
394 /* List modification will update generation count. */
395 volatile uint32_t count; /* number of entries in list. */
396 void *ctx; /* user objects target to callback. */
397 rte_rwlock_t lock; /* read/write lock. */
398 mlx5_list_create_cb cb_create; /**< entry create callback. */
399 mlx5_list_match_cb cb_match; /**< entry match callback. */
400 mlx5_list_remove_cb cb_remove; /**< entry remove callback. */
401 mlx5_list_clone_cb cb_clone; /**< entry clone callback. */
402 mlx5_list_clone_free_cb cb_clone_free;
403 struct mlx5_list_cache cache[RTE_MAX_LCORE + 1];
404 /* Lcore cache, last index is the global cache. */
408 * Create a mlx5 list.
411 * Pointer to the hast list table.
413 * Name of the mlx5 list.
415 * Pointer to the list context data.
417 * Callback function for entry create.
419 * Callback function for entry match.
421 * Callback function for entry remove.
423 * List pointer on success, otherwise NULL.
425 struct mlx5_list *mlx5_list_create(const char *name, void *ctx,
426 mlx5_list_create_cb cb_create,
427 mlx5_list_match_cb cb_match,
428 mlx5_list_remove_cb cb_remove,
429 mlx5_list_clone_cb cb_clone,
430 mlx5_list_clone_free_cb cb_clone_free);
433 * Search an entry matching the key.
435 * Result returned might be destroyed by other thread, must use
436 * this function only in main thread.
439 * Pointer to the mlx5 list.
441 * Common context parameter used by entry callback function.
444 * Pointer of the list entry if found, NULL otherwise.
446 struct mlx5_list_entry *mlx5_list_lookup(struct mlx5_list *list,
450 * Reuse or create an entry to the mlx5 list.
453 * Pointer to the hast list table.
455 * Common context parameter used by callback function.
458 * registered entry on success, NULL otherwise
460 struct mlx5_list_entry *mlx5_list_register(struct mlx5_list *list,
464 * Remove an entry from the mlx5 list.
466 * User should guarantee the validity of the entry.
469 * Pointer to the hast list.
471 * Entry to be removed from the mlx5 list table.
473 * 0 on entry removed, 1 on entry still referenced.
475 int mlx5_list_unregister(struct mlx5_list *list,
476 struct mlx5_list_entry *entry);
479 * Destroy the mlx5 list.
482 * Pointer to the mlx5 list.
484 void mlx5_list_destroy(struct mlx5_list *list);
487 * Get entry number from the mlx5 list.
490 * Pointer to the hast list.
492 * mlx5 list entry number.
495 mlx5_list_get_entry_num(struct mlx5_list *list);
497 /********************************* indexed pool *************************/
500 * This function allocates non-initialized memory entry from pool.
501 * In NUMA systems, the memory entry allocated resides on the same
502 * NUMA socket as the core that calls this function.
504 * Memory entry is allocated from memory trunk, no alignment.
507 * Pointer to indexed memory entry pool.
508 * No initialization required.
510 * Pointer to memory to save allocated index.
511 * Memory index always positive value.
513 * - Pointer to the allocated memory entry.
514 * - NULL on error. Not enough memory, or invalid arguments.
516 void *mlx5_ipool_malloc(struct mlx5_indexed_pool *pool, uint32_t *idx);
519 * This function allocates zero initialized memory entry from pool.
520 * In NUMA systems, the memory entry allocated resides on the same
521 * NUMA socket as the core that calls this function.
523 * Memory entry is allocated from memory trunk, no alignment.
526 * Pointer to indexed memory pool.
527 * No initialization required.
529 * Pointer to memory to save allocated index.
530 * Memory index always positive value.
532 * - Pointer to the allocated memory entry .
533 * - NULL on error. Not enough memory, or invalid arguments.
535 void *mlx5_ipool_zmalloc(struct mlx5_indexed_pool *pool, uint32_t *idx);
538 * This function frees indexed memory entry to pool.
539 * Caller has to make sure that the index is allocated from same pool.
542 * Pointer to indexed memory pool.
544 * Allocated memory entry index.
546 void mlx5_ipool_free(struct mlx5_indexed_pool *pool, uint32_t idx);
549 * This function returns pointer of indexed memory entry from index.
550 * Caller has to make sure that the index is valid, and allocated
554 * Pointer to indexed memory pool.
556 * Allocated memory index.
558 * - Pointer to indexed memory entry.
560 void *mlx5_ipool_get(struct mlx5_indexed_pool *pool, uint32_t idx);
563 * This function creates indexed memory pool.
564 * Caller has to configure the configuration accordingly.
567 * Pointer to indexed memory pool.
569 * Allocated memory index.
571 struct mlx5_indexed_pool *
572 mlx5_ipool_create(struct mlx5_indexed_pool_config *cfg);
575 * This function releases all resources of pool.
576 * Caller has to make sure that all indexes and memories allocated
577 * from this pool not referenced anymore.
580 * Pointer to indexed memory pool.
582 * - non-zero value on error.
585 int mlx5_ipool_destroy(struct mlx5_indexed_pool *pool);
588 * This function dumps debug info of pool.
591 * Pointer to indexed memory pool.
593 void mlx5_ipool_dump(struct mlx5_indexed_pool *pool);
596 * This function flushes all the cache index back to pool trunk.
599 * Pointer to the index memory pool handler.
603 void mlx5_ipool_flush_cache(struct mlx5_indexed_pool *pool);
606 * This function gets the available entry from pos.
609 * Pointer to the index memory pool handler.
611 * Pointer to the index position start from.
614 * - Pointer to the next available entry.
617 void *mlx5_ipool_get_next(struct mlx5_indexed_pool *pool, uint32_t *pos);
620 * This function allocates new empty Three-level table.
623 * The l3t can set as word, double word, quad word or pointer with index.
626 * - Pointer to the allocated l3t.
627 * - NULL on error. Not enough memory, or invalid arguments.
629 struct mlx5_l3t_tbl *mlx5_l3t_create(enum mlx5_l3t_type type);
632 * This function destroys Three-level table.
635 * Pointer to the l3t.
637 void mlx5_l3t_destroy(struct mlx5_l3t_tbl *tbl);
640 * This function gets the index entry from Three-level table.
643 * Pointer to the l3t.
645 * Index to the entry.
647 * Pointer to the memory which saves the entry data.
648 * When function call returns 0, data contains the entry data get from
650 * When function call returns -1, data is not modified.
653 * 0 if success, -1 on error.
656 int32_t mlx5_l3t_get_entry(struct mlx5_l3t_tbl *tbl, uint32_t idx,
657 union mlx5_l3t_data *data);
660 * This function gets the index entry from Three-level table.
662 * If the index entry is not available, allocate new one by callback
663 * function and fill in the entry.
666 * Pointer to the l3t.
668 * Index to the entry.
670 * Pointer to the memory which saves the entry data.
671 * When function call returns 0, data contains the entry data get from
673 * When function call returns -1, data is not modified.
675 * Callback function to allocate new data.
677 * Context for callback function.
680 * 0 if success, -1 on error.
683 int32_t mlx5_l3t_prepare_entry(struct mlx5_l3t_tbl *tbl, uint32_t idx,
684 union mlx5_l3t_data *data,
685 mlx5_l3t_alloc_callback_fn cb, void *ctx);
688 * This function decreases and clear index entry if reference
689 * counter is 0 from Three-level table.
692 * Pointer to the l3t.
694 * Index to the entry.
697 * The remaining reference count, 0 means entry be cleared, -1 on error.
699 int32_t mlx5_l3t_clear_entry(struct mlx5_l3t_tbl *tbl, uint32_t idx);
702 * This function sets the index entry to Three-level table.
703 * If the entry is already set, the EEXIST errno will be given, and
704 * the set data will be filled to the data.
707 * Pointer to the l3t.
709 * Index to the entry.
710 * @param data[in/out]
711 * Pointer to the memory which contains the entry data save to l3t.
712 * If the entry is already set, the set data will be filled.
715 * 0 if success, -1 on error.
717 int32_t mlx5_l3t_set_entry(struct mlx5_l3t_tbl *tbl, uint32_t idx,
718 union mlx5_l3t_data *data);
721 mlx5_l3t_get_next(struct mlx5_l3t_tbl *tbl, uint32_t *pos)
723 struct mlx5_l3t_level_tbl *g_tbl, *m_tbl;
724 uint32_t i, j, k, g_start, m_start, e_start;
727 struct mlx5_l3t_entry_word *w_e_tbl;
728 struct mlx5_l3t_entry_dword *dw_e_tbl;
729 struct mlx5_l3t_entry_qword *qw_e_tbl;
730 struct mlx5_l3t_entry_ptr *ptr_e_tbl;
737 g_start = (idx >> MLX5_L3T_GT_OFFSET) & MLX5_L3T_GT_MASK;
738 m_start = (idx >> MLX5_L3T_MT_OFFSET) & MLX5_L3T_MT_MASK;
739 e_start = idx & MLX5_L3T_ET_MASK;
740 for (i = g_start; i < MLX5_L3T_GT_SIZE; i++) {
741 m_tbl = g_tbl->tbl[i];
743 /* Jump to new table, reset the sub table start. */
748 for (j = m_start; j < MLX5_L3T_MT_SIZE; j++) {
749 if (!m_tbl->tbl[j]) {
751 * Jump to new table, reset the sub table
757 e_tbl = m_tbl->tbl[j];
759 case MLX5_L3T_TYPE_WORD:
760 w_e_tbl = (struct mlx5_l3t_entry_word *)e_tbl;
761 for (k = e_start; k < MLX5_L3T_ET_SIZE; k++) {
762 if (!w_e_tbl->entry[k].data)
764 *pos = (i << MLX5_L3T_GT_OFFSET) |
765 (j << MLX5_L3T_MT_OFFSET) | k;
766 return (void *)&w_e_tbl->entry[k].data;
769 case MLX5_L3T_TYPE_DWORD:
770 dw_e_tbl = (struct mlx5_l3t_entry_dword *)e_tbl;
771 for (k = e_start; k < MLX5_L3T_ET_SIZE; k++) {
772 if (!dw_e_tbl->entry[k].data)
774 *pos = (i << MLX5_L3T_GT_OFFSET) |
775 (j << MLX5_L3T_MT_OFFSET) | k;
776 return (void *)&dw_e_tbl->entry[k].data;
779 case MLX5_L3T_TYPE_QWORD:
780 qw_e_tbl = (struct mlx5_l3t_entry_qword *)e_tbl;
781 for (k = e_start; k < MLX5_L3T_ET_SIZE; k++) {
782 if (!qw_e_tbl->entry[k].data)
784 *pos = (i << MLX5_L3T_GT_OFFSET) |
785 (j << MLX5_L3T_MT_OFFSET) | k;
786 return (void *)&qw_e_tbl->entry[k].data;
790 ptr_e_tbl = (struct mlx5_l3t_entry_ptr *)e_tbl;
791 for (k = e_start; k < MLX5_L3T_ET_SIZE; k++) {
792 if (!ptr_e_tbl->entry[k].data)
794 *pos = (i << MLX5_L3T_GT_OFFSET) |
795 (j << MLX5_L3T_MT_OFFSET) | k;
796 return ptr_e_tbl->entry[k].data;
806 * Macros for linked list based on indexed memory.
807 * Example data structure:
809 * ILIST_ENTRY(uint16_t) next;
814 #define ILIST_ENTRY(type) \
816 type prev; /* Index of previous element. */ \
817 type next; /* Index of next element. */ \
820 #define ILIST_INSERT(pool, head, idx, elem, field) \
823 MLX5_ASSERT((elem) && (idx)); \
824 (elem)->field.next = *(head); \
825 (elem)->field.prev = 0; \
827 (peer) = mlx5_ipool_get(pool, *(head)); \
829 (peer)->field.prev = (idx); \
834 #define ILIST_REMOVE(pool, head, idx, elem, field) \
839 if ((elem)->field.prev) { \
840 (peer) = mlx5_ipool_get \
841 (pool, (elem)->field.prev); \
843 (peer)->field.next = (elem)->field.next;\
845 if ((elem)->field.next) { \
846 (peer) = mlx5_ipool_get \
847 (pool, (elem)->field.next); \
849 (peer)->field.prev = (elem)->field.prev;\
851 if (*(head) == (idx)) \
852 *(head) = (elem)->field.next; \
855 #define ILIST_FOREACH(pool, head, idx, elem, field) \
856 for ((idx) = (head), (elem) = \
857 (idx) ? mlx5_ipool_get(pool, (idx)) : NULL; (elem); \
858 idx = (elem)->field.next, (elem) = \
859 (idx) ? mlx5_ipool_get(pool, idx) : NULL)
861 /* Single index list. */
862 #define SILIST_ENTRY(type) \
864 type next; /* Index of next element. */ \
867 #define SILIST_INSERT(head, idx, elem, field) \
869 MLX5_ASSERT((elem) && (idx)); \
870 (elem)->field.next = *(head); \
874 #define SILIST_FOREACH(pool, head, idx, elem, field) \
875 for ((idx) = (head), (elem) = \
876 (idx) ? mlx5_ipool_get(pool, (idx)) : NULL; (elem); \
877 idx = (elem)->field.next, (elem) = \
878 (idx) ? mlx5_ipool_get(pool, idx) : NULL)
880 #define MLX5_L3T_FOREACH(tbl, idx, entry) \
881 for (idx = 0, (entry) = mlx5_l3t_get_next((tbl), &idx); \
883 idx++, (entry) = mlx5_l3t_get_next((tbl), &idx))
885 #define MLX5_IPOOL_FOREACH(ipool, idx, entry) \
886 for ((idx) = 0, mlx5_ipool_flush_cache((ipool)), \
887 (entry) = mlx5_ipool_get_next((ipool), &idx); \
888 (entry); idx++, (entry) = mlx5_ipool_get_next((ipool), &idx))
890 #endif /* RTE_PMD_MLX5_UTILS_H_ */