stat.c (6852B)
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: bcmx/stat.c 8 * Purpose: BCMX Port Statistics APIs 9 */ 10 11 #include <bcm/types.h> 12 13 #include <bcmx/stat.h> 14 #include <bcmx/lport.h> 15 #include <bcmx/bcmx.h> 16 17 #include "bcmx_int.h" 18 19 #define BCMX_STAT_INIT_CHECK BCMX_READY_CHECK 20 21 #define BCMX_STAT_ERROR_CHECK(_unit, _check, _rv) \ 22 BCMX_ERROR_CHECK(_unit, _check, _rv) 23 24 25 /* 26 * Function: 27 * bcmx_stat_init 28 */ 29 30 int 31 bcmx_stat_init(void) 32 { 33 int rv = BCM_E_UNAVAIL, tmp_rv; 34 int i, bcm_unit; 35 36 BCMX_STAT_INIT_CHECK; 37 38 BCMX_UNIT_ITER(bcm_unit, i) { 39 tmp_rv = bcm_stat_init(bcm_unit); 40 BCM_IF_ERROR_RETURN(BCMX_STAT_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 41 } 42 43 return rv; 44 } 45 46 int 47 bcmx_stat_sync(void) 48 { 49 int rv = BCM_E_UNAVAIL, tmp_rv; 50 int i, bcm_unit; 51 52 BCMX_STAT_INIT_CHECK; 53 54 BCMX_UNIT_ITER(bcm_unit, i) { 55 tmp_rv = bcm_stat_sync(bcm_unit); 56 BCM_IF_ERROR_RETURN(BCMX_STAT_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 57 } 58 59 return rv; 60 } 61 62 /* 63 * Function: 64 * bcmx_stat_clear 65 */ 66 67 int 68 bcmx_stat_clear(bcmx_lport_t port) 69 { 70 int bcm_unit; 71 bcm_port_t bcm_port; 72 73 BCMX_STAT_INIT_CHECK; 74 75 BCM_IF_ERROR_RETURN 76 (_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port, 77 BCMX_DEST_CONVERT_DEFAULT)); 78 79 return bcm_stat_clear(bcm_unit, bcm_port); 80 } 81 82 /* 83 * Function: 84 * bcmx_stat_get 85 */ 86 87 int 88 bcmx_stat_get(bcmx_lport_t port, 89 bcm_stat_val_t type, 90 uint64 *value) 91 { 92 int bcm_unit; 93 bcm_port_t bcm_port; 94 95 BCMX_STAT_INIT_CHECK; 96 97 BCMX_PARAM_NULL_CHECK(value); 98 99 BCM_IF_ERROR_RETURN 100 (_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port, 101 BCMX_DEST_CONVERT_DEFAULT)); 102 103 return bcm_stat_get(bcm_unit, bcm_port, 104 type, value); 105 } 106 107 108 /* 109 * Function: 110 * bcmx_stat_get32 111 */ 112 113 int 114 bcmx_stat_get32(bcmx_lport_t port, 115 bcm_stat_val_t type, 116 uint32 *value) 117 { 118 int bcm_unit; 119 bcm_port_t bcm_port; 120 121 BCMX_STAT_INIT_CHECK; 122 123 BCMX_PARAM_NULL_CHECK(value); 124 125 BCM_IF_ERROR_RETURN 126 (_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port, 127 BCMX_DEST_CONVERT_DEFAULT)); 128 129 return bcm_stat_get32(bcm_unit, bcm_port, 130 type, value); 131 } 132 133 /* 134 * Function: 135 * bcmx_stat_multi_get 136 */ 137 int 138 bcmx_stat_multi_get(bcm_gport_t port, 139 int nstat, bcm_stat_val_t *stat_arr, uint64 *value_arr) 140 { 141 int bcm_unit; 142 bcm_port_t bcm_port; 143 144 BCMX_STAT_INIT_CHECK; 145 146 BCMX_PARAM_ARRAY_NULL_CHECK(nstat, stat_arr); 147 BCMX_PARAM_ARRAY_NULL_CHECK(nstat, value_arr); 148 149 BCM_IF_ERROR_RETURN 150 (_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port, 151 BCMX_DEST_CONVERT_DEFAULT)); 152 153 return bcm_stat_multi_get(bcm_unit, bcm_port, 154 nstat, stat_arr, value_arr); 155 } 156 157 /* 158 * Function: 159 * bcmx_stat_multi_get 160 */ 161 int 162 bcmx_stat_multi_get32(bcm_gport_t port, 163 int nstat, bcm_stat_val_t *stat_arr, uint32 *value_arr) 164 { 165 int bcm_unit; 166 bcm_port_t bcm_port; 167 168 BCMX_STAT_INIT_CHECK; 169 170 BCMX_PARAM_ARRAY_NULL_CHECK(nstat, stat_arr); 171 BCMX_PARAM_ARRAY_NULL_CHECK(nstat, value_arr); 172 173 BCM_IF_ERROR_RETURN 174 (_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port, 175 BCMX_DEST_CONVERT_DEFAULT)); 176 177 return bcm_stat_multi_get32(bcm_unit, bcm_port, 178 nstat, stat_arr, value_arr); 179 } 180 181 182 /* 183 * Function: 184 * bcmx_stat_custom_set 185 */ 186 187 int 188 bcmx_stat_custom_set(bcmx_lport_t port, 189 bcm_stat_val_t type, 190 uint32 flags) 191 { 192 int bcm_unit; 193 bcm_port_t bcm_port; 194 195 BCMX_STAT_INIT_CHECK; 196 197 BCM_IF_ERROR_RETURN 198 (_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port, 199 BCMX_DEST_CONVERT_DEFAULT)); 200 201 return bcm_stat_custom_set(bcm_unit, bcm_port, 202 type, flags); 203 } 204 205 206 /* 207 * Function: 208 * bcmx_stat_custom_get 209 */ 210 211 int 212 bcmx_stat_custom_get(bcmx_lport_t port, 213 bcm_stat_val_t type, 214 uint32 *flags) 215 { 216 int bcm_unit; 217 bcm_port_t bcm_port; 218 219 BCMX_STAT_INIT_CHECK; 220 221 BCMX_PARAM_NULL_CHECK(flags); 222 223 BCM_IF_ERROR_RETURN 224 (_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port, 225 BCMX_DEST_CONVERT_DEFAULT)); 226 227 return bcm_stat_custom_get(bcm_unit, bcm_port, 228 type, flags); 229 } 230 231 232 /* 233 * Function: 234 * bcmx_stat_custom_add 235 */ 236 237 int 238 bcmx_stat_custom_add(bcmx_lport_t port, bcm_stat_val_t type, 239 bcm_custom_stat_trigger_t trigger) 240 { 241 int bcm_unit; 242 bcm_port_t bcm_port; 243 244 BCMX_STAT_INIT_CHECK; 245 246 BCM_IF_ERROR_RETURN 247 (_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port, 248 BCMX_DEST_CONVERT_DEFAULT)); 249 250 return bcm_stat_custom_add(bcm_unit, bcm_port, 251 type, trigger); 252 } 253 254 255 /* 256 * Function: 257 * bcmx_stat_custom_delete 258 */ 259 260 int 261 bcmx_stat_custom_delete(bcmx_lport_t port, bcm_stat_val_t type, 262 bcm_custom_stat_trigger_t trigger) 263 { 264 int bcm_unit; 265 bcm_port_t bcm_port; 266 267 BCMX_STAT_INIT_CHECK; 268 269 BCM_IF_ERROR_RETURN 270 (_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port, 271 BCMX_DEST_CONVERT_DEFAULT)); 272 273 return bcm_stat_custom_delete(bcm_unit, bcm_port, 274 type, trigger); 275 } 276 277 278 /* 279 * Function: 280 * bcmx_stat_custom_delete_all 281 */ 282 283 int 284 bcmx_stat_custom_delete_all(bcmx_lport_t port, bcm_stat_val_t type) 285 { 286 int bcm_unit; 287 bcm_port_t bcm_port; 288 289 BCMX_STAT_INIT_CHECK; 290 291 BCM_IF_ERROR_RETURN 292 (_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port, 293 BCMX_DEST_CONVERT_DEFAULT)); 294 295 return bcm_stat_custom_delete_all(bcm_unit, bcm_port, 296 type); 297 } 298 299 300 /* 301 * Function: 302 * bcmx_stat_custom_check 303 */ 304 305 int 306 bcmx_stat_custom_check(bcmx_lport_t port, bcm_stat_val_t type, 307 bcm_custom_stat_trigger_t trigger, int *result) 308 { 309 int bcm_unit; 310 bcm_port_t bcm_port; 311 312 BCMX_STAT_INIT_CHECK; 313 314 BCMX_PARAM_NULL_CHECK(result); 315 316 BCM_IF_ERROR_RETURN 317 (_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port, 318 BCMX_DEST_CONVERT_DEFAULT)); 319 320 return bcm_stat_custom_check(bcm_unit, bcm_port, 321 type, trigger, result); 322 }