flowcnt.h (8341B)
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: flowcnt.h 8 * Purpose: 9 */ 10 #ifndef _BCM_INT_FLOWCNT_H_ 11 #define _BCM_INT_FLOWCNT_H_ 12 13 #include <soc/drv.h> 14 #include <soc/mem.h> 15 #include <soc/profile_mem.h> 16 #include <shared/idxres_afl.h> 17 #include <bcm/error.h> 18 19 20 /* ****************************************************************** */ 21 /* COMPOSITION OF STAT COUNTER ID */ 22 /* ****************************************************************** */ 23 /* mode_id = Max 3 bits (Total Eight modes) */ 24 /* group_mode_id = Max 5 bits (Total 32) */ 25 /* pool_id = 4 (Max Pool:16) */ 26 /* a/c object_id=4 (Max Object:32) */ 27 /* 15 bits for base index */ 28 /* 000 0-0000 0000 -00000 000-0000 0000-0000 */ 29 /* Mode3b Group5b Pool4b -A/cObj4b base-index */ 30 /* **************************************************************** */ 31 #define _BCM_FLOWCNT_MODE_START_BIT 29 32 #define _BCM_FLOWCNT_MODE_END_BIT 31 33 #define _BCM_FLOWCNT_GROUP_START_BIT 24 34 #define _BCM_FLOWCNT_GROUP_END_BIT 28 35 #define _BCM_FLOWCNT_POOL_START_BIT 20 36 #define _BCM_FLOWCNT_POOL_END_BIT 23 37 #define _BCM_FLOWCNT_OBJECT_START_BIT 15 38 #define _BCM_FLOWCNT_OBJECT_END_BIT 19 39 #define _BCM_FLOWCNT_BASE_IDX_START_BIT 0 40 #define _BCM_FLOWCNT_BASE_IDX_END_BIT 13 41 42 #define _BCM_FLOWCNT_MODE_MASK \ 43 ((1<<(_BCM_FLOWCNT_MODE_END_BIT - _BCM_FLOWCNT_MODE_START_BIT+1))-1) 44 #define _BCM_FLOWCNT_GROUP_MASK \ 45 ((1<<(_BCM_FLOWCNT_GROUP_END_BIT - _BCM_FLOWCNT_GROUP_START_BIT+1))-1) 46 #define _BCM_FLOWCNT_POOL_MASK \ 47 ((1<<(_BCM_FLOWCNT_POOL_END_BIT - _BCM_FLOWCNT_POOL_START_BIT+1))-1) 48 #define _BCM_FLOWCNT_OBJECT_MASK \ 49 ((1<<(_BCM_FLOWCNT_OBJECT_END_BIT - _BCM_FLOWCNT_OBJECT_START_BIT+1))-1) 50 #define _BCM_FLOWCNT_BASE_IDX_MASK \ 51 ((1<<(_BCM_FLOWCNT_BASE_IDX_END_BIT-_BCM_FLOWCNT_BASE_IDX_START_BIT+1))-1) 52 53 typedef enum _bcm_flowcnt_stat_type_e { 54 bcmFlowcntStatTypePacket = 1, 55 bcmFlowcntStatTypeByte = 2 56 }_bcm_flowcnt_stat_type_t; 57 58 typedef struct _bcm_flowcnt_group_mode_attr_selector_s { 59 uint32 counter_offset; /* Counter Offset */ 60 bcm_stat_group_mode_attr_t attr; /* Attribute Selector */ 61 uint32 attr_value; /* Attribute Values */ 62 }_bcm_flowcnt_group_mode_attr_selector_t; 63 64 typedef struct _bcm_esw_flowcnt_profile_group_s { 65 uint32 available; 66 uint32 reference_count; 67 uint32 total_counters; 68 bcm_stat_group_mode_t group_mode; 69 uint32 flags; 70 uint32 num_selectors; 71 _bcm_flowcnt_group_mode_attr_selector_t *attr_selectors; 72 }_bcm_esw_flowcnt_profile_group_t; 73 74 typedef struct _bcm_esw_flowcnt_profile_s { 75 soc_profile_mem_t profile_mem; 76 soc_mem_t profile_table; 77 bcm_stat_group_mode_attr_t attr; 78 bcm_stat_flex_direction_t direction; 79 int num_entries; /* numbers of entries per group */ 80 int num_groups; /* numbers of group per profile */ 81 _bcm_esw_flowcnt_profile_group_t *flowcnt_group; 82 }_bcm_esw_flowcnt_profile_t; 83 84 typedef struct _bcm_esw_flowcnt_pool_stat_s { 85 uint32 used_entries; 86 uint32 attached_entries; 87 }_bcm_esw_flowcnt_pool_stat_t; 88 89 typedef struct _bcm_esw_flowcnt_pool_s { 90 soc_mem_t mem; 91 shr_aidxres_list_handle_t flowcnt_aidxres_list_handle; 92 uint32 *flow_packet_counter; 93 uint64 *flow_byte_counter; 94 uint64 *flow_packet64_counter; 95 uint16 *flow_base_index_reference_count; 96 uint16 *associate_profile_group; 97 _bcm_flowcnt_stat_type_t *flow_stat_type; 98 bcm_stat_object_t *object; 99 _bcm_esw_flowcnt_pool_stat_t pool_stat; 100 }_bcm_esw_flowcnt_pool_t; 101 102 typedef struct _bcm_flowcnt_control_s { 103 int init; 104 sal_mutex_t flowcnt_mutex; 105 uint32 *default_attr_mode_id; 106 /* chip specific */ 107 _bcm_esw_flowcnt_profile_t *flowcnt_profile; 108 int num_profiles; 109 _bcm_esw_flowcnt_pool_t *flowcnt_pool; 110 int num_pools; 111 int counter_block; /* max counter offset value in power of two */ 112 }_bcm_esw_flowcnt_control_t; 113 114 115 typedef enum _bcm_flowcnt_group_mode_e { 116 bcmFlowcntProfileGroup1 = bcmStatGroupModeCount, 117 bcmFlowcntProfileGroup2, 118 bcmFlowcntProfileGroup3, 119 bcmFlowcntProfileGroup4 120 }_bcm_flowcnt_group_mode_t; 121 122 123 #define _BCM_STAT_FLOWCNT_MAX_PROFILES (2) 124 #define _BCM_STAT_FLOWCNT_MAX_PROFILE_GROUP (4) 125 #define _BCM_STAT_FLOWCNT_MAX_SELECTORS (16) 126 127 #ifdef BCM_WARM_BOOT_SUPPORT 128 typedef struct _bcm_flowcnt_warmboot_info_s { 129 uint32 default_attr_mode_id[bcmStatGroupModeAttrMaxValue]; 130 }_bcm_flowcnt_warmboot_info_t; 131 132 typedef struct _bcm_flowcnt_warmboot_group_info_s { 133 uint32 group_mode; 134 uint32 flags; 135 uint32 total_counters; 136 uint32 num_selectors; 137 _bcm_flowcnt_group_mode_attr_selector_t attr_selectors 138 [_BCM_STAT_FLOWCNT_MAX_SELECTORS]; 139 }_bcm_flowcnt_warmboot_group_info_t; 140 #endif 141 142 extern int _bcm_esw_flowcnt_init(int unit); 143 extern int _bcm_esw_flowcnt_cleanup(int unit); 144 extern int _bcm_esw_flowcnt_group_create(int unit, bcm_stat_object_t object, 145 bcm_stat_group_mode_t group_mode, uint32 *stat_counter_id, 146 uint32 *num_entries); 147 extern int _bcm_esw_flowcnt_object_table_attach(int unit, 148 bcm_stat_object_t object, soc_mem_t table, uint32 index, 149 int profile_group, uint32 base_idx, uint32 pool_idx, 150 void *entry_data1); 151 extern void _bcm_esw_flowcnt_counter_id_get(uint32 stat_counter_id, 152 bcm_stat_group_mode_t *group, bcm_stat_object_t *object, 153 uint32 *profile_group, uint32 *pool_idx, 154 uint32 *base_idx); 155 extern int _bcm_esw_flowcnt_counter_set(int unit, uint32 index, 156 soc_mem_t table, uint32 byte_flag, uint32 counter_index, 157 bcm_stat_value_t *value); 158 extern int _bcm_esw_flowcnt_counter_get(int unit, int sync_mode, 159 uint32 index, soc_mem_t table, uint32 byte_flag, 160 uint32 counter_index, bcm_stat_value_t *value); 161 extern int _bcm_esw_flowcnt_group_mode_id_create(int unit, uint32 flags, 162 uint32 total_counters, uint32 num_selectors, 163 bcm_stat_group_mode_attr_selector_t *attr_selectors, 164 uint32 *mode_id); 165 extern int _bcm_esw_flowcnt_group_mode_id_get(int unit, uint32 mode_id, 166 uint32 *flags, uint32 *total_counters, 167 uint32 num_selectors, 168 bcm_stat_group_mode_attr_selector_t *attr_selectors, 169 uint32 *actual_num_selectors); 170 extern int _bcm_esw_flowcnt_group_mode_id_destroy(int unit, uint32 mode_id); 171 extern int _bcm_esw_flowcnt_custom_group_create(int unit, uint32 mode_id, 172 bcm_stat_object_t object, uint32 *stat_counter_id, 173 uint32 *num_entries); 174 extern int _bcm_esw_flowcnt_object_table_detach(int unit, soc_mem_t ingress_table, 175 uint32 index); 176 extern int _bcm_esw_flowcnt_stat_id_get(int unit, soc_mem_t mem, int index, 177 uint32 *stat_counter_id); 178 extern int _bcm_esw_flowcnt_stat_type_validate(int unit, soc_mem_t table, 179 int index, _bcm_flowcnt_stat_type_t flow_stat_type); 180 extern int _bcm_esw_flowcnt_group_destroy(int unit, uint32 stat_counter_id); 181 extern int _bcm_esw_flowcnt_group_dump_info(int unit, int all_flag, 182 bcm_stat_object_t object, bcm_stat_group_mode_t group); 183 extern int _bcm_esw_flowcnt_counter_raw_set(int unit, 184 uint32 stat_counter_id, uint32 byte_flag, 185 uint32 counter_index, bcm_stat_value_t *value); 186 extern int _bcm_esw_flowcnt_counter_raw_get(int unit, int sync_mode, 187 uint32 stat_counter_id, uint32 byte_flag, 188 uint32 counter_index, bcm_stat_value_t *value); 189 extern int _bcm_esw_flowcnt_total_counters_get(int unit, 190 uint32 stat_counter_id, uint32 *total_counters); 191 192 #ifdef BCM_WARM_BOOT_SUPPORT 193 extern int _bcm_esw_flowcnt_sync(int unit); 194 #endif 195 #endif /* !_BCM_INT_FLOWCNT_H_ */