From nobody Sun Nov 24 17:45:13 2024 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) (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 C9594762EB; Mon, 4 Nov 2024 17:03:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730739783; cv=none; b=Sf1KlgQyzBePXqRIdgLHJSBCbYxCRrW4RofAJffP469u6a1VZhoJqvHtKs/yuA9im6pGzJF0+NQk++cOemKoQo3hU1vU2nAieEtWQFu0rUmszKj+VdZitgBAF1c371B/U7/U9A6l8/wk+97p0PzpcvKqNSwljxMB2dGHClCMiJE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730739783; c=relaxed/simple; bh=SwYPaML/m+2xlE7bFiASP090aemPXqfRl2KtqzUESLA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gR4OtgmcRlVgkuw2R+H65zsoLIWYb5AMjS93GJPTAaEMX3DlKNU9LdNCvpelZevkA4aBJ3exKM1azvB16TeXggPppDqxPQbhFbKc0fw6gz4LiOnKSfRDllJcCtwaT24yI98tTFbKELQiYJ9GjJvWfpQZijpZ62PFmeC9mmHVinQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=FT419QD0; arc=none smtp.client-ip=217.70.183.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="FT419QD0" Received: by mail.gandi.net (Postfix) with ESMTPSA id 5152760008; Mon, 4 Nov 2024 17:02:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1730739779; 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: in-reply-to:in-reply-to:references:references; bh=2MZHYosEgWulG/VziP7VK5RTnwW9NHOqqCP8UOYgP1c=; b=FT419QD0SobyzNsNN/cV8FWOV6qZCeMsqlYhb03hVKDaFN6xsHn38Q+cZvp8suifA/PitF OeJHPUN3r49cdozgz2zyxsvRznrhYFewuLem94x1Fc62/fBsgzq3Q/QL3BhZ+jbamyp0P9 wqDPF7tOodPwktCinQy+pDSzyV0xDHaImtowdT4CksRrIjhjbvLyve/TqFHf/ZjmsedATy 6SIh0abVZPFb3MK2eT3H1+QJIFwk83FoVpPQ9fD4Bu+gF2EHBV2tqCBkVAYKJt5bZe7dtp JcdFy3UYTTBdZvH9u0BPvSTdd2wtgqwPzJpHkP3XIUEK/RUW+vMfiBQEUS8oQQ== From: Maxime Chevallier To: Alexandre Torgue , Jose Abreu , Andrew Lunn , davem@davemloft.net, Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , Richard Cochran Cc: Maxime Chevallier , =?UTF-8?q?Alexis=20Lothor=C3=A9?= , Thomas Petazzoni , netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v2 4/9] net: stmmac: Introduce dwmac1000 ptp_clock_info and operations Date: Mon, 4 Nov 2024 18:02:44 +0100 Message-ID: <20241104170251.2202270-5-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241104170251.2202270-1-maxime.chevallier@bootlin.com> References: <20241104170251.2202270-1-maxime.chevallier@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-GND-Sasl: maxime.chevallier@bootlin.com Content-Type: text/plain; charset="utf-8" The PTP configuration for GMAC3_X differs from the other implementations in several ways : - There's only one external snapshot trigger - The snapshot configuration is done through the PTP_TCR register, whereas the other dwmac variants have a dedicated ACR (auxiliary control reg) for that purpose - The layout for the PTP_TCR register also differs, as bits 24/25 are used for the snapshot configuration. These bits are reserved on other variants. On GMAC3_X, we also can't discover the number of snapshot triggers automatically. The GMAC3_X has one PPS output, however it's configuration isn't supported yet so report 0 n_per_out for now. Introduce a dedicated set of ptp_clock_info ops and configuration parameters to reflect these differences specific to GMAC3_X. This was tested on dwmac_socfpga. Signed-off-by: Maxime Chevallier --- V2: No changes drivers/net/ethernet/stmicro/stmmac/common.h | 1 + .../net/ethernet/stmicro/stmmac/dwmac1000.h | 5 +++ .../ethernet/stmicro/stmmac/dwmac1000_core.c | 45 +++++++++++++++++++ drivers/net/ethernet/stmicro/stmmac/hwif.c | 4 +- .../net/ethernet/stmicro/stmmac/stmmac_ptp.c | 18 ++++++++ .../net/ethernet/stmicro/stmmac/stmmac_ptp.h | 6 +++ 6 files changed, 77 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/eth= ernet/stmicro/stmmac/common.h index 4a0a1708c391..6f68a6b298c9 100644 --- a/drivers/net/ethernet/stmicro/stmmac/common.h +++ b/drivers/net/ethernet/stmicro/stmmac/common.h @@ -552,6 +552,7 @@ extern const struct stmmac_hwtimestamp stmmac_ptp; extern const struct stmmac_mode_ops dwmac4_ring_mode_ops; =20 extern const struct ptp_clock_info stmmac_ptp_clock_ops; +extern const struct ptp_clock_info dwmac1000_ptp_clock_ops; =20 struct mac_link { u32 caps; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h b/drivers/net/= ethernet/stmicro/stmmac/dwmac1000.h index 4296ddda8aaa..01eafeb1272f 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h @@ -329,5 +329,10 @@ enum rtc_control { #define GMAC_MMC_RX_CSUM_OFFLOAD 0x208 #define GMAC_EXTHASH_BASE 0x500 =20 +/* PTP and timestamping registers */ + +#define GMAC_PTP_TCR_ATSFC BIT(24) +#define GMAC_PTP_TCR_ATSEN0 BIT(25) + 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 d413d76a8936..b6930009ea06 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c @@ -18,6 +18,7 @@ #include #include "stmmac.h" #include "stmmac_pcs.h" +#include "stmmac_ptp.h" #include "dwmac1000.h" =20 static void dwmac1000_core_init(struct mac_device_info *hw, @@ -551,3 +552,47 @@ int dwmac1000_setup(struct stmmac_priv *priv) =20 return 0; } + +/* DWMAC 1000 ptp_clock_info ops */ + +int dwmac1000_ptp_enable(struct ptp_clock_info *ptp, + struct ptp_clock_request *rq, int on) +{ + struct stmmac_priv *priv =3D + container_of(ptp, struct stmmac_priv, ptp_clock_ops); + void __iomem *ptpaddr =3D priv->ptpaddr; + int ret =3D -EOPNOTSUPP; + u32 tcr_val; + + switch (rq->type) { + case PTP_CLK_REQ_EXTTS: + mutex_lock(&priv->aux_ts_lock); + tcr_val =3D readl(ptpaddr + PTP_TCR); + + if (on) { + tcr_val |=3D GMAC_PTP_TCR_ATSEN0; + tcr_val |=3D GMAC_PTP_TCR_ATSFC; + priv->plat->flags |=3D STMMAC_FLAG_EXT_SNAPSHOT_EN; + } else { + tcr_val &=3D ~GMAC_PTP_TCR_ATSEN0; + priv->plat->flags &=3D ~STMMAC_FLAG_EXT_SNAPSHOT_EN; + } + + netdev_dbg(priv->dev, "Auxiliary Snapshot %s.\n", + on ? "enabled" : "disabled"); + writel(tcr_val, ptpaddr + PTP_TCR); + + mutex_unlock(&priv->aux_ts_lock); + + /* wait for auxts fifo clear to finish */ + ret =3D readl_poll_timeout(ptpaddr + PTP_TCR, tcr_val, + !(tcr_val & GMAC_PTP_TCR_ATSFC), + 10, 10000); + break; + + default: + break; + } + + return ret; +} diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.c b/drivers/net/ether= net/stmicro/stmmac/hwif.c index 9b6d817e8f1e..f425fe3bc22a 100644 --- a/drivers/net/ethernet/stmicro/stmmac/hwif.c +++ b/drivers/net/ethernet/stmicro/stmmac/hwif.c @@ -134,7 +134,7 @@ static const struct stmmac_hwif_entry { .dma =3D &dwmac100_dma_ops, .mac =3D &dwmac100_ops, .hwtimestamp =3D &stmmac_ptp, - .ptp =3D &stmmac_ptp_clock_ops, + .ptp =3D &dwmac1000_ptp_clock_ops, .mode =3D NULL, .tc =3D NULL, .mmc =3D &dwmac_mmc_ops, @@ -153,7 +153,7 @@ static const struct stmmac_hwif_entry { .dma =3D &dwmac1000_dma_ops, .mac =3D &dwmac1000_ops, .hwtimestamp =3D &stmmac_ptp, - .ptp =3D &stmmac_ptp_clock_ops, + .ptp =3D &dwmac1000_ptp_clock_ops, .mode =3D NULL, .tc =3D NULL, .mmc =3D &dwmac_mmc_ops, diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c b/drivers/net= /ethernet/stmicro/stmmac/stmmac_ptp.c index 8ea2b4226234..430905f591b2 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c @@ -282,6 +282,24 @@ const struct ptp_clock_info stmmac_ptp_clock_ops =3D { .getcrosststamp =3D stmmac_getcrosststamp, }; =20 +/* structure describing a PTP hardware clock */ +const struct ptp_clock_info dwmac1000_ptp_clock_ops =3D { + .owner =3D THIS_MODULE, + .name =3D "stmmac ptp", + .max_adj =3D 62500000, + .n_alarm =3D 0, + .n_ext_ts =3D 1, + .n_per_out =3D 0, + .n_pins =3D 0, + .pps =3D 0, + .adjfine =3D stmmac_adjust_freq, + .adjtime =3D stmmac_adjust_time, + .gettime64 =3D stmmac_get_time, + .settime64 =3D stmmac_set_time, + .enable =3D dwmac1000_ptp_enable, + .getcrosststamp =3D stmmac_getcrosststamp, +}; + /** * stmmac_ptp_register * @priv: driver private structure diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h b/drivers/net= /ethernet/stmicro/stmmac/stmmac_ptp.h index fce3fba2ffd2..fa4611855311 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h @@ -94,4 +94,10 @@ enum aux_snapshot { AUX_SNAPSHOT3 =3D 0x80, }; =20 +struct ptp_clock_info; +struct ptp_clock_request; + +int dwmac1000_ptp_enable(struct ptp_clock_info *ptp, + struct ptp_clock_request *rq, int on); + #endif /* __STMMAC_PTP_H__ */ --=20 2.47.0