openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

time.h (14263B)


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