Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp761867lqb; Wed, 17 Apr 2024 09:55:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVyq6D0wXjl8tdyYRpkciUnXHuW95PLFP+qfnSI3X+dK/6+fjTbd7MaQ4tMzRKMNlnBuKU21YJdnrqk5dxafU59qavQOAnzSKvDBZgm+w== X-Google-Smtp-Source: AGHT+IEAKHw8upPqfeA5w8mvyC16mpur1qcy7z23SN3vPFu9EcLgtApX7zy5Lr8X/tJSyo0XvSni X-Received: by 2002:a05:6a20:728d:b0:1a7:63ac:a3aa with SMTP id o13-20020a056a20728d00b001a763aca3aamr281825pzk.30.1713372914964; Wed, 17 Apr 2024 09:55:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713372914; cv=pass; d=google.com; s=arc-20160816; b=AGsvScXesPcbTiyMuOrSjfU0L3hNG64DBfKFSJsCC630s4x2ey+Sw6+Sg2BEVP7PpP oWYWEa+olvjACdJvXrwXqUfrDF7jfOXf72hm/TH+vQr8AA7O73hpyI7QEy49Mw5OyOUV S9uLK+Ju4T7DnepBILrdbs8UMsrkXWQBg0BzGGiGdGifEhrFuUfpO8JlqytQbT/0hdy/ TNvNANoeiESil/Qs4F/MbcFDQO17yyGQ+BXz/8LZaxOofe84nQZdF8nkNDVkSsQ9Uzsb Mr0oyHtyhcbJQOLQWush5NA0sz+9tqNwNhdTPlcf9h/wAZZ2tVcIykd73uEp4AAHxr4G cl6w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=jgLnkzhg7cXcESp7dtulSlVKe6M27/L8o5oIrtBCnf4=; fh=kiRqwkKfO33GRi1br385Tyec0zPEcuOtjrEB95bIg+4=; b=bAMBxcnC6mopfQdMtspMDj2tWTMQbT54mcopjxn9CT55ogibSnQ+uU7mRGOyXzSJ6j rdvHrvsXLc31r+wrjm2yBK7ZX/POPb3c8kKQ4jQL0ySicHvQ17Hb2jeb3c0gQk3bNn3A AYQYlA6Q1ofAcwXtZmiMLG2YMh5wRel1OzTAya+BEXohLk0WtlGNJqyAmIA+ZC8M+LXb zneSWJ/k1CPkgRTOO7MfVLJI0f7+4qCd936DkTUGrZG0D5FszkW0LP5dMy1Bn/TUJrZA NWl4qYS7N4tnPQy73XlxGklfHfHOgKGlCWMqDEHkOrGOTq2l/NWxwEltBGwiahpi5zrx xpjQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-148928-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-148928-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id m6-20020a170902768600b001e5b6a45cb6si9029694pll.263.2024.04.17.09.55.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 09:55:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-148928-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-148928-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-148928-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 46255B21953 for ; Wed, 17 Apr 2024 16:43:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 93EF316FF53; Wed, 17 Apr 2024 16:43:33 +0000 (UTC) Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC17A16FF5E for ; Wed, 17 Apr 2024 16:43:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713372213; cv=none; b=gOYVv2dxpeWkT1n/ihQjdASkCkmlmhL8nEaP9CxQY1VTxbm6po/G0Ig4VDA1AAeDm0LjKzzpqgvEChLvo/ikyNstHpm9FaS2TB7kZr25jsMygx6knSUnNXqqordDr+3WFJy859m4B0vPwgUWKKOHE/feD2YGoV8U/8U0bbv9uFY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713372213; c=relaxed/simple; bh=Z9l2/soyE5tzoITheZvO69xxT5aKufMAHBzJHx8l/e0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=q0c6x0GIvExs0SM6gKH7+qUi0KeGdBIGILftj0sU2PqiN666kigOzN0vDtFYx0sxMRkF01EIG2JOF7+sMbBAUCx9JYM510gyr9nA7NZJckyByWFvc+z0Ha0TWm9YSR+2vxHh/8ggOPSVgGNtVwh2seQ1+93ZxbqesfLG20QABFU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rx8NT-0007N3-VQ; Wed, 17 Apr 2024 18:43:19 +0200 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rx8NR-00CpCe-S0; Wed, 17 Apr 2024 18:43:17 +0200 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1rx8NR-007MeM-2W; Wed, 17 Apr 2024 18:43:17 +0200 From: Oleksij Rempel To: Alexandre Torgue , Jose Abreu , "David S. Miller" , Andrew Lunn , Heiner Kallweit , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , Woojung Huh , Arun Ramadoss , Richard Cochran , Russell King Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, UNGLinuxDriver@microchip.com, linux-stm32@st-md-mailman.stormreply.com Subject: [PATCH net-next v1 4/4] net: stmmac: use delays reported by the PHY driver to correct MAC propagation delay Date: Wed, 17 Apr 2024 18:43:16 +0200 Message-Id: <20240417164316.1755299-5-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240417164316.1755299-1-o.rempel@pengutronix.de> References: <20240417164316.1755299-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Now after PHY drivers are able to report data path delays, we can use them in the MAC drivers for the delay correction. Signed-off-by: Oleksij Rempel --- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 2 ++ .../ethernet/stmicro/stmmac/stmmac_hwtstamp.c | 4 ++++ .../net/ethernet/stmicro/stmmac/stmmac_main.c | 17 ++++++++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h index dddcaa9220cc3..6db54ce33ea72 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h @@ -288,6 +288,8 @@ struct stmmac_priv { u32 sub_second_inc; u32 systime_flags; u32 adv_ts; + u64 phy_tx_delay_ns; + u64 phy_rx_delay_ns; int use_riwt; int irq_wake; rwlock_t ptp_lock; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c index f05bd757dfe52..bbf284cb7cc2a 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c @@ -71,6 +71,8 @@ static void hwtstamp_correct_latency(struct stmmac_priv *priv) /* MAC-internal ingress latency */ scaled_ns = readl(ioaddr + PTP_TS_INGR_LAT); + scaled_ns += priv->phy_rx_delay_ns << 16; + /* See section 11.7.2.5.3.1 "Ingress Correction" on page 4001 of * i.MX8MP Applications Processor Reference Manual Rev. 1, 06/2021 */ @@ -95,6 +97,8 @@ static void hwtstamp_correct_latency(struct stmmac_priv *priv) /* MAC-internal egress latency */ scaled_ns = readl(ioaddr + PTP_TS_EGR_LAT); + scaled_ns += priv->phy_tx_delay_ns << 16; + reg_tsec = scaled_ns >> 16; reg_tsecsns = scaled_ns & 0xff00; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index fe3498e86de9d..30c7c278b7062 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -1097,8 +1097,23 @@ static void stmmac_mac_link_up(struct phylink_config *config, if (priv->dma_cap.fpesel) stmmac_fpe_link_state_handle(priv, true); - if (priv->plat->flags & STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY) + if (priv->plat->flags & STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY) { + int ret = 0; + + if (phy) + ret = phy_get_timesync_data_path_delays(phy, + &priv->phy_tx_delay_ns, + &priv->phy_rx_delay_ns); + if (!phy || ret) { + if (ret != -EOPNOTSUPP) + netdev_err(priv->dev, "Failed to get PHY delay: %pe\n", + ERR_PTR(ret)); + priv->phy_tx_delay_ns = 0; + priv->phy_rx_delay_ns = 0; + } + stmmac_hwtstamp_correct_latency(priv, priv); + } } static const struct phylink_mac_ops stmmac_phylink_mac_ops = { -- 2.39.2