implement support for PTP on E822 hardware
Subsystems (2)
v3 cover implement support for PTP on E822 hardware
Extend the ice driver implementation to support PTP for the E822 based devices.
This includes a few cleanup patches, that fix some minor issues spotted while preparing them. In addition, there are some slight refactors to ease the addition of E822 support, followed by adding the new hardware implementation ice_ptp_hw.c.
There are a few major differences with E822 support compared to E810 support:
*) The E822 device has a Clock Generation Unit which must be initialized in order to generate proper clock frequencies on the output that drives the PTP hardware clock registers
*) The E822 PHY is a bit different and requires a more complex initialization procedure which must be rerun any time the link configuration changes.
*) The E822 devices support enhanced timestamp calibration by making use of a process called Vernier offset measurement. This allows the hardware to measure phase offset related to the PHY clocks for Serdes and FEC, reducing the inaccuracy of the timestamp relative to the actual packet transmission and receipt. Making use of this requires data gathered from the first transmitted and received packets, and waiting for the PHY to complete the calibration measurements. This is done as part of a new kthread, ov_work. Note that to avoid delay in enabling timestamps, we start the PHY in 'bypass' mode which allows timestamps to be captured without the Vernier calibration measurement. Once the first packets have been sent and received, we then complete the calibration setup and exit bypass mode and begin using the more precise timestamps. According to the datasheet, timestamps without calibration data can be incorrect relative to actual receipt or transmission by up to 1 clock cycle (~1.25 nanoseconds), while calibrated timestamps should be correct to within 1/8th of a clock cycle (~0.15 nanoseconds).
*) E822 devices support crosstimestamping via PCIe PTM, which we enable when available on the platform.
There is a fair amount of logic required to perform PHY and CGU initialization, which is the vast majority of the new code, but it is fairly self contained within ice_ptp_hw.c, with the exception of monitoring for offset validity being handled by a kthread.
Changes since v2:
* introduced helper functions to enable and disable clock outputs
Changes since v1:
* Rebased on top of IWL to resolve conflict
* Fixed build against non-X86 arch for the PCIe PTM support
Jacob Keller (13):
ice: fix Tx queue iteration for Tx timestamp enablement
ice: remove dead code for allocating pin_config
ice: add lock around Tx timestamp tracker flush
ice: restart periodic outputs around time changes
ice: introduce ice_base_incval function
ice: PTP: move setting of tstamp_config
ice: use 'int err' instead of 'int status'
ice: introduce ice_ptp_init_phc function
ice: convert clk_freq capability into time_ref
ice: implement basic E822 PTP support
ice: ensure the hardware Clock Generation Unit is configured
ice: exit bypass mode once hardware finishes timestamp calibration
ice: support crosstimestamping on E822 devices if supported
drivers/net/ethernet/intel/Kconfig | 10 + drivers/net/ethernet/intel/ice/ice_cgu_regs.h | 116 + drivers/net/ethernet/intel/ice/ice_common.c | 12 + .../net/ethernet/intel/ice/ice_hw_autogen.h | 9 + drivers/net/ethernet/intel/ice/ice_main.c | 7 + drivers/net/ethernet/intel/ice/ice_ptp.c | 717 ++++- drivers/net/ethernet/intel/ice/ice_ptp.h | 30 +- .../net/ethernet/intel/ice/ice_ptp_consts.h | 374 +++ drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 2794 ++++++++++++++++- drivers/net/ethernet/intel/ice/ice_ptp_hw.h | 345 ++ drivers/net/ethernet/intel/ice/ice_type.h | 23 +- 11 files changed, 4226 insertions(+), 211 deletions(-) create mode 100644 drivers/net/ethernet/intel/ice/ice_cgu_regs.h create mode 100644 drivers/net/ethernet/intel/ice/ice_ptp_consts.h
base-commit: 6e3c27180bcf2635f537ff63164e8df9773b56fb
Signature · 1 line
2.31.1.331.gb0c09ab8796f
PATCH v3 1/13 ice: fix Tx queue iteration for Tx timestamp enablement
The driver accidentally copied the ice_for_each_rxq iterator when implementing enablement of the ptp_tx bit for the Tx rings. We still load the Tx rings and set the ptp_tx field, but we iterate over the count of the num_rxq.
If the number of Tx and Rx queues differ, this could either cause a buffer overrun when accessing the tx_rings list if num_txq is greater than num_rxq, or it could cause us to fail to enable Tx timestamps for some rings.
This was not noticed originally as we generally have the same number of Tx and Rx queues.
--- drivers/net/ethernet/intel/ice/ice_ptp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_ptp.c +1 -1
@@ -22,7 +22,7 @@ static void ice_set_tx_tstamp(struct ice_pf *pf, bool on)return ;/* Set the timestamp enable flag for all the Tx rings */ -ice_for_each_rxq (vsi, i) { +ice_for_each_txq (vsi, i) {if (!vsi->tx_rings[i])continue ; vsi->tx_rings[i]->ptp_tx = on;
Signature · 1 line
2.31.1.331.gb0c09ab8796f
PATCH v3 2/13 ice: remove dead code for allocating pin_config
In reply to Jacob KellerWe have code in the ice driver which allocates the pin_config structure if n_pins is > 0, but we never set n_pins to be greater than zero. There's no reason to keep this code until we actually have pin_config support. Remove this. We can re-add it properly when we implement support for pin_config for E810-T devices.
--- drivers/net/ethernet/intel/ice/ice_ptp.c | 11 ----------- 1 file changed, 11 deletions(-)
drivers/net/ethernet/intel/ice/ice_ptp.c +0 -11
@@ -1064,17 +1064,6 @@ static long ice_ptp_create_clock(struct ice_pf *pf) info = &pf->ptp.info; dev =ice_pf_to_dev (pf); -/* Allocate memory for kernel pins interface */ -if (info->n_pins) { - info->pin_config =devm_kcalloc (dev, info->n_pins, -sizeof (*info->pin_config), -GFP_KERNEL ); -if (!info->pin_config) { - info->n_pins =0 ; -return -ENOMEM ; - } - } -/* Attempt to register the clock before enabling the hardware. */ clock =ptp_clock_register (info, dev);if (IS_ERR (clock))
Signature · 1 line
2.31.1.331.gb0c09ab8796f
PATCH v3 3/13 ice: add lock around Tx timestamp tracker flush
In reply to Jacob KellerThe driver didn't take the lock while flushing the Tx tracker, which could cause a race where one thread is trying to read timestamps out while another thread is trying to read the tracker to check the timestamps.
Avoid this by ensuring that flushing is locked against read accesses.
--- drivers/net/ethernet/intel/ice/ice_ptp.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/ethernet/intel/ice/ice_ptp.c +4 -0
@@ -1267,6 +1267,8 @@ ice_ptp_flush_tx_tracker(struct ice_pf *pf, struct ice_ptp_tx *tx) {u8 idx; +spin_lock (&tx->lock); +for (idx =0 ; idx < tx->len; idx++) {u8 phy_idx = idx + tx->quad_offset;
@@ -1279,6 +1281,8 @@ ice_ptp_flush_tx_tracker(struct ice_pf *pf, struct ice_ptp_tx *tx) tx->tstamps[idx].skb =NULL ; } } + +spin_unlock (&tx->lock); }/**
Signature · 1 line
2.31.1.331.gb0c09ab8796f
PATCH v3 4/13 ice: restart periodic outputs around time changes
In reply to Jacob KellerWen we enabled auxiliary input/output support for the E810 device, we forgot to add logic to restart the output when we change time. This is important as the periodic output will be incorrect after a time change otherwise.
This unfortunately includes the adjust time function, even though it uses an atomic hardware interface. The atomic adjustment can still cause the pin output to stall permanently, so we need to stop and restart it.
Introduce wrapper functions to temporarily disable and then re-enable the clock outputs.
--- drivers/net/ethernet/intel/ice/ice_ptp.c | 49 ++++++++++++++++++++++++ 1 file changed, 49 insertions(+)
drivers/net/ethernet/intel/ice/ice_ptp.c +49 -0
@@ -688,6 +688,41 @@ static int ice_ptp_cfg_clkout(struct ice_pf *pf, unsigned int chan,return -EFAULT ; } +/** +* ice_ptp_disable_all_clkout - Disable all currently configured outputs +* @pf: pointer to the PF structure +* +* Disable all currently configured clock outputs. This is necessary before +* certain changes to the PTP hardware clock. Use ice_ptp_enable_all_clkout to +* re-enable the clocks again. +*/ +static void ice_ptp_disable_all_clkout (struct ice_pf *pf) +{ +uint i; + +for (i =0 ; i < pf->ptp.info.n_per_out; i++) +if (pf->ptp.perout_channels[i].ena) +ice_ptp_cfg_clkout (pf, i,NULL , false); +} + +/** +* ice_ptp_enable_all_clkout - Enable all configured periodic clock outputs +* @pf: pointer to the PF structure +* +* Enable all currently configured clock outputs. Use this after +* ice_ptp_disable_all_clkout to reconfigure the output signals according to +* their configuration. +*/ +static void ice_ptp_enable_all_clkout (struct ice_pf *pf) +{ +uint i; + +for (i =0 ; i < pf->ptp.info.n_per_out; i++) +if (pf->ptp.perout_channels[i].ena) +ice_ptp_cfg_clkout (pf, i, &pf->ptp.perout_channels[i], + false); +} +/** * ice_ptp_gpio_enable_e810 - Enable/disable ancillary features of PHC * @info: the driver's PTP info structure
@@ -783,12 +818,17 @@ ice_ptp_settime64(struct ptp_clock_info *info, const struct timespec64 *ts) goto exit; } +/* Disable periodic outputs */ +ice_ptp_disable_all_clkout (pf); + err =ice_ptp_write_init (pf, &ts64);ice_ptp_unlock (hw);if (!err)ice_ptp_update_cached_phctime (pf); +/* Reenable periodic outputs */ +ice_ptp_enable_all_clkout (pf); exit:if (err) {dev_err (ice_pf_to_dev (pf),"PTP failed to set time %d\n" , err);
@@ -842,8 +882,14 @@ static int ice_ptp_adjtime(struct ptp_clock_info *info, s64 delta)return -EBUSY ; } +/* Disable periodic outputs */ +ice_ptp_disable_all_clkout (pf); + err =ice_ptp_write_adj (pf, delta); +/* Reenable periodic outputs */ +ice_ptp_enable_all_clkout (pf); +ice_ptp_unlock (hw);if (err) {
@@ -1543,6 +1589,9 @@ void ice_ptp_release(struct ice_pf *pf)if (!pf->ptp.clock)return ; +/* Disable periodic outputs */ +ice_ptp_disable_all_clkout (pf); +ice_clear_ptp_clock_index (pf);ptp_clock_unregister (pf->ptp.clock); pf->ptp.clock =NULL ;
Signature · 1 line
2.31.1.331.gb0c09ab8796f
PATCH v3 5/13 ice: introduce ice_base_incval function
In reply to Jacob KellerA future change will add additional possible increment values for the E822 device support. To handle this, we want to look up the increment value to use instead of hard coding it to the nominal value for E810 devices. Introduce ice_base_incval as a function to get the best nominal increment value to use.
For now, it just returns the E810 value, but will be refactored in the future to look up the value based on the device type and configured clock frequency.
--- drivers/net/ethernet/intel/ice/ice_ptp.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/ice/ice_ptp.c +16 -2
@@ -435,6 +435,20 @@ static int ice_ptp_write_adj(struct ice_pf *pf, s32 adj)return ice_ptp_adj_clock (hw, adj); } +/** +* ice_base_incval - Get base timer increment value +* @pf: Board private structure +* +* Look up the base timer increment value for this device. The base increment +* value is used to define the nominal clock tick rate. This increment value +* is programmed during device initialization. It is also used as the basis +* for calculating adjustments using scaled_ppm. +*/ +static u64 ice_base_incval (struct ice_pf *pf) +{ +return ICE_PTP_NOMINAL_INCVAL_E810 ; +} +/** * ice_ptp_adjfine - Adjust clock increment rate * @info: the driver's PTP info structure
@@ -452,7 +466,7 @@ static int ice_ptp_adjfine(struct ptp_clock_info *info, long scaled_ppm)int neg_adj =0 ;int err; - incval =ICE_PTP_NOMINAL_INCVAL_E810 ; + incval =ice_base_incval (pf);if (scaled_ppm <0 ) { neg_adj =1 ;
@@ -1465,7 +1479,7 @@ static int ice_ptp_init_owner(struct ice_pf *pf) }/* Write the increment time value to PHY and LAN */ - err =ice_ptp_write_incval (hw,ICE_PTP_NOMINAL_INCVAL_E810 ); + err =ice_ptp_write_incval (hw,ice_base_incval (pf));if (err) {ice_ptp_unlock (hw); goto err_exit;
Signature · 1 line
2.31.1.331.gb0c09ab8796f
PATCH v3 6/13 ice: PTP: move setting of tstamp_config
In reply to Jacob KellerThe tstamp_config structure is being set inside of ice_ptp_cfg_timestamp, which is the function used to set Tx and Rx timestamping during initialization.
This function is also used in order to set the PHY port timestamping status. However, it makes sense to always set the tstamp_config directly whenever the ice_set_tx_tstamp or ice_set_rx_tstamp functions are called.
Move assignment of tstamp_config into the related functions and out of ice_ptp_cfg_timestamp.
--- drivers/net/ethernet/intel/ice/ice_ptp.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/net/ethernet/intel/ice/ice_ptp.c +10 -9
@@ -35,6 +35,11 @@ static void ice_set_tx_tstamp(struct ice_pf *pf, bool on)else val &= ~PFINT_OICR_TSYN_TX_M ;wr32 (&pf->hw,PFINT_OICR_ENA , val); + +if (on) + pf->ptp.tstamp_config.tx_type =HWTSTAMP_TX_ON ; +else + pf->ptp.tstamp_config.tx_type =HWTSTAMP_TX_OFF ; }/**
@@ -57,6 +62,11 @@ static void ice_set_rx_tstamp(struct ice_pf *pf, bool on)continue ; vsi->rx_rings[i]->ptp_rx = on; } + +if (on) + pf->ptp.tstamp_config.rx_filter =HWTSTAMP_FILTER_ALL ; +else + pf->ptp.tstamp_config.rx_filter =HWTSTAMP_FILTER_NONE ; }/**
@@ -71,14 +81,6 @@ static void ice_ptp_cfg_timestamp(struct ice_pf *pf, bool ena) {ice_set_tx_tstamp (pf, ena);ice_set_rx_tstamp (pf, ena); - -if (ena) { - pf->ptp.tstamp_config.rx_filter =HWTSTAMP_FILTER_ALL ; - pf->ptp.tstamp_config.tx_type =HWTSTAMP_TX_ON ; - }else { - pf->ptp.tstamp_config.rx_filter =HWTSTAMP_FILTER_NONE ; - pf->ptp.tstamp_config.tx_type =HWTSTAMP_TX_OFF ; - } }/**
@@ -977,7 +979,6 @@ ice_ptp_set_timestamp_mode(struct ice_pf *pf, struct hwtstamp_config *config)case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ :case HWTSTAMP_FILTER_NTP_ALL :case HWTSTAMP_FILTER_ALL : - config->rx_filter =HWTSTAMP_FILTER_ALL ;ice_set_rx_tstamp (pf, true);break ;default :
Signature · 1 line
2.31.1.331.gb0c09ab8796f
PATCH v3 7/13 ice: use 'int err' instead of 'int status'
In reply to Jacob KellerThe ice_ptp_hw.c file introduced a bunch of uses of "int status" instead of the more traditional "int err" or "int ret". These are actually traditional Linux error codes (as opposed to the ice_status enumeration values), so lets convert them all now to use "int err" for clarity. This is likely an artifact of refactoring this code to minimize the use of ice_status enumeration in preparation for removing it. We want to avoid adding any new usages of the status enum.
--- drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 206 ++++++++++---------- 1 file changed, 103 insertions(+), 103 deletions(-)
drivers/net/ethernet/intel/ice/ice_ptp_hw.c +103 -103
@@ -68,18 +68,18 @@ u8 ice_get_ptp_src_clock_index(struct ice_hw *hw)static int ice_read_phy_reg_e810 (struct ice_hw *hw,u32 addr,u32 *val) {struct ice_sbq_msg_input msg = {0 }; -int status; +int err; msg.msg_addr_low =lower_16_bits (addr); msg.msg_addr_high =upper_16_bits (addr); msg.opcode = ice_sbq_msg_rd; msg.dest_dev = rmn_0; - status =ice_sbq_rw_reg (hw, &msg); -if (status) { -ice_debug (hw,ICE_DBG_PTP ,"Failed to send message to PHY, status %d\n" , - status); -return status; + err =ice_sbq_rw_reg (hw, &msg); +if (err) { +ice_debug (hw,ICE_DBG_PTP ,"Failed to send message to PHY, err %d\n" , + err); +return err; } *val = msg.data;
@@ -98,7 +98,7 @@ static int ice_read_phy_reg_e810(struct ice_hw *hw, u32 addr, u32 *val)static int ice_write_phy_reg_e810 (struct ice_hw *hw,u32 addr,u32 val) {struct ice_sbq_msg_input msg = {0 }; -int status; +int err; msg.msg_addr_low =lower_16_bits (addr); msg.msg_addr_high =upper_16_bits (addr);
@@ -106,11 +106,11 @@ static int ice_write_phy_reg_e810(struct ice_hw *hw, u32 addr, u32 val) msg.dest_dev = rmn_0; msg.data = val; - status =ice_sbq_rw_reg (hw, &msg); -if (status) { -ice_debug (hw,ICE_DBG_PTP ,"Failed to send message to PHY, status %d\n" , - status); -return status; + err =ice_sbq_rw_reg (hw, &msg); +if (err) { +ice_debug (hw,ICE_DBG_PTP ,"Failed to send message to PHY, err %d\n" , + err); +return err; }return 0 ;
@@ -130,23 +130,23 @@ static int ice_read_phy_tstamp_e810(struct ice_hw *hw, u8 lport, u8 idx, u64 *tstamp) { u32 lo_addr, hi_addr, lo, hi; -int status; +int err; lo_addr =TS_EXT (LOW_TX_MEMORY_BANK_START , lport, idx); hi_addr =TS_EXT (HIGH_TX_MEMORY_BANK_START , lport, idx); - status =ice_read_phy_reg_e810 (hw, lo_addr, &lo); -if (status) { -ice_debug (hw,ICE_DBG_PTP ,"Failed to read low PTP timestamp register, status %d\n" , - status); -return status; + err =ice_read_phy_reg_e810 (hw, lo_addr, &lo); +if (err) { +ice_debug (hw,ICE_DBG_PTP ,"Failed to read low PTP timestamp register, err %d\n" , + err); +return err; } - status =ice_read_phy_reg_e810 (hw, hi_addr, &hi); -if (status) { -ice_debug (hw,ICE_DBG_PTP ,"Failed to read high PTP timestamp register, status %d\n" , - status); -return status; + err =ice_read_phy_reg_e810 (hw, hi_addr, &hi); +if (err) { +ice_debug (hw,ICE_DBG_PTP ,"Failed to read high PTP timestamp register, err %d\n" , + err); +return err; }/* For E810 devices, the timestamp is reported with the lower 32 bits
@@ -169,23 +169,23 @@ ice_read_phy_tstamp_e810(struct ice_hw *hw, u8 lport, u8 idx, u64 *tstamp)static int ice_clear_phy_tstamp_e810 (struct ice_hw *hw,u8 lport,u8 idx) {u32 lo_addr, hi_addr; -int status; +int err; lo_addr =TS_EXT (LOW_TX_MEMORY_BANK_START , lport, idx); hi_addr =TS_EXT (HIGH_TX_MEMORY_BANK_START , lport, idx); - status =ice_write_phy_reg_e810 (hw, lo_addr,0 ); -if (status) { -ice_debug (hw,ICE_DBG_PTP ,"Failed to clear low PTP timestamp register, status %d\n" , - status); -return status; + err =ice_write_phy_reg_e810 (hw, lo_addr,0 ); +if (err) { +ice_debug (hw,ICE_DBG_PTP ,"Failed to clear low PTP timestamp register, err %d\n" , + err); +return err; } - status =ice_write_phy_reg_e810 (hw, hi_addr,0 ); -if (status) { -ice_debug (hw,ICE_DBG_PTP ,"Failed to clear high PTP timestamp register, status %d\n" , - status); -return status; + err =ice_write_phy_reg_e810 (hw, hi_addr,0 ); +if (err) { +ice_debug (hw,ICE_DBG_PTP ,"Failed to clear high PTP timestamp register, err %d\n" , + err); +return err; }return 0 ;
@@ -200,17 +200,17 @@ static int ice_clear_phy_tstamp_e810(struct ice_hw *hw, u8 lport, u8 idx)*/ int ice_ptp_init_phy_e810 (struct ice_hw *hw) { -int status;u8 tmr_idx; +int err; tmr_idx = hw->func_caps.ts_func_info.tmr_index_owned; - status =ice_write_phy_reg_e810 (hw,ETH_GLTSYN_ENA (tmr_idx), -GLTSYN_ENA_TSYN_ENA_M ); -if (status) + err =ice_write_phy_reg_e810 (hw,ETH_GLTSYN_ENA (tmr_idx), +GLTSYN_ENA_TSYN_ENA_M ); +if (err)ice_debug (hw,ICE_DBG_PTP ,"PTP failed in ena_phy_time_syn %d\n" , - status); + err); -return status; +return err; }/**
@@ -227,22 +227,22 @@ int ice_ptp_init_phy_e810(struct ice_hw *hw)*/ static int ice_ptp_prep_phy_time_e810 (struct ice_hw *hw,u32 time) { -int status;u8 tmr_idx; +int err; tmr_idx = hw->func_caps.ts_func_info.tmr_index_owned; - status =ice_write_phy_reg_e810 (hw,ETH_GLTSYN_SHTIME_0 (tmr_idx),0 ); -if (status) { -ice_debug (hw,ICE_DBG_PTP ,"Failed to write SHTIME_0, status %d\n" , - status); -return status; + err =ice_write_phy_reg_e810 (hw,ETH_GLTSYN_SHTIME_0 (tmr_idx),0 ); +if (err) { +ice_debug (hw,ICE_DBG_PTP ,"Failed to write SHTIME_0, err %d\n" , + err); +return err; } - status =ice_write_phy_reg_e810 (hw,ETH_GLTSYN_SHTIME_L (tmr_idx), time); -if (status) { -ice_debug (hw,ICE_DBG_PTP ,"Failed to write SHTIME_L, status %d\n" , - status); -return status; + err =ice_write_phy_reg_e810 (hw,ETH_GLTSYN_SHTIME_L (tmr_idx), time); +if (err) { +ice_debug (hw,ICE_DBG_PTP ,"Failed to write SHTIME_L, err %d\n" , + err); +return err; }return 0 ;
@@ -263,26 +263,26 @@ static int ice_ptp_prep_phy_time_e810(struct ice_hw *hw, u32 time)*/ static int ice_ptp_prep_phy_adj_e810 (struct ice_hw *hw,s32 adj) { -int status;u8 tmr_idx; +int err; tmr_idx = hw->func_caps.ts_func_info.tmr_index_owned;/* Adjustments are represented as signed 2's complement values in * nanoseconds. Sub-nanosecond adjustment is not supported. */ - status =ice_write_phy_reg_e810 (hw,ETH_GLTSYN_SHADJ_L (tmr_idx),0 ); -if (status) { -ice_debug (hw,ICE_DBG_PTP ,"Failed to write adj to PHY SHADJ_L, status %d\n" , - status); -return status; + err =ice_write_phy_reg_e810 (hw,ETH_GLTSYN_SHADJ_L (tmr_idx),0 ); +if (err) { +ice_debug (hw,ICE_DBG_PTP ,"Failed to write adj to PHY SHADJ_L, err %d\n" , + err); +return err; } - status =ice_write_phy_reg_e810 (hw,ETH_GLTSYN_SHADJ_H (tmr_idx), adj); -if (status) { -ice_debug (hw,ICE_DBG_PTP ,"Failed to write adj to PHY SHADJ_H, status %d\n" , - status); -return status; + err =ice_write_phy_reg_e810 (hw,ETH_GLTSYN_SHADJ_H (tmr_idx), adj); +if (err) { +ice_debug (hw,ICE_DBG_PTP ,"Failed to write adj to PHY SHADJ_H, err %d\n" , + err); +return err; }return 0 ;
@@ -300,25 +300,25 @@ static int ice_ptp_prep_phy_adj_e810(struct ice_hw *hw, s32 adj)static int ice_ptp_prep_phy_incval_e810 (struct ice_hw *hw,u64 incval) {u32 high, low; -int status;u8 tmr_idx; +int err; tmr_idx = hw->func_caps.ts_func_info.tmr_index_owned; low =lower_32_bits (incval); high =upper_32_bits (incval); - status =ice_write_phy_reg_e810 (hw,ETH_GLTSYN_SHADJ_L (tmr_idx), low); -if (status) { -ice_debug (hw,ICE_DBG_PTP ,"Failed to write incval to PHY SHADJ_L, status %d\n" , - status); -return status; + err =ice_write_phy_reg_e810 (hw,ETH_GLTSYN_SHADJ_L (tmr_idx), low); +if (err) { +ice_debug (hw,ICE_DBG_PTP ,"Failed to write incval to PHY SHADJ_L, err %d\n" , + err); +return err; } - status =ice_write_phy_reg_e810 (hw,ETH_GLTSYN_SHADJ_H (tmr_idx), high); -if (status) { -ice_debug (hw,ICE_DBG_PTP ,"Failed to write incval PHY SHADJ_H, status %d\n" , - status); -return status; + err =ice_write_phy_reg_e810 (hw,ETH_GLTSYN_SHADJ_H (tmr_idx), high); +if (err) { +ice_debug (hw,ICE_DBG_PTP ,"Failed to write incval PHY SHADJ_H, err %d\n" , + err); +return err; }return 0 ;
@@ -335,7 +335,7 @@ static int ice_ptp_prep_phy_incval_e810(struct ice_hw *hw, u64 incval)static int ice_ptp_port_cmd_e810 (struct ice_hw *hw,enum ice_ptp_tmr_cmd cmd) {u32 cmd_val, val; -int status; +int err;switch (cmd) {case INIT_TIME :
@@ -356,20 +356,20 @@ static int ice_ptp_port_cmd_e810(struct ice_hw *hw, enum ice_ptp_tmr_cmd cmd) }/* Read, modify, write */ - status =ice_read_phy_reg_e810 (hw,ETH_GLTSYN_CMD , &val); -if (status) { -ice_debug (hw,ICE_DBG_PTP ,"Failed to read GLTSYN_CMD, status %d\n" , status); -return status; + err =ice_read_phy_reg_e810 (hw,ETH_GLTSYN_CMD , &val); +if (err) { +ice_debug (hw,ICE_DBG_PTP ,"Failed to read GLTSYN_CMD, err %d\n" , err); +return err; }/* Modify necessary bits only and perform write */ val &= ~TS_CMD_MASK_E810 ; val |= cmd_val; - status =ice_write_phy_reg_e810 (hw,ETH_GLTSYN_CMD , val); -if (status) { -ice_debug (hw,ICE_DBG_PTP ,"Failed to write back GLTSYN_CMD, status %d\n" , status); -return status; + err =ice_write_phy_reg_e810 (hw,ETH_GLTSYN_CMD , val); +if (err) { +ice_debug (hw,ICE_DBG_PTP ,"Failed to write back GLTSYN_CMD, err %d\n" , err); +return err; }return 0 ;
@@ -480,17 +480,17 @@ static void ice_ptp_src_cmd(struct ice_hw *hw, enum ice_ptp_tmr_cmd cmd)*/ static int ice_ptp_tmr_cmd (struct ice_hw *hw,enum ice_ptp_tmr_cmd cmd) { -int status; +int err;/* First, prepare the source timer */ ice_ptp_src_cmd (hw, cmd);/* Next, prepare the ports */ - status =ice_ptp_port_cmd_e810 (hw, cmd); -if (status) { -ice_debug (hw,ICE_DBG_PTP ,"Failed to prepare PHY ports for timer command %u, status %d\n" , - cmd, status); -return status; + err =ice_ptp_port_cmd_e810 (hw, cmd); +if (err) { +ice_debug (hw,ICE_DBG_PTP ,"Failed to prepare PHY ports for timer command %u, err %d\n" , + cmd, err); +return err; }/* Write the sync command register to drive both source and PHY timer commands
@@ -516,8 +516,8 @@ static int ice_ptp_tmr_cmd(struct ice_hw *hw, enum ice_ptp_tmr_cmd cmd)*/ int ice_ptp_init_time (struct ice_hw *hw,u64 time) { -int status;u8 tmr_idx; +int err; tmr_idx = hw->func_caps.ts_func_info.tmr_index_owned;
@@ -528,9 +528,9 @@ int ice_ptp_init_time(struct ice_hw *hw, u64 time)/* PHY timers */ /* Fill Rx and Tx ports and send msg to PHY */ - status =ice_ptp_prep_phy_time_e810 (hw, time &0xFFFFFFFF ); -if (status) -return status; + err =ice_ptp_prep_phy_time_e810 (hw, time &0xFFFFFFFF ); +if (err) +return err;return ice_ptp_tmr_cmd (hw,INIT_TIME ); }
@@ -551,8 +551,8 @@ int ice_ptp_init_time(struct ice_hw *hw, u64 time)*/ int ice_ptp_write_incval (struct ice_hw *hw,u64 incval) { -int status;u8 tmr_idx; +int err; tmr_idx = hw->func_caps.ts_func_info.tmr_index_owned;
@@ -560,9 +560,9 @@ int ice_ptp_write_incval(struct ice_hw *hw, u64 incval)wr32 (hw,GLTSYN_SHADJ_L (tmr_idx),lower_32_bits (incval));wr32 (hw,GLTSYN_SHADJ_H (tmr_idx),upper_32_bits (incval)); - status =ice_ptp_prep_phy_incval_e810 (hw, incval); -if (status) -return status; + err =ice_ptp_prep_phy_incval_e810 (hw, incval); +if (err) +return err;return ice_ptp_tmr_cmd (hw,INIT_INCVAL ); }
@@ -576,16 +576,16 @@ int ice_ptp_write_incval(struct ice_hw *hw, u64 incval)*/ int ice_ptp_write_incval_locked (struct ice_hw *hw,u64 incval) { -int status; +int err;if (!ice_ptp_lock (hw))return -EBUSY ; - status =ice_ptp_write_incval (hw, incval); + err =ice_ptp_write_incval (hw, incval);ice_ptp_unlock (hw); -return status; +return err; }/**
@@ -603,8 +603,8 @@ int ice_ptp_write_incval_locked(struct ice_hw *hw, u64 incval)*/ int ice_ptp_adj_clock (struct ice_hw *hw,s32 adj) { -int status;u8 tmr_idx; +int err; tmr_idx = hw->func_caps.ts_func_info.tmr_index_owned;
@@ -616,9 +616,9 @@ int ice_ptp_adj_clock(struct ice_hw *hw, s32 adj)wr32 (hw,GLTSYN_SHADJ_L (tmr_idx),0 );wr32 (hw,GLTSYN_SHADJ_H (tmr_idx), adj); - status =ice_ptp_prep_phy_adj_e810 (hw, adj); -if (status) -return status; + err =ice_ptp_prep_phy_adj_e810 (hw, adj); +if (err) +return err;return ice_ptp_tmr_cmd (hw,ADJ_TIME ); }
Signature · 1 line
2.31.1.331.gb0c09ab8796f
PATCH v3 8/13 ice: introduce ice_ptp_init_phc function
In reply to Jacob KellerWhen we enable support for E822 devices, there are some additional steps required to initialize the PTP hardware clock. To make this easier to implement as device-specific behavior, refactor the register setups in ice_ptp_init_owner to a new ice_ptp_init_phc function defined in ice_ptp_hw.c
This function will have a common section, and an e810 specific sub-implementation.
This will enable easily extending the functionality to cover the E822 specific setup required to initialize the hardware clock generation unit. It also makes it clear which steps are E810 specific vs which ones are necessary for all ice devices.
--- drivers/net/ethernet/intel/ice/ice_ptp.c | 38 +++++++++------------ drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 34 ++++++++++++++++++ drivers/net/ethernet/intel/ice/ice_ptp_hw.h | 1 + 3 files changed, 52 insertions(+), 21 deletions(-)
drivers/net/ethernet/intel/ice/ice_ptp.c +17 -21
@@ -1454,24 +1454,14 @@ static int ice_ptp_init_owner(struct ice_pf *pf)struct device *dev =ice_pf_to_dev (pf);struct ice_hw *hw = &pf->hw;struct timespec64 ts; -u8 src_idx;int err; -wr32 (hw,GLTSYN_SYNC_DLAY ,0 ); - -/* Clear some HW residue and enable source clock */ - src_idx = hw->func_caps.ts_func_info.tmr_index_owned; - -/* Enable source clocks */ -wr32 (hw,GLTSYN_ENA (src_idx),GLTSYN_ENA_TSYN_ENA_M ); - -/* Enable PHY time sync */ - err =ice_ptp_init_phy_e810 (hw); -if (err) - goto err_exit; - -/* Clear event status indications for auxiliary pins */ - (void )rd32 (hw,GLTSYN_STAT (src_idx)); + err =ice_ptp_init_phc (hw); +if (err) { +dev_err (dev,"Failed to initialize PHC, err %d\n" , + err); +return err; + }/* Acquire the global hardware lock */ if (!ice_ptp_lock (hw)) {
@@ -1516,12 +1506,16 @@ static int ice_ptp_init_owner(struct ice_pf *pf) }/** -* ice_ptp_init - Initialize the PTP support after device probe or reset +* ice_ptp_init - Initialize PTP hardware clock support * @pf: Board private structure * -* This function sets device up for PTP support. The first time it is run, it -* will create a clock device. It does not create a clock device if one -* already exists. It also reconfigures the device after a reset. +* Setup the device for interacting with the PTP hardware clock for all +* functions, both the function that owns the clock hardware, and the +* functions connected to the clock hardware. +* +* The clock owner will allocate and register a ptp_clock with the +* PTP_1588_CLOCK infrastructure. All functions allocate a kthread and work +* items used for asynchronous work such as Tx timestamps and periodic work. */ void ice_ptp_init (struct ice_pf *pf) {
@@ -1534,7 +1528,9 @@ void ice_ptp_init(struct ice_pf *pf)if (!ice_is_e810 (hw))return ; -/* Check if this PF owns the source timer */ +/* If this function owns the clock hardware, it must allocate and +* configure the PTP clock device to represent it. +*/ if (hw->func_caps.ts_func_info.src_tmr_owned) { err =ice_ptp_init_owner (pf);if (err)
drivers/net/ethernet/intel/ice/ice_ptp_hw.c +34 -0
@@ -213,6 +213,21 @@ int ice_ptp_init_phy_e810(struct ice_hw *hw)return err; } +/** +* ice_ptp_init_phc_e810 - Perform E810 specific PHC initialization +* @hw: pointer to HW struct +* +* Perform E810-specific PTP hardware clock initialization steps. +*/ +static int ice_ptp_init_phc_e810 (struct ice_hw *hw) +{ +/* Ensure synchronization delay is zero */ +wr32 (hw,GLTSYN_SYNC_DLAY ,0 ); + +/* Initialize the PHY */ +return ice_ptp_init_phy_e810 (hw); +} +/** * ice_ptp_prep_phy_time_e810 - Prepare PHY port with initial time * @hw: Board private structure
@@ -649,3 +664,22 @@ int ice_clear_phy_tstamp(struct ice_hw *hw, u8 block, u8 idx) {return ice_clear_phy_tstamp_e810 (hw, block, idx); } + +/** +* ice_ptp_init_phc - Initialize PTP hardware clock +* @hw: pointer to the HW struct +* +* Perform the steps required to initialize the PTP hardware clock. +*/ +int ice_ptp_init_phc (struct ice_hw *hw) +{ +u8 src_idx = hw->func_caps.ts_func_info.tmr_index_owned; + +/* Enable source clocks */ +wr32 (hw,GLTSYN_ENA (src_idx),GLTSYN_ENA_TSYN_ENA_M ); + +/* Clear event err indications for auxiliary pins */ + (void )rd32 (hw,GLTSYN_STAT (src_idx)); + +return ice_ptp_init_phc_e810 (hw); +}
drivers/net/ethernet/intel/ice/ice_ptp_hw.h +1 -0
@@ -27,6 +27,7 @@ int ice_ptp_write_incval_locked(struct ice_hw *hw, u64 incval);int ice_ptp_adj_clock (struct ice_hw *hw,s32 adj);int ice_read_phy_tstamp (struct ice_hw *hw,u8 block,u8 idx,u64 *tstamp);int ice_clear_phy_tstamp (struct ice_hw *hw,u8 block,u8 idx); +int ice_ptp_init_phc (struct ice_hw *hw);/* E810 family functions */ int ice_ptp_init_phy_e810 (struct ice_hw *hw);
Signature · 1 line
2.31.1.331.gb0c09ab8796f
PATCH v3 9/13 ice: convert clk_freq capability into time_ref
In reply to Jacob KellerConvert the clk_freq value into the associated time_ref frequency value for E822 devices. This simplifies determining the time reference value for the clock.
--- drivers/net/ethernet/intel/ice/ice_common.c | 12 +++++++++++ drivers/net/ethernet/intel/ice/ice_type.h | 23 ++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_common.c +12 -0
@@ -2129,6 +2129,18 @@ ice_parse_1588_func_caps(struct ice_hw *hw, struct ice_hw_func_caps *func_p, info->clk_freq = (number &ICE_TS_CLK_FREQ_M ) >>ICE_TS_CLK_FREQ_S ; info->clk_src = ((number &ICE_TS_CLK_SRC_M ) !=0 ); +if (info->clk_freq <NUM_ICE_TIME_REF_FREQ ) { + info->time_ref = (enum ice_time_ref_freq )info->clk_freq; + }else { +/* Unknown clock frequency, so assume a (probably incorrect) +* default to avoid out-of-bounds look ups of frequency +* related information. +*/ +ice_debug (hw,ICE_DBG_INIT ,"1588 func caps: unknown clock frequency %u\n" , + info->clk_freq); + info->time_ref =ICE_TIME_REF_FREQ_25_000 ; + } +ice_debug (hw,ICE_DBG_INIT ,"func caps: ieee_1588 = %u\n" , func_p->common_cap.ieee_1588); ice_debug(hw, ICE_DBG_INIT, "func caps: src_tmr_owned = %u\n",
drivers/net/ethernet/intel/ice/ice_type.h +22 -1
@@ -294,9 +294,30 @@ struct ice_hw_common_caps {#define ICE_TS_TMR_IDX_ASSOC_S 24#define ICE_TS_TMR_IDX_ASSOC_M BIT(24) +/* TIME_REF clock rate specification */ +enum ice_time_ref_freq { +ICE_TIME_REF_FREQ_25_000 =0 , +ICE_TIME_REF_FREQ_122_880 =1 , +ICE_TIME_REF_FREQ_125_000 =2 , +ICE_TIME_REF_FREQ_153_600 =3 , +ICE_TIME_REF_FREQ_156_250 =4 , +ICE_TIME_REF_FREQ_245_760 =5 , + +NUM_ICE_TIME_REF_FREQ +}; + +/* Clock source specification */ +enum ice_clk_src { +ICE_CLK_SRC_TCX0 =0 ,/* Temperature compensated oscillator */ +ICE_CLK_SRC_TIME_REF =1 ,/* Use TIME_REF reference clock */ + +NUM_ICE_CLK_SRC +}; +struct ice_ts_func_info {/* Function specific info */ -u32 clk_freq; +enum ice_time_ref_freq time_ref; +u8 clk_freq;u8 clk_src;u8 tmr_index_assoc;u8 ena;
Signature · 1 line
2.31.1.331.gb0c09ab8796f
PATCH v3 10/13 ice: implement basic E822 PTP support
In reply to Jacob KellerImplement support for the basic operations needed to enable the PTP hardware clock on E822 devices.
This includes implementations for the various PHY access functions, as well as the ability to start and stop the PHY timers. This is different from the E810 device because the configuration depends on link speed, so we cannot just start the PHYs immediately. We must wait until the link is up to get proper values for the speed based initialization.
--- .../net/ethernet/intel/ice/ice_hw_autogen.h | 1 + drivers/net/ethernet/intel/ice/ice_main.c | 7 + drivers/net/ethernet/intel/ice/ice_ptp.c | 266 ++- drivers/net/ethernet/intel/ice/ice_ptp.h | 26 +- .../net/ethernet/intel/ice/ice_ptp_consts.h | 300 +++ drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 1863 ++++++++++++++++- drivers/net/ethernet/intel/ice/ice_ptp_hw.h | 323 +++ 7 files changed, 2717 insertions(+), 69 deletions(-) create mode 100644 drivers/net/ethernet/intel/ice/ice_ptp_consts.h
drivers/net/ethernet/intel/ice/ice_hw_autogen.h +1 -0
@@ -100,6 +100,7 @@#define PF_SB_ATQT 0x0022FE00#define PF_SB_ATQT_ATQT_S 0#define PF_SB_ATQT_ATQT_M ICE_M(0x3FF, 0) +#define PF_SB_REM_DEV_CTL 0x002300F0#define PRTDCB_GENC 0x00083000#define PRTDCB_GENC_PFCLDA_S 16#define PRTDCB_GENC_PFCLDA_M ICE_M(0xFFFF, 16)
drivers/net/ethernet/intel/ice/ice_main.c +7 -0
@@ -978,6 +978,9 @@ ice_link_event(struct ice_pf *pf, struct ice_port_info *pi, bool link_up,if (link_up == old_link && link_speed == old_link_speed)return 0 ; +if (!ice_is_e810 (&pf->hw)) +ice_ptp_link_change (pf, pf->hw.pf_id, link_up); +if (ice_is_dcb_active (pf)) {if (test_bit (ICE_FLAG_DCB_ENA , pf->flags))ice_dcb_rebuild (pf);
@@ -5608,6 +5611,8 @@ static int ice_up_complete(struct ice_vsi *vsi)ice_print_link_msg (vsi, true);netif_tx_start_all_queues (vsi->netdev);netif_carrier_on (vsi->netdev); +if (!ice_is_e810 (&pf->hw)) +ice_ptp_link_change (pf, pf->hw.pf_id, true); }ice_service_task_schedule (pf);
@@ -5998,6 +6003,8 @@ int ice_down(struct ice_vsi *vsi)* vsi->state ICE_DOWN bit */ if (vsi->netdev && vsi->type ==ICE_VSI_PF ) { +if (!ice_is_e810 (&vsi->back->hw)) +ice_ptp_link_change (vsi->back, vsi->back->hw.pf_id, false);netif_carrier_off (vsi->netdev);netif_tx_disable (vsi->netdev); }else if (vsi->type ==ICE_VSI_SWITCHDEV_CTRL ) {
drivers/net/ethernet/intel/ice/ice_ptp.c +255 -11
350 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_ptp.h +22 -4
@@ -67,6 +67,8 @@ struct ice_tx_tstamp {* @quad_offset: offset into timestamp block of the quad to get the real index * @len: length of the tstamps and in_use fields. * @init: if true, the tracker is initialized; +* @calibrating: if true, the PHY is calibrating the Tx offset. During this +* window, timestamps are temporarily disabled. */ struct ice_ptp_tx {struct kthread_work work;
@@ -77,6 +79,7 @@ struct ice_ptp_tx {u8 quad_offset;u8 len;u8 init; +u8 calibrating; };/* Quad and port information for initializing timestamp blocks */
@@ -86,15 +89,20 @@ struct ice_ptp_tx {/** * struct ice_ptp_port - data used to initialize an external port for PTP * -* This structure contains PTP data related to the external ports. Currently -* it is used for tracking the Tx timestamps of a port. In the future this -* structure will also hold information for the E822 port initialization -* logic. +* This structure contains data indicating whether a single external port is +* ready for PTP functionality. It is used to track the port initialization +* and determine when the port's PHY offset is valid. * * @tx: Tx timestamp tracking for this port +* @ps_lock: mutex used to protect the overall PTP PHY start procedure +* @link_up: indicates whether the link is up +* @port_num: the port number this structure represents */ struct ice_ptp_port {struct ice_ptp_tx tx; +struct mutex ps_lock;/* protects overall PTP PHY start procedure */ +bool link_up; +u8 port_num; };#define GLTSYN_TGT_H_IDX_MAX 4
@@ -137,9 +145,15 @@ struct ice_ptp {#define ptp_info_to_pf (i) \ container_of(__ptp_info_to_ptp((i)), struct ice_pf, ptp) +#define PFTSYN_SEM_BYTES 4#define PTP_SHARED_CLK_IDX_VALID BIT(31) +#define TS_CMD_MASK 0xF +#define SYNC_EXEC_CMD 0x3#define ICE_PTP_TS_VALID BIT(0) +#define FIFO_EMPTY BIT(2) +#define FIFO_OK 0xFF +#define ICE_PTP_FIFO_NUM_CHECKS 5/* Per-channel register definitions */ #define GLTSYN_AUX_OUT (_chan, _idx) (GLTSYN_AUX_OUT_0(_idx) + ((_chan) * 8))#define GLTSYN_AUX_IN (_chan, _idx) (GLTSYN_AUX_IN_0(_idx) + ((_chan) * 8))
@@ -157,6 +171,7 @@ struct ice_ptp {#define TIME_SYNC_PIN_INDEX 4#define E810_N_EXT_TS 3#define E810_N_PER_OUT 4 +#define ETH_GLTSYN_ENA (_i) (0x03000348 + ((_i) * 4))#if IS_ENABLED (CONFIG_PTP_1588_CLOCK )struct ice_pf ;
@@ -172,6 +187,7 @@ ice_ptp_rx_hwtstamp(struct ice_ring *rx_ring, union ice_32b_rx_flex_desc *rx_desc, struct sk_buff *skb);void ice_ptp_init (struct ice_pf *pf);void ice_ptp_release (struct ice_pf *pf); +int ice_ptp_link_change (struct ice_pf *pf,u8 port,bool linkup);#else /* IS_ENABLED(CONFIG_PTP_1588_CLOCK) */ static inline int ice_ptp_set_ts_config (struct ice_pf *pf,struct ifreq *ifr) {
@@ -200,5 +216,7 @@ ice_ptp_rx_hwtstamp(struct ice_ring *rx_ring, union ice_32b_rx_flex_desc *rx_desc, struct sk_buff *skb) { }static inline void ice_ptp_init (struct ice_pf *pf) { }static inline void ice_ptp_release (struct ice_pf *pf) { } +static inline int ice_ptp_link_change (struct ice_pf *pf,u8 port,bool linkup) +{return 0 ; }#endif /* IS_ENABLED(CONFIG_PTP_1588_CLOCK) */ #endif /* _ICE_PTP_H_ */
drivers/net/ethernet/intel/ice/ice_ptp_consts.h new file +300 -0
300 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_ptp_hw.c +1809 -54
1,952 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_ptp_hw.h +323 -0
291 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.31.1.331.gb0c09ab8796f
Part of the diff is not shown here. View the raw message.
Keller
PATCH v3 10/13 ice: implement basic E822 PTP support
Quoted 11 lines · Jacob E
Implement support for the basic operations needed to enable the PTP hardware clock on E822 devices.
This includes implementations for the various PHY access functions, as well as the ability to start and stop the PHY timers. This is different from the E810 device because the configuration depends on link speed, so we cannot just start the PHYs immediately. We must wait until the link is up to get proper values for the speed based initialization.
Signed-off-by Jacob Keller <[email protected]>---
This patch has a bug, unfortunately....
Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_ptp.c +5
-0+/** +* ice_ptp_init_tx_e822 - Initialize tracking for Tx timestamps +* @pf: Board private structure +* @tx: the Tx tracking structure to initialize +* @port: the port this structure tracks
drivers/net/ethernet/intel/ice/ice_ptp.c ice_ptp_release_tx_tracker(struct ice_pf *pf, struct ice_ptp_tx *tx) · line 1597
Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_ptp.c +10
-0+* +* Initialize the Tx timestamp tracker for this port. For generic MAC devices, +* the timestamp block is shared for all ports in the same quad. To avoid +* ports using the same timestamp index, logically break the block of +* registers into chunks based on the port number. +*/ +static int +ice_ptp_init_tx_e822 (struct ice_pf *pf,struct ice_ptp_tx *tx,u8 port) +{ + tx->quad = port %ICE_PORTS_PER_QUAD ;
This quad calculation is wrong, it should be:
tx->quad = port / ICE_PORTS_PER_QUAD;
This causes the incorrect quad number to be used for all ports except for port 0. Because of this, Tx timestamps only work on port 0.
Can we fix this and have a v4? If not, a fix commit will be required.
Thanks,
Jake
Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_ptp.c +6
-0+ tx->quad_offset = tx->quad *INDEX_PER_PORT ; + tx->len =INDEX_PER_PORT ; + +return ice_ptp_alloc_tx_tracker (tx); +} +
PATCH v3 11/13 ice: ensure the hardware Clock Generation Unit is configured
In reply to Jacob KellerThe E822 device has a Clock Generation Unit (CGU) responsible for determining the clock frequency that drives the timers.
Ensure this function is initialized when bringing up the PTP support, so that the clock has a known frequency.
--- drivers/net/ethernet/intel/ice/ice_cgu_regs.h | 116 +++++++ .../net/ethernet/intel/ice/ice_ptp_consts.h | 74 +++++ drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 290 ++++++++++++++++++ drivers/net/ethernet/intel/ice/ice_ptp_hw.h | 20 ++ 4 files changed, 500 insertions(+) create mode 100644 drivers/net/ethernet/intel/ice/ice_cgu_regs.h
drivers/net/ethernet/intel/ice/ice_cgu_regs.h new file +116 -0
@@ -0,0 +1,116 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2018-2021, Intel Corporation. */ + +#ifndef _ICE_CGU_REGS_H_ +#define _ICE_CGU_REGS_H_ + +#define NAC_CGU_DWORD9 0x24 +union nac_cgu_dword9 { +struct { +u32 time_ref_freq_sel :3 ; +u32 clk_eref1_en :1 ; +u32 clk_eref0_en :1 ; +u32 time_ref_en :1 ; +u32 time_sync_en :1 ; +u32 one_pps_out_en :1 ; +u32 clk_ref_synce_en :1 ; +u32 clk_synce1_en :1 ; +u32 clk_synce0_en :1 ; +u32 net_clk_ref1_en :1 ; +u32 net_clk_ref0_en :1 ; +u32 clk_synce1_amp :2 ; +u32 misc6 :1 ; +u32 clk_synce0_amp :2 ; +u32 one_pps_out_amp :2 ; +u32 misc24 :12 ; + } field; +u32 val; +}; + +#define NAC_CGU_DWORD19 0x4c +union nac_cgu_dword19 { +struct { +u32 tspll_fbdiv_intgr :8 ; +u32 fdpll_ulck_thr :5 ; +u32 misc15 :3 ; +u32 tspll_ndivratio :4 ; +u32 tspll_iref_ndivratio :3 ; +u32 misc19 :1 ; +u32 japll_ndivratio :4 ; +u32 japll_iref_ndivratio :3 ; +u32 misc27 :1 ; + } field; +u32 val; +}; + +#define NAC_CGU_DWORD22 0x58 +union nac_cgu_dword22 { +struct { +u32 fdpll_frac_div_out_nc :2 ; +u32 fdpll_lock_int_for :1 ; +u32 synce_hdov_int_for :1 ; +u32 synce_lock_int_for :1 ; +u32 fdpll_phlead_slip_nc :1 ; +u32 fdpll_acc1_ovfl_nc :1 ; +u32 fdpll_acc2_ovfl_nc :1 ; +u32 synce_status_nc :6 ; +u32 fdpll_acc1f_ovfl :1 ; +u32 misc18 :1 ; +u32 fdpllclk_div :4 ; +u32 time1588clk_div :4 ; +u32 synceclk_div :4 ; +u32 synceclk_sel_div2 :1 ; +u32 fdpllclk_sel_div2 :1 ; +u32 time1588clk_sel_div2 :1 ; +u32 misc3 :1 ; + } field; +u32 val; +}; + +#define NAC_CGU_DWORD24 0x60 +union nac_cgu_dword24 { +struct { +u32 tspll_fbdiv_frac :22 ; +u32 misc20 :2 ; +u32 ts_pll_enable :1 ; +u32 time_sync_tspll_align_sel :1 ; +u32 ext_synce_sel :1 ; +u32 ref1588_ck_div :4 ; +u32 time_ref_sel :1 ; + } field; +u32 val; +}; + +#define TSPLL_CNTR_BIST_SETTINGS 0x344 +union tspll_cntr_bist_settings { +struct { +u32 i_irefgen_settling_time_cntr_7_0 :8 ; +u32 i_irefgen_settling_time_ro_standby_1_0 :2 ; +u32 reserved195 :5 ; +u32 i_plllock_sel_0 :1 ; +u32 i_plllock_sel_1 :1 ; +u32 i_plllock_cnt_6_0 :7 ; +u32 i_plllock_cnt_10_7 :4 ; +u32 reserved200 :4 ; + } field; +u32 val; +}; + +#define TSPLL_RO_BWM_LF 0x370 +union tspll_ro_bwm_lf { +struct { +u32 bw_freqov_high_cri_7_0 :8 ; +u32 bw_freqov_high_cri_9_8 :2 ; +u32 biascaldone_cri :1 ; +u32 plllock_gain_tran_cri :1 ; +u32 plllock_true_lock_cri :1 ; +u32 pllunlock_flag_cri :1 ; +u32 afcerr_cri :1 ; +u32 afcdone_cri :1 ; +u32 feedfwrdgain_cal_cri_7_0 :8 ; +u32 m2fbdivmod_cri_7_0 :8 ; + } field; +u32 val; +}; + +#endif /* _ICE_CGU_REGS_H_ */
drivers/net/ethernet/intel/ice/ice_ptp_consts.h +74 -0
80 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_ptp_hw.c +290 -0
314 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_ptp_hw.h +20 -0
@@ -92,6 +92,26 @@ struct ice_vernier_info_e822 {u32 rx_fixed_delay; }; +/** +* struct ice_cgu_pll_params_e822 +* @refclk_pre_div: Reference clock pre-divisor +* @feedback_div: Feedback divisor +* @frac_n_div: Fractional divisor +* @post_pll_div: Post PLL divisor +* +* Clock Generation Unit parameters used to program the PLL based on the +* selected TIME_REF frequency. +*/ +struct ice_cgu_pll_params_e822 { +u32 refclk_pre_div; +u32 feedback_div; +u32 frac_n_div; +u32 post_pll_div; +}; + +extern const struct +ice_cgu_pll_params_e822 e822_cgu_params[NUM_ICE_TIME_REF_FREQ ]; +/* Table of constants related to possible TIME_REF sources */ extern const struct ice_time_ref_info_e822 e822_time_ref[NUM_ICE_TIME_REF_FREQ ];
Signature · 1 line
2.31.1.331.gb0c09ab8796f
PATCH v3 12/13 ice: exit bypass mode once hardware finishes timestamp calibration
In reply to Jacob KellerOnce the E822 device has sent and received one packet, the hardware computes the internal delay of the PHY using a process known as Vernier calibration. This calibration calculates a more accurate offset for the Tx and Rx timestamps. To make use of this offset, we need to exit the bypass mode. This cannot be done until the PHY has completed offset calibration, as indicated by the offset valid bits.
To handle this, introduce a kthread work item which will poll the offset valid bits every few milliseconds seeing if it is safe to exit bypass mode.
Once we have finished calibrating the offsets, we can program the total Tx and Rx offset registers and turn off the bypass bit. This allows the hardware to include the more precise vernier calibration offset, and improves the timestamp precision.
--- drivers/net/ethernet/intel/ice/ice_ptp.c | 195 ++++++++++ drivers/net/ethernet/intel/ice/ice_ptp.h | 4 + drivers/net/ethernet/intel/ice/ice_ptp_hw.c | 411 ++++++++++++++++++++ drivers/net/ethernet/intel/ice/ice_ptp_hw.h | 1 + 4 files changed, 611 insertions(+)
drivers/net/ethernet/intel/ice/ice_ptp.c +195 -0
@@ -479,6 +479,192 @@ static void ice_ptp_reset_ts_memory_quad(struct ice_pf *pf, int quad)ice_write_quad_reg_e822 (hw, quad,Q_REG_TS_CTRL , ~(u32 )Q_REG_TS_CTRL_M ); } +/** +* ice_ptp_check_tx_fifo - Check whether Tx FIFO is in an OK state +* @port: PTP port for which Tx FIFO is checked +*/ +static int ice_ptp_check_tx_fifo (struct ice_ptp_port *port) +{ +int quad = port->port_num /ICE_PORTS_PER_QUAD ; +int offs = port->port_num %ICE_PORTS_PER_QUAD ; +struct ice_pf *pf; +struct ice_hw *hw; +u32 val, phy_sts; +int err; + + pf =ptp_port_to_pf (port); + hw = &pf->hw; + +if (port->tx_fifo_busy_cnt ==FIFO_OK ) +return 0 ; + +/* need to read FIFO state */ +if (offs ==0 || offs ==1 ) + err =ice_read_quad_reg_e822 (hw, quad,Q_REG_FIFO01_STATUS , + &val); +else + err =ice_read_quad_reg_e822 (hw, quad,Q_REG_FIFO23_STATUS , + &val); + +if (err) { +dev_err (ice_pf_to_dev (pf),"PTP failed to check port %d Tx FIFO, err %d\n" , + port->port_num, err); +return err; + } + +if (offs &0x1 ) + phy_sts = (val &Q_REG_FIFO13_M ) >>Q_REG_FIFO13_S ; +else + phy_sts = (val &Q_REG_FIFO02_M ) >>Q_REG_FIFO02_S ; + +if (phy_sts &FIFO_EMPTY ) { + port->tx_fifo_busy_cnt =FIFO_OK ; +return 0 ; + } + + port->tx_fifo_busy_cnt++; + +dev_dbg (ice_pf_to_dev (pf),"Try %d, port %d FIFO not empty\n" , + port->tx_fifo_busy_cnt, port->port_num); + +if (port->tx_fifo_busy_cnt ==ICE_PTP_FIFO_NUM_CHECKS ) { +dev_dbg (ice_pf_to_dev (pf), +"Port %d Tx FIFO still not empty; resetting quad %d\n" , + port->port_num, quad); +ice_ptp_reset_ts_memory_quad (pf, quad); + port->tx_fifo_busy_cnt =FIFO_OK ; +return 0 ; + } + +return -EAGAIN ; +} + +/** +* ice_ptp_check_tx_offset_valid - Check if the Tx PHY offset is valid +* @port: the PTP port to check +* +* Checks whether the Tx offset for the PHY associated with this port is +* valid. Returns 0 if the offset is valid, and a non-zero error code if it is +* not. +*/ +static int ice_ptp_check_tx_offset_valid (struct ice_ptp_port *port) +{ +struct ice_pf *pf =ptp_port_to_pf (port); +struct device *dev =ice_pf_to_dev (pf); +struct ice_hw *hw = &pf->hw; +u32 val; +int err; + + err =ice_ptp_check_tx_fifo (port); +if (err) +return err; + + err =ice_read_phy_reg_e822 (hw, port->port_num,P_REG_TX_OV_STATUS , + &val); +if (err) { +dev_err (dev,"Failed to read TX_OV_STATUS for port %d, err %d\n" , + port->port_num, err); +return -EAGAIN ; + } + +if (!(val &P_REG_TX_OV_STATUS_OV_M )) +return -EAGAIN ; + +return 0 ; +} + +/** +* ice_ptp_check_rx_offset_valid - Check if the Rx PHY offset is valid +* @port: the PTP port to check +* +* Checks whether the Rx offset for the PHY associated with this port is +* valid. Returns 0 if the offset is valid, and a non-zero error code if it is +* not. +*/ +static int ice_ptp_check_rx_offset_valid (struct ice_ptp_port *port) +{ +struct ice_pf *pf =ptp_port_to_pf (port); +struct device *dev =ice_pf_to_dev (pf); +struct ice_hw *hw = &pf->hw; +int err; +u32 val; + + err =ice_read_phy_reg_e822 (hw, port->port_num,P_REG_RX_OV_STATUS , + &val); +if (err) { +dev_err (dev,"Failed to read RX_OV_STATUS for port %d, err %d\n" , + port->port_num, err); +return err; + } + +if (!(val &P_REG_RX_OV_STATUS_OV_M )) +return -EAGAIN ; + +return 0 ; +} + +/** +* ice_ptp_check_offset_valid - Check port offset valid bit +* @port: Port for which offset valid bit is checked +* +* Returns 0 if both Tx and Rx offset are valid, and -EAGAIN if one of the +* offset is not ready. +*/ +static int ice_ptp_check_offset_valid (struct ice_ptp_port *port) +{ +int tx_err, rx_err; + +/* always check both Tx and Rx offset validity */ + tx_err =ice_ptp_check_tx_offset_valid (port); + rx_err =ice_ptp_check_rx_offset_valid (port); + +if (tx_err || rx_err) +return -EAGAIN ; + +return 0 ; +} + +/** +* ice_ptp_wait_for_offset_valid - Check for valid Tx and Rx offsets +* @work: Pointer to the kthread_work structure for this task +* +* Check whether both the Tx and Rx offsets are valid for enabling the vernier +* calibration. +* +* Once we have valid offsets from hardware, update the total Tx and Rx +* offsets, and exit bypass mode. This enables more precise timestamps using +* the extra data measured during the vernier calibration process. +*/ +static void ice_ptp_wait_for_offset_valid (struct kthread_work *work) +{ +struct ice_ptp_port *port; +int err; +struct device *dev; +struct ice_pf *pf; +struct ice_hw *hw; + + port = container_of(work, struct ice_ptp_port, ov_work.work); + pf =ptp_port_to_pf (port); + hw = &pf->hw; + dev =ice_pf_to_dev (pf); + +if (ice_ptp_check_offset_valid (port)) { +/* Offsets not ready yet, try again later */ +kthread_queue_delayed_work (pf->ptp.kworker, + &port->ov_work, +msecs_to_jiffies (100 )); +return ; + } + +/* Offsets are valid, so it is safe to exit bypass mode */ + err =ice_phy_exit_bypass_e822 (hw, port->port_num); +if (err) { +dev_warn (dev,"Failed to exit bypass mode for PHY port %u, err %d\n" , + port->port_num, err); +return ; + } +} +/** * ice_ptp_port_phy_stop - Stop timestamping for a PHY port * @ptp_port: PTP port to stop
@@ -496,6 +682,8 @@ ice_ptp_port_phy_stop(struct ice_ptp_port *ptp_port)mutex_lock (&ptp_port->ps_lock); +kthread_cancel_delayed_work_sync (&ptp_port->ov_work); + err =ice_stop_phy_timer_e822 (hw, port, true);if (err) dev_err(ice_pf_to_dev(pf), "PTP failed to set PHY port %d down, err %d\n",
@@ -530,8 +718,11 @@ ice_ptp_port_phy_restart(struct ice_ptp_port *ptp_port)mutex_lock (&ptp_port->ps_lock); +kthread_cancel_delayed_work_sync (&ptp_port->ov_work); +/* temporarily disable Tx timestamps while calibrating PHY offset */ ptp_port->tx.calibrating = true; + ptp_port->tx_fifo_busy_cnt =0 ;/* Start the PHY timer in bypass mode */ err =ice_start_phy_timer_e822 (hw, port, true);
@@ -541,6 +732,8 @@ ice_ptp_port_phy_restart(struct ice_ptp_port *ptp_port)/* Enable Tx timestamps right away */ ptp_port->tx.calibrating = false; +kthread_queue_delayed_work (pf->ptp.kworker, &ptp_port->ov_work,0 ); + out_unlock:if (err) dev_err(ice_pf_to_dev(pf), "PTP failed to set PHY port %d up, err %d\n",
@@ -1776,6 +1969,8 @@ void ice_ptp_init(struct ice_pf *pf)/* Initialize PTP port structure */ mutex_init (&pf->ptp.port.ps_lock); pf->ptp.port.port_num = pf->hw.pf_id; +kthread_init_delayed_work (&pf->ptp.port.ov_work, + ice_ptp_wait_for_offset_valid);if (ice_is_e810 (hw))ice_ptp_init_tx_e810 (pf, &pf->ptp.port.tx);
drivers/net/ethernet/intel/ice/ice_ptp.h +4 -0
@@ -94,14 +94,18 @@ struct ice_ptp_tx {* and determine when the port's PHY offset is valid. * * @tx: Tx timestamp tracking for this port +* @ov_work: delayed work task for tracking when PHY offset is valid * @ps_lock: mutex used to protect the overall PTP PHY start procedure * @link_up: indicates whether the link is up +* @tx_fifo_busy_cnt: number of times the Tx FIFO was busy * @port_num: the port number this structure represents */ struct ice_ptp_port {struct ice_ptp_tx tx; +struct kthread_delayed_work ov_work;struct mutex ps_lock;/* protects overall PTP PHY start procedure */ bool link_up; +u8 tx_fifo_busy_cnt;u8 port_num; };
drivers/net/ethernet/intel/ice/ice_ptp_hw.c +411 -0
435 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_ptp_hw.h +1 -0
@@ -185,6 +185,7 @@ static inline u64 ice_e822_pps_delay(enum ice_time_ref_freq time_ref)/* E822 Vernier calibration functions */ int ice_stop_phy_timer_e822 (struct ice_hw *hw,u8 port,bool soft_reset);int ice_start_phy_timer_e822 (struct ice_hw *hw,u8 port,bool bypass); +int ice_phy_exit_bypass_e822 (struct ice_hw *hw,u8 port);/* E810 family functions */ int ice_ptp_init_phy_e810 (struct ice_hw *hw);
Signature · 1 line
2.31.1.331.gb0c09ab8796f
PATCH v3 13/13 ice: support crosstimestamping on E822 devices if supported
In reply to Jacob KellerE822 devices on supported platforms can generate a cross timestamp between the platform ART and the device time. This process allows for very precise measurement of the difference between the PTP hardware clock and the platform time.
This is only supported if we know the TSC frequency relative to ART, so we do not enable this unless the boot CPU has a known TSC frequency (as required by convert_art_ns_to_tsc).
Because PCIe PTM support is not available on all platforms, introduce CONFIG_ICE_HWTS and make it depend on X86 where we know the support exists.
--- drivers/net/ethernet/intel/Kconfig | 10 ++ .../net/ethernet/intel/ice/ice_hw_autogen.h | 8 ++ drivers/net/ethernet/intel/ice/ice_ptp.c | 117 ++++++++++++++++++ 3 files changed, 135 insertions(+)
drivers/net/ethernet/intel/Kconfig +10 -0
@@ -327,6 +327,16 @@ config ICE_SWITCHDEV If unsure, say N. +config ICE_HWTS + bool "Support HW cross-timestamp on platforms with PTM support" + default y + depends on ICE && X86 + help + Say Y to enable hardware supported cross-timestamping on platforms + with PCIe PTM support. The cross-timestamp is available through + the PTP clock driver precise cross-timestamp ioctl + (PTP_SYS_OFFSET_PRECISE). + config FM10K tristate "Intel(R) FM10000 Ethernet Switch Host Interface Support" default n
drivers/net/ethernet/intel/ice/ice_hw_autogen.h +8 -0
@@ -440,6 +440,10 @@#define GLV_UPRCL (_i) (0x003B2000 + ((_i) * 8))#define GLV_UPTCL (_i) (0x0030A000 + ((_i) * 8))#define PRTRPB_RDPC 0x000AC260 +#define GLHH_ART_CTL 0x000A41D4 +#define GLHH_ART_CTL_ACTIVE_M BIT(0) +#define GLHH_ART_TIME_H 0x000A41D8 +#define GLHH_ART_TIME_L 0x000A41DC#define GLTSYN_AUX_IN_0 (_i) (0x000889D8 + ((_i) * 4))#define GLTSYN_AUX_IN_0_INT_ENA_M BIT(4)#define GLTSYN_AUX_OUT_0 (_i) (0x00088998 + ((_i) * 4))
@@ -452,6 +456,8 @@#define GLTSYN_ENA_TSYN_ENA_M BIT(0)#define GLTSYN_EVNT_H_0 (_i) (0x00088970 + ((_i) * 4))#define GLTSYN_EVNT_L_0 (_i) (0x00088968 + ((_i) * 4)) +#define GLTSYN_HHTIME_H (_i) (0x00088900 + ((_i) * 4)) +#define GLTSYN_HHTIME_L (_i) (0x000888F8 + ((_i) * 4))#define GLTSYN_INCVAL_H (_i) (0x00088920 + ((_i) * 4))#define GLTSYN_INCVAL_L (_i) (0x00088918 + ((_i) * 4))#define GLTSYN_SHADJ_H (_i) (0x00088910 + ((_i) * 4))
@@ -468,6 +474,8 @@#define GLTSYN_TGT_L_0 (_i) (0x00088928 + ((_i) * 4))#define GLTSYN_TIME_H (_i) (0x000888D8 + ((_i) * 4))#define GLTSYN_TIME_L (_i) (0x000888D0 + ((_i) * 4)) +#define PFHH_SEM 0x000A4200/* Reset Source: PFR */ +#define PFHH_SEM_BUSY_M BIT(0)#define PFTSYN_SEM 0x00088880#define PFTSYN_SEM_BUSY_M BIT(0)#define VSIQF_FD_CNT (_VSI) (0x00464000 + ((_VSI) * 4))
drivers/net/ethernet/intel/ice/ice_ptp.c +117 -0
135 lines not on this page · raw message
Signature · 1 line
2.31.1.331.gb0c09ab8796f