net: stmmac: do not silently change auxiliary snapshot capture channel
authorJohannes Zink <j.zink@pengutronix.de>
Wed, 18 Oct 2023 07:09:57 +0000 (09:09 +0200)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 19 Oct 2023 11:01:33 +0000 (13:01 +0200)
Even though the hardware theoretically supports up to 4 simultaneous
auxiliary snapshot capture channels, the stmmac driver does support only
a single channel to be active at a time.

Previously in case of a PTP_CLK_REQ_EXTTS request, previously active
auxiliary snapshot capture channels were silently dropped and the new
channel was activated.

Instead of silently changing the state for all consumers, log an error
and return -EBUSY if a channel is already in use in order to signal to
userspace to disable the currently active channel before enabling another one.

Signed-off-by: Johannes Zink <j.zink@pengutronix.de>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c

index 6b639b62f778dd18ff1c4555c7e037f965100c72..bffa5c01703220e0dff2f50734e83f047c3802da 100644 (file)
@@ -191,11 +191,23 @@ static int stmmac_enable(struct ptp_clock_info *ptp,
                                             priv->systime_flags);
                write_unlock_irqrestore(&priv->ptp_lock, flags);
                break;
-       case PTP_CLK_REQ_EXTTS:
+       case PTP_CLK_REQ_EXTTS: {
+               u8 channel;
+
                mutex_lock(&priv->aux_ts_lock);
                acr_value = readl(ptpaddr + PTP_ACR);
+               channel = ilog2(FIELD_GET(PTP_ACR_MASK, acr_value));
                acr_value &= ~PTP_ACR_MASK;
+
                if (on) {
+                       if (FIELD_GET(PTP_ACR_MASK, acr_value)) {
+                               netdev_err(priv->dev,
+                                          "Cannot enable auxiliary snapshot %d as auxiliary snapshot %d is already enabled",
+                                       rq->extts.index, channel);
+                               mutex_unlock(&priv->aux_ts_lock);
+                               return -EBUSY;
+                       }
+
                        priv->plat->flags |= STMMAC_FLAG_EXT_SNAPSHOT_EN;
 
                        /* Enable External snapshot trigger */
@@ -213,6 +225,7 @@ static int stmmac_enable(struct ptp_clock_info *ptp,
                                         !(acr_value & PTP_ACR_ATSFC),
                                         10, 10000);
                break;
+       }
 
        default:
                break;