8cbe81792d621ee2b749f25386fbf8021a431147
[dpdk.git] / drivers / net / ice / base / ice_ptp_hw.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2001-2021 Intel Corporation
3  */
4
5 #ifndef _ICE_PTP_HW_H_
6 #define _ICE_PTP_HW_H_
7
8 enum ice_ptp_tmr_cmd {
9         INIT_TIME,
10         INIT_INCVAL,
11         ADJ_TIME,
12         ADJ_TIME_AT_TIME,
13         READ_TIME
14 };
15
16 enum ice_ptp_serdes {
17         ICE_PTP_SERDES_1G,
18         ICE_PTP_SERDES_10G,
19         ICE_PTP_SERDES_25G,
20         ICE_PTP_SERDES_40G,
21         ICE_PTP_SERDES_50G,
22         ICE_PTP_SERDES_100G
23 };
24
25 enum ice_ptp_link_spd {
26         ICE_PTP_LNK_SPD_1G,
27         ICE_PTP_LNK_SPD_10G,
28         ICE_PTP_LNK_SPD_25G,
29         ICE_PTP_LNK_SPD_25G_RS,
30         ICE_PTP_LNK_SPD_40G,
31         ICE_PTP_LNK_SPD_50G,
32         ICE_PTP_LNK_SPD_50G_RS,
33         ICE_PTP_LNK_SPD_100G_RS,
34         NUM_ICE_PTP_LNK_SPD /* Must be last */
35 };
36
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
41 };
42
43 /**
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
48  *
49  * Characteristic information for the various TIME_REF sources possible in the
50  * E822 devices
51  */
52 struct ice_time_ref_info_e822 {
53         u64 pll_freq;
54         u64 nominal_incval;
55         u8 pps_delay;
56 };
57
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];
60
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.
63  */
64 #define ICE_PTP_NOMINAL_INCVAL_E810 0x13b13b13bULL
65
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);
76 enum ice_status
77 ice_ptp_adj_clock_at_time(struct ice_hw *hw, u64 at_time, s32 adj);
78 enum ice_status
79 ice_read_phy_tstamp(struct ice_hw *hw, u8 block, u8 idx, u64 *tstamp);
80 enum ice_status
81 ice_clear_phy_tstamp(struct ice_hw *hw, u8 block, u8 idx);
82
83 /* E822 family functions */
84 enum ice_status
85 ice_read_phy_reg_e822(struct ice_hw *hw, u8 port, u16 offset, u32 *val);
86 enum ice_status
87 ice_write_phy_reg_e822(struct ice_hw *hw, u8 port, u16 offset, u32 val);
88 enum ice_status
89 ice_read_quad_reg_e822(struct ice_hw *hw, u8 quad, u16 offset, u32 *val);
90 enum ice_status
91 ice_write_quad_reg_e822(struct ice_hw *hw, u8 quad, u16 offset, u32 val);
92 enum ice_status
93 ice_ptp_prep_port_adj_e822(struct ice_hw *hw, u8 port, s64 time,
94                            bool lock_sbq);
95 enum ice_status
96 ice_ptp_read_phy_incval_e822(struct ice_hw *hw, u8 port, u64 *incval);
97 enum ice_status
98 ice_ptp_read_port_capture(struct ice_hw *hw, u8 port, u64 *tx_ts, u64 *rx_ts);
99 enum ice_status
100 ice_ptp_one_port_cmd(struct ice_hw *hw, u8 port, enum ice_ptp_tmr_cmd cmd,
101                      bool lock_sbq);
102
103 static inline u64 ice_e822_pll_freq(enum ice_time_ref_freq time_ref)
104 {
105         return e822_time_ref[time_ref].pll_freq;
106 }
107
108 static inline u64 ice_e822_nominal_incval(enum ice_time_ref_freq time_ref)
109 {
110         return e822_time_ref[time_ref].nominal_incval;
111 }
112
113 static inline u64 ice_e822_pps_delay(enum ice_time_ref_freq time_ref)
114 {
115         return e822_time_ref[time_ref].pps_delay;
116 }
117
118 /* E822 Vernier calibration functions */
119 enum ice_status ice_ptp_set_vernier_wl(struct ice_hw *hw);
120 enum ice_status
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);
125
126 /* E810 family functions */
127 enum ice_status ice_ptp_init_phy_e810(struct ice_hw *hw);
128
129 #define PFTSYN_SEM_BYTES        4
130
131 #define ICE_PTP_CLOCK_INDEX_0   0x00
132 #define ICE_PTP_CLOCK_INDEX_1   0x01
133
134 /* PHY timer commands */
135 #define SEL_CPK_SRC     8
136 #define SEL_PHY_SRC     3
137
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)
145
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))
152
153 #define TS_CMD_MASK_E810                0xFF
154 #define TS_CMD_MASK                     0xF
155 #define SYNC_EXEC_CMD                   0x3
156
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)
162
163 /* PHY QUAD register base addresses */
164 #define Q_0_BASE                        0x94000
165 #define Q_1_BASE                        0x114000
166
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)
171
172 /* Timestamp availability status registers */
173 #define Q_REG_TX_MEMORY_STATUS_L        0xCF0
174 #define Q_REG_TX_MEMORY_STATUS_U        0xCF4
175
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)
183
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)
194
195 /* Tx Timestamp data registers */
196 #define Q_REG_TX_MEMORY_BANK_START      0xA00
197
198 /* PHY port register base addresses */
199 #define P_0_BASE                        0x80000
200 #define P_4_BASE                        0x106000
201
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
207
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
213
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
219
220 /* Timestamp PHY incval registers */
221 #define P_REG_TIMETUS_L                 0x410
222 #define P_REG_TIMETUS_U                 0x414
223
224 #define P_REG_40B_LOW_M                 0xFF
225 #define P_REG_40B_HIGH_S                8
226
227 /* PHY window length registers */
228 #define P_REG_WL                        0x40C
229
230 #define PTP_VERNIER_WL                  0x111ed
231
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)
244
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)
252
253 /* PHY offset ready registers */
254 #define P_REG_TX_OR                     0x45C
255 #define P_REG_RX_OR                     0x47C
256
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
262
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)
300
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)
309
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)
314
315 /* Timestamp command registers */
316 #define P_REG_TX_TMR_CMD                0x448
317 #define P_REG_RX_TMR_CMD                0x468
318
319 /* E810 timesync enable register */
320 #define ETH_GLTSYN_ENA(_i)              (0x03000348 + ((_i) * 4))
321
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))
325
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))
329
330 /* E810 timer command register */
331 #define ETH_GLTSYN_CMD                  0x03000344
332
333 /* Source timer incval macros */
334 #define INCVAL_HIGH_M                   0xFF
335
336 /* Timestamp block macros */
337 #define TS_LOW_M                        0xFFFFFFFF
338 #define TS_HIGH_M                       0xFF
339 #define TS_HIGH_S                       32
340
341 #define TS_PHY_LOW_M                    0xFF
342 #define TS_PHY_HIGH_M                   0xFFFFFFFF
343 #define TS_PHY_HIGH_S                   8
344
345 #define BYTES_PER_IDX_ADDR_L_U          8
346 #define BYTES_PER_IDX_ADDR_L            4
347
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))
352
353 /* External PHY timestamp address */
354 #define TS_EXT(a, port, idx) ((a) + (0x1000 * (port)) +                 \
355                                  ((idx) * BYTES_PER_IDX_ADDR_L_U))
356
357 #define LOW_TX_MEMORY_BANK_START        0x03090000
358 #define HIGH_TX_MEMORY_BANK_START       0x03090004
359
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
367
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)
375
376 #endif /* _ICE_PTP_HW_H_ */