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_util.h (9153B)


      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_util.h
      8  * Purpose:     Function declarations for ALPM UTIL Internal functions.
      9  */
     10 
     11 #ifndef _BCM_INT_ALPM_UTIL_H_
     12 #define _BCM_INT_ALPM_UTIL_H_
     13 
     14 #include <soc/defs.h>
     15 
     16 #ifdef ALPM_ENABLE
     17 
     18 /* ALPM */
     19 typedef struct _alpm_log_s {
     20     uint16  op;
     21     uint16  sublen;
     22     int     vrf;
     23     int     nh_idx;
     24     int     rc; /* op returned code */
     25     int     seq; /* route sequence */
     26     uint32  flags;
     27     union u {
     28         bcm_ip_t    ip;
     29         bcm_ip6_t   ip6;
     30     } u;
     31 } _alpm_log_t;
     32 
     33 typedef struct _alpm_trace_s {
     34     int inited;
     35     int trace_en;
     36     int sanity_en;  /* trace sanity freq_cnt */
     37     int sanity_start;
     38     int sanity_end;
     39     int wrap_en;
     40     int wrap;       /* log wrapped TRUE/FALSE */
     41     int cnt;
     42     _alpm_log_t *buf;
     43     _alpm_log_t *curr;
     44     _alpm_log_t *start;
     45 } _alpm_trace_t;
     46 
     47 #define ALPM_TRACE_SIZE         0x400000
     48 #define ALPM_TRACE_DUMP_SIZE    10000
     49 
     50 #define ALPMTR(u)           (alpm_trace[u])
     51 #define ALPMTR_BUF(u)       (ALPMTR(u)->buf)
     52 #define ALPMTR_START(u)     (ALPMTR(u)->start)
     53 #define ALPMTR_CURR(u)      (ALPMTR(u)->curr)
     54 #define ALPMTR_CNT(u)       (ALPMTR(u)->cnt)
     55 #define ALPMTR_WRAP(u)      (ALPMTR(u)->wrap)
     56 #define ALPMTR_TRACE_EN(u)  (ALPMTR(u)->trace_en)
     57 #define ALPMTR_SANITY_EN(u) (ALPMTR(u)->sanity_en)
     58 #define ALPMTR_SANITY_START(u) (ALPMTR(u)->sanity_start)
     59 #define ALPMTR_SANITY_END(u) (ALPMTR(u)->sanity_end)
     60 #define ALPMTR_WRAP_EN(u)   (ALPMTR(u)->wrap_en)
     61 #define ALPMTR_INITED(u)    (ALPMTR(u)->inited)
     62 
     63 /* Max sub_idx count for both un-pair or pair TCAM
     64    (for pair TCAM step_size=2) */
     65 #define ALPM_TCAM_SUBCNT    2
     66 
     67 #define ALPM_HALF_FIELD_NAME(half, fld0, fld1) ((half) == 0 ? (fld0) : (fld1))
     68 
     69 #define ALPM_KEY_ENT_CNT(ipt) ((ipt) == ALPM_IPT_V4 ? 1 : 4)
     70 
     71 #define ALPM_IS_IPV4(pkm) ((pkm) == ALPM_PKM_32B ? TRUE : FALSE)
     72 #define ALPM_IS_IPV6(pkm) ((pkm) == ALPM_PKM_32B ? FALSE : TRUE)
     73 #define TCAM_TBL_NAME(acb, pkm)     (alpm_tbl_str[acb->pvt_tbl[pkm]])
     74 #define ALPM_TBL_NAME(tbl)          (alpm_tbl_str[tbl])
     75 #define ALPM_FLAGS_FILTER(flag) ((flag) &= (BCM_L3_MULTIPATH |                \
     76                                             BCM_L3_RPE | BCM_L3_DST_DISCARD))
     77 
     78 extern char *alpm_util_pkm_str[];
     79 extern char *alpm_util_ipt_str[];
     80 extern char *alpm_util_acb_str[];
     81 extern char *alpm_tbl_str[];
     82 extern _alpm_trace_t *alpm_trace[];
     83 
     84 /* External functions of alpm_ts.c */
     85 extern void bcm_esw_alpm_sw_dump(int u);
     86 extern int bcm_esw_alpm_debug_show(int u, int vrf_id, uint32 flags);
     87 extern int bcm_esw_alpm_debug_brief_show(int u, int bucket, int index);
     88 extern int bcm_esw_alpm_sanity_check(int u, soc_mem_t mem, int index,
     89                                      int check_sw);
     90 extern int alpm_pfx_hw_route_sanity(int u, int *tot_err);
     91 
     92 /* Additional ALPM & TCAM driver wrapper */
     93 extern int alpm_util_bkt_info_get(int u, int vrf_id, int ipt, int pvt_pkm, _alpm_cb_t *acb,
     94                                   void *e, int sub_idx, _alpm_bkt_info_t *bkt_info,
     95                                   int *kshift, int *def_miss);
     96 extern uint8 alpm_util_bkt_def_fmt_get(int u, _alpm_cb_t *acb, int vrf_id,
     97                                      int ipt);
     98 extern int16 alpm_util_bkt_fmt_type_get(int u, int vrf_id, _alpm_cb_t *acb, uint8 fmt);
     99 extern int alpm_util_ent_ent_get(int u, int vrf_id, _alpm_cb_t *acb, void *e,
    100                                  uint32 fmt, int eid, void *ftmp);
    101 extern void alpm_util_pfx_cat(int u, int ipt, uint32 *pfx1, int len1,
    102                               uint32 *pfx2, int len2, uint32 *new_pfx,
    103                               int *new_len);
    104 extern int alpm_util_pfx_len_cmp(void *a, void *b);
    105 extern int alpm_util_bkt_pfx_get(int u, int vrf_id, _alpm_cb_t *acb, void *e,
    106                                  uint32 fmt, uint32 *new_key, int *new_len,
    107                                  uint32 *valid);
    108 extern int alpm_util_bkt_adata_get(int u, int vrf_id, int ipt, _alpm_cb_t *acb, void *ftmp, int fmt,
    109                                    _alpm_bkt_adata_t *adata1, int *arg1);
    110 extern int alpm_util_ent_data_get(int u, int vrf_id, int ipt, _alpm_cb_t *acb, void *ftmp,
    111                                   int fmt, void *fent1);
    112 extern int alpm_util_ent_phy_idx_get(int u, _alpm_cb_t *acb,
    113                                      int vrf_id, int index);
    114 extern int alpm_util_bkt_token_bnks(int u, _alpm_cb_t *acb, int vrf_id,
    115                                     _alpm_pvt_node_t *pvt_node);
    116 
    117 extern void alpm_trace_print(int u, int showflags, _alpm_log_t *p, char *data);
    118 extern int _tcam_entry_write(int u, int pkm, void *e, int index, int s_index);
    119 extern int tcam_table_size(int u, int pkm);
    120 extern int tcam_entry_vrf_id_get(int u, int pkm, void *e,
    121                                   int sub_idx, int *vrf_id);
    122 extern int tcam_valid_entry_mode_get(int u, int pk, void *e, int *step_size,
    123                               int *pkm, int *ipv6, int *key_mode, int sub_idx);
    124 extern int tcam_entry_valid(int u, int pkm, void *e, int sub_idx);
    125 extern int tcam_entry_pfx_len_get(int u, int pkm, void *e,
    126                                    int sub_idx, int *pfx_len);
    127 extern int tcam_entry_adata_get(int u, int pkm, void *e, int sub_idx,
    128                                 _alpm_bkt_adata_t *adata);
    129 extern int tcam_entry_bdata_get(int u, int pkm, void *e,
    130                                 int sub_idx,  void *fent);
    131 extern int tcam_entry_hit_get(int u, int pkm, void *e, int sub_dx);
    132 extern int tcam_cache_hit_get(int u, int pkm, int tcam_idx);
    133 extern int tcam_hitbit_sync_cache(int u);
    134 extern int tcam_entry_to_cfg(int u, int pkm, void *e, int x,
    135                               _bcm_defip_cfg_t *lpm_cfg);
    136 extern int tcam_entry_read(int u, int pkm, void *e, int index, int s_index);
    137 extern int alpm_bkt_entry_read(int u, _alpm_tbl_t tbl, _alpm_cb_t *acb,
    138                                void *e, int index);
    139 extern int tcam_entry_read_no_cache(int u, int pkm, void *e,
    140                                     int index, int s_index);
    141 extern int alpm_bkt_entry_read_no_cache(int u, _alpm_tbl_t tbl,
    142                             _alpm_cb_t *acb, void *e, int index);
    143 /* ALPM utils */
    144 extern void * alpm_util_alloc(unsigned int sz, char *s);
    145 extern void alpm_util_free(void *addr);
    146 extern void alpm_util_mem_stat_get(uint32 *alloc_cnt, uint32 *free_cnt);
    147 extern void alpm_util_mem_stat_clear(void);
    148 extern int alpm_util_route_capacity_get(int u, soc_mem_t mem,
    149                                    int *max_entries, int *min_entries);
    150 extern void
    151 alpm_util_fmt_tbl_util(int unit, char *buf);
    152 extern void
    153 alpm_util_fmt_bkt_info(char *buf, int vrf_id, _alpm_cb_t *acb, _alpm_bkt_info_t *bkt_info);
    154 extern void
    155 alpm_util_fmt_ipaddr(char buf[SAL_IPADDR_STR_LEN], ip_addr_t ipaddr);
    156 extern void
    157 alpm_util_fmt_ip6addr(char buf[IP6ADDR_STR_LEN], ip6_addr_t ipaddr);
    158 extern void
    159 alpm_trie_key_to_pfx(int u, int ipt, uint32 *key, uint32 len, uint32 *pfx);
    160 extern void
    161 alpm_trie_pfx_to_key(int u, int ipt, uint32 *pfx, uint32 len, uint32 *key);
    162 extern void
    163 alpm_util_key_to_cfg(int u, int ipt, uint32 *key, _bcm_defip_cfg_t *lpm_cfg);
    164 extern void
    165 alpm_util_len_to_mask(int ipt, uint32 len, uint32 *mask);
    166 extern int
    167 alpm_util_cfg_construct(int u, int vrf_id, int ipt, uint32 *key, int key_len,
    168                         _alpm_bkt_adata_t *adata, _bcm_defip_cfg_t *lpm_cfg);
    169 extern int
    170 alpm_util_key_to_str(int u, int pkm, char * ipstr, uint32 *key, uint32 key_len,
    171                      _alpm_bkt_node_t *bkt_node, _alpm_pvt_node_t *pvt_node);
    172 extern int
    173 alpm_util_trie_max_key_len(int u, int ipt);
    174 
    175 extern int
    176 alpm_util_trie_max_split_len(int u, int pkm);
    177 
    178 extern void
    179 alpm_util_trie_pfx_print(int u, int ipt, uint32 *pfx, uint32 len,
    180                          const char *str);
    181 
    182 extern void
    183 alpm_util_adata_cfg_to_trie(int unit, _bcm_defip_cfg_t *lpm_cfg,
    184                             _alpm_bkt_adata_t *bkt_adata);
    185 
    186 extern void
    187 alpm_util_adata_trie_to_cfg(int unit, _alpm_bkt_adata_t *bkt_adata,
    188                             _bcm_defip_cfg_t *lpm_cfg);
    189 
    190 extern void
    191 alpm_util_adata_zero_cfg(int unit, _bcm_defip_cfg_t *lpm_cfg);
    192 
    193 extern uint8
    194 alpm_util_route_type_get(int u, _bcm_defip_cfg_t *lpm_cfg);
    195 
    196 extern int
    197 alpm_util_route_type_check(int u, _bcm_defip_cfg_t *lpm_cfg);
    198 
    199 extern int
    200 alpm_util_def_check(int u, _bcm_defip_cfg_t *lpm_cfg, int is_add);
    201 
    202 extern int
    203 alpm_util_is_my_pivot(int u, uint32 *trie_key, uint32 trie_len,
    204                       uint32 *pvt_key, uint32 pvt_len);
    205 
    206 extern void
    207 alpm_util_cfg_to_key(int u, int ipt, _bcm_defip_cfg_t *lpm_cfg, uint32 *key);
    208 
    209 extern void
    210 alpm_util_cfg_to_msk(int u, int ipt, _bcm_defip_cfg_t *lpm_cfg, uint32 *msk);
    211 
    212 extern void
    213 alpm_util_ipmask_apply(int u, _bcm_defip_cfg_t *lpm_cfg);
    214 
    215 extern void
    216 alpm_util_bnk_range_print(int u, SHR_BITDCL *bnk_bmp, int bnk_sz,
    217                           int bnk_per_row, int start, int end);
    218 
    219 extern int
    220 alpm_util_pvt_idx_get(int u, _alpm_cb_t *acb,
    221                       _alpm_pvt_node_t *pvt_node, int *idx, int *sub_idx);
    222 
    223 #endif /* ALPM_ENABLE */
    224 
    225 #endif /* _BCM_INT_ALPM_UTIL_H_ */
    226