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, ®);
+ 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, ®);
+ 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, ®);
- 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, ®);
- 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