ice: restore timestamp config after reset
Subsystems (3)
v2 cover ice: restore timestamp config after reset
We recently discovered during internal validation that the ice driver has not been properly restoring Tx timestamp configuration after a device reset, which resulted in application failures after a device reset.
After some digging, it turned out this problem is two-fold. Since the introduction of the PTP support the driver has been clobbering the storage of the current timestamp configuration during reset. Thus after a reset, the driver will no longer perform Tx or Rx timestamps, and will report timestamp configuration as disabled if SIOCGHWTSTAMP ioctl is issued.
In addition, the recently merged auxiliary bus support code missed that PFINT_TSYN_MSK must be reprogrammed on the clock owner for E822 devices. Failure to restore this register configuration results in the driver no longer responding to interrupts from other ports. Depending on the traffic pattern, this can either result in increased latency responding to timestamps on the non-owner ports, or it can result in the driver never reporting any timestamps. The configuration of PFINT_TSYN_MSK was only done during initialization. Due to this, the Tx timestamp issue persists even if userspace reconfigures timestamping.
This series fixes both issues, as well as removes a redundant Tx ring field since we can rely on the skb flag as the primary detector for a Tx timestamp request.
Note that I don't think this series will directly apply to older stable releases (even v6.6) as we recently refactored a lot of the PTP code to support auxiliary bus. Patch 2/3 only matters for the post-auxiliary bus implementation. The principle of patch 1/3 and 3/3 could apply as far back as the initial PTP support, but I don't think it will apply cleanly as-is.
Changes since v1
* Update target to net and rebase onto current net tree.
* Add appropriate fixes tag to 1/3.
* Slightly update the cover message.
* picked up Jesse's Reviewed-by tag.
V1 was posted here:
https://lore.kernel.org/netdev/[email protected]/
Jacob Keller (3):
ice: remove ptp_tx ring parameter flag
ice: unify logic for programming PFINT_TSYN_MSK
ice: restore timestamp configuration after device reset
drivers/net/ethernet/intel/ice/ice_main.c | 12 +- drivers/net/ethernet/intel/ice/ice_ptp.c | 146 ++++++++++++---------- drivers/net/ethernet/intel/ice/ice_ptp.h | 5 +- drivers/net/ethernet/intel/ice/ice_txrx.c | 3 - drivers/net/ethernet/intel/ice/ice_txrx.h | 1 - 5 files changed, 84 insertions(+), 83 deletions(-)
base-commit: 55c900477f5b3897d9038446f72a281cae0efd86
Signature · 1 line
2.41.0
PATCH v2 1/3 ice: remove ptp_tx ring parameter flag
Before performing a Tx timestamp in ice_stamp(), the driver checks a ptp_tx ring variable to see if timestamping is enabled on that ring. This value is set for all rings whenever userspace configures Tx timestamping.
Ostensibly this was done to avoid wasting cycles checking other fields when timestamping has not been enabled. However, for Tx timestamps we already get an individual per-SKB flag indicating whether userspace wants to request a timestamp on that packet. We do not gain much by also having a separate flag to check for whether timestamping was enabled.
In fact, the driver currently fails to restore the field after a PF reset. Because of this, if a PF reset occurs, timestamps will be disabled.
Since this flag doesn't add value in the hotpath, remove it and always provide a timestamp if the SKB flag has been set.
A following change will fix the reset path to properly restore user timestamping configuration completely.
This went unnoticed for some time because one of the most common applications using Tx timestamps, ptp4l, will reconfigure the socket as part of its fault recovery logic.
---
Changes since v1:
* Picked up Jesse's Reviewed-by.
* Add appropriate Fixes tag.
drivers/net/ethernet/intel/ice/ice_ptp.c | 14 -------------- drivers/net/ethernet/intel/ice/ice_txrx.c | 3 --- drivers/net/ethernet/intel/ice/ice_txrx.h | 1 - 3 files changed, 18 deletions(-)
drivers/net/ethernet/intel/ice/ice_ptp.c +0 -14
@@ -280,20 +280,6 @@ static void ice_ptp_configure_tx_tstamp(struct ice_pf *pf, bool on)*/ static void ice_set_tx_tstamp (struct ice_pf *pf,bool on) { -struct ice_vsi *vsi; -u16 i; - - vsi =ice_get_main_vsi (pf); -if (!vsi) -return ; - -/* Set the timestamp enable flag for all the Tx rings */ -ice_for_each_txq (vsi, i) { -if (!vsi->tx_rings[i]) -continue ; - vsi->tx_rings[i]->ptp_tx = on; - } -if (pf->ptp.tx_interrupt_mode ==ICE_PTP_TX_INTERRUPT_SELF )ice_ptp_configure_tx_tstamp (pf, on);
drivers/net/ethernet/intel/ice/ice_txrx.c +0 -3
@@ -2306,9 +2306,6 @@ ice_tstamp(struct ice_tx_ring *tx_ring, struct sk_buff *skb,if (likely (!(skb_shinfo (skb)->tx_flags &SKBTX_HW_TSTAMP )))return ; -if (!tx_ring->ptp_tx) -return ; -/* Tx timestamps cannot be sampled when doing TSO */ if (first->tx_flags &ICE_TX_FLAGS_TSO )return ;
drivers/net/ethernet/intel/ice/ice_txrx.h +0 -1
@@ -380,7 +380,6 @@ struct ice_tx_ring {#define ICE_TX_FLAGS_RING_VLAN_L2TAG2 BIT(2)u8 flags;u8 dcb_tc;/* Traffic class of ring */ -u8 ptp_tx; }____cacheline_internodealigned_in_smp ;static inline bool ice_ring_uses_build_skb (struct ice_rx_ring *ring)
Signature · 1 line
2.41.0
PATCH v2 2/3 ice: unify logic for programming PFINT_TSYN_MSK
In reply to Jacob KellerCommit d938a8cca88a ("ice: Auxbus devices & driver for E822 TS") modified how Tx timestamps are handled for E822 devices. On these devices, only the clock owner handles reading the Tx timestamp data from firmware. To do this, the PFINT_TSYN_MSK register is modified from the default value to one which enables reacting to a Tx timestamp on all PHY ports.
The driver currently programs PFINT_TSYN_MSK in different places depending on whether the port is the clock owner or not. For the clock owner, the PFINT_TSYN_MSK value is programmed during ice_ptp_init_owner just before calling ice_ptp_tx_ena_intr to program the PHY ports.
For the non-clock owner ports, the PFINT_TSYN_MSK is programmed during ice_ptp_init_port.
If a large enough device reset occurs, the PFINT_TSYN_MSK register will be reset to the default value in which only the PHY associated directly with the PF will cause the Tx timestamp interrupt to trigger.
The driver lacks logic to reprogram the PFINT_TSYN_MSK register after a device reset. For the E822 device, this results in the PF no longer responding to interrupts for other ports. This results in failure to deliver Tx timestamps to user space applications.
Rename ice_ptp_configure_tx_tstamp to ice_ptp_cfg_tx_interrupt, and unify the logic for programming PFINT_TSYN_MSK and PFINT_OICR_ENA into one place. This function will program both registers according to the combination of user configuration and device requirements.
This ensures that PFINT_TSYN_MSK is always restored when we configure the Tx timestamp interrupt.
---
Changes since v1:
* Picked up Jesse's Reviewed-by.
drivers/net/ethernet/intel/ice/ice_ptp.c | 60 ++++++++++++++---------- 1 file changed, 34 insertions(+), 26 deletions(-)
drivers/net/ethernet/intel/ice/ice_ptp.c +34 -26
@@ -256,21 +256,42 @@ ice_verify_pin_e810t(struct ptp_clock_info *info, unsigned int pin, }/** -* ice_ptp_configure_tx_tstamp - Enable or disable Tx timestamp interrupt -* @pf: The PF pointer to search in -* @on: bool value for whether timestamp interrupt is enabled or disabled +* ice_ptp_cfg_tx_interrupt - Configure Tx timestamp interrupt for the device +* @pf: Board private structure +* +* Program the device to respond appropriately to the Tx timestamp interrupt +* cause. */ -static void ice_ptp_configure_tx_tstamp (struct ice_pf *pf,bool on) +static void ice_ptp_cfg_tx_interrupt (struct ice_pf *pf) { +struct ice_hw *hw = &pf->hw; +bool enable;u32 val; +switch (pf->ptp.tx_interrupt_mode) { +case ICE_PTP_TX_INTERRUPT_ALL : +/* React to interrupts across all quads. */ +wr32 (hw,PFINT_TSYN_MSK + (0x4 * hw->pf_id), (u32 )0x1f ); + enable = true; +break ; +case ICE_PTP_TX_INTERRUPT_NONE : +/* Do not react to interrupts on any quad. */ +wr32 (hw,PFINT_TSYN_MSK + (0x4 * hw->pf_id), (u32 )0x0 ); + enable = false; +break ; +case ICE_PTP_TX_INTERRUPT_SELF : +default : + enable = pf->ptp.tstamp_config.tx_type ==HWTSTAMP_TX_ON ; +break ; + } +/* Configure the Tx timestamp interrupt */ - val =rd32 (&pf->hw,PFINT_OICR_ENA ); -if (on) + val =rd32 (hw,PFINT_OICR_ENA ); +if (enable) val |=PFINT_OICR_TSYN_TX_M ;else val &= ~PFINT_OICR_TSYN_TX_M ; -wr32 (&pf->hw,PFINT_OICR_ENA , val); +wr32 (hw,PFINT_OICR_ENA , val); }/**
@@ -280,10 +301,9 @@ static void ice_ptp_configure_tx_tstamp(struct ice_pf *pf, bool on)*/ static void ice_set_tx_tstamp (struct ice_pf *pf,bool on) { -if (pf->ptp.tx_interrupt_mode ==ICE_PTP_TX_INTERRUPT_SELF ) -ice_ptp_configure_tx_tstamp (pf, on); - pf->ptp.tstamp_config.tx_type = on ?HWTSTAMP_TX_ON :HWTSTAMP_TX_OFF ; + +ice_ptp_cfg_tx_interrupt (pf); }/**
@@ -2789,15 +2809,7 @@ static int ice_ptp_init_owner(struct ice_pf *pf)/* Release the global hardware lock */ ice_ptp_unlock (hw); -if (pf->ptp.tx_interrupt_mode ==ICE_PTP_TX_INTERRUPT_ALL ) { -/* The clock owner for this device type handles the timestamp -* interrupt for all ports. -*/ -ice_ptp_configure_tx_tstamp (pf, true); - -/* React on all quads interrupts for E82x */ -wr32 (hw,PFINT_TSYN_MSK + (0x4 * hw->pf_id), (u32 )0x1f ); - +if (!ice_is_e810 (hw)) {/* Enable quad interrupts */ err =ice_ptp_tx_ena_intr (pf, true, itr);if (err)
@@ -2867,13 +2879,6 @@ static int ice_ptp_init_port(struct ice_pf *pf, struct ice_ptp_port *ptp_port)case ICE_PHY_E810 :return ice_ptp_init_tx_e810 (pf, &ptp_port->tx);case ICE_PHY_E822 : -/* Non-owner PFs don't react to any interrupts on E82x, -* neither on own quad nor on others -*/ -if (!ice_ptp_pf_handles_tx_interrupt (pf)) { -ice_ptp_configure_tx_tstamp (pf, false); -wr32 (hw,PFINT_TSYN_MSK + (0x4 * hw->pf_id), (u32 )0x0 ); - }kthread_init_delayed_work (&ptp_port->ov_work, ice_ptp_wait_for_offsets);
@@ -3018,6 +3023,9 @@ void ice_ptp_init(struct ice_pf *pf)/* Start the PHY timestamping block */ ice_ptp_reset_phy_timestamping (pf); +/* Configure initial Tx interrupt settings */ +ice_ptp_cfg_tx_interrupt (pf); +set_bit (ICE_FLAG_PTP , pf->flags); err =ice_ptp_init_work (pf, ptp);if (err)
Signature · 1 line
2.41.0
PATCH v2 3/3 ice: restore timestamp configuration after device reset
In reply to Jacob KellerThe driver calls ice_ptp_cfg_timestamp() during ice_ptp_prepare_for_reset() to disable timestamping while the device is resetting. This operation destroys the user requested configuration. While the driver does call ice_ptp_cfg_timestamp in ice_rebuild() to restore some hardware settings after a reset, it unconditionally passes true or false, resulting in failure to restore previous user space configuration.
This results in a device reset forcibly disabling timestamp configuration regardless of current user settings.
This was not detected previously due to a quirk of the LinuxPTP ptp4l application. If ptp4l detects a missing timestamp, it enters a fault state and performs recovery logic which includes executing SIOCSHWTSTAMP again, restoring the now accidentally cleared configuration.
Not every application does this, and for these applications, timestamps will mysteriously stop after a PF reset, without being restored until an application restart.
Fix this by replacing ice_ptp_cfg_timestamp() with two new functions:
1) ice_ptp_disable_timestamp_mode() which unconditionally disables the timestamping logic in ice_ptp_prepare_for_reset() and ice_ptp_release()
2) ice_ptp_restore_timestamp_mode() which calls ice_ptp_restore_tx_interrupt() to restore Tx timestamping configuration, calls ice_set_rx_tstamp() to restore Rx timestamping configuration, and issues an immediate TSYN_TX interrupt to ensure that timestamps which may have occurred during the device reset get processed.
Modify the ice_ptp_set_timestamp_mode to directly save the user configuration and then call ice_ptp_restore_timestamp_mode. This way, reset no longer destroys the saved user configuration.
This obsoletes the ice_set_tx_tstamp() function which can now be safely removed.
With this change, all devices should now restore Tx and Rx timestamping functionality correctly after a PF reset without application intervention.
---
Changes since v1:
* Picked up Jesse's Reviewed-by.
drivers/net/ethernet/intel/ice/ice_main.c | 12 +--- drivers/net/ethernet/intel/ice/ice_ptp.c | 76 ++++++++++++++--------- drivers/net/ethernet/intel/ice/ice_ptp.h | 5 +- 3 files changed, 52 insertions(+), 41 deletions(-)
drivers/net/ethernet/intel/ice/ice_main.c +3 -9
@@ -7401,15 +7401,6 @@ static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type) goto err_vsi_rebuild; } -/* configure PTP timestamping after VSI rebuild */ -if (test_bit (ICE_FLAG_PTP_SUPPORTED , pf->flags)) { -if (pf->ptp.tx_interrupt_mode ==ICE_PTP_TX_INTERRUPT_SELF ) -ice_ptp_cfg_timestamp (pf, false); -else if (pf->ptp.tx_interrupt_mode ==ICE_PTP_TX_INTERRUPT_ALL ) -/* for E82x PHC owner always need to have interrupts */ -ice_ptp_cfg_timestamp (pf, true); - } - err =ice_vsi_rebuild_by_type (pf,ICE_VSI_SWITCHDEV_CTRL );if (err) {dev_err (dev,"Switchdev CTRL VSI rebuild failed: %d\n" , err);
@@ -7461,6 +7452,9 @@ static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type)ice_plug_aux_dev (pf);if (ice_is_feature_supported (pf,ICE_F_SRIOV_LAG ))ice_lag_rebuild (pf); + +/* Restore timestamp mode settings after VSI rebuild */ +ice_ptp_restore_timestamp_mode (pf);return ; err_vsi_rebuild:
drivers/net/ethernet/intel/ice/ice_ptp.c +47 -29
138 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_ptp.h +2 -3
@@ -292,7 +292,7 @@ int ice_ptp_clock_index(struct ice_pf *pf);struct ice_pf ;int ice_ptp_set_ts_config (struct ice_pf *pf,struct ifreq *ifr);int ice_ptp_get_ts_config (struct ice_pf *pf,struct ifreq *ifr); -void ice_ptp_cfg_timestamp (struct ice_pf *pf,bool ena); +void ice_ptp_restore_timestamp_mode (struct ice_pf *pf);void ice_ptp_extts_event (struct ice_pf *pf);s8 ice_ptp_request_ts (struct ice_ptp_tx *tx,struct sk_buff *skb);
@@ -317,8 +317,7 @@ static inline int ice_ptp_get_ts_config(struct ice_pf *pf, struct ifreq *ifr)return -EOPNOTSUPP ; } -static inline void ice_ptp_cfg_timestamp (struct ice_pf *pf,bool ena) { } - +static inline void ice_ptp_restore_timestamp_mode (struct ice_pf *pf) { }static inline void ice_ptp_extts_event (struct ice_pf *pf) { }static inline s8 ice_ptp_request_ts (struct ice_ptp_tx *tx,struct sk_buff *skb)
Signature · 1 line
2.41.0