Skip to contentSkip to conversation

Create common DPLL configuration API

RFC PATCH In review Vadim Fedorenko 8 participants 87 messages Apr 28, 2023 – Jun 13, 2023 Page 2 of 2

Subsystems (11)
lore
Share & tools
lore
maintainer
#52 lore raw

Re: [RFC PATCH v7 5/8] ice: implement dpll interface to control cgu

In reply to Vadim Fedorenko
Quoted 93 lines · Fri, Apr 28, 2023 at 02:20:06AM CEST, [email protected] wrote:

From: Arkadiusz Kubalewski <[email protected]>

Control over clock generation unit is required for further development of Synchronous Ethernet feature. Interface provides ability to obtain current state of a dpll, its sources and outputs which are pins, and allows their configuration.

---

drivers/net/ethernet/intel/Kconfig          |    1 +
drivers/net/ethernet/intel/ice/Makefile     |    3 +-
drivers/net/ethernet/intel/ice/ice.h        |    4 +
drivers/net/ethernet/intel/ice/ice_dpll.c   | 1929 +++++++++++++++++++
drivers/net/ethernet/intel/ice/ice_dpll.h   |  101 +
drivers/net/ethernet/intel/ice/ice_main.c   |    7 +
drivers/net/ethernet/intel/ice/ice_ptp_hw.c |   21 +-
drivers/net/ethernet/intel/ice/ice_ptp_hw.h |  148 +-
8 files changed, 2125 insertions(+), 89 deletions(-)

create mode 100644 drivers/net/ethernet/intel/ice/ice_dpll.c create mode 100644 drivers/net/ethernet/intel/ice/ice_dpll.h

drivers/net/ethernet/intel/Kconfig +1 -0
index 9bc0a9519899..913dcf928d15 100644
@@ -284,6 +284,7 @@ config ICE
 	select DIMLIB
 	select NET_DEVLINK
 	select PLDMFW
+	select DPLL
 	help
 	  This driver supports Intel(R) Ethernet Connection E800 Series of
 	  devices.  For more information on how to identify your adapter, go
drivers/net/ethernet/intel/ice/Makefile +2 -1
index 5d89392f969b..6c198cd92d49 100644
@@ -33,7 +33,8 @@ ice-y := ice_main.o	\
 	 ice_lag.o	\
 	 ice_ethtool.o  \
 	 ice_repr.o	\
-	 ice_tc_lib.o
+	 ice_tc_lib.o	\
+	 ice_dpll.o
 ice-$(CONFIG_PCI_IOV) +=	\
 	ice_sriov.o		\
 	ice_virtchnl.o		\
drivers/net/ethernet/intel/ice/ice.h +4 -0
index 5736757039db..a71d46e41c01 100644
@@ -74,6 +74,7 @@
 #include "ice_lag.h"
 #include "ice_vsi_vlan_ops.h"
 #include "ice_gnss.h"
+#include "ice_dpll.h"
 
 #define ICE_BAR0		0
 #define ICE_REQ_DESC_MULTIPLE	32
@@ -201,6 +202,7 @@
 enum ice_feature {
 	ICE_F_DSCP,
 	ICE_F_PTP_EXTTS,
+	ICE_F_PHY_RCLK,
 	ICE_F_SMA_CTRL,
 	ICE_F_CGU,
 	ICE_F_GNSS,
@@ -512,6 +514,7 @@ enum ice_pf_flags {
 	ICE_FLAG_UNPLUG_AUX_DEV,
 	ICE_FLAG_MTU_CHANGED,
 	ICE_FLAG_GNSS,			/* GNSS successfully initialized */
+	ICE_FLAG_DPLL,			/* SyncE/PTP dplls initialized */
 	ICE_PF_FLAGS_NBITS		/* must be last */
 };
 
@@ -635,6 +638,7 @@ struct ice_pf {
 #define ICE_VF_AGG_NODE_ID_START	65
 #define ICE_MAX_VF_AGG_NODES		32
 	struct ice_agg_node vf_agg_node[ICE_MAX_VF_AGG_NODES];
+	struct ice_dplls dplls;
 };
 
 struct ice_netdev_priv {
drivers/net/ethernet/intel/ice/ice_dpll.c new file +0 -0
new file mode 100644
index 000000000000..3217fb36dd12

drivers/net/ethernet/intel/ice/ice_dpll.c line 8

Quoted 8 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +8 -0
@@ -0,0 +1,1929 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2022, Intel Corporation. */
+
+#include "ice.h"
+#include "ice_lib.h"
+#include "ice_trace.h"
+#include <linux/dpll.h>
+#include <uapi/linux/dpll.h>

Don't include uapi directly. I'm pretty sure I had the same comment the last time as well.

Quoted 48 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +48 -0
+
+#define ICE_CGU_STATE_ACQ_ERR_THRESHOLD	50
+#define ICE_DPLL_LOCK_TRIES		1000
+#define ICE_DPLL_PIN_IDX_INVALID	0xff
+
+/**
+ * dpll_lock_status - map ice cgu states into dpll's subsystem lock status
+ */
+static const enum dpll_lock_status
+ice_dpll_status[__DPLL_LOCK_STATUS_MAX] = {
+	[ICE_CGU_STATE_INVALID] = DPLL_LOCK_STATUS_UNSPEC,
+	[ICE_CGU_STATE_FREERUN] = DPLL_LOCK_STATUS_UNLOCKED,
+	[ICE_CGU_STATE_LOCKED] = DPLL_LOCK_STATUS_CALIBRATING,
+	[ICE_CGU_STATE_LOCKED_HO_ACQ] = DPLL_LOCK_STATUS_LOCKED,
+	[ICE_CGU_STATE_HOLDOVER] = DPLL_LOCK_STATUS_HOLDOVER,
+};
+
+/**
+ * ice_dpll_pin_type - enumerate ice pin types
+ */
+enum ice_dpll_pin_type {
+	ICE_DPLL_PIN_INVALID = 0,
+	ICE_DPLL_PIN_TYPE_SOURCE,
+	ICE_DPLL_PIN_TYPE_OUTPUT,
+	ICE_DPLL_PIN_TYPE_RCLK_SOURCE,
+};
+
+/**
+ * pin_type_name - string names of ice pin types
+ */
+static const char * const pin_type_name[] = {
+	[ICE_DPLL_PIN_TYPE_SOURCE] = "source",
+	[ICE_DPLL_PIN_TYPE_OUTPUT] = "output",
+	[ICE_DPLL_PIN_TYPE_RCLK_SOURCE] = "rclk-source",
+};
+
+/**
+ * ice_find_pin_idx - find ice_dpll_pin index on a pf
+ * @pf: private board structure
+ * @pin: kernel's dpll_pin pointer to be searched for
+ * @pin_type: type of pins to be searched for
+ *
+ * Find and return internal ice pin index of a searched dpll subsystem
+ * pin pointer.
+ *
+ * Return:
+ * * valid index for a given pin & pin type found on pf internal dpll struct
+ * * ICE_DPLL_PIN_IDX_INVALID - if pin was not found.

drivers/net/ethernet/intel/ice/ice_dpll.c line 66

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+ */
+static u32
+ice_find_pin_idx(struct ice_pf *pf, const struct dpll_pin *pin,
+		 enum ice_dpll_pin_type pin_type)
+
+{
+	struct ice_dpll_pin *pins;
+	int pin_num, i;
+
+	if (!pin || !pf)

How this can happen? If not, remove.

Quoted 22 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +22 -0
+		return ICE_DPLL_PIN_IDX_INVALID;
+
+	if (pin_type == ICE_DPLL_PIN_TYPE_SOURCE) {
+		pins = pf->dplls.inputs;
+		pin_num = pf->dplls.num_inputs;
+	} else if (pin_type == ICE_DPLL_PIN_TYPE_OUTPUT) {
+		pins = pf->dplls.outputs;
+		pin_num = pf->dplls.num_outputs;
+	} else {
+		return ICE_DPLL_PIN_IDX_INVALID;
+	}
+
+	for (i = 0; i < pin_num; i++)
+		if (pin == pins[i].pin)
+			return i;
+
+	return ICE_DPLL_PIN_IDX_INVALID;
+}
+
+/**
+ * ice_dpll_cb_lock - lock dplls mutex in callback context
+ * @pf: private board structure

drivers/net/ethernet/intel/ice/ice_dpll.c line 98

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+ *
+ * Lock the mutex from the callback operations invoked by dpll subsystem.
+ * Prevent dead lock caused by `rmmod ice` when dpll callbacks are under stress
+ * tests.
+ *
+ * Return:
+ * 0 - if lock acquired
+ * negative - lock not acquired or dpll was deinitialized
+ */
+static int ice_dpll_cb_lock(struct ice_pf *pf)

On many places you call this without saving the return value to int variable. You should do that and propagate the error value.

Quoted 89 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +89 -0
+{
+	int i;
+
+	for (i = 0; i < ICE_DPLL_LOCK_TRIES; i++) {
+		if (mutex_trylock(&pf->dplls.lock))
+			return 0;
+		usleep_range(100, 150);
+		if (!test_bit(ICE_FLAG_DPLL, pf->flags))
+			return -EFAULT;
+	}
+
+	return -EBUSY;
+}
+
+/**
+ * ice_dpll_cb_unlock - unlock dplls mutex in callback context
+ * @pf: private board structure
+ *
+ * Unlock the mutex from the callback operations invoked by dpll subsystem.
+ */
+static void ice_dpll_cb_unlock(struct ice_pf *pf)
+{
+	mutex_unlock(&pf->dplls.lock);
+}
+
+/**
+ * ice_find_pin - find ice_dpll_pin on a pf
+ * @pf: private board structure
+ * @pin: kernel's dpll_pin pointer to be searched for
+ * @pin_type: type of pins to be searched for
+ *
+ * Find and return internal ice pin info pointer holding data of given dpll
+ * subsystem pin pointer.
+ *
+ * Return:
+ * * valid 'struct ice_dpll_pin'-type pointer - if given 'pin' pointer was
+ * found in pf internal pin data.
+ * * NULL - if pin was not found.
+ */
+static struct ice_dpll_pin
+*ice_find_pin(struct ice_pf *pf, const struct dpll_pin *pin,
+	      enum ice_dpll_pin_type pin_type)
+
+{
+	struct ice_dpll_pin *pins;
+	int pin_num, i;
+
+	if (!pin || !pf)
+		return NULL;
+
+	if (pin_type == ICE_DPLL_PIN_TYPE_SOURCE) {
+		pins = pf->dplls.inputs;
+		pin_num = pf->dplls.num_inputs;
+	} else if (pin_type == ICE_DPLL_PIN_TYPE_OUTPUT) {
+		pins = pf->dplls.outputs;
+		pin_num = pf->dplls.num_outputs;
+	} else if (pin_type == ICE_DPLL_PIN_TYPE_RCLK_SOURCE) {
+		if (pin == pf->dplls.rclk.pin)
+			return &pf->dplls.rclk;
+	} else {
+		return NULL;
+	}
+
+	for (i = 0; i < pin_num; i++)
+		if (pin == pins[i].pin)
+			return &pins[i];
+
+	return NULL;
+}
+
+/**
+ * ice_dpll_pin_freq_set - set pin's frequency
+ * @pf: private board structure
+ * @pin: pointer to a pin
+ * @pin_type: type of pin being configured
+ * @freq: frequency to be set
+ *
+ * Set requested frequency on a pin.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - error on AQ or wrong pin type given
+ */
+static int
+ice_dpll_pin_freq_set(struct ice_pf *pf, struct ice_dpll_pin *pin,
+		      const enum ice_dpll_pin_type pin_type, const u32 freq)
+{
+	u8 flags;
+	int ret;

drivers/net/ethernet/intel/ice/ice_dpll.c line 197

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+
+	if (pin_type == ICE_DPLL_PIN_TYPE_SOURCE) {
+		flags = ICE_AQC_SET_CGU_IN_CFG_FLG1_UPDATE_FREQ;
+		ret = ice_aq_set_input_pin_cfg(&pf->hw, pin->idx, flags,
+					       pin->flags[0], freq, 0);
+	} else if (pin_type == ICE_DPLL_PIN_TYPE_OUTPUT) {
+		flags = pin->flags[0] | ICE_AQC_SET_CGU_OUT_CFG_UPDATE_FREQ;
+		ret = ice_aq_set_output_pin_cfg(&pf->hw, pin->idx, flags,
+						0, freq, 0);
+	} else {

How exactly this can happen? If not, avoid it.
And use switch-case for enum values

drivers/net/ethernet/intel/ice/ice_dpll.c line 202

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +5 -0
+		ret = -EINVAL;
+	}
+
+	if (ret) {
+		dev_dbg(ice_pf_to_dev(pf),

dev_err

drivers/net/ethernet/intel/ice/ice_dpll.c line 210

Quoted 8 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +8 -0
+			"err:%d %s failed to set pin freq:%u on pin:%u\n",
+			ret, ice_aq_str(pf->hw.adminq.sq_last_status),
+			freq, pin->idx);
+	} else {
+		pin->freq = freq;
+	}
+
+	return ret;

Usual pattern is:

	ret = something() //switch-case in this case
	if (ret)
		return ret;
	return 0;

Easier to follow.

Quoted 23 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +23 -0
+}
+
+/**
+ * ice_dpll_frequency_set - wrapper for pin callback for set frequency
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: pointer to dpll
+ * @frequency: frequency to be set
+ * @extack: error reporting
+ * @pin_type: type of pin being configured
+ *
+ * Wraps internal set frequency command on a pin.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - error pin not found or couldn't set in hw
+ */
+static int
+ice_dpll_frequency_set(const struct dpll_pin *pin, void *pin_priv,
+		       const struct dpll_device *dpll,
+		       const u32 frequency,
+		       struct netlink_ext_ack *extack,
+		       const enum ice_dpll_pin_type pin_type)

drivers/net/ethernet/intel/ice/ice_dpll.c line 243

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+{
+	struct ice_pf *pf = pin_priv;
+	struct ice_dpll_pin *p;
+	int ret = -EINVAL;
+
+	if (!pf)
+		return ret;
+	if (ice_dpll_cb_lock(pf))
+		return -EBUSY;
+	p = ice_find_pin(pf, pin, pin_type);

This does not make any sense to me. You should avoid the lookups and remove ice_find_pin() function entirely. The purpose of having pin_priv is to carry the struct ice_dpll_pin * directly. You should pass it down during pin register.

pf pointer is stored in dpll_priv.

drivers/net/ethernet/intel/ice/ice_dpll.c line 245

Quoted 2 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +2 -0
+	if (!p) {
+		NL_SET_ERR_MSG(extack, "pin not found");

That would be very odd message the user would see :)

drivers/net/ethernet/intel/ice/ice_dpll.c line 251

Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +6 -0
+		goto unlock;
+	}
+
+	ret = ice_dpll_pin_freq_set(pf, p, pin_type, frequency);
+	if (ret)
+		NL_SET_ERR_MSG_FMT(extack, "freq not set, err:%d", ret);

Why you need to print "ret"? It is propagated to the caller as a return value.

Quoted 17 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +17 -0
+unlock:
+	ice_dpll_cb_unlock(pf);
+
+	return ret;
+}
+
+/**
+ * ice_dpll_source_frequency_set - source pin callback for set frequency
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: pointer to dpll
+ * @dpll_priv: private data pointer passed on dpll registration
+ * @frequency: frequency to be set
+ * @extack: error reporting
+ *
+ * Wraps internal set frequency command on a pin.
+ *

drivers/net/ethernet/intel/ice/ice_dpll.c line 278

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+ * Return:
+ * * 0 - success
+ * * negative - error pin not found or couldn't set in hw
+ */
+static int
+ice_dpll_source_frequency_set(const struct dpll_pin *pin, void *pin_priv,
+			      const struct dpll_device *dpll, void *dpll_priv,
+			      u64 frequency, struct netlink_ext_ack *extack)
+{
+	return ice_dpll_frequency_set(pin, pin_priv, dpll, (u32)frequency, extack,

Avoid the cast here, not needed.

The dpll core should do check if user passes frequency which is supported, so you don't care about the overflow either.

Quoted 53 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +53 -0
+				      ICE_DPLL_PIN_TYPE_SOURCE);
+}
+
+/**
+ * ice_dpll_output_frequency_set - output pin callback for set frequency
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: pointer to dpll
+ * @dpll_priv: private data pointer passed on dpll registration
+ * @frequency: frequency to be set
+ * @extack: error reporting
+ *
+ * Wraps internal set frequency command on a pin.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - error pin not found or couldn't set in hw
+ */
+static int
+ice_dpll_output_frequency_set(const struct dpll_pin *pin, void *pin_priv,
+			      const struct dpll_device *dpll, void *dpll_priv,
+			      u64 frequency, struct netlink_ext_ack *extack)
+{
+	return ice_dpll_frequency_set(pin, pin_priv, dpll, frequency, extack,
+				      ICE_DPLL_PIN_TYPE_OUTPUT);
+}
+
+/**
+ * ice_dpll_frequency_get - wrapper for pin callback for get frequency
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: pointer to dpll
+ * @dpll_priv: private data pointer passed on dpll registration
+ * @frequency: on success holds pin's frequency
+ * @extack: error reporting
+ * @pin_type: type of pin being configured
+ *
+ * Wraps internal get frequency command of a pin.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - error pin not found or couldn't get from hw
+ */
+static int
+ice_dpll_frequency_get(const struct dpll_pin *pin, void *pin_priv,
+		       const struct dpll_device *dpll, u64 *frequency,
+		       struct netlink_ext_ack *extack,
+		       const enum ice_dpll_pin_type pin_type)
+{
+	struct ice_pf *pf = pin_priv;
+	struct ice_dpll_pin *p;
+	int ret = -EINVAL;
+

drivers/net/ethernet/intel/ice/ice_dpll.c line 341

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+	if (!pf)
+		return ret;
+	if (ice_dpll_cb_lock(pf))
+		return -EBUSY;
+	p = ice_find_pin(pf, pin, pin_type);
+	if (!p) {
+		NL_SET_ERR_MSG(extack, "pin not found");
+		goto unlock;
+	}
+	*frequency = (u64)(p->freq);

Drop the pointless cast.

Quoted 71 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +71 -0
+	ret = 0;
+unlock:
+	ice_dpll_cb_unlock(pf);
+
+	return ret;
+}
+
+/**
+ * ice_dpll_source_frequency_get - source pin callback for get frequency
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: pointer to dpll
+ * @dpll_priv: private data pointer passed on dpll registration
+ * @frequency: on success holds pin's frequency
+ * @extack: error reporting
+ *
+ * Wraps internal get frequency command of a source pin.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - error pin not found or couldn't get from hw
+ */
+static int
+ice_dpll_source_frequency_get(const struct dpll_pin *pin, void *pin_priv,
+			      const struct dpll_device *dpll, void *dpll_priv,
+			      u64 *frequency, struct netlink_ext_ack *extack)
+{
+	return ice_dpll_frequency_get(pin, pin_priv, dpll, frequency, extack,
+				      ICE_DPLL_PIN_TYPE_SOURCE);
+}
+
+/**
+ * ice_dpll_output_frequency_get - output pin callback for get frequency
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: pointer to dpll
+ * @dpll_priv: private data pointer passed on dpll registration
+ * @frequency: on success holds pin's frequency
+ * @extack: error reporting
+ *
+ * Wraps internal get frequency command of a pin.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - error pin not found or couldn't get from hw
+ */
+static int
+ice_dpll_output_frequency_get(const struct dpll_pin *pin, void *pin_priv,
+			      const struct dpll_device *dpll, void *dpll_priv,
+			      u64 *frequency, struct netlink_ext_ack *extack)
+{
+	return ice_dpll_frequency_get(pin, pin_priv, dpll, frequency, extack,
+				      ICE_DPLL_PIN_TYPE_OUTPUT);
+}
+
+/**
+ * ice_dpll_pin_enable - enable a pin on dplls
+ * @hw: board private hw structure
+ * @pin: pointer to a pin
+ * @pin_type: type of pin being enabled
+ *
+ * Enable a pin on both dplls. Store current state in pin->flags.
+ *
+ * Return:
+ * * 0 - OK
+ * * negative - error
+ */
+static int
+ice_dpll_pin_enable(struct ice_hw *hw, struct ice_dpll_pin *pin,
+		    const enum ice_dpll_pin_type pin_type)
+{

drivers/net/ethernet/intel/ice/ice_dpll.c line 422

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+	u8 flags = pin->flags[0];
+	int ret;
+
+	if (pin_type == ICE_DPLL_PIN_TYPE_SOURCE) {
+		flags |= ICE_AQC_GET_CGU_IN_CFG_FLG2_INPUT_EN;
+		ret = ice_aq_set_input_pin_cfg(hw, pin->idx, 0, flags, 0, 0);
+	} else if (pin_type == ICE_DPLL_PIN_TYPE_OUTPUT) {
+		flags |= ICE_AQC_SET_CGU_OUT_CFG_OUT_EN;
+		ret = ice_aq_set_output_pin_cfg(hw, pin->idx, flags, 0, 0, 0);
+	}

switch-case

drivers/net/ethernet/intel/ice/ice_dpll.c line 424

Quoted 2 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +2 -0
+	if (ret)
+		dev_dbg(ice_pf_to_dev((struct ice_pf *)(hw->back)),

dev_err?

Quoted 25 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +25 -0
+			"err:%d %s failed to enable %s pin:%u\n",
+			ret, ice_aq_str(hw->adminq.sq_last_status),
+			pin_type_name[pin_type], pin->idx);
+	else
+		pin->flags[0] = flags;
+
+	return ret;
+}
+
+/**
+ * ice_dpll_pin_disable - disable a pin on dplls
+ * @hw: board private hw structure
+ * @pin: pointer to a pin
+ * @pin_type: type of pin being disabled
+ *
+ * Disable a pin on both dplls. Store current state in pin->flags.
+ *
+ * Return:
+ * * 0 - OK
+ * * negative - error
+ */
+static int
+ice_dpll_pin_disable(struct ice_hw *hw, struct ice_dpll_pin *pin,
+		     enum ice_dpll_pin_type pin_type)
+{

drivers/net/ethernet/intel/ice/ice_dpll.c line 459

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+	u8 flags = pin->flags[0];
+	int ret;
+
+	if (pin_type == ICE_DPLL_PIN_TYPE_SOURCE) {
+		flags &= ~(ICE_AQC_GET_CGU_IN_CFG_FLG2_INPUT_EN);
+		ret = ice_aq_set_input_pin_cfg(hw, pin->idx, 0, flags, 0, 0);
+	} else if (pin_type == ICE_DPLL_PIN_TYPE_OUTPUT) {
+		flags &= ~(ICE_AQC_SET_CGU_OUT_CFG_OUT_EN);
+		ret = ice_aq_set_output_pin_cfg(hw, pin->idx, flags, 0, 0, 0);
+	}

switch-case?

drivers/net/ethernet/intel/ice/ice_dpll.c line 461

Quoted 2 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +2 -0
+	if (ret)
+		dev_dbg(ice_pf_to_dev((struct ice_pf *)(hw->back)),

dev_err?

Quoted 24 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +24 -0
+			"err:%d %s failed to disable %s pin:%u\n",
+			ret, ice_aq_str(hw->adminq.sq_last_status),
+			pin_type_name[pin_type], pin->idx);
+	else
+		pin->flags[0] = flags;
+
+	return ret;
+}
+
+/**
+ * ice_dpll_pin_state_update - update pin's state
+ * @hw: private board struct
+ * @pin: structure with pin attributes to be updated
+ * @pin_type: type of pin being updated
+ *
+ * Determine pin current state and frequency, then update struct
+ * holding the pin info. For source pin states are separated for each
+ * dpll, for rclk pins states are separated for each parent.
+ *
+ * Return:
+ * * 0 - OK
+ * * negative - error
+ */
+int

drivers/net/ethernet/intel/ice/ice_dpll.c line 495

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+ice_dpll_pin_state_update(struct ice_pf *pf, struct ice_dpll_pin *pin,
+			  const enum ice_dpll_pin_type pin_type)
+{
+	int ret;
+
+	if (pin_type == ICE_DPLL_PIN_TYPE_SOURCE) {
+		ret = ice_aq_get_input_pin_cfg(&pf->hw, pin->idx, NULL, NULL,
+					       NULL, &pin->flags[0],
+					       &pin->freq, NULL);
+		if (!!(ICE_AQC_GET_CGU_IN_CFG_FLG2_INPUT_EN & pin->flags[0])) {

Don't do "!!", it's not needed. You have this on multiple places. Please reduce.

Quoted 38 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +38 -0
+			if (pin->pin) {
+				pin->state[pf->dplls.eec.dpll_idx] =
+					pin->pin == pf->dplls.eec.active_source ?
+					DPLL_PIN_STATE_CONNECTED :
+					DPLL_PIN_STATE_SELECTABLE;
+				pin->state[pf->dplls.pps.dpll_idx] =
+					pin->pin == pf->dplls.pps.active_source ?
+					DPLL_PIN_STATE_CONNECTED :
+					DPLL_PIN_STATE_SELECTABLE;
+			} else {
+				pin->state[pf->dplls.eec.dpll_idx] =
+					DPLL_PIN_STATE_SELECTABLE;
+				pin->state[pf->dplls.pps.dpll_idx] =
+					DPLL_PIN_STATE_SELECTABLE;
+			}
+		} else {
+			pin->state[pf->dplls.eec.dpll_idx] =
+				DPLL_PIN_STATE_DISCONNECTED;
+			pin->state[pf->dplls.pps.dpll_idx] =
+				DPLL_PIN_STATE_DISCONNECTED;
+		}
+	} else if (pin_type == ICE_DPLL_PIN_TYPE_OUTPUT) {
+		ret = ice_aq_get_output_pin_cfg(&pf->hw, pin->idx,
+						&pin->flags[0], NULL,
+						&pin->freq, NULL);
+		if (!!(ICE_AQC_SET_CGU_OUT_CFG_OUT_EN & pin->flags[0]))
+			pin->state[0] = DPLL_PIN_STATE_CONNECTED;
+		else
+			pin->state[0] = DPLL_PIN_STATE_DISCONNECTED;
+	} else if (pin_type == ICE_DPLL_PIN_TYPE_RCLK_SOURCE) {
+		u8 parent, port_num = ICE_AQC_SET_PHY_REC_CLK_OUT_CURR_PORT;
+
+		for (parent = 0; parent < pf->dplls.rclk.num_parents;
+		     parent++) {
+			ret = ice_aq_get_phy_rec_clk_out(&pf->hw, parent,
+							 &port_num,
+							 &pin->flags[parent],
+							 &pin->freq);

drivers/net/ethernet/intel/ice/ice_dpll.c line 543

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+			if (ret)
+				return ret;
+			if (!!(ICE_AQC_GET_PHY_REC_CLK_OUT_OUT_EN &
+			       pin->flags[parent]))
+				pin->state[parent] = DPLL_PIN_STATE_CONNECTED;
+			else
+				pin->state[parent] =
+					DPLL_PIN_STATE_DISCONNECTED;
+		}
+	}

Perhaps:

	switch (pin_type) {
	case ICE_DPLL_PIN_TYPE_SOURCE:
		..
	case ICE_DPLL_PIN_TYPE_OUTPUT:
		..

?

Quoted 36 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +36 -0
+
+	return ret;
+}
+
+/**
+ * ice_find_dpll - find ice_dpll on a pf
+ * @pf: private board structure
+ * @dpll: kernel's dpll_device pointer to be searched
+ *
+ * Return:
+ * * pointer if ice_dpll with given device dpll pointer is found
+ * * NULL if not found
+ */
+static struct ice_dpll
+*ice_find_dpll(struct ice_pf *pf, const struct dpll_device *dpll)
+{
+	if (!pf || !dpll)
+		return NULL;
+
+	return dpll == pf->dplls.eec.dpll ? &pf->dplls.eec :
+	       dpll == pf->dplls.pps.dpll ? &pf->dplls.pps : NULL;
+}
+
+/**
+ * ice_dpll_hw_source_prio_set - set source priority value in hardware
+ * @pf: board private structure
+ * @dpll: ice dpll pointer
+ * @pin: ice pin pointer
+ * @prio: priority value being set on a dpll
+ *
+ * Internal wrapper for setting the priority in the hardware.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - failure
+ */

drivers/net/ethernet/intel/ice/ice_dpll.c line 589

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+static int
+ice_dpll_hw_source_prio_set(struct ice_pf *pf, struct ice_dpll *dpll,
+			    struct ice_dpll_pin *pin, const u32 prio)
+{
+	int ret;
+
+	ret = ice_aq_set_cgu_ref_prio(&pf->hw, dpll->dpll_idx, pin->idx,
+				      (u8)prio);
+	if (ret)
+		dev_dbg(ice_pf_to_dev(pf),

dev_err

Quoted 22 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +22 -0
+			"err:%d %s failed to set pin prio:%u on pin:%u\n",
+			ret, ice_aq_str(pf->hw.adminq.sq_last_status),
+			prio, pin->idx);
+	else
+		dpll->input_prio[pin->idx] = prio;
+
+	return ret;
+}
+
+/**
+ * ice_dpll_lock_status_get - get dpll lock status callback
+ * @dpll: registered dpll pointer
+ * @status: on success holds dpll's lock status
+ *
+ * Dpll subsystem callback, provides dpll's lock status.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - failure
+ */
+static int ice_dpll_lock_status_get(const struct dpll_device *dpll, void *priv,
+				    enum dpll_lock_status *status,

drivers/net/ethernet/intel/ice/ice_dpll.c line 621

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+				    struct netlink_ext_ack *extack)
+{
+	struct ice_pf *pf = priv;
+	struct ice_dpll *d;
+
+	if (!pf)
+		return -EINVAL;
+	if (ice_dpll_cb_lock(pf))
+		return -EBUSY;
+	d = ice_find_dpll(pf, dpll);

Another example of odd and unneeded lookup. Register dpll device with struct ice_dpll *d as a priv. Store pf pointer there in struct ice_dpll. And remove ice_find_dpll() entirely.

Quoted 87 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +87 -0
+	if (!d)
+		return -EFAULT;
+	dev_dbg(ice_pf_to_dev(pf), "%s: dpll:%p, pf:%p\n", __func__, dpll, pf);
+	*status = ice_dpll_status[d->dpll_state];
+	ice_dpll_cb_unlock(pf);
+
+	return 0;
+}
+
+/**
+ * ice_dpll_mode_get - get dpll's working mode
+ * @dpll: registered dpll pointer
+ * @priv: private data pointer passed on dpll registration
+ * @mode: on success holds current working mode of dpll
+ * @extack: error reporting
+ *
+ * Dpll subsystem callback. Provides working mode of dpll.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - failure
+ */
+static int ice_dpll_mode_get(const struct dpll_device *dpll, void *priv,
+			     enum dpll_mode *mode,
+			     struct netlink_ext_ack *extack)
+{
+	struct ice_pf *pf = priv;
+	struct ice_dpll *d;
+
+	if (!pf)
+		return -EINVAL;
+	if (ice_dpll_cb_lock(pf))
+		return -EBUSY;
+	d = ice_find_dpll(pf, dpll);
+	ice_dpll_cb_unlock(pf);
+	if (!d)
+		return -EFAULT;
+	*mode = DPLL_MODE_AUTOMATIC;
+
+	return 0;
+}
+
+/**
+ * ice_dpll_mode_get - check if dpll's working mode is supported
+ * @dpll: registered dpll pointer
+ * @priv: private data pointer passed on dpll registration
+ * @mode: mode to be checked for support
+ * @extack: error reporting
+ *
+ * Dpll subsystem callback. Provides information if working mode is supported
+ * by dpll.
+ *
+ * Return:
+ * * true - mode is supported
+ * * false - mode is not supported
+ */
+static bool ice_dpll_mode_supported(const struct dpll_device *dpll, void *priv,
+				    const enum dpll_mode mode,
+				    struct netlink_ext_ack *extack)
+{
+	struct ice_pf *pf = priv;
+	struct ice_dpll *d;
+
+	if (!pf)
+		return false;
+
+	if (ice_dpll_cb_lock(pf))
+		return false;
+	d = ice_find_dpll(pf, dpll);
+	ice_dpll_cb_unlock(pf);
+	if (!d)
+		return false;
+	if (mode == DPLL_MODE_AUTOMATIC)
+		return true;
+
+	return false;
+}
+
+/**
+ * ice_dpll_pin_state_set - set pin's state on dpll
+ * @dpll: dpll being configured
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @state: state of pin to be set
+ * @extack: error reporting
+ * @pin_type: type of a pin
+ *

drivers/net/ethernet/intel/ice/ice_dpll.c line 718

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+ * Set pin state on a pin.
+ *
+ * Return:
+ * * 0 - OK or no change required
+ * * negative - error
+ */
+static int
+ice_dpll_pin_state_set(const struct dpll_device *dpll,
+		       const struct dpll_pin *pin, void *pin_priv,
+		       const enum dpll_pin_state state,

Why you use const with enums?

Quoted 14 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +14 -0
+		       struct netlink_ext_ack *extack,
+		       const enum ice_dpll_pin_type pin_type)
+{
+	struct ice_pf *pf = pin_priv;
+	struct ice_dpll_pin *p;
+	int ret = -EINVAL;
+
+	if (!pf)
+		return ret;
+	if (ice_dpll_cb_lock(pf))
+		return -EBUSY;
+	p = ice_find_pin(pf, pin, pin_type);
+	if (!p)
+		goto unlock;

drivers/net/ethernet/intel/ice/ice_dpll.c line 742

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+	if (pin_type == ICE_DPLL_PIN_TYPE_SOURCE) {
+		if (state == DPLL_PIN_STATE_SELECTABLE)
+			ret = ice_dpll_pin_enable(&pf->hw, p, pin_type);
+		else if (state == DPLL_PIN_STATE_DISCONNECTED)
+			ret = ice_dpll_pin_disable(&pf->hw, p, pin_type);
+	} else if (pin_type == ICE_DPLL_PIN_TYPE_OUTPUT) {
+		if (state == DPLL_PIN_STATE_CONNECTED)
+			ret = ice_dpll_pin_enable(&pf->hw, p, pin_type);
+		else if (state == DPLL_PIN_STATE_DISCONNECTED)
+			ret = ice_dpll_pin_disable(&pf->hw, p, pin_type);

switch-case?

Perhaps it would be nicer to do this in ice_dpll_output_state_set() and ice_dpll_source_state_set() directly?

drivers/net/ethernet/intel/ice/ice_dpll.c line 748

Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +6 -0
+	}
+	if (!ret)
+		ret = ice_dpll_pin_state_update(pf, p, pin_type);
+unlock:
+	ice_dpll_cb_unlock(pf);
+	dev_dbg(ice_pf_to_dev(pf),

dev_err in case ret != 0 ?

Quoted 255 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +255 -0
+		"%s: dpll:%p, pin:%p, p:%p pf:%p state: %d ret:%d\n",
+		__func__, dpll, pin, p, pf, state, ret);
+
+	return ret;
+}
+
+/**
+ * ice_dpll_output_state_set - enable/disable output pin on dpll device
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: dpll being configured
+ * @dpll_priv: private data pointer passed on dpll registration
+ * @state: state of pin to be set
+ * @extack: error reporting
+ *
+ * Dpll subsystem callback. Set given state on output type pin.
+ *
+ * Return:
+ * * 0 - successfully enabled mode
+ * * negative - failed to enable mode
+ */
+static int ice_dpll_output_state_set(const struct dpll_pin *pin,
+				     void *pin_priv,
+				     const struct dpll_device *dpll,
+				     void *dpll_priv,
+				     const enum dpll_pin_state state,
+				     struct netlink_ext_ack *extack)
+{
+	return ice_dpll_pin_state_set(dpll, pin, pin_priv, state, extack,
+				      ICE_DPLL_PIN_TYPE_OUTPUT);
+}
+
+/**
+ * ice_dpll_source_state_set - enable/disable source pin on dpll levice
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: dpll being configured
+ * @dpll_priv: private data pointer passed on dpll registration
+ * @state: state of pin to be set
+ * @extack: error reporting
+ *
+ * Dpll subsystem callback. Enables given mode on source type pin.
+ *
+ * Return:
+ * * 0 - successfully enabled mode
+ * * negative - failed to enable mode
+ */
+static int ice_dpll_source_state_set(const struct dpll_pin *pin,
+				     void *pin_priv,
+				     const struct dpll_device *dpll,
+				     void *dpll_priv,
+				     const enum dpll_pin_state state,
+				     struct netlink_ext_ack *extack)
+{
+	return ice_dpll_pin_state_set(dpll, pin, pin_priv, state, extack,
+				      ICE_DPLL_PIN_TYPE_SOURCE);
+}
+
+/**
+ * ice_dpll_pin_state_get - set pin's state on dpll
+ * @dpll: registered dpll pointer
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @state: on success holds state of the pin
+ * @extack: error reporting
+ * @pin_type: type of questioned pin
+ *
+ * Determine pin state set it on a pin.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - failed to get state
+ */
+static int
+ice_dpll_pin_state_get(const struct dpll_device *dpll,
+		       const struct dpll_pin *pin, void *pin_priv,
+		       enum dpll_pin_state *state,
+		       struct netlink_ext_ack *extack,
+		       const enum ice_dpll_pin_type pin_type)
+{
+	struct ice_pf *pf = pin_priv;
+	struct ice_dpll_pin *p;
+	struct ice_dpll *d;
+	int ret = -EINVAL;
+
+	if (!pf)
+		return ret;
+
+	if (ice_dpll_cb_lock(pf))
+		return -EBUSY;
+	p = ice_find_pin(pf, pin, pin_type);
+	if (!p) {
+		NL_SET_ERR_MSG(extack, "pin not found");
+		goto unlock;
+	}
+	d = ice_find_dpll(pf, dpll);
+	if (!d)
+		goto unlock;
+	ret = ice_dpll_pin_state_update(pf, p, pin_type);
+	if (ret)
+		goto unlock;
+	if (pin_type == ICE_DPLL_PIN_TYPE_SOURCE)
+		*state = p->state[d->dpll_idx];
+	else if (pin_type == ICE_DPLL_PIN_TYPE_OUTPUT)
+		*state = p->state[0];
+	ret = 0;
+unlock:
+	ice_dpll_cb_unlock(pf);
+	dev_dbg(ice_pf_to_dev(pf),
+		"%s: dpll:%p, pin:%p, pf:%p state: %d ret:%d\n",
+		__func__, dpll, pin, pf, *state, ret);
+
+	return ret;
+}
+
+/**
+ * ice_dpll_output_state_get - get output pin state on dpll device
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: registered dpll pointer
+ * @dpll_priv: private data pointer passed on dpll registration
+ * @state: on success holds state of the pin
+ * @extack: error reporting
+ *
+ * Dpll subsystem callback. Check state of a pin.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - failed to get state
+ */
+static int ice_dpll_output_state_get(const struct dpll_pin *pin,
+				     void *pin_priv,
+				     const struct dpll_device *dpll,
+				     void *dpll_priv,
+				     enum dpll_pin_state *state,
+				     struct netlink_ext_ack *extack)
+{
+	return ice_dpll_pin_state_get(dpll, pin, pin_priv, state, extack,
+				      ICE_DPLL_PIN_TYPE_OUTPUT);
+}
+
+/**
+ * ice_dpll_source_state_get - get source pin state on dpll device
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: registered dpll pointer
+ * @dpll_priv: private data pointer passed on dpll registration
+ * @state: on success holds state of the pin
+ * @extack: error reporting
+ *
+ * Dpll subsystem callback. Check state of a source pin.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - failed to get state
+ */
+static int ice_dpll_source_state_get(const struct dpll_pin *pin,
+				     void *pin_priv,
+				     const struct dpll_device *dpll,
+				     void *dpll_priv,
+				     enum dpll_pin_state *state,
+				     struct netlink_ext_ack *extack)
+{
+	return ice_dpll_pin_state_get(dpll, pin, pin_priv, state, extack,
+				      ICE_DPLL_PIN_TYPE_SOURCE);
+}
+
+/**
+ * ice_dpll_source_prio_get - get dpll's source prio
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: registered dpll pointer
+ * @dpll_priv: private data pointer passed on dpll registration
+ * @prio: on success - returns source priority on dpll
+ * @extack: error reporting
+ *
+ * Dpll subsystem callback. Handler for getting priority of a source pin.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - failure
+ */
+static int ice_dpll_source_prio_get(const struct dpll_pin *pin, void *pin_priv,
+				    const struct dpll_device *dpll,
+				    void *dpll_priv, u32 *prio,
+				    struct netlink_ext_ack *extack)
+{
+	struct ice_pf *pf = pin_priv;
+	struct ice_dpll *d = NULL;
+	struct ice_dpll_pin *p;
+	int ret = -EINVAL;
+
+	if (!pf)
+		return ret;
+
+	if (ice_dpll_cb_lock(pf))
+		return -EBUSY;
+	p = ice_find_pin(pf, pin, ICE_DPLL_PIN_TYPE_SOURCE);
+	if (!p) {
+		NL_SET_ERR_MSG(extack, "pin not found");
+		goto unlock;
+	}
+	d = ice_find_dpll(pf, dpll);
+	if (!d) {
+		NL_SET_ERR_MSG(extack, "dpll not found");
+		goto unlock;
+	}
+	*prio = d->input_prio[p->idx];
+	ret = 0;
+unlock:
+	ice_dpll_cb_unlock(pf);
+	dev_dbg(ice_pf_to_dev(pf), "%s: dpll:%p, pin:%p, pf:%p ret:%d\n",
+		__func__, dpll, pin, pf, ret);
+
+	return ret;
+}
+
+/**
+ * ice_dpll_source_prio_set - set dpll source prio
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: registered dpll pointer
+ * @dpll_priv: private data pointer passed on dpll registration
+ * @prio: source priority to be set on dpll
+ * @extack: error reporting
+ *
+ * Dpll subsystem callback. Handler for setting priority of a source pin.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - failure
+ */
+static int ice_dpll_source_prio_set(const struct dpll_pin *pin, void *pin_priv,
+				    const struct dpll_device *dpll,
+				    void *dpll_priv, u32 prio,
+				    struct netlink_ext_ack *extack)
+{
+	struct ice_pf *pf = pin_priv;
+	struct ice_dpll *d = NULL;
+	struct ice_dpll_pin *p;
+	int ret = -EINVAL;
+
+	if (!pf)
+		return ret;
+
+	if (prio > ICE_DPLL_PRIO_MAX) {
+		NL_SET_ERR_MSG(extack, "prio out of range");
+		return ret;
+	}
+
+	if (ice_dpll_cb_lock(pf))
+		return -EBUSY;
+	p = ice_find_pin(pf, pin, ICE_DPLL_PIN_TYPE_SOURCE);
+	if (!p) {
+		NL_SET_ERR_MSG(extack, "pin not found");

drivers/net/ethernet/intel/ice/ice_dpll.c line 1013

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+		goto unlock;
+	}
+	d = ice_find_dpll(pf, dpll);
+	if (!d) {
+		NL_SET_ERR_MSG(extack, "dpll not found");
+		goto unlock;
+	}
+	ret = ice_dpll_hw_source_prio_set(pf, d, p, prio);
+	if (ret)
+		NL_SET_ERR_MSG_FMT(extack, "unable to set prio: %d", ret);

Why you need to print "ret"? It is propagated to the caller as a return value.

Quoted 88 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +88 -0
+unlock:
+	ice_dpll_cb_unlock(pf);
+	dev_dbg(ice_pf_to_dev(pf), "%s: dpll:%p, pin:%p, pf:%p ret:%d\n",
+		__func__, dpll, pin, pf, ret);
+
+	return ret;
+}
+
+/**
+ * ice_dpll_source_direction - callback for get source pin direction
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: registered dpll pointer
+ * @dpll_priv: private data pointer passed on dpll registration
+ * @direction: holds source pin direction
+ * @extack: error reporting
+ *
+ * Dpll subsystem callback. Handler for getting direction of a source pin.
+ *
+ * Return:
+ * * 0 - success
+ */
+static int ice_dpll_source_direction(const struct dpll_pin *pin,
+				     void *pin_priv,
+				     const struct dpll_device *dpll,
+				     void *dpll_priv,
+				     enum dpll_pin_direction *direction,
+				     struct netlink_ext_ack *extack)
+{
+	*direction = DPLL_PIN_DIRECTION_SOURCE;
+
+	return 0;
+}
+
+/**
+ * ice_dpll_source_direction - callback for get output pin direction
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: registered dpll pointer
+ * @dpll_priv: private data pointer passed on dpll registration
+ * @direction: holds output pin direction
+ * @extack: error reporting
+ *
+ * Dpll subsystem callback. Handler for getting direction of an output pin.
+ *
+ * Return:
+ * * 0 - success
+ */
+static int ice_dpll_output_direction(const struct dpll_pin *pin,
+				     void *pin_priv,
+				     const struct dpll_device *dpll,
+				     void *dpll_priv,
+				     enum dpll_pin_direction *direction,
+				     struct netlink_ext_ack *extack)
+{
+	*direction = DPLL_PIN_DIRECTION_OUTPUT;
+
+	return 0;
+}
+
+/**
+ * ice_dpll_rclk_state_on_pin_set - set a state on rclk pin
+ * @dpll: registered dpll pointer
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @parent_pin: pin parent pointer
+ * @state: state to be set on pin
+ * @extack: error reporting
+ *
+ * Dpll subsystem callback, set a state of a rclk pin on a parent pin
+ *
+ * Return:
+ * * 0 - success
+ * * negative - failure
+ */
+static int ice_dpll_rclk_state_on_pin_set(const struct dpll_pin *pin,
+					  void *pin_priv,
+					  const struct dpll_pin *parent_pin,
+					  const enum dpll_pin_state state,
+					  struct netlink_ext_ack *extack)
+{
+	bool enable = state == DPLL_PIN_STATE_CONNECTED ? true : false;
+	u32 parent_idx, hw_idx = ICE_DPLL_PIN_IDX_INVALID, i;
+	struct ice_pf *pf = pin_priv;
+	struct ice_dpll_pin *p;
+	int ret = -EINVAL;
+
+	if (!pf)

drivers/net/ethernet/intel/ice/ice_dpll.c line 1111

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+		return ret;
+	if (ice_dpll_cb_lock(pf))
+		return -EBUSY;
+	p = ice_find_pin(pf, pin, ICE_DPLL_PIN_TYPE_RCLK_SOURCE);
+	if (!p) {
+		ret = -EFAULT;
+		goto unlock;
+	}
+	parent_idx = ice_find_pin_idx(pf, parent_pin,
+				      ICE_DPLL_PIN_TYPE_SOURCE);

Again, this does not make sense. You need struct ice_dpll_pin * related to parent. That should be parent priv and passed to dpll subsystem during registration and put as an "void * parent_pin_priv" arg to .state_on_pin_set() op. Whenever you do lookup like this, it is most usually wrong.

drivers/net/ethernet/intel/ice/ice_dpll.c line 1117

Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +6 -0
+	if (parent_idx == ICE_DPLL_PIN_IDX_INVALID) {
+		ret = -EFAULT;
+		goto unlock;
+	}
+	for (i = 0; i < pf->dplls.rclk.num_parents; i++)
+		if (pf->dplls.rclk.parent_idx[i] == parent_idx)

Can't you just store idx in struct ice_dpll_pin to avoid lookups like this one?

Quoted 24 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +24 -0
+			hw_idx = i;
+	if (hw_idx == ICE_DPLL_PIN_IDX_INVALID)
+		goto unlock;
+
+	if ((enable && !!(p->flags[hw_idx] &
+			 ICE_AQC_GET_PHY_REC_CLK_OUT_OUT_EN)) ||
+	    (!enable && !(p->flags[hw_idx] &
+			  ICE_AQC_GET_PHY_REC_CLK_OUT_OUT_EN))) {
+		ret = -EINVAL;
+		goto unlock;
+	}
+	ret = ice_aq_set_phy_rec_clk_out(&pf->hw, hw_idx, enable,
+					 &p->freq);
+unlock:
+	ice_dpll_cb_unlock(pf);
+	dev_dbg(ice_pf_to_dev(pf), "%s: parent:%p, pin:%p, pf:%p ret:%d\n",
+		__func__, parent_pin, pin, pf, ret);
+
+	return ret;
+}
+
+/**
+ * ice_dpll_rclk_state_on_pin_get - get a state of rclk pin
+ * @pin: pointer to a pin

drivers/net/ethernet/intel/ice/ice_dpll.c line 1151

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+ * @pin_priv: private data pointer passed on pin registration
+ * @parent_pin: pin parent pointer
+ * @state: on success holds pin state on parent pin
+ * @extack: error reporting
+ *
+ * dpll subsystem callback, get a state of a recovered clock pin.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - failure

I wonder how valuable this return values table is for a reader. Not much I suppose. Do you need it in comments to all the functions you have here?

drivers/net/ethernet/intel/ice/ice_dpll.c line 1160

Quoted 9 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +9 -0
+ */
+static int ice_dpll_rclk_state_on_pin_get(const struct dpll_pin *pin,
+					  void *pin_priv,
+					  const struct dpll_pin *parent_pin,
+					  enum dpll_pin_state *state,
+					  struct netlink_ext_ack *extack)
+{
+	struct ice_pf *pf = pin_priv;
+	u32 parent_idx, hw_idx = ICE_DPLL_PIN_IDX_INVALID, i;

Reverse christmas tree ordering please.

drivers/net/ethernet/intel/ice/ice_dpll.c line 1164

Quoted 4 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +4 -0
+	struct ice_dpll_pin *p;
+	int ret = -EFAULT;
+
+	if (!pf)

How exacly this can happen. My wild guess is it can't. Don't do such pointless checks please, confuses the reader.

Quoted 12 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +12 -0
+		return ret;
+	if (ice_dpll_cb_lock(pf))
+		return -EBUSY;
+	p = ice_find_pin(pf, pin, ICE_DPLL_PIN_TYPE_RCLK_SOURCE);
+	if (!p)
+		goto unlock;
+	parent_idx = ice_find_pin_idx(pf, parent_pin,
+				      ICE_DPLL_PIN_TYPE_SOURCE);
+	if (parent_idx == ICE_DPLL_PIN_IDX_INVALID)
+		goto unlock;
+	for (i = 0; i < pf->dplls.rclk.num_parents; i++)
+		if (pf->dplls.rclk.parent_idx[i] == parent_idx)

drivers/net/ethernet/intel/ice/ice_dpll.c line 1186

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+			hw_idx = i;
+	if (hw_idx == ICE_DPLL_PIN_IDX_INVALID)
+		goto unlock;
+
+	ret = ice_dpll_pin_state_update(pf, p, ICE_DPLL_PIN_TYPE_RCLK_SOURCE);
+	if (ret)
+		goto unlock;
+
+	if (!!(p->flags[hw_idx] &
+	    ICE_AQC_GET_PHY_REC_CLK_OUT_OUT_EN))

Avoid needless "!!".

drivers/net/ethernet/intel/ice/ice_dpll.c line 1189

Quoted 3 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +3 -0
+		*state = DPLL_PIN_STATE_CONNECTED;
+	else
+		*state = DPLL_PIN_STATE_DISCONNECTED;

Use ternary operator perhaps?

drivers/net/ethernet/intel/ice/ice_dpll.c line 1199

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+	ret = 0;
+unlock:
+	ice_dpll_cb_unlock(pf);
+	dev_dbg(ice_pf_to_dev(pf), "%s: parent:%p, pin:%p, pf:%p ret:%d\n",
+		__func__, parent_pin, pin, pf, ret);
+
+	return ret;
+}
+
+static struct dpll_pin_ops ice_dpll_rclk_ops = {

const.

drivers/net/ethernet/intel/ice/ice_dpll.c line 1205

Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +6 -0
+	.state_on_pin_set = ice_dpll_rclk_state_on_pin_set,
+	.state_on_pin_get = ice_dpll_rclk_state_on_pin_get,
+	.direction_get = ice_dpll_source_direction,
+};
+
+static struct dpll_pin_ops ice_dpll_source_ops = {

const.

drivers/net/ethernet/intel/ice/ice_dpll.c line 1215

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+	.frequency_get = ice_dpll_source_frequency_get,
+	.frequency_set = ice_dpll_source_frequency_set,
+	.state_on_dpll_get = ice_dpll_source_state_get,
+	.state_on_dpll_set = ice_dpll_source_state_set,
+	.prio_get = ice_dpll_source_prio_get,
+	.prio_set = ice_dpll_source_prio_set,
+	.direction_get = ice_dpll_source_direction,
+};
+
+static struct dpll_pin_ops ice_dpll_output_ops = {

const.

drivers/net/ethernet/intel/ice/ice_dpll.c line 1223

Quoted 8 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +8 -0
+	.frequency_get = ice_dpll_output_frequency_get,
+	.frequency_set = ice_dpll_output_frequency_set,
+	.state_on_dpll_get = ice_dpll_output_state_get,
+	.state_on_dpll_set = ice_dpll_output_state_set,
+	.direction_get = ice_dpll_output_direction,
+};
+
+static struct dpll_device_ops ice_dpll_ops = {

const.

Quoted 96 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +96 -0
+	.lock_status_get = ice_dpll_lock_status_get,
+	.mode_get = ice_dpll_mode_get,
+	.mode_supported = ice_dpll_mode_supported,
+};
+
+/**
+ * ice_dpll_release_info - release memory allocated for pins
+ * @pf: board private structure
+ *
+ * Release memory allocated for pins by ice_dpll_init_info function.
+ */
+static void ice_dpll_release_info(struct ice_pf *pf)
+{
+	kfree(pf->dplls.inputs);
+	pf->dplls.inputs = NULL;
+	kfree(pf->dplls.outputs);
+	pf->dplls.outputs = NULL;
+	kfree(pf->dplls.eec.input_prio);
+	pf->dplls.eec.input_prio = NULL;
+	kfree(pf->dplls.pps.input_prio);
+	pf->dplls.pps.input_prio = NULL;
+}
+
+/**
+ * ice_dpll_release_rclk_pin - release rclk pin from its parents
+ * @pf: board private structure
+ *
+ * Deregister from parent pins and release resources in dpll subsystem.
+ */
+static void
+ice_dpll_release_rclk_pin(struct ice_pf *pf)
+{
+	struct ice_dpll_pin *rclk = &pf->dplls.rclk;
+	struct dpll_pin *parent;
+	int i;
+
+	for (i = 0; i < rclk->num_parents; i++) {
+		parent = pf->dplls.inputs[rclk->parent_idx[i]].pin;
+		if (!parent)
+			continue;
+		dpll_pin_on_pin_unregister(parent, rclk->pin,
+					   &ice_dpll_rclk_ops, pf);
+	}
+	dpll_pin_put(rclk->pin);
+	rclk->pin = NULL;
+}
+
+/**
+ * ice_dpll_release_pins - release pin's from dplls registered in subsystem
+ * @pf: board private structure
+ * @dpll_eec: dpll_eec dpll pointer
+ * @dpll_pps: dpll_pps dpll pointer
+ * @pins: pointer to pins array
+ * @count: number of pins
+ * @ops: callback ops registered with the pins
+ * @cgu: if cgu is present and controlled by this NIC
+ *
+ * Deregister and free pins of a given array of pins from dpll devices
+ * registered in dpll subsystem.
+ */
+static void
+ice_dpll_release_pins(struct ice_pf *pf, struct dpll_device *dpll_eec,
+		      struct dpll_device *dpll_pps, struct ice_dpll_pin *pins,
+		      int count, struct dpll_pin_ops *ops, bool cgu)
+{
+	int i;
+
+	for (i = 0; i < count; i++) {
+		struct ice_dpll_pin *p = &pins[i];
+
+		if (p && !IS_ERR_OR_NULL(p->pin)) {
+			if (cgu && dpll_eec)
+				dpll_pin_unregister(dpll_eec, p->pin, ops, pf);
+			if (cgu && dpll_pps)
+				dpll_pin_unregister(dpll_pps, p->pin, ops, pf);
+			dpll_pin_put(p->pin);
+			p->pin = NULL;
+		}
+	}
+}
+
+/**
+ * ice_dpll_register_pins - register pins with a dpll
+ * @pf: board private structure
+ * @cgu: if cgu is present and controlled by this NIC
+ *
+ * Register source or output pins within given DPLL in a Linux dpll subsystem.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - error
+ */
+static int ice_dpll_register_pins(struct ice_pf *pf, bool cgu)
+{
+	struct device *dev = ice_pf_to_dev(pf);
+	struct ice_dpll_pin *pins;

drivers/net/ethernet/intel/ice/ice_dpll.c line 1329

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+	struct dpll_pin_ops *ops;
+	u32 rclk_idx;
+	int ret, i;
+
+	ops = &ice_dpll_source_ops;
+	pins = pf->dplls.inputs;
+	for (i = 0; i < pf->dplls.num_inputs; i++) {
+		pins[i].pin = dpll_pin_get(pf->dplls.clock_id, i,
+					   THIS_MODULE, &pins[i].prop);
+		if (IS_ERR_OR_NULL(pins[i].pin)) {

How exactly dpll_pin_get() can return NULL? It can't, use IS_ERR. Same in ice_dpll_release_pins() and two occurances below.

Quoted 4 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +4 -0
+			pins[i].pin = NULL;
+			return -ENOMEM;
+		}
+		if (cgu) {

drivers/net/ethernet/intel/ice/ice_dpll.c line 1343

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+			ret = dpll_pin_register(pf->dplls.eec.dpll,
+						pins[i].pin,
+						ops, pf, NULL);
+			if (ret)
+				return ret;
+			ret = dpll_pin_register(pf->dplls.pps.dpll,
+						pins[i].pin,
+						ops, pf, NULL);
+			if (ret)
+				return ret;

You have to call dpll_pin_unregister(pf->dplls.eec.dpll, pins[i].pin, ..) here.

drivers/net/ethernet/intel/ice/ice_dpll.c line 1355

Quoted 12 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +12 -0
+		}
+	}
+	if (cgu) {
+		ops = &ice_dpll_output_ops;
+		pins = pf->dplls.outputs;
+		for (i = 0; i < pf->dplls.num_outputs; i++) {
+			pins[i].pin = dpll_pin_get(pf->dplls.clock_id,
+						   i + pf->dplls.num_inputs,
+						   THIS_MODULE, &pins[i].prop);
+			if (IS_ERR_OR_NULL(pins[i].pin)) {
+				pins[i].pin = NULL;
+				return -ENOMEM;

Don't make up error values when you get them from the function you call:

	return PTR_ERR(pins[i].pin);

drivers/net/ethernet/intel/ice/ice_dpll.c line 1364

Quoted 9 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +9 -0
+			}
+			ret = dpll_pin_register(pf->dplls.eec.dpll, pins[i].pin,
+						ops, pf, NULL);
+			if (ret)
+				return ret;
+			ret = dpll_pin_register(pf->dplls.pps.dpll, pins[i].pin,
+						ops, pf, NULL);
+			if (ret)
+				return ret;

You have to call dpll_pin_unregister(pf->dplls.eec.dpll, pins[i].pin, ..) here.

drivers/net/ethernet/intel/ice/ice_dpll.c line 1372

Quoted 11 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +9 -0
+                                              ops, pf, NULL);  
 
 
+		}
+	}
+	rclk_idx = pf->dplls.num_inputs + pf->dplls.num_outputs + pf->hw.pf_id;
+	pf->dplls.rclk.pin = dpll_pin_get(pf->dplls.clock_id, rclk_idx,
+					  THIS_MODULE, &pf->dplls.rclk.prop);
+	if (IS_ERR_OR_NULL(pf->dplls.rclk.pin)) {
+		pf->dplls.rclk.pin = NULL;
+		return -ENOMEM;

Don't make up error values when you get them from the function you call:

	return PTR_ERR(pf->dplls.rclk.pin);
Quoted 17 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +17 -0
+	}
+	ops = &ice_dpll_rclk_ops;
+	for (i = 0; i < pf->dplls.rclk.num_parents; i++) {
+		struct dpll_pin *parent =
+			pf->dplls.inputs[pf->dplls.rclk.parent_idx[i]].pin;
+
+		ret = dpll_pin_on_pin_register(parent, pf->dplls.rclk.pin,
+					       ops, pf, dev);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+/**
+ * ice_generate_clock_id - generates unique clock_id for registering dpll.

drivers/net/ethernet/intel/ice/ice_dpll.c line 1399

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+ * @pf: board private structure
+ * @clock_id: holds generated clock_id
+ *
+ * Generates unique (per board) clock_id for allocation and search of dpll
+ * devices in Linux dpll subsystem.
+ */
+static void ice_generate_clock_id(struct ice_pf *pf, u64 *clock_id)
+{
+	*clock_id = pci_get_dsn(pf->pdev);
+}

How about:

static u64 ice_generate_clock_id(struct ice_pf *pf)

{
	return pci_get_dsn(pf->pdev);
}

??

Quoted 13 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +13 -0
+
+/**
+ * ice_dpll_init_dplls
+ * @pf: board private structure
+ * @cgu: if cgu is present and controlled by this NIC
+ *
+ * Get dplls instances for this board, if cgu is controlled by this NIC,
+ * register dpll with callbacks ops
+ *
+ * Return:
+ * * 0 - success
+ * * negative - allocation fails
+ */

drivers/net/ethernet/intel/ice/ice_dpll.c line 1422

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+static int ice_dpll_init_dplls(struct ice_pf *pf, bool cgu)
+{
+	struct device *dev = ice_pf_to_dev(pf);
+	int ret = -ENOMEM;
+	u64 clock_id;
+
+	ice_generate_clock_id(pf, &clock_id);
+	pf->dplls.eec.dpll = dpll_device_get(clock_id, pf->dplls.eec.dpll_idx,
+					     THIS_MODULE);
+	if (!pf->dplls.eec.dpll) {

You have to use IS_ERR()

drivers/net/ethernet/intel/ice/ice_dpll.c line 1428

Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +6 -0
+		dev_err(ice_pf_to_dev(pf), "dpll_device_get failed (eec)\n");
+		return ret;
+	}
+	pf->dplls.pps.dpll = dpll_device_get(clock_id, pf->dplls.pps.dpll_idx,
+					     THIS_MODULE);
+	if (!pf->dplls.pps.dpll) {

You have to use IS_ERR()

drivers/net/ethernet/intel/ice/ice_dpll.c line 1440

Quoted 12 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +12 -0
+		dev_err(ice_pf_to_dev(pf), "dpll_device_get failed (pps)\n");
+		goto put_eec;
+	}
+
+	if (cgu) {
+		ret = dpll_device_register(pf->dplls.eec.dpll, DPLL_TYPE_EEC,
+					   &ice_dpll_ops, pf, dev);
+		if (ret)
+			goto put_pps;
+		ret = dpll_device_register(pf->dplls.pps.dpll, DPLL_TYPE_PPS,
+					   &ice_dpll_ops, pf, dev);
+		if (ret)

You are missing call to dpll_device_unregister(pf->dplls.eec.dpll, DPLL_TYPE_EEC here. Fix the error path.

Quoted 79 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +79 -0
+			goto put_pps;
+	}
+
+	return 0;
+
+put_pps:
+	dpll_device_put(pf->dplls.pps.dpll);
+	pf->dplls.pps.dpll = NULL;
+put_eec:
+	dpll_device_put(pf->dplls.eec.dpll);
+	pf->dplls.eec.dpll = NULL;
+
+	return ret;
+}
+
+/**
+ * ice_dpll_update_state - update dpll state
+ * @pf: pf private structure
+ * @d: pointer to queried dpll device
+ *
+ * Poll current state of dpll from hw and update ice_dpll struct.
+ * Return:
+ * * 0 - success
+ * * negative - AQ failure
+ */
+static int ice_dpll_update_state(struct ice_pf *pf, struct ice_dpll *d, bool init)
+{
+	struct ice_dpll_pin *p;
+	int ret;
+
+	ret = ice_get_cgu_state(&pf->hw, d->dpll_idx, d->prev_dpll_state,
+				&d->source_idx, &d->ref_state, &d->eec_mode,
+				&d->phase_offset, &d->dpll_state);
+
+	dev_dbg(ice_pf_to_dev(pf),
+		"update dpll=%d, prev_src_idx:%u, src_idx:%u, state:%d, prev:%d\n",
+		d->dpll_idx, d->prev_source_idx, d->source_idx,
+		d->dpll_state, d->prev_dpll_state);
+	if (ret) {
+		dev_err(ice_pf_to_dev(pf),
+			"update dpll=%d state failed, ret=%d %s\n",
+			d->dpll_idx, ret,
+			ice_aq_str(pf->hw.adminq.sq_last_status));
+		return ret;
+	}
+	if (init) {
+		if (d->dpll_state == ICE_CGU_STATE_LOCKED &&
+		    d->dpll_state == ICE_CGU_STATE_LOCKED_HO_ACQ)
+			d->active_source = pf->dplls.inputs[d->source_idx].pin;
+		p = &pf->dplls.inputs[d->source_idx];
+		return ice_dpll_pin_state_update(pf, p,
+						 ICE_DPLL_PIN_TYPE_SOURCE);
+	}
+	if (d->dpll_state == ICE_CGU_STATE_HOLDOVER ||
+	    d->dpll_state == ICE_CGU_STATE_FREERUN) {
+		d->active_source = NULL;
+		p = &pf->dplls.inputs[d->source_idx];
+		d->prev_source_idx = ICE_DPLL_PIN_IDX_INVALID;
+		d->source_idx = ICE_DPLL_PIN_IDX_INVALID;
+		ret = ice_dpll_pin_state_update(pf, p, ICE_DPLL_PIN_TYPE_SOURCE);
+	} else if (d->source_idx != d->prev_source_idx) {
+		p = &pf->dplls.inputs[d->prev_source_idx];
+		ice_dpll_pin_state_update(pf, p, ICE_DPLL_PIN_TYPE_SOURCE);
+		p = &pf->dplls.inputs[d->source_idx];
+		d->active_source = p->pin;
+		ice_dpll_pin_state_update(pf, p, ICE_DPLL_PIN_TYPE_SOURCE);
+		d->prev_source_idx = d->source_idx;
+	}
+
+	return ret;
+}
+
+/**
+ * ice_dpll_notify_changes - notify dpll subsystem about changes
+ * @d: pointer do dpll
+ *
+ * Once change detected appropriate event is submitted to the dpll subsystem.
+ */
+static void ice_dpll_notify_changes(struct ice_dpll *d)

drivers/net/ethernet/intel/ice/ice_dpll.c line 1529

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+{
+	if (d->prev_dpll_state != d->dpll_state) {
+		d->prev_dpll_state = d->dpll_state;
+		dpll_device_notify(d->dpll, DPLL_A_LOCK_STATUS);
+	}
+	if (d->prev_source != d->active_source) {
+		d->prev_source = d->active_source;
+		if (d->active_source)
+			dpll_pin_notify(d->dpll, d->active_source,
+					DPLL_A_PIN_STATE);

Didn't the state of the previously active source change as well? You need to send notification for that too.

Quoted 89 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +89 -0
+	}
+}
+
+/**
+ * ice_dpll_periodic_work - DPLLs periodic worker
+ * @work: pointer to kthread_work structure
+ *
+ * DPLLs periodic worker is responsible for polling state of dpll.
+ */
+static void ice_dpll_periodic_work(struct kthread_work *work)
+{
+	struct ice_dplls *d = container_of(work, struct ice_dplls, work.work);
+	struct ice_pf *pf = container_of(d, struct ice_pf, dplls);
+	struct ice_dpll *de = &pf->dplls.eec;
+	struct ice_dpll *dp = &pf->dplls.pps;
+	int ret = 0;
+
+	if (!test_bit(ICE_FLAG_DPLL, pf->flags))
+		return;
+	ret = ice_dpll_cb_lock(pf);
+	if (ret) {
+		d->lock_err_num++;
+		goto resched;
+	}
+	ret = ice_dpll_update_state(pf, de, false);
+	if (!ret)
+		ret = ice_dpll_update_state(pf, dp, false);
+	if (ret) {
+		d->cgu_state_acq_err_num++;
+		/* stop rescheduling this worker */
+		if (d->cgu_state_acq_err_num >
+		    ICE_CGU_STATE_ACQ_ERR_THRESHOLD) {
+			dev_err(ice_pf_to_dev(pf),
+				"EEC/PPS DPLLs periodic work disabled\n");
+			return;
+		}
+	}
+	ice_dpll_cb_unlock(pf);
+	ice_dpll_notify_changes(de);
+	ice_dpll_notify_changes(dp);
+resched:
+	/* Run twice a second or reschedule if update failed */
+	kthread_queue_delayed_work(d->kworker, &d->work,
+				   ret ? msecs_to_jiffies(10) :
+				   msecs_to_jiffies(500));
+}
+
+/**
+ * ice_dpll_init_worker - Initialize DPLLs periodic worker
+ * @pf: board private structure
+ *
+ * Create and start DPLLs periodic worker.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - create worker failure
+ */
+static int ice_dpll_init_worker(struct ice_pf *pf)
+{
+	struct ice_dplls *d = &pf->dplls;
+	struct kthread_worker *kworker;
+
+	ice_dpll_update_state(pf, &d->eec, true);
+	ice_dpll_update_state(pf, &d->pps, true);
+	kthread_init_delayed_work(&d->work, ice_dpll_periodic_work);
+	kworker = kthread_create_worker(0, "ice-dplls-%s",
+					dev_name(ice_pf_to_dev(pf)));
+	if (IS_ERR(kworker))
+		return PTR_ERR(kworker);
+	d->kworker = kworker;
+	d->cgu_state_acq_err_num = 0;
+	kthread_queue_delayed_work(d->kworker, &d->work, 0);
+
+	return 0;
+}
+
+/**
+ * ice_dpll_release_all - disable support for DPLL and unregister dpll device
+ * @pf: board private structure
+ * @cgu: if cgu is controlled by this driver instance
+ *
+ * This function handles the cleanup work required from the initialization by
+ * freeing resources and unregistering the dpll.
+ *
+ * Context: Called under pf->dplls.lock
+ */
+static void ice_dpll_release_all(struct ice_pf *pf, bool cgu)
+{
+	struct ice_dplls *d = &pf->dplls;

drivers/net/ethernet/intel/ice/ice_dpll.c line 1628

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+	struct ice_dpll *de = &d->eec;
+	struct ice_dpll *dp = &d->pps;
+
+	mutex_lock(&pf->dplls.lock);
+	ice_dpll_release_rclk_pin(pf);
+	ice_dpll_release_pins(pf, de->dpll, dp->dpll, d->inputs,
+			      d->num_inputs, &ice_dpll_source_ops, cgu);
+	mutex_unlock(&pf->dplls.lock);
+	if (cgu) {
+		mutex_lock(&pf->dplls.lock);

Interesting, you lock again a lock you just unlocked. One might wonder why you just don't move the call to mutex_unlock below this "if section".

Quoted 94 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +94 -0
+		ice_dpll_release_pins(pf, de->dpll, dp->dpll, d->outputs,
+				      d->num_outputs,
+				      &ice_dpll_output_ops, cgu);
+		mutex_unlock(&pf->dplls.lock);
+	}
+	ice_dpll_release_info(pf);
+	if (dp->dpll) {
+		mutex_lock(&pf->dplls.lock);
+		if (cgu)
+			dpll_device_unregister(dp->dpll, &ice_dpll_ops, pf);
+		dpll_device_put(dp->dpll);
+		mutex_unlock(&pf->dplls.lock);
+		dev_dbg(ice_pf_to_dev(pf), "PPS dpll removed\n");
+	}
+
+	if (de->dpll) {
+		mutex_lock(&pf->dplls.lock);
+		if (cgu)
+			dpll_device_unregister(de->dpll, &ice_dpll_ops, pf);
+		dpll_device_put(de->dpll);
+		mutex_unlock(&pf->dplls.lock);
+		dev_dbg(ice_pf_to_dev(pf), "EEC dpll removed\n");
+	}
+
+	if (cgu) {
+		mutex_lock(&pf->dplls.lock);
+		kthread_cancel_delayed_work_sync(&d->work);
+		if (d->kworker) {
+			kthread_destroy_worker(d->kworker);
+			d->kworker = NULL;
+			dev_dbg(ice_pf_to_dev(pf), "DPLLs worker removed\n");
+		}
+		mutex_unlock(&pf->dplls.lock);
+	}
+}
+
+/**
+ * ice_dpll_release - Disable the driver/HW support for DPLLs and unregister
+ * the dpll device.
+ * @pf: board private structure
+ *
+ * Handles the cleanup work required after dpll initialization,
+ * freeing resources and unregistering the dpll.
+ */
+void ice_dpll_release(struct ice_pf *pf)
+{
+	if (test_bit(ICE_FLAG_DPLL, pf->flags)) {
+		ice_dpll_release_all(pf,
+				     ice_is_feature_supported(pf, ICE_F_CGU));
+		mutex_destroy(&pf->dplls.lock);
+		clear_bit(ICE_FLAG_DPLL, pf->flags);
+	}
+}
+
+/**
+ * ice_dpll_init_direct_pins - initializes source or output pins information
+ * @pf: board private structure
+ * @pin_type: type of pins being initialized
+ *
+ * Init information about input or output pins, cache them in pins struct.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - init failure
+ */
+static int
+ice_dpll_init_direct_pins(struct ice_pf *pf, enum ice_dpll_pin_type pin_type)
+{
+	struct ice_dpll *de = &pf->dplls.eec, *dp = &pf->dplls.pps;
+	int num_pins, i, ret = -EINVAL;
+	struct ice_hw *hw = &pf->hw;
+	struct ice_dpll_pin *pins;
+	u8 freq_supp_num;
+	bool input;
+
+	if (pin_type == ICE_DPLL_PIN_TYPE_SOURCE) {
+		pins = pf->dplls.inputs;
+		num_pins = pf->dplls.num_inputs;
+		input = true;
+	} else if (pin_type == ICE_DPLL_PIN_TYPE_OUTPUT) {
+		pins = pf->dplls.outputs;
+		num_pins = pf->dplls.num_outputs;
+		input = false;
+	} else {
+		return -EINVAL;
+	}
+
+	for (i = 0; i < num_pins; i++) {
+		pins[i].idx = i;
+		pins[i].prop.label = ice_cgu_get_pin_name(hw, i, input);
+		pins[i].prop.type = ice_cgu_get_pin_type(hw, i, input);
+		if (input) {
+			ret = ice_aq_get_cgu_ref_prio(hw, de->dpll_idx, i,
+						      &de->input_prio[i]);

drivers/net/ethernet/intel/ice/ice_dpll.c line 1732

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+			if (ret)
+				return ret;
+			ret = ice_aq_get_cgu_ref_prio(hw, dp->dpll_idx, i,
+						      &dp->input_prio[i]);
+			if (ret)
+				return ret;
+			pins[i].prop.capabilities +=
+				DPLL_PIN_CAPS_PRIORITY_CAN_CHANGE;
+		}
+		pins[i].prop.capabilities += DPLL_PIN_CAPS_STATE_CAN_CHANGE;

It is a flag. Common is to use bit op &= instead.

Quoted 47 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +47 -0
+		ret = ice_dpll_pin_state_update(pf, &pins[i], pin_type);
+		if (ret)
+			return ret;
+		pins[i].prop.freq_supported =
+			ice_cgu_get_pin_freq_supp(hw, i, input, &freq_supp_num);
+		pins[i].prop.freq_supported_num = freq_supp_num;
+	}
+
+	return ret;
+}
+
+/**
+ * ice_dpll_init_rclk_pin - initializes rclk pin information
+ * @pf: board private structure
+ * @pin_type: type of pins being initialized
+ *
+ * Init information for rclk pin, cache them in pf->dplls.rclk.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - init failure
+ */
+static int ice_dpll_init_rclk_pin(struct ice_pf *pf)
+{
+	struct ice_dpll_pin *pin = &pf->dplls.rclk;
+	struct device *dev = ice_pf_to_dev(pf);
+
+	pin->prop.label = dev_name(dev);
+	pin->prop.type = DPLL_PIN_TYPE_SYNCE_ETH_PORT;
+	pin->prop.capabilities += DPLL_PIN_CAPS_STATE_CAN_CHANGE;
+
+	return ice_dpll_pin_state_update(pf, pin,
+					 ICE_DPLL_PIN_TYPE_RCLK_SOURCE);
+}
+
+/**
+ * ice_dpll_init_pins - init pins wrapper
+ * @pf: board private structure
+ * @pin_type: type of pins being initialized
+ *
+ * Wraps functions for pin inti.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - init failure
+ */
+static int ice_dpll_init_pins(struct ice_pf *pf,

drivers/net/ethernet/intel/ice/ice_dpll.c line 1789

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+			      const enum ice_dpll_pin_type pin_type)
+{
+	if (pin_type == ICE_DPLL_PIN_TYPE_SOURCE)
+		return ice_dpll_init_direct_pins(pf, pin_type);
+	else if (pin_type == ICE_DPLL_PIN_TYPE_OUTPUT)
+		return ice_dpll_init_direct_pins(pf, pin_type);
+	else if (pin_type == ICE_DPLL_PIN_TYPE_RCLK_SOURCE)
+		return ice_dpll_init_rclk_pin(pf);
+	else
+		return -EINVAL;

How this can happen?

How about:

	switch (pin_type) {
	case ICE_DPLL_PIN_TYPE_SOURCE:
	case ICE_DPLL_PIN_TYPE_OUTPUT:
		return ice_dpll_init_direct_pins(pf, pin_type);
	case ICE_DPLL_PIN_TYPE_RCLK_SOURCE:
		return ice_dpll_init_rclk_pin(pf);
	}

?

Quoted 108 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +108 -0
+}
+
+/**
+ * ice_dpll_init_info - prepare pf's dpll information structure
+ * @pf: board private structure
+ * @cgu: if cgu is present and controlled by this NIC
+ *
+ * Acquire (from HW) and set basic dpll information (on pf->dplls struct).
+ *
+ * Return:
+ * * 0 - success
+ * * negative - error
+ */
+static int ice_dpll_init_info(struct ice_pf *pf, bool cgu)
+{
+	struct ice_aqc_get_cgu_abilities abilities;
+	struct ice_dpll *de = &pf->dplls.eec;
+	struct ice_dpll *dp = &pf->dplls.pps;
+	struct ice_dplls *d = &pf->dplls;
+	struct ice_hw *hw = &pf->hw;
+	int ret, alloc_size, i;
+	u8 base_rclk_idx;
+
+	ice_generate_clock_id(pf, &d->clock_id);
+	ret = ice_aq_get_cgu_abilities(hw, &abilities);
+	if (ret) {
+		dev_err(ice_pf_to_dev(pf),
+			"err:%d %s failed to read cgu abilities\n",
+			ret, ice_aq_str(hw->adminq.sq_last_status));
+		return ret;
+	}
+
+	de->dpll_idx = abilities.eec_dpll_idx;
+	dp->dpll_idx = abilities.pps_dpll_idx;
+	d->num_inputs = abilities.num_inputs;
+	d->num_outputs = abilities.num_outputs;
+
+	alloc_size = sizeof(*d->inputs) * d->num_inputs;
+	d->inputs = kzalloc(alloc_size, GFP_KERNEL);
+	if (!d->inputs)
+		return -ENOMEM;
+
+	alloc_size = sizeof(*de->input_prio) * d->num_inputs;
+	de->input_prio = kzalloc(alloc_size, GFP_KERNEL);
+	if (!de->input_prio)
+		return -ENOMEM;
+
+	dp->input_prio = kzalloc(alloc_size, GFP_KERNEL);
+	if (!dp->input_prio)
+		return -ENOMEM;
+
+	ret = ice_dpll_init_pins(pf, ICE_DPLL_PIN_TYPE_SOURCE);
+	if (ret)
+		goto release_info;
+
+	if (cgu) {
+		alloc_size = sizeof(*d->outputs) * d->num_outputs;
+		d->outputs = kzalloc(alloc_size, GFP_KERNEL);
+		if (!d->outputs)
+			goto release_info;
+
+		ret = ice_dpll_init_pins(pf, ICE_DPLL_PIN_TYPE_OUTPUT);
+		if (ret)
+			goto release_info;
+	}
+
+	ret = ice_get_cgu_rclk_pin_info(&pf->hw, &base_rclk_idx,
+					&pf->dplls.rclk.num_parents);
+	if (ret)
+		return ret;
+	for (i = 0; i < pf->dplls.rclk.num_parents; i++)
+		pf->dplls.rclk.parent_idx[i] = base_rclk_idx + i;
+	ret = ice_dpll_init_pins(pf, ICE_DPLL_PIN_TYPE_RCLK_SOURCE);
+	if (ret)
+		return ret;
+
+	dev_dbg(ice_pf_to_dev(pf),
+		"%s - success, inputs:%u, outputs:%u rclk-parents:%u\n",
+		__func__, d->num_inputs, d->num_outputs, d->rclk.num_parents);
+
+	return 0;
+
+release_info:
+	dev_err(ice_pf_to_dev(pf),
+		"%s - fail: d->inputs:%p, de->input_prio:%p, dp->input_prio:%p, d->outputs:%p\n",
+		__func__, d->inputs, de->input_prio,
+		dp->input_prio, d->outputs);
+	ice_dpll_release_info(pf);
+	return ret;
+}
+
+/**
+ * ice_dpll_init - initialize dplls support
+ * @pf: board private structure
+ *
+ * Set up the device dplls registering them and pins connected within Linux dpll
+ * subsystem. Allow userpsace to obtain state of DPLL and handling of DPLL
+ * configuration requests.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - init failure
+ */
+int ice_dpll_init(struct ice_pf *pf)
+{
+	bool cgu_present = ice_is_feature_supported(pf, ICE_F_CGU);
+	struct ice_dplls *d = &pf->dplls;
+	int err = 0;

drivers/net/ethernet/intel/ice/ice_dpll.c line 1907

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+
+	mutex_init(&d->lock);
+	mutex_lock(&d->lock);
+	err = ice_dpll_init_info(pf, cgu_present);
+	if (err)
+		goto release;
+	err = ice_dpll_init_dplls(pf, cgu_present);
+	if (err)
+		goto release;
+	err = ice_dpll_register_pins(pf, cgu_present);

This should be rather called "ice_dpll_init_pins()" to be in sync with ice_dpll_init_dplls() as it is doing more then just registration.

Quoted 432 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +22 -0
+	if (err)
+		goto release;
+	set_bit(ICE_FLAG_DPLL, pf->flags);
+	if (cgu_present) {
+		err = ice_dpll_init_worker(pf);
+		if (err)
+			goto release;
+	}
+	mutex_unlock(&d->lock);
+	dev_info(ice_pf_to_dev(pf), "DPLLs init successful\n");
+
+	return err;
+
+release:
+	ice_dpll_release_all(pf, cgu_present);
+	clear_bit(ICE_FLAG_DPLL, pf->flags);
+	mutex_unlock(&d->lock);
+	mutex_destroy(&d->lock);
+	dev_warn(ice_pf_to_dev(pf), "DPLLs init failure\n");
+
+	return err;
+}
drivers/net/ethernet/intel/ice/ice_dpll.h new file +101 -0
new file mode 100644
index 000000000000..aad48b9910b7
@@ -0,0 +1,101 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2022, Intel Corporation. */
+
+#ifndef _ICE_DPLL_H_
+#define _ICE_DPLL_H_
+
+#include "ice.h"
+
+#define ICE_DPLL_PRIO_MAX	0xF
+#define ICE_DPLL_RCLK_NUM_MAX	4
+/** ice_dpll_pin - store info about pins
+ * @pin: dpll pin structure
+ * @flags: pin flags returned from HW
+ * @idx: ice pin private idx
+ * @state: state of a pin
+ * @type: type of a pin
+ * @freq_mask: mask of supported frequencies
+ * @freq: current frequency of a pin
+ * @caps: capabilities of a pin
+ * @name: pin name
+ */
+struct ice_dpll_pin {
+	struct dpll_pin *pin;
+	u8 idx;
+	u8 num_parents;
+	u8 parent_idx[ICE_DPLL_RCLK_NUM_MAX];
+	u8 flags[ICE_DPLL_RCLK_NUM_MAX];
+	u8 state[ICE_DPLL_RCLK_NUM_MAX];
+	struct dpll_pin_properties prop;
+	u32 freq;
+};
+
+/** ice_dpll - store info required for DPLL control
+ * @dpll: pointer to dpll dev
+ * @dpll_idx: index of dpll on the NIC
+ * @source_idx: source currently selected
+ * @prev_source_idx: source previously selected
+ * @ref_state: state of dpll reference signals
+ * @eec_mode: eec_mode dpll is configured for
+ * @phase_offset: phase delay of a dpll
+ * @input_prio: priorities of each input
+ * @dpll_state: current dpll sync state
+ * @prev_dpll_state: last dpll sync state
+ * @active_source: pointer to active source pin
+ * @prev_source: pointer to previous active source pin
+ */
+struct ice_dpll {
+	struct dpll_device *dpll;
+	int dpll_idx;
+	u8 source_idx;
+	u8 prev_source_idx;
+	u8 ref_state;
+	u8 eec_mode;
+	s64 phase_offset;
+	u8 *input_prio;
+	enum ice_cgu_state dpll_state;
+	enum ice_cgu_state prev_dpll_state;
+	struct dpll_pin *active_source;
+	struct dpll_pin *prev_source;
+};
+
+/** ice_dplls - store info required for CCU (clock controlling unit)
+ * @kworker: periodic worker
+ * @work: periodic work
+ * @lock: locks access to configuration of a dpll
+ * @eec: pointer to EEC dpll dev
+ * @pps: pointer to PPS dpll dev
+ * @inputs: input pins pointer
+ * @outputs: output pins pointer
+ * @rclk: recovered pins pointer
+ * @num_inputs: number of input pins available on dpll
+ * @num_outputs: number of output pins available on dpll
+ * @num_rclk: number of recovered clock pins available on dpll
+ * @cgu_state_acq_err_num: number of errors returned during periodic work
+ */
+struct ice_dplls {
+	struct kthread_worker *kworker;
+	struct kthread_delayed_work work;
+	struct mutex lock;
+	struct ice_dpll eec;
+	struct ice_dpll pps;
+	struct ice_dpll_pin *inputs;
+	struct ice_dpll_pin *outputs;
+	struct ice_dpll_pin rclk;
+	u32 num_inputs;
+	u32 num_outputs;
+	int cgu_state_acq_err_num;
+	int lock_err_num;
+	u8 base_rclk_idx;
+	u64 clock_id;
+};
+
+int ice_dpll_init(struct ice_pf *pf);
+
+void ice_dpll_release(struct ice_pf *pf);
+
+int ice_dpll_rclk_init(struct ice_pf *pf);
+
+void ice_dpll_rclk_release(struct ice_pf *pf);
+
+#endif
drivers/net/ethernet/intel/ice/ice_main.c +7 -0
index a1f7c8edc22f..6b28b95a7254 100644
@@ -4821,6 +4821,10 @@ static void ice_init_features(struct ice_pf *pf)
 	if (ice_is_feature_supported(pf, ICE_F_GNSS))
 		ice_gnss_init(pf);
 
+	if (ice_is_feature_supported(pf, ICE_F_CGU) ||
+	    ice_is_feature_supported(pf, ICE_F_PHY_RCLK))
+		ice_dpll_init(pf);
+
 	/* Note: Flow director init failure is non-fatal to load */
 	if (ice_init_fdir(pf))
 		dev_err(dev, "could not initialize flow director\n");
@@ -4847,6 +4851,9 @@ static void ice_deinit_features(struct ice_pf *pf)
 		ice_gnss_exit(pf);
 	if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags))
 		ice_ptp_release(pf);
+	if (ice_is_feature_supported(pf, ICE_F_PHY_RCLK) ||
+	    ice_is_feature_supported(pf, ICE_F_CGU))
+		ice_dpll_release(pf);
 }
 
 static void ice_init_wakeup(struct ice_pf *pf)
drivers/net/ethernet/intel/ice/ice_ptp_hw.c +12 -9
index e9a371fa038b..39b692945f73 100644
@@ -3609,28 +3609,31 @@ enum dpll_pin_type ice_cgu_get_pin_type(struct ice_hw *hw, u8 pin, bool input)
 }
 
 /**
- * ice_cgu_get_pin_sig_type_mask
+ * ice_cgu_get_pin_freq_supp
 * @hw: pointer to the hw struct
 * @pin: pin index
 * @input: if request is done against input or output pin
+ * @num: output number of supported frequencies
 *
- * Return: signal type bit mask of a pin.
+ * Get frequency supported number and array of supported frequencies.
+ *
+ * Return: array of supported frequencies for given pin.
 */
-unsigned long
-ice_cgu_get_pin_freq_mask(struct ice_hw *hw, u8 pin, bool input)
+struct dpll_pin_frequency *
+ice_cgu_get_pin_freq_supp(struct ice_hw *hw, u8 pin, bool input, u8 *num)
 {
 	const struct ice_cgu_pin_desc *t;
 	int t_size;
 
+	*num = 0;
 	t = ice_cgu_get_pin_desc(hw, input, &t_size);
-
 	if (!t)
-		return 0;
-
+		return NULL;
 	if (pin >= t_size)
-		return 0;
+		return NULL;
+	*num = t[pin].freq_supp_num;
 
-	return t[pin].sig_type_mask;
+	return t[pin].freq_supp;
 }
 
 /**
drivers/net/ethernet/intel/ice/ice_ptp_hw.h +69 -79
index d09e5bca0ff1..4568b0403cd7 100644
@@ -192,147 +192,137 @@ enum ice_si_cgu_out_pins {
 	NUM_SI_CGU_OUTPUT_PINS
 };
 
-#define MAX_CGU_PIN_NAME_LEN		16
-#define ICE_SIG_TYPE_MASK_1PPS_10MHZ	(BIT(DPLL_PIN_FREQ_SUPP_1_HZ) | \
-					 BIT(DPLL_PIN_FREQ_SUPP_10_MHZ))
+static struct dpll_pin_frequency ice_cgu_pin_freq_common[] = {
+	DPLL_PIN_FREQUENCY_1PPS,
+	DPLL_PIN_FREQUENCY_10MHZ,
+};
+
+static struct dpll_pin_frequency ice_cgu_pin_freq_1_hz[] = {
+	DPLL_PIN_FREQUENCY_1PPS,
+};
+
+static struct dpll_pin_frequency ice_cgu_pin_freq_10_mhz[] = {
+	DPLL_PIN_FREQUENCY_10MHZ,
+};
+
 struct ice_cgu_pin_desc {
-	char name[MAX_CGU_PIN_NAME_LEN];
+	char *name;
 	u8 index;
 	enum dpll_pin_type type;
-	unsigned long sig_type_mask;
+	u32 freq_supp_num;
+	struct dpll_pin_frequency *freq_supp;
 };
 
 static const struct ice_cgu_pin_desc ice_e810t_sfp_cgu_inputs[] = {
 	{ "CVL-SDP22",	  ZL_REF0P, DPLL_PIN_TYPE_INT_OSCILLATOR,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
 	{ "CVL-SDP20",	  ZL_REF0N, DPLL_PIN_TYPE_INT_OSCILLATOR,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
-	{ "C827_0-RCLKA", ZL_REF1P, DPLL_PIN_TYPE_MUX,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
-	{ "C827_0-RCLKB", ZL_REF1N, DPLL_PIN_TYPE_MUX,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
+	{ "C827_0-RCLKA", ZL_REF1P, DPLL_PIN_TYPE_MUX, 0, },
+	{ "C827_0-RCLKB", ZL_REF1N, DPLL_PIN_TYPE_MUX, 0, },
 	{ "SMA1",	  ZL_REF3P, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
 	{ "SMA2/U.FL2",	  ZL_REF3N, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
 	{ "GNSS-1PPS",	  ZL_REF4P, DPLL_PIN_TYPE_GNSS,
-		BIT(DPLL_PIN_FREQ_SUPP_1_HZ) },
-	{ "OCXO",	  ZL_REF4N, DPLL_PIN_TYPE_INT_OSCILLATOR,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
+		ARRAY_SIZE(ice_cgu_pin_freq_1_hz), ice_cgu_pin_freq_1_hz },
+	{ "OCXO",	  ZL_REF4N, DPLL_PIN_TYPE_INT_OSCILLATOR, 0, },
 };
 
 static const struct ice_cgu_pin_desc ice_e810t_qsfp_cgu_inputs[] = {
 	{ "CVL-SDP22",	  ZL_REF0P, DPLL_PIN_TYPE_INT_OSCILLATOR,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
 	{ "CVL-SDP20",	  ZL_REF0N, DPLL_PIN_TYPE_INT_OSCILLATOR,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
-	{ "C827_0-RCLKA", ZL_REF1P, DPLL_PIN_TYPE_MUX,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
-	{ "C827_0-RCLKB", ZL_REF1N, DPLL_PIN_TYPE_MUX,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
-	{ "C827_1-RCLKA", ZL_REF2P, DPLL_PIN_TYPE_MUX,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
-	{ "C827_1-RCLKB", ZL_REF2N, DPLL_PIN_TYPE_MUX,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
+	{ "C827_0-RCLKA", ZL_REF1P, DPLL_PIN_TYPE_MUX, },
+	{ "C827_0-RCLKB", ZL_REF1N, DPLL_PIN_TYPE_MUX, },
+	{ "C827_1-RCLKA", ZL_REF2P, DPLL_PIN_TYPE_MUX, },
+	{ "C827_1-RCLKB", ZL_REF2N, DPLL_PIN_TYPE_MUX, },
 	{ "SMA1",	  ZL_REF3P, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
 	{ "SMA2/U.FL2",	  ZL_REF3N, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
 	{ "GNSS-1PPS",	  ZL_REF4P, DPLL_PIN_TYPE_GNSS,
-		BIT(DPLL_PIN_FREQ_SUPP_1_HZ) },
-	{ "OCXO",	  ZL_REF4N, DPLL_PIN_TYPE_INT_OSCILLATOR,
-			BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
+		ARRAY_SIZE(ice_cgu_pin_freq_1_hz), ice_cgu_pin_freq_1_hz },
+	{ "OCXO",	  ZL_REF4N, DPLL_PIN_TYPE_INT_OSCILLATOR, },
 };
 
 static const struct ice_cgu_pin_desc ice_e810t_sfp_cgu_outputs[] = {
 	{ "REF-SMA1",	    ZL_OUT0, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
 	{ "REF-SMA2/U.FL2", ZL_OUT1, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
-	{ "PHY-CLK",	    ZL_OUT2, DPLL_PIN_TYPE_SYNCE_ETH_PORT,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
-	{ "MAC-CLK",	    ZL_OUT3, DPLL_PIN_TYPE_SYNCE_ETH_PORT,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
+	{ "PHY-CLK",	    ZL_OUT2, DPLL_PIN_TYPE_SYNCE_ETH_PORT, },
+	{ "MAC-CLK",	    ZL_OUT3, DPLL_PIN_TYPE_SYNCE_ETH_PORT, },
 	{ "CVL-SDP21",	    ZL_OUT4, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_1_hz), ice_cgu_pin_freq_1_hz },
 	{ "CVL-SDP23",	    ZL_OUT5, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_1_hz), ice_cgu_pin_freq_1_hz },
 };
 
 static const struct ice_cgu_pin_desc ice_e810t_qsfp_cgu_outputs[] = {
 	{ "REF-SMA1",	    ZL_OUT0, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
 	{ "REF-SMA2/U.FL2", ZL_OUT1, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
-	{ "PHY-CLK",	    ZL_OUT2, DPLL_PIN_TYPE_SYNCE_ETH_PORT,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
-	{ "PHY2-CLK",	    ZL_OUT3, DPLL_PIN_TYPE_SYNCE_ETH_PORT,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
-	{ "MAC-CLK",	    ZL_OUT4, DPLL_PIN_TYPE_SYNCE_ETH_PORT,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
+	{ "PHY-CLK",	    ZL_OUT2, DPLL_PIN_TYPE_SYNCE_ETH_PORT, 0 },
+	{ "PHY2-CLK",	    ZL_OUT3, DPLL_PIN_TYPE_SYNCE_ETH_PORT, 0 },
+	{ "MAC-CLK",	    ZL_OUT4, DPLL_PIN_TYPE_SYNCE_ETH_PORT, 0 },
 	{ "CVL-SDP21",	    ZL_OUT5, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_1_hz), ice_cgu_pin_freq_1_hz },
 	{ "CVL-SDP23",	    ZL_OUT6, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_1_hz), ice_cgu_pin_freq_1_hz },
 };
 
 static const struct ice_cgu_pin_desc ice_e823_si_cgu_inputs[] = {
 	{ "NONE",	  SI_REF0P, DPLL_PIN_TYPE_UNSPEC, 0 },
 	{ "NONE",	  SI_REF0N, DPLL_PIN_TYPE_UNSPEC, 0 },
-	{ "SYNCE0_DP",	  SI_REF1P, DPLL_PIN_TYPE_MUX,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
-	{ "SYNCE0_DN",	  SI_REF1N, DPLL_PIN_TYPE_MUX,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
+	{ "SYNCE0_DP",	  SI_REF1P, DPLL_PIN_TYPE_MUX, 0 },
+	{ "SYNCE0_DN",	  SI_REF1N, DPLL_PIN_TYPE_MUX, 0 },
 	{ "EXT_CLK_SYNC", SI_REF2P, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
 	{ "NONE",	  SI_REF2N, DPLL_PIN_TYPE_UNSPEC, 0 },
 	{ "EXT_PPS_OUT",  SI_REF3,  DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
 	{ "INT_PPS_OUT",  SI_REF4,  DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
 };
 
 static const struct ice_cgu_pin_desc ice_e823_si_cgu_outputs[] = {
 	{ "1588-TIME_SYNC", SI_OUT0, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
-	{ "PHY-CLK",	    SI_OUT1, DPLL_PIN_TYPE_SYNCE_ETH_PORT,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
+	{ "PHY-CLK",	    SI_OUT1, DPLL_PIN_TYPE_SYNCE_ETH_PORT, 0 },
 	{ "10MHZ-SMA2",	    SI_OUT2, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_10_mhz), ice_cgu_pin_freq_10_mhz },
 	{ "PPS-SMA1",	    SI_OUT3, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
 };
 
 static const struct ice_cgu_pin_desc ice_e823_zl_cgu_inputs[] = {
 	{ "NONE",	  ZL_REF0P, DPLL_PIN_TYPE_UNSPEC, 0 },
 	{ "INT_PPS_OUT",  ZL_REF0N, DPLL_PIN_TYPE_EXT,
-		BIT(DPLL_PIN_FREQ_SUPP_1_HZ) },
-	{ "SYNCE0_DP",	  ZL_REF1P, DPLL_PIN_TYPE_MUX,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
-	{ "SYNCE0_DN",	  ZL_REF1N, DPLL_PIN_TYPE_MUX,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
+		ARRAY_SIZE(ice_cgu_pin_freq_1_hz), ice_cgu_pin_freq_1_hz },
+	{ "SYNCE0_DP",	  ZL_REF1P, DPLL_PIN_TYPE_MUX, 0 },
+	{ "SYNCE0_DN",	  ZL_REF1N, DPLL_PIN_TYPE_MUX, 0 },
 	{ "NONE",	  ZL_REF2P, DPLL_PIN_TYPE_UNSPEC, 0 },
 	{ "NONE",	  ZL_REF2N, DPLL_PIN_TYPE_UNSPEC, 0 },
 	{ "EXT_CLK_SYNC", ZL_REF3P, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
 	{ "NONE",	  ZL_REF3N, DPLL_PIN_TYPE_UNSPEC, 0 },
 	{ "EXT_PPS_OUT",  ZL_REF4P, DPLL_PIN_TYPE_EXT,
-		BIT(DPLL_PIN_FREQ_SUPP_1_HZ) },
-	{ "OCXO",	  ZL_REF4N, DPLL_PIN_TYPE_INT_OSCILLATOR,
-			BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
+		ARRAY_SIZE(ice_cgu_pin_freq_1_hz), ice_cgu_pin_freq_1_hz },
+	{ "OCXO",	  ZL_REF4N, DPLL_PIN_TYPE_INT_OSCILLATOR, 0 },
 };
 
 static const struct ice_cgu_pin_desc ice_e823_zl_cgu_outputs[] = {
 	{ "PPS-SMA1",	   ZL_OUT0, DPLL_PIN_TYPE_EXT,
-		BIT(DPLL_PIN_FREQ_SUPP_1_HZ) },
+		ARRAY_SIZE(ice_cgu_pin_freq_1_hz), ice_cgu_pin_freq_1_hz },
 	{ "10MHZ-SMA2",	   ZL_OUT1, DPLL_PIN_TYPE_EXT,
-		BIT(DPLL_PIN_FREQ_SUPP_10_MHZ) },
-	{ "PHY-CLK",	   ZL_OUT2, DPLL_PIN_TYPE_SYNCE_ETH_PORT,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
-	{ "1588-TIME_REF", ZL_OUT3, DPLL_PIN_TYPE_SYNCE_ETH_PORT,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
+		ARRAY_SIZE(ice_cgu_pin_freq_10_mhz), ice_cgu_pin_freq_10_mhz },
+	{ "PHY-CLK",	   ZL_OUT2, DPLL_PIN_TYPE_SYNCE_ETH_PORT, 0 },
+	{ "1588-TIME_REF", ZL_OUT3, DPLL_PIN_TYPE_SYNCE_ETH_PORT, 0 },
 	{ "CPK-TIME_SYNC", ZL_OUT4, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
 	{ "NONE",	   ZL_OUT5, DPLL_PIN_TYPE_UNSPEC, 0 },
 };
 
@@ -429,8 +419,8 @@ bool ice_is_clock_mux_present_e810t(struct ice_hw *hw);
 int ice_get_pf_c827_idx(struct ice_hw *hw, u8 *idx);
 bool ice_is_cgu_present(struct ice_hw *hw);
 enum dpll_pin_type ice_cgu_get_pin_type(struct ice_hw *hw, u8 pin, bool input);
-unsigned long
-ice_cgu_get_pin_freq_mask(struct ice_hw *hw, u8 pin, bool input);
+struct dpll_pin_frequency *
+ice_cgu_get_pin_freq_supp(struct ice_hw *hw, u8 pin, bool input, u8 *num);
 const char *ice_cgu_get_pin_name(struct ice_hw *hw, u8 pin, bool input);
 int ice_get_cgu_state(struct ice_hw *hw, u8 dpll_idx,
 		      enum ice_cgu_state last_dpll_state, u8 *pin,
Signature · 1 line
2.34.1
#53 lore raw

RE: [RFC PATCH v7 5/8] ice: implement dpll interface to control cgu

Quoted 104 lines

From: Jiri Pirko <[email protected]>
Sent: Wednesday, May 3, 2023 2:19 PM

Quoted 100 lines · Fri, Apr 28, 2023 at 02:20:06AM CEST, [email protected] wrote:

From: Arkadiusz Kubalewski <[email protected]>

Control over clock generation unit is required for further development of Synchronous Ethernet feature. Interface provides ability to obtain current state of a dpll, its sources and outputs which are pins, and allows their configuration.

---

drivers/net/ethernet/intel/Kconfig          |    1 +
drivers/net/ethernet/intel/ice/Makefile     |    3 +-
drivers/net/ethernet/intel/ice/ice.h        |    4 +
drivers/net/ethernet/intel/ice/ice_dpll.c   | 1929 +++++++++++++++++++
drivers/net/ethernet/intel/ice/ice_dpll.h   |  101 +
drivers/net/ethernet/intel/ice/ice_main.c   |    7 +
drivers/net/ethernet/intel/ice/ice_ptp_hw.c |   21 +-
drivers/net/ethernet/intel/ice/ice_ptp_hw.h |  148 +-
8 files changed, 2125 insertions(+), 89 deletions(-)  create mode

100644 drivers/net/ethernet/intel/ice/ice_dpll.c create mode 100644 drivers/net/ethernet/intel/ice/ice_dpll.h

drivers/net/ethernet/intel/Kconfig +1 -0
index 9bc0a9519899..913dcf928d15 100644
@@ -284,6 +284,7 @@ config ICE
 	select DIMLIB
 	select NET_DEVLINK
 	select PLDMFW
+	select DPLL
 	help
 	  This driver supports Intel(R) Ethernet Connection E800 Series of
 	  devices.  For more information on how to identify your adapter, go
drivers/net/ethernet/intel/ice/Makefile +2 -1
index 5d89392f969b..6c198cd92d49 100644
@@ -33,7 +33,8 @@ ice-y := ice_main.o	\
 	 ice_lag.o	\
 	 ice_ethtool.o  \
 	 ice_repr.o	\
-	 ice_tc_lib.o
+	 ice_tc_lib.o	\
+	 ice_dpll.o
 ice-$(CONFIG_PCI_IOV) +=	\
 	ice_sriov.o		\
 	ice_virtchnl.o		\
drivers/net/ethernet/intel/ice/ice.h +4 -0
index 5736757039db..a71d46e41c01 100644
@@ -74,6 +74,7 @@
 #include "ice_lag.h"
 #include "ice_vsi_vlan_ops.h"
 #include "ice_gnss.h"
+#include "ice_dpll.h"
 
 #define ICE_BAR0		0
 #define ICE_REQ_DESC_MULTIPLE	32
@@ -201,6 +202,7 @@
 enum ice_feature {
 	ICE_F_DSCP,
 	ICE_F_PTP_EXTTS,
+	ICE_F_PHY_RCLK,
 	ICE_F_SMA_CTRL,
 	ICE_F_CGU,
 	ICE_F_GNSS,
@@ -512,6 +514,7 @@ enum ice_pf_flags {
 	ICE_FLAG_UNPLUG_AUX_DEV,
 	ICE_FLAG_MTU_CHANGED,
 	ICE_FLAG_GNSS,			/* GNSS successfully initialized */
+	ICE_FLAG_DPLL,			/* SyncE/PTP dplls initialized */
 	ICE_PF_FLAGS_NBITS		/* must be last */
 };
 
@@ -635,6 +638,7 @@ struct ice_pf {
 #define ICE_VF_AGG_NODE_ID_START	65
 #define ICE_MAX_VF_AGG_NODES		32
 	struct ice_agg_node vf_agg_node[ICE_MAX_VF_AGG_NODES];
+	struct ice_dplls dplls;
 };
 
 struct ice_netdev_priv {
drivers/net/ethernet/intel/ice/ice_dpll.c new file +3 -0
new file mode 100644
index 000000000000..3217fb36dd12
@@ -0,0 +1,1929 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2022, Intel Corporation. */
+
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 8

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +5 -0
+#include "ice.h"
+#include "ice_lib.h"
+#include "ice_trace.h"
+#include <linux/dpll.h>
+#include <uapi/linux/dpll.h>

Don't include uapi directly. I'm pretty sure I had the same comment the last time as well.

Fixed, no idea how it is still there, thanks!

Quoted 49 lines
Quoted 49 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +48 -0
+
+#define ICE_CGU_STATE_ACQ_ERR_THRESHOLD	50
+#define ICE_DPLL_LOCK_TRIES		1000
+#define ICE_DPLL_PIN_IDX_INVALID	0xff
+
+/**
+ * dpll_lock_status - map ice cgu states into dpll's subsystem lock
+status  */ static const enum dpll_lock_status
+ice_dpll_status[__DPLL_LOCK_STATUS_MAX] = {
+	[ICE_CGU_STATE_INVALID] = DPLL_LOCK_STATUS_UNSPEC,
+	[ICE_CGU_STATE_FREERUN] = DPLL_LOCK_STATUS_UNLOCKED,
+	[ICE_CGU_STATE_LOCKED] = DPLL_LOCK_STATUS_CALIBRATING,
+	[ICE_CGU_STATE_LOCKED_HO_ACQ] = DPLL_LOCK_STATUS_LOCKED,
+	[ICE_CGU_STATE_HOLDOVER] = DPLL_LOCK_STATUS_HOLDOVER, };
+
+/**
+ * ice_dpll_pin_type - enumerate ice pin types  */ enum
+ice_dpll_pin_type {
+	ICE_DPLL_PIN_INVALID = 0,
+	ICE_DPLL_PIN_TYPE_SOURCE,
+	ICE_DPLL_PIN_TYPE_OUTPUT,
+	ICE_DPLL_PIN_TYPE_RCLK_SOURCE,
+};
+
+/**
+ * pin_type_name - string names of ice pin types  */ static const char
+* const pin_type_name[] = {
+	[ICE_DPLL_PIN_TYPE_SOURCE] = "source",
+	[ICE_DPLL_PIN_TYPE_OUTPUT] = "output",
+	[ICE_DPLL_PIN_TYPE_RCLK_SOURCE] = "rclk-source", };
+
+/**
+ * ice_find_pin_idx - find ice_dpll_pin index on a pf
+ * @pf: private board structure
+ * @pin: kernel's dpll_pin pointer to be searched for
+ * @pin_type: type of pins to be searched for
+ *
+ * Find and return internal ice pin index of a searched dpll subsystem
+ * pin pointer.
+ *
+ * Return:
+ * * valid index for a given pin & pin type found on pf internal dpll
+struct
+ * * ICE_DPLL_PIN_IDX_INVALID - if pin was not found.
+ */
+static u32
+ice_find_pin_idx(struct ice_pf *pf, const struct dpll_pin *pin,
+		 enum ice_dpll_pin_type pin_type)
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 66

Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +6 -0
+
+{
+	struct ice_dpll_pin *pins;
+	int pin_num, i;
+
+	if (!pin || !pf)

How this can happen? If not, remove.

Makes sense, fixed.

Quoted 28 lines
Quoted 28 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +27 -0
+		return ICE_DPLL_PIN_IDX_INVALID;
+
+	if (pin_type == ICE_DPLL_PIN_TYPE_SOURCE) {
+		pins = pf->dplls.inputs;
+		pin_num = pf->dplls.num_inputs;
+	} else if (pin_type == ICE_DPLL_PIN_TYPE_OUTPUT) {
+		pins = pf->dplls.outputs;
+		pin_num = pf->dplls.num_outputs;
+	} else {
+		return ICE_DPLL_PIN_IDX_INVALID;
+	}
+
+	for (i = 0; i < pin_num; i++)
+		if (pin == pins[i].pin)
+			return i;
+
+	return ICE_DPLL_PIN_IDX_INVALID;
+}
+
+/**
+ * ice_dpll_cb_lock - lock dplls mutex in callback context
+ * @pf: private board structure
+ *
+ * Lock the mutex from the callback operations invoked by dpll subsystem.
+ * Prevent dead lock caused by `rmmod ice` when dpll callbacks are
+under stress
+ * tests.
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +5 -0
+ *
+ * Return:
+ * 0 - if lock acquired
+ * negative - lock not acquired or dpll was deinitialized  */ static
+int ice_dpll_cb_lock(struct ice_pf *pf)

On many places you call this without saving the return value to int variable. You should do that and propagate the error value.

That is true, fixed.

Quoted 94 lines
Quoted 94 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +19 -0
+{
+	int i;
+
+	for (i = 0; i < ICE_DPLL_LOCK_TRIES; i++) {
+		if (mutex_trylock(&pf->dplls.lock))
+			return 0;
+		usleep_range(100, 150);
+		if (!test_bit(ICE_FLAG_DPLL, pf->flags))
+			return -EFAULT;
+	}
+
+	return -EBUSY;
+}
+
+/**
+ * ice_dpll_cb_unlock - unlock dplls mutex in callback context
+ * @pf: private board structure
+ *
+ * Unlock the mutex from the callback operations invoked by dpll

subsystem.
+ */

drivers/net/ethernet/intel/ice/ice_dpll.c new file +72 -0
+static void ice_dpll_cb_unlock(struct ice_pf *pf) {
+	mutex_unlock(&pf->dplls.lock);
+}
+
+/**
+ * ice_find_pin - find ice_dpll_pin on a pf
+ * @pf: private board structure
+ * @pin: kernel's dpll_pin pointer to be searched for
+ * @pin_type: type of pins to be searched for
+ *
+ * Find and return internal ice pin info pointer holding data of given
+dpll
+ * subsystem pin pointer.
+ *
+ * Return:
+ * * valid 'struct ice_dpll_pin'-type pointer - if given 'pin' pointer
+was
+ * found in pf internal pin data.
+ * * NULL - if pin was not found.
+ */
+static struct ice_dpll_pin
+*ice_find_pin(struct ice_pf *pf, const struct dpll_pin *pin,
+	      enum ice_dpll_pin_type pin_type)
+
+{
+	struct ice_dpll_pin *pins;
+	int pin_num, i;
+
+	if (!pin || !pf)
+		return NULL;
+
+	if (pin_type == ICE_DPLL_PIN_TYPE_SOURCE) {
+		pins = pf->dplls.inputs;
+		pin_num = pf->dplls.num_inputs;
+	} else if (pin_type == ICE_DPLL_PIN_TYPE_OUTPUT) {
+		pins = pf->dplls.outputs;
+		pin_num = pf->dplls.num_outputs;
+	} else if (pin_type == ICE_DPLL_PIN_TYPE_RCLK_SOURCE) {
+		if (pin == pf->dplls.rclk.pin)
+			return &pf->dplls.rclk;
+	} else {
+		return NULL;
+	}
+
+	for (i = 0; i < pin_num; i++)
+		if (pin == pins[i].pin)
+			return &pins[i];
+
+	return NULL;
+}
+
+/**
+ * ice_dpll_pin_freq_set - set pin's frequency
+ * @pf: private board structure
+ * @pin: pointer to a pin
+ * @pin_type: type of pin being configured
+ * @freq: frequency to be set
+ *
+ * Set requested frequency on a pin.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - error on AQ or wrong pin type given  */ static int
+ice_dpll_pin_freq_set(struct ice_pf *pf, struct ice_dpll_pin *pin,
+		      const enum ice_dpll_pin_type pin_type, const u32 freq) {
+	u8 flags;
+	int ret;
+
+	if (pin_type == ICE_DPLL_PIN_TYPE_SOURCE) {
+		flags = ICE_AQC_SET_CGU_IN_CFG_FLG1_UPDATE_FREQ;
+		ret = ice_aq_set_input_pin_cfg(&pf->hw, pin->idx, flags,
+					       pin->flags[0], freq, 0);
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 197

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +5 -0
+	} else if (pin_type == ICE_DPLL_PIN_TYPE_OUTPUT) {
+		flags = pin->flags[0] | ICE_AQC_SET_CGU_OUT_CFG_UPDATE_FREQ;
+		ret = ice_aq_set_output_pin_cfg(&pf->hw, pin->idx, flags,
+						0, freq, 0);
+	} else {

How exactly this can happen? If not, avoid it.
And use switch-case for enum values

Sure, fixed.

Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 202

Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +5 -0
+		ret = -EINVAL;
+	}
+
+	if (ret) {
+		dev_dbg(ice_pf_to_dev(pf),

dev_err

True, fixed.

Quoted 11 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 210

Quoted 9 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +8 -0
+			"err:%d %s failed to set pin freq:%u on pin:%u\n",
+			ret, ice_aq_str(pf->hw.adminq.sq_last_status),
+			freq, pin->idx);
+	} else {
+		pin->freq = freq;
+	}
+
+	return ret;

Usual pattern is:

Quoted 6 lines
	ret = something() //switch-case in this case
	if (ret)
		return ret;
	return 0;

Easier to follow.

Ok, fixed.

Quoted 37 lines
Quoted 21 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +20 -0
+}
+
+/**
+ * ice_dpll_frequency_set - wrapper for pin callback for set frequency
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: pointer to dpll
+ * @frequency: frequency to be set
+ * @extack: error reporting
+ * @pin_type: type of pin being configured
+ *
+ * Wraps internal set frequency command on a pin.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - error pin not found or couldn't set in hw  */ static
+int ice_dpll_frequency_set(const struct dpll_pin *pin, void *pin_priv,
+		       const struct dpll_device *dpll,
+		       const u32 frequency,
+		       struct netlink_ext_ack *extack,

drivers/net/ethernet/intel/ice/ice_dpll.c line 243

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+		       const enum ice_dpll_pin_type pin_type) {
+	struct ice_pf *pf = pin_priv;
+	struct ice_dpll_pin *p;
+	int ret = -EINVAL;
+
+	if (!pf)
+		return ret;
+	if (ice_dpll_cb_lock(pf))
+		return -EBUSY;
+	p = ice_find_pin(pf, pin, pin_type);

This does not make any sense to me. You should avoid the lookups and remove ice_find_pin() function entirely. The purpose of having pin_priv is to carry the struct ice_dpll_pin * directly. You should pass it down during pin register.

Quoted 2 lines

pf pointer is stored in dpll_priv.

In this case dpll_priv is not passed, so cannot use it. But in general it makes sense I will hold pf inside of ice_dpll_pin and fix this.

Quoted 6 lines

drivers/net/ethernet/intel/ice/ice_dpll.c

Quoted 3 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +2 -0
+	if (!p) {
+		NL_SET_ERR_MSG(extack, "pin not found");

That would be very odd message the user would see :)

Removed.

Quoted 11 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 251

Quoted 7 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +6 -0
+		goto unlock;
+	}
+
+	ret = ice_dpll_pin_freq_set(pf, p, pin_type, frequency);
+	if (ret)
+		NL_SET_ERR_MSG_FMT(extack, "freq not set, err:%d", ret);

Why you need to print "ret"? It is propagated to the caller as a return value.

Removed.

Quoted 31 lines
Quoted 18 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +17 -0
+unlock:
+	ice_dpll_cb_unlock(pf);
+
+	return ret;
+}
+
+/**
+ * ice_dpll_source_frequency_set - source pin callback for set
+frequency
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: pointer to dpll
+ * @dpll_priv: private data pointer passed on dpll registration
+ * @frequency: frequency to be set
+ * @extack: error reporting
+ *
+ * Wraps internal set frequency command on a pin.

drivers/net/ethernet/intel/ice/ice_dpll.c

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+ *
+ * Return:
+ * * 0 - success
+ * * negative - error pin not found or couldn't set in hw  */ static
+int ice_dpll_source_frequency_set(const struct dpll_pin *pin, void
+*pin_priv,
+			      const struct dpll_device *dpll, void *dpll_priv,
+			      u64 frequency, struct netlink_ext_ack *extack) {
+	return ice_dpll_frequency_set(pin, pin_priv, dpll, (u32)frequency,
+extack,

Avoid the cast here, not needed.

Quoted 2 lines

The dpll core should do check if user passes frequency which is supported, so you don't care about the overflow either.

Fixed.

Quoted 55 lines
Quoted 55 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +53 -0
+				      ICE_DPLL_PIN_TYPE_SOURCE);
+}
+
+/**
+ * ice_dpll_output_frequency_set - output pin callback for set
+frequency
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: pointer to dpll
+ * @dpll_priv: private data pointer passed on dpll registration
+ * @frequency: frequency to be set
+ * @extack: error reporting
+ *
+ * Wraps internal set frequency command on a pin.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - error pin not found or couldn't set in hw  */ static
+int ice_dpll_output_frequency_set(const struct dpll_pin *pin, void
+*pin_priv,
+			      const struct dpll_device *dpll, void *dpll_priv,
+			      u64 frequency, struct netlink_ext_ack *extack) {
+	return ice_dpll_frequency_set(pin, pin_priv, dpll, frequency, extack,
+				      ICE_DPLL_PIN_TYPE_OUTPUT);
+}
+
+/**
+ * ice_dpll_frequency_get - wrapper for pin callback for get frequency
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: pointer to dpll
+ * @dpll_priv: private data pointer passed on dpll registration
+ * @frequency: on success holds pin's frequency
+ * @extack: error reporting
+ * @pin_type: type of pin being configured
+ *
+ * Wraps internal get frequency command of a pin.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - error pin not found or couldn't get from hw  */ static
+int ice_dpll_frequency_get(const struct dpll_pin *pin, void *pin_priv,
+		       const struct dpll_device *dpll, u64 *frequency,
+		       struct netlink_ext_ack *extack,
+		       const enum ice_dpll_pin_type pin_type) {
+	struct ice_pf *pf = pin_priv;
+	struct ice_dpll_pin *p;
+	int ret = -EINVAL;
+
+	if (!pf)
+		return ret;
+	if (ice_dpll_cb_lock(pf))
+		return -EBUSY;
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 341

Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +6 -0
+	p = ice_find_pin(pf, pin, pin_type);
+	if (!p) {
+		NL_SET_ERR_MSG(extack, "pin not found");
+		goto unlock;
+	}
+	*frequency = (u64)(p->freq);

Drop the pointless cast.

Removed.

Quoted 73 lines
Quoted 73 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +72 -0
+	ret = 0;
+unlock:
+	ice_dpll_cb_unlock(pf);
+
+	return ret;
+}
+
+/**
+ * ice_dpll_source_frequency_get - source pin callback for get
+frequency
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: pointer to dpll
+ * @dpll_priv: private data pointer passed on dpll registration
+ * @frequency: on success holds pin's frequency
+ * @extack: error reporting
+ *
+ * Wraps internal get frequency command of a source pin.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - error pin not found or couldn't get from hw  */ static
+int ice_dpll_source_frequency_get(const struct dpll_pin *pin, void
+*pin_priv,
+			      const struct dpll_device *dpll, void *dpll_priv,
+			      u64 *frequency, struct netlink_ext_ack *extack) {
+	return ice_dpll_frequency_get(pin, pin_priv, dpll, frequency, extack,
+				      ICE_DPLL_PIN_TYPE_SOURCE);
+}
+
+/**
+ * ice_dpll_output_frequency_get - output pin callback for get
+frequency
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: pointer to dpll
+ * @dpll_priv: private data pointer passed on dpll registration
+ * @frequency: on success holds pin's frequency
+ * @extack: error reporting
+ *
+ * Wraps internal get frequency command of a pin.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - error pin not found or couldn't get from hw  */ static
+int ice_dpll_output_frequency_get(const struct dpll_pin *pin, void
+*pin_priv,
+			      const struct dpll_device *dpll, void *dpll_priv,
+			      u64 *frequency, struct netlink_ext_ack *extack) {
+	return ice_dpll_frequency_get(pin, pin_priv, dpll, frequency, extack,
+				      ICE_DPLL_PIN_TYPE_OUTPUT);
+}
+
+/**
+ * ice_dpll_pin_enable - enable a pin on dplls
+ * @hw: board private hw structure
+ * @pin: pointer to a pin
+ * @pin_type: type of pin being enabled
+ *
+ * Enable a pin on both dplls. Store current state in pin->flags.
+ *
+ * Return:
+ * * 0 - OK
+ * * negative - error
+ */
+static int
+ice_dpll_pin_enable(struct ice_hw *hw, struct ice_dpll_pin *pin,
+		    const enum ice_dpll_pin_type pin_type) {
+	u8 flags = pin->flags[0];
+	int ret;
+
+	if (pin_type == ICE_DPLL_PIN_TYPE_SOURCE) {
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 422

Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +6 -0
+		flags |= ICE_AQC_GET_CGU_IN_CFG_FLG2_INPUT_EN;
+		ret = ice_aq_set_input_pin_cfg(hw, pin->idx, 0, flags, 0, 0);
+	} else if (pin_type == ICE_DPLL_PIN_TYPE_OUTPUT) {
+		flags |= ICE_AQC_SET_CGU_OUT_CFG_OUT_EN;
+		ret = ice_aq_set_output_pin_cfg(hw, pin->idx, flags, 0, 0, 0);
+	}

switch-case

Fixed.

Quoted 6 lines

drivers/net/ethernet/intel/ice/ice_dpll.c

Quoted 3 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +2 -0
+	if (ret)
+		dev_dbg(ice_pf_to_dev((struct ice_pf *)(hw->back)),

dev_err?

Fixed.

Quoted 29 lines
Quoted 29 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +28 -0
+			"err:%d %s failed to enable %s pin:%u\n",
+			ret, ice_aq_str(hw->adminq.sq_last_status),
+			pin_type_name[pin_type], pin->idx);
+	else
+		pin->flags[0] = flags;
+
+	return ret;
+}
+
+/**
+ * ice_dpll_pin_disable - disable a pin on dplls
+ * @hw: board private hw structure
+ * @pin: pointer to a pin
+ * @pin_type: type of pin being disabled
+ *
+ * Disable a pin on both dplls. Store current state in pin->flags.
+ *
+ * Return:
+ * * 0 - OK
+ * * negative - error
+ */
+static int
+ice_dpll_pin_disable(struct ice_hw *hw, struct ice_dpll_pin *pin,
+		     enum ice_dpll_pin_type pin_type) {
+	u8 flags = pin->flags[0];
+	int ret;
+
+	if (pin_type == ICE_DPLL_PIN_TYPE_SOURCE) {
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 459

Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +6 -0
+		flags &= ~(ICE_AQC_GET_CGU_IN_CFG_FLG2_INPUT_EN);
+		ret = ice_aq_set_input_pin_cfg(hw, pin->idx, 0, flags, 0, 0);
+	} else if (pin_type == ICE_DPLL_PIN_TYPE_OUTPUT) {
+		flags &= ~(ICE_AQC_SET_CGU_OUT_CFG_OUT_EN);
+		ret = ice_aq_set_output_pin_cfg(hw, pin->idx, flags, 0, 0, 0);
+	}

switch-case?

Fixed.

Quoted 6 lines

drivers/net/ethernet/intel/ice/ice_dpll.c

Quoted 3 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +2 -0
+	if (ret)
+		dev_dbg(ice_pf_to_dev((struct ice_pf *)(hw->back)),

dev_err?

Fixed.

Quoted 29 lines
Quoted 29 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +28 -0
+			"err:%d %s failed to disable %s pin:%u\n",
+			ret, ice_aq_str(hw->adminq.sq_last_status),
+			pin_type_name[pin_type], pin->idx);
+	else
+		pin->flags[0] = flags;
+
+	return ret;
+}
+
+/**
+ * ice_dpll_pin_state_update - update pin's state
+ * @hw: private board struct
+ * @pin: structure with pin attributes to be updated
+ * @pin_type: type of pin being updated
+ *
+ * Determine pin current state and frequency, then update struct
+ * holding the pin info. For source pin states are separated for each
+ * dpll, for rclk pins states are separated for each parent.
+ *
+ * Return:
+ * * 0 - OK
+ * * negative - error
+ */
+int
+ice_dpll_pin_state_update(struct ice_pf *pf, struct ice_dpll_pin *pin,
+			  const enum ice_dpll_pin_type pin_type) {
+	int ret;
+
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 495

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +5 -0
+	if (pin_type == ICE_DPLL_PIN_TYPE_SOURCE) {
+		ret = ice_aq_get_input_pin_cfg(&pf->hw, pin->idx, NULL, NULL,
+					       NULL, &pin->flags[0],
+					       &pin->freq, NULL);
+		if (!!(ICE_AQC_GET_CGU_IN_CFG_FLG2_INPUT_EN & pin->flags[0])) {

Don't do "!!", it's not needed. You have this on multiple places. Please reduce.

Fixed.

Quoted 52 lines
Quoted 39 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +38 -0
+			if (pin->pin) {
+				pin->state[pf->dplls.eec.dpll_idx] =
+					pin->pin == pf->dplls.eec.active_source ?
+					DPLL_PIN_STATE_CONNECTED :
+					DPLL_PIN_STATE_SELECTABLE;
+				pin->state[pf->dplls.pps.dpll_idx] =
+					pin->pin == pf->dplls.pps.active_source ?
+					DPLL_PIN_STATE_CONNECTED :
+					DPLL_PIN_STATE_SELECTABLE;
+			} else {
+				pin->state[pf->dplls.eec.dpll_idx] =
+					DPLL_PIN_STATE_SELECTABLE;
+				pin->state[pf->dplls.pps.dpll_idx] =
+					DPLL_PIN_STATE_SELECTABLE;
+			}
+		} else {
+			pin->state[pf->dplls.eec.dpll_idx] =
+				DPLL_PIN_STATE_DISCONNECTED;
+			pin->state[pf->dplls.pps.dpll_idx] =
+				DPLL_PIN_STATE_DISCONNECTED;
+		}
+	} else if (pin_type == ICE_DPLL_PIN_TYPE_OUTPUT) {
+		ret = ice_aq_get_output_pin_cfg(&pf->hw, pin->idx,
+						&pin->flags[0], NULL,
+						&pin->freq, NULL);
+		if (!!(ICE_AQC_SET_CGU_OUT_CFG_OUT_EN & pin->flags[0]))
+			pin->state[0] = DPLL_PIN_STATE_CONNECTED;
+		else
+			pin->state[0] = DPLL_PIN_STATE_DISCONNECTED;
+	} else if (pin_type == ICE_DPLL_PIN_TYPE_RCLK_SOURCE) {
+		u8 parent, port_num = ICE_AQC_SET_PHY_REC_CLK_OUT_CURR_PORT;
+
+		for (parent = 0; parent < pf->dplls.rclk.num_parents;
+		     parent++) {
+			ret = ice_aq_get_phy_rec_clk_out(&pf->hw, parent,
+							 &port_num,
+							 &pin->flags[parent],
+							 &pin->freq);

drivers/net/ethernet/intel/ice/ice_dpll.c line 543

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+			if (ret)
+				return ret;
+			if (!!(ICE_AQC_GET_PHY_REC_CLK_OUT_OUT_EN &
+			       pin->flags[parent]))
+				pin->state[parent] = DPLL_PIN_STATE_CONNECTED;
+			else
+				pin->state[parent] =
+					DPLL_PIN_STATE_DISCONNECTED;
+		}
+	}

Perhaps:

Quoted 7 lines
	switch (pin_type) {
	case ICE_DPLL_PIN_TYPE_SOURCE:
		..
	case ICE_DPLL_PIN_TYPE_OUTPUT:
		..

?

Fixed.

Quoted 38 lines
Quoted 38 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +37 -0
+
+	return ret;
+}
+
+/**
+ * ice_find_dpll - find ice_dpll on a pf
+ * @pf: private board structure
+ * @dpll: kernel's dpll_device pointer to be searched
+ *
+ * Return:
+ * * pointer if ice_dpll with given device dpll pointer is found
+ * * NULL if not found
+ */
+static struct ice_dpll
+*ice_find_dpll(struct ice_pf *pf, const struct dpll_device *dpll) {
+	if (!pf || !dpll)
+		return NULL;
+
+	return dpll == pf->dplls.eec.dpll ? &pf->dplls.eec :
+	       dpll == pf->dplls.pps.dpll ? &pf->dplls.pps : NULL; }
+
+/**
+ * ice_dpll_hw_source_prio_set - set source priority value in hardware
+ * @pf: board private structure
+ * @dpll: ice dpll pointer
+ * @pin: ice pin pointer
+ * @prio: priority value being set on a dpll
+ *
+ * Internal wrapper for setting the priority in the hardware.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - failure
+ */
+static int
+ice_dpll_hw_source_prio_set(struct ice_pf *pf, struct ice_dpll *dpll,
+			    struct ice_dpll_pin *pin, const u32 prio) {
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 589

Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +6 -0
+	int ret;
+
+	ret = ice_aq_set_cgu_ref_prio(&pf->hw, dpll->dpll_idx, pin->idx,
+				      (u8)prio);
+	if (ret)
+		dev_dbg(ice_pf_to_dev(pf),

dev_err

Fixed.

Quoted 29 lines
Quoted 29 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +21 -0
+			"err:%d %s failed to set pin prio:%u on pin:%u\n",
+			ret, ice_aq_str(pf->hw.adminq.sq_last_status),
+			prio, pin->idx);
+	else
+		dpll->input_prio[pin->idx] = prio;
+
+	return ret;
+}
+
+/**
+ * ice_dpll_lock_status_get - get dpll lock status callback
+ * @dpll: registered dpll pointer
+ * @status: on success holds dpll's lock status
+ *
+ * Dpll subsystem callback, provides dpll's lock status.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - failure
+ */
+static int ice_dpll_lock_status_get(const struct dpll_device *dpll, void

*priv,

drivers/net/ethernet/intel/ice/ice_dpll.c new file +6 -0
+				    enum dpll_lock_status *status,
+				    struct netlink_ext_ack *extack) {
+	struct ice_pf *pf = priv;
+	struct ice_dpll *d;
+
+	if (!pf)
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 621

Quoted 4 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +4 -0
+		return -EINVAL;
+	if (ice_dpll_cb_lock(pf))
+		return -EBUSY;
+	d = ice_find_dpll(pf, dpll);

Another example of odd and unneeded lookup. Register dpll device with struct ice_dpll *d as a priv. Store pf pointer there in struct ice_dpll. And remove ice_find_dpll() entirely.

Fixed.

Quoted 93 lines
Quoted 93 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +57 -0
+	if (!d)
+		return -EFAULT;
+	dev_dbg(ice_pf_to_dev(pf), "%s: dpll:%p, pf:%p\n", __func__, dpll, pf);
+	*status = ice_dpll_status[d->dpll_state];
+	ice_dpll_cb_unlock(pf);
+
+	return 0;
+}
+
+/**
+ * ice_dpll_mode_get - get dpll's working mode
+ * @dpll: registered dpll pointer
+ * @priv: private data pointer passed on dpll registration
+ * @mode: on success holds current working mode of dpll
+ * @extack: error reporting
+ *
+ * Dpll subsystem callback. Provides working mode of dpll.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - failure
+ */
+static int ice_dpll_mode_get(const struct dpll_device *dpll, void *priv,
+			     enum dpll_mode *mode,
+			     struct netlink_ext_ack *extack) {
+	struct ice_pf *pf = priv;
+	struct ice_dpll *d;
+
+	if (!pf)
+		return -EINVAL;
+	if (ice_dpll_cb_lock(pf))
+		return -EBUSY;
+	d = ice_find_dpll(pf, dpll);
+	ice_dpll_cb_unlock(pf);
+	if (!d)
+		return -EFAULT;
+	*mode = DPLL_MODE_AUTOMATIC;
+
+	return 0;
+}
+
+/**
+ * ice_dpll_mode_get - check if dpll's working mode is supported
+ * @dpll: registered dpll pointer
+ * @priv: private data pointer passed on dpll registration
+ * @mode: mode to be checked for support
+ * @extack: error reporting
+ *
+ * Dpll subsystem callback. Provides information if working mode is
+supported
+ * by dpll.
+ *
+ * Return:
+ * * true - mode is supported
+ * * false - mode is not supported
+ */
+static bool ice_dpll_mode_supported(const struct dpll_device *dpll, void

*priv,

drivers/net/ethernet/intel/ice/ice_dpll.c new file +33 -0
+				    const enum dpll_mode mode,
+				    struct netlink_ext_ack *extack) {
+	struct ice_pf *pf = priv;
+	struct ice_dpll *d;
+
+	if (!pf)
+		return false;
+
+	if (ice_dpll_cb_lock(pf))
+		return false;
+	d = ice_find_dpll(pf, dpll);
+	ice_dpll_cb_unlock(pf);
+	if (!d)
+		return false;
+	if (mode == DPLL_MODE_AUTOMATIC)
+		return true;
+
+	return false;
+}
+
+/**
+ * ice_dpll_pin_state_set - set pin's state on dpll
+ * @dpll: dpll being configured
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @state: state of pin to be set
+ * @extack: error reporting
+ * @pin_type: type of a pin
+ *
+ * Set pin state on a pin.
+ *
+ * Return:
+ * * 0 - OK or no change required
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 718

Quoted 6 lines

+ * * negative - error
+ */

drivers/net/ethernet/intel/ice/ice_dpll.c new file +4 -0
+static int
+ice_dpll_pin_state_set(const struct dpll_device *dpll,
+		       const struct dpll_pin *pin, void *pin_priv,
+		       const enum dpll_pin_state state,

Why you use const with enums?

Just show usage intention explicitly.

Quoted 27 lines
Quoted 14 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +13 -0
+		       struct netlink_ext_ack *extack,
+		       const enum ice_dpll_pin_type pin_type) {
+	struct ice_pf *pf = pin_priv;
+	struct ice_dpll_pin *p;
+	int ret = -EINVAL;
+
+	if (!pf)
+		return ret;
+	if (ice_dpll_cb_lock(pf))
+		return -EBUSY;
+	p = ice_find_pin(pf, pin, pin_type);
+	if (!p)
+		goto unlock;

drivers/net/ethernet/intel/ice/ice_dpll.c line 742

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+	if (pin_type == ICE_DPLL_PIN_TYPE_SOURCE) {
+		if (state == DPLL_PIN_STATE_SELECTABLE)
+			ret = ice_dpll_pin_enable(&pf->hw, p, pin_type);
+		else if (state == DPLL_PIN_STATE_DISCONNECTED)
+			ret = ice_dpll_pin_disable(&pf->hw, p, pin_type);
+	} else if (pin_type == ICE_DPLL_PIN_TYPE_OUTPUT) {
+		if (state == DPLL_PIN_STATE_CONNECTED)
+			ret = ice_dpll_pin_enable(&pf->hw, p, pin_type);
+		else if (state == DPLL_PIN_STATE_DISCONNECTED)
+			ret = ice_dpll_pin_disable(&pf->hw, p, pin_type);

switch-case?

Quoted 3 lines

Perhaps it would be nicer to do this in ice_dpll_output_state_set() and ice_dpll_source_state_set() directly?

Sure makes sense, fixed.

Quoted 10 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 748

Quoted 7 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +6 -0
+	}
+	if (!ret)
+		ret = ice_dpll_pin_state_update(pf, p, pin_type);
+unlock:
+	ice_dpll_cb_unlock(pf);
+	dev_dbg(ice_pf_to_dev(pf),

dev_err in case ret != 0 ?

Fixed.

Quoted 258 lines
Quoted 258 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +180 -0
+		"%s: dpll:%p, pin:%p, p:%p pf:%p state: %d ret:%d\n",
+		__func__, dpll, pin, p, pf, state, ret);
+
+	return ret;
+}
+
+/**
+ * ice_dpll_output_state_set - enable/disable output pin on dpll
+device
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: dpll being configured
+ * @dpll_priv: private data pointer passed on dpll registration
+ * @state: state of pin to be set
+ * @extack: error reporting
+ *
+ * Dpll subsystem callback. Set given state on output type pin.
+ *
+ * Return:
+ * * 0 - successfully enabled mode
+ * * negative - failed to enable mode
+ */
+static int ice_dpll_output_state_set(const struct dpll_pin *pin,
+				     void *pin_priv,
+				     const struct dpll_device *dpll,
+				     void *dpll_priv,
+				     const enum dpll_pin_state state,
+				     struct netlink_ext_ack *extack) {
+	return ice_dpll_pin_state_set(dpll, pin, pin_priv, state, extack,
+				      ICE_DPLL_PIN_TYPE_OUTPUT);
+}
+
+/**
+ * ice_dpll_source_state_set - enable/disable source pin on dpll
+levice
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: dpll being configured
+ * @dpll_priv: private data pointer passed on dpll registration
+ * @state: state of pin to be set
+ * @extack: error reporting
+ *
+ * Dpll subsystem callback. Enables given mode on source type pin.
+ *
+ * Return:
+ * * 0 - successfully enabled mode
+ * * negative - failed to enable mode
+ */
+static int ice_dpll_source_state_set(const struct dpll_pin *pin,
+				     void *pin_priv,
+				     const struct dpll_device *dpll,
+				     void *dpll_priv,
+				     const enum dpll_pin_state state,
+				     struct netlink_ext_ack *extack) {
+	return ice_dpll_pin_state_set(dpll, pin, pin_priv, state, extack,
+				      ICE_DPLL_PIN_TYPE_SOURCE);
+}
+
+/**
+ * ice_dpll_pin_state_get - set pin's state on dpll
+ * @dpll: registered dpll pointer
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @state: on success holds state of the pin
+ * @extack: error reporting
+ * @pin_type: type of questioned pin
+ *
+ * Determine pin state set it on a pin.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - failed to get state
+ */
+static int
+ice_dpll_pin_state_get(const struct dpll_device *dpll,
+		       const struct dpll_pin *pin, void *pin_priv,
+		       enum dpll_pin_state *state,
+		       struct netlink_ext_ack *extack,
+		       const enum ice_dpll_pin_type pin_type) {
+	struct ice_pf *pf = pin_priv;
+	struct ice_dpll_pin *p;
+	struct ice_dpll *d;
+	int ret = -EINVAL;
+
+	if (!pf)
+		return ret;
+
+	if (ice_dpll_cb_lock(pf))
+		return -EBUSY;
+	p = ice_find_pin(pf, pin, pin_type);
+	if (!p) {
+		NL_SET_ERR_MSG(extack, "pin not found");
+		goto unlock;
+	}
+	d = ice_find_dpll(pf, dpll);
+	if (!d)
+		goto unlock;
+	ret = ice_dpll_pin_state_update(pf, p, pin_type);
+	if (ret)
+		goto unlock;
+	if (pin_type == ICE_DPLL_PIN_TYPE_SOURCE)
+		*state = p->state[d->dpll_idx];
+	else if (pin_type == ICE_DPLL_PIN_TYPE_OUTPUT)
+		*state = p->state[0];
+	ret = 0;
+unlock:
+	ice_dpll_cb_unlock(pf);
+	dev_dbg(ice_pf_to_dev(pf),
+		"%s: dpll:%p, pin:%p, pf:%p state: %d ret:%d\n",
+		__func__, dpll, pin, pf, *state, ret);
+
+	return ret;
+}
+
+/**
+ * ice_dpll_output_state_get - get output pin state on dpll device
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: registered dpll pointer
+ * @dpll_priv: private data pointer passed on dpll registration
+ * @state: on success holds state of the pin
+ * @extack: error reporting
+ *
+ * Dpll subsystem callback. Check state of a pin.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - failed to get state
+ */
+static int ice_dpll_output_state_get(const struct dpll_pin *pin,
+				     void *pin_priv,
+				     const struct dpll_device *dpll,
+				     void *dpll_priv,
+				     enum dpll_pin_state *state,
+				     struct netlink_ext_ack *extack) {
+	return ice_dpll_pin_state_get(dpll, pin, pin_priv, state, extack,
+				      ICE_DPLL_PIN_TYPE_OUTPUT);
+}
+
+/**
+ * ice_dpll_source_state_get - get source pin state on dpll device
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: registered dpll pointer
+ * @dpll_priv: private data pointer passed on dpll registration
+ * @state: on success holds state of the pin
+ * @extack: error reporting
+ *
+ * Dpll subsystem callback. Check state of a source pin.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - failed to get state
+ */
+static int ice_dpll_source_state_get(const struct dpll_pin *pin,
+				     void *pin_priv,
+				     const struct dpll_device *dpll,
+				     void *dpll_priv,
+				     enum dpll_pin_state *state,
+				     struct netlink_ext_ack *extack) {
+	return ice_dpll_pin_state_get(dpll, pin, pin_priv, state, extack,
+				      ICE_DPLL_PIN_TYPE_SOURCE);
+}
+
+/**
+ * ice_dpll_source_prio_get - get dpll's source prio
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: registered dpll pointer
+ * @dpll_priv: private data pointer passed on dpll registration
+ * @prio: on success - returns source priority on dpll
+ * @extack: error reporting
+ *
+ * Dpll subsystem callback. Handler for getting priority of a source pin.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - failure
+ */
+static int ice_dpll_source_prio_get(const struct dpll_pin *pin, void

*pin_priv,

drivers/net/ethernet/intel/ice/ice_dpll.c new file +49 -0
+				    const struct dpll_device *dpll,
+				    void *dpll_priv, u32 *prio,
+				    struct netlink_ext_ack *extack) {
+	struct ice_pf *pf = pin_priv;
+	struct ice_dpll *d = NULL;
+	struct ice_dpll_pin *p;
+	int ret = -EINVAL;
+
+	if (!pf)
+		return ret;
+
+	if (ice_dpll_cb_lock(pf))
+		return -EBUSY;
+	p = ice_find_pin(pf, pin, ICE_DPLL_PIN_TYPE_SOURCE);
+	if (!p) {
+		NL_SET_ERR_MSG(extack, "pin not found");
+		goto unlock;
+	}
+	d = ice_find_dpll(pf, dpll);
+	if (!d) {
+		NL_SET_ERR_MSG(extack, "dpll not found");
+		goto unlock;
+	}
+	*prio = d->input_prio[p->idx];
+	ret = 0;
+unlock:
+	ice_dpll_cb_unlock(pf);
+	dev_dbg(ice_pf_to_dev(pf), "%s: dpll:%p, pin:%p, pf:%p ret:%d\n",
+		__func__, dpll, pin, pf, ret);
+
+	return ret;
+}
+
+/**
+ * ice_dpll_source_prio_set - set dpll source prio
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: registered dpll pointer
+ * @dpll_priv: private data pointer passed on dpll registration
+ * @prio: source priority to be set on dpll
+ * @extack: error reporting
+ *
+ * Dpll subsystem callback. Handler for setting priority of a source pin.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - failure
+ */
+static int ice_dpll_source_prio_set(const struct dpll_pin *pin, void

*pin_priv,

drivers/net/ethernet/intel/ice/ice_dpll.c new file +26 -0
+				    const struct dpll_device *dpll,
+				    void *dpll_priv, u32 prio,
+				    struct netlink_ext_ack *extack) {
+	struct ice_pf *pf = pin_priv;
+	struct ice_dpll *d = NULL;
+	struct ice_dpll_pin *p;
+	int ret = -EINVAL;
+
+	if (!pf)
+		return ret;
+
+	if (prio > ICE_DPLL_PRIO_MAX) {
+		NL_SET_ERR_MSG(extack, "prio out of range");
+		return ret;
+	}
+
+	if (ice_dpll_cb_lock(pf))
+		return -EBUSY;
+	p = ice_find_pin(pf, pin, ICE_DPLL_PIN_TYPE_SOURCE);
+	if (!p) {
+		NL_SET_ERR_MSG(extack, "pin not found");
+		goto unlock;
+	}
+	d = ice_find_dpll(pf, dpll);
+	if (!d) {
+		NL_SET_ERR_MSG(extack, "dpll not found");
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1013

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +5 -0
+		goto unlock;
+	}
+	ret = ice_dpll_hw_source_prio_set(pf, d, p, prio);
+	if (ret)
+		NL_SET_ERR_MSG_FMT(extack, "unable to set prio: %d", ret);

Why you need to print "ret"? It is propagated to the caller as a return value.

Fixed.

Quoted 94 lines
Quoted 94 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +93 -0
+unlock:
+	ice_dpll_cb_unlock(pf);
+	dev_dbg(ice_pf_to_dev(pf), "%s: dpll:%p, pin:%p, pf:%p ret:%d\n",
+		__func__, dpll, pin, pf, ret);
+
+	return ret;
+}
+
+/**
+ * ice_dpll_source_direction - callback for get source pin direction
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: registered dpll pointer
+ * @dpll_priv: private data pointer passed on dpll registration
+ * @direction: holds source pin direction
+ * @extack: error reporting
+ *
+ * Dpll subsystem callback. Handler for getting direction of a source pin.
+ *
+ * Return:
+ * * 0 - success
+ */
+static int ice_dpll_source_direction(const struct dpll_pin *pin,
+				     void *pin_priv,
+				     const struct dpll_device *dpll,
+				     void *dpll_priv,
+				     enum dpll_pin_direction *direction,
+				     struct netlink_ext_ack *extack) {
+	*direction = DPLL_PIN_DIRECTION_SOURCE;
+
+	return 0;
+}
+
+/**
+ * ice_dpll_source_direction - callback for get output pin direction
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: registered dpll pointer
+ * @dpll_priv: private data pointer passed on dpll registration
+ * @direction: holds output pin direction
+ * @extack: error reporting
+ *
+ * Dpll subsystem callback. Handler for getting direction of an output pin.
+ *
+ * Return:
+ * * 0 - success
+ */
+static int ice_dpll_output_direction(const struct dpll_pin *pin,
+				     void *pin_priv,
+				     const struct dpll_device *dpll,
+				     void *dpll_priv,
+				     enum dpll_pin_direction *direction,
+				     struct netlink_ext_ack *extack) {
+	*direction = DPLL_PIN_DIRECTION_OUTPUT;
+
+	return 0;
+}
+
+/**
+ * ice_dpll_rclk_state_on_pin_set - set a state on rclk pin
+ * @dpll: registered dpll pointer
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @parent_pin: pin parent pointer
+ * @state: state to be set on pin
+ * @extack: error reporting
+ *
+ * Dpll subsystem callback, set a state of a rclk pin on a parent pin
+ *
+ * Return:
+ * * 0 - success
+ * * negative - failure
+ */
+static int ice_dpll_rclk_state_on_pin_set(const struct dpll_pin *pin,
+					  void *pin_priv,
+					  const struct dpll_pin *parent_pin,
+					  const enum dpll_pin_state state,
+					  struct netlink_ext_ack *extack) {
+	bool enable = state == DPLL_PIN_STATE_CONNECTED ? true : false;
+	u32 parent_idx, hw_idx = ICE_DPLL_PIN_IDX_INVALID, i;
+	struct ice_pf *pf = pin_priv;
+	struct ice_dpll_pin *p;
+	int ret = -EINVAL;
+
+	if (!pf)
+		return ret;
+	if (ice_dpll_cb_lock(pf))
+		return -EBUSY;
+	p = ice_find_pin(pf, pin, ICE_DPLL_PIN_TYPE_RCLK_SOURCE);
+	if (!p) {
+		ret = -EFAULT;
+		goto unlock;
+	}
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c

Quoted 2 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +2 -0
+	parent_idx = ice_find_pin_idx(pf, parent_pin,
+				      ICE_DPLL_PIN_TYPE_SOURCE);

Again, this does not make sense. You need struct ice_dpll_pin * related to parent. That should be parent priv and passed to dpll subsystem during registration and put as an "void * parent_pin_priv" arg to .state_on_pin_set() op. Whenever you do lookup like this, it is most usually wrong.

Fixed.

Quoted 12 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1117

Quoted 8 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +6 -0
+	if (parent_idx == ICE_DPLL_PIN_IDX_INVALID) {
+		ret = -EFAULT;
+		goto unlock;
+	}
+	for (i = 0; i < pf->dplls.rclk.num_parents; i++)
+		if (pf->dplls.rclk.parent_idx[i] == parent_idx)

Can't you just store idx in struct ice_dpll_pin to avoid lookups like this one?

Fixed.

Quoted 31 lines
Quoted 31 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +30 -0
+			hw_idx = i;
+	if (hw_idx == ICE_DPLL_PIN_IDX_INVALID)
+		goto unlock;
+
+	if ((enable && !!(p->flags[hw_idx] &
+			 ICE_AQC_GET_PHY_REC_CLK_OUT_OUT_EN)) ||
+	    (!enable && !(p->flags[hw_idx] &
+			  ICE_AQC_GET_PHY_REC_CLK_OUT_OUT_EN))) {
+		ret = -EINVAL;
+		goto unlock;
+	}
+	ret = ice_aq_set_phy_rec_clk_out(&pf->hw, hw_idx, enable,
+					 &p->freq);
+unlock:
+	ice_dpll_cb_unlock(pf);
+	dev_dbg(ice_pf_to_dev(pf), "%s: parent:%p, pin:%p, pf:%p ret:%d\n",
+		__func__, parent_pin, pin, pf, ret);
+
+	return ret;
+}
+
+/**
+ * ice_dpll_rclk_state_on_pin_get - get a state of rclk pin
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @parent_pin: pin parent pointer
+ * @state: on success holds pin state on parent pin
+ * @extack: error reporting
+ *
+ * dpll subsystem callback, get a state of a recovered clock pin.
Quoted 9 lines
Quoted 4 lines

+ *
+ * Return:
+ * * 0 - success
+ * * negative - failure

I wonder how valuable this return values table is for a reader. Not much I suppose. Do you need it in comments to all the functions you have here?

0 is success - most impoertant. I will leave those as is.

Quoted 11 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1160

Quoted 9 lines

+ */

drivers/net/ethernet/intel/ice/ice_dpll.c new file +7 -0
+static int ice_dpll_rclk_state_on_pin_get(const struct dpll_pin *pin,
+					  void *pin_priv,
+					  const struct dpll_pin *parent_pin,
+					  enum dpll_pin_state *state,
+					  struct netlink_ext_ack *extack) {
+	struct ice_pf *pf = pin_priv;
+	u32 parent_idx, hw_idx = ICE_DPLL_PIN_IDX_INVALID, i;

Reverse christmas tree ordering please.

Fixed.

Quoted 10 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1164

Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +4 -0
+	struct ice_dpll_pin *p;
+	int ret = -EFAULT;
+
+	if (!pf)

How exacly this can happen. My wild guess is it can't. Don't do such pointless checks please, confuses the reader.

From driver perspective the pf pointer value is given by external entity, why shouldn't it be valdiated?

Quoted 17 lines
Quoted 17 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +16 -0
+		return ret;
+	if (ice_dpll_cb_lock(pf))
+		return -EBUSY;
+	p = ice_find_pin(pf, pin, ICE_DPLL_PIN_TYPE_RCLK_SOURCE);
+	if (!p)
+		goto unlock;
+	parent_idx = ice_find_pin_idx(pf, parent_pin,
+				      ICE_DPLL_PIN_TYPE_SOURCE);
+	if (parent_idx == ICE_DPLL_PIN_IDX_INVALID)
+		goto unlock;
+	for (i = 0; i < pf->dplls.rclk.num_parents; i++)
+		if (pf->dplls.rclk.parent_idx[i] == parent_idx)
+			hw_idx = i;
+	if (hw_idx == ICE_DPLL_PIN_IDX_INVALID)
+		goto unlock;
+
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1186

Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +6 -0
+	ret = ice_dpll_pin_state_update(pf, p, ICE_DPLL_PIN_TYPE_RCLK_SOURCE);
+	if (ret)
+		goto unlock;
+
+	if (!!(p->flags[hw_idx] &
+	    ICE_AQC_GET_PHY_REC_CLK_OUT_OUT_EN))

Avoid needless "!!".

Fixed.

Quoted 7 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1189

Quoted 4 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +3 -0
+		*state = DPLL_PIN_STATE_CONNECTED;
+	else
+		*state = DPLL_PIN_STATE_DISCONNECTED;

Use ternary operator perhaps?

Fixed.

Quoted 14 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1199

Quoted 11 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+	ret = 0;
+unlock:
+	ice_dpll_cb_unlock(pf);
+	dev_dbg(ice_pf_to_dev(pf), "%s: parent:%p, pin:%p, pf:%p ret:%d\n",
+		__func__, parent_pin, pin, pf, ret);
+
+	return ret;
+}
+
+static struct dpll_pin_ops ice_dpll_rclk_ops = {

const.

Fixed.

Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1205

Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +5 -0
+	.state_on_pin_set = ice_dpll_rclk_state_on_pin_set,
+	.state_on_pin_get = ice_dpll_rclk_state_on_pin_get,
+	.direction_get = ice_dpll_source_direction, };
+
+static struct dpll_pin_ops ice_dpll_source_ops = {

const.

Fixed.

Quoted 13 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1215

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +9 -0
+	.frequency_get = ice_dpll_source_frequency_get,
+	.frequency_set = ice_dpll_source_frequency_set,
+	.state_on_dpll_get = ice_dpll_source_state_get,
+	.state_on_dpll_set = ice_dpll_source_state_set,
+	.prio_get = ice_dpll_source_prio_get,
+	.prio_set = ice_dpll_source_prio_set,
+	.direction_get = ice_dpll_source_direction, };
+
+static struct dpll_pin_ops ice_dpll_output_ops = {

const.

Fixed.

Quoted 10 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1223

Quoted 7 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +7 -0
+	.frequency_get = ice_dpll_output_frequency_get,
+	.frequency_set = ice_dpll_output_frequency_set,
+	.state_on_dpll_get = ice_dpll_output_state_get,
+	.state_on_dpll_set = ice_dpll_output_state_set,
+	.direction_get = ice_dpll_output_direction, };
+
+static struct dpll_device_ops ice_dpll_ops = {

const.

Fixed.

Quoted 99 lines
Quoted 99 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +84 -0
+	.lock_status_get = ice_dpll_lock_status_get,
+	.mode_get = ice_dpll_mode_get,
+	.mode_supported = ice_dpll_mode_supported, };
+
+/**
+ * ice_dpll_release_info - release memory allocated for pins
+ * @pf: board private structure
+ *
+ * Release memory allocated for pins by ice_dpll_init_info function.
+ */
+static void ice_dpll_release_info(struct ice_pf *pf) {
+	kfree(pf->dplls.inputs);
+	pf->dplls.inputs = NULL;
+	kfree(pf->dplls.outputs);
+	pf->dplls.outputs = NULL;
+	kfree(pf->dplls.eec.input_prio);
+	pf->dplls.eec.input_prio = NULL;
+	kfree(pf->dplls.pps.input_prio);
+	pf->dplls.pps.input_prio = NULL;
+}
+
+/**
+ * ice_dpll_release_rclk_pin - release rclk pin from its parents
+ * @pf: board private structure
+ *
+ * Deregister from parent pins and release resources in dpll subsystem.
+ */
+static void
+ice_dpll_release_rclk_pin(struct ice_pf *pf) {
+	struct ice_dpll_pin *rclk = &pf->dplls.rclk;
+	struct dpll_pin *parent;
+	int i;
+
+	for (i = 0; i < rclk->num_parents; i++) {
+		parent = pf->dplls.inputs[rclk->parent_idx[i]].pin;
+		if (!parent)
+			continue;
+		dpll_pin_on_pin_unregister(parent, rclk->pin,
+					   &ice_dpll_rclk_ops, pf);
+	}
+	dpll_pin_put(rclk->pin);
+	rclk->pin = NULL;
+}
+
+/**
+ * ice_dpll_release_pins - release pin's from dplls registered in
+subsystem
+ * @pf: board private structure
+ * @dpll_eec: dpll_eec dpll pointer
+ * @dpll_pps: dpll_pps dpll pointer
+ * @pins: pointer to pins array
+ * @count: number of pins
+ * @ops: callback ops registered with the pins
+ * @cgu: if cgu is present and controlled by this NIC
+ *
+ * Deregister and free pins of a given array of pins from dpll devices
+ * registered in dpll subsystem.
+ */
+static void
+ice_dpll_release_pins(struct ice_pf *pf, struct dpll_device *dpll_eec,
+		      struct dpll_device *dpll_pps, struct ice_dpll_pin *pins,
+		      int count, struct dpll_pin_ops *ops, bool cgu) {
+	int i;
+
+	for (i = 0; i < count; i++) {
+		struct ice_dpll_pin *p = &pins[i];
+
+		if (p && !IS_ERR_OR_NULL(p->pin)) {
+			if (cgu && dpll_eec)
+				dpll_pin_unregister(dpll_eec, p->pin, ops, pf);
+			if (cgu && dpll_pps)
+				dpll_pin_unregister(dpll_pps, p->pin, ops, pf);
+			dpll_pin_put(p->pin);
+			p->pin = NULL;
+		}
+	}
+}
+
+/**
+ * ice_dpll_register_pins - register pins with a dpll
+ * @pf: board private structure
+ * @cgu: if cgu is present and controlled by this NIC
+ *
+ * Register source or output pins within given DPLL in a Linux dpll

subsystem.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - error
+ */

drivers/net/ethernet/intel/ice/ice_dpll.c new file +8 -0
+static int ice_dpll_register_pins(struct ice_pf *pf, bool cgu) {
+	struct device *dev = ice_pf_to_dev(pf);
+	struct ice_dpll_pin *pins;
+	struct dpll_pin_ops *ops;
+	u32 rclk_idx;
+	int ret, i;
+
+	ops = &ice_dpll_source_ops;
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1329

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +5 -0
+	pins = pf->dplls.inputs;
+	for (i = 0; i < pf->dplls.num_inputs; i++) {
+		pins[i].pin = dpll_pin_get(pf->dplls.clock_id, i,
+					   THIS_MODULE, &pins[i].prop);
+		if (IS_ERR_OR_NULL(pins[i].pin)) {

How exactly dpll_pin_get() can return NULL? It can't, use IS_ERR. Same in ice_dpll_release_pins() and two occurances below.

Fixed.

Quoted 11 lines
Quoted 11 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +9 -0
+			pins[i].pin = NULL;
+			return -ENOMEM;
+		}
+		if (cgu) {
+			ret = dpll_pin_register(pf->dplls.eec.dpll,
+						pins[i].pin,
+						ops, pf, NULL);
+			if (ret)
+				return ret;
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1343

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +5 -0
+			ret = dpll_pin_register(pf->dplls.pps.dpll,
+						pins[i].pin,
+						ops, pf, NULL);
+			if (ret)
+				return ret;

You have to call dpll_pin_unregister(pf->dplls.eec.dpll, pins[i].pin, ..) here.

No, in case of error, the caller releases everything ice_dpll_release_all(..).

Quoted 15 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1355

Quoted 13 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +12 -0
+		}
+	}
+	if (cgu) {
+		ops = &ice_dpll_output_ops;
+		pins = pf->dplls.outputs;
+		for (i = 0; i < pf->dplls.num_outputs; i++) {
+			pins[i].pin = dpll_pin_get(pf->dplls.clock_id,
+						   i + pf->dplls.num_inputs,
+						   THIS_MODULE, &pins[i].prop);
+			if (IS_ERR_OR_NULL(pins[i].pin)) {
+				pins[i].pin = NULL;
+				return -ENOMEM;

Don't make up error values when you get them from the function you call:

Quoted 1 line
	return PTR_ERR(pins[i].pin);

Fixed.

Quoted 14 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1364

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +9 -0
+			}
+			ret = dpll_pin_register(pf->dplls.eec.dpll, pins[i].pin,
+						ops, pf, NULL);
+			if (ret)
+				return ret;
+			ret = dpll_pin_register(pf->dplls.pps.dpll, pins[i].pin,
+						ops, pf, NULL);
+			if (ret)
+				return ret;

You have to call dpll_pin_unregister(pf->dplls.eec.dpll, pins[i].pin, ..) here.

As above, in case of error, the caller releases everything.

Quoted 15 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1372

Quoted 13 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +4 -0
+                                              ops, pf, NULL);
 
 
+		}
+	}
+	rclk_idx = pf->dplls.num_inputs + pf->dplls.num_outputs + pf-

hw.pf_id;

drivers/net/ethernet/intel/ice/ice_dpll.c new file +5 -0
+	pf->dplls.rclk.pin = dpll_pin_get(pf->dplls.clock_id, rclk_idx,
+					  THIS_MODULE, &pf->dplls.rclk.prop);
+	if (IS_ERR_OR_NULL(pf->dplls.rclk.pin)) {
+		pf->dplls.rclk.pin = NULL;
+		return -ENOMEM;

Don't make up error values when you get them from the function you call:

Quoted 2 lines
	return PTR_ERR(pf->dplls.rclk.pin);

Fixed.

Quoted 31 lines
Quoted 18 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +17 -0
+	}
+	ops = &ice_dpll_rclk_ops;
+	for (i = 0; i < pf->dplls.rclk.num_parents; i++) {
+		struct dpll_pin *parent =
+			pf->dplls.inputs[pf->dplls.rclk.parent_idx[i]].pin;
+
+		ret = dpll_pin_on_pin_register(parent, pf->dplls.rclk.pin,
+					       ops, pf, dev);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+/**
+ * ice_generate_clock_id - generates unique clock_id for registering dpll.

drivers/net/ethernet/intel/ice/ice_dpll.c line 1399

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+ * @pf: board private structure
+ * @clock_id: holds generated clock_id
+ *
+ * Generates unique (per board) clock_id for allocation and search of
+dpll
+ * devices in Linux dpll subsystem.
+ */
+static void ice_generate_clock_id(struct ice_pf *pf, u64 *clock_id) {
+	*clock_id = pci_get_dsn(pf->pdev);
+}

How about:

Quoted 6 lines
static u64 ice_generate_clock_id(struct ice_pf *pf) {
	return pci_get_dsn(pf->pdev);
}

??

Fixed.

Quoted 19 lines
Quoted 19 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +18 -0
+
+/**
+ * ice_dpll_init_dplls
+ * @pf: board private structure
+ * @cgu: if cgu is present and controlled by this NIC
+ *
+ * Get dplls instances for this board, if cgu is controlled by this
+NIC,
+ * register dpll with callbacks ops
+ *
+ * Return:
+ * * 0 - success
+ * * negative - allocation fails
+ */
+static int ice_dpll_init_dplls(struct ice_pf *pf, bool cgu) {
+	struct device *dev = ice_pf_to_dev(pf);
+	int ret = -ENOMEM;
+	u64 clock_id;
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1422

Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +3 -0
+
+	ice_generate_clock_id(pf, &clock_id);
+	pf->dplls.eec.dpll = dpll_device_get(clock_id, pf-

dplls.eec.dpll_idx,

drivers/net/ethernet/intel/ice/ice_dpll.c new file +2 -0
+					     THIS_MODULE);
+	if (!pf->dplls.eec.dpll) {

You have to use IS_ERR()

Fixed.

Quoted 11 lines

drivers/net/ethernet/intel/ice/ice_dpll.c

Quoted 8 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +4 -0
+		dev_err(ice_pf_to_dev(pf), "dpll_device_get failed (eec)\n");
+		return ret;
+	}
+	pf->dplls.pps.dpll = dpll_device_get(clock_id, pf-

dplls.pps.dpll_idx,

drivers/net/ethernet/intel/ice/ice_dpll.c new file +2 -0
+					     THIS_MODULE);
+	if (!pf->dplls.pps.dpll) {

You have to use IS_ERR()

Fixed.

Quoted 17 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1440

Quoted 13 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +12 -0
+		dev_err(ice_pf_to_dev(pf), "dpll_device_get failed (pps)\n");
+		goto put_eec;
+	}
+
+	if (cgu) {
+		ret = dpll_device_register(pf->dplls.eec.dpll, DPLL_TYPE_EEC,
+					   &ice_dpll_ops, pf, dev);
+		if (ret)
+			goto put_pps;
+		ret = dpll_device_register(pf->dplls.pps.dpll, DPLL_TYPE_PPS,
+					   &ice_dpll_ops, pf, dev);
+		if (ret)

You are missing call to dpll_device_unregister(pf->dplls.eec.dpll, DPLL_TYPE_EEC here. Fix the error path.

The caller shall do the clean up, but yeah will fix this as here clean up is not expected.

Quoted 87 lines
Quoted 87 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +36 -0
+			goto put_pps;
+	}
+
+	return 0;
+
+put_pps:
+	dpll_device_put(pf->dplls.pps.dpll);
+	pf->dplls.pps.dpll = NULL;
+put_eec:
+	dpll_device_put(pf->dplls.eec.dpll);
+	pf->dplls.eec.dpll = NULL;
+
+	return ret;
+}
+
+/**
+ * ice_dpll_update_state - update dpll state
+ * @pf: pf private structure
+ * @d: pointer to queried dpll device
+ *
+ * Poll current state of dpll from hw and update ice_dpll struct.
+ * Return:
+ * * 0 - success
+ * * negative - AQ failure
+ */
+static int ice_dpll_update_state(struct ice_pf *pf, struct ice_dpll
+*d, bool init) {
+	struct ice_dpll_pin *p;
+	int ret;
+
+	ret = ice_get_cgu_state(&pf->hw, d->dpll_idx, d->prev_dpll_state,
+				&d->source_idx, &d->ref_state, &d->eec_mode,
+				&d->phase_offset, &d->dpll_state);
+
+	dev_dbg(ice_pf_to_dev(pf),
+		"update dpll=%d, prev_src_idx:%u, src_idx:%u, state:%d,

prev:%d\n",

drivers/net/ethernet/intel/ice/ice_dpll.c new file +24 -0
+		d->dpll_idx, d->prev_source_idx, d->source_idx,
+		d->dpll_state, d->prev_dpll_state);
+	if (ret) {
+		dev_err(ice_pf_to_dev(pf),
+			"update dpll=%d state failed, ret=%d %s\n",
+			d->dpll_idx, ret,
+			ice_aq_str(pf->hw.adminq.sq_last_status));
+		return ret;
+	}
+	if (init) {
+		if (d->dpll_state == ICE_CGU_STATE_LOCKED &&
+		    d->dpll_state == ICE_CGU_STATE_LOCKED_HO_ACQ)
+			d->active_source = pf->dplls.inputs[d->source_idx].pin;
+		p = &pf->dplls.inputs[d->source_idx];
+		return ice_dpll_pin_state_update(pf, p,
+						 ICE_DPLL_PIN_TYPE_SOURCE);
+	}
+	if (d->dpll_state == ICE_CGU_STATE_HOLDOVER ||
+	    d->dpll_state == ICE_CGU_STATE_FREERUN) {
+		d->active_source = NULL;
+		p = &pf->dplls.inputs[d->source_idx];
+		d->prev_source_idx = ICE_DPLL_PIN_IDX_INVALID;
+		d->source_idx = ICE_DPLL_PIN_IDX_INVALID;
+		ret = ice_dpll_pin_state_update(pf, p,

ICE_DPLL_PIN_TYPE_SOURCE);

drivers/net/ethernet/intel/ice/ice_dpll.c new file +17 -0
+	} else if (d->source_idx != d->prev_source_idx) {
+		p = &pf->dplls.inputs[d->prev_source_idx];
+		ice_dpll_pin_state_update(pf, p, ICE_DPLL_PIN_TYPE_SOURCE);
+		p = &pf->dplls.inputs[d->source_idx];
+		d->active_source = p->pin;
+		ice_dpll_pin_state_update(pf, p, ICE_DPLL_PIN_TYPE_SOURCE);
+		d->prev_source_idx = d->source_idx;
+	}
+
+	return ret;
+}
+
+/**
+ * ice_dpll_notify_changes - notify dpll subsystem about changes
+ * @d: pointer do dpll
+ *
+ * Once change detected appropriate event is submitted to the dpll

subsystem.
+ */

drivers/net/ethernet/intel/ice/ice_dpll.c new file +5 -0
+static void ice_dpll_notify_changes(struct ice_dpll *d) {
+	if (d->prev_dpll_state != d->dpll_state) {
+		d->prev_dpll_state = d->dpll_state;
+		dpll_device_notify(d->dpll, DPLL_A_LOCK_STATUS);
+	}
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1529

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +5 -0
+	if (d->prev_source != d->active_source) {
+		d->prev_source = d->active_source;
+		if (d->active_source)
+			dpll_pin_notify(d->dpll, d->active_source,
+					DPLL_A_PIN_STATE);

Didn't the state of the previously active source change as well? You need to send notification for that too.

Makes sense, fixed.

Quoted 94 lines
Quoted 94 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +11 -0
+	}
+}
+
+/**
+ * ice_dpll_periodic_work - DPLLs periodic worker
+ * @work: pointer to kthread_work structure
+ *
+ * DPLLs periodic worker is responsible for polling state of dpll.
+ */
+static void ice_dpll_periodic_work(struct kthread_work *work) {
+	struct ice_dplls *d = container_of(work, struct ice_dplls,

work.work);

drivers/net/ethernet/intel/ice/ice_dpll.c new file +81 -0
+	struct ice_pf *pf = container_of(d, struct ice_pf, dplls);
+	struct ice_dpll *de = &pf->dplls.eec;
+	struct ice_dpll *dp = &pf->dplls.pps;
+	int ret = 0;
+
+	if (!test_bit(ICE_FLAG_DPLL, pf->flags))
+		return;
+	ret = ice_dpll_cb_lock(pf);
+	if (ret) {
+		d->lock_err_num++;
+		goto resched;
+	}
+	ret = ice_dpll_update_state(pf, de, false);
+	if (!ret)
+		ret = ice_dpll_update_state(pf, dp, false);
+	if (ret) {
+		d->cgu_state_acq_err_num++;
+		/* stop rescheduling this worker */
+		if (d->cgu_state_acq_err_num >
+		    ICE_CGU_STATE_ACQ_ERR_THRESHOLD) {
+			dev_err(ice_pf_to_dev(pf),
+				"EEC/PPS DPLLs periodic work disabled\n");
+			return;
+		}
+	}
+	ice_dpll_cb_unlock(pf);
+	ice_dpll_notify_changes(de);
+	ice_dpll_notify_changes(dp);
+resched:
+	/* Run twice a second or reschedule if update failed */
+	kthread_queue_delayed_work(d->kworker, &d->work,
+				   ret ? msecs_to_jiffies(10) :
+				   msecs_to_jiffies(500));
+}
+
+/**
+ * ice_dpll_init_worker - Initialize DPLLs periodic worker
+ * @pf: board private structure
+ *
+ * Create and start DPLLs periodic worker.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - create worker failure
+ */
+static int ice_dpll_init_worker(struct ice_pf *pf) {
+	struct ice_dplls *d = &pf->dplls;
+	struct kthread_worker *kworker;
+
+	ice_dpll_update_state(pf, &d->eec, true);
+	ice_dpll_update_state(pf, &d->pps, true);
+	kthread_init_delayed_work(&d->work, ice_dpll_periodic_work);
+	kworker = kthread_create_worker(0, "ice-dplls-%s",
+					dev_name(ice_pf_to_dev(pf)));
+	if (IS_ERR(kworker))
+		return PTR_ERR(kworker);
+	d->kworker = kworker;
+	d->cgu_state_acq_err_num = 0;
+	kthread_queue_delayed_work(d->kworker, &d->work, 0);
+
+	return 0;
+}
+
+/**
+ * ice_dpll_release_all - disable support for DPLL and unregister dpll
+device
+ * @pf: board private structure
+ * @cgu: if cgu is controlled by this driver instance
+ *
+ * This function handles the cleanup work required from the
+initialization by
+ * freeing resources and unregistering the dpll.
+ *
+ * Context: Called under pf->dplls.lock  */ static void
+ice_dpll_release_all(struct ice_pf *pf, bool cgu) {
+	struct ice_dplls *d = &pf->dplls;
+	struct ice_dpll *de = &d->eec;
+	struct ice_dpll *dp = &d->pps;
+
+	mutex_lock(&pf->dplls.lock);
+	ice_dpll_release_rclk_pin(pf);
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1628

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +5 -0
+	ice_dpll_release_pins(pf, de->dpll, dp->dpll, d->inputs,
+			      d->num_inputs, &ice_dpll_source_ops, cgu);
+	mutex_unlock(&pf->dplls.lock);
+	if (cgu) {
+		mutex_lock(&pf->dplls.lock);

Interesting, you lock again a lock you just unlocked. One might wonder why you just don't move the call to mutex_unlock below this "if section".

Fixed.

Quoted 100 lines
Quoted 100 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +99 -0
+		ice_dpll_release_pins(pf, de->dpll, dp->dpll, d->outputs,
+				      d->num_outputs,
+				      &ice_dpll_output_ops, cgu);
+		mutex_unlock(&pf->dplls.lock);
+	}
+	ice_dpll_release_info(pf);
+	if (dp->dpll) {
+		mutex_lock(&pf->dplls.lock);
+		if (cgu)
+			dpll_device_unregister(dp->dpll, &ice_dpll_ops, pf);
+		dpll_device_put(dp->dpll);
+		mutex_unlock(&pf->dplls.lock);
+		dev_dbg(ice_pf_to_dev(pf), "PPS dpll removed\n");
+	}
+
+	if (de->dpll) {
+		mutex_lock(&pf->dplls.lock);
+		if (cgu)
+			dpll_device_unregister(de->dpll, &ice_dpll_ops, pf);
+		dpll_device_put(de->dpll);
+		mutex_unlock(&pf->dplls.lock);
+		dev_dbg(ice_pf_to_dev(pf), "EEC dpll removed\n");
+	}
+
+	if (cgu) {
+		mutex_lock(&pf->dplls.lock);
+		kthread_cancel_delayed_work_sync(&d->work);
+		if (d->kworker) {
+			kthread_destroy_worker(d->kworker);
+			d->kworker = NULL;
+			dev_dbg(ice_pf_to_dev(pf), "DPLLs worker removed\n");
+		}
+		mutex_unlock(&pf->dplls.lock);
+	}
+}
+
+/**
+ * ice_dpll_release - Disable the driver/HW support for DPLLs and
+unregister
+ * the dpll device.
+ * @pf: board private structure
+ *
+ * Handles the cleanup work required after dpll initialization,
+ * freeing resources and unregistering the dpll.
+ */
+void ice_dpll_release(struct ice_pf *pf) {
+	if (test_bit(ICE_FLAG_DPLL, pf->flags)) {
+		ice_dpll_release_all(pf,
+				     ice_is_feature_supported(pf, ICE_F_CGU));
+		mutex_destroy(&pf->dplls.lock);
+		clear_bit(ICE_FLAG_DPLL, pf->flags);
+	}
+}
+
+/**
+ * ice_dpll_init_direct_pins - initializes source or output pins
+information
+ * @pf: board private structure
+ * @pin_type: type of pins being initialized
+ *
+ * Init information about input or output pins, cache them in pins struct.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - init failure
+ */
+static int
+ice_dpll_init_direct_pins(struct ice_pf *pf, enum ice_dpll_pin_type
+pin_type) {
+	struct ice_dpll *de = &pf->dplls.eec, *dp = &pf->dplls.pps;
+	int num_pins, i, ret = -EINVAL;
+	struct ice_hw *hw = &pf->hw;
+	struct ice_dpll_pin *pins;
+	u8 freq_supp_num;
+	bool input;
+
+	if (pin_type == ICE_DPLL_PIN_TYPE_SOURCE) {
+		pins = pf->dplls.inputs;
+		num_pins = pf->dplls.num_inputs;
+		input = true;
+	} else if (pin_type == ICE_DPLL_PIN_TYPE_OUTPUT) {
+		pins = pf->dplls.outputs;
+		num_pins = pf->dplls.num_outputs;
+		input = false;
+	} else {
+		return -EINVAL;
+	}
+
+	for (i = 0; i < num_pins; i++) {
+		pins[i].idx = i;
+		pins[i].prop.label = ice_cgu_get_pin_name(hw, i, input);
+		pins[i].prop.type = ice_cgu_get_pin_type(hw, i, input);
+		if (input) {
+			ret = ice_aq_get_cgu_ref_prio(hw, de->dpll_idx, i,
+						      &de->input_prio[i]);
+			if (ret)
+				return ret;
+			ret = ice_aq_get_cgu_ref_prio(hw, dp->dpll_idx, i,
+						      &dp->input_prio[i]);
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1732

Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +6 -0
+			if (ret)
+				return ret;
+			pins[i].prop.capabilities +=
+				DPLL_PIN_CAPS_PRIORITY_CAN_CHANGE;
+		}
+		pins[i].prop.capabilities += DPLL_PIN_CAPS_STATE_CAN_CHANGE;

It is a flag. Common is to use bit op &= instead.

Fixed.

Quoted 60 lines
Quoted 46 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +45 -0
+		ret = ice_dpll_pin_state_update(pf, &pins[i], pin_type);
+		if (ret)
+			return ret;
+		pins[i].prop.freq_supported =
+			ice_cgu_get_pin_freq_supp(hw, i, input, &freq_supp_num);
+		pins[i].prop.freq_supported_num = freq_supp_num;
+	}
+
+	return ret;
+}
+
+/**
+ * ice_dpll_init_rclk_pin - initializes rclk pin information
+ * @pf: board private structure
+ * @pin_type: type of pins being initialized
+ *
+ * Init information for rclk pin, cache them in pf->dplls.rclk.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - init failure
+ */
+static int ice_dpll_init_rclk_pin(struct ice_pf *pf) {
+	struct ice_dpll_pin *pin = &pf->dplls.rclk;
+	struct device *dev = ice_pf_to_dev(pf);
+
+	pin->prop.label = dev_name(dev);
+	pin->prop.type = DPLL_PIN_TYPE_SYNCE_ETH_PORT;
+	pin->prop.capabilities += DPLL_PIN_CAPS_STATE_CAN_CHANGE;
+
+	return ice_dpll_pin_state_update(pf, pin,
+					 ICE_DPLL_PIN_TYPE_RCLK_SOURCE);
+}
+
+/**
+ * ice_dpll_init_pins - init pins wrapper
+ * @pf: board private structure
+ * @pin_type: type of pins being initialized
+ *
+ * Wraps functions for pin inti.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - init failure
+ */

drivers/net/ethernet/intel/ice/ice_dpll.c line 1789

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+static int ice_dpll_init_pins(struct ice_pf *pf,
+			      const enum ice_dpll_pin_type pin_type) {
+	if (pin_type == ICE_DPLL_PIN_TYPE_SOURCE)
+		return ice_dpll_init_direct_pins(pf, pin_type);
+	else if (pin_type == ICE_DPLL_PIN_TYPE_OUTPUT)
+		return ice_dpll_init_direct_pins(pf, pin_type);
+	else if (pin_type == ICE_DPLL_PIN_TYPE_RCLK_SOURCE)
+		return ice_dpll_init_rclk_pin(pf);
+	else
+		return -EINVAL;

How this can happen?

How about:

Quoted 9 lines
	switch (pin_type) {
	case ICE_DPLL_PIN_TYPE_SOURCE:
	case ICE_DPLL_PIN_TYPE_OUTPUT:
		return ice_dpll_init_direct_pins(pf, pin_type);
	case ICE_DPLL_PIN_TYPE_RCLK_SOURCE:
		return ice_dpll_init_rclk_pin(pf);
	}

?

It shall not if called properly, changed to switch case as suggested. Altough still needs default: as there is one not covered case, thus compiler warns about it.

Quoted 118 lines
Quoted 118 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +8 -0
+}
+
+/**
+ * ice_dpll_init_info - prepare pf's dpll information structure
+ * @pf: board private structure
+ * @cgu: if cgu is present and controlled by this NIC
+ *
+ * Acquire (from HW) and set basic dpll information (on pf->dplls

struct).
+ *
+ * Return:
+ * * 0 - success
+ * * negative - error
+ */

drivers/net/ethernet/intel/ice/ice_dpll.c new file +71 -0
+static int ice_dpll_init_info(struct ice_pf *pf, bool cgu) {
+	struct ice_aqc_get_cgu_abilities abilities;
+	struct ice_dpll *de = &pf->dplls.eec;
+	struct ice_dpll *dp = &pf->dplls.pps;
+	struct ice_dplls *d = &pf->dplls;
+	struct ice_hw *hw = &pf->hw;
+	int ret, alloc_size, i;
+	u8 base_rclk_idx;
+
+	ice_generate_clock_id(pf, &d->clock_id);
+	ret = ice_aq_get_cgu_abilities(hw, &abilities);
+	if (ret) {
+		dev_err(ice_pf_to_dev(pf),
+			"err:%d %s failed to read cgu abilities\n",
+			ret, ice_aq_str(hw->adminq.sq_last_status));
+		return ret;
+	}
+
+	de->dpll_idx = abilities.eec_dpll_idx;
+	dp->dpll_idx = abilities.pps_dpll_idx;
+	d->num_inputs = abilities.num_inputs;
+	d->num_outputs = abilities.num_outputs;
+
+	alloc_size = sizeof(*d->inputs) * d->num_inputs;
+	d->inputs = kzalloc(alloc_size, GFP_KERNEL);
+	if (!d->inputs)
+		return -ENOMEM;
+
+	alloc_size = sizeof(*de->input_prio) * d->num_inputs;
+	de->input_prio = kzalloc(alloc_size, GFP_KERNEL);
+	if (!de->input_prio)
+		return -ENOMEM;
+
+	dp->input_prio = kzalloc(alloc_size, GFP_KERNEL);
+	if (!dp->input_prio)
+		return -ENOMEM;
+
+	ret = ice_dpll_init_pins(pf, ICE_DPLL_PIN_TYPE_SOURCE);
+	if (ret)
+		goto release_info;
+
+	if (cgu) {
+		alloc_size = sizeof(*d->outputs) * d->num_outputs;
+		d->outputs = kzalloc(alloc_size, GFP_KERNEL);
+		if (!d->outputs)
+			goto release_info;
+
+		ret = ice_dpll_init_pins(pf, ICE_DPLL_PIN_TYPE_OUTPUT);
+		if (ret)
+			goto release_info;
+	}
+
+	ret = ice_get_cgu_rclk_pin_info(&pf->hw, &base_rclk_idx,
+					&pf->dplls.rclk.num_parents);
+	if (ret)
+		return ret;
+	for (i = 0; i < pf->dplls.rclk.num_parents; i++)
+		pf->dplls.rclk.parent_idx[i] = base_rclk_idx + i;
+	ret = ice_dpll_init_pins(pf, ICE_DPLL_PIN_TYPE_RCLK_SOURCE);
+	if (ret)
+		return ret;
+
+	dev_dbg(ice_pf_to_dev(pf),
+		"%s - success, inputs:%u, outputs:%u rclk-parents:%u\n",
+		__func__, d->num_inputs, d->num_outputs, d->rclk.num_parents);
+
+	return 0;
+
+release_info:
+	dev_err(ice_pf_to_dev(pf),
+		"%s - fail: d->inputs:%p, de->input_prio:%p, dp->input_prio:%p,

d->outputs:%p\n",

drivers/net/ethernet/intel/ice/ice_dpll.c new file +30 -0
+		__func__, d->inputs, de->input_prio,
+		dp->input_prio, d->outputs);
+	ice_dpll_release_info(pf);
+	return ret;
+}
+
+/**
+ * ice_dpll_init - initialize dplls support
+ * @pf: board private structure
+ *
+ * Set up the device dplls registering them and pins connected within
+Linux dpll
+ * subsystem. Allow userpsace to obtain state of DPLL and handling of
+DPLL
+ * configuration requests.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - init failure
+ */
+int ice_dpll_init(struct ice_pf *pf)
+{
+	bool cgu_present = ice_is_feature_supported(pf, ICE_F_CGU);
+	struct ice_dplls *d = &pf->dplls;
+	int err = 0;
+
+	mutex_init(&d->lock);
+	mutex_lock(&d->lock);
+	err = ice_dpll_init_info(pf, cgu_present);
+	if (err)
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1907

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +5 -0
+		goto release;
+	err = ice_dpll_init_dplls(pf, cgu_present);
+	if (err)
+		goto release;
+	err = ice_dpll_register_pins(pf, cgu_present);

This should be rather called "ice_dpll_init_pins()" to be in sync with ice_dpll_init_dplls() as it is doing more then just registration.

Makes sense, fixed.

Thank you very much!
Arkadiusz

Quoted 423 lines
Quoted 135 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +22 -0
+	if (err)
+		goto release;
+	set_bit(ICE_FLAG_DPLL, pf->flags);
+	if (cgu_present) {
+		err = ice_dpll_init_worker(pf);
+		if (err)
+			goto release;
+	}
+	mutex_unlock(&d->lock);
+	dev_info(ice_pf_to_dev(pf), "DPLLs init successful\n");
+
+	return err;
+
+release:
+	ice_dpll_release_all(pf, cgu_present);
+	clear_bit(ICE_FLAG_DPLL, pf->flags);
+	mutex_unlock(&d->lock);
+	mutex_destroy(&d->lock);
+	dev_warn(ice_pf_to_dev(pf), "DPLLs init failure\n");
+
+	return err;
+}
drivers/net/ethernet/intel/ice/ice_dpll.h new file +99 -0
new file mode 100644
index 000000000000..aad48b9910b7
@@ -0,0 +1,101 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2022, Intel Corporation. */
+
+#ifndef _ICE_DPLL_H_
+#define _ICE_DPLL_H_
+
+#include "ice.h"
+
+#define ICE_DPLL_PRIO_MAX	0xF
+#define ICE_DPLL_RCLK_NUM_MAX	4
+/** ice_dpll_pin - store info about pins
+ * @pin: dpll pin structure
+ * @flags: pin flags returned from HW
+ * @idx: ice pin private idx
+ * @state: state of a pin
+ * @type: type of a pin
+ * @freq_mask: mask of supported frequencies
+ * @freq: current frequency of a pin
+ * @caps: capabilities of a pin
+ * @name: pin name
+ */
+struct ice_dpll_pin {
+	struct dpll_pin *pin;
+	u8 idx;
+	u8 num_parents;
+	u8 parent_idx[ICE_DPLL_RCLK_NUM_MAX];
+	u8 flags[ICE_DPLL_RCLK_NUM_MAX];
+	u8 state[ICE_DPLL_RCLK_NUM_MAX];
+	struct dpll_pin_properties prop;
+	u32 freq;
+};
+
+/** ice_dpll - store info required for DPLL control
+ * @dpll: pointer to dpll dev
+ * @dpll_idx: index of dpll on the NIC
+ * @source_idx: source currently selected
+ * @prev_source_idx: source previously selected
+ * @ref_state: state of dpll reference signals
+ * @eec_mode: eec_mode dpll is configured for
+ * @phase_offset: phase delay of a dpll
+ * @input_prio: priorities of each input
+ * @dpll_state: current dpll sync state
+ * @prev_dpll_state: last dpll sync state
+ * @active_source: pointer to active source pin
+ * @prev_source: pointer to previous active source pin  */ struct
+ice_dpll {
+	struct dpll_device *dpll;
+	int dpll_idx;
+	u8 source_idx;
+	u8 prev_source_idx;
+	u8 ref_state;
+	u8 eec_mode;
+	s64 phase_offset;
+	u8 *input_prio;
+	enum ice_cgu_state dpll_state;
+	enum ice_cgu_state prev_dpll_state;
+	struct dpll_pin *active_source;
+	struct dpll_pin *prev_source;
+};
+
+/** ice_dplls - store info required for CCU (clock controlling unit)
+ * @kworker: periodic worker
+ * @work: periodic work
+ * @lock: locks access to configuration of a dpll
+ * @eec: pointer to EEC dpll dev
+ * @pps: pointer to PPS dpll dev
+ * @inputs: input pins pointer
+ * @outputs: output pins pointer
+ * @rclk: recovered pins pointer
+ * @num_inputs: number of input pins available on dpll
+ * @num_outputs: number of output pins available on dpll
+ * @num_rclk: number of recovered clock pins available on dpll
+ * @cgu_state_acq_err_num: number of errors returned during periodic
+work  */ struct ice_dplls {
+	struct kthread_worker *kworker;
+	struct kthread_delayed_work work;
+	struct mutex lock;
+	struct ice_dpll eec;
+	struct ice_dpll pps;
+	struct ice_dpll_pin *inputs;
+	struct ice_dpll_pin *outputs;
+	struct ice_dpll_pin rclk;
+	u32 num_inputs;
+	u32 num_outputs;
+	int cgu_state_acq_err_num;
+	int lock_err_num;
+	u8 base_rclk_idx;
+	u64 clock_id;
+};
+
+int ice_dpll_init(struct ice_pf *pf);
+
+void ice_dpll_release(struct ice_pf *pf);
+
+int ice_dpll_rclk_init(struct ice_pf *pf);
+
+void ice_dpll_rclk_release(struct ice_pf *pf);
+
+#endif
drivers/net/ethernet/intel/ice/ice_main.c +0 -0
index a1f7c8edc22f..6b28b95a7254 100644

drivers/net/ethernet/intel/ice/ice_main.c static void ice_init_features(struct ice_pf *pf) · line 4830

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_main.c +4 -0
@@ -4821,6 +4821,10 @@ static void ice_init_features(struct ice_pf *pf)
 	if (ice_is_feature_supported(pf, ICE_F_GNSS))
 		ice_gnss_init(pf);
 
+	if (ice_is_feature_supported(pf, ICE_F_CGU) ||
+	    ice_is_feature_supported(pf, ICE_F_PHY_RCLK))
+		ice_dpll_init(pf);
+
 	/* Note: Flow director init failure is non-fatal to load */
 	if (ice_init_fdir(pf))
 		dev_err(dev, "could not initialize flow director\n"); @@ -

4847,6

Quoted 277 lines

+4851,9 @@ static void ice_deinit_features(struct ice_pf *pf)

		ice_gnss_exit(pf);
	if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags))
		ice_ptp_release(pf);
drivers/net/ethernet/intel/ice/ice_main.c +3 -0
+	if (ice_is_feature_supported(pf, ICE_F_PHY_RCLK) ||
+	    ice_is_feature_supported(pf, ICE_F_CGU))
+		ice_dpll_release(pf);

}

static void ice_init_wakeup(struct ice_pf *pf) diff --git a/drivers/net/ethernet/intel/ice/ice_ptp_hw.c b/drivers/net/ethernet/intel/ice/ice_ptp_hw.c index e9a371fa038b..39b692945f73 100644

drivers/net/ethernet/intel/ice/ice_ptp_hw.c +13 -9
@@ -3609,28 +3609,31 @@ enum dpll_pin_type ice_cgu_get_pin_type(struct
 ice_hw *hw, u8 pin, bool input)  }
 
 /**
- * ice_cgu_get_pin_sig_type_mask
+ * ice_cgu_get_pin_freq_supp
 * @hw: pointer to the hw struct
 * @pin: pin index
 * @input: if request is done against input or output pin
+ * @num: output number of supported frequencies
 *
- * Return: signal type bit mask of a pin.
+ * Get frequency supported number and array of supported frequencies.
+ *
+ * Return: array of supported frequencies for given pin.
 */
-unsigned long
-ice_cgu_get_pin_freq_mask(struct ice_hw *hw, u8 pin, bool input)
+struct dpll_pin_frequency *
+ice_cgu_get_pin_freq_supp(struct ice_hw *hw, u8 pin, bool input, u8
+*num)
 {
 	const struct ice_cgu_pin_desc *t;
 	int t_size;
 
+	*num = 0;
 	t = ice_cgu_get_pin_desc(hw, input, &t_size);
-
 	if (!t)
-		return 0;
-
+		return NULL;
 	if (pin >= t_size)
-		return 0;
+		return NULL;
+	*num = t[pin].freq_supp_num;
 
-	return t[pin].sig_type_mask;
+	return t[pin].freq_supp;
 }
 

/**

drivers/net/ethernet/intel/ice/ice_ptp_hw.h +67 -77
index d09e5bca0ff1..4568b0403cd7 100644
@@ -192,147 +192,137 @@ enum ice_si_cgu_out_pins {
 	NUM_SI_CGU_OUTPUT_PINS
 };
 
-#define MAX_CGU_PIN_NAME_LEN		16
-#define ICE_SIG_TYPE_MASK_1PPS_10MHZ	(BIT(DPLL_PIN_FREQ_SUPP_1_HZ) | \
-					 BIT(DPLL_PIN_FREQ_SUPP_10_MHZ))
+static struct dpll_pin_frequency ice_cgu_pin_freq_common[] = {
+	DPLL_PIN_FREQUENCY_1PPS,
+	DPLL_PIN_FREQUENCY_10MHZ,
+};
+
+static struct dpll_pin_frequency ice_cgu_pin_freq_1_hz[] = {
+	DPLL_PIN_FREQUENCY_1PPS,
+};
+
+static struct dpll_pin_frequency ice_cgu_pin_freq_10_mhz[] = {
+	DPLL_PIN_FREQUENCY_10MHZ,
+};
+
 struct ice_cgu_pin_desc {
-	char name[MAX_CGU_PIN_NAME_LEN];
+	char *name;
 	u8 index;
 	enum dpll_pin_type type;
-	unsigned long sig_type_mask;
+	u32 freq_supp_num;
+	struct dpll_pin_frequency *freq_supp;
 };
 
 static const struct ice_cgu_pin_desc ice_e810t_sfp_cgu_inputs[] = {
 	{ "CVL-SDP22",	  ZL_REF0P, DPLL_PIN_TYPE_INT_OSCILLATOR,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
 	{ "CVL-SDP20",	  ZL_REF0N, DPLL_PIN_TYPE_INT_OSCILLATOR,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
-	{ "C827_0-RCLKA", ZL_REF1P, DPLL_PIN_TYPE_MUX,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
-	{ "C827_0-RCLKB", ZL_REF1N, DPLL_PIN_TYPE_MUX,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
+	{ "C827_0-RCLKA", ZL_REF1P, DPLL_PIN_TYPE_MUX, 0, },
+	{ "C827_0-RCLKB", ZL_REF1N, DPLL_PIN_TYPE_MUX, 0, },
 	{ "SMA1",	  ZL_REF3P, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
 	{ "SMA2/U.FL2",	  ZL_REF3N, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
 	{ "GNSS-1PPS",	  ZL_REF4P, DPLL_PIN_TYPE_GNSS,
-		BIT(DPLL_PIN_FREQ_SUPP_1_HZ) },
-	{ "OCXO",	  ZL_REF4N, DPLL_PIN_TYPE_INT_OSCILLATOR,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
+		ARRAY_SIZE(ice_cgu_pin_freq_1_hz), ice_cgu_pin_freq_1_hz },
+	{ "OCXO",	  ZL_REF4N, DPLL_PIN_TYPE_INT_OSCILLATOR, 0, },
 };
 
 static const struct ice_cgu_pin_desc ice_e810t_qsfp_cgu_inputs[] = {
 	{ "CVL-SDP22",	  ZL_REF0P, DPLL_PIN_TYPE_INT_OSCILLATOR,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
 	{ "CVL-SDP20",	  ZL_REF0N, DPLL_PIN_TYPE_INT_OSCILLATOR,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
-	{ "C827_0-RCLKA", ZL_REF1P, DPLL_PIN_TYPE_MUX,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
-	{ "C827_0-RCLKB", ZL_REF1N, DPLL_PIN_TYPE_MUX,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
-	{ "C827_1-RCLKA", ZL_REF2P, DPLL_PIN_TYPE_MUX,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
-	{ "C827_1-RCLKB", ZL_REF2N, DPLL_PIN_TYPE_MUX,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
+	{ "C827_0-RCLKA", ZL_REF1P, DPLL_PIN_TYPE_MUX, },
+	{ "C827_0-RCLKB", ZL_REF1N, DPLL_PIN_TYPE_MUX, },
+	{ "C827_1-RCLKA", ZL_REF2P, DPLL_PIN_TYPE_MUX, },
+	{ "C827_1-RCLKB", ZL_REF2N, DPLL_PIN_TYPE_MUX, },
 	{ "SMA1",	  ZL_REF3P, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
 	{ "SMA2/U.FL2",	  ZL_REF3N, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
 	{ "GNSS-1PPS",	  ZL_REF4P, DPLL_PIN_TYPE_GNSS,
-		BIT(DPLL_PIN_FREQ_SUPP_1_HZ) },
-	{ "OCXO",	  ZL_REF4N, DPLL_PIN_TYPE_INT_OSCILLATOR,
-			BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
+		ARRAY_SIZE(ice_cgu_pin_freq_1_hz), ice_cgu_pin_freq_1_hz },
+	{ "OCXO",	  ZL_REF4N, DPLL_PIN_TYPE_INT_OSCILLATOR, },
 };
 
 static const struct ice_cgu_pin_desc ice_e810t_sfp_cgu_outputs[] = {
 	{ "REF-SMA1",	    ZL_OUT0, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
 	{ "REF-SMA2/U.FL2", ZL_OUT1, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
-	{ "PHY-CLK",	    ZL_OUT2, DPLL_PIN_TYPE_SYNCE_ETH_PORT,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
-	{ "MAC-CLK",	    ZL_OUT3, DPLL_PIN_TYPE_SYNCE_ETH_PORT,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
+	{ "PHY-CLK",	    ZL_OUT2, DPLL_PIN_TYPE_SYNCE_ETH_PORT, },
+	{ "MAC-CLK",	    ZL_OUT3, DPLL_PIN_TYPE_SYNCE_ETH_PORT, },
 	{ "CVL-SDP21",	    ZL_OUT4, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_1_hz), ice_cgu_pin_freq_1_hz },
 	{ "CVL-SDP23",	    ZL_OUT5, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_1_hz), ice_cgu_pin_freq_1_hz },
 };
 
 static const struct ice_cgu_pin_desc ice_e810t_qsfp_cgu_outputs[] = {
 	{ "REF-SMA1",	    ZL_OUT0, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
 	{ "REF-SMA2/U.FL2", ZL_OUT1, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
-	{ "PHY-CLK",	    ZL_OUT2, DPLL_PIN_TYPE_SYNCE_ETH_PORT,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
-	{ "PHY2-CLK",	    ZL_OUT3, DPLL_PIN_TYPE_SYNCE_ETH_PORT,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
-	{ "MAC-CLK",	    ZL_OUT4, DPLL_PIN_TYPE_SYNCE_ETH_PORT,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
+	{ "PHY-CLK",	    ZL_OUT2, DPLL_PIN_TYPE_SYNCE_ETH_PORT, 0 },
+	{ "PHY2-CLK",	    ZL_OUT3, DPLL_PIN_TYPE_SYNCE_ETH_PORT, 0 },
+	{ "MAC-CLK",	    ZL_OUT4, DPLL_PIN_TYPE_SYNCE_ETH_PORT, 0 },
 	{ "CVL-SDP21",	    ZL_OUT5, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_1_hz), ice_cgu_pin_freq_1_hz },
 	{ "CVL-SDP23",	    ZL_OUT6, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_1_hz), ice_cgu_pin_freq_1_hz },
 };
 
 static const struct ice_cgu_pin_desc ice_e823_si_cgu_inputs[] = {
 	{ "NONE",	  SI_REF0P, DPLL_PIN_TYPE_UNSPEC, 0 },
 	{ "NONE",	  SI_REF0N, DPLL_PIN_TYPE_UNSPEC, 0 },
-	{ "SYNCE0_DP",	  SI_REF1P, DPLL_PIN_TYPE_MUX,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
-	{ "SYNCE0_DN",	  SI_REF1N, DPLL_PIN_TYPE_MUX,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
+	{ "SYNCE0_DP",	  SI_REF1P, DPLL_PIN_TYPE_MUX, 0 },
+	{ "SYNCE0_DN",	  SI_REF1N, DPLL_PIN_TYPE_MUX, 0 },
 	{ "EXT_CLK_SYNC", SI_REF2P, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
 	{ "NONE",	  SI_REF2N, DPLL_PIN_TYPE_UNSPEC, 0 },
 	{ "EXT_PPS_OUT",  SI_REF3,  DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
 	{ "INT_PPS_OUT",  SI_REF4,  DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
 };
 
 static const struct ice_cgu_pin_desc ice_e823_si_cgu_outputs[] = {
 	{ "1588-TIME_SYNC", SI_OUT0, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
-	{ "PHY-CLK",	    SI_OUT1, DPLL_PIN_TYPE_SYNCE_ETH_PORT,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
+	{ "PHY-CLK",	    SI_OUT1, DPLL_PIN_TYPE_SYNCE_ETH_PORT, 0 },
 	{ "10MHZ-SMA2",	    SI_OUT2, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_10_mhz), ice_cgu_pin_freq_10_mhz },
 	{ "PPS-SMA1",	    SI_OUT3, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
 };
 
 static const struct ice_cgu_pin_desc ice_e823_zl_cgu_inputs[] = {
 	{ "NONE",	  ZL_REF0P, DPLL_PIN_TYPE_UNSPEC, 0 },
 	{ "INT_PPS_OUT",  ZL_REF0N, DPLL_PIN_TYPE_EXT,
-		BIT(DPLL_PIN_FREQ_SUPP_1_HZ) },
-	{ "SYNCE0_DP",	  ZL_REF1P, DPLL_PIN_TYPE_MUX,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
-	{ "SYNCE0_DN",	  ZL_REF1N, DPLL_PIN_TYPE_MUX,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
+		ARRAY_SIZE(ice_cgu_pin_freq_1_hz), ice_cgu_pin_freq_1_hz },
+	{ "SYNCE0_DP",	  ZL_REF1P, DPLL_PIN_TYPE_MUX, 0 },
+	{ "SYNCE0_DN",	  ZL_REF1N, DPLL_PIN_TYPE_MUX, 0 },
 	{ "NONE",	  ZL_REF2P, DPLL_PIN_TYPE_UNSPEC, 0 },
 	{ "NONE",	  ZL_REF2N, DPLL_PIN_TYPE_UNSPEC, 0 },
 	{ "EXT_CLK_SYNC", ZL_REF3P, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
 	{ "NONE",	  ZL_REF3N, DPLL_PIN_TYPE_UNSPEC, 0 },
 	{ "EXT_PPS_OUT",  ZL_REF4P, DPLL_PIN_TYPE_EXT,
-		BIT(DPLL_PIN_FREQ_SUPP_1_HZ) },
-	{ "OCXO",	  ZL_REF4N, DPLL_PIN_TYPE_INT_OSCILLATOR,
-			BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
+		ARRAY_SIZE(ice_cgu_pin_freq_1_hz), ice_cgu_pin_freq_1_hz },
+	{ "OCXO",	  ZL_REF4N, DPLL_PIN_TYPE_INT_OSCILLATOR, 0 },
 };
 
 static const struct ice_cgu_pin_desc ice_e823_zl_cgu_outputs[] = {
 	{ "PPS-SMA1",	   ZL_OUT0, DPLL_PIN_TYPE_EXT,
-		BIT(DPLL_PIN_FREQ_SUPP_1_HZ) },
+		ARRAY_SIZE(ice_cgu_pin_freq_1_hz), ice_cgu_pin_freq_1_hz },
 	{ "10MHZ-SMA2",	   ZL_OUT1, DPLL_PIN_TYPE_EXT,
-		BIT(DPLL_PIN_FREQ_SUPP_10_MHZ) },
-	{ "PHY-CLK",	   ZL_OUT2, DPLL_PIN_TYPE_SYNCE_ETH_PORT,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
-	{ "1588-TIME_REF", ZL_OUT3, DPLL_PIN_TYPE_SYNCE_ETH_PORT,
-		BIT(DPLL_PIN_FREQ_SUPP_UNSPEC) },
+		ARRAY_SIZE(ice_cgu_pin_freq_10_mhz), ice_cgu_pin_freq_10_mhz },
+	{ "PHY-CLK",	   ZL_OUT2, DPLL_PIN_TYPE_SYNCE_ETH_PORT, 0 },
+	{ "1588-TIME_REF", ZL_OUT3, DPLL_PIN_TYPE_SYNCE_ETH_PORT, 0 },
 	{ "CPK-TIME_SYNC", ZL_OUT4, DPLL_PIN_TYPE_EXT,
-		ICE_SIG_TYPE_MASK_1PPS_10MHZ },
+		ARRAY_SIZE(ice_cgu_pin_freq_common), ice_cgu_pin_freq_common },
 	{ "NONE",	   ZL_OUT5, DPLL_PIN_TYPE_UNSPEC, 0 },
 };
 
Quoted 14 lines
Quoted 8 lines
drivers/net/ethernet/intel/ice/ice_ptp_hw.h +0 -0
@@ -429,8 +419,8 @@ bool ice_is_clock_mux_present_e810t(struct ice_hw
 *hw);  int ice_get_pf_c827_idx(struct ice_hw *hw, u8 *idx);  bool

ice_is_cgu_present(struct ice_hw *hw); enum dpll_pin_type ice_cgu_get_pin_type(struct ice_hw *hw, u8 pin, bool input); -unsigned long -ice_cgu_get_pin_freq_mask(struct ice_hw *hw, u8 pin, bool input);

drivers/net/ethernet/intel/ice/ice_ptp_hw.h +3 -0
+struct dpll_pin_frequency *
+ice_cgu_get_pin_freq_supp(struct ice_hw *hw, u8 pin, bool input, u8
+*num);
Quoted 6 lines

const char *ice_cgu_get_pin_name(struct ice_hw *hw, u8 pin, bool input); int ice_get_cgu_state(struct ice_hw *hw, u8 dpll_idx,
enum ice_cgu_state last_dpll_state, u8 *pin,
--
2.34.1

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer
#54 lore raw

Re: [RFC PATCH v7 5/8] ice: implement dpll interface to control cgu

Quoted 5 lines · Tue, May 16, 2023 at 12:07:57AM CEST, [email protected] wrote:
Quoted 5 lines

From: Jiri Pirko <[email protected]>
Sent: Wednesday, May 3, 2023 2:19 PM

Quoted 1 line · Fri, Apr 28, 2023 at 02:20:06AM CEST, [email protected] wrote:

From: Arkadiusz Kubalewski <[email protected]>

[...]

Quoted 33 lines
Quoted 33 lines
Quoted 17 lines

+ * ice_dpll_frequency_set - wrapper for pin callback for set frequency
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: pointer to dpll
+ * @frequency: frequency to be set
+ * @extack: error reporting
+ * @pin_type: type of pin being configured
+ *
+ * Wraps internal set frequency command on a pin.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - error pin not found or couldn't set in hw */ static

drivers/net/ethernet/intel/ice/ice_dpll.c new file +4 -0
+int ice_dpll_frequency_set(const struct dpll_pin *pin, void *pin_priv,
+		       const struct dpll_device *dpll,
+		       const u32 frequency,
+		       struct netlink_ext_ack *extack,

drivers/net/ethernet/intel/ice/ice_dpll.c line 243

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+		       const enum ice_dpll_pin_type pin_type) {
+	struct ice_pf *pf = pin_priv;
+	struct ice_dpll_pin *p;
+	int ret = -EINVAL;
+
+	if (!pf)
+		return ret;
+	if (ice_dpll_cb_lock(pf))
+		return -EBUSY;
+	p = ice_find_pin(pf, pin, pin_type);

This does not make any sense to me. You should avoid the lookups and remove ice_find_pin() function entirely. The purpose of having pin_priv is to carry the struct ice_dpll_pin * directly. You should pass it down during pin register.

Quoted 4 lines
Quoted 2 lines

pf pointer is stored in dpll_priv.

In this case dpll_priv is not passed, so cannot use it.

It should be passed. In general to every op where *dpll is passed, the dpll_priv pointer should be passed along. Please, fix this.

Quoted 2 lines

But in general it makes sense I will hold pf inside of ice_dpll_pin and fix this.

Nope, just use dpll_priv. That's why we have it.

[...]

Quoted 23 lines
Quoted 13 lines
Quoted 13 lines

+/**
+ * ice_dpll_pin_state_set - set pin's state on dpll
+ * @dpll: dpll being configured
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @state: state of pin to be set
+ * @extack: error reporting
+ * @pin_type: type of a pin
+ *
+ * Set pin state on a pin.
+ *
+ * Return:
+ * * 0 - OK or no change required

Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 718

Quoted 6 lines

+ * * negative - error
+ */

drivers/net/ethernet/intel/ice/ice_dpll.c new file +4 -0
+static int
+ice_dpll_pin_state_set(const struct dpll_device *dpll,
+		       const struct dpll_pin *pin, void *pin_priv,
+		       const enum dpll_pin_state state,

Why you use const with enums?

Quoted 1 line

Just show usage intention explicitly.

Does not make any sense what so ever. Please avoid it.

Quoted 23 lines
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1160

Quoted 7 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +7 -0
+static int ice_dpll_rclk_state_on_pin_get(const struct dpll_pin *pin,
+					  void *pin_priv,
+					  const struct dpll_pin *parent_pin,
+					  enum dpll_pin_state *state,
+					  struct netlink_ext_ack *extack) {
+	struct ice_pf *pf = pin_priv;
+	u32 parent_idx, hw_idx = ICE_DPLL_PIN_IDX_INVALID, i;

Reverse christmas tree ordering please.

Fixed.

Quoted 10 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1164

Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +4 -0
+	struct ice_dpll_pin *p;
+	int ret = -EFAULT;
+
+	if (!pf)

How exacly this can happen. My wild guess is it can't. Don't do such pointless checks please, confuses the reader.

Quoted 2 lines

From driver perspective the pf pointer value is given by external entity, why shouldn't it be valdiated?

What? You pass it during register, you get it back here. Nothing to check. Please drop it. Non-sense checks like this have no place in kernel, they only confuse reader as he/she assumes it is a valid case.

[...]

Quoted 21 lines
Quoted 11 lines
Quoted 11 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +9 -0
+			pins[i].pin = NULL;
+			return -ENOMEM;
+		}
+		if (cgu) {
+			ret = dpll_pin_register(pf->dplls.eec.dpll,
+						pins[i].pin,
+						ops, pf, NULL);
+			if (ret)
+				return ret;
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1343

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +5 -0
+			ret = dpll_pin_register(pf->dplls.pps.dpll,
+						pins[i].pin,
+						ops, pf, NULL);
+			if (ret)
+				return ret;

You have to call dpll_pin_unregister(pf->dplls.eec.dpll, pins[i].pin, ..) here.

Quoted 1 line

No, in case of error, the caller releases everything ice_dpll_release_all(..).

How does ice_dpll_release_all() where you failed? If you need to unregister one or both or none? I know that in ice you have odd ways to handle error paths in general, but this one clearly seems to be broken.

Quoted 35 lines
Quoted 16 lines
Quoted 4 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +2 -0
+		}
+	}

drivers/net/ethernet/intel/ice/ice_dpll.c line 1355

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+	if (cgu) {
+		ops = &ice_dpll_output_ops;
+		pins = pf->dplls.outputs;
+		for (i = 0; i < pf->dplls.num_outputs; i++) {
+			pins[i].pin = dpll_pin_get(pf->dplls.clock_id,
+						   i + pf->dplls.num_inputs,
+						   THIS_MODULE, &pins[i].prop);
+			if (IS_ERR_OR_NULL(pins[i].pin)) {
+				pins[i].pin = NULL;
+				return -ENOMEM;

Don't make up error values when you get them from the function you call:

Quoted 1 line
	return PTR_ERR(pins[i].pin);

Fixed.

Quoted 14 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1364

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +9 -0
+			}
+			ret = dpll_pin_register(pf->dplls.eec.dpll, pins[i].pin,
+						ops, pf, NULL);
+			if (ret)
+				return ret;
+			ret = dpll_pin_register(pf->dplls.pps.dpll, pins[i].pin,
+						ops, pf, NULL);
+			if (ret)
+				return ret;

You have to call dpll_pin_unregister(pf->dplls.eec.dpll, pins[i].pin, ..) here.

Quoted 1 line

As above, in case of error, the caller releases everything.

As above, I don't think it works.

[...]

Quoted 15 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +5 -0
+	}
+
+	if (cgu) {
+		ret = dpll_device_register(pf->dplls.eec.dpll, DPLL_TYPE_EEC,
+					   &ice_dpll_ops, pf, dev);
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1440

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +5 -0
+		if (ret)
+			goto put_pps;
+		ret = dpll_device_register(pf->dplls.pps.dpll, DPLL_TYPE_PPS,
+					   &ice_dpll_ops, pf, dev);
+		if (ret)

You are missing call to dpll_device_unregister(pf->dplls.eec.dpll, DPLL_TYPE_EEC here. Fix the error path.

Quoted 2 lines

The caller shall do the clean up, but yeah will fix this as here clean up is not expected.

:) Just make your error paths obvious and easy to follow to not to confuse anybody, you included.

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +14 -0
+			goto put_pps;
+	}
+
+	return 0;
+
+put_pps:
+	dpll_device_put(pf->dplls.pps.dpll);
+	pf->dplls.pps.dpll = NULL;
+put_eec:
+	dpll_device_put(pf->dplls.eec.dpll);
+	pf->dplls.eec.dpll = NULL;
+
+	return ret;
+}

[...]

#55 lore raw

RE: [RFC PATCH v7 5/8] ice: implement dpll interface to control cgu

Quoted 51 lines

From: Jiri Pirko <[email protected]>
Sent: Tuesday, May 16, 2023 8:26 AM

Quoted 5 lines · Tue, May 16, 2023 at 12:07:57AM CEST, [email protected] wrote:
Quoted 5 lines

From: Jiri Pirko <[email protected]>
Sent: Wednesday, May 3, 2023 2:19 PM

Quoted 1 line · Fri, Apr 28, 2023 at 02:20:06AM CEST, [email protected] wrote:

From: Arkadiusz Kubalewski <[email protected]>

[...]

Quoted 33 lines
Quoted 33 lines
Quoted 17 lines

+ * ice_dpll_frequency_set - wrapper for pin callback for set frequency
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: pointer to dpll
+ * @frequency: frequency to be set
+ * @extack: error reporting
+ * @pin_type: type of pin being configured
+ *
+ * Wraps internal set frequency command on a pin.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - error pin not found or couldn't set in hw */ static

drivers/net/ethernet/intel/ice/ice_dpll.c new file +4 -0
+int ice_dpll_frequency_set(const struct dpll_pin *pin, void *pin_priv,
+		       const struct dpll_device *dpll,
+		       const u32 frequency,
+		       struct netlink_ext_ack *extack,

drivers/net/ethernet/intel/ice/ice_dpll.c line 243

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+		       const enum ice_dpll_pin_type pin_type) {
+	struct ice_pf *pf = pin_priv;
+	struct ice_dpll_pin *p;
+	int ret = -EINVAL;
+
+	if (!pf)
+		return ret;
+	if (ice_dpll_cb_lock(pf))
+		return -EBUSY;
+	p = ice_find_pin(pf, pin, pin_type);

This does not make any sense to me. You should avoid the lookups and remove ice_find_pin() function entirely. The purpose of having pin_priv is to carry the struct ice_dpll_pin * directly. You should pass it down during pin register.

Quoted 4 lines
Quoted 2 lines

pf pointer is stored in dpll_priv.

In this case dpll_priv is not passed, so cannot use it.

Quoted 9 lines

It should be passed. In general to every op where *dpll is passed, the dpll_priv pointer should be passed along. Please, fix this.

Quoted 2 lines

But in general it makes sense I will hold pf inside of ice_dpll_pin and fix this.

Nope, just use dpll_priv. That's why we have it.

Ok, will propagate it.

Quoted 27 lines

[...]

Quoted 23 lines
Quoted 22 lines
Quoted 9 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +9 -0
+/**
+ * ice_dpll_pin_state_set - set pin's state on dpll
+ * @dpll: dpll being configured
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @state: state of pin to be set
+ * @extack: error reporting
+ * @pin_type: type of a pin
+ *

drivers/net/ethernet/intel/ice/ice_dpll.c line 718

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+ * Set pin state on a pin.
+ *
+ * Return:
+ * * 0 - OK or no change required
+ * * negative - error
+ */
+static int
+ice_dpll_pin_state_set(const struct dpll_device *dpll,
+		       const struct dpll_pin *pin, void *pin_priv,
+		       const enum dpll_pin_state state,

Why you use const with enums?

Quoted 4 lines
Quoted 1 line

Just show usage intention explicitly.

Does not make any sense what so ever. Please avoid it.

Fixed.

Quoted 24 lines
Quoted 24 lines
Quoted 10 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1160

Quoted 8 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +7 -0
+static int ice_dpll_rclk_state_on_pin_get(const struct dpll_pin *pin,
+					  void *pin_priv,
+					  const struct dpll_pin *parent_pin,
+					  enum dpll_pin_state *state,
+					  struct netlink_ext_ack *extack) {
+	struct ice_pf *pf = pin_priv;
+	u32 parent_idx, hw_idx = ICE_DPLL_PIN_IDX_INVALID, i;

Reverse christmas tree ordering please.

Fixed.

Quoted 10 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1164

Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +4 -0
+	struct ice_dpll_pin *p;
+	int ret = -EFAULT;
+
+	if (!pf)

How exacly this can happen. My wild guess is it can't. Don't do such pointless checks please, confuses the reader.

Quoted 7 lines
Quoted 2 lines

From driver perspective the pf pointer value is given by external entity, why shouldn't it be valdiated?

What? You pass it during register, you get it back here. Nothing to check. Please drop it. Non-sense checks like this have no place in kernel, they only confuse reader as he/she assumes it is a valid case.

I have some background from Automotive, MISRA etc. Removed.

Quoted 25 lines

[...]

Quoted 21 lines
Quoted 20 lines
Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +4 -0
+			pins[i].pin = NULL;
+			return -ENOMEM;
+		}
+		if (cgu) {

drivers/net/ethernet/intel/ice/ice_dpll.c line 1343

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+			ret = dpll_pin_register(pf->dplls.eec.dpll,
+						pins[i].pin,
+						ops, pf, NULL);
+			if (ret)
+				return ret;
+			ret = dpll_pin_register(pf->dplls.pps.dpll,
+						pins[i].pin,
+						ops, pf, NULL);
+			if (ret)
+				return ret;

You have to call dpll_pin_unregister(pf->dplls.eec.dpll, pins[i].pin, ..) here.

Quoted 8 lines
Quoted 1 line

No, in case of error, the caller releases everything

ice_dpll_release_all(..).

How does ice_dpll_release_all() where you failed? If you need to unregister one or both or none? I know that in ice you have odd ways to handle error paths in general, but this one clearly seems to be broken.

It doesn't have to, as release all would release all anyway. Leaving it for now.

Quoted 39 lines
Quoted 39 lines
Quoted 20 lines
Quoted 8 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +2 -0
+		}
+	}

drivers/net/ethernet/intel/ice/ice_dpll.c line 1355

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+	if (cgu) {
+		ops = &ice_dpll_output_ops;
+		pins = pf->dplls.outputs;
+		for (i = 0; i < pf->dplls.num_outputs; i++) {
+			pins[i].pin = dpll_pin_get(pf->dplls.clock_id,
+						   i + pf->dplls.num_inputs,
+						   THIS_MODULE, &pins[i].prop);
+			if (IS_ERR_OR_NULL(pins[i].pin)) {
+				pins[i].pin = NULL;
+				return -ENOMEM;

Don't make up error values when you get them from the function you call:

Quoted 1 line
	return PTR_ERR(pins[i].pin);

Fixed.

Quoted 14 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1364

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +9 -0
+			}
+			ret = dpll_pin_register(pf->dplls.eec.dpll, pins[i].pin,
+						ops, pf, NULL);
+			if (ret)
+				return ret;
+			ret = dpll_pin_register(pf->dplls.pps.dpll, pins[i].pin,
+						ops, pf, NULL);
+			if (ret)
+				return ret;

You have to call dpll_pin_unregister(pf->dplls.eec.dpll, pins[i].pin, ..) here.

Quoted 4 lines
Quoted 1 line

As above, in case of error, the caller releases everything.

As above, I don't think it works.

It works, though not all error paths were probably test.. Will take another look on it later.

Quoted 19 lines

[...]

Quoted 15 lines
Quoted 14 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1440

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+	}
+
+	if (cgu) {
+		ret = dpll_device_register(pf->dplls.eec.dpll, DPLL_TYPE_EEC,
+					   &ice_dpll_ops, pf, dev);
+		if (ret)
+			goto put_pps;
+		ret = dpll_device_register(pf->dplls.pps.dpll, DPLL_TYPE_PPS,
+					   &ice_dpll_ops, pf, dev);
+		if (ret)

You are missing call to dpll_device_unregister(pf->dplls.eec.dpll, DPLL_TYPE_EEC here. Fix the error path.

Quoted 6 lines
Quoted 2 lines

The caller shall do the clean up, but yeah will fix this as here clean up is not expected.

:) Just make your error paths obvious and easy to follow to not to confuse anybody, you included.

I am not confused :) it wasn't removed as it should.

Thank you!
Arkadiusz

Quoted 19 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +14 -0
+			goto put_pps;
+	}
+
+	return 0;
+
+put_pps:
+	dpll_device_put(pf->dplls.pps.dpll);
+	pf->dplls.pps.dpll = NULL;
+put_eec:
+	dpll_device_put(pf->dplls.eec.dpll);
+	pf->dplls.eec.dpll = NULL;
+
+	return ret;
+}

[...]

maintainer
#56 lore raw

Re: [RFC PATCH v7 5/8] ice: implement dpll interface to control cgu

Quoted 9 lines · Thu, May 18, 2023 at 06:06:03PM CEST, [email protected] wrote:
Quoted 9 lines

From: Jiri Pirko <[email protected]>
Sent: Tuesday, May 16, 2023 8:26 AM

Quoted 5 lines · Tue, May 16, 2023 at 12:07:57AM CEST, [email protected] wrote:
Quoted 5 lines

From: Jiri Pirko <[email protected]>
Sent: Wednesday, May 3, 2023 2:19 PM

Quoted 1 line · Fri, Apr 28, 2023 at 02:20:06AM CEST, [email protected] wrote:

From: Arkadiusz Kubalewski <[email protected]>

[...]

Quoted 23 lines
Quoted 23 lines
Quoted 19 lines
Quoted 9 lines
Quoted 9 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +9 -0
+			pins[i].pin = NULL;
+			return -ENOMEM;
+		}
+		if (cgu) {
+			ret = dpll_pin_register(pf->dplls.eec.dpll,
+						pins[i].pin,
+						ops, pf, NULL);
+			if (ret)
+				return ret;
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1343

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +5 -0
+			ret = dpll_pin_register(pf->dplls.pps.dpll,
+						pins[i].pin,
+						ops, pf, NULL);
+			if (ret)
+				return ret;

You have to call dpll_pin_unregister(pf->dplls.eec.dpll, pins[i].pin, ..) here.

Quoted 1 line

No, in case of error, the caller releases everything

ice_dpll_release_all(..).

Quoted 7 lines
Quoted 4 lines

How does ice_dpll_release_all() where you failed? If you need to unregister one or both or none? I know that in ice you have odd ways to handle error paths in general, but this one clearly seems to be broken.

It doesn't have to, as release all would release all anyway. Leaving it for now.

So you call dpll_pin_unregister() even for the pin that was not registered before? How is that even remotely correct?

Fix your error paths, please. I don't understand the resistance here :)

[...]

#57 lore raw

RE: [RFC PATCH v7 5/8] ice: implement dpll interface to control cgu

Quoted 50 lines

From: Jiri Pirko <[email protected]>
Sent: Friday, May 19, 2023 8:15 AM

Quoted 10 lines · Thu, May 18, 2023 at 06:06:03PM CEST, [email protected] wrote:
Quoted 10 lines

From: Jiri Pirko <[email protected]>
Sent: Tuesday, May 16, 2023 8:26 AM

Tue, May 16, 2023 at 12:07:57AM CEST, [email protected]

Quoted 5 lines · wrote:
Quoted 5 lines

From: Jiri Pirko <[email protected]>
Sent: Wednesday, May 3, 2023 2:19 PM

Quoted 1 line · Fri, Apr 28, 2023 at 02:20:06AM CEST, [email protected] wrote:

From: Arkadiusz Kubalewski <[email protected]>

[...]

Quoted 24 lines
Quoted 24 lines
Quoted 20 lines
Quoted 10 lines
Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+			pins[i].pin = NULL;
+			return -ENOMEM;
+		}
+		if (cgu) {
+			ret = dpll_pin_register(pf->dplls.eec.dpll,
+						pins[i].pin,
+						ops, pf, NULL);
+			if (ret)
+				return ret;
+			ret = dpll_pin_register(pf->dplls.pps.dpll,
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1338

Quoted 4 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +4 -0
+						pins[i].pin,
+						ops, pf, NULL);
+			if (ret)
+				return ret;

You have to call dpll_pin_unregister(pf->dplls.eec.dpll, pins[i].pin, ..)
here.

Quoted 1 line

No, in case of error, the caller releases everything

ice_dpll_release_all(..).

Quoted 7 lines
Quoted 4 lines

How does ice_dpll_release_all() where you failed? If you need to unregister one or both or none? I know that in ice you have odd ways to handle error paths in general, but this one clearly seems to be broken.

It doesn't have to, as release all would release all anyway. Leaving it for now.

Quoted 6 lines

So you call dpll_pin_unregister() even for the pin that was not registered before? How is that even remotely correct?

Fix your error paths, please. I don't understand the resistance here :)

[...]

Fixed.

Thank you,
Arkadiusz

maintainer
#58 lore raw

Re: [RFC PATCH v7 5/8] ice: implement dpll interface to control cgu

In reply to Jiri Pirko
Quoted 213 lines · Jiri Pirko
Quoted 5 lines · Tue, May 16, 2023 at 12:07:57AM CEST, [email protected] wrote:
Quoted 5 lines

From: Jiri Pirko <[email protected]>
Sent: Wednesday, May 3, 2023 2:19 PM

Quoted 1 line · Fri, Apr 28, 2023 at 02:20:06AM CEST, [email protected] wrote:

From: Arkadiusz Kubalewski <[email protected]>

[...]

Quoted 33 lines
Quoted 33 lines
Quoted 17 lines

+ * ice_dpll_frequency_set - wrapper for pin callback for set frequency
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: pointer to dpll
+ * @frequency: frequency to be set
+ * @extack: error reporting
+ * @pin_type: type of pin being configured
+ *
+ * Wraps internal set frequency command on a pin.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - error pin not found or couldn't set in hw */ static

drivers/net/ethernet/intel/ice/ice_dpll.c new file +4 -0
+int ice_dpll_frequency_set(const struct dpll_pin *pin, void *pin_priv,
+		       const struct dpll_device *dpll,
+		       const u32 frequency,
+		       struct netlink_ext_ack *extack,

drivers/net/ethernet/intel/ice/ice_dpll.c line 243

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+		       const enum ice_dpll_pin_type pin_type) {
+	struct ice_pf *pf = pin_priv;
+	struct ice_dpll_pin *p;
+	int ret = -EINVAL;
+
+	if (!pf)
+		return ret;
+	if (ice_dpll_cb_lock(pf))
+		return -EBUSY;
+	p = ice_find_pin(pf, pin, pin_type);

This does not make any sense to me. You should avoid the lookups and remove ice_find_pin() function entirely. The purpose of having pin_priv is to carry the struct ice_dpll_pin * directly. You should pass it down during pin register.

Quoted 4 lines
Quoted 2 lines

pf pointer is stored in dpll_priv.

In this case dpll_priv is not passed, so cannot use it.

It should be passed. In general to every op where *dpll is passed, the dpll_priv pointer should be passed along. Please, fix this.

Quoted 2 lines

But in general it makes sense I will hold pf inside of ice_dpll_pin and fix this.

Nope, just use dpll_priv. That's why we have it.

[...]

Quoted 23 lines
Quoted 13 lines
Quoted 13 lines

+/**
+ * ice_dpll_pin_state_set - set pin's state on dpll
+ * @dpll: dpll being configured
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @state: state of pin to be set
+ * @extack: error reporting
+ * @pin_type: type of a pin
+ *
+ * Set pin state on a pin.
+ *
+ * Return:
+ * * 0 - OK or no change required

Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 718

Quoted 6 lines

+ * * negative - error
+ */

drivers/net/ethernet/intel/ice/ice_dpll.c new file +4 -0
+static int
+ice_dpll_pin_state_set(const struct dpll_device *dpll,
+		       const struct dpll_pin *pin, void *pin_priv,
+		       const enum dpll_pin_state state,

Why you use const with enums?

Quoted 1 line

Just show usage intention explicitly.

Does not make any sense what so ever. Please avoid it.

Quoted 23 lines
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1160

Quoted 7 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +7 -0
+static int ice_dpll_rclk_state_on_pin_get(const struct dpll_pin *pin,
+					  void *pin_priv,
+					  const struct dpll_pin *parent_pin,
+					  enum dpll_pin_state *state,
+					  struct netlink_ext_ack *extack) {
+	struct ice_pf *pf = pin_priv;
+	u32 parent_idx, hw_idx = ICE_DPLL_PIN_IDX_INVALID, i;

Reverse christmas tree ordering please.

Fixed.

Quoted 10 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1164

Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +4 -0
+	struct ice_dpll_pin *p;
+	int ret = -EFAULT;
+
+	if (!pf)

How exacly this can happen. My wild guess is it can't. Don't do such pointless checks please, confuses the reader.

Quoted 2 lines

From driver perspective the pf pointer value is given by external entity, why shouldn't it be valdiated?

What? You pass it during register, you get it back here. Nothing to check. Please drop it. Non-sense checks like this have no place in kernel, they only confuse reader as he/she assumes it is a valid case.

[...]

Quoted 21 lines
Quoted 11 lines
Quoted 11 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +9 -0
+			pins[i].pin = NULL;
+			return -ENOMEM;
+		}
+		if (cgu) {
+			ret = dpll_pin_register(pf->dplls.eec.dpll,
+						pins[i].pin,
+						ops, pf, NULL);
+			if (ret)
+				return ret;
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1343

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +5 -0
+			ret = dpll_pin_register(pf->dplls.pps.dpll,
+						pins[i].pin,
+						ops, pf, NULL);
+			if (ret)
+				return ret;

You have to call dpll_pin_unregister(pf->dplls.eec.dpll, pins[i].pin, ..) here.

Quoted 1 line

No, in case of error, the caller releases everything ice_dpll_release_all(..).

How does ice_dpll_release_all() where you failed? If you need to unregister one or both or none? I know that in ice you have odd ways to handle error paths in general, but this one clearly seems to be broken.

Quoted 35 lines
Quoted 16 lines
Quoted 4 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +2 -0
+		}
+	}

drivers/net/ethernet/intel/ice/ice_dpll.c line 1355

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+	if (cgu) {
+		ops = &ice_dpll_output_ops;
+		pins = pf->dplls.outputs;
+		for (i = 0; i < pf->dplls.num_outputs; i++) {
+			pins[i].pin = dpll_pin_get(pf->dplls.clock_id,
+						   i + pf->dplls.num_inputs,
+						   THIS_MODULE, &pins[i].prop);
+			if (IS_ERR_OR_NULL(pins[i].pin)) {
+				pins[i].pin = NULL;
+				return -ENOMEM;

Don't make up error values when you get them from the function you call:

Quoted 1 line
	return PTR_ERR(pins[i].pin);

Fixed.

Quoted 14 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1364

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +9 -0
+			}
+			ret = dpll_pin_register(pf->dplls.eec.dpll, pins[i].pin,
+						ops, pf, NULL);
+			if (ret)
+				return ret;
+			ret = dpll_pin_register(pf->dplls.pps.dpll, pins[i].pin,
+						ops, pf, NULL);
+			if (ret)
+				return ret;

You have to call dpll_pin_unregister(pf->dplls.eec.dpll, pins[i].pin, ..) here.

Quoted 1 line

As above, in case of error, the caller releases everything.

As above, I don't think it works.

[...]

Quoted 15 lines
Quoted 14 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1440

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+	}
+
+	if (cgu) {
+		ret = dpll_device_register(pf->dplls.eec.dpll, DPLL_TYPE_EEC,
+					   &ice_dpll_ops, pf, dev);
+		if (ret)
+			goto put_pps;
+		ret = dpll_device_register(pf->dplls.pps.dpll, DPLL_TYPE_PPS,
+					   &ice_dpll_ops, pf, dev);
+		if (ret)

You are missing call to dpll_device_unregister(pf->dplls.eec.dpll, DPLL_TYPE_EEC here. Fix the error path.

Quoted 5 lines
Quoted 2 lines

The caller shall do the clean up, but yeah will fix this as here clean up is not expected.

:) Just make your error paths obvious and easy to follow to not to confuse anybody, you included.

I agree with Jiri. The error paths here and in ice_dpll_init_info() are quite confusing and IMHO error prone.

It will get more easy toread and more consistent if every initialization function does return an error code would leave the state clean in case of error. That is, in case of error, such function should cleanup all the partially allocated/initialized resources.

Note that in ice_dpll_init_info() the situation is more mixed-up as ice_dpll_release_info() is called on most error paths, except the last one. Memory should not leaked due to later ice_dpll_release_all(), but it's really confusing.

Cheers,

Paolo

#59 lore raw

RE: [RFC PATCH v7 5/8] ice: implement dpll interface to control cgu

Quoted 245 lines

From: Paolo Abeni <[email protected]>
Sent: Friday, May 19, 2023 8:48 AM

Quoted 226 lines · Jiri Pirko

Tue, May 16, 2023 at 12:07:57AM CEST, [email protected]

Quoted 6 lines
Quoted 6 lines

wrote:
From: Jiri Pirko <[email protected]>
Sent: Wednesday, May 3, 2023 2:19 PM

Quoted 1 line · Fri, Apr 28, 2023 at 02:20:06AM CEST, [email protected] wrote:

From: Arkadiusz Kubalewski <[email protected]>

[...]

Quoted 39 lines
Quoted 39 lines
Quoted 20 lines

+ * ice_dpll_frequency_set - wrapper for pin callback for set frequency
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @dpll: pointer to dpll
+ * @frequency: frequency to be set
+ * @extack: error reporting
+ * @pin_type: type of pin being configured
+ *
+ * Wraps internal set frequency command on a pin.
+ *
+ * Return:
+ * * 0 - success
+ * * negative - error pin not found or couldn't set in hw */ static
+int ice_dpll_frequency_set(const struct dpll_pin *pin, void *pin_priv,

drivers/net/ethernet/intel/ice/ice_dpll.c new file +3 -0
+		       const struct dpll_device *dpll,
+		       const u32 frequency,
+		       struct netlink_ext_ack *extack,

drivers/net/ethernet/intel/ice/ice_dpll.c line 243

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+		       const enum ice_dpll_pin_type pin_type) {
+	struct ice_pf *pf = pin_priv;
+	struct ice_dpll_pin *p;
+	int ret = -EINVAL;
+
+	if (!pf)
+		return ret;
+	if (ice_dpll_cb_lock(pf))
+		return -EBUSY;
+	p = ice_find_pin(pf, pin, pin_type);

This does not make any sense to me. You should avoid the lookups and remove
ice_find_pin() function entirely. The purpose of having pin_priv is to
carry the struct ice_dpll_pin * directly. You should pass it down during
pin register.

Quoted 4 lines
Quoted 2 lines

pf pointer is stored in dpll_priv.

In this case dpll_priv is not passed, so cannot use it.

It should be passed. In general to every op where *dpll is passed, the dpll_priv pointer should be passed along. Please, fix this.

Quoted 2 lines

But in general it makes sense I will hold pf inside of ice_dpll_pin and fix this.

Nope, just use dpll_priv. That's why we have it.

[...]

Quoted 23 lines
Quoted 13 lines
Quoted 13 lines

+/**
+ * ice_dpll_pin_state_set - set pin's state on dpll
+ * @dpll: dpll being configured
+ * @pin: pointer to a pin
+ * @pin_priv: private data pointer passed on pin registration
+ * @state: state of pin to be set
+ * @extack: error reporting
+ * @pin_type: type of a pin
+ *
+ * Set pin state on a pin.
+ *
+ * Return:
+ * * 0 - OK or no change required

Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 718

Quoted 6 lines

+ * * negative - error
+ */

drivers/net/ethernet/intel/ice/ice_dpll.c new file +4 -0
+static int
+ice_dpll_pin_state_set(const struct dpll_device *dpll,
+		       const struct dpll_pin *pin, void *pin_priv,
+		       const enum dpll_pin_state state,

Why you use const with enums?

Quoted 1 line

Just show usage intention explicitly.

Does not make any sense what so ever. Please avoid it.

Quoted 23 lines
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1160

Quoted 7 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +7 -0
+static int ice_dpll_rclk_state_on_pin_get(const struct dpll_pin *pin,
+					  void *pin_priv,
+					  const struct dpll_pin *parent_pin,
+					  enum dpll_pin_state *state,
+					  struct netlink_ext_ack *extack) {
+	struct ice_pf *pf = pin_priv;
+	u32 parent_idx, hw_idx = ICE_DPLL_PIN_IDX_INVALID, i;

Reverse christmas tree ordering please.

Fixed.

Quoted 10 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1164

Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +4 -0
+	struct ice_dpll_pin *p;
+	int ret = -EFAULT;
+
+	if (!pf)

How exacly this can happen. My wild guess is it can't. Don't do such pointless checks please, confuses the reader.

Quoted 2 lines

From driver perspective the pf pointer value is given by external entity, why shouldn't it be valdiated?

What? You pass it during register, you get it back here. Nothing to check. Please drop it. Non-sense checks like this have no place in kernel, they only confuse reader as he/she assumes it is a valid case.

[...]

Quoted 21 lines
Quoted 11 lines
Quoted 11 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +9 -0
+			pins[i].pin = NULL;
+			return -ENOMEM;
+		}
+		if (cgu) {
+			ret = dpll_pin_register(pf->dplls.eec.dpll,
+						pins[i].pin,
+						ops, pf, NULL);
+			if (ret)
+				return ret;
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1343

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +5 -0
+			ret = dpll_pin_register(pf->dplls.pps.dpll,
+						pins[i].pin,
+						ops, pf, NULL);
+			if (ret)
+				return ret;

You have to call dpll_pin_unregister(pf->dplls.eec.dpll, pins[i].pin, ..) here.

Quoted 2 lines

No, in case of error, the caller releases everything ice_dpll_release_all(..).

How does ice_dpll_release_all() where you failed? If you need to unregister one or both or none? I know that in ice you have odd ways to handle error paths in general, but this one clearly seems to be broken.

Quoted 18 lines
Quoted 16 lines
Quoted 4 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +2 -0
+		}
+	}

drivers/net/ethernet/intel/ice/ice_dpll.c line 1355

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +10 -0
+	if (cgu) {
+		ops = &ice_dpll_output_ops;
+		pins = pf->dplls.outputs;
+		for (i = 0; i < pf->dplls.num_outputs; i++) {
+			pins[i].pin = dpll_pin_get(pf->dplls.clock_id,
+						   i + pf->dplls.num_inputs,
+						   THIS_MODULE, &pins[i].prop);
+			if (IS_ERR_OR_NULL(pins[i].pin)) {
+				pins[i].pin = NULL;
+				return -ENOMEM;

Don't make up error values when you get them from the function you call:

Quoted 1 line
	return PTR_ERR(pins[i].pin);
Quoted 16 lines

Fixed.

Quoted 14 lines

drivers/net/ethernet/intel/ice/ice_dpll.c line 1338

Quoted 12 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +2 -0
+			}
+			ret = dpll_pin_register(pf->dplls.eec.dpll,

pins[i].pin,

drivers/net/ethernet/intel/ice/ice_dpll.c new file +4 -0
+						ops, pf, NULL);
+			if (ret)
+				return ret;
+			ret = dpll_pin_register(pf->dplls.pps.dpll,

pins[i].pin,

drivers/net/ethernet/intel/ice/ice_dpll.c new file +3 -0
+						ops, pf, NULL);
+			if (ret)
+				return ret;

You have to call dpll_pin_unregister(pf->dplls.eec.dpll, pins[i].pin,

..)

Quoted 4 lines
Quoted 2 lines

here.

As above, in case of error, the caller releases everything.

As above, I don't think it works.

[...]

Quoted 17 lines
Quoted 16 lines

Review

Quoted 12 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +4 -0
+	}
+
+	if (cgu) {
+		ret = dpll_device_register(pf->dplls.eec.dpll,

DPLL_TYPE_EEC,

drivers/net/ethernet/intel/ice/ice_dpll.c new file +4 -0
+					   &ice_dpll_ops, pf, dev);
+		if (ret)
+			goto put_pps;
+		ret = dpll_device_register(pf->dplls.pps.dpll,

DPLL_TYPE_PPS,

(quoted diff) +2 -0
+					   &ice_dpll_ops, pf, dev);
+		if (ret)

You are missing call to dpll_device_unregister(pf->dplls.eec.dpll, DPLL_TYPE_EEC here. Fix the error path.

Quoted 5 lines
Quoted 2 lines

The caller shall do the clean up, but yeah will fix this as here clean up is not expected.

:) Just make your error paths obvious and easy to follow to not to confuse anybody, you included.

I agree with Jiri. The error paths here and in ice_dpll_init_info() are quite confusing and IMHO error prone.

It will get more easy toread and more consistent if every initialization function does return an error code would leave the state clean in case of error. That is, in case of error, such function should cleanup all the partially allocated/initialized resources.

Quoted 8 lines

Note that in ice_dpll_init_info() the situation is more mixed-up as ice_dpll_release_info() is called on most error paths, except the last one. Memory should not leaked due to later ice_dpll_release_all(), but it's really confusing.

Cheers,

Paolo

Fixed.

Thank you,
Arkadiusz

maintainer
#60 lore raw

Re: [RFC PATCH v7 5/8] ice: implement dpll interface to control cgu

In reply to Vadim Fedorenko

Fri, Apr 28, 2023 at 02:20:06AM CEST, [email protected] wrote:

[...]

drivers/net/ethernet/intel/ice/ice_dpll.c line 21

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +5 -0
+static const enum dpll_lock_status
+ice_dpll_status[__DPLL_LOCK_STATUS_MAX] = {
+	[ICE_CGU_STATE_INVALID] = DPLL_LOCK_STATUS_UNSPEC,
+	[ICE_CGU_STATE_FREERUN] = DPLL_LOCK_STATUS_UNLOCKED,
+	[ICE_CGU_STATE_LOCKED] = DPLL_LOCK_STATUS_CALIBRATING,

This is a bit confusing to me. You are locked, yet you report calibrating? Wouldn't it be better to have:
DPLL_LOCK_STATUS_LOCKED DPLL_LOCK_STATUS_LOCKED_HO_ACQ

?

Quoted 3 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +3 -0
+	[ICE_CGU_STATE_LOCKED_HO_ACQ] = DPLL_LOCK_STATUS_LOCKED,
+	[ICE_CGU_STATE_HOLDOVER] = DPLL_LOCK_STATUS_HOLDOVER,
+};

[...]

#61 lore raw

RE: [RFC PATCH v7 5/8] ice: implement dpll interface to control cgu

Quoted 18 lines

From: Jiri Pirko <[email protected]>
Sent: Monday, May 15, 2023 7:13 PM

Fri, Apr 28, 2023 at 02:20:06AM CEST, [email protected] wrote:

[...]

drivers/net/ethernet/intel/ice/ice_dpll.c line 21

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +5 -0
+static const enum dpll_lock_status
+ice_dpll_status[__DPLL_LOCK_STATUS_MAX] = {
+	[ICE_CGU_STATE_INVALID] = DPLL_LOCK_STATUS_UNSPEC,
+	[ICE_CGU_STATE_FREERUN] = DPLL_LOCK_STATUS_UNLOCKED,
+	[ICE_CGU_STATE_LOCKED] = DPLL_LOCK_STATUS_CALIBRATING,

This is a bit confusing to me. You are locked, yet you report calibrating? Wouldn't it be better to have:
DPLL_LOCK_STATUS_LOCKED DPLL_LOCK_STATUS_LOCKED_HO_ACQ

Quoted 2 lines

?

Sure makes sense, will add this state.

Quoted 6 lines
Quoted 4 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +3 -0
+	[ICE_CGU_STATE_LOCKED_HO_ACQ] = DPLL_LOCK_STATUS_LOCKED,
+	[ICE_CGU_STATE_HOLDOVER] = DPLL_LOCK_STATUS_HOLDOVER,
+};

[...]

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer
#62 lore raw

Re: [RFC PATCH v7 5/8] ice: implement dpll interface to control cgu

Quoted 18 lines · Tue, May 16, 2023 at 11:22:37AM CEST, [email protected] wrote:
Quoted 18 lines

From: Jiri Pirko <[email protected]>
Sent: Monday, May 15, 2023 7:13 PM

Fri, Apr 28, 2023 at 02:20:06AM CEST, [email protected] wrote:

[...]

drivers/net/ethernet/intel/ice/ice_dpll.c line 21

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +5 -0
+static const enum dpll_lock_status
+ice_dpll_status[__DPLL_LOCK_STATUS_MAX] = {
+	[ICE_CGU_STATE_INVALID] = DPLL_LOCK_STATUS_UNSPEC,
+	[ICE_CGU_STATE_FREERUN] = DPLL_LOCK_STATUS_UNLOCKED,
+	[ICE_CGU_STATE_LOCKED] = DPLL_LOCK_STATUS_CALIBRATING,

This is a bit confusing to me. You are locked, yet you report calibrating? Wouldn't it be better to have:
DPLL_LOCK_STATUS_LOCKED DPLL_LOCK_STATUS_LOCKED_HO_ACQ

Quoted 4 lines
Quoted 2 lines

?

Sure makes sense, will add this state.

Do you need "calibrating" then? I mean, the docs says:
``LOCK_STATUS_CALIBRATING`` dpll device calibrates to lock to the
source pin signal

Yet you do: [ICE_CGU_STATE_LOCKED] = DPLL_LOCK_STATUS_CALIBRATING Seems like you should have:
[ICE_CGU_STATE_LOCKED] = DPLL_LOCK_STATUS_LOCKED [ICE_CGU_STATE_LOCKED_HO_ACQ] = DPLL_LOCK_STATUS_LOCKED_HO_ACQ,

and remove DPLL_LOCK_STATUS_CALIBRATING as it would be unused?

Also, as a sidenote, could you use the whole names of enum value names in documentation? Simple reason, greppability.

Thanks!

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +3 -0
+	[ICE_CGU_STATE_LOCKED_HO_ACQ] = DPLL_LOCK_STATUS_LOCKED,
+	[ICE_CGU_STATE_HOLDOVER] = DPLL_LOCK_STATUS_HOLDOVER,
+};

[...]

#63 lore raw

RE: [RFC PATCH v7 5/8] ice: implement dpll interface to control cgu

Quoted 36 lines

From: Jiri Pirko <[email protected]>
Sent: Tuesday, May 16, 2023 1:47 PM

Quoted 18 lines · Tue, May 16, 2023 at 11:22:37AM CEST, [email protected] wrote:
Quoted 18 lines

From: Jiri Pirko <[email protected]>
Sent: Monday, May 15, 2023 7:13 PM

Fri, Apr 28, 2023 at 02:20:06AM CEST, [email protected] wrote:

[...]

drivers/net/ethernet/intel/ice/ice_dpll.c line 21

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +5 -0
+static const enum dpll_lock_status
+ice_dpll_status[__DPLL_LOCK_STATUS_MAX] = {
+	[ICE_CGU_STATE_INVALID] = DPLL_LOCK_STATUS_UNSPEC,
+	[ICE_CGU_STATE_FREERUN] = DPLL_LOCK_STATUS_UNLOCKED,
+	[ICE_CGU_STATE_LOCKED] = DPLL_LOCK_STATUS_CALIBRATING,

This is a bit confusing to me. You are locked, yet you report calibrating? Wouldn't it be better to have:
DPLL_LOCK_STATUS_LOCKED DPLL_LOCK_STATUS_LOCKED_HO_ACQ

Quoted 4 lines
Quoted 2 lines

?

Sure makes sense, will add this state.

Do you need "calibrating" then? I mean, the docs says:
``LOCK_STATUS_CALIBRATING`` dpll device calibrates to lock to the
source pin signal

Yet you do: [ICE_CGU_STATE_LOCKED] = DPLL_LOCK_STATUS_CALIBRATING Seems like you should have:
[ICE_CGU_STATE_LOCKED] = DPLL_LOCK_STATUS_LOCKED [ICE_CGU_STATE_LOCKED_HO_ACQ] = DPLL_LOCK_STATUS_LOCKED_HO_ACQ,

Quoted 5 lines

and remove DPLL_LOCK_STATUS_CALIBRATING as it would be unused?

Also, as a sidenote, could you use the whole names of enum value names in documentation? Simple reason, greppability.

Yes, removed CALIBRATING.
Fixed the docs.

Thank you!
Arkadiusz

Quoted 10 lines

Thanks!

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +3 -0
+	[ICE_CGU_STATE_LOCKED_HO_ACQ] = DPLL_LOCK_STATUS_LOCKED,
+	[ICE_CGU_STATE_HOLDOVER] = DPLL_LOCK_STATUS_HOLDOVER,
+};

[...]

maintainer
#64 lore raw

Re: [RFC PATCH v7 5/8] ice: implement dpll interface to control cgu

Quoted 36 lines · Thu, May 18, 2023 at 06:07:33PM CEST, [email protected] wrote:
Quoted 36 lines

From: Jiri Pirko <[email protected]>
Sent: Tuesday, May 16, 2023 1:47 PM

Quoted 18 lines · Tue, May 16, 2023 at 11:22:37AM CEST, [email protected] wrote:
Quoted 18 lines

From: Jiri Pirko <[email protected]>
Sent: Monday, May 15, 2023 7:13 PM

Fri, Apr 28, 2023 at 02:20:06AM CEST, [email protected] wrote:

[...]

drivers/net/ethernet/intel/ice/ice_dpll.c line 21

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +5 -0
+static const enum dpll_lock_status
+ice_dpll_status[__DPLL_LOCK_STATUS_MAX] = {
+	[ICE_CGU_STATE_INVALID] = DPLL_LOCK_STATUS_UNSPEC,
+	[ICE_CGU_STATE_FREERUN] = DPLL_LOCK_STATUS_UNLOCKED,
+	[ICE_CGU_STATE_LOCKED] = DPLL_LOCK_STATUS_CALIBRATING,

This is a bit confusing to me. You are locked, yet you report calibrating? Wouldn't it be better to have:
DPLL_LOCK_STATUS_LOCKED DPLL_LOCK_STATUS_LOCKED_HO_ACQ

Quoted 4 lines
Quoted 2 lines

?

Sure makes sense, will add this state.

Do you need "calibrating" then? I mean, the docs says:
``LOCK_STATUS_CALIBRATING`` dpll device calibrates to lock to the
source pin signal

Yet you do: [ICE_CGU_STATE_LOCKED] = DPLL_LOCK_STATUS_CALIBRATING Seems like you should have:
[ICE_CGU_STATE_LOCKED] = DPLL_LOCK_STATUS_LOCKED [ICE_CGU_STATE_LOCKED_HO_ACQ] = DPLL_LOCK_STATUS_LOCKED_HO_ACQ,

Quoted 8 lines
Quoted 5 lines

and remove DPLL_LOCK_STATUS_CALIBRATING as it would be unused?

Also, as a sidenote, could you use the whole names of enum value names in documentation? Simple reason, greppability.

Yes, removed CALIBRATING.
Fixed the docs.

Cool, thanks!

Quoted 14 lines

Thank you!
Arkadiusz

Quoted 10 lines

Thanks!

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_dpll.c new file +3 -0
+	[ICE_CGU_STATE_LOCKED_HO_ACQ] = DPLL_LOCK_STATUS_LOCKED,
+	[ICE_CGU_STATE_HOLDOVER] = DPLL_LOCK_STATUS_HOLDOVER,
+};

[...]

#65 lore raw

RFC PATCH v7 6/8 ptp_ocp: implement DPLL ops

In reply to Vadim Fedorenko

From: Vadim Fedorenko <[email protected]>

Implement basic DPLL operations in ptp_ocp driver as the simplest example of using new subsystem.

---
 drivers/ptp/Kconfig   |   1 +
 drivers/ptp/ptp_ocp.c | 327 +++++++++++++++++++++++++++++++++++-------
 2 files changed, 276 insertions(+), 52 deletions(-)
drivers/ptp/Kconfig +1 -0
index b00201d81313..e3575c2e34dc 100644
@@ -177,6 +177,7 @@ config PTP_1588_CLOCK_OCP
 	depends on COMMON_CLK
 	select NET_DEVLINK
 	select CRC16
+	select DPLL
 	help
 	  This driver adds support for an OpenCompute time card.
 
drivers/ptp/ptp_ocp.c +275 -52

497 lines not on this page · raw message

Signature · 1 line
2.34.1
#66 lore raw

Re: [RFC PATCH v7 6/8] ptp_ocp: implement DPLL ops

kernel test robot noticed the following build warnings:

Hi Vadim,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:

[auto build test WARNING on v6.3]
[cannot apply to tnguy-next-queue/dev-queue linus/master next-20230427] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Vadim-Fedorenko/dpll-spec-Add-Netlink-spec-in-YAML/20230428-082340
base:   457391b0380335d5e9a5babdec90ac53928b23b4
patch link:    https://lore.kernel.org/r/20230428002009.2948020-7-vadfed%40meta.com
patch subject: [RFC PATCH v7 6/8] ptp_ocp: implement DPLL ops
config: x86_64-randconfig-a005 (https://download.01.org/0day-ci/archive/20230428/[email protected]/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/45d9112b4633e7cea8984cb09cc5f55203a8ec32
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Vadim-Fedorenko/dpll-spec-Add-Netlink-spec-in-YAML/20230428-082340
git checkout 45d9112b4633e7cea8984cb09cc5f55203a8ec32
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/dpll/ drivers/ptp/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> drivers/dpll/dpll_core.c:296:1: warning: no previous prototype for function 'dpll_xa_ref_dpll_find' [-Wmissing-prototypes]

dpll_xa_ref_dpll_find(struct xarray *xa_refs, const struct dpll_device *dpll)
^
drivers/dpll/dpll_core.c:295:1: note: declare 'static' if the function is not intended to be used outside of this translation unit struct dpll_pin_ref *
^
static
1 warning generated.
--

>> drivers/dpll/dpll_netlink.c:969:13: warning: no previous prototype for function 'dpll_netlink_fini' [-Wmissing-prototypes]
   void __exit dpll_netlink_fini(void)
               ^

drivers/dpll/dpll_netlink.c:969:1: note: declare 'static' if the function is not intended to be used outside of this translation unit void __exit dpll_netlink_fini(void)
^
static
1 warning generated.
--

>> drivers/ptp/ptp_ocp.c:4314:37: warning: variable 'val' is uninitialized when used here [-Wuninitialized]
                           return ptp_ocp_sma_store_val(bp, val, sma->mode, sma_nr);
                                                            ^~~
   drivers/ptp/ptp_ocp.c:4306:9: note: initialize the variable 'val' to silence this warning
           int val, i;
                  ^
                   = 0

1 warning generated.

vim +/val +4314 drivers/ptp/ptp_ocp.c

4295
4296 static int ptp_ocp_dpll_frequency_set(const struct dpll_pin *pin,

  4297					      void *pin_priv,
  4298					      const struct dpll_device *dpll,
  4299					      void *dpll_priv, u64 frequency,
  4300					      struct netlink_ext_ack *extack)
  4301	{
  4302		struct ptp_ocp_sma_connector *sma = pin_priv;
  4303		struct ptp_ocp *bp = dpll_priv;
  4304		const struct ocp_selector *tbl;
  4305		int sma_nr = (sma - bp->sma);
  4306		int val, i;
  4307	
  4308		if (sma->fixed_fcn)
  4309			return -EOPNOTSUPP;
  4310	
  4311		tbl = bp->sma_op->tbl[sma->mode];
  4312		for (i = 0; tbl[i].name; i++)
  4313			if (tbl[i].frequency == frequency)
> 4314				return ptp_ocp_sma_store_val(bp, val, sma->mode, sma_nr);

4315 return -EINVAL;
4316 }
4317

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
maintainer
#67 lore raw

Re: [RFC PATCH v7 6/8] ptp_ocp: implement DPLL ops

In reply to Vadim Fedorenko
Quoted 36 lines · Fri, Apr 28, 2023 at 02:20:07AM CEST, [email protected] wrote:

From: Vadim Fedorenko <[email protected]>

Implement basic DPLL operations in ptp_ocp driver as the simplest example of using new subsystem.

---
drivers/ptp/Kconfig | 1 +
drivers/ptp/ptp_ocp.c | 327 +++++++++++++++++++++++++++++++++++-------

2 files changed, 276 insertions(+), 52 deletions(-)
drivers/ptp/Kconfig +1 -0
index b00201d81313..e3575c2e34dc 100644
@@ -177,6 +177,7 @@ config PTP_1588_CLOCK_OCP
 	depends on COMMON_CLK
 	select NET_DEVLINK
 	select CRC16
+	select DPLL
 	help
 	  This driver adds support for an OpenCompute time card.
 
drivers/ptp/ptp_ocp.c +1 -0
index 2b63f3487645..100e5da0aeb3 100644
@@ -23,6 +23,7 @@
 #include <linux/mtd/mtd.h>
 #include <linux/nvmem-consumer.h>
 #include <linux/crc16.h>
+#include <linux/dpll.h>
 
 #define PCI_VENDOR_ID_FACEBOOK			0x1d9b
 #define PCI_DEVICE_ID_FACEBOOK_TIMECARD		0x0400

drivers/ptp/ptp_ocp.c enum ptp_ocp_sma_mode { · line 265

Quoted 4 lines
drivers/ptp/ptp_ocp.c +1 -0
@@ -261,12 +262,21 @@ enum ptp_ocp_sma_mode {
 	SMA_MODE_OUT,
 };
 
+static struct dpll_pin_frequency ptp_ocp_sma_freq[] = {

const

Quoted 122 lines
drivers/ptp/ptp_ocp.c +38 -27
+	DPLL_PIN_FREQUENCY_1PPS,
+	DPLL_PIN_FREQUENCY_10MHZ,
+	DPLL_PIN_FREQUENCY_IRIG_B,
+	DPLL_PIN_FREQUENCY_DCF77,
+};
+
 struct ptp_ocp_sma_connector {
 	enum	ptp_ocp_sma_mode mode;
 	bool	fixed_fcn;
 	bool	fixed_dir;
 	bool	disabled;
 	u8	default_fcn;
+	struct dpll_pin		   *dpll_pin;
+	struct dpll_pin_properties dpll_prop;
 };
 
 struct ocp_attr_group {
@@ -295,6 +305,7 @@ struct ptp_ocp_serial_port {
 
 #define OCP_BOARD_ID_LEN		13
 #define OCP_SERIAL_LEN			6
+#define OCP_SMA_NUM			4
 
 struct ptp_ocp {
 	struct pci_dev		*pdev;
@@ -351,8 +362,9 @@ struct ptp_ocp {
 	u32			ts_window_adjust;
 	u64			fw_cap;
 	struct ptp_ocp_signal	signal[4];
-	struct ptp_ocp_sma_connector sma[4];
+	struct ptp_ocp_sma_connector sma[OCP_SMA_NUM];
 	const struct ocp_sma_op *sma_op;
+	struct dpll_device *dpll;
 };
 
 #define OCP_REQ_TIMESTAMP	BIT(0)
@@ -836,6 +848,7 @@ static DEFINE_IDR(ptp_ocp_idr);
 struct ocp_selector {
 	const char *name;
 	int value;
+	u64 frequency;
 };
 
 static const struct ocp_selector ptp_ocp_clock[] = {
@@ -856,31 +869,31 @@ static const struct ocp_selector ptp_ocp_clock[] = {
 #define SMA_SELECT_MASK		GENMASK(14, 0)
 
 static const struct ocp_selector ptp_ocp_sma_in[] = {
-	{ .name = "10Mhz",	.value = 0x0000 },
-	{ .name = "PPS1",	.value = 0x0001 },
-	{ .name = "PPS2",	.value = 0x0002 },
-	{ .name = "TS1",	.value = 0x0004 },
-	{ .name = "TS2",	.value = 0x0008 },
-	{ .name = "IRIG",	.value = 0x0010 },
-	{ .name = "DCF",	.value = 0x0020 },
-	{ .name = "TS3",	.value = 0x0040 },
-	{ .name = "TS4",	.value = 0x0080 },
-	{ .name = "FREQ1",	.value = 0x0100 },
-	{ .name = "FREQ2",	.value = 0x0200 },
-	{ .name = "FREQ3",	.value = 0x0400 },
-	{ .name = "FREQ4",	.value = 0x0800 },
-	{ .name = "None",	.value = SMA_DISABLE },
+	{ .name = "10Mhz",  .value = 0x0000,      .frequency = 10000000 },
+	{ .name = "PPS1",   .value = 0x0001,      .frequency = 1 },
+	{ .name = "PPS2",   .value = 0x0002,      .frequency = 1 },
+	{ .name = "TS1",    .value = 0x0004,      .frequency = 0 },
+	{ .name = "TS2",    .value = 0x0008,      .frequency = 0 },
+	{ .name = "IRIG",   .value = 0x0010,      .frequency = 10000 },
+	{ .name = "DCF",    .value = 0x0020,      .frequency = 77500 },
+	{ .name = "TS3",    .value = 0x0040,      .frequency = 0 },
+	{ .name = "TS4",    .value = 0x0080,      .frequency = 0 },
+	{ .name = "FREQ1",  .value = 0x0100,      .frequency = 0 },
+	{ .name = "FREQ2",  .value = 0x0200,      .frequency = 0 },
+	{ .name = "FREQ3",  .value = 0x0400,      .frequency = 0 },
+	{ .name = "FREQ4",  .value = 0x0800,      .frequency = 0 },
+	{ .name = "None",   .value = SMA_DISABLE, .frequency = 0 },
 	{ }
 };
 
 static const struct ocp_selector ptp_ocp_sma_out[] = {
-	{ .name = "10Mhz",	.value = 0x0000 },
-	{ .name = "PHC",	.value = 0x0001 },
-	{ .name = "MAC",	.value = 0x0002 },
-	{ .name = "GNSS1",	.value = 0x0004 },
-	{ .name = "GNSS2",	.value = 0x0008 },
-	{ .name = "IRIG",	.value = 0x0010 },
-	{ .name = "DCF",	.value = 0x0020 },
+	{ .name = "10Mhz",	.value = 0x0000,  .frequency = 10000000 },
+	{ .name = "PHC",	.value = 0x0001,  .frequency = 1 },
+	{ .name = "MAC",	.value = 0x0002,  .frequency = 1 },
+	{ .name = "GNSS1",	.value = 0x0004,  .frequency = 1 },
+	{ .name = "GNSS2",	.value = 0x0008,  .frequency = 1 },
+	{ .name = "IRIG",	.value = 0x0010,  .frequency = 10000 },
+	{ .name = "DCF",	.value = 0x0020,  .frequency = 77000 },
 	{ .name = "GEN1",	.value = 0x0040 },
 	{ .name = "GEN2",	.value = 0x0080 },
 	{ .name = "GEN3",	.value = 0x0100 },
@@ -891,15 +904,15 @@ static const struct ocp_selector ptp_ocp_sma_out[] = {
 };
 
 static const struct ocp_selector ptp_ocp_art_sma_in[] = {
-	{ .name = "PPS1",	.value = 0x0001 },
-	{ .name = "10Mhz",	.value = 0x0008 },
+	{ .name = "PPS1",	.value = 0x0001,  .frequency = 1 },
+	{ .name = "10Mhz",	.value = 0x0008,  .frequency = 1000000 },
 	{ }
 };
 
 static const struct ocp_selector ptp_ocp_art_sma_out[] = {
-	{ .name = "PHC",	.value = 0x0002 },
-	{ .name = "GNSS",	.value = 0x0004 },
-	{ .name = "10Mhz",	.value = 0x0010 },
+	{ .name = "PHC",	.value = 0x0002,  .frequency = 1 },
+	{ .name = "GNSS",	.value = 0x0004,  .frequency = 1 },
+	{ .name = "10Mhz",	.value = 0x0010,  .frequency = 10000000 },
 	{ }
 };
 
@@ -2283,22 +2296,34 @@ ptp_ocp_sma_fb_set_inputs(struct ptp_ocp *bp, int sma_nr, u32 val)

static void
ptp_ocp_sma_fb_init(struct ptp_ocp *bp)
{

drivers/ptp/ptp_ocp.c

Quoted 1 line
drivers/ptp/ptp_ocp.c +1 -0
+	struct dpll_pin_properties prop = {

Why don't you have this as static const outside the function?

drivers/ptp/ptp_ocp.c

Quoted 1 line
drivers/ptp/ptp_ocp.c +1 -0
+		.label = NULL,

Pointless init.

Quoted 74 lines
drivers/ptp/ptp_ocp.c +6 -0
+		.type = DPLL_PIN_TYPE_EXT,
+		.capabilities = DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE,
+		.freq_supported_num = ARRAY_SIZE(ptp_ocp_sma_freq),
+		.freq_supported = ptp_ocp_sma_freq,
+
+	};
	u32 reg;
	int i;

	/* defaults */
drivers/ptp/ptp_ocp.c +5 -0
+	for (i = 0; i < OCP_SMA_NUM; i++) {
+		bp->sma[i].default_fcn = i & 1;
+		bp->sma[i].dpll_prop = prop;
+		bp->sma[i].dpll_prop.label = bp->ptp_info.pin_config[i].name;
+	}
	bp->sma[0].mode = SMA_MODE_IN;
	bp->sma[1].mode = SMA_MODE_IN;
	bp->sma[2].mode = SMA_MODE_OUT;
	bp->sma[3].mode = SMA_MODE_OUT;
drivers/ptp/ptp_ocp.c +0 -3
-	for (i = 0; i < 4; i++)
-		bp->sma[i].default_fcn = i & 1;
-
	/* If no SMA1 map, the pin functions and directions are fixed. */
	if (!bp->sma_map1) {
drivers/ptp/ptp_ocp.c +1 -1
-		for (i = 0; i < 4; i++) {
+		for (i = 0; i < OCP_SMA_NUM; i++) {
			bp->sma[i].fixed_fcn = true;
			bp->sma[i].fixed_dir = true;
drivers/ptp/ptp_ocp.c +2 -0
+			bp->sma[1].dpll_prop.capabilities &=
+				~DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE;
		}
		return;
	}
drivers/ptp/ptp_ocp.c +1 -1
@@ -2308,7 +2333,7 @@ ptp_ocp_sma_fb_init(struct ptp_ocp *bp)
 	 */
 	reg = ioread32(&bp->sma_map2->gpio2);
 	if (reg == 0xffffffff) {
-		for (i = 0; i < 4; i++)
+		for (i = 0; i < OCP_SMA_NUM; i++)
 			bp->sma[i].fixed_dir = true;
 	} else {
 		reg = ioread32(&bp->sma_map1->gpio1);
@@ -2330,7 +2355,7 @@ static const struct ocp_sma_op ocp_fb_sma_op = {
 };
 

static int

drivers/ptp/ptp_ocp.c +1 -1
-ptp_ocp_fb_set_pins(struct ptp_ocp *bp)
+ptp_ocp_set_pins(struct ptp_ocp *bp)
{
	struct ptp_pin_desc *config;
	int i;
drivers/ptp/ptp_ocp.c +2 -2
@@ -2397,16 +2422,16 @@ ptp_ocp_fb_board_init(struct ptp_ocp *bp, struct ocp_resource *r)
 
 	ptp_ocp_tod_init(bp);
 	ptp_ocp_nmea_out_init(bp);
-	ptp_ocp_sma_init(bp);
 	ptp_ocp_signal_init(bp);
 
 	err = ptp_ocp_attr_group_add(bp, fb_timecard_groups);
 	if (err)
 		return err;
 
-	err = ptp_ocp_fb_set_pins(bp);
+	err = ptp_ocp_set_pins(bp);
 	if (err)
 		return err;
+	ptp_ocp_sma_init(bp);
 
 	return ptp_ocp_init_clock(bp);
 }
@@ -2446,6 +2471,14 @@ ptp_ocp_register_resources(struct ptp_ocp *bp, kernel_ulong_t driver_data)

static void
ptp_ocp_art_sma_init(struct ptp_ocp *bp)
{

drivers/ptp/ptp_ocp.c ptp_ocp_register_resources(struct ptp_ocp *bp, kernel_ulong_t driver_data) · line 2477

Quoted 4 lines
drivers/ptp/ptp_ocp.c +4 -0
+	struct dpll_pin_properties prop = {
+		.label = NULL,
+		.type = DPLL_PIN_TYPE_EXT,
+		.capabilities = 0,

Same comment as to the similar prop struct above. Plus another pointless init here.

Quoted 98 lines
drivers/ptp/ptp_ocp.c +4 -0
+		.freq_supported_num = ARRAY_SIZE(ptp_ocp_sma_freq),
+		.freq_supported = ptp_ocp_sma_freq,
+
+	};
	u32 reg;
	int i;
drivers/ptp/ptp_ocp.c +14 -7
@@ -2460,16 +2493,16 @@ ptp_ocp_art_sma_init(struct ptp_ocp *bp)
 	bp->sma[2].default_fcn = 0x10;	/* OUT: 10Mhz */
 	bp->sma[3].default_fcn = 0x02;	/* OUT: PHC */
 
-	/* If no SMA map, the pin functions and directions are fixed. */
-	if (!bp->art_sma) {
-		for (i = 0; i < 4; i++) {
+
+	for (i = 0; i < OCP_SMA_NUM; i++) {
+		/* If no SMA map, the pin functions and directions are fixed. */
+		bp->sma[i].dpll_prop = prop;
+		bp->sma[i].dpll_prop.label = bp->ptp_info.pin_config[i].name;
+		if (!bp->art_sma) {
 			bp->sma[i].fixed_fcn = true;
 			bp->sma[i].fixed_dir = true;
+			continue;
 		}
-		return;
-	}
-
-	for (i = 0; i < 4; i++) {
 		reg = ioread32(&bp->art_sma->map[i].gpio);
 
 		switch (reg & 0xff) {
@@ -2480,9 +2513,13 @@ ptp_ocp_art_sma_init(struct ptp_ocp *bp)
 		case 1:
 		case 8:
 			bp->sma[i].mode = SMA_MODE_IN;
+			bp->sma[i].dpll_prop.capabilities =
+				DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE;
 			break;
 		default:
 			bp->sma[i].mode = SMA_MODE_OUT;
+			bp->sma[i].dpll_prop.capabilities =
+				DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE;
 			break;
 		}
 	}
@@ -2549,6 +2586,9 @@ ptp_ocp_art_board_init(struct ptp_ocp *bp, struct ocp_resource *r)
 	/* Enable MAC serial port during initialisation */
 	iowrite32(1, &bp->board_config->mro50_serial_activate);
 
+	err = ptp_ocp_set_pins(bp);
+	if (err)
+		return err;
 	ptp_ocp_sma_init(bp);
 
 	err = ptp_ocp_attr_group_add(bp, art_timecard_groups);
@@ -2690,16 +2730,9 @@ sma4_show(struct device *dev, struct device_attribute *attr, char *buf)
 }
 

static int

drivers/ptp/ptp_ocp.c +1 -1
-ptp_ocp_sma_store(struct ptp_ocp *bp, const char *buf, int sma_nr)
+ptp_ocp_sma_store_val(struct ptp_ocp *bp, int val, enum ptp_ocp_sma_mode mode, int sma_nr)
{
	struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr - 1];
drivers/ptp/ptp_ocp.c +0 -7
-	enum ptp_ocp_sma_mode mode;
-	int val;
-
-	mode = sma->mode;
-	val = sma_parse_inputs(bp->sma_op->tbl, buf, &mode);
-	if (val < 0)
-		return val;
	if (sma->fixed_dir && (mode != sma->mode || val & SMA_DISABLE))
		return -EOPNOTSUPP;
drivers/ptp/ptp_ocp.c +14 -0
@@ -2734,6 +2767,20 @@ ptp_ocp_sma_store(struct ptp_ocp *bp, const char *buf, int sma_nr)
 	return val;
 }
 
+static int
+ptp_ocp_sma_store(struct ptp_ocp *bp, const char *buf, int sma_nr)
+{
+	struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr - 1];
+	enum ptp_ocp_sma_mode mode;
+	int val;
+
+	mode = sma->mode;
+	val = sma_parse_inputs(bp->sma_op->tbl, buf, &mode);
+	if (val < 0)
+		return val;
+	return ptp_ocp_sma_store_val(bp, val, mode, sma_nr);
+}
+

static ssize_t
sma1_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)

drivers/ptp/ptp_ocp.c +0 -0
@@ -4172,12 +4219,148 @@ ptp_ocp_detach(struct ptp_ocp *bp)
 	device_unregister(&bp->dev);
 }
 

drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4231

Quoted 10 lines
drivers/ptp/ptp_ocp.c +10 -0
+static int ptp_ocp_dpll_lock_status_get(const struct dpll_device *dpll,
+					void *priv,
+					enum dpll_lock_status *status,
+					struct netlink_ext_ack *extack)
+{
+	struct ptp_ocp *bp = priv;
+	int sync;
+
+	sync = ioread32(&bp->reg->status) & OCP_STATUS_IN_SYNC;
+	*status = sync ? DPLL_LOCK_STATUS_LOCKED : DPLL_LOCK_STATUS_UNLOCKED;

Does your device support event delivery in case of the status change? ice and mlx5 drivers do poll for changes in this area anyway. It's a part of this patchset. You should do the same if your device does not support events.

Could you please implement notifications using dpll_device_notify() for status change and dpll_pin_notify() for pin state change?

Quoted 49 lines
drivers/ptp/ptp_ocp.c +49 -0
+
+	return 0;
+}
+
+static int ptp_ocp_dpll_source_idx_get(const struct dpll_device *dpll,
+				       void *priv, u32 *idx,
+				       struct netlink_ext_ack *extack)
+{
+	struct ptp_ocp *bp = priv;
+
+	if (bp->pps_select) {
+		*idx = ioread32(&bp->pps_select->gpio1);
+		return 0;
+	}
+	return -EINVAL;
+}
+
+static int ptp_ocp_dpll_mode_get(const struct dpll_device *dpll, void *priv,
+				 u32 *mode, struct netlink_ext_ack *extack)
+{
+	*mode = DPLL_MODE_AUTOMATIC;
+	return 0;
+}
+
+static bool ptp_ocp_dpll_mode_supported(const struct dpll_device *dpll,
+					void *priv, const enum dpll_mode mode,
+					struct netlink_ext_ack *extack)
+{
+	return mode == DPLL_MODE_AUTOMATIC;
+}
+
+static int ptp_ocp_dpll_direction_get(const struct dpll_pin *pin,
+				      void *pin_priv,
+				      const struct dpll_device *dpll,
+				      void *priv,
+				      enum dpll_pin_direction *direction,
+				      struct netlink_ext_ack *extack)
+{
+	struct ptp_ocp_sma_connector *sma = pin_priv;
+
+	*direction = sma->mode == SMA_MODE_IN ?
+				  DPLL_PIN_DIRECTION_SOURCE :
+				  DPLL_PIN_DIRECTION_OUTPUT;
+	return 0;
+}
+
+static int ptp_ocp_dpll_direction_set(const struct dpll_pin *pin,
+				      void *pin_priv,
+				      const struct dpll_device *dpll,

drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4290

Quoted 10 lines
drivers/ptp/ptp_ocp.c +10 -0
+				      void *dpll_priv,
+				      enum dpll_pin_direction direction,
+				      struct netlink_ext_ack *extack)
+{
+	struct ptp_ocp_sma_connector *sma = pin_priv;
+	struct ptp_ocp *bp = dpll_priv;
+	enum ptp_ocp_sma_mode mode;
+	int sma_nr = (sma - bp->sma);
+
+	if (sma->fixed_dir)

I believe that this is a pointless check as DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE is not set and therefore the check in dpll_pin_direction_set() will be true and -EOPNOTSUPP will be returned from there.
Remove this.

drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4294

Quoted 4 lines
drivers/ptp/ptp_ocp.c +4 -0
+		return -EOPNOTSUPP;
+	mode = direction == DPLL_PIN_DIRECTION_SOURCE ?
+			    SMA_MODE_IN : SMA_MODE_OUT;
+	return ptp_ocp_sma_store_val(bp, 0, mode, sma_nr);

You need sma_nr just here. Why can't you change ptp_ocp_sma_store_val() to accept struct ptp_ocp_sma_connector * instead avoiding the need for tne sma_nr completely?

Quoted 5 lines
drivers/ptp/ptp_ocp.c +5 -0
+}
+
+static int ptp_ocp_dpll_frequency_set(const struct dpll_pin *pin,
+				      void *pin_priv,
+				      const struct dpll_device *dpll,

drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4309

Quoted 10 lines
drivers/ptp/ptp_ocp.c +10 -0
+				      void *dpll_priv, u64 frequency,
+				      struct netlink_ext_ack *extack)
+{
+	struct ptp_ocp_sma_connector *sma = pin_priv;
+	struct ptp_ocp *bp = dpll_priv;
+	const struct ocp_selector *tbl;
+	int sma_nr = (sma - bp->sma);
+	int val, i;
+
+	if (sma->fixed_fcn)

In that case, just fill up a single frequency in the properties, avoid this check-fail and let the dpll core handle it.

Quoted 9 lines
drivers/ptp/ptp_ocp.c +9 -0
+		return -EOPNOTSUPP;
+
+	tbl = bp->sma_op->tbl[sma->mode];
+	for (i = 0; tbl[i].name; i++)
+		if (tbl[i].frequency == frequency)
+			return ptp_ocp_sma_store_val(bp, val, sma->mode, sma_nr);
+	return -EINVAL;
+}
+

drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4328

Quoted 10 lines
drivers/ptp/ptp_ocp.c +10 -0
+static int ptp_ocp_dpll_frequency_get(const struct dpll_pin *pin,
+				      void *pin_priv,
+				      const struct dpll_device *dpll,
+				      void *dpll_priv, u64 *frequency,
+				      struct netlink_ext_ack *extack)
+{
+	struct ptp_ocp_sma_connector *sma = pin_priv;
+	struct ptp_ocp *bp = dpll_priv;
+	const struct ocp_selector *tbl;
+	int sma_nr = (sma - bp->sma);

1) void "()"s here.
2) why don't you fill the sma_nr in struct ptp_ocp_sma_connector to make this easier to follow? IDK, just a suggestion, take or leave.

Same applies to the the rest of similar occurances above.

Quoted 7 lines
drivers/ptp/ptp_ocp.c +7 -0
+	u32 val;
+	int i;
+
+	val = bp->sma_op->get(bp, sma_nr);
+	tbl = bp->sma_op->tbl[sma->mode];
+	for (i = 0; tbl[i].name; i++)
+		if (val == tbl[i].value) {

drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4345

Quoted 10 lines
drivers/ptp/ptp_ocp.c +10 -0
+			*frequency = tbl[i].frequency;
+			return 0;
+		}
+
+	return -EINVAL;
+}
+
+static const struct dpll_device_ops dpll_ops = {
+	.lock_status_get = ptp_ocp_dpll_lock_status_get,
+	.source_pin_idx_get = ptp_ocp_dpll_source_idx_get,

This op is a leftover, in dpll core it is not called. This was removed and agreed that drivers should implement state_on_dpll_get() op for pins to see which one is connected.

Please fix here and remove the leftover from DPLL patch #2 as well.

Quoted 23 lines
drivers/ptp/ptp_ocp.c +11 -0
+	.mode_get = ptp_ocp_dpll_mode_get,
+	.mode_supported = ptp_ocp_dpll_mode_supported,
+};
+
+static const struct dpll_pin_ops dpll_pins_ops = {
+	.frequency_get = ptp_ocp_dpll_frequency_get,
+	.frequency_set = ptp_ocp_dpll_frequency_set,
+	.direction_get = ptp_ocp_dpll_direction_get,
+	.direction_set = ptp_ocp_dpll_direction_set,
+};
+

static int
ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)

{
	struct devlink *devlink;
	struct ptp_ocp *bp;
drivers/ptp/ptp_ocp.c +2 -1
-	int err;
+	int err, i;
+	u64 clkid;
	devlink = devlink_alloc(&ptp_ocp_devlink_ops, sizeof(*bp), &pdev->dev);
	if (!devlink) {

drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4415

Quoted 7 lines
drivers/ptp/ptp_ocp.c +2 -1
@@ -4227,8 +4410,39 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
 	ptp_ocp_info(bp);
 	devlink_register(devlink);
-	return 0;
 
+	clkid = pci_get_dsn(pdev);
+	bp->dpll = dpll_device_get(clkid, 0, THIS_MODULE);

I suggested this the last time, but again: Could you please:
1) rename dpll_device_get to __dpll_device_get
2) introduce dpll_device_get as a macro filling up THIS_MODULE

Then drivers will just call always:
bp->dpll = dpll_device_get(clkid, 0);
and the macro will fillup the module automatically.

Please do the same for dpll_pin_get()

drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4417

Quoted 2 lines
drivers/ptp/ptp_ocp.c +2 -0
+	if (IS_ERR(bp->dpll)) {
+		dev_err(&pdev->dev, "dpll_device_alloc failed\n");

You need to fix your error path to call devlink_unregister() in this case.

drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4422

Quoted 5 lines
drivers/ptp/ptp_ocp.c +5 -0
+		goto out;
+	}
+
+	err = dpll_device_register(bp->dpll, DPLL_TYPE_PPS, &dpll_ops, bp, &pdev->dev);
+	if (err)

You need to fix your error path to call dpll_device_put() in this case.

Quoted 9 lines
drivers/ptp/ptp_ocp.c +9 -0
+		goto out;
+
+	for (i = 0; i < OCP_SMA_NUM; i++) {
+		bp->sma[i].dpll_pin = dpll_pin_get(clkid, i, THIS_MODULE, &bp->sma[i].dpll_prop);
+		if (IS_ERR(bp->sma[i].dpll_pin))
+			goto out_dpll;
+
+		err = dpll_pin_register(bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops,
+					&bp->sma[i], NULL);

drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4441

Quoted 10 lines
drivers/ptp/ptp_ocp.c +10 -0
+		if (err) {
+			dpll_pin_put(bp->sma[i].dpll_pin);
+			goto out_dpll;
+		}
+	}
+
+	return 0;
+out_dpll:
+	while (i) {
+		--i;
	while (i--) {
	?
Quoted 8 lines
drivers/ptp/ptp_ocp.c +4 -0
+		dpll_pin_unregister(bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, &bp->sma[i]);
+		dpll_pin_put(bp->sma[i].dpll_pin);
+	}
+	dpll_device_put(bp->dpll);

out:

	ptp_ocp_detach(bp);

out_disable:

drivers/ptp/ptp_ocp.c ptp_ocp_remove(struct pci_dev *pdev) · line 4463

Quoted 7 lines
drivers/ptp/ptp_ocp.c +3 -0
@@ -4243,7 +4457,16 @@ ptp_ocp_remove(struct pci_dev *pdev)
 {
 	struct ptp_ocp *bp = pci_get_drvdata(pdev);
 	struct devlink *devlink = priv_to_devlink(bp);
+	int i;
 
+	for (i = 0; i < OCP_SMA_NUM; i++) {
+		if (bp->sma[i].dpll_pin) {

Remove this pointless check. It is always true.

Quoted 12 lines
drivers/ptp/ptp_ocp.c +6 -0
+			dpll_pin_unregister(bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, bp);
+			dpll_pin_put(bp->sma[i].dpll_pin);
+		}
+	}
+	dpll_device_unregister(bp->dpll, &dpll_ops, bp);
+	dpll_device_put(bp->dpll);
 	devlink_unregister(devlink);
 	ptp_ocp_detach(bp);
 	pci_disable_device(pdev);
Signature · 1 line
2.34.1
maintainer
#68 lore raw

Re: [RFC PATCH v7 6/8] ptp_ocp: implement DPLL ops

Quoted 40 lines · Jiri Pirko
Quoted 39 lines · Fri, Apr 28, 2023 at 02:20:07AM CEST, [email protected] wrote:

From: Vadim Fedorenko <[email protected]>

Implement basic DPLL operations in ptp_ocp driver as the simplest example of using new subsystem.

---
drivers/ptp/Kconfig | 1 +
drivers/ptp/ptp_ocp.c | 327 +++++++++++++++++++++++++++++++++++-------

2 files changed, 276 insertions(+), 52 deletions(-)
drivers/ptp/Kconfig +1 -0
index b00201d81313..e3575c2e34dc 100644
@@ -177,6 +177,7 @@ config PTP_1588_CLOCK_OCP
 	depends on COMMON_CLK
 	select NET_DEVLINK
 	select CRC16
+	select DPLL
 	help
 	  This driver adds support for an OpenCompute time card.
 
drivers/ptp/ptp_ocp.c +1 -0
index 2b63f3487645..100e5da0aeb3 100644
@@ -23,6 +23,7 @@
 #include <linux/mtd/mtd.h>
 #include <linux/nvmem-consumer.h>
 #include <linux/crc16.h>
+#include <linux/dpll.h>
 
 #define PCI_VENDOR_ID_FACEBOOK			0x1d9b
 #define PCI_DEVICE_ID_FACEBOOK_TIMECARD		0x0400
@@ -261,12 +262,21 @@ enum ptp_ocp_sma_mode {
 	SMA_MODE_OUT,
 };
 
Quoted 3 lines

drivers/ptp/ptp_ocp.c enum ptp_ocp_sma_mode { · line 265

Quoted 1 line
drivers/ptp/ptp_ocp.c +1 -0
+static struct dpll_pin_frequency ptp_ocp_sma_freq[] = {

const

Forgot about this one, will change it.

Quoted 119 lines
Quoted 119 lines
drivers/ptp/ptp_ocp.c +38 -27
+	DPLL_PIN_FREQUENCY_1PPS,
+	DPLL_PIN_FREQUENCY_10MHZ,
+	DPLL_PIN_FREQUENCY_IRIG_B,
+	DPLL_PIN_FREQUENCY_DCF77,
+};
+
 struct ptp_ocp_sma_connector {
 	enum	ptp_ocp_sma_mode mode;
 	bool	fixed_fcn;
 	bool	fixed_dir;
 	bool	disabled;
 	u8	default_fcn;
+	struct dpll_pin		   *dpll_pin;
+	struct dpll_pin_properties dpll_prop;
 };
 
 struct ocp_attr_group {
@@ -295,6 +305,7 @@ struct ptp_ocp_serial_port {
 
 #define OCP_BOARD_ID_LEN		13
 #define OCP_SERIAL_LEN			6
+#define OCP_SMA_NUM			4
 
 struct ptp_ocp {
 	struct pci_dev		*pdev;
@@ -351,8 +362,9 @@ struct ptp_ocp {
 	u32			ts_window_adjust;
 	u64			fw_cap;
 	struct ptp_ocp_signal	signal[4];
-	struct ptp_ocp_sma_connector sma[4];
+	struct ptp_ocp_sma_connector sma[OCP_SMA_NUM];
 	const struct ocp_sma_op *sma_op;
+	struct dpll_device *dpll;
 };
 
 #define OCP_REQ_TIMESTAMP	BIT(0)
@@ -836,6 +848,7 @@ static DEFINE_IDR(ptp_ocp_idr);
 struct ocp_selector {
 	const char *name;
 	int value;
+	u64 frequency;
 };
 
 static const struct ocp_selector ptp_ocp_clock[] = {
@@ -856,31 +869,31 @@ static const struct ocp_selector ptp_ocp_clock[] = {
 #define SMA_SELECT_MASK		GENMASK(14, 0)
 
 static const struct ocp_selector ptp_ocp_sma_in[] = {
-	{ .name = "10Mhz",	.value = 0x0000 },
-	{ .name = "PPS1",	.value = 0x0001 },
-	{ .name = "PPS2",	.value = 0x0002 },
-	{ .name = "TS1",	.value = 0x0004 },
-	{ .name = "TS2",	.value = 0x0008 },
-	{ .name = "IRIG",	.value = 0x0010 },
-	{ .name = "DCF",	.value = 0x0020 },
-	{ .name = "TS3",	.value = 0x0040 },
-	{ .name = "TS4",	.value = 0x0080 },
-	{ .name = "FREQ1",	.value = 0x0100 },
-	{ .name = "FREQ2",	.value = 0x0200 },
-	{ .name = "FREQ3",	.value = 0x0400 },
-	{ .name = "FREQ4",	.value = 0x0800 },
-	{ .name = "None",	.value = SMA_DISABLE },
+	{ .name = "10Mhz",  .value = 0x0000,      .frequency = 10000000 },
+	{ .name = "PPS1",   .value = 0x0001,      .frequency = 1 },
+	{ .name = "PPS2",   .value = 0x0002,      .frequency = 1 },
+	{ .name = "TS1",    .value = 0x0004,      .frequency = 0 },
+	{ .name = "TS2",    .value = 0x0008,      .frequency = 0 },
+	{ .name = "IRIG",   .value = 0x0010,      .frequency = 10000 },
+	{ .name = "DCF",    .value = 0x0020,      .frequency = 77500 },
+	{ .name = "TS3",    .value = 0x0040,      .frequency = 0 },
+	{ .name = "TS4",    .value = 0x0080,      .frequency = 0 },
+	{ .name = "FREQ1",  .value = 0x0100,      .frequency = 0 },
+	{ .name = "FREQ2",  .value = 0x0200,      .frequency = 0 },
+	{ .name = "FREQ3",  .value = 0x0400,      .frequency = 0 },
+	{ .name = "FREQ4",  .value = 0x0800,      .frequency = 0 },
+	{ .name = "None",   .value = SMA_DISABLE, .frequency = 0 },
 	{ }
 };
 
 static const struct ocp_selector ptp_ocp_sma_out[] = {
-	{ .name = "10Mhz",	.value = 0x0000 },
-	{ .name = "PHC",	.value = 0x0001 },
-	{ .name = "MAC",	.value = 0x0002 },
-	{ .name = "GNSS1",	.value = 0x0004 },
-	{ .name = "GNSS2",	.value = 0x0008 },
-	{ .name = "IRIG",	.value = 0x0010 },
-	{ .name = "DCF",	.value = 0x0020 },
+	{ .name = "10Mhz",	.value = 0x0000,  .frequency = 10000000 },
+	{ .name = "PHC",	.value = 0x0001,  .frequency = 1 },
+	{ .name = "MAC",	.value = 0x0002,  .frequency = 1 },
+	{ .name = "GNSS1",	.value = 0x0004,  .frequency = 1 },
+	{ .name = "GNSS2",	.value = 0x0008,  .frequency = 1 },
+	{ .name = "IRIG",	.value = 0x0010,  .frequency = 10000 },
+	{ .name = "DCF",	.value = 0x0020,  .frequency = 77000 },
 	{ .name = "GEN1",	.value = 0x0040 },
 	{ .name = "GEN2",	.value = 0x0080 },
 	{ .name = "GEN3",	.value = 0x0100 },
@@ -891,15 +904,15 @@ static const struct ocp_selector ptp_ocp_sma_out[] = {
 };
 
 static const struct ocp_selector ptp_ocp_art_sma_in[] = {
-	{ .name = "PPS1",	.value = 0x0001 },
-	{ .name = "10Mhz",	.value = 0x0008 },
+	{ .name = "PPS1",	.value = 0x0001,  .frequency = 1 },
+	{ .name = "10Mhz",	.value = 0x0008,  .frequency = 1000000 },
 	{ }
 };
 
 static const struct ocp_selector ptp_ocp_art_sma_out[] = {
-	{ .name = "PHC",	.value = 0x0002 },
-	{ .name = "GNSS",	.value = 0x0004 },
-	{ .name = "10Mhz",	.value = 0x0010 },
+	{ .name = "PHC",	.value = 0x0002,  .frequency = 1 },
+	{ .name = "GNSS",	.value = 0x0004,  .frequency = 1 },
+	{ .name = "10Mhz",	.value = 0x0010,  .frequency = 10000000 },
 	{ }
 };
 
Quoted 8 lines

drivers/ptp/ptp_ocp.c

Quoted 5 lines
drivers/ptp/ptp_ocp.c +0 -0
@@ -2283,22 +2296,34 @@ ptp_ocp_sma_fb_set_inputs(struct ptp_ocp *bp, int sma_nr, u32 val)

static void
ptp_ocp_sma_fb_init(struct ptp_ocp *bp)
{

drivers/ptp/ptp_ocp.c +1 -0
+	struct dpll_pin_properties prop = {

Why don't you have this as static const outside the function?

Because I'm changing label string for every pin. I cannot change it in the const object.

Quoted 4 lines

drivers/ptp/ptp_ocp.c

Quoted 2 lines
drivers/ptp/ptp_ocp.c +1 -0
+		.label = NULL,

Pointless init.

Agree

Quoted 68 lines
Quoted 68 lines
drivers/ptp/ptp_ocp.c +6 -0
+		.type = DPLL_PIN_TYPE_EXT,
+		.capabilities = DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE,
+		.freq_supported_num = ARRAY_SIZE(ptp_ocp_sma_freq),
+		.freq_supported = ptp_ocp_sma_freq,
+
+	};
	u32 reg;
	int i;

	/* defaults */
drivers/ptp/ptp_ocp.c +5 -0
+	for (i = 0; i < OCP_SMA_NUM; i++) {
+		bp->sma[i].default_fcn = i & 1;
+		bp->sma[i].dpll_prop = prop;
+		bp->sma[i].dpll_prop.label = bp->ptp_info.pin_config[i].name;
+	}
	bp->sma[0].mode = SMA_MODE_IN;
	bp->sma[1].mode = SMA_MODE_IN;
	bp->sma[2].mode = SMA_MODE_OUT;
	bp->sma[3].mode = SMA_MODE_OUT;
drivers/ptp/ptp_ocp.c +0 -3
-	for (i = 0; i < 4; i++)
-		bp->sma[i].default_fcn = i & 1;
-
	/* If no SMA1 map, the pin functions and directions are fixed. */
	if (!bp->sma_map1) {
drivers/ptp/ptp_ocp.c +1 -1
-		for (i = 0; i < 4; i++) {
+		for (i = 0; i < OCP_SMA_NUM; i++) {
			bp->sma[i].fixed_fcn = true;
			bp->sma[i].fixed_dir = true;
drivers/ptp/ptp_ocp.c +2 -0
+			bp->sma[1].dpll_prop.capabilities &=
+				~DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE;
		}
		return;
	}
drivers/ptp/ptp_ocp.c +1 -1
@@ -2308,7 +2333,7 @@ ptp_ocp_sma_fb_init(struct ptp_ocp *bp)
 	 */
 	reg = ioread32(&bp->sma_map2->gpio2);
 	if (reg == 0xffffffff) {
-		for (i = 0; i < 4; i++)
+		for (i = 0; i < OCP_SMA_NUM; i++)
 			bp->sma[i].fixed_dir = true;
 	} else {
 		reg = ioread32(&bp->sma_map1->gpio1);
@@ -2330,7 +2355,7 @@ static const struct ocp_sma_op ocp_fb_sma_op = {
 };
 

static int

drivers/ptp/ptp_ocp.c +1 -1
-ptp_ocp_fb_set_pins(struct ptp_ocp *bp)
+ptp_ocp_set_pins(struct ptp_ocp *bp)
{
	struct ptp_pin_desc *config;
	int i;
drivers/ptp/ptp_ocp.c +2 -2
@@ -2397,16 +2422,16 @@ ptp_ocp_fb_board_init(struct ptp_ocp *bp, struct ocp_resource *r)
 
 	ptp_ocp_tod_init(bp);
 	ptp_ocp_nmea_out_init(bp);
-	ptp_ocp_sma_init(bp);
 	ptp_ocp_signal_init(bp);
 
 	err = ptp_ocp_attr_group_add(bp, fb_timecard_groups);
 	if (err)
 		return err;
 
-	err = ptp_ocp_fb_set_pins(bp);
+	err = ptp_ocp_set_pins(bp);
 	if (err)
 		return err;
+	ptp_ocp_sma_init(bp);
 
Quoted 14 lines

drivers/ptp/ptp_ocp.c ptp_ocp_register_resources(struct ptp_ocp *bp, kernel_ulong_t driver_data) · line 2477

Quoted 10 lines
drivers/ptp/ptp_ocp.c +0 -0
 	return ptp_ocp_init_clock(bp);
 }
@@ -2446,6 +2471,14 @@ ptp_ocp_register_resources(struct ptp_ocp *bp, kernel_ulong_t driver_data)

static void
ptp_ocp_art_sma_init(struct ptp_ocp *bp)
{

drivers/ptp/ptp_ocp.c +4 -0
+	struct dpll_pin_properties prop = {
+		.label = NULL,
+		.type = DPLL_PIN_TYPE_EXT,
+		.capabilities = 0,

Same comment as to the similar prop struct above. Plus another pointless init here.

Will remove pointless init.

Quoted 115 lines
Quoted 99 lines
drivers/ptp/ptp_ocp.c +4 -0
+		.freq_supported_num = ARRAY_SIZE(ptp_ocp_sma_freq),
+		.freq_supported = ptp_ocp_sma_freq,
+
+	};
	u32 reg;
	int i;
drivers/ptp/ptp_ocp.c +14 -7
@@ -2460,16 +2493,16 @@ ptp_ocp_art_sma_init(struct ptp_ocp *bp)
 	bp->sma[2].default_fcn = 0x10;	/* OUT: 10Mhz */
 	bp->sma[3].default_fcn = 0x02;	/* OUT: PHC */
 
-	/* If no SMA map, the pin functions and directions are fixed. */
-	if (!bp->art_sma) {
-		for (i = 0; i < 4; i++) {
+
+	for (i = 0; i < OCP_SMA_NUM; i++) {
+		/* If no SMA map, the pin functions and directions are fixed. */
+		bp->sma[i].dpll_prop = prop;
+		bp->sma[i].dpll_prop.label = bp->ptp_info.pin_config[i].name;
+		if (!bp->art_sma) {
 			bp->sma[i].fixed_fcn = true;
 			bp->sma[i].fixed_dir = true;
+			continue;
 		}
-		return;
-	}
-
-	for (i = 0; i < 4; i++) {
 		reg = ioread32(&bp->art_sma->map[i].gpio);
 
 		switch (reg & 0xff) {
@@ -2480,9 +2513,13 @@ ptp_ocp_art_sma_init(struct ptp_ocp *bp)
 		case 1:
 		case 8:
 			bp->sma[i].mode = SMA_MODE_IN;
+			bp->sma[i].dpll_prop.capabilities =
+				DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE;
 			break;
 		default:
 			bp->sma[i].mode = SMA_MODE_OUT;
+			bp->sma[i].dpll_prop.capabilities =
+				DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE;
 			break;
 		}
 	}
@@ -2549,6 +2586,9 @@ ptp_ocp_art_board_init(struct ptp_ocp *bp, struct ocp_resource *r)
 	/* Enable MAC serial port during initialisation */
 	iowrite32(1, &bp->board_config->mro50_serial_activate);
 
+	err = ptp_ocp_set_pins(bp);
+	if (err)
+		return err;
 	ptp_ocp_sma_init(bp);
 
 	err = ptp_ocp_attr_group_add(bp, art_timecard_groups);
@@ -2690,16 +2730,9 @@ sma4_show(struct device *dev, struct device_attribute *attr, char *buf)
 }
 

static int

drivers/ptp/ptp_ocp.c +1 -1
-ptp_ocp_sma_store(struct ptp_ocp *bp, const char *buf, int sma_nr)
+ptp_ocp_sma_store_val(struct ptp_ocp *bp, int val, enum ptp_ocp_sma_mode mode, int sma_nr)
{
	struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr - 1];
drivers/ptp/ptp_ocp.c +0 -7
-	enum ptp_ocp_sma_mode mode;
-	int val;
-
-	mode = sma->mode;
-	val = sma_parse_inputs(bp->sma_op->tbl, buf, &mode);
-	if (val < 0)
-		return val;
	if (sma->fixed_dir && (mode != sma->mode || val & SMA_DISABLE))
		return -EOPNOTSUPP;
drivers/ptp/ptp_ocp.c +14 -0
@@ -2734,6 +2767,20 @@ ptp_ocp_sma_store(struct ptp_ocp *bp, const char *buf, int sma_nr)
 	return val;
 }
 
+static int
+ptp_ocp_sma_store(struct ptp_ocp *bp, const char *buf, int sma_nr)
+{
+	struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr - 1];
+	enum ptp_ocp_sma_mode mode;
+	int val;
+
+	mode = sma->mode;
+	val = sma_parse_inputs(bp->sma_op->tbl, buf, &mode);
+	if (val < 0)
+		return val;
+	return ptp_ocp_sma_store_val(bp, val, mode, sma_nr);
+}
+

static ssize_t
sma1_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)

drivers/ptp/ptp_ocp.c +0 -0
@@ -4172,12 +4219,148 @@ ptp_ocp_detach(struct ptp_ocp *bp)
 	device_unregister(&bp->dev);
 }
 

drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4231

Quoted 10 lines
drivers/ptp/ptp_ocp.c +10 -0
+static int ptp_ocp_dpll_lock_status_get(const struct dpll_device *dpll,
+					void *priv,
+					enum dpll_lock_status *status,
+					struct netlink_ext_ack *extack)
+{
+	struct ptp_ocp *bp = priv;
+	int sync;
+
+	sync = ioread32(&bp->reg->status) & OCP_STATUS_IN_SYNC;
+	*status = sync ? DPLL_LOCK_STATUS_LOCKED : DPLL_LOCK_STATUS_UNLOCKED;

Does your device support event delivery in case of the status change? ice and mlx5 drivers do poll for changes in this area anyway. It's a part of this patchset. You should do the same if your device does not support events.

Quoted 4 lines

Could you please implement notifications using dpll_device_notify() for status change and dpll_pin_notify() for pin state change?

We are working on implementation of interrupt-based notifications, that's why I didn't implement polling code. Hopefully it will be ready before the non-RFC patchset submission.

Quoted 57 lines
Quoted 57 lines
drivers/ptp/ptp_ocp.c +56 -0
+
+	return 0;
+}
+
+static int ptp_ocp_dpll_source_idx_get(const struct dpll_device *dpll,
+				       void *priv, u32 *idx,
+				       struct netlink_ext_ack *extack)
+{
+	struct ptp_ocp *bp = priv;
+
+	if (bp->pps_select) {
+		*idx = ioread32(&bp->pps_select->gpio1);
+		return 0;
+	}
+	return -EINVAL;
+}
+
+static int ptp_ocp_dpll_mode_get(const struct dpll_device *dpll, void *priv,
+				 u32 *mode, struct netlink_ext_ack *extack)
+{
+	*mode = DPLL_MODE_AUTOMATIC;
+	return 0;
+}
+
+static bool ptp_ocp_dpll_mode_supported(const struct dpll_device *dpll,
+					void *priv, const enum dpll_mode mode,
+					struct netlink_ext_ack *extack)
+{
+	return mode == DPLL_MODE_AUTOMATIC;
+}
+
+static int ptp_ocp_dpll_direction_get(const struct dpll_pin *pin,
+				      void *pin_priv,
+				      const struct dpll_device *dpll,
+				      void *priv,
+				      enum dpll_pin_direction *direction,
+				      struct netlink_ext_ack *extack)
+{
+	struct ptp_ocp_sma_connector *sma = pin_priv;
+
+	*direction = sma->mode == SMA_MODE_IN ?
+				  DPLL_PIN_DIRECTION_SOURCE :
+				  DPLL_PIN_DIRECTION_OUTPUT;
+	return 0;
+}
+
+static int ptp_ocp_dpll_direction_set(const struct dpll_pin *pin,
+				      void *pin_priv,
+				      const struct dpll_device *dpll,
+				      void *dpll_priv,
+				      enum dpll_pin_direction direction,
+				      struct netlink_ext_ack *extack)
+{
+	struct ptp_ocp_sma_connector *sma = pin_priv;
+	struct ptp_ocp *bp = dpll_priv;
+	enum ptp_ocp_sma_mode mode;
Quoted 8 lines

drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4290

Quoted 3 lines
drivers/ptp/ptp_ocp.c +3 -0
+	int sma_nr = (sma - bp->sma);
+
+	if (sma->fixed_dir)

I believe that this is a pointless check as DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE is not set and therefore the check in dpll_pin_direction_set() will be true and -EOPNOTSUPP will be returned from there.
Remove this.

Yep, will do it.

Quoted 10 lines

drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4294

Quoted 5 lines
drivers/ptp/ptp_ocp.c +4 -0
+		return -EOPNOTSUPP;
+	mode = direction == DPLL_PIN_DIRECTION_SOURCE ?
+			    SMA_MODE_IN : SMA_MODE_OUT;
+	return ptp_ocp_sma_store_val(bp, 0, mode, sma_nr);

You need sma_nr just here. Why can't you change ptp_ocp_sma_store_val() to accept struct ptp_ocp_sma_connector * instead avoiding the need for tne sma_nr completely?

I wanted to add minimal changes to the driver, I will consider changing this as a separate net-next patch.

Quoted 11 lines
Quoted 11 lines
drivers/ptp/ptp_ocp.c +10 -0
+}
+
+static int ptp_ocp_dpll_frequency_set(const struct dpll_pin *pin,
+				      void *pin_priv,
+				      const struct dpll_device *dpll,
+				      void *dpll_priv, u64 frequency,
+				      struct netlink_ext_ack *extack)
+{
+	struct ptp_ocp_sma_connector *sma = pin_priv;
+	struct ptp_ocp *bp = dpll_priv;
Quoted 9 lines

drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4309

Quoted 5 lines
drivers/ptp/ptp_ocp.c +5 -0
+	const struct ocp_selector *tbl;
+	int sma_nr = (sma - bp->sma);
+	int val, i;
+
+	if (sma->fixed_fcn)

In that case, just fill up a single frequency in the properties, avoid this check-fail and let the dpll core handle it.

Makes sense.

Quoted 25 lines
Quoted 10 lines
drivers/ptp/ptp_ocp.c +9 -0
+		return -EOPNOTSUPP;
+
+	tbl = bp->sma_op->tbl[sma->mode];
+	for (i = 0; tbl[i].name; i++)
+		if (tbl[i].frequency == frequency)
+			return ptp_ocp_sma_store_val(bp, val, sma->mode, sma_nr);
+	return -EINVAL;
+}
+

drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4328

Quoted 10 lines
drivers/ptp/ptp_ocp.c +10 -0
+static int ptp_ocp_dpll_frequency_get(const struct dpll_pin *pin,
+				      void *pin_priv,
+				      const struct dpll_device *dpll,
+				      void *dpll_priv, u64 *frequency,
+				      struct netlink_ext_ack *extack)
+{
+	struct ptp_ocp_sma_connector *sma = pin_priv;
+	struct ptp_ocp *bp = dpll_priv;
+	const struct ocp_selector *tbl;
+	int sma_nr = (sma - bp->sma);

1) void "()"s here.
2) why don't you fill the sma_nr in struct ptp_ocp_sma_connector to make this easier to follow? IDK, just a suggestion, take or leave.

Quoted 2 lines

Same applies to the the rest of similar occurances above.

Will do it, yes.

Quoted 61 lines
Quoted 8 lines
drivers/ptp/ptp_ocp.c +7 -0
+	u32 val;
+	int i;
+
+	val = bp->sma_op->get(bp, sma_nr);
+	tbl = bp->sma_op->tbl[sma->mode];
+	for (i = 0; tbl[i].name; i++)
+		if (val == tbl[i].value) {

drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4345

Quoted 10 lines
drivers/ptp/ptp_ocp.c +10 -0
+			*frequency = tbl[i].frequency;
+			return 0;
+		}
+
+	return -EINVAL;
+}
+
+static const struct dpll_device_ops dpll_ops = {
+	.lock_status_get = ptp_ocp_dpll_lock_status_get,
+	.source_pin_idx_get = ptp_ocp_dpll_source_idx_get,

This op is a leftover, in dpll core it is not called. This was removed and agreed that drivers should implement state_on_dpll_get() op for pins to see which one is connected.

Please fix here and remove the leftover from DPLL patch #2 as well.

Quoted 23 lines
drivers/ptp/ptp_ocp.c +11 -0
+	.mode_get = ptp_ocp_dpll_mode_get,
+	.mode_supported = ptp_ocp_dpll_mode_supported,
+};
+
+static const struct dpll_pin_ops dpll_pins_ops = {
+	.frequency_get = ptp_ocp_dpll_frequency_get,
+	.frequency_set = ptp_ocp_dpll_frequency_set,
+	.direction_get = ptp_ocp_dpll_direction_get,
+	.direction_set = ptp_ocp_dpll_direction_set,
+};
+

static int
ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)

{
	struct devlink *devlink;
	struct ptp_ocp *bp;
drivers/ptp/ptp_ocp.c +2 -1
-	int err;
+	int err, i;
+	u64 clkid;
	devlink = devlink_alloc(&ptp_ocp_devlink_ops, sizeof(*bp), &pdev->dev);
	if (!devlink) {

drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4415

Quoted 7 lines
drivers/ptp/ptp_ocp.c +2 -1
@@ -4227,8 +4410,39 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
 	ptp_ocp_info(bp);
 	devlink_register(devlink);
-	return 0;
 
+	clkid = pci_get_dsn(pdev);
+	bp->dpll = dpll_device_get(clkid, 0, THIS_MODULE);

I suggested this the last time, but again: Could you please:
1) rename dpll_device_get to __dpll_device_get
2) introduce dpll_device_get as a macro filling up THIS_MODULE

Quoted 6 lines

Then drivers will just call always:
bp->dpll = dpll_device_get(clkid, 0);
and the macro will fillup the module automatically.

Please do the same for dpll_pin_get()

Not sure why I have missed this part, but sure will do it.

Quoted 8 lines

drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4417

Quoted 3 lines
drivers/ptp/ptp_ocp.c +2 -0
+	if (IS_ERR(bp->dpll)) {
+		dev_err(&pdev->dev, "dpll_device_alloc failed\n");

You need to fix your error path to call devlink_unregister() in this case.

Quoted 9 lines

drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4422

Quoted 5 lines
drivers/ptp/ptp_ocp.c +5 -0
+		goto out;
+	}
+
+	err = dpll_device_register(bp->dpll, DPLL_TYPE_PPS, &dpll_ops, bp, &pdev->dev);
+	if (err)

You need to fix your error path to call dpll_device_put() in this case.

Ok, I'll re-check and update the error path for the next version.

Quoted 37 lines
Quoted 10 lines
drivers/ptp/ptp_ocp.c +9 -0
+		goto out;
+
+	for (i = 0; i < OCP_SMA_NUM; i++) {
+		bp->sma[i].dpll_pin = dpll_pin_get(clkid, i, THIS_MODULE, &bp->sma[i].dpll_prop);
+		if (IS_ERR(bp->sma[i].dpll_pin))
+			goto out_dpll;
+
+		err = dpll_pin_register(bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops,
+					&bp->sma[i], NULL);

drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4441

Quoted 10 lines
drivers/ptp/ptp_ocp.c +10 -0
+		if (err) {
+			dpll_pin_put(bp->sma[i].dpll_pin);
+			goto out_dpll;
+		}
+	}
+
+	return 0;
+out_dpll:
+	while (i) {
+		--i;
	while (i--) {
	?
Quoted 13 lines
drivers/ptp/ptp_ocp.c +4 -0
+		dpll_pin_unregister(bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, &bp->sma[i]);
+		dpll_pin_put(bp->sma[i].dpll_pin);
+	}
+	dpll_device_put(bp->dpll);

out:

	ptp_ocp_detach(bp);

out_disable:

drivers/ptp/ptp_ocp.c +1 -0
@@ -4243,7 +4457,16 @@ ptp_ocp_remove(struct pci_dev *pdev)
 {
 	struct ptp_ocp *bp = pci_get_drvdata(pdev);
 	struct devlink *devlink = priv_to_devlink(bp);
+	int i;
 
Quoted 4 lines

drivers/ptp/ptp_ocp.c ptp_ocp_remove(struct pci_dev *pdev) · line 4463

Quoted 2 lines
drivers/ptp/ptp_ocp.c +2 -0
+	for (i = 0; i < OCP_SMA_NUM; i++) {
+		if (bp->sma[i].dpll_pin) {

Remove this pointless check. It is always true.

Agree.

Quoted 14 lines
Quoted 14 lines
drivers/ptp/ptp_ocp.c +6 -0
+			dpll_pin_unregister(bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, bp);
+			dpll_pin_put(bp->sma[i].dpll_pin);
+		}
+	}
+	dpll_device_unregister(bp->dpll, &dpll_ops, bp);
+	dpll_device_put(bp->dpll);
 	devlink_unregister(devlink);
 	ptp_ocp_detach(bp);
 	pci_disable_device(pdev);
Signature · 1 line
2.34.1
maintainer
#69 lore raw

Re: [RFC PATCH v7 6/8] ptp_ocp: implement DPLL ops

Quoted 175 lines · Fri, May 05, 2023 at 03:43:08PM CEST, [email protected] wrote:
Quoted 40 lines · Jiri Pirko
Quoted 39 lines · Fri, Apr 28, 2023 at 02:20:07AM CEST, [email protected] wrote:

From: Vadim Fedorenko <[email protected]>

Implement basic DPLL operations in ptp_ocp driver as the simplest example of using new subsystem.

---
drivers/ptp/Kconfig | 1 +
drivers/ptp/ptp_ocp.c | 327 +++++++++++++++++++++++++++++++++++-------

2 files changed, 276 insertions(+), 52 deletions(-)
drivers/ptp/Kconfig +1 -0
index b00201d81313..e3575c2e34dc 100644
@@ -177,6 +177,7 @@ config PTP_1588_CLOCK_OCP
 	depends on COMMON_CLK
 	select NET_DEVLINK
 	select CRC16
+	select DPLL
 	help
 	  This driver adds support for an OpenCompute time card.
 
drivers/ptp/ptp_ocp.c +1 -0
index 2b63f3487645..100e5da0aeb3 100644
@@ -23,6 +23,7 @@
 #include <linux/mtd/mtd.h>
 #include <linux/nvmem-consumer.h>
 #include <linux/crc16.h>
+#include <linux/dpll.h>
 
 #define PCI_VENDOR_ID_FACEBOOK			0x1d9b
 #define PCI_DEVICE_ID_FACEBOOK_TIMECARD		0x0400
@@ -261,12 +262,21 @@ enum ptp_ocp_sma_mode {
 	SMA_MODE_OUT,
 };
 
Quoted 3 lines

drivers/ptp/ptp_ocp.c enum ptp_ocp_sma_mode { · line 265

Quoted 1 line
drivers/ptp/ptp_ocp.c +1 -0
+static struct dpll_pin_frequency ptp_ocp_sma_freq[] = {

const

Forgot about this one, will change it.

Quoted 119 lines
Quoted 119 lines
drivers/ptp/ptp_ocp.c +38 -27
+	DPLL_PIN_FREQUENCY_1PPS,
+	DPLL_PIN_FREQUENCY_10MHZ,
+	DPLL_PIN_FREQUENCY_IRIG_B,
+	DPLL_PIN_FREQUENCY_DCF77,
+};
+
 struct ptp_ocp_sma_connector {
 	enum	ptp_ocp_sma_mode mode;
 	bool	fixed_fcn;
 	bool	fixed_dir;
 	bool	disabled;
 	u8	default_fcn;
+	struct dpll_pin		   *dpll_pin;
+	struct dpll_pin_properties dpll_prop;
 };
 
 struct ocp_attr_group {
@@ -295,6 +305,7 @@ struct ptp_ocp_serial_port {
 
 #define OCP_BOARD_ID_LEN		13
 #define OCP_SERIAL_LEN			6
+#define OCP_SMA_NUM			4
 
 struct ptp_ocp {
 	struct pci_dev		*pdev;
@@ -351,8 +362,9 @@ struct ptp_ocp {
 	u32			ts_window_adjust;
 	u64			fw_cap;
 	struct ptp_ocp_signal	signal[4];
-	struct ptp_ocp_sma_connector sma[4];
+	struct ptp_ocp_sma_connector sma[OCP_SMA_NUM];
 	const struct ocp_sma_op *sma_op;
+	struct dpll_device *dpll;
 };
 
 #define OCP_REQ_TIMESTAMP	BIT(0)
@@ -836,6 +848,7 @@ static DEFINE_IDR(ptp_ocp_idr);
 struct ocp_selector {
 	const char *name;
 	int value;
+	u64 frequency;
 };
 
 static const struct ocp_selector ptp_ocp_clock[] = {
@@ -856,31 +869,31 @@ static const struct ocp_selector ptp_ocp_clock[] = {
 #define SMA_SELECT_MASK		GENMASK(14, 0)
 
 static const struct ocp_selector ptp_ocp_sma_in[] = {
-	{ .name = "10Mhz",	.value = 0x0000 },
-	{ .name = "PPS1",	.value = 0x0001 },
-	{ .name = "PPS2",	.value = 0x0002 },
-	{ .name = "TS1",	.value = 0x0004 },
-	{ .name = "TS2",	.value = 0x0008 },
-	{ .name = "IRIG",	.value = 0x0010 },
-	{ .name = "DCF",	.value = 0x0020 },
-	{ .name = "TS3",	.value = 0x0040 },
-	{ .name = "TS4",	.value = 0x0080 },
-	{ .name = "FREQ1",	.value = 0x0100 },
-	{ .name = "FREQ2",	.value = 0x0200 },
-	{ .name = "FREQ3",	.value = 0x0400 },
-	{ .name = "FREQ4",	.value = 0x0800 },
-	{ .name = "None",	.value = SMA_DISABLE },
+	{ .name = "10Mhz",  .value = 0x0000,      .frequency = 10000000 },
+	{ .name = "PPS1",   .value = 0x0001,      .frequency = 1 },
+	{ .name = "PPS2",   .value = 0x0002,      .frequency = 1 },
+	{ .name = "TS1",    .value = 0x0004,      .frequency = 0 },
+	{ .name = "TS2",    .value = 0x0008,      .frequency = 0 },
+	{ .name = "IRIG",   .value = 0x0010,      .frequency = 10000 },
+	{ .name = "DCF",    .value = 0x0020,      .frequency = 77500 },
+	{ .name = "TS3",    .value = 0x0040,      .frequency = 0 },
+	{ .name = "TS4",    .value = 0x0080,      .frequency = 0 },
+	{ .name = "FREQ1",  .value = 0x0100,      .frequency = 0 },
+	{ .name = "FREQ2",  .value = 0x0200,      .frequency = 0 },
+	{ .name = "FREQ3",  .value = 0x0400,      .frequency = 0 },
+	{ .name = "FREQ4",  .value = 0x0800,      .frequency = 0 },
+	{ .name = "None",   .value = SMA_DISABLE, .frequency = 0 },
 	{ }
 };
 
 static const struct ocp_selector ptp_ocp_sma_out[] = {
-	{ .name = "10Mhz",	.value = 0x0000 },
-	{ .name = "PHC",	.value = 0x0001 },
-	{ .name = "MAC",	.value = 0x0002 },
-	{ .name = "GNSS1",	.value = 0x0004 },
-	{ .name = "GNSS2",	.value = 0x0008 },
-	{ .name = "IRIG",	.value = 0x0010 },
-	{ .name = "DCF",	.value = 0x0020 },
+	{ .name = "10Mhz",	.value = 0x0000,  .frequency = 10000000 },
+	{ .name = "PHC",	.value = 0x0001,  .frequency = 1 },
+	{ .name = "MAC",	.value = 0x0002,  .frequency = 1 },
+	{ .name = "GNSS1",	.value = 0x0004,  .frequency = 1 },
+	{ .name = "GNSS2",	.value = 0x0008,  .frequency = 1 },
+	{ .name = "IRIG",	.value = 0x0010,  .frequency = 10000 },
+	{ .name = "DCF",	.value = 0x0020,  .frequency = 77000 },
 	{ .name = "GEN1",	.value = 0x0040 },
 	{ .name = "GEN2",	.value = 0x0080 },
 	{ .name = "GEN3",	.value = 0x0100 },
@@ -891,15 +904,15 @@ static const struct ocp_selector ptp_ocp_sma_out[] = {
 };
 
 static const struct ocp_selector ptp_ocp_art_sma_in[] = {
-	{ .name = "PPS1",	.value = 0x0001 },
-	{ .name = "10Mhz",	.value = 0x0008 },
+	{ .name = "PPS1",	.value = 0x0001,  .frequency = 1 },
+	{ .name = "10Mhz",	.value = 0x0008,  .frequency = 1000000 },
 	{ }
 };
 
 static const struct ocp_selector ptp_ocp_art_sma_out[] = {
-	{ .name = "PHC",	.value = 0x0002 },
-	{ .name = "GNSS",	.value = 0x0004 },
-	{ .name = "10Mhz",	.value = 0x0010 },
+	{ .name = "PHC",	.value = 0x0002,  .frequency = 1 },
+	{ .name = "GNSS",	.value = 0x0004,  .frequency = 1 },
+	{ .name = "10Mhz",	.value = 0x0010,  .frequency = 10000000 },
 	{ }
 };
 
Quoted 8 lines

drivers/ptp/ptp_ocp.c

Quoted 5 lines
drivers/ptp/ptp_ocp.c +0 -0
@@ -2283,22 +2296,34 @@ ptp_ocp_sma_fb_set_inputs(struct ptp_ocp *bp, int sma_nr, u32 val)

static void
ptp_ocp_sma_fb_init(struct ptp_ocp *bp)
{

drivers/ptp/ptp_ocp.c +1 -0
+	struct dpll_pin_properties prop = {

Why don't you have this as static const outside the function?

Quoted 2 lines

Because I'm changing label string for every pin. I cannot change it in the const object.

No you don't. You just copy prop to bp->sma[i].dpll_prop. Prop does not change.

Quoted 208 lines
Quoted 5 lines

drivers/ptp/ptp_ocp.c

Quoted 3 lines
drivers/ptp/ptp_ocp.c +1 -0
+		.label = NULL,

Pointless init.

Agree

Quoted 68 lines
Quoted 68 lines
drivers/ptp/ptp_ocp.c +6 -0
+		.type = DPLL_PIN_TYPE_EXT,
+		.capabilities = DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE,
+		.freq_supported_num = ARRAY_SIZE(ptp_ocp_sma_freq),
+		.freq_supported = ptp_ocp_sma_freq,
+
+	};
	u32 reg;
	int i;

	/* defaults */
drivers/ptp/ptp_ocp.c +5 -0
+	for (i = 0; i < OCP_SMA_NUM; i++) {
+		bp->sma[i].default_fcn = i & 1;
+		bp->sma[i].dpll_prop = prop;
+		bp->sma[i].dpll_prop.label = bp->ptp_info.pin_config[i].name;
+	}
	bp->sma[0].mode = SMA_MODE_IN;
	bp->sma[1].mode = SMA_MODE_IN;
	bp->sma[2].mode = SMA_MODE_OUT;
	bp->sma[3].mode = SMA_MODE_OUT;
drivers/ptp/ptp_ocp.c +0 -3
-	for (i = 0; i < 4; i++)
-		bp->sma[i].default_fcn = i & 1;
-
	/* If no SMA1 map, the pin functions and directions are fixed. */
	if (!bp->sma_map1) {
drivers/ptp/ptp_ocp.c +1 -1
-		for (i = 0; i < 4; i++) {
+		for (i = 0; i < OCP_SMA_NUM; i++) {
			bp->sma[i].fixed_fcn = true;
			bp->sma[i].fixed_dir = true;
drivers/ptp/ptp_ocp.c +2 -0
+			bp->sma[1].dpll_prop.capabilities &=
+				~DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE;
		}
		return;
	}
drivers/ptp/ptp_ocp.c +1 -1
@@ -2308,7 +2333,7 @@ ptp_ocp_sma_fb_init(struct ptp_ocp *bp)
 	 */
 	reg = ioread32(&bp->sma_map2->gpio2);
 	if (reg == 0xffffffff) {
-		for (i = 0; i < 4; i++)
+		for (i = 0; i < OCP_SMA_NUM; i++)
 			bp->sma[i].fixed_dir = true;
 	} else {
 		reg = ioread32(&bp->sma_map1->gpio1);
@@ -2330,7 +2355,7 @@ static const struct ocp_sma_op ocp_fb_sma_op = {
 };
 

static int

drivers/ptp/ptp_ocp.c +1 -1
-ptp_ocp_fb_set_pins(struct ptp_ocp *bp)
+ptp_ocp_set_pins(struct ptp_ocp *bp)
{
	struct ptp_pin_desc *config;
	int i;
drivers/ptp/ptp_ocp.c +2 -2
@@ -2397,16 +2422,16 @@ ptp_ocp_fb_board_init(struct ptp_ocp *bp, struct ocp_resource *r)
 
 	ptp_ocp_tod_init(bp);
 	ptp_ocp_nmea_out_init(bp);
-	ptp_ocp_sma_init(bp);
 	ptp_ocp_signal_init(bp);
 
 	err = ptp_ocp_attr_group_add(bp, fb_timecard_groups);
 	if (err)
 		return err;
 
-	err = ptp_ocp_fb_set_pins(bp);
+	err = ptp_ocp_set_pins(bp);
 	if (err)
 		return err;
+	ptp_ocp_sma_init(bp);
 
Quoted 14 lines

drivers/ptp/ptp_ocp.c ptp_ocp_register_resources(struct ptp_ocp *bp, kernel_ulong_t driver_data) · line 2477

Quoted 10 lines
drivers/ptp/ptp_ocp.c +0 -0
 	return ptp_ocp_init_clock(bp);
 }
@@ -2446,6 +2471,14 @@ ptp_ocp_register_resources(struct ptp_ocp *bp, kernel_ulong_t driver_data)

static void
ptp_ocp_art_sma_init(struct ptp_ocp *bp)
{

drivers/ptp/ptp_ocp.c +4 -0
+	struct dpll_pin_properties prop = {
+		.label = NULL,
+		.type = DPLL_PIN_TYPE_EXT,
+		.capabilities = 0,

Same comment as to the similar prop struct above. Plus another pointless init here.

Will remove pointless init.

Quoted 115 lines
Quoted 99 lines
drivers/ptp/ptp_ocp.c +4 -0
+		.freq_supported_num = ARRAY_SIZE(ptp_ocp_sma_freq),
+		.freq_supported = ptp_ocp_sma_freq,
+
+	};
	u32 reg;
	int i;
drivers/ptp/ptp_ocp.c +14 -7
@@ -2460,16 +2493,16 @@ ptp_ocp_art_sma_init(struct ptp_ocp *bp)
 	bp->sma[2].default_fcn = 0x10;	/* OUT: 10Mhz */
 	bp->sma[3].default_fcn = 0x02;	/* OUT: PHC */
 
-	/* If no SMA map, the pin functions and directions are fixed. */
-	if (!bp->art_sma) {
-		for (i = 0; i < 4; i++) {
+
+	for (i = 0; i < OCP_SMA_NUM; i++) {
+		/* If no SMA map, the pin functions and directions are fixed. */
+		bp->sma[i].dpll_prop = prop;
+		bp->sma[i].dpll_prop.label = bp->ptp_info.pin_config[i].name;
+		if (!bp->art_sma) {
 			bp->sma[i].fixed_fcn = true;
 			bp->sma[i].fixed_dir = true;
+			continue;
 		}
-		return;
-	}
-
-	for (i = 0; i < 4; i++) {
 		reg = ioread32(&bp->art_sma->map[i].gpio);
 
 		switch (reg & 0xff) {
@@ -2480,9 +2513,13 @@ ptp_ocp_art_sma_init(struct ptp_ocp *bp)
 		case 1:
 		case 8:
 			bp->sma[i].mode = SMA_MODE_IN;
+			bp->sma[i].dpll_prop.capabilities =
+				DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE;
 			break;
 		default:
 			bp->sma[i].mode = SMA_MODE_OUT;
+			bp->sma[i].dpll_prop.capabilities =
+				DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE;
 			break;
 		}
 	}
@@ -2549,6 +2586,9 @@ ptp_ocp_art_board_init(struct ptp_ocp *bp, struct ocp_resource *r)
 	/* Enable MAC serial port during initialisation */
 	iowrite32(1, &bp->board_config->mro50_serial_activate);
 
+	err = ptp_ocp_set_pins(bp);
+	if (err)
+		return err;
 	ptp_ocp_sma_init(bp);
 
 	err = ptp_ocp_attr_group_add(bp, art_timecard_groups);
@@ -2690,16 +2730,9 @@ sma4_show(struct device *dev, struct device_attribute *attr, char *buf)
 }
 

static int

drivers/ptp/ptp_ocp.c +1 -1
-ptp_ocp_sma_store(struct ptp_ocp *bp, const char *buf, int sma_nr)
+ptp_ocp_sma_store_val(struct ptp_ocp *bp, int val, enum ptp_ocp_sma_mode mode, int sma_nr)
{
	struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr - 1];
drivers/ptp/ptp_ocp.c +0 -7
-	enum ptp_ocp_sma_mode mode;
-	int val;
-
-	mode = sma->mode;
-	val = sma_parse_inputs(bp->sma_op->tbl, buf, &mode);
-	if (val < 0)
-		return val;
	if (sma->fixed_dir && (mode != sma->mode || val & SMA_DISABLE))
		return -EOPNOTSUPP;
drivers/ptp/ptp_ocp.c +14 -0
@@ -2734,6 +2767,20 @@ ptp_ocp_sma_store(struct ptp_ocp *bp, const char *buf, int sma_nr)
 	return val;
 }
 
+static int
+ptp_ocp_sma_store(struct ptp_ocp *bp, const char *buf, int sma_nr)
+{
+	struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr - 1];
+	enum ptp_ocp_sma_mode mode;
+	int val;
+
+	mode = sma->mode;
+	val = sma_parse_inputs(bp->sma_op->tbl, buf, &mode);
+	if (val < 0)
+		return val;
+	return ptp_ocp_sma_store_val(bp, val, mode, sma_nr);
+}
+

static ssize_t
sma1_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)

drivers/ptp/ptp_ocp.c +0 -0
@@ -4172,12 +4219,148 @@ ptp_ocp_detach(struct ptp_ocp *bp)
 	device_unregister(&bp->dev);
 }
 

drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4231

Quoted 10 lines
drivers/ptp/ptp_ocp.c +10 -0
+static int ptp_ocp_dpll_lock_status_get(const struct dpll_device *dpll,
+					void *priv,
+					enum dpll_lock_status *status,
+					struct netlink_ext_ack *extack)
+{
+	struct ptp_ocp *bp = priv;
+	int sync;
+
+	sync = ioread32(&bp->reg->status) & OCP_STATUS_IN_SYNC;
+	*status = sync ? DPLL_LOCK_STATUS_LOCKED : DPLL_LOCK_STATUS_UNLOCKED;

Does your device support event delivery in case of the status change? ice and mlx5 drivers do poll for changes in this area anyway. It's a part of this patchset. You should do the same if your device does not support events.

Quoted 8 lines
Quoted 4 lines

Could you please implement notifications using dpll_device_notify() for status change and dpll_pin_notify() for pin state change?

We are working on implementation of interrupt-based notifications, that's why I didn't implement polling code. Hopefully it will be ready before the non-RFC patchset submission.

Do polling implementation if not and replace by interrupt driver later. Point is, there have to be notifications from day 1.

Quoted 80 lines
Quoted 58 lines
Quoted 58 lines
drivers/ptp/ptp_ocp.c +56 -0
+
+	return 0;
+}
+
+static int ptp_ocp_dpll_source_idx_get(const struct dpll_device *dpll,
+				       void *priv, u32 *idx,
+				       struct netlink_ext_ack *extack)
+{
+	struct ptp_ocp *bp = priv;
+
+	if (bp->pps_select) {
+		*idx = ioread32(&bp->pps_select->gpio1);
+		return 0;
+	}
+	return -EINVAL;
+}
+
+static int ptp_ocp_dpll_mode_get(const struct dpll_device *dpll, void *priv,
+				 u32 *mode, struct netlink_ext_ack *extack)
+{
+	*mode = DPLL_MODE_AUTOMATIC;
+	return 0;
+}
+
+static bool ptp_ocp_dpll_mode_supported(const struct dpll_device *dpll,
+					void *priv, const enum dpll_mode mode,
+					struct netlink_ext_ack *extack)
+{
+	return mode == DPLL_MODE_AUTOMATIC;
+}
+
+static int ptp_ocp_dpll_direction_get(const struct dpll_pin *pin,
+				      void *pin_priv,
+				      const struct dpll_device *dpll,
+				      void *priv,
+				      enum dpll_pin_direction *direction,
+				      struct netlink_ext_ack *extack)
+{
+	struct ptp_ocp_sma_connector *sma = pin_priv;
+
+	*direction = sma->mode == SMA_MODE_IN ?
+				  DPLL_PIN_DIRECTION_SOURCE :
+				  DPLL_PIN_DIRECTION_OUTPUT;
+	return 0;
+}
+
+static int ptp_ocp_dpll_direction_set(const struct dpll_pin *pin,
+				      void *pin_priv,
+				      const struct dpll_device *dpll,
+				      void *dpll_priv,
+				      enum dpll_pin_direction direction,
+				      struct netlink_ext_ack *extack)
+{
+	struct ptp_ocp_sma_connector *sma = pin_priv;
+	struct ptp_ocp *bp = dpll_priv;
+	enum ptp_ocp_sma_mode mode;
Quoted 8 lines

drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4290

Quoted 3 lines
drivers/ptp/ptp_ocp.c +3 -0
+	int sma_nr = (sma - bp->sma);
+
+	if (sma->fixed_dir)

I believe that this is a pointless check as DPLL_PIN_CAPS_DIRECTION_CAN_CHANGE is not set and therefore the check in dpll_pin_direction_set() will be true and -EOPNOTSUPP will be returned from there.
Remove this.

Yep, will do it.

Quoted 10 lines

drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4294

Quoted 5 lines
drivers/ptp/ptp_ocp.c +4 -0
+		return -EOPNOTSUPP;
+	mode = direction == DPLL_PIN_DIRECTION_SOURCE ?
+			    SMA_MODE_IN : SMA_MODE_OUT;
+	return ptp_ocp_sma_store_val(bp, 0, mode, sma_nr);

You need sma_nr just here. Why can't you change ptp_ocp_sma_store_val() to accept struct ptp_ocp_sma_connector * instead avoiding the need for tne sma_nr completely?

Quoted 2 lines

I wanted to add minimal changes to the driver, I will consider changing this as a separate net-next patch.

Hmm, you do change ptp_ocp_sma_store_val() here anyway. Could be an extra patch in this patchset before this one if you want to have it separate.

Quoted 49 lines
Quoted 12 lines
Quoted 12 lines
drivers/ptp/ptp_ocp.c +10 -0
+}
+
+static int ptp_ocp_dpll_frequency_set(const struct dpll_pin *pin,
+				      void *pin_priv,
+				      const struct dpll_device *dpll,
+				      void *dpll_priv, u64 frequency,
+				      struct netlink_ext_ack *extack)
+{
+	struct ptp_ocp_sma_connector *sma = pin_priv;
+	struct ptp_ocp *bp = dpll_priv;
Quoted 9 lines

drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4309

Quoted 5 lines
drivers/ptp/ptp_ocp.c +5 -0
+	const struct ocp_selector *tbl;
+	int sma_nr = (sma - bp->sma);
+	int val, i;
+
+	if (sma->fixed_fcn)

In that case, just fill up a single frequency in the properties, avoid this check-fail and let the dpll core handle it.

Makes sense.

Quoted 25 lines
Quoted 10 lines
drivers/ptp/ptp_ocp.c +9 -0
+		return -EOPNOTSUPP;
+
+	tbl = bp->sma_op->tbl[sma->mode];
+	for (i = 0; tbl[i].name; i++)
+		if (tbl[i].frequency == frequency)
+			return ptp_ocp_sma_store_val(bp, val, sma->mode, sma_nr);
+	return -EINVAL;
+}
+

drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4328

Quoted 10 lines
drivers/ptp/ptp_ocp.c +10 -0
+static int ptp_ocp_dpll_frequency_get(const struct dpll_pin *pin,
+				      void *pin_priv,
+				      const struct dpll_device *dpll,
+				      void *dpll_priv, u64 *frequency,
+				      struct netlink_ext_ack *extack)
+{
+	struct ptp_ocp_sma_connector *sma = pin_priv;
+	struct ptp_ocp *bp = dpll_priv;
+	const struct ocp_selector *tbl;
+	int sma_nr = (sma - bp->sma);

1) void "()"s here.
2) why don't you fill the sma_nr in struct ptp_ocp_sma_connector to make this easier to follow? IDK, just a suggestion, take or leave.

Quoted 29 lines
Quoted 2 lines

Same applies to the the rest of similar occurances above.

Will do it, yes.

Quoted 24 lines
Quoted 8 lines
drivers/ptp/ptp_ocp.c +7 -0
+	u32 val;
+	int i;
+
+	val = bp->sma_op->get(bp, sma_nr);
+	tbl = bp->sma_op->tbl[sma->mode];
+	for (i = 0; tbl[i].name; i++)
+		if (val == tbl[i].value) {

drivers/ptp/ptp_ocp.c ptp_ocp_detach(struct ptp_ocp *bp) · line 4345

Quoted 10 lines
drivers/ptp/ptp_ocp.c +10 -0
+			*frequency = tbl[i].frequency;
+			return 0;
+		}
+
+	return -EINVAL;
+}
+
+static const struct dpll_device_ops dpll_ops = {
+	.lock_status_get = ptp_ocp_dpll_lock_status_get,
+	.source_pin_idx_get = ptp_ocp_dpll_source_idx_get,

This op is a leftover, in dpll core it is not called. This was removed and agreed that drivers should implement state_on_dpll_get() op for pins to see which one is connected.

Please fix here and remove the leftover from DPLL patch #2 as well.

Did you miss this by any chance?

Quoted 37 lines
Quoted 37 lines
Quoted 25 lines
drivers/ptp/ptp_ocp.c +11 -0
+	.mode_get = ptp_ocp_dpll_mode_get,
+	.mode_supported = ptp_ocp_dpll_mode_supported,
+};
+
+static const struct dpll_pin_ops dpll_pins_ops = {
+	.frequency_get = ptp_ocp_dpll_frequency_get,
+	.frequency_set = ptp_ocp_dpll_frequency_set,
+	.direction_get = ptp_ocp_dpll_direction_get,
+	.direction_set = ptp_ocp_dpll_direction_set,
+};
+

static int
ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)

{
	struct devlink *devlink;
	struct ptp_ocp *bp;
drivers/ptp/ptp_ocp.c +2 -1
-	int err;
+	int err, i;
+	u64 clkid;
	devlink = devlink_alloc(&ptp_ocp_devlink_ops, sizeof(*bp), &pdev->dev);
	if (!devlink) {

drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4415

Quoted 7 lines
drivers/ptp/ptp_ocp.c +2 -1
@@ -4227,8 +4410,39 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
 	ptp_ocp_info(bp);
 	devlink_register(devlink);
-	return 0;
 
+	clkid = pci_get_dsn(pdev);
+	bp->dpll = dpll_device_get(clkid, 0, THIS_MODULE);

I suggested this the last time, but again: Could you please:
1) rename dpll_device_get to __dpll_device_get
2) introduce dpll_device_get as a macro filling up THIS_MODULE

Quoted 8 lines
Quoted 6 lines

Then drivers will just call always:
bp->dpll = dpll_device_get(clkid, 0);
and the macro will fillup the module automatically.

Please do the same for dpll_pin_get()

Not sure why I have missed this part, but sure will do it.

Awesome.

Quoted 80 lines
Quoted 9 lines

drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4417

Quoted 4 lines
drivers/ptp/ptp_ocp.c +2 -0
+	if (IS_ERR(bp->dpll)) {
+		dev_err(&pdev->dev, "dpll_device_alloc failed\n");

You need to fix your error path to call devlink_unregister() in this case.

Quoted 9 lines

drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4422

Quoted 5 lines
drivers/ptp/ptp_ocp.c +5 -0
+		goto out;
+	}
+
+	err = dpll_device_register(bp->dpll, DPLL_TYPE_PPS, &dpll_ops, bp, &pdev->dev);
+	if (err)

You need to fix your error path to call dpll_device_put() in this case.

Ok, I'll re-check and update the error path for the next version.

Quoted 37 lines
Quoted 10 lines
drivers/ptp/ptp_ocp.c +9 -0
+		goto out;
+
+	for (i = 0; i < OCP_SMA_NUM; i++) {
+		bp->sma[i].dpll_pin = dpll_pin_get(clkid, i, THIS_MODULE, &bp->sma[i].dpll_prop);
+		if (IS_ERR(bp->sma[i].dpll_pin))
+			goto out_dpll;
+
+		err = dpll_pin_register(bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops,
+					&bp->sma[i], NULL);

drivers/ptp/ptp_ocp.c ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 4441

Quoted 10 lines
drivers/ptp/ptp_ocp.c +10 -0
+		if (err) {
+			dpll_pin_put(bp->sma[i].dpll_pin);
+			goto out_dpll;
+		}
+	}
+
+	return 0;
+out_dpll:
+	while (i) {
+		--i;
	while (i--) {
	?
Quoted 13 lines
drivers/ptp/ptp_ocp.c +4 -0
+		dpll_pin_unregister(bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, &bp->sma[i]);
+		dpll_pin_put(bp->sma[i].dpll_pin);
+	}
+	dpll_device_put(bp->dpll);

out:

	ptp_ocp_detach(bp);

out_disable:

drivers/ptp/ptp_ocp.c +1 -0
@@ -4243,7 +4457,16 @@ ptp_ocp_remove(struct pci_dev *pdev)
 {
 	struct ptp_ocp *bp = pci_get_drvdata(pdev);
 	struct devlink *devlink = priv_to_devlink(bp);
+	int i;
 
Quoted 4 lines

drivers/ptp/ptp_ocp.c ptp_ocp_remove(struct pci_dev *pdev) · line 4463

Quoted 2 lines
drivers/ptp/ptp_ocp.c +2 -0
+	for (i = 0; i < OCP_SMA_NUM; i++) {
+		if (bp->sma[i].dpll_pin) {

Remove this pointless check. It is always true.

Agree.

Quoted 14 lines
Quoted 14 lines
drivers/ptp/ptp_ocp.c +6 -0
+			dpll_pin_unregister(bp->dpll, bp->sma[i].dpll_pin, &dpll_pins_ops, bp);
+			dpll_pin_put(bp->sma[i].dpll_pin);
+		}
+	}
+	dpll_device_unregister(bp->dpll, &dpll_ops, bp);
+	dpll_device_put(bp->dpll);
 	devlink_unregister(devlink);
 	ptp_ocp_detach(bp);
 	pci_disable_device(pdev);
Signature · 1 line
2.34.1
#70 lore raw

RFC PATCH v7 7/8 netdev: expose DPLL pin handle for netdevice

In reply to Vadim Fedorenko

From: Jiri Pirko <[email protected]>

In case netdevice represents a SyncE port, the user needs to understand the connection between netdevice and associated DPLL pin. There might me multiple netdevices pointing to the same pin, in case of VF/SF implementation.

Add a IFLA Netlink attribute to nest the DPLL pin handle, similar to how it is implemented for devlink port. Add a struct dpll_pin pointer to netdev and protect access to it by RTNL. Expose netdev_dpll_pin_set() and netdev_dpll_pin_clear() helpers to the drivers so they can set/clear the DPLL pin relationship to netdev.

Note that during the lifetime of struct dpll_pin the handle fields do not change. Therefore it is save to access them lockless. It is drivers responsibility to call netdev_dpll_pin_clear() before dpll_pin_put().

---
 drivers/dpll/dpll_netlink.c  | 23 ++++++++++++++++++++--
 include/linux/dpll.h         | 20 +++++++++++++++++++
 include/linux/netdevice.h    |  7 +++++++
 include/uapi/linux/if_link.h |  2 ++
 net/core/dev.c               | 20 +++++++++++++++++++
 net/core/rtnetlink.c         | 38 ++++++++++++++++++++++++++++++++++++
 6 files changed, 108 insertions(+), 2 deletions(-)
drivers/dpll/dpll_netlink.c +21 -2
index 1eb0b4a2fce4..734b6776b07c 100644
@@ -269,8 +269,9 @@ dpll_cmd_pin_fill_details(struct sk_buff *msg, struct dpll_pin *pin,
 {
 	int ret;
 
-	if (nla_put_u32(msg, DPLL_A_PIN_IDX, pin->pin_idx))
-		return -EMSGSIZE;
+	ret = dpll_msg_add_pin_handle(msg, pin);
+	if (ret)
+		return ret;
 	if (nla_put_string(msg, DPLL_A_PIN_LABEL, pin->prop.label))
 		return -EMSGSIZE;
 	if (nla_put_u8(msg, DPLL_A_PIN_TYPE, pin->prop.type))
@@ -290,6 +291,24 @@ dpll_cmd_pin_fill_details(struct sk_buff *msg, struct dpll_pin *pin,
 	return 0;
 }
 
+size_t dpll_msg_pin_handle_size(struct dpll_pin *pin)
+{
+	// TMP- THE HANDLE IS GOING TO CHANGE TO DRIVERNAME/CLOCKID/PIN_INDEX
+	// LEAVING ORIG HANDLE NOW AS PUT IN THE LAST RFC VERSION
+	return nla_total_size(4); /* DPLL_A_PIN_IDX */
+}
+EXPORT_SYMBOL_GPL(dpll_msg_pin_handle_size);
+
+int dpll_msg_add_pin_handle(struct sk_buff *msg, struct dpll_pin *pin)
+{
+	// TMP- THE HANDLE IS GOING TO CHANGE TO DRIVERNAME/CLOCKID/PIN_INDEX
+	// LEAVING ORIG HANDLE NOW AS PUT IN THE LAST RFC VERSION
+	if (nla_put_u32(msg, DPLL_A_PIN_IDX, pin->pin_idx))
+		return -EMSGSIZE;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(dpll_msg_add_pin_handle);
+
 static int
 __dpll_cmd_pin_dump_one(struct sk_buff *msg, struct dpll_pin *pin,
 			struct netlink_ext_ack *extack)
include/linux/dpll.h +20 -0
index 5194efaf55a8..5945bb456794 100644
@@ -104,6 +104,26 @@ struct dpll_pin_properties {
 	struct dpll_pin_frequency *freq_supported;
 };
 
+#if IS_ENABLED(CONFIG_DPLL)
+
+size_t dpll_msg_pin_handle_size(struct dpll_pin *pin);
+
+int dpll_msg_add_pin_handle(struct sk_buff *msg, struct dpll_pin *pin);
+
+#else
+
+static inline size_t dpll_msg_pin_handle_size(struct dpll_pin *pin)
+{
+	return 0;
+}
+
+static inline int dpll_msg_add_pin_handle(struct sk_buff *msg, struct dpll_pin *pin)
+{
+	return 0;
+}
+
+#endif
+
 /**
  * dpll_device_get - find or create dpll_device object
  * @clock_id: a system unique number for a device
include/linux/netdevice.h +7 -0
index 08fbd4622ccf..be162d8db611 100644
@@ -34,6 +34,7 @@
 #include <linux/rculist.h>
 #include <linux/workqueue.h>
 #include <linux/dynamic_queue_limits.h>
+#include <linux/dpll.h>
 
 #include <net/net_namespace.h>
 #ifdef CONFIG_DCB
@@ -2411,6 +2412,10 @@ struct net_device {
 	struct rtnl_hw_stats64	*offload_xstats_l3;
 
 	struct devlink_port	*devlink_port;
+
+#if IS_ENABLED(CONFIG_DPLL)
+	struct dpll_pin		*dpll_pin;
+#endif
 };
 #define to_net_dev(d) container_of(d, struct net_device, dev)
 
@@ -3954,6 +3959,8 @@ int dev_get_mac_address(struct sockaddr *sa, struct net *net, char *dev_name);
 int dev_get_port_parent_id(struct net_device *dev,
 			   struct netdev_phys_item_id *ppid, bool recurse);
 bool netdev_port_same_parent_id(struct net_device *a, struct net_device *b);
+void netdev_dpll_pin_set(struct net_device *dev, struct dpll_pin *dpll_pin);
+void netdev_dpll_pin_clear(struct net_device *dev);
 struct sk_buff *validate_xmit_skb_list(struct sk_buff *skb, struct net_device *dev, bool *again);
 struct sk_buff *dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
 				    struct netdev_queue *txq, int *ret);
include/uapi/linux/if_link.h +2 -0
index 4ac1000b0ef2..9244d6ff23fc 100644
@@ -377,6 +377,8 @@ enum {
 	IFLA_GSO_IPV4_MAX_SIZE,
 	IFLA_GRO_IPV4_MAX_SIZE,
 
+	IFLA_DPLL_PIN,
+
 	__IFLA_MAX
 };
 
net/core/dev.c +20 -0
index 735096d42c1d..fe594e23c1cb 100644
@@ -8990,6 +8990,26 @@ bool netdev_port_same_parent_id(struct net_device *a, struct net_device *b)
 }
 EXPORT_SYMBOL(netdev_port_same_parent_id);
 
+static void netdev_dpll_pin_assign(struct net_device *dev, struct dpll_pin *dpll_pin)
+{
+	rtnl_lock();
+	dev->dpll_pin = dpll_pin;
+	rtnl_unlock();
+}
+
+void netdev_dpll_pin_set(struct net_device *dev, struct dpll_pin *dpll_pin)
+{
+	WARN_ON(!dpll_pin);
+	netdev_dpll_pin_assign(dev, dpll_pin);
+}
+EXPORT_SYMBOL(netdev_dpll_pin_set);
+
+void netdev_dpll_pin_clear(struct net_device *dev)
+{
+	netdev_dpll_pin_assign(dev, NULL);
+}
+EXPORT_SYMBOL(netdev_dpll_pin_clear);
+
 /**
  *	dev_change_proto_down - set carrier according to proto_down.
  *
net/core/rtnetlink.c +38 -0
index 653901a1bf75..2d1f5d2024ac 100644
@@ -1052,6 +1052,16 @@ static size_t rtnl_devlink_port_size(const struct net_device *dev)
 	return size;
 }
 
+static size_t rtnl_dpll_pin_size(const struct net_device *dev)
+{
+	size_t size = nla_total_size(0); /* nest IFLA_DPLL_PIN */
+
+	if (dev->dpll_pin)
+		size += dpll_msg_pin_handle_size(dev->dpll_pin);
+
+	return size;
+}
+
 static noinline size_t if_nlmsg_size(const struct net_device *dev,
 				     u32 ext_filter_mask)
 {
@@ -1108,6 +1118,7 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev,
 	       + rtnl_prop_list_size(dev)
 	       + nla_total_size(MAX_ADDR_LEN) /* IFLA_PERM_ADDRESS */
 	       + rtnl_devlink_port_size(dev)
+	       + rtnl_dpll_pin_size(dev)
 	       + 0;
 }
 
@@ -1769,6 +1780,30 @@ static int rtnl_fill_devlink_port(struct sk_buff *skb,
 	return ret;
 }
 
+static int rtnl_fill_dpll_pin(struct sk_buff *skb,
+			      const struct net_device *dev)
+{
+	struct nlattr *dpll_pin_nest;
+	int ret;
+
+	dpll_pin_nest = nla_nest_start(skb, IFLA_DPLL_PIN);
+	if (!dpll_pin_nest)
+		return -EMSGSIZE;
+
+	if (dev->dpll_pin) {
+		ret = dpll_msg_add_pin_handle(skb, dev->dpll_pin);
+		if (ret < 0)
+			goto nest_cancel;
+	}
+
+	nla_nest_end(skb, dpll_pin_nest);
+	return 0;
+
+nest_cancel:
+	nla_nest_cancel(skb, dpll_pin_nest);
+	return ret;
+}
+
 static int rtnl_fill_ifinfo(struct sk_buff *skb,
 			    struct net_device *dev, struct net *src_net,
 			    int type, u32 pid, u32 seq, u32 change,
@@ -1911,6 +1946,9 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb,
 	if (rtnl_fill_devlink_port(skb, dev))
 		goto nla_put_failure;
 
+	if (rtnl_fill_dpll_pin(skb, dev))
+		goto nla_put_failure;
+
 	nlmsg_end(skb, nlh);
 	return 0;
 
Signature · 1 line
2.34.1
#71 lore raw

Re: [RFC PATCH v7 7/8] netdev: expose DPLL pin handle for netdevice

drivers/dpll/dpll_netlink.c dpll_cmd_pin_fill_details(struct sk_buff *msg, struct dpll_pin *pin, · line 297

Quoted 4 lines · On Thu, 27 Apr 2023 17:20:08 -0700 Vadim Fedorenko <[email protected]> wrote:
drivers/dpll/dpll_netlink.c +4 -0
+size_t dpll_msg_pin_handle_size(struct dpll_pin *pin)
+{
+	// TMP- THE HANDLE IS GOING TO CHANGE TO DRIVERNAME/CLOCKID/PIN_INDEX
+	// LEAVING ORIG HANDLE NOW AS PUT IN THE LAST RFC VERSION

Please don't use C++ style comments

#72 lore raw

Re: [RFC PATCH v7 7/8] netdev: expose DPLL pin handle for netdevice

Quoted 9 lines · Stephen Hemminger

drivers/dpll/dpll_netlink.c dpll_cmd_pin_fill_details(struct sk_buff *msg, struct dpll_pin *pin, · line 297

Quoted 4 lines · On Thu, 27 Apr 2023 17:20:08 -0700 Vadim Fedorenko <[email protected]> wrote:
drivers/dpll/dpll_netlink.c +4 -0
+size_t dpll_msg_pin_handle_size(struct dpll_pin *pin)
+{
+	// TMP- THE HANDLE IS GOING TO CHANGE TO DRIVERNAME/CLOCKID/PIN_INDEX
+	// LEAVING ORIG HANDLE NOW AS PUT IN THE LAST RFC VERSION

Please don't use C++ style comments

Sure, these comments were put in as a placeholder for RFC patches, will be definitely removed for the next version which I hope will be ready to merge.

#73 lore raw

Re: [RFC PATCH v7 7/8] netdev: expose DPLL pin handle for netdevice

In reply to Vadim Fedorenko
kernel test robot noticed the following build errors:

Hi Vadim,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on v6.3]
[cannot apply to tnguy-next-queue/dev-queue linus/master next-20230427] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Vadim-Fedorenko/dpll-spec-Add-Netlink-spec-in-YAML/20230428-082340
base:   457391b0380335d5e9a5babdec90ac53928b23b4
patch link:    https://lore.kernel.org/r/20230428002009.2948020-8-vadfed%40meta.com
patch subject: [RFC PATCH v7 7/8] netdev: expose DPLL pin handle for netdevice
config: sh-allmodconfig (https://download.01.org/0day-ci/archive/20230428/[email protected]/config)
compiler: sh4-linux-gcc (GCC) 12.1.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/896bf6147acb6644a9a3cf4825510821d86ba577
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Vadim-Fedorenko/dpll-spec-Add-Netlink-spec-in-YAML/20230428-082340 git checkout 896bf6147acb6644a9a3cf4825510821d86ba577
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sh olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sh SHELL=/bin/bash net/core/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

net/core/dev.c: In function 'netdev_dpll_pin_assign':

>> net/core/dev.c:8958:12: error: 'struct net_device' has no member named 'dpll_pin'
    8958 |         dev->dpll_pin = dpll_pin;
         |            ^~
--
   net/core/rtnetlink.c: In function 'rtnl_dpll_pin_size':
>> net/core/rtnetlink.c:1056:16: error: 'const struct net_device' has no member named 'dpll_pin'
    1056 |         if (dev->dpll_pin)
         |                ^~
   net/core/rtnetlink.c:1057:53: error: 'const struct net_device' has no member named 'dpll_pin'
    1057 |                 size += dpll_msg_pin_handle_size(dev->dpll_pin);
         |                                                     ^~
   net/core/rtnetlink.c: In function 'rtnl_fill_dpll_pin':
   net/core/rtnetlink.c:1790:16: error: 'const struct net_device' has no member named 'dpll_pin'
    1790 |         if (dev->dpll_pin) {
         |                ^~
   net/core/rtnetlink.c:1791:55: error: 'const struct net_device' has no member named 'dpll_pin'
    1791 |                 ret = dpll_msg_add_pin_handle(skb, dev->dpll_pin);
         |                                                       ^~

vim +8958 net/core/dev.c

8954
8955 static void netdev_dpll_pin_assign(struct net_device *dev, struct dpll_pin *dpll_pin)
8956 {
8957 rtnl_lock();

> 8958		dev->dpll_pin = dpll_pin;

8959 rtnl_unlock();
8960 }
8961

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
#74 lore raw

Re: [RFC PATCH v7 7/8] netdev: expose DPLL pin handle for netdevice

In reply to Vadim Fedorenko
kernel test robot noticed the following build errors:

Hi Vadim,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on v6.3]
[cannot apply to tnguy-next-queue/dev-queue linus/master next-20230427] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Vadim-Fedorenko/dpll-spec-Add-Netlink-spec-in-YAML/20230428-082340
base:   457391b0380335d5e9a5babdec90ac53928b23b4
patch link:    https://lore.kernel.org/r/20230428002009.2948020-8-vadfed%40meta.com
patch subject: [RFC PATCH v7 7/8] netdev: expose DPLL pin handle for netdevice
config: hexagon-randconfig-r031-20230428 (https://download.01.org/0day-ci/archive/20230428/[email protected]/config)
compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project 437b7602e4a998220871de78afcb020b9c14a661)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/896bf6147acb6644a9a3cf4825510821d86ba577
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Vadim-Fedorenko/dpll-spec-Add-Netlink-spec-in-YAML/20230428-082340 git checkout 896bf6147acb6644a9a3cf4825510821d86ba577
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash net/core/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from net/core/dev.c:88:
In file included from include/linux/interrupt.h:11:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/hexagon/include/asm/io.h:334:
include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]

           val = __raw_readb(PCI_IOBASE + addr);
                             ~~~~~~~~~~ ^
   include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
                                                           ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu'
   #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
                                                     ^
   In file included from net/core/dev.c:88:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/hexagon/include/asm/io.h:334:
   include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
                                                           ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
   #define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
                                                     ^
   In file included from net/core/dev.c:88:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/hexagon/include/asm/io.h:334:
   include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writeb(value, PCI_IOBASE + addr);
                               ~~~~~~~~~~ ^
   include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
                                                         ~~~~~~~~~~ ^
   include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
                                                         ~~~~~~~~~~ ^
>> net/core/dev.c:8958:7: error: no member named 'dpll_pin' in 'struct net_device'
           dev->dpll_pin = dpll_pin;
           ~~~  ^

6 warnings and 1 error generated.
--
In file included from net/core/rtnetlink.c:28:
In file included from include/linux/interrupt.h:11:
In file included from include/linux/hardirq.h:11:
In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
In file included from include/asm-generic/hardirq.h:17:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:13:
In file included from arch/hexagon/include/asm/io.h:334:
include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]

           val = __raw_readb(PCI_IOBASE + addr);
                             ~~~~~~~~~~ ^
   include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
                                                           ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu'
   #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
                                                     ^
   In file included from net/core/rtnetlink.c:28:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/hexagon/include/asm/io.h:334:
   include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
                                                           ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
   #define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
                                                     ^
   In file included from net/core/rtnetlink.c:28:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/hexagon/include/asm/io.h:334:
   include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writeb(value, PCI_IOBASE + addr);
                               ~~~~~~~~~~ ^
   include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
                                                         ~~~~~~~~~~ ^
   include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
                                                         ~~~~~~~~~~ ^
>> net/core/rtnetlink.c:1056:11: error: no member named 'dpll_pin' in 'struct net_device'
           if (dev->dpll_pin)
               ~~~  ^
   net/core/rtnetlink.c:1057:41: error: no member named 'dpll_pin' in 'struct net_device'
                   size += dpll_msg_pin_handle_size(dev->dpll_pin);
                                                    ~~~  ^
   net/core/rtnetlink.c:1790:11: error: no member named 'dpll_pin' in 'struct net_device'
           if (dev->dpll_pin) {
               ~~~  ^
   net/core/rtnetlink.c:1791:43: error: no member named 'dpll_pin' in 'struct net_device'
                   ret = dpll_msg_add_pin_handle(skb, dev->dpll_pin);
                                                      ~~~  ^

6 warnings and 4 errors generated.

vim +8958 net/core/dev.c

8954
8955 static void netdev_dpll_pin_assign(struct net_device *dev, struct dpll_pin *dpll_pin)
8956 {
8957 rtnl_lock();

> 8958		dev->dpll_pin = dpll_pin;

8959 rtnl_unlock();
8960 }
8961

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
maintainer
#75 lore raw

Re: [RFC PATCH v7 7/8] netdev: expose DPLL pin handle for netdevice

In reply to Vadim Fedorenko

include/linux/netdevice.h struct net_device { · line 2418

Quoted 8 lines · On Thu, 27 Apr 2023 17:20:08 -0700 Vadim Fedorenko wrote:
include/linux/netdevice.h +4 -0
@@ -2411,6 +2412,10 @@ struct net_device {
 	struct rtnl_hw_stats64	*offload_xstats_l3;
 
 	struct devlink_port	*devlink_port;
+
+#if IS_ENABLED(CONFIG_DPLL)
+	struct dpll_pin		*dpll_pin;
+#endif

kdoc is missing. I'm guessing that one pin covers all current user cases but we should clearly document on what this pin is, so that when we extend the code to support multiple pins (in/out, per lane, idk) we know which one this was.. ?

maintainer
#76 lore raw

Re: [RFC PATCH v7 7/8] netdev: expose DPLL pin handle for netdevice

Quoted 4 lines · Thu, May 04, 2023 at 10:31:40PM CEST, [email protected] wrote:
Quoted 3 lines · On Thu, 27 Apr 2023 17:20:08 -0700 Vadim Fedorenko wrote:
include/linux/netdevice.h +0 -0
@@ -2411,6 +2412,10 @@ struct net_device {
 	struct rtnl_hw_stats64	*offload_xstats_l3;
 
Quoted 10 lines

include/linux/netdevice.h struct net_device { · line 2418

Quoted 5 lines
include/linux/netdevice.h +4 -0
 	struct devlink_port	*devlink_port;
+
+#if IS_ENABLED(CONFIG_DPLL)
+	struct dpll_pin		*dpll_pin;
+#endif

kdoc is missing. I'm guessing that one pin covers all current user cases but we should clearly document on what this pin is, so that when we extend the code to support multiple pins (in/out, per lane, idk) we know which one this was.. ?

Oh, yeah. Will do.

#77 lore raw

RFC PATCH v7 8/8 mlx5: Implement SyncE support using DPLL infrastructure

In reply to Vadim Fedorenko

From: Jiri Pirko <[email protected]>

Implement SyncE support using newly introduced DPLL support. Make sure that each PFs/VFs/SFs probed with appropriate capability will spawn a dpll auxiliary device and register appropriate dpll device and pin instances.

---
 .../net/ethernet/mellanox/mlx5/core/Kconfig   |   8 +
 .../net/ethernet/mellanox/mlx5/core/Makefile  |   3 +
 drivers/net/ethernet/mellanox/mlx5/core/dev.c |  17 +
 .../net/ethernet/mellanox/mlx5/core/dpll.c    | 438 ++++++++++++++++++
 include/linux/mlx5/driver.h                   |   2 +
 include/linux/mlx5/mlx5_ifc.h                 |  59 ++-
 6 files changed, 526 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/dpll.c
drivers/net/ethernet/mellanox/mlx5/core/Kconfig +8 -0
index bb1d7b039a7e..15a48d376eb3 100644
@@ -188,3 +188,11 @@ config MLX5_SF_MANAGER
 	port is managed through devlink.  A subfunction supports RDMA, netdevice
 	and vdpa device. It is similar to a SRIOV VF but it doesn't require
 	SRIOV support.
+
+config MLX5_DPLL
+	tristate "Mellanox 5th generation network adapters (ConnectX series) DPLL support"
+	depends on NETDEVICES && ETHERNET && PCI && MLX5_CORE
+	select DPLL
+	help
+	  DPLL support in Mellanox Technologies ConnectX NICs.
+
drivers/net/ethernet/mellanox/mlx5/core/Makefile +3 -0
index ddf1e352f51d..69434e8c2fb1 100644
@@ -123,3 +123,6 @@ mlx5_core-$(CONFIG_MLX5_SF) += sf/vhca_event.o sf/dev/dev.o sf/dev/driver.o irq_
 # SF manager
 #
 mlx5_core-$(CONFIG_MLX5_SF_MANAGER) += sf/cmd.o sf/hw_table.o sf/devlink.o
+
+obj-$(CONFIG_MLX5_DPLL) += mlx5_dpll.o
+mlx5_dpll-y :=	dpll.o
drivers/net/ethernet/mellanox/mlx5/core/dev.c +17 -0
index 1b33533b15de..7d677332a18b 100644
@@ -211,6 +211,19 @@ static bool is_ib_enabled(struct mlx5_core_dev *dev)
 	return err ? false : val.vbool;
 }
 
+static bool is_dpll_supported(struct mlx5_core_dev *dev)
+{
+	if (!IS_ENABLED(CONFIG_MLX5_DPLL))
+		return false;
+
+	if (!MLX5_CAP_MCAM_REG2(dev, synce_registers)) {
+		mlx5_core_warn(dev, "Missing SyncE capability\n");
+		return false;
+	}
+
+	return true;
+}
+
 enum {
 	MLX5_INTERFACE_PROTOCOL_ETH,
 	MLX5_INTERFACE_PROTOCOL_ETH_REP,
@@ -220,6 +233,8 @@ enum {
 	MLX5_INTERFACE_PROTOCOL_MPIB,
 
 	MLX5_INTERFACE_PROTOCOL_VNET,
+
+	MLX5_INTERFACE_PROTOCOL_DPLL,
 };
 
 static const struct mlx5_adev_device {
@@ -242,6 +257,8 @@ static const struct mlx5_adev_device {
 					   .is_supported = &is_ib_rep_supported },
 	[MLX5_INTERFACE_PROTOCOL_MPIB] = { .suffix = "multiport",
 					   .is_supported = &is_mp_supported },
+	[MLX5_INTERFACE_PROTOCOL_DPLL] = { .suffix = "dpll",
+					   .is_supported = &is_dpll_supported },
 };
 
 int mlx5_adev_idx_alloc(void)
drivers/net/ethernet/mellanox/mlx5/core/dpll.c new file +438 -0

438 lines not on this page · raw message

include/linux/mlx5/driver.h +2 -0
index a4c4f737f9c1..6e7546f2bb84 100644
@@ -154,6 +154,8 @@ enum {
 	MLX5_REG_MCC		 = 0x9062,
 	MLX5_REG_MCDA		 = 0x9063,
 	MLX5_REG_MCAM		 = 0x907f,
+	MLX5_REG_MSECQ		 = 0x9155,
+	MLX5_REG_MSEES		 = 0x9156,
 	MLX5_REG_MIRC		 = 0x9162,
 	MLX5_REG_SBCAM		 = 0xB01F,
 	MLX5_REG_RESOURCE_DUMP   = 0xC000,
include/linux/mlx5/mlx5_ifc.h +58 -1

69 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#78 lore raw
In reply to Vadim Fedorenko
Quoted 6 lines · Fri, Apr 28, 2023 at 02:20:01AM CEST, [email protected] wrote:

From: Vadim Fedorenko <[email protected]>

Implement common API for clock/DPLL configuration and status reporting. The API utilises netlink interface as transport for commands and event notifications. This API aim to extend current pin configuration and make it flexible and easy to cover special configurations.

Vadim, I guess you forgot, could you please add some example commands here? Please keep them in for the next V.

Thanks!

Quoted 141 lines

v6 -> v7:
* YAML spec:
- remove nested 'pin' attribute
- clean up definitions on top of the latest changes
* pin object:
- pin xarray uses id provided by the driver
- remove usage of PIN_IDX_INVALID in set function
- source_pin_get() returns object instead of idx
- fixes in frequency support API
* device and pin operations are const now
* small fixes in naming in Makefile and in the functions
* single mutex for the subsystem to avoid possible ABBA locks
* no special *_priv() helpers anymore, private data is passed as void*
* no netlink filters by name anymore, only index is supported
* update ptp_ocp and ice drivers to follow new API version
* add mlx5e driver as a new customer of the subsystem
v5 -> v6:
* rework pin part to better fit shared pins use cases
* add YAML spec to easy generate user-space apps
* simple implementation in ptp_ocp is back again
v4 -> v5:
* fix code issues found during last reviews:
- replace cookie with clock id
- follow one naming schema in dpll subsys
- move function comments to dpll_core.c, fix exports
- remove single-use helper functions
- merge device register with alloc
- lock and unlock mutex on dpll device release
- move dpll_type to uapi header
- rename DPLLA_DUMP_FILTER to DPLLA_FILTER
- rename dpll_pin_state to dpll_pin_mode
- rename DPLL_MODE_FORCED to DPLL_MODE_MANUAL
- remove DPLL_CHANGE_PIN_TYPE enum value
* rewrite framework once again (Arkadiusz)
- add clock class:
Provide userspace with clock class value of DPLL with dpll device dump netlink request. Clock class is assigned by driver allocating a dpll device. Clock class values are defined as specified in:
ITU-T G.8273.2/Y.1368.2 recommendation.
- dpll device naming schema use new pattern:
"dpll_%s_%d_%d", where:
- %s - dev_name(parent) of parent device,
- %d (1) - enum value of dpll type,
- %d (2) - device index provided by parent device.
- new muxed/shared pin registration:
Let the kernel module to register a shared or muxed pin without finding it or its parent. Instead use a parent/shared pin description to find correct pin internally in dpll_core, simplifing a dpll API
* Implement complex DPLL design in ice driver (Arkadiusz)
* Remove ptp_ocp driver from the series for now
v3 -> v4:
* redesign framework to make pins dynamically allocated (Arkadiusz)
* implement shared pins (Arkadiusz)
v2 -> v3:
* implement source select mode (Arkadiusz)
* add documentation
* implementation improvements (Jakub)
v1 -> v2:
* implement returning supported input/output types
* ptp_ocp: follow suggestions from Jonathan
* add linux-clk mailing list
v0 -> v1:
* fix code style and errors
* add linux-arm mailing list

Arkadiusz Kubalewski (3):
dpll: spec: Add Netlink spec in YAML
ice: add admin commands to access cgu configuration
ice: implement dpll interface to control cgu

Jiri Pirko (2):
netdev: expose DPLL pin handle for netdevice
mlx5: Implement SyncE support using DPLL infrastructure

Vadim Fedorenko (3):
dpll: Add DPLL framework base functions
dpll: documentation on DPLL subsystem interface
ptp_ocp: implement DPLL ops

Documentation/dpll.rst                        |  408 ++++
Documentation/netlink/specs/dpll.yaml         |  472 ++++
Documentation/networking/index.rst            |    1 +
MAINTAINERS                                   |    8 +
drivers/Kconfig                               |    2 +
drivers/Makefile                              |    1 +
drivers/dpll/Kconfig                          |    7 +
drivers/dpll/Makefile                         |   10 +
drivers/dpll/dpll_core.c                      |  939 ++++++++
drivers/dpll/dpll_core.h                      |  113 +
drivers/dpll/dpll_netlink.c                   |  991 +++++++++
drivers/dpll/dpll_netlink.h                   |   27 +
drivers/dpll/dpll_nl.c                        |  126 ++
drivers/dpll/dpll_nl.h                        |   42 +
drivers/net/ethernet/intel/Kconfig            |    1 +
drivers/net/ethernet/intel/ice/Makefile       |    3 +-
drivers/net/ethernet/intel/ice/ice.h          |    5 +
.../net/ethernet/intel/ice/ice_adminq_cmd.h   |  240 +-
drivers/net/ethernet/intel/ice/ice_common.c   |  467 ++++
drivers/net/ethernet/intel/ice/ice_common.h   |   43 +
drivers/net/ethernet/intel/ice/ice_dpll.c     | 1929 +++++++++++++++++
drivers/net/ethernet/intel/ice/ice_dpll.h     |  101 +
drivers/net/ethernet/intel/ice/ice_lib.c      |   17 +-
drivers/net/ethernet/intel/ice/ice_main.c     |    7 +
drivers/net/ethernet/intel/ice/ice_ptp_hw.c   |  414 ++++
drivers/net/ethernet/intel/ice/ice_ptp_hw.h   |  230 ++
drivers/net/ethernet/intel/ice/ice_type.h     |    1 +
.../net/ethernet/mellanox/mlx5/core/Kconfig   |    8 +
.../net/ethernet/mellanox/mlx5/core/Makefile  |    3 +
drivers/net/ethernet/mellanox/mlx5/core/dev.c |   17 +
.../net/ethernet/mellanox/mlx5/core/dpll.c    |  438 ++++
drivers/ptp/Kconfig                           |    1 +
drivers/ptp/ptp_ocp.c                         |  327 ++-
include/linux/dpll.h                          |  294 +++
include/linux/mlx5/driver.h                   |    2 +
include/linux/mlx5/mlx5_ifc.h                 |   59 +-
include/linux/netdevice.h                     |    7 +
include/uapi/linux/dpll.h                     |  204 ++
include/uapi/linux/if_link.h                  |    2 +
net/core/dev.c                                |   20 +
net/core/rtnetlink.c                          |   38 +
41 files changed, 7966 insertions(+), 59 deletions(-)

create mode 100644 Documentation/dpll.rst
create mode 100644 Documentation/netlink/specs/dpll.yaml create mode 100644 drivers/dpll/Kconfig
create mode 100644 drivers/dpll/Makefile
create mode 100644 drivers/dpll/dpll_core.c
create mode 100644 drivers/dpll/dpll_core.h
create mode 100644 drivers/dpll/dpll_netlink.c
create mode 100644 drivers/dpll/dpll_netlink.h
create mode 100644 drivers/dpll/dpll_nl.c
create mode 100644 drivers/dpll/dpll_nl.h
create mode 100644 drivers/net/ethernet/intel/ice/ice_dpll.c create mode 100644 drivers/net/ethernet/intel/ice/ice_dpll.h create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/dpll.c create mode 100644 include/linux/dpll.h
create mode 100644 include/uapi/linux/dpll.h

Signature · 1 line
2.34.1
maintainer
#79 lore raw
In reply to Vadim Fedorenko
Quoted 1 line · Fri, Apr 28, 2023 at 02:20:01AM CEST, [email protected] wrote:

From: Vadim Fedorenko <[email protected]>

[...]

Quoted 7 lines

Arkadiusz Kubalewski (3):
dpll: spec: Add Netlink spec in YAML
ice: add admin commands to access cgu configuration
ice: implement dpll interface to control cgu

Jiri Pirko (2):
netdev: expose DPLL pin handle for netdevice

Arkadiusz, could you please expose pin for netdev in ice as well?

Quoted 1 line

mlx5: Implement SyncE support using DPLL infrastructure

[...]

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#80 lore raw
Quoted 16 lines

From: Jiri Pirko <[email protected]>
Sent: Tuesday, May 2, 2023 3:04 PM

Quoted 1 line · Fri, Apr 28, 2023 at 02:20:01AM CEST, [email protected] wrote:

From: Vadim Fedorenko <[email protected]>

[...]

Quoted 7 lines

Arkadiusz Kubalewski (3):
dpll: spec: Add Netlink spec in YAML
ice: add admin commands to access cgu configuration
ice: implement dpll interface to control cgu

Jiri Pirko (2):
netdev: expose DPLL pin handle for netdevice

Quoted 6 lines

Arkadiusz, could you please expose pin for netdev in ice as well?

Quoted 1 line

mlx5: Implement SyncE support using DPLL infrastructure

[...]

Yes, will do.

Thank you,
Arkadiusz

maintainer
#81 lore raw
In reply to Vadim Fedorenko
Quoted 63 lines · Fri, Apr 28, 2023 at 02:20:01AM CEST, [email protected] wrote:

From: Vadim Fedorenko <[email protected]>

Implement common API for clock/DPLL configuration and status reporting. The API utilises netlink interface as transport for commands and event notifications. This API aim to extend current pin configuration and make it flexible and easy to cover special configurations.

v6 -> v7:
* YAML spec:
- remove nested 'pin' attribute
- clean up definitions on top of the latest changes
* pin object:
- pin xarray uses id provided by the driver
- remove usage of PIN_IDX_INVALID in set function
- source_pin_get() returns object instead of idx
- fixes in frequency support API
* device and pin operations are const now
* small fixes in naming in Makefile and in the functions
* single mutex for the subsystem to avoid possible ABBA locks
* no special *_priv() helpers anymore, private data is passed as void*
* no netlink filters by name anymore, only index is supported
* update ptp_ocp and ice drivers to follow new API version
* add mlx5e driver as a new customer of the subsystem
v5 -> v6:
* rework pin part to better fit shared pins use cases
* add YAML spec to easy generate user-space apps
* simple implementation in ptp_ocp is back again
v4 -> v5:
* fix code issues found during last reviews:
- replace cookie with clock id
- follow one naming schema in dpll subsys
- move function comments to dpll_core.c, fix exports
- remove single-use helper functions
- merge device register with alloc
- lock and unlock mutex on dpll device release
- move dpll_type to uapi header
- rename DPLLA_DUMP_FILTER to DPLLA_FILTER
- rename dpll_pin_state to dpll_pin_mode
- rename DPLL_MODE_FORCED to DPLL_MODE_MANUAL
- remove DPLL_CHANGE_PIN_TYPE enum value
* rewrite framework once again (Arkadiusz)
- add clock class:
Provide userspace with clock class value of DPLL with dpll device dump netlink request. Clock class is assigned by driver allocating a dpll device. Clock class values are defined as specified in:
ITU-T G.8273.2/Y.1368.2 recommendation.
- dpll device naming schema use new pattern:
"dpll_%s_%d_%d", where:
- %s - dev_name(parent) of parent device,
- %d (1) - enum value of dpll type,
- %d (2) - device index provided by parent device.
- new muxed/shared pin registration:
Let the kernel module to register a shared or muxed pin without finding it or its parent. Instead use a parent/shared pin description to find correct pin internally in dpll_core, simplifing a dpll API
* Implement complex DPLL design in ice driver (Arkadiusz)
* Remove ptp_ocp driver from the series for now
v3 -> v4:
* redesign framework to make pins dynamically allocated (Arkadiusz)
* implement shared pins (Arkadiusz)
v2 -> v3:
* implement source select mode (Arkadiusz)
* add documentation

Quoted 8 lines

* implementation improvements (Jakub)
v1 -> v2:
* implement returning supported input/output types
* ptp_ocp: follow suggestions from Jonathan
* add linux-clk mailing list
v0 -> v1:
* fix code style and errors
* add linux-arm mailing list

Vadim, did you try ynl monitor? I think there might be something wrong with the yaml spec:

# ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/dpll.yaml --subscribe monitor --sleep 10
Unexpected msg id done while checking for ntf nl_len = 92 (76) nl_flags = 0x0 nl_type = 19
#82 lore raw
Quoted 76 lines

From: Jiri Pirko <[email protected]>
Sent: Thursday, May 11, 2023 9:53 AM

Quoted 63 lines · Fri, Apr 28, 2023 at 02:20:01AM CEST, [email protected] wrote:

From: Vadim Fedorenko <[email protected]>

Implement common API for clock/DPLL configuration and status reporting. The API utilises netlink interface as transport for commands and event notifications. This API aim to extend current pin configuration and make it flexible and easy to cover special configurations.

v6 -> v7:
* YAML spec:
- remove nested 'pin' attribute
- clean up definitions on top of the latest changes
* pin object:
- pin xarray uses id provided by the driver
- remove usage of PIN_IDX_INVALID in set function
- source_pin_get() returns object instead of idx
- fixes in frequency support API
* device and pin operations are const now
* small fixes in naming in Makefile and in the functions
* single mutex for the subsystem to avoid possible ABBA locks
* no special *_priv() helpers anymore, private data is passed as void*
* no netlink filters by name anymore, only index is supported
* update ptp_ocp and ice drivers to follow new API version
* add mlx5e driver as a new customer of the subsystem
v5 -> v6:
* rework pin part to better fit shared pins use cases
* add YAML spec to easy generate user-space apps
* simple implementation in ptp_ocp is back again
v4 -> v5:
* fix code issues found during last reviews:
- replace cookie with clock id
- follow one naming schema in dpll subsys
- move function comments to dpll_core.c, fix exports
- remove single-use helper functions
- merge device register with alloc
- lock and unlock mutex on dpll device release
- move dpll_type to uapi header
- rename DPLLA_DUMP_FILTER to DPLLA_FILTER
- rename dpll_pin_state to dpll_pin_mode
- rename DPLL_MODE_FORCED to DPLL_MODE_MANUAL
- remove DPLL_CHANGE_PIN_TYPE enum value
* rewrite framework once again (Arkadiusz)
- add clock class:
Provide userspace with clock class value of DPLL with dpll device dump netlink request. Clock class is assigned by driver allocating a dpll device. Clock class values are defined as specified in:
ITU-T G.8273.2/Y.1368.2 recommendation.
- dpll device naming schema use new pattern:
"dpll_%s_%d_%d", where:
- %s - dev_name(parent) of parent device,
- %d (1) - enum value of dpll type,
- %d (2) - device index provided by parent device.
- new muxed/shared pin registration:
Let the kernel module to register a shared or muxed pin without finding it or its parent. Instead use a parent/shared pin description to find correct pin internally in dpll_core, simplifing a dpll API
* Implement complex DPLL design in ice driver (Arkadiusz)
* Remove ptp_ocp driver from the series for now
v3 -> v4:
* redesign framework to make pins dynamically allocated (Arkadiusz)
* implement shared pins (Arkadiusz)
v2 -> v3:
* implement source select mode (Arkadiusz)
* add documentation

Quoted 8 lines

* implementation improvements (Jakub)
v1 -> v2:
* implement returning supported input/output types
* ptp_ocp: follow suggestions from Jonathan
* add linux-clk mailing list
v0 -> v1:
* fix code style and errors
* add linux-arm mailing list

Quoted 7 lines

Vadim, did you try ynl monitor? I think there might be something wrong with the yaml spec:

# ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/dpll.yaml --
subscribe monitor --sleep 10
Unexpected msg id done while checking for ntf nl_len = 92 (76) nl_flags =
0x0 nl_type = 19

One of the commits I have prepared already replaces old notifications with the ones suggested previously, where format of notification is the same as format of get command.
It works there, altough not sure if it works only for me or for everyone, I might have done some modifications to ynl-lib itself, need to double check that.

Thank you,
Arkadiusz

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer
#83 lore raw
In reply to Vadim Fedorenko

Let me summarize the outcome of the discussion between me and Jakub regarding attributes, handles and ID lookups in the RFCv7 thread:

--------------------------------------------------------------
** Needed changes for RFCv8 **

1) No scoped indexes.
The indexes passed from driver to dpll core during call of:
dpll_device_get() - device_idx
dpll_pin_get() - pin_idx
should be for INTERNAL kernel use only and NOT EXPOSED over uapi. Therefore following attributes need to be removed:
DPLL_A_PIN_IDX
DPLL_A_PIN_PARENT_IDX

2) For device, the handle will be DPLL_A_ID == dpll->id.
This will be the only handle for device for every
device related GET, SET command and every device related notification.
Note: this ID is not deterministing and may be different depending on order of device probes etc.

3) For pin, the handle will be DPLL_A_PIN_ID == pin->id
This will be the only handle for pin for every
pin related GET, SET command and every pin related notification.
Note: this ID is not deterministing and may be different depending on order of device probes etc.

4) Remove attribute:
DPLL_A_PIN_LABEL
and replace it with:
DPLL_A_PIN_PANEL_LABEL (string)
DPLL_A_PIN_XXX (string)
where XXX is a label type, like for example:
DPLL_A_PIN_BOARD_LABEL
DPLL_A_PIN_BOARD_TRACE
DPLL_A_PIN_PACKAGE_PIN

5) Make sure you expose following attributes for every device and pin GET/DUMP command reply message:
DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID

6) Remove attributes:
DPLL_A_DEV_NAME
DPLL_A_BUS_NAME
as they no longer have any value and do no make sense (even in RFCv7)

--------------------------------------------------------------
** Lookup commands **

Basically these would allow user to query DEVICE_ID and PIN_ID according to provided atributes (see examples below).

These would be from my perspective optional for this patchsets. I believe we can do it as follow-up if needed. For example for mlx5 I don't have usecase for it, since I can consistently get PIN_ID using RT netlink for given netdev. But I can imagine that for non-SyncE dpll driver this would make sense to have.

1) Introduce CMD_GET_ID - query the kernel for a dpll device specified by given attrs Example:
-> DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
DPLL_A_TYPE
<- DPLL_A_ID
Example:
-> DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
<- DPLL_A_ID
Example:
-> DPLL_A_MODULE_NAME
<- -EINVAL (Extack: "multiple devices matched")

If user passes a subset of attrs which would not result in a single match, kernel returns -EINVAL and proper extack message.

2) Introduce CMD_GET_PIN_ID - query the kernel for a dpll pin specified by given attrs Example:
-> DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
DPLL_A_PIN_TYPE
DPLL_A_PIN_PANEL_LABEL
<- DPLL_A_PIN_ID
Example:
-> DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
<- DPLL_A_PIN_ID (There was only one pin for given module/clock_id)
Example:
-> DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
<- -EINVAL (Extack: "multiple pins matched")

If user passes a subset of attrs which would not result in a single match, kernel returns -EINVAL and proper extack message.

#84 lore raw
Quoted 9 lines

From: Jiri Pirko <[email protected]>
Sent: Wednesday, May 17, 2023 12:19 PM

Let me summarize the outcome of the discussion between me and Jakub regarding attributes, handles and ID lookups in the RFCv7 thread:

--------------------------------------------------------------
** Needed changes for RFCv8 **

Quoted 9 lines

1) No scoped indexes.
The indexes passed from driver to dpll core during call of:
dpll_device_get() - device_idx
dpll_pin_get() - pin_idx
should be for INTERNAL kernel use only and NOT EXPOSED over uapi. Therefore following attributes need to be removed:
DPLL_A_PIN_IDX
DPLL_A_PIN_PARENT_IDX

Seems doable.
So just to be clear, configuring a pin-pair (MUXed pins) will now be done with DPLL_A_PIN_PARENT nested attribute.
I.e. configuring state of pin on parent:
DPLL_CMD_PIN_SET
DPLL_A_PIN_ID (id of pin being configured)
DPLL_A_PIN_PARENT (nested)
DPLL_A_PIN_ID (id of parent pin)
DPLL_A_PIN_STATE(expected state)
... (other pin-pair attributes to be set)

Is that ok, or we need separated attribute like DPLL_A_PIN_PARENT_ID?? I think there is no need for separated one, documentation shall just reflect that.
Also we have nested attribute DPLL_A_DEVICE which is used to show connections between PIN and multiple dpll devices, to make it consistent I will rename it to DPLL_A_DEVICE_PARENT and make configuration set cmd for the pin-dpll pair similar to the above:
DPLL_CMD_PIN_SET
DPLL_A_PIN_ID (id of pin being configured)
DPLL_A_DEVICE_PARENT (nested)
DPLL_A_ID (id of parent dpll)
DPLL_A_PIN_STATE(expected state)
... (other pin-dpll attributes to be set)

Does it make sense?

Quoted 6 lines

2) For device, the handle will be DPLL_A_ID == dpll->id. This will be the only handle for device for every
device related GET, SET command and every device related notification.
Note: this ID is not deterministing and may be different depending on order of device probes etc.

Seems doable.

Quoted 6 lines

3) For pin, the handle will be DPLL_A_PIN_ID == pin->id
This will be the only handle for pin for every
pin related GET, SET command and every pin related notification.
Note: this ID is not deterministing and may be different depending on order of device probes etc.

Seems doable.

Quoted 10 lines

4) Remove attribute:
DPLL_A_PIN_LABEL
and replace it with:
DPLL_A_PIN_PANEL_LABEL (string)
DPLL_A_PIN_XXX (string)
where XXX is a label type, like for example:
DPLL_A_PIN_BOARD_LABEL
DPLL_A_PIN_BOARD_TRACE
DPLL_A_PIN_PACKAGE_PIN

Sorry, I don't get this idea, what are those types? What are they for?

Quoted 5 lines

5) Make sure you expose following attributes for every device and pin GET/DUMP command reply message:
DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID

Seems doable.

Quoted 5 lines

6) Remove attributes:
DPLL_A_DEV_NAME
DPLL_A_BUS_NAME
as they no longer have any value and do no make sense (even in RFCv7)

Seems doable.

Quoted 28 lines

--------------------------------------------------------------
** Lookup commands **

Basically these would allow user to query DEVICE_ID and PIN_ID according to provided atributes (see examples below).

These would be from my perspective optional for this patchsets. I believe we can do it as follow-up if needed. For example for mlx5 I don't have usecase for it, since I can consistently get PIN_ID using RT netlink for given netdev. But I can imagine that for non-SyncE dpll driver this would make sense to have.

1) Introduce CMD_GET_ID - query the kernel for a dpll device specified by given attrs Example:
-> DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
DPLL_A_TYPE
<- DPLL_A_ID
Example:
-> DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
<- DPLL_A_ID
Example:
-> DPLL_A_MODULE_NAME
<- -EINVAL (Extack: "multiple devices matched")

Quoted 3 lines

If user passes a subset of attrs which would not result in a single match, kernel returns -EINVAL and proper extack message.

Seems ok.

Quoted 17 lines

2) Introduce CMD_GET_PIN_ID - query the kernel for a dpll pin specified by given attrs Example:
-> DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
DPLL_A_PIN_TYPE
DPLL_A_PIN_PANEL_LABEL
<- DPLL_A_PIN_ID
Example:
-> DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
<- DPLL_A_PIN_ID (There was only one pin for given module/clock_id)
Example:
-> DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
<- -EINVAL (Extack: "multiple pins matched")

Quoted 2 lines

If user passes a subset of attrs which would not result in a single match, kernel returns -EINVAL and proper extack message.

Seems ok.

Will try to implement those now.

Thank you,
Arkadiusz

maintainer
#85 lore raw
Quoted 30 lines · Fri, May 26, 2023 at 12:14:00PM CEST, [email protected] wrote:
Quoted 9 lines

From: Jiri Pirko <[email protected]>
Sent: Wednesday, May 17, 2023 12:19 PM

Let me summarize the outcome of the discussion between me and Jakub regarding attributes, handles and ID lookups in the RFCv7 thread:

--------------------------------------------------------------
** Needed changes for RFCv8 **

Quoted 9 lines

1) No scoped indexes.
The indexes passed from driver to dpll core during call of:
dpll_device_get() - device_idx
dpll_pin_get() - pin_idx
should be for INTERNAL kernel use only and NOT EXPOSED over uapi. Therefore following attributes need to be removed:
DPLL_A_PIN_IDX
DPLL_A_PIN_PARENT_IDX

Seems doable.
So just to be clear, configuring a pin-pair (MUXed pins) will now be done with DPLL_A_PIN_PARENT nested attribute.
I.e. configuring state of pin on parent:
DPLL_CMD_PIN_SET
DPLL_A_PIN_ID (id of pin being configured)
DPLL_A_PIN_PARENT (nested)
DPLL_A_PIN_ID (id of parent pin)
DPLL_A_PIN_STATE(expected state)
... (other pin-pair attributes to be set)

Quoted 10 lines

Is that ok, or we need separated attribute like DPLL_A_PIN_PARENT_ID?? I think there is no need for separated one, documentation shall just reflect that.
Also we have nested attribute DPLL_A_DEVICE which is used to show connections between PIN and multiple dpll devices, to make it consistent I will rename it to DPLL_A_DEVICE_PARENT and make configuration set cmd for the pin-dpll pair similar to the above:
DPLL_CMD_PIN_SET
DPLL_A_PIN_ID (id of pin being configured)
DPLL_A_DEVICE_PARENT (nested)

It is a parent of pin, not device. The name is confusing. But see below.

Quoted 5 lines

DPLL_A_ID (id of parent dpll)
DPLL_A_PIN_STATE(expected state)
... (other pin-dpll attributes to be set)

Does it make sense?

Yeah, good idea. I like this. We will have consistent approach for parent pin and device. To take it even further, we can have one nested attr for parent and decide the parent type according to the id attr given:

DPLL_CMD_PIN_SET
DPLL_A_PIN_ID (id of pin being configured)
DPLL_A_PIN_PARENT (nested)
DPLL_A_PIN_ID (id of parent pin)
DPLL_A_PIN_STATE(expected state)
... (other pin-pair attributes to be set)

DPLL_CMD_PIN_SET
DPLL_A_PIN_ID (id of pin being configured)
DPLL_A_PIN_PARENT (nested)
DPLL_A_ID (id of parent dpll)
DPLL_A_PIN_STATE(expected state)
... (other pin-dpll attributes to be set)

Same for PIN_GET

Makes sense?

Quoted 31 lines
Quoted 8 lines

2) For device, the handle will be DPLL_A_ID == dpll->id. This will be the only handle for device for every
device related GET, SET command and every device related notification.
Note: this ID is not deterministing and may be different depending on order of device probes etc.

Seems doable.

Quoted 6 lines

3) For pin, the handle will be DPLL_A_PIN_ID == pin->id
This will be the only handle for pin for every
pin related GET, SET command and every pin related notification.
Note: this ID is not deterministing and may be different depending on order of device probes etc.

Seems doable.

Quoted 10 lines

4) Remove attribute:
DPLL_A_PIN_LABEL
and replace it with:
DPLL_A_PIN_PANEL_LABEL (string)
DPLL_A_PIN_XXX (string)
where XXX is a label type, like for example:
DPLL_A_PIN_BOARD_LABEL
DPLL_A_PIN_BOARD_TRACE
DPLL_A_PIN_PACKAGE_PIN

Quoted 2 lines

Sorry, I don't get this idea, what are those types? What are they for?

The point is to make the driver developer to think before passing randomly constructed label strings. For example, "board_label" would lead the developer to check how the pin is labeled on the board. The "panel_label" indicates this is label on a panel. Also, developer can fill multiple labels for the same pin.

Quoted 68 lines
Quoted 6 lines

5) Make sure you expose following attributes for every device and pin GET/DUMP command reply message:
DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID

Seems doable.

Quoted 5 lines

6) Remove attributes:
DPLL_A_DEV_NAME
DPLL_A_BUS_NAME
as they no longer have any value and do no make sense (even in RFCv7)

Seems doable.

Quoted 28 lines

--------------------------------------------------------------
** Lookup commands **

Basically these would allow user to query DEVICE_ID and PIN_ID according to provided atributes (see examples below).

These would be from my perspective optional for this patchsets. I believe we can do it as follow-up if needed. For example for mlx5 I don't have usecase for it, since I can consistently get PIN_ID using RT netlink for given netdev. But I can imagine that for non-SyncE dpll driver this would make sense to have.

1) Introduce CMD_GET_ID - query the kernel for a dpll device specified by given attrs Example:
-> DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
DPLL_A_TYPE
<- DPLL_A_ID
Example:
-> DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
<- DPLL_A_ID
Example:
-> DPLL_A_MODULE_NAME
<- -EINVAL (Extack: "multiple devices matched")

Quoted 3 lines

If user passes a subset of attrs which would not result in a single match, kernel returns -EINVAL and proper extack message.

Seems ok.

Quoted 17 lines

2) Introduce CMD_GET_PIN_ID - query the kernel for a dpll pin specified by given attrs Example:
-> DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
DPLL_A_PIN_TYPE
DPLL_A_PIN_PANEL_LABEL
<- DPLL_A_PIN_ID
Example:
-> DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
<- DPLL_A_PIN_ID (There was only one pin for given module/clock_id)
Example:
-> DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
<- -EINVAL (Extack: "multiple pins matched")

Quoted 7 lines
Quoted 2 lines

If user passes a subset of attrs which would not result in a single match, kernel returns -EINVAL and proper extack message.

Seems ok.

Will try to implement those now.

Cool, thx!

Quoted 3 lines

Thank you,
Arkadiusz

#86 lore raw
Quoted 75 lines

From: Jiri Pirko <[email protected]>
Sent: Friday, May 26, 2023 12:39 PM

Quoted 30 lines · Fri, May 26, 2023 at 12:14:00PM CEST, [email protected] wrote:
Quoted 9 lines

From: Jiri Pirko <[email protected]>
Sent: Wednesday, May 17, 2023 12:19 PM

Let me summarize the outcome of the discussion between me and Jakub regarding attributes, handles and ID lookups in the RFCv7 thread:

--------------------------------------------------------------
** Needed changes for RFCv8 **

Quoted 9 lines

1) No scoped indexes.
The indexes passed from driver to dpll core during call of:
dpll_device_get() - device_idx
dpll_pin_get() - pin_idx
should be for INTERNAL kernel use only and NOT EXPOSED over uapi. Therefore following attributes need to be removed:
DPLL_A_PIN_IDX
DPLL_A_PIN_PARENT_IDX

Seems doable.
So just to be clear, configuring a pin-pair (MUXed pins) will now be done with DPLL_A_PIN_PARENT nested attribute.
I.e. configuring state of pin on parent:
DPLL_CMD_PIN_SET
DPLL_A_PIN_ID (id of pin being configured)
DPLL_A_PIN_PARENT (nested)
DPLL_A_PIN_ID (id of parent pin)
DPLL_A_PIN_STATE(expected state)
... (other pin-pair attributes to be set)

Quoted 4 lines

Is that ok, or we need separated attribute like DPLL_A_PIN_PARENT_ID?? I think there is no need for separated one, documentation shall just reflect that.
Also we have nested attribute DPLL_A_DEVICE which is used to show

connections

Quoted 6 lines

between PIN and multiple dpll devices, to make it consistent I will rename it to DPLL_A_DEVICE_PARENT and make configuration set cmd for the pin-dpll pair similar to the above:
DPLL_CMD_PIN_SET
DPLL_A_PIN_ID (id of pin being configured)
DPLL_A_DEVICE_PARENT (nested)

It is a parent of pin, not device. The name is confusing. But see below.

Quoted 5 lines

DPLL_A_ID (id of parent dpll)
DPLL_A_PIN_STATE(expected state)
... (other pin-dpll attributes to be set)

Does it make sense?

Yeah, good idea. I like this. We will have consistent approach for parent pin and device. To take it even further, we can have one nested attr for parent and decide the parent type according to the id attr given:

DPLL_CMD_PIN_SET
DPLL_A_PIN_ID (id of pin being configured)
DPLL_A_PIN_PARENT (nested)
DPLL_A_PIN_ID (id of parent pin)
DPLL_A_PIN_STATE(expected state)
... (other pin-pair attributes to be set)

DPLL_CMD_PIN_SET
DPLL_A_PIN_ID (id of pin being configured)
DPLL_A_PIN_PARENT (nested)
DPLL_A_ID (id of parent dpll)
DPLL_A_PIN_STATE(expected state)
... (other pin-dpll attributes to be set)

Quoted 4 lines

Same for PIN_GET

Makes sense?

Sure, fixed.

Quoted 33 lines
Quoted 33 lines
Quoted 10 lines

2) For device, the handle will be DPLL_A_ID == dpll->id. This will be the only handle for device for every
device related GET, SET command and every device related notification.
Note: this ID is not deterministing and may be different depending on order of device probes etc.

Seems doable.

Quoted 6 lines

3) For pin, the handle will be DPLL_A_PIN_ID == pin->id
This will be the only handle for pin for every
pin related GET, SET command and every pin related notification.
Note: this ID is not deterministing and may be different depending on order of device probes etc.

Seems doable.

Quoted 10 lines

4) Remove attribute:
DPLL_A_PIN_LABEL
and replace it with:
DPLL_A_PIN_PANEL_LABEL (string)
DPLL_A_PIN_XXX (string)
where XXX is a label type, like for example:
DPLL_A_PIN_BOARD_LABEL
DPLL_A_PIN_BOARD_TRACE
DPLL_A_PIN_PACKAGE_PIN

Quoted 9 lines
Quoted 2 lines

Sorry, I don't get this idea, what are those types? What are they for?

The point is to make the driver developer to think before passing randomly constructed label strings. For example, "board_label" would lead the developer to check how the pin is labeled on the board. The "panel_label" indicates this is label on a panel. Also, developer can fill multiple labels for the same pin.

Ok, makes sense, added as suggested.

Thank you,
Arkadiusz

Quoted 84 lines
Quoted 70 lines
Quoted 8 lines

5) Make sure you expose following attributes for every device and pin GET/DUMP command reply message:
DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID

Seems doable.

Quoted 5 lines

6) Remove attributes:
DPLL_A_DEV_NAME
DPLL_A_BUS_NAME
as they no longer have any value and do no make sense (even in RFCv7)

Seems doable.

Quoted 28 lines

--------------------------------------------------------------
** Lookup commands **

Basically these would allow user to query DEVICE_ID and PIN_ID according to provided atributes (see examples below).

These would be from my perspective optional for this patchsets. I believe we can do it as follow-up if needed. For example for mlx5 I don't have usecase for it, since I can consistently get PIN_ID using RT netlink for given netdev. But I can imagine that for non-SyncE dpll driver this would make sense to have.

1) Introduce CMD_GET_ID - query the kernel for a dpll device specified by given attrs Example:
-> DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
DPLL_A_TYPE
<- DPLL_A_ID
Example:
-> DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
<- DPLL_A_ID
Example:
-> DPLL_A_MODULE_NAME
<- -EINVAL (Extack: "multiple devices matched")

Quoted 3 lines

If user passes a subset of attrs which would not result in a single match, kernel returns -EINVAL and proper extack message.

Seems ok.

Quoted 17 lines

2) Introduce CMD_GET_PIN_ID - query the kernel for a dpll pin specified by given attrs Example:
-> DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
DPLL_A_PIN_TYPE
DPLL_A_PIN_PANEL_LABEL
<- DPLL_A_PIN_ID
Example:
-> DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
<- DPLL_A_PIN_ID (There was only one pin for given module/clock_id)
Example:
-> DPLL_A_MODULE_NAME
DPLL_A_CLOCK_ID
<- -EINVAL (Extack: "multiple pins matched")

Quoted 7 lines
Quoted 2 lines

If user passes a subset of attrs which would not result in a single match, kernel returns -EINVAL and proper extack message.

Seems ok.

Will try to implement those now.

Cool, thx!

Quoted 3 lines

Thank you,
Arkadiusz