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

flow.h (15256B)


      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-2020 Broadcom Inc. All rights reserved.
      6  *
      7  * This file contains Flow definitions internal to the BCM library.
      8  */
      9 
     10 
     11 #ifndef _BCM_INT_FLOW_H
     12 #define _BCM_INT_FLOW_H
     13 
     14 #include <bcm/types.h>
     15 #include <soc/drv.h>
     16 #include <bcm/flow.h>
     17 #include <include/bcm_int/esw/vxlan.h>
     18 #include <include/soc/tnl_term.h>
     19 #ifdef INCLUDE_L3
     20 
     21 #define _BCM_FLOW_VFI_INVALID 0
     22 
     23 /*
     24  * Do not change - Implementation assumes
     25  * _BCM_FLOW_VPN_TYPE_ELINE == _BCM_FLOW_VPN_TYPE_ELAN
     26  */
     27 #define _BCM_FLOW_VPN_TYPE_ELINE         _BCM_VPN_TYPE_VFI
     28 #define _BCM_FLOW_VPN_TYPE_ELAN          _BCM_VPN_TYPE_VFI
     29 
     30 #define _BCM_FLOW_VPN_SET(_vpn_, _type_, _id_) \
     31         _BCM_VPN_SET(_vpn_, _type_, _id_)
     32 
     33 #define _BCM_FLOW_VPN_GET(_id_, _type_,  _vpn_) \
     34         _BCM_VPN_GET(_id_, _type_, _vpn_)
     35 
     36 #define _BCM_FLOW_CLEANUP(_rv_) \
     37         if ( (_rv_) < 0) { \
     38             goto cleanup; \
     39         }
     40 
     41 
     42 /* index to memory usage array, do not change */
     43 #define _BCM_FLOW_VXLT1_INX   0
     44 #define _BCM_FLOW_VXLT2_INX   1
     45 #define _BCM_FLOW_MPLS_INX    2
     46 #define _BCM_FLOW_EVXLT1_INX  3
     47 #define _BCM_FLOW_EVXLT2_INX  4
     48 #define _BCM_FLOW_TNL_INX     5 
     49 #define _BM_FLOW_MEM_USE_MAX  6  /* last index + 1 */
     50 
     51 typedef struct _bcm_flow_init_tunnel_entry_s {
     52     uint16  idx;     /* index to egr_ip_tunnel table */
     53 } _bcm_flow_init_tunnel_entry_t;
     54 
     55 /* Flow match config structure */
     56 typedef struct bcm_flow_match_vp_s {
     57     uint32 vnid;                        /* VN_ID. */
     58     bcm_vlan_t vlan;                    /* Outer VLAN ID to match. */
     59     bcm_vlan_t inner_vlan;              /* Inner VLAN ID to match. */
     60     bcm_gport_t port;                   /* Match port / trunk */
     61     bcm_ip_t sip;                       /* source IPv4 address */
     62     bcm_ip6_t sip6;                     /* source IPv6 address */
     63     bcm_mpls_label_t mpls_label;
     64     bcm_flow_match_criteria_t criteria; /* flow match criteria. */
     65     uint32 valid_elements;              /* bitmap of valid fields for the match
     66                                            action */
     67     bcm_flow_handle_t flow_handle;      /* flow handle derived from flow name */
     68     uint32 flow_option;                 /* flow option derived from flow option
     69                                            name */
     70 } bcm_flow_match_vp_t;
     71 
     72 /*
     73  * Software book keeping for Flex Flow related information
     74  */
     75 typedef struct _bcm_flow_bookkeeping_s {
     76     int         initialized;        /* Set to TRUE when FLOW module initialized */
     77     sal_mutex_t    flow_mutex;    /* Protection mutex. */
     78     bcm_vlan_t                      *flow_vpn_vlan; /* Outer VLAN for VPN */
     79 
     80     /* match function */
     81     uint16 *iif_ref_cnt; /* iif usage reference count  */
     82     uint16 *vp_ref_cnt;  /* svp usage reference count  */
     83     uint32 mem_use_cnt[_BM_FLOW_MEM_USE_MAX];  /* memory referenc count in */
     84 
     85     /* encap set */
     86     SHR_BITDCL *dvp_attr_bitmap;  /* EGR_DVP_ATTRIBUTE index usage bitmap */
     87       
     88     /* 
     89      * The initiator tunnel here means these IP header fields such as SIP,DIP.
     90      * They do not always reside in the same hardware table. A single software
     91      * tunnel table is constructed to point to all these fields. 
     92      * soft tunnel index:
     93      *    L2 tunnel:   dvp
     94      *    L3 tunnel:   max_dvp + egr_intf ID
     95      */ 
     96     _bcm_flow_init_tunnel_entry_t *init_tunnel;
     97 
     98     /* IP tunnel fragmentID(sequence number) table base index*/
     99     uint32 frag_base_inx; 
    100     bcm_flow_match_vp_t* match_key;
    101 } _bcm_flow_bookkeeping_t;
    102 
    103 extern _bcm_flow_bookkeeping_t *_bcm_flow_bk_info[BCM_MAX_NUM_UNITS];
    104 #define FLOW_INFO(_unit_)      (_bcm_flow_bk_info[_unit_])
    105 
    106 /*
    107  * EGR_DVP_ATTRIBUTE table usage bitmap operations
    108  */
    109 #define _BCM_FLOW_EGR_DVP_USED_GET(_u_, _dvp_) \
    110         SHR_BITGET(FLOW_INFO(_u_)->dvp_attr_bitmap, (_dvp_))
    111 #define _BCM_FLOW_EGR_DVP_USED_SET(_u_, _dvp_) \
    112         SHR_BITSET(FLOW_INFO((_u_))->dvp_attr_bitmap, (_dvp_))
    113 #define _BCM_FLOW_EGR_DVP_USED_CLR(_u_, _dvp_) \
    114         SHR_BITCLR(FLOW_INFO((_u_))->dvp_attr_bitmap, (_dvp_))
    115 
    116 
    117 /* Generic memory allocation routine. */
    118 #define BCM_TD3_FLOW_ALLOC(_ptr_,_size_,_descr_)                      \
    119             do {                                                     \
    120                 if ((NULL == (_ptr_))) {                             \
    121                    _ptr_ = sal_alloc((_size_),(_descr_));            \
    122                 }                                                    \
    123                 if((_ptr_) != NULL) {                                \
    124                     sal_memset((_ptr_), 0, (_size_));                \
    125                 }                                                    \
    126             } while (0)
    127 
    128 /**** macros used for flexflow modules only(under flexflow dir) ****/
    129 
    130 #define _BCM_FLOW_LOGICAL_FIELD_MAX       20
    131 #define _BCM_FLOW_IPV6_ADDR_WORD_LEN      4
    132 
    133 #define _BCM_FLOW_IS_FLEX_VIEW(_info) \
    134 	((_info)->flow_handle >= SOC_FLOW_DB_FLOW_ID_START)
    135 
    136 /* flow match */
    137 
    138 /* flow encap */
    139 
    140 #define _BCM_FLOW_ENCAP_L2GRE_KEY_TYPE_VFI        0x05
    141 #define _BCM_FLOW_ENCAP_L2GRE_KEY_TYPE_VFI_DVP    0x06
    142 #define _BCM_FLOW_ENCAP_VXLAN_KEY_TYPE_VFI        0x08
    143 #define _BCM_FLOW_ENCAP_VXLAN_KEY_TYPE_VFI_DVP    0x09
    144 #define _BCM_FLOW_ENCAP_KEY_TYPE_VFI_DVP_GROUP    0x0a
    145 #define _BCM_FLOW_ENCAP_KEY_TYPE_VRF_MAPPING      0x0b
    146 #define _BCM_FLOW_ENCAP_KEY_TYPE_VLAN_XLATE_VFI   0x0c
    147 
    148 #define _BCM_FLOW_VXLAN_EGRESS_DEST_VP_TYPE       2
    149 #define _BCM_FLOW_L2GRE_EGRESS_DEST_VP_TYPE       3
    150 
    151 #define  _BCM_FLOW_DEST_VP_TYPE_ACCESS         0x0
    152 #define  _BCM_FLOW_L2GRE_INGRESS_DEST_VP_TYPE  0x2
    153 #define  _BCM_FLOW_VXLAN_INGRESS_DEST_VP_TYPE  0x3
    154 
    155 /* internal use only. must avoid conflict with API encap flags */
    156 #define  _BCM_FLOW_ENCAP_FLAG_TPID_INDEX       (1 << 31)
    157 
    158 #define _BCM_FLOW_SD_TAG_FORMAT(_info) (_BCM_FLOW_IS_FLEX_VIEW(_info) || \
    159         ((_info)->criteria == BCM_FLOW_ENCAP_CRITERIA_VRF_MAPPING) || \
    160         ((_info)->criteria == BCM_FLOW_ENCAP_CRITERIA_VFI_DVP_GROUP))
    161 
    162 #define _BCM_FLOW_TUNNEL_DATA_FORMAT(_info) \
    163         (((_info)->criteria == BCM_FLOW_ENCAP_CRITERIA_VRF_MAPPING) || \
    164          ((_info)->criteria == BCM_FLOW_ENCAP_CRITERIA_VFI_DVP_GROUP))
    165 
    166 /* flow match */
    167 
    168 #define _BCM_FLOW_MATCH_KEY_TYPE_VXLAN_SIP       0x8
    169 #define _BCM_FLOW_MATCH_KEY_TYPE_VXLAN_VNID      0x9
    170 #define _BCM_FLOW_MATCH_KEY_TYPE_VXLAN_SIP_VNID  0xa
    171 #define _BCM_FLOW_MATCH_KEY_TYPE_L2GRE_SIP       0x6
    172 #define _BCM_FLOW_MATCH_KEY_TYPE_L2GRE_VPNID     0x7
    173 #define _BCM_FLOW_MATCH_KEY_TYPE_L2GRE_SIP_VPNID 0x4
    174 #define _BCM_FLOW_MATCH_KEY_TYPE_VXLAN_FLEX_VNID      0x13
    175 #define _BCM_FLOW_MATCH_KEY_TYPE_VXLAN_FLEX_SIP_VNID  0x1c
    176 
    177 #define _BCM_FLOW_MATCH_PORT_CTRL_SET     0
    178 #define _BCM_FLOW_MATCH_PORT_CTRL_DELETE  1
    179 #define _BCM_FLOW_MATCH_PORT_CTRL_GET     2
    180 
    181 #define _BCM_FLOW_TD3_L3_TUNNEL_DOUBLE_WIDE 2
    182 #define _BCM_FLOW_TD3_L3_TUNNEL_QUAD_WIDE   1
    183 
    184 #define _BCM_FLOW_TD3_L3_TUNNEL_WIDTH_SINGLE 1
    185 #define _BCM_FLOW_TD3_L3_TUNNEL_DOUBLE 2
    186 #define _BCM_FLOW_TD3_L3_TUNNEL_QUAD 4
    187 
    188 typedef struct _bcm_flow_frag_field_info_s {
    189     int pos_min;
    190     int pos_max;
    191     uint32 id;
    192 } _bcm_flow_frag_field_info_t;
    193 
    194 /* functions only used within flexflow */
    195 extern int
    196 bcmi_esw_flow_vp_is_eline( int unit, int vp, uint8 *isEline);
    197 
    198 extern int
    199 _bcm_flow_key_is_valid(int unit, soc_mem_t mem_view_id,
    200                        uint32 *key, int num_keys);
    201 
    202 extern int 
    203 _bcm_flow_mem_view_to_flow_info_get(int unit,
    204                uint32 mem_view_id,
    205                uint32 func_id,
    206                uint32 *flow_hndl,
    207                uint32 *flow_opt,
    208                int    instance);
    209 
    210 #ifdef BCM_WARM_BOOT_SUPPORT
    211 extern int
    212 _bcm_flow_tunnel_initiator_reinit(int unit);
    213 #endif
    214 
    215 /**** internal global functions ****/
    216 extern int _bcm_esw_flow_sync(int unit);
    217 
    218 extern int bcmi_esw_flow_port_create(
    219     int unit, 
    220     bcm_vpn_t vpn, 
    221     bcm_flow_port_t  *flow_port);
    222 
    223 extern int bcmi_esw_flow_port_destroy(
    224     int unit, 
    225     bcm_vpn_t vpn, 
    226     bcm_gport_t vxlan_port_id);
    227 
    228 extern int bcmi_esw_flow_port_get(
    229     int unit, 
    230     bcm_vpn_t vpn, 
    231     bcm_flow_port_t *flow_port);
    232 
    233 extern int bcmi_esw_flow_port_get_all( 
    234     int unit, 
    235     bcm_vpn_t l2vpn, 
    236     int port_max, 
    237     bcm_flow_port_t *port_array, 
    238     int *port_count);
    239 
    240 extern int  bcmi_esw_flow_lock(int unit);
    241 
    242 extern void  bcmi_esw_flow_unlock(int unit);
    243 
    244 extern int bcmi_esw_flow_init(int unit);
    245 
    246 extern int bcmi_esw_flow_check_init(int unit);
    247 
    248 extern int bcmi_esw_flow_cleanup(int unit);
    249 
    250 #ifdef BCM_WARM_BOOT_SUPPORT_SW_DUMP
    251 extern void bcmi_esw_flow_sw_dump (int unit);
    252 #endif /* BCM_WARM_BOOT_SUPPORT_SW_DUMP */
    253 
    254 extern int bcmi_esw_flow_vpn_is_valid(
    255     int unit, 
    256     bcm_vpn_t l2vpn);
    257 
    258 extern int bcmi_esw_flow_vpn_is_eline(
    259     int unit,
    260     bcm_vpn_t l2vpn,
    261     uint8 *isEline);
    262 
    263 extern int bcmi_esw_flow_match_add(
    264     int unit,
    265     bcm_flow_match_config_t *info,
    266     uint32 num_of_fields,
    267     bcm_flow_logical_field_t *field);
    268 
    269 extern int bcmi_esw_flow_match_delete(
    270     int unit,
    271     bcm_flow_match_config_t *info,
    272     uint32 num_of_fields,
    273     bcm_flow_logical_field_t *field);
    274 
    275 extern int bcmi_esw_flow_match_get(
    276     int unit,
    277     bcm_flow_match_config_t *info,
    278     uint32 num_of_fields,
    279     bcm_flow_logical_field_t *field);
    280 
    281 extern int bcmi_esw_flow_match_traverse(
    282     int unit,
    283     bcm_flow_match_traverse_cb cb,
    284     void *user_data);
    285 
    286 extern int bcmi_esw_flow_tunnel_initiator_create(
    287     int unit,
    288     bcm_flow_tunnel_initiator_t *info,
    289     uint32 num_of_fields,
    290     bcm_flow_logical_field_t *field);
    291 
    292 extern int bcmi_esw_flow_tunnel_initiator_destroy(
    293     int unit,
    294     bcm_gport_t flow_tunnel_id);
    295 
    296 extern int bcmi_esw_flow_tunnel_initiator_destroy_all(
    297     int unit);
    298 
    299 extern int bcmi_esw_flow_tunnel_initiator_get(
    300     int unit,
    301     bcm_flow_tunnel_initiator_t *info,
    302     uint32 num_of_fields,
    303     bcm_flow_logical_field_t *field);
    304 
    305 extern int bcmi_esw_flow_tunnel_initiator_traverse(
    306     int unit,
    307     bcm_flow_tunnel_initiator_traverse_cb cb,
    308     void *user_data);
    309 
    310 extern int bcmi_esw_flow_tunnel_terminator_create(
    311     int unit,
    312     bcm_flow_tunnel_terminator_t *info,
    313     uint32 num_of_fields,
    314     bcm_flow_logical_field_t *field);
    315 
    316 extern int bcmi_esw_flow_tunnel_terminator_update(
    317     int unit,
    318     bcm_flow_tunnel_terminator_t *info,
    319     uint32 num_of_fields,
    320     bcm_flow_logical_field_t *field);
    321 
    322 extern int bcmi_esw_flow_tunnel_terminator_destroy(
    323     int unit,
    324     bcm_flow_tunnel_terminator_t *info,
    325     uint32 num_of_fields,
    326     bcm_flow_logical_field_t *field);
    327 
    328 extern int bcmi_esw_flow_tunnel_terminator_destroy_all(
    329     int unit);
    330 
    331 extern int bcmi_esw_flow_tunnel_terminator_get(
    332     int unit,
    333     bcm_flow_tunnel_terminator_t *info,
    334     uint32 num_of_fields,
    335     bcm_flow_logical_field_t *field);
    336   
    337 extern int bcmi_esw_flow_port_encap_set(
    338     int unit,
    339     bcm_flow_port_encap_t *info,
    340     uint32 num_of_fields,
    341     bcm_flow_logical_field_t *field);
    342 
    343 extern int  bcmi_esw_flow_tunnel_terminator_traverse(
    344     int unit,
    345     bcm_flow_tunnel_terminator_traverse_cb cb,
    346     void *user_data);
    347 
    348 extern int bcmi_esw_flow_port_encap_get(
    349     int unit,
    350     bcm_flow_port_encap_t *info,
    351     uint32 num_of_fields,
    352     bcm_flow_logical_field_t *field);
    353 
    354 extern int bcmi_esw_flow_encap_add(
    355     int unit,
    356     bcm_flow_encap_config_t *info,
    357     uint32 num_of_fields,
    358     bcm_flow_logical_field_t *field);
    359 
    360 extern int bcmi_esw_flow_encap_delete(
    361     int unit,
    362     bcm_flow_encap_config_t *info,
    363     uint32 num_of_fields,
    364     bcm_flow_logical_field_t *field);
    365 
    366 extern int bcmi_esw_flow_encap_get(
    367     int unit,
    368     bcm_flow_encap_config_t *info,
    369     uint32 num_of_fields,
    370     bcm_flow_logical_field_t *field);
    371 
    372 extern int bcmi_esw_flow_encap_traverse(
    373     int unit,
    374     bcm_flow_encap_traverse_cb cb,
    375     void *user_data);
    376 
    377 extern int
    378 bcmi_esw_flow_vpn_create(int unit, bcm_vpn_t *vpn,
    379                             bcm_flow_vpn_config_t *info);
    380 extern int
    381 bcmi_esw_flow_vpn_destroy(int unit, bcm_vpn_t vpn);
    382 
    383 extern int
    384 bcmi_esw_flow_vpn_destroy_all(int unit);
    385 
    386 extern int
    387 bcmi_esw_flow_vpn_get(int unit, bcm_vpn_t vpn,
    388                          bcm_flow_vpn_config_t *info);
    389 extern int
    390 bcmi_esw_flow_vpn_traverse(int unit,
    391                               bcm_flow_vpn_traverse_cb cb,
    392                               void *user_data);
    393 
    394 extern int bcmi_esw_flow_port_delete_all(int unit, bcm_vpn_t vpn);
    395 
    396 extern int bcmi_esw_flow_dvp_vlan_xlate_key_set(int unit, 
    397                    bcm_gport_t port_id, int key_type);
    398 extern int bcmi_esw_flow_dvp_vlan_xlate_key_get(int unit, 
    399                    bcm_gport_t port_id, int *key_type);
    400 
    401 /* Flex Counter */
    402 extern int bcmi_esw_flow_stat_object_get(int unit,
    403                           bcm_flow_handle_t flow_handle,
    404                           bcm_flow_option_id_t flow_option_id,
    405                           bcm_flow_function_type_t function_type,
    406                           bcm_stat_object_t *stat_object);
    407 
    408 extern int bcmi_esw_flow_stat_attach(int unit,
    409                           bcm_flow_stat_info_t *flow_stat_info,
    410                           uint32 num_of_fields,
    411                           bcm_flow_logical_field_t *field,
    412                           uint32 stat_counter_id);
    413 
    414 extern int bcmi_esw_flow_stat_detach(int unit,
    415                           bcm_flow_stat_info_t *flow_stat_info,
    416                           uint32 num_of_fields,
    417                           bcm_flow_logical_field_t *field,
    418                           uint32 stat_counter_id);
    419 
    420 extern int bcmi_esw_flow_stat_id_get(int unit,
    421                          bcm_flow_stat_info_t *flow_stat_info,
    422                          uint32 num_of_fields,
    423                          bcm_flow_logical_field_t *field,
    424                          bcm_stat_object_t stat_object,
    425                          uint32 *stat_counter_id);
    426 
    427 extern int  bcmi_esw_flow_entry_to_tnl_term(int unit,
    428                                     uint32 *entry,
    429                                     soc_tunnel_term_t *tnl_term);
    430 
    431 extern int bcmi_esw_flow_tnl_term_to_entry(int unit,
    432                                     soc_tunnel_term_t *tnl_term,
    433                                     uint32 *entry);
    434 
    435 extern int
    436 bcmi_flow_ip6_addr_is_valid(bcm_ip6_t addr);
    437 
    438 extern int
    439 bcmi_esw_flow_vpnid_get(int unit, int vfi_index, bcm_vlan_t *vid);
    440 
    441 extern int
    442 bcmi_esw_flow_mshg_prune_egress_set(
    443         int unit,
    444         bcm_switch_network_group_t src_group_id,
    445         bcm_switch_network_group_t dst_group_id,
    446         int prune_enable);
    447 
    448 extern int
    449 bcmi_esw_flow_mshg_prune_egress_init(int unit);
    450 extern int
    451 _bcm_esw_flow_port_source_vp_lag_set(int unit, bcm_gport_t gport, int vp_lag_vp);
    452 extern int
    453 _bcm_esw_flow_port_source_vp_lag_clear(int unit, bcm_gport_t gport, int vp_lag_vp);
    454 extern int
    455 _bcm_esw_flow_port_source_vp_lag_get(int unit, bcm_gport_t gport, int* vp_lag_vp);
    456 extern int
    457 bcmi_esw_flow_match_svp_get(int unit, bcm_gport_t gport, int* vp_lag_vp);
    458 extern int
    459 bcmi_esw_flow_match_svp_replace(int unit, int gport, int new_vp);
    460 extern int
    461 bcmi_esw_flow_trunk_member_add(int unit, bcm_trunk_t trunk_id,
    462                 int trunk_member_count, bcm_port_t *trunk_member_array);
    463 extern int
    464 bcmi_esw_flow_trunk_member_delete(int unit, bcm_trunk_t trunk_id,
    465                 int trunk_member_count, bcm_port_t *trunk_member_array);
    466 #endif /* INCLUDE_L3 */
    467 #endif  /* !_BCM_INT_FLOW_H */