policer.c (4635B)
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/policer.c 8 * Purpose: BCMX Policer APIs 9 */ 10 11 #include <bcm/types.h> 12 13 #include <bcmx/bcmx.h> 14 #include <bcmx/policer.h> 15 16 #include "bcmx_int.h" 17 18 #define BCMX_POLICER_INIT_CHECK BCMX_READY_CHECK 19 20 #define BCMX_POLICER_ERROR_CHECK(_unit, _check, _rv) \ 21 BCMX_ERROR_CHECK(_unit, _check, _rv) 22 23 #define BCMX_POLICER_SET_ERROR_CHECK(_unit, _check, _rv) \ 24 BCMX_SET_ERROR_CHECK(_unit, _check, _rv) 25 26 #define BCMX_POLICER_DELETE_ERROR_CHECK(_unit, _check, _rv) \ 27 BCMX_DELETE_ERROR_CHECK(_unit, _check, _rv) 28 29 #define BCMX_POLICER_GET_IS_VALID(_unit, _rv) \ 30 BCMX_ERROR_IS_VALID(_unit, _rv) 31 32 33 #define BCMX_POLICER_CONFIG_T_PTR_TO_BCM(_config) \ 34 ((bcm_policer_config_t *)(_config)) 35 36 37 /* 38 * Function: 39 * bcmx_policer_config_t_init 40 */ 41 void 42 bcmx_policer_config_t_init(bcmx_policer_config_t *pol_cfg) 43 { 44 if (pol_cfg != NULL) { 45 bcm_policer_config_t_init(BCMX_POLICER_CONFIG_T_PTR_TO_BCM(pol_cfg)); 46 } 47 } 48 49 /* 50 * Function: 51 * bcmx_policer_init 52 */ 53 int 54 bcmx_policer_init(void) 55 { 56 int rv = BCM_E_UNAVAIL, tmp_rv; 57 int i, bcm_unit; 58 59 BCMX_POLICER_INIT_CHECK; 60 61 BCMX_UNIT_ITER(bcm_unit, i) { 62 tmp_rv = bcm_policer_init(bcm_unit); 63 BCM_IF_ERROR_RETURN(BCMX_POLICER_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 64 } 65 66 return rv; 67 } 68 69 /* 70 * Function: 71 * bcmx_policer_create 72 * Notes: 73 * If policer ID is not specified, the ID returned 74 * from the first successful 'create' is used for the remaining 75 * units. 76 */ 77 int 78 bcmx_policer_create(bcmx_policer_config_t *pol_cfg, 79 bcm_policer_t *policer_id) 80 { 81 int rv = BCM_E_UNAVAIL, tmp_rv; 82 int i, bcm_unit; 83 bcmx_policer_config_t tmp_pol_cfg; 84 85 BCMX_POLICER_INIT_CHECK; 86 87 BCMX_PARAM_NULL_CHECK(pol_cfg); 88 BCMX_PARAM_NULL_CHECK(policer_id); 89 90 tmp_pol_cfg = *pol_cfg; 91 BCMX_UNIT_ITER(bcm_unit, i) { 92 93 tmp_rv = bcm_policer_create(bcm_unit, 94 BCMX_POLICER_CONFIG_T_PTR_TO_BCM 95 (&tmp_pol_cfg), 96 policer_id); 97 BCM_IF_ERROR_RETURN 98 (BCMX_POLICER_SET_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 99 100 /* 101 * Use the ID from first successful 'create' if policer ID 102 * is not specified. 103 */ 104 if (!(tmp_pol_cfg.flags & BCM_POLICER_WITH_ID)) { 105 if (BCM_SUCCESS(tmp_rv)) { 106 tmp_pol_cfg.flags |= BCM_POLICER_WITH_ID; 107 } 108 } 109 } 110 111 return rv; 112 } 113 114 /* 115 * Function: 116 * bcmx_policer_destroy 117 */ 118 int 119 bcmx_policer_destroy(bcm_policer_t policer_id) 120 { 121 int rv = BCM_E_UNAVAIL, tmp_rv; 122 int i, bcm_unit; 123 124 BCMX_POLICER_INIT_CHECK; 125 126 BCMX_UNIT_ITER(bcm_unit, i) { 127 tmp_rv = bcm_policer_destroy(bcm_unit, policer_id); 128 BCM_IF_ERROR_RETURN 129 (BCMX_POLICER_DELETE_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 130 } 131 132 return rv; 133 } 134 135 /* 136 * Function: 137 * bcmx_policer_destroy_all 138 */ 139 int 140 bcmx_policer_destroy_all(void) 141 { 142 int rv = BCM_E_UNAVAIL, tmp_rv; 143 int i, bcm_unit; 144 145 BCMX_POLICER_INIT_CHECK; 146 147 BCMX_UNIT_ITER(bcm_unit, i) { 148 tmp_rv = bcm_policer_destroy_all(bcm_unit); 149 BCM_IF_ERROR_RETURN 150 (BCMX_POLICER_DELETE_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 151 } 152 153 return rv; 154 } 155 156 /* 157 * Function: 158 * bcmx_policer_set 159 */ 160 int 161 bcmx_policer_set(bcm_policer_t policer_id, 162 bcmx_policer_config_t *pol_cfg) 163 { 164 int rv = BCM_E_UNAVAIL, tmp_rv; 165 int i, bcm_unit; 166 167 BCMX_POLICER_INIT_CHECK; 168 169 BCMX_PARAM_NULL_CHECK(pol_cfg); 170 171 BCMX_UNIT_ITER(bcm_unit, i) { 172 tmp_rv = bcm_policer_set(bcm_unit, policer_id, 173 BCMX_POLICER_CONFIG_T_PTR_TO_BCM 174 (pol_cfg)); 175 BCM_IF_ERROR_RETURN 176 (BCMX_POLICER_SET_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 177 } 178 179 return rv; 180 } 181 182 /* 183 * Function: 184 * bcmx_policer_get 185 */ 186 int 187 bcmx_policer_get(bcm_policer_t policer_id, 188 bcmx_policer_config_t *pol_cfg) 189 { 190 int rv; 191 int i, bcm_unit; 192 193 BCMX_POLICER_INIT_CHECK; 194 195 BCMX_PARAM_NULL_CHECK(pol_cfg); 196 197 BCMX_UNIT_ITER(bcm_unit, i) { 198 rv = bcm_policer_get(bcm_unit, policer_id, 199 BCMX_POLICER_CONFIG_T_PTR_TO_BCM(pol_cfg)); 200 if (BCMX_POLICER_GET_IS_VALID(bcm_unit, rv)) { 201 return rv; 202 } 203 } 204 205 return BCM_E_UNAVAIL; 206 } 207