Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp839590lqb; Wed, 17 Apr 2024 12:13:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUYcn9ERydsvGQQCtdGAmkS1zRMPCqHKv5PD1cDUtKPsXcmEfpEDm3oP3b/rn99aecvYdXLMYg1wmhQT6gkJGEdMoY7jmn4sQGUb6WW4w== X-Google-Smtp-Source: AGHT+IGNSvalsRHAlOWECs7TNva4QEvArv1V0kjYvBedyZ0wUqQabdhqpKydBEEIwILLT85i0s8I X-Received: by 2002:a05:6512:4cb:b0:518:9b42:b846 with SMTP id w11-20020a05651204cb00b005189b42b846mr108880lfq.21.1713381234503; Wed, 17 Apr 2024 12:13:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713381234; cv=pass; d=google.com; s=arc-20160816; b=N5pVA4AVQdClG9SvTi061a5+sJqrQq03dYLcjAVtSNferrBs8/3Ok99ZBcquHOMGVh JI0kyDGGTdqMvGgWc2AivFyCSplFNwOgtWzPB9i7LhFGryrp09Ei6dDuQJEme9T82SFP fe+TwCbtGEw4Fm8B8erqmzFj79gDsv8WEzaeln12GK42cIx0nDvrxEqMz5gX+NfE1LNK LTuInlG5TzhFob1e4FTy154zxRZ+XbLEwgI2PtiOena1B3l+7w2cUbCon++2RbeWb5Gy jj7mfDlHjYIUQoFvx+z/rpjN5l4ykw9d2SwVq99mCJ/T8+cnH62RJVFV/xwykmNiC8un kHZw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=JTcCtqawFKRHlvcDtRKkDTTkbfy/GJAXrQ0aSEOy+RI=; fh=lMme+vRxlfCLmpzY7jHaqjwrGtojJiH+UVKzqDCgZ6I=; b=hw99l3O9WPsCin21iUg0Ohw2zdroxLWWfzI4mLhpUuSZw7xL4yYztroXvGG4otbGP6 v/wiS47q+v6xVl7T8EekNTGID8GGuZVg50ukLwtWdnU20A6SulYX/x5ENGiOVvUgO5+D UA5FjG5oJEQi5iwH7a7riSQf0SSvl8H/56snz7pfDctEtYylRrRJ2xIFVgVZH4tbXzGv MfPE15MtBssR5EsM029v6kQ1ssvP0q+FjejznZ5v26g/5xt1NLD2eWzYBLx9cVR8aI8f X/hM0MdUZawI/URW/NOD/AbixG6JiwzdBYVd4cOMeHIpDmzlgbZAexN/YsGi9xEquIYK B9pA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=EEmc6EZm; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-149106-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149106-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id kq9-20020a170906abc900b00a55552c2161si1052830ejb.167.2024.04.17.12.13.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 12:13:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-149106-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=EEmc6EZm; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-149106-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149106-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 39D2B1F22E46 for ; Wed, 17 Apr 2024 19:13:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 76DB124B34; Wed, 17 Apr 2024 19:13:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EEmc6EZm" Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1FF31DA53; Wed, 17 Apr 2024 19:13:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713381223; cv=none; b=QwlUfQnz84EPHLFAgZB62KlgiC0409TxPI1OYJ+WYjzsLBgrAwsZZjPiezo9KLPYmsEuZYJ6fuWS1qla4ajw/Y5iRtjosBeKAvnICnF8sV6RcdonTOWNdGcBMAxeqE5ctHrvJnBwEyR8BWeupuNQqUWOml6RxG4sR9SidjATZ2k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713381223; c=relaxed/simple; bh=CmzwNIApee8Fwt4pVcYGZwnquvTzM85msk5kFBGJ/X8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ERdj+R365NJmUfz0xJbM4ao0tbKTIv5zEB7lxhiGLVDRXRmfwFq6Mz/blPK+MuNBP5c546C4HDTFo0siU3t3WWtxgi25TeNd7FwoF2RNz1kNvmwfYpzrr+35E+JiJi2Qppwm6mrVlG/6tZ0WYGqoF1T4oIWghIwVnVgMsBDXy3A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=EEmc6EZm; arc=none smtp.client-ip=209.85.167.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-516d1c8dc79so13277e87.1; Wed, 17 Apr 2024 12:13:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713381220; x=1713986020; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=JTcCtqawFKRHlvcDtRKkDTTkbfy/GJAXrQ0aSEOy+RI=; b=EEmc6EZm0q9U8Kzdq5yphngQ5Bae36iIACiTgcJTOuiwgp4hUurKN9sPV6LqRnMTob QXviFalp1x7Ql8xEQ9RW15u/d1JqYqteetvQgN5D0yMD18aeyV6ih16CfNTg+qEgxubH 3D2+DlnAHTkAqfQe8s0mO2aD7f7/ggQ6vhn5h3Ka3AWqTkZBz8un5qrukDkrBybxX7JK PpVY0t2MoFfNRpBVRi+9XaliLhvwAmjG5o4rSKPYwlF8cxC6XAgRNRJ4QJCl+cxo+xLG JSDFJ9/IIB6bgh617NrCozTHXHwnPC0aKWX8raDa+lAcippUIOwbXpnSp+fX4zBggZDc vR9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713381220; x=1713986020; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=JTcCtqawFKRHlvcDtRKkDTTkbfy/GJAXrQ0aSEOy+RI=; b=gyKornl0OnUwYRVhrSfGy+1m6AZUvbBqNQUDXDAJ4zVIHSki/KZrsGzU01PyH1+dyu dhKkqI+aFsa1JITBcCJ5DMG5HUuO1+qh+WrT5ySLSqImZNsLtc0jpV6GJCdxToDIQ/mO Usxw42yuESx+HExq4I1zbCIKhyJ+HRZWeNMy6U3Uz32b+UcDu7ei5lIwjXSydCUkOFOZ oETKXfUS4mDFPbVsjWuKJC817+jPwY27GWeZii0az+iYkr55VDsFmSlW6QyAg/2/Fyj7 EZ4dPA404bDrH2jE8pKkapgzv1plOk9SVzdcn8aIFzqTDr2fbE6YkoaNb3xz4SqpHdkM Q56A== X-Forwarded-Encrypted: i=1; AJvYcCVoSH+YXISuk7zeaEfk5rjav3uUYlGfLfjlX7NZI3wL3oUYVwTYphH/AsOE7CIr0qrfBF4A9y0ww4hGauX9SKXfw1r1xnVD5uaj4Sr8GcjBfwJjjH9YkEMYCwbLMCceyQgLWRFt X-Gm-Message-State: AOJu0Yx0xzIeuUiN3/F7Hu3Y2I/j2xY1lbndKUxugoGc8jYTrlU5MxwF Fs4suGYWp+Yeur4Sy/uG5OIqPOILvYTYgITIVGl+HkSUFT+kEdyC X-Received: by 2002:ac2:5fcf:0:b0:515:99f6:2ca4 with SMTP id q15-20020ac25fcf000000b0051599f62ca4mr104968lfg.36.1713381219670; Wed, 17 Apr 2024 12:13:39 -0700 (PDT) Received: from mobilestation.baikal.int (srv1.baikalchip.ru. [87.245.175.227]) by smtp.gmail.com with ESMTPSA id q3-20020ac25143000000b00518c86b3eb7sm1251742lfd.80.2024.04.17.12.13.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 12:13:39 -0700 (PDT) Date: Wed, 17 Apr 2024 22:13:37 +0300 From: Serge Semin To: Oleksij Rempel Cc: 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 , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, UNGLinuxDriver@microchip.com, linux-stm32@st-md-mailman.stormreply.com Subject: Re: [PATCH net-next v1 4/4] net: stmmac: use delays reported by the PHY driver to correct MAC propagation delay Message-ID: <3ib7rkbwxtdd26waw2dseuwwlijhxxjmjp6jbxe6g6i5hk6ua2@3zt2avhdh2lu> References: <20240417164316.1755299-1-o.rempel@pengutronix.de> <20240417164316.1755299-5-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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240417164316.1755299-5-o.rempel@pengutronix.de> On Wed, Apr 17, 2024 at 06:43:16PM +0200, Oleksij Rempel wrote: > 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; What's the point in adding these fields to the private data if you retrieve the delays and use them in a single place? Just extend the stmmac_hwtstamp_correct_latency() arguments list and pass the delays as the function parameters. -Serge(y) > 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 > >