Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2025 Intel Corporation 3 : : */ 4 : : 5 : : #ifndef _IDPF_PTP_H_ 6 : : #define _IDPF_PTP_H_ 7 : : 8 : : #include "base/idpf_osdep.h" 9 : : #include <rte_time.h> 10 : : #include "idpf_common_device.h" 11 : : 12 : : struct idpf_ptp_cmd { 13 : : uint32_t exec_cmd_mask; 14 : : uint32_t shtime_enable_mask; 15 : : }; 16 : : 17 : : struct idpf_ptp_dev_clk_regs { 18 : : volatile uint32_t *dev_clk_ns_l; 19 : : volatile uint32_t *dev_clk_ns_h; 20 : : volatile uint32_t *phy_clk_ns_l; 21 : : volatile uint32_t *phy_clk_ns_h; 22 : : volatile uint32_t *sys_time_ns_l; 23 : : volatile uint32_t *sys_time_ns_h; 24 : : volatile uint32_t *incval_l; 25 : : volatile uint32_t *incval_h; 26 : : volatile uint32_t *shadj_l; 27 : : volatile uint32_t *shadj_h; 28 : : volatile uint32_t *phy_incval_l; 29 : : volatile uint32_t *phy_incval_h; 30 : : volatile uint32_t *phy_shadj_l; 31 : : volatile uint32_t *phy_shadj_h; 32 : : volatile uint32_t *cmd; 33 : : volatile uint32_t *phy_cmd; 34 : : volatile uint32_t *cmd_sync; 35 : : }; 36 : : 37 : : enum idpf_ptp_access { 38 : : IDPF_PTP_NONE = 0, 39 : : IDPF_PTP_DIRECT, 40 : : IDPF_PTP_MAILBOX, 41 : : }; 42 : : 43 : : struct idpf_ptp_secondary_mbx { 44 : : uint16_t peer_mbx_q_id; 45 : : uint16_t peer_id; 46 : : bool valid:1; 47 : : }; 48 : : 49 : : enum idpf_ptp_tx_tstamp_state { 50 : : IDPF_PTP_FREE, 51 : : IDPF_PTP_REQUEST, 52 : : IDPF_PTP_READ_VALUE, 53 : : }; 54 : : 55 : : struct idpf_ptp_tx_tstamp { 56 : : uint64_t tstamp; 57 : : uint32_t tx_latch_reg_offset_l; 58 : : uint32_t tx_latch_reg_offset_h; 59 : : uint32_t idx; 60 : : }; 61 : : 62 : : struct idpf_ptp_vport_tx_tstamp_caps { 63 : : uint32_t vport_id; 64 : : uint16_t num_entries; 65 : : uint16_t tstamp_ns_lo_bit; 66 : : uint16_t latched_idx; 67 : : bool access:1; 68 : : struct idpf_ptp_tx_tstamp tx_tstamp[]; 69 : : }; 70 : : 71 : : struct idpf_ptp { 72 : : uint64_t base_incval; 73 : : uint64_t max_adj; 74 : : struct idpf_ptp_cmd cmd; 75 : : struct idpf_ptp_dev_clk_regs dev_clk_regs; 76 : : uint32_t caps; 77 : : uint8_t get_dev_clk_time_access:2; 78 : : uint8_t get_cross_tstamp_access:2; 79 : : uint8_t set_dev_clk_time_access:2; 80 : : uint8_t adj_dev_clk_time_access:2; 81 : : uint8_t tx_tstamp_access:2; 82 : : uint8_t rsv:6; 83 : : struct idpf_ptp_secondary_mbx secondary_mbx; 84 : : }; 85 : : 86 : : struct idpf_ptp_dev_timers { 87 : : uint64_t sys_time_ns; 88 : : uint64_t dev_clk_time_ns; 89 : : }; 90 : : 91 : : int idpf_ptp_get_caps(struct idpf_adapter *adapter); 92 : : int idpf_ptp_read_src_clk_reg(struct idpf_adapter *adapter, uint64_t *src_clk); 93 : : int idpf_ptp_get_dev_clk_time(struct idpf_adapter *adapter, 94 : : struct idpf_ptp_dev_timers *dev_clk_time); 95 : : int idpf_ptp_get_cross_time(struct idpf_adapter *adapter, 96 : : struct idpf_ptp_dev_timers *cross_time); 97 : : int idpf_ptp_set_dev_clk_time(struct idpf_adapter *adapter, uint64_t time); 98 : : int idpf_ptp_adj_dev_clk_fine(struct idpf_adapter *adapter, uint64_t incval); 99 : : int idpf_ptp_adj_dev_clk_time(struct idpf_adapter *adapter, int64_t delta); 100 : : int idpf_ptp_get_vport_tstamps_caps(struct idpf_vport *vport); 101 : : int idpf_ptp_get_tx_tstamp(struct idpf_vport *vport); 102 : : 103 : : static inline uint64_t 104 : : idpf_tstamp_convert_32b_64b(struct idpf_adapter *ad, uint32_t flag, 105 : : bool is_rx, uint32_t in_timestamp) 106 : : { 107 : : const uint64_t mask = 0xFFFFFFFFULL; 108 : : uint32_t phc_time_lo, delta; 109 : : uint64_t ns; 110 : : 111 [ # # # # : 0 : if (flag != 0) # # ] 112 : 0 : idpf_ptp_read_src_clk_reg(ad, &ad->time_hw); 113 : : 114 : 0 : phc_time_lo = (uint32_t)(ad->time_hw); 115 : 0 : delta = in_timestamp - phc_time_lo; 116 : : 117 [ # # # # : 0 : if (delta > mask / 2) { # # ] 118 : 0 : delta = phc_time_lo - in_timestamp; 119 : 0 : ns = ad->time_hw - delta; 120 : : } else { 121 : : if (is_rx) 122 : 0 : ns = ad->time_hw - delta; 123 : : else 124 : 0 : ns = ad->time_hw + delta; 125 : : } 126 : : 127 : : return ns; 128 : : } 129 : : 130 : : #endif /* _IDPF_PTP_H_ */