xgs4.h (13359B)
1 /* 2 * 3 * 4 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 5 * 6 * Copyright 2007-2020 Broadcom Inc. All rights reserved. 7 */ 8 #ifndef __BCM_INT_XGS4_H__ 9 #define __BCM_INT_XGS4_H__ 10 11 #include <bcm/udf.h> 12 #include <bcm/field.h> 13 #include <bcm/types.h> 14 15 #include <soc/field.h> 16 #include <soc/mcm/memregs.h> 17 18 #include<sal/core/sync.h> 19 20 #define BCMI_XGS4_UDF_ID_MIN 0x1 21 #define BCMI_XGS4_UDF_ID_MAX 0xfffe 22 23 #define BCMI_XGS4_UDF_PKT_FORMAT_ID_MIN 0x1 24 #define BCMI_XGS4_UDF_PKT_FORMAT_ID_MAX 0xfffe 25 26 #define BCMI_XGS4_UDF_MAX_BYTE_SELECTION 128 27 28 #define BCMI_XGS4_UDF_INVALID_PIPE_NUM -1 29 /* Offset entry flags */ 30 #define BCMI_XGS4_UDF_OFFSET_ENTRY_GROUP 0x1 31 #define BCMI_XGS4_UDF_OFFSET_ENTRY_MEMBER 0x2 32 #define BCMI_XGS4_UDF_OFFSET_ENTRY_SHARED 0x4 33 #define BCMI_XGS4_UDF_OFFSET_ENTRY_HALF 0x8 34 35 /* Offset Support flags */ 36 #define BCMI_XGS4_UDF_CTRL_MODULE_INITIALIZED (1 << 1) 37 #define BCMI_XGS4_UDF_CTRL_OFFSET_ADJUST_IP4 (1 << 2) 38 #define BCMI_XGS4_UDF_CTRL_OFFSET_ADJUST_GRE (1 << 3) 39 40 #define BCMI_XGS4_UDF_CTRL_TCAM_HIGIG (1 << 4) 41 #define BCMI_XGS4_UDF_CTRL_TCAM_VNTAG (1 << 5) 42 #define BCMI_XGS4_UDF_CTRL_TCAM_ETAG (1 << 6) 43 #define BCMI_XGS4_UDF_CTRL_TCAM_ICNM (1 << 7) 44 #define BCMI_XGS4_UDF_CTRL_TCAM_CNTAG (1 << 8) 45 #define BCMI_XGS4_UDF_CTRL_TCAM_SUBPORT_TAG (1 << 9) 46 #define BCMI_XGS4_UDF_CTRL_FLEXHASH (1 << 10) 47 #define BCMI_XGS4_UDF_CTRL_POLICER_GROUP (1 << 11) 48 #define BCMI_XGS4_UDF_CTRL_UDFHASH (1 << 12) 49 #define BCMI_XGS4_UDF_CTRL_RANGE_CHECK (1 << 13) 50 #define BCMI_XGS4_UDF_PKT_FORMAT_CLASS_ID (1 << 14) 51 #define BCMI_XGS4_UDF_CONDITIONAL_CHECK (1 << 15) 52 #define BCMI_XGS4_UDF_CTRL_FLEX_COUNTER (1 << 16) 53 #define BCMI_XGS4_UDF_CTRL_L4_DST_PORT (1 << 17) 54 #define BCMI_XGS4_UDF_CTRL_OPAQUE_TAG_TYPE (1 << 18) 55 #define BCMI_XGS4_UDF_CTRL_INT_PKT (1 << 19) 56 #define BCMI_XGS4_UDF_CTRL_SRC_PORT (1 << 20) 57 #define BCMI_XGS4_UDF_CTRL_LB_PKT_TYPE (1 << 21) 58 59 60 /* TD2 - Offset Base */ 61 #define BCMI_XGS4_UDF_OFFSET_BASE_START_OF_MH (0) 62 #define BCMI_XGS4_UDF_OFFSET_BASE_START_OF_L2 (1) 63 #define BCMI_XGS4_UDF_OFFSET_BASE_START_OF_OUTER_L3 (2) 64 #define BCMI_XGS4_UDF_OFFSET_BASE_START_OF_INNER_L3 (3) 65 #define BCMI_XGS4_UDF_OFFSET_BASE_START_OF_L4 (4) 66 67 /* Offset entry flags */ 68 #define BCMI_XGS4_UDF_OFFSET_INSTALLED (1 << 0) 69 #define BCMI_XGS4_UDF_OFFSET_IFP (1 << 1) 70 #define BCMI_XGS4_UDF_OFFSET_VFP (1 << 2) 71 #define BCMI_XGS4_UDF_OFFSET_FLEXHASH (1 << 3) 72 #define BCMI_XGS4_UDF_OFFSET_POLICER (1 << 4) 73 #define BCMI_XGS4_UDF_OFFSET_UDFHASH (1 << 5) 74 #define BCMI_XGS4_UDF_OFFSET_UDFHASH_CONFIG (1 << 6) 75 #define BCMI_XGS4_UDF_OFFSET_RANGE_CHECK (1 << 7) 76 77 /* TD2 Maximums */ 78 #define MAX_UDF_TCAM_ENTRIES 512 79 #define MAX_UDF_OFFSET_CHUNKS 16 80 #define MAX_UDF_ID_LIST (MAX_UDF_OFFSET_CHUNKS*SOC_MAX_NUM_PIPES) 81 82 #define UDF_CTRL(u) udf_control[u] 83 #define UDF_CTRL_FLAGS(u) udf_control[u]->flags 84 85 #define BCMI_XGS4_UDF_ID_RUNNING(u) \ 86 (udf_control[u]->udf_id_running += \ 87 (udf_control[u]->udf_id_running > BCMI_XGS4_UDF_ID_MAX ? 0 : 1)) 88 #define BCMI_XGS4_UDF_PKT_FORMAT_ID_RUNNING(u) \ 89 (udf_control[u]->udf_pkt_format_id_running += \ 90 (udf_control[u]->udf_pkt_format_id_running > BCMI_XGS4_UDF_PKT_FORMAT_ID_MAX ? 0 : 1)) 91 92 #define BCMI_XGS4_UDF_CTRL_OFFSET_GRAN(u) udf_control[u]->gran 93 #define BCMI_XGS4_UDF_CTRL_MAX_UDF_CHUNKS(u) udf_control[u]->noffsets 94 #define BCMI_XGS4_UDF_CTRL_MAX_UDF_ENTRIES(u) udf_control[u]->nentries 95 96 #define BCMI_XGS4_UDF_OFFSET_INFO_SHARED 0x1 97 98 #define UDF_LOCK(u) sal_mutex_take((UDF_CTRL(u)->udf_mutex), sal_mutex_FOREVER); 99 #define UDF_UNLOCK(u) sal_mutex_give(UDF_CTRL(u)->udf_mutex); 100 101 /* Offset Chunk Granularity */ 102 #define UDF_OFFSET_GRAN2 0x2 103 #define UDF_OFFSET_GRAN4 0x4 104 105 /* No. of Offset Chunks */ 106 #define UDF_OFFSET_CHUNKS16 0x10 107 #define UDF_OFFSET_CHUNKS8 0x8 108 109 /* No. of bytes parsed in frame */ 110 #define UDF_PACKET_PARSE_LENGTH 0x80 111 112 /* Flags of udf used by module */ 113 #define UDF_USED_BY_NONE 0 114 #define UDF_USED_BY_UDF_MODULE 1 115 #define UDF_USED_BY_FIELD_MODULE 2 116 117 #if defined (BCM_TOMAHAWK3_SUPPORT) || defined (BCM_TOMAHAWK2_SUPPORT) 118 #define MPLS_LABEL_COUNT_WIDTH_FOR_UDF_L3_FIELDS (0x4) 119 #endif 120 121 /* User input UDF info structure and hardware offset map */ 122 typedef struct bcmi_xgs4_udf_offset_info_s { 123 bcm_udf_id_t udf_id; 124 bcm_udf_layer_t layer; 125 uint16 start; 126 uint16 width; 127 128 uint8 flags; 129 uint8 grp_id; /* First chunk when group of chunks in use */ 130 uint32 hw_bmap; /* HW bitmap : 1 bit for each chunk */ 131 uint32 byte_bmap; /* Byte granular bitmap: 2 bits for each chunk 132 * when gran is 2 and 4 bits for each chunk when 133 * gran is 4 134 */ 135 uint8 byte_offset; /* Data offset inside the word */ 136 int num_pkt_formats; /* Number of packet formats associated */ 137 138 bcm_pbmp_t associated_ports; /* Used to store bitmap provided */ 139 uint32 associated_pipe; /* used only in pipe local mode */ 140 141 struct bcmi_xgs4_udf_offset_info_s *next; 142 struct bcmi_xgs4_udf_offset_info_s *prev; 143 } bcmi_xgs4_udf_offset_info_t; 144 145 146 typedef struct bcmi_xgs4_udf_tcam_info_s { 147 bcm_udf_pkt_format_id_t pkt_format_id; /* Packet format ID */ 148 int priority; /* priority of the entry */ 149 uint32 offset_bmap; /* offset chunk bitmap */ 150 151 int hw_idx; /* TCAM index */ 152 fp_udf_tcam_entry_t hw_buf; /* UDF tcam buffer */ 153 int num_udfs; /* Number of UDFs associated */ 154 155 int class_id; /* class id used by IFP */ 156 int associated_pipe; /* used only in pipe local mode */ 157 158 /* Offset chunk bitmap per pipe */ 159 uint32 offset_bmap_per_pipe[SOC_MAX_NUM_PIPES]; 160 161 /* TCAM index per pipe */ 162 int hw_idx_per_pipe[SOC_MAX_NUM_PIPES]; 163 164 /* Number of UDFs associated per pipe */ 165 int num_udfs_per_pipe[SOC_MAX_NUM_PIPES]; 166 167 /* Associated pipes */ 168 int associated_pipes[SOC_MAX_NUM_PIPES]; 169 170 /* List of udfs associated */ 171 uint16 udf_id_list[MAX_UDF_ID_LIST]; 172 173 /* List of udfs associated - used in delete_all/get_all */ 174 struct bcmi_xgs4_udf_offset_info_s *offset_info_list[MAX_UDF_OFFSET_CHUNKS]; 175 176 struct bcmi_xgs4_udf_tcam_info_s *next; 177 struct bcmi_xgs4_udf_tcam_info_s *prev; 178 } bcmi_xgs4_udf_tcam_info_t; 179 180 181 typedef struct bcmi_xgs4_udf_tcam_entry_s { 182 int valid; /* Entry Valid/Installed */ 183 bcmi_xgs4_udf_tcam_info_t *tcam_info; /* Pointer to tcam info */ 184 } bcmi_xgs4_udf_tcam_entry_t; 185 186 typedef struct bcmi_xgs4_udf_offset_entry_s { 187 uint8 flags; /* BCMI_XGS4_UDF_OFFSET_ENTRY_XXX */ 188 uint8 grp_id; /* first chunk id in an offset group */ 189 uint8 num_udfs; /* Number of (shared) udfs using the offset chunk */ 190 uint8 num_pkt_formats; /* Num of pkt formats currently using */ 191 int associated_pipe; /* used only in PipeLocal Mode */ 192 } bcmi_xgs4_udf_offset_entry_t; 193 194 /* 195 * Typedef: 196 * _field_udf_bmp_t 197 * Purpose: 198 * Udf chunk bit map for tracking allocated chunks in UDF 1 and 2 199 */ 200 typedef struct bcmi_xgs4_udf_bmp_s { 201 SHR_BITDCL *w; 202 } bcmi_xgs4_udf_bmp_t; 203 204 #define _BCMI_UDF_BMP_FREE(bmp) sal_free((bmp).w) 205 #define _BCMI_UDF_BMP_ADD(bmp, ctr) SHR_BITSET(((bmp).w), (ctr)) 206 #define _BCMI_UDF_BMP_REMOVE(bmp, ctr) SHR_BITCLR(((bmp).w), (ctr)) 207 #define _BCMI_UDF_BMP_TEST(bmp, ctr) SHR_BITGET(((bmp).w), (ctr)) 208 209 210 typedef struct bcmi_xgs4_udf_ctrl_s { 211 soc_mem_t offset_mem; /* offset memory */ 212 soc_mem_t tcam_mem; /* tcam memory */ 213 sal_mutex_t udf_mutex; /* UDF lock */ 214 215 uint32 flags; /* misc. info */ 216 217 uint8 gran; /* UDF chunk granularity (in bytes) */ 218 uint8 noffsets; /* Number of offsets per entry */ 219 uint16 nentries; /* Number of entries in UDF table */ 220 221 uint16 max_udfs; /* Restrict max udfs (for WB) */ 222 223 uint16 num_udfs; /* Number of UDFs existing in the system */ 224 uint16 num_pkt_formats; /* Number of packet formats installed so far */ 225 226 uint16 max_parse_bytes; /* Restrict max byte selection */ 227 228 /* UDF & Packet format ID running trackers */ 229 uint16 udf_id_running; 230 uint16 udf_pkt_format_id_running; 231 232 uint32 hw_bmap; /* HW bitmap : 1 bit for each chunk */ 233 uint32 byte_bmap; /* Byte granular bitmap: 2 bits for each chunk 234 * when gran is 2 and 4 bits for each chunk when 235 * gran is 4 236 */ 237 uint32 hw_bmap_per_pipe[SOC_MAX_NUM_PIPES]; /* HW bitmap in pipeLocalMode */ 238 uint32 byte_bmap_per_pipe[SOC_MAX_NUM_PIPES];/* Byte bitmap in pipeLocalMode */ 239 240 uint8 udf_hash_1; /* udf hash chunk 1 */ 241 uint8 udf_hash_2; /* udf hash chunk 2 */ 242 243 uint32 udf_used_by_module; /* udf used by module: 244 0 - used by none module 245 1 - used by udf module 246 2 - used by field module */ 247 248 /* Pointers to tcam entry arrays used in global mode*/ 249 bcmi_xgs4_udf_tcam_entry_t *tcam_entry_array; 250 251 /* Pointers to tcam entry arrays used in pipe local mode*/ 252 bcmi_xgs4_udf_tcam_entry_t *tcam_entry_array_per_pipe[SOC_MAX_NUM_PIPES]; 253 254 /* Pointers to tcam/offset entry arrays */ 255 bcmi_xgs4_udf_offset_entry_t *offset_entry_array; 256 257 /* Pointers to tcam/offset entry arrays used in pipe local mode*/ 258 bcmi_xgs4_udf_offset_entry_t *offset_entry_array_per_pipe[SOC_MAX_NUM_PIPES]; 259 260 /* Pointers to tcam/offset nodes */ 261 bcmi_xgs4_udf_offset_info_t *offset_info_head; 262 bcmi_xgs4_udf_tcam_info_t *tcam_info_head; 263 264 /* number of udf qualfiers _bcmFieldQualifyData0~15 */ 265 bcmi_xgs4_udf_bmp_t udf_field_bmp[SOC_MAX_NUM_PIPES]; 266 int max_chunks; 267 268 } bcmi_xgs4_udf_ctrl_t; 269 270 /* UDF module initialized state */ 271 extern int _bcm_xgs_udf_init[BCM_MAX_NUM_UNITS]; 272 273 extern bcmi_xgs4_udf_ctrl_t *udf_control[BCM_MAX_NUM_UNITS]; 274 275 #define UDF_INIT_CHECK(unit) \ 276 do { \ 277 if (udf_control[unit] == NULL) { \ 278 return BCM_E_INIT; \ 279 } \ 280 } while(0) 281 282 283 /* Extern function declarations */ 284 extern int bcmi_xgs4_udf_init(int unit); 285 extern int bcmi_xgs4_udf_detach(int unit); 286 287 #ifdef BCM_WARM_BOOT_SUPPORT 288 extern int _bcm_esw_udf_scache_sync(int unit); 289 extern int bcmi_xgs4_udf_wb_sync(int unit); 290 #endif /* BCM_WARM_BOOT_SUPPORT */ 291 292 extern int bcmi_xgs4_udf_tcam_node_get(int unit, 293 bcm_udf_pkt_format_id_t pkt_format_id, 294 bcmi_xgs4_udf_tcam_info_t **cur); 295 296 extern int bcmi_xgs4_udf_offset_node_get(int unit, 297 bcm_udf_id_t udf_id, 298 bcmi_xgs4_udf_offset_info_t **cur); 299 300 extern int bcm_xgs4_udf_detach(int unit); 301 302 extern int bcm_xgs4_udf_init(int unit); 303 304 extern int bcmi_xgs4_udf_create(int unit, bcm_udf_alloc_hints_t *hints, 305 bcm_udf_t *udf_info, bcm_udf_id_t *udf_id); 306 307 extern int bcmi_xgs4_udf_get(int unit, 308 bcm_udf_id_t udf_id, bcm_udf_t *udf_info); 309 310 extern int bcmi_xgs4_udf_destroy(int unit, bcm_udf_id_t udf_id); 311 312 extern int bcmi_xgs4_udf_get_all(int unit, int max, 313 bcm_udf_id_t *udf_list, int *actual); 314 315 extern int bcmi_xgs4_udf_pkt_format_create(int unit, 316 bcm_udf_pkt_format_options_t options, 317 bcm_udf_pkt_format_info_t *pkt_format_info, 318 bcm_udf_pkt_format_id_t *pkt_format_id); 319 320 extern int bcmi_xgs4_udf_pkt_format_destroy(int unit, 321 bcm_udf_pkt_format_id_t pkt_format_id); 322 323 extern int bcmi_xgs4_udf_pkt_format_info_get(int unit, 324 bcm_udf_pkt_format_id_t pkt_format_id, 325 bcm_udf_pkt_format_info_t *pkt_format_info); 326 327 extern int bcmi_xgs4_udf_pkt_format_add(int unit, 328 bcm_udf_id_t udf_id, bcm_udf_pkt_format_id_t pkt_format_id); 329 330 extern int bcmi_xgs4_udf_pkt_format_delete(int unit, 331 bcm_udf_id_t udf_id, bcm_udf_pkt_format_id_t pkt_format_id); 332 333 extern int bcmi_xgs4_udf_pkt_format_delete_all(int unit, bcm_udf_id_t udf_id); 334 335 extern int bcmi_xgs4_udf_pkt_format_get(int unit, 336 bcm_udf_pkt_format_id_t pkt_format_id, 337 int max, bcm_udf_id_t *udf_id_list, int *actual); 338 339 extern int bcmi_xgs4_udf_pkt_format_get_all(int unit, 340 bcm_udf_id_t udf_id, int max, 341 bcm_udf_pkt_format_id_t *pkt_format_id_list, int *actual); 342 343 extern int bcmi_xgs4_udf_hash_config_add(int unit, 344 uint32 options, 345 bcm_udf_hash_config_t *config); 346 347 extern int bcmi_xgs4_udf_hash_config_delete(int unit, 348 bcm_udf_hash_config_t *config); 349 350 extern int bcmi_xgs4_udf_hash_config_delete_all(int unit); 351 352 extern int bcmi_xgs4_udf_hash_config_get(int unit, 353 bcm_udf_hash_config_t *config); 354 355 extern int bcmi_xgs4_udf_hash_config_get_all(int unit, 356 int max, 357 bcm_udf_hash_config_t *udf_hash_config_list, 358 int *actual); 359 360 #if defined (BCM_TOMAHAWK_SUPPORT) 361 extern int bcmi_xgs4_udf_oper_mode_set(int unit, 362 bcm_udf_oper_mode_t mode); 363 364 extern int bcmi_xgs4_udf_oper_mode_get(int unit, 365 bcm_udf_oper_mode_t *mode); 366 #endif 367 368 #endif /*BCM_XGS4_H*/