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

alpm.h (51734B)


      1 /*
      2  * 
      3  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      4  * 
      5  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      6  *
      7  * File:        alpm.h
      8  * Purpose:     Function declarations for ALPM Internal functions.
      9  */
     10 
     11 #ifndef _BCM_INT_ALPM_H_
     12 #define _BCM_INT_ALPM_H_
     13 
     14 #include <soc/defs.h>
     15 
     16 #ifdef ALPM_ENABLE
     17 
     18 /* ALPM */
     19 
     20 #include <bcm_int/esw/alpm_lib_trie.h>
     21 
     22 #define ALPM_DEBUG          0
     23 
     24 /* #define PSEUDO_ALPM_FMT13 1 */
     25 #if 1
     26 #define ALPM_FMT_TP_CNT     13
     27 #endif
     28 
     29 /* max bank per bucket */
     30 #if defined(BCM_TRIDENT3_SUPPORT)
     31 #define ALPM_BPB_MAX        16
     32 #else
     33 #define ALPM_BPB_MAX        8
     34 #endif
     35 #define ALPM_CB_CNT         2
     36 #define ALPM_ENT_WORDS_MAX  15  /* 480 bits */
     37 
     38 /* Maximum TCAM/ALPM memory entry size in words (640 bits) */
     39 #define ALPM_MEM_ENT_MAX    20
     40 
     41 /* Max entry per bank */
     42 #define ALPM_EPB_MAX        15
     43 /* max prefix per bucket */
     44 #define ALPM_PPB_MAX        (ALPM_EPB_MAX * ALPM_BPB_MAX)
     45 
     46 #define ALPM_PPG_INSERT     0
     47 #define ALPM_PPG_DELETE     1
     48 #define ALPM_PPG_HBP        3
     49 
     50 #define ALPM_MERGE_THRESHOLD_MAX      10
     51 
     52 /* ALPM Packing Mode definitions */
     53 #define ALPM_PKM_32B        (0)
     54 #define ALPM_PKM_64B        (1)
     55 #define ALPM_PKM_128        (2)
     56 #define ALPM_PKM_CNT        (3)
     57 /* IP database type V4 V6 */
     58 #define ALPM_IPT_V4         (ALPM_PKM_32B)
     59 #define ALPM_IPT_V6         (ALPM_PKM_64B)
     60 #define ALPM_IPT_CNT        (2)
     61 
     62 #define ALPM_PKM2IPT(pkm)   (!!(pkm))
     63 
     64 #define ALPM_BKT_PRT_PID    0
     65 #define ALPM_BKT_GLB_PID    1
     66 #define ALPM_BKT_PID_CNT    2
     67 
     68 #define ALPM_TRACE_OP_ADD      0
     69 #define ALPM_TRACE_OP_DELETE   1
     70 #define ALPM_TRACE_OP_DELETE_ALL    2
     71 
     72 /* ref: esw/dump.c
     73  #define DUMP_TABLE_RAW       0x01
     74  #define DUMP_TABLE_HEX       0x02
     75  #define DUMP_TABLE_ALL       0x04
     76  #define DUMP_TABLE_CHANGED   0x08
     77  #define DUMP_TABLE_EXT       0x10
     78  #define DUMP_TABLE_PIPE_X    0x20
     79  #define DUMP_TABLE_PIPE_Y    0x40
     80  #define DUMP_TABLE_PIPE_0    0x80
     81  #define DUMP_TABLE_PIPE_1    0x100
     82  #define DUMP_TABLE_PIPE_2    0x200
     83  #define DUMP_TABLE_PIPE_3    0x400
     84  #define DUMP_TABLE_NO_CACHE  0x800
     85  #define DUMP_TABLE_PHY_INDEX 0x1000
     86  #define DUMP_TABLE_SIMPLIFIED 0x2000
     87  #define DUMP_TABLE_FORMAT 0x4000
     88  #define DUMP_TABLE_ALL_DMA_THRESHOLD 8
     89  #define DUMP_TABLE_ITER_BEFORE_YIELD 8
     90  */
     91 #define ALPM_DUMP_TABLE_RAW          0x01
     92 #define ALPM_DUMP_TABLE_HEX          0x02
     93 #define ALPM_DUMP_TABLE_ALL          0x04
     94 #define ALPM_DUMP_TABLE_CHANGED      0x08
     95 #define ALPM_DUMP_TABLE_NOCACHE      0x800
     96 
     97 /* ALPM Distributed Hitbits */
     98 #define ALPM_HIT_INTERVAL_DEF 1000000   /* 1s */
     99 #define ALPM_HIT_INTERVAL_MIN 100000    /* 100ms  */
    100 #define ALPM_HIT_INTERVAL_MAX 60000000  /* 1 min  */
    101 #define ALPM_HIT_PRIORITY_DEF 200       /* Dist hitbit thread task priority */
    102 #define ALPM_MAX_HIT_ENT_MASK 0xffff    /* max 16 bits of HIT table entry */
    103 
    104 /* ALPM mode */
    105 #define BCM_ALPM_MODE_INVALID       -1
    106 #define BCM_ALPM_MODE_COMBINED      0
    107 #define BCM_ALPM_MODE_PARALLEL      1
    108 #define BCM_ALPM_MODE_TCAM_ALPM     2
    109 
    110 /* SOC_ALPM_LOOKUP_HIT */
    111 #define BCM_ALPM_LOOKUP_HIT             (1 << 31)
    112 /* SOC_ALPM_COOKIE_FLEX */
    113 #define ALPM_ROUTE_FULL_MD              (1 << 29)
    114 /* SOC_ALPM_LPM_LOOKUP_HIT */
    115 #define BCM_ALPM_LPM_LOOKUP_HIT         (1 << 28)
    116 /* SOC_ALPM_DEBUG_SHOW_FLAG_BKT */
    117 /* for ALPM debug show */
    118 #define BCM_ALPM_DEBUG_SHOW_FLAG_PVT    (1U << 0)
    119 #define BCM_ALPM_DEBUG_SHOW_FLAG_BKT    (1U << 1)
    120 #define BCM_ALPM_DEBUG_SHOW_FLAG_BKTUSG (1U << 2)
    121 #define BCM_ALPM_DEBUG_SHOW_FLAG_CNT    (1U << 3)
    122 #define BCM_ALPM_DEBUG_SHOW_FLAG_INTDBG (1U << 4)
    123 #define BCM_ALPM_DEBUG_SHOW_FLAG_ALL    (~0U)
    124 
    125 /* Hit table control for bucket levels
    126    (TCAM level hitbit access uses direct soc_mem cache/hw interface) */
    127 typedef struct _alpm_hit_tbl_ctrl_s {
    128     soc_mem_t mem;          /* Hit table mem */
    129     int     index_cnt;      /* Hit table index count */
    130     int     size;           /* Hit Table size (in bytes) */
    131     int     ent_moved;      /* Entry moved (TRUE or FALSE) */
    132     int     ent_moved_cnt;  /* Entry moved counter */
    133 
    134     void    *cache;         /* Hit cache table */
    135     void    *move;          /* Hit move table */
    136     void    *move_mask;     /* Hit move mask table */
    137 } _alpm_hit_tbl_ctrl_t;
    138 
    139 /* ALPM distributed hitbit control structure */
    140 typedef struct _alpm_dist_hitbit_s {
    141     /* Hit tbl ctrl for Level2 & Level3 per PID */
    142     _alpm_hit_tbl_ctrl_t *hit_tbl[ALPM_CB_CNT][ALPM_BKT_PID_CNT];
    143     char              taskname[16];       /* Dist hitbit thread name */
    144     VOL sal_thread_t  thread;             /* Dist hitbit thread id */
    145     VOL int           interval;           /* Time between dist hitbit thread (us) */
    146     int               priority;           /* task priority */
    147     sal_sem_t         sema;               /* Dist hitbit semaphore */
    148 } _alpm_dist_hitbit_t;
    149 
    150 extern _alpm_dist_hitbit_t *alpm_dist_hitbit[];
    151 
    152 /* threshold in number of HITBIT entries moved (>= threshold use DMA_write) */
    153 #define ALPM_HIT_DMA_THRESHOLD          500
    154 
    155 #define ALPMDH(u)                       (alpm_dist_hitbit[u])
    156 #define ALPM_HTBL(u, i, p)              (ALPMDH(u)->hit_tbl[i][p])
    157 #define ALPM_HTBL_MEM(u, i, p)          (ALPM_HTBL(u, i, p)->mem)
    158 #define ALPM_HTBL_IDX_CNT(u, i, p)      (ALPM_HTBL(u, i, p)->index_cnt)
    159 #define ALPM_HTBL_SIZE(u, i, p)         (ALPM_HTBL(u, i, p)->size)
    160 #define ALPM_HTBL_CACHE(u, i, p)        (ALPM_HTBL(u, i, p)->cache)
    161 #define ALPM_HTBL_MOVE(u, i, p)         (ALPM_HTBL(u, i, p)->move)
    162 #define ALPM_HTBL_MOVE_MASK(u, i, p)    (ALPM_HTBL(u, i, p)->move_mask)
    163 #define ALPM_HTBL_ENT_MOVED(u, i, p)    (ALPM_HTBL(u, i, p)->ent_moved)
    164 #define ALPM_HTBL_ENT_MOVED_CNT(u, i, p) (ALPM_HTBL(u, i, p)->ent_moved_cnt)
    165 
    166 #define ALPM_HIT_LOCK(u)          L3_LOCK(u)
    167 #define ALPM_HIT_UNLOCK(u)        L3_UNLOCK(u)
    168 
    169 /* ALPM control block */
    170 
    171 /* Propagation data structure */
    172 typedef struct _alpm_ppg_data_s {
    173     uint32 ipt;
    174     uint32 key_len;
    175     uint32 bpm_len;
    176     uint32 vrf_id;
    177     uint32 key[5];
    178     void   *bkt_def;
    179 } _alpm_ppg_data_t;
    180 
    181 /* Defines Logical ALPM table ID */
    182 typedef enum _alpm_tbl_e {
    183     alpmTblInvalid = 0,
    184     alpmTblPvtCmodeL1,
    185     alpmTblPvtPmodeL1,
    186     alpmTblPvtCmodeL1P128,
    187     alpmTblPvtPmodeL1P128,
    188     alpmTblBktCmodeL2,
    189     alpmTblBktPmodeL2,
    190     alpmTblBktPmodeGblL2,
    191     alpmTblBktPmodePrtL2,
    192     alpmTblBktCmodeL3,
    193     alpmTblBktPmodeGblL3,
    194     alpmTblBktPmodePrtL3,
    195     alpmTblCount
    196 } _alpm_tbl_t;
    197 
    198 typedef struct _alpm_fmt_info_s {
    199     int16       fmt_type;   /* ALPM_FMT_PVT/RTE */
    200     int16       fmt_count;
    201     int16       fmt_ent_max[ALPM_FMT_TP_CNT];
    202     int16       fmt_pfx_len[ALPM_FMT_TP_CNT];
    203     int         fmt_bnk[ALPM_FMT_TP_CNT];
    204     int         fmt_ent[ALPM_FMT_TP_CNT];
    205     int         fmt_ftype[ALPM_FMT_TP_CNT];
    206 } _alpm_fmt_info_t;
    207 
    208 typedef struct _alpm_bnk_info_s {
    209     /* Support max to 131072 (4096 * 32) banks */
    210     SHR_BITDCL      bnk_btmp[4096];
    211     int             bnk_rsvd;
    212     int             bnk_used;
    213 } _alpm_bnk_info_t;
    214 
    215 typedef struct _alpm_bkt_pool_conf_s {
    216     _alpm_bnk_info_t *bnk_info[ALPM_IPT_CNT];
    217     int             bnk_total;
    218     int             bnk_per_bkt;
    219 
    220     /* Indicating the logical bucket table */
    221     _alpm_tbl_t     bkt_tbl;
    222     int             bkt_wra;
    223     int             bkt_fixed_fmt;
    224     /* Table entry array to store pivot pointer */
    225     void            **pvt_ptr;
    226 
    227     /* Bank fmt configuration */
    228     _alpm_fmt_info_t *fmt_info;
    229 } _alpm_bkt_pool_conf_t;
    230 
    231 typedef struct _alpm_bnk_conf_s {
    232     /* Bank pool config:
    233      * We have 2 bank pool pointer,
    234      * They can point to the same logical pool (Combined Mode)
    235      * or point to the different pools (Parallel & Mixed Mode)
    236      *
    237      * Private routes use pool 0.
    238      * Global routes use pool 1.
    239      */
    240     _alpm_bkt_pool_conf_t *bkt_pool[ALPM_BKT_PID_CNT];
    241 
    242     /* Bucket config */
    243     int16 bkt_bits;
    244     int16 bkt_dw;
    245     int16 phy_bnks_per_bkt;
    246     int16 bnk_bits;
    247 } _alpm_bnk_conf_t;
    248 
    249 typedef struct _alpm_bkt_info_s {
    250     uint8  bnk_fmt[ALPM_BPB_MAX];
    251     uint32 vet_bmp[ALPM_BPB_MAX];
    252     uint16 sub_bkt_idx;
    253     uint16 bkt_idx;
    254     uint8  rofs; /* ROFS */
    255     uint8  reverse;
    256 } _alpm_bkt_info_t;
    257 
    258 typedef struct _alpm_bkt_adata_s {
    259     uint32  defip_flags;
    260     int     defip_ecmp_index;
    261     int     defip_prio;
    262     int     defip_lookup_class;
    263     int     defip_flex_ctr_pool;
    264     int     defip_flex_ctr_mode;
    265     int     defip_flex_ctr_base_id;
    266 } _alpm_bkt_adata_t;
    267 
    268 /* Used for bucket trie node */
    269 typedef struct _alpm_bkt_node_s {
    270     alpm_lib_trie_node_t node; /* trie node */
    271     struct _alpm_bkt_node_s *bkt_ptr;   /* pfx_node -> bkt_node */
    272     struct _alpm_bkt_adata_s adata;
    273     uint32 key[5];
    274     uint32 key_len;
    275     /* ent_idx format: ent | bnk | bkt @ALPM_IDX_MAKE */
    276     uint32 ent_idx;             /* HW memory loc */
    277 } _alpm_bkt_node_t;
    278 
    279 /* Used for prefix trie node, same as _alpm_bkt_node_t */
    280 typedef struct _alpm_bkt_node_s _alpm_pfx_node_t;
    281 
    282 typedef struct _alpm_bkt_pfx_arr_s {
    283     _alpm_bkt_node_t *pfx[ALPM_PPB_MAX];
    284     int pfx_cnt;
    285 } _alpm_bkt_pfx_arr_t;
    286 
    287 typedef struct _alpm_bnk_idx_arr_s {
    288     int idx[ALPM_BPB_MAX];
    289     int idx_cnt;
    290 } _alpm_bnk_idx_arr_t;
    291 
    292 typedef struct _alpm_bkt_split_cb_data_s {
    293     struct _alpm_cb_s *acb;
    294     int pvt_len;
    295     int bkt_cur_cnt;
    296     int bkt_max_cnt;
    297 } _alpm_bkt_split_cb_data_t;
    298 
    299 typedef struct _alpm_tcam_write_s {
    300     int rv;
    301     int hw_idx; /* -1 means invalid or already updated */
    302     uint32 ent[SOC_MAX_MEM_FIELD_WORDS];
    303 } _alpm_tcam_write_t;
    304 
    305 /* Pivot Structure */
    306 typedef struct _alpm_pvt_node_s {
    307     alpm_lib_trie_node_t node;           /* trie node */
    308     alpm_lib_trie_t *bkt_trie;           /* Link to bucket trie -> _alpm_bkt_node_t */
    309 
    310     uint32 vrf_id;
    311     uint32 bkt_pkm;             /* V4, V6 */
    312     uint32 key[5];              /* pivot */
    313     uint32 key_len;             /* pivot length, aka kshift */
    314     uint32 bpm_len;             /* pivot bpm_len */
    315     uint32 has_def;             /* has default route */
    316 
    317     uint32 tcam_idx;            /* TCAM index in 1st level */
    318     uint32 pvt_flags;
    319 
    320     struct _alpm_bkt_node_s *def_pfx; /* Link to bkt_node for bkt def route */
    321     struct _alpm_bkt_info_s bkt_info;    /* Bucket info */
    322 } _alpm_pvt_node_t;
    323 
    324 typedef struct _alpm_pvt_ctrl_s {
    325     alpm_lib_trie_t *pvt_trie;           /* -> _alpm_pvt_node_t */
    326     uint32 route_cnt;
    327     uint32 pvt_len_cnt[128];
    328     /* spl_len only valid for acb 1 */
    329     uint32 spl_len_diff1;
    330     uint32 spl_len_diff2;
    331 
    332     /* Debug counter */
    333     uint32 cnt_add;
    334     uint32 cnt_del;
    335 
    336     uint8 dr_inited; /* to indicate direct route inited first */
    337     uint8 db_inited;
    338     /* database type: FULL | REDUCED
    339      * FULL : supports Destination AND
    340      *        flex counter, pri, rpe, dst_discard, class_id
    341      * REDUCED : only supports Destination
    342      */
    343     uint8 db_type;
    344 } _alpm_pvt_ctrl_t;
    345 
    346 typedef struct _alpm_cb_stat_s {
    347     uint32      c_mem[alpmTblCount][2]; /* RD 0, WR 1 */
    348     uint32      c_bulk_mem[alpmTblCount][2]; /* RD 0, WR 1 */
    349 
    350     uint32      c_defrag;
    351     uint32      c_merge;
    352     uint32      c_expand;
    353     uint32      c_split;
    354     uint32      c_ripple;
    355     uint32      c_bnkshrk;
    356     uint32      c_bnkfree;
    357     uint32      c_full;
    358 
    359     /* Split misplaced case counter */
    360     uint32      c_spl_mp_cs1;
    361     uint32      c_spl_mp_cs21;
    362     uint32      c_spl_mp_cs221;
    363     uint32      c_spl_mp_cs222;
    364 } _alpm_cb_stat_t;
    365 
    366 #define ALPM_FMT_PVT        (0)
    367 #define ALPM_FMT_RTE        (1)
    368 #define ALPM_FMT_CNT        (2)
    369 
    370 typedef struct _alpm_cb_s {
    371     int         unit;
    372     _alpm_pvt_ctrl_t *pvt_ctl[ALPM_IPT_CNT];
    373     _alpm_tbl_t pvt_tbl[ALPM_PKM_CNT];
    374 
    375     struct _alpm_bnk_conf_s bnk_conf;
    376     uint32      acb_idx;    /* Current Control Block index */
    377 
    378     struct _alpm_cb_stat_s acb_cnt;
    379 } _alpm_cb_t;
    380 
    381 typedef struct _alpm_pfx_ctrl_s {
    382     alpm_lib_trie_t *pfx_trie[ALPM_IPT_CNT];
    383 } _alpm_pfx_ctrl_t;
    384 
    385 typedef struct _alpm_ctrl_s {
    386     _alpm_pfx_ctrl_t *_vrf_pfx_hdl;
    387     _alpm_cb_t *alpm_cb[ALPM_CB_CNT];   /* ALPM Control Block */
    388 #define _ALPM_MERGE_CHANGE      0
    389 #define _ALPM_MERGE_UNCHANGE    1
    390     /* UNCHANGE -> CHANGE: split/delete
    391      * CHANGE -> UNCHANGE: unsuccessful merge
    392      */
    393     int *_alpm_merge_state;             /* Per VRF merge state */
    394     int _alpm_cb_cnt;                   /* Numbers of ALPM Control Block */
    395     int _alpm_btm_cb_idx[ALPM_BKT_PID_CNT];
    396     int _alpm_no_hit_bit;
    397     int _alpm_tcam_hb_is_ptr;
    398     int _alpm_mode;
    399     int _alpm_tcam_zoned;
    400     int _alpm_half_banks;
    401     int _alpm_128b;
    402     int _alpm_128b_paired_blk_cnt;
    403     int _alpm_128b_bkt_rsvd;
    404     int _alpm_128b_bkt_rsvd_cnt;
    405     int _alpm_inited;
    406     int _alpm_bulk_wr_threshold;
    407     int _alpm_bnk_threshold;
    408     int _alpm_max_vrf_id;
    409     int _alpm_spl[ALPM_PKM_CNT];
    410     int _alpm_tcam_tbl_skip[ALPM_PKM_CNT];
    411 
    412     /* properties for debug purpose */
    413 #define _ALPM_DBG_PVT_SANITY        (1 << 0)    /* 0x1   */
    414 #define _ALPM_DBG_PVT_SANITY_LEN    (1 << 1)    /* 0x2   */
    415 #define _ALPM_DBG_PVT_DEFRAG        (1 << 2)    /* 0x4   */
    416 #define _ALPM_DBG_PVT_SANITY_NODE   (1 << 3)    /* 0x8   */
    417 #define _ALPM_DBG_PVT_SANITY_COUNT  (1 << 4)    /* 0x10  */
    418 #define _ALPM_DBG_WRITE_CACHE_ONLY  (1 << 5)    /* 0x20  */
    419 #define _ALPM_DBG_BNK_CONF          (1 << 6)    /* 0x40  */
    420 #define _ALPM_DBG_PVT_UPDATE_SKIP   (1 << 7)    /* 0x80  */
    421 #define _ALPM_DBG_HITBIT            (1 << 8)    /* 0x100 */
    422 #define _ALPM_DBG_PVT_PTR_CHK       (1 << 9)    /* 0x200 */
    423 #define _ALPM_DBG_PVT_BKT_BNK_CONT  (1 << 10)   /* 0x400 */
    424 #define _ALPM_DBG_PVT_NODE_BKT      (1 << 11)   /* 0x800 */
    425 #define _ALPM_DBG_BNK_CONF_NULL_PVT (1 << 12)   /* 0x1000*/
    426 
    427     uint32 _alpm_dbg_bmp;
    428 
    429     /* properties for debug info purpose */
    430 #define _ALPM_DBG_INFO_PVT  (1 << 0)
    431 #define _ALPM_DBG_INFO_RTE  (1 << 1)
    432 #define _ALPM_DBG_INFO_CNT  (1 << 2)
    433 #define _ALPM_DBG_INFO_HIT  (1 << 3)
    434 #define _ALPM_DBG_INFO_MAX_NUM    4
    435 #define _ALPM_DBG_INFO_ALL  0xffffffff
    436     uint32 _alpm_dbg_info_bmp;
    437 
    438 #define _ALPM_ERR_MSG_BUF_CNT       128
    439 #define _ALPM_ERR_MSG_BUF_ENT_SZ    128
    440     char *_alpm_err_msg_buf;
    441 
    442     uint32 _alpm_schan_fifo_handle;
    443 
    444     struct alpm_functions_s *alpm_driver;
    445 
    446 } _alpm_ctrl_t;
    447 
    448 #define _ALPM_ERR_MSG_ENT(u, idx)  (ALPMC(u)->_alpm_err_msg_buf+1+((idx)*_ALPM_ERR_MSG_BUF_ENT_SZ))
    449 /* First char stores the current index */
    450 #define _ALPM_ERR_MSG_CUR_IDX(u) ((ALPMC(u)->_alpm_err_msg_buf[0]))
    451 #define _ALPM_ERR_MSG_INSERT(u, msg) \
    452     do { \
    453         uint8 cur_idx = _ALPM_ERR_MSG_CUR_IDX(u);\
    454         if (cur_idx < _ALPM_ERR_MSG_BUF_CNT - 1) { \
    455             sal_memcpy(_ALPM_ERR_MSG_ENT(u, cur_idx), msg, _ALPM_ERR_MSG_BUF_ENT_SZ); \
    456             _ALPM_ERR_MSG_CUR_IDX(u) = cur_idx + 1; \
    457         } \
    458     } while(0)
    459 
    460 extern _alpm_ctrl_t *alpm_control[SOC_MAX_NUM_DEVICES];
    461 
    462 /* bcm_esw_alpm_pvt_trav_cb */
    463 typedef int (*bcm_esw_alpm_pvt_trav_cb) (
    464     int                 u,
    465     _alpm_cb_t          *acb,
    466     _alpm_pvt_node_t    *pvt_node,
    467     void                *user_data);
    468 
    469 typedef struct _alpm_pvt_trav_s {
    470     _alpm_cb_t                  *acb;
    471     bcm_esw_alpm_pvt_trav_cb    user_cb;
    472     void                        *user_data;
    473 } _alpm_pvt_trav_t;
    474 
    475 /* bcm_esw_alpm_pfx_trav_cb */
    476 typedef int (*bcm_esw_alpm_pfx_trav_cb)(
    477     _alpm_pfx_node_t *pfx_node,
    478     void *user_data);
    479 
    480 typedef struct _alpm_pfx_trav_s {
    481     bcm_esw_alpm_pfx_trav_cb    user_cb;
    482     void                        *user_data;
    483 } _alpm_pfx_trav_t;
    484 
    485 /* bcm_esw_alpm_bkt_trav_cb */
    486 typedef int (*bcm_esw_alpm_bkt_trav_cb)(
    487     _alpm_bkt_node_t *bkt_node,
    488     void *user_data);
    489 
    490 typedef struct _alpm_bkt_trav_s {
    491     bcm_esw_alpm_bkt_trav_cb    user_cb;
    492     void                        *user_data;
    493 } _alpm_bkt_trav_t;
    494 
    495 typedef struct _alpm_ppg_cb_user_data_s {
    496     int  unit;
    497     int  ppg_op;
    498     int  ppg_cnt;
    499     void *ppg_acb;
    500     void *ppg_data;
    501 } _alpm_ppg_cb_user_data_t;
    502 
    503 #define ALPM_INFO_MASK_VALID             0x00000001
    504 #define ALPM_INFO_MASK_KEYLEN            0x00000002
    505 #define ALPM_INFO_MASK_ASSOC_DATA        0x00000004
    506 #define ALPM_INFO_MASK_ALPM_DATA         0x00000008
    507 #define ALPM_INFO_MASK_ALPM_DATA_RAW     0x00000010
    508 #define ALPM_INFO_MASK_FIXED_DATA        0x00000020
    509 
    510 /* Used for retrieving alpm info from given entry,
    511  * Entry can be a TCAM entry or a entry entry, not bank entry */
    512 typedef struct _alpm_ent_info_s {
    513     /* Input */
    514     uint32  action_mask;
    515     /* ent_fmt or sub_idx */
    516     int     ent_fmt;
    517     int     vrf_id;
    518     int     pvt_pkm;
    519     int     ipt;
    520 
    521     /* KEY & LENGTH */
    522     uint32  ent_valid;
    523     uint32  key[5];
    524     int     key_len;
    525 
    526     /* ALPM_DATA */
    527     void    *alpm_data_raw;
    528     int     default_miss;
    529     int     kshift;
    530     _alpm_bkt_info_t    bkt_info;
    531 
    532     /* FIXED_DATA */
    533     int     route_pri; /* Global Hi/Lo, Private */
    534 
    535     /* ASSOC_DATA */
    536     _alpm_bkt_adata_t   adata;
    537 
    538 } _alpm_ent_info_t;
    539 
    540 typedef struct _alpm_cb_merge_ctrl_s {
    541     int unit;
    542     int merge_count;
    543     int vrf_id;
    544     int ipt;
    545     int bnk_pbkt;
    546     int ent_pbnk;
    547 
    548     _alpm_cb_t *acb;
    549 
    550     int max_cnt;
    551 } _alpm_cb_merge_ctrl_t;
    552 
    553 typedef enum _alpm_cb_merge_type_e {
    554     ACB_MERGE_INVALID = 0,
    555     ACB_MERGE_CHILD_TO_PARENT,
    556     ACB_MERGE_PARENT_TO_CHILD
    557 } _alpm_cb_merge_type_t;
    558 
    559 #define ACB_REPART_THRESHOLD 8
    560 #define ACB_MERGE_THRESHOLD  8
    561 
    562 #define ALPM_MERGE_REQD(u, vrf_id)              \
    563         (ALPMC(u)->_alpm_merge_state[vrf_id] != _ALPM_MERGE_UNCHANGE)
    564 #define ALPM_MERGE_STATE_CHKED(u, vrf_id)        \
    565         (ALPMC(u)->_alpm_merge_state[vrf_id] = _ALPM_MERGE_UNCHANGE)
    566 #define ALPM_MERGE_STATE_CHANGED(u, vrf_id)     \
    567         (ALPMC(u)->_alpm_merge_state[vrf_id] = _ALPM_MERGE_CHANGE)
    568 
    569 #define ALPM_PVT_UPDATE_ALPM_DATA    (0xffffffff)
    570 #define ALPM_PVT_UPDATE_ASSOC_DATA   (0xffffffff)
    571 #define ALPM_PVT_UPDATE_PREFIX       (0xffffffff)
    572 #define ALPM_PVT_UPDATE_ALL          (0xffffffff)
    573 
    574 /* ALPM functions */
    575 typedef int (*alpm_ctrl_init_f)(int);
    576 typedef void (*alpm_ctrl_deinit_f)(int);
    577 typedef int (*alpm_ctrl_cleanup_f)(int);
    578 typedef int (*alpm_bkt_bnk_copy_f)(int u, _alpm_cb_t *acb,
    579                                    _alpm_pvt_node_t *pvt_node,
    580                                    _alpm_bkt_info_t *src_bkt,
    581                                    _alpm_bkt_info_t *dst_bkt,
    582                                    int src_idx, int dst_idx);
    583 typedef int (*alpm_bkt_bnk_clear_f)(int u, _alpm_cb_t *acb,
    584                                    _alpm_pvt_node_t *pvt_node,
    585                                    int tab_idx);
    586 
    587 typedef int (*alpm_bkt_pfx_copy_f)(int u, _alpm_cb_t *acb,
    588                                    _alpm_bkt_pfx_arr_t *pfx_arr,
    589                                    _alpm_pvt_node_t *opvt_node,
    590                                    _alpm_pvt_node_t *npvt_node);
    591 typedef int (*alpm_bkt_pfx_clean_f)(int u, _alpm_cb_t *acb,
    592                                     _alpm_pvt_node_t *pvt_node,
    593                                     int count, uint32 *ent_idx);
    594 typedef int (*alpm_bkt_pfx_shrink_f)(int u, _alpm_cb_t *acb,
    595                                      _alpm_pvt_node_t *pvt_node,
    596                                      _alpm_bkt_pfx_arr_t *pfx_arr,
    597                                      int shrink_empty_only);
    598 typedef int (*alpm_bkt_ent_write_f)(int u, _alpm_cb_t *acb,
    599                                     _alpm_pvt_node_t *pvt_node,
    600                                     _bcm_defip_cfg_t *lpm_cfg,
    601                                     int ent_idx, uint32 write_flags);
    602 typedef uint8 (*alpm_bkt_def_fmt_get_f)(int u, _alpm_cb_t *acb,
    603                                         int vrf_id, int pkm);
    604 typedef int16 (*alpm_bkt_fmt_type_get_f)(int u, int vrf_id, _alpm_cb_t *acb, uint8 fmt);
    605 typedef int (*alpm_ent_ent_get_f)(int u, int vrf_id, _alpm_cb_t *acb,
    606                                   void *e, uint32 fmt, int eid, void *ftmp);
    607 typedef int (*alpm_ent_pfx_len_get_f)(int u, _alpm_cb_t *acb,
    608                                    _alpm_pvt_node_t *pvt_node, int ent_idx);
    609 typedef int (*alpm_ent_selective_get_f)(int u, _alpm_cb_t *acb, void *e,
    610                                    _alpm_ent_info_t *info);
    611 
    612 /* TCAM function pointer */
    613 typedef int (*tcam_tab_sz_f)(int, int);
    614 typedef int (*tcam_hw_cleanup_f)(int);
    615 typedef int (*tcam_ent_x_to_y_f)(int, int, void *, void *, int, int, int);
    616 typedef int (*tcam_ent_from_cfg_f)(int, int, _bcm_defip_cfg_t *, void *, int, uint32 write_flags);
    617 typedef int (*tcam_ent_to_cfg_f)(int, int, void *, int, _bcm_defip_cfg_t *);
    618 typedef int (*tcam_ent_valid_f)(int, int, void *, int);
    619 typedef int (*tcam_ent_valid_set_f)(int, int, void *, int, int);
    620 typedef int (*tcam_ent_vrf_id_get_f)(int, int, void *, int, int *);
    621 typedef int (*tcam_ent_pfx_len_get_f)(int, int, void *, int, int *);
    622 typedef int (*tcam_ent_to_key_f)(int, int, void *, int, uint32 *);
    623 
    624 typedef int (*tcam_ent_mode_get_f)(int u, int pk, void *e,
    625              int *step_size, int *pkm, int *ipv6, int *key_mode, int sub_idx);
    626 typedef int (*tcam_ent_adata_get_f)(int u, int pkm, void *e, int sub_idx,
    627                                     _alpm_bkt_adata_t *adata);
    628 typedef int (*tcam_ent_bdata_get_f)(int u, int pkm, void *e,
    629                                     int sub_idx,  void *fent);
    630 
    631 /* HITBIT function pointer */
    632 typedef int (*alpm_hit_init_f)(int);
    633 typedef void (*alpm_hit_deinit_f)(int);
    634 typedef int (*alpm_hit_cleanup_f)(int);
    635 typedef int (*alpm_bkt_hit_get_f)(int u, int vrf_id, _alpm_cb_t *acb,
    636                                   _alpm_tbl_t tbl, int idx, int ent);
    637 typedef int (*alpm_bkt_hit_set_f)(int u, int vrf_id, _alpm_cb_t *acb,
    638                                   _alpm_tbl_t tbl, int idx, int ent, int hit_val);
    639 typedef int (*alpm_bkt_hit_write_f)(int u, int vrf_id, _alpm_cb_t *acb,
    640                                     _alpm_tbl_t tbl, int ent_idx, int hit_val);
    641 typedef int (*alpm_hit_move_update_f)(int u, int i, int pid);
    642 typedef int (*alpm_hit_cache_sync_f)(int u, int i, int pid);
    643 typedef int (*alpm_hit_hw_write_f)(int u, int i, int pid);
    644 typedef int (*tcam_ent_hit_get_f)(int u, int pkm, void *e, int sub_idx);
    645 typedef int (*tcam_cache_hit_get_f)(int u, int pkm, int tcam_idx);
    646 typedef int (*tcam_hit_cache_sync_f)(int u);
    647 typedef int (*alpm_table_dump_f)(int u, int vrf_id, soc_mem_t mem, int copyno,
    648                                  int index, int fmt, int ent_idx, int flags);
    649 typedef int (*alpm_cap_get_f)(int u, soc_mem_t mem, int *max, int *min);
    650 
    651 /* TCAM/ALPM function pointer */
    652 typedef int (*mem_ent_read_f)(int unit, _alpm_cb_t *acb, _alpm_tbl_t tbl,
    653                               int index, void *entry_data,
    654                               int no_cache);
    655 typedef int (*mem_ent_write_f)(int unit, _alpm_cb_t *acb,
    656                                _alpm_pvt_node_t *pvt_node, _alpm_tbl_t tbl,
    657                                int index, void *entry_data);
    658 typedef int (*mem_ent_phy_idx_get_f)(int u, _alpm_cb_t *acb,
    659                                      _alpm_tbl_t tbl, int index);
    660 typedef struct alpm_functions_s {
    661     /* ALPM */
    662     alpm_ctrl_init_f        alpm_ctrl_init;
    663     alpm_ctrl_deinit_f      alpm_ctrl_deinit;
    664     alpm_ctrl_cleanup_f     alpm_ctrl_cleanup;
    665     alpm_bkt_bnk_copy_f     alpm_bkt_bnk_copy;
    666     alpm_bkt_bnk_clear_f    alpm_bkt_bnk_clear;
    667     alpm_bkt_pfx_copy_f     alpm_bkt_pfx_copy;
    668     alpm_bkt_pfx_clean_f    alpm_bkt_pfx_clean;
    669     alpm_bkt_pfx_shrink_f   alpm_bkt_pfx_shrink;
    670     alpm_bkt_ent_write_f    alpm_bkt_ent_write;
    671     alpm_bkt_def_fmt_get_f  alpm_bkt_def_fmt_get;
    672     alpm_bkt_fmt_type_get_f alpm_bkt_fmt_type_get;
    673 
    674     alpm_ent_ent_get_f      alpm_ent_ent_get;
    675     alpm_ent_pfx_len_get_f  alpm_ent_pfx_len_get;
    676     alpm_ent_selective_get_f alpm_ent_selective_get;
    677 
    678     /* TCAM */
    679     tcam_tab_sz_f           tcam_table_sz;
    680     tcam_hw_cleanup_f       tcam_hw_cleanup;
    681     tcam_ent_x_to_y_f       tcam_entry_x_to_y;
    682     tcam_ent_from_cfg_f     tcam_entry_from_cfg;
    683     tcam_ent_to_cfg_f       tcam_entry_to_cfg;
    684     tcam_ent_valid_f        tcam_entry_valid;
    685     tcam_ent_valid_set_f    tcam_entry_valid_set;
    686     tcam_ent_vrf_id_get_f   tcam_entry_vrf_id_get;
    687     tcam_ent_pfx_len_get_f  tcam_entry_pfx_len_get;
    688     tcam_ent_to_key_f       tcam_entry_to_key;
    689 
    690     tcam_ent_mode_get_f     tcam_entry_mode_get;
    691     tcam_ent_adata_get_f    tcam_entry_adata_get;
    692     tcam_ent_bdata_get_f    tcam_entry_bdata_get;
    693 
    694     /* TCAM/ALPM */
    695     mem_ent_read_f          mem_entry_read;
    696     mem_ent_write_f         mem_entry_write;
    697 
    698     /* HITBIT */
    699     alpm_hit_init_f         alpm_hit_init;
    700     alpm_hit_deinit_f       alpm_hit_deinit;
    701     alpm_hit_cleanup_f      alpm_hit_cleanup;
    702     alpm_bkt_hit_get_f      alpm_bkt_hit_get;
    703     alpm_bkt_hit_set_f      alpm_bkt_hit_set;
    704     alpm_bkt_hit_write_f    alpm_bkt_hit_write;
    705     alpm_hit_move_update_f  alpm_hit_move_update;
    706     alpm_hit_cache_sync_f   alpm_hit_cache_sync;
    707     alpm_hit_hw_write_f     alpm_hit_hw_write;
    708     tcam_ent_hit_get_f      tcam_entry_hit_get;
    709     tcam_cache_hit_get_f    tcam_cache_hit_get;
    710     tcam_hit_cache_sync_f   tcam_hit_cache_sync;
    711 
    712     /* dump table */
    713     alpm_table_dump_f       alpm_table_dump;
    714     alpm_cap_get_f          alpm_cap_get;
    715 
    716     /* Logical idx to physical idx mapping */
    717     mem_ent_phy_idx_get_f   mem_ent_phy_idx_get;
    718 } alpm_functions_t;
    719 
    720 extern alpm_functions_t th3_alpm_driver;
    721 extern alpm_functions_t th_alpm_driver;
    722 
    723 #define _SHIFT_LEFT(val, count) \
    724     (((count) == 32) ? 0 : (val) << (count))
    725 
    726 #define _SHIFT_RIGHT(val, count) \
    727     (((count) == 32) ? 0 : (val) >> (count))
    728 
    729 #define PVT_BKT_TRIE(pvt_node)          ((pvt_node)->bkt_trie)
    730 #define PVT_BKT_DEF(pvt_node)           ((pvt_node)->def_pfx)
    731 #define PVT_BKT_INFO(pvt_node)          ((pvt_node)->bkt_info)
    732 #define PVT_ROFS(pvt_node)              (PVT_BKT_INFO(pvt_node).rofs)
    733 #define PVT_BKT_IDX(pvt_node)           (PVT_BKT_INFO(pvt_node).bkt_idx)
    734 #define PVT_SUB_BKT_IDX(pvt_node)       (PVT_BKT_INFO(pvt_node).sub_bkt_idx)
    735 #define PVT_BKT_VRF(pvt_node)           ((pvt_node)->vrf_id)
    736 #define PVT_FLAGS(pvt_node)             ((pvt_node)->pvt_flags)
    737 #define PVT_IS_IPMC(pvt_node)           (PVT_FLAGS(pvt_node) & BCM_L3_IPMC)
    738 #define PVT_BKT_PKM(pvt_node)           ((pvt_node)->bkt_pkm)
    739 #define PVT_BKT_IPT(pvt_node)           (ALPM_PKM2IPT((pvt_node)->bkt_pkm))
    740 #define PVT_BPM_LEN(pvt_node)           ((pvt_node)->bpm_len)
    741 #define PVT_KEY_LEN(pvt_node)           ((pvt_node)->key_len)
    742 #define PVT_KEY_CPY(pvt_node, _key)     (sal_memcpy(pvt_node->key, _key, 4 * 5))
    743 #define PVT_IDX(pvt_node)               ((pvt_node)->tcam_idx)
    744 
    745 /* Bucket Info Macros */
    746 #define BI_BNK_IS_USED(bkt_info, bnk)   ((bkt_info)->bnk_fmt[(bnk)] != 0)
    747 #define BI_BNK_FREE(bkt_info, bnk)      ((bkt_info)->bnk_fmt[(bnk)] = 0)
    748 #define BI_SUB_BKT_IDX(bkt_info)        ((bkt_info)->sub_bkt_idx)
    749 #define BI_BKT_IDX(bkt_info)            ((bkt_info)->bkt_idx)
    750 #define BI_ROFS(bkt_info)               ((bkt_info)->rofs)
    751 
    752 /* ALPM Macros */
    753 #define ALPMC(u)                    (alpm_control[u])
    754 #define ALPM_MODE(u)                (ALPMC(u)->_alpm_mode)
    755 #define ALPM_MODE_CHK(u, md)        (ALPM_MODE(u) == md)
    756 #define ALPM_TCAM_ZONED(u)          (ALPMC(u)->_alpm_tcam_zoned)
    757 #define ALPM_128B(u)                (ALPMC(u)->_alpm_128b)
    758 #define ALPM_TCAM_PAIR_BLK_CNT(u)   (ALPMC(u)->_alpm_128b_paired_blk_cnt)
    759 #define ALPM_BKT_RSVD(u)            (ALPMC(u)->_alpm_128b_bkt_rsvd)
    760 #define ALPM_BKT_RSVD_CNT(u)        (ALPMC(u)->_alpm_128b_bkt_rsvd_cnt)
    761 #define ALPM_DRV(u)                 (ALPMC(u)->alpm_driver)
    762 #define ALPM_HIT_SKIP(u)            (ALPMC(u)->_alpm_no_hit_bit)
    763 #define ALPM_TCAM_HB_IS_PTR(u)      (ALPMC(u)->_alpm_tcam_hb_is_ptr)
    764 #define ALPM_TCAM_TBL_SKIP(u, pk)   (ALPMC(u)->_alpm_tcam_tbl_skip[pk])
    765 #define ALPM_SCHAN_FIFO_HDL(u)      (ALPMC(u)->_alpm_schan_fifo_handle)
    766 #define ALPM_HLF_BNKS(u)            (ALPMC(u)->_alpm_half_banks)
    767 #define ALPM_PKM_RECOVER(u, ipt) \
    768     (((ipt) == ALPM_IPT_V4) ? ALPM_PKM_32B : ((ALPM_128B(u)) ? ALPM_PKM_128 : ALPM_PKM_64B))
    769 
    770 /* ALPM VRF/VRF_ID Macros */
    771 #define ALPM_VRF_ID_GHI(u)    (ALPMC(u)->_alpm_max_vrf_id + 2)
    772 #define ALPM_VRF_ID_GLO(u)    (ALPMC(u)->_alpm_max_vrf_id + 1)
    773 #define ALPM_VRF_ID_MAX(u)    (ALPMC(u)->_alpm_max_vrf_id + 2)
    774 #define ALPM_VRF_ID_CNT(u)    (ALPMC(u)->_alpm_max_vrf_id + 3)
    775 
    776 #define ALPM_VRF_ID_TO_VRF(u, vrf_id)                           \
    777     ((vrf_id) == ALPM_VRF_ID_GHI(u) ? BCM_L3_VRF_OVERRIDE :     \
    778      (vrf_id) == ALPM_VRF_ID_GLO(u) ? BCM_L3_VRF_GLOBAL :       \
    779      (vrf_id))
    780 
    781 #define ALPM_VRF_IS_GBL(u, vrf)                                 \
    782     ((vrf) == BCM_L3_VRF_OVERRIDE || (vrf) == BCM_L3_VRF_GLOBAL)
    783 
    784 #define ALPM_VRF_ID_IS_GBL(u, vrf_id)                           \
    785     ((vrf_id) == ALPM_VRF_ID_GHI(u) || (vrf_id) == ALPM_VRF_ID_GLO(u))
    786 #define ALPM_VRF_ID_TO_BPC_PID(u, vrf_id)                       \
    787     (ALPM_VRF_ID_IS_GBL(u, (vrf_id)) ? 1 : 0)
    788 #define ALPM_BPC_PID_TO_VRF_ID(u, pid)                          \
    789     (pid == ALPM_BKT_GLB_PID ? ALPM_VRF_ID_GLO(u) : 1)
    790 #define ALPM_VRF_ID_HAS_BKT(u, vrf_id)                          \
    791     ((vrf_id) == ALPM_VRF_ID_GHI(u) ? 0 :                       \
    792      (vrf_id) == ALPM_VRF_ID_GLO(u) ?                           \
    793      (ALPM_MODE_CHK(u, BCM_ALPM_MODE_TCAM_ALPM) ? 0 : 1) : 1)
    794 
    795 #define ALPM_VRF_TO_VRFID(u, vrf)                               \
    796     ((vrf) == BCM_L3_VRF_OVERRIDE ? ALPM_VRF_ID_GHI(u) :        \
    797      (vrf) == BCM_L3_VRF_GLOBAL ? ALPM_VRF_ID_GLO(u) :          \
    798      (vrf))
    799 
    800 #define ALPM_VRF_TRIE(u, vrf_id, ipt)                           \
    801         (ALPMC(u)->_vrf_pfx_hdl[vrf_id].pfx_trie[!!ipt])
    802 #define ALPM_VRF_DATA_MODE(u, vrf_id)                           \
    803         (ALPMC(u)->_vrf_pfx_hdl[vrf_id].data_mode)
    804 
    805 #define ALPM_GLO_VRF_IN_HLF_PMODE(u, vrf_id)                    \
    806         (ALPM_HLF_BNKS(u) && ALPM_MODE_CHK(u, BCM_ALPM_MODE_PARALLEL) && \
    807          vrf_id == ALPM_VRF_ID_GLO(u))
    808 
    809 /* ALPM BPC(BUCKET POOL CONFIG) Macros */
    810 #define BPC_BNK_PER_BKT(bp_conf)        ((bp_conf)->bnk_per_bkt)
    811 #define BPC_BNK_INFO(bp_conf, ipt)      ((bp_conf)->bnk_info[ipt])
    812 #define BPC_BNK_CNT(bp_conf)            ((bp_conf)->bnk_total)
    813 #define BPC_BNK_BMP(bp_conf, ipt)       (BPC_BNK_INFO(bp_conf, ipt)->bnk_btmp)
    814 #define BPC_BNK_RSVD(bp_conf, ipt)      (BPC_BNK_INFO(bp_conf, ipt)->bnk_rsvd)
    815 #define BPC_BNK_USED(bp_conf, ipt)      (BPC_BNK_INFO(bp_conf, ipt)->bnk_used)
    816 #define BPC_BKT_TBL(bp_conf)            ((bp_conf)->bkt_tbl)
    817 #define BPC_BKT_WRA(bp_conf)            ((bp_conf)->bkt_wra)
    818 #define BPC_BKT_FIXED_FMT(bp_conf)      ((bp_conf)->bkt_fixed_fmt)
    819 #define BPC_FMT_INFO(bp_conf)           ((bp_conf)->fmt_info)
    820 #define BPC_FMT_CNT(bp_conf)            (BPC_FMT_INFO(bp_conf)->fmt_count)
    821 #define BPC_FMT_TYPE(bp_conf)           (BPC_FMT_INFO(bp_conf)->fmt_type)
    822 #define BPC_FMT_PFX_LEN(bp_conf, fmt)   (BPC_FMT_INFO(bp_conf)->fmt_pfx_len[fmt])
    823 #define BPC_FMT_ENT_MAX(bp_conf, fmt)   (BPC_FMT_INFO(bp_conf)->fmt_ent_max[fmt])
    824 #define BPC_FMT_BNK(bp_conf, fmt)       (BPC_FMT_INFO(bp_conf)->fmt_bnk[fmt])
    825 #define BPC_FMT_ENT(bp_conf, fmt)       (BPC_FMT_INFO(bp_conf)->fmt_ent[fmt])
    826 #define BPC_FMT_FULL_TYPE(bp_conf, fmt) (BPC_FMT_INFO(bp_conf)->fmt_ftype[fmt])
    827 
    828 /* ALPM ACB Macros */
    829 #define ACB_IDX(acb)                ((acb)->acb_idx)
    830 #define ACB_HAS_TCAM(acb)           (ACB_IDX(acb) == 0)
    831 #define ACB(u, i)                   (ALPMC(u)->alpm_cb[i])
    832 #define ACB_UPR(u, acb)             (ACB(u, ACB_IDX(acb) - 1))
    833 #define ACB_DWN(u, acb)             (ACB(u, ACB_IDX(acb) + 1))
    834 #define ACB_TOP(u)                  (ACB(u, 0))
    835 #define ACB_CNT(u)                  (ALPMC(u)->_alpm_cb_cnt)
    836 #define ACB_BTM(u)                  (ACB(u, ACB_CNT(u) - 1))
    837 #define ACB_VRF_BTM_IDX(u, vrf_id)  (ALPMC(u)->_alpm_btm_cb_idx[ALPM_VRF_ID_TO_BPC_PID(u, vrf_id)])
    838 #define ACB_VRF_BTM(u, vrf_id)      (ACB(u, ACB_VRF_BTM_IDX(u, vrf_id)))
    839 
    840 #define ACB_VRF_INITED(u, acb, vrf_id, ipt)                     \
    841         ((acb)->pvt_ctl[!!ipt] &&                               \
    842          ACB_PVT_CTRL(acb, vrf_id, ipt).db_inited)
    843 #define ACB_VRF_INIT_SET(u, acb, vrf_id, ipt)                   \
    844         (ACB_PVT_CTRL(acb, vrf_id, ipt).db_inited = TRUE)
    845 #define ACB_VRF_INIT_CLEAR(u, acb, vrf_id, ipt)                 \
    846         (ACB_PVT_CTRL(acb, vrf_id, ipt).db_inited = FALSE)
    847 #define ACB_VRF_DB_TYPE(u, acb, vrf_id, ipt)                    \
    848         (ACB_PVT_CTRL(acb, vrf_id, ipt).db_type)
    849 #define ACB_VRF_DB_TYPE_SET(u, acb, vrf_id, ipt, rt)            \
    850         (ACB_PVT_CTRL(acb, vrf_id, ipt).db_type = rt)
    851 #define ACB_VRF_SPLEN_DIFF1(u, acb, vrf_id, ipt)                \
    852         (ACB_PVT_CTRL(acb, vrf_id, ipt).spl_len_diff1)
    853 #define ACB_VRF_SPLEN_DIFF2(u, acb, vrf_id, ipt)                \
    854         (ACB_PVT_CTRL(acb, vrf_id, ipt).spl_len_diff2)
    855 
    856 #define ACB_DR_INITED(u, acb, vrf_id, ipt)                      \
    857         ((acb)->pvt_ctl[!!ipt] &&                               \
    858          ACB_PVT_CTRL(acb, vrf_id, ipt).dr_inited)
    859 #define ACB_DR_INIT_SET(u, acb, vrf_id, ipt)                    \
    860         (ACB_PVT_CTRL(acb, vrf_id, ipt).dr_inited = TRUE)
    861 #define ACB_DR_INIT_CLEAR(u, acb, vrf_id, ipt)                  \
    862         (ACB_PVT_CTRL(acb, vrf_id, ipt).dr_inited = FALSE)
    863 
    864 #define ACB_BNK_CONF(acb)               ((acb)->bnk_conf)
    865 #define ACB_BNK_BMP(acb, vrf_id, ipt)                           \
    866         (BPC_BNK_BMP(ACB_BKT_VRF_POOL(acb, vrf_id), ipt))
    867 #define ACB_BNK_CNT(acb, vrf_id)                                \
    868         (BPC_BNK_CNT(ACB_BKT_VRF_POOL(acb, vrf_id)))
    869 #define ACB_PID_BNK_CNT(acb, pid)                               \
    870         (BPC_BNK_CNT(ACB_BKT_POOL(acb, pid)))
    871 #define ACB_BNK_PER_BKT(acb, vrf_id)                            \
    872         (BPC_BNK_PER_BKT(ACB_BKT_VRF_POOL(acb, vrf_id)))
    873 #define ACB_BKT_POOL(acb, pid)          (ACB_BNK_CONF(acb).bkt_pool[pid])
    874 #define ACB_BKT_VRF_POOL(acb, vrf_id)                           \
    875         (ACB_BKT_POOL(acb, ALPM_VRF_ID_TO_BPC_PID(acb->unit, vrf_id)))
    876 #define ACB_POOL_FMT_INFO(acb, pid)     (BPC_FMT_INFO(ACB_BKT_POOL(acb, pid)))
    877 #define ACB_VRF_POOL_FMT_INFO(acb, vrf_id)                      \
    878         (BPC_FMT_INFO(ACB_BKT_POOL(acb, ALPM_VRF_ID_TO_BPC_PID(acb->unit, vrf_id))))
    879 #define ACB_BKT_TBL(acb, vrf_id)                                \
    880         (BPC_BKT_TBL(ACB_BKT_VRF_POOL(acb, vrf_id)))
    881 #define ACB_BKT_WRA(acb, vrf_id)                                \
    882         (BPC_BKT_WRA(ACB_BKT_VRF_POOL(acb, vrf_id)))
    883 #define ACB_BKT_FIXED_FMT(acb, vrf_id)                          \
    884         (BPC_BKT_FIXED_FMT(ACB_BKT_VRF_POOL(acb, vrf_id)))
    885 #define ACB_PVT_CTRL(acb, vrf_id, ipt)  (acb->pvt_ctl[!!ipt][vrf_id])
    886 #define ACB_PVT_TRIE(acb, vrf_id, ipt)                          \
    887         (ACB_PVT_CTRL(acb, vrf_id, ipt).pvt_trie)
    888 #define ACB_VRF_PVT_PTR(acb, vrf_id, idx)                       \
    889         (ACB_BKT_VRF_POOL(acb, vrf_id)->pvt_ptr[idx])
    890 #define ACB_PVT_PTR(acb, pvt_node, idx)                         \
    891         (ACB_VRF_PVT_PTR(acb, PVT_BKT_VRF(pvt_node), idx))
    892 
    893 #define ACB_PID_CNT(acb)                                        \
    894         (ACB_BKT_POOL(acb, 0) == ACB_BKT_POOL(acb, 1) ? 1 : 2)
    895 #define ACB_BKT_VRF_PID(acb, vrf_id)                            \
    896         (ACB_BKT_POOL(acb, 0) == ACB_BKT_POOL(acb, 1) ? 0 :     \
    897         ALPM_VRF_ID_TO_BPC_PID(acb->unit, vrf_id))
    898 
    899 #define ACB_BKT_BITS(acb)               (ACB_BNK_CONF(acb).bkt_bits)
    900 #define ACB_BKT_CNT(acb)                (1 << ACB_BKT_BITS(acb))
    901 #define ACB_BKT_DW(acb)                 (ACB_BNK_CONF(acb).bkt_dw)
    902 #define ACB_BNK_BITS(acb)               (ACB_BNK_CONF(acb).bnk_bits)
    903 #define ACB_PHY_BNK_PER_BKT(acb)        (ACB_BNK_CONF(acb).phy_bnks_per_bkt)
    904 #define ACB_FMT_PFX_LEN(acb, vrf_id, fmt)  (ACB_VRF_POOL_FMT_INFO(acb, vrf_id)->fmt_pfx_len[fmt])
    905 #define ACB_FMT_ENT_MAX(acb, vrf_id, fmt)  (ACB_VRF_POOL_FMT_INFO(acb, vrf_id)->fmt_ent_max[fmt])
    906 #define ACB_FMT_BNK(acb, vrf_id, fmt)   (ACB_VRF_POOL_FMT_INFO(acb, vrf_id)->fmt_bnk[fmt])
    907 #define ACB_FMT_ENT(acb, vrf_id, fmt)   (ACB_VRF_POOL_FMT_INFO(acb, vrf_id)->fmt_ent[fmt])
    908 #define ACB_FMT_FULL_TYPE(acb, vrf_id, fmt)  (ACB_VRF_POOL_FMT_INFO(acb, vrf_id)->fmt_ftype[fmt])
    909 #define ACB_FMT_CNT(acb, vrf_id)        (ACB_VRF_POOL_FMT_INFO(acb, vrf_id)->fmt_count)
    910 #define ACB_FMT_TYPE(acb, vrf_id)        (ACB_VRF_POOL_FMT_INFO(acb, vrf_id)->fmt_type)
    911 #define ACB_HLF_BNK_MD(acb)             (ACB_BNK_BITS(acb) == 2)
    912 
    913 #define ACB_HAS_RTE(acb, vrf_id)    (ACB_FMT_TYPE(acb, vrf_id) == ALPM_FMT_RTE)
    914 #define ACB_HAS_PVT(acb, vrf_id)    (ACB_FMT_TYPE(acb, vrf_id) == ALPM_FMT_PVT)
    915 #define ACB_VRF_EMPTY(acb, vrf_id)  (ACB_FMT_TYPE(acb, vrf_id) == ALPM_FMT_CNT)
    916 
    917 /* ALPM LPM Macros */
    918 #define ALPM_LPM_DIRECT_RTE(u, lpm_cfg)                         \
    919     ((lpm_cfg->defip_flags & BCM_L3_IPMC) ||                    \
    920     (((lpm_cfg)->defip_vrf == BCM_L3_VRF_OVERRIDE) ? 1 :        \
    921      ((lpm_cfg)->defip_vrf == BCM_L3_VRF_GLOBAL) ?              \
    922      (ALPM_MODE_CHK(u, BCM_ALPM_MODE_TCAM_ALPM) ? 1 : 0) : 0))
    923 
    924 #define ALPM_LPM_PKM(u, lpm_cfg)                                \
    925     ((lpm_cfg)->defip_flags & BCM_L3_IP6 ?                      \
    926      (ALPM_128B(u) ? ALPM_PKM_128 : ALPM_PKM_64B) :             \
    927      ALPM_PKM_32B)
    928 
    929 #define ALPM_LPM_IPT(u, lpm_cfg)                                \
    930     (((lpm_cfg)->defip_flags & BCM_L3_IP6) ? ALPM_IPT_V6 : ALPM_IPT_V4)
    931 
    932 #define ALPM_LPM_VRF_ID(u, lpm_cfg)                             \
    933     ((lpm_cfg)->defip_vrf >= 0 ?    (lpm_cfg)->defip_vrf :      \
    934      (lpm_cfg)->defip_vrf == BCM_L3_VRF_GLOBAL ?                \
    935                                     (ALPM_VRF_ID_GLO(u)) :      \
    936                                     (ALPM_VRF_ID_GHI(u)))
    937 
    938 /*  -- ALPM entry IDX Format --
    939  * IDX:
    940  *   <ent> | <bnk> | <bkt>
    941  * TAB_IDX:
    942  *   <bnk> | <bkt>
    943  */
    944 
    945 /*
    946  +-----------------------------------+
    947  | 8 bits    | bnk bits | bkt bits   |
    948  +-----------------------------------+
    949  | EntryID   | BankID   | BucketID   |
    950  +-----------------------------------+
    951  */
    952 
    953 #define ALPM_IDX_ENT_SHIFT          24
    954 #define ALPM_IDX_ENT_MASK           0xff
    955 #define ALPM_IDX_BNK_SHIFT(acb)     ACB_BKT_BITS(acb)
    956 #define ALPM_IDX_BNK_MASK           0xff
    957 #define ALPM_IDX_BKT_MASK(acb)      ((1 << ALPM_IDX_BNK_SHIFT(acb)) - 1)
    958 #define ALPM_TAB_IDX_MASK           ((1 << ALPM_IDX_ENT_SHIFT) - 1) /* 0xffffff */
    959 
    960 #define ALPM_IDX_TO_BKT(acb, idx)                            \
    961     ((idx) & ALPM_IDX_BKT_MASK(acb))
    962 
    963 #define ALPM_IDX_TO_BNK(acb, idx)                            \
    964     (((idx) >> ALPM_IDX_BNK_SHIFT(acb)) & ALPM_IDX_BNK_MASK)
    965 
    966 #define ALPM_IDX_TO_ENT(idx)                                 \
    967     (((idx) >> ALPM_IDX_ENT_SHIFT) & ALPM_IDX_ENT_MASK)
    968 
    969 #define ALPM_IDX_MAKE(acb, bi, bnk, ent)                     \
    970     (((ent) & ALPM_IDX_ENT_MASK) << ALPM_IDX_ENT_SHIFT |     \
    971      (bnk) << ALPM_IDX_BNK_SHIFT(acb) |                      \
    972      ((BI_BKT_IDX(bi) + ((bnk) < BI_ROFS(bi))) & ALPM_IDX_BKT_MASK(acb)))
    973 
    974 /*  -- ALPM Table IDX construct --
    975  * TAB_IDX:
    976  *   <bnk> | <bkt>
    977  */
    978 #define ALPM_TAB_IDX_GET_BKT_BNK(acb, rofs, bkt, bnk)       \
    979     ((bnk << ALPM_IDX_BNK_SHIFT(acb)) | (bkt + (rofs > bnk)))
    980 
    981 #define ALPM_TAB_IDX_GET(idx)   (idx & ALPM_TAB_IDX_MASK)
    982 
    983 #define ALPM_TAB_IDX_GET_BI_BNK(acb, bi, bnk)               \
    984     ALPM_TAB_IDX_GET_BKT_BNK(acb, BI_ROFS(bi), BI_BKT_IDX(bi), bnk)
    985 
    986 /* VRF Based Counter */
    987 #define VRF_PVT_LEN_CNT_ADD(acb, vrf_id, ipt, pvt_len)  \
    988 do {                                                    \
    989     ACB_PVT_CTRL(acb, vrf_id, ipt).pvt_len_cnt[pvt_len] ++;      \
    990 } while (0)
    991 
    992 #define VRF_PVT_LEN_CNT_DEC(acb, vrf_id, ipt, pvt_len)  \
    993 do {                                                    \
    994     ACB_PVT_CTRL(acb, vrf_id, ipt).pvt_len_cnt[pvt_len] --;      \
    995 } while (0)
    996 
    997 #define VRF_PVT_LEN_CNT_GET(acb, vrf_id, ipt, pvt_len)  \
    998     (ACB_PVT_CTRL(acb, vrf_id, ipt).pvt_len_cnt[pvt_len])
    999 
   1000 #define VRF_PVT_LEN_CNT_PTR(acb, vrf_id, ipt)           \
   1001     (ACB_PVT_CTRL(acb, vrf_id, ipt).pvt_len_cnt)
   1002 
   1003 #define VRF_ROUTE_ADD(acb, vrf_id, ipt)               \
   1004 do {                                                  \
   1005     ACB_PVT_CTRL(acb, vrf_id, ipt).route_cnt ++;      \
   1006     ACB_PVT_CTRL(acb, vrf_id, ipt).cnt_add ++;        \
   1007 } while (0)
   1008 
   1009 #define VRF_ROUTE_DEC(acb, vrf_id, ipt)               \
   1010 do {                                                  \
   1011     ACB_PVT_CTRL(acb, vrf_id, ipt).route_cnt --;      \
   1012     ACB_PVT_CTRL(acb, vrf_id, ipt).cnt_del ++;        \
   1013 } while (0)
   1014 
   1015 #define VRF_ROUTE_CNT(acb, vrf_id, ipt)               \
   1016     (ACB_PVT_CTRL(acb, vrf_id, ipt).route_cnt)
   1017 
   1018 /* ALPM logs */
   1019 /* Macro for invoking "fast" checker */
   1020 #define ALPM_LOG(chk_, stuff_) do {         \
   1021         if (bsl_fast_check(chk_)) {         \
   1022             bsl_printf stuff_;              \
   1023         }                                   \
   1024     } while (0)
   1025 
   1026 extern char alpm_tmpbuf[_ALPM_ERR_MSG_BUF_ENT_SZ];
   1027 extern void alpm_util_snprintf(const char *fmt, ...);
   1028 
   1029 #define ALPM_ERR_MSG_LOG(stuff_) do {       \
   1030         if (ALPMTR(u)) ALPM_LOG(BSL_LS_BCM_ALPM|BSL_ERROR, ("#%d: ", ALPMTR_CNT(u)));\
   1031         ALPM_LOG(BSL_LS_BCM_ALPM|BSL_ERROR, stuff_);\
   1032         if (ALPMC(u) != NULL) {\
   1033             sal_memset(alpm_tmpbuf, 0, sizeof(alpm_tmpbuf));\
   1034             if (ALPMTR(u)) sal_sprintf(alpm_tmpbuf, "#%d: ", ALPMTR_CNT(u));\
   1035             alpm_util_snprintf stuff_;\
   1036             _ALPM_ERR_MSG_INSERT(u, alpm_tmpbuf);  \
   1037         }\
   1038     } while (0)
   1039 
   1040 /* Any layer log macros */
   1041 #define ALPM_FATAL(stuff_)          ALPM_LOG(BSL_LS_BCM_ALPM|BSL_FATAL, stuff_)
   1042 #define ALPM_ERR(stuff_)            ALPM_ERR_MSG_LOG(stuff_)
   1043 #define ALPM_WARN(stuff_)           ALPM_LOG(BSL_LS_BCM_ALPM|BSL_WARN, stuff_)
   1044 #define ALPM_INFO(stuff_)           ALPM_LOG(BSL_LS_BCM_ALPM|BSL_INFO, stuff_)
   1045 #define ALPM_VERB(stuff_)           ALPM_LOG(BSL_LS_BCM_ALPM|BSL_VERBOSE, stuff_)
   1046 #define ALPM_DBG(stuff_)            ALPM_LOG(BSL_LS_BCM_ALPM|BSL_DEBUG, stuff_)
   1047 #define ALPM_LOG_CHECK(stuff_)      LOG_CHECK(BSL_LS_BCM_ALPM|(stuff_))
   1048 
   1049 /* ALPM ERROR condition check */
   1050 
   1051 #define ALPM_IER_PRT_EXCEPT(op, except_err)            \
   1052     do { int __rv__; if ((__rv__ = (op)) < 0) { \
   1053         if (__rv__ != (except_err) && __rv__ != BCM_E_BUSY) \
   1054         {ALPM_ERR(("ALPMerr: %s : %d rv %d\n", FUNCTION_NAME(), __LINE__, __rv__));} return(__rv__); } } while(0)
   1055 
   1056 /* If error return */
   1057 #define ALPM_IER(op)            \
   1058     do { int __rv__; if ((__rv__ = (op)) < 0) { \
   1059         if (__rv__ != BCM_E_BUSY) \
   1060         {ALPM_ERR(("ALPMerr: %s : %d rv %d\n", FUNCTION_NAME(), __LINE__, __rv__));} return(__rv__); } } while(0)
   1061 
   1062 #define ALPM_IEG_PRT_EXCEPT(op, except_err)            \
   1063     do { if ((rv = (op)) < 0) { \
   1064         if (rv != (except_err) && rv != BCM_E_BUSY) \
   1065         {ALPM_ERR(("ALPMerr: %s : %d rv %d\n", FUNCTION_NAME(), __LINE__, rv));} goto bad; } } while(0)
   1066 
   1067 /* If error goto */
   1068 #define ALPM_IEG(op)            \
   1069     do { if ((rv = (op)) < 0) { \
   1070         if (rv != BCM_E_BUSY) \
   1071         {ALPM_ERR(("ALPMerr: %s : %d rv %d\n", FUNCTION_NAME(), __LINE__, rv));} goto bad; } } while(0)
   1072 
   1073 #define ALPM_REALLOC_EG(_ptr, _size, _str)  \
   1074     do {                                    \
   1075         if (_ptr == NULL) {                 \
   1076             _ptr = alpm_util_alloc(_size, _str);\
   1077         }                                   \
   1078         if (_ptr == NULL) {                 \
   1079             rv = BCM_E_MEMORY;              \
   1080             ALPM_ERR(("ALPMerr: out of memory at %s : %d\n", FUNCTION_NAME(), __LINE__)); \
   1081             goto bad;                       \
   1082         }                                   \
   1083         sal_memset(_ptr, 0, _size);         \
   1084     } while (0)
   1085 
   1086 #define ALPM_ALLOC_EG(_ptr, _size, _str)    \
   1087     do {                                    \
   1088         _ptr = alpm_util_alloc(_size, _str);\
   1089         if (_ptr == NULL) {                 \
   1090             rv = BCM_E_MEMORY;              \
   1091             ALPM_ERR(("ALPMerr: out of memory at %s : %d\n", FUNCTION_NAME(), __LINE__)); \
   1092             goto bad;                       \
   1093         }                                   \
   1094         sal_memset(_ptr, 0, _size);         \
   1095     } while (0)
   1096 
   1097 #define ALPM_DMA_ALLOC_EG(_u, _ptr, _size, _str)    \
   1098     do {                                            \
   1099         _ptr = soc_cm_salloc(_u, _size, _str);      \
   1100         if (_ptr == NULL) {                 \
   1101             rv = BCM_E_MEMORY;              \
   1102             ALPM_ERR(("ALPMerr: out of memory at %s : %d\n", FUNCTION_NAME(), __LINE__)); \
   1103             goto bad;                       \
   1104         }                                   \
   1105         sal_memset(_ptr, 0, _size);         \
   1106     } while (0)
   1107 
   1108 /* ALPM externs */
   1109 extern int
   1110 alpm_trie_ent_to_pfx(int u, int pkm, void *e, int, int, uint32 *key);
   1111 extern void
   1112 alpm_trie_pfx_to_cfg(int u, uint32 *pfx, int plen, _bcm_defip_cfg_t *cfg);
   1113 
   1114 extern int
   1115 alpm_bkt_free_bnk_range_get(int u, SHR_BITDCL *bnk_bmp, int bnk_sz,
   1116                             int req_cnt, int *rng_left, int *rng_right,
   1117                             int *rng_mid);
   1118 extern int
   1119 alpm_bkt_bnk_nearest_get(int u, SHR_BITDCL *bnk_bmp, int bnk_sz,
   1120                          int left_bnk, int right_bnk, int *nst_bnk);
   1121 extern int
   1122 alpm_bkt_ent_get_attempt(int u, _alpm_cb_t *acb, _alpm_bkt_pool_conf_t *bp_conf,
   1123                  _alpm_bkt_info_t *bkt_info, uint8 def_fmt, int pfx_len,
   1124                  uint32 *ent_idx, int *fmt_update, int bkt_test);
   1125 
   1126 extern int alpm_cb_merge(int u, _alpm_cb_t *acb, int vrf_id, int ipt);
   1127 extern int alpm_cb_delete(int u, _alpm_cb_t *acb, _bcm_defip_cfg_t *lpm_cfg);
   1128 extern int alpm_cb_insert(int u, _alpm_cb_t *acb, _bcm_defip_cfg_t *cfg);
   1129 extern int alpm_cb_defrag(int u, _alpm_cb_t *acb, int vrf_id, int ipt);
   1130 extern int alpm_cb_expand(int u, _alpm_cb_t *acb, _alpm_pvt_node_t *, int, int *);
   1131 extern int alpm_cb_expand_in_bkt(int u, _alpm_cb_t *acb, _alpm_pvt_node_t *, int );
   1132 extern int alpm_cb_pvt_sanity_cb(int, _alpm_cb_t *, _alpm_pvt_node_t *, void *);
   1133 extern int alpm_cb_sanity(int u, int acb_bmp, int vrf_id, int);
   1134 extern int alpm_cb_find(int, _alpm_cb_t *, _bcm_defip_cfg_t *,
   1135                         _alpm_pvt_node_t **, _alpm_bkt_node_t **);
   1136 extern void alpm_cb_pvt_dump(int u, int acb_bmp, int bkt_idx);
   1137 extern void alpm_cb_fmt_dump(int u, int acb_bmp);
   1138 extern void alpm_cb_pvtlen_dump(int u, int acb_bmp);
   1139 extern void alpm_cb_bkt_dump(int u, int acb_bmp);
   1140 extern void alpm_cb_stat_dump(int u, int acb_bmp);
   1141 extern void alpm_cb_conf_dump(int u, int acb_bmp);
   1142 
   1143 extern int alpm_bkt_ent_write(int, _alpm_cb_t *, _alpm_pvt_node_t *,
   1144                               _bcm_defip_cfg_t *, int, uint32 write_flags);
   1145 
   1146 extern int  alpm_table_dump(int u, int vrf_id, soc_mem_t mem, int copyno, int index,
   1147                             int fmt, int ent_idx, int flags);
   1148 extern void th_alpm_table_ent_dump(int u, int vrf_id, soc_mem_t mem, void *entry,
   1149                 int copyno, int index, int fmt,
   1150                 int ent_idx, int flags, char *pfx);
   1151 
   1152 extern int soc_alpm_cmn_mode_get(int unit);
   1153 extern int soc_alpm_cmn_banks_get(int unit);
   1154 
   1155 /* ESW externs */
   1156 extern int bcm_esw_alpm_init(int u);
   1157 extern int bcm_esw_alpm_cleanup(int u, _bcm_l3_trvrs_data_t *trv_data,
   1158                                 _bcm_l3_trvrs_data_t *trv_data1);
   1159 extern int bcm_esw_alpm_fast_delete_all(int u, _bcm_l3_trvrs_data_t *trv_data,
   1160                                         _bcm_l3_trvrs_data_t *trv_data1);
   1161 extern int bcm_esw_alpm_lookup(int u, _bcm_defip_cfg_t *lpm_cfg);
   1162 extern int bcm_esw_alpm_insert(int u, _bcm_defip_cfg_t *lpm_cfg);
   1163 extern int bcm_esw_alpm_delete(int u, _bcm_defip_cfg_t *lpm_cfg);
   1164 extern int bcm_esw_alpm_update(int u, _bcm_defip_cfg_t *lpm_cfg);
   1165 extern int bcm_esw_alpm_find(int u, _bcm_defip_cfg_t *lpm_cfg,
   1166                              int *nh_ecmp_idx);
   1167 extern int bcm_esw_alpm_update_match(int u, _bcm_l3_trvrs_data_t *trv_data);
   1168 extern int bcm_esw_alpm_pvt_traverse(int u, int lvlp, int vrf_id, int ipt,
   1169                 bcm_esw_alpm_pvt_trav_cb trav_fn, void *user_data);
   1170 extern int bcm_esw_alpm_pfx_traverse(int u, int vrf_id, int ipt,
   1171                 bcm_esw_alpm_pfx_trav_cb trav_fn, void *user_data);
   1172 extern int bcm_esw_alpm_bkt_traverse(alpm_lib_trie_t *bkt_trie,
   1173                 bcm_esw_alpm_bkt_trav_cb trav_fn, void *user_data);
   1174 extern int bcm_esw_alpm_pvt_count_get(int u, _alpm_pvt_node_t *pvt_node, int *);
   1175 extern int bcm_esw_alpm_vrf_data_mode_get(int u, bcm_vrf_t vrf, uint32 flags,
   1176                                           bcm_l3_vrf_route_data_mode_t *mode);
   1177 extern int bcm_esw_alpm_vrf_data_mode_set(int u, bcm_vrf_t vrf, uint32 flags,
   1178                                           bcm_l3_vrf_route_data_mode_t mode);
   1179 extern int tcam_entry_to_key(int u, int pkm, void *e, int sub_idx, uint32 *key);
   1180 
   1181 #if defined(BCM_TOMAHAWK_SUPPORT)
   1182 extern int bcm_th3_alpm_add(int unit, _bcm_defip_cfg_t *lpm_cfg,
   1183                             int nh_ecmp_idx);
   1184 extern int bcm_th3_alpm_del(int unit, _bcm_defip_cfg_t *lpm_cfg);
   1185 extern int bcm_th3_alpm_get(int unit, _bcm_defip_cfg_t *lpm_cfg, int
   1186                             *nh_ecmp_idx);
   1187 extern int bcm_th3_alpm_find(int unit, _bcm_defip_cfg_t *lpm_cfg,
   1188                              int *nh_ecmp_idx);
   1189 extern int bcm_th3_alpm_update_match(int unit, _bcm_l3_trvrs_data_t *trv_data);
   1190 extern int bcm_th_alpm_add(int unit, _bcm_defip_cfg_t *lpm_cfg,
   1191                              int nh_ecmp_idx);
   1192 extern int bcm_th_alpm_del(int unit, _bcm_defip_cfg_t *lpm_cfg);
   1193 extern int bcm_th_alpm_get(int unit, _bcm_defip_cfg_t *lpm_cfg, int
   1194                             *nh_ecmp_idx);
   1195 extern int bcm_th_alpm_find(int unit, _bcm_defip_cfg_t *lpm_cfg,
   1196                              int *nh_ecmp_idx);
   1197 extern int bcm_th_alpm_update_match(int unit, _bcm_l3_trvrs_data_t *trv_data);
   1198 #endif
   1199 
   1200 /* Extern functions of alpm_tcam.c */
   1201 extern int bcm_esw_alpm_tcam_insert(int u, _bcm_defip_cfg_t *lpm_cfg, uint32 write_flags);
   1202 extern int bcm_esw_alpm_tcam_match(int u, _bcm_defip_cfg_t *lpm_cfg, int *idx);
   1203 extern int bcm_esw_alpm_tcam_delete(int u, _bcm_defip_cfg_t *lpm_cfg);
   1204 extern int bcm_esw_alpm_tcam_init(int u);
   1205 extern int bcm_esw_alpm_tcam_deinit(int u);
   1206 extern int bcm_esw_alpm_tcam_cleanup(int u);
   1207 extern int bcm_esw_alpm_tcam_state_free_get(int, int zn, int *fcnt, int *vcnt);
   1208 extern void bcm_esw_alpm_tcam_zone_dump(int u, char *pfx_str);
   1209 extern void bcm_esw_alpm_tcam_zone_state_dump(int u);
   1210 extern int bcm_esw_alpm_tcam_avail(int u, int vrf_id, int ipt, int key_len, int mc);
   1211 extern int alpm_pvt_trie_init(int u, int vrf_id, int ipt);
   1212 extern int alpm_pvt_trie_insert(int u, _bcm_defip_cfg_t *lpm_cfg);
   1213 extern int alpm_pvt_trie_delete(int u, _bcm_defip_cfg_t *lpm_cfg);
   1214 
   1215 /* APIs distributed hitbits */
   1216 extern int bcm_esw_alpm_hit_init(int u);
   1217 extern int bcm_esw_alpm_hit_deinit(int u);
   1218 extern int bcm_esw_alpm_clear_hit(int u, _bcm_defip_cfg_t *lpm_cfg);
   1219 extern int alpm_dist_hitbit_enable_set(int u, int us);
   1220 extern int alpm_dist_hitbit_interval_get(int u);
   1221 extern int alpm_rte_hit_get(int u, int vrf_id, _alpm_tbl_t tbl, int idx, int ent);
   1222 extern int alpm_pvt_ent_idx_get(int u, _alpm_cb_t *acb,
   1223                                 _alpm_pvt_node_t *pvt_node, int *ent_idx);
   1224 /* Extern fucntions for alpm_tr.c */
   1225 extern int bcm_esw_alpm_trace_init(int u);
   1226 extern int bcm_esw_alpm_trace_deinit(int u);
   1227 extern int alpm_trace_set(int u, int val);
   1228 extern int alpm_trace_clear(int u);
   1229 extern int alpm_trace_sanity(int u, int enable, int start, int end);
   1230 extern int alpm_trace_wrap_set(int u, int val);
   1231 extern int alpm_trace_log(int u, int op, _bcm_defip_cfg_t *cfg, int nh_idx, int rc);
   1232 
   1233 /* ALPM UnitTest definitions */
   1234 
   1235 #define ALPM_UT_FLAG_IP_INCR    (1U << 1)
   1236 #define ALPM_UT_FLAG_LEN_INCR   (1U << 2)
   1237 #define ALPM_UT_FLAG_VRF_INCR   (1U << 3)
   1238 #define ALPM_UT_FLAG_SPEED      (1U << 4)
   1239 #define ALPM_UT_FLAG_NOMSG      (1U << 5)
   1240 
   1241 #define ALPM_UT_V4 (1 << 0)
   1242 #define ALPM_UT_V6 (1 << 1)
   1243 
   1244 #define ALPM_UT_OPC_ADD     0
   1245 #define ALPM_UT_OPC_DEL     1
   1246 
   1247 typedef struct alpm_ut_route_db_s {
   1248     int         type;
   1249     int         vrf;
   1250     char        *base_addr;
   1251     uint32      pfx_len;
   1252     int         count;
   1253     int         opc;
   1254 } alpm_ut_route_db_t;
   1255 
   1256 
   1257 /* dbg_info */
   1258 extern int alpm_dbg_info_bmp_show(int u);
   1259 extern int alpm_dbg_info_bmp_set(int u, uint32 flags);
   1260 
   1261 #endif /* ALPM_ENABLE */
   1262 
   1263 #endif /* _BCM_INT_ALPM_H_ */
   1264