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

multicast.c (3942B)


      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:    multicast.c
      8  * Purpose: Manages multicast functions
      9  */
     10 
     11 #include <soc/defs.h>
     12 #include <sal/core/libc.h>
     13 
     14 #if defined(BCM_XGS3_SWITCH_SUPPORT) && defined(INCLUDE_L3)
     15 
     16 #include <soc/drv.h>
     17 #include <soc/mem.h>
     18 #include <soc/util.h>
     19 #include <soc/debug.h>
     20 
     21 #include <bcm/error.h>
     22 
     23 #include <bcm_int/esw/mbcm.h>
     24 #include <bcm_int/esw/l3.h>
     25 #include <bcm_int/esw/firebolt.h>
     26 #include <bcm_int/esw/xgs3.h>
     27 #include <bcm_int/common/multicast.h>
     28 #include <bcm_int/esw/multicast.h>
     29 #include <bcm_int/esw/stack.h>
     30 
     31 #include <bcm_int/esw_dispatch.h>
     32 
     33 /*
     34  * Function:
     35  *      bcm_xgs3_multicast_group_get
     36  * Purpose:
     37  *      Allocate a multicast group index
     38  * Parameters:
     39  *      unit       - (IN)   Device Number
     40  *      group      - (IN)  Group ID
     41  *      flags      - (OUT)   BCM_MULTICAST_*
     42  * Returns:
     43  *      BCM_E_XXX
     44  */
     45 int
     46 bcm_xgs3_multicast_group_get(int unit, bcm_multicast_t group, uint32 *flags)
     47 {
     48     int mc_index, is_set = FALSE;
     49 
     50     mc_index = _BCM_MULTICAST_ID_GET(group);
     51     if (_BCM_MULTICAST_IS_L2(group)) {
     52         BCM_IF_ERROR_RETURN
     53             (_bcm_xgs3_l2mc_index_is_set(unit, mc_index, &is_set));
     54         *flags = BCM_MULTICAST_TYPE_L2;
     55     } else {
     56         if (!_BCM_MULTICAST_IS_L3(group)) {
     57             return BCM_E_PARAM;
     58         }
     59 
     60         BCM_IF_ERROR_RETURN
     61             (bcm_xgs3_ipmc_id_is_set(unit, mc_index, &is_set));
     62         *flags = BCM_MULTICAST_TYPE_L3;
     63     }
     64 
     65     if (is_set) {
     66         *flags |= BCM_MULTICAST_WITH_ID;
     67     } else {
     68         *flags = 0;
     69         return BCM_E_NOT_FOUND;
     70     }
     71 
     72     return BCM_E_NONE;
     73 }
     74 
     75 /*
     76  * Function:
     77  *      bcm_xgs3_multicast_group_traverse
     78  * Purpose:
     79  *      Iterate over the defined multicast groups of the type
     80  *      specified in 'flags'.  If all types are desired, use
     81  *      MULTICAST_TYPE_MASK.
     82  * Parameters:
     83  *      unit - (IN) Unit number.
     84  *      trav_fn - (IN) Callback function.
     85  *      flags - (IN) BCM_MULTICAST_*
     86  *      user_data - (IN) User data to be passed to callback function.
     87  * Returns:
     88  *      BCM_E_XXX
     89  */
     90 int
     91 bcm_xgs3_multicast_group_traverse(int unit,
     92                                   bcm_multicast_group_traverse_cb_t trav_fn, 
     93                                   uint32 flags, void *user_data)
     94 {
     95     int l2mc_size, l3mc_size, mc_index, is_set;
     96     uint32 group_flags;
     97     bcm_multicast_t group;
     98 
     99     if (flags & BCM_MULTICAST_TYPE_L2) {
    100         BCM_IF_ERROR_RETURN(_bcm_xgs3_l2mc_size_get(unit, &l2mc_size));
    101         group_flags = BCM_MULTICAST_TYPE_L2 | BCM_MULTICAST_WITH_ID;
    102 
    103         for (mc_index = 0; mc_index < l2mc_size; mc_index++) {
    104             BCM_IF_ERROR_RETURN
    105                 (_bcm_xgs3_l2mc_index_is_set(unit, mc_index, &is_set));
    106             if (is_set) {
    107                 _BCM_MULTICAST_GROUP_SET(group, _BCM_MULTICAST_TYPE_L2,
    108                                          mc_index);
    109                 BCM_IF_ERROR_RETURN
    110                     ((*trav_fn)(unit, group, group_flags, user_data));
    111             }
    112         }
    113     }
    114 
    115     if (flags & BCM_MULTICAST_TYPE_L3) {
    116         l3mc_size = soc_mem_index_count(unit, L3_IPMCm);
    117         group_flags = BCM_MULTICAST_TYPE_L3 | BCM_MULTICAST_WITH_ID;
    118 
    119         for (mc_index = 0; mc_index < l3mc_size; mc_index++) {
    120             BCM_IF_ERROR_RETURN
    121                 (bcm_xgs3_ipmc_id_is_set(unit, mc_index, &is_set));
    122             if (is_set) {
    123                 _BCM_MULTICAST_GROUP_SET(group, _BCM_MULTICAST_TYPE_L3,
    124                                          mc_index);
    125                 BCM_IF_ERROR_RETURN
    126                     ((*trav_fn)(unit, group, group_flags, user_data));
    127             }
    128         }
    129     }
    130 
    131     return BCM_E_NONE;
    132 }
    133 
    134 #else  /* INCLUDE_L3 && BCM_XGS3_SWITCH_SUPPORT */
    135 int bcm_esw_xgs3_multicast_not_empty;
    136 #endif /* INCLUDE_L3 && BCM_XGS3_SWITCH_SUPPORT */