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_MALLOC_ASAN 57 : : #define MLX5DR_ASAN_ALIGN alignas(64) 58 : : #else 59 : : #define MLX5DR_ASAN_ALIGN 60 : : #endif 61 : : 62 : : #ifdef RTE_PMD_MLX5_DEBUG 63 : : 64 : : /* Prevent double function name print when debug is set */ 65 : : #define DR_LOG DRV_LOG 66 : : #else 67 : : /* Print function name as part of the log */ 68 : : #define DR_LOG(level, ...) \ 69 : : DRV_LOG(level, RTE_FMT("[%s]: " RTE_FMT_HEAD(__VA_ARGS__,), __func__, RTE_FMT_TAIL(__VA_ARGS__,))) 70 : : #endif 71 : : 72 : : static inline void *simple_malloc(size_t size) 73 : : { 74 : 0 : return mlx5_malloc(MLX5_MEM_SYS, 75 : : size, 76 : : MLX5_MALLOC_ALIGNMENT, 77 : : SOCKET_ID_ANY); 78 : : } 79 : : 80 : : static inline void *simple_calloc(size_t nmemb, size_t size) 81 : : { 82 : 0 : return mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, 83 : : nmemb * size, 84 : : MLX5_MALLOC_ALIGNMENT, 85 : : SOCKET_ID_ANY); 86 : : } 87 : : 88 : : static inline void simple_free(void *addr) 89 : : { 90 : 0 : mlx5_free(addr); 91 : 0 : } 92 : : 93 : 0 : static inline bool is_mem_zero(const uint8_t *mem, size_t size) 94 : : { 95 [ # # ]: 0 : assert(size); 96 [ # # # # ]: 0 : return (*mem == 0) && memcmp(mem, mem + 1, size - 1) == 0; 97 : : } 98 : : 99 : : static inline uint64_t roundup_pow_of_two(uint64_t n) 100 : : { 101 [ # # ]: 0 : return n == 1 ? 1 : 1ULL << log2above(n); 102 : : } 103 : : 104 : : static inline unsigned long align(unsigned long val, unsigned long align) 105 : : { 106 : 0 : return (val + align - 1) & ~(align - 1); 107 : : } 108 : : 109 : : #endif /* MLX5DR_INTERNAL_H_ */