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 : : 43 : : #define W_SIZE 2 44 : : #define DW_SIZE 4 45 : : #define BITS_IN_BYTE 8 46 : : #define BITS_IN_DW (BITS_IN_BYTE * DW_SIZE) 47 : : 48 : : #define BIT(_bit) (1ULL << (_bit)) 49 : : #define IS_BIT_SET(_value, _bit) ((_value) & (1ULL << (_bit))) 50 : : 51 : : #ifndef ARRAY_SIZE 52 : : #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 53 : : #endif 54 : : 55 : : #ifdef RTE_LIBRTE_MLX5_DEBUG 56 : : /* Prevent double function name print when debug is set */ 57 : : #define DR_LOG DRV_LOG 58 : : #else 59 : : /* Print function name as part of the log */ 60 : : #define DR_LOG(level, ...) \ 61 : : DRV_LOG(level, RTE_FMT("[%s]: " RTE_FMT_HEAD(__VA_ARGS__,), __func__, RTE_FMT_TAIL(__VA_ARGS__,))) 62 : : #endif 63 : : 64 : : static inline void *simple_malloc(size_t size) 65 : : { 66 : 0 : return mlx5_malloc(MLX5_MEM_SYS, 67 : : size, 68 : : MLX5_MALLOC_ALIGNMENT, 69 : : SOCKET_ID_ANY); 70 : : } 71 : : 72 : : static inline void *simple_calloc(size_t nmemb, size_t size) 73 : : { 74 : 0 : return mlx5_malloc(MLX5_MEM_SYS | MLX5_MEM_ZERO, 75 : : nmemb * size, 76 : : MLX5_MALLOC_ALIGNMENT, 77 : : SOCKET_ID_ANY); 78 : : } 79 : : 80 : : static inline void simple_free(void *addr) 81 : : { 82 : 0 : mlx5_free(addr); 83 : 0 : } 84 : : 85 : 0 : static inline bool is_mem_zero(const uint8_t *mem, size_t size) 86 : : { 87 [ # # ]: 0 : assert(size); 88 [ # # # # ]: 0 : return (*mem == 0) && memcmp(mem, mem + 1, size - 1) == 0; 89 : : } 90 : : 91 : : static inline uint64_t roundup_pow_of_two(uint64_t n) 92 : : { 93 [ # # ]: 0 : return n == 1 ? 1 : 1ULL << log2above(n); 94 : : } 95 : : 96 : : static inline unsigned long align(unsigned long val, unsigned long align) 97 : : { 98 : 0 : return (val + align - 1) & ~(align - 1); 99 : : } 100 : : 101 : : #endif /* MLX5DR_INTERNAL_H_ */