From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 72EA7C5DF74 for ; Tue, 18 Aug 2026 13:28:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+3s0Ug7tKmBUVY9glqgI6hd1KhOLM6Z7RD4robd3dno=; b=dAusR++FEeiiiUEW61tqpUPlcZ GkqV3PU+Z5PNk7eVhFjjrN2eAqXoFhhQAj1JcYOZvZPHnUzyToXLGVG6iCipGBv48qBUzbbR+2foD lEHyW3M4ESMBx5yfdflCl9z9iRmYuBaJb37oK9A4HcnjZUhrwfHH4Cny0xHKcWMkLn+V3HQG+Z4Zm rWG9LmtfQXm3vTTGQxzpNdNmkel0/PZuJ/dA/1mb6e6EAoGlo1DF6z0APw1LJ/h4z5/2OlHdmlZO2 FsyLperKnTyv4fosB7j8mk8oAO3YScNWdvLO1ZGSF1jJDzfIEULlk2Yihr/5QccQxChE/HRFj0Roh HMyFJd+w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wwJrD-000000082wm-0E4P; Tue, 18 Aug 2026 13:27:59 +0000 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wwJrA-000000082vf-21dK for linux-arm-kernel@lists.infradead.org; Tue, 18 Aug 2026 13:27:57 +0000 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-4815b8781c7so1873401f8f.0 for ; Tue, 18 Aug 2026 06:27:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787059674; x=1787664474; darn=lists.infradead.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=+3s0Ug7tKmBUVY9glqgI6hd1KhOLM6Z7RD4robd3dno=; b=ax9qN9zWCAR2vmXBTV8Jya61wXEMAJbwgG7XfYV2tmH5dCPafMlwgcwNsT6YOBR2tL GbhnP+zimspyHgJl0QxRcsUirBV3Xesd7pD81AarEw6+KhXcF5UWiqC25m/+j8ZAWlAw rdxaZkn2fOIqePm1D34TtgYS13A9hGx9D5uf3/igFJRodBtROQFooWqYVVhlQLFiq5xE zRlpZJtmbqGxTqnbNSCgMo/cTWwGAhVkmJTqqwVffxe2I7Zkbx3hX5YZQxEe59iXoqmT O/s6l2O2bt23rTcMZ0rczOUEBs1fBYD52OoSoFvRIRx6aaOeMVWgnu/lVkLhgim9VMCo o//A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787059674; x=1787664474; 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=+3s0Ug7tKmBUVY9glqgI6hd1KhOLM6Z7RD4robd3dno=; b=eb6QlbDbbLo/XaAGfTMIitGDrS6RXW3ze/UD78mfHNnItQED0L7DuXNGVvh0Y3oVGo kS1vrLVVIF7Pu1nLg732FpXojixL01mAbnN6IeBEZek2K5GrinNquE3H/Ztx78Q09BTW 1S9qtYzyYzqLLs6UvUzJJFI/Jqz1qYuPwxJgt5ukoxGd9SAHaKVNr7tOk51PwBaRSxsT OR0sarO7c6b75VfY84honHK0U+GZoH0UQ3lOaxsv2pl0UBq+4L3s7Vh49Bw0DQMEdzNQ aTNqJm70K0klKghgkZBJ9OiBgV9ZHubjxGvsp712VWwn784eKjxJBJ9V+aio9Kq8BsrZ FzNA== X-Forwarded-Encrypted: i=1; AHgh+RpD/M2iwOhZuraxkgbxEGbWFzOnGcoB5zc8mYVBGrD598rlPg49tZBpwl5Fh2Dnd0rpCUVJ752goLLo43Dvr80M@lists.infradead.org X-Gm-Message-State: AOJu0YyjAMAwjILKPERGbb+QNtH8kYetyift7SBFPSxMlcg3GbAsXa/y McHziax06A8wjm1zqIJda3sVnZ2KOPeLA/JMMQtfafIGZcYSG7At38s5 X-Gm-Gg: AR+sD13GCVCbORHr7EiXxiK4WDMuYoHh/OICVx8eoFRA4P1+Nl5beTJIx3xD0hUYPGN bNbaQKTIP8PDnCRZVfh6dxBNa+PAsJVa+xc0i7UlH7vDIacVbjHuv248USL9w4uY9SuF33nzIik LJqs58p1SwcnevznF6CO2oaTEeFcbpOlbb5CZuVKkmY5L72i5H6k0vVMc4AFbGFnfA1RiYOdlXv 0hTSvgw7nFxKjGn9A2XLxphSYllUEGbosFPzw+z3xNQyLVZ9tci80ZFdQ6blQ1frmgwOTRPqIas 9hiWEaneGU8thdBdianXCwRz9fZtnxPAnP0p9UeLhKzuq4PGIbfPSlO3npxOfSihoPwM9BbCFpz KW9MJhsvaQdfHaqVBmUWcvwDR6sCrBdg0oy4aX55RG1i8s/U8GpCbIJ/j5mOJLaSnYHTril8tdN ElXm3bHL5Jk8eJeUB0eT++aPJabcgNnMMcfg+X9X+qdVnKZzbz8VGKESOGsTch45RY+TuR0g== X-Received: by 2002:a05:6000:25fe:b0:482:a9d7:7ced with SMTP id ffacd0b85a97d-482a9d77d37mr13957650f8f.14.1787059673878; Tue, 18 Aug 2026 06:27:53 -0700 (PDT) Received: from server227.. ([39.170.101.209]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-482a5a7c568sm12140145f8f.18.2026.08.18.06.27.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Aug 2026 06:27:53 -0700 (PDT) From: Zxyan Zhu To: maxime.chevallier@bootlin.com, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, andrew+netdev@lunn.ch, richardcochran@gmail.com Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, muhammad.nazim.amirul.nazle.asmade@altera.com, Zxyan Zhu Subject: [PATCH net-next v3 1/2] net: stmmac: dwxgmac2: add XGMAC timestamp interrupt support Date: Tue, 18 Aug 2026 21:27:21 +0800 Message-Id: <20260818132722.1852876-2-zxyan0222@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260818132722.1852876-1-zxyan0222@gmail.com> References: <20260818132722.1852876-1-zxyan0222@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260818_062756_563650_6D2FF8C8 X-CRM114-Status: GOOD ( 21.47 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 61b6d45a02f5..76e2860a9517 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 f02b434bbd50..b849cebf9b29 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 511b0fd5e834..9718582b8480 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 e6317b94fff7..818ab3daa91c 100644 --- a/drivers/net/ethernet/stmicro/stmmac/hwif.h +++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h @@ -671,6 +671,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