qos.c (7666B)
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/qos.c 8 * Purpose: BCMX Quality of Service APIs 9 */ 10 11 #include <sal/core/libc.h> 12 13 #include <bcm/types.h> 14 15 #include <bcmx/lport.h> 16 #include <bcmx/qos.h> 17 18 #include "bcmx_int.h" 19 20 #define BCMX_QOS_INIT_CHECK BCMX_READY_CHECK 21 22 #define BCMX_QOS_ERROR_CHECK(_unit, _check, _rv) \ 23 BCMX_ERROR_CHECK(_unit, _check, _rv) 24 25 #define BCMX_QOS_SET_ERROR_CHECK(_unit, _check, _rv) \ 26 BCMX_SET_ERROR_CHECK(_unit, _check, _rv) 27 28 #define BCMX_QOS_DELETE_ERROR_CHECK(_unit, _check, _rv) \ 29 BCMX_DELETE_ERROR_CHECK(_unit, _check, _rv) 30 31 #define BCMX_QOS_GET_IS_VALID(_unit, _rv) \ 32 BCMX_ERROR_IS_VALID(_unit, _rv) 33 34 35 #define BCMX_QOS_MAP_T_PTR_TO_BCM(_qos_map) ((bcm_qos_map_t *)(_qos_map)) 36 37 38 /* 39 * Function: 40 * bcmx_qos_map_t_init 41 */ 42 void 43 bcmx_qos_map_t_init(bcmx_qos_map_t *qos_map) 44 { 45 if (qos_map != NULL) { 46 bcm_qos_map_t_init(BCMX_QOS_MAP_T_PTR_TO_BCM(qos_map)); 47 } 48 } 49 50 /* 51 * Function: 52 * bcmx_qos_init 53 */ 54 int 55 bcmx_qos_init(void) 56 { 57 int rv = BCM_E_UNAVAIL, tmp_rv; 58 int i, bcm_unit; 59 60 BCMX_QOS_INIT_CHECK; 61 62 BCMX_UNIT_ITER(bcm_unit, i) { 63 tmp_rv = bcm_qos_init(bcm_unit); 64 BCM_IF_ERROR_RETURN(BCMX_QOS_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 65 } 66 67 return rv; 68 } 69 70 /* 71 * Function: 72 * bcmx_qos_detach 73 */ 74 int 75 bcmx_qos_detach(void) 76 { 77 int rv = BCM_E_UNAVAIL, tmp_rv; 78 int i, bcm_unit; 79 80 BCMX_QOS_INIT_CHECK; 81 82 BCMX_UNIT_ITER(bcm_unit, i) { 83 tmp_rv = bcm_qos_detach(bcm_unit); 84 BCM_IF_ERROR_RETURN(BCMX_QOS_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 85 } 86 87 return rv; 88 } 89 90 /* 91 * Function: 92 * bcmx_qos_map_create 93 */ 94 int 95 bcmx_qos_map_create(uint32 flags, int *map_id) 96 { 97 int rv = BCM_E_UNAVAIL, tmp_rv; 98 int i, bcm_unit; 99 100 BCMX_QOS_INIT_CHECK; 101 102 BCMX_PARAM_NULL_CHECK(map_id); 103 104 BCMX_UNIT_ITER(bcm_unit, i) { 105 tmp_rv = bcm_qos_map_create(bcm_unit, flags, map_id); 106 107 BCM_IF_ERROR_RETURN(BCMX_QOS_SET_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 108 109 /* 110 * Use the ID from first successful 'create' if group ID 111 * is not specified. 112 */ 113 if (!(flags & BCM_QOS_MAP_WITH_ID)) { 114 if (BCM_SUCCESS(tmp_rv)) { 115 flags |= BCM_QOS_MAP_WITH_ID; 116 } 117 } 118 } 119 120 return rv; 121 } 122 123 /* 124 * Function: 125 * bcmx_qos_map_destroy 126 */ 127 int 128 bcmx_qos_map_destroy(int map_id) 129 { 130 int rv = BCM_E_UNAVAIL, tmp_rv; 131 int i, bcm_unit; 132 133 BCMX_QOS_INIT_CHECK; 134 135 BCMX_UNIT_ITER(bcm_unit, i) { 136 tmp_rv = bcm_qos_map_destroy(bcm_unit, map_id); 137 BCM_IF_ERROR_RETURN(BCMX_QOS_DELETE_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 138 } 139 140 return rv; 141 } 142 143 /* 144 * Function: 145 * bcmx_qos_map_add 146 */ 147 int 148 bcmx_qos_map_add(uint32 flags, bcmx_qos_map_t *map, int map_id) 149 { 150 int rv = BCM_E_UNAVAIL, tmp_rv; 151 int i, bcm_unit; 152 153 BCMX_QOS_INIT_CHECK; 154 155 BCMX_PARAM_NULL_CHECK(map); 156 157 BCMX_UNIT_ITER(bcm_unit, i) { 158 tmp_rv = bcm_qos_map_add(bcm_unit, flags, 159 BCMX_QOS_MAP_T_PTR_TO_BCM(map), map_id); 160 BCM_IF_ERROR_RETURN(BCMX_QOS_SET_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 161 } 162 163 return rv; 164 } 165 166 /* 167 * Function: 168 * bcmx_qos_map_delete 169 */ 170 int 171 bcmx_qos_map_delete(uint32 flags, bcmx_qos_map_t *map, int map_id) 172 { 173 int rv = BCM_E_UNAVAIL, tmp_rv; 174 int i, bcm_unit; 175 176 BCMX_QOS_INIT_CHECK; 177 178 BCMX_PARAM_NULL_CHECK(map); 179 180 BCMX_UNIT_ITER(bcm_unit, i) { 181 tmp_rv = bcm_qos_map_delete(bcm_unit, flags, 182 BCMX_QOS_MAP_T_PTR_TO_BCM(map), map_id); 183 BCM_IF_ERROR_RETURN(BCMX_QOS_DELETE_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 184 } 185 186 return rv; 187 } 188 189 /* 190 * Function: 191 * bcmx_qos_map_multi_get 192 * Notes: 193 * Assumes homogeneuous systems and all devices in stack 194 * has the same QoS mapping. 195 */ 196 int 197 bcmx_qos_map_multi_get(uint32 flags, int map_id, 198 int array_size, bcmx_qos_map_t *array, 199 int *array_count) 200 { 201 int rv; 202 int i, bcm_unit; 203 204 BCMX_QOS_INIT_CHECK; 205 206 BCMX_PARAM_NULL_CHECK(array_count); 207 208 /* 209 * No need to gather entries from all units. BCMX assumes 210 * that QoS mapping were created with BCMX APIs. 211 */ 212 BCMX_UNIT_ITER(bcm_unit, i) { 213 rv = bcm_qos_map_multi_get(bcm_unit, flags, map_id, 214 array_size, 215 BCMX_QOS_MAP_T_PTR_TO_BCM(array), 216 array_count); 217 if (BCMX_QOS_GET_IS_VALID(bcm_unit, rv)) { 218 return rv; 219 } 220 } 221 222 return BCM_E_UNAVAIL; 223 } 224 225 /* 226 * Function: 227 * bcmx_qos_port_map_set 228 */ 229 int 230 bcmx_qos_port_map_set(bcm_gport_t port, int ing_map, int egr_map) 231 { 232 int rv = BCM_E_UNAVAIL, tmp_rv; 233 int i, bcm_unit; 234 235 BCMX_QOS_INIT_CHECK; 236 237 BCMX_UNIT_ITER(bcm_unit, i) { 238 tmp_rv = bcm_qos_port_map_set(bcm_unit, port, ing_map, egr_map); 239 BCM_IF_ERROR_RETURN(BCMX_QOS_SET_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 240 } 241 242 return rv; 243 } 244 245 /* 246 * Function: 247 * bcmx_qos_port_map_get 248 */ 249 int 250 bcmx_qos_port_map_get(bcm_gport_t port, int *ing_map, int *egr_map) 251 { 252 int rv; 253 int i, bcm_unit; 254 255 BCMX_QOS_INIT_CHECK; 256 257 BCMX_PARAM_NULL_CHECK(ing_map); 258 BCMX_PARAM_NULL_CHECK(egr_map); 259 260 BCMX_UNIT_ITER(bcm_unit, i) { 261 rv = bcm_qos_port_map_get(bcm_unit, port, ing_map, egr_map); 262 if (BCMX_QOS_GET_IS_VALID(bcm_unit, rv)) { 263 return rv; 264 } 265 } 266 267 return BCM_E_UNAVAIL; 268 } 269 270 /* 271 * Function: 272 * bcmx_qos_port_vlan_map_set 273 * Notes: 274 * Port is a physical port. 275 */ 276 int bcmx_qos_port_vlan_map_set(bcm_gport_t port, bcm_vlan_t vid, 277 int ing_map, int egr_map) 278 { 279 int bcm_unit; 280 bcm_port_t bcm_port; 281 282 BCMX_QOS_INIT_CHECK; 283 284 BCM_IF_ERROR_RETURN 285 (_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port, 286 BCMX_DEST_CONVERT_DEFAULT)); 287 288 return bcm_qos_port_vlan_map_set(bcm_unit, bcm_port, vid, 289 ing_map, egr_map); 290 } 291 292 /* 293 * Function: 294 * bcmx_qos_port_vlan_map_get 295 * Notes: 296 * Port is a physical port. 297 */ 298 int 299 bcmx_qos_port_vlan_map_get(bcm_gport_t port, bcm_vlan_t vid, 300 int *ing_map, int *egr_map) 301 { 302 int bcm_unit; 303 bcm_port_t bcm_port; 304 305 BCMX_QOS_INIT_CHECK; 306 307 BCMX_PARAM_NULL_CHECK(ing_map); 308 BCMX_PARAM_NULL_CHECK(egr_map); 309 310 BCM_IF_ERROR_RETURN 311 (_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port, 312 BCMX_DEST_CONVERT_DEFAULT)); 313 314 return bcm_qos_port_vlan_map_get(bcm_unit, bcm_port, vid, 315 ing_map, egr_map); 316 } 317 318 /* 319 * Function: 320 * bcmx_qos_multi_get 321 * Notes: 322 * Assumes homogeneuous systems and all devices in stack 323 * has the same QoS mapping. 324 */ 325 int 326 bcmx_qos_multi_get(int array_size, int *map_ids_array, 327 int *flags_array, int *array_count) 328 { 329 int rv; 330 int i, bcm_unit; 331 332 BCMX_QOS_INIT_CHECK; 333 334 BCMX_PARAM_NULL_CHECK(array_count); 335 336 /* 337 * No need to gather entries from all units. BCMX assumes 338 * that QoS mapping were created with BCMX APIs. 339 */ 340 BCMX_UNIT_ITER(bcm_unit, i) { 341 rv = bcm_qos_multi_get(bcm_unit, array_size, map_ids_array, 342 flags_array, array_count); 343 if (BCMX_QOS_GET_IS_VALID(bcm_unit, rv)) { 344 return rv; 345 } 346 } 347 348 return BCM_E_UNAVAIL; 349 }