clock_init.c (28019B)
1 /* 2 * 3 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 4 * 5 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 6 * 7 * File: clock_init.c 8 * 9 * Purpose: 10 * 11 * Functions: 12 * bcm_common_ptp_clock_port_identity_get 13 * bcm_common_ptp_clock_create 14 */ 15 16 #if defined(INCLUDE_PTP) 17 18 #include <shared/bsl.h> 19 20 #include <soc/defs.h> 21 #include <soc/drv.h> 22 23 #include <bcm/ptp.h> 24 #include <bcm_int/common/ptp.h> 25 #include <bcm_int/ptp_common.h> 26 #include <bcm/error.h> 27 28 /* 29 * Function: 30 * bcm_common_ptp_clock_port_identity_get 31 * Purpose: 32 * Get port identity of a PTP clock port. 33 * Parameters: 34 * unit - (IN) Unit number. 35 * ptp_id - (IN) PTP stack ID. 36 * clock_num - (IN) PTP clock number. 37 * clock_port - (IN) PTP clock port number. 38 * identity - (OUT) PTP port identity. 39 * Returns: 40 * BCM_E_XXX 41 * Notes: 42 */ 43 int 44 bcm_common_ptp_clock_port_identity_get( 45 int unit, 46 bcm_ptp_stack_id_t ptp_id, 47 int clock_num, 48 uint32 clock_port, 49 bcm_ptp_port_identity_t *identity) 50 { 51 int rv = BCM_E_UNAVAIL; 52 53 bcm_ptp_clock_info_t ci; 54 55 if (BCM_FAILURE(rv = _bcm_ptp_function_precheck(unit, ptp_id, clock_num, 56 clock_port))) { 57 return rv; 58 } 59 60 if (BCM_FAILURE(rv = 61 _bcm_ptp_clock_cache_info_get(unit, ptp_id, clock_num, &ci))) { 62 return rv; 63 } 64 65 sal_memcpy(identity->clock_identity, 66 ci.clock_identity, 67 sizeof(bcm_ptp_clock_identity_t)); 68 69 identity->port_number = (uint16)clock_port; 70 71 return rv; 72 } 73 74 /* 75 * Function: 76 * bcm_common_ptp_clock_create 77 * Purpose: 78 * Create a PTP clock. 79 * Parameters: 80 * unit - (IN) Unit number. 81 * ptp_id - (IN) PTP stack ID. 82 * clock_info - (IN/OUT) PTP clock information. 83 * Returns: 84 * BCM_E_XXX 85 * Notes: 86 */ 87 int 88 bcm_common_ptp_clock_create( 89 int unit, 90 bcm_ptp_stack_id_t ptp_id, 91 bcm_ptp_clock_info_t *clock_info) 92 { 93 int rv = BCM_E_UNAVAIL; 94 95 uint8 payload[PTP_MGMTMSG_PAYLOAD_CLOCK_INSTANCE_SIZE_OCTETS]= {0}; 96 uint8 resp[PTP_MGMTMSG_RESP_MAX_SIZE_OCTETS]; 97 int resp_len= PTP_MGMTMSG_RESP_MAX_SIZE_OCTETS; 98 int i= 0; 99 100 _bcm_ptp_info_t *ptp_info_p; 101 bcm_ptp_port_identity_t portid; 102 _bcm_ptp_clock_cache_t *clock_cache; 103 int clock_max_num_ports; 104 uint8 profile_type; 105 106 bcm_ptp_telecom_g8265_network_option_t telecom_network_option = 107 bcm_ptp_telecom_g8265_network_option_disable; 108 109 sal_sleep(1); 110 111 if (soc_feature(unit, soc_feature_ptp)) { 112 rv = BCM_E_NONE; 113 114 rv = bcm_common_ptp_lock(unit); 115 if (BCM_FAILURE(rv)) { 116 return rv; 117 } 118 119 SET_PTP_INFO; 120 121 if (ptp_info_p->memstate != PTP_MEMSTATE_INITIALIZED) { 122 return BCM_E_PARAM; 123 } 124 125 126 #if 0 127 if (clock_info->flags & BCM_PTP_CLOCK_WITH_ID) { 128 if (clock_info->clock_num > PTP_MAX_CLOCKS_PER_STACK) { 129 return BCM_E_PARAM; 130 } 131 132 }else { 133 if (clock_info->clock_num >= PTP_MAX_CLOCKS_PER_STACK) { 134 return BCM_E_PARAM; 135 } 136 } 137 #else 138 clock_info->clock_num = 0; 139 #endif 140 141 /* Clock type and port number checks. */ 142 switch (clock_info->type) { 143 case bcmPTPClockTypeOrdinary: 144 if (clock_info->num_ports != 1) { 145 /* Too few / too many ports. */ 146 return BCM_E_PARAM; 147 } 148 break; 149 150 case bcmPTPClockTypeBoundary: 151 if ((clock_info->num_ports < 1) || 152 (clock_info->num_ports > PTP_MAX_CLOCK_INSTANCE_PORTS)) { 153 /* Too few / too many ports. */ 154 return BCM_E_PARAM; 155 } 156 break; 157 158 case bcmPTPClockTypeTransparent: 159 /* Fall through (v1.2.0 firmware does not support transparent clocks). */ 160 default: 161 /* Invalid/unknown clock type. */ 162 return BCM_E_UNAVAIL; 163 } 164 165 profile_type = ((clock_info->flags >> 8) & 0x0F); 166 if (profile_type >= e_PtpProfType_None) { 167 /* check for invalid profile type values */ 168 return BCM_E_PARAM; 169 } 170 171 /* Parameter extrema checking. */ 172 if ((clock_info->announce_receipt_timeout_minimum < 173 PTP_CLOCK_PRESETS_ANNOUNCE_RECEIPT_TIMEOUT_MINIMUM) || 174 (clock_info->announce_receipt_timeout_maximum > 175 PTP_CLOCK_PRESETS_ANNOUNCE_RECEIPT_TIMEOUT_MAXIMUM)) { 176 /* Caller provided (min,max) exceed allowable value(s). */ 177 return BCM_E_PARAM; 178 } 179 180 if (SHR_BITGET(&(clock_info->flags), PTP_CLOCK_FLAGS_TELECOM_PROFILE_BIT)) { 181 182 if ( e_PtpProfType_8265p1 != profile_type) { 183 /* Clock can only be configured for either telecom freq or phase profile */ 184 return BCM_E_PARAM; 185 } 186 187 /* Telecom profile. */ 188 if ((clock_info->log_announce_interval_minimum < 189 PTP_CLOCK_PRESETS_TELECOM_LOG_ANNOUNCE_INTERVAL_MINIMUM) || 190 (clock_info->log_announce_interval_maximum > 191 PTP_CLOCK_PRESETS_TELECOM_LOG_ANNOUNCE_INTERVAL_MAXIMUM)) { 192 /* Caller provided (min,max) exceed allowable value(s). */ 193 return BCM_E_PARAM; 194 } 195 196 if ((clock_info->log_sync_interval_minimum < 197 PTP_CLOCK_PRESETS_TELECOM_LOG_SYNC_INTERVAL_MINIMUM) || 198 (clock_info->log_sync_interval_maximum > 199 PTP_CLOCK_PRESETS_TELECOM_LOG_SYNC_INTERVAL_MAXIMUM)) { 200 /* Caller provided (min,max) exceed allowable value(s). */ 201 return BCM_E_PARAM; 202 } 203 204 if ((clock_info->log_min_delay_req_interval_minimum < 205 PTP_CLOCK_PRESETS_TELECOM_LOG_MIN_DELAY_REQ_INTERVAL_MINIMUM) || 206 (clock_info->log_min_delay_req_interval_maximum > 207 PTP_CLOCK_PRESETS_TELECOM_LOG_MIN_DELAY_REQ_INTERVAL_MAXIMUM)) { 208 /* Caller provided (min,max) exceed allowable value(s). */ 209 return BCM_E_PARAM; 210 } 211 212 if ((clock_info->domain_number_minimum < 213 PTP_CLOCK_PRESETS_TELECOM_DOMAIN_NUMBER_MINIMUM) || 214 (clock_info->domain_number_maximum > 215 PTP_CLOCK_PRESETS_TELECOM_DOMAIN_NUMBER_MAXIMUM)) { 216 /* Caller provided (min,max) exceed allowable value(s). */ 217 return BCM_E_PARAM; 218 } 219 } else if(e_PtpProfType_8275p1 == profile_type) { 220 /* Telecom profile for phase - ITU-T 8275.1. */ 221 222 if ((clock_info->domain_number_minimum < 223 PTP_CLOCK_PRESETS_TELECOM_PHASE_DOMAIN_NUMBER_MINIMUM) || 224 (clock_info->domain_number_maximum > 225 PTP_CLOCK_PRESETS_TELECOM_PHASE_DOMAIN_NUMBER_MAXIMUM)) { 226 /* Caller provided (min,max) exceed allowable value(s). */ 227 return BCM_E_PARAM; 228 } 229 230 if (0 == clock_info->local_priority) { 231 /* local priority shall be between 1 and 255*/ 232 return BCM_E_PARAM; 233 } 234 235 if ( clock_info->slaveonly && 236 (PTP_CLOCK_PRESETS_TELECOM_PHASE_PRIORITY2_TSC_DEFAULT != clock_info->priority2)) { 237 /* priority2 for Telecom-Slave clock shall be 255*/ 238 return BCM_E_PARAM; 239 } 240 241 if ((clock_info->flags) & (1u << PTP_CLOCK_FLAGS_ONEWAY_BIT)) 242 { 243 /* 8275.1 supports only 2-way operation */ 244 return BCM_E_PARAM; 245 } 246 } else if(e_PtpProfType_8275p2 == profile_type) { 247 /* Telecom profile for phase - ITU-T 8275.2. */ 248 249 if ((clock_info->domain_number_minimum < 250 PTP_CLOCK_PRESETS_G8275P2_DOMAIN_NUMBER_MINIMUM) || 251 (clock_info->domain_number_maximum > 252 PTP_CLOCK_PRESETS_G8275P2_DOMAIN_NUMBER_MAXIMUM)) { 253 /* Caller provided (min,max) exceed allowable value(s). */ 254 return BCM_E_PARAM; 255 } 256 257 if (0 == clock_info->local_priority) { 258 /* local priority shall be between 1 and 255*/ 259 return BCM_E_PARAM; 260 } 261 262 if ( clock_info->slaveonly && 263 (PTP_CLOCK_PRESETS_G8275P2_PRIORITY2_TSC_DEFAULT != clock_info->priority2)) { 264 /* priority2 for Telecom-Slave clock shall be 255*/ 265 return BCM_E_PARAM; 266 } 267 } else { 268 /* Standard profile. */ 269 if ((clock_info->log_announce_interval_minimum < 270 PTP_CLOCK_PRESETS_LOG_ANNOUNCE_INTERVAL_MINIMUM) || 271 (clock_info->log_announce_interval_maximum > 272 PTP_CLOCK_PRESETS_LOG_ANNOUNCE_INTERVAL_MAXIMUM)) { 273 /* Caller provided (min,max) exceed allowable value(s). */ 274 return BCM_E_PARAM; 275 } 276 277 if ((clock_info->log_sync_interval_minimum < 278 PTP_CLOCK_PRESETS_LOG_SYNC_INTERVAL_MINIMUM) || 279 (clock_info->log_sync_interval_maximum > 280 PTP_CLOCK_PRESETS_LOG_SYNC_INTERVAL_MAXIMUM)) { 281 /* Caller provided (min,max) exceed allowable value(s). */ 282 return BCM_E_PARAM; 283 } 284 285 if ((clock_info->log_min_delay_req_interval_minimum < 286 PTP_CLOCK_PRESETS_LOG_MIN_DELAY_REQ_INTERVAL_MINIMUM) || 287 (clock_info->log_min_delay_req_interval_maximum > 288 PTP_CLOCK_PRESETS_LOG_MIN_DELAY_REQ_INTERVAL_MAXIMUM)) { 289 /* Caller provided (min,max) exceed allowable value(s). */ 290 return BCM_E_PARAM; 291 } 292 } 293 294 /* DEFAULT clock configuration PTP attribute checking. */ 295 if ((clock_info->announce_receipt_timeout_default < 296 clock_info->announce_receipt_timeout_minimum) || 297 (clock_info->announce_receipt_timeout_default> 298 clock_info->announce_receipt_timeout_maximum)) { 299 /* Caller provided default value is not in (min,max) range. */ 300 return BCM_E_PARAM; 301 } 302 303 if ((clock_info->log_announce_interval_default < 304 clock_info->log_announce_interval_minimum) || 305 (clock_info->log_announce_interval_default > 306 clock_info->log_announce_interval_maximum)) { 307 /* Caller provided default value is not in (min,max) range. */ 308 return BCM_E_PARAM; 309 } 310 311 if ((clock_info->log_sync_interval_default < 312 clock_info->log_sync_interval_minimum) || 313 (clock_info->log_sync_interval_default > 314 clock_info->log_sync_interval_maximum)) { 315 /* Caller provided default value is not in (min,max) range. */ 316 return BCM_E_PARAM; 317 } 318 319 if ((clock_info->log_min_delay_req_interval_default < 320 clock_info->log_min_delay_req_interval_minimum) || 321 (clock_info->log_min_delay_req_interval_default > 322 clock_info->log_min_delay_req_interval_maximum)) { 323 /* Caller provided default value is not in (min,max) range. */ 324 return BCM_E_PARAM; 325 } 326 327 if ((clock_info->domain_number_default < 328 clock_info->domain_number_minimum) || 329 (clock_info->domain_number_default > 330 clock_info->domain_number_maximum)) 331 { 332 /* Caller provided default value is not in (min,max) range. */ 333 return BCM_E_PARAM; 334 } 335 336 if ((clock_info->priority1_default < clock_info->priority1_minimum) || 337 (clock_info->priority1_default > clock_info->priority1_maximum)) { 338 /* Caller provided default value is not in (min,max) range. */ 339 return BCM_E_PARAM; 340 } 341 342 if ((clock_info->priority2_default < clock_info->priority2_minimum) || 343 (clock_info->priority2_default > clock_info->priority2_maximum)) { 344 /* Caller provided default value is not in (min,max) range. */ 345 return BCM_E_PARAM; 346 } 347 348 /* CURRENT clock configuration PTP attribute checking. */ 349 if ((clock_info->domain_number < clock_info->domain_number_minimum) || 350 (clock_info->domain_number > clock_info->domain_number_maximum)) { 351 /* Caller provided current value is not in (min,max) range. */ 352 return BCM_E_PARAM; 353 } 354 355 if ((clock_info->priority1< clock_info->priority1_minimum) || 356 (clock_info->priority1> clock_info->priority1_maximum)) { 357 /* Caller provided current value is not in (min,max) range. */ 358 return BCM_E_PARAM; 359 } 360 361 if ((clock_info->priority2< clock_info->priority2_minimum) || 362 (clock_info->priority2> clock_info->priority2_maximum)) { 363 /* Caller provided current value is not in (min,max) range. */ 364 return BCM_E_PARAM; 365 } 366 367 /* Set clock flags based on active PTP profile. */ 368 if (SHR_BITGET(&(clock_info->flags), PTP_CLOCK_FLAGS_TELECOM_PROFILE_BIT)) { 369 SHR_BITSET(&(clock_info->flags), PTP_CLOCK_FLAGS_DELREQ_ALTMASTER_BIT); 370 } 371 372 /* If this is the first initialization, the passed-in num ports will be the max for this clock */ 373 clock_max_num_ports = clock_info->num_ports; 374 375 /* Assign PTP clock information to cache. */ 376 if (_bcm_common_ptp_unit_array[unit].stack_array[ptp_id].memstate != PTP_MEMSTATE_INITIALIZED) { 377 return BCM_E_PARAM; 378 } 379 clock_cache = &_bcm_common_ptp_unit_array[unit].stack_array[ptp_id].clock_array[clock_info->clock_num]; 380 381 if (clock_cache->in_use) { 382 /* reconfiguration. Don't allow the number of ports to exceed the initial config */ 383 if (clock_info->num_ports > clock_cache->max_num_ports) { 384 LOG_ERROR(BSL_LS_BCM_COMMON, 385 (BSL_META_U(unit, 386 "Clock reconfiguration with %d ports exceeds initial number (%d)\n"), 387 clock_info->num_ports, clock_cache->max_num_ports)); 388 return BCM_E_PARAM; 389 } 390 391 /* Keep the original number of ports as the max */ 392 clock_max_num_ports = clock_cache->max_num_ports; 393 394 #ifdef BCM_PTP_EXT_SERVO_SUPPORT 395 if (BCM_FAILURE(rv = _bcm_ptp_servo_deinit(unit, ptp_id, PTP_CLOCK_NUMBER_DEFAULT))) { 396 PTP_ERROR_FUNC("bcm_common_ptp_clock_create()"); 397 return BCM_E_INTERNAL; 398 } 399 #endif /* BCM_PTP_EXT_SERVO_SUPPORT */ 400 401 } 402 403 if (BCM_FAILURE(rv = _bcm_ptp_clock_cache_info_create( 404 unit, ptp_id, clock_info->clock_num))) { 405 return rv; 406 } 407 408 /* Set initially configured number of ports, as the upper limit for reconfiguration */ 409 clock_cache->max_num_ports = clock_max_num_ports; 410 clock_cache->in_use = 1; 411 412 clock_cache->clock_info = *clock_info; 413 414 #ifdef BCM_PTP_EXT_SERVO_SUPPORT 415 /* Set Servo to 3rd-party servo by Default*/ 416 clock_cache->servo_type = bcmPTPServoTypeExt; 417 /* PTPPP firmware supports only bcm servo */ 418 if (BCM_SUCCESS(rv = _bcm_ptp_check_firmware_exist("PTP_BRCM_SERVO"))) { 419 if (e_PtpProfType_8275p2 == profile_type) { 420 return BCM_E_PARAM; 421 } 422 clock_cache->servo_type = bcmPTPServoTypeBCM; 423 } 424 #endif /* BCM_PTP_EXT_SERVO_SUPPORT */ 425 if (BCM_FAILURE(rv = bcm_common_ptp_clock_port_identity_get(unit, ptp_id, 426 clock_info->clock_num, PTP_IEEE1588_ALL_PORTS, &portid))) { 427 return rv; 428 } 429 430 /* Create the PTP management data for the PTP clock. */ 431 if (BCM_FAILURE(rv = _bcm_ptp_management_clock_create(unit, ptp_id, clock_info->clock_num))) { 432 return rv; 433 } 434 435 /* 436 * Make payload. 437 * Octet 0...2 : Custom management message key/identifier. 438 * Octet 0= 'B'; Octet 1= 'C'; Octet 2= 'M'. 439 * Octet 3...5 : Reserved. 440 * Octet 6 : Instance. 441 * Octet 7 : Clock type. 442 * Octet 8...9 : Number of ports. 443 * Octet 10 : Clock class. 444 * Octet 11 : PTP domain. 445 * Octet 12...13 : Scaled log variance. 446 * Octet 14 : Priority1. 447 * Octet 15 : Priority2. 448 * Octet 16 : Slave-Only (SO) Boolean. 449 * Octet 17 : Transparent clock primary domain. 450 * Octet 18 : Transparent clock delay mechanism. 451 * Octet 19 : Log announce interval (MINIMUM). 452 * Octet 20 : Log announce interval (DEFAULT). 453 * Octet 21 : Log announce interval (MAXIMUM). 454 * Octet 22 : Announce receipt timeout (MINIMUM). 455 * Octet 23 : Announce receipt timeout (DEFAULT). 456 * Octet 24 : Announce receipt timeout (MAXIMUM). 457 * Octet 25 : Log sync interval (MINIMUM). 458 * Octet 26 : Log sync interval (DEFAULT). 459 * Octet 27 : Log sync interval (MAXIMUM). 460 * Octet 28 : Log min PDelay request interval (MININUM) or 461 * log min delay request interval (MINIMUM). 462 * Octet 29 : Log min PDelay request interval (DEFAULT) or 463 * log min delay request interval (DEFAULT). 464 * Octet 30 : Log min PDelay request interval (MAXIMUM) or 465 * log min delay request interval (MAXIMUM). 466 * Octet 31 : PTP domain number (MINIMUM). 467 * Octet 32 : PTP domain number (DEFAULT). 468 * Octet 33 : PTP domain number (MAXIMUM). 469 * Octet 34 : Priority1 (MINIMUM). 470 * Octet 35 : Priority1 (DEFAULT). 471 * Octet 36 : Priority1 (MAXIMUM). 472 * Octet 37 : Priority2 (MINIMUM). 473 * Octet 38 : Priority2 (DEFAULT). 474 * Octet 39 : Priority2 (MAXIMUM). 475 * Octet 40 : Flags 476 * Octet 41-42 : Max Unicast Master table size. 477 * Octet 43-44 : Max Acceptable Master table size. 478 * Octet 45-46 : Max Unicast Slave table size. 479 * Octet 47-48 : Max MC slaves (for peer data) 480 * Octet 49 : local_priority of the clock 481 * Octet 50 : profile type 482 * Octet 51 : res 483 * Octet 52-55 : holdover_in_spec_secs 484 */ 485 i = 0; 486 payload[i++] = 'B'; 487 payload[i++] = 'C'; 488 payload[i++] = 'M'; 489 i += 3; 490 491 payload[i++] = clock_info->clock_num; 492 payload[i++] = clock_info->type; 493 494 _bcm_ptp_uint16_write(payload+i, clock_info->num_ports); 495 i += sizeof(uint16); 496 497 payload[i++] = clock_info->clock_class; 498 payload[i++] = clock_info->domain_number; 499 500 _bcm_ptp_uint16_write(payload+i, clock_info->scaled_log_variance); 501 i += sizeof(uint16); 502 503 payload[i++] = clock_info->priority1; 504 payload[i++] = clock_info->priority2; 505 payload[i++] = clock_info->slaveonly & 1; 506 507 payload[i++] = clock_info->tc_primary_domain; 508 payload[i++] = clock_info->tc_delay_mechanism; 509 510 payload[i++] = clock_info->log_announce_interval_minimum; 511 payload[i++] = clock_info->log_announce_interval_default; 512 payload[i++] = clock_info->log_announce_interval_maximum; 513 514 payload[i++] = clock_info->announce_receipt_timeout_minimum; 515 payload[i++] = clock_info->announce_receipt_timeout_default; 516 payload[i++] = clock_info->announce_receipt_timeout_maximum; 517 518 payload[i++] = clock_info->log_sync_interval_minimum; 519 payload[i++] = clock_info->log_sync_interval_default; 520 payload[i++] = clock_info->log_sync_interval_maximum; 521 522 payload[i++] = clock_info->log_min_delay_req_interval_minimum; 523 payload[i++] = clock_info->log_min_delay_req_interval_default; 524 payload[i++] = clock_info->log_min_delay_req_interval_maximum; 525 526 payload[i++] = clock_info->domain_number_minimum; 527 payload[i++] = clock_info->domain_number_default; 528 payload[i++] = clock_info->domain_number_maximum; 529 530 payload[i++] = clock_info->priority1_minimum; 531 payload[i++] = clock_info->priority1_default; 532 payload[i++] = clock_info->priority1_maximum; 533 534 payload[i++] = clock_info->priority2_minimum; 535 payload[i++] = clock_info->priority2_default; 536 payload[i++] = clock_info->priority2_maximum; 537 538 { 539 /* Note: this relies on the firmware using bits 0-6 to represent 540 the same as 1-7 of the passed-in structure. Is correct for now, 541 but may need more logic in future */ 542 uint8 passed_flags = (clock_info->flags >> 1); 543 payload[i++] = passed_flags; 544 } 545 546 _bcm_ptp_uint16_write(payload+i, ptp_info_p->stack_info->unicast_master_table_size); 547 i += sizeof(uint16); 548 549 _bcm_ptp_uint16_write(payload+i, ptp_info_p->stack_info->acceptable_master_table_size); 550 i += sizeof(uint16); 551 552 _bcm_ptp_uint16_write(payload+i, ptp_info_p->stack_info->unicast_slave_table_size); 553 i += sizeof(uint16); 554 555 _bcm_ptp_uint16_write(payload+i, ptp_info_p->stack_info->multicast_slave_stats_size); 556 i += sizeof(uint16); 557 558 payload[i++] = clock_info->local_priority; 559 560 profile_type = ((clock_info->flags >> 8) & 0x0F); 561 payload[i++] = profile_type; 562 i++; /* Skip Reserve */ 563 if(e_PtpProfType_8275p1 == profile_type || e_PtpProfType_8275p2 == profile_type) { 564 _bcm_ptp_uint32_write(payload+i, clock_info->holdover_in_spec_secs); 565 i += sizeof(uint32); 566 } 567 568 if (BCM_FAILURE(rv = _bcm_ptp_management_message_send(unit, ptp_id, 569 clock_info->clock_num, &portid, 570 PTP_MGMTMSG_SET, PTP_MGMTMSG_ID_CREATE_CLOCK_INSTANCE, 571 payload, PTP_MGMTMSG_PAYLOAD_CLOCK_INSTANCE_SIZE_OCTETS, 572 resp, &resp_len))) { 573 574 return rv; 575 } 576 577 /* 578 * Register domain with PTP management framework. 579 * Ensure subsequent management messages are configured with proper 580 * domain. 581 */ 582 if (BCM_FAILURE(rv = _bcm_ptp_management_domain_set(unit, ptp_id, 583 clock_info->clock_num, clock_info->domain_number))) { 584 return rv; 585 } 586 587 /* Create a unicast master table for the PTP clock. */ 588 if (BCM_FAILURE(rv = _bcm_ptp_unicast_master_table_clock_create(unit, 589 ptp_id, clock_info->clock_num))) { 590 return rv; 591 } 592 593 /* Create unicast slave tables for the PTP clock ports. */ 594 if (BCM_FAILURE(rv = _bcm_ptp_unicast_slave_table_clock_create(unit, 595 ptp_id, clock_info->clock_num))) { 596 return rv; 597 } 598 599 /* Create an acceptable master table for the PTP clock. */ 600 if (BCM_FAILURE(rv = _bcm_ptp_acceptable_master_table_clock_create(unit, 601 ptp_id, clock_info->clock_num))) { 602 return rv; 603 } 604 605 /* 606 * Telecom profile support. 607 * Enable/disable host-side telecom profile. 608 */ 609 if (SHR_BITGET(&(clock_info->flags), PTP_CLOCK_FLAGS_TELECOM_PROFILE_BIT)) { 610 telecom_network_option = PTP_TELECOM_NETWORKING_OPTION_DEFAULT; 611 } else { 612 telecom_network_option = bcm_ptp_telecom_g8265_network_option_disable; 613 } 614 615 if (BCM_FAILURE(rv = bcm_common_ptp_telecom_g8265_network_option_set(unit, ptp_id, 616 clock_info->clock_num, telecom_network_option))) { 617 return rv; 618 } 619 620 if(e_PtpProfType_8275p1 == profile_type) { 621 /* G.8275.1 ptpTimescale compliance as per Table A.4,A.6,V.2 and V.3 */ 622 /* Note: clockClass check is not done before enabling ptpTimescale as TRUE */ 623 bcm_ptp_timescale_t timescale; 624 /* Get the default configured ptpTimescale property */ 625 if (BCM_FAILURE(rv = bcm_ptp_clock_timescale_get(unit,ptp_id, clock_info->clock_num,×cale))) { 626 return rv; 627 } 628 629 /* Set the ptpTimescale property according to G.8275.1 default value */ 630 timescale.ptp_timescale = TRUE; 631 632 if (BCM_FAILURE(rv = bcm_ptp_clock_timescale_set(unit,ptp_id, clock_info->clock_num,×cale))) { 633 return rv; 634 } 635 636 if (BCM_FAILURE(rv = bcm_ptp_clock_max_steps_removed_set(unit,ptp_id, clock_info->clock_num, clock_info->max_steps_removed))) { 637 PTP_ERROR_FUNC("bcm_ptp_clock_max_steps_removed_set()"); 638 return rv; 639 } 640 #ifdef BCM_PTP_EXT_SERVO_SUPPORT 641 /* Set Servo to BCM for G.8275.1 profile */ 642 clock_cache->servo_type = bcmPTPServoTypeBCM; 643 #endif /* BCM_PTP_EXT_SERVO_SUPPORT */ 644 } else { 645 if(e_PtpProfType_8275p2 == profile_type) { 646 /* G.8275.2 ptpTimescale compliance as per Table A.4,A.6,V.2 and V.3 */ 647 /* Note: clockClass check is not done before enabling ptpTimescale as TRUE */ 648 bcm_ptp_timescale_t timescale; 649 bcm_ptp_clock_accuracy_t accuracy; 650 /* Get the default configured ptpTimescale property */ 651 if (BCM_FAILURE(rv = bcm_ptp_clock_timescale_get(unit,ptp_id, clock_info->clock_num,×cale))) { 652 return rv; 653 } 654 655 /* Set the ptpTimescale property according to G.8275.2 default value */ 656 timescale.ptp_timescale = TRUE; 657 658 if (BCM_FAILURE(rv = bcm_ptp_clock_timescale_set(unit,ptp_id, clock_info->clock_num,×cale))) { 659 return rv; 660 } 661 accuracy = 0xFE; 662 if (BCM_FAILURE(rv = bcm_ptp_clock_accuracy_set(unit,ptp_id, clock_info->clock_num, &accuracy))) { 663 return rv; 664 } 665 } 666 #ifdef BCM_PTP_EXT_SERVO_SUPPORT 667 LOG_VERBOSE(BSL_LS_BCM_PTP, 668 (BSL_META_U(unit, "Initializing 3rd party servo ... \n"))); 669 _bcm_ptp_servo_init(unit, ptp_id, clock_info->clock_num, bcmPTPOscTypeOCXO); 670 #endif /* BCM_PTP_EXT_SERVO_SUPPORT */ 671 } 672 673 /* Modular system support */ 674 if (BCM_FAILURE(rv = _bcm_ptp_modular_init(unit, ptp_id, clock_info->clock_num, 0))) { 675 return rv; 676 } 677 678 /* On Katana, there is a default 1PPS output on TSGPIO1, so set that up: */ 679 if (SOC_HAS_PTP_INTERNAL_STACK_SUPPORT(unit)) { 680 bcm_ptp_signal_output_t signal; 681 int signal_id = 0; 682 signal.pin = 1; 683 signal.frequency = 1; 684 signal.phase_lock = 1; 685 signal.pulse_width_ns = 100000000; 686 signal.pulse_offset_ns = 0; 687 688 if (BCM_FAILURE(rv = bcm_common_ptp_signal_output_set(unit, ptp_id, 689 clock_info->clock_num, 690 &signal_id, &signal))) { 691 return rv; 692 } 693 } 694 695 BCM_IF_ERROR_RETURN(bcm_common_ptp_unlock(unit)); 696 } 697 698 return rv; 699 } 700 #endif /* defined(INCLUDE_PTP)*/ 701