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

bsldnx.c (5132B)


      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  * Broadcom System Log Console Sink
      8  */
      9 
     10 #include <shared/bslenum.h>
     11 #include <appl/diag/bsldnx.h>
     12 
     13 #include <sal/core/libc.h> 
     14 #include <sal/appl/io.h> 
     15 #include <appl/diag/bslsink.h>
     16 #include <appl/diag/bslcons.h>
     17 #ifdef BCM_DNX_SUPPORT
     18 /* { */
     19 #include <shared/shrextend/shrextend_error.h>
     20 #include <appl/diag/bslenable.h>
     21 /* } */
     22 #endif
     23 STATIC int
     24 bsldnx_cons_vfprintf(void *file, const char *format, va_list args)
     25 {
     26     return sal_vprintf(format, args);
     27 }
     28 
     29 STATIC int
     30 bsldnx_cons_check(bsl_meta_t *meta)
     31 {
     32     return bslcons_is_enabled();
     33 }
     34 
     35 STATIC int
     36 bsldnx_cons_init(int* sink_id)
     37 {
     38     static bslsink_sink_t console_sink;
     39     bslsink_sink_t *sink = bslsink_sink_find("dnx console");
     40 
     41     if (sink == NULL) { /*no dnx console - create a new one*/
     42         /* Create console sink */
     43         sink = &console_sink;
     44         bslsink_sink_t_init(sink);
     45         sal_strncpy(sink->name, "dnx console", sizeof(sink->name));
     46         sink->vfprintf = bsldnx_cons_vfprintf;
     47         sink->check = bsldnx_cons_check;
     48         sink->enable_range.min = bslSeverityOff+1;
     49         sink->enable_range.max = bslSeverityCount-1;
     50         sal_strncpy(sink->prefix_format, "%f[%l]%F unit %u:",
     51                     sizeof(sink->prefix_format));
     52         sink->prefix_range.min = bslSeverityOff+1;
     53         sink->prefix_range.max = bslSeverityWarn;
     54         sink->options = BSLSINK_OPT_NO_ECHO;
     55 
     56         /* Clear all unit, they will be set in bsldnx_mgmt_init */
     57         SHR_BITCLR_RANGE(sink->units, 0, BSLSINK_MAX_NUM_UNITS);
     58         *sink_id = bslsink_sink_add(sink);
     59     } else{
     60         *sink_id = sink->sink_id;
     61     }
     62     
     63     return 0;
     64 }
     65 
     66 STATIC int
     67 bsldnx_unit_move(int unit, int old_sink_id, int new_sink_id)
     68 {
     69     bslsink_sink_t *old_sink, *new_sink;
     70 
     71     old_sink = bslsink_sink_find_by_id(old_sink_id);
     72     if (old_sink == NULL){
     73         return -1;
     74     }
     75 
     76     new_sink = bslsink_sink_find_by_id(new_sink_id);
     77     if (new_sink == NULL){
     78         return -1;
     79     }
     80     SHR_BITCLR(old_sink->units, unit);
     81     SHR_BITCLR(old_sink->units, BSLSINK_UNIT_UNKNOWN);
     82     SHR_BITSET(new_sink->units, unit);
     83     SHR_BITSET(new_sink->units, BSLSINK_UNIT_UNKNOWN);
     84     return 0;
     85 }
     86 #ifdef BCM_DNX_SUPPORT
     87 /* { */
     88 /*
     89  * Set minimal/maximal severity level for displaying the 'prefix' as defined for DNX.
     90  * The 'prefix' is, by standard usage, 'line number', 'procedure name', 'file name', etc.
     91  */
     92 static int
     93   bsldnx_set_prefix_range_min_max(bsl_severity_t min_severity, bsl_severity_t max_severity)
     94 {
     95     bslsink_sink_t *sink ;
     96     int ret ;
     97 
     98     ret = 0 ;
     99     sink = bslsink_sink_find("dnx console") ;
    100     /*
    101      * If severity is out of range then do nothing.
    102      */
    103     if ((min_severity < (bslSeverityOff + 1)) || (min_severity >= bslSeverityCount)) {
    104         ret = 1 ;
    105         goto exit ;
    106     }
    107     if ((max_severity < (bslSeverityOff + 1)) || (max_severity >= bslSeverityCount)) {
    108         ret = 2 ;
    109         goto exit ;
    110     }
    111     /*
    112      * If there is no sink for 'dnx' (yet) then do nothing.
    113      */
    114     if (sink != NULL) {
    115         sink->prefix_range.min = min_severity ;
    116         sink->prefix_range.max = max_severity ;
    117     } else{
    118         ret = 3 ;
    119         goto exit ;
    120     }
    121 exit:
    122     return (ret) ;
    123 }
    124 /*
    125  * Get minimal/maximal severity level for displaying the 'prefix' as defined for DNX.
    126  * The 'prefix' is, by standard usage, 'line number', 'procedure name', 'file name', etc.
    127  */
    128 static int
    129   bsldnx_get_prefix_range_min_max(bsl_severity_t *min_severity, bsl_severity_t *max_severity)
    130 {
    131     bslsink_sink_t *sink ;
    132     int ret ;
    133 
    134     ret = 0 ;
    135     sink = bslsink_sink_find("dnx console") ;
    136     /*
    137      * If there is no sink for 'dnx' (yet) then return error and '*xxx_severity=0'.
    138      */
    139     if (sink != NULL) {
    140         *min_severity = sink->prefix_range.min ;
    141         *max_severity = sink->prefix_range.max ;
    142     } else{
    143         *min_severity = *max_severity = 0 ;
    144         ret = 1 ;
    145         goto exit ;
    146     }
    147 exit:
    148     return (ret) ;
    149 }
    150 /* } */
    151 #endif
    152 int
    153 bsldnx_mgmt_init(int unit)
    154 {
    155     int dnx_console_sink_id;
    156     bslsink_sink_t *console_sink_find = bslsink_sink_find("console");
    157     if (console_sink_find == NULL){
    158         return -1;
    159     }
    160     if (bsldnx_cons_init(&dnx_console_sink_id) != 0) {
    161         return -1;
    162     }
    163 #ifdef BCM_DNX_SUPPORT
    164 /* { */
    165     /*
    166      * Open access channel, to 'prefix control' system, for DNX error/debug
    167      * system. See LOG_DEBUG_EX.
    168      */
    169     set_proc_get_prefix_range_min_max(bsldnx_get_prefix_range_min_max) ;
    170     set_proc_set_prefix_range_min_max(bsldnx_set_prefix_range_min_max) ;
    171     /*
    172      * Open access channel, to 'severity control' system, for DNX error/debug
    173      * system. See SHR_SET_SEVERITY_FOR_MODULE/SHR_GET_SEVERITY_FOR_MODULE.
    174      */
    175     set_proc_bslenable_get(bslenable_get) ;
    176     set_proc_bslenable_set(bslenable_set) ;
    177 /* } */
    178 #endif
    179     return bsldnx_unit_move(unit,
    180                             console_sink_find->sink_id,
    181                             dnx_console_sink_id);
    182 }
    183