From patchwork Fri Jun 16 10:04:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alexis_Lothor=C3=A9?= X-Patchwork-Id: 13282529 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 D845CEB64D8 for ; Fri, 16 Jun 2023 10:06:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=S1mshSphbMEfvJrWkTxDfQe+LpO037hT5vhVDvTtzPE=; b=swsfuvkjPxZT/k 7T406Y0avJHcQ0NazflbWC9QQBrgNJnuQvJ7NCpO/8FF288awoz54oM4CZPcSYGTKiM1IoLooIJaF 6VRkQOlCSb1gOCoWdBsSoS2JOPF2qCzJA8NBxB9q22kFQaEVfFEqxbRrWa99T801uswBPlq1ASwhD 3W1BOSH9hhxcBjNJ89RorRzfSZ4Ltcv90VFKffJmaJghHkvQNE0ePxfNttWXKIz9hckndml4mN4oY 9A+yaWq4mSlBnORR+gtEq76bQAWW61KI5EZM9zIhciXIONotfFNSS21RVxiysyFrqngy8pXRpb4jc 2ZA76iG5AIjgXX5xMhng==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qA6Kq-00HXs5-0s; Fri, 16 Jun 2023 10:05:40 +0000 Received: from relay7-d.mail.gandi.net ([2001:4b98:dc4:8::227]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qA6Km-00HXpa-1M for linux-arm-kernel@lists.infradead.org; Fri, 16 Jun 2023 10:05:38 +0000 X-GND-Sasl: alexis.lothore@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1686909931; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZQ1+xbvMnidBmGeXT0nP+KHmlPyfa+N1kU3ye5N9Y2M=; b=Sicjf9ks2PJoF/K2iAiEzxbRBrNIvgpB0mTA1GqD4eEWaZ/tLOB7KOSnyaLhISAEocTwyv RPPNUS3DqAW37JRUxacbu68edCx2UY30ktDi8ZHWIPaU3ya2meksVLKyBsbYx8Z9NbUvDu TufohlkapBs05jQMj4Z1KYsaobvwW/QyXoaLG2TKo6rfGryl2XQ/dTwFIZfZAjjr+0dl3Z uho3Q9qfYJAsLMrKUaCReSYe1T/RMrWJp3tNl2W3+RR20V7o1YE5iN3C/mCGPEeHFOqnDc FRadOLh+++SFziNFZf4WOF9z9MFgLm/RUxOx94IdYHQeAe/56hJzx92ZbJ5n1w== X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 83BF520003; Fri, 16 Jun 2023 10:05:30 +0000 (UTC) From: alexis.lothore@bootlin.com To: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , Richard Cochran Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, Thomas Petazzoni , Nicolas Carrier Subject: [PATCH net-next 1/8] net: stmmac: add IP-specific callbacks for auxiliary snapshot Date: Fri, 16 Jun 2023 12:04:02 +0200 Message-ID: <20230616100409.164583-2-alexis.lothore@bootlin.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230616100409.164583-1-alexis.lothore@bootlin.com> References: <20230616100409.164583-1-alexis.lothore@bootlin.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_030536_769797_3043A89A X-CRM114-Status: UNSURE ( 9.30 ) X-CRM114-Notice: Please train this message. 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 From: Alexis Lothoré Since auxiliary snapshots configuration registers may be different depending the DWMAC IP, we need a specific set of callbacks to - configure timestamp snapshot triggers - clear the snapshots FIFO Signed-off-by: Alexis Lothoré --- drivers/net/ethernet/stmicro/stmmac/hwif.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h b/drivers/net/ethernet/stmicro/stmmac/hwif.h index 6ee7cf07cfd7..d0b2f13510aa 100644 --- a/drivers/net/ethernet/stmicro/stmmac/hwif.h +++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h @@ -419,6 +419,10 @@ struct stmmac_ops { void (*fpe_send_mpacket)(void __iomem *ioaddr, enum stmmac_mpacket_type type); int (*fpe_irq_status)(void __iomem *ioaddr, struct net_device *dev); + /* Auxiliary snapshots */ + void (*extts_configure)(void __iomem *ioaddr, int ext_snapshot_num, + bool on, struct net_device *dev); + int (*clear_snapshot_fifo)(void __iomem *ioaddr); }; #define stmmac_core_init(__priv, __args...) \ @@ -523,6 +527,10 @@ struct stmmac_ops { stmmac_do_void_callback(__priv, mac, fpe_send_mpacket, __args) #define stmmac_fpe_irq_status(__priv, __args...) \ stmmac_do_callback(__priv, mac, fpe_irq_status, __args) +#define stmmac_extts_configure(__priv, __args...) \ + stmmac_do_void_callback(__priv, mac, extts_configure, __args) +#define stmmac_clear_snapshot_fifo(__priv, __args...) \ + stmmac_do_callback(__priv, mac, clear_snapshot_fifo, __args) /* PTP and HW Timer helpers */ struct stmmac_hwtimestamp { From patchwork Fri Jun 16 10:04:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alexis_Lothor=C3=A9?= X-Patchwork-Id: 13282531 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 41302EB64DC for ; Fri, 16 Jun 2023 10:06:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=29B9NL1zM2n6mel0QNSROZFO9Gb6aS8IF2tpg4dhsdc=; b=pC7nBABMdV86iN bRuvpb1ejbpES5jVneyAFTXqbnIxmcm7msv9opFJlx/vv6/r40sjp56HWLzvck5VfWv/wgBnwhilN 2QY+GQrelPNhHQstxRxySft6ZXB+kW4yH/G5fLFr7LC29JhRDXna4CHYDCYxqONSmLZV8iiFixum6 pPsh5BuOqVXad8njoikSF0tWBUAgTeoXPJfMMOm3LFX6+P6F0yXyjb0B5kjutzT4OMx2sEseYHf2K oFvLrowfCGPShORLml/FIOBT6Qhyzv2r1pJLoAh7LoyJVGkLoBHOtJ/igFWYr4K35mmtOD+PQ0p9J yYJzEylL5Aa+AT2LNs1Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qA6L3-00HXxh-0f; Fri, 16 Jun 2023 10:05:53 +0000 Received: from relay7-d.mail.gandi.net ([2001:4b98:dc4:8::227]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qA6Km-00HXpb-1M for linux-arm-kernel@lists.infradead.org; Fri, 16 Jun 2023 10:05:40 +0000 X-GND-Sasl: alexis.lothore@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1686909932; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RlKfBubQaLPW6K+ql37Q+2HGvyJMouSBVoPzyWY8+lQ=; b=abt1qeClvlCyL9z75uDOY0nQ5EnUQwmGYXSQLVRjO5Q+K0qaH5HZFECsb/jfWAfTGmiwiI K2G6belDwjs+QVzaFr84OxGGRJanZVw5Tt7qGn91iooeVuNNxqb3F3FTbyS/BAy3Q366vo ITok6AyovOMB4aJhksCAVYNMrYkfnwW4Ryn6V5Ijiw1pjNXEnR9nPeF1zsV96rM0EIRTLf tsK5I/FGVNRZwUIaxl+U5XzLctE3ZsMCdYDT2JoUaxCokTxVIyJcIj3bmR/q/9XJ1BORYA Gy2ZlECDEv9Cf5E2SCPYz+WWeNUWpHcp29AIORVPsW3Hb8B5NNhTTQcum2LiFw== X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id D258D2000D; Fri, 16 Jun 2023 10:05:31 +0000 (UTC) From: alexis.lothore@bootlin.com To: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , Richard Cochran Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, Thomas Petazzoni , Nicolas Carrier Subject: [PATCH net-next 2/8] net: stmmac: populate dwmac4 callbacks for auxiliary snapshots Date: Fri, 16 Jun 2023 12:04:03 +0200 Message-ID: <20230616100409.164583-3-alexis.lothore@bootlin.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230616100409.164583-1-alexis.lothore@bootlin.com> References: <20230616100409.164583-1-alexis.lothore@bootlin.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_030536_770213_98211BD5 X-CRM114-Status: GOOD ( 16.18 ) 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 From: Alexis Lothoré Contrary to generic PTP registers (timestamp control, system time, time update, addend, etc), auxiliary snapshots registers addresses and layout differ depending on exact DWMAC IP. Current implementation matches register layout for DWMAC4, so move current behaviour from stmmac_ptp.c to dwmac4_core.c. Wire those callbacks for all DWMAC4 versions. Signed-off-by: Alexis Lothoré --- drivers/net/ethernet/stmicro/stmmac/dwmac4.h | 22 ++++++++++++ .../net/ethernet/stmicro/stmmac/dwmac4_core.c | 34 +++++++++++++++++++ .../net/ethernet/stmicro/stmmac/stmmac_ptp.c | 24 +++---------- .../net/ethernet/stmicro/stmmac/stmmac_ptp.h | 19 ----------- 4 files changed, 60 insertions(+), 39 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h index d3c5306f1c41..d249a68f6787 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h @@ -51,6 +51,7 @@ #define GMAC_L3_ADDR0(reg) (0x910 + (reg) * 0x30) #define GMAC_L3_ADDR1(reg) (0x914 + (reg) * 0x30) #define GMAC_TIMESTAMP_STATUS 0x00000b20 +#define GMAC_AUXILIARY_CONTROL 0x00000b40 /* Auxiliary Control Reg */ /* RX Queues Routing */ #define GMAC_RXQCTRL_AVCPQ_MASK GENMASK(2, 0) @@ -580,6 +581,27 @@ static inline u32 mtl_low_credx_base_addr(const struct dwmac4_addrs *addrs, #define GMAC_PHYIF_CTRLSTATUS_SPEED_25 0x1 #define GMAC_PHYIF_CTRLSTATUS_SPEED_2_5 0x0 +/* Auxiliary Control defines */ +#define PTP_ACR_ATSFC BIT(0) /* Auxiliary Snapshot FIFO Clear */ +#define PTP_ACR_ATSEN0 BIT(4) /* Auxiliary Snapshot 0 Enable */ +#define PTP_ACR_ATSEN1 BIT(5) /* Auxiliary Snapshot 1 Enable */ +#define PTP_ACR_ATSEN2 BIT(6) /* Auxiliary Snapshot 2 Enable */ +#define PTP_ACR_ATSEN3 BIT(7) /* Auxiliary Snapshot 3 Enable */ +#define PTP_ACR_ATSEN_SHIFT 5 /* Auxiliary Snapshot shift */ +#define PTP_ACR_MASK GENMASK(7, 4) /* Aux Snapshot Mask */ +#define PMC_ART_VALUE0 0x01 /* PMC_ART[15:0] timer value */ +#define PMC_ART_VALUE1 0x02 /* PMC_ART[31:16] timer value */ +#define PMC_ART_VALUE2 0x03 /* PMC_ART[47:32] timer value */ +#define PMC_ART_VALUE3 0x04 /* PMC_ART[63:48] timer value */ +#define GMAC4_ART_TIME_SHIFT 16 /* ART TIME 16-bits shift */ + +enum aux_snapshot { + AUX_SNAPSHOT0 = 0x10, + AUX_SNAPSHOT1 = 0x20, + AUX_SNAPSHOT2 = 0x40, + AUX_SNAPSHOT3 = 0x80, +}; + extern const struct stmmac_dma_ops dwmac4_dma_ops; extern const struct stmmac_dma_ops dwmac410_dma_ops; #endif /* __DWMAC4_H__ */ diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c index 03b1c5a97826..01c0822d37e6 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c @@ -1129,6 +1129,34 @@ static int dwmac4_config_l4_filter(struct mac_device_info *hw, u32 filter_no, return 0; } +static void dwmac4_extts_configure(void __iomem *ioaddr, int ext_snapshot_num, bool on, + struct net_device *dev) +{ + u32 acr_value; + + acr_value = readl(ioaddr + GMAC_AUXILIARY_CONTROL); + acr_value &= ~PTP_ACR_MASK; + if (on) { + /* Enable External snapshot trigger */ + acr_value |= ext_snapshot_num; + acr_value |= PTP_ACR_ATSFC; + netdev_dbg(dev, "Auxiliary Snapshot %d enabled.\n", + ext_snapshot_num >> PTP_ACR_ATSEN_SHIFT); + } else { + netdev_dbg(dev, "Auxiliary Snapshot %d disabled.\n", + ext_snapshot_num >> PTP_ACR_ATSEN_SHIFT); + } + writel(acr_value, ioaddr + GMAC_AUXILIARY_CONTROL); +} + +static int dwmac4_clear_snapshot_fifo(void __iomem *ioaddr) +{ + u32 acr_value; + + return readl_poll_timeout(ioaddr + GMAC_AUXILIARY_CONTROL, acr_value, + !(acr_value & PTP_ACR_ATSFC), 10, 10000); +} + const struct stmmac_ops dwmac4_ops = { .core_init = dwmac4_core_init, .set_mac = stmmac_set_mac, @@ -1169,6 +1197,8 @@ const struct stmmac_ops dwmac4_ops = { .add_hw_vlan_rx_fltr = dwmac4_add_hw_vlan_rx_fltr, .del_hw_vlan_rx_fltr = dwmac4_del_hw_vlan_rx_fltr, .restore_hw_vlan_rx_fltr = dwmac4_restore_hw_vlan_rx_fltr, + .extts_configure = dwmac4_extts_configure, + .clear_snapshot_fifo = dwmac4_clear_snapshot_fifo }; const struct stmmac_ops dwmac410_ops = { @@ -1217,6 +1247,8 @@ const struct stmmac_ops dwmac410_ops = { .add_hw_vlan_rx_fltr = dwmac4_add_hw_vlan_rx_fltr, .del_hw_vlan_rx_fltr = dwmac4_del_hw_vlan_rx_fltr, .restore_hw_vlan_rx_fltr = dwmac4_restore_hw_vlan_rx_fltr, + .extts_configure = dwmac4_extts_configure, + .clear_snapshot_fifo = dwmac4_clear_snapshot_fifo }; const struct stmmac_ops dwmac510_ops = { @@ -1269,6 +1301,8 @@ const struct stmmac_ops dwmac510_ops = { .add_hw_vlan_rx_fltr = dwmac4_add_hw_vlan_rx_fltr, .del_hw_vlan_rx_fltr = dwmac4_del_hw_vlan_rx_fltr, .restore_hw_vlan_rx_fltr = dwmac4_restore_hw_vlan_rx_fltr, + .extts_configure = dwmac4_extts_configure, + .clear_snapshot_fifo = dwmac4_clear_snapshot_fifo }; static u32 dwmac4_get_num_vlan(void __iomem *ioaddr) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c index b4388ca8d211..167bfbf68911 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c @@ -165,11 +165,9 @@ static int stmmac_enable(struct ptp_clock_info *ptp, { struct stmmac_priv *priv = container_of(ptp, struct stmmac_priv, ptp_clock_ops); - void __iomem *ptpaddr = priv->ptpaddr; struct stmmac_pps_cfg *cfg; int ret = -EOPNOTSUPP; unsigned long flags; - u32 acr_value; switch (rq->type) { case PTP_CLK_REQ_PEROUT: @@ -194,26 +192,12 @@ static int stmmac_enable(struct ptp_clock_info *ptp, case PTP_CLK_REQ_EXTTS: priv->plat->ext_snapshot_en = on; mutex_lock(&priv->aux_ts_lock); - acr_value = readl(ptpaddr + PTP_ACR); - acr_value &= ~PTP_ACR_MASK; - if (on) { - /* Enable External snapshot trigger */ - acr_value |= priv->plat->ext_snapshot_num; - acr_value |= PTP_ACR_ATSFC; - netdev_dbg(priv->dev, "Auxiliary Snapshot %d enabled.\n", - priv->plat->ext_snapshot_num >> - PTP_ACR_ATSEN_SHIFT); - } else { - netdev_dbg(priv->dev, "Auxiliary Snapshot %d disabled.\n", - priv->plat->ext_snapshot_num >> - PTP_ACR_ATSEN_SHIFT); - } - writel(acr_value, ptpaddr + PTP_ACR); + stmmac_extts_configure(priv, priv->ioaddr, + priv->plat->ext_snapshot_num, on, + priv->dev); mutex_unlock(&priv->aux_ts_lock); /* wait for auxts fifo clear to finish */ - ret = readl_poll_timeout(ptpaddr + PTP_ACR, acr_value, - !(acr_value & PTP_ACR_ATSFC), - 10, 10000); + ret = stmmac_clear_snapshot_fifo(priv, priv->ioaddr); break; default: diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h index bf619295d079..9e0ff2cec352 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h @@ -67,25 +67,6 @@ #define PTP_SSIR_SSINC_MAX 0xff #define GMAC4_PTP_SSIR_SSINC_SHIFT 16 -/* Auxiliary Control defines */ -#define PTP_ACR_ATSFC BIT(0) /* Auxiliary Snapshot FIFO Clear */ -#define PTP_ACR_ATSEN0 BIT(4) /* Auxiliary Snapshot 0 Enable */ -#define PTP_ACR_ATSEN1 BIT(5) /* Auxiliary Snapshot 1 Enable */ -#define PTP_ACR_ATSEN2 BIT(6) /* Auxiliary Snapshot 2 Enable */ -#define PTP_ACR_ATSEN3 BIT(7) /* Auxiliary Snapshot 3 Enable */ -#define PTP_ACR_ATSEN_SHIFT 5 /* Auxiliary Snapshot shift */ -#define PTP_ACR_MASK GENMASK(7, 4) /* Aux Snapshot Mask */ -#define PMC_ART_VALUE0 0x01 /* PMC_ART[15:0] timer value */ -#define PMC_ART_VALUE1 0x02 /* PMC_ART[31:16] timer value */ -#define PMC_ART_VALUE2 0x03 /* PMC_ART[47:32] timer value */ -#define PMC_ART_VALUE3 0x04 /* PMC_ART[63:48] timer value */ -#define GMAC4_ART_TIME_SHIFT 16 /* ART TIME 16-bits shift */ -enum aux_snapshot { - AUX_SNAPSHOT0 = 0x10, - AUX_SNAPSHOT1 = 0x20, - AUX_SNAPSHOT2 = 0x40, - AUX_SNAPSHOT3 = 0x80, -}; #endif /* __STMMAC_PTP_H__ */ From patchwork Fri Jun 16 10:04:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alexis_Lothor=C3=A9?= X-Patchwork-Id: 13282534 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 8FFBBC0015E for ; Fri, 16 Jun 2023 10:06:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=liIon2ZTveV9Rxy7Iq+hZADXmxSeZ+BbrhG1CQCMUTA=; b=iKVcQz2wkTrc8F ydhUMG2gBbo931hHTVYD7KLVsxaaOse9bW5xBSJ3kOEesng1BF37alN0nyWWCIchIqASwBQSgQAzK aBwGdMow1Up/RCRieDxOiPQVCJVR8gbEB0ZO0qdhtLOSZ3yOsO8Ej5WVzXWFGrD2Er3x4uzMH8xVP 5To01ZgnBF17oRXYI4uFiVj8CnI+5pqZBlcstbmPSnRaYkFluY855O/3QMhj4qDZP2cx3O5FpAirc 1Z4a8Z6pckmLyKGAvP8YhNpjl5YEgz992ZLfI81P7Q+V2gz8pNQcKz9kZ0OfI8xczaxzOqMHD33qO hqUaYc5ilmTuLvKoOBiw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qA6L3-00HXy1-2F; Fri, 16 Jun 2023 10:05:53 +0000 Received: from relay7-d.mail.gandi.net ([217.70.183.200]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qA6Kn-00HXpe-14 for linux-arm-kernel@lists.infradead.org; Fri, 16 Jun 2023 10:05:40 +0000 X-GND-Sasl: alexis.lothore@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1686909934; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bu3ZgXdHuaAGXwkANc4+sjRTQos43KxjZuFR24WnayE=; b=MB6d8Q+efJDjMCCibSm0q2VQUawspSNupGdeu4AIyYnF8Kr/l2mSqcHmOklij2dXf0xHUk tjpJ5i/Mi+0wmJExgdWlqVW/EeLGopEBvb5S7RLExSoEDMwzH5NG5cdznKjVziHCoAhNMv HTftMCzak3QoMU8w92BIjqKQtJCwUndNbxSE5G4SDWYX18y5NO+ebczf/lCTkPfOr/KlNQ xjmsdTImMhCVfrhyc3SZgGs8QxDijRNejOAKG5t8JlfOiAHMljNy/Ds/Sc8kN6GQlh7sqF Wb9IGt0MI7XvUZHfT5Rn5v98g5wbq3yY2zEk2lbKidkyldL9m6SE5koVDAHj9Q== X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 0F28620010; Fri, 16 Jun 2023 10:05:33 +0000 (UTC) From: alexis.lothore@bootlin.com To: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , Richard Cochran Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, Thomas Petazzoni , Nicolas Carrier Subject: [PATCH net-next 3/8] net: stmmac: move PTP interrupt handling to IP-specific DWMAC file Date: Fri, 16 Jun 2023 12:04:04 +0200 Message-ID: <20230616100409.164583-4-alexis.lothore@bootlin.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230616100409.164583-1-alexis.lothore@bootlin.com> References: <20230616100409.164583-1-alexis.lothore@bootlin.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_030537_650684_CF55ACC6 X-CRM114-Status: GOOD ( 19.98 ) 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 From: Alexis Lothoré As for auxiliary snapshot triggers configuration, reading snapshots depends on specific registers addresses and layout. As a consequence, move PTP-specific part of stmmac interrupt handling to specific DWMAC IP file Signed-off-by: Alexis Lothoré --- drivers/net/ethernet/stmicro/stmmac/dwmac4.h | 2 + .../net/ethernet/stmicro/stmmac/dwmac4_core.c | 51 ++++++++++++++++++ .../ethernet/stmicro/stmmac/stmmac_hwtstamp.c | 52 ------------------- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 2 - .../net/ethernet/stmicro/stmmac/stmmac_ptp.h | 3 -- 5 files changed, 53 insertions(+), 57 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h index d249a68f6787..9e7ba5f2e53a 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h @@ -52,6 +52,8 @@ #define GMAC_L3_ADDR1(reg) (0x914 + (reg) * 0x30) #define GMAC_TIMESTAMP_STATUS 0x00000b20 #define GMAC_AUXILIARY_CONTROL 0x00000b40 /* Auxiliary Control Reg */ +#define GMAC_AT_NS 0x00000b48 /* Auxiliary Timestamp - Nanoseconds Reg */ +#define GMAC_AT_S 0x00000b4c /* Auxiliary Timestamp - Seconds Reg */ /* RX Queues Routing */ #define GMAC_RXQCTRL_AVCPQ_MASK GENMASK(2, 0) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c index 01c0822d37e6..b36fbb0fa5da 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c @@ -16,6 +16,7 @@ #include #include "stmmac.h" #include "stmmac_pcs.h" +#include "stmmac_ptp.h" #include "dwmac4.h" #include "dwmac5.h" @@ -798,9 +799,56 @@ static int dwmac4_irq_mtl_status(struct stmmac_priv *priv, return ret; } +static void get_ptptime(void __iomem *ioaddr, u64 *ptp_time) +{ + u64 ns; + + ns = readl(ioaddr + GMAC_AT_NS); + ns += readl(ioaddr + GMAC_AT_S) * NSEC_PER_SEC; + + *ptp_time = ns; +} + +static void dwmac4_ptp_isr(struct stmmac_priv *priv) +{ + u32 num_snapshot, ts_status; + struct ptp_clock_event event; + unsigned long flags; + u64 ptp_time; + int i; + + if (priv->plat->int_snapshot_en) { + wake_up(&priv->tstamp_busy_wait); + return; + } + + /* Read timestamp status to clear interrupt from either external + * timestamp or start/end of PPS. + */ + ts_status = readl(priv->ioaddr + GMAC_TIMESTAMP_STATUS); + + if (!priv->plat->ext_snapshot_en) + return; + + num_snapshot = (ts_status & GMAC_TIMESTAMP_ATSNS_MASK) >> + GMAC_TIMESTAMP_ATSNS_SHIFT; + + for (i = 0; i < num_snapshot; i++) { + read_lock_irqsave(&priv->ptp_lock, flags); + get_ptptime(priv->ioaddr, &ptp_time); + read_unlock_irqrestore(&priv->ptp_lock, flags); + event.type = PTP_CLOCK_EXTTS; + event.index = 0; + event.timestamp = ptp_time; + ptp_clock_event(priv->ptp_clock, &event); + } +} + static int dwmac4_irq_status(struct mac_device_info *hw, struct stmmac_extra_stats *x) { + struct stmmac_priv *priv = + container_of(x, struct stmmac_priv, xstats); void __iomem *ioaddr = hw->pcsr; u32 intr_status = readl(ioaddr + GMAC_INT_STATUS); u32 intr_enable = readl(ioaddr + GMAC_INT_EN); @@ -841,6 +889,9 @@ static int dwmac4_irq_status(struct mac_device_info *hw, x->irq_rx_path_exit_lpi_mode_n++; } + if (intr_status & time_stamp_irq) + dwmac4_ptp_isr(priv); + dwmac_pcs_isr(ioaddr, GMAC_PCS_BASE, intr_status, x); if (intr_status & PCS_RGSMIIIS_IRQ) dwmac4_phystatus(ioaddr, x); diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c index 8b50f03056b7..2cd0ec17f4c6 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c @@ -162,56 +162,6 @@ static void get_systime(void __iomem *ioaddr, u64 *systime) *systime = ns + (sec1 * 1000000000ULL); } -static void get_ptptime(void __iomem *ptpaddr, u64 *ptp_time) -{ - u64 ns; - - ns = readl(ptpaddr + PTP_ATNR); - ns += readl(ptpaddr + PTP_ATSR) * NSEC_PER_SEC; - - *ptp_time = ns; -} - -static void timestamp_interrupt(struct stmmac_priv *priv) -{ - u32 num_snapshot, ts_status, tsync_int; - struct ptp_clock_event event; - unsigned long flags; - u64 ptp_time; - int i; - - if (priv->plat->int_snapshot_en) { - wake_up(&priv->tstamp_busy_wait); - return; - } - - tsync_int = readl(priv->ioaddr + GMAC_INT_STATUS) & GMAC_INT_TSIE; - - if (!tsync_int) - return; - - /* Read timestamp status to clear interrupt from either external - * timestamp or start/end of PPS. - */ - ts_status = readl(priv->ioaddr + GMAC_TIMESTAMP_STATUS); - - if (!priv->plat->ext_snapshot_en) - return; - - num_snapshot = (ts_status & GMAC_TIMESTAMP_ATSNS_MASK) >> - GMAC_TIMESTAMP_ATSNS_SHIFT; - - for (i = 0; i < num_snapshot; i++) { - read_lock_irqsave(&priv->ptp_lock, flags); - get_ptptime(priv->ptpaddr, &ptp_time); - read_unlock_irqrestore(&priv->ptp_lock, flags); - event.type = PTP_CLOCK_EXTTS; - event.index = 0; - event.timestamp = ptp_time; - ptp_clock_event(priv->ptp_clock, &event); - } -} - const struct stmmac_hwtimestamp stmmac_ptp = { .config_hw_tstamping = config_hw_tstamping, .init_systime = init_systime, @@ -219,6 +169,4 @@ const struct stmmac_hwtimestamp stmmac_ptp = { .config_addend = config_addend, .adjust_systime = adjust_systime, .get_systime = get_systime, - .get_ptptime = get_ptptime, - .timestamp_interrupt = timestamp_interrupt, }; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 5c645b6d5660..4f0ef73d5121 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -5804,8 +5804,6 @@ static void stmmac_common_interrupt(struct stmmac_priv *priv) else netif_carrier_off(priv->dev); } - - stmmac_timestamp_interrupt(priv, priv); } } diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h index 9e0ff2cec352..92ed421702b9 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h @@ -23,9 +23,6 @@ #define PTP_STSUR 0x10 /* System Time – Seconds Update Reg */ #define PTP_STNSUR 0x14 /* System Time – Nanoseconds Update Reg */ #define PTP_TAR 0x18 /* Timestamp Addend Reg */ -#define PTP_ACR 0x40 /* Auxiliary Control Reg */ -#define PTP_ATNR 0x48 /* Auxiliary Timestamp - Nanoseconds Reg */ -#define PTP_ATSR 0x4c /* Auxiliary Timestamp - Seconds Reg */ #define PTP_STNSUR_ADDSUB_SHIFT 31 #define PTP_DIGITAL_ROLLOVER_MODE 0x3B9ACA00 /* 10e9-1 ns */ From patchwork Fri Jun 16 10:04:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alexis_Lothor=C3=A9?= X-Patchwork-Id: 13282532 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 A6E69EB64DD for ; Fri, 16 Jun 2023 10:06:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=g6zqkuK6uvAYgrZNgyJF/2dABQoh7zYSYVqMYWijJLA=; b=1KLkU6R/W1WoOH BQBAkzfMOOqxXyd4Qp+3qJGzkR2XzN6FDBXj0rSQpIn9n7JFzIjyP/RR/x8tWTXkG7JtY9tAuBE+8 4/lTC2qr7iqoL93s5bgpXG3lYl3A4aYNDCn7PkuTclyJw3wgUp/wDEZcTddWApqvuq23vC9yGs9Vn uYY5vB5e2h6MOTD4q68Ib6U+/y2r/7Cw0e95SzBYW3UgGVK9630D/RpwWQTDHd7m//lHRhQjlyaXU Njezpo9GKjeuL5oGCEktjb2WUquMYYtUFO2jXfm1nfnGsdiFgy1NpwcUWcnDBt4PUCUWpybJlqYBU LzWObOMDnO6jh7oAa67w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qA6L2-00HXwg-0n; Fri, 16 Jun 2023 10:05:52 +0000 Received: from relay7-d.mail.gandi.net ([2001:4b98:dc4:8::227]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qA6Kn-00HXpg-0K for linux-arm-kernel@lists.infradead.org; Fri, 16 Jun 2023 10:05:39 +0000 X-GND-Sasl: alexis.lothore@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1686909935; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WQbCjIioSzpbvbd6fIl1lAwDG3upjPsirLpyT1TX/+k=; b=FwY8GMlD/bBWxk8342rA6F1IqDZ1jjrj++Nq7MUtdB9mGuU2C72330sqMSEubUgeEIby8G /FuksITI31BlpVpofEogiJe3NdE4Z6hwTtxfe3ErdY5NALmv5t5hivLA/jaS8xC1mvMdkd e5uSI0AB5xO0bjjobDQqbRV55DjeDv6ZmqFrijmS+caeeq2xP72H2zv8CeFzAlmQgfAPhc L1S5kQ8TPNghKGkjm3xR+xQX4NL9Uumb8MGH9pOAS30gyGcKbq0nZBbk+KfGxcd1+6mzkq nI8ebkmz5rZgSV/WTqv7Bark6usUQJnoutNBXNcICbmq3FNiSLzngxksao9tEA== X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 6708420002; Fri, 16 Jun 2023 10:05:34 +0000 (UTC) From: alexis.lothore@bootlin.com To: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , Richard Cochran Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, Thomas Petazzoni , Nicolas Carrier Subject: [PATCH net-next 4/8] net: stmmac: move common defines in stmmac_ptp.h Date: Fri, 16 Jun 2023 12:04:05 +0200 Message-ID: <20230616100409.164583-5-alexis.lothore@bootlin.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230616100409.164583-1-alexis.lothore@bootlin.com> References: <20230616100409.164583-1-alexis.lothore@bootlin.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_030537_443497_AA646421 X-CRM114-Status: GOOD ( 11.89 ) 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 From: Alexis Lothoré Even if the address of registers containing statuses is not the same between dwamc4 and dwmac 1000, the offsets of interest inside those register are the same regarding auxiliary snapshots. As a consequence, move those offset definitions in stmmac_ptp.h Signed-off-by: Alexis Lothoré --- drivers/net/ethernet/stmicro/stmmac/dwmac4.h | 5 ----- drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h | 4 +++- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h index 9e7ba5f2e53a..32a15c020a43 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4.h +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4.h @@ -313,11 +313,6 @@ enum power_event { #define GMAC_L4DP0_SHIFT 16 #define GMAC_L4SP0 GENMASK(15, 0) -/* MAC Timestamp Status */ -#define GMAC_TIMESTAMP_AUXTSTRIG BIT(2) -#define GMAC_TIMESTAMP_ATSNS_MASK GENMASK(29, 25) -#define GMAC_TIMESTAMP_ATSNS_SHIFT 25 - /* MTL registers */ #define MTL_OPERATION_MODE 0x00000c00 #define MTL_FRPE BIT(15) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h index 92ed421702b9..04bbf12dfd4b 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h @@ -64,6 +64,8 @@ #define PTP_SSIR_SSINC_MAX 0xff #define GMAC4_PTP_SSIR_SSINC_SHIFT 16 - +/* MAC Timestamp Status */ +#define GMAC_TIMESTAMP_ATSNS_MASK GENMASK(29, 25) +#define GMAC_TIMESTAMP_ATSNS_SHIFT 25 #endif /* __STMMAC_PTP_H__ */ From patchwork Fri Jun 16 10:04:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alexis_Lothor=C3=A9?= X-Patchwork-Id: 13282533 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 879B1EB64DA for ; Fri, 16 Jun 2023 10:06:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=PPdLg/3MSBInBvBFICEF/Td0ruQY8eDNaoFwd8khqkA=; b=QKVb6vMRKpxrK3 3VIBsa4o4ZCx9RW4+OrwzV6AQ7yUeiZh0sKF2WoW1aMEhXcZu1SmVk992jes9w4XBDU0p+T0/sEd0 VGTw/qNCnoJDkrdCof1ZYCFaC+uebfii+nEgSOoScdZrJIVcn8Mm8MBJsuATtqWThlJ/jJFz7Wrjw AbIlziArWw/gRsNXY3ridadJu0wjwDg/ristcOG8gVpjby6vKZVehARtfEHJk9pTp5jT4RkzUp+Rr hDGJyrSZtRLoPqs4QI2s9GJndxpV7ERnrTfXdUD0qBkCLpfWC3xTEZrPcw7Os/hMD6ryHW/be/yDf iQXqeYVkNEDkDAnk2LHw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qA6L2-00HXx4-2L; Fri, 16 Jun 2023 10:05:52 +0000 Received: from relay7-d.mail.gandi.net ([2001:4b98:dc4:8::227]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qA6Ko-00HXqK-1D for linux-arm-kernel@lists.infradead.org; Fri, 16 Jun 2023 10:05:39 +0000 X-GND-Sasl: alexis.lothore@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1686909936; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TuLT0Dx8INmVuQ+Tjg5nObFk3ZPU55oE6gxmpAOjP2k=; b=lzUlV6Vl1+7PGIIxMRVfnCBB6Dz/NpkZawq1V/uJWhuAkOFIuN+draPM1L5Gg566KO4kvF z8zjlfLDt8oXatl77D3OHSqS/P5KebT1YLOHsBw2aGvtvFrYeZsNMFFYazPh/h80l8mpzu PjKiDGTM7rvRB7E9n7NNjVRH/0TnjV+/oNTag4KyZ4mLPJGNMpdliEy5NXYRM9kHDAAqC1 NqCggXkU2o8fSr+1asolZiUSSvxvvj1VmoZOTRnkNtWvMgaGMZthqLCU+yZqKtSF6riVM0 SpxF5DQJi9JFcreWJcbOgVttfiHi08F8TPdlEpG1VL1p168dIPEAdqu27IChVw== X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id ADD9920007; Fri, 16 Jun 2023 10:05:35 +0000 (UTC) From: alexis.lothore@bootlin.com To: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , Richard Cochran Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, Thomas Petazzoni , Nicolas Carrier Subject: [PATCH net-next 5/8] net: stmmac: set number of snapshot external triggers for GMAC3 Date: Fri, 16 Jun 2023 12:04:06 +0200 Message-ID: <20230616100409.164583-6-alexis.lothore@bootlin.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230616100409.164583-1-alexis.lothore@bootlin.com> References: <20230616100409.164583-1-alexis.lothore@bootlin.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_030538_581290_895A1D62 X-CRM114-Status: GOOD ( 11.06 ) 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 From: Alexis Lothoré While GMAC4 exposes number of available auxiliary snapshots inputs in MAC_HW_FEATURE2 register, GMAC3 (DWMAC1000) does not expose this information in its only hardware feature register. When running on GMAC3, hardcode the value to 1 to allow external trigger usage Signed-off-by: Alexis Lothoré --- drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c index 167bfbf68911..090a9d803446 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c @@ -280,7 +280,10 @@ void stmmac_ptp_register(struct stmmac_priv *priv) priv->plat->cdc_error_adj = (2 * NSEC_PER_SEC) / priv->plat->clk_ptp_rate; stmmac_ptp_clock_ops.n_per_out = priv->dma_cap.pps_out_num; - stmmac_ptp_clock_ops.n_ext_ts = priv->dma_cap.aux_snapshot_n; + /* Number of available external triggers is not provided through a + * hardware capabilities register for GMAC3 + */ + stmmac_ptp_clock_ops.n_ext_ts = priv->plat->has_gmac ? 1 : priv->dma_cap.aux_snapshot_n; rwlock_init(&priv->ptp_lock); mutex_init(&priv->aux_ts_lock); From patchwork Fri Jun 16 10:04:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alexis_Lothor=C3=A9?= X-Patchwork-Id: 13282535 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 7FBE0EB64DC for ; Fri, 16 Jun 2023 10:06:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=qKbnFkROIJ5J2ZxYJBUwr34TWSKzo/pgsxwr1sfuuws=; b=MwrPtjoXI8HuJ9 JeobxBfHtTiMxRpNwMuGJm8kUcVHsF6KsrzcO09+K05WC8xuVKij5dTOF+HA2CrAwAuivtotCmaTo rDkFbqzRUXtU4IetFmgkbhTBnRXKW7poeSJo8Yp7O4JY4JvA2ZUJWiBgWgSCaBymZtinGgg5Mbf2S f7pm1BK/2loqzMrgseSqjwSvIHcWGiNMUSnxei3QYUIQUGcwIEJRe1X2fHk7ymEDdb9tlmBgqcqUa fSRmbFBDptDLfsfYP0HQVA8TVxYuy1oR58Y5+CADodoHiNVOOvQqui10XzE/n9fRY7M0RMeVcVsdD bL/+1bD6GERep5jJxVlw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qA6L4-00HXya-0a; Fri, 16 Jun 2023 10:05:54 +0000 Received: from relay7-d.mail.gandi.net ([217.70.183.200]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qA6Kp-00HXqt-1B for linux-arm-kernel@lists.infradead.org; Fri, 16 Jun 2023 10:05:41 +0000 X-GND-Sasl: alexis.lothore@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1686909938; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NYtleP6ALm9DjFnX75BkWEiXccu4UQqKWZMcyeQcTVc=; b=bVuD32OCRkfoKqqd+GjpOZlYBL3/cZ0Gs1SZIDvFe+/r51UUGDB5Cx5AYiAKtYihhicTB9 QPA8ezsc4lv0pVDzIXZ/E4xMMXQ2cVJPko+EmH4Qer8NH3fl7CN07G4C1ufbp0DO3OZdA8 R5SO/tk4qD/V6AIFTnmJWYx6hHYkLiT1lEEBlfXgZJSx2giXMIEbIIHy5FIKi4DTWzbqhp BBZ+OAPvRSYaki/0kKFa8d5l6n0JpTLOZPKiX/TCp20ieG/9r8tiIUn8Mwn+Rg9341eCIJ UQcYf+abSmCGMKr5WDElVT3bSdYWIr9FrcHr77Xp6qe2awhZVUVwvtHIBZp1fw== X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id EB87C20013; Fri, 16 Jun 2023 10:05:36 +0000 (UTC) From: alexis.lothore@bootlin.com To: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , Richard Cochran Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, Thomas Petazzoni , Nicolas Carrier Subject: [PATCH net-next 6/8] net: stmmac: introduce setter/getter for timestamp configuration Date: Fri, 16 Jun 2023 12:04:07 +0200 Message-ID: <20230616100409.164583-7-alexis.lothore@bootlin.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230616100409.164583-1-alexis.lothore@bootlin.com> References: <20230616100409.164583-1-alexis.lothore@bootlin.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_030539_674347_34992CE6 X-CRM114-Status: GOOD ( 14.89 ) 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 From: Alexis Lothoré stmmac_hwtstamp_set currently writes the whole Timestamp Control register when configuring hardware timestamping. It is done for all GMAC variants, and leads to issues with DWMAC1000: this version also bears the Auxiliary Snapshot Trigger bit in the same register. This field, which is set independently with during PTP_CLK_REQ_EXTTS ioctl, is then overwritten when stmmac_hwtstamp_set is called. Introduce setter and getter to allow modifying only relevant parts of the timestamp control register instead of overwriting it all. Signed-off-by: Alexis Lothoré --- drivers/net/ethernet/stmicro/stmmac/hwif.h | 9 ++++++--- drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c | 10 ++++++++-- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 4 ++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h b/drivers/net/ethernet/stmicro/stmmac/hwif.h index d0b2f13510aa..927324e3d748 100644 --- a/drivers/net/ethernet/stmicro/stmmac/hwif.h +++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h @@ -534,7 +534,8 @@ struct stmmac_ops { /* PTP and HW Timer helpers */ struct stmmac_hwtimestamp { - void (*config_hw_tstamping) (void __iomem *ioaddr, u32 data); + void (*config_hw_tstamping_set)(void __iomem *ioaddr, u32 data); + u32 (*config_hw_tstamping_get)(void __iomem *ioaddr); void (*config_sub_second_increment)(void __iomem *ioaddr, u32 ptp_clock, int gmac4, u32 *ssinc); int (*init_systime) (void __iomem *ioaddr, u32 sec, u32 nsec); @@ -546,8 +547,10 @@ struct stmmac_hwtimestamp { void (*timestamp_interrupt)(struct stmmac_priv *priv); }; -#define stmmac_config_hw_tstamping(__priv, __args...) \ - stmmac_do_void_callback(__priv, ptp, config_hw_tstamping, __args) +#define stmmac_config_hw_tstamping_set(__priv, __args...) \ + stmmac_do_void_callback(__priv, ptp, config_hw_tstamping_set, __args) +#define stmmac_config_hw_tstamping_get(__priv, __args...) \ + stmmac_do_callback(__priv, ptp, config_hw_tstamping_get, __args) #define stmmac_config_sub_second_increment(__priv, __args...) \ stmmac_do_void_callback(__priv, ptp, config_sub_second_increment, __args) #define stmmac_init_systime(__priv, __args...) \ diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c index 2cd0ec17f4c6..cbb94d3e0fa1 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c @@ -18,11 +18,16 @@ #include "dwmac4.h" #include "stmmac.h" -static void config_hw_tstamping(void __iomem *ioaddr, u32 data) +static void config_hw_tstamping_set(void __iomem *ioaddr, u32 data) { writel(data, ioaddr + PTP_TCR); } +static u32 config_hw_tstamping_get(void __iomem *ioaddr) +{ + return readl(ioaddr + PTP_TCR); +} + static void config_sub_second_increment(void __iomem *ioaddr, u32 ptp_clock, int gmac4, u32 *ssinc) { @@ -163,7 +168,8 @@ static void get_systime(void __iomem *ioaddr, u64 *systime) } const struct stmmac_hwtimestamp stmmac_ptp = { - .config_hw_tstamping = config_hw_tstamping, + .config_hw_tstamping_set = config_hw_tstamping_set, + .config_hw_tstamping_get = config_hw_tstamping_get, .init_systime = init_systime, .config_sub_second_increment = config_sub_second_increment, .config_addend = config_addend, diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 4f0ef73d5121..528d2e010926 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -792,7 +792,7 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr) ts_master_en | snap_type_sel; } - stmmac_config_hw_tstamping(priv, priv->ptpaddr, priv->systime_flags); + stmmac_config_hw_tstamping_set(priv, priv->ptpaddr, priv->systime_flags); memcpy(&priv->tstamp_config, &config, sizeof(config)); @@ -841,7 +841,7 @@ int stmmac_init_tstamp_counter(struct stmmac_priv *priv, u32 systime_flags) if (!(priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp)) return -EOPNOTSUPP; - stmmac_config_hw_tstamping(priv, priv->ptpaddr, systime_flags); + stmmac_config_hw_tstamping_set(priv, priv->ptpaddr, systime_flags); priv->systime_flags = systime_flags; /* program Sub Second Increment reg */ From patchwork Fri Jun 16 10:04:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alexis_Lothor=C3=A9?= X-Patchwork-Id: 13282537 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 43B14EB64DA for ; Fri, 16 Jun 2023 10:06:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=BjLusp/Dw2J00hSJ3ceuSgOHRFXpUrKKGwL6r1+Flf4=; b=I7kgLkxYI+VPdl TwTlxCCs9NjSJtbNHzZ47/uGau5UjKmJgb9sltUDnrceMA0uK6BR0NivwsGYlfPV/8WcO0gMtIF2A pnMNp/keoZSBELvqkyaqzgMoapf7LcV7thsZb46IxVIJvboaVP36hmXR1YhDGYhuVfUXZXy74g6dc aWcAHDAJaGEsRVBltpea4xGeDsrWtCW6EWsrSPHYWKpu52r5eIu4984qTv+cY+jyglmiuXgc5Vsyo HOyzDBlc2YVBj5NP1Re2XRDQ1u6R5NNqA/xsEz2VXvFBbFrUiBA9I/G14mlF/KxIkhFK8HU0bhU3S soMSmvOSOJocPq1hC17Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qA6L4-00HXz0-29; Fri, 16 Jun 2023 10:05:54 +0000 Received: from relay7-d.mail.gandi.net ([2001:4b98:dc4:8::227]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qA6Kq-00HXrO-2j for linux-arm-kernel@lists.infradead.org; Fri, 16 Jun 2023 10:05:42 +0000 X-GND-Sasl: alexis.lothore@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1686909939; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rkCCowvxOYGZg7Z9wbkDB7S4cuEwrkMFzeVio1wTdXo=; b=NlNjR5IkiS/CJUICRXHd3Pdo1W8yas6A2Oo6pwfqiAQO+7QGvo0k3a8IM+afn5B2XKdwbr MtWhVmbCN5DDEioTii3QuSGjQfveVj0G0Z/sJBRwIdWmECCZuMGdr4u7V1a/ss6AhgUQMg PVSZdgDUpckaph1m4J6etyD8BvA1x/eynmEZTnzUq9ALTNbD5dj4Nj1H0odPELVqLvjir6 onQGCqinFG/Wk6VozVsdDsZPNGuEzLFuZUre7dTmQ/OYkkzcVCWJZQXo7F0UoykYmDAUIE 9xy34PWfCvDrG9OGH1DwUk2YpoiMDT6jVQHxr/OQWJXCZsE0d3ec7yOTicWFmw== X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 2E0CE2000F; Fri, 16 Jun 2023 10:05:38 +0000 (UTC) From: alexis.lothore@bootlin.com To: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , Richard Cochran Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, Thomas Petazzoni , Nicolas Carrier Subject: [PATCH net-next 7/8] net: stmmac: do not overwrite other flags when writing timestamp control Date: Fri, 16 Jun 2023 12:04:08 +0200 Message-ID: <20230616100409.164583-8-alexis.lothore@bootlin.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230616100409.164583-1-alexis.lothore@bootlin.com> References: <20230616100409.164583-1-alexis.lothore@bootlin.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_030541_200518_DF8F216D X-CRM114-Status: GOOD ( 11.69 ) 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 From: Alexis Lothoré On some versions of GMAC IP, for example, DWMAC1000, we may overwrite some other flags like ATSEN0 when writing Timestamp Control register. Avoid overwriting those additional flags by setting a read-write-modify process only on flags of interest Signed-off-by: Alexis Lothoré --- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 528d2e010926..ba483adf4e1a 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -616,6 +616,10 @@ static void stmmac_get_rx_hwtstamp(struct stmmac_priv *priv, struct dma_desc *p, */ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr) { + u32 reset_mask = PTP_TCR_SNAPTYPSEL_1 | PTP_TCR_TSIPV4ENA | + PTP_TCR_TSIPV6ENA | PTP_TCR_TSEVNTENA | + PTP_TCR_TSMSTRENA | PTP_TCR_TSVER2ENA | + PTP_TCR_TSIPENA | PTP_TCR_TSENALL; struct stmmac_priv *priv = netdev_priv(dev); struct hwtstamp_config config; u32 ptp_v2 = 0; @@ -783,7 +787,9 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr) priv->hwts_rx_en = ((config.rx_filter == HWTSTAMP_FILTER_NONE) ? 0 : 1); priv->hwts_tx_en = config.tx_type == HWTSTAMP_TX_ON; - priv->systime_flags = STMMAC_HWTS_ACTIVE; + priv->systime_flags = stmmac_config_hw_tstamping_get(priv, priv->ptpaddr); + priv->systime_flags &= ~reset_mask; + priv->systime_flags |= STMMAC_HWTS_ACTIVE; if (priv->hwts_tx_en || priv->hwts_rx_en) { priv->systime_flags |= tstamp_all | ptp_v2 | From patchwork Fri Jun 16 10:04:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alexis_Lothor=C3=A9?= X-Patchwork-Id: 13282536 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 2C5B3EB64D7 for ; Fri, 16 Jun 2023 10:06:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=wLbtAZI+SDTW+Sy68+83lY6IuWa3sNaxQeJcshdzgnw=; b=l0cT97mIQgK/hj cAIlz1FJ8yZC+UjPYu1YZBFV3VxLqMO0TfC9/PIBosD186EloyyuuHFkzEPhFywQK0le5fylJVAPK tcgwL19177G+95F+U0GQ7qvaEPA5LnFMNXU+MeLmeBuT24vu+/GSbxrtEad5AbeV7nRYKGhsQvG/G xbSPyUwKhbdUfsK0flAk3CuWcw+RVwnXx61zsPggB6u0uRGMRRK+l9N2kJ1TqKjIGuOV6Sv591gu/ 4QM30RvpNBp27T8dfiTiSMrdU9WaoGYkjTiQM/htJjcfV4vRz+UhgUJPuLx/zyp2S7VWHwM5gXZ95 Jjbh4XxxHP1I5CT0o+hw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qA6L5-00HXzi-1e; Fri, 16 Jun 2023 10:05:55 +0000 Received: from relay7-d.mail.gandi.net ([2001:4b98:dc4:8::227]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qA6Ks-00HXsd-0P for linux-arm-kernel@lists.infradead.org; Fri, 16 Jun 2023 10:05:44 +0000 X-GND-Sasl: alexis.lothore@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1686909940; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t2Z5u2pdOFyGeWrHTpiauz2Y6DQCmtBj67ZZlH6r9Yw=; b=VlB+mmJ2KMVQ8xlzcP3HMRvb5AeWgOC78aVXaAdm09rhishVYbGo+PWKobqI3HDIUmYt2g 9H26shu1MISdr0Dia4H4wI2xmUuJX6x7PfTBr6o7bwSKeqNcq+SjtLTaIuzTSDGJiV2CTc eMZtWGVB03cIOL/+zTHKONDW9IVPnQ2JXqMX7Sh8ngeoZVSBwebjDYE/5hFvPuQ9kypHdO Gr0yiCKawtD8wSSvJjkdLmo0WZc6XL1ODdy2i94C7PBAt9Y19PpLySKigSUxM74dGF6eSn XWBgVNi/8rf6CjbYOie1iT5GEko7xJWXEPVqJQsGNDkOdydVBmyZKLTNTdEXEg== X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com X-GND-Sasl: alexis.lothore@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 70DAC20014; Fri, 16 Jun 2023 10:05:39 +0000 (UTC) From: alexis.lothore@bootlin.com To: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , Richard Cochran Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, Thomas Petazzoni , Nicolas Carrier Subject: [PATCH net-next 8/8] net: stmmac: enable timestamp external trigger for dwmac1000 Date: Fri, 16 Jun 2023 12:04:09 +0200 Message-ID: <20230616100409.164583-9-alexis.lothore@bootlin.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230616100409.164583-1-alexis.lothore@bootlin.com> References: <20230616100409.164583-1-alexis.lothore@bootlin.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230616_030542_473221_AE1AE228 X-CRM114-Status: GOOD ( 21.68 ) 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 From: Alexis Lothoré The code is pretty similar to dwmac4 snapshot external trigger code. The difference is mostly about used registers addresses and/or bits offset in registers Signed-off-by: Alexis Lothoré --- .../ethernet/stmicro/stmmac/dwmac-socfpga.c | 2 + .../net/ethernet/stmicro/stmmac/dwmac1000.h | 12 ++- .../ethernet/stmicro/stmmac/dwmac1000_core.c | 83 +++++++++++++++++++ 3 files changed, 95 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c index 6267bcb60206..98f5413cefee 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-socfpga.c @@ -17,6 +17,7 @@ #include "stmmac.h" #include "stmmac_platform.h" +#include "dwmac1000.h" #define SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_GMII_MII 0x0 #define SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RGMII 0x1 @@ -428,6 +429,7 @@ static int socfpga_dwmac_probe(struct platform_device *pdev) dwmac->ops = ops; plat_dat->bsp_priv = dwmac; plat_dat->fix_mac_speed = socfpga_dwmac_fix_mac_speed; + plat_dat->ext_snapshot_num = GMAC_TC_ATSEN0; ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res); if (ret) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h b/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h index 4296ddda8aaa..d17929ea63e0 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h @@ -41,8 +41,7 @@ #define GMAC_INT_DISABLE_PCS (GMAC_INT_DISABLE_RGMII | \ GMAC_INT_DISABLE_PCSLINK | \ GMAC_INT_DISABLE_PCSAN) -#define GMAC_INT_DEFAULT_MASK (GMAC_INT_DISABLE_TIMESTAMP | \ - GMAC_INT_DISABLE_PCS) +#define GMAC_INT_DEFAULT_MASK GMAC_INT_DISABLE_PCS /* PMT Control and Status */ #define GMAC_PMT 0x0000002c @@ -329,5 +328,14 @@ enum rtc_control { #define GMAC_MMC_RX_CSUM_OFFLOAD 0x208 #define GMAC_EXTHASH_BASE 0x500 +/* Timestamping registers */ +#define GMAC_TIMESTAMP_C0NTROL 0x00000700 +#define GMAC_TC_ATSFC BIT(24) +#define GMAC_TC_ATSEN0 BIT(25) +#define GMAC_TIMESTAMP_STATUS 0x00000728 +#define GMAC_AT_NS 0x00000730 +#define GMAC_AT_NS_MASK 0x7FFFFFFF +#define GMAC_AT_S 0x00000734 + extern const struct stmmac_dma_ops dwmac1000_dma_ops; #endif /* __DWMAC1000_H__ */ diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c index 3927609abc44..97d94b009014 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c @@ -19,6 +19,7 @@ #include "stmmac.h" #include "stmmac_pcs.h" #include "dwmac1000.h" +#include "stmmac_ptp.h" static void dwmac1000_core_init(struct mac_device_info *hw, struct net_device *dev) @@ -294,9 +295,58 @@ static void dwmac1000_rgsmii(void __iomem *ioaddr, struct stmmac_extra_stats *x) } } +static void get_ptptime(void __iomem *ioaddr, u64 *ptp_time) +{ + u64 ns; + + ns = (readl(ioaddr + GMAC_AT_NS) & GMAC_AT_NS_MASK); + *ptp_time = ns; + ns = readl(ioaddr + GMAC_AT_S); + *ptp_time += ns * NSEC_PER_SEC; +} + +static void dwmac1000_ptp_isr(struct stmmac_priv *priv) +{ + struct ptp_clock_event event; + u32 status_reg, num_snapshot; + unsigned long flags; + u64 ptp_time; + int i = 0; + + if (priv->plat->int_snapshot_en) { + wake_up(&priv->tstamp_busy_wait); + return; + } + + /* Read timestamp status to clear interrupt from either external + * timestamp or start/end of PPS. + */ + status_reg = readl(priv->ioaddr + GMAC_TIMESTAMP_STATUS); + + if (!priv->plat->ext_snapshot_en) + return; + + num_snapshot = (status_reg & GMAC_TIMESTAMP_ATSNS_MASK) >> + GMAC_TIMESTAMP_ATSNS_SHIFT; + if (!num_snapshot) + return; + + for (i = 0; i < num_snapshot; i++) { + read_lock_irqsave(&priv->ptp_lock, flags); + get_ptptime(priv->ioaddr, &ptp_time); + read_unlock_irqrestore(&priv->ptp_lock, flags); + event.type = PTP_CLOCK_EXTTS; + event.index = 0; + event.timestamp = ptp_time; + ptp_clock_event(priv->ptp_clock, &event); + } +} + static int dwmac1000_irq_status(struct mac_device_info *hw, struct stmmac_extra_stats *x) { + struct stmmac_priv *priv = + container_of(x, struct stmmac_priv, xstats); void __iomem *ioaddr = hw->pcsr; u32 intr_status = readl(ioaddr + GMAC_INT_STATUS); u32 intr_mask = readl(ioaddr + GMAC_INT_MASK); @@ -318,6 +368,9 @@ static int dwmac1000_irq_status(struct mac_device_info *hw, x->irq_receive_pmt_irq_n++; } + if (intr_status & GMAC_INT_STATUS_TSTAMP) + dwmac1000_ptp_isr(priv); + /* MAC tx/rx EEE LPI entry/exit interrupts */ if (intr_status & GMAC_INT_STATUS_LPIIS) { /* Clean LPI interrupt by reading the Reg 12 */ @@ -502,6 +555,34 @@ static void dwmac1000_set_mac_loopback(void __iomem *ioaddr, bool enable) writel(value, ioaddr + GMAC_CONTROL); } +static void dwmac1000_extts_configure(void __iomem *ioaddr, int ext_snapshot_num, + bool on, struct net_device *dev) +{ + u32 acr_value; + + /* Since DWMAC1000 has only one external trigger input, + * ext_snapshot_num is not used + */ + acr_value = readl(ioaddr + GMAC_TIMESTAMP_C0NTROL); + acr_value &= ~GMAC_TC_ATSEN0; + if (on) { + acr_value |= GMAC_TC_ATSEN0; + acr_value |= GMAC_TC_ATSFC; + netdev_dbg(dev, "Auxiliary Snapshot 0 enabled.\n"); + } else { + netdev_dbg(dev, "Auxiliary Snapshot 0 disabled.\n"); + } + writel(acr_value, ioaddr + GMAC_TIMESTAMP_C0NTROL); +} + +static int dwmac1000_clear_snapshot_fifo(void __iomem *ioaddr) +{ + u32 acr_value; + + return readl_poll_timeout(ioaddr + GMAC_TIMESTAMP_C0NTROL, acr_value, + !(acr_value & GMAC_TC_ATSFC), 10, 10000); +} + const struct stmmac_ops dwmac1000_ops = { .core_init = dwmac1000_core_init, .set_mac = stmmac_set_mac, @@ -522,6 +603,8 @@ const struct stmmac_ops dwmac1000_ops = { .pcs_rane = dwmac1000_rane, .pcs_get_adv_lp = dwmac1000_get_adv_lp, .set_mac_loopback = dwmac1000_set_mac_loopback, + .extts_configure = dwmac1000_extts_configure, + .clear_snapshot_fifo = dwmac1000_clear_snapshot_fifo }; int dwmac1000_setup(struct stmmac_priv *priv)