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

ifa.c (8679B)


      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  * IFA - In-band Flow Analyzer Monitoring Embedded Application APP interface
      8  * Purpose: API to configure IFA embedded app interface.
      9  */
     10 
     11 #include <shared/bslenum.h>
     12 #include <shared/bsl.h>
     13 #include <soc/defs.h>
     14 #include <soc/drv.h>
     15 #include <bcm/error.h>
     16 #include <bcm/ifa.h>
     17 
     18 #include <bcm_int/esw/xgs5.h>
     19 #include <bcm_int/esw/tomahawk.h>
     20 #include <bcm_int/esw/trident3.h>
     21 
     22 static sal_mutex_t mutex[BCM_MAX_NUM_UNITS];
     23 
     24 int bcm_esw_ifa_lock(int unit)
     25 {
     26     if (mutex[unit] == NULL) {
     27         return BCM_E_INIT;
     28     }
     29 
     30     sal_mutex_take(mutex[unit], sal_mutex_FOREVER);
     31     return BCM_E_NONE;
     32 }
     33 
     34 int bcm_esw_ifa_unlock(int unit)
     35 {
     36     if (mutex[unit] == NULL) {
     37         return BCM_E_INIT;
     38     }
     39 
     40     if (sal_mutex_give(mutex[unit]) != 0) {
     41         return BCM_E_INTERNAL;
     42     }
     43     return BCM_E_NONE;
     44 }
     45 
     46 /* Initialize the IFA app. */
     47 int bcm_esw_ifa_init(int unit)
     48 {
     49     int result = BCM_E_UNAVAIL;
     50 #if defined(INCLUDE_IFA)
     51     /* Create mutex */
     52     if (mutex[unit] == NULL) {
     53         mutex[unit] = sal_mutex_create("ifa.mutex");
     54         if (mutex[unit] == NULL) {
     55             return BCM_E_MEMORY;
     56         }
     57     }
     58 
     59 #if defined(BCM_TRIDENT3_SUPPORT) || defined(BCM_MAVERICK2_SUPPORT)
     60     if ((SOC_IS_TRIDENT3(unit)) || (SOC_IS_MAVERICK2(unit))) {
     61         result = _bcm_td3_ifa_init(unit);
     62     }
     63 #endif  /* BCM_TRIDENT3_SUPPORT and BCM_MAVERICK2_SUPPORT */
     64 
     65     /* If init itself fails, there is no point in having the mutex.
     66      * Destroy it.
     67      */
     68     if (BCM_FAILURE(result)) {
     69         sal_mutex_destroy(mutex[unit]);
     70         mutex[unit] = NULL;
     71     }
     72 #endif  /* INCLUDE_IFA */
     73     return result;
     74 }
     75 
     76 /* Shut down the IFA app. */
     77 int bcm_esw_ifa_detach(int unit)
     78 {
     79     int result = BCM_E_UNAVAIL;
     80 #if defined(INCLUDE_IFA)
     81     /* Take lock */
     82     BCM_IF_ERROR_RETURN(bcm_esw_ifa_lock(unit));
     83 
     84 #if defined(BCM_TRIDENT3_SUPPORT) || defined(BCM_MAVERICK2_SUPPORT)
     85     if ((SOC_IS_TRIDENT3(unit)) || (SOC_IS_MAVERICK2(unit))) {
     86         result = _bcm_td3_ifa_detach(unit);
     87     }
     88 #endif  /* BCM_TRIDENT3_SUPPORT and BCM_MAVERICK2_SUPPORT */
     89 
     90     /* Release lock */
     91     BCM_IF_ERROR_RETURN(bcm_esw_ifa_unlock(unit));
     92 #endif  /* INCLUDE_IFA */
     93     return result;
     94 }
     95 
     96 /*
     97  * Function:
     98  *      bcm_esw_ifa_collector_set
     99  * Purpose:
    100  *      Create a ifa collector with given collector info.
    101  * Parameters:
    102  *      unit            - (IN)  BCM device number
    103  *      options         - (IN)  Collector create options
    104  *      collector_info  - (IN)  Collector info
    105  * Returns:
    106  *      BCM_E_XXX   - BCM error code.
    107  */
    108 
    109 int bcm_esw_ifa_collector_set(int unit,
    110         uint32 options,
    111         bcm_ifa_collector_info_t *collector_info)
    112 {
    113     int result = BCM_E_UNAVAIL;
    114 #if defined(INCLUDE_IFA)
    115     /* Take lock */
    116     BCM_IF_ERROR_RETURN(bcm_esw_ifa_lock(unit));
    117 
    118     /* IFA app APIs.  */
    119     if (soc_feature(unit, soc_feature_ifa)) {
    120 #if defined(BCM_TRIDENT3_SUPPORT) || defined(BCM_MAVERICK2_SUPPORT)
    121         if ((SOC_IS_TRIDENT3(unit)) || (SOC_IS_MAVERICK2(unit))) {
    122             result = _bcm_td3_ifa_collector_set(unit, options,
    123                     collector_info);
    124         }
    125 #endif  /* BCM_TRIDENT3_SUPPORT and BCM_MAVERICK2_SUPPORT */
    126     }
    127 
    128     /* Release lock */
    129     BCM_IF_ERROR_RETURN(bcm_esw_ifa_unlock(unit));
    130 #endif  /* INCLUDE_IFA */
    131     return result;
    132 }
    133 
    134 /*
    135  * Function:
    136  *      bcm_esw_ifa_collector_get
    137  * Purpose:
    138  *      Get ifa collector information
    139  * Parameters:
    140  *      unit            - (IN)  BCM device number
    141  *      collector_info  - (OUT) Collector info
    142  * Returns:
    143  *      BCM_E_XXX   - BCM error code.
    144  */
    145 
    146 int bcm_esw_ifa_collector_get(int unit,
    147         bcm_ifa_collector_info_t *collector_info)
    148 {
    149     int result = BCM_E_UNAVAIL;
    150 #if defined(INCLUDE_IFA)
    151     /* Take lock */
    152     BCM_IF_ERROR_RETURN(bcm_esw_ifa_lock(unit));
    153 
    154     /* IFA app APIs.  */
    155     if (soc_feature(unit, soc_feature_ifa)) {
    156 #if defined(BCM_TRIDENT3_SUPPORT) || defined(BCM_MAVERICK2_SUPPORT)
    157         if ((SOC_IS_TRIDENT3(unit)) || (SOC_IS_MAVERICK2(unit))) {
    158             result = _bcm_td3_ifa_collector_get(unit,
    159                     collector_info);
    160         }
    161 #endif  /* BCM_TRIDENT3_SUPPORT and BCM_MAVERICK2_SUPPORT */
    162     }
    163 
    164     /* Release lock */
    165     BCM_IF_ERROR_RETURN(bcm_esw_ifa_unlock(unit));
    166 #endif  /* INCLUDE_IFA */
    167     return result;
    168 }
    169 
    170 int bcm_esw_ifa_config_info_set(int unit,
    171         uint32 options,
    172         bcm_ifa_config_info_t *config_data)
    173 {
    174     int result = BCM_E_UNAVAIL;
    175 #if defined(INCLUDE_IFA)
    176     /* Take lock */
    177     BCM_IF_ERROR_RETURN(bcm_esw_ifa_lock(unit));
    178 
    179     /* IFA app APIs.  */
    180     if (soc_feature(unit, soc_feature_ifa)) {
    181 #if defined(BCM_TRIDENT3_SUPPORT) || defined(BCM_MAVERICK2_SUPPORT)
    182         if ((SOC_IS_TRIDENT3(unit)) || (SOC_IS_MAVERICK2(unit))) {
    183             result = _bcm_td3_ifa_config_set(unit, options,
    184                     config_data);
    185         }
    186 #endif  /* BCM_TRIDENT3_SUPPORT and BCM_MAVERICK2_SUPPORT */
    187     }
    188 
    189     /* Release lock */
    190     BCM_IF_ERROR_RETURN(bcm_esw_ifa_unlock(unit));
    191 #endif  /* INCLUDE_IFA */
    192     return result;
    193 }
    194 
    195 int bcm_esw_ifa_config_info_get(int unit,
    196         bcm_ifa_config_info_t *config_data)
    197 {
    198     int result = BCM_E_UNAVAIL;
    199 #if defined(INCLUDE_IFA)
    200     /* Take lock */
    201     BCM_IF_ERROR_RETURN(bcm_esw_ifa_lock(unit));
    202 
    203     /* IFA app APIs.  */
    204     if (soc_feature(unit, soc_feature_ifa)) {
    205 #if defined(BCM_TRIDENT3_SUPPORT) || defined(BCM_MAVERICK2_SUPPORT)
    206         if ((SOC_IS_TRIDENT3(unit)) || (SOC_IS_MAVERICK2(unit))) {
    207             result = _bcm_td3_ifa_config_get(unit,
    208                     config_data);
    209         }
    210 #endif  /* BCM_TRIDENT3_SUPPORT and BCM_MAVERICK2_SUPPORT */
    211     }
    212 
    213     /* Release lock */
    214     BCM_IF_ERROR_RETURN(bcm_esw_ifa_unlock(unit));
    215 #endif  /* INCLUDE_IFA */
    216     return result;
    217 }
    218 
    219 /*
    220  * Function:
    221  *      bcm_esw_ifa_stat_info_get
    222  * Purpose:
    223  *      Get ifa statistics information data
    224  * Parameters:
    225  *      unit            - (IN)  BCM device number
    226  *      stat_data       - (OUT) Statistics information data
    227  * Returns:
    228  *      BCM_E_XXX   - BCM error code.
    229  */
    230 int bcm_esw_ifa_stat_info_get(int unit,
    231         bcm_ifa_stat_info_t *stat_data)
    232 {
    233     int result = BCM_E_UNAVAIL;
    234 #if defined(INCLUDE_IFA)
    235     /* Take lock */
    236     BCM_IF_ERROR_RETURN(bcm_esw_ifa_lock(unit));
    237 
    238     /* IFA app APIs.  */
    239     if (soc_feature(unit, soc_feature_ifa)) {
    240 #if defined(BCM_TRIDENT3_SUPPORT) || defined(BCM_MAVERICK2_SUPPORT)
    241         if ((SOC_IS_TRIDENT3(unit)) || (SOC_IS_MAVERICK2(unit))) {
    242             result = _bcm_td3_ifa_stat_get(unit,
    243                     stat_data);
    244         }
    245 #endif  /* BCM_TRIDENT3_SUPPORT and BCM_MAVERICK2_SUPPORT */
    246     }
    247 
    248     /* Release lock */
    249     BCM_IF_ERROR_RETURN(bcm_esw_ifa_unlock(unit));
    250 #endif  /* INCLUDE_IFA */
    251     return result;
    252 }
    253 
    254 /*
    255  * Function:
    256  *      bcm_esw_ifa_stat_info_set
    257  * Purpose:
    258  *      Get ifa statistics information data
    259  * Parameters:
    260  *      unit            - (IN)  BCM device number
    261  *      stat_data       - (OUT) Statistics information data
    262  * Returns:
    263  *      BCM_E_XXX   - BCM error code.
    264  */
    265 int bcm_esw_ifa_stat_info_set(int unit,
    266         bcm_ifa_stat_info_t *stat_data)
    267 {
    268     int result = BCM_E_UNAVAIL;
    269 #if defined(INCLUDE_IFA)
    270     /* Take lock */
    271     BCM_IF_ERROR_RETURN(bcm_esw_ifa_lock(unit));
    272 
    273     /* IFA app APIs.  */
    274     if (soc_feature(unit, soc_feature_ifa)) {
    275 #if defined(BCM_TRIDENT3_SUPPORT) || defined(BCM_MAVERICK2_SUPPORT)
    276         if ((SOC_IS_TRIDENT3(unit)) || (SOC_IS_MAVERICK2(unit))) {
    277             result = _bcm_td3_ifa_stat_set(unit,
    278                     stat_data);
    279         }
    280 #endif  /* BCM_TRIDENT3_SUPPORT and BCM_MAVERICK2_SUPPORT */
    281     }
    282 
    283     /* Release lock */
    284     BCM_IF_ERROR_RETURN(bcm_esw_ifa_unlock(unit));
    285 #endif  /* INCLUDE_IFA */
    286     return result;
    287 }
    288 
    289 #ifdef BCM_WARM_BOOT_SUPPORT
    290 /*
    291  * Function:
    292  *      _bcm_esw_ifa_sync
    293  * Purpose:
    294  *      Warmboot scache sync
    295  * Parameters:
    296  *      unit - (IN) Unit number.
    297  * Returns:
    298  *      BCM_E_XXX
    299  * Notes:
    300  */
    301 int _bcm_esw_ifa_sync(int unit)
    302 {
    303     int result = BCM_E_UNAVAIL;
    304 #if defined(INCLUDE_IFA)
    305     /* Take lock */
    306     BCM_IF_ERROR_RETURN(bcm_esw_ifa_lock(unit));
    307 
    308     if (soc_feature(unit, soc_feature_ifa)) {
    309 #if defined(BCM_TRIDENT3_SUPPORT) || defined(BCM_MAVERICK2_SUPPORT)
    310         if ((SOC_IS_TRIDENT3(unit)) || (SOC_IS_MAVERICK2(unit))) {
    311             result = _bcm_td3_ifa_sync(unit);
    312         }
    313 #endif  /* BCM_TRIDENT3_SUPPORT and BCM_MAVERICK2_SUPPORT */
    314     }
    315 
    316     /* Release lock */
    317     BCM_IF_ERROR_RETURN(bcm_esw_ifa_unlock(unit));
    318 #endif /* INCLUDE_IFA */
    319     return result;
    320 }
    321 #endif /* BCM_WARM_BOOT_SUPPORT */