time.h (13072B)
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 * This file contains Time Interface definitions internal to the BCM library. 8 */ 9 10 #ifndef _BCM_INT_COMMON_TIME_H 11 #define _BCM_INT_COMMON_TIME_H 12 13 #include <sal/core/sync.h> 14 15 16 /* Time module internal defines */ 17 #define TIME_EPOCH_MAX 0x7FFF /* Max epoch value allowed in HW */ 18 #define TIME_SEC_MAX 0xFFFFFFFF /* HW supports only 32 bits second */ 19 #define TIME_NANOSEC_MAX 1000000000 /* Max nanosec value is 10^9 */ 20 #define TIME_DRIFT_DENOMINATOR 1000000000 /* Drift denominator = 1 second */ 21 #define TIME_DRIFT_MAX TIME_DRIFT_DENOMINATOR / 8 22 23 #define TIME_ACCURACY_CLK_MAX 19 /* How many accuracy values we can have */ 24 25 #define TIME_MODE_INPUT 0x0 /* Time interface will recieve the time as input(Slave)*/ 26 #define TIME_MODE_OUTPUT 0x1 /* Time interface will output the time (Master)*/ 27 28 /* HELIX4 and KATANA2 capture mode bits */ 29 #define IPROC_TIME_CAPTURE_MODE_DISABLE 0x0 /* Disable HW time capture */ 30 #define IPROC_TIME_CAPTURE_MODE_IMMEDIATE 0x1 /* Capture time immediately on CPU request */ 31 #define IPROC_TIME_CAPTURE_MODE_HB_BS_0 0x2 /* Capture time on rising edge of heartbeat of BroadSync 0 */ 32 #define IPROC_TIME_CAPTURE_MODE_HB_BS_1 0x4 /* Capture time on rising edge of heartbeat of BroadSync 1 */ 33 #define IPROC_TIME_CAPTURE_MODE_GPIO_0 0x8 /* Capture time on GPIO event */ 34 #define IPROC_TIME_CAPTURE_MODE_GPIO_1 0x10 35 #define IPROC_TIME_CAPTURE_MODE_GPIO_2 0x20 36 #define IPROC_TIME_CAPTURE_MODE_GPIO_3 0x40 37 #define IPROC_TIME_CAPTURE_MODE_GPIO_4 0x80 38 #define IPROC_TIME_CAPTURE_MODE_GPIO_5 0x100 39 #define IPROC_TIME_CAPTURE_MODE_SYNCE_1 0x200 /* Capture on rising edge of SyncE clk_x event */ 40 #define IPROC_TIME_CAPTURE_MODE_SYNCE_2 0x400 41 #define IPROC_TIME_CAPTURE_MODE_SYNCE_3 0x800 42 #define IPROC_TIME_CAPTURE_MODE_SYNCE_4 0x1000 43 #define IPROC_TIME_CAPTURE_MODE_SYNCE_5 0x2000 44 #define IPROC_TIME_CAPTURE_MODE_IP_DM_0 0x4000 /* Capture on rising edge of IP_DM_x event */ 45 #define IPROC_TIME_CAPTURE_MODE_IP_DM_1 0x8000 46 #define IPROC_TIME_CAPTURE_MODE_TS1 0x10000 47 #define IPROC_TIME_CAPTURE_MODE_CLK_BS_0 0x20000 /* Capture on rising edge of Broadsync 0 clock event */ 48 #define IPROC_TIME_CAPTURE_MODE_CLK_BS_1 0x40000 /* Capture on rising edge of Broadsync 1 clock event */ 49 50 #define TIME_CAPTURE_MODE_DISABLE 0x0 /* Disable HW time capture */ 51 #define TIME_CAPTURE_MODE_IMMEDIATE 0x1 /* Capture time immediately on CPU request */ 52 #define TIME_CAPTURE_MODE_HEARTBEAT 0x2 /* Capture time on rising edge of heartbeat */ 53 #define TIME_CAPTURE_MODE_GPIO_0 0x4 /* Capture time on GPIO event */ 54 #define TIME_CAPTURE_MODE_GPIO_1 0x8 55 #define TIME_CAPTURE_MODE_GPIO_2 0x10 56 #define TIME_CAPTURE_MODE_GPIO_3 0x20 57 #define TIME_CAPTURE_MODE_GPIO_4 0x40 58 #define TIME_CAPTURE_MODE_GPIO_5 0x80 59 #define TIME_CAPTURE_MODE_L1_CLOCK_PRIMARY 0x100 /* Capture on L1 Clock */ 60 #define TIME_CAPTURE_MODE_L1_CLOCK_SECONDARY 0x200 61 #define TIME_CAPTURE_MODE_LCPLL 0x400 /* Capture on LCPLL */ 62 #define TIME_CAPTURE_MODE_IP_DM_0 0x800 63 #define TIME_CAPTURE_MODE_IP_DM_1 0x1000 64 65 66 #define TIME_HEARTBEAT_HZ_CLK 125000000 /* 125 MHz */ 67 #define TIME_HEARTBEAT_HZ_MAX 8000 /* 8 KHz */ 68 #define TIME_HEARTBEAT_HZ_MIN 1 /* 1 Hz */ 69 #define TIME_HEARTBEAT_NS_HZ 1000000000 /* 10^9 ns in 1 HZ */ 70 71 72 /* Full cycle BS clock frequencies values in nanoseconds */ 73 #define TIME_BS_FREQUENCY_1000NS 1000 74 #define TIME_BS_FREQUENCY_1024NS 1024 75 #define TIME_BS_FREQUENCY_1544NS 1544 76 #define TIME_BS_FREQUENCY_2000NS 2000 77 #define TIME_BS_FREQUENCY_2048NS 2048 78 79 #define TIME_BS_FREQUENCIES_NUM 5 /* Total number of supported frequencies */ 80 81 #define TIME_TS_CLK_FREQUENCY_40NS 40 /* 25Mhz TS_CLK */ 82 83 #define TIME_INTERFACE_ID_MAX(unit) NUM_TIME_INTERFACE(unit) - 1 84 85 typedef enum _bcm_time_message_type_e { 86 _BCM_TIME_FREQ_OFFSET_SET, 87 _BCM_TIME_FREQ_OFFSET_GET, 88 _BCM_TIME_PHASE_OFFSET_SET, 89 _BCM_TIME_PHASE_OFFSET_GET, 90 _BCM_TIME_DEBUG_1PPS_SET, 91 _BCM_TIME_DEBUG_1PPS_GET, 92 _BCM_TIME_STATUS_GET, 93 _BCM_TIME_LOG_SET, 94 _BCM_TIME_LOG_GET, 95 _BCM_TIME_NTP_OFFSET_SET, 96 _BCM_TIME_NTP_OFFSET_GET, 97 _BCM_TIME_MAX_MESSAGE_NUM, 98 _BCM_TIME_BS_TIME_GET, 99 _BCM_TIME_BS_TIME_SET 100 } _bcm_time_message_type_t; 101 102 103 /* User call back management structure */ 104 typedef struct _bcm_time_user_cb_s { 105 bcm_time_heartbeat_cb heartbeat_cb; /* Callback function on hearbeat */ 106 void *user_data; /* User data provided */ 107 } _bcm_time_user_cb_t, *_bcm_time_user_cb_p; 108 109 /* Time interface managment structure. */ 110 typedef struct _bcm_time_interface_config_s { 111 bcm_time_interface_t time_interface; /* Time Interface structure */ 112 bcm_time_capture_t time_capture; /* Time capture structure */ 113 int ref_count; /* Reference count. */ 114 _bcm_time_user_cb_p user_cb; /* User call back info */ 115 } _bcm_time_interface_config_t, *_bcm_time_interface_config_p; 116 117 118 /* Module control structure. */ 119 typedef struct _bcm_time_config_s { 120 _bcm_time_interface_config_p intf_arr; /* Time Interface config array */ 121 int intf_count; /* Time interfaces size. */ 122 sal_mutex_t mutex; /* Protection mutex. */ 123 } _bcm_time_config_t, *_bcm_time_config_p; 124 125 126 /* Verify that time module is initialized */ 127 #define TIME_INIT(unit) (NULL != _bcm_time_config[unit]) 128 /* Time control configuration per unit */ 129 #define TIME_CONFIG(unit) (_bcm_time_config[unit]) 130 /* Time interface configuration */ 131 #define TIME_INTERFACE_CONFIG(unit, idx) ((TIME_CONFIG(unit))->intf_arr[idx]) 132 /* Time interface */ 133 #define TIME_INTERFACE(unit, idx) &TIME_INTERFACE_CONFIG(unit,idx).time_interface 134 /* Time capture */ 135 #define TIME_CAPTURE(unit, idx) &TIME_INTERFACE_CONFIG(unit, idx).time_capture 136 137 /* Time interface configuration reference count */ 138 #define TIME_INTERFACE_CONFIG_REF_COUNT(unit, idx) (TIME_INTERFACE_CONFIG(unit, idx).ref_count) 139 140 /* Time module lock */ 141 #define TIME_LOCK(unit) sal_mutex_take(TIME_CONFIG(unit)->mutex, sal_mutex_FOREVER) 142 /* Time module unlock */ 143 #define TIME_UNLOCK(unit) sal_mutex_give(TIME_CONFIG(unit)->mutex) 144 145 146 #define TIME_NANOSEC_2_SEC_ROUND(ns) ((ns > (TIME_NANOSEC_MAX / 2)) ? 1: 0) 147 148 #define TIME_ACCURACY_UNKNOWN 0 149 #define TIME_ACCURACY_INFINITE TIME_NANOSEC_MAX 150 #define TIME_ACCURACY_UNKNOWN_IDX 18 151 #define TIME_ACCURACY_LOW_HW_VAL 32 152 #define TIME_ACCURACY_HIGH_HW_VAL 49 153 #define TIME_ACCURACY_UNKNOWN_HW_VAL 254 154 155 #define TIME_ACCURACY_HW_2_SW_IDX(val) ((val == TIME_ACCURACY_UNKNOWN_HW_VAL) ? TIME_ACCURACY_UNKNOWN_IDX : val - TIME_ACCURACY_LOW_HW_VAL) 156 #define TIME_ACCURACY_SW_IDX_2_HW(idx) ((idx == TIME_ACCURACY_UNKNOWN_IDX) ? TIME_ACCURACY_UNKNOWN_HW_VAL : idx + TIME_ACCURACY_LOW_HW_VAL) 157 158 159 #ifdef BCM_WARM_BOOT_SUPPORT_SW_DUMP 160 extern void _bcm_time_sw_dump(int unit); 161 #endif /* BCM_WARM_BOOT_SUPPORT_SW_DUMP */ 162 163 #ifdef BCM_WARM_BOOT_SUPPORT 164 extern int _bcm_time_scache_sync(int unit); 165 #endif 166 167 #if defined(BCM_MONTEREY_SUPPORT) || defined(BCM_TOMAHAWK3_SUPPORT) || defined(BCM_GREYHOUND2_SUPPORT) 168 #define BCM_TIME_READ_NS_REGr(unit, reg, idx, rvp) \ 169 soc_iproc_getreg(unit, soc_reg_addr(unit, reg, REG_PORT_ANY, idx), rvp); 170 #define BCM_TIME_WRITE_NS_REGr(unit, reg, idx, rv) \ 171 soc_iproc_setreg(unit, soc_reg_addr(unit, reg, REG_PORT_ANY, idx), rv) 172 #define TS_GPIO_COUNT 6 173 174 typedef enum _bcm_time_capture_event_e { 175 _bcmTimeCaptureEventCpu = 0, /* CPU generated input event type */ 176 _bcmTimeCaptureEventBS0HB = 1, /* Broadsync0 heartbeat input event type */ 177 _bcmTimeCaptureEventBS1HB = 2, /* Broadsync1 heartbeat input event type */ 178 _bcmTimeCaptureEventGPIO0 = 3, /* GPIO0 input event type */ 179 _bcmTimeCaptureEventGPIO1 = 4, /* GPIO1 input event type */ 180 _bcmTimeCaptureEventGPIO2 = 5, /* GPIO2 input event type */ 181 _bcmTimeCaptureEventGPIO3 = 6, /* GPIO3 input event type */ 182 _bcmTimeCaptureEventGPIO4 = 7, /* GPIO4 input event type */ 183 _bcmTimeCaptureEventGPIO5 = 8, /* GPIO5 input event type */ 184 _bcmTimeCaptureEventIPDM0 = 9, /* IPDM0 input event type */ 185 _bcmTimeCaptureEventIPDM1 = 10, /* IPDM1 input event type */ 186 _bcmTimeCaptureEventTS1TS = 11, /* TS1 counter timestamp event type */ 187 _bcmTimeCaptureEventBS0PLL = 12, /* Broadsync0 PLL input event type */ 188 _bcmTimeCaptureEventBS1PLL = 13, /* Broadsync1 PLL input event type */ 189 _bcmTimeCaptureEventRSVD1IF = 14, /* RSVD1 interface input event type */ 190 _bcmTimeCaptureEventRSVD1RF = 15, /* BCN counter input event type */ 191 _bcmTimeCaptureEventBS0ConvTC = 16, /* Broadsync0 converted timecode input 192 type */ 193 _bcmTimeCaptureEventBS1ConvTC = 17, /* Broadsync1 converted timecode input 194 type */ 195 _bcmTimeCaptureEventLCPLL0 = 18, /* Serdes LCPLL0 input event type */ 196 _bcmTimeCaptureEventLCPLL1 = 19, /* Serdes LCPLL1 input event type */ 197 _bcmTimeCaptureEventLCPLL2 = 20, /* Serdes LCPLL2 input event type */ 198 _bcmTimeCaptureEventLCPLL3 = 21, /* Serdes LCPLL3 input event type */ 199 _bcmTimeCaptureEventPORT = 22, /* Input event from port type */ 200 _bcmTimeCaptureEventR5 = 23, /* Input event from R5 core */ 201 _bcmTimeCaptureEventMax = 24 /* Input event max value */ 202 } _bcm_time_capture_event_t; 203 204 typedef enum _bcm_time_capture_dest_e { 205 _bcmTimeCaptureDestCPU = 0, /* Event forward to CPU FIFO */ 206 _bcmTimeCaptureDestM7 = 1, /* Event forward to GDPLL IA */ 207 _bcmTimeCaptureDestALL = 2 /* Event forward to both */ 208 } _bcm_time_capture_dest_t; 209 210 typedef struct _bcm_time_capture_input_s { 211 _bcm_time_capture_event_t input_event; /* Input event type for the channel */ 212 bcm_port_t port; /* Event input from the port */ 213 bcm_time_port_event_t port_event_type; /* Event input type from the port */ 214 uint32 event_divisor; /* Divisor value for an input event */ 215 _bcm_time_capture_dest_t event_dest; /* Input event forwarding destination 216 type */ 217 int ts_counter; /* 0: TS0, 1:TS1 */ 218 int ppm_check_enable; /* PPM check enable flag, boolean */ 219 } _bcm_time_capture_input_t; 220 221 /* Internal datastructure for event destination config */ 222 typedef struct _bcm_time_capture_dest_cfg_s { 223 _bcm_time_capture_dest_t event_dest; 224 int ts_counter; /* 0: TS0 1:TS1*/ 225 int ppm_check_enable; /* PPM check enable */ 226 } _bcm_time_capture_dest_cfg_t; 227 228 /* NS Interrupts */ 229 #define INTR_TS_FIFO_NOT_EMPTY (1<<0) /* TS_FIFO fill */ 230 #define INTR_TS_FIFO_OVERFLOW (1<<1) /* TS_FIFO overflow */ 231 #define INTR_NS_TIME_CAPTURE (INTR_TS_FIFO_NOT_EMPTY | \ 232 INTR_TS_FIFO_OVERFLOW) 233 234 #define BCM_TIME_CAPTURE_NUM_INPUT_EVENTS 256 235 #define BCM_TIME_CAPTURE_IA_START_TXPI_TXSOF 128 236 #define BCM_TIME_CAPTURE_IA_START_MISC 192 237 #define BCM_TIME_CAPTURE_IA_START_R5 214 238 239 #define BCM_TIME_CAPTURE_MISC_EVENT_EN_CPU (1<<0) 240 #define BCM_TIME_CAPTURE_MISC_EVENT_EN_BS0HB (1<<1) 241 #define BCM_TIME_CAPTURE_MISC_EVENT_EN_BS1HB (1<<2) 242 #define BCM_TIME_CAPTURE_MISC_EVENT_EN_IPDM0 (1<<3) 243 #define BCM_TIME_CAPTURE_MISC_EVENT_EN_IPDM1 (1<<4) 244 #define BCM_TIME_CAPTURE_MISC_EVENT_EN_TS1 (1<<5) 245 #define BCM_TIME_CAPTURE_MISC_EVENT_EN_RSVD1IF (1<<6) 246 #define BCM_TIME_CAPTURE_MISC_EVENT_EN_RSVD1RF (1<<7) 247 #define BCM_TIME_CAPTURE_MISC_EVENT_EN_BS0CONV (1<<8) 248 #define BCM_TIME_CAPTURE_MISC_EVENT_EN_BS1CONV (1<<9) 249 #define BCM_TIME_CAPTURE_NUM_PORTS 64 /* NS supports 64 ports */ 250 #define BCM_TIME_CAPTURE_NUM_CPRI_PORTS 32 /* NS supports 32 CPRI ports */ 251 252 #define SOC_TIME_NS_INTR_POS (1<<24) 253 254 #define BCM_TIME_CAPTURE_HANDLE_INVALID (0xFFFFFFFF) 255 #define BCM_TIME_CAPTURE_MAX_EVENT_ID (215) 256 #define BCM_TIME_CAPTURE_EVENT_STATE_NOT_IN_USE 0x0 257 #define BCM_TIME_CAPTURE_EVENT_STATE_IN_USE 0x1 258 259 #define BCM_TIME_CAPTURE_MAX_FIFO_DATA_SIZE (2574) 260 261 #elif defined(BCM_PETRA_SUPPORT) || defined(BCM_GREYHOUND2_SUPPORT) 262 263 #define BCM_TIME_CAPTURE_MAX_FIFO_DATA_SIZE (2574) 264 265 #endif /* BCM_MONTEREY_SUPPORT || defined(BCM_TOMAHAWK3_SUPPORT)*/ 266 267 #if defined(BCM_TIMESYNC_TIME_CAPTURE_SUPPORT) 268 #define BCM_TIME_TS_CAPTURE_BUF_SIZE (200000) 269 #endif /* BCM_TIMESYNC_TIME_CAPTURE_SUPPORT */ 270 271 #endif /* _BCM_INT_COMMON_TIME_H */ 272