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

switch.c (9179B)


      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  * File:       switch.c
      8  * Purpose:    Switch common APIs
      9  */
     10 
     11 #include <soc/drv.h>
     12 #include <bcm/switch.h>
     13 #include <bcm/init.h>
     14 #include <bcm/error.h>
     15 #include <bcm_int/common/debug.h>
     16 #include <appl/diag/shell.h>
     17 #include <bcm_int/control.h>
     18 
     19 #if defined(BCM_PETRA_SUPPORT) && defined(CRASH_RECOVERY_SUPPORT)
     20 #include <soc/dcmn/dcmn_crash_recovery.h>
     21 #endif
     22 
     23 #if (defined(BCM_DPP_SUPPORT) || defined(BCM_PETRA_SUPPORT) || defined(BCM_DFE_SUPPORT))
     24 #define SOC_SYNC_WHEN_NOT_DIRTY ((SOC_IS_DPP(unit) || SOC_IS_DFE(unit)) ? 1 : 0)
     25 #else
     26 #define SOC_SYNC_WHEN_NOT_DIRTY 0
     27 #endif
     28 
     29 /*
     30  * Function:
     31  *     bcm_switch_pkt_info_t_init
     32  * Description:
     33  *     Initialize an switch packet parameter strucutre
     34  * Parameters:
     35  *     pkt_info - pointer to switch packet parameter strucutre
     36  * Return: none
     37  */
     38 void
     39 bcm_switch_pkt_info_t_init(bcm_switch_pkt_info_t *pkt_info)
     40 {
     41     sal_memset(pkt_info, 0, sizeof(bcm_switch_pkt_info_t));
     42 }
     43 
     44 /*
     45  * Function:
     46  *     bcm_switch_network_group_config_t_init
     47  * Description:
     48  *     Initialize a bcm_switch_network_group_config_t structure.
     49  * Parameters:
     50  *     config - pointer to switch network group config parameter strucutre
     51  * Return: none
     52  */
     53 extern void bcm_switch_network_group_config_t_init(
     54     bcm_switch_network_group_config_t *config)
     55 {
     56     sal_memset(config, 0, sizeof(bcm_switch_network_group_config_t));
     57 }
     58 
     59 /*
     60  * Function:
     61  *     bcm_switch_service_config_t_init
     62  * Description:
     63  *     Initialize a bcm_switch_service_config_t structure.
     64  * Parameters:
     65  *     config - pointer to service config parameter strucutre
     66  * Return: none
     67  */
     68 extern void bcm_switch_service_config_t_init(
     69     bcm_switch_service_config_t *config)
     70 {
     71     sal_memset(config, 0, sizeof(bcm_switch_service_config_t));
     72 }
     73 
     74 void bcm_switch_profile_mapping_t_init(bcm_switch_profile_mapping_t *profile_mapping)
     75 {
     76     if (profile_mapping != NULL) {
     77         sal_memset(profile_mapping, 0, sizeof(bcm_switch_profile_mapping_t));
     78     }
     79 }
     80 
     81 /*
     82  * Function:
     83  *     bcm_switch_hash_entry_config_t_init
     84  * Description:
     85  *     Initialize a bcm_switch_reflector_data_t structure.
     86  * Parameters:
     87  *     data - pointer to data parameter structure
     88  * Return: none
     89  */
     90 
     91 void
     92 bcm_switch_reflector_data_t_init(bcm_switch_reflector_data_t *data)
     93 {
     94     if (data != NULL) {
     95         sal_memset(data, 0, sizeof(bcm_switch_reflector_data_t));
     96     }
     97 }
     98 
     99 /*
    100  * Function:
    101  *     bcm_switch_hash_entry_config_t_init
    102  * Description:
    103  *     Initialize a bcm_switch_hash_entry_config_t structure.
    104  * Parameters:
    105  *     config - pointer to flex hash config parameter strucutre
    106  * Return: none
    107  */
    108 
    109 void
    110 bcm_switch_hash_entry_config_t_init(bcm_switch_hash_entry_config_t *config)
    111 {
    112     if (config != NULL) {
    113         sal_memset(config, 0, sizeof(bcm_switch_hash_entry_config_t));
    114     }
    115 }
    116 
    117 /* Initialize the structure bcm_switch_olp_l2_addr_t to default values */
    118 void bcm_switch_olp_l2_addr_t_init(
    119     bcm_switch_olp_l2_addr_t *l2_addr)
    120 {
    121     if (l2_addr != NULL) {
    122         sal_memset(l2_addr, 0, sizeof(bcm_switch_olp_l2_addr_t));
    123     }
    124 }    
    125 
    126 /*
    127  * Function:
    128  *     bcm_switch_agm_info_t_init
    129  * Description:
    130  *     Initialize an switch agm info parameter strucutre
    131  * Parameters:
    132  *     agm_info - pointer to switch agm info parameter strucutre
    133  * Return: none
    134  */
    135 void
    136 bcm_switch_agm_info_t_init(bcm_switch_agm_info_t *agm_info)
    137 {
    138     sal_memset(agm_info, 0, sizeof(bcm_switch_agm_info_t));
    139 }
    140 
    141 /*
    142  * Function:
    143  *     bcm_switch_agm_stat_t_init
    144  * Description:
    145  *     Initialize an switch agm stat parameter strucutre
    146  * Parameters:
    147  *     agm_info - pointer to switch agm stat parameter strucutre
    148  * Return: none
    149  */
    150 void
    151 bcm_switch_agm_stat_t_init(bcm_switch_agm_stat_t *agm_stat)
    152 {
    153     sal_memset(agm_stat, 0, sizeof(bcm_switch_agm_stat_t));
    154 }
    155 
    156 /*
    157  * Function:
    158  *     bcm_switch_match_config_info_t_init
    159  * Description:
    160  *     Initialize a bcm_switch_match_config_info_t structure.
    161  * Parameters:
    162  *     config_info - pointer to match config parameter strucutre
    163  * Return: none
    164  */
    165 void bcm_switch_match_config_info_t_init(
    166     bcm_switch_match_config_info_t *config_info)
    167 {
    168     if (config_info != NULL) {
    169         sal_memset(config_info, 0, sizeof(bcm_switch_match_config_info_t));
    170     }
    171 }
    172 
    173 /*
    174  * Function:
    175  *     bcm_switch_match_control_info_t_init
    176  * Description:
    177  *     Initialize a bcm_switch_match_control_info_t structure.
    178  * Parameters:
    179  *     control_info - pointer to match control parameter strucutre
    180  * Return: none
    181  */
    182 void bcm_switch_match_control_info_t_init(
    183     bcm_switch_match_control_info_t *control_info)
    184 {
    185     if (control_info != NULL) {
    186         sal_memset(control_info, 0, sizeof(bcm_switch_match_control_info_t));
    187     }
    188 }
    189 
    190 /*
    191  * Function:
    192  *     bcm_switch_encap_info_t_init
    193  * Description:
    194  *     Initialize a bcm_switch_encap_info_t structure.
    195  * Parameters:
    196  *     encap_info - pointer to switch encap parameter strucutre
    197  * Return: none
    198  */
    199 void
    200 bcm_switch_encap_info_t_init(bcm_switch_encap_info_t *encap_info)
    201 {
    202     if (encap_info != NULL) {
    203         sal_memset(encap_info, 0, sizeof(bcm_switch_encap_info_t));
    204     }
    205 }
    206 
    207 
    208 /*
    209  * Function:
    210  *     bcm_switch_tpid_class_t_init
    211  * Description:
    212  *     Initialize a bcm_switch_tpid_class_t structure.
    213  * Parameters:
    214  *     tpid_class - pointer to tpid class parameter strucutre
    215  * Return: none
    216  */
    217 void
    218 bcm_switch_tpid_class_t_init(bcm_switch_tpid_class_t *tpid_class)
    219 {
    220     if (tpid_class != NULL) {
    221         sal_memset(tpid_class, 0, sizeof(bcm_switch_tpid_class_t));
    222     }
    223 }
    224 
    225 /*
    226  * Function:
    227  *     bcm_switch_ser_log_info_t_init
    228  * Description:
    229  *     Initialize a bcm_switch_ser_log_info_t structure.
    230  * Parameters:
    231  *     info - pointer to ser log info parameter strucutre
    232  * Return: none
    233  */
    234 void
    235 bcm_switch_ser_log_info_t_init(bcm_switch_ser_log_info_t *info)
    236 {
    237     if (info != NULL) {
    238         sal_memset(info, 0, sizeof(bcm_switch_ser_log_info_t));
    239     }
    240 }
    241 
    242 /*
    243  * Function:
    244  *     bcm_switch_ser_error_stat_type_t_init
    245  * Description:
    246  *     Initialize a bcm_switch_ser_error_stat_type_t_init structure.
    247  * Parameters:
    248  *     stat_type - pointer to ser statistics type parameter strucutre
    249  * Return: none
    250  */
    251 void
    252 bcm_switch_ser_error_stat_type_t_init(bcm_switch_ser_error_stat_type_t *stat_type)
    253 {
    254     if (stat_type != NULL) {
    255         sal_memset(stat_type, 0, sizeof(bcm_switch_ser_error_stat_type_t));
    256     }
    257 }
    258 
    259 /*
    260  * Function:
    261  *     bcm_switch_opaque_tag_config_t_init
    262  * Description:
    263  *     Initialize a bcm_switch_opaque_tag_params_t structure
    264  * Parameters:
    265  *     info - pointer to opaque tag parameters structure
    266  * Return: none
    267  */
    268 void
    269 bcm_switch_opaque_tag_config_t_init(bcm_switch_opaque_tag_params_t *info)
    270 {
    271     if (info != NULL) {
    272         sal_memset(info, 0, sizeof(bcm_switch_opaque_tag_params_t));
    273     }
    274 }
    275 
    276 #ifdef BCM_WARM_BOOT_SUPPORT
    277 
    278 /* Externs for bcm_<arch>_switch_control_get functions */
    279 #define BCM_DLIST_ENTRY(_dtype) \
    280 extern int bcm_##_dtype##_switch_control_set( \
    281     int unit, bcm_switch_control_t type, int arg);
    282 #include <bcm_int/bcm_dlist.h>
    283 
    284 /* Dispatch table for this function, which uses the externs above */
    285 #define BCM_DLIST_ENTRY(_dtype)\
    286 bcm_##_dtype##_switch_control_set,
    287 static int (*_switch_control_set_disp[])(
    288     int unit, 
    289     bcm_switch_control_t type, 
    290     int arg) =
    291 {
    292 #include <bcm_int/bcm_dlist.h>
    293 0
    294 };
    295 
    296 /* Externs for bcm_<arch>_switch_control_get functions */
    297 #define BCM_DLIST_ENTRY(_dtype) \
    298 extern int bcm_##_dtype##_switch_control_get( \
    299     int unit, bcm_switch_control_t type, int *arg);
    300 #include <bcm_int/bcm_dlist.h>
    301 
    302 /* Dispatch table for this function, which uses the externs above */
    303 #define BCM_DLIST_ENTRY(_dtype)\
    304 bcm_##_dtype##_switch_control_get,
    305 static int (*_switch_control_get_disp[])(
    306     int unit, 
    307     bcm_switch_control_t type, 
    308     int *arg) =
    309 {
    310 #include <bcm_int/bcm_dlist.h>
    311 0
    312 };
    313 
    314 
    315 /**
    316  * Function:
    317  *      _bcm_switch_state_sync
    318  * Purpose:
    319  *      Sync warm boot cache if necessary
    320  * Parameters:
    321  *      unit - (IN) Unit number.
    322  *      dtype - (IN) Dispatch index
    323  * Returns:
    324  *      BCM_E_xxx
    325  * Notes:
    326  */
    327 
    328 int
    329 _bcm_switch_state_sync(int unit, bcm_dtype_t dtype)
    330 {
    331     int rv = BCM_E_UNIT;
    332     int arg = 0;
    333 
    334     if (SOC_UNIT_VALID(unit)) {
    335         rv = _switch_control_get_disp[dtype](unit,
    336                                              bcmSwitchControlAutoSync, &arg);
    337         if (BCM_SUCCESS(rv) && (arg != 0)) {
    338             if (SOC_CONTROL(unit)->scache_dirty || SOC_SYNC_WHEN_NOT_DIRTY) {
    339                 rv = _switch_control_set_disp[dtype](unit,
    340                                                      bcmSwitchControlSync, 1);
    341             }
    342         }
    343     }
    344 
    345     return rv;
    346 }
    347 
    348 #endif /* BCM_WARM_BOOT_SUPPORT */
    349 
    350 /*
    351  * Function:
    352  *      bcm_switch_obm_classifier_t_init
    353  * Purpose:
    354  *      Initialize the OBM  classifier struct
    355  * Parameters:
    356  *      switch_classifier - Pointer to the struct to be init'ed
    357  */
    358 
    359 void
    360 bcm_switch_obm_classifier_t_init(bcm_switch_obm_classifier_t *switch_classifier)
    361 {
    362     if (switch_classifier != NULL) {
    363         sal_memset(switch_classifier, 0, sizeof(*switch_classifier));
    364     }
    365 }