sw_state.h (9956B)
1 /* 2 * 3 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 4 * 5 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 6 */ 7 #ifndef _SHR_SW_STATE_H 8 #define _SHR_SW_STATE_H 9 10 #include <bcm/types.h> 11 #include <soc/types.h> 12 13 #define SOC_MODULE_SW_STATE 100 14 15 #define PARSER_HINT_ARR 16 #define PARSER_HINT_PTR 17 #define PARSER_HINT_ARR_ARR 18 #define PARSER_HINT_ARR_PTR 19 #define PARSER_HINT_PTR_ARR 20 #define PARSER_HINT_PTR_PTR 21 #define PARSER_HINT_ALLOW_WB_ACCESS 22 #define PARSER_HINT_AUTOSYNC_EXCLUDE 23 /* when the variable's size is too big we may want to pass it through pointer 24 * in this case the we should prefix the variable definition with this parser hint: PARSER_HINT_PTR_SET 25 * this cause the implementation of the set function (generated by the autocoder) to get the value of the variable through pointer 26 */ 27 #define PARSER_HINT_PTR_SET 28 29 typedef enum { 30 SHR_BITDCL_ASSIGNMENT, 31 SHR_BITDCL_AND, 32 SHR_BITDCL_OR, 33 SHR_BITDCL_XOR, 34 SHR_BITDCL_REMOVE, 35 SHR_BITDCL_CLEAR, 36 SHR_BITDCL_SET 37 } shrbitdcl_op_t; 38 39 typedef enum { 40 SW_STATE_BUFF_ASSIGNMENT, 41 SW_STATE_BUFF_SET 42 } sw_state_buff_op_t; 43 44 typedef enum 45 { 46 SW_ST_PBMP_INVALID, 47 SW_ST_PBMP_NEQ, 48 SW_ST_PBMP_EQ, 49 SW_ST_PBMP_MEMBER, 50 SW_ST_PBMP_NOT_NULL, 51 SW_ST_PBMP_IS_NULL, 52 SW_ST_PBMP_COUNT, 53 SW_ST_PBMP_XOR, 54 SW_ST_PBMP_REMOVE, 55 SW_ST_PBMP_ASSIGN, 56 SW_ST_PBMP_GET, 57 SW_ST_PBMP_AND, 58 SW_ST_PBMP_NEGATE, 59 SW_ST_PBMP_OR, 60 SW_ST_PBMP_CLEAR, 61 SW_ST_PBMP_PORT_ADD, 62 SW_ST_PBMP_PORT_FLIP, 63 SW_ST_PBMP_PORT_REMOVE, 64 SW_ST_PBMP_PORT_SET, 65 SW_ST_PBMP_PORTS_RANGE_ADD, 66 SW_ST_PBMP_FMT, 67 SW_ST_PBMP_NOF 68 } SW_ST_PBMP; 69 70 typedef enum 71 { 72 SW_ST_BIT_SET, 73 SW_ST_BIT_CLEAR, 74 SW_ST_BIT_GET, 75 SW_ST_BIT_RANGE_READ, 76 SW_ST_BIT_RANGE_WRITE, 77 SW_ST_BIT_RANGE_AND, 78 SW_ST_BIT_RANGE_OR, 79 SW_ST_BIT_RANGE_XOR, 80 SW_ST_BIT_RANGE_REMOVE, 81 SW_ST_BIT_RANGE_NEGATE, 82 SW_ST_BIT_RANGE_CLEAR, 83 SW_ST_BIT_RANGE_SET, 84 SW_ST_BIT_RANGE_NULL, 85 SW_ST_BIT_RANGE_TEST, 86 SW_ST_BIT_RANGE_EQ, 87 SW_ST_BIT_RANGE_COUNT, 88 SW_ST_BIT_NOF 89 } SW_ST_BITDCL; 90 91 typedef struct sw_state_bitdcl_param_s { 92 int _bit_num; 93 int sw_state_bmp_first; 94 int result_first; 95 int input_bmp_first; 96 int _range; 97 SHR_BITDCL *sw_state_bmp; 98 SHR_BITDCL *input_bmp; 99 SHR_BITDCL *result_bmp; 100 uint8 *bool_result; 101 uint8 *bit_result; 102 int *int_result; 103 SW_ST_BITDCL op; 104 uint32 flags; 105 } sw_state_bitdcl_param_t; 106 107 int shr_sw_state_bit_op(int unit, sw_state_bitdcl_param_t param); 108 109 #define SHR_SW_STATE_BIT_OP(unit, param)\ 110 SW_STATE_IF_ERR_EXIT(shr_sw_state_bit_op(unit, param)) 111 112 typedef uint8 SW_STATE_BUFF; 113 114 #define SHR_SW_STATE_IS_SMART_SYNC(unit) (0x0) 115 #define SHR_SW_STATE_MAX_DATA_SIZE_IN_BYTES (300000000) /* fall back to this size if stable_size soc property is not defined */ 116 /* reserve some scache space for legacy wb modules or Crash recovery journals */ 117 #define SHR_SW_STATE_SCACHE_RESERVE_SIZE (SOC_IS_JERICHO(unit) ? 55000000 : 20000000) 118 #define SHR_SW_STATE_MEMBER_NAME_MAX_LENGTH (128) 119 #define SHR_SW_STATE_SCACHE_CONTROL_SIZE (0x0) /* currently not using any control */ 120 #define SW_STATE_MAX_NOF_HASH_TABLES (100) /* in the future derive from some property ?*/ 121 #define SW_STATE_EFFICIENT_DUMP (0x1) /* ommit 00 and FF from sw state block dump */ 122 123 #ifdef BCM_WARM_BOOT_SUPPORT 124 #define SHR_SW_STATE_SCACHE_HANDLE_SET(_wb_handle, unit, _id)\ 125 SOC_SCACHE_HANDLE_SET(_wb_handle, unit, SOC_MODULE_SW_STATE, _id) 126 #else 127 #define SHR_SW_STATE_SCACHE_HANDLE_SET(_wb_handle, unit, _id) 128 #endif /*BCM_WARM_BOOT_SUPPORT*/ 129 130 #define SHR_SW_STATE_ALIGN_SIZE(size) \ 131 (size) = ((size) + 3) & (~3) 132 133 #define NOF_BITS_IN_BYTE 8 134 135 #define INIT_SW_STATE_MEM 136 #define DISPLAY_SW_STATE_MEM 137 #define DISPLAY_SW_STATE_MEM_PRINTF(x) 138 #ifdef BROADCOM_DEBUG 139 /* { */ 140 #ifndef __KERNEL__ 141 /* { */ 142 #ifdef SW_STATE_MEM_MONITOR 143 /* { */ 144 void 145 sw_state_alloc_resource_usage_get(unsigned int *alloc_curr, unsigned int *alloc_max); 146 void 147 sw_state_alloc_resource_usage_init(void) ; 148 #undef DISPLAY_SW_STATE_MEM 149 /* 150 * Display total memory allocated by shr_sw_state_alloc() so far and maximum 151 * allocated so far. 152 * Note that collection is initialized to zero in shr_sw_state_init() (See INIT_SW_STATE_MEM). 153 */ 154 #define DISPLAY_SW_STATE_MEM \ 155 { \ 156 uint32 alloc_curr ; \ 157 uint32 alloc_max ; \ 158 sw_state_alloc_resource_usage_get(&alloc_curr, &alloc_max) ; \ 159 sal_printf( \ 160 "\r\n" \ 161 "%s(),%d: Sw state memory consumers - curr/max %lu/%lu bytes\r\n\n", \ 162 __FUNCTION__,__LINE__,(unsigned long)alloc_curr,(unsigned long)alloc_max) ; \ 163 } 164 #undef INIT_SW_STATE_MEM 165 #define INIT_SW_STATE_MEM sw_state_alloc_resource_usage_init() ; 166 #undef DISPLAY_SW_STATE_MEM_PRINTF 167 #define DISPLAY_SW_STATE_MEM_PRINTF(x) sal_printf x ; 168 /* } */ 169 #endif 170 /* } */ 171 #endif 172 /* } */ 173 #endif 174 175 typedef enum shr_sw_state_data_block_init_mode_e { 176 socSwStateDataBlockRegularInit, 177 socSwStateDataBlockRestoreAndOveride 178 } shr_sw_state_init_mode_t; 179 180 181 182 typedef struct shr_sw_state_alloc_element_s { 183 uint32 ptr_offset; 184 uint8 *ptr_value; 185 } shr_sw_state_alloc_element_t; 186 187 188 /* a layout node represent an element of the struct. 189 * Therefore, it has a size: size of the element's type 190 it has an offset: position of the element in memory, relative to the struct memory position*/ 191 typedef struct shr_sw_state_ds_layout_node_s { 192 char name[50]; 193 int size; /* size of the struct */ 194 uint32 offset; /* offset of the element in the struct */ 195 int nof_pointer; 196 int array_sizes[2]; 197 char type[50]; 198 int first_child_node_index; 199 int last_child_node_index; 200 int next_brother_node_index; /* node index to the next brother. */ 201 } shr_sw_state_ds_layout_node_t; 202 203 204 typedef struct shr_sw_state_data_block_header_s { 205 uint8 is_init; 206 uint32 total_buffer_size; 207 shr_sw_state_alloc_element_t *ptr_offsets_sp; /* stack pointer */ 208 shr_sw_state_alloc_element_t *ptr_offsets_stack_base; 209 uint8 *data_ptr; 210 uint32 data_size; 211 uint8 *next_free_data_slot; 212 uint32 size_left; 213 uint32 nof_ds_layout_nodes; 214 uint32 nof_max_ds_layout_nodes; /* contains SW_STATE_LAYOUT_NOF_MAX_LAYOUT_NODES 215 nof_ds_layout_nodes contains the nof layout nodes for the current compilation. 216 nof_max_ds_layout_nodes (or SW_STATE_LAYOUT_NOF_MAX_LAYOUT_NODES) is nof layout nodes, not depending on compilation flags, 217 calculated by autocoder. */ 218 shr_sw_state_ds_layout_node_t *ds_layout_nodes; /* data structure layout node array */ 219 } shr_sw_state_data_block_header_t; 220 221 222 extern shr_sw_state_data_block_header_t *shr_sw_state_data_block_header[SOC_MAX_NUM_DEVICES]; 223 224 void _sw_state_access_debug_hook(int id); 225 int shr_sw_state_init(int unit, int flags, shr_sw_state_init_mode_t init_mode, uint32 size); 226 int shr_sw_state_deinit(int unit); 227 int shr_sw_state_alloc(int unit, uint8** ptr, uint32 size, uint32 flags, char* dbg_string); 228 int shr_sw_state_memcpy(int unit, uint8 *location, uint8 *input, uint32 length, uint32 flags); 229 int shr_sw_state_memcpy_general(int unit, uint8 *location, uint8 *input, uint32 length, uint32 flags, uint8 internal_use, uint8 is_ptr); 230 int shr_sw_state_memcpy_internal(int unit, uint8 *location, uint8 *input, uint32 length, uint32 flags); 231 int shr_sw_state_memcpy_ptr(int unit, uint8 *location, uint8 *input, uint32 length, uint32 flags); 232 int shr_sw_state_memset(int unit, uint8 *location, int input, uint32 length, uint32 flags); 233 int shr_sw_state_pbmp_operation(int unit, _shr_pbmp_t *path, SW_ST_PBMP op, _shr_pbmp_t *input_pbmp, 234 _shr_pbmp_t *output_pbmp, int input_port, int range, uint8 *result, 235 int *countr, char* buffer, uint32 flags, char *debug_string); 236 int shr_sw_state_free(int unit, uint8 *ptr, uint32 flags); 237 int shr_sw_state_data_block_free_restored_data(int unit); 238 int shr_sw_state_data_block_set(int unit, int start, int end, uint8 *data); 239 int shr_sw_state_data_block_get(int unit, int start, int end, uint8 *data); 240 int shr_sw_state_data_block_restored_get(int unit, int start, int end, uint8 *data); 241 int shr_sw_state_data_block_sync(int unit, int start, int end); 242 void shr_sw_state_block_dump(int unit, uint32 flags, char *file_name, char *mode); 243 int shr_sw_state_auto_sync(int unit, uint8* current_pointer_in_sw_state, int size); 244 int shr_sw_state_sizes_get(int unit, uint32* in_use, uint32* left); 245 int shr_sw_state_defrag(int unit, uint8*** old_ptr, uint32 flags); 246 int soc_sw_state_nof_allocations_get(void); 247 int shr_sw_state_allocated_size_get(int unit, uint8* ptr, uint32* allocated_size); 248 int shr_sw_state_shr_bitdcl_nof_bits_get(int unit, uint8 *ptr, uint32 *num_of_bits_allocated); 249 int shr_sw_state_shr_bitdcl_nof_bits_update(int unit, uint8 *ptr, uint32 num_of_bits, uint32 flags); 250 int shr_sw_state_shr_bitdcl_independent(CONST SHR_BITDCL *bits1, CONST SHR_BITDCL *bits2, 251 int bits1_first, int bits2_first, int range, shrbitdcl_op_t op,int *result); 252 int shr_sw_state_buff_independent(CONST SW_STATE_BUFF *sw_state_buff, CONST SW_STATE_BUFF *input_buff, 253 int _value, int _offset, unsigned int _len, sw_state_buff_op_t op, int *result); 254 #ifdef BCM_WARM_BOOT_API_TEST 255 void* sw_state_copy_endian_independent ( void* destination, const void* source, uint32 dst_size, uint32 src_size, uint32 size ); 256 #endif 257 #ifdef SW_STATE_ISSU_DIAG 258 int shr_sw_state_print_node(int unit, int node_idx,shr_sw_state_ds_layout_node_t *nodes_arr, 259 char* prefix); 260 #endif 261 262 #if !defined(BCM_WARM_BOOT_SUPPORT) 263 int shr_sw_state_no_wb_init(int unit); 264 int shr_sw_state_no_wb_deinit(int unit); 265 #endif 266 #endif /* _SHR_SW_STATE_H */