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

kbp_mngr.h (34931B)


      1 /*! \file bcm_int/dnx/kbp/kbp_mngr.h
      2  *
      3  * Internal DNX KBP APIs
      4  *
      5  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      6  * 
      7  * Copyright 2007-2020 Broadcom Inc. All rights reserved.
      8  */
      9 
     10 #ifndef _KBP_MNGR_H_INCLUDED__
     11 /*
     12  * {
     13  */
     14 #define _KBP_MNGR_H_INCLUDED__
     15 
     16 #ifndef BCM_DNX_SUPPORT
     17 #error "This file is for use by DNX (JR2) family only!"
     18 #endif
     19 
     20 /*
     21  * Include files
     22  * {
     23  */
     24 #include <shared/shrextend/shrextend_debug.h>
     25 #include <shared/utilex/utilex_bitstream.h>
     26 #include <soc/dnx/dnx_data/auto_generated/dnx_data_max_elk.h>
     27 #include <soc/dnx/dbal/dbal.h>
     28 #include <soc/dnx/kbp/kbp_common.h>
     29 #include <soc/dnx/swstate/auto_generated/access/kbp_fwd_tcam_access_mapper_access.h>
     30 #include <bcm_int/dnx/kbp/kbp_connectivity.h>
     31 
     32 /*
     33  * }
     34  */
     35 
     36 /*
     37  * TYPEDEFs
     38  * {
     39  */
     40 
     41 /** Internal KBP manager indications for distinguishing between master key and DB key */
     42 typedef enum
     43 {
     44     DNX_KBP_DB_TABLE_INDICATION,
     45     DNX_KBP_OPCODE_TABLE_INDICATION,
     46     DNX_KBP_NOF_SW_TABLE_INDICATION
     47 } dnx_kbp_sw_table_indication_e;
     48 
     49 /*
     50  * }
     51  */
     52 
     53 /*
     54  * DEFINEs
     55  * {
     56  */
     57 #define KBP_ACCESS kbp_sw_state
     58 
     59 /** Convenience macro for blocking dynamic APIs for ACL configurations after the device has been locked */
     60 #define DNX_KBP_BLOCK_API_IF_DEVICE_IS_LOCKED() \
     61     do { \
     62         dbal_enum_value_field_kbp_device_status_e _kbp_mngr_status_; \
     63         SHR_IF_ERR_EXIT(kbp_mngr_status_get(unit, &_kbp_mngr_status_)); \
     64         if (_kbp_mngr_status_ == DBAL_ENUM_FVAL_KBP_DEVICE_STATUS_LOCKED) { \
     65             SHR_ERR_EXIT(_SHR_E_CONFIG, "API is not allowed to run when KBP device is locked\n"); \
     66         } \
     67     } while(0)
     68 
     69 #if defined(INCLUDE_KBP)
     70 
     71 /** KBP is configured in dual port mode by default in SDK */
     72 #define DNX_KBP_MAX_NOF_OPCODES                 KBP_HW_MAX_LTR_DUAL_PORT
     73 
     74 #define DNX_KBP_MAX_NOF_LOOKUPS                 KBP_HW_MAX_SEARCH_DB
     75 #define DNX_KBP_MAX_NOF_RESULTS                 KBP_INSTRUCTION_MAX_RESULTS
     76 
     77 #define MAX_NUMBER_OF_LOOKUPS_WHEN_XL_DB_EXISTS 6
     78 
     79 #define DNX_KBP_MAX_NOF_SEGMENTS_PER_LOOKUP     KBP_MAX_NUM_OF_SEGMENTS_PER_KEY
     80 
     81 /**
     82  * MAX_KEY_LENGTH limited to 360 from the available 640 /NLMDEV_MAX_KEY_LEN_IN_BITS/ due to bandwidth requirements.
     83  * However, we allow up to 480 bits to accomodate user scenarios where the larger keys are not expected to run at 
     84  * full bandwidth.
     85  */
     86 #define DNX_KBP_MAX_KEY_LENGTH_IN_BITS_LOSSLESS 360
     87 #define DNX_KBP_MAX_KEY_LENGTH_IN_BITS          480
     88 
     89 #define DNX_KBP_MAX_PAYLOAD_LENGTH_IN_BITS      NLMDEV_MAX_AD_LEN_IN_BITS
     90 
     91 #define DNX_KBP_MAX_NOF_SMTS                    NLM_MAX_NUM_SMT
     92 
     93 #define DNX_KBP_MIN_ACL_PRIORITY                KBP_HW_MINIMUM_PRIORITY
     94 
     95 #else
     96 
     97 /*
     98  * Below defines are mapped to KBPSDK defines.
     99  * For compatibility with non-KBP compilations they are redefined to 0 or 1.
    100  */
    101 #define DNX_KBP_MAX_NOF_OPCODES                 1 /** Used as array initializer */
    102 
    103 #define DNX_KBP_MAX_NOF_LOOKUPS                 1 /** Used as array initializer */
    104 #define DNX_KBP_MAX_NOF_RESULTS                 1
    105 
    106 #define DNX_KBP_MAX_NOF_SEGMENTS_PER_LOOKUP     1 /** Used as array initializer */
    107 
    108 #define DNX_KBP_MAX_KEY_LENGTH_IN_BITS_LOSSLESS 0
    109 #define DNX_KBP_MAX_KEY_LENGTH_IN_BITS          0
    110 #define DNX_KBP_MAX_PAYLOAD_LENGTH_IN_BITS      0
    111 
    112 #define DNX_KBP_MAX_NOF_SMTS                    0
    113 
    114 #define DNX_KBP_MIN_ACL_PRIORITY                0
    115 
    116 #endif
    117 
    118 #define DNX_KBP_OPCODE_MIN                      1 /** Min opcode Value (HW) */
    119 #define DNX_KBP_OPCODE_MAX                      200 /** MAx opcode Value (HW) */
    120 #define DNX_KBP_MAX_NOF_DBS                     256 /** No suitable define was found amongst the KBPSDK defines */
    121 #define DNX_KBP_MAX_SEGMENT_LENGTH_IN_BYTES     16 /** No suitable define was found amongst the KBPSDK defines */
    122 #define DNX_KBP_HIT_INDICATION_SIZE_IN_BITS     8 /** the size of the hitbit in the result buffer from the KBP */
    123 
    124 #define DNX_KBP_MAX_KEY_LENGTH_IN_BYTES         BITS2BYTES(DNX_KBP_MAX_KEY_LENGTH_IN_BITS)
    125 #define DNX_KBP_MAX_PAYLOAD_LENGTH_IN_BYTES     BITS2BYTES(DNX_KBP_MAX_PAYLOAD_LENGTH_IN_BITS)
    126 
    127 #define DNX_KBP_KEY_SEGMENT_NAME_SIZE_IN_BYTES  64 /** Arbitrary size that should fit almost all field names */
    128 #define DNX_KBP_KEY_SEGMENT_NAME_SIZE_IN_WORDS  BYTES2WORDS(DNX_KBP_KEY_SEGMENT_NAME_SIZE_IN_BYTES)
    129 
    130 #define DNX_KBP_MAX_NOF_SEGMENTS_PER_MASTER_KEY 22 /** Arbitrary size */
    131 
    132 /*
    133  * In SMT mode the opcode pool is divided between the two threads.
    134  * Offset is used to configure same context to different thread.
    135  */
    136 #define DNX_KBP_SMT_INSTRUCTION_OFFSET          DNX_KBP_MAX_NOF_OPCODES
    137 
    138 
    139 #define DNX_KBP_RESULT_SIZE_FWD                 64
    140 #define DNX_KBP_RESULT_SIZE_RPF                 32
    141 
    142 /** this assumes that there are 32 contexts that are reserved to FWD and 32 reserved for ACL. the first ACL ID context is
    143  *  32. this will allow support ISSU (we keeping some context for FWD and some for ACLs */
    144 #define DNX_KBP_FWD_CONTEXT_LAST                (32)
    145 /*
    146  *  This assumes that there are 32 opcodes that are reserved to FWD (static) and 32 reserved for ACL (dynamic).
    147  *  the first dynamic opcode is 32. this will allow support ISSU (we keeping some opcodes for FWD and some for ACLs)
    148  */
    149 #define DNX_KBP_MAX_STATIC_OPCODES_NOF          (32)
    150 
    151 /** 171 taken from "kbp_field_types_definitions.xml" */
    152 #define DNX_KBP_KEY_SEGMENT_SIZE                (BITS2WORDS(179))
    153 
    154 /** Bitmap for swstate caching indication */
    155 #define DNX_KBP_CACHING_BMP_FWD                 (1 << 0)
    156 #define DNX_KBP_CACHING_BMP_ACL                 (1 << 1)
    157 #define DNX_KBP_CACHING_BMP_ALLOWED             (1 << 2)
    158 
    159 /** Values indicating to use the default values for  */
    160 #define DNX_KBP_DB_PROPERTIES_MIN_CAPACITY_DEFAULT_INDICATION       (0)
    161 #define DNX_KBP_DB_PROPERTIES_ALGORITHMIC_MODE_DEFAULT_INDICATION   (DBAL_ENUM_FVAL_ALGO_MODE_DEFAULT)
    162 
    163 #define DNX_KBP_OVERLAY_FIELD_INVALID 80
    164 #define DNX_KBP_KEY_IS_OVERLAY_FIELD(_overlay_field_offset_) \
    165     (((_overlay_field_offset_) == DNX_KBP_OVERLAY_FIELD_INVALID) ? FALSE : TRUE)
    166 
    167 /** The maximum allowed data length per result */
    168 #define DNX_KBP_MAX_RESULT_DATA_LEN             128
    169 
    170 /*
    171  * }
    172  */
    173 /*
    174  * INVALID DEFINEs
    175  * {
    176  */
    177 #define DNX_KBP_INVALID_LOOKUP_ID                 -1
    178 #define DNX_KBP_INVALID_RESULT_ID                 -1
    179 #define DNX_KBP_INVALID_OPCODE_ID                 -1
    180 #define DNX_KBP_INVALID_SEGMENT_ID                -1
    181 #define DNX_KBP_INVALID_SEGMENT_SIZE              -1
    182 #define DNX_KBP_INVALID_DB_ID                     -1
    183 /*
    184  * }
    185  */
    186 
    187 /*
    188  * MACROs
    189  * {
    190  */
    191 /**
    192  * Check if KBP status means that device lock has occured.
    193  */
    194 #define DNX_KBP_STATUS_IS_LOCKED(_status) \
    195     ((_status == DBAL_ENUM_FVAL_KBP_DEVICE_STATUS_LOCKED) || \
    196      (_status == DBAL_ENUM_FVAL_KBP_DEVICE_STATUS_CONFIG_UPDATED))
    197 
    198 #define DNX_KBP_FIELD_OMMITTED_FROM_OPTIMIZED_RESULT(_field_id_) \
    199     (((_field_id_ == DBAL_FIELD_KBP_ALIGNMENT_PADDING_1) || (_field_id_ == DBAL_FIELD_KBP_ALIGNMENT_PADDING_2) || (_field_id_ == DBAL_FIELD_RESULT_TYPE)) ? 1 : 0)
    200 
    201 #define DNX_KBP_OPTIMIZED_RESULT_TYPE_HW_VALUE 0
    202 
    203 /*
    204  * }
    205  */
    206 
    207 /*
    208  * TYPEDEFs
    209  * {
    210  */
    211 
    212 #if defined(INCLUDE_KBP)
    213 typedef struct
    214 {
    215     struct kbp_allocator *dalloc_p[DNX_KBP_MAX_NOF_INST];
    216     void *xpt_p[DNX_KBP_MAX_NOF_INST];
    217     struct kbp_device *device_p[DNX_KBP_MAX_NOF_INST];
    218     struct kbp_device *smt_p[DNX_KBP_MAX_NOF_INST][DNX_KBP_MAX_NOF_SMTS];
    219     uint32 flags;
    220     enum kbp_device_type device_type;
    221     struct kbp_device_config device_config[DNX_KBP_MAX_NOF_INST];
    222     dnx_kbp_user_data_t user_data[DNX_KBP_MAX_NOF_INST];
    223 } generic_kbp_app_data_t;
    224 
    225 #else
    226 
    227 typedef struct
    228 {
    229     void *dummy_p;
    230 } generic_kbp_app_data_t;
    231 
    232 #endif
    233 
    234 /** Used in FP to provide to KBP manager information on new ACL lookup */
    235 typedef struct
    236 {
    237     /** the result index in the KBP result (payload) buffer */
    238     uint8 result_index;
    239 
    240     /** offset from the start of the KBP result buffer, indicating the result location of the lookup */
    241     uint32 result_offset;
    242 
    243     /** the DBAL table ID related to the lookup */
    244     dbal_tables_e dbal_table_id;
    245 
    246     /** the number of relevant segments */
    247     uint32 nof_segments;
    248 
    249     /** the relevant key segments from the master key */
    250     uint8 key_segment_index[DNX_KBP_MAX_NOF_SEGMENTS_PER_LOOKUP];
    251 
    252     /*
    253      * The result size in the result buffer (note, can be smaller than the result size in the DB).
    254      * 0 means to take the size from the DBAL table (thus it will be the same as in the DB).
    255      */
    256     uint32 result_size;
    257 
    258 } kbp_opcode_lookup_info_t;
    259 
    260 typedef struct
    261 {
    262     dbal_tables_e table_id;
    263     uint8 lookup_id;
    264     char lookup_type_str[DBAL_MAX_STRING_LENGTH];
    265     dbal_printable_entry_t entry_print_info;
    266 } kbp_printable_entry_t;
    267 
    268 /*
    269  * Utility structure that represent one segment in the master key or the DB key.
    270  * This structure is used to retrieve/update master key and DB key.
    271  * The max number of master key segments is DNX_KBP_MAX_NOF_SEGMENTS_PER_MASTER_KEY.
    272  * The max number of DB key segments is DNX_KBP_MAX_NOF_SEGMENTS_PER_LOOKUP.
    273  *
    274  * Overlay indication and overlay offset are supposed to be used only for master key.
    275  * An overlay field is a key segment that takes its value from the master key, based on its offset and size.
    276  * The overlay fields are used as keys for DB lookups.
    277  * They allow for the reduction of the master key and DB keys.
    278  */
    279 typedef struct
    280 {
    281     /** Indication whether the key field is a master key or an overlay field */
    282     uint8 is_overlay_field;
    283 
    284     /** Offset of the overlay field location in relation to the MSB of the master key */
    285     uint32 overlay_offset_bytes;
    286 
    287     /** Size in bytes; KBP segments has to be byte aligned; In case of DNX_KBP_INVALID_SEGMENT_SIZE the segment is not valid */
    288     uint32 nof_bytes;
    289 
    290     /** Name of the key segment */
    291     char name[DNX_KBP_KEY_SEGMENT_NAME_SIZE_IN_BYTES];
    292 } kbp_mngr_key_segment_t;
    293 
    294 /*
    295  * struct that represents a FWD context and all of the ACL contexts that can be derived from it.
    296  */
    297 typedef struct
    298 {
    299     uint8 fwd_context;
    300     uint8 nof_acl_contexts;
    301     uint8 acl_contexts[DNX_DATA_MAX_FIELD_KBP_MAX_ACL_CONTEXT_NUM];
    302 } kbp_mngr_fwd_acl_context_mapping_t;
    303 
    304 /*
    305  * }
    306  */
    307 
    308 /*
    309  * FUNCTIONs
    310  * {
    311  */
    312 
    313 /**
    314 * \brief
    315 *   KBP Manager Init API, called from Init sequence. Performs KBP device initialization, and set all static applications
    316 *   \param [in] unit - Relevant unit.
    317 *  \return
    318 *    \retval errors if unexpected behavior. See \ref shr_error_e
    319 *  \remark
    320 *    None
    321 *  \see
    322 *    shr_error_e
    323 */
    324 shr_error_e kbp_mngr_init(
    325     int unit);
    326 
    327 /**
    328 * \brief
    329 *   KBP Manager De-Init API, called from DeInit sequence. Performs KBP device de-initialization
    330 *   \param [in] unit - Relevant unit.
    331 *  \return
    332 *    \retval errors if unexpected behavior. See \ref shr_error_e
    333 *  \remark
    334 *    None
    335 *  \see
    336 *    shr_error_e
    337 */
    338 shr_error_e kbp_mngr_deinit(
    339     int unit);
    340 
    341 /**
    342 * \brief
    343 *   For a given opcode ID provides all FWD context and their respective ACL contexts that use the opcode ID.
    344 *   \param [in] unit - Relevant unit.
    345 *   \param [in] opcode_id - The opcode ID.
    346 *   \param [out] fwd_nof_contexts - The number of fwd contexts the use the opcode_id. The numbe rod elements in fwd_acl_mapping.
    347 *   \param [out] fwd_acl_ctx_mapping - An array of FWD contexts and the ACL contexts that derive from them.
    348 *                                      Contains DNX_DATA_MAX_FIELD_KBP_MAX_CONTEXT_NUM_FOR_ONE_APPTYPE elements.
    349 *  \return
    350 *    \retval errors if unexpected behavior. See \ref shr_error_e
    351 *  \remark
    352 *    None
    353 *  \see
    354 *    shr_error_e
    355 */
    356 shr_error_e kbp_mngr_opcode_to_contexts_get(
    357     int unit,
    358     uint8 opcode_id,
    359     uint8 *fwd_nof_contexts,
    360     kbp_mngr_fwd_acl_context_mapping_t fwd_acl_ctx_mapping[DNX_DATA_MAX_FIELD_KBP_MAX_FWD_CONTEXT_NUM_FOR_ONE_APPTYPE]);
    361 
    362 /**
    363 * \brief
    364 *   this API returns the KBP opcode and opcode anme from the FWD and RPF contexts.
    365 *   \param [in] unit - Relevant unit.
    366 *   \param [in] fwd_context - context of the required info
    367 *   \param [in] acl_context - context of the required info
    368 *   \param [out] opcode_id - the relevant opcode ID
    369 *   \param [out] opcode_name - string that represnts the opcde should be at least char DBAL_MAX_STRING_LENGTH
    370 *  \return
    371 *    \retval errors if unexpected behavior. See \ref shr_error_e
    372 *  \remark
    373 *    None
    374 *  \see
    375 *    shr_error_e
    376 */
    377 shr_error_e kbp_mngr_context_to_opcode_get(
    378     int unit,
    379     uint8 fwd_context,
    380     uint8 acl_context,
    381     uint8 *opcode_id,
    382     char *opcode_name);
    383 
    384 /**
    385  * \brief
    386  *   Returns printable entry for visibility packet diagnostic
    387  *   \param [in] unit - Relevant unit.
    388  *   \param [in] flags - Flags for result parsing.
    389  *   \param [in] fwd_context - Forwarding context (only from IFWD2 stage).
    390  *   \param [in] acl_context - ACL context.
    391  *   \param [in] key_sig_value - The key signal for parsing the lookup key.
    392  *   \param [in] key_sig_size - number of fields in the key.
    393  *   \param [in] res_sig_value - The result signal for parsing the lookup results.
    394  *   \param [in] res_sig_size - number of fields in the results.
    395  *   \param [in] nof_print_info - number of returned printable entry infos
    396  *   \param [out] entry_print_info - The returned printable entry info, built by the key and result signals.
    397  *  \return
    398  *    \retval errors if unexpected behavior. See \ref shr_error_e
    399  *  \remark
    400  *    None
    401  *  \see
    402  *    shr_error_e
    403  */
    404 shr_error_e kbp_mngr_opcode_printable_entry_get(
    405     int unit,
    406     uint32 flags,
    407     uint8 fwd_context,
    408     uint8 acl_context,
    409     uint32 *key_sig_value,
    410     int key_sig_size,
    411     uint32 *res_sig_value,
    412     int res_sig_size,
    413     uint8 *nof_print_info,
    414     kbp_printable_entry_t * entry_print_info);
    415 
    416 /**
    417 * \brief
    418 *   this API takes the KBP SW information update the DB according to the valid opcodes and configures the the KBP HW,
    419 *   once this API is called the device is ready to use.
    420 *   \param [in] unit - Relevant unit.
    421 *  \return
    422 *    \retval errors if unexpected behavior. See \ref shr_error_e
    423 *  \remark
    424 *    None
    425 *  \see
    426 *    shr_error_e
    427 */
    428 shr_error_e kbp_mngr_sync(
    429     int unit);
    430 
    431 /**
    432 * \brief
    433 *   During warmboot this API performs KBP device restore, takes the KBP swstate information for KBP DB and instruction handles,
    434 *   performs refresh on the handles and locks the device.
    435 *   \param [in] unit - Relevant unit.
    436 *  \return
    437 *    \retval errors if unexpected behavior. See \ref shr_error_e
    438 *  \remark
    439 *    None
    440 *  \see
    441 *    shr_error_e
    442 */
    443 shr_error_e kbp_mngr_wb_init(
    444     int unit);
    445 
    446 /**
    447 * \brief
    448 *   this API updates the KBP HW with the previously applied configurations during warmboot.
    449 *   \param [in] unit - Relevant unit.
    450 *  \return
    451 *    \retval errors if unexpected behavior. See \ref shr_error_e
    452 *  \remark
    453 *    None
    454 *  \see
    455 *    shr_error_e
    456 */
    457 shr_error_e kbp_mngr_wb_sync(
    458     int unit);
    459 
    460 /**
    461 * \brief
    462 *   This API creates KBP dynamic table. Used for ACLs that are created after init. It takes the DBAL KBP SW
    463 *   information and transform it to the KBP info. Updates the number of DBs in KBP.
    464 *   Returns error if KBP device is locked.
    465 *   \param [in]  unit          - Relevant unit.
    466 *   \param [in]  counters_enable - enable counters for ACL db.
    467 *   \param [in]  dbal_table_id - the related table ID.
    468 *   \param [in]  initial_capacity - initial capacity of the DB, this parameter affect on how much the DB can grow. if
    469 *          user doens't have any special requirements set to DNX_KBP_DB_PROPERTIES_MIN_CAPACITY_DEFAULT_INDICATION and kbp will
    470 *          use default value:
    471 *          DNX_KBP_INITIAL_DB_SIZE_CREATION_TCAM.
    472 *   \param [in]  algo_mode - the DB algorithmic mode, the value is used to set the DB property KBP_PROP_ALGORITHMIC
    473 *          optional values are 0 - non algo, 1 - power ctrl (partitions of the TCAM), 2 - power ctrl advance, 3 - net
    474 *          ACL (improve capacity and power) to use default value set (DNX_KBP_DB_PROPERTIES_ALGORITHMIC_MODE_DEFAULT_INDICATION).
    475 *  \return
    476 *    \retval errors if unexpected behavior. See \ref shr_error_e
    477 *  \remark
    478 *    None
    479 *  \see
    480 *    shr_error_e
    481 */
    482 shr_error_e kbp_mngr_db_create(
    483     int unit,
    484     uint8 counters_enable,
    485     dbal_tables_e dbal_table_id,
    486     uint32 initial_capacity,
    487     int algo_mode);
    488 
    489 /**
    490 * \brief
    491 *   This API retrieves the properties provided to a dynamic KBP table created by kbp_mngr_db_create.
    492 *   \param [in]  unit          - Relevant unit.
    493 *   \param [in]  dbal_table_id - the related table ID.
    494 *   \param [out]  counters_enable - enable counters for ACL db.
    495 *   \param [out]  initial_capacity - initial capacity of the DB, this parameter affect on how much the DB can grow. if
    496 *          user doens't have any special requirements set to DNX_KBP_DB_PROPERTIES_MIN_CAPACITY_DEFAULT_INDICATION and kbp will
    497 *          use default value:
    498 *          DNX_KBP_INITIAL_DB_SIZE_CREATION_TCAM.
    499 *   \param [out]  algo_mode - the DB algorithmic mode, the value is used to set the DB property KBP_PROP_ALGORITHMIC
    500 *          optional values are 0 - non algo, 1 - power ctrl (partitions of the TCAM), 2 - power ctrl advance, 3 - net
    501 *          ACL (improve capacity and power) to use default value set (DNX_KBP_DB_PROPERTIES_ALGORITHMIC_MODE_DEFAULT_INDICATION).
    502 *  \return
    503 *    \retval errors if unexpected behavior. See \ref shr_error_e
    504 *  \remark
    505 *    None
    506 *  \see
    507 *    shr_error_e
    508 */
    509 shr_error_e kbp_mngr_db_properties_get(
    510     int unit,
    511     dbal_tables_e dbal_table_id,
    512     uint8 *counters_enable,
    513     uint32 *initial_capacity,
    514     int *algo_mode);
    515 
    516 /**
    517  * \brief - updating the KBP status in the SW table.
    518  * \param [in] unit - Relevant unit.
    519  * \param [in] kbp_mngr_status - example: DBAL_ENUM_FVAL_KBP_DEVICE_STATUS_BEFORE_INIT,
    520  *        DBAL_ENUM_FVAL_KBP_DEVICE_STATUS_INIT_DONE, DBAL_ENUM_FVAL_KBP_DEVICE_STATUS_FWD_CONFIG_DONE,
    521  *        DBAL_ENUM_FVAL_KBP_DEVICE_STATUS_CONFIG_UPDATED, DBAL_ENUM_FVAL_KBP_DEVICE_STATUS_LOCKED
    522   \return
    523  *   Error indication according to shr_error_e enum
    524  *
    525  * \remark
    526  *   * None
    527  * \see
    528  *   * None
    529  */
    530 shr_error_e kbp_mngr_status_update(
    531     int unit,
    532     dbal_enum_value_field_kbp_device_status_e kbp_mngr_status);
    533 
    534 /**
    535  * \brief - Get the KBP status from the SW table.
    536  * \param [in]  unit - Relevant unit.
    537  * \param [out] kbp_mngr_status - The returned status. Can be one of these: DBAL_ENUM_FVAL_KBP_DEVICE_STATUS_BEFORE_INIT,
    538  *        DBAL_ENUM_FVAL_KBP_DEVICE_STATUS_INIT_DONE, DBAL_ENUM_FVAL_KBP_DEVICE_STATUS_FWD_CONFIG_DONE,
    539  *        DBAL_ENUM_FVAL_KBP_DEVICE_STATUS_CONFIG_UPDATED, DBAL_ENUM_FVAL_KBP_DEVICE_STATUS_LOCKED
    540   \return
    541  *   Error indication according to shr_error_e enum
    542  *
    543  * \remark
    544  *   * None
    545  * \see
    546  *   * None
    547  */
    548 shr_error_e kbp_mngr_status_get(
    549     int unit,
    550     dbal_enum_value_field_kbp_device_status_e * kbp_mngr_status);
    551 
    552 /**
    553  * \brief - Get from the SW table if KBP IPv4 public is enabled.
    554  * \param [in]  unit - Relevant unit.
    555  * \param [out] enabled - The returned indication, TRUE or FALSE.
    556   \return
    557  *   Error indication according to shr_error_e enum
    558  *
    559  * \remark
    560  *   * None
    561  * \see
    562  *   * None
    563  */
    564 shr_error_e kbp_mngr_ipv4_public_enabled_get(
    565     int unit,
    566     uint8 *enabled);
    567 
    568 /**
    569  * \brief - Get from the SW table if KBP IPv6 public is enabled.
    570  * \param [in]  unit - Relevant unit.
    571  * \param [out] enabled - The returned indication, TRUE or FALSE.
    572   \return
    573  *   Error indication according to shr_error_e enum
    574  *
    575  * \remark
    576  *   * None
    577  * \see
    578  *   * None
    579  */
    580 shr_error_e kbp_mngr_ipv6_public_enabled_get(
    581     int unit,
    582     uint8 *enabled);
    583 
    584 /**
    585  * \brief - Get the total result size of a given opcode.
    586  * \param [in]  unit - Relevant unit.
    587  * \param [in]  opcode_id - Relevant opcode ID.
    588  * \param [out] result_size - The returned total opcode result size.
    589   \return
    590  *   Error indication according to shr_error_e enum
    591  *
    592  * \remark
    593  *   * None
    594  * \see
    595  *   * None
    596  */
    597 shr_error_e kbp_mngr_opcode_total_result_size_get(
    598     int unit,
    599     uint8 opcode_id,
    600     uint32 *result_size);
    601 
    602 /**
    603 * \brief
    604 *   Set the master key of an opcode using the provided segments.
    605 *   This will replace all current master key segments.
    606 *   The first 'nof_segments' will be set according to the provided segments.
    607 *   All other segments will be set to invalid '0' values.
    608 *   Overlay fields can be set by sending them via the segments array.
    609 *   \param [in] unit          - Relevant unit.
    610 *   \param [in] opcode_id     - ID of related opcode.
    611 *   \param [in] nof_segments  - The number of segments to set.
    612 *   \param [in] key_segments  - Array of segments to be set to the opcode master key.
    613 *  \return
    614 *    \retval errors if unexpected behavior. See \ref shr_error_e
    615 *  \remark
    616 *    None
    617 *  \see
    618 *    shr_error_e
    619 */
    620 shr_error_e kbp_mngr_opcode_master_key_set(
    621     int unit,
    622     uint8 opcode_id,
    623     uint32 nof_segments,
    624     kbp_mngr_key_segment_t * key_segments);
    625 
    626 /**
    627 * \brief
    628 *   This API retrieves the master key structure for specific KBP opcode.
    629 *   Used by FP for updating the KBP opcode master key when attaching KBP group to context.
    630 *   Overlay fields are retrieved in the segments array.
    631 *   \param [in] unit              - Relevant unit.
    632 *   \param [in] opcode_id         - ID of related opcode.
    633 *   \param [out] nof_key_segments - The number of retrieved segments.
    634 *   \param [out] key_segments     - Array of retrieved segments info each segment is used. the location of the array is
    635 *          the location in the master key.
    636 *  \return
    637 *    \retval errors if unexpected behavior. See \ref shr_error_e
    638 *  \remark
    639 *    None
    640 *  \see
    641 *    shr_error_e
    642 */
    643 shr_error_e kbp_mngr_opcode_master_key_get(
    644     int unit,
    645     uint32 opcode_id,
    646     uint32 *nof_key_segments,
    647     kbp_mngr_key_segment_t * key_segments);
    648 
    649 /**
    650 * \brief
    651 *   This API used to add segments to the master key for specific KBP opcode. This API will add only the new key
    652 *   segments. all the segments in the master key has to have unique names. The new segments will be added at the end of
    653 *   the master key if new_segments_placement is DNX_KBP_INVALID_SEGMENT_ID, otherwise the will be added in the middle
    654 *   and all lookups using the following segments will be updated.
    655 *   Returns error if KBP device is locked.
    656 *   \param [in] unit              - Relevant unit.
    657 *   \param [in] opcode_id         - ID of related opcode.
    658 *   \param [in] new_segments_index  - The place on the master key the new segments will be placed.
    659 *                                     If the value is DNX_KBP_INVALID_SEGMENT_ID, the segments will be appended
    660 *                                     at the end of the master key.
    661 *   \param [in] nof_new_segments  - The number of new segments.
    662 *   \param [in] key_segments      - Array of segments to be added to the opcode master key.
    663 *  \return
    664 *    \retval errors if unexpected behavior. See \ref shr_error_e
    665 *  \remark
    666 *    None
    667 *  \see
    668 *    shr_error_e
    669 */
    670 shr_error_e kbp_mngr_opcode_master_key_segments_add(
    671     int unit,
    672     uint32 opcode_id,
    673     uint32 new_segments_index,
    674     uint32 nof_new_segments,
    675     kbp_mngr_key_segment_t * key_segments);
    676 
    677 /**
    678 * \brief
    679 *   Removes a segment from a master key. Lookups will be updated (unless a lookup uses the segment to be removed).
    680 *   Returns error if KBP device is locked.
    681 *   \param [in] unit              - Relevant unit.
    682 *   \param [in] opcode_id         - ID of related opcode.
    683 *   \param [in] segment_index  - The segment to be removed.
    684 *  \return
    685 *    \retval errors if unexpected behavior. See \ref shr_error_e
    686 *  \remark
    687 *    None
    688 *  \see
    689 *    shr_error_e
    690 */
    691 shr_error_e kbp_mngr_opcode_master_key_segment_remove(
    692     int unit,
    693     uint32 opcode_id,
    694     uint32 segment_index);
    695 
    696 /**
    697 * \brief
    698 *   This API adds a lookup to an existing opcode. The lookup ID has to be available (unused) in the opcode.
    699 *   Used by FP when attaching KBP group to a context.
    700 *   Returns error if KBP device is locked.
    701 *   \param [in] unit         - Relevant unit.
    702 *   \param [in] opcode_id    - The related opcode ID to update.
    703 *   \param [in] lookup_info  - The lookup info to add.
    704 *  \return
    705 *    \retval errors if unexpected behavior. See \ref shr_error_e
    706 *  \remark
    707 *    None
    708 *  \see
    709 *    shr_error_e
    710 */
    711 shr_error_e kbp_mngr_opcode_lookup_add(
    712     int unit,
    713     uint8 opcode_id,
    714     kbp_opcode_lookup_info_t * lookup_info);
    715 
    716 /**
    717 * \brief
    718 *   This API retrieves a lookup from an existing opcode.
    719 *   \param [in] unit         - Relevant unit.
    720 *   \param [in] opcode_id    - The related opcode ID to get.
    721 *   \param [out] lookup_info - The lookup to get; result_index need to be set.
    722 *  \return
    723 *    \retval errors if unexpected behavior. See \ref shr_error_e
    724 *  \remark
    725 *    None
    726 *  \see
    727 *    shr_error_e
    728 */
    729 shr_error_e kbp_mngr_opcode_lookup_get(
    730     int unit,
    731     uint8 opcode_id,
    732     kbp_opcode_lookup_info_t * lookup_info);
    733 
    734 /**
    735 * \brief
    736 *   This API clears a lookup from an existing opcode.
    737 *   Returns error if KBP device is locked.
    738 *   \param [in] unit         - Relevant unit.
    739 *   \param [in] opcode_id    - The related opcode ID.
    740 *   \param [in] result_id    - The related result to clear.
    741 *  \return
    742 *    \retval errors if unexpected behavior. See \ref shr_error_e
    743 *  \remark
    744 *    None
    745 *  \see
    746 *    shr_error_e
    747 */
    748 shr_error_e kbp_mngr_opcode_result_clear(
    749     int unit,
    750     uint8 opcode_id,
    751     uint8 result_id);
    752 
    753 /**
    754 * \brief
    755 *   This API clears all configurations done for an opcode.
    756 *   Returns error if KBP device is locked.
    757 *   \param [in] unit         - Relevant unit.
    758 *   \param [in] opcode_id    - The related opcode ID.
    759 *  \return
    760 *    \retval errors if unexpected behavior. See \ref shr_error_e
    761 *  \remark
    762 *    None
    763 *  \see
    764 *    shr_error_e
    765 */
    766 shr_error_e kbp_mngr_opcode_clear(
    767     int unit,
    768     uint8 opcode_id);
    769 
    770 /**
    771 * \brief
    772 *   Return the number of entries in the DB and the estimated capacity.
    773 *   \param [in] unit - Relevant unit.
    774 *   \param [in] db_id - the DB id.
    775 *   \param [out] nof_entries - the returned number of entries.
    776 *   \param [out] estimated_capacity - the returned estimated capacity.
    777 *  \return
    778 *    \retval errors if unexpected behavior. See \ref shr_error_e
    779 *  \remark
    780 *    None
    781 *  \see
    782 *    shr_error_e
    783 */
    784 shr_error_e kbp_mngr_db_capacity_get(
    785     int unit,
    786     uint8 db_id,
    787     uint32 *nof_entries,
    788     uint32 *estimated_capacity);
    789 
    790 /**
    791 * \brief
    792 *   This API create a new opcode accroding to the source opcode. all the source opcode info (lookups and master key) is
    793 *   duplicated (since it is a cascaded opcode, meaning that the ACL is done on top of all other FWD lookups). NOTES:
    794 *   this API support only apptypes that connected to one FWC Ctx.
    795 *   Returns error if KBP device is locked.
    796 *   \param [in] unit         - Relevant unit.
    797 *   \param [in] source_opcode_id    - the opcode ID to generate from it the new opcode. (cascaded from).
    798 *   \param [in] opcode_name    - The new opcode name.
    799 *   \param [out] acl_ctx    - an available fwd2 context that will be use for this opcode.
    800 *   \param [out] new_opcode_id    - the new opcode ID.
    801 *  \return
    802 *    \retval errors if unexpected behavior. See \ref shr_error_e
    803 *  \remark
    804 *    None
    805 *  \see
    806 *    shr_error_e
    807 */
    808 shr_error_e kbp_mngr_opcode_create(
    809     int unit,
    810     uint8 source_opcode_id,
    811     char *opcode_name,
    812     uint8 *acl_ctx,
    813     uint8 *new_opcode_id);
    814 
    815 /**
    816 * \brief
    817 *   This API returns an array with result indexes, which are using given acl_qual_name.
    818 *   \param [in] unit         - Relevant unit.
    819 *   \param [in] opcode_id    - The related opcode ID.
    820 *   \param [in] acl_qual_name    - The name of the ACL qualifier for which info
    821 *    will be returned.
    822 *   \param [out] result_ids    - Array with result indexes. Note the initial value is
    823 *   DNX_KBP_INVALID_RESULT_ID, which is indicating the end of the array.
    824 *  \return
    825 *    \retval errors if unexpected behavior. See \ref shr_error_e
    826 *  \remark
    827 *    None
    828 *  \see
    829 *    shr_error_e
    830 */
    831 shr_error_e kbp_mngr_segment_used_result_indexes_get(
    832     int unit,
    833     uint8 opcode_id,
    834     char *acl_qual_name,
    835     uint32 result_ids[DNX_KBP_MAX_NOF_RESULTS]);
    836 
    837 /**
    838 * \brief
    839 *   This function returns the number of FFCs allocated for ACL usage at init for a specific predefined opcode.
    840 *   Used to reserve FFCs for future use in the FWD.
    841 *   \param [in] unit         - Relevant unit.
    842 *   \param [in] opcode_id    - The predefined (static) opcode ID which uses the FFCs
    843 *   \param [out] nof_ffcs    - The amount of FFCs that we can allocate for ACL for the OPCODE
    844 *  \return
    845 *    \retval errors if unexpected behavior. See \ref shr_error_e
    846 *  \remark
    847 *    None
    848 *  \see
    849 *    shr_error_e
    850 */
    851 shr_error_e kbp_mngr_opcode_nof_acl_ffcs(
    852     int unit,
    853     uint8 opcode_id,
    854     uint32 *nof_ffcs);
    855 
    856 /**
    857 * \brief
    858 *   This function returns whether a certain acl context is static (created for predefined opcode) or
    859 *   dynamic (created when creating a new opcode)
    860 *   \param [in] unit         - Relevant unit.
    861 *   \param [in] acl_ctx      - The ACL context
    862 *   \param [out] is_dynamic  - Whether the ACL context is dynamic or static.
    863 *  \return
    864 *    \retval errors if unexpected behavior. See \ref shr_error_e
    865 *  \remark
    866 *    None
    867 *  \see
    868 *    shr_error_e
    869 */
    870 shr_error_e kbp_mngr_context_acl_is_dynamic(
    871     int unit,
    872     uint8 acl_ctx,
    873     uint8 *is_dynamic);
    874 
    875 /**
    876 * \brief
    877 *   This function returns whether a certain opcode is static (predefined opcode) or
    878 *   dynamic (created when creating a new opcode, user defined opcode)
    879 *   \param [in] unit         - Relevant unit.
    880 *   \param [in] opcode_id    - The opcode Id
    881 *   \param [out] is_dynamic  - Whether the ACL context is dynamic or static.
    882 *  \return
    883 *    \retval errors if unexpected behavior. See \ref shr_error_e
    884 *  \remark
    885 *    None
    886 *  \see
    887 *    shr_error_e
    888 */
    889 shr_error_e kbp_mngr_opcode_is_dynamic(
    890     int unit,
    891     uint8 opcode_id,
    892     uint8 *is_dynamic);
    893 
    894 /**
    895 * \brief
    896 *   Translates FWD and ACL contexts to KBP opcode ID.
    897 *   \param [in] unit - Relevant unit.
    898 *   \param [in] fwd_context - Forwarding context (only from IFWD2 stage).
    899 *   \param [in] acl_context - ACL context.
    900 *   \param [out] opcode_id - The returned opcode ID if not value is mapped will return -1 and error _SHR_E_NOT_FOUND.
    901 *  \return
    902 *    \retval errors if unexpected behavior. See \ref shr_error_e if context not mapped returns _SHR_E_NOT_FOUND
    903 *  \remark
    904 *    None
    905 *  \see
    906 *    shr_error_e
    907 */
    908 shr_error_e kbp_mngr_context_to_opcode_translate(
    909     int unit,
    910     uint8 fwd_context,
    911     uint8 acl_context,
    912     uint8 *opcode_id);
    913 
    914 /**
    915 * \brief
    916 *   this API inits the kbp_mngr_key_segment_t structure to default (invalid) values
    917 *   \param [in] unit      - Relevant unit.
    918 *   \param [in] segment_p - This procedure loads the pointed memory by that structure, containing invalid values.
    919 *  \return
    920 *    \retval errors if unexpected behavior. See \ref shr_error_e
    921 *  \remark
    922 *    None
    923 *  \see
    924 *    shr_error_e
    925 */
    926 shr_error_e kbp_mngr_key_segment_t_init(
    927     int unit,
    928     kbp_mngr_key_segment_t * segment_p);
    929 
    930 /**
    931 * \brief
    932 *   this API inits the kbp_opcode_lookup_info_t structure to default (invalid) values
    933 *   \param [in] unit          - Relevant unit.
    934 *   \param [in] lookup_info_p - The pointer to structure to initialize.
    935 *  \return
    936 *    \retval errors if unexpected behavior. See \ref shr_error_e
    937 *  \remark
    938 *    None
    939 *  \see
    940 *    shr_error_e
    941 */
    942 shr_error_e kbp_opcode_lookup_info_t_init(
    943     int unit,
    944     kbp_opcode_lookup_info_t * lookup_info_p);
    945 
    946 /**
    947  * \brief
    948  *   Sets the KBP tables capacities according to the KBP DBAL table ID and capacity value
    949  * \param [in] unit - Relevant unit.
    950  * \param [in] dbal_table_id - The KBP DBAL table ID.
    951  * \param [in] is_opt - Optimized result indication.
    952  * \param [in] capacity_value - The capacity to be set.
    953   \return
    954  *    \retval errors if unexpected behavior. See \ref shr_error_e
    955  *  \remark
    956  *    None
    957  *  \see
    958  *    shr_error_e
    959  */
    960 shr_error_e kbp_mngr_table_capacity_set(
    961     int unit,
    962     dbal_tables_e dbal_table_id,
    963     uint8 is_opt,
    964     int capacity_value);
    965 
    966 /**
    967  * \brief
    968  *   Gets the KBP tables capacity according to the DBAL table ID
    969  * \param [in] unit - Relevant unit.
    970  * \param [in] dbal_table_id - The KBP DBAL table ID.
    971  * \param [in] is_opt - Optimized result indication.
    972  * \param [out] capacity_value - The returned capacity.
    973   \return
    974  *    \retval errors if unexpected behavior. See \ref shr_error_e
    975  *  \remark
    976  *    None
    977  *  \see
    978  *    shr_error_e
    979  */
    980 shr_error_e kbp_mngr_table_capacity_get(
    981     int unit,
    982     dbal_tables_e dbal_table_id,
    983     uint8 is_opt,
    984     int *capacity_value);
    985 
    986 /**
    987  * \brief - Indicates if SMT is enabled for the KBP device or not.
    988  * \param [in] unit - Relevant unit.
    989   \return
    990  *   TRUE when SMT is enabled, FALSE otherwise
    991  *
    992  * \remark
    993  *   * None
    994  * \see
    995  *   * None
    996  */
    997 uint8 kbp_mngr_smt_enabled(
    998     int unit);
    999 
   1000 /**
   1001  * \brief
   1002  *   Indicates if split or non-split KBP RPF tables are used.
   1003  *   Non-split RPF is used on single core devices. FWD and RPF tables are single physical table and entries are shared.
   1004  *   Split RPF is available for devices with two cores.
   1005  *   FWD and RPF tables are physically divided and entries need to be managed separately.
   1006  * \param [in] unit - Relevant unit.
   1007   \return
   1008  *   TRUE when KBP RPF is split, FALSE otherwise
   1009  *
   1010  * \remark
   1011  *   * None
   1012  * \see
   1013  *   * None
   1014  */
   1015 uint8 kbp_mngr_split_rpf_in_use(
   1016     int unit);
   1017 
   1018 /**
   1019  * \brief
   1020  *   Indicates if KBP IPv4 FWD is used.
   1021  * \param [in] unit - Relevant unit.
   1022   \return
   1023  *   TRUE when KBP IPv4 FWD is used, FALSE otherwise
   1024  *
   1025  * \remark
   1026  *   * None
   1027  * \see
   1028  *   * None
   1029  */
   1030 uint8 kbp_mngr_ipv4_in_use(
   1031     int unit);
   1032 
   1033 /**
   1034  * \brief
   1035  *   Indicates if KBP IPv6 FWD is used.
   1036  * \param [in] unit - Relevant unit.
   1037   \return
   1038  *   TRUE when KBP IPv6 FWD is used, FALSE otherwise
   1039  *
   1040  * \remark
   1041  *   * None
   1042  * \see
   1043  *   * None
   1044  */
   1045 uint8 kbp_mngr_ipv6_in_use(
   1046     int unit);
   1047 
   1048 /**
   1049  * \brief
   1050  *   init to KBP device according to the KBP mode.
   1051  *   \param [in] unit - Relevant unit.
   1052  * \return
   1053  *   \retval errors if unexpected behavior. See \ref shr_error_e
   1054  * \remark
   1055  *   None
   1056  * \see
   1057  *   shr_error_e
   1058  */
   1059 shr_error_e dnx_kbp_device_init(
   1060     int unit);
   1061 
   1062 /**
   1063  * \brief
   1064  *  deinit to KBP device according to the KBP mode.
   1065  *   \param [in] unit - Relevant unit.
   1066  * \return
   1067  *   \retval errors if unexpected behavior. See \ref shr_error_e
   1068  * \remark
   1069  *   None
   1070  * \see
   1071  *   shr_error_e
   1072  */
   1073 shr_error_e dnx_kbp_device_deinit(
   1074     int unit);
   1075 
   1076 /*
   1077  * }
   1078  */
   1079 
   1080 shr_error_e kbp_mngr_db_key_segment_set(
   1081     int unit,
   1082     uint32 db_id,
   1083     int index,
   1084     uint32 *segment_type,
   1085     uint32 *segment_size,
   1086     char segment_name[DNX_KBP_KEY_SEGMENT_NAME_SIZE_IN_BYTES]);
   1087 
   1088 shr_error_e kbp_mngr_db_key_segment_get(
   1089     int unit,
   1090     uint32 db_id,
   1091     int index,
   1092     uint32 *segment_type,
   1093     uint32 *segment_size,
   1094     char segment_name[DNX_KBP_KEY_SEGMENT_NAME_SIZE_IN_BYTES]);
   1095 
   1096 shr_error_e kbp_mngr_master_key_segment_set(
   1097     int unit,
   1098     uint32 opcode_id,
   1099     int index,
   1100     uint32 *segment_type,
   1101     uint32 *segment_size,
   1102     char segment_name[DNX_KBP_KEY_SEGMENT_NAME_SIZE_IN_BYTES],
   1103     uint32 *overlay_offset);
   1104 
   1105 shr_error_e kbp_mngr_master_key_segment_get(
   1106     int unit,
   1107     uint32 opcode_id,
   1108     int index,
   1109     uint32 *segment_type,
   1110     uint32 *segment_size,
   1111     char segment_name[DNX_KBP_KEY_SEGMENT_NAME_SIZE_IN_BYTES],
   1112     uint32 *overlay_offset);
   1113 
   1114 #endif/*_KBP_MNGR_H_INCLUDED__*/