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

flowtracker.h (15542B)


      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:        flowtracker.h
      8  * Purpose:     
      9  */
     10 #ifndef _BCM_INT_FLOWTRACKER_H_
     11 #define _BCM_INT_FLOWTRACKER_H_
     12 
     13 #if defined(INCLUDE_FLOWTRACKER)
     14 
     15 #include <soc/shared/ft.h>
     16 #include <soc/shared/ft_msg.h>
     17 #include <soc/profile_mem.h>
     18 #include <shared/idxres_fl.h>
     19 #include <bcm/flowtracker.h>
     20 
     21 /* Group Start Id */
     22 #define BCM_INT_FT_GROUP_START_ID 1
     23 
     24 /* Maximum number of flow groups
     25  * TH/TH2 - IFP is used for FT Group hence restricted by MATCHED_RULE 8 bit
     26  *          value in COPY_TO_CPU functionality.
     27  * MV2 - Equal to number of entries in FT_GROUP_TABLE_CONFIGm minus entry
     28  *       with index 0 which is reserved entry.
     29  */
     30 #define BCM_INT_FT_MAX_FLOW_GROUPS \
     31         (soc_feature(unit, soc_feature_mv2_style_flowtracker) ? \
     32         (soc_mem_index_count(unit, FT_GROUP_TABLE_CONFIGm) - 1) : \
     33          255)
     34 
     35 /* Default value for max flows */
     36 #define BCM_INT_FT_DEF_MAX_FLOWS \
     37         soc_feature(unit, soc_feature_mv2_style_flowtracker) ? 32768 : 16384
     38 
     39 /* Default value for max counters per flow */
     40 #define BCM_INT_FT_DEF_MAX_COUNTERS_PER_FLOW  1
     41 
     42 /* Default max export length is 1500 bytes */
     43 #define BCM_INT_FT_DEF_MAX_EXPORT_LENGTH 1500
     44 
     45 /* Maximum number of templates  */
     46 #define BCM_INT_FT_MAX_TEMPLATES 1
     47 
     48 /* Template start Id */
     49 #define BCM_INT_FT_TEMPLATE_START_ID 1
     50 
     51 /* Template end Id */
     52 #define BCM_INT_FT_TEMPLATE_END_ID \
     53     (BCM_INT_FT_TEMPLATE_START_ID + BCM_INT_FT_MAX_TEMPLATES - 1)
     54 
     55 /* Maximum number of collectors. */
     56 #define BCM_INT_FT_MAX_COLLECTORS 1
     57 
     58 /* Collector Start Id */
     59 #define BCM_INT_FT_COLLECTOR_START_ID 1
     60 
     61 /* Collector End Id */
     62 #define BCM_INT_FT_COLLECTOR_END_ID \
     63     (BCM_INT_FT_COLLECTOR_START_ID + BCM_INT_FT_MAX_COLLECTORS - 1)
     64 
     65 /* Maximum number of export_profiles. */
     66 #define BCM_INT_FT_MAX_EXPORT_PROFILES 1
     67 
     68 /* Export_Profile Start Id */
     69 #define BCM_INT_FT_EXPORT_PROFILE_START_ID 1
     70 
     71 /* Export_Profile End Id */
     72 #define BCM_INT_FT_EXPORT_PROFILE_END_ID \
     73     (BCM_INT_FT_EXPORT_PROFILE_START_ID + BCM_INT_FT_MAX_EXPORT_PROFILES - 1)
     74 
     75 /* Valid range of Set_ID is 256 to 65535. 
     76  * Not checking 65535 condition since its satisfied 
     77  * by the fact that set_id is uint16
     78  */
     79 #define BCM_INT_FT_TEMPLATE_SET_ID_VALID(set_id) (set_id >=256)
     80 
     81 /* Set Id used when transmiting template sets */
     82 #define FT_INT_TEMPLATE_XMIT_SET_ID 2
     83 
     84 /* Default value of export interval in elephant mode. 50 ms */
     85 #define BCM_INT_FT_ELPH_DEF_EXPORT_INTERVAL_MSECS (50)
     86 
     87 /* Default value of export interval. 100 ms */
     88 #define BCM_INT_FT_DEF_EXPORT_INTERVAL_MSECS (100)
     89 
     90 /* Default value of scan interval. 100 ms */
     91 #define BCM_INT_FT_DEF_SCAN_INTERVAL_USECS (BCM_INT_FT_DEF_EXPORT_INTERVAL_MSECS * 1000)
     92 
     93 /* Default value of scan interval. 100 ms */
     94 #define BCM_INT_FT_ELPH_DEF_SCAN_INTERVAL_USECS (100 * 1000)
     95 
     96 /* Minimum value of scan interval (2msec) */
     97 #define BCM_INT_FT_ELPH_MIN_SCAN_INTERVAL_USECS (2 * 1000)
     98 
     99 /* Elephant Scan interval must be in steps of 1 msec */
    100 #define BCM_INT_FT_ELPH_SCAN_INTERVAL_STEP_USECS (1 * 1000)
    101 
    102 /* Scan interval must be in steps of 1 msec */
    103 #define BCM_INT_FT_SCAN_INTERVAL_STEP_USECS (1 * 1000)
    104 
    105 /* Max value of scan interval. 500 ms */
    106 #define BCM_INT_FT_MAX_SCAN_INTERVAL_USECS (500 * 1000)
    107 
    108 /* Default value of aging time. 20 secs in milliseconds */
    109 #define BCM_INT_FT_DEF_AGING_INTERVAL_MSECS (20 * 1000)
    110 
    111 /* Aging interval must be in steps of 1 sec */
    112 #define BCM_INT_FT_AGING_INTERVAL_STEP_MSECS (1000)
    113 
    114 /* Aging interval can be up to 255 times scan interval */
    115 #define BCM_INT_FT_AGING_INTERVAL_SCAN_MULTIPLE (255)
    116 
    117 /* Size of the template set header */
    118 #define BCM_INT_FT_SET_HDR_LENGTH 4
    119 
    120 /* Size of the IPFIX header */
    121 #define BCM_INT_FT_IPFIX_MSG_HDR_LENGTH 16
    122 
    123 /* Minimum length of the collecotor encap
    124  * UDP_HDR  =  8 bytes
    125  * IPv4_HDR = 20 bytes
    126  * ETH_HDR  = 14 bytes
    127  * L2_CRC   =  4 bytes
    128  * 8 + 20 + 14 + 4 = 46
    129  */
    130 #define BCM_INT_FT_MIN_COLLECTOR_ENCAP_LENGTH 46
    131 
    132 /* Length of the L2 CRC field */
    133 #define BCM_INT_FT_L2_CRC_LENGTH 4
    134 
    135 /* Rx channel index used by FT EAPP */
    136 #define BCM_INT_FT_EAPP_RX_CHANNEL 1
    137 
    138 /* Maximum number of elephant profiles */
    139 #define BCM_INT_FT_MAX_ELEPHANT_PROFILES 4
    140 
    141 /* Elephant rate thresholds must be configured in steps of 80 kbits/sec */
    142 #define BCM_INT_FT_ELPH_RATE_THRESHOLD_STEP 80
    143 
    144 /* Elephant profile Start Id */
    145 #define BCM_INT_FT_ELPH_PROFILE_START_ID 1
    146 
    147 /* Elephant profile END Id */
    148 #define BCM_INT_FT_ELPH_PROFILE_END_ID \
    149     (BCM_INT_FT_ELPH_PROFILE_START_ID + BCM_INT_FT_MAX_ELEPHANT_PROFILES - 1)
    150 
    151 /* Max number of actions that can be applied on a group */
    152 #define BCM_INT_FT_MAX_GROUP_ACTIONS 5
    153 
    154 /* Max number of params per action */
    155 #define BCM_INT_FT_MAX_GROUP_ACTION_PARAMS 2
    156 
    157 /* Invalid EM group Id */
    158 #define BCM_INT_FT_INVALID_EM_GROUP_ID (-1)
    159 
    160 /*
    161  * Macro:
    162  *     _BCM_FT_ALLOC
    163  * Purpose:
    164  *      Generic memory allocation routine.
    165  * Parameters:
    166  *    _ptr_     - Pointer to allocated memory.
    167  *    _ptype_   - Pointer type.
    168  *    _size_    - Size of heap memory to be allocated.
    169  *    _descr_   - Information about this memory allocation.
    170  */
    171 #define _BCM_FT_ALLOC(_ptr_,_ptype_,_size_,_descr_)                     \
    172             do {                                                         \
    173                 if (NULL == (_ptr_)) {                                   \
    174                    (_ptr_) = (_ptype_ *) sal_alloc((_size_), (_descr_)); \
    175                 }                                                        \
    176                 if((_ptr_) != NULL) {                                    \
    177                     sal_memset((_ptr_), 0, (_size_));                    \
    178                 }  else {                                                \
    179                     LOG_ERROR(BSL_LS_BCM_FLOWTRACKER, \
    180                               (BSL_META("FT Error: Allocation failure %s\n"), \
    181                                (_descr_)));                              \
    182                 }                                                        \
    183             } while (0)
    184 
    185 /* Max number of parts the actions is divided in H/w */
    186 #define BCM_INT_FT_ACTION_MAX_PARTS 2
    187 
    188 /* Minimum of 2 values */
    189 #define _BCM_FT_MIN(a,b) ((a) < (b) ? (a) : (b))
    190 
    191 
    192 /* Group actions width, offset linked list */
    193 typedef struct _bcm_int_ft_action_offset_s {
    194     /* Offset into the H/w buffer */
    195     uint16 offset[BCM_INT_FT_ACTION_MAX_PARTS];
    196 
    197     /* Width of the action*/
    198     uint8 width[BCM_INT_FT_ACTION_MAX_PARTS];
    199 
    200     /* Value that needs to be programmed */
    201     uint8 value[BCM_INT_FT_ACTION_MAX_PARTS];
    202 
    203 } _bcm_int_ft_action_offset_t;
    204 
    205 /* Flowtracker Internal action types */
    206 typedef enum _bcm_ft_action_e {
    207     /* Change color of green packets */
    208     _bcmIntFtActionGpDropPrecedence = 0,
    209 
    210     /* Change color of yellow packets */
    211     _bcmIntFtActionYpDropPrecedence = 1,
    212 
    213     /* Change color of red packets */
    214     _bcmIntFtActionRpDropPrecedence = 2,
    215 
    216     /* Assign new Unicast cosq for Green packets */
    217     _bcmIntFtActionGpUcastCosQNew = 3,
    218 
    219     /* Assign new Unicast cosq for Yellow packets */
    220     _bcmIntFtActionYpUcastCosQNew = 4,
    221 
    222     /* Assign new Unicast cosq for Red packets */
    223     _bcmIntFtActionRpUcastCosQNew = 5,
    224 
    225     /* Assign new Multicast cosq for Green packets */
    226     _bcmIntFtActionGpMcastCosQNew = 6,
    227 
    228     /* Assign new Multicast cosq for Yellow packets */
    229     _bcmIntFtActionYpMcastCosQNew = 7,
    230 
    231     /* Assign new Multicast cosq for Red packets */
    232     _bcmIntFtActionRpMcastCosQNew = 8,
    233 
    234     /* Assign new Unicast & Multicast cosq for Green packets */
    235     _bcmIntFtActionGpCosQNew = 9,
    236 
    237     /* Assign new Unicast & Multicast cosq for Yellow packets */
    238     _bcmIntFtActionYpCosQNew = 10,
    239 
    240     /* Assign new Unicast & Multicast cosq for Red packets */
    241     _bcmIntFtActionRpCosQNew = 11,
    242 
    243     /* Change int_pri for Green packets */
    244     _bcmIntFtActionGpPrioIntNew = 12,
    245 
    246     /* Change int_pri for Yellow packets */
    247     _bcmIntFtActionYpPrioIntNew = 13,
    248 
    249     /* Change int_pri for Red packets */
    250     _bcmIntFtActionRpPrioIntNew = 14,
    251 
    252     /* First Seen INT Packet */
    253     _bcmIntFtFspReinjectActionIntNew = 15,
    254 
    255     /* Monitor flows Dropped packet */
    256     _bcmIntFtDropMonitorActionIntNew = 16,
    257 
    258     /* Last value, not usable */
    259     _bcmIntFtActionCount
    260 } _bcm_ft_action_t;
    261 
    262 /* Actions info internal */
    263 typedef struct _bcm_int_ft_action_info_s {
    264     /* Action element */
    265     _bcm_ft_action_t action;
    266 
    267     /* param0 */
    268     uint32 param0;
    269 
    270 } _bcm_int_ft_action_info_t;
    271 
    272 /* Group actions info */
    273 typedef struct _bcm_int_ft_group_action_info_s {
    274     /* Action */
    275     bcm_flowtracker_group_action_t action;
    276 
    277     /* Number of params */
    278     int num_params;
    279 
    280     /* Params */
    281     uint32 params[BCM_INT_FT_MAX_GROUP_ACTION_PARAMS];
    282 } _bcm_int_ft_group_action_info_t;
    283 
    284 /* Per pipe information. */
    285 typedef struct  _bcm_int_ft_pipe_info_s {
    286     /* Max flows */
    287     uint32 max_flows;
    288 
    289     /* Size of reserved pools */
    290     uint16 ctr_pool_size[SHR_FT_MAX_CTR_POOLS];
    291 
    292     /* Reserved Flex counter pools per pipe */
    293     uint8 ctr_pools[SHR_FT_MAX_CTR_POOLS];
    294 
    295     /* Number of reserved counter pools */
    296     uint8 num_ctr_pools;
    297 
    298     /* QoS profile mem ptr */
    299     soc_profile_mem_t *qos_profile_mem;
    300 } _bcm_int_ft_pipe_info_t;
    301 
    302 #define BCM_INT_FT_INFO_FLAGS_FLOW_START_TS (1 << 0)
    303 #define BCM_INT_FT_INFO_FLAGS_DROP_MONITOR  (1 << 1)
    304 
    305 
    306 /* Internal data structure to store
    307  * global flowtracker information.
    308  */
    309 typedef struct _bcm_int_flowtracker_info_s {
    310     /* Elephant mode */
    311     uint8 elph_mode;
    312 
    313     /* Flow Tracker Config Mode */
    314     uint8 ft_config_mode;
    315 
    316     /* Configuration mode */
    317     shr_ft_cfg_modes_t cfg_mode;
    318 
    319     /* Features supported by the EApp */
    320     uint32 uc_features;
    321 
    322     /* flags, See BCM_INT_FT_INFO_FLAGS_XXX */
    323     uint32 flags;
    324 
    325     /* Max number of flow groups.
    326      * Got from soc property flowtracker_max_flow_groups
    327      */
    328     uint32 max_flow_groups;
    329     /* Max number of flows for entire switch.
    330      * Just a summation of max_flows_per_pipe for all pipes.
    331      */
    332     uint32 max_flows_total;
    333     /* The maximum MTU size that is possible for export
    334      * packets.
    335      * Got from soc property flowtracker_max_export_pkt_length
    336      */
    337     uint16 max_export_pkt_length;
    338     /* IPFIX observation domain Id */
    339     bcm_flowtracker_ipfix_observation_domain_t observation_domain_id;
    340     /* DMA Buffer used for messaging between SDK and
    341      * UKERNEL.
    342      */
    343     uint8 *dma_buffer;
    344     /* Length of the DMA buffer */
    345     int dma_buffer_len;
    346     /* Template ID pool */
    347     shr_idxres_list_handle_t template_pool;
    348     /* Collector ID pool */
    349     shr_idxres_list_handle_t collector_pool;
    350     /* Export profile ID pool */
    351     shr_idxres_list_handle_t export_profile_pool;
    352     /* Flow group ID pool */
    353     shr_idxres_list_handle_t flow_group_pool;
    354     /* Flow group ID pool */
    355     shr_idxres_list_handle_t elph_profile_pool;
    356     /* Number of pipes. */
    357     uint8 num_pipes; 
    358     /* Per pipe information. */
    359     _bcm_int_ft_pipe_info_t pipe_info[BCM_PIPES_MAX];
    360 
    361     /* Enterprise Number */
    362     uint32 enterprise_number;
    363 
    364     /* Export interval (msecs) */
    365     uint32 export_interval;
    366 
    367     /* Scan interval (usecs) */
    368     uint32 scan_interval_usecs;
    369 
    370     /* Maximum length of the reinjected FSP packet */
    371     uint16 fsp_reinject_max_length;
    372 
    373     /* Default group ID */
    374     uint16 default_grp_id;
    375 
    376     /* EM groups Mapping */
    377     int  em_group_id_map[SHR_FT_MAX_EM_GROUPS][BCM_PIPES_MAX];
    378 
    379 } _bcm_int_ft_info_t;
    380 
    381 
    382 /* Internal data structure to store the information element data, used in
    383  * template set export
    384  */
    385 typedef struct _bcm_int_ft_info_elem_s {
    386     /* Export element */
    387     shr_ft_template_info_elem_t element;
    388 
    389     /* Size of each element */
    390     uint16 data_size;
    391 
    392     /* Id corresponding to the export element, IANA assigned for
    393      * non-enterprise
    394      */
    395     uint16 id;
    396 
    397     /* 1 - Enterprise element, 0 - Non enterprise element */
    398     uint8 enterprise;
    399 } _bcm_int_ft_export_element_t;
    400 
    401 /* Internal data structure to store per export template
    402  * information.
    403  */
    404 typedef struct _bcm_int_ft_export_template_info_s {
    405     /* Software ID of the template */
    406     bcm_flowtracker_export_template_t template_id;
    407     /* Set ID that is put into the IPFIX packet */
    408     uint16 set_id;
    409     /* Template set transmit interval */
    410     int interval_secs;
    411     /* Number of packets sent out initially */
    412     int initial_burst;
    413     /* Number of information elements */
    414     int num_export_elements;
    415     /* Export elements */
    416     _bcm_int_ft_export_element_t elements[SHR_FT_TEMPLATE_MAX_INFO_ELEMENTS];
    417 } _bcm_int_ft_export_template_info_t;
    418 
    419 
    420 /* Internal data structure to store per collector information
    421  */
    422 typedef struct _bcm_int_ft_collector_info_s {
    423     /* Software ID of the collector */
    424     bcm_flowtracker_collector_t collector_id;
    425     /* Collector information structure */
    426     bcm_flowtracker_collector_info_t collector_info;
    427 } _bcm_int_ft_collector_info_t;
    428 
    429 typedef struct _bcm_int_ft_v2_collector_info_s {
    430     /* Internal Collector Id */
    431     int int_id;
    432 } _bcm_int_ft_v2_collector_info_t;
    433 
    434 typedef struct _bcm_int_ft_v2_export_profile_info_s {
    435     /* Internal Export_Profile Id */
    436     int int_id;
    437 } _bcm_int_ft_v2_export_profile_info_t;
    438 
    439 /* Internal data structure to store per flow_group information
    440  */
    441 typedef struct _bcm_int_ft_flow_group_info_s {
    442     /* Software ID of the flow_group */
    443     bcm_flowtracker_group_t flow_group_id;
    444     /* Aging interval in msecs */
    445     uint32 aging_interval_msecs;
    446     /* Max flows that can be learned on this group */
    447     uint32  flow_limit;
    448     /* Collector associated with the flow group */
    449     int collector_id;
    450     /* Collector associated with the flow group */
    451     int export_profile_id;
    452     /* Template associated with the flow group */
    453     uint16 template_id;
    454 
    455     /* Elephant profle Id */
    456     bcm_flowtracker_elephant_profile_t elph_profile_id;
    457 
    458     /* QoS profile Id */
    459     uint32 qos_profile_id;
    460 
    461     /* Number of actions on the group */
    462     uint16 num_actions;
    463 
    464     _bcm_int_ft_group_action_info_t *action_list;
    465 
    466     /* Export triggers which will result in the export of the packets */
    467     uint32    export_trigger;
    468 
    469     /* Field group corresponding to the flow group. */
    470     bcm_field_group_t field_group[BCM_PIPES_MAX];
    471 
    472     /* Number of Tracking Params on the group */
    473     int num_tracking_params;
    474 
    475     bcm_flowtracker_tracking_param_info_t *tracking_params;
    476 
    477 } _bcm_int_ft_flow_group_info_t;
    478 
    479 
    480 /* Internal data structure to store elephant profile info
    481  */
    482 typedef struct _bcm_int_ft_elph_profile_info_s {
    483     /* Software Id of the profile */
    484     bcm_flowtracker_elephant_profile_t id;
    485 
    486     /* Profile information structure */
    487     bcm_flowtracker_elephant_profile_info_t profile;
    488 } _bcm_int_ft_elph_profile_info_t;
    489 
    490 /* Global data structures extern declarations */
    491 extern _bcm_int_ft_info_t *ft_global_info[BCM_MAX_NUM_UNITS];
    492 
    493 /* Utility functions */
    494 extern int
    495 _bcm_esw_flowtracker_ucast_cosq_resolve(int unit, uint32 cosq, int *hw_cosq);
    496 
    497 extern int
    498 _bcm_esw_flowtracker_mcast_cosq_resolve(int unit, uint32 cosq, int *hw_cosq);
    499 
    500 /* Get the FT_INFO struct for the unit */
    501 #define FT_INFO_GET(_u) ft_global_info[(_u)]
    502 
    503 
    504 extern void _bcm_esw_flowtracker_sw_dump(int unit);
    505 extern void _bcm_esw_flowtracker_dump_stats_learn(int unit);
    506 extern void _bcm_esw_flowtracker_dump_stats_export(int unit);
    507 extern void _bcm_esw_flowtracker_dump_stats_age(int unit);
    508 extern void _bcm_esw_flowtracker_dump_stats_elephant(int unit);
    509 
    510 #endif /* INCLUDE_FLOWTRACKER */
    511 
    512 extern int _bcm_esw_flowtracker_sync(int unit);
    513 
    514 
    515 #endif  /* !_BCM_INT_FT_H_ */