net/ice/base: print human-friendly PHY types
[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 /**
59  * struct ice_cgu_pll_params_e822
60  * @refclk_pre_div: Reference clock pre-divisor
61  * @feedback_div: Feedback divisor
62  * @frac_n_div: Fractional divisor
63  * @post_pll_div: Post PLL divisor
64  *
65  * Clock Generation Unit parameters used to program the PLL based on the
66  * selected TIME_REF frequency.
67  */
68 struct ice_cgu_pll_params_e822 {
69         u32 refclk_pre_div;
70         u32 feedback_div;
71         u32 frac_n_div;
72         u32 post_pll_div;
73 };
74
75 extern const struct
76 ice_cgu_pll_params_e822 e822_cgu_params[NUM_ICE_TIME_REF_FREQ];
77
78 /* Table of constants related to possible TIME_REF sources */
79 extern const struct ice_time_ref_info_e822 e822_time_ref[NUM_ICE_TIME_REF_FREQ];
80
81 /* Increment value to generate nanoseconds in the GLTSYN_TIME_L register for
82  * the E810 devices. Based off of a PLL with an 812.5 MHz frequency.
83  */
84 #define ICE_PTP_NOMINAL_INCVAL_E810 0x13b13b13bULL
85
86 /* Device agnostic functions */
87 u8 ice_get_ptp_src_clock_index(struct ice_hw *hw);
88 u64 ice_ptp_read_src_incval(struct ice_hw *hw);
89 bool ice_ptp_lock(struct ice_hw *hw);
90 void ice_ptp_unlock(struct ice_hw *hw);
91 void ice_ptp_src_cmd(struct ice_hw *hw, enum ice_ptp_tmr_cmd cmd);
92 enum ice_status ice_ptp_init_time(struct ice_hw *hw, u64 time);
93 enum ice_status ice_ptp_write_incval(struct ice_hw *hw, u64 incval);
94 enum ice_status ice_ptp_write_incval_locked(struct ice_hw *hw, u64 incval);
95 enum ice_status ice_ptp_adj_clock(struct ice_hw *hw, s32 adj, bool lock_sbq);
96 enum ice_status
97 ice_ptp_adj_clock_at_time(struct ice_hw *hw, u64 at_time, s32 adj);
98 enum ice_status
99 ice_read_phy_tstamp(struct ice_hw *hw, u8 block, u8 idx, u64 *tstamp);
100 enum ice_status
101 ice_clear_phy_tstamp(struct ice_hw *hw, u8 block, u8 idx);
102 enum ice_status ice_ptp_init_phc(struct ice_hw *hw);
103
104 /* E822 family functions */
105 enum ice_status
106 ice_read_phy_reg_e822(struct ice_hw *hw, u8 port, u16 offset, u32 *val);
107 enum ice_status
108 ice_write_phy_reg_e822(struct ice_hw *hw, u8 port, u16 offset, u32 val);
109 enum ice_status
110 ice_read_quad_reg_e822(struct ice_hw *hw, u8 quad, u16 offset, u32 *val);
111 enum ice_status
112 ice_write_quad_reg_e822(struct ice_hw *hw, u8 quad, u16 offset, u32 val);
113 enum ice_status
114 ice_ptp_prep_port_adj_e822(struct ice_hw *hw, u8 port, s64 time,
115                            bool lock_sbq);
116 enum ice_status
117 ice_ptp_read_phy_incval_e822(struct ice_hw *hw, u8 port, u64 *incval);
118 enum ice_status
119 ice_ptp_read_port_capture(struct ice_hw *hw, u8 port, u64 *tx_ts, u64 *rx_ts);
120 enum ice_status
121 ice_ptp_one_port_cmd(struct ice_hw *hw, u8 port, enum ice_ptp_tmr_cmd cmd,
122                      bool lock_sbq);
123 enum ice_status
124 ice_cfg_cgu_pll_e822(struct ice_hw *hw, enum ice_time_ref_freq clk_freq,
125                      enum ice_clk_src clk_src);
126
127 /**
128  * ice_e822_time_ref - Get the current TIME_REF from capabilities
129  * @hw: pointer to the HW structure
130  *
131  * Returns the current TIME_REF from the capabilities structure.
132  */
133 static inline enum ice_time_ref_freq ice_e822_time_ref(struct ice_hw *hw)
134 {
135         return hw->func_caps.ts_func_info.time_ref;
136 }
137
138 /**
139  * ice_set_e822_time_ref - Set new TIME_REF
140  * @hw: pointer to the HW structure
141  * @time_ref: new TIME_REF to set
142  *
143  * Update the TIME_REF in the capabilities structure in response to some
144  * change, such as an update to the CGU registers.
145  */
146 static inline void
147 ice_set_e822_time_ref(struct ice_hw *hw, enum ice_time_ref_freq time_ref)
148 {
149         hw->func_caps.ts_func_info.time_ref = time_ref;
150 }
151
152 static inline u64 ice_e822_pll_freq(enum ice_time_ref_freq time_ref)
153 {
154         return e822_time_ref[time_ref].pll_freq;
155 }
156
157 static inline u64 ice_e822_nominal_incval(enum ice_time_ref_freq time_ref)
158 {
159         return e822_time_ref[time_ref].nominal_incval;
160 }
161
162 static inline u64 ice_e822_pps_delay(enum ice_time_ref_freq time_ref)
163 {
164         return e822_time_ref[time_ref].pps_delay;
165 }
166
167 /* E822 Vernier calibration functions */
168 enum ice_status ice_ptp_set_vernier_wl(struct ice_hw *hw);
169 enum ice_status
170 ice_phy_get_speed_and_fec_e822(struct ice_hw *hw, u8 port,
171                                enum ice_ptp_link_spd *link_out,
172                                enum ice_ptp_fec_mode *fec_out);
173 void ice_phy_cfg_lane_e822(struct ice_hw *hw, u8 port);
174
175 /* E810 family functions */
176 enum ice_status ice_ptp_init_phy_e810(struct ice_hw *hw);
177
178 #define PFTSYN_SEM_BYTES        4
179
180 #define ICE_PTP_CLOCK_INDEX_0   0x00
181 #define ICE_PTP_CLOCK_INDEX_1   0x01
182
183 /* PHY timer commands */
184 #define SEL_CPK_SRC     8
185 #define SEL_PHY_SRC     3
186
187 /* Time Sync command Definitions */
188 #define GLTSYN_CMD_INIT_TIME            BIT(0)
189 #define GLTSYN_CMD_INIT_INCVAL          BIT(1)
190 #define GLTSYN_CMD_INIT_TIME_INCVAL     (BIT(0) | BIT(1))
191 #define GLTSYN_CMD_ADJ_TIME             BIT(2)
192 #define GLTSYN_CMD_ADJ_INIT_TIME        (BIT(2) | BIT(3))
193 #define GLTSYN_CMD_READ_TIME            BIT(7)
194
195 /* PHY port Time Sync command definitions */
196 #define PHY_CMD_INIT_TIME               BIT(0)
197 #define PHY_CMD_INIT_INCVAL             BIT(1)
198 #define PHY_CMD_ADJ_TIME                (BIT(0) | BIT(1))
199 #define PHY_CMD_ADJ_TIME_AT_TIME        (BIT(0) | BIT(2))
200 #define PHY_CMD_READ_TIME               (BIT(0) | BIT(1) | BIT(2))
201
202 #define TS_CMD_MASK_E810                0xFF
203 #define TS_CMD_MASK                     0xF
204 #define SYNC_EXEC_CMD                   0x3
205
206 /* Macros to derive port low and high addresses on both quads */
207 #define P_Q0_L(a, p) ((((a) + (0x2000 * (p)))) & 0xFFFF)
208 #define P_Q0_H(a, p) ((((a) + (0x2000 * (p)))) >> 16)
209 #define P_Q1_L(a, p) ((((a) - (0x2000 * ((p) - ICE_PORTS_PER_QUAD)))) & 0xFFFF)
210 #define P_Q1_H(a, p) ((((a) - (0x2000 * ((p) - ICE_PORTS_PER_QUAD)))) >> 16)
211
212 /* PHY QUAD register base addresses */
213 #define Q_0_BASE                        0x94000
214 #define Q_1_BASE                        0x114000
215
216 /* Timestamp memory reset registers */
217 #define Q_REG_TS_CTRL                   0x618
218 #define Q_REG_TS_CTRL_S                 0
219 #define Q_REG_TS_CTRL_M                 BIT(0)
220
221 /* Timestamp availability status registers */
222 #define Q_REG_TX_MEMORY_STATUS_L        0xCF0
223 #define Q_REG_TX_MEMORY_STATUS_U        0xCF4
224
225 /* Tx FIFO status registers */
226 #define Q_REG_FIFO23_STATUS             0xCF8
227 #define Q_REG_FIFO01_STATUS             0xCFC
228 #define Q_REG_FIFO02_S                  0
229 #define Q_REG_FIFO02_M                  MAKEMASK(0x3FF, 0)
230 #define Q_REG_FIFO13_S                  10
231 #define Q_REG_FIFO13_M                  MAKEMASK(0x3FF, 10)
232
233 /* Interrupt control Config registers */
234 #define Q_REG_TX_MEM_GBL_CFG            0xC08
235 #define Q_REG_TX_MEM_GBL_CFG_LANE_TYPE_S        0
236 #define Q_REG_TX_MEM_GBL_CFG_LANE_TYPE_M        BIT(0)
237 #define Q_REG_TX_MEM_GBL_CFG_TX_TYPE_S  1
238 #define Q_REG_TX_MEM_GBL_CFG_TX_TYPE_M  MAKEMASK(0xFF, 1)
239 #define Q_REG_TX_MEM_GBL_CFG_INTR_THR_S 9
240 #define Q_REG_TX_MEM_GBL_CFG_INTR_THR_M MAKEMASK(0x3F, 9)
241 #define Q_REG_TX_MEM_GBL_CFG_INTR_ENA_S 15
242 #define Q_REG_TX_MEM_GBL_CFG_INTR_ENA_M BIT(15)
243
244 /* Tx Timestamp data registers */
245 #define Q_REG_TX_MEMORY_BANK_START      0xA00
246
247 /* PHY port register base addresses */
248 #define P_0_BASE                        0x80000
249 #define P_4_BASE                        0x106000
250
251 /* Timestamp init registers */
252 #define P_REG_RX_TIMER_INC_PRE_L        0x46C
253 #define P_REG_RX_TIMER_INC_PRE_U        0x470
254 #define P_REG_TX_TIMER_INC_PRE_L        0x44C
255 #define P_REG_TX_TIMER_INC_PRE_U        0x450
256
257 /* Timestamp match and adjust target registers */
258 #define P_REG_RX_TIMER_CNT_ADJ_L        0x474
259 #define P_REG_RX_TIMER_CNT_ADJ_U        0x478
260 #define P_REG_TX_TIMER_CNT_ADJ_L        0x454
261 #define P_REG_TX_TIMER_CNT_ADJ_U        0x458
262
263 /* Timestamp capture registers */
264 #define P_REG_RX_CAPTURE_L              0x4D8
265 #define P_REG_RX_CAPTURE_U              0x4DC
266 #define P_REG_TX_CAPTURE_L              0x4B4
267 #define P_REG_TX_CAPTURE_U              0x4B8
268
269 /* Timestamp PHY incval registers */
270 #define P_REG_TIMETUS_L                 0x410
271 #define P_REG_TIMETUS_U                 0x414
272
273 #define P_REG_40B_LOW_M                 0xFF
274 #define P_REG_40B_HIGH_S                8
275
276 /* PHY window length registers */
277 #define P_REG_WL                        0x40C
278
279 #define PTP_VERNIER_WL                  0x111ed
280
281 /* PHY start registers */
282 #define P_REG_PS                        0x408
283 #define P_REG_PS_START_S                0
284 #define P_REG_PS_START_M                BIT(0)
285 #define P_REG_PS_BYPASS_MODE_S          1
286 #define P_REG_PS_BYPASS_MODE_M          BIT(1)
287 #define P_REG_PS_ENA_CLK_S              2
288 #define P_REG_PS_ENA_CLK_M              BIT(2)
289 #define P_REG_PS_LOAD_OFFSET_S          3
290 #define P_REG_PS_LOAD_OFFSET_M          BIT(3)
291 #define P_REG_PS_SFT_RESET_S            11
292 #define P_REG_PS_SFT_RESET_M            BIT(11)
293
294 /* PHY offset valid registers */
295 #define P_REG_TX_OV_STATUS              0x4D4
296 #define P_REG_TX_OV_STATUS_OV_S         0
297 #define P_REG_TX_OV_STATUS_OV_M         BIT(0)
298 #define P_REG_RX_OV_STATUS              0x4F8
299 #define P_REG_RX_OV_STATUS_OV_S         0
300 #define P_REG_RX_OV_STATUS_OV_M         BIT(0)
301
302 /* PHY offset ready registers */
303 #define P_REG_TX_OR                     0x45C
304 #define P_REG_RX_OR                     0x47C
305
306 /* PHY total offset registers */
307 #define P_REG_TOTAL_RX_OFFSET_L         0x460
308 #define P_REG_TOTAL_RX_OFFSET_U         0x464
309 #define P_REG_TOTAL_TX_OFFSET_L         0x440
310 #define P_REG_TOTAL_TX_OFFSET_U         0x444
311
312 /* Timestamp PAR/PCS registers */
313 #define P_REG_UIX66_10G_40G_L           0x480
314 #define P_REG_UIX66_10G_40G_U           0x484
315 #define P_REG_UIX66_25G_100G_L          0x488
316 #define P_REG_UIX66_25G_100G_U          0x48C
317 #define P_REG_DESK_PAR_RX_TUS_L         0x490
318 #define P_REG_DESK_PAR_RX_TUS_U         0x494
319 #define P_REG_DESK_PAR_TX_TUS_L         0x498
320 #define P_REG_DESK_PAR_TX_TUS_U         0x49C
321 #define P_REG_DESK_PCS_RX_TUS_L         0x4A0
322 #define P_REG_DESK_PCS_RX_TUS_U         0x4A4
323 #define P_REG_DESK_PCS_TX_TUS_L         0x4A8
324 #define P_REG_DESK_PCS_TX_TUS_U         0x4AC
325 #define P_REG_PAR_RX_TUS_L              0x420
326 #define P_REG_PAR_RX_TUS_U              0x424
327 #define P_REG_PAR_TX_TUS_L              0x428
328 #define P_REG_PAR_TX_TUS_U              0x42C
329 #define P_REG_PCS_RX_TUS_L              0x430
330 #define P_REG_PCS_RX_TUS_U              0x434
331 #define P_REG_PCS_TX_TUS_L              0x438
332 #define P_REG_PCS_TX_TUS_U              0x43C
333 #define P_REG_PAR_RX_TIME_L             0x4F0
334 #define P_REG_PAR_RX_TIME_U             0x4F4
335 #define P_REG_PAR_TX_TIME_L             0x4CC
336 #define P_REG_PAR_TX_TIME_U             0x4D0
337 #define P_REG_PAR_PCS_RX_OFFSET_L       0x4E8
338 #define P_REG_PAR_PCS_RX_OFFSET_U       0x4EC
339 #define P_REG_PAR_PCS_TX_OFFSET_L       0x4C4
340 #define P_REG_PAR_PCS_TX_OFFSET_U       0x4C8
341 #define P_REG_LINK_SPEED                0x4FC
342 #define P_REG_LINK_SPEED_SERDES_S       0
343 #define P_REG_LINK_SPEED_SERDES_M       MAKEMASK(0x7, 0)
344 #define P_REG_LINK_SPEED_FEC_MODE_S     3
345 #define P_REG_LINK_SPEED_FEC_MODE_M     MAKEMASK(0x3, 3)
346 #define P_REG_LINK_SPEED_FEC_MODE(reg)                  \
347         (((reg) & P_REG_LINK_SPEED_FEC_MODE_M) >>       \
348          P_REG_LINK_SPEED_FEC_MODE_S)
349
350 /* PHY timestamp related registers */
351 #define P_REG_PMD_ALIGNMENT             0x0FC
352 #define P_REG_RX_80_TO_160_CNT          0x6FC
353 #define P_REG_RX_80_TO_160_CNT_RXCYC_S  0
354 #define P_REG_RX_80_TO_160_CNT_RXCYC_M  BIT(0)
355 #define P_REG_RX_40_TO_160_CNT          0x8FC
356 #define P_REG_RX_40_TO_160_CNT_RXCYC_S  0
357 #define P_REG_RX_40_TO_160_CNT_RXCYC_M  MAKEMASK(0x3, 0)
358
359 /* Rx FIFO status registers */
360 #define P_REG_RX_OV_FS                  0x4F8
361 #define P_REG_RX_OV_FS_FIFO_STATUS_S    2
362 #define P_REG_RX_OV_FS_FIFO_STATUS_M    MAKEMASK(0x3FF, 2)
363
364 /* Timestamp command registers */
365 #define P_REG_TX_TMR_CMD                0x448
366 #define P_REG_RX_TMR_CMD                0x468
367
368 /* E810 timesync enable register */
369 #define ETH_GLTSYN_ENA(_i)              (0x03000348 + ((_i) * 4))
370
371 /* E810 shadow init time registers */
372 #define ETH_GLTSYN_SHTIME_0(i)          (0x03000368 + ((i) * 32))
373 #define ETH_GLTSYN_SHTIME_L(i)          (0x0300036C + ((i) * 32))
374
375 /* E810 shadow time adjust registers */
376 #define ETH_GLTSYN_SHADJ_L(_i)          (0x03000378 + ((_i) * 32))
377 #define ETH_GLTSYN_SHADJ_H(_i)          (0x0300037C + ((_i) * 32))
378
379 /* E810 timer command register */
380 #define ETH_GLTSYN_CMD                  0x03000344
381
382 /* Source timer incval macros */
383 #define INCVAL_HIGH_M                   0xFF
384
385 /* Timestamp block macros */
386 #define TS_LOW_M                        0xFFFFFFFF
387 #define TS_HIGH_M                       0xFF
388 #define TS_HIGH_S                       32
389
390 #define TS_PHY_LOW_M                    0xFF
391 #define TS_PHY_HIGH_M                   0xFFFFFFFF
392 #define TS_PHY_HIGH_S                   8
393
394 #define BYTES_PER_IDX_ADDR_L_U          8
395 #define BYTES_PER_IDX_ADDR_L            4
396
397 /* Internal PHY timestamp address */
398 #define TS_L(a, idx) ((a) + ((idx) * BYTES_PER_IDX_ADDR_L_U))
399 #define TS_H(a, idx) ((a) + ((idx) * BYTES_PER_IDX_ADDR_L_U +           \
400                              BYTES_PER_IDX_ADDR_L))
401
402 /* External PHY timestamp address */
403 #define TS_EXT(a, port, idx) ((a) + (0x1000 * (port)) +                 \
404                                  ((idx) * BYTES_PER_IDX_ADDR_L_U))
405
406 #define LOW_TX_MEMORY_BANK_START        0x03090000
407 #define HIGH_TX_MEMORY_BANK_START       0x03090004
408
409 /* E810T PCA9575 IO controller registers */
410 #define ICE_PCA9575_P0_IN       0x0
411 #define ICE_PCA9575_P1_IN       0x1
412 #define ICE_PCA9575_P0_CFG      0x8
413 #define ICE_PCA9575_P1_CFG      0x9
414 #define ICE_PCA9575_P0_OUT      0xA
415 #define ICE_PCA9575_P1_OUT      0xB
416
417 /* E810T PCA9575 IO controller pin control */
418 #define ICE_E810T_P0_GNSS_PRSNT_N       BIT(4)
419 #define ICE_E810T_P1_SMA1_DIR_EN        BIT(4)
420 #define ICE_E810T_P1_SMA1_TX_EN         BIT(5)
421 #define ICE_E810T_P1_SMA2_UFL2_RX_DIS   BIT(3)
422 #define ICE_E810T_P1_SMA2_DIR_EN        BIT(6)
423 #define ICE_E810T_P1_SMA2_TX_EN         BIT(7)
424
425 #endif /* _ICE_PTP_HW_H_ */