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

system.h (14083B)


      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-2020 Broadcom Inc. All rights reserved.
      6  *
      7  * This header file defines important constants and structures for
      8  * use with the SOC Diagnostics Shell which is built upon the SOC
      9  * driver and SAL (System Abstraction Layer)
     10  */
     11 
     12 #ifndef _DIAG_SYSTEM_H
     13 #define _DIAG_SYSTEM_H
     14 
     15 #ifndef __KERNEL__
     16 #include <stdlib.h>
     17 #include <string.h>
     18 #include <ctype.h>
     19 #else
     20 #include <sal/core/libc.h>
     21 #endif
     22 
     23 #if !defined(BCM_DNX_SUPPORT) && !defined(BCM_DNXF_SUPPORT)
     24 /* { */
     25 /*
     26  * Do not include drv.h for any of DNXC compilations.
     27  */
     28 #include <soc/drv.h>
     29 /* } */
     30 #else
     31 /* { */
     32 /*
     33  * If this is any of DNXC compilations but ESW is also included then do
     34  * include drv.h
     35  */
     36 #if defined(BCM_ESW_SUPPORT)
     37 /* { */
     38 #include <soc/drv.h>
     39 /* } */
     40 #endif
     41 /* } */
     42 #endif
     43 #include <assert.h>
     44 #include <soc/types.h>
     45 #include <soc/chip.h>
     46 #include <soc/cm.h>
     47 #include <sal/core/alloc.h>
     48 #include <sal/core/spl.h>
     49 #include <soc/macipadr.h>
     50 #include <soc/portmode.h>
     51 #include <soc/port_ability.h>
     52 #include <soc/phyctrl.h>
     53 #include <soc/register.h>
     54 
     55 #include <soc/debug.h>
     56 
     57 #include <sal/core/thread.h>
     58 
     59 #include <bcm/types.h>
     60 
     61 #include <appl/diag/cmdlist.h>
     62 #include <sal/appl/sal.h>
     63 
     64 #include <bcm/l2.h>
     65 #include <bcm/l3.h>
     66 #include <bcm/tunnel.h>
     67 
     68 #include <bcm/field.h>
     69 #include <bcm/switch.h>
     70 
     71 /*
     72  * Define:      SOC_SCRIPT_EXT
     73  * Purpose:     Define standard BCM script file name extension
     74  */
     75 #ifndef SOC_SCRIPT_EXT
     76 #define SOC_SCRIPT_EXT  ".soc"
     77 #endif
     78 
     79 /*
     80  * Define:      SOC_INIT_RC
     81  * Purpose:     Defines a default run command/init file to load on startup.
     82  *              This is read from the default directory, which is commonly
     83  *              the same as where the image was booted from.
     84  *              This can be overridden globally by defining SOC_INIT_RC
     85  *              on the compile line, or on a per-unit basis by calling
     86  *              diag_rc_set() before diag_shell().
     87  */
     88 #ifndef SOC_INIT_RC
     89 #define SOC_INIT_RC     "rc.soc"
     90 #endif
     91 
     92 /*
     93  * Register types we understand
     94  */
     95 
     96 typedef struct regtype_entry_t {
     97     char *name;         /* Name of register for setreg/getreg commands */
     98     soc_regtype_t type; /* Type of register (e.g. soc_cpureg) */
     99     char *help;         /* Description of register for help command */
    100 } regtype_entry_t;
    101 
    102 
    103 
    104 #define    REGTEST_FLAG_MINIMAL    0x0001
    105 #define    REGTEST_FLAG_MASK64    0x0002    
    106 #define    REGTEST_FLAG_INC_PORT_MACROS   0x0004
    107 #define    REGTEST_FLAG_ACCESS_ONLY       0x0008
    108 #define SOC_REG_FIRST_BLK_TYPE(regblklist) regblklist[0]
    109 
    110 typedef struct reg_data {
    111     int unit;
    112     int start_from;
    113     int count;
    114     int error;
    115     int flags;
    116 } reg_data_t;
    117 
    118 
    119 extern regtype_entry_t *regtype_lookup_name(char *str);
    120 extern void regtype_print_all(void);
    121 
    122 
    123 /*
    124  * Diagnostic shell utilities: diag/util.c
    125  */
    126 
    127 #define FORMAT_PBMP_MAX   400   /* "0xdeadbeefdeadbeef; fe0,fe2,....ge2,hg" */
    128 #define FORMAT_GPORT_MAX  128
    129 
    130  extern int     i2xdigit(int digit);
    131  extern int     xdigit2i(int digit);
    132  extern int     isint(char *);
    133  extern void    tabify_line(char *out, char *in, int tab_width);
    134  extern sal_vaddr_t parse_address(char *str);
    135  extern uint32  parse_integer(char *str);
    136  extern int     parse_small_integers(int unit, char *s, soc_pbmp_t *pbmp);
    137  extern int     diag_parse_range(char *low, char *high,
    138                          int *min, int *max,
    139                          int legal_min, int legal_max);
    140  extern void    parse_long_integer(uint32 *val, int nval, char *str);
    141  extern void    format_long_integer(char *buf, uint32 *val, int nval);
    142  extern void    format_spec_long_integer(char *buf, uint32 *val, int nval);
    143  extern void    add_long_integer(uint32 *dst, uint32 *src, int nval);
    144  extern void    sub_long_integer(uint32 *dst, uint32 *src, int nval);
    145  extern void    neg_long_integer(uint32 *dst, int nval);
    146  extern void    format_uint64(char *buf, uint64 n);
    147  extern void    format_uint64_decimal(char *buf, uint64 n, int comma);
    148  extern uint64  parse_uint64(char *str);
    149  extern int     parse_macaddr(char *str, sal_mac_addr_t macaddr);
    150  extern void    format_macaddr(char buf[MACADDR_STR_LEN], sal_mac_addr_t macaddr);
    151  extern void    increment_macaddr(sal_mac_addr_t macaddr, int amount);
    152  extern int     parse_ipaddr(char *str, ip_addr_t *ipaddr);
    153  extern int     parse_ip6addr(char *str, ip6_addr_t ipaddr);
    154  extern void    increment_ip6addr(ip6_addr_t ipaddr, uint32 byte_pos, int amount);
    155  extern void    format_ipaddr(char buf[IPADDR_STR_LEN], ip_addr_t ipaddr);
    156  extern void    format_ipaddr_mask(char *buf, ip_addr_t ipaddr, ip_addr_t mask);
    157  extern void    format_ip6addr(char buf[IP6ADDR_STR_LEN], ip6_addr_t ipaddr);
    158  extern int     parse_pbmp(int unit, char *s, soc_pbmp_t *pbmp);
    159  extern int     parse_pp_pbmp(int unit, char *s, soc_pbmp_t *pbmp);
    160  extern int     parse_bcm_pbmp(int unit, char *s, bcm_pbmp_t *pbmp);
    161  extern int     parse_pbmp_no_error(int unit, char *s, soc_pbmp_t *pbmp);
    162  extern char   *format_pbmp(int unit, char *buf, int bufsize, soc_pbmp_t pbmp);
    163  extern char   *format_bcm_pbmp(int unit, char *buf, int bufsize, bcm_pbmp_t pbmp);
    164  extern char   *bcm_port_name(int unit, int port);
    165  extern char   *mod_port_name(int unit, int modid, int port);
    166  extern int     parse_port(int unit, char *s, soc_port_t *portp);
    167  extern char   *format_gport(char *buf, bcm_gport_t gport);
    168  extern int     parse_gport(int unit, char *s, soc_port_t *portp);
    169  extern int     parse_bcm_port(int unit, char *s, bcm_port_t *portp);
    170  extern int     parse_mod_port(int unit, char *s, bcm_mod_port_t *mp);
    171  extern bcm_field_qualify_t parse_field_qualifier(char *str);
    172  extern char   *format_field_qualifier(char *buf, bcm_field_qualify_t qual,
    173                                        int brief);
    174  extern int     parse_field_qset(char *str, bcm_field_qset_t *qset);
    175  extern char   *format_field_qset(char *buf, bcm_field_qset_t qset,
    176                                   char *separator);
    177  extern bcm_field_group_mode_t parse_field_group_mode(char *str);
    178  extern char   *format_field_group_mode(char *buf, bcm_field_group_mode_t mode,
    179                                         int brief);
    180  extern bcm_field_action_t parse_field_action(char *str);
    181  extern char   *format_field_action(char *buf, bcm_field_action_t action,
    182                                     int brief);
    183  extern int     parse_field_aset(char *str, bcm_field_aset_t *aset, uint8 add);
    184  extern char   *format_field_aset(char *buf, bcm_field_aset_t aset,
    185                                   char *separator);
    186 
    187  extern bcm_field_decap_t parse_field_decap(char *str);
    188  extern  bcm_field_MplsOam_Control_pktType_t parse_field_MplsOamCtrlPktType(char *str);
    189  extern  bcm_field_oam_type_t  parse_field_oam_type(char *str);
    190  extern  bcm_field_olp_header_type_t parse_field_olp_hdr_type(char *str);
    191  extern bcm_field_roe_frame_type_t parse_field_roe_frame_type(char *str);
    192  extern char   *format_field_decap(char *buf, bcm_field_decap_t decap);
    193  extern int     parse_num_range(int unit, char *s, int *min, int *max,
    194                                 int legal_min, int legal_max);
    195  extern int     parse_block_range(int unit, soc_block_types_t regtype, char *s,
    196                           int *min, int *max, soc_block_types_t mask);
    197  extern int     parse_memory_name(int unit, soc_mem_t *result, char *str, int *copyno, unsigned *array_index);
    198  extern int     parse_memory_index(int unit, soc_mem_t mem, char *val_str);
    199  extern unsigned parse_memory_array_index(int unit, soc_mem_t mem, char *val_str);
    200  extern int     parse_cmic_regname(int unit, char *name, uint32 *offset_ptr);
    201  extern int     parse_port_mode(char *str, soc_port_mode_t *mode);
    202  extern int     parse_port_ability(char *str, soc_port_ability_t *mode);
    203  extern void    format_port_mode(char *buf, int bufsize,
    204                          soc_port_mode_t mode, int abbrev);
    205  extern char   *format_system_control(bcm_switch_control_t control);
    206 
    207  extern pbmp_t   soc_property_get_bcm_pbmp(int unit, const char *name, int defneg);
    208  extern uint32   soc_property_bcm_port_get(int unit, bcm_port_t aport, const char *name, uint32 defl);
    209 
    210  extern int     parse_phy_control_longreach_ability(char *str, 
    211                          soc_phy_control_longreach_ability_t *ability);
    212  extern void    format_phy_control_longreach_ability(char *buf, int bufsize, 
    213                          soc_phy_control_longreach_ability_t ability);
    214 
    215  extern int     parse_format_name(int unit, char *str, soc_format_t *format);
    216 
    217 #ifdef __KERNEL__
    218 #include <linux/kernel.h>
    219  extern char *strtok(char *s, const char *delim);
    220 #endif
    221  extern const char *strcaseindex(const char *s, const char *sub);
    222  extern char    *strrepl(char *s, int start, int len, const char *repstr);
    223 
    224  extern uint32  packet_load(uint8 *addr, int size);
    225  extern void    packet_random_store(uint8 *buf, int size);
    226  extern uint32  packet_store(uint8 *buf, int size, uint32 val, uint32 inc);
    227  extern int     packet_compare(uint8 *p1, uint8 *p2, int size);
    228  extern void    dump_l2_addr(int unit, char *pfx, bcm_l2_addr_t *l2addr);
    229  extern void    dump_l2_cache_addr(int unit, char *pfx, bcm_l2_cache_addr_t *l2caddr);
    230 
    231 
    232 #define BCM_PORT_NAME(_u,_p) bcm_port_name(_u,_p)
    233 
    234 /*
    235  * A couple of routines in reg.c
    236  */
    237 
    238 #define REG_PRINT_HEX           0x01
    239 #define REG_PRINT_RAW           0x02
    240 #define REG_PRINT_DO_PRINT      0x04
    241 #define REG_PRINT_CHG           0x08
    242 #define REG_PRINT_ADDR          0x10
    243 #define REG_PRINT_BLOCK         0x20
    244 
    245  extern void reg_print(int unit, soc_regaddrinfo_t *ainfo, uint64 val, uint32 flags,
    246                char *fld_sep, int wrap, char *field_names);
    247  extern int reg_print_all(int unit, soc_regaddrlist_t *alist, uint32 flags, char *field_names);
    248 
    249 /*
    250  * symtab.c
    251  */
    252  extern void init_symtab(void);
    253 
    254  extern int parse_symbolic_reference(int unit, soc_regaddrlist_t *alist, char *ref);
    255 
    256 /*
    257  * reg_skip.c
    258  */
    259  extern int reg_mask_subset(int unit, soc_regaddrinfo_t *ainfo, uint64 *mask);
    260  extern int rval_test_skip_reg(int unit, soc_regaddrinfo_t *ainfo, reg_data_t *rd);
    261 
    262 /* 
    263  * Shell routines: internal, used for diagnostics shell.
    264  */
    265 
    266  extern void    diag_init(void);
    267  extern void    diag_rc_set(int unit, const char *fname);
    268  extern void    diag_rc_get(int unit, const char **fname);
    269  extern int     diag_rc_load(int unit);
    270  extern void    diag_shell(void);
    271  extern void    diag_sdk_init(void);
    272  extern void    diag_cli_run(void);
    273  extern int     parseEndOk(args_t *, parse_table_t *, cmd_result_t *);
    274 
    275 #if defined(INCLUDE_EDITLINE)
    276  extern int diag_list_possib(char *regpref, char ***avp);
    277  extern char *diag_complete(char *regpref, int *unique);
    278 #endif
    279 
    280 #if defined (BCM_ESW_SUPPORT) ||  defined (BCM_DFE_SUPPORT)|| defined (BCM_PETRA_SUPPORT)
    281  extern int bist_args_to_mems(int unit, args_t *a, soc_mem_t *mems, int *num_mems);
    282 #endif
    283 #ifdef BCM_PETRA_SUPPORT
    284 extern uint8 blocks_can_be_disabled(soc_block_types_t blocks);
    285 extern uint8 block_can_be_disabled(soc_block_type_t block);
    286 #endif
    287 
    288 /* Packet Watcher */
    289 
    290  extern int pw_running(int unit);
    291  extern cmd_result_t pw_stop(int unit, int sync);
    292 
    293 #if defined(INCLUDE_PKTIO)
    294 extern int pktio_pw_running(int unit);
    295 extern int pktio_pw_clean(int unit);
    296 #endif /* INCLUDE_PKTIO */
    297 
    298 #if defined(BCM_LTSW_SUPPORT)
    299 extern int ltsw_pw_running(int unit);
    300 extern int ltsw_pw_clean(int unit);
    301 #endif /* BCM_LTSW_SUPPORT */
    302 
    303 /* Build Information */
    304 
    305 extern char *_build_release;
    306 extern char *_build_user;
    307 extern char *_build_host;
    308 extern char *_build_date;
    309 extern char *_build_datestamp;
    310 extern char *_build_tree;
    311 extern char *_build_arch;
    312 extern char *_build_os;
    313 
    314 #define UNSUPPORTED_COMMAND(unit, chiptype, a)\
    315     if (SOC_CHIP_GROUP(unit) == chiptype) { \
    316         LOG_ERROR(BSL_LS_APPL_SHELL, \
    317                   (BSL_META_U(unit, \
    318                               "%s: command unsupported on %s\n"),    \
    319                    ARG_CMD(a), soc_dev_name(unit)));      \
    320         ARG_DISCARD(a);\
    321         return CMD_OK; /* Don't error out, or scripts may fail */\
    322     }
    323 
    324 /* counter.c */
    325 
    326 #define SHOW_CTR_CHANGED        0x01
    327 #define SHOW_CTR_SAME           0x02
    328 #define SHOW_CTR_Z              0x04
    329 #define SHOW_CTR_NZ             0x08
    330 #define SHOW_CTR_HEX            0x10
    331 #define SHOW_CTR_RAW            0x20
    332 #define SHOW_CTR_ED             0x40
    333 #define SHOW_CTR_MS             0x80
    334 #define SHOW_TOTAL              0x100
    335 #define SHOW_SELECTED_PORTS     0x200
    336 #define SHOW_FABRIC             0x400
    337 #define SHOW_NIF                0x800
    338 #define SHOW_COMPACT            0x1000
    339 #define SHOW_FULL               0x2000
    340 #define SHOW_CTR_DBG            0x4000
    341 #define SHOW_CTR_ALL_QUEUE      0x8000
    342 
    343 #define SHOW_INTR_Z             0x01
    344 #define SHOW_INTR_MASK          0x02
    345 #define SHOW_INTR_UNMASK        0x04
    346 #define SHOW_INTR_ALL           0x08
    347 
    348  extern void    do_show_counter(int unit, soc_port_t port, soc_reg_t ctr_reg,
    349                         int ar_idx, int flags);
    350  extern int     do_show_counters(int unit, soc_reg_t ctr_reg, soc_pbmp_t pbmp,
    351                          int flags);
    352 
    353 
    354  extern int     do_resync_counters(int unit, soc_pbmp_t pbmp);
    355 
    356  extern void    counter_val_set_by_port(int unit, soc_pbmp_t pbmp, uint64 val);
    357 
    358  extern int     system_init(int unit);
    359  extern int     system_shutdown(int unit, int cleanup);
    360 
    361 
    362 #if defined(BCM_LTSW_SUPPORT)
    363 extern int
    364 ltsw_show_counters_proc(int unit, bcm_pbmp_t pbmp, int flags);
    365 
    366 extern int
    367 ltsw_clear_counters_proc(int unit, bcm_pbmp_t pbmp);
    368 
    369 extern int
    370 ltsw_do_resync_counters(int unit, bcm_pbmp_t pbmp);
    371 #endif /* BCM_LTSW_SUPPORT */
    372 
    373 extern int sys_board_type_mng_get(void);  
    374 
    375 /* Memory watch utility */
    376 typedef struct mem_count_s {
    377     uint32  rd_count_old; /* Read counter, updated by cmd "memwatch show" */
    378     uint32  rd_count_cur; /* Read counter which shows current counts */
    379     uint32  wr_count_old; /* Write counter, updated by cmd "memwatch show" */
    380     uint32  wr_count_cur; /* Write counter which shows current counts */
    381 } mem_count_t;
    382 
    383 #ifdef BCM_DNX_SUPPORT
    384 #ifdef ADAPTER_SERVER_MODE
    385 extern sal_mutex_t dnx_adapter_init_lock;
    386 #endif
    387 #endif
    388 #endif /* !_DIAG_SYSTEM_H */