openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

policer.h (64916B)


      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  * DO NOT EDIT THIS FILE!
      9  * This file is auto-generated.
     10  * Edits to this file will be lost when it is regenerated.
     11  */
     12 
     13 #ifndef __BCM_POLICER_H__
     14 #define __BCM_POLICER_H__
     15 
     16 #include <bcm/types.h>
     17 
     18 /* Policer Modes. */
     19 typedef enum bcm_policer_mode_e {
     20     bcmPolicerModeSrTcm = 0,            /* RFC 2697 */
     21     bcmPolicerModeCommitted = 1, 
     22     bcmPolicerModePeak = 2, 
     23     bcmPolicerModeTrTcm = 3,            /* RFC 2698 */
     24     bcmPolicerModeTrTcmDs = 4,          /* RFC 4115, TrTcmModified */
     25     bcmPolicerModeGreen = 5, 
     26     bcmPolicerModePassThrough = 6, 
     27     bcmPolicerModeSrTcmModified = 7, 
     28     bcmPolicerModeCoupledTrTcmDs = 8, 
     29     bcmPolicerModeCascade = 9, 
     30     bcmPolicerModeCoupledCascade = 10, 
     31     bcmPolicerModeSrTcmTsn = 11,        /* IEEE 802.1Qci TSN Modified srTCM */
     32     bcmPolicerModeCount = 12 
     33 } bcm_policer_mode_t;
     34 
     35 /* Modes for creating a group of policers */
     36 typedef enum bcm_policer_group_mode_e {
     37     bcmPolicerGroupModeSingle = 0,      /* A single policer used for all traffic
     38                                            types */
     39     bcmPolicerGroupModeTrafficType = 1, /* A dedicated policer per traffic type
     40                                            unicast, multicast, broadcast */
     41     bcmPolicerGroupModeDlfAll = 2,      /* A pair of policers where the base
     42                                            policer is used for dlf and the other
     43                                            policer is used for all traffic types */
     44     bcmPolicerGroupModeDlfIntPri = 3,   /* N+1 policers where the base policer
     45                                            is used for dlf and next N are used
     46                                            per Cos */
     47     bcmPolicerGroupModeTyped = 4,       /* A dedicated policer for unknown
     48                                            unicast, known unicast, multicast,
     49                                            broadcast */
     50     bcmPolicerGroupModeTypedAll = 5,    /* A dedicated policer for unknown
     51                                            unicast, known unicast, multicast,
     52                                            broadcast and one for all traffic
     53                                            (not already policed) */
     54     bcmPolicerGroupModeTypedIntPri = 6, /* A dedicated policer for unknown
     55                                            unicast, known unicast, multicast,
     56                                            broadcast and N internal priority
     57                                            policers for traffic (not already
     58                                            policed) */
     59     bcmPolicerGroupModeSingleWithControl = 7, /* A single policer used for all traffic
     60                                            types with an additional policer for
     61                                            control traffic */
     62     bcmPolicerGroupModeTrafficTypeWithControl = 8, /* A dedicated policer per traffic type
     63                                            unicast, multicast, broadcast with an
     64                                            additional policer for control
     65                                            traffic */
     66     bcmPolicerGroupModeDlfAllWithControl = 9, /* A pair of policers where the base
     67                                            policer is used for control, the next
     68                                            one for dlf and the other policer is
     69                                            used for all traffic types */
     70     bcmPolicerGroupModeDlfIntPriWithControl = 10, /* N+2 policers where the base policer
     71                                            is used for control, the next one for
     72                                            dlf and next N are used per Cos */
     73     bcmPolicerGroupModeTypedWithControl = 11, /* A dedicated policer for control,
     74                                            unknown unicast, known unicast,
     75                                            multicast, broadcast */
     76     bcmPolicerGroupModeTypedAllWithControl = 12, /* A dedicated policer for control,
     77                                            unknown unicast, known unicast,
     78                                            multicast, broadcast and one for all
     79                                            traffic (not already policed) */
     80     bcmPolicerGroupModeTypedIntPriWithControl = 13, /* A dedicated policer for control,
     81                                            unknown unicast, known unicast,
     82                                            multicast, broadcast and N internal
     83                                            priority policers for traffic (not
     84                                            already policed) */
     85     bcmPolicerGroupModeDot1P = 14,      /* A Set of 8 policers based on outer
     86                                            Vlan priority */
     87     bcmPolicerGroupModeIntPri = 15,     /* A Set of 16 policers based on
     88                                            internal priority */
     89     bcmPolicerGroupModeIntPriCng = 16,  /* A Set of 64 policers based on
     90                                            internal priority and cng */
     91     bcmPolicerGroupModeSvpType = 17,    /* A Set of 2 policers based on SVP type */
     92     bcmPolicerGroupModeDscp = 18,       /* A Set of 64 policers based on IP DSCP
     93                                            bits */
     94     bcmPolicerGroupModeCascade = 19,    /*  User specified set of policers(max
     95                                            8), wherein excess bandwidth can
     96                                            overflow from high priority bucket to
     97                                            low priority bucket */
     98     bcmPolicerGroupModeCascadeWithCoupling = 20, /*  User specified set of policers(max
     99                                            4), wherein excess bandwidth can
    100                                            overflow from high priority bucket to
    101                                            low priority bucket and from low
    102                                            priority green bucket to high
    103                                            priority yellow bucket */
    104     bcmPolicerGroupModeInnerDot1P = 21, /* A Set of 8 policers based on inner
    105                                            Vlan priority */
    106     bcmPolicerGroupModeEgressSingle = 22, /* A dedicated policer for all egress
    107                                            traffic */
    108     bcmPolicerGroupModeEgressIntPri = 23, /* A dedicated policer for egress
    109                                            traffic for each cos level */
    110     bcmPolicerGroupModeShortIntPri = 24, /* A Set of 8 policers based on internal
    111                                            priority */
    112     bcmPolicerGroupModeIntPriCascade = 25, /* Set of policers(max 8), wherein
    113                                            excess bandwidth can overflow from
    114                                            high priority bucket to low priority
    115                                            bucket, qualified on internal
    116                                            priority */
    117     bcmPolicerGroupModeIntPriCascadeWithCoupling = 26, /* Set of policers(max 4), wherein
    118                                            excess bandwidth can overflow from
    119                                            high priority bucket to low priority
    120                                            bucket and from low priority green
    121                                            bucket to high priority yellow */
    122     bcmPolicerGroupModePreemptable = 27, /* A set of 2 policers based on whether
    123                                            the packet is preemptable or not */
    124     bcmPolicerGroupModeCascadeDroppedPktExclude = 28, /* Set of policers(max 8), wherein
    125                                            excess bandwidth can overflow from
    126                                            high priority bucket to low priority
    127                                            bucket, with dropped packets ignored
    128                                            for metering */
    129     bcmPolicerGroupModeCount = 29       /* Last value. Not to be used */
    130 } bcm_policer_group_mode_t;
    131 
    132 /* Supported policer stats */
    133 typedef enum bcm_policer_stat_e {
    134     bcmPolicerStatGreenToGreenPackets = 0, /* Packet count for G-To-G transitions */
    135     bcmPolicerStatGreenToGreenBytes = 1, /* Byte count for G-To-G transitions */
    136     bcmPolicerStatGreenToYellowPackets = 2, /* Packet count for G-To-Y transitions */
    137     bcmPolicerStatGreenToYellowBytes = 3, /* Byte count for G-To-Y transitions */
    138     bcmPolicerStatGreenToRedPackets = 4, /* Packet count for G-To-R transitions */
    139     bcmPolicerStatGreenToRedBytes = 5,  /* Byte count for G-To-R transitions */
    140     bcmPolicerStatGreenToDropPackets = 6, /* Packet count for G-To-D transitions */
    141     bcmPolicerStatGreenToDropBytes = 7, /* Byte count for G-To-D transitions */
    142     bcmPolicerStatYellowToGreenPackets = 8, /* Packet count for Y-To-G transitions */
    143     bcmPolicerStatYellowToGreenBytes = 9, /* Byte count for Y-To-G transitions */
    144     bcmPolicerStatYellowToYellowPackets = 10, /* Packet count for Y-To-Y transitions */
    145     bcmPolicerStatYellowToYellowBytes = 11, /* Byte count for Y-To-Y transitions */
    146     bcmPolicerStatYellowToRedPackets = 12, /* Packet count for Y-To-R transitions */
    147     bcmPolicerStatYellowToRedBytes = 13, /* Byte count for Y-To-R transitions */
    148     bcmPolicerStatYellowToDropPackets = 14, /* Packet count for Y-To-D transitions */
    149     bcmPolicerStatYellowToDropBytes = 15, /* Byte count for Y-To-D transitions */
    150     bcmPolicerStatRedToGreenPackets = 16, /* Packet count for R-To-G transitions */
    151     bcmPolicerStatRedToGreenBytes = 17, /* Byte count for R-To-G transitions */
    152     bcmPolicerStatRedToYellowPackets = 18, /* Packet count for R-To-Y transitions */
    153     bcmPolicerStatRedToYellowBytes = 19, /* Byte count for R-To-Y transitions */
    154     bcmPolicerStatRedToRedPackets = 20, /* Packet count for R-To-R transitions */
    155     bcmPolicerStatRedToRedBytes = 21,   /* Byte count for R-To-R transitions */
    156     bcmPolicerStatRedToDropPackets = 22, /* Packet count for R-To-D transitions */
    157     bcmPolicerStatRedToDropBytes = 23,  /* Byte count for R-To-D transitions */
    158     bcmPolicerStatPackets = 24,         /* Packet count for all types of traffic
    159                                            policed */
    160     bcmPolicerStatBytes = 25,           /* Byte count for all types of traffic
    161                                            policed */
    162     bcmPolicerStatUnknownUnicastPackets = 26, /* Packet count for policed unknown
    163                                            unicast traffic */
    164     bcmPolicerStatUnknownUnicastBytes = 27, /* Byte count for policed unknown
    165                                            unicast traffic */
    166     bcmPolicerStatUnicastPackets = 28,  /* Packet count for policed unicast
    167                                            traffic */
    168     bcmPolicerStatUnicastBytes = 29,    /* Byte count for policed unicast
    169                                            traffic */
    170     bcmPolicerStatMulticastPackets = 30, /* Packet count for policed multicast
    171                                            traffic */
    172     bcmPolicerStatMulticastBytes = 31,  /* Byte count for policed multicast
    173                                            traffic */
    174     bcmPolicerStatBroadcastPackets = 32, /* Packet count for policed broadcast
    175                                            traffic */
    176     bcmPolicerStatBroadcastBytes = 33,  /* Byte count for policed broadcast
    177                                            traffic */
    178     bcmPolicerStatDropPackets = 34,     /* Packet count for all types of traffic
    179                                            dropped */
    180     bcmPolicerStatDropBytes = 35,       /* Byte count for all types of traffic
    181                                            dropped */
    182     bcmPolicerStatDropUnknownUnicastPackets = 36, /* Packet count for dropped unknown
    183                                            unicast traffic */
    184     bcmPolicerStatDropUnknownUnicastBytes = 37, /* Byte count for dropped unknown
    185                                            unicast traffic */
    186     bcmPolicerStatDropUnicastPackets = 38, /* Packet count for dropped unicast
    187                                            traffic */
    188     bcmPolicerStatDropUnicastBytes = 39, /* Byte count for dropped unicast
    189                                            traffic */
    190     bcmPolicerStatDropMulticastPackets = 40, /* Packet count for dropped multicast
    191                                            traffic */
    192     bcmPolicerStatDropMulticastBytes = 41, /* Byte count for dropped multicast
    193                                            traffic */
    194     bcmPolicerStatDropBroadcastPackets = 42, /* Packet count for dropped broadcast
    195                                            traffic */
    196     bcmPolicerStatDropBroadcastBytes = 43, /* Byte count for dropped broadcast
    197                                            traffic */
    198     bcmPolicerStatGreenPackets = 44,    /* Packet count for traffic marked green */
    199     bcmPolicerStatGreenBytes = 45,      /* Byte count for traffic marked green */
    200     bcmPolicerStatYellowPackets = 46,   /* Packet count for traffic marked
    201                                            yellow */
    202     bcmPolicerStatYellowBytes = 47,     /* Byte count for traffic marked yellow */
    203     bcmPolicerStatRedPackets = 48,      /* Packet count for traffic marked red */
    204     bcmPolicerStatRedBytes = 49,        /* Byte count for traffic marked red */
    205     bcmPolicerStatGlobalInRedColorPackets = 50, /* Global - packet count incoming
    206                                            traffic marked as red */
    207     bcmPolicerStatGlobalInRedColorBytes = 51, /* Global - byte count incoming traffic
    208                                            marked as red */
    209     bcmPolicerStatGlobalInBlackColorPackets = 52, /* Global - packet count incoming
    210                                            traffic marked as black */
    211     bcmPolicerStatGlobalInBlackColorBytes = 53, /* Global - byte count incoming traffic
    212                                            marked as black */
    213     bcmPolicerStatGlobalRejectPackets = 54, /* Global - packet count rejected
    214                                            traffic */
    215     bcmPolicerStatGlobalRejectBytes = 55, /* Global - byte count rejected traffic */
    216     bcmPolicerStatCount = 56            /* Always last */
    217 } bcm_policer_stat_t;
    218 
    219 #define BCM_POLICER_WITH_ID                 0x00000001 
    220 #define BCM_POLICER_REPLACE                 0x00000002 
    221 #define BCM_POLICER_COLOR_BLIND             0x00000004 
    222 #define BCM_POLICER_DROP_RED                0x00000008 
    223 #define BCM_POLICER_COLOR_MERGE_MASK        0x00000030 
    224 #define BCM_POLICER_COLOR_MERGE_AND         0x00000000 
    225 #define BCM_POLICER_COLOR_MERGE_OR          0x00000010 
    226 #define BCM_POLICER_COLOR_MERGE_DUAL        0x00000020 
    227 #define BCM_POLICER_MODE_BYTES              0x00000040 
    228 #define BCM_POLICER_MODE_PACKETS            0x00000080 
    229 #define BCM_POLICER_MAX_CKBITS_SEC_VALID    0x00000100 
    230 #define BCM_POLICER_MAX_PKBITS_SEC_VALID    0x00000200 
    231 #define BCM_POLICER_MACRO                   0x00000400 
    232 #define BCM_POLICER_EGRESS                  0x00000800 /* Allocate policer for
    233                                                           egress usage */
    234 #define BCM_POLICER_REGEX                   0x00001000 /* Allocate policer for
    235                                                           regex usage */
    236 #define BCM_POLICER_REPLACE_SHARED          0x00002000 /* Replace the profile
    237                                                           rather than the
    238                                                           configuration */
    239 #define BCM_POLICER_MIXED_MICRO_MACRO       0x00004000 /* Micro policer not
    240                                                           under the macro
    241                                                           envelope */
    242 #define BCM_POLICER_BW_SHARING_GROUP_START  0x00008000 /* Indicates that this
    243                                                           policer corresponds to
    244                                                           the start of the
    245                                                           bandwidth sharing
    246                                                           group(cascade chain) */
    247 #define BCM_POLICER_BW_SHARING_GROUP_END    0x00010000 /* Indicates that this
    248                                                           policer corresponds to
    249                                                           the end of the
    250                                                           bandwidth sharing
    251                                                           group(cascade chain) */
    252 #define BCM_POLICER_WITH_POOL_ID            0x00020000 /* Indicates that this
    253                                                           Policer needs to be
    254                                                           created with the given
    255                                                           meter pool id */
    256 #define BCM_POLICER_AS_PACKET_COUNTER       0x00040000 /* Indicates that this
    257                                                           Policer needs to be
    258                                                           created as packet
    259                                                           counter */
    260 #define BCM_POLICER_PKT_ADJ_HEADER_TRUNCATE 0x00080000 /*  Indicates that this
    261                                                           Policer needs to be
    262                                                           considerate of header
    263                                                           truncate adjustment */
    264 #define BCM_POLICER_APPLY_GLOBAL_POOL_ID    0x00100000 /*  Indicates that this
    265                                                           Policer needs to be
    266                                                           allocated from the
    267                                                           given global meter
    268                                                           pool id. */
    269 #define BCM_POLICER_LARGE_BUCKET_MODE       0x00200000 /*  if set, force policer
    270                                                           to use large bucket
    271                                                           mode */
    272 
    273 #define BCM_POLICER_GLOBAL_METER_SHARING_MODE_MIN_MAX 0x00000000 
    274 #define BCM_POLICER_GLOBAL_METER_SHARING_MODE_MIN 0x00000001 
    275 #define BCM_POLICER_GLOBAL_METER_SHARING_MODE_MAX 0x00000002 
    276 
    277 #define BCM_POLICER_GLOBAL_METER_ENVELOP_MICRO_FLOW 0x1        
    278 #define BCM_POLICER_GLOBAL_METER_ENVELOP_MACRO_FLOW 0x2        
    279 
    280 typedef struct bcm_policer_config_s {
    281     uint32 flags;                       /* BCM_POLICER_* Flags. */
    282     bcm_policer_mode_t mode;            /* Policer mode. */
    283     uint32 ckbits_sec;                  /* Committed rate (kbits per sec). */
    284     uint32 cbits_sec_lower;             /* Committed rate (lower digits; 0~999
    285                                            bits per sec). */
    286     uint32 max_ckbits_sec;              /* Maximum Committed rate (kbits per
    287                                            sec), Applicable only for cascade
    288                                            mode. */
    289     uint32 max_cbits_sec_lower;         /* Maximum Committed rate (lower digits;
    290                                            0~999 bits per sec). */
    291     uint32 ckbits_burst;                /* Committed burst size (kbits). */
    292     uint32 cbits_burst_lower;           /* Committed burst size (lower digits;
    293                                            0~999 bits). */
    294     uint32 pkbits_sec;                  /* Peak rate (kbits per sec). */
    295     uint32 pbits_sec_lower;             /* Peak rate (lower digits; 0~999 bits
    296                                            per sec). */
    297     uint32 max_pkbits_sec;              /* Maximum Peak rate (kbits per sec),
    298                                            Applicable only for cascade mode. */
    299     uint32 max_pbits_sec_lower;         /* Maximum Peak rate (lower digits;
    300                                            0~999 bits per sec). */
    301     uint32 pkbits_burst;                /* Peak burst size (kbits). */
    302     uint32 pbits_burst_lower;           /* Peak burst size (lower digits; 0~999
    303                                            bits). */
    304     uint32 kbits_current;               /* Current size (kbits). */
    305     uint32 bits_current_lower;          /* Current size (lower digits; 0~999
    306                                            bits). */
    307     uint32 action_id;                   /* Index of the global meter action
    308                                            entry */
    309     uint32 sharing_mode;                /* Meter sharing mode in case of Macro
    310                                            meter of Envelop */
    311     uint32 entropy_id;                  /* If set, indicate the configuration
    312                                            group the policer belongs to */
    313     bcm_policer_pool_t pool_id;         /* Meter Pool Id of the current policer */
    314     uint32 bucket_width;                /* Bucket width in bits of the current
    315                                            policer */
    316     uint32 token_gran;                  /* Token granularity of the current
    317                                            policer */
    318     uint32 bucket_init_val;             /* Initial bucket count of the current
    319                                            policer */
    320     uint32 bucket_rollover_val;         /* Rollover bucket count of the current
    321                                            policer */
    322     bcm_core_t core_id;                 /* Device core on which to allocate the
    323                                            policer */
    324     bcm_policer_t ncoflow_policer_id;   /* Next lower priority committed policer
    325                                            ID to overflow to. Applicable in
    326                                            Cascaded  policer modes on MEF 10.3+
    327                                            compliant devices */
    328     bcm_policer_t npoflow_policer_id;   /* Next lower priority peak policer ID
    329                                            to overflow to. Applicable in
    330                                            Cascaded and CoupledCascade policer
    331                                            modes on MEF 10.3+  compliant devices */
    332     uint32 actual_ckbits_sec;           /* Granularity adjusted Committed rate
    333                                            (kbits per sec). */
    334     uint32 actual_cbits_sec_lower;      /* Granularity adjusted Committed rate
    335                                            (lower digits; 0~999 bits per sec). */
    336     uint32 actual_ckbits_burst;         /* Granularity adjusted Committed burst
    337                                            size (kbits). */
    338     uint32 actual_cbits_burst_lower;    /* Granularity adjusted Committed burst
    339                                            size (lower digits; 0~999 bits). */
    340     uint32 actual_pkbits_sec;           /* Granularity adjusted Peak rate (kbits
    341                                            per sec). */
    342     uint32 actual_pbits_sec_lower;      /* Granularity adjusted Peak rate (lower
    343                                            digits; 0~999 bits per sec). */
    344     uint32 actual_pkbits_burst;         /* Granularity adjusted Peak burst size
    345                                            (kbits). */
    346     uint32 actual_pbits_burst_lower;    /* Granularity adjusted Peak burst size
    347                                            (lower digits; 0~999 bits). */
    348     uint32 average_pkt_size;            /* Estimated average Ethernet packet
    349                                            size (1 to 16383 Bytes) for more
    350                                            accurate metering. */
    351     int mark_drop_as_black;             /* For drop decision (no committed or
    352                                            Excess credits), mark it as black
    353                                            (otherwise, it will be marked as
    354                                            red). */
    355     int color_resolve_profile;          /* Input data for the resolved table. */
    356 } bcm_policer_config_t;
    357 
    358 typedef struct bcm_policer_aggregate_group_info_s {
    359     bcm_policer_group_mode_t mode;  /* Policer mode. */
    360     bcm_core_t core;                /* Device core on which to allocate the
    361                                        policer */
    362     uint32 flags;                   /* BCM_POLICER_* Flags. */
    363 } bcm_policer_aggregate_group_info_t;
    364 
    365 typedef struct bcm_policer_map_s {
    366     int count;          /* Number of offset mappings */
    367     uint8 *offset_map;  /* policer offset for each index */
    368 } bcm_policer_map_t;
    369 
    370 /* Initialize a policer map structure. */
    371 extern void bcm_policer_map_t_init(
    372     bcm_policer_map_t *offset_map);
    373 
    374 /* Initialize a policer config structure. */
    375 extern void bcm_policer_config_t_init(
    376     bcm_policer_config_t *pol_cfg);
    377 
    378 #ifndef BCM_HIDE_DISPATCHABLE
    379 
    380 /* Initialize policer module. */
    381 extern int bcm_policer_init(
    382     int unit);
    383 
    384 /* Create a policer entry. */
    385 extern int bcm_policer_create(
    386     int unit, 
    387     bcm_policer_config_t *pol_cfg, 
    388     bcm_policer_t *policer_id);
    389 
    390 /* Destroy a policer entry. */
    391 extern int bcm_policer_destroy(
    392     int unit, 
    393     bcm_policer_t policer_id);
    394 
    395 /* Destroy all policer entries. */
    396 extern int bcm_policer_destroy_all(
    397     int unit);
    398 
    399 /* Set the config settings for a policer entry. */
    400 extern int bcm_policer_set(
    401     int unit, 
    402     bcm_policer_t policer_id, 
    403     bcm_policer_config_t *pol_cfg);
    404 
    405 /* Get the config settings for a policer entry. */
    406 extern int bcm_policer_get(
    407     int unit, 
    408     bcm_policer_t policer_id, 
    409     bcm_policer_config_t *pol_cfg);
    410 
    411 /* Get the packet count for a policer entry. */
    412 extern int bcm_policer_packet_counter_get32(
    413     int unit, 
    414     bcm_policer_t policer_id, 
    415     uint32 *count);
    416 
    417 /* 
    418  * Resets count to initial value and gets the updated packet count for a
    419  * policer entry.
    420  */
    421 extern int bcm_policer_packet_reset_counter_get32(
    422     int unit, 
    423     bcm_policer_t policer_id, 
    424     uint32 *count);
    425 
    426 #endif /* BCM_HIDE_DISPATCHABLE */
    427 
    428 typedef int (*bcm_policer_traverse_cb)(
    429     int unit, 
    430     bcm_policer_t policer_id, 
    431     bcm_policer_config_t *info, 
    432     void *user_data);
    433 
    434 #ifndef BCM_HIDE_DISPATCHABLE
    435 
    436 /* 
    437  * Traverse all existing policer entries and call supplied callback
    438  * function.
    439  */
    440 extern int bcm_policer_traverse(
    441     int unit, 
    442     bcm_policer_traverse_cb cb, 
    443     void *user_data);
    444 
    445 /* 
    446  * Allocate a block of policer entries. Note that bcm_policer_set must be
    447  * called to setup the individual policers.
    448  */
    449 extern int bcm_policer_group_create(
    450     int unit, 
    451     bcm_policer_group_mode_t mode, 
    452     bcm_policer_t *policer_id, 
    453     int *npolicers);
    454 
    455 /* 
    456  * Allocate a block of policer entries. Note that bcm_policer_set must be
    457  * called to setup the individual policers.
    458  */
    459 extern int bcm_policer_aggregate_group_create(
    460     int unit, 
    461     bcm_policer_aggregate_group_info_t *info, 
    462     bcm_policer_t *policer_id, 
    463     int *npolicers);
    464 
    465 /* 
    466  * Allocate a block of policer entries. Note that bcm_policer_set must be
    467  * called to setup the individual policers.
    468  */
    469 extern int bcm_policer_group_create_with_map(
    470     int unit, 
    471     bcm_policer_group_mode_t mode, 
    472     bcm_policer_map_t *offset_map, 
    473     bcm_policer_t *policer_id, 
    474     int *num_policers);
    475 
    476 /* 
    477  * Allocate a policer for envelop meter. Depending on the flag a micro or
    478  * a macro meter is allocated. Note that bcm_policer_set must be called
    479  * to setup the individual policers.
    480  */
    481 extern int bcm_policer_envelop_create(
    482     int unit, 
    483     uint32 flag, 
    484     bcm_policer_t macro_flow_policer_id, 
    485     bcm_policer_t *policer_id);
    486 
    487 /* 
    488  * Allocate a group of policers for envelop meter. Depending on the flag
    489  * a micro or a macro meter is allocated. Note that bcm_policer_set must
    490  * be called to setup the individual policers. In case of macro meter
    491  * only PolicerGroupModeSingle is allowed
    492  */
    493 extern int bcm_policer_envelop_group_create(
    494     int unit, 
    495     uint32 flag, 
    496     bcm_policer_group_mode_t mode, 
    497     bcm_policer_t macro_flow_policer_id, 
    498     bcm_policer_t *policer_id, 
    499     int *npolicers);
    500 
    501 #endif /* BCM_HIDE_DISPATCHABLE */
    502 
    503 /* Policer group mode types */
    504 typedef enum bcm_policer_group_mode_type_e {
    505     bcmPolicerGroupModeTypeNormal = 0,  /* A group of n policers (max 256) which
    506                                            do not share bandwidth amongst each
    507                                            other */
    508     bcmPolicerGroupModeTypeCascade = 1, /* User specified set of n policers (max
    509                                            8), wherein excess bandwidth can
    510                                            overflow from high priority policers
    511                                            (i.e policer with higher index)bucket
    512                                            to low priority policers
    513                                            bucket(policer with next higher index
    514                                            in the group) */
    515     bcmPolicerGroupModeTypeCascadeWithCoupling = 2, /* User specified set of policers (max
    516                                            4),  wherein excess bandwidth can
    517                                            overflow from high priority (i.e
    518                                            policer with higher index)policers
    519                                            bucket to low priority bucket and
    520                                            from low priority green bucket to
    521                                            high priority yellow bucket */
    522     bcmPolicerGroupModeTypeCount = 3    /* Always last, Not to be used */
    523 } bcm_policer_group_mode_type_t;
    524 
    525 /* Vlan related policer attributes values */
    526 typedef enum bcm_policer_group_mode_attr_vlan_e {
    527     bcmPolicerGroupModeAttrVlanUnTagged = 1, /* UnTagged Vlan */
    528     bcmPolicerGroupModeAttrVlanInnerTag = 2, /* Inner Tagged Vlan */
    529     bcmPolicerGroupModeAttrVlanOuterTag = 3, /* Outer Tagged Vlan */
    530     bcmPolicerGroupModeAttrVlanStackedTag = 4, /* Both Inner and Outer Tagged Vlan */
    531     bcmPolicerGroupModeAttrVlanAll = 5  /* UnTagged,Inner and Outer Tagged Vlan */
    532 } bcm_policer_group_mode_attr_vlan_t;
    533 
    534 /* Packet type related policer attributes values */
    535 typedef enum bcm_policer_group_mode_attr_pkt_type_e {
    536     bcmPolicerGroupModeAttrPktTypeAll = 1, /* All Packet Types */
    537     bcmPolicerGroupModeAttrPktTypeUnknown = 2, /* Unknown Packet */
    538     bcmPolicerGroupModeAttrPktTypeControl = 3, /* Control Packet */
    539     bcmPolicerGroupModeAttrPktTypeOAM = 4, /* OAM Packet */
    540     bcmPolicerGroupModeAttrPktTypeBFD = 5, /* BFD Packet */
    541     bcmPolicerGroupModeAttrPktTypeBPDU = 6, /* BPDU Packet */
    542     bcmPolicerGroupModeAttrPktTypeICNM = 7, /* ICNM Packet */
    543     bcmPolicerGroupModeAttrPktType1588 = 8, /* 1588 Packet */
    544     bcmPolicerGroupModeAttrPktTypeKnownL2UC = 9, /* Known L2 Unicast Packet */
    545     bcmPolicerGroupModeAttrPktTypeUnknownL2UC = 10, /* Unknown L2 Unicast Packet */
    546     bcmPolicerGroupModeAttrPktTypeL2BC = 11, /* L2 Broadcast Packet */
    547     bcmPolicerGroupModeAttrPktTypeKnownL2MC = 12, /* Known L2 Multicast Packet */
    548     bcmPolicerGroupModeAttrPktTypeUnknownL2MC = 13, /* Unknown L2 Multicast Packet */
    549     bcmPolicerGroupModeAttrPktTypeKnownL3UC = 14, /* Known L3 Unicast Packet */
    550     bcmPolicerGroupModeAttrPktTypeUnknownL3UC = 15, /* Unknown L3 Unicast Packet */
    551     bcmPolicerGroupModeAttrPktTypeKnownIPMC = 16, /* Known IPMC Packet */
    552     bcmPolicerGroupModeAttrPktTypeUnknownIPMC = 17, /* Unknown IPMC Packet */
    553     bcmPolicerGroupModeAttrPktTypeKnownMplsL2 = 18, /* Known MPLS L2 Packet */
    554     bcmPolicerGroupModeAttrPktTypeKnownMplsL3 = 19, /* Known MPLS L3 Packet */
    555     bcmPolicerGroupModeAttrPktTypeKnownMpls = 20, /* Known MPLS Packet */
    556     bcmPolicerGroupModeAttrPktTypeUnknownMpls = 21, /* Unknown MPLS Packet */
    557     bcmPolicerGroupModeAttrPktTypeKnownMplsMulticast = 22, /* Known MPLS Multicast Packet */
    558     bcmPolicerGroupModeAttrPktTypeKnownMim = 23, /* Known MiM Packet */
    559     bcmPolicerGroupModeAttrPktTypeUnknownMim = 24, /* Unknown MiM Packet */
    560     bcmPolicerGroupModeAttrPktTypeKnownTrill = 25, /* Known TRILL Packet */
    561     bcmPolicerGroupModeAttrPktTypeUnknownTrill = 26, /* Unknown TRILL Packet */
    562     bcmPolicerGroupModeAttrPktTypeKnownNiv = 27, /* Known  NIV Packet */
    563     bcmPolicerGroupModeAttrPktTypeUnknownNiv = 28 /* Unknown  NIV Packet */
    564 } bcm_policer_group_mode_attr_pkt_type_t;
    565 
    566 /* Policer Group Mode Attribute Selectors */
    567 typedef enum bcm_policer_group_mode_attr_e {
    568     bcmPolicerGroupModeAttrUdf = 1,     /* UDF selector: Possible values:0 to
    569                                            2^N-1. Value of N may vary depending
    570                                            on device. */
    571     bcmPolicerGroupModeAttrFieldIngressColor = 2, /* Field Ingress Color Selector:
    572                                            Possible
    573                                            Values:bcmColorGreen|Yellow|REd or
    574                                            POLICER_GROUP_MODE_ATTR_ALL_VALUES
    575                                            for all */
    576     bcmPolicerGroupModeAttrIntPri = 3,  /* Internal Priority Selector: Possible
    577                                            Values: 0 to 15 or
    578                                            POLICER_GROUP_MODE_ATTR_ALL_VALUES
    579                                            for all */
    580     bcmPolicerGroupModeAttrVlan = 4,    /* Vlan Type Selector: Possible Values:
    581                                            bcmPolicerGroupModeVlanAttr */
    582     bcmPolicerGroupModeAttrOuterPri = 5, /* Outer Vlan Priority Selector:
    583                                            Possible Values: 0 to 7 or
    584                                            POLICER_GROUP_MODE_ATTR_ALL_VALUES
    585                                            for all */
    586     bcmPolicerGroupModeAttrInnerPri = 6, /* Inner Vlan Priority Selector:
    587                                            Possible Values: 0 to 7 or
    588                                            POLICER_GROUP_MODE_ATTR_ALL_VALUES
    589                                            for all */
    590     bcmPolicerGroupModeAttrPort = 7,    /* Logical Port Selector: Possible
    591                                            Values:<MaxLogicalPort> or
    592                                            POLICER_GROUP_MODE_ATTR_ALL_VALUES
    593                                            for all */
    594     bcmPolicerGroupModeAttrTosDscp = 8, /* Type Of Service Selector(DSCP :
    595                                            Differentiated services Code Point):
    596                                            Possible Values:<6b:TOS Val> or
    597                                            POLICER_GROUP_MODE_ATTR_ALL_VALUES
    598                                            for all */
    599     bcmPolicerGroupModeAttrTosEcn = 9,  /* Type Of Service Selector(ECN:
    600                                            Explicit Congestion Notification):
    601                                            Possible Values:<2b:TOS Val> or
    602                                            POLICER_GROUP_MODE_ATTR_ALL_VALUES
    603                                            for all */
    604     bcmPolicerGroupModeAttrPktType = 10, /* Packet Type Selector: Possible
    605                                            Values:<bcmPolicerGroupModeAttrPktType*> */
    606     bcmPolicerGroupModeAttrIngNetworkGroup = 11, /* Ingress Network Group Selector:
    607                                            Possible Values:<Value> or
    608                                            POLICER_GROUP_MODE_ATTR_ALL_VALUES
    609                                            for all */
    610     bcmPolicerGroupModeAttrDrop = 12,   /* Drop Selector: Possible Values:<0 or
    611                                            1> */
    612     bcmPolicerGroupModeAttrPacketTypeIp = 13, /* Ip Packet Selector: Possible
    613                                            Values:<0 or 1> */
    614     bcmPolicerGroupModeAttrPreemptable = 14, /* Preemptable Packet Selector: Possible
    615                                            Values:<0 or 1> */
    616     bcmPolicerGroupModeAttrEtherType = 15, /* Ether Type: Possible
    617                                            values:0x0-0xFFFF */
    618     bcmPolicerGroupModeAttrOuterVlanCfi = 16, /* Outer VLAN CFI: Possible Values:<0 or
    619                                            1> */
    620     bcmPolicerGroupModeAttrInnerVlanCfi = 17, /* Inner VLAN CFI: Possible Values:<0 or
    621                                            1> */
    622     bcmPolicerGroupModeAttrLast = 18,   /* Last value. Not to be used */
    623     bcmPolicerGroupModeAttrCount = bcmPolicerGroupModeAttrLast /* Last value. Not to be used */
    624 } bcm_policer_group_mode_attr_t;
    625 
    626 /* Unique constants */
    627 #define BCM_POLICER_GROUP_MODE_ATTR_ALL_VALUES 0xFFFFFFFF /* A unique constant for
    628                                                           using all attr values */
    629 
    630 /* packet attribute selector flags values */
    631 #define BCM_POLICER_ATTR_WIDTH_OFFSET   0x1        /* Offset and width fields
    632                                                       are valid for this
    633                                                       attribute */
    634 
    635 /* packet attribute selector flags values */
    636 #define BCM_POLICER_ATTR_VALUE_MASK 0x2        /* Mask is valid for this
    637                                                   attribute. Flags WIDTH_OFFSET
    638                                                   and MASK are mutually
    639                                                   exclusive */
    640 
    641 /* packet attribute selector flags values */
    642 #define BCM_POLICER_ATTR_MULTI  0x4        /* Matching multiple attributes in
    643                                               single selector. The
    644                                               policer_offset is chosen only if
    645                                               all attributes match */
    646 
    647 /* Policer Group Attribute Selector */
    648 typedef struct bcm_policer_group_mode_attr_selector_s {
    649     uint32 flags;                       /* packet attribute selector flags */
    650     uint32 policer_offset;              /* Policer Offset */
    651     bcm_policer_group_mode_attr_t attr; /* Attribute Selector */
    652     uint32 attr_value;                  /* Attribute Values */
    653     uint32 attr_value_mask;             /* Attribute Mask */
    654     int udf_id;                         /* UDF ID created using bcm_udf_create.
    655                                            Applicable only if Group mode
    656                                            attribute is
    657                                            bcmPolicerGroupModeAttrUdf. */
    658     uint32 offset;                      /* Offset in bits from the beginning of
    659                                            the packet attribute */
    660     uint32 width;                       /* Number of bits in packet attribute
    661                                            from offset to be used for policer
    662                                            offset mapping */
    663     uint32 multi_attr_count;            /* Number of multiple elements specified
    664                                            in all of the multi_attr_xxx[] array. */
    665     uint32 multi_attr_flags[bcmPolicerGroupModeAttrCount]; /* Attribute flags */
    666     bcm_policer_group_mode_attr_t multi_attr[bcmPolicerGroupModeAttrCount]; /* Attribute Selector */
    667     uint32 multi_attr_value[bcmPolicerGroupModeAttrCount]; /* Attribute Values */
    668     uint32 multi_attr_value_mask[bcmPolicerGroupModeAttrCount]; /* Attribute Mask */
    669     int multi_udf_id[bcmPolicerGroupModeAttrCount]; /* UDF ID created using bcm_udf_create.
    670                                            Applicable only if attribute is
    671                                            bcmPolicerGroupModeAttrUdf. */
    672     uint32 multi_offset[bcmPolicerGroupModeAttrCount]; /* Offset in bits from the beginning of
    673                                            the packet attribute */
    674     uint32 multi_width[bcmPolicerGroupModeAttrCount]; /* Number of bits in packet attribute
    675                                            from offset to be used */
    676 } bcm_policer_group_mode_attr_selector_t;
    677 
    678 /* Initialize the policer group attribute selector structure. */
    679 extern void bcm_policer_group_mode_attr_selector_t_init(
    680     bcm_policer_group_mode_attr_selector_t *pol_group_mode_attr_selector);
    681 
    682 #ifndef BCM_HIDE_DISPATCHABLE
    683 
    684 /* Create Customized policer group mode for given policer attributes */
    685 extern int bcm_policer_group_mode_id_create(
    686     int unit, 
    687     uint32 flags, 
    688     bcm_policer_group_mode_type_t type, 
    689     uint32 total_policers, 
    690     uint32 num_selectors, 
    691     bcm_policer_group_mode_attr_selector_t *attr_selectors, 
    692     uint32 *mode_id);
    693 
    694 /* Destroy policer group mode */
    695 extern int bcm_policer_group_mode_id_destroy(
    696     int unit, 
    697     uint32 mode_id);
    698 
    699 /* Retrieves policer group mode attributes for a given mode_id. */
    700 extern int bcm_policer_group_mode_id_get(
    701     int unit, 
    702     uint32 mode_id, 
    703     uint32 num_selectors, 
    704     uint32 *flags, 
    705     bcm_policer_group_mode_type_t *type, 
    706     uint32 *total_policers, 
    707     bcm_policer_group_mode_attr_selector_t *attr_selectors, 
    708     uint32 *actual_num_selectors);
    709 
    710 /* 
    711  * Allocate a block of policer entries. Note that bcm_policer_set must be
    712  * called to setup the individual policers.
    713  */
    714 extern int bcm_policer_custom_group_create(
    715     int unit, 
    716     uint32 flags, 
    717     uint32 mode_id, 
    718     bcm_policer_t macro_flow_policer_id, 
    719     bcm_policer_t *policer_id, 
    720     uint32 *npolicers);
    721 
    722 /* 
    723  * Get the list of policer members for a given policer group represented
    724  * by its base policer id
    725  */
    726 extern int bcm_policer_group_get(
    727     int unit, 
    728     bcm_policer_t base_policer_id, 
    729     int member_max, 
    730     bcm_policer_t *member_array, 
    731     int *member_count);
    732 
    733 /* 
    734  * Checks if statistics collection is enabled on the specified policer
    735  * id.
    736  */
    737 extern int bcm_policer_stat_enable_get(
    738     int unit, 
    739     bcm_policer_t policer_id, 
    740     int *enable);
    741 
    742 /* Enables statistics collection on the specified policer id. */
    743 extern int bcm_policer_stat_enable_set(
    744     int unit, 
    745     bcm_policer_t policer_id, 
    746     int enable);
    747 
    748 /* Gets the specified stat */
    749 extern int bcm_policer_stat_get(
    750     int unit, 
    751     bcm_policer_t policer_id, 
    752     bcm_cos_t int_pri, 
    753     bcm_policer_stat_t stat, 
    754     uint64 *value);
    755 
    756 /* 32bit version of stat get API */
    757 extern int bcm_policer_stat_get32(
    758     int unit, 
    759     bcm_policer_t policer_id, 
    760     bcm_cos_t int_pri, 
    761     bcm_policer_stat_t stat, 
    762     uint32 *value);
    763 
    764 /* Sets the specified stat */
    765 extern int bcm_policer_stat_set(
    766     int unit, 
    767     bcm_policer_t policer_id, 
    768     bcm_cos_t int_pri, 
    769     bcm_policer_stat_t stat, 
    770     uint64 value);
    771 
    772 /* 32bit version of stat set API */
    773 extern int bcm_policer_stat_set32(
    774     int unit, 
    775     bcm_policer_t policer_id, 
    776     bcm_cos_t int_pri, 
    777     bcm_policer_stat_t stat, 
    778     uint32 value);
    779 
    780 /* Attach policer action to a policer id */
    781 extern int bcm_policer_action_attach(
    782     int unit, 
    783     bcm_policer_t policer_id, 
    784     uint32 action_id);
    785 
    786 /* detach policer action from a policer id */
    787 extern int bcm_policer_action_detach(
    788     int unit, 
    789     bcm_policer_t policer_id, 
    790     uint32 action_id);
    791 
    792 /* Get the action id associated with a policer id */
    793 extern int bcm_policer_action_attach_get(
    794     int unit, 
    795     bcm_policer_t policer_id, 
    796     uint32 *action_id);
    797 
    798 #endif /* BCM_HIDE_DISPATCHABLE */
    799 
    800 /* Global meter policer actions */
    801 typedef enum bcm_policer_action_e {
    802     bcmPolicerActionGpDrop = 0,         /* Green priority drop */
    803     bcmPolicerActionGpDscpNew = 1,      /* Green packet change DSCP value
    804                                            param0: New DSCP value */
    805     bcmPolicerActionGpEcnNew = 2,       /* Green packet change ECN value param0:
    806                                            New ECN value */
    807     bcmPolicerActionGpPrioIntNew = 3,   /* Green packet internal priority from
    808                                            an argument. param0: New priority */
    809     bcmPolicerActionGpCngNew = 4,       /* Green packet change CNG */
    810     bcmPolicerActionGpVlanPrioNew = 5,  /* Green packet change vlan priority.
    811                                            param0: New priority */
    812     bcmPolicerActionYpDrop = 6,         /* Yellow priority drop */
    813     bcmPolicerActionYpDscpNew = 7,      /* Yellow packet change DSCP value
    814                                            param0: New DSCP value */
    815     bcmPolicerActionYpEcnNew = 8,       /* Yellow packet change ECN value
    816                                            param0: New ECN value */
    817     bcmPolicerActionYpPrioIntNew = 9,   /* Yellow packet internal priority from
    818                                            an argument. param0: New priority */
    819     bcmPolicerActionYpCngNew = 10,      /* Yellow packet change CNG */
    820     bcmPolicerActionYpVlanPrioNew = 11, /* Yellow packet change vlan priority.
    821                                            param0: New priority */
    822     bcmPolicerActionRpDrop = 12,        /* Red priority drop */
    823     bcmPolicerActionRpDscpNew = 13,     /* Red packet change DSCP value param0:
    824                                            New DSCP value */
    825     bcmPolicerActionRpEcnNew = 14,      /* Red packet change ECN value param0:
    826                                            New ECN value */
    827     bcmPolicerActionRpPrioIntNew = 15,  /* Red packet internal priority from an
    828                                            argument. param0: New priority */
    829     bcmPolicerActionRpCngNew = 16,      /* Red packet change CNG */
    830     bcmPolicerActionRpVlanPrioNew = 17, /* Red packet change vlan priority.
    831                                            param0: New priority */
    832     bcmPolicerActionGpIntCongestionNotificationNew = 18, /* Replace the internal congestion
    833                                            notification value of green packet.
    834                                            param0: Internal congestion
    835                                            notification value. */
    836     bcmPolicerActionYpIntCongestionNotificationNew = 19, /* Replace the internal congestion
    837                                            notification value of yellow packet.
    838                                            param0: Internal congestion
    839                                            notification value. */
    840     bcmPolicerActionRpIntCongestionNotificationNew = 20, /* Replace the internal congestion
    841                                            notification value of red packet.
    842                                            param0: Internal congestion
    843                                            notification value. */
    844     bcmPolicerActionCount = 21          /* Last value. Not to be used */
    845 } bcm_policer_action_t;
    846 
    847 #ifndef BCM_HIDE_DISPATCHABLE
    848 
    849 /* Create a new action entry in global meter action table */
    850 extern int bcm_policer_action_create(
    851     int unit, 
    852     uint32 *action_id);
    853 
    854 /* Delete an entry from meter action table */
    855 extern int bcm_policer_action_destroy(
    856     int unit, 
    857     uint32 action_id);
    858 
    859 /* Add an action to global meter action table entry */
    860 extern int bcm_policer_action_add(
    861     int unit, 
    862     uint32 action_id, 
    863     bcm_policer_action_t action, 
    864     uint32 param0);
    865 
    866 /* get action parameter for a given action */
    867 extern int bcm_policer_action_get(
    868     int unit, 
    869     uint32 action_id, 
    870     bcm_policer_action_t action, 
    871     uint32 *param0);
    872 
    873 #endif /* BCM_HIDE_DISPATCHABLE */
    874 
    875 /* Policer internal color */
    876 typedef enum bcm_policer_color_e {
    877     bcmPolicerColorGreen = 0,   /* Green color */
    878     bcmPolicerColorInvalid = 1, /* Invalid color */
    879     bcmPolicerColorYellow = 2,  /* Yellow color */
    880     bcmPolicerColorRed = 3      /* Red color */
    881 } bcm_policer_color_t;
    882 
    883 /* Policer color decision entry */
    884 typedef struct bcm_policer_color_decision_s {
    885     uint32 flags;                       /* color decision flags */
    886     bcm_policer_color_t policer0_color; /* policer-0 color decision */
    887     uint8 policer0_other_bucket_has_credits; /* if policer0_color is yellow, indicate
    888                                            if green bucket has credits,
    889                                            otherwise if yellow bucket has
    890                                            credits */
    891     bcm_policer_color_t policer1_color; /* policer-1 color decision */
    892     uint8 policer1_other_bucket_has_credits; /* if policer1_color is yellow, indicate
    893                                            if green bucket has credits,
    894                                            otherwise if yellow bucket has
    895                                            credits */
    896     int policer0_mark_drop_as_black;    /* if policer0 decision is drop,
    897                                            indicate if it is marked black or
    898                                            red. */
    899     int policer1_mark_drop_as_black;    /* if policer1 decision is drop,
    900                                            indicate if it is marked black or
    901                                            red. */
    902     bcm_policer_color_t policer0_update_bucket; /* the policer-0 bucket to update */
    903     bcm_policer_color_t policer1_update_bucket; /* the policer-1 bucket to update */
    904     bcm_color_t policer_color;          /* policer color decision */
    905 } bcm_policer_color_decision_t;
    906 
    907 /* Policer color resolution entry */
    908 typedef struct bcm_policer_color_resolution_s {
    909     uint32 flags;                       /* color resolution flags */
    910     uint32 policer_action;              /* policer command */
    911     bcm_color_t incoming_color;         /* incoming color */
    912     bcm_color_t ethernet_policer_color; /* ethernet policer color */
    913     bcm_color_t policer_color;          /* policer color */
    914     bcm_color_t ingress_color;          /* ingress color */
    915     bcm_color_t egress_color;           /* egress color */
    916 } bcm_policer_color_resolution_t;
    917 
    918 #ifndef BCM_HIDE_DISPATCHABLE
    919 
    920 /* Sets a policer color decision table entry */
    921 extern int bcm_policer_color_decision_set(
    922     int unit, 
    923     bcm_policer_color_decision_t *policer_color_decision);
    924 
    925 /* Gets a policer color decision table entry */
    926 extern int bcm_policer_color_decision_get(
    927     int unit, 
    928     bcm_policer_color_decision_t *policer_color_decision);
    929 
    930 /* Sets a policer color resolution table entry */
    931 extern int bcm_policer_color_resolution_set(
    932     int unit, 
    933     bcm_policer_color_resolution_t *policer_color_resolution);
    934 
    935 /* Gets a policer color resolution table entry */
    936 extern int bcm_policer_color_resolution_get(
    937     int unit, 
    938     bcm_policer_color_resolution_t *policer_color_resolution);
    939 
    940 #endif /* BCM_HIDE_DISPATCHABLE */
    941 
    942 /* Sources of global metering. */
    943 typedef enum bcm_policer_global_meter_source_e {
    944     bcmPolicerGlobalMeterSourceFieldStageLookup = 0, /* VFP - Field Stage Lookup */
    945     bcmPolicerGlobalMeterSourceDstMac = 1, /* Destination MAC Address Lookup */
    946     bcmPolicerGlobalMeterSourceSrcMac = 2, /* Source MAC Address Lookup */
    947     bcmPolicerGlobalMeterSourceVlanTranslateFirst = 3, /* VLAN Translation First Lookup */
    948     bcmPolicerGlobalMeterSourceVlanTranslateSecond = 4, /* VLAN Translation Second Lookup */
    949     bcmPolicerGlobalMeterSourceVlan = 5, /* Outer VLAN ID Matched */
    950     bcmPolicerGlobalMeterSourcePort = 6, /* Ingress Port Matched */
    951     bcmPolicerGlobalMeterSourceCount = 7 /* Always last */
    952 } bcm_policer_global_meter_source_t;
    953 
    954 /* bcm policer global meter configuration structure */
    955 typedef struct bcm_policer_global_meter_config_s {
    956     uint8 ifg_enable;                   /* Enable Inter Frame Gap(IFG) for
    957                                            incoming packet length in global
    958                                            metering. The IFG value is configured
    959                                            by switch API
    960                                            bcmSwitchMeterAdjustInterframeGap
    961                                            (per port). 0 = Disable, 1 = Enable. */
    962     bcm_policer_global_meter_source_t source_order[bcmPolicerGlobalMeterSourceCount]; /* Specify global metering sources in
    963                                            the order or precedence. Source at
    964                                            array index 0 has highest precedence. */
    965     uint32 source_order_count;          /* Valid index count in source_order
    966                                            array. */
    967 } bcm_policer_global_meter_config_t;
    968 
    969 /* Initialize a Global Meter Configuration structure */
    970 extern void bcm_policer_global_meter_config_t_init(
    971     bcm_policer_global_meter_config_t *config);
    972 
    973 #ifndef BCM_HIDE_DISPATCHABLE
    974 
    975 /* Sets Global Meter Configuration */
    976 extern int bcm_policer_global_meter_config_set(
    977     int unit, 
    978     bcm_policer_global_meter_config_t *config);
    979 
    980 /* Gets Global Meter Configuration */
    981 extern int bcm_policer_global_meter_config_get(
    982     int unit, 
    983     bcm_policer_global_meter_config_t *config);
    984 
    985 #endif /* BCM_HIDE_DISPATCHABLE */
    986 
    987 /* Enum to select the scope of the policer. */
    988 typedef enum bcm_policer_scope_e {
    989     bcmPolicerScopeIngressGlobal = 0, 
    990     bcmPolicerScopeIngress = 1, 
    991     bcmPolicerScopeEgress = 2 
    992 } bcm_policer_scope_t;
    993 
    994 /* Forwarding types enum. */
    995 typedef enum bcm_policer_fwd_types_e {
    996     bcmPolicerFwdTypeUc = 0, 
    997     bcmPolicerFwdTypeUnkownUc = 1, 
    998     bcmPolicerFwdTypeMc = 2, 
    999     bcmPolicerFwdTypeUnkownMc = 3, 
   1000     bcmPolicerFwdTypeBc = 4, 
   1001     bcmPolicerFwdTypeMax = 5 
   1002 } bcm_policer_fwd_types_t;
   1003 
   1004 /* 
   1005  * Structure hold the for each forwarding type the offset in the
   1006  * expansion group and if to do meter on it or not.
   1007  */
   1008 typedef struct bcm_policer_expansion_group_types_config_s {
   1009     int offset; /* Offset in expansion group */
   1010     int valid;  /* If not valid, packet with this type will be filtered. */
   1011 } bcm_policer_expansion_group_types_config_t;
   1012 
   1013 /* 
   1014  * Structure holds the policer expansion groups, according the forwarding
   1015  * types.
   1016  */
   1017 typedef struct bcm_policer_expansion_group_s {
   1018     bcm_policer_expansion_group_types_config_t config[bcmPolicerFwdTypeMax]; 
   1019 } bcm_policer_expansion_group_t;
   1020 
   1021 #ifndef BCM_HIDE_DISPATCHABLE
   1022 
   1023 /* 
   1024  * API Defines groups of L2 Fwd-Types and decide if to count them and in
   1025  * which offset in the expansion to count them.
   1026  */
   1027 extern int bcm_policer_expansion_groups_set(
   1028     int unit, 
   1029     int flags, 
   1030     bcm_core_t core_id, 
   1031     bcm_policer_expansion_group_t *expansion_group);
   1032 
   1033 /* API gets the expansion groups of L2 Fwd-Types. */
   1034 extern int bcm_policer_expansion_groups_get(
   1035     int unit, 
   1036     int flags, 
   1037     bcm_core_t core_id, 
   1038     bcm_policer_expansion_group_t *expansion_group);
   1039 
   1040 #endif /* BCM_HIDE_DISPATCHABLE */
   1041 
   1042 /* Structure holds configuration per policer database. */
   1043 typedef struct bcm_policer_database_config_s {
   1044     int expansion_enable;   /* Allowed to ingress database 0. if enabled,
   1045                                expansion size, filter and offsets will be  made
   1046                                according API bcm_policer_expansion_groups_set. */
   1047     int is_single_bucket;   /* Single or dual bucket mode. */
   1048 } bcm_policer_database_config_t;
   1049 
   1050 #ifndef BCM_HIDE_DISPATCHABLE
   1051 
   1052 /* 
   1053  * API create a policer database (sw create). database represent the
   1054  * meter processor belong to one of the meter commands.It gets as input
   1055  * database handler which gather the key parameters: core, scope,
   1056  * database_id
   1057  */
   1058 extern int bcm_policer_database_create(
   1059     int unit, 
   1060     int flags, 
   1061     int policer_database_handle, 
   1062     bcm_policer_database_config_t *config);
   1063 
   1064 /* API destroy a policer database */
   1065 extern int bcm_policer_database_destroy(
   1066     int unit, 
   1067     int flags, 
   1068     int policer_database_handle);
   1069 
   1070 #endif /* BCM_HIDE_DISPATCHABLE */
   1071 
   1072 /* Enum holds the policer control types. */
   1073 typedef enum bcm_policer_control_type_e {
   1074     bcmPolicerControlTypeFilterByDpCommand = 0, /* Filter meter pointers according the
   1075                                            dp command. It is a bitmap. */
   1076     bcmPolicerControlTypeDpResolutionByDpCommand = 1, /* select the input for the resolve
   1077                                            table: policer-profile or dp-command.
   1078                                            This type is per ingress/egress only
   1079                                            and not per database. */
   1080     bcmPolicerControlTypeCountBytes = 2 /* Select if to count bytes or packets
   1081                                            in the internal policer stats.
   1082                                            (default=packets). */
   1083 } bcm_policer_control_type_t;
   1084 
   1085 #ifndef BCM_HIDE_DISPATCHABLE
   1086 
   1087 /* 
   1088  * API which contain several policer control types that can be
   1089  * configured.
   1090  */
   1091 extern int bcm_policer_control_set(
   1092     int unit, 
   1093     int flags, 
   1094     int policer_database_handle, 
   1095     bcm_policer_control_type_t type, 
   1096     uint32 arg);
   1097 
   1098 /* API get the value of one of the control types. */
   1099 extern int bcm_policer_control_get(
   1100     int unit, 
   1101     int flags, 
   1102     int policer_database_handle, 
   1103     bcm_policer_control_type_t type, 
   1104     uint32 *arg);
   1105 
   1106 #endif /* BCM_HIDE_DISPATCHABLE */
   1107 
   1108 /* Enum to select the section in the policer-crps shared memory engines. */
   1109 typedef enum bcm_policer_engine_section_e {
   1110     bcmPolicerEngineSectionAll = 0, 
   1111     bcmPolicerEngineSectionLow = 1, 
   1112     bcmPolicerEngineSectionHigh = 2 
   1113 } bcm_policer_engine_section_t;
   1114 
   1115 /* Structure holds the policer memory engine key configuration. */
   1116 typedef struct bcm_policer_engine_s {
   1117     int core_id; 
   1118     int engine_id;                      /* Same units as the crps engines. valid
   1119                                            engines are the ones that are shared
   1120                                            with crps: 0,1,16,17,18,19,20,21. */
   1121     bcm_policer_engine_section_t section; /* When using dual bucket moode, must
   1122                                            use 'All'. */
   1123 } bcm_policer_engine_t;
   1124 
   1125 /* 
   1126  * Structure define the database that the engine will attached to and its
   1127  * base stat pointer.
   1128  */
   1129 typedef struct bcm_policer_database_attach_config_s {
   1130     int policer_database_handle;    /* Database handle defines the database that
   1131                                        engine belong to. */
   1132     int object_stat_pointer_base;   /* Resolution after expansion. */
   1133 } bcm_policer_database_attach_config_t;
   1134 
   1135 #ifndef BCM_HIDE_DISPATCHABLE
   1136 
   1137 /* API attach one engine (or half engine) to a policer database. */
   1138 extern int bcm_policer_engine_database_attach(
   1139     int unit, 
   1140     int flags, 
   1141     bcm_policer_engine_t *engine, 
   1142     bcm_policer_database_attach_config_t *config);
   1143 
   1144 /* API gets per engine (or half engine), the database it attached to. */
   1145 extern int bcm_policer_engine_database_get(
   1146     int unit, 
   1147     int flags, 
   1148     bcm_policer_engine_t *engine, 
   1149     bcm_policer_database_attach_config_t *config);
   1150 
   1151 /* 
   1152  * API detach one engine (or half engine) from a policer database. From
   1153  * this point, it can be used to crps or other policer database.
   1154  */
   1155 extern int bcm_policer_engine_database_detach(
   1156     int unit, 
   1157     int flags, 
   1158     bcm_policer_engine_t *engine);
   1159 
   1160 /* API enable/disable policer database. */
   1161 extern int bcm_policer_database_enable_set(
   1162     int unit, 
   1163     int flags, 
   1164     int policer_database_handle, 
   1165     int enable);
   1166 
   1167 /* API gets if policer database is enabled or disabled. */
   1168 extern int bcm_policer_database_enable_get(
   1169     int unit, 
   1170     int flags, 
   1171     int policer_database_handle, 
   1172     int *enable);
   1173 
   1174 #endif /* BCM_HIDE_DISPATCHABLE */
   1175 
   1176 #define BCM_COLOR_RESOLUTION_EGRESS 0x1        /* Refer to egress meter final
   1177                                                   resolve table. (default is
   1178                                                   ingress) */
   1179 
   1180 /* Structure holds the data of each single meter. */
   1181 typedef struct bcm_policer_color_data_s {
   1182     bcm_policer_color_t policer_color;  /* Meter color decision. */
   1183     int policer_other_bucket_has_credits; /* If policer0_color is yellow, indicate
   1184                                            if green bucket has credits,otherwise
   1185                                            if yellow bucket has credits. */
   1186 } bcm_policer_color_data_t;
   1187 
   1188 /* Structure holds the entire key for the color resolution table. */
   1189 typedef struct bcm_policer_primary_color_resolution_key_s {
   1190     bcm_core_t core_id; 
   1191     int is_ingress; 
   1192     int action;                         /* Holds the DP-CMD data or the meter
   1193                                            profile data (depend on
   1194                                            configuration). */
   1195     bcm_policer_color_data_t color_data[3]; /* Color data per meter. For egress,
   1196                                            only 2 are relevant. */
   1197 } bcm_policer_primary_color_resolution_key_t;
   1198 
   1199 /* Holds all the outputs of the resolve table. */
   1200 typedef struct bcm_policer_primary_color_resolution_config_s {
   1201     int policer_count[3];               /* Is to count the policer. */
   1202     bcm_color_t policer_color[3];       /* The color which will be marked for
   1203                                            the counter (if counted). */
   1204     bcm_policer_color_t policer_update_bucket[3]; /* The policer bucket to update. */
   1205     bcm_color_t resolved_color;         /* The resolved color (or color
   1206                                            decision). */
   1207 } bcm_policer_primary_color_resolution_config_t;
   1208 
   1209 #ifndef BCM_HIDE_DISPATCHABLE
   1210 
   1211 /* 
   1212  * API configure one entry of the color resolved table (the first/primary
   1213  * table).
   1214  */
   1215 extern int bcm_policer_primary_color_resolution_set(
   1216     int unit, 
   1217     int flags, 
   1218     bcm_policer_primary_color_resolution_key_t *key, 
   1219     bcm_policer_primary_color_resolution_config_t *config);
   1220 
   1221 /* 
   1222  * API get one entry of the color resolved table (the first/primary
   1223  * table).
   1224  */
   1225 extern int bcm_policer_primary_color_resolution_get(
   1226     int unit, 
   1227     int flags, 
   1228     bcm_policer_primary_color_resolution_key_t *key, 
   1229     bcm_policer_primary_color_resolution_config_t *config);
   1230 
   1231 #endif /* BCM_HIDE_DISPATCHABLE */
   1232 
   1233 /* init bcm_policer_primary_color_resolution_key_t */
   1234 extern void bcm_policer_primary_color_resolution_key_t_init(
   1235     bcm_policer_primary_color_resolution_key_t *policer_primary_color_resolution_key);
   1236 
   1237 /* init bcm_policer_primary_color_resolution_config_t */
   1238 extern void bcm_policer_primary_color_resolution_config_t_init(
   1239     bcm_policer_primary_color_resolution_config_t *policer_primary_color_resolution_config);
   1240 
   1241 /* init bcm_policer_engine_t */
   1242 extern void bcm_policer_engine_t_init(
   1243     bcm_policer_engine_t *policer_engine);
   1244 
   1245 /* init bcm_policer_database_attach_config_t */
   1246 extern void bcm_policer_database_attach_config_t_init(
   1247     bcm_policer_database_attach_config_t *policer_database_attach_config);
   1248 
   1249 /* init bcm_policer_database_config_t */
   1250 extern void bcm_policer_database_config_t_init(
   1251     bcm_policer_database_config_t *policer_database_config);
   1252 
   1253 /* init bcm_policer_expansion_group_t */
   1254 extern void bcm_policer_expansion_group_t_init(
   1255     bcm_policer_expansion_group_t *policer_expansion_group);
   1256 
   1257 /* init bcm_policer_color_resolution_t */
   1258 extern void bcm_policer_color_resolution_t_init(
   1259     bcm_policer_color_resolution_t *policer_color_resolution);
   1260 
   1261 /* Direction of entries allocation in hardware. */
   1262 typedef enum bcm_policer_group_direction_e {
   1263     bcmPolicerGroupDirectionVertical = 0, /* Entries allocation within pool */
   1264     bcmPolicerGroupDirectionHorizontal = 1 /* Entries allocation across pool */
   1265 } bcm_policer_group_direction_t;
   1266 
   1267 /* Policer group information */
   1268 typedef struct bcm_policer_group_info_s {
   1269     bcm_policer_t policer_id;           /* Policer Identifier. */
   1270     bcm_policer_group_direction_t direction; /* Direction of allocation of entries */
   1271     uint32 mode_id;                     /* Policer group mode identifier. */
   1272     bcm_policer_group_mode_t mode;      /* Policer group mode. */
   1273     uint32 pool_id;                     /* Pool number of allocated entries. If
   1274                                            direction is vertical, it represent
   1275                                            pool in which all entries are
   1276                                            allocated. If direction is
   1277                                            horizontal, it is always 0. */
   1278     uint32 base_offset;                 /* In vertical allocation, it represents
   1279                                            offset of Base policer Index from the
   1280                                            start of pool. In horizontal
   1281                                            direction, it represents offset of
   1282                                            each policers allocated from start of
   1283                                            their respective pool. */
   1284     uint32 num_policers;                /* Number of policers allocated in the
   1285                                            group. */
   1286     uint32 num_offset_reserved;         /* Number of entries reserved in the
   1287                                            hardware. Direction along with this
   1288                                            value provide information of how
   1289                                            entries are allocated */
   1290     bcm_policer_t macro_policer_id;     /* Macro policer of the policer group. */
   1291 } bcm_policer_group_info_t;
   1292 
   1293 /* Initialize bcm_policer_group_info_t */
   1294 extern void bcm_policer_group_info_t_init(
   1295     bcm_policer_group_info_t *policer_group_info);
   1296 
   1297 #ifndef BCM_HIDE_DISPATCHABLE
   1298 
   1299 /* Create a custom policer group with given mode_id. */
   1300 extern int bcm_policer_custom_group_id_create(
   1301     int unit, 
   1302     uint32 flags, 
   1303     uint32 mode_id, 
   1304     bcm_policer_t macro_flow_policer_id, 
   1305     bcm_policer_group_info_t *policer_group_info);
   1306 
   1307 /* Copy Policer group from old hardware location to new */
   1308 extern int bcm_policer_custom_group_id_copy(
   1309     int unit, 
   1310     bcm_policer_group_info_t *old_policer_group_info, 
   1311     bcm_policer_group_info_t *new_policer_group_info);
   1312 
   1313 #endif /* BCM_HIDE_DISPATCHABLE */
   1314 
   1315 #endif /* __BCM_POLICER_H__ */