mim.c (9471B)
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/mim.c 8 * Purpose: BCMX MAC-in-MAC APIs 9 */ 10 #ifdef INCLUDE_L3 11 12 #include <bcm/types.h> 13 14 #include <bcmx/lport.h> 15 #include <bcmx/mim.h> 16 17 #include "bcmx_int.h" 18 19 #define BCMX_MIM_INIT_CHECK BCMX_READY_CHECK 20 21 #define BCMX_MIM_ERROR_CHECK(_unit, _check, _rv) \ 22 BCMX_ERROR_CHECK(_unit, _check, _rv) 23 24 #define BCMX_MIM_SET_ERROR_CHECK(_unit, _check, _rv) \ 25 BCMX_SET_ERROR_CHECK(_unit, _check, _rv) 26 27 #define BCMX_MIM_DELETE_ERROR_CHECK(_unit, _check, _rv) \ 28 BCMX_DELETE_ERROR_CHECK(_unit, _check, _rv) 29 30 #define BCMX_MIM_GET_IS_VALID(_unit, _rv) \ 31 BCMX_ERROR_IS_VALID(_unit, _rv) 32 33 34 #define BCMX_MIM_VPN_CONFIG_T_PTR_TO_BCM(_config) \ 35 ((bcm_mim_vpn_config_t *)(_config)) 36 37 #define BCMX_MIM_PORT_T_PTR_TO_BCM(_port) \ 38 ((bcm_mim_port_t *)(_port)) 39 40 41 /* 42 * Function: 43 * bcmx_mim_vpn_config_t_init 44 */ 45 void 46 bcmx_mim_vpn_config_t_init(bcmx_mim_vpn_config_t *mim_vpn_config) 47 { 48 if (mim_vpn_config != NULL) { 49 bcm_mim_vpn_config_t_init(BCMX_MIM_VPN_CONFIG_T_PTR_TO_BCM 50 (mim_vpn_config)); 51 } 52 } 53 54 /* 55 * Function: 56 * bcmx_mim_port_t_init 57 */ 58 void 59 bcmx_mim_port_t_init(bcmx_mim_port_t *mim_port) 60 { 61 if (mim_port != NULL) { 62 bcm_mim_port_t_init(BCMX_MIM_PORT_T_PTR_TO_BCM(mim_port)); 63 } 64 } 65 66 67 /* 68 * Function: 69 * bcmx_mim_init 70 * Purpose: 71 * Initialize the MIM software module. 72 * Parameters: 73 * None 74 * Returns: 75 * BCM_E_XXX 76 * Notes: 77 */ 78 int 79 bcmx_mim_init(void) 80 { 81 int rv = BCM_E_UNAVAIL, tmp_rv; 82 int i, bcm_unit; 83 84 BCMX_MIM_INIT_CHECK; 85 86 BCMX_UNIT_ITER(bcm_unit, i) { 87 tmp_rv = bcm_mim_init(bcm_unit); 88 BCM_IF_ERROR_RETURN(BCMX_MIM_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 89 } 90 91 return rv; 92 } 93 94 /* 95 * Function: 96 * bcmx_mim_detach 97 * Purpose: 98 * Detach the MIM software module. 99 * Parameters: 100 * None 101 * Returns: 102 * BCM_E_XXX 103 * Notes: 104 */ 105 int 106 bcmx_mim_detach(void) 107 { 108 int rv = BCM_E_UNAVAIL, tmp_rv; 109 int i, bcm_unit; 110 111 BCMX_MIM_INIT_CHECK; 112 113 BCMX_UNIT_ITER(bcm_unit, i) { 114 tmp_rv = bcm_mim_detach(bcm_unit); 115 BCM_IF_ERROR_RETURN(BCMX_MIM_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 116 } 117 118 return rv; 119 } 120 121 /* 122 * Function: 123 * bcmx_mim_vpn_create 124 * Purpose: 125 * Create a VPN instance. 126 * Parameters: 127 * info - (IN/OUT) VPN configuration info 128 * Returns: 129 * BCM_E_XXX 130 * Notes: 131 */ 132 int 133 bcmx_mim_vpn_create(bcmx_mim_vpn_config_t *info) 134 { 135 int rv = BCM_E_UNAVAIL, tmp_rv; 136 int i, bcm_unit; 137 uint32 flags_orig; 138 139 BCMX_MIM_INIT_CHECK; 140 141 BCMX_PARAM_NULL_CHECK(info); 142 143 /* Store original 'xxx_WITH_ID' flag bit */ 144 flags_orig = info->flags & BCM_MIM_VPN_WITH_ID; 145 146 BCMX_UNIT_ITER(bcm_unit, i) { 147 tmp_rv = bcm_mim_vpn_create(bcm_unit, 148 BCMX_MIM_VPN_CONFIG_T_PTR_TO_BCM(info)); 149 if (BCM_FAILURE(BCMX_MIM_SET_ERROR_CHECK(bcm_unit, tmp_rv, &rv))) { 150 break; 151 } 152 153 /* 154 * Use the ID from first successful 'create' if ID 155 * is not specified. 156 */ 157 if (!(info->flags & BCM_MIM_VPN_WITH_ID)) { 158 if (BCM_SUCCESS(tmp_rv)) { 159 info->flags |= BCM_MIM_VPN_WITH_ID; 160 } 161 } 162 } 163 164 /* Restore 'xxx_WITH_ID' flag bit */ 165 info->flags &= ~BCM_MIM_VPN_WITH_ID; 166 info->flags |= flags_orig; 167 168 return rv; 169 } 170 171 /* 172 * Function: 173 * bcmx_mim_vpn_destroy 174 * Purpose: 175 * Delete a VPN instance. 176 * Parameters: 177 * vpn - VPN instance ID 178 * Returns: 179 * BCM_E_XXX 180 * Notes: 181 */ 182 int 183 bcmx_mim_vpn_destroy(bcm_mim_vpn_t vpn) 184 { 185 int rv = BCM_E_UNAVAIL, tmp_rv; 186 int i, bcm_unit; 187 188 BCMX_MIM_INIT_CHECK; 189 190 BCMX_UNIT_ITER(bcm_unit, i) { 191 tmp_rv = bcm_mim_vpn_destroy(bcm_unit, vpn); 192 BCM_IF_ERROR_RETURN(BCMX_MIM_DELETE_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 193 } 194 195 return rv; 196 } 197 198 /* 199 * Function: 200 * bcmx_mim_vpn_destroy_all 201 * Purpose: 202 * Delete all VPN instances. 203 * Parameters: 204 * None 205 * Returns: 206 * BCM_E_XXX 207 * Notes: 208 */ 209 int 210 bcmx_mim_vpn_destroy_all(void) 211 { 212 int rv = BCM_E_UNAVAIL, tmp_rv; 213 int i, bcm_unit; 214 215 BCMX_MIM_INIT_CHECK; 216 217 BCMX_UNIT_ITER(bcm_unit, i) { 218 tmp_rv = bcm_mim_vpn_destroy_all(bcm_unit); 219 BCM_IF_ERROR_RETURN(BCMX_MIM_DELETE_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 220 } 221 222 return rv; 223 } 224 225 /* 226 * Function: 227 * bcmx_mim_vpn_get 228 * Purpose: 229 * Get configuration for a given VPN instance id. 230 * Parameters: 231 * vpn - VPN instance ID 232 * info - (OUT) VPN configuration info 233 * Returns: 234 * BCM_E_XXX 235 * Notes: 236 */ 237 int 238 bcmx_mim_vpn_get(bcm_mim_vpn_t vpn, bcmx_mim_vpn_config_t *info) 239 { 240 int rv; 241 int i, bcm_unit; 242 243 BCMX_MIM_INIT_CHECK; 244 245 BCMX_PARAM_NULL_CHECK(info); 246 247 BCMX_UNIT_ITER(bcm_unit, i) { 248 rv = bcm_mim_vpn_get(bcm_unit, vpn, 249 BCMX_MIM_VPN_CONFIG_T_PTR_TO_BCM(info)); 250 if (BCMX_MIM_GET_IS_VALID(bcm_unit, rv)) { 251 return rv; 252 } 253 } 254 255 return BCM_E_UNAVAIL; 256 } 257 258 /* 259 * Function: 260 * bcmx_mim_port_add 261 * Purpose: 262 * Add a MAC-in-MAC port to a VPN. 263 * Parameters: 264 * vpn - VPN instance ID 265 * mim_port - (IN/OUT) MAC-in-MAC port information 266 * Returns: 267 * BCM_E_XXX 268 * Notes: 269 */ 270 int 271 bcmx_mim_port_add(bcm_mim_vpn_t vpn, bcmx_mim_port_t *mim_port) 272 { 273 int rv = BCM_E_UNAVAIL, tmp_rv; 274 int i, bcm_unit; 275 uint32 flags_orig; 276 277 BCMX_MIM_INIT_CHECK; 278 279 BCMX_PARAM_NULL_CHECK(mim_port); 280 281 /* Store original 'xxx_WITH_ID' flag bit */ 282 flags_orig = mim_port->flags & BCM_MIM_PORT_WITH_ID; 283 284 BCMX_UNIT_ITER(bcm_unit, i) { 285 tmp_rv = bcm_mim_port_add(bcm_unit, vpn, 286 BCMX_MIM_PORT_T_PTR_TO_BCM(mim_port)); 287 if (BCM_FAILURE(BCMX_MIM_SET_ERROR_CHECK(bcm_unit, tmp_rv, &rv))) { 288 break; 289 } 290 291 /* 292 * Use the ID from first successful 'add' if ID 293 * is not specified. 294 */ 295 if (!(mim_port->flags & BCM_MIM_PORT_WITH_ID)) { 296 if (BCM_SUCCESS(tmp_rv)) { 297 mim_port->flags |= BCM_MIM_PORT_WITH_ID; 298 } 299 } 300 } 301 302 /* Restore 'xxx_WITH_ID' flag bit */ 303 mim_port->flags &= ~BCM_MIM_PORT_WITH_ID; 304 mim_port->flags |= flags_orig; 305 306 return rv; 307 } 308 309 /* 310 * Function: 311 * bcmx_mim_port_delete 312 * Purpose: 313 * Delete a MAC-in-MAC port from a VPN. 314 * Parameters: 315 * vpn - VPN instance ID 316 * mim_port_id - MAC-in-MAC port ID 317 * Returns: 318 * BCM_E_XXX 319 * Notes: 320 */ 321 int 322 bcmx_mim_port_delete(bcm_mim_vpn_t vpn, bcm_gport_t mim_port_id) 323 { 324 int rv = BCM_E_UNAVAIL, tmp_rv; 325 int i, bcm_unit; 326 327 BCMX_MIM_INIT_CHECK; 328 329 BCMX_UNIT_ITER(bcm_unit, i) { 330 tmp_rv = bcm_mim_port_delete(bcm_unit, vpn, mim_port_id); 331 BCM_IF_ERROR_RETURN(BCMX_MIM_DELETE_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 332 } 333 334 return rv; 335 } 336 337 /* 338 * Function: 339 * bcmx_mim_port_delete_all 340 * Purpose: 341 * Delete all MAC-in-MAC ports from a VPN. 342 * Parameters: 343 * vpn - VPN instance ID 344 * Returns: 345 * BCM_E_XXX 346 * Notes: 347 */ 348 int 349 bcmx_mim_port_delete_all(bcm_mim_vpn_t vpn) 350 { 351 int rv = BCM_E_UNAVAIL, tmp_rv; 352 int i, bcm_unit; 353 354 BCMX_MIM_INIT_CHECK; 355 356 BCMX_UNIT_ITER(bcm_unit, i) { 357 tmp_rv = bcm_mim_port_delete_all(bcm_unit, vpn); 358 BCM_IF_ERROR_RETURN(BCMX_MIM_DELETE_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 359 } 360 361 return rv; 362 } 363 364 /* 365 * Function: 366 * bcmx_mim_port_get 367 * Purpose: 368 * Get MAC-in-MAC port information for a VPN. 369 * Parameters: 370 * vpn - VPN instance ID 371 * mim_port - (IN/OUT) mim port information 372 * Returns: 373 * BCM_E_XXX 374 * Notes: 375 */ 376 int 377 bcmx_mim_port_get(bcm_mim_vpn_t vpn, bcmx_mim_port_t *mim_port) 378 { 379 int rv; 380 int i, bcm_unit; 381 382 BCMX_MIM_INIT_CHECK; 383 384 BCMX_PARAM_NULL_CHECK(mim_port); 385 386 BCMX_UNIT_ITER(bcm_unit, i) { 387 rv = bcm_mim_port_get(bcm_unit, vpn, 388 BCMX_MIM_PORT_T_PTR_TO_BCM(mim_port)); 389 if (BCMX_MIM_GET_IS_VALID(bcm_unit, rv)) { 390 return rv; 391 } 392 } 393 394 return BCM_E_UNAVAIL; 395 } 396 397 /* 398 * Function: 399 * bcmx_mim_port_get_all 400 * Purpose: 401 * Get all MAC-in-MAC ports information for a VPN. 402 * Parameters: 403 * vpn - VPN instance ID 404 * port_max - Maximum number of interfaces in array 405 * port_array - (OUT) Array of mim ports 406 * port_count - (OUT) Number of interfaces returned in array 407 * Returns: 408 * BCM_E_XXX 409 * Notes: 410 * MAC-in-MAC ports are added to all devices since they are global 411 * entities. API '_get_all()' can just return port information 412 * from call on first switch. 413 */ 414 int 415 bcmx_mim_port_get_all(bcm_mim_vpn_t vpn, int port_max, 416 bcmx_mim_port_t *port_array, int *port_count) 417 { 418 int rv; 419 int i, bcm_unit; 420 421 BCMX_MIM_INIT_CHECK; 422 423 BCMX_PARAM_NULL_CHECK(port_array); 424 BCMX_PARAM_NULL_CHECK(port_count); 425 426 BCMX_UNIT_ITER(bcm_unit, i) { 427 rv = bcm_mim_port_get_all(bcm_unit, vpn, port_max, 428 BCMX_MIM_PORT_T_PTR_TO_BCM(port_array), 429 port_count); 430 if (BCMX_MIM_GET_IS_VALID(bcm_unit, rv)) { 431 return rv; 432 } 433 } 434 435 return BCM_E_UNAVAIL; 436 } 437 438 #endif /* INCLUDE_L3 */