range.c (10558B)
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: range.c 8 * Purpose: Manages RANGE_CHECKER (IFP_RANGE_CHECK) 9 */ 10 11 #include <bcm/range.h> 12 #include <bcm/error.h> 13 14 #include <soc/defs.h> 15 16 #include <bcm_int/esw/range.h> 17 18 /* Function : bcm_esw_range_init 19 * 20 * Purpose : Initialize range module 21 * 22 * Parameters : unit - (IN) Unit number. 23 * 24 * Returns: 25 * BCM_E_NONE : Range Module initialized successfully. 26 * BCM_E_UNIT : Invalid BCM Unit number. 27 * BCM_E_UNAVAIL : Feature not supported. 28 * BCM_E_XXX : Standard error code. 29 */ 30 int 31 bcm_esw_range_init( int unit ) { 32 33 #if defined (BCM_TOMAHAWK_SUPPORT) 34 return bcmi_xgs5_range_init(unit); 35 #endif 36 37 return BCM_E_UNAVAIL; 38 } 39 40 /* Function : bcm_esw_range_detach 41 * 42 * Purpose : Detach range module 43 * 44 * Parameters : unit - (IN) Unit number. 45 * 46 * Returns: 47 * BCM_E_NONE : Range Module detached successfully. 48 * BCM_E_UNIT : Invalid BCM Unit number. 49 * BCM_E_UNAVAIL : Feature not supported. 50 * BCM_E_INIT : Range module not initialized. 51 * BCM_E_XXX : Standard error code. 52 */ 53 int 54 bcm_esw_range_detach( int unit ) { 55 56 #if defined (BCM_TOMAHAWK_SUPPORT) 57 return bcmi_xgs5_range_detach(unit); 58 #endif 59 60 return BCM_E_UNAVAIL; 61 } 62 63 /* Function : bcm_esw_range_create 64 * 65 * Purpose : This API is to create a Layer 4 TCP/UDP port range checker 66 * or a VLAN ranger checker or a packet length range checker or 67 * a UDF range checker and returns an identifier that can be 68 * passed to "bcm_field_qualify_RangeCheck" API, to qualify 69 * a Field entry with Range Checker match criteria. 70 * 71 * Parameters : unit - (IN) Unit number. 72 * flags - (IN) Flags to Range allocator 73 * range_config - (IN) Range Config Structure 74 * 75 * Returns: 76 * BCM_E_NONE : Range Module created successfully. 77 * BCM_E_EXISTS : Entry already exists. 78 * BCM_E_UNAVAIL : Feature not supported. 79 * BCM_E_INIT : Range module not initialized. 80 * BCM_E_RESOURCE : Range Ids are all allocated 81 * BCM_E_XXX : Standard error code. 82 */ 83 int 84 bcm_esw_range_create( 85 int unit, 86 int flags, 87 bcm_range_config_t *range_config) 88 { 89 int rv = BCM_E_UNAVAIL; 90 91 #if defined (BCM_TOMAHAWK_SUPPORT) 92 if (soc_feature(unit, soc_feature_field_multi_pipe_support)) { 93 /* Range Module Init Check */ 94 RANGE_INIT_CHECK(unit); 95 96 /* Range Module Lock */ 97 RANGE_LOCK(unit); 98 99 rv = bcmi_xgs5_range_create(unit, flags, range_config); 100 101 /* Unlock Range Module */ 102 RANGE_UNLOCK(unit); 103 104 } 105 106 #endif 107 108 return rv; 109 } 110 111 /* Function : bcm_esw_range_get 112 * 113 * Purpose : This API is to retrieve the operational configuration for the given range id. 114 * 115 * Parameters : range_config - (IN) Range Config Structure 116 * 117 * Returns : 118 * BCM_E_NONE : Range Module get successful 119 * BCM_E_NOT_FOUND : Range not found 120 * BCM_E_INIT : Range Module not initialized 121 * BCM_E_UNAVAIL : Feature not supported. 122 * BCM_E_XXX : Standard error code. 123 */ 124 int 125 bcm_esw_range_get( 126 int unit, 127 bcm_range_config_t *range_config) 128 { 129 int rv = BCM_E_UNAVAIL; 130 131 #if defined (BCM_TOMAHAWK_SUPPORT) 132 133 if (soc_feature(unit, soc_feature_field_multi_pipe_support)) { 134 /* Range Module Init Check */ 135 RANGE_INIT_CHECK(unit); 136 137 /* Range Module Lock */ 138 RANGE_LOCK(unit); 139 140 rv = bcmi_xgs5_range_get(unit, range_config); 141 /* Unlock Range Module */ 142 RANGE_UNLOCK(unit); 143 144 } 145 146 147 #endif 148 149 return rv; 150 } 151 152 /* 153 * Function : bcm_esw_range_destroy 154 * 155 * Purpose : Destroys a range checker and releases resources allocated to the range checker. 156 * Hardware resources will also be freed. But this API will return BCM_E_BUSY, 157 * if the range checker is in use. 158 * 159 * Parameters : unit - (IN) Unit number. 160 * rid - (IN) Range ID. 161 * 162 * Returns: 163 * BCM_E_NONE : Range deleted successfully 164 * BCM_E_NOT_FOUND : Range does not exist 165 * BCM_E_INIT : Range module not initialised 166 * BCM_E_UNAVAIL : Feature not supported 167 * BCM_E_XXX : Standard error code 168 */ 169 int 170 bcm_esw_range_destroy( 171 int unit, 172 bcm_range_t rid) 173 { 174 int rv = BCM_E_UNAVAIL; 175 176 #if defined (BCM_TOMAHAWK_SUPPORT) 177 178 if (soc_feature(unit, soc_feature_field_multi_pipe_support)) { 179 /* Range Module Init Check */ 180 RANGE_INIT_CHECK(unit); 181 182 /* Range Module Lock */ 183 RANGE_LOCK(unit); 184 rv = bcmi_xgs5_range_destroy(unit, rid); 185 186 /* Unlock Range Module */ 187 RANGE_UNLOCK(unit); 188 189 } 190 #endif 191 192 return rv; 193 } 194 /* 195 * Function : bcm_esw_range_traverse 196 * 197 * Purpose : Traverse all the valid range ids in the system, calling a specified 198 * callback for each one 199 * 200 * Parameters : unit - (IN) Unit number. 201 * callback - (IN) A pointer to the callback function to call for each range 202 * user_data - (IN) Pointer to user data to supply in the callback 203 * 204 * Returns : 205 * BCM_E_XXX 206 */ 207 int 208 bcm_esw_range_traverse( 209 int unit, 210 bcm_range_traverse_cb callback, 211 void *user_data) 212 { 213 #if defined (BCM_TOMAHAWK_SUPPORT) 214 return bcmi_xgs5_range_traverse(unit, callback, user_data); 215 #endif 216 return BCM_E_UNAVAIL; 217 } 218 /* 219 * Function : bcm_esw_range_oper_mode_set 220 * 221 * Purpose : Configure Operational mode of Range Module to either Global or Pipe Local. 222 * 223 * Parameters : 224 * unit - (IN) BCM Device number. 225 * oper_mode - (IN) Range Operational Mode enum value. 226 * Returns : 227 * BCM_E_NONE : Operation successful. 228 * BCM_E_PARAM : Invalid operational mode. 229 * BCM_E_UNIT : Range module not initialized. 230 * BCM_E_BUSY : Ranges are already existing. Hence cannot change 231 * operational mode 232 */ 233 int 234 bcm_esw_range_oper_mode_set( 235 int unit, 236 bcm_range_oper_mode_t oper_mode) 237 { 238 #if defined (BCM_TOMAHAWK_SUPPORT) 239 if (0 == soc_feature(unit, soc_feature_field_single_pipe_support)) { 240 return bcmi_xgs5_range_oper_mode_set(unit, oper_mode); 241 } 242 #endif 243 return BCM_E_UNAVAIL; 244 } 245 246 /* 247 * Function : bcm_esw_range_oper_mode_get 248 * 249 * Purpose : Get current operational mode of the Range Module. 250 * 251 * Parameters : unit - (IN) BCM Device number. 252 * oper_mode-(OUT) Reference to Range Operational Mode value. 253 * Returns : 254 * BCM_E_NONE : Operation successful. 255 * BCM_E_PARAM : Invalid parameter. 256 * BCM_E_UNIT : Range module not initialized. 257 */ 258 int bcm_esw_range_oper_mode_get( 259 int unit, 260 bcm_range_oper_mode_t *oper_mode) 261 { 262 #if defined (BCM_TOMAHAWK_SUPPORT) 263 if (0 == soc_feature(unit, soc_feature_field_single_pipe_support)) { 264 return bcmi_xgs5_range_oper_mode_get(unit, oper_mode); 265 } 266 #endif 267 return BCM_E_UNAVAIL; 268 } 269 /* 270 * Function : _bcm_esw_range_scache_sync 271 * 272 * Purpose : Update the scache based on the latest range module state 273 * 274 * Parameters: unit - (IN) BCM Device number. 275 * 276 * Returns : BCM_E_XXX 277 */ 278 int _bcm_esw_range_scache_sync( 279 int unit) 280 { 281 #if defined (BCM_TOMAHAWK_SUPPORT) 282 #if defined BCM_WARM_BOOT_SUPPORT 283 return bcmi_xgs5_range_wb_sync(unit); 284 #endif 285 #endif 286 return BCM_E_UNAVAIL; 287 } 288 289 /* 290 * This API will help to combine different Range Checkers into a single 291 * group. It returns a range group identifier that can be passed to 292 * 'bcm_field_qualify_RangeGroup' API, to qualify a Field entry with 293 * Range Group match criteria. The Individual RangeCheck conditions and 294 * its IDs has to be created separately using bcm_range_create API. 295 */ 296 int bcm_esw_range_group_create( 297 int unit, 298 bcm_range_group_config_t *range_group_config) 299 { 300 int rv = BCM_E_UNAVAIL; 301 302 303 #if defined (BCM_TOMAHAWK_SUPPORT) 304 305 if (soc_feature(unit, soc_feature_range_check_group_support)) { 306 /* Range Module Init Check */ 307 RANGE_INIT_CHECK(unit); 308 309 /* Range Module Lock */ 310 RANGE_LOCK(unit); 311 rv = bcmi_xgs5_range_group_create(unit, range_group_config); 312 313 /* Unlock Range Module */ 314 RANGE_UNLOCK(unit); 315 } 316 317 318 #endif 319 320 return rv; 321 } 322 323 324 /* 325 * This API will help to delete the range group created using 326 * bcm_range_group_create. 327 */ 328 int bcm_esw_range_group_delete( 329 int unit, 330 bcm_range_group_config_t *range_group_config) 331 { 332 int rv = BCM_E_UNAVAIL; 333 334 #if defined (BCM_TOMAHAWK_SUPPORT) 335 336 if (soc_feature(unit, soc_feature_range_check_group_support)) { 337 /* Range Module Init Check */ 338 RANGE_INIT_CHECK(unit); 339 340 /* Range Module Lock */ 341 RANGE_LOCK(unit); 342 343 rv = bcmi_xgs5_range_group_delete(unit, range_group_config); 344 345 /* Unlock Range Module */ 346 RANGE_UNLOCK(unit); 347 348 } 349 350 #endif 351 return rv; 352 353 } 354 355 /* 356 * This API will help to update the range IDs in the range group created 357 * using bcm_range_group_create. 358 */ 359 int bcm_esw_range_group_update( 360 int unit, 361 bcm_range_group_config_t *range_group_config) 362 { 363 int rv = BCM_E_UNAVAIL; 364 365 #if defined (BCM_TOMAHAWK_SUPPORT) 366 if (soc_feature(unit, soc_feature_range_check_group_support)) { 367 /* Range Module Init Check */ 368 RANGE_INIT_CHECK(unit); 369 370 /* Range Module Lock */ 371 RANGE_LOCK(unit); 372 373 rv = bcmi_xgs5_range_group_update(unit, range_group_config); 374 /* Unlock Range Module */ 375 RANGE_UNLOCK(unit); 376 } 377 #endif 378 return rv; 379 380 } 381 382 /* 383 * This API will help to fetch the range group configuration created 384 * using bcm_range_group_create. 385 */ 386 int bcm_esw_range_group_get( 387 int unit, 388 bcm_range_group_config_t *range_group_config) 389 { 390 int rv = BCM_E_UNAVAIL; 391 392 #if defined (BCM_TOMAHAWK_SUPPORT) 393 if (soc_feature(unit, soc_feature_range_check_group_support)) { 394 /* Range Module Init Check */ 395 RANGE_INIT_CHECK(unit); 396 397 /* Range Module Lock */ 398 RANGE_LOCK(unit); 399 rv = bcmi_xgs5_range_group_get(unit, range_group_config); 400 /* Unlock Range Module */ 401 RANGE_UNLOCK(unit); 402 } 403 #endif 404 405 return rv; 406 }