From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj2-f40.google.com (mail-pj2-f40.google.com [74.125.227.168]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF7E539D6CC for ; Tue, 29 Sep 2026 07:37:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.227.168 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790667439; cv=none; b=DFAt16uM/SWS8gkQkZZytvaOB+U9kM4QM3vYyjGf3bkPct4ZKISYdPjmmGQNflAia25qMCf4kETyggBjYXQxj3n96MpL6PgEx4SxAPwAliJ6aD/9d0fbUj/aWKhYIEMyh9AthUnFgxJYrLdMvbvXqI/qAgx/dL1JWFXhQ9/tNNs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790667439; c=relaxed/simple; bh=+Q5KrLa+RYUVXTCmo/Pl8dhHC3ruyrmu7q7LsWKI10k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=H2fnfm45JiF/EJnoLfSJeKQf7lOwZXyKpW6Bk8PxrbwT2IuE5rNGDSrRPOMFuocTjAvP8vsqtu0E/9CIC1Ak+zNvOatTTj4ffAv65Dq7K26Apitpyr6Rmqm3uxIgz3zm81BeElrrib6nmtb/AZQPREB6+dMNu22COUguyWRH6yE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=pXHMLy59; arc=none smtp.client-ip=74.125.227.168 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pXHMLy59" Received: by mail-pj2-f40.google.com with SMTP id 98e67ed59e1d1-3a0d31bda43so2173977a91.1 for ; Tue, 29 Sep 2026 00:37:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790667434; x=1791272234; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=FTEYOw9n/f+CuyLaWuC1D1eq7TsF3FBxSGnXYETmVL4=; b=pXHMLy59CGs73+DmrA1D0zs2/nEzcu9D+iqgGcE+AYC9hJPzEsmMsA9vZe1xdyrQ1f YH6RPX+FJSdG1/5GyqOY1OYlKOSHscEFIGRJ6eHWlg1MsGqNMPCIwsfSQSt+BcqOLBXW yJ8r+gFYdUfi9fABMJlLyfi1H7HXOnoUqV3dzFKKHD4Oo7VBtNW5i2qNK1AFS/qeYrZ9 H7hRp4YNCutKQ1sNdzA39ikCILPV64nDgcAX3fhJgITrA7+McTQNPqfDaDDafZ/ZmWjT BmqqUeUieM7rgfnSX021DWkB+uPr4gHRNDrTioyG3MvzQI14eXowMCaREM6UbtRRqEar 45DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790667434; x=1791272234; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=FTEYOw9n/f+CuyLaWuC1D1eq7TsF3FBxSGnXYETmVL4=; b=Z2OVLI+4mx2E+r/Rx/j7y7T+01VkZMPwL606jept2RFGu3n7d9PA47yC5hVnkyHFbf hwBKyB2uK9RturPIJxYiBu7jDtTOuC4Mq/hANM+KkTw16H7+gAwYYM8kYKubgbjYzUWP 1EhNfxeckH1p51RaxfT77F2fP8Ck+/XVGeuDEowS7EMGS0HiqrXEE2ERSNKzxgFzbQxU 1E/eIoOYQvnumr0xuSECQFNqZ0w5PFa+2x2JWy6lecS28qR/buYxTV/ZngQBJ4mkw+g5 YqsYaRP4i90hIGiyLeubVxfuKb96yKNiG1dTu6eCJcV+A9gyUmrNrQZ3g8YQt0CHIIfh w50A== X-Forwarded-Encrypted: i=1; AKwUvBzBU0xzm+I11hZ/T9EKCYIWXJB5RfirvFCvVIlKhjVLwu3rtM363Jz9WllPTG9pR35VVwtQLtkfi1Xjkoc=@vger.kernel.org X-Gm-Message-State: AFq9FYKt5bMDx1TdfBKxgGiwOek5Ri9rgp0XhXdtdhqhMFO1wbpR4NV1 w651xkybvvPjOCRSIIlFT1dD6hh/N2wAc4SczZpGs8bEVom3xZCjvIdC X-Gm-Gg: AYBFou0xf6paBuEvXJbMp8yh3NW1EaZuVi8baWppbuk5/r57vQtoiaEGS6JPARkekRr /xZwRdV30WAsD9VHCq6Z7ljktAYqHBjvtGabY8kY9NepnfepBdMKrvLPD+6Ijn/BYRLv3JlFUFK oRS2Rb+tQQdGsrF1zekjtmz3/Tcw0bauYluhGsxyp3gLQ5JaKpxHoq+5Eri+uyp5NxtPYn7IGZ8 xbqvrGR9VFiWetAABLaw2K9qKui824oGXFY9eNnfNMnGRII+BhAe7EXPcGTRHJDXs8EXoiUDrjF +MBc2KAr9zWmFPA1nsaFsmpCKLQ5aVpZwmR7NX0GU688/LhLPV8T9OlnVptVf0eaml3uUg8Nz7z KWNGaaho3gmUZvPrX3UzSBB0+/YpKzcOy8V3+4utCBbAUz8mBUv/KrJQViMOHkcFi3iWUXFwj7F T4uNzvUMIUMp8uUDWZ3LHfx1Iz86Swr3BhxSyH3FO3Ekxqg+AfHFSdLVYqKONMmAfktwEvFg== X-Received: by 2002:a17:90b:4b12:b0:39e:6c6a:4b78 with SMTP id 98e67ed59e1d1-3a098e43c20mr13687872a91.66.1790667434388; Tue, 29 Sep 2026 00:37:14 -0700 (PDT) Received: from server227.. ([39.170.101.209]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3a498ecc986sm1328708a91.3.2026.09.29.00.37.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2026 00:37:14 -0700 (PDT) From: Zxyan Zhu To: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, richardcochran@gmail.com, maxime.chevallier@bootlin.com, muhammad.nazim.amirul.nazle.asmade@altera.com, rohan.g.thomas@altera.com, netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Zxyan Zhu Subject: [PATCH net-next v6 1/3] net: stmmac: dwmac-socfpga: complete cross-timestamp on ATSNS Date: Tue, 29 Sep 2026 15:35:51 +0800 Message-Id: <20260929073553.4136336-2-zxyan0222@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260929073553.4136336-1-zxyan0222@gmail.com> References: <20260929073553.4136336-1-zxyan0222@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The Agilex5 smtg_crosststamp() handler arms an internal auxiliary snapshot, toggles GPO0 and then polls XGMAC_INT_STATUS for TSIS to learn that the snapshot is ready. TSIS is a transient, read-to-clear status bit: it is set by any MAC timestamp event and cleared the moment XGMAC_TIMESTAMP_STATUS is read. That makes the TSIS poll racy in two ways. A stale TSIS latched by an unrelated event satisfies the poll immediately, before the auxiliary snapshot is latched, so the FIFO comes back empty and *device is never written even though the call returns 0. Conversely a concurrent reader of XGMAC_TIMESTAMP_STATUS, such as the TX timestamp completion path, can clear TSIS while the poll is waiting and make it time out with "Wait for time sync operation timeout". The auxiliary snapshot FIFO level is also reported by the ATSNS count in XGMAC_TIMESTAMP_STATUS. Reading XGMAC_TIMESTAMP_STATUS does not affect ATSNS, so the destructive reads above cannot disturb it. Poll ATSNS instead of TSIS, and wait for the PTP_ACR_ATSFC FIFO clear to complete first so a stale ATSNS from a previous snapshot cannot satisfy the poll before the new snapshot is latched. Hold aux_ts_lock across the whole sequence instead of dropping it right after arming, so a concurrent PTP_CLK_REQ_EXTTS request cannot set PTP_ACR_ATSFC and flush the FIFO between the poll and the drain loop, which would leave *device filled from an empty FIFO. Fixes: fd8c4f645496 ("net: stmmac: socfpga: Add hardware supported cross-timestamp") Signed-off-by: Zxyan Zhu --- .../ethernet/stmicro/stmmac/dwmac-socfpga.c | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c index 1d7f0a57d288..c5f71bfc7cf4 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c @@ -337,8 +337,18 @@ static int smtg_crosststamp(ktime_t *device, struct system_counterval_t *system, acr_value = readl(ptpaddr + PTP_ACR); acr_value |= PTP_ACR_ATSFC; writel(acr_value, ptpaddr + PTP_ACR); - /* Release the mutex */ - mutex_unlock(&priv->aux_ts_lock); + + /* Wait for the FIFO clear to complete, so the poll below only + * observes snapshots latched by this trigger. + */ + ret = readl_poll_timeout(ptpaddr + PTP_ACR, acr_value, + !(acr_value & PTP_ACR_ATSFC), 10, 10000); + if (ret) { + mutex_unlock(&priv->aux_ts_lock); + netdev_err(priv->dev, "%s: Failed to clear snapshot FIFO\n", + __func__); + return ret; + } /* Trigger Internal snapshot signal. Create a rising edge by just toggle * the GPO0 to low and back to high. @@ -349,10 +359,16 @@ static int smtg_crosststamp(ktime_t *device, struct system_counterval_t *system, gpio_value |= XGMAC_GPIO_GPO0; writel(gpio_value, ioaddr + XGMAC_GPIO_STATUS); - /* Poll for time sync operation done */ - ret = readl_poll_timeout(priv->ioaddr + XGMAC_INT_STATUS, v, - (v & XGMAC_INT_TSIS), 100, 10000); + /* Wait for the auxiliary snapshot to be latched: the ATSNS count + * is the FIFO level and is not affected by reading + * XGMAC_TIMESTAMP_STATUS, so concurrent readers cannot disturb + * the poll. + */ + ret = readl_poll_timeout(ioaddr + XGMAC_TIMESTAMP_STATUS, v, + FIELD_GET(XGMAC_TIMESTAMP_ATSNS_MASK, v), + 100, 10000); if (ret) { + mutex_unlock(&priv->aux_ts_lock); netdev_err(priv->dev, "%s: Wait for time sync operation timeout\n", __func__); return ret; @@ -364,8 +380,7 @@ static int smtg_crosststamp(ktime_t *device, struct system_counterval_t *system, .use_nsecs = false, }; - num_snapshot = FIELD_GET(XGMAC_TIMESTAMP_ATSNS_MASK, - readl(ioaddr + XGMAC_TIMESTAMP_STATUS)); + num_snapshot = FIELD_GET(XGMAC_TIMESTAMP_ATSNS_MASK, v); /* Repeat until the timestamps are from the FIFO last segment */ for (i = 0; i < num_snapshot; i++) { @@ -375,6 +390,8 @@ static int smtg_crosststamp(ktime_t *device, struct system_counterval_t *system, read_unlock_irqrestore(&priv->ptp_lock, flags); } + mutex_unlock(&priv->aux_ts_lock); + get_smtgtime(priv->mii, SMTG_MDIO_ADDR, &smtg_time); system->cycles = smtg_time; -- 2.34.1