Add a check for the PTP state at the start of ice_ptp_settime64(),
ice_ptp_adjtime(), ice_ptp_adjfine(), and ice_ptp_gpio_enable(). If the
driver PTP state is not ICE_PTP_READY, exit with -EIO instead of continuing
to try to modify the clock while the driver may still be loading,
resetting, unloading, or after a failed rebuild.

The check is currently best effort and doesn't guarantee to prevent a race
between the start of a new command and a reset. For that, we will need more
time to investigate and develop a proper synchronization mechanism.

The ice_ptp_gpio_enable() still allows requests to disable the pins. This
is intentional as it will be called by ptp_clock_unregister() when tearing
down. Additionally, the core PTP code often ignores the return value of
ptp_disable_pinfunc() anyways. Allowing disables through ensures the
internal driver state matches, while new enable requests are blocked until
the driver is ready.

Signed-off-by: Jacob Keller <[email protected]>
---
 drivers/net/ethernet/intel/ice/ice_ptp.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c 
b/drivers/net/ethernet/intel/ice/ice_ptp.c
index a4c7c36905e8..bf37c2a7ff86 100644
--- a/drivers/net/ethernet/intel/ice/ice_ptp.c
+++ b/drivers/net/ethernet/intel/ice/ice_ptp.c
@@ -1607,6 +1607,9 @@ static int ice_ptp_adjfine(struct ptp_clock_info *info, 
long scaled_ppm)
        u64 incval;
        int err;
 
+       if (pf->ptp.state != ICE_PTP_READY)
+               return -EIO;
+
        incval = adjust_by_scaled_ppm(ice_base_incval(pf), scaled_ppm);
        err = ice_ptp_write_incval_locked(hw, incval);
        if (err) {
@@ -1997,6 +2000,9 @@ static int ice_ptp_gpio_enable(struct ptp_clock_info 
*info,
                struct ptp_perout_request *cached =
                        &pf->ptp.perout_rqs[rq->perout.index];
 
+               if (on && pf->ptp.state != ICE_PTP_READY)
+                       return -EIO;
+
                err = ice_ptp_cfg_perout(pf, &rq->perout, on);
                if (!err) {
                        *cached = rq->perout;
@@ -2011,6 +2017,9 @@ static int ice_ptp_gpio_enable(struct ptp_clock_info 
*info,
                struct ptp_extts_request *cached =
                        &pf->ptp.extts_rqs[rq->extts.index];
 
+               if (on && pf->ptp.state != ICE_PTP_READY)
+                       return -EIO;
+
                err = ice_ptp_cfg_extts(pf, &rq->extts, on);
                if (!err)
                        *cached = rq->extts;
@@ -2065,6 +2074,9 @@ ice_ptp_settime64(struct ptp_clock_info *info, const 
struct timespec64 *ts)
        struct ice_hw *hw = &pf->hw;
        int err;
 
+       if (pf->ptp.state != ICE_PTP_READY)
+               return -EIO;
+
        /* For Vernier mode on E82X, we need to recalibrate after new settime.
         * Start with marking timestamps as invalid.
         */
@@ -2134,6 +2146,9 @@ static int ice_ptp_adjtime(struct ptp_clock_info *info, 
s64 delta)
        struct device *dev;
        int err;
 
+       if (pf->ptp.state != ICE_PTP_READY)
+               return -EIO;
+
        dev = ice_pf_to_dev(pf);
 
        /* Hardware only supports atomic adjustments using signed 32-bit

-- 
2.56.0.215.g47fdf2208c5b

Reply via email to