l2x.h (13427B)
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 * File: l2x.h 8 * Purpose: Draco L2X hardware table manipulation support 9 */ 10 11 #ifndef _L2X_H_ 12 #define _L2X_H_ 13 14 #include <sal/core/time.h> 15 #include <shared/avl.h> 16 #include <shared/bitop.h> 17 #include <soc/macipadr.h> 18 #include <soc/hash.h> 19 20 #ifdef BCM_XGS_SWITCH_SUPPORT 21 22 extern int _soc_l2x_cml_struct_alloc(int unit); 23 extern void _soc_l2x_cml_struct_free(int unit); 24 extern int soc_l2x_attach(int unit); 25 extern int soc_l2x_detach(int unit); 26 extern int soc_l2x_init(int unit); 27 28 extern int soc_l2x_entry_valid(int unit, l2x_entry_t *entry); 29 30 extern int soc_l2x_entry_compare_key(void *user_data, 31 shr_avl_datum_t *datum1, 32 shr_avl_datum_t *datum2); 33 extern int soc_l2x_entry_compare_all(void *user_data, 34 shr_avl_datum_t *datum1, 35 shr_avl_datum_t *datum2); 36 37 extern int soc_l2x_entry_dump(void *user_data, 38 shr_avl_datum_t *datum, 39 void *extra_data); 40 41 /* 42 * L2 hardware insert, delete, and lookup 43 */ 44 45 extern int soc_l2x_insert(int unit, l2x_entry_t *entry); 46 extern int soc_l2x_delete(int unit, l2x_entry_t *entry); 47 extern int soc_l2x_delete_all(int unit, int static_too); 48 extern int soc_l2x_port_age(int unit, soc_reg_t reg0, soc_reg_t reg1); 49 extern int soc_l2x_lookup(int unit, 50 l2x_entry_t *key, l2x_entry_t *result, 51 int *index); 52 53 #define SOC_L2X_INC_STATIC 0x00000001 54 #define SOC_L2X_NO_CALLBACKS 0x00000002 55 #define SOC_L2X_EXT_MEM 0x00000004 56 57 /* Modes by which delete can take place */ 58 #define SOC_L2X_NO_DEL 0 59 #define SOC_L2X_PORTMOD_DEL 1 60 #define SOC_L2X_VLAN_DEL 2 61 #define SOC_L2X_MAC_DEL 3 62 #define SOC_L2X_PORTMOD_VLAN_DEL 4 63 #define SOC_L2X_ALL_DEL 5 64 #define SOC_L2X_TRUNK_DEL 6 65 #define SOC_L2X_VFI_DEL 7 66 #define SOC_L2X_TRUNK_VLAN_DEL 8 67 68 #define SOC_L2X_FROZEN_WITH_LOCK 0 69 #define SOC_L2X_FROZEN_WITHOUT_LOCK 1 70 #define SOC_L2X_FROZEN 2 71 72 #define SOC_L2X_FREEZE_MODE_PORT_RECONFIGURE 0 73 #define SOC_L2X_FREEZE_MODE_GLOBAL_OVERRIDE 1 74 75 extern int soc_l2x_freeze_mode_set(int unit, int mode); 76 extern int soc_l2x_freeze_mode_get(int unit, int *mode); 77 #ifdef BCM_WARM_BOOT_SUPPORT 78 extern int soc_l2x_wb_scache_size_get(int unit, int *req_scache_size); 79 extern int soc_l2x_scache_sync(int unit, uint8 **scache_ptr); 80 extern int soc_l2x_reinit(int unit, uint8 **scache_ptr); 81 #endif /* BCM_WARM_BOOT_SUPPORT */ 82 extern int soc_l2x_sync_delete(int unit, uint32 *del_entry, int index, uint32 flags); 83 extern int _soc_l2x_sync_delete_by(int, uint32, uint32, uint16, uint32, int, 84 uint32, uint32); 85 extern int _soc_l2x_sync_replace(int unit, l2x_entry_t *l2x_match_data, 86 l2x_entry_t *l2x_match_mask, uint32 flags); 87 #ifdef BCM_TSN_SUPPORT 88 extern int soc_l2x_sr_ref_sync(int unit, int l2_index); 89 #endif /* BCM_TSN_SUPPORT */ 90 91 #define SOC_L2X_ENTRY_OVERFLOW 0x00000001 92 #define SOC_L2X_ENTRY_DUMMY 0x00000002 93 #define SOC_L2X_ENTRY_NO_ACTION 0x00000004 94 #define SOC_L2X_ENTRY_TSN_SR_FLOWSET_REF_CNT 0x00000008 95 #define SOC_L2X_ENTRY_DELETE 0x00000010 96 #define SOC_L2X_ENTRY_AGE 0x00000020 97 #define SOC_L2X_ENTRY_INSERT 0x00000040 98 #define SOC_L2X_ENTRY_LEARN 0x00000080 99 100 #ifdef BCM_TRIUMPH3_SUPPORT 101 /**************************************************************** 102 * 103 * L2 replace structure 104 */ 105 typedef struct _soc_tr3_l2_replace_dest_s { 106 soc_module_t module; 107 soc_port_t port; 108 trunk_id_t trunk; 109 int vp; 110 } _soc_tr3_l2_replace_dest_t; 111 112 typedef struct _soc_tr3_l2_replace_s { 113 uint32 flags; /* BCM_L2_REPLACE_XXX */ 114 int key_type; 115 int ext_key_type; 116 sal_mac_addr_t key_mac; 117 vlan_id_t key_vlan; 118 int key_vfi; 119 _soc_tr3_l2_replace_dest_t match_dest; 120 _soc_tr3_l2_replace_dest_t new_dest; 121 l2_bulk_entry_t match_data1; 122 l2_bulk_entry_t match_mask1; 123 l2_bulk_entry_t new_data1; 124 l2_bulk_entry_t new_mask1; 125 l2_bulk_entry_t match_data2; 126 l2_bulk_entry_t match_mask2; 127 l2_bulk_entry_t new_data2; 128 l2_bulk_entry_t new_mask2; 129 l2_bulk_entry_t ext_match_data1; 130 l2_bulk_entry_t ext_match_mask1; 131 l2_bulk_entry_t ext_new_data1; 132 l2_bulk_entry_t ext_new_mask1; 133 l2_bulk_entry_t ext_match_data2; 134 l2_bulk_entry_t ext_match_mask2; 135 l2_bulk_entry_t ext_new_data2; 136 l2_bulk_entry_t ext_new_mask2; 137 } _soc_tr3_l2_replace_t; 138 139 extern int soc_tr3_l2x_sync_delete(int unit, soc_mem_t mem, uint32 *del_entry, 140 int index, uint32 flags); 141 extern int _soc_tr3_l2x_sync_delete_by(int, uint32, uint32, uint16, uint32, int, 142 uint32, uint32); 143 extern int _soc_tr3_l2x_sync_replace(int unit, _soc_tr3_l2_replace_t *rep_st, 144 uint32 flags); 145 #endif 146 extern int soc_l2x_sync_delete_by_port(int unit, int mod, 147 soc_port_t port, uint32 flags); 148 extern int soc_l2x_sync_delete_by_trunk(int unit, 149 int tid, uint32 flags); 150 extern int soc_er_l2x_entries_external(int unit); 151 extern int soc_er_l2x_entries_internal(int unit); 152 extern int soc_er_l2x_entries_overflow(int unit); 153 154 extern int soc_l2x_mode_cfg_get(int unit); 155 /* 156 * Registration to receive inserts, deletes, and updates. 157 * For inserts, entry_del is NULL. 158 * For deletes, entry_ins is NULL. 159 * For updates, neither is NULL. 160 */ 161 162 typedef void (*soc_l2x_cb_fn)(int unit, 163 int flags, 164 l2x_entry_t *entry_del, 165 l2x_entry_t *entry_add, 166 void *fn_data); 167 #ifdef BCM_TRIDENT3_SUPPORT 168 typedef int (*soc_l2x_cml_cb_fn)(int unit, soc_port_t port, int save, 169 int *save_cml, int *save_cml_move); 170 extern int soc_l2x_cml_register(int unit, soc_l2x_cml_cb_fn fn); 171 #endif 172 extern int soc_l2x_register(int unit, soc_l2x_cb_fn fn, void *fn_data); 173 extern int soc_l2x_unregister(int unit, soc_l2x_cb_fn fn, void *fn_data); 174 175 #define soc_l2x_unregister_all(unit) \ 176 soc_l2x_unregister((unit), NULL, NULL) 177 178 extern void soc_l2x_callback(int unit, 179 int flags, 180 l2x_entry_t *entry_del, 181 l2x_entry_t *entry_add); 182 183 /* 184 * TR3 style l2 entry update callback structure and routine 185 */ 186 typedef union l2_entry_u { 187 uint32 words[SOC_MAX_MEM_WORDS]; 188 ext_l2_entry_1_entry_t ext_l2_entry_1; 189 ext_l2_entry_2_entry_t ext_l2_entry_2; 190 l2_entry_1_entry_t l2_entry_1; 191 l2_entry_2_entry_t l2_entry_2; 192 } l2_combo_entry_t; 193 194 typedef void (*soc_l2_entry_cb_fn)(int unit, uint32 flags, 195 soc_mem_t mem_type, 196 l2_combo_entry_t *entry_del, 197 l2_combo_entry_t *entry_add, 198 void *fn_data); 199 extern int soc_l2_entry_register(int unit, soc_l2_entry_cb_fn, void* fn_data); 200 extern int soc_l2_entry_unregister(int unit, soc_l2_entry_cb_fn, void* fn_data); 201 202 /* 203 * L2 miscellaneous functions 204 */ 205 extern void soc_age_timer_cache_set(int unit, int age_seconds, int enabled); 206 extern void soc_age_timer_cache_get(int unit,int *age_seconds,int *enabled); 207 extern int soc_l2x_selective_freeze(int unit, int hw_freeze); 208 extern int soc_l2x_selective_thaw(int unit, int hw_thaw); 209 extern int soc_l2x_freeze(int unit); 210 extern int soc_l2x_is_frozen(int unit, int hw_frozen, int *frozen); 211 extern int soc_l2x_thaw(int unit); 212 extern int soc_l2x_entries(int unit); /* Warning: very slow */ 213 extern int soc_l2x_hash(int unit, l2x_entry_t *entry); 214 215 extern int soc_l2x_frozen_cml_set(int unit, soc_port_t port, int cml, int cml_move, 216 int *repl_cml, int *repl_cml_move); 217 extern int soc_l2x_frozen_cml_get(int unit, soc_port_t port, int *cml, int *cml_move); 218 extern int _soc_l2x_frozen_cml_save(int unit); 219 extern int _soc_l2x_frozen_cml_restore(int unit); 220 extern void soc_l2x_cml_vp_bitmap_set(int unit, SHR_BITDCL *vp_bitmap); 221 222 extern void soc_tr3_l2_overflow_interrupt_handler(int unit); 223 extern int soc_tr3_l2_overflow_start(int unit); 224 extern int soc_tr3_l2_overflow_stop(int unit); 225 extern int soc_tr3_l2_overflow_entry_get(int unit, l2_combo_entry_t *entry, 226 soc_mem_t *mem_type); 227 228 extern void soc_l2_entry_callback(int unit, uint32 flags, soc_mem_t mem_type, 229 l2_combo_entry_t *entry_del, l2_combo_entry_t *entry_add); 230 231 extern void soc_td2_l2_overflow_interrupt_handler(int unit); 232 extern int soc_td2_l2_overflow_start(int unit); 233 extern int soc_td2_l2_overflow_stop(int unit); 234 235 /* 236 * L2X Thread 237 */ 238 239 #define SOC_L2X_INTERVAL_DEFAULT 3000000 240 241 extern int soc_l2x_start(int unit, uint32 flags, sal_usecs_t interval); 242 extern int soc_l2x_running(int unit, uint32 *flags, sal_usecs_t *interval); 243 extern int soc_l2x_stop(int unit); 244 extern int soc_td2_l2_bulk_age_start(int unit, int interval); 245 extern int soc_td2_l2_bulk_age_stop(int unit); 246 247 /* 248 * L2 software-based sanity routines 249 */ 250 251 #define SOC_L2X_BUCKET_SIZE 8 252 extern int soc_l2x_software_hash(int unit, int hash_select, 253 l2x_entry_t *entry); 254 255 /* 256 * Debugging features - for diagnostic purposes only 257 */ 258 259 extern void soc_l2x_key_dump(int unit, char *pfx, 260 l2x_entry_t *entry, char *sfx); 261 262 #endif /* BCM_XGS_SWITCH_SUPPORT */ 263 264 #ifdef BCM_FIREBOLT_SUPPORT 265 266 extern int soc_fb_l2x_bank_insert(int unit, uint8 banks, l2x_entry_t *entry); 267 extern int soc_fb_l2x_bank_delete(int unit, uint8 banks, l2x_entry_t *entry); 268 extern int soc_fb_l2x_bank_lookup(int unit, uint8 banks, l2x_entry_t *key, 269 l2x_entry_t *result, int *index_ptr); 270 271 extern int soc_fb_l2x_insert(int unit, l2x_entry_t *entry) ; 272 extern int soc_fb_l2x_delete(int unit, l2x_entry_t *entry); 273 extern int soc_fb_l2x_lookup(int unit, l2x_entry_t *key, 274 l2x_entry_t *result, int *index_ptr); 275 extern int soc_fb_l2x_delete_all(int unit); 276 277 /* 278 * We must use SOC_MEM_INFO here, because we may redefine the 279 * index_max due to configuration, but the SCHAN msg uses the maximum size. 280 */ 281 #define SOC_L2X_OP_FAIL_POS(unit) \ 282 ((_shr_popcount(SOC_MEM_INFO(unit, L2Xm).index_max) + \ 283 soc_mem_entry_bits(unit, L2Xm)) %32) 284 285 #endif /* BCM_FIREBOLT_SUPPORT */ 286 287 288 #define SOC_L2X_MEM_LOCK(unit)\ 289 if (soc_feature(unit, soc_feature_ism_memory)) {\ 290 soc_mem_lock(unit, L2_ENTRY_1m);\ 291 soc_mem_lock(unit, L2_ENTRY_2m);\ 292 } else { soc_mem_lock(unit, L2Xm); } 293 294 #define SOC_L2X_MEM_UNLOCK(unit)\ 295 if (soc_feature(unit, soc_feature_ism_memory)) {\ 296 soc_mem_unlock(unit, L2_ENTRY_2m);\ 297 soc_mem_unlock(unit, L2_ENTRY_1m);\ 298 } else { soc_mem_unlock(unit, L2Xm); } 299 300 #define SOC_EXT_L2X_MEM_LOCK(unit)\ 301 if (soc_feature(unit, soc_feature_esm_support)) {\ 302 if (soc_feature(unit, soc_feature_ism_memory)) {\ 303 soc_mem_lock(unit, EXT_L2_ENTRY_1m);\ 304 soc_mem_lock(unit, EXT_L2_ENTRY_2m);\ 305 }\ 306 } 307 308 #define SOC_EXT_L2X_MEM_UNLOCK(unit)\ 309 if (soc_feature(unit, soc_feature_esm_support)) {\ 310 if (soc_feature(unit, soc_feature_ism_memory)) {\ 311 soc_mem_unlock(unit, EXT_L2_ENTRY_2m);\ 312 soc_mem_unlock(unit, EXT_L2_ENTRY_1m);\ 313 }\ 314 } 315 316 /* The overflow indicator of the index of L2_ENTRY */ 317 #define SOC_L2X_GEN_RESP_INDEX_L2_OVERFLOW(unit) \ 318 ((SOC_IS_GREYHOUND2(unit)) ? 0x8000 : 0x4000) 319 320 321 /* 322 * L2 Mod Thread 323 */ 324 325 typedef enum l2x_mode_e { 326 L2MODE_POLL, 327 L2MODE_FIFO 328 } l2x_mode_t; 329 330 #define L2MOD_PASS_CPU 0x01 331 332 #if defined(BCM_TOMAHAWK3_SUPPORT) 333 /* Defines if L2 learning happens through interrupt mechanism provided by learn 334 * cache, or polling is used to get entries from learn cache (to learn) 335 */ 336 typedef enum soc_th3_l2x_lrn_mode_e { 337 L2_LRN_MODE_POLL = 1, 338 L2_LRN_MODE_INTR = 2 339 } soc_th3_l2x_lrn_mode_t; 340 #endif /* BCM_TOMAHAWK3_SUPPORT */ 341 342 extern int soc_l2mod_start(int unit, uint32 flags, sal_usecs_t interval); 343 extern int soc_l2mod_running(int unit, uint32 *flags, sal_usecs_t *interval); 344 extern int soc_l2mod_stop(int unit); 345 346 #ifdef BCM_TRIDENT2_SUPPORT 347 extern int soc_l2x_cml_override_is_enabled(int unit); 348 extern void _soc_td2_l2mod_fifo_process(int unit, uint32 flags, 349 l2_mod_fifo_entry_t *entry); 350 #endif /* BCM_TRIDENT2_SUPPORT */ 351 #ifdef BCM_KATANA2_SUPPORT 352 extern void _soc_kt_l2mod_fifo_process(int unit, uint32 flags, 353 l2_mod_fifo_entry_t *entry); 354 #endif 355 #ifdef BCM_HURRICANE2_SUPPORT 356 extern void _soc_hu2_l2mod_fifo_process(int unit, uint32 flags, 357 l2_mod_fifo_entry_t *entry); 358 #endif /* BCM_HURRICANE2_SUPPORT */ 359 #if defined(BCM_TOMAHAWK3_SUPPORT) 360 void soc_th3_l2x_reset_freeze_state(int unit); 361 #endif /* BCM_TOMAHAWK3_SUPPORT */ 362 363 #endif /* !_L2X_H_ */