1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001-2021 Intel Corporation
25 enum ice_ptp_link_spd {
29 ICE_PTP_LNK_SPD_25G_RS,
32 ICE_PTP_LNK_SPD_50G_RS,
33 ICE_PTP_LNK_SPD_100G_RS,
34 NUM_ICE_PTP_LNK_SPD /* Must be last */
37 enum ice_ptp_fec_mode {
38 ICE_PTP_FEC_MODE_NONE,
39 ICE_PTP_FEC_MODE_CLAUSE74,
40 ICE_PTP_FEC_MODE_RS_FEC
44 * struct ice_time_ref_info_e822
45 * @pll_freq: Frequency of PLL that drives timer ticks in Hz
46 * @nominal_incval: increment to generate nanoseconds in GLTSYN_TIME_L
47 * @pps_delay: propagation delay of the PPS output signal
49 * Characteristic information for the various TIME_REF sources possible in the
52 struct ice_time_ref_info_e822 {
58 /* Table of constants related to possible TIME_REF sources */
59 extern const struct ice_time_ref_info_e822 e822_time_ref[NUM_ICE_TIME_REF_FREQ];
61 /* Increment value to generate nanoseconds in the GLTSYN_TIME_L register for
62 * the E810 devices. Based off of a PLL with an 812.5 MHz frequency.
64 #define ICE_PTP_NOMINAL_INCVAL_E810 0x13b13b13bULL
66 /* Device agnostic functions */
67 u8 ice_get_ptp_src_clock_index(struct ice_hw *hw);
68 u64 ice_ptp_read_src_incval(struct ice_hw *hw);
69 bool ice_ptp_lock(struct ice_hw *hw);
70 void ice_ptp_unlock(struct ice_hw *hw);
71 void ice_ptp_src_cmd(struct ice_hw *hw, enum ice_ptp_tmr_cmd cmd);
72 enum ice_status ice_ptp_init_time(struct ice_hw *hw, u64 time);
73 enum ice_status ice_ptp_write_incval(struct ice_hw *hw, u64 incval);
74 enum ice_status ice_ptp_write_incval_locked(struct ice_hw *hw, u64 incval);
75 enum ice_status ice_ptp_adj_clock(struct ice_hw *hw, s32 adj, bool lock_sbq);
77 ice_ptp_adj_clock_at_time(struct ice_hw *hw, u64 at_time, s32 adj);
79 ice_read_phy_tstamp(struct ice_hw *hw, u8 block, u8 idx, u64 *tstamp);
81 ice_clear_phy_tstamp(struct ice_hw *hw, u8 block, u8 idx);
83 /* E822 family functions */
85 ice_read_phy_reg_e822(struct ice_hw *hw, u8 port, u16 offset, u32 *val);
87 ice_write_phy_reg_e822(struct ice_hw *hw, u8 port, u16 offset, u32 val);
89 ice_read_quad_reg_e822(struct ice_hw *hw, u8 quad, u16 offset, u32 *val);
91 ice_write_quad_reg_e822(struct ice_hw *hw, u8 quad, u16 offset, u32 val);
93 ice_ptp_prep_port_adj_e822(struct ice_hw *hw, u8 port, s64 time,
96 ice_ptp_read_phy_incval_e822(struct ice_hw *hw, u8 port, u64 *incval);
98 ice_ptp_read_port_capture(struct ice_hw *hw, u8 port, u64 *tx_ts, u64 *rx_ts);
100 ice_ptp_one_port_cmd(struct ice_hw *hw, u8 port, enum ice_ptp_tmr_cmd cmd,
103 static inline u64 ice_e822_pll_freq(enum ice_time_ref_freq time_ref)
105 return e822_time_ref[time_ref].pll_freq;
108 static inline u64 ice_e822_nominal_incval(enum ice_time_ref_freq time_ref)
110 return e822_time_ref[time_ref].nominal_incval;
113 static inline u64 ice_e822_pps_delay(enum ice_time_ref_freq time_ref)
115 return e822_time_ref[time_ref].pps_delay;
118 /* E822 Vernier calibration functions */
119 enum ice_status ice_ptp_set_vernier_wl(struct ice_hw *hw);
121 ice_phy_get_speed_and_fec_e822(struct ice_hw *hw, u8 port,
122 enum ice_ptp_link_spd *link_out,
123 enum ice_ptp_fec_mode *fec_out);
124 void ice_phy_cfg_lane_e822(struct ice_hw *hw, u8 port);
126 /* E810 family functions */
127 enum ice_status ice_ptp_init_phy_e810(struct ice_hw *hw);
129 #define PFTSYN_SEM_BYTES 4
131 #define ICE_PTP_CLOCK_INDEX_0 0x00
132 #define ICE_PTP_CLOCK_INDEX_1 0x01
134 /* PHY timer commands */
135 #define SEL_CPK_SRC 8
136 #define SEL_PHY_SRC 3
138 /* Time Sync command Definitions */
139 #define GLTSYN_CMD_INIT_TIME BIT(0)
140 #define GLTSYN_CMD_INIT_INCVAL BIT(1)
141 #define GLTSYN_CMD_INIT_TIME_INCVAL (BIT(0) | BIT(1))
142 #define GLTSYN_CMD_ADJ_TIME BIT(2)
143 #define GLTSYN_CMD_ADJ_INIT_TIME (BIT(2) | BIT(3))
144 #define GLTSYN_CMD_READ_TIME BIT(7)
146 /* PHY port Time Sync command definitions */
147 #define PHY_CMD_INIT_TIME BIT(0)
148 #define PHY_CMD_INIT_INCVAL BIT(1)
149 #define PHY_CMD_ADJ_TIME (BIT(0) | BIT(1))
150 #define PHY_CMD_ADJ_TIME_AT_TIME (BIT(0) | BIT(2))
151 #define PHY_CMD_READ_TIME (BIT(0) | BIT(1) | BIT(2))
153 #define TS_CMD_MASK_E810 0xFF
154 #define TS_CMD_MASK 0xF
155 #define SYNC_EXEC_CMD 0x3
157 /* Macros to derive port low and high addresses on both quads */
158 #define P_Q0_L(a, p) ((((a) + (0x2000 * (p)))) & 0xFFFF)
159 #define P_Q0_H(a, p) ((((a) + (0x2000 * (p)))) >> 16)
160 #define P_Q1_L(a, p) ((((a) - (0x2000 * ((p) - ICE_PORTS_PER_QUAD)))) & 0xFFFF)
161 #define P_Q1_H(a, p) ((((a) - (0x2000 * ((p) - ICE_PORTS_PER_QUAD)))) >> 16)
163 /* PHY QUAD register base addresses */
164 #define Q_0_BASE 0x94000
165 #define Q_1_BASE 0x114000
167 /* Timestamp memory reset registers */
168 #define Q_REG_TS_CTRL 0x618
169 #define Q_REG_TS_CTRL_S 0
170 #define Q_REG_TS_CTRL_M BIT(0)
172 /* Timestamp availability status registers */
173 #define Q_REG_TX_MEMORY_STATUS_L 0xCF0
174 #define Q_REG_TX_MEMORY_STATUS_U 0xCF4
176 /* Tx FIFO status registers */
177 #define Q_REG_FIFO23_STATUS 0xCF8
178 #define Q_REG_FIFO01_STATUS 0xCFC
179 #define Q_REG_FIFO02_S 0
180 #define Q_REG_FIFO02_M MAKEMASK(0x3FF, 0)
181 #define Q_REG_FIFO13_S 10
182 #define Q_REG_FIFO13_M MAKEMASK(0x3FF, 10)
184 /* Interrupt control Config registers */
185 #define Q_REG_TX_MEM_GBL_CFG 0xC08
186 #define Q_REG_TX_MEM_GBL_CFG_LANE_TYPE_S 0
187 #define Q_REG_TX_MEM_GBL_CFG_LANE_TYPE_M BIT(0)
188 #define Q_REG_TX_MEM_GBL_CFG_TX_TYPE_S 1
189 #define Q_REG_TX_MEM_GBL_CFG_TX_TYPE_M MAKEMASK(0xFF, 1)
190 #define Q_REG_TX_MEM_GBL_CFG_INTR_THR_S 9
191 #define Q_REG_TX_MEM_GBL_CFG_INTR_THR_M MAKEMASK(0x3F, 9)
192 #define Q_REG_TX_MEM_GBL_CFG_INTR_ENA_S 15
193 #define Q_REG_TX_MEM_GBL_CFG_INTR_ENA_M BIT(15)
195 /* Tx Timestamp data registers */
196 #define Q_REG_TX_MEMORY_BANK_START 0xA00
198 /* PHY port register base addresses */
199 #define P_0_BASE 0x80000
200 #define P_4_BASE 0x106000
202 /* Timestamp init registers */
203 #define P_REG_RX_TIMER_INC_PRE_L 0x46C
204 #define P_REG_RX_TIMER_INC_PRE_U 0x470
205 #define P_REG_TX_TIMER_INC_PRE_L 0x44C
206 #define P_REG_TX_TIMER_INC_PRE_U 0x450
208 /* Timestamp match and adjust target registers */
209 #define P_REG_RX_TIMER_CNT_ADJ_L 0x474
210 #define P_REG_RX_TIMER_CNT_ADJ_U 0x478
211 #define P_REG_TX_TIMER_CNT_ADJ_L 0x454
212 #define P_REG_TX_TIMER_CNT_ADJ_U 0x458
214 /* Timestamp capture registers */
215 #define P_REG_RX_CAPTURE_L 0x4D8
216 #define P_REG_RX_CAPTURE_U 0x4DC
217 #define P_REG_TX_CAPTURE_L 0x4B4
218 #define P_REG_TX_CAPTURE_U 0x4B8
220 /* Timestamp PHY incval registers */
221 #define P_REG_TIMETUS_L 0x410
222 #define P_REG_TIMETUS_U 0x414
224 #define P_REG_40B_LOW_M 0xFF
225 #define P_REG_40B_HIGH_S 8
227 /* PHY window length registers */
228 #define P_REG_WL 0x40C
230 #define PTP_VERNIER_WL 0x111ed
232 /* PHY start registers */
233 #define P_REG_PS 0x408
234 #define P_REG_PS_START_S 0
235 #define P_REG_PS_START_M BIT(0)
236 #define P_REG_PS_BYPASS_MODE_S 1
237 #define P_REG_PS_BYPASS_MODE_M BIT(1)
238 #define P_REG_PS_ENA_CLK_S 2
239 #define P_REG_PS_ENA_CLK_M BIT(2)
240 #define P_REG_PS_LOAD_OFFSET_S 3
241 #define P_REG_PS_LOAD_OFFSET_M BIT(3)
242 #define P_REG_PS_SFT_RESET_S 11
243 #define P_REG_PS_SFT_RESET_M BIT(11)
245 /* PHY offset valid registers */
246 #define P_REG_TX_OV_STATUS 0x4D4
247 #define P_REG_TX_OV_STATUS_OV_S 0
248 #define P_REG_TX_OV_STATUS_OV_M BIT(0)
249 #define P_REG_RX_OV_STATUS 0x4F8
250 #define P_REG_RX_OV_STATUS_OV_S 0
251 #define P_REG_RX_OV_STATUS_OV_M BIT(0)
253 /* PHY offset ready registers */
254 #define P_REG_TX_OR 0x45C
255 #define P_REG_RX_OR 0x47C
257 /* PHY total offset registers */
258 #define P_REG_TOTAL_RX_OFFSET_L 0x460
259 #define P_REG_TOTAL_RX_OFFSET_U 0x464
260 #define P_REG_TOTAL_TX_OFFSET_L 0x440
261 #define P_REG_TOTAL_TX_OFFSET_U 0x444
263 /* Timestamp PAR/PCS registers */
264 #define P_REG_UIX66_10G_40G_L 0x480
265 #define P_REG_UIX66_10G_40G_U 0x484
266 #define P_REG_UIX66_25G_100G_L 0x488
267 #define P_REG_UIX66_25G_100G_U 0x48C
268 #define P_REG_DESK_PAR_RX_TUS_L 0x490
269 #define P_REG_DESK_PAR_RX_TUS_U 0x494
270 #define P_REG_DESK_PAR_TX_TUS_L 0x498
271 #define P_REG_DESK_PAR_TX_TUS_U 0x49C
272 #define P_REG_DESK_PCS_RX_TUS_L 0x4A0
273 #define P_REG_DESK_PCS_RX_TUS_U 0x4A4
274 #define P_REG_DESK_PCS_TX_TUS_L 0x4A8
275 #define P_REG_DESK_PCS_TX_TUS_U 0x4AC
276 #define P_REG_PAR_RX_TUS_L 0x420
277 #define P_REG_PAR_RX_TUS_U 0x424
278 #define P_REG_PAR_TX_TUS_L 0x428
279 #define P_REG_PAR_TX_TUS_U 0x42C
280 #define P_REG_PCS_RX_TUS_L 0x430
281 #define P_REG_PCS_RX_TUS_U 0x434
282 #define P_REG_PCS_TX_TUS_L 0x438
283 #define P_REG_PCS_TX_TUS_U 0x43C
284 #define P_REG_PAR_RX_TIME_L 0x4F0
285 #define P_REG_PAR_RX_TIME_U 0x4F4
286 #define P_REG_PAR_TX_TIME_L 0x4CC
287 #define P_REG_PAR_TX_TIME_U 0x4D0
288 #define P_REG_PAR_PCS_RX_OFFSET_L 0x4E8
289 #define P_REG_PAR_PCS_RX_OFFSET_U 0x4EC
290 #define P_REG_PAR_PCS_TX_OFFSET_L 0x4C4
291 #define P_REG_PAR_PCS_TX_OFFSET_U 0x4C8
292 #define P_REG_LINK_SPEED 0x4FC
293 #define P_REG_LINK_SPEED_SERDES_S 0
294 #define P_REG_LINK_SPEED_SERDES_M MAKEMASK(0x7, 0)
295 #define P_REG_LINK_SPEED_FEC_MODE_S 3
296 #define P_REG_LINK_SPEED_FEC_MODE_M MAKEMASK(0x3, 3)
297 #define P_REG_LINK_SPEED_FEC_MODE(reg) \
298 (((reg) & P_REG_LINK_SPEED_FEC_MODE_M) >> \
299 P_REG_LINK_SPEED_FEC_MODE_S)
301 /* PHY timestamp related registers */
302 #define P_REG_PMD_ALIGNMENT 0x0FC
303 #define P_REG_RX_80_TO_160_CNT 0x6FC
304 #define P_REG_RX_80_TO_160_CNT_RXCYC_S 0
305 #define P_REG_RX_80_TO_160_CNT_RXCYC_M BIT(0)
306 #define P_REG_RX_40_TO_160_CNT 0x8FC
307 #define P_REG_RX_40_TO_160_CNT_RXCYC_S 0
308 #define P_REG_RX_40_TO_160_CNT_RXCYC_M MAKEMASK(0x3, 0)
310 /* Rx FIFO status registers */
311 #define P_REG_RX_OV_FS 0x4F8
312 #define P_REG_RX_OV_FS_FIFO_STATUS_S 2
313 #define P_REG_RX_OV_FS_FIFO_STATUS_M MAKEMASK(0x3FF, 2)
315 /* Timestamp command registers */
316 #define P_REG_TX_TMR_CMD 0x448
317 #define P_REG_RX_TMR_CMD 0x468
319 /* E810 timesync enable register */
320 #define ETH_GLTSYN_ENA(_i) (0x03000348 + ((_i) * 4))
322 /* E810 shadow init time registers */
323 #define ETH_GLTSYN_SHTIME_0(i) (0x03000368 + ((i) * 32))
324 #define ETH_GLTSYN_SHTIME_L(i) (0x0300036C + ((i) * 32))
326 /* E810 shadow time adjust registers */
327 #define ETH_GLTSYN_SHADJ_L(_i) (0x03000378 + ((_i) * 32))
328 #define ETH_GLTSYN_SHADJ_H(_i) (0x0300037C + ((_i) * 32))
330 /* E810 timer command register */
331 #define ETH_GLTSYN_CMD 0x03000344
333 /* Source timer incval macros */
334 #define INCVAL_HIGH_M 0xFF
336 /* Timestamp block macros */
337 #define TS_LOW_M 0xFFFFFFFF
338 #define TS_HIGH_M 0xFF
341 #define TS_PHY_LOW_M 0xFF
342 #define TS_PHY_HIGH_M 0xFFFFFFFF
343 #define TS_PHY_HIGH_S 8
345 #define BYTES_PER_IDX_ADDR_L_U 8
346 #define BYTES_PER_IDX_ADDR_L 4
348 /* Internal PHY timestamp address */
349 #define TS_L(a, idx) ((a) + ((idx) * BYTES_PER_IDX_ADDR_L_U))
350 #define TS_H(a, idx) ((a) + ((idx) * BYTES_PER_IDX_ADDR_L_U + \
351 BYTES_PER_IDX_ADDR_L))
353 /* External PHY timestamp address */
354 #define TS_EXT(a, port, idx) ((a) + (0x1000 * (port)) + \
355 ((idx) * BYTES_PER_IDX_ADDR_L_U))
357 #define LOW_TX_MEMORY_BANK_START 0x03090000
358 #define HIGH_TX_MEMORY_BANK_START 0x03090004
360 /* E810T PCA9575 IO controller registers */
361 #define ICE_PCA9575_P0_IN 0x0
362 #define ICE_PCA9575_P1_IN 0x1
363 #define ICE_PCA9575_P0_CFG 0x8
364 #define ICE_PCA9575_P1_CFG 0x9
365 #define ICE_PCA9575_P0_OUT 0xA
366 #define ICE_PCA9575_P1_OUT 0xB
368 /* E810T PCA9575 IO controller pin control */
369 #define ICE_E810T_P0_GNSS_PRSNT_N BIT(4)
370 #define ICE_E810T_P1_SMA1_DIR_EN BIT(4)
371 #define ICE_E810T_P1_SMA1_TX_EN BIT(5)
372 #define ICE_E810T_P1_SMA2_UFL2_RX_DIS BIT(3)
373 #define ICE_E810T_P1_SMA2_DIR_EN BIT(6)
374 #define ICE_E810T_P1_SMA2_TX_EN BIT(7)
376 #endif /* _ICE_PTP_HW_H_ */