net/mlx: do not enforce RSS hash offload
[dpdk.git] / drivers / net / mlx5 / mlx5_utils.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2015 6WIND S.A.
3  * Copyright 2015 Mellanox Technologies, Ltd
4  */
5
6 #ifndef RTE_PMD_MLX5_UTILS_H_
7 #define RTE_PMD_MLX5_UTILS_H_
8
9 #include <stddef.h>
10 #include <stdint.h>
11 #include <stdio.h>
12 #include <limits.h>
13 #include <errno.h>
14
15 #include <rte_spinlock.h>
16 #include <rte_memory.h>
17 #include <rte_bitmap.h>
18
19 #include <mlx5_common.h>
20
21 #include "mlx5_defs.h"
22
23
24 /* Convert a bit number to the corresponding 64-bit mask */
25 #define MLX5_BITSHIFT(v) (UINT64_C(1) << (v))
26
27 /* Save and restore errno around argument evaluation. */
28 #define ERRNO_SAFE(x) ((errno = (int []){ errno, ((x), 0) }[0]))
29
30 extern int mlx5_logtype;
31
32 /* Generic printf()-like logging macro with automatic line feed. */
33 #define DRV_LOG(level, ...) \
34         PMD_DRV_LOG_(level, mlx5_logtype, MLX5_DRIVER_NAME, \
35                 __VA_ARGS__ PMD_DRV_LOG_STRIP PMD_DRV_LOG_OPAREN, \
36                 PMD_DRV_LOG_CPAREN)
37
38 /* Convenience macros for accessing mbuf fields. */
39 #define NEXT(m) ((m)->next)
40 #define DATA_LEN(m) ((m)->data_len)
41 #define PKT_LEN(m) ((m)->pkt_len)
42 #define DATA_OFF(m) ((m)->data_off)
43 #define SET_DATA_OFF(m, o) ((m)->data_off = (o))
44 #define NB_SEGS(m) ((m)->nb_segs)
45 #define PORT(m) ((m)->port)
46
47 /* Transpose flags. Useful to convert IBV to DPDK flags. */
48 #define TRANSPOSE(val, from, to) \
49         (((from) >= (to)) ? \
50          (((val) & (from)) / ((from) / (to))) : \
51          (((val) & (from)) * ((to) / (from))))
52
53 /*
54  * For the case which data is linked with sequence increased index, the
55  * array table will be more efficiect than hash table once need to serarch
56  * one data entry in large numbers of entries. Since the traditional hash
57  * tables has fixed table size, when huge numbers of data saved to the hash
58  * table, it also comes lots of hash conflict.
59  *
60  * But simple array table also has fixed size, allocates all the needed
61  * memory at once will waste lots of memory. For the case don't know the
62  * exactly number of entries will be impossible to allocate the array.
63  *
64  * Then the multiple level table helps to balance the two disadvantages.
65  * Allocate a global high level table with sub table entries at first,
66  * the global table contains the sub table entries, and the sub table will
67  * be allocated only once the corresponding index entry need to be saved.
68  * e.g. for up to 32-bits index, three level table with 10-10-12 splitting,
69  * with sequence increased index, the memory grows with every 4K entries.
70  *
71  * The currently implementation introduces 10-10-12 32-bits splitting
72  * Three-Level table to help the cases which have millions of enties to
73  * save. The index entries can be addressed directly by the index, no
74  * search will be needed.q
75  */
76
77 /* L3 table global table define. */
78 #define MLX5_L3T_GT_OFFSET 22
79 #define MLX5_L3T_GT_SIZE (1 << 10)
80 #define MLX5_L3T_GT_MASK (MLX5_L3T_GT_SIZE - 1)
81
82 /* L3 table middle table define. */
83 #define MLX5_L3T_MT_OFFSET 12
84 #define MLX5_L3T_MT_SIZE (1 << 10)
85 #define MLX5_L3T_MT_MASK (MLX5_L3T_MT_SIZE - 1)
86
87 /* L3 table entry table define. */
88 #define MLX5_L3T_ET_OFFSET 0
89 #define MLX5_L3T_ET_SIZE (1 << 12)
90 #define MLX5_L3T_ET_MASK (MLX5_L3T_ET_SIZE - 1)
91
92 /* L3 table type. */
93 enum mlx5_l3t_type {
94         MLX5_L3T_TYPE_WORD = 0,
95         MLX5_L3T_TYPE_DWORD,
96         MLX5_L3T_TYPE_QWORD,
97         MLX5_L3T_TYPE_PTR,
98         MLX5_L3T_TYPE_MAX,
99 };
100
101 struct mlx5_indexed_pool;
102
103 /* Generic data struct. */
104 union mlx5_l3t_data {
105         uint16_t word;
106         uint32_t dword;
107         uint64_t qword;
108         void *ptr;
109 };
110
111 /* L3 level table data structure. */
112 struct mlx5_l3t_level_tbl {
113         uint64_t ref_cnt; /* Table ref_cnt. */
114         void *tbl[]; /* Table array. */
115 };
116
117 /* L3 word entry table data structure. */
118 struct mlx5_l3t_entry_word {
119         uint32_t idx; /* Table index. */
120         uint64_t ref_cnt; /* Table ref_cnt. */
121         struct {
122                 uint16_t data;
123                 uint32_t ref_cnt;
124         } entry[MLX5_L3T_ET_SIZE]; /* Entry array */
125 } __rte_packed;
126
127 /* L3 double word entry table data structure. */
128 struct mlx5_l3t_entry_dword {
129         uint32_t idx; /* Table index. */
130         uint64_t ref_cnt; /* Table ref_cnt. */
131         struct {
132                 uint32_t data;
133                 int32_t ref_cnt;
134         } entry[MLX5_L3T_ET_SIZE]; /* Entry array */
135 } __rte_packed;
136
137 /* L3 quad word entry table data structure. */
138 struct mlx5_l3t_entry_qword {
139         uint32_t idx; /* Table index. */
140         uint64_t ref_cnt; /* Table ref_cnt. */
141         struct {
142                 uint64_t data;
143                 uint32_t ref_cnt;
144         } entry[MLX5_L3T_ET_SIZE]; /* Entry array */
145 } __rte_packed;
146
147 /* L3 pointer entry table data structure. */
148 struct mlx5_l3t_entry_ptr {
149         uint32_t idx; /* Table index. */
150         uint64_t ref_cnt; /* Table ref_cnt. */
151         struct {
152                 void *data;
153                 uint32_t ref_cnt;
154         } entry[MLX5_L3T_ET_SIZE]; /* Entry array */
155 } __rte_packed;
156
157 /* L3 table data structure. */
158 struct mlx5_l3t_tbl {
159         enum mlx5_l3t_type type; /* Table type. */
160         struct mlx5_indexed_pool *eip;
161         /* Table index pool handles. */
162         struct mlx5_l3t_level_tbl *tbl; /* Global table index. */
163         rte_spinlock_t sl; /* The table lock. */
164 };
165
166 /** Type of function that is used to handle the data before freeing. */
167 typedef int32_t (*mlx5_l3t_alloc_callback_fn)(void *ctx,
168                                            union mlx5_l3t_data *data);
169
170 /*
171  * The indexed memory entry index is made up of trunk index and offset of
172  * the entry in the trunk. Since the entry index is 32 bits, in case user
173  * prefers to have small trunks, user can change the macro below to a big
174  * number which helps the pool contains more trunks with lots of entries
175  * allocated.
176  */
177 #define TRUNK_IDX_BITS 16
178 #define TRUNK_MAX_IDX ((1 << TRUNK_IDX_BITS) - 1)
179 #define TRUNK_INVALID TRUNK_MAX_IDX
180 #define MLX5_IPOOL_DEFAULT_TRUNK_SIZE (1 << (28 - TRUNK_IDX_BITS))
181 #ifdef RTE_LIBRTE_MLX5_DEBUG
182 #define POOL_DEBUG 1
183 #endif
184
185 struct mlx5_indexed_pool_config {
186         uint32_t size; /* Pool entry size. */
187         uint32_t trunk_size:22;
188         /*
189          * Trunk entry number. Must be power of 2. It can be increased
190          * if trunk_grow enable. The trunk entry number increases with
191          * left shift grow_shift. Trunks with index are after grow_trunk
192          * will keep the entry number same with the last grow trunk.
193          */
194         uint32_t grow_trunk:4;
195         /*
196          * Trunks with entry number increase in the pool. Set it to 0
197          * to make the pool works as trunk entry fixed pool. It works
198          * only if grow_shift is not 0.
199          */
200         uint32_t grow_shift:4;
201         /*
202          * Trunk entry number increase shift value, stop after grow_trunk.
203          * It works only if grow_trunk is not 0.
204          */
205         uint32_t need_lock:1;
206         /* Lock is needed for multiple thread usage. */
207         uint32_t release_mem_en:1; /* Rlease trunk when it is free. */
208         const char *type; /* Memory allocate type name. */
209         void *(*malloc)(uint32_t flags, size_t size, unsigned int align,
210                         int socket);
211         /* User defined memory allocator. */
212         void (*free)(void *addr); /* User defined memory release. */
213 };
214
215 struct mlx5_indexed_trunk {
216         uint32_t idx; /* Trunk id. */
217         uint32_t prev; /* Previous free trunk in free list. */
218         uint32_t next; /* Next free trunk in free list. */
219         uint32_t free; /* Free entries available */
220         struct rte_bitmap *bmp;
221         uint8_t data[] __rte_cache_aligned; /* Entry data start. */
222 };
223
224 struct mlx5_indexed_pool {
225         struct mlx5_indexed_pool_config cfg; /* Indexed pool configuration. */
226         rte_spinlock_t lock; /* Pool lock for multiple thread usage. */
227         uint32_t n_trunk_valid; /* Trunks allocated. */
228         uint32_t n_trunk; /* Trunk pointer array size. */
229         /* Dim of trunk pointer array. */
230         struct mlx5_indexed_trunk **trunks;
231         uint32_t free_list; /* Index to first free trunk. */
232 #ifdef POOL_DEBUG
233         uint32_t n_entry;
234         uint32_t trunk_new;
235         uint32_t trunk_avail;
236         uint32_t trunk_empty;
237         uint32_t trunk_free;
238 #endif
239         uint32_t grow_tbl[]; /* Save the index offset for the grow trunks. */
240 };
241
242 /**
243  * Return logarithm of the nearest power of two above input value.
244  *
245  * @param v
246  *   Input value.
247  *
248  * @return
249  *   Logarithm of the nearest power of two above input value.
250  */
251 static inline unsigned int
252 log2above(unsigned int v)
253 {
254         unsigned int l;
255         unsigned int r;
256
257         for (l = 0, r = 0; (v >> 1); ++l, v >>= 1)
258                 r |= (v & 1);
259         return l + r;
260 }
261
262 /** Maximum size of string for naming the hlist table. */
263 #define MLX5_HLIST_NAMESIZE                     32
264
265 /**
266  * Structure of the entry in the hash list, user should define its own struct
267  * that contains this in order to store the data. The 'key' is 64-bits right
268  * now and its user's responsibility to guarantee there is no collision.
269  */
270 struct mlx5_hlist_entry {
271         LIST_ENTRY(mlx5_hlist_entry) next; /* entry pointers in the list. */
272         uint64_t key; /* user defined 'key', could be the hash signature. */
273 };
274
275 /** Structure for hash head. */
276 LIST_HEAD(mlx5_hlist_head, mlx5_hlist_entry);
277
278 /** Type of function that is used to handle the data before freeing. */
279 typedef void (*mlx5_hlist_destroy_callback_fn)(void *p, void *ctx);
280
281 /**
282  * Type of function for user defined matching.
283  *
284  * @param entry
285  *   The entry in the list.
286  * @param ctx
287  *   The pointer to new entry context.
288  *
289  * @return
290  *   0 if matching, -1 otherwise.
291  */
292 typedef int (*mlx5_hlist_match_callback_fn)(struct mlx5_hlist_entry *entry,
293                                              void *ctx);
294
295 /** hash list table structure */
296 struct mlx5_hlist {
297         char name[MLX5_HLIST_NAMESIZE]; /**< Name of the hash list. */
298         /**< number of heads, need to be power of 2. */
299         uint32_t table_sz;
300         /**< mask to get the index of the list heads. */
301         uint32_t mask;
302         struct mlx5_hlist_head heads[]; /**< list head arrays. */
303 };
304
305 /**
306  * Create a hash list table, the user can specify the list heads array size
307  * of the table, now the size should be a power of 2 in order to get better
308  * distribution for the entries. Each entry is a part of the whole data element
309  * and the caller should be responsible for the data element's allocation and
310  * cleanup / free. Key of each entry will be calculated with CRC in order to
311  * generate a little fairer distribution.
312  *
313  * @param name
314  *   Name of the hash list(optional).
315  * @param size
316  *   Heads array size of the hash list.
317  *
318  * @return
319  *   Pointer of the hash list table created, NULL on failure.
320  */
321 struct mlx5_hlist *mlx5_hlist_create(const char *name, uint32_t size);
322
323 /**
324  * Search an entry matching the key.
325  *
326  * @param h
327  *   Pointer to the hast list table.
328  * @param key
329  *   Key for the searching entry.
330  *
331  * @return
332  *   Pointer of the hlist entry if found, NULL otherwise.
333  */
334 struct mlx5_hlist_entry *mlx5_hlist_lookup(struct mlx5_hlist *h, uint64_t key);
335
336 /**
337  * Insert an entry to the hash list table, the entry is only part of whole data
338  * element and a 64B key is used for matching. User should construct the key or
339  * give a calculated hash signature and guarantee there is no collision.
340  *
341  * @param h
342  *   Pointer to the hast list table.
343  * @param entry
344  *   Entry to be inserted into the hash list table.
345  *
346  * @return
347  *   - zero for success.
348  *   - -EEXIST if the entry is already inserted.
349  */
350 int mlx5_hlist_insert(struct mlx5_hlist *h, struct mlx5_hlist_entry *entry);
351
352 /**
353  * Extended routine to search an entry matching the context with
354  * user defined match function.
355  *
356  * @param h
357  *   Pointer to the hast list table.
358  * @param key
359  *   Key for the searching entry.
360  * @param cb
361  *   Callback function to match the node with context.
362  * @param ctx
363  *   Common context parameter used by callback function.
364  *
365  * @return
366  *   Pointer of the hlist entry if found, NULL otherwise.
367  */
368 struct mlx5_hlist_entry *mlx5_hlist_lookup_ex(struct mlx5_hlist *h,
369                                               uint64_t key,
370                                               mlx5_hlist_match_callback_fn cb,
371                                               void *ctx);
372
373 /**
374  * Extended routine to insert an entry to the list with key collisions.
375  *
376  * For the list have key collision, the extra user defined match function
377  * allows node with same key will be inserted.
378  *
379  * @param h
380  *   Pointer to the hast list table.
381  * @param entry
382  *   Entry to be inserted into the hash list table.
383  * @param cb
384  *   Callback function to match the node with context.
385  * @param ctx
386  *   Common context parameter used by callback function.
387  *
388  * @return
389  *   - zero for success.
390  *   - -EEXIST if the entry is already inserted.
391  */
392 int mlx5_hlist_insert_ex(struct mlx5_hlist *h, struct mlx5_hlist_entry *entry,
393                          mlx5_hlist_match_callback_fn cb, void *ctx);
394
395 /**
396  * Remove an entry from the hash list table. User should guarantee the validity
397  * of the entry.
398  *
399  * @param h
400  *   Pointer to the hast list table. (not used)
401  * @param entry
402  *   Entry to be removed from the hash list table.
403  */
404 void mlx5_hlist_remove(struct mlx5_hlist *h __rte_unused,
405                        struct mlx5_hlist_entry *entry);
406
407 /**
408  * Destroy the hash list table, all the entries already inserted into the lists
409  * will be handled by the callback function provided by the user (including
410  * free if needed) before the table is freed.
411  *
412  * @param h
413  *   Pointer to the hast list table.
414  * @param cb
415  *   Callback function for each inserted entry when destroying the hash list.
416  * @param ctx
417  *   Common context parameter used by callback function for each entry.
418  */
419 void mlx5_hlist_destroy(struct mlx5_hlist *h,
420                         mlx5_hlist_destroy_callback_fn cb, void *ctx);
421
422 /**
423  * This function allocates non-initialized memory entry from pool.
424  * In NUMA systems, the memory entry allocated resides on the same
425  * NUMA socket as the core that calls this function.
426  *
427  * Memory entry is allocated from memory trunk, no alignment.
428  *
429  * @param pool
430  *   Pointer to indexed memory entry pool.
431  *   No initialization required.
432  * @param[out] idx
433  *   Pointer to memory to save allocated index.
434  *   Memory index always positive value.
435  * @return
436  *   - Pointer to the allocated memory entry.
437  *   - NULL on error. Not enough memory, or invalid arguments.
438  */
439 void *mlx5_ipool_malloc(struct mlx5_indexed_pool *pool, uint32_t *idx);
440
441 /**
442  * This function allocates zero initialized memory entry from pool.
443  * In NUMA systems, the memory entry allocated resides on the same
444  * NUMA socket as the core that calls this function.
445  *
446  * Memory entry is allocated from memory trunk, no alignment.
447  *
448  * @param pool
449  *   Pointer to indexed memory pool.
450  *   No initialization required.
451  * @param[out] idx
452  *   Pointer to memory to save allocated index.
453  *   Memory index always positive value.
454  * @return
455  *   - Pointer to the allocated memory entry .
456  *   - NULL on error. Not enough memory, or invalid arguments.
457  */
458 void *mlx5_ipool_zmalloc(struct mlx5_indexed_pool *pool, uint32_t *idx);
459
460 /**
461  * This function frees indexed memory entry to pool.
462  * Caller has to make sure that the index is allocated from same pool.
463  *
464  * @param pool
465  *   Pointer to indexed memory pool.
466  * @param idx
467  *   Allocated memory entry index.
468  */
469 void mlx5_ipool_free(struct mlx5_indexed_pool *pool, uint32_t idx);
470
471 /**
472  * This function returns pointer of indexed memory entry from index.
473  * Caller has to make sure that the index is valid, and allocated
474  * from same pool.
475  *
476  * @param pool
477  *   Pointer to indexed memory pool.
478  * @param idx
479  *   Allocated memory index.
480  * @return
481  *   - Pointer to indexed memory entry.
482  */
483 void *mlx5_ipool_get(struct mlx5_indexed_pool *pool, uint32_t idx);
484
485 /**
486  * This function creates indexed memory pool.
487  * Caller has to configure the configuration accordingly.
488  *
489  * @param pool
490  *   Pointer to indexed memory pool.
491  * @param cfg
492  *   Allocated memory index.
493  */
494 struct mlx5_indexed_pool *
495 mlx5_ipool_create(struct mlx5_indexed_pool_config *cfg);
496
497 /**
498  * This function releases all resources of pool.
499  * Caller has to make sure that all indexes and memories allocated
500  * from this pool not referenced anymore.
501  *
502  * @param pool
503  *   Pointer to indexed memory pool.
504  * @return
505  *   - non-zero value on error.
506  *   - 0 on success.
507  */
508 int mlx5_ipool_destroy(struct mlx5_indexed_pool *pool);
509
510 /**
511  * This function dumps debug info of pool.
512  *
513  * @param pool
514  *   Pointer to indexed memory pool.
515  */
516 void mlx5_ipool_dump(struct mlx5_indexed_pool *pool);
517
518 /**
519  * This function allocates new empty Three-level table.
520  *
521  * @param type
522  *   The l3t can set as word, double word, quad word or pointer with index.
523  *
524  * @return
525  *   - Pointer to the allocated l3t.
526  *   - NULL on error. Not enough memory, or invalid arguments.
527  */
528 struct mlx5_l3t_tbl *mlx5_l3t_create(enum mlx5_l3t_type type);
529
530 /**
531  * This function destroys Three-level table.
532  *
533  * @param tbl
534  *   Pointer to the l3t.
535  */
536 void mlx5_l3t_destroy(struct mlx5_l3t_tbl *tbl);
537
538 /**
539  * This function gets the index entry from Three-level table.
540  *
541  * @param tbl
542  *   Pointer to the l3t.
543  * @param idx
544  *   Index to the entry.
545  * @param data
546  *   Pointer to the memory which saves the entry data.
547  *   When function call returns 0, data contains the entry data get from
548  *   l3t.
549  *   When function call returns -1, data is not modified.
550  *
551  * @return
552  *   0 if success, -1 on error.
553  */
554
555 int32_t mlx5_l3t_get_entry(struct mlx5_l3t_tbl *tbl, uint32_t idx,
556                             union mlx5_l3t_data *data);
557
558 /**
559  * This function gets the index entry from Three-level table.
560  *
561  * If the index entry is not available, allocate new one by callback
562  * function and fill in the entry.
563  *
564  * @param tbl
565  *   Pointer to the l3t.
566  * @param idx
567  *   Index to the entry.
568  * @param data
569  *   Pointer to the memory which saves the entry data.
570  *   When function call returns 0, data contains the entry data get from
571  *   l3t.
572  *   When function call returns -1, data is not modified.
573  * @param cb
574  *   Callback function to allocate new data.
575  * @param ctx
576  *   Context for callback function.
577  *
578  * @return
579  *   0 if success, -1 on error.
580  */
581
582 int32_t mlx5_l3t_prepare_entry(struct mlx5_l3t_tbl *tbl, uint32_t idx,
583                                union mlx5_l3t_data *data,
584                                mlx5_l3t_alloc_callback_fn cb, void *ctx);
585
586 /**
587  * This function decreases and clear index entry if reference
588  * counter is 0 from Three-level table.
589  *
590  * @param tbl
591  *   Pointer to the l3t.
592  * @param idx
593  *   Index to the entry.
594  *
595  * @return
596  *   The remaining reference count, 0 means entry be cleared, -1 on error.
597  */
598 int32_t mlx5_l3t_clear_entry(struct mlx5_l3t_tbl *tbl, uint32_t idx);
599
600 /**
601  * This function sets the index entry to Three-level table.
602  * If the entry is already set, the EEXIST errno will be given, and
603  * the set data will be filled to the data.
604  *
605  * @param tbl[in]
606  *   Pointer to the l3t.
607  * @param idx[in]
608  *   Index to the entry.
609  * @param data[in/out]
610  *   Pointer to the memory which contains the entry data save to l3t.
611  *   If the entry is already set, the set data will be filled.
612  *
613  * @return
614  *   0 if success, -1 on error.
615  */
616 int32_t mlx5_l3t_set_entry(struct mlx5_l3t_tbl *tbl, uint32_t idx,
617                             union mlx5_l3t_data *data);
618
619 /*
620  * Macros for linked list based on indexed memory.
621  * Example data structure:
622  * struct Foo {
623  *      ILIST_ENTRY(uint16_t) next;
624  *      ...
625  * }
626  *
627  */
628 #define ILIST_ENTRY(type)                                               \
629 struct {                                                                \
630         type prev; /* Index of previous element. */                     \
631         type next; /* Index of next element. */                         \
632 }
633
634 #define ILIST_INSERT(pool, head, idx, elem, field)                      \
635         do {                                                            \
636                 typeof(elem) peer;                                      \
637                 MLX5_ASSERT((elem) && (idx));                           \
638                 (elem)->field.next = *(head);                           \
639                 (elem)->field.prev = 0;                                 \
640                 if (*(head)) {                                          \
641                         (peer) = mlx5_ipool_get(pool, *(head));         \
642                         if (peer)                                       \
643                                 (peer)->field.prev = (idx);             \
644                 }                                                       \
645                 *(head) = (idx);                                        \
646         } while (0)
647
648 #define ILIST_REMOVE(pool, head, idx, elem, field)                      \
649         do {                                                            \
650                 typeof(elem) peer;                                      \
651                 MLX5_ASSERT(elem);                                      \
652                 MLX5_ASSERT(head);                                      \
653                 if ((elem)->field.prev) {                               \
654                         (peer) = mlx5_ipool_get                         \
655                                  (pool, (elem)->field.prev);            \
656                         if (peer)                                       \
657                                 (peer)->field.next = (elem)->field.next;\
658                 }                                                       \
659                 if ((elem)->field.next) {                               \
660                         (peer) = mlx5_ipool_get                         \
661                                  (pool, (elem)->field.next);            \
662                         if (peer)                                       \
663                                 (peer)->field.prev = (elem)->field.prev;\
664                 }                                                       \
665                 if (*(head) == (idx))                                   \
666                         *(head) = (elem)->field.next;                   \
667         } while (0)
668
669 #define ILIST_FOREACH(pool, head, idx, elem, field)                     \
670         for ((idx) = (head), (elem) =                                   \
671              (idx) ? mlx5_ipool_get(pool, (idx)) : NULL; (elem);        \
672              idx = (elem)->field.next, (elem) =                         \
673              (idx) ? mlx5_ipool_get(pool, idx) : NULL)
674
675 /* Single index list. */
676 #define SILIST_ENTRY(type)                                              \
677 struct {                                                                \
678         type next; /* Index of next element. */                         \
679 }
680
681 #define SILIST_INSERT(head, idx, elem, field)                           \
682         do {                                                            \
683                 MLX5_ASSERT((elem) && (idx));                           \
684                 (elem)->field.next = *(head);                           \
685                 *(head) = (idx);                                        \
686         } while (0)
687
688 #define SILIST_FOREACH(pool, head, idx, elem, field)                    \
689         for ((idx) = (head), (elem) =                                   \
690              (idx) ? mlx5_ipool_get(pool, (idx)) : NULL; (elem);        \
691              idx = (elem)->field.next, (elem) =                         \
692              (idx) ? mlx5_ipool_get(pool, idx) : NULL)
693
694 #endif /* RTE_PMD_MLX5_UTILS_H_ */