scache.h (8349B)
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 * This file contains structure and routine declarations for the 8 * storage cache management internal api. 9 * 10 * The scache is used to manage handles to persistent storage 11 */ 12 13 #ifndef _SOC_SCACHE_H_ 14 #define _SOC_SCACHE_H_ 15 #ifdef BCM_WARM_BOOT_SUPPORT 16 17 #include <shared/warmboot.h> 18 #include <soc/types.h> 19 #include <soc/defs.h> 20 21 #define SOC_DEFAULT_LVL2_STABLE_SIZE (1000 * 3072) 22 23 #define SOC_SCACHE_MEMCACHE_HANDLE 0xFF 24 #define SOC_SCACHE_SOC_DEFIP_HANDLE 0xFE 25 #define SOC_SCACHE_FLEXIO_HANDLE 0xFD 26 #define SOC_SCACHE_SERDES_HANDLE 0xFC 27 #define SOC_SCACHE_SOC_OVERLAY_TCAM_HANDLE 0xFB 28 #define SOC_SCACHE_PHYSIM_HANDLE 0xFA 29 #define SOC_SCACHE_SOC_SAT_HANDLE 0xF9 30 #define SOC_SCACHE_TDM_HANDLE 0xF8 31 #define SOC_SCACHE_DICTIONARY_HANDLE 0xF7 32 #define SOC_SCACHE_CANCUN_HANDLE 0xF6 33 #define SOC_SCACHE_DNXC_SW_STATE 0xF5 34 35 #define SOC_SCACHE_SWITCH_CONTROL 0xFC 36 #define SOC_SCACHE_SWITCH_CONTROL_PART0 0x0 37 38 /* The definition is only used for memory allocation when scache synchronization. 39 Based on current implmentation, the size needed is less than 2 times of 40 the largest scache buff */ 41 #define SOC_SCACHE_MAX_ALLOC_MULTIPLIER 2 42 43 #ifndef SCACHE_PHASE1_UPGRADE_COMPLETE 44 /* upgrade: temporary - shd be removed when scache upgrade is complete */ 45 46 #define SOC_STABLE_BASIC 0x00000001 47 #define SOC_STABLE_FIELD 0x00000002 48 #define SOC_STABLE_MPLS 0x00000004 49 #define SOC_STABLE_MULTICAST 0x00000008 50 51 #define SOC_STABLE_CORRUPT 1 52 #define SOC_STABLE_STALE 2 53 54 #define SOC_STABLE_FLAGS(unit) (soc_stable_tmp_flags_get(unit)) 55 #define SOC_WARM_BOOT_SCACHE_IS_LIMITED(unit) \ 56 (SOC_STABLE_FLAGS(unit) & SOC_STABLE_BASIC) 57 #endif 58 59 /* 60 * Read function signature to register for the application provided 61 * stable for Level 2 Warm Boot 62 */ 63 typedef int (*soc_read_func_t)( 64 int unit, 65 uint8 *buf, 66 int offset, 67 int nbytes); 68 69 /* 70 * Write function signature to register for the application provided 71 * stable for Level 2 Warm Boot 72 */ 73 typedef int (*soc_write_func_t)( 74 int unit, 75 uint8 *buf, 76 int offset, 77 int nbytes); 78 79 #define SOC_SCACHE_MAX_MODULES 256 80 81 extern int scache_max_partitions[SOC_MAX_NUM_DEVICES][SOC_SCACHE_MAX_MODULES]; 82 83 /* 84 * Set the maximum number of partitions used in scache for a module 85 */ 86 87 #define SOC_SCACHE_MODULE_MAX_PARTITIONS_SET(unit, module, partitions) \ 88 (scache_max_partitions[unit][module] > partitions) ? \ 89 0: (scache_max_partitions[unit][module] = partitions) 90 91 #define SOC_SCACHE_MODULE_MAX_PARTITIONS_GET(unit, module, partitions) \ 92 (*partitions = scache_max_partitions[unit][module]) 93 94 95 /* 96 * [De]Allocator function signatures to register for the application provided 97 * stable for Level 2 Warm Boot. The allocator function is called for each 98 * new cache handle allocated by the SDK. This buffer is used for persistent 99 * storage synchronization. Access to it is protected by an internal lock. 100 * When a commit occurs, this buffer is passed to the read/write functions 101 * registered with the stable. 102 */ 103 typedef void * (*soc_alloc_func_t) (uint32 sz); 104 typedef void (*soc_free_func_t) (void *p); 105 106 /* Register read/write and alloc/free interfaces with the scache. 107 * if alloc_f is null, sal_alloc used; 108 * if free_f is null, sall_free is used. 109 */ 110 extern int soc_switch_stable_register(int unit, soc_read_func_t rf, 111 soc_write_func_t wf, 112 soc_alloc_func_t alloc_f, 113 soc_free_func_t free_f); 114 extern int soc_stable_attach(int unit); 115 extern int soc_stable_set(int unit, int arg, uint32 flags); 116 extern int soc_stable_get(int unit, int *arg, uint32 *flags); 117 extern int soc_stable_size_update(int unit, int arg); 118 extern int soc_stable_size_set(int unit, int arg); 119 extern int soc_stable_size_get(int unit, int *arg); 120 extern int soc_stable_used_get(int unit, int *arg); 121 extern int soc_scache_handle_used_set(int unit, soc_scache_handle_t handle, uint32 arg); 122 extern int soc_scache_handle_used_get(int unit, soc_scache_handle_t handle, uint32 *arg); 123 124 #ifndef SCACHE_PHASE1_UPGRADE_COMPLETE 125 /* upgrade: temporary - shd be removed when scache upgrade is complete */ 126 typedef enum { 127 sf_index_min, sf_index_max 128 } soc_stable_field_t; 129 130 extern int soc_stable_tmp_access(int unit, soc_stable_field_t field, 131 uint32 *val, int get); 132 extern int soc_stable_tmp_flags_get(int unit); 133 #endif /* SCACHE_PHASE1_UPGRADE_COMPLETE */ 134 135 136 #define SOC_SCACHE_HANDLE_SET(_handle_, _unit_, _module_, _sequence_) \ 137 _SHR_SCACHE_HANDLE_SET(_handle_, _unit_, _module_, _sequence_) 138 139 #define SOC_SCACHE_HANDLE_UNIT_GET(_handle_) \ 140 _SHR_SCACHE_HANDLE_UNIT_GET(_handle_) 141 142 #define SOC_SCACHE_HANDLE_MODULE_GET(_handle_) \ 143 _SHR_SCACHE_HANDLE_MODULE_GET(_handle_) 144 145 #define SOC_SCACHE_HANDLE_SEQUENCE_GET(_handle_) \ 146 _SHR_SCACHE_HANDLE_SEQUENCE_GET(_handle_) 147 148 #define SOC_SCACHE_ALIGN_SIZE(size) \ 149 (size) = ((size) + 3) & (~3) 150 151 /* scache warm boot versioning */ 152 #define SOC_SCACHE_VERSION(major_, minor_) _SHR_SCACHE_VERSION(major_, minor_) 153 #define SOC_SCACHE_VERSION_MAJOR(v_) _SHR_SCACHE_VERSION_MAJOR(v_) 154 #define SOC_SCACHE_VERSION_MINOR(v_) _SHR_SCACHE_VERSION_MINOR(v_) 155 156 /* A common scache layout for warm boot */ 157 typedef _shr_wb_cache_t soc_wb_cache_t; 158 159 /* Size of scache used by control data */ 160 #define SOC_WB_SCACHE_CONTROL_SIZE _SHR_WB_SCACHE_CONTROL_SIZE 161 162 /* get the size of the caller usable scache, 163 * size of _shr_wb_cache_t->scache 164 */ 165 #define SOC_WB_SCACHE_SIZE(raw_size_) _SHR_WB_SCACHE_SIZE(raw_size_) 166 167 /* global scache operations */ 168 #ifdef CRASH_RECOVERY_SUPPORT 169 extern int soc_stable_sanity(int unit); 170 #endif 171 172 extern int soc_scache_handle_state_dirty_flag_set(int unit); 173 extern int soc_scache_init(int unit, uint32 size, uint32 flags); 174 extern int soc_scache_detach(int unit); 175 extern int soc_scache_recover(int unit); 176 extern int soc_scache_commit_handle(int unit, soc_scache_handle_t handle, uint32 flags); 177 extern int soc_scache_commit(int unit); 178 extern int soc_scache_is_config(int unit); 179 extern int soc_scache_commit_specific_data(int unit, soc_scache_handle_t handle, uint32 data_size, uint8 *data, int offset); 180 extern int soc_scache_partial_commit(int unit, soc_scache_handle_t handle, uint32 offset, uint32 length); 181 182 extern int soc_scache_hsbuf_crc32_append(int unit, soc_scache_handle_t handle_id); 183 184 /* per-handle based operations */ 185 extern int soc_scache_alloc(int unit, soc_scache_handle_t handle, uint32 size); 186 extern int soc_scache_realloc(int unit, soc_scache_handle_t handle, int32 size); 187 extern int soc_scache_ptr_get(int unit, soc_scache_handle_t handle, 188 uint8 **ptr, uint32 *size); 189 extern void soc_scache_info_dump(int unit); 190 extern int soc_scache_handle_lock(int unit, soc_scache_handle_t handle); 191 extern int soc_scache_handle_unlock(int unit, soc_scache_handle_t handle); 192 extern int soc_scache_module_max_alloc (int unit, uint8 **ptr, int *part_size); 193 extern int soc_scache_module_dirty_set (int unit, int module, uint8 **ptr, 194 int min_part, int max_part); 195 extern int soc_scache_module_data_backup (int unit, int module, uint8 **ptr, 196 int min_part, int max_part,int backup_size); 197 198 extern int 199 soc_versioned_scache_ptr_get(int unit, soc_scache_handle_t handle, int create, 200 uint32 *size, uint8 **scache_ptr, 201 uint16 default_ver, uint16 *recovered_ver); 202 203 extern int soc_extended_scache_ptr_get(int unit, 204 soc_scache_handle_t handle, 205 int create, 206 uint32 size, 207 uint8 **scache_ptr); 208 209 extern void soc_scache_dump_state(int unit); 210 211 #if (defined(BCM_PETRA_SUPPORT) || defined(BCM_DNX_SUPPORT) || defined(BCM_DNXF_SUPPORT)) && !defined(__KERNEL__) && (defined(LINUX) || defined(UNIX)) 212 extern uint8 soc_scache_is_shmem(int unit); 213 #endif 214 215 #endif /* BCM_WARM_BOOT_SUPPORT */ 216 #endif /* _SOC_SCACHE_H_ */