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

telemetry.c (15649B)


      1 /*
      2  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      3  * 
      4  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      5  */
      6 
      7 #include <shared/bslenum.h>
      8 #include <shared/bsl.h>
      9 
     10 #include <soc/defs.h>
     11 #include <soc/drv.h>
     12 
     13 #include <bcm/error.h>
     14 #include <bcm/telemetry.h>
     15 #include <bcm/collector.h>
     16 
     17 #include <bcm_int/esw/xgs5.h>
     18 #include <bcm_int/esw/telemetry.h>
     19 
     20 static sal_mutex_t mutex[BCM_MAX_NUM_UNITS];
     21 
     22 int bcm_esw_telemetry_lock(int unit)
     23 {
     24     if (mutex[unit] == NULL)
     25     {
     26         return BCM_E_INIT;
     27     }
     28 
     29     sal_mutex_take(mutex[unit], sal_mutex_FOREVER);
     30 
     31     return BCM_E_NONE;
     32 }
     33 
     34 int bcm_esw_telemetry_unlock(int unit)
     35 {
     36     if (mutex[unit] == NULL)
     37     {
     38         return BCM_E_INIT;
     39     }
     40 
     41     if (sal_mutex_give(mutex[unit]) != 0)
     42     {
     43         return BCM_E_INTERNAL;
     44     }
     45 
     46     return BCM_E_NONE;
     47 }
     48 
     49 /*
     50  * Function:
     51  *      bcm_esw_telemetry_init
     52  * Purpose:
     53  *      Initialize the Telemetry module.
     54  * Parameters:
     55  *      unit         - (IN) BCM device number
     56  * Returns:
     57  *      BCM_E_XXX   - BCM error code.
     58  */
     59 int bcm_esw_telemetry_init(int unit)
     60 {
     61     int result = BCM_E_UNAVAIL;
     62 #if defined(INCLUDE_TELEMETRY)
     63     if (soc_feature(unit, soc_feature_telemetry)) {
     64         /* Create mutex */
     65         if (mutex[unit] == NULL)
     66         {
     67             mutex[unit] = sal_mutex_create("telemetry.mutex");
     68 
     69             if (mutex[unit] == NULL)
     70             {
     71                 return BCM_E_MEMORY;
     72             }
     73         }
     74         result = _bcm_xgs5_telemetry_init(unit);
     75 
     76         /* If init itself fails, there is no point in having the mutex.
     77          * Destroy it.
     78          */
     79         if (BCM_FAILURE(result))
     80         {
     81             sal_mutex_destroy(mutex[unit]);
     82             mutex[unit] = NULL;
     83         }
     84     }
     85 #endif /* INCLUDE_TELEMETRY */
     86     return result;
     87 }
     88 
     89 /* Shut down the Telemetry module . */
     90 int bcm_esw_telemetry_detach(int unit)
     91 {
     92     int result = BCM_E_UNAVAIL;
     93 #if defined(INCLUDE_TELEMETRY)
     94     if (soc_feature(unit, soc_feature_telemetry)) {
     95         /* Take lock */
     96         BCM_IF_ERROR_RETURN(bcm_esw_telemetry_lock(unit));
     97 
     98         result = _bcm_xgs5_telemetry_detach(unit);
     99         /* Release lock */
    100         BCM_IF_ERROR_RETURN(bcm_esw_telemetry_unlock(unit));
    101     }
    102 #endif /* INCLUDE_TELEMETRY */
    103     return result;
    104 }
    105 
    106 /*
    107  * Function:
    108  *      bcm_esw_telemetry_config_set
    109  * Purpose:
    110  *      Configures a Telemetry application instance with specified
    111  *      number of telemetry objects information.
    112  * Parameters:
    113  *      unit                - (IN) BCM device number
    114  *      telemetry_instance  - (IN) The ID of telemetry instance to be created
    115  *      core                - (IN) FW core on which this instance need to be run
    116  *      config_count        - (IN)  Number of telemetry objects to be
    117  *                                     associated with this instance.
    118  *      telemetry_config_list  - (IN)  Telemetry objects information
    119  * Returns:
    120  *      BCM_E_XXX   - BCM error code.
    121  */
    122 int bcm_esw_telemetry_config_set(
    123         int unit,
    124         int telemetry_instance,
    125         int core,
    126         int config_count,
    127         bcm_telemetry_config_t *telemetry_config_list)
    128 {
    129     int result = BCM_E_UNAVAIL;
    130 #if defined(INCLUDE_TELEMETRY)
    131     /* Take lock */
    132     BCM_IF_ERROR_RETURN(bcm_esw_telemetry_lock(unit));
    133 
    134     if (soc_feature(unit, soc_feature_telemetry)) {
    135         result = _bcm_xgs5_telemetry_instance_config_update(unit,
    136                 telemetry_instance,
    137                 core, config_count,
    138                 telemetry_config_list);
    139     }
    140     /* Release lock */
    141     BCM_IF_ERROR_RETURN(bcm_esw_telemetry_unlock(unit));
    142 #endif /* INCLUDE_TELEMETRY */
    143     return result;
    144 }
    145 
    146 /*
    147  * Function:
    148  *      bcm_esw_telemetry_config_get
    149  * Purpose:
    150  *      Fetches a Telemetry application instance information.
    151  * Parameters:
    152  *      unit                - (IN) BCM device number
    153  *      telemetry_instance  - (IN) The ID of telemetry instance to be fetched
    154  *      core                - (IN) FW core on which this instance is being run
    155  *      max_count           - (IN) Maximum number of telemetry objects need 
    156  *                                 to be fetched
    157  *      telemetry_config_list - (OUT)  Telemetry objects information
    158  *      config_count        - (OUT) Actual number of telemetry objects to be
    159  *                                 associated with this instance.
    160  * Returns:
    161  *      BCM_E_XXX   - BCM error code.
    162  */
    163 int bcm_esw_telemetry_config_get(
    164         int unit,
    165         int telemetry_instance,
    166         int core,
    167         int max_count,
    168         bcm_telemetry_config_t *telemetry_config_list,
    169         int *config_count)
    170 {
    171     int result = BCM_E_UNAVAIL;
    172 #if defined(INCLUDE_TELEMETRY)
    173     /* Take lock */
    174     BCM_IF_ERROR_RETURN(bcm_esw_telemetry_lock(unit));
    175 
    176     if (soc_feature(unit, soc_feature_telemetry)) {
    177         result = _bcm_xgs5_telemetry_instance_config_get(unit,
    178                 telemetry_instance,
    179                 core, max_count,
    180                 telemetry_config_list,
    181                 config_count);
    182     }
    183     /* Release lock */
    184     BCM_IF_ERROR_RETURN(bcm_esw_telemetry_unlock(unit));
    185 #endif /* INCLUDE_TELEMETRY */
    186     return result;
    187 }
    188 
    189 /*
    190  * Function:
    191  *      bcm_esw_telemetry_export_config_set
    192  * Purpose:
    193  *      Configures the Telemetry instance export information.
    194  * Parameters:
    195  *      unit                - (IN) BCM device number
    196  *      telemetry_instance  - (IN) The ID of telemetry instance to be associated
    197  *      collector_id        - (IN) Colletor ID with which telemery instance
    198  *                                 needs to be associated
    199  *      export_profile_id   - (IN) Colletor export profile ID with which
    200  *                                 telemery instance needs to be associated
    201  * Returns:
    202  *      BCM_E_XXX   - BCM error code.
    203  */
    204 int bcm_esw_telemetry_export_config_set(
    205         int unit,
    206         int telemetry_instance,
    207         bcm_collector_t collector_id,
    208         int export_profile_id)
    209 {
    210     int result = BCM_E_UNAVAIL;
    211 #if defined(INCLUDE_TELEMETRY)
    212     /* Take lock */
    213     BCM_IF_ERROR_RETURN(bcm_esw_telemetry_lock(unit));
    214 
    215     if (soc_feature(unit, soc_feature_telemetry)) {
    216         result = _bcm_xgs5_telemetry_instance_export_config_update(unit,
    217                 telemetry_instance,
    218                 collector_id,
    219                 export_profile_id);
    220     }
    221     /* Release lock */
    222     BCM_IF_ERROR_RETURN(bcm_esw_telemetry_unlock(unit));
    223 #endif /* INCLUDE_TELEMETRY */
    224     return result;
    225 }
    226 
    227 /*
    228  * Function:
    229  *      bcm_esw_telemetry_export_config_get
    230  * Purpose:
    231  *      Fetches the Telemetry instance export information.
    232  * Parameters:
    233  *      unit                - (IN) BCM device number
    234  *      telemetry_instance  - (IN) The ID of telemetry instance whose details
    235  *                                 needs to be fetched
    236  *      collector_id        - (OUT) Pointer to colletor ID with which telemery
    237  *                                  instance has been associated
    238  *      export_profile_id   - (OUT) Pointer to colletor export profile ID with
    239  *                                  which telemery instance has been associated
    240  * Returns:
    241  *      BCM_E_XXX   - BCM error code.
    242  */
    243 int bcm_esw_telemetry_export_config_get(
    244         int unit,
    245         int telemetry_instance,
    246         bcm_collector_t *collector_id,
    247         int *export_profile_id)
    248 {
    249     int result = BCM_E_UNAVAIL;
    250 #if defined(INCLUDE_TELEMETRY)
    251     /* Take lock */
    252     BCM_IF_ERROR_RETURN(bcm_esw_telemetry_lock(unit));
    253 
    254     if (soc_feature(unit, soc_feature_telemetry)) {
    255         result = _bcm_xgs5_telemetry_instance_export_config_get(unit,
    256                 telemetry_instance,
    257                 collector_id,
    258                 export_profile_id);
    259     }
    260     /* Release lock */
    261     BCM_IF_ERROR_RETURN(bcm_esw_telemetry_unlock(unit));
    262 #endif /* INCLUDE_TELEMETRY */
    263     return result;
    264 }
    265 
    266 /*
    267  * Function:
    268  *      bcm_esw_telemetry_export_config_delete
    269  * Purpose:
    270  *      Deletes the Telemetry instance export information.
    271  * Parameters:
    272  *      unit                - (IN) BCM device number
    273  *      telemetry_instance  - (IN) The ID of telemetry instance whose
    274  *                                 association needs to be deleted
    275  *      collector_id        - (OUT) Pointer to colletor ID with which telemery
    276  *                                  instance has been associated
    277  *      export_profile_id   - (OUT) Pointer to colletor export profile ID with
    278  *                                  which telemery instance has been associated
    279  * Returns:
    280  *      BCM_E_XXX   - BCM error code.
    281  */
    282 int bcm_esw_telemetry_export_config_delete(
    283         int unit,
    284         int telemetry_instance,
    285         bcm_collector_t collector_id,
    286         int export_profile_id)
    287 {
    288     int result = BCM_E_UNAVAIL;
    289 #if defined(INCLUDE_TELEMETRY)
    290     bcm_collector_t coll_id;
    291     int profile_id;
    292 
    293     /* Check if the instance is mapped to the correct collector and export
    294      * profile
    295      */
    296     BCM_IF_ERROR_RETURN(
    297              bcm_esw_telemetry_export_config_get(unit, telemetry_instance,
    298                                                  &coll_id, &profile_id));
    299     if ((collector_id != coll_id) || (export_profile_id != profile_id)) {
    300         LOG_ERROR(BSL_LS_BCM_TELEMETRY,
    301                   (BSL_META_U(unit,
    302                                 "TELEMETRY(unit %d) Error: Invalid collector_id(%d)"
    303                                 " or export_profile_id(%d) \n"),
    304                    unit, collector_id, export_profile_id));
    305         return BCM_E_NOT_FOUND;
    306     }
    307 
    308     /* Take lock */
    309     BCM_IF_ERROR_RETURN(bcm_esw_telemetry_lock(unit));
    310 
    311     if (soc_feature(unit, soc_feature_telemetry)) {
    312         result = _bcm_xgs5_telemetry_instance_export_config_update(unit,
    313                 telemetry_instance,
    314                 BCM_TELEMETRY_INVALID_INDEX,
    315                 BCM_TELEMETRY_INVALID_INDEX);
    316     }
    317     /* Release lock */
    318     BCM_IF_ERROR_RETURN(bcm_esw_telemetry_unlock(unit));
    319 #endif /* INCLUDE_TELEMETRY */
    320     return result;
    321 }
    322 
    323 /*
    324  * Function:
    325  *      bcm_esw_telemetry_config_set
    326  * Purpose:
    327  *      Configures Telemetry system ID information.
    328  * Parameters:
    329  *      unit                - (IN) BCM device number
    330  *      system_id_len       - (IN) length of telemetry system ID
    331  *      system_id           - (IN) System ID value
    332  * Returns:
    333  *      BCM_E_XXX   - BCM error code.
    334  */
    335 int bcm_esw_telemetry_system_id_set(
    336         int unit, int system_id_len,
    337         uint8 *system_id)
    338 {
    339     int result = BCM_E_UNAVAIL;
    340 #if defined(INCLUDE_TELEMETRY)
    341     /* Take lock */
    342     BCM_IF_ERROR_RETURN(bcm_esw_telemetry_lock(unit));
    343 
    344     if (soc_feature(unit, soc_feature_telemetry)) {
    345         result = _bcm_xgs5_telemetry_system_id_set(unit,
    346                 system_id_len,
    347                 system_id);
    348     }
    349     /* Release lock */
    350     BCM_IF_ERROR_RETURN(bcm_esw_telemetry_unlock(unit));
    351 #endif /* INCLUDE_TELEMETRY */
    352     return result;
    353 }
    354 
    355 /*
    356  * Function:
    357  *      bcm_esw_telemetry_system_id_get
    358  * Purpose:
    359  *      Fetches Telemetry system ID information.
    360  * Parameters:
    361  *      unit                - (IN) BCM device number
    362  *      max_system_id_len   - (IN) Max length of telemetry system ID
    363  *      system_id_len       - (IN) System ID configured length
    364  *      system_id           - (IN) System ID value
    365  * Returns:
    366  *      BCM_E_XXX   - BCM error code.
    367  */
    368 int bcm_esw_telemetry_system_id_get(
    369         int unit, int max_system_id_len,
    370         int *system_id_len,
    371         uint8 *system_id)
    372 {
    373     int result = BCM_E_UNAVAIL;
    374 #if defined(INCLUDE_TELEMETRY)
    375     /* Take lock */
    376     BCM_IF_ERROR_RETURN(bcm_esw_telemetry_lock(unit));
    377 
    378     if (soc_feature(unit, soc_feature_telemetry)) {
    379         result = _bcm_xgs5_telemetry_system_id_get(unit,
    380                 max_system_id_len,
    381                 system_id_len,
    382                 system_id);
    383     }
    384     /* Release lock */
    385     BCM_IF_ERROR_RETURN(bcm_esw_telemetry_unlock(unit));
    386 #endif /* INCLUDE_TELEMETRY */
    387     return result;
    388 }
    389 
    390 /*
    391  * Function:
    392  *      bcm_esw_telemetry_instance_export_stats_get
    393  * Purpose:
    394  *      Get the telemetry export statistics.
    395  * Parameters:
    396  *      unit                - (IN)  BCM device number
    397  *      telemetry_instance  - (IN)  Telemetry instance ID
    398  *      collector_id        - (IN)  Collector ID
    399  *      stats               - (OUT) Export statistics.
    400  * Returns:
    401  *      BCM_E_XXX   - BCM error code.
    402  */
    403 int bcm_esw_telemetry_instance_export_stats_get(
    404                                     int unit,
    405                                     int telemetry_instance,
    406                                     bcm_collector_t collector_id,
    407                                     bcm_telemetry_instance_export_stats_t *stats)
    408 {
    409     int result = BCM_E_UNAVAIL;
    410 #if defined(INCLUDE_TELEMETRY)
    411     /* Take lock */
    412     BCM_IF_ERROR_RETURN(bcm_esw_telemetry_lock(unit));
    413 
    414     if (soc_feature(unit, soc_feature_telemetry)) {
    415         result = bcm_xgs5_telemetry_instance_export_stats_get(unit,
    416                                                               telemetry_instance,
    417                                                               collector_id,
    418                                                               stats);
    419     }
    420 
    421     /* Release lock */
    422     BCM_IF_ERROR_RETURN(bcm_esw_telemetry_unlock(unit));
    423 #endif /* INCLUDE_TELEMETRY */
    424     return result;
    425 }
    426 
    427 /*
    428  * Function:
    429  *      bcm_esw_telemetry_instance_export_stats_set
    430  * Purpose:
    431  *      Set the telemetry export statistics.
    432  * Parameters:
    433  *      unit                - (IN) BCM device number
    434  *      telemetry_instance  - (IN) Telemetry instance ID
    435  *      collector_id        - (IN) Collector ID
    436  *      stats               - (IN) Export statistics.
    437  * Returns:
    438  *      BCM_E_XXX   - BCM error code.
    439  */
    440 int bcm_esw_telemetry_instance_export_stats_set(
    441                                     int unit,
    442                                     int telemetry_instance,
    443                                     bcm_collector_t collector_id,
    444                                     bcm_telemetry_instance_export_stats_t *stats)
    445 {
    446     int result = BCM_E_UNAVAIL;
    447 #if defined(INCLUDE_TELEMETRY)
    448     /* Take lock */
    449     BCM_IF_ERROR_RETURN(bcm_esw_telemetry_lock(unit));
    450 
    451     if (soc_feature(unit, soc_feature_telemetry)) {
    452         result = bcm_xgs5_telemetry_instance_export_stats_set(unit,
    453                                                               telemetry_instance,
    454                                                               collector_id,
    455                                                               stats);
    456     }
    457 
    458     /* Release lock */
    459     BCM_IF_ERROR_RETURN(bcm_esw_telemetry_unlock(unit));
    460 #endif /* INCLUDE_TELEMETRY */
    461     return result;
    462 }
    463 
    464 /*
    465  * Function:
    466  *      _bcm_esw_telemetry_sw_dump
    467  * Purpose:
    468  *      Dumps telemetry module information
    469  * Parameters:
    470  *      unit           - (IN)  BCM device number
    471  * Returns: void
    472  */
    473 void _bcm_esw_telemetry_sw_dump(int unit)
    474 {
    475 #if defined(INCLUDE_TELEMETRY)
    476 
    477     if (soc_feature(unit, soc_feature_telemetry)) {
    478         _bcm_xgs5_telemetry_sw_dump(unit);
    479     }
    480 #endif /* INCLUDE_COLLECTOR */
    481 
    482 }
    483 
    484 #ifdef BCM_WARM_BOOT_SUPPORT
    485 /*
    486  * Function:
    487  *      _bcm_esw_telemetry_sync
    488  * Purpose:
    489  *      Warmboot scache sync for telemetry module
    490  * Parameters:
    491  *      unit - (IN) Unit number.
    492  * Returns:
    493  *      BCM_E_XXX
    494  * Notes:
    495  */
    496 int _bcm_esw_telemetry_sync(int unit)
    497 {
    498     int result = BCM_E_UNAVAIL;
    499 #if defined(INCLUDE_TELEMETRY)
    500     /* Take lock */
    501     BCM_IF_ERROR_RETURN(bcm_esw_telemetry_lock(unit));
    502 
    503     if (soc_feature(unit, soc_feature_telemetry)) {
    504         result = _bcm_xgs5_telemetry_sync(unit);
    505     }
    506     /* Release lock */
    507     BCM_IF_ERROR_RETURN(bcm_esw_telemetry_unlock(unit));
    508 #endif /* INCLUDE_TELEMETRY */
    509     return result;
    510 }
    511 #endif /* BCM_WARM_BOOT_SUPPORT */
    512