From patchwork Fri Nov 19 08:10:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kurt Kanzenbach X-Patchwork-Id: 12693111 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 793D2C433F5 for ; Fri, 19 Nov 2021 08:11:49 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 43A0961A55 for ; Fri, 19 Nov 2021 08:11:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 43A0961A55 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linutronix.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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: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:In-Reply-To:References: List-Owner; bh=9y3ySlmgZ4cDA+h42evmKncIK3jp54RWZ0POFGHh2iI=; b=5D0SsfDcWuLB7n MLzLOWbEDMef39+xtih0AoMX7J/47qMbDKqbRj65lApT6wLMsFoxRSyoXBAXzOIYXPvChcDTZJLn5 j+5fF9E8LjGz0bq2q25fd9DM4OFf0oo6oNorgabWtDNcbCNQx34+GQl6wlFOxXAH+26Dc0xvjhb/4 NVb/dO9CDkewSs/0J0hvfWbblo8+lq3kspDJapbP26bfREdQOsrAtkX+2WQ4phgY0RaPvQ9lKz/JH R/noNUohI7Dleky0YZ7J+vbFJdKtrmumRfbxM4TTZbpcs2BjzVaFMfEkIe5zCxrcM7o71HGAidhEB JQCI4+Oj5BeKMLJB3v5w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnyyc-009htb-Gl; Fri, 19 Nov 2021 08:10:30 +0000 Received: from galois.linutronix.de ([2a0a:51c0:0:12e:550::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mnyyY-009hrs-C7 for linux-arm-kernel@lists.infradead.org; Fri, 19 Nov 2021 08:10:27 +0000 From: Kurt Kanzenbach DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1637309422; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=u4z4KZzApJAKUjf78C7LiERGFGnsrWpuLIEte2H/AUo=; b=xnbMUUndcOMXIhXIk2x14+VSqwdAjEm+AjJBfOwa86kZsGK4MYb0clCJUQuuF31QtAu8iQ s4eIvHz8FrNbSte7WY8aR28Q2NON6q02eB+iwMozBNgBR4bh0IXh8JLqS8GSOcFGD8x8BP v8QGJ1bkMRblgSf8+VR0UMVwRZ/kOVlcSeJp+6Slf5pY/mkq0fEPJyODvej1sdUOHbIMDi tI6jfyM3qP1Sjbvb7U80Oxcp+UZHT/I4bSPWugrmKfjHOa0PV0HPabxGC13mSxW1o/zSZy RHVoqNTXySouerzAKVLlbODLThtj6LX0Ynwdukjio4pGjbIWFa5aCMRI7BwSKg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1637309422; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=u4z4KZzApJAKUjf78C7LiERGFGnsrWpuLIEte2H/AUo=; b=LQwiCwTf6e7wOVJ9L1LKhW+5InOuprsPGxeXBVonOg6KcuSlMbR1nBol8o94g2/oiopLS3 0FQLjdYLmd/Yb2AQ== To: "David S. Miller" , Jakub Kicinski Cc: Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , Maxime Coquelin , Voon Weifeng , Ong Boon Leong , Wong Vee Khee , Tan Tee Min , "Wong, Vee Khee" , Xiaoliang Yang , netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, Benedikt Spranger , Kurt Kanzenbach , Thomas Gleixner Subject: [PATCH net-next v1] net: stmmac: Caclucate clock domain crossing error only once Date: Fri, 19 Nov 2021 09:10:10 +0100 Message-Id: <20211119081010.27084-1-kurt@linutronix.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211119_001026_605615_7C4DBD9B X-CRM114-Status: GOOD ( 13.09 ) 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 The clock domain crossing error (CDC) is calculated at every fetch of Tx or Rx timestamps. It includes a division. Especially on arm32 based systems it is expensive. It also saves the two conditionals. Therefore, move the calculation to the PTP initialization code and just use the cached value in the timestamp retrieval functions. Suggested-by: Thomas Gleixner Signed-off-by: Kurt Kanzenbach --- Bene, would you mind to test this patch on stm32mp1 too? drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 12 ++---------- drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c | 6 ++++++ include/linux/stmmac.h | 1 + 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 21111df73719..340076b5bb38 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -511,14 +511,6 @@ bool stmmac_eee_init(struct stmmac_priv *priv) return true; } -static inline u32 stmmac_cdc_adjust(struct stmmac_priv *priv) -{ - /* Correct the clk domain crossing(CDC) error */ - if (priv->plat->has_gmac4 && priv->plat->clk_ptp_rate) - return (2 * NSEC_PER_SEC) / priv->plat->clk_ptp_rate; - return 0; -} - /* stmmac_get_tx_hwtstamp - get HW TX timestamps * @priv: driver private structure * @p : descriptor pointer @@ -550,7 +542,7 @@ static void stmmac_get_tx_hwtstamp(struct stmmac_priv *priv, } if (found) { - ns -= stmmac_cdc_adjust(priv); + ns -= priv->plat->cdc_error_adj; memset(&shhwtstamp, 0, sizeof(struct skb_shared_hwtstamps)); shhwtstamp.hwtstamp = ns_to_ktime(ns); @@ -587,7 +579,7 @@ static void stmmac_get_rx_hwtstamp(struct stmmac_priv *priv, struct dma_desc *p, if (stmmac_get_rx_timestamp_status(priv, p, np, priv->adv_ts)) { stmmac_get_timestamp(priv, desc, priv->adv_ts, &ns); - ns -= stmmac_cdc_adjust(priv); + ns -= priv->plat->cdc_error_adj; netdev_dbg(priv->dev, "get valid RX hw timestamp %llu\n", ns); shhwtstamp = skb_hwtstamps(skb); diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c index 580cc035536b..96b9e4175f08 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c @@ -309,6 +309,12 @@ void stmmac_ptp_register(struct stmmac_priv *priv) if (priv->plat->ptp_max_adj) stmmac_ptp_clock_ops.max_adj = priv->plat->ptp_max_adj; + /* Calculate the clock domain crossing (CDC) error if necessary */ + priv->plat->cdc_error_adj = 0; + if (priv->plat->has_gmac4 && priv->plat->clk_ptp_rate) + 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; diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h index a6f03b36fc4f..89b8e208cd7b 100644 --- a/include/linux/stmmac.h +++ b/include/linux/stmmac.h @@ -241,6 +241,7 @@ struct plat_stmmacenet_data { unsigned int clk_ref_rate; unsigned int mult_fact_100ns; s32 ptp_max_adj; + u32 cdc_error_adj; struct reset_control *stmmac_rst; struct reset_control *stmmac_ahb_rst; struct stmmac_axi *axi;