flexstate.h (20685B)
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 */ 9 10 #ifndef __BCM_FLEXSTATE_H__ 11 #define __BCM_FLEXSTATE_H__ 12 13 #include <bcm/types.h> 14 #include <bcm/port.h> 15 16 /* 17 * Enumeration of flex state sources. 18 * 19 * Flex state source indicates the sources to generates a flex state 20 * action. 21 */ 22 typedef enum bcm_flexstate_source_e { 23 bcmFlexstateSourceEmFt = 0, /* Ingress EM flow tracker. */ 24 bcmFlexstateSourceIngPort = 1, /* Ingress Port. */ 25 bcmFlexstateSourceCount = 2 /* Always last one. */ 26 } bcm_flexstate_source_t; 27 28 #define BCM_FLEXSTATE_SOURCE_NAME_INITIALIZER \ 29 { \ 30 "bcmFlexstateSourceEmFt", \ 31 "bcmFlexstateSourceIngPort", \ 32 "bcmFlexstateSourceCount" \ 33 } 34 35 /* 36 * Enumeration of flex state objects. 37 * 38 * Flex state object could be used to generate state index and counter 39 * value. 40 * Some objects could also be used for conditional trigger and 41 * quantization. 42 */ 43 typedef enum bcm_flexstate_object_e { 44 bcmFlexstateObjectConstZero = 0, /* Const value 0 object. */ 45 bcmFlexstateObjectConstOne = 1, /* Const value 1 object. */ 46 bcmFlexstateObjectTriggerInterval = 2, /* Trigger interval object. */ 47 bcmFlexstateObjectQuant = 3, /* Quantization result object. */ 48 bcmFlexstateObjectIngL2Iif = 1000, /* Ingress l2 iif object. */ 49 bcmFlexstateObjectIngEmFtHitIndex0 = 1001, /* Ingress em ft hit index 0 object. */ 50 bcmFlexstateObjectIngEmFtHitIndex1 = 1002, /* Ingress em ft hit index 1 object. */ 51 bcmFlexstateObjectIngEmFtOpaqueObj0 = 1003, /* Ingress em ft opaque obj 0 object. */ 52 bcmFlexstateObjectEgrPipePortQueueNum = 1004, /* Egress pipe port queue num object. */ 53 bcmFlexstateObjectEgrResidenceTimeRaw0 = 1005, /* Egress residence time raw 0 object. */ 54 bcmFlexstateObjectEgrResidenceTimeRaw = 1006, /* Egress residence time raw object. */ 55 bcmFlexstateObjectEgrPktLenObj = 1007, /* Egress pkt len obj object. */ 56 bcmFlexstateObjectCount = 1008 /* Always last one. */ 57 } bcm_flexstate_object_t; 58 59 #define BCM_FLEXSTATE_OBJECT_NAME_INITIALIZER \ 60 { \ 61 "bcmFlexstateObjectConstZero", \ 62 "bcmFlexstateObjectConstOne", \ 63 "bcmFlexstateObjectTriggerInterval", \ 64 "bcmFlexstateObjectQuant", \ 65 "bcmFlexstateObjectIngL2Iif", \ 66 "bcmFlexstateObjectIngEmFtHitIndex0", \ 67 "bcmFlexstateObjectIngEmFtHitIndex1", \ 68 "bcmFlexstateObjectIngEmFtOpaqueObj0", \ 69 "bcmFlexstateObjectEgrPipePortQueueNum", \ 70 "bcmFlexstateObjectEgrResidenceTimeRaw0", \ 71 "bcmFlexstateObjectEgrResidenceTimeRaw", \ 72 "bcmFlexstateObjectEgrPktLenObj", \ 73 "bcmFlexstateObjectCount" \ 74 } 75 76 #define BCM_FLEXSTATE_COUNTER_VALUE_SIZE 2 /* Counter array size 77 number. */ 78 79 /* 80 * Flex state statistic value. 81 * 82 * Normal mode: 83 * value[0] is the data of counter value A. 84 * value[1] is the data of counter value B. 85 * Wide mode: 86 * value[0] is the upper part data of counter value A. 87 * value[1] is the lower part data of counter value A. 88 */ 89 typedef struct bcm_flexstate_counter_value_s { 90 uint64 value[BCM_FLEXSTATE_COUNTER_VALUE_SIZE]; /* Flex state statistic value array. */ 91 } bcm_flexstate_counter_value_t; 92 93 #define BCM_FLEXSTATE_OPERATION_OBJECT_SIZE 2 /* Operation object array 94 size number. */ 95 96 /* 97 * Flex state index operation structure. 98 * 99 * This data structure lists the operation of a flex state index. 100 * Flex state index would be generated as below: 101 * value0 = (SEL(object0) >> shift0) & ((1 << mask_size0) - 1)). 102 * value1 = (SEL(object1) & ((1 << mask_size1) - 1)) << shift1. 103 * index = (value1 | value0). 104 */ 105 typedef struct bcm_flexstate_index_operation_s { 106 bcm_flexstate_object_t object[BCM_FLEXSTATE_OPERATION_OBJECT_SIZE]; /* Flex state object array. */ 107 uint32 quant_id[BCM_FLEXSTATE_OPERATION_OBJECT_SIZE]; /* Quantization ID. */ 108 uint8 mask_size[BCM_FLEXSTATE_OPERATION_OBJECT_SIZE]; /* Object mask size array. */ 109 uint8 shift[BCM_FLEXSTATE_OPERATION_OBJECT_SIZE]; /* Object shift array. */ 110 } bcm_flexstate_index_operation_t; 111 112 /* Enumeration of flex state value select. */ 113 typedef enum bcm_flexstate_value_select_e { 114 bcmFlexstateValueSelectCounterValue = 0, /* Select state value generated by 115 operation to update counter. */ 116 bcmFlexstateValueSelectPairedCounter = 1, /* Select paired counter value to update 117 counter. */ 118 bcmFlexstateValueSelectCount = 2 /* Always last one. */ 119 } bcm_flexstate_value_select_t; 120 121 /* Enumeration of flex state value operation types. */ 122 typedef enum bcm_flexstate_value_operation_type_e { 123 bcmFlexstateValueOperationTypeNoop = 0, /* COUNTER = OLD_COUNTER. */ 124 bcmFlexstateValueOperationTypeSet = 1, /* COUNTER = CVALUE. */ 125 bcmFlexstateValueOperationTypeInc = 2, /* COUNTER = OLD_COUNTER + CVALUE. */ 126 bcmFlexstateValueOperationTypeDec = 3, /* COUNTER = OLD_COUNTER - CVALUE. */ 127 bcmFlexstateValueOperationTypeMax = 4, /* COUNTER = MAX(OLD_COUNTER, CVALUE). */ 128 bcmFlexstateValueOperationTypeMin = 5, /* COUNTER = MIN(OLD_COUNTER, CVALUE). */ 129 bcmFlexstateValueOperationTypeAverage = 6, /* COUNTER = AVERAGE(OLD_COUNTER, 130 CVALUE). */ 131 bcmFlexstateValueOperationTypeSetBit = 7, /* COUNTER = SETBIT(OLD_COUNTER, 132 CVALUE). */ 133 bcmFlexstateValueOperationTypeRdec = 8, /* COUNTER = CVALUE - OLD_COUNTER. */ 134 bcmFlexstateValueOperationTypeXor = 9, /* COUNTER = XOR(OLD_COUNTER, CVALUE). */ 135 bcmFlexstateValueOperationTypeCount = 10 /* Always last one. */ 136 } bcm_flexstate_value_operation_type_t; 137 138 /* 139 * Flex state value operation structure. 140 * 141 * This data structure lists the operation of a flex state update value. 142 * Flex state update value would be generated as below: 143 * value0 = (SEL(object0) >> shift0) & ((1 << mask_size0) - 1)). 144 * value1 = (SEL(object1) & ((1 << mask_size1) - 1)) << shift1. 145 * value = (value1 | value0). 146 * New_counter = UPDATE_TYPE(old_counter, value). 147 */ 148 typedef struct bcm_flexstate_value_operation_s { 149 bcm_flexstate_value_select_t select; /* Select state value. */ 150 bcm_flexstate_object_t object[BCM_FLEXSTATE_OPERATION_OBJECT_SIZE]; /* Flex state object array. */ 151 uint32 quant_id[BCM_FLEXSTATE_OPERATION_OBJECT_SIZE]; /* Quantization ID. */ 152 uint8 mask_size[BCM_FLEXSTATE_OPERATION_OBJECT_SIZE]; /* Object mask size array. */ 153 uint8 shift[BCM_FLEXSTATE_OPERATION_OBJECT_SIZE]; /* Object shift array. */ 154 bcm_flexstate_value_operation_type_t type; /* Counter value operation type. */ 155 } bcm_flexstate_value_operation_t; 156 157 #define BCM_FLEXSTATE_QUANTIZATION_RANGE_SIZE 8 /* Quantization range 158 check array size 159 number. */ 160 161 /* 162 * Flex state quantization structure. 163 * 164 * This data structure lists the properties of a flex state quantization. 165 * Each quantization instance generates a range check result. 166 */ 167 typedef struct bcm_flexstate_quantization_s { 168 bcm_flexstate_object_t object; /* Flex state object. */ 169 bcm_pbmp_t ports; /* Flex state ports. */ 170 uint32 range_check_min[BCM_FLEXSTATE_QUANTIZATION_RANGE_SIZE]; /* Range check min value array. */ 171 uint32 range_check_max[BCM_FLEXSTATE_QUANTIZATION_RANGE_SIZE]; /* Range check max value array. */ 172 uint8 range_num; /* Total range check number */ 173 } bcm_flexstate_quantization_t; 174 175 /* Enumeration of flex state trigger type. */ 176 typedef enum bcm_flexstate_trigger_type_e { 177 bcmFlexstateTriggerTypeTime = 0, /* Time based trigger type. */ 178 bcmFlexstateTriggerTypeCondition = 1, /* Condition based trigger type. */ 179 bcmFlexstateTriggerTypeConditionStartTimeStop = 2, /* Condition based start and time based 180 stop type. */ 181 bcmFlexstateTriggerTypeCount = 3 /* Always last one. */ 182 } bcm_flexstate_trigger_type_t; 183 184 /* Enumeration of flex state trigger interval scale. */ 185 typedef enum bcm_flexstate_trigger_interval_e { 186 bcmFlexstateTriggerIntervalUnlimited = 0, /* Unlimited collection. */ 187 bcmFlexstateTriggerInterval100ns = 1, /* 100 nanosecond interval. */ 188 bcmFlexstateTriggerInterval500ns = 2, /* 500 nanosecond interval. */ 189 bcmFlexstateTriggerInterval1us = 3, /* 1 millisecond interval. */ 190 bcmFlexstateTriggerInterval10us = 4, /* 10 millisecond interval. */ 191 bcmFlexstateTriggerInterval100us = 5, /* 100 microsecond interval. */ 192 bcmFlexstateTriggerInterval1ms = 6, /* 1 microsecond interval. */ 193 bcmFlexstateTriggerInterval10ms = 7, /* 10 microsecond interval. */ 194 bcmFlexstateTriggerIntervalCount = 8 /* Always last one. */ 195 } bcm_flexstate_trigger_interval_t; 196 197 /* 198 * Flex state trigger structure. 199 * 200 * This data structure lists the properties of the flex state trigger. 201 */ 202 typedef struct bcm_flexstate_trigger_s { 203 bcm_flexstate_trigger_type_t trigger_type; /* Trigger type. */ 204 uint8 period_num; /* Time trigger period number. */ 205 bcm_flexstate_trigger_interval_t interval; /* Time trigger interval scale. */ 206 bcm_flexstate_object_t object; /* Flex state object. */ 207 uint16 object_value_start; /* Conditional trigger start value. */ 208 uint16 object_value_stop; /* Conditional trigger stop value. */ 209 uint16 object_value_mask; /* Conditional trigger mask. */ 210 } bcm_flexstate_trigger_t; 211 212 /* Enumeration of flex state counter modes. */ 213 typedef enum bcm_flexstate_counter_mode_e { 214 bcmFlexstateCounterModeNormal = 0, /* Each counter contains two values A 215 and B. 216 The update value of value A and B are 217 separately controlled by 218 value_a_operation and 219 value_b_operation in counter action. 220 All value operation modes are 221 suitable for values A and B. */ 222 bcmFlexstateCounterModeWide = 1, /* Each counter only contains one value 223 A. 224 The update value of value A is 225 controlled by value_a_operation in 226 counter action. 227 Only value operation modes noop, set, 228 inc and setbit are suitable for value 229 A. */ 230 bcmFlexstateCounterModeCount = 2 /* Always last one. */ 231 } bcm_flexstate_counter_mode_t; 232 233 /* Enumeration of flex state drop count modes. */ 234 typedef enum bcm_flexstate_drop_count_mode_e { 235 bcmFlexstateDropCountModeNoDrop = 0, /* Count only if not being dropped. */ 236 bcmFlexstateDropCountModeDrop = 1, /* Count only if being dropped. */ 237 bcmFlexstateDropCountModeAll = 2, /* Ignore drop status and always count. */ 238 bcmFlexstateDropCountModeCount = 3 /* Always last one. */ 239 } bcm_flexstate_drop_count_mode_t; 240 241 /* Enumeration of flex state update compare types. */ 242 typedef enum bcm_flexstate_update_compare_e { 243 bcmFlexstateUpdateCompareAlwaysTrue = 0, /* No conditional update. */ 244 bcmFlexstateUpdateCompareEqual = 1, /* Update if stored counter value = 245 computed value. */ 246 bcmFlexstateUpdateCompareLess = 2, /* Update if stored counter value < 247 computed value. */ 248 bcmFlexstateUpdateCompareCount = 3 /* Always last one. */ 249 } bcm_flexstate_update_compare_t; 250 251 /* Flex state operation structure. */ 252 typedef struct bcm_flexstate_operation_s { 253 bcm_flexstate_update_compare_t update_compare; /* Comparison operation in the 254 conditional update logic. */ 255 bcm_flexstate_value_operation_t compare_operation; /* Comparison value in the conditional 256 update logic. */ 257 bcm_flexstate_value_operation_t operation_true; /* Update value when conditional update 258 logic returns true. */ 259 bcm_flexstate_value_operation_t operation_false; /* Update value when conditional update 260 logic returns false. */ 261 } bcm_flexstate_operation_t; 262 263 #define BCM_FLEXSTATE_ACTION_FLAGS_TRIGGER 0x1 /* Flex state trigger is 264 attached in the 265 action. */ 266 #define BCM_FLEXSTATE_ACTION_FLAGS_HINT_OUTPUT 0x2 /* Flex state hint value 267 is used to specify 268 output number. */ 269 270 /* 271 * Flex state action structure. 272 * 273 * This data structure lists the properties of a flex state action. 274 */ 275 typedef struct bcm_flexstate_action_s { 276 uint32 flags; /* Action flags. */ 277 bcm_flexstate_source_t source; /* Flex state source. */ 278 bcm_pbmp_t ports; /* Flex state ports. */ 279 int hint; /* Flex state hint. */ 280 bcm_flexstate_drop_count_mode_t drop_count_mode; /* Counter drop mode for functional 281 packet drops. */ 282 int exception_drop_count_enable; /* Enable to count on hardware exception 283 drops. */ 284 int egress_mirror_count_enable; /* Enable to count egress mirrored 285 packets also. */ 286 bcm_flexstate_counter_mode_t mode; /* Action mode. */ 287 uint32 index_num; /* Total counter index number. */ 288 bcm_flexstate_index_operation_t index_operation; /* Flex state index operation structure. */ 289 bcm_flexstate_operation_t operation_a; /* Flex state value A operation 290 structure. */ 291 bcm_flexstate_operation_t operation_b; /* Flex state value B operation 292 structure. */ 293 bcm_flexstate_trigger_t trigger; /* Flex state trigger structure. */ 294 } bcm_flexstate_action_t; 295 296 #define BCM_FLEXSTATE_GROUP_ACTION_SIZE 4 /* Group action array size 297 number. */ 298 299 /* 300 * Flex state group action structure. 301 * 302 * This data structure lists the properties of a flex state group action. 303 */ 304 typedef struct bcm_flexstate_group_action_s { 305 bcm_flexstate_source_t source; /* Flex state source. */ 306 bcm_pbmp_t ports; /* Flex state ports. */ 307 uint32 action_id[BCM_FLEXSTATE_GROUP_ACTION_SIZE]; /* Flex state group action array. */ 308 uint8 action_num; /* Total group action array number */ 309 } bcm_flexstate_group_action_t; 310 311 #ifndef BCM_HIDE_DISPATCHABLE 312 313 /* 314 * Flexstate module initialization function. 315 * 316 * This function is used to initialize flexstate module. 317 * 318 * [in] unit Unit number. 319 * 320 * BCM_E_NONE No errors. 321 * BCM_E_XXX API errors. 322 */ 323 extern int bcm_flexstate_init( 324 int unit); 325 326 /* 327 * Flexstate module cleanup function. 328 * 329 * This function is used to shut down flexstate module. 330 * 331 * [in] unit Unit number. 332 * 333 * BCM_E_NONE No errors. 334 * BCM_E_XXX API errors. 335 */ 336 extern int bcm_flexstate_cleanup( 337 int unit); 338 339 #endif /* BCM_HIDE_DISPATCHABLE */ 340 341 #define BCM_FLEXSTATE_OPTIONS_WITH_ID 0x1 /* Instance id is presented. */ 342 #define BCM_FLEXSTATE_OPTIONS_REPLACE 0x2 /* Need to replace an 343 existing instance. */ 344 345 /* Flex counter quantization data structure initialization function. */ 346 extern void bcm_flexstate_quantization_t_init( 347 bcm_flexstate_quantization_t *quantization); 348 349 #ifndef BCM_HIDE_DISPATCHABLE 350 351 /* Flex counter quantization creation function. */ 352 extern int bcm_flexstate_quantization_create( 353 int unit, 354 int options, 355 bcm_flexstate_quantization_t *quantization, 356 uint32 *quant_id); 357 358 /* Flex counter quantization destroy function. */ 359 extern int bcm_flexstate_quantization_destroy( 360 int unit, 361 uint32 quant_id); 362 363 /* Flex counter quantization get function. */ 364 extern int bcm_flexstate_quantization_get( 365 int unit, 366 uint32 quant_id, 367 bcm_flexstate_quantization_t *quantization); 368 369 #endif /* BCM_HIDE_DISPATCHABLE */ 370 371 /* Flex counter quantization traverse callback. */ 372 typedef int (*bcm_flexstate_quantization_traverse_cb)( 373 int unit, 374 uint32 quant_id, 375 bcm_flexstate_quantization_t *quantization, 376 void *user_data); 377 378 #ifndef BCM_HIDE_DISPATCHABLE 379 380 /* Flex counter quantization traverse function. */ 381 extern int bcm_flexstate_quantization_traverse( 382 int unit, 383 bcm_flexstate_quantization_traverse_cb trav_fn, 384 void *user_data); 385 386 #endif /* BCM_HIDE_DISPATCHABLE */ 387 388 /* Flex counter action data structure initialization function. */ 389 extern void bcm_flexstate_action_t_init( 390 bcm_flexstate_action_t *action); 391 392 #ifndef BCM_HIDE_DISPATCHABLE 393 394 /* Flex counter action creation function. */ 395 extern int bcm_flexstate_action_create( 396 int unit, 397 int options, 398 bcm_flexstate_action_t *action, 399 uint32 *action_id); 400 401 /* Flex counter action destroy function. */ 402 extern int bcm_flexstate_action_destroy( 403 int unit, 404 uint32 action_id); 405 406 /* Flex counter action get function. */ 407 extern int bcm_flexstate_action_get( 408 int unit, 409 uint32 action_id, 410 bcm_flexstate_action_t *action); 411 412 #endif /* BCM_HIDE_DISPATCHABLE */ 413 414 /* Flex counter action traverse callback. */ 415 typedef int (*bcm_flexstate_action_traverse_cb)( 416 int unit, 417 uint32 action_id, 418 bcm_flexstate_action_t *action, 419 void *user_data); 420 421 #ifndef BCM_HIDE_DISPATCHABLE 422 423 /* Flex counter action traverse function. */ 424 extern int bcm_flexstate_action_traverse( 425 int unit, 426 bcm_flexstate_action_traverse_cb trav_fn, 427 void *user_data); 428 429 #endif /* BCM_HIDE_DISPATCHABLE */ 430 431 /* Flex counter group action data structure initialization function. */ 432 extern void bcm_flexstate_group_action_t_init( 433 bcm_flexstate_group_action_t *group_action); 434 435 #ifndef BCM_HIDE_DISPATCHABLE 436 437 /* Flex counter group action creation function. */ 438 extern int bcm_flexstate_group_action_create( 439 int unit, 440 int options, 441 bcm_flexstate_group_action_t *group_action, 442 uint32 *group_stat_counter_id); 443 444 /* Flex counter group action destroy function. */ 445 extern int bcm_flexstate_group_action_destroy( 446 int unit, 447 uint32 group_stat_counter_id); 448 449 /* Flex counter group action get function. */ 450 extern int bcm_flexstate_group_action_get( 451 int unit, 452 uint32 group_stat_counter_id, 453 bcm_flexstate_group_action_t *group_action); 454 455 #endif /* BCM_HIDE_DISPATCHABLE */ 456 457 /* Flex counter group action traverse callback. */ 458 typedef int (*bcm_flexstate_group_action_traverse_cb)( 459 int unit, 460 uint32 group_stat_counter_id, 461 bcm_flexstate_group_action_t *group_action, 462 void *user_data); 463 464 #ifndef BCM_HIDE_DISPATCHABLE 465 466 /* Flex counter group action traverse function. */ 467 extern int bcm_flexstate_group_action_traverse( 468 int unit, 469 bcm_flexstate_group_action_traverse_cb trav_fn, 470 void *user_data); 471 472 /* Flex counter trigger enable set function. */ 473 extern int bcm_flexstate_trigger_enable_set( 474 int unit, 475 uint32 action_id, 476 int enable); 477 478 /* Flex counter trigger enable get function. */ 479 extern int bcm_flexstate_trigger_enable_get( 480 int unit, 481 uint32 action_id, 482 int *enable); 483 484 /* Flex counter statistic get function. */ 485 extern int bcm_flexstate_stat_get( 486 int unit, 487 uint32 action_id, 488 uint32 num_entries, 489 uint32 *counter_indexes, 490 bcm_flexstate_counter_value_t *counter_values); 491 492 /* Flex counter statistic sync get function. */ 493 extern int bcm_flexstate_stat_sync_get( 494 int unit, 495 uint32 action_id, 496 uint32 num_entries, 497 uint32 *counter_indexes, 498 bcm_flexstate_counter_value_t *counter_values); 499 500 /* Flex counter statistic set function. */ 501 extern int bcm_flexstate_stat_set( 502 int unit, 503 uint32 action_id, 504 uint32 num_entries, 505 uint32 *counter_indexes, 506 bcm_flexstate_counter_value_t *counter_values); 507 508 #endif /* BCM_HIDE_DISPATCHABLE */ 509 510 #endif /* __BCM_FLEXSTATE_H__ */