From: Arkadiusz Kubalewski <[email protected]>
Remove redundant ice_ptp_link_change() calls from ice_up_complete() and
ice_down(). These duplicate the call already made from
ice_handle_link_event(), creating three problems:
1. Double initialization on link-up: ice_handle_link_event() calls
ice_ptp_link_change(true), then ice_up_complete() calls it again.
The second call re-enters ice_ptp_port_phy_restart(), re-setting the
calibrating flag and restarting the PHY timer while the first
invocation's offset verification work (ov_work) may still be running.
2. Premature cleanup on administrative down: ice_down() calls
ice_ptp_link_change(false) during ifconfig down or reset preparation,
even when the physical link is still up. This clears timestamp state
unnecessarily and can interfere with ongoing PTP operations.
3. Ordering dependency: ice_down()/ice_up_complete() are called during
reset sequences where PTP may not be fully initialized, creating
edge cases with partially configured state.
The link event handler is the correct and sufficient place to drive PTP
link state changes, as it reflects actual physical link transitions.
Add the link_up to be set within ice_ptp_init(..), it is required to
have actual state of link_up flag on driver load.
Fixes: 6b1ff5d39228 ("ice: always call ice_ptp_link_change and make it void")
Reviewed-by: Aleksandr Loktionov <[email protected]>
Signed-off-by: Arkadiusz Kubalewski <[email protected]>
Signed-off-by: Przemyslaw Korba <[email protected]>
---
drivers/net/ethernet/intel/ice/ice_main.c | 2 --
drivers/net/ethernet/intel/ice/ice_ptp.c | 39 +++++++++++++++++++----
2 files changed, 32 insertions(+), 9 deletions(-)
diff --git a/drivers/net/ethernet/intel/ice/ice_main.c
b/drivers/net/ethernet/intel/ice/ice_main.c
index 231d533309cb..8c25c1604949 100644
--- a/drivers/net/ethernet/intel/ice/ice_main.c
+++ b/drivers/net/ethernet/intel/ice/ice_main.c
@@ -6782,7 +6782,6 @@ 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);
- ice_ptp_link_change(pf, true);
}
/* Perform an initial read of the statistics registers now to
@@ -7310,7 +7309,6 @@ int ice_down(struct ice_vsi *vsi)
if (vsi->netdev) {
vlan_err = ice_vsi_del_vlan_zero(vsi);
- ice_ptp_link_change(vsi->back, false);
netif_carrier_off(vsi->netdev);
netif_tx_disable(vsi->netdev);
}
diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c
b/drivers/net/ethernet/intel/ice/ice_ptp.c
index e0be88024ac3..e1c8bc5fafc1 100644
--- a/drivers/net/ethernet/intel/ice/ice_ptp.c
+++ b/drivers/net/ethernet/intel/ice/ice_ptp.c
@@ -3343,9 +3343,13 @@ static int ice_ptp_init_owner(struct ice_pf *pf)
}
/**
- * ice_ptp_init_work - Initialize PTP work threads
+ * ice_ptp_init_work - Initialize the PTP kworker
* @pf: Board private structure
* @ptp: PF PTP structure
+ *
+ * Allocate the kworker and initialize the periodic work function. The
+ * periodic work is not queued here; the caller starts it once the PTP
+ * state is ICE_PTP_READY.
*/
static int ice_ptp_init_work(struct ice_pf *pf, struct ice_ptp *ptp)
{
@@ -3364,9 +3368,6 @@ static int ice_ptp_init_work(struct ice_pf *pf, struct
ice_ptp *ptp)
ptp->kworker = kworker;
- /* Start periodic work going */
- kthread_queue_delayed_work(ptp->kworker, &ptp->work, 0);
-
return 0;
}
@@ -3489,6 +3490,29 @@ void ice_ptp_init(struct ice_pf *pf)
if (err)
goto err_clean_pf;
+ /* Seed the cached PTP link state from the current PHY link status
+ * before starting the PHY timestamping block. On a fresh load the
+ * port structure is zeroed (link_up == false); if the link is
+ * already up at probe (for example after a PXE boot) no link-change
+ * edge will follow, and ice_ptp_link_change() is edge-driven, so the
+ * flag would stay stale. Seeding it here also lets
+ * ice_ptp_reset_phy_timestamping() make the correct start/stop
+ * decision instead of stopping the PHY timer on an already-up link.
+ */
+ if (pf->hw.port_info)
+ ptp->port.link_up =
+ !!(pf->hw.port_info->phy.link_info.link_info &
+ ICE_AQ_LINK_UP);
+
+ /* Create the PTP kworker before (re)starting the PHY, because the
+ * E82x restart path queues offset verification work on it, and
+ * before ICE_PTP_READY is set, so a concurrent link event cannot
+ * reach ice_ptp_port_phy_restart() while the kworker is still NULL.
+ */
+ err = ice_ptp_init_work(pf, ptp);
+ if (err)
+ goto err_exit;
+
/* Start the PHY timestamping block */
ice_ptp_reset_phy_timestamping(pf);
@@ -3497,9 +3521,10 @@ void ice_ptp_init(struct ice_pf *pf)
ptp->state = ICE_PTP_READY;
- err = ice_ptp_init_work(pf, ptp);
- if (err)
- goto err_exit;
+ /* Start periodic work only after the state is READY; the worker
+ * returns without rescheduling while the state is not READY.
+ */
+ kthread_queue_delayed_work(ptp->kworker, &ptp->work, 0);
dev_info(ice_pf_to_dev(pf), "PTP init successful\n");
return;
--
2.43.0