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

vlan.h (14418B)


      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-2020 Broadcom Inc. All rights reserved.
      5  * $Copyright: (c) 2013 Broadcom Corporation All Rights Reserved.$
      6  * $
      7 */
      8 
      9 #ifndef _BCM_INT_DPP_VLAN_H
     10 #define _BCM_INT_DPP_VLAN_H
     11 
     12 #include <sal/types.h>
     13 #include <bcm/types.h>
     14 #include <bcm/vlan.h>
     15 #include <soc/types.h>
     16 #include <soc/dpp/SAND/Utils/sand_multi_set.h>
     17 #include <soc/dpp/PPD/ppd_api_lif.h>
     18 #include <soc/dpp/PPD/ppd_api_lif_ing_vlan_edit.h>
     19 #include <soc/dpp/PPD/ppd_api_eg_vlan_edit.h>
     20 #include <soc/dpp/PPD/ppd_api_llp_parse.h>
     21 #include <soc/dpp/dpp_wb_engine.h>
     22 #include <shared/swstate/sw_state.h>
     23 
     24 #define VLAN_ACCESS         sw_state_access[unit].dpp.bcm.vlan
     25 
     26 /*
     27  * Define:
     28  *    VLAN_CHK_ID
     29  * Purpose:
     30  *    Causes a routine to return BCM_E_BADID if the specified
     31  *    VLAN ID is out of range.
     32  */
     33 
     34 #define BCM_DPP_VLAN_CHK_ID(unit, vid) do { \
     35     if (vid > BCM_VLAN_MAX) BCMDNX_ERR_EXIT_MSG(BCM_E_PARAM, (_BSL_BCM_MSG("Invalid VID"))); \
     36     } while (0);
     37 
     38 /*
     39  * Define:
     40  *    ING_TUNNEL_CHK_ID
     41  * Purpose:
     42  *    Causes a routine to return BCM_E_BADID if the specified
     43  *    TUNNEL ID is out of range.
     44  */
     45 
     46 #define BCM_DPP_ING_TUNNEL_CHK_ID(unit, tunnel) do { \
     47     if (tunnel > 2047) BCMDNX_ERR_EXIT_MSG(BCM_E_PARAM, (_BSL_BCM_MSG("Invalid ingress Tunnel ID"))); \
     48     } while (0);
     49 
     50 /*
     51  * Define:
     52  *    EGR_TUNNEL_CHK_ID
     53  * Purpose:
     54  *    Causes a routine to return BCM_E_BADID if the specified
     55  *    TUNNEL ID is out of range.
     56  */
     57 
     58 #define BCM_DPP_EGR_TUNNEL_CHK_ID(unit, tunnel) do { \
     59     if (tunnel > 4096) BCMDNX_ERR_EXIT_MSG(BCM_E_PARAM, (_BSL_BCM_MSG("Invalid egress Tunnel ID"))); \
     60     } while (0);
     61 
     62  /*
     63   * Define:
     64  *    BCM_DPP_GPON_TUNNEL_CHK_ID
     65  * Purpose:
     66  *    Causes a routine to return BCM_E_BADID if the specified
     67  *    TUNNEL ID is out of range.
     68  */
     69 
     70 #define BCM_DPP_GPON_TUNNEL_CHK_ID(unit, tunnel) do { \
     71     if (tunnel > 0x0fff) BCMDNX_ERR_EXIT_MSG(BCM_E_PARAM, (_BSL_BCM_MSG("Invalid ingress Tunnel ID"))); \
     72     } while (0);
     73 
     74 /*
     75  * Define:
     76  *    VLAN_PORT_CLASS_VALID
     77  * Purpose:
     78  *    Causes a routine to return BCM_E_PARAM if the specified
     79  *    PORT CLASS is out of range.
     80  */
     81 
     82 #define BCM_DPP_PORT_CLASS_VALID(unit, port_class) do { \
     83     if (port_class > SOC_DPP_DEFS_GET(unit, nof_vlan_domains)) BCMDNX_ERR_EXIT_MSG(BCM_E_PORT, (_BSL_BCM_MSG("Invalid port class"))); \
     84     } while (0);
     85 
     86 /*
     87  * Define:
     88  *    VLAN_CHK_PRIO
     89  * Purpose:
     90  *    Causes a routine to return BCM_E_PARAM if the specified
     91  *    priority (802.1p CoS) is out of range.
     92  */
     93 
     94 #define BCM_DPP_VLAN_CHK_PRIO(unit, prio) do { \
     95     if ((prio < BCM_PRIO_MIN || prio > BCM_PRIO_MAX)) BCMDNX_ERR_EXIT_MSG(BCM_E_PARAM, (_BSL_BCM_MSG("Invalid priority"))); \
     96     } while (0);
     97 
     98 #define BCM_DPP_VLAN_CHK_ACTION(unit, action) do { \
     99     if (action < bcmVlanActionNone || action > bcmVlanActionCopy) BCMDNX_ERR_EXIT_MSG(BCM_E_PARAM, (_BSL_BCM_MSG("Invalid action"))); \
    100     } while (0);
    101 
    102 
    103 /* 
    104   * In case of vlan port match is BCM_VLAN_PORT_MATCH_PORT, 
    105   * if vsi is set to -1, the VSI  assignment is set to SOC_PPC_VSI_EQ_IN_VID.
    106   */
    107 #define _BCM_DPP_VSI_USE_AS_ASSIGNMENT_MODE(_vsi) (_vsi == BCM_VLAN_ALL)
    108 
    109 
    110 /* Default forward profile for VSIs. Part of mapping to vsi default default forward
    111  * info.
    112  * default forward profile 0 maps unknown UC/MC/BC to mc group 0 + vsid
    113  * default forward profile 1 maps unknown UC to mc group 0 + vsid, unknown MC to 4K + vsid,
    114  * and unkonwn BC to 8K + vsid.
    115  */
    116 
    117 #define DPP_VSI_DEFAULT_DROP_PROFILE (0)
    118 #define DPP_VSI_DEFAULT_FRWRD_PROFILE (3)
    119 #define DPP_VSI_DEFAULT_FRWRD_PROFILE_UC_0_MC_4K_UC_8K (2)
    120 #define DPP_BVID_DEFAULT_FRWRD_PROFILE (1) /* for mac in mac, point to trap flooding, base = 12K*/
    121 
    122 #define DPP_NOF_SHARED_FIDS (7)
    123 
    124 /* unknown-da trap-actions for drop/flooding */
    125 #define _BCM_DPP_VLAN_UNKNOWN_DA_DROP_TRAP  (SOC_PPC_TRAP_CODE_UNKNOWN_DA_0)
    126 #define _BCM_DPP_VLAN_UNKNOWN_DA_FLD_TRAP  (SOC_PPC_TRAP_CODE_UNKNOWN_DA_1)
    127 #define _BCM_DPP_BVID_UNKNOWN_DA_FLD_TRAP  (SOC_PPC_TRAP_CODE_UNKNOWN_DA_7)
    128 
    129 #define DPP_PRTCL_NOF_ETHER_TYPE_IDS (16)
    130 #define NOS_PRTCL_PORT_PROFILES (8)
    131 
    132 
    133 #define BCM_DPP_NOF_BRIDGE_VLANS (BCM_VLAN_INVALID)
    134 
    135 /* Advanced VLAN edit mode defines */
    136 #define   DPP_NOF_INGRESS_VLAN_EDIT_PROFILES        (8)
    137 
    138 #define   DPP_NOF_EGRESS_VLAN_EDIT_PROFILE_BITS(unit)   (SOC_DPP_DEFS_GET(unit, nof_eve_profile_bits))
    139 #define   DPP_NOF_EGRESS_VLAN_EDIT_PROFILES(unit)       (0x1 << (DPP_NOF_EGRESS_VLAN_EDIT_PROFILE_BITS(unit)))
    140 #define   DPP_EGRESS_VLAN_EDIT_PROFILE_MASK(unit)       (DPP_NOF_EGRESS_VLAN_EDIT_PROFILES(unit) - 1)
    141 
    142 #define   DPP_NOF_VLAN_TAG_FORMATS                  (16)
    143 #define   DPP_VLAN_TAG_FORMAT_MASK                  (0xF)
    144 
    145 /*
    146  * Define:
    147  *    BCM_DPP_VLAN_EDIT_PROFILE_VALID
    148  * Purpose:
    149  *    Causes a routine to return BCM_E_PARAM if the specified
    150  *    VLAN edit profile is out of range.
    151  */
    152 
    153 #define BCM_DPP_VLAN_EDIT_PROFILE_VALID(unit, vlan_edit_profile, is_ingress) do {                               \
    154     if ( (is_ingress && (vlan_edit_profile >= DPP_NOF_INGRESS_VLAN_EDIT_PROFILES)) ||                           \
    155         (!is_ingress && (vlan_edit_profile >= DPP_NOF_EGRESS_VLAN_EDIT_PROFILES(unit))))                              \
    156             BCMDNX_ERR_EXIT_MSG(BCM_E_PARAM, (_BSL_BCM_MSG("Invalid VLAN edit profile")));                             \
    157     } while (0)
    158 
    159 
    160 /*
    161  * The entire vlan_info structure is protected by BCM_LOCK.
    162  */
    163 typedef struct bcm_dpp_vlan_info_s {
    164     int        init;      /* TRUE if VLAN module has been inited */
    165     bcm_vlan_t defl;      /* Default VLAN */
    166     bcm_pbmp_t defl_pbmp; /* Memeber ports of default vlan */
    167     bcm_pbmp_t defl_ubmp; /* Untagged ports of default vlan */
    168     int        count;     /* Number of existing VLANs */
    169     SOC_PPC_LIF_ID local_lif_index_drop; /* Local lif index of the vlan drop lif. */
    170     SOC_PPC_LIF_ID local_lif_index_simple; /* Local lif index of the vlan simple lif (vsi == vlan). */
    171     SOC_PPC_LIF_ID local_lif_rch; /* Local lif index of the RCH port default lif (vsi == vlan). */
    172 } bcm_dpp_vlan_info_t;
    173 
    174 /* struct used to maintain reference count to used FIDs */
    175 typedef struct {
    176     int ref_count;
    177     int fid;
    178 } fid_ref_count_t;
    179 
    180 /*
    181  *  Working state description (per unit)
    182  */
    183 typedef struct _bcm_dpp_vlan_unit_state_s {
    184     bcm_dpp_vlan_info_t vlan_info;
    185     fid_ref_count_t fid_ref_count[DPP_NOF_SHARED_FIDS];
    186     _bcm_dpp_vlan_translate_action_t edit_ing_action[SOC_PPC_NOF_INGRESS_VLAN_EDIT_ACTION_IDS];
    187     _bcm_dpp_vlan_translate_action_t edit_eg_action[SOC_PPC_MAX_NOF_EGRESS_VLAN_EDIT_ACTION_IDS];
    188     uint16 edit_eg_action_mapping[SOC_PPC_MAX_NOF_EGRESS_VLAN_EDIT_ACTION_MAPPINGS];
    189 } _bcm_dpp_vlan_unit_state_t;
    190 
    191 
    192 uint32
    193   _sand_multiset_buffer_get_entry(
    194     SOC_SAND_IN  int                             unit,
    195     SOC_SAND_IN  uint32                             sec_hanlde,
    196     SOC_SAND_IN  uint8                              *buffer,
    197     SOC_SAND_IN  uint32                             offset,
    198     SOC_SAND_IN  uint32                             len,
    199     SOC_SAND_OUT uint8                              *data
    200   );
    201 
    202 uint32
    203   _sand_multiset_buffer_set_entry(
    204     SOC_SAND_IN  int                             unit,
    205     SOC_SAND_IN  uint32                             sec_hanlde,
    206     SOC_SAND_INOUT  uint8                           *buffer,
    207     SOC_SAND_IN  uint32                             offset,
    208     SOC_SAND_IN  uint32                             len,
    209     SOC_SAND_IN  uint8                              *data
    210   );
    211 
    212 /* VLAN SW state */
    213 int _bcm_dpp_in_lif_ac_match_get(int unit, bcm_vlan_port_t *vlan_port, int in_lif);
    214 
    215 /*
    216  * set STP state for port and topology
    217  */
    218 int
    219 _bcm_ppd_stg_stp_port_set(int unit, bcm_stg_t stg_id, bcm_port_t port, int stp_state);
    220 
    221 int
    222 _bcm_ppd_stg_stp_port_get(int unit, bcm_stg_t stg_id, bcm_port_t port, int *stp_state);
    223 
    224 int
    225 _bcm_petra_vlan_flooding_per_lif_set(int unit, bcm_port_t port, SOC_PPC_LIF_ID lif_index, int is_port_flooding,  
    226                                      int is_lif_flooding, bcm_gport_t unknown_unicast_group, 
    227                                      bcm_gport_t unknown_multicast_group, bcm_gport_t broadcast_group);
    228 
    229 int
    230 _bcm_petra_vlan_flooding_per_lif_get(int unit, bcm_port_t port, SOC_PPC_LIF_ID lif_index, int is_port_flooding,
    231                                      int is_lif_flooding, bcm_gport_t *unknown_unicast_group, 
    232                                      bcm_gport_t *unknown_multicast_group, bcm_gport_t *broadcast_group);
    233 
    234 int 
    235 _bcm_petra_vlan_stg_set(int unit, bcm_vlan_t vid, bcm_stg_t stg);
    236 
    237 typedef struct bcm_dpp_vlan_egress_priority_mapping_s {
    238     /* Priority (PCP & DEI) */
    239         SOC_SAND_PP_PCP_UP pcp; 
    240         SOC_SAND_PP_DEI_CFI dei; 
    241 } bcm_dpp_vlan_egress_priority_mapping_t;
    242 
    243 typedef struct bcm_dpp_vlan_egress_priority_mapping_table_info_s {
    244     /* Priority (PCP & DEI) per TC * DP */
    245     bcm_dpp_vlan_egress_priority_mapping_t    pcp_dei[SOC_SAND_PP_TC_MAX + 1][SOC_SAND_PP_DP_MAX + 1];
    246 } bcm_dpp_vlan_egress_priority_mapping_table_info_t;
    247 
    248 typedef struct bcm_dpp_vlan_edit_profile_mapping_info_s {
    249         /* 
    250          *  Edit Profile defined by the mapping:
    251          *  Per VLAN Structure, which IVEC attributes
    252          */
    253     SOC_PPC_LIF_ING_VLAN_EDIT_COMMAND_INFO ivec[SOC_SAND_PP_NOF_ETHERNET_FRAME_VLAN_FORMATS];
    254 } bcm_dpp_vlan_edit_profile_mapping_info_t;
    255 
    256 typedef struct bcm_dpp_vlan_egress_edit_profile_info_s {
    257         /* 
    258          *  Egress Edit Profile 
    259          *  Per VLAN Structure, which EVEC attributes
    260          */
    261     SOC_PPC_EG_VLAN_EDIT_COMMAND_INFO evec[SOC_SAND_PP_NOF_ETHERNET_FRAME_VLAN_FORMATS];
    262 } bcm_dpp_vlan_egress_edit_profile_info_t;
    263 
    264 typedef struct bcm_dpp_vlan_flooding_profile_info_s {
    265 
    266   /* 
    267    *  Unknown Unicast addition in case of flooding
    268    */
    269   int unknown_uc_add;
    270   /* 
    271    *  Unknown Multicast addition in case of flooding
    272    */
    273   int unknown_mc_add;
    274   /* 
    275    *  Unknown BC addition in case of flooding
    276    */
    277   int bc_add;
    278 } bcm_dpp_vlan_flooding_profile_info_t;
    279 
    280 typedef struct bcm_dpp_vlan_port_protocol_profile_info_s {
    281   /* 
    282    *  Ethertype
    283    */
    284   uint16 ethertype;
    285   /* 
    286    *  Other data including: valid_entry(1bit), vlan (12bit), vlan_is_valid (1bit), tc (3bit), tc_is_valid(1bit)
    287    */
    288   uint32 vlan_tc_data;
    289 
    290 } bcm_dpp_vlan_port_protocol_profile_info_t;
    291 
    292 typedef struct bcm_dpp_vlan_port_protocol_entries_s {
    293    bcm_dpp_vlan_port_protocol_profile_info_t port_protocol_entry[DPP_PRTCL_NOF_ETHER_TYPE_IDS];
    294 } bcm_dpp_vlan_port_protocol_entries_t;
    295 
    296 void 
    297 _bcm_dpp_vlan_egress_edit_profile_info_t_init(bcm_dpp_vlan_egress_edit_profile_info_t *info);
    298 
    299 void 
    300 _bcm_dpp_vlan_edit_profile_mapping_info_t_init(bcm_dpp_vlan_edit_profile_mapping_info_t *info);
    301 
    302 int
    303 _bcm_petra_vlan_edit_profile_info_hw_set(int unit,
    304                      int vlan_edit_profile,
    305                      bcm_dpp_vlan_edit_profile_mapping_info_t *mapping_info);
    306 
    307 extern int
    308 bcm_petra_vlan_detach(int unit);
    309 
    310 int _bcm_dpp_vlan_port_create(int unit, bcm_vlan_port_t *vlan_port);
    311 
    312 void
    313 _bcm_petra_vlan_edit_command_hw_get(int unit,
    314                                     int vlan_edit_profile,
    315                                     SOC_SAND_PP_ETHERNET_FRAME_VLAN_FORMAT vlan_format,
    316                                     int *ivec_id,
    317                                     uint8 *is_ivec_to_set,
    318                                     uint8 *is_vlan_format_valid);
    319 
    320 
    321 int 
    322 _bcm_petra_vlan_translate_action_add(
    323     int unit, 
    324     bcm_gport_t port, 
    325     bcm_vlan_translate_key_t key_type, 
    326     bcm_vlan_t outer_vlan, 
    327     bcm_vlan_t inner_vlan, 
    328     bcm_vlan_action_set_t *action);
    329 
    330 int
    331 _bcm_petra_vlan_translate_match_tpid_value_to_index(int unit, int tpid_value, SOC_PPC_LLP_PARSE_TPID_VALUES* tpid_vals, int* tpid_index);
    332 
    333 int
    334 _bcm_petra_vlan_translate_match_tpid_index_to_value(int unit, int tpid_index, SOC_PPC_LLP_PARSE_TPID_VALUES* tpid_vals, uint16* tpid_value);
    335 
    336 /* 
    337  * Advanced VLAN editing: action SW table Get/Set/Init functions
    338  */
    339 
    340 /* Initialize BCM DPP VLAN editing action SW table structure.
    341    The structure is used in order to store a VLAN translation action in the SW */
    342 void 
    343 _bcm_dpp_vlan_translate_action_t_init(_bcm_dpp_vlan_translate_action_t *action);
    344 
    345 /* Set a BCM DPP VLAN editing action structure that is stored in a SW actions table */
    346 int
    347 _bcm_dpp_vlan_edit_action_set(
    348     int unit,
    349     int action_id,
    350     uint32 is_ingress,
    351     _bcm_dpp_vlan_translate_action_t *action);
    352 
    353 /* Get a BCM DPP VLAN editing action structure that is stored in a SW actions table */
    354 int
    355 _bcm_dpp_vlan_edit_action_get(
    356     int unit,
    357     int action_id,
    358     uint32 is_ingress,
    359     _bcm_dpp_vlan_translate_action_t *action);
    360 
    361 /* Get tag format and profile from from action ID that is stored in  SW Egress action mapping table. */
    362 int
    363 _bcm_petra_vlan_edit_eg_command_id_find(
    364     int unit,
    365     uint32 action_id,
    366     int find_from_current,
    367     SOC_PPC_EG_VLAN_EDIT_COMMAND_KEY *command_key);
    368 
    369 /* Given a vlan port and a pointer to lif_ac_keu struct, fills the lif_ac_key struct according to the vlan port. */
    370 int _bcm_dpp_gport_fill_ac_key(
    371     int                  unit,
    372     void                 *gport, 
    373     int                  gport_type, 
    374     SOC_PPC_L2_LIF_AC_KEY  *in_ac_key);
    375 
    376 /*
    377  * given gport return out_ac_key where this gport is defined
    378  */
    379 int _bcm_dpp_gport_fill_out_ac_key(
    380     int                  unit,
    381     bcm_vlan_port_t      *vlan_port,     
    382     uint8                *is_cep,
    383     SOC_PPC_EG_AC_VBP_KEY *vbp_key,
    384     SOC_PPC_EG_AC_CEP_PORT_KEY *cep_key
    385  );
    386 
    387 /*
    388  * Convert the VLAN Action to the VLAN Edit Profile Info
    389  */
    390 int _bcm_petra_vlan_action_to_edit_profile_info_build(
    391     int unit,
    392     bcm_vlan_action_set_t *action_set,
    393     uint32 tpid_profile,
    394     int is_ingress,
    395     bcm_dpp_vlan_edit_profile_mapping_info_t *mapping_info,
    396     bcm_dpp_vlan_egress_edit_profile_info_t *eg_mapping_info,
    397     uint8 is_extender);
    398 
    399 /*
    400  * Set in the HW the Egress VLAN Edit profile attributes
    401  */
    402 int _bcm_petra_vlan_edit_profile_info_eg_hw_set(
    403     int unit,
    404     int vlan_edit_profile_eg,
    405     bcm_dpp_vlan_egress_edit_profile_info_t *eg_edit_profile_set);
    406 
    407 /*
    408  *    get vlan port learn fec for mc group
    409  */
    410 int bcm_petra_vlan_port_get_mc_fec(
    411     int unit,
    412     bcm_gport_t gport,
    413     SOC_PPC_FEC_ID *fec_id);
    414 
    415  int
    416 _bcm_petra_vlan_translation_tpids_to_tpid_profile(
    417     int unit,
    418     uint16 *tpids,
    419     int nof_tpids,
    420     int inner_tpid_only,
    421     uint32 *tpid_profile);
    422 
    423 #endif    /* !_BCM_INT_DPP_VLAN_H */