stg.c (7898B)
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/stg.c 8 * Purpose: stg.c BCMX source file 9 */ 10 11 #include <bcm/types.h> 12 13 #include <bcmx/stg.h> 14 #include <bcmx/lport.h> 15 #include <bcmx/bcmx.h> 16 17 #include "bcmx_int.h" 18 19 #define BCMX_STG_INIT_CHECK BCMX_READY_CHECK 20 21 #define BCMX_STG_ERROR_CHECK(_unit, _check, _rv) \ 22 BCMX_ERROR_CHECK(_unit, _check, _rv) 23 24 #define BCMX_STG_SET_ERROR_CHECK(_unit, _check, _rv) \ 25 BCMX_SET_ERROR_CHECK(_unit, _check, _rv) 26 27 #define BCMX_STG_DELETE_ERROR_CHECK(_unit, _check, _rv) \ 28 BCMX_DELETE_ERROR_CHECK(_unit, _check, _rv) 29 30 #define BCMX_STG_GET_IS_VALID(_unit, _rv) \ 31 BCMX_ERROR_IS_VALID(_unit, _rv) 32 33 #define BCMX_STG_ERROR_IS_VALID(_unit, _rv) \ 34 BCMX_ERROR_IS_VALID(_unit, _rv) 35 36 37 int 38 bcmx_stg_init(void) 39 { 40 int rv = BCM_E_UNAVAIL, tmp_rv; 41 int i, bcm_unit; 42 43 BCMX_STG_INIT_CHECK; 44 45 BCMX_UNIT_ITER(bcm_unit, i) { 46 tmp_rv = bcm_stg_init(bcm_unit); 47 BCM_IF_ERROR_RETURN(BCMX_STG_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 48 } 49 50 return rv; 51 } 52 53 /* 54 * Function: 55 * bcmx_stg_default_get 56 */ 57 58 int 59 bcmx_stg_default_get(bcm_stg_t *stg_ptr) 60 { 61 int rv, i, bcm_unit; 62 63 BCMX_STG_INIT_CHECK; 64 65 BCMX_PARAM_NULL_CHECK(stg_ptr); 66 67 BCMX_UNIT_ITER(bcm_unit, i) { 68 rv = bcm_stg_default_get(bcm_unit, stg_ptr); 69 if (BCMX_STG_GET_IS_VALID(bcm_unit, rv)) { 70 return rv; 71 } 72 } 73 74 return BCM_E_UNAVAIL; 75 } 76 77 78 /* 79 * Function: 80 * bcmx_stg_default_set 81 */ 82 83 int 84 bcmx_stg_default_set(bcm_stg_t stg) 85 { 86 int rv = BCM_E_UNAVAIL, tmp_rv; 87 int i, bcm_unit; 88 89 BCMX_STG_INIT_CHECK; 90 91 BCMX_UNIT_ITER(bcm_unit, i) { 92 tmp_rv = bcm_stg_default_set(bcm_unit, stg); 93 BCM_IF_ERROR_RETURN(BCMX_STG_SET_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 94 } 95 96 return rv; 97 } 98 99 100 /* 101 * Function: 102 * bcmx_stg_vlan_add 103 */ 104 105 int 106 bcmx_stg_vlan_add(bcm_stg_t stg, 107 bcm_vlan_t vid) 108 { 109 int rv = BCM_E_UNAVAIL, tmp_rv; 110 int i, bcm_unit; 111 112 BCMX_STG_INIT_CHECK; 113 114 BCMX_UNIT_ITER(bcm_unit, i) { 115 tmp_rv = bcm_stg_vlan_add(bcm_unit, stg, vid); 116 BCM_IF_ERROR_RETURN(BCMX_STG_SET_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 117 } 118 119 return rv; 120 } 121 122 123 /* 124 * Function: 125 * bcmx_stg_vlan_remove 126 */ 127 128 int 129 bcmx_stg_vlan_remove(bcm_stg_t stg, 130 bcm_vlan_t vid) 131 { 132 int rv = BCM_E_UNAVAIL, tmp_rv; 133 int i, bcm_unit; 134 135 BCMX_STG_INIT_CHECK; 136 137 BCMX_UNIT_ITER(bcm_unit, i) { 138 tmp_rv = bcm_stg_vlan_remove(bcm_unit, stg, vid); 139 BCM_IF_ERROR_RETURN(BCMX_STG_DELETE_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 140 } 141 142 return rv; 143 } 144 145 146 /* 147 * Function: 148 * bcmx_stg_vlan_remove_all 149 */ 150 151 int 152 bcmx_stg_vlan_remove_all(bcm_stg_t stg) 153 { 154 int rv = BCM_E_UNAVAIL, tmp_rv; 155 int i, bcm_unit; 156 157 BCMX_STG_INIT_CHECK; 158 159 BCMX_UNIT_ITER(bcm_unit, i) { 160 tmp_rv = bcm_stg_vlan_remove_all(bcm_unit, stg); 161 BCM_IF_ERROR_RETURN(BCMX_STG_DELETE_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 162 } 163 164 return rv; 165 } 166 167 168 /* 169 * Function: 170 * bcmx_stg_vlan_list 171 */ 172 173 int 174 bcmx_stg_vlan_list(bcm_stg_t stg, 175 bcm_vlan_t **list, 176 int *count) 177 { 178 int rv, i, bcm_unit; 179 180 BCMX_STG_INIT_CHECK; 181 182 BCMX_PARAM_NULL_CHECK(list); 183 BCMX_PARAM_NULL_CHECK(count); 184 185 BCMX_LOCAL_UNIT_ITER(bcm_unit, i) { 186 rv = bcm_stg_vlan_list(bcm_unit, stg, list, count); 187 if (BCMX_STG_ERROR_IS_VALID(bcm_unit, rv)) { 188 return rv; 189 } 190 } 191 192 return BCM_E_UNAVAIL; 193 } 194 195 196 /* 197 * Function: 198 * bcmx_stg_vlan_list_destroy 199 */ 200 201 int 202 bcmx_stg_vlan_list_destroy(bcm_vlan_t *list, 203 int count) 204 { 205 int rv, i, bcm_unit; 206 207 BCMX_STG_INIT_CHECK; 208 209 BCMX_PARAM_ARRAY_NULL_CHECK(count, list); 210 211 BCMX_LOCAL_UNIT_ITER(bcm_unit, i) { 212 rv = bcm_stg_vlan_list_destroy(bcm_unit, list, count); 213 if (BCMX_STG_ERROR_IS_VALID(bcm_unit, rv)) { 214 return rv; 215 } 216 } 217 218 return BCM_E_UNAVAIL; 219 } 220 221 222 /* 223 * Function: 224 * bcmx_stg_create 225 * Notes: 226 * Attempt to create the same STGID across all chips; the 227 * first time we succeed, we call "create_id". Will 228 * return BCM_E_NONE if the stg id exists in some chips. 229 */ 230 231 int 232 bcmx_stg_create(bcm_stg_t *stg_ptr) 233 { 234 int rv = BCM_E_UNAVAIL; 235 int i, bcm_unit; 236 237 BCMX_STG_INIT_CHECK; 238 239 BCMX_UNIT_ITER(bcm_unit, i) { 240 rv = bcm_stg_create(bcm_unit, stg_ptr); 241 if (BCMX_STG_ERROR_IS_VALID(bcm_unit, rv)) { 242 if (BCM_SUCCESS(rv)) { /* Found an STG */ 243 rv = bcmx_stg_create_id(*stg_ptr); 244 } 245 break; 246 } 247 } 248 249 return rv; 250 } 251 252 253 /* 254 * Function: 255 * bcmx_stg_create_id 256 * Notes: 257 * Returns BCM_E_NONE if the STG already exists. 258 */ 259 260 int 261 bcmx_stg_create_id(bcm_stg_t stg) 262 { 263 int rv = BCM_E_UNAVAIL, tmp_rv; 264 int i, bcm_unit; 265 266 BCMX_STG_INIT_CHECK; 267 268 BCMX_UNIT_ITER(bcm_unit, i) { 269 tmp_rv = bcm_stg_create_id(bcm_unit, stg); 270 BCM_IF_ERROR_RETURN(BCMX_STG_SET_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 271 } 272 273 return rv; 274 } 275 276 277 /* 278 * Function: 279 * bcmx_stg_destroy 280 */ 281 282 int 283 bcmx_stg_destroy(bcm_stg_t stg) 284 { 285 int rv = BCM_E_UNAVAIL, tmp_rv; 286 int i, bcm_unit; 287 288 BCMX_STG_INIT_CHECK; 289 290 BCMX_UNIT_ITER(bcm_unit, i) { 291 tmp_rv = bcm_stg_destroy(bcm_unit, stg); 292 BCM_IF_ERROR_RETURN(BCMX_STG_DELETE_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 293 } 294 295 return rv; 296 } 297 298 299 /* 300 * Function: 301 * bcmx_stg_list 302 */ 303 304 int 305 bcmx_stg_list(bcm_stg_t **list, 306 int *count) 307 { 308 int rv, i, bcm_unit; 309 310 BCMX_STG_INIT_CHECK; 311 312 BCMX_PARAM_NULL_CHECK(list); 313 BCMX_PARAM_NULL_CHECK(count); 314 315 BCMX_LOCAL_UNIT_ITER(bcm_unit, i) { 316 rv = bcm_stg_list(bcm_unit, list, count); 317 if (BCMX_STG_ERROR_IS_VALID(bcm_unit, rv)) { 318 return rv; 319 } 320 } 321 322 return BCM_E_UNAVAIL; 323 } 324 325 326 /* 327 * Function: 328 * bcmx_stg_list_destroy 329 */ 330 331 int 332 bcmx_stg_list_destroy(bcm_stg_t *list, 333 int count) 334 { 335 int rv, i, bcm_unit; 336 337 BCMX_STG_INIT_CHECK; 338 339 BCMX_PARAM_ARRAY_NULL_CHECK(count, list); 340 341 BCMX_LOCAL_UNIT_ITER(bcm_unit, i) { 342 rv = bcm_stg_list_destroy(bcm_unit, list, count); 343 if (BCMX_STG_ERROR_IS_VALID(bcm_unit, rv)) { 344 return rv; 345 } 346 } 347 348 return BCM_E_UNAVAIL; 349 } 350 351 352 /* 353 * Function: 354 * bcmx_stg_stp_set 355 */ 356 357 int 358 bcmx_stg_stp_set(bcm_stg_t stg, 359 bcmx_lport_t port, 360 int stp_state) 361 { 362 int bcm_unit; 363 bcm_port_t bcm_port; 364 365 BCMX_STG_INIT_CHECK; 366 367 BCM_IF_ERROR_RETURN 368 (_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port, 369 BCMX_DEST_CONVERT_DEFAULT)); 370 371 return bcm_stg_stp_set(bcm_unit, 372 stg, 373 bcm_port, 374 stp_state); 375 } 376 377 378 /* 379 * Function: 380 * bcmx_stg_stp_get 381 */ 382 383 int 384 bcmx_stg_stp_get(bcm_stg_t stg, 385 bcmx_lport_t port, 386 int *stp_state) 387 { 388 int bcm_unit; 389 bcm_port_t bcm_port; 390 391 BCMX_STG_INIT_CHECK; 392 393 BCM_IF_ERROR_RETURN 394 (_bcmx_dest_to_unit_port(port, &bcm_unit, &bcm_port, 395 BCMX_DEST_CONVERT_DEFAULT)); 396 397 return bcm_stg_stp_get(bcm_unit, 398 stg, 399 bcm_port, 400 stp_state); 401 } 402 403 404 /* 405 * Function: 406 * bcmx_stg_count_get 407 */ 408 409 int 410 bcmx_stg_count_get(int *max_stg) 411 { 412 int rv, i, bcm_unit; 413 414 BCMX_STG_INIT_CHECK; 415 416 BCMX_PARAM_NULL_CHECK(max_stg); 417 418 BCMX_UNIT_ITER(bcm_unit, i) { 419 rv = bcm_stg_count_get(bcm_unit, max_stg); 420 if (BCMX_STG_GET_IS_VALID(bcm_unit, rv)) { 421 return rv; 422 } 423 } 424 425 return BCM_E_UNAVAIL; 426 }