mpls.c (7408B)
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: mpls.c 8 * Purpose: Handle trident2plus specific MPLS APIs 9 */ 10 11 12 #include <shared/bsl.h> 13 14 #include <soc/defs.h> 15 #include <sal/core/libc.h> 16 17 #ifdef INCLUDE_L3 18 #ifdef BCM_MPLS_SUPPORT 19 #ifdef BCM_TRIDENT2PLUS_SUPPORT 20 21 #include <soc/drv.h> 22 #include <soc/mem.h> 23 #include <soc/util.h> 24 #include <soc/debug.h> 25 26 #include <bcm/types.h> 27 #include <bcm/error.h> 28 29 #include <bcm_int/esw/trident2plus.h> 30 31 /* 32 * Function: 33 * bcm_mpls_entropy_identifier_add 34 * Purpose: 35 * Add an MPLS entropy label identifier 36 * Parameters: 37 * unit - Device Number 38 * info - Entropy Label information 39 * Returns: 40 * BCM_E_XXX 41 */ 42 int 43 bcm_td2p_mpls_entropy_identifier_add( 44 int unit, 45 uint32 options, 46 bcm_mpls_entropy_identifier_t *info) 47 { 48 int rv = BCM_E_NONE; 49 uint64 val64; 50 mpls_entropy_label_data_entry_t label_data; 51 52 /* Input parameters check. */ 53 if (NULL == info) { 54 return BCM_E_PARAM; 55 } 56 57 if (!BCM_TD2P_ENTROPY_LABEL_ID_VALID(info->label) || 58 !BCM_TD2P_ENTROPY_LABEL_MASK_VALID(info->mask)) { 59 return BCM_E_PARAM; 60 } 61 62 COMPILER_64_ZERO(val64); 63 BCM_IF_ERROR_RETURN(READ_MPLS_ENTROPY_LABEL_CONFIG_64r(unit, &val64)); 64 soc_reg64_field32_set(unit, MPLS_ENTROPY_LABEL_CONFIG_64r, &val64, 65 VALIDf, 1); 66 soc_reg64_field32_set(unit, MPLS_ENTROPY_LABEL_CONFIG_64r, &val64, 67 VALUEf, info->label); 68 soc_reg64_field32_set(unit, MPLS_ENTROPY_LABEL_CONFIG_64r, &val64, 69 MASKf, info->mask); 70 BCM_IF_ERROR_RETURN(WRITE_MPLS_ENTROPY_LABEL_CONFIG_64r(unit, val64)); 71 72 sal_memset(&label_data, 0, sizeof(label_data)); 73 soc_MPLS_ENTROPY_LABEL_DATAm_field32_set(unit, &label_data, VALIDf, 1); 74 soc_MPLS_ENTROPY_LABEL_DATAm_field32_set(unit, &label_data, 75 MPLS_ACTION_IF_NOT_BOSf, 1); 76 WRITE_MPLS_ENTROPY_LABEL_DATAm(unit, MEM_BLOCK_ALL, 0, &label_data); 77 78 return rv; 79 } 80 81 /* 82 * Function: 83 * bcm_mpls_entropy_identifier_delete 84 * Purpose: 85 * Delete an MPLS entropy label identifier 86 * If no label information is passed, return error. 87 * Parameters: 88 * unit - Device Number 89 * info - Entropy Label information 90 * Returns: 91 * BCM_E_XXX 92 */ 93 int 94 bcm_td2p_mpls_entropy_identifier_delete( 95 int unit, 96 bcm_mpls_entropy_identifier_t *info) 97 { 98 int rv = BCM_E_NONE; 99 uint64 val64; 100 int valid; 101 bcm_mpls_label_t entropy_label; 102 bcm_mpls_label_t entropy_mask; 103 mpls_entropy_label_data_entry_t label_data; 104 105 /* Input parameters check. */ 106 if (NULL == info) { 107 return BCM_E_PARAM; 108 } 109 110 BCM_IF_ERROR_RETURN(READ_MPLS_ENTROPY_LABEL_CONFIG_64r(unit, 111 &val64)); 112 valid = soc_reg64_field32_get(unit, 113 MPLS_ENTROPY_LABEL_CONFIG_64r, val64, VALIDf); 114 if (!valid) { 115 return BCM_E_EMPTY; 116 } 117 118 if (!BCM_TD2P_ENTROPY_LABEL_ID_VALID(info->label) || 119 !BCM_TD2P_ENTROPY_LABEL_MASK_VALID(info->mask)) { 120 return BCM_E_PARAM; 121 } else { 122 entropy_label = soc_reg64_field32_get(unit, 123 MPLS_ENTROPY_LABEL_CONFIG_64r, val64, VALUEf); 124 entropy_mask = soc_reg64_field32_get(unit, 125 MPLS_ENTROPY_LABEL_CONFIG_64r, val64, MASKf); 126 if ((info->label != entropy_label) || (info->mask != entropy_mask)) { 127 return BCM_E_NOT_FOUND; 128 } 129 } 130 131 COMPILER_64_ZERO(val64); 132 BCM_IF_ERROR_RETURN(WRITE_MPLS_ENTROPY_LABEL_CONFIG_64r(unit, val64)); 133 134 sal_memset(&label_data, 0, sizeof(label_data)); 135 WRITE_MPLS_ENTROPY_LABEL_DATAm(unit, MEM_BLOCK_ALL, 0, &label_data); 136 137 return rv; 138 } 139 140 /* 141 * Function: 142 * bcm_mpls_entropy_identifier_delete_all 143 * Purpose: 144 * Delete all MPLS entropy label identifier entries. 145 * Parameters: 146 * unit - Device Number 147 * Returns: 148 * BCM_E_XXX 149 */ 150 int 151 bcm_td2p_mpls_entropy_identifier_delete_all( 152 int unit) 153 { 154 int rv = BCM_E_NONE; 155 uint64 val64; 156 mpls_entropy_label_data_entry_t label_data; 157 158 COMPILER_64_ZERO(val64); 159 BCM_IF_ERROR_RETURN(WRITE_MPLS_ENTROPY_LABEL_CONFIG_64r(unit, val64)); 160 161 sal_memset(&label_data, 0, sizeof(label_data)); 162 WRITE_MPLS_ENTROPY_LABEL_DATAm(unit, MEM_BLOCK_ALL, 0, &label_data); 163 164 return rv; 165 } 166 167 /* 168 * Function: 169 * bcm_mpls_entropy_identifier_get 170 * Purpose: 171 * Get an MPLS entropy label identifier entry 172 * If no label info is passed, return the only configured 173 * entropy label. 174 * Parameters: 175 * unit - Device Number 176 * info - Entropy Label information 177 * Returns: 178 * BCM_E_XXX 179 */ 180 int 181 bcm_td2p_mpls_entropy_identifier_get( 182 int unit, 183 bcm_mpls_entropy_identifier_t *info) 184 { 185 int rv = BCM_E_NONE; 186 uint64 val64; 187 int valid; 188 bcm_mpls_label_t entropy_label; 189 bcm_mpls_label_t entropy_mask; 190 191 /* Input parameters check. */ 192 if (NULL == info) { 193 return BCM_E_PARAM; 194 } 195 196 BCM_IF_ERROR_RETURN(READ_MPLS_ENTROPY_LABEL_CONFIG_64r(unit, 197 &val64)); 198 valid = soc_reg64_field32_get(unit, 199 MPLS_ENTROPY_LABEL_CONFIG_64r, val64, VALIDf); 200 if (!valid) { 201 return BCM_E_EMPTY; 202 } 203 204 if (BCM_TD2P_ENTROPY_LABEL_ID_VALID(info->label) && 205 BCM_TD2P_ENTROPY_LABEL_MASK_VALID(info->mask)) { 206 entropy_label = soc_reg64_field32_get(unit, 207 MPLS_ENTROPY_LABEL_CONFIG_64r, val64, VALUEf); 208 entropy_mask = soc_reg64_field32_get(unit, 209 MPLS_ENTROPY_LABEL_CONFIG_64r, val64, MASKf); 210 if ((info->label & info->mask) != (entropy_label & entropy_mask)) { 211 return BCM_E_NOT_FOUND; 212 } 213 } 214 215 info->label = soc_reg64_field32_get(unit, 216 MPLS_ENTROPY_LABEL_CONFIG_64r, val64, VALUEf); 217 info->mask = soc_reg64_field32_get(unit, 218 MPLS_ENTROPY_LABEL_CONFIG_64r, val64, MASKf); 219 220 return rv; 221 } 222 223 /* 224 * Function: 225 * bcm_mpls_entropy_identifier_traverse 226 * Purpose: 227 * Traverse all valid MPLS entropy label identifier entries 228 * and call the supplied callback routine. 229 * Parameters: 230 * unit - Device Number 231 * cb - User callback function, called once per MPLS ELI entry. 232 * user_data - cookie 233 * Returns: 234 * BCM_E_XXX 235 */ 236 int 237 bcm_td2p_mpls_entropy_identifier_traverse( 238 int unit, 239 bcm_mpls_entropy_identifier_traverse_cb cb, 240 void *user_data) 241 { 242 int rv = BCM_E_NONE; 243 uint64 val64; 244 int valid; 245 bcm_mpls_entropy_identifier_t entropy_info; 246 247 sal_memset(&entropy_info, 0, sizeof(entropy_info)); 248 BCM_IF_ERROR_RETURN(READ_MPLS_ENTROPY_LABEL_CONFIG_64r(unit, 249 &val64)); 250 valid = soc_reg64_field32_get(unit, 251 MPLS_ENTROPY_LABEL_CONFIG_64r, val64, VALIDf); 252 if (!valid) { 253 return BCM_E_EMPTY; 254 } 255 256 entropy_info.label = soc_reg64_field32_get(unit, 257 MPLS_ENTROPY_LABEL_CONFIG_64r, val64, VALUEf); 258 entropy_info.mask = soc_reg64_field32_get(unit, 259 MPLS_ENTROPY_LABEL_CONFIG_64r, val64, MASKf); 260 261 rv = cb(unit, &entropy_info, user_data); 262 #ifdef BCM_CB_ABORT_ON_ERR 263 if (BCM_FAILURE(rv) && SOC_CB_ABORT_ON_ERR(unit)) { 264 return rv; 265 } 266 #endif 267 268 return rv; 269 } 270 #endif /* BCM_TRIDENT2PLUS_SUPPORT */ 271 #endif /* BCM_MPLS_SUPPORT */ 272 #endif /* INCLUDE_L3 */