stat.h (14883B)
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 STAT definitions internal to the BCM library. 8 */ 9 10 #ifndef _BCM_INT_STAT_H 11 #define _BCM_INT_STAT_H 12 13 #include <bcm/stat.h> 14 15 /* 16 * Utility routines for statistics accumulation 17 */ 18 19 /* The REG_* macros require the following declaration in any function which 20 * uses them: 21 */ 22 23 #define REG_MATH_DECL \ 24 uint64 reg_val 25 26 #define _BCM_SYNC_MODE_NO_SYNC 0 /* No hardware sync. */ 27 #define _BCM_SYNC_MODE_SYNC 1 /* sync hardware and update cache. */ 28 #define _BCM_SYNC_MODE_NO_CACHE 2 /* sync hardware and no cache update. */ 29 30 #define REG_ADD(unit, port, sync_mode, reg, val) \ 31 if (SOC_REG_IS_COUNTER_TABLE(unit, reg) || \ 32 (SOC_REG_IS_VALID(unit, reg) && SOC_REG_IS_COUNTER(unit, reg))) { \ 33 if (sync_mode == _BCM_SYNC_MODE_NO_CACHE) { \ 34 SOC_IF_ERROR_RETURN(soc_counter_direct_get(unit, port, reg, \ 35 0, ®_val)); \ 36 } else if (sync_mode) { \ 37 SOC_IF_ERROR_RETURN(soc_counter_sync_get(unit, port, reg, \ 38 0, ®_val)); \ 39 } else { \ 40 SOC_IF_ERROR_RETURN(soc_counter_get(unit, port, reg, \ 41 0, ®_val)); \ 42 } \ 43 COMPILER_64_ADD_64(val, reg_val); \ 44 } 45 #define REG_ADD_IDX(unit, port, sync_mode, reg, val, ar_idx) \ 46 if (SOC_REG_IS_COUNTER_TABLE(unit, reg) || \ 47 (SOC_REG_IS_VALID(unit, reg) && SOC_REG_IS_COUNTER(unit, reg))) { \ 48 if (sync_mode) { \ 49 SOC_IF_ERROR_RETURN(soc_counter_sync_get(unit, port, reg, \ 50 ar_idx, ®_val)); \ 51 } else { \ 52 SOC_IF_ERROR_RETURN(soc_counter_get(unit, port, reg, \ 53 ar_idx, ®_val)); \ 54 } \ 55 COMPILER_64_ADD_64(val, reg_val); \ 56 } 57 #define REG_SUB(unit, port, sync_mode, reg, val) \ 58 if (SOC_REG_IS_COUNTER_TABLE(unit, reg) || \ 59 (SOC_REG_IS_VALID(unit, reg) && SOC_REG_IS_COUNTER(unit, reg))) { \ 60 if (sync_mode) { \ 61 SOC_IF_ERROR_RETURN(soc_counter_sync_get(unit, port, reg, \ 62 0, ®_val)); \ 63 } else { \ 64 SOC_IF_ERROR_RETURN(soc_counter_get(unit, port, reg, \ 65 0, ®_val)); \ 66 } \ 67 if (COMPILER_64_GT(val, reg_val)) { \ 68 COMPILER_64_SUB_64(val, reg_val); \ 69 } else { \ 70 COMPILER_64_ZERO(val); \ 71 } \ 72 } 73 #define REG_SUB_IDX(unit, port, sync_mode, reg, val, ar_idx) \ 74 if (SOC_REG_IS_COUNTER_TABLE(unit, reg) || \ 75 (SOC_REG_IS_VALID(unit, reg) && SOC_REG_IS_COUNTER(unit, reg))) { \ 76 if (sync_mode) { \ 77 SOC_IF_ERROR_RETURN(soc_counter_sync_get(unit, port, reg, \ 78 ar_idx, ®_val)); \ 79 } else { \ 80 SOC_IF_ERROR_RETURN(soc_counter_get(unit, port, reg, \ 81 ar_idx, ®_val)); \ 82 } \ 83 COMPILER_64_SUB_64(val, reg_val); \ 84 } 85 #define REG_CLEAR(unit, port, reg, val) \ 86 if (SOC_REG_IS_COUNTER_TABLE(unit, reg) || \ 87 (SOC_REG_IS_VALID(unit, reg) && SOC_REG_IS_COUNTER(unit, reg))) { \ 88 SOC_IF_ERROR_RETURN(soc_counter_clear_by_port_reg(unit, \ 89 port, reg, \ 90 0, val)); \ 91 } 92 #define REG_CLEAR_IDX(unit, port, sync_mode, reg, val, ar_idx) \ 93 if (SOC_REG_IS_COUNTER_TABLE(unit, reg) || \ 94 (SOC_REG_IS_VALID(unit, reg) && SOC_REG_IS_COUNTER(unit, reg))) { \ 95 SOC_IF_ERROR_RETURN(soc_counter_clear_by_port_reg(unit, \ 96 port, reg, \ 97 ar_idx, \ 98 val)); \ 99 } 100 101 #define BCM_STAT_REG_OPER(unit, port, sync_mode, reg_op, ctr_reg, val) \ 102 BCM_IF_ERROR_RETURN (_bcm_stat_reg_op(unit, port, sync_mode, reg_op, ctr_reg, val)) 103 104 #define BCM_STAT_GENERIC_REG_OPER(unit, port, sync_mode, reg_op, ctr_reg, val) \ 105 if (soc_feature(unit, soc_feature_cxl_mib) || \ 106 soc_feature(unit, soc_feature_cd_mib)) { \ 107 soc_reg_t ctr_reg_adj = ctr_reg##r; \ 108 \ 109 if (IS_CL_PORT(unit, port)) { \ 110 if (SOC_REG_IS_VALID(unit, CLMIB_##ctr_reg##r)) { \ 111 ctr_reg_adj = CLMIB_##ctr_reg##r; \ 112 } \ 113 } else if (IS_XL_PORT(unit, port)) { \ 114 if (SOC_REG_IS_VALID(unit, XLMIB_##ctr_reg##r)) { \ 115 ctr_reg_adj = XLMIB_##ctr_reg##r; \ 116 } \ 117 } else if (IS_CD_PORT(unit, port)) { \ 118 if (SOC_REG_IS_COUNTER_TABLE(unit, CDMIB_##ctr_reg##f + \ 119 SOC_COUNTER_TABLE_FIELD_START)) { \ 120 ctr_reg_adj = CDMIB_##ctr_reg##f + SOC_COUNTER_TABLE_FIELD_START; \ 121 } \ 122 } \ 123 BCM_STAT_REG_OPER(unit, port, sync_mode, reg_op, ctr_reg_adj, val); \ 124 } else { \ 125 BCM_STAT_REG_OPER(unit, port, sync_mode, reg_op, ctr_reg##r, val); \ 126 } 127 128 #define BCM_STAT_GENERIC_REG_VALIDATE(unit, port, ctr, valid) \ 129 if (soc_feature(unit, soc_feature_cxl_mib) || \ 130 soc_feature(unit, soc_feature_cd_mib)) { \ 131 valid = FALSE; \ 132 if (IS_CL_PORT(unit, port)) { \ 133 if (SOC_REG_IS_VALID(unit, CLMIB_##ctr##r)) { \ 134 valid = TRUE; \ 135 } \ 136 } else if (IS_XL_PORT(unit, port)) { \ 137 if (SOC_REG_IS_VALID(unit, XLMIB_##ctr##r)) { \ 138 valid = TRUE; \ 139 } \ 140 } else if (IS_CD_PORT(unit, port)) { \ 141 if (SOC_REG_IS_COUNTER_TABLE(unit, CDMIB_##ctr##f + \ 142 SOC_COUNTER_TABLE_FIELD_START)) { \ 143 valid = TRUE; \ 144 } \ 145 } \ 146 } else { \ 147 valid = FALSE; \ 148 if (SOC_REG_IS_VALID(unit, ctr##r)) { \ 149 valid = TRUE; \ 150 } \ 151 } 152 153 /* 154 * For collecting addition non-DMA counters, unlike the non-DMA counter 155 * in the soc_counter_non_dma_t, the counters collected here are not shown 156 * in "show counter" command. 157 */ 158 enum { 159 _BCM_STAT_EXTRA_COUNTER_EGRDROPPKTCOUNT = 0, 160 _BCM_STAT_EXTRA_COUNTER_COUNT 161 }; 162 163 typedef enum _bcm_stat_oper_e { 164 _BCM_STAT_GET, 165 _BCM_STAT_CLEAR 166 }_bcm_stat_oper_t; 167 168 typedef enum _bcm_stat_reg_oper_e { 169 _BCM_STAT_REG_ADD, 170 _BCM_STAT_REG_SUB, 171 _BCM_STAT_REG_CLEAR 172 }_bcm_stat_reg_oper_t; 173 174 typedef struct _bcm_stat_extra_counter_s { 175 soc_reg_t reg; 176 uint32 *ctr_prev; 177 uint64 *count64; 178 } _bcm_stat_extra_counter_t; 179 180 /* Oversize packet error control */ 181 extern SHR_BITDCL *_bcm_stat_ovr_control; 182 183 #define COUNT_OVR_ERRORS(unit) \ 184 (soc_feature(unit, soc_feature_stat_jumbo_adj) && \ 185 ((_bcm_stat_ovr_control != NULL) && \ 186 (SHR_BITGET(&_bcm_stat_ovr_control[(unit)],(port))))) 187 188 /* Oversize packet size threshold accessor functions */ 189 extern int _bcm_esw_stat_ovr_threshold_set(int unit, bcm_port_t port, int value); 190 extern int _bcm_esw_stat_ovr_threshold_get(int unit, bcm_port_t port, int *value); 191 extern int _bcm_esw_stat_ovr_error_control_set(int unit, bcm_port_t port, int value); 192 extern int _bcm_esw_stat_ovr_error_control_get(int unit, bcm_port_t port, int *value); 193 194 extern int 195 _bcm_stat_reg_op(int unit, bcm_port_t port, 196 int sync_mode, int reg_op, 197 soc_reg_t ctr_reg, uint64 *val); 198 extern int 199 _bcm_stat_reg_idx_op(int unit, bcm_port_t port, 200 int sync_mode, int reg_op, 201 soc_reg_t ctr_reg, int ar_idx, 202 uint64 *val); 203 204 205 /* Library-private functions exported from stat_fe.c */ 206 207 extern int _bcm_stat_fe_get_set(int unit, bcm_port_t port, 208 int sync_mode, int stat_op, 209 bcm_stat_val_t type, uint64 *val); 210 211 /* Library-private functions exported from stat_ge.c */ 212 213 extern int _bcm_stat_ge_get_set(int unit, bcm_port_t port, int sync_mode, 214 int stat_op, bcm_stat_val_t type, 215 uint64 *val, int incl_non_ge_stat); 216 217 /* Library-private functions exported from stat_xe.c */ 218 219 extern int _bcm_stat_xe_get_set(int unit, bcm_port_t port, 220 int sync_mode, int stat_op, 221 bcm_stat_val_t type, uint64 *val); 222 223 /* Library-private functions exported from stat_hg.c */ 224 225 extern int _bcm_stat_hg_get_set(int unit, bcm_port_t port, 226 int sync_mode, int stat_op, 227 bcm_stat_val_t type, uint64 *val); 228 229 /* Library-private functions exported from stat_generic.c */ 230 231 extern int _bcm_stat_generic_get_set(int unit, bcm_port_t port, 232 int sync_mode, int stat_op, 233 bcm_stat_val_t type, uint64 *val); 234 235 /* Library-private functions exported from stat_mxq.c */ 236 extern int _bcm_stat_mxq_get_set(int unit, bcm_port_t port, int sync_mode, 237 int stat_op, 238 bcm_stat_val_t type, uint64 *val); 239 240 /* Library-private functions exported from stat_clmib.c */ 241 extern int bcmi_stat_clmib_get_set(int unit, bcm_port_t port, 242 int sync_mode, int stat_op, 243 bcm_stat_val_t type, uint64 *val); 244 245 /* Library-private functions exported from stat_preempt.c */ 246 extern int bcmi_stat_preempt_ge_get_set(int unit, bcm_port_t port, 247 int sync_mode, int stat_op, 248 bcm_stat_val_t type, uint64 *val, int incl_non_ge_stat); 249 250 extern int bcmi_stat_preempt_xl_get_set(int unit, bcm_port_t port, 251 int sync_mode, int stat_op, 252 bcm_stat_val_t type, uint64 *val); 253 254 extern int bcmi_stat_preempt_get_set(int unit, bcm_port_t port, 255 int sync_mode, int stat_op, 256 bcm_stat_val_t type, uint64 *val); 257 258 extern int _bcm_stat_counter_extra_get(int unit, soc_reg_t reg, 259 soc_port_t port, uint64 *val); 260 extern int _bcm_stat_counter_non_dma_extra_get(int unit, 261 soc_counter_non_dma_id_t non_dma_id, 262 soc_port_t port, 263 uint64 *val); 264 extern int _bcm_esw_stat_detach(int unit); 265 extern int _bcm_esw_stat_sync(int unit); 266 267 /* Stat chunks for warm-boot functionality */ 268 #ifdef BCM_WARM_BOOT_SUPPORT 269 #define _BCM_STAT_WARM_BOOT_CHUNK_PORTS 0 270 #define _BCM_STAT_WARM_BOOT_CHUNK_FLEX 1 271 extern int _bcm_esw_stat_sync_version_above_equal(int unit,uint16 version); 272 extern int _bcm_esw_stat_sync_version_below_equal(int unit,uint16 version); 273 #endif 274 275 #ifdef BCM_WARM_BOOT_SUPPORT_SW_DUMP 276 extern void _bcm_stat_sw_dump(int unit); 277 #endif /* BCM_WARM_BOOT_SUPPORT_SW_DUMP */ 278 279 extern void _bcm_stat_flexctr_pool_info_sw_dump(int unit); 280 281 #endif /* !_BCM_INT_STAT_H */