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: 109008 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1222360vqr; Fri, 16 Jun 2023 03:13:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5SMmw+oOjuciT5HdezHerp3C+ALhuQ6osRr99fJKo1iWzmrxlm7uosvRcBqLEmYFNVFuox X-Received: by 2002:a05:6358:9f9f:b0:129:b8e9:b740 with SMTP id fy31-20020a0563589f9f00b00129b8e9b740mr285991rwb.27.1686910427251; Fri, 16 Jun 2023 03:13:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686910427; cv=none; d=google.com; s=arc-20160816; b=SDIK5zAUTrSLDptvDQ0X3lDTENMTXaYw/nacwOYaltNN94Hau+LLIfyBqEcy7j+5qe ml+t3c6pDveN+lqqIV3imSkiVPqjqG3ah+DcbwjF2gfxphHfBhy3kVAHo96YLQecKLG5 JvuHdmaTNrlI8GZQVD6TW+YnTGiAg2tapy8iM9na6dYC1yxSttaYw4hr6IPWsPfCMj7f POnfaDjynrudgYQik9NxdM1jO9HedT62t0j5NW3w3BucHhlWPQ61EGFwkewqaBhVbdRF sfvGxMGFQPp4XsCh1ha8fBwacQ0QS3gegQdqPR+g96pfnQVQpwA3XlOFblDFKuwCZmGC 0i3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bu3ZgXdHuaAGXwkANc4+sjRTQos43KxjZuFR24WnayE=; b=Nxs4EAyVC1DCyPu6bwj0Tud4ZcHWf1SyGURmBUL3Y/Zh7af0Ti+QfK5vRSG7jv+XOD zVsT4YCgBaGRoOqP8M6aIcuB9aRxV2u1xLEXh/p0zTpgZQqoDwsNLikdZ72QEYJd0B1Y l0q6jgvrZAi6JmEbPlGkQAEgeYLXvbjvoOpoSkJgrtzFpHI5a94B9ze3U1gOto+quFkp emzbrMwV8lBTkZlT3CQXC8nCCR+iB1s6CJfdRCz+cRGrxPG1d0Kh2Ba6vTcSAyt+MhgB FLz5JrpoTxlV/vimcjKhfmIx8MDa+UIkhcx66T60GAqZIB6xx8wcbH9KEJ1LjB4sP5Ez KQ6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=MB6d8Q+e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b73-20020a63344c000000b0053f955eda7csi14906843pga.559.2023.06.16.03.13.32; Fri, 16 Jun 2023 03:13:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=MB6d8Q+e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243849AbjFPKFt (ORCPT + 99 others); Fri, 16 Jun 2023 06:05:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230108AbjFPKFh (ORCPT ); Fri, 16 Jun 2023 06:05:37 -0400 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9779F2137; Fri, 16 Jun 2023 03:05:35 -0700 (PDT) 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-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768853788528373877?= X-GMAIL-MSGID: =?utf-8?q?1768853788528373877?= 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 */