time.h (21089B)
1 /* 2 * 3 * 4 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 5 * 6 * Copyright 2007-2020 Broadcom Inc. All rights reserved. 7 * 8 * DO NOT EDIT THIS FILE! 9 * This file is auto-generated. 10 * Edits to this file will be lost when it is regenerated. 11 */ 12 13 #ifndef __BCM_TIME_H__ 14 #define __BCM_TIME_H__ 15 16 #include <bcm/types.h> 17 18 /* Time Interface Identifier. */ 19 typedef int bcm_time_if_t; 20 21 #define BCM_TIME_ENABLE 0x00000001 /* Enable Time Synchronization 22 Interface */ 23 #define BCM_TIME_WITH_ID 0x00000002 /* Create/Update interface with valid 24 identifier in the structure */ 25 #define BCM_TIME_REPLACE 0x00000004 /* Replace current interface settings 26 according to flags provided */ 27 #define BCM_TIME_INPUT 0x00000008 /* Current interface will recieve a 28 time sync messages (Act as slave) */ 29 #define BCM_TIME_DRIFT 0x00000020 /* To set/get the drift parameter for 30 Interface */ 31 #define BCM_TIME_OFFSET 0x00000040 /* To set/get the offset parameter 32 for Interface */ 33 #define BCM_TIME_ACCURACY 0x00000080 /* To set/get the accuracy parameter 34 for Interface */ 35 #define BCM_TIME_HEARTBEAT 0x00000100 /* To set the heartbeat frequency for 36 Interface */ 37 #define BCM_TIME_LOCKED 0x00000200 /* To indicate that interface is 38 locked on a grand master's clock */ 39 #define BCM_TIME_REF_CLOCK 0x00000400 /* Enable Reference clock */ 40 #define BCM_TIME_SYNC_STAMPER 0x00000800 /* Enable BroadSync timestamper sync 41 support */ 42 #define BCM_TIME_NTP_OFFSET 0x000001000 /* To set/get the ntp offset 43 parameter for Interface */ 44 #define BCM_TIME_BS_TIME 0x000002000 /* set UTC time or system time for 45 BroadSync Master */ 46 47 /* BroadSync Time Source Status. */ 48 typedef enum bcm_bs_time_source_e { 49 bcmBsTimeSourceNotLocked = 0, /* No time-code received, Holdover mode 50 or Not Locked */ 51 bcmBsTimeSourceAcquiring = 1, /* Acquiring state */ 52 bcmBsTimeSourceExcessiveJitter = 2, /* Acquiring state but locked with 53 excessive jitter */ 54 bcmBsTimeSourceLocked = 3 /* Locked State */ 55 } bcm_bs_time_source_t; 56 57 /* Base time structure. */ 58 typedef struct bcm_time_interface_s { 59 uint32 flags; /* Flags BCM_TIME_* */ 60 bcm_time_if_t id; /* Time Interface Identifier */ 61 bcm_time_spec_t drift; /* Drift amount per 1 Sec */ 62 bcm_time_spec_t offset; /* Offset */ 63 bcm_time_spec_t accuracy; /* Accuracy */ 64 int heartbeat_hz; /* HeartBeat Rate */ 65 int clk_resolution; /* Reference clock resolution in nsecs */ 66 int bitclock_hz; /* BitClock frequency */ 67 bcm_bs_time_source_t status; /* BroadSync Time Source Status */ 68 bcm_time_spec_t ntp_offset; /* NTP Offset */ 69 bcm_time_spec_t bs_time; /* UTC time or system time for BroadSync 70 Master */ 71 } bcm_time_interface_t; 72 73 #define BCM_TIME_CAPTURE_LOCKED 0x00000001 /* Captured Time is 74 synchronized with 75 Grand Master */ 76 #define BCM_TIME_CAPTURE_GPIO_0 0x00000002 /* Capture Time at rising 77 edge of GPIO 0 */ 78 #define BCM_TIME_CAPTURE_GPIO_1 0x00000004 /* Capture Time at rising 79 edge of GPIO 1 */ 80 #define BCM_TIME_CAPTURE_GPIO_2 0x00000008 /* Capture Time at rising 81 edge of GPIO 2 */ 82 #define BCM_TIME_CAPTURE_GPIO_3 0x00000010 /* Capture Time at rising 83 edge of GPIO 3 */ 84 #define BCM_TIME_CAPTURE_GPIO_4 0x00000020 /* Capture Time at rising 85 edge of GPIO 4 */ 86 #define BCM_TIME_CAPTURE_GPIO_5 0x00000040 /* Capture Time at rising 87 edge of GPIO 5 */ 88 #define BCM_TIME_CAPTURE_L1_CLOCK_PRIMARY 0x00000080 /* Capture Time at rising 89 edge of primary L1 */ 90 #define BCM_TIME_CAPTURE_L1_CLOCK_SECONDARY 0x00000100 /* Capture Time at rising 91 edge of primary L2 */ 92 #define BCM_TIME_CAPTURE_LCPLL 0x00000200 /* Capture Time at rising 93 edge of LCPLL */ 94 #define BCM_TIME_CAPTURE_IP_DM_0 0x00000400 /* Capture Time at rising 95 edge of DM0 */ 96 #define BCM_TIME_CAPTURE_IP_DM_1 0x00000800 /* Capture Time at rising 97 edge of DM1 */ 98 #define BCM_TIME_CAPTURE_IMMEDIATE 0x00001000 /* Capture Immediate */ 99 #define BCM_TIME_CAPTURE_ALL 0x00002000 /* Capture Immediate */ 100 #define BCM_TIME_CAPTURE_BS0HB 0x00004000 /* Capture Time at rising 101 edge of Broadsync 0 */ 102 #define BCM_TIME_CAPTURE_BS1HB 0x00008000 /* Capture Time at rising 103 edge of Broadsync 1 */ 104 #define BCM_TIME_CAPTURE_TS1TS 0x00010000 /* Capture Time of TS1 105 event */ 106 #define BCM_TIME_CAPTURE_BS0PLL 0x00020000 /* Capture Time of rising 107 edge of Broadsync0 PL */ 108 #define BCM_TIME_CAPTURE_BS1PLL 0x00040000 /* Capture Time of rising 109 edge of Broadsync1 PL */ 110 #define BCM_TIME_CAPTURE_RSVD1IF 0x00080000 /* Capture Time of rising 111 edge of RSVD1 112 interfac */ 113 #define BCM_TIME_CAPTURE_RSVD1RF 0x00100000 /* Capture Time of rising 114 edge of RSVD2 counte */ 115 #define BCM_TIME_CAPTURE_BS0CONVTC 0x00200000 /* Capture Time of 116 Broadsync0 converted 117 timecode */ 118 #define BCM_TIME_CAPTURE_BS1CONVTC 0x00400000 /* Capture Time of 119 Broadsync1 converted 120 timecod */ 121 #define BCM_TIME_CAPTURE_LCPLL1 0x00800000 /* Capture Time at rising 122 edge of LCPLL1 */ 123 #define BCM_TIME_CAPTURE_LCPLL2 0x01000000 /* Capture Time at rising 124 edge of LCPLL2 */ 125 #define BCM_TIME_CAPTURE_LCPLL3 0x02000000 /* Capture Time at rising 126 edge of LCPLL3 */ 127 #define BCM_TIME_CAPTURE_PORT 0x04000000 /* Capture Time at port */ 128 129 /* Time port events */ 130 typedef enum bcm_time_port_event_e { 131 bcmTimePortEventRXSOF = 0, /* CPRI port recieve SOF input event */ 132 bcmTimePortEventTXSOF = 1, /* CPRI port transmit SOF input event */ 133 bcmTimePortEventROE = 2, /* CPRI ROE timestamp event */ 134 bcmTimePortEventRXCDR = 3, /* Port recieve CDR event */ 135 bcmTimePortEventTXPI = 4 /* Port TXPI event */ 136 } bcm_time_port_event_t; 137 138 /* Base time capture structure. */ 139 typedef struct bcm_time_capture_s { 140 uint32 flags; /* Flags BCM_TIME_CAPTURE_* */ 141 bcm_time_spec_t free; /* Free running clock */ 142 bcm_time_spec_t syntonous; /* Syntonous clock */ 143 bcm_time_spec_t synchronous; /* Synchronous clock */ 144 bcm_time_spec_t received; /* Received clock */ 145 bcm_time_spec_t received_accuracy; /* Received clock accuracy */ 146 bcm_port_t port; /* Port number */ 147 bcm_time_port_event_t port_event_type; /* Port related event type */ 148 uint32 event_divisor; /* Divisor value for a ts event */ 149 int ts_counter; /* Sample on TS0(0), TS1(1) */ 150 } bcm_time_capture_t; 151 152 /* SyncE Clock Source Type. */ 153 typedef enum bcm_time_synce_clock_src_type_e { 154 bcmTimeSynceClockSourcePrimary = 0, /* Primary Clock Source */ 155 bcmTimeSynceClockSourceSecondary = 1 /* Secondary Clock Source */ 156 } bcm_time_synce_clock_src_type_t; 157 158 /* SyncE Input Source Type. */ 159 typedef enum bcm_time_synce_input_src_type_e { 160 bcmTimeSynceInputSourceTypePort = 0, /* Input Source Port */ 161 bcmTimeSynceInputSourceTypePLL = 1 /* Input Source PLL */ 162 } bcm_time_synce_input_src_type_t; 163 164 /* SyncE Stage0 Mode. */ 165 typedef enum bcm_time_synce_stage0_mode_e { 166 bcmTimeSynceModeBypass = 0, /* Stage0 Mode Bypass */ 167 bcmTimeSynceModeGap45 = 1, /* Stage0 Mode GAP 4/5 */ 168 bcmTimeSynceModeSDMFracDiv = 2 /* Stage0 Mode SDM Frac Div */ 169 } bcm_time_synce_stage0_mode_t; 170 171 /* bcm_time_synce_stage1_div_e */ 172 typedef enum bcm_time_synce_stage1_div_e { 173 bcmTimeSynceStage1Div1 = 0, /* Stage1 Div1 */ 174 bcmTimeSynceStage1Div7 = 1, /* Stage1 Div7 */ 175 bcmTimeSynceStage1Div11 = 2 /* Stage1 Div11 */ 176 } bcm_time_synce_stage1_div_t; 177 178 /* Time Synce Divisor setting structure. */ 179 typedef struct bcm_time_synce_divisor_setting_s { 180 bcm_time_synce_input_src_type_t input_src; /* Input source type */ 181 uint32 index; /* Logical port number or PLL index */ 182 bcm_time_synce_stage0_mode_t stage0_mode; /* Stage0 Mode bcmTimeSynceMode* */ 183 uint32 stage0_sdm_whole; /* Stage0 SDM whole value */ 184 uint32 stage0_sdm_frac; /* Stage0 SDM frac value */ 185 bcm_time_synce_stage1_div_t stage1_div; /* Stage1 Div bcmTimeSynceStage1Div* */ 186 } bcm_time_synce_divisor_setting_t; 187 188 /* BS log configuration structure. */ 189 typedef struct bcm_time_bs_log_cfg_s { 190 uint32 debug_mask; /* mask indicating log level */ 191 uint64 udp_log_mask; /* mask indicating UDP log level */ 192 bcm_mac_t src_mac; /* Source MAC address */ 193 bcm_mac_t dest_mac; /* Destination MAC address */ 194 uint16 tpid; /* TPID */ 195 uint16 vid; /* VLAN ID */ 196 uint8 ttl; /* Time to live */ 197 bcm_ip_t src_addr; /* Source IP address */ 198 bcm_ip_t dest_addr; /* Destination IP address */ 199 uint16 udp_port; /* UDP port number */ 200 } bcm_time_bs_log_cfg_t; 201 202 #define BCM_BS_LOG_NONE 0x00000000 /* BS log level None */ 203 #define BCM_BS_LOG_SYS_INFO 0x00000001 /* BS log level info */ 204 #define BCM_BS_LOG_SYS_WARN 0x00000002 /* BS log level warning */ 205 #define BCM_BS_LOG_SYS_ERR 0x00000004 /* BS log level error */ 206 #define BCM_BS_LOG_SYS_CRIT 0x00000008 /* BS log level critical */ 207 #define BCM_BS_LOG_SYS_ALL 0x000000FF /* BS log level all */ 208 209 #ifndef BCM_HIDE_DISPATCHABLE 210 211 /* Configure BS log configuration */ 212 extern int bcm_time_bs_log_configure_set( 213 int unit, 214 bcm_time_bs_log_cfg_t bs_log_cfg); 215 216 /* Retrieves BS log configuration */ 217 extern int bcm_time_bs_log_configure_get( 218 int unit, 219 bcm_time_bs_log_cfg_t *bs_log_cfg); 220 221 /* Initialize time module */ 222 extern int bcm_time_init( 223 int unit); 224 225 /* Uninitialize time module */ 226 extern int bcm_time_deinit( 227 int unit); 228 229 #endif /* BCM_HIDE_DISPATCHABLE */ 230 231 /* Initialize bcm_time_spec_t structure */ 232 extern void bcm_time_spec_t_init( 233 bcm_time_spec_t *spec); 234 235 /* Initialize bcm_time_interface_t structure */ 236 extern void bcm_time_interface_t_init( 237 bcm_time_interface_t *intf); 238 239 /* Initialize bcm_time_capture_t structure */ 240 extern void bcm_time_capture_t_init( 241 bcm_time_capture_t *capture); 242 243 /* Initialize bcm_time_divisor_setting_t structure */ 244 extern void bcm_time_synce_divisor_setting_t_init( 245 bcm_time_synce_divisor_setting_t *divisor); 246 247 #ifndef BCM_HIDE_DISPATCHABLE 248 249 /* Add a time sync interfaces on a unit */ 250 extern int bcm_time_interface_add( 251 int unit, 252 bcm_time_interface_t *intf); 253 254 /* Get a time sync interfaces on a unit */ 255 extern int bcm_time_interface_get( 256 int unit, 257 bcm_time_interface_t *intf); 258 259 /* Delete a time sync interfaces on a unit */ 260 extern int bcm_time_interface_delete( 261 int unit, 262 bcm_time_if_t intf_id); 263 264 /* Delete all time sync interfaces on a unit */ 265 extern int bcm_time_interface_delete_all( 266 int unit); 267 268 #endif /* BCM_HIDE_DISPATCHABLE */ 269 270 /* bcm_time_interface_traverse_cb */ 271 typedef int (*bcm_time_interface_traverse_cb)( 272 int unit, 273 bcm_time_interface_t *intf, 274 void *user_data); 275 276 #ifndef BCM_HIDE_DISPATCHABLE 277 278 /* bcm_time_interface_traverse */ 279 extern int bcm_time_interface_traverse( 280 int unit, 281 bcm_time_interface_traverse_cb cb, 282 void *user_data); 283 284 /* Gets HW clocks capture */ 285 extern int bcm_time_capture_get( 286 int unit, 287 bcm_time_if_t intf_id, 288 bcm_time_capture_t *time); 289 290 #endif /* BCM_HIDE_DISPATCHABLE */ 291 292 /* bcm_time_heartbeat_cb */ 293 typedef int (*bcm_time_heartbeat_cb)( 294 int unit, 295 bcm_time_if_t id, 296 bcm_time_capture_t *time, 297 void *user_data); 298 299 #ifndef BCM_HIDE_DISPATCHABLE 300 301 /* Register callback function to be called on heartbeat */ 302 extern int bcm_time_heartbeat_register( 303 int unit, 304 bcm_time_if_t id, 305 bcm_time_heartbeat_cb f, 306 void *user_data); 307 308 /* Unregister callback function */ 309 extern int bcm_time_heartbeat_unregister( 310 int unit, 311 bcm_time_if_t id); 312 313 /* bcm_time_heartbeat_enable_set */ 314 extern int bcm_time_heartbeat_enable_set( 315 int unit, 316 bcm_time_if_t id, 317 int enable); 318 319 /* bcm_time_heartbeat_enable_get */ 320 extern int bcm_time_heartbeat_enable_get( 321 int unit, 322 bcm_time_if_t id, 323 int *enable); 324 325 /* bcm_time_trigger_enable_set */ 326 extern int bcm_time_trigger_enable_set( 327 int unit, 328 bcm_time_if_t id, 329 uint32 mode_flags); 330 331 /* bcm_time_trigger_enable_get */ 332 extern int bcm_time_trigger_enable_get( 333 int unit, 334 bcm_time_if_t id, 335 uint32 *mode_flags); 336 337 /* bcm_time_synce_clock_get */ 338 extern int bcm_time_synce_clock_get( 339 int unit, 340 bcm_time_synce_clock_src_type_t clk_src, 341 bcm_time_synce_divisor_setting_t *divisor_setting); 342 343 /* bcm_time_synce_clock_set */ 344 extern int bcm_time_synce_clock_set( 345 int unit, 346 bcm_time_synce_clock_src_type_t clk_src, 347 bcm_time_synce_divisor_setting_t *divisor_setting); 348 349 #endif /* BCM_HIDE_DISPATCHABLE */ 350 351 /* synce clock source config */ 352 typedef struct bcm_time_synce_clock_source_config_s { 353 bcm_time_synce_clock_src_type_t clk_src; /* Synce Clock Source Primary or 354 Secondary */ 355 bcm_time_synce_input_src_type_t input_src; /* Input source type Port or PLL */ 356 uint32 pll_index; /* PLL index */ 357 bcm_port_t port; /* Logical port number */ 358 } bcm_time_synce_clock_source_config_t; 359 360 /* bcm_time_synce_clock_source_control */ 361 typedef enum bcm_time_synce_clock_source_control_e { 362 bcmTimeSynceClockSourceControlSquelch = 0, /* Squelch of synce source */ 363 bcmTimeSynceClockSourceControlFrequency = 1 /* Frequency of synce source */ 364 } bcm_time_synce_clock_source_control_t; 365 366 /* SyncE Frequency */ 367 typedef enum bcm_time_synce_frequency_e { 368 bcmTimeSyncE23MHz = 1, /* TSCF - 23.4375 MHz */ 369 bcmTimeSyncE25MHz = 2, /* SDM - 25MHz */ 370 bcmTimeSyncE28MHz = 3, /* General - 28.4 MHz */ 371 bcmTimeSyncE46MHz = 4, /* General - 46.875 MHz */ 372 bcmTimeSyncE125MHz = 5, /* General - 125MHz */ 373 bcmTimeSyncE515MHz = 6, /* General - 515.625MHz */ 374 bcmTimeSyncE7MHz = 7, /* SDM - 7.8125 MHz */ 375 bcmTimeSyncE12MHz = 8, /* SDM - 12.5 MHz */ 376 bcmTimeSyncE31MHz = 9, /* SDM - 31.25 MHz */ 377 bcmTimeSyncE37MHz = 10 /* SDM - 37.5 MHz */ 378 } bcm_time_synce_frequency_t; 379 380 #ifndef BCM_HIDE_DISPATCHABLE 381 382 /* bcm_time_synce_clock_source_control_set */ 383 extern int bcm_time_synce_clock_source_control_set( 384 int unit, 385 bcm_time_synce_clock_source_config_t *clk_src_config, 386 bcm_time_synce_clock_source_control_t control, 387 int value); 388 389 /* bcm_time_synce_clock_source_control_get */ 390 extern int bcm_time_synce_clock_source_control_get( 391 int unit, 392 bcm_time_synce_clock_source_config_t *clk_src_config, 393 bcm_time_synce_clock_source_control_t control, 394 int *value); 395 396 /* Get Broadsync time on a unit */ 397 extern int bcm_time_bs_time_get( 398 int unit, 399 bcm_time_spec_t *bs_time); 400 401 #endif /* BCM_HIDE_DISPATCHABLE */ 402 403 /* Time formats */ 404 typedef enum bcm_time_format_e { 405 bcmTimeFormatPTP = 0, /* The time format is PTP. */ 406 bcmTimeFormatNTP = 1 /* The time format is NTP. */ 407 } bcm_time_format_t; 408 409 /* values to set initial counter in ts clock. */ 410 typedef struct bcm_time_ts_counter_s { 411 bcm_time_format_t time_format; /* Time format for counter */ 412 int enable; /* Enable/disable control for counter. */ 413 int ts_counter; /* TS0/TS1 counter. */ 414 uint64 ts_counter_ns; /* nanosecond value of counter. */ 415 } bcm_time_ts_counter_t; 416 417 /* Initialize counter structure for timestamping. */ 418 extern void bcm_time_ts_counter_t_init( 419 bcm_time_ts_counter_t *counter); 420 421 #ifndef BCM_HIDE_DISPATCHABLE 422 423 /* Set counter value for timestamping. */ 424 extern int bcm_time_ts_counter_set( 425 int unit, 426 bcm_time_ts_counter_t *counter); 427 428 /* Get counter value for timestamping. */ 429 extern int bcm_time_ts_counter_get( 430 int unit, 431 bcm_time_ts_counter_t *counter); 432 433 #endif /* BCM_HIDE_DISPATCHABLE */ 434 435 /* Time stamping stages. */ 436 #define BCM_TIME_STAGE_INGRESS_FLOWTRACKER (1 << 0) /* Ingress Flowtracker 437 stage for time 438 stamping. */ 439 #define BCM_TIME_STAGE_EGRESS (1 << 1) /* Egress stage for time 440 stamping. */ 441 #define BCM_TIME_STAGE_ALL (1 << 2) /* Timestamping will be 442 applied to all the 443 stages. */ 444 445 /* Structure for Time of the day values. */ 446 typedef struct bcm_time_tod_s { 447 bcm_time_format_t time_format; /* Time format for counter */ 448 bcm_time_spec_t ts; /* time of the day values. */ 449 uint64 ts_adjustment_counter_ns; /* tod value adjustment in nanoseconds. */ 450 } bcm_time_tod_t; 451 452 /* Initialize tod structure for timestamping. */ 453 extern void bcm_time_tod_t_init( 454 bcm_time_tod_t *tod); 455 456 #ifndef BCM_HIDE_DISPATCHABLE 457 458 /* Set time of the day values for various stages. */ 459 extern int bcm_time_tod_set( 460 int unit, 461 uint32 stages, 462 bcm_time_tod_t *tod); 463 464 /* Get time of the day values for various stages. */ 465 extern int bcm_time_tod_get( 466 int unit, 467 uint32 stages, 468 bcm_time_tod_t *tod); 469 470 #endif /* BCM_HIDE_DISPATCHABLE */ 471 472 /* Time capture callback types */ 473 typedef enum bcm_time_capture_cb_type_e { 474 bcmTimeCaptureOverflow = 0, /* Cb will be called only on overflow */ 475 bcmTimeCapturetFill = 1, /* Cb will be called only for ts events */ 476 bcmTimeCaptureAll = 2 /* Cb will be called for both overflow and ts 477 events */ 478 } bcm_time_capture_cb_type_t; 479 480 #ifndef BCM_HIDE_DISPATCHABLE 481 482 /* Enable/Disable FIFO timestamp capture for a particular event */ 483 extern int bcm_time_capture_enable_set( 484 int unit, 485 bcm_time_if_t id, 486 bcm_time_capture_t *time_capture, 487 int enable, 488 int *capture_handle); 489 490 #endif /* BCM_HIDE_DISPATCHABLE */ 491 492 /* Generic callback for time capture events */ 493 typedef int (*bcm_time_capture_cb)( 494 int unit, 495 void *user_data, 496 uint32 *cb_data, 497 bcm_time_capture_cb_type_t cb_status); 498 499 #ifndef BCM_HIDE_DISPATCHABLE 500 501 /* Register callback function for a given type */ 502 extern int bcm_time_capture_cb_register( 503 int unit, 504 bcm_time_if_t id, 505 bcm_time_capture_cb_type_t cb_type, 506 bcm_time_capture_cb cb, 507 void *user_data); 508 509 /* Un-register callback function for a given type */ 510 extern int bcm_time_capture_cb_unregister( 511 int unit, 512 bcm_time_if_t id, 513 bcm_time_capture_cb_type_t cb_type); 514 515 #endif /* BCM_HIDE_DISPATCHABLE */ 516 517 #endif /* __BCM_TIME_H__ */