flowtracker.h (17401B)
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-2020 Broadcom Inc. All rights reserved. 6 * 7 * File: flowtracker.h 8 * Purpose: 9 */ 10 #ifndef _BCM_INT_FLOWTRACKER_H_ 11 #define _BCM_INT_FLOWTRACKER_H_ 12 13 #if defined(INCLUDE_FLOWTRACKER) 14 15 #include <soc/shared/ft.h> 16 #include <soc/shared/ft_msg.h> 17 #include <soc/profile_mem.h> 18 #include <shared/idxres_fl.h> 19 #include <bcm/flowtracker.h> 20 21 /* Group Start Id */ 22 #define BCM_INT_FT_GROUP_START_ID 1 23 24 /* Maximum number of flow groups 25 * TH/TH2 - IFP is used for FT Group hence restricted by MATCHED_RULE 8 bit 26 * value in COPY_TO_CPU functionality. 27 * MV2 - Equal to number of entries in FT_GROUP_TABLE_CONFIGm minus entry 28 * with index 0 which is reserved entry. 29 */ 30 #define BCM_INT_FT_MAX_FLOW_GROUPS \ 31 (soc_feature(unit, soc_feature_mv2_style_flowtracker) ? \ 32 (soc_mem_index_count(unit, FT_GROUP_TABLE_CONFIGm) - 1) : \ 33 255) 34 35 /* Default value for max flows */ 36 #define BCM_INT_FT_DEF_MAX_FLOWS \ 37 soc_feature(unit, soc_feature_mv2_style_flowtracker) ? 32768 : 16384 38 39 /* Default value for max counters per flow */ 40 #define BCM_INT_FT_DEF_MAX_COUNTERS_PER_FLOW 1 41 42 /* Default max export length is 1500 bytes */ 43 #define BCM_INT_FT_DEF_MAX_EXPORT_LENGTH 1500 44 45 /* Maximum number of templates */ 46 #define BCM_INT_FT_MAX_TEMPLATES 3 47 48 /* Template start Id */ 49 #define BCM_INT_FT_TEMPLATE_START_ID 1 50 51 /* Template end Id */ 52 #define BCM_INT_FT_TEMPLATE_END_ID \ 53 (BCM_INT_FT_TEMPLATE_START_ID + BCM_INT_FT_MAX_TEMPLATES - 1) 54 55 /* Maximum number of collectors. */ 56 #define BCM_INT_FT_MAX_COLLECTORS 1 57 58 /* Collector Start Id */ 59 #define BCM_INT_FT_COLLECTOR_START_ID 1 60 61 /* Collector End Id */ 62 #define BCM_INT_FT_COLLECTOR_END_ID \ 63 (BCM_INT_FT_COLLECTOR_START_ID + BCM_INT_FT_MAX_COLLECTORS - 1) 64 65 /* Maximum number of export_profiles. */ 66 #define BCM_INT_FT_MAX_EXPORT_PROFILES 1 67 68 /* Export_Profile Start Id */ 69 #define BCM_INT_FT_EXPORT_PROFILE_START_ID 1 70 71 /* Export_Profile End Id */ 72 #define BCM_INT_FT_EXPORT_PROFILE_END_ID \ 73 (BCM_INT_FT_EXPORT_PROFILE_START_ID + BCM_INT_FT_MAX_EXPORT_PROFILES - 1) 74 75 /* Valid range of Set_ID is 256 to 65535. 76 * Not checking 65535 condition since its satisfied 77 * by the fact that set_id is uint16 78 */ 79 #define BCM_INT_FT_TEMPLATE_SET_ID_VALID(set_id) (set_id >=256) 80 81 /* Set Id used when transmiting template sets */ 82 #define FT_INT_TEMPLATE_XMIT_SET_ID 2 83 84 /* Default value of export interval in elephant mode. 50 ms */ 85 #define BCM_INT_FT_ELPH_DEF_EXPORT_INTERVAL_MSECS (50) 86 87 /* Default value of export interval. 100 ms */ 88 #define BCM_INT_FT_DEF_EXPORT_INTERVAL_MSECS (100) 89 90 /* Default value of scan interval. 100 ms */ 91 #define BCM_INT_FT_DEF_SCAN_INTERVAL_USECS (BCM_INT_FT_DEF_EXPORT_INTERVAL_MSECS * 1000) 92 93 /* Default value of scan interval. 100 ms */ 94 #define BCM_INT_FT_ELPH_DEF_SCAN_INTERVAL_USECS (100 * 1000) 95 96 /* Minimum value of scan interval (2msec) */ 97 #define BCM_INT_FT_ELPH_MIN_SCAN_INTERVAL_USECS (2 * 1000) 98 99 /* Elephant Scan interval must be in steps of 1 msec */ 100 #define BCM_INT_FT_ELPH_SCAN_INTERVAL_STEP_USECS (1 * 1000) 101 102 /* Scan interval must be in steps of 1 msec */ 103 #define BCM_INT_FT_SCAN_INTERVAL_STEP_USECS (1 * 1000) 104 105 /* Max value of scan interval. 500 ms */ 106 #define BCM_INT_FT_MAX_SCAN_INTERVAL_USECS (500 * 1000) 107 108 /* Default value of aging time. 20 secs in milliseconds */ 109 #define BCM_INT_FT_DEF_AGING_INTERVAL_MSECS (20 * 1000) 110 111 /* Aging interval must be in steps of 1 sec */ 112 #define BCM_INT_FT_AGING_INTERVAL_STEP_MSECS (1000) 113 114 /* Aging interval can be up to 255 times scan interval */ 115 #define BCM_INT_FT_AGING_INTERVAL_SCAN_MULTIPLE (255) 116 117 /* Size of the template set header */ 118 #define BCM_INT_FT_SET_HDR_LENGTH 4 119 120 /* Size of the IPFIX header */ 121 #define BCM_INT_FT_IPFIX_MSG_HDR_LENGTH 16 122 123 /* Minimum length of the collecotor encap 124 * UDP_HDR = 8 bytes 125 * IPv4_HDR = 20 bytes 126 * ETH_HDR = 14 bytes 127 * L2_CRC = 4 bytes 128 * 8 + 20 + 14 + 4 = 46 129 */ 130 #define BCM_INT_FT_MIN_COLLECTOR_ENCAP_LENGTH 46 131 132 /* Length of the L2 CRC field */ 133 #define BCM_INT_FT_L2_CRC_LENGTH 4 134 135 /* Rx channel index used by FT EAPP */ 136 #define BCM_INT_FT_EAPP_RX_CHANNEL 1 137 138 /* Maximum number of elephant profiles */ 139 #define BCM_INT_FT_MAX_ELEPHANT_PROFILES 4 140 141 /* Elephant rate thresholds must be configured in steps of 80 kbits/sec */ 142 #define BCM_INT_FT_ELPH_RATE_THRESHOLD_STEP 80 143 144 /* Elephant profile Start Id */ 145 #define BCM_INT_FT_ELPH_PROFILE_START_ID 1 146 147 /* Elephant profile END Id */ 148 #define BCM_INT_FT_ELPH_PROFILE_END_ID \ 149 (BCM_INT_FT_ELPH_PROFILE_START_ID + BCM_INT_FT_MAX_ELEPHANT_PROFILES - 1) 150 151 /* Max number of actions that can be applied on a group */ 152 #define BCM_INT_FT_MAX_GROUP_ACTIONS 5 153 154 /* Max number of params per action */ 155 #define BCM_INT_FT_MAX_GROUP_ACTION_PARAMS 2 156 157 /* Invalid EM group Id */ 158 #define BCM_INT_FT_INVALID_EM_GROUP_ID (-1) 159 160 /* Maximum number of congestion monitor flows */ 161 #define BCM_INT_QCM_FT_MAX_FLOWS 1000 162 163 /* Maximum number of congestion monitor flow groups */ 164 #define BCM_INT_QCM_FT_MAX_FLOW_GROUPS 15 165 166 /* Invalid FW core */ 167 #define BCM_INT_FT_INVALID_FW_CORE (-1) 168 169 /* 170 * Macro: 171 * _BCM_FT_ALLOC 172 * Purpose: 173 * Generic memory allocation routine. 174 * Parameters: 175 * _ptr_ - Pointer to allocated memory. 176 * _ptype_ - Pointer type. 177 * _size_ - Size of heap memory to be allocated. 178 * _descr_ - Information about this memory allocation. 179 */ 180 #define _BCM_FT_ALLOC(_ptr_,_ptype_,_size_,_descr_) \ 181 do { \ 182 if (NULL == (_ptr_)) { \ 183 (_ptr_) = (_ptype_ *) sal_alloc((_size_), (_descr_)); \ 184 } \ 185 if((_ptr_) != NULL) { \ 186 sal_memset((_ptr_), 0, (_size_)); \ 187 } else { \ 188 LOG_ERROR(BSL_LS_BCM_FLOWTRACKER, \ 189 (BSL_META("FT Error: Allocation failure %s\n"), \ 190 (_descr_))); \ 191 } \ 192 } while (0) 193 194 /* Max number of parts the actions is divided in H/w */ 195 #define BCM_INT_FT_ACTION_MAX_PARTS 2 196 197 /* Minimum of 2 values */ 198 #define _BCM_FT_MIN(a,b) ((a) < (b) ? (a) : (b)) 199 200 201 /* Group actions width, offset linked list */ 202 typedef struct _bcm_int_ft_action_offset_s { 203 /* Offset into the H/w buffer */ 204 uint16 offset[BCM_INT_FT_ACTION_MAX_PARTS]; 205 206 /* Width of the action*/ 207 uint8 width[BCM_INT_FT_ACTION_MAX_PARTS]; 208 209 /* Value that needs to be programmed */ 210 uint8 value[BCM_INT_FT_ACTION_MAX_PARTS]; 211 212 } _bcm_int_ft_action_offset_t; 213 214 /* Flowtracker Internal action types */ 215 typedef enum _bcm_ft_action_e { 216 /* Change color of green packets */ 217 _bcmIntFtActionGpDropPrecedence = 0, 218 219 /* Change color of yellow packets */ 220 _bcmIntFtActionYpDropPrecedence = 1, 221 222 /* Change color of red packets */ 223 _bcmIntFtActionRpDropPrecedence = 2, 224 225 /* Assign new Unicast cosq for Green packets */ 226 _bcmIntFtActionGpUcastCosQNew = 3, 227 228 /* Assign new Unicast cosq for Yellow packets */ 229 _bcmIntFtActionYpUcastCosQNew = 4, 230 231 /* Assign new Unicast cosq for Red packets */ 232 _bcmIntFtActionRpUcastCosQNew = 5, 233 234 /* Assign new Multicast cosq for Green packets */ 235 _bcmIntFtActionGpMcastCosQNew = 6, 236 237 /* Assign new Multicast cosq for Yellow packets */ 238 _bcmIntFtActionYpMcastCosQNew = 7, 239 240 /* Assign new Multicast cosq for Red packets */ 241 _bcmIntFtActionRpMcastCosQNew = 8, 242 243 /* Assign new Unicast & Multicast cosq for Green packets */ 244 _bcmIntFtActionGpCosQNew = 9, 245 246 /* Assign new Unicast & Multicast cosq for Yellow packets */ 247 _bcmIntFtActionYpCosQNew = 10, 248 249 /* Assign new Unicast & Multicast cosq for Red packets */ 250 _bcmIntFtActionRpCosQNew = 11, 251 252 /* Change int_pri for Green packets */ 253 _bcmIntFtActionGpPrioIntNew = 12, 254 255 /* Change int_pri for Yellow packets */ 256 _bcmIntFtActionYpPrioIntNew = 13, 257 258 /* Change int_pri for Red packets */ 259 _bcmIntFtActionRpPrioIntNew = 14, 260 261 /* First Seen INT Packet */ 262 _bcmIntFtFspReinjectActionIntNew = 15, 263 264 /* Monitor flows Dropped packet */ 265 _bcmIntFtDropMonitorActionIntNew = 16, 266 267 /* Congestion Monitor flows */ 268 _bcmIntFtCongestionMonitorActionIntNew = 17, 269 270 /* Last value, not usable */ 271 _bcmIntFtActionCount 272 } _bcm_ft_action_t; 273 274 /* Actions info internal */ 275 typedef struct _bcm_int_ft_action_info_s { 276 /* Action element */ 277 _bcm_ft_action_t action; 278 279 /* param0 */ 280 uint32 param0; 281 282 } _bcm_int_ft_action_info_t; 283 284 /* Group actions info */ 285 typedef struct _bcm_int_ft_group_action_info_s { 286 /* Action */ 287 bcm_flowtracker_group_action_t action; 288 289 /* Number of params */ 290 int num_params; 291 292 /* Params */ 293 uint32 params[BCM_INT_FT_MAX_GROUP_ACTION_PARAMS]; 294 } _bcm_int_ft_group_action_info_t; 295 296 /* Per pipe information. */ 297 typedef struct _bcm_int_ft_pipe_info_s { 298 /* Max flows */ 299 uint32 max_flows; 300 301 /* Size of reserved pools */ 302 uint16 ctr_pool_size[SHR_FT_MAX_CTR_POOLS]; 303 304 /* Reserved Flex counter pools per pipe */ 305 uint8 ctr_pools[SHR_FT_MAX_CTR_POOLS]; 306 307 /* Number of reserved counter pools */ 308 uint8 num_ctr_pools; 309 310 /* QoS profile mem ptr */ 311 soc_profile_mem_t *qos_profile_mem; 312 } _bcm_int_ft_pipe_info_t; 313 314 #define BCM_INT_FT_INFO_FLAGS_FLOW_START_TS (1 << 0) 315 #define BCM_INT_FT_INFO_FLAGS_DROP_MONITOR (1 << 1) 316 #define BCM_INT_FT_INFO_FLAGS_HOSTMEM_ENABLE (1 << 2) 317 #define BCM_INT_FT_INFO_FLAGS_DROP_CONGESTION_MONITOR (1 << 3) 318 319 /* Internal data structure to store 320 * global flowtracker information. 321 */ 322 typedef struct _bcm_int_flowtracker_info_s { 323 /* uController number running FT appl */ 324 int uc_num; 325 /* Elephant mode */ 326 uint8 elph_mode; 327 328 /* Flow Tracker Config Mode */ 329 uint8 ft_config_mode; 330 331 /* Configuration mode */ 332 shr_ft_cfg_modes_t cfg_mode; 333 334 /* Features supported by the EApp */ 335 uint32 uc_features; 336 337 /* flags, See BCM_INT_FT_INFO_FLAGS_XXX */ 338 uint32 flags; 339 340 /* Max number of flow groups. 341 * Got from soc property flowtracker_max_flow_groups 342 */ 343 uint32 max_flow_groups; 344 /* Max number of flows for entire switch. 345 * Just a summation of max_flows_per_pipe for all pipes. 346 */ 347 uint32 max_flows_total; 348 /* The maximum MTU size that is possible for export 349 * packets. 350 * Got from soc property flowtracker_max_export_pkt_length 351 */ 352 uint16 max_export_pkt_length; 353 /* IPFIX observation domain Id */ 354 bcm_flowtracker_ipfix_observation_domain_t observation_domain_id; 355 /* DMA Buffer used for messaging between SDK and 356 * UKERNEL. 357 */ 358 uint8 *dma_buffer; 359 /* Length of the DMA buffer */ 360 int dma_buffer_len; 361 /* Template ID pool */ 362 shr_idxres_list_handle_t template_pool; 363 /* Collector ID pool */ 364 shr_idxres_list_handle_t collector_pool; 365 /* Export profile ID pool */ 366 shr_idxres_list_handle_t export_profile_pool; 367 /* Flow group ID pool */ 368 shr_idxres_list_handle_t flow_group_pool; 369 /* Flow group ID pool */ 370 shr_idxres_list_handle_t elph_profile_pool; 371 /* Number of pipes. */ 372 uint8 num_pipes; 373 /* Per pipe information. */ 374 _bcm_int_ft_pipe_info_t pipe_info[BCM_PIPES_MAX]; 375 376 /* Enterprise Number */ 377 uint32 enterprise_number; 378 379 /* Export interval (msecs) */ 380 uint32 export_interval; 381 382 /* Scan interval (usecs) */ 383 uint32 scan_interval_usecs; 384 385 /* Maximum length of the reinjected FSP packet */ 386 uint16 fsp_reinject_max_length; 387 388 /* Default group ID */ 389 uint16 default_grp_id; 390 391 /* Number of templates configured */ 392 uint16 num_templates; 393 394 /* EM groups Mapping */ 395 int em_group_id_map[SHR_FT_MAX_EM_GROUPS][BCM_PIPES_MAX]; 396 397 } _bcm_int_ft_info_t; 398 399 400 /* Internal data structure to store the information element data, used in 401 * template set export 402 */ 403 typedef struct _bcm_int_ft_info_elem_s { 404 /* Export element */ 405 shr_ft_template_info_elem_t element; 406 407 /* Size of each element */ 408 uint16 data_size; 409 410 /* Id corresponding to the export element, IANA assigned for 411 * non-enterprise 412 */ 413 uint16 id; 414 415 /* 1 - Enterprise element, 0 - Non enterprise element */ 416 uint8 enterprise; 417 } _bcm_int_ft_export_element_t; 418 419 /* Internal data structure to store per export template 420 * information. 421 */ 422 typedef struct _bcm_int_ft_export_template_info_s { 423 /* Software ID of the template */ 424 bcm_flowtracker_export_template_t template_id; 425 /* Set ID that is put into the IPFIX packet */ 426 uint16 set_id; 427 /* Template set transmit interval */ 428 int interval_secs; 429 /* Number of packets sent out initially */ 430 int initial_burst; 431 /* Number of information elements */ 432 int num_export_elements; 433 /* Export elements */ 434 _bcm_int_ft_export_element_t elements[SHR_FT_TEMPLATE_MAX_INFO_ELEMENTS]; 435 } _bcm_int_ft_export_template_info_t; 436 437 438 /* Internal data structure to store per collector information 439 */ 440 typedef struct _bcm_int_ft_collector_info_s { 441 /* Software ID of the collector */ 442 bcm_flowtracker_collector_t collector_id; 443 /* Collector information structure */ 444 bcm_flowtracker_collector_info_t collector_info; 445 } _bcm_int_ft_collector_info_t; 446 447 typedef struct _bcm_int_ft_v2_collector_info_s { 448 /* Internal Collector Id */ 449 int int_id; 450 } _bcm_int_ft_v2_collector_info_t; 451 452 typedef struct _bcm_int_ft_v2_export_profile_info_s { 453 /* Internal Export_Profile Id */ 454 int int_id; 455 } _bcm_int_ft_v2_export_profile_info_t; 456 457 /* Internal data structure to store per flow_group information 458 */ 459 typedef struct _bcm_int_ft_flow_group_info_s { 460 /* Software ID of the flow_group */ 461 bcm_flowtracker_group_t flow_group_id; 462 /* Aging interval in msecs */ 463 uint32 aging_interval_msecs; 464 /* Max flows that can be learned on this group */ 465 uint32 flow_limit; 466 /* Collector associated with the flow group */ 467 int collector_id; 468 /* Collector associated with the flow group */ 469 int export_profile_id; 470 /* Template associated with the flow group */ 471 uint16 template_id; 472 473 /* Elephant profle Id */ 474 bcm_flowtracker_elephant_profile_t elph_profile_id; 475 476 /* QoS profile Id */ 477 uint32 qos_profile_id; 478 479 /* Number of actions on the group */ 480 uint16 num_actions; 481 482 _bcm_int_ft_group_action_info_t *action_list; 483 484 /* Export triggers which will result in the export of the packets */ 485 uint32 export_trigger; 486 487 /* Field group corresponding to the flow group. */ 488 bcm_field_group_t field_group[BCM_PIPES_MAX]; 489 490 /* Number of Tracking Params on the group */ 491 int num_tracking_params; 492 493 bcm_flowtracker_tracking_param_info_t *tracking_params; 494 495 } _bcm_int_ft_flow_group_info_t; 496 497 /* Internal data structure to store elephant profile info 498 */ 499 typedef struct _bcm_int_ft_elph_profile_info_s { 500 /* Software Id of the profile */ 501 bcm_flowtracker_elephant_profile_t id; 502 503 /* Profile information structure */ 504 bcm_flowtracker_elephant_profile_info_t profile; 505 } _bcm_int_ft_elph_profile_info_t; 506 507 /* Global data structures extern declarations */ 508 extern _bcm_int_ft_info_t *ft_global_info[BCM_MAX_NUM_UNITS]; 509 510 /* Utility functions */ 511 extern int 512 _bcm_esw_flowtracker_ucast_cosq_resolve(int unit, uint32 cosq, int *hw_cosq); 513 514 extern int 515 _bcm_esw_flowtracker_mcast_cosq_resolve(int unit, uint32 cosq, int *hw_cosq); 516 517 /* Get the FT_INFO struct for the unit */ 518 #define FT_INFO_GET(_u) ft_global_info[(_u)] 519 520 521 extern void _bcm_esw_flowtracker_sw_dump(int unit); 522 extern void _bcm_esw_flowtracker_dump_stats_learn(int unit); 523 extern void _bcm_esw_flowtracker_dump_stats_export(int unit); 524 extern void _bcm_esw_flowtracker_dump_stats_age(int unit); 525 extern void _bcm_esw_flowtracker_dump_stats_elephant(int unit); 526 extern void _bcm_esw_qcm_sw_dump(int unit); 527 extern void _bcm_esw_qcm_stats_enable(int unit, uint8 enable); 528 extern void _bcm_esw_qcm_dump_stats_learn(int unit); 529 extern void _bcm_esw_qcm_dump_stats_export(int unit); 530 extern void _bcm_esw_qcm_dump_stats_age(int unit); 531 extern void _bcm_esw_qcm_dump_stats_scan(int unit); 532 533 /* Max number of pipes across all devices */ 534 #define BCM_INT_FT_QCM_MAX_PIPES 8 535 536 /* Max number of counter per pipes */ 537 #define BCM_INT_FT_QCM_MAX_COUNTERS 2 538 539 /* Max number of MMU BLOCK */ 540 #define BCM_INT_FT_QCM_NUM_MMU_BLOCK 4 541 542 typedef struct ft_qcm_port_cfg_s { 543 bcm_gport_t gport; 544 uint32 global_num; 545 uint32 port_pipe_queue_num; 546 uint16 pport; 547 } _bcm_esw_ft_qcm_port_cfg_t; 548 549 typedef struct ft_qcm_init_cfg_s { 550 uint32 drop_index[(BCM_INT_FT_QCM_MAX_PIPES * BCM_INT_FT_QCM_MAX_COUNTERS)]; 551 uint32 util_index[(BCM_INT_FT_QCM_MAX_PIPES * BCM_INT_FT_QCM_MAX_COUNTERS)]; 552 uint32 egr_index[BCM_INT_FT_QCM_MAX_PIPES]; 553 uint16 max_port_num; 554 uint16 queues_per_pipe; 555 uint16 ports_per_pipe; 556 uint8 queues_per_port; 557 uint8 num_pipes; 558 uint8 num_counters_per_pipe; 559 uint8 acc_type[(BCM_INT_FT_QCM_MAX_PIPES * BCM_INT_FT_QCM_MAX_COUNTERS)]; 560 } _bcm_esw_ft_qcm_init_cfg_t; 561 562 #endif /* INCLUDE_FLOWTRACKER */ 563 extern int _bcm_esw_flowtracker_sync(int unit); 564 #endif /* !_BCM_INT_FT_H_ */