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

collector.c (17605B)


      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/collector.h>
     15 
     16 #include <bcm_int/esw/collector.h>
     17 
     18 static sal_mutex_t mutex[BCM_MAX_NUM_UNITS];
     19 
     20 int bcm_esw_collector_lock(int unit)
     21 {
     22     if (mutex[unit] == NULL)
     23     {
     24         return BCM_E_INIT;
     25     }
     26 
     27     sal_mutex_take(mutex[unit], sal_mutex_FOREVER);
     28 
     29     return BCM_E_NONE;
     30 }
     31 
     32 int bcm_esw_collector_unlock(int unit)
     33 {
     34     if (mutex[unit] == NULL)
     35     {
     36         return BCM_E_INIT;
     37     }
     38 
     39     if (sal_mutex_give(mutex[unit]) != 0)
     40     {
     41         return BCM_E_INTERNAL;
     42     }
     43 
     44     return BCM_E_NONE;
     45 }
     46 
     47 /*
     48  * Function:
     49  *      bcm_esw_collector_init
     50  * Purpose:
     51  *      Initialize the Collector module.
     52  * Parameters:
     53  *      unit         - (IN) BCM device number
     54  * Returns:
     55  *      BCM_E_XXX   - BCM error code.
     56  */
     57 int bcm_esw_collector_init(int unit)
     58 {
     59 
     60     int result = BCM_E_UNAVAIL;
     61 #if defined(BCM_COLLECTOR_SUPPORT)
     62     if (soc_feature(unit, soc_feature_collector)) {
     63         /* Create mutex */
     64         if (mutex[unit] == NULL)
     65         {
     66             mutex[unit] = sal_mutex_create("collector.mutex");
     67 
     68             if (mutex[unit] == NULL)
     69             {
     70                 return BCM_E_MEMORY;
     71             }
     72         }
     73         result = _bcm_xgs5_collector_init(unit);
     74          /* If init itself fails, there is no point in having the mutex.
     75          * Destroy it.
     76          */
     77         if (BCM_FAILURE(result))
     78         {
     79             sal_mutex_destroy(mutex[unit]);
     80 
     81             mutex[unit] = NULL;
     82         }
     83     }
     84 #endif /* BCM_COLLECTOR_SUPPORT */
     85 
     86     return result;
     87 }
     88 
     89 /* Shut down the Collector module . */
     90 int bcm_esw_collector_detach(int unit)
     91 {
     92     int result = BCM_E_UNAVAIL;
     93 
     94 #if defined(BCM_COLLECTOR_SUPPORT)
     95     if (soc_feature(unit, soc_feature_collector)) {
     96         /* Take lock */
     97         BCM_IF_ERROR_RETURN(bcm_esw_collector_lock(unit));
     98 
     99         result = _bcm_xgs5_collector_detach(unit);
    100         /* Release lock */
    101         BCM_IF_ERROR_RETURN(bcm_esw_collector_unlock(unit));
    102     }
    103 #endif /* BCM_COLLECTOR_SUPPORT */
    104     
    105     return result;
    106 }
    107 
    108 /*
    109  * Function:
    110  *      bcm_esw_collector_export_profile_create
    111  * Purpose:
    112  *      Creates a collector export profile with given export profile info.
    113  * Parameters:
    114  *      unit            - (IN)  BCM device number
    115  *      options         - (IN)  Create options
    116  *      export_profile  - (INOUT)  Export profile Id
    117  *      export_profile_info  - (IN)  Export profile info
    118  * Returns:
    119  *      BCM_E_XXX   - BCM error code.
    120  */
    121 int bcm_esw_collector_export_profile_create(
    122         int unit,
    123         uint32 options,
    124         int *export_profile,
    125         bcm_collector_export_profile_t *export_profile_info)
    126 {
    127     int result = BCM_E_UNAVAIL;
    128 
    129 #if defined(BCM_COLLECTOR_SUPPORT)
    130    /* Take lock */
    131     BCM_IF_ERROR_RETURN(bcm_esw_collector_lock(unit));
    132 
    133     if (soc_feature(unit, soc_feature_collector)) {
    134         result = _bcm_xgs5_collector_export_profile_create(unit, options,
    135                 export_profile,
    136                 export_profile_info);
    137     }
    138     /* Release lock */
    139     BCM_IF_ERROR_RETURN(bcm_esw_collector_unlock(unit));
    140 #endif /* BCM_COLLECTOR_SUPPORT */
    141     return result;
    142 }
    143 
    144 /*
    145  * Function:
    146  *      bcm_esw_collector_export_profile_get
    147  * Purpose:
    148  *      Gets collector export profile information
    149  * Parameters:
    150  *      unit            - (IN)  BCM device number
    151  *      id              - (IN)  Export profile Id
    152  *      export_profile_info  - (OUT)  Export profile info
    153  * Returns:
    154  *      BCM_E_XXX   - BCM error code.
    155  */
    156 int bcm_esw_collector_export_profile_get(
    157         int unit,
    158         int export_profile,
    159         bcm_collector_export_profile_t *export_profile_info)
    160 {
    161     int result = BCM_E_UNAVAIL;
    162 #if defined(BCM_COLLECTOR_SUPPORT)
    163    /* Take lock */
    164     BCM_IF_ERROR_RETURN(bcm_esw_collector_lock(unit));
    165 
    166     if (soc_feature(unit, soc_feature_collector)) {
    167         result = _bcm_xgs5_collector_export_profile_get(unit,
    168                 export_profile,
    169                 export_profile_info);
    170     }
    171     /* Release lock */
    172     BCM_IF_ERROR_RETURN(bcm_esw_collector_unlock(unit));
    173 #endif /* BCM_COLLECTOR_SUPPORT */
    174     return result;
    175 }
    176 
    177 /*
    178  * Function:
    179  *      bcm_esw_collector_export_profile_ids_get_all
    180  * Purpose:
    181  *      Gets the list of all collector export profile Ids configured.
    182  * Parameters:
    183  *      unit                 - (IN)  BCM device number
    184  *      max_size             - (IN)  Size of the collector export profile IDs
    185  *      export_profile_ids_list - (OUT) List of collector export profile Ids configured
    186  *      list_size            - (OUT) NUmber of elements in the above list
    187  * Returns:
    188  *      BCM_E_XXX   - BCM error code.
    189  */
    190 int bcm_esw_collector_export_profile_ids_get_all(
    191                                      int unit,
    192                                      int max_size,
    193                                      int *export_profile_ids_list,
    194                                      int *list_size)
    195 {
    196     int result = BCM_E_UNAVAIL;
    197 #if defined(BCM_COLLECTOR_SUPPORT)
    198    /* Take lock */
    199     BCM_IF_ERROR_RETURN(bcm_esw_collector_lock(unit));
    200 
    201     if (soc_feature(unit, soc_feature_collector)) {
    202         result = _bcm_xgs5_collector_export_profile_ids_get_all(unit,
    203                 max_size,
    204                 export_profile_ids_list,
    205                 list_size);
    206     }
    207     /* Release lock */
    208     BCM_IF_ERROR_RETURN(bcm_esw_collector_unlock(unit));
    209 #endif /* BCM_COLLECTOR_SUPPORT */
    210     return result;
    211 }
    212 
    213 /*
    214  * Function:
    215  *      bcm_esw_collector_export_profile_destroy
    216  * Purpose:
    217  *      Destroys a collector export profile
    218  * Parameters:
    219  *      unit           - (IN)  BCM device number
    220  *      export_profile_id - (IN) Collector export profile Id
    221  * Returns:
    222  *      BCM_E_XXX   - BCM error code.
    223  */
    224 int bcm_esw_collector_export_profile_destroy(
    225         int unit,
    226         int export_profile_id)
    227 {
    228     int result = BCM_E_UNAVAIL;
    229 #if defined(BCM_COLLECTOR_SUPPORT)
    230    /* Take lock */
    231     BCM_IF_ERROR_RETURN(bcm_esw_collector_lock(unit));
    232 
    233     if (soc_feature(unit, soc_feature_collector)) {
    234         result = _bcm_xgs5_collector_export_profile_destroy(unit,
    235                 export_profile_id);
    236     }
    237     /* Release lock */
    238     BCM_IF_ERROR_RETURN(bcm_esw_collector_unlock(unit));
    239 #endif /* BCM_COLLECTOR_SUPPORT */
    240     return result;
    241 }
    242 
    243 /*
    244  * Function:
    245  *      bcm_esw_collector_create
    246  * Purpose:
    247  *      Creates a collector with given collector info.
    248  * Parameters:
    249  *      unit            - (IN)  BCM device number
    250  *      options         - (IN)  Collector create options
    251  *      id              - (INOUT)  Collector Id
    252  *      collector_info  - (IN)  Collector info
    253  * Returns:
    254  *      BCM_E_XXX   - BCM error code.
    255  */
    256 int bcm_esw_collector_create(
    257         int unit,
    258         uint32 options,
    259         bcm_collector_t *collector_id,
    260         bcm_collector_info_t *collector_info)
    261 {
    262     int result = BCM_E_UNAVAIL;
    263 #if defined(BCM_COLLECTOR_SUPPORT)
    264    /* Take lock */
    265     BCM_IF_ERROR_RETURN(bcm_esw_collector_lock(unit));
    266 
    267     if (soc_feature(unit, soc_feature_collector)) {
    268         result = _bcm_xgs5_collector_create(unit, options, collector_id,
    269                 collector_info);
    270     }
    271     /* Release lock */
    272     BCM_IF_ERROR_RETURN(bcm_esw_collector_unlock(unit));
    273 #endif /* BCM_COLLECTOR_SUPPORT */
    274 
    275     return result;
    276 }
    277 
    278 /*
    279  * Function:
    280  *      bcm_esw_collector_get
    281  * Purpose:
    282  *      Gets collector information
    283  * Parameters:
    284  *      unit            - (IN)  BCM device number
    285  *      collector_id    - (IN)  Collector Id
    286  *      collector_info  - (OUT) Collector info
    287  * Returns:
    288  *      BCM_E_XXX   - BCM error code.
    289  */
    290 int bcm_esw_collector_get(
    291         int unit,
    292         bcm_collector_t collector_id,
    293         bcm_collector_info_t *collector_info)
    294 {
    295     int result = BCM_E_UNAVAIL;
    296 #if defined(BCM_COLLECTOR_SUPPORT)
    297    /* Take lock */
    298     BCM_IF_ERROR_RETURN(bcm_esw_collector_lock(unit));
    299 
    300     if (soc_feature(unit, soc_feature_collector)) {
    301         result = _bcm_xgs5_collector_get(unit, collector_id,
    302                 collector_info);
    303     }
    304     /* Release lock */
    305     BCM_IF_ERROR_RETURN(bcm_esw_collector_unlock(unit));
    306 #endif /* BCM_COLLECTOR_SUPPORT */
    307 
    308     return result;
    309 }
    310 
    311 /*
    312  * Function:
    313  *      bcm_esw_collector_get_all
    314  * Purpose:
    315  *      Gets the list of all collector Ids configured.
    316  * Parameters:
    317  *      unit                 - (IN)  BCM device number
    318  *      max_size             - (IN)  Size of the collector list array
    319  *      collector_list       - (OUT) List of collector Ids configured
    320  *      list_size            - (OUT) NUmber of elements in the list
    321  * Returns:
    322  *      BCM_E_XXX   - BCM error code.
    323  */
    324 int bcm_esw_collector_get_all(
    325                                      int unit,
    326                                      int max_size,
    327                                      bcm_collector_t *collector_list,
    328                                      int *list_size)
    329 {
    330     int result = BCM_E_UNAVAIL;
    331 #if defined(BCM_COLLECTOR_SUPPORT)
    332    /* Take lock */
    333     BCM_IF_ERROR_RETURN(bcm_esw_collector_lock(unit));
    334 
    335     if (soc_feature(unit, soc_feature_collector)) {
    336         result = _bcm_xgs5_collector_ids_get_all(unit, max_size,
    337                 collector_list, list_size);
    338     }
    339     /* Release lock */
    340     BCM_IF_ERROR_RETURN(bcm_esw_collector_unlock(unit));
    341 #endif /* BCM_COLLECTOR_SUPPORT */
    342     return result;
    343 }
    344 
    345 /*
    346  * Function:
    347  *      bcm_esw_collector_destroy
    348  * Purpose:
    349  *      Destroys a collector
    350  * Parameters:
    351  *      unit           - (IN)  BCM device number
    352  *      collector_id   - (IN) Collector Id
    353  * Returns:
    354  *      BCM_E_XXX   - BCM error code.
    355  */
    356 int bcm_esw_collector_destroy(
    357         int unit,
    358         bcm_collector_t collector_id)
    359 {
    360     int result = BCM_E_UNAVAIL;
    361 #if defined(BCM_COLLECTOR_SUPPORT)
    362    /* Take lock */
    363     BCM_IF_ERROR_RETURN(bcm_esw_collector_lock(unit));
    364 
    365     if (soc_feature(unit, soc_feature_collector)) {
    366         result = _bcm_xgs5_collector_destroy(unit, collector_id);
    367     }
    368     /* Release lock */
    369     BCM_IF_ERROR_RETURN(bcm_esw_collector_unlock(unit));
    370 #endif /* BCM_COLLECTOR_SUPPORT */
    371 
    372     return result;
    373 }
    374 
    375 /*
    376  * Function:
    377  *     _bcm_esw_collector_export_profile_ref_count_update
    378  * Purpose:
    379  *     Increment/Decrement reference count for an export profile
    380  * Parameters:
    381  *     unit          - (IN) BCM device number
    382  *     id            - (IN) Export profile Id
    383  *     update        - (IN) Reference count update (+/-)
    384  * Returns:
    385  *     BCM_E_XXX
    386  */
    387 int
    388 _bcm_esw_collector_export_profile_ref_count_update(int unit, int id, int update)
    389 {
    390     int result = BCM_E_UNAVAIL;
    391 #if defined(BCM_COLLECTOR_SUPPORT)
    392    /* Take lock */
    393     BCM_IF_ERROR_RETURN(bcm_esw_collector_lock(unit));
    394 
    395     if (soc_feature(unit, soc_feature_collector)) {
    396         result = _bcm_xgs5_collector_export_profile_ref_count_update(unit, id,
    397                                                                     update);
    398     }
    399     /* Release lock */
    400     BCM_IF_ERROR_RETURN(bcm_esw_collector_unlock(unit));
    401 #endif /* BCM_COLLECTOR_SUPPORT */
    402 
    403     return result;
    404 }
    405 
    406 /*
    407  * Function:
    408  *     _bcm_esw_collector_ref_count_update
    409  * Purpose:
    410  *     Increment/Decrement reference count for a collector
    411  * Parameters:
    412  *     unit          - (IN) BCM device number
    413  *     id            - (IN) Collector Id
    414  *     update        - (IN) Reference count update (+/-)
    415  * Returns:
    416  *     BCM_E_XXX
    417  */
    418 int
    419 _bcm_esw_collector_ref_count_update(int unit, bcm_collector_t id, int update)
    420 {
    421     int result = BCM_E_UNAVAIL;
    422 #if defined(BCM_COLLECTOR_SUPPORT)
    423    /* Take lock */
    424     BCM_IF_ERROR_RETURN(bcm_esw_collector_lock(unit));
    425 
    426     if (soc_feature(unit, soc_feature_collector)) {
    427         result = _bcm_xgs5_collector_ref_count_update(unit, id, update);
    428     }
    429     /* Release lock */
    430     BCM_IF_ERROR_RETURN(bcm_esw_collector_unlock(unit));
    431 #endif /* BCM_COLLECTOR_SUPPORT */
    432 
    433     return result;
    434 }
    435 
    436 /*
    437  * Function:
    438  *     _bcm_esw_collector_ref_count_get
    439  * Purpose:
    440  *     Get reference count for a collector
    441  * Parameters:
    442  *     unit          - (IN) BCM device number
    443  *     id            - (IN) Collector Id
    444  * Returns:
    445  *     reference count value
    446  */
    447 int
    448 _bcm_esw_collector_ref_count_get(int unit, bcm_collector_t id)
    449 {
    450     int result = 0;
    451 #if defined(BCM_COLLECTOR_SUPPORT)
    452    /* Take lock */
    453     BCM_IF_ERROR_RETURN(bcm_esw_collector_lock(unit));
    454 
    455     if (soc_feature(unit, soc_feature_collector)) {
    456         result = _bcm_xgs5_collector_ref_count_get(unit, id);
    457     }
    458     /* Release lock */
    459     BCM_IF_ERROR_RETURN(bcm_esw_collector_unlock(unit));
    460 #endif /* BCM_COLLECTOR_SUPPORT */
    461 
    462     return result;
    463 }
    464 
    465 #if defined(BCM_COLLECTOR_SUPPORT)
    466 /*
    467  * Function:
    468  *     _bcm_esw_collector_user_update
    469  * Purpose:
    470  *     Add user for a collector. 
    471  *     Currently one user is expected per collector.
    472  * Parameters:
    473  *     unit          - (IN) BCM device number
    474  *     id            - (IN) Collector Id
    475  *     user          - (IN) The user type of calling app
    476  * Returns:
    477  *     BCM_E_XXX
    478  */
    479 int
    480 _bcm_esw_collector_user_update(int unit, bcm_collector_t id, _bcm_collector_export_app_t user)
    481 {
    482     int result = BCM_E_UNAVAIL;
    483    /* Take lock */
    484     BCM_IF_ERROR_RETURN(bcm_esw_collector_lock(unit));
    485 
    486     if (soc_feature(unit, soc_feature_collector)) {
    487         result = _bcm_xgs5_collector_user_update(unit, id, user);
    488     }
    489     /* Release lock */
    490     BCM_IF_ERROR_RETURN(bcm_esw_collector_unlock(unit));
    491 
    492     return result;
    493 }
    494 
    495 /*
    496  * Function:
    497  *     _bcm_esw_collector_check_user_is_other 
    498  * Purpose:
    499  *     Check if collector ID is used by other user.
    500  * Parameters:
    501  *     unit          - (IN) BCM device number
    502  *     id            - (IN) Collector Id
    503  *     my_user       - (IN) The user type of calling app
    504  * Returns:
    505  *     BCM_E_XXX
    506  */
    507 uint8
    508 _bcm_esw_collector_check_user_is_other(int unit, bcm_collector_t id, _bcm_collector_export_app_t my_user)
    509 {
    510     int result = BCM_E_UNAVAIL;
    511 
    512    /* Take lock */
    513     BCM_IF_ERROR_RETURN(bcm_esw_collector_lock(unit));
    514 
    515     if (soc_feature(unit, soc_feature_collector)) {
    516         result = _bcm_xgs5_collector_check_user_is_other(unit, id, my_user);
    517     }
    518     /* Release lock */
    519     BCM_IF_ERROR_RETURN(bcm_esw_collector_unlock(unit));
    520 
    521     return result;
    522 }
    523 
    524 #endif /* BCM_COLLECTOR_SUPPORT */
    525 
    526 /*
    527  * Function:
    528  *      bcm_collector_export_record_register
    529  * Purpose:
    530  *      Register callback routine for Local collector Flowtracker
    531  *      record export.
    532  * Parameters:
    533  *      unit - (IN) Unit number.
    534  *      collector_id - (IN) collector Software ID.
    535  *      callback_options - (IN) export callback options.
    536  *      callback_fn - (IN) <UNDEF>
    537  *      userdata - (IN) <UNDEF>
    538  * Returns:
    539  *      BCM_E_xxx
    540  * Notes:
    541  */
    542 int
    543 bcm_esw_collector_export_record_register(
    544     int unit,
    545     bcm_collector_t collector_id,
    546     bcm_collector_callback_options_t callback_options,
    547     bcm_collector_export_record_cb_f callback_fn,
    548     void *userdata)
    549 {
    550     int result = BCM_E_UNAVAIL;
    551 
    552 #if defined(BCM_COLLECTOR_SUPPORT)
    553    /* Take lock */
    554     BCM_IF_ERROR_RETURN(bcm_esw_collector_lock(unit));
    555 
    556     if (soc_feature(unit, soc_feature_collector)) {
    557         result = _bcm_xgs5_collector_export_record_register(unit, collector_id,
    558                 callback_options, callback_fn, userdata);
    559     }
    560     /* Release lock */
    561     BCM_IF_ERROR_RETURN(bcm_esw_collector_unlock(unit));
    562 #endif /* BCM_COLLECTOR_SUPPORT */
    563 
    564     return result;
    565 }
    566 
    567 /*
    568  * Function:
    569  *      bcm_collector_export_record_unregister
    570  * Purpose:
    571  *      Unregister callback routine for Local collector
    572  *      record export.
    573  * Parameters:
    574  *      unit - (IN) Unit number.
    575  *      collector_id - (IN) collector Software ID.
    576  *      callback_options - (IN) export callback options.
    577  *      callback_fn - (IN) <UNDEF>
    578  * Returns:
    579  *      BCM_E_xxx
    580  * Notes:
    581  */
    582 int
    583 bcm_esw_collector_export_record_unregister(
    584     int unit,
    585     bcm_collector_t collector_id,
    586     bcm_collector_callback_options_t callback_options,
    587     bcm_collector_export_record_cb_f callback_fn)
    588 {
    589     int result = BCM_E_UNAVAIL;
    590 
    591 #if defined(BCM_COLLECTOR_SUPPORT)
    592    /* Take lock */
    593     BCM_IF_ERROR_RETURN(bcm_esw_collector_lock(unit));
    594 
    595     if (soc_feature(unit, soc_feature_collector)) {
    596         result = _bcm_xgs5_collector_export_record_unregister(unit, collector_id,
    597                 callback_options, callback_fn);
    598     }
    599     /* Release lock */
    600     BCM_IF_ERROR_RETURN(bcm_esw_collector_unlock(unit));
    601 #endif /* BCM_COLLECTOR_SUPPORT */
    602 
    603     return result;
    604 }
    605 
    606 
    607 /*
    608  * Function:
    609  *      _bcm_esw_collector_sw_dump
    610  * Purpose:
    611  *      Dumps collector module information
    612  * Parameters:
    613  *      unit           - (IN)  BCM device number
    614  * Returns: void
    615  */
    616 void _bcm_esw_collector_sw_dump(int unit)
    617 {
    618 #if defined(BCM_COLLECTOR_SUPPORT)
    619 
    620     if (soc_feature(unit, soc_feature_collector)) {
    621         _bcm_xgs5_collector_sw_dump(unit);
    622     }
    623 #endif /* BCM_COLLECTOR_SUPPORT */
    624 
    625 }
    626 
    627 #ifdef BCM_WARM_BOOT_SUPPORT
    628 /*
    629  * Function:
    630  *      _bcm_esw_collector_sync
    631  * Purpose:
    632  *      Warmboot scache sync
    633  * Parameters:
    634  *      unit - (IN) Unit number.
    635  * Returns:
    636  *      BCM_E_XXX
    637  * Notes:
    638  */
    639 int _bcm_esw_collector_sync(int unit)
    640 {
    641     int result = BCM_E_UNAVAIL;
    642  #if defined(BCM_COLLECTOR_SUPPORT)
    643    /* Take lock */
    644     BCM_IF_ERROR_RETURN(bcm_esw_collector_lock(unit));
    645 
    646     if (soc_feature(unit, soc_feature_collector)) {
    647         result = _bcm_xgs5_collector_sync(unit);
    648     }
    649     /* Release lock */
    650     BCM_IF_ERROR_RETURN(bcm_esw_collector_unlock(unit));
    651 #endif /* BCM_COLLECTOR_SUPPORT */
    652    
    653     return result;
    654 }
    655 #endif /* BCM_WARM_BOOT_SUPPORT */
    656