Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright (c) 2022 NVIDIA Corporation & Affiliates 3 : : */ 4 : : 5 : : #ifndef MLX5DR_INTERNAL_H_ 6 : : #define MLX5DR_INTERNAL_H_ 7 : : 8 : : #include <stdint.h> 9 : : #include <sys/queue.h> 10 : : /* Verbs headers do not support -pedantic. */ 11 : : #ifdef PEDANTIC 12 : : #pragma GCC diagnostic ignored "-Wpedantic" 13 : : #endif 14 : : #include <infiniband/verbs.h> 15 : : #include <infiniband/mlx5dv.h> 16 : : #ifdef PEDANTIC 17 : : #pragma GCC diagnostic error "-Wpedantic" 18 : : #endif 19 : : #include <rte_flow.h> 20 : : #include <rte_gtp.h> 21 : : #include <rte_random.h> 22 : : 23 : : #include "mlx5_prm.h" 24 : : #include "mlx5_glue.h" 25 : : #include "mlx5_flow.h" 26 : : #include "mlx5_utils.h" 27 : : #include "mlx5_malloc.h" 28 : : 29 : : #include "mlx5dr.h" 30 : : #include "mlx5dr_pool.h" 31 : : #include "mlx5dr_context.h" 32 : : #include "mlx5dr_table.h" 33 : : #include "mlx5dr_send.h" 34 : : #include "mlx5dr_rule.h" 35 : : #include "mlx5dr_cmd.h" 36 : : #include "mlx5dr_action.h" 37 : : #include "mlx5dr_definer.h" 38 : : #include "mlx5dr_matcher.h" 39 : : #include "mlx5dr_debug.h" 40 : : #include "mlx5dr_pat_arg.h" 41 : : #include "mlx5dr_crc32.h" 42 : : #include "mlx5dr_bwc.h" 43 : : 44 : : #define W_SIZE 2 45 : : #define DW_SIZE 4 46 : : #define BITS_IN_BYTE 8 47 : : #define BITS_IN_DW (BITS_IN_BYTE * DW_SIZE) 48 : : 49 : : #define BIT(_bit) (1ULL << (_bit)) 50 : : #define IS_BIT_SET(_value, _bit) ((_value) & (1ULL << (_bit))) 51 : : 52 : : #ifndef ARRAY_SIZE 53 : : #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 54 : : #endif 55 : : 56 : : #ifdef RTE_LIBRTE_MLX5_DEBUG 57 : : /* Prevent double function name print when debug is set */ 58 : : #define DR_LOG DRV_LOG 59 : : #else 60 : : /* Print function name as part of the log */ 61 : : #define DR_LOG(level, ...) \ 62 : : DRV_LOG(level, RTE_FMT("[%s]: " RTE_FMT_HEAD(__VA_ARGS__,), __func__, RTE_FMT_TAIL(__VA_ARGS__,))) 63 : : #endif 64 : : 65 : : static inline void *simple_malloc(size_t size) 66 : : { 67 : 0 : return mlx5_malloc(MLX5_MEM_SYS, 68 : : size, 69 : : MLX5_MALLOC_ALIGNMENT, 70 : : SOCKET_ID_ANY); 71 : : } 72 : : 73 : : static inline void *simple_calloc(size_t nmemb, size_t size) 74 : : { 75 : 0 : return mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, 76 : : nmemb * size, 77 : : MLX5_MALLOC_ALIGNMENT, 78 : : SOCKET_ID_ANY); 79 : : } 80 : : 81 : : static inline void simple_free(void *addr) 82 : : { 83 : 0 : mlx5_free(addr); 84 : 0 : } 85 : : 86 : 0 : static inline bool is_mem_zero(const uint8_t *mem, size_t size) 87 : : { 88 [ # # ]: 0 : assert(size); 89 [ # # # # ]: 0 : return (*mem == 0) && memcmp(mem, mem + 1, size - 1) == 0; 90 : : } 91 : : 92 : : static inline uint64_t roundup_pow_of_two(uint64_t n) 93 : : { 94 [ # # ]: 0 : return n == 1 ? 1 : 1ULL << log2above(n); 95 : : } 96 : : 97 : : static inline unsigned long align(unsigned long val, unsigned long align) 98 : : { 99 : 0 : return (val + align - 1) & ~(align - 1); 100 : : } 101 : : 102 : : #endif /* MLX5DR_INTERNAL_H_ */