From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (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 8AA3949E5DD for ; Wed, 2 Sep 2026 13:15:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788354918; cv=none; b=JPyof+f2S6nUt+uJGJVvnPVWoIAue2hESeA88ke15AKnFYPZFb3VjwbA/3yafOMjlecORsH8TC4f/1VjwG2r4Ghq78wi1KIiFIWkRqzXaymKTK/7co7M9tMbyjnISCpYUpwFyQ98dx/an0RI9ALPV2Rv50PikV/nhGqzLPcjswU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788354918; c=relaxed/simple; bh=9WBU4UV+7UtsnX768TqabQ63Pb0Bd1MZ4nCo0ppSUks=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TjlrSuaD5Z8JLD8LrHJZVsTN3F8s6/7omHa42AarnqPhWai8FQSrkblPTEedREc8xjnnx6Kfd+qETMi1FJx4JmUFJcLWKu6bRSc855nlxB4PS/dqjG8ROokTvPcAft5Y+qjPDF8u0dog0x/WzqxS5l/lz5i07XVRrSV3hVaGFaQ= 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=HZFMd9Pj; arc=none smtp.client-ip=209.85.210.182 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="HZFMd9Pj" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-8541875f596so370118b3a.0 for ; Wed, 02 Sep 2026 06:15:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788354916; x=1788959716; 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=V7icB+mFn47r22Tll8dVKEqXUZ7IexWk6IFOaTVD/4o=; b=HZFMd9Pj6C5xMvJRzwUFrhUpAzH8uTqcoy3d+m0S6cnBJpnHeNcGYMEh+ZPIr9cq+j k16GfZQX35cuVySz5d+hKxuquGdCx1t6vXaM2+BMACNiSb+pniT3hJmwLmQ35qpnBl4b 7rAGJpaQLTGzXDxXrl8rrEgpnla6JruVemR2S8TLHIakiY8a8w8NTp4hBN9HnoPjIyaS cPJgjuVDN8H/fyriFh4WsGP5MViPhjWiNCnAPVAIZttuRD/S4f+PCYjcl4Ygc2V/8yIX kNGcCvZ4OAPW1+ibmEw6JUat4KdOn0SQ53TA6Lc+gTkElISwnTZzSw4bdow2xgCsL5Aa FREg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788354916; x=1788959716; 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=V7icB+mFn47r22Tll8dVKEqXUZ7IexWk6IFOaTVD/4o=; b=BhGTIISws/E5GYuJ5RB4ePpH+Uf+aVJGY3vOeEG4qG0hrVDVk4tD8fPNYp63r8f1fp QQhwEcAz2NPI0nZ6nAqGfz4C86pJyzZ8xx9duuuvbBTzdnuQbu68CPrVjBcrMsCXU6Ae 8kHrNwBKDBRXFQROJ5WyA4ye/6IrSiLwmBp524ffMWv/uakSLadOB21IYQ2jaZL+s0fr G4OsntG0oWIPgCtl/vFt6tQqm6c0+cnw5YRPb8nnZSUaW/SnwXhii5D2wI/QhKO+QQPA wZm244Ksy+Y7n45tresDFt4jphQOcswGF7uFQr/1dVkCpYJ97dM53bZ/5qj2p4Hw3D8e fyGA== X-Forwarded-Encrypted: i=1; AKwUvBwfjBAgFun8zo+pY8bLdoYwWo1wxnwuxznocOsXo1aNZUHLHXme7HFGblwUO1TE2ROALnm27AhPbMdJCoA=@vger.kernel.org X-Gm-Message-State: AFuF++kcvvnHu9eqWPLblG+mSCqS7Pgox9pMJVnuZbgyOelfSlU8Jabg x4NagPWbD2OvAyZW6q+s1/XR7WYTh3YQHEYqn5R8Jezh7nISzrdXy697 X-Gm-Gg: AYBFou1ZskJhTODon05klpGLEcnZJ71tOVoCs2GjOMaLpfLLWMX66e0xjXPO6Hl2rv/ Mgjl+eCz3WyONfblKZ8AkpUsKAFUPEtrQAHngAWxduiP8zHp+Nn0TD8nL+mDZIksDJ6q7pAAZbQ Anh7YAMyTM2RSUUNi/UFSf2xAE4sG7KXbpE7zAMSVpzqLVVsXS6VIruHAlwsy2ED2ZOiMYoyIW/ 4Se7HUJbSVkwPNCEU0gv6/vP4uutscbp+ODdOkA0U/e67Iez1MdvE1Q2lN0UtZ3XIrcG730qxou 5/Bj43FR6WRTU7HoRiYtIhaRA0V5/lra30obV6TIMQbiwJGL1hG36IzeTCLMRKtF8WIWow7NmSp /7WaT6O8lZooI3+TScNRti4ubzn80DB6jANc5hkWcfqS9olQWal0khlK7Xuwipgv3g6BW5g/VSv dcAVMA2aFBjS5JApHKjaXCVP5l+0KA8iwBizX+nIWzyhXr/SUQSn8v0yWEFTo= X-Received: by 2002:a05:6a00:8d1:b0:84e:89a:b8ec with SMTP id d2e1a72fcca58-85ed7d20685mr6658379b3a.11.1788354915822; Wed, 02 Sep 2026 06:15:15 -0700 (PDT) Received: from server227.. ([39.170.101.209]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-85da342023asm1398533b3a.0.2026.09.02.06.15.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Sep 2026 06:15:15 -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 v4 1/2] net: stmmac: dwxgmac2: add XGMAC timestamp interrupt support Date: Wed, 2 Sep 2026 21:14:40 +0800 Message-Id: <20260902131441.322167-2-zxyan0222@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260902131441.322167-1-zxyan0222@gmail.com> References: <20260902131441.322167-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 DWXGMAC2 uses XGMAC_TIMESTAMP_STATUS at offset 0xd20, while the generic stmmac PTP handler reads the dwmac4 offset GMAC_TIMESTAMP_STATUS (0xb20). Before this change, the DWXGMAC2 and DWXLGMAC2 hwif entries used &stmmac_ptp, whose timestamp_interrupt callback read the wrong register and whose config_hw_tstamping callback never enabled the XGMAC timestamp interrupt (XGMAC_TSIE was not in XGMAC_INT_DEFAULT_EN). As a result, auxiliary snapshot events were never reported on XGMAC platforms. Add a dedicated DWXGMAC2 timestamp interrupt handler that: - reads XGMAC_TIMESTAMP_STATUS before checking STMMAC_FLAG_EXT_SNAPSHOT_EN, so that the timestamp interrupt status is cleared even when auxiliary snapshots are disabled - derives the pending auxiliary snapshot count from the persistent ATSNS field instead of the transient AUXTSTRIG status bit - generates the corresponding PTP_CLOCK_EXTTS events Also enable XGMAC_TSIE in XGMAC_INT_DEFAULT_EN and hook the new handler into the DWXGMAC2 and DWXLGMAC2 hwif entries. Signed-off-by: Zxyan Zhu --- .../net/ethernet/stmicro/stmmac/dwxgmac2.h | 2 +- .../ethernet/stmicro/stmmac/dwxgmac2_core.c | 43 +++++++++++++++++++ drivers/net/ethernet/stmicro/stmmac/hwif.c | 4 +- drivers/net/ethernet/stmicro/stmmac/hwif.h | 1 + .../ethernet/stmicro/stmmac/stmmac_hwtstamp.c | 12 ++++++ .../net/ethernet/stmicro/stmmac/stmmac_ptp.h | 1 + 6 files changed, 60 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h index f8ab347f7b5b..03cbae326995 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h +++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2.h @@ -87,7 +87,7 @@ #define XGMAC_TSIE BIT(12) #define XGMAC_LPIIE BIT(5) #define XGMAC_PMTIE BIT(4) -#define XGMAC_INT_DEFAULT_EN (XGMAC_LPIIE | XGMAC_PMTIE) +#define XGMAC_INT_DEFAULT_EN (XGMAC_LPIIE | XGMAC_PMTIE | XGMAC_TSIE) #define XGMAC_Qx_TX_FLOW_CTRL(x) (0x00000070 + (x) * 4) #define XGMAC_PT GENMASK(31, 16) #define XGMAC_TFE BIT(1) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c index 1a88cbaed70c..891b7ceea2d4 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c @@ -1154,6 +1154,49 @@ static int dwxgmac2_get_mac_tx_timestamp(struct mac_device_info *hw, u64 *ts) return 0; } +void dwxgmac2_timestamp_interrupt(struct stmmac_priv *priv) +{ + u32 ts_status, pending_snapshots, acr_value, channel; + struct ptp_clock_event event; + unsigned long flags; + u64 ptp_time; + int i; + + /* Read XGMAC_TIMESTAMP_STATUS to get the AUX snapshot + * count. This read also clears the TSIS bit in + * XGMAC_INT_STATUS. + * TX timestamp polling may have already cleared TSIS + * and AUXTSTRIG, so rely on ATSNS instead. + * TXTSC is cleared by XGMAC_TXTIMESTAMP_SEC, not by + * this register, so there is no conflict. + */ + ts_status = readl(priv->ioaddr + XGMAC_TIMESTAMP_STATUS); + + if (!(priv->plat->flags & STMMAC_FLAG_EXT_SNAPSHOT_EN)) + return; + + pending_snapshots = FIELD_GET(XGMAC_TIMESTAMP_ATSNS_MASK, ts_status); + if (!pending_snapshots) + return; + + acr_value = readl(priv->ptpaddr + PTP_ACR); + channel = FIELD_GET(PTP_ACR_MASK, acr_value); + if (!channel) + return; + channel = ilog2(channel); + + for (i = 0; i < pending_snapshots; i++) { + read_lock_irqsave(&priv->ptp_lock, flags); + stmmac_get_ptptime(priv, priv->ptpaddr, &ptp_time); + read_unlock_irqrestore(&priv->ptp_lock, flags); + + event.type = PTP_CLOCK_EXTTS; + event.index = channel; + event.timestamp = ptp_time; + ptp_clock_event(priv->ptp_clock, &event); + } +} + static int dwxgmac2_flex_pps_config(void __iomem *ioaddr, int index, struct stmmac_pps_cfg *cfg, bool enable, u32 sub_second_inc, u32 systime_flags) diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.c b/drivers/net/ethernet/stmicro/stmmac/hwif.c index 265671170bf6..eba87410f985 100644 --- a/drivers/net/ethernet/stmicro/stmmac/hwif.c +++ b/drivers/net/ethernet/stmicro/stmmac/hwif.c @@ -258,7 +258,7 @@ static const struct stmmac_hwif_entry { .dma = &dwxgmac210_dma_ops, .mac = &dwxgmac210_ops, .vlan = &dwxgmac210_vlan_ops, - .hwtimestamp = &stmmac_ptp, + .hwtimestamp = &dwxgmac2_ptp, .ptp = &stmmac_ptp_clock_ops, .mode = NULL, .tc = &dwmac510_tc_ops, @@ -280,7 +280,7 @@ static const struct stmmac_hwif_entry { .dma = &dwxgmac210_dma_ops, .mac = &dwxlgmac2_ops, .vlan = &dwxlgmac2_vlan_ops, - .hwtimestamp = &stmmac_ptp, + .hwtimestamp = &dwxgmac2_ptp, .ptp = &stmmac_ptp_clock_ops, .mode = NULL, .tc = &dwmac510_tc_ops, diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h b/drivers/net/ethernet/stmicro/stmmac/hwif.h index fe18f98fae45..5a308e79db4a 100644 --- a/drivers/net/ethernet/stmicro/stmmac/hwif.h +++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h @@ -672,6 +672,7 @@ extern const struct stmmac_desc_ops ndesc_ops; extern const struct stmmac_hwtimestamp stmmac_ptp; extern const struct stmmac_hwtimestamp dwmac1000_ptp; +extern const struct stmmac_hwtimestamp dwxgmac2_ptp; extern const struct stmmac_mode_ops ring_mode_ops; extern const struct stmmac_mode_ops chain_mode_ops; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c index b9a985fa772c..9d7d24259abd 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c @@ -277,3 +277,15 @@ const struct stmmac_hwtimestamp dwmac1000_ptp = { .get_ptptime = dwmac1000_get_ptptime, .timestamp_interrupt = dwmac1000_timestamp_interrupt, }; + +const struct stmmac_hwtimestamp dwxgmac2_ptp = { + .config_hw_tstamping = config_hw_tstamping, + .init_systime = init_systime, + .config_sub_second_increment = config_sub_second_increment, + .config_addend = config_addend, + .adjust_systime = adjust_systime, + .get_systime = get_systime, + .get_ptptime = get_ptptime, + .timestamp_interrupt = dwxgmac2_timestamp_interrupt, + .hwtstamp_correct_latency = hwtstamp_correct_latency, +}; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h index 3fe0e3a80e80..dade09614163 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h @@ -103,6 +103,7 @@ int dwmac1000_ptp_enable(struct ptp_clock_info *ptp, void dwmac1000_get_ptptime(void __iomem *ptpaddr, u64 *ptp_time); void dwmac1000_timestamp_interrupt(struct stmmac_priv *priv); +void dwxgmac2_timestamp_interrupt(struct stmmac_priv *priv); extern const struct ptp_clock_info stmmac_ptp_clock_ops; extern const struct ptp_clock_info dwmac1000_ptp_clock_ops; -- 2.34.1