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

keygen_api.h (52594B)


      1 /*
      2  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      3  * 
      4  * Copyright 2007-2020 Broadcom Inc. All rights reserved.
      5  */
      6 
      7 #ifndef _BCM_INT_FIELD_KEYGEN_API_H
      8 #define _BCM_INT_FIELD_KEYGEN_API_H
      9 
     10 #include <sal/types.h>
     11 #include <shared/bsl.h>
     12 #include <shared/bitop.h>
     13 #include <bcm/field.h>
     14 #include <bcm/types.h>
     15 #include <bcm/error.h>
     16 #include <sal/core/libc.h>
     17 #include <sal/core/alloc.h>
     18 #include <bcm_int/esw/keygen_error.h>
     19 
     20 /* Maxmimum number of slices occupied by any
     21  * keygen mode in any device.
     22  */
     23 #define BCMI_KEYGEN_ENTRY_PARTS_MAX 4
     24 
     25 /* Different keygen modes */
     26 typedef enum bcmi_keygen_mode_e {
     27      /* Mode HALF. This mode will have half of the key
     28       * size of SINGLE mode.
     29       */
     30     BCMI_KEYGEN_MODE_HALF = 0,
     31      /* Single wide mode which uses one slice only */
     32     BCMI_KEYGEN_MODE_SINGLE = 1,
     33      /* Single wide mode which uses one slice only,
     34       * but have narrow ASET. Used in EM HASH FP.
     35       */
     36     BCMI_KEYGEN_MODE_SINGLE_ASET_NARROW = 2,
     37      /* Single wide mode which uses one slice only,
     38       * but have wider ASET. Used in EM HASH FP.
     39       */
     40     BCMI_KEYGEN_MODE_SINGLE_ASET_WIDE = 3,
     41     /* Uses single slice but key size is double the key
     42      * size of SINGLE mode.
     43      */
     44     BCMI_KEYGEN_MODE_DBLINTRA = 4,
     45     /* Uses two slices and key size is double the key
     46      * size of SINGLE mode.
     47      */
     48     BCMI_KEYGEN_MODE_DBLINTER = 5,
     49     /* Uses two slices and key size is triple the key
     50      * size of SINGLE mode.
     51      */
     52     BCMI_KEYGEN_MODE_TRIPLE = 6,
     53     /* Uses two slices and key size is four times the key
     54      * size of SINGLE mode.
     55      */
     56     BCMI_KEYGEN_MODE_QUAD = 7,
     57     /* Always Last. Not a usable value. */
     58     BCMI_KEYGEN_MODE_COUNT = 8
     59 } bcmi_keygen_mode_t;
     60 
     61 /* extractor attributes used to validity of extractor configuration
     62  * for a given keygen mode and qualifer list.
     63  * Note: enumerations in bcmi_keygen_ext_attr_t must have 1-to-1
     64  * mapping with enumerations in bcmi_keygen_acl_attr_t.
     65  */
     66 typedef enum bcmi_keygen_ext_attr_s {
     67      /* Extractor can operate in multiple granularities. */
     68     BCMI_KEYGEN_EXT_ATTR_MULTI_GRAN = 0,
     69     /* Extractor can operate in granularity 1 */
     70     BCMI_KEYGEN_EXT_ATTR_MULTI_GRAN_1,
     71     /* Extractor can operate in granularity 2 */
     72     BCMI_KEYGEN_EXT_ATTR_MULTI_GRAN_2,
     73     /* Extractor can operate in granularity 4 */
     74     BCMI_KEYGEN_EXT_ATTR_MULTI_GRAN_4,
     75     /* Extractor can operate in granularity 8 */
     76     BCMI_KEYGEN_EXT_ATTR_MULTI_GRAN_8,
     77     /* Extractor can operate in granularity 16 */
     78     BCMI_KEYGEN_EXT_ATTR_MULTI_GRAN_16,
     79     /* Extractor can operate in granularity 32 */
     80     BCMI_KEYGEN_EXT_ATTR_MULTI_GRAN_32,
     81     /* Extractor is extracts bits from the pass through section. */
     82     BCMI_KEYGEN_EXT_ATTR_PASS_THRU,
     83     /* Extractor cannot be used when keygen mode is HALF */
     84     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_MODE_HALF,
     85     /* Extractor cannot be used if IPBM is part of final key. */
     86     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_PMUX_IPBM,
     87     /* Extractor cannot be used if SRC_DST_CONT_0 LSB 16bits
     88      * (Total length is 17 bits), is part of final key.
     89      */
     90     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_PMUX_SRC_DST_CONT_0,
     91     /* Extractor cannot be used if SRC_DST_CONT_1 LSB 16bits
     92      * (Total length is 17 bits), is part of final key.
     93      */
     94     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_PMUX_SRC_DST_CONT_1,
     95     /* Extractor cannot be used if MSB bits of SRC_DST_CONT_0
     96      * (or) SRC_DST_CONT_1, is part of the final key.
     97      */
     98     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_PMUX_SRC_DST_CONT_MSB,
     99     /* Extractor cannot be used if SRC_DST_CONT_0 LSB 16bits
    100      * (Total length is 17 bits), is part of final key of
    101      * HALF(80bit) mode group.
    102      */
    103     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_PMUX_SRC_DST_CONT_0_HM,
    104     /* Extractor cannot be used if SRC_DST_CONT_1 LSB 16bits
    105      * (Total length is 17 bits), is part of final key of
    106      * HALF(80bit) mode group.
    107      */
    108     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_PMUX_SRC_DST_CONT_1_HM,
    109     /* Extractor cannot be used if MSB bits of SRC_DST_CONT_0
    110      * (or) SRC_DST_CONT_1, is part of the final key of HALF
    111      * (80bit) mode group.
    112      */
    113     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_PMUX_SRC_DST_CONT_MSB_HM,
    114     /* Extractor cannot be used if post mux qualifier, Drop,
    115      * is present in the QSET.
    116      */
    117     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_PMUX_DROP,
    118     /* Extractor cannot be used if LSB 4 bits of class id, generated
    119      * in second lookup of Exact Match Rules, are part of the final key.
    120      */
    121     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_PMUX_EM_SECOND_LOOKUP_CLASSID_BITS_0_3,
    122     /* Extractor cannot be used if middle 4 bits of class id, generated
    123      * in second lookup of Exact Match Rules, are part of the final key.
    124      */
    125     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_PMUX_EM_SECOND_LOOKUP_CLASSID_BITS_4_7,
    126     /* Extractor cannot be used if MSB 4 bits of class id, generated
    127      * in second lookup of Exact Match Rules, are part of the final key.
    128      */
    129     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_PMUX_EM_SECOND_LOOKUP_CLASSID_BITS_8_11,
    130     /* Extractor cannot be used if LSB 4 bits of class id, generated
    131      * in first lookup of Exact Match Rules, are part of the final key.
    132      */
    133     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_PMUX_EM_FIRST_LOOKUP_CLASSID_BITS_0_3,
    134     /* Extractor cannot be used if middle 4 bits of class id, generated
    135      * in first lookup of Exact Match Rules, are part of the final key.
    136      */
    137     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_PMUX_EM_FIRST_LOOKUP_CLASSID_BITS_4_7,
    138     /* Extractor cannot be used if MSB 4 bits of class id, generated
    139      * in first lookup of Exact Match Rules, are part of the final key.
    140      */
    141     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_PMUX_EM_FIRST_LOOKUP_CLASSID_BITS_8_11,
    142     /* Extractor cannot be used if post mux qualifier, HIT status from Exact
    143      * Match first lookup,  is present in the QSET.
    144      */
    145     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_PMUX_EM_FIRST_LOOKUP_HIT,
    146     /* Extractor cannot be used if post mux qualifier, HIT status from Exact
    147      * Match second lookup,  is present in the QSET.
    148      */
    149     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_PMUX_EM_SECOND_LOOKUP_HIT,
    150     /* Extractor cannot be used if post mux qualifier, NatNeeded,
    151      * is present in the QSET.
    152      */
    153     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_PMUX_NAT_NEEDED,
    154     /* Extractor cannot be used if post mux qualifier, NatDstRealmId,
    155      * is present in the QSET.
    156      */
    157     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_PMUX_NAT_DST_REALM_ID,
    158     /* Extractor cannot be used if LSB 4 bits of lookup status vector,
    159      * are part of the final key.
    160      */
    161     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_PMUX_LOOKUP_STATUS_VECTOR_BITS_0_3,
    162     /* Extractor cannot be used if MSB 4 bits of lookup status vector,
    163      * are part of the final key.
    164      */
    165     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_PMUX_LOOKUP_STATUS_VECTOR_BITS_4_7,
    166     /* Extractor cannot be used if 17 bits of SRC_DST_CONT_A
    167      * is part of the final key.
    168      */
    169     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_PMUX_DST_CONTAINER_A,
    170     /* Extractor cannot be used if 17 bits of SRC_DST_CONT_B
    171      * is part of the final key.
    172      */
    173     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_PMUX_DST_CONTAINER_B,
    174     /* Extractor cannot be used if post mux qualifier, PacketRes,
    175      * is present in the QSET.
    176      */
    177     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_PMUX_PKT_RESOLUTION,
    178     /* Extractor cannot be used if 16 bits of CLASS_ID C
    179      * container is part of the final key.
    180      */
    181     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_PMUX_CLASS_ID_C,
    182     /* Extractor cannot be used if 16 bits of CLASS_ID D
    183      * container is part of the final key.
    184      */
    185     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_PMUX_CLASS_ID_D,
    186     /* Extractor cannot be used if post mux qualifier,
    187      * Internal Priority, is present in the QSET.
    188      */
    189     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_PMUX_INT_PRI,
    190     /* Extractor cannot be used if drop Reasons generated in
    191      * ingress pipeline before IFP are part of final key.
    192      */
    193     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_PMUX_IFP_DROP_VECTOR,
    194     /* Extractor cannot be used if post mux qualifier,
    195      * HiGiG header opcode, is present in the QSET.
    196      */
    197     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_PMUX_MH_OPCODE,
    198     /* Extractor cannot be used if keygen mode is EM_128. */
    199     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_MODE_SINGLE_ASET_WIDE,
    200     /* Extractor cannot be used if keygen algorithm is called for
    201      * QSET update.
    202      */
    203     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_QSET_UPDATE,
    204 
    205     BCMI_KEYGEN_EXT_ATTR_NOT_WITH_PMUX_LTID,
    206     /* Always Last. Not a usable value. */
    207     BCMI_KEYGEN_EXT_ATTR_COUNT
    208 } bcmi_keygen_ext_attr_t;
    209 
    210 /* Bitmap of extractor attributes. */
    211 typedef struct bcmi_keygen_ext_attrs_s {
    212     SHR_BITDCL w[_SHR_BITDCLSIZE(BCMI_KEYGEN_EXT_ATTR_COUNT)];
    213 } bcmi_keygen_ext_attrs_t;
    214 
    215 /* All the different qualifier controls to serve all keygen blocks
    216  * in different chips.
    217  */
    218 typedef enum bcmi_keygen_ext_ctrl_sel_e {
    219     /* Selector disabled. */
    220     BCMI_KEYGEN_EXT_CTRL_SEL_DISABLE            = 0,
    221     /* Auxiliary Tag A selector. */
    222     BCMI_KEYGEN_EXT_CTRL_SEL_AUX_TAG_A          = 1,
    223     /* Auxiliary Tag B selector. */
    224     BCMI_KEYGEN_EXT_CTRL_SEL_AUX_TAG_B          = 2,
    225     /* Auxiliary Tag C selector. */
    226     BCMI_KEYGEN_EXT_CTRL_SEL_AUX_TAG_C          = 3,
    227     /* Auxiliary Tag D selector. */
    228     BCMI_KEYGEN_EXT_CTRL_SEL_AUX_TAG_D          = 4,
    229     /* TCP function selector. */
    230     BCMI_KEYGEN_EXT_CTRL_SEL_TCP_FN             = 5,
    231     /* ToS function selector. */
    232     BCMI_KEYGEN_EXT_CTRL_SEL_TOS_FN             = 6,
    233     /* TTL function selector. */
    234     BCMI_KEYGEN_EXT_CTRL_SEL_TTL_FN             = 7,
    235     /* Class ID container A selector. */
    236     BCMI_KEYGEN_EXT_CTRL_SEL_CLASSID_A          = 8,
    237     /* Class ID container B selector. */
    238     BCMI_KEYGEN_EXT_CTRL_SEL_CLASSID_B          = 9,
    239     /* Class ID container C selector. */
    240     BCMI_KEYGEN_EXT_CTRL_SEL_CLASSID_C          = 10,
    241     /* Class ID container D selector. */
    242     BCMI_KEYGEN_EXT_CTRL_SEL_CLASSID_D          = 11,
    243     /* Source Container A selector. */
    244     BCMI_KEYGEN_EXT_CTRL_SEL_SRC_A              = 12,
    245     /* Source Container B selector. */
    246     BCMI_KEYGEN_EXT_CTRL_SEL_SRC_B              = 13,
    247     /* Src/Dst Container 0 selector. */
    248     BCMI_KEYGEN_EXT_CTRL_SEL_SRC_DST_0          = 14,
    249     /* Src/Dst Container 1 selector. */
    250     BCMI_KEYGEN_EXT_CTRL_SEL_SRC_DST_1          = 15,
    251     /* IPBM Source. */
    252     BCMI_KEYGEN_EXT_CTRL_SEL_IPBM_PRESENT       = 16,
    253     /* Multiplexer in extractor hierarchy. */
    254     BCMI_KEYGEN_EXT_CTRL_SEL_MULTIPLEXER        = 17,
    255     /* Normalize L3 and L4 addresses. */
    256     BCMI_KEYGEN_EXT_CTRL_SEL_L3_L4_NORM         = 18,
    257     /* Normalize Mac address. */
    258     BCMI_KEYGEN_EXT_CTRL_SEL_MAC_NORM           = 19,
    259     /* PostMux Qualifier. */
    260     BCMI_KEYGEN_EXT_CTRL_SEL_PMUX               = 20,
    261     /* UDF Qualifiers. */
    262     BCMI_KEYGEN_EXT_CTRL_SEL_UDF                = 21,
    263     /* Destination Container A selector. */
    264     BCMI_KEYGEN_EXT_CTRL_SEL_DST_A              = 22,
    265     /* Destination Container B selector. */
    266     BCMI_KEYGEN_EXT_CTRL_SEL_DST_B              = 23,
    267     /* ALT TTL function selector. */
    268     BCMI_KEYGEN_EXT_CTRL_SEL_ALT_TTL_FN         = 24,
    269     /* LTID function selector. */
    270     BCMI_KEYGEN_EXT_CTRL_SEL_LTID               = 25,
    271     /* ING_FIELD_BUS Container selector. */
    272     BCMI_KEYGEN_EXT_CTRL_SEL_ING_FBUS_CONT      = 26,
    273     /* Always Last. Not a usable value. */
    274     BCMI_KEYGEN_EXT_CTRL_SEL_COUNT              = 27
    275 } bcmi_keygen_ext_ctrl_sel_t;
    276 
    277 /* All the different hairarchical bus sections to
    278  * serve all keygen blocks in different chips.
    279  */
    280 typedef enum bcmi_keygen_ext_section_e {
    281     /* Selector disabled. */
    282     BCMI_KEYGEN_EXT_SECTION_DISABLE = 0,
    283     /* Level-1 32 bit extractor. */
    284     BCMI_KEYGEN_EXT_SECTION_L1E32,
    285     /* Level-1 16 bit extractor. */
    286     BCMI_KEYGEN_EXT_SECTION_L1E16,
    287     /* Level-1 8 bit extractor. */
    288     BCMI_KEYGEN_EXT_SECTION_L1E8,
    289     /* Level-1 4 bit extractor. */
    290     BCMI_KEYGEN_EXT_SECTION_L1E4,
    291     /* Level-1 2 bit extractor. */
    292     BCMI_KEYGEN_EXT_SECTION_L1E2,
    293     /* Level-2 1st extractor section. */
    294     BCMI_KEYGEN_EXT_SECTION_L2S1,
    295     /* Level-2 2nd extractor section. */
    296     BCMI_KEYGEN_EXT_SECTION_L2S2,
    297     /* Level-2 3rd extractor section. */
    298     BCMI_KEYGEN_EXT_SECTION_L2S3,
    299     /* Level-2 4th extractor section. */
    300     BCMI_KEYGEN_EXT_SECTION_L2S4,
    301     /* Level-2 5th extractor section. */
    302     BCMI_KEYGEN_EXT_SECTION_L2S5,
    303     /* Level-2 6th extractor section. */
    304     BCMI_KEYGEN_EXT_SECTION_L2S6,
    305     /* Level-2 7th extractor section. */
    306     BCMI_KEYGEN_EXT_SECTION_L2S7,
    307     /* Level-2 8th extractor section. */
    308     BCMI_KEYGEN_EXT_SECTION_L2S8,
    309     /* Level-2 9th extractor section. */
    310     BCMI_KEYGEN_EXT_SECTION_L2S9,
    311     /* Level-2 10th extractor section. */
    312     BCMI_KEYGEN_EXT_SECTION_L2S10,
    313     /* Level-3 1st extractor section. */
    314     BCMI_KEYGEN_EXT_SECTION_L3S1,
    315     /* Level-3 2nd extractor section. */
    316     BCMI_KEYGEN_EXT_SECTION_L3S2,
    317     /* Level-3 3rd extractor section. */
    318     BCMI_KEYGEN_EXT_SECTION_L3S3,
    319     /* Level-3 4th extractor section. */
    320     BCMI_KEYGEN_EXT_SECTION_L3S4,
    321     /* Level-3 5th extractor section. */
    322     BCMI_KEYGEN_EXT_SECTION_L3S5,
    323     /* Level-3 6th extractor section. */
    324     BCMI_KEYGEN_EXT_SECTION_L3S6,
    325     /* Level-3 7th extractor section. */
    326     BCMI_KEYGEN_EXT_SECTION_L3S7,
    327     /* Level-3 8th extractor section. */
    328     BCMI_KEYGEN_EXT_SECTION_L3S8,
    329     /* Level-3 9th extractor section. */
    330     BCMI_KEYGEN_EXT_SECTION_L3S9,
    331     /* Level-3 10th extractor section. */
    332     BCMI_KEYGEN_EXT_SECTION_L3S10,
    333     /* Level-2 Slice A 1st extractor section. */
    334     BCMI_KEYGEN_EXT_SECTION_L2AS1,
    335     /* Level-2 Slice A 2nd extractor section. */
    336     BCMI_KEYGEN_EXT_SECTION_L2AS2,
    337     /* Level-2 Slice A 3rd extractor section. */
    338     BCMI_KEYGEN_EXT_SECTION_L2AS3,
    339     /* Level-2 Slice A 4th extractor section. */
    340     BCMI_KEYGEN_EXT_SECTION_L2AS4,
    341     /* Level-2 Slice A 5th extractor section. */
    342     BCMI_KEYGEN_EXT_SECTION_L2AS5,
    343     /* Level-2 Slice A 6th extractor section. */
    344     BCMI_KEYGEN_EXT_SECTION_L2AS6,
    345     /* Level-2 Slice A 7th extractor section. */
    346     BCMI_KEYGEN_EXT_SECTION_L2AS7,
    347     /* Level-2 Slice A 8th extractor section. */
    348     BCMI_KEYGEN_EXT_SECTION_L2AS8,
    349     /* Level-2 Slice A 9th extractor section. */
    350     BCMI_KEYGEN_EXT_SECTION_L2AS9,
    351     /* Level-2 Slice A 10th extractor section. */
    352     BCMI_KEYGEN_EXT_SECTION_L2AS10,
    353     /* Level-2 Slice B 1st extractor section. */
    354     BCMI_KEYGEN_EXT_SECTION_L2BS1,
    355     /* Level-2 Slice B 2nd extractor section. */
    356     BCMI_KEYGEN_EXT_SECTION_L2BS2,
    357     /* Level-2 Slice B 3rd extractor section. */
    358     BCMI_KEYGEN_EXT_SECTION_L2BS3,
    359     /* Level-2 Slice B 4th extractor section. */
    360     BCMI_KEYGEN_EXT_SECTION_L2BS4,
    361     /* Level-2 Slice B 5th extractor section. */
    362     BCMI_KEYGEN_EXT_SECTION_L2BS5,
    363     /* Level-2 Slice B 6th extractor section. */
    364     BCMI_KEYGEN_EXT_SECTION_L2BS6,
    365     /* Level-2 Slice B 7th extractor section. */
    366     BCMI_KEYGEN_EXT_SECTION_L2BS7,
    367     /* Level-2 Slice B 8th extractor section. */
    368     BCMI_KEYGEN_EXT_SECTION_L2BS8,
    369     /* Level-2 Slice B 9th extractor section. */
    370     BCMI_KEYGEN_EXT_SECTION_L2BS9,
    371     /* Level-2 Slice B 10th extractor section. */
    372     BCMI_KEYGEN_EXT_SECTION_L2BS10,
    373     /* Level-2 Slice C 1st extractor section. */
    374     BCMI_KEYGEN_EXT_SECTION_L2CS1,
    375     /* Level-2 Slice C 2nd extractor section. */
    376     BCMI_KEYGEN_EXT_SECTION_L2CS2,
    377     /* Level-2 Slice C 3rd extractor section. */
    378     BCMI_KEYGEN_EXT_SECTION_L2CS3,
    379     /* Level-2 Slice C 4th extractor section. */
    380     BCMI_KEYGEN_EXT_SECTION_L2CS4,
    381     /* Level-2 Slice C 5th extractor section. */
    382     BCMI_KEYGEN_EXT_SECTION_L2CS5,
    383     /* Level-2 Slice C 6th extractor section. */
    384     BCMI_KEYGEN_EXT_SECTION_L2CS6,
    385     /* Level-2 Slice C 7th extractor section. */
    386     BCMI_KEYGEN_EXT_SECTION_L2CS7,
    387     /* Level-2 Slice C 8th extractor section. */
    388     BCMI_KEYGEN_EXT_SECTION_L2CS8,
    389     /* Level-2 Slice C 9th extractor section. */
    390     BCMI_KEYGEN_EXT_SECTION_L2CS9,
    391     /* Level-2 Slice C 10th extractor section. */
    392     BCMI_KEYGEN_EXT_SECTION_L2CS10,
    393     /* Level-3 Slice A 1st extractor section. */
    394     BCMI_KEYGEN_EXT_SECTION_L3AS1,
    395     /* Level-3 Slice A 2nd extractor section. */
    396     BCMI_KEYGEN_EXT_SECTION_L3AS2,
    397     /* Level-3 Slice A 3rd extractor section. */
    398     BCMI_KEYGEN_EXT_SECTION_L3AS3,
    399     /* Level-3 Slice A 4th extractor section. */
    400     BCMI_KEYGEN_EXT_SECTION_L3AS4,
    401     /* Level-3 Slice A 5th extractor section. */
    402     BCMI_KEYGEN_EXT_SECTION_L3AS5,
    403     /* Level-3 Slice A 6th extractor section. */
    404     BCMI_KEYGEN_EXT_SECTION_L3AS6,
    405     /* Level-3 Slice A 7th extractor section. */
    406     BCMI_KEYGEN_EXT_SECTION_L3AS7,
    407     /* Level-3 Slice A 8th extractor section. */
    408     BCMI_KEYGEN_EXT_SECTION_L3AS8,
    409     /* Level-3 Slice A 9th extractor section. */
    410     BCMI_KEYGEN_EXT_SECTION_L3AS9,
    411     /* Level-3 Slice A 10th extractor section. */
    412     BCMI_KEYGEN_EXT_SECTION_L3AS10,
    413     /* Level-3 Slice B 1st extractor section. */
    414     BCMI_KEYGEN_EXT_SECTION_L3BS1,
    415     /* Level-3 Slice B 2nd extractor section. */
    416     BCMI_KEYGEN_EXT_SECTION_L3BS2,
    417     /* Level-3 Slice B 3rd extractor section. */
    418     BCMI_KEYGEN_EXT_SECTION_L3BS3,
    419     /* Level-3 Slice B 4th extractor section. */
    420     BCMI_KEYGEN_EXT_SECTION_L3BS4,
    421     /* Level-3 Slice B 5th extractor section. */
    422     BCMI_KEYGEN_EXT_SECTION_L3BS5,
    423     /* Level-3 Slice B 6th extractor section. */
    424     BCMI_KEYGEN_EXT_SECTION_L3BS6,
    425     /* Level-3 Slice B 7th extractor section. */
    426     BCMI_KEYGEN_EXT_SECTION_L3BS7,
    427     /* Level-3 Slice B 8th extractor section. */
    428     BCMI_KEYGEN_EXT_SECTION_L3BS8,
    429     /* Level-3 Slice B 9th extractor section. */
    430     BCMI_KEYGEN_EXT_SECTION_L3BS9,
    431     /* Level-3 Slice B 10th extractor section. */
    432     BCMI_KEYGEN_EXT_SECTION_L3BS10,
    433     /* Level3 Slice C 1st extractor section. */
    434     BCMI_KEYGEN_EXT_SECTION_L3CS1,
    435     /* Level-3 Slice C 2nd extractor section. */
    436     BCMI_KEYGEN_EXT_SECTION_L3CS2,
    437     /* Level-3 Slice C 3rd extractor section. */
    438     BCMI_KEYGEN_EXT_SECTION_L3CS3,
    439     /* Level-3 Slice C 4th extractor section. */
    440     BCMI_KEYGEN_EXT_SECTION_L3CS4,
    441     /* Level-3 Slice C 5th extractor section. */
    442     BCMI_KEYGEN_EXT_SECTION_L3CS5,
    443     /* Level-3 Slice C 6th extractor section. */
    444     BCMI_KEYGEN_EXT_SECTION_L3CS6,
    445     /* Level-3 Slice C 7th extractor section. */
    446     BCMI_KEYGEN_EXT_SECTION_L3CS7,
    447     /* Level-3 Slice C 8th extractor section. */
    448     BCMI_KEYGEN_EXT_SECTION_L3CS8,
    449     /* Level-3 Slice C 9th extractor section. */
    450     BCMI_KEYGEN_EXT_SECTION_L3CS9,
    451     /* Level-3 Slice C 10th extractor section. */
    452     BCMI_KEYGEN_EXT_SECTION_L3CS10,
    453     /* Final Key Section. */
    454     BCMI_KEYGEN_EXT_SECTION_FK,
    455     /* Slice A Final Key section. */
    456     BCMI_KEYGEN_EXT_SECTION_FKA,
    457     /* Slice B Final Key section. */
    458     BCMI_KEYGEN_EXT_SECTION_FKB,
    459     /* Slice C Final Key section. */
    460     BCMI_KEYGEN_EXT_SECTION_FKC,
    461     /* Section for post Mux qualifier "Ingress Port bitmap"
    462      * in the final key. */
    463     BCMI_KEYGEN_EXT_SECTION_IPBM,
    464     /* Section for post Mux qualifier "DROP"
    465      * in the final key. */
    466     BCMI_KEYGEN_EXT_SECTION_DROP,
    467     /* Section for post Mux qualifier "NAT Needed"
    468      * in the final key. */
    469     BCMI_KEYGEN_EXT_SECTION_NAT_NEEDED,
    470     /* Section for post Mux qualifier "NAT destination realm Id"
    471      * in the final key. */
    472     BCMI_KEYGEN_EXT_SECTION_NAT_DST_REALMID,
    473     /* Section for post Mux qualifier "HIT status of first
    474      * lookup in Exact Match rules" in the final key.
    475      */
    476     BCMI_KEYGEN_EXT_SECTION_EM_FIRST_LOOKUP_HIT,
    477     /* Section for post Mux qualifier "HIT status of second
    478      * lookup in Exact Match rules" in the final key.
    479      */
    480     BCMI_KEYGEN_EXT_SECTION_EM_SECOND_LOOKUP_HIT,
    481     /* Section for post Mux qualifier "LSB 4 bits of 12 Class Id
    482      * generated in first lookup in Exact Match rules" in the
    483      * final key.
    484      */
    485     BCMI_KEYGEN_EXT_SECTION_EM_FIRST_LOOKUP_CLASSID_BITS_0_3,
    486     /* Section for post Mux qualifier "bits 4 - 7 of 12 Class Id
    487      * generated in first lookup in Exact Match rules" in the
    488      * final key.
    489      */
    490     BCMI_KEYGEN_EXT_SECTION_EM_FIRST_LOOKUP_CLASSID_BITS_4_7,
    491     /* Section for post Mux qualifier "bits 8 - 11 of 12 Class Id
    492      * generated in first lookup in Exact Match rules" in the
    493      * final key.
    494      */
    495     BCMI_KEYGEN_EXT_SECTION_EM_SECOND_LOOKUP_CLASSID_BITS_8_11,
    496     /* Section for post Mux qualifier "LSB 4 bits of 12 Class Id
    497      * generated in second lookup in Exact Match rules" in the
    498      * final key.
    499      */
    500     BCMI_KEYGEN_EXT_SECTION_EM_SECOND_LOOKUP_CLASSID_BITS_0_3,
    501     /* Section for post Mux qualifier "bits 4 - 7 of 12 Class Id
    502      * generated in second lookup in Exact Match rules" in the
    503      * final key.
    504      */
    505     BCMI_KEYGEN_EXT_SECTION_EM_SECOND_LOOKUP_CLASSID_BITS_4_7,
    506     /* Section for post Mux qualifier "bits 8 - 11 of 12 Class Id
    507      * generated in second lookup in Exact Match rules" in the
    508      * final key.
    509      */
    510     BCMI_KEYGEN_EXT_SECTION_EM_FIRST_LOOKUP_CLASSID_BITS_8_11,
    511     /* Section for post Mux qualifiers LSB 16 bits, sharing the
    512      * source destination container 0, in the final key.
    513      */
    514     BCMI_KEYGEN_EXT_SECTION_SRC_DST_CONTAINER_0,
    515     /* Section for post Mux qualifiers LSB 16 bits, sharing the
    516      * source destination container 1, in the final key.
    517      */
    518     BCMI_KEYGEN_EXT_SECTION_SRC_DST_CONTAINER_1,
    519     /* Section for post Mux qualifiers MSB bit, sharing the source
    520      * destination container 0/1, in the final key.
    521      */
    522     BCMI_KEYGEN_EXT_SECTION_SRC_DST_CONTAINERS_MSB,
    523     /* Section for post Mux qualifier Lookup up status vectors
    524      * LSB 4 bits in the final key.
    525      */
    526     BCMI_KEYGEN_EXT_SECTION_LOOKUP_STATUS_VECTOR_BITS_0_3,
    527     /* Section for post Mux qualifier Lookup up status vectors
    528      * MSB 4 bits in the final key.
    529      */
    530     BCMI_KEYGEN_EXT_SECTION_LOOKUP_STATUS_VECTOR_BITS_4_7,
    531     /* Section for post Mux qualifiers, sharing the destination
    532      * container 0(all 17 bits), in the final key.
    533      */
    534     BCMI_KEYGEN_EXT_SECTION_DST_CONTAINER_A,
    535     /* Section for post Mux qualifiers, sharing the destination
    536      * container 1(all 17 bits), in the final key.
    537      */
    538     BCMI_KEYGEN_EXT_SECTION_DST_CONTAINER_B,
    539     /* Section for post Mux qualifier packet resolution
    540      * in the final key.
    541      */
    542     BCMI_KEYGEN_EXT_SECTION_PKT_RESOLUTION,
    543     /* Section for post Mux qualifiers, sharing the class id
    544      * container C, in the final key.
    545      */
    546     BCMI_KEYGEN_EXT_SECTION_CLASS_ID_C,
    547     /* Section for post Mux qualifiers, sharing the class id
    548      * container D, in the final key.
    549      */
    550     BCMI_KEYGEN_EXT_SECTION_CLASS_ID_D,
    551     /* Section for post Mux qualifier internal priority
    552      * in the final key.
    553      */
    554     BCMI_KEYGEN_EXT_SECTION_INT_PRI,
    555     /* Section for post Mux qualifier "drop reason codes in
    556      * pipeline fed to IFP" in the final key.
    557      */
    558     BCMI_KEYGEN_EXT_SECTION_IFP_DROP_VECTOR,
    559     /* Section for post Mux qualifier "HiGiG header opcode"
    560      * in the final key.
    561      */
    562     BCMI_KEYGEN_EXT_SECTION_MH_OPCODE,
    563     /* Section for post Mux qualifier "IP Type"
    564      * in the final key. */
    565     BCMI_KEYGEN_EXT_SECTION_LTID,
    566     /* Always Last. Not a usable value. */
    567     BCMI_KEYGEN_EXT_SECTION_COUNT
    568 } bcmi_keygen_ext_section_t;
    569 
    570 /* extractor control information */
    571 typedef struct bcmi_keygen_ext_ctrl_sel_info_s {
    572     /* Extractor control type. */
    573     bcmi_keygen_ext_ctrl_sel_t ctrl_sel;
    574     /* Selector value */
    575     uint8 ctrl_sel_val;
    576     /* part to which this selector belongs to */
    577     uint8 part;
    578     /* extractor hierarchy level. May not be required for all types
    579      * of extractor controls.
    580      */
    581     uint8 level;
    582     /* Granularity of the extractor. May not be required for all types
    583      *  of extractor controls.
    584      */
    585     uint8 gran;
    586     /* Extractor number. May not be required for all types
    587      *  of extractor controls.
    588      */
    589     uint16 ext_num;
    590 } bcmi_keygen_ext_ctrl_sel_info_t;
    591 
    592 /* Maximum number of extractor hirerachy levels on any device */
    593 #define BCMI_KEYGEN_EXT_LEVEL_COUNT 5
    594 
    595 /* Single extractor configuration. */
    596 typedef struct bcmi_keygen_ext_cfg_s {
    597     /* Run time field used to know whether the extractor
    598      * is already used or not. By default it is set to zero.
    599      */
    600     uint8  in_use;
    601     /* Extractor Id which holds 4 tuple (part, level, granularity, extractor number)
    602      * information of an extractor.
    603      * 10 bits[0 - 9]  = entractor number.
    604      * 8 bits[10 - 17] = granularity.
    605      * 4 bits[18 - 21] = hierarchy level.
    606      * 2 bits[29 - 31] = part(If extractor database is for multi wide modes).
    607      */
    608     uint32 ext_id;
    609     /* Input section from which this extractor will extract fields. */
    610     bcmi_keygen_ext_section_t in_sec;
    611     /* Output section to which this extractor will fed fields. */
    612     bcmi_keygen_ext_section_t out_sec;
    613    /* Offset of the extracted field in the output section */
    614    uint16 offset;
    615     /* Extractor attributes used to validate the extractor configuration
    616      * for the given keygen mode and qualifiers that needs to be extracted.
    617      */
    618    bcmi_keygen_ext_attrs_t ext_attrs;
    619 
    620    /* Used internally by the keygen algorithm. */
    621    void *finfo;
    622 } bcmi_keygen_ext_cfg_t;
    623 
    624 /* Extractor section Configuration */
    625 typedef struct bcmi_keygen_ext_section_cfg_s {
    626     /* Section Flags. Currently there is one flag created
    627      * BCMI_KEYGEN_EXT_SECTION_PASS_THRU.
    628      */
    629     uint32 flags;
    630     /* Section identifier. */
    631     bcmi_keygen_ext_section_t sec;
    632     /* Section size in bits */
    633     /* Parent section identifier */
    634     bcmi_keygen_ext_section_t parent_sec;
    635     int drain_bits;
    636     /* This field is used in runtime to avoid pushing more bits
    637      * than drain_bits.
    638      */
    639     int fill_bits;
    640     /* Generally it is set to 1. If section has any extractor
    641      * which can operate in multiple granularities, then this can
    642      * be more than 1.
    643      */
    644     uint16 ext_cfg_combinations;
    645 } bcmi_keygen_ext_section_cfg_t;
    646 
    647 /* Extractor database for a particular keygen mode */
    648 typedef struct bcmi_keygen_ext_cfg_db_s {
    649     /* Total number of extractor levels */
    650     uint8 num_ext_levels;
    651      /* keygen mode for which this extractor database is used.  */
    652     bcmi_keygen_mode_t mode;
    653      /* Extractors configuration in each extractor hierarchy.   */
    654     bcmi_keygen_ext_cfg_t *ext_cfg[BCMI_KEYGEN_EXT_LEVEL_COUNT];
    655      /* Number of extractor configurations in each extractor hierarchy.  */
    656     uint16 conf_size[BCMI_KEYGEN_EXT_LEVEL_COUNT];
    657     /* Extractor sections configuration */
    658     bcmi_keygen_ext_section_cfg_t *sec_cfg[BCMI_KEYGEN_EXT_SECTION_COUNT];
    659     /* Number of valid section configurations in this database.  */
    660     uint16 num_sec;
    661 } bcmi_keygen_ext_cfg_db_t;
    662 
    663 /*
    664  * Extractor ID construction macro.
    665  */
    666 #define BCMI_KEYGEN_EXT_ID_CREATE(_p_, _l_, _g_, _e_num_, _e_id_)              \
    667     (_e_id_) = (((_p_) << 28) |  ((_l_) << 18) | ((_g_) << 10)  |  (_e_num_))
    668 
    669 /*
    670  * Parse an Extractor ID and get the extractor level, granularity and
    671  * extractor number information.
    672  */
    673 #define BCMI_KEYGEN_EXT_ID_PARSE(_e_id_, _p_, _l_, _g_, _e_num_)      \
    674                                 (_e_num_) = ((_e_id_) & 0x3ff);       \
    675                                 (_g_) = (((_e_id_) >> 10) & 0xff);    \
    676                                 (_l_) = (((_e_id_) >> 18) & 0xf);     \
    677                                 (_p_) = (((_e_id_) >> 28) & 0x3)
    678 
    679 #define BCMI_KEYGEN_EXT_ID_PART_GET(_ext_id_)  (((_ext_id_) >> 28) & 0x3)
    680 #define BCMI_KEYGEN_EXT_ID_GRAN_GET(_ext_id_)  (((_ext_id_) >> 10) & 0xff)
    681 #define BCMI_KEYGEN_EXT_ID_LEVEL_GET(_ext_id_) (((_ext_id_) >> 18) & 0xf)
    682 #define BCMI_KEYGEN_EXT_ID_NUM_GET(_ext_id_)   ((_ext_id_) & 0x3ff)
    683 
    684 #define BCMI_KEYGEN_EXT_ID_GRAN_SET(_ext_id_, gran)   \
    685                   (_ext_id_) &= ~(0xFF << 10);        \
    686                   (_ext_id_) |= ((gran & 0xff) << 10)
    687 
    688 #define BCMI_KEYGEN_EXT_ATTR_IDX_TO_GRAN(attr_idx, gran)              \
    689                switch (attr_idx) {                                    \
    690                    case 0:                                            \
    691                        gran = 1;                                      \
    692                        break;                                         \
    693                    case 1:                                            \
    694                        gran = 2;                                      \
    695                        break;                                         \
    696                    case 2:                                            \
    697                        gran = 4;                                      \
    698                        break;                                         \
    699                    case 3:                                            \
    700                        gran = 8;                                      \
    701                        break;                                         \
    702                    case 4:                                            \
    703                        gran = 16;                                     \
    704                        break;                                         \
    705                    case 5:                                            \
    706                        gran = 32;                                     \
    707                        break;                                         \
    708                    default:                                           \
    709                        BCMI_KEYGEN_RETURN_VAL_EXIT(BCM_E_INTERNAL);   \
    710                }
    711 
    712 #define BCMI_KEYGEN_EXT_GRAN_TO_ATTR_IDX(gran, attr_idx)              \
    713                switch (gran) {                                        \
    714                    case 1:                                            \
    715                        attr_idx = 0;                                  \
    716                        break;                                         \
    717                    case 2:                                            \
    718                        attr_idx = 1;                                  \
    719                        break;                                         \
    720                    case 4:                                            \
    721                        attr_idx = 2;                                  \
    722                        break;                                         \
    723                    case 8:                                            \
    724                        attr_idx = 3;                                  \
    725                        break;                                         \
    726                    case 16:                                           \
    727                        attr_idx = 4;                                  \
    728                        break;                                         \
    729                    case 32:                                           \
    730                        attr_idx = 5;                                  \
    731                        break;                                         \
    732                    default:                                           \
    733                        BCMI_KEYGEN_RETURN_VAL_EXIT(BCM_E_INTERNAL);   \
    734                }
    735 
    736 /* BCMI_KEYGEN_EXT_CFG_ADD macro needs the following declaration
    737  * in any function that uses it.
    738  */
    739 #define BCMI_KEYGEN_EXT_CFG_DECL            \
    740     int _rv_;                               \
    741     int _ext_id_ = 0;                       \
    742     bcmi_keygen_ext_cfg_t _ext_cfg_
    743 
    744 /*
    745  * Extractor hierarcy construction utility macro.
    746  */
    747 #define BCMI_KEYGEN_EXT_CFG_ADD(_unit_, _ext_cfg_db_,                          \
    748                                 _p_, _l_, _g_, _e_num_,                        \
    749                                 _in_sec_, _out_sec_,                           \
    750                                 _offset_, _ext_attrs_)                         \
    751             do {                                                               \
    752                 _rv_ = bcmi_keygen_ext_cfg_t_init(unit, &_ext_cfg_);           \
    753                 if (BCMI_KEYGEN_FAILURE(_rv_)) {                               \
    754                     BCMI_KEYGEN_RETURN_VAL_EXIT(_rv_);                         \
    755                 }                                                              \
    756                 BCMI_KEYGEN_EXT_ID_CREATE(_p_, _l_, _g_, _e_num_, _ext_id_);   \
    757                 (_ext_cfg_).ext_id = (_ext_id_);                               \
    758                 (_ext_cfg_).in_sec = (_in_sec_);                               \
    759                 (_ext_cfg_).out_sec = (_out_sec_);                             \
    760                 (_ext_cfg_).in_use = 0;                                        \
    761                 (_ext_cfg_).offset = (_offset_);                               \
    762                 sal_memcpy(&((_ext_cfg_).ext_attrs),                           \
    763                            (_ext_attrs_),                                      \
    764                            sizeof(bcmi_keygen_ext_attrs_t));                   \
    765                 _rv_ = bcmi_keygen_ext_cfg_insert((_unit_), (_l_),             \
    766                                          &(_ext_cfg_), (_ext_cfg_db_));        \
    767                 if (BCMI_KEYGEN_FAILURE(_rv_)) {                               \
    768                     BCMI_KEYGEN_RETURN_VAL_EXIT(_rv_);                         \
    769                 }                                                              \
    770             } while(0)
    771 
    772 /*
    773  * By default, sum of granularity of all extractors going out of the section
    774  * is set to drain bits of a section. In some special scenarios (when extractor
    775  * with programmable granularity is present in sections outgoing extractors),
    776  * drain bits of section may be less than the sum calculated. In such cases,
    777  * section drain bits needs to be overwritten with correct value after
    778  * (strictly) initializing all the extractors using BCMI_KEYGEN_EXT_CFG_ADD.
    779  */
    780 #define BCMI_KEYGEN_EXT_SECTION_DBITS_SET(_unit_, _ext_cfg_db_,                \
    781                                           _sec_, _drain_bits_)                 \
    782             do {                                                               \
    783                 _rv_ = bcmi_keygen_ext_sec_dbit_set((_unit_), (_sec_),         \
    784                                          (_drain_bits_), (_ext_cfg_db_));      \
    785                 if (BCMI_KEYGEN_FAILURE(_rv_)) {                               \
    786                     BCMI_KEYGEN_RETURN_VAL_EXIT(_rv_);                         \
    787                 }                                                              \
    788             } while(0)
    789 
    790 /*
    791  * By default, each section have parents section set to its own section.
    792  * So each section and its parent section will have same drain bits.
    793  * But in some cases, section will have its own drain bits and group of
    794  * sections together should have drain bits less than the sum of all the
    795  * sections drain bits. In order to manage such hierarchical levels of drain
    796  * bits, a common parent section can be assigned to a group of sections.
    797  */
    798 #define BCMI_KEYGEN_EXT_SECTION_PARENT_SET(_unit_, _ext_cfg_db_,               \
    799                                            _sec_, _parent_sec_)                \
    800             do {                                                               \
    801                 _rv_ = bcmi_keygen_ext_sec_parent_set((_unit_), (_sec_),       \
    802                                         (_parent_sec_), (_ext_cfg_db_));       \
    803                 if (BCMI_KEYGEN_FAILURE(_rv_)) {                               \
    804                     BCMI_KEYGEN_RETURN_VAL_EXIT(_rv_);                         \
    805                 }                                                              \
    806             } while(0)
    807 
    808 /* Max number of chunks a qualifer can have in any of
    809  * its configurations of type bcmi_keygen_qual_cfg_t.
    810  */
    811 #define BCMI_KEYGEN_QUAL_MAX_CHUNKS 32
    812 
    813 /* Maximum offsets any qualifier can have in final key */
    814 #define BCMI_KEYGEN_QUAL_OFFSETS_MAX 64
    815 
    816 /* */
    817 #define BCMI_KEYGEN_QUAL_BITMAP_MAX_WORDS 8
    818 
    819 typedef enum bcmi_keygen_qual_flags_e {
    820     /* Qualifier is configuration is post muxed. */
    821     BCMI_KEYGEN_QUAL_FLAGS_PMUX = 0,
    822     /* Qualifier configuration is not valid if
    823      * keygen is in mode "SINGLE".
    824      */
    825     BCMI_KEYGEN_QUAL_FLAGS_NOT_IN_SINGLE,
    826     /* Qualifier configuration is not valid if
    827      * keygen is in mode "DBLINTRA".
    828      */
    829     BCMI_KEYGEN_QUAL_FLAGS_NOT_IN_DBLINTRA,
    830     /* Qualifier configuration is not valid for
    831      * Exact Match.
    832      */
    833     BCMI_KEYGEN_QUAL_FLAGS_NOT_IN_EM,
    834     /* Qualifier configuration is not valid for
    835      * IFP.
    836      */
    837     BCMI_KEYGEN_QUAL_FLAGS_NOT_IN_IFP,
    838     /* Always Last. Not a usable value. */
    839     BCMI_KEYGEN_QUAL_FLAGS_COUNT
    840 } bcmi_keygen_qual_flags_t;
    841 
    842 /* Qualifier flags set used in key generation algorithm to
    843  * validate the qualifier configuration.
    844  */
    845 typedef struct bcmi_keygen_qual_flags_bmp_s {
    846     SHR_BITDCL w[_SHR_BITDCLSIZE(BCMI_KEYGEN_QUAL_FLAGS_COUNT)];
    847 } bcmi_keygen_qual_flags_bmp_t;
    848 
    849 /* Qualifier chunk information. */
    850 typedef struct bcmi_keygen_qual_offset_cfg_s {
    851     /* section in input bus from which this chunk is fed to extraction. */
    852     bcmi_keygen_ext_section_t section;
    853     /* chunk number. For example , if a section has 10 chunks,
    854      * then this field will be set to any one value from 0 to 9 which
    855      * is appropriate to this chunk.
    856      */
    857     uint16 sec_val;
    858     /* Required number bits in this chunk for the qualifier this chunk
    859      * information belongs to. This will be any value between 1 to ?size?.
    860      */
    861     uint16 width;
    862     /* start bit(w.r.t total width of the section) from where ?width?
    863      * number of bits in this chunk are required for the qualifier.
    864      */
    865     uint16 offset;
    866     /* Size of the chunk. Generally all chunks in a section will
    867      * have the same size.
    868      */
    869     uint16 size;
    870 } bcmi_keygen_qual_offset_cfg_t;
    871 
    872 /* Qualifier configuration */
    873 typedef struct bcmi_keygen_qual_cfg_s {
    874     /* keygen algorithm uses these flags to validate this configuration
    875      * for the given keygen mode(bcmi_keygen_mode_t).
    876      */
    877     bcmi_keygen_qual_flags_bmp_t qual_flags;
    878     /* Qualifier control to be reserved in case keygen algorithm is using
    879      * this qualifier configuration.
    880      */
    881     bcmi_keygen_ext_ctrl_sel_t pri_ctrl_sel;
    882     /* "ctrl_sel" should be set to this value in case this configuration is
    883      * successfully used by keygen algorithm.
    884      */
    885     uint16 pri_ctrl_sel_val;
    886     /* Secondary control to be reserved for given primary ctrl
    887      * Not applicable in keygen alogrithm.
    888      */
    889     bcmi_keygen_ext_ctrl_sel_t sec_ctrl_sel;
    890     /* "sec_ctrl_sel" should be set to this value. */
    891     uint16 sec_ctrl_sel_val;
    892     /* Qualifer chunk information for different chunks belongs to this
    893      *  qualifier configuration. Chunks may either come from same section
    894      *  or from different sections in the input bus.
    895      */
    896     bcmi_keygen_qual_offset_cfg_t e_params[BCMI_KEYGEN_QUAL_MAX_CHUNKS];
    897     /* number of valid elements in the e_params array. Valid values of this
    898      *  field ranges between 1 to BCMI_KEYGEN_QUAL_MAX_CHUNKS.
    899      */
    900     uint8 num_chunks;
    901     /* Size of all valid chunks together. */
    902     uint32 size;
    903 
    904     uint8 update_count;
    905 } bcmi_keygen_qual_cfg_t;
    906 
    907 /* All possible qualifiers configurations of a single qualifier. */
    908 typedef struct bcmi_keygen_qual_cfg_info_s {
    909     /* Qualifier Identifier.  Keygen library uses qualifier identifiers
    910      *  created in field module.
    911      */
    912     bcm_field_qualify_t qual;
    913     /* Array of qualifier configurations of a qualifier. Most of the
    914      * qualifiers have single configurations but some have more
    915      * than one configuration to choose.
    916      */
    917     bcmi_keygen_qual_cfg_t *qual_cfg_arr;
    918      /* "qual_cfg_arr" size */
    919      uint8 num_qual_cfg;
    920 } bcmi_keygen_qual_cfg_info_t;
    921 
    922 /* Qualifier configuration information of all qualifiers supported
    923  * on the device.
    924  */
    925 typedef struct bcmi_keygen_qual_cfg_info_db_s {
    926     /* Number of valid qualifiers in the database. This value is anywhere
    927      * in between 1 to BCM_FIELD_QUALIFY_MAX.
    928      */
    929     int num_quals;
    930     /* Holds pointers to Qualifier Configuration information for
    931      * each supported qualifier. If some qualifier is not supported
    932      * on the device then it?s pointer is set to NULL.
    933      */
    934     bcmi_keygen_qual_cfg_info_t *qual_cfg_info[BCM_FIELD_QUALIFY_MAX];
    935 } bcmi_keygen_qual_cfg_info_db_t;
    936 
    937 /* BCMI_KEYGEN_QUAL_CFG_XXX macros require the following declaration in any
    938  * function which uses them.
    939  */
    940 #define BCMI_KEYGEN_QUAL_CFG_DECL          \
    941     int _rv_;                              \
    942     bcmi_keygen_qual_cfg_t _qual_cfg_
    943 
    944 /* To re-init the bcmi_keygen_qual_cfg_t structure. */
    945 #define BCMI_KEYGEN_QUAL_CFG_INIT(_unit_)                       \
    946     _rv_ = bcmi_keygen_qual_cfg_t_init(_unit_, &(_qual_cfg_));  \
    947     if (BCMI_KEYGEN_FAILURE(_rv_)) {                            \
    948         BCMI_KEYGEN_RETURN_VAL_EXIT(_rv_);                      \
    949     }
    950 
    951 /* To update the selectors, offset and width of the
    952  * bcmi_keygen_qual_cfg_t variable based on the index.
    953  */
    954 #define BCMI_KEYGEN_QUAL_CFG_OFFSET_ADD(_index_,                           \
    955                                         _section_,                         \
    956                                         _sec_val_,                         \
    957                                         _offset_,                          \
    958                                         _width_)                           \
    959                 (_qual_cfg_).e_params[_index_].section      = (_section_); \
    960                 (_qual_cfg_).e_params[_index_].sec_val      = (_sec_val_); \
    961                 (_qual_cfg_).e_params[_index_].offset       = (_offset_);  \
    962                 (_qual_cfg_).e_params[_index_].width        = (_width_);   \
    963                 (_qual_cfg_).num_chunks++;
    964 
    965 /* To update the control selectors and its value in the
    966  * bcmi_keygen_qual_cfg_t structure.
    967  */
    968 #define BCMI_KEYGEN_QUAL_CFG_PRI_CTRL_SEL_ADD(_ctrl_sel_, _ctrl_sel_val_)   \
    969                     (_qual_cfg_).pri_ctrl_sel     = (_ctrl_sel_);           \
    970                     (_qual_cfg_).pri_ctrl_sel_val = (_ctrl_sel_val_);       \
    971 
    972 /* To update the secondary control selectors and its value. */
    973 #define BCMI_KEYGEN_QUAL_CFG_SEC_CTRL_SEL_ADD(_ctrl_sel_, _ctrl_sel_val_)  \
    974                 (_qual_cfg_).sec_ctrl_sel     = (_ctrl_sel_);              \
    975                 (_qual_cfg_).sec_ctrl_sel_val = (_ctrl_sel_val_);          \
    976 
    977 /* To update the control selectors and its value in the
    978  * bcmi_keygen_qual_cfg_t structure.
    979  */
    980 #define BCMI_KEYGEN_QUAL_CFG_INSERT(_unit_, _qual_cfg_info_db_,        \
    981                                     _qual_id_, _qual_flags_)           \
    982                 sal_memcpy(&((_qual_cfg_).qual_flags),                 \
    983                            &(_qual_flags_),                            \
    984                            sizeof(bcmi_keygen_qual_flags_bmp_t));      \
    985                 _rv_ = bcmi_keygen_qual_cfg_insert((_unit_),           \
    986                                              (_qual_id_),              \
    987                                              &(_qual_cfg_),            \
    988                                              (_qual_cfg_info_db_));    \
    989                 if (BCMI_KEYGEN_FAILURE(_rv_)) {                       \
    990                     BCMI_KEYGEN_RETURN_VAL_EXIT(_rv_);                 \
    991                 }
    992 
    993 /* Qualifier flag to use new finfo while converting this qualifier
    994  * bitmap to finfo. Default behavior of algorithm is to search in
    995  * assigned finfo for given section/sec_val/pri_ctrl_sel/
    996  * pri_ctrl_sel_val. If a match is found, that finfo is updated with
    997  * bitmap of this new qualifer. This flag override this default behavior
    998  * and valid only for flowtracker style extractors. Using this flag
    999  * in ifp style extractors will give unexpected results.
   1000  */
   1001 #define BCMI_KEYGEN_QUAL_F_USE_FINFO_NEW                    (1 << 0)
   1002 
   1003 /* Qualifier flags to use extractor of granularity 16 at level 2
   1004  * to extract this qualifier bitmap. Default behavior is to loop
   1005  * through all extractors at given level and try to extract all
   1006  * required bit in given finfo using extractors of any granularity
   1007  * available at given section in given level. This flags override
   1008  * this behavior and valid only for flowtracker style extractors.
   1009  * To use this flag,
   1010  * a. Qualifier size must be equal or less than 16 bits.
   1011  *
   1012  * Qual flags BCMI_KEYGEN_QUAL_F_USE_FINFO_NEW can also be
   1013  * combined with this flag. Using this flag in ifp style extractors
   1014  * will give unexpected results.
   1015  */
   1016 #define BCMI_KEYGEN_QUAL_F_USE_L2_EXT_GRAN16                (1 << 1)
   1017 
   1018 /* Qualifier flags to use extractor of granularity 8 at level 2
   1019  * to extract this qualifier bitmap. Default behavior is to loop
   1020  * through all extractors at given level and try to extract all
   1021  * required bit in given finfo using extractors of any granularity
   1022  * available at given section in given level. This flags override
   1023  * this behavior and valid only for flowtracker style extractors.
   1024  * To use this flag,
   1025  * a. Qualifier size must be less than 8 bits.
   1026  * b. Either or both of qual flag BCMI_KEYGEN_QUAL_F_USE_FINFO_NEW
   1027  *    and BCMI_KEYGEN_QUAL_F_USE_L2_EXT_GRAN16  can be used.
   1028  * c. DO NOT use only this flag alone. It might fail to allocate
   1029  *    extractors even if extraction is possible.
   1030  *
   1031  * Using this flag in ifp style extractors will give unexpected
   1032  * results.
   1033  */
   1034 #define BCMI_KEYGEN_QUAL_F_USE_L2_EXT_GRAN8                 (1 << 2)
   1035 
   1036 /* Qualifier has to be extrctaed to modulo 32 offsets in the final
   1037  * key.In general keygen algorithm doesnot give any preference to
   1038  * any qualifier while placing it in the final key. But this flag
   1039  * ovverrides this behaviour.
   1040  */
   1041 #define BCMI_KEYGEN_QUAL_F_EXTRACT_TO_MODULO_32_OFFSET     (1 << 3)
   1042 
   1043 /* This flag will make sure that all input bus containers related to
   1044  * a qualifier are extrcted by consecutive muxers of same part of the
   1045  * muxer hierarchy.
   1046  */
   1047 #define BCMI_KEYGEN_QUAL_F_STICKY_CONTAINERS               (1 << 4)
   1048 
   1049 /* Qualifier information */
   1050 typedef struct bcmi_keygen_qual_info_s {
   1051     /* Qualifier flags */
   1052     uint32 flags;
   1053     /* Need to extract all bits in the qualifier or some? */
   1054     uint8 partial;
   1055     /* Qualifier Id. */
   1056     bcm_field_qualify_t qual_id;
   1057     /* bits required if partial is set to TRUE. otherwise,
   1058      * ignore this field.
   1059      */
   1060     uint32 bitmap[BCMI_KEYGEN_QUAL_BITMAP_MAX_WORDS];
   1061 } bcmi_keygen_qual_info_t;
   1062 
   1063 /* Offset and width information of a qualifer in final key of a given part */
   1064 typedef struct bcmi_keygen_qual_offset_s {
   1065     /* Number of Offsets. */
   1066     uint8 num_offsets;
   1067     /* offset. */
   1068     uint16 offset[BCMI_KEYGEN_QUAL_OFFSETS_MAX];
   1069     /* width from the corresponding offset. */
   1070     uint8 width[BCMI_KEYGEN_QUAL_OFFSETS_MAX];
   1071 } bcmi_keygen_qual_offset_t;
   1072 
   1073 /* All qualifiers offset and width information in final key of a given part */
   1074 typedef struct bcmi_keygen_qual_offset_info_s {
   1075     /* Array qualifiers present in the part given */
   1076     bcm_field_qualify_t *qid_arr;
   1077     /* offset and width information corresponding to qualifiers in qid_arr. */
   1078     bcmi_keygen_qual_offset_t *offset_arr;
   1079     /* Size of the qid_arr and offset_arr arrays */
   1080     uint16 size;
   1081 } bcmi_keygen_qual_offset_info_t;
   1082 
   1083 /* Validate whether extractors can be allocated for all
   1084  * qualifiers in the given keygen mode. Dont need to generate
   1085  * the offsets of qualifiers in the final key.
   1086  */
   1087 #define BCMI_KEYGEN_CFG_FLAGS_VALIDATE_ONLY (1 << 0)
   1088 /* Keygen algorithm has generated operation information for the given
   1089  * keygen configuration but applicatipon wants to add more configuration
   1090  * (like adding more qualifiers) to it and keygen algorithm has regenerate
   1091  * the operational information for the newly added configuration. During
   1092  * this process keygen algorithm should not use resources(like multiplexers)
   1093  * that are in use for old keygen configuration.
   1094  */
   1095 #define BCMI_KEYGEN_CFG_FLAGS_QSET_UPDATE   (1 << 1)
   1096 
   1097 /* When num_parts in keygen configuration is more than one, then input bus
   1098  * containers corresponding to all qualifiers are distributed to all parts
   1099  * symmetrically. That means if two 16 bit container needs to be extracted
   1100  * from two parts, first container is extracted from part one and second one
   1101  * is extracted from part2 instead of extracting both containers from first
   1102  * part. If this flag is set, then all muxers are used in part one first and
   1103  * then go to 2nd part, 3rd part and so on.
   1104  */
   1105 #define BCMI_KEYGEN_CFG_FLAGS_SERIAL_MUX_ALLOC (1 << 2)
   1106 
   1107 /* Keygen algorithm builds list of containers corresponding to all
   1108  * qualifiers and sort the list in the descending order based on the
   1109  * container size. This flag will voids the sorting of the containers.
   1110  * This is the requirement for FlowTracker groups in some cases.
   1111  */
   1112 #define BCMI_KEYGEN_CFG_FLAGS_SERIAL_QUAL_CONTAINERS (1 << 3)
   1113 
   1114 /* Keygen Configuration to be used to allocate multiplexers */
   1115 typedef struct bcmi_keygen_cfg_s {
   1116     /* Flags(BCMI_KEYGEN_CFG_FLAGS_XXX). */
   1117     uint32 flags;
   1118     /* keygen mode */
   1119     bcmi_keygen_mode_t mode;
   1120     /* Information about the qualifiers in the final key */
   1121     bcmi_keygen_qual_info_t *qual_info_arr;
   1122     /* size of qual_info_arr array */
   1123     uint8 qual_info_count;
   1124     /* Number of parts. Generally it depends on keygen mode.
   1125      * 1 in case of keygen mode SINGLE, 2 in case of DBLINTRA,
   1126      * 3 in case of TRIPLE. But there are other modes as well for
   1127      * which num parts cannot be assumed by keygen library so is
   1128      * the reason for creation of this field.
   1129      */
   1130     uint8 num_parts;
   1131     /* Qualifiers configuration information database */
   1132     bcmi_keygen_qual_cfg_info_db_t *qual_cfg_info_db;
   1133     /* Extractor configuration database. Applications may have multiple
   1134      * extractor databases but need to pass the right pointer for keygen mode.
   1135      */
   1136     bcmi_keygen_ext_cfg_db_t *ext_cfg_db;
   1137     /* Different controls generated by the keygen algorithm. This is required
   1138      * if application need to update the existing QSET.
   1139      */
   1140     bcmi_keygen_ext_ctrl_sel_info_t *ext_ctrl_sel_info;
   1141     /* Size of ext_ctrl_sel_info array */
   1142     uint16 ext_ctrl_sel_info_count;
   1143 } bcmi_keygen_cfg_t;
   1144 
   1145 /* Operational data generated by keygen algorithm */
   1146 typedef struct bcmi_keygen_oper_s {
   1147     /* Final key offset information of each qualifier specified
   1148      * in keygen_cfg.
   1149      */
   1150     bcmi_keygen_qual_offset_info_t *qual_offset_info;
   1151     /* Different controls generated by the keygen algorithm.
   1152      * Calling module should push this information to h/w.
   1153      */
   1154     bcmi_keygen_ext_ctrl_sel_info_t *ext_ctrl_sel_info;
   1155     /* Size of ext_ctrl_sel_info array */
   1156     uint16 ext_ctrl_sel_info_count;
   1157 } bcmi_keygen_oper_t;
   1158 
   1159 extern int
   1160 bcmi_keygen_cfg_process(int unit,
   1161                         bcmi_keygen_cfg_t *keygen_cfg,
   1162                         bcmi_keygen_oper_t *keygen_oper);
   1163 extern int
   1164 bcmi_keygen_qual_cfg_t_init(int unit,
   1165                             bcmi_keygen_qual_cfg_t *qual_cfg);
   1166 extern int
   1167 bcmi_keygen_qual_cfg_insert(int unit,
   1168                  bcm_field_qualify_t qual_id,
   1169                  bcmi_keygen_qual_cfg_t *new_qual_cfg,
   1170                  bcmi_keygen_qual_cfg_info_db_t *qual_cfg_info_db);
   1171 extern int
   1172 bcmi_keygen_ext_cfg_insert(int unit,
   1173                            uint8 level,
   1174                            bcmi_keygen_ext_cfg_t *ext_cfg,
   1175                            bcmi_keygen_ext_cfg_db_t *ext_cfg_db);
   1176 extern int
   1177 bcmi_keygen_ext_cfg_t_init(int unit,
   1178                            bcmi_keygen_ext_cfg_t *ext_cfg);
   1179 
   1180 extern int
   1181 bcmi_keygen_ext_cfg_db_free(int unit, bcmi_keygen_ext_cfg_db_t *ext_cfg_db);
   1182 
   1183 extern int
   1184 bcmi_keygen_oper_free(int unit,
   1185                       uint16 num_parts,
   1186                       bcmi_keygen_oper_t *keygen_oper);
   1187 extern int
   1188 bcmi_keygen_keysize_get(int unit,
   1189                         bcmi_keygen_cfg_t *keygen_cfg,
   1190                         uint16 *rkey_size);
   1191 
   1192 /*
   1193  * Overwrite drain bits for given section.
   1194  */
   1195 extern int
   1196 bcmi_keygen_ext_sec_dbit_set(int unit,
   1197                 bcmi_keygen_ext_section_t sec,
   1198                 int drain_bits,
   1199                 bcmi_keygen_ext_cfg_db_t *ext_cfg_db);
   1200 
   1201 /*
   1202  * Overwrite parent section for given section.
   1203  */
   1204 extern int
   1205 bcmi_keygen_ext_sec_parent_set(int unit,
   1206                 bcmi_keygen_ext_section_t sec,
   1207                 bcmi_keygen_ext_section_t parent_sec,
   1208                 bcmi_keygen_ext_cfg_db_t *ext_cfg_db);
   1209 
   1210 /*
   1211  * Free Extractor config database.
   1212  */
   1213 extern int
   1214 bcmi_keygen_ext_cfg_db_cleanup(int unit,
   1215                                bcmi_keygen_ext_cfg_db_t *ext_cfg_db);
   1216 
   1217 /*
   1218  * Free Qualifier config database.
   1219  */
   1220 extern int
   1221 bcmi_keygen_qual_cfg_info_db_free(int unit,
   1222                   bcmi_keygen_qual_cfg_info_db_t *qual_cfg_info_db);
   1223 
   1224 /*
   1225  * Max size of qualifier
   1226  */
   1227 extern int
   1228 bcmi_keygen_qual_cfg_max_size_get(int unit,
   1229                 bcmi_keygen_cfg_t *keygen_cfg,
   1230                 bcm_field_qualify_t qual_id,
   1231                 uint16 *qual_cfg_max_size);
   1232 
   1233 #endif
   1234