niv.c (7661B)
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/niv.c 8 * Purpose: BCMX NIV APIs 9 */ 10 11 #ifdef INCLUDE_L3 12 13 #include <bcm/types.h> 14 15 #include <bcmx/lport.h> 16 #include <bcmx/niv.h> 17 #include "bcmx_int.h" 18 19 #define BCMX_NIV_INIT_CHECK BCMX_READY_CHECK 20 21 #define BCMX_NIV_ERROR_CHECK(_unit, _check, _rv) \ 22 BCMX_ERROR_CHECK(_unit, _check, _rv) 23 24 #define BCMX_NIV_SET_ERROR_CHECK(_unit, _check, _rv) \ 25 BCMX_SET_ERROR_CHECK(_unit, _check, _rv) 26 27 #define BCMX_NIV_DELETE_ERROR_CHECK(_unit, _check, _rv) \ 28 BCMX_DELETE_ERROR_CHECK(_unit, _check, _rv) 29 30 #define BCMX_NIV_GET_IS_VALID(_unit, _rv) \ 31 BCMX_ERROR_IS_VALID(_unit, _rv) 32 33 34 #define BCMX_NIV_PORT_T_PTR_TO_BCM(_port) \ 35 ((bcm_niv_port_t *)(_port)) 36 37 #define BCMX_NIV_FORWARD_T_PTR_TO_BCM(_info) \ 38 ((bcm_niv_forward_t *)(_info)) 39 40 41 /* Initialize the NIV port structure. */ 42 void 43 bcmx_niv_port_t_init(bcmx_niv_port_t *niv_port) 44 { 45 if (niv_port != NULL) { 46 bcm_niv_port_t_init(BCMX_NIV_PORT_T_PTR_TO_BCM(niv_port)); 47 } 48 } 49 50 /* Initialize the NIV Forwarding Entry structure. */ 51 void 52 bcmx_niv_forward_t_init(bcmx_niv_forward_t *iv_fwd_entry) 53 { 54 if (iv_fwd_entry != NULL) { 55 bcm_niv_forward_t_init(BCMX_NIV_FORWARD_T_PTR_TO_BCM(iv_fwd_entry)); 56 } 57 } 58 59 /* 60 * Function: 61 * bcmx_niv_init 62 * Purpose: 63 * Initialize NIV module. 64 * Parameters: 65 * None 66 * Returns: 67 * BCM_E_XXX 68 * Notes: 69 */ 70 int 71 bcmx_niv_init(void) 72 { 73 int rv = BCM_E_UNAVAIL, tmp_rv; 74 int i, bcm_unit; 75 76 BCMX_NIV_INIT_CHECK; 77 78 BCMX_UNIT_ITER(bcm_unit, i) { 79 tmp_rv = bcm_niv_init(bcm_unit); 80 BCM_IF_ERROR_RETURN(BCMX_NIV_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 81 } 82 83 return rv; 84 } 85 86 /* 87 * Function: 88 * bcmx_niv_cleanup 89 * Purpose: 90 * Detach NIV module, clear all HW states. 91 * Parameters: 92 * None 93 * Returns: 94 * BCM_E_XXX 95 * Notes: 96 */ 97 int 98 bcmx_niv_cleanup(void) 99 { 100 int rv = BCM_E_UNAVAIL, tmp_rv; 101 int i, bcm_unit; 102 103 BCMX_NIV_INIT_CHECK; 104 105 BCMX_UNIT_ITER(bcm_unit, i) { 106 tmp_rv = bcm_niv_cleanup(bcm_unit); 107 BCM_IF_ERROR_RETURN(BCMX_NIV_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 108 } 109 110 return rv; 111 } 112 113 /* 114 * Function: 115 * bcmx_niv_port_add 116 * Purpose: 117 * Create NIV Port. 118 * Parameters: 119 * niv_port - (IN/OUT) NIV port information 120 * Returns: 121 * BCM_E_XXX 122 * Notes: 123 * NIV port is a global entity, apply to all units. 124 */ 125 int 126 bcmx_niv_port_add(bcmx_niv_port_t *niv_port) 127 { 128 int rv = BCM_E_UNAVAIL, tmp_rv; 129 int i, bcm_unit; 130 uint32 flags_orig; 131 132 BCMX_NIV_INIT_CHECK; 133 134 BCMX_PARAM_NULL_CHECK(niv_port); 135 136 /* Store original 'xxx_WITH_ID' flag bit */ 137 flags_orig = niv_port->flags & BCM_NIV_PORT_WITH_ID; 138 139 BCMX_UNIT_ITER(bcm_unit, i) { 140 tmp_rv = bcm_niv_port_add(bcm_unit, 141 BCMX_NIV_PORT_T_PTR_TO_BCM(niv_port)); 142 if (BCM_FAILURE(BCMX_NIV_SET_ERROR_CHECK(bcm_unit, tmp_rv, &rv))) { 143 break; 144 } 145 146 /* 147 * Use the ID from first successful 'create' if NIV port ID 148 * is not specified. 149 */ 150 if (!(niv_port->flags & BCM_NIV_PORT_WITH_ID)) { 151 if (BCM_SUCCESS(tmp_rv)) { 152 niv_port->flags |= BCM_NIV_PORT_WITH_ID; 153 } 154 } 155 } 156 157 /* Restore 'xxx_WITH_ID' flag bit */ 158 niv_port->flags &= ~BCM_NIV_PORT_WITH_ID; 159 niv_port->flags |= flags_orig; 160 161 return rv; 162 } 163 164 /* 165 * Function: 166 * bcmx_niv_port_delete 167 * Purpose: 168 * Delete a NIV port. 169 * Parameters: 170 * niv_port_id - NIV port id to delete 171 * Returns: 172 * BCM_E_XXX 173 */ 174 int 175 bcmx_niv_port_delete(bcm_gport_t niv_port_id) 176 { 177 int rv = BCM_E_UNAVAIL, tmp_rv; 178 int i, bcm_unit; 179 180 BCMX_NIV_INIT_CHECK; 181 182 BCMX_UNIT_ITER(bcm_unit, i) { 183 tmp_rv = bcm_niv_port_delete(bcm_unit, niv_port_id); 184 BCM_IF_ERROR_RETURN 185 (BCMX_NIV_DELETE_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 186 } 187 188 return rv; 189 } 190 191 /* 192 * Function: 193 * bcmx_niv_port_delete_all 194 * Purpose: 195 * Delete all NIV ports. 196 * Parameters: 197 * None 198 * Returns: 199 * BCM_E_XXX 200 */ 201 int 202 bcmx_niv_port_delete_all(void) 203 { 204 int rv = BCM_E_UNAVAIL, tmp_rv; 205 int i, bcm_unit; 206 207 BCMX_NIV_INIT_CHECK; 208 209 BCMX_UNIT_ITER(bcm_unit, i) { 210 tmp_rv = bcm_niv_port_delete_all(bcm_unit); 211 BCM_IF_ERROR_RETURN 212 (BCMX_NIV_DELETE_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 213 } 214 215 return rv; 216 } 217 218 /* 219 * Function: 220 * bcmx_niv_port_get 221 * Purpose: 222 * Get NIV port information for given ID. 223 * Parameters: 224 * niv_port - (IN/OUT) NIV port info 225 * Returns: 226 * BCM_E_XXX 227 */ 228 int 229 bcmx_niv_port_get(bcmx_niv_port_t *niv_port) 230 { 231 int rv; 232 int i, bcm_unit; 233 234 BCMX_NIV_INIT_CHECK; 235 236 BCMX_PARAM_NULL_CHECK(niv_port); 237 238 BCMX_UNIT_ITER(bcm_unit, i) { 239 rv = bcm_niv_port_get(bcm_unit, BCMX_NIV_PORT_T_PTR_TO_BCM(niv_port)); 240 if (BCMX_NIV_GET_IS_VALID(bcm_unit, rv)) { 241 return rv; 242 } 243 } 244 245 return BCM_E_UNAVAIL; 246 } 247 248 249 /* 250 * Function: 251 * bcmx_niv_forward_add 252 * Purpose: 253 * Add NIV forwarding table entry. 254 * Parameters: 255 * iv_fwd_entry - (IN) NIV Forward entry information 256 * Returns: 257 * BCM_E_XXX 258 * Notes: 259 * NIV Forward entry is a global entity, apply to all units. 260 */ 261 int 262 bcmx_niv_forward_add(bcmx_niv_forward_t *iv_fwd_entry) 263 { 264 int rv = BCM_E_UNAVAIL, tmp_rv; 265 int i, bcm_unit; 266 267 BCMX_NIV_INIT_CHECK; 268 269 BCMX_PARAM_NULL_CHECK(iv_fwd_entry); 270 271 272 BCMX_UNIT_ITER(bcm_unit, i) { 273 tmp_rv = bcm_niv_forward_add(bcm_unit, 274 BCMX_NIV_FORWARD_T_PTR_TO_BCM(iv_fwd_entry)); 275 BCM_IF_ERROR_RETURN 276 (BCMX_NIV_SET_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 277 } 278 279 return rv; 280 } 281 282 /* 283 * Function: 284 * bcmx_niv_forward_delete 285 * Purpose: 286 * Delete a NIV Forward entry. 287 * Parameters: 288 * iv_fwd_entry - (IN) NIV forward entry id to delete 289 * Returns: 290 * BCM_E_XXX 291 */ 292 int 293 bcmx_niv_forward_delete(bcmx_niv_forward_t *iv_fwd_entry) 294 { 295 int rv = BCM_E_UNAVAIL, tmp_rv; 296 int i, bcm_unit; 297 298 BCMX_NIV_INIT_CHECK; 299 300 BCMX_UNIT_ITER(bcm_unit, i) { 301 tmp_rv = bcm_niv_forward_delete(bcm_unit, iv_fwd_entry); 302 BCM_IF_ERROR_RETURN 303 (BCMX_NIV_DELETE_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 304 } 305 306 return rv; 307 } 308 309 /* 310 * Function: 311 * bcmx_niv_forward_delete_all 312 * Purpose: 313 * Delete all NIV Forwarding table entries. 314 * Parameters: 315 * None 316 * Returns: 317 * BCM_E_XXX 318 */ 319 int 320 bcmx_niv_forward_delete_all(void) 321 { 322 int rv = BCM_E_UNAVAIL, tmp_rv; 323 int i, bcm_unit; 324 325 BCMX_NIV_INIT_CHECK; 326 327 BCMX_UNIT_ITER(bcm_unit, i) { 328 tmp_rv = bcm_niv_forward_delete_all(bcm_unit); 329 BCM_IF_ERROR_RETURN 330 (BCMX_NIV_DELETE_ERROR_CHECK(bcm_unit, tmp_rv, &rv)); 331 } 332 333 return rv; 334 } 335 336 /* 337 * Function: 338 * bcmx_niv_forward_get 339 * Purpose: 340 * Get NIV Forwarding entry information for given ID. 341 * Parameters: 342 * iv_fwd_entry - (IN/OUT) NIV forwarding entry info 343 * Returns: 344 * BCM_E_XXX 345 */ 346 int 347 bcmx_niv_forward_get(bcmx_niv_forward_t *iv_fwd_entry) 348 { 349 int rv; 350 int i, bcm_unit; 351 352 BCMX_NIV_INIT_CHECK; 353 354 BCMX_PARAM_NULL_CHECK(iv_fwd_entry); 355 356 BCMX_UNIT_ITER(bcm_unit, i) { 357 rv = bcm_niv_forward_get(bcm_unit, 358 BCMX_NIV_FORWARD_T_PTR_TO_BCM(iv_fwd_entry)); 359 if (BCMX_NIV_GET_IS_VALID(bcm_unit, rv)) { 360 return rv; 361 } 362 } 363 364 return BCM_E_UNAVAIL; 365 } 366 367 #endif /* INCLUDE_L3 */