Linux Documentation
 help / color / mirror / Atom feed
From: Ivan Vecera <ivecera@redhat.com>
To: netdev@vger.kernel.org
Cc: Vadim Fedorenko <vadim.fedorenko@linux.dev>,
	Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>,
	Jiri Pirko <jiri@resnulli.us>, Jonathan Corbet <corbet@lwn.net>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	Donald Hunter <donald.hunter@gmail.com>,
	Tony Nguyen <anthony.l.nguyen@intel.com>,
	Przemek Kitszel <przemyslaw.kitszel@intel.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	Alexander Lobakin <aleksander.lobakin@intel.com>,
	Richard Cochran <richardcochran@gmail.com>,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	intel-wired-lan@lists.osuosl.org, Min Li <min.li@microchip.com>,
	Grzegorz Nitka <grzegorz.nitka@intel.com>,
	Karol Kolacinski <karol.kolacinski@intel.com>,
	Saeed Mahameed <saeedm@nvidia.com>,
	Tariq Toukan <tariqt@nvidia.com>, Petr Oros <poros@redhat.com>
Subject: [PATCH RFC net-next 12/19] ice: dpll: track the E825 recovered clock routing in the adapter
Date: Thu, 26 Nov 2026 21:32:24 +0100	[thread overview]
Message-ID: <20261126203231.934632-13-ivecera@redhat.com> (raw)
In-Reply-To: <20261126203231.934632-1-ivecera@redhat.com>

On E825 the CGU has two muxes, each routing the recovered clock of one
port of the adapter to a SyncE output. All PFs of the adapter reach the
muxes, but the driver tracks the routing only per PF, as the state of
the recovered clock pin of the PF on each mux.

Record in the adapter which recovered clock pin each mux routes. A PF
records its pin when it creates the pin and the mux routes its port, and
when it routes its port. The record is cleared when a PF disables the
mux and when the routed PF removes its pin. A failed configuration may
leave the mux registers changed, for example the R11 selection of SyncE
output 1 is written before R10, so the record is then read back from
them, or set to no port if that read fails too, as the routing is then
unknown. Writers hold cgu_synce_lock, which already serializes the
writes of the mux registers.

Nothing reads the record yet. Creating the pin adds one read of the mux
registers R10 and R11, the same reads as for getting the pin state, and
a failed configuration adds a read of the register that selects the
port.

Tested on a GNR-D platform with a dual NAC E825 and a ZL80132B DPLL: the
record follows the routing of each of the eight ports, and the mux
registers keep the routing over a PF reset, a CORER and a GLOBR, so the
record stays valid. EMPR was not tested.

Signed-off-by: Ivan Vecera <ivecera@redhat.com>
---
 drivers/net/ethernet/intel/ice/ice_adapter.h |  15 ++
 drivers/net/ethernet/intel/ice/ice_dpll.c    | 154 ++++++++++++++++---
 2 files changed, 150 insertions(+), 19 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/ice_adapter.h b/drivers/net/ethernet/intel/ice/ice_adapter.h
index 698a5b9af82ffd..1e4558f2d8c727 100644
--- a/drivers/net/ethernet/intel/ice/ice_adapter.h
+++ b/drivers/net/ethernet/intel/ice/ice_adapter.h
@@ -13,6 +13,7 @@
 
 #include "ice_type.h"
 
+struct dpll_pin;
 struct pci_dev;
 struct ice_pf;
 
@@ -34,6 +35,18 @@ struct ice_port_list {
 	struct srcu_struct srcu;
 };
 
+/**
+ * struct ice_dpll_rclk_mux - recovered clock mux of the E825C CGU
+ * @src: recovered clock pin of the port that the mux routes to its output,
+ *	 NULL when it routes no port of a bound PF or the routing is unknown
+ *
+ * The CGU routes the recovered clock of one port of the adapter to each of
+ * its two SyncE outputs. Writers of @src hold cgu_synce_lock of the adapter.
+ */
+struct ice_dpll_rclk_mux {
+	struct dpll_pin *src;
+};
+
 /**
  * struct ice_adapter - PCI adapter resources shared across PFs
  * @devlink: ice adapter's devlink (whole dev devlink)
@@ -44,6 +57,7 @@ struct ice_port_list {
  *               Index 0 = PHY0, index 1 = PHY1. Used on E825C devices.
  * @cgu_synce_lock: Mutex serializing changes of the CGU registers R10 and R11,
  *                  which all PFs reach. Used on E825C devices.
+ * @rclk_mux: Recovered clock muxes of the CGU. Used on E825C devices.
  * @ctrl_pf: Control PF of the adapter
  * @ports: Ports list
  */
@@ -58,6 +72,7 @@ struct ice_adapter {
 	struct mutex cpi_phy_lock[ICE_E825_MAX_PHYS];
 	/* Serialize changes of the SyncE CGU registers (E825C only) */
 	struct mutex cgu_synce_lock;
+	struct ice_dpll_rclk_mux rclk_mux[ICE_SYNCE_CLK_NUM];
 
 	struct ice_pf *ctrl_pf;
 	struct ice_port_list ports;
diff --git a/drivers/net/ethernet/intel/ice/ice_dpll.c b/drivers/net/ethernet/intel/ice/ice_dpll.c
index ccbe34abf74661..11c5dc0376bb4c 100644
--- a/drivers/net/ethernet/intel/ice/ice_dpll.c
+++ b/drivers/net/ethernet/intel/ice/ice_dpll.c
@@ -556,6 +556,37 @@ ice_dpll_pin_store_state(struct ice_dpll_pin *pin, int parent, bool state)
 					DPLL_PIN_STATE_DISCONNECTED;
 }
 
+/**
+ * ice_dpll_rclk_mux_sel_get - get the input selected by a recovered clock mux
+ * @hw: pointer to the HW struct
+ * @output: SyncE output of the CGU fed by the mux
+ * @sel: on success holds the selected input
+ *
+ * Return:
+ * * 0 - OK
+ * * negative - error
+ */
+static int ice_dpll_rclk_mux_sel_get(struct ice_hw *hw,
+				     enum ice_synce_clk output, u8 *sel)
+{
+	int err;
+	u32 reg;
+
+	if (output == ICE_SYNCE_CLK0) {
+		err = ice_read_cgu_reg(hw, ICE_CGU_R10, &reg);
+		if (err)
+			return err;
+		*sel = FIELD_GET(ICE_CGU_R10_SYNCE_S_REF_CLK, reg);
+	} else {
+		err = ice_read_cgu_reg(hw, ICE_CGU_R11, &reg);
+		if (err)
+			return err;
+		*sel = FIELD_GET(ICE_CGU_R11_SYNCE_S_BYP_CLK, reg);
+	}
+
+	return 0;
+}
+
 /**
  * ice_dpll_rclk_update_e825c - updates the state of rclk pin on e825c device
  * @pf: private board struct
@@ -571,28 +602,19 @@ ice_dpll_pin_store_state(struct ice_dpll_pin *pin, int parent, bool state)
 static int ice_dpll_rclk_update_e825c(struct ice_pf *pf,
 				      struct ice_dpll_pin *pin)
 {
-	u8 rclk_bits;
-	int err;
-	u32 reg;
+	u8 port = pf->ptp.port.port_num + ICE_CGU_BYPASS_MUX_OFFSET_E825C;
+	int err, i;
+	u8 sel;
 
 	if (pf->dplls.rclk.num_parents > ICE_SYNCE_CLK_NUM)
 		return -EINVAL;
 
-	err = ice_read_cgu_reg(&pf->hw, ICE_CGU_R10, &reg);
-	if (err)
-		return err;
-
-	rclk_bits = FIELD_GET(ICE_CGU_R10_SYNCE_S_REF_CLK, reg);
-	ice_dpll_pin_store_state(pin, ICE_SYNCE_CLK0, rclk_bits ==
-		(pf->ptp.port.port_num + ICE_CGU_BYPASS_MUX_OFFSET_E825C));
-
-	err = ice_read_cgu_reg(&pf->hw, ICE_CGU_R11, &reg);
-	if (err)
-		return err;
-
-	rclk_bits = FIELD_GET(ICE_CGU_R11_SYNCE_S_BYP_CLK, reg);
-	ice_dpll_pin_store_state(pin, ICE_SYNCE_CLK1, rclk_bits ==
-		(pf->ptp.port.port_num + ICE_CGU_BYPASS_MUX_OFFSET_E825C));
+	for (i = 0; i < ICE_SYNCE_CLK_NUM; i++) {
+		err = ice_dpll_rclk_mux_sel_get(&pf->hw, i, &sel);
+		if (err)
+			return err;
+		ice_dpll_pin_store_state(pin, i, sel == port);
+	}
 
 	return 0;
 }
@@ -2020,6 +2042,40 @@ ice_dpll_phase_offset_get(const struct dpll_pin *pin, void *pin_priv,
 	return 0;
 }
 
+/**
+ * ice_dpll_rclk_src_sync - record the port a recovered clock mux routes
+ * @pf: board private structure
+ * @output: SyncE output of the CGU fed by the mux
+ *
+ * Read the input selected by the mux. Record the recovered clock pin of the
+ * PF as the source of the mux when the mux routes the port of the PF, and no
+ * pin when it routes no port. When it routes another port, keep the record
+ * unless it names the PF.
+ *
+ * Context: Called under adapter->cgu_synce_lock
+ * Return:
+ * * 0 - OK
+ * * negative - error
+ */
+static int ice_dpll_rclk_src_sync(struct ice_pf *pf, enum ice_synce_clk output)
+{
+	u8 port = pf->ptp.port.port_num + ICE_CGU_BYPASS_MUX_OFFSET_E825C;
+	struct ice_dpll_rclk_mux *mux = &pf->adapter->rclk_mux[output];
+	struct dpll_pin *pin = pf->dplls.rclk.pin;
+	int err;
+	u8 sel;
+
+	err = ice_dpll_rclk_mux_sel_get(&pf->hw, output, &sel);
+	if (err)
+		return err;
+	if (sel == port)
+		WRITE_ONCE(mux->src, pin);
+	else if (sel < ICE_CGU_BYPASS_MUX_OFFSET_E825C || mux->src == pin)
+		WRITE_ONCE(mux->src, NULL);
+
+	return 0;
+}
+
 /**
  * ice_dpll_synce_update_e825c - setting PHY recovered clock pins on e825c
  * @hw: Pointer to the HW struct
@@ -2028,6 +2084,7 @@ ice_dpll_phase_offset_get(const struct dpll_pin *pin, void *pin_priv,
  * @output: output pin, we have two in E825C
  *
  * DPLL subsystem callback. Set proper signals to recover clock from port.
+ * Record in the adapter which port the mux routes.
  *
  * Context: Called under pf->dplls.lock, acquires adapter->cgu_synce_lock
  * Return:
@@ -2043,8 +2100,17 @@ static int ice_dpll_synce_update_e825c(struct ice_hw *hw, bool ena,
 	mutex_lock(&pf->adapter->cgu_synce_lock);
 	/* configure the mux to deliver proper signal to DPLL from the MUX */
 	err = ice_tspll_cfg_bypass_mux_e825c(hw, ena, port_num, output);
-	if (!err)
+	if (!err) {
+		/* A disabled mux routes no port, whichever it routed before */
+		WRITE_ONCE(pf->adapter->rclk_mux[output].src,
+			   ena ? pf->dplls.rclk.pin : NULL);
 		err = ice_tspll_cfg_synce_ethdiv_e825c(hw, output);
+	} else if (ice_dpll_rclk_src_sync(pf, output)) {
+		/* The routing is unknown after a partial write that cannot
+		 * be read back, record no port.
+		 */
+		WRITE_ONCE(pf->adapter->rclk_mux[output].src, NULL);
+	}
 	mutex_unlock(&pf->adapter->cgu_synce_lock);
 	if (err)
 		return err;
@@ -2055,6 +2121,48 @@ static int ice_dpll_synce_update_e825c(struct ice_hw *hw, bool ena,
 	return 0;
 }
 
+/**
+ * ice_dpll_rclk_src_init - record the muxes that route the port of the PF
+ * @pf: board private structure
+ *
+ * Record the recovered clock pin of the PF as the source of the recovered
+ * clock muxes that route the port of the PF, see ice_dpll_rclk_src_sync().
+ *
+ * Context: Acquires adapter->cgu_synce_lock
+ * Return:
+ * * 0 - success
+ * * negative - error
+ */
+static int ice_dpll_rclk_src_init(struct ice_pf *pf)
+{
+	int err = 0, i;
+
+	mutex_lock(&pf->adapter->cgu_synce_lock);
+	for (i = 0; !err && i < ICE_SYNCE_CLK_NUM; i++)
+		err = ice_dpll_rclk_src_sync(pf, i);
+	mutex_unlock(&pf->adapter->cgu_synce_lock);
+
+	return err;
+}
+
+/**
+ * ice_dpll_rclk_src_fini - drop the PF as the source of recovered clock muxes
+ * @pf: board private structure
+ *
+ * Context: Acquires adapter->cgu_synce_lock
+ */
+static void ice_dpll_rclk_src_fini(struct ice_pf *pf)
+{
+	struct ice_adapter *adapter = pf->adapter;
+	int i;
+
+	mutex_lock(&adapter->cgu_synce_lock);
+	for (i = 0; i < ICE_SYNCE_CLK_NUM; i++)
+		if (adapter->rclk_mux[i].src == pf->dplls.rclk.pin)
+			WRITE_ONCE(adapter->rclk_mux[i].src, NULL);
+	mutex_unlock(&adapter->cgu_synce_lock);
+}
+
 /**
  * ice_dpll_output_esync_set - callback for setting embedded sync
  * @pin: pointer to a pin
@@ -3745,6 +3853,8 @@ static void ice_dpll_deinit_rclk_pin(struct ice_pf *pf)
 		dpll_pin_on_pin_unregister(parent->pin, rclk->pin,
 					   &ice_dpll_rclk_ops, rclk);
 	}
+	if (pf->hw.mac_type == ICE_MAC_GENERIC_3K_E825)
+		ice_dpll_rclk_src_fini(pf);
 	if (WARN_ON_ONCE(!vsi || !vsi->netdev))
 		return;
 	dpll_netdev_pin_clear(vsi->netdev);
@@ -4328,6 +4438,12 @@ static int ice_dpll_init_pins_e825(struct ice_pf *pf)
 	if (ret)
 		goto unregister_pins;
 
+	ret = ice_dpll_rclk_src_init(pf);
+	if (ret) {
+		ice_dpll_deinit_rclk_pin(pf);
+		goto unregister_pins;
+	}
+
 	ret = ice_dpll_init_txclk_pins(pf);
 	if (ret) {
 		ice_dpll_deinit_rclk_pin(pf);
-- 
2.56.1


  parent reply	other threads:[~2026-11-26 20:34 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 20:32 [PATCH RFC net-next 00/19] dpll: single-owner pins, board wiring as pin links Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 01/19] dpll: add " Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 02/19] dpll: report " Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 03/19] dpll: notify linked pins when a pin is registered or unregistered Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 04/19] dpll: add KUnit tests for pin links Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 05/19] ice: dpll: use own pins for the TX and time references Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 06/19] ice: dpll: drop the filter of notifications from own registrations Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 07/19] dpll: register pins only with a DPLL of their owner Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 08/19] dpll: drop the state change exception for pins with a firmware node Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 09/19] dpll: drop the source clock id from pin notifications Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 10/19] dpll: drop device events from the in-kernel notifier Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 11/19] dpll: drop the cached module name of a pin Ivan Vecera
2026-11-26 20:32 ` Ivan Vecera [this message]
2026-11-26 20:32 ` [PATCH RFC net-next 13/19] ice: dpll: register the E825 recovered clock muxes as DPLL devices Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 14/19] ice: dpll: route the E825 recovered clock through the mux devices Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 15/19] dpll: register pins only with a parent pin of their owner Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 16/19] dpll: drop the in-kernel notifier chain Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 17/19] dpll: require a registered DPLL for pin registration Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 18/19] dpll: drop the owner reference selection of pins Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 19/19] dpll: add KUnit tests for the pin owner checks Ivan Vecera

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261126203231.934632-13-ivecera@redhat.com \
    --to=ivecera@redhat.com \
    --cc=aleksander.lobakin@intel.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=anthony.l.nguyen@intel.com \
    --cc=arkadiusz.kubalewski@intel.com \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=donald.hunter@gmail.com \
    --cc=edumazet@kernel.org \
    --cc=grzegorz.nitka@intel.com \
    --cc=horms@kernel.org \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=jiri@resnulli.us \
    --cc=karol.kolacinski@intel.com \
    --cc=kuba@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=min.li@microchip.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=poros@redhat.com \
    --cc=przemyslaw.kitszel@intel.com \
    --cc=rdunlap@infradead.org \
    --cc=richardcochran@gmail.com \
    --cc=saeedm@nvidia.com \
    --cc=skhan@linuxfoundation.org \
    --cc=tariqt@nvidia.com \
    --cc=vadim.fedorenko@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox