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

l2.c (6462B)


      1 
      2 /*
      3  * 
      4  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      5  * 
      6  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      7  *
      8  * L2 - Broadcom StrataSwitch Layer-2 switch common API.
      9  */
     10 
     11 #include <soc/drv.h> 
     12 #include <bcm/l2.h>
     13 #include <bcm/tsn.h>
     14 #include <shared/bsl.h>
     15 char *bcm_l2_flags_str[] = BCM_L2_FLAGS_STR;
     16 int bcm_l2_flags_count = sizeof(bcm_l2_flags_str)/sizeof(bcm_l2_flags_str[0]);
     17  /*
     18  * Function:
     19  *	bcm_esw_l2_addr_dump
     20  * Purpose:
     21  *	Dump a hardware-independent L2 address for debugging
     22  * Parameters:
     23  *	l2e - L2 address to dump
     24  */
     25 
     26 void
     27 bcm_l2_addr_dump(bcm_l2_addr_t *l2e)
     28 {
     29     LOG_CLI((BSL_META("MAC_ADDR=%02x:%02x:%02x:%02x:%02x:%02x, "),
     30 l2e->mac[0],l2e->mac[1],l2e->mac[2],
     31              l2e->mac[3],l2e->mac[4],l2e->mac[5]));
     32     LOG_CLI((BSL_META("VLAN_TAG=0x%x, PORT=%d, TGID=%d ENCAP=0x%x,\n"),
     33 l2e->vid, l2e->port, l2e->tgid, l2e->encap_id));
     34     LOG_CLI((BSL_META("    MODID=%d, L2MC_IDX=%d,"),
     35 l2e->modid, l2e->l2mc_group));
     36     LOG_CLI((BSL_META(" COS_DST=%d, COS_SRC=%d, \n    FLAGS=0x%08x\n"),
     37 l2e->cos_dst, l2e->cos_src, l2e->flags));
     38 
     39 }
     40 
     41 
     42 /*
     43  * Function:
     44  *	bcm_l2_addr_t_init
     45  * Description:
     46  *	Initialize a bcm_l2_addr_t to a specified MAC address and VLAN,
     47  *	while zeroing all other fields.
     48  * Parameters:
     49  *	l2addr - Pointer to bcm_l2_addr_t
     50  * Returns:
     51  *	Nothing.
     52  */
     53 
     54 void
     55 bcm_l2_addr_t_init(bcm_l2_addr_t *l2addr, const sal_mac_addr_t mac, bcm_vlan_t vid)
     56 {
     57     if (NULL != l2addr) {
     58         sal_memset(l2addr, 0, sizeof (*l2addr));
     59         sal_memcpy(l2addr->mac, mac, sizeof (sal_mac_addr_t));
     60         l2addr->vid = vid;
     61         l2addr->encap_id = BCM_FORWARD_ENCAP_ID_INVALID;
     62         l2addr->taf_gate_primap = BCM_TSN_PRI_MAP_INVALID;
     63     }
     64     return;
     65 }
     66 
     67 
     68 void
     69 bcm_l2_auth_addr_t_init(bcm_l2_auth_addr_t *addr)
     70 {
     71     if (NULL != addr) {
     72         sal_memset(addr, 0, sizeof (*addr));
     73     }
     74     return;
     75 }
     76 
     77 
     78 
     79 /*
     80  * Function:
     81  *      bcm_l2_cache_addr_init
     82  * Purpose:
     83  *      Intitialize an L2 cache address structure
     84  * Parameters:
     85  *      addr - (OUT) l2 cache address to initialize
     86  * Returns:
     87  *      nothing
     88  * Notes:
     89  *      All masks in the structure are cleared.
     90  */
     91 void
     92 bcm_l2_cache_addr_t_init(bcm_l2_cache_addr_t *addr)
     93 {
     94     if (NULL != addr) {
     95         sal_memset(addr, 0, sizeof (*addr));
     96     }
     97     return;
     98 }
     99 
    100 /*
    101  * Function:
    102  *     bcm_l2_learn_limit_t_init
    103  * Description:
    104  *     Initialize an L2 learn limit structure
    105  * Parameters:
    106  *     limit       pointer to learn limit control info
    107  * Return: none
    108  */
    109 void
    110 bcm_l2_learn_limit_t_init(bcm_l2_learn_limit_t *limit)
    111 {
    112     if (NULL != limit) {
    113         sal_memset(limit, 0, sizeof(bcm_l2_learn_limit_t));
    114     }
    115     return;
    116 }
    117 
    118 /*
    119  * Function:
    120  *     bcm_l2_learn_msgs_config_t_init
    121  * Description:
    122  *     Initialize an L2 learn message structure
    123  * Parameters:
    124  *     learn_msg_config       pointer to learn message info
    125  * Return: none
    126  */
    127 void
    128 bcm_l2_learn_msgs_config_t_init(bcm_l2_learn_msgs_config_t *learn_msg_config)
    129 {
    130     if (NULL != learn_msg_config) {
    131         sal_memset(learn_msg_config, 0, sizeof(bcm_l2_learn_msgs_config_t));
    132         learn_msg_config->vlan = BCM_VLAN_INVALID;
    133     }
    134     return;
    135 }
    136 
    137 
    138 /*
    139  * Function:
    140  *     bcm_l2_addr_distribute_t_init
    141  * Description:
    142  *     Initialize an L2 learn distribution structure
    143  * Parameters:
    144  *     distribution       pointer to learn distribution info
    145  * Return: none
    146  */
    147 void
    148 bcm_l2_addr_distribute_t_init(bcm_l2_addr_distribute_t *distribution)
    149 {
    150     if (NULL != distribution) {
    151         sal_memset(distribution, 0, sizeof(bcm_l2_addr_distribute_t));
    152     }
    153     return;
    154 }
    155 
    156 
    157 /*
    158  * Function:
    159  *      bcm_l2_egress_addr_t_init
    160  * Purpose:
    161  *      Intitialize an L2 egress structure
    162  * Parameters:
    163  *      addr - (OUT) l2 egress to initialize
    164  * Returns:
    165  *      nothing
    166  */
    167 void
    168 bcm_l2_egress_t_init(bcm_l2_egress_t *addr)
    169 {
    170     if (NULL != addr) {
    171         sal_memset(addr, 0, sizeof (bcm_l2_egress_t));
    172     }
    173     return;
    174 }
    175 
    176 /*
    177  * Function:
    178  *      bcm_l2_station_t_init
    179  * Purpose:
    180  *      Intitialize an L2 station structure
    181  * Parameters:
    182  *      addr - (OUT) Pointer to L2 station address info.
    183  * Returns:
    184  *      nothing
    185  */
    186 void
    187 bcm_l2_station_t_init(bcm_l2_station_t *addr)
    188 {
    189     if (NULL != addr) {
    190         sal_memset(addr, 0, sizeof (bcm_l2_station_t));
    191         addr->taf_gate_primap = BCM_TSN_PRI_MAP_INVALID;
    192     }
    193     return;
    194 }
    195 
    196 /*
    197  * Function:
    198  *      bcm_l2_ring_t_init
    199  * Purpose:
    200  *      Intitialize an L2 ring structure
    201  * Parameters:
    202  *      addr - (OUT) Pointer to L2 ring structure.
    203  * Returns:
    204  *      nothing
    205  */
    206 void
    207 bcm_l2_ring_t_init(bcm_l2_ring_t *addr)
    208 {
    209     if (NULL != addr) {
    210         sal_memset(addr, 0, sizeof (bcm_l2_ring_t));
    211         addr->port0 = BCM_GPORT_INVALID;
    212         addr->port1 = BCM_GPORT_INVALID;
    213     }
    214     return;
    215 }
    216 
    217 /*
    218  * Function:
    219  *      bcm_l2_mac_port_t_init
    220  * Purpose:
    221  *      Intitialize an L2 MAC port structure
    222  * Parameters:
    223  *      addr - (OUT) Pointer to L2 MAC port structure.
    224  * Returns:
    225  *      nothing
    226  */
    227 void
    228 bcm_l2_mac_port_t_init(bcm_l2_mac_port_t *mac_port)
    229 {
    230     if (NULL != mac_port) {
    231         sal_memset(mac_port, 0, sizeof (bcm_l2_mac_port_t));
    232     }
    233     return;
    234 }
    235 
    236 /*
    237  * Function:
    238  *      bcm_l2_gport_forward_info_t_init
    239  * Purpose:
    240  *      Intitialize an L2 gportd forward info struct.
    241  * Parameters:
    242  *      addr - (OUT) Pointer to L2 gportd forward info struct.
    243  * Returns:
    244  *      nothing
    245  */
    246 void bcm_l2_gport_forward_info_t_init(
    247     bcm_l2_gport_forward_info_t *forward_info)
    248 {
    249     if (NULL != forward_info) {
    250         sal_memset(forward_info, 0, sizeof (bcm_l2_gport_forward_info_t));
    251     }
    252     return;
    253 }
    254 
    255 /*
    256  * Function:
    257  *     bcm_l2_learn_stat_t_init
    258  * Description:
    259  *     Initialize a bcm_l2_learn_stat_t structure.
    260  * Parameters:
    261  *     learn_stat - (OUT) Pointer to the L2 learned statistic structure.
    262  * Return: none
    263  */
    264 void bcm_l2_learn_stat_t_init(
    265     bcm_l2_learn_stat_t *learn_stat)
    266 {
    267     if (learn_stat != NULL) {
    268         sal_memset(learn_stat, 0, sizeof(bcm_l2_learn_stat_t));
    269     }
    270 }
    271 
    272 #if defined(INCLUDE_L3)
    273 /*
    274  * Function:
    275  *     bcm_l2_change_fields_t_init
    276  * Description:
    277  *     Initialize a bcm_l2_change_fields_t structure.
    278  * Parameters:
    279  *     l2_info - (OUT) Pointer to the L2 Change Fields structure.
    280  * Return: none
    281  */
    282 void bcm_l2_change_fields_t_init(
    283     bcm_l2_change_fields_t *l2_info)
    284 {
    285     if (l2_info != NULL) {
    286         sal_memset(l2_info, 0, sizeof(bcm_l2_change_fields_t));
    287     }
    288 }
    289 #endif