telemetry.c (103989B)
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 * Telemetry - Common telemetry infrastructure interface 8 * Purpose: APIs to configure telemetry instances 9 * which will be used by instrumentation applications. 10 */ 11 12 #if defined(INCLUDE_TELEMETRY) 13 14 #include <shared/bsl.h> 15 #include <soc/defs.h> 16 #include <soc/drv.h> 17 #include <soc/uc.h> 18 #include <shared/alloc.h> 19 #include <soc/shared/shr_pkt.h> 20 #include <soc/shared/st_pack.h> 21 #include <soc/tomahawk.h> 22 23 #include <bcm/types.h> 24 #include <bcm/error.h> 25 #include <bcm/module.h> 26 27 #include <bcm_int/esw/telemetry.h> 28 #include <bcm_int/esw/xgs5.h> 29 #include <bcm_int/esw/switch.h> 30 #include <bcm_int/esw/collector.h> 31 #include <bcm_int/esw_dispatch.h> 32 #include <bcm_int/esw/st_feature.h> 33 #include <bcm_int/esw/st_sdk_pack.h> 34 #include <bcm_int/esw/st_sdk_msg.h> 35 36 /*Global to hold the ifa firmware version for feature compatibility check */ 37 uint32 st_firmware_version = 0; 38 39 /* Telemetry global information */ 40 _bcm_telemetry_global_info_t *telemetry_global_info[BCM_MAX_NUM_UNITS] = {0}; 41 42 /* List of telemetry instances info*/ 43 _bcm_telemetry_instance_info_t *telemetry_instances_info_list[BCM_MAX_NUM_UNITS] 44 = {0}; 45 46 /* Telemetry module invalid value definition */ 47 #define BCM_TELEMETRY_INVALID_VALUE -1 48 49 /* Default max export length is 1500 bytes */ 50 #define BCM_TELEMETRY_DEFAULT_MAX_EXPORT_LENGTH 1500 51 52 /****************************************************** 53 * * 54 * UTILITY FUNCTIONS * 55 */ 56 57 /* 58 * Function: 59 * _bcm_xgs5_telemetry_is_instance_exists 60 * Purpose: 61 * Checks whether a telemetry instance exists or not. 62 * Parameters: 63 * unit - (IN) BCM device number 64 * telemetry_instance_id - (IN) The telemetry instance ID 65 * instance_index - (IN) If exists, Index of that instance 66 * first_free_index - (IN) Index of first free instance 67 * Returns: 68 * BCM_E_XXX 69 */ 70 STATIC int 71 _bcm_xgs5_telemetry_is_instance_exists(int unit, 72 int telemetry_instance_id, 73 int *instance_index, 74 int *first_free_index) 75 { 76 int i = 0, rv = BCM_E_NONE, match_found = 0; 77 _bcm_telemetry_instance_info_t *telemetry_instance_list_node = NULL; 78 79 for (i=0; i< BCM_INT_TELEMETRY_MAX_INSTANCES; i++) { 80 telemetry_instance_list_node = 81 &(telemetry_instances_info_list[unit][i]); 82 if(telemetry_instance_list_node->instance_id == telemetry_instance_id) 83 { 84 match_found = 1; 85 *instance_index = i; 86 break; 87 } else if (telemetry_instance_list_node->instance_id == 88 BCM_TELEMETRY_INVALID_INDEX) { 89 *first_free_index = i; 90 } 91 } 92 93 if(match_found == 0) 94 { 95 rv = BCM_E_NOT_FOUND; 96 } 97 LOG_DEBUG(BSL_LS_BCM_TELEMETRY, 98 (BSL_META_U(unit, 99 "TELEMETRY(unit %d) Instance exist check: %s" 100 " (Telemetry instance=0x%x).\n"), unit, __FUNCTION__, 101 telemetry_instance_id)); 102 return rv; 103 } 104 105 /****************************************************** 106 * * 107 * ST EMBEDDED APP MESSAGING FUNCTIONS * 108 */ 109 110 /* 111 * Function: 112 * _bcm_xgs5_st_convert_uc_error 113 * Purpose: 114 * Converts uController error code to corresponding BCM error code. 115 * Parameters: 116 * uc_rv - (IN) uController error code to convert. 117 * Returns: 118 * BCM_E_XXX - BCM error code. 119 * Notes: 120 */ 121 STATIC int 122 _bcm_xgs5_st_convert_uc_error(uint32 uc_rv) 123 { 124 int rv = BCM_E_NONE; 125 126 switch(uc_rv) { 127 case SHR_ST_UC_E_NONE: 128 rv = BCM_E_NONE; 129 break; 130 case SHR_ST_UC_E_INTERNAL: 131 rv = BCM_E_INTERNAL; 132 break; 133 case SHR_ST_UC_E_MEMORY: 134 rv = BCM_E_MEMORY; 135 break; 136 case SHR_ST_UC_E_UNIT: 137 rv = BCM_E_UNIT; 138 break; 139 case SHR_ST_UC_E_PARAM: 140 rv = BCM_E_PARAM; 141 break; 142 case SHR_ST_UC_E_EMPTY: 143 rv = BCM_E_EMPTY; 144 break; 145 case SHR_ST_UC_E_FULL: 146 rv = BCM_E_FULL; 147 break; 148 case SHR_ST_UC_E_NOT_FOUND: 149 rv = BCM_E_NOT_FOUND; 150 break; 151 case SHR_ST_UC_E_EXISTS: 152 rv = BCM_E_EXISTS; 153 break; 154 case SHR_ST_UC_E_TIMEOUT: 155 rv = BCM_E_TIMEOUT; 156 break; 157 case SHR_ST_UC_E_BUSY: 158 rv = BCM_E_BUSY; 159 break; 160 case SHR_ST_UC_E_FAIL: 161 rv = BCM_E_FAIL; 162 break; 163 case SHR_ST_UC_E_DISABLED: 164 rv = BCM_E_DISABLED; 165 break; 166 case SHR_ST_UC_E_BADID: 167 rv = BCM_E_BADID; 168 break; 169 case SHR_ST_UC_E_RESOURCE: 170 rv = BCM_E_RESOURCE; 171 break; 172 case SHR_ST_UC_E_CONFIG: 173 rv = BCM_E_CONFIG; 174 break; 175 case SHR_ST_UC_E_UNAVAIL: 176 rv = BCM_E_UNAVAIL; 177 break; 178 case SHR_ST_UC_E_INIT: 179 rv = BCM_E_INIT; 180 break; 181 case SHR_ST_UC_E_PORT: 182 rv = BCM_E_PORT; 183 break; 184 default: 185 rv = BCM_E_INTERNAL; 186 break; 187 } 188 189 return rv; 190 } 191 192 STATIC int 193 _bcm_xgs5_st_msg_send_receive(int unit, uint8 s_subclass, 194 uint16 s_len, uint32 s_data, 195 uint8 r_subclass, uint16 *r_len, 196 sal_usecs_t timeout) 197 { 198 int rv; 199 mos_msg_data_t send, reply; 200 uint32 uc_rv; 201 _bcm_telemetry_global_info_t *telemetry_config_per_unit = 202 TELEMETRY_GLOBAL_INFO_GET(unit); 203 uint8 *dma_buffer; 204 int dma_buffer_len; 205 206 207 dma_buffer = telemetry_config_per_unit->dma_buffer; 208 dma_buffer_len = telemetry_config_per_unit->dma_buffer_len; 209 210 sal_memset(&send, 0, sizeof(send)); 211 sal_memset(&reply, 0, sizeof(reply)); 212 send.s.mclass = MOS_MSG_CLASS_ST; 213 send.s.subclass = s_subclass; 214 send.s.len = bcm_htons(s_len); 215 216 /* 217 * Set 'data' to DMA buffer address if a DMA operation is 218 * required for send or receive. 219 */ 220 if (MOS_MSG_DMA_MSG(s_subclass) || 221 MOS_MSG_DMA_MSG(r_subclass)) { 222 send.s.data = bcm_htonl(soc_cm_l2p(unit, dma_buffer)); 223 } else { 224 send.s.data = bcm_htonl(s_data); 225 } 226 227 /* Flush DMA memory */ 228 if (MOS_MSG_DMA_MSG(s_subclass)) { 229 soc_cm_sflush(unit, dma_buffer, s_len); 230 } 231 232 /* Invalidate DMA memory to read */ 233 if (MOS_MSG_DMA_MSG(r_subclass)) { 234 soc_cm_sinval(unit, dma_buffer, dma_buffer_len); 235 } 236 237 rv = soc_cmic_uc_msg_send_receive(unit, telemetry_config_per_unit->uC, 238 &send, &reply, 239 timeout); 240 if (rv != SOC_E_NONE){ 241 return BCM_E_INTERNAL; 242 } 243 244 /* Convert ST uController error code to BCM */ 245 uc_rv = bcm_ntohl(reply.s.data); 246 rv = _bcm_xgs5_st_convert_uc_error(uc_rv); 247 248 *r_len = bcm_ntohs(reply.s.len); 249 250 /*Check reply class and subclass*/ 251 if((rv == SOC_E_NONE) && ((reply.s.mclass != MOS_MSG_CLASS_ST) || 252 (reply.s.subclass != r_subclass))) 253 { 254 return BCM_E_INTERNAL; 255 } 256 return rv; 257 } 258 259 STATIC int 260 bcm_xgs5_st_eapp_instance_get_msg (int unit, 261 int instance_id, 262 bcm_telemetry_config_t *telemetry_config, 263 int config_count) 264 { 265 shr_st_msg_ctrl_instance_get_t instance_get_msg; 266 uint8 *buffer_req = NULL, *buffer_ptr = NULL; 267 uint16 buffer_len = 0, reply_len = 0; 268 _bcm_telemetry_global_info_t *telemetry_per_unit_global_info = 269 TELEMETRY_GLOBAL_INFO_GET(unit); 270 int i,j; 271 bcm_telemetry_config_t *object_config = NULL; 272 273 sal_memset(&instance_get_msg, 0, sizeof(instance_get_msg)); 274 BCM_IF_ERROR_RETURN(_bcm_xgs5_st_msg_send_receive(unit, 275 MOS_MSG_SUBCLASS_ST_INSTANCE_GET, 276 instance_id, 0, 277 MOS_MSG_SUBCLASS_ST_INSTANCE_GET_REPLY, 278 &reply_len, 279 SHR_ST_MAX_UC_MSG_TIMEOUT)); 280 281 buffer_req = telemetry_per_unit_global_info->dma_buffer; 282 buffer_ptr = shr_st_msg_ctrl_instance_get_unpack(buffer_req, 283 &instance_get_msg); 284 buffer_len = buffer_ptr - buffer_req; 285 286 if (reply_len != buffer_len) { 287 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 288 (BSL_META_U(unit, 289 "TELEMETRY(unit %d) Error: Port " 290 " get failed from BTE\n"), unit)); 291 return BCM_E_INTERNAL; 292 } 293 294 if (config_count != instance_get_msg.num_ports) 295 { 296 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 297 (BSL_META_U(unit, 298 "TELEMETRY(unit %d) Error: Num Ports %d" 299 " and config count %d mismatch in instance(%d) get from BTE\n"), 300 unit, instance_get_msg.num_ports, config_count, instance_id)); 301 return BCM_E_INTERNAL; 302 303 } 304 305 for (i= 0; i < instance_get_msg.num_ports; i++) 306 { 307 object_config = &(telemetry_config[i]); 308 BCM_GPORT_LOCAL_SET(object_config->gport,instance_get_msg.lports[i]); 309 object_config->component_id = instance_get_msg.component_id; 310 311 sal_memset(object_config->object_type, bcmTelemetryObjectTypeNone, 312 sizeof(object_config->object_type)); 313 j = 0; 314 if (instance_get_msg.stat_types[i] & SHR_ST_STAT_TYPE_IF_INGRESS) 315 { 316 object_config->object_type[j] = bcmTelemetryObjectTypeIntfIngress; 317 j++; 318 } 319 320 if (instance_get_msg.stat_types[i] & SHR_ST_STAT_TYPE_IF_EGRESS) 321 { 322 object_config->object_type[j] = bcmTelemetryObjectTypeIntfEgress; 323 j++; 324 } 325 if (instance_get_msg.stat_types[i] & SHR_ST_STAT_TYPE_QUEUE_EGRESS) 326 { 327 object_config->object_type[j] = 328 bcmTelemetryObjectTypeIntfEgressQueue; 329 j++; 330 } 331 if (instance_get_msg.stat_types[i] & SHR_ST_STAT_TYPE_IF_INGRESS_ERRORS) 332 { 333 object_config->object_type[j] = 334 bcmTelemetryObjectTypeIntfIngressError; 335 j++; 336 } 337 338 sal_memcpy(object_config->port_name, instance_get_msg.if_names[i], 339 instance_get_msg.if_name_lengths[i]); 340 object_config->port_name[instance_get_msg.if_name_lengths[i]] = '\0'; 341 } 342 343 return BCM_E_NONE; 344 } 345 STATIC int 346 bcm_xgs5_st_eapp_instance_create_msg (int unit, 347 int instance_id, 348 bcm_telemetry_config_t *telemetry_config, 349 int config_count) 350 { 351 shr_st_msg_ctrl_instance_create_t instance_create_msg; 352 uint8 *buffer_req = NULL, *buffer_ptr = NULL; 353 uint16 buffer_len = 0, reply_len = 0; 354 _bcm_telemetry_global_info_t *telemetry_per_unit_global_info = 355 TELEMETRY_GLOBAL_INFO_GET(unit); 356 int i,j; 357 bcm_telemetry_config_t *object_config = NULL; 358 uint16 lports[SHR_ST_MAX_PORTS], config_lport = 0; 359 uint32 stat_types = 0; 360 char *port_name; 361 362 sal_memset(&instance_create_msg, 0, sizeof(instance_create_msg)); 363 364 for (i= 0; i < config_count; i++) 365 { 366 object_config = &(telemetry_config[i]); 367 config_lport = BCM_GPORT_LOCAL_GET(object_config->gport); 368 369 lports[i] = config_lport; 370 stat_types = 0; 371 for (j = 0; j < bcmTelemetryObjectTypeCount; j++) 372 { 373 if(object_config->object_type[j] == 374 bcmTelemetryObjectTypeIntfIngress) 375 { 376 stat_types |= SHR_ST_STAT_TYPE_IF_INGRESS; 377 } 378 if(object_config->object_type[j] == 379 bcmTelemetryObjectTypeIntfEgress) 380 { 381 stat_types |= SHR_ST_STAT_TYPE_IF_EGRESS; 382 } 383 if(object_config->object_type[j] == 384 bcmTelemetryObjectTypeIntfEgressQueue) 385 { 386 stat_types |= SHR_ST_STAT_TYPE_QUEUE_EGRESS; 387 } 388 if(object_config->object_type[j] == 389 bcmTelemetryObjectTypeIntfIngressError) 390 { 391 stat_types |= SHR_ST_STAT_TYPE_IF_INGRESS_ERRORS; 392 } 393 } 394 instance_create_msg.stat_types[i] = stat_types; 395 instance_create_msg.component_id = object_config->component_id; 396 port_name = (char*)object_config->port_name; 397 instance_create_msg.if_name_lengths[i] = 398 sal_strlen(port_name); 399 sal_memcpy(&(instance_create_msg.if_names[i]), port_name, 400 sal_strlen(port_name)); 401 } 402 instance_create_msg.num_ports = config_count; 403 instance_create_msg.instance_id = instance_id; 404 sal_memcpy(instance_create_msg.lports, 405 lports, 406 (instance_create_msg.num_ports * sizeof(uint16))); 407 408 buffer_req = telemetry_per_unit_global_info->dma_buffer; 409 buffer_ptr = shr_st_msg_ctrl_instance_create_pack(buffer_req, 410 &instance_create_msg); 411 buffer_len = buffer_ptr - buffer_req; 412 413 BCM_IF_ERROR_RETURN(_bcm_xgs5_st_msg_send_receive(unit, 414 MOS_MSG_SUBCLASS_ST_INSTANCE_CREATE, 415 buffer_len, 0, 416 MOS_MSG_SUBCLASS_ST_INSTANCE_CREATE_REPLY, 417 &reply_len, 418 SHR_ST_MAX_UC_MSG_TIMEOUT)); 419 return BCM_E_NONE; 420 } 421 422 STATIC int 423 bcm_xgs5_st_eapp_instance_delete_msg (int unit, int instance_id) 424 { 425 uint16 reply_len = 0; 426 427 BCM_IF_ERROR_RETURN(_bcm_xgs5_st_msg_send_receive(unit, 428 MOS_MSG_SUBCLASS_ST_INSTANCE_DELETE, 429 instance_id, 0, 430 MOS_MSG_SUBCLASS_ST_INSTANCE_DELETE_REPLY, 431 &reply_len, 432 SHR_ST_MAX_UC_MSG_TIMEOUT)); 433 return BCM_E_NONE; 434 } 435 436 STATIC int 437 bcm_xgs5_st_eapp_port_get_msg(int unit) 438 { 439 shr_st_msg_ctrl_ports_get_t ports_get_msg; 440 uint8 *buffer_req = NULL, *buffer_ptr = NULL; 441 uint16 buffer_len = 0, reply_len = 0; 442 _bcm_telemetry_global_info_t *telemetry_per_unit_global_info = 443 TELEMETRY_GLOBAL_INFO_GET(unit); 444 445 sal_memset(&ports_get_msg, 0, sizeof(ports_get_msg)); 446 447 BCM_IF_ERROR_RETURN(_bcm_xgs5_st_msg_send_receive(unit, 448 MOS_MSG_SUBCLASS_ST_PORTS_GET, 449 0, 0, 450 MOS_MSG_SUBCLASS_ST_PORTS_GET_REPLY, 451 &reply_len, 452 SHR_ST_MAX_UC_MSG_TIMEOUT)); 453 454 buffer_req = telemetry_per_unit_global_info->dma_buffer; 455 buffer_ptr = shr_st_msg_ctrl_ports_get_unpack(buffer_req, 456 &ports_get_msg); 457 buffer_len = buffer_ptr - buffer_req; 458 459 if (reply_len != buffer_len) { 460 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 461 (BSL_META_U(unit, 462 "TELEMETRY(unit %d) Error: Port " 463 " get failed from BTE\n"), unit)); 464 return BCM_E_INTERNAL; 465 } 466 467 telemetry_per_unit_global_info->num_ports = ports_get_msg.num_ports; 468 sal_memcpy(telemetry_per_unit_global_info->lports, ports_get_msg.lports, 469 (ports_get_msg.num_ports * sizeof(uint16))); 470 471 return BCM_E_NONE; 472 } 473 474 STATIC int 475 bcm_xgs5_st_eapp_port_delete_msg (int unit, 476 bcm_telemetry_config_t *telemetry_config, 477 int config_count) 478 { 479 shr_st_msg_ctrl_ports_delete_t ports_delete_msg; 480 uint8 *buffer_req = NULL, *buffer_ptr = NULL, match_found = 0; 481 uint16 buffer_len = 0, reply_len = 0; 482 _bcm_telemetry_global_info_t *telemetry_per_unit_global_info = 483 TELEMETRY_GLOBAL_INFO_GET(unit); 484 int i,j,k=0,next_pos = 0; 485 bcm_telemetry_config_t *object_config = NULL; 486 uint16 config_lport = 0, list_lport = 0; 487 uint16 lports_list[SHR_ST_MAX_PORTS], del_lports_list[SHR_ST_MAX_PORTS]; 488 uint16 num_ports; 489 490 sal_memset(&ports_delete_msg, 0, sizeof(ports_delete_msg)); 491 num_ports = telemetry_per_unit_global_info->num_ports; 492 493 sal_memcpy(lports_list, telemetry_per_unit_global_info->lports, 494 (num_ports * sizeof(uint16))); 495 /* Currently FW does not support multi instance export hence below 496 port add/delete will be operating in a single instance context */ 497 498 /*Deleting from ports list which does not present in new config */ 499 for (i= 0; i < num_ports; i++) 500 { 501 match_found = 0; 502 list_lport = lports_list[i]; 503 for (j= 0; j < config_count; j++) { 504 object_config = &(telemetry_config[j]); 505 config_lport = BCM_GPORT_LOCAL_GET(object_config->gport); 506 if (config_lport == list_lport) { 507 match_found = 1; 508 break; 509 } 510 } 511 if(match_found == 0) 512 { 513 lports_list[i] = 0; 514 telemetry_per_unit_global_info->num_ports--; 515 del_lports_list[k] = list_lport; 516 k++; 517 } 518 } 519 /*Construct the original port list without any gaps */ 520 sal_memset(telemetry_per_unit_global_info->lports, 0, 521 (num_ports * sizeof(uint16))); 522 for (i=0; i< num_ports; i++) 523 { 524 if(lports_list[i] != 0) 525 { 526 telemetry_per_unit_global_info->lports[next_pos] = 527 lports_list[i]; 528 next_pos++; 529 } 530 } 531 532 ports_delete_msg.num_ports = k; 533 sal_memcpy(ports_delete_msg.lports, 534 del_lports_list, 535 (ports_delete_msg.num_ports * sizeof(uint16))); 536 537 buffer_req = telemetry_per_unit_global_info->dma_buffer; 538 buffer_ptr = shr_st_msg_ctrl_ports_delete_pack(buffer_req, 539 &ports_delete_msg); 540 buffer_len = buffer_ptr - buffer_req; 541 542 BCM_IF_ERROR_RETURN(_bcm_xgs5_st_msg_send_receive(unit, 543 MOS_MSG_SUBCLASS_ST_PORTS_DELETE, 544 buffer_len, 0, 545 MOS_MSG_SUBCLASS_ST_PORTS_DELETE_REPLY, 546 &reply_len, 547 SHR_ST_MAX_UC_MSG_TIMEOUT)); 548 return BCM_E_NONE; 549 } 550 551 STATIC int 552 bcm_xgs5_st_eapp_port_add_msg (int unit, 553 bcm_telemetry_config_t *telemetry_config, 554 int config_count) 555 { 556 shr_st_msg_ctrl_ports_add_t ports_add_msg; 557 uint8 *buffer_req = NULL, *buffer_ptr = NULL, match_found = 0; 558 uint16 buffer_len = 0, reply_len = 0; 559 _bcm_telemetry_global_info_t *telemetry_per_unit_global_info = 560 TELEMETRY_GLOBAL_INFO_GET(unit); 561 int i,j; 562 bcm_telemetry_config_t *object_config = NULL; 563 uint16 config_lport = 0; 564 uint16 pports[SHR_ST_MAX_PORTS], mports[SHR_ST_MAX_PORTS]; 565 uint16 num_ports, phy_port = 0; 566 soc_info_t *si = &SOC_INFO(unit); 567 568 sal_memset(&ports_add_msg, 0, sizeof(ports_add_msg)); 569 num_ports = telemetry_per_unit_global_info->num_ports; 570 571 /* Currently FW does not support multi instance export hence below 572 port add/delete will be operating in a single instance context */ 573 574 /*Adding new ports to existing ports list */ 575 for (i= 0; i < config_count; i++) 576 { 577 match_found = 0; 578 object_config = &(telemetry_config[i]); 579 config_lport = BCM_GPORT_LOCAL_GET(object_config->gport); 580 for (j= 0; j < num_ports; j++) { 581 if (config_lport == telemetry_per_unit_global_info->lports[j]) { 582 match_found = 1; 583 break; 584 } 585 } 586 if(match_found == 0) 587 { 588 telemetry_per_unit_global_info->lports 589 [telemetry_per_unit_global_info->num_ports] = config_lport; 590 phy_port = si->port_l2p_mapping[config_lport]; 591 pports[telemetry_per_unit_global_info->num_ports] = phy_port; 592 mports[telemetry_per_unit_global_info->num_ports] = 593 si->port_p2m_mapping[phy_port]; 594 telemetry_per_unit_global_info->num_ports++; 595 } 596 } 597 598 ports_add_msg.num_ports = telemetry_per_unit_global_info->num_ports; 599 sal_memcpy(ports_add_msg.lports, 600 telemetry_per_unit_global_info->lports, 601 (ports_add_msg.num_ports * sizeof(uint16))); 602 sal_memcpy(ports_add_msg.pports, pports, 603 (ports_add_msg.num_ports * sizeof(uint16))); 604 sal_memcpy(ports_add_msg.mports, mports, 605 (ports_add_msg.num_ports * sizeof(uint16))); 606 607 buffer_req = telemetry_per_unit_global_info->dma_buffer; 608 buffer_ptr = shr_st_msg_ctrl_ports_add_pack(buffer_req, 609 &ports_add_msg); 610 buffer_len = buffer_ptr - buffer_req; 611 612 BCM_IF_ERROR_RETURN(_bcm_xgs5_st_msg_send_receive(unit, 613 MOS_MSG_SUBCLASS_ST_PORTS_ADD, 614 buffer_len, 0, 615 MOS_MSG_SUBCLASS_ST_PORTS_ADD_REPLY, 616 &reply_len, 617 SHR_ST_MAX_UC_MSG_TIMEOUT)); 618 return BCM_E_NONE; 619 } 620 621 STATIC int 622 _bcm_xgs5_st_eapp_collector_encap_build_pack (int unit, 623 bcm_collector_info_t *collector_info, 624 shr_st_msg_ctrl_collector_create_t *collector_create_msg) 625 { 626 uint8 *buffer = collector_create_msg->encap; 627 uint8 *cur_ptr; 628 uint16 etype = 0; 629 shr_udp_header_t udp; 630 shr_ipv4_header_t ipv4; 631 shr_l2_header_t l2; 632 uint16 ip_offset = 0; 633 uint16 udp_offset = 0; 634 635 sal_memset(&udp, 0, sizeof(udp)); 636 sal_memset(&ipv4, 0, sizeof(ipv4)); 637 sal_memset(&l2, 0, sizeof(l2)); 638 639 640 /* 641 * Get necessary headers/labels information. 642 * 643 * Following order is important since some headers/labels 644 * may depend on previous header/label information. 645 */ 646 if (collector_info->transport_type == bcmCollectorTransportTypeIpv4Udp) { 647 BCM_IF_ERROR_RETURN 648 (_bcm_xgs5_collector_udp_header_get(unit, collector_info, &udp)); 649 } 650 651 if (collector_info->transport_type == bcmCollectorTransportTypeIpv4Udp) { 652 BCM_IF_ERROR_RETURN 653 (_bcm_xgs5_collector_ip_headers_get(unit, collector_info, 654 &etype, 655 &ipv4)); 656 } 657 658 /* Always build L2 Header */ 659 BCM_IF_ERROR_RETURN 660 (_bcm_xgs5_collector_l2_header_get(unit, collector_info, etype, &l2)); 661 662 /* 663 * Pack header/labels into given buffer (network packet format). 664 * 665 * Following packing order must be followed to correctly 666 * build the packet encapsulation. 667 */ 668 cur_ptr = buffer; 669 670 /* L2 Header is always present */ 671 cur_ptr = shr_l2_header_pack(cur_ptr, &l2); 672 673 if (collector_info->transport_type == bcmCollectorTransportTypeIpv4Udp) { 674 /* 675 * IP offset 676 */ 677 ip_offset = cur_ptr - buffer; 678 679 cur_ptr = shr_ipv4_header_pack(cur_ptr, &ipv4); 680 } 681 682 if (collector_info->transport_type == bcmCollectorTransportTypeIpv4Udp) { 683 /* 684 * UDP offset 685 */ 686 udp_offset = cur_ptr - buffer; 687 cur_ptr = shr_udp_header_pack(cur_ptr, &udp); 688 } 689 690 691 /* Set export pkt encapsulation length */ 692 collector_create_msg->encap_length = cur_ptr - buffer; 693 694 /* Set export pkt IP base offset */ 695 collector_create_msg->ip_offset = ip_offset; 696 697 /* Set export pkt IP Base checksum */ 698 collector_create_msg->ip_base_checksum = 699 shr_initial_chksum_get(SHR_IPV4_HEADER_LENGTH, buffer + ip_offset); 700 701 /* Set export pkt UDP Base checksum */ 702 if (collector_info->transport_type == bcmCollectorTransportTypeIpv4Udp) { 703 collector_create_msg->udp_base_checksum = 704 shr_udp_initial_checksum_get(0, &ipv4, NULL, NULL, &udp); 705 } 706 /* Set export pkt UDP base offset */ 707 collector_create_msg->udp_offset = udp_offset; 708 709 return BCM_E_NONE; 710 } 711 712 STATIC int 713 bcm_xgs5_st_eapp_collector_create_msg (int unit, 714 bcm_collector_t collector_id, int export_profile_id) 715 { 716 shr_st_msg_ctrl_collector_create_t collector_create_msg; 717 bcm_collector_info_t collector_info; 718 bcm_collector_export_profile_t export_profile_info; 719 uint8 *buffer_req = NULL, *buffer_ptr = NULL; 720 uint16 buffer_len = 0, reply_len = 0; 721 _bcm_telemetry_global_info_t *telemetry_per_unit_global_info = 722 TELEMETRY_GLOBAL_INFO_GET(unit); 723 int rv = BCM_E_NONE; 724 725 sal_memset(&collector_info, 0, sizeof(collector_info)); 726 /* Get the collector info for this collector id */ 727 rv = bcm_esw_collector_get(unit, collector_id, &collector_info); 728 729 /* Return BCM_E_NOT_FOUND if not found */ 730 if (BCM_FAILURE(rv)) { 731 return rv; 732 } 733 /* Get the export profile info for this profile id */ 734 rv = bcm_esw_collector_export_profile_get(unit, export_profile_id, 735 &export_profile_info); 736 737 /* Return BCM_E_NOT_FOUND if not found */ 738 if (BCM_FAILURE(rv)) { 739 return rv; 740 } 741 if (export_profile_info.export_interval != _SHR_ST_EXPORT_INTERVAL_USECS) { 742 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 743 (BSL_META_U(unit, 744 "TELEMETRY(unit %d) Error: Invalid export_interval=%u\n"), 745 unit, export_profile_info.export_interval)); 746 return BCM_E_PARAM; 747 } 748 749 if (collector_info.transport_type != bcmCollectorTransportTypeIpv4Udp) 750 { 751 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 752 (BSL_META_U(unit, 753 "TELEMETRY(unit %d) Error: unsupported Transport type\n"), 754 unit)); 755 return BCM_E_PARAM; 756 } 757 758 sal_memset(&collector_create_msg, 0, sizeof(collector_create_msg)); 759 /*Implement multiple collector when it really being supported by BTE */ 760 collector_create_msg.id = 0; 761 762 if (export_profile_info.flags & 763 BCM_COLLECTOR_EXPORT_PROFILE_FLAGS_USE_NUM_RECORDS) { 764 collector_create_msg.num_port_in_pkt = export_profile_info.num_records; 765 } else { 766 collector_create_msg.mtu = export_profile_info.max_packet_length; 767 } 768 if (collector_info.udp.flags & BCM_COLLECTOR_UDP_FLAGS_CHECKSUM_ENABLE) { 769 collector_create_msg.flags |= SHR_ST_MSG_CTRL_COLLECTOR_FLAGS_UDP_CHECKSUM; 770 } 771 772 rv = _bcm_xgs5_st_eapp_collector_encap_build_pack(unit, 773 &collector_info, 774 &collector_create_msg); 775 if (BCM_FAILURE(rv)) { 776 return rv; 777 } 778 779 if (!(export_profile_info.flags & 780 BCM_COLLECTOR_EXPORT_PROFILE_FLAGS_USE_NUM_RECORDS)) { 781 if ((export_profile_info.max_packet_length > 782 telemetry_per_unit_global_info->max_pkt_size) || 783 (export_profile_info.max_packet_length < 784 (collector_create_msg.encap_length + SHR_L2_CRC_LENGTH))) { 785 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 786 (BSL_META_U(unit, 787 "TELEMETRY(unit %d) Error: Invalid max_packet_length=%u\n"), 788 unit, export_profile_info.max_packet_length)); 789 return BCM_E_PARAM; 790 } 791 } 792 793 buffer_req = telemetry_per_unit_global_info->dma_buffer; 794 buffer_ptr = shr_st_msg_ctrl_collector_create_pack(buffer_req, 795 &collector_create_msg); 796 buffer_len = buffer_ptr - buffer_req; 797 798 BCM_IF_ERROR_RETURN(_bcm_xgs5_st_msg_send_receive(unit, 799 MOS_MSG_SUBCLASS_ST_COLLECTOR_CREATE, 800 buffer_len, 0, 801 MOS_MSG_SUBCLASS_ST_COLLECTOR_CREATE_REPLY, 802 &reply_len, 803 SHR_ST_MAX_UC_MSG_TIMEOUT)); 804 return BCM_E_NONE; 805 } 806 807 STATIC int 808 bcm_xgs5_st_eapp_collector_delete_msg (int unit, 809 int int_collector_id) 810 { 811 uint16 reply_len = 0; 812 813 814 BCM_IF_ERROR_RETURN(_bcm_xgs5_st_msg_send_receive(unit, 815 MOS_MSG_SUBCLASS_ST_COLLECTOR_DELETE, 816 int_collector_id, 0, 817 MOS_MSG_SUBCLASS_ST_COLLECTOR_DELETE_REPLY, 818 &reply_len, 819 SHR_ST_MAX_UC_MSG_TIMEOUT)); 820 return BCM_E_NONE; 821 822 } 823 824 STATIC int 825 bcm_xgs5_st_eapp_collector_attach_msg (int unit, int instance_id, 826 uint32 export_interval) 827 { 828 shr_st_msg_ctrl_instance_collector_attach_t collector_attach_msg; 829 uint8 *buffer_req = NULL, *buffer_ptr = NULL; 830 uint16 buffer_len = 0, reply_len = 0; 831 _bcm_telemetry_global_info_t *telemetry_per_unit_global_info = 832 TELEMETRY_GLOBAL_INFO_GET(unit); 833 834 sal_memset(&collector_attach_msg, 0, sizeof(collector_attach_msg)); 835 /*Implement multiple collector when it really being supported by BTE */ 836 collector_attach_msg.instance_id = instance_id; 837 collector_attach_msg.export_interval_usecs = export_interval; 838 collector_attach_msg.collector_id = 0; 839 840 buffer_req = telemetry_per_unit_global_info->dma_buffer; 841 buffer_ptr = shr_st_msg_ctrl_instance_collector_attach_pack(buffer_req, 842 &collector_attach_msg); 843 buffer_len = buffer_ptr - buffer_req; 844 845 BCM_IF_ERROR_RETURN(_bcm_xgs5_st_msg_send_receive(unit, 846 MOS_MSG_SUBCLASS_ST_INSTANCE_COLLECTOR_ATTACH, 847 buffer_len, 0, 848 MOS_MSG_SUBCLASS_ST_INSTANCE_COLLECTOR_ATTACH_REPLY, 849 &reply_len, 850 SHR_ST_MAX_UC_MSG_TIMEOUT)); 851 return BCM_E_NONE; 852 } 853 854 STATIC int 855 bcm_xgs5_st_eapp_collector_detach_msg (int unit, 856 int instance_id) 857 { 858 uint16 reply_len = 0; 859 860 BCM_IF_ERROR_RETURN(_bcm_xgs5_st_msg_send_receive(unit, 861 MOS_MSG_SUBCLASS_ST_INSTANCE_COLLECTOR_DETACH, 862 instance_id, 0, 863 MOS_MSG_SUBCLASS_ST_INSTANCE_COLLECTOR_DETACH_REPLY, 864 &reply_len, 865 SHR_ST_MAX_UC_MSG_TIMEOUT)); 866 return BCM_E_NONE; 867 } 868 869 STATIC 870 int _bcm_xgs5_st_eapp_system_id_set_msg(int unit) 871 { 872 shr_st_msg_system_id_t system_id_set_msg; 873 uint8 *buffer_req = NULL, *buffer_ptr = NULL; 874 uint16 buffer_len = 0, reply_len = 0; 875 _bcm_telemetry_global_info_t *telemetry_config_per_unit = 876 TELEMETRY_GLOBAL_INFO_GET(unit); 877 878 879 sal_memset(&system_id_set_msg, 0, sizeof(system_id_set_msg)); 880 system_id_set_msg.system_id_length = 881 telemetry_config_per_unit->system_id_length; 882 sal_memcpy(system_id_set_msg.system_id, 883 telemetry_config_per_unit->system_id, 884 (system_id_set_msg.system_id_length * sizeof(uint8))); 885 886 buffer_req = telemetry_config_per_unit->dma_buffer; 887 buffer_ptr = shr_st_msg_system_id_pack(buffer_req, 888 &system_id_set_msg); 889 buffer_len = buffer_ptr - buffer_req; 890 891 BCM_IF_ERROR_RETURN(_bcm_xgs5_st_msg_send_receive(unit, 892 MOS_MSG_SUBCLASS_ST_SYSTEM_ID_SET, 893 buffer_len, 0, 894 MOS_MSG_SUBCLASS_ST_SYSTEM_ID_SET_REPLY, 895 &reply_len, 896 SHR_ST_MAX_UC_MSG_TIMEOUT)); 897 return BCM_E_NONE; 898 } 899 900 STATIC 901 int _bcm_xgs5_st_eapp_system_id_get_msg(int unit) 902 { 903 shr_st_msg_system_id_t system_id_get_msg; 904 uint8 *buffer_req = NULL, *buffer_ptr = NULL; 905 uint16 buffer_len = 0, reply_len = 0; 906 _bcm_telemetry_global_info_t *telemetry_per_unit_global_info = 907 TELEMETRY_GLOBAL_INFO_GET(unit); 908 909 sal_memset(&system_id_get_msg, 0, sizeof(system_id_get_msg)); 910 911 BCM_IF_ERROR_RETURN(_bcm_xgs5_st_msg_send_receive(unit, 912 MOS_MSG_SUBCLASS_ST_SYSTEM_ID_GET, 913 0, 0, 914 MOS_MSG_SUBCLASS_ST_SYSTEM_ID_GET_REPLY, 915 &reply_len, 916 SHR_ST_MAX_UC_MSG_TIMEOUT)); 917 918 buffer_req = telemetry_per_unit_global_info->dma_buffer; 919 buffer_ptr = shr_st_msg_system_id_unpack(buffer_req, 920 &system_id_get_msg); 921 buffer_len = buffer_ptr - buffer_req; 922 923 if (reply_len != buffer_len) { 924 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 925 (BSL_META_U(unit, 926 "TELEMETRY(unit %d) Error: System ID " 927 " get failed from BTE\n"), unit)); 928 return BCM_E_INTERNAL; 929 } 930 931 telemetry_per_unit_global_info->system_id_length = 932 system_id_get_msg.system_id_length; 933 sal_memcpy(telemetry_per_unit_global_info->system_id, 934 system_id_get_msg.system_id, 935 (telemetry_per_unit_global_info->system_id_length * sizeof(uint8))); 936 937 return BCM_E_NONE; 938 } 939 940 /* 941 * Function: 942 * _bcm_xgs5_st_eapp_instance_export_stats_get_msg 943 * Purpose: 944 * Send the Instance export statistics get message to EApp 945 * Parameters: 946 * unit - (IN) BCM device number 947 * stats - (OUT) Export statistics. 948 * Returns: 949 * BCM_E_XXX - BCM error code. 950 */ 951 STATIC int 952 _bcm_xgs5_st_eapp_instance_export_stats_get_msg( 953 int unit, 954 bcm_telemetry_instance_export_stats_t *stats) 955 { 956 shr_st_msg_instance_export_stats_t msg; 957 uint8 *buffer_req = NULL, *buffer_ptr = NULL; 958 uint16 buffer_len = 0, reply_len = 0; 959 _bcm_telemetry_global_info_t *telemetry_per_unit_global_info = 960 TELEMETRY_GLOBAL_INFO_GET(unit); 961 962 sal_memset(&msg, 0, sizeof(msg)); 963 964 BCM_IF_ERROR_RETURN( 965 _bcm_xgs5_st_msg_send_receive( 966 unit, 967 MOS_MSG_SUBCLASS_ST_INSTANCE_EXPORT_STATS_GET, 968 0, 0, 969 MOS_MSG_SUBCLASS_ST_INSTANCE_EXPORT_STATS_GET_REPLY, 970 &reply_len, 971 SHR_ST_MAX_UC_MSG_TIMEOUT)); 972 973 buffer_req = telemetry_per_unit_global_info->dma_buffer; 974 buffer_ptr = shr_st_msg_instance_export_stats_unpack(buffer_req, &msg); 975 buffer_len = buffer_ptr - buffer_req; 976 977 if (reply_len != buffer_len) { 978 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 979 (BSL_META_U(unit, 980 "TELEMETRY(unit %d) Error: Instance export stats " 981 " get failed from BTE\n"), unit)); 982 return BCM_E_INTERNAL; 983 } 984 985 COMPILER_64_SET(stats->tx_pkts, msg.tx_pkts_hi, msg.tx_pkts_lo); 986 COMPILER_64_SET(stats->tx_pkt_fails, msg.tx_pkt_fails_hi, msg.tx_pkt_fails_lo); 987 988 return BCM_E_NONE; 989 } 990 991 /* 992 * Function: 993 * _bcm_xgs5_st_eapp_instance_export_stats_set_msg 994 * Purpose: 995 * Send the Instance export statistics set message to EApp 996 * Parameters: 997 * unit - (IN) BCM device number 998 * stats - (IN) Export statistics. 999 * Returns: 1000 * BCM_E_XXX - BCM error code. 1001 */ 1002 STATIC int 1003 _bcm_xgs5_st_eapp_instance_export_stats_set_msg( 1004 int unit, 1005 bcm_telemetry_instance_export_stats_t *stats) 1006 { 1007 shr_st_msg_instance_export_stats_t msg; 1008 uint8 *buffer_req = NULL, *buffer_ptr = NULL; 1009 uint16 buffer_len = 0, reply_len = 0; 1010 _bcm_telemetry_global_info_t *telemetry_per_unit_global_info = 1011 TELEMETRY_GLOBAL_INFO_GET(unit); 1012 1013 sal_memset(&msg, 0, sizeof(msg)); 1014 1015 msg.tx_pkts_hi = COMPILER_64_HI(stats->tx_pkts); 1016 msg.tx_pkts_lo = COMPILER_64_LO(stats->tx_pkts); 1017 1018 msg.tx_pkt_fails_hi = COMPILER_64_HI(stats->tx_pkt_fails); 1019 msg.tx_pkt_fails_lo = COMPILER_64_LO(stats->tx_pkt_fails); 1020 1021 buffer_req = telemetry_per_unit_global_info->dma_buffer; 1022 buffer_ptr = shr_st_msg_instance_export_stats_pack(buffer_req, &msg); 1023 buffer_len = buffer_ptr - buffer_req; 1024 1025 BCM_IF_ERROR_RETURN( 1026 _bcm_xgs5_st_msg_send_receive( 1027 unit, 1028 MOS_MSG_SUBCLASS_ST_INSTANCE_EXPORT_STATS_SET, 1029 buffer_len, 0, 1030 MOS_MSG_SUBCLASS_ST_INSTANCE_EXPORT_STATS_SET_REPLY, 1031 &reply_len, 1032 SHR_ST_MAX_UC_MSG_TIMEOUT)); 1033 1034 1035 return BCM_E_NONE; 1036 } 1037 1038 /****************************************************** 1039 * * 1040 * TELEMETRY INSTANCE LIST MANAGEMENT FUNCTIONS * 1041 */ 1042 1043 /* 1044 * Function: 1045 * _bcm_xgs5_telemetry_system_id_set 1046 * Purpose: 1047 * Configures Telemetry system ID information. 1048 * Parameters: 1049 * unit - (IN) BCM device number 1050 * system_id_len - (IN) length of telemetry system ID 1051 * system_id - (IN) System ID value 1052 * Returns: 1053 * BCM_E_XXX - BCM error code. 1054 */ 1055 int _bcm_xgs5_telemetry_system_id_set( 1056 int unit, int system_id_len, 1057 uint8 *system_id) 1058 { 1059 int rv = BCM_E_NONE; 1060 _bcm_telemetry_global_info_t *telemetry_config_per_unit = 1061 TELEMETRY_GLOBAL_INFO_GET(unit); 1062 _bcm_telemetry_instance_info_t *telemetry_instance_list_node = NULL; 1063 1064 if (telemetry_config_per_unit == NULL) { 1065 return BCM_E_INIT; 1066 } 1067 1068 if ((telemetry_config_per_unit->system_id_length != 0) && 1069 (system_id_len == 0)) 1070 { 1071 /*Check whether instance has valid config count 1072 * if so reject system ID reset 1073 */ 1074 telemetry_instance_list_node = 1075 &(telemetry_instances_info_list[unit][0]); 1076 1077 if (telemetry_instance_list_node && 1078 (telemetry_instance_list_node->config_count != 1079 BCM_TELEMETRY_INVALID_VALUE)) 1080 { 1081 1082 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1083 (BSL_META_U(unit, 1084 "TELEMETRY(unit %d) Error: Telemetry System ID " 1085 " cannot be reset with telemetry config exist \n"), unit)); 1086 } 1087 } 1088 1089 if ((system_id_len < 0) || 1090 (system_id_len > BCM_TELEMETRY_MAX_SYSTEM_ID_LENGTH)) { 1091 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1092 (BSL_META_U(unit, 1093 "TELEMETRY(unit %d) Error: Invalid " 1094 " System ID length \n"), unit)); 1095 return BCM_E_PARAM; 1096 } 1097 1098 if (system_id == NULL) { 1099 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1100 (BSL_META_U(unit, 1101 "TELEMETRY(unit %d) Error: Missing " 1102 " System ID value\n"), unit)); 1103 return BCM_E_PARAM; 1104 } 1105 1106 if ((system_id_len == 0) && 1107 (telemetry_config_per_unit->system_id_length == 0)) { 1108 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1109 (BSL_META_U(unit, 1110 "TELEMETRY(unit %d) Error: " 1111 " System ID length cnnot be zero\n"), unit)); 1112 return BCM_E_PARAM; 1113 } 1114 1115 if ((system_id_len == 0) && 1116 (telemetry_config_per_unit->system_id_length != 0)) { 1117 1118 sal_memset(telemetry_config_per_unit->system_id, 0, 1119 (telemetry_config_per_unit->system_id_length * sizeof(uint8))); 1120 } else { 1121 sal_memcpy(telemetry_config_per_unit->system_id, system_id, 1122 (system_id_len * sizeof(uint8))); 1123 } 1124 1125 telemetry_config_per_unit->system_id_length = system_id_len; 1126 1127 rv = _bcm_xgs5_st_eapp_system_id_set_msg(unit); 1128 if (BCM_FAILURE(rv)) { 1129 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1130 (BSL_META_U(unit, 1131 "TELEMETRY(unit %d) Error: system ID " 1132 " set failed to BTE %s\n"), unit, bcm_errmsg(rv))); 1133 return rv; 1134 } 1135 1136 return BCM_E_NONE; 1137 } 1138 1139 /* 1140 * Function: 1141 * _bcm_xgs5_telemetry_system_id_get 1142 * Purpose: 1143 * Fetches Telemetry system ID information. 1144 * Parameters: 1145 * unit - (IN) BCM device number 1146 * max_system_id_len - (IN) Max length of telemetry system ID 1147 * system_id_len - (IN) System ID configured length 1148 * system_id - (IN) System ID value 1149 * Returns: 1150 * BCM_E_XXX - BCM error code. 1151 */ 1152 int _bcm_xgs5_telemetry_system_id_get( 1153 int unit, int max_system_id_len, 1154 int *system_id_len, 1155 uint8 *system_id) 1156 { 1157 _bcm_telemetry_global_info_t *telemetry_config_per_unit = 1158 TELEMETRY_GLOBAL_INFO_GET(unit); 1159 1160 if (telemetry_config_per_unit == NULL) { 1161 return BCM_E_INIT; 1162 } 1163 1164 if (system_id_len == NULL) { 1165 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1166 (BSL_META_U(unit, 1167 "TELEMETRY(unit %d) Error: NULL " 1168 " System ID length passed \n"), unit)); 1169 return BCM_E_PARAM; 1170 } 1171 1172 1173 if(max_system_id_len == 0) 1174 { 1175 *system_id_len = telemetry_config_per_unit->system_id_length; 1176 return BCM_E_NONE; 1177 } 1178 1179 if (max_system_id_len < (int)telemetry_config_per_unit->system_id_length) 1180 { 1181 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1182 (BSL_META_U(unit, 1183 "TELEMETRY(unit %d) Error: Invalid max system ID " 1184 " length passed \n"), unit)); 1185 return BCM_E_PARAM; 1186 } 1187 1188 if (system_id == NULL) { 1189 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1190 (BSL_META_U(unit, 1191 "TELEMETRY(unit %d) Error: NULL " 1192 " System ID passed \n"), unit)); 1193 return BCM_E_PARAM; 1194 } 1195 1196 sal_memset(system_id, 0, (max_system_id_len * sizeof(uint8))); 1197 *system_id_len = telemetry_config_per_unit->system_id_length; 1198 sal_memcpy(system_id, telemetry_config_per_unit->system_id, 1199 (telemetry_config_per_unit->system_id_length * sizeof(uint8))); 1200 1201 return BCM_E_NONE; 1202 } 1203 1204 /* 1205 * Function: 1206 * _bcm_xgs5_telemetry_instance_config_update 1207 * Purpose: 1208 * Updates a telemetry instance config information. 1209 * Parameters: 1210 * unit - (IN) BCM device number 1211 * telemetry_instance_id - (IN) The telemetry instance ID 1212 * core - (IN) FW core on which instance have to run 1213 * config_count - (IN) Number of telemetry objects to be 1214 * associated with this instance. 1215 * telemetry_config - (IN) Telemetry instance configuration. 1216 * Returns: 1217 * BCM_E_XXX 1218 */ 1219 int 1220 _bcm_xgs5_telemetry_instance_config_update(int unit, 1221 int telemetry_instance_id, 1222 int core, 1223 int config_count, 1224 bcm_telemetry_config_t *telemetry_config) 1225 { 1226 int index = BCM_TELEMETRY_INVALID_INDEX; 1227 int cur_instance_index = BCM_TELEMETRY_INVALID_INDEX, rv = BCM_E_NONE; 1228 int first_free_index = BCM_TELEMETRY_INVALID_INDEX; 1229 _bcm_telemetry_instance_info_t *telemetry_instance_list_node = NULL; 1230 _bcm_telemetry_global_info_t *telemetry_per_unit_global_info = 1231 TELEMETRY_GLOBAL_INFO_GET(unit); 1232 int i; 1233 bcm_port_t port; 1234 bcm_gport_t gport; 1235 1236 if (telemetry_per_unit_global_info == NULL) { 1237 return BCM_E_INIT; 1238 } 1239 1240 if (config_count < 0) 1241 { 1242 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1243 (BSL_META_U(unit, 1244 "TELEMETRY(unit %d) Error: Invalid " 1245 " configuration count passed\n"), unit)); 1246 return BCM_E_PARAM; 1247 } 1248 1249 if ((config_count != 0) && 1250 (telemetry_per_unit_global_info->system_id_length == 0)) 1251 { 1252 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1253 (BSL_META_U(unit, 1254 "TELEMETRY(unit %d) Error: System ID " 1255 " was not configured\n"), unit)); 1256 return BCM_E_CONFIG; 1257 } 1258 1259 if (core != telemetry_per_unit_global_info->uC) 1260 { 1261 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1262 (BSL_META_U(unit, 1263 "TELEMETRY(unit %d) Error: Only core %u is allowed to " 1264 " configure for Telemetry instances\n"), unit, 1265 telemetry_per_unit_global_info->uC)); 1266 return BCM_E_PARAM; 1267 } 1268 1269 for (i = 0; i < config_count; i++) { 1270 gport = telemetry_config[i].gport; 1271 if (!BCM_GPORT_IS_LOCAL(gport)) { 1272 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1273 (BSL_META_U(unit, 1274 "TELEMETRY(unit %d) Error: only local " 1275 " type gport add is supported \n"), unit)); 1276 return BCM_E_CONFIG; 1277 } 1278 port = BCM_GPORT_LOCAL_GET(gport); 1279 if (!(IS_E_PORT(unit, port)) || (IS_MANAGEMENT_PORT(unit, port))) { 1280 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1281 (BSL_META_U(unit, 1282 "TELEMETRY(unit %d) Error: Invalid port=%d\n"), 1283 unit, port)); 1284 return BCM_E_PARAM; 1285 } 1286 } 1287 1288 rv = _bcm_xgs5_telemetry_is_instance_exists(unit, telemetry_instance_id, 1289 &cur_instance_index, &first_free_index); 1290 if(rv == BCM_E_NOT_FOUND) 1291 { 1292 if (first_free_index == BCM_TELEMETRY_INVALID_INDEX) 1293 { 1294 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1295 (BSL_META_U(unit, 1296 "TELEMETRY(unit %d) Error: Not allowed to " 1297 "configure more than supported %d telemetry instances\n"), 1298 unit, BCM_INT_TELEMETRY_MAX_INSTANCES)); 1299 return BCM_E_RESOURCE; 1300 } 1301 index = first_free_index; 1302 if (config_count) { 1303 telemetry_per_unit_global_info->num_telemetry_instances++; 1304 } 1305 rv = BCM_E_NONE; 1306 } else { 1307 index = cur_instance_index; 1308 if (!config_count) { 1309 telemetry_per_unit_global_info->num_telemetry_instances--; 1310 } 1311 } 1312 1313 telemetry_instance_list_node = 1314 &(telemetry_instances_info_list[unit][index]); 1315 1316 if (telemetry_instance_list_node->config_count != 1317 BCM_TELEMETRY_INVALID_VALUE) 1318 { 1319 rv = bcm_xgs5_st_eapp_port_delete_msg(unit, 1320 telemetry_config, 1321 config_count); 1322 if (BCM_FAILURE(rv)) { 1323 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1324 (BSL_META_U(unit, 1325 "TELEMETRY(unit %d) Error: port " 1326 " delete failed to BTE %s\n"), unit, bcm_errmsg(rv))); 1327 return rv; 1328 } 1329 if (config_count == 0) 1330 { 1331 rv = bcm_xgs5_st_eapp_instance_delete_msg(unit, 1332 telemetry_instance_list_node->instance_id); 1333 if (BCM_FAILURE(rv)) { 1334 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1335 (BSL_META_U(unit, 1336 "TELEMETRY(unit %d) Error: Instance " 1337 " delete failed to BTE %s\n"), unit, bcm_errmsg(rv))); 1338 return rv; 1339 } 1340 } 1341 sal_free(telemetry_instance_list_node->telemetry_config); 1342 telemetry_instance_list_node->telemetry_config = NULL; 1343 telemetry_instance_list_node->config_count = 1344 BCM_TELEMETRY_INVALID_VALUE; 1345 telemetry_instance_list_node->instance_id = BCM_TELEMETRY_INVALID_INDEX; 1346 1347 } 1348 1349 if (config_count) { 1350 _BCM_TELEMETRY_ALLOC(telemetry_instance_list_node->telemetry_config, 1351 bcm_telemetry_config_t, 1352 (config_count * sizeof(bcm_telemetry_config_t)), 1353 "TELEMETRY_CONFIG_INFO"); 1354 sal_memcpy(telemetry_instance_list_node->telemetry_config, 1355 telemetry_config, 1356 (config_count *sizeof(bcm_telemetry_config_t))); 1357 telemetry_instance_list_node->config_count = config_count; 1358 telemetry_instance_list_node->instance_id = telemetry_instance_id; 1359 telemetry_instance_list_node->core = core; 1360 rv = bcm_xgs5_st_eapp_port_add_msg(unit, 1361 telemetry_instance_list_node->telemetry_config, 1362 telemetry_instance_list_node->config_count); 1363 if (BCM_FAILURE(rv)) { 1364 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1365 (BSL_META_U(unit, 1366 "TELEMETRY(unit %d) Error: port " 1367 " add failed to BTE %s\n"), unit, bcm_errmsg(rv))); 1368 return rv; 1369 } 1370 rv = bcm_xgs5_st_eapp_instance_create_msg(unit, 1371 telemetry_instance_list_node->instance_id, 1372 telemetry_instance_list_node->telemetry_config, 1373 telemetry_instance_list_node->config_count); 1374 if (BCM_FAILURE(rv)) { 1375 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1376 (BSL_META_U(unit, 1377 "TELEMETRY(unit %d) Error: Instance " 1378 " add failed to BTE %s\n"), unit, bcm_errmsg(rv))); 1379 return rv; 1380 } 1381 } 1382 LOG_DEBUG(BSL_LS_BCM_TELEMETRY, 1383 (BSL_META_U(unit, 1384 "TELEMETRY(unit %d) Config Info update: %s" 1385 " (Telemetry instance=0x%x).\n"), unit, __FUNCTION__, 1386 telemetry_instance_id)); 1387 return rv; 1388 } 1389 1390 /* 1391 * Function: 1392 * _bcm_xgs5_telemetry_instance_config_get 1393 * Purpose: 1394 * Updates a telemetry instance config information. 1395 * Parameters: 1396 * unit - (IN) BCM device number 1397 * telemetry_instance_id - (IN) The telemetry instance ID 1398 * core - (IN) FW Core on which instance is being run 1399 * max_count - (IN) Max objects requested 1400 * telemetry_config - (OUT) Telemetry instance configuration. 1401 * config_count - (OUT) Number of telemetry objects to be 1402 * associated with this instance. 1403 * Returns: 1404 * BCM_E_XXX 1405 */ 1406 int 1407 _bcm_xgs5_telemetry_instance_config_get(int unit, 1408 int telemetry_instance_id, 1409 int core, 1410 int max_count, 1411 bcm_telemetry_config_t *telemetry_config, 1412 int *config_count) 1413 { 1414 int first_free_index = 0, cur_instance_index = 0, rv = BCM_E_NONE; 1415 _bcm_telemetry_instance_info_t *telemetry_instance_list_node = NULL; 1416 _bcm_telemetry_global_info_t *telemetry_per_unit_global_info = 1417 TELEMETRY_GLOBAL_INFO_GET(unit); 1418 1419 if (telemetry_per_unit_global_info == NULL) { 1420 return BCM_E_INIT; 1421 } 1422 rv = _bcm_xgs5_telemetry_is_instance_exists(unit, telemetry_instance_id, 1423 &cur_instance_index, &first_free_index); 1424 1425 /* If not found, return BCM_E_NOT_FOUND */ 1426 if (BCM_FAILURE(rv)) { 1427 return rv; 1428 } 1429 telemetry_instance_list_node = 1430 &(telemetry_instances_info_list[unit][cur_instance_index]); 1431 *config_count = telemetry_instance_list_node->config_count; 1432 if (max_count < *config_count) 1433 { 1434 *config_count = max_count; 1435 } 1436 if (max_count == 0) 1437 { 1438 *config_count = telemetry_instance_list_node->config_count; 1439 return rv; 1440 } 1441 if (telemetry_config != NULL) 1442 { 1443 sal_memcpy(telemetry_config, 1444 telemetry_instance_list_node->telemetry_config, 1445 ((*config_count) *sizeof(bcm_telemetry_config_t))); 1446 } 1447 LOG_DEBUG(BSL_LS_BCM_TELEMETRY, 1448 (BSL_META_U(unit, 1449 "TELEMETRY(unit %d) Config Info get: %s" 1450 " (Telemetry instance=0x%x).\n"), unit, __FUNCTION__, 1451 telemetry_instance_id)); 1452 return rv; 1453 } 1454 1455 /* 1456 * Function: 1457 * _bcm_xgs5_telemetry_instance_export_config_update 1458 * Purpose: 1459 * Updates a telemetry instance export config information. 1460 * Parameters: 1461 * unit - (IN) BCM device number 1462 * telemetry_instance_id - (IN) The telemetry instance ID 1463 * collector_id - (IN) Collector ID 1464 * export_profile_id - (IN) Export profile ID 1465 * Returns: 1466 * BCM_E_XXX 1467 */ 1468 int 1469 _bcm_xgs5_telemetry_instance_export_config_update(int unit, 1470 int telemetry_instance_id, 1471 bcm_collector_t collector_id, 1472 int export_profile_id) 1473 { 1474 int first_free_index = 0, cur_instance_index = 0, rv = BCM_E_NONE; 1475 _bcm_telemetry_instance_info_t *telemetry_instance_list_node = NULL; 1476 bcm_collector_info_t collector_info; 1477 bcm_collector_export_profile_t profile_info; 1478 _bcm_telemetry_global_info_t *telemetry_per_unit_global_info = 1479 TELEMETRY_GLOBAL_INFO_GET(unit); 1480 1481 if (telemetry_per_unit_global_info == NULL) { 1482 return BCM_E_INIT; 1483 } 1484 rv = _bcm_xgs5_telemetry_is_instance_exists(unit, telemetry_instance_id, 1485 &cur_instance_index, &first_free_index); 1486 1487 /* If not found, return BCM_E_NOT_FOUND */ 1488 if (BCM_FAILURE(rv)) { 1489 return rv; 1490 } 1491 1492 telemetry_instance_list_node = 1493 &(telemetry_instances_info_list[unit][cur_instance_index]); 1494 1495 if(collector_id != BCM_TELEMETRY_INVALID_VALUE) 1496 { 1497 rv = bcm_esw_collector_get(unit, collector_id, &collector_info); 1498 1499 /* If not found, return BCM_E_NOT_FOUND */ 1500 if (BCM_FAILURE(rv)) { 1501 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1502 (BSL_META_U(unit, 1503 "TELEMETRY(unit %d) Error: Invalid " 1504 " collector ID passed\n"), unit)); 1505 return rv; 1506 } 1507 1508 rv = bcm_esw_collector_export_profile_get(unit, export_profile_id, 1509 &profile_info); 1510 1511 /* If not found, return BCM_E_NOT_FOUND */ 1512 if (BCM_FAILURE(rv)) { 1513 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1514 (BSL_META_U(unit, 1515 "TELEMETRY(unit %d) Error: Invalid " 1516 " export profile ID passed\n"), unit)); 1517 return rv; 1518 } 1519 1520 if (profile_info.wire_format != bcmCollectorWireFormatProtoBuf) { 1521 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1522 (BSL_META_U(unit, 1523 "TELEMETRY(unit %d) Error: Invalid " 1524 " export profile wire format\n"), unit)); 1525 return BCM_E_PARAM; 1526 } 1527 1528 if ((telemetry_instance_list_node->collector_id != 1529 BCM_TELEMETRY_INVALID_VALUE) && 1530 (telemetry_instance_list_node->collector_id != collector_id)) 1531 { 1532 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1533 (BSL_META_U(unit, 1534 "TELEMETRY(unit %d) Error: Only " 1535 " one collector is supported\n"), unit)); 1536 return BCM_E_CONFIG; 1537 } 1538 if ((telemetry_instance_list_node->export_profile_id != 1539 BCM_TELEMETRY_INVALID_VALUE) && 1540 (telemetry_instance_list_node->export_profile_id != 1541 export_profile_id)) 1542 { 1543 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1544 (BSL_META_U(unit, 1545 "TELEMETRY(unit %d) Error: Only " 1546 " one collector is supported\n"), unit)); 1547 return BCM_E_CONFIG; 1548 } 1549 /* 1550 * Check if I am the only user for this collector. Else 1551 * return error. 1552 */ 1553 if (_bcm_esw_collector_check_user_is_other(unit, collector_id, 1554 _BCM_COLLECTOR_EXPORT_APP_ST_PROTOBUF)) { 1555 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1556 (BSL_META_U(unit, 1557 "TELEMETRY(unit %d) Error: Collector " 1558 " is already attached to another application\n"), unit)); 1559 return BCM_E_CONFIG; 1560 } 1561 } 1562 1563 if (telemetry_instance_list_node->collector_id == 1564 BCM_TELEMETRY_INVALID_VALUE) 1565 { 1566 1567 rv = bcm_xgs5_st_eapp_collector_create_msg(unit, collector_id, 1568 export_profile_id); 1569 if (BCM_FAILURE(rv)) { 1570 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1571 (BSL_META_U(unit, 1572 "TELEMETRY(unit %d) Error: collector " 1573 " add failed to BTE %s\n"), unit, bcm_errmsg(rv))); 1574 return rv; 1575 } 1576 rv = bcm_xgs5_st_eapp_collector_attach_msg(unit, 1577 telemetry_instance_id, 1578 profile_info.export_interval); 1579 if (BCM_FAILURE(rv)) { 1580 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1581 (BSL_META_U(unit, 1582 "TELEMETRY(unit %d) Error: collector " 1583 " attach failed to BTE %s\n"), unit, bcm_errmsg(rv))); 1584 return rv; 1585 } 1586 telemetry_instance_list_node->num_collectors++; 1587 1588 rv = _bcm_esw_collector_ref_count_update(unit, collector_id, 1); 1589 if (BCM_FAILURE(rv)) { 1590 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1591 (BSL_META_U(unit, 1592 "TELEMETRY(unit %d) Error: collector " 1593 " ref_count update failed %s\n"), unit, bcm_errmsg(rv))); 1594 return rv; 1595 } 1596 rv = _bcm_esw_collector_user_update(unit, collector_id, _BCM_COLLECTOR_EXPORT_APP_ST_PROTOBUF); 1597 if (BCM_FAILURE(rv)) { 1598 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1599 (BSL_META_U(unit, 1600 "TELEMETRY(unit %d) Error: collector " 1601 " user update failed %s\n"), unit, bcm_errmsg(rv))); 1602 return rv; 1603 } 1604 rv = _bcm_esw_collector_export_profile_ref_count_update(unit, 1605 export_profile_id, 1606 1); 1607 if (BCM_FAILURE(rv)) { 1608 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1609 (BSL_META_U(unit, 1610 "TELEMETRY(unit %d) Error: export profile " 1611 " ref_count update failed %s\n"), unit, bcm_errmsg(rv))); 1612 return rv; 1613 } 1614 1615 } else if (collector_id == BCM_TELEMETRY_INVALID_VALUE){ 1616 rv = bcm_xgs5_st_eapp_collector_detach_msg(unit, 1617 telemetry_instance_id); 1618 if (BCM_FAILURE(rv)) { 1619 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1620 (BSL_META_U(unit, 1621 "TELEMETRY(unit %d) Error: collector " 1622 " detach failed to BTE %s\n"), unit, bcm_errmsg(rv))); 1623 return rv; 1624 } 1625 /* Hard code BTE internal collector id to zero as of now as 1626 only one collector supported*/ 1627 rv = bcm_xgs5_st_eapp_collector_delete_msg(unit, 0); 1628 if (BCM_FAILURE(rv)) { 1629 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1630 (BSL_META_U(unit, 1631 "TELEMETRY(unit %d) Error: collector " 1632 " delete failed to BTE %s\n"), unit, bcm_errmsg(rv))); 1633 return rv; 1634 } 1635 telemetry_instance_list_node->num_collectors--; 1636 1637 rv = _bcm_esw_collector_ref_count_update( 1638 unit, 1639 telemetry_instance_list_node->collector_id, 1640 -1); 1641 if (BCM_FAILURE(rv)) { 1642 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1643 (BSL_META_U(unit, 1644 "TELEMETRY(unit %d) Error: collector " 1645 " ref_count update failed %s\n"), unit, bcm_errmsg(rv))); 1646 return rv; 1647 } 1648 rv = _bcm_esw_collector_export_profile_ref_count_update( 1649 unit, 1650 telemetry_instance_list_node->export_profile_id, 1651 -1); 1652 if (BCM_FAILURE(rv)) { 1653 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1654 (BSL_META_U(unit, 1655 "TELEMETRY(unit %d) Error: collector " 1656 " ref_count update failed %s\n"), unit, bcm_errmsg(rv))); 1657 return rv; 1658 } 1659 } 1660 1661 telemetry_instance_list_node->collector_id = collector_id; 1662 telemetry_instance_list_node->export_profile_id = export_profile_id; 1663 1664 LOG_DEBUG(BSL_LS_BCM_TELEMETRY, 1665 (BSL_META_U(unit, 1666 "TELEMETRY(unit %d) Export Config Info update: %s" 1667 " (Telemetry instance=0x%x).\n"), unit, __FUNCTION__, 1668 telemetry_instance_id)); 1669 return rv; 1670 } 1671 1672 /* 1673 * Function: 1674 * _bcm_xgs5_telemetry_instance_export_config_get 1675 * Purpose: 1676 * Fetches a telemetry instance export config information. 1677 * Parameters: 1678 * unit - (IN) BCM device number 1679 * telemetry_instance_id - (IN) The telemetry instance ID 1680 * collector_id - (IN) Pointer to collector ID 1681 * export_profile_id - (IN) Pointer to export profile ID 1682 * Returns: 1683 * BCM_E_XXX 1684 */ 1685 int 1686 _bcm_xgs5_telemetry_instance_export_config_get(int unit, 1687 int telemetry_instance_id, 1688 bcm_collector_t *collector_id, 1689 int *export_profile_id) 1690 { 1691 int first_free_index = 0, cur_instance_index = 0, rv = BCM_E_NONE; 1692 _bcm_telemetry_instance_info_t *telemetry_instance_list_node = NULL; 1693 _bcm_telemetry_global_info_t *telemetry_per_unit_global_info = 1694 TELEMETRY_GLOBAL_INFO_GET(unit); 1695 1696 if (telemetry_per_unit_global_info == NULL) { 1697 return BCM_E_INIT; 1698 } 1699 rv = _bcm_xgs5_telemetry_is_instance_exists(unit, telemetry_instance_id, 1700 &cur_instance_index, &first_free_index); 1701 1702 /* If not found, return BCM_E_NOT_FOUND */ 1703 if (BCM_FAILURE(rv)) { 1704 return rv; 1705 } 1706 telemetry_instance_list_node = 1707 &(telemetry_instances_info_list[unit][cur_instance_index]); 1708 1709 *collector_id = telemetry_instance_list_node->collector_id; 1710 *export_profile_id = telemetry_instance_list_node->export_profile_id; 1711 1712 LOG_DEBUG(BSL_LS_BCM_TELEMETRY, 1713 (BSL_META_U(unit, 1714 "TELEMETRY(unit %d) Export Config Info update: %s" 1715 " (Telemetry instance=0x%x).\n"), unit, __FUNCTION__, 1716 telemetry_instance_id)); 1717 return rv; 1718 } 1719 1720 /* 1721 * Function: 1722 * bcm_xgs5_telemetry_instance_export_stats_get 1723 * Purpose: 1724 * Get the telemetry export statistics. 1725 * Parameters: 1726 * unit - (IN) BCM device number 1727 * telemetry_instance - (IN) Telemetry instance ID 1728 * collector_id - (IN) Collector ID 1729 * stats - (OUT) Export statistics. 1730 * Returns: 1731 * BCM_E_XXX - BCM error code. 1732 */ 1733 int bcm_xgs5_telemetry_instance_export_stats_get( 1734 int unit, 1735 int telemetry_instance, 1736 bcm_collector_t collector_id, 1737 bcm_telemetry_instance_export_stats_t *stats) 1738 { 1739 int first_free_index = 0, cur_instance_index = 0; 1740 int rv = BCM_E_NONE; 1741 bcm_collector_info_t collector_info; 1742 _bcm_telemetry_global_info_t *telemetry_per_unit_global_info = 1743 TELEMETRY_GLOBAL_INFO_GET(unit); 1744 1745 if (telemetry_per_unit_global_info == NULL) { 1746 return BCM_E_INIT; 1747 } 1748 1749 if (stats == NULL) { 1750 return BCM_E_PARAM; 1751 } 1752 1753 rv = _bcm_xgs5_telemetry_is_instance_exists(unit, telemetry_instance, 1754 &cur_instance_index, 1755 &first_free_index); 1756 /* If not found, return BCM_E_NOT_FOUND */ 1757 if (BCM_FAILURE(rv)) { 1758 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1759 (BSL_META_U(unit, 1760 "TELEMETRY(unit %d) Error: Invalid " 1761 " instance ID passed\n"), unit)); 1762 return rv; 1763 } 1764 1765 rv = bcm_esw_collector_get(unit, collector_id, &collector_info); 1766 /* If not found, return BCM_E_NOT_FOUND */ 1767 if (BCM_FAILURE(rv)) { 1768 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1769 (BSL_META_U(unit, 1770 "TELEMETRY(unit %d) Error: Invalid " 1771 " collector ID passed\n"), unit)); 1772 return rv; 1773 } 1774 1775 rv = _bcm_xgs5_st_eapp_instance_export_stats_get_msg(unit, stats); 1776 if (BCM_FAILURE(rv)) { 1777 return rv; 1778 } 1779 1780 return BCM_E_NONE; 1781 } 1782 1783 /* 1784 * Function: 1785 * bcm_xgs5_telemetry_instance_export_stats_set 1786 * Purpose: 1787 * Set the telemetry export statistics. 1788 * Parameters: 1789 * unit - (IN) BCM device number 1790 * telemetry_instance - (IN) Telemetry instance ID 1791 * collector_id - (IN) Collector ID 1792 * stats - (IN) Export statistics. 1793 * Returns: 1794 * BCM_E_XXX - BCM error code. 1795 */ 1796 int bcm_xgs5_telemetry_instance_export_stats_set( 1797 int unit, 1798 int telemetry_instance, 1799 bcm_collector_t collector_id, 1800 bcm_telemetry_instance_export_stats_t *stats) 1801 { 1802 int first_free_index = 0, cur_instance_index = 0; 1803 int rv = BCM_E_NONE; 1804 bcm_collector_info_t collector_info; 1805 _bcm_telemetry_global_info_t *telemetry_per_unit_global_info = 1806 TELEMETRY_GLOBAL_INFO_GET(unit); 1807 1808 if (telemetry_per_unit_global_info == NULL) { 1809 return BCM_E_INIT; 1810 } 1811 1812 if (stats == NULL) { 1813 return BCM_E_PARAM; 1814 } 1815 1816 rv = _bcm_xgs5_telemetry_is_instance_exists(unit, telemetry_instance, 1817 &cur_instance_index, 1818 &first_free_index); 1819 /* If not found, return BCM_E_NOT_FOUND */ 1820 if (BCM_FAILURE(rv)) { 1821 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1822 (BSL_META_U(unit, 1823 "TELEMETRY(unit %d) Error: Invalid " 1824 " instance ID passed\n"), unit)); 1825 return rv; 1826 } 1827 1828 rv = bcm_esw_collector_get(unit, collector_id, &collector_info); 1829 /* If not found, return BCM_E_NOT_FOUND */ 1830 if (BCM_FAILURE(rv)) { 1831 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 1832 (BSL_META_U(unit, 1833 "TELEMETRY(unit %d) Error: Invalid " 1834 " collector ID passed\n"), unit)); 1835 return rv; 1836 } 1837 1838 rv = _bcm_xgs5_st_eapp_instance_export_stats_set_msg(unit, stats); 1839 if (BCM_FAILURE(rv)) { 1840 return rv; 1841 } 1842 1843 return BCM_E_NONE; 1844 } 1845 1846 /* 1847 * Function: 1848 * _bcm_xgs5_telemetry_instance_list_destroy 1849 * Purpose: 1850 * Destroys the telemetry instance list. 1851 * Parameters: 1852 * unit - (IN) BCM device number 1853 * Returns: 1854 * BCM_E_XXX 1855 */ 1856 STATIC int 1857 _bcm_xgs5_telemetry_instance_list_destroy (int unit) 1858 { 1859 if (telemetry_instances_info_list[unit] != NULL) { 1860 sal_free(telemetry_instances_info_list[unit]); 1861 } 1862 1863 telemetry_instances_info_list[unit] = NULL; 1864 return BCM_E_NONE; 1865 } 1866 1867 /* 1868 * Function: 1869 * _bcm_xgs5_telemetry_instance_list_create 1870 * Purpose: 1871 * Creates the telemetry instance list. 1872 * Parameters: 1873 * unit - (IN) BCM device number 1874 * Returns: 1875 * BCM_E_XXX 1876 */ 1877 STATIC int 1878 _bcm_xgs5_telemetry_instance_list_create (int unit) 1879 { 1880 int i = 0; 1881 _bcm_telemetry_instance_info_t *telemetry_instance_node = NULL; 1882 1883 if (telemetry_instances_info_list[unit] == NULL) { 1884 _BCM_TELEMETRY_ALLOC(telemetry_instances_info_list[unit], 1885 _bcm_telemetry_instance_info_t, 1886 sizeof(_bcm_telemetry_instance_info_t) * 1887 (BCM_INT_TELEMETRY_MAX_INSTANCES), 1888 "telemetry instances list"); 1889 } 1890 1891 if (telemetry_instances_info_list[unit] == NULL) { 1892 return BCM_E_MEMORY; 1893 } 1894 1895 for (i= 0; 1896 i< BCM_INT_TELEMETRY_MAX_INSTANCES; i++) { 1897 telemetry_instance_node = &(telemetry_instances_info_list[unit][i]); 1898 telemetry_instance_node->instance_id = 1899 BCM_TELEMETRY_INVALID_INDEX; 1900 telemetry_instance_node->config_count = 1901 BCM_TELEMETRY_INVALID_VALUE; 1902 telemetry_instance_node->collector_id = 1903 BCM_TELEMETRY_INVALID_VALUE; 1904 telemetry_instance_node->export_profile_id = 1905 BCM_TELEMETRY_INVALID_VALUE; 1906 } 1907 return BCM_E_NONE; 1908 } 1909 1910 #ifdef BCM_WARM_BOOT_SUPPORT 1911 1912 typedef enum _bcm_xgs5_telemetry_wb_sequence_e { 1913 _bcmTelemetryWbSequenceConfig = 0, 1914 _bcmTelemetryWbSequenceModuleStatus = 1, 1915 _bcmTelemetryWbSequenceCount 1916 } _bcm_xgs5_telemetry_wb_sequence_t; 1917 1918 #define BCM_WB_TELEMETRY_CONFIG_VERSION_1_0 SOC_SCACHE_VERSION(1,0) 1919 #define BCM_WB_TELEMETRY_CONFIG_DEFAULT_VERSION BCM_WB_TELEMETRY_CONFIG_VERSION_1_0 1920 1921 #define BCM_WB_TELEMETRY_MODULE_STATUS_VERSION_1_0 SOC_SCACHE_VERSION(1,0) 1922 #define BCM_WB_TELEMETRY_MODULE_STATUS_DEFAULT_VERSION BCM_WB_TELEMETRY_MODULE_STATUS_VERSION_1_0 1923 1924 #define TELEMETRY_SCACHE_WRITE(_scache, _val, _type) \ 1925 do { \ 1926 _type _tmp = (_type) (_val); \ 1927 sal_memcpy((_scache), &(_tmp), sizeof(_type)); \ 1928 (_scache) += sizeof(_type); \ 1929 } while(0) 1930 1931 #define TELEMETRY_SCACHE_READ(_scache, _var, _type) \ 1932 do { \ 1933 _type _tmp; \ 1934 sal_memcpy(&(_tmp), (_scache), sizeof(_type)); \ 1935 (_scache) += sizeof(_type); \ 1936 (_var) = (_tmp); \ 1937 } while(0) 1938 1939 1940 /* 1941 * Function: 1942 * _bcm_telemetry_config_sync 1943 * Purpose: 1944 * Syncs all telemetry instances information to scache 1945 * Parameters: 1946 * unit - (IN) Device unit number 1947 * scache - (IN) Pointer to current scache location 1948 * Returns: 1949 * BCM_E_XXX 1950 */ 1951 STATIC void 1952 _bcm_telemetry_config_sync(int unit, uint8 **scache) 1953 { 1954 1955 int i; 1956 _bcm_telemetry_instance_info_t *telemetry_instance = NULL; 1957 _bcm_telemetry_global_info_t *telemetry_per_unit_global_info = 1958 TELEMETRY_GLOBAL_INFO_GET(unit); 1959 1960 1961 /* Number of telemetry instances configured */ 1962 TELEMETRY_SCACHE_WRITE(*scache, 1963 telemetry_per_unit_global_info->num_telemetry_instances, uint32); 1964 1965 for (i = 0; 1966 i < BCM_INT_TELEMETRY_MAX_INSTANCES; i++) { 1967 1968 telemetry_instance = &(telemetry_instances_info_list[unit][i]); 1969 1970 if (telemetry_instance->instance_id == BCM_TELEMETRY_INVALID_INDEX) { 1971 /* Telemetry instance does not exist, continue */ 1972 continue; 1973 } 1974 1975 /* Telemetry instance Id */ 1976 TELEMETRY_SCACHE_WRITE(*scache, telemetry_instance->instance_id, int); 1977 1978 /* Telemetry instance core */ 1979 TELEMETRY_SCACHE_WRITE(*scache, telemetry_instance->core, int); 1980 1981 /* Telemetry instance configuration count */ 1982 TELEMETRY_SCACHE_WRITE(*scache, telemetry_instance->config_count, int); 1983 1984 /* Telemetry instance collector ID*/ 1985 TELEMETRY_SCACHE_WRITE(*scache, telemetry_instance->collector_id, 1986 bcm_collector_t); 1987 1988 /* Telemetry instance export profile ID*/ 1989 TELEMETRY_SCACHE_WRITE(*scache, telemetry_instance->export_profile_id, 1990 int); 1991 1992 1993 } 1994 } 1995 1996 /* 1997 * Function: 1998 * _bcm_xgs5_telemetry_config_sync 1999 * Purpose: 2000 * Syncs Telemetry config data to scache 2001 * Parameters: 2002 * unit - (IN) Device unit number 2003 * Returns: 2004 * BCM_E_XXX 2005 */ 2006 STATIC int 2007 _bcm_xgs5_telemetry_config_sync(int unit) 2008 { 2009 2010 int stable_size; 2011 soc_scache_handle_t scache_handle; 2012 uint8 *scache = NULL; 2013 _bcm_telemetry_global_info_t *telemetry_per_unit_global_info = 2014 TELEMETRY_GLOBAL_INFO_GET(unit); 2015 2016 if (telemetry_per_unit_global_info == NULL) { 2017 return BCM_E_NONE; 2018 } 2019 2020 /* Get Telemetry module storage size. */ 2021 SOC_IF_ERROR_RETURN(soc_stable_size_get(unit, &stable_size)); 2022 2023 /* If level 2 store is not configured return from here. */ 2024 if (SOC_WARM_BOOT_SCACHE_IS_LIMITED(unit) || (stable_size == 0)) { 2025 return BCM_E_NONE; 2026 } 2027 2028 SOC_SCACHE_HANDLE_SET(scache_handle, unit, 2029 BCM_MODULE_TELEMETRY, _bcmTelemetryWbSequenceConfig); 2030 BCM_IF_ERROR_RETURN(_bcm_esw_scache_ptr_get(unit, scache_handle, 0, 0, 2031 &scache, 0, NULL)); 2032 if (NULL == scache) { 2033 return BCM_E_INTERNAL; 2034 } 2035 2036 _bcm_telemetry_config_sync(unit, &scache); 2037 2038 return BCM_E_NONE; 2039 } 2040 2041 /* 2042 * Function: 2043 * _bcm_telemetry_recover 2044 * Purpose: 2045 * Recover Telemetry data from scache 2046 * Parameters: 2047 * unit - (IN) Device unit number 2048 * scache - (IN) Pointer to current scache location 2049 * Returns: 2050 * BCM_E_XXX 2051 */ 2052 STATIC int 2053 _bcm_telemetry_recover(int unit, uint8 **scache) 2054 { 2055 int i, rv = BCM_E_NONE; 2056 _bcm_telemetry_instance_info_t *telemetry_instance = NULL; 2057 _bcm_telemetry_global_info_t *telemetry_per_unit_global_info = 2058 TELEMETRY_GLOBAL_INFO_GET(unit); 2059 2060 2061 /* Number of telemetry instances configured */ 2062 TELEMETRY_SCACHE_READ(*scache, 2063 telemetry_per_unit_global_info->num_telemetry_instances, uint32); 2064 2065 for (i = 0; 2066 i < telemetry_per_unit_global_info->num_telemetry_instances; i++) { 2067 2068 telemetry_instance = &(telemetry_instances_info_list[unit][i]); 2069 2070 /* Telemetry instance Id */ 2071 TELEMETRY_SCACHE_READ(*scache, telemetry_instance->instance_id, int); 2072 2073 /* Transport instance core */ 2074 TELEMETRY_SCACHE_READ(*scache, telemetry_instance->core, int); 2075 2076 /* Transport instance config count */ 2077 TELEMETRY_SCACHE_READ(*scache, telemetry_instance->config_count, int); 2078 2079 /* Telemetry instance collector ID*/ 2080 TELEMETRY_SCACHE_READ(*scache, telemetry_instance->collector_id, 2081 bcm_collector_t); 2082 2083 /* Telemetry instance export profile ID*/ 2084 TELEMETRY_SCACHE_READ(*scache, telemetry_instance->export_profile_id, 2085 int); 2086 2087 if (telemetry_instance->config_count) { 2088 _BCM_TELEMETRY_ALLOC(telemetry_instance->telemetry_config, 2089 bcm_telemetry_config_t, 2090 (telemetry_instance->config_count * sizeof(bcm_telemetry_config_t)), 2091 "TELEMETRY_CONFIG_INFO"); 2092 } 2093 rv = bcm_xgs5_st_eapp_instance_get_msg(unit, 2094 telemetry_instance->instance_id, 2095 telemetry_instance->telemetry_config, 2096 telemetry_instance->config_count); 2097 if (BCM_FAILURE(rv)) { 2098 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 2099 (BSL_META_U(unit, 2100 "TELEMETRY(unit %d) Error: Instance " 2101 " get failed from BTE"), unit)); 2102 return rv; 2103 } 2104 2105 rv = _bcm_esw_collector_ref_count_update(unit, 2106 telemetry_instance->collector_id, 2107 1); 2108 if (BCM_FAILURE(rv)) { 2109 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 2110 (BSL_META_U(unit, 2111 "TELEMETRY(unit %d) Error: collector " 2112 " ref_count update failed %s\n"), unit, bcm_errmsg(rv))); 2113 return rv; 2114 } 2115 rv = _bcm_esw_collector_export_profile_ref_count_update( 2116 unit, 2117 telemetry_instance->export_profile_id, 2118 1); 2119 if (BCM_FAILURE(rv)) { 2120 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 2121 (BSL_META_U(unit, 2122 "TELEMETRY(unit %d) Error: export profile " 2123 " ref_count update failed %s\n"), unit, bcm_errmsg(rv))); 2124 return rv; 2125 } 2126 rv = _bcm_esw_collector_user_update(unit, 2127 telemetry_instance->collector_id, 2128 _BCM_COLLECTOR_EXPORT_APP_ST_PROTOBUF); 2129 if (BCM_FAILURE(rv)) { 2130 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 2131 (BSL_META_U(unit, 2132 "TELEMETRY(unit %d) Error: collector " 2133 " user update failed %s\n"), unit, bcm_errmsg(rv))); 2134 return rv; 2135 } 2136 2137 } 2138 2139 rv = bcm_xgs5_st_eapp_port_get_msg(unit); 2140 if (BCM_FAILURE(rv)) { 2141 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 2142 (BSL_META_U(unit, 2143 "TELEMETRY(unit %d) Error: ports " 2144 " get failed from BTE"), unit)); 2145 return rv; 2146 } 2147 2148 rv = _bcm_xgs5_st_eapp_system_id_get_msg(unit); 2149 if (BCM_FAILURE(rv)) { 2150 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 2151 (BSL_META_U(unit, 2152 "TELEMETRY(unit %d) Error: system ID " 2153 " get failed to BTE %s\n"), unit, bcm_errmsg(rv))); 2154 return rv; 2155 } 2156 2157 return BCM_E_NONE; 2158 } 2159 2160 /* 2161 * Function: 2162 * _bcm_telemetry_config_scache_size_get 2163 * Purpose: 2164 * Get the size required to sync telemetry data to scache 2165 * Parameters: 2166 * unit - (IN) Device unit number 2167 * Returns: 2168 * Required size 2169 */ 2170 STATIC uint32 2171 _bcm_telemetry_config_scache_size_get(int unit) 2172 { 2173 uint32 telemetry_total_size = 0; 2174 uint32 telemetry_instances_info_size = 0; 2175 2176 /* Max telemetry instances configured */ 2177 telemetry_total_size += sizeof(uint32); 2178 2179 /* Telemetry instance Id */ 2180 telemetry_instances_info_size += sizeof(int); 2181 2182 /* Telemetry instance core ID */ 2183 telemetry_instances_info_size += sizeof(int); 2184 2185 /* Telemetry instance config count */ 2186 telemetry_instances_info_size += sizeof(int); 2187 2188 /* Telemetry instance collector ID*/ 2189 telemetry_instances_info_size += sizeof(bcm_collector_t); 2190 2191 /* Telemetry instance export profile ID*/ 2192 telemetry_instances_info_size += sizeof(int); 2193 2194 /* Multiply by number of telemetry instances */ 2195 telemetry_instances_info_size *= BCM_INT_TELEMETRY_MAX_INSTANCES; 2196 2197 telemetry_total_size += telemetry_instances_info_size; 2198 2199 return telemetry_total_size; 2200 } 2201 2202 /* 2203 * Function: 2204 * _bcm_telemetry_config_scache_alloc 2205 * Purpose: 2206 * Telemetry WB scache alloc for storing configuration 2207 * Parameters: 2208 * unit - (IN) Unit number. 2209 * create - (IN) 1 - Create, 0 - Realloc 2210 * Returns: 2211 * BCM_E_XXX 2212 * Notes: 2213 */ 2214 STATIC int _bcm_telemetry_config_scache_alloc(int unit, int create) 2215 { 2216 uint32 cur_size = 0; 2217 uint32 rqd_size = 0; 2218 int rv = BCM_E_NONE; 2219 soc_scache_handle_t scache_handle; 2220 uint8 *scache = NULL; 2221 2222 rqd_size += _bcm_telemetry_config_scache_size_get(unit); 2223 2224 SOC_SCACHE_HANDLE_SET(scache_handle, unit, 2225 BCM_MODULE_TELEMETRY, _bcmTelemetryWbSequenceConfig); 2226 2227 if (create) { 2228 rv = _bcm_esw_scache_ptr_get(unit, scache_handle, 1, rqd_size, 2229 &scache, BCM_WB_TELEMETRY_CONFIG_DEFAULT_VERSION, NULL); 2230 BCM_IF_ERROR_RETURN(rv); 2231 } else { 2232 /* Get current size */ 2233 rv = soc_scache_ptr_get(unit, scache_handle, &scache, &cur_size); 2234 SOC_IF_ERROR_RETURN(rv); 2235 2236 if (rqd_size > cur_size) { 2237 /* Request the extra size */ 2238 rv = soc_scache_realloc(unit, scache_handle, rqd_size - cur_size); 2239 SOC_IF_ERROR_RETURN(rv); 2240 } 2241 } 2242 2243 return BCM_E_NONE; 2244 } 2245 2246 /* 2247 * Function: 2248 * _bcm_xgs5_telemetry_module_status_sync 2249 * Purpose: 2250 * Syncs Telemetry module status to scache 2251 * Parameters: 2252 * unit - (IN) Device unit number 2253 * Returns: 2254 * BCM_E_XXX 2255 */ 2256 STATIC int 2257 _bcm_xgs5_telemetry_module_status_sync(int unit) 2258 { 2259 2260 int stable_size; 2261 soc_scache_handle_t scache_handle; 2262 uint8 *scache = NULL; 2263 _bcm_telemetry_global_info_t *telemetry_per_unit_global_info = 2264 TELEMETRY_GLOBAL_INFO_GET(unit); 2265 2266 /* Get Telemetry module storage size. */ 2267 SOC_IF_ERROR_RETURN(soc_stable_size_get(unit, &stable_size)); 2268 2269 /* If level 2 store is not configured return from here. */ 2270 if (SOC_WARM_BOOT_SCACHE_IS_LIMITED(unit) || (stable_size == 0)) { 2271 return BCM_E_NONE; 2272 } 2273 2274 SOC_SCACHE_HANDLE_SET(scache_handle, unit, 2275 BCM_MODULE_TELEMETRY, _bcmTelemetryWbSequenceModuleStatus); 2276 BCM_IF_ERROR_RETURN(_bcm_esw_scache_ptr_get(unit, scache_handle, 0, 0, 2277 &scache, 0, NULL)); 2278 if (NULL == scache) { 2279 return BCM_E_INTERNAL; 2280 } 2281 2282 2283 if (telemetry_per_unit_global_info == NULL) { 2284 /* Module not running */ 2285 TELEMETRY_SCACHE_WRITE(scache, 0, uint8); 2286 } else { 2287 /* Module in running state */ 2288 TELEMETRY_SCACHE_WRITE(scache, 1, uint8); 2289 } 2290 2291 return BCM_E_NONE; 2292 } 2293 2294 /* 2295 * Function: 2296 * _bcm_telemetry_module_status_scache_size_get 2297 * Purpose: 2298 * Get the size required to sync telemetry module status to scache 2299 * Parameters: 2300 * unit - (IN) Device unit number 2301 * Returns: 2302 * Required size 2303 */ 2304 STATIC uint32 2305 _bcm_telemetry_module_status_scache_size_get(int unit) 2306 { 2307 return (sizeof(uint8)); 2308 } 2309 2310 /* 2311 * Function: 2312 * _bcm_telemetry_module_status_scache_alloc 2313 * Purpose: 2314 * Telemetry WB scache alloc for storing module_status 2315 * Parameters: 2316 * unit - (IN) Unit number. 2317 * create - (IN) 1 - Create, 0 - Realloc 2318 * Returns: 2319 * BCM_E_XXX 2320 * Notes: 2321 */ 2322 STATIC int _bcm_telemetry_module_status_scache_alloc(int unit, int create) 2323 { 2324 uint32 cur_size = 0; 2325 uint32 rqd_size = 0; 2326 int rv = BCM_E_NONE; 2327 soc_scache_handle_t scache_handle; 2328 uint8 *scache = NULL; 2329 2330 rqd_size += _bcm_telemetry_module_status_scache_size_get(unit); 2331 2332 SOC_SCACHE_HANDLE_SET(scache_handle, unit, 2333 BCM_MODULE_TELEMETRY, 2334 _bcmTelemetryWbSequenceModuleStatus); 2335 2336 if (create) { 2337 rv = _bcm_esw_scache_ptr_get(unit, scache_handle, 1, rqd_size, 2338 &scache, BCM_WB_TELEMETRY_MODULE_STATUS_DEFAULT_VERSION, NULL); 2339 BCM_IF_ERROR_RETURN(rv); 2340 } else { 2341 /* Get current size */ 2342 rv = soc_scache_ptr_get(unit, scache_handle, &scache, &cur_size); 2343 SOC_IF_ERROR_RETURN(rv); 2344 2345 if (rqd_size > cur_size) { 2346 /* Request the extra size */ 2347 rv = soc_scache_realloc(unit, scache_handle, rqd_size - cur_size); 2348 SOC_IF_ERROR_RETURN(rv); 2349 } 2350 } 2351 2352 return BCM_E_NONE; 2353 } 2354 2355 /* 2356 * Function: 2357 * _bcm_xgs5_telemetry_sync 2358 * Purpose: 2359 * Syncs Telemetry data to scache 2360 * Parameters: 2361 * unit - (IN) Device unit number 2362 * Returns: 2363 * BCM_E_XXX 2364 */ 2365 int 2366 _bcm_xgs5_telemetry_sync(int unit) 2367 { 2368 BCM_IF_ERROR_RETURN(_bcm_xgs5_telemetry_config_sync(unit)); 2369 BCM_IF_ERROR_RETURN(_bcm_xgs5_telemetry_module_status_sync(unit)); 2370 2371 return BCM_E_NONE; 2372 } 2373 2374 /* 2375 * Function: 2376 * _bcm_telemetry_scache_alloc 2377 * Purpose: 2378 * Telemetry WB scache alloc 2379 * Parameters: 2380 * unit - (IN) Unit number. 2381 * create - (IN) 1 - Create, 0 - Realloc 2382 * Returns: 2383 * BCM_E_XXX 2384 * Notes: 2385 */ 2386 STATIC int _bcm_telemetry_scache_alloc(int unit, int create) 2387 { 2388 BCM_IF_ERROR_RETURN(_bcm_telemetry_config_scache_alloc(unit, create)); 2389 BCM_IF_ERROR_RETURN(_bcm_telemetry_module_status_scache_alloc(unit, create)); 2390 2391 return BCM_E_NONE; 2392 } 2393 2394 /* 2395 * Function: 2396 * _bcm_telemetry_wb_config_recover 2397 * Purpose: 2398 * Telemetry WB config recovery 2399 * Parameters: 2400 * unit - (IN) Unit number. 2401 * Returns: 2402 * BCM_E_XXX 2403 * Notes: 2404 */ 2405 STATIC int _bcm_telemetry_wb_config_recover(int unit) 2406 { 2407 int stable_size; /* Secondary storage size. */ 2408 uint8 *scache = NULL; 2409 soc_scache_handle_t scache_handle; 2410 int rv = BCM_E_NONE; 2411 uint16 recovered_ver = 0; 2412 2413 SOC_IF_ERROR_RETURN(soc_stable_size_get(unit, &stable_size)); 2414 2415 if (!SOC_WARM_BOOT_SCACHE_IS_LIMITED(unit) && (stable_size > 0)) { 2416 SOC_SCACHE_HANDLE_SET(scache_handle, unit, 2417 BCM_MODULE_TELEMETRY, _bcmTelemetryWbSequenceConfig); 2418 2419 rv = _bcm_esw_scache_ptr_get(unit, scache_handle, 0, 0, 2420 &scache, BCM_WB_TELEMETRY_CONFIG_DEFAULT_VERSION, 2421 &recovered_ver); 2422 if (BCM_E_NOT_FOUND == rv) { 2423 /* Upgrading from SDK release that does not have warmboot state */ 2424 rv = _bcm_telemetry_scache_alloc(unit, 1); 2425 return rv; 2426 } else if (BCM_FAILURE(rv)) { 2427 return rv; 2428 } 2429 2430 if (NULL == scache) { 2431 return BCM_E_NOT_FOUND; 2432 } 2433 } else { 2434 return BCM_E_NONE; 2435 } 2436 2437 /* Scache recovery */ 2438 BCM_IF_ERROR_RETURN(_bcm_telemetry_recover(unit, &scache)); 2439 2440 /* Realloc any extra scache that may be needed */ 2441 BCM_IF_ERROR_RETURN(_bcm_telemetry_config_scache_alloc(unit, 0)); 2442 2443 return rv; 2444 } 2445 2446 /* 2447 * Function: 2448 * _bcm_xgs5_telemetry_wb_module_status_recover 2449 * Purpose: 2450 * Find out if the telemetry module was running prior to warmboot 2451 * Parameters: 2452 * unit - (IN) BCM device number 2453 * init - (OUT) 1 - Module initialized, 2454 * 0 - Module detached 2455 * Returns: 2456 * BCM_E_XXX - BCM error code. 2457 */ 2458 int _bcm_xgs5_telemetry_wb_module_status_recover(int unit, int *init) 2459 { 2460 int stable_size; /* Secondary storage size. */ 2461 uint8 *scache = NULL; 2462 soc_scache_handle_t scache_handle; 2463 int rv = BCM_E_NONE; 2464 uint16 recovered_ver = 0; 2465 2466 SOC_IF_ERROR_RETURN(soc_stable_size_get(unit, &stable_size)); 2467 2468 if (!SOC_WARM_BOOT_SCACHE_IS_LIMITED(unit) && (stable_size > 0)) { 2469 SOC_SCACHE_HANDLE_SET(scache_handle, unit, 2470 BCM_MODULE_TELEMETRY, 2471 _bcmTelemetryWbSequenceModuleStatus); 2472 2473 rv = _bcm_esw_scache_ptr_get(unit, scache_handle, 0, 0, 2474 &scache, 2475 BCM_WB_TELEMETRY_MODULE_STATUS_DEFAULT_VERSION, 2476 &recovered_ver); 2477 if (BCM_E_NOT_FOUND == rv) { 2478 /* Upgrading from SDK release that does not have 2479 * warmboot state for module status 2480 */ 2481 rv = _bcm_telemetry_module_status_scache_alloc(unit, 1); 2482 2483 /* Set init = 1 to avoid breaking upgrade from older release */ 2484 *init = 1; 2485 return rv; 2486 } else if (BCM_FAILURE(rv)) { 2487 return rv; 2488 } 2489 2490 if (NULL == scache) { 2491 return BCM_E_NOT_FOUND; 2492 } 2493 } else { 2494 return BCM_E_NONE; 2495 } 2496 2497 /* Scache recovery */ 2498 TELEMETRY_SCACHE_READ(scache, *init, uint8); 2499 2500 /* Realloc any extra scache that may be needed */ 2501 BCM_IF_ERROR_RETURN(_bcm_telemetry_module_status_scache_alloc(unit, 0)); 2502 2503 return BCM_E_NONE; 2504 } 2505 2506 #endif /* BCM_WARM_BOOT_SUPPORT */ 2507 2508 /****************************************************** 2509 * * 2510 * Telemetry APP APIs * 2511 */ 2512 2513 STATIC 2514 int bcm_xgs5_telemetry_eapp_detach(int unit) 2515 { 2516 _bcm_telemetry_global_info_t *telemetry_config_per_unit = 2517 TELEMETRY_GLOBAL_INFO_GET(unit); 2518 int rv = BCM_E_NONE; 2519 int uc, status = 0; 2520 uint16 reply_len = 0; 2521 2522 if (telemetry_config_per_unit->uc_loaded == 0) { 2523 return BCM_E_NONE; 2524 } 2525 uc = telemetry_config_per_unit->uC; 2526 2527 if (!SOC_WARM_BOOT(unit)) { 2528 /* Un Init the app */ 2529 SOC_IF_ERROR_RETURN(soc_uc_status(unit, uc, &status)); 2530 if (status) { 2531 rv = _bcm_xgs5_st_msg_send_receive(unit, 2532 MOS_MSG_SUBCLASS_ST_SHUTDOWN, 2533 0, 0, 2534 MOS_MSG_SUBCLASS_ST_SHUTDOWN_REPLY, 2535 &reply_len, 2536 SHR_ST_MAX_UC_MSG_TIMEOUT); 2537 if (BCM_SUCCESS(rv) && (reply_len != 0)) { 2538 return BCM_E_INTERNAL; 2539 } 2540 } 2541 } 2542 telemetry_config_per_unit->uc_loaded = 0; 2543 2544 /* 2545 * Free DMA buffer 2546 */ 2547 if (telemetry_config_per_unit->dma_buffer != NULL) { 2548 soc_cm_sfree(unit, telemetry_config_per_unit->dma_buffer); 2549 } 2550 2551 return BCM_E_NONE; 2552 } 2553 2554 STATIC 2555 int _bcm_xgs5_st_eapp_send_ctrl_init_msg(int unit) 2556 { 2557 st_sdk_msg_ctrl_init_t ctrl_init_msg; 2558 uint8 *buffer_req = NULL, *buffer_ptr = NULL; 2559 uint16 buffer_len = 0, reply_len = 0; 2560 _bcm_telemetry_global_info_t *telemetry_config_per_unit = 2561 TELEMETRY_GLOBAL_INFO_GET(unit); 2562 2563 2564 sal_memset(&ctrl_init_msg, 0, sizeof(ctrl_init_msg)); 2565 ctrl_init_msg.max_export_pkt_length = 2566 telemetry_config_per_unit->max_pkt_size; 2567 /*Init time in milli seconds as per proto file*/ 2568 ctrl_init_msg.init_time_l = (sal_time() *1000); 2569 ctrl_init_msg.num_instances = BCM_INT_TELEMETRY_MAX_INSTANCES; 2570 ctrl_init_msg.num_collectors = 1; 2571 if (ST_UC_FEATURE_CHECK(ST_MAX_NUM_PORTS)) { 2572 ctrl_init_msg.max_num_ports = telemetry_config_per_unit->max_num_ports; 2573 } 2574 2575 buffer_req = telemetry_config_per_unit->dma_buffer; 2576 buffer_ptr = st_sdk_msg_ctrl_init_pack(buffer_req, &ctrl_init_msg); 2577 buffer_len = buffer_ptr - buffer_req; 2578 2579 BCM_IF_ERROR_RETURN(_bcm_xgs5_st_msg_send_receive(unit, 2580 MOS_MSG_SUBCLASS_ST_INIT, 2581 buffer_len, 0, 2582 MOS_MSG_SUBCLASS_ST_INIT_REPLY, 2583 &reply_len, 2584 SHR_ST_MAX_UC_MSG_TIMEOUT)); 2585 return BCM_E_NONE; 2586 } 2587 2588 STATIC 2589 int bcm_xgs5_telemetry_eapp_init(int unit) 2590 { 2591 _bcm_telemetry_global_info_t *telemetry_config_per_unit = 2592 TELEMETRY_GLOBAL_INFO_GET(unit); 2593 int rv = BCM_E_NONE; 2594 int uc = 1; 2595 2596 /* Init the app, determine which core is running the app by chooosing 2597 * the first uC that returns sucessfully 2598 */ 2599 for (uc = 0; uc < CMICM_NUM_UCS; uc++) { 2600 if (!soc_uc_in_reset(unit, uc)) { 2601 rv = soc_cmic_uc_appl_init(unit, uc, MOS_MSG_CLASS_ST, 2602 SHR_ST_MAX_UC_MSG_TIMEOUT, 2603 ST_SDK_VERSION, ST_UC_MIN_VERSION, 2604 NULL, NULL); 2605 if (SOC_E_NONE == rv) { 2606 telemetry_config_per_unit->uc_loaded = 1; 2607 break; 2608 } 2609 } 2610 } 2611 2612 if (telemetry_config_per_unit->uc_loaded == 1) { 2613 telemetry_config_per_unit->uC = uc; 2614 } else { 2615 /* Could not find or start Telemetry appl */ 2616 LOG_WARN(BSL_LS_BCM_BFD, 2617 (BSL_META_U(unit, 2618 "uKernel Telemetry application not available\n"))); 2619 return BCM_E_NONE; 2620 } 2621 2622 /* 2623 * Allocate DMA buffer 2624 * 2625 * DMA buffer will be used to send and receive 'long' messages 2626 * between SDK Host and uController (BTE). 2627 */ 2628 telemetry_config_per_unit->dma_buffer_len = sizeof(st_sdk_msg_ctrl_init_t); 2629 telemetry_config_per_unit->dma_buffer = soc_cm_salloc(unit, 2630 telemetry_config_per_unit->dma_buffer_len, 2631 "Telemetry DMA buffer"); 2632 if (!telemetry_config_per_unit->dma_buffer) { 2633 BCM_IF_ERROR_RETURN(bcm_xgs5_telemetry_eapp_detach(unit)); 2634 return BCM_E_MEMORY; 2635 } 2636 sal_memset(telemetry_config_per_unit->dma_buffer, 0, 2637 telemetry_config_per_unit->dma_buffer_len); 2638 2639 if (!SOC_WARM_BOOT(unit)) { 2640 /* Send the init config to UKERNEL */ 2641 rv = _bcm_xgs5_st_eapp_send_ctrl_init_msg(unit); 2642 if (BCM_FAILURE(rv)) { 2643 BCM_IF_ERROR_RETURN(bcm_xgs5_telemetry_eapp_detach(unit)); 2644 return rv; 2645 } 2646 } 2647 2648 return BCM_E_NONE; 2649 } 2650 2651 /* 2652 * Function: 2653 * _bcm_xgs5_telemetry_detach 2654 * Purpose: 2655 * Detaches the Telemetry module. 2656 * Parameters: 2657 * unit - (IN) BCM device number 2658 * Returns: 2659 * BCM_E_XXX - BCM error code. 2660 */ 2661 int _bcm_xgs5_telemetry_detach(int unit) 2662 { 2663 _bcm_telemetry_global_info_t *telemetry_config_per_unit = 2664 TELEMETRY_GLOBAL_INFO_GET(unit); 2665 int rv = BCM_E_NONE; 2666 2667 if (telemetry_config_per_unit == NULL) { 2668 /* Telemetry not initialized */ 2669 return BCM_E_NONE; 2670 } 2671 /* De-init the embedded app */ 2672 rv = bcm_xgs5_telemetry_eapp_detach(unit); 2673 if (BCM_FAILURE(rv)) { 2674 return rv; 2675 } 2676 2677 /* Counter module settings */ 2678 rv = soc_counter_tomahawk_telemetry_detach(unit); 2679 if (BCM_FAILURE(rv)) { 2680 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 2681 (BSL_META_U(unit, 2682 "TELEMETRY(unit %d) Error: telemetry " 2683 " counter Init failed %s\n"), unit, bcm_errmsg(rv))); 2684 return rv; 2685 } 2686 2687 /* Free up telemetry instances list */ 2688 BCM_IF_ERROR_RETURN(_bcm_xgs5_telemetry_instance_list_destroy(unit)); 2689 2690 sal_free(telemetry_config_per_unit); 2691 telemetry_global_info[unit] = NULL; 2692 2693 SOC_CONTROL(unit)->uc_telemetry_enable = 0; 2694 2695 return BCM_E_NONE; 2696 } 2697 2698 /* 2699 * Function: 2700 * _bcm_xgs5_telemetry_init 2701 * Purpose: 2702 * Initializes the Telemetry module. 2703 * Parameters: 2704 * unit - (IN) BCM device number 2705 * Returns: 2706 * BCM_E_XXX - BCM error code. 2707 */ 2708 int _bcm_xgs5_telemetry_init(int unit) 2709 { 2710 _bcm_telemetry_global_info_t *telemetry_config_per_unit = 2711 TELEMETRY_GLOBAL_INFO_GET(unit); 2712 int rv = BCM_E_NONE; 2713 uint16 max_num_ports = 0; 2714 #ifdef BCM_WARM_BOOT_SUPPORT 2715 int init = 0; 2716 #endif /* BCM_WARM_BOOT_SUPPORT */ 2717 2718 #ifdef BCM_WARM_BOOT_SUPPORT 2719 if (SOC_WARM_BOOT(unit)) { 2720 BCM_IF_ERROR_RETURN 2721 (_bcm_xgs5_telemetry_wb_module_status_recover(unit, &init)); 2722 2723 if (init == 0) { 2724 /* Module was not initialized prior to WB, skip initializing it now */ 2725 return BCM_E_NONE; 2726 } 2727 } 2728 #endif /* BCM_WARM_BOOT_SUPPORT */ 2729 2730 max_num_ports = soc_property_get(unit, 2731 spn_TELEMETRY_MAX_PORTS_MONITOR, 2732 SHR_ST_MAX_PORTS); 2733 if (!max_num_ports) { 2734 return BCM_E_NONE; 2735 } 2736 2737 if (max_num_ports > SHR_ST_MAX_PORTS) { 2738 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 2739 (BSL_META_U(unit, 2740 "TELEMETRY(unit %d) Error: Invalid " 2741 " Maximum ports \n"), unit)); 2742 return BCM_E_CONFIG; 2743 } 2744 2745 if (telemetry_config_per_unit != NULL) { 2746 BCM_IF_ERROR_RETURN(_bcm_xgs5_telemetry_detach(unit)); 2747 telemetry_config_per_unit = NULL; 2748 } 2749 2750 _BCM_TELEMETRY_ALLOC(telemetry_config_per_unit, _bcm_telemetry_global_info_t, 2751 sizeof(_bcm_telemetry_global_info_t), "TELEMETRY_INFO_PER_UNIT"); 2752 if (telemetry_config_per_unit == NULL) { 2753 return BCM_E_MEMORY; 2754 } 2755 telemetry_global_info[unit] = telemetry_config_per_unit; 2756 2757 telemetry_config_per_unit->max_pkt_size = soc_property_get(unit, 2758 spn_TELEMETRY_EXPORT_MAX_PACKET_SIZE, 2759 BCM_TELEMETRY_DEFAULT_MAX_EXPORT_LENGTH); 2760 if ((telemetry_config_per_unit->max_pkt_size < 2761 SHR_ST_MAX_COLLECTOR_ENCAP_LENGTH) || 2762 (telemetry_config_per_unit->max_pkt_size > SHR_ST_MAX_EXPORT_LENGTH)) { 2763 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 2764 (BSL_META_U(unit, 2765 "TELEMETRY(unit %d) Error: Invalid " 2766 " export pkt size\n"), unit)); 2767 return BCM_E_CONFIG; 2768 } 2769 2770 telemetry_config_per_unit->max_num_ports = max_num_ports; 2771 2772 /* Init the embedded app */ 2773 rv = bcm_xgs5_telemetry_eapp_init(unit); 2774 if (BCM_FAILURE(rv)) { 2775 LOG_WARN(BSL_LS_BCM_TELEMETRY, 2776 (BSL_META_U(unit, 2777 "TELEMETRY(unit %d) Error: telemetry " 2778 " App Init failed %s\n"), unit, bcm_errmsg(rv))); 2779 return rv; 2780 } 2781 2782 if (telemetry_config_per_unit->uc_loaded == 0) { 2783 BCM_IF_ERROR_RETURN(_bcm_xgs5_telemetry_detach(unit)); 2784 return BCM_E_NONE; 2785 } 2786 SOC_CONTROL(unit)->uc_telemetry_enable = 1; 2787 2788 /* Counter module settings */ 2789 rv = soc_counter_tomahawk_telemetry_init(unit); 2790 if (BCM_FAILURE(rv)) { 2791 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 2792 (BSL_META_U(unit, 2793 "TELEMETRY(unit %d) Error: telemetry " 2794 " counter Init failed %s\n"), unit, bcm_errmsg(rv))); 2795 return rv; 2796 } 2797 2798 2799 /* Create telemetry list */ 2800 BCM_IF_ERROR_RETURN(_bcm_xgs5_telemetry_instance_list_create(unit)); 2801 2802 #ifdef BCM_WARM_BOOT_SUPPORT 2803 if (SOC_WARM_BOOT(unit)) { 2804 rv = _bcm_telemetry_wb_config_recover(unit); 2805 } else { 2806 rv = _bcm_telemetry_scache_alloc(unit, 1); 2807 } 2808 #endif /* BCM_WARM_BOOT_SUPPORT */ 2809 2810 if (rv == BCM_E_NOT_FOUND) { 2811 /* Continue with initialization if scache not found */ 2812 rv = BCM_E_NONE; 2813 } 2814 if (BCM_FAILURE(rv)) { 2815 LOG_ERROR(BSL_LS_BCM_TELEMETRY, 2816 (BSL_META_U(unit, 2817 "TELEMETRY(unit %d) Error: telemetry " 2818 " Init failed\n"), unit)); 2819 return (rv); 2820 } 2821 2822 return BCM_E_NONE; 2823 } 2824 2825 char *_bcm_xgs5_telemetry_object_type_str[bcmTelemetryObjectTypeCount] = 2826 { 2827 "None", 2828 "Interface Ingress", 2829 "Interface Egress", 2830 "Interface Egress Queue", 2831 "Interface Ingress Error", 2832 "INT Metadata", 2833 }; 2834 2835 STATIC void 2836 _bcm_xgs5_telemetry_instnace_config_dump(int unit, 2837 bcm_telemetry_config_t *telemetry_config) 2838 { 2839 int i = 0; 2840 LOG_CLI((BSL_META("\t\tTelemetry instance component Id = %u\r\n"), 2841 telemetry_config->component_id)); 2842 LOG_CLI((BSL_META("\t\tTelemetry instance gport = %d\r\n"), 2843 telemetry_config->gport)); 2844 LOG_CLI((BSL_META_U(unit,"Telemetry port name = %s\r\n"), 2845 telemetry_config->port_name)); 2846 LOG_CLI((BSL_META_U(unit,"Object types configured: \r\n"))); 2847 for (i = 0;i<bcmTelemetryObjectTypeCount; i++) { 2848 LOG_CLI((BSL_META("\tObject type = %s\r\n"), 2849 _bcm_xgs5_telemetry_object_type_str[telemetry_config->object_type[i]])); 2850 } 2851 } 2852 2853 /* 2854 * Function: 2855 * _bcm_xgs5_telemetry_dump 2856 * Purpose: 2857 * Dump the telemetry info. 2858 * Parameters: 2859 * unit - (IN) BCM device number 2860 * telemetry_node - (IN) Telemetry information. 2861 * Returns: 2862 * Nothing 2863 */ 2864 STATIC void 2865 _bcm_xgs5_telemetry_instance_dump (int unit, 2866 _bcm_telemetry_instance_info_t *telemetry_instance_node) 2867 { 2868 int i = 0; 2869 2870 LOG_CLI((BSL_META("Telemetry instance ID = %d\r\n"), 2871 telemetry_instance_node->instance_id)); 2872 LOG_CLI((BSL_META("Telemetry instance core ID = %d\r\n"), 2873 telemetry_instance_node->core)); 2874 LOG_CLI((BSL_META("Telemetry instance config count = %d\r\n"), 2875 telemetry_instance_node->config_count)); 2876 for (i = 0;i<telemetry_instance_node->config_count; i++) { 2877 _bcm_xgs5_telemetry_instnace_config_dump(unit, 2878 &(telemetry_instance_node->telemetry_config[i])); 2879 2880 } 2881 LOG_CLI((BSL_META("Telemetry instance collector ID = %d\r\n"), 2882 telemetry_instance_node->collector_id)); 2883 LOG_CLI((BSL_META("Telemetry instance export profile ID = %d\r\n"), 2884 telemetry_instance_node->export_profile_id)); 2885 } 2886 2887 /* 2888 * Function: 2889 * _bcm_xgs5_telemetry_list_dump 2890 * Purpose: 2891 * Dump the telemetry list. 2892 * Parameters: 2893 * unit - (IN) BCM device number 2894 * Returns: 2895 * Nothing 2896 */ 2897 STATIC void 2898 _bcm_xgs5_telemetry_list_dump (int unit) 2899 { 2900 _bcm_telemetry_instance_info_t *telemetry_instance_node = NULL; 2901 int i; 2902 2903 if (telemetry_instances_info_list[unit] == NULL) { 2904 return; 2905 } 2906 2907 for (i = 0; 2908 i < BCM_INT_TELEMETRY_MAX_INSTANCES; i++) { 2909 telemetry_instance_node = &(telemetry_instances_info_list[unit][i]); 2910 if (telemetry_instance_node->instance_id != 2911 BCM_TELEMETRY_INVALID_INDEX) { 2912 _bcm_xgs5_telemetry_instance_dump(unit, telemetry_instance_node); 2913 } 2914 } 2915 } 2916 2917 /* Dump routine for dumping 2918 * telemetry list and export profile list. 2919 */ 2920 void _bcm_xgs5_telemetry_sw_dump(int unit) 2921 { 2922 _bcm_telemetry_global_info_t *telemetry_config_per_unit = NULL; 2923 2924 telemetry_config_per_unit = TELEMETRY_GLOBAL_INFO_GET(unit); 2925 2926 if (telemetry_config_per_unit == NULL) { 2927 return; 2928 } 2929 2930 LOG_CLI((BSL_META_U(unit,"Telemetry Global Info: \r\n"))); 2931 LOG_CLI((BSL_META_U(unit,"Telemetry System_id = %s\r\n"), 2932 telemetry_config_per_unit->system_id)); 2933 LOG_CLI((BSL_META_U(unit,"Telemetry System_id length = %u\r\n"), 2934 telemetry_config_per_unit->system_id_length)); 2935 LOG_CLI((BSL_META_U(unit,"Telemetry maximum packet size = %u\r\n"), 2936 telemetry_config_per_unit->max_pkt_size)); 2937 2938 _bcm_xgs5_telemetry_list_dump(unit); 2939 } 2940 2941 #else /* INCLUDE_TELEMETRY */ 2942 int _bcm_xgs5_telemetry_not_empty; 2943 #endif /* INCLUDE_TELEMETRY */