sat.c (86328B)
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 * BCM layer SAT APIs 8 */ 9 10 #include <shared/bsl.h> 11 #include <bcm/error.h> 12 #include <bcm/pkt.h> 13 #include <bcm_int/control.h> 14 #include <bcm_int/common/sat.h> 15 #include <bcm_int/common/debug.h> 16 #if defined(BCM_DPP_SUPPORT) 17 #include <bcm_int/dpp/oam.h> 18 #include <soc/dpp/ARAD/arad_chip_defines.h> 19 #endif 20 #include <bcm/sat.h> 21 #if defined(BCM_SABER2_SUPPORT) 22 #include <bcm_int/esw/saber2.h> 23 #endif /* BCM_SABER2_SUPPORT */ 24 #include <sal/core/alloc.h> 25 26 #include <soc/drv.h> 27 #include <soc/shared/mbcm_sat.h> 28 29 #ifdef BCM_WARM_BOOT_SUPPORT 30 #include <soc/scache.h> 31 #include <bcm/module.h> 32 #endif 33 34 #ifdef CRASH_RECOVERY_SUPPORT 35 #include <soc/dcmn/dcmn_crash_recovery.h> 36 #endif 37 38 #define _BCM_SAT_NUM_CLKS_PER_SEC_JERICHO 720000000 39 #define _BCM_SAT_NUM_CLKS_PER_SEC_SABER2 130000000 40 #define _BCM_SAT_BPS_MODE 0x1 41 #define _BCM_SAT_PPS_MODE 0x2 42 #define _BCM_SAT_CMIC_TOD_MODE 0x2 43 #define _BCM_SAT_RATE_NUM_CLKS_CYCLE 720000 44 #define _BCM_SAT_PAYLOAD_OFFSET_MIN 0 45 #define _BCM_SAT_PAYLOAD_OFFSET_MAX 0xFFFF 46 #define _BCM_SAT_SEQ_NUM_OFFSET_MIN -1 47 #define _BCM_SAT_SEQ_NUM_OFFSET_MAX 0xFFFF 48 #define _BCM_SAT_TIME_STAMP_OFFSET_MIN 0 49 #define _BCM_SAT_TIME_STAMP_OFFSET_MAX 0xFFFF 50 #define _BCM_SAT_CRC_BYTE_OFFSET_MIN 0 51 #define _BCM_SAT_CRC_BYTE_OFFSET_MAX 0xFFFF 52 #define _BCM_SAT_MEF_PAYLOAD_OFFSET 41 53 #define _BCM_SAT_MEF_SEQ_NUM_OFFSET 30 54 #define _BCM_SAT_MEF_TIME_STAMP_OFFSET 0 55 #define _BCM_SAT_MEF_CRC_BYTE_OFFSET_OFFSET 20 56 #define _BCM_SAT_Y1731_PAYLOAD_OFFSET 0 57 #define _BCM_SAT_Y1731_SEQ_NUM_OFFSET 0 58 #define _BCM_SAT_Y1731_TIME_STAMP_OFFSET 22 59 #define _BCM_SAT_Y1731_CRC_BYTE_OFFSET_OFFSET 20 60 61 #define _BCM_SAT_GTF_ID_MIN 0 62 #define _BCM_SAT_GTF_ID_MAX 7 63 64 #define _BCM_SAT_GTF_OBJ_COMMON -1 65 #define _BCM_SAT_GTF_OBJ_CIR 0 66 #define _BCM_SAT_GTF_OBJ_EIR 1 67 68 #define _BCM_SAT_GTF_PKT_HDR_LEN_MIN 1 69 #define _BCM_SAT_GTF_PKT_HDR_LEN_MAX 127 70 #define _BCM_SAT_GTF_PKT_LEN_PATN_INX_MIN 0 71 #define _BCM_SAT_GTF_PKT_LEN_PATN_INX_MAX 7 72 #define _BCM_SAT_GTF_SEQ_PERIOD_MIN 1 73 #define _BCM_SAT_GTF_SEQ_PERIOD_MAX 4 74 #define _BCM_SAT_GTF_STAMP_INC_STEP_MIN 1 75 #define _BCM_SAT_GTF_STAMP_INC_STEP_MAX 0x7f 76 #define _BCM_SAT_GTF_STAMP_INC_PERIOD_MIN 0 77 #define _BCM_SAT_GTF_STAMP_INC_PERIOD_MAX 0x3 78 #define _BCM_SAT_GTF_STAMP_2_bit_VALUE_MIN 0 79 #define _BCM_SAT_GTF_STAMP_2_bit_VALUE_MAX 0x3 80 81 #define _BCM_SAT_GTF_BW_RATE_MAX 23000000 /* 23Gbits */ 82 #define _BCM_SAT_GTF_BW_RATE_MIN 0 83 #define _BCM_SAT_GTF_BW_BURST_MAX (0x7fff8000/125) /* 0xffff*(1<<15)*8/1000 */ 84 #define _BCM_SAT_GTF_BW_BURST_MIN 0 85 #define _BCM_SAT_GTF_RATE_PATN_HIGH_TH_MAX 23000000 /* 23Gbits */ 86 #define _BCM_SAT_GTF_RATE_PATN_HIGH_TH_MIN 1 87 #define _BCM_SAT_GTF_RATE_PATN_LOW_TH_MAX 23000000 /* 23Gbits */ 88 #define _BCM_SAT_GTF_RATE_PATN_LOW_TH_MIN 1 89 #define _BCM_SAT_GTF_RATE_PATN_STOP_ITER_MAX 0x3ff 90 #define _BCM_SAT_GTF_RATE_PATN_STOP_ITER_MIN 0 91 #define _BCM_SAT_GTF_RATE_PATN_STOP_BURST_MAX 0xffffffff 92 #define _BCM_SAT_GTF_RATE_PATN_STOP_BURST_MIN 0 93 #define _BCM_SAT_GTF_RATE_PATN_STOP_INTERVAL_MAX 0xffffffff 94 #define _BCM_SAT_GTF_RATE_PATN_STOP_INTERVAL_MIN 0 95 #define _BCM_SAT_GTF_RATE_PATN_BURST_PACKET_WEIGHT_MAX 0xffffffff 96 #define _BCM_SAT_GTF_RATE_PATN_BURST_PACKET_WEIGHT_MIN 0 97 #define _BCM_SAT_GTF_RATE_PATN_INTERVAL_PACKET_WEIGHT_MAX 0xffffffff 98 #define _BCM_SAT_GTF_RATE_PATN_INTERVAL_PACKET_WEIGHT_MIN 0 99 100 #define _BCM_SAT_CTF_TRAP_ID_MAX_NUM 3 101 #define _BCM_SAT_CTF_ID_MIN 0 102 #define _BCM_SAT_CTF_ID_MAX 31 103 #define _BCM_SAT_CTF_OAM_ID_MIN 0 104 #define _BCM_SAT_CTF_OAM_ID_MAX 15 105 #define _BCM_SAT_CTF_TRAP_ID_MIN 0 106 #define _BCM_SAT_CTF_TRAP_ID_MAX 3 107 #define _BCM_SAT_CTF_COLOR_MIN 0 108 #define _BCM_SAT_CTF_COLOR_MAX 3 109 #define _BCM_SAT_CTF_COS_MIN 0 110 #define _BCM_SAT_CTF_COS_MAX 7 111 #define _BCM_SAT_CTF_TRAP_ID_VAL_MIN 0 112 #define _BCM_SAT_CTF_TRAP_ID_VAL_MAX 255 113 #define _BCM_SAT_CTF_TRAP_ID_UNSET_VAL 0x0 114 #define _BCM_SAT_CTF_BINS_LIMIT_CNT_MIN 1 115 #define _BCM_SAT_CTF_BINS_LIMIT_CNT_MAX 9 116 #define _BCM_SAT_CTF_BINS_LIMIT_SELECT_MAX 8 117 #define _BCM_SAT_CTF_SWITCH_STATE_NUM_OF_SLOTS_MIN 0 118 #define _BCM_SAT_CTF_SWITCH_STATE_NUM_OF_SLOTS_MAX 31 119 #define _BCM_SAT_CTF_SWITCH_STATE_THRES_PER_SLOT_MIN 0 120 #define _BCM_SAT_CTF_SWITCH_STATE_THRES_PER_SLOT_MAX 0x1FFFFFF 121 #define _BCM_SAT_CTF_REPORT_SAMPLING_PER_MAX 100 122 #define _BCM_SAT_CTF_TRAP_DATA_MIN 0x0 123 #define _BCM_SAT_CTF_TRAP_DATA_MAX 0x3FFF 124 #define _BCM_SAT_CTF_TRAP_DATA_MASK_MIN 0x0 125 #define _BCM_SAT_CTF_TRAP_DATA_MASK_MAX 0x3FFF 126 #define _BCM_SAT_CTF_TRAP_DATA_ENTRY_NUM 16 127 #define _BCM_SAT_CTF_TRAP_DATA_SSID_MAX 0xF 128 129 130 typedef struct _bcm_sat_ctf_trap_data_s { 131 uint16 trap_data; 132 uint16 trap_mask; 133 uint8 ssid; 134 }_bcm_sat_ctf_trap_data_t; 135 136 typedef struct _bcm_sat_data_s { 137 uint32 ctf_id_bitmap; 138 uint32 gtf_id_bitmap; 139 uint32 ctf_trap_id[_BCM_SAT_CTF_TRAP_ID_MAX_NUM]; 140 uint32 ctf_trap_bitmap; 141 uint32 ctf_ssid_bitmap; 142 _bcm_sat_ctf_trap_data_t trap_data[_BCM_SAT_CTF_TRAP_DATA_ENTRY_NUM]; 143 sal_mutex_t sat_mutex; /* SAT mutex */ 144 uint8 rate_mode; /*1: bps 2:pps*/ 145 uint8 granularity_flag; /*flag for granularity */ 146 uint8 is_dirty; 147 } _bcm_sat_data_t; 148 149 150 _bcm_sat_data_t sat_data[BCM_UNITS_MAX]; 151 152 /* Callbacks are not supported by warmboot. Need re-register after warmboot */ 153 #ifdef BCM_SAT_SUPPORT 154 static bcm_sat_event_cb _bcm_sat_event_cb[BCM_UNITS_MAX][bcmSATEventCount]; 155 static void *_bcm_sat_event_ud[BCM_UNITS_MAX][bcmSATEventCount]; 156 #endif /* BCM_SAT_SUPPORT */ 157 158 #define SAT_NULL_CHECK(p, para_name) \ 159 if (p == NULL) { \ 160 LOG_ERROR(BSL_LS_BCM_SAT, \ 161 (BSL_META_U(unit, \ 162 "Fail(%s) parameter(%s) is NULL\n"), \ 163 soc_errmsg(BCM_E_PARAM), para_name)); \ 164 return BCM_E_PARAM; \ 165 } 166 167 #define SAT_VALUE_CHECK(val, min, max, para_name) \ 168 if ((val) < (min) || (val) >= (max)) { \ 169 LOG_ERROR(BSL_LS_BCM_SAT, \ 170 (BSL_META_U(unit, \ 171 "Fail(%s) parameter(%s=%d) should be in range of [%d, %d]\n"), \ 172 soc_errmsg(BCM_E_PARAM), para_name, val, min, (max-1))); \ 173 return BCM_E_PARAM; \ 174 } 175 176 #define SAT_VALUE_MAX_CHECK(val, max, para_name) \ 177 if ((val) >= (max)) { \ 178 LOG_ERROR(BSL_LS_BCM_SAT, \ 179 (BSL_META_U(unit, \ 180 "Fail(%s) parameter(%s=%d) should be less than %d\n"), \ 181 soc_errmsg(BCM_E_PARAM), para_name, val, max)); \ 182 return BCM_E_PARAM; \ 183 } 184 185 186 #define SAT_BITMAP_EXIST(bitmap, index) \ 187 ((bitmap) & (1U << (index))) 188 #define SAT_BITMAP_SET(bitmap, index) \ 189 ((bitmap) |= (1U << (index))) 190 #define SAT_BITMAP_CLR(bitmap, index) \ 191 ((bitmap) &= (~(1U << (index)))) 192 193 /* GTF ID */ 194 #define SAT_GTF_ID_EXIST(psat_data, gtf_id) \ 195 SAT_BITMAP_EXIST((psat_data)->gtf_id_bitmap, gtf_id) 196 #define SAT_GTF_ID_SET(psat_data, gtf_id) \ 197 SAT_BITMAP_SET((psat_data)->gtf_id_bitmap, gtf_id) 198 #define SAT_GTF_ID_CLR(psat_data, gtf_id) \ 199 SAT_BITMAP_CLR((psat_data)->gtf_id_bitmap, gtf_id) 200 #define SAT_GTF_ID_CLR_ALL(psat_data) \ 201 ((psat_data)->gtf_id_bitmap = 0) 202 #define SAT_GTF_ID_NOT_EXIST_EXIT(psat_data, gtf_id) \ 203 if (!SAT_GTF_ID_EXIST(psat_data, gtf_id)) {\ 204 LOG_ERROR(BSL_LS_BCM_SAT, \ 205 (BSL_META_U(unit, \ 206 "Fail(%s) gtf_id(%d) does not exist\n"), \ 207 soc_errmsg(BCM_E_NOT_FOUND), gtf_id)); \ 208 return BCM_E_NOT_FOUND; \ 209 } 210 211 /* CTF ID */ 212 #define SAT_CTF_ID_EXIST(psat_data, ctf_id) \ 213 SAT_BITMAP_EXIST((psat_data)->ctf_id_bitmap, ctf_id) 214 #define SAT_CTF_ID_SET(psat_data, ctf_id) \ 215 SAT_BITMAP_SET((psat_data)->ctf_id_bitmap, ctf_id) 216 #define SAT_CTF_ID_CLR(psat_data, ctf_id) \ 217 SAT_BITMAP_CLR((psat_data)->ctf_id_bitmap, ctf_id) 218 #define SAT_CTF_ID_CLR_ALL(psat_data) \ 219 ((psat_data)->ctf_id_bitmap = 0) 220 #define SAT_CTF_ID_NOT_EXIST_EXIT(psat_data, ctf_id) \ 221 if (!SAT_CTF_ID_EXIST(psat_data, ctf_id)) {\ 222 LOG_ERROR(BSL_LS_BCM_SAT, \ 223 (BSL_META_U(unit, \ 224 "Fail(%s) ctf_id(%d) does not exist\n"), \ 225 soc_errmsg(BCM_E_NOT_FOUND), ctf_id)); \ 226 return BCM_E_NOT_FOUND; \ 227 } 228 229 /* CTF TRAP ID */ 230 #define SAT_CTF_TRAP_ID_EXIST(psat_data, trap_idx) \ 231 SAT_BITMAP_EXIST((psat_data)->ctf_trap_bitmap, trap_idx) 232 #define SAT_CTF_TRAP_ID_SET(psat_data, trap_idx, trap_id) \ 233 (psat_data)->ctf_trap_id[trap_idx] = trap_id; \ 234 SAT_BITMAP_SET((psat_data)->ctf_trap_bitmap, trap_idx) 235 #define SAT_CTF_TRAP_ID_CLR(psat_data, trap_idx) \ 236 (psat_data)->ctf_trap_id[trap_idx] = _BCM_SAT_CTF_TRAP_ID_UNSET_VAL; \ 237 SAT_BITMAP_CLR((psat_data)->ctf_trap_bitmap, trap_idx) 238 #define SAT_CTF_TRAP_ID_CLR_ALL(psat_data) \ 239 ((psat_data)->ctf_trap_bitmap = 0); \ 240 for (trap_idx = 0; trap_idx < _BCM_SAT_CTF_TRAP_ID_MAX_NUM; trap_idx++) { \ 241 (psat_data)->ctf_trap_id[trap_idx] = _BCM_SAT_CTF_TRAP_ID_UNSET_VAL; \ 242 } 243 244 #define _BCM_SAT_SYSTEM_LOCK(unit) \ 245 sal_mutex_take(sat_data[unit].sat_mutex, sal_mutex_FOREVER) 246 #define _BCM_SAT_SYSTEM_UNLOCK(unit) sal_mutex_give(sat_data[unit].sat_mutex) 247 248 #ifdef BCM_WARM_BOOT_SUPPORT 249 #define SAT_WB_VERSION_1_0 SOC_SCACHE_VERSION(1,0) 250 #define SAT_WB_CURRENT_VERSION SAT_WB_VERSION_1_0 251 #ifdef BCM_SAT_SUPPORT 252 STATIC int bcm_common_sat_wb_init(int unit); 253 STATIC int _bcm_common_sat_trap_id_find (_bcm_sat_data_t* psat_data,uint32 trap_id, int32* trap_idx); 254 #endif /* BCM_SAT_SUPPORT */ 255 #endif /* BCM_WARM_BOOT_SUPPORT */ 256 #ifdef BCM_SAT_SUPPORT 257 static uint8 _bcm_common_sat_rate_mode_get(int unit) { 258 return sat_data[unit].rate_mode; 259 } 260 static uint8 _bcm_common_sat_rate_mode_set(int unit, uint8 rate_mode) { 261 sat_data[unit].rate_mode = rate_mode; 262 return BCM_E_NONE; 263 } 264 static uint8 _bcm_common_sat_granularity_flag_get(int unit) { 265 return sat_data[unit].granularity_flag; 266 } 267 static uint8 _bcm_common_sat_granularity_flag_set(int unit, int flag) { 268 sat_data[unit].granularity_flag = flag; 269 return BCM_E_NONE; 270 } 271 272 #endif /* BCM_SAT_SUPPORT */ 273 /* Functions */ 274 275 #if defined(BCM_SAT_SUPPORT) || defined(BCM_WARM_BOOT_SUPPORT) 276 static _bcm_sat_data_t* sat_data_get(int unit) { 277 #ifdef CRASH_RECOVERY_SUPPORT 278 soc_dcmn_cr_suppress(unit, dcmn_cr_no_support_sat); 279 #endif 280 sat_data[unit].is_dirty = TRUE; 281 return &(sat_data[unit]); 282 } 283 284 #endif 285 286 #ifdef BCM_WARM_BOOT_SUPPORT 287 static uint8 _bcm_common_sat_is_dirty(int unit) { 288 return sat_data[unit].is_dirty; 289 } 290 291 static void _bcm_commot_sat_mark_not_dirty(int unit) { 292 sat_data[unit].is_dirty = FALSE; 293 294 } 295 #endif 296 297 #ifdef BCM_SAT_SUPPORT 298 299 int bcm_common_sat_init(int unit) 300 { 301 int rv = BCM_E_UNAVAIL; 302 303 _bcm_sat_data_t *psat_data; 304 soc_sat_init_t soc_sat_init; 305 uint32 freq_hz = 0; 306 int granularity = 1000; /* 1kbits per sec */ 307 308 psat_data = sat_data_get(unit); 309 sal_memset(psat_data, 0, sizeof(_bcm_sat_data_t)); 310 #ifdef BCM_WARM_BOOT_SUPPORT 311 rv = bcm_common_sat_wb_init(unit); 312 #endif 313 psat_data->sat_mutex = sal_mutex_create("SAT LOCK"); 314 if(psat_data->sat_mutex == NULL) { 315 BCM_FREE(psat_data->sat_mutex); 316 LOG_ERROR(BSL_LS_BCM_SAT, 317 (BSL_META_U(unit, 318 "Fail to allocate memory for sat_mutex\n"))); 319 return BCM_E_MEMORY; 320 } 321 322 rv = mbcm_sat_init(unit); 323 if (rv != SOC_E_NONE) 324 { 325 LOG_ERROR(BSL_LS_BCM_SAT, 326 (BSL_META_U(unit, 327 "soc_dpp_init error in mbcm_sat_init\n"))); 328 return rv; 329 } 330 if (!SOC_WARM_BOOT(unit)) { 331 /* Time tickets */ 332 freq_hz = SOC_INFO(unit).frequency * 1000000; 333 #if defined(BCM_DPP_SUPPORT) 334 if (SOC_IS_JERICHO(unit)) { 335 freq_hz = arad_chip_kilo_ticks_per_sec_get(unit)*1000; 336 granularity = 64000; /* 64kbits per sec */ 337 } 338 #endif 339 soc_sat_init.cmic_tod_mode = _BCM_SAT_CMIC_TOD_MODE; 340 soc_sat_init.num_clks_sec = freq_hz; 341 soc_sat_init.rate_num_clks_cycle = (freq_hz/granularity)*8; /* 1kbits per sec(125 cycles per sec) */ 342 343 _BCM_SAT_SYSTEM_LOCK(unit); 344 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_general_cfg_init, (unit, &soc_sat_init)); 345 _BCM_SAT_SYSTEM_UNLOCK(unit); 346 } 347 return rv; 348 } 349 350 int bcm_common_sat_detach(int unit) 351 { 352 int rv = BCM_E_UNAVAIL; 353 _bcm_sat_data_t *psat_data; 354 355 psat_data = sat_data_get(unit); 356 rv = BCM_E_NONE; 357 sal_memset(psat_data, 0, sizeof(_bcm_sat_data_t)); 358 359 if (psat_data->sat_mutex != NULL) { 360 sal_mutex_destroy(psat_data->sat_mutex); 361 psat_data->sat_mutex = NULL; 362 } 363 364 return rv; 365 } 366 #endif /* BCM_SAT_SUPPORT */ 367 368 /* 369 * Function: 370 * bcm_sat_endpoint_info_t_init 371 * Purpose: 372 * Initialize an SAT endpoint info structure 373 * Parameters: 374 * endpoint_info - (OUT) Pointer to SAT endpoint info structure 375 * to be initialized 376 * Returns: 377 * NONE 378 * Notes: 379 */ 380 381 void bcm_sat_endpoint_info_t_init (bcm_sat_endpoint_info_t *endpoint_info) 382 { 383 if (NULL != endpoint_info) { 384 sal_memset(endpoint_info, 0, sizeof(bcm_sat_endpoint_info_t)); 385 endpoint_info->src_gport = BCM_GPORT_INVALID; 386 endpoint_info->dest_gport = BCM_GPORT_INVALID; 387 } 388 return; 389 } 390 391 void bcm_sat_config_t_init(bcm_sat_config_t *conf) 392 { 393 if (NULL != conf) { 394 sal_memset(conf, 0, sizeof (*conf)); 395 } 396 return; 397 } 398 399 int 400 bcm_common_sat_config_get( 401 int unit, 402 bcm_sat_config_t* conf) 403 { 404 int rv = BCM_E_UNAVAIL; 405 #ifdef BCM_SAT_SUPPORT 406 soc_sat_config_t soc_conf; 407 408 SAT_NULL_CHECK(conf, "conf"); 409 sal_memset(&soc_conf, 0, sizeof(soc_sat_config_t)); 410 411 _BCM_SAT_SYSTEM_LOCK(unit); 412 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_config_get, (unit, &soc_conf)); 413 _BCM_SAT_SYSTEM_UNLOCK(unit); 414 conf->config_flags = soc_conf.config_flags; 415 conf->timestamp_format = soc_conf.timestamp_format; 416 #endif /* BCM_SAT_SUPPORT */ 417 418 return rv; 419 } 420 421 int 422 bcm_common_sat_config_set( 423 int unit, 424 bcm_sat_config_t* conf) 425 426 { 427 int rv = BCM_E_UNAVAIL; 428 #ifdef BCM_SAT_SUPPORT 429 soc_sat_config_t soc_conf; 430 431 SAT_NULL_CHECK(conf, "conf"); 432 SAT_VALUE_CHECK(conf->timestamp_format, bcmSATTimestampFormatIEEE1588v1, (bcmSATTimestampFormatNTP+1), "timestamp_format"); 433 sal_memset(&soc_conf, 0, sizeof(soc_sat_config_t)); 434 soc_conf.config_flags = conf->config_flags; 435 soc_conf.timestamp_format = conf->timestamp_format; 436 _BCM_SAT_SYSTEM_LOCK(unit); 437 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_config_set, (unit, &soc_conf)); 438 #ifdef BCM_SABER2_SUPPORT 439 if (BCM_SUCCESS(rv) && SOC_IS_SABER2(unit)) { 440 rv = bcm_sb2_sat_ts_format_set(unit, soc_conf.timestamp_format); 441 } 442 #endif 443 _BCM_SAT_SYSTEM_UNLOCK(unit); 444 #endif /* BCM_SAT_SUPPORT */ 445 446 return rv; 447 } 448 449 #ifdef BCM_SAT_SUPPORT 450 STATIC int _bcm_common_sat_gtf_freed_id_find ( 451 _bcm_sat_data_t* psat_data, 452 bcm_sat_gtf_t* gtf_id 453 ) 454 { 455 int rv = BCM_E_NONE; 456 int idx = 0; 457 458 for (idx = _BCM_SAT_GTF_ID_MIN; idx <= _BCM_SAT_GTF_ID_MAX; idx++) { 459 if (!SAT_GTF_ID_EXIST(psat_data, idx)) { 460 break; 461 } 462 } 463 464 if (idx == (_BCM_SAT_GTF_ID_MAX + 1)) { 465 rv = BCM_E_RESOURCE; 466 } else { 467 *gtf_id = idx; 468 } 469 470 return rv; 471 } 472 #endif 473 474 void bcm_sat_header_user_define_offsets_t_init(bcm_sat_header_user_define_offsets_t *offsets) 475 { 476 if (NULL != offsets) { 477 sal_memset(offsets, 0, sizeof (*offsets)); 478 } 479 return; 480 } 481 482 void bcm_sat_payload_t_init(bcm_sat_payload_t *payload) 483 { 484 if (NULL != payload) { 485 sal_memset(payload, 0, sizeof (*payload)); 486 } 487 return; 488 } 489 490 void bcm_sat_stamp_t_init(bcm_sat_stamp_t *stamp) 491 { 492 if (NULL != stamp) { 493 sal_memset(stamp, 0, sizeof (*stamp)); 494 } 495 return; 496 } 497 498 void bcm_sat_gtf_packet_edit_t_init(bcm_sat_gtf_packet_edit_t *packet_edit) 499 { 500 if (NULL != packet_edit) { 501 sal_memset(packet_edit, 0, sizeof (*packet_edit)); 502 } 503 return; 504 } 505 506 void bcm_sat_gtf_packet_config_t_init(bcm_sat_gtf_packet_config_t *pkt_cfg) 507 { 508 if (NULL != pkt_cfg) { 509 sal_memset(pkt_cfg, 0, sizeof (*pkt_cfg)); 510 } 511 return; 512 } 513 514 void bcm_sat_gtf_bandwidth_t_init(bcm_sat_gtf_bandwidth_t *bw) 515 { 516 if (NULL != bw) { 517 sal_memset(bw, 0, sizeof (*bw)); 518 } 519 return; 520 } 521 522 void bcm_sat_gtf_rate_pattern_t_init(bcm_sat_gtf_rate_pattern_t *rate_pattern) 523 { 524 if (NULL != rate_pattern) { 525 sal_memset(rate_pattern, 0, sizeof (*rate_pattern)); 526 } 527 return; 528 } 529 530 int bcm_common_sat_gtf_create ( 531 int unit, 532 uint32 flags, 533 bcm_sat_gtf_t *gtf_id 534 ) 535 { 536 int rv = BCM_E_UNAVAIL; 537 #ifdef BCM_SAT_SUPPORT 538 _bcm_sat_data_t *psat_data; 539 bcm_sat_gtf_t tmp_gtf_id = 0; 540 541 psat_data = sat_data_get(unit); 542 SAT_NULL_CHECK(gtf_id, "gtf_id"); 543 LOG_VERBOSE(BSL_LS_BCM_SAT, ("%s %d: u(%d) flags(%d) gtf_id(%d)\n", BSL_FUNC, BSL_LINE, 544 unit, flags, (*gtf_id) )); 545 546 rv = BCM_E_NONE; 547 if (flags & BCM_SAT_GTF_WITH_ID) { 548 SAT_VALUE_CHECK(*gtf_id, _BCM_SAT_GTF_ID_MIN, (_BCM_SAT_GTF_ID_MAX+1), "gtf_id"); 549 if (SAT_GTF_ID_EXIST(psat_data, *gtf_id)) { 550 rv = BCM_E_EXISTS; 551 LOG_ERROR(BSL_LS_BCM_SAT, 552 (BSL_META_U(unit, 553 "Fail(%s) gtf_id(%d) exists\n"), soc_errmsg(rv), (*gtf_id))); 554 return rv; 555 } else { 556 tmp_gtf_id = *gtf_id; 557 } 558 } else { 559 /* Find a freed gtf ID */ 560 rv = _bcm_common_sat_gtf_freed_id_find(psat_data, &tmp_gtf_id); 561 if (rv != BCM_E_NONE) { 562 LOG_ERROR(BSL_LS_BCM_SAT, 563 (BSL_META_U(unit, 564 "Fail(%s) to find a freed gtf ID\n"), soc_errmsg(rv))); 565 return rv; 566 } 567 } 568 569 *gtf_id = tmp_gtf_id; 570 571 SAT_GTF_ID_SET(psat_data, tmp_gtf_id); 572 573 #endif/* BCM_SAT_SUPPORT */ 574 575 return rv; 576 } 577 578 int bcm_common_sat_gtf_destroy ( 579 int unit, 580 bcm_sat_gtf_t gtf_id 581 ) 582 { 583 int rv = BCM_E_UNAVAIL; 584 #ifdef BCM_SAT_SUPPORT 585 _bcm_sat_data_t *psat_data; 586 int pkt_gen_en = 0; 587 588 psat_data = sat_data_get(unit); 589 LOG_VERBOSE(BSL_LS_BCM_SAT, ("%s %d: u(%d) gtf_id(%d)\n", BSL_FUNC, BSL_LINE, unit, gtf_id )); 590 SAT_VALUE_CHECK(gtf_id, _BCM_SAT_GTF_ID_MIN, (_BCM_SAT_GTF_ID_MAX+1), "gtf_id"); 591 592 SAT_GTF_ID_NOT_EXIST_EXIT(psat_data, gtf_id); 593 594 /* Disable Generate Packet */ 595 pkt_gen_en = 0; 596 _BCM_SAT_SYSTEM_LOCK(unit); 597 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_gtf_packet_gen_set, (unit, gtf_id, _BCM_SAT_GTF_OBJ_COMMON, pkt_gen_en)); 598 _BCM_SAT_SYSTEM_UNLOCK(unit); 599 600 SAT_GTF_ID_CLR(psat_data, gtf_id); 601 if (rv != BCM_E_NONE) { 602 return rv; 603 } 604 605 if(psat_data->gtf_id_bitmap == 0){ 606 /* if no gtf, init rate mode*/ 607 rv =_bcm_common_sat_rate_mode_set(unit, 0); 608 if (rv != BCM_E_NONE) { 609 LOG_ERROR(BSL_LS_BCM_SAT, 610 (BSL_META_U(unit,"Fail(%s) init rate mode fail\n"), soc_errmsg(rv))); 611 } 612 /* if no gtf, init granularity flag*/ 613 rv =_bcm_common_sat_granularity_flag_set(unit,0); 614 if (rv != BCM_E_NONE) { 615 LOG_ERROR(BSL_LS_BCM_SAT, 616 (BSL_META_U(unit,"Fail(%s) init granularity fail\n"), soc_errmsg(rv))); 617 } 618 } 619 #endif/* BCM_SAT_SUPPORT */ 620 621 return rv; 622 } 623 624 int bcm_common_sat_gtf_destroy_all ( 625 int unit 626 ) 627 { 628 int rv = BCM_E_UNAVAIL; 629 #ifdef BCM_SAT_SUPPORT 630 _bcm_sat_data_t *psat_data; 631 bcm_sat_gtf_t gtf_id; 632 int pkt_gen_en = 0; 633 634 psat_data = sat_data_get(unit); 635 LOG_VERBOSE(BSL_LS_BCM_SAT, ("%s %d: u(%d)\n", BSL_FUNC, BSL_LINE, unit)); 636 rv = BCM_E_NONE; 637 638 _BCM_SAT_SYSTEM_LOCK(unit); 639 for(gtf_id = _BCM_SAT_GTF_ID_MIN; gtf_id <= _BCM_SAT_GTF_ID_MAX; gtf_id++) 640 { 641 if (SAT_GTF_ID_EXIST(psat_data, gtf_id)) { 642 /* Disable Generate Packet */ 643 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_gtf_packet_gen_set, (unit, gtf_id, _BCM_SAT_GTF_OBJ_COMMON, pkt_gen_en)); 644 } 645 } 646 _BCM_SAT_SYSTEM_UNLOCK(unit); 647 648 SAT_GTF_ID_CLR_ALL(psat_data); 649 650 if (rv != BCM_E_NONE) { 651 return rv; 652 } 653 654 rv =_bcm_common_sat_rate_mode_set(unit, 0); 655 if (rv != BCM_E_NONE) { 656 LOG_ERROR(BSL_LS_BCM_SAT, 657 (BSL_META_U(unit,"Fail(%s) init rate mode fail\n"), soc_errmsg(rv))); 658 } 659 660 /* if no gtf, init granularity flag*/ 661 rv =_bcm_common_sat_granularity_flag_set(unit,0); 662 if (rv != BCM_E_NONE) { 663 LOG_ERROR(BSL_LS_BCM_SAT, 664 (BSL_META_U(unit,"Fail(%s) init granularity fail\n"), soc_errmsg(rv))); 665 } 666 667 #endif/* BCM_SAT_SUPPORT */ 668 669 return rv; 670 } 671 672 int bcm_common_sat_gtf_inuse(int unit) 673 { 674 #ifdef BCM_SAT_SUPPORT 675 _bcm_sat_data_t *psat_data; 676 bcm_sat_gtf_t gtf_id; 677 678 psat_data = sat_data_get(unit); 679 LOG_VERBOSE(BSL_LS_BCM_SAT, ("%s %d: u(%d)\n", BSL_FUNC, BSL_LINE, unit)); 680 681 _BCM_SAT_SYSTEM_LOCK(unit); 682 for(gtf_id = _BCM_SAT_GTF_ID_MIN; gtf_id <= _BCM_SAT_GTF_ID_MAX; gtf_id++) 683 { 684 if (SAT_GTF_ID_EXIST(psat_data, gtf_id)) { 685 _BCM_SAT_SYSTEM_UNLOCK(unit); 686 return TRUE; 687 } 688 } 689 690 _BCM_SAT_SYSTEM_UNLOCK(unit); 691 #endif/* BCM_SAT_SUPPORT */ 692 693 return FALSE; 694 } 695 696 697 int 698 bcm_common_sat_gtf_traverse( 699 int unit, 700 bcm_sat_gtf_traverse_cb cb, 701 void *user_data) 702 { 703 int rv = BCM_E_UNAVAIL; 704 #ifdef BCM_SAT_SUPPORT 705 bcm_sat_gtf_t gtf_id; 706 _bcm_sat_data_t *psat_data; 707 708 psat_data = sat_data_get(unit); 709 LOG_VERBOSE(BSL_LS_BCM_SAT, ("%s %d: u(%d) \n", BSL_FUNC, BSL_LINE, unit )); 710 SAT_NULL_CHECK(user_data, "user_data"); 711 712 for(gtf_id = _BCM_SAT_GTF_ID_MIN; gtf_id <= _BCM_SAT_GTF_ID_MAX; gtf_id++) 713 { 714 if (SAT_GTF_ID_EXIST(psat_data, gtf_id)) { 715 /* Invoke user callback. */ 716 (*cb)(unit, gtf_id, user_data); 717 } 718 } 719 720 rv = BCM_E_NONE; 721 #endif/* BCM_SAT_SUPPORT */ 722 723 return rv; 724 } 725 726 /* 727 * Dump data in buffer - For debug usage. 728 */ 729 void _sat_packet_config_dump(bcm_sat_gtf_packet_config_t *config) { 730 int i = 0, j = 0, ele = 0; 731 uint8 *buffer; 732 int len; 733 734 if (!LOG_CHECK(BSL_LS_BCM_SAT | BSL_VERBOSE)) { 735 return; 736 } 737 if (config == NULL) { 738 return; 739 } 740 741 cli_out(" header_type:%d\n", config->sat_header_type); 742 cli_out(" header_info:\n"); 743 if ((config->header_info.pkt_data != NULL) && (config->header_info.pkt_data[0].data != NULL)) { 744 buffer = config->header_info.pkt_data[0].data; 745 len = config->header_info.pkt_data[0].len; 746 cli_out(" len:%d\n", len); 747 cli_out(" data:"); 748 ele = (len < 0)? 0 : len; 749 ele = (ele > (_BCM_SAT_GTF_PKT_HDR_LEN_MAX + 1)) ? (_BCM_SAT_GTF_PKT_HDR_LEN_MAX + 1) : ele; 750 for (i = 0; i < ele ; i++) { 751 if ((i % 16) == 0) 752 cli_out("\n "); 753 else if ((i % 4) == 0) 754 cli_out(" "); 755 cli_out("%02x", buffer[i]); 756 } 757 } 758 else { 759 cli_out("Invalid"); 760 } 761 cli_out("\n"); 762 cli_out(" payload_type:%d\n", config->payload.payload_type); 763 cli_out(" payload_pattern:"); 764 ele = (config->payload.payload_type == bcmSatPayloadConstant8Bytes) ? 8 : 4; 765 if (config->payload.payload_type != bcmSatPayloadPRBS) { 766 for (i = 0; i < ele; i++) { 767 cli_out("%02x ", config->payload.payload_pattern[i]); 768 } 769 } 770 cli_out("\n"); 771 for (i = 0; i < BCM_SAT_GTF_NUM_OF_PRIORITIES; i++) { 772 cli_out(" %s packet_edit:\n", ((i == 0)?"cir":"eir")); 773 cli_out(" packet_length:"); 774 for (j = 0; j < BCM_SAT_GTF_PACKET_LENGTH_NUM_OF_PATTERNS; j++) { 775 cli_out("%d ", config->packet_edit[i].packet_length[j]); 776 } 777 cli_out("\n"); 778 cli_out(" packet_length_pattern:"); 779 for (j = 0; j < BCM_SAT_GTF_PACKET_MAX_PATTERN_LENGTH; j++) { 780 cli_out("%d ", config->packet_edit[i].packet_length_pattern[j]); 781 } 782 cli_out("\n"); 783 cli_out(" pattern_length:%d\n", config->packet_edit[i].pattern_length); 784 cli_out(" number_of_stamps:%d\n", config->packet_edit[i].number_of_stamps); 785 for (j = 0; j < config->packet_edit[i].number_of_stamps; j++) { 786 cli_out(" stamp(%d): stamp_type:%d field_type:%d inc_step:%d inc_period_packets:%d value:%d offset:%d\n", 787 j, 788 config->packet_edit[i].stamps[j].stamp_type, 789 config->packet_edit[i].stamps[j].field_type, 790 config->packet_edit[i].stamps[j].inc_step, 791 config->packet_edit[i].stamps[j].inc_period_packets, 792 config->packet_edit[i].stamps[j].value, 793 config->packet_edit[i].stamps[j].offset); 794 } 795 cli_out(" number_of_ctfs:%d\n", config->packet_edit[i].number_of_ctfs); 796 cli_out(" flags:%d\n", config->packet_edit[i].flags); 797 } 798 cli_out(" packet_context_id:%d\n", config->packet_context_id); 799 cli_out(" offsets:\n"); 800 cli_out(" seq_number_offset:%d\n", config->offsets.seq_number_offset); 801 cli_out(" timestamp_offset:%d\n", config->offsets.timestamp_offset); 802 } 803 804 int bcm_common_sat_gtf_packet_config ( 805 int unit, 806 bcm_sat_gtf_t gtf_id, 807 bcm_sat_gtf_packet_config_t *config 808 ) 809 { 810 int rv = BCM_E_UNAVAIL; 811 #ifdef BCM_SAT_SUPPORT 812 _bcm_sat_data_t *psat_data; 813 soc_sat_gtf_packet_config_t *soc_pkt_cfg; 814 int i; 815 int priority; 816 int stamp_count[bcmSatStampCount] = {0}; 817 uint8 pkt_data[128]; 818 int pkt_len_idx = 0; 819 820 psat_data = sat_data_get(unit); 821 SAT_NULL_CHECK(config, "config"); 822 LOG_VERBOSE(BSL_LS_BCM_SAT, ("%s %d: u(%d) gtf_id(%d)\n", BSL_FUNC, BSL_LINE, unit, gtf_id )); 823 _sat_packet_config_dump(config); 824 SAT_VALUE_CHECK(gtf_id, _BCM_SAT_GTF_ID_MIN, (_BCM_SAT_GTF_ID_MAX+1), "gtf_id"); 825 SAT_GTF_ID_NOT_EXIST_EXIT(psat_data, gtf_id); 826 827 SAT_VALUE_CHECK(config->sat_header_type, bcmSatHeaderUserDefined, bcmSatHeadersCount, "sat_header_type"); 828 SAT_NULL_CHECK(config->header_info.pkt_data, "config->header_info.pkt_data"); 829 SAT_VALUE_CHECK(config->header_info.pkt_data[0].len, _BCM_SAT_GTF_PKT_HDR_LEN_MIN, (_BCM_SAT_GTF_PKT_HDR_LEN_MAX+1), "header_info.pkt_data[0].len"); 830 SAT_VALUE_CHECK(config->payload.payload_type, bcmSatPayloadConstant8Bytes, bcmSatPayloadsCount, "payload_type"); 831 for (priority = 0; priority < BCM_SAT_GTF_NUM_OF_PRIORITIES; priority++) { 832 833 SAT_VALUE_CHECK(config->packet_edit[priority].pattern_length, 1, (BCM_SAT_GTF_PACKET_MAX_PATTERN_LENGTH+1), "pattern_length"); 834 for (i = 0; i < config->packet_edit[priority].pattern_length; i++) { 835 SAT_VALUE_MAX_CHECK(config->packet_edit[priority].packet_length_pattern[i], (_BCM_SAT_GTF_PKT_LEN_PATN_INX_MAX+1), "packet_length_pattern"); 836 pkt_len_idx = config->packet_edit[priority].packet_length_pattern[i]; 837 if ((config->packet_edit[priority].packet_length[pkt_len_idx]) <= (config->header_info.pkt_data[0].len) || 838 (config->packet_edit[priority].packet_length[pkt_len_idx]) > _BCM_SAT_PAYLOAD_OFFSET_MAX) { 839 LOG_ERROR(BSL_LS_BCM_SAT, 840 (BSL_META_U(unit, 841 "Fail(%s) packet_length(%d) should be greater than packet header length(%d) and less then max packet_length(%d)\n"), 842 soc_errmsg(BCM_E_PARAM), config->packet_edit[priority].packet_length[pkt_len_idx], config->header_info.pkt_data[0].len, _BCM_SAT_PAYLOAD_OFFSET_MAX)); 843 return BCM_E_PARAM; 844 } 845 } 846 SAT_VALUE_MAX_CHECK(config->packet_edit[priority].number_of_stamps, (BCM_SAT_GTF_MAX_STAMPS+1), "number_of_stamps"); 847 SAT_VALUE_CHECK(config->packet_edit[priority].number_of_ctfs, _BCM_SAT_GTF_SEQ_PERIOD_MIN, (_BCM_SAT_GTF_SEQ_PERIOD_MAX+1), "number_of_ctfs"); 848 849 stamp_count[bcmSatStampConstant2Bit] = stamp_count[bcmSatStampCounter8Bit] = stamp_count[bcmSatStampCounter16Bit] = 0; 850 for (i = 0; i < BCM_SAT_GTF_MAX_STAMPS; i++) { 851 SAT_VALUE_CHECK(config->packet_edit[priority].stamps[i].stamp_type, bcmSatStampInvalid, bcmSatStampCount, "stamp_type"); 852 SAT_VALUE_CHECK(config->packet_edit[priority].stamps[i].field_type, bcmSatStampFieldUserDefined, bcmSatStampFieldsCount, "stamp_field_type"); 853 854 if ((config->packet_edit[priority].stamps[i].stamp_type == bcmSatStampCounter8Bit) || 855 (config->packet_edit[priority].stamps[i].stamp_type == bcmSatStampCounter16Bit)) { 856 SAT_VALUE_CHECK(config->packet_edit[priority].stamps[i].inc_step, _BCM_SAT_GTF_STAMP_INC_STEP_MIN, _BCM_SAT_GTF_STAMP_INC_STEP_MAX+1, "stamp_inc_step"); 857 SAT_VALUE_MAX_CHECK(config->packet_edit[priority].stamps[i].inc_period_packets, (_BCM_SAT_GTF_STAMP_INC_PERIOD_MAX+1), "stamp_inc_period_packets"); 858 } 859 else if (config->packet_edit[priority].stamps[i].stamp_type == bcmSatStampConstant2Bit) { 860 SAT_VALUE_MAX_CHECK(config->packet_edit[priority].stamps[i].value, (_BCM_SAT_GTF_STAMP_2_bit_VALUE_MAX+1), "stamp_value"); 861 } 862 863 stamp_count[config->packet_edit[priority].stamps[i].stamp_type]++; 864 } 865 866 if ((stamp_count[bcmSatStampConstant2Bit] > 1) || 867 (stamp_count[bcmSatStampCounter8Bit] > 1) || 868 (stamp_count[bcmSatStampCounter16Bit] > 1)) { 869 LOG_ERROR(BSL_LS_BCM_SAT, 870 (BSL_META_U(unit, 871 "Fail(%s) a CIR/EIR can have only one 2bit stamp, one 8bit counter and one 16bit counter\n"), soc_errmsg(BCM_E_PARAM))); 872 return BCM_E_PARAM; 873 } 874 } 875 876 #if defined(BCM_DPP_SUPPORT) 877 SAT_VALUE_MAX_CHECK(config->packet_context_id, (MAX_NUM_OF_CORES), "packet_context_id"); 878 #endif 879 880 soc_pkt_cfg = sal_alloc(sizeof(soc_sat_gtf_packet_config_t), 881 "soc_sat_gtf_packet_config"); 882 if (!soc_pkt_cfg) { 883 return BCM_E_MEMORY; 884 } 885 886 sal_memset(soc_pkt_cfg, 0, sizeof(soc_sat_gtf_packet_config_t)); 887 /* Don't allow to configure gtf packet during packet generate enable */ 888 soc_pkt_cfg->sat_header_type = config->sat_header_type; 889 soc_pkt_cfg->header_info.pkt_data = &(soc_pkt_cfg->header_info._pkt_data); 890 soc_pkt_cfg->header_info.blk_count = 1; 891 soc_pkt_cfg->header_info.pkt_data[0].data = pkt_data; 892 soc_pkt_cfg->header_info.pkt_data[0].len = config->header_info.pkt_data[0].len; 893 sal_memcpy(soc_pkt_cfg->header_info.pkt_data[0].data, config->header_info.pkt_data[0].data, sizeof(uint8)*config->header_info.pkt_data[0].len); 894 soc_pkt_cfg->payload.payload_type = config->payload.payload_type; 895 sal_memcpy(soc_pkt_cfg->payload.payload_pattern, config->payload.payload_pattern, sizeof(uint8)*BCM_SAT_PAYLOAD_MAX_PATTERN_SIZE); 896 897 for (priority = 0; priority < BCM_SAT_GTF_NUM_OF_PRIORITIES; priority++) { 898 sal_memcpy(soc_pkt_cfg->packet_edit[priority].packet_length, config->packet_edit[priority].packet_length, sizeof(uint32)*BCM_SAT_GTF_PACKET_LENGTH_NUM_OF_PATTERNS); 899 sal_memcpy(soc_pkt_cfg->packet_edit[priority].packet_length_pattern, config->packet_edit[priority].packet_length_pattern, sizeof(uint32)*BCM_SAT_GTF_PACKET_MAX_PATTERN_LENGTH); 900 soc_pkt_cfg->packet_edit[priority].pattern_length = config->packet_edit[priority].pattern_length; 901 902 soc_pkt_cfg->packet_edit[priority].number_of_stamps = config->packet_edit[priority].number_of_stamps; 903 for (i = 0; i < config->packet_edit[priority].number_of_stamps; i++) { 904 soc_pkt_cfg->packet_edit[priority].stamps[i].stamp_type = config->packet_edit[priority].stamps[i].stamp_type; 905 soc_pkt_cfg->packet_edit[priority].stamps[i].field_type = config->packet_edit[priority].stamps[i].field_type; 906 if ((config->packet_edit[priority].stamps[i].stamp_type == bcmSatStampCounter8Bit) || 907 (config->packet_edit[priority].stamps[i].stamp_type == bcmSatStampCounter16Bit)) { 908 soc_pkt_cfg->packet_edit[priority].stamps[i].inc_step = config->packet_edit[priority].stamps[i].inc_step; 909 soc_pkt_cfg->packet_edit[priority].stamps[i].inc_period_packets = config->packet_edit[priority].stamps[i].inc_period_packets; 910 } 911 else if (config->packet_edit[priority].stamps[i].stamp_type == bcmSatStampConstant2Bit) { 912 soc_pkt_cfg->packet_edit[priority].stamps[i].value = config->packet_edit[priority].stamps[i].value; 913 } 914 soc_pkt_cfg->packet_edit[priority].stamps[i].offset= config->packet_edit[priority].stamps[i].offset; 915 } 916 soc_pkt_cfg->packet_edit[priority].number_of_ctfs = config->packet_edit[priority].number_of_ctfs; 917 if(config->packet_edit[priority].flags & BCM_SAT_GTF_PACKET_EDIT_ADD_END_TLV) { 918 soc_pkt_cfg->packet_edit[priority].flags |= SOC_SAT_GTF_PACKET_EDIT_ADD_END_TLV; 919 } 920 if(config->packet_edit[priority].flags & BCM_SAT_GTF_PACKET_EDIT_ADD_CRC) { 921 soc_pkt_cfg->packet_edit[priority].flags |= SOC_SAT_GTF_PACKET_EDIT_ADD_CRC; 922 } 923 } 924 925 soc_pkt_cfg->packet_context_id = config->packet_context_id; 926 soc_pkt_cfg->offsets.payload_offset = config->offsets.payload_offset; 927 soc_pkt_cfg->offsets.timestamp_offset = config->offsets.timestamp_offset; 928 soc_pkt_cfg->offsets.seq_number_offset = config->offsets.seq_number_offset; 929 soc_pkt_cfg->offsets.crc_byte_offset = config->offsets.crc_byte_offset; 930 931 _BCM_SAT_SYSTEM_LOCK(unit); 932 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_gtf_packet_config, 933 (unit, gtf_id, soc_pkt_cfg)); 934 _BCM_SAT_SYSTEM_UNLOCK(unit); 935 936 sal_free(soc_pkt_cfg); 937 #endif/* BCM_SAT_SUPPORT */ 938 939 return rv; 940 } 941 942 int bcm_common_sat_gtf_bandwidth_set ( 943 int unit, 944 bcm_sat_gtf_t gtf_id, 945 int priority, 946 bcm_sat_gtf_bandwidth_t *bw 947 ) 948 { 949 int rv = BCM_E_UNAVAIL; 950 #ifdef BCM_SAT_SUPPORT 951 _bcm_sat_data_t *psat_data; 952 soc_sat_gtf_bandwidth_t soc_bandwidth; 953 uint8 rate_mode = 0; /*1: bps 2:pps*/ 954 uint8 is_granularity_set = 1; 955 956 psat_data = sat_data_get(unit); 957 SAT_NULL_CHECK(bw, "bw"); 958 LOG_VERBOSE(BSL_LS_BCM_SAT, ("%s %d: u(%d) gtf_id(%d) priority(%d) rate(%d) max_burst(%d)\n", BSL_FUNC, BSL_LINE, 959 unit, gtf_id, priority, bw->rate, bw->max_burst)); 960 961 SAT_VALUE_CHECK(gtf_id, _BCM_SAT_GTF_ID_MIN, (_BCM_SAT_GTF_ID_MAX+1), "gtf_id"); 962 SAT_GTF_ID_NOT_EXIST_EXIT(psat_data, gtf_id); 963 964 SAT_VALUE_CHECK(priority, _BCM_SAT_GTF_OBJ_COMMON, (_BCM_SAT_GTF_OBJ_EIR+1), "priority"); 965 SAT_VALUE_MAX_CHECK(bw->rate, (_BCM_SAT_GTF_BW_RATE_MAX+1), "rate"); 966 SAT_VALUE_MAX_CHECK(bw->max_burst, (_BCM_SAT_GTF_BW_BURST_MAX+1), "max_burst"); 967 968 if (SOC_IS_QAX(unit)) { 969 if(bw->flags & BCM_SAT_GTF_RATE_WITH_GRANULARITY){ 970 if(!(bw->flags & BCM_SAT_GTF_RATE_IN_PACKETS)){ 971 LOG_ERROR(BSL_LS_BCM_SAT,(BSL_META_U(unit,"Fail(%s) granularity only for PPS \n"), soc_errmsg(BCM_E_PARAM))); 972 return BCM_E_PARAM; 973 } 974 /* checking granularity value*/ 975 if(bw->granularity == 0){ 976 LOG_ERROR(BSL_LS_BCM_SAT,(BSL_META_U(unit,"Fail(%s) granularity shouldn't be zero \n"), soc_errmsg(BCM_E_PARAM))); 977 return BCM_E_PARAM; 978 } 979 /* checking if granularity is set. Granularity is shared by all GTF*/ 980 if(is_granularity_set == _bcm_common_sat_granularity_flag_get(unit)){ 981 LOG_WARN(BSL_LS_BCM_SAT,(BSL_META_U(unit, 982 "Warning : Granularity is shared by all GTFs, which will influce all the GTF granularity\n"))); 983 } 984 /* setting granularity flag*/ 985 rv =_bcm_common_sat_granularity_flag_set(unit,1); 986 if (rv != BCM_E_NONE) { 987 return rv; 988 } 989 } 990 991 if(bw->flags & BCM_SAT_GTF_RATE_IN_PACKETS){ 992 rate_mode = _BCM_SAT_PPS_MODE; 993 } 994 else{ 995 rate_mode = _BCM_SAT_BPS_MODE; 996 } 997 998 /* fisrt GTF will decide the "global mode" for BPS/PPS */ 999 if(0 == _bcm_common_sat_rate_mode_get(unit)){ 1000 rv =_bcm_common_sat_rate_mode_set(unit, rate_mode); 1001 if (rv != BCM_E_NONE) { 1002 return rv; 1003 } 1004 if(rate_mode == _BCM_SAT_PPS_MODE){ 1005 /* Default set granularity flag in PPS mode, default granularity is 1 packet/s*/ 1006 rv =_bcm_common_sat_granularity_flag_set(unit,1); 1007 if (rv != BCM_E_NONE) { 1008 return rv; 1009 } 1010 } 1011 } 1012 else if(rate_mode != _bcm_common_sat_rate_mode_get(unit)){ 1013 LOG_ERROR(BSL_LS_BCM_SAT,(BSL_META_U(unit, 1014 "Fail(%s) BPS/PPS mode conflicts with global rate mode (which is decided by first GTF ), you should delete all GTFs before change it\n"), soc_errmsg(BCM_E_PARAM))); 1015 return BCM_E_PARAM; 1016 } 1017 } 1018 1019 soc_bandwidth.rate = bw->rate; 1020 soc_bandwidth.max_burst = bw->max_burst; 1021 soc_bandwidth.flags = bw->flags; 1022 soc_bandwidth.granularity = bw->granularity; 1023 1024 _BCM_SAT_SYSTEM_LOCK(unit); 1025 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_gtf_bandwidth_set, (unit, gtf_id, priority, &soc_bandwidth)); 1026 _BCM_SAT_SYSTEM_UNLOCK(unit); 1027 #endif/* BCM_SAT_SUPPORT */ 1028 1029 return rv; 1030 } 1031 1032 int bcm_common_sat_gtf_bandwidth_get ( 1033 int unit, 1034 bcm_sat_gtf_t gtf_id, 1035 int priority, 1036 bcm_sat_gtf_bandwidth_t *bw 1037 ) 1038 { 1039 int rv = BCM_E_UNAVAIL; 1040 #ifdef BCM_SAT_SUPPORT 1041 _bcm_sat_data_t *psat_data; 1042 soc_sat_gtf_bandwidth_t soc_bandwidth; 1043 1044 psat_data = sat_data_get(unit); 1045 SAT_NULL_CHECK(bw, "bw"); 1046 SAT_VALUE_CHECK(gtf_id, _BCM_SAT_GTF_ID_MIN, (_BCM_SAT_GTF_ID_MAX+1), "gtf_id"); 1047 SAT_GTF_ID_NOT_EXIST_EXIT(psat_data, gtf_id); 1048 1049 SAT_VALUE_CHECK(priority, _BCM_SAT_GTF_OBJ_COMMON, (_BCM_SAT_GTF_OBJ_EIR+1), "priority"); 1050 1051 _BCM_SAT_SYSTEM_LOCK(unit); 1052 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_gtf_bandwidth_get, (unit, gtf_id, priority, &soc_bandwidth)); 1053 _BCM_SAT_SYSTEM_UNLOCK(unit); 1054 1055 if (BCM_SUCCESS(rv)) { 1056 bw->rate = soc_bandwidth.rate; 1057 bw->max_burst = soc_bandwidth.max_burst; 1058 bw->flags = soc_bandwidth.flags; 1059 } 1060 #endif/* BCM_SAT_SUPPORT */ 1061 1062 return rv; 1063 } 1064 1065 int bcm_common_sat_gtf_rate_pattern_set ( 1066 int unit, 1067 bcm_sat_gtf_t gtf_id, 1068 int priority, 1069 bcm_sat_gtf_rate_pattern_t *config 1070 ) 1071 { 1072 int rv = BCM_E_UNAVAIL; 1073 #ifdef BCM_SAT_SUPPORT 1074 _bcm_sat_data_t *psat_data; 1075 soc_sat_gtf_rate_pattern_t soc_rate_pattern; 1076 1077 psat_data = sat_data_get(unit); 1078 SAT_NULL_CHECK(config, "config"); 1079 LOG_VERBOSE(BSL_LS_BCM_SAT, ("%s %d: u(%d) gtf_id(%d) priority(%d)\n" 1080 " rate_pattern_mode(%d)\n" 1081 " high_threshold(%d) low_threshold(%d)\n" 1082 " stop_iter_count(%d) stop_burst_count(%d) stop_interval_count(%d)\n" 1083 " burst_packet_weight(%d) interval_packet_weight(%d) flags(%d)\n", BSL_FUNC, BSL_LINE, 1084 unit, gtf_id, priority, 1085 config->rate_pattern_mode, config->high_threshold, config->low_threshold, 1086 config->stop_iter_count, config->stop_burst_count, config->stop_interval_count, 1087 config->burst_packet_weight, config->interval_packet_weight, config->flags)); 1088 SAT_VALUE_CHECK(gtf_id, _BCM_SAT_GTF_ID_MIN, (_BCM_SAT_GTF_ID_MAX+1), "gtf_id"); 1089 SAT_GTF_ID_NOT_EXIST_EXIT(psat_data, gtf_id); 1090 1091 SAT_VALUE_CHECK(priority, _BCM_SAT_GTF_OBJ_CIR, (_BCM_SAT_GTF_OBJ_EIR+1), "gtf_id"); 1092 1093 SAT_VALUE_CHECK(config->high_threshold, _BCM_SAT_GTF_RATE_PATN_HIGH_TH_MIN, (_BCM_SAT_GTF_RATE_PATN_HIGH_TH_MAX+1), "high_threshold"); 1094 SAT_VALUE_CHECK(config->low_threshold, _BCM_SAT_GTF_RATE_PATN_LOW_TH_MIN, (_BCM_SAT_GTF_RATE_PATN_LOW_TH_MAX+1), "low_threshold"); 1095 SAT_VALUE_MAX_CHECK(config->stop_iter_count, (_BCM_SAT_GTF_RATE_PATN_STOP_ITER_MAX+1), "stop_iter_count"); 1096 1097 if (config->rate_pattern_mode == bcmSatGtfRatePatternContinues) { 1098 if (config->high_threshold != config->low_threshold) { 1099 rv = BCM_E_PARAM; 1100 LOG_ERROR(BSL_LS_BCM_SAT, 1101 (BSL_META_U(unit, 1102 "Fail(%s) in continues mode, high_threshold(%d) should equals to low_threshold(%d)\n"), 1103 soc_errmsg(rv), config->high_threshold, config->low_threshold)); 1104 return rv; 1105 } 1106 } 1107 else if (config->rate_pattern_mode == bcmSatGtfRatePatternSimpleBurst) { 1108 if (config->high_threshold <= config->low_threshold) { 1109 rv = BCM_E_PARAM; 1110 LOG_ERROR(BSL_LS_BCM_SAT, 1111 (BSL_META_U(unit, 1112 "Fail(%s) in simplebusrt mode, high_threshold(%d) should be greater than low_threshold(%d)\n"), 1113 soc_errmsg(rv), config->high_threshold, config->low_threshold)); 1114 return rv; 1115 } 1116 } 1117 else if (config->rate_pattern_mode == bcmSatGtfRatePatternCombined) { 1118 if (config->high_threshold < config->low_threshold) { 1119 rv = BCM_E_PARAM; 1120 LOG_ERROR(BSL_LS_BCM_SAT, 1121 (BSL_META_U(unit, 1122 "Fail(%s) in combined mode, high_threshold(%d) should be greater than low_threshold(%d)\n"), 1123 soc_errmsg(rv), config->high_threshold, config->low_threshold)); 1124 return rv; 1125 } 1126 } 1127 else if (config->rate_pattern_mode == bcmSatGtfRatePatternInterval) { 1128 if (config->high_threshold < config->low_threshold) { 1129 rv = BCM_E_PARAM; 1130 LOG_ERROR(BSL_LS_BCM_SAT, 1131 (BSL_META_U(unit, 1132 "Fail(%s) in interval mode, high_threshold(%d) should be greater than low_threshold(%d)\n"), 1133 soc_errmsg(rv), config->high_threshold, config->low_threshold)); 1134 return rv; 1135 } 1136 } 1137 else { 1138 rv = BCM_E_PARAM; 1139 LOG_ERROR(BSL_LS_BCM_SAT, 1140 (BSL_META_U(unit, 1141 "Fail(%s) rate_pattern_mode(%d) is not supported\n"), 1142 soc_errmsg(rv), config->rate_pattern_mode)); 1143 return rv; 1144 } 1145 1146 sal_memset(&soc_rate_pattern, 0, sizeof(soc_rate_pattern)); 1147 1148 if(config->flags & BCM_SAT_GTF_RATE_PATTERN_STOP_INTERVAL_EQ_BURST) { 1149 soc_rate_pattern.flags |= SOC_SAT_GTF_RATE_PATTERN_STOP_INTERVAL_EQ_BURST; 1150 } 1151 soc_rate_pattern.rate_pattern_mode = config->rate_pattern_mode; 1152 soc_rate_pattern.high_threshold = config->high_threshold; 1153 soc_rate_pattern.low_threshold = config->low_threshold; 1154 soc_rate_pattern.stop_iter_count = config->stop_iter_count; 1155 soc_rate_pattern.stop_burst_count = config->stop_burst_count; 1156 soc_rate_pattern.stop_interval_count = config->stop_interval_count; 1157 soc_rate_pattern.burst_packet_weight = config->burst_packet_weight; 1158 soc_rate_pattern.interval_packet_weight = config->interval_packet_weight; 1159 1160 _BCM_SAT_SYSTEM_LOCK(unit); 1161 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_gtf_rate_pattern_set, (unit, gtf_id, priority, &soc_rate_pattern)); 1162 _BCM_SAT_SYSTEM_UNLOCK(unit); 1163 #endif/* BCM_SAT_SUPPORT */ 1164 1165 return rv; 1166 } 1167 1168 int bcm_common_sat_gtf_rate_pattern_get ( 1169 int unit, 1170 bcm_sat_gtf_t gtf_id, 1171 int priority, 1172 bcm_sat_gtf_rate_pattern_t *config 1173 ) 1174 { 1175 int rv = BCM_E_UNAVAIL; 1176 #ifdef BCM_SAT_SUPPORT 1177 _bcm_sat_data_t *psat_data; 1178 soc_sat_gtf_rate_pattern_t soc_rate_pattern; 1179 1180 psat_data = sat_data_get(unit); 1181 SAT_NULL_CHECK(config, "config"); 1182 SAT_VALUE_CHECK(gtf_id, _BCM_SAT_GTF_ID_MIN, (_BCM_SAT_GTF_ID_MAX+1), "gtf_id"); 1183 SAT_GTF_ID_NOT_EXIST_EXIT(psat_data, gtf_id); 1184 1185 SAT_VALUE_CHECK(priority, _BCM_SAT_GTF_OBJ_CIR, (_BCM_SAT_GTF_OBJ_EIR+1), "priority"); 1186 sal_memset(&soc_rate_pattern, 0, sizeof(soc_rate_pattern)); 1187 1188 _BCM_SAT_SYSTEM_LOCK(unit); 1189 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_gtf_rate_pattern_get, (unit, gtf_id, priority, &soc_rate_pattern)); 1190 _BCM_SAT_SYSTEM_UNLOCK(unit); 1191 1192 if (BCM_SUCCESS(rv)) { 1193 config->rate_pattern_mode = soc_rate_pattern.rate_pattern_mode; 1194 config->high_threshold = soc_rate_pattern.high_threshold; 1195 config->low_threshold = soc_rate_pattern.low_threshold; 1196 config->stop_iter_count = soc_rate_pattern.stop_iter_count; 1197 config->stop_burst_count = soc_rate_pattern.stop_burst_count; 1198 config->stop_interval_count = soc_rate_pattern.stop_interval_count; 1199 config->burst_packet_weight = soc_rate_pattern.burst_packet_weight; 1200 config->interval_packet_weight = soc_rate_pattern.interval_packet_weight; 1201 if(soc_rate_pattern.flags & BCM_SAT_GTF_RATE_PATTERN_STOP_INTERVAL_EQ_BURST) { 1202 config->flags |= SOC_SAT_GTF_RATE_PATTERN_STOP_INTERVAL_EQ_BURST; 1203 } 1204 } 1205 #endif/* BCM_SAT_SUPPORT */ 1206 1207 return rv; 1208 } 1209 1210 int bcm_common_sat_gtf_packet_start ( 1211 int unit, 1212 bcm_sat_gtf_t gtf_id, 1213 bcm_sat_gtf_pri_t priority 1214 ) 1215 { 1216 int rv = BCM_E_UNAVAIL; 1217 #ifdef BCM_SAT_SUPPORT 1218 _bcm_sat_data_t *psat_data; 1219 int pkt_gen_en = 0; 1220 1221 psat_data = sat_data_get(unit); 1222 LOG_VERBOSE(BSL_LS_BCM_SAT, ("%s %d: u(%d) gtf_id(%d) priority(%d)\n", BSL_FUNC, BSL_LINE, 1223 unit, gtf_id, priority)); 1224 SAT_VALUE_CHECK(gtf_id, _BCM_SAT_GTF_ID_MIN, (_BCM_SAT_GTF_ID_MAX+1), "gtf_id"); 1225 SAT_VALUE_CHECK(priority, bcmSatGtfPriAll, (bcmSatGtfPriEir+1), "priority"); 1226 SAT_GTF_ID_NOT_EXIST_EXIT(psat_data, gtf_id); 1227 1228 /* Enable Genrate Packet */ 1229 pkt_gen_en = 1; 1230 _BCM_SAT_SYSTEM_LOCK(unit); 1231 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_gtf_packet_gen_set, (unit, gtf_id, priority, pkt_gen_en)); 1232 _BCM_SAT_SYSTEM_UNLOCK(unit); 1233 1234 #endif/* BCM_SAT_SUPPORT */ 1235 1236 return rv; 1237 } 1238 1239 int bcm_common_sat_gtf_packet_stop ( 1240 int unit, 1241 bcm_sat_gtf_t gtf_id, 1242 bcm_sat_gtf_pri_t priority 1243 ) 1244 { 1245 int rv = BCM_E_UNAVAIL; 1246 #ifdef BCM_SAT_SUPPORT 1247 _bcm_sat_data_t *psat_data; 1248 int pkt_gen_en = 0; 1249 1250 psat_data = sat_data_get(unit); 1251 LOG_VERBOSE(BSL_LS_BCM_SAT, ("%s %d: u(%d) gtf_id(%d) priority(%d)\n", BSL_FUNC, BSL_LINE, 1252 unit, gtf_id, priority)); 1253 SAT_VALUE_CHECK(gtf_id, _BCM_SAT_GTF_ID_MIN, (_BCM_SAT_GTF_ID_MAX+1), "gtf_id"); 1254 SAT_VALUE_CHECK(priority, bcmSatGtfPriAll, (bcmSatGtfPriEir+1), "priority"); 1255 SAT_GTF_ID_NOT_EXIST_EXIT(psat_data, gtf_id); 1256 1257 /* Disable Genrate Packet */ 1258 pkt_gen_en = 0; 1259 _BCM_SAT_SYSTEM_LOCK(unit); 1260 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_gtf_packet_gen_set, (unit, gtf_id, priority, pkt_gen_en)); 1261 _BCM_SAT_SYSTEM_UNLOCK(unit); 1262 #endif/* BCM_SAT_SUPPORT */ 1263 1264 return rv; 1265 } 1266 1267 int bcm_common_sat_gtf_stat_get ( 1268 int unit, 1269 bcm_sat_gtf_t gtf_id, 1270 int priority, 1271 uint32 flags, 1272 bcm_sat_gtf_stat_counter_t type, 1273 uint64* value 1274 ) 1275 { 1276 int rv = BCM_E_UNAVAIL; 1277 #ifdef BCM_SAT_SUPPORT 1278 soc_sat_gtf_stat_counter_t stat_type; 1279 uint64 stat_cur; 1280 _bcm_sat_data_t *psat_data; 1281 1282 #ifdef CRASH_RECOVERY_SUPPORT 1283 /* the problem is that the sat_data[unit] is being reset in the wb/cr reset. 1284 After doing bcm_common_sat_ctf_create/bcm_common_sat_gtf_create the sat_data 1285 is updated (ctf_id_bitmap/gtf_id_bitmap), but after the reset it is being zero. */ 1286 soc_dcmn_cr_suppress(unit, dcmn_cr_no_support_sat); 1287 #endif 1288 1289 SAT_NULL_CHECK(value, "value"); 1290 SAT_VALUE_CHECK(gtf_id, _BCM_SAT_GTF_ID_MIN, (_BCM_SAT_GTF_ID_MAX+1), "gtf_id"); 1291 1292 SAT_VALUE_CHECK(priority, _BCM_SAT_GTF_OBJ_CIR, (_BCM_SAT_GTF_OBJ_EIR+1), "priority"); 1293 SAT_VALUE_CHECK(type, bcmSatGtfStatPacketCount, (bcmSatGtfStatCount), "type"); 1294 /* parameter check */ 1295 1296 psat_data = sat_data_get(unit); 1297 SAT_GTF_ID_NOT_EXIST_EXIT(psat_data, gtf_id); 1298 if (flags != 0) { 1299 rv = BCM_E_PARAM; 1300 LOG_ERROR(BSL_LS_BCM_SAT, 1301 (BSL_META_U(unit, 1302 "Fail(%s) flags(%d) should be 0\n"), 1303 soc_errmsg(rv), flags)); 1304 return rv; 1305 } 1306 1307 stat_type = type; 1308 COMPILER_64_ZERO(stat_cur); 1309 1310 _BCM_SAT_SYSTEM_LOCK(unit); 1311 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_gtf_stat_get, (unit, gtf_id, priority, flags, stat_type, &stat_cur)); 1312 _BCM_SAT_SYSTEM_UNLOCK(unit); 1313 1314 COMPILER_64_ZERO(*value); 1315 COMPILER_64_ADD_64(*value, stat_cur); 1316 #endif/* BCM_SAT_SUPPORT */ 1317 1318 return rv; 1319 } 1320 1321 /* CTF functions */ 1322 void bcm_sat_ctf_packet_info_t_init(bcm_sat_ctf_packet_info_t *packet_info) 1323 { 1324 if (NULL != packet_info) { 1325 sal_memset(packet_info, 0, sizeof (*packet_info)); 1326 } 1327 return; 1328 } 1329 1330 void bcm_sat_ctf_identifier_t_init(bcm_sat_ctf_identifier_t *ctf_identifier) 1331 { 1332 if (NULL != ctf_identifier) { 1333 sal_memset(ctf_identifier, 0, sizeof (*ctf_identifier)); 1334 } 1335 return; 1336 } 1337 1338 void bcm_sat_ctf_bin_limit_t_init(bcm_sat_ctf_bin_limit_t *bins) 1339 { 1340 if (NULL != bins) { 1341 sal_memset(bins, 0, sizeof (*bins)); 1342 } 1343 return; 1344 } 1345 1346 void bcm_sat_ctf_stat_config_t_init(bcm_sat_ctf_stat_config_t *stat_cfg) 1347 { 1348 if (NULL != stat_cfg) { 1349 sal_memset(stat_cfg, 0, sizeof (*stat_cfg)); 1350 } 1351 return; 1352 } 1353 1354 void bcm_sat_ctf_stat_t_init(bcm_sat_ctf_stat_t *stat) 1355 { 1356 if (NULL != stat) { 1357 sal_memset(stat, 0, sizeof (*stat)); 1358 } 1359 return; 1360 } 1361 1362 void bcm_sat_ctf_availability_config_t_init(bcm_sat_ctf_availability_config_t *config) 1363 { 1364 if (NULL != config) { 1365 sal_memset(config, 0, sizeof (*config)); 1366 } 1367 return; 1368 } 1369 1370 void bcm_sat_ctf_report_config_t_init(bcm_sat_ctf_report_config_t *reports) 1371 { 1372 if (NULL != reports) { 1373 sal_memset(reports, 0, sizeof (*reports)); 1374 } 1375 return; 1376 } 1377 1378 #ifdef BCM_SAT_SUPPORT 1379 STATIC int _bcm_common_sat_ctf_freed_id_find ( 1380 _bcm_sat_data_t* psat_data, 1381 bcm_sat_ctf_t* ctf_id 1382 ) 1383 { 1384 int rv = BCM_E_NONE; 1385 int idx = 0; 1386 1387 for (idx = _BCM_SAT_CTF_ID_MIN; idx <= _BCM_SAT_CTF_ID_MAX; idx++) { 1388 if (!SAT_CTF_ID_EXIST(psat_data, idx)) { 1389 break; 1390 } 1391 } 1392 1393 if (idx == (_BCM_SAT_CTF_ID_MAX + 1)) { 1394 rv = BCM_E_RESOURCE; 1395 } else { 1396 *ctf_id = idx; 1397 } 1398 1399 return rv; 1400 } 1401 1402 STATIC int _bcm_common_sat_ctf_freed_trap_id_find ( 1403 _bcm_sat_data_t* psat_data, 1404 int32* trap_idx 1405 ) 1406 { 1407 int rv = BCM_E_NONE; 1408 int idx = 0; 1409 1410 for (idx = 0; idx < _BCM_SAT_CTF_TRAP_ID_MAX_NUM; idx++) { 1411 if (!SAT_CTF_TRAP_ID_EXIST(psat_data, idx)) { 1412 break; 1413 } 1414 } 1415 1416 if (idx == _BCM_SAT_CTF_TRAP_ID_MAX_NUM) { 1417 rv = BCM_E_RESOURCE; 1418 } else { 1419 *trap_idx = idx; 1420 } 1421 1422 return rv; 1423 } 1424 1425 STATIC int _bcm_common_sat_trap_id_find ( 1426 _bcm_sat_data_t* psat_data, 1427 uint32 trap_id, 1428 int32* trap_idx 1429 ) 1430 { 1431 int rv = BCM_E_NONE; 1432 int idx = 0; 1433 1434 for (idx = 0; idx < _BCM_SAT_CTF_TRAP_ID_MAX_NUM; idx++) { 1435 if (trap_id == psat_data->ctf_trap_id[idx] && SAT_CTF_TRAP_ID_EXIST(psat_data, idx)) { 1436 break; 1437 } 1438 } 1439 1440 if (idx == _BCM_SAT_CTF_TRAP_ID_MAX_NUM) { 1441 rv = BCM_E_NOT_FOUND; 1442 } else { 1443 *trap_idx = idx; 1444 } 1445 1446 return rv; 1447 } 1448 1449 STATIC int _bcm_common_sat_ctf_trap_entry_find ( 1450 _bcm_sat_data_t* psat_data, 1451 uint32 trap_data, 1452 uint32 trap_mask, 1453 uint32 *entry_idx 1454 ) 1455 { 1456 int rv = BCM_E_NONE; 1457 int idx = 0; 1458 uint8 found = FALSE; 1459 1460 /* Check the entry whether is existed */ 1461 for (idx = 0; idx < _BCM_SAT_CTF_TRAP_DATA_ENTRY_NUM; idx++) { 1462 if (psat_data->trap_data[idx].trap_data == trap_data && 1463 psat_data->trap_data[idx].trap_mask == trap_mask && 1464 SAT_BITMAP_EXIST(psat_data->ctf_ssid_bitmap, idx)) { 1465 found = TRUE; 1466 break; 1467 } 1468 } 1469 1470 if (found == TRUE) { 1471 *entry_idx = idx; 1472 } else { 1473 rv = BCM_E_NOT_FOUND; 1474 } 1475 1476 return rv; 1477 } 1478 1479 1480 STATIC int _bcm_common_sat_ctf_freed_trap_entry_find ( 1481 _bcm_sat_data_t* psat_data, 1482 uint32 trap_data, 1483 uint32 trap_mask, 1484 uint32 *entry_idx 1485 ) 1486 { 1487 int rv = BCM_E_NONE; 1488 int idx = 0; 1489 1490 /* Check the entry whether is existed */ 1491 rv = _bcm_common_sat_ctf_trap_entry_find(psat_data, trap_data, trap_mask, entry_idx); 1492 if (rv == BCM_E_NONE) { 1493 *entry_idx = idx; 1494 rv = BCM_E_EXISTS; 1495 } else { 1496 /* Find a freed entry */ 1497 rv = BCM_E_NONE; 1498 for (idx = 0; idx < _BCM_SAT_CTF_TRAP_DATA_ENTRY_NUM; idx++) { 1499 if (!SAT_BITMAP_EXIST(psat_data->ctf_ssid_bitmap, idx)) { 1500 break; 1501 } 1502 } 1503 1504 if (idx == _BCM_SAT_CTF_TRAP_DATA_ENTRY_NUM) { 1505 rv = BCM_E_RESOURCE; 1506 } else { 1507 *entry_idx = idx; 1508 } 1509 } 1510 1511 return rv; 1512 } 1513 #endif 1514 1515 int bcm_common_sat_ctf_create ( 1516 int unit, 1517 uint32 flags, 1518 bcm_sat_ctf_t *ctf_id 1519 ) 1520 { 1521 int rv = BCM_E_UNAVAIL; 1522 #ifdef BCM_SAT_SUPPORT 1523 _bcm_sat_data_t *psat_data; 1524 bcm_sat_ctf_t tmp_ctf_id = 0; 1525 1526 psat_data = sat_data_get(unit); 1527 SAT_NULL_CHECK(ctf_id, "ctf_id"); 1528 rv = BCM_E_NONE; 1529 if (flags & BCM_SAT_CTF_WITH_ID) { 1530 /* In case return BCM_E_PARAM if ctf_id is invalid */ 1531 SAT_VALUE_CHECK(*ctf_id, _BCM_SAT_CTF_ID_MIN, (_BCM_SAT_CTF_ID_MAX+1), "ctf_id"); 1532 if (SAT_CTF_ID_EXIST(psat_data, *ctf_id)) { 1533 return BCM_E_EXISTS; 1534 } else { 1535 tmp_ctf_id = *ctf_id; 1536 } 1537 } else { 1538 /* Find a freed CTF ID */ 1539 /* In case return BCM_E_RESOURCE if haven't resource. 1540 */ 1541 rv = _bcm_common_sat_ctf_freed_id_find(psat_data, &tmp_ctf_id); 1542 if (rv != BCM_E_NONE) { 1543 return rv; 1544 } 1545 *ctf_id = tmp_ctf_id; 1546 } 1547 SAT_CTF_ID_SET(psat_data, tmp_ctf_id); 1548 #endif /* BCM_SAT_SUPPORT */ 1549 1550 return rv; 1551 } 1552 1553 int bcm_common_sat_ctf_destroy ( 1554 int unit, 1555 bcm_sat_ctf_t ctf_id 1556 ) 1557 { 1558 int rv = BCM_E_UNAVAIL; 1559 #ifdef BCM_SAT_SUPPORT 1560 _bcm_sat_data_t *psat_data; 1561 1562 rv = BCM_E_NONE; 1563 psat_data = sat_data_get(unit); 1564 SAT_VALUE_CHECK(ctf_id, _BCM_SAT_CTF_ID_MIN, (_BCM_SAT_CTF_ID_MAX+1), "ctf_id"); 1565 SAT_CTF_ID_NOT_EXIST_EXIT(psat_data, ctf_id); 1566 SAT_CTF_ID_CLR(psat_data, ctf_id); 1567 #endif /* BCM_SAT_SUPPORT */ 1568 1569 return rv; 1570 } 1571 1572 int bcm_common_sat_ctf_destroy_all ( 1573 int unit 1574 ) 1575 { 1576 int rv = BCM_E_UNAVAIL; 1577 #ifdef BCM_SAT_SUPPORT 1578 _bcm_sat_data_t *psat_data; 1579 1580 rv = BCM_E_NONE; 1581 psat_data = sat_data_get(unit); 1582 SAT_CTF_ID_CLR_ALL(psat_data); 1583 #endif/* BCM_SAT_SUPPORT */ 1584 1585 return rv; 1586 } 1587 1588 int bcm_common_sat_ctf_inuse(int unit) 1589 { 1590 #ifdef BCM_SAT_SUPPORT 1591 bcm_sat_ctf_t ctf_id; 1592 _bcm_sat_data_t *psat_data; 1593 1594 psat_data = sat_data_get(unit); 1595 LOG_VERBOSE(BSL_LS_BCM_SAT, ("%s %d: u(%d)\n", BSL_FUNC, BSL_LINE, unit)); 1596 1597 _BCM_SAT_SYSTEM_LOCK(unit); 1598 for (ctf_id = _BCM_SAT_CTF_ID_MIN; 1599 ctf_id <= _BCM_SAT_CTF_ID_MAX; ctf_id++) { 1600 if (SAT_CTF_ID_EXIST(psat_data, ctf_id)) { 1601 _BCM_SAT_SYSTEM_UNLOCK(unit); 1602 return TRUE; 1603 } 1604 } 1605 _BCM_SAT_SYSTEM_UNLOCK(unit); 1606 #endif/* BCM_SAT_SUPPORT */ 1607 1608 return FALSE; 1609 } 1610 1611 int 1612 bcm_common_sat_ctf_traverse( 1613 int unit, 1614 bcm_sat_ctf_traverse_cb cb, 1615 void *user_data) 1616 { 1617 int rv = BCM_E_UNAVAIL; 1618 #ifdef BCM_SAT_SUPPORT 1619 bcm_sat_ctf_t ctf_id; 1620 _bcm_sat_data_t *psat_data; 1621 1622 rv = BCM_E_NONE; 1623 psat_data = sat_data_get(unit); 1624 SAT_NULL_CHECK(user_data, "user_data"); 1625 for(ctf_id = _BCM_SAT_CTF_ID_MIN; ctf_id <= _BCM_SAT_CTF_ID_MAX; ctf_id++) 1626 { 1627 if (SAT_CTF_ID_EXIST(psat_data, ctf_id)) { 1628 /* Invoke user callback. */ 1629 (*cb)(unit, ctf_id, user_data); 1630 } 1631 } 1632 #endif/* BCM_SAT_SUPPORT */ 1633 1634 return rv; 1635 } 1636 1637 int bcm_common_sat_ctf_packet_config ( 1638 int unit, 1639 bcm_sat_ctf_t ctf_id, 1640 bcm_sat_ctf_packet_info_t *packet_info 1641 ) 1642 { 1643 int rv = BCM_E_UNAVAIL; 1644 #ifdef BCM_SAT_SUPPORT 1645 soc_sat_ctf_packet_info_t soc_packet_info; 1646 _bcm_sat_data_t *psat_data; 1647 1648 psat_data = sat_data_get(unit); 1649 SAT_NULL_CHECK(packet_info, "packet_info"); 1650 SAT_VALUE_CHECK(ctf_id, _BCM_SAT_CTF_ID_MIN, (_BCM_SAT_CTF_ID_MAX+1), "ctf_id"); 1651 SAT_CTF_ID_NOT_EXIST_EXIT(psat_data, ctf_id); 1652 SAT_VALUE_CHECK(packet_info->sat_header_type, bcmSatHeaderUserDefined, bcmSatHeadersCount, "sat_header_type"); 1653 SAT_VALUE_CHECK(packet_info->payload.payload_type, bcmSatPayloadConstant8Bytes, bcmSatPayloadsCount, "payload_type"); 1654 SAT_VALUE_CHECK(packet_info->offsets.payload_offset, _BCM_SAT_PAYLOAD_OFFSET_MIN, (_BCM_SAT_PAYLOAD_OFFSET_MAX+1), "payload_offset"); 1655 SAT_VALUE_CHECK(packet_info->offsets.seq_number_offset, _BCM_SAT_SEQ_NUM_OFFSET_MIN, (_BCM_SAT_SEQ_NUM_OFFSET_MAX+1), "seq_number_offset"); 1656 SAT_VALUE_CHECK(packet_info->offsets.timestamp_offset, _BCM_SAT_TIME_STAMP_OFFSET_MIN, (_BCM_SAT_TIME_STAMP_OFFSET_MAX+1), "timestamp_offset"); 1657 if(packet_info->flags & BCM_SAT_CTF_PACKET_INFO_ADD_CRC) { 1658 SAT_VALUE_CHECK(packet_info->offsets.crc_byte_offset, _BCM_SAT_CRC_BYTE_OFFSET_MIN, (_BCM_SAT_CRC_BYTE_OFFSET_MAX+1), "crc_byte_offset"); 1659 } 1660 sal_memset(&soc_packet_info, 0, sizeof(soc_packet_info)); 1661 1662 if(packet_info->flags & BCM_SAT_CTF_PACKET_INFO_ADD_END_TLV) { 1663 soc_packet_info.flags |= SOC_SAT_CTF_PACKET_INFO_ADD_END_TLV; 1664 } 1665 if(packet_info->flags & BCM_SAT_CTF_PACKET_INFO_ADD_CRC) { 1666 soc_packet_info.flags |= SOC_SAT_CTF_PACKET_INFO_ADD_CRC; 1667 } 1668 soc_packet_info.sat_header_type = packet_info->sat_header_type; 1669 soc_packet_info.payload.payload_type = packet_info->payload.payload_type; 1670 sal_memcpy(soc_packet_info.payload.payload_pattern, packet_info->payload.payload_pattern, sizeof(uint8)*BCM_SAT_PAYLOAD_MAX_PATTERN_SIZE); 1671 if (packet_info->sat_header_type == bcmSatHeaderUserDefined) { 1672 soc_packet_info.offsets.payload_offset = packet_info->offsets.payload_offset; 1673 soc_packet_info.offsets.seq_number_offset = packet_info->offsets.seq_number_offset; 1674 soc_packet_info.offsets.timestamp_offset = packet_info->offsets.timestamp_offset; 1675 if (packet_info->flags & BCM_SAT_CTF_PACKET_INFO_ADD_CRC) { 1676 soc_packet_info.offsets.crc_byte_offset = packet_info->offsets.crc_byte_offset; 1677 } 1678 } 1679 else if (packet_info->sat_header_type == bcmSatHeaderY1731) { 1680 soc_packet_info.offsets.payload_offset = 1681 (packet_info->offsets.payload_offset ? packet_info->offsets.payload_offset : _BCM_SAT_Y1731_PAYLOAD_OFFSET); 1682 soc_packet_info.offsets.seq_number_offset = 1683 (packet_info->offsets.seq_number_offset ? packet_info->offsets.seq_number_offset : _BCM_SAT_Y1731_SEQ_NUM_OFFSET); 1684 soc_packet_info.offsets.timestamp_offset = 1685 (packet_info->offsets.timestamp_offset ? packet_info->offsets.timestamp_offset : _BCM_SAT_Y1731_TIME_STAMP_OFFSET); 1686 if (packet_info->flags & BCM_SAT_CTF_PACKET_INFO_ADD_CRC) { 1687 soc_packet_info.offsets.crc_byte_offset = (packet_info->offsets.crc_byte_offset ? 1688 packet_info->offsets.crc_byte_offset : _BCM_SAT_Y1731_CRC_BYTE_OFFSET_OFFSET); 1689 } 1690 } 1691 else if (packet_info->sat_header_type == bcmSatHeaderMEF) { 1692 soc_packet_info.offsets.payload_offset = 1693 (packet_info->offsets.payload_offset ? packet_info->offsets.payload_offset : _BCM_SAT_MEF_PAYLOAD_OFFSET); 1694 soc_packet_info.offsets.seq_number_offset = 1695 (packet_info->offsets.seq_number_offset ? packet_info->offsets.seq_number_offset : _BCM_SAT_MEF_SEQ_NUM_OFFSET); 1696 soc_packet_info.offsets.timestamp_offset = 1697 (packet_info->offsets.timestamp_offset ? packet_info->offsets.timestamp_offset : _BCM_SAT_MEF_TIME_STAMP_OFFSET); 1698 if (packet_info->flags & BCM_SAT_CTF_PACKET_INFO_ADD_CRC) { 1699 soc_packet_info.offsets.crc_byte_offset = (packet_info->offsets.crc_byte_offset ? 1700 packet_info->offsets.crc_byte_offset : _BCM_SAT_MEF_CRC_BYTE_OFFSET_OFFSET); 1701 } 1702 } 1703 _BCM_SAT_SYSTEM_LOCK(unit); 1704 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_ctf_packet_config, (unit, ctf_id, &soc_packet_info)); 1705 _BCM_SAT_SYSTEM_UNLOCK(unit); 1706 #endif/* BCM_SAT_SUPPORT */ 1707 1708 return rv; 1709 } 1710 1711 int bcm_common_sat_ctf_identifier_map ( 1712 int unit, 1713 bcm_sat_ctf_identifier_t *identifier, 1714 bcm_sat_ctf_t ctf_id 1715 ) 1716 { 1717 int rv = BCM_E_UNAVAIL; 1718 #ifdef BCM_SAT_SUPPORT 1719 soc_sat_ctf_identifier_t soc_identifier; 1720 _bcm_sat_data_t *psat_data; 1721 1722 psat_data = sat_data_get(unit); 1723 SAT_NULL_CHECK(identifier, "identifier"); 1724 SAT_VALUE_CHECK(ctf_id, _BCM_SAT_CTF_ID_MIN, (_BCM_SAT_CTF_ID_MAX+1), "ctf_id"); 1725 SAT_CTF_ID_NOT_EXIST_EXIT(psat_data, ctf_id); 1726 SAT_VALUE_MAX_CHECK(identifier->session_id, (_BCM_SAT_CTF_OAM_ID_MAX+1), "session_id"); 1727 SAT_VALUE_MAX_CHECK(identifier->trap_id, (_BCM_SAT_CTF_TRAP_ID_MAX+1), "trap_id"); 1728 SAT_VALUE_MAX_CHECK(identifier->color, (_BCM_SAT_CTF_COLOR_MAX+1), "color"); 1729 SAT_VALUE_MAX_CHECK(identifier->tc, (_BCM_SAT_CTF_COS_MAX+1), "tc"); 1730 sal_memset(&soc_identifier, 0, sizeof(soc_identifier)); 1731 soc_identifier.session_id = identifier->session_id; 1732 soc_identifier.trap_id = identifier->trap_id; 1733 soc_identifier.color = identifier->color; 1734 soc_identifier.tc = identifier->tc; 1735 _BCM_SAT_SYSTEM_LOCK(unit); 1736 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_ctf_identifier_map, (unit, &soc_identifier, ctf_id)); 1737 _BCM_SAT_SYSTEM_UNLOCK(unit); 1738 #endif/* BCM_SAT_SUPPORT */ 1739 1740 return rv; 1741 } 1742 1743 int bcm_common_sat_ctf_identifier_unmap ( 1744 int unit, 1745 bcm_sat_ctf_identifier_t *identifier 1746 ) 1747 { 1748 int rv = BCM_E_UNAVAIL; 1749 #ifdef BCM_SAT_SUPPORT 1750 soc_sat_ctf_identifier_t soc_identifier; 1751 1752 SAT_NULL_CHECK(identifier, "identifier"); 1753 SAT_VALUE_MAX_CHECK(identifier->session_id, (_BCM_SAT_CTF_OAM_ID_MAX+1), "session_id"); 1754 SAT_VALUE_MAX_CHECK(identifier->trap_id, (_BCM_SAT_CTF_TRAP_ID_MAX+1), "trap_id"); 1755 SAT_VALUE_MAX_CHECK(identifier->color, (_BCM_SAT_CTF_COLOR_MAX+1), "color"); 1756 SAT_VALUE_MAX_CHECK(identifier->tc, (_BCM_SAT_CTF_COS_MAX+1), "tc"); 1757 sal_memset(&soc_identifier, 0, sizeof(soc_identifier)); 1758 soc_identifier.session_id = identifier->session_id; 1759 soc_identifier.trap_id = identifier->trap_id; 1760 soc_identifier.color = identifier->color; 1761 soc_identifier.tc = identifier->tc; 1762 _BCM_SAT_SYSTEM_LOCK(unit); 1763 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_ctf_identifier_unmap, (unit, &soc_identifier)); 1764 _BCM_SAT_SYSTEM_UNLOCK(unit); 1765 #endif/* BCM_SAT_SUPPORT */ 1766 1767 return rv; 1768 } 1769 1770 int bcm_common_sat_ctf_trap_add ( 1771 int unit, 1772 uint32 trap_id 1773 ) 1774 { 1775 int rv = BCM_E_UNAVAIL; 1776 #ifdef BCM_SAT_SUPPORT 1777 _bcm_sat_data_t *psat_data; 1778 int trap_idx = 0; 1779 1780 psat_data = sat_data_get(unit); 1781 SAT_VALUE_MAX_CHECK(trap_id, (_BCM_SAT_CTF_TRAP_ID_VAL_MAX+1), "trap_id"); 1782 rv = _bcm_common_sat_trap_id_find(psat_data, trap_id, &trap_idx); 1783 if (rv == BCM_E_NONE) { 1784 rv = BCM_E_EXISTS; 1785 return rv; 1786 } 1787 rv = BCM_E_NONE; 1788 rv = _bcm_common_sat_ctf_freed_trap_id_find(psat_data, &trap_idx); 1789 if (rv != BCM_E_NONE) { 1790 return rv; 1791 } 1792 1793 SAT_CTF_TRAP_ID_SET(psat_data, trap_idx, trap_id); 1794 _BCM_SAT_SYSTEM_LOCK(unit); 1795 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_ctf_trap_set, (unit, _BCM_SAT_CTF_TRAP_ID_MAX_NUM, psat_data->ctf_trap_id)); 1796 _BCM_SAT_SYSTEM_UNLOCK(unit); 1797 #endif/* BCM_SAT_SUPPORT */ 1798 1799 return rv; 1800 } 1801 1802 int bcm_common_sat_trap_idx_get(int unit, uint32 trap_id,int *trap_idx) 1803 { 1804 int rv = BCM_E_UNAVAIL; 1805 #ifdef BCM_SAT_SUPPORT 1806 int trap_index = 0; 1807 _bcm_sat_data_t *psat_data; 1808 1809 psat_data = sat_data_get(unit); 1810 SAT_VALUE_MAX_CHECK(trap_id, (_BCM_SAT_CTF_TRAP_ID_VAL_MAX+1), "trap_id"); 1811 rv = _bcm_common_sat_trap_id_find(psat_data, trap_id, &trap_index); 1812 if (rv != BCM_E_NONE) { 1813 return rv; 1814 } 1815 *trap_idx = trap_index; 1816 #endif/* BCM_SAT_SUPPORT */ 1817 return rv; 1818 } 1819 1820 int bcm_common_sat_ctf_trap_remove ( 1821 int unit, 1822 uint32 trap_id 1823 ) 1824 { 1825 int rv = BCM_E_UNAVAIL; 1826 #ifdef BCM_SAT_SUPPORT 1827 _bcm_sat_data_t *psat_data; 1828 int trap_idx = 0; 1829 1830 psat_data = sat_data_get(unit); 1831 SAT_VALUE_MAX_CHECK(trap_id, (_BCM_SAT_CTF_TRAP_ID_VAL_MAX+1), "trap_id"); 1832 rv = _bcm_common_sat_trap_id_find(psat_data, trap_id, &trap_idx); 1833 if (rv != BCM_E_NONE) { 1834 return rv; 1835 } 1836 SAT_CTF_TRAP_ID_CLR(psat_data, trap_idx); 1837 _BCM_SAT_SYSTEM_LOCK(unit); 1838 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_ctf_trap_set, (unit, _BCM_SAT_CTF_TRAP_ID_MAX_NUM, psat_data->ctf_trap_id)); 1839 _BCM_SAT_SYSTEM_UNLOCK(unit); 1840 #endif/* BCM_SAT_SUPPORT */ 1841 1842 return rv; 1843 } 1844 1845 int bcm_common_sat_ctf_trap_remove_all 1846 ( 1847 int unit 1848 ) 1849 { 1850 int rv = BCM_E_UNAVAIL; 1851 #ifdef BCM_SAT_SUPPORT 1852 _bcm_sat_data_t *psat_data; 1853 int trap_idx = 0; 1854 1855 psat_data = sat_data_get(unit); 1856 SAT_CTF_TRAP_ID_CLR_ALL(psat_data); 1857 _BCM_SAT_SYSTEM_LOCK(unit); 1858 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_ctf_trap_set, (unit, _BCM_SAT_CTF_TRAP_ID_MAX_NUM, psat_data->ctf_trap_id)); 1859 _BCM_SAT_SYSTEM_UNLOCK(unit); 1860 #endif/* BCM_SAT_SUPPORT */ 1861 1862 return rv; 1863 } 1864 1865 int bcm_common_sat_ctf_bin_limit_set ( 1866 int unit, 1867 int bins_count, 1868 bcm_sat_ctf_bin_limit_t* bins 1869 ) 1870 { 1871 int rv = BCM_E_UNAVAIL; 1872 #ifdef BCM_SAT_SUPPORT 1873 soc_sat_ctf_bin_limit_t soc_bins_limit[_BCM_SAT_CTF_BINS_LIMIT_CNT_MAX]; 1874 int idx = 0; 1875 1876 SAT_NULL_CHECK(bins, "bins"); 1877 SAT_VALUE_CHECK(bins_count, _BCM_SAT_CTF_BINS_LIMIT_CNT_MIN, (_BCM_SAT_CTF_BINS_LIMIT_CNT_MAX+1), "bins_count"); 1878 sal_memset(&soc_bins_limit, 0, sizeof(soc_bins_limit)); 1879 for (idx = 0; idx < bins_count; idx++) { 1880 SAT_VALUE_MAX_CHECK(bins[idx].bin_select, _BCM_SAT_CTF_BINS_LIMIT_CNT_MAX, "bin_select"); 1881 soc_bins_limit[idx].bin_select = bins[idx].bin_select; 1882 soc_bins_limit[idx].bin_limit = bins[idx].bin_limit; 1883 } 1884 _BCM_SAT_SYSTEM_LOCK(unit); 1885 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_ctf_bin_limit_set, (unit, bins_count, soc_bins_limit)); 1886 _BCM_SAT_SYSTEM_UNLOCK(unit); 1887 #endif/* BCM_SAT_SUPPORT */ 1888 1889 return rv; 1890 } 1891 1892 int bcm_common_sat_ctf_bin_limit_get ( 1893 int unit, 1894 int max_bins_count, 1895 bcm_sat_ctf_bin_limit_t* bins, 1896 int * bins_count 1897 ) 1898 { 1899 int rv = BCM_E_UNAVAIL; 1900 #ifdef BCM_SAT_SUPPORT 1901 soc_sat_ctf_bin_limit_t soc_bins_limit[_BCM_SAT_CTF_BINS_LIMIT_CNT_MAX]; 1902 int idx = 0; 1903 1904 SAT_NULL_CHECK(bins_count, "bins_count"); 1905 SAT_NULL_CHECK(bins, "bins"); 1906 SAT_VALUE_CHECK(max_bins_count, _BCM_SAT_CTF_BINS_LIMIT_CNT_MIN, _BCM_SAT_CTF_BINS_LIMIT_CNT_MAX+1, "max_bins_count"); 1907 sal_memset(&soc_bins_limit, 0, sizeof(soc_bins_limit)); 1908 _BCM_SAT_SYSTEM_LOCK(unit); 1909 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_ctf_bin_limit_get, (unit, max_bins_count, bins_count, soc_bins_limit)); 1910 _BCM_SAT_SYSTEM_UNLOCK(unit); 1911 for (idx = 0; idx < (*bins_count); idx++) { 1912 bins[idx].bin_select = soc_bins_limit[idx].bin_select; 1913 bins[idx].bin_limit = soc_bins_limit[idx].bin_limit; 1914 } 1915 #endif/* BCM_SAT_SUPPORT */ 1916 1917 return rv; 1918 } 1919 1920 int bcm_common_sat_ctf_stat_config_set ( 1921 int unit, 1922 bcm_sat_ctf_t ctf_id, 1923 bcm_sat_ctf_stat_config_t *stat 1924 ) 1925 { 1926 int rv = BCM_E_UNAVAIL; 1927 #ifdef BCM_SAT_SUPPORT 1928 soc_sat_ctf_stat_config_t soc_sat_ctf_stat_cfg; 1929 _bcm_sat_data_t *psat_data; 1930 1931 psat_data = sat_data_get(unit); 1932 SAT_NULL_CHECK(stat, "stat"); 1933 SAT_VALUE_CHECK(ctf_id, _BCM_SAT_CTF_ID_MIN, (_BCM_SAT_CTF_ID_MAX+1), "ctf_id"); 1934 SAT_CTF_ID_NOT_EXIST_EXIT(psat_data, ctf_id); 1935 sal_memset(&soc_sat_ctf_stat_cfg, 0, sizeof(soc_sat_ctf_stat_cfg)); 1936 soc_sat_ctf_stat_cfg.bin_min_delay = stat->bin_min_delay; 1937 soc_sat_ctf_stat_cfg.bin_step = stat->bin_step; 1938 soc_sat_ctf_stat_cfg.use_global_bin_config = (stat->use_global_bin_config ? 1 : 0); 1939 soc_sat_ctf_stat_cfg.update_counters_in_unvavail_state = (stat->update_counters_in_unvavail_state ? 1 : 0); 1940 _BCM_SAT_SYSTEM_LOCK(unit); 1941 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_ctf_stat_config_set, (unit, ctf_id, &soc_sat_ctf_stat_cfg)); 1942 _BCM_SAT_SYSTEM_UNLOCK(unit); 1943 #endif/* BCM_SAT_SUPPORT */ 1944 1945 return rv; 1946 } 1947 1948 int bcm_common_sat_ctf_stat_get ( 1949 int unit, 1950 bcm_sat_ctf_t ctf_id, 1951 uint32 flags, 1952 bcm_sat_ctf_stat_t* stat 1953 ) 1954 { 1955 int rv = BCM_E_UNAVAIL; 1956 #ifdef BCM_SAT_SUPPORT 1957 _bcm_sat_data_t *psat_data; 1958 soc_sat_ctf_stat_t soc_stat; 1959 1960 psat_data = sat_data_get(unit); 1961 SAT_NULL_CHECK(stat, "stat"); 1962 SAT_VALUE_CHECK(ctf_id, _BCM_SAT_CTF_ID_MIN, (_BCM_SAT_CTF_ID_MAX+1), "ctf_id"); 1963 SAT_CTF_ID_NOT_EXIST_EXIT(psat_data, ctf_id); 1964 sal_memset(&soc_stat, 0, sizeof(soc_sat_ctf_stat_t)); 1965 _BCM_SAT_SYSTEM_LOCK(unit); 1966 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_ctf_stat_get, (unit, ctf_id, flags, &soc_stat)); 1967 _BCM_SAT_SYSTEM_UNLOCK(unit); 1968 sal_memcpy(stat, &soc_stat, sizeof(bcm_sat_ctf_stat_t)); 1969 #endif/* BCM_SAT_SUPPORT */ 1970 1971 return rv; 1972 } 1973 1974 int bcm_common_sat_ctf_availability_config_set ( 1975 int unit, 1976 bcm_sat_ctf_t ctf_id, 1977 bcm_sat_ctf_availability_config_t *config 1978 ) 1979 { 1980 int rv = BCM_E_UNAVAIL; 1981 #ifdef BCM_SAT_SUPPORT 1982 soc_sat_ctf_availability_config_t avail_cfg; 1983 _bcm_sat_data_t *psat_data; 1984 1985 psat_data = sat_data_get(unit); 1986 SAT_NULL_CHECK(config, "config"); 1987 SAT_VALUE_CHECK(ctf_id, _BCM_SAT_CTF_ID_MIN, (_BCM_SAT_CTF_ID_MAX+1), "ctf_id"); 1988 SAT_CTF_ID_NOT_EXIST_EXIT(psat_data, ctf_id); 1989 SAT_VALUE_MAX_CHECK(config->switch_state_num_of_slots, 1990 (_BCM_SAT_CTF_SWITCH_STATE_NUM_OF_SLOTS_MAX+1), "switch_state_num_of_slots"); 1991 SAT_VALUE_MAX_CHECK(config->switch_state_threshold_per_slot, 1992 (_BCM_SAT_CTF_SWITCH_STATE_THRES_PER_SLOT_MAX+1), "switch_state_threshold_per_slot"); 1993 sal_memset(&avail_cfg, 0, sizeof(avail_cfg)); 1994 avail_cfg.switch_state_num_of_slots = config->switch_state_num_of_slots; 1995 avail_cfg.switch_state_threshold_per_slot = config->switch_state_threshold_per_slot; 1996 _BCM_SAT_SYSTEM_LOCK(unit); 1997 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_ctf_availability_config_set, (unit, ctf_id, &avail_cfg)); 1998 _BCM_SAT_SYSTEM_UNLOCK(unit); 1999 #endif/* BCM_SAT_SUPPORT */ 2000 2001 return rv; 2002 } 2003 2004 int bcm_common_sat_ctf_trap_data_to_session_map ( 2005 int unit, 2006 uint32 trap_data, 2007 uint32 trap_data_mask, 2008 uint32 session_id 2009 ) 2010 { 2011 int rv = BCM_E_UNAVAIL; 2012 #ifdef BCM_SAT_SUPPORT 2013 _bcm_sat_data_t *psat_data; 2014 uint32 entry_idx; 2015 2016 psat_data = sat_data_get(unit); 2017 SAT_VALUE_MAX_CHECK(trap_data, (_BCM_SAT_CTF_TRAP_DATA_MAX+1), "trap_data"); 2018 SAT_VALUE_MAX_CHECK(trap_data_mask, (_BCM_SAT_CTF_TRAP_DATA_MASK_MAX+1), "trap_data_mask"); 2019 SAT_VALUE_MAX_CHECK(session_id, (_BCM_SAT_CTF_TRAP_DATA_SSID_MAX+1), "session_id"); 2020 2021 rv = _bcm_common_sat_ctf_freed_trap_entry_find(psat_data, trap_data, trap_data_mask, &entry_idx); 2022 if (rv != BCM_E_NONE) { 2023 return rv; 2024 } 2025 _BCM_SAT_SYSTEM_LOCK(unit); 2026 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_ctf_trap_data_to_session_map, (unit, trap_data, trap_data_mask, entry_idx, session_id)); 2027 _BCM_SAT_SYSTEM_UNLOCK(unit); 2028 SAT_BITMAP_SET(psat_data->ctf_ssid_bitmap, entry_idx); 2029 psat_data->trap_data[entry_idx].trap_data = trap_data; 2030 psat_data->trap_data[entry_idx].trap_mask = trap_data_mask; 2031 psat_data->trap_data[entry_idx].ssid = session_id; 2032 #endif/* BCM_SAT_SUPPORT */ 2033 2034 return rv; 2035 } 2036 2037 int bcm_common_sat_ctf_trap_data_to_session_unmap ( 2038 int unit, 2039 uint32 trap_data, 2040 uint32 trap_data_mask 2041 ) 2042 { 2043 int rv = BCM_E_UNAVAIL; 2044 #ifdef BCM_SAT_SUPPORT 2045 _bcm_sat_data_t *psat_data; 2046 uint32 entry_idx; 2047 2048 psat_data = sat_data_get(unit); 2049 SAT_VALUE_MAX_CHECK(trap_data, (_BCM_SAT_CTF_TRAP_DATA_MAX+1), "trap_data"); 2050 SAT_VALUE_MAX_CHECK(trap_data_mask, (_BCM_SAT_CTF_TRAP_DATA_MASK_MAX+1), "trap_data_mask"); 2051 rv = _bcm_common_sat_ctf_trap_entry_find(psat_data, trap_data, trap_data_mask, &entry_idx); 2052 if (rv != BCM_E_NONE) { 2053 return rv; 2054 } 2055 _BCM_SAT_SYSTEM_LOCK(unit); 2056 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_ctf_trap_data_to_session_unmap, (unit, entry_idx)); 2057 _BCM_SAT_SYSTEM_UNLOCK(unit); 2058 SAT_BITMAP_CLR(psat_data->ctf_ssid_bitmap, entry_idx); 2059 sal_memset(&(psat_data->trap_data[entry_idx]), 0, sizeof(_bcm_sat_ctf_trap_data_t)); 2060 #endif/* BCM_SAT_SUPPORT */ 2061 2062 return rv; 2063 } 2064 2065 int bcm_common_sat_ctf_reports_config_set ( 2066 int unit, 2067 bcm_sat_ctf_t ctf_id, 2068 bcm_sat_ctf_report_config_t *reports 2069 ) 2070 { 2071 int rv = BCM_E_UNAVAIL; 2072 #ifdef BCM_SAT_SUPPORT 2073 soc_sat_ctf_report_config_t soc_reports; 2074 _bcm_sat_data_t *psat_data; 2075 2076 psat_data = sat_data_get(unit); 2077 SAT_NULL_CHECK(reports, "reports"); 2078 SAT_VALUE_CHECK(ctf_id, _BCM_SAT_CTF_ID_MIN, (_BCM_SAT_CTF_ID_MAX+1), "ctf_id"); 2079 SAT_VALUE_MAX_CHECK(reports->report_sampling_percent, (_BCM_SAT_CTF_REPORT_SAMPLING_PER_MAX+1), "report_sampling_percent"); 2080 SAT_CTF_ID_NOT_EXIST_EXIT(psat_data, ctf_id); 2081 sal_memset(&soc_reports, 0, sizeof(bcm_sat_ctf_report_config_t)); 2082 soc_reports.report_sampling_percent = reports->report_sampling_percent; 2083 if (reports->flags & BCM_SAT_CTF_REPORT_ADD_SEQ_NUM) { 2084 soc_reports.flags |= SOC_SAT_CTF_REPORT_ADD_SEQ_NUM; 2085 } 2086 if (reports->flags & BCM_SAT_CTF_REPORT_ADD_DELAY) { 2087 soc_reports.flags |= SOC_SAT_CTF_REPORT_ADD_DELAY; 2088 } 2089 _BCM_SAT_SYSTEM_LOCK(unit); 2090 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_ctf_reports_config_set, (unit, ctf_id, &soc_reports)); 2091 _BCM_SAT_SYSTEM_UNLOCK(unit); 2092 #endif/* BCM_SAT_SUPPORT */ 2093 2094 return rv; 2095 } 2096 2097 int bcm_common_sat_interrupt_process(int unit) 2098 { 2099 int rv = BCM_E_UNAVAIL; 2100 #ifdef BCM_SAT_SUPPORT 2101 #if defined(BCM_SABER2_SUPPORT) 2102 if (SOC_IS_SABER2(unit)) { 2103 bcm_sat_event_type_t type = bcmSATEventReport; 2104 BCM_IF_ERROR_RETURN(bcm_sb2_sat_ctf_report_process(unit, 2105 _bcm_sat_event_cb[unit][type], 2106 _bcm_sat_event_ud[unit][type])); 2107 } 2108 2109 /* Clear OAMP interrupt */ 2110 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_oamp_stat_event_clear, (unit)); 2111 #endif /* BCM_SABER2_SUPPORT */ 2112 2113 #endif /* BCM_SAT_SUPPORT */ 2114 2115 return rv; 2116 } 2117 2118 int 2119 bcm_common_sat_event_register( 2120 int unit, 2121 bcm_sat_event_type_t event_type, 2122 bcm_sat_event_cb cb, 2123 void *user_data) 2124 { 2125 int rv = BCM_E_UNAVAIL; 2126 2127 #ifdef BCM_SAT_SUPPORT 2128 bcm_sat_event_type_t type; 2129 2130 if (soc_feature(unit, soc_feature_sat) && 2131 soc_property_get(unit, spn_SAT_ENABLE, 0)) { 2132 rv = BCM_E_NONE; 2133 for (type = 0; type < bcmSATEventCount; type++) { 2134 if (type == event_type) { 2135 break; 2136 } 2137 } 2138 if (type == bcmSATEventCount) { 2139 return BCM_E_PARAM; 2140 } 2141 2142 if (_bcm_sat_event_cb[unit][type] && 2143 (_bcm_sat_event_cb[unit][type] != cb)) { 2144 LOG_ERROR(BSL_LS_BCM_SAT, (BSL_META_U(unit, 2145 "EVENT %d already has a registered callback\n"), type)); 2146 return BCM_E_EXISTS; 2147 } 2148 _bcm_sat_event_cb[unit][type] = cb; 2149 _bcm_sat_event_ud[unit][type] = user_data; 2150 2151 #if defined(BCM_SABER2_SUPPORT) 2152 BCM_IF_ERROR_RETURN(soc_common_sat_handler_register( 2153 unit, bcm_common_sat_interrupt_process)); 2154 /* Enable OAMP interrupt */ 2155 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_oamp_stat_event_control, (unit, 1)); 2156 #elif defined(BCM_DPP_SUPPORT) 2157 rv = _bcm_jer_sat_event_register(unit, event_type, cb, user_data); 2158 #endif 2159 } 2160 #endif/* BCM_SAT_SUPPORT */ 2161 2162 return rv; 2163 } 2164 2165 int 2166 bcm_common_sat_event_unregister( 2167 int unit, 2168 bcm_sat_event_type_t event_type, 2169 bcm_sat_event_cb cb) 2170 { 2171 int rv = BCM_E_UNAVAIL; 2172 2173 #ifdef BCM_SAT_SUPPORT 2174 bcm_sat_event_type_t type; 2175 2176 if (soc_feature(unit, soc_feature_sat) && 2177 soc_property_get(unit, spn_SAT_ENABLE, 0)) { 2178 rv = BCM_E_NONE; 2179 for (type = 0; type < bcmSATEventCount; type++) { 2180 if (type == event_type) { 2181 break; 2182 } 2183 } 2184 if (type == bcmSATEventCount) { 2185 return BCM_E_PARAM; 2186 } 2187 2188 if (_bcm_sat_event_cb[unit][type] && 2189 (_bcm_sat_event_cb[unit][type] != cb)) { 2190 LOG_ERROR(BSL_LS_BCM_SAT, (BSL_META_U(unit, 2191 "A different callback is registered for %d\n"), type)); 2192 return BCM_E_EXISTS; 2193 } 2194 2195 _bcm_sat_event_cb[unit][type] = NULL; 2196 _bcm_sat_event_ud[unit][type] = NULL; 2197 #if defined(BCM_SABER2_SUPPORT) 2198 /* Disable OAMP interrupt */ 2199 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_oamp_stat_event_control, (unit, 0)); 2200 BCM_IF_ERROR_RETURN(soc_common_sat_handler_register(unit, NULL)); 2201 #elif defined(BCM_DPP_SUPPORT) 2202 rv = _bcm_jer_sat_event_unregister(unit, event_type, cb); 2203 #endif 2204 2205 } 2206 #endif/* BCM_SAT_SUPPORT */ 2207 2208 return rv; 2209 } 2210 2211 2212 /* 2213 * Function: 2214 * bcm_common_sat_endpoint_create 2215 * Purpose: 2216 * Create or replace a SAT endpoint object 2217 * Parameters: 2218 * unit - (IN) Unit number. 2219 * endpoint_info - (IN/OUT) Pointer to an SAT endpoint structure 2220 * result =s: 2221 * BCM_E_XXX 2222 * Notes: 2223 */ 2224 int 2225 bcm_common_sat_endpoint_create( 2226 int unit, 2227 bcm_sat_endpoint_info_t *endpoint_info) 2228 { 2229 int rv = BCM_E_UNAVAIL; 2230 2231 if (soc_feature(unit, soc_feature_sat)) 2232 { 2233 #ifdef BCM_SABER2_SUPPORT 2234 rv = bcm_sb2_sat_endpoint_create(unit, endpoint_info); 2235 #endif /* BCM_SABER2_SUPPORT */ 2236 } 2237 2238 return rv; 2239 } 2240 2241 /* 2242 * Function: 2243 * bcm_common_sat_endpoint_destroy 2244 * Purpose: 2245 * Destroy an SAT endpoint object 2246 * Parameters: 2247 * unit - (IN) Unit number. 2248 * endpoint - (IN) The ID of the SAT endpoint object to destroy 2249 * flags - (IN) The SAT UPMEP/DOWNMEP endpoint type to be destroyed 2250 * result =s: 2251 * BCM_E_XXX 2252 * Notes: 2253 */ 2254 int 2255 bcm_common_sat_endpoint_destroy( 2256 int unit, 2257 bcm_sat_endpoint_t endpoint, 2258 uint32 flags) 2259 2260 { 2261 int rv = BCM_E_UNAVAIL; 2262 if (soc_feature(unit, soc_feature_sat)) 2263 { 2264 #ifdef BCM_SABER2_SUPPORT 2265 rv = bcm_sb2_sat_endpoint_destroy(unit, endpoint, flags); 2266 #endif /* BCM_SABER2_SUPPORT */ 2267 } 2268 2269 return rv; 2270 2271 } 2272 2273 /* 2274 * Function: 2275 * bcm_common_sat_endpoint_destroy_all 2276 * Purpose: 2277 * Destroy all SAT endpoint objects associated for a given SAT 2278 * endpoint type (UPMEP/DOWNMEP) 2279 * Parameters: 2280 * unit - (IN) Unit number. 2281 * flags - (IN) The SAT UPMEP/DOWNMEP endpoint type whose endpoints should be destroyed 2282 * result =s: 2283 * BCM_E_XXX 2284 * Notes: 2285 */ 2286 int 2287 bcm_common_sat_endpoint_destroy_all( 2288 int unit, 2289 uint32 flags) 2290 { 2291 int rv = BCM_E_UNAVAIL; 2292 2293 if (soc_feature(unit, soc_feature_sat)) 2294 { 2295 #ifdef BCM_SABER2_SUPPORT 2296 rv = bcm_sb2_sat_endpoint_destroy_all(unit, flags); 2297 #endif /* BCM_SABER2_SUPPORT */ 2298 } 2299 2300 return rv; 2301 } 2302 2303 2304 /* 2305 * Function: 2306 * bcm_common_sat_endpoint_get 2307 * Purpose: 2308 * Get an SAT endpoint object 2309 * Parameters: 2310 * unit - (IN) Unit number. 2311 * endpoint - (IN) The ID of the endpoint object to get 2312 * endpoint_info - (OUT) Pointer to an SAT endpoint structure to 2313 * receive the data 2314 * result =s: 2315 * BCM_E_XXX 2316 * Notes: 2317 */ 2318 int bcm_common_sat_endpoint_get( 2319 int unit, 2320 bcm_sat_endpoint_t endpoint, 2321 uint32 flags, 2322 bcm_sat_endpoint_info_t *endpoint_info) 2323 { 2324 int rv = BCM_E_UNAVAIL; 2325 2326 if (soc_feature(unit, soc_feature_sat)) 2327 { 2328 #ifdef BCM_SABER2_SUPPORT 2329 rv = bcm_sb2_sat_endpoint_get(unit, endpoint, flags, endpoint_info); 2330 #endif /* BCM_SABER2_SUPPORT */ 2331 } 2332 2333 return rv; 2334 } 2335 2336 2337 /* 2338 * Function: 2339 * bcm_common_sat_endpoint_traverse 2340 * Purpose: 2341 * Traverse the set of SAT endpoints associated with the 2342 * specified group, calling a specified callback for each one 2343 * Parameters: 2344 * unit - (IN) Unit number. 2345 * cb - (IN) A pointer to the callback function to call for each OAM 2346 endpoint in the specified group 2347 * user_data - (IN) Pointer to user data to supply in the callback 2348 * result =s: 2349 * BCM_E_XXX 2350 * Notes: 2351 */ 2352 int 2353 bcm_common_sat_endpoint_traverse( 2354 int unit, 2355 uint32 flags, 2356 bcm_sat_endpoint_traverse_cb cb, 2357 void *user_data) 2358 { 2359 int rv = BCM_E_UNAVAIL; 2360 2361 if (soc_feature(unit, soc_feature_sat)) 2362 { 2363 #ifdef BCM_SABER2_SUPPORT 2364 rv = bcm_sb2_sat_endpoint_traverse(unit,flags,cb,user_data); 2365 #endif /* BCM_SABER2_SUPPORT */ 2366 } 2367 2368 return rv; 2369 } 2370 2371 int bcm_common_oamp_port_enable_get(int unit, bcm_port_t port) { 2372 2373 #if defined(BCM_SABER2_SUPPORT) 2374 int oamp_enable; 2375 if(SOC_IS_SABER2(unit) && (port == _BCM_SB2_SAT_OAMP_PHY_PORT_NUMBER)) { 2376 (void)bcm_sb2_sat_oamp_enable_get(unit, &oamp_enable); 2377 /* Skip OAMP port for saber2 device */ 2378 if(oamp_enable) { 2379 return TRUE; 2380 } 2381 } 2382 #endif 2383 2384 return FALSE; 2385 } 2386 /* 2387 * Function: 2388 * bcm_common_sat_session_inuse 2389 * Purpose: 2390 * To get the whether the session ID was used or not 2391 * Parameters: 2392 * unit - (IN) Unit number. 2393 * session_id - (IN) SAT session_id 2394 2395 * result: True, session ID is in used. False, session ID is free. 2396 * 2397 * Notes: 2398 */ 2399 int bcm_common_sat_session_inuse( int unit,int session_id) 2400 { 2401 int rv = BCM_E_UNAVAIL; 2402 2403 #ifdef BCM_SAT_SUPPORT 2404 2405 rv = MBCM_SAT_DRIVER_CALL(unit, mbcm_sat_session_inuse, (unit, session_id)); 2406 #endif 2407 2408 return rv; 2409 } 2410 2411 #ifdef BCM_WARM_BOOT_SUPPORT 2412 #ifdef BCM_SAT_SUPPORT 2413 int 2414 bcm_common_sat_wb_init(int unit) 2415 { 2416 _bcm_sat_data_t *psat_data; 2417 int rv = BCM_E_NONE; 2418 uint32 size; 2419 uint32 scache_handle; 2420 uint8 *scache_ptr = NULL; 2421 uint16 default_ver = SAT_WB_CURRENT_VERSION; 2422 uint16 recovered_ver = SAT_WB_CURRENT_VERSION; 2423 int stable_size; 2424 int create; 2425 2426 psat_data = sat_data_get(unit); 2427 2428 /* check to see if an scache table has been configured */ 2429 rv = soc_stable_size_get(unit, &stable_size); 2430 if (SOC_FAILURE(rv) || stable_size <= 0) { 2431 return rv; 2432 } 2433 2434 SOC_SCACHE_HANDLE_SET(scache_handle, unit, BCM_MODULE_SAT, 0); 2435 create = (SOC_WARM_BOOT(unit) ? FALSE : TRUE); 2436 size = (SOC_WARM_BOOT(unit) ? 0 : sizeof(_bcm_sat_data_t)); 2437 2438 /* on cold boot, setup scache */ 2439 rv = soc_versioned_scache_ptr_get(unit, scache_handle, 2440 create, 2441 &size, &scache_ptr, 2442 default_ver, &recovered_ver); 2443 if (BCM_FAILURE(rv) && (rv != SOC_E_NOT_FOUND)) { 2444 LOG_ERROR(BSL_LS_BCM_SAT, 2445 (BSL_META_U(unit, 2446 "Error(%s) reading scache. scache_ptr:%p and len:%d\n"), 2447 soc_errmsg(rv), scache_ptr, size)); 2448 /* If warmboot initialization fails, skip using warmboot for sat */ 2449 rv = SOC_E_NOT_FOUND; 2450 return rv; 2451 } 2452 2453 LOG_VERBOSE(BSL_LS_BCM_SAT, 2454 (BSL_META_U(unit, 2455 "SAT: allocating 0x%x (%d) bytes of scache:"), 2456 size, size)); 2457 2458 if (SOC_WARM_BOOT(unit)) { 2459 soc_scache_handle_used_set(unit, scache_handle, size); 2460 /* if supporting warmboot, use scache */ 2461 if (scache_ptr) { 2462 sal_memcpy(psat_data, scache_ptr, sizeof(_bcm_sat_data_t)); 2463 /* clear out non-recoverable resources */ 2464 psat_data->sat_mutex = NULL; 2465 } 2466 } 2467 2468 return BCM_E_NONE; 2469 } 2470 #endif /* BCM_SAT_SUPPORT */ 2471 2472 int 2473 bcm_common_sat_wb_sync(int unit, int sync) 2474 { 2475 int rv = BCM_E_NONE; 2476 uint8 *scache_ptr = NULL; 2477 uint32 scache_len = 0; 2478 soc_scache_handle_t scache_handle; 2479 uint16 default_ver = SAT_WB_CURRENT_VERSION; 2480 uint16 recovered_ver = SAT_WB_CURRENT_VERSION; 2481 _bcm_sat_data_t *psat_data; 2482 int stable_size; 2483 2484 if(!_bcm_common_sat_is_dirty(unit)) 2485 return BCM_E_NONE; 2486 2487 psat_data = sat_data_get(unit); 2488 2489 if (SOC_WARM_BOOT(unit)) { 2490 LOG_ERROR(BSL_LS_BCM_SAT, 2491 (BSL_META_U(unit, 2492 "Cannot write to SCACHE during WarmBoot\n"))); 2493 return SOC_E_INTERNAL; 2494 } 2495 /* check to see if an scache table has been configured */ 2496 rv = soc_stable_size_get(unit, &stable_size); 2497 if (SOC_FAILURE(rv) || stable_size <= 0) { 2498 return rv; 2499 } 2500 2501 SOC_SCACHE_HANDLE_SET(scache_handle, unit, BCM_MODULE_SAT, 0); 2502 2503 rv = soc_versioned_scache_ptr_get(unit, scache_handle, 2504 FALSE, &scache_len, &scache_ptr, 2505 default_ver, &recovered_ver); 2506 if (SOC_FAILURE(rv) && (rv != SOC_E_NOT_FOUND)) { 2507 LOG_ERROR(BSL_LS_BCM_SAT, 2508 (BSL_META_U(unit, 2509 "Error(%s) reading scache. scache_ptr:%p and len:%d\n"), 2510 soc_errmsg(rv), scache_ptr, scache_len)); 2511 return rv; 2512 } 2513 2514 sal_memcpy(scache_ptr, psat_data, sizeof(_bcm_sat_data_t)); 2515 2516 rv = soc_scache_handle_used_set(unit, scache_handle, sizeof(_bcm_sat_data_t)); 2517 2518 if (sync) { 2519 rv = soc_scache_commit(unit); 2520 if (rv != SOC_E_NONE) { 2521 LOG_ERROR(BSL_LS_BCM_SAT, 2522 (BSL_META_U(unit, 2523 "Error(%s) sync'ing scache to Persistent memory. \n"), 2524 soc_errmsg(rv))); 2525 return rv; 2526 } 2527 } 2528 2529 _bcm_commot_sat_mark_not_dirty(unit); 2530 2531 return BCM_E_NONE; 2532 } 2533 #endif /* BCM_WARM_BOOT_SUPPORT */ 2534