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

diag_sand_utils.h (4644B)


      1 /**
      2  * \file diag_sand_utils.h
      3  *
      4  * Misc. utilities for shell commands
      5  */
      6 /*
      7  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      8  * 
      9  * Copyright 2007-2020 Broadcom Inc. All rights reserved.
     10  */
     11 
     12 #ifndef DIAG_SAND_UTILS_H_INCLUDED
     13 #define DIAG_SAND_UTILS_H_INCLUDED
     14 
     15 #include <sal/core/libc.h>
     16 #include <sal/appl/field_types.h>
     17 #include <shared/utilex/utilex_rhlist.h>
     18 #include <shared/shrextend/shrextend_debug.h>
     19 #include <soc/register.h>
     20 #include <appl/diag/parse.h>
     21 #include <appl/diag/shell.h>
     22 #include <appl/diag/sand/diag_sand_utils.h>
     23 
     24 /**
     25  * \brief This macro, _SHR_CLI_EXIT, is the actual implementation of \ref SHR_CLI_EXIT
     26  *   Its documentation applies to \ref SHR_CLI_EXIT below.
     27  *   This macro is NOT to be used except from within \ref SHR_CLI_EXIT
     28  */
     29 /**
     30  * \brief Set exit error code and error-exit on expression error
     31  * with user log that has any number of parameters on formatting
     32  * string.
     33  *
     34  * \par DIRECT INPUT:
     35  *   \param [in] _expr              -\n
     36  *     Expression representing error. One of shr_error_e (_shr_error_t).
     37  *     If it evaluates to a 'non error' code then no log is created.
     38  *   \param [in] _formatting_string -
     39  *     Formatting string (to display) such that it matches the list
     40  *     of parameters (_p1, _p2, ...)
     41  *   \param [in] ...
     42  *     Any number of parameters (_p1,_p2,_p3,...) to display via the
     43  *     formatting string.
     44  * \par INDIRECT INPUT:
     45  *    LOG_ERROR            -             \n
     46  *      Standard BSL (JR1) LOG macro     \n
     47  *    _func_unit           -             \n
     48  *      Value of 'unit' input parameter at entry     \n
     49  *    BSL_META_U           -                         \n
     50  *      Standard BSL (JR1) meta data constructor
     51  * \par INDIRECT OUTPUT:
     52  *   * Newly set exit error value.
     53  *   * Full formatted string which may also be logged or printed.
     54  *   * Exit procedure.
     55  * \remark
     56  *   The number of parameters is fleaxible. This is forwarded
     57  *   to underlying macros using __VA_ARGS__
     58  *   See also: https://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html
     59  *   (including the explanation for ## before __VA_ARGS__)
     60  * \remark
     61  *   Note that with the introduction of the SHR_CLI_EXIT/_SHR_CLI_EXIT pair, the number of input parameters to
     62  *   _SHR_CLI_EXIT is at least one and it is not necessary to add the '##' before __VA_ARGS__. However, we leave
     63  *   it there as an example of usage. Also, the formatting string assumes an extra parameter of type 'string"!
     64  */
     65 #define _SHR_CLI_EXIT(_expr,_formatting_string,...) \
     66 { \
     67   int _rv = _expr;    \
     68   LOG_CLI((BSL_META_U(_func_unit, _formatting_string "%s"), ##__VA_ARGS__) ) ; \
     69   _func_rv = _rv ;    \
     70   SHR_EXIT() ;        \
     71 }
     72 /**
     73  * \brief
     74  *   Use this macro with the input as described on \ref _SHR_CLI_EXIT above!!!
     75  *
     76  *   This is only a 'prelude' for the main macro \ref _SHR_CLI_EXIT and
     77  *   is only intended TO ADD AN EMPTY PARAMETER.
     78  *   This is required because a variadic macro does not take invocation with no
     79  *   parameters when compiled under --pedantic-64
     80  * \sa https://notmuchmail.org/pipermail/notmuch/2012/007436.html
     81  */
     82 #define SHR_CLI_EXIT(...) _SHR_CLI_EXIT(__VA_ARGS__, "")
     83 
     84 /**
     85  * The same as above only exit when error
     86  */
     87 #define _SHR_CLI_EXIT_IF_ERR(_expr,_formatting_string,...) \
     88 { \
     89   int _rv = _expr;    \
     90   if (SHR_FAILURE(_rv)) \
     91   {             \
     92       LOG_CLI((BSL_META_U(_func_unit, _formatting_string "%s"), ##__VA_ARGS__) ) ; \
     93       _func_rv = _rv ;    \
     94       SHR_EXIT() ;        \
     95   }\
     96 }
     97 
     98 #define SHR_CLI_EXIT_IF_ERR(...) _SHR_CLI_EXIT_IF_ERR(__VA_ARGS__, "")
     99 
    100 void diag_sand_utils_collect_comma_args(
    101     args_t * a,
    102     char *valstr,
    103     char *first);
    104 
    105 cmd_result_t diag_sand_error_get(
    106     shr_error_e shr_ret);
    107 
    108 void diag_sand_value_to_str(
    109     uint32 *value,
    110     int value_bit_size,
    111     char *value_str,
    112     int value_str_size);
    113 
    114 int diag_sand_value_same(
    115     uint32 *value_first,
    116     uint32 *value_second,
    117     int value_bit_size);
    118 
    119 #define SHR_ERR_TO_SHELL    diag_sand_error_get(_func_rv)
    120 
    121 shr_error_e diag_sand_compare_init(
    122     char *match_n,
    123     void **compare_handle_p);
    124 
    125 int diag_sand_compare(
    126     void *compare_handle,
    127     char *string);
    128 
    129 void diag_sand_compare_close(
    130     void *compare_handle);
    131 
    132 shr_error_e diag_sand_reg_blocks_get(
    133     int unit,
    134     soc_reg_info_t * reginfo,
    135     char *block_str,
    136     char *match_n);
    137 
    138 shr_error_e diag_sand_mem_blocks_get(
    139     int unit,
    140     soc_mem_t mem,
    141     char *block_str,
    142     char *match_n);
    143 
    144 extern char cmd_set_device_usage[];
    145 
    146 cmd_result_t cmd_set_device(
    147     int unit,
    148     args_t * a);
    149 
    150 #endif /* DIAG_SAND_UTILS_H_INCLUDED */